odf.js 1.5.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 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
  }
@@ -1495,6 +1514,28 @@ function parseBox(element) {
1495
1514
  heightPt
1496
1515
  };
1497
1516
  }
1517
+ function parseLinePoints(element) {
1518
+ const x1Value = attrValue(element, "svg:x1");
1519
+ const y1Value = attrValue(element, "svg:y1");
1520
+ const x2Value = attrValue(element, "svg:x2");
1521
+ const y2Value = attrValue(element, "svg:y2");
1522
+ if (x1Value === void 0 || y1Value === void 0 || x2Value === void 0 || y2Value === void 0) return;
1523
+ const x1Pt = parseOdfLength(x1Value);
1524
+ const y1Pt = parseOdfLength(y1Value);
1525
+ const x2Pt = parseOdfLength(x2Value);
1526
+ const y2Pt = parseOdfLength(y2Value);
1527
+ if (x1Pt === void 0 || y1Pt === void 0 || x2Pt === void 0 || y2Pt === void 0) return;
1528
+ return {
1529
+ from: {
1530
+ xPt: x1Pt,
1531
+ yPt: y1Pt
1532
+ },
1533
+ to: {
1534
+ xPt: x2Pt,
1535
+ yPt: y2Pt
1536
+ }
1537
+ };
1538
+ }
1498
1539
  //#endregion
1499
1540
  //#region src/typed/shared/cascade.ts
1500
1541
  const STYLE_PARTS = ["content.xml", "styles.xml"];
@@ -1680,7 +1721,7 @@ function readOdfParagraph(pElement, pkg) {
1680
1721
  }
1681
1722
  //#endregion
1682
1723
  //#region src/typed/shared/table.ts
