@evotecit/officeimo 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (259) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1219 -2
  3. package/bundles/officeimo-canopyx.js +11286 -0
  4. package/bundles/officeimo-canopyx.mjs +11185 -0
  5. package/bundles/officeimo-csv.js +1254 -0
  6. package/bundles/officeimo-csv.mjs +1229 -0
  7. package/bundles/officeimo-datatables.js +11572 -0
  8. package/bundles/officeimo-datatables.mjs +11470 -0
  9. package/bundles/officeimo-execution.js +1503 -0
  10. package/bundles/officeimo-execution.mjs +1479 -0
  11. package/bundles/officeimo-pdf.js +6564 -0
  12. package/bundles/officeimo-pdf.mjs +6502 -0
  13. package/bundles/officeimo-xlsx.js +5333 -0
  14. package/bundles/officeimo-xlsx.mjs +5279 -0
  15. package/bundles/officeimo.js +11022 -0
  16. package/bundles/officeimo.mjs +10924 -0
  17. package/dist/core/dates.d.ts +1 -0
  18. package/dist/core/dates.js +16 -0
  19. package/dist/core/errors.d.ts +12 -0
  20. package/dist/core/errors.js +31 -0
  21. package/dist/core/grouped-report.d.ts +87 -0
  22. package/dist/core/grouped-report.js +252 -0
  23. package/dist/core/index.d.ts +72 -0
  24. package/dist/core/index.js +37 -0
  25. package/dist/core/iteration.d.ts +7 -0
  26. package/dist/core/iteration.js +149 -0
  27. package/dist/core/limits.d.ts +7 -0
  28. package/dist/core/limits.js +56 -0
  29. package/dist/core/links.d.ts +5 -0
  30. package/dist/core/links.js +14 -0
  31. package/dist/core/presentation.d.ts +29 -0
  32. package/dist/core/presentation.js +59 -0
  33. package/dist/core/progress.d.ts +1 -0
  34. package/dist/core/progress.js +10 -0
  35. package/dist/core/sinks.d.ts +33 -0
  36. package/dist/core/sinks.js +101 -0
  37. package/dist/core/table.d.ts +8 -0
  38. package/dist/core/table.js +1 -0
  39. package/dist/core/value-text.d.ts +7 -0
  40. package/dist/core/value-text.js +13 -0
  41. package/dist/csv/index.d.ts +44 -0
  42. package/dist/csv/index.js +133 -0
  43. package/dist/csv/options.d.ts +1 -0
  44. package/dist/csv/options.js +8 -0
  45. package/dist/csv/structured-rows.d.ts +3 -0
  46. package/dist/csv/structured-rows.js +15 -0
  47. package/dist/execution/host.d.ts +5 -0
  48. package/dist/execution/host.js +164 -0
  49. package/dist/execution/index.d.ts +3 -0
  50. package/dist/execution/index.js +2 -0
  51. package/dist/execution/protocol.d.ts +48 -0
  52. package/dist/execution/protocol.js +173 -0
  53. package/dist/execution/types.d.ts +42 -0
  54. package/dist/execution/types.js +1 -0
  55. package/dist/execution/worker.d.ts +3 -0
  56. package/dist/execution/worker.js +147 -0
  57. package/dist/index.d.ts +32 -0
  58. package/dist/index.js +14 -0
  59. package/dist/integrations/canopyx/dates.d.ts +1 -0
  60. package/dist/integrations/canopyx/dates.js +34 -0
  61. package/dist/integrations/canopyx/index.d.ts +10 -0
  62. package/dist/integrations/canopyx/index.js +45 -0
  63. package/dist/integrations/canopyx/source.d.ts +3 -0
  64. package/dist/integrations/canopyx/source.js +116 -0
  65. package/dist/integrations/canopyx/types.d.ts +83 -0
  66. package/dist/integrations/canopyx/types.js +1 -0
  67. package/dist/integrations/datatables/api.d.ts +1 -0
  68. package/dist/integrations/datatables/api.js +27 -0
  69. package/dist/integrations/datatables/headings.d.ts +1 -0
  70. package/dist/integrations/datatables/headings.js +65 -0
  71. package/dist/integrations/datatables/index.d.ts +12 -0
  72. package/dist/integrations/datatables/index.js +167 -0
  73. package/dist/integrations/datatables/snapshot.d.ts +3 -0
  74. package/dist/integrations/datatables/snapshot.js +206 -0
  75. package/dist/integrations/datatables/types.d.ts +98 -0
  76. package/dist/integrations/datatables/types.js +1 -0
  77. package/dist/integrations/options.d.ts +13 -0
  78. package/dist/integrations/options.js +34 -0
  79. package/dist/internal/capture.d.ts +4 -0
  80. package/dist/internal/capture.js +14 -0
  81. package/dist/internal/columns.d.ts +27 -0
  82. package/dist/internal/columns.js +1 -0
  83. package/dist/internal/crc32.d.ts +6 -0
  84. package/dist/internal/crc32.js +17 -0
  85. package/dist/internal/export-values.d.ts +3 -0
  86. package/dist/internal/export-values.js +14 -0
  87. package/dist/internal/rows.d.ts +6 -0
  88. package/dist/internal/rows.js +68 -0
  89. package/dist/internal/table-spans.d.ts +11 -0
  90. package/dist/internal/table-spans.js +58 -0
  91. package/dist/internal/totals.d.ts +15 -0
  92. package/dist/internal/totals.js +42 -0
  93. package/dist/opc/index.d.ts +67 -0
  94. package/dist/opc/index.js +233 -0
  95. package/dist/opc/properties.d.ts +15 -0
  96. package/dist/opc/properties.js +18 -0
  97. package/dist/opc/uri.d.ts +5 -0
  98. package/dist/opc/uri.js +41 -0
  99. package/dist/pdf/annotations.d.ts +1 -0
  100. package/dist/pdf/annotations.js +38 -0
  101. package/dist/pdf/binary.d.ts +6 -0
  102. package/dist/pdf/binary.js +24 -0
  103. package/dist/pdf/document-drawings.d.ts +15 -0
  104. package/dist/pdf/document-drawings.js +237 -0
  105. package/dist/pdf/document-grouped.d.ts +1 -0
  106. package/dist/pdf/document-grouped.js +194 -0
  107. package/dist/pdf/document-images.d.ts +19 -0
  108. package/dist/pdf/document-images.js +125 -0
  109. package/dist/pdf/document-types.d.ts +160 -0
  110. package/dist/pdf/document-types.js +1 -0
  111. package/dist/pdf/document-vectors.d.ts +11 -0
  112. package/dist/pdf/document-vectors.js +77 -0
  113. package/dist/pdf/document.d.ts +9 -0
  114. package/dist/pdf/document.js +270 -0
  115. package/dist/pdf/drawing-types.d.ts +53 -0
  116. package/dist/pdf/drawing-types.js +1 -0
  117. package/dist/pdf/font-resources.d.ts +43 -0
  118. package/dist/pdf/font-resources.js +201 -0
  119. package/dist/pdf/font-support.d.ts +1 -0
  120. package/dist/pdf/font-support.js +60 -0
  121. package/dist/pdf/font.d.ts +17 -0
  122. package/dist/pdf/font.js +56 -0
  123. package/dist/pdf/grouped-table.d.ts +6 -0
  124. package/dist/pdf/grouped-table.js +40 -0
  125. package/dist/pdf/grouped-types.d.ts +34 -0
  126. package/dist/pdf/grouped-types.js +1 -0
  127. package/dist/pdf/grouped.d.ts +10 -0
  128. package/dist/pdf/grouped.js +37 -0
  129. package/dist/pdf/index.d.ts +22 -0
  130. package/dist/pdf/index.js +8 -0
  131. package/dist/pdf/inline-text.d.ts +30 -0
  132. package/dist/pdf/inline-text.js +142 -0
  133. package/dist/pdf/inline-types.d.ts +15 -0
  134. package/dist/pdf/inline-types.js +1 -0
  135. package/dist/pdf/list-layout.d.ts +6 -0
  136. package/dist/pdf/list-layout.js +49 -0
  137. package/dist/pdf/objects.d.ts +2 -0
  138. package/dist/pdf/objects.js +143 -0
  139. package/dist/pdf/outlines.d.ts +1 -0
  140. package/dist/pdf/outlines.js +55 -0
  141. package/dist/pdf/page-context.d.ts +1 -0
  142. package/dist/pdf/page-context.js +12 -0
  143. package/dist/pdf/pages.d.ts +1 -0
  144. package/dist/pdf/pages.js +679 -0
  145. package/dist/pdf/paragraph-layout.d.ts +19 -0
  146. package/dist/pdf/paragraph-layout.js +66 -0
  147. package/dist/pdf/paragraph-styles.d.ts +1 -0
  148. package/dist/pdf/paragraph-styles.js +66 -0
  149. package/dist/pdf/png.d.ts +9 -0
  150. package/dist/pdf/png.js +259 -0
  151. package/dist/pdf/preflight.d.ts +7 -0
  152. package/dist/pdf/preflight.js +32 -0
  153. package/dist/pdf/presentation-settings.d.ts +5 -0
  154. package/dist/pdf/presentation-settings.js +28 -0
  155. package/dist/pdf/providers/harfbuzz.d.ts +60 -0
  156. package/dist/pdf/providers/harfbuzz.js +112 -0
  157. package/dist/pdf/providers/unicode13-profile.d.ts +2 -0
  158. package/dist/pdf/providers/unicode13-profile.js +115 -0
  159. package/dist/pdf/section-types.d.ts +15 -0
  160. package/dist/pdf/section-types.js +40 -0
  161. package/dist/pdf/session.d.ts +25 -0
  162. package/dist/pdf/session.js +55 -0
  163. package/dist/pdf/settings.d.ts +15 -0
  164. package/dist/pdf/settings.js +171 -0
  165. package/dist/pdf/shaped-text.d.ts +5 -0
  166. package/dist/pdf/shaped-text.js +205 -0
  167. package/dist/pdf/standard-widths.d.ts +1 -0
  168. package/dist/pdf/standard-widths.js +317 -0
  169. package/dist/pdf/structure-parent-tree.d.ts +1 -0
  170. package/dist/pdf/structure-parent-tree.js +57 -0
  171. package/dist/pdf/structure.d.ts +6 -0
  172. package/dist/pdf/structure.js +250 -0
  173. package/dist/pdf/table-band-flow.d.ts +34 -0
  174. package/dist/pdf/table-band-flow.js +114 -0
  175. package/dist/pdf/table-band-plan.d.ts +10 -0
  176. package/dist/pdf/table-band-plan.js +85 -0
  177. package/dist/pdf/table-layout.d.ts +71 -0
  178. package/dist/pdf/table-layout.js +205 -0
  179. package/dist/pdf/table-structure.d.ts +1 -0
  180. package/dist/pdf/table-structure.js +92 -0
  181. package/dist/pdf/text-shaping-types.d.ts +39 -0
  182. package/dist/pdf/text-shaping-types.js +1 -0
  183. package/dist/pdf/text.d.ts +13 -0
  184. package/dist/pdf/text.js +96 -0
  185. package/dist/pdf/truetype-subset.d.ts +5 -0
  186. package/dist/pdf/truetype-subset.js +217 -0
  187. package/dist/pdf/truetype.d.ts +1 -0
  188. package/dist/pdf/truetype.js +235 -0
  189. package/dist/pdf/types.d.ts +169 -0
  190. package/dist/pdf/types.js +1 -0
  191. package/dist/pdf/write.d.ts +6 -0
  192. package/dist/pdf/write.js +57 -0
  193. package/dist/xlsx/attachments.d.ts +30 -0
  194. package/dist/xlsx/attachments.js +67 -0
  195. package/dist/xlsx/chart-bindings.d.ts +1 -0
  196. package/dist/xlsx/chart-bindings.js +122 -0
  197. package/dist/xlsx/chart-types.d.ts +73 -0
  198. package/dist/xlsx/chart-types.js +1 -0
  199. package/dist/xlsx/chart-xml.d.ts +2 -0
  200. package/dist/xlsx/chart-xml.js +103 -0
  201. package/dist/xlsx/charts.d.ts +1 -0
  202. package/dist/xlsx/charts.js +159 -0
  203. package/dist/xlsx/conditional-formatting.d.ts +1 -0
  204. package/dist/xlsx/conditional-formatting.js +158 -0
  205. package/dist/xlsx/conditional-types.d.ts +64 -0
  206. package/dist/xlsx/conditional-types.js +1 -0
  207. package/dist/xlsx/data-row-ranges.d.ts +5 -0
  208. package/dist/xlsx/data-row-ranges.js +39 -0
  209. package/dist/xlsx/differential-styles.d.ts +1 -0
  210. package/dist/xlsx/differential-styles.js +102 -0
  211. package/dist/xlsx/formula.d.ts +8 -0
  212. package/dist/xlsx/formula.js +104 -0
  213. package/dist/xlsx/grouped-layout.d.ts +61 -0
  214. package/dist/xlsx/grouped-layout.js +79 -0
  215. package/dist/xlsx/grouped.d.ts +16 -0
  216. package/dist/xlsx/grouped.js +161 -0
  217. package/dist/xlsx/index.d.ts +24 -0
  218. package/dist/xlsx/index.js +10 -0
  219. package/dist/xlsx/layout.d.ts +1 -0
  220. package/dist/xlsx/layout.js +186 -0
  221. package/dist/xlsx/options.d.ts +1 -0
  222. package/dist/xlsx/options.js +16 -0
  223. package/dist/xlsx/portable.d.ts +27 -0
  224. package/dist/xlsx/portable.js +44 -0
  225. package/dist/xlsx/preservation.d.ts +1 -0
  226. package/dist/xlsx/preservation.js +60 -0
  227. package/dist/xlsx/ranges.d.ts +1 -0
  228. package/dist/xlsx/ranges.js +24 -0
  229. package/dist/xlsx/regions.d.ts +1 -0
  230. package/dist/xlsx/regions.js +97 -0
  231. package/dist/xlsx/structured-rows.d.ts +11 -0
  232. package/dist/xlsx/structured-rows.js +28 -0
  233. package/dist/xlsx/style-xml.d.ts +1 -0
  234. package/dist/xlsx/style-xml.js +6 -0
  235. package/dist/xlsx/styles.d.ts +70 -0
  236. package/dist/xlsx/styles.js +203 -0
  237. package/dist/xlsx/table.d.ts +12 -0
  238. package/dist/xlsx/table.js +35 -0
  239. package/dist/xlsx/types.d.ts +180 -0
  240. package/dist/xlsx/types.js +1 -0
  241. package/dist/xlsx/validation-types.d.ts +18 -0
  242. package/dist/xlsx/validation-types.js +1 -0
  243. package/dist/xlsx/validation.d.ts +1 -0
  244. package/dist/xlsx/validation.js +92 -0
  245. package/dist/xlsx/values.d.ts +13 -0
  246. package/dist/xlsx/values.js +86 -0
  247. package/dist/xlsx/workbook.d.ts +50 -0
  248. package/dist/xlsx/workbook.js +452 -0
  249. package/dist/xlsx/worksheet.d.ts +71 -0
  250. package/dist/xlsx/worksheet.js +700 -0
  251. package/dist/xlsx/write.d.ts +15 -0
  252. package/dist/xlsx/write.js +47 -0
  253. package/dist/xml/index.d.ts +24 -0
  254. package/dist/xml/index.js +74 -0
  255. package/dist/zip/entry.d.ts +39 -0
  256. package/dist/zip/entry.js +122 -0
  257. package/dist/zip/index.d.ts +44 -0
  258. package/dist/zip/index.js +248 -0
  259. package/package.json +104 -4
