@evotecit/officeimo 0.1.4 → 0.1.9

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 (36) hide show
  1. package/README.md +18 -4
  2. package/bundles/officeimo-canopyx-adapter.js +1444 -0
  3. package/bundles/officeimo-canopyx-adapter.min.js +2 -0
  4. package/bundles/officeimo-canopyx-adapter.min.mjs +2 -0
  5. package/bundles/officeimo-canopyx-adapter.mjs +1426 -0
  6. package/bundles/officeimo-canopyx.js +108 -50
  7. package/bundles/officeimo-canopyx.min.js +2 -0
  8. package/bundles/officeimo-canopyx.min.mjs +2 -0
  9. package/bundles/officeimo-canopyx.mjs +96 -38
  10. package/bundles/officeimo-csv.min.js +2 -0
  11. package/bundles/officeimo-csv.min.mjs +2 -0
  12. package/bundles/officeimo-datatables-adapter.js +626 -0
  13. package/bundles/officeimo-datatables-adapter.min.js +2 -0
  14. package/bundles/officeimo-datatables-adapter.min.mjs +2 -0
  15. package/bundles/officeimo-datatables-adapter.mjs +617 -0
  16. package/bundles/officeimo-datatables.js +55 -10
  17. package/bundles/officeimo-datatables.min.js +2 -0
  18. package/bundles/officeimo-datatables.min.mjs +2 -0
  19. package/bundles/officeimo-datatables.mjs +51 -6
  20. package/bundles/officeimo-execution.min.js +2 -0
  21. package/bundles/officeimo-execution.min.mjs +2 -0
  22. package/bundles/officeimo-pdf.min.js +2 -0
  23. package/bundles/officeimo-pdf.min.mjs +2 -0
  24. package/bundles/officeimo-xlsx.min.js +2 -0
  25. package/bundles/officeimo-xlsx.min.mjs +2 -0
  26. package/bundles/officeimo.min.js +2 -0
  27. package/bundles/officeimo.min.mjs +2 -0
  28. package/bundles/officeimo.mjs +2 -1
  29. package/dist/integrations/canopyx/pdf-number.d.ts +1 -1
  30. package/dist/integrations/canopyx/pdf-number.js +89 -35
  31. package/dist/integrations/canopyx/pivot.d.ts +1 -1
  32. package/dist/integrations/canopyx/pivot.js +4 -0
  33. package/dist/integrations/canopyx/source.js +2 -2
  34. package/dist/integrations/canopyx/types.d.ts +1 -0
  35. package/dist/integrations/datatables/snapshot.js +51 -6
  36. package/package.json +6 -2