1683
- function readRepeatCount(element, attrName) {
1724
+ function readRepeatCount$1(element, attrName) {
1684
1725
  const raw = attrValue(element, attrName);
1685
1726
  if (raw === void 0) return 1;
1686
1727
  const parsed = Number.parseInt(raw, 10);
@@ -1723,11 +1764,11 @@ function readTableRow(rowElement, pkg) {
1723
1764
  for (const child of rowElement.children) {
1724
1765
  if (child.type !== "element") continue;
1725
1766
  if (child.tag === "table:covered-table-cell") {
1726
- const repeat = readRepeatCount(child, "table:number-columns-repeated");
1767
+ const repeat = readRepeatCount$1(child, "table:number-columns-repeated");
1727
1768
  for (let i = 0; i < repeat; i++) cells.push({ blocks: [] });
1728
1769
  } else if (child.tag === "table:table-cell") {
1729
1770
  const cell = readTableCell(child, pkg);
1730
- const repeat = readRepeatCount(child, "table:number-columns-repeated");
1771
+ const repeat = readRepeatCount$1(child, "table:number-columns-repeated");
1731
1772
  for (let i = 0; i < repeat; i++) cells.push(cell);
1732
1773
  }
1733
1774
  }
@@ -1740,13 +1781,13 @@ function readOdfTable(tableElement, pkg) {
1740
1781
  const columnWidthsPt = [];
1741
1782
  for (const column of childrenWithTag(tableElement, "table:table-column")) {
1742
1783
  const widthPt = resolveColumnWidthPt(column, pkg);
1743
- const repeat = readRepeatCount(column, "table:number-columns-repeated");
1784
+ const repeat = readRepeatCount$1(column, "table:number-columns-repeated");
1744
1785
  for (let i = 0; i < repeat; i++) columnWidthsPt.push(widthPt);
1745
1786
  }
1746
1787
  const rows = [];
1747
1788
  for (const rowElement of childrenWithTag(tableElement, "table:table-row")) {
1748
1789
  const row = readTableRow(rowElement, pkg);
1749
- const repeat = readRepeatCount(rowElement, "table:number-rows-repeated");
1790
+ const repeat = readRepeatCount$1(rowElement, "table:number-rows-repeated");
1750
1791
  for (let i = 0; i < repeat; i++) rows.push(row);
1751
1792
  }
1752
1793
  return {
@@ -1859,6 +1900,294 @@ function composeOdfGroupTransform(groupFunctions, child) {
1859
1900
  };
1860
1901
  }
1861
1902
  //#endregion
1903
+ //#region src/typed/shared/masterpage.ts
1904
+ const STYLES_PART$1 = "styles.xml";
1905
+ const AUTOMATIC_STYLE_PARTS$1 = ["content.xml", STYLES_PART$1];
1906
+ function findMasterPageElement(pkg, masterPageName) {
1907
+ if (masterPageName === void 0) return;
1908
+ const stylesPart = pkg.parts[STYLES_PART$1];
1909
+ if (stylesPart?.kind !== "xml") return;
1910
+ const root = rootElement(stylesPart.nodes);
1911
+ const masterStyles = root === void 0 ? void 0 : findChildElement(root.children, "office:master-styles");
1912
+ if (masterStyles === void 0) return;
1913
+ return childrenWithTag(masterStyles, "style:master-page").find((element) => attrValue(element, "style:name") === masterPageName);
1914
+ }
1915
+ function findPageLayoutElement$1(pkg, pageLayoutName) {
1916
+ if (pageLayoutName === void 0) return;
1917
+ for (const partPath of AUTOMATIC_STYLE_PARTS$1) {
1918
+ const part = pkg.parts[partPath];
1919
+ if (part?.kind !== "xml") continue;
1920
+ const root = rootElement(part.nodes);
1921
+ const automaticStyles = root === void 0 ? void 0 : findChildElement(root.children, "office:automatic-styles");
1922
+ if (automaticStyles === void 0) continue;
1923
+ const found = childrenWithTag(automaticStyles, "style:page-layout").find((element) => attrValue(element, "style:name") === pageLayoutName);
1924
+ if (found !== void 0) return found;
1925
+ }
1926
+ }
1927
+ function resolvePageLayoutProperties(pkg, masterPageName) {
1928
+ const masterPage = findMasterPageElement(pkg, masterPageName);
1929
+ const pageLayout = findPageLayoutElement$1(pkg, masterPage === void 0 ? void 0 : attrValue(masterPage, "style:page-layout-name"));
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"));
1934
+ return properties === void 0 ? void 0 : parsePageSize(properties);
1935
+ }
1936
+ //#endregion
1937
+ //#region src/typed/shared/path.ts
1938
+ const VIEW_BOX_PATTERN = /^(-?\d+(?:\.\d+)?)\s+(-?\d+(?:\.\d+)?)\s+(-?\d+(?:\.\d+)?)\s+(-?\d+(?:\.\d+)?)$/;
1939
+ function parseOdfViewBox(value) {
1940
+ const match = VIEW_BOX_PATTERN.exec(value.trim());
1941
+ if (match === null) return;
1942
+ const minX = Number(match[1]);
1943
+ const minY = Number(match[2]);
1944
+ const width = Number(match[3]);
1945
+ const height = Number(match[4]);
1946
+ if (width <= 0 || height <= 0) return;
1947
+ return {
1948
+ minX,
1949
+ minY,
1950
+ width,
1951
+ height
1952
+ };
1953
+ }
1954
+ function parseOdfPointsList(value) {
1955
+ const points = [];
1956
+ for (const pair of value.trim().split(/\s+/)) {
1957
+ if (pair.length === 0) continue;
1958
+ const [xRaw, yRaw] = pair.split(",");
1959
+ if (xRaw === void 0 || yRaw === void 0) continue;
1960
+ const x = Number(xRaw);
1961
+ const y = Number(yRaw);
1962
+ if (!Number.isFinite(x) || !Number.isFinite(y)) continue;
1963
+ points.push({
1964
+ x,
1965
+ y
1966
+ });
1967
+ }
1968
+ return points;
1969
+ }
1970
+ function rawSubpathFromPoints(points, closed) {
1971
+ const start = points[0];
1972
+ if (start === void 0) return;
1973
+ return {
1974
+ start,
1975
+ segments: points.slice(1).map((to) => ({
1976
+ kind: "line",
1977
+ to
1978
+ })),
1979
+ closed
1980
+ };
1981
+ }
1982
+ const COMMAND_LETTERS = /* @__PURE__ */ new Set([
1983
+ "M",
1984
+ "m",
1985
+ "L",
1986
+ "l",
1987
+ "H",
1988
+ "h",
1989
+ "V",
1990
+ "v",
1991
+ "C",
1992
+ "c",
1993
+ "S",
1994
+ "s",
1995
+ "Q",
1996
+ "q",
1997
+ "T",
1998
+ "t",
1999
+ "A",
2000
+ "a",
2001
+ "Z",
2002
+ "z"
2003
+ ]);
2004
+ function isCommandLetter(token) {
2005
+ return COMMAND_LETTERS.has(token);
2006
+ }
2007
+ const PATH_TOKEN_PATTERN = /[MmLlHhVvCcSsQqTtAaZz]|-?(?:\d+\.\d+|\.\d+|\d+)(?:[eE][-+]?\d+)?/g;
2008
+ function tokenizePathData(d) {
2009
+ return d.match(PATH_TOKEN_PATTERN) ?? [];
2010
+ }
2011
+ function parseOdfPathData(d) {
2012
+ const tokens = tokenizePathData(d);
2013
+ const subpaths = [];
2014
+ let current = {
2015
+ x: 0,
2016
+ y: 0
2017
+ };
2018
+ let subpathStart = {
2019
+ x: 0,
2020
+ y: 0
2021
+ };
2022
+ let activeSubpath;
2023
+ let command;
2024
+ let firstMInCommand = true;
2025
+ function startSubpath(point) {
2026
+ activeSubpath = {
2027
+ start: point,
2028
+ segments: [],
2029
+ closed: false
2030
+ };
2031
+ subpaths.push(activeSubpath);
2032
+ subpathStart = point;
2033
+ current = point;
2034
+ }
2035
+ function pushSegment(segment, to) {
2036
+ if (activeSubpath !== void 0) activeSubpath.segments.push(segment);
2037
+ current = to;
2038
+ }
2039
+ let i = 0;
2040
+ while (i < tokens.length) {
2041
+ const token = tokens[i];
2042
+ if (token === void 0) break;
2043
+ if (isCommandLetter(token)) {
2044
+ if (token === "Z" || token === "z") {
2045
+ if (activeSubpath !== void 0) {
2046
+ activeSubpath.closed = true;
2047
+ current = subpathStart;
2048
+ }
2049
+ command = void 0;
2050
+ i += 1;
2051
+ continue;
2052
+ }
2053
+ command = token;
2054
+ firstMInCommand = true;
2055
+ i += 1;
2056
+ continue;
2057
+ }
2058
+ if (command === void 0) {
2059
+ i += 1;
2060
+ continue;
2061
+ }
2062
+ const upper = command.toUpperCase();
2063
+ const relative = command !== upper;
2064
+ if (upper === "M" || upper === "L") {
2065
+ const xTok = tokens[i];
2066
+ const yTok = tokens[i + 1];
2067
+ i += 2;
2068
+ if (xTok === void 0 || yTok === void 0) break;
2069
+ const x = Number(xTok);
2070
+ const y = Number(yTok);
2071
+ if (!Number.isFinite(x) || !Number.isFinite(y)) continue;
2072
+ const point = relative ? {
2073
+ x: current.x + x,
2074
+ y: current.y + y
2075
+ } : {
2076
+ x,
2077
+ y
2078
+ };
2079
+ if (upper === "M" && firstMInCommand) {
2080
+ startSubpath(point);
2081
+ firstMInCommand = false;
2082
+ } else pushSegment({
2083
+ kind: "line",
2084
+ to: point
2085
+ }, point);
2086
+ } else if (upper === "H") {
2087
+ const xTok = tokens[i];
2088
+ i += 1;
2089
+ if (xTok === void 0) break;
2090
+ const x = Number(xTok);
2091
+ if (!Number.isFinite(x)) continue;
2092
+ const point = relative ? {
2093
+ x: current.x + x,
2094
+ y: current.y
2095
+ } : {
2096
+ x,
2097
+ y: current.y
2098
+ };
2099
+ pushSegment({
2100
+ kind: "line",
2101
+ to: point
2102
+ }, point);
2103
+ } else if (upper === "V") {
2104
+ const yTok = tokens[i];
2105
+ i += 1;
2106
+ if (yTok === void 0) break;
2107
+ const y = Number(yTok);
2108
+ if (!Number.isFinite(y)) continue;
2109
+ const point = relative ? {
2110
+ x: current.x,
2111
+ y: current.y + y
2112
+ } : {
2113
+ x: current.x,
2114
+ y
2115
+ };
2116
+ pushSegment({
2117
+ kind: "line",
2118
+ to: point
2119
+ }, point);
2120
+ } else if (upper === "C") {
2121
+ const rawArgs = tokens.slice(i, i + 6);
2122
+ i += 6;
2123
+ if (rawArgs.length < 6) break;
2124
+ const x1 = Number(rawArgs[0]);
2125
+ const y1 = Number(rawArgs[1]);
2126
+ const x2 = Number(rawArgs[2]);
2127
+ const y2 = Number(rawArgs[3]);
2128
+ const x = Number(rawArgs[4]);
2129
+ const y = Number(rawArgs[5]);
2130
+ if (![
2131
+ x1,
2132
+ y1,
2133
+ x2,
2134
+ y2,
2135
+ x,
2136
+ y
2137
+ ].every(Number.isFinite)) continue;
2138
+ const control1 = relative ? {
2139
+ x: current.x + x1,
2140
+ y: current.y + y1
2141
+ } : {
2142
+ x: x1,
2143
+ y: y1
2144
+ };
2145
+ const control2 = relative ? {
2146
+ x: current.x + x2,
2147
+ y: current.y + y2
2148
+ } : {
2149
+ x: x2,
2150
+ y: y2
2151
+ };
2152
+ const to = relative ? {
2153
+ x: current.x + x,
2154
+ y: current.y + y
2155
+ } : {
2156
+ x,
2157
+ y
2158
+ };
2159
+ pushSegment({
2160
+ kind: "cubic",
2161
+ control1,
2162
+ control2,
2163
+ to
2164
+ }, to);
2165
+ } else i += 1;
2166
+ }
2167
+ return subpaths;
2168
+ }
2169
+ function scaleOdfRawPoint(point, viewBox, frame) {
2170
+ return {
2171
+ xPt: (point.x - viewBox.minX) * (frame.widthPt / viewBox.width),
2172
+ yPt: (point.y - viewBox.minY) * (frame.heightPt / viewBox.height)
2173
+ };
2174
+ }
2175
+ function buildOdfSubpaths(rawSubpaths, viewBox, frame) {
2176
+ return rawSubpaths.map((raw) => ({
2177
+ start: scaleOdfRawPoint(raw.start, viewBox, frame),
2178
+ closed: raw.closed,
2179
+ segments: raw.segments.map((segment) => segment.kind === "line" ? {
2180
+ kind: "line",
2181
+ to: scaleOdfRawPoint(segment.to, viewBox, frame)
2182
+ } : {
2183
+ kind: "cubic",
2184
+ control1: scaleOdfRawPoint(segment.control1, viewBox, frame),
2185
+ control2: scaleOdfRawPoint(segment.control2, viewBox, frame),
2186
+ to: scaleOdfRawPoint(segment.to, viewBox, frame)
2187
+ })
2188
+ }));
2189
+ }
2190
+ //#endregion
1862
2191
  //#region src/typed/draw/shapes.ts
1863
2192
  const ZERO_INSETS = {
1864
2193
  insetLeftPt: 0,
@@ -1940,37 +2269,224 @@ function walkDrawShapes(children, groupFunctions, pkg, out) {
1940
2269
  }
1941
2270
  }
1942
2271
  }
1943
- //#endregion
1944
- //#region src/typed/odp/read.ts
1945
- const CONTENT_PART$1 = "content.xml";
1946
- const STYLES_PART$1 = "styles.xml";
1947
- const AUTOMATIC_STYLE_PARTS$1 = [CONTENT_PART$1, STYLES_PART$1];
1948
- function findMasterPageElement(pkg, masterPageName) {
1949
- if (masterPageName === void 0) return;
1950
- const stylesPart = pkg.parts[STYLES_PART$1];
1951
- if (stylesPart?.kind !== "xml") return;
1952
- const root = rootElement(stylesPart.nodes);
1953
- const masterStyles = root === void 0 ? void 0 : findChildElement(root.children, "office:master-styles");
1954
- if (masterStyles === void 0) return;
1955
- return childrenWithTag(masterStyles, "style:master-page").find((element) => attrValue(element, "style:name") === masterPageName);
2272
+ function readOdfFillAndStroke(element, pkg) {
2273
+ const { elements } = resolveStyleElementChain(attrValue(element, "draw:style-name"), "graphic", pkg);
2274
+ let fill;
2275
+ let stroke;
2276
+ for (const styleElement of elements) {
2277
+ const props = childrenWithTag(styleElement, "style:graphic-properties")[0];
2278
+ if (props === void 0) continue;
2279
+ if (attrValue(props, "draw:fill") === "none") fill = void 0;
2280
+ else {
2281
+ const fillColorValue = attrValue(props, "draw:fill-color");
2282
+ const parsedFill = fillColorValue === void 0 ? void 0 : parseOdfColor(fillColorValue);
2283
+ if (parsedFill !== void 0) fill = parsedFill;
2284
+ }
2285
+ if (attrValue(props, "draw:stroke") === "none") stroke = void 0;
2286
+ else {
2287
+ const strokeColorValue = attrValue(props, "svg:stroke-color");
2288
+ const strokeWidthValue = attrValue(props, "svg:stroke-width");
2289
+ const strokeColor = strokeColorValue === void 0 ? void 0 : parseOdfColor(strokeColorValue);
2290
+ const strokeWidthPt = strokeWidthValue === void 0 ? void 0 : parseOdfLength(strokeWidthValue);
2291
+ if (strokeColor !== void 0 && strokeWidthPt !== void 0 && strokeWidthPt > 0) stroke = {
2292
+ color: strokeColor,
2293
+ widthPt: strokeWidthPt
2294
+ };
2295
+ }
2296
+ }
2297
+ return {
2298
+ fill,
2299
+ stroke
2300
+ };
1956
2301
  }
1957
- function findPageLayoutElement$1(pkg, pageLayoutName) {
1958
- if (pageLayoutName === void 0) return;
1959
- for (const partPath of AUTOMATIC_STYLE_PARTS$1) {
1960
- const part = pkg.parts[partPath];
1961
- if (part?.kind !== "xml") continue;
1962
- const root = rootElement(part.nodes);
1963
- const automaticStyles = root === void 0 ? void 0 : findChildElement(root.children, "office:automatic-styles");
1964
- if (automaticStyles === void 0) continue;
1965
- const found = childrenWithTag(automaticStyles, "style:page-layout").find((element) => attrValue(element, "style:name") === pageLayoutName);
1966
- if (found !== void 0) return found;
2302
+ function resolveVectorFrame(element, groupFunctions) {
2303
+ const geometry = resolveOdfShapeGeometry(element);
2304
+ if (geometry === void 0) return;
2305
+ return composeOdfGroupTransform(groupFunctions, geometry).frame;
2306
+ }
2307
+ function readDrawRectVector(element, groupFunctions, pkg) {
2308
+ const frame = resolveVectorFrame(element, groupFunctions);
2309
+ if (frame === void 0) return;
2310
+ const { fill, stroke } = readOdfFillAndStroke(element, pkg);
2311
+ return {
2312
+ kind: "rect",
2313
+ frame,
2314
+ fill,
2315
+ stroke
2316
+ };
2317
+ }
2318
+ function readDrawEllipseVector(element, groupFunctions, pkg) {
2319
+ const frame = resolveVectorFrame(element, groupFunctions);
2320
+ if (frame === void 0) return;
2321
+ const { fill, stroke } = readOdfFillAndStroke(element, pkg);
2322
+ return {
2323
+ kind: "ellipse",
2324
+ frame,
2325
+ fill,
2326
+ stroke
2327
+ };
2328
+ }
2329
+ function readDrawLineVector(element, groupFunctions, pkg) {
2330
+ const raw = parseLinePoints(element);
2331
+ if (raw === void 0) return;
2332
+ const from = groupFunctions.length === 0 ? raw.from : applyOdfTransform(groupFunctions, raw.from);
2333
+ const to = groupFunctions.length === 0 ? raw.to : applyOdfTransform(groupFunctions, raw.to);
2334
+ const { stroke } = readOdfFillAndStroke(element, pkg);
2335
+ if (stroke === void 0) return;
2336
+ return {
2337
+ kind: "line",
2338
+ from,
2339
+ to,
2340
+ stroke
2341
+ };
2342
+ }
2343
+ function readDrawPathVector(element, groupFunctions, pkg) {
2344
+ const frame = resolveVectorFrame(element, groupFunctions);
2345
+ if (frame === void 0) return;
2346
+ const viewBoxValue = attrValue(element, "svg:viewBox");
2347
+ const viewBox = viewBoxValue === void 0 ? void 0 : parseOdfViewBox(viewBoxValue);
2348
+ if (viewBox === void 0) return;
2349
+ let rawSubpaths;
2350
+ if (element.tag === "draw:path") {
2351
+ const d = attrValue(element, "svg:d");
2352
+ rawSubpaths = d === void 0 ? [] : parseOdfPathData(d);
2353
+ } else {
2354
+ const pointsValue = attrValue(element, "draw:points");
2355
+ const subpath = rawSubpathFromPoints(pointsValue === void 0 ? [] : parseOdfPointsList(pointsValue), element.tag === "draw:polygon");
2356
+ rawSubpaths = subpath === void 0 ? [] : [subpath];
2357
+ }
2358
+ if (rawSubpaths.length === 0) return;
2359
+ const subpaths = buildOdfSubpaths(rawSubpaths, viewBox, frame);
2360
+ const { fill, stroke } = readOdfFillAndStroke(element, pkg);
2361
+ return {
2362
+ kind: "path",
2363
+ frame,
2364
+ subpaths,
2365
+ fill,
2366
+ stroke
2367
+ };
2368
+ }
2369
+ const RECOGNIZED_CUSTOM_SHAPE_PRESETS = /* @__PURE__ */ new Set([
2370
+ "rectangle",
2371
+ "round-rectangle",
2372
+ "ellipse"
2373
+ ]);
2374
+ function readCustomShapeVector(element, groupFunctions, pkg) {
2375
+ const geometryElement = childrenWithTag(element, "draw:enhanced-geometry")[0];
2376
+ const type = geometryElement === void 0 ? void 0 : attrValue(geometryElement, "draw:type");
2377
+ if (type === void 0 || !RECOGNIZED_CUSTOM_SHAPE_PRESETS.has(type)) return;
2378
+ const frame = resolveVectorFrame(element, groupFunctions);
2379
+ if (frame === void 0) return;
2380
+ const { fill, stroke } = readOdfFillAndStroke(element, pkg);
2381
+ return {
2382
+ kind: type === "ellipse" ? "ellipse" : "rect",
2383
+ frame,
2384
+ fill,
2385
+ stroke
2386
+ };
2387
+ }
2388
+ function readCustomShapeAsTextShape(element, groupFunctions, pkg) {
2389
+ const paragraphs = elementsWithTag(element.children, "text:p").map((p) => readOdfParagraph(p, pkg));
2390
+ if (!paragraphs.some((paragraph) => paragraph.runs.some((run) => run.text.length > 0))) return;
2391
+ const ownGeometry = resolveOdfShapeGeometry(element);
2392
+ if (ownGeometry === void 0) return;
2393
+ const geometry = composeOdfGroupTransform(groupFunctions, ownGeometry);
2394
+ return {
2395
+ name: attrValue(element, "draw:name"),
2396
+ frame: geometry.frame,
2397
+ rotationDeg: geometry.rotationDeg,
2398
+ ...readFrameInsets(element, pkg),
2399
+ blocks: paragraphs
2400
+ };
2401
+ }
2402
+ function nextDocumentIndex(state) {
2403
+ const value = state.next;
2404
+ state.next += 1;
2405
+ return value;
2406
+ }
2407
+ function paintOrderKey(element, state) {
2408
+ const documentIndex = nextDocumentIndex(state);
2409
+ const raw = attrValue(element, "draw:z-index");
2410
+ if (raw === void 0) return documentIndex;
2411
+ const parsed = Number.parseInt(raw, 10);
2412
+ return Number.isInteger(parsed) && parsed >= 0 ? parsed : documentIndex;
2413
+ }
2414
+ function byPaintOrder(items) {
2415
+ return items.slice().sort((a, b) => a.zIndex - b.zIndex).map((item) => item.value);
2416
+ }
2417
+ function walkDrawPageContent(children, groupFunctions, pkg, indexState, shapesOut, vectorsOut) {
2418
+ for (const node of children) {
2419
+ if (node.type !== "element") continue;
2420
+ if (node.tag === "draw:frame") {
2421
+ const zIndex = paintOrderKey(node, indexState);
2422
+ const shape = readDrawFrame(node, groupFunctions, pkg);
2423
+ if (shape !== void 0) shapesOut.push({
2424
+ value: shape,
2425
+ zIndex
2426
+ });
2427
+ } else if (node.tag === "draw:g") {
2428
+ const ownFunctions = readOwnTransformFunctions(node);
2429
+ const nested = ownFunctions.length === 0 ? groupFunctions : [...ownFunctions, ...groupFunctions];
2430
+ walkDrawPageContent(node.children, nested, pkg, indexState, shapesOut, vectorsOut);
2431
+ } else if (node.tag === "draw:rect") {
2432
+ const zIndex = paintOrderKey(node, indexState);
2433
+ const vector = readDrawRectVector(node, groupFunctions, pkg);
2434
+ if (vector !== void 0) vectorsOut.push({
2435
+ value: vector,
2436
+ zIndex
2437
+ });
2438
+ } else if (node.tag === "draw:ellipse" || node.tag === "draw:circle") {
2439
+ const zIndex = paintOrderKey(node, indexState);
2440
+ const vector = readDrawEllipseVector(node, groupFunctions, pkg);
2441
+ if (vector !== void 0) vectorsOut.push({
2442
+ value: vector,
2443
+ zIndex
2444
+ });
2445
+ } else if (node.tag === "draw:line") {
2446
+ const zIndex = paintOrderKey(node, indexState);
2447
+ const vector = readDrawLineVector(node, groupFunctions, pkg);
2448
+ if (vector !== void 0) vectorsOut.push({
2449
+ value: vector,
2450
+ zIndex
2451
+ });
2452
+ } else if (node.tag === "draw:path" || node.tag === "draw:polygon" || node.tag === "draw:polyline") {
2453
+ const zIndex = paintOrderKey(node, indexState);
2454
+ const vector = readDrawPathVector(node, groupFunctions, pkg);
2455
+ if (vector !== void 0) vectorsOut.push({
2456
+ value: vector,
2457
+ zIndex
2458
+ });
2459
+ } else if (node.tag === "draw:custom-shape") {
2460
+ const zIndex = paintOrderKey(node, indexState);
2461
+ const vector = readCustomShapeVector(node, groupFunctions, pkg);
2462
+ if (vector !== void 0) vectorsOut.push({
2463
+ value: vector,
2464
+ zIndex
2465
+ });
2466
+ else {
2467
+ const shape = readCustomShapeAsTextShape(node, groupFunctions, pkg);
2468
+ if (shape !== void 0) shapesOut.push({
2469
+ value: shape,
2470
+ zIndex
2471
+ });
2472
+ }
2473
+ }
1967
2474
  }
1968
2475
  }
2476
+ function readDrawPageContent(children, pkg) {
2477
+ const shapesOut = [];
2478
+ const vectorsOut = [];
2479
+ walkDrawPageContent(children, [], pkg, { next: 0 }, shapesOut, vectorsOut);
2480
+ return {
2481
+ shapes: byPaintOrder(shapesOut),
2482
+ vectors: byPaintOrder(vectorsOut)
2483
+ };
2484
+ }
2485
+ //#endregion
2486
+ //#region src/typed/odp/read.ts
2487
+ const CONTENT_PART$3 = "content.xml";
1969
2488
  function readSlideSize(page, pkg) {
1970
- const masterPage = findMasterPageElement(pkg, attrValue(page, "draw:master-page-name"));
1971
- const pageLayout = findPageLayoutElement$1(pkg, masterPage === void 0 ? void 0 : attrValue(masterPage, "style:page-layout-name"));
1972
- const properties = pageLayout === void 0 ? void 0 : childrenWithTag(pageLayout, "style:page-layout-properties")[0];
1973
- return (properties === void 0 ? void 0 : parsePageSize(properties)) ?? document_content_model.SLIDE_SIZE_WIDESCREEN;
2489
+ return resolveDrawPageSize(page, pkg) ?? document_content_model.SLIDE_SIZE_WIDESCREEN;
1974
2490
  }
1975
2491
  function readSlideNotes(page) {
1976
2492
  const notes = childrenWithTag(page, "presentation:notes")[0];
@@ -1987,7 +2503,7 @@ function readSlide(page, pkg) {
1987
2503
  };
1988
2504
  }
1989
2505
  function readOdp(pkg) {
1990
- const contentPart = pkg.parts[CONTENT_PART$1];
2506
+ const contentPart = pkg.parts[CONTENT_PART$3];
1991
2507
  const root = contentPart?.kind === "xml" ? rootElement(contentPart.nodes) : void 0;
1992
2508
  const body = root === void 0 ? void 0 : findChildElement(root.children, "office:body");
1993
2509
  const presentation = body === void 0 ? void 0 : findChildElement(body.children, "office:presentation");
@@ -1999,9 +2515,9 @@ function readOdp(pkg) {
1999
2515
  }
2000
2516
  //#endregion
2001
2517
  //#region src/typed/odt/read.ts
2002
- const CONTENT_PART = "content.xml";
2518
+ const CONTENT_PART$2 = "content.xml";
2003
2519
  const STYLES_PART = "styles.xml";
2004
- const AUTOMATIC_STYLE_PARTS = [CONTENT_PART, STYLES_PART];
2520
+ const AUTOMATIC_STYLE_PARTS = [CONTENT_PART$2, STYLES_PART];
2005
2521
  function readOutlineLevel(headingElement) {
2006
2522
  const raw = attrValue(headingElement, "text:outline-level");
2007
2523
  if (raw === void 0) return 1;
@@ -2044,18 +2560,18 @@ function readBlocks(nodes, pkg, listIdState) {
2044
2560
  }
2045
2561
  return blocks;
2046
2562
  }
2047
- function parseKnownOdfLength(value) {
2563
+ function parseKnownOdfLength$1(value) {
2048
2564
  const parsed = parseOdfLength(value);
2049
2565
  if (parsed === void 0) throw new Error(`readOdt: internal error -- "${value}" is not a valid ODF length literal`);
2050
2566
  return parsed;
2051
2567
  }
2052
- const DEFAULT_PAGE_SIZE = document_content_model.PAGE_SIZE_A4;
2053
- const DEFAULT_MARGIN_PT = parseKnownOdfLength("2cm");
2054
- const DEFAULT_MARGINS = {
2055
- topPt: DEFAULT_MARGIN_PT,
2056
- rightPt: DEFAULT_MARGIN_PT,
2057
- bottomPt: DEFAULT_MARGIN_PT,
2058
- 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
2059
2575
  };
2060
2576
  function findPageLayoutElement(pkg, pageLayoutName) {
2061
2577
  if (pageLayoutName === void 0) return;
@@ -2079,17 +2595,17 @@ function readFirstMasterPageGeometry(pkg) {
2079
2595
  const pageSize = properties === void 0 ? void 0 : parsePageSize(properties);
2080
2596
  const margins = properties === void 0 ? void 0 : parseMargins(properties);
2081
2597
  return {
2082
- pageSize: pageSize ?? DEFAULT_PAGE_SIZE,
2083
- margins: margins ?? DEFAULT_MARGINS
2598
+ pageSize: pageSize ?? DEFAULT_PAGE_SIZE$2,
2599
+ margins: margins ?? DEFAULT_MARGINS$1
2084
2600
  };
2085
2601
  }
2086
2602
  function readOdt(pkg) {
2087
- const contentPart = pkg.parts[CONTENT_PART];
2088
- if (contentPart?.kind !== "xml") throw new Error(`readOdt: package has no ${CONTENT_PART} 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`);
2089
2605
  const contentRoot = rootElement(contentPart.nodes);
2090
2606
  const body = contentRoot === void 0 ? void 0 : findChildElement(contentRoot.children, "office:body");
2091
2607
  const textElement = body === void 0 ? void 0 : findChildElement(body.children, "office:text");
2092
- if (textElement === void 0) throw new Error(`readOdt: ${CONTENT_PART} has no office:body/office:text element`);
2608
+ if (textElement === void 0) throw new Error(`readOdt: ${CONTENT_PART$2} has no office:body/office:text element`);
2093
2609
  const metadata = readOdfMetadata(pkg);
2094
2610
  const { pageSize, margins } = readFirstMasterPageGeometry(pkg);
2095
2611
  return {
@@ -2102,6 +2618,337 @@ function readOdt(pkg) {
2102
2618
  };
2103
2619
  }
2104
2620
  //#endregion
2621
+ //#region src/typed/odg/read.ts
2622
+ const CONTENT_PART$1 = "content.xml";
2623
+ const DEFAULT_PAGE_SIZE$1 = document_content_model.PAGE_SIZE_A4;
2624
+ function readPage(page, pkg) {
2625
+ const size = resolveDrawPageSize(page, pkg) ?? DEFAULT_PAGE_SIZE$1;
2626
+ const { shapes, vectors } = readDrawPageContent(page.children, pkg);
2627
+ return {
2628
+ size,
2629
+ shapes,
2630
+ vectors
2631
+ };
2632
+ }
2633
+ function readOdg(pkg) {
2634
+ const contentPart = pkg.parts[CONTENT_PART$1];
2635
+ const root = contentPart?.kind === "xml" ? rootElement(contentPart.nodes) : void 0;
2636
+ const body = root === void 0 ? void 0 : findChildElement(root.children, "office:body");
2637
+ const drawing = body === void 0 ? void 0 : findChildElement(body.children, "office:drawing");
2638
+ const pages = drawing === void 0 ? [] : childrenWithTag(drawing, "draw:page");
2639
+ return {
2640
+ metadata: readOdfMetadata(pkg),
2641
+ pages: pages.map((page) => readPage(page, pkg))
2642
+ };
2643
+ }
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
2105
2952
  Object.defineProperty(exports, "AlignmentSchema", {
2106
2953
  enumerable: true,
2107
2954
  get: function() {
@@ -2136,6 +2983,7 @@ exports.applyOdfTransform = applyOdfTransform;
2136
2983
  exports.attrValue = attrValue;
2137
2984
  exports.base64ToBytes = base64ToBytes;
2138
2985
  exports.buildManifest = buildManifest;
2986
+ exports.buildOdfSubpaths = buildOdfSubpaths;
2139
2987
  exports.buildStylePropertyElements = buildStylePropertyElements;
2140
2988
  exports.buildXml = buildXml;
2141
2989
  exports.bytesToBase64 = bytesToBase64;
@@ -2143,6 +2991,7 @@ exports.canonicalPropertiesString = canonicalPropertiesString;
2143
2991
  exports.cellReference = cellReference;
2144
2992
  exports.childrenWithTag = childrenWithTag;
2145
2993
  exports.columnIndexToLetters = columnIndexToLetters;
2994
+ exports.columnLettersToIndex = columnLettersToIndex;
2146
2995
  exports.composeOdfGroupTransform = composeOdfGroupTransform;
2147
2996
  exports.decodeOdfText = decodeOdfText;
2148
2997
  exports.decodePackage = decodePackage;
@@ -2167,29 +3016,41 @@ exports.netRotationDeg = netRotationDeg;
2167
3016
  exports.packageCodec = packageCodec;
2168
3017
  exports.paragraphPropertiesToAttributes = paragraphPropertiesToAttributes;
2169
3018
  exports.parseBox = parseBox;
3019
+ exports.parseCellReference = parseCellReference;
2170
3020
  exports.parseLength = parseLength;
3021
+ exports.parseLinePoints = parseLinePoints;
2171
3022
  exports.parseMargins = parseMargins;
2172
3023
  exports.parseOdfColor = parseOdfColor;
2173
3024
  exports.parseOdfLength = parseOdfLength;
3025
+ exports.parseOdfPathData = parseOdfPathData;
3026
+ exports.parseOdfPointsList = parseOdfPointsList;
2174
3027
  exports.parseOdfTransform = parseOdfTransform;
3028
+ exports.parseOdfViewBox = parseOdfViewBox;
2175
3029
  exports.parsePackage = parsePackage;
2176
3030
  exports.parsePageSize = parsePageSize;
2177
3031
  exports.parseParagraphProperties = parseParagraphProperties;
2178
3032
  exports.parseStyleElementProperties = parseStyleElementProperties;
2179
3033
  exports.parseTextProperties = parseTextProperties;
2180
3034
  exports.parseXml = parseXml;
3035
+ exports.rawSubpathFromPoints = rawSubpathFromPoints;
2181
3036
  exports.readDrawFrame = readDrawFrame;
3037
+ exports.readDrawPageContent = readDrawPageContent;
2182
3038
  exports.readManifest = readManifest;
2183
3039
  exports.readMimetype = readMimetype;
2184
3040
  exports.readOdfMetadata = readOdfMetadata;
2185
3041
  exports.readOdfParagraph = readOdfParagraph;
2186
3042
  exports.readOdfTable = readOdfTable;
3043
+ exports.readOdg = readOdg;
2187
3044
  exports.readOdp = readOdp;
3045
+ exports.readOds = readOds;
2188
3046
  exports.readOdt = readOdt;
3047
+ exports.resolveDrawPageSize = resolveDrawPageSize;
2189
3048
  exports.resolveOdfShapeGeometry = resolveOdfShapeGeometry;
3049
+ exports.resolvePageLayoutProperties = resolvePageLayoutProperties;
2190
3050
  exports.resolveStyle = resolveStyle;
2191
3051
  exports.resolveStyleElementChain = resolveStyleElementChain;
2192
3052
  exports.rootElement = rootElement;
3053
+ exports.scaleOdfRawPoint = scaleOdfRawPoint;
2193
3054
  exports.serializePackage = serializePackage;
2194
3055
  exports.setDocumentMediaType = setDocumentMediaType;
2195
3056
  exports.sniffImageFormat = sniffImageFormat;