@@ -0,0 +1,167 @@
1
+ import { BlobByteSink, checkAbort, saveBlob } from "../../core/index.js";
2
+ import { notifyProgress } from "../../core/progress.js";
3
+ import { writeCsvTo } from "../../csv/index.js";
4
+ import { writeXlsxTo } from "../../xlsx/index.js";
5
+ import { writePdfTo } from "../../pdf/index.js";
6
+ import { portableSheet, portableWorkbook } from "../../xlsx/portable.js";
7
+ import { call, member } from "./api.js";
8
+ import { value } from "./headings.js";
9
+ import { captureDataTablesExport } from "./snapshot.js";
10
+ import { captureFields } from "../../internal/capture.js";
11
+ import { captureCommonLimits, captureXlsxOptions, captureCsvOptions, capturePdfOptions, mergeAdapterLimits } from "../options.js";
12
+ export { createDataTablesExport } from "./snapshot.js";
13
+ export { ExportCell } from "../../core/presentation.js";
14
+ export { PdfFont } from "../../pdf/font.js";
15
+ const writeOptionFields = ["mode", "exportOptions", "batchRows", "maxBatchCells", "headings", "includeFooter", "serverSide", "columnOptions", "project", "signal", "limits", "onProgress", "xlsx", "csv", "pdf"];
16
+ const buttonOptionFields = [...writeOptionFields, "filename", "save", "onError"];
17
+ /** Write directly to a caller-owned destination. Failed destinations own disposal of their partial bytes. */
18
+ export async function writeDataTableTo(host, table, format, destination, options = {}) {
19
+ if (format !== "xlsx" && format !== "csv" && format !== "pdf")
20
+ throw new TypeError("DataTables export format must be xlsx, csv or pdf.");
21
+ for (const key of ["workbook", "sheet", "sheetName"])
22
+ if (key in options)
23
+ throw new TypeError("DataTables writer settings belong in xlsx; use xlsx.sheet.name for the worksheet name.");
24
+ const captured = captureFields(options, writeOptionFields);
25
+ const { signal, onProgress } = captured, limits = captureCommonLimits(captured.limits);
26
+ const xlsx = captureXlsxOptions(format === "xlsx" ? captured.xlsx : undefined);
27
+ const csv = captureCsvOptions(format === "csv" ? captured.csv : undefined);
28
+ const pdf = capturePdfOptions(format === "pdf" ? captured.pdf : undefined);
29
+ const sheet = xlsx.sheet;
30
+ if (format === "xlsx") {
31
+ portableSheet(sheet);
32
+ portableWorkbook(xlsx);
33
+ }
34
+ const replacementXlsxFooter = sheet?.footer && [sheet.footer.rows, sheet.footer.values, sheet.footer.totals].some(value => value !== undefined);
35
+ const source = captureDataTablesExport(host, table, { ...captured, ...(limits === undefined ? {} : { limits }), ...(format === "pdf" ? { headings: captured.headings ?? "structured" } : {}) }, {
36
+ header: format === "pdf" ? pdf.includeHeader === false || pdf.headerRows !== undefined
37
+ : format === "xlsx" ? sheet?.includeHeader === false || sheet?.headerRows !== undefined
38
+ : csv.includeHeader === false || csv.headerRows !== undefined,
39
+ footer: format === "pdf" ? pdf.footer !== undefined : format === "xlsx" ? Boolean(replacementXlsxFooter) : csv.footer !== undefined
40
+ });
41
+ let result;
42
+ const stream = { ...(signal ? { signal } : {}), ...(onProgress ? {
43
+ onProgress: (event) => notifyProgress(onProgress, { ...event, totalRows: source.rowCount })
44
+ } : {}) };
45
+ if (format === "xlsx") {
46
+ const sourceFooter = source.footerStructure ? { rows: source.footerStructure } : source.footer ? { values: source.footer } : undefined;
47
+ const footer = replacementXlsxFooter ? sheet?.footer : sourceFooter || sheet?.footer ? { ...sourceFooter, ...sheet?.footer } : undefined;
48
+ result = await writeXlsxTo(source.rows, destination, { ...xlsx, ...stream, columns: source.columns,
49
+ limits: mergeAdapterLimits(xlsx.limits, limits),
50
+ sheet: { ...sheet, ...(source.headerStructure && sheet?.includeHeader !== false && sheet?.headerRows === undefined ? { headerRows: source.headerStructure } : {}), ...(footer ? { footer } : {}) } });
51
+ }
52
+ else if (format === "pdf") {
53
+ const footer = pdf.footer ?? (source.footerStructure ? { rows: source.footerStructure } : source.footer ? { values: source.footer } : undefined);
54
+ result = await writePdfTo(source.rows, destination, { ...pdf, ...stream, columns: source.columns,
55
+ limits: mergeAdapterLimits(pdf.limits, limits),
56
+ ...(source.headerStructure && pdf.includeHeader !== false && !pdf.headerRows ? { headerRows: source.headerStructure } : {}),
57
+ ...(footer ? { footer } : {}) });
58
+ }
59
+ else {
60
+ const footer = csv.footer ?? (source.footerStructure ? { rows: source.footerStructure }
61
+ : source.footer ? { rows: [source.footer.map(value => ({ value }))] } : undefined);
62
+ result = await writeCsvTo(source.rows, destination, { ...csv, ...stream, columns: source.columns,
63
+ limits: mergeAdapterLimits(csv.limits, limits),
64
+ ...(csv.includeHeader !== false && csv.headerRows === undefined ? { headerRows: source.headerStructure ?? source.headers.map(row => row.map(value => ({ value }))) } : {}), ...(footer ? { footer } : {}) });
65
+ }
66
+ checkAbort(signal);
67
+ return { rows: source.rowCount, columns: source.columns.length, bytes: result.bytes };
68
+ }
69
+ /** Return a browser/worker/Node Blob. Use writeDataTableTo to avoid retaining the completed file in memory. */
70
+ export async function exportDataTable(host, table, format, options = {}) {
71
+ const sink = new BlobByteSink();
72
+ try {
73
+ await writeDataTableTo(host, table, format, sink, options);
74
+ return sink.toBlob(format === "pdf" ? "application/pdf" : format === "csv" ? "text/csv;charset=utf-8" : "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
75
+ }
76
+ catch (error) {
77
+ sink.discard();
78
+ throw error;
79
+ }
80
+ }
81
+ /** Register opt-in Buttons entries; no import-time registration, DataTables import or jQuery dependency. */
82
+ export function registerDataTablesButtons(host, options = {}) {
83
+ const buttons = host.ext?.buttons;
84
+ if (!buttons || typeof member(host.Buttons, "stripData") !== "function")
85
+ throw new TypeError("Install DataTables Buttons before registering OfficeIMO exports.");
86
+ if (buttons.officeimoExcel || buttons.officeimoCsv || buttons.officeimoPdf)
87
+ throw new TypeError("OfficeIMO DataTables buttons are already registered.");
88
+ for (const [name, format, label] of [["officeimoExcel", "xlsx", "Excel"], ["officeimoCsv", "csv", "CSV"], ["officeimoPdf", "pdf", "PDF"]]) {
89
+ buttons[name] = { text: label, async: 1,
90
+ action: function (_event, table, _node, configuration, complete) {
91
+ let current = options;
92
+ const finish = () => { const callback = complete; complete = undefined; callback?.(); };
93
+ void (async () => {
94
+ try {
95
+ const configured = member(configuration, "officeimo"), filename = member(configuration, "filename");
96
+ if (configured !== undefined && (!configured || typeof configured !== "object"))
97
+ throw new TypeError("Button officeimo settings must be an object.");
98
+ const defaults = captureFields(options, buttonOptionFields), overrides = captureFields((configured ?? {}), buttonOptionFields);
99
+ current = { ...defaults, ...overrides,
100
+ ...(filename !== undefined ? { filename: filename } : {}),
101
+ ...(member(configuration, "footer") === false ? { includeFooter: false } : {}),
102
+ ...(member(configuration, "exportOptions") ? { exportOptions: member(configuration, "exportOptions") } : {}) };
103
+ if (member(configuration, "customize") !== undefined)
104
+ throw new TypeError("Native customize callbacks are unsupported; use OfficeIMO xlsx/pdf options.");
105
+ if (format === "xlsx") {
106
+ const base = captureXlsxOptions(defaults.xlsx), selected = captureXlsxOptions(overrides.xlsx);
107
+ current = { ...current, xlsx: { ...base, ...selected,
108
+ ...(base.sheet || selected.sheet ? { sheet: { ...base.sheet, ...selected.sheet } } : {}) } };
109
+ }
110
+ else if (format === "csv")
111
+ current = { ...current, csv: { ...captureCsvOptions(defaults.csv), ...captureCsvOptions(overrides.csv) } };
112
+ if (format === "pdf") {
113
+ const info = call(table.buttons, "exportInfo", configuration);
114
+ const pdf = { ...capturePdfOptions(defaults.pdf), ...capturePdfOptions(overrides.pdf) };
115
+ for (const key of ["title", "messageTop", "messageBottom"])
116
+ if (member(configuration, key) !== undefined) {
117
+ if (member(configuration, key) === null) {
118
+ delete pdf[key];
119
+ continue;
120
+ }
121
+ const text = member(info, key);
122
+ if (text === null || text === "") {
123
+ delete pdf[key];
124
+ continue;
125
+ }
126
+ if (typeof text !== "string")
127
+ throw new TypeError("PDF " + key + " must resolve to text.");
128
+ pdf[key] = text;
129
+ }
130
+ for (const key of ["orientation", "pageSize"])
131
+ if (member(configuration, key) !== undefined)
132
+ Object.assign(pdf, { [key]: member(configuration, key) });
133
+ if (member(configuration, "header") === false) {
134
+ pdf.includeHeader = false;
135
+ delete pdf.headerRows;
136
+ }
137
+ if (member(configuration, "footer") === false)
138
+ delete pdf.footer;
139
+ current = { ...current, pdf };
140
+ }
141
+ else if (member(configuration, "header") === false || ["title", "messageTop", "messageBottom"].some(key => member(configuration, key) != null))
142
+ throw new TypeError("Use OfficeIMO xlsx.sheet title/footer options; native Buttons report layout options are unsupported.");
143
+ const pattern = value(typeof current.filename === "function" ? current.filename(configuration, table) : current.filename ?? "Export");
144
+ if (typeof pattern !== "string" || !pattern.trim())
145
+ throw new TypeError("Export filename must be a non-empty string.");
146
+ const file = value(member(call(table.buttons, "exportInfo", { filename: pattern, extension: "" }), "filename"));
147
+ if (typeof file !== "string" || !file.trim())
148
+ throw new TypeError("Resolved export filename must be a non-empty string.");
149
+ const blob = await exportDataTable(host, table, format, current);
150
+ await (current.save ?? saveBlob)(blob, file.toLowerCase().endsWith("." + format) ? file : file + "." + format);
151
+ }
152
+ catch (error) {
153
+ // Completion runs before the error handler so application error UI cannot strand Buttons' spinner.
154
+ finish();
155
+ if (current.onError)
156
+ await current.onError(error);
157
+ else
158
+ console.error("OfficeIMO table export failed.", error);
159
+ }
160
+ finally {
161
+ finish();
162
+ }
163
+ })().catch(error => console.error("OfficeIMO export error handler failed.", error));
164
+ }
165
+ };
166
+ }
167
+ }
@@ -0,0 +1,3 @@
1
+ import type { DataTablesApi, DataTablesExport, DataTablesHost, DataTablesOptions } from "./types.js";
2
+ /** Capture export scope and headings, then produce values in bounded batches using public DataTables APIs. */
3
+ export declare function createDataTablesExport(host: DataTablesHost, table: DataTablesApi, options?: DataTablesOptions): DataTablesExport;
@@ -0,0 +1,206 @@
1
+ import { checkAbort, pause, rowsFromBatches, taskYieldDue } from "../../core/iteration.js";
2
+ import { ExportBudget } from "../../core/limits.js";
3
+ import { captureFields } from "../../internal/capture.js";
4
+ import { columnOptionFields } from "../../internal/rows.js";
5
+ import { array, call, indexes, member } from "./api.js";
6
+ import { headings, text, value } from "./headings.js";
7
+ function safeOptions(options) {
8
+ options = captureFields(options, ["rows", "columns", "modifier", "orthogonal", "stripHtml", "stripNewlines", "decodeEntities", "escapeExcelFormula", "trim", "format", "customizeData"]);
9
+ const format = options.format && captureFields(options.format, ["header", "footer", "body"]), customize = options.customizeData;
10
+ return { ...options, ...(format ? { format: {
11
+ ...(format.header ? { header: (v, c, n) => value(format.header(v, c, n)) } : {}),
12
+ ...(format.footer ? { footer: (v, c, n) => value(format.footer(v, c, n)) } : {}),
13
+ ...(format.body ? { body: (v, r, c, n) => value(format.body(v, r, c, n)) } : {})
14
+ } } : {}), ...(customize ? { customizeData: (data) => {
15
+ const result = customize(data);
16
+ // Buttons ignores synchronous return values; only asynchronous callbacks violate this contract.
17
+ if (typeof member(result, "then") === "function")
18
+ value(result);
19
+ } } : {}) };
20
+ }
21
+ /** Capture export scope and headings, then produce values in bounded batches using public DataTables APIs. */
22
+ export function createDataTablesExport(host, table, options = {}) {
23
+ return captureDataTablesExport(host, table, options);
24
+ }
25
+ /** @internal Writers omit source structures only when their output explicitly suppresses or replaces them. */
26
+ export function captureDataTablesExport(host, table, options = {}, omitted) {
27
+ options = captureFields(options, ["mode", "exportOptions", "batchRows", "maxBatchCells", "headings", "includeFooter", "serverSide", "columnOptions", "project", "signal", "limits", "onProgress"]);
28
+ if (options.columnOptions !== undefined) {
29
+ const columnOptions = Object.fromEntries(Object.entries(options.columnOptions).map(([index, column]) => [index,
30
+ captureFields(column, columnOptionFields)]));
31
+ options = { ...options, columnOptions };
32
+ }
33
+ for (const column of Object.values(options.columnOptions ?? {}))
34
+ if (column.style !== undefined)
35
+ throw new TypeError("Workbook-local column styles require the advanced Workbook API; use portable ExportCell presentation.");
36
+ const mode = options.mode ?? "batched", headingMode = options.headings ?? "grouped";
37
+ if (!["batched", "compatibility"].includes(mode))
38
+ throw new TypeError("Unknown DataTables export mode.");
39
+ if (!["grouped", "leaf", "structured"].includes(headingMode))
40
+ throw new TypeError("Unknown DataTables heading mode.");
41
+ if (options.serverSide !== undefined && !["reject", "loaded"].includes(options.serverSide))
42
+ throw new TypeError("Unknown server-side export policy.");
43
+ const batchRows = options.batchRows ?? 4096, maxBatchCells = options.maxBatchCells ?? 65536;
44
+ if (!Number.isInteger(batchRows) || batchRows < 1 || batchRows > 4096)
45
+ throw new RangeError("batchRows must be between 1 and 4,096.");
46
+ if (!Number.isSafeInteger(maxBatchCells) || maxBatchCells < 1)
47
+ throw new RangeError("maxBatchCells must be a positive safe integer.");
48
+ const signal = options.signal, projectValue = options.project, budget = new ExportBudget(options.limits);
49
+ checkAbort(signal);
50
+ if (member(call(table.page, "info"), "serverSide") && options.serverSide !== "loaded")
51
+ throw new TypeError("Server-side DataTables exports require a separate full-data source or explicit serverSide: 'loaded'.");
52
+ const config = safeOptions(options.exportOptions ?? {});
53
+ const stripOptions = { stripHtml: true, stripNewlines: true, decodeEntities: true, trim: true, ...config };
54
+ const stripOwner = host.Buttons, strip = member(stripOwner, "stripData");
55
+ const stripData = typeof strip === "function" ? strip.bind(stripOwner) : undefined;
56
+ if (mode === "batched" && !config.format?.body && typeof strip !== "function")
57
+ throw new TypeError("DataTables API requires stripData().");
58
+ if (mode === "batched" && config.customizeData)
59
+ throw new TypeError("customizeData requires compatibility mode.");
60
+ if (config.customizeData && options.project)
61
+ throw new TypeError("project cannot identify source indexes after customizeData.");
62
+ const modifier = { search: "applied", order: "applied", ...config.modifier };
63
+ if (member(modifier, "selected") === undefined && typeof member(member(table, "select"), "info") === "function"
64
+ && Number(call(call(table, "rows", config.rows ?? null, { ...modifier, selected: true }), "count")) > 0)
65
+ Object.assign(modifier, { selected: true });
66
+ const rowIndexes = indexes(call(table, "rows", config.rows ?? null, modifier));
67
+ const columnIndexes = indexes(call(table, "columns", config.columns ?? ""));
68
+ if (columnIndexes.length > maxBatchCells)
69
+ throw new RangeError("A selected row exceeds maxBatchCells.");
70
+ if (new Set(rowIndexes).size !== rowIndexes.length || new Set(columnIndexes).size !== columnIndexes.length)
71
+ throw new TypeError("DataTables export indexes must be unique.");
72
+ const data = call(table.buttons, "exportData", { ...config, modifier, ...(mode === "batched" ? { rows: [] } : {}) });
73
+ const leaf = array(member(data, "header"));
74
+ if (leaf.length !== columnIndexes.length)
75
+ throw new TypeError("Export header must match the selected columns.");
76
+ const heading = headings(omitted?.header ? undefined : member(data, "headerStructure"), leaf, omitted?.header ? "leaf" : headingMode);
77
+ for (const index of columnIndexes)
78
+ if (member(options.columnOptions?.[index], "value") !== undefined)
79
+ throw new TypeError("DataTables columnOptions describes columns; resolve values with project.");
80
+ const columns = Object.freeze(leaf.map((label, index) => Object.freeze({
81
+ header: text(label), key: "dt:" + columnIndexes[index], ...options.columnOptions?.[columnIndexes[index]],
82
+ ...(heading.groups[index].length ? { groups: Object.freeze(heading.groups[index]) } : {})
83
+ })));
84
+ // Explicit heading overrides also apply to CSV's leaf heading.
85
+ if (!heading.structure)
86
+ heading.rows[heading.rows.length - 1] = columns.map(column => column.header);
87
+ const headerStructure = heading.structure?.map((row, level) => Object.freeze(row.map((cell, index) => {
88
+ if (!cell || level + (cell.rowSpan ?? 1) !== heading.structure.length)
89
+ return cell;
90
+ const override = options.columnOptions?.[columnIndexes[index]]?.header;
91
+ if ((cell.columnSpan ?? 1) > 1 && columnIndexes.slice(index, index + (cell.columnSpan ?? 1)).some(c => options.columnOptions?.[c]?.header !== undefined))
92
+ throw new TypeError("A spanning leaf heading cannot have per-column header overrides.");
93
+ return override === undefined ? cell : Object.freeze({ ...cell, value: override });
94
+ })));
95
+ const includeSourceFooter = options.includeFooter !== false && omitted?.footer !== true;
96
+ const footerStructure = includeSourceFooter ? member(data, "footerStructure") : undefined;
97
+ if (headingMode !== "structured" && includeSourceFooter && Array.isArray(footerStructure) && footerStructure.length > 1)
98
+ throw new TypeError("Only a single footer row is supported; select includeFooter: false to omit it explicitly.");
99
+ const rawFooter = includeSourceFooter ? member(data, "footer") : undefined;
100
+ const footer = rawFooter == null ? undefined : array(rawFooter).map(value);
101
+ if (footer && footer.length !== columns.length)
102
+ throw new TypeError("Export footer must match the selected columns.");
103
+ const footerHeading = footer && Array.isArray(footerStructure) && footerStructure.length ? headings(footerStructure, footer, headingMode === "structured" ? "structured" : "grouped") : undefined;
104
+ const body = mode === "compatibility" ? array(member(data, "body")) : undefined;
105
+ const count = columns.length ? body?.length ?? rowIndexes.length : 0;
106
+ budget.check("maxRows", count);
107
+ const batchSize = columns.length ? Math.min(batchRows, Math.floor(maxBatchCells / columns.length)) : batchRows;
108
+ const columnPositions = new Map(columnIndexes.map((index, ordinal) => [index, ordinal]));
109
+ // Keep the public cell API context without selecting or traversing the table's rows.
110
+ const emptyCells = mode === "batched" && count ? call(table, "cells", [], []) : undefined;
111
+ if (emptyCells) {
112
+ let tables = 0;
113
+ call(emptyCells, "iterator", "table", () => { tables++; });
114
+ if (tables !== 1)
115
+ throw new TypeError("A batched export requires exactly one DataTables table.");
116
+ }
117
+ const rows = rowsFromBatches({ [Symbol.asyncIterator]: () => iterate() });
118
+ async function* iterate() {
119
+ for (let first = 0; first < count; first += batchSize) {
120
+ checkAbort(signal);
121
+ let batch;
122
+ if (body) {
123
+ batch = body.slice(first, first + batchSize).map((row, ordinal) => {
124
+ if (!Array.isArray(row) || row.length !== columns.length)
125
+ throw new TypeError("Export body row must match the selected columns.");
126
+ return row.map((cell, index) => project(cell, rowIndexes[first + ordinal] ?? first + ordinal, index, first + ordinal));
127
+ });
128
+ }
129
+ else {
130
+ const selectedRows = rowIndexes.slice(first, first + batchSize);
131
+ // Public result-set operations replace the bounded cell indexes. Row selectors would
132
+ // rescan the complete table on every batch, even with constant-time membership.
133
+ const requested = new Array(selectedRows.length * columns.length);
134
+ for (let row = 0, cell = 0; row < selectedRows.length; row++)
135
+ for (const column of columnIndexes)
136
+ requested[cell++] = { row: selectedRows[row], column };
137
+ call(emptyCells, "pop");
138
+ call(emptyCells, "push", requested);
139
+ const cells = emptyCells;
140
+ const rendered = array(call(cells, "render", config.orthogonal ?? "display"));
141
+ const positions = array(call(cells, "indexes"));
142
+ const nodes = config.format?.body ? array(call(cells, "nodes")) : undefined;
143
+ if (rendered.length !== selectedRows.length * columns.length || positions.length !== rendered.length || nodes && nodes.length > rendered.length)
144
+ throw new TypeError("The table changed or returned an incomplete export batch.");
145
+ batch = selectedRows.map(() => new Array(columns.length));
146
+ // Validate coordinates while formatting instead of scanning every cell twice.
147
+ // The usual ordered result needs no mapping or duplicate set. On the first
148
+ // reordered cell, include the already accepted ordered prefix in that set.
149
+ let rowPositions, seen;
150
+ let ordinalRow = 0, ordinalColumn = 0;
151
+ for (let cell = 0; cell < rendered.length; cell++) {
152
+ checkAbort(signal);
153
+ const rowIndex = member(positions[cell], "row"), columnIndex = member(positions[cell], "column");
154
+ if (!seen && (rowIndex !== requested[cell].row || columnIndex !== requested[cell].column)) {
155
+ rowPositions = new Map(selectedRows.map((index, ordinal) => [index, ordinal]));
156
+ seen = new Set();
157
+ for (let accepted = 0; accepted < cell; accepted++)
158
+ seen.add(accepted);
159
+ }
160
+ const row = seen ? rowPositions.get(rowIndex) : ordinalRow;
161
+ const column = seen ? columnPositions.get(columnIndex) : ordinalColumn;
162
+ if (row === undefined || column === undefined || seen?.has(row * columns.length + column))
163
+ throw new TypeError("Invalid DataTables cell indexes.");
164
+ seen?.add(row * columns.length + column);
165
+ let node = nodes?.[cell];
166
+ if (nodes && nodes.length !== rendered.length) {
167
+ // nodes() omits deferred cells without DOM nodes. Resolve each coordinate
168
+ // through the same bounded result set so compacted nodes cannot shift rows.
169
+ call(cells, "pop");
170
+ call(cells, "push", [{ row: rowIndex, column: columnIndex }]);
171
+ const exact = array(call(cells, "nodes"));
172
+ if (exact.length > 1)
173
+ throw new TypeError("Invalid DataTables cell nodes.");
174
+ node = exact[0];
175
+ }
176
+ const formatted = config.format?.body ? config.format.body(rendered[cell], rowIndex, columnIndex, node)
177
+ : stripData(rendered[cell], stripOptions);
178
+ batch[row][column] = project(formatted, rowIndex, column, first + row);
179
+ if (++ordinalColumn === columns.length) {
180
+ ordinalColumn = 0;
181
+ ordinalRow++;
182
+ }
183
+ if ((cell & 127) === 127 && taskYieldDue()) {
184
+ await pause();
185
+ checkAbort(signal);
186
+ }
187
+ }
188
+ }
189
+ checkAbort(signal);
190
+ yield batch;
191
+ if (taskYieldDue()) {
192
+ await pause();
193
+ checkAbort(signal);
194
+ }
195
+ }
196
+ }
197
+ function project(input, rowIndex, column, rowOrdinal) {
198
+ checkAbort(signal);
199
+ const scalar = value(input);
200
+ return projectValue ? value(projectValue(scalar, { sourceRowIndex: rowIndex, sourceColumnIndex: columnIndexes[column], rowIndex: rowOrdinal, columnIndex: column })) : scalar;
201
+ }
202
+ return Object.freeze({ columns, headers: Object.freeze(heading.rows.map(row => Object.freeze(row))),
203
+ footer: footer ? Object.freeze(footer) : undefined,
204
+ ...(headerStructure ? { headerStructure: Object.freeze(headerStructure) } : {}),
205
+ ...(footerHeading?.structure ? { footerStructure: footerHeading.structure } : {}), rowCount: count, rows });
206
+ }
@@ -0,0 +1,98 @@
1
+ import type { Column, ExportValue, StreamOptions, TableSpanRows } from "../../core/index.js";
2
+ import type { CsvOptions } from "../../csv/index.js";
3
+ import type { XlsxOptions, WorkbookLimits } from "../../xlsx/index.js";
4
+ import type { PdfOptions, PdfLimits } from "../../pdf/index.js";
5
+ /** Structural interoperability boundary; importing this adapter never imports DataTables. */
6
+ export type DataTablesMethod = (...args: never[]) => unknown;
7
+ export interface DataTablesApi {
8
+ readonly rows: DataTablesMethod;
9
+ readonly columns: DataTablesMethod;
10
+ readonly cells: DataTablesMethod;
11
+ readonly page: {
12
+ readonly info: DataTablesMethod;
13
+ };
14
+ readonly buttons: {
15
+ readonly exportData: DataTablesMethod;
16
+ readonly exportInfo?: DataTablesMethod;
17
+ };
18
+ }
19
+ export interface DataTablesHost {
20
+ /** Checked at runtime; older Buttons declarations omit the public stripData helper. */
21
+ readonly Buttons: object;
22
+ readonly ext: {
23
+ readonly buttons: Record<string, unknown>;
24
+ };
25
+ }
26
+ export interface DataTablesCellContext {
27
+ /** DataTables indexes, after any column reordering. */
28
+ readonly sourceRowIndex: number;
29
+ readonly sourceColumnIndex: number;
30
+ /** Zero-based position in the selected export. */
31
+ readonly rowIndex: number;
32
+ readonly columnIndex: number;
33
+ }
34
+ export interface DataTablesFormat {
35
+ readonly header?: (value: unknown, column: number, node: unknown) => unknown;
36
+ readonly footer?: (value: unknown, column: number, node: unknown) => unknown;
37
+ readonly body?: (value: unknown, row: number, column: number, node: unknown) => unknown;
38
+ }
39
+ /** Passed to the installed Buttons implementation in compatibility mode. */
40
+ export interface DataTablesExportOptions {
41
+ readonly rows?: unknown;
42
+ readonly columns?: unknown;
43
+ readonly modifier?: Readonly<Record<string, unknown>>;
44
+ readonly orthogonal?: string;
45
+ readonly stripHtml?: boolean;
46
+ readonly stripNewlines?: boolean;
47
+ readonly decodeEntities?: boolean;
48
+ readonly escapeExcelFormula?: boolean;
49
+ readonly trim?: boolean;
50
+ readonly format?: DataTablesFormat;
51
+ /** Whole-matrix customization is supported only by compatibility mode. */
52
+ readonly customizeData?: (data: unknown) => void;
53
+ }
54
+ export interface DataTablesOptions extends StreamOptions {
55
+ /** Batched avoids Buttons' complete body matrix; compatibility delegates gathering to Buttons. */
56
+ readonly mode?: "batched" | "compatibility";
57
+ readonly exportOptions?: DataTablesExportOptions;
58
+ /** Maximum rows per projection batch, default 4,096, also bounded by maxBatchCells. */
59
+ readonly batchRows?: number;
60
+ /** Maximum cells per projection batch, default 65,536. One row must fit. */
61
+ readonly maxBatchCells?: number;
62
+ /** Grouped accepts horizontal spans; leaf selects one row; structured preserves XLSX/PDF rectangles or explicitly flattens CSV spans. */
63
+ readonly headings?: "grouped" | "leaf" | "structured";
64
+ readonly includeFooter?: boolean;
65
+ /** Server-side tables require explicit acknowledgement that only loaded rows are available. */
66
+ readonly serverSide?: "reject" | "loaded";
67
+ /** Overrides keyed by DataTables column index, independent of the selected export position. */
68
+ readonly columnOptions?: Readonly<Record<number, Partial<Omit<Column, "groups" | "value">> & {
69
+ readonly style?: never;
70
+ }>>;
71
+ /** Resolve portable values/presentation once. Results must be synchronous scalar values or ExportCells. */
72
+ readonly project?: (value: ExportValue, context: DataTablesCellContext) => ExportValue;
73
+ }
74
+ /** Selection and heading metadata are captured immediately; batched body values are read during iteration. */
75
+ export interface DataTablesExport {
76
+ readonly columns: readonly Column<readonly ExportValue[]>[];
77
+ readonly headers: readonly (readonly ExportValue[])[];
78
+ readonly footer: readonly ExportValue[] | undefined;
79
+ readonly headerStructure?: TableSpanRows;
80
+ readonly footerStructure?: TableSpanRows;
81
+ readonly rowCount: number;
82
+ /** Single-use source. Keep the table's data stable until iteration finishes. */
83
+ readonly rows: AsyncIterable<readonly ExportValue[]>;
84
+ }
85
+ export interface DataTablesWriteOptions extends DataTablesOptions {
86
+ readonly limits?: WorkbookLimits & PdfLimits;
87
+ /** The same single-table settings accepted by writeXlsx; the capture supplies columns. */
88
+ readonly xlsx?: Omit<XlsxOptions, "columns" | "signal" | "onProgress">;
89
+ readonly csv?: Omit<CsvOptions, "columns" | "signal" | "onProgress">;
90
+ readonly pdf?: Omit<PdfOptions, "columns" | "signal" | "onProgress">;
91
+ }
92
+ export interface DataTablesButtonOptions extends DataTablesWriteOptions {
93
+ readonly filename?: string | ((configuration: unknown, table: DataTablesApi) => string);
94
+ /** Receives failures after Buttons' completion callback has cleared its processing state. */
95
+ readonly onError?: (error: unknown) => void | Promise<void>;
96
+ /** Override destination delivery, for example to retain a download in an application. */
97
+ readonly save?: (blob: Blob, filename: string) => void | Promise<void>;
98
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,13 @@
1
+ import type { ExportLimits } from "../core/limits.js";
2
+ import type { CsvOptions } from "../csv/index.js";
3
+ import type { PdfOptions, PdfLimits } from "../pdf/index.js";
4
+ import type { XlsxOptions, WorkbookLimits } from "../xlsx/index.js";
5
+ type CommonLimits = WorkbookLimits & PdfLimits;
6
+ /** Shared adapter budgets override only explicitly supplied numeric format ceilings. */
7
+ export declare function captureCommonLimits(input: CommonLimits | undefined): Readonly<CommonLimits> | undefined;
8
+ export declare function mergeAdapterLimits<T extends ExportLimits>(format: T | undefined, common: Readonly<CommonLimits> | undefined): T;
9
+ /** Snapshot the format owner's fields before an adapter adds captured columns and stream policy. */
10
+ export declare function captureXlsxOptions(input?: Omit<XlsxOptions, "columns">): Omit<XlsxOptions, "columns">;
11
+ export declare function captureCsvOptions(input?: Omit<CsvOptions, "columns">): Omit<CsvOptions, "columns">;
12
+ export declare function capturePdfOptions(input?: Omit<PdfOptions, "columns">): Omit<PdfOptions, "columns">;
13
+ export {};
@@ -0,0 +1,34 @@
1
+ import { captureFields } from "../internal/capture.js";
2
+ import { ExportBudget } from "../core/limits.js";
3
+ import { captureCsvOptions as captureCsv } from "../csv/options.js";
4
+ import { capturePdfOptions as capturePdf, capturePdfLimits, pdfLimitFields } from "../pdf/settings.js";
5
+ import { captureWorkbookLimits, workbookLimitFields, workbookOptionFields, sheetOptionFields } from "../xlsx/options.js";
6
+ const limitFields = [...new Set([...workbookLimitFields, ...pdfLimitFields])];
7
+ const portableWorkbookFields = workbookOptionFields.filter((key) => key !== "sink");
8
+ /** Shared adapter budgets override only explicitly supplied numeric format ceilings. */
9
+ export function captureCommonLimits(input) {
10
+ return input === undefined ? undefined : new ExportBudget(captureFields(input, limitFields)).limits;
11
+ }
12
+ export function mergeAdapterLimits(format, common) {
13
+ const result = { ...format };
14
+ for (const [key, value] of Object.entries(common ?? {}))
15
+ if (value !== undefined)
16
+ result[key] = value;
17
+ return result;
18
+ }
19
+ /** Snapshot the format owner's fields before an adapter adds captured columns and stream policy. */
20
+ export function captureXlsxOptions(input = {}) {
21
+ const options = captureFields(input, [...portableWorkbookFields, "sheet"]);
22
+ const sheet = options.sheet && captureFields(options.sheet, [...sheetOptionFields, "name"]);
23
+ const footer = sheet?.footer && captureFields(sheet.footer, ["rows", "values", "totals", "style"]);
24
+ return { ...options, ...(sheet === undefined ? {} : { sheet: { ...sheet, ...(footer === undefined ? {} : { footer }) } }),
25
+ ...(options.limits === undefined ? {} : { limits: captureWorkbookLimits(options.limits) }) };
26
+ }
27
+ export function captureCsvOptions(input = {}) {
28
+ const options = captureCsv(input);
29
+ return { ...options, ...(options.limits === undefined ? {} : { limits: new ExportBudget(options.limits).limits }) };
30
+ }
31
+ export function capturePdfOptions(input = {}) {
32
+ const options = capturePdf(input);
33
+ return { ...options, ...(options.limits === undefined ? {} : { limits: capturePdfLimits(options.limits) }) };
34
+ }
@@ -0,0 +1,4 @@
1
+ /** Capture a structural option record before validation or asynchronous work.
2
+ * Own fields and supported prototype accessors are read once. Nested values remain
3
+ * borrowed until their owning format captures or validates them. */
4
+ export declare function captureFields<T extends object>(input: T, fields: readonly (keyof T)[]): T;
@@ -0,0 +1,14 @@
1
+ /** Capture a structural option record before validation or asynchronous work.
2
+ * Own fields and supported prototype accessors are read once. Nested values remain
3
+ * borrowed until their owning format captures or validates them. */
4
+ export function captureFields(input, fields) {
5
+ const captured = { ...input };
6
+ for (const field of fields) {
7
+ if (Object.hasOwn(captured, field))
8
+ continue;
9
+ const value = input[field];
10
+ if (value !== undefined)
11
+ captured[field] = value;
12
+ }
13
+ return captured;
14
+ }
@@ -0,0 +1,27 @@
1
+ import type { ColumnSettings, ColumnValueContext } from "../core/index.js";
2
+ type ValueKey<T, V> = {
3
+ [K in Extract<keyof T, string>]-?: T[K] extends V ? K : never;
4
+ }[Extract<keyof T, string>];
5
+ type Selector<T, V> = [T] extends [never] ? {
6
+ readonly key?: string;
7
+ readonly value?: never;
8
+ } : T extends readonly unknown[] ? T[number] extends V ? {
9
+ readonly key?: string;
10
+ readonly value?: never;
11
+ } : never : {
12
+ readonly key: ValueKey<T, V>;
13
+ readonly value?: never;
14
+ };
15
+ /** One selector definition, with values admitted by the destination's public contract. */
16
+ export type ProjectedColumn<T, V> = ColumnSettings & {
17
+ readonly key?: string;
18
+ } & (Selector<T, V> | {
19
+ readonly key?: string;
20
+ readonly value: (row: T, context: ColumnValueContext) => V;
21
+ });
22
+ /** Erased metadata for owners that invoke the captured getter with the source row. */
23
+ export type ProjectionColumn = ColumnSettings & {
24
+ readonly key?: string;
25
+ readonly value?: (row: never, context: ColumnValueContext) => unknown;
26
+ };
27
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,6 @@
1
+ /** Incremental CRC-32/ISO-HDLC shared by ZIP and PNG chunk validation. */
2
+ export declare class Crc32 {
3
+ private crc;
4
+ update(bytes: Uint8Array): void;
5
+ get value(): number;
6
+ }
@@ -0,0 +1,17 @@
1
+ const crcTable = new Uint32Array(256).map((_, index) => {
2
+ let value = index;
3
+ for (let bit = 0; bit < 8; bit++)
4
+ value = value & 1 ? 0xedb88320 ^ (value >>> 1) : value >>> 1;
5
+ return value >>> 0;
6
+ });
7
+ /** Incremental CRC-32/ISO-HDLC shared by ZIP and PNG chunk validation. */
8
+ export class Crc32 {
9
+ crc = 0xffffffff;
10
+ update(bytes) {
11
+ let crc = this.crc;
12
+ for (let index = 0; index < bytes.length; index++)
13
+ crc = crcTable[(crc ^ bytes[index]) & 255] ^ (crc >>> 8);
14
+ this.crc = crc;
15
+ }
16
+ get value() { return (this.crc ^ 0xffffffff) >>> 0; }
17
+ }
@@ -0,0 +1,3 @@
1
+ import type { ExportValue } from "../core/presentation.js";
2
+ /** Copy portable values when an operation retains metadata or a projected row beyond its producer's turn. */
3
+ export declare function copyExportValue(value: unknown): ExportValue;
@@ -0,0 +1,14 @@
1
+ import { ExportCell, assertExportValue } from "../core/presentation.js";
2
+ import { isDate } from "../core/dates.js";
3
+ /** Copy portable values when an operation retains metadata or a projected row beyond its producer's turn. */
4
+ export function copyExportValue(value) {
5
+ assertExportValue(value);
6
+ if (isDate(value))
7
+ return new Date(Date.prototype.getTime.call(value));
8
+ if (value instanceof ExportCell) {
9
+ const { value: scalar, text, presentation, link } = value;
10
+ return new ExportCell(isDate(scalar) ? new Date(Date.prototype.getTime.call(scalar)) : scalar, { ...(text === undefined ? {} : { text }), ...(presentation === undefined ? {} : { presentation }),
11
+ ...(link === undefined ? {} : { link }) });
12
+ }
13
+ return value;
14
+ }