odf.js 1.12.0 → 1.13.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 +39 -0
- package/dist/codec.cjs +28 -0
- package/dist/codec.d.cts +72 -0
- package/dist/codec.d.ts +72 -0
- package/dist/codec.js +24 -0
- package/dist/image/sniff.cjs +28 -0
- package/dist/image/sniff.d.cts +5 -0
- package/dist/image/sniff.d.ts +5 -0
- package/dist/image/sniff.js +27 -0
- package/dist/index.cjs +156 -3242
- package/dist/index.d.cts +42 -679
- package/dist/index.d.ts +42 -679
- package/dist/index.js +42 -3129
- package/dist/manifest.cjs +252 -0
- package/dist/manifest.d.cts +41 -0
- package/dist/manifest.d.ts +41 -0
- package/dist/manifest.js +242 -0
- package/dist/media-type.cjs +27 -0
- package/dist/media-type.d.cts +20 -0
- package/dist/media-type.d.ts +20 -0
- package/dist/media-type.js +25 -0
- package/dist/mimetype.cjs +19 -0
- package/dist/mimetype.d.cts +7 -0
- package/dist/mimetype.d.ts +7 -0
- package/dist/mimetype.js +16 -0
- package/dist/model/node.cjs +67 -0
- package/dist/model/node.d.cts +2 -0
- package/dist/model/node.d.ts +2 -0
- package/dist/model/node.js +58 -0
- package/dist/model/package.cjs +19 -0
- package/dist/model/package.d.cts +114 -0
- package/dist/model/package.d.ts +114 -0
- package/dist/model/package.js +15 -0
- package/dist/node-CkBWRjNR.d.cts +83 -0
- package/dist/node-CkBWRjNR.d.ts +83 -0
- package/dist/ns.cjs +37 -0
- package/dist/ns.d.cts +32 -0
- package/dist/ns.d.ts +32 -0
- package/dist/ns.js +35 -0
- package/dist/package-io/read.cjs +35 -0
- package/dist/package-io/read.d.cts +5 -0
- package/dist/package-io/read.d.ts +5 -0
- package/dist/package-io/read.js +34 -0
- package/dist/package-io/write.cjs +36 -0
- package/dist/package-io/write.d.cts +7 -0
- package/dist/package-io/write.d.ts +7 -0
- package/dist/package-io/write.js +33 -0
- package/dist/styles/properties.cjs +286 -0
- package/dist/styles/properties.d.cts +45 -0
- package/dist/styles/properties.d.ts +45 -0
- package/dist/styles/properties.js +277 -0
- package/dist/styles/registry.cjs +212 -0
- package/dist/styles/registry.d.cts +37 -0
- package/dist/styles/registry.d.ts +37 -0
- package/dist/styles/registry.js +209 -0
- package/dist/styles/serialize.cjs +23 -0
- package/dist/styles/serialize.d.cts +7 -0
- package/dist/styles/serialize.d.ts +7 -0
- package/dist/styles/serialize.js +21 -0
- package/dist/styles/span.cjs +114 -0
- package/dist/styles/span.d.cts +5 -0
- package/dist/styles/span.d.ts +5 -0
- package/dist/styles/span.js +113 -0
- package/dist/typed/draw/shapes.cjs +314 -0
- package/dist/typed/draw/shapes.d.cts +14 -0
- package/dist/typed/draw/shapes.d.ts +14 -0
- package/dist/typed/draw/shapes.js +311 -0
- package/dist/typed/formula/read.cjs +48 -0
- package/dist/typed/formula/read.d.cts +12 -0
- package/dist/typed/formula/read.d.ts +12 -0
- package/dist/typed/formula/read.js +47 -0
- package/dist/typed/odb/read.cjs +112 -0
- package/dist/typed/odb/read.d.cts +17 -0
- package/dist/typed/odb/read.d.ts +17 -0
- package/dist/typed/odb/read.js +111 -0
- package/dist/typed/odg/read.cjs +30 -0
- package/dist/typed/odg/read.d.cts +10 -0
- package/dist/typed/odg/read.d.ts +10 -0
- package/dist/typed/odg/read.js +29 -0
- package/dist/typed/odm/read.cjs +37 -0
- package/dist/typed/odm/read.d.cts +15 -0
- package/dist/typed/odm/read.d.ts +15 -0
- package/dist/typed/odm/read.js +36 -0
- package/dist/typed/odp/read.cjs +39 -0
- package/dist/typed/odp/read.d.cts +10 -0
- package/dist/typed/odp/read.d.ts +10 -0
- package/dist/typed/odp/read.js +38 -0
- package/dist/typed/ods/read.cjs +318 -0
- package/dist/typed/ods/read.d.cts +10 -0
- package/dist/typed/ods/read.d.ts +10 -0
- package/dist/typed/ods/read.js +317 -0
- package/dist/typed/odt/read.cjs +112 -0
- package/dist/typed/odt/read.d.cts +10 -0
- package/dist/typed/odt/read.d.ts +10 -0
- package/dist/typed/odt/read.js +111 -0
- package/dist/typed/shared/a1.cjs +68 -0
- package/dist/typed/shared/a1.d.cts +18 -0
- package/dist/typed/shared/a1.d.ts +18 -0
- package/dist/typed/shared/a1.js +63 -0
- package/dist/typed/shared/cascade.cjs +102 -0
- package/dist/typed/shared/cascade.d.cts +22 -0
- package/dist/typed/shared/cascade.d.ts +22 -0
- package/dist/typed/shared/cascade.js +99 -0
- package/dist/typed/shared/color.cjs +14 -0
- package/dist/typed/shared/color.d.cts +6 -0
- package/dist/typed/shared/color.d.ts +6 -0
- package/dist/typed/shared/color.js +12 -0
- package/dist/typed/shared/geometry.cjs +79 -0
- package/dist/typed/shared/geometry.d.cts +12 -0
- package/dist/typed/shared/geometry.d.ts +12 -0
- package/dist/typed/shared/geometry.js +75 -0
- package/dist/typed/shared/masterpage.cjs +39 -0
- package/dist/typed/shared/masterpage.d.cts +8 -0
- package/dist/typed/shared/masterpage.d.ts +8 -0
- package/dist/typed/shared/masterpage.js +37 -0
- package/dist/typed/shared/metadata.cjs +42 -0
- package/dist/typed/shared/metadata.d.cts +7 -0
- package/dist/typed/shared/metadata.d.ts +7 -0
- package/dist/typed/shared/metadata.js +40 -0
- package/dist/typed/shared/paragraph.cjs +57 -0
- package/dist/typed/shared/paragraph.d.cts +7 -0
- package/dist/typed/shared/paragraph.d.ts +7 -0
- package/dist/typed/shared/paragraph.js +56 -0
- package/dist/typed/shared/path.cjs +261 -0
- package/dist/typed/shared/path.d.cts +34 -0
- package/dist/typed/shared/path.d.ts +34 -0
- package/dist/typed/shared/path.js +255 -0
- package/dist/typed/shared/style.cjs +8 -0
- package/dist/typed/shared/style.d.cts +2 -0
- package/dist/typed/shared/style.d.ts +2 -0
- package/dist/typed/shared/style.js +2 -0
- package/dist/typed/shared/table.cjs +84 -0
- package/dist/typed/shared/table.d.cts +7 -0
- package/dist/typed/shared/table.d.ts +7 -0
- package/dist/typed/shared/table.js +83 -0
- package/dist/typed/shared/text.cjs +43 -0
- package/dist/typed/shared/text.d.cts +8 -0
- package/dist/typed/shared/text.d.ts +8 -0
- package/dist/typed/shared/text.js +39 -0
- package/dist/typed/shared/transform.cjs +112 -0
- package/dist/typed/shared/transform.d.cts +26 -0
- package/dist/typed/shared/transform.d.ts +26 -0
- package/dist/typed/shared/transform.js +107 -0
- package/dist/typed/shared/units.cjs +35 -0
- package/dist/typed/shared/units.d.cts +2 -0
- package/dist/typed/shared/units.d.ts +2 -0
- package/dist/typed/shared/units.js +33 -0
- package/dist/units-7pCiECuP.d.cts +6 -0
- package/dist/units-7pCiECuP.d.ts +6 -0
- package/dist/util/base64.cjs +48 -0
- package/dist/util/base64.d.cts +5 -0
- package/dist/util/base64.d.ts +5 -0
- package/dist/util/base64.js +46 -0
- package/dist/xml/build.cjs +46 -0
- package/dist/xml/build.d.cts +5 -0
- package/dist/xml/build.d.ts +5 -0
- package/dist/xml/build.js +46 -0
- package/dist/xml/entities.cjs +19 -0
- package/dist/xml/entities.d.cts +5 -0
- package/dist/xml/entities.d.ts +5 -0
- package/dist/xml/entities.js +17 -0
- package/dist/xml/fragment.cjs +22 -0
- package/dist/xml/fragment.d.cts +6 -0
- package/dist/xml/fragment.d.ts +6 -0
- package/dist/xml/fragment.js +20 -0
- package/dist/xml/parse.cjs +88 -0
- package/dist/xml/parse.d.cts +5 -0
- package/dist/xml/parse.d.ts +5 -0
- package/dist/xml/parse.js +88 -0
- package/dist/xml/query.cjs +33 -0
- package/dist/xml/query.d.cts +9 -0
- package/dist/xml/query.d.ts +9 -0
- package/dist/xml/query.js +28 -0
- package/dist/zip.cjs +15 -0
- package/dist/zip.d.cts +9 -0
- package/dist/zip.d.ts +9 -0
- package/dist/zip.js +13 -0
- package/package.json +9 -1
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { childrenWithTag, elementsWithTag, findChildElement, rootElement } from "../../xml/query.js";
|
|
2
|
+
import { decodeOdfText } from "../shared/text.js";
|
|
3
|
+
import { readOdfMetadata } from "../shared/metadata.js";
|
|
4
|
+
import { resolveDrawPageSize } from "../shared/masterpage.js";
|
|
5
|
+
import { walkDrawShapes } from "../draw/shapes.js";
|
|
6
|
+
import { SLIDE_SIZE_WIDESCREEN } from "document-schema.js";
|
|
7
|
+
//#region src/typed/odp/read.ts
|
|
8
|
+
const CONTENT_PART = "content.xml";
|
|
9
|
+
function readSlideSize(page, pkg) {
|
|
10
|
+
return resolveDrawPageSize(page, pkg) ?? SLIDE_SIZE_WIDESCREEN;
|
|
11
|
+
}
|
|
12
|
+
function readSlideNotes(page) {
|
|
13
|
+
const notes = childrenWithTag(page, "presentation:notes")[0];
|
|
14
|
+
if (notes === void 0) return "";
|
|
15
|
+
return elementsWithTag(notes.children, "text:p").map(decodeOdfText).join("\n");
|
|
16
|
+
}
|
|
17
|
+
function readSlide(page, pkg) {
|
|
18
|
+
const shapes = [];
|
|
19
|
+
walkDrawShapes(page.children, [], pkg, shapes);
|
|
20
|
+
return {
|
|
21
|
+
size: readSlideSize(page, pkg),
|
|
22
|
+
shapes,
|
|
23
|
+
notes: readSlideNotes(page)
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
function readOdp(pkg) {
|
|
27
|
+
const contentPart = pkg.parts[CONTENT_PART];
|
|
28
|
+
const root = contentPart?.kind === "xml" ? rootElement(contentPart.nodes) : void 0;
|
|
29
|
+
const body = root === void 0 ? void 0 : findChildElement(root.children, "office:body");
|
|
30
|
+
const presentation = body === void 0 ? void 0 : findChildElement(body.children, "office:presentation");
|
|
31
|
+
const pages = presentation === void 0 ? [] : childrenWithTag(presentation, "draw:page");
|
|
32
|
+
return {
|
|
33
|
+
metadata: readOdfMetadata(pkg),
|
|
34
|
+
slides: pages.map((page) => readSlide(page, pkg))
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
//#endregion
|
|
38
|
+
export { readOdp };
|
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_typed_shared_units = require("../shared/units.cjs");
|
|
3
|
+
const require_xml_query = require("../../xml/query.cjs");
|
|
4
|
+
const require_typed_shared_a1 = require("../shared/a1.cjs");
|
|
5
|
+
const require_typed_shared_geometry = require("../shared/geometry.cjs");
|
|
6
|
+
const require_typed_shared_cascade = require("../shared/cascade.cjs");
|
|
7
|
+
const require_typed_shared_metadata = require("../shared/metadata.cjs");
|
|
8
|
+
const require_typed_shared_paragraph = require("../shared/paragraph.cjs");
|
|
9
|
+
const require_typed_shared_masterpage = require("../shared/masterpage.cjs");
|
|
10
|
+
let document_schema_js = require("document-schema.js");
|
|
11
|
+
//#region src/typed/ods/read.ts
|
|
12
|
+
const CONTENT_PART = "content.xml";
|
|
13
|
+
function parseKnownOdfLength(value) {
|
|
14
|
+
const parsed = require_typed_shared_units.parseOdfLength(value);
|
|
15
|
+
if (parsed === void 0) throw new Error(`readOds: internal error -- "${value}" is not a valid ODF length literal`);
|
|
16
|
+
return parsed;
|
|
17
|
+
}
|
|
18
|
+
const DEFAULT_MARGIN_PT = parseKnownOdfLength("2cm");
|
|
19
|
+
const DEFAULT_MARGINS = {
|
|
20
|
+
topPt: DEFAULT_MARGIN_PT,
|
|
21
|
+
rightPt: DEFAULT_MARGIN_PT,
|
|
22
|
+
bottomPt: DEFAULT_MARGIN_PT,
|
|
23
|
+
leftPt: DEFAULT_MARGIN_PT
|
|
24
|
+
};
|
|
25
|
+
function readRepeatCount(element, attrName) {
|
|
26
|
+
const raw = require_xml_query.attrValue(element, attrName);
|
|
27
|
+
if (raw === void 0) return 1;
|
|
28
|
+
const parsed = Number.parseInt(raw, 10);
|
|
29
|
+
return Number.isInteger(parsed) && parsed > 0 ? parsed : 1;
|
|
30
|
+
}
|
|
31
|
+
function isHidden(element) {
|
|
32
|
+
return require_xml_query.attrValue(element, "table:visibility") === "collapse";
|
|
33
|
+
}
|
|
34
|
+
function readColumnLayout(columnElement, pkg) {
|
|
35
|
+
const styleName = require_xml_query.attrValue(columnElement, "table:style-name");
|
|
36
|
+
const styleElement = styleName === void 0 ? void 0 : require_typed_shared_cascade.findStyleElement(styleName, "table-column", pkg);
|
|
37
|
+
const properties = styleElement === void 0 ? void 0 : require_xml_query.childrenWithTag(styleElement, "style:table-column-properties")[0];
|
|
38
|
+
const widthValue = properties === void 0 ? void 0 : require_xml_query.attrValue(properties, "style:column-width");
|
|
39
|
+
return {
|
|
40
|
+
widthPt: widthValue === void 0 ? 0 : require_typed_shared_units.parseOdfLength(widthValue) ?? 0,
|
|
41
|
+
manualBreak: (properties === void 0 ? void 0 : require_xml_query.attrValue(properties, "fo:break-before")) === "page"
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
function readRowLayout(rowElement, pkg) {
|
|
45
|
+
const styleName = require_xml_query.attrValue(rowElement, "table:style-name");
|
|
46
|
+
const styleElement = styleName === void 0 ? void 0 : require_typed_shared_cascade.findStyleElement(styleName, "table-row", pkg);
|
|
47
|
+
const properties = styleElement === void 0 ? void 0 : require_xml_query.childrenWithTag(styleElement, "style:table-row-properties")[0];
|
|
48
|
+
const heightValue = properties === void 0 ? void 0 : require_xml_query.attrValue(properties, "style:row-height");
|
|
49
|
+
return {
|
|
50
|
+
heightPt: heightValue === void 0 ? 0 : require_typed_shared_units.parseOdfLength(heightValue) ?? 0,
|
|
51
|
+
manualBreak: (properties === void 0 ? void 0 : require_xml_query.attrValue(properties, "fo:break-before")) === "page"
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
function readCellText(cellElement, pkg) {
|
|
55
|
+
const paragraphs = require_xml_query.childrenWithTag(cellElement, "text:p");
|
|
56
|
+
const runs = [];
|
|
57
|
+
paragraphs.forEach((paragraph, index) => {
|
|
58
|
+
if (index > 0) runs.push({ text: "\n" });
|
|
59
|
+
runs.push(...require_typed_shared_paragraph.readOdfParagraph(paragraph, pkg).runs);
|
|
60
|
+
});
|
|
61
|
+
return {
|
|
62
|
+
runs,
|
|
63
|
+
displayText: runs.map((run) => run.text).join("")
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
function readCellValue(cellElement, displayText) {
|
|
67
|
+
const valueType = require_xml_query.attrValue(cellElement, "office:value-type");
|
|
68
|
+
const stringFallback = {
|
|
69
|
+
kind: "string",
|
|
70
|
+
value: displayText
|
|
71
|
+
};
|
|
72
|
+
switch (valueType) {
|
|
73
|
+
case "float": {
|
|
74
|
+
const value = parseRequiredNumber(require_xml_query.attrValue(cellElement, "office:value"));
|
|
75
|
+
return value === void 0 ? stringFallback : {
|
|
76
|
+
kind: "number",
|
|
77
|
+
value
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
case "percentage": {
|
|
81
|
+
const value = parseRequiredNumber(require_xml_query.attrValue(cellElement, "office:value"));
|
|
82
|
+
return value === void 0 ? stringFallback : {
|
|
83
|
+
kind: "percentage",
|
|
84
|
+
value
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
case "currency": {
|
|
88
|
+
const value = parseRequiredNumber(require_xml_query.attrValue(cellElement, "office:value"));
|
|
89
|
+
if (value === void 0) return stringFallback;
|
|
90
|
+
const currency = require_xml_query.attrValue(cellElement, "office:currency");
|
|
91
|
+
return currency === void 0 ? {
|
|
92
|
+
kind: "currency",
|
|
93
|
+
value
|
|
94
|
+
} : {
|
|
95
|
+
kind: "currency",
|
|
96
|
+
value,
|
|
97
|
+
currency
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
case "boolean": {
|
|
101
|
+
const raw = require_xml_query.attrValue(cellElement, "office:boolean-value");
|
|
102
|
+
return raw === void 0 ? stringFallback : {
|
|
103
|
+
kind: "boolean",
|
|
104
|
+
value: raw === "true"
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
case "date": return {
|
|
108
|
+
kind: "date",
|
|
109
|
+
value: require_xml_query.attrValue(cellElement, "office:date-value") ?? displayText
|
|
110
|
+
};
|
|
111
|
+
case "time": return {
|
|
112
|
+
kind: "time",
|
|
113
|
+
value: require_xml_query.attrValue(cellElement, "office:time-value") ?? displayText
|
|
114
|
+
};
|
|
115
|
+
case "string": return {
|
|
116
|
+
kind: "string",
|
|
117
|
+
value: require_xml_query.attrValue(cellElement, "office:string-value") ?? displayText
|
|
118
|
+
};
|
|
119
|
+
default: return { kind: "empty" };
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
function parseRequiredNumber(raw) {
|
|
123
|
+
if (raw === void 0) return;
|
|
124
|
+
const value = Number(raw);
|
|
125
|
+
return Number.isNaN(value) ? void 0 : value;
|
|
126
|
+
}
|
|
127
|
+
function parsePrintRanges(value) {
|
|
128
|
+
const first = value.split(" ").find((part) => part.length > 0);
|
|
129
|
+
if (first === void 0) return;
|
|
130
|
+
const separatorIndex = first.indexOf(":");
|
|
131
|
+
if (separatorIndex === -1) return;
|
|
132
|
+
const start = parseA1WithOptionalSheetPrefix(first.slice(0, separatorIndex));
|
|
133
|
+
const end = parseA1WithOptionalSheetPrefix(first.slice(separatorIndex + 1));
|
|
134
|
+
if (start === void 0 || end === void 0) return;
|
|
135
|
+
return {
|
|
136
|
+
startRow: start.row,
|
|
137
|
+
startColumn: start.column,
|
|
138
|
+
endRow: end.row,
|
|
139
|
+
endColumn: end.column
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
function parseA1WithOptionalSheetPrefix(cellPart) {
|
|
143
|
+
const dotIndex = cellPart.lastIndexOf(".");
|
|
144
|
+
const bareReference = dotIndex === -1 ? cellPart : cellPart.slice(dotIndex + 1);
|
|
145
|
+
return require_typed_shared_a1.parseCellReference(bareReference);
|
|
146
|
+
}
|
|
147
|
+
function parseScalePercentage(value) {
|
|
148
|
+
const match = /^(\d+(?:\.\d+)?)%$/.exec(value);
|
|
149
|
+
if (match === null) return;
|
|
150
|
+
const numeric = match[1];
|
|
151
|
+
return numeric === void 0 ? void 0 : Number(numeric);
|
|
152
|
+
}
|
|
153
|
+
function parseNonNegativeInteger(value) {
|
|
154
|
+
if (value === void 0) return;
|
|
155
|
+
const parsed = Number.parseInt(value, 10);
|
|
156
|
+
return Number.isInteger(parsed) && parsed >= 0 ? parsed : void 0;
|
|
157
|
+
}
|
|
158
|
+
function readTable(tableElement, pkg) {
|
|
159
|
+
const columns = [];
|
|
160
|
+
const rows = [];
|
|
161
|
+
const cells = [];
|
|
162
|
+
const manualBreakRows = [];
|
|
163
|
+
const manualBreakColumns = [];
|
|
164
|
+
let repeatColumns;
|
|
165
|
+
let repeatRows;
|
|
166
|
+
let columnCursor = 0;
|
|
167
|
+
const cursor = new require_typed_shared_a1.TableCursor();
|
|
168
|
+
function processColumn(columnElement) {
|
|
169
|
+
const { widthPt, manualBreak } = readColumnLayout(columnElement, pkg);
|
|
170
|
+
columns.push({
|
|
171
|
+
index: columnCursor,
|
|
172
|
+
widthPt,
|
|
173
|
+
hidden: isHidden(columnElement) ? true : void 0
|
|
174
|
+
});
|
|
175
|
+
if (manualBreak) manualBreakColumns.push(columnCursor);
|
|
176
|
+
columnCursor += readRepeatCount(columnElement, "table:number-columns-repeated");
|
|
177
|
+
}
|
|
178
|
+
function processRowCells(rowElement) {
|
|
179
|
+
for (const child of rowElement.children) {
|
|
180
|
+
if (child.type !== "element") continue;
|
|
181
|
+
if (child.tag === "table:covered-table-cell") cursor.nextCell(readRepeatCount(child, "table:number-columns-repeated"));
|
|
182
|
+
else if (child.tag === "table:table-cell") {
|
|
183
|
+
const columnIndex = cursor.columnIndex;
|
|
184
|
+
const rowIndex = cursor.rowIndex;
|
|
185
|
+
cursor.nextCell(readRepeatCount(child, "table:number-columns-repeated"));
|
|
186
|
+
const formula = require_xml_query.attrValue(child, "table:formula");
|
|
187
|
+
const { runs, displayText } = readCellText(child, pkg);
|
|
188
|
+
if (!(require_xml_query.attrValue(child, "office:value-type") !== void 0) && formula === void 0 && displayText.length === 0) continue;
|
|
189
|
+
const value = readCellValue(child, displayText);
|
|
190
|
+
const colSpan = parseNonNegativeInteger(require_xml_query.attrValue(child, "table:number-columns-spanned"));
|
|
191
|
+
const rowSpan = parseNonNegativeInteger(require_xml_query.attrValue(child, "table:number-rows-spanned"));
|
|
192
|
+
const cell = {
|
|
193
|
+
row: rowIndex,
|
|
194
|
+
column: columnIndex,
|
|
195
|
+
value,
|
|
196
|
+
displayText
|
|
197
|
+
};
|
|
198
|
+
if (formula !== void 0) cell.formula = formula;
|
|
199
|
+
if (runs.length > 0) cell.runs = runs;
|
|
200
|
+
if (colSpan !== void 0) cell.colSpan = colSpan;
|
|
201
|
+
if (rowSpan !== void 0) cell.rowSpan = rowSpan;
|
|
202
|
+
cells.push(cell);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
function processRow(rowElement) {
|
|
207
|
+
const startIndex = cursor.rowIndex;
|
|
208
|
+
processRowCells(rowElement);
|
|
209
|
+
const { heightPt, manualBreak } = readRowLayout(rowElement, pkg);
|
|
210
|
+
rows.push({
|
|
211
|
+
index: startIndex,
|
|
212
|
+
heightPt,
|
|
213
|
+
hidden: isHidden(rowElement) ? true : void 0
|
|
214
|
+
});
|
|
215
|
+
if (manualBreak) manualBreakRows.push(startIndex);
|
|
216
|
+
cursor.nextRow(readRepeatCount(rowElement, "table:number-rows-repeated"));
|
|
217
|
+
}
|
|
218
|
+
for (const child of tableElement.children) {
|
|
219
|
+
if (child.type !== "element") continue;
|
|
220
|
+
if (child.tag === "table:table-column") processColumn(child);
|
|
221
|
+
else if (child.tag === "table:table-header-columns") {
|
|
222
|
+
const startIndex = columnCursor;
|
|
223
|
+
for (const headerChild of child.children) if (headerChild.type === "element" && headerChild.tag === "table:table-column") processColumn(headerChild);
|
|
224
|
+
if (columnCursor > startIndex) repeatColumns = {
|
|
225
|
+
start: startIndex,
|
|
226
|
+
end: columnCursor - 1
|
|
227
|
+
};
|
|
228
|
+
} else if (child.tag === "table:table-row") processRow(child);
|
|
229
|
+
else if (child.tag === "table:table-header-rows") {
|
|
230
|
+
const startIndex = cursor.rowIndex;
|
|
231
|
+
for (const headerChild of child.children) if (headerChild.type === "element" && headerChild.tag === "table:table-row") processRow(headerChild);
|
|
232
|
+
if (cursor.rowIndex > startIndex) repeatRows = {
|
|
233
|
+
start: startIndex,
|
|
234
|
+
end: cursor.rowIndex - 1
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
return {
|
|
239
|
+
columns,
|
|
240
|
+
rows,
|
|
241
|
+
cells,
|
|
242
|
+
repeatColumns,
|
|
243
|
+
repeatRows,
|
|
244
|
+
manualBreakRows,
|
|
245
|
+
manualBreakColumns
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
function readPrintSettings(tableElement, pkg, repeatColumns, repeatRows, manualBreakRows, manualBreakColumns) {
|
|
249
|
+
const tableStyleName = require_xml_query.attrValue(tableElement, "table:style-name");
|
|
250
|
+
const tableStyleElement = tableStyleName === void 0 ? void 0 : require_typed_shared_cascade.findStyleElement(tableStyleName, "table", pkg);
|
|
251
|
+
const masterPageName = tableStyleElement === void 0 ? void 0 : require_xml_query.attrValue(tableStyleElement, "style:master-page-name");
|
|
252
|
+
const layoutProperties = require_typed_shared_masterpage.resolvePageLayoutProperties(pkg, masterPageName);
|
|
253
|
+
const pageSize = layoutProperties === void 0 ? void 0 : require_typed_shared_geometry.parsePageSize(layoutProperties);
|
|
254
|
+
const margins = layoutProperties === void 0 ? void 0 : require_typed_shared_geometry.parseMargins(layoutProperties);
|
|
255
|
+
const printTokens = new Set((layoutProperties === void 0 ? void 0 : require_xml_query.attrValue(layoutProperties, "style:print"))?.split(" ").filter((token) => token.length > 0));
|
|
256
|
+
const pageOrder = (layoutProperties === void 0 ? void 0 : require_xml_query.attrValue(layoutProperties, "style:print-page-order")) === "ltr" ? "overThenDown" : "downThenOver";
|
|
257
|
+
const scaleToRaw = layoutProperties === void 0 ? void 0 : require_xml_query.attrValue(layoutProperties, "style:scale-to");
|
|
258
|
+
const scale = scaleToRaw === void 0 ? void 0 : parseScalePercentage(scaleToRaw);
|
|
259
|
+
const scaleToXRaw = layoutProperties === void 0 ? void 0 : require_xml_query.attrValue(layoutProperties, "style:scale-to-X");
|
|
260
|
+
const scaleToYRaw = layoutProperties === void 0 ? void 0 : require_xml_query.attrValue(layoutProperties, "style:scale-to-Y");
|
|
261
|
+
const fitWidth = parseNonNegativeInteger(scaleToXRaw);
|
|
262
|
+
const fitHeight = parseNonNegativeInteger(scaleToYRaw);
|
|
263
|
+
const fitToPages = fitWidth === void 0 || fitHeight === void 0 ? void 0 : {
|
|
264
|
+
width: fitWidth,
|
|
265
|
+
height: fitHeight
|
|
266
|
+
};
|
|
267
|
+
const printRangesRaw = require_xml_query.attrValue(tableElement, "table:print-ranges");
|
|
268
|
+
const printRange = printRangesRaw === void 0 ? void 0 : parsePrintRanges(printRangesRaw);
|
|
269
|
+
const manualBreaks = manualBreakRows.length > 0 || manualBreakColumns.length > 0 ? {
|
|
270
|
+
rows: manualBreakRows,
|
|
271
|
+
columns: manualBreakColumns
|
|
272
|
+
} : void 0;
|
|
273
|
+
const settings = {
|
|
274
|
+
pageSize: pageSize ?? document_schema_js.PAGE_SIZE_A4,
|
|
275
|
+
margins: margins ?? DEFAULT_MARGINS,
|
|
276
|
+
gridlines: printTokens.has("grid"),
|
|
277
|
+
headers: printTokens.has("headers"),
|
|
278
|
+
pageOrder
|
|
279
|
+
};
|
|
280
|
+
if (printRange !== void 0) settings.printRange = printRange;
|
|
281
|
+
if (scale !== void 0) settings.scale = scale;
|
|
282
|
+
if (fitToPages !== void 0) settings.fitToPages = fitToPages;
|
|
283
|
+
if (repeatRows !== void 0) settings.repeatRows = repeatRows;
|
|
284
|
+
if (repeatColumns !== void 0) settings.repeatColumns = repeatColumns;
|
|
285
|
+
if (manualBreaks !== void 0) settings.manualBreaks = manualBreaks;
|
|
286
|
+
return settings;
|
|
287
|
+
}
|
|
288
|
+
function readSheet(tableElement, pkg) {
|
|
289
|
+
const name = require_xml_query.attrValue(tableElement, "table:name");
|
|
290
|
+
if (name === void 0) return;
|
|
291
|
+
const { columns, rows, cells, repeatColumns, repeatRows, manualBreakRows, manualBreakColumns } = readTable(tableElement, pkg);
|
|
292
|
+
return {
|
|
293
|
+
name,
|
|
294
|
+
cells,
|
|
295
|
+
columns,
|
|
296
|
+
rows,
|
|
297
|
+
images: [],
|
|
298
|
+
printSettings: readPrintSettings(tableElement, pkg, repeatColumns, repeatRows, manualBreakRows, manualBreakColumns)
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
function readOds(pkg) {
|
|
302
|
+
const contentPart = pkg.parts[CONTENT_PART];
|
|
303
|
+
const root = contentPart?.kind === "xml" ? require_xml_query.rootElement(contentPart.nodes) : void 0;
|
|
304
|
+
const body = root === void 0 ? void 0 : require_xml_query.findChildElement(root.children, "office:body");
|
|
305
|
+
const spreadsheet = body === void 0 ? void 0 : require_xml_query.findChildElement(body.children, "office:spreadsheet");
|
|
306
|
+
const tables = spreadsheet === void 0 ? [] : require_xml_query.childrenWithTag(spreadsheet, "table:table");
|
|
307
|
+
const sheets = [];
|
|
308
|
+
for (const table of tables) {
|
|
309
|
+
const sheet = readSheet(table, pkg);
|
|
310
|
+
if (sheet !== void 0) sheets.push(sheet);
|
|
311
|
+
}
|
|
312
|
+
return {
|
|
313
|
+
metadata: require_typed_shared_metadata.readOdfMetadata(pkg),
|
|
314
|
+
sheets
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
//#endregion
|
|
318
|
+
exports.readOds = readOds;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Package } from "../../model/package.cjs";
|
|
2
|
+
import { ContentSheet, LayoutMetadata } from "document-schema.js";
|
|
3
|
+
//#region src/typed/ods/read.d.ts
|
|
4
|
+
interface OdsDocument {
|
|
5
|
+
metadata: LayoutMetadata;
|
|
6
|
+
sheets: ContentSheet[];
|
|
7
|
+
}
|
|
8
|
+
declare function readOds(pkg: Package): OdsDocument;
|
|
9
|
+
//#endregion
|
|
10
|
+
export { OdsDocument, readOds };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Package } from "../../model/package.js";
|
|
2
|
+
import { ContentSheet, LayoutMetadata } from "document-schema.js";
|
|
3
|
+
//#region src/typed/ods/read.d.ts
|
|
4
|
+
interface OdsDocument {
|
|
5
|
+
metadata: LayoutMetadata;
|
|
6
|
+
sheets: ContentSheet[];
|
|
7
|
+
}
|
|
8
|
+
declare function readOds(pkg: Package): OdsDocument;
|
|
9
|
+
//#endregion
|
|
10
|
+
export { OdsDocument, readOds };
|