documents.js 1.46.1 → 1.48.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/README.md +34 -23
- package/dist/index.cjs +680 -61
- package/dist/index.d.cts +10 -2
- package/dist/index.d.ts +10 -2
- package/dist/index.js +676 -63
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -536,7 +536,7 @@ function needsSpacePreserve(text) {
|
|
|
536
536
|
}
|
|
537
537
|
//#endregion
|
|
538
538
|
//#region src/edit/docx/run.ts
|
|
539
|
-
function directChild$
|
|
539
|
+
function directChild$11(parent, tag) {
|
|
540
540
|
for (const child of parent.children) if (child.type === "element" && child.tag === tag) return child;
|
|
541
541
|
}
|
|
542
542
|
function appendUElement(rPr, value) {
|
|
@@ -545,7 +545,7 @@ function appendUElement(rPr, value) {
|
|
|
545
545
|
return created;
|
|
546
546
|
}
|
|
547
547
|
function findOrCreateT(run) {
|
|
548
|
-
const existing = directChild$
|
|
548
|
+
const existing = directChild$11(run, "w:t");
|
|
549
549
|
if (existing !== void 0) return existing;
|
|
550
550
|
const created = el("w:t");
|
|
551
551
|
run.children.push(created);
|
|
@@ -565,7 +565,7 @@ var DocxRun = class {
|
|
|
565
565
|
}
|
|
566
566
|
rPr(create) {
|
|
567
567
|
const node = this.live();
|
|
568
|
-
return create ? ensureFirstChild(node, "w:rPr") : directChild$
|
|
568
|
+
return create ? ensureFirstChild(node, "w:rPr") : directChild$11(node, "w:rPr");
|
|
569
569
|
}
|
|
570
570
|
get text() {
|
|
571
571
|
return (0, ooxml_js.textContent)(this.live());
|
|
@@ -589,14 +589,14 @@ var DocxRun = class {
|
|
|
589
589
|
}
|
|
590
590
|
get underline() {
|
|
591
591
|
const rPr = this.rPr(false);
|
|
592
|
-
const uElement = rPr === void 0 ? void 0 : directChild$
|
|
592
|
+
const uElement = rPr === void 0 ? void 0 : directChild$11(rPr, "w:u");
|
|
593
593
|
if (uElement === void 0) return false;
|
|
594
594
|
for (const a of uElement.attributes) if (a.name === "w:val") return a.value !== "none";
|
|
595
595
|
return true;
|
|
596
596
|
}
|
|
597
597
|
set underline(value) {
|
|
598
598
|
const rPr = this.rPr(true);
|
|
599
|
-
const existing = directChild$
|
|
599
|
+
const existing = directChild$11(rPr, "w:u");
|
|
600
600
|
if (existing === void 0) {
|
|
601
601
|
appendUElement(rPr, value);
|
|
602
602
|
return;
|
|
@@ -670,7 +670,7 @@ function buildRun$1(init = {}) {
|
|
|
670
670
|
}
|
|
671
671
|
//#endregion
|
|
672
672
|
//#region src/edit/docx/paragraph.ts
|
|
673
|
-
function directChild$
|
|
673
|
+
function directChild$10(parent, tag) {
|
|
674
674
|
for (const child of parent.children) if (child.type === "element" && child.tag === tag) return child;
|
|
675
675
|
}
|
|
676
676
|
var DocxParagraph = class {
|
|
@@ -689,7 +689,7 @@ var DocxParagraph = class {
|
|
|
689
689
|
}
|
|
690
690
|
pPr(create) {
|
|
691
691
|
const node = this.live();
|
|
692
|
-
return create ? ensureFirstChild(node, "w:pPr") : directChild$
|
|
692
|
+
return create ? ensureFirstChild(node, "w:pPr") : directChild$10(node, "w:pPr");
|
|
693
693
|
}
|
|
694
694
|
get text() {
|
|
695
695
|
return (0, ooxml_js.textContent)(this.live());
|
|
@@ -726,7 +726,7 @@ var DocxParagraph = class {
|
|
|
726
726
|
set styleId(value) {
|
|
727
727
|
if (value === void 0) {
|
|
728
728
|
const pPr = this.pPr(false);
|
|
729
|
-
const existing = pPr === void 0 ? void 0 : directChild$
|
|
729
|
+
const existing = pPr === void 0 ? void 0 : directChild$10(pPr, "w:pStyle");
|
|
730
730
|
if (existing !== void 0 && pPr !== void 0) removeChild(pPr.children, existing);
|
|
731
731
|
return;
|
|
732
732
|
}
|
|
@@ -738,7 +738,7 @@ var DocxParagraph = class {
|
|
|
738
738
|
set alignment(value) {
|
|
739
739
|
if (value === void 0) {
|
|
740
740
|
const pPr = this.pPr(false);
|
|
741
|
-
const existing = pPr === void 0 ? void 0 : directChild$
|
|
741
|
+
const existing = pPr === void 0 ? void 0 : directChild$10(pPr, "w:jc");
|
|
742
742
|
if (existing !== void 0 && pPr !== void 0) removeChild(pPr.children, existing);
|
|
743
743
|
return;
|
|
744
744
|
}
|
|
@@ -746,12 +746,12 @@ var DocxParagraph = class {
|
|
|
746
746
|
}
|
|
747
747
|
get list() {
|
|
748
748
|
const pPr = this.pPr(false);
|
|
749
|
-
const numPr = pPr === void 0 ? void 0 : directChild$
|
|
749
|
+
const numPr = pPr === void 0 ? void 0 : directChild$10(pPr, "w:numPr");
|
|
750
750
|
if (numPr === void 0) return;
|
|
751
|
-
const numIdElement = directChild$
|
|
751
|
+
const numIdElement = directChild$10(numPr, "w:numId");
|
|
752
752
|
const numId = numIdElement === void 0 ? void 0 : (0, ooxml_js.attr)(numIdElement, "w:val");
|
|
753
753
|
if (numId === void 0) return;
|
|
754
|
-
const ilvlElement = directChild$
|
|
754
|
+
const ilvlElement = directChild$10(numPr, "w:ilvl");
|
|
755
755
|
const ilvl = ilvlElement === void 0 ? void 0 : (0, ooxml_js.attr)(ilvlElement, "w:val");
|
|
756
756
|
return {
|
|
757
757
|
numId,
|
|
@@ -761,7 +761,7 @@ var DocxParagraph = class {
|
|
|
761
761
|
set list(value) {
|
|
762
762
|
const pPr = this.pPr(true);
|
|
763
763
|
if (value === void 0) {
|
|
764
|
-
const existing = directChild$
|
|
764
|
+
const existing = directChild$10(pPr, "w:numPr");
|
|
765
765
|
if (existing !== void 0) removeChild(pPr.children, existing);
|
|
766
766
|
return;
|
|
767
767
|
}
|
|
@@ -1426,7 +1426,7 @@ function createEmptyPptxPackage() {
|
|
|
1426
1426
|
}
|
|
1427
1427
|
//#endregion
|
|
1428
1428
|
//#region src/edit/pptx/shape.ts
|
|
1429
|
-
function directChild$
|
|
1429
|
+
function directChild$9(parent, tag) {
|
|
1430
1430
|
for (const child of parent.children) if (child.type === "element" && child.tag === tag) return child;
|
|
1431
1431
|
}
|
|
1432
1432
|
function parseEmuAttr(element, name) {
|
|
@@ -1447,7 +1447,7 @@ var PptxShape = class {
|
|
|
1447
1447
|
}
|
|
1448
1448
|
spPrElement(create) {
|
|
1449
1449
|
const node = this.live();
|
|
1450
|
-
const existing = directChild$
|
|
1450
|
+
const existing = directChild$9(node, "p:spPr");
|
|
1451
1451
|
if (existing !== void 0 || !create) return existing;
|
|
1452
1452
|
const created = el("p:spPr");
|
|
1453
1453
|
node.children.push(created);
|
|
@@ -1455,10 +1455,10 @@ var PptxShape = class {
|
|
|
1455
1455
|
}
|
|
1456
1456
|
get frame() {
|
|
1457
1457
|
const spPr = this.spPrElement(false);
|
|
1458
|
-
const xfrm = spPr === void 0 ? void 0 : directChild$
|
|
1458
|
+
const xfrm = spPr === void 0 ? void 0 : directChild$9(spPr, "a:xfrm");
|
|
1459
1459
|
if (xfrm === void 0) return;
|
|
1460
|
-
const off = directChild$
|
|
1461
|
-
const ext = directChild$
|
|
1460
|
+
const off = directChild$9(xfrm, "a:off");
|
|
1461
|
+
const ext = directChild$9(xfrm, "a:ext");
|
|
1462
1462
|
if (off === void 0 || ext === void 0) return;
|
|
1463
1463
|
const x = parseEmuAttr(off, "x");
|
|
1464
1464
|
const y = parseEmuAttr(off, "y");
|
|
@@ -1474,7 +1474,7 @@ var PptxShape = class {
|
|
|
1474
1474
|
}
|
|
1475
1475
|
set frame(value) {
|
|
1476
1476
|
const spPr = this.spPrElement(true);
|
|
1477
|
-
let xfrm = directChild$
|
|
1477
|
+
let xfrm = directChild$9(spPr, "a:xfrm");
|
|
1478
1478
|
if (xfrm === void 0) {
|
|
1479
1479
|
xfrm = el("a:xfrm");
|
|
1480
1480
|
spPr.children.unshift(xfrm);
|
|
@@ -1488,12 +1488,12 @@ var PptxShape = class {
|
|
|
1488
1488
|
})];
|
|
1489
1489
|
}
|
|
1490
1490
|
get text() {
|
|
1491
|
-
const txBody = directChild$
|
|
1491
|
+
const txBody = directChild$9(this.live(), "p:txBody");
|
|
1492
1492
|
return txBody === void 0 ? "" : (0, ooxml_js.textContent)(txBody);
|
|
1493
1493
|
}
|
|
1494
1494
|
set text(value) {
|
|
1495
1495
|
const node = this.live();
|
|
1496
|
-
let txBody = directChild$
|
|
1496
|
+
let txBody = directChild$9(node, "p:txBody");
|
|
1497
1497
|
if (txBody === void 0) {
|
|
1498
1498
|
txBody = el("p:txBody", {}, [el("a:bodyPr"), el("a:lstStyle")]);
|
|
1499
1499
|
node.children.push(txBody);
|
|
@@ -1504,7 +1504,7 @@ var PptxShape = class {
|
|
|
1504
1504
|
}
|
|
1505
1505
|
setParagraphs(paragraphs) {
|
|
1506
1506
|
const node = this.live();
|
|
1507
|
-
let txBody = directChild$
|
|
1507
|
+
let txBody = directChild$9(node, "p:txBody");
|
|
1508
1508
|
if (txBody === void 0) {
|
|
1509
1509
|
txBody = el("p:txBody", {}, [el("a:bodyPr"), el("a:lstStyle")]);
|
|
1510
1510
|
node.children.push(txBody);
|
|
@@ -1615,12 +1615,12 @@ function insertPictureShapeMedia(context, slideRoot, frame, image) {
|
|
|
1615
1615
|
}
|
|
1616
1616
|
//#endregion
|
|
1617
1617
|
//#region src/edit/pptx/slide.ts
|
|
1618
|
-
function directChild$
|
|
1618
|
+
function directChild$8(parent, tag) {
|
|
1619
1619
|
for (const child of parent.children) if (child.type === "element" && child.tag === tag) return child;
|
|
1620
1620
|
}
|
|
1621
1621
|
function findSpTree(slideRoot) {
|
|
1622
|
-
const cSld = directChild$
|
|
1623
|
-
const spTree = cSld === void 0 ? void 0 : directChild$
|
|
1622
|
+
const cSld = directChild$8(slideRoot, "p:cSld");
|
|
1623
|
+
const spTree = cSld === void 0 ? void 0 : directChild$8(cSld, "p:spTree");
|
|
1624
1624
|
if (spTree === void 0) throw new Error("slide has no p:cSld/p:spTree element");
|
|
1625
1625
|
return spTree;
|
|
1626
1626
|
}
|
|
@@ -1752,7 +1752,7 @@ const PRESENTATION_PART_PATH = "ppt/presentation.xml";
|
|
|
1752
1752
|
const MEDIA_DIR = "ppt/media";
|
|
1753
1753
|
const SLIDE_CONTENT_TYPE = "application/vnd.openxmlformats-officedocument.presentationml.slide+xml";
|
|
1754
1754
|
const SLIDE_RELATIONSHIP_TYPE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/slide";
|
|
1755
|
-
function directChild$
|
|
1755
|
+
function directChild$7(parent, tag) {
|
|
1756
1756
|
for (const child of parent.children) if (child.type === "element" && child.tag === tag) return child;
|
|
1757
1757
|
}
|
|
1758
1758
|
function attrValue(element, name) {
|
|
@@ -1764,12 +1764,12 @@ function findPresentationRoot(pkg) {
|
|
|
1764
1764
|
return root;
|
|
1765
1765
|
}
|
|
1766
1766
|
function findSldIdLst(presentationRoot) {
|
|
1767
|
-
const sldIdLst = directChild$
|
|
1767
|
+
const sldIdLst = directChild$7(presentationRoot, "p:sldIdLst");
|
|
1768
1768
|
if (sldIdLst === void 0) throw new Error(`${PRESENTATION_PART_PATH} has no p:sldIdLst element`);
|
|
1769
1769
|
return sldIdLst;
|
|
1770
1770
|
}
|
|
1771
1771
|
function findSldSz(presentationRoot) {
|
|
1772
|
-
const sldSz = directChild$
|
|
1772
|
+
const sldSz = directChild$7(presentationRoot, "p:sldSz");
|
|
1773
1773
|
if (sldSz === void 0) throw new Error(`${PRESENTATION_PART_PATH} has no p:sldSz element`);
|
|
1774
1774
|
return sldSz;
|
|
1775
1775
|
}
|
|
@@ -1968,12 +1968,12 @@ function appendShape$2(slide, shape) {
|
|
|
1968
1968
|
}
|
|
1969
1969
|
//#endregion
|
|
1970
1970
|
//#region src/edit/odt/automatic-styles.ts
|
|
1971
|
-
const CONTENT_PART_PATH$
|
|
1971
|
+
const CONTENT_PART_PATH$5 = "content.xml";
|
|
1972
1972
|
function ensureAutomaticStyles(pkg) {
|
|
1973
|
-
const part = pkg.parts[CONTENT_PART_PATH$
|
|
1974
|
-
if (part?.kind !== "xml") throw new Error(`ensureAutomaticStyles: package has no ${CONTENT_PART_PATH$
|
|
1973
|
+
const part = pkg.parts[CONTENT_PART_PATH$5];
|
|
1974
|
+
if (part?.kind !== "xml") throw new Error(`ensureAutomaticStyles: package has no ${CONTENT_PART_PATH$5} part`);
|
|
1975
1975
|
const root = part.nodes.find((n) => n.type === "element");
|
|
1976
|
-
if (root === void 0) throw new Error(`ensureAutomaticStyles: ${CONTENT_PART_PATH$
|
|
1976
|
+
if (root === void 0) throw new Error(`ensureAutomaticStyles: ${CONTENT_PART_PATH$5} has no root element`);
|
|
1977
1977
|
for (const child of root.children) if (child.type === "element" && child.tag === "office:automatic-styles") return child;
|
|
1978
1978
|
const created = el("office:automatic-styles");
|
|
1979
1979
|
const insertBeforeTags = /* @__PURE__ */ new Set([
|
|
@@ -2067,7 +2067,7 @@ function applyStyleChange(pkg, element, family, change) {
|
|
|
2067
2067
|
...readCurrentStyleProperties(pkg, element, family),
|
|
2068
2068
|
...change
|
|
2069
2069
|
};
|
|
2070
|
-
const name = odf_js.StyleRegistry.forPart(pkg, CONTENT_PART_PATH$
|
|
2070
|
+
const name = odf_js.StyleRegistry.forPart(pkg, CONTENT_PART_PATH$5).intern({
|
|
2071
2071
|
family,
|
|
2072
2072
|
properties: merged
|
|
2073
2073
|
});
|
|
@@ -2326,7 +2326,7 @@ const META_NS_PREFIXES$3 = [
|
|
|
2326
2326
|
const ODF_VERSION$3 = "1.3";
|
|
2327
2327
|
const PAGE_LAYOUT_NAME$3 = "PM1";
|
|
2328
2328
|
const MASTER_PAGE_NAME$3 = "Standard";
|
|
2329
|
-
const DEFAULT_MARGIN_PT = 72;
|
|
2329
|
+
const DEFAULT_MARGIN_PT$1 = 72;
|
|
2330
2330
|
function declaration$3() {
|
|
2331
2331
|
return {
|
|
2332
2332
|
type: "declaration",
|
|
@@ -2350,10 +2350,10 @@ function buildPageLayout$3() {
|
|
|
2350
2350
|
return el("style:page-layout", { "style:name": PAGE_LAYOUT_NAME$3 }, [el("style:page-layout-properties", {
|
|
2351
2351
|
"fo:page-width": `${document_content_model.PAGE_SIZE_LETTER.widthPt}pt`,
|
|
2352
2352
|
"fo:page-height": `${document_content_model.PAGE_SIZE_LETTER.heightPt}pt`,
|
|
2353
|
-
"fo:margin-top": `${DEFAULT_MARGIN_PT}pt`,
|
|
2354
|
-
"fo:margin-right": `${DEFAULT_MARGIN_PT}pt`,
|
|
2355
|
-
"fo:margin-bottom": `${DEFAULT_MARGIN_PT}pt`,
|
|
2356
|
-
"fo:margin-left": `${DEFAULT_MARGIN_PT}pt`
|
|
2353
|
+
"fo:margin-top": `${DEFAULT_MARGIN_PT$1}pt`,
|
|
2354
|
+
"fo:margin-right": `${DEFAULT_MARGIN_PT$1}pt`,
|
|
2355
|
+
"fo:margin-bottom": `${DEFAULT_MARGIN_PT$1}pt`,
|
|
2356
|
+
"fo:margin-left": `${DEFAULT_MARGIN_PT$1}pt`
|
|
2357
2357
|
})]);
|
|
2358
2358
|
}
|
|
2359
2359
|
function buildStylesXml$3() {
|
|
@@ -2514,20 +2514,20 @@ function buildTable(pkg, init) {
|
|
|
2514
2514
|
}
|
|
2515
2515
|
//#endregion
|
|
2516
2516
|
//#region src/edit/odt/editor.ts
|
|
2517
|
-
const CONTENT_PART_PATH$
|
|
2517
|
+
const CONTENT_PART_PATH$4 = "content.xml";
|
|
2518
2518
|
function findContentRoot(pkg) {
|
|
2519
|
-
const part = pkg.parts[CONTENT_PART_PATH$
|
|
2519
|
+
const part = pkg.parts[CONTENT_PART_PATH$4];
|
|
2520
2520
|
const root = part?.kind === "xml" ? part.nodes.find((n) => n.type === "element") : void 0;
|
|
2521
|
-
if (root === void 0) throw new Error(`package has no root element at ${CONTENT_PART_PATH$
|
|
2521
|
+
if (root === void 0) throw new Error(`package has no root element at ${CONTENT_PART_PATH$4}`);
|
|
2522
2522
|
return root;
|
|
2523
2523
|
}
|
|
2524
|
-
function directChild$
|
|
2524
|
+
function directChild$6(parent, tag) {
|
|
2525
2525
|
for (const child of parent.children) if (child.type === "element" && child.tag === tag) return child;
|
|
2526
2526
|
}
|
|
2527
2527
|
function findOfficeText(contentRoot) {
|
|
2528
|
-
const body = directChild$
|
|
2529
|
-
const text = body === void 0 ? void 0 : directChild$
|
|
2530
|
-
if (text === void 0) throw new Error(`${CONTENT_PART_PATH$
|
|
2528
|
+
const body = directChild$6(contentRoot, "office:body");
|
|
2529
|
+
const text = body === void 0 ? void 0 : directChild$6(body, "office:text");
|
|
2530
|
+
if (text === void 0) throw new Error(`${CONTENT_PART_PATH$4} has no office:body/office:text element`);
|
|
2531
2531
|
return text;
|
|
2532
2532
|
}
|
|
2533
2533
|
var OdtBodyImpl = class {
|
|
@@ -2790,7 +2790,7 @@ function addImageMedia(pkg, imageBytes, format) {
|
|
|
2790
2790
|
}
|
|
2791
2791
|
//#endregion
|
|
2792
2792
|
//#region src/edit/odp/shape.ts
|
|
2793
|
-
function directChild$
|
|
2793
|
+
function directChild$5(parent, tag) {
|
|
2794
2794
|
for (const child of parent.children) if (child.type === "element" && child.tag === tag) return child;
|
|
2795
2795
|
}
|
|
2796
2796
|
function buildTransformAttr(frame, rotationDeg) {
|
|
@@ -2858,7 +2858,7 @@ var OdpShape = class {
|
|
|
2858
2858
|
}
|
|
2859
2859
|
textBox(create) {
|
|
2860
2860
|
const node = this.live();
|
|
2861
|
-
const existing = directChild$
|
|
2861
|
+
const existing = directChild$5(node, "draw:text-box");
|
|
2862
2862
|
if (existing !== void 0 || !create) return existing;
|
|
2863
2863
|
const created = el("draw:text-box");
|
|
2864
2864
|
node.children.push(created);
|
|
@@ -2919,7 +2919,7 @@ function insertImageFrameMedia(context, frame, image) {
|
|
|
2919
2919
|
}
|
|
2920
2920
|
//#endregion
|
|
2921
2921
|
//#region src/edit/odp/slide.ts
|
|
2922
|
-
function directChild$
|
|
2922
|
+
function directChild$4(parent, tag) {
|
|
2923
2923
|
for (const child of parent.children) if (child.type === "element" && child.tag === tag) return child;
|
|
2924
2924
|
}
|
|
2925
2925
|
const NOTES_FRAME_X_PT = 20;
|
|
@@ -2968,13 +2968,13 @@ var OdpSlide = class {
|
|
|
2968
2968
|
return new OdpShape(node.children, frameElement, this.context.pkg);
|
|
2969
2969
|
}
|
|
2970
2970
|
get notes() {
|
|
2971
|
-
const notesElement = directChild$
|
|
2971
|
+
const notesElement = directChild$4(this.live(), "presentation:notes");
|
|
2972
2972
|
if (notesElement === void 0) return "";
|
|
2973
2973
|
return (0, ooxml_js.elementsWithTag)(notesElement.children, "text:p").map((p) => decodeOdfText(p.children)).join("\n");
|
|
2974
2974
|
}
|
|
2975
2975
|
set notes(value) {
|
|
2976
2976
|
const node = this.live();
|
|
2977
|
-
const existing = directChild$
|
|
2977
|
+
const existing = directChild$4(node, "presentation:notes");
|
|
2978
2978
|
const notesElement = buildNotesElement(this.context.pkg, value);
|
|
2979
2979
|
if (existing === void 0) node.children.push(notesElement);
|
|
2980
2980
|
else existing.children = notesElement.children;
|
|
@@ -2986,27 +2986,27 @@ var OdpSlide = class {
|
|
|
2986
2986
|
};
|
|
2987
2987
|
//#endregion
|
|
2988
2988
|
//#region src/edit/odp/editor.ts
|
|
2989
|
-
const CONTENT_PART_PATH$
|
|
2990
|
-
const STYLES_PART_PATH$
|
|
2991
|
-
function directChild$
|
|
2989
|
+
const CONTENT_PART_PATH$3 = "content.xml";
|
|
2990
|
+
const STYLES_PART_PATH$2 = "styles.xml";
|
|
2991
|
+
function directChild$3(parent, tag) {
|
|
2992
2992
|
for (const child of parent.children) if (child.type === "element" && child.tag === tag) return child;
|
|
2993
2993
|
}
|
|
2994
|
-
function findRoot$
|
|
2994
|
+
function findRoot$3(pkg, partPath) {
|
|
2995
2995
|
const part = pkg.parts[partPath];
|
|
2996
2996
|
const root = part?.kind === "xml" ? part.nodes.find((n) => n.type === "element") : void 0;
|
|
2997
2997
|
if (root === void 0) throw new Error(`package has no root element at ${partPath}`);
|
|
2998
2998
|
return root;
|
|
2999
2999
|
}
|
|
3000
3000
|
function findOfficePresentation(pkg) {
|
|
3001
|
-
const body = directChild$
|
|
3002
|
-
const presentation = body === void 0 ? void 0 : directChild$
|
|
3003
|
-
if (presentation === void 0) throw new Error(`${CONTENT_PART_PATH$
|
|
3001
|
+
const body = directChild$3(findRoot$3(pkg, CONTENT_PART_PATH$3), "office:body");
|
|
3002
|
+
const presentation = body === void 0 ? void 0 : directChild$3(body, "office:presentation");
|
|
3003
|
+
if (presentation === void 0) throw new Error(`${CONTENT_PART_PATH$3} has no office:body/office:presentation element`);
|
|
3004
3004
|
return presentation;
|
|
3005
3005
|
}
|
|
3006
3006
|
function findPageLayoutProperties$1(pkg) {
|
|
3007
|
-
const pageLayout = directChild$
|
|
3008
|
-
const properties = pageLayout === void 0 ? void 0 : directChild$
|
|
3009
|
-
if (properties === void 0) throw new Error(`${STYLES_PART_PATH$
|
|
3007
|
+
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" && (0, ooxml_js.attr)(c, "style:name") === "PM1");
|
|
3008
|
+
const properties = pageLayout === void 0 ? void 0 : directChild$3(pageLayout, "style:page-layout-properties");
|
|
3009
|
+
if (properties === void 0) throw new Error(`${STYLES_PART_PATH$2} has no style:page-layout[style:name="PM1"]/style:page-layout-properties element`);
|
|
3010
3010
|
return properties;
|
|
3011
3011
|
}
|
|
3012
3012
|
var OdpEditor = class {
|
|
@@ -3508,6 +3508,87 @@ var OdsCell = class {
|
|
|
3508
3508
|
}
|
|
3509
3509
|
};
|
|
3510
3510
|
//#endregion
|
|
3511
|
+
//#region src/edit/ods/print-settings.ts
|
|
3512
|
+
const STYLES_PART_PATH$1 = "styles.xml";
|
|
3513
|
+
const CONTENT_PART_PATH$2 = "content.xml";
|
|
3514
|
+
function findRoot$2(pkg, partPath) {
|
|
3515
|
+
const part = pkg.parts[partPath];
|
|
3516
|
+
const root = part?.kind === "xml" ? part.nodes.find((n) => n.type === "element") : void 0;
|
|
3517
|
+
if (root === void 0) throw new Error(`package has no root element at ${partPath}`);
|
|
3518
|
+
return root;
|
|
3519
|
+
}
|
|
3520
|
+
function directChild$2(parent, tag) {
|
|
3521
|
+
for (const child of parent.children) if (child.type === "element" && child.tag === tag) return child;
|
|
3522
|
+
}
|
|
3523
|
+
function findStylesAutomaticStyles(pkg) {
|
|
3524
|
+
const found = directChild$2(findRoot$2(pkg, STYLES_PART_PATH$1), "office:automatic-styles");
|
|
3525
|
+
if (found === void 0) throw new Error(`${STYLES_PART_PATH$1} has no office:automatic-styles element`);
|
|
3526
|
+
return found;
|
|
3527
|
+
}
|
|
3528
|
+
function findMasterStyles(pkg) {
|
|
3529
|
+
const found = directChild$2(findRoot$2(pkg, STYLES_PART_PATH$1), "office:master-styles");
|
|
3530
|
+
if (found === void 0) throw new Error(`${STYLES_PART_PATH$1} has no office:master-styles element`);
|
|
3531
|
+
return found;
|
|
3532
|
+
}
|
|
3533
|
+
function findContentAutomaticStyles(pkg) {
|
|
3534
|
+
const found = directChild$2(findRoot$2(pkg, CONTENT_PART_PATH$2), "office:automatic-styles");
|
|
3535
|
+
if (found === void 0) throw new Error(`${CONTENT_PART_PATH$2} has no office:automatic-styles element`);
|
|
3536
|
+
return found;
|
|
3537
|
+
}
|
|
3538
|
+
const DEFAULT_MARGIN_PT = 56.69291338582677;
|
|
3539
|
+
const DEFAULT_MARGINS = {
|
|
3540
|
+
topPt: DEFAULT_MARGIN_PT,
|
|
3541
|
+
rightPt: DEFAULT_MARGIN_PT,
|
|
3542
|
+
bottomPt: DEFAULT_MARGIN_PT,
|
|
3543
|
+
leftPt: DEFAULT_MARGIN_PT
|
|
3544
|
+
};
|
|
3545
|
+
function readSheetPrintSettings(pkg, tableElement) {
|
|
3546
|
+
const tableStyleName = (0, ooxml_js.attr)(tableElement, "table:style-name");
|
|
3547
|
+
const tableStyleElement = tableStyleName === void 0 ? void 0 : (0, odf_js.findStyleElement)(tableStyleName, "table", pkg);
|
|
3548
|
+
const masterPageName = tableStyleElement === void 0 ? void 0 : (0, ooxml_js.attr)(tableStyleElement, "style:master-page-name");
|
|
3549
|
+
const layoutProperties = (0, odf_js.resolvePageLayoutProperties)(pkg, masterPageName);
|
|
3550
|
+
const pageSize = layoutProperties === void 0 ? void 0 : (0, odf_js.parsePageSize)(layoutProperties);
|
|
3551
|
+
const margins = layoutProperties === void 0 ? void 0 : (0, odf_js.parseMargins)(layoutProperties);
|
|
3552
|
+
const printTokens = new Set((layoutProperties === void 0 ? void 0 : (0, ooxml_js.attr)(layoutProperties, "style:print"))?.split(" ").filter((token) => token.length > 0) ?? []);
|
|
3553
|
+
const pageOrder = (layoutProperties === void 0 ? void 0 : (0, ooxml_js.attr)(layoutProperties, "style:print-page-order")) === "ltr" ? "overThenDown" : "downThenOver";
|
|
3554
|
+
return {
|
|
3555
|
+
pageSize: pageSize ?? document_content_model.PAGE_SIZE_A4,
|
|
3556
|
+
margins: margins ?? DEFAULT_MARGINS,
|
|
3557
|
+
gridlines: printTokens.has("grid"),
|
|
3558
|
+
headers: printTokens.has("headers"),
|
|
3559
|
+
pageOrder
|
|
3560
|
+
};
|
|
3561
|
+
}
|
|
3562
|
+
function writeSheetPrintSettings(pkg, tableElement, settings) {
|
|
3563
|
+
const stylesAutomaticStyles = findStylesAutomaticStyles(pkg);
|
|
3564
|
+
const masterStyles = findMasterStyles(pkg);
|
|
3565
|
+
const contentAutomaticStyles = findContentAutomaticStyles(pkg);
|
|
3566
|
+
const printTokens = [settings.gridlines ? "grid" : void 0, settings.headers ? "headers" : void 0].filter((token) => token !== void 0);
|
|
3567
|
+
const pageLayoutName = nextStyleName(stylesAutomaticStyles, "style:page-layout", "OdsPageLayout");
|
|
3568
|
+
stylesAutomaticStyles.children.push(el("style:page-layout", { "style:name": pageLayoutName }, [el("style:page-layout-properties", {
|
|
3569
|
+
"fo:page-width": (0, odf_js.formatOdfLength)(settings.pageSize.widthPt),
|
|
3570
|
+
"fo:page-height": (0, odf_js.formatOdfLength)(settings.pageSize.heightPt),
|
|
3571
|
+
"fo:margin-top": (0, odf_js.formatOdfLength)(settings.margins.topPt),
|
|
3572
|
+
"fo:margin-right": (0, odf_js.formatOdfLength)(settings.margins.rightPt),
|
|
3573
|
+
"fo:margin-bottom": (0, odf_js.formatOdfLength)(settings.margins.bottomPt),
|
|
3574
|
+
"fo:margin-left": (0, odf_js.formatOdfLength)(settings.margins.leftPt),
|
|
3575
|
+
...printTokens.length > 0 ? { "style:print": printTokens.join(" ") } : {},
|
|
3576
|
+
"style:print-page-order": settings.pageOrder === "overThenDown" ? "ltr" : "ttb"
|
|
3577
|
+
})]));
|
|
3578
|
+
const masterPageName = nextStyleName(masterStyles, "style:master-page", "OdsMasterPage");
|
|
3579
|
+
masterStyles.children.push(el("style:master-page", {
|
|
3580
|
+
"style:name": masterPageName,
|
|
3581
|
+
"style:page-layout-name": pageLayoutName
|
|
3582
|
+
}));
|
|
3583
|
+
const tableStyleName = nextStyleName(contentAutomaticStyles, "style:style", "OdsSheetPrint");
|
|
3584
|
+
contentAutomaticStyles.children.push(el("style:style", {
|
|
3585
|
+
"style:name": tableStyleName,
|
|
3586
|
+
"style:family": "table",
|
|
3587
|
+
"style:master-page-name": masterPageName
|
|
3588
|
+
}));
|
|
3589
|
+
setAttr(tableElement, "table:style-name", tableStyleName);
|
|
3590
|
+
}
|
|
3591
|
+
//#endregion
|
|
3511
3592
|
//#region src/edit/ods/sheet.ts
|
|
3512
3593
|
const NAME_ATTR = "table:name";
|
|
3513
3594
|
var OdsSheet = class {
|
|
@@ -3532,6 +3613,12 @@ var OdsSheet = class {
|
|
|
3532
3613
|
set name(value) {
|
|
3533
3614
|
setAttr(this.live(), NAME_ATTR, value);
|
|
3534
3615
|
}
|
|
3616
|
+
get printSettings() {
|
|
3617
|
+
return readSheetPrintSettings(this.pkg, this.live());
|
|
3618
|
+
}
|
|
3619
|
+
set printSettings(value) {
|
|
3620
|
+
writeSheetPrintSettings(this.pkg, this.live(), value);
|
|
3621
|
+
}
|
|
3535
3622
|
cell(row, column) {
|
|
3536
3623
|
const node = resolveCellNode(this.live(), row, column);
|
|
3537
3624
|
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`);
|
|
@@ -3644,6 +3731,7 @@ function buildOdsPackage(content) {
|
|
|
3644
3731
|
if (content.sheets.length > 0) editor.removeSheetAt(0);
|
|
3645
3732
|
for (const sheet of content.sheets) {
|
|
3646
3733
|
const odsSheet = editor.addSheet(sheet.name);
|
|
3734
|
+
odsSheet.printSettings = sheet.printSettings;
|
|
3647
3735
|
for (const cell of sheet.cells) appendCell(odsSheet, cell);
|
|
3648
3736
|
}
|
|
3649
3737
|
return editor.toPackage();
|
|
@@ -3762,7 +3850,10 @@ const GRAPHIC_STYLE_PREFIX = "gr";
|
|
|
3762
3850
|
function graphicPropertyAttrs(init) {
|
|
3763
3851
|
const attrs = {};
|
|
3764
3852
|
if (init.fill === void 0) attrs["draw:fill"] = "none";
|
|
3765
|
-
else
|
|
3853
|
+
else {
|
|
3854
|
+
attrs["draw:fill"] = "solid";
|
|
3855
|
+
attrs["draw:fill-color"] = (0, odf_js.formatOdfColor)(init.fill);
|
|
3856
|
+
}
|
|
3766
3857
|
if (init.stroke === void 0) attrs["draw:stroke"] = "none";
|
|
3767
3858
|
else {
|
|
3768
3859
|
attrs["svg:stroke-color"] = (0, odf_js.formatOdfColor)(init.stroke.color);
|
|
@@ -8442,6 +8533,7 @@ function writeEllipse(writer, item) {
|
|
|
8442
8533
|
writer.writeAscii(`${formatPoint(cx - kx, cy + ry)} ${formatPoint(cx - rx, cy + ky)} ${formatPoint(cx - rx, cy)} c\n`);
|
|
8443
8534
|
writer.writeAscii(`${formatPoint(cx - rx, cy - ky)} ${formatPoint(cx - kx, cy - ry)} ${formatPoint(cx, cy - ry)} c\n`);
|
|
8444
8535
|
writer.writeAscii(`${formatPoint(cx + kx, cy - ry)} ${formatPoint(cx + rx, cy - ky)} ${formatPoint(cx + rx, cy)} c\n`);
|
|
8536
|
+
writer.writeAscii("h\n");
|
|
8445
8537
|
writer.writeAscii(`${paint}\n`);
|
|
8446
8538
|
}
|
|
8447
8539
|
function writeSubpath(writer, subpath) {
|
|
@@ -10824,6 +10916,471 @@ function imageToShape(img, slideHeightPt, images) {
|
|
|
10824
10916
|
}]
|
|
10825
10917
|
};
|
|
10826
10918
|
}
|
|
10919
|
+
function reconstructDrawing(doc, options) {
|
|
10920
|
+
const signal = options?.signal;
|
|
10921
|
+
const pages = doc.pages.map((page) => {
|
|
10922
|
+
throwIfAborted(signal);
|
|
10923
|
+
return reconstructDrawPage(page, doc.images);
|
|
10924
|
+
});
|
|
10925
|
+
return {
|
|
10926
|
+
kind: "drawing",
|
|
10927
|
+
formatVersion: 1,
|
|
10928
|
+
metadata: doc.metadata,
|
|
10929
|
+
pages
|
|
10930
|
+
};
|
|
10931
|
+
}
|
|
10932
|
+
function reconstructDrawPage(page, images) {
|
|
10933
|
+
const vectors = [];
|
|
10934
|
+
const shapes = [];
|
|
10935
|
+
for (const item of page.items) if (item.kind === "rect") vectors.push(layoutRectToVector(item, page.heightPt));
|
|
10936
|
+
else if (item.kind === "ellipse") vectors.push(layoutEllipseToVector(item, page.heightPt));
|
|
10937
|
+
else if (item.kind === "line") vectors.push(layoutLineToVector(item, page.heightPt));
|
|
10938
|
+
else if (item.kind === "path") vectors.push(layoutPathToVector(item, page.heightPt));
|
|
10939
|
+
else if (item.kind === "text") shapes.push(layoutTextToShape(item, page.heightPt));
|
|
10940
|
+
else if (item.kind === "image") {
|
|
10941
|
+
const shape = imageToShape(item, page.heightPt, images);
|
|
10942
|
+
if (shape !== void 0) shapes.push(shape);
|
|
10943
|
+
}
|
|
10944
|
+
return {
|
|
10945
|
+
size: {
|
|
10946
|
+
widthPt: page.widthPt,
|
|
10947
|
+
heightPt: page.heightPt
|
|
10948
|
+
},
|
|
10949
|
+
shapes,
|
|
10950
|
+
vectors
|
|
10951
|
+
};
|
|
10952
|
+
}
|
|
10953
|
+
function layoutRectToVector(item, pageHeightPt) {
|
|
10954
|
+
return {
|
|
10955
|
+
kind: "rect",
|
|
10956
|
+
frame: flipY({
|
|
10957
|
+
xPt: item.xPt,
|
|
10958
|
+
yPt: item.yPt,
|
|
10959
|
+
widthPt: item.widthPt,
|
|
10960
|
+
heightPt: item.heightPt
|
|
10961
|
+
}, pageHeightPt),
|
|
10962
|
+
fill: item.fill,
|
|
10963
|
+
stroke: item.stroke,
|
|
10964
|
+
sourcePath: item.sourcePath
|
|
10965
|
+
};
|
|
10966
|
+
}
|
|
10967
|
+
function layoutEllipseToVector(item, pageHeightPt) {
|
|
10968
|
+
return {
|
|
10969
|
+
kind: "ellipse",
|
|
10970
|
+
frame: flipY({
|
|
10971
|
+
xPt: item.xPt,
|
|
10972
|
+
yPt: item.yPt,
|
|
10973
|
+
widthPt: item.widthPt,
|
|
10974
|
+
heightPt: item.heightPt
|
|
10975
|
+
}, pageHeightPt),
|
|
10976
|
+
fill: item.fill,
|
|
10977
|
+
stroke: item.stroke,
|
|
10978
|
+
sourcePath: item.sourcePath
|
|
10979
|
+
};
|
|
10980
|
+
}
|
|
10981
|
+
function layoutLineToVector(item, pageHeightPt) {
|
|
10982
|
+
return {
|
|
10983
|
+
kind: "line",
|
|
10984
|
+
from: {
|
|
10985
|
+
xPt: item.x1Pt,
|
|
10986
|
+
yPt: pageHeightPt - item.y1Pt
|
|
10987
|
+
},
|
|
10988
|
+
to: {
|
|
10989
|
+
xPt: item.x2Pt,
|
|
10990
|
+
yPt: pageHeightPt - item.y2Pt
|
|
10991
|
+
},
|
|
10992
|
+
stroke: {
|
|
10993
|
+
color: item.color,
|
|
10994
|
+
widthPt: item.widthPt
|
|
10995
|
+
},
|
|
10996
|
+
sourcePath: item.sourcePath
|
|
10997
|
+
};
|
|
10998
|
+
}
|
|
10999
|
+
function collectPathPoints(subpaths) {
|
|
11000
|
+
const points = [];
|
|
11001
|
+
for (const subpath of subpaths) {
|
|
11002
|
+
points.push({
|
|
11003
|
+
xPt: subpath.startXPt,
|
|
11004
|
+
yPt: subpath.startYPt
|
|
11005
|
+
});
|
|
11006
|
+
for (const segment of subpath.segments) {
|
|
11007
|
+
if (segment.kind === "cubic") {
|
|
11008
|
+
points.push({
|
|
11009
|
+
xPt: segment.c1xPt,
|
|
11010
|
+
yPt: segment.c1yPt
|
|
11011
|
+
});
|
|
11012
|
+
points.push({
|
|
11013
|
+
xPt: segment.c2xPt,
|
|
11014
|
+
yPt: segment.c2yPt
|
|
11015
|
+
});
|
|
11016
|
+
}
|
|
11017
|
+
points.push({
|
|
11018
|
+
xPt: segment.xPt,
|
|
11019
|
+
yPt: segment.yPt
|
|
11020
|
+
});
|
|
11021
|
+
}
|
|
11022
|
+
}
|
|
11023
|
+
return points;
|
|
11024
|
+
}
|
|
11025
|
+
function pathBoundingFrame(points, pageHeightPt) {
|
|
11026
|
+
if (points.length === 0) return {
|
|
11027
|
+
xPt: 0,
|
|
11028
|
+
yPt: 0,
|
|
11029
|
+
widthPt: 0,
|
|
11030
|
+
heightPt: 0
|
|
11031
|
+
};
|
|
11032
|
+
let minX = Number.POSITIVE_INFINITY;
|
|
11033
|
+
let maxX = Number.NEGATIVE_INFINITY;
|
|
11034
|
+
let minYDown = Number.POSITIVE_INFINITY;
|
|
11035
|
+
let maxYDown = Number.NEGATIVE_INFINITY;
|
|
11036
|
+
for (const point of points) {
|
|
11037
|
+
const yDown = pageHeightPt - point.yPt;
|
|
11038
|
+
minX = Math.min(minX, point.xPt);
|
|
11039
|
+
maxX = Math.max(maxX, point.xPt);
|
|
11040
|
+
minYDown = Math.min(minYDown, yDown);
|
|
11041
|
+
maxYDown = Math.max(maxYDown, yDown);
|
|
11042
|
+
}
|
|
11043
|
+
return {
|
|
11044
|
+
xPt: minX,
|
|
11045
|
+
yPt: minYDown,
|
|
11046
|
+
widthPt: maxX - minX,
|
|
11047
|
+
heightPt: maxYDown - minYDown
|
|
11048
|
+
};
|
|
11049
|
+
}
|
|
11050
|
+
function localizePathPoint(frame, point, pageHeightPt) {
|
|
11051
|
+
return {
|
|
11052
|
+
xPt: point.xPt - frame.xPt,
|
|
11053
|
+
yPt: pageHeightPt - frame.yPt - point.yPt
|
|
11054
|
+
};
|
|
11055
|
+
}
|
|
11056
|
+
function layoutPathToVector(item, pageHeightPt) {
|
|
11057
|
+
const frame = pathBoundingFrame(collectPathPoints(item.subpaths), pageHeightPt);
|
|
11058
|
+
return {
|
|
11059
|
+
kind: "path",
|
|
11060
|
+
frame,
|
|
11061
|
+
subpaths: item.subpaths.map((subpath) => ({
|
|
11062
|
+
start: localizePathPoint(frame, {
|
|
11063
|
+
xPt: subpath.startXPt,
|
|
11064
|
+
yPt: subpath.startYPt
|
|
11065
|
+
}, pageHeightPt),
|
|
11066
|
+
closed: subpath.closed,
|
|
11067
|
+
segments: subpath.segments.map((segment) => {
|
|
11068
|
+
if (segment.kind === "line") return {
|
|
11069
|
+
kind: "line",
|
|
11070
|
+
to: localizePathPoint(frame, {
|
|
11071
|
+
xPt: segment.xPt,
|
|
11072
|
+
yPt: segment.yPt
|
|
11073
|
+
}, pageHeightPt)
|
|
11074
|
+
};
|
|
11075
|
+
return {
|
|
11076
|
+
kind: "cubic",
|
|
11077
|
+
control1: localizePathPoint(frame, {
|
|
11078
|
+
xPt: segment.c1xPt,
|
|
11079
|
+
yPt: segment.c1yPt
|
|
11080
|
+
}, pageHeightPt),
|
|
11081
|
+
control2: localizePathPoint(frame, {
|
|
11082
|
+
xPt: segment.c2xPt,
|
|
11083
|
+
yPt: segment.c2yPt
|
|
11084
|
+
}, pageHeightPt),
|
|
11085
|
+
to: localizePathPoint(frame, {
|
|
11086
|
+
xPt: segment.xPt,
|
|
11087
|
+
yPt: segment.yPt
|
|
11088
|
+
}, pageHeightPt)
|
|
11089
|
+
};
|
|
11090
|
+
})
|
|
11091
|
+
})),
|
|
11092
|
+
fill: item.fill,
|
|
11093
|
+
fillRule: item.fillRule,
|
|
11094
|
+
stroke: item.stroke,
|
|
11095
|
+
sourcePath: item.sourcePath
|
|
11096
|
+
};
|
|
11097
|
+
}
|
|
11098
|
+
function layoutTextToShape(item, pageHeightPt) {
|
|
11099
|
+
return {
|
|
11100
|
+
frame: computeBlockFrame({ lines: [{
|
|
11101
|
+
items: [item],
|
|
11102
|
+
baselineY: item.yPt
|
|
11103
|
+
}] }, pageHeightPt),
|
|
11104
|
+
rotationDeg: item.rotationDeg !== void 0 ? -item.rotationDeg : void 0,
|
|
11105
|
+
insetLeftPt: 0,
|
|
11106
|
+
insetTopPt: 0,
|
|
11107
|
+
insetRightPt: 0,
|
|
11108
|
+
insetBottomPt: 0,
|
|
11109
|
+
blocks: [{
|
|
11110
|
+
kind: "paragraph",
|
|
11111
|
+
runs: [textItemToContentRun(item)]
|
|
11112
|
+
}]
|
|
11113
|
+
};
|
|
11114
|
+
}
|
|
11115
|
+
function extractLineCandidates(items) {
|
|
11116
|
+
const segments = [];
|
|
11117
|
+
for (const item of items) {
|
|
11118
|
+
if (item.kind === "line") {
|
|
11119
|
+
segments.push({
|
|
11120
|
+
x1Pt: item.x1Pt,
|
|
11121
|
+
y1Pt: item.y1Pt,
|
|
11122
|
+
x2Pt: item.x2Pt,
|
|
11123
|
+
y2Pt: item.y2Pt
|
|
11124
|
+
});
|
|
11125
|
+
continue;
|
|
11126
|
+
}
|
|
11127
|
+
if (item.kind === "path" && item.stroke !== void 0 && item.subpaths.length === 1) {
|
|
11128
|
+
const subpath = item.subpaths[0];
|
|
11129
|
+
if (subpath.segments.length === 1 && subpath.segments[0].kind === "line") {
|
|
11130
|
+
const segment = subpath.segments[0];
|
|
11131
|
+
segments.push({
|
|
11132
|
+
x1Pt: subpath.startXPt,
|
|
11133
|
+
y1Pt: subpath.startYPt,
|
|
11134
|
+
x2Pt: segment.xPt,
|
|
11135
|
+
y2Pt: segment.yPt
|
|
11136
|
+
});
|
|
11137
|
+
}
|
|
11138
|
+
}
|
|
11139
|
+
}
|
|
11140
|
+
return segments;
|
|
11141
|
+
}
|
|
11142
|
+
const AXIS_ALIGNMENT_TOLERANCE_PT = .5;
|
|
11143
|
+
const MIN_GRIDLINE_LENGTH_PT = 4;
|
|
11144
|
+
function classifyAxisLine(seg) {
|
|
11145
|
+
const dx = Math.abs(seg.x2Pt - seg.x1Pt);
|
|
11146
|
+
const dy = Math.abs(seg.y2Pt - seg.y1Pt);
|
|
11147
|
+
if (dy <= AXIS_ALIGNMENT_TOLERANCE_PT && dx >= MIN_GRIDLINE_LENGTH_PT) return {
|
|
11148
|
+
axis: "horizontal",
|
|
11149
|
+
position: (seg.y1Pt + seg.y2Pt) / 2,
|
|
11150
|
+
spanPt: dx
|
|
11151
|
+
};
|
|
11152
|
+
if (dx <= AXIS_ALIGNMENT_TOLERANCE_PT && dy >= MIN_GRIDLINE_LENGTH_PT) return {
|
|
11153
|
+
axis: "vertical",
|
|
11154
|
+
position: (seg.x1Pt + seg.x2Pt) / 2,
|
|
11155
|
+
spanPt: dy
|
|
11156
|
+
};
|
|
11157
|
+
}
|
|
11158
|
+
const POSITION_DEDUPE_TOLERANCE_PT = .5;
|
|
11159
|
+
function dedupeAxisLines(lines, descending) {
|
|
11160
|
+
const sorted = [...lines].sort((a, b) => descending ? b.position - a.position : a.position - b.position);
|
|
11161
|
+
const result = [];
|
|
11162
|
+
for (const candidate of sorted) {
|
|
11163
|
+
const last = result[result.length - 1];
|
|
11164
|
+
if (last !== void 0 && Math.abs(candidate.position - last.position) <= POSITION_DEDUPE_TOLERANCE_PT) last.spanPt = Math.max(last.spanPt, candidate.spanPt);
|
|
11165
|
+
else result.push({
|
|
11166
|
+
position: candidate.position,
|
|
11167
|
+
spanPt: candidate.spanPt
|
|
11168
|
+
});
|
|
11169
|
+
}
|
|
11170
|
+
return result;
|
|
11171
|
+
}
|
|
11172
|
+
const MIN_GRIDLINE_COUNT_PER_AXIS = 3;
|
|
11173
|
+
const GRID_SPAN_CONSISTENCY_RATIO = .9;
|
|
11174
|
+
function isRegularLattice(lines) {
|
|
11175
|
+
if (lines.length < MIN_GRIDLINE_COUNT_PER_AXIS) return false;
|
|
11176
|
+
const maxSpanPt = Math.max(...lines.map((l) => l.spanPt));
|
|
11177
|
+
return lines.filter((l) => l.spanPt >= maxSpanPt * GRID_SPAN_CONSISTENCY_RATIO).length >= MIN_GRIDLINE_COUNT_PER_AXIS;
|
|
11178
|
+
}
|
|
11179
|
+
function detectGridLattice(items) {
|
|
11180
|
+
const horizontal = [];
|
|
11181
|
+
const vertical = [];
|
|
11182
|
+
for (const seg of extractLineCandidates(items)) {
|
|
11183
|
+
const classified = classifyAxisLine(seg);
|
|
11184
|
+
if (classified === void 0) continue;
|
|
11185
|
+
(classified.axis === "horizontal" ? horizontal : vertical).push(classified);
|
|
11186
|
+
}
|
|
11187
|
+
const rowBoundaries = dedupeAxisLines(horizontal, true);
|
|
11188
|
+
const columnBoundaries = dedupeAxisLines(vertical, false);
|
|
11189
|
+
if (!isRegularLattice(rowBoundaries) || !isRegularLattice(columnBoundaries)) return;
|
|
11190
|
+
return {
|
|
11191
|
+
rowBoundariesDescPt: rowBoundaries.map((l) => l.position),
|
|
11192
|
+
columnBoundariesAscPt: columnBoundaries.map((l) => l.position)
|
|
11193
|
+
};
|
|
11194
|
+
}
|
|
11195
|
+
const OUTER_EDGE_TOLERANCE_PT = 3;
|
|
11196
|
+
function findRowIndex(rowBoundariesDescPt, yPt) {
|
|
11197
|
+
const lastIndex = rowBoundariesDescPt.length - 1;
|
|
11198
|
+
if (yPt > rowBoundariesDescPt[0] + OUTER_EDGE_TOLERANCE_PT || yPt < rowBoundariesDescPt[lastIndex] - OUTER_EDGE_TOLERANCE_PT) return;
|
|
11199
|
+
for (let i = 0; i < lastIndex; i++) if (yPt > rowBoundariesDescPt[i + 1]) return i;
|
|
11200
|
+
return lastIndex - 1;
|
|
11201
|
+
}
|
|
11202
|
+
function findColumnIndex(columnBoundariesAscPt, xPt) {
|
|
11203
|
+
const lastIndex = columnBoundariesAscPt.length - 1;
|
|
11204
|
+
if (xPt < columnBoundariesAscPt[0] - OUTER_EDGE_TOLERANCE_PT || xPt > columnBoundariesAscPt[lastIndex] + OUTER_EDGE_TOLERANCE_PT) return;
|
|
11205
|
+
for (let j = 0; j < lastIndex; j++) if (xPt < columnBoundariesAscPt[j + 1]) return j;
|
|
11206
|
+
return lastIndex - 1;
|
|
11207
|
+
}
|
|
11208
|
+
function joinCellText(items) {
|
|
11209
|
+
const sorted = [...items].sort((a, b) => a.xPt - b.xPt);
|
|
11210
|
+
let text = "";
|
|
11211
|
+
sorted.forEach((item, i) => {
|
|
11212
|
+
if (i > 0) {
|
|
11213
|
+
const prev = sorted[i - 1];
|
|
11214
|
+
if (item.xPt - (prev.xPt + (prev.widthPt ?? 0)) > MIN_WORD_GAP_PT) text += " ";
|
|
11215
|
+
}
|
|
11216
|
+
text += item.text;
|
|
11217
|
+
});
|
|
11218
|
+
return text;
|
|
11219
|
+
}
|
|
11220
|
+
function groupKey(row, column) {
|
|
11221
|
+
return `${row},${column}`;
|
|
11222
|
+
}
|
|
11223
|
+
function addToGroup(groups, row, column, item) {
|
|
11224
|
+
const key = groupKey(row, column);
|
|
11225
|
+
const existing = groups.get(key);
|
|
11226
|
+
if (existing === void 0) groups.set(key, [item]);
|
|
11227
|
+
else existing.push(item);
|
|
11228
|
+
}
|
|
11229
|
+
function buildCellsFromGroups(groups) {
|
|
11230
|
+
const cells = [];
|
|
11231
|
+
for (const [key, items] of groups) {
|
|
11232
|
+
const displayText = joinCellText(items);
|
|
11233
|
+
if (displayText.length === 0) continue;
|
|
11234
|
+
const [rowPart, columnPart] = key.split(",");
|
|
11235
|
+
cells.push({
|
|
11236
|
+
row: Number(rowPart),
|
|
11237
|
+
column: Number(columnPart),
|
|
11238
|
+
value: {
|
|
11239
|
+
kind: "string",
|
|
11240
|
+
value: displayText
|
|
11241
|
+
},
|
|
11242
|
+
displayText
|
|
11243
|
+
});
|
|
11244
|
+
}
|
|
11245
|
+
cells.sort((a, b) => a.row - b.row || a.column - b.column);
|
|
11246
|
+
return cells;
|
|
11247
|
+
}
|
|
11248
|
+
function buildGridFromLattice(textItems, lattice) {
|
|
11249
|
+
const groups = /* @__PURE__ */ new Map();
|
|
11250
|
+
for (const item of textItems) {
|
|
11251
|
+
const row = findRowIndex(lattice.rowBoundariesDescPt, item.yPt);
|
|
11252
|
+
const column = findColumnIndex(lattice.columnBoundariesAscPt, item.xPt);
|
|
11253
|
+
if (row === void 0 || column === void 0) continue;
|
|
11254
|
+
addToGroup(groups, row, column, item);
|
|
11255
|
+
}
|
|
11256
|
+
const columns = [];
|
|
11257
|
+
for (let j = 0; j < lattice.columnBoundariesAscPt.length - 1; j++) columns.push({
|
|
11258
|
+
index: j,
|
|
11259
|
+
widthPt: lattice.columnBoundariesAscPt[j + 1] - lattice.columnBoundariesAscPt[j]
|
|
11260
|
+
});
|
|
11261
|
+
const rows = [];
|
|
11262
|
+
for (let i = 0; i < lattice.rowBoundariesDescPt.length - 1; i++) rows.push({
|
|
11263
|
+
index: i,
|
|
11264
|
+
heightPt: lattice.rowBoundariesDescPt[i] - lattice.rowBoundariesDescPt[i + 1]
|
|
11265
|
+
});
|
|
11266
|
+
return {
|
|
11267
|
+
cells: buildCellsFromGroups(groups),
|
|
11268
|
+
columns,
|
|
11269
|
+
rows,
|
|
11270
|
+
gridlines: true
|
|
11271
|
+
};
|
|
11272
|
+
}
|
|
11273
|
+
const COLUMN_ALIGNMENT_TOLERANCE_PT = 3;
|
|
11274
|
+
const MIN_COLUMN_RECURRENCE = 2;
|
|
11275
|
+
function detectColumnPositions(segmentsByLine) {
|
|
11276
|
+
const allXs = segmentsByLine.flatMap((segments) => segments.map((segment) => segment.items[0].xPt));
|
|
11277
|
+
if (allXs.length === 0) return [];
|
|
11278
|
+
const counts = bucketCounts(allXs, COLUMN_ALIGNMENT_TOLERANCE_PT);
|
|
11279
|
+
const recurring = [...counts.entries()].filter(([, count]) => count >= MIN_COLUMN_RECURRENCE).map(([bucket]) => bucket);
|
|
11280
|
+
const positions = recurring.length > 0 ? recurring : [...counts.keys()];
|
|
11281
|
+
positions.sort((a, b) => a - b);
|
|
11282
|
+
return positions;
|
|
11283
|
+
}
|
|
11284
|
+
function nearestColumnIndex(positions, xPt) {
|
|
11285
|
+
let bestIndex = 0;
|
|
11286
|
+
let bestDistancePt = Number.POSITIVE_INFINITY;
|
|
11287
|
+
positions.forEach((position, index) => {
|
|
11288
|
+
const distancePt = Math.abs(position - xPt);
|
|
11289
|
+
if (distancePt < bestDistancePt) {
|
|
11290
|
+
bestDistancePt = distancePt;
|
|
11291
|
+
bestIndex = index;
|
|
11292
|
+
}
|
|
11293
|
+
});
|
|
11294
|
+
return bestIndex;
|
|
11295
|
+
}
|
|
11296
|
+
const DEFAULT_COLUMN_WIDTH_FALLBACK_PT = 40;
|
|
11297
|
+
function lastColumnWidthPt(groups, columnIndex, anchorXPt) {
|
|
11298
|
+
let maxWidthPt = 0;
|
|
11299
|
+
for (const [key, items] of groups) {
|
|
11300
|
+
const [, columnPart] = key.split(",");
|
|
11301
|
+
if (Number(columnPart) !== columnIndex) continue;
|
|
11302
|
+
for (const item of items) maxWidthPt = Math.max(maxWidthPt, item.xPt + (item.widthPt ?? 0) - anchorXPt);
|
|
11303
|
+
}
|
|
11304
|
+
return maxWidthPt > 0 ? maxWidthPt : DEFAULT_COLUMN_WIDTH_FALLBACK_PT;
|
|
11305
|
+
}
|
|
11306
|
+
function buildGridFromTextClustering(textItems) {
|
|
11307
|
+
const lines = clusterIntoLines(textItems);
|
|
11308
|
+
if (lines.length === 0) return {
|
|
11309
|
+
cells: [],
|
|
11310
|
+
columns: [],
|
|
11311
|
+
rows: [],
|
|
11312
|
+
gridlines: false
|
|
11313
|
+
};
|
|
11314
|
+
const segmentsByLine = lines.map((l) => splitLineByLargeGaps(l));
|
|
11315
|
+
const columnPositions = detectColumnPositions(segmentsByLine);
|
|
11316
|
+
const groups = /* @__PURE__ */ new Map();
|
|
11317
|
+
segmentsByLine.forEach((segments, rowIndex) => {
|
|
11318
|
+
for (const segment of segments) {
|
|
11319
|
+
const key = groupKey(rowIndex, nearestColumnIndex(columnPositions, segment.items[0].xPt));
|
|
11320
|
+
const existing = groups.get(key);
|
|
11321
|
+
if (existing === void 0) groups.set(key, [...segment.items]);
|
|
11322
|
+
else existing.push(...segment.items);
|
|
11323
|
+
}
|
|
11324
|
+
});
|
|
11325
|
+
const nominalRowHeightPt = estimateModalLineSpacing(lines);
|
|
11326
|
+
const rows = lines.map((line, i) => {
|
|
11327
|
+
const nextBaselineY = lines[i + 1]?.baselineY;
|
|
11328
|
+
const heightPt = nextBaselineY !== void 0 ? line.baselineY - nextBaselineY : nominalRowHeightPt;
|
|
11329
|
+
return {
|
|
11330
|
+
index: i,
|
|
11331
|
+
heightPt: heightPt > 0 ? heightPt : nominalRowHeightPt
|
|
11332
|
+
};
|
|
11333
|
+
});
|
|
11334
|
+
const columns = columnPositions.map((position, j) => {
|
|
11335
|
+
const nextPosition = columnPositions[j + 1];
|
|
11336
|
+
return {
|
|
11337
|
+
index: j,
|
|
11338
|
+
widthPt: nextPosition !== void 0 ? nextPosition - position : lastColumnWidthPt(groups, j, position)
|
|
11339
|
+
};
|
|
11340
|
+
});
|
|
11341
|
+
return {
|
|
11342
|
+
cells: buildCellsFromGroups(groups),
|
|
11343
|
+
columns,
|
|
11344
|
+
rows,
|
|
11345
|
+
gridlines: false
|
|
11346
|
+
};
|
|
11347
|
+
}
|
|
11348
|
+
function reconstructSheet(page, pageIndex) {
|
|
11349
|
+
const textItems = page.items.filter((i) => i.kind === "text");
|
|
11350
|
+
const lattice = detectGridLattice(page.items);
|
|
11351
|
+
const grid = lattice !== void 0 ? buildGridFromLattice(textItems, lattice) : buildGridFromTextClustering(textItems);
|
|
11352
|
+
const printSettings = {
|
|
11353
|
+
pageSize: {
|
|
11354
|
+
widthPt: page.widthPt,
|
|
11355
|
+
heightPt: page.heightPt
|
|
11356
|
+
},
|
|
11357
|
+
margins: ZERO_MARGINS,
|
|
11358
|
+
gridlines: grid.gridlines,
|
|
11359
|
+
headers: false,
|
|
11360
|
+
pageOrder: "downThenOver"
|
|
11361
|
+
};
|
|
11362
|
+
return {
|
|
11363
|
+
name: `Sheet${pageIndex + 1}`,
|
|
11364
|
+
cells: grid.cells,
|
|
11365
|
+
columns: grid.columns,
|
|
11366
|
+
rows: grid.rows,
|
|
11367
|
+
images: [],
|
|
11368
|
+
printSettings
|
|
11369
|
+
};
|
|
11370
|
+
}
|
|
11371
|
+
function reconstructSpreadsheet(doc, options) {
|
|
11372
|
+
const signal = options?.signal;
|
|
11373
|
+
const sheets = doc.pages.map((page, index) => {
|
|
11374
|
+
throwIfAborted(signal);
|
|
11375
|
+
return reconstructSheet(page, index);
|
|
11376
|
+
});
|
|
11377
|
+
return {
|
|
11378
|
+
kind: "spreadsheet",
|
|
11379
|
+
formatVersion: 1,
|
|
11380
|
+
metadata: doc.metadata,
|
|
11381
|
+
sheets
|
|
11382
|
+
};
|
|
11383
|
+
}
|
|
10827
11384
|
//#endregion
|
|
10828
11385
|
//#region src/convert/convert.ts
|
|
10829
11386
|
function docxToPdf(bytes, options) {
|
|
@@ -10905,6 +11462,20 @@ function pdfToOdp(bytes, options) {
|
|
|
10905
11462
|
}), { signal: options?.signal });
|
|
10906
11463
|
return (0, odf_js.encodePackage)(buildOdpPackage(content));
|
|
10907
11464
|
}
|
|
11465
|
+
function pdfToOdg(bytes, options) {
|
|
11466
|
+
const content = reconstructDrawing(readPdf(bytes, {
|
|
11467
|
+
signal: options?.signal,
|
|
11468
|
+
sink: options?.sink
|
|
11469
|
+
}), { signal: options?.signal });
|
|
11470
|
+
return (0, odf_js.encodePackage)(buildOdgPackage(content));
|
|
11471
|
+
}
|
|
11472
|
+
function pdfToOds(bytes, options) {
|
|
11473
|
+
const content = reconstructSpreadsheet(readPdf(bytes, {
|
|
11474
|
+
signal: options?.signal,
|
|
11475
|
+
sink: options?.sink
|
|
11476
|
+
}), { signal: options?.signal });
|
|
11477
|
+
return (0, odf_js.encodePackage)(buildOdsPackage(content));
|
|
11478
|
+
}
|
|
10908
11479
|
//#endregion
|
|
10909
11480
|
//#region src/convert/codec.ts
|
|
10910
11481
|
const docxPdfCodec = zod.z.codec(DocxBytesSchema, PdfBytesSchema, {
|
|
@@ -10923,6 +11494,14 @@ const odpPdfCodec = zod.z.codec(OdpBytesSchema, PdfBytesSchema, {
|
|
|
10923
11494
|
decode: (odpBytes) => odpToPdf(odpBytes),
|
|
10924
11495
|
encode: (pdfBytes) => pdfToOdp(pdfBytes)
|
|
10925
11496
|
});
|
|
11497
|
+
const odsPdfCodec = zod.z.codec(OdsBytesSchema, PdfBytesSchema, {
|
|
11498
|
+
decode: (odsBytes) => odsToPdf(odsBytes),
|
|
11499
|
+
encode: (pdfBytes) => pdfToOds(pdfBytes)
|
|
11500
|
+
});
|
|
11501
|
+
const odgPdfCodec = zod.z.codec(OdgBytesSchema, PdfBytesSchema, {
|
|
11502
|
+
decode: (odgBytes) => odgToPdf(odgBytes),
|
|
11503
|
+
encode: (pdfBytes) => pdfToOdg(pdfBytes)
|
|
11504
|
+
});
|
|
10926
11505
|
//#endregion
|
|
10927
11506
|
//#region src/convert/local.ts
|
|
10928
11507
|
const SUPPORTED_CONVERSIONS = [
|
|
@@ -10965,6 +11544,14 @@ const SUPPORTED_CONVERSIONS = [
|
|
|
10965
11544
|
{
|
|
10966
11545
|
source: "pdf",
|
|
10967
11546
|
target: "odp"
|
|
11547
|
+
},
|
|
11548
|
+
{
|
|
11549
|
+
source: "pdf",
|
|
11550
|
+
target: "ods"
|
|
11551
|
+
},
|
|
11552
|
+
{
|
|
11553
|
+
source: "pdf",
|
|
11554
|
+
target: "odg"
|
|
10968
11555
|
}
|
|
10969
11556
|
];
|
|
10970
11557
|
function substitutionDiagnostic(substitution, context) {
|
|
@@ -11120,6 +11707,32 @@ function createLocalDocumentConverter() {
|
|
|
11120
11707
|
diagnostics
|
|
11121
11708
|
});
|
|
11122
11709
|
}
|
|
11710
|
+
if (source.format === "pdf" && targetFormat === "ods") {
|
|
11711
|
+
const bytes = pdfToOds(source.bytes, {
|
|
11712
|
+
signal: options.signal,
|
|
11713
|
+
sink: (d) => diagnostics.push(fromPdfDiagnostic(d))
|
|
11714
|
+
});
|
|
11715
|
+
return Promise.resolve({
|
|
11716
|
+
document: {
|
|
11717
|
+
format: "ods",
|
|
11718
|
+
bytes
|
|
11719
|
+
},
|
|
11720
|
+
diagnostics
|
|
11721
|
+
});
|
|
11722
|
+
}
|
|
11723
|
+
if (source.format === "pdf" && targetFormat === "odg") {
|
|
11724
|
+
const bytes = pdfToOdg(source.bytes, {
|
|
11725
|
+
signal: options.signal,
|
|
11726
|
+
sink: (d) => diagnostics.push(fromPdfDiagnostic(d))
|
|
11727
|
+
});
|
|
11728
|
+
return Promise.resolve({
|
|
11729
|
+
document: {
|
|
11730
|
+
format: "odg",
|
|
11731
|
+
bytes
|
|
11732
|
+
},
|
|
11733
|
+
diagnostics
|
|
11734
|
+
});
|
|
11735
|
+
}
|
|
11123
11736
|
return Promise.reject(/* @__PURE__ */ new Error(`unsupported conversion: ${source.format} -> ${targetFormat}`));
|
|
11124
11737
|
}
|
|
11125
11738
|
};
|
|
@@ -11588,9 +12201,11 @@ Object.defineProperty(exports, "isXmlNode", {
|
|
|
11588
12201
|
return ooxml_js.isXmlNode;
|
|
11589
12202
|
}
|
|
11590
12203
|
});
|
|
12204
|
+
exports.odgPdfCodec = odgPdfCodec;
|
|
11591
12205
|
exports.odgToPdf = odgToPdf;
|
|
11592
12206
|
exports.odpPdfCodec = odpPdfCodec;
|
|
11593
12207
|
exports.odpToPdf = odpToPdf;
|
|
12208
|
+
exports.odsPdfCodec = odsPdfCodec;
|
|
11594
12209
|
exports.odsToPdf = odsToPdf;
|
|
11595
12210
|
exports.odtPdfCodec = odtPdfCodec;
|
|
11596
12211
|
exports.odtToPdf = odtToPdf;
|
|
@@ -11620,7 +12235,9 @@ Object.defineProperty(exports, "parseXml", {
|
|
|
11620
12235
|
});
|
|
11621
12236
|
exports.pdfCodec = pdfCodec;
|
|
11622
12237
|
exports.pdfToDocx = pdfToDocx;
|
|
12238
|
+
exports.pdfToOdg = pdfToOdg;
|
|
11623
12239
|
exports.pdfToOdp = pdfToOdp;
|
|
12240
|
+
exports.pdfToOds = pdfToOds;
|
|
11624
12241
|
exports.pdfToOdt = pdfToOdt;
|
|
11625
12242
|
exports.pdfToPptx = pdfToPptx;
|
|
11626
12243
|
exports.pptxPdfCodec = pptxPdfCodec;
|
|
@@ -11632,7 +12249,9 @@ exports.readOdsContent = readOdsContent;
|
|
|
11632
12249
|
exports.readOdtContent = readOdtContent;
|
|
11633
12250
|
exports.readPdf = readPdf;
|
|
11634
12251
|
exports.readPptxContent = readPptxContent;
|
|
12252
|
+
exports.reconstructDrawing = reconstructDrawing;
|
|
11635
12253
|
exports.reconstructPresentation = reconstructPresentation;
|
|
12254
|
+
exports.reconstructSpreadsheet = reconstructSpreadsheet;
|
|
11636
12255
|
exports.reconstructWordprocessing = reconstructWordprocessing;
|
|
11637
12256
|
Object.defineProperty(exports, "resolveRelationships", {
|
|
11638
12257
|
enumerable: true,
|