documents.js 1.42.0 → 1.43.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
@@ -530,7 +530,7 @@ function needsSpacePreserve(text) {
530
530
  }
531
531
  //#endregion
532
532
  //#region src/edit/docx/run.ts
533
- function directChild$8(parent, tag) {
533
+ function directChild$9(parent, tag) {
534
534
  for (const child of parent.children) if (child.type === "element" && child.tag === tag) return child;
535
535
  }
536
536
  function appendUElement(rPr, value) {
@@ -539,7 +539,7 @@ function appendUElement(rPr, value) {
539
539
  return created;
540
540
  }
541
541
  function findOrCreateT(run) {
542
- const existing = directChild$8(run, "w:t");
542
+ const existing = directChild$9(run, "w:t");
543
543
  if (existing !== void 0) return existing;
544
544
  const created = el("w:t");
545
545
  run.children.push(created);
@@ -559,7 +559,7 @@ var DocxRun = class {
559
559
  }
560
560
  rPr(create) {
561
561
  const node = this.live();
562
- return create ? ensureFirstChild(node, "w:rPr") : directChild$8(node, "w:rPr");
562
+ return create ? ensureFirstChild(node, "w:rPr") : directChild$9(node, "w:rPr");
563
563
  }
564
564
  get text() {
565
565
  return (0, ooxml_js.textContent)(this.live());
@@ -583,14 +583,14 @@ var DocxRun = class {
583
583
  }
584
584
  get underline() {
585
585
  const rPr = this.rPr(false);
586
- const uElement = rPr === void 0 ? void 0 : directChild$8(rPr, "w:u");
586
+ const uElement = rPr === void 0 ? void 0 : directChild$9(rPr, "w:u");
587
587
  if (uElement === void 0) return false;
588
588
  for (const a of uElement.attributes) if (a.name === "w:val") return a.value !== "none";
589
589
  return true;
590
590
  }
591
591
  set underline(value) {
592
592
  const rPr = this.rPr(true);
593
- const existing = directChild$8(rPr, "w:u");
593
+ const existing = directChild$9(rPr, "w:u");
594
594
  if (existing === void 0) {
595
595
  appendUElement(rPr, value);
596
596
  return;
@@ -664,7 +664,7 @@ function buildRun$1(init = {}) {
664
664
  }
665
665
  //#endregion
666
666
  //#region src/edit/docx/paragraph.ts
667
- function directChild$7(parent, tag) {
667
+ function directChild$8(parent, tag) {
668
668
  for (const child of parent.children) if (child.type === "element" && child.tag === tag) return child;
669
669
  }
670
670
  var DocxParagraph = class {
@@ -683,7 +683,7 @@ var DocxParagraph = class {
683
683
  }
684
684
  pPr(create) {
685
685
  const node = this.live();
686
- return create ? ensureFirstChild(node, "w:pPr") : directChild$7(node, "w:pPr");
686
+ return create ? ensureFirstChild(node, "w:pPr") : directChild$8(node, "w:pPr");
687
687
  }
688
688
  get text() {
689
689
  return (0, ooxml_js.textContent)(this.live());
@@ -720,7 +720,7 @@ var DocxParagraph = class {
720
720
  set styleId(value) {
721
721
  if (value === void 0) {
722
722
  const pPr = this.pPr(false);
723
- const existing = pPr === void 0 ? void 0 : directChild$7(pPr, "w:pStyle");
723
+ const existing = pPr === void 0 ? void 0 : directChild$8(pPr, "w:pStyle");
724
724
  if (existing !== void 0 && pPr !== void 0) removeChild(pPr.children, existing);
725
725
  return;
726
726
  }
@@ -732,7 +732,7 @@ var DocxParagraph = class {
732
732
  set alignment(value) {
733
733
  if (value === void 0) {
734
734
  const pPr = this.pPr(false);
735
- const existing = pPr === void 0 ? void 0 : directChild$7(pPr, "w:jc");
735
+ const existing = pPr === void 0 ? void 0 : directChild$8(pPr, "w:jc");
736
736
  if (existing !== void 0 && pPr !== void 0) removeChild(pPr.children, existing);
737
737
  return;
738
738
  }
@@ -740,12 +740,12 @@ var DocxParagraph = class {
740
740
  }
741
741
  get list() {
742
742
  const pPr = this.pPr(false);
743
- const numPr = pPr === void 0 ? void 0 : directChild$7(pPr, "w:numPr");
743
+ const numPr = pPr === void 0 ? void 0 : directChild$8(pPr, "w:numPr");
744
744
  if (numPr === void 0) return;
745
- const numIdElement = directChild$7(numPr, "w:numId");
745
+ const numIdElement = directChild$8(numPr, "w:numId");
746
746
  const numId = numIdElement === void 0 ? void 0 : (0, ooxml_js.attr)(numIdElement, "w:val");
747
747
  if (numId === void 0) return;
748
- const ilvlElement = directChild$7(numPr, "w:ilvl");
748
+ const ilvlElement = directChild$8(numPr, "w:ilvl");
749
749
  const ilvl = ilvlElement === void 0 ? void 0 : (0, ooxml_js.attr)(ilvlElement, "w:val");
750
750
  return {
751
751
  numId,
@@ -755,7 +755,7 @@ var DocxParagraph = class {
755
755
  set list(value) {
756
756
  const pPr = this.pPr(true);
757
757
  if (value === void 0) {
758
- const existing = directChild$7(pPr, "w:numPr");
758
+ const existing = directChild$8(pPr, "w:numPr");
759
759
  if (existing !== void 0) removeChild(pPr.children, existing);
760
760
  return;
761
761
  }
@@ -789,7 +789,7 @@ function buildParagraph$1(init = {}) {
789
789
  const CONTENT_TYPES_NS$1 = "http://schemas.openxmlformats.org/package/2006/content-types";
790
790
  const RELS_NS$1 = "http://schemas.openxmlformats.org/package/2006/relationships";
791
791
  const WORDML_NS = "http://schemas.openxmlformats.org/wordprocessingml/2006/main";
792
- function declaration$3() {
792
+ function declaration$4() {
793
793
  return {
794
794
  type: "declaration",
795
795
  attributes: [
@@ -858,23 +858,23 @@ function createEmptyDocxPackage() {
858
858
  return { parts: {
859
859
  "[Content_Types].xml": {
860
860
  kind: "xml",
861
- nodes: [declaration$3(), contentTypes]
861
+ nodes: [declaration$4(), contentTypes]
862
862
  },
863
863
  "_rels/.rels": {
864
864
  kind: "xml",
865
- nodes: [declaration$3(), rootRels]
865
+ nodes: [declaration$4(), rootRels]
866
866
  },
867
867
  "word/document.xml": {
868
868
  kind: "xml",
869
- nodes: [declaration$3(), document]
869
+ nodes: [declaration$4(), document]
870
870
  },
871
871
  "word/_rels/document.xml.rels": {
872
872
  kind: "xml",
873
- nodes: [declaration$3(), documentRels]
873
+ nodes: [declaration$4(), documentRels]
874
874
  },
875
875
  "word/styles.xml": {
876
876
  kind: "xml",
877
- nodes: [declaration$3(), styles]
877
+ nodes: [declaration$4(), styles]
878
878
  }
879
879
  } };
880
880
  }
@@ -1165,7 +1165,7 @@ const SLIDE_LAYOUT_REL_TYPE = "http://schemas.openxmlformats.org/officeDocument/
1165
1165
  const THEME_REL_TYPE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme";
1166
1166
  const NOTES_MASTER_REL_TYPE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/notesMaster";
1167
1167
  const MIN_MASTER_OR_LAYOUT_ID = 2147483648;
1168
- function declaration$2() {
1168
+ function declaration$3() {
1169
1169
  return {
1170
1170
  type: "declaration",
1171
1171
  attributes: [
@@ -1315,7 +1315,7 @@ function ensureNotesMaster(pkg) {
1315
1315
  });
1316
1316
  pkg.parts[NOTES_MASTER_PART_PATH] = {
1317
1317
  kind: "xml",
1318
- nodes: [declaration$2(), buildNotesMaster()]
1318
+ nodes: [declaration$3(), buildNotesMaster()]
1319
1319
  };
1320
1320
  ensureContentTypeOverride(pkg, NOTES_MASTER_PART_PATH, NOTES_MASTER_CONTENT_TYPE);
1321
1321
  const presentationToNotesMasterTarget = buildRelativeTarget(PRESENTATION_PART_PATH$1, NOTES_MASTER_PART_PATH);
@@ -1354,15 +1354,15 @@ function createEmptyPptxPackage() {
1354
1354
  const pkg = { parts: {
1355
1355
  "[Content_Types].xml": {
1356
1356
  kind: "xml",
1357
- nodes: [declaration$2(), contentTypes]
1357
+ nodes: [declaration$3(), contentTypes]
1358
1358
  },
1359
1359
  "_rels/.rels": {
1360
1360
  kind: "xml",
1361
- nodes: [declaration$2(), rootRels]
1361
+ nodes: [declaration$3(), rootRels]
1362
1362
  },
1363
1363
  [PRESENTATION_PART_PATH$1]: {
1364
1364
  kind: "xml",
1365
- nodes: [declaration$2(), el("p:presentation", {
1365
+ nodes: [declaration$3(), el("p:presentation", {
1366
1366
  "xmlns:p": PML_NS,
1367
1367
  "xmlns:r": R_NS
1368
1368
  })]
@@ -1375,7 +1375,7 @@ function createEmptyPptxPackage() {
1375
1375
  });
1376
1376
  pkg.parts[SLIDE_LAYOUT_PART_PATH] = {
1377
1377
  kind: "xml",
1378
- nodes: [declaration$2(), buildSlideLayout()]
1378
+ nodes: [declaration$3(), buildSlideLayout()]
1379
1379
  };
1380
1380
  ensureContentTypeOverride(pkg, SLIDE_LAYOUT_PART_PATH, SLIDE_LAYOUT_CONTENT_TYPE);
1381
1381
  const masterToLayoutTarget = buildRelativeTarget(SLIDE_MASTER_PART_PATH, SLIDE_LAYOUT_PART_PATH);
@@ -1390,12 +1390,12 @@ function createEmptyPptxPackage() {
1390
1390
  });
1391
1391
  pkg.parts[SLIDE_MASTER_PART_PATH] = {
1392
1392
  kind: "xml",
1393
- nodes: [declaration$2(), buildSlideMaster(masterToLayoutRelId)]
1393
+ nodes: [declaration$3(), buildSlideMaster(masterToLayoutRelId)]
1394
1394
  };
1395
1395
  ensureContentTypeOverride(pkg, SLIDE_MASTER_PART_PATH, SLIDE_MASTER_CONTENT_TYPE);
1396
1396
  pkg.parts[THEME_PART_PATH] = {
1397
1397
  kind: "xml",
1398
- nodes: [declaration$2(), buildTheme()]
1398
+ nodes: [declaration$3(), buildTheme()]
1399
1399
  };
1400
1400
  ensureContentTypeOverride(pkg, THEME_PART_PATH, THEME_CONTENT_TYPE);
1401
1401
  const presentationToMasterTarget = buildRelativeTarget(PRESENTATION_PART_PATH$1, SLIDE_MASTER_PART_PATH);
@@ -1420,7 +1420,7 @@ function createEmptyPptxPackage() {
1420
1420
  }
1421
1421
  //#endregion
1422
1422
  //#region src/edit/pptx/shape.ts
1423
- function directChild$6(parent, tag) {
1423
+ function directChild$7(parent, tag) {
1424
1424
  for (const child of parent.children) if (child.type === "element" && child.tag === tag) return child;
1425
1425
  }
1426
1426
  function parseEmuAttr(element, name) {
@@ -1441,7 +1441,7 @@ var PptxShape = class {
1441
1441
  }
1442
1442
  spPrElement(create) {
1443
1443
  const node = this.live();
1444
- const existing = directChild$6(node, "p:spPr");
1444
+ const existing = directChild$7(node, "p:spPr");
1445
1445
  if (existing !== void 0 || !create) return existing;
1446
1446
  const created = el("p:spPr");
1447
1447
  node.children.push(created);
@@ -1449,10 +1449,10 @@ var PptxShape = class {
1449
1449
  }
1450
1450
  get frame() {
1451
1451
  const spPr = this.spPrElement(false);
1452
- const xfrm = spPr === void 0 ? void 0 : directChild$6(spPr, "a:xfrm");
1452
+ const xfrm = spPr === void 0 ? void 0 : directChild$7(spPr, "a:xfrm");
1453
1453
  if (xfrm === void 0) return;
1454
- const off = directChild$6(xfrm, "a:off");
1455
- const ext = directChild$6(xfrm, "a:ext");
1454
+ const off = directChild$7(xfrm, "a:off");
1455
+ const ext = directChild$7(xfrm, "a:ext");
1456
1456
  if (off === void 0 || ext === void 0) return;
1457
1457
  const x = parseEmuAttr(off, "x");
1458
1458
  const y = parseEmuAttr(off, "y");
@@ -1468,7 +1468,7 @@ var PptxShape = class {
1468
1468
  }
1469
1469
  set frame(value) {
1470
1470
  const spPr = this.spPrElement(true);
1471
- let xfrm = directChild$6(spPr, "a:xfrm");
1471
+ let xfrm = directChild$7(spPr, "a:xfrm");
1472
1472
  if (xfrm === void 0) {
1473
1473
  xfrm = el("a:xfrm");
1474
1474
  spPr.children.unshift(xfrm);
@@ -1482,12 +1482,12 @@ var PptxShape = class {
1482
1482
  })];
1483
1483
  }
1484
1484
  get text() {
1485
- const txBody = directChild$6(this.live(), "p:txBody");
1485
+ const txBody = directChild$7(this.live(), "p:txBody");
1486
1486
  return txBody === void 0 ? "" : (0, ooxml_js.textContent)(txBody);
1487
1487
  }
1488
1488
  set text(value) {
1489
1489
  const node = this.live();
1490
- let txBody = directChild$6(node, "p:txBody");
1490
+ let txBody = directChild$7(node, "p:txBody");
1491
1491
  if (txBody === void 0) {
1492
1492
  txBody = el("p:txBody", {}, [el("a:bodyPr"), el("a:lstStyle")]);
1493
1493
  node.children.push(txBody);
@@ -1498,7 +1498,7 @@ var PptxShape = class {
1498
1498
  }
1499
1499
  setParagraphs(paragraphs) {
1500
1500
  const node = this.live();
1501
- let txBody = directChild$6(node, "p:txBody");
1501
+ let txBody = directChild$7(node, "p:txBody");
1502
1502
  if (txBody === void 0) {
1503
1503
  txBody = el("p:txBody", {}, [el("a:bodyPr"), el("a:lstStyle")]);
1504
1504
  node.children.push(txBody);
@@ -1609,12 +1609,12 @@ function insertPictureShapeMedia(context, slideRoot, frame, image) {
1609
1609
  }
1610
1610
  //#endregion
1611
1611
  //#region src/edit/pptx/slide.ts
1612
- function directChild$5(parent, tag) {
1612
+ function directChild$6(parent, tag) {
1613
1613
  for (const child of parent.children) if (child.type === "element" && child.tag === tag) return child;
1614
1614
  }
1615
1615
  function findSpTree(slideRoot) {
1616
- const cSld = directChild$5(slideRoot, "p:cSld");
1617
- const spTree = cSld === void 0 ? void 0 : directChild$5(cSld, "p:spTree");
1616
+ const cSld = directChild$6(slideRoot, "p:cSld");
1617
+ const spTree = cSld === void 0 ? void 0 : directChild$6(cSld, "p:spTree");
1618
1618
  if (spTree === void 0) throw new Error("slide has no p:cSld/p:spTree element");
1619
1619
  return spTree;
1620
1620
  }
@@ -1746,7 +1746,7 @@ const PRESENTATION_PART_PATH = "ppt/presentation.xml";
1746
1746
  const MEDIA_DIR = "ppt/media";
1747
1747
  const SLIDE_CONTENT_TYPE = "application/vnd.openxmlformats-officedocument.presentationml.slide+xml";
1748
1748
  const SLIDE_RELATIONSHIP_TYPE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/slide";
1749
- function directChild$4(parent, tag) {
1749
+ function directChild$5(parent, tag) {
1750
1750
  for (const child of parent.children) if (child.type === "element" && child.tag === tag) return child;
1751
1751
  }
1752
1752
  function attrValue(element, name) {
@@ -1758,12 +1758,12 @@ function findPresentationRoot(pkg) {
1758
1758
  return root;
1759
1759
  }
1760
1760
  function findSldIdLst(presentationRoot) {
1761
- const sldIdLst = directChild$4(presentationRoot, "p:sldIdLst");
1761
+ const sldIdLst = directChild$5(presentationRoot, "p:sldIdLst");
1762
1762
  if (sldIdLst === void 0) throw new Error(`${PRESENTATION_PART_PATH} has no p:sldIdLst element`);
1763
1763
  return sldIdLst;
1764
1764
  }
1765
1765
  function findSldSz(presentationRoot) {
1766
- const sldSz = directChild$4(presentationRoot, "p:sldSz");
1766
+ const sldSz = directChild$5(presentationRoot, "p:sldSz");
1767
1767
  if (sldSz === void 0) throw new Error(`${PRESENTATION_PART_PATH} has no p:sldSz element`);
1768
1768
  return sldSz;
1769
1769
  }
@@ -1962,12 +1962,12 @@ function appendShape$1(slide, shape) {
1962
1962
  }
1963
1963
  //#endregion
1964
1964
  //#region src/edit/odt/automatic-styles.ts
1965
- const CONTENT_PART_PATH$2 = "content.xml";
1965
+ const CONTENT_PART_PATH$3 = "content.xml";
1966
1966
  function ensureAutomaticStyles(pkg) {
1967
- const part = pkg.parts[CONTENT_PART_PATH$2];
1968
- if (part?.kind !== "xml") throw new Error(`ensureAutomaticStyles: package has no ${CONTENT_PART_PATH$2} part`);
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`);
1969
1969
  const root = part.nodes.find((n) => n.type === "element");
1970
- if (root === void 0) throw new Error(`ensureAutomaticStyles: ${CONTENT_PART_PATH$2} has no root element`);
1970
+ if (root === void 0) throw new Error(`ensureAutomaticStyles: ${CONTENT_PART_PATH$3} has no root element`);
1971
1971
  for (const child of root.children) if (child.type === "element" && child.tag === "office:automatic-styles") return child;
1972
1972
  const created = el("office:automatic-styles");
1973
1973
  const insertBeforeTags = /* @__PURE__ */ new Set([
@@ -2061,7 +2061,7 @@ function applyStyleChange(pkg, element, family, change) {
2061
2061
  ...readCurrentStyleProperties(pkg, element, family),
2062
2062
  ...change
2063
2063
  };
2064
- const name = odf_js.StyleRegistry.forPart(pkg, CONTENT_PART_PATH$2).intern({
2064
+ const name = odf_js.StyleRegistry.forPart(pkg, CONTENT_PART_PATH$3).intern({
2065
2065
  family,
2066
2066
  properties: merged
2067
2067
  });
@@ -2292,7 +2292,7 @@ function buildList(pkg) {
2292
2292
  }
2293
2293
  //#endregion
2294
2294
  //#region src/edit/odt/scaffold.ts
2295
- const CONTENT_NS_PREFIXES$1 = [
2295
+ const CONTENT_NS_PREFIXES$2 = [
2296
2296
  "office",
2297
2297
  "style",
2298
2298
  "text",
@@ -2302,7 +2302,7 @@ const CONTENT_NS_PREFIXES$1 = [
2302
2302
  "svg",
2303
2303
  "xlink"
2304
2304
  ];
2305
- const STYLES_NS_PREFIXES$1 = [
2305
+ const STYLES_NS_PREFIXES$2 = [
2306
2306
  "office",
2307
2307
  "style",
2308
2308
  "text",
@@ -2312,16 +2312,16 @@ const STYLES_NS_PREFIXES$1 = [
2312
2312
  "svg",
2313
2313
  "xlink"
2314
2314
  ];
2315
- const META_NS_PREFIXES$1 = [
2315
+ const META_NS_PREFIXES$2 = [
2316
2316
  "office",
2317
2317
  "meta",
2318
2318
  "dc"
2319
2319
  ];
2320
- const ODF_VERSION$1 = "1.3";
2321
- const PAGE_LAYOUT_NAME$1 = "PM1";
2322
- const MASTER_PAGE_NAME$1 = "Standard";
2320
+ const ODF_VERSION$2 = "1.3";
2321
+ const PAGE_LAYOUT_NAME$2 = "PM1";
2322
+ const MASTER_PAGE_NAME$2 = "Standard";
2323
2323
  const DEFAULT_MARGIN_PT = 72;
2324
- function declaration$1() {
2324
+ function declaration$2() {
2325
2325
  return {
2326
2326
  type: "declaration",
2327
2327
  attributes: [
@@ -2340,8 +2340,8 @@ function declaration$1() {
2340
2340
  ]
2341
2341
  };
2342
2342
  }
2343
- function buildPageLayout$1() {
2344
- return el("style:page-layout", { "style:name": PAGE_LAYOUT_NAME$1 }, [el("style:page-layout-properties", {
2343
+ function buildPageLayout$2() {
2344
+ return el("style:page-layout", { "style:name": PAGE_LAYOUT_NAME$2 }, [el("style:page-layout-properties", {
2345
2345
  "fo:page-width": `${document_content_model.PAGE_SIZE_LETTER.widthPt}pt`,
2346
2346
  "fo:page-height": `${document_content_model.PAGE_SIZE_LETTER.heightPt}pt`,
2347
2347
  "fo:margin-top": `${DEFAULT_MARGIN_PT}pt`,
@@ -2350,44 +2350,44 @@ function buildPageLayout$1() {
2350
2350
  "fo:margin-left": `${DEFAULT_MARGIN_PT}pt`
2351
2351
  })]);
2352
2352
  }
2353
- function buildStylesXml$1() {
2353
+ function buildStylesXml$2() {
2354
2354
  return el("office:document-styles", {
2355
- ...(0, odf_js.xmlnsAttributes)([...STYLES_NS_PREFIXES$1]),
2356
- "office:version": ODF_VERSION$1
2355
+ ...(0, odf_js.xmlnsAttributes)([...STYLES_NS_PREFIXES$2]),
2356
+ "office:version": ODF_VERSION$2
2357
2357
  }, [
2358
2358
  el("office:styles"),
2359
- el("office:automatic-styles", {}, [buildPageLayout$1()]),
2359
+ el("office:automatic-styles", {}, [buildPageLayout$2()]),
2360
2360
  el("office:master-styles", {}, [el("style:master-page", {
2361
- "style:name": MASTER_PAGE_NAME$1,
2362
- "style:page-layout-name": PAGE_LAYOUT_NAME$1
2361
+ "style:name": MASTER_PAGE_NAME$2,
2362
+ "style:page-layout-name": PAGE_LAYOUT_NAME$2
2363
2363
  })])
2364
2364
  ]);
2365
2365
  }
2366
- function buildContentXml$1() {
2366
+ function buildContentXml$2() {
2367
2367
  return el("office:document-content", {
2368
- ...(0, odf_js.xmlnsAttributes)([...CONTENT_NS_PREFIXES$1]),
2369
- "office:version": ODF_VERSION$1
2368
+ ...(0, odf_js.xmlnsAttributes)([...CONTENT_NS_PREFIXES$2]),
2369
+ "office:version": ODF_VERSION$2
2370
2370
  }, [el("office:automatic-styles"), el("office:body", {}, [el("office:text")])]);
2371
2371
  }
2372
- function buildMetaXml$1() {
2372
+ function buildMetaXml$2() {
2373
2373
  return el("office:document-meta", {
2374
- ...(0, odf_js.xmlnsAttributes)([...META_NS_PREFIXES$1]),
2375
- "office:version": ODF_VERSION$1
2374
+ ...(0, odf_js.xmlnsAttributes)([...META_NS_PREFIXES$2]),
2375
+ "office:version": ODF_VERSION$2
2376
2376
  }, [el("office:meta")]);
2377
2377
  }
2378
2378
  function createEmptyOdtPackage() {
2379
2379
  const pkg = { parts: {
2380
2380
  "content.xml": {
2381
2381
  kind: "xml",
2382
- nodes: [declaration$1(), buildContentXml$1()]
2382
+ nodes: [declaration$2(), buildContentXml$2()]
2383
2383
  },
2384
2384
  "styles.xml": {
2385
2385
  kind: "xml",
2386
- nodes: [declaration$1(), buildStylesXml$1()]
2386
+ nodes: [declaration$2(), buildStylesXml$2()]
2387
2387
  },
2388
2388
  "meta.xml": {
2389
2389
  kind: "xml",
2390
- nodes: [declaration$1(), buildMetaXml$1()]
2390
+ nodes: [declaration$2(), buildMetaXml$2()]
2391
2391
  }
2392
2392
  } };
2393
2393
  (0, odf_js.setDocumentMediaType)(pkg, odf_js.ODF_MEDIA_TYPES.odt);
@@ -2508,20 +2508,20 @@ function buildTable(pkg, init) {
2508
2508
  }
2509
2509
  //#endregion
2510
2510
  //#region src/edit/odt/editor.ts
2511
- const CONTENT_PART_PATH$1 = "content.xml";
2511
+ const CONTENT_PART_PATH$2 = "content.xml";
2512
2512
  function findContentRoot(pkg) {
2513
- const part = pkg.parts[CONTENT_PART_PATH$1];
2513
+ const part = pkg.parts[CONTENT_PART_PATH$2];
2514
2514
  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$1}`);
2515
+ if (root === void 0) throw new Error(`package has no root element at ${CONTENT_PART_PATH$2}`);
2516
2516
  return root;
2517
2517
  }
2518
- function directChild$3(parent, tag) {
2518
+ function directChild$4(parent, tag) {
2519
2519
  for (const child of parent.children) if (child.type === "element" && child.tag === tag) return child;
2520
2520
  }
2521
2521
  function findOfficeText(contentRoot) {
2522
- const body = directChild$3(contentRoot, "office:body");
2523
- const text = body === void 0 ? void 0 : directChild$3(body, "office:text");
2524
- if (text === void 0) throw new Error(`${CONTENT_PART_PATH$1} has no office:body/office:text element`);
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`);
2525
2525
  return text;
2526
2526
  }
2527
2527
  var OdtBodyImpl = class {
@@ -2653,7 +2653,7 @@ function appendBlock(body, block) {
2653
2653
  }
2654
2654
  //#endregion
2655
2655
  //#region src/edit/odp/scaffold.ts
2656
- const CONTENT_NS_PREFIXES = [
2656
+ const CONTENT_NS_PREFIXES$1 = [
2657
2657
  "office",
2658
2658
  "style",
2659
2659
  "text",
@@ -2664,7 +2664,7 @@ const CONTENT_NS_PREFIXES = [
2664
2664
  "svg",
2665
2665
  "xlink"
2666
2666
  ];
2667
- const STYLES_NS_PREFIXES = [
2667
+ const STYLES_NS_PREFIXES$1 = [
2668
2668
  "office",
2669
2669
  "style",
2670
2670
  "text",
@@ -2675,14 +2675,14 @@ const STYLES_NS_PREFIXES = [
2675
2675
  "svg",
2676
2676
  "xlink"
2677
2677
  ];
2678
- const META_NS_PREFIXES = [
2678
+ const META_NS_PREFIXES$1 = [
2679
2679
  "office",
2680
2680
  "meta",
2681
2681
  "dc"
2682
2682
  ];
2683
- const ODF_VERSION = "1.3";
2684
- const MASTER_PAGE_NAME = "Standard";
2685
- function declaration() {
2683
+ const ODF_VERSION$1 = "1.3";
2684
+ const MASTER_PAGE_NAME$1 = "Standard";
2685
+ function declaration$1() {
2686
2686
  return {
2687
2687
  type: "declaration",
2688
2688
  attributes: [
@@ -2701,50 +2701,50 @@ function declaration() {
2701
2701
  ]
2702
2702
  };
2703
2703
  }
2704
- function buildPageLayout() {
2704
+ function buildPageLayout$1() {
2705
2705
  return el("style:page-layout", { "style:name": "PM1" }, [el("style:page-layout-properties", {
2706
2706
  "fo:page-width": `${document_content_model.SLIDE_SIZE_WIDESCREEN.widthPt}pt`,
2707
2707
  "fo:page-height": `${document_content_model.SLIDE_SIZE_WIDESCREEN.heightPt}pt`
2708
2708
  })]);
2709
2709
  }
2710
- function buildStylesXml() {
2710
+ function buildStylesXml$1() {
2711
2711
  return el("office:document-styles", {
2712
- ...(0, odf_js.xmlnsAttributes)([...STYLES_NS_PREFIXES]),
2713
- "office:version": ODF_VERSION
2712
+ ...(0, odf_js.xmlnsAttributes)([...STYLES_NS_PREFIXES$1]),
2713
+ "office:version": ODF_VERSION$1
2714
2714
  }, [
2715
2715
  el("office:styles"),
2716
- el("office:automatic-styles", {}, [buildPageLayout()]),
2716
+ el("office:automatic-styles", {}, [buildPageLayout$1()]),
2717
2717
  el("office:master-styles", {}, [el("style:master-page", {
2718
- "style:name": MASTER_PAGE_NAME,
2718
+ "style:name": MASTER_PAGE_NAME$1,
2719
2719
  "style:page-layout-name": "PM1"
2720
2720
  })])
2721
2721
  ]);
2722
2722
  }
2723
- function buildContentXml() {
2723
+ function buildContentXml$1() {
2724
2724
  return el("office:document-content", {
2725
- ...(0, odf_js.xmlnsAttributes)([...CONTENT_NS_PREFIXES]),
2726
- "office:version": ODF_VERSION
2725
+ ...(0, odf_js.xmlnsAttributes)([...CONTENT_NS_PREFIXES$1]),
2726
+ "office:version": ODF_VERSION$1
2727
2727
  }, [el("office:automatic-styles"), el("office:body", {}, [el("office:presentation")])]);
2728
2728
  }
2729
- function buildMetaXml() {
2729
+ function buildMetaXml$1() {
2730
2730
  return el("office:document-meta", {
2731
- ...(0, odf_js.xmlnsAttributes)([...META_NS_PREFIXES]),
2732
- "office:version": ODF_VERSION
2731
+ ...(0, odf_js.xmlnsAttributes)([...META_NS_PREFIXES$1]),
2732
+ "office:version": ODF_VERSION$1
2733
2733
  }, [el("office:meta")]);
2734
2734
  }
2735
2735
  function createEmptyOdpPackage() {
2736
2736
  const pkg = { parts: {
2737
2737
  "content.xml": {
2738
2738
  kind: "xml",
2739
- nodes: [declaration(), buildContentXml()]
2739
+ nodes: [declaration$1(), buildContentXml$1()]
2740
2740
  },
2741
2741
  "styles.xml": {
2742
2742
  kind: "xml",
2743
- nodes: [declaration(), buildStylesXml()]
2743
+ nodes: [declaration$1(), buildStylesXml$1()]
2744
2744
  },
2745
2745
  "meta.xml": {
2746
2746
  kind: "xml",
2747
- nodes: [declaration(), buildMetaXml()]
2747
+ nodes: [declaration$1(), buildMetaXml$1()]
2748
2748
  }
2749
2749
  } };
2750
2750
  (0, odf_js.setDocumentMediaType)(pkg, odf_js.ODF_MEDIA_TYPES.odp);
@@ -2784,7 +2784,7 @@ function addImageMedia(pkg, imageBytes, format) {
2784
2784
  }
2785
2785
  //#endregion
2786
2786
  //#region src/edit/odp/shape.ts
2787
- function directChild$2(parent, tag) {
2787
+ function directChild$3(parent, tag) {
2788
2788
  for (const child of parent.children) if (child.type === "element" && child.tag === tag) return child;
2789
2789
  }
2790
2790
  function buildTransformAttr(frame, rotationDeg) {
@@ -2852,7 +2852,7 @@ var OdpShape = class {
2852
2852
  }
2853
2853
  textBox(create) {
2854
2854
  const node = this.live();
2855
- const existing = directChild$2(node, "draw:text-box");
2855
+ const existing = directChild$3(node, "draw:text-box");
2856
2856
  if (existing !== void 0 || !create) return existing;
2857
2857
  const created = el("draw:text-box");
2858
2858
  node.children.push(created);
@@ -2913,7 +2913,7 @@ function insertImageFrameMedia(context, frame, image) {
2913
2913
  }
2914
2914
  //#endregion
2915
2915
  //#region src/edit/odp/slide.ts
2916
- function directChild$1(parent, tag) {
2916
+ function directChild$2(parent, tag) {
2917
2917
  for (const child of parent.children) if (child.type === "element" && child.tag === tag) return child;
2918
2918
  }
2919
2919
  const NOTES_FRAME_X_PT = 20;
@@ -2962,13 +2962,13 @@ var OdpSlide = class {
2962
2962
  return new OdpShape(node.children, frameElement, this.context.pkg);
2963
2963
  }
2964
2964
  get notes() {
2965
- const notesElement = directChild$1(this.live(), "presentation:notes");
2965
+ const notesElement = directChild$2(this.live(), "presentation:notes");
2966
2966
  if (notesElement === void 0) return "";
2967
2967
  return (0, ooxml_js.elementsWithTag)(notesElement.children, "text:p").map((p) => decodeOdfText(p.children)).join("\n");
2968
2968
  }
2969
2969
  set notes(value) {
2970
2970
  const node = this.live();
2971
- const existing = directChild$1(node, "presentation:notes");
2971
+ const existing = directChild$2(node, "presentation:notes");
2972
2972
  const notesElement = buildNotesElement(this.context.pkg, value);
2973
2973
  if (existing === void 0) node.children.push(notesElement);
2974
2974
  else existing.children = notesElement.children;
@@ -2980,26 +2980,26 @@ var OdpSlide = class {
2980
2980
  };
2981
2981
  //#endregion
2982
2982
  //#region src/edit/odp/editor.ts
2983
- const CONTENT_PART_PATH = "content.xml";
2983
+ const CONTENT_PART_PATH$1 = "content.xml";
2984
2984
  const STYLES_PART_PATH = "styles.xml";
2985
- function directChild(parent, tag) {
2985
+ function directChild$1(parent, tag) {
2986
2986
  for (const child of parent.children) if (child.type === "element" && child.tag === tag) return child;
2987
2987
  }
2988
- function findRoot(pkg, partPath) {
2988
+ function findRoot$1(pkg, partPath) {
2989
2989
  const part = pkg.parts[partPath];
2990
2990
  const root = part?.kind === "xml" ? part.nodes.find((n) => n.type === "element") : void 0;
2991
2991
  if (root === void 0) throw new Error(`package has no root element at ${partPath}`);
2992
2992
  return root;
2993
2993
  }
2994
2994
  function findOfficePresentation(pkg) {
2995
- const body = directChild(findRoot(pkg, CONTENT_PART_PATH), "office:body");
2996
- const presentation = body === void 0 ? void 0 : directChild(body, "office:presentation");
2997
- if (presentation === void 0) throw new Error(`${CONTENT_PART_PATH} has no office:body/office:presentation element`);
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`);
2998
2998
  return presentation;
2999
2999
  }
3000
3000
  function findPageLayoutProperties(pkg) {
3001
- 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");
3002
- const properties = pageLayout === void 0 ? void 0 : directChild(pageLayout, "style:page-layout-properties");
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
3003
  if (properties === void 0) throw new Error(`${STYLES_PART_PATH} has no style:page-layout[style:name="PM1"]/style:page-layout-properties element`);
3004
3004
  return properties;
3005
3005
  }
@@ -3019,7 +3019,7 @@ var OdpEditor = class {
3019
3019
  }
3020
3020
  addSlide() {
3021
3021
  const presentation = findOfficePresentation(this.pkg);
3022
- const pageElement = el("draw:page", { "draw:master-page-name": MASTER_PAGE_NAME });
3022
+ const pageElement = el("draw:page", { "draw:master-page-name": MASTER_PAGE_NAME$1 });
3023
3023
  presentation.children.push(pageElement);
3024
3024
  const context = { pkg: this.pkg };
3025
3025
  return new OdpSlide(presentation.children, pageElement, context);
@@ -3120,6 +3120,539 @@ function appendShape(slide, shape) {
3120
3120
  }
3121
3121
  }
3122
3122
  //#endregion
3123
+ //#region src/edit/ods/scaffold.ts
3124
+ const CONTENT_NS_PREFIXES = [
3125
+ "office",
3126
+ "style",
3127
+ "text",
3128
+ "table",
3129
+ "fo"
3130
+ ];
3131
+ const STYLES_NS_PREFIXES = [
3132
+ "office",
3133
+ "style",
3134
+ "table",
3135
+ "fo"
3136
+ ];
3137
+ const META_NS_PREFIXES = [
3138
+ "office",
3139
+ "meta",
3140
+ "dc"
3141
+ ];
3142
+ 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";
3145
+ const SHEET_TABLE_STYLE_NAME = "OdsTable";
3146
+ const DEFAULT_SHEET_NAME = "Sheet1";
3147
+ const DEFAULT_MARGIN = "2cm";
3148
+ function declaration() {
3149
+ return {
3150
+ type: "declaration",
3151
+ attributes: [
3152
+ {
3153
+ name: "version",
3154
+ value: "1.0"
3155
+ },
3156
+ {
3157
+ name: "encoding",
3158
+ value: "UTF-8"
3159
+ },
3160
+ {
3161
+ name: "standalone",
3162
+ value: "yes"
3163
+ }
3164
+ ]
3165
+ };
3166
+ }
3167
+ function buildPageLayout() {
3168
+ return el("style:page-layout", { "style:name": "PM1" }, [el("style:page-layout-properties", {
3169
+ "fo:page-width": `${document_content_model.PAGE_SIZE_A4.widthPt}pt`,
3170
+ "fo:page-height": `${document_content_model.PAGE_SIZE_A4.heightPt}pt`,
3171
+ "fo:margin-top": DEFAULT_MARGIN,
3172
+ "fo:margin-right": DEFAULT_MARGIN,
3173
+ "fo:margin-bottom": DEFAULT_MARGIN,
3174
+ "fo:margin-left": DEFAULT_MARGIN
3175
+ })]);
3176
+ }
3177
+ function buildStylesXml() {
3178
+ return el("office:document-styles", {
3179
+ ...(0, odf_js.xmlnsAttributes)([...STYLES_NS_PREFIXES]),
3180
+ "office:version": ODF_VERSION
3181
+ }, [
3182
+ el("office:styles"),
3183
+ el("office:automatic-styles", {}, [buildPageLayout()]),
3184
+ el("office:master-styles", {}, [el("style:master-page", {
3185
+ "style:name": MASTER_PAGE_NAME,
3186
+ "style:page-layout-name": "PM1"
3187
+ })])
3188
+ ]);
3189
+ }
3190
+ function buildSheetTableStyle() {
3191
+ return el("style:style", {
3192
+ "style:name": SHEET_TABLE_STYLE_NAME,
3193
+ "style:family": "table",
3194
+ "style:master-page-name": MASTER_PAGE_NAME
3195
+ });
3196
+ }
3197
+ function buildCalculationSettings() {
3198
+ return el("table:calculation-settings", {
3199
+ "table:automatic-find-labels": "false",
3200
+ "table:use-regular-expressions": "false",
3201
+ "table:use-wildcards": "true",
3202
+ "table:null-year": "1950"
3203
+ });
3204
+ }
3205
+ function buildContentXml() {
3206
+ const table = el("table:table", {
3207
+ "table:name": DEFAULT_SHEET_NAME,
3208
+ "table:style-name": SHEET_TABLE_STYLE_NAME
3209
+ });
3210
+ return el("office:document-content", {
3211
+ ...(0, odf_js.xmlnsAttributes)([...CONTENT_NS_PREFIXES]),
3212
+ ...OF_NAMESPACE_ATTR,
3213
+ "office:version": ODF_VERSION
3214
+ }, [el("office:automatic-styles", {}, [buildSheetTableStyle()]), el("office:body", {}, [el("office:spreadsheet", {}, [buildCalculationSettings(), table])])]);
3215
+ }
3216
+ function buildMetaXml() {
3217
+ return el("office:document-meta", {
3218
+ ...(0, odf_js.xmlnsAttributes)([...META_NS_PREFIXES]),
3219
+ "office:version": ODF_VERSION
3220
+ }, [el("office:meta")]);
3221
+ }
3222
+ function createEmptyOdsPackage() {
3223
+ const pkg = { parts: {
3224
+ "content.xml": {
3225
+ kind: "xml",
3226
+ nodes: [declaration(), buildContentXml()]
3227
+ },
3228
+ "styles.xml": {
3229
+ kind: "xml",
3230
+ nodes: [declaration(), buildStylesXml()]
3231
+ },
3232
+ "meta.xml": {
3233
+ kind: "xml",
3234
+ nodes: [declaration(), buildMetaXml()]
3235
+ }
3236
+ } };
3237
+ (0, odf_js.setDocumentMediaType)(pkg, odf_js.ODF_MEDIA_TYPES.ods);
3238
+ (0, odf_js.syncManifest)(pkg);
3239
+ return pkg;
3240
+ }
3241
+ //#endregion
3242
+ //#region src/edit/ods/address.ts
3243
+ const ROW_TAG = "table:table-row";
3244
+ const COLUMN_TAG = "table:table-column";
3245
+ const CELL_TAG = "table:table-cell";
3246
+ const COVERED_CELL_TAG = "table:covered-table-cell";
3247
+ const ROW_REPEAT_ATTR = "table:number-rows-repeated";
3248
+ const COLUMN_REPEAT_ATTR = "table:number-columns-repeated";
3249
+ function isElementWithTag(tag) {
3250
+ return (node) => node.type === "element" && node.tag === tag;
3251
+ }
3252
+ function isCellOrCoveredCell(node) {
3253
+ return node.type === "element" && (node.tag === "table:table-cell" || node.tag === "table:covered-table-cell");
3254
+ }
3255
+ function validateIndex(value, label) {
3256
+ if (!Number.isInteger(value) || value < 0) throw new Error(`${label} must be a non-negative integer, got ${value}`);
3257
+ }
3258
+ function readRepeatCount(node, attrName) {
3259
+ const raw = node.attributes.find((attribute) => attribute.name === attrName)?.value;
3260
+ if (raw === void 0) return 1;
3261
+ const parsed = Number.parseInt(raw, 10);
3262
+ return Number.isInteger(parsed) && parsed > 0 ? parsed : 1;
3263
+ }
3264
+ function withRepeatCount(node, attrName, count) {
3265
+ const clone = structuredClone(node);
3266
+ clone.attributes = clone.attributes.filter((attribute) => attribute.name !== attrName);
3267
+ if (count > 1) clone.attributes.push({
3268
+ name: attrName,
3269
+ value: String(count)
3270
+ });
3271
+ return clone;
3272
+ }
3273
+ function replaceRun(children, isMember, targetIndex, repeatAttr, buildEmpty) {
3274
+ validateIndex(targetIndex, "targetIndex");
3275
+ const members = [];
3276
+ children.forEach((node, position) => {
3277
+ if (isMember(node)) members.push({
3278
+ node,
3279
+ position
3280
+ });
3281
+ });
3282
+ let cursor = 0;
3283
+ for (const member of members) {
3284
+ const count = readRepeatCount(member.node, repeatAttr);
3285
+ if (targetIndex < cursor + count) {
3286
+ const offset = targetIndex - cursor;
3287
+ if (count === 1) return member.node;
3288
+ const before = offset > 0 ? withRepeatCount(member.node, repeatAttr, offset) : void 0;
3289
+ const target = withRepeatCount(member.node, repeatAttr, 1);
3290
+ const replacement = [
3291
+ before,
3292
+ target,
3293
+ count - offset - 1 > 0 ? withRepeatCount(member.node, repeatAttr, count - offset - 1) : void 0
3294
+ ].filter((candidate) => candidate !== void 0);
3295
+ children.splice(member.position, 1, ...replacement);
3296
+ return target;
3297
+ }
3298
+ cursor += count;
3299
+ }
3300
+ const gap = targetIndex - cursor;
3301
+ const lastMember = members[members.length - 1];
3302
+ const insertAt = lastMember === void 0 ? children.length : lastMember.position + 1;
3303
+ const toInsert = [];
3304
+ if (gap > 0) toInsert.push(withRepeatCount(buildEmpty(), repeatAttr, gap));
3305
+ const target = buildEmpty();
3306
+ toInsert.push(target);
3307
+ children.splice(insertAt, 0, ...toInsert);
3308
+ return target;
3309
+ }
3310
+ function ensureColumnCoverage(tableElement, minCount) {
3311
+ if (minCount <= 0) return;
3312
+ const columnMembers = [];
3313
+ tableElement.children.forEach((node, position) => {
3314
+ if (isElementWithTag("table:table-column")(node)) columnMembers.push({
3315
+ node,
3316
+ position
3317
+ });
3318
+ });
3319
+ const covered = columnMembers.reduce((sum, member) => sum + readRepeatCount(member.node, COLUMN_REPEAT_ATTR), 0);
3320
+ if (covered >= minCount) return;
3321
+ const additional = minCount - covered;
3322
+ const newColumn = withRepeatCount(el(COLUMN_TAG), COLUMN_REPEAT_ATTR, additional);
3323
+ const lastColumn = columnMembers[columnMembers.length - 1];
3324
+ if (lastColumn === void 0) {
3325
+ const firstRowPosition = tableElement.children.findIndex(isElementWithTag(ROW_TAG));
3326
+ const insertAt = firstRowPosition === -1 ? tableElement.children.length : firstRowPosition;
3327
+ tableElement.children.splice(insertAt, 0, newColumn);
3328
+ } else tableElement.children.splice(lastColumn.position + 1, 0, newColumn);
3329
+ }
3330
+ function resolveCellNode(tableElement, row, column) {
3331
+ validateIndex(row, "row");
3332
+ validateIndex(column, "column");
3333
+ ensureColumnCoverage(tableElement, column + 1);
3334
+ return replaceRun(replaceRun(tableElement.children, isElementWithTag(ROW_TAG), row, ROW_REPEAT_ATTR, () => el(ROW_TAG)).children, isCellOrCoveredCell, column, COLUMN_REPEAT_ATTR, () => el(CELL_TAG));
3335
+ }
3336
+ //#endregion
3337
+ //#region src/edit/ods/cell.ts
3338
+ const VALUE_TYPE_ATTR = "office:value-type";
3339
+ const VALUE_ATTR = "office:value";
3340
+ const BOOLEAN_VALUE_ATTR = "office:boolean-value";
3341
+ const DATE_VALUE_ATTR = "office:date-value";
3342
+ const TIME_VALUE_ATTR = "office:time-value";
3343
+ const STRING_VALUE_ATTR = "office:string-value";
3344
+ const CURRENCY_ATTR = "office:currency";
3345
+ const FORMULA_ATTR = "table:formula";
3346
+ const VALUE_ATTRS = [
3347
+ VALUE_TYPE_ATTR,
3348
+ VALUE_ATTR,
3349
+ BOOLEAN_VALUE_ATTR,
3350
+ DATE_VALUE_ATTR,
3351
+ TIME_VALUE_ATTR,
3352
+ STRING_VALUE_ATTR,
3353
+ CURRENCY_ATTR
3354
+ ];
3355
+ function parseNumber(raw) {
3356
+ if (raw === void 0) return;
3357
+ const value = Number(raw);
3358
+ return Number.isNaN(value) ? void 0 : value;
3359
+ }
3360
+ var OdsCell = class {
3361
+ node;
3362
+ pkg;
3363
+ constructor(node, pkg) {
3364
+ this.node = node;
3365
+ this.pkg = pkg;
3366
+ }
3367
+ get value() {
3368
+ const valueType = (0, ooxml_js.attr)(this.node, VALUE_TYPE_ATTR);
3369
+ const displayText = this.displayText;
3370
+ switch (valueType) {
3371
+ case "float": {
3372
+ const value = parseNumber((0, ooxml_js.attr)(this.node, VALUE_ATTR));
3373
+ return value === void 0 ? {
3374
+ kind: "string",
3375
+ value: displayText
3376
+ } : {
3377
+ kind: "number",
3378
+ value
3379
+ };
3380
+ }
3381
+ case "percentage": {
3382
+ const value = parseNumber((0, ooxml_js.attr)(this.node, VALUE_ATTR));
3383
+ return value === void 0 ? {
3384
+ kind: "string",
3385
+ value: displayText
3386
+ } : {
3387
+ kind: "percentage",
3388
+ value
3389
+ };
3390
+ }
3391
+ case "currency": {
3392
+ const value = parseNumber((0, ooxml_js.attr)(this.node, VALUE_ATTR));
3393
+ if (value === void 0) return {
3394
+ kind: "string",
3395
+ value: displayText
3396
+ };
3397
+ const currency = (0, ooxml_js.attr)(this.node, CURRENCY_ATTR);
3398
+ return currency === void 0 ? {
3399
+ kind: "currency",
3400
+ value
3401
+ } : {
3402
+ kind: "currency",
3403
+ value,
3404
+ currency
3405
+ };
3406
+ }
3407
+ case "boolean": {
3408
+ const raw = (0, ooxml_js.attr)(this.node, BOOLEAN_VALUE_ATTR);
3409
+ return raw === void 0 ? {
3410
+ kind: "string",
3411
+ value: displayText
3412
+ } : {
3413
+ kind: "boolean",
3414
+ value: raw === "true"
3415
+ };
3416
+ }
3417
+ case "date": return {
3418
+ kind: "date",
3419
+ value: (0, ooxml_js.attr)(this.node, DATE_VALUE_ATTR) ?? displayText
3420
+ };
3421
+ case "time": return {
3422
+ kind: "time",
3423
+ value: (0, ooxml_js.attr)(this.node, TIME_VALUE_ATTR) ?? displayText
3424
+ };
3425
+ case "string": return {
3426
+ kind: "string",
3427
+ value: (0, ooxml_js.attr)(this.node, STRING_VALUE_ATTR) ?? displayText
3428
+ };
3429
+ default: return { kind: "empty" };
3430
+ }
3431
+ }
3432
+ set value(value) {
3433
+ for (const name of VALUE_ATTRS) removeAttr(this.node, name);
3434
+ switch (value.kind) {
3435
+ case "number":
3436
+ setAttr(this.node, VALUE_TYPE_ATTR, "float");
3437
+ setAttr(this.node, VALUE_ATTR, String(value.value));
3438
+ this.displayText = String(value.value);
3439
+ break;
3440
+ case "percentage":
3441
+ setAttr(this.node, VALUE_TYPE_ATTR, "percentage");
3442
+ setAttr(this.node, VALUE_ATTR, String(value.value));
3443
+ this.displayText = `${value.value * 100}%`;
3444
+ break;
3445
+ case "currency":
3446
+ setAttr(this.node, VALUE_TYPE_ATTR, "currency");
3447
+ setAttr(this.node, VALUE_ATTR, String(value.value));
3448
+ if (value.currency !== void 0) setAttr(this.node, CURRENCY_ATTR, value.currency);
3449
+ this.displayText = value.currency === void 0 ? String(value.value) : `${value.value} ${value.currency}`;
3450
+ break;
3451
+ case "boolean":
3452
+ setAttr(this.node, VALUE_TYPE_ATTR, "boolean");
3453
+ setAttr(this.node, BOOLEAN_VALUE_ATTR, value.value ? "true" : "false");
3454
+ this.displayText = value.value ? "TRUE" : "FALSE";
3455
+ break;
3456
+ case "date":
3457
+ setAttr(this.node, VALUE_TYPE_ATTR, "date");
3458
+ setAttr(this.node, DATE_VALUE_ATTR, value.value);
3459
+ this.displayText = value.value;
3460
+ break;
3461
+ case "time":
3462
+ setAttr(this.node, VALUE_TYPE_ATTR, "time");
3463
+ setAttr(this.node, TIME_VALUE_ATTR, value.value);
3464
+ this.displayText = value.value;
3465
+ break;
3466
+ case "string":
3467
+ setAttr(this.node, VALUE_TYPE_ATTR, "string");
3468
+ setAttr(this.node, STRING_VALUE_ATTR, value.value);
3469
+ this.displayText = value.value;
3470
+ break;
3471
+ case "error":
3472
+ setAttr(this.node, VALUE_TYPE_ATTR, "string");
3473
+ setAttr(this.node, STRING_VALUE_ATTR, value.value);
3474
+ this.displayText = value.value;
3475
+ break;
3476
+ case "empty": this.displayText = "";
3477
+ }
3478
+ }
3479
+ get formula() {
3480
+ return (0, ooxml_js.attr)(this.node, FORMULA_ATTR);
3481
+ }
3482
+ set formula(value) {
3483
+ if (value === void 0) {
3484
+ removeAttr(this.node, FORMULA_ATTR);
3485
+ return;
3486
+ }
3487
+ setAttr(this.node, FORMULA_ATTR, value);
3488
+ }
3489
+ get displayText() {
3490
+ return this.node.children.filter((child) => child.type === "element" && child.tag === "text:p").map((paragraph) => decodeOdfText(paragraph.children)).join("\n");
3491
+ }
3492
+ set displayText(value) {
3493
+ this.node.children = [el("text:p", {}, encodeOdfText(value))];
3494
+ }
3495
+ setStyledRuns(runs) {
3496
+ const textParagraph = el("text:p");
3497
+ this.node.children = [textParagraph];
3498
+ populateParagraph(new OdtParagraph(this.node.children, textParagraph, this.pkg), {
3499
+ kind: "paragraph",
3500
+ runs: [...runs]
3501
+ });
3502
+ }
3503
+ };
3504
+ //#endregion
3505
+ //#region src/edit/ods/sheet.ts
3506
+ const NAME_ATTR = "table:name";
3507
+ var OdsSheet = class {
3508
+ container;
3509
+ node;
3510
+ pkg;
3511
+ removed = false;
3512
+ constructor(container, node, pkg) {
3513
+ this.container = container;
3514
+ this.node = node;
3515
+ this.pkg = pkg;
3516
+ }
3517
+ live() {
3518
+ if (this.removed) throw new Error("this OdsSheet has been removed from the spreadsheet and can no longer be used");
3519
+ return this.node;
3520
+ }
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;
3525
+ }
3526
+ set name(value) {
3527
+ setAttr(this.live(), NAME_ATTR, value);
3528
+ }
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);
3533
+ }
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);
3538
+ }
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);
3554
+ }
3555
+ remove() {
3556
+ removeChild(this.container, this.live());
3557
+ this.removed = true;
3558
+ }
3559
+ };
3560
+ //#endregion
3561
+ //#region src/edit/ods/editor.ts
3562
+ const CONTENT_PART_PATH = "content.xml";
3563
+ function directChild(parent, tag) {
3564
+ for (const child of parent.children) if (child.type === "element" && child.tag === tag) return child;
3565
+ }
3566
+ function findRoot(pkg) {
3567
+ const part = pkg.parts[CONTENT_PART_PATH];
3568
+ 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}`);
3570
+ return root;
3571
+ }
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;
3577
+ }
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;
3587
+ }
3588
+ var OdsEditor = class {
3589
+ pkg;
3590
+ constructor(pkg) {
3591
+ this.pkg = pkg;
3592
+ }
3593
+ sheets() {
3594
+ const spreadsheet = findOfficeSpreadsheet(this.pkg);
3595
+ 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));
3597
+ return out;
3598
+ }
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;
3603
+ }
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);
3612
+ }
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);
3619
+ }
3620
+ toPackage() {
3621
+ return this.pkg;
3622
+ }
3623
+ toBytes() {
3624
+ return (0, odf_js.encodePackage)(this.pkg);
3625
+ }
3626
+ };
3627
+ function openOds(bytes) {
3628
+ return new OdsEditor((0, odf_js.decodePackage)(bytes));
3629
+ }
3630
+ function createOds() {
3631
+ return new OdsEditor(createEmptyOdsPackage());
3632
+ }
3633
+ //#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);
3642
+ }
3643
+ return editor.toPackage();
3644
+ }
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);
3654
+ }
3655
+ //#endregion
3123
3656
  //#region src/bytes/crc32.ts
3124
3657
  const CRC32_POLYNOMIAL = 3988292384;
3125
3658
  const BYTE_VALUES = 256;
@@ -9773,6 +10306,9 @@ exports.OdpEditor = OdpEditor;
9773
10306
  exports.OdpShape = OdpShape;
9774
10307
  exports.OdpSlide = OdpSlide;
9775
10308
  exports.OdsBytesSchema = OdsBytesSchema;
10309
+ exports.OdsCell = OdsCell;
10310
+ exports.OdsEditor = OdsEditor;
10311
+ exports.OdsSheet = OdsSheet;
9776
10312
  exports.OdtBytesSchema = OdtBytesSchema;
9777
10313
  exports.OdtEditor = OdtEditor;
9778
10314
  exports.OdtList = OdtList;
@@ -9887,6 +10423,7 @@ Object.defineProperty(exports, "base64ToBytes", {
9887
10423
  });
9888
10424
  exports.buildDocxPackage = buildDocxPackage;
9889
10425
  exports.buildOdpPackage = buildOdpPackage;
10426
+ exports.buildOdsPackage = buildOdsPackage;
9890
10427
  exports.buildOdtPackage = buildOdtPackage;
9891
10428
  exports.buildPptxPackage = buildPptxPackage;
9892
10429
  Object.defineProperty(exports, "buildXml", {
@@ -9925,6 +10462,7 @@ exports.convertWordprocessingToLayout = convertWordprocessingToLayout;
9925
10462
  exports.createDocx = createDocx;
9926
10463
  exports.createLocalDocumentConverter = createLocalDocumentConverter;
9927
10464
  exports.createOdp = createOdp;
10465
+ exports.createOds = createOds;
9928
10466
  exports.createOdt = createOdt;
9929
10467
  exports.createPptx = createPptx;
9930
10468
  Object.defineProperty(exports, "decodeCompactPackage", {
@@ -9998,6 +10536,7 @@ exports.odtPdfCodec = odtPdfCodec;
9998
10536
  exports.odtToPdf = odtToPdf;
9999
10537
  exports.openDocx = openDocx;
10000
10538
  exports.openOdp = openOdp;
10539
+ exports.openOds = openOds;
10001
10540
  exports.openOdt = openOdt;
10002
10541
  exports.openPptx = openPptx;
10003
10542
  Object.defineProperty(exports, "packageCodec", {