odf.js 5.1.2 → 5.3.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.
Files changed (92) hide show
  1. package/README.md +5 -3
  2. package/dist/{cascade-rhqUQrUa.d.ts → cascade-BZ7zqXhL.d.ts} +2 -2
  3. package/dist/{cascade-BmvsXcAz.d.cts → cascade-DWQfTwaM.d.cts} +2 -2
  4. package/dist/{codec-BAz7YIru.d.cts → codec-LgpdP32n.d.cts} +13 -13
  5. package/dist/{codec-BxxFEqvT.d.ts → codec-sFSMk-if.d.ts} +13 -13
  6. package/dist/codec.d.cts +1 -1
  7. package/dist/codec.d.ts +1 -1
  8. package/dist/{constructs-CJpDDQV0.d.ts → constructs-B1yajQJB.d.ts} +8 -1
  9. package/dist/{constructs-Dy_DMFs3.d.cts → constructs-BSC_5kfU.d.cts} +8 -1
  10. package/dist/embedded-BSSdoKcK.js +904 -0
  11. package/dist/{embedded-BPhuSEEI.d.ts → embedded-ClsebpWi.d.ts} +7 -2
  12. package/dist/embedded-DbLrCGPi.cjs +945 -0
  13. package/dist/{embedded-J3M3kDvY.d.cts → embedded-rKOsAsjg.d.cts} +7 -2
  14. package/dist/{form-D3H5H2NL.d.ts → form-CsOrcORr.d.ts} +2 -2
  15. package/dist/{form-BGCT81ss.d.cts → form-D8wh-xhJ.d.cts} +2 -2
  16. package/dist/{forms-cIjw-Jf-.d.cts → forms-BydLKkI0.d.cts} +1 -1
  17. package/dist/{forms-D1-0spCe.d.ts → forms-iwRSwhOn.d.ts} +1 -1
  18. package/dist/index.cjs +7 -9
  19. package/dist/index.d.cts +15 -15
  20. package/dist/index.d.ts +15 -15
  21. package/dist/index.js +2 -4
  22. package/dist/{masterpage-XJ2v2khe.d.cts → masterpage-Bt6gxuoL.d.cts} +2 -1
  23. package/dist/{masterpage-C1McDhMv.d.ts → masterpage-By_F05W4.d.ts} +2 -1
  24. package/dist/{paragraph-6hzAZpmi.d.ts → paragraph-BE71DZ0t.d.ts} +4 -3
  25. package/dist/{paragraph-BBmSl_sK.d.cts → paragraph-CuEMXbDg.d.cts} +4 -3
  26. package/dist/{properties-BF_Fv6B3.d.cts → properties-C-JKQZUD.d.cts} +2 -0
  27. package/dist/{properties-DjAIdPry.d.ts → properties-Rral02h1.d.ts} +2 -0
  28. package/dist/read-24g5eZw6.d.ts +25 -0
  29. package/dist/{read-lc0t0UHK.d.ts → read-BLoaDxr_.d.ts} +2 -1
  30. package/dist/{read-B4238IGr.d.cts → read-C3Ei_MYc.d.cts} +2 -1
  31. package/dist/{read-CTfeWaWq.d.cts → read-CDSmR3qt.d.cts} +2 -1
  32. package/dist/{read-CdvX2qnz.d.ts → read-DJqvINGW.d.ts} +2 -1
  33. package/dist/{read-Db_GZ0ZH.d.ts → read-DfEHXwgn.d.ts} +2 -1
  34. package/dist/{read-DOYWO6BM.d.cts → read-IOYq80AA.d.cts} +2 -1
  35. package/dist/read-rwDsgR0d.d.cts +25 -0
  36. package/dist/{registry-CaJpWDke.d.cts → registry-CphRYjDD.d.cts} +1 -1
  37. package/dist/{registry-BVeEpUMI.d.ts → registry-D5RGBteE.d.ts} +1 -1
  38. package/dist/{serialize-DvaE_t5D.d.ts → serialize-B-lq0LiG.d.ts} +1 -1
  39. package/dist/{serialize-9xvti0FF.d.cts → serialize-D1fti8C5.d.cts} +1 -1
  40. package/dist/styles/properties.cjs +25 -3
  41. package/dist/styles/properties.d.cts +1 -1
  42. package/dist/styles/properties.d.ts +1 -1
  43. package/dist/styles/properties.js +25 -3
  44. package/dist/styles/registry.d.cts +1 -1
  45. package/dist/styles/registry.d.ts +1 -1
  46. package/dist/styles/serialize.d.cts +1 -1
  47. package/dist/styles/serialize.d.ts +1 -1
  48. package/dist/typed/draw/embedded.cjs +4 -85
  49. package/dist/typed/draw/embedded.d.cts +2 -2
  50. package/dist/typed/draw/embedded.d.ts +2 -2
  51. package/dist/typed/draw/embedded.js +2 -84
  52. package/dist/typed/draw/shapes.cjs +4 -1
  53. package/dist/typed/draw/shapes.js +4 -1
  54. package/dist/typed/odb/form.cjs +2 -2
  55. package/dist/typed/odb/form.d.cts +1 -1
  56. package/dist/typed/odb/form.d.ts +1 -1
  57. package/dist/typed/odb/form.js +1 -1
  58. package/dist/typed/odg/read.cjs +14 -4
  59. package/dist/typed/odg/read.d.cts +1 -1
  60. package/dist/typed/odg/read.d.ts +1 -1
  61. package/dist/typed/odg/read.js +14 -4
  62. package/dist/typed/odp/read.cjs +51 -4
  63. package/dist/typed/odp/read.d.cts +1 -1
  64. package/dist/typed/odp/read.d.ts +1 -1
  65. package/dist/typed/odp/read.js +52 -5
  66. package/dist/typed/ods/read.cjs +3 -446
  67. package/dist/typed/ods/read.d.cts +1 -1
  68. package/dist/typed/ods/read.d.ts +1 -1
  69. package/dist/typed/ods/read.js +1 -444
  70. package/dist/typed/odt/read.cjs +3 -310
  71. package/dist/typed/odt/read.d.cts +2 -2
  72. package/dist/typed/odt/read.d.ts +2 -2
  73. package/dist/typed/odt/read.js +1 -308
  74. package/dist/typed/shared/cascade.d.cts +1 -1
  75. package/dist/typed/shared/cascade.d.ts +1 -1
  76. package/dist/typed/shared/constructs.cjs +73 -0
  77. package/dist/typed/shared/constructs.d.cts +2 -2
  78. package/dist/typed/shared/constructs.d.ts +2 -2
  79. package/dist/typed/shared/constructs.js +67 -1
  80. package/dist/typed/shared/forms.d.cts +1 -1
  81. package/dist/typed/shared/forms.d.ts +1 -1
  82. package/dist/typed/shared/masterpage.cjs +7 -0
  83. package/dist/typed/shared/masterpage.d.cts +2 -2
  84. package/dist/typed/shared/masterpage.d.ts +2 -2
  85. package/dist/typed/shared/masterpage.js +7 -1
  86. package/dist/typed/shared/paragraph.cjs +17 -6
  87. package/dist/typed/shared/paragraph.d.cts +2 -2
  88. package/dist/typed/shared/paragraph.d.ts +2 -2
  89. package/dist/typed/shared/paragraph.js +18 -8
  90. package/package.json +2 -2
  91. package/dist/read-Cs1ktkWB.d.cts +0 -15
  92. package/dist/read-DHuiGh_y.d.ts +0 -15
