documents.js 1.47.0 → 1.49.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
- 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";
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, buildXlsxPackage, 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, readXlsxContent, 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, ContentDrawPageSchema, ContentDrawPageSchema as ContentDrawPageSchema$1, ContentImageBlockSchema, ContentPageBreakSchema, ContentParagraphSchema, ContentPathPointSchema, ContentPathSegmentSchema, ContentRunSchema, ContentSectionSchema, ContentSectionSchema as ContentSectionSchema$1, ContentShapeSchema, ContentSheetCellSchema, ContentSheetColumnSchema, ContentSheetPrintRangeSchema, ContentSheetPrintSettingsSchema, ContentSheetRepeatRangeSchema, ContentSheetRowSchema, ContentSheetSchema, ContentSheetSchema as ContentSheetSchema$1, ContentSlideSchema, ContentSlideSchema as ContentSlideSchema$1, ContentStrokeSchema, ContentSubpathSchema, ContentTableCellSchema, ContentTableRowSchema, ContentTableSchema, ContentVectorSchema, DEFAULT_LAYOUT_FONT, LAYOUT_FORMAT_VERSION, LAYOUT_FORMAT_VERSION as LAYOUT_FORMAT_VERSION$1, LayoutDocumentSchema, LayoutMetadataSchema, PAGE_SIZE_A4, PAGE_SIZE_LETTER, SLIDE_SIZE_STANDARD, SLIDE_SIZE_WIDESCREEN, colorToRgbHex, isContentBlock, rgbHexToColor } from "document-content-model";
3
3
  import { z } from "zod";