@@ -0,0 +1,626 @@
1
+ // Generated by OfficeIMO.JavaScript/scripts/bundles.mjs from tsc output. MIT.
2
+ (function (root) {
3
+ "use strict";
4
+ const officeimo = root.OfficeIMO || (root.OfficeIMO = {});
5
+ const cacheKey = Symbol.for("@evotecit/officeimo/modules");
6
+ const _modules = officeimo[cacheKey];
7
+ const _core = key => { const value = _modules && _modules.get(key); if (!value) throw new Error("officeimo-datatables-adapter.js needs officeimo.js or officeimo.min.js from the same OfficeIMO build, loaded first."); return value; };
8
+ const _c0 = _core("81b3d47c02b7d8443b79e02b3cfb52032d6b73d9a3fb592b777ebe028ad0ef00");
9
+ const _c1 = _core("6cfd3e806439f6301003a2d1699a74fdfa574d935550ab62b97b528728eaee1f");
10
+ const _c2 = _core("b48bcab805d4c75294dd8d8e8dc57f96d9db3f5af31a8f0ddc6562f010f566e4");
11
+ const _c3 = _core("d6587a933b36ccfdba9a2a252389924ac8461f672b3a500082cceb5e53c8b0b6");
12
+ const _c4 = _core("027aafa08408056b10d7d717d63d1f7c0ee20ecfc68213aa66feacc75ec525fe");
13
+ const _c5 = _core("a10003e971cd5ec2cee127bc9b029a0aa06fe3d50112838929d7a04a55e177c0");
14
+ const _c6 = _core("732224f6995c2478cf33a6ed01f3e3d3dcccb159a731d6db9280104bd5040fc5");
15
+ const _c7 = _core("d56b24243cff6f3552a2f7b45521af4491494375ec76117e9ac1ebb047ce02da");
16
+ const _c8 = _core("87c24efeaa0f1579c19afeeb4918caeb4f8f65a88d24a246e2cfd712b37dbac3");
17
+ const _c9 = _core("42faf379960e5674a6fdfa8c8fca0bb68bbd74587231248d2524d7004def3671");
18
+ const _c10 = _core("50b3c10b690ceff693c8c5f809195ba6845b20e60f408e791a750d2ecbd5c669");
19
+ const _c11 = _core("0391fe35ea7d02b25804ab4d0e7543136d6bb615f368f268c74aa135f23aa6bc");
20
+ const _c12 = _core("f0627ba89e5c8fcb376ebe3ce72dcc8d68c34952981f8703e36b8bb1a9894208");
21
+ const _c13 = _core("4a089607f7cbe50e13d4382d1cc4e5f6ce32c5773bbec2df84178710f54d9a38");
22
+ const _c14 = _core("477ff98f49343b8ec4213008254b57a60dd42d07cb9843b3791d5e5f8e295865");
23
+ const _c15 = _core("d9c1509dff0538488752433e47cd0927ece5f93c559ad0e32dc56602dfd44596");
24
+ const _m7 = _modules.get("e37eb5f0298d8bc9492db790f163f4a1d6d8b4293981cfdacfcd9d9810ec9b7f") ?? (() => {
25
+ /** @internal Runtime-checked calls across the optional third-party API boundary. */
26
+ function call(owner, name, ...args) {
27
+ const fn = member(owner, name);
28
+ if (typeof fn !== "function")
29
+ throw new TypeError("DataTables API requires " + name + "().");
30
+ return Reflect.apply(fn, owner, args);
31
+ }
32
+ /** @internal */
33
+ function member(owner, name) {
34
+ return owner != null && (typeof owner === "object" || typeof owner === "function")
35
+ ? owner[name] : undefined;
36
+ }
37
+ /** @internal */
38
+ function array(value) {
39
+ const result = Array.isArray(value) ? value : call(value, "toArray");
40
+ if (!Array.isArray(result))
41
+ throw new TypeError("DataTables API must return an array.");
42
+ return result;
43
+ }
44
+ /** @internal */
45
+ function indexes(value) {
46
+ return array(call(value, "indexes")).map(index => {
47
+ if (!Number.isSafeInteger(index) || index < 0)
48
+ throw new TypeError("Invalid DataTables index.");
49
+ return index;
50
+ });
51
+ }
52
+ const _exports = Object.freeze({ call: call, member: member, array: array, indexes: indexes });
53
+ _modules.set("e37eb5f0298d8bc9492db790f163f4a1d6d8b4293981cfdacfcd9d9810ec9b7f", _exports);
54
+ return _exports;
55
+ })();
56
+
57
+ const _m8 = _modules.get("0e5ede7759618ed3ec827d34fbd62b205f3a5241650504807c24e5323a2496a5") ?? (() => {
58
+ const { ExportCell, assertExportValue } = _c6;
59
+
60
+ const { tableSpans } = _c7;
61
+
62
+ const { member } = _m7;
63
+
64
+ /** @internal */
65
+ function value(input) {
66
+ assertExportValue(input);
67
+ return input;
68
+ }
69
+ /** @internal */
70
+ function text(input) {
71
+ const scalar = value(input);
72
+ return String(scalar instanceof ExportCell ? scalar.text ?? scalar.value ?? "" : scalar ?? "");
73
+ }
74
+ /** @internal Horizontal hierarchy maps to the existing shared Column.groups contract. */
75
+ function headings(structure, leaf, mode) {
76
+ const groups = leaf.map(() => []);
77
+ if (mode === "leaf" || !Array.isArray(structure) || !structure.length)
78
+ return { rows: [leaf.map(value)], groups };
79
+ if (mode === "structured") {
80
+ const cells = structure.map((row) => {
81
+ if (!Array.isArray(row))
82
+ throw new TypeError("Invalid DataTables heading structure.");
83
+ return row.map((cell) => cell == null ? null : Object.freeze({ value: value(member(cell, "title")),
84
+ columnSpan: member(cell, "colspan"), rowSpan: member(cell, "rowspan") }));
85
+ });
86
+ tableSpans(cells, leaf.length);
87
+ return { rows: cells.map(row => row.map(cell => cell?.value ?? "")), groups, structure: Object.freeze(cells.map(row => Object.freeze(row))) };
88
+ }
89
+ const rows = structure.map((source, level) => {
90
+ if (!Array.isArray(source) || source.length !== leaf.length)
91
+ throw new TypeError("Invalid DataTables heading structure.");
92
+ const row = leaf.map(() => "");
93
+ for (let index = 0; index < source.length;) {
94
+ const cell = source[index];
95
+ const span = member(cell, "colspan"), height = member(cell, "rowspan");
96
+ if (cell == null || height !== 1 || !Number.isInteger(span) || span < 1 || index + span > leaf.length)
97
+ throw new TypeError("Grouped export requires horizontal header spans; select headings: 'leaf' for vertical spans.");
98
+ if (level === structure.length - 1 && span !== 1)
99
+ throw new TypeError("Grouped export requires one leaf header per column.");
100
+ const title = text(member(cell, "title"));
101
+ row[index] = title;
102
+ if (span !== 1 && !title)
103
+ throw new TypeError("Blank spanning headings require headings: 'leaf'.");
104
+ for (let covered = index; covered < index + span; covered++) {
105
+ if (covered !== index && source[covered] != null)
106
+ throw new TypeError("Invalid overlapping DataTables heading cells.");
107
+ if (level < structure.length - 1)
108
+ groups[covered].push(title);
109
+ }
110
+ index += span;
111
+ }
112
+ return row;
113
+ });
114
+ // The shared layout merges equal adjacent group paths. Reject distinct source cells
115
+ // that would otherwise become one merge instead of changing their structure silently.
116
+ for (let level = 0; level < rows.length - 1; level++) {
117
+ const source = structure[level];
118
+ for (let index = 1; index < source.length; index++) {
119
+ if (source[index] != null && groups[index][level] &&
120
+ JSON.stringify(groups[index].slice(0, level + 1)) === JSON.stringify(groups[index - 1].slice(0, level + 1)))
121
+ throw new TypeError("Adjacent separate headings with equal group paths require headings: 'leaf'.");
122
+ }
123
+ }
124
+ return { rows, groups };
125
+ }
126
+ const _exports = Object.freeze({ value: value, text: text, headings: headings });
127
+ _modules.set("0e5ede7759618ed3ec827d34fbd62b205f3a5241650504807c24e5323a2496a5", _exports);
128
+ return _exports;
129
+ })();
130
+
131
+ const _m11 = _modules.get("8edb7b3b19d6555ea24a92d771d532dc0448ad18101fdf663217b4c518b5a31b") ?? (() => {
132
+ const { checkAbort, pause, rowsFromBatches, taskYieldDue } = _c8;
133
+
134
+ const { ExportBudget } = _c9;
135
+
136
+ const { captureFields } = _c10;
137
+
138
+ const { columnOptionFields, copyColumns } = _c11;
139
+
140
+ const { array, call, indexes, member } = _m7;
141
+
142
+ const { headings, text, value } = _m8;
143
+
144
+ function safeOptions(options) {
145
+ options = captureFields(options, ["rows", "columns", "modifier", "orthogonal", "stripHtml", "stripNewlines", "decodeEntities", "escapeExcelFormula", "trim", "format", "customizeData"]);
146
+ const format = options.format && captureFields(options.format, ["header", "footer", "body"]), customize = options.customizeData;
147
+ return { ...options, ...(format ? { format: {
148
+ ...(format.header ? { header: (v, c, n) => value(format.header(v, c, n)) } : {}),
149
+ ...(format.footer ? { footer: (v, c, n) => value(format.footer(v, c, n)) } : {}),
150
+ ...(format.body ? { body: (v, r, c, n) => value(format.body(v, r, c, n)) } : {})
151
+ } } : {}), ...(customize ? { customizeData: (data) => {
152
+ const result = customize(data);
153
+ // Buttons ignores synchronous return values; only asynchronous callbacks violate this contract.
154
+ if (typeof member(result, "then") === "function")
155
+ value(result);
156
+ } } : {}) };
157
+ }
158
+ /** Buttons builds the heading structures before customizeData runs; carry changed leaf labels into their bottom row. */
159
+ function customizedStructure(structure, before, after, kind) {
160
+ if (!before || !Array.isArray(structure) || !structure.length)
161
+ return structure;
162
+ const changed = after.map((label, index) => !Object.is(label, before[index]));
163
+ if (!changed.some(Boolean))
164
+ return structure;
165
+ return structure.map((row, level) => !Array.isArray(row) ? row : row.map((cell, index) => {
166
+ if (cell == null || level + (Number(member(cell, "rowspan")) || 1) !== structure.length)
167
+ return cell;
168
+ const span = Number(member(cell, "colspan")) || 1;
169
+ if (!changed.slice(index, index + span).some(Boolean))
170
+ return cell;
171
+ if (span !== 1)
172
+ throw new TypeError("customizeData cannot change one column of a spanning " + kind + " cell.");
173
+ return { ...cell, title: after[index] };
174
+ }));
175
+ }
176
+ /** A customizeData reorder is visible as a permutation of distinct leaf labels; map each output column to its source. */
177
+ function reorderedSources(before, after) {
178
+ if (!before || before.length !== after.length || new Set(before).size !== before.length)
179
+ return undefined;
180
+ const sources = after.map(label => before.indexOf(label));
181
+ return sources.every(source => source >= 0) && new Set(sources).size === sources.length && sources.some((source, index) => source !== index) ? sources : undefined;
182
+ }
183
+ /** Capture export scope and headings, then produce values in bounded batches using public DataTables APIs. */
184
+ function createDataTablesExport(host, table, options = {}) {
185
+ return captureDataTablesExport(host, table, options);
186
+ }
187
+ /** @internal Writers omit source structures only when their output explicitly suppresses or replaces them. */
188
+ function captureDataTablesExport(host, table, options = {}, omitted) {
189
+ options = captureFields(options, ["mode", "exportOptions", "batchRows", "maxBatchCells", "headings", "includeFooter", "serverSide", "columnOptions", "project", "signal", "limits", "onProgress"]);
190
+ if (options.columnOptions !== undefined) {
191
+ const columnOptions = Object.fromEntries(Object.entries(options.columnOptions).map(([index, column]) => [index,
192
+ captureFields(column, columnOptionFields)]));
193
+ options = { ...options, columnOptions };
194
+ }
195
+ for (const column of Object.values(options.columnOptions ?? {}))
196
+ if (column.style !== undefined)
197
+ throw new TypeError("Workbook-local column styles require the advanced Workbook API; use portable ExportCell presentation.");
198
+ const mode = options.mode ?? "batched", headingMode = options.headings ?? "grouped";
199
+ if (!["batched", "compatibility"].includes(mode))
200
+ throw new TypeError("Unknown DataTables export mode.");
201
+ if (!["grouped", "leaf", "structured"].includes(headingMode))
202
+ throw new TypeError("Unknown DataTables heading mode.");
203
+ if (options.serverSide !== undefined && !["reject", "loaded"].includes(options.serverSide))
204
+ throw new TypeError("Unknown server-side export policy.");
205
+ const batchRows = options.batchRows ?? 4096, maxBatchCells = options.maxBatchCells ?? 65536;
206
+ if (!Number.isInteger(batchRows) || batchRows < 1 || batchRows > 4096)
207
+ throw new RangeError("batchRows must be between 1 and 4,096.");
208
+ if (!Number.isSafeInteger(maxBatchCells) || maxBatchCells < 1)
209
+ throw new RangeError("maxBatchCells must be a positive safe integer.");
210
+ const signal = options.signal, projectValue = options.project, budget = new ExportBudget(options.limits);
211
+ checkAbort(signal);
212
+ if (member(call(table.page, "info"), "serverSide") && options.serverSide !== "loaded")
213
+ throw new TypeError("Server-side DataTables exports require a separate full-data source or explicit serverSide: 'loaded'.");
214
+ const config = safeOptions(options.exportOptions ?? {});
215
+ const stripOptions = { stripHtml: true, stripNewlines: true, decodeEntities: true, trim: true, ...config };
216
+ const stripOwner = host.Buttons, strip = member(stripOwner, "stripData");
217
+ const stripData = typeof strip === "function" ? strip.bind(stripOwner) : undefined;
218
+ if (mode === "batched" && !config.format?.body && typeof strip !== "function")
219
+ throw new TypeError("DataTables API requires stripData().");
220
+ if (mode === "batched" && config.customizeData)
221
+ throw new TypeError("customizeData requires compatibility mode.");
222
+ if (config.customizeData && options.project)
223
+ throw new TypeError("project cannot identify source indexes after customizeData.");
224
+ const modifier = { search: "applied", order: "applied", ...config.modifier };
225
+ if (member(modifier, "selected") === undefined && typeof member(member(table, "select"), "info") === "function"
226
+ && Number(call(call(table, "rows", config.rows ?? null, { ...modifier, selected: true }), "count")) > 0)
227
+ Object.assign(modifier, { selected: true });
228
+ const rowIndexes = indexes(call(table, "rows", config.rows ?? null, modifier));
229
+ const columnIndexes = indexes(call(table, "columns", config.columns ?? ""));
230
+ if (columnIndexes.length > maxBatchCells)
231
+ throw new RangeError("A selected row exceeds maxBatchCells.");
232
+ if (new Set(rowIndexes).size !== rowIndexes.length || new Set(columnIndexes).size !== columnIndexes.length)
233
+ throw new TypeError("DataTables export indexes must be unique.");
234
+ let before;
235
+ const customize = config.customizeData;
236
+ const data = call(table.buttons, "exportData", { ...config, modifier, ...(mode === "batched" ? { rows: [] } : {}),
237
+ ...(customize ? { customizeData: (input) => {
238
+ const footer = member(input, "footer");
239
+ before = { header: [...array(member(input, "header"))], footer: footer == null ? undefined : [...array(footer)] };
240
+ customize(input);
241
+ } } : {}) });
242
+ const leaf = array(member(data, "header"));
243
+ if (leaf.length !== columnIndexes.length)
244
+ throw new TypeError("Export header must match the selected columns.");
245
+ // Only structured output reaches the source structures' bottom row; leaf and grouped headings take the leaf labels.
246
+ const structured = headingMode === "structured" && !omitted?.header;
247
+ const sourceStructure = omitted?.header ? undefined : member(data, "headerStructure");
248
+ const heading = headings(structured ? customizedStructure(sourceStructure, before?.header, leaf, "header") : sourceStructure, leaf, omitted?.header ? "leaf" : headingMode);
249
+ const reordered = reorderedSources(before?.header, leaf);
250
+ if (reordered && heading.rows.length > 1)
251
+ throw new TypeError("customizeData cannot reorder columns under grouped headings; select headings: 'leaf' or reorder the table's columns.");
252
+ // Column options and keys follow each column to its new position after a customizeData reorder. Any other heading
253
+ // change (a rename, or a reorder with a rename) leaves no reliable source mapping for column options.
254
+ if (before && !reordered && before.header.some((label, index) => !Object.is(label, leaf[index])) &&
255
+ columnIndexes.some(index => options.columnOptions?.[index] !== undefined))
256
+ throw new TypeError("customizeData changed column headings, so columnOptions cannot be matched to columns; rename columns with columnOptions header instead.");
257
+ const sourceColumns = reordered ? reordered.map(source => columnIndexes[source]) : columnIndexes;
258
+ for (const index of columnIndexes)
259
+ if (member(options.columnOptions?.[index], "value") !== undefined)
260
+ throw new TypeError("DataTables columnOptions describes columns; resolve values with project.");
261
+ const columns = Object.freeze(copyColumns(leaf.map((label, index) => ({
262
+ header: text(label), key: "dt:" + sourceColumns[index], ...options.columnOptions?.[sourceColumns[index]],
263
+ ...(heading.groups[index].length ? { groups: Object.freeze(heading.groups[index]) } : {})
264
+ }))).map(column => Object.freeze(column)));
265
+ // Explicit heading overrides also apply to CSV's leaf heading.
266
+ if (!heading.structure)
267
+ heading.rows[heading.rows.length - 1] = columns.map(column => column.header);
268
+ const headerStructure = heading.structure?.map((row, level) => Object.freeze(row.map((cell, index) => {
269
+ if (!cell || level + (cell.rowSpan ?? 1) !== heading.structure.length)
270
+ return cell;
271
+ const override = options.columnOptions?.[sourceColumns[index]]?.header;
272
+ if ((cell.columnSpan ?? 1) > 1 && sourceColumns.slice(index, index + (cell.columnSpan ?? 1)).some(c => options.columnOptions?.[c]?.header !== undefined))
273
+ throw new TypeError("A spanning leaf heading cannot have per-column header overrides.");
274
+ return override === undefined ? cell : Object.freeze({ ...cell, value: override });
275
+ })));
276
+ const includeSourceFooter = options.includeFooter !== false && omitted?.footer !== true;
277
+ const footerStructure = includeSourceFooter ? member(data, "footerStructure") : undefined;
278
+ if (headingMode !== "structured" && includeSourceFooter && Array.isArray(footerStructure) && footerStructure.length > 1)
279
+ throw new TypeError("Only a single footer row is supported; select includeFooter: false to omit it explicitly.");
280
+ const rawFooter = includeSourceFooter ? member(data, "footer") : undefined;
281
+ const footer = rawFooter == null ? undefined : array(rawFooter).map(value);
282
+ if (footer && footer.length !== columns.length)
283
+ throw new TypeError("Export footer must match the selected columns.");
284
+ const footerHeading = footer && Array.isArray(footerStructure) && footerStructure.length
285
+ ? headings(headingMode === "structured" ? customizedStructure(footerStructure, before?.footer, array(rawFooter), "footer") : footerStructure, footer, headingMode === "structured" ? "structured" : "grouped") : undefined;
286
+ const body = mode === "compatibility" ? array(member(data, "body")) : undefined;
287
+ const count = columns.length ? body?.length ?? rowIndexes.length : 0;
288
+ budget.check("maxRows", count);
289
+ const batchSize = columns.length ? Math.min(batchRows, Math.floor(maxBatchCells / columns.length)) : batchRows;
290
+ const columnPositions = new Map(columnIndexes.map((index, ordinal) => [index, ordinal]));
291
+ // Keep the public cell API context without selecting or traversing the table's rows.
292
+ const emptyCells = mode === "batched" && count ? call(table, "cells", [], []) : undefined;
293
+ if (emptyCells) {
294
+ let tables = 0;
295
+ call(emptyCells, "iterator", "table", () => { tables++; });
296
+ if (tables !== 1)
297
+ throw new TypeError("A batched export requires exactly one DataTables table.");
298
+ }
299
+ const rows = rowsFromBatches({ [Symbol.asyncIterator]: () => iterate() });
300
+ async function* iterate() {
301
+ for (let first = 0; first < count; first += batchSize) {
302
+ checkAbort(signal);
303
+ let batch;
304
+ if (body) {
305
+ batch = body.slice(first, first + batchSize).map((row, ordinal) => {
306
+ if (!Array.isArray(row) || row.length !== columns.length)
307
+ throw new TypeError("Export body row must match the selected columns.");
308
+ return row.map((cell, index) => project(cell, rowIndexes[first + ordinal] ?? first + ordinal, index, first + ordinal));
309
+ });
310
+ }
311
+ else {
312
+ const selectedRows = rowIndexes.slice(first, first + batchSize);
313
+ // Public result-set operations replace the bounded cell indexes. Row selectors would
314
+ // rescan the complete table on every batch, even with constant-time membership.
315
+ const requested = new Array(selectedRows.length * columns.length);
316
+ for (let row = 0, cell = 0; row < selectedRows.length; row++)
317
+ for (const column of columnIndexes)
318
+ requested[cell++] = { row: selectedRows[row], column };
319
+ call(emptyCells, "pop");
320
+ call(emptyCells, "push", requested);
321
+ const cells = emptyCells;
322
+ const rendered = array(call(cells, "render", config.orthogonal ?? "display"));
323
+ const positions = array(call(cells, "indexes"));
324
+ const nodes = config.format?.body ? array(call(cells, "nodes")) : undefined;
325
+ if (rendered.length !== selectedRows.length * columns.length || positions.length !== rendered.length || nodes && nodes.length > rendered.length)
326
+ throw new TypeError("The table changed or returned an incomplete export batch.");
327
+ batch = selectedRows.map(() => new Array(columns.length));
328
+ // Validate coordinates while formatting instead of scanning every cell twice.
329
+ // The usual ordered result needs no mapping or duplicate set. On the first
330
+ // reordered cell, include the already accepted ordered prefix in that set.
331
+ let rowPositions, seen;
332
+ let ordinalRow = 0, ordinalColumn = 0;
333
+ for (let cell = 0; cell < rendered.length; cell++) {
334
+ checkAbort(signal);
335
+ const rowIndex = member(positions[cell], "row"), columnIndex = member(positions[cell], "column");
336
+ if (!seen && (rowIndex !== requested[cell].row || columnIndex !== requested[cell].column)) {
337
+ rowPositions = new Map(selectedRows.map((index, ordinal) => [index, ordinal]));
338
+ seen = new Set();
339
+ for (let accepted = 0; accepted < cell; accepted++)
340
+ seen.add(accepted);
341
+ }
342
+ const row = seen ? rowPositions.get(rowIndex) : ordinalRow;
343
+ const column = seen ? columnPositions.get(columnIndex) : ordinalColumn;
344
+ if (row === undefined || column === undefined || seen?.has(row * columns.length + column))
345
+ throw new TypeError("Invalid DataTables cell indexes.");
346
+ seen?.add(row * columns.length + column);
347
+ let node = nodes?.[cell];
348
+ if (nodes && nodes.length !== rendered.length) {
349
+ // nodes() omits deferred cells without DOM nodes. Resolve each coordinate
350
+ // through the same bounded result set so compacted nodes cannot shift rows.
351
+ call(cells, "pop");
352
+ call(cells, "push", [{ row: rowIndex, column: columnIndex }]);
353
+ const exact = array(call(cells, "nodes"));
354
+ if (exact.length > 1)
355
+ throw new TypeError("Invalid DataTables cell nodes.");
356
+ node = exact[0];
357
+ }
358
+ const formatted = config.format?.body ? config.format.body(rendered[cell], rowIndex, columnIndex, node)
359
+ : stripData(rendered[cell], stripOptions);
360
+ batch[row][column] = project(formatted, rowIndex, column, first + row);
361
+ if (++ordinalColumn === columns.length) {
362
+ ordinalColumn = 0;
363
+ ordinalRow++;
364
+ }
365
+ if ((cell & 127) === 127 && taskYieldDue()) {
366
+ await pause();
367
+ checkAbort(signal);
368
+ }
369
+ }
370
+ }
371
+ checkAbort(signal);
372
+ yield batch;
373
+ if (taskYieldDue()) {
374
+ await pause();
375
+ checkAbort(signal);
376
+ }
377
+ }
378
+ }
379
+ function project(input, rowIndex, column, rowOrdinal) {
380
+ checkAbort(signal);
381
+ const scalar = value(input);
382
+ return projectValue ? value(projectValue(scalar, { sourceRowIndex: rowIndex, sourceColumnIndex: columnIndexes[column], rowIndex: rowOrdinal, columnIndex: column })) : scalar;
383
+ }
384
+ return Object.freeze({ columns, headers: Object.freeze(heading.rows.map(row => Object.freeze(row))),
385
+ footer: footer ? Object.freeze(footer) : undefined,
386
+ ...(headerStructure ? { headerStructure: Object.freeze(headerStructure) } : {}),
387
+ ...(footerHeading?.structure ? { footerStructure: footerHeading.structure } : {}), rowCount: count, rows });
388
+ }
389
+ const _exports = Object.freeze({ createDataTablesExport: createDataTablesExport, captureDataTablesExport: captureDataTablesExport });
390
+ _modules.set("8edb7b3b19d6555ea24a92d771d532dc0448ad18101fdf663217b4c518b5a31b", _exports);
391
+ return _exports;
392
+ })();
393
+
394
+ const _m16 = _modules.get("7b12a415e92cc9ef7212fb3a88007cb6dc37f9f30077165d4897cfa8052f9a3c") ?? (() => {
395
+ const { captureFields } = _c10;
396
+
397
+ const { ExportBudget } = _c9;
398
+
399
+ const { captureCsvOptions: captureCsv } = _c12;
400
+
401
+ const { capturePdfOptions: capturePdf, capturePdfLimits, pdfLimitFields } = _c13;
402
+
403
+ const { captureWorkbookLimits, workbookLimitFields, workbookOptionFields, sheetOptionFields } = _c14;
404
+
405
+ const limitFields = [...new Set([...workbookLimitFields, ...pdfLimitFields])];
406
+ const portableWorkbookFields = workbookOptionFields.filter((key) => key !== "sink");
407
+ /** Shared adapter budgets override only explicitly supplied numeric format ceilings. */
408
+ function captureCommonLimits(input) {
409
+ return input === undefined ? undefined : new ExportBudget(captureFields(input, limitFields)).limits;
410
+ }
411
+ function mergeAdapterLimits(format, common) {
412
+ const result = { ...format };
413
+ for (const [key, value] of Object.entries(common ?? {}))
414
+ if (value !== undefined)
415
+ result[key] = value;
416
+ return result;
417
+ }
418
+ /** Snapshot the format owner's fields before an adapter adds captured columns and stream policy. */
419
+ function captureXlsxOptions(input = {}) {
420
+ const options = captureFields(input, [...portableWorkbookFields, "sheet"]);
421
+ const sheet = options.sheet && captureFields(options.sheet, [...sheetOptionFields, "name"]);
422
+ const footer = sheet?.footer && captureFields(sheet.footer, ["rows", "values", "totals", "style"]);
423
+ return { ...options, ...(sheet === undefined ? {} : { sheet: { ...sheet, ...(footer === undefined ? {} : { footer }) } }),
424
+ ...(options.limits === undefined ? {} : { limits: captureWorkbookLimits(options.limits) }) };
425
+ }
426
+ function captureCsvOptions(input = {}) {
427
+ const options = captureCsv(input);
428
+ return { ...options, ...(options.limits === undefined ? {} : { limits: new ExportBudget(options.limits).limits }) };
429
+ }
430
+ function capturePdfOptions(input = {}) {
431
+ const options = capturePdf(input);
432
+ return { ...options, ...(options.limits === undefined ? {} : { limits: capturePdfLimits(options.limits) }) };
433
+ }
434
+ const _exports = Object.freeze({ captureCommonLimits: captureCommonLimits, mergeAdapterLimits: mergeAdapterLimits, captureXlsxOptions: captureXlsxOptions, captureCsvOptions: captureCsvOptions, capturePdfOptions: capturePdfOptions });
435
+ _modules.set("7b12a415e92cc9ef7212fb3a88007cb6dc37f9f30077165d4897cfa8052f9a3c", _exports);
436
+ return _exports;
437
+ })();
438
+
439
+ const _m0 = _modules.get("f5f1435b6f22ab08d91f4a58bb66e975d4427bcaf5697011e28bfa9e74b2a2ca") ?? (() => {
440
+ const { BlobByteSink, checkAbort, saveBlob } = _c0;
441
+
442
+ const { notifyProgress } = _c1;
443
+
444
+ const { writeCsvTo } = _c2;
445
+
446
+ const { writeXlsxTo } = _c3;
447
+
448
+ const { writePdfTo } = _c4;
449
+
450
+ const { portableSheet, portableWorkbook } = _c5;
451
+
452
+ const { call, member } = _m7;
453
+
454
+ const { value } = _m8;
455
+
456
+ const { captureDataTablesExport } = _m11;
457
+
458
+ const { captureFields } = _c10;
459
+
460
+ const { captureCommonLimits, captureXlsxOptions, captureCsvOptions, capturePdfOptions, mergeAdapterLimits } = _m16;
461
+
462
+
463
+
464
+
465
+
466
+
467
+
468
+ const writeOptionFields = ["mode", "exportOptions", "batchRows", "maxBatchCells", "headings", "includeFooter", "serverSide", "columnOptions", "project", "signal", "limits", "onProgress", "xlsx", "csv", "pdf"];
469
+ const buttonOptionFields = [...writeOptionFields, "filename", "save", "onError"];
470
+ /** Write directly to a caller-owned destination. Failed destinations own disposal of their partial bytes. */
471
+ async function writeDataTableTo(host, table, format, destination, options = {}) {
472
+ if (format !== "xlsx" && format !== "csv" && format !== "pdf")
473
+ throw new TypeError("DataTables export format must be xlsx, csv or pdf.");
474
+ for (const key of ["workbook", "sheet", "sheetName"])
475
+ if (key in options)
476
+ throw new TypeError("DataTables writer settings belong in xlsx; use xlsx.sheet.name for the worksheet name.");
477
+ const captured = captureFields(options, writeOptionFields);
478
+ const { signal, onProgress } = captured, limits = captureCommonLimits(captured.limits);
479
+ const xlsx = captureXlsxOptions(format === "xlsx" ? captured.xlsx : undefined);
480
+ const csv = captureCsvOptions(format === "csv" ? captured.csv : undefined);
481
+ const pdf = capturePdfOptions(format === "pdf" ? captured.pdf : undefined);
482
+ const sheet = xlsx.sheet;
483
+ if (format === "xlsx") {
484
+ portableSheet(sheet);
485
+ portableWorkbook(xlsx);
486
+ }
487
+ const replacementXlsxFooter = sheet?.footer && [sheet.footer.rows, sheet.footer.values, sheet.footer.totals].some(value => value !== undefined);
488
+ const source = captureDataTablesExport(host, table, { ...captured, ...(limits === undefined ? {} : { limits }), ...(format === "pdf" ? { headings: captured.headings ?? "structured" } : {}) }, {
489
+ header: format === "pdf" ? pdf.includeHeader === false || pdf.headerRows !== undefined
490
+ : format === "xlsx" ? sheet?.includeHeader === false || sheet?.headerRows !== undefined
491
+ : csv.includeHeader === false || csv.headerRows !== undefined,
492
+ footer: format === "pdf" ? pdf.footer !== undefined : format === "xlsx" ? Boolean(replacementXlsxFooter) : csv.footer !== undefined
493
+ });
494
+ let result;
495
+ const stream = { ...(signal ? { signal } : {}), ...(onProgress ? {
496
+ onProgress: (event) => notifyProgress(onProgress, { ...event, totalRows: source.rowCount })
497
+ } : {}) };
498
+ if (format === "xlsx") {
499
+ const sourceFooter = source.footerStructure ? { rows: source.footerStructure } : source.footer ? { values: source.footer } : undefined;
500
+ const footer = replacementXlsxFooter ? sheet?.footer : sourceFooter || sheet?.footer ? { ...sourceFooter, ...sheet?.footer } : undefined;
501
+ result = await writeXlsxTo(source.rows, destination, { ...xlsx, ...stream, columns: source.columns,
502
+ limits: mergeAdapterLimits(xlsx.limits, limits),
503
+ sheet: { ...sheet, ...(source.headerStructure && sheet?.includeHeader !== false && sheet?.headerRows === undefined ? { headerRows: source.headerStructure } : {}), ...(footer ? { footer } : {}) } });
504
+ }
505
+ else if (format === "pdf") {
506
+ const footer = pdf.footer ?? (source.footerStructure ? { rows: source.footerStructure } : source.footer ? { values: source.footer } : undefined);
507
+ result = await writePdfTo(source.rows, destination, { ...pdf, ...stream, columns: source.columns,
508
+ limits: mergeAdapterLimits(pdf.limits, limits),
509
+ ...(source.headerStructure && pdf.includeHeader !== false && !pdf.headerRows ? { headerRows: source.headerStructure } : {}),
510
+ ...(footer ? { footer } : {}) });
511
+ }
512
+ else {
513
+ const footer = csv.footer ?? (source.footerStructure ? { rows: source.footerStructure }
514
+ : source.footer ? { rows: [source.footer.map(value => ({ value }))] } : undefined);
515
+ result = await writeCsvTo(source.rows, destination, { ...csv, ...stream, columns: source.columns,
516
+ limits: mergeAdapterLimits(csv.limits, limits),
517
+ ...(csv.includeHeader !== false && csv.headerRows === undefined ? { headerRows: source.headerStructure ?? source.headers.map(row => row.map(value => ({ value }))) } : {}), ...(footer ? { footer } : {}) });
518
+ }
519
+ checkAbort(signal);
520
+ return { rows: source.rowCount, columns: source.columns.length, bytes: result.bytes };
521
+ }
522
+ /** Return a browser/worker/Node Blob. Use writeDataTableTo to avoid retaining the completed file in memory. */
523
+ async function exportDataTable(host, table, format, options = {}) {
524
+ const sink = new BlobByteSink();
525
+ try {
526
+ await writeDataTableTo(host, table, format, sink, options);
527
+ return sink.toBlob(format === "pdf" ? "application/pdf" : format === "csv" ? "text/csv;charset=utf-8" : "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
528
+ }
529
+ catch (error) {
530
+ sink.discard();
531
+ throw error;
532
+ }
533
+ }
534
+ /** Register opt-in Buttons entries; no import-time registration, DataTables import or jQuery dependency. */
535
+ function registerDataTablesButtons(host, options = {}) {
536
+ const buttons = host.ext?.buttons;
537
+ if (!buttons || typeof member(host.Buttons, "stripData") !== "function")
538
+ throw new TypeError("Install DataTables Buttons before registering OfficeIMO exports.");
539
+ if (buttons.officeimoExcel || buttons.officeimoCsv || buttons.officeimoPdf)
540
+ throw new TypeError("OfficeIMO DataTables buttons are already registered.");
541
+ for (const [name, format, label] of [["officeimoExcel", "xlsx", "Excel"], ["officeimoCsv", "csv", "CSV"], ["officeimoPdf", "pdf", "PDF"]]) {
542
+ buttons[name] = { text: label, async: 1,
543
+ action: function (_event, table, _node, configuration, complete) {
544
+ let current = options;
545
+ const finish = () => { const callback = complete; complete = undefined; callback?.(); };
546
+ void (async () => {
547
+ try {
548
+ const configured = member(configuration, "officeimo"), filename = member(configuration, "filename");
549
+ if (configured !== undefined && (!configured || typeof configured !== "object"))
550
+ throw new TypeError("Button officeimo settings must be an object.");
551
+ const defaults = captureFields(options, buttonOptionFields), overrides = captureFields((configured ?? {}), buttonOptionFields);
552
+ current = { ...defaults, ...overrides,
553
+ ...(filename !== undefined ? { filename: filename } : {}),
554
+ ...(member(configuration, "footer") === false ? { includeFooter: false } : {}),
555
+ ...(member(configuration, "exportOptions") ? { exportOptions: member(configuration, "exportOptions") } : {}) };
556
+ if (member(configuration, "customize") !== undefined)
557
+ throw new TypeError("Native customize callbacks are unsupported; use OfficeIMO xlsx/pdf options.");
558
+ if (format === "xlsx") {
559
+ const base = captureXlsxOptions(defaults.xlsx), selected = captureXlsxOptions(overrides.xlsx);
560
+ current = { ...current, xlsx: { ...base, ...selected,
561
+ ...(base.sheet || selected.sheet ? { sheet: { ...base.sheet, ...selected.sheet } } : {}) } };
562
+ }
563
+ else if (format === "csv")
564
+ current = { ...current, csv: { ...captureCsvOptions(defaults.csv), ...captureCsvOptions(overrides.csv) } };
565
+ if (format === "pdf") {
566
+ const info = call(table.buttons, "exportInfo", configuration);
567
+ const pdf = { ...capturePdfOptions(defaults.pdf), ...capturePdfOptions(overrides.pdf) };
568
+ for (const key of ["title", "messageTop", "messageBottom"])
569
+ if (member(configuration, key) !== undefined) {
570
+ if (member(configuration, key) === null) {
571
+ delete pdf[key];
572
+ continue;
573
+ }
574
+ const text = member(info, key);
575
+ if (text === null || text === "") {
576
+ delete pdf[key];
577
+ continue;
578
+ }
579
+ if (typeof text !== "string")
580
+ throw new TypeError("PDF " + key + " must resolve to text.");
581
+ pdf[key] = text;
582
+ }
583
+ for (const key of ["orientation", "pageSize"])
584
+ if (member(configuration, key) !== undefined)
585
+ Object.assign(pdf, { [key]: member(configuration, key) });
586
+ if (member(configuration, "header") === false) {
587
+ pdf.includeHeader = false;
588
+ delete pdf.headerRows;
589
+ }
590
+ if (member(configuration, "footer") === false)
591
+ delete pdf.footer;
592
+ current = { ...current, pdf };
593
+ }
594
+ else if (member(configuration, "header") === false || ["title", "messageTop", "messageBottom"].some(key => member(configuration, key) != null))
595
+ throw new TypeError("Use OfficeIMO xlsx.sheet title/footer options; native Buttons report layout options are unsupported.");
596
+ const pattern = value(typeof current.filename === "function" ? current.filename(configuration, table) : current.filename ?? "Export");
597
+ if (typeof pattern !== "string" || !pattern.trim())
598
+ throw new TypeError("Export filename must be a non-empty string.");
599
+ const file = value(member(call(table.buttons, "exportInfo", { filename: pattern, extension: "" }), "filename"));
600
+ if (typeof file !== "string" || !file.trim())
601
+ throw new TypeError("Resolved export filename must be a non-empty string.");
602
+ const blob = await exportDataTable(host, table, format, current);
603
+ await (current.save ?? saveBlob)(blob, file.toLowerCase().endsWith("." + format) ? file : file + "." + format);
604
+ }
605
+ catch (error) {
606
+ // Completion runs before the error handler so application error UI cannot strand Buttons' spinner.
607
+ finish();
608
+ if (current.onError)
609
+ await current.onError(error);
610
+ else
611
+ console.error("OfficeIMO table export failed.", error);
612
+ }
613
+ finally {
614
+ finish();
615
+ }
616
+ })().catch(error => console.error("OfficeIMO export error handler failed.", error));
617
+ }
618
+ };
619
+ }
620
+ }
621
+ const _exports = Object.freeze({ createDataTablesExport: _m11.createDataTablesExport, ExportCell: _c6.ExportCell, PdfFont: _c15.PdfFont, writeDataTableTo: writeDataTableTo, exportDataTable: exportDataTable, registerDataTablesButtons: registerDataTablesButtons });
622
+ _modules.set("f5f1435b6f22ab08d91f4a58bb66e975d4427bcaf5697011e28bfa9e74b2a2ca", _exports);
623
+ return _exports;
624
+ })();
625
+ Object.assign(officeimo, _m0);
626
+ })(globalThis);