@@ -0,0 +1,904 @@
1
+ import { parseOdfLength } from "./typed/shared/units.js";
2
+ import { attrValue, childrenWithTag, elementsWithTag, findChildElement, rootElement } from "./xml/query.js";
3
+ import { TableCursor, parseCellReference as parseCellReference$1 } from "./typed/shared/a1.js";
4
+ import { parseMargins, parsePageSize } from "./typed/shared/geometry.js";
5
+ import { findStyleElement, resolveStyleElementChain } from "./typed/shared/cascade.js";
6
+ import { readOdfMetadata } from "./typed/shared/metadata.js";
7
+ import { mintOdfListNumId, readOdfListParagraphs } from "./typed/shared/list.js";
8
+ import { addOdfPackageResidue, collectOdfDataStyleDefinitions, collectOdfFieldMasterDefinitions, collectOdfFontFaceDefinitions, collectOdfNamedExpressions, collectOdfNonContentPartResidue, collectOdfProvenanceRegions, insertOdfConstructMarkers, isOdfExtensionElement, isOdfIndexWrapper, odfDivisionDescriptor, odfIndexControlDescriptor, odfMarkerHalfEventIndex, odfResidue, resolveOdfMarkerEvents } from "./typed/shared/constructs.js";
9
+ import { readOdfConstructBodyBlocks, readOdfParagraph } from "./typed/shared/paragraph.js";
10
+ import { readCellStyleDecoration, readOdfTable } from "./typed/shared/table.js";
11
+ import { parseOdfTransform } from "./typed/shared/transform.js";
12
+ import { readOdfMasterPageElements, resolvePageLayoutProperties } from "./typed/shared/masterpage.js";
13
+ import { readDrawFrame } from "./typed/draw/shapes.js";
14
+ import { findMathRoot, readOdfFormulaContent } from "./typed/formula/read.js";
15
+ import { subDocumentPackage } from "./typed/odb/subdocument.js";
16
+ import { readOdgContent } from "./typed/odg/read.js";
17
+ import { readOdpContent } from "./typed/odp/read.js";
18
+ import { readOdfFormControlConstructs } from "./typed/shared/forms.js";
19
+ import { PAGE_SIZE_A4, assemblePackage } from "document-schema.js";
20
+ //#region src/typed/ods/read.ts
21
+ const CONTENT_PART$2 = "content.xml";
22
+ function parseKnownOdfLength$1(value) {
23
+ const parsed = parseOdfLength(value);
24
+ if (parsed === void 0) throw new Error(`readOdsContent: internal error -- "${value}" is not a valid ODF length literal`);
25
+ return parsed;
26
+ }
27
+ const DEFAULT_MARGIN_PT$1 = parseKnownOdfLength$1("2cm");
28
+ const DEFAULT_MARGINS$1 = {
29
+ topPt: DEFAULT_MARGIN_PT$1,
30
+ rightPt: DEFAULT_MARGIN_PT$1,
31
+ bottomPt: DEFAULT_MARGIN_PT$1,
32
+ leftPt: DEFAULT_MARGIN_PT$1
33
+ };
34
+ function readRepeatCount(element, attrName) {
35
+ const raw = attrValue(element, attrName);
36
+ if (raw === void 0) return 1;
37
+ const parsed = Number.parseInt(raw, 10);
38
+ return Number.isInteger(parsed) && parsed > 0 ? parsed : 1;
39
+ }
40
+ function isHidden(element) {
41
+ return attrValue(element, "table:visibility") === "collapse";
42
+ }
43
+ const DEFAULT_COLUMN_WIDTH_PT = 64;
44
+ const DEFAULT_ROW_HEIGHT_PT = 15;
45
+ function readColumnLayout(columnElement, pkg) {
46
+ const styleName = attrValue(columnElement, "table:style-name");
47
+ const styleElement = styleName === void 0 ? void 0 : findStyleElement(styleName, "table-column", pkg);
48
+ const properties = styleElement === void 0 ? void 0 : childrenWithTag(styleElement, "style:table-column-properties")[0];
49
+ const widthValue = properties === void 0 ? void 0 : attrValue(properties, "style:column-width");
50
+ return {
51
+ widthPt: widthValue === void 0 ? DEFAULT_COLUMN_WIDTH_PT : parseOdfLength(widthValue) ?? DEFAULT_COLUMN_WIDTH_PT,
52
+ manualBreak: (properties === void 0 ? void 0 : attrValue(properties, "fo:break-before")) === "page"
53
+ };
54
+ }
55
+ function readRowLayout(rowElement, pkg) {
56
+ const styleName = attrValue(rowElement, "table:style-name");
57
+ const styleElement = styleName === void 0 ? void 0 : findStyleElement(styleName, "table-row", pkg);
58
+ const properties = styleElement === void 0 ? void 0 : childrenWithTag(styleElement, "style:table-row-properties")[0];
59
+ const heightValue = properties === void 0 ? void 0 : attrValue(properties, "style:row-height");
60
+ return {
61
+ heightPt: heightValue === void 0 ? DEFAULT_ROW_HEIGHT_PT : parseOdfLength(heightValue) ?? DEFAULT_ROW_HEIGHT_PT,
62
+ manualBreak: (properties === void 0 ? void 0 : attrValue(properties, "fo:break-before")) === "page"
63
+ };
64
+ }
65
+ function readCellText(cellElement, pkg) {
66
+ const paragraphs = childrenWithTag(cellElement, "text:p");
67
+ const runs = [];
68
+ paragraphs.forEach((paragraph, index) => {
69
+ if (index > 0) runs.push({ text: "\n" });
70
+ runs.push(...readOdfParagraph(paragraph, pkg).runs);
71
+ });
72
+ return {
73
+ runs,
74
+ displayText: runs.map((run) => run.text).join("")
75
+ };
76
+ }
77
+ function readCellValue(cellElement, displayText) {
78
+ const valueType = attrValue(cellElement, "office:value-type");
79
+ const stringFallback = {
80
+ kind: "string",
81
+ value: displayText
82
+ };
83
+ switch (valueType) {
84
+ case "float": {
85
+ const value = parseRequiredNumber(attrValue(cellElement, "office:value"));
86
+ return value === void 0 ? stringFallback : {
87
+ kind: "number",
88
+ value
89
+ };
90
+ }
91
+ case "percentage": {
92
+ const value = parseRequiredNumber(attrValue(cellElement, "office:value"));
93
+ return value === void 0 ? stringFallback : {
94
+ kind: "percentage",
95
+ value
96
+ };
97
+ }
98
+ case "currency": {
99
+ const value = parseRequiredNumber(attrValue(cellElement, "office:value"));
100
+ if (value === void 0) return stringFallback;
101
+ const currency = attrValue(cellElement, "office:currency");
102
+ return currency === void 0 ? {
103
+ kind: "currency",
104
+ value
105
+ } : {
106
+ kind: "currency",
107
+ value,
108
+ currency
109
+ };
110
+ }
111
+ case "boolean": {
112
+ const raw = attrValue(cellElement, "office:boolean-value");
113
+ return raw === void 0 ? stringFallback : {
114
+ kind: "boolean",
115
+ value: raw === "true"
116
+ };
117
+ }
118
+ case "date": return {
119
+ kind: "date",
120
+ value: attrValue(cellElement, "office:date-value") ?? displayText
121
+ };
122
+ case "time": return {
123
+ kind: "time",
124
+ value: attrValue(cellElement, "office:time-value") ?? displayText
125
+ };
126
+ case "string": return {
127
+ kind: "string",
128
+ value: attrValue(cellElement, "office:string-value") ?? displayText
129
+ };
130
+ default: return { kind: "empty" };
131
+ }
132
+ }
133
+ function parseRequiredNumber(raw) {
134
+ if (raw === void 0) return;
135
+ const value = Number(raw);
136
+ return Number.isNaN(value) ? void 0 : value;
137
+ }
138
+ function parsePrintRanges(value) {
139
+ const first = value.split(" ").find((part) => part.length > 0);
140
+ if (first === void 0) return;
141
+ const separatorIndex = first.indexOf(":");
142
+ if (separatorIndex === -1) return;
143
+ const start = parseA1WithOptionalSheetPrefix(first.slice(0, separatorIndex));
144
+ const end = parseA1WithOptionalSheetPrefix(first.slice(separatorIndex + 1));
145
+ if (start === void 0 || end === void 0) return;
146
+ return {
147
+ startRow: start.row,
148
+ startColumn: start.column,
149
+ endRow: end.row,
150
+ endColumn: end.column
151
+ };
152
+ }
153
+ function parseA1WithOptionalSheetPrefix(cellPart) {
154
+ const dotIndex = cellPart.lastIndexOf(".");
155
+ const bareReference = dotIndex === -1 ? cellPart : cellPart.slice(dotIndex + 1);
156
+ return parseCellReference$1(bareReference);
157
+ }
158
+ function parseScalePercentage(value) {
159
+ const match = /^(\d+(?:\.\d+)?)%$/.exec(value);
160
+ if (match === null) return;
161
+ const numeric = match[1];
162
+ return numeric === void 0 ? void 0 : Number(numeric);
163
+ }
164
+ function parseNonNegativeInteger(value) {
165
+ if (value === void 0) return;
166
+ const parsed = Number.parseInt(value, 10);
167
+ return Number.isInteger(parsed) && parsed >= 0 ? parsed : void 0;
168
+ }
169
+ function collectAnchoredFrame(frameElement, groupFunctions, pkg, anchorRow, anchorColumn, images, embeddedObjects) {
170
+ const shape = readDrawFrame(frameElement, groupFunctions, pkg);
171
+ if (shape === void 0) return;
172
+ const reference = readDrawObjectReference(frameElement, pkg);
173
+ if (reference !== void 0) {
174
+ const { document, residue } = readEmbeddedObjectDocument(reference, shape.frame, "ods");
175
+ const object = {
176
+ objectKind: reference.objectKind,
177
+ document,
178
+ frame: shape.frame,
179
+ anchorRow,
180
+ anchorColumn,
181
+ offsetXPt: shape.frame.xPt,
182
+ offsetYPt: shape.frame.yPt
183
+ };
184
+ if (residue !== void 0) object.source = residue;
185
+ embeddedObjects.push(object);
186
+ return;
187
+ }
188
+ for (const block of shape.blocks) if (block.kind === "image") images.push({
189
+ ...block,
190
+ anchorRow,
191
+ anchorColumn,
192
+ offsetXPt: shape.frame.xPt,
193
+ offsetYPt: shape.frame.yPt
194
+ });
195
+ }
196
+ function collectAnchoredFrames(children, groupFunctions, pkg, anchorRow, anchorColumn, images, embeddedObjects) {
197
+ for (const child of children) {
198
+ if (child.type !== "element") continue;
199
+ if (child.tag === "draw:frame") collectAnchoredFrame(child, groupFunctions, pkg, anchorRow, anchorColumn, images, embeddedObjects);
200
+ else if (child.tag === "draw:g") {
201
+ const ownValue = attrValue(child, "draw:transform");
202
+ const ownFunctions = ownValue === void 0 ? [] : parseOdfTransform(ownValue);
203
+ const nested = ownFunctions.length === 0 ? groupFunctions : [...ownFunctions, ...groupFunctions];
204
+ collectAnchoredFrames(child.children, nested, pkg, anchorRow, anchorColumn, images, embeddedObjects);
205
+ }
206
+ }
207
+ }
208
+ function readTable(tableElement, pkg) {
209
+ const columns = [];
210
+ const rows = [];
211
+ const cells = [];
212
+ const images = [];
213
+ const embeddedObjects = [];
214
+ const manualBreakRows = [];
215
+ const manualBreakColumns = [];
216
+ let repeatColumns;
217
+ let repeatRows;
218
+ let columnCursor = 0;
219
+ const cursor = new TableCursor();
220
+ function processColumn(columnElement) {
221
+ const { widthPt, manualBreak } = readColumnLayout(columnElement, pkg);
222
+ columns.push({
223
+ index: columnCursor,
224
+ widthPt,
225
+ hidden: isHidden(columnElement) ? true : void 0
226
+ });
227
+ if (manualBreak) manualBreakColumns.push(columnCursor);
228
+ columnCursor += readRepeatCount(columnElement, "table:number-columns-repeated");
229
+ }
230
+ function processRowCells(rowElement) {
231
+ for (const child of rowElement.children) {
232
+ if (child.type !== "element") continue;
233
+ if (child.tag === "table:covered-table-cell") cursor.nextCell(readRepeatCount(child, "table:number-columns-repeated"));
234
+ else if (child.tag === "table:table-cell") {
235
+ const columnIndex = cursor.columnIndex;
236
+ const rowIndex = cursor.rowIndex;
237
+ cursor.nextCell(readRepeatCount(child, "table:number-columns-repeated"));
238
+ collectAnchoredFrames(child.children, [], pkg, rowIndex, columnIndex, images, embeddedObjects);
239
+ const formula = attrValue(child, "table:formula");
240
+ const { runs, displayText } = readCellText(child, pkg);
241
+ if (!(attrValue(child, "office:value-type") !== void 0) && formula === void 0 && displayText.length === 0) continue;
242
+ const value = readCellValue(child, displayText);
243
+ const colSpan = parseNonNegativeInteger(attrValue(child, "table:number-columns-spanned"));
244
+ const rowSpan = parseNonNegativeInteger(attrValue(child, "table:number-rows-spanned"));
245
+ const cell = {
246
+ row: rowIndex,
247
+ column: columnIndex,
248
+ value,
249
+ displayText
250
+ };
251
+ if (formula !== void 0) cell.formula = formula;
252
+ if (runs.length > 0) cell.runs = runs;
253
+ if (colSpan !== void 0) cell.colSpan = colSpan;
254
+ if (rowSpan !== void 0) cell.rowSpan = rowSpan;
255
+ const cellStyleName = attrValue(child, "table:style-name");
256
+ const { elements: cellStyleChain } = resolveStyleElementChain(cellStyleName, "table-cell", pkg);
257
+ const decoration = readCellStyleDecoration(cellStyleChain);
258
+ if (decoration.background !== void 0) cell.background = decoration.background;
259
+ if (decoration.borders !== void 0) cell.borders = decoration.borders;
260
+ if (decoration.alignment !== void 0) cell.alignment = decoration.alignment;
261
+ if (decoration.verticalAlignment !== void 0) cell.verticalAlignment = decoration.verticalAlignment;
262
+ cells.push(cell);
263
+ }
264
+ }
265
+ }
266
+ function processRow(rowElement) {
267
+ const startIndex = cursor.rowIndex;
268
+ processRowCells(rowElement);
269
+ const { heightPt, manualBreak } = readRowLayout(rowElement, pkg);
270
+ rows.push({
271
+ index: startIndex,
272
+ heightPt,
273
+ hidden: isHidden(rowElement) ? true : void 0
274
+ });
275
+ if (manualBreak) manualBreakRows.push(startIndex);
276
+ cursor.nextRow(readRepeatCount(rowElement, "table:number-rows-repeated"));
277
+ }
278
+ for (const child of tableElement.children) {
279
+ if (child.type !== "element") continue;
280
+ if (child.tag === "table:shapes") collectAnchoredFrames(child.children, [], pkg, 0, 0, images, embeddedObjects);
281
+ else if (child.tag === "table:table-column") processColumn(child);
282
+ else if (child.tag === "table:table-header-columns") {
283
+ const startIndex = columnCursor;
284
+ for (const headerChild of child.children) if (headerChild.type === "element" && headerChild.tag === "table:table-column") processColumn(headerChild);
285
+ if (columnCursor > startIndex) repeatColumns = {
286
+ start: startIndex,
287
+ end: columnCursor - 1
288
+ };
289
+ } else if (child.tag === "table:table-row") processRow(child);
290
+ else if (child.tag === "table:table-header-rows") {
291
+ const startIndex = cursor.rowIndex;
292
+ for (const headerChild of child.children) if (headerChild.type === "element" && headerChild.tag === "table:table-row") processRow(headerChild);
293
+ if (cursor.rowIndex > startIndex) repeatRows = {
294
+ start: startIndex,
295
+ end: cursor.rowIndex - 1
296
+ };
297
+ }
298
+ }
299
+ return {
300
+ columns,
301
+ rows,
302
+ cells,
303
+ images,
304
+ embeddedObjects,
305
+ repeatColumns,
306
+ repeatRows,
307
+ manualBreakRows,
308
+ manualBreakColumns
309
+ };
310
+ }
311
+ function readPrintSettings(tableElement, pkg, repeatColumns, repeatRows, manualBreakRows, manualBreakColumns) {
312
+ const tableStyleName = attrValue(tableElement, "table:style-name");
313
+ const tableStyleElement = tableStyleName === void 0 ? void 0 : findStyleElement(tableStyleName, "table", pkg);
314
+ const masterPageName = tableStyleElement === void 0 ? void 0 : attrValue(tableStyleElement, "style:master-page-name");
315
+ const layoutProperties = resolvePageLayoutProperties(pkg, masterPageName);
316
+ const pageSize = layoutProperties === void 0 ? void 0 : parsePageSize(layoutProperties);
317
+ const margins = layoutProperties === void 0 ? void 0 : parseMargins(layoutProperties);
318
+ const printTokens = new Set((layoutProperties === void 0 ? void 0 : attrValue(layoutProperties, "style:print"))?.split(" ").filter((token) => token.length > 0));
319
+ const pageOrder = (layoutProperties === void 0 ? void 0 : attrValue(layoutProperties, "style:print-page-order")) === "ltr" ? "overThenDown" : "downThenOver";
320
+ const scaleToRaw = layoutProperties === void 0 ? void 0 : attrValue(layoutProperties, "style:scale-to");
321
+ const scale = scaleToRaw === void 0 ? void 0 : parseScalePercentage(scaleToRaw);
322
+ const scaleToXRaw = layoutProperties === void 0 ? void 0 : attrValue(layoutProperties, "style:scale-to-X");
323
+ const scaleToYRaw = layoutProperties === void 0 ? void 0 : attrValue(layoutProperties, "style:scale-to-Y");
324
+ const fitWidth = parseNonNegativeInteger(scaleToXRaw);
325
+ const fitHeight = parseNonNegativeInteger(scaleToYRaw);
326
+ const fitToPages = fitWidth === void 0 || fitHeight === void 0 ? void 0 : {
327
+ width: fitWidth,
328
+ height: fitHeight
329
+ };
330
+ const printRangesRaw = attrValue(tableElement, "table:print-ranges");
331
+ const printRange = printRangesRaw === void 0 ? void 0 : parsePrintRanges(printRangesRaw);
332
+ const manualBreaks = manualBreakRows.length > 0 || manualBreakColumns.length > 0 ? {
333
+ rows: manualBreakRows,
334
+ columns: manualBreakColumns
335
+ } : void 0;
336
+ const settings = {
337
+ pageSize: pageSize ?? PAGE_SIZE_A4,
338
+ margins: margins ?? DEFAULT_MARGINS$1,
339
+ gridlines: printTokens.has("grid"),
340
+ headers: printTokens.has("headers"),
341
+ pageOrder
342
+ };
343
+ if (printRange !== void 0) settings.printRange = printRange;
344
+ if (scale !== void 0) settings.scalePercent = scale;
345
+ if (fitToPages !== void 0) settings.fitToPages = fitToPages;
346
+ if (repeatRows !== void 0) settings.repeatRows = repeatRows;
347
+ if (repeatColumns !== void 0) settings.repeatColumns = repeatColumns;
348
+ if (manualBreaks !== void 0) settings.manualBreaks = manualBreaks;
349
+ return settings;
350
+ }
351
+ function readSheet(tableElement, pkg) {
352
+ const name = attrValue(tableElement, "table:name");
353
+ if (name === void 0) return;
354
+ const { columns, rows, cells, images, embeddedObjects, repeatColumns, repeatRows, manualBreakRows, manualBreakColumns } = readTable(tableElement, pkg);
355
+ const sheet = {
356
+ name,
357
+ cells,
358
+ columns,
359
+ rows,
360
+ images,
361
+ printSettings: readPrintSettings(tableElement, pkg, repeatColumns, repeatRows, manualBreakRows, manualBreakColumns)
362
+ };
363
+ if (embeddedObjects.length > 0) sheet.embeddedObjects = embeddedObjects;
364
+ return sheet;
365
+ }
366
+ function collectOdsExtensionElementResidue(children, source) {
367
+ for (const child of children) if (child.type === "element" && isOdfExtensionElement(child)) addOdfPackageResidue(source, child.tag, "ods", child);
368
+ }
369
+ function readOdsContent(pkg) {
370
+ const contentPart = pkg.parts[CONTENT_PART$2];
371
+ const root = contentPart?.kind === "xml" ? rootElement(contentPart.nodes) : void 0;
372
+ const body = root === void 0 ? void 0 : findChildElement(root.children, "office:body");
373
+ const spreadsheet = body === void 0 ? void 0 : findChildElement(body.children, "office:spreadsheet");
374
+ const tables = spreadsheet === void 0 ? [] : childrenWithTag(spreadsheet, "table:table");
375
+ const sheets = [];
376
+ for (const table of tables) {
377
+ const sheet = readSheet(table, pkg);
378
+ if (sheet !== void 0) sheets.push(sheet);
379
+ }
380
+ const definitions = {};
381
+ const source = {};
382
+ if (spreadsheet !== void 0) {
383
+ collectOdfNamedExpressions(spreadsheet.children, definitions);
384
+ addOdfPackageResidue(source, "calculation-settings", "ods", ...childrenWithTag(spreadsheet, "table:calculation-settings"));
385
+ collectOdsExtensionElementResidue(spreadsheet.children, source);
386
+ for (const table of tables) collectOdsExtensionElementResidue(table.children, source);
387
+ }
388
+ collectOdfNonContentPartResidue(pkg, "ods", source);
389
+ return {
390
+ metadata: readOdfMetadata(pkg),
391
+ sheets,
392
+ ...Object.keys(definitions).length > 0 ? { definitions } : {},
393
+ ...Object.keys(source).length > 0 ? { source } : {}
394
+ };
395
+ }
396
+ function readOds(pkg) {
397
+ const { metadata, sheets, definitions, source } = readOdsContent(pkg);
398
+ const assembled = assemblePackage({
399
+ kind: "spreadsheet",
400
+ metadata,
401
+ sheets
402
+ });
403
+ if (definitions !== void 0) assembled.definitions = definitions;
404
+ if (source !== void 0) assembled.source = source;
405
+ return assembled;
406
+ }
407
+ //#endregion
408
+ //#region src/typed/odt/read.ts
409
+ const ODT_HEADER_FOOTER_TAGS = /* @__PURE__ */ new Map([
410
+ ["style:header", {
411
+ kind: "header",
412
+ variant: "default"
413
+ }],
414
+ ["style:header-left", {
415
+ kind: "header",
416
+ variant: "left"
417
+ }],
418
+ ["style:header-first", {
419
+ kind: "header",
420
+ variant: "first"
421
+ }],
422
+ ["style:footer", {
423
+ kind: "footer",
424
+ variant: "default"
425
+ }],
426
+ ["style:footer-left", {
427
+ kind: "footer",
428
+ variant: "left"
429
+ }],
430
+ ["style:footer-first", {
431
+ kind: "footer",
432
+ variant: "first"
433
+ }]
434
+ ]);
435
+ const CONTENT_PART$1 = "content.xml";
436
+ const AUTOMATIC_STYLE_PARTS = [CONTENT_PART$1, "styles.xml"];
437
+ function readOutlineLevel(headingElement) {
438
+ const raw = attrValue(headingElement, "text:outline-level");
439
+ if (raw === void 0) return 1;
440
+ const parsed = Number.parseInt(raw, 10);
441
+ return Number.isInteger(parsed) && parsed > 0 ? parsed : 1;
442
+ }
443
+ function readParagraphOrHeading(element, paragraph) {
444
+ if (element.tag === "text:h") {
445
+ const outlineLevel = readOutlineLevel(element);
446
+ paragraph.styleId = `Heading${outlineLevel}`;
447
+ paragraph.headingLevel = outlineLevel;
448
+ }
449
+ return paragraph;
450
+ }
451
+ function resolveParagraphMasterPageName(element, pkg, state) {
452
+ const styleName = attrValue(element, "text:style-name");
453
+ if (state.masterPageByStyleName.has(styleName)) return state.masterPageByStyleName.get(styleName);
454
+ let resolved;
455
+ for (const style of resolveStyleElementChain(styleName, "paragraph", pkg).elements) {
456
+ const properties = findChildElement(style.children, "style:paragraph-properties");
457
+ const name = properties === void 0 ? void 0 : attrValue(properties, "style:master-page-name");
458
+ if (name !== void 0) resolved = name;
459
+ }
460
+ state.masterPageByStyleName.set(styleName, resolved);
461
+ return resolved;
462
+ }
463
+ function readAnchoredFrameSources(paragraphElement, pkg, state) {
464
+ if (!state.liftFrames) return [];
465
+ const sources = [];
466
+ const readFrameInto = (blocks, frameElement) => {
467
+ const shape = readDrawFrame(frameElement, [], pkg, state.listIdState, true);
468
+ if (shape === void 0) return;
469
+ const reference = readDrawObjectReference(frameElement, pkg);
470
+ if (reference !== void 0) {
471
+ const { document, residue } = readEmbeddedObjectDocument(reference, shape.frame, "odt");
472
+ const embeddedBlock = {
473
+ kind: "embeddedObject",
474
+ objectKind: reference.objectKind,
475
+ document,
476
+ frame: shape.frame
477
+ };
478
+ if (residue !== void 0) embeddedBlock.source = residue;
479
+ blocks.push(embeddedBlock);
480
+ return;
481
+ }
482
+ blocks.push(...shape.blocks);
483
+ };
484
+ for (const child of paragraphElement.children) {
485
+ if (child.type !== "element") continue;
486
+ if (child.tag === "draw:frame") {
487
+ const blocks = [];
488
+ readFrameInto(blocks, child);
489
+ if (blocks.length > 0) sources.push({
490
+ child,
491
+ blocks
492
+ });
493
+ } else if (child.tag === "draw:g") {
494
+ const blocks = [];
495
+ for (const grandChild of child.children) if (grandChild.type === "element" && grandChild.tag === "draw:frame") readFrameInto(blocks, grandChild);
496
+ if (blocks.length > 0) sources.push({
497
+ child,
498
+ blocks
499
+ });
500
+ }
501
+ }
502
+ return sources;
503
+ }
504
+ function liftedBlocksBeforeHalf(read, half) {
505
+ const halfIndex = read.element.children.indexOf(half);
506
+ if (halfIndex === -1) return 0;
507
+ let count = 0;
508
+ for (const source of read.liftedSources) if (read.element.children.indexOf(source.child) < halfIndex) count += source.blocks.length;
509
+ return count;
510
+ }
511
+ function readBlocks(nodes, pkg, state, baseIndex = 0) {
512
+ const blocks = [];
513
+ const emitParagraphs = (reads) => {
514
+ let cursor = baseIndex + blocks.length;
515
+ for (const read of reads) {
516
+ if (read.masterPageName !== void 0 && read.masterPageName !== state.masterPage) {
517
+ state.sectionSplits.push({
518
+ index: cursor,
519
+ masterPage: read.masterPageName
520
+ });
521
+ state.masterPage = read.masterPageName;
522
+ }
523
+ const lifted = read.liftedSources.flatMap((source) => source.blocks);
524
+ for (const half of read.halves) {
525
+ const eventIndex = odfMarkerHalfEventIndex(half, read.element, cursor, liftedBlocksBeforeHalf(read, half.element));
526
+ if (eventIndex !== void 0) state.markerEvents.push({
527
+ kind: half.kind,
528
+ side: half.side,
529
+ key: half.key,
530
+ index: eventIndex,
531
+ qualified: true,
532
+ order: state.order++,
533
+ descriptor: half.descriptor,
534
+ element: half.element
535
+ });
536
+ }
537
+ blocks.push(read.paragraph);
538
+ for (const block of lifted) blocks.push(block);
539
+ cursor += 1 + lifted.length;
540
+ }
541
+ };
542
+ const readOneParagraph = (element) => {
543
+ const halves = [];
544
+ return {
545
+ element,
546
+ paragraph: readParagraphOrHeading(element, readOdfParagraph(element, pkg, {
547
+ provenanceRegions: state.provenanceRegions,
548
+ markersOut: halves,
549
+ definitions: state.definitions,
550
+ listIdState: state.listIdState,
551
+ format: "odt"
552
+ })),
553
+ halves,
554
+ liftedSources: readAnchoredFrameSources(element, pkg, state),
555
+ masterPageName: resolveParagraphMasterPageName(element, pkg, state)
556
+ };
557
+ };
558
+ for (const node of nodes) {
559
+ if (node.type !== "element") continue;
560
+ if (node.tag === "text:p" || node.tag === "text:h") emitParagraphs([readOneParagraph(node)]);
561
+ else if (node.tag === "text:list") {
562
+ const numId = mintOdfListNumId(pkg, node, state.listIdState);
563
+ const reads = [];
564
+ readOdfListParagraphs(node, {
565
+ numId,
566
+ level: 0
567
+ }, (element) => {
568
+ const read = readOneParagraph(element);
569
+ reads.push(read);
570
+ return read.paragraph;
571
+ });
572
+ emitParagraphs(reads);
573
+ } else if (node.tag === "table:table") blocks.push(readOdfTable(node, pkg));
574
+ else if (node.tag === "text:section") {
575
+ const startIndex = baseIndex + blocks.length;
576
+ const order = state.order++;
577
+ blocks.push(...readBlocks(node.children, pkg, state, startIndex));
578
+ state.wrapperExtents.push({
579
+ startIndex,
580
+ endIndex: baseIndex + blocks.length,
581
+ order,
582
+ descriptor: odfDivisionDescriptor(node, pkg)
583
+ });
584
+ addOdfPackageResidue(state.packageResidue, "dde-links", "odt", ...childrenWithTag(node, "text:dde-source"));
585
+ } else if (isOdfIndexWrapper(node)) {
586
+ const startIndex = baseIndex + blocks.length;
587
+ const order = state.order++;
588
+ const body = node.children.find((child) => child.type === "element" && child.tag === "text:index-body");
589
+ blocks.push(...body === void 0 ? [] : readBlocks(body.children, pkg, state, startIndex));
590
+ state.wrapperExtents.push({
591
+ startIndex,
592
+ endIndex: baseIndex + blocks.length,
593
+ order,
594
+ descriptor: odfIndexControlDescriptor(node)
595
+ });
596
+ } else if (node.tag === "text:index-title") blocks.push(...readBlocks(node.children, pkg, state, baseIndex + blocks.length));
597
+ else if (node.tag === "office:forms") {
598
+ blocks.push(...readOdfFormControlConstructs(node, "odt"));
599
+ addOdfPackageResidue(state.packageResidue, "xforms", "odt", ...childrenWithTag(node, "xforms:model"));
600
+ } else if (node.tag === "text:dde-connection-decls") addOdfPackageResidue(state.packageResidue, "dde-connections", "odt", ...childrenWithTag(node, "text:dde-connection-decl"));
601
+ else if (isOdfExtensionElement(node)) addOdfPackageResidue(state.packageResidue, node.tag, "odt", node);
602
+ }
603
+ return blocks;
604
+ }
605
+ function parseKnownOdfLength(value) {
606
+ const parsed = parseOdfLength(value);
607
+ if (parsed === void 0) throw new Error(`readOdtContent: internal error -- "${value}" is not a valid ODF length literal`);
608
+ return parsed;
609
+ }
610
+ const DEFAULT_MARGIN_PT = parseKnownOdfLength("2cm");
611
+ const DEFAULT_MARGINS = {
612
+ topPt: DEFAULT_MARGIN_PT,
613
+ rightPt: DEFAULT_MARGIN_PT,
614
+ bottomPt: DEFAULT_MARGIN_PT,
615
+ leftPt: DEFAULT_MARGIN_PT
616
+ };
617
+ function findPageLayoutElement(pkg, pageLayoutName) {
618
+ if (pageLayoutName === void 0) return;
619
+ for (const partPath of AUTOMATIC_STYLE_PARTS) {
620
+ const part = pkg.parts[partPath];
621
+ if (part?.kind !== "xml") continue;
622
+ const root = rootElement(part.nodes);
623
+ const automaticStyles = root === void 0 ? void 0 : findChildElement(root.children, "office:automatic-styles");
624
+ if (automaticStyles === void 0) continue;
625
+ const found = childrenWithTag(automaticStyles, "style:page-layout").find((element) => attrValue(element, "style:name") === pageLayoutName);
626
+ if (found !== void 0) return found;
627
+ }
628
+ }
629
+ function resolveMasterPageGeometry(pkg, masterPage) {
630
+ const layout = findPageLayoutElement(pkg, attrValue(masterPage, "style:page-layout-name"));
631
+ const properties = layout === void 0 ? void 0 : findChildElement(layout.children, "style:page-layout-properties");
632
+ const pageSize = properties === void 0 ? void 0 : parsePageSize(properties);
633
+ const margins = properties === void 0 ? void 0 : parseMargins(properties);
634
+ return {
635
+ pageSize: pageSize ?? PAGE_SIZE_A4,
636
+ margins: margins ?? DEFAULT_MARGINS
637
+ };
638
+ }
639
+ function splitOdtSections(walked, extents, splits, initialMasterPage, geometryByMasterPage) {
640
+ let initial = initialMasterPage;
641
+ let boundaries = splits;
642
+ const firstSplit = splits[0];
643
+ if (firstSplit?.index === 0) {
644
+ initial = firstSplit.masterPage;
645
+ boundaries = splits.slice(1);
646
+ }
647
+ const sections = [];
648
+ const masterPages = [];
649
+ for (let segment = 0; segment <= boundaries.length; segment += 1) {
650
+ const start = segment === 0 ? 0 : boundaries[segment - 1].index;
651
+ const end = segment === boundaries.length ? walked.length : boundaries[segment].index;
652
+ const masterPage = segment === 0 ? initial : boundaries[segment - 1].masterPage;
653
+ const geometry = masterPage === void 0 ? void 0 : geometryByMasterPage.get(masterPage);
654
+ const segmentExtents = extents.filter((extent) => extent.startIndex >= start && extent.endIndex <= end).map((extent) => ({
655
+ ...extent,
656
+ startIndex: extent.startIndex - start,
657
+ endIndex: extent.endIndex - start
658
+ }));
659
+ const blocks = insertOdfConstructMarkers(walked.slice(start, end), segmentExtents);
660
+ sections.push({
661
+ pageSize: geometry?.pageSize ?? PAGE_SIZE_A4,
662
+ margins: geometry?.margins ?? DEFAULT_MARGINS,
663
+ blocks,
664
+ ...segment > 0 ? { breakType: "nextPage" } : {}
665
+ });
666
+ masterPages.push(masterPage);
667
+ }
668
+ return {
669
+ sections,
670
+ masterPages
671
+ };
672
+ }
673
+ function readOdtContent(pkg, options = {}) {
674
+ const contentPart = pkg.parts[CONTENT_PART$1];
675
+ if (contentPart?.kind !== "xml") throw new Error(`readOdtContent: package has no ${CONTENT_PART$1} part`);
676
+ const contentRoot = rootElement(contentPart.nodes);
677
+ const body = contentRoot === void 0 ? void 0 : findChildElement(contentRoot.children, "office:body");
678
+ const textElement = body === void 0 ? void 0 : findChildElement(body.children, "office:text");
679
+ if (textElement === void 0) throw new Error(`readOdtContent: ${CONTENT_PART$1} has no office:body/office:text element`);
680
+ const metadata = readOdfMetadata(pkg);
681
+ const masterPageElements = readOdfMasterPageElements(pkg);
682
+ const geometryByMasterPage = /* @__PURE__ */ new Map();
683
+ for (const masterPage of masterPageElements) {
684
+ const name = attrValue(masterPage, "style:name");
685
+ if (name !== void 0) geometryByMasterPage.set(name, resolveMasterPageGeometry(pkg, masterPage));
686
+ }
687
+ const firstMasterPageName = masterPageElements.map((masterPage) => attrValue(masterPage, "style:name")).find((name) => name !== void 0);
688
+ const provenanceRegions = /* @__PURE__ */ new Map();
689
+ collectOdfProvenanceRegions(textElement.children, provenanceRegions);
690
+ const definitions = {
691
+ entries: {},
692
+ nextNoteOrdinal: 1,
693
+ nextAnnotationOrdinal: 1
694
+ };
695
+ collectOdfFieldMasterDefinitions(textElement.children, definitions.entries);
696
+ for (const partPath of AUTOMATIC_STYLE_PARTS) {
697
+ const part = pkg.parts[partPath];
698
+ if (part?.kind !== "xml") continue;
699
+ collectOdfDataStyleDefinitions(part.nodes, definitions.entries);
700
+ collectOdfFontFaceDefinitions(part.nodes, definitions.entries);
701
+ }
702
+ const state = {
703
+ listIdState: { next: 1 },
704
+ provenanceRegions,
705
+ definitions,
706
+ wrapperExtents: [],
707
+ markerEvents: [],
708
+ liftFrames: options.frames !== "none",
709
+ sectionSplits: [],
710
+ masterPageByStyleName: /* @__PURE__ */ new Map(),
711
+ packageResidue: {},
712
+ masterPage: firstMasterPageName,
713
+ order: 0
714
+ };
715
+ const walked = readBlocks(textElement.children, pkg, state);
716
+ const { extents: markerExtents, paired } = resolveOdfMarkerEvents(state.markerEvents);
717
+ const extents = [...state.wrapperExtents, ...markerExtents];
718
+ for (const event of state.markerEvents) if (event.kind === "annotation" && event.side === "start" && !paired.has(event.element)) {
719
+ const descriptor = event.descriptor();
720
+ if (descriptor !== void 0) extents.push({
721
+ startIndex: event.index,
722
+ endIndex: event.index,
723
+ order: event.order,
724
+ descriptor
725
+ });
726
+ }
727
+ const { sections, masterPages } = splitOdtSections(walked, extents, state.sectionSplits, firstMasterPageName, geometryByMasterPage);
728
+ const headerFooterParts = [];
729
+ for (const masterPage of masterPageElements) {
730
+ const masterPageName = attrValue(masterPage, "style:name");
731
+ if (masterPageName === void 0) continue;
732
+ for (const child of masterPage.children) {
733
+ if (child.type !== "element") continue;
734
+ const slot = ODT_HEADER_FOOTER_TAGS.get(child.tag);
735
+ if (slot === void 0 || attrValue(child, "style:display") === "false") continue;
736
+ const blocks = readOdfConstructBodyBlocks(child, pkg, {
737
+ provenanceRegions,
738
+ definitions,
739
+ listIdState: state.listIdState,
740
+ format: "odt"
741
+ }, state.listIdState);
742
+ if (blocks.length > 0) headerFooterParts.push({
743
+ masterPage: masterPageName,
744
+ kind: slot.kind,
745
+ variant: slot.variant,
746
+ blocks
747
+ });
748
+ }
749
+ }
750
+ const packageResidue = { ...state.packageResidue };
751
+ collectOdfNonContentPartResidue(pkg, "odt", packageResidue);
752
+ return {
753
+ metadata,
754
+ sections,
755
+ ...Object.keys(definitions.entries).length > 0 ? { definitions: definitions.entries } : {},
756
+ ...headerFooterParts.length > 0 ? { headerFooterParts } : {},
757
+ ...masterPageElements.length > 0 ? { sectionMasterPages: masterPages } : {},
758
+ ...Object.keys(packageResidue).length > 0 ? { source: packageResidue } : {}
759
+ };
760
+ }
761
+ function readOdt(pkg, options = {}) {
762
+ const { metadata, sections, definitions, source } = readOdtContent(pkg, options);
763
+ const assembled = assemblePackage({
764
+ kind: "wordprocessing",
765
+ metadata,
766
+ sections
767
+ });
768
+ if (definitions !== void 0) assembled.definitions = definitions;
769
+ if (source !== void 0) assembled.source = source;
770
+ return assembled;
771
+ }
772
+ //#endregion
773
+ //#region src/typed/draw/embedded.ts
774
+ const CONTENT_PART = "content.xml";
775
+ function embeddedKindFor(bodyChildTag) {
776
+ switch (bodyChildTag) {
777
+ case "office:text": return "wordprocessing";
778
+ case "office:spreadsheet": return "spreadsheet";
779
+ case "office:presentation": return "presentation";
780
+ case "office:drawing": return "drawing";
781
+ case "office:chart": return "chart";
782
+ default: return;
783
+ }
784
+ }
785
+ function readOdfChartContent(chartPackage, frame, format) {
786
+ const contentPart = chartPackage.parts[CONTENT_PART];
787
+ const contentRoot = contentPart?.kind === "xml" ? rootElement(contentPart.nodes) : void 0;
788
+ const chartElement = contentRoot === void 0 ? void 0 : elementsWithTag(contentRoot.children, "chart:chart")[0];
789
+ const localTable = chartElement === void 0 ? void 0 : elementsWithTag(chartElement.children, "table:table")[0];
790
+ const blocks = localTable === void 0 ? [] : [readOdfTable(localTable, chartPackage)];
791
+ return {
792
+ document: {
793
+ kind: "drawing",
794
+ metadata: {},
795
+ pages: [{
796
+ size: {
797
+ widthPt: frame.widthPt,
798
+ heightPt: frame.heightPt
799
+ },
800
+ shapes: [{
801
+ frame: {
802
+ xPt: 0,
803
+ yPt: 0,
804
+ widthPt: frame.widthPt,
805
+ heightPt: frame.heightPt
806
+ },
807
+ insetLeftPt: 0,
808
+ insetTopPt: 0,
809
+ insetRightPt: 0,
810
+ insetBottomPt: 0,
811
+ blocks
812
+ }],
813
+ vectors: []
814
+ }]
815
+ },
816
+ residue: chartElement === void 0 ? void 0 : odfResidue(format, chartElement)
817
+ };
818
+ }
819
+ function readEmbeddedObjectDocument(reference, frame, format) {
820
+ switch (reference.objectKind) {
821
+ case "wordprocessing": {
822
+ const { metadata, sections } = readOdtContent(reference.package);
823
+ return {
824
+ document: {
825
+ kind: "wordprocessing",
826
+ metadata,
827
+ sections
828
+ },
829
+ residue: void 0
830
+ };
831
+ }
832
+ case "presentation": {
833
+ const { metadata, slides } = readOdpContent(reference.package);
834
+ return {
835
+ document: {
836
+ kind: "presentation",
837
+ metadata,
838
+ slides
839
+ },
840
+ residue: void 0
841
+ };
842
+ }
843
+ case "drawing": {
844
+ const { metadata, pages } = readOdgContent(reference.package);
845
+ return {
846
+ document: {
847
+ kind: "drawing",
848
+ metadata,
849
+ pages
850
+ },
851
+ residue: void 0
852
+ };
853
+ }
854
+ case "spreadsheet": {
855
+ const { metadata, sheets } = readOdsContent(reference.package);
856
+ return {
857
+ document: {
858
+ kind: "spreadsheet",
859
+ metadata,
860
+ sheets
861
+ },
862
+ residue: void 0
863
+ };
864
+ }
865
+ case "formula": return {
866
+ document: readOdfFormulaContent(reference.package),
867
+ residue: void 0
868
+ };
869
+ case "chart": return readOdfChartContent(reference.package, frame, format);
870
+ }
871
+ }
872
+ function subDocumentKind(nodes) {
873
+ const root = rootElement(nodes);
874
+ const body = root === void 0 ? void 0 : findChildElement(root.children, "office:body");
875
+ const bodyChild = body === void 0 ? void 0 : rootElement(body.children);
876
+ const bodyKind = bodyChild === void 0 ? void 0 : embeddedKindFor(bodyChild.tag);
877
+ if (bodyKind !== void 0) return bodyKind;
878
+ return findMathRoot(nodes) === void 0 ? void 0 : "formula";
879
+ }
880
+ function normaliseObjectHref(raw) {
881
+ const withoutPrefix = raw.startsWith("./") ? raw.slice(2) : raw;
882
+ const trimmed = withoutPrefix.endsWith("/") ? withoutPrefix.slice(0, -1) : withoutPrefix;
883
+ if (trimmed.length === 0 || trimmed.startsWith("..") || trimmed.startsWith("/") || trimmed.includes("://")) return;
884
+ return trimmed;
885
+ }
886
+ function readDrawObjectReference(frame, pkg) {
887
+ const object = childrenWithTag(frame, "draw:object")[0];
888
+ if (object === void 0) return;
889
+ const rawHref = attrValue(object, "xlink:href");
890
+ const href = rawHref === void 0 ? void 0 : normaliseObjectHref(rawHref);
891
+ if (href === void 0) return;
892
+ const subPackage = subDocumentPackage(pkg, href, { allowMissingContent: true });
893
+ const contentPart = subPackage.parts[CONTENT_PART];
894
+ if (contentPart?.kind !== "xml") return;
895
+ const objectKind = subDocumentKind(contentPart.nodes);
896
+ if (objectKind === void 0) return;
897
+ return {
898
+ objectKind,
899
+ package: subPackage,
900
+ href
901
+ };
902
+ }
903
+ //#endregion
904
+ export { readOdtContent as a, readOdt as i, readEmbeddedObjectDocument as n, readOds as o, readOdfChartContent as r, readOdsContent as s, readDrawObjectReference as t };