4
- import { ODF_MEDIA_TYPES, StyleRegistry, applyOdfTransform, base64ToBytes as base64ToBytes$2, buildOdfSubpaths, bytesToBase64 as bytesToBase64$2, decodeOdfText, decodePackage as decodePackage$2, encodePackage as encodePackage$2, formatOdfColor, formatOdfLength, parseBox, parseCellReference, parseLinePoints, parseOdfColor, parseOdfLength, parseOdfPathData, parseOdfViewBox, readOdg, readOdp, readOds, readOdt, resolveOdfShapeGeometry, resolveStyle, setDocumentMediaType, syncManifest, syncManifest as syncManifest$1, xmlnsAttributes } from "odf.js";
4
+ import { ODF_MEDIA_TYPES, StyleRegistry, applyOdfTransform, base64ToBytes as base64ToBytes$2, buildOdfSubpaths, bytesToBase64 as bytesToBase64$2, decodeOdfText, decodePackage as decodePackage$2, encodePackage as encodePackage$2, findStyleElement, formatOdfColor, formatOdfLength, parseBox, parseCellReference, parseLinePoints, parseMargins, parseOdfColor, parseOdfLength, parseOdfPathData, parseOdfViewBox, parsePageSize, readOdg, readOdp, readOds, readOdt, resolveOdfShapeGeometry, resolvePageLayoutProperties, 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;
@@ -79,6 +79,7 @@ function zipBytesSchema(label) {
79
79
  }
80
80
  const DocxBytesSchema = zipBytesSchema("docx");
81
81
  const PptxBytesSchema = zipBytesSchema("pptx");
82
+ const XlsxBytesSchema = zipBytesSchema("xlsx");
82
83
  const PdfBytesSchema = z.instanceof(Uint8Array).refine((bytes) => containsBytesWithin(bytes, PDF_HEADER, PDF_HEADER_SEARCH_WINDOW), { message: "not a valid PDF file: missing the %PDF- header" });
83
84
  const MIMETYPE_ENTRY_FILENAME = "mimetype";
84
85
  const MIMETYPE_FILENAME_OFFSET = 30;
@@ -535,7 +536,7 @@ function needsSpacePreserve(text) {
535
536
  }
536
537
  //#endregion
537
538
  //#region src/edit/docx/run.ts
538
- function directChild$10(parent, tag) {
539
+ function directChild$11(parent, tag) {
539
540
  for (const child of parent.children) if (child.type === "element" && child.tag === tag) return child;
540
541
  }
541
542
  function appendUElement(rPr, value) {
@@ -544,7 +545,7 @@ function appendUElement(rPr, value) {
544
545
  return created;
545
546
  }
546
547
  function findOrCreateT(run) {
547
- const existing = directChild$10(run, "w:t");
548
+ const existing = directChild$11(run, "w:t");
548
549
  if (existing !== void 0) return existing;
549
550
  const created = el("w:t");
550
551
  run.children.push(created);
@@ -564,7 +565,7 @@ var DocxRun = class {
564
565
  }
565
566
  rPr(create) {
566
567
  const node = this.live();
567
- return create ? ensureFirstChild(node, "w:rPr") : directChild$10(node, "w:rPr");
568
+ return create ? ensureFirstChild(node, "w:rPr") : directChild$11(node, "w:rPr");
568
569
  }
569
570
  get text() {
570
571
  return textContent$1(this.live());
@@ -588,14 +589,14 @@ var DocxRun = class {
588
589
  }
589
590
  get underline() {
590
591
  const rPr = this.rPr(false);
591
- const uElement = rPr === void 0 ? void 0 : directChild$10(rPr, "w:u");
592
+ const uElement = rPr === void 0 ? void 0 : directChild$11(rPr, "w:u");
592
593
  if (uElement === void 0) return false;
593
594
  for (const a of uElement.attributes) if (a.name === "w:val") return a.value !== "none";
594
595
  return true;
595
596
  }
596
597
  set underline(value) {
597
598
  const rPr = this.rPr(true);
598
- const existing = directChild$10(rPr, "w:u");
599
+ const existing = directChild$11(rPr, "w:u");
599
600
  if (existing === void 0) {
600
601
  appendUElement(rPr, value);
601
602
  return;
@@ -669,7 +670,7 @@ function buildRun$1(init = {}) {
669
670
  }
670
671
  //#endregion
671
672
  //#region src/edit/docx/paragraph.ts
672
- function directChild$9(parent, tag) {
673
+ function directChild$10(parent, tag) {
673
674
  for (const child of parent.children) if (child.type === "element" && child.tag === tag) return child;
674
675
  }
675
676
  var DocxParagraph = class {
@@ -688,7 +689,7 @@ var DocxParagraph = class {
688
689
  }
689
690
  pPr(create) {
690
691
  const node = this.live();
691
- return create ? ensureFirstChild(node, "w:pPr") : directChild$9(node, "w:pPr");
692
+ return create ? ensureFirstChild(node, "w:pPr") : directChild$10(node, "w:pPr");
692
693
  }
693
694
  get text() {
694
695
  return textContent$1(this.live());
@@ -725,7 +726,7 @@ var DocxParagraph = class {
725
726
  set styleId(value) {
726
727
  if (value === void 0) {
727
728
  const pPr = this.pPr(false);
728
- const existing = pPr === void 0 ? void 0 : directChild$9(pPr, "w:pStyle");
729
+ const existing = pPr === void 0 ? void 0 : directChild$10(pPr, "w:pStyle");
729
730
  if (existing !== void 0 && pPr !== void 0) removeChild(pPr.children, existing);
730
731
  return;
731
732
  }
@@ -737,7 +738,7 @@ var DocxParagraph = class {
737
738
  set alignment(value) {
738
739
  if (value === void 0) {
739
740
  const pPr = this.pPr(false);
740
- const existing = pPr === void 0 ? void 0 : directChild$9(pPr, "w:jc");
741
+ const existing = pPr === void 0 ? void 0 : directChild$10(pPr, "w:jc");
741
742
  if (existing !== void 0 && pPr !== void 0) removeChild(pPr.children, existing);
742
743
  return;
743
744
  }
@@ -745,12 +746,12 @@ var DocxParagraph = class {
745
746
  }
746
747
  get list() {
747
748
  const pPr = this.pPr(false);
748
- const numPr = pPr === void 0 ? void 0 : directChild$9(pPr, "w:numPr");
749
+ const numPr = pPr === void 0 ? void 0 : directChild$10(pPr, "w:numPr");
749
750
  if (numPr === void 0) return;
750
- const numIdElement = directChild$9(numPr, "w:numId");
751
+ const numIdElement = directChild$10(numPr, "w:numId");
751
752
  const numId = numIdElement === void 0 ? void 0 : attr$1(numIdElement, "w:val");
752
753
  if (numId === void 0) return;
753
- const ilvlElement = directChild$9(numPr, "w:ilvl");
754
+ const ilvlElement = directChild$10(numPr, "w:ilvl");
754
755
  const ilvl = ilvlElement === void 0 ? void 0 : attr$1(ilvlElement, "w:val");
755
756
  return {
756
757
  numId,
@@ -760,7 +761,7 @@ var DocxParagraph = class {
760
761
  set list(value) {
761
762
  const pPr = this.pPr(true);
762
763
  if (value === void 0) {
763
- const existing = directChild$9(pPr, "w:numPr");
764
+ const existing = directChild$10(pPr, "w:numPr");
764
765
  if (existing !== void 0) removeChild(pPr.children, existing);
765
766
  return;
766
767
  }
@@ -1094,6 +1095,7 @@ function buildDocxPackage(content) {
1094
1095
  function populateParagraph$1(paragraph, block) {
1095
1096
  paragraph.styleId = block.styleId;
1096
1097
  paragraph.alignment = block.alignment;
1098
+ paragraph.list = block.list;
1097
1099
  for (const run of block.runs) {
1098
1100
  if (run.text === " ") {
1099
1101
  paragraph.appendTab();
@@ -1425,7 +1427,7 @@ function createEmptyPptxPackage() {
1425
1427
  }
1426
1428
  //#endregion
1427
1429
  //#region src/edit/pptx/shape.ts
1428
- function directChild$8(parent, tag) {
1430
+ function directChild$9(parent, tag) {
1429
1431
  for (const child of parent.children) if (child.type === "element" && child.tag === tag) return child;
1430
1432
  }
1431
1433
  function parseEmuAttr(element, name) {
@@ -1446,7 +1448,7 @@ var PptxShape = class {
1446
1448
  }
1447
1449
  spPrElement(create) {
1448
1450
  const node = this.live();
1449
- const existing = directChild$8(node, "p:spPr");
1451
+ const existing = directChild$9(node, "p:spPr");
1450
1452
  if (existing !== void 0 || !create) return existing;
1451
1453
  const created = el("p:spPr");
1452
1454
  node.children.push(created);
@@ -1454,10 +1456,10 @@ var PptxShape = class {
1454
1456
  }
1455
1457
  get frame() {
1456
1458
  const spPr = this.spPrElement(false);
1457
- const xfrm = spPr === void 0 ? void 0 : directChild$8(spPr, "a:xfrm");
1459
+ const xfrm = spPr === void 0 ? void 0 : directChild$9(spPr, "a:xfrm");
1458
1460
  if (xfrm === void 0) return;
1459
- const off = directChild$8(xfrm, "a:off");
1460
- const ext = directChild$8(xfrm, "a:ext");
1461
+ const off = directChild$9(xfrm, "a:off");
1462
+ const ext = directChild$9(xfrm, "a:ext");
1461
1463
  if (off === void 0 || ext === void 0) return;
1462
1464
  const x = parseEmuAttr(off, "x");
1463
1465
  const y = parseEmuAttr(off, "y");
@@ -1473,7 +1475,7 @@ var PptxShape = class {
1473
1475
  }
1474
1476
  set frame(value) {
1475
1477
  const spPr = this.spPrElement(true);
1476
- let xfrm = directChild$8(spPr, "a:xfrm");
1478
+ let xfrm = directChild$9(spPr, "a:xfrm");
1477
1479
  if (xfrm === void 0) {
1478
1480
  xfrm = el("a:xfrm");
1479
1481
  spPr.children.unshift(xfrm);
@@ -1487,12 +1489,12 @@ var PptxShape = class {
1487
1489
  })];
1488
1490
  }
1489
1491
  get text() {
1490
- const txBody = directChild$8(this.live(), "p:txBody");
1492
+ const txBody = directChild$9(this.live(), "p:txBody");
1491
1493
  return txBody === void 0 ? "" : textContent$1(txBody);
1492
1494
  }
1493
1495
  set text(value) {
1494
1496
  const node = this.live();
1495
- let txBody = directChild$8(node, "p:txBody");
1497
+ let txBody = directChild$9(node, "p:txBody");
1496
1498
  if (txBody === void 0) {
1497
1499
  txBody = el("p:txBody", {}, [el("a:bodyPr"), el("a:lstStyle")]);
1498
1500
  node.children.push(txBody);
@@ -1503,7 +1505,7 @@ var PptxShape = class {
1503
1505
  }
1504
1506
  setParagraphs(paragraphs) {
1505
1507
  const node = this.live();
1506
- let txBody = directChild$8(node, "p:txBody");
1508
+ let txBody = directChild$9(node, "p:txBody");
1507
1509
  if (txBody === void 0) {
1508
1510
  txBody = el("p:txBody", {}, [el("a:bodyPr"), el("a:lstStyle")]);
1509
1511
  node.children.push(txBody);
@@ -1614,12 +1616,12 @@ function insertPictureShapeMedia(context, slideRoot, frame, image) {
1614
1616
  }
1615
1617
  //#endregion
1616
1618
  //#region src/edit/pptx/slide.ts
1617
- function directChild$7(parent, tag) {
1619
+ function directChild$8(parent, tag) {
1618
1620
  for (const child of parent.children) if (child.type === "element" && child.tag === tag) return child;
1619
1621
  }
1620
1622
  function findSpTree(slideRoot) {
1621
- const cSld = directChild$7(slideRoot, "p:cSld");
1622
- const spTree = cSld === void 0 ? void 0 : directChild$7(cSld, "p:spTree");
1623
+ const cSld = directChild$8(slideRoot, "p:cSld");
1624
+ const spTree = cSld === void 0 ? void 0 : directChild$8(cSld, "p:spTree");
1623
1625
  if (spTree === void 0) throw new Error("slide has no p:cSld/p:spTree element");
1624
1626
  return spTree;
1625
1627
  }
@@ -1751,7 +1753,7 @@ const PRESENTATION_PART_PATH = "ppt/presentation.xml";
1751
1753
  const MEDIA_DIR = "ppt/media";
1752
1754
  const SLIDE_CONTENT_TYPE = "application/vnd.openxmlformats-officedocument.presentationml.slide+xml";
1753
1755
  const SLIDE_RELATIONSHIP_TYPE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/slide";
1754
- function directChild$6(parent, tag) {
1756
+ function directChild$7(parent, tag) {
1755
1757
  for (const child of parent.children) if (child.type === "element" && child.tag === tag) return child;
1756
1758
  }
1757
1759
  function attrValue(element, name) {
@@ -1763,12 +1765,12 @@ function findPresentationRoot(pkg) {
1763
1765
  return root;
1764
1766
  }
1765
1767
  function findSldIdLst(presentationRoot) {
1766
- const sldIdLst = directChild$6(presentationRoot, "p:sldIdLst");
1768
+ const sldIdLst = directChild$7(presentationRoot, "p:sldIdLst");
1767
1769
  if (sldIdLst === void 0) throw new Error(`${PRESENTATION_PART_PATH} has no p:sldIdLst element`);
1768
1770
  return sldIdLst;
1769
1771
  }
1770
1772
  function findSldSz(presentationRoot) {
1771
- const sldSz = directChild$6(presentationRoot, "p:sldSz");
1773
+ const sldSz = directChild$7(presentationRoot, "p:sldSz");
1772
1774
  if (sldSz === void 0) throw new Error(`${PRESENTATION_PART_PATH} has no p:sldSz element`);
1773
1775
  return sldSz;
1774
1776
  }
@@ -1967,12 +1969,12 @@ function appendShape$2(slide, shape) {
1967
1969
  }
1968
1970
  //#endregion
1969
1971
  //#region src/edit/odt/automatic-styles.ts
1970
- const CONTENT_PART_PATH$4 = "content.xml";
1972
+ const CONTENT_PART_PATH$5 = "content.xml";
1971
1973
  function ensureAutomaticStyles(pkg) {
1972
- const part = pkg.parts[CONTENT_PART_PATH$4];
1973
- if (part?.kind !== "xml") throw new Error(`ensureAutomaticStyles: package has no ${CONTENT_PART_PATH$4} part`);
1974
+ const part = pkg.parts[CONTENT_PART_PATH$5];
1975
+ if (part?.kind !== "xml") throw new Error(`ensureAutomaticStyles: package has no ${CONTENT_PART_PATH$5} part`);
1974
1976
  const root = part.nodes.find((n) => n.type === "element");
1975
- if (root === void 0) throw new Error(`ensureAutomaticStyles: ${CONTENT_PART_PATH$4} has no root element`);
1977
+ if (root === void 0) throw new Error(`ensureAutomaticStyles: ${CONTENT_PART_PATH$5} has no root element`);
1976
1978
  for (const child of root.children) if (child.type === "element" && child.tag === "office:automatic-styles") return child;
1977
1979
  const created = el("office:automatic-styles");
1978
1980
  const insertBeforeTags = /* @__PURE__ */ new Set([
@@ -2066,7 +2068,7 @@ function applyStyleChange(pkg, element, family, change) {
2066
2068
  ...readCurrentStyleProperties(pkg, element, family),
2067
2069
  ...change
2068
2070
  };
2069
- const name = StyleRegistry.forPart(pkg, CONTENT_PART_PATH$4).intern({
2071
+ const name = StyleRegistry.forPart(pkg, CONTENT_PART_PATH$5).intern({
2070
2072
  family,
2071
2073
  properties: merged
2072
2074
  });
@@ -2325,7 +2327,7 @@ const META_NS_PREFIXES$3 = [
2325
2327
  const ODF_VERSION$3 = "1.3";
2326
2328
  const PAGE_LAYOUT_NAME$3 = "PM1";
2327
2329
  const MASTER_PAGE_NAME$3 = "Standard";
2328
- const DEFAULT_MARGIN_PT = 72;
2330
+ const DEFAULT_MARGIN_PT$1 = 72;
2329
2331
  function declaration$3() {
2330
2332
  return {
2331
2333
  type: "declaration",
@@ -2349,10 +2351,10 @@ function buildPageLayout$3() {
2349
2351
  return el("style:page-layout", { "style:name": PAGE_LAYOUT_NAME$3 }, [el("style:page-layout-properties", {
2350
2352
  "fo:page-width": `${PAGE_SIZE_LETTER.widthPt}pt`,
2351
2353
  "fo:page-height": `${PAGE_SIZE_LETTER.heightPt}pt`,
2352
- "fo:margin-top": `${DEFAULT_MARGIN_PT}pt`,
2353
- "fo:margin-right": `${DEFAULT_MARGIN_PT}pt`,
2354
- "fo:margin-bottom": `${DEFAULT_MARGIN_PT}pt`,
2355
- "fo:margin-left": `${DEFAULT_MARGIN_PT}pt`
2354
+ "fo:margin-top": `${DEFAULT_MARGIN_PT$1}pt`,
2355
+ "fo:margin-right": `${DEFAULT_MARGIN_PT$1}pt`,
2356
+ "fo:margin-bottom": `${DEFAULT_MARGIN_PT$1}pt`,
2357
+ "fo:margin-left": `${DEFAULT_MARGIN_PT$1}pt`
2356
2358
  })]);
2357
2359
  }
2358
2360
  function buildStylesXml$3() {
@@ -2513,20 +2515,20 @@ function buildTable(pkg, init) {
2513
2515
  }
2514
2516
  //#endregion
2515
2517
  //#region src/edit/odt/editor.ts
2516
- const CONTENT_PART_PATH$3 = "content.xml";
2518
+ const CONTENT_PART_PATH$4 = "content.xml";
2517
2519
  function findContentRoot(pkg) {
2518
- const part = pkg.parts[CONTENT_PART_PATH$3];
2520
+ const part = pkg.parts[CONTENT_PART_PATH$4];
2519
2521
  const root = part?.kind === "xml" ? part.nodes.find((n) => n.type === "element") : void 0;
2520
- if (root === void 0) throw new Error(`package has no root element at ${CONTENT_PART_PATH$3}`);
2522
+ if (root === void 0) throw new Error(`package has no root element at ${CONTENT_PART_PATH$4}`);
2521
2523
  return root;
2522
2524
  }
2523
- function directChild$5(parent, tag) {
2525
+ function directChild$6(parent, tag) {
2524
2526
  for (const child of parent.children) if (child.type === "element" && child.tag === tag) return child;
2525
2527
  }
2526
2528
  function findOfficeText(contentRoot) {
2527
- const body = directChild$5(contentRoot, "office:body");
2528
- const text = body === void 0 ? void 0 : directChild$5(body, "office:text");
2529
- if (text === void 0) throw new Error(`${CONTENT_PART_PATH$3} has no office:body/office:text element`);
2529
+ const body = directChild$6(contentRoot, "office:body");
2530
+ const text = body === void 0 ? void 0 : directChild$6(body, "office:text");
2531
+ if (text === void 0) throw new Error(`${CONTENT_PART_PATH$4} has no office:body/office:text element`);
2530
2532
  return text;
2531
2533
  }
2532
2534
  var OdtBodyImpl = class {
@@ -2606,11 +2608,60 @@ function buildOdtPackage(content) {
2606
2608
  const editor = createOdt();
2607
2609
  content.sections.forEach((section, sectionIndex) => {
2608
2610
  if (sectionIndex > 0) editor.body.appendPageBreak();
2609
- for (const block of section.blocks) appendBlock(editor.body, block);
2611
+ appendBlocks(editor.body, section.blocks);
2610
2612
  });
2611
2613
  return editor.toPackage();
2612
2614
  }
2615
+ function appendBlocks(body, blocks) {
2616
+ let i = 0;
2617
+ while (i < blocks.length) {
2618
+ const block = blocks[i];
2619
+ if (block === void 0) {
2620
+ i++;
2621
+ continue;
2622
+ }
2623
+ if (block.kind === "paragraph" && block.list !== void 0) {
2624
+ const run = [];
2625
+ while (i < blocks.length) {
2626
+ const candidate = blocks[i];
2627
+ if (candidate?.kind !== "paragraph" || candidate.list === void 0) break;
2628
+ run.push(candidate);
2629
+ i++;
2630
+ }
2631
+ appendListRun(body, run);
2632
+ continue;
2633
+ }
2634
+ appendBlock(body, block);
2635
+ i++;
2636
+ }
2637
+ }
2638
+ function appendListRun(body, paragraphs) {
2639
+ let stack = [];
2640
+ let lastItem;
2641
+ let activeNumId;
2642
+ for (const para of paragraphs) {
2643
+ const membership = para.list;
2644
+ if (membership === void 0) continue;
2645
+ if (activeNumId === void 0 || membership.numId !== activeNumId) {
2646
+ stack = [body.appendList()];
2647
+ lastItem = void 0;
2648
+ activeNumId = membership.numId;
2649
+ }
2650
+ const targetLevel = lastItem === void 0 ? 0 : membership.level;
2651
+ while (stack.length - 1 < targetLevel && lastItem !== void 0) {
2652
+ stack.push(lastItem.addNestedList());
2653
+ lastItem = void 0;
2654
+ }
2655
+ while (stack.length - 1 > targetLevel) stack.pop();
2656
+ const currentList = stack[stack.length - 1];
2657
+ if (currentList === void 0) continue;
2658
+ const item = currentList.addItem();
2659
+ populateParagraph(item.appendParagraph(), para);
2660
+ lastItem = item;
2661
+ }
2662
+ }
2613
2663
  function populateParagraph(paragraph, block) {
2664
+ if (block.styleId !== void 0) paragraph.styleId = block.styleId;
2614
2665
  if (block.alignment !== void 0) paragraph.alignment = block.alignment;
2615
2666
  for (const run of block.runs) {
2616
2667
  if (run.text === " ") {
@@ -2789,7 +2840,7 @@ function addImageMedia(pkg, imageBytes, format) {
2789
2840
  }
2790
2841
  //#endregion
2791
2842
  //#region src/edit/odp/shape.ts
2792
- function directChild$4(parent, tag) {
2843
+ function directChild$5(parent, tag) {
2793
2844
  for (const child of parent.children) if (child.type === "element" && child.tag === tag) return child;
2794
2845
  }
2795
2846
  function buildTransformAttr(frame, rotationDeg) {
@@ -2857,7 +2908,7 @@ var OdpShape = class {
2857
2908
  }
2858
2909
  textBox(create) {
2859
2910
  const node = this.live();
2860
- const existing = directChild$4(node, "draw:text-box");
2911
+ const existing = directChild$5(node, "draw:text-box");
2861
2912
  if (existing !== void 0 || !create) return existing;
2862
2913
  const created = el("draw:text-box");
2863
2914
  node.children.push(created);
@@ -2918,7 +2969,7 @@ function insertImageFrameMedia(context, frame, image) {
2918
2969
  }
2919
2970
  //#endregion
2920
2971
  //#region src/edit/odp/slide.ts
2921
- function directChild$3(parent, tag) {
2972
+ function directChild$4(parent, tag) {
2922
2973
  for (const child of parent.children) if (child.type === "element" && child.tag === tag) return child;
2923
2974
  }
2924
2975
  const NOTES_FRAME_X_PT = 20;
@@ -2967,13 +3018,13 @@ var OdpSlide = class {
2967
3018
  return new OdpShape(node.children, frameElement, this.context.pkg);
2968
3019
  }
2969
3020
  get notes() {
2970
- const notesElement = directChild$3(this.live(), "presentation:notes");
3021
+ const notesElement = directChild$4(this.live(), "presentation:notes");
2971
3022
  if (notesElement === void 0) return "";
2972
3023
  return elementsWithTag$1(notesElement.children, "text:p").map((p) => decodeOdfText$1(p.children)).join("\n");
2973
3024
  }
2974
3025
  set notes(value) {
2975
3026
  const node = this.live();
2976
- const existing = directChild$3(node, "presentation:notes");
3027
+ const existing = directChild$4(node, "presentation:notes");
2977
3028
  const notesElement = buildNotesElement(this.context.pkg, value);
2978
3029
  if (existing === void 0) node.children.push(notesElement);
2979
3030
  else existing.children = notesElement.children;
@@ -2985,27 +3036,27 @@ var OdpSlide = class {
2985
3036
  };
2986
3037
  //#endregion
2987
3038
  //#region src/edit/odp/editor.ts
2988
- const CONTENT_PART_PATH$2 = "content.xml";
2989
- const STYLES_PART_PATH$1 = "styles.xml";
2990
- function directChild$2(parent, tag) {
3039
+ const CONTENT_PART_PATH$3 = "content.xml";
3040
+ const STYLES_PART_PATH$2 = "styles.xml";
3041
+ function directChild$3(parent, tag) {
2991
3042
  for (const child of parent.children) if (child.type === "element" && child.tag === tag) return child;
2992
3043
  }
2993
- function findRoot$2(pkg, partPath) {
3044
+ function findRoot$3(pkg, partPath) {
2994
3045
  const part = pkg.parts[partPath];
2995
3046
  const root = part?.kind === "xml" ? part.nodes.find((n) => n.type === "element") : void 0;
2996
3047
  if (root === void 0) throw new Error(`package has no root element at ${partPath}`);
2997
3048
  return root;
2998
3049
  }
2999
3050
  function findOfficePresentation(pkg) {
3000
- const body = directChild$2(findRoot$2(pkg, CONTENT_PART_PATH$2), "office:body");
3001
- const presentation = body === void 0 ? void 0 : directChild$2(body, "office:presentation");
3002
- if (presentation === void 0) throw new Error(`${CONTENT_PART_PATH$2} has no office:body/office:presentation element`);
3051
+ const body = directChild$3(findRoot$3(pkg, CONTENT_PART_PATH$3), "office:body");
3052
+ const presentation = body === void 0 ? void 0 : directChild$3(body, "office:presentation");
3053
+ if (presentation === void 0) throw new Error(`${CONTENT_PART_PATH$3} has no office:body/office:presentation element`);
3003
3054
  return presentation;
3004
3055
  }
3005
3056
  function findPageLayoutProperties$1(pkg) {
3006
- const pageLayout = directChild$2(findRoot$2(pkg, STYLES_PART_PATH$1), "office:automatic-styles")?.children.find((c) => c.type === "element" && c.tag === "style:page-layout" && attr$1(c, "style:name") === "PM1");
3007
- const properties = pageLayout === void 0 ? void 0 : directChild$2(pageLayout, "style:page-layout-properties");
3008
- if (properties === void 0) throw new Error(`${STYLES_PART_PATH$1} has no style:page-layout[style:name="PM1"]/style:page-layout-properties element`);
3057
+ const pageLayout = directChild$3(findRoot$3(pkg, STYLES_PART_PATH$2), "office:automatic-styles")?.children.find((c) => c.type === "element" && c.tag === "style:page-layout" && attr$1(c, "style:name") === "PM1");
3058
+ const properties = pageLayout === void 0 ? void 0 : directChild$3(pageLayout, "style:page-layout-properties");
3059
+ if (properties === void 0) throw new Error(`${STYLES_PART_PATH$2} has no style:page-layout[style:name="PM1"]/style:page-layout-properties element`);
3009
3060
  return properties;
3010
3061
  }
3011
3062
  var OdpEditor = class {
@@ -3507,6 +3558,87 @@ var OdsCell = class {
3507
3558
  }
3508
3559
  };
3509
3560
  //#endregion
3561
+ //#region src/edit/ods/print-settings.ts
3562
+ const STYLES_PART_PATH$1 = "styles.xml";
3563
+ const CONTENT_PART_PATH$2 = "content.xml";
3564
+ function findRoot$2(pkg, partPath) {
3565
+ const part = pkg.parts[partPath];
3566
+ const root = part?.kind === "xml" ? part.nodes.find((n) => n.type === "element") : void 0;
3567
+ if (root === void 0) throw new Error(`package has no root element at ${partPath}`);
3568
+ return root;
3569
+ }
3570
+ function directChild$2(parent, tag) {
3571
+ for (const child of parent.children) if (child.type === "element" && child.tag === tag) return child;
3572
+ }
3573
+ function findStylesAutomaticStyles(pkg) {
3574
+ const found = directChild$2(findRoot$2(pkg, STYLES_PART_PATH$1), "office:automatic-styles");
3575
+ if (found === void 0) throw new Error(`${STYLES_PART_PATH$1} has no office:automatic-styles element`);
3576
+ return found;
3577
+ }
3578
+ function findMasterStyles(pkg) {
3579
+ const found = directChild$2(findRoot$2(pkg, STYLES_PART_PATH$1), "office:master-styles");
3580
+ if (found === void 0) throw new Error(`${STYLES_PART_PATH$1} has no office:master-styles element`);
3581
+ return found;
3582
+ }
3583
+ function findContentAutomaticStyles(pkg) {
3584
+ const found = directChild$2(findRoot$2(pkg, CONTENT_PART_PATH$2), "office:automatic-styles");
3585
+ if (found === void 0) throw new Error(`${CONTENT_PART_PATH$2} has no office:automatic-styles element`);
3586
+ return found;
3587
+ }
3588
+ const DEFAULT_MARGIN_PT = 56.69291338582677;
3589
+ const DEFAULT_MARGINS = {
3590
+ topPt: DEFAULT_MARGIN_PT,
3591
+ rightPt: DEFAULT_MARGIN_PT,
3592
+ bottomPt: DEFAULT_MARGIN_PT,
3593
+ leftPt: DEFAULT_MARGIN_PT
3594
+ };
3595
+ function readSheetPrintSettings(pkg, tableElement) {
3596
+ const tableStyleName = attr$1(tableElement, "table:style-name");
3597
+ const tableStyleElement = tableStyleName === void 0 ? void 0 : findStyleElement(tableStyleName, "table", pkg);
3598
+ const masterPageName = tableStyleElement === void 0 ? void 0 : attr$1(tableStyleElement, "style:master-page-name");
3599
+ const layoutProperties = resolvePageLayoutProperties(pkg, masterPageName);
3600
+ const pageSize = layoutProperties === void 0 ? void 0 : parsePageSize(layoutProperties);
3601
+ const margins = layoutProperties === void 0 ? void 0 : parseMargins(layoutProperties);
3602
+ const printTokens = new Set((layoutProperties === void 0 ? void 0 : attr$1(layoutProperties, "style:print"))?.split(" ").filter((token) => token.length > 0) ?? []);
3603
+ const pageOrder = (layoutProperties === void 0 ? void 0 : attr$1(layoutProperties, "style:print-page-order")) === "ltr" ? "overThenDown" : "downThenOver";
3604
+ return {
3605
+ pageSize: pageSize ?? PAGE_SIZE_A4,
3606
+ margins: margins ?? DEFAULT_MARGINS,
3607
+ gridlines: printTokens.has("grid"),
3608
+ headers: printTokens.has("headers"),
3609
+ pageOrder
3610
+ };
3611
+ }
3612
+ function writeSheetPrintSettings(pkg, tableElement, settings) {
3613
+ const stylesAutomaticStyles = findStylesAutomaticStyles(pkg);
3614
+ const masterStyles = findMasterStyles(pkg);
3615
+ const contentAutomaticStyles = findContentAutomaticStyles(pkg);
3616
+ const printTokens = [settings.gridlines ? "grid" : void 0, settings.headers ? "headers" : void 0].filter((token) => token !== void 0);
3617
+ const pageLayoutName = nextStyleName(stylesAutomaticStyles, "style:page-layout", "OdsPageLayout");
3618
+ stylesAutomaticStyles.children.push(el("style:page-layout", { "style:name": pageLayoutName }, [el("style:page-layout-properties", {
3619
+ "fo:page-width": formatOdfLength(settings.pageSize.widthPt),
3620
+ "fo:page-height": formatOdfLength(settings.pageSize.heightPt),
3621
+ "fo:margin-top": formatOdfLength(settings.margins.topPt),
3622
+ "fo:margin-right": formatOdfLength(settings.margins.rightPt),
3623
+ "fo:margin-bottom": formatOdfLength(settings.margins.bottomPt),
3624
+ "fo:margin-left": formatOdfLength(settings.margins.leftPt),
3625
+ ...printTokens.length > 0 ? { "style:print": printTokens.join(" ") } : {},
3626
+ "style:print-page-order": settings.pageOrder === "overThenDown" ? "ltr" : "ttb"
3627
+ })]));
3628
+ const masterPageName = nextStyleName(masterStyles, "style:master-page", "OdsMasterPage");
3629
+ masterStyles.children.push(el("style:master-page", {
3630
+ "style:name": masterPageName,
3631
+ "style:page-layout-name": pageLayoutName
3632
+ }));
3633
+ const tableStyleName = nextStyleName(contentAutomaticStyles, "style:style", "OdsSheetPrint");
3634
+ contentAutomaticStyles.children.push(el("style:style", {
3635
+ "style:name": tableStyleName,
3636
+ "style:family": "table",
3637
+ "style:master-page-name": masterPageName
3638
+ }));
3639
+ setAttr(tableElement, "table:style-name", tableStyleName);
3640
+ }
3641
+ //#endregion
3510
3642
  //#region src/edit/ods/sheet.ts
3511
3643
  const NAME_ATTR = "table:name";
3512
3644
  var OdsSheet = class {
@@ -3531,6 +3663,12 @@ var OdsSheet = class {
3531
3663
  set name(value) {
3532
3664
  setAttr(this.live(), NAME_ATTR, value);
3533
3665
  }
3666
+ get printSettings() {
3667
+ return readSheetPrintSettings(this.pkg, this.live());
3668
+ }
3669
+ set printSettings(value) {
3670
+ writeSheetPrintSettings(this.pkg, this.live(), value);
3671
+ }
3534
3672
  cell(row, column) {
3535
3673
  const node = resolveCellNode(this.live(), row, column);
3536
3674
  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`);
@@ -3643,6 +3781,7 @@ function buildOdsPackage(content) {
3643
3781
  if (content.sheets.length > 0) editor.removeSheetAt(0);
3644
3782
  for (const sheet of content.sheets) {
3645
3783
  const odsSheet = editor.addSheet(sheet.name);
3784
+ odsSheet.printSettings = sheet.printSettings;
3646
3785
  for (const cell of sheet.cells) appendCell(odsSheet, cell);
3647
3786
  }
3648
3787
  return editor.toPackage();
@@ -11023,6 +11162,275 @@ function layoutTextToShape(item, pageHeightPt) {
11023
11162
  }]
11024
11163
  };
11025
11164
  }
11165
+ function extractLineCandidates(items) {
11166
+ const segments = [];
11167
+ for (const item of items) {
11168
+ if (item.kind === "line") {
11169
+ segments.push({
11170
+ x1Pt: item.x1Pt,
11171
+ y1Pt: item.y1Pt,
11172
+ x2Pt: item.x2Pt,
11173
+ y2Pt: item.y2Pt
11174
+ });
11175
+ continue;
11176
+ }
11177
+ if (item.kind === "path" && item.stroke !== void 0 && item.subpaths.length === 1) {
11178
+ const subpath = item.subpaths[0];
11179
+ if (subpath.segments.length === 1 && subpath.segments[0].kind === "line") {
11180
+ const segment = subpath.segments[0];
11181
+ segments.push({
11182
+ x1Pt: subpath.startXPt,
11183
+ y1Pt: subpath.startYPt,
11184
+ x2Pt: segment.xPt,
11185
+ y2Pt: segment.yPt
11186
+ });
11187
+ }
11188
+ }
11189
+ }
11190
+ return segments;
11191
+ }
11192
+ const AXIS_ALIGNMENT_TOLERANCE_PT = .5;
11193
+ const MIN_GRIDLINE_LENGTH_PT = 4;
11194
+ function classifyAxisLine(seg) {
11195
+ const dx = Math.abs(seg.x2Pt - seg.x1Pt);
11196
+ const dy = Math.abs(seg.y2Pt - seg.y1Pt);
11197
+ if (dy <= AXIS_ALIGNMENT_TOLERANCE_PT && dx >= MIN_GRIDLINE_LENGTH_PT) return {
11198
+ axis: "horizontal",
11199
+ position: (seg.y1Pt + seg.y2Pt) / 2,
11200
+ spanPt: dx
11201
+ };
11202
+ if (dx <= AXIS_ALIGNMENT_TOLERANCE_PT && dy >= MIN_GRIDLINE_LENGTH_PT) return {
11203
+ axis: "vertical",
11204
+ position: (seg.x1Pt + seg.x2Pt) / 2,
11205
+ spanPt: dy
11206
+ };
11207
+ }
11208
+ const POSITION_DEDUPE_TOLERANCE_PT = .5;
11209
+ function dedupeAxisLines(lines, descending) {
11210
+ const sorted = [...lines].sort((a, b) => descending ? b.position - a.position : a.position - b.position);
11211
+ const result = [];
11212
+ for (const candidate of sorted) {
11213
+ const last = result[result.length - 1];
11214
+ if (last !== void 0 && Math.abs(candidate.position - last.position) <= POSITION_DEDUPE_TOLERANCE_PT) last.spanPt = Math.max(last.spanPt, candidate.spanPt);
11215
+ else result.push({
11216
+ position: candidate.position,
11217
+ spanPt: candidate.spanPt
11218
+ });
11219
+ }
11220
+ return result;
11221
+ }
11222
+ const MIN_GRIDLINE_COUNT_PER_AXIS = 3;
11223
+ const GRID_SPAN_CONSISTENCY_RATIO = .9;
11224
+ function isRegularLattice(lines) {
11225
+ if (lines.length < MIN_GRIDLINE_COUNT_PER_AXIS) return false;
11226
+ const maxSpanPt = Math.max(...lines.map((l) => l.spanPt));
11227
+ return lines.filter((l) => l.spanPt >= maxSpanPt * GRID_SPAN_CONSISTENCY_RATIO).length >= MIN_GRIDLINE_COUNT_PER_AXIS;
11228
+ }
11229
+ function detectGridLattice(items) {
11230
+ const horizontal = [];
11231
+ const vertical = [];
11232
+ for (const seg of extractLineCandidates(items)) {
11233
+ const classified = classifyAxisLine(seg);
11234
+ if (classified === void 0) continue;
11235
+ (classified.axis === "horizontal" ? horizontal : vertical).push(classified);
11236
+ }
11237
+ const rowBoundaries = dedupeAxisLines(horizontal, true);
11238
+ const columnBoundaries = dedupeAxisLines(vertical, false);
11239
+ if (!isRegularLattice(rowBoundaries) || !isRegularLattice(columnBoundaries)) return;
11240
+ return {
11241
+ rowBoundariesDescPt: rowBoundaries.map((l) => l.position),
11242
+ columnBoundariesAscPt: columnBoundaries.map((l) => l.position)
11243
+ };
11244
+ }
11245
+ const OUTER_EDGE_TOLERANCE_PT = 3;
11246
+ function findRowIndex(rowBoundariesDescPt, yPt) {
11247
+ const lastIndex = rowBoundariesDescPt.length - 1;
11248
+ if (yPt > rowBoundariesDescPt[0] + OUTER_EDGE_TOLERANCE_PT || yPt < rowBoundariesDescPt[lastIndex] - OUTER_EDGE_TOLERANCE_PT) return;
11249
+ for (let i = 0; i < lastIndex; i++) if (yPt > rowBoundariesDescPt[i + 1]) return i;
11250
+ return lastIndex - 1;
11251
+ }
11252
+ function findColumnIndex(columnBoundariesAscPt, xPt) {
11253
+ const lastIndex = columnBoundariesAscPt.length - 1;
11254
+ if (xPt < columnBoundariesAscPt[0] - OUTER_EDGE_TOLERANCE_PT || xPt > columnBoundariesAscPt[lastIndex] + OUTER_EDGE_TOLERANCE_PT) return;
11255
+ for (let j = 0; j < lastIndex; j++) if (xPt < columnBoundariesAscPt[j + 1]) return j;
11256
+ return lastIndex - 1;
11257
+ }
11258
+ function joinCellText(items) {
11259
+ const sorted = [...items].sort((a, b) => a.xPt - b.xPt);
11260
+ let text = "";
11261
+ sorted.forEach((item, i) => {
11262
+ if (i > 0) {
11263
+ const prev = sorted[i - 1];
11264
+ if (item.xPt - (prev.xPt + (prev.widthPt ?? 0)) > MIN_WORD_GAP_PT) text += " ";
11265
+ }
11266
+ text += item.text;
11267
+ });
11268
+ return text;
11269
+ }
11270
+ function groupKey(row, column) {
11271
+ return `${row},${column}`;
11272
+ }
11273
+ function addToGroup(groups, row, column, item) {
11274
+ const key = groupKey(row, column);
11275
+ const existing = groups.get(key);
11276
+ if (existing === void 0) groups.set(key, [item]);
11277
+ else existing.push(item);
11278
+ }
11279
+ function buildCellsFromGroups(groups) {
11280
+ const cells = [];
11281
+ for (const [key, items] of groups) {
11282
+ const displayText = joinCellText(items);
11283
+ if (displayText.length === 0) continue;
11284
+ const [rowPart, columnPart] = key.split(",");
11285
+ cells.push({
11286
+ row: Number(rowPart),
11287
+ column: Number(columnPart),
11288
+ value: {
11289
+ kind: "string",
11290
+ value: displayText
11291
+ },
11292
+ displayText
11293
+ });
11294
+ }
11295
+ cells.sort((a, b) => a.row - b.row || a.column - b.column);
11296
+ return cells;
11297
+ }
11298
+ function buildGridFromLattice(textItems, lattice) {
11299
+ const groups = /* @__PURE__ */ new Map();
11300
+ for (const item of textItems) {
11301
+ const row = findRowIndex(lattice.rowBoundariesDescPt, item.yPt);
11302
+ const column = findColumnIndex(lattice.columnBoundariesAscPt, item.xPt);
11303
+ if (row === void 0 || column === void 0) continue;
11304
+ addToGroup(groups, row, column, item);
11305
+ }
11306
+ const columns = [];
11307
+ for (let j = 0; j < lattice.columnBoundariesAscPt.length - 1; j++) columns.push({
11308
+ index: j,
11309
+ widthPt: lattice.columnBoundariesAscPt[j + 1] - lattice.columnBoundariesAscPt[j]
11310
+ });
11311
+ const rows = [];
11312
+ for (let i = 0; i < lattice.rowBoundariesDescPt.length - 1; i++) rows.push({
11313
+ index: i,
11314
+ heightPt: lattice.rowBoundariesDescPt[i] - lattice.rowBoundariesDescPt[i + 1]
11315
+ });
11316
+ return {
11317
+ cells: buildCellsFromGroups(groups),
11318
+ columns,
11319
+ rows,
11320
+ gridlines: true
11321
+ };
11322
+ }
11323
+ const COLUMN_ALIGNMENT_TOLERANCE_PT = 3;
11324
+ const MIN_COLUMN_RECURRENCE = 2;
11325
+ function detectColumnPositions(segmentsByLine) {
11326
+ const allXs = segmentsByLine.flatMap((segments) => segments.map((segment) => segment.items[0].xPt));
11327
+ if (allXs.length === 0) return [];
11328
+ const counts = bucketCounts(allXs, COLUMN_ALIGNMENT_TOLERANCE_PT);
11329
+ const recurring = [...counts.entries()].filter(([, count]) => count >= MIN_COLUMN_RECURRENCE).map(([bucket]) => bucket);
11330
+ const positions = recurring.length > 0 ? recurring : [...counts.keys()];
11331
+ positions.sort((a, b) => a - b);
11332
+ return positions;
11333
+ }
11334
+ function nearestColumnIndex(positions, xPt) {
11335
+ let bestIndex = 0;
11336
+ let bestDistancePt = Number.POSITIVE_INFINITY;
11337
+ positions.forEach((position, index) => {
11338
+ const distancePt = Math.abs(position - xPt);
11339
+ if (distancePt < bestDistancePt) {
11340
+ bestDistancePt = distancePt;
11341
+ bestIndex = index;
11342
+ }
11343
+ });
11344
+ return bestIndex;
11345
+ }
11346
+ const DEFAULT_COLUMN_WIDTH_FALLBACK_PT = 40;
11347
+ function lastColumnWidthPt(groups, columnIndex, anchorXPt) {
11348
+ let maxWidthPt = 0;
11349
+ for (const [key, items] of groups) {
11350
+ const [, columnPart] = key.split(",");
11351
+ if (Number(columnPart) !== columnIndex) continue;
11352
+ for (const item of items) maxWidthPt = Math.max(maxWidthPt, item.xPt + (item.widthPt ?? 0) - anchorXPt);
11353
+ }
11354
+ return maxWidthPt > 0 ? maxWidthPt : DEFAULT_COLUMN_WIDTH_FALLBACK_PT;
11355
+ }
11356
+ function buildGridFromTextClustering(textItems) {
11357
+ const lines = clusterIntoLines(textItems);
11358
+ if (lines.length === 0) return {
11359
+ cells: [],
11360
+ columns: [],
11361
+ rows: [],
11362
+ gridlines: false
11363
+ };
11364
+ const segmentsByLine = lines.map((l) => splitLineByLargeGaps(l));
11365
+ const columnPositions = detectColumnPositions(segmentsByLine);
11366
+ const groups = /* @__PURE__ */ new Map();
11367
+ segmentsByLine.forEach((segments, rowIndex) => {
11368
+ for (const segment of segments) {
11369
+ const key = groupKey(rowIndex, nearestColumnIndex(columnPositions, segment.items[0].xPt));
11370
+ const existing = groups.get(key);
11371
+ if (existing === void 0) groups.set(key, [...segment.items]);
11372
+ else existing.push(...segment.items);
11373
+ }
11374
+ });
11375
+ const nominalRowHeightPt = estimateModalLineSpacing(lines);
11376
+ const rows = lines.map((line, i) => {
11377
+ const nextBaselineY = lines[i + 1]?.baselineY;
11378
+ const heightPt = nextBaselineY !== void 0 ? line.baselineY - nextBaselineY : nominalRowHeightPt;
11379
+ return {
11380
+ index: i,
11381
+ heightPt: heightPt > 0 ? heightPt : nominalRowHeightPt
11382
+ };
11383
+ });
11384
+ const columns = columnPositions.map((position, j) => {
11385
+ const nextPosition = columnPositions[j + 1];
11386
+ return {
11387
+ index: j,
11388
+ widthPt: nextPosition !== void 0 ? nextPosition - position : lastColumnWidthPt(groups, j, position)
11389
+ };
11390
+ });
11391
+ return {
11392
+ cells: buildCellsFromGroups(groups),
11393
+ columns,
11394
+ rows,
11395
+ gridlines: false
11396
+ };
11397
+ }
11398
+ function reconstructSheet(page, pageIndex) {
11399
+ const textItems = page.items.filter((i) => i.kind === "text");
11400
+ const lattice = detectGridLattice(page.items);
11401
+ const grid = lattice !== void 0 ? buildGridFromLattice(textItems, lattice) : buildGridFromTextClustering(textItems);
11402
+ const printSettings = {
11403
+ pageSize: {
11404
+ widthPt: page.widthPt,
11405
+ heightPt: page.heightPt
11406
+ },
11407
+ margins: ZERO_MARGINS,
11408
+ gridlines: grid.gridlines,
11409
+ headers: false,
11410
+ pageOrder: "downThenOver"
11411
+ };
11412
+ return {
11413
+ name: `Sheet${pageIndex + 1}`,
11414
+ cells: grid.cells,
11415
+ columns: grid.columns,
11416
+ rows: grid.rows,
11417
+ images: [],
11418
+ printSettings
11419
+ };
11420
+ }
11421
+ function reconstructSpreadsheet(doc, options) {
11422
+ const signal = options?.signal;
11423
+ const sheets = doc.pages.map((page, index) => {
11424
+ throwIfAborted(signal);
11425
+ return reconstructSheet(page, index);
11426
+ });
11427
+ return {
11428
+ kind: "spreadsheet",
11429
+ formatVersion: 1,
11430
+ metadata: doc.metadata,
11431
+ sheets
11432
+ };
11433
+ }
11026
11434
  //#endregion
11027
11435
  //#region src/convert/convert.ts
11028
11436
  function docxToPdf(bytes, options) {
@@ -11111,6 +11519,56 @@ function pdfToOdg(bytes, options) {
11111
11519
  }), { signal: options?.signal });
11112
11520
  return encodePackage$2(buildOdgPackage(content));
11113
11521
  }
11522
+ function pdfToOds(bytes, options) {
11523
+ const content = reconstructSpreadsheet(readPdf(bytes, {
11524
+ signal: options?.signal,
11525
+ sink: options?.sink
11526
+ }), { signal: options?.signal });
11527
+ return encodePackage$2(buildOdsPackage(content));
11528
+ }
11529
+ function odtToDocx(bytes, options) {
11530
+ throwIfAborted(options?.signal);
11531
+ const content = readOdtContent(decodePackage$2(bytes));
11532
+ if (content.kind !== "wordprocessing") throw new Error("readOdtContent returned a non-wordprocessing ContentDocument");
11533
+ throwIfAborted(options?.signal);
11534
+ return encodePackage$1(buildDocxPackage(content));
11535
+ }
11536
+ function docxToOdt(bytes, options) {
11537
+ throwIfAborted(options?.signal);
11538
+ const content = readDocxContent(decodePackage$1(bytes));
11539
+ if (content.kind !== "wordprocessing") throw new Error("readDocxContent returned a non-wordprocessing ContentDocument");
11540
+ throwIfAborted(options?.signal);
11541
+ return encodePackage$2(buildOdtPackage(content));
11542
+ }
11543
+ function odpToPptx(bytes, options) {
11544
+ throwIfAborted(options?.signal);
11545
+ const content = readOdpContent(decodePackage$2(bytes));
11546
+ if (content.kind !== "presentation") throw new Error("readOdpContent returned a non-presentation ContentDocument");
11547
+ throwIfAborted(options?.signal);
11548
+ return encodePackage$1(buildPptxPackage(content));
11549
+ }
11550
+ function pptxToOdp(bytes, options) {
11551
+ throwIfAborted(options?.signal);
11552
+ const content = readPptxContent(decodePackage$1(bytes));
11553
+ if (content.kind !== "presentation") throw new Error("readPptxContent returned a non-presentation ContentDocument");
11554
+ throwIfAborted(options?.signal);
11555
+ return encodePackage$2(buildOdpPackage(content));
11556
+ }
11557
+ function odsToXlsx(bytes, options) {
11558
+ throwIfAborted(options?.signal);
11559
+ const content = readOdsContent(decodePackage$2(bytes));
11560
+ if (content.kind !== "spreadsheet") throw new Error("readOdsContent returned a non-spreadsheet ContentDocument");
11561
+ throwIfAborted(options?.signal);
11562
+ return encodePackage$1(buildXlsxPackage(content));
11563
+ }
11564
+ function xlsxToOds(bytes, options) {
11565
+ throwIfAborted(options?.signal);
11566
+ const pkg = decodePackage$1(bytes);
11567
+ const content = readXlsxContent(pkg);
11568
+ if (content.kind !== "spreadsheet") throw new Error("readXlsxContent returned a non-spreadsheet ContentDocument");
11569
+ throwIfAborted(options?.signal);
11570
+ return encodePackage$2(buildOdsPackage(content));
11571
+ }
11114
11572
  //#endregion
11115
11573
  //#region src/convert/codec.ts
11116
11574
  const docxPdfCodec = z.codec(DocxBytesSchema, PdfBytesSchema, {
@@ -11129,10 +11587,26 @@ const odpPdfCodec = z.codec(OdpBytesSchema, PdfBytesSchema, {
11129
11587
  decode: (odpBytes) => odpToPdf(odpBytes),
11130
11588
  encode: (pdfBytes) => pdfToOdp(pdfBytes)
11131
11589
  });
11590
+ const odsPdfCodec = z.codec(OdsBytesSchema, PdfBytesSchema, {
11591
+ decode: (odsBytes) => odsToPdf(odsBytes),
11592
+ encode: (pdfBytes) => pdfToOds(pdfBytes)
11593
+ });
11132
11594
  const odgPdfCodec = z.codec(OdgBytesSchema, PdfBytesSchema, {
11133
11595
  decode: (odgBytes) => odgToPdf(odgBytes),
11134
11596
  encode: (pdfBytes) => pdfToOdg(pdfBytes)
11135
11597
  });
11598
+ const odtDocxCodec = z.codec(OdtBytesSchema, DocxBytesSchema, {
11599
+ decode: (odtBytes) => odtToDocx(odtBytes),
11600
+ encode: (docxBytes) => docxToOdt(docxBytes)
11601
+ });
11602
+ const odpPptxCodec = z.codec(OdpBytesSchema, PptxBytesSchema, {
11603
+ decode: (odpBytes) => odpToPptx(odpBytes),
11604
+ encode: (pptxBytes) => pptxToOdp(pptxBytes)
11605
+ });
11606
+ const odsXlsxCodec = z.codec(OdsBytesSchema, XlsxBytesSchema, {
11607
+ decode: (odsBytes) => odsToXlsx(odsBytes),
11608
+ encode: (xlsxBytes) => xlsxToOds(xlsxBytes)
11609
+ });
11136
11610
  //#endregion
11137
11611
  //#region src/convert/local.ts
11138
11612
  const SUPPORTED_CONVERSIONS = [
@@ -11176,9 +11650,37 @@ const SUPPORTED_CONVERSIONS = [
11176
11650
  source: "pdf",
11177
11651
  target: "odp"
11178
11652
  },
11653
+ {
11654
+ source: "pdf",
11655
+ target: "ods"
11656
+ },
11179
11657
  {
11180
11658
  source: "pdf",
11181
11659
  target: "odg"
11660
+ },
11661
+ {
11662
+ source: "odt",
11663
+ target: "docx"
11664
+ },
11665
+ {
11666
+ source: "docx",
11667
+ target: "odt"
11668
+ },
11669
+ {
11670
+ source: "odp",
11671
+ target: "pptx"
11672
+ },
11673
+ {
11674
+ source: "pptx",
11675
+ target: "odp"
11676
+ },
11677
+ {
11678
+ source: "ods",
11679
+ target: "xlsx"
11680
+ },
11681
+ {
11682
+ source: "xlsx",
11683
+ target: "ods"
11182
11684
  }
11183
11685
  ];
11184
11686
  function substitutionDiagnostic(substitution, context) {
@@ -11334,6 +11836,19 @@ function createLocalDocumentConverter() {
11334
11836
  diagnostics
11335
11837
  });
11336
11838
  }
11839
+ if (source.format === "pdf" && targetFormat === "ods") {
11840
+ const bytes = pdfToOds(source.bytes, {
11841
+ signal: options.signal,
11842
+ sink: (d) => diagnostics.push(fromPdfDiagnostic(d))
11843
+ });
11844
+ return Promise.resolve({
11845
+ document: {
11846
+ format: "ods",
11847
+ bytes
11848
+ },
11849
+ diagnostics
11850
+ });
11851
+ }
11337
11852
  if (source.format === "pdf" && targetFormat === "odg") {
11338
11853
  const bytes = pdfToOdg(source.bytes, {
11339
11854
  signal: options.signal,
@@ -11347,6 +11862,66 @@ function createLocalDocumentConverter() {
11347
11862
  diagnostics
11348
11863
  });
11349
11864
  }
11865
+ if (source.format === "odt" && targetFormat === "docx") {
11866
+ const bytes = odtToDocx(source.bytes, { signal: options.signal });
11867
+ return Promise.resolve({
11868
+ document: {
11869
+ format: "docx",
11870
+ bytes
11871
+ },
11872
+ diagnostics
11873
+ });
11874
+ }
11875
+ if (source.format === "docx" && targetFormat === "odt") {
11876
+ const bytes = docxToOdt(source.bytes, { signal: options.signal });
11877
+ return Promise.resolve({
11878
+ document: {
11879
+ format: "odt",
11880
+ bytes
11881
+ },
11882
+ diagnostics
11883
+ });
11884
+ }
11885
+ if (source.format === "odp" && targetFormat === "pptx") {
11886
+ const bytes = odpToPptx(source.bytes, { signal: options.signal });
11887
+ return Promise.resolve({
11888
+ document: {
11889
+ format: "pptx",
11890
+ bytes
11891
+ },
11892
+ diagnostics
11893
+ });
11894
+ }
11895
+ if (source.format === "pptx" && targetFormat === "odp") {
11896
+ const bytes = pptxToOdp(source.bytes, { signal: options.signal });
11897
+ return Promise.resolve({
11898
+ document: {
11899
+ format: "odp",
11900
+ bytes
11901
+ },
11902
+ diagnostics
11903
+ });
11904
+ }
11905
+ if (source.format === "ods" && targetFormat === "xlsx") {
11906
+ const bytes = odsToXlsx(source.bytes, { signal: options.signal });
11907
+ return Promise.resolve({
11908
+ document: {
11909
+ format: "xlsx",
11910
+ bytes
11911
+ },
11912
+ diagnostics
11913
+ });
11914
+ }
11915
+ if (source.format === "xlsx" && targetFormat === "ods") {
11916
+ const bytes = xlsxToOds(source.bytes, { signal: options.signal });
11917
+ return Promise.resolve({
11918
+ document: {
11919
+ format: "ods",
11920
+ bytes
11921
+ },
11922
+ diagnostics
11923
+ });
11924
+ }
11350
11925
  return Promise.reject(/* @__PURE__ */ new Error(`unsupported conversion: ${source.format} -> ${targetFormat}`));
11351
11926
  }
11352
11927
  };
@@ -11358,4 +11933,4 @@ function fixedClock(date) {
11358
11933
  return { now: () => date };
11359
11934
  }
11360
11935
  //#endregion
11361
- export { AttributeSchema, BinaryPartSchema, COLOR_BLACK, CONTENT_FORMAT_VERSION, CommentSchema, CompactPackageSchema, CompactPartSchema, CompactXmlNodeSchema, ContentBlockSchema, ContentCellValueSchema, ContentDocumentSchema, ContentDrawPageSchema, ContentImageBlockSchema, ContentPageBreakSchema, ContentParagraphSchema, ContentPathPointSchema, ContentPathSegmentSchema, ContentRunSchema, ContentSectionSchema, ContentShapeSchema, ContentSheetCellSchema, ContentSheetColumnSchema, ContentSheetPrintRangeSchema, ContentSheetPrintSettingsSchema, ContentSheetRepeatRangeSchema, ContentSheetRowSchema, ContentSheetSchema, ContentSlideSchema, ContentStrokeSchema, ContentSubpathSchema, ContentTableCellSchema, ContentTableRowSchema, ContentTableSchema, ContentVectorSchema, DEFAULT_LAYOUT_FONT, DefinedNameSchema, DocxBytesSchema, DocxEditor, DocxParagraph, DocxRun, DocxTable, DocxTableCell, DocxTableRow, LAYOUT_FORMAT_VERSION, NOOP_DIAGNOSTIC_SINK, OdgBoxVector, OdgBytesSchema, OdgEditor, OdgLineVector, OdgPage, OdgPathVector, OdpBytesSchema, OdpEditor, OdpShape, OdpSlide, OdsBytesSchema, OdsCell, OdsEditor, OdsSheet, OdtBytesSchema, OdtEditor, OdtList, OdtListItem, OdtParagraph, OdtRun, OdtTable, OdtTableCell, OdtTableRow, PAGE_SIZE_A4, PAGE_SIZE_LETTER, PackageSchema, PartSchema, PdfBytesSchema, PdfEncryptedError, PdfParseError, PptxBytesSchema, PptxEditor, PptxShape, PptxSlide, SLIDE_SIZE_STANDARD, SLIDE_SIZE_WIDESCREEN, XmlCdataSchema, XmlCommentSchema, XmlDeclarationSchema, XmlElementSchema, XmlNodeSchema, XmlPartSchema, XmlPiSchema, XmlTextSchema, attr, base64ToBytes, buildDocxPackage, buildOdgPackage, buildOdpPackage, buildOdsPackage, buildOdtPackage, buildPptxPackage, buildXml, bytesToBase64, childrenWithTag, compactCodec, compactPackageCodec, convertDrawingToLayout, convertPresentationToLayout, convertSpreadsheetToLayout, convertWordprocessingToLayout, createDocx, createLocalDocumentConverter, createOdg, createOdp, createOds, createOdt, createPptx, decodeCompactPackage, decodeEntities, decodePackage, docxPdfCodec, docxToPdf, elementsWithTag, encodeCompactPackage, encodePackage, fixedClock, flipY, fromCompact, isCompactXmlNode, isContentBlock, isXmlNode, odgPdfCodec, odgToPdf, odpPdfCodec, odpToPdf, odsToPdf, odtPdfCodec, odtToPdf, openDocx, openOdg, openOdp, openOds, openOdt, openPptx, packageCodec, parsePackage, parseXml, pdfCodec, pdfToDocx, pdfToOdg, pdfToOdp, pdfToOdt, pdfToPptx, pptxPdfCodec, pptxToPdf, readDocxContent, readOdgContent, readOdpContent, readOdsContent, readOdtContent, readPdf, readPptxContent, reconstructDrawing, reconstructPresentation, reconstructWordprocessing, resolveRelationships, rgbHexToColor, rootElement, serializePackage, systemClock, textContent, throwIfAborted, toCompact, unzipPackage, walk, writePdf, xmlCodec, zipPackage };
11936
+ export { AttributeSchema, BinaryPartSchema, COLOR_BLACK, CONTENT_FORMAT_VERSION, CommentSchema, CompactPackageSchema, CompactPartSchema, CompactXmlNodeSchema, ContentBlockSchema, ContentCellValueSchema, ContentDocumentSchema, ContentDrawPageSchema, ContentImageBlockSchema, ContentPageBreakSchema, ContentParagraphSchema, ContentPathPointSchema, ContentPathSegmentSchema, ContentRunSchema, ContentSectionSchema, ContentShapeSchema, ContentSheetCellSchema, ContentSheetColumnSchema, ContentSheetPrintRangeSchema, ContentSheetPrintSettingsSchema, ContentSheetRepeatRangeSchema, ContentSheetRowSchema, ContentSheetSchema, ContentSlideSchema, ContentStrokeSchema, ContentSubpathSchema, ContentTableCellSchema, ContentTableRowSchema, ContentTableSchema, ContentVectorSchema, DEFAULT_LAYOUT_FONT, DefinedNameSchema, DocxBytesSchema, DocxEditor, DocxParagraph, DocxRun, DocxTable, DocxTableCell, DocxTableRow, LAYOUT_FORMAT_VERSION, NOOP_DIAGNOSTIC_SINK, OdgBoxVector, OdgBytesSchema, OdgEditor, OdgLineVector, OdgPage, OdgPathVector, OdpBytesSchema, OdpEditor, OdpShape, OdpSlide, OdsBytesSchema, OdsCell, OdsEditor, OdsSheet, OdtBytesSchema, OdtEditor, OdtList, OdtListItem, OdtParagraph, OdtRun, OdtTable, OdtTableCell, OdtTableRow, PAGE_SIZE_A4, PAGE_SIZE_LETTER, PackageSchema, PartSchema, PdfBytesSchema, PdfEncryptedError, PdfParseError, PptxBytesSchema, PptxEditor, PptxShape, PptxSlide, SLIDE_SIZE_STANDARD, SLIDE_SIZE_WIDESCREEN, XlsxBytesSchema, XmlCdataSchema, XmlCommentSchema, XmlDeclarationSchema, XmlElementSchema, XmlNodeSchema, XmlPartSchema, XmlPiSchema, XmlTextSchema, attr, base64ToBytes, buildDocxPackage, buildOdgPackage, buildOdpPackage, buildOdsPackage, buildOdtPackage, buildPptxPackage, buildXml, bytesToBase64, childrenWithTag, compactCodec, compactPackageCodec, convertDrawingToLayout, convertPresentationToLayout, convertSpreadsheetToLayout, convertWordprocessingToLayout, createDocx, createLocalDocumentConverter, createOdg, createOdp, createOds, createOdt, createPptx, decodeCompactPackage, decodeEntities, decodePackage, docxPdfCodec, docxToOdt, docxToPdf, elementsWithTag, encodeCompactPackage, encodePackage, fixedClock, flipY, fromCompact, isCompactXmlNode, isContentBlock, isXmlNode, odgPdfCodec, odgToPdf, odpPdfCodec, odpPptxCodec, odpToPdf, odpToPptx, odsPdfCodec, odsToPdf, odsToXlsx, odsXlsxCodec, odtDocxCodec, odtPdfCodec, odtToDocx, odtToPdf, openDocx, openOdg, openOdp, openOds, openOdt, openPptx, packageCodec, parsePackage, parseXml, pdfCodec, pdfToDocx, pdfToOdg, pdfToOdp, pdfToOds, pdfToOdt, pdfToPptx, pptxPdfCodec, pptxToOdp, pptxToPdf, readDocxContent, readOdgContent, readOdpContent, readOdsContent, readOdtContent, readPdf, readPptxContent, reconstructDrawing, reconstructPresentation, reconstructSpreadsheet, reconstructWordprocessing, resolveRelationships, rgbHexToColor, rootElement, serializePackage, systemClock, textContent, throwIfAborted, toCompact, unzipPackage, walk, writePdf, xlsxToOds, xmlCodec, zipPackage };