documents.js 1.44.0 → 1.45.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
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, ContentCellValueSchema, ContentDrawPageSchema, ContentDrawPageSchema as ContentDrawPageSchema$1, ContentImageBlockSchema, ContentPageBreakSchema, ContentParagraphSchema, ContentPathPointSchema, ContentPathSegmentSchema, ContentRunSchema, ContentSectionSchema, ContentSectionSchema as ContentSectionSchema$1, ContentShapeSchema, ContentSheetCellSchema, ContentSheetColumnSchema, ContentSheetPrintRangeSchema, ContentSheetPrintSettingsSchema, ContentSheetRepeatRangeSchema, ContentSheetRowSchema, ContentSheetSchema, ContentSheetSchema as ContentSheetSchema$1, ContentSlideSchema, ContentSlideSchema as ContentSlideSchema$1, ContentStrokeSchema, ContentSubpathSchema, ContentTableCellSchema, ContentTableRowSchema, ContentTableSchema, ContentVectorSchema, 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, applyOdfTransform, base64ToBytes as base64ToBytes$2, bytesToBase64 as bytesToBase64$2, decodeOdfText, decodePackage as decodePackage$2, encodePackage as encodePackage$2, formatOdfLength, parseCellReference, parseOdfLength, readOdg, readOdp, readOds, readOdt, resolveOdfShapeGeometry, resolveStyle, setDocumentMediaType, syncManifest, syncManifest as syncManifest$1, xmlnsAttributes } from "odf.js";
4
+ import { ODF_MEDIA_TYPES, StyleRegistry, applyOdfTransform, base64ToBytes as base64ToBytes$2, buildOdfSubpaths, bytesToBase64 as bytesToBase64$2, decodeOdfText, decodePackage as decodePackage$2, encodePackage as encodePackage$2, formatOdfColor, formatOdfLength, parseBox, parseCellReference, parseLinePoints, parseOdfColor, parseOdfLength, parseOdfPathData, parseOdfViewBox, readOdg, readOdp, readOds, 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;
@@ -535,7 +535,7 @@ function needsSpacePreserve(text) {
535
535
  }
536
536
  //#endregion
537
537
  //#region src/edit/docx/run.ts
538
- function directChild$9(parent, tag) {
538
+ function directChild$10(parent, tag) {
539
539
  for (const child of parent.children) if (child.type === "element" && child.tag === tag) return child;
540
540
  }
541
541
  function appendUElement(rPr, value) {
@@ -544,7 +544,7 @@ function appendUElement(rPr, value) {
544
544
  return created;
545
545
  }
546
546
  function findOrCreateT(run) {
547
- const existing = directChild$9(run, "w:t");
547
+ const existing = directChild$10(run, "w:t");
548
548
  if (existing !== void 0) return existing;
549
549
  const created = el("w:t");
550
550
  run.children.push(created);
@@ -564,7 +564,7 @@ var DocxRun = class {
564
564
  }
565
565
  rPr(create) {
566
566
  const node = this.live();
567
- return create ? ensureFirstChild(node, "w:rPr") : directChild$9(node, "w:rPr");
567
+ return create ? ensureFirstChild(node, "w:rPr") : directChild$10(node, "w:rPr");
568
568
  }
569
569
  get text() {
570
570
  return textContent$1(this.live());
@@ -588,14 +588,14 @@ var DocxRun = class {
588
588
  }
589
589
  get underline() {
590
590
  const rPr = this.rPr(false);
591
- const uElement = rPr === void 0 ? void 0 : directChild$9(rPr, "w:u");
591
+ const uElement = rPr === void 0 ? void 0 : directChild$10(rPr, "w:u");
592
592
  if (uElement === void 0) return false;
593
593
  for (const a of uElement.attributes) if (a.name === "w:val") return a.value !== "none";
594
594
  return true;
595
595
  }
596
596
  set underline(value) {
597
597
  const rPr = this.rPr(true);
598
- const existing = directChild$9(rPr, "w:u");
598
+ const existing = directChild$10(rPr, "w:u");
599
599
  if (existing === void 0) {
600
600
  appendUElement(rPr, value);
601
601
  return;
@@ -669,7 +669,7 @@ function buildRun$1(init = {}) {
669
669
  }
670
670
  //#endregion
671
671
  //#region src/edit/docx/paragraph.ts
672
- function directChild$8(parent, tag) {
672
+ function directChild$9(parent, tag) {
673
673
  for (const child of parent.children) if (child.type === "element" && child.tag === tag) return child;
674
674
  }
675
675
  var DocxParagraph = class {
@@ -688,7 +688,7 @@ var DocxParagraph = class {
688
688
  }
689
689
  pPr(create) {
690
690
  const node = this.live();
691
- return create ? ensureFirstChild(node, "w:pPr") : directChild$8(node, "w:pPr");
691
+ return create ? ensureFirstChild(node, "w:pPr") : directChild$9(node, "w:pPr");
692
692
  }
693
693
  get text() {
694
694
  return textContent$1(this.live());
@@ -725,7 +725,7 @@ var DocxParagraph = class {
725
725
  set styleId(value) {
726
726
  if (value === void 0) {
727
727
  const pPr = this.pPr(false);
728
- const existing = pPr === void 0 ? void 0 : directChild$8(pPr, "w:pStyle");
728
+ const existing = pPr === void 0 ? void 0 : directChild$9(pPr, "w:pStyle");
729
729
  if (existing !== void 0 && pPr !== void 0) removeChild(pPr.children, existing);
730
730
  return;
731
731
  }
@@ -737,7 +737,7 @@ var DocxParagraph = class {
737
737
  set alignment(value) {
738
738
  if (value === void 0) {
739
739
  const pPr = this.pPr(false);
740
- const existing = pPr === void 0 ? void 0 : directChild$8(pPr, "w:jc");
740
+ const existing = pPr === void 0 ? void 0 : directChild$9(pPr, "w:jc");
741
741
  if (existing !== void 0 && pPr !== void 0) removeChild(pPr.children, existing);
742
742
  return;
743
743
  }
@@ -745,12 +745,12 @@ var DocxParagraph = class {
745
745
  }
746
746
  get list() {
747
747
  const pPr = this.pPr(false);
748
- const numPr = pPr === void 0 ? void 0 : directChild$8(pPr, "w:numPr");
748
+ const numPr = pPr === void 0 ? void 0 : directChild$9(pPr, "w:numPr");
749
749
  if (numPr === void 0) return;
750
- const numIdElement = directChild$8(numPr, "w:numId");
750
+ const numIdElement = directChild$9(numPr, "w:numId");
751
751
  const numId = numIdElement === void 0 ? void 0 : attr$1(numIdElement, "w:val");
752
752
  if (numId === void 0) return;
753
- const ilvlElement = directChild$8(numPr, "w:ilvl");
753
+ const ilvlElement = directChild$9(numPr, "w:ilvl");
754
754
  const ilvl = ilvlElement === void 0 ? void 0 : attr$1(ilvlElement, "w:val");
755
755
  return {
756
756
  numId,
@@ -760,7 +760,7 @@ var DocxParagraph = class {
760
760
  set list(value) {
761
761
  const pPr = this.pPr(true);
762
762
  if (value === void 0) {
763
- const existing = directChild$8(pPr, "w:numPr");
763
+ const existing = directChild$9(pPr, "w:numPr");
764
764
  if (existing !== void 0) removeChild(pPr.children, existing);
765
765
  return;
766
766
  }
@@ -794,7 +794,7 @@ function buildParagraph$1(init = {}) {
794
794
  const CONTENT_TYPES_NS$1 = "http://schemas.openxmlformats.org/package/2006/content-types";
795
795
  const RELS_NS$1 = "http://schemas.openxmlformats.org/package/2006/relationships";
796
796
  const WORDML_NS = "http://schemas.openxmlformats.org/wordprocessingml/2006/main";
797
- function declaration$4() {
797
+ function declaration$5() {
798
798
  return {
799
799
  type: "declaration",
800
800
  attributes: [
@@ -863,23 +863,23 @@ function createEmptyDocxPackage() {
863
863
  return { parts: {
864
864
  "[Content_Types].xml": {
865
865
  kind: "xml",
866
- nodes: [declaration$4(), contentTypes]
866
+ nodes: [declaration$5(), contentTypes]
867
867
  },
868
868
  "_rels/.rels": {
869
869
  kind: "xml",
870
- nodes: [declaration$4(), rootRels]
870
+ nodes: [declaration$5(), rootRels]
871
871
  },
872
872
  "word/document.xml": {
873
873
  kind: "xml",
874
- nodes: [declaration$4(), document]
874
+ nodes: [declaration$5(), document]
875
875
  },
876
876
  "word/_rels/document.xml.rels": {
877
877
  kind: "xml",
878
- nodes: [declaration$4(), documentRels]
878
+ nodes: [declaration$5(), documentRels]
879
879
  },
880
880
  "word/styles.xml": {
881
881
  kind: "xml",
882
- nodes: [declaration$4(), styles]
882
+ nodes: [declaration$5(), styles]
883
883
  }
884
884
  } };
885
885
  }
@@ -1170,7 +1170,7 @@ const SLIDE_LAYOUT_REL_TYPE = "http://schemas.openxmlformats.org/officeDocument/
1170
1170
  const THEME_REL_TYPE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme";
1171
1171
  const NOTES_MASTER_REL_TYPE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/notesMaster";
1172
1172
  const MIN_MASTER_OR_LAYOUT_ID = 2147483648;
1173
- function declaration$3() {
1173
+ function declaration$4() {
1174
1174
  return {
1175
1175
  type: "declaration",
1176
1176
  attributes: [
@@ -1320,7 +1320,7 @@ function ensureNotesMaster(pkg) {
1320
1320
  });
1321
1321
  pkg.parts[NOTES_MASTER_PART_PATH] = {
1322
1322
  kind: "xml",
1323
- nodes: [declaration$3(), buildNotesMaster()]
1323
+ nodes: [declaration$4(), buildNotesMaster()]
1324
1324
  };
1325
1325
  ensureContentTypeOverride(pkg, NOTES_MASTER_PART_PATH, NOTES_MASTER_CONTENT_TYPE);
1326
1326
  const presentationToNotesMasterTarget = buildRelativeTarget(PRESENTATION_PART_PATH$1, NOTES_MASTER_PART_PATH);
@@ -1359,15 +1359,15 @@ function createEmptyPptxPackage() {
1359
1359
  const pkg = { parts: {
1360
1360
  "[Content_Types].xml": {
1361
1361
  kind: "xml",
1362
- nodes: [declaration$3(), contentTypes]
1362
+ nodes: [declaration$4(), contentTypes]
1363
1363
  },
1364
1364
  "_rels/.rels": {
1365
1365
  kind: "xml",
1366
- nodes: [declaration$3(), rootRels]
1366
+ nodes: [declaration$4(), rootRels]
1367
1367
  },
1368
1368
  [PRESENTATION_PART_PATH$1]: {
1369
1369
  kind: "xml",
1370
- nodes: [declaration$3(), el("p:presentation", {
1370
+ nodes: [declaration$4(), el("p:presentation", {
1371
1371
  "xmlns:p": PML_NS,
1372
1372
  "xmlns:r": R_NS
1373
1373
  })]
@@ -1380,7 +1380,7 @@ function createEmptyPptxPackage() {
1380
1380
  });
1381
1381
  pkg.parts[SLIDE_LAYOUT_PART_PATH] = {
1382
1382
  kind: "xml",
1383
- nodes: [declaration$3(), buildSlideLayout()]
1383
+ nodes: [declaration$4(), buildSlideLayout()]
1384
1384
  };
1385
1385
  ensureContentTypeOverride(pkg, SLIDE_LAYOUT_PART_PATH, SLIDE_LAYOUT_CONTENT_TYPE);
1386
1386
  const masterToLayoutTarget = buildRelativeTarget(SLIDE_MASTER_PART_PATH, SLIDE_LAYOUT_PART_PATH);
@@ -1395,12 +1395,12 @@ function createEmptyPptxPackage() {
1395
1395
  });
1396
1396
  pkg.parts[SLIDE_MASTER_PART_PATH] = {
1397
1397
  kind: "xml",
1398
- nodes: [declaration$3(), buildSlideMaster(masterToLayoutRelId)]
1398
+ nodes: [declaration$4(), buildSlideMaster(masterToLayoutRelId)]
1399
1399
  };
1400
1400
  ensureContentTypeOverride(pkg, SLIDE_MASTER_PART_PATH, SLIDE_MASTER_CONTENT_TYPE);
1401
1401
  pkg.parts[THEME_PART_PATH] = {
1402
1402
  kind: "xml",
1403
- nodes: [declaration$3(), buildTheme()]
1403
+ nodes: [declaration$4(), buildTheme()]
1404
1404
  };
1405
1405
  ensureContentTypeOverride(pkg, THEME_PART_PATH, THEME_CONTENT_TYPE);
1406
1406
  const presentationToMasterTarget = buildRelativeTarget(PRESENTATION_PART_PATH$1, SLIDE_MASTER_PART_PATH);
@@ -1425,7 +1425,7 @@ function createEmptyPptxPackage() {
1425
1425
  }
1426
1426
  //#endregion
1427
1427
  //#region src/edit/pptx/shape.ts
1428
- function directChild$7(parent, tag) {
1428
+ function directChild$8(parent, tag) {
1429
1429
  for (const child of parent.children) if (child.type === "element" && child.tag === tag) return child;
1430
1430
  }
1431
1431
  function parseEmuAttr(element, name) {
@@ -1446,7 +1446,7 @@ var PptxShape = class {
1446
1446
  }
1447
1447
  spPrElement(create) {
1448
1448
  const node = this.live();
1449
- const existing = directChild$7(node, "p:spPr");
1449
+ const existing = directChild$8(node, "p:spPr");
1450
1450
  if (existing !== void 0 || !create) return existing;
1451
1451
  const created = el("p:spPr");
1452
1452
  node.children.push(created);
@@ -1454,10 +1454,10 @@ var PptxShape = class {
1454
1454
  }
1455
1455
  get frame() {
1456
1456
  const spPr = this.spPrElement(false);
1457
- const xfrm = spPr === void 0 ? void 0 : directChild$7(spPr, "a:xfrm");
1457
+ const xfrm = spPr === void 0 ? void 0 : directChild$8(spPr, "a:xfrm");
1458
1458
  if (xfrm === void 0) return;
1459
- const off = directChild$7(xfrm, "a:off");
1460
- const ext = directChild$7(xfrm, "a:ext");
1459
+ const off = directChild$8(xfrm, "a:off");
1460
+ const ext = directChild$8(xfrm, "a:ext");
1461
1461
  if (off === void 0 || ext === void 0) return;
1462
1462
  const x = parseEmuAttr(off, "x");
1463
1463
  const y = parseEmuAttr(off, "y");
@@ -1473,7 +1473,7 @@ var PptxShape = class {
1473
1473
  }
1474
1474
  set frame(value) {
1475
1475
  const spPr = this.spPrElement(true);
1476
- let xfrm = directChild$7(spPr, "a:xfrm");
1476
+ let xfrm = directChild$8(spPr, "a:xfrm");
1477
1477
  if (xfrm === void 0) {
1478
1478
  xfrm = el("a:xfrm");
1479
1479
  spPr.children.unshift(xfrm);
@@ -1487,12 +1487,12 @@ var PptxShape = class {
1487
1487
  })];
1488
1488
  }
1489
1489
  get text() {
1490
- const txBody = directChild$7(this.live(), "p:txBody");
1490
+ const txBody = directChild$8(this.live(), "p:txBody");
1491
1491
  return txBody === void 0 ? "" : textContent$1(txBody);
1492
1492
  }
1493
1493
  set text(value) {
1494
1494
  const node = this.live();
1495
- let txBody = directChild$7(node, "p:txBody");
1495
+ let txBody = directChild$8(node, "p:txBody");
1496
1496
  if (txBody === void 0) {
1497
1497
  txBody = el("p:txBody", {}, [el("a:bodyPr"), el("a:lstStyle")]);
1498
1498
  node.children.push(txBody);
@@ -1503,7 +1503,7 @@ var PptxShape = class {
1503
1503
  }
1504
1504
  setParagraphs(paragraphs) {
1505
1505
  const node = this.live();
1506
- let txBody = directChild$7(node, "p:txBody");
1506
+ let txBody = directChild$8(node, "p:txBody");
1507
1507
  if (txBody === void 0) {
1508
1508
  txBody = el("p:txBody", {}, [el("a:bodyPr"), el("a:lstStyle")]);
1509
1509
  node.children.push(txBody);
@@ -1614,12 +1614,12 @@ function insertPictureShapeMedia(context, slideRoot, frame, image) {
1614
1614
  }
1615
1615
  //#endregion
1616
1616
  //#region src/edit/pptx/slide.ts
1617
- function directChild$6(parent, tag) {
1617
+ function directChild$7(parent, tag) {
1618
1618
  for (const child of parent.children) if (child.type === "element" && child.tag === tag) return child;
1619
1619
  }
1620
1620
  function findSpTree(slideRoot) {
1621
- const cSld = directChild$6(slideRoot, "p:cSld");
1622
- const spTree = cSld === void 0 ? void 0 : directChild$6(cSld, "p:spTree");
1621
+ const cSld = directChild$7(slideRoot, "p:cSld");
1622
+ const spTree = cSld === void 0 ? void 0 : directChild$7(cSld, "p:spTree");
1623
1623
  if (spTree === void 0) throw new Error("slide has no p:cSld/p:spTree element");
1624
1624
  return spTree;
1625
1625
  }
@@ -1751,7 +1751,7 @@ const PRESENTATION_PART_PATH = "ppt/presentation.xml";
1751
1751
  const MEDIA_DIR = "ppt/media";
1752
1752
  const SLIDE_CONTENT_TYPE = "application/vnd.openxmlformats-officedocument.presentationml.slide+xml";
1753
1753
  const SLIDE_RELATIONSHIP_TYPE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/slide";
1754
- function directChild$5(parent, tag) {
1754
+ function directChild$6(parent, tag) {
1755
1755
  for (const child of parent.children) if (child.type === "element" && child.tag === tag) return child;
1756
1756
  }
1757
1757
  function attrValue(element, name) {
@@ -1763,12 +1763,12 @@ function findPresentationRoot(pkg) {
1763
1763
  return root;
1764
1764
  }
1765
1765
  function findSldIdLst(presentationRoot) {
1766
- const sldIdLst = directChild$5(presentationRoot, "p:sldIdLst");
1766
+ const sldIdLst = directChild$6(presentationRoot, "p:sldIdLst");
1767
1767
  if (sldIdLst === void 0) throw new Error(`${PRESENTATION_PART_PATH} has no p:sldIdLst element`);
1768
1768
  return sldIdLst;
1769
1769
  }
1770
1770
  function findSldSz(presentationRoot) {
1771
- const sldSz = directChild$5(presentationRoot, "p:sldSz");
1771
+ const sldSz = directChild$6(presentationRoot, "p:sldSz");
1772
1772
  if (sldSz === void 0) throw new Error(`${PRESENTATION_PART_PATH} has no p:sldSz element`);
1773
1773
  return sldSz;
1774
1774
  }
@@ -1929,12 +1929,12 @@ function buildPptxPackage(content) {
1929
1929
  if (firstSlide !== void 0) editor.slideSize = firstSlide.size;
1930
1930
  for (const slide of content.slides) {
1931
1931
  const pptxSlide = editor.addSlide();
1932
- for (const shape of slide.shapes) appendShape$1(pptxSlide, shape);
1932
+ for (const shape of slide.shapes) appendShape$2(pptxSlide, shape);
1933
1933
  if (slide.notes.length > 0) pptxSlide.notes = slide.notes;
1934
1934
  }
1935
1935
  return editor.toPackage();
1936
1936
  }
1937
- function appendShape$1(slide, shape) {
1937
+ function appendShape$2(slide, shape) {
1938
1938
  const [onlyBlock] = shape.blocks;
1939
1939
  if (shape.blocks.length === 1 && onlyBlock?.kind === "image") {
1940
1940
  slide.addImage({
@@ -1967,12 +1967,12 @@ function appendShape$1(slide, shape) {
1967
1967
  }
1968
1968
  //#endregion
1969
1969
  //#region src/edit/odt/automatic-styles.ts
1970
- const CONTENT_PART_PATH$3 = "content.xml";
1970
+ const CONTENT_PART_PATH$4 = "content.xml";
1971
1971
  function ensureAutomaticStyles(pkg) {
1972
- const part = pkg.parts[CONTENT_PART_PATH$3];
1973
- if (part?.kind !== "xml") throw new Error(`ensureAutomaticStyles: package has no ${CONTENT_PART_PATH$3} part`);
1972
+ const part = pkg.parts[CONTENT_PART_PATH$4];
1973
+ if (part?.kind !== "xml") throw new Error(`ensureAutomaticStyles: package has no ${CONTENT_PART_PATH$4} part`);
1974
1974
  const root = part.nodes.find((n) => n.type === "element");
1975
- if (root === void 0) throw new Error(`ensureAutomaticStyles: ${CONTENT_PART_PATH$3} has no root element`);
1975
+ if (root === void 0) throw new Error(`ensureAutomaticStyles: ${CONTENT_PART_PATH$4} has no root element`);
1976
1976
  for (const child of root.children) if (child.type === "element" && child.tag === "office:automatic-styles") return child;
1977
1977
  const created = el("office:automatic-styles");
1978
1978
  const insertBeforeTags = /* @__PURE__ */ new Set([
@@ -2066,7 +2066,7 @@ function applyStyleChange(pkg, element, family, change) {
2066
2066
  ...readCurrentStyleProperties(pkg, element, family),
2067
2067
  ...change
2068
2068
  };
2069
- const name = StyleRegistry.forPart(pkg, CONTENT_PART_PATH$3).intern({
2069
+ const name = StyleRegistry.forPart(pkg, CONTENT_PART_PATH$4).intern({
2070
2070
  family,
2071
2071
  properties: merged
2072
2072
  });
@@ -2297,7 +2297,7 @@ function buildList(pkg) {
2297
2297
  }
2298
2298
  //#endregion
2299
2299
  //#region src/edit/odt/scaffold.ts
2300
- const CONTENT_NS_PREFIXES$2 = [
2300
+ const CONTENT_NS_PREFIXES$3 = [
2301
2301
  "office",
2302
2302
  "style",
2303
2303
  "text",
@@ -2307,7 +2307,7 @@ const CONTENT_NS_PREFIXES$2 = [
2307
2307
  "svg",
2308
2308
  "xlink"
2309
2309
  ];
2310
- const STYLES_NS_PREFIXES$2 = [
2310
+ const STYLES_NS_PREFIXES$3 = [
2311
2311
  "office",
2312
2312
  "style",
2313
2313
  "text",
@@ -2317,16 +2317,16 @@ const STYLES_NS_PREFIXES$2 = [
2317
2317
  "svg",
2318
2318
  "xlink"
2319
2319
  ];
2320
- const META_NS_PREFIXES$2 = [
2320
+ const META_NS_PREFIXES$3 = [
2321
2321
  "office",
2322
2322
  "meta",
2323
2323
  "dc"
2324
2324
  ];
2325
- const ODF_VERSION$2 = "1.3";
2326
- const PAGE_LAYOUT_NAME$2 = "PM1";
2327
- const MASTER_PAGE_NAME$2 = "Standard";
2325
+ const ODF_VERSION$3 = "1.3";
2326
+ const PAGE_LAYOUT_NAME$3 = "PM1";
2327
+ const MASTER_PAGE_NAME$3 = "Standard";
2328
2328
  const DEFAULT_MARGIN_PT = 72;
2329
- function declaration$2() {
2329
+ function declaration$3() {
2330
2330
  return {
2331
2331
  type: "declaration",
2332
2332
  attributes: [
@@ -2345,8 +2345,8 @@ function declaration$2() {
2345
2345
  ]
2346
2346
  };
2347
2347
  }
2348
- function buildPageLayout$2() {
2349
- return el("style:page-layout", { "style:name": PAGE_LAYOUT_NAME$2 }, [el("style:page-layout-properties", {
2348
+ function buildPageLayout$3() {
2349
+ return el("style:page-layout", { "style:name": PAGE_LAYOUT_NAME$3 }, [el("style:page-layout-properties", {
2350
2350
  "fo:page-width": `${PAGE_SIZE_LETTER.widthPt}pt`,
2351
2351
  "fo:page-height": `${PAGE_SIZE_LETTER.heightPt}pt`,
2352
2352
  "fo:margin-top": `${DEFAULT_MARGIN_PT}pt`,
@@ -2355,44 +2355,44 @@ function buildPageLayout$2() {
2355
2355
  "fo:margin-left": `${DEFAULT_MARGIN_PT}pt`
2356
2356
  })]);
2357
2357
  }
2358
- function buildStylesXml$2() {
2358
+ function buildStylesXml$3() {
2359
2359
  return el("office:document-styles", {
2360
- ...xmlnsAttributes([...STYLES_NS_PREFIXES$2]),
2361
- "office:version": ODF_VERSION$2
2360
+ ...xmlnsAttributes([...STYLES_NS_PREFIXES$3]),
2361
+ "office:version": ODF_VERSION$3
2362
2362
  }, [
2363
2363
  el("office:styles"),
2364
- el("office:automatic-styles", {}, [buildPageLayout$2()]),
2364
+ el("office:automatic-styles", {}, [buildPageLayout$3()]),
2365
2365
  el("office:master-styles", {}, [el("style:master-page", {
2366
- "style:name": MASTER_PAGE_NAME$2,
2367
- "style:page-layout-name": PAGE_LAYOUT_NAME$2
2366
+ "style:name": MASTER_PAGE_NAME$3,
2367
+ "style:page-layout-name": PAGE_LAYOUT_NAME$3
2368
2368
  })])
2369
2369
  ]);
2370
2370
  }
2371
- function buildContentXml$2() {
2371
+ function buildContentXml$3() {
2372
2372
  return el("office:document-content", {
2373
- ...xmlnsAttributes([...CONTENT_NS_PREFIXES$2]),
2374
- "office:version": ODF_VERSION$2
2373
+ ...xmlnsAttributes([...CONTENT_NS_PREFIXES$3]),
2374
+ "office:version": ODF_VERSION$3
2375
2375
  }, [el("office:automatic-styles"), el("office:body", {}, [el("office:text")])]);
2376
2376
  }
2377
- function buildMetaXml$2() {
2377
+ function buildMetaXml$3() {
2378
2378
  return el("office:document-meta", {
2379
- ...xmlnsAttributes([...META_NS_PREFIXES$2]),
2380
- "office:version": ODF_VERSION$2
2379
+ ...xmlnsAttributes([...META_NS_PREFIXES$3]),
2380
+ "office:version": ODF_VERSION$3
2381
2381
  }, [el("office:meta")]);
2382
2382
  }
2383
2383
  function createEmptyOdtPackage() {
2384
2384
  const pkg = { parts: {
2385
2385
  "content.xml": {
2386
2386
  kind: "xml",
2387
- nodes: [declaration$2(), buildContentXml$2()]
2387
+ nodes: [declaration$3(), buildContentXml$3()]
2388
2388
  },
2389
2389
  "styles.xml": {
2390
2390
  kind: "xml",
2391
- nodes: [declaration$2(), buildStylesXml$2()]
2391
+ nodes: [declaration$3(), buildStylesXml$3()]
2392
2392
  },
2393
2393
  "meta.xml": {
2394
2394
  kind: "xml",
2395
- nodes: [declaration$2(), buildMetaXml$2()]
2395
+ nodes: [declaration$3(), buildMetaXml$3()]
2396
2396
  }
2397
2397
  } };
2398
2398
  setDocumentMediaType(pkg, ODF_MEDIA_TYPES.odt);
@@ -2513,20 +2513,20 @@ function buildTable(pkg, init) {
2513
2513
  }
2514
2514
  //#endregion
2515
2515
  //#region src/edit/odt/editor.ts
2516
- const CONTENT_PART_PATH$2 = "content.xml";
2516
+ const CONTENT_PART_PATH$3 = "content.xml";
2517
2517
  function findContentRoot(pkg) {
2518
- const part = pkg.parts[CONTENT_PART_PATH$2];
2518
+ const part = pkg.parts[CONTENT_PART_PATH$3];
2519
2519
  const root = part?.kind === "xml" ? part.nodes.find((n) => n.type === "element") : void 0;
2520
- if (root === void 0) throw new Error(`package has no root element at ${CONTENT_PART_PATH$2}`);
2520
+ if (root === void 0) throw new Error(`package has no root element at ${CONTENT_PART_PATH$3}`);
2521
2521
  return root;
2522
2522
  }
2523
- function directChild$4(parent, tag) {
2523
+ function directChild$5(parent, tag) {
2524
2524
  for (const child of parent.children) if (child.type === "element" && child.tag === tag) return child;
2525
2525
  }
2526
2526
  function findOfficeText(contentRoot) {
2527
- const body = directChild$4(contentRoot, "office:body");
2528
- const text = body === void 0 ? void 0 : directChild$4(body, "office:text");
2529
- if (text === void 0) throw new Error(`${CONTENT_PART_PATH$2} has no office:body/office:text element`);
2527
+ const body = directChild$5(contentRoot, "office:body");
2528
+ const text = body === void 0 ? void 0 : directChild$5(body, "office:text");
2529
+ if (text === void 0) throw new Error(`${CONTENT_PART_PATH$3} has no office:body/office:text element`);
2530
2530
  return text;
2531
2531
  }
2532
2532
  var OdtBodyImpl = class {
@@ -2658,7 +2658,7 @@ function appendBlock(body, block) {
2658
2658
  }
2659
2659
  //#endregion
2660
2660
  //#region src/edit/odp/scaffold.ts
2661
- const CONTENT_NS_PREFIXES$1 = [
2661
+ const CONTENT_NS_PREFIXES$2 = [
2662
2662
  "office",
2663
2663
  "style",
2664
2664
  "text",
@@ -2669,7 +2669,7 @@ const CONTENT_NS_PREFIXES$1 = [
2669
2669
  "svg",
2670
2670
  "xlink"
2671
2671
  ];
2672
- const STYLES_NS_PREFIXES$1 = [
2672
+ const STYLES_NS_PREFIXES$2 = [
2673
2673
  "office",
2674
2674
  "style",
2675
2675
  "text",
@@ -2680,14 +2680,14 @@ const STYLES_NS_PREFIXES$1 = [
2680
2680
  "svg",
2681
2681
  "xlink"
2682
2682
  ];
2683
- const META_NS_PREFIXES$1 = [
2683
+ const META_NS_PREFIXES$2 = [
2684
2684
  "office",
2685
2685
  "meta",
2686
2686
  "dc"
2687
2687
  ];
2688
- const ODF_VERSION$1 = "1.3";
2689
- const MASTER_PAGE_NAME$1 = "Standard";
2690
- function declaration$1() {
2688
+ const ODF_VERSION$2 = "1.3";
2689
+ const MASTER_PAGE_NAME$2 = "Standard";
2690
+ function declaration$2() {
2691
2691
  return {
2692
2692
  type: "declaration",
2693
2693
  attributes: [
@@ -2706,50 +2706,50 @@ function declaration$1() {
2706
2706
  ]
2707
2707
  };
2708
2708
  }
2709
- function buildPageLayout$1() {
2709
+ function buildPageLayout$2() {
2710
2710
  return el("style:page-layout", { "style:name": "PM1" }, [el("style:page-layout-properties", {
2711
2711
  "fo:page-width": `${SLIDE_SIZE_WIDESCREEN.widthPt}pt`,
2712
2712
  "fo:page-height": `${SLIDE_SIZE_WIDESCREEN.heightPt}pt`
2713
2713
  })]);
2714
2714
  }
2715
- function buildStylesXml$1() {
2715
+ function buildStylesXml$2() {
2716
2716
  return el("office:document-styles", {
2717
- ...xmlnsAttributes([...STYLES_NS_PREFIXES$1]),
2718
- "office:version": ODF_VERSION$1
2717
+ ...xmlnsAttributes([...STYLES_NS_PREFIXES$2]),
2718
+ "office:version": ODF_VERSION$2
2719
2719
  }, [
2720
2720
  el("office:styles"),
2721
- el("office:automatic-styles", {}, [buildPageLayout$1()]),
2721
+ el("office:automatic-styles", {}, [buildPageLayout$2()]),
2722
2722
  el("office:master-styles", {}, [el("style:master-page", {
2723
- "style:name": MASTER_PAGE_NAME$1,
2723
+ "style:name": MASTER_PAGE_NAME$2,
2724
2724
  "style:page-layout-name": "PM1"
2725
2725
  })])
2726
2726
  ]);
2727
2727
  }
2728
- function buildContentXml$1() {
2728
+ function buildContentXml$2() {
2729
2729
  return el("office:document-content", {
2730
- ...xmlnsAttributes([...CONTENT_NS_PREFIXES$1]),
2731
- "office:version": ODF_VERSION$1
2730
+ ...xmlnsAttributes([...CONTENT_NS_PREFIXES$2]),
2731
+ "office:version": ODF_VERSION$2
2732
2732
  }, [el("office:automatic-styles"), el("office:body", {}, [el("office:presentation")])]);
2733
2733
  }
2734
- function buildMetaXml$1() {
2734
+ function buildMetaXml$2() {
2735
2735
  return el("office:document-meta", {
2736
- ...xmlnsAttributes([...META_NS_PREFIXES$1]),
2737
- "office:version": ODF_VERSION$1
2736
+ ...xmlnsAttributes([...META_NS_PREFIXES$2]),
2737
+ "office:version": ODF_VERSION$2
2738
2738
  }, [el("office:meta")]);
2739
2739
  }
2740
2740
  function createEmptyOdpPackage() {
2741
2741
  const pkg = { parts: {
2742
2742
  "content.xml": {
2743
2743
  kind: "xml",
2744
- nodes: [declaration$1(), buildContentXml$1()]
2744
+ nodes: [declaration$2(), buildContentXml$2()]
2745
2745
  },
2746
2746
  "styles.xml": {
2747
2747
  kind: "xml",
2748
- nodes: [declaration$1(), buildStylesXml$1()]
2748
+ nodes: [declaration$2(), buildStylesXml$2()]
2749
2749
  },
2750
2750
  "meta.xml": {
2751
2751
  kind: "xml",
2752
- nodes: [declaration$1(), buildMetaXml$1()]
2752
+ nodes: [declaration$2(), buildMetaXml$2()]
2753
2753
  }
2754
2754
  } };
2755
2755
  setDocumentMediaType(pkg, ODF_MEDIA_TYPES.odp);
@@ -2789,7 +2789,7 @@ function addImageMedia(pkg, imageBytes, format) {
2789
2789
  }
2790
2790
  //#endregion
2791
2791
  //#region src/edit/odp/shape.ts
2792
- function directChild$3(parent, tag) {
2792
+ function directChild$4(parent, tag) {
2793
2793
  for (const child of parent.children) if (child.type === "element" && child.tag === tag) return child;
2794
2794
  }
2795
2795
  function buildTransformAttr(frame, rotationDeg) {
@@ -2857,7 +2857,7 @@ var OdpShape = class {
2857
2857
  }
2858
2858
  textBox(create) {
2859
2859
  const node = this.live();
2860
- const existing = directChild$3(node, "draw:text-box");
2860
+ const existing = directChild$4(node, "draw:text-box");
2861
2861
  if (existing !== void 0 || !create) return existing;
2862
2862
  const created = el("draw:text-box");
2863
2863
  node.children.push(created);
@@ -2918,7 +2918,7 @@ function insertImageFrameMedia(context, frame, image) {
2918
2918
  }
2919
2919
  //#endregion
2920
2920
  //#region src/edit/odp/slide.ts
2921
- function directChild$2(parent, tag) {
2921
+ function directChild$3(parent, tag) {
2922
2922
  for (const child of parent.children) if (child.type === "element" && child.tag === tag) return child;
2923
2923
  }
2924
2924
  const NOTES_FRAME_X_PT = 20;
@@ -2967,13 +2967,13 @@ var OdpSlide = class {
2967
2967
  return new OdpShape(node.children, frameElement, this.context.pkg);
2968
2968
  }
2969
2969
  get notes() {
2970
- const notesElement = directChild$2(this.live(), "presentation:notes");
2970
+ const notesElement = directChild$3(this.live(), "presentation:notes");
2971
2971
  if (notesElement === void 0) return "";
2972
2972
  return elementsWithTag$1(notesElement.children, "text:p").map((p) => decodeOdfText$1(p.children)).join("\n");
2973
2973
  }
2974
2974
  set notes(value) {
2975
2975
  const node = this.live();
2976
- const existing = directChild$2(node, "presentation:notes");
2976
+ const existing = directChild$3(node, "presentation:notes");
2977
2977
  const notesElement = buildNotesElement(this.context.pkg, value);
2978
2978
  if (existing === void 0) node.children.push(notesElement);
2979
2979
  else existing.children = notesElement.children;
@@ -2985,27 +2985,27 @@ var OdpSlide = class {
2985
2985
  };
2986
2986
  //#endregion
2987
2987
  //#region src/edit/odp/editor.ts
2988
- const CONTENT_PART_PATH$1 = "content.xml";
2989
- const STYLES_PART_PATH = "styles.xml";
2990
- function directChild$1(parent, tag) {
2988
+ const CONTENT_PART_PATH$2 = "content.xml";
2989
+ const STYLES_PART_PATH$1 = "styles.xml";
2990
+ function directChild$2(parent, tag) {
2991
2991
  for (const child of parent.children) if (child.type === "element" && child.tag === tag) return child;
2992
2992
  }
2993
- function findRoot$1(pkg, partPath) {
2993
+ function findRoot$2(pkg, partPath) {
2994
2994
  const part = pkg.parts[partPath];
2995
2995
  const root = part?.kind === "xml" ? part.nodes.find((n) => n.type === "element") : void 0;
2996
2996
  if (root === void 0) throw new Error(`package has no root element at ${partPath}`);
2997
2997
  return root;
2998
2998
  }
2999
2999
  function findOfficePresentation(pkg) {
3000
- const body = directChild$1(findRoot$1(pkg, CONTENT_PART_PATH$1), "office:body");
3001
- const presentation = body === void 0 ? void 0 : directChild$1(body, "office:presentation");
3002
- if (presentation === void 0) throw new Error(`${CONTENT_PART_PATH$1} has no office:body/office:presentation element`);
3000
+ const body = directChild$2(findRoot$2(pkg, CONTENT_PART_PATH$2), "office:body");
3001
+ const presentation = body === void 0 ? void 0 : directChild$2(body, "office:presentation");
3002
+ if (presentation === void 0) throw new Error(`${CONTENT_PART_PATH$2} has no office:body/office:presentation element`);
3003
3003
  return presentation;
3004
3004
  }
3005
- function findPageLayoutProperties(pkg) {
3006
- const pageLayout = directChild$1(findRoot$1(pkg, STYLES_PART_PATH), "office:automatic-styles")?.children.find((c) => c.type === "element" && c.tag === "style:page-layout" && attr$1(c, "style:name") === "PM1");
3007
- const properties = pageLayout === void 0 ? void 0 : directChild$1(pageLayout, "style:page-layout-properties");
3008
- if (properties === void 0) throw new Error(`${STYLES_PART_PATH} has no style:page-layout[style:name="PM1"]/style:page-layout-properties element`);
3005
+ function findPageLayoutProperties$1(pkg) {
3006
+ const pageLayout = directChild$2(findRoot$2(pkg, STYLES_PART_PATH$1), "office:automatic-styles")?.children.find((c) => c.type === "element" && c.tag === "style:page-layout" && attr$1(c, "style:name") === "PM1");
3007
+ const properties = pageLayout === void 0 ? void 0 : directChild$2(pageLayout, "style:page-layout-properties");
3008
+ if (properties === void 0) throw new Error(`${STYLES_PART_PATH$1} has no style:page-layout[style:name="PM1"]/style:page-layout-properties element`);
3009
3009
  return properties;
3010
3010
  }
3011
3011
  var OdpEditor = class {
@@ -3024,7 +3024,7 @@ var OdpEditor = class {
3024
3024
  }
3025
3025
  addSlide() {
3026
3026
  const presentation = findOfficePresentation(this.pkg);
3027
- const pageElement = el("draw:page", { "draw:master-page-name": MASTER_PAGE_NAME$1 });
3027
+ const pageElement = el("draw:page", { "draw:master-page-name": MASTER_PAGE_NAME$2 });
3028
3028
  presentation.children.push(pageElement);
3029
3029
  const context = { pkg: this.pkg };
3030
3030
  return new OdpSlide(presentation.children, pageElement, context);
@@ -3054,7 +3054,7 @@ var OdpEditor = class {
3054
3054
  presentation.children.splice(insertAt, 0, moved);
3055
3055
  }
3056
3056
  get slideSize() {
3057
- const properties = findPageLayoutProperties(this.pkg);
3057
+ const properties = findPageLayoutProperties$1(this.pkg);
3058
3058
  const widthValue = attr$1(properties, "fo:page-width");
3059
3059
  const heightValue = attr$1(properties, "fo:page-height");
3060
3060
  const widthPt = widthValue === void 0 ? void 0 : parseOdfLength(widthValue);
@@ -3065,7 +3065,7 @@ var OdpEditor = class {
3065
3065
  };
3066
3066
  }
3067
3067
  set slideSize(size) {
3068
- const properties = findPageLayoutProperties(this.pkg);
3068
+ const properties = findPageLayoutProperties$1(this.pkg);
3069
3069
  properties.attributes = [{
3070
3070
  name: "fo:page-width",
3071
3071
  value: formatOdfLength(size.widthPt)
@@ -3096,12 +3096,12 @@ function buildOdpPackage(content) {
3096
3096
  if (firstSlide !== void 0) editor.slideSize = firstSlide.size;
3097
3097
  for (const slide of content.slides) {
3098
3098
  const odpSlide = editor.addSlide();
3099
- for (const shape of slide.shapes) appendShape(odpSlide, shape);
3099
+ for (const shape of slide.shapes) appendShape$1(odpSlide, shape);
3100
3100
  if (slide.notes.length > 0) odpSlide.notes = slide.notes;
3101
3101
  }
3102
3102
  return editor.toPackage();
3103
3103
  }
3104
- function appendShape(slide, shape) {
3104
+ function appendShape$1(slide, shape) {
3105
3105
  const [onlyBlock] = shape.blocks;
3106
3106
  if (shape.blocks.length === 1 && onlyBlock?.kind === "image") {
3107
3107
  const imageShape = slide.addImage({
@@ -3126,31 +3126,31 @@ function appendShape(slide, shape) {
3126
3126
  }
3127
3127
  //#endregion
3128
3128
  //#region src/edit/ods/scaffold.ts
3129
- const CONTENT_NS_PREFIXES = [
3129
+ const CONTENT_NS_PREFIXES$1 = [
3130
3130
  "office",
3131
3131
  "style",
3132
3132
  "text",
3133
3133
  "table",
3134
3134
  "fo"
3135
3135
  ];
3136
- const STYLES_NS_PREFIXES = [
3136
+ const STYLES_NS_PREFIXES$1 = [
3137
3137
  "office",
3138
3138
  "style",
3139
3139
  "table",
3140
3140
  "fo"
3141
3141
  ];
3142
- const META_NS_PREFIXES = [
3142
+ const META_NS_PREFIXES$1 = [
3143
3143
  "office",
3144
3144
  "meta",
3145
3145
  "dc"
3146
3146
  ];
3147
3147
  const OF_NAMESPACE_ATTR = { "xmlns:of": "urn:oasis:names:tc:opendocument:xmlns:of:1.2" };
3148
- const ODF_VERSION = "1.3";
3149
- const MASTER_PAGE_NAME = "Standard";
3148
+ const ODF_VERSION$1 = "1.3";
3149
+ const MASTER_PAGE_NAME$1 = "Standard";
3150
3150
  const SHEET_TABLE_STYLE_NAME = "OdsTable";
3151
3151
  const DEFAULT_SHEET_NAME = "Sheet1";
3152
3152
  const DEFAULT_MARGIN = "2cm";
3153
- function declaration() {
3153
+ function declaration$1() {
3154
3154
  return {
3155
3155
  type: "declaration",
3156
3156
  attributes: [
@@ -3169,7 +3169,7 @@ function declaration() {
3169
3169
  ]
3170
3170
  };
3171
3171
  }
3172
- function buildPageLayout() {
3172
+ function buildPageLayout$1() {
3173
3173
  return el("style:page-layout", { "style:name": "PM1" }, [el("style:page-layout-properties", {
3174
3174
  "fo:page-width": `${PAGE_SIZE_A4.widthPt}pt`,
3175
3175
  "fo:page-height": `${PAGE_SIZE_A4.heightPt}pt`,
@@ -3179,15 +3179,15 @@ function buildPageLayout() {
3179
3179
  "fo:margin-left": DEFAULT_MARGIN
3180
3180
  })]);
3181
3181
  }
3182
- function buildStylesXml() {
3182
+ function buildStylesXml$1() {
3183
3183
  return el("office:document-styles", {
3184
- ...xmlnsAttributes([...STYLES_NS_PREFIXES]),
3185
- "office:version": ODF_VERSION
3184
+ ...xmlnsAttributes([...STYLES_NS_PREFIXES$1]),
3185
+ "office:version": ODF_VERSION$1
3186
3186
  }, [
3187
3187
  el("office:styles"),
3188
- el("office:automatic-styles", {}, [buildPageLayout()]),
3188
+ el("office:automatic-styles", {}, [buildPageLayout$1()]),
3189
3189
  el("office:master-styles", {}, [el("style:master-page", {
3190
- "style:name": MASTER_PAGE_NAME,
3190
+ "style:name": MASTER_PAGE_NAME$1,
3191
3191
  "style:page-layout-name": "PM1"
3192
3192
  })])
3193
3193
  ]);
@@ -3196,7 +3196,7 @@ function buildSheetTableStyle() {
3196
3196
  return el("style:style", {
3197
3197
  "style:name": SHEET_TABLE_STYLE_NAME,
3198
3198
  "style:family": "table",
3199
- "style:master-page-name": MASTER_PAGE_NAME
3199
+ "style:master-page-name": MASTER_PAGE_NAME$1
3200
3200
  });
3201
3201
  }
3202
3202
  function buildCalculationSettings() {
@@ -3207,36 +3207,36 @@ function buildCalculationSettings() {
3207
3207
  "table:null-year": "1950"
3208
3208
  });
3209
3209
  }
3210
- function buildContentXml() {
3210
+ function buildContentXml$1() {
3211
3211
  const table = el("table:table", {
3212
3212
  "table:name": DEFAULT_SHEET_NAME,
3213
3213
  "table:style-name": SHEET_TABLE_STYLE_NAME
3214
3214
  });
3215
3215
  return el("office:document-content", {
3216
- ...xmlnsAttributes([...CONTENT_NS_PREFIXES]),
3216
+ ...xmlnsAttributes([...CONTENT_NS_PREFIXES$1]),
3217
3217
  ...OF_NAMESPACE_ATTR,
3218
- "office:version": ODF_VERSION
3218
+ "office:version": ODF_VERSION$1
3219
3219
  }, [el("office:automatic-styles", {}, [buildSheetTableStyle()]), el("office:body", {}, [el("office:spreadsheet", {}, [buildCalculationSettings(), table])])]);
3220
3220
  }
3221
- function buildMetaXml() {
3221
+ function buildMetaXml$1() {
3222
3222
  return el("office:document-meta", {
3223
- ...xmlnsAttributes([...META_NS_PREFIXES]),
3224
- "office:version": ODF_VERSION
3223
+ ...xmlnsAttributes([...META_NS_PREFIXES$1]),
3224
+ "office:version": ODF_VERSION$1
3225
3225
  }, [el("office:meta")]);
3226
3226
  }
3227
3227
  function createEmptyOdsPackage() {
3228
3228
  const pkg = { parts: {
3229
3229
  "content.xml": {
3230
3230
  kind: "xml",
3231
- nodes: [declaration(), buildContentXml()]
3231
+ nodes: [declaration$1(), buildContentXml$1()]
3232
3232
  },
3233
3233
  "styles.xml": {
3234
3234
  kind: "xml",
3235
- nodes: [declaration(), buildStylesXml()]
3235
+ nodes: [declaration$1(), buildStylesXml$1()]
3236
3236
  },
3237
3237
  "meta.xml": {
3238
3238
  kind: "xml",
3239
- nodes: [declaration(), buildMetaXml()]
3239
+ nodes: [declaration$1(), buildMetaXml$1()]
3240
3240
  }
3241
3241
  } };
3242
3242
  setDocumentMediaType(pkg, ODF_MEDIA_TYPES.ods);
@@ -3564,20 +3564,20 @@ var OdsSheet = class {
3564
3564
  };
3565
3565
  //#endregion
3566
3566
  //#region src/edit/ods/editor.ts
3567
- const CONTENT_PART_PATH = "content.xml";
3568
- function directChild(parent, tag) {
3567
+ const CONTENT_PART_PATH$1 = "content.xml";
3568
+ function directChild$1(parent, tag) {
3569
3569
  for (const child of parent.children) if (child.type === "element" && child.tag === tag) return child;
3570
3570
  }
3571
- function findRoot(pkg) {
3572
- const part = pkg.parts[CONTENT_PART_PATH];
3571
+ function findRoot$1(pkg) {
3572
+ const part = pkg.parts[CONTENT_PART_PATH$1];
3573
3573
  const root = part?.kind === "xml" ? part.nodes.find((n) => n.type === "element") : void 0;
3574
- if (root === void 0) throw new Error(`package has no root element at ${CONTENT_PART_PATH}`);
3574
+ if (root === void 0) throw new Error(`package has no root element at ${CONTENT_PART_PATH$1}`);
3575
3575
  return root;
3576
3576
  }
3577
3577
  function findOfficeSpreadsheet(pkg) {
3578
- const body = directChild(findRoot(pkg), "office:body");
3579
- const spreadsheet = body === void 0 ? void 0 : directChild(body, "office:spreadsheet");
3580
- if (spreadsheet === void 0) throw new Error(`${CONTENT_PART_PATH} has no office:body/office:spreadsheet element`);
3578
+ const body = directChild$1(findRoot$1(pkg), "office:body");
3579
+ const spreadsheet = body === void 0 ? void 0 : directChild$1(body, "office:spreadsheet");
3580
+ if (spreadsheet === void 0) throw new Error(`${CONTENT_PART_PATH$1} has no office:body/office:spreadsheet element`);
3581
3581
  return spreadsheet;
3582
3582
  }
3583
3583
  function ensureSheetTableStyleName(pkg) {
@@ -3586,7 +3586,7 @@ function ensureSheetTableStyleName(pkg) {
3586
3586
  automaticStyles.children.push(el("style:style", {
3587
3587
  "style:name": SHEET_TABLE_STYLE_NAME,
3588
3588
  "style:family": "table",
3589
- "style:master-page-name": MASTER_PAGE_NAME
3589
+ "style:master-page-name": MASTER_PAGE_NAME$1
3590
3590
  }));
3591
3591
  return SHEET_TABLE_STYLE_NAME;
3592
3592
  }
@@ -3658,6 +3658,598 @@ function appendCell(odsSheet, cell) {
3658
3658
  if (rowSpan > 1 || colSpan > 1) odsSheet.mergeCells(cell.row, cell.column, rowSpan, colSpan);
3659
3659
  }
3660
3660
  //#endregion
3661
+ //#region src/edit/odg/scaffold.ts
3662
+ const CONTENT_NS_PREFIXES = [
3663
+ "office",
3664
+ "style",
3665
+ "text",
3666
+ "table",
3667
+ "draw",
3668
+ "fo",
3669
+ "svg",
3670
+ "xlink"
3671
+ ];
3672
+ const STYLES_NS_PREFIXES = [
3673
+ "office",
3674
+ "style",
3675
+ "text",
3676
+ "table",
3677
+ "draw",
3678
+ "fo",
3679
+ "svg",
3680
+ "xlink"
3681
+ ];
3682
+ const META_NS_PREFIXES = [
3683
+ "office",
3684
+ "meta",
3685
+ "dc"
3686
+ ];
3687
+ const ODF_VERSION = "1.3";
3688
+ const MASTER_PAGE_NAME = "Standard";
3689
+ function declaration() {
3690
+ return {
3691
+ type: "declaration",
3692
+ attributes: [
3693
+ {
3694
+ name: "version",
3695
+ value: "1.0"
3696
+ },
3697
+ {
3698
+ name: "encoding",
3699
+ value: "UTF-8"
3700
+ },
3701
+ {
3702
+ name: "standalone",
3703
+ value: "yes"
3704
+ }
3705
+ ]
3706
+ };
3707
+ }
3708
+ function buildPageLayout() {
3709
+ return el("style:page-layout", { "style:name": "PM1" }, [el("style:page-layout-properties", {
3710
+ "fo:page-width": `${PAGE_SIZE_A4.widthPt}pt`,
3711
+ "fo:page-height": `${PAGE_SIZE_A4.heightPt}pt`
3712
+ })]);
3713
+ }
3714
+ function buildStylesXml() {
3715
+ return el("office:document-styles", {
3716
+ ...xmlnsAttributes([...STYLES_NS_PREFIXES]),
3717
+ "office:version": ODF_VERSION
3718
+ }, [
3719
+ el("office:styles"),
3720
+ el("office:automatic-styles", {}, [buildPageLayout()]),
3721
+ el("office:master-styles", {}, [el("style:master-page", {
3722
+ "style:name": MASTER_PAGE_NAME,
3723
+ "style:page-layout-name": "PM1"
3724
+ })])
3725
+ ]);
3726
+ }
3727
+ function buildContentXml() {
3728
+ return el("office:document-content", {
3729
+ ...xmlnsAttributes([...CONTENT_NS_PREFIXES]),
3730
+ "office:version": ODF_VERSION
3731
+ }, [el("office:automatic-styles"), el("office:body", {}, [el("office:drawing")])]);
3732
+ }
3733
+ function buildMetaXml() {
3734
+ return el("office:document-meta", {
3735
+ ...xmlnsAttributes([...META_NS_PREFIXES]),
3736
+ "office:version": ODF_VERSION
3737
+ }, [el("office:meta")]);
3738
+ }
3739
+ function createEmptyOdgPackage() {
3740
+ const pkg = { parts: {
3741
+ "content.xml": {
3742
+ kind: "xml",
3743
+ nodes: [declaration(), buildContentXml()]
3744
+ },
3745
+ "styles.xml": {
3746
+ kind: "xml",
3747
+ nodes: [declaration(), buildStylesXml()]
3748
+ },
3749
+ "meta.xml": {
3750
+ kind: "xml",
3751
+ nodes: [declaration(), buildMetaXml()]
3752
+ }
3753
+ } };
3754
+ setDocumentMediaType(pkg, ODF_MEDIA_TYPES.odg);
3755
+ syncManifest(pkg);
3756
+ return pkg;
3757
+ }
3758
+ //#endregion
3759
+ //#region src/edit/odg/style.ts
3760
+ const GRAPHIC_STYLE_PREFIX = "gr";
3761
+ function graphicPropertyAttrs(init) {
3762
+ const attrs = {};
3763
+ if (init.fill === void 0) attrs["draw:fill"] = "none";
3764
+ else attrs["draw:fill-color"] = formatOdfColor(init.fill);
3765
+ if (init.stroke === void 0) attrs["draw:stroke"] = "none";
3766
+ else {
3767
+ attrs["svg:stroke-color"] = formatOdfColor(init.stroke.color);
3768
+ attrs["svg:stroke-width"] = formatOdfLength(init.stroke.widthPt);
3769
+ }
3770
+ return attrs;
3771
+ }
3772
+ function buildGraphicStyle(pkg, init) {
3773
+ const automaticStyles = ensureAutomaticStyles(pkg);
3774
+ const name = nextStyleName(automaticStyles, "style:style", GRAPHIC_STYLE_PREFIX);
3775
+ automaticStyles.children.push(el("style:style", {
3776
+ "style:name": name,
3777
+ "style:family": "graphic"
3778
+ }, [el("style:graphic-properties", graphicPropertyAttrs(init))]));
3779
+ return name;
3780
+ }
3781
+ function findAutomaticStylesReadOnly(pkg) {
3782
+ const part = pkg.parts["content.xml"];
3783
+ const root = part?.kind === "xml" ? part.nodes.find((n) => n.type === "element") : void 0;
3784
+ if (root === void 0) return;
3785
+ for (const child of root.children) if (child.type === "element" && child.tag === "office:automatic-styles") return child;
3786
+ }
3787
+ function findGraphicStyle(pkg, element) {
3788
+ const styleName = attr$1(element, "draw:style-name");
3789
+ if (styleName === void 0) return;
3790
+ return findAutomaticStylesReadOnly(pkg)?.children.find((c) => c.type === "element" && c.tag === "style:style" && attr$1(c, "style:name") === styleName);
3791
+ }
3792
+ function graphicProperties(pkg, element) {
3793
+ return findGraphicStyle(pkg, element)?.children.find((c) => c.type === "element" && c.tag === "style:graphic-properties");
3794
+ }
3795
+ function readGraphicFill(pkg, element) {
3796
+ const props = graphicProperties(pkg, element);
3797
+ if (props === void 0 || attr$1(props, "draw:fill") === "none") return;
3798
+ const value = attr$1(props, "draw:fill-color");
3799
+ return value === void 0 ? void 0 : parseOdfColor(value);
3800
+ }
3801
+ function readGraphicStroke(pkg, element) {
3802
+ const props = graphicProperties(pkg, element);
3803
+ if (props === void 0 || attr$1(props, "draw:stroke") === "none") return;
3804
+ const colorValue = attr$1(props, "svg:stroke-color");
3805
+ const widthValue = attr$1(props, "svg:stroke-width");
3806
+ const color = colorValue === void 0 ? void 0 : parseOdfColor(colorValue);
3807
+ const widthPt = widthValue === void 0 ? void 0 : parseOdfLength(widthValue);
3808
+ return color === void 0 || widthPt === void 0 ? void 0 : {
3809
+ color,
3810
+ widthPt
3811
+ };
3812
+ }
3813
+ function setGraphicFill(pkg, element, fill) {
3814
+ setAttr(element, "draw:style-name", buildGraphicStyle(pkg, {
3815
+ fill,
3816
+ stroke: readGraphicStroke(pkg, element)
3817
+ }));
3818
+ }
3819
+ function setGraphicStroke(pkg, element, stroke) {
3820
+ setAttr(element, "draw:style-name", buildGraphicStyle(pkg, {
3821
+ fill: readGraphicFill(pkg, element),
3822
+ stroke
3823
+ }));
3824
+ }
3825
+ //#endregion
3826
+ //#region src/edit/odg/svg-path.ts
3827
+ const PATH_NUMBER_DECIMALS = 6;
3828
+ const PATH_NUMBER_SCALE = 10 ** PATH_NUMBER_DECIMALS;
3829
+ function formatPathNumber(value) {
3830
+ if (!Number.isFinite(value)) throw new Error(`cannot format a non-finite path coordinate: ${value}`);
3831
+ const rounded = Math.round(value * PATH_NUMBER_SCALE) / PATH_NUMBER_SCALE;
3832
+ if (rounded === 0) return "0";
3833
+ return rounded.toFixed(PATH_NUMBER_DECIMALS).replace(/0+$/, "").replace(/\.$/, "");
3834
+ }
3835
+ function formatPathPoint(point) {
3836
+ return `${formatPathNumber(point.xPt)} ${formatPathNumber(point.yPt)}`;
3837
+ }
3838
+ function buildSvgPathData(subpaths) {
3839
+ const commands = [];
3840
+ for (const subpath of subpaths) {
3841
+ commands.push(`M${formatPathPoint(subpath.start)}`);
3842
+ for (const segment of subpath.segments) if (segment.kind === "line") commands.push(`L${formatPathPoint(segment.to)}`);
3843
+ else commands.push(`C${formatPathPoint(segment.control1)} ${formatPathPoint(segment.control2)} ${formatPathPoint(segment.to)}`);
3844
+ if (subpath.closed) commands.push("Z");
3845
+ }
3846
+ return commands.join(" ");
3847
+ }
3848
+ function buildSvgViewBox(widthPt, heightPt) {
3849
+ return `0 0 ${formatPathNumber(widthPt)} ${formatPathNumber(heightPt)}`;
3850
+ }
3851
+ //#endregion
3852
+ //#region src/edit/odg/vector.ts
3853
+ function directTextP() {
3854
+ return el("text:p");
3855
+ }
3856
+ function buildBoxVectorElement(pkg, tag, init) {
3857
+ return el(tag, {
3858
+ "draw:style-name": buildGraphicStyle(pkg, {
3859
+ fill: init.fill,
3860
+ stroke: init.stroke
3861
+ }),
3862
+ "svg:x": formatOdfLength(init.frame.xPt),
3863
+ "svg:y": formatOdfLength(init.frame.yPt),
3864
+ "svg:width": formatOdfLength(init.frame.widthPt),
3865
+ "svg:height": formatOdfLength(init.frame.heightPt)
3866
+ }, [directTextP()]);
3867
+ }
3868
+ function buildRectElement(pkg, init) {
3869
+ return buildBoxVectorElement(pkg, "draw:rect", init);
3870
+ }
3871
+ function buildEllipseElement(pkg, init) {
3872
+ return buildBoxVectorElement(pkg, "draw:ellipse", init);
3873
+ }
3874
+ var OdgBoxVector = class {
3875
+ container;
3876
+ node;
3877
+ pkg;
3878
+ removed = false;
3879
+ constructor(container, node, pkg) {
3880
+ this.container = container;
3881
+ this.node = node;
3882
+ this.pkg = pkg;
3883
+ }
3884
+ live() {
3885
+ if (this.removed) throw new Error("this OdgBoxVector has been removed from its page and can no longer be used");
3886
+ return this.node;
3887
+ }
3888
+ get kind() {
3889
+ return this.live().tag === "draw:ellipse" ? "ellipse" : "rect";
3890
+ }
3891
+ get name() {
3892
+ return attr$1(this.live(), "draw:name");
3893
+ }
3894
+ get frame() {
3895
+ return parseBox(this.live());
3896
+ }
3897
+ set frame(value) {
3898
+ const node = this.live();
3899
+ setAttr(node, "svg:x", formatOdfLength(value.xPt));
3900
+ setAttr(node, "svg:y", formatOdfLength(value.yPt));
3901
+ setAttr(node, "svg:width", formatOdfLength(value.widthPt));
3902
+ setAttr(node, "svg:height", formatOdfLength(value.heightPt));
3903
+ }
3904
+ get fill() {
3905
+ return readGraphicFill(this.pkg, this.live());
3906
+ }
3907
+ set fill(value) {
3908
+ setGraphicFill(this.pkg, this.live(), value);
3909
+ }
3910
+ get stroke() {
3911
+ return readGraphicStroke(this.pkg, this.live());
3912
+ }
3913
+ set stroke(value) {
3914
+ setGraphicStroke(this.pkg, this.live(), value);
3915
+ }
3916
+ remove() {
3917
+ removeChild(this.container, this.live());
3918
+ this.removed = true;
3919
+ }
3920
+ };
3921
+ function buildLineElement(pkg, init) {
3922
+ return el("draw:line", {
3923
+ "draw:style-name": buildGraphicStyle(pkg, { stroke: init.stroke }),
3924
+ "svg:x1": formatOdfLength(init.from.xPt),
3925
+ "svg:y1": formatOdfLength(init.from.yPt),
3926
+ "svg:x2": formatOdfLength(init.to.xPt),
3927
+ "svg:y2": formatOdfLength(init.to.yPt)
3928
+ }, [directTextP()]);
3929
+ }
3930
+ var OdgLineVector = class {
3931
+ container;
3932
+ node;
3933
+ pkg;
3934
+ removed = false;
3935
+ constructor(container, node, pkg) {
3936
+ this.container = container;
3937
+ this.node = node;
3938
+ this.pkg = pkg;
3939
+ }
3940
+ live() {
3941
+ if (this.removed) throw new Error("this OdgLineVector has been removed from its page and can no longer be used");
3942
+ return this.node;
3943
+ }
3944
+ get name() {
3945
+ return attr$1(this.live(), "draw:name");
3946
+ }
3947
+ get from() {
3948
+ return parseLinePoints(this.live())?.from;
3949
+ }
3950
+ set from(value) {
3951
+ const node = this.live();
3952
+ setAttr(node, "svg:x1", formatOdfLength(value.xPt));
3953
+ setAttr(node, "svg:y1", formatOdfLength(value.yPt));
3954
+ }
3955
+ get to() {
3956
+ return parseLinePoints(this.live())?.to;
3957
+ }
3958
+ set to(value) {
3959
+ const node = this.live();
3960
+ setAttr(node, "svg:x2", formatOdfLength(value.xPt));
3961
+ setAttr(node, "svg:y2", formatOdfLength(value.yPt));
3962
+ }
3963
+ get stroke() {
3964
+ return readGraphicStroke(this.pkg, this.live());
3965
+ }
3966
+ set stroke(value) {
3967
+ setGraphicStroke(this.pkg, this.live(), value);
3968
+ }
3969
+ remove() {
3970
+ removeChild(this.container, this.live());
3971
+ this.removed = true;
3972
+ }
3973
+ };
3974
+ function buildPathElement(pkg, init) {
3975
+ return el("draw:path", {
3976
+ "draw:style-name": buildGraphicStyle(pkg, {
3977
+ fill: init.fill,
3978
+ stroke: init.stroke
3979
+ }),
3980
+ "svg:x": formatOdfLength(init.frame.xPt),
3981
+ "svg:y": formatOdfLength(init.frame.yPt),
3982
+ "svg:width": formatOdfLength(init.frame.widthPt),
3983
+ "svg:height": formatOdfLength(init.frame.heightPt),
3984
+ "svg:viewBox": buildSvgViewBox(init.frame.widthPt, init.frame.heightPt),
3985
+ "svg:d": buildSvgPathData(init.subpaths)
3986
+ }, [directTextP()]);
3987
+ }
3988
+ var OdgPathVector = class {
3989
+ container;
3990
+ node;
3991
+ pkg;
3992
+ removed = false;
3993
+ constructor(container, node, pkg) {
3994
+ this.container = container;
3995
+ this.node = node;
3996
+ this.pkg = pkg;
3997
+ }
3998
+ live() {
3999
+ if (this.removed) throw new Error("this OdgPathVector has been removed from its page and can no longer be used");
4000
+ return this.node;
4001
+ }
4002
+ get name() {
4003
+ return attr$1(this.live(), "draw:name");
4004
+ }
4005
+ get frame() {
4006
+ return parseBox(this.live());
4007
+ }
4008
+ set frame(value) {
4009
+ const node = this.live();
4010
+ setAttr(node, "svg:x", formatOdfLength(value.xPt));
4011
+ setAttr(node, "svg:y", formatOdfLength(value.yPt));
4012
+ setAttr(node, "svg:width", formatOdfLength(value.widthPt));
4013
+ setAttr(node, "svg:height", formatOdfLength(value.heightPt));
4014
+ }
4015
+ get fill() {
4016
+ return readGraphicFill(this.pkg, this.live());
4017
+ }
4018
+ set fill(value) {
4019
+ setGraphicFill(this.pkg, this.live(), value);
4020
+ }
4021
+ get stroke() {
4022
+ return readGraphicStroke(this.pkg, this.live());
4023
+ }
4024
+ set stroke(value) {
4025
+ setGraphicStroke(this.pkg, this.live(), value);
4026
+ }
4027
+ get subpaths() {
4028
+ const node = this.live();
4029
+ const viewBoxValue = attr$1(node, "svg:viewBox");
4030
+ const dValue = attr$1(node, "svg:d");
4031
+ const frame = parseBox(node);
4032
+ if (viewBoxValue === void 0 || dValue === void 0 || frame === void 0) return [];
4033
+ const viewBox = parseOdfViewBox(viewBoxValue);
4034
+ if (viewBox === void 0) return [];
4035
+ return buildOdfSubpaths(parseOdfPathData(dValue), viewBox, frame);
4036
+ }
4037
+ remove() {
4038
+ removeChild(this.container, this.live());
4039
+ this.removed = true;
4040
+ }
4041
+ };
4042
+ //#endregion
4043
+ //#region src/edit/odg/page.ts
4044
+ var OdgPage = class {
4045
+ container;
4046
+ node;
4047
+ context;
4048
+ removed = false;
4049
+ constructor(container, node, context) {
4050
+ this.container = container;
4051
+ this.node = node;
4052
+ this.context = context;
4053
+ }
4054
+ live() {
4055
+ if (this.removed) throw new Error("this OdgPage has been removed from the drawing and can no longer be used");
4056
+ return this.node;
4057
+ }
4058
+ shapes() {
4059
+ const node = this.live();
4060
+ const out = [];
4061
+ for (const child of node.children) if (child.type === "element" && child.tag === "draw:frame") out.push(new OdpShape(node.children, child, this.context.pkg));
4062
+ return out;
4063
+ }
4064
+ addTextBox(init) {
4065
+ const node = this.live();
4066
+ const frameElement = buildTextBoxFrame(this.context.pkg, init.frame, init.text);
4067
+ node.children.push(frameElement);
4068
+ return new OdpShape(node.children, frameElement, this.context.pkg);
4069
+ }
4070
+ addImage(init) {
4071
+ const node = this.live();
4072
+ const frameElement = insertImageFrameMedia({ pkg: this.context.pkg }, init.frame, init);
4073
+ node.children.push(frameElement);
4074
+ return new OdpShape(node.children, frameElement, this.context.pkg);
4075
+ }
4076
+ addRect(init) {
4077
+ const node = this.live();
4078
+ const element = buildRectElement(this.context.pkg, init);
4079
+ node.children.push(element);
4080
+ return new OdgBoxVector(node.children, element, this.context.pkg);
4081
+ }
4082
+ addEllipse(init) {
4083
+ const node = this.live();
4084
+ const element = buildEllipseElement(this.context.pkg, init);
4085
+ node.children.push(element);
4086
+ return new OdgBoxVector(node.children, element, this.context.pkg);
4087
+ }
4088
+ addLine(init) {
4089
+ const node = this.live();
4090
+ const element = buildLineElement(this.context.pkg, init);
4091
+ node.children.push(element);
4092
+ return new OdgLineVector(node.children, element, this.context.pkg);
4093
+ }
4094
+ addPath(init) {
4095
+ const node = this.live();
4096
+ const element = buildPathElement(this.context.pkg, init);
4097
+ node.children.push(element);
4098
+ return new OdgPathVector(node.children, element, this.context.pkg);
4099
+ }
4100
+ remove() {
4101
+ removeChild(this.container, this.live());
4102
+ this.removed = true;
4103
+ }
4104
+ };
4105
+ //#endregion
4106
+ //#region src/edit/odg/editor.ts
4107
+ const CONTENT_PART_PATH = "content.xml";
4108
+ const STYLES_PART_PATH = "styles.xml";
4109
+ function directChild(parent, tag) {
4110
+ for (const child of parent.children) if (child.type === "element" && child.tag === tag) return child;
4111
+ }
4112
+ function findRoot(pkg, partPath) {
4113
+ const part = pkg.parts[partPath];
4114
+ const root = part?.kind === "xml" ? part.nodes.find((n) => n.type === "element") : void 0;
4115
+ if (root === void 0) throw new Error(`package has no root element at ${partPath}`);
4116
+ return root;
4117
+ }
4118
+ function findOfficeDrawing(pkg) {
4119
+ const body = directChild(findRoot(pkg, CONTENT_PART_PATH), "office:body");
4120
+ const drawing = body === void 0 ? void 0 : directChild(body, "office:drawing");
4121
+ if (drawing === void 0) throw new Error(`${CONTENT_PART_PATH} has no office:body/office:drawing element`);
4122
+ return drawing;
4123
+ }
4124
+ function findPageLayoutProperties(pkg) {
4125
+ 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");
4126
+ const properties = pageLayout === void 0 ? void 0 : directChild(pageLayout, "style:page-layout-properties");
4127
+ if (properties === void 0) throw new Error(`${STYLES_PART_PATH} has no style:page-layout[style:name="PM1"]/style:page-layout-properties element`);
4128
+ return properties;
4129
+ }
4130
+ var OdgEditor = class {
4131
+ pkg;
4132
+ constructor(pkg) {
4133
+ this.pkg = pkg;
4134
+ }
4135
+ pages() {
4136
+ const drawing = findOfficeDrawing(this.pkg);
4137
+ const out = [];
4138
+ for (const child of drawing.children) if (child.type === "element" && child.tag === "draw:page") {
4139
+ const context = { pkg: this.pkg };
4140
+ out.push(new OdgPage(drawing.children, child, context));
4141
+ }
4142
+ return out;
4143
+ }
4144
+ addPage() {
4145
+ const drawing = findOfficeDrawing(this.pkg);
4146
+ const pageElement = el("draw:page", { "draw:master-page-name": MASTER_PAGE_NAME });
4147
+ drawing.children.push(pageElement);
4148
+ const context = { pkg: this.pkg };
4149
+ return new OdgPage(drawing.children, pageElement, context);
4150
+ }
4151
+ removePageAt(index) {
4152
+ const drawing = findOfficeDrawing(this.pkg);
4153
+ const target = drawing.children.filter((c) => c.type === "element" && c.tag === "draw:page")[index];
4154
+ if (target === void 0) throw new Error(`page index ${index} does not exist`);
4155
+ const listIndex = drawing.children.indexOf(target);
4156
+ drawing.children.splice(listIndex, 1);
4157
+ }
4158
+ get pageSize() {
4159
+ const properties = findPageLayoutProperties(this.pkg);
4160
+ const widthValue = attr$1(properties, "fo:page-width");
4161
+ const heightValue = attr$1(properties, "fo:page-height");
4162
+ const widthPt = widthValue === void 0 ? void 0 : parseOdfLength(widthValue);
4163
+ const heightPt = heightValue === void 0 ? void 0 : parseOdfLength(heightValue);
4164
+ return {
4165
+ widthPt: widthPt ?? 0,
4166
+ heightPt: heightPt ?? 0
4167
+ };
4168
+ }
4169
+ set pageSize(size) {
4170
+ const properties = findPageLayoutProperties(this.pkg);
4171
+ properties.attributes = [{
4172
+ name: "fo:page-width",
4173
+ value: formatOdfLength(size.widthPt)
4174
+ }, {
4175
+ name: "fo:page-height",
4176
+ value: formatOdfLength(size.heightPt)
4177
+ }];
4178
+ }
4179
+ toPackage() {
4180
+ return this.pkg;
4181
+ }
4182
+ toBytes() {
4183
+ return encodePackage$2(this.pkg);
4184
+ }
4185
+ };
4186
+ function openOdg(bytes) {
4187
+ return new OdgEditor(decodePackage$2(bytes));
4188
+ }
4189
+ function createOdg() {
4190
+ return new OdgEditor(createEmptyOdgPackage());
4191
+ }
4192
+ //#endregion
4193
+ //#region src/edit/odg/content.ts
4194
+ function buildOdgPackage(content) {
4195
+ if (content.kind !== "drawing") throw new Error("buildOdgPackage requires a drawing ContentDocument");
4196
+ const editor = createOdg();
4197
+ const firstPage = content.pages[0];
4198
+ if (firstPage !== void 0) editor.pageSize = firstPage.size;
4199
+ for (const page of content.pages) {
4200
+ const odgPage = editor.addPage();
4201
+ for (const vector of page.vectors) appendVector(odgPage, vector);
4202
+ for (const shape of page.shapes) appendShape(odgPage, shape);
4203
+ }
4204
+ return editor.toPackage();
4205
+ }
4206
+ function appendVector(page, vector) {
4207
+ if (vector.kind === "rect") page.addRect({
4208
+ frame: vector.frame,
4209
+ fill: vector.fill,
4210
+ stroke: vector.stroke
4211
+ });
4212
+ else if (vector.kind === "ellipse") page.addEllipse({
4213
+ frame: vector.frame,
4214
+ fill: vector.fill,
4215
+ stroke: vector.stroke
4216
+ });
4217
+ else if (vector.kind === "line") page.addLine({
4218
+ from: vector.from,
4219
+ to: vector.to,
4220
+ stroke: vector.stroke
4221
+ });
4222
+ else page.addPath({
4223
+ frame: vector.frame,
4224
+ subpaths: vector.subpaths,
4225
+ fill: vector.fill,
4226
+ stroke: vector.stroke
4227
+ });
4228
+ }
4229
+ function appendShape(page, shape) {
4230
+ const [onlyBlock] = shape.blocks;
4231
+ if (shape.blocks.length === 1 && onlyBlock?.kind === "image") {
4232
+ const imageShape = page.addImage({
4233
+ frame: shape.frame,
4234
+ format: onlyBlock.format,
4235
+ bytes: base64ToBytes$2(onlyBlock.base64),
4236
+ altText: onlyBlock.altText
4237
+ });
4238
+ if (shape.rotationDeg !== void 0) imageShape.rotationDeg = shape.rotationDeg;
4239
+ return;
4240
+ }
4241
+ const textShape = page.addTextBox({
4242
+ frame: shape.frame,
4243
+ text: ""
4244
+ });
4245
+ if (shape.rotationDeg !== void 0) textShape.rotationDeg = shape.rotationDeg;
4246
+ textShape.paragraphs()[0]?.remove();
4247
+ for (const block of shape.blocks) {
4248
+ if (block.kind !== "paragraph") continue;
4249
+ populateParagraph(textShape.appendParagraph(), block);
4250
+ }
4251
+ }
4252
+ //#endregion
3661
4253
  //#region src/bytes/crc32.ts
3662
4254
  const CRC32_POLYNOMIAL = 3988292384;
3663
4255
  const BYTE_VALUES = 256;
@@ -10286,4 +10878,4 @@ function fixedClock(date) {
10286
10878
  return { now: () => date };
10287
10879
  }
10288
10880
  //#endregion
10289
- export { AttributeSchema, BinaryPartSchema, COLOR_BLACK, CONTENT_FORMAT_VERSION, CommentSchema, CompactPackageSchema, CompactPartSchema, CompactXmlNodeSchema, ContentBlockSchema, ContentCellValueSchema, ContentDocumentSchema, ContentDrawPageSchema, ContentImageBlockSchema, ContentPageBreakSchema, ContentParagraphSchema, ContentPathPointSchema, ContentPathSegmentSchema, ContentRunSchema, ContentSectionSchema, ContentShapeSchema, ContentSheetCellSchema, ContentSheetColumnSchema, ContentSheetPrintRangeSchema, ContentSheetPrintSettingsSchema, ContentSheetRepeatRangeSchema, ContentSheetRowSchema, ContentSheetSchema, ContentSlideSchema, ContentStrokeSchema, ContentSubpathSchema, ContentTableCellSchema, ContentTableRowSchema, ContentTableSchema, ContentVectorSchema, DEFAULT_LAYOUT_FONT, DefinedNameSchema, DocxBytesSchema, DocxEditor, DocxParagraph, DocxRun, DocxTable, DocxTableCell, DocxTableRow, LAYOUT_FORMAT_VERSION, NOOP_DIAGNOSTIC_SINK, OdgBytesSchema, OdpBytesSchema, OdpEditor, OdpShape, OdpSlide, OdsBytesSchema, OdsCell, OdsEditor, OdsSheet, 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, buildOdsPackage, buildOdtPackage, buildPptxPackage, buildXml, bytesToBase64, childrenWithTag, compactCodec, compactPackageCodec, convertDrawingToLayout, convertPresentationToLayout, convertSpreadsheetToLayout, convertWordprocessingToLayout, createDocx, createLocalDocumentConverter, createOdp, createOds, createOdt, createPptx, decodeCompactPackage, decodeEntities, decodePackage, docxPdfCodec, docxToPdf, elementsWithTag, encodeCompactPackage, encodePackage, fixedClock, flipY, fromCompact, isCompactXmlNode, isContentBlock, isXmlNode, odgToPdf, odpPdfCodec, odpToPdf, odsToPdf, odtPdfCodec, odtToPdf, openDocx, openOdp, openOds, openOdt, openPptx, packageCodec, parsePackage, parseXml, pdfCodec, pdfToDocx, pdfToOdp, pdfToOdt, pdfToPptx, pptxPdfCodec, pptxToPdf, readDocxContent, readOdgContent, readOdpContent, readOdsContent, readOdtContent, readPdf, readPptxContent, reconstructPresentation, reconstructWordprocessing, resolveRelationships, rgbHexToColor, rootElement, serializePackage, systemClock, textContent, throwIfAborted, toCompact, unzipPackage, walk, writePdf, xmlCodec, zipPackage };
10881
+ export { AttributeSchema, BinaryPartSchema, COLOR_BLACK, CONTENT_FORMAT_VERSION, CommentSchema, CompactPackageSchema, CompactPartSchema, CompactXmlNodeSchema, ContentBlockSchema, ContentCellValueSchema, ContentDocumentSchema, ContentDrawPageSchema, ContentImageBlockSchema, ContentPageBreakSchema, ContentParagraphSchema, ContentPathPointSchema, ContentPathSegmentSchema, ContentRunSchema, ContentSectionSchema, ContentShapeSchema, ContentSheetCellSchema, ContentSheetColumnSchema, ContentSheetPrintRangeSchema, ContentSheetPrintSettingsSchema, ContentSheetRepeatRangeSchema, ContentSheetRowSchema, ContentSheetSchema, ContentSlideSchema, ContentStrokeSchema, ContentSubpathSchema, ContentTableCellSchema, ContentTableRowSchema, ContentTableSchema, ContentVectorSchema, DEFAULT_LAYOUT_FONT, DefinedNameSchema, DocxBytesSchema, DocxEditor, DocxParagraph, DocxRun, DocxTable, DocxTableCell, DocxTableRow, LAYOUT_FORMAT_VERSION, NOOP_DIAGNOSTIC_SINK, OdgBoxVector, OdgBytesSchema, OdgEditor, OdgLineVector, OdgPage, OdgPathVector, OdpBytesSchema, OdpEditor, OdpShape, OdpSlide, OdsBytesSchema, OdsCell, OdsEditor, OdsSheet, 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, buildOdgPackage, buildOdpPackage, buildOdsPackage, buildOdtPackage, buildPptxPackage, buildXml, bytesToBase64, childrenWithTag, compactCodec, compactPackageCodec, convertDrawingToLayout, convertPresentationToLayout, convertSpreadsheetToLayout, convertWordprocessingToLayout, createDocx, createLocalDocumentConverter, createOdg, createOdp, createOds, createOdt, createPptx, decodeCompactPackage, decodeEntities, decodePackage, docxPdfCodec, docxToPdf, elementsWithTag, encodeCompactPackage, encodePackage, fixedClock, flipY, fromCompact, isCompactXmlNode, isContentBlock, isXmlNode, odgToPdf, odpPdfCodec, odpToPdf, odsToPdf, odtPdfCodec, odtToPdf, openDocx, openOdg, openOdp, openOds, openOdt, openPptx, packageCodec, parsePackage, parseXml, pdfCodec, pdfToDocx, pdfToOdp, pdfToOdt, pdfToPptx, pptxPdfCodec, pptxToPdf, readDocxContent, readOdgContent, readOdpContent, readOdsContent, readOdtContent, readPdf, readPptxContent, reconstructPresentation, reconstructWordprocessing, resolveRelationships, rgbHexToColor, rootElement, serializePackage, systemClock, textContent, throwIfAborted, toCompact, unzipPackage, walk, writePdf, xmlCodec, zipPackage };