documents.js 1.43.1 → 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
- import { COLOR_BLACK, ContentBlockSchema, ContentCellValueSchema, ContentImageBlockSchema, ContentPageBreakSchema, ContentParagraphSchema, ContentRunSchema, ContentSectionSchema, ContentSectionSchema as ContentSectionSchema$1, ContentShapeSchema, ContentSheetCellSchema, ContentSheetColumnSchema, ContentSheetPrintRangeSchema, ContentSheetPrintSettingsSchema, ContentSheetRepeatRangeSchema, ContentSheetRowSchema, ContentSheetSchema, ContentSheetSchema as ContentSheetSchema$1, ContentSlideSchema, ContentSlideSchema as ContentSlideSchema$1, ContentTableCellSchema, ContentTableRowSchema, ContentTableSchema, DEFAULT_LAYOUT_FONT, LAYOUT_FORMAT_VERSION, LAYOUT_FORMAT_VERSION as LAYOUT_FORMAT_VERSION$1, LayoutDocumentSchema, LayoutMetadataSchema, PAGE_SIZE_A4, PAGE_SIZE_LETTER, SLIDE_SIZE_STANDARD, SLIDE_SIZE_WIDESCREEN, colorToRgbHex, isContentBlock, rgbHexToColor } from "document-content-model";
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, 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;
@@ -23,6 +23,12 @@ const ContentDocumentSchema = z.discriminatedUnion("kind", [
23
23
  formatVersion: z.literal(1),
24
24
  metadata: LayoutMetadataSchema,
25
25
  sheets: z.array(ContentSheetSchema$1)
26
+ }),
27
+ z.object({
28
+ kind: z.literal("drawing"),
29
+ formatVersion: z.literal(1),
30
+ metadata: LayoutMetadataSchema,
31
+ pages: z.array(ContentDrawPageSchema$1)
26
32
  })
27
33
  ]);
28
34
  //#endregion
@@ -529,7 +535,7 @@ function needsSpacePreserve(text) {
529
535
  }
530
536
  //#endregion
531
537
  //#region src/edit/docx/run.ts
