odf.js 1.6.0 → 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +362 -29
- package/dist/index.d.cts +15 -2
- package/dist/index.d.ts +15 -2
- package/dist/index.js +359 -30
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1421,6 +1421,25 @@ function cellReference(columnIndex, rowIndex) {
|
|
|
1421
1421
|
if (!Number.isInteger(rowIndex) || rowIndex < 0) throw new Error(`cellReference: rowIndex must be a non-negative integer, got ${rowIndex}`);
|
|
1422
1422
|
return `${columnIndexToLetters(columnIndex)}${rowIndex + 1}`;
|
|
1423
1423
|
}
|
|
1424
|
+
function columnLettersToIndex(letters) {
|
|
1425
|
+
if (!/^[A-Z]+$/.test(letters)) return;
|
|
1426
|
+
let index = 0;
|
|
1427
|
+
for (const char of letters) index = index * ALPHABET_SIZE + (char.charCodeAt(0) - ALPHABET_START_CODE + 1);
|
|
1428
|
+
return index - 1;
|
|
1429
|
+
}
|
|
1430
|
+
function parseCellReference(reference) {
|
|
1431
|
+
const match = /^([A-Z]+)(\d+)$/.exec(reference);
|
|
1432
|
+
if (match === null) return;
|
|
1433
|
+
const [, letters, digits] = match;
|
|
1434
|
+
if (letters === void 0 || digits === void 0) return;
|
|
1435
|
+
const column = columnLettersToIndex(letters);
|
|
1436
|
+
const row = Number.parseInt(digits, 10) - 1;
|
|
1437
|
+
if (column === void 0 || row < 0) return;
|
|
1438
|
+
return {
|
|
1439
|
+
column,
|
|
1440
|
+
row
|
|
1441
|
+
};
|
|
1442
|
+
}
|
|
1424
1443
|
function validateRepeatCount(repeatCount, caller) {
|
|
1425
1444
|
if (!Number.isInteger(repeatCount) || repeatCount < 1) throw new Error(`${caller}: repeatCount must be a positive integer, got ${repeatCount}`);
|
|
1426
1445
|
}
|
|
@@ -1702,7 +1721,7 @@ function readOdfParagraph(pElement, pkg) {
|
|
|
1702
1721
|
}
|
|
1703
1722
|
//#endregion
|
|
1704
1723
|
//#region src/typed/shared/table.ts
|
|
1705
|
-
function readRepeatCount(element, attrName) {
|
|
1724
|
+
function readRepeatCount$1(element, attrName) {
|
|
1706
1725
|
const raw = attrValue(element, attrName);
|
|
1707
1726
|
if (raw === void 0) return 1;
|
|
1708
1727
|
const parsed = Number.parseInt(raw, 10);
|
|
@@ -1745,11 +1764,11 @@ function readTableRow(rowElement, pkg) {
|
|
|
1745
1764
|
for (const child of rowElement.children) {
|
|
1746
1765
|
if (child.type !== "element") continue;
|
|
1747
1766
|
if (child.tag === "table:covered-table-cell") {
|
|
1748
|
-
const repeat = readRepeatCount(child, "table:number-columns-repeated");
|
|
1767
|
+
const repeat = readRepeatCount$1(child, "table:number-columns-repeated");
|
|
1749
1768
|
for (let i = 0; i < repeat; i++) cells.push({ blocks: [] });
|
|
1750
1769
|
} else if (child.tag === "table:table-cell") {
|
|
1751
1770
|
const cell = readTableCell(child, pkg);
|
|
1752
|
-
const repeat = readRepeatCount(child, "table:number-columns-repeated");
|
|
1771
|
+
const repeat = readRepeatCount$1(child, "table:number-columns-repeated");
|
|
1753
1772
|
for (let i = 0; i < repeat; i++) cells.push(cell);
|
|
1754
1773
|
}
|
|
1755
1774
|
}
|
|
@@ -1762,13 +1781,13 @@ function readOdfTable(tableElement, pkg) {
|
|
|
1762
1781
|
const columnWidthsPt = [];
|
|
1763
1782
|
for (const column of childrenWithTag(tableElement, "table:table-column")) {
|
|
1764
1783
|
const widthPt = resolveColumnWidthPt(column, pkg);
|
|
1765
|
-
const repeat = readRepeatCount(column, "table:number-columns-repeated");
|
|
1784
|
+
const repeat = readRepeatCount$1(column, "table:number-columns-repeated");
|
|
1766
1785
|
for (let i = 0; i < repeat; i++) columnWidthsPt.push(widthPt);
|
|
1767
1786
|
}
|
|
1768
1787
|
const rows = [];
|
|
1769
1788
|
for (const rowElement of childrenWithTag(tableElement, "table:table-row")) {
|
|
1770
1789
|
const row = readTableRow(rowElement, pkg);
|
|
1771
|
-
const repeat = readRepeatCount(rowElement, "table:number-rows-repeated");
|
|
1790
|
+
const repeat = readRepeatCount$1(rowElement, "table:number-rows-repeated");
|
|
1772
1791
|
for (let i = 0; i < repeat; i++) rows.push(row);
|
|
1773
1792
|
}
|
|
1774
1793
|
return {
|
|
@@ -1905,10 +1924,13 @@ function findPageLayoutElement$1(pkg, pageLayoutName) {
|
|
|
1905
1924
|
if (found !== void 0) return found;
|
|
1906
1925
|
}
|
|
1907
1926
|
}
|
|
1908
|
-
function
|
|
1909
|
-
const masterPage = findMasterPageElement(pkg,
|
|
1927
|
+
function resolvePageLayoutProperties(pkg, masterPageName) {
|
|
1928
|
+
const masterPage = findMasterPageElement(pkg, masterPageName);
|
|
1910
1929
|
const pageLayout = findPageLayoutElement$1(pkg, masterPage === void 0 ? void 0 : attrValue(masterPage, "style:page-layout-name"));
|
|
1911
|
-
|
|
1930
|
+
return pageLayout === void 0 ? void 0 : childrenWithTag(pageLayout, "style:page-layout-properties")[0];
|
|
1931
|
+
}
|
|
1932
|
+
function resolveDrawPageSize(page, pkg) {
|
|
1933
|
+
const properties = resolvePageLayoutProperties(pkg, attrValue(page, "draw:master-page-name"));
|
|
1912
1934
|
return properties === void 0 ? void 0 : parsePageSize(properties);
|
|
1913
1935
|
}
|
|
1914
1936
|
//#endregion
|
|
@@ -2462,7 +2484,7 @@ function readDrawPageContent(children, pkg) {
|
|
|
2462
2484
|
}
|
|
2463
2485
|
//#endregion
|
|
2464
2486
|
//#region src/typed/odp/read.ts
|
|
2465
|
-
const CONTENT_PART$
|
|
2487
|
+
const CONTENT_PART$3 = "content.xml";
|
|
2466
2488
|
function readSlideSize(page, pkg) {
|
|
2467
2489
|
return resolveDrawPageSize(page, pkg) ?? document_content_model.SLIDE_SIZE_WIDESCREEN;
|
|
2468
2490
|
}
|
|
@@ -2481,7 +2503,7 @@ function readSlide(page, pkg) {
|
|
|
2481
2503
|
};
|
|
2482
2504
|
}
|
|
2483
2505
|
function readOdp(pkg) {
|
|
2484
|
-
const contentPart = pkg.parts[CONTENT_PART$
|
|
2506
|
+
const contentPart = pkg.parts[CONTENT_PART$3];
|
|
2485
2507
|
const root = contentPart?.kind === "xml" ? rootElement(contentPart.nodes) : void 0;
|
|
2486
2508
|
const body = root === void 0 ? void 0 : findChildElement(root.children, "office:body");
|
|
2487
2509
|
const presentation = body === void 0 ? void 0 : findChildElement(body.children, "office:presentation");
|
|
@@ -2493,9 +2515,9 @@ function readOdp(pkg) {
|
|
|
2493
2515
|
}
|
|
2494
2516
|
//#endregion
|
|
2495
2517
|
//#region src/typed/odt/read.ts
|
|
2496
|
-
const CONTENT_PART$
|
|
2518
|
+
const CONTENT_PART$2 = "content.xml";
|
|
2497
2519
|
const STYLES_PART = "styles.xml";
|
|
2498
|
-
const AUTOMATIC_STYLE_PARTS = [CONTENT_PART$
|
|
2520
|
+
const AUTOMATIC_STYLE_PARTS = [CONTENT_PART$2, STYLES_PART];
|
|
2499
2521
|
function readOutlineLevel(headingElement) {
|
|
2500
2522
|
const raw = attrValue(headingElement, "text:outline-level");
|
|
2501
2523
|
if (raw === void 0) return 1;
|
|
@@ -2538,18 +2560,18 @@ function readBlocks(nodes, pkg, listIdState) {
|
|
|
2538
2560
|
}
|
|
2539
2561
|
return blocks;
|
|
2540
2562
|
}
|
|
2541
|
-
function parseKnownOdfLength(value) {
|
|
2563
|
+
function parseKnownOdfLength$1(value) {
|
|
2542
2564
|
const parsed = parseOdfLength(value);
|
|
2543
2565
|
if (parsed === void 0) throw new Error(`readOdt: internal error -- "${value}" is not a valid ODF length literal`);
|
|
2544
2566
|
return parsed;
|
|
2545
2567
|
}
|
|
2546
|
-
const DEFAULT_PAGE_SIZE$
|
|
2547
|
-
const DEFAULT_MARGIN_PT = parseKnownOdfLength("2cm");
|
|
2548
|
-
const DEFAULT_MARGINS = {
|
|
2549
|
-
topPt: DEFAULT_MARGIN_PT,
|
|
2550
|
-
rightPt: DEFAULT_MARGIN_PT,
|
|
2551
|
-
bottomPt: DEFAULT_MARGIN_PT,
|
|
2552
|
-
leftPt: DEFAULT_MARGIN_PT
|
|
2568
|
+
const DEFAULT_PAGE_SIZE$2 = document_content_model.PAGE_SIZE_A4;
|
|
2569
|
+
const DEFAULT_MARGIN_PT$1 = parseKnownOdfLength$1("2cm");
|
|
2570
|
+
const DEFAULT_MARGINS$1 = {
|
|
2571
|
+
topPt: DEFAULT_MARGIN_PT$1,
|
|
2572
|
+
rightPt: DEFAULT_MARGIN_PT$1,
|
|
2573
|
+
bottomPt: DEFAULT_MARGIN_PT$1,
|
|
2574
|
+
leftPt: DEFAULT_MARGIN_PT$1
|
|
2553
2575
|
};
|
|
2554
2576
|
function findPageLayoutElement(pkg, pageLayoutName) {
|
|
2555
2577
|
if (pageLayoutName === void 0) return;
|
|
@@ -2573,17 +2595,17 @@ function readFirstMasterPageGeometry(pkg) {
|
|
|
2573
2595
|
const pageSize = properties === void 0 ? void 0 : parsePageSize(properties);
|
|
2574
2596
|
const margins = properties === void 0 ? void 0 : parseMargins(properties);
|
|
2575
2597
|
return {
|
|
2576
|
-
pageSize: pageSize ?? DEFAULT_PAGE_SIZE$
|
|
2577
|
-
margins: margins ?? DEFAULT_MARGINS
|
|
2598
|
+
pageSize: pageSize ?? DEFAULT_PAGE_SIZE$2,
|
|
2599
|
+
margins: margins ?? DEFAULT_MARGINS$1
|
|
2578
2600
|
};
|
|
2579
2601
|
}
|
|
2580
2602
|
function readOdt(pkg) {
|
|
2581
|
-
const contentPart = pkg.parts[CONTENT_PART$
|
|
2582
|
-
if (contentPart?.kind !== "xml") throw new Error(`readOdt: package has no ${CONTENT_PART$
|
|
2603
|
+
const contentPart = pkg.parts[CONTENT_PART$2];
|
|
2604
|
+
if (contentPart?.kind !== "xml") throw new Error(`readOdt: package has no ${CONTENT_PART$2} part`);
|
|
2583
2605
|
const contentRoot = rootElement(contentPart.nodes);
|
|
2584
2606
|
const body = contentRoot === void 0 ? void 0 : findChildElement(contentRoot.children, "office:body");
|
|
2585
2607
|
const textElement = body === void 0 ? void 0 : findChildElement(body.children, "office:text");
|
|
2586
|
-
if (textElement === void 0) throw new Error(`readOdt: ${CONTENT_PART$
|
|
2608
|
+
if (textElement === void 0) throw new Error(`readOdt: ${CONTENT_PART$2} has no office:body/office:text element`);
|
|
2587
2609
|
const metadata = readOdfMetadata(pkg);
|
|
2588
2610
|
const { pageSize, margins } = readFirstMasterPageGeometry(pkg);
|
|
2589
2611
|
return {
|
|
@@ -2597,10 +2619,10 @@ function readOdt(pkg) {
|
|
|
2597
2619
|
}
|
|
2598
2620
|
//#endregion
|
|
2599
2621
|
//#region src/typed/odg/read.ts
|
|
2600
|
-
const CONTENT_PART = "content.xml";
|
|
2601
|
-
const DEFAULT_PAGE_SIZE = document_content_model.PAGE_SIZE_A4;
|
|
2622
|
+
const CONTENT_PART$1 = "content.xml";
|
|
2623
|
+
const DEFAULT_PAGE_SIZE$1 = document_content_model.PAGE_SIZE_A4;
|
|
2602
2624
|
function readPage(page, pkg) {
|
|
2603
|
-
const size = resolveDrawPageSize(page, pkg) ?? DEFAULT_PAGE_SIZE;
|
|
2625
|
+
const size = resolveDrawPageSize(page, pkg) ?? DEFAULT_PAGE_SIZE$1;
|
|
2604
2626
|
const { shapes, vectors } = readDrawPageContent(page.children, pkg);
|
|
2605
2627
|
return {
|
|
2606
2628
|
size,
|
|
@@ -2609,7 +2631,7 @@ function readPage(page, pkg) {
|
|
|
2609
2631
|
};
|
|
2610
2632
|
}
|
|
2611
2633
|
function readOdg(pkg) {
|
|
2612
|
-
const contentPart = pkg.parts[CONTENT_PART];
|
|
2634
|
+
const contentPart = pkg.parts[CONTENT_PART$1];
|
|
2613
2635
|
const root = contentPart?.kind === "xml" ? rootElement(contentPart.nodes) : void 0;
|
|
2614
2636
|
const body = root === void 0 ? void 0 : findChildElement(root.children, "office:body");
|
|
2615
2637
|
const drawing = body === void 0 ? void 0 : findChildElement(body.children, "office:drawing");
|
|
@@ -2620,6 +2642,313 @@ function readOdg(pkg) {
|
|
|
2620
2642
|
};
|
|
2621
2643
|
}
|
|
2622
2644
|
//#endregion
|
|
2645
|
+
//#region src/typed/ods/read.ts
|
|
2646
|
+
const CONTENT_PART = "content.xml";
|
|
2647
|
+
function parseKnownOdfLength(value) {
|
|
2648
|
+
const parsed = parseOdfLength(value);
|
|
2649
|
+
if (parsed === void 0) throw new Error(`readOds: internal error -- "${value}" is not a valid ODF length literal`);
|
|
2650
|
+
return parsed;
|
|
2651
|
+
}
|
|
2652
|
+
const DEFAULT_PAGE_SIZE = document_content_model.PAGE_SIZE_A4;
|
|
2653
|
+
const DEFAULT_MARGIN_PT = parseKnownOdfLength("2cm");
|
|
2654
|
+
const DEFAULT_MARGINS = {
|
|
2655
|
+
topPt: DEFAULT_MARGIN_PT,
|
|
2656
|
+
rightPt: DEFAULT_MARGIN_PT,
|
|
2657
|
+
bottomPt: DEFAULT_MARGIN_PT,
|
|
2658
|
+
leftPt: DEFAULT_MARGIN_PT
|
|
2659
|
+
};
|
|
2660
|
+
function readRepeatCount(element, attrName) {
|
|
2661
|
+
const raw = attrValue(element, attrName);
|
|
2662
|
+
if (raw === void 0) return 1;
|
|
2663
|
+
const parsed = Number.parseInt(raw, 10);
|
|
2664
|
+
return Number.isInteger(parsed) && parsed > 0 ? parsed : 1;
|
|
2665
|
+
}
|
|
2666
|
+
function isHidden(element) {
|
|
2667
|
+
return attrValue(element, "table:visibility") === "collapse";
|
|
2668
|
+
}
|
|
2669
|
+
function readColumnLayout(columnElement, pkg) {
|
|
2670
|
+
const styleName = attrValue(columnElement, "table:style-name");
|
|
2671
|
+
const styleElement = styleName === void 0 ? void 0 : findStyleElement(styleName, "table-column", pkg);
|
|
2672
|
+
const properties = styleElement === void 0 ? void 0 : childrenWithTag(styleElement, "style:table-column-properties")[0];
|
|
2673
|
+
const widthValue = properties === void 0 ? void 0 : attrValue(properties, "style:column-width");
|
|
2674
|
+
return {
|
|
2675
|
+
widthPt: widthValue === void 0 ? 0 : parseOdfLength(widthValue) ?? 0,
|
|
2676
|
+
manualBreak: (properties === void 0 ? void 0 : attrValue(properties, "fo:break-before")) === "page"
|
|
2677
|
+
};
|
|
2678
|
+
}
|
|
2679
|
+
function readRowLayout(rowElement, pkg) {
|
|
2680
|
+
const styleName = attrValue(rowElement, "table:style-name");
|
|
2681
|
+
const styleElement = styleName === void 0 ? void 0 : findStyleElement(styleName, "table-row", pkg);
|
|
2682
|
+
const properties = styleElement === void 0 ? void 0 : childrenWithTag(styleElement, "style:table-row-properties")[0];
|
|
2683
|
+
const heightValue = properties === void 0 ? void 0 : attrValue(properties, "style:row-height");
|
|
2684
|
+
return {
|
|
2685
|
+
heightPt: heightValue === void 0 ? 0 : parseOdfLength(heightValue) ?? 0,
|
|
2686
|
+
manualBreak: (properties === void 0 ? void 0 : attrValue(properties, "fo:break-before")) === "page"
|
|
2687
|
+
};
|
|
2688
|
+
}
|
|
2689
|
+
function readCellText(cellElement, pkg) {
|
|
2690
|
+
const paragraphs = childrenWithTag(cellElement, "text:p");
|
|
2691
|
+
const runs = [];
|
|
2692
|
+
paragraphs.forEach((paragraph, index) => {
|
|
2693
|
+
if (index > 0) runs.push({ text: "\n" });
|
|
2694
|
+
runs.push(...readOdfParagraph(paragraph, pkg).runs);
|
|
2695
|
+
});
|
|
2696
|
+
return {
|
|
2697
|
+
runs,
|
|
2698
|
+
displayText: runs.map((run) => run.text).join("")
|
|
2699
|
+
};
|
|
2700
|
+
}
|
|
2701
|
+
function readCellValue(cellElement, displayText) {
|
|
2702
|
+
const valueType = attrValue(cellElement, "office:value-type");
|
|
2703
|
+
const stringFallback = {
|
|
2704
|
+
kind: "string",
|
|
2705
|
+
value: displayText
|
|
2706
|
+
};
|
|
2707
|
+
switch (valueType) {
|
|
2708
|
+
case "float": {
|
|
2709
|
+
const value = parseRequiredNumber(attrValue(cellElement, "office:value"));
|
|
2710
|
+
return value === void 0 ? stringFallback : {
|
|
2711
|
+
kind: "number",
|
|
2712
|
+
value
|
|
2713
|
+
};
|
|
2714
|
+
}
|
|
2715
|
+
case "percentage": {
|
|
2716
|
+
const value = parseRequiredNumber(attrValue(cellElement, "office:value"));
|
|
2717
|
+
return value === void 0 ? stringFallback : {
|
|
2718
|
+
kind: "percentage",
|
|
2719
|
+
value
|
|
2720
|
+
};
|
|
2721
|
+
}
|
|
2722
|
+
case "currency": {
|
|
2723
|
+
const value = parseRequiredNumber(attrValue(cellElement, "office:value"));
|
|
2724
|
+
if (value === void 0) return stringFallback;
|
|
2725
|
+
const currency = attrValue(cellElement, "office:currency");
|
|
2726
|
+
return currency === void 0 ? {
|
|
2727
|
+
kind: "currency",
|
|
2728
|
+
value
|
|
2729
|
+
} : {
|
|
2730
|
+
kind: "currency",
|
|
2731
|
+
value,
|
|
2732
|
+
currency
|
|
2733
|
+
};
|
|
2734
|
+
}
|
|
2735
|
+
case "boolean": {
|
|
2736
|
+
const raw = attrValue(cellElement, "office:boolean-value");
|
|
2737
|
+
return raw === void 0 ? stringFallback : {
|
|
2738
|
+
kind: "boolean",
|
|
2739
|
+
value: raw === "true"
|
|
2740
|
+
};
|
|
2741
|
+
}
|
|
2742
|
+
case "date": return {
|
|
2743
|
+
kind: "date",
|
|
2744
|
+
value: attrValue(cellElement, "office:date-value") ?? displayText
|
|
2745
|
+
};
|
|
2746
|
+
case "time": return {
|
|
2747
|
+
kind: "time",
|
|
2748
|
+
value: attrValue(cellElement, "office:time-value") ?? displayText
|
|
2749
|
+
};
|
|
2750
|
+
case "string": return {
|
|
2751
|
+
kind: "string",
|
|
2752
|
+
value: attrValue(cellElement, "office:string-value") ?? displayText
|
|
2753
|
+
};
|
|
2754
|
+
default: return { kind: "empty" };
|
|
2755
|
+
}
|
|
2756
|
+
}
|
|
2757
|
+
function parseRequiredNumber(raw) {
|
|
2758
|
+
if (raw === void 0) return;
|
|
2759
|
+
const value = Number(raw);
|
|
2760
|
+
return Number.isNaN(value) ? void 0 : value;
|
|
2761
|
+
}
|
|
2762
|
+
function parsePrintRanges(value) {
|
|
2763
|
+
const first = value.split(" ").find((part) => part.length > 0);
|
|
2764
|
+
if (first === void 0) return;
|
|
2765
|
+
const separatorIndex = first.indexOf(":");
|
|
2766
|
+
if (separatorIndex === -1) return;
|
|
2767
|
+
const start = parseA1WithOptionalSheetPrefix(first.slice(0, separatorIndex));
|
|
2768
|
+
const end = parseA1WithOptionalSheetPrefix(first.slice(separatorIndex + 1));
|
|
2769
|
+
if (start === void 0 || end === void 0) return;
|
|
2770
|
+
return {
|
|
2771
|
+
startRow: start.row,
|
|
2772
|
+
startColumn: start.column,
|
|
2773
|
+
endRow: end.row,
|
|
2774
|
+
endColumn: end.column
|
|
2775
|
+
};
|
|
2776
|
+
}
|
|
2777
|
+
function parseA1WithOptionalSheetPrefix(cellPart) {
|
|
2778
|
+
const dotIndex = cellPart.lastIndexOf(".");
|
|
2779
|
+
return parseCellReference(dotIndex === -1 ? cellPart : cellPart.slice(dotIndex + 1));
|
|
2780
|
+
}
|
|
2781
|
+
function parseScalePercentage(value) {
|
|
2782
|
+
const match = /^(\d+(?:\.\d+)?)%$/.exec(value);
|
|
2783
|
+
if (match === null) return;
|
|
2784
|
+
const numeric = match[1];
|
|
2785
|
+
return numeric === void 0 ? void 0 : Number(numeric);
|
|
2786
|
+
}
|
|
2787
|
+
function parseNonNegativeInteger(value) {
|
|
2788
|
+
if (value === void 0) return;
|
|
2789
|
+
const parsed = Number.parseInt(value, 10);
|
|
2790
|
+
return Number.isInteger(parsed) && parsed >= 0 ? parsed : void 0;
|
|
2791
|
+
}
|
|
2792
|
+
function readTable(tableElement, pkg) {
|
|
2793
|
+
const columns = [];
|
|
2794
|
+
const rows = [];
|
|
2795
|
+
const cells = [];
|
|
2796
|
+
const manualBreakRows = [];
|
|
2797
|
+
const manualBreakColumns = [];
|
|
2798
|
+
let repeatColumns;
|
|
2799
|
+
let repeatRows;
|
|
2800
|
+
let columnCursor = 0;
|
|
2801
|
+
const cursor = new TableCursor();
|
|
2802
|
+
function processColumn(columnElement) {
|
|
2803
|
+
const startIndex = columnCursor;
|
|
2804
|
+
const { widthPt, manualBreak } = readColumnLayout(columnElement, pkg);
|
|
2805
|
+
columns.push({
|
|
2806
|
+
index: startIndex,
|
|
2807
|
+
widthPt,
|
|
2808
|
+
hidden: isHidden(columnElement) ? true : void 0
|
|
2809
|
+
});
|
|
2810
|
+
if (manualBreak) manualBreakColumns.push(startIndex);
|
|
2811
|
+
columnCursor += readRepeatCount(columnElement, "table:number-columns-repeated");
|
|
2812
|
+
}
|
|
2813
|
+
function processRowCells(rowElement) {
|
|
2814
|
+
for (const child of rowElement.children) {
|
|
2815
|
+
if (child.type !== "element") continue;
|
|
2816
|
+
if (child.tag === "table:covered-table-cell") cursor.nextCell(readRepeatCount(child, "table:number-columns-repeated"));
|
|
2817
|
+
else if (child.tag === "table:table-cell") {
|
|
2818
|
+
const columnIndex = cursor.columnIndex;
|
|
2819
|
+
const rowIndex = cursor.rowIndex;
|
|
2820
|
+
cursor.nextCell(readRepeatCount(child, "table:number-columns-repeated"));
|
|
2821
|
+
const formula = attrValue(child, "table:formula");
|
|
2822
|
+
const { runs, displayText } = readCellText(child, pkg);
|
|
2823
|
+
if (!(attrValue(child, "office:value-type") !== void 0) && formula === void 0 && displayText.length === 0) continue;
|
|
2824
|
+
const value = readCellValue(child, displayText);
|
|
2825
|
+
const colSpan = parseNonNegativeInteger(attrValue(child, "table:number-columns-spanned"));
|
|
2826
|
+
const rowSpan = parseNonNegativeInteger(attrValue(child, "table:number-rows-spanned"));
|
|
2827
|
+
const cell = {
|
|
2828
|
+
row: rowIndex,
|
|
2829
|
+
column: columnIndex,
|
|
2830
|
+
value,
|
|
2831
|
+
displayText
|
|
2832
|
+
};
|
|
2833
|
+
if (formula !== void 0) cell.formula = formula;
|
|
2834
|
+
if (runs.length > 0) cell.runs = runs;
|
|
2835
|
+
if (colSpan !== void 0) cell.colSpan = colSpan;
|
|
2836
|
+
if (rowSpan !== void 0) cell.rowSpan = rowSpan;
|
|
2837
|
+
cells.push(cell);
|
|
2838
|
+
}
|
|
2839
|
+
}
|
|
2840
|
+
}
|
|
2841
|
+
function processRow(rowElement) {
|
|
2842
|
+
const startIndex = cursor.rowIndex;
|
|
2843
|
+
processRowCells(rowElement);
|
|
2844
|
+
const { heightPt, manualBreak } = readRowLayout(rowElement, pkg);
|
|
2845
|
+
rows.push({
|
|
2846
|
+
index: startIndex,
|
|
2847
|
+
heightPt,
|
|
2848
|
+
hidden: isHidden(rowElement) ? true : void 0
|
|
2849
|
+
});
|
|
2850
|
+
if (manualBreak) manualBreakRows.push(startIndex);
|
|
2851
|
+
cursor.nextRow(readRepeatCount(rowElement, "table:number-rows-repeated"));
|
|
2852
|
+
}
|
|
2853
|
+
for (const child of tableElement.children) {
|
|
2854
|
+
if (child.type !== "element") continue;
|
|
2855
|
+
if (child.tag === "table:table-column") processColumn(child);
|
|
2856
|
+
else if (child.tag === "table:table-header-columns") {
|
|
2857
|
+
const startIndex = columnCursor;
|
|
2858
|
+
for (const headerChild of child.children) if (headerChild.type === "element" && headerChild.tag === "table:table-column") processColumn(headerChild);
|
|
2859
|
+
if (columnCursor > startIndex) repeatColumns = {
|
|
2860
|
+
start: startIndex,
|
|
2861
|
+
end: columnCursor - 1
|
|
2862
|
+
};
|
|
2863
|
+
} else if (child.tag === "table:table-row") processRow(child);
|
|
2864
|
+
else if (child.tag === "table:table-header-rows") {
|
|
2865
|
+
const startIndex = cursor.rowIndex;
|
|
2866
|
+
for (const headerChild of child.children) if (headerChild.type === "element" && headerChild.tag === "table:table-row") processRow(headerChild);
|
|
2867
|
+
if (cursor.rowIndex > startIndex) repeatRows = {
|
|
2868
|
+
start: startIndex,
|
|
2869
|
+
end: cursor.rowIndex - 1
|
|
2870
|
+
};
|
|
2871
|
+
}
|
|
2872
|
+
}
|
|
2873
|
+
return {
|
|
2874
|
+
columns,
|
|
2875
|
+
rows,
|
|
2876
|
+
cells,
|
|
2877
|
+
repeatColumns,
|
|
2878
|
+
repeatRows,
|
|
2879
|
+
manualBreakRows,
|
|
2880
|
+
manualBreakColumns
|
|
2881
|
+
};
|
|
2882
|
+
}
|
|
2883
|
+
function readPrintSettings(tableElement, pkg, repeatColumns, repeatRows, manualBreakRows, manualBreakColumns) {
|
|
2884
|
+
const tableStyleName = attrValue(tableElement, "table:style-name");
|
|
2885
|
+
const tableStyleElement = tableStyleName === void 0 ? void 0 : findStyleElement(tableStyleName, "table", pkg);
|
|
2886
|
+
const layoutProperties = resolvePageLayoutProperties(pkg, tableStyleElement === void 0 ? void 0 : attrValue(tableStyleElement, "style:master-page-name"));
|
|
2887
|
+
const pageSize = layoutProperties === void 0 ? void 0 : parsePageSize(layoutProperties);
|
|
2888
|
+
const margins = layoutProperties === void 0 ? void 0 : parseMargins(layoutProperties);
|
|
2889
|
+
const printTokens = new Set((layoutProperties === void 0 ? void 0 : attrValue(layoutProperties, "style:print"))?.split(" ").filter((token) => token.length > 0));
|
|
2890
|
+
const pageOrder = (layoutProperties === void 0 ? void 0 : attrValue(layoutProperties, "style:print-page-order")) === "ltr" ? "overThenDown" : "downThenOver";
|
|
2891
|
+
const scaleToRaw = layoutProperties === void 0 ? void 0 : attrValue(layoutProperties, "style:scale-to");
|
|
2892
|
+
const scale = scaleToRaw === void 0 ? void 0 : parseScalePercentage(scaleToRaw);
|
|
2893
|
+
const scaleToXRaw = layoutProperties === void 0 ? void 0 : attrValue(layoutProperties, "style:scale-to-X");
|
|
2894
|
+
const scaleToYRaw = layoutProperties === void 0 ? void 0 : attrValue(layoutProperties, "style:scale-to-Y");
|
|
2895
|
+
const fitWidth = parseNonNegativeInteger(scaleToXRaw);
|
|
2896
|
+
const fitHeight = parseNonNegativeInteger(scaleToYRaw);
|
|
2897
|
+
const fitToPages = fitWidth === void 0 || fitHeight === void 0 ? void 0 : {
|
|
2898
|
+
width: fitWidth,
|
|
2899
|
+
height: fitHeight
|
|
2900
|
+
};
|
|
2901
|
+
const printRangesRaw = attrValue(tableElement, "table:print-ranges");
|
|
2902
|
+
const printRange = printRangesRaw === void 0 ? void 0 : parsePrintRanges(printRangesRaw);
|
|
2903
|
+
const manualBreaks = manualBreakRows.length > 0 || manualBreakColumns.length > 0 ? {
|
|
2904
|
+
rows: manualBreakRows,
|
|
2905
|
+
columns: manualBreakColumns
|
|
2906
|
+
} : void 0;
|
|
2907
|
+
const settings = {
|
|
2908
|
+
pageSize: pageSize ?? DEFAULT_PAGE_SIZE,
|
|
2909
|
+
margins: margins ?? DEFAULT_MARGINS,
|
|
2910
|
+
gridlines: printTokens.has("grid"),
|
|
2911
|
+
headers: printTokens.has("headers"),
|
|
2912
|
+
pageOrder
|
|
2913
|
+
};
|
|
2914
|
+
if (printRange !== void 0) settings.printRange = printRange;
|
|
2915
|
+
if (scale !== void 0) settings.scale = scale;
|
|
2916
|
+
if (fitToPages !== void 0) settings.fitToPages = fitToPages;
|
|
2917
|
+
if (repeatRows !== void 0) settings.repeatRows = repeatRows;
|
|
2918
|
+
if (repeatColumns !== void 0) settings.repeatColumns = repeatColumns;
|
|
2919
|
+
if (manualBreaks !== void 0) settings.manualBreaks = manualBreaks;
|
|
2920
|
+
return settings;
|
|
2921
|
+
}
|
|
2922
|
+
function readSheet(tableElement, pkg) {
|
|
2923
|
+
const name = attrValue(tableElement, "table:name");
|
|
2924
|
+
if (name === void 0) return;
|
|
2925
|
+
const { columns, rows, cells, repeatColumns, repeatRows, manualBreakRows, manualBreakColumns } = readTable(tableElement, pkg);
|
|
2926
|
+
return {
|
|
2927
|
+
name,
|
|
2928
|
+
cells,
|
|
2929
|
+
columns,
|
|
2930
|
+
rows,
|
|
2931
|
+
images: [],
|
|
2932
|
+
printSettings: readPrintSettings(tableElement, pkg, repeatColumns, repeatRows, manualBreakRows, manualBreakColumns)
|
|
2933
|
+
};
|
|
2934
|
+
}
|
|
2935
|
+
function readOds(pkg) {
|
|
2936
|
+
const contentPart = pkg.parts[CONTENT_PART];
|
|
2937
|
+
const root = contentPart?.kind === "xml" ? rootElement(contentPart.nodes) : void 0;
|
|
2938
|
+
const body = root === void 0 ? void 0 : findChildElement(root.children, "office:body");
|
|
2939
|
+
const spreadsheet = body === void 0 ? void 0 : findChildElement(body.children, "office:spreadsheet");
|
|
2940
|
+
const tables = spreadsheet === void 0 ? [] : childrenWithTag(spreadsheet, "table:table");
|
|
2941
|
+
const sheets = [];
|
|
2942
|
+
for (const table of tables) {
|
|
2943
|
+
const sheet = readSheet(table, pkg);
|
|
2944
|
+
if (sheet !== void 0) sheets.push(sheet);
|
|
2945
|
+
}
|
|
2946
|
+
return {
|
|
2947
|
+
metadata: readOdfMetadata(pkg),
|
|
2948
|
+
sheets
|
|
2949
|
+
};
|
|
2950
|
+
}
|
|
2951
|
+
//#endregion
|
|
2623
2952
|
Object.defineProperty(exports, "AlignmentSchema", {
|
|
2624
2953
|
enumerable: true,
|
|
2625
2954
|
get: function() {
|
|
@@ -2662,6 +2991,7 @@ exports.canonicalPropertiesString = canonicalPropertiesString;
|
|
|
2662
2991
|
exports.cellReference = cellReference;
|
|
2663
2992
|
exports.childrenWithTag = childrenWithTag;
|
|
2664
2993
|
exports.columnIndexToLetters = columnIndexToLetters;
|
|
2994
|
+
exports.columnLettersToIndex = columnLettersToIndex;
|
|
2665
2995
|
exports.composeOdfGroupTransform = composeOdfGroupTransform;
|
|
2666
2996
|
exports.decodeOdfText = decodeOdfText;
|
|
2667
2997
|
exports.decodePackage = decodePackage;
|
|
@@ -2686,6 +3016,7 @@ exports.netRotationDeg = netRotationDeg;
|
|
|
2686
3016
|
exports.packageCodec = packageCodec;
|
|
2687
3017
|
exports.paragraphPropertiesToAttributes = paragraphPropertiesToAttributes;
|
|
2688
3018
|
exports.parseBox = parseBox;
|
|
3019
|
+
exports.parseCellReference = parseCellReference;
|
|
2689
3020
|
exports.parseLength = parseLength;
|
|
2690
3021
|
exports.parseLinePoints = parseLinePoints;
|
|
2691
3022
|
exports.parseMargins = parseMargins;
|
|
@@ -2711,9 +3042,11 @@ exports.readOdfParagraph = readOdfParagraph;
|
|
|
2711
3042
|
exports.readOdfTable = readOdfTable;
|
|
2712
3043
|
exports.readOdg = readOdg;
|
|
2713
3044
|
exports.readOdp = readOdp;
|
|
3045
|
+
exports.readOds = readOds;
|
|
2714
3046
|
exports.readOdt = readOdt;
|
|
2715
3047
|
exports.resolveDrawPageSize = resolveDrawPageSize;
|
|
2716
3048
|
exports.resolveOdfShapeGeometry = resolveOdfShapeGeometry;
|
|
3049
|
+
exports.resolvePageLayoutProperties = resolvePageLayoutProperties;
|
|
2717
3050
|
exports.resolveStyle = resolveStyle;
|
|
2718
3051
|
exports.resolveStyleElementChain = resolveStyleElementChain;
|
|
2719
3052
|
exports.rootElement = rootElement;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import { Alignment, AlignmentSchema, Box, Color, ContentDrawPage, ContentParagraph, ContentPathPoint, ContentSection, ContentShape, ContentSlide, ContentSubpath, ContentTable, ContentVector, LayoutMetadata, Margins, PageSize } from "document-content-model";
|
|
2
|
+
import { Alignment, AlignmentSchema, Box, Color, ContentDrawPage, ContentParagraph, ContentPathPoint, ContentSection, ContentShape, ContentSheet, ContentSlide, ContentSubpath, ContentTable, ContentVector, LayoutMetadata, Margins, PageSize } from "document-content-model";
|
|
3
3
|
//#region src/model/node.d.ts
|
|
4
4
|
declare const AttributeSchema: z.ZodObject<{
|
|
5
5
|
name: z.ZodString;
|
|
@@ -486,6 +486,11 @@ declare function attrValue(element: XmlElement, name: string): string | undefine
|
|
|
486
486
|
//#region src/typed/shared/a1.d.ts
|
|
487
487
|
declare function columnIndexToLetters(index: number): string;
|
|
488
488
|
declare function cellReference(columnIndex: number, rowIndex: number): string;
|
|
489
|
+
declare function columnLettersToIndex(letters: string): number | undefined;
|
|
490
|
+
declare function parseCellReference(reference: string): {
|
|
491
|
+
column: number;
|
|
492
|
+
row: number;
|
|
493
|
+
} | undefined;
|
|
489
494
|
declare class TableCursor {
|
|
490
495
|
private columnCursor;
|
|
491
496
|
private rowCursor;
|
|
@@ -565,6 +570,7 @@ declare function resolveOdfShapeGeometry(element: XmlElement): OdfShapeGeometry
|
|
|
565
570
|
declare function composeOdfGroupTransform(groupFunctions: readonly OdfTransformFunction[], child: OdfShapeGeometry): OdfShapeGeometry;
|
|
566
571
|
//#endregion
|
|
567
572
|
//#region src/typed/shared/masterpage.d.ts
|
|
573
|
+
declare function resolvePageLayoutProperties(pkg: Package, masterPageName: string | undefined): XmlElement | undefined;
|
|
568
574
|
declare function resolveDrawPageSize(page: XmlElement, pkg: Package): PageSize | undefined;
|
|
569
575
|
//#endregion
|
|
570
576
|
//#region src/typed/shared/path.d.ts
|
|
@@ -629,4 +635,11 @@ interface OdgDocument {
|
|
|
629
635
|
}
|
|
630
636
|
declare function readOdg(pkg: Package): OdgDocument;
|
|
631
637
|
//#endregion
|
|
632
|
-
|
|
638
|
+
//#region src/typed/ods/read.d.ts
|
|
639
|
+
interface OdsDocument {
|
|
640
|
+
metadata: LayoutMetadata;
|
|
641
|
+
sheets: ContentSheet[];
|
|
642
|
+
}
|
|
643
|
+
declare function readOds(pkg: Package): OdsDocument;
|
|
644
|
+
//#endregion
|
|
645
|
+
export { type Alignment, AlignmentSchema, type Attribute, AttributeSchema, type BinaryPart, BinaryPartSchema, type BuildManifestOptions, type CascadeDiagnostic, type DrawPageContent, type ImageFormat, type InternRequest, type LengthUnit, MANIFEST_PART, META_PART, MIMETYPE_PART, type Manifest, type ManifestEntry, ManifestEntrySchema, type ManifestProblem, ManifestProblemSchema, ManifestSchema, ODF_MEDIA_TYPES, ODF_NAMESPACES, type OdfExtension, type OdfNamespacePrefix, type OdfPoint, type OdfRawPoint, type OdfRawSegment, type OdfRawSubpath, type OdfShapeGeometry, type OdfTransformFunction, type OdfViewBox, type OdgDocument, type OdpDocument, type OdsDocument, type OdtDocument, type OtherPartRef, type Package, PackageSchema, type ParsedProperties, type Part, PartSchema, STYLE_FAMILIES, type StyleCascadeResult, type StyleElementChainResult, type StyleFamily, type StyleProperties, StylePropertiesSchema, StyleRegistry, type StyleRegistryOptions, TableCursor, type XmlCdata, XmlCdataSchema, type XmlComment, XmlCommentSchema, type XmlDeclaration, XmlDeclarationSchema, type XmlElement, XmlElementSchema, type XmlNode, XmlNodeSchema, type XmlPart, XmlPartSchema, type XmlPi, XmlPiSchema, type XmlText, XmlTextSchema, type ZipEntry, applyOdfTransform, attrValue, base64ToBytes, buildManifest, buildOdfSubpaths, buildStylePropertyElements, buildXml, bytesToBase64, canonicalPropertiesString, cellReference, childrenWithTag, columnIndexToLetters, columnLettersToIndex, composeOdfGroupTransform, decodeOdfText, decodePackage, decodeXmlText, el, elementsWithTag, encodePackage, encodeXmlText, ensureSpan, findChildElement, findStyleElement, formatOdfColor, formatOdfLength, formatPercentageMultiplier, formatPt, getOdfSpaceCount, isStyleFamily, isXmlNode, measureOdfNodeLength, mediaTypeForExtension, netRotationDeg, packageCodec, paragraphPropertiesToAttributes, parseBox, parseCellReference, parseLength, parseLinePoints, parseMargins, parseOdfColor, parseOdfLength, parseOdfPathData, parseOdfPointsList, parseOdfTransform, parseOdfViewBox, parsePackage, parsePageSize, parseParagraphProperties, parseStyleElementProperties, parseTextProperties, parseXml, rawSubpathFromPoints, readDrawFrame, readDrawPageContent, readManifest, readMimetype, readOdfMetadata, readOdfParagraph, readOdfTable, readOdg, readOdp, readOds, readOdt, resolveDrawPageSize, resolveOdfShapeGeometry, resolvePageLayoutProperties, resolveStyle, resolveStyleElementChain, rootElement, scaleOdfRawPoint, serializePackage, setDocumentMediaType, sniffImageFormat, sumOdfNodeLength, syncManifest, textPropertiesToAttributes, txt, unzipPackage, validateManifest, walkDrawShapes, writeManifest, writeMimetype, xmlCodec, xmlnsAttributes, zipPackage };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import { Alignment, AlignmentSchema, Box, Color, ContentDrawPage, ContentParagraph, ContentPathPoint, ContentSection, ContentShape, ContentSlide, ContentSubpath, ContentTable, ContentVector, LayoutMetadata, Margins, PageSize } from "document-content-model";
|
|
2
|
+
import { Alignment, AlignmentSchema, Box, Color, ContentDrawPage, ContentParagraph, ContentPathPoint, ContentSection, ContentShape, ContentSheet, ContentSlide, ContentSubpath, ContentTable, ContentVector, LayoutMetadata, Margins, PageSize } from "document-content-model";
|
|
3
3
|
//#region src/model/node.d.ts
|
|
4
4
|
declare const AttributeSchema: z.ZodObject<{
|
|
5
5
|
name: z.ZodString;
|
|
@@ -486,6 +486,11 @@ declare function attrValue(element: XmlElement, name: string): string | undefine
|
|
|
486
486
|
//#region src/typed/shared/a1.d.ts
|
|
487
487
|
declare function columnIndexToLetters(index: number): string;
|
|
488
488
|
declare function cellReference(columnIndex: number, rowIndex: number): string;
|
|
489
|
+
declare function columnLettersToIndex(letters: string): number | undefined;
|
|
490
|
+
declare function parseCellReference(reference: string): {
|
|
491
|
+
column: number;
|
|
492
|
+
row: number;
|
|
493
|
+
} | undefined;
|
|
489
494
|
declare class TableCursor {
|
|
490
495
|
private columnCursor;
|
|
491
496
|
private rowCursor;
|
|
@@ -565,6 +570,7 @@ declare function resolveOdfShapeGeometry(element: XmlElement): OdfShapeGeometry
|
|
|
565
570
|
declare function composeOdfGroupTransform(groupFunctions: readonly OdfTransformFunction[], child: OdfShapeGeometry): OdfShapeGeometry;
|
|
566
571
|
//#endregion
|
|
567
572
|
//#region src/typed/shared/masterpage.d.ts
|
|
573
|
+
declare function resolvePageLayoutProperties(pkg: Package, masterPageName: string | undefined): XmlElement | undefined;
|
|
568
574
|
declare function resolveDrawPageSize(page: XmlElement, pkg: Package): PageSize | undefined;
|
|
569
575
|
//#endregion
|
|
570
576
|
//#region src/typed/shared/path.d.ts
|
|
@@ -629,4 +635,11 @@ interface OdgDocument {
|
|
|
629
635
|
}
|
|
630
636
|
declare function readOdg(pkg: Package): OdgDocument;
|
|
631
637
|
//#endregion
|
|
632
|
-
|
|
638
|
+
//#region src/typed/ods/read.d.ts
|
|
639
|
+
interface OdsDocument {
|
|
640
|
+
metadata: LayoutMetadata;
|
|
641
|
+
sheets: ContentSheet[];
|
|
642
|
+
}
|
|
643
|
+
declare function readOds(pkg: Package): OdsDocument;
|
|
644
|
+
//#endregion
|
|
645
|
+
export { type Alignment, AlignmentSchema, type Attribute, AttributeSchema, type BinaryPart, BinaryPartSchema, type BuildManifestOptions, type CascadeDiagnostic, type DrawPageContent, type ImageFormat, type InternRequest, type LengthUnit, MANIFEST_PART, META_PART, MIMETYPE_PART, type Manifest, type ManifestEntry, ManifestEntrySchema, type ManifestProblem, ManifestProblemSchema, ManifestSchema, ODF_MEDIA_TYPES, ODF_NAMESPACES, type OdfExtension, type OdfNamespacePrefix, type OdfPoint, type OdfRawPoint, type OdfRawSegment, type OdfRawSubpath, type OdfShapeGeometry, type OdfTransformFunction, type OdfViewBox, type OdgDocument, type OdpDocument, type OdsDocument, type OdtDocument, type OtherPartRef, type Package, PackageSchema, type ParsedProperties, type Part, PartSchema, STYLE_FAMILIES, type StyleCascadeResult, type StyleElementChainResult, type StyleFamily, type StyleProperties, StylePropertiesSchema, StyleRegistry, type StyleRegistryOptions, TableCursor, type XmlCdata, XmlCdataSchema, type XmlComment, XmlCommentSchema, type XmlDeclaration, XmlDeclarationSchema, type XmlElement, XmlElementSchema, type XmlNode, XmlNodeSchema, type XmlPart, XmlPartSchema, type XmlPi, XmlPiSchema, type XmlText, XmlTextSchema, type ZipEntry, applyOdfTransform, attrValue, base64ToBytes, buildManifest, buildOdfSubpaths, buildStylePropertyElements, buildXml, bytesToBase64, canonicalPropertiesString, cellReference, childrenWithTag, columnIndexToLetters, columnLettersToIndex, composeOdfGroupTransform, decodeOdfText, decodePackage, decodeXmlText, el, elementsWithTag, encodePackage, encodeXmlText, ensureSpan, findChildElement, findStyleElement, formatOdfColor, formatOdfLength, formatPercentageMultiplier, formatPt, getOdfSpaceCount, isStyleFamily, isXmlNode, measureOdfNodeLength, mediaTypeForExtension, netRotationDeg, packageCodec, paragraphPropertiesToAttributes, parseBox, parseCellReference, parseLength, parseLinePoints, parseMargins, parseOdfColor, parseOdfLength, parseOdfPathData, parseOdfPointsList, parseOdfTransform, parseOdfViewBox, parsePackage, parsePageSize, parseParagraphProperties, parseStyleElementProperties, parseTextProperties, parseXml, rawSubpathFromPoints, readDrawFrame, readDrawPageContent, readManifest, readMimetype, readOdfMetadata, readOdfParagraph, readOdfTable, readOdg, readOdp, readOds, readOdt, resolveDrawPageSize, resolveOdfShapeGeometry, resolvePageLayoutProperties, resolveStyle, resolveStyleElementChain, rootElement, scaleOdfRawPoint, serializePackage, setDocumentMediaType, sniffImageFormat, sumOdfNodeLength, syncManifest, textPropertiesToAttributes, txt, unzipPackage, validateManifest, walkDrawShapes, writeManifest, writeMimetype, xmlCodec, xmlnsAttributes, zipPackage };
|
package/dist/index.js
CHANGED
|
@@ -1420,6 +1420,25 @@ function cellReference(columnIndex, rowIndex) {
|
|
|
1420
1420
|
if (!Number.isInteger(rowIndex) || rowIndex < 0) throw new Error(`cellReference: rowIndex must be a non-negative integer, got ${rowIndex}`);
|
|
1421
1421
|
return `${columnIndexToLetters(columnIndex)}${rowIndex + 1}`;
|
|
1422
1422
|
}
|
|
1423
|
+
function columnLettersToIndex(letters) {
|
|
1424
|
+
if (!/^[A-Z]+$/.test(letters)) return;
|
|
1425
|
+
let index = 0;
|
|
1426
|
+
for (const char of letters) index = index * ALPHABET_SIZE + (char.charCodeAt(0) - ALPHABET_START_CODE + 1);
|
|
1427
|
+
return index - 1;
|
|
1428
|
+
}
|
|
1429
|
+
function parseCellReference(reference) {
|
|
1430
|
+
const match = /^([A-Z]+)(\d+)$/.exec(reference);
|
|
1431
|
+
if (match === null) return;
|
|
1432
|
+
const [, letters, digits] = match;
|
|
1433
|
+
if (letters === void 0 || digits === void 0) return;
|
|
1434
|
+
const column = columnLettersToIndex(letters);
|
|
1435
|
+
const row = Number.parseInt(digits, 10) - 1;
|
|
1436
|
+
if (column === void 0 || row < 0) return;
|
|
1437
|
+
return {
|
|
1438
|
+
column,
|
|
1439
|
+
row
|
|
1440
|
+
};
|
|
1441
|
+
}
|
|
1423
1442
|
function validateRepeatCount(repeatCount, caller) {
|
|
1424
1443
|
if (!Number.isInteger(repeatCount) || repeatCount < 1) throw new Error(`${caller}: repeatCount must be a positive integer, got ${repeatCount}`);
|
|
1425
1444
|
}
|
|
@@ -1701,7 +1720,7 @@ function readOdfParagraph(pElement, pkg) {
|
|
|
1701
1720
|
}
|
|
1702
1721
|
//#endregion
|
|
1703
1722
|
//#region src/typed/shared/table.ts
|
|
1704
|
-
function readRepeatCount(element, attrName) {
|
|
1723
|
+
function readRepeatCount$1(element, attrName) {
|
|
1705
1724
|
const raw = attrValue(element, attrName);
|
|
1706
1725
|
if (raw === void 0) return 1;
|
|
1707
1726
|
const parsed = Number.parseInt(raw, 10);
|
|
@@ -1744,11 +1763,11 @@ function readTableRow(rowElement, pkg) {
|
|
|
1744
1763
|
for (const child of rowElement.children) {
|
|
1745
1764
|
if (child.type !== "element") continue;
|
|
1746
1765
|
if (child.tag === "table:covered-table-cell") {
|
|
1747
|
-
const repeat = readRepeatCount(child, "table:number-columns-repeated");
|
|
1766
|
+
const repeat = readRepeatCount$1(child, "table:number-columns-repeated");
|
|
1748
1767
|
for (let i = 0; i < repeat; i++) cells.push({ blocks: [] });
|
|
1749
1768
|
} else if (child.tag === "table:table-cell") {
|
|
1750
1769
|
const cell = readTableCell(child, pkg);
|
|
1751
|
-
const repeat = readRepeatCount(child, "table:number-columns-repeated");
|
|
1770
|
+
const repeat = readRepeatCount$1(child, "table:number-columns-repeated");
|
|
1752
1771
|
for (let i = 0; i < repeat; i++) cells.push(cell);
|
|
1753
1772
|
}
|
|
1754
1773
|
}
|
|
@@ -1761,13 +1780,13 @@ function readOdfTable(tableElement, pkg) {
|
|
|
1761
1780
|
const columnWidthsPt = [];
|
|
1762
1781
|
for (const column of childrenWithTag(tableElement, "table:table-column")) {
|
|
1763
1782
|
const widthPt = resolveColumnWidthPt(column, pkg);
|
|
1764
|
-
const repeat = readRepeatCount(column, "table:number-columns-repeated");
|
|
1783
|
+
const repeat = readRepeatCount$1(column, "table:number-columns-repeated");
|
|
1765
1784
|
for (let i = 0; i < repeat; i++) columnWidthsPt.push(widthPt);
|
|
1766
1785
|
}
|
|
1767
1786
|
const rows = [];
|
|
1768
1787
|
for (const rowElement of childrenWithTag(tableElement, "table:table-row")) {
|
|
1769
1788
|
const row = readTableRow(rowElement, pkg);
|
|
1770
|
-
const repeat = readRepeatCount(rowElement, "table:number-rows-repeated");
|
|
1789
|
+
const repeat = readRepeatCount$1(rowElement, "table:number-rows-repeated");
|
|
1771
1790
|
for (let i = 0; i < repeat; i++) rows.push(row);
|
|
1772
1791
|
}
|
|
1773
1792
|
return {
|
|
@@ -1904,10 +1923,13 @@ function findPageLayoutElement$1(pkg, pageLayoutName) {
|
|
|
1904
1923
|
if (found !== void 0) return found;
|
|
1905
1924
|
}
|
|
1906
1925
|
}
|
|
1907
|
-
function
|
|
1908
|
-
const masterPage = findMasterPageElement(pkg,
|
|
1926
|
+
function resolvePageLayoutProperties(pkg, masterPageName) {
|
|
1927
|
+
const masterPage = findMasterPageElement(pkg, masterPageName);
|
|
1909
1928
|
const pageLayout = findPageLayoutElement$1(pkg, masterPage === void 0 ? void 0 : attrValue(masterPage, "style:page-layout-name"));
|
|
1910
|
-
|
|
1929
|
+
return pageLayout === void 0 ? void 0 : childrenWithTag(pageLayout, "style:page-layout-properties")[0];
|
|
1930
|
+
}
|
|
1931
|
+
function resolveDrawPageSize(page, pkg) {
|
|
1932
|
+
const properties = resolvePageLayoutProperties(pkg, attrValue(page, "draw:master-page-name"));
|
|
1911
1933
|
return properties === void 0 ? void 0 : parsePageSize(properties);
|
|
1912
1934
|
}
|
|
1913
1935
|
//#endregion
|
|
@@ -2461,7 +2483,7 @@ function readDrawPageContent(children, pkg) {
|
|
|
2461
2483
|
}
|
|
2462
2484
|
//#endregion
|
|
2463
2485
|
//#region src/typed/odp/read.ts
|
|
2464
|
-
const CONTENT_PART$
|
|
2486
|
+
const CONTENT_PART$3 = "content.xml";
|
|
2465
2487
|
function readSlideSize(page, pkg) {
|
|
2466
2488
|
return resolveDrawPageSize(page, pkg) ?? SLIDE_SIZE_WIDESCREEN;
|
|
2467
2489
|
}
|
|
@@ -2480,7 +2502,7 @@ function readSlide(page, pkg) {
|
|
|
2480
2502
|
};
|
|
2481
2503
|
}
|
|
2482
2504
|
function readOdp(pkg) {
|
|
2483
|
-
const contentPart = pkg.parts[CONTENT_PART$
|
|
2505
|
+
const contentPart = pkg.parts[CONTENT_PART$3];
|
|
2484
2506
|
const root = contentPart?.kind === "xml" ? rootElement(contentPart.nodes) : void 0;
|
|
2485
2507
|
const body = root === void 0 ? void 0 : findChildElement(root.children, "office:body");
|
|
2486
2508
|
const presentation = body === void 0 ? void 0 : findChildElement(body.children, "office:presentation");
|
|
@@ -2492,9 +2514,9 @@ function readOdp(pkg) {
|
|
|
2492
2514
|
}
|
|
2493
2515
|
//#endregion
|
|
2494
2516
|
//#region src/typed/odt/read.ts
|
|
2495
|
-
const CONTENT_PART$
|
|
2517
|
+
const CONTENT_PART$2 = "content.xml";
|
|
2496
2518
|
const STYLES_PART = "styles.xml";
|
|
2497
|
-
const AUTOMATIC_STYLE_PARTS = [CONTENT_PART$
|
|
2519
|
+
const AUTOMATIC_STYLE_PARTS = [CONTENT_PART$2, STYLES_PART];
|
|
2498
2520
|
function readOutlineLevel(headingElement) {
|
|
2499
2521
|
const raw = attrValue(headingElement, "text:outline-level");
|
|
2500
2522
|
if (raw === void 0) return 1;
|
|
@@ -2537,18 +2559,18 @@ function readBlocks(nodes, pkg, listIdState) {
|
|
|
2537
2559
|
}
|
|
2538
2560
|
return blocks;
|
|
2539
2561
|
}
|
|
2540
|
-
function parseKnownOdfLength(value) {
|
|
2562
|
+
function parseKnownOdfLength$1(value) {
|
|
2541
2563
|
const parsed = parseOdfLength(value);
|
|
2542
2564
|
if (parsed === void 0) throw new Error(`readOdt: internal error -- "${value}" is not a valid ODF length literal`);
|
|
2543
2565
|
return parsed;
|
|
2544
2566
|
}
|
|
2545
|
-
const DEFAULT_PAGE_SIZE$
|
|
2546
|
-
const DEFAULT_MARGIN_PT = parseKnownOdfLength("2cm");
|
|
2547
|
-
const DEFAULT_MARGINS = {
|
|
2548
|
-
topPt: DEFAULT_MARGIN_PT,
|
|
2549
|
-
rightPt: DEFAULT_MARGIN_PT,
|
|
2550
|
-
bottomPt: DEFAULT_MARGIN_PT,
|
|
2551
|
-
leftPt: DEFAULT_MARGIN_PT
|
|
2567
|
+
const DEFAULT_PAGE_SIZE$2 = PAGE_SIZE_A4;
|
|
2568
|
+
const DEFAULT_MARGIN_PT$1 = parseKnownOdfLength$1("2cm");
|
|
2569
|
+
const DEFAULT_MARGINS$1 = {
|
|
2570
|
+
topPt: DEFAULT_MARGIN_PT$1,
|
|
2571
|
+
rightPt: DEFAULT_MARGIN_PT$1,
|
|
2572
|
+
bottomPt: DEFAULT_MARGIN_PT$1,
|
|
2573
|
+
leftPt: DEFAULT_MARGIN_PT$1
|
|
2552
2574
|
};
|
|
2553
2575
|
function findPageLayoutElement(pkg, pageLayoutName) {
|
|
2554
2576
|
if (pageLayoutName === void 0) return;
|
|
@@ -2572,17 +2594,17 @@ function readFirstMasterPageGeometry(pkg) {
|
|
|
2572
2594
|
const pageSize = properties === void 0 ? void 0 : parsePageSize(properties);
|
|
2573
2595
|
const margins = properties === void 0 ? void 0 : parseMargins(properties);
|
|
2574
2596
|
return {
|
|
2575
|
-
pageSize: pageSize ?? DEFAULT_PAGE_SIZE$
|
|
2576
|
-
margins: margins ?? DEFAULT_MARGINS
|
|
2597
|
+
pageSize: pageSize ?? DEFAULT_PAGE_SIZE$2,
|
|
2598
|
+
margins: margins ?? DEFAULT_MARGINS$1
|
|
2577
2599
|
};
|
|
2578
2600
|
}
|
|
2579
2601
|
function readOdt(pkg) {
|
|
2580
|
-
const contentPart = pkg.parts[CONTENT_PART$
|
|
2581
|
-
if (contentPart?.kind !== "xml") throw new Error(`readOdt: package has no ${CONTENT_PART$
|
|
2602
|
+
const contentPart = pkg.parts[CONTENT_PART$2];
|
|
2603
|
+
if (contentPart?.kind !== "xml") throw new Error(`readOdt: package has no ${CONTENT_PART$2} part`);
|
|
2582
2604
|
const contentRoot = rootElement(contentPart.nodes);
|
|
2583
2605
|
const body = contentRoot === void 0 ? void 0 : findChildElement(contentRoot.children, "office:body");
|
|
2584
2606
|
const textElement = body === void 0 ? void 0 : findChildElement(body.children, "office:text");
|
|
2585
|
-
if (textElement === void 0) throw new Error(`readOdt: ${CONTENT_PART$
|
|
2607
|
+
if (textElement === void 0) throw new Error(`readOdt: ${CONTENT_PART$2} has no office:body/office:text element`);
|
|
2586
2608
|
const metadata = readOdfMetadata(pkg);
|
|
2587
2609
|
const { pageSize, margins } = readFirstMasterPageGeometry(pkg);
|
|
2588
2610
|
return {
|
|
@@ -2596,10 +2618,10 @@ function readOdt(pkg) {
|
|
|
2596
2618
|
}
|
|
2597
2619
|
//#endregion
|
|
2598
2620
|
//#region src/typed/odg/read.ts
|
|
2599
|
-
const CONTENT_PART = "content.xml";
|
|
2600
|
-
const DEFAULT_PAGE_SIZE = PAGE_SIZE_A4;
|
|
2621
|
+
const CONTENT_PART$1 = "content.xml";
|
|
2622
|
+
const DEFAULT_PAGE_SIZE$1 = PAGE_SIZE_A4;
|
|
2601
2623
|
function readPage(page, pkg) {
|
|
2602
|
-
const size = resolveDrawPageSize(page, pkg) ?? DEFAULT_PAGE_SIZE;
|
|
2624
|
+
const size = resolveDrawPageSize(page, pkg) ?? DEFAULT_PAGE_SIZE$1;
|
|
2603
2625
|
const { shapes, vectors } = readDrawPageContent(page.children, pkg);
|
|
2604
2626
|
return {
|
|
2605
2627
|
size,
|
|
@@ -2608,7 +2630,7 @@ function readPage(page, pkg) {
|
|
|
2608
2630
|
};
|
|
2609
2631
|
}
|
|
2610
2632
|
function readOdg(pkg) {
|
|
2611
|
-
const contentPart = pkg.parts[CONTENT_PART];
|
|
2633
|
+
const contentPart = pkg.parts[CONTENT_PART$1];
|
|
2612
2634
|
const root = contentPart?.kind === "xml" ? rootElement(contentPart.nodes) : void 0;
|
|
2613
2635
|
const body = root === void 0 ? void 0 : findChildElement(root.children, "office:body");
|
|
2614
2636
|
const drawing = body === void 0 ? void 0 : findChildElement(body.children, "office:drawing");
|
|
@@ -2619,4 +2641,311 @@ function readOdg(pkg) {
|
|
|
2619
2641
|
};
|
|
2620
2642
|
}
|
|
2621
2643
|
//#endregion
|
|
2622
|
-
|
|
2644
|
+
//#region src/typed/ods/read.ts
|
|
2645
|
+
const CONTENT_PART = "content.xml";
|
|
2646
|
+
function parseKnownOdfLength(value) {
|
|
2647
|
+
const parsed = parseOdfLength(value);
|
|
2648
|
+
if (parsed === void 0) throw new Error(`readOds: internal error -- "${value}" is not a valid ODF length literal`);
|
|
2649
|
+
return parsed;
|
|
2650
|
+
}
|
|
2651
|
+
const DEFAULT_PAGE_SIZE = PAGE_SIZE_A4;
|
|
2652
|
+
const DEFAULT_MARGIN_PT = parseKnownOdfLength("2cm");
|
|
2653
|
+
const DEFAULT_MARGINS = {
|
|
2654
|
+
topPt: DEFAULT_MARGIN_PT,
|
|
2655
|
+
rightPt: DEFAULT_MARGIN_PT,
|
|
2656
|
+
bottomPt: DEFAULT_MARGIN_PT,
|
|
2657
|
+
leftPt: DEFAULT_MARGIN_PT
|
|
2658
|
+
};
|
|
2659
|
+
function readRepeatCount(element, attrName) {
|
|
2660
|
+
const raw = attrValue(element, attrName);
|
|
2661
|
+
if (raw === void 0) return 1;
|
|
2662
|
+
const parsed = Number.parseInt(raw, 10);
|
|
2663
|
+
return Number.isInteger(parsed) && parsed > 0 ? parsed : 1;
|
|
2664
|
+
}
|
|
2665
|
+
function isHidden(element) {
|
|
2666
|
+
return attrValue(element, "table:visibility") === "collapse";
|
|
2667
|
+
}
|
|
2668
|
+
function readColumnLayout(columnElement, pkg) {
|
|
2669
|
+
const styleName = attrValue(columnElement, "table:style-name");
|
|
2670
|
+
const styleElement = styleName === void 0 ? void 0 : findStyleElement(styleName, "table-column", pkg);
|
|
2671
|
+
const properties = styleElement === void 0 ? void 0 : childrenWithTag(styleElement, "style:table-column-properties")[0];
|
|
2672
|
+
const widthValue = properties === void 0 ? void 0 : attrValue(properties, "style:column-width");
|
|
2673
|
+
return {
|
|
2674
|
+
widthPt: widthValue === void 0 ? 0 : parseOdfLength(widthValue) ?? 0,
|
|
2675
|
+
manualBreak: (properties === void 0 ? void 0 : attrValue(properties, "fo:break-before")) === "page"
|
|
2676
|
+
};
|
|
2677
|
+
}
|
|
2678
|
+
function readRowLayout(rowElement, pkg) {
|
|
2679
|
+
const styleName = attrValue(rowElement, "table:style-name");
|
|
2680
|
+
const styleElement = styleName === void 0 ? void 0 : findStyleElement(styleName, "table-row", pkg);
|
|
2681
|
+
const properties = styleElement === void 0 ? void 0 : childrenWithTag(styleElement, "style:table-row-properties")[0];
|
|
2682
|
+
const heightValue = properties === void 0 ? void 0 : attrValue(properties, "style:row-height");
|
|
2683
|
+
return {
|
|
2684
|
+
heightPt: heightValue === void 0 ? 0 : parseOdfLength(heightValue) ?? 0,
|
|
2685
|
+
manualBreak: (properties === void 0 ? void 0 : attrValue(properties, "fo:break-before")) === "page"
|
|
2686
|
+
};
|
|
2687
|
+
}
|
|
2688
|
+
function readCellText(cellElement, pkg) {
|
|
2689
|
+
const paragraphs = childrenWithTag(cellElement, "text:p");
|
|
2690
|
+
const runs = [];
|
|
2691
|
+
paragraphs.forEach((paragraph, index) => {
|
|
2692
|
+
if (index > 0) runs.push({ text: "\n" });
|
|
2693
|
+
runs.push(...readOdfParagraph(paragraph, pkg).runs);
|
|
2694
|
+
});
|
|
2695
|
+
return {
|
|
2696
|
+
runs,
|
|
2697
|
+
displayText: runs.map((run) => run.text).join("")
|
|
2698
|
+
};
|
|
2699
|
+
}
|
|
2700
|
+
function readCellValue(cellElement, displayText) {
|
|
2701
|
+
const valueType = attrValue(cellElement, "office:value-type");
|
|
2702
|
+
const stringFallback = {
|
|
2703
|
+
kind: "string",
|
|
2704
|
+
value: displayText
|
|
2705
|
+
};
|
|
2706
|
+
switch (valueType) {
|
|
2707
|
+
case "float": {
|
|
2708
|
+
const value = parseRequiredNumber(attrValue(cellElement, "office:value"));
|
|
2709
|
+
return value === void 0 ? stringFallback : {
|
|
2710
|
+
kind: "number",
|
|
2711
|
+
value
|
|
2712
|
+
};
|
|
2713
|
+
}
|
|
2714
|
+
case "percentage": {
|
|
2715
|
+
const value = parseRequiredNumber(attrValue(cellElement, "office:value"));
|
|
2716
|
+
return value === void 0 ? stringFallback : {
|
|
2717
|
+
kind: "percentage",
|
|
2718
|
+
value
|
|
2719
|
+
};
|
|
2720
|
+
}
|
|
2721
|
+
case "currency": {
|
|
2722
|
+
const value = parseRequiredNumber(attrValue(cellElement, "office:value"));
|
|
2723
|
+
if (value === void 0) return stringFallback;
|
|
2724
|
+
const currency = attrValue(cellElement, "office:currency");
|
|
2725
|
+
return currency === void 0 ? {
|
|
2726
|
+
kind: "currency",
|
|
2727
|
+
value
|
|
2728
|
+
} : {
|
|
2729
|
+
kind: "currency",
|
|
2730
|
+
value,
|
|
2731
|
+
currency
|
|
2732
|
+
};
|
|
2733
|
+
}
|
|
2734
|
+
case "boolean": {
|
|
2735
|
+
const raw = attrValue(cellElement, "office:boolean-value");
|
|
2736
|
+
return raw === void 0 ? stringFallback : {
|
|
2737
|
+
kind: "boolean",
|
|
2738
|
+
value: raw === "true"
|
|
2739
|
+
};
|
|
2740
|
+
}
|
|
2741
|
+
case "date": return {
|
|
2742
|
+
kind: "date",
|
|
2743
|
+
value: attrValue(cellElement, "office:date-value") ?? displayText
|
|
2744
|
+
};
|
|
2745
|
+
case "time": return {
|
|
2746
|
+
kind: "time",
|
|
2747
|
+
value: attrValue(cellElement, "office:time-value") ?? displayText
|
|
2748
|
+
};
|
|
2749
|
+
case "string": return {
|
|
2750
|
+
kind: "string",
|
|
2751
|
+
value: attrValue(cellElement, "office:string-value") ?? displayText
|
|
2752
|
+
};
|
|
2753
|
+
default: return { kind: "empty" };
|
|
2754
|
+
}
|
|
2755
|
+
}
|
|
2756
|
+
function parseRequiredNumber(raw) {
|
|
2757
|
+
if (raw === void 0) return;
|
|
2758
|
+
const value = Number(raw);
|
|
2759
|
+
return Number.isNaN(value) ? void 0 : value;
|
|
2760
|
+
}
|
|
2761
|
+
function parsePrintRanges(value) {
|
|
2762
|
+
const first = value.split(" ").find((part) => part.length > 0);
|
|
2763
|
+
if (first === void 0) return;
|
|
2764
|
+
const separatorIndex = first.indexOf(":");
|
|
2765
|
+
if (separatorIndex === -1) return;
|
|
2766
|
+
const start = parseA1WithOptionalSheetPrefix(first.slice(0, separatorIndex));
|
|
2767
|
+
const end = parseA1WithOptionalSheetPrefix(first.slice(separatorIndex + 1));
|
|
2768
|
+
if (start === void 0 || end === void 0) return;
|
|
2769
|
+
return {
|
|
2770
|
+
startRow: start.row,
|
|
2771
|
+
startColumn: start.column,
|
|
2772
|
+
endRow: end.row,
|
|
2773
|
+
endColumn: end.column
|
|
2774
|
+
};
|
|
2775
|
+
}
|
|
2776
|
+
function parseA1WithOptionalSheetPrefix(cellPart) {
|
|
2777
|
+
const dotIndex = cellPart.lastIndexOf(".");
|
|
2778
|
+
return parseCellReference(dotIndex === -1 ? cellPart : cellPart.slice(dotIndex + 1));
|
|
2779
|
+
}
|
|
2780
|
+
function parseScalePercentage(value) {
|
|
2781
|
+
const match = /^(\d+(?:\.\d+)?)%$/.exec(value);
|
|
2782
|
+
if (match === null) return;
|
|
2783
|
+
const numeric = match[1];
|
|
2784
|
+
return numeric === void 0 ? void 0 : Number(numeric);
|
|
2785
|
+
}
|
|
2786
|
+
function parseNonNegativeInteger(value) {
|
|
2787
|
+
if (value === void 0) return;
|
|
2788
|
+
const parsed = Number.parseInt(value, 10);
|
|
2789
|
+
return Number.isInteger(parsed) && parsed >= 0 ? parsed : void 0;
|
|
2790
|
+
}
|
|
2791
|
+
function readTable(tableElement, pkg) {
|
|
2792
|
+
const columns = [];
|
|
2793
|
+
const rows = [];
|
|
2794
|
+
const cells = [];
|
|
2795
|
+
const manualBreakRows = [];
|
|
2796
|
+
const manualBreakColumns = [];
|
|
2797
|
+
let repeatColumns;
|
|
2798
|
+
let repeatRows;
|
|
2799
|
+
let columnCursor = 0;
|
|
2800
|
+
const cursor = new TableCursor();
|
|
2801
|
+
function processColumn(columnElement) {
|
|
2802
|
+
const startIndex = columnCursor;
|
|
2803
|
+
const { widthPt, manualBreak } = readColumnLayout(columnElement, pkg);
|
|
2804
|
+
columns.push({
|
|
2805
|
+
index: startIndex,
|
|
2806
|
+
widthPt,
|
|
2807
|
+
hidden: isHidden(columnElement) ? true : void 0
|
|
2808
|
+
});
|
|
2809
|
+
if (manualBreak) manualBreakColumns.push(startIndex);
|
|
2810
|
+
columnCursor += readRepeatCount(columnElement, "table:number-columns-repeated");
|
|
2811
|
+
}
|
|
2812
|
+
function processRowCells(rowElement) {
|
|
2813
|
+
for (const child of rowElement.children) {
|
|
2814
|
+
if (child.type !== "element") continue;
|
|
2815
|
+
if (child.tag === "table:covered-table-cell") cursor.nextCell(readRepeatCount(child, "table:number-columns-repeated"));
|
|
2816
|
+
else if (child.tag === "table:table-cell") {
|
|
2817
|
+
const columnIndex = cursor.columnIndex;
|
|
2818
|
+
const rowIndex = cursor.rowIndex;
|
|
2819
|
+
cursor.nextCell(readRepeatCount(child, "table:number-columns-repeated"));
|
|
2820
|
+
const formula = attrValue(child, "table:formula");
|
|
2821
|
+
const { runs, displayText } = readCellText(child, pkg);
|
|
2822
|
+
if (!(attrValue(child, "office:value-type") !== void 0) && formula === void 0 && displayText.length === 0) continue;
|
|
2823
|
+
const value = readCellValue(child, displayText);
|
|
2824
|
+
const colSpan = parseNonNegativeInteger(attrValue(child, "table:number-columns-spanned"));
|
|
2825
|
+
const rowSpan = parseNonNegativeInteger(attrValue(child, "table:number-rows-spanned"));
|
|
2826
|
+
const cell = {
|
|
2827
|
+
row: rowIndex,
|
|
2828
|
+
column: columnIndex,
|
|
2829
|
+
value,
|
|
2830
|
+
displayText
|
|
2831
|
+
};
|
|
2832
|
+
if (formula !== void 0) cell.formula = formula;
|
|
2833
|
+
if (runs.length > 0) cell.runs = runs;
|
|
2834
|
+
if (colSpan !== void 0) cell.colSpan = colSpan;
|
|
2835
|
+
if (rowSpan !== void 0) cell.rowSpan = rowSpan;
|
|
2836
|
+
cells.push(cell);
|
|
2837
|
+
}
|
|
2838
|
+
}
|
|
2839
|
+
}
|
|
2840
|
+
function processRow(rowElement) {
|
|
2841
|
+
const startIndex = cursor.rowIndex;
|
|
2842
|
+
processRowCells(rowElement);
|
|
2843
|
+
const { heightPt, manualBreak } = readRowLayout(rowElement, pkg);
|
|
2844
|
+
rows.push({
|
|
2845
|
+
index: startIndex,
|
|
2846
|
+
heightPt,
|
|
2847
|
+
hidden: isHidden(rowElement) ? true : void 0
|
|
2848
|
+
});
|
|
2849
|
+
if (manualBreak) manualBreakRows.push(startIndex);
|
|
2850
|
+
cursor.nextRow(readRepeatCount(rowElement, "table:number-rows-repeated"));
|
|
2851
|
+
}
|
|
2852
|
+
for (const child of tableElement.children) {
|
|
2853
|
+
if (child.type !== "element") continue;
|
|
2854
|
+
if (child.tag === "table:table-column") processColumn(child);
|
|
2855
|
+
else if (child.tag === "table:table-header-columns") {
|
|
2856
|
+
const startIndex = columnCursor;
|
|
2857
|
+
for (const headerChild of child.children) if (headerChild.type === "element" && headerChild.tag === "table:table-column") processColumn(headerChild);
|
|
2858
|
+
if (columnCursor > startIndex) repeatColumns = {
|
|
2859
|
+
start: startIndex,
|
|
2860
|
+
end: columnCursor - 1
|
|
2861
|
+
};
|
|
2862
|
+
} else if (child.tag === "table:table-row") processRow(child);
|
|
2863
|
+
else if (child.tag === "table:table-header-rows") {
|
|
2864
|
+
const startIndex = cursor.rowIndex;
|
|
2865
|
+
for (const headerChild of child.children) if (headerChild.type === "element" && headerChild.tag === "table:table-row") processRow(headerChild);
|
|
2866
|
+
if (cursor.rowIndex > startIndex) repeatRows = {
|
|
2867
|
+
start: startIndex,
|
|
2868
|
+
end: cursor.rowIndex - 1
|
|
2869
|
+
};
|
|
2870
|
+
}
|
|
2871
|
+
}
|
|
2872
|
+
return {
|
|
2873
|
+
columns,
|
|
2874
|
+
rows,
|
|
2875
|
+
cells,
|
|
2876
|
+
repeatColumns,
|
|
2877
|
+
repeatRows,
|
|
2878
|
+
manualBreakRows,
|
|
2879
|
+
manualBreakColumns
|
|
2880
|
+
};
|
|
2881
|
+
}
|
|
2882
|
+
function readPrintSettings(tableElement, pkg, repeatColumns, repeatRows, manualBreakRows, manualBreakColumns) {
|
|
2883
|
+
const tableStyleName = attrValue(tableElement, "table:style-name");
|
|
2884
|
+
const tableStyleElement = tableStyleName === void 0 ? void 0 : findStyleElement(tableStyleName, "table", pkg);
|
|
2885
|
+
const layoutProperties = resolvePageLayoutProperties(pkg, tableStyleElement === void 0 ? void 0 : attrValue(tableStyleElement, "style:master-page-name"));
|
|
2886
|
+
const pageSize = layoutProperties === void 0 ? void 0 : parsePageSize(layoutProperties);
|
|
2887
|
+
const margins = layoutProperties === void 0 ? void 0 : parseMargins(layoutProperties);
|
|
2888
|
+
const printTokens = new Set((layoutProperties === void 0 ? void 0 : attrValue(layoutProperties, "style:print"))?.split(" ").filter((token) => token.length > 0));
|
|
2889
|
+
const pageOrder = (layoutProperties === void 0 ? void 0 : attrValue(layoutProperties, "style:print-page-order")) === "ltr" ? "overThenDown" : "downThenOver";
|
|
2890
|
+
const scaleToRaw = layoutProperties === void 0 ? void 0 : attrValue(layoutProperties, "style:scale-to");
|
|
2891
|
+
const scale = scaleToRaw === void 0 ? void 0 : parseScalePercentage(scaleToRaw);
|
|
2892
|
+
const scaleToXRaw = layoutProperties === void 0 ? void 0 : attrValue(layoutProperties, "style:scale-to-X");
|
|
2893
|
+
const scaleToYRaw = layoutProperties === void 0 ? void 0 : attrValue(layoutProperties, "style:scale-to-Y");
|
|
2894
|
+
const fitWidth = parseNonNegativeInteger(scaleToXRaw);
|
|
2895
|
+
const fitHeight = parseNonNegativeInteger(scaleToYRaw);
|
|
2896
|
+
const fitToPages = fitWidth === void 0 || fitHeight === void 0 ? void 0 : {
|
|
2897
|
+
width: fitWidth,
|
|
2898
|
+
height: fitHeight
|
|
2899
|
+
};
|
|
2900
|
+
const printRangesRaw = attrValue(tableElement, "table:print-ranges");
|
|
2901
|
+
const printRange = printRangesRaw === void 0 ? void 0 : parsePrintRanges(printRangesRaw);
|
|
2902
|
+
const manualBreaks = manualBreakRows.length > 0 || manualBreakColumns.length > 0 ? {
|
|
2903
|
+
rows: manualBreakRows,
|
|
2904
|
+
columns: manualBreakColumns
|
|
2905
|
+
} : void 0;
|
|
2906
|
+
const settings = {
|
|
2907
|
+
pageSize: pageSize ?? DEFAULT_PAGE_SIZE,
|
|
2908
|
+
margins: margins ?? DEFAULT_MARGINS,
|
|
2909
|
+
gridlines: printTokens.has("grid"),
|
|
2910
|
+
headers: printTokens.has("headers"),
|
|
2911
|
+
pageOrder
|
|
2912
|
+
};
|
|
2913
|
+
if (printRange !== void 0) settings.printRange = printRange;
|
|
2914
|
+
if (scale !== void 0) settings.scale = scale;
|
|
2915
|
+
if (fitToPages !== void 0) settings.fitToPages = fitToPages;
|
|
2916
|
+
if (repeatRows !== void 0) settings.repeatRows = repeatRows;
|
|
2917
|
+
if (repeatColumns !== void 0) settings.repeatColumns = repeatColumns;
|
|
2918
|
+
if (manualBreaks !== void 0) settings.manualBreaks = manualBreaks;
|
|
2919
|
+
return settings;
|
|
2920
|
+
}
|
|
2921
|
+
function readSheet(tableElement, pkg) {
|
|
2922
|
+
const name = attrValue(tableElement, "table:name");
|
|
2923
|
+
if (name === void 0) return;
|
|
2924
|
+
const { columns, rows, cells, repeatColumns, repeatRows, manualBreakRows, manualBreakColumns } = readTable(tableElement, pkg);
|
|
2925
|
+
return {
|
|
2926
|
+
name,
|
|
2927
|
+
cells,
|
|
2928
|
+
columns,
|
|
2929
|
+
rows,
|
|
2930
|
+
images: [],
|
|
2931
|
+
printSettings: readPrintSettings(tableElement, pkg, repeatColumns, repeatRows, manualBreakRows, manualBreakColumns)
|
|
2932
|
+
};
|
|
2933
|
+
}
|
|
2934
|
+
function readOds(pkg) {
|
|
2935
|
+
const contentPart = pkg.parts[CONTENT_PART];
|
|
2936
|
+
const root = contentPart?.kind === "xml" ? rootElement(contentPart.nodes) : void 0;
|
|
2937
|
+
const body = root === void 0 ? void 0 : findChildElement(root.children, "office:body");
|
|
2938
|
+
const spreadsheet = body === void 0 ? void 0 : findChildElement(body.children, "office:spreadsheet");
|
|
2939
|
+
const tables = spreadsheet === void 0 ? [] : childrenWithTag(spreadsheet, "table:table");
|
|
2940
|
+
const sheets = [];
|
|
2941
|
+
for (const table of tables) {
|
|
2942
|
+
const sheet = readSheet(table, pkg);
|
|
2943
|
+
if (sheet !== void 0) sheets.push(sheet);
|
|
2944
|
+
}
|
|
2945
|
+
return {
|
|
2946
|
+
metadata: readOdfMetadata(pkg),
|
|
2947
|
+
sheets
|
|
2948
|
+
};
|
|
2949
|
+
}
|
|
2950
|
+
//#endregion
|
|
2951
|
+
export { AlignmentSchema, AttributeSchema, BinaryPartSchema, MANIFEST_PART, META_PART, MIMETYPE_PART, ManifestEntrySchema, ManifestProblemSchema, ManifestSchema, ODF_MEDIA_TYPES, ODF_NAMESPACES, PackageSchema, PartSchema, STYLE_FAMILIES, StylePropertiesSchema, StyleRegistry, TableCursor, XmlCdataSchema, XmlCommentSchema, XmlDeclarationSchema, XmlElementSchema, XmlNodeSchema, XmlPartSchema, XmlPiSchema, XmlTextSchema, applyOdfTransform, attrValue, base64ToBytes, buildManifest, buildOdfSubpaths, buildStylePropertyElements, buildXml, bytesToBase64, canonicalPropertiesString, cellReference, childrenWithTag, columnIndexToLetters, columnLettersToIndex, composeOdfGroupTransform, decodeOdfText, decodePackage, decodeXmlText, el, elementsWithTag, encodePackage, encodeXmlText, ensureSpan, findChildElement, findStyleElement, formatOdfColor, formatOdfLength, formatPercentageMultiplier, formatPt, getOdfSpaceCount, isStyleFamily, isXmlNode, measureOdfNodeLength, mediaTypeForExtension, netRotationDeg, packageCodec, paragraphPropertiesToAttributes, parseBox, parseCellReference, parseLength, parseLinePoints, parseMargins, parseOdfColor, parseOdfLength, parseOdfPathData, parseOdfPointsList, parseOdfTransform, parseOdfViewBox, parsePackage, parsePageSize, parseParagraphProperties, parseStyleElementProperties, parseTextProperties, parseXml, rawSubpathFromPoints, readDrawFrame, readDrawPageContent, readManifest, readMimetype, readOdfMetadata, readOdfParagraph, readOdfTable, readOdg, readOdp, readOds, readOdt, resolveDrawPageSize, resolveOdfShapeGeometry, resolvePageLayoutProperties, resolveStyle, resolveStyleElementChain, rootElement, scaleOdfRawPoint, serializePackage, setDocumentMediaType, sniffImageFormat, sumOdfNodeLength, syncManifest, textPropertiesToAttributes, txt, unzipPackage, validateManifest, walkDrawShapes, writeManifest, writeMimetype, xmlCodec, xmlnsAttributes, zipPackage };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "odf.js",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.0",
|
|
4
4
|
"description": "Type-safe, lossless round-trip conversion between OpenDocument Format packages (odt, ods, odp) and JSON, hand-written and dependency-minimal, built on Zod 4 codecs.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|