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.cjs CHANGED
@@ -24,6 +24,12 @@ const ContentDocumentSchema = zod.z.discriminatedUnion("kind", [
24
24
  formatVersion: zod.z.literal(1),
25
25
  metadata: document_content_model.LayoutMetadataSchema,
26
26
  sheets: zod.z.array(document_content_model.ContentSheetSchema)
27
+ }),
28
+ zod.z.object({
29
+ kind: zod.z.literal("drawing"),
30
+ formatVersion: zod.z.literal(1),
31
+ metadata: document_content_model.LayoutMetadataSchema,
32
+ pages: zod.z.array(document_content_model.ContentDrawPageSchema)
27
33
  })
28
34
  ]);
29
35
  //#endregion
@@ -530,7 +536,7 @@ function needsSpacePreserve(text) {
530
536
  }
531
537
  //#endregion
532
538
  //#region src/edit/docx/run.ts
533
- function directChild$9(parent, tag) {
539
+ function directChild$10(parent, tag) {
534
540
  for (const child of parent.children) if (child.type === "element" && child.tag === tag) return child;
535
541
  }
536
542
  function appendUElement(rPr, value) {
@@ -539,7 +545,7 @@ function appendUElement(rPr, value) {
539
545
  return created;
540
546
  }
541
547
  function findOrCreateT(run) {
542
- const existing = directChild$9(run, "w:t");
548
+ const existing = directChild$10(run, "w:t");
543
549
  if (existing !== void 0) return existing;
544
550
  const created = el("w:t");
545
551
  run.children.push(created);
@@ -559,7 +565,7 @@ var DocxRun = class {
559
565
  }
560
566
  rPr(create) {
561
567
  const node = this.live();
562
- return create ? ensureFirstChild(node, "w:rPr") : directChild$9(node, "w:rPr");
568
+ return create ? ensureFirstChild(node, "w:rPr") : directChild$10(node, "w:rPr");
563
569
  }
564
570
  get text() {
565
571
  return (0, ooxml_js.textContent)(this.live());
@@ -583,14 +589,14 @@ var DocxRun = class {
583
589
  }
584
590
  get underline() {
585
591
  const rPr = this.rPr(false);
586
- const uElement = rPr === void 0 ? void 0 : directChild$9(rPr, "w:u");
592
+ const uElement = rPr === void 0 ? void 0 : directChild$10(rPr, "w:u");
587
593
  if (uElement === void 0) return false;
588
594
  for (const a of uElement.attributes) if (a.name === "w:val") return a.value !== "none";
589
595
  return true;
590
596
  }
591
597
  set underline(value) {
592
598
  const rPr = this.rPr(true);
593
- const existing = directChild$9(rPr, "w:u");
599
+ const existing = directChild$10(rPr, "w:u");
594
600
  if (existing === void 0) {
595
601
  appendUElement(rPr, value);
596
602
  return;
@@ -664,7 +670,7 @@ function buildRun$1(init = {}) {
664
670
  }
665
671
  //#endregion
666
672
  //#region src/edit/docx/paragraph.ts
667
- function directChild$8(parent, tag) {
673
+ function directChild$9(parent, tag) {
668
674
  for (const child of parent.children) if (child.type === "element" && child.tag === tag) return child;
669
675
  }
670
676
  var DocxParagraph = class {
@@ -683,7 +689,7 @@ var DocxParagraph = class {
683
689
  }
684
690
  pPr(create) {
685
691
  const node = this.live();
686
- return create ? ensureFirstChild(node, "w:pPr") : directChild$8(node, "w:pPr");
692
+ return create ? ensureFirstChild(node, "w:pPr") : directChild$9(node, "w:pPr");
687
693
  }
688
694
  get text() {
689
695
  return (0, ooxml_js.textContent)(this.live());
@@ -720,7 +726,7 @@ var DocxParagraph = class {
720
726
  set styleId(value) {
721
727
  if (value === void 0) {
722
728
  const pPr = this.pPr(false);
723
- const existing = pPr === void 0 ? void 0 : directChild$8(pPr, "w:pStyle");
729
+ const existing = pPr === void 0 ? void 0 : directChild$9(pPr, "w:pStyle");
724
730
  if (existing !== void 0 && pPr !== void 0) removeChild(pPr.children, existing);
725
731
  return;
726
732
  }
@@ -732,7 +738,7 @@ var DocxParagraph = class {
732
738
  set alignment(value) {
733
739
  if (value === void 0) {
734
740
  const pPr = this.pPr(false);
735
- const existing = pPr === void 0 ? void 0 : directChild$8(pPr, "w:jc");
741
+ const existing = pPr === void 0 ? void 0 : directChild$9(pPr, "w:jc");
736
742
  if (existing !== void 0 && pPr !== void 0) removeChild(pPr.children, existing);
737
743
  return;
738
744
  }
@@ -740,12 +746,12 @@ var DocxParagraph = class {
740
746
  }
741
747
  get list() {
742
748
  const pPr = this.pPr(false);
743
- const numPr = pPr === void 0 ? void 0 : directChild$8(pPr, "w:numPr");
749
+ const numPr = pPr === void 0 ? void 0 : directChild$9(pPr, "w:numPr");
744
750
  if (numPr === void 0) return;
745
- const numIdElement = directChild$8(numPr, "w:numId");
751
+ const numIdElement = directChild$9(numPr, "w:numId");
746
752
  const numId = numIdElement === void 0 ? void 0 : (0, ooxml_js.attr)(numIdElement, "w:val");
747
753
  if (numId === void 0) return;
748
- const ilvlElement = directChild$8(numPr, "w:ilvl");
754
+ const ilvlElement = directChild$9(numPr, "w:ilvl");
749
755
  const ilvl = ilvlElement === void 0 ? void 0 : (0, ooxml_js.attr)(ilvlElement, "w:val");
750
756
  return {
751
757
  numId,
@@ -755,7 +761,7 @@ var DocxParagraph = class {
755
761
  set list(value) {
756
762
  const pPr = this.pPr(true);
757
763
  if (value === void 0) {
758
- const existing = directChild$8(pPr, "w:numPr");
764
+ const existing = directChild$9(pPr, "w:numPr");
759
765
  if (existing !== void 0) removeChild(pPr.children, existing);
760
766
  return;
761
767
  }
@@ -789,7 +795,7 @@ function buildParagraph$1(init = {}) {
789
795
  const CONTENT_TYPES_NS$1 = "http://schemas.openxmlformats.org/package/2006/content-types";
790
796
  const RELS_NS$1 = "http://schemas.openxmlformats.org/package/2006/relationships";
791
797
  const WORDML_NS = "http://schemas.openxmlformats.org/wordprocessingml/2006/main";
792
- function declaration$4() {
798
+ function declaration$5() {
793
799
  return {
794
800
  type: "declaration",
795
801
  attributes: [
@@ -858,23 +864,23 @@ function createEmptyDocxPackage() {
858
864
  return { parts: {
859
865
  "[Content_Types].xml": {
860
866
  kind: "xml",
861
- nodes: [declaration$4(), contentTypes]
867
+ nodes: [declaration$5(), contentTypes]
862
868
  },
863
869
  "_rels/.rels": {
864
870
  kind: "xml",
865
- nodes: [declaration$4(), rootRels]
871
+ nodes: [declaration$5(), rootRels]
866
872
  },
867
873
  "word/document.xml": {
868
874
  kind: "xml",
869
- nodes: [declaration$4(), document]
875
+ nodes: [declaration$5(), document]
870
876
  },
871
877
  "word/_rels/document.xml.rels": {
872
878
  kind: "xml",
873
- nodes: [declaration$4(), documentRels]
879
+ nodes: [declaration$5(), documentRels]
874
880
  },
875
881
  "word/styles.xml": {
876
882
  kind: "xml",
877
- nodes: [declaration$4(), styles]
883
+ nodes: [declaration$5(), styles]
878
884
  }
879
885
  } };
880
886
  }
@@ -1165,7 +1171,7 @@ const SLIDE_LAYOUT_REL_TYPE = "http://schemas.openxmlformats.org/officeDocument/
1165
1171
  const THEME_REL_TYPE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme";
1166
1172
  const NOTES_MASTER_REL_TYPE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/notesMaster";
1167
1173
  const MIN_MASTER_OR_LAYOUT_ID = 2147483648;
1168
- function declaration$3() {
1174
+ function declaration$4() {
1169
1175
  return {
1170
1176
  type: "declaration",
1171
1177
  attributes: [
@@ -1315,7 +1321,7 @@ function ensureNotesMaster(pkg) {
1315
1321
  });
1316
1322
  pkg.parts[NOTES_MASTER_PART_PATH] = {
1317
1323
  kind: "xml",
1318
- nodes: [declaration$3(), buildNotesMaster()]
1324
+ nodes: [declaration$4(), buildNotesMaster()]
1319
1325
  };
1320
1326
  ensureContentTypeOverride(pkg, NOTES_MASTER_PART_PATH, NOTES_MASTER_CONTENT_TYPE);
1321
1327
  const presentationToNotesMasterTarget = buildRelativeTarget(PRESENTATION_PART_PATH$1, NOTES_MASTER_PART_PATH);
@@ -1354,15 +1360,15 @@ function createEmptyPptxPackage() {
1354
1360
  const pkg = { parts: {
1355
1361
  "[Content_Types].xml": {
1356
1362
  kind: "xml",
1357
- nodes: [declaration$3(), contentTypes]
1363
+ nodes: [declaration$4(), contentTypes]
1358
1364
  },
1359
1365
  "_rels/.rels": {
1360
1366
  kind: "xml",
1361
- nodes: [declaration$3(), rootRels]
1367
+ nodes: [declaration$4(), rootRels]
1362
1368
  },
1363
1369
  [PRESENTATION_PART_PATH$1]: {
1364
1370
  kind: "xml",
1365
- nodes: [declaration$3(), el("p:presentation", {
1371
+ nodes: [declaration$4(), el("p:presentation", {
1366
1372
  "xmlns:p": PML_NS,
1367
1373
  "xmlns:r": R_NS
1368
1374
  })]
@@ -1375,7 +1381,7 @@ function createEmptyPptxPackage() {
1375
1381
  });
1376
1382
  pkg.parts[SLIDE_LAYOUT_PART_PATH] = {
1377
1383
  kind: "xml",
1378
- nodes: [declaration$3(), buildSlideLayout()]
1384
+ nodes: [declaration$4(), buildSlideLayout()]
1379
1385
  };
1380
1386
  ensureContentTypeOverride(pkg, SLIDE_LAYOUT_PART_PATH, SLIDE_LAYOUT_CONTENT_TYPE);
1381
1387
  const masterToLayoutTarget = buildRelativeTarget(SLIDE_MASTER_PART_PATH, SLIDE_LAYOUT_PART_PATH);
@@ -1390,12 +1396,12 @@ function createEmptyPptxPackage() {
1390
1396
  });
1391
1397
  pkg.parts[SLIDE_MASTER_PART_PATH] = {
1392
1398
  kind: "xml",
1393
- nodes: [declaration$3(), buildSlideMaster(masterToLayoutRelId)]
1399
+ nodes: [declaration$4(), buildSlideMaster(masterToLayoutRelId)]
1394
1400
  };
1395
1401
  ensureContentTypeOverride(pkg, SLIDE_MASTER_PART_PATH, SLIDE_MASTER_CONTENT_TYPE);
1396
1402
  pkg.parts[THEME_PART_PATH] = {
1397
1403
  kind: "xml",
1398
- nodes: [declaration$3(), buildTheme()]
1404
+ nodes: [declaration$4(), buildTheme()]
1399
1405
  };
1400
1406
  ensureContentTypeOverride(pkg, THEME_PART_PATH, THEME_CONTENT_TYPE);
1401
1407
  const presentationToMasterTarget = buildRelativeTarget(PRESENTATION_PART_PATH$1, SLIDE_MASTER_PART_PATH);
@@ -1420,7 +1426,7 @@ function createEmptyPptxPackage() {
1420
1426
  }
1421
1427
  //#endregion
1422
1428
  //#region src/edit/pptx/shape.ts
1423
- function directChild$7(parent, tag) {
1429
+ function directChild$8(parent, tag) {
1424
1430
  for (const child of parent.children) if (child.type === "element" && child.tag === tag) return child;
1425
1431
  }
1426
1432
  function parseEmuAttr(element, name) {
@@ -1441,7 +1447,7 @@ var PptxShape = class {
1441
1447
  }
1442
1448
  spPrElement(create) {
1443
1449
  const node = this.live();
1444
- const existing = directChild$7(node, "p:spPr");
1450
+ const existing = directChild$8(node, "p:spPr");
1445
1451
  if (existing !== void 0 || !create) return existing;
1446
1452
  const created = el("p:spPr");
1447
1453
  node.children.push(created);
@@ -1449,10 +1455,10 @@ var PptxShape = class {
1449
1455
  }
1450
1456
  get frame() {
1451
1457
  const spPr = this.spPrElement(false);
1452
- const xfrm = spPr === void 0 ? void 0 : directChild$7(spPr, "a:xfrm");
1458
+ const xfrm = spPr === void 0 ? void 0 : directChild$8(spPr, "a:xfrm");
1453
1459
  if (xfrm === void 0) return;
1454
- const off = directChild$7(xfrm, "a:off");
1455
- const ext = directChild$7(xfrm, "a:ext");
1460
+ const off = directChild$8(xfrm, "a:off");
1461
+ const ext = directChild$8(xfrm, "a:ext");
1456
1462
  if (off === void 0 || ext === void 0) return;
1457
1463
  const x = parseEmuAttr(off, "x");
1458
1464
  const y = parseEmuAttr(off, "y");
@@ -1468,7 +1474,7 @@ var PptxShape = class {
1468
1474
  }
1469
1475
  set frame(value) {
1470
1476
  const spPr = this.spPrElement(true);
1471
- let xfrm = directChild$7(spPr, "a:xfrm");
1477
+ let xfrm = directChild$8(spPr, "a:xfrm");
1472
1478
  if (xfrm === void 0) {
1473
1479
  xfrm = el("a:xfrm");
1474
1480
  spPr.children.unshift(xfrm);
@@ -1482,12 +1488,12 @@ var PptxShape = class {
1482
1488
  })];
1483
1489
  }
1484
1490
  get text() {
1485
- const txBody = directChild$7(this.live(), "p:txBody");
1491
+ const txBody = directChild$8(this.live(), "p:txBody");
1486
1492
  return txBody === void 0 ? "" : (0, ooxml_js.textContent)(txBody);
1487
1493
  }
1488
1494
  set text(value) {
1489
1495
  const node = this.live();
1490
- let txBody = directChild$7(node, "p:txBody");
1496
+ let txBody = directChild$8(node, "p:txBody");
1491
1497
  if (txBody === void 0) {
1492
1498
  txBody = el("p:txBody", {}, [el("a:bodyPr"), el("a:lstStyle")]);
1493
1499
  node.children.push(txBody);
@@ -1498,7 +1504,7 @@ var PptxShape = class {
1498
1504
  }
1499
1505
  setParagraphs(paragraphs) {
1500
1506
  const node = this.live();
1501
- let txBody = directChild$7(node, "p:txBody");
1507
+ let txBody = directChild$8(node, "p:txBody");
1502
1508
  if (txBody === void 0) {
1503
1509
  txBody = el("p:txBody", {}, [el("a:bodyPr"), el("a:lstStyle")]);
1504
1510
  node.children.push(txBody);
@@ -1609,12 +1615,12 @@ function insertPictureShapeMedia(context, slideRoot, frame, image) {
1609
1615
  }
1610
1616
  //#endregion
1611
1617
  //#region src/edit/pptx/slide.ts
1612
- function directChild$6(parent, tag) {
1618
+ function directChild$7(parent, tag) {
1613
1619
  for (const child of parent.children) if (child.type === "element" && child.tag === tag) return child;
1614
1620
  }
1615
1621
  function findSpTree(slideRoot) {
1616
- const cSld = directChild$6(slideRoot, "p:cSld");
1617
- const spTree = cSld === void 0 ? void 0 : directChild$6(cSld, "p:spTree");
1622
+ const cSld = directChild$7(slideRoot, "p:cSld");
1623
+ const spTree = cSld === void 0 ? void 0 : directChild$7(cSld, "p:spTree");
1618
1624
  if (spTree === void 0) throw new Error("slide has no p:cSld/p:spTree element");
1619
1625
  return spTree;
1620
1626
  }
@@ -1746,7 +1752,7 @@ const PRESENTATION_PART_PATH = "ppt/presentation.xml";
1746
1752
  const MEDIA_DIR = "ppt/media";
1747
1753
  const SLIDE_CONTENT_TYPE = "application/vnd.openxmlformats-officedocument.presentationml.slide+xml";
1748
1754
  const SLIDE_RELATIONSHIP_TYPE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/slide";
1749
- function directChild$5(parent, tag) {
1755
+ function directChild$6(parent, tag) {
1750
1756
  for (const child of parent.children) if (child.type === "element" && child.tag === tag) return child;
1751
1757
  }
1752
1758
  function attrValue(element, name) {
@@ -1758,12 +1764,12 @@ function findPresentationRoot(pkg) {
1758
1764
  return root;
1759
1765
  }
1760
1766
  function findSldIdLst(presentationRoot) {
1761
- const sldIdLst = directChild$5(presentationRoot, "p:sldIdLst");
1767
+ const sldIdLst = directChild$6(presentationRoot, "p:sldIdLst");
1762
1768
  if (sldIdLst === void 0) throw new Error(`${PRESENTATION_PART_PATH} has no p:sldIdLst element`);
1763
1769
  return sldIdLst;
1764
1770
  }
1765
1771
  function findSldSz(presentationRoot) {
1766
- const sldSz = directChild$5(presentationRoot, "p:sldSz");
1772
+ const sldSz = directChild$6(presentationRoot, "p:sldSz");
1767
1773
  if (sldSz === void 0) throw new Error(`${PRESENTATION_PART_PATH} has no p:sldSz element`);
1768
1774
  return sldSz;
1769
1775
  }
@@ -1924,12 +1930,12 @@ function buildPptxPackage(content) {
1924
1930
  if (firstSlide !== void 0) editor.slideSize = firstSlide.size;
1925
1931
  for (const slide of content.slides) {
1926
1932
  const pptxSlide = editor.addSlide();
1927
- for (const shape of slide.shapes) appendShape$1(pptxSlide, shape);
1933
+ for (const shape of slide.shapes) appendShape$2(pptxSlide, shape);
1928
1934
  if (slide.notes.length > 0) pptxSlide.notes = slide.notes;
1929
1935
  }
1930
1936
  return editor.toPackage();
1931
1937
  }
1932
- function appendShape$1(slide, shape) {
1938
+ function appendShape$2(slide, shape) {
1933
1939
  const [onlyBlock] = shape.blocks;
1934
1940
  if (shape.blocks.length === 1 && onlyBlock?.kind === "image") {
1935
1941
  slide.addImage({
@@ -1962,12 +1968,12 @@ function appendShape$1(slide, shape) {
1962
1968
  }
1963
1969
  //#endregion
1964
1970
  //#region src/edit/odt/automatic-styles.ts
1965
- const CONTENT_PART_PATH$3 = "content.xml";
1971
+ const CONTENT_PART_PATH$4 = "content.xml";
1966
1972
  function ensureAutomaticStyles(pkg) {
1967
- const part = pkg.parts[CONTENT_PART_PATH$3];
1968
- if (part?.kind !== "xml") throw new Error(`ensureAutomaticStyles: package has no ${CONTENT_PART_PATH$3} part`);
1973
+ const part = pkg.parts[CONTENT_PART_PATH$4];
1974
+ if (part?.kind !== "xml") throw new Error(`ensureAutomaticStyles: package has no ${CONTENT_PART_PATH$4} part`);
1969
1975
  const root = part.nodes.find((n) => n.type === "element");
1970
- if (root === void 0) throw new Error(`ensureAutomaticStyles: ${CONTENT_PART_PATH$3} has no root element`);
1976
+ if (root === void 0) throw new Error(`ensureAutomaticStyles: ${CONTENT_PART_PATH$4} has no root element`);
1971
1977
  for (const child of root.children) if (child.type === "element" && child.tag === "office:automatic-styles") return child;
1972
1978
  const created = el("office:automatic-styles");
1973
1979
  const insertBeforeTags = /* @__PURE__ */ new Set([
@@ -2061,7 +2067,7 @@ function applyStyleChange(pkg, element, family, change) {
2061
2067
  ...readCurrentStyleProperties(pkg, element, family),
2062
2068
  ...change
2063
2069
  };
2064
- const name = odf_js.StyleRegistry.forPart(pkg, CONTENT_PART_PATH$3).intern({
2070
+ const name = odf_js.StyleRegistry.forPart(pkg, CONTENT_PART_PATH$4).intern({
2065
2071
  family,
2066
2072
  properties: merged
2067
2073
  });
@@ -2292,7 +2298,7 @@ function buildList(pkg) {
2292
2298
  }
2293
2299
  //#endregion
2294
2300
  //#region src/edit/odt/scaffold.ts
2295
- const CONTENT_NS_PREFIXES$2 = [
2301
+ const CONTENT_NS_PREFIXES$3 = [
2296
2302
  "office",
2297
2303
  "style",
2298
2304
  "text",
@@ -2302,7 +2308,7 @@ const CONTENT_NS_PREFIXES$2 = [
2302
2308
  "svg",
2303
2309
  "xlink"
2304
2310
  ];
2305
- const STYLES_NS_PREFIXES$2 = [
2311
+ const STYLES_NS_PREFIXES$3 = [
2306
2312
  "office",
2307
2313
  "style",
2308
2314
  "text",
@@ -2312,16 +2318,16 @@ const STYLES_NS_PREFIXES$2 = [
2312
2318
  "svg",
2313
2319
  "xlink"
2314
2320
  ];
2315
- const META_NS_PREFIXES$2 = [
2321
+ const META_NS_PREFIXES$3 = [
2316
2322
  "office",
2317
2323
  "meta",
2318
2324
  "dc"
2319
2325
  ];
2320
- const ODF_VERSION$2 = "1.3";
2321
- const PAGE_LAYOUT_NAME$2 = "PM1";
2322
- const MASTER_PAGE_NAME$2 = "Standard";
2326
+ const ODF_VERSION$3 = "1.3";
2327
+ const PAGE_LAYOUT_NAME$3 = "PM1";
2328
+ const MASTER_PAGE_NAME$3 = "Standard";
2323
2329
  const DEFAULT_MARGIN_PT = 72;
2324
- function declaration$2() {
2330
+ function declaration$3() {
2325
2331
  return {
2326
2332
  type: "declaration",
2327
2333
  attributes: [
@@ -2340,8 +2346,8 @@ function declaration$2() {
2340
2346
  ]
2341
2347
  };
2342
2348
  }
2343
- function buildPageLayout$2() {
2344
- return el("style:page-layout", { "style:name": PAGE_LAYOUT_NAME$2 }, [el("style:page-layout-properties", {
2349
+ function buildPageLayout$3() {
2350
+ return el("style:page-layout", { "style:name": PAGE_LAYOUT_NAME$3 }, [el("style:page-layout-properties", {
2345
2351
  "fo:page-width": `${document_content_model.PAGE_SIZE_LETTER.widthPt}pt`,
2346
2352
  "fo:page-height": `${document_content_model.PAGE_SIZE_LETTER.heightPt}pt`,
2347
2353
  "fo:margin-top": `${DEFAULT_MARGIN_PT}pt`,
@@ -2350,44 +2356,44 @@ function buildPageLayout$2() {
2350
2356
  "fo:margin-left": `${DEFAULT_MARGIN_PT}pt`
2351
2357
  })]);
2352
2358
  }
2353
- function buildStylesXml$2() {
2359
+ function buildStylesXml$3() {
2354
2360
  return el("office:document-styles", {
2355
- ...(0, odf_js.xmlnsAttributes)([...STYLES_NS_PREFIXES$2]),
2356
- "office:version": ODF_VERSION$2
2361
+ ...(0, odf_js.xmlnsAttributes)([...STYLES_NS_PREFIXES$3]),
2362
+ "office:version": ODF_VERSION$3
2357
2363
  }, [
2358
2364
  el("office:styles"),
2359
- el("office:automatic-styles", {}, [buildPageLayout$2()]),
2365
+ el("office:automatic-styles", {}, [buildPageLayout$3()]),
2360
2366
  el("office:master-styles", {}, [el("style:master-page", {
2361
- "style:name": MASTER_PAGE_NAME$2,
2362
- "style:page-layout-name": PAGE_LAYOUT_NAME$2
2367
+ "style:name": MASTER_PAGE_NAME$3,
2368
+ "style:page-layout-name": PAGE_LAYOUT_NAME$3
2363
2369
  })])
2364
2370
  ]);
2365
2371
  }
2366
- function buildContentXml$2() {
2372
+ function buildContentXml$3() {
2367
2373
  return el("office:document-content", {
2368
- ...(0, odf_js.xmlnsAttributes)([...CONTENT_NS_PREFIXES$2]),
2369
- "office:version": ODF_VERSION$2
2374
+ ...(0, odf_js.xmlnsAttributes)([...CONTENT_NS_PREFIXES$3]),
2375
+ "office:version": ODF_VERSION$3
2370
2376
  }, [el("office:automatic-styles"), el("office:body", {}, [el("office:text")])]);
2371
2377
  }
2372
- function buildMetaXml$2() {
2378
+ function buildMetaXml$3() {
2373
2379
  return el("office:document-meta", {
2374
- ...(0, odf_js.xmlnsAttributes)([...META_NS_PREFIXES$2]),
2375
- "office:version": ODF_VERSION$2
2380
+ ...(0, odf_js.xmlnsAttributes)([...META_NS_PREFIXES$3]),
2381
+ "office:version": ODF_VERSION$3
2376
2382
  }, [el("office:meta")]);
2377
2383
  }
2378
2384
  function createEmptyOdtPackage() {
2379
2385
  const pkg = { parts: {
2380
2386
  "content.xml": {
2381
2387
  kind: "xml",
2382
- nodes: [declaration$2(), buildContentXml$2()]
2388
+ nodes: [declaration$3(), buildContentXml$3()]
2383
2389
  },
2384
2390
  "styles.xml": {
2385
2391
  kind: "xml",
2386
- nodes: [declaration$2(), buildStylesXml$2()]
2392
+ nodes: [declaration$3(), buildStylesXml$3()]
2387
2393
  },
2388
2394
  "meta.xml": {
2389
2395
  kind: "xml",
2390
- nodes: [declaration$2(), buildMetaXml$2()]
2396
+ nodes: [declaration$3(), buildMetaXml$3()]
2391
2397
  }
2392
2398
  } };
2393
2399
  (0, odf_js.setDocumentMediaType)(pkg, odf_js.ODF_MEDIA_TYPES.odt);
@@ -2508,20 +2514,20 @@ function buildTable(pkg, init) {
2508
2514
  }
2509
2515
  //#endregion
2510
2516
  //#region src/edit/odt/editor.ts
2511
- const CONTENT_PART_PATH$2 = "content.xml";
2517
+ const CONTENT_PART_PATH$3 = "content.xml";
2512
2518
  function findContentRoot(pkg) {
2513
- const part = pkg.parts[CONTENT_PART_PATH$2];
2519
+ const part = pkg.parts[CONTENT_PART_PATH$3];
2514
2520
  const root = part?.kind === "xml" ? part.nodes.find((n) => n.type === "element") : void 0;
2515
- if (root === void 0) throw new Error(`package has no root element at ${CONTENT_PART_PATH$2}`);
2521
+ if (root === void 0) throw new Error(`package has no root element at ${CONTENT_PART_PATH$3}`);
2516
2522
  return root;
2517
2523
  }
2518
- function directChild$4(parent, tag) {
2524
+ function directChild$5(parent, tag) {
2519
2525
  for (const child of parent.children) if (child.type === "element" && child.tag === tag) return child;
2520
2526
  }
2521
2527
  function findOfficeText(contentRoot) {
2522
- const body = directChild$4(contentRoot, "office:body");
2523
- const text = body === void 0 ? void 0 : directChild$4(body, "office:text");
2524
- if (text === void 0) throw new Error(`${CONTENT_PART_PATH$2} has no office:body/office:text element`);
2528
+ const body = directChild$5(contentRoot, "office:body");
2529
+ const text = body === void 0 ? void 0 : directChild$5(body, "office:text");
2530
+ if (text === void 0) throw new Error(`${CONTENT_PART_PATH$3} has no office:body/office:text element`);
2525
2531
  return text;
2526
2532
  }
2527
2533
  var OdtBodyImpl = class {
@@ -2653,7 +2659,7 @@ function appendBlock(body, block) {
2653
2659
  }
2654
2660
  //#endregion
2655
2661
  //#region src/edit/odp/scaffold.ts
2656
- const CONTENT_NS_PREFIXES$1 = [
2662
+ const CONTENT_NS_PREFIXES$2 = [
2657
2663
  "office",
2658
2664
  "style",
2659
2665
  "text",
@@ -2664,7 +2670,7 @@ const CONTENT_NS_PREFIXES$1 = [
2664
2670
  "svg",
2665
2671
  "xlink"
2666
2672
  ];
2667
- const STYLES_NS_PREFIXES$1 = [
2673
+ const STYLES_NS_PREFIXES$2 = [
2668
2674
  "office",
2669
2675
  "style",
2670
2676
  "text",
@@ -2675,14 +2681,14 @@ const STYLES_NS_PREFIXES$1 = [
2675
2681
  "svg",
2676
2682
  "xlink"
2677
2683
  ];
2678
- const META_NS_PREFIXES$1 = [
2684
+ const META_NS_PREFIXES$2 = [
2679
2685
  "office",
2680
2686
  "meta",
2681
2687
  "dc"
2682
2688
  ];
2683
- const ODF_VERSION$1 = "1.3";
2684
- const MASTER_PAGE_NAME$1 = "Standard";
2685
- function declaration$1() {
2689
+ const ODF_VERSION$2 = "1.3";
2690
+ const MASTER_PAGE_NAME$2 = "Standard";
2691
+ function declaration$2() {
2686
2692
  return {
2687
2693
  type: "declaration",
2688
2694
  attributes: [
@@ -2701,50 +2707,50 @@ function declaration$1() {
2701
2707
  ]
2702
2708
  };
2703
2709
  }
2704
- function buildPageLayout$1() {
2710
+ function buildPageLayout$2() {
2705
2711
  return el("style:page-layout", { "style:name": "PM1" }, [el("style:page-layout-properties", {
2706
2712
  "fo:page-width": `${document_content_model.SLIDE_SIZE_WIDESCREEN.widthPt}pt`,
2707
2713
  "fo:page-height": `${document_content_model.SLIDE_SIZE_WIDESCREEN.heightPt}pt`
2708
2714
  })]);
2709
2715
  }
2710
- function buildStylesXml$1() {
2716
+ function buildStylesXml$2() {
2711
2717
  return el("office:document-styles", {
2712
- ...(0, odf_js.xmlnsAttributes)([...STYLES_NS_PREFIXES$1]),
2713
- "office:version": ODF_VERSION$1
2718
+ ...(0, odf_js.xmlnsAttributes)([...STYLES_NS_PREFIXES$2]),
2719
+ "office:version": ODF_VERSION$2
2714
2720
  }, [
2715
2721
  el("office:styles"),
2716
- el("office:automatic-styles", {}, [buildPageLayout$1()]),
2722
+ el("office:automatic-styles", {}, [buildPageLayout$2()]),
2717
2723
  el("office:master-styles", {}, [el("style:master-page", {
2718
- "style:name": MASTER_PAGE_NAME$1,
2724
+ "style:name": MASTER_PAGE_NAME$2,
2719
2725
  "style:page-layout-name": "PM1"
2720
2726
  })])
2721
2727
  ]);
2722
2728
  }
2723
- function buildContentXml$1() {
2729
+ function buildContentXml$2() {
2724
2730
  return el("office:document-content", {
2725
- ...(0, odf_js.xmlnsAttributes)([...CONTENT_NS_PREFIXES$1]),
2726
- "office:version": ODF_VERSION$1
2731
+ ...(0, odf_js.xmlnsAttributes)([...CONTENT_NS_PREFIXES$2]),
2732
+ "office:version": ODF_VERSION$2
2727
2733
  }, [el("office:automatic-styles"), el("office:body", {}, [el("office:presentation")])]);
2728
2734
  }
2729
- function buildMetaXml$1() {
2735
+ function buildMetaXml$2() {
2730
2736
  return el("office:document-meta", {
2731
- ...(0, odf_js.xmlnsAttributes)([...META_NS_PREFIXES$1]),
2732
- "office:version": ODF_VERSION$1
2737
+ ...(0, odf_js.xmlnsAttributes)([...META_NS_PREFIXES$2]),
2738
+ "office:version": ODF_VERSION$2
2733
2739
  }, [el("office:meta")]);
2734
2740
  }
2735
2741
  function createEmptyOdpPackage() {
2736
2742
  const pkg = { parts: {
2737
2743
  "content.xml": {
2738
2744
  kind: "xml",
2739
- nodes: [declaration$1(), buildContentXml$1()]
2745
+ nodes: [declaration$2(), buildContentXml$2()]
2740
2746
  },
2741
2747
  "styles.xml": {
2742
2748
  kind: "xml",
2743
- nodes: [declaration$1(), buildStylesXml$1()]
2749
+ nodes: [declaration$2(), buildStylesXml$2()]
2744
2750
  },
2745
2751
  "meta.xml": {
2746
2752
  kind: "xml",
2747
- nodes: [declaration$1(), buildMetaXml$1()]
2753
+ nodes: [declaration$2(), buildMetaXml$2()]
2748
2754
  }
2749
2755
  } };
2750
2756
  (0, odf_js.setDocumentMediaType)(pkg, odf_js.ODF_MEDIA_TYPES.odp);
@@ -2784,7 +2790,7 @@ function addImageMedia(pkg, imageBytes, format) {
2784
2790
  }
2785
2791
  //#endregion
2786
2792
  //#region src/edit/odp/shape.ts
2787
- function directChild$3(parent, tag) {
2793
+ function directChild$4(parent, tag) {
2788
2794
  for (const child of parent.children) if (child.type === "element" && child.tag === tag) return child;
2789
2795
  }
2790
2796
  function buildTransformAttr(frame, rotationDeg) {
@@ -2852,7 +2858,7 @@ var OdpShape = class {
2852
2858
  }
2853
2859
  textBox(create) {
2854
2860
  const node = this.live();
2855
- const existing = directChild$3(node, "draw:text-box");
2861
+ const existing = directChild$4(node, "draw:text-box");
2856
2862
  if (existing !== void 0 || !create) return existing;
2857
2863
  const created = el("draw:text-box");
2858
2864
  node.children.push(created);
@@ -2913,7 +2919,7 @@ function insertImageFrameMedia(context, frame, image) {
2913
2919
  }
2914
2920
  //#endregion
2915
2921
  //#region src/edit/odp/slide.ts
2916
- function directChild$2(parent, tag) {
2922
+ function directChild$3(parent, tag) {
2917
2923
  for (const child of parent.children) if (child.type === "element" && child.tag === tag) return child;
2918
2924
  }
2919
2925
  const NOTES_FRAME_X_PT = 20;
@@ -2962,13 +2968,13 @@ var OdpSlide = class {
2962
2968
  return new OdpShape(node.children, frameElement, this.context.pkg);
2963
2969
  }
2964
2970
  get notes() {
2965
- const notesElement = directChild$2(this.live(), "presentation:notes");
2971
+ const notesElement = directChild$3(this.live(), "presentation:notes");
2966
2972
  if (notesElement === void 0) return "";
2967
2973
  return (0, ooxml_js.elementsWithTag)(notesElement.children, "text:p").map((p) => decodeOdfText(p.children)).join("\n");
2968
2974
  }
2969
2975
  set notes(value) {
2970
2976
  const node = this.live();
2971
- const existing = directChild$2(node, "presentation:notes");
2977
+ const existing = directChild$3(node, "presentation:notes");
2972
2978
  const notesElement = buildNotesElement(this.context.pkg, value);
2973
2979
  if (existing === void 0) node.children.push(notesElement);
2974
2980
  else existing.children = notesElement.children;
@@ -2980,27 +2986,27 @@ var OdpSlide = class {
2980
2986
  };
2981
2987
  //#endregion
2982
2988
  //#region src/edit/odp/editor.ts
2983
- const CONTENT_PART_PATH$1 = "content.xml";
2984
- const STYLES_PART_PATH = "styles.xml";
2985
- function directChild$1(parent, tag) {
2989
+ const CONTENT_PART_PATH$2 = "content.xml";
2990
+ const STYLES_PART_PATH$1 = "styles.xml";
2991
+ function directChild$2(parent, tag) {
2986
2992
  for (const child of parent.children) if (child.type === "element" && child.tag === tag) return child;
2987
2993
  }
2988
- function findRoot$1(pkg, partPath) {
2994
+ function findRoot$2(pkg, partPath) {
2989
2995
  const part = pkg.parts[partPath];
2990
2996
  const root = part?.kind === "xml" ? part.nodes.find((n) => n.type === "element") : void 0;
2991
2997
  if (root === void 0) throw new Error(`package has no root element at ${partPath}`);
2992
2998
  return root;
2993
2999
  }
2994
3000
  function findOfficePresentation(pkg) {
2995
- const body = directChild$1(findRoot$1(pkg, CONTENT_PART_PATH$1), "office:body");
2996
- const presentation = body === void 0 ? void 0 : directChild$1(body, "office:presentation");
2997
- if (presentation === void 0) throw new Error(`${CONTENT_PART_PATH$1} has no office:body/office:presentation element`);
3001
+ const body = directChild$2(findRoot$2(pkg, CONTENT_PART_PATH$2), "office:body");
3002
+ const presentation = body === void 0 ? void 0 : directChild$2(body, "office:presentation");
3003
+ if (presentation === void 0) throw new Error(`${CONTENT_PART_PATH$2} has no office:body/office:presentation element`);
2998
3004
  return presentation;
2999
3005
  }
3000
- function findPageLayoutProperties(pkg) {
3001
- const pageLayout = directChild$1(findRoot$1(pkg, STYLES_PART_PATH), "office:automatic-styles")?.children.find((c) => c.type === "element" && c.tag === "style:page-layout" && (0, ooxml_js.attr)(c, "style:name") === "PM1");
3002
- const properties = pageLayout === void 0 ? void 0 : directChild$1(pageLayout, "style:page-layout-properties");
3003
- if (properties === void 0) throw new Error(`${STYLES_PART_PATH} has no style:page-layout[style:name="PM1"]/style:page-layout-properties element`);
3006
+ function findPageLayoutProperties$1(pkg) {
3007
+ 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" && (0, ooxml_js.attr)(c, "style:name") === "PM1");
3008
+ const properties = pageLayout === void 0 ? void 0 : directChild$2(pageLayout, "style:page-layout-properties");
3009
+ if (properties === void 0) throw new Error(`${STYLES_PART_PATH$1} has no style:page-layout[style:name="PM1"]/style:page-layout-properties element`);
3004
3010
  return properties;
3005
3011
  }
3006
3012
  var OdpEditor = class {
@@ -3019,7 +3025,7 @@ var OdpEditor = class {
3019
3025
  }
3020
3026
  addSlide() {
3021
3027
  const presentation = findOfficePresentation(this.pkg);
3022
- const pageElement = el("draw:page", { "draw:master-page-name": MASTER_PAGE_NAME$1 });
3028
+ const pageElement = el("draw:page", { "draw:master-page-name": MASTER_PAGE_NAME$2 });
3023
3029
  presentation.children.push(pageElement);
3024
3030
  const context = { pkg: this.pkg };
3025
3031
  return new OdpSlide(presentation.children, pageElement, context);
@@ -3049,7 +3055,7 @@ var OdpEditor = class {
3049
3055
  presentation.children.splice(insertAt, 0, moved);
3050
3056
  }
3051
3057
  get slideSize() {
3052
- const properties = findPageLayoutProperties(this.pkg);
3058
+ const properties = findPageLayoutProperties$1(this.pkg);
3053
3059
  const widthValue = (0, ooxml_js.attr)(properties, "fo:page-width");
3054
3060
  const heightValue = (0, ooxml_js.attr)(properties, "fo:page-height");
3055
3061
  const widthPt = widthValue === void 0 ? void 0 : (0, odf_js.parseOdfLength)(widthValue);
@@ -3060,7 +3066,7 @@ var OdpEditor = class {
3060
3066
  };
3061
3067
  }
3062
3068
  set slideSize(size) {
3063
- const properties = findPageLayoutProperties(this.pkg);
3069
+ const properties = findPageLayoutProperties$1(this.pkg);
3064
3070
  properties.attributes = [{
3065
3071
  name: "fo:page-width",
3066
3072
  value: (0, odf_js.formatOdfLength)(size.widthPt)
@@ -3091,12 +3097,12 @@ function buildOdpPackage(content) {
3091
3097
  if (firstSlide !== void 0) editor.slideSize = firstSlide.size;
3092
3098
  for (const slide of content.slides) {
3093
3099
  const odpSlide = editor.addSlide();
3094
- for (const shape of slide.shapes) appendShape(odpSlide, shape);
3100
+ for (const shape of slide.shapes) appendShape$1(odpSlide, shape);
3095
3101
  if (slide.notes.length > 0) odpSlide.notes = slide.notes;
3096
3102
  }
3097
3103
  return editor.toPackage();
3098
3104
  }
3099
- function appendShape(slide, shape) {
3105
+ function appendShape$1(slide, shape) {
3100
3106
  const [onlyBlock] = shape.blocks;
3101
3107
  if (shape.blocks.length === 1 && onlyBlock?.kind === "image") {
3102
3108
  const imageShape = slide.addImage({
@@ -3121,31 +3127,31 @@ function appendShape(slide, shape) {
3121
3127
  }
3122
3128
  //#endregion
3123
3129
  //#region src/edit/ods/scaffold.ts
3124
- const CONTENT_NS_PREFIXES = [
3130
+ const CONTENT_NS_PREFIXES$1 = [
3125
3131
  "office",
3126
3132
  "style",
3127
3133
  "text",
3128
3134
  "table",
3129
3135
  "fo"
3130
3136
  ];
3131
- const STYLES_NS_PREFIXES = [
3137
+ const STYLES_NS_PREFIXES$1 = [
3132
3138
  "office",
3133
3139
  "style",
3134
3140
  "table",
3135
3141
  "fo"
3136
3142
  ];
3137
- const META_NS_PREFIXES = [
3143
+ const META_NS_PREFIXES$1 = [
3138
3144
  "office",
3139
3145
  "meta",
3140
3146
  "dc"
3141
3147
  ];
3142
3148
  const OF_NAMESPACE_ATTR = { "xmlns:of": "urn:oasis:names:tc:opendocument:xmlns:of:1.2" };
3143
- const ODF_VERSION = "1.3";
3144
- const MASTER_PAGE_NAME = "Standard";
3149
+ const ODF_VERSION$1 = "1.3";
3150
+ const MASTER_PAGE_NAME$1 = "Standard";
3145
3151
  const SHEET_TABLE_STYLE_NAME = "OdsTable";
3146
3152
  const DEFAULT_SHEET_NAME = "Sheet1";
3147
3153
  const DEFAULT_MARGIN = "2cm";
3148
- function declaration() {
3154
+ function declaration$1() {
3149
3155
  return {
3150
3156
  type: "declaration",
3151
3157
  attributes: [
@@ -3164,7 +3170,7 @@ function declaration() {
3164
3170
  ]
3165
3171
  };
3166
3172
  }
3167
- function buildPageLayout() {
3173
+ function buildPageLayout$1() {
3168
3174
  return el("style:page-layout", { "style:name": "PM1" }, [el("style:page-layout-properties", {
3169
3175
  "fo:page-width": `${document_content_model.PAGE_SIZE_A4.widthPt}pt`,
3170
3176
  "fo:page-height": `${document_content_model.PAGE_SIZE_A4.heightPt}pt`,
@@ -3174,15 +3180,15 @@ function buildPageLayout() {
3174
3180
  "fo:margin-left": DEFAULT_MARGIN
3175
3181
  })]);
3176
3182
  }
3177
- function buildStylesXml() {
3183
+ function buildStylesXml$1() {
3178
3184
  return el("office:document-styles", {
3179
- ...(0, odf_js.xmlnsAttributes)([...STYLES_NS_PREFIXES]),
3180
- "office:version": ODF_VERSION
3185
+ ...(0, odf_js.xmlnsAttributes)([...STYLES_NS_PREFIXES$1]),
3186
+ "office:version": ODF_VERSION$1
3181
3187
  }, [
3182
3188
  el("office:styles"),
3183
- el("office:automatic-styles", {}, [buildPageLayout()]),
3189
+ el("office:automatic-styles", {}, [buildPageLayout$1()]),
3184
3190
  el("office:master-styles", {}, [el("style:master-page", {
3185
- "style:name": MASTER_PAGE_NAME,
3191
+ "style:name": MASTER_PAGE_NAME$1,
3186
3192
  "style:page-layout-name": "PM1"
3187
3193
  })])
3188
3194
  ]);
@@ -3191,7 +3197,7 @@ function buildSheetTableStyle() {
3191
3197
  return el("style:style", {
3192
3198
  "style:name": SHEET_TABLE_STYLE_NAME,
3193
3199
  "style:family": "table",
3194
- "style:master-page-name": MASTER_PAGE_NAME
3200
+ "style:master-page-name": MASTER_PAGE_NAME$1
3195
3201
  });
3196
3202
  }
3197
3203
  function buildCalculationSettings() {
@@ -3202,36 +3208,36 @@ function buildCalculationSettings() {
3202
3208
  "table:null-year": "1950"
3203
3209
  });
3204
3210
  }
3205
- function buildContentXml() {
3211
+ function buildContentXml$1() {
3206
3212
  const table = el("table:table", {
3207
3213
  "table:name": DEFAULT_SHEET_NAME,
3208
3214
  "table:style-name": SHEET_TABLE_STYLE_NAME
3209
3215
  });
3210
3216
  return el("office:document-content", {
3211
- ...(0, odf_js.xmlnsAttributes)([...CONTENT_NS_PREFIXES]),
3217
+ ...(0, odf_js.xmlnsAttributes)([...CONTENT_NS_PREFIXES$1]),
3212
3218
  ...OF_NAMESPACE_ATTR,
3213
- "office:version": ODF_VERSION
3219
+ "office:version": ODF_VERSION$1
3214
3220
  }, [el("office:automatic-styles", {}, [buildSheetTableStyle()]), el("office:body", {}, [el("office:spreadsheet", {}, [buildCalculationSettings(), table])])]);
3215
3221
  }
3216
- function buildMetaXml() {
3222
+ function buildMetaXml$1() {
3217
3223
  return el("office:document-meta", {
3218
- ...(0, odf_js.xmlnsAttributes)([...META_NS_PREFIXES]),
3219
- "office:version": ODF_VERSION
3224
+ ...(0, odf_js.xmlnsAttributes)([...META_NS_PREFIXES$1]),
3225
+ "office:version": ODF_VERSION$1
3220
3226
  }, [el("office:meta")]);
3221
3227
  }
3222
3228
  function createEmptyOdsPackage() {
3223
3229
  const pkg = { parts: {
3224
3230
  "content.xml": {
3225
3231
  kind: "xml",
3226
- nodes: [declaration(), buildContentXml()]
3232
+ nodes: [declaration$1(), buildContentXml$1()]
3227
3233
  },
3228
3234
  "styles.xml": {
3229
3235
  kind: "xml",
3230
- nodes: [declaration(), buildStylesXml()]
3236
+ nodes: [declaration$1(), buildStylesXml$1()]
3231
3237
  },
3232
3238
  "meta.xml": {
3233
3239
  kind: "xml",
3234
- nodes: [declaration(), buildMetaXml()]
3240
+ nodes: [declaration$1(), buildMetaXml$1()]
3235
3241
  }
3236
3242
  } };
3237
3243
  (0, odf_js.setDocumentMediaType)(pkg, odf_js.ODF_MEDIA_TYPES.ods);
@@ -3502,55 +3508,595 @@ var OdsCell = class {
3502
3508
  }
3503
3509
  };
3504
3510
  //#endregion
3505
- //#region src/edit/ods/sheet.ts
3506
- const NAME_ATTR = "table:name";
3507
- var OdsSheet = class {
3511
+ //#region src/edit/ods/sheet.ts
3512
+ const NAME_ATTR = "table:name";
3513
+ var OdsSheet = class {
3514
+ container;
3515
+ node;
3516
+ pkg;
3517
+ removed = false;
3518
+ constructor(container, node, pkg) {
3519
+ this.container = container;
3520
+ this.node = node;
3521
+ this.pkg = pkg;
3522
+ }
3523
+ live() {
3524
+ if (this.removed) throw new Error("this OdsSheet has been removed from the spreadsheet and can no longer be used");
3525
+ return this.node;
3526
+ }
3527
+ get name() {
3528
+ const value = (0, ooxml_js.attr)(this.live(), NAME_ATTR);
3529
+ if (value === void 0) throw new Error("this table:table element has no table:name attribute");
3530
+ return value;
3531
+ }
3532
+ set name(value) {
3533
+ setAttr(this.live(), NAME_ATTR, value);
3534
+ }
3535
+ cell(row, column) {
3536
+ const node = resolveCellNode(this.live(), row, column);
3537
+ 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`);
3538
+ return new OdsCell(node, this.pkg);
3539
+ }
3540
+ cellAt(reference) {
3541
+ const parsed = (0, odf_js.parseCellReference)(reference);
3542
+ if (parsed === void 0) throw new Error(`cellAt: "${reference}" is not a valid A1-style cell reference`);
3543
+ return this.cell(parsed.row, parsed.column);
3544
+ }
3545
+ mergeCells(startRow, startColumn, rowSpan, colSpan) {
3546
+ 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}`);
3547
+ const tableElement = this.live();
3548
+ const anchorNode = resolveCellNode(tableElement, startRow, startColumn);
3549
+ if (anchorNode.tag === "table:covered-table-cell") throw new Error(`mergeCells: (${startRow}, ${startColumn}) is already covered by another merged range`);
3550
+ if (rowSpan > 1) setAttr(anchorNode, "table:number-rows-spanned", String(rowSpan));
3551
+ if (colSpan > 1) setAttr(anchorNode, "table:number-columns-spanned", String(colSpan));
3552
+ for (let rowOffset = 0; rowOffset < rowSpan; rowOffset++) for (let columnOffset = 0; columnOffset < colSpan; columnOffset++) {
3553
+ if (rowOffset === 0 && columnOffset === 0) continue;
3554
+ const coveredNode = resolveCellNode(tableElement, startRow + rowOffset, startColumn + columnOffset);
3555
+ coveredNode.tag = COVERED_CELL_TAG;
3556
+ coveredNode.attributes = [];
3557
+ coveredNode.children = [];
3558
+ }
3559
+ return new OdsCell(anchorNode, this.pkg);
3560
+ }
3561
+ remove() {
3562
+ removeChild(this.container, this.live());
3563
+ this.removed = true;
3564
+ }
3565
+ };
3566
+ //#endregion
3567
+ //#region src/edit/ods/editor.ts
3568
+ const CONTENT_PART_PATH$1 = "content.xml";
3569
+ function directChild$1(parent, tag) {
3570
+ for (const child of parent.children) if (child.type === "element" && child.tag === tag) return child;
3571
+ }
3572
+ function findRoot$1(pkg) {
3573
+ const part = pkg.parts[CONTENT_PART_PATH$1];
3574
+ const root = part?.kind === "xml" ? part.nodes.find((n) => n.type === "element") : void 0;
3575
+ if (root === void 0) throw new Error(`package has no root element at ${CONTENT_PART_PATH$1}`);
3576
+ return root;
3577
+ }
3578
+ function findOfficeSpreadsheet(pkg) {
3579
+ const body = directChild$1(findRoot$1(pkg), "office:body");
3580
+ const spreadsheet = body === void 0 ? void 0 : directChild$1(body, "office:spreadsheet");
3581
+ if (spreadsheet === void 0) throw new Error(`${CONTENT_PART_PATH$1} has no office:body/office:spreadsheet element`);
3582
+ return spreadsheet;
3583
+ }
3584
+ function ensureSheetTableStyleName(pkg) {
3585
+ const automaticStyles = ensureAutomaticStyles(pkg);
3586
+ if (automaticStyles.children.find((child) => child.type === "element" && child.tag === "style:style" && (0, ooxml_js.attr)(child, "style:name") === "OdsTable") !== void 0) return SHEET_TABLE_STYLE_NAME;
3587
+ automaticStyles.children.push(el("style:style", {
3588
+ "style:name": SHEET_TABLE_STYLE_NAME,
3589
+ "style:family": "table",
3590
+ "style:master-page-name": MASTER_PAGE_NAME$1
3591
+ }));
3592
+ return SHEET_TABLE_STYLE_NAME;
3593
+ }
3594
+ var OdsEditor = class {
3595
+ pkg;
3596
+ constructor(pkg) {
3597
+ this.pkg = pkg;
3598
+ }
3599
+ sheets() {
3600
+ const spreadsheet = findOfficeSpreadsheet(this.pkg);
3601
+ const out = [];
3602
+ for (const child of spreadsheet.children) if (child.type === "element" && child.tag === "table:table") out.push(new OdsSheet(spreadsheet.children, child, this.pkg));
3603
+ return out;
3604
+ }
3605
+ sheet(name) {
3606
+ const found = this.sheets().find((candidate) => candidate.name === name);
3607
+ if (found === void 0) throw new Error(`no sheet named "${name}" exists in this spreadsheet`);
3608
+ return found;
3609
+ }
3610
+ addSheet(name) {
3611
+ const spreadsheet = findOfficeSpreadsheet(this.pkg);
3612
+ const tableElement = el("table:table", {
3613
+ "table:name": name,
3614
+ "table:style-name": ensureSheetTableStyleName(this.pkg)
3615
+ });
3616
+ spreadsheet.children.push(tableElement);
3617
+ return new OdsSheet(spreadsheet.children, tableElement, this.pkg);
3618
+ }
3619
+ removeSheetAt(index) {
3620
+ const spreadsheet = findOfficeSpreadsheet(this.pkg);
3621
+ const target = spreadsheet.children.filter((child) => child.type === "element" && child.tag === "table:table")[index];
3622
+ if (target === void 0) throw new Error(`sheet index ${index} does not exist`);
3623
+ const listIndex = spreadsheet.children.indexOf(target);
3624
+ spreadsheet.children.splice(listIndex, 1);
3625
+ }
3626
+ toPackage() {
3627
+ return this.pkg;
3628
+ }
3629
+ toBytes() {
3630
+ return (0, odf_js.encodePackage)(this.pkg);
3631
+ }
3632
+ };
3633
+ function openOds(bytes) {
3634
+ return new OdsEditor((0, odf_js.decodePackage)(bytes));
3635
+ }
3636
+ function createOds() {
3637
+ return new OdsEditor(createEmptyOdsPackage());
3638
+ }
3639
+ //#endregion
3640
+ //#region src/edit/ods/content.ts
3641
+ function buildOdsPackage(content) {
3642
+ if (content.kind !== "spreadsheet") throw new Error("buildOdsPackage requires a spreadsheet ContentDocument");
3643
+ const editor = createOds();
3644
+ if (content.sheets.length > 0) editor.removeSheetAt(0);
3645
+ for (const sheet of content.sheets) {
3646
+ const odsSheet = editor.addSheet(sheet.name);
3647
+ for (const cell of sheet.cells) appendCell(odsSheet, cell);
3648
+ }
3649
+ return editor.toPackage();
3650
+ }
3651
+ function appendCell(odsSheet, cell) {
3652
+ const odsCell = odsSheet.cell(cell.row, cell.column);
3653
+ odsCell.value = cell.value;
3654
+ if (cell.formula !== void 0) odsCell.formula = cell.formula;
3655
+ if (cell.runs !== void 0 && cell.runs.length > 0) odsCell.setStyledRuns(cell.runs);
3656
+ else odsCell.displayText = cell.displayText;
3657
+ const rowSpan = cell.rowSpan ?? 1;
3658
+ const colSpan = cell.colSpan ?? 1;
3659
+ if (rowSpan > 1 || colSpan > 1) odsSheet.mergeCells(cell.row, cell.column, rowSpan, colSpan);
3660
+ }
3661
+ //#endregion
3662
+ //#region src/edit/odg/scaffold.ts
3663
+ const CONTENT_NS_PREFIXES = [
3664
+ "office",
3665
+ "style",
3666
+ "text",
3667
+ "table",
3668
+ "draw",
3669
+ "fo",
3670
+ "svg",
3671
+ "xlink"
3672
+ ];
3673
+ const STYLES_NS_PREFIXES = [
3674
+ "office",
3675
+ "style",
3676
+ "text",
3677
+ "table",
3678
+ "draw",
3679
+ "fo",
3680
+ "svg",
3681
+ "xlink"
3682
+ ];
3683
+ const META_NS_PREFIXES = [
3684
+ "office",
3685
+ "meta",
3686
+ "dc"
3687
+ ];
3688
+ const ODF_VERSION = "1.3";
3689
+ const MASTER_PAGE_NAME = "Standard";
3690
+ function declaration() {
3691
+ return {
3692
+ type: "declaration",
3693
+ attributes: [
3694
+ {
3695
+ name: "version",
3696
+ value: "1.0"
3697
+ },
3698
+ {
3699
+ name: "encoding",
3700
+ value: "UTF-8"
3701
+ },
3702
+ {
3703
+ name: "standalone",
3704
+ value: "yes"
3705
+ }
3706
+ ]
3707
+ };
3708
+ }
3709
+ function buildPageLayout() {
3710
+ return el("style:page-layout", { "style:name": "PM1" }, [el("style:page-layout-properties", {
3711
+ "fo:page-width": `${document_content_model.PAGE_SIZE_A4.widthPt}pt`,
3712
+ "fo:page-height": `${document_content_model.PAGE_SIZE_A4.heightPt}pt`
3713
+ })]);
3714
+ }
3715
+ function buildStylesXml() {
3716
+ return el("office:document-styles", {
3717
+ ...(0, odf_js.xmlnsAttributes)([...STYLES_NS_PREFIXES]),
3718
+ "office:version": ODF_VERSION
3719
+ }, [
3720
+ el("office:styles"),
3721
+ el("office:automatic-styles", {}, [buildPageLayout()]),
3722
+ el("office:master-styles", {}, [el("style:master-page", {
3723
+ "style:name": MASTER_PAGE_NAME,
3724
+ "style:page-layout-name": "PM1"
3725
+ })])
3726
+ ]);
3727
+ }
3728
+ function buildContentXml() {
3729
+ return el("office:document-content", {
3730
+ ...(0, odf_js.xmlnsAttributes)([...CONTENT_NS_PREFIXES]),
3731
+ "office:version": ODF_VERSION
3732
+ }, [el("office:automatic-styles"), el("office:body", {}, [el("office:drawing")])]);
3733
+ }
3734
+ function buildMetaXml() {
3735
+ return el("office:document-meta", {
3736
+ ...(0, odf_js.xmlnsAttributes)([...META_NS_PREFIXES]),
3737
+ "office:version": ODF_VERSION
3738
+ }, [el("office:meta")]);
3739
+ }
3740
+ function createEmptyOdgPackage() {
3741
+ const pkg = { parts: {
3742
+ "content.xml": {
3743
+ kind: "xml",
3744
+ nodes: [declaration(), buildContentXml()]
3745
+ },
3746
+ "styles.xml": {
3747
+ kind: "xml",
3748
+ nodes: [declaration(), buildStylesXml()]
3749
+ },
3750
+ "meta.xml": {
3751
+ kind: "xml",
3752
+ nodes: [declaration(), buildMetaXml()]
3753
+ }
3754
+ } };
3755
+ (0, odf_js.setDocumentMediaType)(pkg, odf_js.ODF_MEDIA_TYPES.odg);
3756
+ (0, odf_js.syncManifest)(pkg);
3757
+ return pkg;
3758
+ }
3759
+ //#endregion
3760
+ //#region src/edit/odg/style.ts
3761
+ const GRAPHIC_STYLE_PREFIX = "gr";
3762
+ function graphicPropertyAttrs(init) {
3763
+ const attrs = {};
3764
+ if (init.fill === void 0) attrs["draw:fill"] = "none";
3765
+ else attrs["draw:fill-color"] = (0, odf_js.formatOdfColor)(init.fill);
3766
+ if (init.stroke === void 0) attrs["draw:stroke"] = "none";
3767
+ else {
3768
+ attrs["svg:stroke-color"] = (0, odf_js.formatOdfColor)(init.stroke.color);
3769
+ attrs["svg:stroke-width"] = (0, odf_js.formatOdfLength)(init.stroke.widthPt);
3770
+ }
3771
+ return attrs;
3772
+ }
3773
+ function buildGraphicStyle(pkg, init) {
3774
+ const automaticStyles = ensureAutomaticStyles(pkg);
3775
+ const name = nextStyleName(automaticStyles, "style:style", GRAPHIC_STYLE_PREFIX);
3776
+ automaticStyles.children.push(el("style:style", {
3777
+ "style:name": name,
3778
+ "style:family": "graphic"
3779
+ }, [el("style:graphic-properties", graphicPropertyAttrs(init))]));
3780
+ return name;
3781
+ }
3782
+ function findAutomaticStylesReadOnly(pkg) {
3783
+ const part = pkg.parts["content.xml"];
3784
+ const root = part?.kind === "xml" ? part.nodes.find((n) => n.type === "element") : void 0;
3785
+ if (root === void 0) return;
3786
+ for (const child of root.children) if (child.type === "element" && child.tag === "office:automatic-styles") return child;
3787
+ }
3788
+ function findGraphicStyle(pkg, element) {
3789
+ const styleName = (0, ooxml_js.attr)(element, "draw:style-name");
3790
+ if (styleName === void 0) return;
3791
+ return findAutomaticStylesReadOnly(pkg)?.children.find((c) => c.type === "element" && c.tag === "style:style" && (0, ooxml_js.attr)(c, "style:name") === styleName);
3792
+ }
3793
+ function graphicProperties(pkg, element) {
3794
+ return findGraphicStyle(pkg, element)?.children.find((c) => c.type === "element" && c.tag === "style:graphic-properties");
3795
+ }
3796
+ function readGraphicFill(pkg, element) {
3797
+ const props = graphicProperties(pkg, element);
3798
+ if (props === void 0 || (0, ooxml_js.attr)(props, "draw:fill") === "none") return;
3799
+ const value = (0, ooxml_js.attr)(props, "draw:fill-color");
3800
+ return value === void 0 ? void 0 : (0, odf_js.parseOdfColor)(value);
3801
+ }
3802
+ function readGraphicStroke(pkg, element) {
3803
+ const props = graphicProperties(pkg, element);
3804
+ if (props === void 0 || (0, ooxml_js.attr)(props, "draw:stroke") === "none") return;
3805
+ const colorValue = (0, ooxml_js.attr)(props, "svg:stroke-color");
3806
+ const widthValue = (0, ooxml_js.attr)(props, "svg:stroke-width");
3807
+ const color = colorValue === void 0 ? void 0 : (0, odf_js.parseOdfColor)(colorValue);
3808
+ const widthPt = widthValue === void 0 ? void 0 : (0, odf_js.parseOdfLength)(widthValue);
3809
+ return color === void 0 || widthPt === void 0 ? void 0 : {
3810
+ color,
3811
+ widthPt
3812
+ };
3813
+ }
3814
+ function setGraphicFill(pkg, element, fill) {
3815
+ setAttr(element, "draw:style-name", buildGraphicStyle(pkg, {
3816
+ fill,
3817
+ stroke: readGraphicStroke(pkg, element)
3818
+ }));
3819
+ }
3820
+ function setGraphicStroke(pkg, element, stroke) {
3821
+ setAttr(element, "draw:style-name", buildGraphicStyle(pkg, {
3822
+ fill: readGraphicFill(pkg, element),
3823
+ stroke
3824
+ }));
3825
+ }
3826
+ //#endregion
3827
+ //#region src/edit/odg/svg-path.ts
3828
+ const PATH_NUMBER_DECIMALS = 6;
3829
+ const PATH_NUMBER_SCALE = 10 ** PATH_NUMBER_DECIMALS;
3830
+ function formatPathNumber(value) {
3831
+ if (!Number.isFinite(value)) throw new Error(`cannot format a non-finite path coordinate: ${value}`);
3832
+ const rounded = Math.round(value * PATH_NUMBER_SCALE) / PATH_NUMBER_SCALE;
3833
+ if (rounded === 0) return "0";
3834
+ return rounded.toFixed(PATH_NUMBER_DECIMALS).replace(/0+$/, "").replace(/\.$/, "");
3835
+ }
3836
+ function formatPathPoint(point) {
3837
+ return `${formatPathNumber(point.xPt)} ${formatPathNumber(point.yPt)}`;
3838
+ }
3839
+ function buildSvgPathData(subpaths) {
3840
+ const commands = [];
3841
+ for (const subpath of subpaths) {
3842
+ commands.push(`M${formatPathPoint(subpath.start)}`);
3843
+ for (const segment of subpath.segments) if (segment.kind === "line") commands.push(`L${formatPathPoint(segment.to)}`);
3844
+ else commands.push(`C${formatPathPoint(segment.control1)} ${formatPathPoint(segment.control2)} ${formatPathPoint(segment.to)}`);
3845
+ if (subpath.closed) commands.push("Z");
3846
+ }
3847
+ return commands.join(" ");
3848
+ }
3849
+ function buildSvgViewBox(widthPt, heightPt) {
3850
+ return `0 0 ${formatPathNumber(widthPt)} ${formatPathNumber(heightPt)}`;
3851
+ }
3852
+ //#endregion
3853
+ //#region src/edit/odg/vector.ts
3854
+ function directTextP() {
3855
+ return el("text:p");
3856
+ }
3857
+ function buildBoxVectorElement(pkg, tag, init) {
3858
+ return el(tag, {
3859
+ "draw:style-name": buildGraphicStyle(pkg, {
3860
+ fill: init.fill,
3861
+ stroke: init.stroke
3862
+ }),
3863
+ "svg:x": (0, odf_js.formatOdfLength)(init.frame.xPt),
3864
+ "svg:y": (0, odf_js.formatOdfLength)(init.frame.yPt),
3865
+ "svg:width": (0, odf_js.formatOdfLength)(init.frame.widthPt),
3866
+ "svg:height": (0, odf_js.formatOdfLength)(init.frame.heightPt)
3867
+ }, [directTextP()]);
3868
+ }
3869
+ function buildRectElement(pkg, init) {
3870
+ return buildBoxVectorElement(pkg, "draw:rect", init);
3871
+ }
3872
+ function buildEllipseElement(pkg, init) {
3873
+ return buildBoxVectorElement(pkg, "draw:ellipse", init);
3874
+ }
3875
+ var OdgBoxVector = class {
3876
+ container;
3877
+ node;
3878
+ pkg;
3879
+ removed = false;
3880
+ constructor(container, node, pkg) {
3881
+ this.container = container;
3882
+ this.node = node;
3883
+ this.pkg = pkg;
3884
+ }
3885
+ live() {
3886
+ if (this.removed) throw new Error("this OdgBoxVector has been removed from its page and can no longer be used");
3887
+ return this.node;
3888
+ }
3889
+ get kind() {
3890
+ return this.live().tag === "draw:ellipse" ? "ellipse" : "rect";
3891
+ }
3892
+ get name() {
3893
+ return (0, ooxml_js.attr)(this.live(), "draw:name");
3894
+ }
3895
+ get frame() {
3896
+ return (0, odf_js.parseBox)(this.live());
3897
+ }
3898
+ set frame(value) {
3899
+ const node = this.live();
3900
+ setAttr(node, "svg:x", (0, odf_js.formatOdfLength)(value.xPt));
3901
+ setAttr(node, "svg:y", (0, odf_js.formatOdfLength)(value.yPt));
3902
+ setAttr(node, "svg:width", (0, odf_js.formatOdfLength)(value.widthPt));
3903
+ setAttr(node, "svg:height", (0, odf_js.formatOdfLength)(value.heightPt));
3904
+ }
3905
+ get fill() {
3906
+ return readGraphicFill(this.pkg, this.live());
3907
+ }
3908
+ set fill(value) {
3909
+ setGraphicFill(this.pkg, this.live(), value);
3910
+ }
3911
+ get stroke() {
3912
+ return readGraphicStroke(this.pkg, this.live());
3913
+ }
3914
+ set stroke(value) {
3915
+ setGraphicStroke(this.pkg, this.live(), value);
3916
+ }
3917
+ remove() {
3918
+ removeChild(this.container, this.live());
3919
+ this.removed = true;
3920
+ }
3921
+ };
3922
+ function buildLineElement(pkg, init) {
3923
+ return el("draw:line", {
3924
+ "draw:style-name": buildGraphicStyle(pkg, { stroke: init.stroke }),
3925
+ "svg:x1": (0, odf_js.formatOdfLength)(init.from.xPt),
3926
+ "svg:y1": (0, odf_js.formatOdfLength)(init.from.yPt),
3927
+ "svg:x2": (0, odf_js.formatOdfLength)(init.to.xPt),
3928
+ "svg:y2": (0, odf_js.formatOdfLength)(init.to.yPt)
3929
+ }, [directTextP()]);
3930
+ }
3931
+ var OdgLineVector = class {
3932
+ container;
3933
+ node;
3934
+ pkg;
3935
+ removed = false;
3936
+ constructor(container, node, pkg) {
3937
+ this.container = container;
3938
+ this.node = node;
3939
+ this.pkg = pkg;
3940
+ }
3941
+ live() {
3942
+ if (this.removed) throw new Error("this OdgLineVector has been removed from its page and can no longer be used");
3943
+ return this.node;
3944
+ }
3945
+ get name() {
3946
+ return (0, ooxml_js.attr)(this.live(), "draw:name");
3947
+ }
3948
+ get from() {
3949
+ return (0, odf_js.parseLinePoints)(this.live())?.from;
3950
+ }
3951
+ set from(value) {
3952
+ const node = this.live();
3953
+ setAttr(node, "svg:x1", (0, odf_js.formatOdfLength)(value.xPt));
3954
+ setAttr(node, "svg:y1", (0, odf_js.formatOdfLength)(value.yPt));
3955
+ }
3956
+ get to() {
3957
+ return (0, odf_js.parseLinePoints)(this.live())?.to;
3958
+ }
3959
+ set to(value) {
3960
+ const node = this.live();
3961
+ setAttr(node, "svg:x2", (0, odf_js.formatOdfLength)(value.xPt));
3962
+ setAttr(node, "svg:y2", (0, odf_js.formatOdfLength)(value.yPt));
3963
+ }
3964
+ get stroke() {
3965
+ return readGraphicStroke(this.pkg, this.live());
3966
+ }
3967
+ set stroke(value) {
3968
+ setGraphicStroke(this.pkg, this.live(), value);
3969
+ }
3970
+ remove() {
3971
+ removeChild(this.container, this.live());
3972
+ this.removed = true;
3973
+ }
3974
+ };
3975
+ function buildPathElement(pkg, init) {
3976
+ return el("draw:path", {
3977
+ "draw:style-name": buildGraphicStyle(pkg, {
3978
+ fill: init.fill,
3979
+ stroke: init.stroke
3980
+ }),
3981
+ "svg:x": (0, odf_js.formatOdfLength)(init.frame.xPt),
3982
+ "svg:y": (0, odf_js.formatOdfLength)(init.frame.yPt),
3983
+ "svg:width": (0, odf_js.formatOdfLength)(init.frame.widthPt),
3984
+ "svg:height": (0, odf_js.formatOdfLength)(init.frame.heightPt),
3985
+ "svg:viewBox": buildSvgViewBox(init.frame.widthPt, init.frame.heightPt),
3986
+ "svg:d": buildSvgPathData(init.subpaths)
3987
+ }, [directTextP()]);
3988
+ }
3989
+ var OdgPathVector = class {
3990
+ container;
3991
+ node;
3992
+ pkg;
3993
+ removed = false;
3994
+ constructor(container, node, pkg) {
3995
+ this.container = container;
3996
+ this.node = node;
3997
+ this.pkg = pkg;
3998
+ }
3999
+ live() {
4000
+ if (this.removed) throw new Error("this OdgPathVector has been removed from its page and can no longer be used");
4001
+ return this.node;
4002
+ }
4003
+ get name() {
4004
+ return (0, ooxml_js.attr)(this.live(), "draw:name");
4005
+ }
4006
+ get frame() {
4007
+ return (0, odf_js.parseBox)(this.live());
4008
+ }
4009
+ set frame(value) {
4010
+ const node = this.live();
4011
+ setAttr(node, "svg:x", (0, odf_js.formatOdfLength)(value.xPt));
4012
+ setAttr(node, "svg:y", (0, odf_js.formatOdfLength)(value.yPt));
4013
+ setAttr(node, "svg:width", (0, odf_js.formatOdfLength)(value.widthPt));
4014
+ setAttr(node, "svg:height", (0, odf_js.formatOdfLength)(value.heightPt));
4015
+ }
4016
+ get fill() {
4017
+ return readGraphicFill(this.pkg, this.live());
4018
+ }
4019
+ set fill(value) {
4020
+ setGraphicFill(this.pkg, this.live(), value);
4021
+ }
4022
+ get stroke() {
4023
+ return readGraphicStroke(this.pkg, this.live());
4024
+ }
4025
+ set stroke(value) {
4026
+ setGraphicStroke(this.pkg, this.live(), value);
4027
+ }
4028
+ get subpaths() {
4029
+ const node = this.live();
4030
+ const viewBoxValue = (0, ooxml_js.attr)(node, "svg:viewBox");
4031
+ const dValue = (0, ooxml_js.attr)(node, "svg:d");
4032
+ const frame = (0, odf_js.parseBox)(node);
4033
+ if (viewBoxValue === void 0 || dValue === void 0 || frame === void 0) return [];
4034
+ const viewBox = (0, odf_js.parseOdfViewBox)(viewBoxValue);
4035
+ if (viewBox === void 0) return [];
4036
+ return (0, odf_js.buildOdfSubpaths)((0, odf_js.parseOdfPathData)(dValue), viewBox, frame);
4037
+ }
4038
+ remove() {
4039
+ removeChild(this.container, this.live());
4040
+ this.removed = true;
4041
+ }
4042
+ };
4043
+ //#endregion
4044
+ //#region src/edit/odg/page.ts
4045
+ var OdgPage = class {
3508
4046
  container;
3509
4047
  node;
3510
- pkg;
4048
+ context;
3511
4049
  removed = false;
3512
- constructor(container, node, pkg) {
4050
+ constructor(container, node, context) {
3513
4051
  this.container = container;
3514
4052
  this.node = node;
3515
- this.pkg = pkg;
4053
+ this.context = context;
3516
4054
  }
3517
4055
  live() {
3518
- if (this.removed) throw new Error("this OdsSheet has been removed from the spreadsheet and can no longer be used");
4056
+ if (this.removed) throw new Error("this OdgPage has been removed from the drawing and can no longer be used");
3519
4057
  return this.node;
3520
4058
  }
3521
- get name() {
3522
- const value = (0, ooxml_js.attr)(this.live(), NAME_ATTR);
3523
- if (value === void 0) throw new Error("this table:table element has no table:name attribute");
3524
- return value;
4059
+ shapes() {
4060
+ const node = this.live();
4061
+ const out = [];
4062
+ for (const child of node.children) if (child.type === "element" && child.tag === "draw:frame") out.push(new OdpShape(node.children, child, this.context.pkg));
4063
+ return out;
3525
4064
  }
3526
- set name(value) {
3527
- setAttr(this.live(), NAME_ATTR, value);
4065
+ addTextBox(init) {
4066
+ const node = this.live();
4067
+ const frameElement = buildTextBoxFrame(this.context.pkg, init.frame, init.text);
4068
+ node.children.push(frameElement);
4069
+ return new OdpShape(node.children, frameElement, this.context.pkg);
3528
4070
  }
3529
- cell(row, column) {
3530
- const node = resolveCellNode(this.live(), row, column);
3531
- 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`);
3532
- return new OdsCell(node, this.pkg);
4071
+ addImage(init) {
4072
+ const node = this.live();
4073
+ const frameElement = insertImageFrameMedia({ pkg: this.context.pkg }, init.frame, init);
4074
+ node.children.push(frameElement);
4075
+ return new OdpShape(node.children, frameElement, this.context.pkg);
3533
4076
  }
3534
- cellAt(reference) {
3535
- const parsed = (0, odf_js.parseCellReference)(reference);
3536
- if (parsed === void 0) throw new Error(`cellAt: "${reference}" is not a valid A1-style cell reference`);
3537
- return this.cell(parsed.row, parsed.column);
4077
+ addRect(init) {
4078
+ const node = this.live();
4079
+ const element = buildRectElement(this.context.pkg, init);
4080
+ node.children.push(element);
4081
+ return new OdgBoxVector(node.children, element, this.context.pkg);
3538
4082
  }
3539
- mergeCells(startRow, startColumn, rowSpan, colSpan) {
3540
- 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}`);
3541
- const tableElement = this.live();
3542
- const anchorNode = resolveCellNode(tableElement, startRow, startColumn);
3543
- if (anchorNode.tag === "table:covered-table-cell") throw new Error(`mergeCells: (${startRow}, ${startColumn}) is already covered by another merged range`);
3544
- if (rowSpan > 1) setAttr(anchorNode, "table:number-rows-spanned", String(rowSpan));
3545
- if (colSpan > 1) setAttr(anchorNode, "table:number-columns-spanned", String(colSpan));
3546
- for (let rowOffset = 0; rowOffset < rowSpan; rowOffset++) for (let columnOffset = 0; columnOffset < colSpan; columnOffset++) {
3547
- if (rowOffset === 0 && columnOffset === 0) continue;
3548
- const coveredNode = resolveCellNode(tableElement, startRow + rowOffset, startColumn + columnOffset);
3549
- coveredNode.tag = COVERED_CELL_TAG;
3550
- coveredNode.attributes = [];
3551
- coveredNode.children = [];
3552
- }
3553
- return new OdsCell(anchorNode, this.pkg);
4083
+ addEllipse(init) {
4084
+ const node = this.live();
4085
+ const element = buildEllipseElement(this.context.pkg, init);
4086
+ node.children.push(element);
4087
+ return new OdgBoxVector(node.children, element, this.context.pkg);
4088
+ }
4089
+ addLine(init) {
4090
+ const node = this.live();
4091
+ const element = buildLineElement(this.context.pkg, init);
4092
+ node.children.push(element);
4093
+ return new OdgLineVector(node.children, element, this.context.pkg);
4094
+ }
4095
+ addPath(init) {
4096
+ const node = this.live();
4097
+ const element = buildPathElement(this.context.pkg, init);
4098
+ node.children.push(element);
4099
+ return new OdgPathVector(node.children, element, this.context.pkg);
3554
4100
  }
3555
4101
  remove() {
3556
4102
  removeChild(this.container, this.live());
@@ -3558,64 +4104,78 @@ var OdsSheet = class {
3558
4104
  }
3559
4105
  };
3560
4106
  //#endregion
3561
- //#region src/edit/ods/editor.ts
4107
+ //#region src/edit/odg/editor.ts
3562
4108
  const CONTENT_PART_PATH = "content.xml";
4109
+ const STYLES_PART_PATH = "styles.xml";
3563
4110
  function directChild(parent, tag) {
3564
4111
  for (const child of parent.children) if (child.type === "element" && child.tag === tag) return child;
3565
4112
  }
3566
- function findRoot(pkg) {
3567
- const part = pkg.parts[CONTENT_PART_PATH];
4113
+ function findRoot(pkg, partPath) {
4114
+ const part = pkg.parts[partPath];
3568
4115
  const root = part?.kind === "xml" ? part.nodes.find((n) => n.type === "element") : void 0;
3569
- if (root === void 0) throw new Error(`package has no root element at ${CONTENT_PART_PATH}`);
4116
+ if (root === void 0) throw new Error(`package has no root element at ${partPath}`);
3570
4117
  return root;
3571
4118
  }
3572
- function findOfficeSpreadsheet(pkg) {
3573
- const body = directChild(findRoot(pkg), "office:body");
3574
- const spreadsheet = body === void 0 ? void 0 : directChild(body, "office:spreadsheet");
3575
- if (spreadsheet === void 0) throw new Error(`${CONTENT_PART_PATH} has no office:body/office:spreadsheet element`);
3576
- return spreadsheet;
4119
+ function findOfficeDrawing(pkg) {
4120
+ const body = directChild(findRoot(pkg, CONTENT_PART_PATH), "office:body");
4121
+ const drawing = body === void 0 ? void 0 : directChild(body, "office:drawing");
4122
+ if (drawing === void 0) throw new Error(`${CONTENT_PART_PATH} has no office:body/office:drawing element`);
4123
+ return drawing;
3577
4124
  }
3578
- function ensureSheetTableStyleName(pkg) {
3579
- const automaticStyles = ensureAutomaticStyles(pkg);
3580
- if (automaticStyles.children.find((child) => child.type === "element" && child.tag === "style:style" && (0, ooxml_js.attr)(child, "style:name") === "OdsTable") !== void 0) return SHEET_TABLE_STYLE_NAME;
3581
- automaticStyles.children.push(el("style:style", {
3582
- "style:name": SHEET_TABLE_STYLE_NAME,
3583
- "style:family": "table",
3584
- "style:master-page-name": MASTER_PAGE_NAME
3585
- }));
3586
- return SHEET_TABLE_STYLE_NAME;
4125
+ function findPageLayoutProperties(pkg) {
4126
+ const pageLayout = directChild(findRoot(pkg, STYLES_PART_PATH), "office:automatic-styles")?.children.find((c) => c.type === "element" && c.tag === "style:page-layout" && (0, ooxml_js.attr)(c, "style:name") === "PM1");
4127
+ const properties = pageLayout === void 0 ? void 0 : directChild(pageLayout, "style:page-layout-properties");
4128
+ if (properties === void 0) throw new Error(`${STYLES_PART_PATH} has no style:page-layout[style:name="PM1"]/style:page-layout-properties element`);
4129
+ return properties;
3587
4130
  }
3588
- var OdsEditor = class {
4131
+ var OdgEditor = class {
3589
4132
  pkg;
3590
4133
  constructor(pkg) {
3591
4134
  this.pkg = pkg;
3592
4135
  }
3593
- sheets() {
3594
- const spreadsheet = findOfficeSpreadsheet(this.pkg);
4136
+ pages() {
4137
+ const drawing = findOfficeDrawing(this.pkg);
3595
4138
  const out = [];
3596
- for (const child of spreadsheet.children) if (child.type === "element" && child.tag === "table:table") out.push(new OdsSheet(spreadsheet.children, child, this.pkg));
4139
+ for (const child of drawing.children) if (child.type === "element" && child.tag === "draw:page") {
4140
+ const context = { pkg: this.pkg };
4141
+ out.push(new OdgPage(drawing.children, child, context));
4142
+ }
3597
4143
  return out;
3598
4144
  }
3599
- sheet(name) {
3600
- const found = this.sheets().find((candidate) => candidate.name === name);
3601
- if (found === void 0) throw new Error(`no sheet named "${name}" exists in this spreadsheet`);
3602
- return found;
4145
+ addPage() {
4146
+ const drawing = findOfficeDrawing(this.pkg);
4147
+ const pageElement = el("draw:page", { "draw:master-page-name": MASTER_PAGE_NAME });
4148
+ drawing.children.push(pageElement);
4149
+ const context = { pkg: this.pkg };
4150
+ return new OdgPage(drawing.children, pageElement, context);
3603
4151
  }
3604
- addSheet(name) {
3605
- const spreadsheet = findOfficeSpreadsheet(this.pkg);
3606
- const tableElement = el("table:table", {
3607
- "table:name": name,
3608
- "table:style-name": ensureSheetTableStyleName(this.pkg)
3609
- });
3610
- spreadsheet.children.push(tableElement);
3611
- return new OdsSheet(spreadsheet.children, tableElement, this.pkg);
4152
+ removePageAt(index) {
4153
+ const drawing = findOfficeDrawing(this.pkg);
4154
+ const target = drawing.children.filter((c) => c.type === "element" && c.tag === "draw:page")[index];
4155
+ if (target === void 0) throw new Error(`page index ${index} does not exist`);
4156
+ const listIndex = drawing.children.indexOf(target);
4157
+ drawing.children.splice(listIndex, 1);
3612
4158
  }
3613
- removeSheetAt(index) {
3614
- const spreadsheet = findOfficeSpreadsheet(this.pkg);
3615
- const target = spreadsheet.children.filter((child) => child.type === "element" && child.tag === "table:table")[index];
3616
- if (target === void 0) throw new Error(`sheet index ${index} does not exist`);
3617
- const listIndex = spreadsheet.children.indexOf(target);
3618
- spreadsheet.children.splice(listIndex, 1);
4159
+ get pageSize() {
4160
+ const properties = findPageLayoutProperties(this.pkg);
4161
+ const widthValue = (0, ooxml_js.attr)(properties, "fo:page-width");
4162
+ const heightValue = (0, ooxml_js.attr)(properties, "fo:page-height");
4163
+ const widthPt = widthValue === void 0 ? void 0 : (0, odf_js.parseOdfLength)(widthValue);
4164
+ const heightPt = heightValue === void 0 ? void 0 : (0, odf_js.parseOdfLength)(heightValue);
4165
+ return {
4166
+ widthPt: widthPt ?? 0,
4167
+ heightPt: heightPt ?? 0
4168
+ };
4169
+ }
4170
+ set pageSize(size) {
4171
+ const properties = findPageLayoutProperties(this.pkg);
4172
+ properties.attributes = [{
4173
+ name: "fo:page-width",
4174
+ value: (0, odf_js.formatOdfLength)(size.widthPt)
4175
+ }, {
4176
+ name: "fo:page-height",
4177
+ value: (0, odf_js.formatOdfLength)(size.heightPt)
4178
+ }];
3619
4179
  }
3620
4180
  toPackage() {
3621
4181
  return this.pkg;
@@ -3624,33 +4184,71 @@ var OdsEditor = class {
3624
4184
  return (0, odf_js.encodePackage)(this.pkg);
3625
4185
  }
3626
4186
  };
3627
- function openOds(bytes) {
3628
- return new OdsEditor((0, odf_js.decodePackage)(bytes));
4187
+ function openOdg(bytes) {
4188
+ return new OdgEditor((0, odf_js.decodePackage)(bytes));
3629
4189
  }
3630
- function createOds() {
3631
- return new OdsEditor(createEmptyOdsPackage());
4190
+ function createOdg() {
4191
+ return new OdgEditor(createEmptyOdgPackage());
3632
4192
  }
3633
4193
  //#endregion
3634
- //#region src/edit/ods/content.ts
3635
- function buildOdsPackage(content) {
3636
- if (content.kind !== "spreadsheet") throw new Error("buildOdsPackage requires a spreadsheet ContentDocument");
3637
- const editor = createOds();
3638
- if (content.sheets.length > 0) editor.removeSheetAt(0);
3639
- for (const sheet of content.sheets) {
3640
- const odsSheet = editor.addSheet(sheet.name);
3641
- for (const cell of sheet.cells) appendCell(odsSheet, cell);
4194
+ //#region src/edit/odg/content.ts
4195
+ function buildOdgPackage(content) {
4196
+ if (content.kind !== "drawing") throw new Error("buildOdgPackage requires a drawing ContentDocument");
4197
+ const editor = createOdg();
4198
+ const firstPage = content.pages[0];
4199
+ if (firstPage !== void 0) editor.pageSize = firstPage.size;
4200
+ for (const page of content.pages) {
4201
+ const odgPage = editor.addPage();
4202
+ for (const vector of page.vectors) appendVector(odgPage, vector);
4203
+ for (const shape of page.shapes) appendShape(odgPage, shape);
3642
4204
  }
3643
4205
  return editor.toPackage();
3644
4206
  }
3645
- function appendCell(odsSheet, cell) {
3646
- const odsCell = odsSheet.cell(cell.row, cell.column);
3647
- odsCell.value = cell.value;
3648
- if (cell.formula !== void 0) odsCell.formula = cell.formula;
3649
- if (cell.runs !== void 0 && cell.runs.length > 0) odsCell.setStyledRuns(cell.runs);
3650
- else odsCell.displayText = cell.displayText;
3651
- const rowSpan = cell.rowSpan ?? 1;
3652
- const colSpan = cell.colSpan ?? 1;
3653
- if (rowSpan > 1 || colSpan > 1) odsSheet.mergeCells(cell.row, cell.column, rowSpan, colSpan);
4207
+ function appendVector(page, vector) {
4208
+ if (vector.kind === "rect") page.addRect({
4209
+ frame: vector.frame,
4210
+ fill: vector.fill,
4211
+ stroke: vector.stroke
4212
+ });
4213
+ else if (vector.kind === "ellipse") page.addEllipse({
4214
+ frame: vector.frame,
4215
+ fill: vector.fill,
4216
+ stroke: vector.stroke
4217
+ });
4218
+ else if (vector.kind === "line") page.addLine({
4219
+ from: vector.from,
4220
+ to: vector.to,
4221
+ stroke: vector.stroke
4222
+ });
4223
+ else page.addPath({
4224
+ frame: vector.frame,
4225
+ subpaths: vector.subpaths,
4226
+ fill: vector.fill,
4227
+ stroke: vector.stroke
4228
+ });
4229
+ }
4230
+ function appendShape(page, shape) {
4231
+ const [onlyBlock] = shape.blocks;
4232
+ if (shape.blocks.length === 1 && onlyBlock?.kind === "image") {
4233
+ const imageShape = page.addImage({
4234
+ frame: shape.frame,
4235
+ format: onlyBlock.format,
4236
+ bytes: (0, odf_js.base64ToBytes)(onlyBlock.base64),
4237
+ altText: onlyBlock.altText
4238
+ });
4239
+ if (shape.rotationDeg !== void 0) imageShape.rotationDeg = shape.rotationDeg;
4240
+ return;
4241
+ }
4242
+ const textShape = page.addTextBox({
4243
+ frame: shape.frame,
4244
+ text: ""
4245
+ });
4246
+ if (shape.rotationDeg !== void 0) textShape.rotationDeg = shape.rotationDeg;
4247
+ textShape.paragraphs()[0]?.remove();
4248
+ for (const block of shape.blocks) {
4249
+ if (block.kind !== "paragraph") continue;
4250
+ populateParagraph(textShape.appendParagraph(), block);
4251
+ }
3654
4252
  }
3655
4253
  //#endregion
3656
4254
  //#region src/bytes/crc32.ts
@@ -7604,11 +8202,15 @@ function writeText(writer, item, context, substitutions) {
7604
8202
  writeUnderline(writer, item, item.widthPt ?? encoded.width1000 / 1e3 * item.sizePt * scale, context.measurer);
7605
8203
  }
7606
8204
  }
7607
- function paintOperatorFor(fill, stroke) {
7608
- if (fill !== void 0 && stroke !== void 0) return "B";
7609
- if (fill !== void 0) return "f";
8205
+ function paintOperatorFor(fill, stroke, fillRule) {
8206
+ const evenOdd = fillRule === "evenodd";
8207
+ if (fill !== void 0 && stroke !== void 0) return evenOdd ? "B*" : "B";
8208
+ if (fill !== void 0) return evenOdd ? "f*" : "f";
7610
8209
  if (stroke !== void 0) return "S";
7611
8210
  }
8211
+ function formatPoint(x, y) {
8212
+ return `${formatNumber(x)} ${formatNumber(y)}`;
8213
+ }
7612
8214
  function writeFillAndStroke(writer, fill, stroke) {
7613
8215
  if (fill !== void 0) writeRgbOperator(writer, fill, "rg");
7614
8216
  if (stroke !== void 0) {
@@ -7639,12 +8241,24 @@ function writeEllipse(writer, item) {
7639
8241
  const ry = item.heightPt / 2;
7640
8242
  const kx = rx * BEZIER_KAPPA;
7641
8243
  const ky = ry * BEZIER_KAPPA;
7642
- const point = (x, y) => `${formatNumber(x)} ${formatNumber(y)}`;
7643
- writer.writeAscii(`${point(cx + rx, cy)} m\n`);
7644
- writer.writeAscii(`${point(cx + rx, cy + ky)} ${point(cx + kx, cy + ry)} ${point(cx, cy + ry)} c\n`);
7645
- writer.writeAscii(`${point(cx - kx, cy + ry)} ${point(cx - rx, cy + ky)} ${point(cx - rx, cy)} c\n`);
7646
- writer.writeAscii(`${point(cx - rx, cy - ky)} ${point(cx - kx, cy - ry)} ${point(cx, cy - ry)} c\n`);
7647
- writer.writeAscii(`${point(cx + kx, cy - ry)} ${point(cx + rx, cy - ky)} ${point(cx + rx, cy)} c\n`);
8244
+ writer.writeAscii(`${formatPoint(cx + rx, cy)} m\n`);
8245
+ writer.writeAscii(`${formatPoint(cx + rx, cy + ky)} ${formatPoint(cx + kx, cy + ry)} ${formatPoint(cx, cy + ry)} c\n`);
8246
+ writer.writeAscii(`${formatPoint(cx - kx, cy + ry)} ${formatPoint(cx - rx, cy + ky)} ${formatPoint(cx - rx, cy)} c\n`);
8247
+ writer.writeAscii(`${formatPoint(cx - rx, cy - ky)} ${formatPoint(cx - kx, cy - ry)} ${formatPoint(cx, cy - ry)} c\n`);
8248
+ writer.writeAscii(`${formatPoint(cx + kx, cy - ry)} ${formatPoint(cx + rx, cy - ky)} ${formatPoint(cx + rx, cy)} c\n`);
8249
+ writer.writeAscii(`${paint}\n`);
8250
+ }
8251
+ function writeSubpath(writer, subpath) {
8252
+ writer.writeAscii(`${formatPoint(subpath.startXPt, subpath.startYPt)} m\n`);
8253
+ for (const segment of subpath.segments) if (segment.kind === "line") writer.writeAscii(`${formatPoint(segment.xPt, segment.yPt)} l\n`);
8254
+ else writer.writeAscii(`${formatPoint(segment.c1xPt, segment.c1yPt)} ${formatPoint(segment.c2xPt, segment.c2yPt)} ${formatPoint(segment.xPt, segment.yPt)} c\n`);
8255
+ if (subpath.closed) writer.writeAscii("h\n");
8256
+ }
8257
+ function writePath(writer, item) {
8258
+ const paint = paintOperatorFor(item.fill, item.stroke, item.fillRule);
8259
+ if (paint === void 0) return;
8260
+ writeFillAndStroke(writer, item.fill, item.stroke);
8261
+ for (const subpath of item.subpaths) writeSubpath(writer, subpath);
7648
8262
  writer.writeAscii(`${paint}\n`);
7649
8263
  }
7650
8264
  function writeImage(writer, item, context) {
@@ -7663,6 +8277,7 @@ function writeContentStream(items, context) {
7663
8277
  else if (item.kind === "rect") writeRect(writer, item);
7664
8278
  else if (item.kind === "line") writeLine(writer, item);
7665
8279
  else if (item.kind === "ellipse") writeEllipse(writer, item);
8280
+ else if (item.kind === "path") writePath(writer, item);
7666
8281
  return {
7667
8282
  bytes: writer.toBytes(),
7668
8283
  substitutions
@@ -8469,6 +9084,17 @@ function readOdsContent(pkg) {
8469
9084
  };
8470
9085
  }
8471
9086
  //#endregion
9087
+ //#region src/odf/odg/read.ts
9088
+ function readOdgContent(pkg) {
9089
+ const odgDoc = (0, odf_js.readOdg)(pkg);
9090
+ return {
9091
+ kind: "drawing",
9092
+ formatVersion: 1,
9093
+ metadata: { ...odgDoc.metadata },
9094
+ pages: odgDoc.pages
9095
+ };
9096
+ }
9097
+ //#endregion
8472
9098
  //#region src/pdf/text-layout.ts
8473
9099
  const WORD_OR_WHITESPACE_PATTERN = /\n|\s+|\S+/g;
8474
9100
  function atomizeRuns(runs, measurer) {
@@ -9500,6 +10126,118 @@ function convertSpreadsheetToLayout(doc, options) {
9500
10126
  };
9501
10127
  }
9502
10128
  //#endregion
10129
+ //#region src/layout/drawing.ts
10130
+ function convertRectVector(vector, pageHeightPt, out) {
10131
+ const flipped = flipY(vector.frame, pageHeightPt);
10132
+ out.push({
10133
+ kind: "rect",
10134
+ xPt: flipped.xPt,
10135
+ yPt: flipped.yPt,
10136
+ widthPt: flipped.widthPt,
10137
+ heightPt: flipped.heightPt,
10138
+ fill: vector.fill,
10139
+ stroke: vector.stroke,
10140
+ sourcePath: vector.sourcePath
10141
+ });
10142
+ }
10143
+ function convertEllipseVector(vector, pageHeightPt, out) {
10144
+ const flipped = flipY(vector.frame, pageHeightPt);
10145
+ out.push({
10146
+ kind: "ellipse",
10147
+ xPt: flipped.xPt,
10148
+ yPt: flipped.yPt,
10149
+ widthPt: flipped.widthPt,
10150
+ heightPt: flipped.heightPt,
10151
+ fill: vector.fill,
10152
+ stroke: vector.stroke,
10153
+ sourcePath: vector.sourcePath
10154
+ });
10155
+ }
10156
+ function convertLineVector(vector, pageHeightPt, out) {
10157
+ out.push({
10158
+ kind: "line",
10159
+ x1Pt: vector.from.xPt,
10160
+ y1Pt: pageHeightPt - vector.from.yPt,
10161
+ x2Pt: vector.to.xPt,
10162
+ y2Pt: pageHeightPt - vector.to.yPt,
10163
+ color: vector.stroke.color,
10164
+ widthPt: vector.stroke.widthPt,
10165
+ sourcePath: vector.sourcePath
10166
+ });
10167
+ }
10168
+ function placePathPoint(frame, point, pageHeightPt) {
10169
+ return {
10170
+ xPt: frame.xPt + point.xPt,
10171
+ yPt: pageHeightPt - frame.yPt - point.yPt
10172
+ };
10173
+ }
10174
+ function convertPathVector(vector, pageHeightPt, out) {
10175
+ const subpaths = vector.subpaths.map((subpath) => {
10176
+ const start = placePathPoint(vector.frame, subpath.start, pageHeightPt);
10177
+ return {
10178
+ startXPt: start.xPt,
10179
+ startYPt: start.yPt,
10180
+ closed: subpath.closed,
10181
+ segments: subpath.segments.map((segment) => {
10182
+ if (segment.kind === "line") {
10183
+ const to = placePathPoint(vector.frame, segment.to, pageHeightPt);
10184
+ return {
10185
+ kind: "line",
10186
+ xPt: to.xPt,
10187
+ yPt: to.yPt
10188
+ };
10189
+ }
10190
+ const control1 = placePathPoint(vector.frame, segment.control1, pageHeightPt);
10191
+ const control2 = placePathPoint(vector.frame, segment.control2, pageHeightPt);
10192
+ const to = placePathPoint(vector.frame, segment.to, pageHeightPt);
10193
+ return {
10194
+ kind: "cubic",
10195
+ c1xPt: control1.xPt,
10196
+ c1yPt: control1.yPt,
10197
+ c2xPt: control2.xPt,
10198
+ c2yPt: control2.yPt,
10199
+ xPt: to.xPt,
10200
+ yPt: to.yPt
10201
+ };
10202
+ })
10203
+ };
10204
+ });
10205
+ out.push({
10206
+ kind: "path",
10207
+ subpaths,
10208
+ fill: vector.fill,
10209
+ fillRule: vector.fillRule,
10210
+ stroke: vector.stroke,
10211
+ sourcePath: vector.sourcePath
10212
+ });
10213
+ }
10214
+ function convertVector(vector, pageHeightPt, out) {
10215
+ if (vector.kind === "rect") convertRectVector(vector, pageHeightPt, out);
10216
+ else if (vector.kind === "ellipse") convertEllipseVector(vector, pageHeightPt, out);
10217
+ else if (vector.kind === "line") convertLineVector(vector, pageHeightPt, out);
10218
+ else convertPathVector(vector, pageHeightPt, out);
10219
+ }
10220
+ function convertPage(page, measurer, images) {
10221
+ const items = [];
10222
+ for (const vector of page.vectors) convertVector(vector, page.size.heightPt, items);
10223
+ for (const shape of page.shapes) convertShape(shape, page.size.heightPt, measurer, images, items);
10224
+ return {
10225
+ widthPt: page.size.widthPt,
10226
+ heightPt: page.size.heightPt,
10227
+ items
10228
+ };
10229
+ }
10230
+ function convertDrawingToLayout(doc, options) {
10231
+ const images = {};
10232
+ const pages = doc.pages.map((page) => convertPage(page, options.measurer, images));
10233
+ return {
10234
+ formatVersion: document_content_model.LAYOUT_FORMAT_VERSION,
10235
+ metadata: doc.metadata,
10236
+ pages,
10237
+ images
10238
+ };
10239
+ }
10240
+ //#endregion
9503
10241
  //#region src/layout/reconstruct.ts
9504
10242
  const ZERO_MARGINS = {
9505
10243
  topPt: 0,
@@ -9879,6 +10617,14 @@ function odsToPdf(bytes, options) {
9879
10617
  onSubstitution: options?.onSubstitution
9880
10618
  });
9881
10619
  }
10620
+ function odgToPdf(bytes, options) {
10621
+ const content = readOdgContent((0, odf_js.decodePackage)(bytes));
10622
+ if (content.kind !== "drawing") throw new Error("readOdgContent returned a non-drawing ContentDocument");
10623
+ return writePdf(convertDrawingToLayout(content, { measurer: createStandardFontMeasurer() }), {
10624
+ signal: options?.signal,
10625
+ onSubstitution: options?.onSubstitution
10626
+ });
10627
+ }
9882
10628
  function pdfToDocx(bytes, options) {
9883
10629
  const content = reconstructWordprocessing(readPdf(bytes, {
9884
10630
  signal: options?.signal,
@@ -9948,6 +10694,10 @@ const SUPPORTED_CONVERSIONS = [
9948
10694
  source: "ods",
9949
10695
  target: "pdf"
9950
10696
  },
10697
+ {
10698
+ source: "odg",
10699
+ target: "pdf"
10700
+ },
9951
10701
  {
9952
10702
  source: "pdf",
9953
10703
  target: "docx"
@@ -10053,6 +10803,19 @@ function createLocalDocumentConverter() {
10053
10803
  diagnostics
10054
10804
  });
10055
10805
  }
10806
+ if (source.format === "odg" && targetFormat === "pdf") {
10807
+ const bytes = odgToPdf(source.bytes, {
10808
+ signal: options.signal,
10809
+ onSubstitution: (s, c) => diagnostics.push(substitutionDiagnostic(s, c))
10810
+ });
10811
+ return Promise.resolve({
10812
+ document: {
10813
+ format: "pdf",
10814
+ bytes
10815
+ },
10816
+ diagnostics
10817
+ });
10818
+ }
10056
10819
  if (source.format === "pdf" && targetFormat === "docx") {
10057
10820
  const bytes = pdfToDocx(source.bytes, {
10058
10821
  signal: options.signal,
@@ -10172,6 +10935,12 @@ Object.defineProperty(exports, "ContentCellValueSchema", {
10172
10935
  }
10173
10936
  });
10174
10937
  exports.ContentDocumentSchema = ContentDocumentSchema;
10938
+ Object.defineProperty(exports, "ContentDrawPageSchema", {
10939
+ enumerable: true,
10940
+ get: function() {
10941
+ return document_content_model.ContentDrawPageSchema;
10942
+ }
10943
+ });
10175
10944
  Object.defineProperty(exports, "ContentImageBlockSchema", {
10176
10945
  enumerable: true,
10177
10946
  get: function() {
@@ -10190,6 +10959,18 @@ Object.defineProperty(exports, "ContentParagraphSchema", {
10190
10959
  return document_content_model.ContentParagraphSchema;
10191
10960
  }
10192
10961
  });
10962
+ Object.defineProperty(exports, "ContentPathPointSchema", {
10963
+ enumerable: true,
10964
+ get: function() {
10965
+ return document_content_model.ContentPathPointSchema;
10966
+ }
10967
+ });
10968
+ Object.defineProperty(exports, "ContentPathSegmentSchema", {
10969
+ enumerable: true,
10970
+ get: function() {
10971
+ return document_content_model.ContentPathSegmentSchema;
10972
+ }
10973
+ });
10193
10974
  Object.defineProperty(exports, "ContentRunSchema", {
10194
10975
  enumerable: true,
10195
10976
  get: function() {
@@ -10256,6 +11037,18 @@ Object.defineProperty(exports, "ContentSlideSchema", {
10256
11037
  return document_content_model.ContentSlideSchema;
10257
11038
  }
10258
11039
  });
11040
+ Object.defineProperty(exports, "ContentStrokeSchema", {
11041
+ enumerable: true,
11042
+ get: function() {
11043
+ return document_content_model.ContentStrokeSchema;
11044
+ }
11045
+ });
11046
+ Object.defineProperty(exports, "ContentSubpathSchema", {
11047
+ enumerable: true,
11048
+ get: function() {
11049
+ return document_content_model.ContentSubpathSchema;
11050
+ }
11051
+ });
10259
11052
  Object.defineProperty(exports, "ContentTableCellSchema", {
10260
11053
  enumerable: true,
10261
11054
  get: function() {
@@ -10274,6 +11067,12 @@ Object.defineProperty(exports, "ContentTableSchema", {
10274
11067
  return document_content_model.ContentTableSchema;
10275
11068
  }
10276
11069
  });
11070
+ Object.defineProperty(exports, "ContentVectorSchema", {
11071
+ enumerable: true,
11072
+ get: function() {
11073
+ return document_content_model.ContentVectorSchema;
11074
+ }
11075
+ });
10277
11076
  Object.defineProperty(exports, "DEFAULT_LAYOUT_FONT", {
10278
11077
  enumerable: true,
10279
11078
  get: function() {
@@ -10300,7 +11099,12 @@ Object.defineProperty(exports, "LAYOUT_FORMAT_VERSION", {
10300
11099
  }
10301
11100
  });
10302
11101
  exports.NOOP_DIAGNOSTIC_SINK = NOOP_DIAGNOSTIC_SINK;
11102
+ exports.OdgBoxVector = OdgBoxVector;
10303
11103
  exports.OdgBytesSchema = OdgBytesSchema;
11104
+ exports.OdgEditor = OdgEditor;
11105
+ exports.OdgLineVector = OdgLineVector;
11106
+ exports.OdgPage = OdgPage;
11107
+ exports.OdgPathVector = OdgPathVector;
10304
11108
  exports.OdpBytesSchema = OdpBytesSchema;
10305
11109
  exports.OdpEditor = OdpEditor;
10306
11110
  exports.OdpShape = OdpShape;
@@ -10422,6 +11226,7 @@ Object.defineProperty(exports, "base64ToBytes", {
10422
11226
  }
10423
11227
  });
10424
11228
  exports.buildDocxPackage = buildDocxPackage;
11229
+ exports.buildOdgPackage = buildOdgPackage;
10425
11230
  exports.buildOdpPackage = buildOdpPackage;
10426
11231
  exports.buildOdsPackage = buildOdsPackage;
10427
11232
  exports.buildOdtPackage = buildOdtPackage;
@@ -10456,11 +11261,13 @@ Object.defineProperty(exports, "compactPackageCodec", {
10456
11261
  return ooxml_js.compactPackageCodec;
10457
11262
  }
10458
11263
  });
11264
+ exports.convertDrawingToLayout = convertDrawingToLayout;
10459
11265
  exports.convertPresentationToLayout = convertPresentationToLayout;
10460
11266
  exports.convertSpreadsheetToLayout = convertSpreadsheetToLayout;
10461
11267
  exports.convertWordprocessingToLayout = convertWordprocessingToLayout;
10462
11268
  exports.createDocx = createDocx;
10463
11269
  exports.createLocalDocumentConverter = createLocalDocumentConverter;
11270
+ exports.createOdg = createOdg;
10464
11271
  exports.createOdp = createOdp;
10465
11272
  exports.createOds = createOds;
10466
11273
  exports.createOdt = createOdt;
@@ -10529,12 +11336,14 @@ Object.defineProperty(exports, "isXmlNode", {
10529
11336
  return ooxml_js.isXmlNode;
10530
11337
  }
10531
11338
  });
11339
+ exports.odgToPdf = odgToPdf;
10532
11340
  exports.odpPdfCodec = odpPdfCodec;
10533
11341
  exports.odpToPdf = odpToPdf;
10534
11342
  exports.odsToPdf = odsToPdf;
10535
11343
  exports.odtPdfCodec = odtPdfCodec;
10536
11344
  exports.odtToPdf = odtToPdf;
10537
11345
  exports.openDocx = openDocx;
11346
+ exports.openOdg = openOdg;
10538
11347
  exports.openOdp = openOdp;
10539
11348
  exports.openOds = openOds;
10540
11349
  exports.openOdt = openOdt;
@@ -10565,6 +11374,7 @@ exports.pdfToPptx = pdfToPptx;
10565
11374
  exports.pptxPdfCodec = pptxPdfCodec;
10566
11375
  exports.pptxToPdf = pptxToPdf;
10567
11376
  exports.readDocxContent = readDocxContent;
11377
+ exports.readOdgContent = readOdgContent;
10568
11378
  exports.readOdpContent = readOdpContent;
10569
11379
  exports.readOdsContent = readOdsContent;
10570
11380
  exports.readOdtContent = readOdtContent;