532
- function directChild$9(parent, tag) {
538
+ function directChild$10(parent, tag) {
533
539
  for (const child of parent.children) if (child.type === "element" && child.tag === tag) return child;
534
540
  }
535
541
  function appendUElement(rPr, value) {
@@ -538,7 +544,7 @@ function appendUElement(rPr, value) {
538
544
  return created;
539
545
  }
540
546
  function findOrCreateT(run) {
541
- const existing = directChild$9(run, "w:t");
547
+ const existing = directChild$10(run, "w:t");
542
548
  if (existing !== void 0) return existing;
543
549
  const created = el("w:t");
544
550
  run.children.push(created);
@@ -558,7 +564,7 @@ var DocxRun = class {
558
564
  }
559
565
  rPr(create) {
560
566
  const node = this.live();
561
- return create ? ensureFirstChild(node, "w:rPr") : directChild$9(node, "w:rPr");
567
+ return create ? ensureFirstChild(node, "w:rPr") : directChild$10(node, "w:rPr");
562
568
  }
563
569
  get text() {
564
570
  return textContent$1(this.live());
@@ -582,14 +588,14 @@ var DocxRun = class {
582
588
  }
583
589
  get underline() {
584
590
  const rPr = this.rPr(false);
585
- 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");
586
592
  if (uElement === void 0) return false;
587
593
  for (const a of uElement.attributes) if (a.name === "w:val") return a.value !== "none";
588
594
  return true;
589
595
  }
590
596
  set underline(value) {
591
597
  const rPr = this.rPr(true);
592
- const existing = directChild$9(rPr, "w:u");
598
+ const existing = directChild$10(rPr, "w:u");
593
599
  if (existing === void 0) {
594
600
  appendUElement(rPr, value);
595
601
  return;
@@ -663,7 +669,7 @@ function buildRun$1(init = {}) {
663
669
  }
664
670
  //#endregion
665
671
  //#region src/edit/docx/paragraph.ts
666
- function directChild$8(parent, tag) {
672
+ function directChild$9(parent, tag) {
667
673
  for (const child of parent.children) if (child.type === "element" && child.tag === tag) return child;
668
674
  }
669
675
  var DocxParagraph = class {
@@ -682,7 +688,7 @@ var DocxParagraph = class {
682
688
  }
683
689
  pPr(create) {
684
690
  const node = this.live();
685
- return create ? ensureFirstChild(node, "w:pPr") : directChild$8(node, "w:pPr");
691
+ return create ? ensureFirstChild(node, "w:pPr") : directChild$9(node, "w:pPr");
686
692
  }
687
693
  get text() {
688
694
  return textContent$1(this.live());
@@ -719,7 +725,7 @@ var DocxParagraph = class {
719
725
  set styleId(value) {
720
726
  if (value === void 0) {
721
727
  const pPr = this.pPr(false);
722
- 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");
723
729
  if (existing !== void 0 && pPr !== void 0) removeChild(pPr.children, existing);
724
730
  return;
725
731
  }
@@ -731,7 +737,7 @@ var DocxParagraph = class {
731
737
  set alignment(value) {
732
738
  if (value === void 0) {
733
739
  const pPr = this.pPr(false);
734
- 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");
735
741
  if (existing !== void 0 && pPr !== void 0) removeChild(pPr.children, existing);
736
742
  return;
737
743
  }
@@ -739,12 +745,12 @@ var DocxParagraph = class {
739
745
  }
740
746
  get list() {
741
747
  const pPr = this.pPr(false);
742
- 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");
743
749
  if (numPr === void 0) return;
744
- const numIdElement = directChild$8(numPr, "w:numId");
750
+ const numIdElement = directChild$9(numPr, "w:numId");
745
751
  const numId = numIdElement === void 0 ? void 0 : attr$1(numIdElement, "w:val");
746
752
  if (numId === void 0) return;
747
- const ilvlElement = directChild$8(numPr, "w:ilvl");
753
+ const ilvlElement = directChild$9(numPr, "w:ilvl");
748
754
  const ilvl = ilvlElement === void 0 ? void 0 : attr$1(ilvlElement, "w:val");
749
755
  return {
750
756
  numId,
@@ -754,7 +760,7 @@ var DocxParagraph = class {
754
760
  set list(value) {
755
761
  const pPr = this.pPr(true);
756
762
  if (value === void 0) {
757
- const existing = directChild$8(pPr, "w:numPr");
763
+ const existing = directChild$9(pPr, "w:numPr");
758
764
  if (existing !== void 0) removeChild(pPr.children, existing);
759
765
  return;
760
766
  }
@@ -788,7 +794,7 @@ function buildParagraph$1(init = {}) {
788
794
  const CONTENT_TYPES_NS$1 = "http://schemas.openxmlformats.org/package/2006/content-types";
789
795
  const RELS_NS$1 = "http://schemas.openxmlformats.org/package/2006/relationships";
790
796
  const WORDML_NS = "http://schemas.openxmlformats.org/wordprocessingml/2006/main";
791
- function declaration$4() {
797
+ function declaration$5() {
792
798
  return {
793
799
  type: "declaration",
794
800
  attributes: [
@@ -857,23 +863,23 @@ function createEmptyDocxPackage() {
857
863
  return { parts: {
858
864
  "[Content_Types].xml": {
859
865
  kind: "xml",
860
- nodes: [declaration$4(), contentTypes]
866
+ nodes: [declaration$5(), contentTypes]
861
867
  },
862
868
  "_rels/.rels": {
863
869
  kind: "xml",
864
- nodes: [declaration$4(), rootRels]
870
+ nodes: [declaration$5(), rootRels]
865
871
  },
866
872
  "word/document.xml": {
867
873
  kind: "xml",
868
- nodes: [declaration$4(), document]
874
+ nodes: [declaration$5(), document]
869
875
  },
870
876
  "word/_rels/document.xml.rels": {
871
877
  kind: "xml",
872
- nodes: [declaration$4(), documentRels]
878
+ nodes: [declaration$5(), documentRels]
873
879
  },
874
880
  "word/styles.xml": {
875
881
  kind: "xml",
876
- nodes: [declaration$4(), styles]
882
+ nodes: [declaration$5(), styles]
877
883
  }
878
884
  } };
879
885
  }
@@ -1164,7 +1170,7 @@ const SLIDE_LAYOUT_REL_TYPE = "http://schemas.openxmlformats.org/officeDocument/
1164
1170
  const THEME_REL_TYPE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme";
1165
1171
  const NOTES_MASTER_REL_TYPE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/notesMaster";
1166
1172
  const MIN_MASTER_OR_LAYOUT_ID = 2147483648;
1167
- function declaration$3() {
1173
+ function declaration$4() {
1168
1174
  return {
1169
1175
  type: "declaration",
1170
1176
  attributes: [
@@ -1314,7 +1320,7 @@ function ensureNotesMaster(pkg) {
1314
1320
  });
1315
1321
  pkg.parts[NOTES_MASTER_PART_PATH] = {
1316
1322
  kind: "xml",
1317
- nodes: [declaration$3(), buildNotesMaster()]
1323
+ nodes: [declaration$4(), buildNotesMaster()]
1318
1324
  };
1319
1325
  ensureContentTypeOverride(pkg, NOTES_MASTER_PART_PATH, NOTES_MASTER_CONTENT_TYPE);
1320
1326
  const presentationToNotesMasterTarget = buildRelativeTarget(PRESENTATION_PART_PATH$1, NOTES_MASTER_PART_PATH);
@@ -1353,15 +1359,15 @@ function createEmptyPptxPackage() {
1353
1359
  const pkg = { parts: {
1354
1360
  "[Content_Types].xml": {
1355
1361
  kind: "xml",
1356
- nodes: [declaration$3(), contentTypes]
1362
+ nodes: [declaration$4(), contentTypes]
1357
1363
  },
1358
1364
  "_rels/.rels": {
1359
1365
  kind: "xml",
1360
- nodes: [declaration$3(), rootRels]
1366
+ nodes: [declaration$4(), rootRels]
1361
1367
  },
1362
1368
  [PRESENTATION_PART_PATH$1]: {
1363
1369
  kind: "xml",
1364
- nodes: [declaration$3(), el("p:presentation", {
1370
+ nodes: [declaration$4(), el("p:presentation", {
1365
1371
  "xmlns:p": PML_NS,
1366
1372
  "xmlns:r": R_NS
1367
1373
  })]
@@ -1374,7 +1380,7 @@ function createEmptyPptxPackage() {
1374
1380
  });
1375
1381
  pkg.parts[SLIDE_LAYOUT_PART_PATH] = {
1376
1382
  kind: "xml",
1377
- nodes: [declaration$3(), buildSlideLayout()]
1383
+ nodes: [declaration$4(), buildSlideLayout()]
1378
1384
  };
1379
1385
  ensureContentTypeOverride(pkg, SLIDE_LAYOUT_PART_PATH, SLIDE_LAYOUT_CONTENT_TYPE);
1380
1386
  const masterToLayoutTarget = buildRelativeTarget(SLIDE_MASTER_PART_PATH, SLIDE_LAYOUT_PART_PATH);
@@ -1389,12 +1395,12 @@ function createEmptyPptxPackage() {
1389
1395
  });
1390
1396
  pkg.parts[SLIDE_MASTER_PART_PATH] = {
1391
1397
  kind: "xml",
1392
- nodes: [declaration$3(), buildSlideMaster(masterToLayoutRelId)]
1398
+ nodes: [declaration$4(), buildSlideMaster(masterToLayoutRelId)]
1393
1399
  };
1394
1400
  ensureContentTypeOverride(pkg, SLIDE_MASTER_PART_PATH, SLIDE_MASTER_CONTENT_TYPE);
1395
1401
  pkg.parts[THEME_PART_PATH] = {
1396
1402
  kind: "xml",
1397
- nodes: [declaration$3(), buildTheme()]
1403
+ nodes: [declaration$4(), buildTheme()]
1398
1404
  };
1399
1405
  ensureContentTypeOverride(pkg, THEME_PART_PATH, THEME_CONTENT_TYPE);
1400
1406
  const presentationToMasterTarget = buildRelativeTarget(PRESENTATION_PART_PATH$1, SLIDE_MASTER_PART_PATH);
@@ -1419,7 +1425,7 @@ function createEmptyPptxPackage() {
1419
1425
  }
1420
1426
  //#endregion
1421
1427
  //#region src/edit/pptx/shape.ts
1422
- function directChild$7(parent, tag) {
1428
+ function directChild$8(parent, tag) {
1423
1429
  for (const child of parent.children) if (child.type === "element" && child.tag === tag) return child;
1424
1430
  }
1425
1431
  function parseEmuAttr(element, name) {
@@ -1440,7 +1446,7 @@ var PptxShape = class {
1440
1446
  }
1441
1447
  spPrElement(create) {
1442
1448
  const node = this.live();
1443
- const existing = directChild$7(node, "p:spPr");
1449
+ const existing = directChild$8(node, "p:spPr");
1444
1450
  if (existing !== void 0 || !create) return existing;
1445
1451
  const created = el("p:spPr");
1446
1452
  node.children.push(created);
@@ -1448,10 +1454,10 @@ var PptxShape = class {
1448
1454
  }
1449
1455
  get frame() {
1450
1456
  const spPr = this.spPrElement(false);
1451
- 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");
1452
1458
  if (xfrm === void 0) return;
1453
- const off = directChild$7(xfrm, "a:off");
1454
- const ext = directChild$7(xfrm, "a:ext");
1459
+ const off = directChild$8(xfrm, "a:off");
1460
+ const ext = directChild$8(xfrm, "a:ext");
1455
1461
  if (off === void 0 || ext === void 0) return;
1456
1462
  const x = parseEmuAttr(off, "x");
1457
1463
  const y = parseEmuAttr(off, "y");
@@ -1467,7 +1473,7 @@ var PptxShape = class {
1467
1473
  }
1468
1474
  set frame(value) {
1469
1475
  const spPr = this.spPrElement(true);
1470
- let xfrm = directChild$7(spPr, "a:xfrm");
1476
+ let xfrm = directChild$8(spPr, "a:xfrm");
1471
1477
  if (xfrm === void 0) {
1472
1478
  xfrm = el("a:xfrm");
1473
1479
  spPr.children.unshift(xfrm);
@@ -1481,12 +1487,12 @@ var PptxShape = class {
1481
1487
  })];
1482
1488
  }
1483
1489
  get text() {
1484
- const txBody = directChild$7(this.live(), "p:txBody");
1490
+ const txBody = directChild$8(this.live(), "p:txBody");
1485
1491
  return txBody === void 0 ? "" : textContent$1(txBody);
1486
1492
  }
1487
1493
  set text(value) {
1488
1494
  const node = this.live();
1489
- let txBody = directChild$7(node, "p:txBody");
1495
+ let txBody = directChild$8(node, "p:txBody");
1490
1496
  if (txBody === void 0) {
1491
1497
  txBody = el("p:txBody", {}, [el("a:bodyPr"), el("a:lstStyle")]);
1492
1498
  node.children.push(txBody);
@@ -1497,7 +1503,7 @@ var PptxShape = class {
1497
1503
  }
1498
1504
  setParagraphs(paragraphs) {
1499
1505
  const node = this.live();
1500
- let txBody = directChild$7(node, "p:txBody");
1506
+ let txBody = directChild$8(node, "p:txBody");
1501
1507
  if (txBody === void 0) {
1502
1508
  txBody = el("p:txBody", {}, [el("a:bodyPr"), el("a:lstStyle")]);
1503
1509
  node.children.push(txBody);
@@ -1608,12 +1614,12 @@ function insertPictureShapeMedia(context, slideRoot, frame, image) {
1608
1614
  }
1609
1615
  //#endregion
1610
1616
  //#region src/edit/pptx/slide.ts
1611
- function directChild$6(parent, tag) {
1617
+ function directChild$7(parent, tag) {
1612
1618
  for (const child of parent.children) if (child.type === "element" && child.tag === tag) return child;
1613
1619
  }
1614
1620
  function findSpTree(slideRoot) {
1615
- const cSld = directChild$6(slideRoot, "p:cSld");
1616
- 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");
1617
1623
  if (spTree === void 0) throw new Error("slide has no p:cSld/p:spTree element");
1618
1624
  return spTree;
1619
1625
  }
@@ -1745,7 +1751,7 @@ const PRESENTATION_PART_PATH = "ppt/presentation.xml";
1745
1751
  const MEDIA_DIR = "ppt/media";
1746
1752
  const SLIDE_CONTENT_TYPE = "application/vnd.openxmlformats-officedocument.presentationml.slide+xml";
1747
1753
  const SLIDE_RELATIONSHIP_TYPE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/slide";
1748
- function directChild$5(parent, tag) {
1754
+ function directChild$6(parent, tag) {
1749
1755
  for (const child of parent.children) if (child.type === "element" && child.tag === tag) return child;
1750
1756
  }
1751
1757
  function attrValue(element, name) {
@@ -1757,12 +1763,12 @@ function findPresentationRoot(pkg) {
1757
1763
  return root;
1758
1764
  }
1759
1765
  function findSldIdLst(presentationRoot) {
1760
- const sldIdLst = directChild$5(presentationRoot, "p:sldIdLst");
1766
+ const sldIdLst = directChild$6(presentationRoot, "p:sldIdLst");
1761
1767
  if (sldIdLst === void 0) throw new Error(`${PRESENTATION_PART_PATH} has no p:sldIdLst element`);
1762
1768
  return sldIdLst;
1763
1769
  }
1764
1770
  function findSldSz(presentationRoot) {
1765
- const sldSz = directChild$5(presentationRoot, "p:sldSz");
1771
+ const sldSz = directChild$6(presentationRoot, "p:sldSz");
1766
1772
  if (sldSz === void 0) throw new Error(`${PRESENTATION_PART_PATH} has no p:sldSz element`);
1767
1773
  return sldSz;
1768
1774
  }
@@ -1923,12 +1929,12 @@ function buildPptxPackage(content) {
1923
1929
  if (firstSlide !== void 0) editor.slideSize = firstSlide.size;
1924
1930
  for (const slide of content.slides) {
1925
1931
  const pptxSlide = editor.addSlide();
1926
- for (const shape of slide.shapes) appendShape$1(pptxSlide, shape);
1932
+ for (const shape of slide.shapes) appendShape$2(pptxSlide, shape);
1927
1933
  if (slide.notes.length > 0) pptxSlide.notes = slide.notes;
1928
1934
  }
1929
1935
  return editor.toPackage();
1930
1936
  }
1931
- function appendShape$1(slide, shape) {
1937
+ function appendShape$2(slide, shape) {
1932
1938
  const [onlyBlock] = shape.blocks;
1933
1939
  if (shape.blocks.length === 1 && onlyBlock?.kind === "image") {
1934
1940
  slide.addImage({
@@ -1961,12 +1967,12 @@ function appendShape$1(slide, shape) {
1961
1967
  }
1962
1968
  //#endregion
1963
1969
  //#region src/edit/odt/automatic-styles.ts
1964
- const CONTENT_PART_PATH$3 = "content.xml";
1970
+ const CONTENT_PART_PATH$4 = "content.xml";
1965
1971
  function ensureAutomaticStyles(pkg) {
1966
- const part = pkg.parts[CONTENT_PART_PATH$3];
1967
- 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`);
1968
1974
  const root = part.nodes.find((n) => n.type === "element");
1969
- 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`);
1970
1976
  for (const child of root.children) if (child.type === "element" && child.tag === "office:automatic-styles") return child;
1971
1977
  const created = el("office:automatic-styles");
1972
1978
  const insertBeforeTags = /* @__PURE__ */ new Set([
@@ -2060,7 +2066,7 @@ function applyStyleChange(pkg, element, family, change) {
2060
2066
  ...readCurrentStyleProperties(pkg, element, family),
2061
2067
  ...change
2062
2068
  };
2063
- const name = StyleRegistry.forPart(pkg, CONTENT_PART_PATH$3).intern({
2069
+ const name = StyleRegistry.forPart(pkg, CONTENT_PART_PATH$4).intern({
2064
2070
  family,
2065
2071
  properties: merged
2066
2072
  });
@@ -2291,7 +2297,7 @@ function buildList(pkg) {
2291
2297
  }
2292
2298
  //#endregion
2293
2299
  //#region src/edit/odt/scaffold.ts
2294
- const CONTENT_NS_PREFIXES$2 = [
2300
+ const CONTENT_NS_PREFIXES$3 = [
2295
2301
  "office",
2296
2302
  "style",
2297
2303
  "text",
@@ -2301,7 +2307,7 @@ const CONTENT_NS_PREFIXES$2 = [
2301
2307
  "svg",
2302
2308
  "xlink"
2303
2309
  ];
2304
- const STYLES_NS_PREFIXES$2 = [
2310
+ const STYLES_NS_PREFIXES$3 = [
2305
2311
  "office",
2306
2312
  "style",
2307
2313
  "text",
@@ -2311,16 +2317,16 @@ const STYLES_NS_PREFIXES$2 = [
2311
2317
  "svg",
2312
2318
  "xlink"
2313
2319
  ];
2314
- const META_NS_PREFIXES$2 = [
2320
+ const META_NS_PREFIXES$3 = [
2315
2321
  "office",
2316
2322
  "meta",
2317
2323
  "dc"
2318
2324
  ];
2319
- const ODF_VERSION$2 = "1.3";
2320
- const PAGE_LAYOUT_NAME$2 = "PM1";
2321
- 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";
2322
2328
  const DEFAULT_MARGIN_PT = 72;
2323
- function declaration$2() {
2329
+ function declaration$3() {
2324
2330
  return {
2325
2331
  type: "declaration",
2326
2332
  attributes: [
@@ -2339,8 +2345,8 @@ function declaration$2() {
2339
2345
  ]
2340
2346
  };
2341
2347
  }
2342
- function buildPageLayout$2() {
2343
- 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", {
2344
2350
  "fo:page-width": `${PAGE_SIZE_LETTER.widthPt}pt`,
2345
2351
  "fo:page-height": `${PAGE_SIZE_LETTER.heightPt}pt`,
2346
2352
  "fo:margin-top": `${DEFAULT_MARGIN_PT}pt`,
@@ -2349,44 +2355,44 @@ function buildPageLayout$2() {
2349
2355
  "fo:margin-left": `${DEFAULT_MARGIN_PT}pt`
2350
2356
  })]);
2351
2357
  }
2352
- function buildStylesXml$2() {
2358
+ function buildStylesXml$3() {
2353
2359
  return el("office:document-styles", {
2354
- ...xmlnsAttributes([...STYLES_NS_PREFIXES$2]),
2355
- "office:version": ODF_VERSION$2
2360
+ ...xmlnsAttributes([...STYLES_NS_PREFIXES$3]),
2361
+ "office:version": ODF_VERSION$3
2356
2362
  }, [
2357
2363
  el("office:styles"),
2358
- el("office:automatic-styles", {}, [buildPageLayout$2()]),
2364
+ el("office:automatic-styles", {}, [buildPageLayout$3()]),
2359
2365
  el("office:master-styles", {}, [el("style:master-page", {
2360
- "style:name": MASTER_PAGE_NAME$2,
2361
- "style:page-layout-name": PAGE_LAYOUT_NAME$2
2366
+ "style:name": MASTER_PAGE_NAME$3,
2367
+ "style:page-layout-name": PAGE_LAYOUT_NAME$3
2362
2368
  })])
2363
2369
  ]);
2364
2370
  }
2365
- function buildContentXml$2() {
2371
+ function buildContentXml$3() {
2366
2372
  return el("office:document-content", {
2367
- ...xmlnsAttributes([...CONTENT_NS_PREFIXES$2]),
2368
- "office:version": ODF_VERSION$2
2373
+ ...xmlnsAttributes([...CONTENT_NS_PREFIXES$3]),
2374
+ "office:version": ODF_VERSION$3
2369
2375
  }, [el("office:automatic-styles"), el("office:body", {}, [el("office:text")])]);
2370
2376
  }
2371
- function buildMetaXml$2() {
2377
+ function buildMetaXml$3() {
2372
2378
  return el("office:document-meta", {
2373
- ...xmlnsAttributes([...META_NS_PREFIXES$2]),
2374
- "office:version": ODF_VERSION$2
2379
+ ...xmlnsAttributes([...META_NS_PREFIXES$3]),
2380
+ "office:version": ODF_VERSION$3
2375
2381
  }, [el("office:meta")]);
2376
2382
  }
2377
2383
  function createEmptyOdtPackage() {
2378
2384
  const pkg = { parts: {
2379
2385
  "content.xml": {
2380
2386
  kind: "xml",
2381
- nodes: [declaration$2(), buildContentXml$2()]
2387
+ nodes: [declaration$3(), buildContentXml$3()]
2382
2388
  },
2383
2389
  "styles.xml": {
2384
2390
  kind: "xml",
2385
- nodes: [declaration$2(), buildStylesXml$2()]
2391
+ nodes: [declaration$3(), buildStylesXml$3()]
2386
2392
  },
2387
2393
  "meta.xml": {
2388
2394
  kind: "xml",
2389
- nodes: [declaration$2(), buildMetaXml$2()]
2395
+ nodes: [declaration$3(), buildMetaXml$3()]
2390
2396
  }
2391
2397
  } };
2392
2398
  setDocumentMediaType(pkg, ODF_MEDIA_TYPES.odt);
@@ -2507,20 +2513,20 @@ function buildTable(pkg, init) {
2507
2513
  }
2508
2514
  //#endregion
2509
2515
  //#region src/edit/odt/editor.ts
2510
- const CONTENT_PART_PATH$2 = "content.xml";
2516
+ const CONTENT_PART_PATH$3 = "content.xml";
2511
2517
  function findContentRoot(pkg) {
2512
- const part = pkg.parts[CONTENT_PART_PATH$2];
2518
+ const part = pkg.parts[CONTENT_PART_PATH$3];
2513
2519
  const root = part?.kind === "xml" ? part.nodes.find((n) => n.type === "element") : void 0;
2514
- 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}`);
2515
2521
  return root;
2516
2522
  }
2517
- function directChild$4(parent, tag) {
2523
+ function directChild$5(parent, tag) {
2518
2524
  for (const child of parent.children) if (child.type === "element" && child.tag === tag) return child;
2519
2525
  }
2520
2526
  function findOfficeText(contentRoot) {
2521
- const body = directChild$4(contentRoot, "office:body");
2522
- const text = body === void 0 ? void 0 : directChild$4(body, "office:text");
2523
- 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`);
2524
2530
  return text;
2525
2531
  }
2526
2532
  var OdtBodyImpl = class {
@@ -2652,7 +2658,7 @@ function appendBlock(body, block) {
2652
2658
  }
2653
2659
  //#endregion
2654
2660
  //#region src/edit/odp/scaffold.ts
2655
- const CONTENT_NS_PREFIXES$1 = [
2661
+ const CONTENT_NS_PREFIXES$2 = [
2656
2662
  "office",
2657
2663
  "style",
2658
2664
  "text",
@@ -2663,7 +2669,7 @@ const CONTENT_NS_PREFIXES$1 = [
2663
2669
  "svg",
2664
2670
  "xlink"
2665
2671
  ];
2666
- const STYLES_NS_PREFIXES$1 = [
2672
+ const STYLES_NS_PREFIXES$2 = [
2667
2673
  "office",
2668
2674
  "style",
2669
2675
  "text",
@@ -2674,14 +2680,14 @@ const STYLES_NS_PREFIXES$1 = [
2674
2680
  "svg",
2675
2681
  "xlink"
2676
2682
  ];
2677
- const META_NS_PREFIXES$1 = [
2683
+ const META_NS_PREFIXES$2 = [
2678
2684
  "office",
2679
2685
  "meta",
2680
2686
  "dc"
2681
2687
  ];
2682
- const ODF_VERSION$1 = "1.3";
2683
- const MASTER_PAGE_NAME$1 = "Standard";
2684
- function declaration$1() {
2688
+ const ODF_VERSION$2 = "1.3";
2689
+ const MASTER_PAGE_NAME$2 = "Standard";
2690
+ function declaration$2() {
2685
2691
  return {
2686
2692
  type: "declaration",
2687
2693
  attributes: [
@@ -2700,50 +2706,50 @@ function declaration$1() {
2700
2706
  ]
2701
2707
  };
2702
2708
  }
2703
- function buildPageLayout$1() {
2709
+ function buildPageLayout$2() {
2704
2710
  return el("style:page-layout", { "style:name": "PM1" }, [el("style:page-layout-properties", {
2705
2711
  "fo:page-width": `${SLIDE_SIZE_WIDESCREEN.widthPt}pt`,
2706
2712
  "fo:page-height": `${SLIDE_SIZE_WIDESCREEN.heightPt}pt`
2707
2713
  })]);
2708
2714
  }
2709
- function buildStylesXml$1() {
2715
+ function buildStylesXml$2() {
2710
2716
  return el("office:document-styles", {
2711
- ...xmlnsAttributes([...STYLES_NS_PREFIXES$1]),
2712
- "office:version": ODF_VERSION$1
2717
+ ...xmlnsAttributes([...STYLES_NS_PREFIXES$2]),
2718
+ "office:version": ODF_VERSION$2
2713
2719
  }, [
2714
2720
  el("office:styles"),
2715
- el("office:automatic-styles", {}, [buildPageLayout$1()]),
2721
+ el("office:automatic-styles", {}, [buildPageLayout$2()]),
2716
2722
  el("office:master-styles", {}, [el("style:master-page", {
2717
- "style:name": MASTER_PAGE_NAME$1,
2723
+ "style:name": MASTER_PAGE_NAME$2,
2718
2724
  "style:page-layout-name": "PM1"
2719
2725
  })])
2720
2726
  ]);
2721
2727
  }
2722
- function buildContentXml$1() {
2728
+ function buildContentXml$2() {
2723
2729
  return el("office:document-content", {
2724
- ...xmlnsAttributes([...CONTENT_NS_PREFIXES$1]),
2725
- "office:version": ODF_VERSION$1
2730
+ ...xmlnsAttributes([...CONTENT_NS_PREFIXES$2]),
2731
+ "office:version": ODF_VERSION$2
2726
2732
  }, [el("office:automatic-styles"), el("office:body", {}, [el("office:presentation")])]);
2727
2733
  }
2728
- function buildMetaXml$1() {
2734
+ function buildMetaXml$2() {
2729
2735
  return el("office:document-meta", {
2730
- ...xmlnsAttributes([...META_NS_PREFIXES$1]),
2731
- "office:version": ODF_VERSION$1
2736
+ ...xmlnsAttributes([...META_NS_PREFIXES$2]),
2737
+ "office:version": ODF_VERSION$2
2732
2738
  }, [el("office:meta")]);
2733
2739
  }
2734
2740
  function createEmptyOdpPackage() {
2735
2741
  const pkg = { parts: {
2736
2742
  "content.xml": {
2737
2743
  kind: "xml",
2738
- nodes: [declaration$1(), buildContentXml$1()]
2744
+ nodes: [declaration$2(), buildContentXml$2()]
2739
2745
  },
2740
2746
  "styles.xml": {
2741
2747
  kind: "xml",
2742
- nodes: [declaration$1(), buildStylesXml$1()]
2748
+ nodes: [declaration$2(), buildStylesXml$2()]
2743
2749
  },
2744
2750
  "meta.xml": {
2745
2751
  kind: "xml",
2746
- nodes: [declaration$1(), buildMetaXml$1()]
2752
+ nodes: [declaration$2(), buildMetaXml$2()]
2747
2753
  }
2748
2754
  } };
2749
2755
  setDocumentMediaType(pkg, ODF_MEDIA_TYPES.odp);
@@ -2783,7 +2789,7 @@ function addImageMedia(pkg, imageBytes, format) {
2783
2789
  }
2784
2790
  //#endregion
2785
2791
  //#region src/edit/odp/shape.ts
2786
- function directChild$3(parent, tag) {
2792
+ function directChild$4(parent, tag) {
2787
2793
  for (const child of parent.children) if (child.type === "element" && child.tag === tag) return child;
2788
2794
  }
2789
2795
  function buildTransformAttr(frame, rotationDeg) {
@@ -2851,7 +2857,7 @@ var OdpShape = class {
2851
2857
  }
2852
2858
  textBox(create) {
2853
2859
  const node = this.live();
2854
- const existing = directChild$3(node, "draw:text-box");
2860
+ const existing = directChild$4(node, "draw:text-box");
2855
2861
  if (existing !== void 0 || !create) return existing;
2856
2862
  const created = el("draw:text-box");
2857
2863
  node.children.push(created);
@@ -2912,7 +2918,7 @@ function insertImageFrameMedia(context, frame, image) {
2912
2918
  }
2913
2919
  //#endregion
2914
2920
  //#region src/edit/odp/slide.ts
2915
- function directChild$2(parent, tag) {
2921
+ function directChild$3(parent, tag) {
2916
2922
  for (const child of parent.children) if (child.type === "element" && child.tag === tag) return child;
2917
2923
  }
2918
2924
  const NOTES_FRAME_X_PT = 20;
@@ -2961,13 +2967,13 @@ var OdpSlide = class {
2961
2967
  return new OdpShape(node.children, frameElement, this.context.pkg);
2962
2968
  }
2963
2969
  get notes() {
2964
- const notesElement = directChild$2(this.live(), "presentation:notes");
2970
+ const notesElement = directChild$3(this.live(), "presentation:notes");
2965
2971
  if (notesElement === void 0) return "";
2966
2972
  return elementsWithTag$1(notesElement.children, "text:p").map((p) => decodeOdfText$1(p.children)).join("\n");
2967
2973
  }
2968
2974
  set notes(value) {
2969
2975
  const node = this.live();
2970
- const existing = directChild$2(node, "presentation:notes");
2976
+ const existing = directChild$3(node, "presentation:notes");
2971
2977
  const notesElement = buildNotesElement(this.context.pkg, value);
2972
2978
  if (existing === void 0) node.children.push(notesElement);
2973
2979
  else existing.children = notesElement.children;
@@ -2979,27 +2985,27 @@ var OdpSlide = class {
2979
2985
  };
2980
2986
  //#endregion
2981
2987
  //#region src/edit/odp/editor.ts
2982
- const CONTENT_PART_PATH$1 = "content.xml";
2983
- const STYLES_PART_PATH = "styles.xml";
2984
- 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) {
2985
2991
  for (const child of parent.children) if (child.type === "element" && child.tag === tag) return child;
2986
2992
  }
2987
- function findRoot$1(pkg, partPath) {
2993
+ function findRoot$2(pkg, partPath) {
2988
2994
  const part = pkg.parts[partPath];
2989
2995
  const root = part?.kind === "xml" ? part.nodes.find((n) => n.type === "element") : void 0;
2990
2996
  if (root === void 0) throw new Error(`package has no root element at ${partPath}`);
2991
2997
  return root;
2992
2998
  }
2993
2999
  function findOfficePresentation(pkg) {
2994
- const body = directChild$1(findRoot$1(pkg, CONTENT_PART_PATH$1), "office:body");
2995
- const presentation = body === void 0 ? void 0 : directChild$1(body, "office:presentation");
2996
- 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`);
2997
3003
  return presentation;
2998
3004
  }
2999
- function findPageLayoutProperties(pkg) {
3000
- 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");
3001
- const properties = pageLayout === void 0 ? void 0 : directChild$1(pageLayout, "style:page-layout-properties");
3002
- 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`);
3003
3009
  return properties;
3004
3010
  }
3005
3011
  var OdpEditor = class {
@@ -3018,7 +3024,7 @@ var OdpEditor = class {
3018
3024
  }
3019
3025
  addSlide() {
3020
3026
  const presentation = findOfficePresentation(this.pkg);
3021
- 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 });
3022
3028
  presentation.children.push(pageElement);
3023
3029
  const context = { pkg: this.pkg };
3024
3030
  return new OdpSlide(presentation.children, pageElement, context);
@@ -3048,7 +3054,7 @@ var OdpEditor = class {
3048
3054
  presentation.children.splice(insertAt, 0, moved);
3049
3055
  }
3050
3056
  get slideSize() {
3051
- const properties = findPageLayoutProperties(this.pkg);
3057
+ const properties = findPageLayoutProperties$1(this.pkg);
3052
3058
  const widthValue = attr$1(properties, "fo:page-width");
3053
3059
  const heightValue = attr$1(properties, "fo:page-height");
3054
3060
  const widthPt = widthValue === void 0 ? void 0 : parseOdfLength(widthValue);
@@ -3059,7 +3065,7 @@ var OdpEditor = class {
3059
3065
  };
3060
3066
  }
3061
3067
  set slideSize(size) {
3062
- const properties = findPageLayoutProperties(this.pkg);
3068
+ const properties = findPageLayoutProperties$1(this.pkg);
3063
3069
  properties.attributes = [{
3064
3070
  name: "fo:page-width",
3065
3071
  value: formatOdfLength(size.widthPt)
@@ -3090,12 +3096,12 @@ function buildOdpPackage(content) {
3090
3096
  if (firstSlide !== void 0) editor.slideSize = firstSlide.size;
3091
3097
  for (const slide of content.slides) {
3092
3098
  const odpSlide = editor.addSlide();
3093
- for (const shape of slide.shapes) appendShape(odpSlide, shape);
3099
+ for (const shape of slide.shapes) appendShape$1(odpSlide, shape);
3094
3100
  if (slide.notes.length > 0) odpSlide.notes = slide.notes;
3095
3101
  }
3096
3102
  return editor.toPackage();
3097
3103
  }
3098
- function appendShape(slide, shape) {
3104
+ function appendShape$1(slide, shape) {
3099
3105
  const [onlyBlock] = shape.blocks;
3100
3106
  if (shape.blocks.length === 1 && onlyBlock?.kind === "image") {
3101
3107
  const imageShape = slide.addImage({
@@ -3120,31 +3126,31 @@ function appendShape(slide, shape) {
3120
3126
  }
3121
3127
  //#endregion
3122
3128
  //#region src/edit/ods/scaffold.ts
3123
- const CONTENT_NS_PREFIXES = [
3129
+ const CONTENT_NS_PREFIXES$1 = [
3124
3130
  "office",
3125
3131
  "style",
3126
3132
  "text",
3127
3133
  "table",
3128
3134
  "fo"
3129
3135
  ];
3130
- const STYLES_NS_PREFIXES = [
3136
+ const STYLES_NS_PREFIXES$1 = [
3131
3137
  "office",
3132
3138
  "style",
3133
3139
  "table",
3134
3140
  "fo"
3135
3141
  ];
3136
- const META_NS_PREFIXES = [
3142
+ const META_NS_PREFIXES$1 = [
3137
3143
  "office",
3138
3144
  "meta",
3139
3145
  "dc"
3140
3146
  ];
3141
3147
  const OF_NAMESPACE_ATTR = { "xmlns:of": "urn:oasis:names:tc:opendocument:xmlns:of:1.2" };
3142
- const ODF_VERSION = "1.3";
3143
- const MASTER_PAGE_NAME = "Standard";
3148
+ const ODF_VERSION$1 = "1.3";
3149
+ const MASTER_PAGE_NAME$1 = "Standard";
3144
3150
  const SHEET_TABLE_STYLE_NAME = "OdsTable";
3145
3151
  const DEFAULT_SHEET_NAME = "Sheet1";
3146
3152
  const DEFAULT_MARGIN = "2cm";
3147
- function declaration() {
3153
+ function declaration$1() {
3148
3154
  return {
3149
3155
  type: "declaration",
3150
3156
  attributes: [
@@ -3163,7 +3169,7 @@ function declaration() {
3163
3169
  ]
3164
3170
  };
3165
3171
  }
3166
- function buildPageLayout() {
3172
+ function buildPageLayout$1() {
3167
3173
  return el("style:page-layout", { "style:name": "PM1" }, [el("style:page-layout-properties", {
3168
3174
  "fo:page-width": `${PAGE_SIZE_A4.widthPt}pt`,
3169
3175
  "fo:page-height": `${PAGE_SIZE_A4.heightPt}pt`,
@@ -3173,15 +3179,15 @@ function buildPageLayout() {
3173
3179
  "fo:margin-left": DEFAULT_MARGIN
3174
3180
  })]);
3175
3181
  }
3176
- function buildStylesXml() {
3182
+ function buildStylesXml$1() {
3177
3183
  return el("office:document-styles", {
3178
- ...xmlnsAttributes([...STYLES_NS_PREFIXES]),
3179
- "office:version": ODF_VERSION
3184
+ ...xmlnsAttributes([...STYLES_NS_PREFIXES$1]),
3185
+ "office:version": ODF_VERSION$1
3180
3186
  }, [
3181
3187
  el("office:styles"),
3182
- el("office:automatic-styles", {}, [buildPageLayout()]),
3188
+ el("office:automatic-styles", {}, [buildPageLayout$1()]),
3183
3189
  el("office:master-styles", {}, [el("style:master-page", {
3184
- "style:name": MASTER_PAGE_NAME,
3190
+ "style:name": MASTER_PAGE_NAME$1,
3185
3191
  "style:page-layout-name": "PM1"
3186
3192
  })])
3187
3193
  ]);
@@ -3190,7 +3196,7 @@ function buildSheetTableStyle() {
3190
3196
  return el("style:style", {
3191
3197
  "style:name": SHEET_TABLE_STYLE_NAME,
3192
3198
  "style:family": "table",
3193
- "style:master-page-name": MASTER_PAGE_NAME
3199
+ "style:master-page-name": MASTER_PAGE_NAME$1
3194
3200
  });
3195
3201
  }
3196
3202
  function buildCalculationSettings() {
@@ -3201,36 +3207,36 @@ function buildCalculationSettings() {
3201
3207
  "table:null-year": "1950"
3202
3208
  });
3203
3209
  }
3204
- function buildContentXml() {
3210
+ function buildContentXml$1() {
3205
3211
  const table = el("table:table", {
3206
3212
  "table:name": DEFAULT_SHEET_NAME,
3207
3213
  "table:style-name": SHEET_TABLE_STYLE_NAME
3208
3214
  });
3209
3215
  return el("office:document-content", {
3210
- ...xmlnsAttributes([...CONTENT_NS_PREFIXES]),
3216
+ ...xmlnsAttributes([...CONTENT_NS_PREFIXES$1]),
3211
3217
  ...OF_NAMESPACE_ATTR,
3212
- "office:version": ODF_VERSION
3218
+ "office:version": ODF_VERSION$1
3213
3219
  }, [el("office:automatic-styles", {}, [buildSheetTableStyle()]), el("office:body", {}, [el("office:spreadsheet", {}, [buildCalculationSettings(), table])])]);
3214
3220
  }
3215
- function buildMetaXml() {
3221
+ function buildMetaXml$1() {
3216
3222
  return el("office:document-meta", {
3217
- ...xmlnsAttributes([...META_NS_PREFIXES]),
3218
- "office:version": ODF_VERSION
3223
+ ...xmlnsAttributes([...META_NS_PREFIXES$1]),
3224
+ "office:version": ODF_VERSION$1
3219
3225
  }, [el("office:meta")]);
3220
3226
  }
3221
3227
  function createEmptyOdsPackage() {
3222
3228
  const pkg = { parts: {
3223
3229
  "content.xml": {
3224
3230
  kind: "xml",
3225
- nodes: [declaration(), buildContentXml()]
3231
+ nodes: [declaration$1(), buildContentXml$1()]
3226
3232
  },
3227
3233
  "styles.xml": {
3228
3234
  kind: "xml",
3229
- nodes: [declaration(), buildStylesXml()]
3235
+ nodes: [declaration$1(), buildStylesXml$1()]
3230
3236
  },
3231
3237
  "meta.xml": {
3232
3238
  kind: "xml",
3233
- nodes: [declaration(), buildMetaXml()]
3239
+ nodes: [declaration$1(), buildMetaXml$1()]
3234
3240
  }
3235
3241
  } };
3236
3242
  setDocumentMediaType(pkg, ODF_MEDIA_TYPES.ods);
@@ -3475,81 +3481,621 @@ var OdsCell = class {
3475
3481
  case "empty": this.displayText = "";
3476
3482
  }
3477
3483
  }
3478
- get formula() {
3479
- return attr$1(this.node, FORMULA_ATTR);
3484
+ get formula() {
3485
+ return attr$1(this.node, FORMULA_ATTR);
3486
+ }
3487
+ set formula(value) {
3488
+ if (value === void 0) {
3489
+ removeAttr(this.node, FORMULA_ATTR);
3490
+ return;
3491
+ }
3492
+ setAttr(this.node, FORMULA_ATTR, value);
3493
+ }
3494
+ get displayText() {
3495
+ return this.node.children.filter((child) => child.type === "element" && child.tag === "text:p").map((paragraph) => decodeOdfText$1(paragraph.children)).join("\n");
3496
+ }
3497
+ set displayText(value) {
3498
+ this.node.children = [el("text:p", {}, encodeOdfText(value))];
3499
+ }
3500
+ setStyledRuns(runs) {
3501
+ const textParagraph = el("text:p");
3502
+ this.node.children = [textParagraph];
3503
+ populateParagraph(new OdtParagraph(this.node.children, textParagraph, this.pkg), {
3504
+ kind: "paragraph",
3505
+ runs: [...runs]
3506
+ });
3507
+ }
3508
+ };
3509
+ //#endregion
3510
+ //#region src/edit/ods/sheet.ts
3511
+ const NAME_ATTR = "table:name";
3512
+ var OdsSheet = class {
3513
+ container;
3514
+ node;
3515
+ pkg;
3516
+ removed = false;
3517
+ constructor(container, node, pkg) {
3518
+ this.container = container;
3519
+ this.node = node;
3520
+ this.pkg = pkg;
3521
+ }
3522
+ live() {
3523
+ if (this.removed) throw new Error("this OdsSheet has been removed from the spreadsheet and can no longer be used");
3524
+ return this.node;
3525
+ }
3526
+ get name() {
3527
+ const value = attr$1(this.live(), NAME_ATTR);
3528
+ if (value === void 0) throw new Error("this table:table element has no table:name attribute");
3529
+ return value;
3530
+ }
3531
+ set name(value) {
3532
+ setAttr(this.live(), NAME_ATTR, value);
3533
+ }
3534
+ cell(row, column) {
3535
+ const node = resolveCellNode(this.live(), row, column);
3536
+ if (node.tag === "table:covered-table-cell") throw new Error(`cell (${row}, ${column}) is covered by a merged range -- address the merge's own anchor cell instead`);
3537
+ return new OdsCell(node, this.pkg);
3538
+ }
3539
+ cellAt(reference) {
3540
+ const parsed = parseCellReference(reference);
3541
+ if (parsed === void 0) throw new Error(`cellAt: "${reference}" is not a valid A1-style cell reference`);
3542
+ return this.cell(parsed.row, parsed.column);
3543
+ }
3544
+ mergeCells(startRow, startColumn, rowSpan, colSpan) {
3545
+ if (!Number.isInteger(rowSpan) || rowSpan < 1 || !Number.isInteger(colSpan) || colSpan < 1) throw new Error(`mergeCells: rowSpan and colSpan must be positive integers, got rowSpan=${rowSpan}, colSpan=${colSpan}`);
3546
+ const tableElement = this.live();
3547
+ const anchorNode = resolveCellNode(tableElement, startRow, startColumn);
3548
+ if (anchorNode.tag === "table:covered-table-cell") throw new Error(`mergeCells: (${startRow}, ${startColumn}) is already covered by another merged range`);
3549
+ if (rowSpan > 1) setAttr(anchorNode, "table:number-rows-spanned", String(rowSpan));
3550
+ if (colSpan > 1) setAttr(anchorNode, "table:number-columns-spanned", String(colSpan));
3551
+ for (let rowOffset = 0; rowOffset < rowSpan; rowOffset++) for (let columnOffset = 0; columnOffset < colSpan; columnOffset++) {
3552
+ if (rowOffset === 0 && columnOffset === 0) continue;
3553
+ const coveredNode = resolveCellNode(tableElement, startRow + rowOffset, startColumn + columnOffset);
3554
+ coveredNode.tag = COVERED_CELL_TAG;
3555
+ coveredNode.attributes = [];
3556
+ coveredNode.children = [];
3557
+ }
3558
+ return new OdsCell(anchorNode, this.pkg);
3559
+ }
3560
+ remove() {
3561
+ removeChild(this.container, this.live());
3562
+ this.removed = true;
3563
+ }
3564
+ };
3565
+ //#endregion
3566
+ //#region src/edit/ods/editor.ts
3567
+ const CONTENT_PART_PATH$1 = "content.xml";
3568
+ function directChild$1(parent, tag) {
3569
+ for (const child of parent.children) if (child.type === "element" && child.tag === tag) return child;
3570
+ }
3571
+ function findRoot$1(pkg) {
3572
+ const part = pkg.parts[CONTENT_PART_PATH$1];
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$1}`);
3575
+ return root;
3576
+ }
3577
+ function findOfficeSpreadsheet(pkg) {
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
+ return spreadsheet;
3582
+ }
3583
+ function ensureSheetTableStyleName(pkg) {
3584
+ const automaticStyles = ensureAutomaticStyles(pkg);
3585
+ if (automaticStyles.children.find((child) => child.type === "element" && child.tag === "style:style" && attr$1(child, "style:name") === "OdsTable") !== void 0) return SHEET_TABLE_STYLE_NAME;
3586
+ automaticStyles.children.push(el("style:style", {
3587
+ "style:name": SHEET_TABLE_STYLE_NAME,
3588
+ "style:family": "table",
3589
+ "style:master-page-name": MASTER_PAGE_NAME$1
3590
+ }));
3591
+ return SHEET_TABLE_STYLE_NAME;
3592
+ }
3593
+ var OdsEditor = class {
3594
+ pkg;
3595
+ constructor(pkg) {
3596
+ this.pkg = pkg;
3597
+ }
3598
+ sheets() {
3599
+ const spreadsheet = findOfficeSpreadsheet(this.pkg);
3600
+ const out = [];
3601
+ for (const child of spreadsheet.children) if (child.type === "element" && child.tag === "table:table") out.push(new OdsSheet(spreadsheet.children, child, this.pkg));
3602
+ return out;
3603
+ }
3604
+ sheet(name) {
3605
+ const found = this.sheets().find((candidate) => candidate.name === name);
3606
+ if (found === void 0) throw new Error(`no sheet named "${name}" exists in this spreadsheet`);
3607
+ return found;
3608
+ }
3609
+ addSheet(name) {
3610
+ const spreadsheet = findOfficeSpreadsheet(this.pkg);
3611
+ const tableElement = el("table:table", {
3612
+ "table:name": name,
3613
+ "table:style-name": ensureSheetTableStyleName(this.pkg)
3614
+ });
3615
+ spreadsheet.children.push(tableElement);
3616
+ return new OdsSheet(spreadsheet.children, tableElement, this.pkg);
3617
+ }
3618
+ removeSheetAt(index) {
3619
+ const spreadsheet = findOfficeSpreadsheet(this.pkg);
3620
+ const target = spreadsheet.children.filter((child) => child.type === "element" && child.tag === "table:table")[index];
3621
+ if (target === void 0) throw new Error(`sheet index ${index} does not exist`);
3622
+ const listIndex = spreadsheet.children.indexOf(target);
3623
+ spreadsheet.children.splice(listIndex, 1);
3624
+ }
3625
+ toPackage() {
3626
+ return this.pkg;
3627
+ }
3628
+ toBytes() {
3629
+ return encodePackage$2(this.pkg);
3630
+ }
3631
+ };
3632
+ function openOds(bytes) {
3633
+ return new OdsEditor(decodePackage$2(bytes));
3634
+ }
3635
+ function createOds() {
3636
+ return new OdsEditor(createEmptyOdsPackage());
3637
+ }
3638
+ //#endregion
3639
+ //#region src/edit/ods/content.ts
3640
+ function buildOdsPackage(content) {
3641
+ if (content.kind !== "spreadsheet") throw new Error("buildOdsPackage requires a spreadsheet ContentDocument");
3642
+ const editor = createOds();
3643
+ if (content.sheets.length > 0) editor.removeSheetAt(0);
3644
+ for (const sheet of content.sheets) {
3645
+ const odsSheet = editor.addSheet(sheet.name);
3646
+ for (const cell of sheet.cells) appendCell(odsSheet, cell);
3647
+ }
3648
+ return editor.toPackage();
3649
+ }
3650
+ function appendCell(odsSheet, cell) {
3651
+ const odsCell = odsSheet.cell(cell.row, cell.column);
3652
+ odsCell.value = cell.value;
3653
+ if (cell.formula !== void 0) odsCell.formula = cell.formula;
3654
+ if (cell.runs !== void 0 && cell.runs.length > 0) odsCell.setStyledRuns(cell.runs);
3655
+ else odsCell.displayText = cell.displayText;
3656
+ const rowSpan = cell.rowSpan ?? 1;
3657
+ const colSpan = cell.colSpan ?? 1;
3658
+ if (rowSpan > 1 || colSpan > 1) odsSheet.mergeCells(cell.row, cell.column, rowSpan, colSpan);
3659
+ }
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());
3480
4007
  }
3481
- set formula(value) {
3482
- if (value === void 0) {
3483
- removeAttr(this.node, FORMULA_ATTR);
3484
- return;
3485
- }
3486
- setAttr(this.node, FORMULA_ATTR, value);
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));
3487
4014
  }
3488
- get displayText() {
3489
- return this.node.children.filter((child) => child.type === "element" && child.tag === "text:p").map((paragraph) => decodeOdfText$1(paragraph.children)).join("\n");
4015
+ get fill() {
4016
+ return readGraphicFill(this.pkg, this.live());
3490
4017
  }
3491
- set displayText(value) {
3492
- this.node.children = [el("text:p", {}, encodeOdfText(value))];
4018
+ set fill(value) {
4019
+ setGraphicFill(this.pkg, this.live(), value);
3493
4020
  }
3494
- setStyledRuns(runs) {
3495
- const textParagraph = el("text:p");
3496
- this.node.children = [textParagraph];
3497
- populateParagraph(new OdtParagraph(this.node.children, textParagraph, this.pkg), {
3498
- kind: "paragraph",
3499
- runs: [...runs]
3500
- });
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;
3501
4040
  }
3502
4041
  };
3503
4042
  //#endregion
3504
- //#region src/edit/ods/sheet.ts
3505
- const NAME_ATTR = "table:name";
3506
- var OdsSheet = class {
4043
+ //#region src/edit/odg/page.ts
4044
+ var OdgPage = class {
3507
4045
  container;
3508
4046
  node;
3509
- pkg;
4047
+ context;
3510
4048
  removed = false;
3511
- constructor(container, node, pkg) {
4049
+ constructor(container, node, context) {
3512
4050
  this.container = container;
3513
4051
  this.node = node;
3514
- this.pkg = pkg;
4052
+ this.context = context;
3515
4053
  }
3516
4054
  live() {
3517
- if (this.removed) throw new Error("this OdsSheet has been removed from the spreadsheet and can no longer be used");
4055
+ if (this.removed) throw new Error("this OdgPage has been removed from the drawing and can no longer be used");
3518
4056
  return this.node;
3519
4057
  }
3520
- get name() {
3521
- const value = attr$1(this.live(), NAME_ATTR);
3522
- if (value === void 0) throw new Error("this table:table element has no table:name attribute");
3523
- return value;
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;
3524
4063
  }
3525
- set name(value) {
3526
- setAttr(this.live(), NAME_ATTR, value);
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);
3527
4069
  }
3528
- cell(row, column) {
3529
- const node = resolveCellNode(this.live(), row, column);
3530
- if (node.tag === "table:covered-table-cell") throw new Error(`cell (${row}, ${column}) is covered by a merged range -- address the merge's own anchor cell instead`);
3531
- return new OdsCell(node, this.pkg);
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);
3532
4075
  }
3533
- cellAt(reference) {
3534
- const parsed = parseCellReference(reference);
3535
- if (parsed === void 0) throw new Error(`cellAt: "${reference}" is not a valid A1-style cell reference`);
3536
- return this.cell(parsed.row, parsed.column);
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);
3537
4081
  }
3538
- mergeCells(startRow, startColumn, rowSpan, colSpan) {
3539
- if (!Number.isInteger(rowSpan) || rowSpan < 1 || !Number.isInteger(colSpan) || colSpan < 1) throw new Error(`mergeCells: rowSpan and colSpan must be positive integers, got rowSpan=${rowSpan}, colSpan=${colSpan}`);
3540
- const tableElement = this.live();
3541
- const anchorNode = resolveCellNode(tableElement, startRow, startColumn);
3542
- if (anchorNode.tag === "table:covered-table-cell") throw new Error(`mergeCells: (${startRow}, ${startColumn}) is already covered by another merged range`);
3543
- if (rowSpan > 1) setAttr(anchorNode, "table:number-rows-spanned", String(rowSpan));
3544
- if (colSpan > 1) setAttr(anchorNode, "table:number-columns-spanned", String(colSpan));
3545
- for (let rowOffset = 0; rowOffset < rowSpan; rowOffset++) for (let columnOffset = 0; columnOffset < colSpan; columnOffset++) {
3546
- if (rowOffset === 0 && columnOffset === 0) continue;
3547
- const coveredNode = resolveCellNode(tableElement, startRow + rowOffset, startColumn + columnOffset);
3548
- coveredNode.tag = COVERED_CELL_TAG;
3549
- coveredNode.attributes = [];
3550
- coveredNode.children = [];
3551
- }
3552
- return new OdsCell(anchorNode, this.pkg);
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);
3553
4099
  }
3554
4100
  remove() {
3555
4101
  removeChild(this.container, this.live());
@@ -3557,64 +4103,78 @@ var OdsSheet = class {
3557
4103
  }
3558
4104
  };
3559
4105
  //#endregion
3560
- //#region src/edit/ods/editor.ts
4106
+ //#region src/edit/odg/editor.ts
3561
4107
  const CONTENT_PART_PATH = "content.xml";
4108
+ const STYLES_PART_PATH = "styles.xml";
3562
4109
  function directChild(parent, tag) {
3563
4110
  for (const child of parent.children) if (child.type === "element" && child.tag === tag) return child;
3564
4111
  }
3565
- function findRoot(pkg) {
3566
- const part = pkg.parts[CONTENT_PART_PATH];
4112
+ function findRoot(pkg, partPath) {
4113
+ const part = pkg.parts[partPath];
3567
4114
  const root = part?.kind === "xml" ? part.nodes.find((n) => n.type === "element") : void 0;
3568
- if (root === void 0) throw new Error(`package has no root element at ${CONTENT_PART_PATH}`);
4115
+ if (root === void 0) throw new Error(`package has no root element at ${partPath}`);
3569
4116
  return root;
3570
4117
  }
3571
- function findOfficeSpreadsheet(pkg) {
3572
- const body = directChild(findRoot(pkg), "office:body");
3573
- const spreadsheet = body === void 0 ? void 0 : directChild(body, "office:spreadsheet");
3574
- if (spreadsheet === void 0) throw new Error(`${CONTENT_PART_PATH} has no office:body/office:spreadsheet element`);
3575
- return spreadsheet;
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;
3576
4123
  }
3577
- function ensureSheetTableStyleName(pkg) {
3578
- const automaticStyles = ensureAutomaticStyles(pkg);
3579
- if (automaticStyles.children.find((child) => child.type === "element" && child.tag === "style:style" && attr$1(child, "style:name") === "OdsTable") !== void 0) return SHEET_TABLE_STYLE_NAME;
3580
- automaticStyles.children.push(el("style:style", {
3581
- "style:name": SHEET_TABLE_STYLE_NAME,
3582
- "style:family": "table",
3583
- "style:master-page-name": MASTER_PAGE_NAME
3584
- }));
3585
- return SHEET_TABLE_STYLE_NAME;
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;
3586
4129
  }
3587
- var OdsEditor = class {
4130
+ var OdgEditor = class {
3588
4131
  pkg;
3589
4132
  constructor(pkg) {
3590
4133
  this.pkg = pkg;
3591
4134
  }
3592
- sheets() {
3593
- const spreadsheet = findOfficeSpreadsheet(this.pkg);
4135
+ pages() {
4136
+ const drawing = findOfficeDrawing(this.pkg);
3594
4137
  const out = [];
3595
- for (const child of spreadsheet.children) if (child.type === "element" && child.tag === "table:table") out.push(new OdsSheet(spreadsheet.children, child, this.pkg));
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
+ }
3596
4142
  return out;
3597
4143
  }
3598
- sheet(name) {
3599
- const found = this.sheets().find((candidate) => candidate.name === name);
3600
- if (found === void 0) throw new Error(`no sheet named "${name}" exists in this spreadsheet`);
3601
- return found;
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);
3602
4150
  }
3603
- addSheet(name) {
3604
- const spreadsheet = findOfficeSpreadsheet(this.pkg);
3605
- const tableElement = el("table:table", {
3606
- "table:name": name,
3607
- "table:style-name": ensureSheetTableStyleName(this.pkg)
3608
- });
3609
- spreadsheet.children.push(tableElement);
3610
- return new OdsSheet(spreadsheet.children, tableElement, this.pkg);
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);
3611
4157
  }
3612
- removeSheetAt(index) {
3613
- const spreadsheet = findOfficeSpreadsheet(this.pkg);
3614
- const target = spreadsheet.children.filter((child) => child.type === "element" && child.tag === "table:table")[index];
3615
- if (target === void 0) throw new Error(`sheet index ${index} does not exist`);
3616
- const listIndex = spreadsheet.children.indexOf(target);
3617
- spreadsheet.children.splice(listIndex, 1);
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
+ }];
3618
4178
  }
3619
4179
  toPackage() {
3620
4180
  return this.pkg;
@@ -3623,33 +4183,71 @@ var OdsEditor = class {
3623
4183
  return encodePackage$2(this.pkg);
3624
4184
  }
3625
4185
  };
3626
- function openOds(bytes) {
3627
- return new OdsEditor(decodePackage$2(bytes));
4186
+ function openOdg(bytes) {
4187
+ return new OdgEditor(decodePackage$2(bytes));
3628
4188
  }
3629
- function createOds() {
3630
- return new OdsEditor(createEmptyOdsPackage());
4189
+ function createOdg() {
4190
+ return new OdgEditor(createEmptyOdgPackage());
3631
4191
  }
3632
4192
  //#endregion
3633
- //#region src/edit/ods/content.ts
3634
- function buildOdsPackage(content) {
3635
- if (content.kind !== "spreadsheet") throw new Error("buildOdsPackage requires a spreadsheet ContentDocument");
3636
- const editor = createOds();
3637
- if (content.sheets.length > 0) editor.removeSheetAt(0);
3638
- for (const sheet of content.sheets) {
3639
- const odsSheet = editor.addSheet(sheet.name);
3640
- for (const cell of sheet.cells) appendCell(odsSheet, cell);
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);
3641
4203
  }
3642
4204
  return editor.toPackage();
3643
4205
  }
3644
- function appendCell(odsSheet, cell) {
3645
- const odsCell = odsSheet.cell(cell.row, cell.column);
3646
- odsCell.value = cell.value;
3647
- if (cell.formula !== void 0) odsCell.formula = cell.formula;
3648
- if (cell.runs !== void 0 && cell.runs.length > 0) odsCell.setStyledRuns(cell.runs);
3649
- else odsCell.displayText = cell.displayText;
3650
- const rowSpan = cell.rowSpan ?? 1;
3651
- const colSpan = cell.colSpan ?? 1;
3652
- if (rowSpan > 1 || colSpan > 1) odsSheet.mergeCells(cell.row, cell.column, rowSpan, colSpan);
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
+ }
3653
4251
  }
3654
4252
  //#endregion
3655
4253
  //#region src/bytes/crc32.ts
@@ -7603,11 +8201,15 @@ function writeText(writer, item, context, substitutions) {
7603
8201
  writeUnderline(writer, item, item.widthPt ?? encoded.width1000 / 1e3 * item.sizePt * scale, context.measurer);
7604
8202
  }
7605
8203
  }
7606
- function paintOperatorFor(fill, stroke) {
7607
- if (fill !== void 0 && stroke !== void 0) return "B";
7608
- if (fill !== void 0) return "f";
8204
+ function paintOperatorFor(fill, stroke, fillRule) {
8205
+ const evenOdd = fillRule === "evenodd";
8206
+ if (fill !== void 0 && stroke !== void 0) return evenOdd ? "B*" : "B";
8207
+ if (fill !== void 0) return evenOdd ? "f*" : "f";
7609
8208
  if (stroke !== void 0) return "S";
7610
8209
  }
8210
+ function formatPoint(x, y) {
8211
+ return `${formatNumber(x)} ${formatNumber(y)}`;
8212
+ }
7611
8213
  function writeFillAndStroke(writer, fill, stroke) {
7612
8214
  if (fill !== void 0) writeRgbOperator(writer, fill, "rg");
7613
8215
  if (stroke !== void 0) {
@@ -7638,12 +8240,24 @@ function writeEllipse(writer, item) {
7638
8240
  const ry = item.heightPt / 2;
7639
8241
  const kx = rx * BEZIER_KAPPA;
7640
8242
  const ky = ry * BEZIER_KAPPA;
7641
- const point = (x, y) => `${formatNumber(x)} ${formatNumber(y)}`;
7642
- writer.writeAscii(`${point(cx + rx, cy)} m\n`);
7643
- writer.writeAscii(`${point(cx + rx, cy + ky)} ${point(cx + kx, cy + ry)} ${point(cx, cy + ry)} c\n`);
7644
- writer.writeAscii(`${point(cx - kx, cy + ry)} ${point(cx - rx, cy + ky)} ${point(cx - rx, cy)} c\n`);
7645
- writer.writeAscii(`${point(cx - rx, cy - ky)} ${point(cx - kx, cy - ry)} ${point(cx, cy - ry)} c\n`);
7646
- writer.writeAscii(`${point(cx + kx, cy - ry)} ${point(cx + rx, cy - ky)} ${point(cx + rx, cy)} c\n`);
8243
+ writer.writeAscii(`${formatPoint(cx + rx, cy)} m\n`);
8244
+ writer.writeAscii(`${formatPoint(cx + rx, cy + ky)} ${formatPoint(cx + kx, cy + ry)} ${formatPoint(cx, cy + ry)} c\n`);
8245
+ writer.writeAscii(`${formatPoint(cx - kx, cy + ry)} ${formatPoint(cx - rx, cy + ky)} ${formatPoint(cx - rx, cy)} c\n`);
8246
+ writer.writeAscii(`${formatPoint(cx - rx, cy - ky)} ${formatPoint(cx - kx, cy - ry)} ${formatPoint(cx, cy - ry)} c\n`);
8247
+ writer.writeAscii(`${formatPoint(cx + kx, cy - ry)} ${formatPoint(cx + rx, cy - ky)} ${formatPoint(cx + rx, cy)} c\n`);
8248
+ writer.writeAscii(`${paint}\n`);
8249
+ }
8250
+ function writeSubpath(writer, subpath) {
8251
+ writer.writeAscii(`${formatPoint(subpath.startXPt, subpath.startYPt)} m\n`);
8252
+ for (const segment of subpath.segments) if (segment.kind === "line") writer.writeAscii(`${formatPoint(segment.xPt, segment.yPt)} l\n`);
8253
+ else writer.writeAscii(`${formatPoint(segment.c1xPt, segment.c1yPt)} ${formatPoint(segment.c2xPt, segment.c2yPt)} ${formatPoint(segment.xPt, segment.yPt)} c\n`);
8254
+ if (subpath.closed) writer.writeAscii("h\n");
8255
+ }
8256
+ function writePath(writer, item) {
8257
+ const paint = paintOperatorFor(item.fill, item.stroke, item.fillRule);
8258
+ if (paint === void 0) return;
8259
+ writeFillAndStroke(writer, item.fill, item.stroke);
8260
+ for (const subpath of item.subpaths) writeSubpath(writer, subpath);
7647
8261
  writer.writeAscii(`${paint}\n`);
7648
8262
  }
7649
8263
  function writeImage(writer, item, context) {
@@ -7662,6 +8276,7 @@ function writeContentStream(items, context) {
7662
8276
  else if (item.kind === "rect") writeRect(writer, item);
7663
8277
  else if (item.kind === "line") writeLine(writer, item);
7664
8278
  else if (item.kind === "ellipse") writeEllipse(writer, item);
8279
+ else if (item.kind === "path") writePath(writer, item);
7665
8280
  return {
7666
8281
  bytes: writer.toBytes(),
7667
8282
  substitutions
@@ -8468,6 +9083,17 @@ function readOdsContent(pkg) {
8468
9083
  };
8469
9084
  }
8470
9085
  //#endregion
9086
+ //#region src/odf/odg/read.ts
9087
+ function readOdgContent(pkg) {
9088
+ const odgDoc = readOdg(pkg);
9089
+ return {
9090
+ kind: "drawing",
9091
+ formatVersion: 1,
9092
+ metadata: { ...odgDoc.metadata },
9093
+ pages: odgDoc.pages
9094
+ };
9095
+ }
9096
+ //#endregion
8471
9097
  //#region src/pdf/text-layout.ts
8472
9098
  const WORD_OR_WHITESPACE_PATTERN = /\n|\s+|\S+/g;
8473
9099
  function atomizeRuns(runs, measurer) {
@@ -9499,6 +10125,118 @@ function convertSpreadsheetToLayout(doc, options) {
9499
10125
  };
9500
10126
  }
9501
10127
  //#endregion
10128
+ //#region src/layout/drawing.ts
10129
+ function convertRectVector(vector, pageHeightPt, out) {
10130
+ const flipped = flipY(vector.frame, pageHeightPt);
10131
+ out.push({
10132
+ kind: "rect",
10133
+ xPt: flipped.xPt,
10134
+ yPt: flipped.yPt,
10135
+ widthPt: flipped.widthPt,
10136
+ heightPt: flipped.heightPt,
10137
+ fill: vector.fill,
10138
+ stroke: vector.stroke,
10139
+ sourcePath: vector.sourcePath
10140
+ });
10141
+ }
10142
+ function convertEllipseVector(vector, pageHeightPt, out) {
10143
+ const flipped = flipY(vector.frame, pageHeightPt);
10144
+ out.push({
10145
+ kind: "ellipse",
10146
+ xPt: flipped.xPt,
10147
+ yPt: flipped.yPt,
10148
+ widthPt: flipped.widthPt,
10149
+ heightPt: flipped.heightPt,
10150
+ fill: vector.fill,
10151
+ stroke: vector.stroke,
10152
+ sourcePath: vector.sourcePath
10153
+ });
10154
+ }
10155
+ function convertLineVector(vector, pageHeightPt, out) {
10156
+ out.push({
10157
+ kind: "line",
10158
+ x1Pt: vector.from.xPt,
10159
+ y1Pt: pageHeightPt - vector.from.yPt,
10160
+ x2Pt: vector.to.xPt,
10161
+ y2Pt: pageHeightPt - vector.to.yPt,
10162
+ color: vector.stroke.color,
10163
+ widthPt: vector.stroke.widthPt,
10164
+ sourcePath: vector.sourcePath
10165
+ });
10166
+ }
10167
+ function placePathPoint(frame, point, pageHeightPt) {
10168
+ return {
10169
+ xPt: frame.xPt + point.xPt,
10170
+ yPt: pageHeightPt - frame.yPt - point.yPt
10171
+ };
10172
+ }
10173
+ function convertPathVector(vector, pageHeightPt, out) {
10174
+ const subpaths = vector.subpaths.map((subpath) => {
10175
+ const start = placePathPoint(vector.frame, subpath.start, pageHeightPt);
10176
+ return {
10177
+ startXPt: start.xPt,
10178
+ startYPt: start.yPt,
10179
+ closed: subpath.closed,
10180
+ segments: subpath.segments.map((segment) => {
10181
+ if (segment.kind === "line") {
10182
+ const to = placePathPoint(vector.frame, segment.to, pageHeightPt);
10183
+ return {
10184
+ kind: "line",
10185
+ xPt: to.xPt,
10186
+ yPt: to.yPt
10187
+ };
10188
+ }
10189
+ const control1 = placePathPoint(vector.frame, segment.control1, pageHeightPt);
10190
+ const control2 = placePathPoint(vector.frame, segment.control2, pageHeightPt);
10191
+ const to = placePathPoint(vector.frame, segment.to, pageHeightPt);
10192
+ return {
10193
+ kind: "cubic",
10194
+ c1xPt: control1.xPt,
10195
+ c1yPt: control1.yPt,
10196
+ c2xPt: control2.xPt,
10197
+ c2yPt: control2.yPt,
10198
+ xPt: to.xPt,
10199
+ yPt: to.yPt
10200
+ };
10201
+ })
10202
+ };
10203
+ });
10204
+ out.push({
10205
+ kind: "path",
10206
+ subpaths,
10207
+ fill: vector.fill,
10208
+ fillRule: vector.fillRule,
10209
+ stroke: vector.stroke,
10210
+ sourcePath: vector.sourcePath
10211
+ });
10212
+ }
10213
+ function convertVector(vector, pageHeightPt, out) {
10214
+ if (vector.kind === "rect") convertRectVector(vector, pageHeightPt, out);
10215
+ else if (vector.kind === "ellipse") convertEllipseVector(vector, pageHeightPt, out);
10216
+ else if (vector.kind === "line") convertLineVector(vector, pageHeightPt, out);
10217
+ else convertPathVector(vector, pageHeightPt, out);
10218
+ }
10219
+ function convertPage(page, measurer, images) {
10220
+ const items = [];
10221
+ for (const vector of page.vectors) convertVector(vector, page.size.heightPt, items);
10222
+ for (const shape of page.shapes) convertShape(shape, page.size.heightPt, measurer, images, items);
10223
+ return {
10224
+ widthPt: page.size.widthPt,
10225
+ heightPt: page.size.heightPt,
10226
+ items
10227
+ };
10228
+ }
10229
+ function convertDrawingToLayout(doc, options) {
10230
+ const images = {};
10231
+ const pages = doc.pages.map((page) => convertPage(page, options.measurer, images));
10232
+ return {
10233
+ formatVersion: LAYOUT_FORMAT_VERSION$1,
10234
+ metadata: doc.metadata,
10235
+ pages,
10236
+ images
10237
+ };
10238
+ }
10239
+ //#endregion
9502
10240
  //#region src/layout/reconstruct.ts
9503
10241
  const ZERO_MARGINS = {
9504
10242
  topPt: 0,
@@ -9878,6 +10616,14 @@ function odsToPdf(bytes, options) {
9878
10616
  onSubstitution: options?.onSubstitution
9879
10617
  });
9880
10618
  }
10619
+ function odgToPdf(bytes, options) {
10620
+ const content = readOdgContent(decodePackage$2(bytes));
10621
+ if (content.kind !== "drawing") throw new Error("readOdgContent returned a non-drawing ContentDocument");
10622
+ return writePdf(convertDrawingToLayout(content, { measurer: createStandardFontMeasurer() }), {
10623
+ signal: options?.signal,
10624
+ onSubstitution: options?.onSubstitution
10625
+ });
10626
+ }
9881
10627
  function pdfToDocx(bytes, options) {
9882
10628
  const content = reconstructWordprocessing(readPdf(bytes, {
9883
10629
  signal: options?.signal,
@@ -9947,6 +10693,10 @@ const SUPPORTED_CONVERSIONS = [
9947
10693
  source: "ods",
9948
10694
  target: "pdf"
9949
10695
  },
10696
+ {
10697
+ source: "odg",
10698
+ target: "pdf"
10699
+ },
9950
10700
  {
9951
10701
  source: "pdf",
9952
10702
  target: "docx"
@@ -10052,6 +10802,19 @@ function createLocalDocumentConverter() {
10052
10802
  diagnostics
10053
10803
  });
10054
10804
  }
10805
+ if (source.format === "odg" && targetFormat === "pdf") {
10806
+ const bytes = odgToPdf(source.bytes, {
10807
+ signal: options.signal,
10808
+ onSubstitution: (s, c) => diagnostics.push(substitutionDiagnostic(s, c))
10809
+ });
10810
+ return Promise.resolve({
10811
+ document: {
10812
+ format: "pdf",
10813
+ bytes
10814
+ },
10815
+ diagnostics
10816
+ });
10817
+ }
10055
10818
  if (source.format === "pdf" && targetFormat === "docx") {
10056
10819
  const bytes = pdfToDocx(source.bytes, {
10057
10820
  signal: options.signal,
@@ -10115,4 +10878,4 @@ function fixedClock(date) {
10115
10878
  return { now: () => date };
10116
10879
  }
10117
10880
  //#endregion
10118
- export { AttributeSchema, BinaryPartSchema, COLOR_BLACK, CONTENT_FORMAT_VERSION, CommentSchema, CompactPackageSchema, CompactPartSchema, CompactXmlNodeSchema, ContentBlockSchema, ContentCellValueSchema, ContentDocumentSchema, ContentImageBlockSchema, ContentPageBreakSchema, ContentParagraphSchema, ContentRunSchema, ContentSectionSchema, ContentShapeSchema, ContentSheetCellSchema, ContentSheetColumnSchema, ContentSheetPrintRangeSchema, ContentSheetPrintSettingsSchema, ContentSheetRepeatRangeSchema, ContentSheetRowSchema, ContentSheetSchema, ContentSlideSchema, ContentTableCellSchema, ContentTableRowSchema, ContentTableSchema, DEFAULT_LAYOUT_FONT, DefinedNameSchema, DocxBytesSchema, DocxEditor, DocxParagraph, DocxRun, DocxTable, DocxTableCell, DocxTableRow, LAYOUT_FORMAT_VERSION, NOOP_DIAGNOSTIC_SINK, OdgBytesSchema, OdpBytesSchema, OdpEditor, OdpShape, OdpSlide, OdsBytesSchema, 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, convertPresentationToLayout, convertSpreadsheetToLayout, convertWordprocessingToLayout, createDocx, createLocalDocumentConverter, createOdp, createOds, createOdt, createPptx, decodeCompactPackage, decodeEntities, decodePackage, docxPdfCodec, docxToPdf, elementsWithTag, encodeCompactPackage, encodePackage, fixedClock, flipY, fromCompact, isCompactXmlNode, isContentBlock, isXmlNode, odpPdfCodec, odpToPdf, odsToPdf, odtPdfCodec, odtToPdf, openDocx, openOdp, openOds, openOdt, openPptx, packageCodec, parsePackage, parseXml, pdfCodec, pdfToDocx, pdfToOdp, pdfToOdt, pdfToPptx, pptxPdfCodec, pptxToPdf, readDocxContent, 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 };