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.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { AttributeSchema, BinaryPartSchema, CommentSchema, CompactPackageSchema, CompactPartSchema, CompactXmlNodeSchema, DefinedNameSchema, PackageSchema, PartSchema, XmlCdataSchema, XmlCommentSchema, XmlDeclarationSchema, XmlElementSchema, XmlNodeSchema, XmlPartSchema, XmlPiSchema, XmlTextSchema, attr, attr as attr$1, base64ToBytes, base64ToBytes as base64ToBytes$1, buildXml, bytesToBase64, bytesToBase64 as bytesToBase64$1, childrenWithTag, compactCodec, compactPackageCodec, decodeCompactPackage, decodeEntities, decodePackage, decodePackage as decodePackage$1, elementsWithTag, elementsWithTag as elementsWithTag$1, encodeCompactPackage, encodePackage, encodePackage as encodePackage$1, fromCompact, isCompactXmlNode, isXmlNode, packageCodec, parsePackage, parseXml, readDocx, readPptx, resolveRelationships, resolveRelationships as resolveRelationships$1, rootElement, rootElement as rootElement$1, serializePackage, textContent, textContent as textContent$1, toCompact, unzipPackage, walk, xmlCodec, zipPackage } from "ooxml.js";
2
2
  import { COLOR_BLACK, ContentBlockSchema, ContentCellValueSchema, ContentImageBlockSchema, ContentPageBreakSchema, ContentParagraphSchema, ContentRunSchema, ContentSectionSchema, ContentSectionSchema as ContentSectionSchema$1, ContentShapeSchema, ContentSheetCellSchema, ContentSheetColumnSchema, ContentSheetPrintRangeSchema, ContentSheetPrintSettingsSchema, ContentSheetRepeatRangeSchema, ContentSheetRowSchema, ContentSheetSchema, ContentSheetSchema as ContentSheetSchema$1, ContentSlideSchema, ContentSlideSchema as ContentSlideSchema$1, ContentTableCellSchema, ContentTableRowSchema, ContentTableSchema, DEFAULT_LAYOUT_FONT, LAYOUT_FORMAT_VERSION, LAYOUT_FORMAT_VERSION as LAYOUT_FORMAT_VERSION$1, LayoutDocumentSchema, LayoutMetadataSchema, PAGE_SIZE_A4, PAGE_SIZE_LETTER, SLIDE_SIZE_STANDARD, SLIDE_SIZE_WIDESCREEN, colorToRgbHex, isContentBlock, rgbHexToColor } from "document-content-model";
3
3
  import { z } from "zod";
4
- import { ODF_MEDIA_TYPES, StyleRegistry, applyOdfTransform, base64ToBytes as base64ToBytes$2, bytesToBase64 as bytesToBase64$2, decodeOdfText, decodePackage as decodePackage$2, encodePackage as encodePackage$2, formatOdfLength, parseOdfLength, readOdp, readOds, readOdt, resolveOdfShapeGeometry, resolveStyle, setDocumentMediaType, syncManifest, syncManifest as syncManifest$1, xmlnsAttributes } from "odf.js";
4
+ import { ODF_MEDIA_TYPES, StyleRegistry, applyOdfTransform, base64ToBytes as base64ToBytes$2, bytesToBase64 as bytesToBase64$2, decodeOdfText, decodePackage as decodePackage$2, encodePackage as encodePackage$2, formatOdfLength, parseCellReference, parseOdfLength, readOdp, readOds, readOdt, resolveOdfShapeGeometry, resolveStyle, setDocumentMediaType, syncManifest, syncManifest as syncManifest$1, xmlnsAttributes } from "odf.js";
5
5
  import { Unzlib, inflateSync, unzlibSync, zlibSync } from "fflate";
6
6
  //#region src/model/content.ts
7
7
  const CONTENT_FORMAT_VERSION = 1;
@@ -529,7 +529,7 @@ function needsSpacePreserve(text) {
529
529
  }
530
530
  //#endregion
531
531
  //#region src/edit/docx/run.ts
