@rowsncolumns/toolkit 24.4.1 → 24.4.3

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 (131) hide show
  1. package/dist/cjs/excel-parser/cfb-decryptor.d.ts +6 -0
  2. package/dist/cjs/excel-parser/cfb-decryptor.d.ts.map +1 -1
  3. package/dist/cjs/excel-parser/cfb-decryptor.js +6 -0
  4. package/dist/cjs/excel-parser/helpers.d.ts +9 -1
  5. package/dist/cjs/excel-parser/helpers.d.ts.map +1 -1
  6. package/dist/cjs/excel-parser/helpers.js +37 -0
  7. package/dist/cjs/excel-parser/interface.d.ts +10 -1
  8. package/dist/cjs/excel-parser/interface.d.ts.map +1 -1
  9. package/dist/cjs/excel-parser/plugins/ods/index.d.ts +19 -0
  10. package/dist/cjs/excel-parser/plugins/ods/index.d.ts.map +1 -1
  11. package/dist/cjs/excel-parser/plugins/ods/index.js +676 -304
  12. package/dist/cjs/excel-parser/plugins/ods/styles.d.ts +43 -1
  13. package/dist/cjs/excel-parser/plugins/ods/styles.d.ts.map +1 -1
  14. package/dist/cjs/excel-parser/plugins/ods/styles.js +343 -45
  15. package/dist/cjs/excel-parser/plugins/xls/index.d.ts +11 -3
  16. package/dist/cjs/excel-parser/plugins/xls/index.d.ts.map +1 -1
  17. package/dist/cjs/excel-parser/plugins/xls/index.js +55 -6
  18. package/dist/cjs/excel-parser/plugins/xlsb/index.d.ts +4 -0
  19. package/dist/cjs/excel-parser/plugins/xlsb/index.d.ts.map +1 -1
  20. package/dist/cjs/excel-parser/plugins/xlsb/index.js +21 -9
  21. package/dist/cjs/excel-parser/plugins/xlsx/charts.d.ts +10 -0
  22. package/dist/cjs/excel-parser/plugins/xlsx/charts.d.ts.map +1 -1
  23. package/dist/cjs/excel-parser/plugins/xlsx/charts.js +68 -9
  24. package/dist/cjs/excel-parser/plugins/xlsx/drawing.d.ts +28 -1
  25. package/dist/cjs/excel-parser/plugins/xlsx/drawing.d.ts.map +1 -1
  26. package/dist/cjs/excel-parser/plugins/xlsx/drawing.js +155 -20
  27. package/dist/cjs/excel-parser/plugins/xlsx/index.d.ts +26 -1
  28. package/dist/cjs/excel-parser/plugins/xlsx/index.d.ts.map +1 -1
  29. package/dist/cjs/excel-parser/plugins/xlsx/index.js +567 -234
  30. package/dist/cjs/excel-parser/plugins/xlsx/pivots.d.ts.map +1 -1
  31. package/dist/cjs/excel-parser/plugins/xlsx/pivots.js +125 -37
  32. package/dist/cjs/excel-parser/plugins/xlsx/sheet-views.d.ts +3 -0
  33. package/dist/cjs/excel-parser/plugins/xlsx/sheet-views.d.ts.map +1 -1
  34. package/dist/cjs/excel-parser/plugins/xlsx/sheet-views.js +4 -1
  35. package/dist/cjs/excel-parser/plugins/xlsx/styles.d.ts.map +1 -1
  36. package/dist/cjs/excel-parser/plugins/xlsx/styles.js +12 -2
  37. package/dist/cjs/excel-parser/registry.d.ts.map +1 -1
  38. package/dist/cjs/excel-parser/registry.js +2 -0
  39. package/dist/cjs/excel-parser/types.d.ts +7 -1
  40. package/dist/cjs/excel-parser/types.d.ts.map +1 -1
  41. package/dist/cjs/excel-parser/workbook.d.ts +1 -0
  42. package/dist/cjs/excel-parser/workbook.d.ts.map +1 -1
  43. package/dist/cjs/excel-parser/workbook.js +4 -0
  44. package/dist/cjs/excel-parser/worker.js +3 -1
  45. package/dist/cjs/exporter/ods/ods-export.d.ts.map +1 -1
  46. package/dist/cjs/exporter/ods/ods-export.js +432 -175
  47. package/dist/cjs/exporter/xlsx/chart-builder.d.ts.map +1 -1
  48. package/dist/cjs/exporter/xlsx/chart-builder.js +210 -6
  49. package/dist/cjs/exporter/xlsx/pivot-builder.d.ts +8 -0
  50. package/dist/cjs/exporter/xlsx/pivot-builder.d.ts.map +1 -1
  51. package/dist/cjs/exporter/xlsx/pivot-builder.js +141 -42
  52. package/dist/cjs/exporter/xlsx/style-builder.js +9 -3
  53. package/dist/cjs/exporter/xlsx/threaded-comments-builder.d.ts +7 -1
  54. package/dist/cjs/exporter/xlsx/threaded-comments-builder.d.ts.map +1 -1
  55. package/dist/cjs/exporter/xlsx/threaded-comments-builder.js +15 -3
  56. package/dist/cjs/exporter/xlsx/xlsx-export.d.ts +11 -2
  57. package/dist/cjs/exporter/xlsx/xlsx-export.d.ts.map +1 -1
  58. package/dist/cjs/exporter/xlsx/xlsx-export.js +678 -222
  59. package/dist/cjs/helpers/implicit-intersection.d.ts +16 -0
  60. package/dist/cjs/helpers/implicit-intersection.d.ts.map +1 -0
  61. package/dist/cjs/helpers/implicit-intersection.js +197 -0
  62. package/dist/cjs/print-settings.d.ts +105 -0
  63. package/dist/cjs/print-settings.d.ts.map +1 -0
  64. package/dist/cjs/print-settings.js +494 -0
  65. package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
  66. package/dist/esm/excel-parser/cfb-decryptor.d.ts +6 -0
  67. package/dist/esm/excel-parser/cfb-decryptor.d.ts.map +1 -1
  68. package/dist/esm/excel-parser/cfb-decryptor.js +6 -0
  69. package/dist/esm/excel-parser/helpers.d.ts +9 -1
  70. package/dist/esm/excel-parser/helpers.d.ts.map +1 -1
  71. package/dist/esm/excel-parser/helpers.js +34 -0
  72. package/dist/esm/excel-parser/interface.d.ts +10 -1
  73. package/dist/esm/excel-parser/interface.d.ts.map +1 -1
  74. package/dist/esm/excel-parser/plugins/ods/index.d.ts +19 -0
  75. package/dist/esm/excel-parser/plugins/ods/index.d.ts.map +1 -1
  76. package/dist/esm/excel-parser/plugins/ods/index.js +347 -33
  77. package/dist/esm/excel-parser/plugins/ods/styles.d.ts +43 -1
  78. package/dist/esm/excel-parser/plugins/ods/styles.d.ts.map +1 -1
  79. package/dist/esm/excel-parser/plugins/ods/styles.js +276 -2
  80. package/dist/esm/excel-parser/plugins/xls/index.d.ts +11 -3
  81. package/dist/esm/excel-parser/plugins/xls/index.d.ts.map +1 -1
  82. package/dist/esm/excel-parser/plugins/xls/index.js +37 -5
  83. package/dist/esm/excel-parser/plugins/xlsb/index.d.ts +4 -0
  84. package/dist/esm/excel-parser/plugins/xlsb/index.d.ts.map +1 -1
  85. package/dist/esm/excel-parser/plugins/xlsb/index.js +20 -6
  86. package/dist/esm/excel-parser/plugins/xlsx/charts.d.ts +10 -0
  87. package/dist/esm/excel-parser/plugins/xlsx/charts.d.ts.map +1 -1
  88. package/dist/esm/excel-parser/plugins/xlsx/charts.js +69 -6
  89. package/dist/esm/excel-parser/plugins/xlsx/drawing.d.ts +28 -1
  90. package/dist/esm/excel-parser/plugins/xlsx/drawing.d.ts.map +1 -1
  91. package/dist/esm/excel-parser/plugins/xlsx/drawing.js +99 -0
  92. package/dist/esm/excel-parser/plugins/xlsx/index.d.ts +26 -1
  93. package/dist/esm/excel-parser/plugins/xlsx/index.d.ts.map +1 -1
  94. package/dist/esm/excel-parser/plugins/xlsx/index.js +362 -26
  95. package/dist/esm/excel-parser/plugins/xlsx/pivots.d.ts.map +1 -1
  96. package/dist/esm/excel-parser/plugins/xlsx/pivots.js +86 -6
  97. package/dist/esm/excel-parser/plugins/xlsx/sheet-views.d.ts +3 -0
  98. package/dist/esm/excel-parser/plugins/xlsx/sheet-views.d.ts.map +1 -1
  99. package/dist/esm/excel-parser/plugins/xlsx/sheet-views.js +2 -0
  100. package/dist/esm/excel-parser/plugins/xlsx/styles.d.ts.map +1 -1
  101. package/dist/esm/excel-parser/plugins/xlsx/styles.js +12 -2
  102. package/dist/esm/excel-parser/registry.d.ts.map +1 -1
  103. package/dist/esm/excel-parser/registry.js +2 -0
  104. package/dist/esm/excel-parser/types.d.ts +7 -1
  105. package/dist/esm/excel-parser/types.d.ts.map +1 -1
  106. package/dist/esm/excel-parser/workbook.d.ts +1 -0
  107. package/dist/esm/excel-parser/workbook.d.ts.map +1 -1
  108. package/dist/esm/excel-parser/workbook.js +3 -0
  109. package/dist/esm/excel-parser/worker.js +2 -0
  110. package/dist/esm/exporter/ods/ods-export.d.ts.map +1 -1
  111. package/dist/esm/exporter/ods/ods-export.js +306 -35
  112. package/dist/esm/exporter/xlsx/chart-builder.d.ts.map +1 -1
  113. package/dist/esm/exporter/xlsx/chart-builder.js +161 -0
  114. package/dist/esm/exporter/xlsx/pivot-builder.d.ts +8 -0
  115. package/dist/esm/exporter/xlsx/pivot-builder.d.ts.map +1 -1
  116. package/dist/esm/exporter/xlsx/pivot-builder.js +104 -19
  117. package/dist/esm/exporter/xlsx/style-builder.js +9 -3
  118. package/dist/esm/exporter/xlsx/threaded-comments-builder.d.ts +7 -1
  119. package/dist/esm/exporter/xlsx/threaded-comments-builder.d.ts.map +1 -1
  120. package/dist/esm/exporter/xlsx/threaded-comments-builder.js +15 -3
  121. package/dist/esm/exporter/xlsx/xlsx-export.d.ts +11 -2
  122. package/dist/esm/exporter/xlsx/xlsx-export.d.ts.map +1 -1
  123. package/dist/esm/exporter/xlsx/xlsx-export.js +449 -47
  124. package/dist/esm/helpers/implicit-intersection.d.ts +16 -0
  125. package/dist/esm/helpers/implicit-intersection.d.ts.map +1 -0
  126. package/dist/esm/helpers/implicit-intersection.js +184 -0
  127. package/dist/esm/print-settings.d.ts +105 -0
  128. package/dist/esm/print-settings.d.ts.map +1 -0
  129. package/dist/esm/print-settings.js +422 -0
  130. package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
  131. package/package.json +3 -3
@@ -1,4 +1,4 @@
1
- import { __assign, __asyncGenerator, __await, __awaiter, __extends, __generator, __read, __spreadArray, __values } from "tslib";
1
+ import { __assign, __asyncGenerator, __await, __awaiter, __extends, __generator, __read, __rest, __spreadArray, __values } from "tslib";
2
2
  import { addressToCell, cellToAddress, getCellXfsKey, uuid, } from "@rowsncolumns/utils";
3
3
  import { XMLParser } from "fast-xml-parser";
4
4
  import { get } from "lodash-es";
@@ -12,6 +12,7 @@ import { extractDataValidations } from "./data-validations";
12
12
  import { convertOdsFormulaToExcel } from "./formula";
13
13
  import { extractSparklines, extractSparklineData, } from "./sparklines";
14
14
  import { OdsStyles } from "./styles";
15
+ import { compactPrintSettings } from "../../../print-settings";
15
16
  var ODS_XML_OPTIONS = {
16
17
  ignoreAttributes: false,
17
18
  attributeNamePrefix: "@_",
@@ -46,8 +47,159 @@ function getAttribute(node, attributeName) {
46
47
  }
47
48
  return undefined;
48
49
  }
49
- function fastMergeCellFormats() {
50
+ var ROW_WRAPPER_TAGS = [
51
+ "table:table-row-group",
52
+ "table:table-header-rows",
53
+ "table:table-rows",
54
+ "table-row-group",
55
+ "table-header-rows",
56
+ "table-rows",
57
+ ];
58
+ var COLUMN_WRAPPER_TAGS = [
59
+ "table:table-column-group",
60
+ "table:table-header-columns",
61
+ "table:table-columns",
62
+ "table-column-group",
63
+ "table-header-columns",
64
+ "table-columns",
65
+ ];
66
+ /**
67
+ * Order-preserving `<table:table>` children → the `<table:table-row>` nodes in
68
+ * document order, descending into `<table:table-row-group>` (outline),
69
+ * `<table:table-header-rows>` (print titles) and `<table:table-rows>`
70
+ * wrappers. Rows inside a wrapper are ordinary rows for cell data, merges,
71
+ * metadata and positions.
72
+ */
73
+ function flattenOrderedRows(children) {
50
74
  var e_1, _a;
75
+ var rows = [];
76
+ var _loop_1 = function (child) {
77
+ if (!child || typeof child !== "object")
78
+ return "continue";
79
+ if (child["table:table-row"] || child["table-row"]) {
80
+ rows.push(child);
81
+ return "continue";
82
+ }
83
+ var wrapper = ROW_WRAPPER_TAGS.find(function (tag) { return child[tag]; });
84
+ if (wrapper)
85
+ rows.push.apply(rows, __spreadArray([], __read(flattenOrderedRows(child[wrapper])), false));
86
+ };
87
+ try {
88
+ for (var _b = __values(children !== null && children !== void 0 ? children : []), _c = _b.next(); !_c.done; _c = _b.next()) {
89
+ var child = _c.value;
90
+ _loop_1(child);
91
+ }
92
+ }
93
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
94
+ finally {
95
+ try {
96
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
97
+ }
98
+ finally { if (e_1) throw e_1.error; }
99
+ }
100
+ return rows;
101
+ }
102
+ /** Column counterpart of {@link flattenOrderedRows}. */
103
+ function flattenOrderedColumns(children) {
104
+ var e_2, _a;
105
+ var columns = [];
106
+ var _loop_2 = function (child) {
107
+ if (!child || typeof child !== "object")
108
+ return "continue";
109
+ if (child["table:table-column"] || child["table-column"]) {
110
+ columns.push(child);
111
+ return "continue";
112
+ }
113
+ var wrapper = COLUMN_WRAPPER_TAGS.find(function (tag) { return child[tag]; });
114
+ if (wrapper)
115
+ columns.push.apply(columns, __spreadArray([], __read(flattenOrderedColumns(child[wrapper])), false));
116
+ };
117
+ try {
118
+ for (var _b = __values(children !== null && children !== void 0 ? children : []), _c = _b.next(); !_c.done; _c = _b.next()) {
119
+ var child = _c.value;
120
+ _loop_2(child);
121
+ }
122
+ }
123
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
124
+ finally {
125
+ try {
126
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
127
+ }
128
+ finally { if (e_2) throw e_2.error; }
129
+ }
130
+ return columns;
131
+ }
132
+ /**
133
+ * The 1-based band covered by the `<table:table-header-rows>` /
134
+ * `<table:table-header-columns>` wrappers (ODS print titles), or undefined.
135
+ * A band that straddles an outline-group edge is written as several
136
+ * wrappers (ODF forbids a group inside header rows; LibreOffice closes and
137
+ * re-opens the wrapper around the group), so the segments are unioned back
138
+ * into one band — the same rule LibreOffice applies on import.
139
+ */
140
+ function findOrderedHeaderBand(children, axis) {
141
+ var itemTags = axis === "row"
142
+ ? ["table:table-row", "table-row"]
143
+ : ["table:table-column", "table-column"];
144
+ var headerTags = axis === "row"
145
+ ? ["table:table-header-rows", "table-header-rows"]
146
+ : ["table:table-header-columns", "table-header-columns"];
147
+ var wrapperTags = axis === "row" ? ROW_WRAPPER_TAGS : COLUMN_WRAPPER_TAGS;
148
+ var repeatAttr = axis === "row" ? "table:number-rows-repeated" : "table:number-columns-repeated";
149
+ var flatten = axis === "row" ? flattenOrderedRows : flattenOrderedColumns;
150
+ var countItems = function (nodes) {
151
+ return flatten(nodes).reduce(function (total, node) {
152
+ var _a;
153
+ var repeated = parseInt((_a = getAttribute(node, repeatAttr)) !== null && _a !== void 0 ? _a : "1", 10);
154
+ return total + (Number.isFinite(repeated) && repeated > 0 ? repeated : 1);
155
+ }, 0);
156
+ };
157
+ var position = 1;
158
+ var band;
159
+ var visit = function (nodes) {
160
+ var e_3, _a;
161
+ var _loop_3 = function (child) {
162
+ if (!child || typeof child !== "object")
163
+ return "continue";
164
+ if (itemTags.some(function (tag) { return child[tag]; })) {
165
+ position += countItems([child]);
166
+ return "continue";
167
+ }
168
+ var header = headerTags.find(function (tag) { return child[tag]; });
169
+ if (header) {
170
+ var count = countItems(child[header]);
171
+ if (count) {
172
+ var end = position + count - 1;
173
+ band = band
174
+ ? { start: Math.min(band.start, position), end: Math.max(band.end, end) }
175
+ : { start: position, end: end };
176
+ position = end + 1;
177
+ }
178
+ return "continue";
179
+ }
180
+ var wrapper = wrapperTags.find(function (tag) { return child[tag]; });
181
+ if (wrapper)
182
+ visit(child[wrapper]);
183
+ };
184
+ try {
185
+ for (var _b = __values(nodes !== null && nodes !== void 0 ? nodes : []), _c = _b.next(); !_c.done; _c = _b.next()) {
186
+ var child = _c.value;
187
+ _loop_3(child);
188
+ }
189
+ }
190
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
191
+ finally {
192
+ try {
193
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
194
+ }
195
+ finally { if (e_3) throw e_3.error; }
196
+ }
197
+ };
198
+ visit(children);
199
+ return band;
200
+ }
201
+ function fastMergeCellFormats() {
202
+ var e_4, _a;
51
203
  var formats = [];
52
204
  for (var _i = 0; _i < arguments.length; _i++) {
53
205
  formats[_i] = arguments[_i];
@@ -97,12 +249,12 @@ function fastMergeCellFormats() {
97
249
  }
98
250
  }
99
251
  }
100
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
252
+ catch (e_4_1) { e_4 = { error: e_4_1 }; }
101
253
  finally {
102
254
  try {
103
255
  if (formats_1_1 && !formats_1_1.done && (_a = formats_1.return)) _a.call(formats_1);
104
256
  }
105
- finally { if (e_1) throw e_1.error; }
257
+ finally { if (e_4) throw e_4.error; }
106
258
  }
107
259
  return result;
108
260
  }
