documents.js 1.44.0 → 1.46.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
@@ -536,7 +536,7 @@ function needsSpacePreserve(text) {
536
536
  }
537
537
  //#endregion
538
538
  //#region src/edit/docx/run.ts
539
- function directChild$9(parent, tag) {
539
+ function directChild$10(parent, tag) {
540
540
  for (const child of parent.children) if (child.type === "element" && child.tag === tag) return child;
541
541
  }
542
542
  function appendUElement(rPr, value) {
@@ -545,7 +545,7 @@ function appendUElement(rPr, value) {
545
545
  return created;
546
546
  }
547
547
  function findOrCreateT(run) {
548
- const existing = directChild$9(run, "w:t");
548
+ const existing = directChild$10(run, "w:t");
549
549
  if (existing !== void 0) return existing;
550
550
  const created = el("w:t");
551
551
  run.children.push(created);
@@ -565,7 +565,7 @@ var DocxRun = class {
565
565
  }
566
566
  rPr(create) {
567
567
  const node = this.live();
568
- return create ? ensureFirstChild(node, "w:rPr") : directChild$9(node, "w:rPr");
568
+ return create ? ensureFirstChild(node, "w:rPr") : directChild$10(node, "w:rPr");
569
569
  }
570
570
  get text() {
571
571
  return (0, ooxml_js.textContent)(this.live());
@@ -589,14 +589,14 @@ var DocxRun = class {
589
589
  }
590
590
  get underline() {
591
591
  const rPr = this.rPr(false);
592
- 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");
593
593
  if (uElement === void 0) return false;
594
594
  for (const a of uElement.attributes) if (a.name === "w:val") return a.value !== "none";
595
595
  return true;
596
596
  }
597
597
  set underline(value) {
598
598
  const rPr = this.rPr(true);
599
- const existing = directChild$9(rPr, "w:u");
599
+ const existing = directChild$10(rPr, "w:u");
600
600
  if (existing === void 0) {
601
601
  appendUElement(rPr, value);
602
602
  return;
@@ -670,7 +670,7 @@ function buildRun$1(init = {}) {
670
670
  }
671
671
  //#endregion
672
672
  //#region src/edit/docx/paragraph.ts
673
- function directChild$8(parent, tag) {
673
+ function directChild$9(parent, tag) {
674
674
  for (const child of parent.children) if (child.type === "element" && child.tag === tag) return child;
675
675
  }
676
676
  var DocxParagraph = class {
@@ -689,7 +689,7 @@ var DocxParagraph = class {
689
689
  }
690
690
  pPr(create) {
691
691
  const node = this.live();
692
- return create ? ensureFirstChild(node, "w:pPr") : directChild$8(node, "w:pPr");
692
+ return create ? ensureFirstChild(node, "w:pPr") : directChild$9(node, "w:pPr");
693
693
  }
694
694
  get text() {
695
695
  return (0, ooxml_js.textContent)(this.live());
@@ -726,7 +726,7 @@ var DocxParagraph = class {
726
726
  set styleId(value) {
727
727
  if (value === void 0) {
728
728
  const pPr = this.pPr(false);
729
- 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");
730
730
  if (existing !== void 0 && pPr !== void 0) removeChild(pPr.children, existing);
731
731
  return;
732
732
  }
@@ -738,7 +738,7 @@ var DocxParagraph = class {
738
738
  set alignment(value) {
739
739
  if (value === void 0) {
740
740
  const pPr = this.pPr(false);
741
- 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");
742
742
  if (existing !== void 0 && pPr !== void 0) removeChild(pPr.children, existing);
743
743
  return;
744
744
  }
@@ -746,12 +746,12 @@ var DocxParagraph = class {
746
746
  }
747
747
  get list() {
748
748
  const pPr = this.pPr(false);
749
- 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");
750
750
  if (numPr === void 0) return;
751
- const numIdElement = directChild$8(numPr, "w:numId");
751
+ const numIdElement = directChild$9(numPr, "w:numId");
752
752
  const numId = numIdElement === void 0 ? void 0 : (0, ooxml_js.attr)(numIdElement, "w:val");
753
753
  if (numId === void 0) return;
754
- const ilvlElement = directChild$8(numPr, "w:ilvl");
754
+ const ilvlElement = directChild$9(numPr, "w:ilvl");
755
755
  const ilvl = ilvlElement === void 0 ? void 0 : (0, ooxml_js.attr)(ilvlElement, "w:val");
756
756
  return {
757
757
  numId,
@@ -761,7 +761,7 @@ var DocxParagraph = class {
761
761
  set list(value) {
762
762
  const pPr = this.pPr(true);
763
763
  if (value === void 0) {
764
- const existing = directChild$8(pPr, "w:numPr");
764
+ const existing = directChild$9(pPr, "w:numPr");
765
765
  if (existing !== void 0) removeChild(pPr.children, existing);
766
766
  return;
767
767
  }
@@ -795,7 +795,7 @@ function buildParagraph$1(init = {}) {
795
795
  const CONTENT_TYPES_NS$1 = "http://schemas.openxmlformats.org/package/2006/content-types";
796
796
  const RELS_NS$1 = "http://schemas.openxmlformats.org/package/2006/relationships";
797
797
  const WORDML_NS = "http://schemas.openxmlformats.org/wordprocessingml/2006/main";
798
- function declaration$4() {
798
+ function declaration$5() {
799
799
  return {
800
800
  type: "declaration",
801
801
  attributes: [
@@ -864,23 +864,23 @@ function createEmptyDocxPackage() {
864
864
  return { parts: {
865
865
  "[Content_Types].xml": {
866
866
  kind: "xml",
867
- nodes: [declaration$4(), contentTypes]
867
+ nodes: [declaration$5(), contentTypes]
868
868
  },
869
869
  "_rels/.rels": {
870
870
  kind: "xml",
871
- nodes: [declaration$4(), rootRels]
871
+ nodes: [declaration$5(), rootRels]
872
872
  },
873
873
  "word/document.xml": {
874
874
  kind: "xml",
875
- nodes: [declaration$4(), document]
875
+ nodes: [declaration$5(), document]
876
876
  },
877
877
  "word/_rels/document.xml.rels": {
878
878
  kind: "xml",
879
- nodes: [declaration$4(), documentRels]
879
+ nodes: [declaration$5(), documentRels]
880
880
  },
881
881
  "word/styles.xml": {
882
882
  kind: "xml",
883
- nodes: [declaration$4(), styles]
883
+ nodes: [declaration$5(), styles]
884
884
  }
885
885
  } };
886
886
  }
@@ -1171,7 +1171,7 @@ const SLIDE_LAYOUT_REL_TYPE = "http://schemas.openxmlformats.org/officeDocument/
1171
1171
  const THEME_REL_TYPE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme";
1172
1172
  const NOTES_MASTER_REL_TYPE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/notesMaster";
1173
1173
  const MIN_MASTER_OR_LAYOUT_ID = 2147483648;
1174
- function declaration$3() {
1174
+ function declaration$4() {
1175
1175
  return {
1176
1176
  type: "declaration",
1177
1177
  attributes: [
@@ -1321,7 +1321,7 @@ function ensureNotesMaster(pkg) {
1321
1321
  });
1322
1322
  pkg.parts[NOTES_MASTER_PART_PATH] = {
1323
1323
  kind: "xml",
1324
- nodes: [declaration$3(), buildNotesMaster()]
1324
+ nodes: [declaration$4(), buildNotesMaster()]
1325
1325
  };
1326
1326
  ensureContentTypeOverride(pkg, NOTES_MASTER_PART_PATH, NOTES_MASTER_CONTENT_TYPE);
1327
1327
  const presentationToNotesMasterTarget = buildRelativeTarget(PRESENTATION_PART_PATH$1, NOTES_MASTER_PART_PATH);
@@ -1360,15 +1360,15 @@ function createEmptyPptxPackage() {
1360
1360
  const pkg = { parts: {
1361
1361
  "[Content_Types].xml": {
1362
1362
  kind: "xml",
1363
- nodes: [declaration$3(), contentTypes]
1363
+ nodes: [declaration$4(), contentTypes]
1364
1364
  },
1365
1365
  "_rels/.rels": {
1366
1366
  kind: "xml",
1367
- nodes: [declaration$3(), rootRels]
1367
+ nodes: [declaration$4(), rootRels]
1368
1368
  },
1369
1369
  [PRESENTATION_PART_PATH$1]: {
1370
1370
  kind: "xml",
1371
- nodes: [declaration$3(), el("p:presentation", {
1371
+ nodes: [declaration$4(), el("p:presentation", {
1372
1372
  "xmlns:p": PML_NS,
1373
1373
  "xmlns:r": R_NS
1374
1374
  })]
@@ -1381,7 +1381,7 @@ function createEmptyPptxPackage() {
1381
1381
  });
1382
1382
  pkg.parts[SLIDE_LAYOUT_PART_PATH] = {
1383
1383
  kind: "xml",
1384
- nodes: [declaration$3(), buildSlideLayout()]
1384
+ nodes: [declaration$4(), buildSlideLayout()]
1385
1385
  };
1386
1386
  ensureContentTypeOverride(pkg, SLIDE_LAYOUT_PART_PATH, SLIDE_LAYOUT_CONTENT_TYPE);
1387
1387
  const masterToLayoutTarget = buildRelativeTarget(SLIDE_MASTER_PART_PATH, SLIDE_LAYOUT_PART_PATH);
@@ -1396,12 +1396,12 @@ function createEmptyPptxPackage() {
1396
1396
  });
1397
1397
  pkg.parts[SLIDE_MASTER_PART_PATH] = {
1398
1398
  kind: "xml",
1399
- nodes: [declaration$3(), buildSlideMaster(masterToLayoutRelId)]
1399
+ nodes: [declaration$4(), buildSlideMaster(masterToLayoutRelId)]
1400
1400
  };
1401
1401
  ensureContentTypeOverride(pkg, SLIDE_MASTER_PART_PATH, SLIDE_MASTER_CONTENT_TYPE);
1402
1402
  pkg.parts[THEME_PART_PATH] = {
1403
1403
  kind: "xml",
1404
- nodes: [declaration$3(), buildTheme()]
1404
+ nodes: [declaration$4(), buildTheme()]
1405
1405
  };
1406
1406
  ensureContentTypeOverride(pkg, THEME_PART_PATH, THEME_CONTENT_TYPE);
1407
1407
  const presentationToMasterTarget = buildRelativeTarget(PRESENTATION_PART_PATH$1, SLIDE_MASTER_PART_PATH);
@@ -1426,7 +1426,7 @@ function createEmptyPptxPackage() {
1426
1426
  }
1427
1427
  //#endregion
1428
1428
  //#region src/edit/pptx/shape.ts
1429
- function directChild$7(parent, tag) {
1429
+ function directChild$8(parent, tag) {
1430
1430
  for (const child of parent.children) if (child.type === "element" && child.tag === tag) return child;
1431
1431
  }
1432
1432
  function parseEmuAttr(element, name) {
@@ -1447,7 +1447,7 @@ var PptxShape = class {
1447
1447
  }
1448
1448
  spPrElement(create) {
1449
1449
  const node = this.live();
1450
- const existing = directChild$7(node, "p:spPr");
1450
+ const existing = directChild$8(node, "p:spPr");
1451
1451
  if (existing !== void 0 || !create) return existing;
1452
1452
  const created = el("p:spPr");
1453
1453
  node.children.push(created);
@@ -1455,10 +1455,10 @@ var PptxShape = class {
1455
1455
  }
1456
1456
  get frame() {
1457
1457
  const spPr = this.spPrElement(false);
1458
- 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");
1459
1459
  if (xfrm === void 0) return;
1460
- const off = directChild$7(xfrm, "a:off");
1461
- const ext = directChild$7(xfrm, "a:ext");
1460
+ const off = directChild$8(xfrm, "a:off");
1461
+ const ext = directChild$8(xfrm, "a:ext");
1462
1462
  if (off === void 0 || ext === void 0) return;
1463
1463
  const x = parseEmuAttr(off, "x");
1464
1464
  const y = parseEmuAttr(off, "y");
@@ -1474,7 +1474,7 @@ var PptxShape = class {
1474
1474
  }
1475
1475
  set frame(value) {
1476
1476
  const spPr = this.spPrElement(true);
1477
- let xfrm = directChild$7(spPr, "a:xfrm");
1477
+ let xfrm = directChild$8(spPr, "a:xfrm");
1478
1478
  if (xfrm === void 0) {
1479
1479
  xfrm = el("a:xfrm");
1480
1480
  spPr.children.unshift(xfrm);
@@ -1488,12 +1488,12 @@ var PptxShape = class {
1488
1488
  })];
1489
1489
  }
1490
1490
  get text() {
1491
- const txBody = directChild$7(this.live(), "p:txBody");
1491
+ const txBody = directChild$8(this.live(), "p:txBody");
1492
1492
  return txBody === void 0 ? "" : (0, ooxml_js.textContent)(txBody);
1493
1493
  }
1494
1494
  set text(value) {
1495
1495
  const node = this.live();
1496
- let txBody = directChild$7(node, "p:txBody");
1496
+ let txBody = directChild$8(node, "p:txBody");
1497
1497
  if (txBody === void 0) {
1498
1498
  txBody = el("p:txBody", {}, [el("a:bodyPr"), el("a:lstStyle")]);
1499
1499
  node.children.push(txBody);
@@ -1504,7 +1504,7 @@ var PptxShape = class {
1504
1504
  }
1505
1505
  setParagraphs(paragraphs) {
1506
1506
  const node = this.live();
1507
- let txBody = directChild$7(node, "p:txBody");
1507
+ let txBody = directChild$8(node, "p:txBody");
1508
1508
  if (txBody === void 0) {
1509
1509
  txBody = el("p:txBody", {}, [el("a:bodyPr"), el("a:lstStyle")]);
1510
1510
  node.children.push(txBody);
@@ -1615,12 +1615,12 @@ function insertPictureShapeMedia(context, slideRoot, frame, image) {
1615
1615
  }
1616
1616
  //#endregion
1617
1617
  //#region src/edit/pptx/slide.ts
1618
- function directChild$6(parent, tag) {
1618
+ function directChild$7(parent, tag) {
1619
1619
  for (const child of parent.children) if (child.type === "element" && child.tag === tag) return child;
1620
1620
  }
1621
1621
  function findSpTree(slideRoot) {
1622
- const cSld = directChild$6(slideRoot, "p:cSld");
1623
- 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");
1624
1624
  if (spTree === void 0) throw new Error("slide has no p:cSld/p:spTree element");
1625
1625
  return spTree;
1626
1626
  }
@@ -1752,7 +1752,7 @@ const PRESENTATION_PART_PATH = "ppt/presentation.xml";
1752
1752
  const MEDIA_DIR = "ppt/media";
1753
1753
  const SLIDE_CONTENT_TYPE = "application/vnd.openxmlformats-officedocument.presentationml.slide+xml";
1754
1754
  const SLIDE_RELATIONSHIP_TYPE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/slide";
1755
- function directChild$5(parent, tag) {
1755
+ function directChild$6(parent, tag) {
1756
1756
  for (const child of parent.children) if (child.type === "element" && child.tag === tag) return child;
1757
1757
  }
1758
1758
  function attrValue(element, name) {
@@ -1764,12 +1764,12 @@ function findPresentationRoot(pkg) {
1764
1764
  return root;
1765
1765
  }
1766
1766
  function findSldIdLst(presentationRoot) {
1767
- const sldIdLst = directChild$5(presentationRoot, "p:sldIdLst");
1767
+ const sldIdLst = directChild$6(presentationRoot, "p:sldIdLst");
1768
1768
  if (sldIdLst === void 0) throw new Error(`${PRESENTATION_PART_PATH} has no p:sldIdLst element`);
1769
1769
  return sldIdLst;
1770
1770
  }
1771
1771
  function findSldSz(presentationRoot) {
1772
- const sldSz = directChild$5(presentationRoot, "p:sldSz");
1772
+ const sldSz = directChild$6(presentationRoot, "p:sldSz");
1773
1773
  if (sldSz === void 0) throw new Error(`${PRESENTATION_PART_PATH} has no p:sldSz element`);
1774
1774
  return sldSz;
1775
1775
  }
@@ -1930,12 +1930,12 @@ function buildPptxPackage(content) {
1930
1930
  if (firstSlide !== void 0) editor.slideSize = firstSlide.size;
1931
1931
  for (const slide of content.slides) {
1932
1932
  const pptxSlide = editor.addSlide();
1933
- for (const shape of slide.shapes) appendShape$1(pptxSlide, shape);
1933
+ for (const shape of slide.shapes) appendShape$2(pptxSlide, shape);
1934
1934
  if (slide.notes.length > 0) pptxSlide.notes = slide.notes;
1935
1935
  }
1936
1936
  return editor.toPackage();
1937
1937
  }
1938
- function appendShape$1(slide, shape) {
1938
+ function appendShape$2(slide, shape) {
1939
1939
  const [onlyBlock] = shape.blocks;
1940
1940
  if (shape.blocks.length === 1 && onlyBlock?.kind === "image") {
1941
1941
  slide.addImage({
@@ -1968,12 +1968,12 @@ function appendShape$1(slide, shape) {
1968
1968
  }
1969
1969
  //#endregion
1970
1970
  //#region src/edit/odt/automatic-styles.ts
1971
- const CONTENT_PART_PATH$3 = "content.xml";
1971
+ const CONTENT_PART_PATH$4 = "content.xml";
1972
1972
  function ensureAutomaticStyles(pkg) {
1973
- const part = pkg.parts[CONTENT_PART_PATH$3];
1974
- 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`);
1975
1975
  const root = part.nodes.find((n) => n.type === "element");
1976
- 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`);
1977
1977
  for (const child of root.children) if (child.type === "element" && child.tag === "office:automatic-styles") return child;
1978
1978
  const created = el("office:automatic-styles");
1979
1979
  const insertBeforeTags = /* @__PURE__ */ new Set([
@@ -2067,7 +2067,7 @@ function applyStyleChange(pkg, element, family, change) {
2067
2067
  ...readCurrentStyleProperties(pkg, element, family),
2068
2068
  ...change
2069
2069
  };
2070
- 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({
2071
2071
  family,
2072
2072
  properties: merged
2073
2073
  });
@@ -2298,7 +2298,7 @@ function buildList(pkg) {
2298
2298
  }
2299
2299
  //#endregion
2300
2300
  //#region src/edit/odt/scaffold.ts
2301
- const CONTENT_NS_PREFIXES$2 = [
2301
+ const CONTENT_NS_PREFIXES$3 = [
2302
2302
  "office",
2303
2303
  "style",
2304
2304
  "text",
@@ -2308,7 +2308,7 @@ const CONTENT_NS_PREFIXES$2 = [
2308
2308
  "svg",
2309
2309
  "xlink"
2310
2310
  ];
2311
- const STYLES_NS_PREFIXES$2 = [
2311
+ const STYLES_NS_PREFIXES$3 = [
2312
2312
  "office",
2313
2313
  "style",
2314
2314
  "text",
@@ -2318,16 +2318,16 @@ const STYLES_NS_PREFIXES$2 = [
2318
2318
  "svg",
2319
2319
  "xlink"
2320
2320
  ];
2321
- const META_NS_PREFIXES$2 = [
2321
+ const META_NS_PREFIXES$3 = [
2322
2322
  "office",
2323
2323
  "meta",
2324
2324
  "dc"
2325
2325
  ];
2326
- const ODF_VERSION$2 = "1.3";
2327
- const PAGE_LAYOUT_NAME$2 = "PM1";
2328
- 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";
2329
2329
  const DEFAULT_MARGIN_PT = 72;
2330
- function declaration$2() {
2330
+ function declaration$3() {
2331
2331
  return {
2332
2332
  type: "declaration",
2333
2333
  attributes: [
@@ -2346,8 +2346,8 @@ function declaration$2() {
2346
2346
  ]
2347
2347
  };
2348
2348
  }
2349
- function buildPageLayout$2() {
2350
- 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", {
2351
2351
  "fo:page-width": `${document_content_model.PAGE_SIZE_LETTER.widthPt}pt`,
2352
2352
  "fo:page-height": `${document_content_model.PAGE_SIZE_LETTER.heightPt}pt`,
2353
2353
  "fo:margin-top": `${DEFAULT_MARGIN_PT}pt`,
@@ -2356,44 +2356,44 @@ function buildPageLayout$2() {
2356
2356
  "fo:margin-left": `${DEFAULT_MARGIN_PT}pt`
2357
2357
  })]);
2358
2358
  }
2359
- function buildStylesXml$2() {
2359
+ function buildStylesXml$3() {
2360
2360
  return el("office:document-styles", {
2361
- ...(0, odf_js.xmlnsAttributes)([...STYLES_NS_PREFIXES$2]),
2362
- "office:version": ODF_VERSION$2
2361
+ ...(0, odf_js.xmlnsAttributes)([...STYLES_NS_PREFIXES$3]),
2362
+ "office:version": ODF_VERSION$3
2363
2363
  }, [
2364
2364
  el("office:styles"),
2365
- el("office:automatic-styles", {}, [buildPageLayout$2()]),
2365
+ el("office:automatic-styles", {}, [buildPageLayout$3()]),
2366
2366
  el("office:master-styles", {}, [el("style:master-page", {
2367
- "style:name": MASTER_PAGE_NAME$2,
2368
- "style:page-layout-name": PAGE_LAYOUT_NAME$2
2367
+ "style:name": MASTER_PAGE_NAME$3,
2368
+ "style:page-layout-name": PAGE_LAYOUT_NAME$3
2369
2369
  })])
2370
2370
  ]);
2371
2371
  }
2372
- function buildContentXml$2() {
2372
+ function buildContentXml$3() {
2373
2373
  return el("office:document-content", {
2374
- ...(0, odf_js.xmlnsAttributes)([...CONTENT_NS_PREFIXES$2]),
2375
- "office:version": ODF_VERSION$2
2374
+ ...(0, odf_js.xmlnsAttributes)([...CONTENT_NS_PREFIXES$3]),
2375
+ "office:version": ODF_VERSION$3
2376
2376
  }, [el("office:automatic-styles"), el("office:body", {}, [el("office:text")])]);
2377
2377
  }
2378
- function buildMetaXml$2() {
2378
+ function buildMetaXml$3() {
2379
2379
  return el("office:document-meta", {
2380
- ...(0, odf_js.xmlnsAttributes)([...META_NS_PREFIXES$2]),
2381
- "office:version": ODF_VERSION$2
2380
+ ...(0, odf_js.xmlnsAttributes)([...META_NS_PREFIXES$3]),
2381
+ "office:version": ODF_VERSION$3
2382
2382
  }, [el("office:meta")]);
2383
2383
  }
2384
2384
  function createEmptyOdtPackage() {
2385
2385
  const pkg = { parts: {
2386
2386
  "content.xml": {
2387
2387
  kind: "xml",
2388
- nodes: [declaration$2(), buildContentXml$2()]
2388
+ nodes: [declaration$3(), buildContentXml$3()]
2389
2389
  },
2390
2390
  "styles.xml": {
2391
2391
  kind: "xml",
2392
- nodes: [declaration$2(), buildStylesXml$2()]
2392
+ nodes: [declaration$3(), buildStylesXml$3()]
2393
2393
  },
2394
2394
  "meta.xml": {
2395
2395
  kind: "xml",
2396
- nodes: [declaration$2(), buildMetaXml$2()]
2396
+ nodes: [declaration$3(), buildMetaXml$3()]
2397
2397
  }
2398
2398
  } };
2399
2399
  (0, odf_js.setDocumentMediaType)(pkg, odf_js.ODF_MEDIA_TYPES.odt);
@@ -2514,20 +2514,20 @@ function buildTable(pkg, init) {
2514
2514
  }
2515
2515
  //#endregion
2516
2516
  //#region src/edit/odt/editor.ts
2517
- const CONTENT_PART_PATH$2 = "content.xml";
2517
+ const CONTENT_PART_PATH$3 = "content.xml";
2518
2518
  function findContentRoot(pkg) {
2519
- const part = pkg.parts[CONTENT_PART_PATH$2];
2519
+ const part = pkg.parts[CONTENT_PART_PATH$3];
2520
2520
  const root = part?.kind === "xml" ? part.nodes.find((n) => n.type === "element") : void 0;
2521
- 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}`);
2522
2522
  return root;
2523
2523
  }
2524
- function directChild$4(parent, tag) {
2524
+ function directChild$5(parent, tag) {
2525
2525
  for (const child of parent.children) if (child.type === "element" && child.tag === tag) return child;
2526
2526
  }
2527
2527
  function findOfficeText(contentRoot) {
2528
- const body = directChild$4(contentRoot, "office:body");
2529
- const text = body === void 0 ? void 0 : directChild$4(body, "office:text");
2530
- 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`);
2531
2531
  return text;
2532
2532
  }
2533
2533
  var OdtBodyImpl = class {
@@ -2659,7 +2659,7 @@ function appendBlock(body, block) {
2659
2659
  }
2660
2660
  //#endregion
2661
2661
  //#region src/edit/odp/scaffold.ts
2662
- const CONTENT_NS_PREFIXES$1 = [
2662
+ const CONTENT_NS_PREFIXES$2 = [
2663
2663
  "office",
2664
2664
  "style",
2665
2665
  "text",
@@ -2670,7 +2670,7 @@ const CONTENT_NS_PREFIXES$1 = [
2670
2670
  "svg",
2671
2671
  "xlink"
2672
2672
  ];
2673
- const STYLES_NS_PREFIXES$1 = [
2673
+ const STYLES_NS_PREFIXES$2 = [
2674
2674
  "office",
2675
2675
  "style",
2676
2676
  "text",
@@ -2681,14 +2681,14 @@ const STYLES_NS_PREFIXES$1 = [
2681
2681
  "svg",
2682
2682
  "xlink"
2683
2683
  ];
2684
- const META_NS_PREFIXES$1 = [
2684
+ const META_NS_PREFIXES$2 = [
2685
2685
  "office",
2686
2686
  "meta",
2687
2687
  "dc"
2688
2688
  ];
2689
- const ODF_VERSION$1 = "1.3";
2690
- const MASTER_PAGE_NAME$1 = "Standard";
2691
- function declaration$1() {
2689
+ const ODF_VERSION$2 = "1.3";
2690
+ const MASTER_PAGE_NAME$2 = "Standard";
2691
+ function declaration$2() {
2692
2692
  return {
2693
2693
  type: "declaration",
2694
2694
  attributes: [
@@ -2707,50 +2707,50 @@ function declaration$1() {
2707
2707
  ]
2708
2708
  };
2709
2709
  }
2710
- function buildPageLayout$1() {
2710
+ function buildPageLayout$2() {
2711
2711
  return el("style:page-layout", { "style:name": "PM1" }, [el("style:page-layout-properties", {
2712
2712
  "fo:page-width": `${document_content_model.SLIDE_SIZE_WIDESCREEN.widthPt}pt`,
2713
2713
  "fo:page-height": `${document_content_model.SLIDE_SIZE_WIDESCREEN.heightPt}pt`
2714
2714
  })]);
2715
2715
  }
2716
- function buildStylesXml$1() {
2716
+ function buildStylesXml$2() {
2717
2717
  return el("office:document-styles", {
2718
- ...(0, odf_js.xmlnsAttributes)([...STYLES_NS_PREFIXES$1]),
2719
- "office:version": ODF_VERSION$1
2718
+ ...(0, odf_js.xmlnsAttributes)([...STYLES_NS_PREFIXES$2]),
2719
+ "office:version": ODF_VERSION$2
2720
2720
  }, [
2721
2721
  el("office:styles"),
2722
- el("office:automatic-styles", {}, [buildPageLayout$1()]),
2722
+ el("office:automatic-styles", {}, [buildPageLayout$2()]),
2723
2723
  el("office:master-styles", {}, [el("style:master-page", {
2724
- "style:name": MASTER_PAGE_NAME$1,
2724
+ "style:name": MASTER_PAGE_NAME$2,
2725
2725
  "style:page-layout-name": "PM1"
2726
2726
  })])
2727
2727
  ]);
2728
2728
  }
2729
- function buildContentXml$1() {
2729
+ function buildContentXml$2() {
2730
2730
  return el("office:document-content", {
2731
- ...(0, odf_js.xmlnsAttributes)([...CONTENT_NS_PREFIXES$1]),
2732
- "office:version": ODF_VERSION$1
2731
+ ...(0, odf_js.xmlnsAttributes)([...CONTENT_NS_PREFIXES$2]),
2732
+ "office:version": ODF_VERSION$2
2733
2733
  }, [el("office:automatic-styles"), el("office:body", {}, [el("office:presentation")])]);
2734
2734
  }
2735
- function buildMetaXml$1() {
2735
+ function buildMetaXml$2() {
2736
2736
  return el("office:document-meta", {
2737
- ...(0, odf_js.xmlnsAttributes)([...META_NS_PREFIXES$1]),
2738
- "office:version": ODF_VERSION$1
2737
+ ...(0, odf_js.xmlnsAttributes)([...META_NS_PREFIXES$2]),
2738
+ "office:version": ODF_VERSION$2
2739
2739
  }, [el("office:meta")]);
2740
2740
  }
2741
2741
  function createEmptyOdpPackage() {
2742
2742
  const pkg = { parts: {
2743
2743
  "content.xml": {
2744
2744
  kind: "xml",
2745
- nodes: [declaration$1(), buildContentXml$1()]
2745
+ nodes: [declaration$2(), buildContentXml$2()]
2746
2746
  },
2747
2747
  "styles.xml": {
2748
2748
  kind: "xml",
2749
- nodes: [declaration$1(), buildStylesXml$1()]
2749
+ nodes: [declaration$2(), buildStylesXml$2()]
2750
2750
  },
2751
2751
  "meta.xml": {
2752
2752
  kind: "xml",
2753
- nodes: [declaration$1(), buildMetaXml$1()]
2753
+ nodes: [declaration$2(), buildMetaXml$2()]
2754
2754
  }
2755
2755
  } };
2756
2756
  (0, odf_js.setDocumentMediaType)(pkg, odf_js.ODF_MEDIA_TYPES.odp);
@@ -2790,7 +2790,7 @@ function addImageMedia(pkg, imageBytes, format) {
2790
2790
  }
2791
2791
  //#endregion
2792
2792
  //#region src/edit/odp/shape.ts
2793
- function directChild$3(parent, tag) {
2793
+ function directChild$4(parent, tag) {
2794
2794
  for (const child of parent.children) if (child.type === "element" && child.tag === tag) return child;
2795
2795
  }
2796
2796
  function buildTransformAttr(frame, rotationDeg) {
@@ -2858,7 +2858,7 @@ var OdpShape = class {
2858
2858
  }
2859
2859
  textBox(create) {
2860
2860
  const node = this.live();
2861
- const existing = directChild$3(node, "draw:text-box");
2861
+ const existing = directChild$4(node, "draw:text-box");
2862
2862
  if (existing !== void 0 || !create) return existing;
2863
2863
  const created = el("draw:text-box");
2864
2864
  node.children.push(created);
@@ -2919,7 +2919,7 @@ function insertImageFrameMedia(context, frame, image) {
2919
2919
  }
2920
2920
  //#endregion
2921
2921
  //#region src/edit/odp/slide.ts
2922
- function directChild$2(parent, tag) {
2922
+ function directChild$3(parent, tag) {
2923
2923
  for (const child of parent.children) if (child.type === "element" && child.tag === tag) return child;
2924
2924
  }
2925
2925
  const NOTES_FRAME_X_PT = 20;
@@ -2968,13 +2968,13 @@ var OdpSlide = class {
2968
2968
  return new OdpShape(node.children, frameElement, this.context.pkg);
2969
2969
  }
2970
2970
  get notes() {
2971
- const notesElement = directChild$2(this.live(), "presentation:notes");
2971
+ const notesElement = directChild$3(this.live(), "presentation:notes");
2972
2972
  if (notesElement === void 0) return "";
2973
2973
  return (0, ooxml_js.elementsWithTag)(notesElement.children, "text:p").map((p) => decodeOdfText(p.children)).join("\n");
2974
2974
  }
2975
2975
  set notes(value) {
2976
2976
  const node = this.live();
2977
- const existing = directChild$2(node, "presentation:notes");
2977
+ const existing = directChild$3(node, "presentation:notes");
2978
2978
  const notesElement = buildNotesElement(this.context.pkg, value);
2979
2979
  if (existing === void 0) node.children.push(notesElement);
2980
2980
  else existing.children = notesElement.children;
@@ -2986,27 +2986,27 @@ var OdpSlide = class {
2986
2986
  };
2987
2987
  //#endregion
2988
2988
  //#region src/edit/odp/editor.ts
2989
- const CONTENT_PART_PATH$1 = "content.xml";
2990
- const STYLES_PART_PATH = "styles.xml";
2991
- 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) {
2992
2992
  for (const child of parent.children) if (child.type === "element" && child.tag === tag) return child;
2993
2993
  }
2994
- function findRoot$1(pkg, partPath) {
2994
+ function findRoot$2(pkg, partPath) {
2995
2995
  const part = pkg.parts[partPath];
2996
2996
  const root = part?.kind === "xml" ? part.nodes.find((n) => n.type === "element") : void 0;
2997
2997
  if (root === void 0) throw new Error(`package has no root element at ${partPath}`);
2998
2998
  return root;
2999
2999
  }
3000
3000
  function findOfficePresentation(pkg) {
3001
- const body = directChild$1(findRoot$1(pkg, CONTENT_PART_PATH$1), "office:body");
3002
- const presentation = body === void 0 ? void 0 : directChild$1(body, "office:presentation");
3003
- 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`);
3004
3004
  return presentation;
3005
3005
  }
3006
- function findPageLayoutProperties(pkg) {
3007
- 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");
3008
- const properties = pageLayout === void 0 ? void 0 : directChild$1(pageLayout, "style:page-layout-properties");
3009
- 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`);
3010
3010
  return properties;
3011
3011
  }
3012
3012
  var OdpEditor = class {
@@ -3025,7 +3025,7 @@ var OdpEditor = class {
3025
3025
  }
3026
3026
  addSlide() {
3027
3027
  const presentation = findOfficePresentation(this.pkg);
3028
- 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 });
3029
3029
  presentation.children.push(pageElement);
3030
3030
  const context = { pkg: this.pkg };
3031
3031
  return new OdpSlide(presentation.children, pageElement, context);
@@ -3055,7 +3055,7 @@ var OdpEditor = class {
3055
3055
  presentation.children.splice(insertAt, 0, moved);
3056
3056
  }
3057
3057
  get slideSize() {
3058
- const properties = findPageLayoutProperties(this.pkg);
3058
+ const properties = findPageLayoutProperties$1(this.pkg);
3059
3059
  const widthValue = (0, ooxml_js.attr)(properties, "fo:page-width");
3060
3060
  const heightValue = (0, ooxml_js.attr)(properties, "fo:page-height");
3061
3061
  const widthPt = widthValue === void 0 ? void 0 : (0, odf_js.parseOdfLength)(widthValue);
@@ -3066,7 +3066,7 @@ var OdpEditor = class {
3066
3066
  };
3067
3067
  }
3068
3068
  set slideSize(size) {
3069
- const properties = findPageLayoutProperties(this.pkg);
3069
+ const properties = findPageLayoutProperties$1(this.pkg);
3070
3070
  properties.attributes = [{
3071
3071
  name: "fo:page-width",
3072
3072
  value: (0, odf_js.formatOdfLength)(size.widthPt)
@@ -3097,12 +3097,12 @@ function buildOdpPackage(content) {
3097
3097
  if (firstSlide !== void 0) editor.slideSize = firstSlide.size;
3098
3098
  for (const slide of content.slides) {
3099
3099
  const odpSlide = editor.addSlide();
3100
- for (const shape of slide.shapes) appendShape(odpSlide, shape);
3100
+ for (const shape of slide.shapes) appendShape$1(odpSlide, shape);
3101
3101
  if (slide.notes.length > 0) odpSlide.notes = slide.notes;
3102
3102
  }
3103
3103
  return editor.toPackage();
3104
3104
  }
3105
- function appendShape(slide, shape) {
3105
+ function appendShape$1(slide, shape) {
3106
3106
  const [onlyBlock] = shape.blocks;
3107
3107
  if (shape.blocks.length === 1 && onlyBlock?.kind === "image") {
3108
3108
  const imageShape = slide.addImage({
@@ -3127,31 +3127,31 @@ function appendShape(slide, shape) {
3127
3127
  }
3128
3128
  //#endregion
3129
3129
  //#region src/edit/ods/scaffold.ts
3130
- const CONTENT_NS_PREFIXES = [
3130
+ const CONTENT_NS_PREFIXES$1 = [
3131
3131
  "office",
3132
3132
  "style",
3133
3133
  "text",
3134
3134
  "table",
3135
3135
  "fo"
3136
3136
  ];
3137
- const STYLES_NS_PREFIXES = [
3137
+ const STYLES_NS_PREFIXES$1 = [
3138
3138
  "office",
3139
3139
  "style",
3140
3140
  "table",
3141
3141
  "fo"
3142
3142
  ];
3143
- const META_NS_PREFIXES = [
3143
+ const META_NS_PREFIXES$1 = [
3144
3144
  "office",
3145
3145
  "meta",
3146
3146
  "dc"
3147
3147
  ];
3148
3148
  const OF_NAMESPACE_ATTR = { "xmlns:of": "urn:oasis:names:tc:opendocument:xmlns:of:1.2" };
3149
- const ODF_VERSION = "1.3";
3150
- const MASTER_PAGE_NAME = "Standard";
3149
+ const ODF_VERSION$1 = "1.3";
3150
+ const MASTER_PAGE_NAME$1 = "Standard";
3151
3151
  const SHEET_TABLE_STYLE_NAME = "OdsTable";
3152
3152
  const DEFAULT_SHEET_NAME = "Sheet1";
3153
3153
  const DEFAULT_MARGIN = "2cm";
3154
- function declaration() {
3154
+ function declaration$1() {
3155
3155
  return {
3156
3156
  type: "declaration",
3157
3157
  attributes: [
@@ -3170,7 +3170,7 @@ function declaration() {
3170
3170
  ]
3171
3171
  };
3172
3172
  }
3173
- function buildPageLayout() {
3173
+ function buildPageLayout$1() {
3174
3174
  return el("style:page-layout", { "style:name": "PM1" }, [el("style:page-layout-properties", {
3175
3175
  "fo:page-width": `${document_content_model.PAGE_SIZE_A4.widthPt}pt`,
3176
3176
  "fo:page-height": `${document_content_model.PAGE_SIZE_A4.heightPt}pt`,
@@ -3180,15 +3180,15 @@ function buildPageLayout() {
3180
3180
  "fo:margin-left": DEFAULT_MARGIN
3181
3181
  })]);
3182
3182
  }
3183
- function buildStylesXml() {
3183
+ function buildStylesXml$1() {
3184
3184
  return el("office:document-styles", {
3185
- ...(0, odf_js.xmlnsAttributes)([...STYLES_NS_PREFIXES]),
3186
- "office:version": ODF_VERSION
3185
+ ...(0, odf_js.xmlnsAttributes)([...STYLES_NS_PREFIXES$1]),
3186
+ "office:version": ODF_VERSION$1
3187
3187
  }, [
3188
3188
  el("office:styles"),
3189
- el("office:automatic-styles", {}, [buildPageLayout()]),
3189
+ el("office:automatic-styles", {}, [buildPageLayout$1()]),
3190
3190
  el("office:master-styles", {}, [el("style:master-page", {
3191
- "style:name": MASTER_PAGE_NAME,
3191
+ "style:name": MASTER_PAGE_NAME$1,
3192
3192
  "style:page-layout-name": "PM1"
3193
3193
  })])
3194
3194
  ]);
@@ -3197,7 +3197,7 @@ function buildSheetTableStyle() {
3197
3197
  return el("style:style", {
3198
3198
  "style:name": SHEET_TABLE_STYLE_NAME,
3199
3199
  "style:family": "table",
3200
- "style:master-page-name": MASTER_PAGE_NAME
3200
+ "style:master-page-name": MASTER_PAGE_NAME$1
3201
3201
  });
3202
3202
  }
3203
3203
  function buildCalculationSettings() {
@@ -3208,36 +3208,36 @@ function buildCalculationSettings() {
3208
3208
  "table:null-year": "1950"
3209
3209
  });
3210
3210
  }
3211
- function buildContentXml() {
3211
+ function buildContentXml$1() {
3212
3212
  const table = el("table:table", {
3213
3213
  "table:name": DEFAULT_SHEET_NAME,
3214
3214
  "table:style-name": SHEET_TABLE_STYLE_NAME
3215
3215
  });
3216
3216
  return el("office:document-content", {
3217
- ...(0, odf_js.xmlnsAttributes)([...CONTENT_NS_PREFIXES]),
3217
+ ...(0, odf_js.xmlnsAttributes)([...CONTENT_NS_PREFIXES$1]),
3218
3218
  ...OF_NAMESPACE_ATTR,
3219
- "office:version": ODF_VERSION
3219
+ "office:version": ODF_VERSION$1
3220
3220
  }, [el("office:automatic-styles", {}, [buildSheetTableStyle()]), el("office:body", {}, [el("office:spreadsheet", {}, [buildCalculationSettings(), table])])]);
3221
3221
  }
3222
- function buildMetaXml() {
3222
+ function buildMetaXml$1() {
3223
3223
  return el("office:document-meta", {
3224
- ...(0, odf_js.xmlnsAttributes)([...META_NS_PREFIXES]),
3225
- "office:version": ODF_VERSION
3224
+ ...(0, odf_js.xmlnsAttributes)([...META_NS_PREFIXES$1]),
3225
+ "office:version": ODF_VERSION$1
3226
3226
  }, [el("office:meta")]);
3227
3227
  }
3228
3228
  function createEmptyOdsPackage() {
3229
3229
  const pkg = { parts: {
3230
3230
  "content.xml": {
3231
3231
  kind: "xml",
3232
- nodes: [declaration(), buildContentXml()]
3232
+ nodes: [declaration$1(), buildContentXml$1()]
3233
3233
  },
3234
3234
  "styles.xml": {
3235
3235
  kind: "xml",
3236
- nodes: [declaration(), buildStylesXml()]
3236
+ nodes: [declaration$1(), buildStylesXml$1()]
3237
3237
  },
3238
3238
  "meta.xml": {
3239
3239
  kind: "xml",
3240
- nodes: [declaration(), buildMetaXml()]
3240
+ nodes: [declaration$1(), buildMetaXml$1()]
3241
3241
  }
3242
3242
  } };
3243
3243
  (0, odf_js.setDocumentMediaType)(pkg, odf_js.ODF_MEDIA_TYPES.ods);
@@ -3495,68 +3495,608 @@ var OdsCell = class {
3495
3495
  get displayText() {
3496
3496
  return this.node.children.filter((child) => child.type === "element" && child.tag === "text:p").map((paragraph) => decodeOdfText(paragraph.children)).join("\n");
3497
3497
  }
3498
- set displayText(value) {
3499
- this.node.children = [el("text:p", {}, encodeOdfText(value))];
3498
+ set displayText(value) {
3499
+ this.node.children = [el("text:p", {}, encodeOdfText(value))];
3500
+ }
3501
+ setStyledRuns(runs) {
3502
+ const textParagraph = el("text:p");
3503
+ this.node.children = [textParagraph];
3504
+ populateParagraph(new OdtParagraph(this.node.children, textParagraph, this.pkg), {
3505
+ kind: "paragraph",
3506
+ runs: [...runs]
3507
+ });
3508
+ }
3509
+ };
3510
+ //#endregion
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);
3500
4037
  }
3501
- setStyledRuns(runs) {
3502
- const textParagraph = el("text:p");
3503
- this.node.children = [textParagraph];
3504
- populateParagraph(new OdtParagraph(this.node.children, textParagraph, this.pkg), {
3505
- kind: "paragraph",
3506
- runs: [...runs]
3507
- });
4038
+ remove() {
4039
+ removeChild(this.container, this.live());
4040
+ this.removed = true;
3508
4041
  }
3509
4042
  };
3510
4043
  //#endregion
3511
- //#region src/edit/ods/sheet.ts
3512
- const NAME_ATTR = "table:name";
3513
- var OdsSheet = class {
4044
+ //#region src/edit/odg/page.ts
4045
+ var OdgPage = class {
3514
4046
  container;
3515
4047
  node;
3516
- pkg;
4048
+ context;
3517
4049
  removed = false;
3518
- constructor(container, node, pkg) {
4050
+ constructor(container, node, context) {
3519
4051
  this.container = container;
3520
4052
  this.node = node;
3521
- this.pkg = pkg;
4053
+ this.context = context;
3522
4054
  }
3523
4055
  live() {
3524
- 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");
3525
4057
  return this.node;
3526
4058
  }
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;
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;
3531
4064
  }
3532
- set name(value) {
3533
- 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);
3534
4070
  }
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);
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);
3539
4076
  }
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);
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);
3544
4082
  }
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);
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);
3560
4100
  }
3561
4101
  remove() {
3562
4102
  removeChild(this.container, this.live());
@@ -3564,64 +4104,78 @@ var OdsSheet = class {
3564
4104
  }
3565
4105
  };
3566
4106
  //#endregion
3567
- //#region src/edit/ods/editor.ts
4107
+ //#region src/edit/odg/editor.ts
3568
4108
  const CONTENT_PART_PATH = "content.xml";
4109
+ const STYLES_PART_PATH = "styles.xml";
3569
4110
  function directChild(parent, tag) {
3570
4111
  for (const child of parent.children) if (child.type === "element" && child.tag === tag) return child;
3571
4112
  }
3572
- function findRoot(pkg) {
3573
- const part = pkg.parts[CONTENT_PART_PATH];
4113
+ function findRoot(pkg, partPath) {
4114
+ const part = pkg.parts[partPath];
3574
4115
  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}`);
4116
+ if (root === void 0) throw new Error(`package has no root element at ${partPath}`);
3576
4117
  return root;
3577
4118
  }
3578
- function findOfficeSpreadsheet(pkg) {
3579
- const body = directChild(findRoot(pkg), "office:body");
3580
- const spreadsheet = body === void 0 ? void 0 : directChild(body, "office:spreadsheet");
3581
- if (spreadsheet === void 0) throw new Error(`${CONTENT_PART_PATH} has no office:body/office:spreadsheet element`);
3582
- 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;
3583
4124
  }
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
3591
- }));
3592
- 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;
3593
4130
  }
3594
- var OdsEditor = class {
4131
+ var OdgEditor = class {
3595
4132
  pkg;
3596
4133
  constructor(pkg) {
3597
4134
  this.pkg = pkg;
3598
4135
  }
3599
- sheets() {
3600
- const spreadsheet = findOfficeSpreadsheet(this.pkg);
4136
+ pages() {
4137
+ const drawing = findOfficeDrawing(this.pkg);
3601
4138
  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));
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
+ }
3603
4143
  return out;
3604
4144
  }
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;
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);
3609
4151
  }
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);
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);
3618
4158
  }
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);
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
+ }];
3625
4179
  }
3626
4180
  toPackage() {
3627
4181
  return this.pkg;
@@ -3630,33 +4184,71 @@ var OdsEditor = class {
3630
4184
  return (0, odf_js.encodePackage)(this.pkg);
3631
4185
  }
3632
4186
  };
3633
- function openOds(bytes) {
3634
- return new OdsEditor((0, odf_js.decodePackage)(bytes));
4187
+ function openOdg(bytes) {
4188
+ return new OdgEditor((0, odf_js.decodePackage)(bytes));
3635
4189
  }
3636
- function createOds() {
3637
- return new OdsEditor(createEmptyOdsPackage());
4190
+ function createOdg() {
4191
+ return new OdgEditor(createEmptyOdgPackage());
3638
4192
  }
3639
4193
  //#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);
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);
3648
4204
  }
3649
4205
  return editor.toPackage();
3650
4206
  }
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);
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
+ }
3660
4252
  }
3661
4253
  //#endregion
3662
4254
  //#region src/bytes/crc32.ts
@@ -6952,6 +7544,7 @@ function readInlineImage(reader, sink) {
6952
7544
  //#region src/pdf/interpret.ts
6953
7545
  const MAX_FORM_XOBJECT_DEPTH = 12;
6954
7546
  const FALLBACK_GLYPH_WIDTH_PER_1000 = 500;
7547
+ const DEFAULT_LINE_WIDTH_PT = 1;
6955
7548
  function defaultTextState() {
6956
7549
  return {
6957
7550
  tm: IDENTITY_MATRIX,
@@ -7044,16 +7637,118 @@ function interpretContentStream(bytes, resources, context) {
7044
7637
  runContentStream(bytes, resources, {
7045
7638
  ctm: IDENTITY_MATRIX,
7046
7639
  fillColor: document_content_model.COLOR_BLACK,
7047
- strokeColor: document_content_model.COLOR_BLACK
7640
+ strokeColor: document_content_model.COLOR_BLACK,
7641
+ lineWidth: DEFAULT_LINE_WIDTH_PT
7048
7642
  }, context, items, 0);
7049
7643
  return items;
7050
7644
  }
7645
+ function lastPointOf(subpath) {
7646
+ const last = subpath.segments[subpath.segments.length - 1];
7647
+ return last === void 0 ? {
7648
+ x: subpath.startXPt,
7649
+ y: subpath.startYPt
7650
+ } : {
7651
+ x: last.xPt,
7652
+ y: last.yPt
7653
+ };
7654
+ }
7051
7655
  function runContentStream(bytes, resources, initialState, context, items, depth) {
7052
7656
  const operations = readContentStream(bytes, context.sink);
7053
7657
  const gsStack = [];
7054
7658
  let gs = initialState;
7055
7659
  let ts = defaultTextState();
7056
7660
  let pendingRect;
7661
+ let pathSubpaths = [];
7662
+ let currentSubpath;
7663
+ const finalizeCurrentSubpath = () => {
7664
+ if (currentSubpath !== void 0) {
7665
+ pathSubpaths.push(currentSubpath);
7666
+ currentSubpath = void 0;
7667
+ }
7668
+ };
7669
+ const resetPath = () => {
7670
+ pendingRect = void 0;
7671
+ pathSubpaths = [];
7672
+ currentSubpath = void 0;
7673
+ };
7674
+ const appendRectSubpath = (operands, ctm) => {
7675
+ finalizeCurrentSubpath();
7676
+ const x = numAt(operands, 0);
7677
+ const y = numAt(operands, 1);
7678
+ const w = numAt(operands, 2);
7679
+ const h = numAt(operands, 3);
7680
+ const p1 = applyMatrix(ctm, {
7681
+ x,
7682
+ y
7683
+ });
7684
+ const p2 = applyMatrix(ctm, {
7685
+ x: x + w,
7686
+ y
7687
+ });
7688
+ const p3 = applyMatrix(ctm, {
7689
+ x: x + w,
7690
+ y: y + h
7691
+ });
7692
+ const p4 = applyMatrix(ctm, {
7693
+ x,
7694
+ y: y + h
7695
+ });
7696
+ pathSubpaths.push({
7697
+ startXPt: p1.x,
7698
+ startYPt: p1.y,
7699
+ segments: [
7700
+ {
7701
+ kind: "line",
7702
+ xPt: p2.x,
7703
+ yPt: p2.y
7704
+ },
7705
+ {
7706
+ kind: "line",
7707
+ xPt: p3.x,
7708
+ yPt: p3.y
7709
+ },
7710
+ {
7711
+ kind: "line",
7712
+ xPt: p4.x,
7713
+ yPt: p4.y
7714
+ }
7715
+ ],
7716
+ closed: true
7717
+ });
7718
+ };
7719
+ const paintFillRuleFor = (operator) => operator.endsWith("*") ? "evenodd" : "nonzero";
7720
+ const emitPaint = (operator) => {
7721
+ if (operator === "n") {
7722
+ resetPath();
7723
+ return;
7724
+ }
7725
+ if ((operator === "s" || operator === "b" || operator === "b*") && currentSubpath !== void 0) currentSubpath.closed = true;
7726
+ if ((operator === "f" || operator === "F" || operator === "f*") && currentSubpath === void 0 && pathSubpaths.length === 1 && pendingRect !== void 0) {
7727
+ items.push({
7728
+ kind: "rect",
7729
+ ...pendingRect,
7730
+ color: gs.fillColor
7731
+ });
7732
+ resetPath();
7733
+ return;
7734
+ }
7735
+ finalizeCurrentSubpath();
7736
+ if (pathSubpaths.length > 0) {
7737
+ const isFillOp = operator === "f" || operator === "F" || operator === "f*" || operator === "B" || operator === "B*" || operator === "b" || operator === "b*";
7738
+ const isStrokeOp = operator === "S" || operator === "s" || operator === "B" || operator === "B*" || operator === "b" || operator === "b*";
7739
+ items.push({
7740
+ kind: "path",
7741
+ subpaths: pathSubpaths,
7742
+ fillRule: paintFillRuleFor(operator),
7743
+ fill: isFillOp ? gs.fillColor : void 0,
7744
+ stroke: isStrokeOp ? {
7745
+ color: gs.strokeColor,
7746
+ widthPt: gs.lineWidth
7747
+ } : void 0
7748
+ });
7749
+ }
7750
+ resetPath();
7751
+ };
7057
7752
  const advanceThroughString = (codes) => {
7058
7753
  if (ts.fontResourceName === void 0) return;
7059
7754
  let offset = 0;
@@ -7237,25 +7932,118 @@ function runContentStream(bytes, resources, initialState, context, items, depth)
7237
7932
  }
7238
7933
  case "re":
7239
7934
  pendingRect = rectFromOperands(operands, gs.ctm);
7935
+ appendRectSubpath(operands, gs.ctm);
7936
+ break;
7937
+ case "m": {
7938
+ finalizeCurrentSubpath();
7939
+ const p = applyMatrix(gs.ctm, {
7940
+ x: numAt(operands, 0),
7941
+ y: numAt(operands, 1)
7942
+ });
7943
+ currentSubpath = {
7944
+ startXPt: p.x,
7945
+ startYPt: p.y,
7946
+ segments: [],
7947
+ closed: false
7948
+ };
7949
+ pendingRect = void 0;
7950
+ break;
7951
+ }
7952
+ case "l": {
7953
+ const p = applyMatrix(gs.ctm, {
7954
+ x: numAt(operands, 0),
7955
+ y: numAt(operands, 1)
7956
+ });
7957
+ currentSubpath?.segments.push({
7958
+ kind: "line",
7959
+ xPt: p.x,
7960
+ yPt: p.y
7961
+ });
7962
+ pendingRect = void 0;
7963
+ break;
7964
+ }
7965
+ case "c": {
7966
+ const c1 = applyMatrix(gs.ctm, {
7967
+ x: numAt(operands, 0),
7968
+ y: numAt(operands, 1)
7969
+ });
7970
+ const c2 = applyMatrix(gs.ctm, {
7971
+ x: numAt(operands, 2),
7972
+ y: numAt(operands, 3)
7973
+ });
7974
+ const p = applyMatrix(gs.ctm, {
7975
+ x: numAt(operands, 4),
7976
+ y: numAt(operands, 5)
7977
+ });
7978
+ currentSubpath?.segments.push({
7979
+ kind: "cubic",
7980
+ c1xPt: c1.x,
7981
+ c1yPt: c1.y,
7982
+ c2xPt: c2.x,
7983
+ c2yPt: c2.y,
7984
+ xPt: p.x,
7985
+ yPt: p.y
7986
+ });
7987
+ pendingRect = void 0;
7240
7988
  break;
7241
- case "m":
7242
- case "l":
7243
- case "c":
7989
+ }
7244
7990
  case "v":
7245
- case "y":
7991
+ if (currentSubpath !== void 0) {
7992
+ const cur = lastPointOf(currentSubpath);
7993
+ const c2 = applyMatrix(gs.ctm, {
7994
+ x: numAt(operands, 0),
7995
+ y: numAt(operands, 1)
7996
+ });
7997
+ const p = applyMatrix(gs.ctm, {
7998
+ x: numAt(operands, 2),
7999
+ y: numAt(operands, 3)
8000
+ });
8001
+ currentSubpath.segments.push({
8002
+ kind: "cubic",
8003
+ c1xPt: cur.x,
8004
+ c1yPt: cur.y,
8005
+ c2xPt: c2.x,
8006
+ c2yPt: c2.y,
8007
+ xPt: p.x,
8008
+ yPt: p.y
8009
+ });
8010
+ }
8011
+ pendingRect = void 0;
8012
+ break;
8013
+ case "y": {
8014
+ const c1 = applyMatrix(gs.ctm, {
8015
+ x: numAt(operands, 0),
8016
+ y: numAt(operands, 1)
8017
+ });
8018
+ const p = applyMatrix(gs.ctm, {
8019
+ x: numAt(operands, 2),
8020
+ y: numAt(operands, 3)
8021
+ });
8022
+ currentSubpath?.segments.push({
8023
+ kind: "cubic",
8024
+ c1xPt: c1.x,
8025
+ c1yPt: c1.y,
8026
+ c2xPt: p.x,
8027
+ c2yPt: p.y,
8028
+ xPt: p.x,
8029
+ yPt: p.y
8030
+ });
8031
+ pendingRect = void 0;
8032
+ break;
8033
+ }
7246
8034
  case "h":
8035
+ if (currentSubpath !== void 0) currentSubpath.closed = true;
7247
8036
  pendingRect = void 0;
7248
8037
  break;
8038
+ case "w":
8039
+ gs = {
8040
+ ...gs,
8041
+ lineWidth: numAt(operands, 0)
8042
+ };
8043
+ break;
7249
8044
  case "f":
7250
8045
  case "F":
7251
8046
  case "f*":
7252
- if (pendingRect !== void 0) items.push({
7253
- kind: "rect",
7254
- ...pendingRect,
7255
- color: gs.fillColor
7256
- });
7257
- pendingRect = void 0;
7258
- break;
7259
8047
  case "S":
7260
8048
  case "s":
7261
8049
  case "B":
@@ -7263,7 +8051,7 @@ function runContentStream(bytes, resources, initialState, context, items, depth)
7263
8051
  case "b":
7264
8052
  case "b*":
7265
8053
  case "n":
7266
- pendingRect = void 0;
8054
+ emitPaint(operator);
7267
8055
  break;
7268
8056
  case "BT":
7269
8057
  ts = defaultTextState();
@@ -8245,6 +9033,7 @@ function readPage(page, resolver, fontResolver, images, imageIdCache, sink) {
8245
9033
  function convertExtractedItem(item, pageMatrix, fontResolver, images, imageIdCache, resolver, sink) {
8246
9034
  if (item.kind === "text") return convertText(item, pageMatrix, fontResolver);
8247
9035
  if (item.kind === "rect") return convertRect(item, pageMatrix);
9036
+ if (item.kind === "path") return convertPath(item, pageMatrix);
8248
9037
  if (item.kind === "image") return convertImage(item, pageMatrix, images, imageIdCache, resolver, sink);
8249
9038
  return convertInlineImage(item, pageMatrix, images, resolver, sink);
8250
9039
  }
@@ -8292,6 +9081,61 @@ function convertRect(item, pageMatrix) {
8292
9081
  fill: item.color
8293
9082
  };
8294
9083
  }
9084
+ function transformSubpath(subpath, pageMatrix) {
9085
+ const start = applyMatrix(pageMatrix, {
9086
+ x: subpath.startXPt,
9087
+ y: subpath.startYPt
9088
+ });
9089
+ const segments = subpath.segments.map((segment) => {
9090
+ if (segment.kind === "line") {
9091
+ const p = applyMatrix(pageMatrix, {
9092
+ x: segment.xPt,
9093
+ y: segment.yPt
9094
+ });
9095
+ return {
9096
+ kind: "line",
9097
+ xPt: p.x,
9098
+ yPt: p.y
9099
+ };
9100
+ }
9101
+ const c1 = applyMatrix(pageMatrix, {
9102
+ x: segment.c1xPt,
9103
+ y: segment.c1yPt
9104
+ });
9105
+ const c2 = applyMatrix(pageMatrix, {
9106
+ x: segment.c2xPt,
9107
+ y: segment.c2yPt
9108
+ });
9109
+ const p = applyMatrix(pageMatrix, {
9110
+ x: segment.xPt,
9111
+ y: segment.yPt
9112
+ });
9113
+ return {
9114
+ kind: "cubic",
9115
+ c1xPt: c1.x,
9116
+ c1yPt: c1.y,
9117
+ c2xPt: c2.x,
9118
+ c2yPt: c2.y,
9119
+ xPt: p.x,
9120
+ yPt: p.y
9121
+ };
9122
+ });
9123
+ return {
9124
+ startXPt: start.x,
9125
+ startYPt: start.y,
9126
+ segments,
9127
+ closed: subpath.closed
9128
+ };
9129
+ }
9130
+ function convertPath(item, pageMatrix) {
9131
+ return {
9132
+ kind: "path",
9133
+ subpaths: item.subpaths.map((subpath) => transformSubpath(subpath, pageMatrix)),
9134
+ ...item.fill !== void 0 ? { fill: item.fill } : {},
9135
+ ...item.fill !== void 0 && item.fillRule === "evenodd" ? { fillRule: "evenodd" } : {},
9136
+ ...item.stroke !== void 0 ? { stroke: item.stroke } : {}
9137
+ };
9138
+ }
8295
9139
  function imagePlacementFrom(matrix) {
8296
9140
  const rotationDeg = matrixRotationDegrees(matrix);
8297
9141
  return {
@@ -10507,7 +11351,12 @@ Object.defineProperty(exports, "LAYOUT_FORMAT_VERSION", {
10507
11351
  }
10508
11352
  });
10509
11353
  exports.NOOP_DIAGNOSTIC_SINK = NOOP_DIAGNOSTIC_SINK;
11354
+ exports.OdgBoxVector = OdgBoxVector;
10510
11355
  exports.OdgBytesSchema = OdgBytesSchema;
11356
+ exports.OdgEditor = OdgEditor;
11357
+ exports.OdgLineVector = OdgLineVector;
11358
+ exports.OdgPage = OdgPage;
11359
+ exports.OdgPathVector = OdgPathVector;
10511
11360
  exports.OdpBytesSchema = OdpBytesSchema;
10512
11361
  exports.OdpEditor = OdpEditor;
10513
11362
  exports.OdpShape = OdpShape;
@@ -10629,6 +11478,7 @@ Object.defineProperty(exports, "base64ToBytes", {
10629
11478
  }
10630
11479
  });
10631
11480
  exports.buildDocxPackage = buildDocxPackage;
11481
+ exports.buildOdgPackage = buildOdgPackage;
10632
11482
  exports.buildOdpPackage = buildOdpPackage;
10633
11483
  exports.buildOdsPackage = buildOdsPackage;
10634
11484
  exports.buildOdtPackage = buildOdtPackage;
@@ -10669,6 +11519,7 @@ exports.convertSpreadsheetToLayout = convertSpreadsheetToLayout;
10669
11519
  exports.convertWordprocessingToLayout = convertWordprocessingToLayout;
10670
11520
  exports.createDocx = createDocx;
10671
11521
  exports.createLocalDocumentConverter = createLocalDocumentConverter;
11522
+ exports.createOdg = createOdg;
10672
11523
  exports.createOdp = createOdp;
10673
11524
  exports.createOds = createOds;
10674
11525
  exports.createOdt = createOdt;
@@ -10744,6 +11595,7 @@ exports.odsToPdf = odsToPdf;
10744
11595
  exports.odtPdfCodec = odtPdfCodec;
10745
11596
  exports.odtToPdf = odtToPdf;
10746
11597
  exports.openDocx = openDocx;
11598
+ exports.openOdg = openOdg;
10747
11599
  exports.openOdp = openOdp;
10748
11600
  exports.openOds = openOds;
10749
11601
  exports.openOdt = openOdt;