532
- function directChild$8(parent, tag) {
532
+ function directChild$9(parent, tag) {
533
533
  for (const child of parent.children) if (child.type === "element" && child.tag === tag) return child;
534
534
  }
535
535
  function appendUElement(rPr, value) {
@@ -538,7 +538,7 @@ function appendUElement(rPr, value) {
538
538
  return created;
539
539
  }
540
540
  function findOrCreateT(run) {
541
- const existing = directChild$8(run, "w:t");
541
+ const existing = directChild$9(run, "w:t");
542
542
  if (existing !== void 0) return existing;
543
543
  const created = el("w:t");
544
544
  run.children.push(created);
@@ -558,7 +558,7 @@ var DocxRun = class {
558
558
  }
559
559
  rPr(create) {
560
560
  const node = this.live();
561
- return create ? ensureFirstChild(node, "w:rPr") : directChild$8(node, "w:rPr");
561
+ return create ? ensureFirstChild(node, "w:rPr") : directChild$9(node, "w:rPr");
562
562
  }
563
563
  get text() {
564
564
  return textContent$1(this.live());
@@ -582,14 +582,14 @@ var DocxRun = class {
582
582
  }
583
583
  get underline() {
584
584
  const rPr = this.rPr(false);
585
- const uElement = rPr === void 0 ? void 0 : directChild$8(rPr, "w:u");
585
+ const uElement = rPr === void 0 ? void 0 : directChild$9(rPr, "w:u");
586
586
  if (uElement === void 0) return false;
587
587
  for (const a of uElement.attributes) if (a.name === "w:val") return a.value !== "none";
588
588
  return true;
589
589
  }
590
590
  set underline(value) {
591
591
  const rPr = this.rPr(true);
592
- const existing = directChild$8(rPr, "w:u");
592
+ const existing = directChild$9(rPr, "w:u");
593
593
  if (existing === void 0) {
594
594
  appendUElement(rPr, value);
595
595
  return;
@@ -663,7 +663,7 @@ function buildRun$1(init = {}) {
663
663
  }
664
664
  //#endregion
665
665
  //#region src/edit/docx/paragraph.ts
666
- function directChild$7(parent, tag) {
666
+ function directChild$8(parent, tag) {
667
667
  for (const child of parent.children) if (child.type === "element" && child.tag === tag) return child;
668
668
  }
669
669
  var DocxParagraph = class {
@@ -682,7 +682,7 @@ var DocxParagraph = class {
682
682
  }
683
683
  pPr(create) {
684
684
  const node = this.live();
685
- return create ? ensureFirstChild(node, "w:pPr") : directChild$7(node, "w:pPr");
685
+ return create ? ensureFirstChild(node, "w:pPr") : directChild$8(node, "w:pPr");
686
686
  }
687
687
  get text() {
688
688
  return textContent$1(this.live());
@@ -719,7 +719,7 @@ var DocxParagraph = class {
719
719
  set styleId(value) {
720
720
  if (value === void 0) {
721
721
  const pPr = this.pPr(false);
722
- const existing = pPr === void 0 ? void 0 : directChild$7(pPr, "w:pStyle");
722
+ const existing = pPr === void 0 ? void 0 : directChild$8(pPr, "w:pStyle");
723
723
  if (existing !== void 0 && pPr !== void 0) removeChild(pPr.children, existing);
724
724
  return;
725
725
  }
@@ -731,7 +731,7 @@ var DocxParagraph = class {
731
731
  set alignment(value) {
732
732
  if (value === void 0) {
733
733
  const pPr = this.pPr(false);
734
- const existing = pPr === void 0 ? void 0 : directChild$7(pPr, "w:jc");
734
+ const existing = pPr === void 0 ? void 0 : directChild$8(pPr, "w:jc");
735
735
  if (existing !== void 0 && pPr !== void 0) removeChild(pPr.children, existing);
736
736
  return;
737
737
  }
@@ -739,12 +739,12 @@ var DocxParagraph = class {
739
739
  }
740
740
  get list() {
741
741
  const pPr = this.pPr(false);
742
- const numPr = pPr === void 0 ? void 0 : directChild$7(pPr, "w:numPr");
742
+ const numPr = pPr === void 0 ? void 0 : directChild$8(pPr, "w:numPr");
743
743
  if (numPr === void 0) return;
744
- const numIdElement = directChild$7(numPr, "w:numId");
744
+ const numIdElement = directChild$8(numPr, "w:numId");
745
745
  const numId = numIdElement === void 0 ? void 0 : attr$1(numIdElement, "w:val");
746
746
  if (numId === void 0) return;
747
- const ilvlElement = directChild$7(numPr, "w:ilvl");
747
+ const ilvlElement = directChild$8(numPr, "w:ilvl");
748
748
  const ilvl = ilvlElement === void 0 ? void 0 : attr$1(ilvlElement, "w:val");
749
749
  return {
750
750
  numId,
@@ -754,7 +754,7 @@ var DocxParagraph = class {
754
754
  set list(value) {
755
755
  const pPr = this.pPr(true);
756
756
  if (value === void 0) {
757
- const existing = directChild$7(pPr, "w:numPr");
757
+ const existing = directChild$8(pPr, "w:numPr");
758
758
  if (existing !== void 0) removeChild(pPr.children, existing);
759
759
  return;
760
760
  }
@@ -788,7 +788,7 @@ function buildParagraph$1(init = {}) {
788
788
  const CONTENT_TYPES_NS$1 = "http://schemas.openxmlformats.org/package/2006/content-types";
789
789
  const RELS_NS$1 = "http://schemas.openxmlformats.org/package/2006/relationships";
790
790
  const WORDML_NS = "http://schemas.openxmlformats.org/wordprocessingml/2006/main";
791
- function declaration$3() {
791
+ function declaration$4() {
792
792
  return {
793
793
  type: "declaration",
794
794
  attributes: [
@@ -857,23 +857,23 @@ function createEmptyDocxPackage() {
857
857
  return { parts: {
858
858
  "[Content_Types].xml": {
859
859
  kind: "xml",
860
- nodes: [declaration$3(), contentTypes]
860
+ nodes: [declaration$4(), contentTypes]
861
861
  },
862
862
  "_rels/.rels": {
863
863
  kind: "xml",
864
- nodes: [declaration$3(), rootRels]
864
+ nodes: [declaration$4(), rootRels]
865
865
  },
866
866
  "word/document.xml": {
867
867
  kind: "xml",
868
- nodes: [declaration$3(), document]
868
+ nodes: [declaration$4(), document]
869
869
  },
870
870
  "word/_rels/document.xml.rels": {
871
871
  kind: "xml",
872
- nodes: [declaration$3(), documentRels]
872
+ nodes: [declaration$4(), documentRels]
873
873
  },
874
874
  "word/styles.xml": {
875
875
  kind: "xml",
876
- nodes: [declaration$3(), styles]
876
+ nodes: [declaration$4(), styles]
877
877
  }
878
878
  } };
879
879
  }
@@ -1164,7 +1164,7 @@ const SLIDE_LAYOUT_REL_TYPE = "http://schemas.openxmlformats.org/officeDocument/
1164
1164
  const THEME_REL_TYPE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme";
1165
1165
  const NOTES_MASTER_REL_TYPE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/notesMaster";
1166
1166
  const MIN_MASTER_OR_LAYOUT_ID = 2147483648;
1167
- function declaration$2() {
1167
+ function declaration$3() {
1168
1168
  return {
1169
1169
  type: "declaration",
1170
1170
  attributes: [
@@ -1314,7 +1314,7 @@ function ensureNotesMaster(pkg) {
1314
1314
  });
1315
1315
  pkg.parts[NOTES_MASTER_PART_PATH] = {
1316
1316
  kind: "xml",
1317
- nodes: [declaration$2(), buildNotesMaster()]
1317
+ nodes: [declaration$3(), buildNotesMaster()]
1318
1318
  };
1319
1319
  ensureContentTypeOverride(pkg, NOTES_MASTER_PART_PATH, NOTES_MASTER_CONTENT_TYPE);
1320
1320
  const presentationToNotesMasterTarget = buildRelativeTarget(PRESENTATION_PART_PATH$1, NOTES_MASTER_PART_PATH);
@@ -1353,15 +1353,15 @@ function createEmptyPptxPackage() {
1353
1353
  const pkg = { parts: {
1354
1354
  "[Content_Types].xml": {
1355
1355
  kind: "xml",
1356
- nodes: [declaration$2(), contentTypes]
1356
+ nodes: [declaration$3(), contentTypes]
1357
1357
  },
1358
1358
  "_rels/.rels": {
1359
1359
  kind: "xml",
1360
- nodes: [declaration$2(), rootRels]
1360
+ nodes: [declaration$3(), rootRels]
1361
1361
  },
1362
1362
  [PRESENTATION_PART_PATH$1]: {
1363
1363
  kind: "xml",
1364
- nodes: [declaration$2(), el("p:presentation", {
1364
+ nodes: [declaration$3(), el("p:presentation", {
1365
1365
  "xmlns:p": PML_NS,
1366
1366
  "xmlns:r": R_NS
1367
1367
  })]
@@ -1374,7 +1374,7 @@ function createEmptyPptxPackage() {
1374
1374
  });
1375
1375
  pkg.parts[SLIDE_LAYOUT_PART_PATH] = {
1376
1376
  kind: "xml",
1377
- nodes: [declaration$2(), buildSlideLayout()]
1377
+ nodes: [declaration$3(), buildSlideLayout()]
1378
1378
  };
1379
1379
  ensureContentTypeOverride(pkg, SLIDE_LAYOUT_PART_PATH, SLIDE_LAYOUT_CONTENT_TYPE);
1380
1380
  const masterToLayoutTarget = buildRelativeTarget(SLIDE_MASTER_PART_PATH, SLIDE_LAYOUT_PART_PATH);
@@ -1389,12 +1389,12 @@ function createEmptyPptxPackage() {
1389
1389
  });
1390
1390
  pkg.parts[SLIDE_MASTER_PART_PATH] = {
1391
1391
  kind: "xml",
1392
- nodes: [declaration$2(), buildSlideMaster(masterToLayoutRelId)]
1392
+ nodes: [declaration$3(), buildSlideMaster(masterToLayoutRelId)]
1393
1393
  };
1394
1394
  ensureContentTypeOverride(pkg, SLIDE_MASTER_PART_PATH, SLIDE_MASTER_CONTENT_TYPE);
1395
1395
  pkg.parts[THEME_PART_PATH] = {
1396
1396
  kind: "xml",
1397
- nodes: [declaration$2(), buildTheme()]
1397
+ nodes: [declaration$3(), buildTheme()]
1398
1398
  };
1399
1399
  ensureContentTypeOverride(pkg, THEME_PART_PATH, THEME_CONTENT_TYPE);
1400
1400
  const presentationToMasterTarget = buildRelativeTarget(PRESENTATION_PART_PATH$1, SLIDE_MASTER_PART_PATH);
@@ -1419,7 +1419,7 @@ function createEmptyPptxPackage() {
1419
1419
  }
1420
1420
  //#endregion
1421
1421
  //#region src/edit/pptx/shape.ts
1422
- function directChild$6(parent, tag) {
1422
+ function directChild$7(parent, tag) {
1423
1423
  for (const child of parent.children) if (child.type === "element" && child.tag === tag) return child;
1424
1424
  }
1425
1425
  function parseEmuAttr(element, name) {
@@ -1440,7 +1440,7 @@ var PptxShape = class {
1440
1440
  }
1441
1441
  spPrElement(create) {
1442
1442
  const node = this.live();
1443
- const existing = directChild$6(node, "p:spPr");
1443
+ const existing = directChild$7(node, "p:spPr");
1444
1444
  if (existing !== void 0 || !create) return existing;
1445
1445
  const created = el("p:spPr");
1446
1446
  node.children.push(created);
@@ -1448,10 +1448,10 @@ var PptxShape = class {
1448
1448
  }
1449
1449
  get frame() {
1450
1450
  const spPr = this.spPrElement(false);
1451
- const xfrm = spPr === void 0 ? void 0 : directChild$6(spPr, "a:xfrm");
1451
+ const xfrm = spPr === void 0 ? void 0 : directChild$7(spPr, "a:xfrm");
1452
1452
  if (xfrm === void 0) return;
1453
- const off = directChild$6(xfrm, "a:off");
1454
- const ext = directChild$6(xfrm, "a:ext");
1453
+ const off = directChild$7(xfrm, "a:off");
1454
+ const ext = directChild$7(xfrm, "a:ext");
1455
1455
  if (off === void 0 || ext === void 0) return;
1456
1456
  const x = parseEmuAttr(off, "x");
1457
1457
  const y = parseEmuAttr(off, "y");
@@ -1467,7 +1467,7 @@ var PptxShape = class {
1467
1467
  }
1468
1468
  set frame(value) {
1469
1469
  const spPr = this.spPrElement(true);
1470
- let xfrm = directChild$6(spPr, "a:xfrm");
1470
+ let xfrm = directChild$7(spPr, "a:xfrm");
1471
1471
  if (xfrm === void 0) {
1472
1472
  xfrm = el("a:xfrm");
1473
1473
  spPr.children.unshift(xfrm);
@@ -1481,12 +1481,12 @@ var PptxShape = class {
1481
1481
  })];
1482
1482
  }
1483
1483
  get text() {
1484
- const txBody = directChild$6(this.live(), "p:txBody");
1484
+ const txBody = directChild$7(this.live(), "p:txBody");
1485
1485
  return txBody === void 0 ? "" : textContent$1(txBody);
1486
1486
  }
1487
1487
  set text(value) {
1488
1488
  const node = this.live();
1489
- let txBody = directChild$6(node, "p:txBody");
1489
+ let txBody = directChild$7(node, "p:txBody");
1490
1490
  if (txBody === void 0) {
1491
1491
  txBody = el("p:txBody", {}, [el("a:bodyPr"), el("a:lstStyle")]);
1492
1492
  node.children.push(txBody);
@@ -1497,7 +1497,7 @@ var PptxShape = class {
1497
1497
  }
1498
1498
  setParagraphs(paragraphs) {
1499
1499
  const node = this.live();
1500
- let txBody = directChild$6(node, "p:txBody");
1500
+ let txBody = directChild$7(node, "p:txBody");
1501
1501
  if (txBody === void 0) {
1502
1502
  txBody = el("p:txBody", {}, [el("a:bodyPr"), el("a:lstStyle")]);
1503
1503
  node.children.push(txBody);
@@ -1608,12 +1608,12 @@ function insertPictureShapeMedia(context, slideRoot, frame, image) {
1608
1608
  }
1609
1609
  //#endregion
1610
1610
  //#region src/edit/pptx/slide.ts
1611
- function directChild$5(parent, tag) {
1611
+ function directChild$6(parent, tag) {
1612
1612
  for (const child of parent.children) if (child.type === "element" && child.tag === tag) return child;
1613
1613
  }
1614
1614
  function findSpTree(slideRoot) {
1615
- const cSld = directChild$5(slideRoot, "p:cSld");
1616
- const spTree = cSld === void 0 ? void 0 : directChild$5(cSld, "p:spTree");
1615
+ const cSld = directChild$6(slideRoot, "p:cSld");
1616
+ const spTree = cSld === void 0 ? void 0 : directChild$6(cSld, "p:spTree");
1617
1617
  if (spTree === void 0) throw new Error("slide has no p:cSld/p:spTree element");
1618
1618
  return spTree;
1619
1619
  }
@@ -1745,7 +1745,7 @@ const PRESENTATION_PART_PATH = "ppt/presentation.xml";
1745
1745
  const MEDIA_DIR = "ppt/media";
1746
1746
  const SLIDE_CONTENT_TYPE = "application/vnd.openxmlformats-officedocument.presentationml.slide+xml";
1747
1747
  const SLIDE_RELATIONSHIP_TYPE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/slide";
1748
- function directChild$4(parent, tag) {
1748
+ function directChild$5(parent, tag) {
1749
1749
  for (const child of parent.children) if (child.type === "element" && child.tag === tag) return child;
1750
1750
  }
1751
1751
  function attrValue(element, name) {
@@ -1757,12 +1757,12 @@ function findPresentationRoot(pkg) {
1757
1757
  return root;
1758
1758
  }
1759
1759
  function findSldIdLst(presentationRoot) {
1760
- const sldIdLst = directChild$4(presentationRoot, "p:sldIdLst");
1760
+ const sldIdLst = directChild$5(presentationRoot, "p:sldIdLst");
1761
1761
  if (sldIdLst === void 0) throw new Error(`${PRESENTATION_PART_PATH} has no p:sldIdLst element`);
1762
1762
  return sldIdLst;
1763
1763
  }
1764
1764
  function findSldSz(presentationRoot) {
1765
- const sldSz = directChild$4(presentationRoot, "p:sldSz");
1765
+ const sldSz = directChild$5(presentationRoot, "p:sldSz");
1766
1766
  if (sldSz === void 0) throw new Error(`${PRESENTATION_PART_PATH} has no p:sldSz element`);
1767
1767
  return sldSz;
1768
1768
  }
@@ -1961,12 +1961,12 @@ function appendShape$1(slide, shape) {
1961
1961
  }
1962
1962
  //#endregion
1963
1963
  //#region src/edit/odt/automatic-styles.ts
1964
- const CONTENT_PART_PATH$2 = "content.xml";
1964
+ const CONTENT_PART_PATH$3 = "content.xml";
1965
1965
  function ensureAutomaticStyles(pkg) {
1966
- const part = pkg.parts[CONTENT_PART_PATH$2];
1967
- if (part?.kind !== "xml") throw new Error(`ensureAutomaticStyles: package has no ${CONTENT_PART_PATH$2} part`);
1966
+ const part = pkg.parts[CONTENT_PART_PATH$3];
1967
+ if (part?.kind !== "xml") throw new Error(`ensureAutomaticStyles: package has no ${CONTENT_PART_PATH$3} part`);
1968
1968
  const root = part.nodes.find((n) => n.type === "element");
1969
- if (root === void 0) throw new Error(`ensureAutomaticStyles: ${CONTENT_PART_PATH$2} has no root element`);
1969
+ if (root === void 0) throw new Error(`ensureAutomaticStyles: ${CONTENT_PART_PATH$3} has no root element`);
1970
1970
  for (const child of root.children) if (child.type === "element" && child.tag === "office:automatic-styles") return child;
1971
1971
  const created = el("office:automatic-styles");
1972
1972
  const insertBeforeTags = /* @__PURE__ */ new Set([
@@ -2060,7 +2060,7 @@ function applyStyleChange(pkg, element, family, change) {
2060
2060
  ...readCurrentStyleProperties(pkg, element, family),
2061
2061
  ...change
2062
2062
  };
2063
- const name = StyleRegistry.forPart(pkg, CONTENT_PART_PATH$2).intern({
2063
+ const name = StyleRegistry.forPart(pkg, CONTENT_PART_PATH$3).intern({
2064
2064
  family,
2065
2065
  properties: merged
2066
2066
  });
@@ -2291,7 +2291,7 @@ function buildList(pkg) {
2291
2291
  }
2292
2292
  //#endregion
2293
2293
  //#region src/edit/odt/scaffold.ts
2294
- const CONTENT_NS_PREFIXES$1 = [
2294
+ const CONTENT_NS_PREFIXES$2 = [
2295
2295
  "office",
2296
2296
  "style",
2297
2297
  "text",
@@ -2301,7 +2301,7 @@ const CONTENT_NS_PREFIXES$1 = [
2301
2301
  "svg",
2302
2302
  "xlink"
2303
2303
  ];
2304
- const STYLES_NS_PREFIXES$1 = [
2304
+ const STYLES_NS_PREFIXES$2 = [
2305
2305
  "office",
2306
2306
  "style",
2307
2307
  "text",
@@ -2311,16 +2311,16 @@ const STYLES_NS_PREFIXES$1 = [
2311
2311
  "svg",
2312
2312
  "xlink"
2313
2313
  ];
2314
- const META_NS_PREFIXES$1 = [
2314
+ const META_NS_PREFIXES$2 = [
2315
2315
  "office",
2316
2316
  "meta",
2317
2317
  "dc"
2318
2318
  ];
2319
- const ODF_VERSION$1 = "1.3";
2320
- const PAGE_LAYOUT_NAME$1 = "PM1";
2321
- const MASTER_PAGE_NAME$1 = "Standard";
2319
+ const ODF_VERSION$2 = "1.3";
2320
+ const PAGE_LAYOUT_NAME$2 = "PM1";
2321
+ const MASTER_PAGE_NAME$2 = "Standard";
2322
2322
  const DEFAULT_MARGIN_PT = 72;
2323
- function declaration$1() {
2323
+ function declaration$2() {
2324
2324
  return {
2325
2325
  type: "declaration",
2326
2326
  attributes: [
@@ -2339,8 +2339,8 @@ function declaration$1() {
2339
2339
  ]
2340
2340
  };
2341
2341
  }
2342
- function buildPageLayout$1() {
2343
- return el("style:page-layout", { "style:name": PAGE_LAYOUT_NAME$1 }, [el("style:page-layout-properties", {
2342
+ function buildPageLayout$2() {
2343
+ return el("style:page-layout", { "style:name": PAGE_LAYOUT_NAME$2 }, [el("style:page-layout-properties", {
2344
2344
  "fo:page-width": `${PAGE_SIZE_LETTER.widthPt}pt`,
2345
2345
  "fo:page-height": `${PAGE_SIZE_LETTER.heightPt}pt`,
2346
2346
  "fo:margin-top": `${DEFAULT_MARGIN_PT}pt`,
@@ -2349,44 +2349,44 @@ function buildPageLayout$1() {
2349
2349
  "fo:margin-left": `${DEFAULT_MARGIN_PT}pt`
2350
2350
  })]);
2351
2351
  }
2352
- function buildStylesXml$1() {
2352
+ function buildStylesXml$2() {
2353
2353
  return el("office:document-styles", {
2354
- ...xmlnsAttributes([...STYLES_NS_PREFIXES$1]),
2355
- "office:version": ODF_VERSION$1
2354
+ ...xmlnsAttributes([...STYLES_NS_PREFIXES$2]),
2355
+ "office:version": ODF_VERSION$2
2356
2356
  }, [
2357
2357
  el("office:styles"),
2358
- el("office:automatic-styles", {}, [buildPageLayout$1()]),
2358
+ el("office:automatic-styles", {}, [buildPageLayout$2()]),
2359
2359
  el("office:master-styles", {}, [el("style:master-page", {
2360
- "style:name": MASTER_PAGE_NAME$1,
2361
- "style:page-layout-name": PAGE_LAYOUT_NAME$1
2360
+ "style:name": MASTER_PAGE_NAME$2,
2361
+ "style:page-layout-name": PAGE_LAYOUT_NAME$2
2362
2362
  })])
2363
2363
  ]);
2364
2364
  }
2365
- function buildContentXml$1() {
2365
+ function buildContentXml$2() {
2366
2366
  return el("office:document-content", {
2367
- ...xmlnsAttributes([...CONTENT_NS_PREFIXES$1]),
2368
- "office:version": ODF_VERSION$1
2367
+ ...xmlnsAttributes([...CONTENT_NS_PREFIXES$2]),
2368
+ "office:version": ODF_VERSION$2
2369
2369
  }, [el("office:automatic-styles"), el("office:body", {}, [el("office:text")])]);
2370
2370
  }
2371
- function buildMetaXml$1() {
2371
+ function buildMetaXml$2() {
2372
2372
  return el("office:document-meta", {
2373
- ...xmlnsAttributes([...META_NS_PREFIXES$1]),
2374
- "office:version": ODF_VERSION$1
2373
+ ...xmlnsAttributes([...META_NS_PREFIXES$2]),
2374
+ "office:version": ODF_VERSION$2
2375
2375
  }, [el("office:meta")]);
2376
2376
  }
2377
2377
  function createEmptyOdtPackage() {
2378
2378
  const pkg = { parts: {
2379
2379
  "content.xml": {
2380
2380
  kind: "xml",
2381
- nodes: [declaration$1(), buildContentXml$1()]
2381
+ nodes: [declaration$2(), buildContentXml$2()]
2382
2382
  },
2383
2383
  "styles.xml": {
2384
2384
  kind: "xml",
2385
- nodes: [declaration$1(), buildStylesXml$1()]
2385
+ nodes: [declaration$2(), buildStylesXml$2()]
2386
2386
  },
2387
2387
  "meta.xml": {
2388
2388
  kind: "xml",
2389
- nodes: [declaration$1(), buildMetaXml$1()]
2389
+ nodes: [declaration$2(), buildMetaXml$2()]
2390
2390
  }
2391
2391
  } };
2392
2392
  setDocumentMediaType(pkg, ODF_MEDIA_TYPES.odt);
@@ -2507,20 +2507,20 @@ function buildTable(pkg, init) {
2507
2507
  }
2508
2508
  //#endregion
2509
2509
  //#region src/edit/odt/editor.ts
2510
- const CONTENT_PART_PATH$1 = "content.xml";
2510
+ const CONTENT_PART_PATH$2 = "content.xml";
2511
2511
  function findContentRoot(pkg) {
2512
- const part = pkg.parts[CONTENT_PART_PATH$1];
2512
+ const part = pkg.parts[CONTENT_PART_PATH$2];
2513
2513
  const root = part?.kind === "xml" ? part.nodes.find((n) => n.type === "element") : void 0;
2514
- if (root === void 0) throw new Error(`package has no root element at ${CONTENT_PART_PATH$1}`);
2514
+ if (root === void 0) throw new Error(`package has no root element at ${CONTENT_PART_PATH$2}`);
2515
2515
  return root;
2516
2516
  }
2517
- function directChild$3(parent, tag) {
2517
+ function directChild$4(parent, tag) {
2518
2518
  for (const child of parent.children) if (child.type === "element" && child.tag === tag) return child;
2519
2519
  }
2520
2520
  function findOfficeText(contentRoot) {
2521
- const body = directChild$3(contentRoot, "office:body");
2522
- const text = body === void 0 ? void 0 : directChild$3(body, "office:text");
2523
- if (text === void 0) throw new Error(`${CONTENT_PART_PATH$1} has no office:body/office:text element`);
2521
+ const body = directChild$4(contentRoot, "office:body");
2522
+ const text = body === void 0 ? void 0 : directChild$4(body, "office:text");
2523
+ if (text === void 0) throw new Error(`${CONTENT_PART_PATH$2} has no office:body/office:text element`);
2524
2524
  return text;
2525
2525
  }
2526
2526
  var OdtBodyImpl = class {
@@ -2652,7 +2652,7 @@ function appendBlock(body, block) {
2652
2652
  }
2653
2653
  //#endregion
2654
2654
  //#region src/edit/odp/scaffold.ts
2655
- const CONTENT_NS_PREFIXES = [
2655
+ const CONTENT_NS_PREFIXES$1 = [
2656
2656
  "office",
2657
2657
  "style",
2658
2658
  "text",
@@ -2663,7 +2663,7 @@ const CONTENT_NS_PREFIXES = [
2663
2663
  "svg",
2664
2664
  "xlink"
2665
2665
  ];
2666
- const STYLES_NS_PREFIXES = [
2666
+ const STYLES_NS_PREFIXES$1 = [
2667
2667
  "office",
2668
2668
  "style",
2669
2669
  "text",
@@ -2674,14 +2674,14 @@ const STYLES_NS_PREFIXES = [
2674
2674
  "svg",
2675
2675
  "xlink"
2676
2676
  ];
2677
- const META_NS_PREFIXES = [
2677
+ const META_NS_PREFIXES$1 = [
2678
2678
  "office",
2679
2679
  "meta",
2680
2680
  "dc"
2681
2681
  ];
2682
- const ODF_VERSION = "1.3";
2683
- const MASTER_PAGE_NAME = "Standard";
2684
- function declaration() {
2682
+ const ODF_VERSION$1 = "1.3";
2683
+ const MASTER_PAGE_NAME$1 = "Standard";
2684
+ function declaration$1() {
2685
2685
  return {
2686
2686
  type: "declaration",
2687
2687
  attributes: [
@@ -2700,50 +2700,50 @@ function declaration() {
2700
2700
  ]
2701
2701
  };
2702
2702
  }
2703
- function buildPageLayout() {
2703
+ function buildPageLayout$1() {
2704
2704
  return el("style:page-layout", { "style:name": "PM1" }, [el("style:page-layout-properties", {
2705
2705
  "fo:page-width": `${SLIDE_SIZE_WIDESCREEN.widthPt}pt`,
2706
2706
  "fo:page-height": `${SLIDE_SIZE_WIDESCREEN.heightPt}pt`
2707
2707
  })]);
2708
2708
  }
2709
- function buildStylesXml() {
2709
+ function buildStylesXml$1() {
2710
2710
  return el("office:document-styles", {
2711
- ...xmlnsAttributes([...STYLES_NS_PREFIXES]),
2712
- "office:version": ODF_VERSION
2711
+ ...xmlnsAttributes([...STYLES_NS_PREFIXES$1]),
2712
+ "office:version": ODF_VERSION$1
2713
2713
  }, [
2714
2714
  el("office:styles"),
2715
- el("office:automatic-styles", {}, [buildPageLayout()]),
2715
+ el("office:automatic-styles", {}, [buildPageLayout$1()]),
2716
2716
  el("office:master-styles", {}, [el("style:master-page", {
2717
- "style:name": MASTER_PAGE_NAME,
2717
+ "style:name": MASTER_PAGE_NAME$1,
2718
2718
  "style:page-layout-name": "PM1"
2719
2719
  })])
2720
2720
  ]);
2721
2721
  }
2722
- function buildContentXml() {
2722
+ function buildContentXml$1() {
2723
2723
  return el("office:document-content", {
2724
- ...xmlnsAttributes([...CONTENT_NS_PREFIXES]),
2725
- "office:version": ODF_VERSION
2724
+ ...xmlnsAttributes([...CONTENT_NS_PREFIXES$1]),
2725
+ "office:version": ODF_VERSION$1
2726
2726
  }, [el("office:automatic-styles"), el("office:body", {}, [el("office:presentation")])]);
2727
2727
  }
2728
- function buildMetaXml() {
2728
+ function buildMetaXml$1() {
2729
2729
  return el("office:document-meta", {
2730
- ...xmlnsAttributes([...META_NS_PREFIXES]),
2731
- "office:version": ODF_VERSION
2730
+ ...xmlnsAttributes([...META_NS_PREFIXES$1]),
2731
+ "office:version": ODF_VERSION$1
2732
2732
  }, [el("office:meta")]);
2733
2733
  }
2734
2734
  function createEmptyOdpPackage() {
2735
2735
  const pkg = { parts: {
2736
2736
  "content.xml": {
2737
2737
  kind: "xml",
2738
- nodes: [declaration(), buildContentXml()]
2738
+ nodes: [declaration$1(), buildContentXml$1()]
2739
2739
  },
2740
2740
  "styles.xml": {
2741
2741
  kind: "xml",
2742
- nodes: [declaration(), buildStylesXml()]
2742
+ nodes: [declaration$1(), buildStylesXml$1()]
2743
2743
  },
2744
2744
  "meta.xml": {
2745
2745
  kind: "xml",
2746
- nodes: [declaration(), buildMetaXml()]
2746
+ nodes: [declaration$1(), buildMetaXml$1()]
2747
2747
  }
2748
2748
  } };
2749
2749
  setDocumentMediaType(pkg, ODF_MEDIA_TYPES.odp);
@@ -2783,7 +2783,7 @@ function addImageMedia(pkg, imageBytes, format) {
2783
2783
  }
2784
2784
  //#endregion
2785
2785
  //#region src/edit/odp/shape.ts
2786
- function directChild$2(parent, tag) {
2786
+ function directChild$3(parent, tag) {
2787
2787
  for (const child of parent.children) if (child.type === "element" && child.tag === tag) return child;
2788
2788
  }
2789
2789
  function buildTransformAttr(frame, rotationDeg) {
@@ -2851,7 +2851,7 @@ var OdpShape = class {
2851
2851
  }
2852
2852
  textBox(create) {
2853
2853
  const node = this.live();
2854
- const existing = directChild$2(node, "draw:text-box");
2854
+ const existing = directChild$3(node, "draw:text-box");
2855
2855
  if (existing !== void 0 || !create) return existing;
2856
2856
  const created = el("draw:text-box");
2857
2857
  node.children.push(created);
@@ -2912,7 +2912,7 @@ function insertImageFrameMedia(context, frame, image) {
2912
2912
  }
2913
2913
  //#endregion
2914
2914
  //#region src/edit/odp/slide.ts
2915
- function directChild$1(parent, tag) {
2915
+ function directChild$2(parent, tag) {
2916
2916
  for (const child of parent.children) if (child.type === "element" && child.tag === tag) return child;
2917
2917
  }
2918
2918
  const NOTES_FRAME_X_PT = 20;
@@ -2961,13 +2961,13 @@ var OdpSlide = class {
2961
2961
  return new OdpShape(node.children, frameElement, this.context.pkg);
2962
2962
  }
2963
2963
  get notes() {
2964
- const notesElement = directChild$1(this.live(), "presentation:notes");
2964
+ const notesElement = directChild$2(this.live(), "presentation:notes");
2965
2965
  if (notesElement === void 0) return "";
2966
2966
  return elementsWithTag$1(notesElement.children, "text:p").map((p) => decodeOdfText$1(p.children)).join("\n");
2967
2967
  }
2968
2968
  set notes(value) {
2969
2969
  const node = this.live();
2970
- const existing = directChild$1(node, "presentation:notes");
2970
+ const existing = directChild$2(node, "presentation:notes");
2971
2971
  const notesElement = buildNotesElement(this.context.pkg, value);
2972
2972
  if (existing === void 0) node.children.push(notesElement);
2973
2973
  else existing.children = notesElement.children;
@@ -2979,26 +2979,26 @@ var OdpSlide = class {
2979
2979
  };
2980
2980
  //#endregion
2981
2981
  //#region src/edit/odp/editor.ts
2982
- const CONTENT_PART_PATH = "content.xml";
2982
+ const CONTENT_PART_PATH$1 = "content.xml";
2983
2983
  const STYLES_PART_PATH = "styles.xml";
2984
- function directChild(parent, tag) {
2984
+ function directChild$1(parent, tag) {
2985
2985
  for (const child of parent.children) if (child.type === "element" && child.tag === tag) return child;
2986
2986
  }
2987
- function findRoot(pkg, partPath) {
2987
+ function findRoot$1(pkg, partPath) {
2988
2988
  const part = pkg.parts[partPath];
2989
2989
  const root = part?.kind === "xml" ? part.nodes.find((n) => n.type === "element") : void 0;
2990
2990
  if (root === void 0) throw new Error(`package has no root element at ${partPath}`);
2991
2991
  return root;
2992
2992
  }
2993
2993
  function findOfficePresentation(pkg) {
2994
- const body = directChild(findRoot(pkg, CONTENT_PART_PATH), "office:body");
2995
- const presentation = body === void 0 ? void 0 : directChild(body, "office:presentation");
2996
- if (presentation === void 0) throw new Error(`${CONTENT_PART_PATH} has no office:body/office:presentation element`);
2994
+ const body = directChild$1(findRoot$1(pkg, CONTENT_PART_PATH$1), "office:body");
2995
+ const presentation = body === void 0 ? void 0 : directChild$1(body, "office:presentation");
2996
+ if (presentation === void 0) throw new Error(`${CONTENT_PART_PATH$1} has no office:body/office:presentation element`);
2997
2997
  return presentation;
2998
2998
  }
2999
2999
  function findPageLayoutProperties(pkg) {
3000
- const pageLayout = directChild(findRoot(pkg, STYLES_PART_PATH), "office:automatic-styles")?.children.find((c) => c.type === "element" && c.tag === "style:page-layout" && attr$1(c, "style:name") === "PM1");
3001
- const properties = pageLayout === void 0 ? void 0 : directChild(pageLayout, "style:page-layout-properties");
3000
+ const pageLayout = directChild$1(findRoot$1(pkg, STYLES_PART_PATH), "office:automatic-styles")?.children.find((c) => c.type === "element" && c.tag === "style:page-layout" && attr$1(c, "style:name") === "PM1");
3001
+ const properties = pageLayout === void 0 ? void 0 : directChild$1(pageLayout, "style:page-layout-properties");
3002
3002
  if (properties === void 0) throw new Error(`${STYLES_PART_PATH} has no style:page-layout[style:name="PM1"]/style:page-layout-properties element`);
3003
3003
  return properties;
3004
3004
  }
@@ -3018,7 +3018,7 @@ var OdpEditor = class {
3018
3018
  }
3019
3019
  addSlide() {
3020
3020
  const presentation = findOfficePresentation(this.pkg);
3021
- const pageElement = el("draw:page", { "draw:master-page-name": MASTER_PAGE_NAME });
3021
+ const pageElement = el("draw:page", { "draw:master-page-name": MASTER_PAGE_NAME$1 });
3022
3022
  presentation.children.push(pageElement);
3023
3023
  const context = { pkg: this.pkg };
3024
3024
  return new OdpSlide(presentation.children, pageElement, context);
@@ -3119,6 +3119,539 @@ function appendShape(slide, shape) {
3119
3119
  }
3120
3120
  }
3121
3121
  //#endregion
3122
+ //#region src/edit/ods/scaffold.ts
3123
+ const CONTENT_NS_PREFIXES = [
3124
+ "office",
3125
+ "style",
3126
+ "text",
3127
+ "table",
3128
+ "fo"
3129
+ ];
3130
+ const STYLES_NS_PREFIXES = [
3131
+ "office",
3132
+ "style",
3133
+ "table",
3134
+ "fo"
3135
+ ];
3136
+ const META_NS_PREFIXES = [
3137
+ "office",
3138
+ "meta",
3139
+ "dc"
3140
+ ];
3141
+ const OF_NAMESPACE_ATTR = { "xmlns:of": "urn:oasis:names:tc:opendocument:xmlns:of:1.2" };
3142
+ const ODF_VERSION = "1.3";
3143
+ const MASTER_PAGE_NAME = "Standard";
3144
+ const SHEET_TABLE_STYLE_NAME = "OdsTable";
3145
+ const DEFAULT_SHEET_NAME = "Sheet1";
3146
+ const DEFAULT_MARGIN = "2cm";
3147
+ function declaration() {
3148
+ return {
3149
+ type: "declaration",
3150
+ attributes: [
3151
+ {
3152
+ name: "version",
3153
+ value: "1.0"
3154
+ },
3155
+ {
3156
+ name: "encoding",
3157
+ value: "UTF-8"
3158
+ },
3159
+ {
3160
+ name: "standalone",
3161
+ value: "yes"
3162
+ }
3163
+ ]
3164
+ };
3165
+ }
3166
+ function buildPageLayout() {
3167
+ return el("style:page-layout", { "style:name": "PM1" }, [el("style:page-layout-properties", {
3168
+ "fo:page-width": `${PAGE_SIZE_A4.widthPt}pt`,
3169
+ "fo:page-height": `${PAGE_SIZE_A4.heightPt}pt`,
3170
+ "fo:margin-top": DEFAULT_MARGIN,
3171
+ "fo:margin-right": DEFAULT_MARGIN,
3172
+ "fo:margin-bottom": DEFAULT_MARGIN,
3173
+ "fo:margin-left": DEFAULT_MARGIN
3174
+ })]);
3175
+ }
3176
+ function buildStylesXml() {
3177
+ return el("office:document-styles", {
3178
+ ...xmlnsAttributes([...STYLES_NS_PREFIXES]),
3179
+ "office:version": ODF_VERSION
3180
+ }, [
3181
+ el("office:styles"),
3182
+ el("office:automatic-styles", {}, [buildPageLayout()]),
3183
+ el("office:master-styles", {}, [el("style:master-page", {
3184
+ "style:name": MASTER_PAGE_NAME,
3185
+ "style:page-layout-name": "PM1"
3186
+ })])
3187
+ ]);
3188
+ }
3189
+ function buildSheetTableStyle() {
3190
+ return el("style:style", {
3191
+ "style:name": SHEET_TABLE_STYLE_NAME,
3192
+ "style:family": "table",
3193
+ "style:master-page-name": MASTER_PAGE_NAME
3194
+ });
3195
+ }
3196
+ function buildCalculationSettings() {
3197
+ return el("table:calculation-settings", {
3198
+ "table:automatic-find-labels": "false",
3199
+ "table:use-regular-expressions": "false",
3200
+ "table:use-wildcards": "true",
3201
+ "table:null-year": "1950"
3202
+ });
3203
+ }
3204
+ function buildContentXml() {
3205
+ const table = el("table:table", {
3206
+ "table:name": DEFAULT_SHEET_NAME,
3207
+ "table:style-name": SHEET_TABLE_STYLE_NAME
3208
+ });
3209
+ return el("office:document-content", {
3210
+ ...xmlnsAttributes([...CONTENT_NS_PREFIXES]),
3211
+ ...OF_NAMESPACE_ATTR,
3212
+ "office:version": ODF_VERSION
3213
+ }, [el("office:automatic-styles", {}, [buildSheetTableStyle()]), el("office:body", {}, [el("office:spreadsheet", {}, [buildCalculationSettings(), table])])]);
3214
+ }
3215
+ function buildMetaXml() {
3216
+ return el("office:document-meta", {
3217
+ ...xmlnsAttributes([...META_NS_PREFIXES]),
3218
+ "office:version": ODF_VERSION
3219
+ }, [el("office:meta")]);
3220
+ }
3221
+ function createEmptyOdsPackage() {
3222
+ const pkg = { parts: {
3223
+ "content.xml": {
3224
+ kind: "xml",
3225
+ nodes: [declaration(), buildContentXml()]
3226
+ },
3227
+ "styles.xml": {
3228
+ kind: "xml",
3229
+ nodes: [declaration(), buildStylesXml()]
3230
+ },
3231
+ "meta.xml": {
3232
+ kind: "xml",
3233
+ nodes: [declaration(), buildMetaXml()]
3234
+ }
3235
+ } };
3236
+ setDocumentMediaType(pkg, ODF_MEDIA_TYPES.ods);
3237
+ syncManifest(pkg);
3238
+ return pkg;
3239
+ }
3240
+ //#endregion
3241
+ //#region src/edit/ods/address.ts
3242
+ const ROW_TAG = "table:table-row";
3243
+ const COLUMN_TAG = "table:table-column";
3244
+ const CELL_TAG = "table:table-cell";
3245
+ const COVERED_CELL_TAG = "table:covered-table-cell";
3246
+ const ROW_REPEAT_ATTR = "table:number-rows-repeated";
3247
+ const COLUMN_REPEAT_ATTR = "table:number-columns-repeated";
3248
+ function isElementWithTag(tag) {
3249
+ return (node) => node.type === "element" && node.tag === tag;
3250
+ }
3251
+ function isCellOrCoveredCell(node) {
3252
+ return node.type === "element" && (node.tag === "table:table-cell" || node.tag === "table:covered-table-cell");
3253
+ }
3254
+ function validateIndex(value, label) {
3255
+ if (!Number.isInteger(value) || value < 0) throw new Error(`${label} must be a non-negative integer, got ${value}`);
3256
+ }
3257
+ function readRepeatCount(node, attrName) {
3258
+ const raw = node.attributes.find((attribute) => attribute.name === attrName)?.value;
3259
+ if (raw === void 0) return 1;
3260
+ const parsed = Number.parseInt(raw, 10);
3261
+ return Number.isInteger(parsed) && parsed > 0 ? parsed : 1;
3262
+ }
3263
+ function withRepeatCount(node, attrName, count) {
3264
+ const clone = structuredClone(node);
3265
+ clone.attributes = clone.attributes.filter((attribute) => attribute.name !== attrName);
3266
+ if (count > 1) clone.attributes.push({
3267
+ name: attrName,
3268
+ value: String(count)
3269
+ });
3270
+ return clone;
3271
+ }
3272
+ function replaceRun(children, isMember, targetIndex, repeatAttr, buildEmpty) {
3273
+ validateIndex(targetIndex, "targetIndex");
3274
+ const members = [];
3275
+ children.forEach((node, position) => {
3276
+ if (isMember(node)) members.push({
3277
+ node,
3278
+ position
3279
+ });
3280
+ });
3281
+ let cursor = 0;
3282
+ for (const member of members) {
3283
+ const count = readRepeatCount(member.node, repeatAttr);
3284
+ if (targetIndex < cursor + count) {
3285
+ const offset = targetIndex - cursor;
3286
+ if (count === 1) return member.node;
3287
+ const before = offset > 0 ? withRepeatCount(member.node, repeatAttr, offset) : void 0;
3288
+ const target = withRepeatCount(member.node, repeatAttr, 1);
3289
+ const replacement = [
3290
+ before,
3291
+ target,
3292
+ count - offset - 1 > 0 ? withRepeatCount(member.node, repeatAttr, count - offset - 1) : void 0
3293
+ ].filter((candidate) => candidate !== void 0);
3294
+ children.splice(member.position, 1, ...replacement);
3295
+ return target;
3296
+ }
3297
+ cursor += count;
3298
+ }
3299
+ const gap = targetIndex - cursor;
3300
+ const lastMember = members[members.length - 1];
3301
+ const insertAt = lastMember === void 0 ? children.length : lastMember.position + 1;
3302
+ const toInsert = [];
3303
+ if (gap > 0) toInsert.push(withRepeatCount(buildEmpty(), repeatAttr, gap));
3304
+ const target = buildEmpty();
3305
+ toInsert.push(target);
3306
+ children.splice(insertAt, 0, ...toInsert);
3307
+ return target;
3308
+ }
3309
+ function ensureColumnCoverage(tableElement, minCount) {
3310
+ if (minCount <= 0) return;
3311
+ const columnMembers = [];
3312
+ tableElement.children.forEach((node, position) => {
3313
+ if (isElementWithTag("table:table-column")(node)) columnMembers.push({
3314
+ node,
3315
+ position
3316
+ });
3317
+ });
3318
+ const covered = columnMembers.reduce((sum, member) => sum + readRepeatCount(member.node, COLUMN_REPEAT_ATTR), 0);
3319
+ if (covered >= minCount) return;
3320
+ const additional = minCount - covered;
3321
+ const newColumn = withRepeatCount(el(COLUMN_TAG), COLUMN_REPEAT_ATTR, additional);
3322
+ const lastColumn = columnMembers[columnMembers.length - 1];
3323
+ if (lastColumn === void 0) {
3324
+ const firstRowPosition = tableElement.children.findIndex(isElementWithTag(ROW_TAG));
3325
+ const insertAt = firstRowPosition === -1 ? tableElement.children.length : firstRowPosition;
3326
+ tableElement.children.splice(insertAt, 0, newColumn);
3327
+ } else tableElement.children.splice(lastColumn.position + 1, 0, newColumn);
3328
+ }
3329
+ function resolveCellNode(tableElement, row, column) {
3330
+ validateIndex(row, "row");
3331
+ validateIndex(column, "column");
3332
+ ensureColumnCoverage(tableElement, column + 1);
3333
+ return replaceRun(replaceRun(tableElement.children, isElementWithTag(ROW_TAG), row, ROW_REPEAT_ATTR, () => el(ROW_TAG)).children, isCellOrCoveredCell, column, COLUMN_REPEAT_ATTR, () => el(CELL_TAG));
3334
+ }
3335
+ //#endregion
3336
+ //#region src/edit/ods/cell.ts
3337
+ const VALUE_TYPE_ATTR = "office:value-type";
3338
+ const VALUE_ATTR = "office:value";
3339
+ const BOOLEAN_VALUE_ATTR = "office:boolean-value";
3340
+ const DATE_VALUE_ATTR = "office:date-value";
3341
+ const TIME_VALUE_ATTR = "office:time-value";
3342
+ const STRING_VALUE_ATTR = "office:string-value";
3343
+ const CURRENCY_ATTR = "office:currency";
3344
+ const FORMULA_ATTR = "table:formula";
3345
+ const VALUE_ATTRS = [
3346
+ VALUE_TYPE_ATTR,
3347
+ VALUE_ATTR,
3348
+ BOOLEAN_VALUE_ATTR,
3349
+ DATE_VALUE_ATTR,
3350
+ TIME_VALUE_ATTR,
3351
+ STRING_VALUE_ATTR,
3352
+ CURRENCY_ATTR
3353
+ ];
3354
+ function parseNumber(raw) {
3355
+ if (raw === void 0) return;
3356
+ const value = Number(raw);
3357
+ return Number.isNaN(value) ? void 0 : value;
3358
+ }
3359
+ var OdsCell = class {
3360
+ node;
3361
+ pkg;
3362
+ constructor(node, pkg) {
3363
+ this.node = node;
3364
+ this.pkg = pkg;
3365
+ }
3366
+ get value() {
3367
+ const valueType = attr$1(this.node, VALUE_TYPE_ATTR);
3368
+ const displayText = this.displayText;
3369
+ switch (valueType) {
3370
+ case "float": {
3371
+ const value = parseNumber(attr$1(this.node, VALUE_ATTR));
3372
+ return value === void 0 ? {
3373
+ kind: "string",
3374
+ value: displayText
3375
+ } : {
3376
+ kind: "number",
3377
+ value
3378
+ };
3379
+ }
3380
+ case "percentage": {
3381
+ const value = parseNumber(attr$1(this.node, VALUE_ATTR));
3382
+ return value === void 0 ? {
3383
+ kind: "string",
3384
+ value: displayText
3385
+ } : {
3386
+ kind: "percentage",
3387
+ value
3388
+ };
3389
+ }
3390
+ case "currency": {
3391
+ const value = parseNumber(attr$1(this.node, VALUE_ATTR));
3392
+ if (value === void 0) return {
3393
+ kind: "string",
3394
+ value: displayText
3395
+ };
3396
+ const currency = attr$1(this.node, CURRENCY_ATTR);
3397
+ return currency === void 0 ? {
3398
+ kind: "currency",
3399
+ value
3400
+ } : {
3401
+ kind: "currency",
3402
+ value,
3403
+ currency
3404
+ };
3405
+ }
3406
+ case "boolean": {
3407
+ const raw = attr$1(this.node, BOOLEAN_VALUE_ATTR);
3408
+ return raw === void 0 ? {
3409
+ kind: "string",
3410
+ value: displayText
3411
+ } : {
3412
+ kind: "boolean",
3413
+ value: raw === "true"
3414
+ };
3415
+ }
3416
+ case "date": return {
3417
+ kind: "date",
3418
+ value: attr$1(this.node, DATE_VALUE_ATTR) ?? displayText
3419
+ };
3420
+ case "time": return {
3421
+ kind: "time",
3422
+ value: attr$1(this.node, TIME_VALUE_ATTR) ?? displayText
3423
+ };
3424
+ case "string": return {
3425
+ kind: "string",
3426
+ value: attr$1(this.node, STRING_VALUE_ATTR) ?? displayText
3427
+ };
3428
+ default: return { kind: "empty" };
3429
+ }
3430
+ }
3431
+ set value(value) {
3432
+ for (const name of VALUE_ATTRS) removeAttr(this.node, name);
3433
+ switch (value.kind) {
3434
+ case "number":
3435
+ setAttr(this.node, VALUE_TYPE_ATTR, "float");
3436
+ setAttr(this.node, VALUE_ATTR, String(value.value));
3437
+ this.displayText = String(value.value);
3438
+ break;
3439
+ case "percentage":
3440
+ setAttr(this.node, VALUE_TYPE_ATTR, "percentage");
3441
+ setAttr(this.node, VALUE_ATTR, String(value.value));
3442
+ this.displayText = `${value.value * 100}%`;
3443
+ break;
3444
+ case "currency":
3445
+ setAttr(this.node, VALUE_TYPE_ATTR, "currency");
3446
+ setAttr(this.node, VALUE_ATTR, String(value.value));
3447
+ if (value.currency !== void 0) setAttr(this.node, CURRENCY_ATTR, value.currency);
3448
+ this.displayText = value.currency === void 0 ? String(value.value) : `${value.value} ${value.currency}`;
3449
+ break;
3450
+ case "boolean":
3451
+ setAttr(this.node, VALUE_TYPE_ATTR, "boolean");
3452
+ setAttr(this.node, BOOLEAN_VALUE_ATTR, value.value ? "true" : "false");
3453
+ this.displayText = value.value ? "TRUE" : "FALSE";
3454
+ break;
3455
+ case "date":
3456
+ setAttr(this.node, VALUE_TYPE_ATTR, "date");
3457
+ setAttr(this.node, DATE_VALUE_ATTR, value.value);
3458
+ this.displayText = value.value;
3459
+ break;
3460
+ case "time":
3461
+ setAttr(this.node, VALUE_TYPE_ATTR, "time");
3462
+ setAttr(this.node, TIME_VALUE_ATTR, value.value);
3463
+ this.displayText = value.value;
3464
+ break;
3465
+ case "string":
3466
+ setAttr(this.node, VALUE_TYPE_ATTR, "string");
3467
+ setAttr(this.node, STRING_VALUE_ATTR, value.value);
3468
+ this.displayText = value.value;
3469
+ break;
3470
+ case "error":
3471
+ setAttr(this.node, VALUE_TYPE_ATTR, "string");
3472
+ setAttr(this.node, STRING_VALUE_ATTR, value.value);
3473
+ this.displayText = value.value;
3474
+ break;
3475
+ case "empty": this.displayText = "";
3476
+ }
3477
+ }
3478
+ get formula() {
3479
+ return attr$1(this.node, FORMULA_ATTR);
3480
+ }
3481
+ set formula(value) {
3482
+ if (value === void 0) {
3483
+ removeAttr(this.node, FORMULA_ATTR);
3484
+ return;
3485
+ }
3486
+ setAttr(this.node, FORMULA_ATTR, value);
3487
+ }
3488
+ get displayText() {
3489
+ return this.node.children.filter((child) => child.type === "element" && child.tag === "text:p").map((paragraph) => decodeOdfText$1(paragraph.children)).join("\n");
3490
+ }
3491
+ set displayText(value) {
3492
+ this.node.children = [el("text:p", {}, encodeOdfText(value))];
3493
+ }
3494
+ setStyledRuns(runs) {
3495
+ const textParagraph = el("text:p");
3496
+ this.node.children = [textParagraph];
3497
+ populateParagraph(new OdtParagraph(this.node.children, textParagraph, this.pkg), {
3498
+ kind: "paragraph",
3499
+ runs: [...runs]
3500
+ });
3501
+ }
3502
+ };
3503
+ //#endregion
3504
+ //#region src/edit/ods/sheet.ts
3505
+ const NAME_ATTR = "table:name";
3506
+ var OdsSheet = class {
3507
+ container;
3508
+ node;
3509
+ pkg;
3510
+ removed = false;
3511
+ constructor(container, node, pkg) {
3512
+ this.container = container;
3513
+ this.node = node;
3514
+ this.pkg = pkg;
3515
+ }
3516
+ live() {
3517
+ if (this.removed) throw new Error("this OdsSheet has been removed from the spreadsheet and can no longer be used");
3518
+ return this.node;
3519
+ }
3520
+ get name() {
3521
+ const value = attr$1(this.live(), NAME_ATTR);
3522
+ if (value === void 0) throw new Error("this table:table element has no table:name attribute");
3523
+ return value;
3524
+ }
3525
+ set name(value) {
3526
+ setAttr(this.live(), NAME_ATTR, value);
3527
+ }
3528
+ cell(row, column) {
3529
+ const node = resolveCellNode(this.live(), row, column);
3530
+ if (node.tag === "table:covered-table-cell") throw new Error(`cell (${row}, ${column}) is covered by a merged range -- address the merge's own anchor cell instead`);
3531
+ return new OdsCell(node, this.pkg);
3532
+ }
3533
+ cellAt(reference) {
3534
+ const parsed = parseCellReference(reference);
3535
+ if (parsed === void 0) throw new Error(`cellAt: "${reference}" is not a valid A1-style cell reference`);
3536
+ return this.cell(parsed.row, parsed.column);
3537
+ }
3538
+ mergeCells(startRow, startColumn, rowSpan, colSpan) {
3539
+ if (!Number.isInteger(rowSpan) || rowSpan < 1 || !Number.isInteger(colSpan) || colSpan < 1) throw new Error(`mergeCells: rowSpan and colSpan must be positive integers, got rowSpan=${rowSpan}, colSpan=${colSpan}`);
3540
+ const tableElement = this.live();
3541
+ const anchorNode = resolveCellNode(tableElement, startRow, startColumn);
3542
+ if (anchorNode.tag === "table:covered-table-cell") throw new Error(`mergeCells: (${startRow}, ${startColumn}) is already covered by another merged range`);
3543
+ if (rowSpan > 1) setAttr(anchorNode, "table:number-rows-spanned", String(rowSpan));
3544
+ if (colSpan > 1) setAttr(anchorNode, "table:number-columns-spanned", String(colSpan));
3545
+ for (let rowOffset = 0; rowOffset < rowSpan; rowOffset++) for (let columnOffset = 0; columnOffset < colSpan; columnOffset++) {
3546
+ if (rowOffset === 0 && columnOffset === 0) continue;
3547
+ const coveredNode = resolveCellNode(tableElement, startRow + rowOffset, startColumn + columnOffset);
3548
+ coveredNode.tag = COVERED_CELL_TAG;
3549
+ coveredNode.attributes = [];
3550
+ coveredNode.children = [];
3551
+ }
3552
+ return new OdsCell(anchorNode, this.pkg);
3553
+ }
3554
+ remove() {
3555
+ removeChild(this.container, this.live());
3556
+ this.removed = true;
3557
+ }
3558
+ };
3559
+ //#endregion
3560
+ //#region src/edit/ods/editor.ts
3561
+ const CONTENT_PART_PATH = "content.xml";
3562
+ function directChild(parent, tag) {
3563
+ for (const child of parent.children) if (child.type === "element" && child.tag === tag) return child;
3564
+ }
3565
+ function findRoot(pkg) {
3566
+ const part = pkg.parts[CONTENT_PART_PATH];
3567
+ const root = part?.kind === "xml" ? part.nodes.find((n) => n.type === "element") : void 0;
3568
+ if (root === void 0) throw new Error(`package has no root element at ${CONTENT_PART_PATH}`);
3569
+ return root;
3570
+ }
3571
+ function findOfficeSpreadsheet(pkg) {
3572
+ const body = directChild(findRoot(pkg), "office:body");
3573
+ const spreadsheet = body === void 0 ? void 0 : directChild(body, "office:spreadsheet");
3574
+ if (spreadsheet === void 0) throw new Error(`${CONTENT_PART_PATH} has no office:body/office:spreadsheet element`);
3575
+ return spreadsheet;
3576
+ }
3577
+ function ensureSheetTableStyleName(pkg) {
3578
+ const automaticStyles = ensureAutomaticStyles(pkg);
3579
+ if (automaticStyles.children.find((child) => child.type === "element" && child.tag === "style:style" && attr$1(child, "style:name") === "OdsTable") !== void 0) return SHEET_TABLE_STYLE_NAME;
3580
+ automaticStyles.children.push(el("style:style", {
3581
+ "style:name": SHEET_TABLE_STYLE_NAME,
3582
+ "style:family": "table",
3583
+ "style:master-page-name": MASTER_PAGE_NAME
3584
+ }));
3585
+ return SHEET_TABLE_STYLE_NAME;
3586
+ }
3587
+ var OdsEditor = class {
3588
+ pkg;
3589
+ constructor(pkg) {
3590
+ this.pkg = pkg;
3591
+ }
3592
+ sheets() {
3593
+ const spreadsheet = findOfficeSpreadsheet(this.pkg);
3594
+ const out = [];
3595
+ for (const child of spreadsheet.children) if (child.type === "element" && child.tag === "table:table") out.push(new OdsSheet(spreadsheet.children, child, this.pkg));
3596
+ return out;
3597
+ }
3598
+ sheet(name) {
3599
+ const found = this.sheets().find((candidate) => candidate.name === name);
3600
+ if (found === void 0) throw new Error(`no sheet named "${name}" exists in this spreadsheet`);
3601
+ return found;
3602
+ }
3603
+ addSheet(name) {
3604
+ const spreadsheet = findOfficeSpreadsheet(this.pkg);
3605
+ const tableElement = el("table:table", {
3606
+ "table:name": name,
3607
+ "table:style-name": ensureSheetTableStyleName(this.pkg)
3608
+ });
3609
+ spreadsheet.children.push(tableElement);
3610
+ return new OdsSheet(spreadsheet.children, tableElement, this.pkg);
3611
+ }
3612
+ removeSheetAt(index) {
3613
+ const spreadsheet = findOfficeSpreadsheet(this.pkg);
3614
+ const target = spreadsheet.children.filter((child) => child.type === "element" && child.tag === "table:table")[index];
3615
+ if (target === void 0) throw new Error(`sheet index ${index} does not exist`);
3616
+ const listIndex = spreadsheet.children.indexOf(target);
3617
+ spreadsheet.children.splice(listIndex, 1);
3618
+ }
3619
+ toPackage() {
3620
+ return this.pkg;
3621
+ }
3622
+ toBytes() {
3623
+ return encodePackage$2(this.pkg);
3624
+ }
3625
+ };
3626
+ function openOds(bytes) {
3627
+ return new OdsEditor(decodePackage$2(bytes));
3628
+ }
3629
+ function createOds() {
3630
+ return new OdsEditor(createEmptyOdsPackage());
3631
+ }
3632
+ //#endregion
3633
+ //#region src/edit/ods/content.ts
3634
+ function buildOdsPackage(content) {
3635
+ if (content.kind !== "spreadsheet") throw new Error("buildOdsPackage requires a spreadsheet ContentDocument");
3636
+ const editor = createOds();
3637
+ if (content.sheets.length > 0) editor.removeSheetAt(0);
3638
+ for (const sheet of content.sheets) {
3639
+ const odsSheet = editor.addSheet(sheet.name);
3640
+ for (const cell of sheet.cells) appendCell(odsSheet, cell);
3641
+ }
3642
+ return editor.toPackage();
3643
+ }
3644
+ function appendCell(odsSheet, cell) {
3645
+ const odsCell = odsSheet.cell(cell.row, cell.column);
3646
+ odsCell.value = cell.value;
3647
+ if (cell.formula !== void 0) odsCell.formula = cell.formula;
3648
+ if (cell.runs !== void 0 && cell.runs.length > 0) odsCell.setStyledRuns(cell.runs);
3649
+ else odsCell.displayText = cell.displayText;
3650
+ const rowSpan = cell.rowSpan ?? 1;
3651
+ const colSpan = cell.colSpan ?? 1;
3652
+ if (rowSpan > 1 || colSpan > 1) odsSheet.mergeCells(cell.row, cell.column, rowSpan, colSpan);
3653
+ }
3654
+ //#endregion
3122
3655
  //#region src/bytes/crc32.ts
3123
3656
  const CRC32_POLYNOMIAL = 3988292384;
3124
3657
  const BYTE_VALUES = 256;
@@ -9582,4 +10115,4 @@ function fixedClock(date) {
9582
10115
  return { now: () => date };
9583
10116
  }
9584
10117
  //#endregion
9585
- export { AttributeSchema, BinaryPartSchema, COLOR_BLACK, CONTENT_FORMAT_VERSION, CommentSchema, CompactPackageSchema, CompactPartSchema, CompactXmlNodeSchema, ContentBlockSchema, ContentCellValueSchema, ContentDocumentSchema, ContentImageBlockSchema, ContentPageBreakSchema, ContentParagraphSchema, ContentRunSchema, ContentSectionSchema, ContentShapeSchema, ContentSheetCellSchema, ContentSheetColumnSchema, ContentSheetPrintRangeSchema, ContentSheetPrintSettingsSchema, ContentSheetRepeatRangeSchema, ContentSheetRowSchema, ContentSheetSchema, ContentSlideSchema, ContentTableCellSchema, ContentTableRowSchema, ContentTableSchema, DEFAULT_LAYOUT_FONT, DefinedNameSchema, DocxBytesSchema, DocxEditor, DocxParagraph, DocxRun, DocxTable, DocxTableCell, DocxTableRow, LAYOUT_FORMAT_VERSION, NOOP_DIAGNOSTIC_SINK, OdgBytesSchema, OdpBytesSchema, OdpEditor, OdpShape, OdpSlide, OdsBytesSchema, OdtBytesSchema, OdtEditor, OdtList, OdtListItem, OdtParagraph, OdtRun, OdtTable, OdtTableCell, OdtTableRow, PAGE_SIZE_A4, PAGE_SIZE_LETTER, PackageSchema, PartSchema, PdfBytesSchema, PdfEncryptedError, PdfParseError, PptxBytesSchema, PptxEditor, PptxShape, PptxSlide, SLIDE_SIZE_STANDARD, SLIDE_SIZE_WIDESCREEN, XmlCdataSchema, XmlCommentSchema, XmlDeclarationSchema, XmlElementSchema, XmlNodeSchema, XmlPartSchema, XmlPiSchema, XmlTextSchema, attr, base64ToBytes, buildDocxPackage, buildOdpPackage, buildOdtPackage, buildPptxPackage, buildXml, bytesToBase64, childrenWithTag, compactCodec, compactPackageCodec, convertPresentationToLayout, convertSpreadsheetToLayout, convertWordprocessingToLayout, createDocx, createLocalDocumentConverter, createOdp, createOdt, createPptx, decodeCompactPackage, decodeEntities, decodePackage, docxPdfCodec, docxToPdf, elementsWithTag, encodeCompactPackage, encodePackage, fixedClock, flipY, fromCompact, isCompactXmlNode, isContentBlock, isXmlNode, odpPdfCodec, odpToPdf, odsToPdf, odtPdfCodec, odtToPdf, openDocx, openOdp, openOdt, openPptx, packageCodec, parsePackage, parseXml, pdfCodec, pdfToDocx, pdfToOdp, pdfToOdt, pdfToPptx, pptxPdfCodec, pptxToPdf, readDocxContent, readOdpContent, readOdsContent, readOdtContent, readPdf, readPptxContent, reconstructPresentation, reconstructWordprocessing, resolveRelationships, rgbHexToColor, rootElement, serializePackage, systemClock, textContent, throwIfAborted, toCompact, unzipPackage, walk, writePdf, xmlCodec, zipPackage };
10118
+ export { AttributeSchema, BinaryPartSchema, COLOR_BLACK, CONTENT_FORMAT_VERSION, CommentSchema, CompactPackageSchema, CompactPartSchema, CompactXmlNodeSchema, ContentBlockSchema, ContentCellValueSchema, ContentDocumentSchema, ContentImageBlockSchema, ContentPageBreakSchema, ContentParagraphSchema, ContentRunSchema, ContentSectionSchema, ContentShapeSchema, ContentSheetCellSchema, ContentSheetColumnSchema, ContentSheetPrintRangeSchema, ContentSheetPrintSettingsSchema, ContentSheetRepeatRangeSchema, ContentSheetRowSchema, ContentSheetSchema, ContentSlideSchema, ContentTableCellSchema, ContentTableRowSchema, ContentTableSchema, DEFAULT_LAYOUT_FONT, DefinedNameSchema, DocxBytesSchema, DocxEditor, DocxParagraph, DocxRun, DocxTable, DocxTableCell, DocxTableRow, LAYOUT_FORMAT_VERSION, NOOP_DIAGNOSTIC_SINK, OdgBytesSchema, OdpBytesSchema, OdpEditor, OdpShape, OdpSlide, OdsBytesSchema, OdsCell, OdsEditor, OdsSheet, OdtBytesSchema, OdtEditor, OdtList, OdtListItem, OdtParagraph, OdtRun, OdtTable, OdtTableCell, OdtTableRow, PAGE_SIZE_A4, PAGE_SIZE_LETTER, PackageSchema, PartSchema, PdfBytesSchema, PdfEncryptedError, PdfParseError, PptxBytesSchema, PptxEditor, PptxShape, PptxSlide, SLIDE_SIZE_STANDARD, SLIDE_SIZE_WIDESCREEN, XmlCdataSchema, XmlCommentSchema, XmlDeclarationSchema, XmlElementSchema, XmlNodeSchema, XmlPartSchema, XmlPiSchema, XmlTextSchema, attr, base64ToBytes, buildDocxPackage, buildOdpPackage, buildOdsPackage, buildOdtPackage, buildPptxPackage, buildXml, bytesToBase64, childrenWithTag, compactCodec, compactPackageCodec, convertPresentationToLayout, convertSpreadsheetToLayout, convertWordprocessingToLayout, createDocx, createLocalDocumentConverter, createOdp, createOds, createOdt, createPptx, decodeCompactPackage, decodeEntities, decodePackage, docxPdfCodec, docxToPdf, elementsWithTag, encodeCompactPackage, encodePackage, fixedClock, flipY, fromCompact, isCompactXmlNode, isContentBlock, isXmlNode, odpPdfCodec, odpToPdf, odsToPdf, odtPdfCodec, odtToPdf, openDocx, openOdp, openOds, openOdt, openPptx, packageCodec, parsePackage, parseXml, pdfCodec, pdfToDocx, pdfToOdp, pdfToOdt, pdfToPptx, pptxPdfCodec, pptxToPdf, readDocxContent, readOdpContent, readOdsContent, readOdtContent, readPdf, readPptxContent, reconstructPresentation, reconstructWordprocessing, resolveRelationships, rgbHexToColor, rootElement, serializePackage, systemClock, textContent, throwIfAborted, toCompact, unzipPackage, walk, writePdf, xmlCodec, zipPackage };