@@ -182,10 +334,20 @@ var OdsPlugin = /** @class */ (function (_super) {
182
334
  if (styles) {
183
335
  parsedStyles = this.xmlParser.parse(styles);
184
336
  this.odsStyles.parseStylesXml(parsedStyles);
337
+ // Master pages carry mixed-content header/footer paragraphs
338
+ // (`Page <text:page-number/> of …`), so they are read from an
339
+ // order-preserving parse that also keeps the significant spaces
340
+ // around the fields and leaves the text verbatim (a `+1` after the
341
+ // page number is header text, not the number 1).
342
+ this.odsStyles.parseMasterPagesOrdered(new XMLParser(__assign(__assign({}, ODS_ORDERED_XML_OPTIONS), { trimValues: false, parseTagValue: false })).parse(styles));
185
343
  }
186
- settings = this.zipParser.Get("settings.xml");
187
- if (settings) {
188
- this.settingsXml = this.xmlParser.parse(settings);
344
+ // settings.xml is optional in ODF (our own exporter omits it when no
345
+ // sheet has view settings); `Get` throws on a missing part.
346
+ if (this.zipParser.Has("settings.xml")) {
347
+ settings = this.zipParser.Get("settings.xml");
348
+ if (settings) {
349
+ this.settingsXml = this.xmlParser.parse(settings);
350
+ }
189
351
  }
190
352
  }
191
353
  catch (e) {
@@ -254,20 +416,32 @@ var OdsPlugin = /** @class */ (function (_super) {
254
416
  return cache;
255
417
  };
256
418
  OdsPlugin.prototype.buildSheetCache = function () {
257
- var e_2, _a;
419
+ var e_5, _a;
258
420
  var _this = this;
259
421
  var _b, _c;
260
422
  var tables = this.getTables();
423
+ var orderedTables = this.getOrderedTableWrappers();
261
424
  var sheets = [];
262
425
  var sheetContexts = [];
426
+ // `table:print-ranges` per sheet, resolved once the sheet-name map exists.
427
+ var printRangesBySheetId = new Map();
263
428
  tables.forEach(function (table, index) {
264
- var e_3, _a, e_4, _b;
265
- var _c, _d, _e, _f;
429
+ var e_6, _a, e_7, _b;
430
+ var _c, _d, _e, _f, _g;
266
431
  var name = table["@_table:name"] ||
267
432
  table["@_name"] ||
268
433
  table["table:name"] ||
269
434
  table["name"] ||
270
435
  "Sheet".concat(index + 1);
436
+ // Order-preserving children of the same table: rows/columns nested in
437
+ // `<table:table-header-rows>` / `<table:table-row-group>` only appear in
438
+ // document order there.
439
+ var orderedTable = orderedTables[index];
440
+ var orderedTableChildren = orderedTable
441
+ ? orderedTable[orderedTable["table:table"] ? "table:table" : "table"]
442
+ : undefined;
443
+ var rowBreaks = [];
444
+ var columnBreaks = [];
271
445
  var sheet = {
272
446
  sheetId: index + 1,
273
447
  title: name,
@@ -278,13 +452,27 @@ var OdsPlugin = /** @class */ (function (_super) {
278
452
  columnMetadata: [],
279
453
  merges: [],
280
454
  };
455
+ // `table:protected="true"` is ODF's sheet-protection switch. The
456
+ // `table:protection-key` digest is not an OOXML hash, so only the master
457
+ // flag is modeled — the key itself cannot round-trip into `<sheetProtection>`.
458
+ var protectedAttr = (_e = table["@_table:protected"]) !== null && _e !== void 0 ? _e : table["table:protected"];
459
+ if (protectedAttr === "true" || protectedAttr === true) {
460
+ sheet.sheetProtection = { sheet: true };
461
+ }
462
+ // Right-to-left sheets live on the table style's `style:writing-mode`
463
+ // (the ODF counterpart of `<sheetView rightToLeft="1">`).
464
+ if (_this.odsStyles.isTableStyleRightToLeft(table["@_table:style-name"] || table["table:style-name"])) {
465
+ sheet.rightToLeft = true;
466
+ }
281
467
  // Column metadata from table-column elements
282
468
  var columnNodes = get(table, "table:table-column") || get(table, "table-column") || [];
283
- var allColumns = Array.isArray(columnNodes)
284
- ? columnNodes
285
- : columnNodes
286
- ? [columnNodes]
287
- : [];
469
+ var allColumns = orderedTableChildren
470
+ ? flattenOrderedColumns(orderedTableChildren)
471
+ : Array.isArray(columnNodes)
472
+ ? columnNodes
473
+ : columnNodes
474
+ ? [columnNodes]
475
+ : [];
288
476
  var currentColumnIndex = 1;
289
477
  var detectedColumnCount = 0;
290
478
  var defaultColumnWidth;
@@ -309,6 +497,10 @@ var OdsPlugin = /** @class */ (function (_super) {
309
497
  visibility === "hidden" ||
310
498
  visibility === "none" ||
311
499
  (columnStyle === null || columnStyle === void 0 ? void 0 : columnStyle.hidden);
500
+ // `fo:break-before="page"` on column N = a manual break after N-1.
501
+ if ((columnStyle === null || columnStyle === void 0 ? void 0 : columnStyle.breakBefore) && currentColumnIndex > 1) {
502
+ columnBreaks.push(currentColumnIndex - 1);
503
+ }
312
504
  for (var c = 0; c < colsRepeated; c++) {
313
505
  var props = {};
314
506
  var shouldAssign = false;
@@ -341,16 +533,20 @@ var OdsPlugin = /** @class */ (function (_super) {
341
533
  detectedColumnCount = Math.max(detectedColumnCount, currentColumnIndex - 1);
342
534
  }
343
535
  }
344
- catch (e_3_1) { e_3 = { error: e_3_1 }; }
536
+ catch (e_6_1) { e_6 = { error: e_6_1 }; }
345
537
  finally {
346
538
  try {
347
539
  if (allColumns_1_1 && !allColumns_1_1.done && (_a = allColumns_1.return)) _a.call(allColumns_1);
348
540
  }
349
- finally { if (e_3) throw e_3.error; }
541
+ finally { if (e_6) throw e_6.error; }
350
542
  }
351
543
  // Row metadata from table-row elements
352
544
  var rowNodes = get(table, "table:table-row") || get(table, "table-row") || [];
353
- var allRows = Array.isArray(rowNodes) ? rowNodes : [rowNodes];
545
+ var allRows = orderedTableChildren
546
+ ? flattenOrderedRows(orderedTableChildren)
547
+ : Array.isArray(rowNodes)
548
+ ? rowNodes
549
+ : [rowNodes];
354
550
  // DO NOT DELETE
355
551
  // console.log("allRows", allRows);
356
552
  var currentRowIndex = 1;
@@ -378,6 +574,10 @@ var OdsPlugin = /** @class */ (function (_super) {
378
574
  visibility === "none" ||
379
575
  (rowStyle === null || rowStyle === void 0 ? void 0 : rowStyle.hidden);
380
576
  var effectiveRepeats = Math.min(rowsRepeated, 10000);
577
+ // `fo:break-before="page"` on row N = a manual break after N-1.
578
+ if ((rowStyle === null || rowStyle === void 0 ? void 0 : rowStyle.breakBefore) && currentRowIndex > 1) {
579
+ rowBreaks.push(currentRowIndex - 1);
580
+ }
381
581
  var shouldProcessRowMetadata = typeof height === "number" || isHidden;
382
582
  if (!shouldProcessRowMetadata) {
383
583
  currentRowIndex += effectiveRepeats;
@@ -416,18 +616,57 @@ var OdsPlugin = /** @class */ (function (_super) {
416
616
  detectedRowCount = Math.max(detectedRowCount, currentRowIndex - 1);
417
617
  }
418
618
  }
419
- catch (e_4_1) { e_4 = { error: e_4_1 }; }
619
+ catch (e_7_1) { e_7 = { error: e_7_1 }; }
420
620
  finally {
421
621
  try {
422
622
  if (allRows_1_1 && !allRows_1_1.done && (_b = allRows_1.return)) _b.call(allRows_1);
423
623
  }
424
- finally { if (e_4) throw e_4.error; }
624
+ finally { if (e_7) throw e_7.error; }
425
625
  }
426
626
  if (detectedRowCount > 0) {
427
- sheet.rowCount = Math.max((_e = sheet.rowCount) !== null && _e !== void 0 ? _e : 0, detectedRowCount);
627
+ sheet.rowCount = Math.max((_f = sheet.rowCount) !== null && _f !== void 0 ? _f : 0, detectedRowCount);
428
628
  }
429
629
  if (detectedColumnCount > 0) {
430
- sheet.columnCount = Math.max((_f = sheet.columnCount) !== null && _f !== void 0 ? _f : 0, detectedColumnCount);
630
+ sheet.columnCount = Math.max((_g = sheet.columnCount) !== null && _g !== void 0 ? _g : 0, detectedColumnCount);
631
+ }
632
+ // Print settings: the table style's master page (page layout +
633
+ // header/footer), manual breaks, and the header-rows/columns bands
634
+ // (print titles). `table:print-ranges` is resolved below.
635
+ var tableStyleName = table["@_table:style-name"] || table["table:style-name"];
636
+ var masterPageName = tableStyleName
637
+ ? _this.odsStyles.getTableMasterPageName(tableStyleName)
638
+ : undefined;
639
+ var masterPage = masterPageName
640
+ ? _this.odsStyles.getMasterPage(masterPageName)
641
+ : undefined;
642
+ var pageLayout = (masterPage === null || masterPage === void 0 ? void 0 : masterPage.pageLayoutName)
643
+ ? _this.odsStyles.getPageLayout(masterPage.pageLayoutName)
644
+ : undefined;
645
+ var headerRows = findOrderedHeaderBand(orderedTableChildren, "row");
646
+ var headerColumns = findOrderedHeaderBand(orderedTableChildren, "column");
647
+ var printSettings = compactPrintSettings({
648
+ pageSetup: pageLayout === null || pageLayout === void 0 ? void 0 : pageLayout.pageSetup,
649
+ pageMargins: pageLayout === null || pageLayout === void 0 ? void 0 : pageLayout.pageMargins,
650
+ printOptions: pageLayout === null || pageLayout === void 0 ? void 0 : pageLayout.printOptions,
651
+ headerFooter: (masterPage === null || masterPage === void 0 ? void 0 : masterPage.header) || (masterPage === null || masterPage === void 0 ? void 0 : masterPage.footer)
652
+ ? __assign(__assign({}, (masterPage.header ? { oddHeader: masterPage.header } : {})), (masterPage.footer ? { oddFooter: masterPage.footer } : {})) : undefined,
653
+ printTitles: headerRows || headerColumns
654
+ ? __assign(__assign({}, (headerRows
655
+ ? { rowStart: headerRows.start, rowEnd: headerRows.end }
656
+ : {})), (headerColumns
657
+ ? {
658
+ columnStart: headerColumns.start,
659
+ columnEnd: headerColumns.end,
660
+ }
661
+ : {})) : undefined,
662
+ rowBreaks: rowBreaks,
663
+ columnBreaks: columnBreaks,
664
+ });
665
+ if (printSettings)
666
+ sheet.printSettings = printSettings;
667
+ var printRanges = table["@_table:print-ranges"] || table["table:print-ranges"];
668
+ if (typeof printRanges === "string" && printRanges.trim()) {
669
+ printRangesBySheetId.set(sheet.sheetId, printRanges);
431
670
  }
432
671
  sheets.push(sheet);
433
672
  sheetContexts.push({ node: table, sheetId: sheet.sheetId, name: name });
@@ -469,37 +708,54 @@ var OdsPlugin = /** @class */ (function (_super) {
469
708
  this.extractOutlineGroups(sheets);
470
709
  var sheetSettings = this.extractSheetSettings(sheetContexts);
471
710
  var basicFilters = this.extractBasicFilters(sheetContexts, sheetNameMap, spreadsheetNode);
711
+ var _loop_4 = function (sheet) {
712
+ sheet.merges = (_c = (_b = mergesMap.get(sheet.sheetId)) !== null && _b !== void 0 ? _b : sheet.merges) !== null && _c !== void 0 ? _c : [];
713
+ var printRanges = printRangesBySheetId.get(sheet.sheetId);
714
+ if (printRanges) {
715
+ var context = sheetContexts.find(function (c) { return c.sheetId === sheet.sheetId; });
716
+ var printArea = this_1.parseRangeList(printRanges, sheetNameMap, context)
717
+ .filter(function (range) { return range.sheetId === sheet.sheetId; })
718
+ .map(function (_a) {
719
+ var _sheetId = _a.sheetId, range = __rest(_a, ["sheetId"]);
720
+ return range;
721
+ });
722
+ if (printArea.length) {
723
+ sheet.printSettings = __assign(__assign({}, sheet.printSettings), { printArea: printArea });
724
+ }
725
+ }
726
+ var settings = sheetSettings.get(sheet.sheetId);
727
+ if (settings) {
728
+ if (settings.frozenRowCount !== undefined) {
729
+ sheet.frozenRowCount = settings.frozenRowCount;
730
+ }
731
+ if (settings.frozenColumnCount !== undefined) {
732
+ sheet.frozenColumnCount = settings.frozenColumnCount;
733
+ }
734
+ if (settings.showGridLines !== undefined) {
735
+ sheet.showGridLines = settings.showGridLines;
736
+ }
737
+ if (settings.tabColor) {
738
+ sheet.tabColor = settings.tabColor;
739
+ }
740
+ }
741
+ var filter = basicFilters.get(sheet.sheetId);
742
+ if (filter) {
743
+ sheet.basicFilter = filter;
744
+ }
745
+ };
746
+ var this_1 = this;
472
747
  try {
473
748
  for (var sheets_1 = __values(sheets), sheets_1_1 = sheets_1.next(); !sheets_1_1.done; sheets_1_1 = sheets_1.next()) {
474
749
  var sheet = sheets_1_1.value;
475
- sheet.merges = (_c = (_b = mergesMap.get(sheet.sheetId)) !== null && _b !== void 0 ? _b : sheet.merges) !== null && _c !== void 0 ? _c : [];
476
- var settings = sheetSettings.get(sheet.sheetId);
477
- if (settings) {
478
- if (settings.frozenRowCount !== undefined) {
479
- sheet.frozenRowCount = settings.frozenRowCount;
480
- }
481
- if (settings.frozenColumnCount !== undefined) {
482
- sheet.frozenColumnCount = settings.frozenColumnCount;
483
- }
484
- if (settings.showGridLines !== undefined) {
485
- sheet.showGridLines = settings.showGridLines;
486
- }
487
- if (settings.tabColor) {
488
- sheet.tabColor = settings.tabColor;
489
- }
490
- }
491
- var filter = basicFilters.get(sheet.sheetId);
492
- if (filter) {
493
- sheet.basicFilter = filter;
494
- }
750
+ _loop_4(sheet);
495
751
  }
496
752
  }
497
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
753
+ catch (e_5_1) { e_5 = { error: e_5_1 }; }
498
754
  finally {
499
755
  try {
500
756
  if (sheets_1_1 && !sheets_1_1.done && (_a = sheets_1.return)) _a.call(sheets_1);
501
757
  }
502
- finally { if (e_2) throw e_2.error; }
758
+ finally { if (e_5) throw e_5.error; }
503
759
  }
504
760
  return {
505
761
  sheets: sheets,
@@ -512,7 +768,7 @@ var OdsPlugin = /** @class */ (function (_super) {
512
768
  };
513
769
  };
514
770
  OdsPlugin.prototype.extractTableViews = function (sheetContexts) {
515
- var e_5, _a, e_6, _b, e_7, _c;
771
+ var e_8, _a, e_9, _b, e_10, _c;
516
772
  if (!sheetContexts.length)
517
773
  return [];
518
774
  var spreadsheet = this.getSpreadsheetNode();
@@ -531,12 +787,12 @@ var OdsPlugin = /** @class */ (function (_super) {
531
787
  }
532
788
  }
533
789
  }
534
- catch (e_5_1) { e_5 = { error: e_5_1 }; }
790
+ catch (e_8_1) { e_8 = { error: e_8_1 }; }
535
791
  finally {
536
792
  try {
537
793
  if (globalRanges_1_1 && !globalRanges_1_1.done && (_a = globalRanges_1.return)) _a.call(globalRanges_1);
538
794
  }
539
- finally { if (e_5) throw e_5.error; }
795
+ finally { if (e_8) throw e_8.error; }
540
796
  }
541
797
  try {
542
798
  for (var sheetContexts_1 = __values(sheetContexts), sheetContexts_1_1 = sheetContexts_1.next(); !sheetContexts_1_1.done; sheetContexts_1_1 = sheetContexts_1.next()) {
@@ -544,7 +800,7 @@ var OdsPlugin = /** @class */ (function (_super) {
544
800
  var inlineRanges = this.toArray(get(context.node, "table:database-range") ||
545
801
  get(context.node, "database-range"));
546
802
  try {
547
- for (var inlineRanges_1 = (e_7 = void 0, __values(inlineRanges)), inlineRanges_1_1 = inlineRanges_1.next(); !inlineRanges_1_1.done; inlineRanges_1_1 = inlineRanges_1.next()) {
803
+ for (var inlineRanges_1 = (e_10 = void 0, __values(inlineRanges)), inlineRanges_1_1 = inlineRanges_1.next(); !inlineRanges_1_1.done; inlineRanges_1_1 = inlineRanges_1.next()) {
548
804
  var node = inlineRanges_1_1.value;
549
805
  var tableView = this.convertDatabaseRangeNode(node, sheetNameMap, context, sheetContexts);
550
806
  if (tableView) {
@@ -552,21 +808,21 @@ var OdsPlugin = /** @class */ (function (_super) {
552
808
  }
553
809
  }
554
810
  }
555
- catch (e_7_1) { e_7 = { error: e_7_1 }; }
811
+ catch (e_10_1) { e_10 = { error: e_10_1 }; }
556
812
  finally {
557
813
  try {
558
814
  if (inlineRanges_1_1 && !inlineRanges_1_1.done && (_c = inlineRanges_1.return)) _c.call(inlineRanges_1);
559
815
  }
560
- finally { if (e_7) throw e_7.error; }
816
+ finally { if (e_10) throw e_10.error; }
561
817
  }
562
818
  }
563
819
  }
564
- catch (e_6_1) { e_6 = { error: e_6_1 }; }
820
+ catch (e_9_1) { e_9 = { error: e_9_1 }; }
565
821
  finally {
566
822
  try {
567
823
  if (sheetContexts_1_1 && !sheetContexts_1_1.done && (_b = sheetContexts_1.return)) _b.call(sheetContexts_1);
568
824
  }
569
- finally { if (e_6) throw e_6.error; }
825
+ finally { if (e_9) throw e_9.error; }
570
826
  }
571
827
  return tableViews;
572
828
  };
@@ -620,7 +876,7 @@ var OdsPlugin = /** @class */ (function (_super) {
620
876
  return tableView;
621
877
  };
622
878
  OdsPlugin.prototype.extractNamedRanges = function (sheetContexts) {
623
- var e_8, _a, e_9, _b, e_10, _c;
879
+ var e_11, _a, e_12, _b, e_13, _c;
624
880
  var _this = this;
625
881
  var spreadsheet = this.getSpreadsheetNode();
626
882
  if (!spreadsheet)
@@ -628,7 +884,7 @@ var OdsPlugin = /** @class */ (function (_super) {
628
884
  var sheetNameMap = this.buildSheetNameMap(sheetContexts);
629
885
  var namedRanges = [];
630
886
  var processContainer = function (container, context) {
631
- var e_11, _a, e_12, _b, e_13, _c;
887
+ var e_14, _a, e_15, _b, e_16, _c;
632
888
  if (!container)
633
889
  return;
634
890
  var rangeNodes = _this.toArray(get(container, "table:named-range") || get(container, "named-range"));
@@ -649,7 +905,7 @@ var OdsPlugin = /** @class */ (function (_super) {
649
905
  attrs["@_base-cell-address"];
650
906
  var ranges = _this.parseRangeList(addressAttr, sheetNameMap, context);
651
907
  try {
652
- for (var ranges_1 = (e_12 = void 0, __values(ranges)), ranges_1_1 = ranges_1.next(); !ranges_1_1.done; ranges_1_1 = ranges_1.next()) {
908
+ for (var ranges_1 = (e_15 = void 0, __values(ranges)), ranges_1_1 = ranges_1.next(); !ranges_1_1.done; ranges_1_1 = ranges_1.next()) {
653
909
  var range = ranges_1_1.value;
654
910
  namedRanges.push({
655
911
  namedRangeId: uuid(),
@@ -658,21 +914,21 @@ var OdsPlugin = /** @class */ (function (_super) {
658
914
  });
659
915
  }
660
916
  }
661
- catch (e_12_1) { e_12 = { error: e_12_1 }; }
917
+ catch (e_15_1) { e_15 = { error: e_15_1 }; }
662
918
  finally {
663
919
  try {
664
920
  if (ranges_1_1 && !ranges_1_1.done && (_b = ranges_1.return)) _b.call(ranges_1);
665
921
  }
666
- finally { if (e_12) throw e_12.error; }
922
+ finally { if (e_15) throw e_15.error; }
667
923
  }
668
924
  }
669
925
  }
670
- catch (e_11_1) { e_11 = { error: e_11_1 }; }
926
+ catch (e_14_1) { e_14 = { error: e_14_1 }; }
671
927
  finally {
672
928
  try {
673
929
  if (rangeNodes_1_1 && !rangeNodes_1_1.done && (_a = rangeNodes_1.return)) _a.call(rangeNodes_1);
674
930
  }
675
- finally { if (e_11) throw e_11.error; }
931
+ finally { if (e_14) throw e_14.error; }
676
932
  }
677
933
  var expressionNodes = _this.toArray(get(container, "table:named-expression") ||
678
934
  get(container, "named-expression"));
@@ -698,12 +954,12 @@ var OdsPlugin = /** @class */ (function (_super) {
698
954
  }
699
955
  }
700
956
  }
701
- catch (e_13_1) { e_13 = { error: e_13_1 }; }
957
+ catch (e_16_1) { e_16 = { error: e_16_1 }; }
702
958
  finally {
703
959
  try {
704
960
  if (expressionNodes_1_1 && !expressionNodes_1_1.done && (_c = expressionNodes_1.return)) _c.call(expressionNodes_1);
705
961
  }
706
- finally { if (e_13) throw e_13.error; }
962
+ finally { if (e_16) throw e_16.error; }
707
963
  }
708
964
  };
709
965
  var globalContainers = this.toArray(get(spreadsheet, "table:named-expressions") ||
@@ -714,12 +970,12 @@ var OdsPlugin = /** @class */ (function (_super) {
714
970
  processContainer(container);
715
971
  }
716
972
  }
717
- catch (e_8_1) { e_8 = { error: e_8_1 }; }
973
+ catch (e_11_1) { e_11 = { error: e_11_1 }; }
718
974
  finally {
719
975
  try {
720
976
  if (globalContainers_1_1 && !globalContainers_1_1.done && (_a = globalContainers_1.return)) _a.call(globalContainers_1);
721
977
  }
722
- finally { if (e_8) throw e_8.error; }
978
+ finally { if (e_11) throw e_11.error; }
723
979
  }
724
980
  try {
725
981
  for (var sheetContexts_2 = __values(sheetContexts), sheetContexts_2_1 = sheetContexts_2.next(); !sheetContexts_2_1.done; sheetContexts_2_1 = sheetContexts_2.next()) {
@@ -727,31 +983,31 @@ var OdsPlugin = /** @class */ (function (_super) {
727
983
  var containers = this.toArray(get(context.node, "table:named-expressions") ||
728
984
  get(context.node, "named-expressions"));
729
985
  try {
730
- for (var containers_1 = (e_10 = void 0, __values(containers)), containers_1_1 = containers_1.next(); !containers_1_1.done; containers_1_1 = containers_1.next()) {
986
+ for (var containers_1 = (e_13 = void 0, __values(containers)), containers_1_1 = containers_1.next(); !containers_1_1.done; containers_1_1 = containers_1.next()) {
731
987
  var container = containers_1_1.value;
732
988
  processContainer(container, context);
733
989
  }
734
990
  }
735
- catch (e_10_1) { e_10 = { error: e_10_1 }; }
991
+ catch (e_13_1) { e_13 = { error: e_13_1 }; }
736
992
  finally {
737
993
  try {
738
994
  if (containers_1_1 && !containers_1_1.done && (_c = containers_1.return)) _c.call(containers_1);
739
995
  }
740
- finally { if (e_10) throw e_10.error; }
996
+ finally { if (e_13) throw e_13.error; }
741
997
  }
742
998
  }
743
999
  }
744
- catch (e_9_1) { e_9 = { error: e_9_1 }; }
1000
+ catch (e_12_1) { e_12 = { error: e_12_1 }; }
745
1001
  finally {
746
1002
  try {
747
1003
  if (sheetContexts_2_1 && !sheetContexts_2_1.done && (_b = sheetContexts_2.return)) _b.call(sheetContexts_2);
748
1004
  }
749
- finally { if (e_9) throw e_9.error; }
1005
+ finally { if (e_12) throw e_12.error; }
750
1006
  }
751
1007
  return namedRanges;
752
1008
  };
753
1009
  OdsPlugin.prototype.extractBasicFilters = function (sheetContexts, sheetNameMap, spreadsheetNode) {
754
- var e_14, _a, e_15, _b, e_16, _c;
1010
+ var e_17, _a, e_18, _b, e_19, _c;
755
1011
  var _this = this;
756
1012
  var filters = new Map();
757
1013
  if (!sheetContexts.length) {
@@ -796,12 +1052,12 @@ var OdsPlugin = /** @class */ (function (_super) {
796
1052
  processNode(node);
797
1053
  }
798
1054
  }
799
- catch (e_14_1) { e_14 = { error: e_14_1 }; }
1055
+ catch (e_17_1) { e_17 = { error: e_17_1 }; }
800
1056
  finally {
801
1057
  try {
802
1058
  if (globalRanges_2_1 && !globalRanges_2_1.done && (_a = globalRanges_2.return)) _a.call(globalRanges_2);
803
1059
  }
804
- finally { if (e_14) throw e_14.error; }
1060
+ finally { if (e_17) throw e_17.error; }
805
1061
  }
806
1062
  }
807
1063
  try {
@@ -810,35 +1066,35 @@ var OdsPlugin = /** @class */ (function (_super) {
810
1066
  var inlineRanges = this.toArray(get(context.node, "table:database-range") ||
811
1067
  get(context.node, "database-range"));
812
1068
  try {
813
- for (var inlineRanges_2 = (e_16 = void 0, __values(inlineRanges)), inlineRanges_2_1 = inlineRanges_2.next(); !inlineRanges_2_1.done; inlineRanges_2_1 = inlineRanges_2.next()) {
1069
+ for (var inlineRanges_2 = (e_19 = void 0, __values(inlineRanges)), inlineRanges_2_1 = inlineRanges_2.next(); !inlineRanges_2_1.done; inlineRanges_2_1 = inlineRanges_2.next()) {
814
1070
  var node = inlineRanges_2_1.value;
815
1071
  processNode(node, context);
816
1072
  }
817
1073
  }
818
- catch (e_16_1) { e_16 = { error: e_16_1 }; }
1074
+ catch (e_19_1) { e_19 = { error: e_19_1 }; }
819
1075
  finally {
820
1076
  try {
821
1077
  if (inlineRanges_2_1 && !inlineRanges_2_1.done && (_c = inlineRanges_2.return)) _c.call(inlineRanges_2);
822
1078
  }
823
- finally { if (e_16) throw e_16.error; }
1079
+ finally { if (e_19) throw e_19.error; }
824
1080
  }
825
1081
  }
826
1082
  }
827
- catch (e_15_1) { e_15 = { error: e_15_1 }; }
1083
+ catch (e_18_1) { e_18 = { error: e_18_1 }; }
828
1084
  finally {
829
1085
  try {
830
1086
  if (sheetContexts_3_1 && !sheetContexts_3_1.done && (_b = sheetContexts_3.return)) _b.call(sheetContexts_3);
831
1087
  }
832
- finally { if (e_15) throw e_15.error; }
1088
+ finally { if (e_18) throw e_18.error; }
833
1089
  }
834
1090
  return filters;
835
1091
  };
836
1092
  OdsPlugin.prototype.convertFilterNodeToSpecs = function (filterNode) {
837
- var e_17, _a, e_18, _b;
1093
+ var e_20, _a, e_21, _b;
838
1094
  var _this = this;
839
1095
  var specMap = new Map();
840
1096
  var addConditions = function (container) {
841
- var e_19, _a;
1097
+ var e_22, _a;
842
1098
  var conditions = _this.toArray(get(container, "table:filter-condition") ||
843
1099
  get(container, "filter-condition"));
844
1100
  try {
@@ -847,12 +1103,12 @@ var OdsPlugin = /** @class */ (function (_super) {
847
1103
  _this.applyFilterCondition(condition, specMap);
848
1104
  }
849
1105
  }
850
- catch (e_19_1) { e_19 = { error: e_19_1 }; }
1106
+ catch (e_22_1) { e_22 = { error: e_22_1 }; }
851
1107
  finally {
852
1108
  try {
853
1109
  if (conditions_1_1 && !conditions_1_1.done && (_a = conditions_1.return)) _a.call(conditions_1);
854
1110
  }
855
- finally { if (e_19) throw e_19.error; }
1111
+ finally { if (e_22) throw e_22.error; }
856
1112
  }
857
1113
  };
858
1114
  addConditions(filterNode);
@@ -863,12 +1119,12 @@ var OdsPlugin = /** @class */ (function (_super) {
863
1119
  addConditions(node);
864
1120
  }
865
1121
  }
866
- catch (e_17_1) { e_17 = { error: e_17_1 }; }
1122
+ catch (e_20_1) { e_20 = { error: e_20_1 }; }
867
1123
  finally {
868
1124
  try {
869
1125
  if (andNodes_1_1 && !andNodes_1_1.done && (_a = andNodes_1.return)) _a.call(andNodes_1);
870
1126
  }
871
- finally { if (e_17) throw e_17.error; }
1127
+ finally { if (e_20) throw e_20.error; }
872
1128
  }
873
1129
  var orNodes = this.toArray(get(filterNode, "table:filter-or") || get(filterNode, "filter-or"));
874
1130
  try {
@@ -877,12 +1133,12 @@ var OdsPlugin = /** @class */ (function (_super) {
877
1133
  addConditions(node);
878
1134
  }
879
1135
  }
880
- catch (e_18_1) { e_18 = { error: e_18_1 }; }
1136
+ catch (e_21_1) { e_21 = { error: e_21_1 }; }
881
1137
  finally {
882
1138
  try {
883
1139
  if (orNodes_1_1 && !orNodes_1_1.done && (_b = orNodes_1.return)) _b.call(orNodes_1);
884
1140
  }
885
- finally { if (e_18) throw e_18.error; }
1141
+ finally { if (e_21) throw e_21.error; }
886
1142
  }
887
1143
  return Array.from(specMap.values()).sort(function (a, b) { return a.columnIndex - b.columnIndex; });
888
1144
  };
@@ -991,7 +1247,7 @@ var OdsPlugin = /** @class */ (function (_super) {
991
1247
  }
992
1248
  };
993
1249
  var walk = function (value, inherited) {
994
- var e_20, _a;
1250
+ var e_23, _a;
995
1251
  var _b;
996
1252
  if (value === null || value === undefined)
997
1253
  return;
@@ -1036,12 +1292,12 @@ var OdsPlugin = /** @class */ (function (_super) {
1036
1292
  }
1037
1293
  }
1038
1294
  }
1039
- catch (e_20_1) { e_20 = { error: e_20_1 }; }
1295
+ catch (e_23_1) { e_23 = { error: e_23_1 }; }
1040
1296
  finally {
1041
1297
  try {
1042
1298
  if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
1043
1299
  }
1044
- finally { if (e_20) throw e_20.error; }
1300
+ finally { if (e_23) throw e_23.error; }
1045
1301
  }
1046
1302
  }
1047
1303
  if (value["text:a"]) {
@@ -1075,7 +1331,7 @@ var OdsPlugin = /** @class */ (function (_super) {
1075
1331
  return location;
1076
1332
  };
1077
1333
  OdsPlugin.prototype.extractHyperlinkValue = function (node) {
1078
- var e_21, _a, e_22, _b, e_23, _c;
1334
+ var e_24, _a, e_25, _b, e_26, _c;
1079
1335
  if (node === null || node === undefined)
1080
1336
  return undefined;
1081
1337
  if (Array.isArray(node)) {
@@ -1087,12 +1343,12 @@ var OdsPlugin = /** @class */ (function (_super) {
1087
1343
  return result;
1088
1344
  }
1089
1345
  }
1090
- catch (e_21_1) { e_21 = { error: e_21_1 }; }
1346
+ catch (e_24_1) { e_24 = { error: e_24_1 }; }
1091
1347
  finally {
1092
1348
  try {
1093
1349
  if (node_1_1 && !node_1_1.done && (_a = node_1.return)) _a.call(node_1);
1094
1350
  }
1095
- finally { if (e_21) throw e_21.error; }
1351
+ finally { if (e_24) throw e_24.error; }
1096
1352
  }
1097
1353
  return undefined;
1098
1354
  }
@@ -1120,12 +1376,12 @@ var OdsPlugin = /** @class */ (function (_super) {
1120
1376
  return __assign({ kind: "external", url: href }, (display ? { display: display } : {}));
1121
1377
  }
1122
1378
  }
1123
- catch (e_22_1) { e_22 = { error: e_22_1 }; }
1379
+ catch (e_25_1) { e_25 = { error: e_25_1 }; }
1124
1380
  finally {
1125
1381
  try {
1126
1382
  if (anchors_1_1 && !anchors_1_1.done && (_b = anchors_1.return)) _b.call(anchors_1);
1127
1383
  }
1128
- finally { if (e_22) throw e_22.error; }
1384
+ finally { if (e_25) throw e_25.error; }
1129
1385
  }
1130
1386
  }
1131
1387
  try {
@@ -1136,12 +1392,12 @@ var OdsPlugin = /** @class */ (function (_super) {
1136
1392
  return result;
1137
1393
  }
1138
1394
  }
1139
- catch (e_23_1) { e_23 = { error: e_23_1 }; }
1395
+ catch (e_26_1) { e_26 = { error: e_26_1 }; }
1140
1396
  finally {
1141
1397
  try {
1142
1398
  if (_e && !_e.done && (_c = _d.return)) _c.call(_d);
1143
1399
  }
1144
- finally { if (e_23) throw e_23.error; }
1400
+ finally { if (e_26) throw e_26.error; }
1145
1401
  }
1146
1402
  return undefined;
1147
1403
  };
@@ -1177,8 +1433,8 @@ var OdsPlugin = /** @class */ (function (_super) {
1177
1433
  return Math.max(1, count + 1);
1178
1434
  };
1179
1435
  OdsPlugin.prototype.extractEmbeddedObjects = function (sheetContexts, sheetNameMap) {
1180
- var e_24, _a, e_25, _b, e_26, _c;
1181
- var _d;
1436
+ var e_27, _a, e_28, _b, e_29, _c, e_30, _d, e_31, _e;
1437
+ var _f, _g, _h, _j;
1182
1438
  var tables = this.getOrderedTableWrappers();
1183
1439
  if (!tables.length || !sheetContexts.length) {
1184
1440
  return { drawings: [], charts: [] };
@@ -1196,12 +1452,62 @@ var OdsPlugin = /** @class */ (function (_super) {
1196
1452
  var tableChildren = tableWrapper[tableNameKey];
1197
1453
  if (!tableChildren)
1198
1454
  continue;
1199
- var rows = tableChildren.filter(function (child) { return child["table:table-row"] || child["table-row"]; });
1455
+ var rows = flattenOrderedRows(tableChildren);
1200
1456
  var currentRowIndex = 1;
1201
1457
  var sheetContext = sheetContexts[sheetIndex];
1202
- var sheetId = (_d = sheetContext === null || sheetContext === void 0 ? void 0 : sheetContext.sheetId) !== null && _d !== void 0 ? _d : sheetIndex + 1;
1458
+ var sheetId = (_f = sheetContext === null || sheetContext === void 0 ? void 0 : sheetContext.sheetId) !== null && _f !== void 0 ? _f : sheetIndex + 1;
1203
1459
  try {
1204
- for (var rows_1 = (e_24 = void 0, __values(rows)), rows_1_1 = rows_1.next(); !rows_1_1.done; rows_1_1 = rows_1.next()) {
1460
+ // Sheet-level `<table:shapes>` frames (what LibreOffice and our own
1461
+ // ODS exporter write for charts/images floating over the grid). They
1462
+ // anchor through `table:anchor-cell-address`; their `svg:x`/`svg:y`
1463
+ // are sheet-absolute, so the cell anchor alone positions them.
1464
+ for (var _k = (e_27 = void 0, __values(tableChildren.filter(function (child) { return child["table:shapes"] || child["shapes"]; }))), _l = _k.next(); !_l.done; _l = _k.next()) {
1465
+ var shapesWrapper = _l.value;
1466
+ var shapeChildren = shapesWrapper["table:shapes"] || shapesWrapper["shapes"];
1467
+ try {
1468
+ // `collectFrameNodes` yields each frame child (the `draw:object` /
1469
+ // `draw:image` wrapper) as `frame` and the `<draw:frame>` attributes
1470
+ // as `cellAttrs`.
1471
+ for (var _m = (e_28 = void 0, __values(this.collectFrameNodes(shapeChildren))), _o = _m.next(); !_o.done; _o = _m.next()) {
1472
+ var _p = _o.value, frame = _p.frame, frameAttrs = _p.cellAttrs;
1473
+ var anchorAddress = (frameAttrs === null || frameAttrs === void 0 ? void 0 : frameAttrs["@_table:anchor-cell-address"]) ||
1474
+ (frameAttrs === null || frameAttrs === void 0 ? void 0 : frameAttrs["@_anchor-cell-address"]);
1475
+ var anchor = typeof anchorAddress === "string"
1476
+ ? addressToCell((_g = anchorAddress.split(".").pop()) !== null && _g !== void 0 ? _g : anchorAddress)
1477
+ : null;
1478
+ var anchorRow = (_h = anchor === null || anchor === void 0 ? void 0 : anchor.rowIndex) !== null && _h !== void 0 ? _h : 1;
1479
+ var anchorColumn = (_j = anchor === null || anchor === void 0 ? void 0 : anchor.columnIndex) !== null && _j !== void 0 ? _j : 1;
1480
+ var placementAttrs = this.withoutAbsoluteOffsets(frameAttrs);
1481
+ var chart = this.convertFrameToEmbeddedChart(frame, sheetContext, sheetId, anchorRow, anchorColumn, sheetNameMap, placementAttrs);
1482
+ if (chart) {
1483
+ chartAnchors.add(this.buildAnchorKey(sheetId, anchorRow, anchorColumn));
1484
+ charts.push(chart);
1485
+ continue;
1486
+ }
1487
+ var embedded = this.convertFrameToEmbeddedObject(frame, sheetId, anchorRow, anchorColumn, imageCache, placementAttrs);
1488
+ if (embedded) {
1489
+ drawings.push(embedded);
1490
+ }
1491
+ }
1492
+ }
1493
+ catch (e_28_1) { e_28 = { error: e_28_1 }; }
1494
+ finally {
1495
+ try {
1496
+ if (_o && !_o.done && (_b = _m.return)) _b.call(_m);
1497
+ }
1498
+ finally { if (e_28) throw e_28.error; }
1499
+ }
1500
+ }
1501
+ }
1502
+ catch (e_27_1) { e_27 = { error: e_27_1 }; }
1503
+ finally {
1504
+ try {
1505
+ if (_l && !_l.done && (_a = _k.return)) _a.call(_k);
1506
+ }
1507
+ finally { if (e_27) throw e_27.error; }
1508
+ }
1509
+ try {
1510
+ for (var rows_1 = (e_29 = void 0, __values(rows)), rows_1_1 = rows_1.next(); !rows_1_1.done; rows_1_1 = rows_1.next()) {
1205
1511
  var rowWrapper = rows_1_1.value;
1206
1512
  var rowNameKey = rowWrapper["table:table-row"]
1207
1513
  ? "table:table-row"
@@ -1219,7 +1525,7 @@ var OdsPlugin = /** @class */ (function (_super) {
1219
1525
  : null;
1220
1526
  if (normalizedRowChildren) {
1221
1527
  try {
1222
- for (var normalizedRowChildren_1 = (e_25 = void 0, __values(normalizedRowChildren)), normalizedRowChildren_1_1 = normalizedRowChildren_1.next(); !normalizedRowChildren_1_1.done; normalizedRowChildren_1_1 = normalizedRowChildren_1.next()) {
1528
+ for (var normalizedRowChildren_1 = (e_30 = void 0, __values(normalizedRowChildren)), normalizedRowChildren_1_1 = normalizedRowChildren_1.next(); !normalizedRowChildren_1_1.done; normalizedRowChildren_1_1 = normalizedRowChildren_1.next()) {
1223
1529
  var cellWrapper = normalizedRowChildren_1_1.value;
1224
1530
  var isCell = !!cellWrapper["table:table-cell"];
1225
1531
  var isCovered = !!cellWrapper["table:covered-table-cell"];
@@ -1242,8 +1548,8 @@ var OdsPlugin = /** @class */ (function (_super) {
1242
1548
  for (var c = 0; c < colsRepeated; c++) {
1243
1549
  var anchorColumnIndex = columnIndex + c;
1244
1550
  try {
1245
- for (var frameNodes_1 = (e_26 = void 0, __values(frameNodes)), frameNodes_1_1 = frameNodes_1.next(); !frameNodes_1_1.done; frameNodes_1_1 = frameNodes_1.next()) {
1246
- var _e = frameNodes_1_1.value, frame = _e.frame, frameCellAttrs = _e.cellAttrs;
1551
+ for (var frameNodes_1 = (e_31 = void 0, __values(frameNodes)), frameNodes_1_1 = frameNodes_1.next(); !frameNodes_1_1.done; frameNodes_1_1 = frameNodes_1.next()) {
1552
+ var _q = frameNodes_1_1.value, frame = _q.frame, frameCellAttrs = _q.cellAttrs;
1247
1553
  var chart = this.convertFrameToEmbeddedChart(frame, sheetContext, sheetId, currentRowIndex, anchorColumnIndex, sheetNameMap, frameCellAttrs);
1248
1554
  if (chart) {
1249
1555
  chartAnchors.add(this.buildAnchorKey(sheetId, currentRowIndex, anchorColumnIndex));
@@ -1260,36 +1566,36 @@ var OdsPlugin = /** @class */ (function (_super) {
1260
1566
  }
1261
1567
  }
1262
1568
  }
1263
- catch (e_26_1) { e_26 = { error: e_26_1 }; }
1569
+ catch (e_31_1) { e_31 = { error: e_31_1 }; }
1264
1570
  finally {
1265
1571
  try {
1266
- if (frameNodes_1_1 && !frameNodes_1_1.done && (_c = frameNodes_1.return)) _c.call(frameNodes_1);
1572
+ if (frameNodes_1_1 && !frameNodes_1_1.done && (_e = frameNodes_1.return)) _e.call(frameNodes_1);
1267
1573
  }
1268
- finally { if (e_26) throw e_26.error; }
1574
+ finally { if (e_31) throw e_31.error; }
1269
1575
  }
1270
1576
  }
1271
1577
  }
1272
1578
  columnIndex += colsRepeated;
1273
1579
  }
1274
1580
  }
1275
- catch (e_25_1) { e_25 = { error: e_25_1 }; }
1581
+ catch (e_30_1) { e_30 = { error: e_30_1 }; }
1276
1582
  finally {
1277
1583
  try {
1278
- if (normalizedRowChildren_1_1 && !normalizedRowChildren_1_1.done && (_b = normalizedRowChildren_1.return)) _b.call(normalizedRowChildren_1);
1584
+ if (normalizedRowChildren_1_1 && !normalizedRowChildren_1_1.done && (_d = normalizedRowChildren_1.return)) _d.call(normalizedRowChildren_1);
1279
1585
  }
1280
- finally { if (e_25) throw e_25.error; }
1586
+ finally { if (e_30) throw e_30.error; }
1281
1587
  }
1282
1588
  }
1283
1589
  currentRowIndex++;
1284
1590
  }
1285
1591
  }
1286
1592
  }
1287
- catch (e_24_1) { e_24 = { error: e_24_1 }; }
1593
+ catch (e_29_1) { e_29 = { error: e_29_1 }; }
1288
1594
  finally {
1289
1595
  try {
1290
- if (rows_1_1 && !rows_1_1.done && (_a = rows_1.return)) _a.call(rows_1);
1596
+ if (rows_1_1 && !rows_1_1.done && (_c = rows_1.return)) _c.call(rows_1);
1291
1597
  }
1292
- finally { if (e_24) throw e_24.error; }
1598
+ finally { if (e_29) throw e_29.error; }
1293
1599
  }
1294
1600
  }
1295
1601
  return { drawings: drawings, charts: charts };
@@ -1297,6 +1603,18 @@ var OdsPlugin = /** @class */ (function (_super) {
1297
1603
  OdsPlugin.prototype.buildAnchorKey = function (sheetId, rowIndex, columnIndex) {
1298
1604
  return "".concat(sheetId, ":").concat(rowIndex, ":").concat(columnIndex);
1299
1605
  };
1606
+ /**
1607
+ * Copy of a `<draw:frame>` attribute record without `svg:x` / `svg:y`.
1608
+ * Frames in `<table:shapes>` carry sheet-absolute coordinates there,
1609
+ * which `buildOverlayPlacement` would otherwise read as an offset inside
1610
+ * the anchor cell.
1611
+ */
1612
+ OdsPlugin.prototype.withoutAbsoluteOffsets = function (frameAttrs) {
1613
+ if (!frameAttrs || typeof frameAttrs !== "object")
1614
+ return frameAttrs;
1615
+ var _x = frameAttrs["@_svg:x"], _y = frameAttrs["@_svg:y"], _bareX = frameAttrs["@_x"], _bareY = frameAttrs["@_y"], rest = __rest(frameAttrs, ["@_svg:x", "@_svg:y", "@_x", "@_y"]);
1616
+ return rest;
1617
+ };
1300
1618
  /**
1301
1619
  * Walk the ordered content XML for each table and assign outline
1302
1620
  * level + collapsed/hiddenByGroup state on `rowMetadata` and
@@ -1324,7 +1642,7 @@ var OdsPlugin = /** @class */ (function (_super) {
1324
1642
  return;
1325
1643
  var tables = spreadsheet.filter(function (child) { return child["table:table"] || child["table"]; });
1326
1644
  var tableCount = Math.min(tables.length, sheets.length);
1327
- var _loop_1 = function (sheetIndex) {
1645
+ var _loop_5 = function (sheetIndex) {
1328
1646
  var tableWrapper = tables[sheetIndex];
1329
1647
  var tableNameKey = tableWrapper["table:table"]
1330
1648
  ? "table:table"
@@ -1344,100 +1662,112 @@ var OdsPlugin = /** @class */ (function (_super) {
1344
1662
  meta[index] = {};
1345
1663
  Object.assign(meta[index], patch);
1346
1664
  };
1347
- var walk = function (nodes, itemTag, groupTag, meta, repeatAttrs, summaryAfter) {
1665
+ var walk = function (nodes, itemTag, groupTag, wrapperTags, meta, repeatAttrs, summaryAfter) {
1348
1666
  var cursor = 1;
1349
1667
  var openStack = [];
1350
1668
  var collapsedDepth = function () { return openStack.some(function (g) { return g.collapsed; }); };
1351
1669
  var currentLevel = function () { return openStack.length; };
1352
1670
  var visit = function (children) {
1353
- var e_27, _a, e_28, _b;
1354
- var _c;
1355
- try {
1356
- for (var children_1 = (e_27 = void 0, __values(children)), children_1_1 = children_1.next(); !children_1_1.done; children_1_1 = children_1.next()) {
1357
- var child = children_1_1.value;
1358
- if (!child)
1359
- continue;
1360
- if (child[groupTag]) {
1361
- var attrs = child[":@"] || {};
1362
- var display = (_c = attrs["@_table:display"]) !== null && _c !== void 0 ? _c : attrs["@_display"];
1363
- var collapsed = display === "false" || display === false;
1364
- var startIndex = cursor;
1365
- openStack.push({
1366
- level: openStack.length + 1,
1367
- startIndex: startIndex,
1368
- collapsed: collapsed,
1369
- });
1370
- visit(child[groupTag] || []);
1371
- var closing = openStack.pop();
1372
- if (closing.collapsed) {
1373
- var summaryIndex = summaryAfter
1374
- ? cursor
1375
- : closing.startIndex - 1;
1376
- if (summaryIndex >= 1) {
1377
- setMeta(meta, summaryIndex, { collapsed: true });
1378
- }
1671
+ var e_32, _a;
1672
+ var _b;
1673
+ var _loop_6 = function (child) {
1674
+ var e_33, _c;
1675
+ if (!child)
1676
+ return "continue";
1677
+ // `<table:table-header-rows>` / `<table:table-rows>` (and the
1678
+ // column twins) only group rows for printing; their rows keep
1679
+ // the surrounding outline level and still advance the cursor.
1680
+ var wrapper = wrapperTags.find(function (tag) { return tag !== groupTag && child[tag]; });
1681
+ if (wrapper) {
1682
+ visit(child[wrapper] || []);
1683
+ return "continue";
1684
+ }
1685
+ if (child[groupTag]) {
1686
+ var attrs = child[":@"] || {};
1687
+ var display = (_b = attrs["@_table:display"]) !== null && _b !== void 0 ? _b : attrs["@_display"];
1688
+ var collapsed = display === "false" || display === false;
1689
+ var startIndex = cursor;
1690
+ openStack.push({
1691
+ level: openStack.length + 1,
1692
+ startIndex: startIndex,
1693
+ collapsed: collapsed,
1694
+ });
1695
+ visit(child[groupTag] || []);
1696
+ var closing = openStack.pop();
1697
+ if (closing.collapsed) {
1698
+ var summaryIndex = summaryAfter
1699
+ ? cursor
1700
+ : closing.startIndex - 1;
1701
+ if (summaryIndex >= 1) {
1702
+ setMeta(meta, summaryIndex, { collapsed: true });
1379
1703
  }
1380
1704
  }
1381
- else if (child[itemTag]) {
1382
- var attrs = child[":@"] || {};
1383
- var repeat = 1;
1384
- try {
1385
- for (var repeatAttrs_1 = (e_28 = void 0, __values(repeatAttrs)), repeatAttrs_1_1 = repeatAttrs_1.next(); !repeatAttrs_1_1.done; repeatAttrs_1_1 = repeatAttrs_1.next()) {
1386
- var attrName = repeatAttrs_1_1.value;
1387
- var raw = attrs["@_".concat(attrName)];
1388
- if (raw !== undefined) {
1389
- repeat = Math.max(1, parseInt(String(raw), 10) || 1);
1390
- break;
1391
- }
1705
+ }
1706
+ else if (child[itemTag]) {
1707
+ var attrs = child[":@"] || {};
1708
+ var repeat = 1;
1709
+ try {
1710
+ for (var repeatAttrs_1 = (e_33 = void 0, __values(repeatAttrs)), repeatAttrs_1_1 = repeatAttrs_1.next(); !repeatAttrs_1_1.done; repeatAttrs_1_1 = repeatAttrs_1.next()) {
1711
+ var attrName = repeatAttrs_1_1.value;
1712
+ var raw = attrs["@_".concat(attrName)];
1713
+ if (raw !== undefined) {
1714
+ repeat = Math.max(1, parseInt(String(raw), 10) || 1);
1715
+ break;
1392
1716
  }
1393
1717
  }
1394
- catch (e_28_1) { e_28 = { error: e_28_1 }; }
1395
- finally {
1396
- try {
1397
- if (repeatAttrs_1_1 && !repeatAttrs_1_1.done && (_b = repeatAttrs_1.return)) _b.call(repeatAttrs_1);
1398
- }
1399
- finally { if (e_28) throw e_28.error; }
1718
+ }
1719
+ catch (e_33_1) { e_33 = { error: e_33_1 }; }
1720
+ finally {
1721
+ try {
1722
+ if (repeatAttrs_1_1 && !repeatAttrs_1_1.done && (_c = repeatAttrs_1.return)) _c.call(repeatAttrs_1);
1400
1723
  }
1401
- repeat = Math.min(repeat, 10000);
1402
- var level = currentLevel();
1403
- var hidden = collapsedDepth();
1404
- if (level > 0 || hidden) {
1405
- for (var r = 0; r < repeat; r++) {
1406
- var patch = {};
1407
- if (level > 0)
1408
- patch.outlineLevel = level;
1409
- if (hidden)
1410
- patch.hiddenByGroup = true;
1411
- setMeta(meta, cursor + r, patch);
1412
- }
1724
+ finally { if (e_33) throw e_33.error; }
1725
+ }
1726
+ repeat = Math.min(repeat, 10000);
1727
+ var level = currentLevel();
1728
+ var hidden = collapsedDepth();
1729
+ if (level > 0 || hidden) {
1730
+ for (var r = 0; r < repeat; r++) {
1731
+ var patch = {};
1732
+ if (level > 0)
1733
+ patch.outlineLevel = level;
1734
+ if (hidden)
1735
+ patch.hiddenByGroup = true;
1736
+ setMeta(meta, cursor + r, patch);
1413
1737
  }
1414
- cursor += repeat;
1415
1738
  }
1739
+ cursor += repeat;
1740
+ }
1741
+ };
1742
+ try {
1743
+ for (var children_1 = (e_32 = void 0, __values(children)), children_1_1 = children_1.next(); !children_1_1.done; children_1_1 = children_1.next()) {
1744
+ var child = children_1_1.value;
1745
+ _loop_6(child);
1416
1746
  }
1417
1747
  }
1418
- catch (e_27_1) { e_27 = { error: e_27_1 }; }
1748
+ catch (e_32_1) { e_32 = { error: e_32_1 }; }
1419
1749
  finally {
1420
1750
  try {
1421
1751
  if (children_1_1 && !children_1_1.done && (_a = children_1.return)) _a.call(children_1);
1422
1752
  }
1423
- finally { if (e_27) throw e_27.error; }
1753
+ finally { if (e_32) throw e_32.error; }
1424
1754
  }
1425
1755
  };
1426
1756
  visit(nodes);
1427
1757
  };
1428
- walk(tableChildren, "table:table-column", "table:table-column-group", columnMetadata, ["table:number-columns-repeated", "number-columns-repeated"], summaryRight);
1429
- walk(tableChildren, "table:table-row", "table:table-row-group", rowMetadata, ["table:number-rows-repeated", "number-rows-repeated"], summaryBelow);
1758
+ walk(tableChildren, "table:table-column", "table:table-column-group", COLUMN_WRAPPER_TAGS, columnMetadata, ["table:number-columns-repeated", "number-columns-repeated"], summaryRight);
1759
+ walk(tableChildren, "table:table-row", "table:table-row-group", ROW_WRAPPER_TAGS, rowMetadata, ["table:number-rows-repeated", "number-rows-repeated"], summaryBelow);
1430
1760
  if (columnMetadata.length > 0)
1431
1761
  sheet.columnMetadata = columnMetadata;
1432
1762
  if (rowMetadata.length > 0)
1433
1763
  sheet.rowMetadata = rowMetadata;
1434
1764
  };
1435
1765
  for (var sheetIndex = 0; sheetIndex < tableCount; sheetIndex++) {
1436
- _loop_1(sheetIndex);
1766
+ _loop_5(sheetIndex);
1437
1767
  }
1438
1768
  };
1439
1769
  OdsPlugin.prototype.extractMerges = function (sheetContexts) {
1440
- var e_29, _a, e_30, _b;
1770
+ var e_34, _a, e_35, _b;
1441
1771
  var _c, _d, _e, _f;
1442
1772
  var merges = new Map();
1443
1773
  if (!this.contentXmlOrdered || !sheetContexts.length) {
@@ -1465,11 +1795,11 @@ var OdsPlugin = /** @class */ (function (_super) {
1465
1795
  var tableChildren = tableWrapper[tableNameKey];
1466
1796
  if (!tableChildren)
1467
1797
  continue;
1468
- var rows = tableChildren.filter(function (child) { return child["table:table-row"] || child["table-row"]; });
1798
+ var rows = flattenOrderedRows(tableChildren);
1469
1799
  var sheetId = (_f = (_e = sheetContexts[sheetIndex]) === null || _e === void 0 ? void 0 : _e.sheetId) !== null && _f !== void 0 ? _f : sheetIndex + 1;
1470
1800
  var currentRowIndex = 1;
1471
1801
  try {
1472
- for (var rows_2 = (e_29 = void 0, __values(rows)), rows_2_1 = rows_2.next(); !rows_2_1.done; rows_2_1 = rows_2.next()) {
1802
+ for (var rows_2 = (e_34 = void 0, __values(rows)), rows_2_1 = rows_2.next(); !rows_2_1.done; rows_2_1 = rows_2.next()) {
1473
1803
  var rowWrapper = rows_2_1.value;
1474
1804
  var rowNameKey = rowWrapper["table:table-row"]
1475
1805
  ? "table:table-row"
@@ -1484,7 +1814,7 @@ var OdsPlugin = /** @class */ (function (_super) {
1484
1814
  var columnIndex = 1;
1485
1815
  if (rowChildren) {
1486
1816
  try {
1487
- for (var rowChildren_1 = (e_30 = void 0, __values(rowChildren)), rowChildren_1_1 = rowChildren_1.next(); !rowChildren_1_1.done; rowChildren_1_1 = rowChildren_1.next()) {
1817
+ for (var rowChildren_1 = (e_35 = void 0, __values(rowChildren)), rowChildren_1_1 = rowChildren_1.next(); !rowChildren_1_1.done; rowChildren_1_1 = rowChildren_1.next()) {
1488
1818
  var cellWrapper = rowChildren_1_1.value;
1489
1819
  var isCell = !!cellWrapper["table:table-cell"];
1490
1820
  var isCovered = !!cellWrapper["table:covered-table-cell"];
@@ -1532,24 +1862,24 @@ var OdsPlugin = /** @class */ (function (_super) {
1532
1862
  columnIndex += colsRepeated;
1533
1863
  }
1534
1864
  }
1535
- catch (e_30_1) { e_30 = { error: e_30_1 }; }
1865
+ catch (e_35_1) { e_35 = { error: e_35_1 }; }
1536
1866
  finally {
1537
1867
  try {
1538
1868
  if (rowChildren_1_1 && !rowChildren_1_1.done && (_b = rowChildren_1.return)) _b.call(rowChildren_1);
1539
1869
  }
1540
- finally { if (e_30) throw e_30.error; }
1870
+ finally { if (e_35) throw e_35.error; }
1541
1871
  }
1542
1872
  }
1543
1873
  currentRowIndex++;
1544
1874
  }
1545
1875
  }
1546
1876
  }
1547
- catch (e_29_1) { e_29 = { error: e_29_1 }; }
1877
+ catch (e_34_1) { e_34 = { error: e_34_1 }; }
1548
1878
  finally {
1549
1879
  try {
1550
1880
  if (rows_2_1 && !rows_2_1.done && (_a = rows_2.return)) _a.call(rows_2);
1551
1881
  }
1552
- finally { if (e_29) throw e_29.error; }
1882
+ finally { if (e_34) throw e_34.error; }
1553
1883
  }
1554
1884
  }
1555
1885
  return merges;
@@ -1572,7 +1902,7 @@ var OdsPlugin = /** @class */ (function (_super) {
1572
1902
  return spreadsheet.filter(function (child) { return child["table:table"] || child["table"]; });
1573
1903
  };
1574
1904
  OdsPlugin.prototype.findOrderedTableWrapperForContext = function (sheetContext, sheetId) {
1575
- var e_31, _a;
1905
+ var e_36, _a;
1576
1906
  var tables = this.getOrderedTableWrappers();
1577
1907
  if (!tables.length)
1578
1908
  return undefined;
@@ -1594,12 +1924,12 @@ var OdsPlugin = /** @class */ (function (_super) {
1594
1924
  }
1595
1925
  }
1596
1926
  }
1597
- catch (e_31_1) { e_31 = { error: e_31_1 }; }
1927
+ catch (e_36_1) { e_36 = { error: e_36_1 }; }
1598
1928
  finally {
1599
1929
  try {
1600
1930
  if (tables_1_1 && !tables_1_1.done && (_a = tables_1.return)) _a.call(tables_1);
1601
1931
  }
1602
- finally { if (e_31) throw e_31.error; }
1932
+ finally { if (e_36) throw e_36.error; }
1603
1933
  }
1604
1934
  }
1605
1935
  if (sheetId && tables[sheetId - 1]) {
@@ -1608,7 +1938,7 @@ var OdsPlugin = /** @class */ (function (_super) {
1608
1938
  return tables[0];
1609
1939
  };
1610
1940
  OdsPlugin.prototype.extractTableColumnsFromHeader = function (range, sheetContext, useHeaderRow) {
1611
- var e_32, _a, e_33, _b;
1941
+ var e_37, _a, e_38, _b;
1612
1942
  var _c, _d, _e;
1613
1943
  if (useHeaderRow === void 0) { useHeaderRow = true; }
1614
1944
  var startColumn = Math.max(1, (_c = range.startColumnIndex) !== null && _c !== void 0 ? _c : 1);
@@ -1631,7 +1961,7 @@ var OdsPlugin = /** @class */ (function (_super) {
1631
1961
  if (!tableChildren) {
1632
1962
  return buildDefaultColumns();
1633
1963
  }
1634
- var rows = tableChildren.filter(function (child) { return child["table:table-row"] || child["table-row"]; });
1964
+ var rows = flattenOrderedRows(tableChildren);
1635
1965
  if (!rows.length) {
1636
1966
  return buildDefaultColumns();
1637
1967
  }
@@ -1658,7 +1988,7 @@ var OdsPlugin = /** @class */ (function (_super) {
1658
1988
  var columnIndex = 1;
1659
1989
  if (normalizedRowChildren) {
1660
1990
  try {
1661
- for (var normalizedRowChildren_2 = (e_33 = void 0, __values(normalizedRowChildren)), normalizedRowChildren_2_1 = normalizedRowChildren_2.next(); !normalizedRowChildren_2_1.done; normalizedRowChildren_2_1 = normalizedRowChildren_2.next()) {
1991
+ for (var normalizedRowChildren_2 = (e_38 = void 0, __values(normalizedRowChildren)), normalizedRowChildren_2_1 = normalizedRowChildren_2.next(); !normalizedRowChildren_2_1.done; normalizedRowChildren_2_1 = normalizedRowChildren_2.next()) {
1662
1992
  var cellWrapper = normalizedRowChildren_2_1.value;
1663
1993
  var isCell = !!cellWrapper["table:table-cell"];
1664
1994
  var isCovered = !!cellWrapper["table:covered-table-cell"];
@@ -1708,12 +2038,12 @@ var OdsPlugin = /** @class */ (function (_super) {
1708
2038
  }
1709
2039
  }
1710
2040
  }
1711
- catch (e_33_1) { e_33 = { error: e_33_1 }; }
2041
+ catch (e_38_1) { e_38 = { error: e_38_1 }; }
1712
2042
  finally {
1713
2043
  try {
1714
2044
  if (normalizedRowChildren_2_1 && !normalizedRowChildren_2_1.done && (_b = normalizedRowChildren_2.return)) _b.call(normalizedRowChildren_2);
1715
2045
  }
1716
- finally { if (e_33) throw e_33.error; }
2046
+ finally { if (e_38) throw e_38.error; }
1717
2047
  }
1718
2048
  }
1719
2049
  break outer;
@@ -1725,12 +2055,12 @@ var OdsPlugin = /** @class */ (function (_super) {
1725
2055
  }
1726
2056
  }
1727
2057
  }
1728
- catch (e_32_1) { e_32 = { error: e_32_1 }; }
2058
+ catch (e_37_1) { e_37 = { error: e_37_1 }; }
1729
2059
  finally {
1730
2060
  try {
1731
2061
  if (rows_3_1 && !rows_3_1.done && (_a = rows_3.return)) _a.call(rows_3);
1732
2062
  }
1733
- finally { if (e_32) throw e_32.error; }
2063
+ finally { if (e_37) throw e_37.error; }
1734
2064
  }
1735
2065
  if (!headerValues.length) {
1736
2066
  return buildDefaultColumns();
@@ -1745,7 +2075,7 @@ var OdsPlugin = /** @class */ (function (_super) {
1745
2075
  return columns;
1746
2076
  };
1747
2077
  OdsPlugin.prototype.collectFrameNodes = function (cellChildren, cellAttrs) {
1748
- var e_34, _a, e_35, _b;
2078
+ var e_39, _a, e_40, _b;
1749
2079
  if (!cellChildren)
1750
2080
  return [];
1751
2081
  var children = Array.isArray(cellChildren)
@@ -1762,17 +2092,17 @@ var OdsPlugin = /** @class */ (function (_super) {
1762
2092
  continue;
1763
2093
  if (Array.isArray(frameNode)) {
1764
2094
  try {
1765
- for (var frameNode_1 = (e_35 = void 0, __values(frameNode)), frameNode_1_1 = frameNode_1.next(); !frameNode_1_1.done; frameNode_1_1 = frameNode_1.next()) {
2095
+ for (var frameNode_1 = (e_40 = void 0, __values(frameNode)), frameNode_1_1 = frameNode_1.next(); !frameNode_1_1.done; frameNode_1_1 = frameNode_1.next()) {
1766
2096
  var node = frameNode_1_1.value;
1767
2097
  frames.push({ frame: node, cellAttrs: child[":@"] || cellAttrs });
1768
2098
  }
1769
2099
  }
1770
- catch (e_35_1) { e_35 = { error: e_35_1 }; }
2100
+ catch (e_40_1) { e_40 = { error: e_40_1 }; }
1771
2101
  finally {
1772
2102
  try {
1773
2103
  if (frameNode_1_1 && !frameNode_1_1.done && (_b = frameNode_1.return)) _b.call(frameNode_1);
1774
2104
  }
1775
- finally { if (e_35) throw e_35.error; }
2105
+ finally { if (e_40) throw e_40.error; }
1776
2106
  }
1777
2107
  }
1778
2108
  else {
@@ -1780,17 +2110,17 @@ var OdsPlugin = /** @class */ (function (_super) {
1780
2110
  }
1781
2111
  }
1782
2112
  }
1783
- catch (e_34_1) { e_34 = { error: e_34_1 }; }
2113
+ catch (e_39_1) { e_39 = { error: e_39_1 }; }
1784
2114
  finally {
1785
2115
  try {
1786
2116
  if (children_2_1 && !children_2_1.done && (_a = children_2.return)) _a.call(children_2);
1787
2117
  }
1788
- finally { if (e_34) throw e_34.error; }
2118
+ finally { if (e_39) throw e_39.error; }
1789
2119
  }
1790
2120
  return frames;
1791
2121
  };
1792
2122
  OdsPlugin.prototype.extractSheetSettings = function (sheetContexts) {
1793
- var e_36, _a, e_37, _b;
2123
+ var e_41, _a, e_42, _b;
1794
2124
  var _this = this;
1795
2125
  var map = new Map();
1796
2126
  if (!this.settingsXml || !sheetContexts.length) {
@@ -1806,7 +2136,7 @@ var OdsPlugin = /** @class */ (function (_super) {
1806
2136
  return map;
1807
2137
  var nameMap = new Map();
1808
2138
  var traverse = function (node) {
1809
- var e_38, _a, e_39, _b;
2139
+ var e_43, _a, e_44, _b;
1810
2140
  if (!node || typeof node !== "object")
1811
2141
  return;
1812
2142
  var entries = _this.toArray(node["config:config-item-map-entry"] || node["config-item-map-entry"]);
@@ -1833,12 +2163,12 @@ var OdsPlugin = /** @class */ (function (_super) {
1833
2163
  traverse(entry);
1834
2164
  }
1835
2165
  }
1836
- catch (e_38_1) { e_38 = { error: e_38_1 }; }
2166
+ catch (e_43_1) { e_43 = { error: e_43_1 }; }
1837
2167
  finally {
1838
2168
  try {
1839
2169
  if (entries_1_1 && !entries_1_1.done && (_a = entries_1.return)) _a.call(entries_1);
1840
2170
  }
1841
- finally { if (e_38) throw e_38.error; }
2171
+ finally { if (e_43) throw e_43.error; }
1842
2172
  }
1843
2173
  var namedMaps = _this.toArray(node["config:config-item-map-named"] || node["config-item-map-named"]);
1844
2174
  try {
@@ -1847,12 +2177,12 @@ var OdsPlugin = /** @class */ (function (_super) {
1847
2177
  traverse(named);
1848
2178
  }
1849
2179
  }
1850
- catch (e_39_1) { e_39 = { error: e_39_1 }; }
2180
+ catch (e_44_1) { e_44 = { error: e_44_1 }; }
1851
2181
  finally {
1852
2182
  try {
1853
2183
  if (namedMaps_1_1 && !namedMaps_1_1.done && (_b = namedMaps_1.return)) _b.call(namedMaps_1);
1854
2184
  }
1855
- finally { if (e_39) throw e_39.error; }
2185
+ finally { if (e_44) throw e_44.error; }
1856
2186
  }
1857
2187
  };
1858
2188
  var itemSets = this.toArray(get(settingsNode, "config:config-item-set") ||
@@ -1863,12 +2193,12 @@ var OdsPlugin = /** @class */ (function (_super) {
1863
2193
  traverse(set);
1864
2194
  }
1865
2195
  }
1866
- catch (e_36_1) { e_36 = { error: e_36_1 }; }
2196
+ catch (e_41_1) { e_41 = { error: e_41_1 }; }
1867
2197
  finally {
1868
2198
  try {
1869
2199
  if (itemSets_1_1 && !itemSets_1_1.done && (_a = itemSets_1.return)) _a.call(itemSets_1);
1870
2200
  }
1871
- finally { if (e_36) throw e_36.error; }
2201
+ finally { if (e_41) throw e_41.error; }
1872
2202
  }
1873
2203
  try {
1874
2204
  for (var sheetContexts_4 = __values(sheetContexts), sheetContexts_4_1 = sheetContexts_4.next(); !sheetContexts_4_1.done; sheetContexts_4_1 = sheetContexts_4.next()) {
@@ -1881,17 +2211,17 @@ var OdsPlugin = /** @class */ (function (_super) {
1881
2211
  }
1882
2212
  }
1883
2213
  }
1884
- catch (e_37_1) { e_37 = { error: e_37_1 }; }
2214
+ catch (e_42_1) { e_42 = { error: e_42_1 }; }
1885
2215
  finally {
1886
2216
  try {
1887
2217
  if (sheetContexts_4_1 && !sheetContexts_4_1.done && (_b = sheetContexts_4.return)) _b.call(sheetContexts_4);
1888
2218
  }
1889
- finally { if (e_37) throw e_37.error; }
2219
+ finally { if (e_42) throw e_42.error; }
1890
2220
  }
1891
2221
  return map;
1892
2222
  };
1893
2223
  OdsPlugin.prototype.parseConfigItemEntry = function (entry) {
1894
- var e_40, _a;
2224
+ var e_45, _a;
1895
2225
  var configItems = this.toArray(get(entry, "config:config-item") || get(entry, "config-item"));
1896
2226
  if (!configItems.length)
1897
2227
  return undefined;
@@ -1947,12 +2277,12 @@ var OdsPlugin = /** @class */ (function (_super) {
1947
2277
  }
1948
2278
  }
1949
2279
  }
1950
- catch (e_40_1) { e_40 = { error: e_40_1 }; }
2280
+ catch (e_45_1) { e_45 = { error: e_45_1 }; }
1951
2281
  finally {
1952
2282
  try {
1953
2283
  if (configItems_1_1 && !configItems_1_1.done && (_a = configItems_1.return)) _a.call(configItems_1);
1954
2284
  }
1955
- finally { if (e_40) throw e_40.error; }
2285
+ finally { if (e_45) throw e_45.error; }
1956
2286
  }
1957
2287
  return Object.keys(settings).length ? settings : undefined;
1958
2288
  };
@@ -2003,14 +2333,24 @@ var OdsPlugin = /** @class */ (function (_super) {
2003
2333
  var frameAttrs = this.getAttributes(frameNode);
2004
2334
  var inlineChart = this.findInlineChartNode(frameNode);
2005
2335
  var chartNode = inlineChart;
2336
+ // An inline chart's styles live in the workbook's content.xml, so the
2337
+ // workbook-level table applies. An embedded object is its own ODF
2338
+ // document with its own <office:automatic-styles>, and every object
2339
+ // reuses the same automatic style names (LibreOffice: ch1/ch2…, our
2340
+ // exporter: plot1/series0…), so its styles are scoped to the object —
2341
+ // sharing one table would let the previous chart's
2342
+ // `chart:three-dimensional` flag or series colours leak into this one.
2343
+ var chartStyles = this.odsStyles;
2006
2344
  if (!chartNode) {
2007
2345
  var objectNode = this.findFrameObjectNode(frameNode);
2008
- var chartFromObject = this.loadChartNodeFromObject(objectNode, frameAttrs);
2346
+ var objectStyles = new OdsStyles();
2347
+ var chartFromObject = this.loadChartNodeFromObject(objectNode, frameAttrs, objectStyles);
2009
2348
  chartNode = chartFromObject;
2349
+ chartStyles = objectStyles;
2010
2350
  }
2011
2351
  if (!chartNode)
2012
2352
  return undefined;
2013
- var spec = this.convertChartNodeToSpec(chartNode, sheetNameMap, sheetContext);
2353
+ var spec = this.convertChartNodeToSpec(chartNode, sheetNameMap, sheetContext, chartStyles);
2014
2354
  if (!spec)
2015
2355
  return undefined;
2016
2356
  var overlayPosition = this.buildOverlayPlacement(frameAttrs, cellAttrs, rowIndex, columnIndex).overlayPosition;
@@ -2027,7 +2367,7 @@ var OdsPlugin = /** @class */ (function (_super) {
2027
2367
  };
2028
2368
  };
2029
2369
  OdsPlugin.prototype.findInlineChartNode = function (frameNode) {
2030
- var e_41, _a;
2370
+ var e_46, _a;
2031
2371
  if (!frameNode)
2032
2372
  return undefined;
2033
2373
  if (Array.isArray(frameNode)) {
@@ -2039,12 +2379,12 @@ var OdsPlugin = /** @class */ (function (_super) {
2039
2379
  return found;
2040
2380
  }
2041
2381
  }
2042
- catch (e_41_1) { e_41 = { error: e_41_1 }; }
2382
+ catch (e_46_1) { e_46 = { error: e_46_1 }; }
2043
2383
  finally {
2044
2384
  try {
2045
2385
  if (frameNode_2_1 && !frameNode_2_1.done && (_a = frameNode_2.return)) _a.call(frameNode_2);
2046
2386
  }
2047
- finally { if (e_41) throw e_41.error; }
2387
+ finally { if (e_46) throw e_46.error; }
2048
2388
  }
2049
2389
  return undefined;
2050
2390
  }
@@ -2055,7 +2395,7 @@ var OdsPlugin = /** @class */ (function (_super) {
2055
2395
  return undefined;
2056
2396
  };
2057
2397
  OdsPlugin.prototype.findFrameObjectNode = function (frameNode) {
2058
- var e_42, _a;
2398
+ var e_47, _a;
2059
2399
  if (!frameNode)
2060
2400
  return undefined;
2061
2401
  if (Array.isArray(frameNode)) {
@@ -2067,12 +2407,12 @@ var OdsPlugin = /** @class */ (function (_super) {
2067
2407
  return found;
2068
2408
  }
2069
2409
  }
2070
- catch (e_42_1) { e_42 = { error: e_42_1 }; }
2410
+ catch (e_47_1) { e_47 = { error: e_47_1 }; }
2071
2411
  finally {
2072
2412
  try {
2073
2413
  if (frameNode_3_1 && !frameNode_3_1.done && (_a = frameNode_3.return)) _a.call(frameNode_3);
2074
2414
  }
2075
- finally { if (e_42) throw e_42.error; }
2415
+ finally { if (e_47) throw e_47.error; }
2076
2416
  }
2077
2417
  return undefined;
2078
2418
  }
@@ -2083,7 +2423,7 @@ var OdsPlugin = /** @class */ (function (_super) {
2083
2423
  return undefined;
2084
2424
  };
2085
2425
  OdsPlugin.prototype.findFrameImageNode = function (frameNode) {
2086
- var e_43, _a;
2426
+ var e_48, _a;
2087
2427
  if (!frameNode)
2088
2428
  return undefined;
2089
2429
  if (Array.isArray(frameNode)) {
@@ -2095,12 +2435,12 @@ var OdsPlugin = /** @class */ (function (_super) {
2095
2435
  return found;
2096
2436
  }
2097
2437
  }
2098
- catch (e_43_1) { e_43 = { error: e_43_1 }; }
2438
+ catch (e_48_1) { e_48 = { error: e_48_1 }; }
2099
2439
  finally {
2100
2440
  try {
2101
2441
  if (frameNode_4_1 && !frameNode_4_1.done && (_a = frameNode_4.return)) _a.call(frameNode_4);
2102
2442
  }
2103
- finally { if (e_43) throw e_43.error; }
2443
+ finally { if (e_48) throw e_48.error; }
2104
2444
  }
2105
2445
  return undefined;
2106
2446
  }
@@ -2110,24 +2450,32 @@ var OdsPlugin = /** @class */ (function (_super) {
2110
2450
  }
2111
2451
  return undefined;
2112
2452
  };
2113
- OdsPlugin.prototype.loadChartNodeFromObject = function (objectNode, frameAttrs) {
2114
- if (!objectNode)
2453
+ OdsPlugin.prototype.loadChartNodeFromObject = function (objectNode, frameAttrs, styles) {
2454
+ // A self-closing `<draw:object xlink:href="…"/>` parses to an empty
2455
+ // child list with its attributes on the wrapper (`frameAttrs` here), so
2456
+ // the href must still be honoured when there is no object node.
2457
+ if (!objectNode && !frameAttrs)
2115
2458
  return undefined;
2116
2459
  var objectAttrs = this.getAttributes(objectNode);
2117
2460
  var href = (objectAttrs === null || objectAttrs === void 0 ? void 0 : objectAttrs["@_xlink:href"]) ||
2118
2461
  (objectAttrs === null || objectAttrs === void 0 ? void 0 : objectAttrs["@_href"]) ||
2119
2462
  (frameAttrs === null || frameAttrs === void 0 ? void 0 : frameAttrs["@_xlink:href"]) ||
2120
2463
  (frameAttrs === null || frameAttrs === void 0 ? void 0 : frameAttrs["@_href"]);
2121
- return this.loadChartNodeFromHref(href);
2464
+ return this.loadChartNodeFromHref(href, styles);
2122
2465
  };
2123
- OdsPlugin.prototype.loadChartNodeFromHref = function (href) {
2466
+ /**
2467
+ * Loads an embedded chart object's `content.xml` and registers its
2468
+ * `<office:automatic-styles>` into `styles` — the per-object table the
2469
+ * caller resolves plot-area / series styles against.
2470
+ */
2471
+ OdsPlugin.prototype.loadChartNodeFromHref = function (href, styles) {
2124
2472
  var path = this.resolveObjectPath(href);
2125
2473
  if (!path)
2126
2474
  return undefined;
2127
2475
  try {
2128
2476
  var content = this.zipParser.Get(path);
2129
2477
  var chartDoc = this.xmlParser.parse(content);
2130
- this.odsStyles.parseContentXml(chartDoc);
2478
+ styles.parseContentXml(chartDoc);
2131
2479
  return this.findChartNodeInDocument(chartDoc);
2132
2480
  }
2133
2481
  catch (_a) {
@@ -2135,7 +2483,7 @@ var OdsPlugin = /** @class */ (function (_super) {
2135
2483
  }
2136
2484
  };
2137
2485
  OdsPlugin.prototype.resolveObjectPath = function (href) {
2138
- var e_44, _a;
2486
+ var e_49, _a;
2139
2487
  if (!href)
2140
2488
  return undefined;
2141
2489
  var normalized = href.trim();
@@ -2172,12 +2520,12 @@ var OdsPlugin = /** @class */ (function (_super) {
2172
2520
  }
2173
2521
  }
2174
2522
  }
2175
- catch (e_44_1) { e_44 = { error: e_44_1 }; }
2523
+ catch (e_49_1) { e_49 = { error: e_49_1 }; }
2176
2524
  finally {
2177
2525
  try {
2178
2526
  if (candidates_1_1 && !candidates_1_1.done && (_a = candidates_1.return)) _a.call(candidates_1);
2179
2527
  }
2180
- finally { if (e_44) throw e_44.error; }
2528
+ finally { if (e_49) throw e_49.error; }
2181
2529
  }
2182
2530
  return undefined;
2183
2531
  };
@@ -2193,7 +2541,7 @@ var OdsPlugin = /** @class */ (function (_super) {
2193
2541
  return this.findNodeRecursive(doc, "chart:chart");
2194
2542
  };
2195
2543
  OdsPlugin.prototype.findNodeRecursive = function (node, key) {
2196
- var e_45, _a, e_46, _b;
2544
+ var e_50, _a, e_51, _b;
2197
2545
  if (!node || typeof node !== "object")
2198
2546
  return undefined;
2199
2547
  if (node[key]) {
@@ -2204,19 +2552,19 @@ var OdsPlugin = /** @class */ (function (_super) {
2204
2552
  var value = _d.value;
2205
2553
  if (Array.isArray(value)) {
2206
2554
  try {
2207
- for (var value_1 = (e_46 = void 0, __values(value)), value_1_1 = value_1.next(); !value_1_1.done; value_1_1 = value_1.next()) {
2555
+ for (var value_1 = (e_51 = void 0, __values(value)), value_1_1 = value_1.next(); !value_1_1.done; value_1_1 = value_1.next()) {
2208
2556
  var entry = value_1_1.value;
2209
2557
  var found = this.findNodeRecursive(entry, key);
2210
2558
  if (found)
2211
2559
  return found;
2212
2560
  }
2213
2561
  }
2214
- catch (e_46_1) { e_46 = { error: e_46_1 }; }
2562
+ catch (e_51_1) { e_51 = { error: e_51_1 }; }
2215
2563
  finally {
2216
2564
  try {
2217
2565
  if (value_1_1 && !value_1_1.done && (_b = value_1.return)) _b.call(value_1);
2218
2566
  }
2219
- finally { if (e_46) throw e_46.error; }
2567
+ finally { if (e_51) throw e_51.error; }
2220
2568
  }
2221
2569
  }
2222
2570
  else if (typeof value === "object") {
@@ -2226,21 +2574,22 @@ var OdsPlugin = /** @class */ (function (_super) {
2226
2574
  }
2227
2575
  }
2228
2576
  }
2229
- catch (e_45_1) { e_45 = { error: e_45_1 }; }
2577
+ catch (e_50_1) { e_50 = { error: e_50_1 }; }
2230
2578
  finally {
2231
2579
  try {
2232
2580
  if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
2233
2581
  }
2234
- finally { if (e_45) throw e_45.error; }
2582
+ finally { if (e_50) throw e_50.error; }
2235
2583
  }
2236
2584
  return undefined;
2237
2585
  };
2238
- OdsPlugin.prototype.convertChartNodeToSpec = function (chartNode, sheetNameMap, context) {
2239
- var e_47, _a;
2586
+ OdsPlugin.prototype.convertChartNodeToSpec = function (chartNode, sheetNameMap, context, styles) {
2587
+ var e_52, _a;
2240
2588
  if (!chartNode)
2241
2589
  return undefined;
2242
2590
  var chartAttrs = this.getAttributes(chartNode);
2243
- var chartType = this.mapOdsChartClassToType((chartAttrs === null || chartAttrs === void 0 ? void 0 : chartAttrs["@_chart:class"]) || (chartAttrs === null || chartAttrs === void 0 ? void 0 : chartAttrs["@_class"]));
2591
+ var chartClass = (chartAttrs === null || chartAttrs === void 0 ? void 0 : chartAttrs["@_chart:class"]) || (chartAttrs === null || chartAttrs === void 0 ? void 0 : chartAttrs["@_class"]);
2592
+ var chartType = this.mapOdsChartClassToType(chartClass);
2244
2593
  var titleNode = get(chartNode, "chart:title.chart:title-text") ||
2245
2594
  get(chartNode, "chart:title") ||
2246
2595
  get(chartNode, "title");
@@ -2249,6 +2598,8 @@ var OdsPlugin = /** @class */ (function (_super) {
2249
2598
  var plotArea = get(chartNode, "chart:plot-area") || get(chartNode, "plot-area");
2250
2599
  if (!plotArea)
2251
2600
  return undefined;
2601
+ var plotAreaAttrs = this.getAttributes(plotArea);
2602
+ var sourceChartType = this.resolveOdsSourceChartType(chartClass, chartType, (plotAreaAttrs === null || plotAreaAttrs === void 0 ? void 0 : plotAreaAttrs["@_chart:style-name"]) || (plotAreaAttrs === null || plotAreaAttrs === void 0 ? void 0 : plotAreaAttrs["@_style-name"]), styles);
2252
2603
  var seriesNodes = this.toArray(get(plotArea, "chart:series") ||
2253
2604
  get(plotArea, "chart:data-series") ||
2254
2605
  get(plotArea, "series"));
@@ -2278,7 +2629,7 @@ var OdsPlugin = /** @class */ (function (_super) {
2278
2629
  if (seriesData) {
2279
2630
  var label = this.extractSeriesLabel(seriesNode);
2280
2631
  seriesData.dataLabel = label || "Series ".concat(seriesIndex);
2281
- var color = this.extractChartSeriesColor(seriesNode);
2632
+ var color = this.extractChartSeriesColor(seriesNode, styles);
2282
2633
  if (color) {
2283
2634
  seriesData.color = color;
2284
2635
  }
@@ -2288,23 +2639,18 @@ var OdsPlugin = /** @class */ (function (_super) {
2288
2639
  }
2289
2640
  }
2290
2641
  }
2291
- catch (e_47_1) { e_47 = { error: e_47_1 }; }
2642
+ catch (e_52_1) { e_52 = { error: e_52_1 }; }
2292
2643
  finally {
2293
2644
  try {
2294
2645
  if (seriesNodes_1_1 && !seriesNodes_1_1.done && (_a = seriesNodes_1.return)) _a.call(seriesNodes_1);
2295
2646
  }
2296
- finally { if (e_47) throw e_47.error; }
2647
+ finally { if (e_52) throw e_52.error; }
2297
2648
  }
2298
2649
  if (!series.length) {
2299
2650
  return undefined;
2300
2651
  }
2301
2652
  var finalizedDomains = domains.length ? domains : [series[0]];
2302
- return {
2303
- chartType: chartType,
2304
- title: title,
2305
- domains: finalizedDomains,
2306
- series: series,
2307
- };
2653
+ return __assign({ chartType: chartType, title: title, domains: finalizedDomains, series: series }, (sourceChartType ? { sourceChartType: sourceChartType } : {}));
2308
2654
  };
2309
2655
  OdsPlugin.prototype.extractSeriesLabel = function (seriesNode) {
2310
2656
  if (!seriesNode)
@@ -2315,8 +2661,8 @@ var OdsPlugin = /** @class */ (function (_super) {
2315
2661
  var label = labelNode ? this.extractTextContent(labelNode) : undefined;
2316
2662
  return (label === null || label === void 0 ? void 0 : label.trim()) || undefined;
2317
2663
  };
2318
- OdsPlugin.prototype.extractChartSeriesColor = function (seriesNode) {
2319
- var e_48, _a, e_49, _b, e_50, _c;
2664
+ OdsPlugin.prototype.extractChartSeriesColor = function (seriesNode, styles) {
2665
+ var e_53, _a, e_54, _b, e_55, _c;
2320
2666
  if (!seriesNode)
2321
2667
  return undefined;
2322
2668
  var attrs = this.getAttributes(seriesNode);
@@ -2328,18 +2674,18 @@ var OdsPlugin = /** @class */ (function (_super) {
2328
2674
  try {
2329
2675
  for (var styleCandidates_1 = __values(styleCandidates), styleCandidates_1_1 = styleCandidates_1.next(); !styleCandidates_1_1.done; styleCandidates_1_1 = styleCandidates_1.next()) {
2330
2676
  var candidate = styleCandidates_1_1.value;
2331
- var color = this.odsStyles.getChartStyleColor(candidate);
2677
+ var color = styles.getChartStyleColor(candidate);
2332
2678
  if (color) {
2333
2679
  return typeof color === "string" ? color : undefined;
2334
2680
  }
2335
2681
  }
2336
2682
  }
2337
- catch (e_48_1) { e_48 = { error: e_48_1 }; }
2683
+ catch (e_53_1) { e_53 = { error: e_53_1 }; }
2338
2684
  finally {
2339
2685
  try {
2340
2686
  if (styleCandidates_1_1 && !styleCandidates_1_1.done && (_a = styleCandidates_1.return)) _a.call(styleCandidates_1);
2341
2687
  }
2342
- finally { if (e_48) throw e_48.error; }
2688
+ finally { if (e_53) throw e_53.error; }
2343
2689
  }
2344
2690
  var seriesProps = get(seriesNode, "chart:data-point-properties") ||
2345
2691
  get(seriesNode, "chart:series-properties");
@@ -2360,31 +2706,31 @@ var OdsPlugin = /** @class */ (function (_super) {
2360
2706
  pointAttrs === null || pointAttrs === void 0 ? void 0 : pointAttrs["@_style-name"],
2361
2707
  ];
2362
2708
  try {
2363
- for (var pointStyleCandidates_1 = (e_50 = void 0, __values(pointStyleCandidates)), pointStyleCandidates_1_1 = pointStyleCandidates_1.next(); !pointStyleCandidates_1_1.done; pointStyleCandidates_1_1 = pointStyleCandidates_1.next()) {
2709
+ for (var pointStyleCandidates_1 = (e_55 = void 0, __values(pointStyleCandidates)), pointStyleCandidates_1_1 = pointStyleCandidates_1.next(); !pointStyleCandidates_1_1.done; pointStyleCandidates_1_1 = pointStyleCandidates_1.next()) {
2364
2710
  var candidate = pointStyleCandidates_1_1.value;
2365
- var color = this.odsStyles.getChartStyleColor(candidate);
2711
+ var color = styles.getChartStyleColor(candidate);
2366
2712
  if (color)
2367
2713
  return typeof color === "string" ? color : undefined;
2368
2714
  }
2369
2715
  }
2370
- catch (e_50_1) { e_50 = { error: e_50_1 }; }
2716
+ catch (e_55_1) { e_55 = { error: e_55_1 }; }
2371
2717
  finally {
2372
2718
  try {
2373
2719
  if (pointStyleCandidates_1_1 && !pointStyleCandidates_1_1.done && (_c = pointStyleCandidates_1.return)) _c.call(pointStyleCandidates_1);
2374
2720
  }
2375
- finally { if (e_50) throw e_50.error; }
2721
+ finally { if (e_55) throw e_55.error; }
2376
2722
  }
2377
2723
  var pointColor = this.extractColorFromChartProperties(get(dataPoint, "chart:data-point-properties") || dataPoint);
2378
2724
  if (pointColor)
2379
2725
  return pointColor;
2380
2726
  }
2381
2727
  }
2382
- catch (e_49_1) { e_49 = { error: e_49_1 }; }
2728
+ catch (e_54_1) { e_54 = { error: e_54_1 }; }
2383
2729
  finally {
2384
2730
  try {
2385
2731
  if (dataPoints_1_1 && !dataPoints_1_1.done && (_b = dataPoints_1.return)) _b.call(dataPoints_1);
2386
2732
  }
2387
- finally { if (e_49) throw e_49.error; }
2733
+ finally { if (e_54) throw e_54.error; }
2388
2734
  }
2389
2735
  return undefined;
2390
2736
  };
@@ -2414,16 +2760,42 @@ var OdsPlugin = /** @class */ (function (_super) {
2414
2760
  if (normalized.includes("line") || normalized.includes("scatter")) {
2415
2761
  return "line";
2416
2762
  }
2417
- if (normalized.includes("pie")) {
2763
+ if (normalized.includes("pie") || normalized.includes("circle")) {
2418
2764
  return "pie";
2419
2765
  }
2420
- if (normalized.includes("area")) {
2766
+ // `chart:surface` degrades to area — the same 2-D base the OOXML
2767
+ // surfaceChart / surface3DChart import uses (sourceChartType SURFACE).
2768
+ if (normalized.includes("area") || normalized.includes("surface")) {
2421
2769
  return "area";
2422
2770
  }
2423
2771
  return "bar";
2424
2772
  };
2773
+ /**
2774
+ * The authored 3-D class token for an ODS chart: `chart:surface` is a
2775
+ * surface, and any other class whose plot-area style declares
2776
+ * `chart:three-dimensional="true"` maps to the OOXML 3-D variant of its
2777
+ * 2-D base (`BAR_3D`, `LINE_3D`, `PIE_3D`, `AREA_3D`). Undefined for 2-D.
2778
+ */
2779
+ OdsPlugin.prototype.resolveOdsSourceChartType = function (chartClass, chartType, plotAreaStyleName, styles) {
2780
+ var threeDimensional = styles.isChartStyleThreeDimensional(plotAreaStyleName);
2781
+ if (((chartClass === null || chartClass === void 0 ? void 0 : chartClass.toLowerCase()) || "").includes("surface")) {
2782
+ return threeDimensional ? "SURFACE_3D" : "SURFACE";
2783
+ }
2784
+ if (!threeDimensional)
2785
+ return undefined;
2786
+ switch (chartType) {
2787
+ case "bar":
2788
+ return "BAR_3D";
2789
+ case "line":
2790
+ return "LINE_3D";
2791
+ case "pie":
2792
+ return "PIE_3D";
2793
+ case "area":
2794
+ return "AREA_3D";
2795
+ }
2796
+ };
2425
2797
  OdsPlugin.prototype.findRangeString = function (node, skipKeys) {
2426
- var e_51, _a, e_52, _b;
2798
+ var e_56, _a, e_57, _b;
2427
2799
  if (!node)
2428
2800
  return undefined;
2429
2801
  var stack = [node];
@@ -2444,7 +2816,7 @@ var OdsPlugin = /** @class */ (function (_super) {
2444
2816
  if (typeof current === "object") {
2445
2817
  var attrs = current[":@"] || current;
2446
2818
  try {
2447
- for (var _c = (e_51 = void 0, __values(Object.entries(attrs))), _d = _c.next(); !_d.done; _d = _c.next()) {
2819
+ for (var _c = (e_56 = void 0, __values(Object.entries(attrs))), _d = _c.next(); !_d.done; _d = _c.next()) {
2448
2820
  var _e = __read(_d.value, 2), key = _e[0], attrValue = _e[1];
2449
2821
  if (key.startsWith("@_") &&
2450
2822
  typeof attrValue === "string" &&
@@ -2453,15 +2825,15 @@ var OdsPlugin = /** @class */ (function (_super) {
2453
2825
  }
2454
2826
  }
2455
2827
  }
2456
- catch (e_51_1) { e_51 = { error: e_51_1 }; }
2828
+ catch (e_56_1) { e_56 = { error: e_56_1 }; }
2457
2829
  finally {
2458
2830
  try {
2459
2831
  if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
2460
2832
  }
2461
- finally { if (e_51) throw e_51.error; }
2833
+ finally { if (e_56) throw e_56.error; }
2462
2834
  }
2463
2835
  try {
2464
- for (var _f = (e_52 = void 0, __values(Object.entries(current))), _g = _f.next(); !_g.done; _g = _f.next()) {
2836
+ for (var _f = (e_57 = void 0, __values(Object.entries(current))), _g = _f.next(); !_g.done; _g = _f.next()) {
2465
2837
  var _h = __read(_g.value, 2), childKey = _h[0], childValue = _h[1];
2466
2838
  if (childKey === ":@")
2467
2839
  continue;
@@ -2470,12 +2842,12 @@ var OdsPlugin = /** @class */ (function (_super) {
2470
2842
  stack.push(childValue);
2471
2843
  }
2472
2844
  }
2473
- catch (e_52_1) { e_52 = { error: e_52_1 }; }
2845
+ catch (e_57_1) { e_57 = { error: e_57_1 }; }
2474
2846
  finally {
2475
2847
  try {
2476
2848
  if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
2477
2849
  }
2478
- finally { if (e_52) throw e_52.error; }
2850
+ finally { if (e_57) throw e_57.error; }
2479
2851
  }
2480
2852
  }
2481
2853
  }
@@ -2679,7 +3051,7 @@ var OdsPlugin = /** @class */ (function (_super) {
2679
3051
  return undefined;
2680
3052
  };
2681
3053
  OdsPlugin.prototype.buildSheetNameMap = function (sheetContexts) {
2682
- var e_53, _a;
3054
+ var e_58, _a;
2683
3055
  var map = new Map();
2684
3056
  try {
2685
3057
  for (var sheetContexts_5 = __values(sheetContexts), sheetContexts_5_1 = sheetContexts_5.next(); !sheetContexts_5_1.done; sheetContexts_5_1 = sheetContexts_5.next()) {
@@ -2687,12 +3059,12 @@ var OdsPlugin = /** @class */ (function (_super) {
2687
3059
  this.registerSheetNameVariants(map, context.name, context.sheetId);
2688
3060
  }
2689
3061
  }
2690
- catch (e_53_1) { e_53 = { error: e_53_1 }; }
3062
+ catch (e_58_1) { e_58 = { error: e_58_1 }; }
2691
3063
  finally {
2692
3064
  try {
2693
3065
  if (sheetContexts_5_1 && !sheetContexts_5_1.done && (_a = sheetContexts_5.return)) _a.call(sheetContexts_5);
2694
3066
  }
2695
- finally { if (e_53) throw e_53.error; }
3067
+ finally { if (e_58) throw e_58.error; }
2696
3068
  }
2697
3069
  return map;
2698
3070
  };
@@ -2718,7 +3090,7 @@ var OdsPlugin = /** @class */ (function (_super) {
2718
3090
  return normalized;
2719
3091
  };
2720
3092
  OdsPlugin.prototype.parseRangeList = function (addresses, sheetNameMap, context) {
2721
- var e_54, _a;
3093
+ var e_59, _a;
2722
3094
  if (!addresses)
2723
3095
  return [];
2724
3096
  var segments = this.splitAddressSegments(addresses);
@@ -2732,12 +3104,12 @@ var OdsPlugin = /** @class */ (function (_super) {
2732
3104
  }
2733
3105
  }
2734
3106
  }
2735
- catch (e_54_1) { e_54 = { error: e_54_1 }; }
3107
+ catch (e_59_1) { e_59 = { error: e_59_1 }; }
2736
3108
  finally {
2737
3109
  try {
2738
3110
  if (segments_1_1 && !segments_1_1.done && (_a = segments_1.return)) _a.call(segments_1);
2739
3111
  }
2740
- finally { if (e_54) throw e_54.error; }
3112
+ finally { if (e_59) throw e_59.error; }
2741
3113
  }
2742
3114
  return ranges;
2743
3115
  };
@@ -2878,7 +3250,7 @@ var OdsPlugin = /** @class */ (function (_super) {
2878
3250
  return Array.isArray(value) ? value : [value];
2879
3251
  };
2880
3252
  OdsPlugin.prototype.expandRowCells = function (rowChildren) {
2881
- var e_55, _a;
3253
+ var e_60, _a;
2882
3254
  if (!rowChildren) {
2883
3255
  return [];
2884
3256
  }
@@ -2899,12 +3271,12 @@ var OdsPlugin = /** @class */ (function (_super) {
2899
3271
  }
2900
3272
  }
2901
3273
  }
2902
- catch (e_55_1) { e_55 = { error: e_55_1 }; }
3274
+ catch (e_60_1) { e_60 = { error: e_60_1 }; }
2903
3275
  finally {
2904
3276
  try {
2905
3277
  if (entries_2_1 && !entries_2_1.done && (_a = entries_2.return)) _a.call(entries_2);
2906
3278
  }
2907
- finally { if (e_55) throw e_55.error; }
3279
+ finally { if (e_60) throw e_60.error; }
2908
3280
  }
2909
3281
  return normalized;
2910
3282
  };
@@ -2921,7 +3293,7 @@ var OdsPlugin = /** @class */ (function (_super) {
2921
3293
  return wrapper;
2922
3294
  };
2923
3295
  OdsPlugin.prototype.extractAttributesFromNode = function (node) {
2924
- var e_56, _a, _b;
3296
+ var e_61, _a, _b;
2925
3297
  var attributes = {};
2926
3298
  var childNodes = [];
2927
3299
  if (node === undefined || node === null) {
@@ -2947,12 +3319,12 @@ var OdsPlugin = /** @class */ (function (_super) {
2947
3319
  childNodes.push((_b = {}, _b[key] = value, _b));
2948
3320
  }
2949
3321
  }
2950
- catch (e_56_1) { e_56 = { error: e_56_1 }; }
3322
+ catch (e_61_1) { e_61 = { error: e_61_1 }; }
2951
3323
  finally {
2952
3324
  try {
2953
3325
  if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
2954
3326
  }
2955
- finally { if (e_56) throw e_56.error; }
3327
+ finally { if (e_61) throw e_61.error; }
2956
3328
  }
2957
3329
  return { attributes: attributes, childNodes: childNodes };
2958
3330
  };
@@ -3029,7 +3401,7 @@ var OdsPlugin = /** @class */ (function (_super) {
3029
3401
  return this.ensureSheetCache().namedRanges;
3030
3402
  };
3031
3403
  OdsPlugin.prototype.findCalculationSettings = function (node) {
3032
- var e_57, _a;
3404
+ var e_62, _a;
3033
3405
  if (!node)
3034
3406
  return undefined;
3035
3407
  if (Array.isArray(node)) {
@@ -3041,12 +3413,12 @@ var OdsPlugin = /** @class */ (function (_super) {
3041
3413
  return found;
3042
3414
  }
3043
3415
  }
3044
- catch (e_57_1) { e_57 = { error: e_57_1 }; }
3416
+ catch (e_62_1) { e_62 = { error: e_62_1 }; }
3045
3417
  finally {
3046
3418
  try {
3047
3419
  if (node_2_1 && !node_2_1.done && (_a = node_2.return)) _a.call(node_2);
3048
3420
  }
3049
- finally { if (e_57) throw e_57.error; }
3421
+ finally { if (e_62) throw e_62.error; }
3050
3422
  }
3051
3423
  return undefined;
3052
3424
  }
@@ -3097,8 +3469,8 @@ var OdsPlugin = /** @class */ (function (_super) {
3097
3469
  };
3098
3470
  OdsPlugin.prototype.processSheetData = function () {
3099
3471
  return __asyncGenerator(this, arguments, function processSheetData_1(chunkSize, enableCellXfsRegistry, enableSharedStrings) {
3100
- var docContent, body, spreadsheet, tables, totalSheets, currentSheetIndex, tableWrapper, tableNameKey, tableChildren, tableAttrs, name_4, sheetId, tableStyleName, tableCellFormat, rows, columnWrappers, columnFormats, formattedColumnIndex, columnWrappers_1, columnWrappers_1_1, columnWrapper, columnAttrs, colsRepeated, columnStyleName, columnStyle, columnCellFormat, col, chunkIndex, currentChunk, currentChunkRowIndices, currentRowIndex, dvStamper, _a, rows_4, rows_4_1, rowWrapper, rowNameKey, rowChildren, rowAttrs, rowsRepeated, rowStyleName, rowStyle, rowCellFormat, rowBaseFormat, effectiveRepeats, r, rowData, columnIndex, normalizedRowChildren, normalizedRowChildren_3, normalizedRowChildren_3_1, cellWrapper, isCell, isCovered, cellNameKey, cellChildren, cellAttrs, colsRepeated, valueType, cellValue, displayValue, textFormatRuns, textPWrapper, textPKey, richText, hyperlinkValue, cellData, formula, isSharedString, excelFormula, matrixCols, matrixRows, cols, rows_5, start, end, cellStyleName, cellFormat, hasCellValue, c, targetColumnIndex, mergedFormat, alignment, needsDefaultRightAlign, displaySuggestsCurrency, currencySymbol, pattern, shouldInferNumberFormat, detectionSource, _b, detectedValueType, detectedNumberFormatType, detectedPattern, shouldOverrideExistingFormat, finalCellData, styleId, sheetSparklines, rowSparklines, _c, _d, _e, colIndex, sparkline, existingCell, sparklineData, sparklineOptions, cellData, isRowEmpty, e_58_1, _f, _g, trailing, e_59_1, error_1;
3101
- var e_60, _h, e_58, _j, e_61, _k, e_62, _l, e_59, _m;
3472
+ var docContent, body, spreadsheet, tables, totalSheets, currentSheetIndex, tableWrapper, tableNameKey, tableChildren, tableAttrs, name_4, sheetId, tableStyleName, tableCellFormat, rows, columnWrappers, columnFormats, formattedColumnIndex, columnWrappers_1, columnWrappers_1_1, columnWrapper, columnAttrs, colsRepeated, columnStyleName, columnStyle, columnCellFormat, col, chunkIndex, currentChunk, currentChunkRowIndices, currentRowIndex, dvStamper, _a, rows_4, rows_4_1, rowWrapper, rowNameKey, rowChildren, rowAttrs, rowsRepeated, rowStyleName, rowStyle, rowCellFormat, rowBaseFormat, effectiveRepeats, r, rowData, columnIndex, normalizedRowChildren, normalizedRowChildren_3, normalizedRowChildren_3_1, cellWrapper, isCell, isCovered, cellNameKey, cellChildren, cellAttrs, colsRepeated, valueType, cellValue, displayValue, textFormatRuns, textPWrapper, textPKey, richText, hyperlinkValue, cellData, formula, isSharedString, excelFormula, matrixCols, matrixRows, cols, rows_5, start, end, cellStyleName, cellFormat, hasCellValue, c, targetColumnIndex, mergedFormat, alignment, needsDefaultRightAlign, displaySuggestsCurrency, currencySymbol, pattern, shouldInferNumberFormat, detectionSource, _b, detectedValueType, detectedNumberFormatType, detectedPattern, shouldOverrideExistingFormat, finalCellData, styleId, sheetSparklines, rowSparklines, _c, _d, _e, colIndex, sparkline, existingCell, sparklineData, sparklineOptions, cellData, isRowEmpty, e_63_1, _f, _g, trailing, e_64_1, error_1;
3473
+ var e_65, _h, e_63, _j, e_66, _k, e_67, _l, e_64, _m;
3102
3474
  var _o, _p, _q, _r;
3103
3475
  if (chunkSize === void 0) { chunkSize = 100; }
3104
3476
  if (enableCellXfsRegistry === void 0) { enableCellXfsRegistry = false; }
@@ -3149,12 +3521,12 @@ var OdsPlugin = /** @class */ (function (_super) {
3149
3521
  tableCellFormat = tableStyleName
3150
3522
  ? this.odsStyles.getTableCellFormat(tableStyleName)
3151
3523
  : undefined;
3152
- rows = tableChildren.filter(function (child) { return child["table:table-row"] || child["table-row"]; });
3153
- columnWrappers = tableChildren.filter(function (child) { return child["table:table-column"] || child["table-column"]; });
3524
+ rows = flattenOrderedRows(tableChildren);
3525
+ columnWrappers = flattenOrderedColumns(tableChildren);
3154
3526
  columnFormats = new Map();
3155
3527
  formattedColumnIndex = 1;
3156
3528
  try {
3157
- for (columnWrappers_1 = (e_60 = void 0, __values(columnWrappers)), columnWrappers_1_1 = columnWrappers_1.next(); !columnWrappers_1_1.done; columnWrappers_1_1 = columnWrappers_1.next()) {
3529
+ for (columnWrappers_1 = (e_65 = void 0, __values(columnWrappers)), columnWrappers_1_1 = columnWrappers_1.next(); !columnWrappers_1_1.done; columnWrappers_1_1 = columnWrappers_1.next()) {
3158
3530
  columnWrapper = columnWrappers_1_1.value;
3159
3531
  columnAttrs = columnWrapper[":@"] || {};
3160
3532
  colsRepeated = parseInt(columnAttrs["@_table:number-columns-repeated"] ||
@@ -3173,12 +3545,12 @@ var OdsPlugin = /** @class */ (function (_super) {
3173
3545
  }
3174
3546
  }
3175
3547
  }
3176
- catch (e_60_1) { e_60 = { error: e_60_1 }; }
3548
+ catch (e_65_1) { e_65 = { error: e_65_1 }; }
3177
3549
  finally {
3178
3550
  try {
3179
3551
  if (columnWrappers_1_1 && !columnWrappers_1_1.done && (_h = columnWrappers_1.return)) _h.call(columnWrappers_1);
3180
3552
  }
3181
- finally { if (e_60) throw e_60.error; }
3553
+ finally { if (e_65) throw e_65.error; }
3182
3554
  }
3183
3555
  chunkIndex = 0;
3184
3556
  currentChunk = [];
@@ -3191,7 +3563,7 @@ var OdsPlugin = /** @class */ (function (_super) {
3191
3563
  _s.label = 11;
3192
3564
  case 11:
3193
3565
  _s.trys.push([11, 19, 20, 21]);
3194
- rows_4 = (e_58 = void 0, __values(rows)), rows_4_1 = rows_4.next();
3566
+ rows_4 = (e_63 = void 0, __values(rows)), rows_4_1 = rows_4.next();
3195
3567
  _s.label = 12;
3196
3568
  case 12:
3197
3569
  if (!!rows_4_1.done) return [3 /*break*/, 18];
@@ -3224,7 +3596,7 @@ var OdsPlugin = /** @class */ (function (_super) {
3224
3596
  : null;
3225
3597
  if (normalizedRowChildren) {
3226
3598
  try {
3227
- for (normalizedRowChildren_3 = (e_61 = void 0, __values(normalizedRowChildren)), normalizedRowChildren_3_1 = normalizedRowChildren_3.next(); !normalizedRowChildren_3_1.done; normalizedRowChildren_3_1 = normalizedRowChildren_3.next()) {
3599
+ for (normalizedRowChildren_3 = (e_66 = void 0, __values(normalizedRowChildren)), normalizedRowChildren_3_1 = normalizedRowChildren_3.next(); !normalizedRowChildren_3_1.done; normalizedRowChildren_3_1 = normalizedRowChildren_3.next()) {
3228
3600
  cellWrapper = normalizedRowChildren_3_1.value;
3229
3601
  isCell = !!cellWrapper["table:table-cell"];
3230
3602
  isCovered = !!cellWrapper["table:covered-table-cell"];
@@ -3433,12 +3805,12 @@ var OdsPlugin = /** @class */ (function (_super) {
3433
3805
  }
3434
3806
  }
3435
3807
  }
3436
- catch (e_61_1) { e_61 = { error: e_61_1 }; }
3808
+ catch (e_66_1) { e_66 = { error: e_66_1 }; }
3437
3809
  finally {
3438
3810
  try {
3439
3811
  if (normalizedRowChildren_3_1 && !normalizedRowChildren_3_1.done && (_k = normalizedRowChildren_3.return)) _k.call(normalizedRowChildren_3);
3440
3812
  }
3441
- finally { if (e_61) throw e_61.error; }
3813
+ finally { if (e_66) throw e_66.error; }
3442
3814
  }
3443
3815
  }
3444
3816
  sheetSparklines = this.sparklinesBySheet.get(sheetId);
@@ -3446,7 +3818,7 @@ var OdsPlugin = /** @class */ (function (_super) {
3446
3818
  rowSparklines = sheetSparklines.get(currentRowIndex);
3447
3819
  if (rowSparklines) {
3448
3820
  try {
3449
- for (_c = (e_62 = void 0, __values(rowSparklines.entries())), _d = _c.next(); !_d.done; _d = _c.next()) {
3821
+ for (_c = (e_67 = void 0, __values(rowSparklines.entries())), _d = _c.next(); !_d.done; _d = _c.next()) {
3450
3822
  _e = __read(_d.value, 2), colIndex = _e[0], sparkline = _e[1];
3451
3823
  existingCell = rowData.values[colIndex];
3452
3824
  // Only set formula if cell doesn't already have one
@@ -3475,12 +3847,12 @@ var OdsPlugin = /** @class */ (function (_super) {
3475
3847
  rowData.values[colIndex] = cellData;
3476
3848
  }
3477
3849
  }
3478
- catch (e_62_1) { e_62 = { error: e_62_1 }; }
3850
+ catch (e_67_1) { e_67 = { error: e_67_1 }; }
3479
3851
  finally {
3480
3852
  try {
3481
3853
  if (_d && !_d.done && (_l = _c.return)) _l.call(_c);
3482
3854
  }
3483
- finally { if (e_62) throw e_62.error; }
3855
+ finally { if (e_67) throw e_67.error; }
3484
3856
  }
3485
3857
  // Clean up processed sparklines
3486
3858
  sheetSparklines.delete(currentRowIndex);
@@ -3529,18 +3901,18 @@ var OdsPlugin = /** @class */ (function (_super) {
3529
3901
  return [3 /*break*/, 12];
3530
3902
  case 18: return [3 /*break*/, 21];
3531
3903
  case 19:
3532
- e_58_1 = _s.sent();
3533
- e_58 = { error: e_58_1 };
3904
+ e_63_1 = _s.sent();
3905
+ e_63 = { error: e_63_1 };
3534
3906
  return [3 /*break*/, 21];
3535
3907
  case 20:
3536
3908
  try {
3537
3909
  if (rows_4_1 && !rows_4_1.done && (_j = rows_4.return)) _j.call(rows_4);
3538
3910
  }
3539
- finally { if (e_58) throw e_58.error; }
3911
+ finally { if (e_63) throw e_63.error; }
3540
3912
  return [7 /*endfinally*/];
3541
3913
  case 21:
3542
3914
  _s.trys.push([21, 27, 28, 29]);
3543
- _f = (e_59 = void 0, __values(dvStamper.trailingRows())), _g = _f.next();
3915
+ _f = (e_64 = void 0, __values(dvStamper.trailingRows())), _g = _f.next();
3544
3916
  _s.label = 22;
3545
3917
  case 22:
3546
3918
  if (!!_g.done) return [3 /*break*/, 26];
@@ -3574,14 +3946,14 @@ var OdsPlugin = /** @class */ (function (_super) {
3574
3946
  return [3 /*break*/, 22];
3575
3947
  case 26: return [3 /*break*/, 29];
3576
3948
  case 27:
3577
- e_59_1 = _s.sent();
3578
- e_59 = { error: e_59_1 };
3949
+ e_64_1 = _s.sent();
3950
+ e_64 = { error: e_64_1 };
3579
3951
  return [3 /*break*/, 29];
3580
3952
  case 28:
3581
3953
  try {
3582
3954
  if (_g && !_g.done && (_m = _f.return)) _m.call(_f);
3583
3955
  }
3584
- finally { if (e_59) throw e_59.error; }
3956
+ finally { if (e_64) throw e_64.error; }
3585
3957
  return [7 /*endfinally*/];
3586
3958
  case 29:
3587
3959
  if (!(currentChunk.length > 0)) return [3 /*break*/, 32];