@evotecit/officeimo 0.0.0-stage → 0.1.1

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 (261) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1222 -2
  3. package/bundles/officeimo-canopyx.js +11741 -0
  4. package/bundles/officeimo-canopyx.mjs +11639 -0
  5. package/bundles/officeimo-csv.js +1264 -0
  6. package/bundles/officeimo-csv.mjs +1239 -0
  7. package/bundles/officeimo-datatables.js +12018 -0
  8. package/bundles/officeimo-datatables.mjs +11915 -0
  9. package/bundles/officeimo-execution.js +1513 -0
  10. package/bundles/officeimo-execution.mjs +1489 -0
  11. package/bundles/officeimo-pdf.js +7009 -0
  12. package/bundles/officeimo-pdf.mjs +6946 -0
  13. package/bundles/officeimo-xlsx.js +5344 -0
  14. package/bundles/officeimo-xlsx.mjs +5290 -0
  15. package/bundles/officeimo.js +11468 -0
  16. package/bundles/officeimo.mjs +11369 -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 +74 -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 +102 -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 +122 -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 +77 -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 +244 -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 +202 -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 +183 -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 +320 -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 +678 -0
  145. package/dist/pdf/paragraph-layout.d.ts +21 -0
  146. package/dist/pdf/paragraph-layout.js +71 -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 +17 -0
  164. package/dist/pdf/settings.js +196 -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 +302 -0
  173. package/dist/pdf/table-band-flow.d.ts +34 -0
  174. package/dist/pdf/table-band-flow.js +129 -0
  175. package/dist/pdf/table-band-plan.d.ts +10 -0
  176. package/dist/pdf/table-band-plan.js +83 -0
  177. package/dist/pdf/table-layout.d.ts +75 -0
  178. package/dist/pdf/table-layout.js +217 -0
  179. package/dist/pdf/table-structure.d.ts +1 -0
  180. package/dist/pdf/table-structure.js +108 -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 +101 -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 +171 -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/pdf/xref.d.ts +1 -0
  194. package/dist/pdf/xref.js +30 -0
  195. package/dist/xlsx/attachments.d.ts +30 -0
  196. package/dist/xlsx/attachments.js +67 -0
  197. package/dist/xlsx/chart-bindings.d.ts +1 -0
  198. package/dist/xlsx/chart-bindings.js +122 -0
  199. package/dist/xlsx/chart-types.d.ts +73 -0
  200. package/dist/xlsx/chart-types.js +1 -0
  201. package/dist/xlsx/chart-xml.d.ts +2 -0
  202. package/dist/xlsx/chart-xml.js +103 -0
  203. package/dist/xlsx/charts.d.ts +1 -0
  204. package/dist/xlsx/charts.js +159 -0
  205. package/dist/xlsx/conditional-formatting.d.ts +1 -0
  206. package/dist/xlsx/conditional-formatting.js +158 -0
  207. package/dist/xlsx/conditional-types.d.ts +64 -0
  208. package/dist/xlsx/conditional-types.js +1 -0
  209. package/dist/xlsx/data-row-ranges.d.ts +5 -0
  210. package/dist/xlsx/data-row-ranges.js +39 -0
  211. package/dist/xlsx/differential-styles.d.ts +1 -0
  212. package/dist/xlsx/differential-styles.js +102 -0
  213. package/dist/xlsx/formula.d.ts +8 -0
  214. package/dist/xlsx/formula.js +104 -0
  215. package/dist/xlsx/grouped-layout.d.ts +61 -0
  216. package/dist/xlsx/grouped-layout.js +79 -0
  217. package/dist/xlsx/grouped.d.ts +16 -0
  218. package/dist/xlsx/grouped.js +161 -0
  219. package/dist/xlsx/index.d.ts +24 -0
  220. package/dist/xlsx/index.js +10 -0
  221. package/dist/xlsx/layout.d.ts +1 -0
  222. package/dist/xlsx/layout.js +186 -0
  223. package/dist/xlsx/options.d.ts +1 -0
  224. package/dist/xlsx/options.js +16 -0
  225. package/dist/xlsx/portable.d.ts +27 -0
  226. package/dist/xlsx/portable.js +44 -0
  227. package/dist/xlsx/preservation.d.ts +1 -0
  228. package/dist/xlsx/preservation.js +60 -0
  229. package/dist/xlsx/ranges.d.ts +1 -0
  230. package/dist/xlsx/ranges.js +24 -0
  231. package/dist/xlsx/regions.d.ts +1 -0
  232. package/dist/xlsx/regions.js +97 -0
  233. package/dist/xlsx/structured-rows.d.ts +11 -0
  234. package/dist/xlsx/structured-rows.js +28 -0
  235. package/dist/xlsx/style-xml.d.ts +1 -0
  236. package/dist/xlsx/style-xml.js +6 -0
  237. package/dist/xlsx/styles.d.ts +70 -0
  238. package/dist/xlsx/styles.js +203 -0
  239. package/dist/xlsx/table.d.ts +12 -0
  240. package/dist/xlsx/table.js +35 -0
  241. package/dist/xlsx/types.d.ts +180 -0
  242. package/dist/xlsx/types.js +1 -0
  243. package/dist/xlsx/validation-types.d.ts +18 -0
  244. package/dist/xlsx/validation-types.js +1 -0
  245. package/dist/xlsx/validation.d.ts +1 -0
  246. package/dist/xlsx/validation.js +92 -0
  247. package/dist/xlsx/values.d.ts +13 -0
  248. package/dist/xlsx/values.js +87 -0
  249. package/dist/xlsx/workbook.d.ts +50 -0
  250. package/dist/xlsx/workbook.js +452 -0
  251. package/dist/xlsx/worksheet.d.ts +71 -0
  252. package/dist/xlsx/worksheet.js +700 -0
  253. package/dist/xlsx/write.d.ts +15 -0
  254. package/dist/xlsx/write.js +47 -0
  255. package/dist/xml/index.d.ts +24 -0
  256. package/dist/xml/index.js +74 -0
  257. package/dist/zip/entry.d.ts +39 -0
  258. package/dist/zip/entry.js +122 -0
  259. package/dist/zip/index.d.ts +44 -0
  260. package/dist/zip/index.js +248 -0
  261. package/package.json +104 -4
@@ -0,0 +1,147 @@
1
+ import { checkAbort, withAbort } from "../core/iteration.js";
2
+ import { OfficeIMOError } from "../core/errors.js";
3
+ import { bounds, captureInput, captureProgress, message, protocol, restoreError, restoreRows, result, wireError } from "./protocol.js";
4
+ const installed = new WeakSet();
5
+ /** Install reusable transport on a host-created worker. The operation owns format selection and ordinary writer options. */
6
+ export function handleWorkerExports(endpoint, operation) {
7
+ if (installed.has(endpoint))
8
+ throw new OfficeIMOError("INVALID_STATE", "A worker export handler is already installed.");
9
+ if (typeof operation !== "function")
10
+ throw new TypeError("A worker export operation is required.");
11
+ installed.add(endpoint);
12
+ let current;
13
+ let disposed = false;
14
+ const post = (job, payload) => endpoint.postMessage({ protocol, job, ...payload });
15
+ async function run(start) {
16
+ const controller = new AbortController(), limits = bounds(start.bounds ?? {}), input = captureInput(start.input, limits);
17
+ const pending = new Map();
18
+ let sequence = 0, writing = false, claimed = false, latest, progress;
19
+ const cancel = () => { for (const entry of pending.values())
20
+ entry.reject(controller.signal.reason); pending.clear(); latest = undefined; };
21
+ controller.signal.addEventListener("abort", cancel, { once: true });
22
+ current = { job: start.job, controller, deliver(data) {
23
+ const entry = pending.get(data.id);
24
+ if (!entry)
25
+ return;
26
+ pending.delete(data.id);
27
+ entry.resolve(data);
28
+ } };
29
+ const ask = (kind, payload = {}) => {
30
+ checkAbort(controller.signal);
31
+ return new Promise((resolve, reject) => {
32
+ const id = ++sequence;
33
+ pending.set(id, { resolve, reject });
34
+ try {
35
+ post(start.job, { kind, id, ...payload });
36
+ }
37
+ catch (error) {
38
+ pending.delete(id);
39
+ reject(error);
40
+ }
41
+ });
42
+ };
43
+ function onProgress(value) {
44
+ checkAbort(controller.signal);
45
+ latest = captureProgress(value, limits);
46
+ if (!progress) {
47
+ progress = (async () => {
48
+ while (latest) {
49
+ const next = latest;
50
+ latest = undefined;
51
+ await ask("progress", { progress: next });
52
+ }
53
+ })().finally(() => { progress = undefined; });
54
+ void progress.catch(error => controller.abort(error));
55
+ }
56
+ }
57
+ const rows = { [Symbol.asyncIterator]() {
58
+ if (claimed)
59
+ throw new TypeError("Worker rows can be consumed only once.");
60
+ claimed = true;
61
+ return (async function* () {
62
+ while (true) {
63
+ const batch = await ask("requestRows");
64
+ if (batch.kind !== "rows" || typeof batch.done !== "boolean")
65
+ throw new TypeError("Invalid worker row response.");
66
+ for (const row of restoreRows(batch.rows, limits)) {
67
+ checkAbort(controller.signal);
68
+ yield row;
69
+ }
70
+ if (batch.done)
71
+ return;
72
+ }
73
+ })();
74
+ } };
75
+ const sink = { async write(bytes) {
76
+ checkAbort(controller.signal);
77
+ if (writing || !(bytes instanceof Uint8Array))
78
+ throw new OfficeIMOError("INVALID_STATE", "Await each worker output write.");
79
+ writing = true;
80
+ try {
81
+ for (let offset = 0; offset < bytes.length; offset += limits.maxChunkBytes)
82
+ // Structured clone copies a view's entire backing buffer. Own exactly
83
+ // this chunk so a large producer write cannot multiply clone memory.
84
+ await ask("output", { bytes: new Uint8Array(bytes.subarray(offset, Math.min(bytes.length, offset + limits.maxChunkBytes))) });
85
+ }
86
+ finally {
87
+ writing = false;
88
+ }
89
+ } };
90
+ try {
91
+ const completed = result(await withAbort(operation({ input, rows, sink, signal: controller.signal, onProgress }), controller.signal));
92
+ if (progress)
93
+ await withAbort(progress, controller.signal);
94
+ if (pending.size)
95
+ throw new OfficeIMOError("INVALID_STATE", "Await worker row and output operations before completing.");
96
+ post(start.job, { kind: "complete", result: completed });
97
+ }
98
+ catch (error) {
99
+ controller.abort(error);
100
+ try {
101
+ post(start.job, { kind: "failed", error: wireError(error) });
102
+ }
103
+ catch { /* A closed endpoint cannot receive a terminal message. */ }
104
+ }
105
+ finally {
106
+ controller.signal.removeEventListener("abort", cancel);
107
+ cancel();
108
+ current = undefined;
109
+ }
110
+ }
111
+ const receive = event => {
112
+ const data = message(event.data);
113
+ if (!data || disposed)
114
+ return;
115
+ if (data.kind === "start") {
116
+ if (current) {
117
+ post(data.job, { kind: "failed", error: wireError(new OfficeIMOError("INVALID_STATE", "The worker already has an active export.")) });
118
+ return;
119
+ }
120
+ void run(data).catch(error => { try {
121
+ post(data.job, { kind: "failed", error: wireError(error) });
122
+ }
123
+ catch { /* Disconnected endpoint. */ } });
124
+ }
125
+ else if (data.job === current?.job) {
126
+ if (data.kind === "cancel")
127
+ current.controller.abort(restoreError(data.error));
128
+ else
129
+ current.deliver(data);
130
+ }
131
+ };
132
+ const broken = event => current?.controller.abort(new Error(event.message || "Worker messaging failed."));
133
+ endpoint.addEventListener("message", receive);
134
+ endpoint.addEventListener("error", broken);
135
+ endpoint.addEventListener("messageerror", broken);
136
+ endpoint.start?.();
137
+ return { dispose(reason = new DOMException("Worker export handler disposed.", "AbortError")) {
138
+ if (disposed)
139
+ return;
140
+ disposed = true;
141
+ current?.controller.abort(reason);
142
+ endpoint.removeEventListener("message", receive);
143
+ endpoint.removeEventListener("error", broken);
144
+ endpoint.removeEventListener("messageerror", broken);
145
+ installed.delete(endpoint);
146
+ } };
147
+ }
@@ -0,0 +1,32 @@
1
+ export * as core from "./core/index.js";
2
+ export * as zip from "./zip/index.js";
3
+ export * as xml from "./xml/index.js";
4
+ export * as opc from "./opc/index.js";
5
+ export * as xlsx from "./xlsx/index.js";
6
+ export * as csv from "./csv/index.js";
7
+ export * as pdf from "./pdf/index.js";
8
+ export { Workbook, Worksheet, Cell, FormulaCell, StyleRegistry, NumberFormats, writeXlsx, writeXlsxTo } from "./xlsx/index.js";
9
+ export { writeCsv, writeCsvTo } from "./csv/index.js";
10
+ export { createGroupedReport } from "./core/grouped-report.js";
11
+ export { writeGroupedXlsx, writeGroupedXlsxTo, addGroupedXlsx } from "./xlsx/grouped.js";
12
+ export { writeGroupedPdf, writeGroupedPdfTo, pdfGroupedTable } from "./pdf/grouped.js";
13
+ export type { GroupedPdfOptions, GroupedPdfTableOptions } from "./pdf/grouped-types.js";
14
+ export type { PdfPageNumberLabels } from "./pdf/types.js";
15
+ export type { RowOutline } from "./xlsx/types.js";
16
+ export type { GroupedXlsxOptions, GroupedXlsxSheetOptions, GroupedXlsxWorksheet, GroupedXlsxGroupRows } from "./xlsx/grouped.js";
17
+ export type { GroupedReportSource, GroupedReportEvent, GroupedReportOptions, GroupedReportSummary, GroupedReportValueContext, GroupedReportLevel, GroupedReportGroup } from "./core/grouped-report.js";
18
+ export type { BooleanText } from "./core/value-text.js";
19
+ export { writePdf, writePdfTo, writePdfDocument, writePdfDocumentTo, pdfTable, PdfFont, preflightPdfText } from "./pdf/index.js";
20
+ export { OfficeIMOError, NotSupportedError, detectFeatures, saveBlob, ExportCell } from "./core/index.js";
21
+ export type { ErrorCode } from "./core/index.js";
22
+ export type { CellValue, Column, ColumnSettings, ColumnValueContext, Row, Rows, ExportValue, CellPresentation, ExportCellOptions, ExportLink, ExportLimits, ExportProgress, ExportResult, OutputDestination, ByteSink, StreamOptions, TableSpanCell, TableSpanRows } from "./core/index.js";
23
+ export type { XlsxOptions, XlsxColumn, WorkbookOptions, SheetOptions, WorkbookLimits, ChartType, ChartData, ChartSeries, ChartColumn, ChartRangeSeries, ChartRangeData, ChartDataLabels, ChartCategoryAxis, ChartValueAxis, WorksheetChart, WorksheetAnchor, ListValidation } from "./xlsx/index.js";
24
+ export type { CsvOptions, CsvColumn, CsvValueContext } from "./csv/index.js";
25
+ export type { PdfOptions, PdfPageSize, PdfMargins, PdfFonts, PdfLimits, PdfTaggedOptions, PdfTableBands, PdfTableFooter, PdfPageContext, PdfTotal } from "./pdf/index.js";
26
+ export type { PdfTextPreflightOptions, PdfTextPreflightResult, PdfTextIssueCode } from "./pdf/index.js";
27
+ export type { PdfFontPreparationOptions } from "./pdf/index.js";
28
+ export type { PdfTextDirection, PdfShapingRun, PdfShapedGlyph, PdfShapedRun, PdfShapeLineRequest, PdfTextShaper } from "./pdf/index.js";
29
+ export type { PdfDocumentOptions, PdfDocumentBlock, PdfTableOptions, PdfTableBlock, PdfParagraphBlock, PdfParagraphStyle, PdfCaption, PdfListBlock, PdfListItem, PdfGroupBlock, PdfPageBreakBlock, PdfImageBlock, PdfRawImage, PdfJpegImage, PdfPngImage, PdfVectorBlock, PdfPathCommand, PdfTextRun, PdfText } from "./pdf/index.js";
30
+ export type { PdfDrawing, PdfDrawingBlock, PdfDrawingElement, PdfDrawingPath, PdfDrawingText, PdfDrawingGroup, PdfDrawingClip, PdfDrawingFont } from "./pdf/index.js";
31
+ export type { PdfSectionBlock, PdfBookmark } from "./pdf/section-types.js";
32
+ export type { PdfGroupedTableBlock } from "./pdf/document-types.js";
package/dist/index.js ADDED
@@ -0,0 +1,14 @@
1
+ export * as core from "./core/index.js";
2
+ export * as zip from "./zip/index.js";
3
+ export * as xml from "./xml/index.js";
4
+ export * as opc from "./opc/index.js";
5
+ export * as xlsx from "./xlsx/index.js";
6
+ export * as csv from "./csv/index.js";
7
+ export * as pdf from "./pdf/index.js";
8
+ export { Workbook, Worksheet, Cell, FormulaCell, StyleRegistry, NumberFormats, writeXlsx, writeXlsxTo } from "./xlsx/index.js";
9
+ export { writeCsv, writeCsvTo } from "./csv/index.js";
10
+ export { createGroupedReport } from "./core/grouped-report.js";
11
+ export { writeGroupedXlsx, writeGroupedXlsxTo, addGroupedXlsx } from "./xlsx/grouped.js";
12
+ export { writeGroupedPdf, writeGroupedPdfTo, pdfGroupedTable } from "./pdf/grouped.js";
13
+ export { writePdf, writePdfTo, writePdfDocument, writePdfDocumentTo, pdfTable, PdfFont, preflightPdfText } from "./pdf/index.js";
14
+ export { OfficeIMOError, NotSupportedError, detectFeatures, saveBlob, ExportCell } from "./core/index.js";
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,34 @@
1
+ /** @internal Typed conversion follows declared datetime intent, never localized display text. */
2
+ export function datetime(value, mode, clock) {
3
+ if (mode === "text")
4
+ return value;
5
+ const match = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})(?::(\d{2})(?:\.(\d+))?)?(Z|[+-]\d{2}:\d{2})$/.exec(value);
6
+ if (!match)
7
+ throw new TypeError("Canopy datetime values require an ISO timestamp with an explicit time zone.");
8
+ const date = new Date(value);
9
+ const offset = match[8] === "Z" ? 0 : (match[8][0] === "+" ? 1 : -1) * (Number(match[8].slice(1, 3)) * 60 + Number(match[8].slice(4)));
10
+ const year = Number(match[1]), month = Number(match[2]), day = Number(match[3]);
11
+ const hour = Number(match[4]), minute = Number(match[5]), second = Number(match[6] ?? "0"), fraction = match[7] ?? "";
12
+ // setUTCFullYear preserves years 0 through 99. Validate the calendar before allowing ISO's next-day 24:00 spelling.
13
+ const wall = new Date(0);
14
+ wall.setUTCFullYear(year, month - 1, day);
15
+ if (!Number.isFinite(date.getTime()) || Number(match[8].slice(1, 3)) > 23 || Number(match[8].slice(4)) > 59 ||
16
+ wall.getUTCFullYear() !== year || wall.getUTCMonth() + 1 !== month || wall.getUTCDate() !== day ||
17
+ hour > 24 || minute > 59 || second > 59 || hour === 24 && (minute !== 0 || second !== 0 || /[1-9]/.test(fraction)))
18
+ throw new TypeError("Invalid Canopy datetime value.");
19
+ wall.setUTCHours(hour, minute, second, Number((fraction + "000").slice(0, 3)));
20
+ if (wall.getTime() !== date.getTime() + offset * 60000)
21
+ throw new TypeError("Invalid Canopy datetime value.");
22
+ if (/[1-9]/.test(fraction.slice(3))) {
23
+ if (mode === "typed")
24
+ throw new TypeError("Typed Excel dates cannot preserve sub-millisecond precision; use datetime: preserve or text.");
25
+ return value;
26
+ }
27
+ const excelYear = clock === "utc" ? date.getUTCFullYear() : date.getFullYear();
28
+ if (excelYear < 1900 || excelYear > 9999) {
29
+ if (mode === "typed")
30
+ throw new TypeError("Typed Excel dates require years 1900 through 9999; use datetime: preserve or text.");
31
+ return value;
32
+ }
33
+ return date;
34
+ }
@@ -0,0 +1,10 @@
1
+ import type { OutputDestination, ExportResult } from "../../core/index.js";
2
+ import type { CanopyCapture, CanopyFormat, CanopyWriteOptions } from "./types.js";
3
+ export { createCanopyExport } from "./source.js";
4
+ export { ExportCell } from "../../core/presentation.js";
5
+ export { PdfFont } from "../../pdf/font.js";
6
+ export type { CanopyCapture, CanopyExportCell, CanopyExportColumn, CanopyExportRow, CanopyExport, CanopyFormat, CanopyDiagnostic, CanopySourceOptions, CanopyWriteOptions } from "./types.js";
7
+ /** Write a captured CanopyX grid to a caller-owned destination; its partial bytes remain caller-owned on failure. */
8
+ export declare function writeCanopyTo(capture: CanopyCapture, format: CanopyFormat, destination: OutputDestination, options?: CanopyWriteOptions): Promise<ExportResult>;
9
+ /** Export an immutable native capture as a Blob without loading or registering CanopyX. */
10
+ export declare function exportCanopy(capture: CanopyCapture, format: CanopyFormat, options?: CanopyWriteOptions): Promise<Blob>;
@@ -0,0 +1,45 @@
1
+ import { BlobByteSink } from "../../core/index.js";
2
+ import { notifyProgress } from "../../core/progress.js";
3
+ import { captureFields } from "../../internal/capture.js";
4
+ import { captureCommonLimits, captureXlsxOptions, captureCsvOptions, capturePdfOptions, mergeAdapterLimits } from "../options.js";
5
+ import { writeXlsxTo } from "../../xlsx/index.js";
6
+ import { writeCsvTo } from "../../csv/index.js";
7
+ import { writePdfTo } from "../../pdf/index.js";
8
+ import { createCanopyExport } from "./source.js";
9
+ export { createCanopyExport } from "./source.js";
10
+ export { ExportCell } from "../../core/presentation.js";
11
+ export { PdfFont } from "../../pdf/font.js";
12
+ /** Write a captured CanopyX grid to a caller-owned destination; its partial bytes remain caller-owned on failure. */
13
+ export async function writeCanopyTo(capture, format, destination, options = {}) {
14
+ const selected = captureFields(options, ["tones", "columnOptions", "unsupportedPresentation", "datetime", "xlsx", "csv", "pdf", "signal", "onDiagnostic", "limits", "onProgress"]);
15
+ const { signal, onProgress } = selected, limits = captureCommonLimits(selected.limits);
16
+ const xlsx = captureXlsxOptions(format === "xlsx" ? selected.xlsx : undefined);
17
+ const csv = captureCsvOptions(format === "csv" ? selected.csv : undefined);
18
+ const pdf = capturePdfOptions(format === "pdf" ? selected.pdf : undefined);
19
+ const source = createCanopyExport(capture, format, { ...selected, xlsx });
20
+ const progress = onProgress ? { onProgress: (event) => {
21
+ notifyProgress(onProgress, { ...event, ...(source.rowCount === null ? {} : { totalRows: source.rowCount }) });
22
+ } } : {};
23
+ const stream = { ...(signal ? { signal } : {}), ...progress };
24
+ if (format === "xlsx")
25
+ return writeXlsxTo(source.rows(), destination, { ...xlsx, ...stream, columns: source.columns,
26
+ dateMode: xlsx.dateMode ?? capture.request.timeZone,
27
+ limits: mergeAdapterLimits(xlsx.limits, limits) });
28
+ if (format === "pdf")
29
+ return writePdfTo(source.rows(), destination, { ...pdf, ...stream, columns: source.columns,
30
+ limits: mergeAdapterLimits(pdf.limits, limits) });
31
+ return writeCsvTo(source.rows(), destination, { ...csv, ...stream, columns: source.columns, valueMode: capture.request.values,
32
+ limits: mergeAdapterLimits(csv.limits, limits) });
33
+ }
34
+ /** Export an immutable native capture as a Blob without loading or registering CanopyX. */
35
+ export async function exportCanopy(capture, format, options = {}) {
36
+ const sink = new BlobByteSink();
37
+ try {
38
+ await writeCanopyTo(capture, format, sink, options);
39
+ return sink.toBlob(format === "xlsx" ? "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" : format === "pdf" ? "application/pdf" : "text/csv;charset=utf-8");
40
+ }
41
+ catch (error) {
42
+ sink.discard();
43
+ throw error;
44
+ }
45
+ }
@@ -0,0 +1,3 @@
1
+ import type { CanopyCapture, CanopyExport, CanopyFormat, CanopySourceOptions } from "./types.js";
2
+ /** Map an immutable CanopyX record capture to a writer without querying the grid or retaining its body. */
3
+ export declare function createCanopyExport(capture: CanopyCapture, format: CanopyFormat, options?: CanopySourceOptions): CanopyExport;
@@ -0,0 +1,122 @@
1
+ import { ExportCell, checkAbort, inputRows } from "../../core/index.js";
2
+ import { datetime } from "./dates.js";
3
+ import { captureFields } from "../../internal/capture.js";
4
+ import { copyColumns } from "../../internal/rows.js";
5
+ import { copyCellPresentation } from "../../core/presentation.js";
6
+ const columnFields = ["width", "format", "wrapText", "alignment", "rowHeader", "groups"];
7
+ /** Map an immutable CanopyX record capture to a writer without querying the grid or retaining its body. */
8
+ export function createCanopyExport(capture, format, options = {}) {
9
+ options = captureFields(options, ["tones", "columnOptions", "unsupportedPresentation", "datetime", "xlsx", "signal", "onDiagnostic"]);
10
+ if (format !== "xlsx" && format !== "csv" && format !== "pdf")
11
+ throw new TypeError("Canopy export format must be xlsx, csv or pdf.");
12
+ if (!capture || typeof capture.rows !== "function" || !capture.request)
13
+ throw new TypeError("A portable CanopyX capture with request and rows() is required.");
14
+ const { request } = capture, signal = options.signal, values = request.values;
15
+ if (!Array.isArray(request.columns) || !request.columns.length || (request.recordCount !== null && (!Number.isSafeInteger(request.recordCount) || request.recordCount < 0)) ||
16
+ (values !== "raw" && values !== "display") || (request.timeZone !== "utc" && request.timeZone !== "local") || typeof request.revision !== "string")
17
+ throw new TypeError("Invalid portable CanopyX capture metadata.");
18
+ const policy = options.unsupportedPresentation ?? (format === "csv" ? "text" : "reject"), dateMode = options.datetime ?? "preserve", notify = options.onDiagnostic;
19
+ const clock = options.xlsx?.dateMode ?? request.timeZone;
20
+ if (clock !== "utc" && clock !== "local")
21
+ throw new TypeError("XLSX dateMode must be utc or local.");
22
+ if (policy !== "reject" && policy !== "text")
23
+ throw new TypeError("unsupportedPresentation must be reject or text.");
24
+ if (dateMode !== "preserve" && dateMode !== "typed" && dateMode !== "text")
25
+ throw new TypeError("datetime must be preserve, typed or text.");
26
+ if (notify !== undefined && typeof notify !== "function")
27
+ throw new TypeError("onDiagnostic must be a synchronous function.");
28
+ const report = (diagnostic) => {
29
+ if (policy === "reject")
30
+ throw new TypeError("Unsupported Canopy presentation: " + diagnostic.code + (diagnostic.columnId ? " (" + diagnostic.columnId + ")" : ""));
31
+ const result = notify?.(Object.freeze(diagnostic));
32
+ if (result && typeof result.then === "function") {
33
+ void Promise.resolve(result).catch(() => { });
34
+ throw new TypeError("onDiagnostic must be synchronous.");
35
+ }
36
+ };
37
+ const diagnostics = (items, rowId, columnId) => {
38
+ if (items === undefined)
39
+ return;
40
+ if (!Array.isArray(items) || items.some(item => typeof item !== "string"))
41
+ throw new TypeError("Canopy presentation diagnostics must be strings.");
42
+ for (const code of items)
43
+ report({ code, ...(rowId === undefined ? {} : { rowId }), ...(columnId === undefined ? {} : { columnId }) });
44
+ };
45
+ if (request.presentation === "text")
46
+ report({ code: "TEXT_ONLY_CAPTURE" });
47
+ else if (request.presentation !== "semantic")
48
+ throw new TypeError("Canopy captures must declare text or semantic presentation.");
49
+ const tones = new Map(Object.entries(options.tones ?? {}).map(([name, style]) => {
50
+ if (!style || typeof style !== "object" || Array.isArray(style))
51
+ throw new TypeError("Tone mappings must be portable presentation objects.");
52
+ return [name, copyCellPresentation(style)];
53
+ }));
54
+ const tone = (name, rowId, columnId) => {
55
+ if (name === undefined)
56
+ return undefined;
57
+ if (typeof name !== "string")
58
+ throw new TypeError("Canopy tones must be strings.");
59
+ const style = tones.get(name);
60
+ if (!style)
61
+ report({ code: "UNMAPPED_TONE:" + name, rowId, ...(columnId === undefined ? {} : { columnId }) });
62
+ return style;
63
+ };
64
+ const ids = new Set();
65
+ const specs = request.columns.map(column => {
66
+ if (!column || typeof column.id !== "string" || !column.id || ids.has(column.id) || typeof column.title !== "string" ||
67
+ !["text", "number", "datetime"].includes(column.kind) ||
68
+ (column.wrap !== undefined && typeof column.wrap !== "boolean") || (column.alignment !== undefined && !["left", "right"].includes(column.alignment)) ||
69
+ (column.width !== undefined && (column.width.unit !== "css-px" || !Number.isFinite(column.width.preferred) ||
70
+ !Number.isFinite(column.width.minimum) || column.width.minimum <= 0 || column.width.preferred < column.width.minimum ||
71
+ column.width.maximum !== undefined && (!Number.isFinite(column.width.maximum) || column.width.maximum < column.width.preferred))) ||
72
+ (request.presentation === "semantic" && (column.wrap === undefined || column.alignment === undefined || column.width === undefined)))
73
+ throw new TypeError("Invalid or duplicate Canopy export column.");
74
+ ids.add(column.id);
75
+ diagnostics(column.diagnostics, undefined, column.id);
76
+ const selected = Object.hasOwn(options.columnOptions ?? {}, column.id) ? options.columnOptions[column.id] : {};
77
+ for (const key of Object.keys(selected))
78
+ if (!columnFields.includes(key))
79
+ throw new TypeError("Unsupported Canopy column option: " + key);
80
+ const override = captureFields(selected, columnFields);
81
+ const [captured] = copyColumns([{ ...override, key: column.id, header: column.title,
82
+ ...(values === "raw" && column.kind === "number" ? { type: "number" } : {}),
83
+ ...(override.wrapText === undefined && column.wrap === undefined ? {} : { wrapText: override.wrapText ?? column.wrap }),
84
+ ...(override.alignment === undefined && column.alignment === undefined ? {} : { alignment: override.alignment ?? column.alignment }) }]);
85
+ return Object.freeze({ id: column.id, kind: column.kind, column: Object.freeze(captured) });
86
+ });
87
+ const rowCount = request.recordCount;
88
+ return Object.freeze({ columns: Object.freeze(specs.map(spec => spec.column)), rowCount, async *rows() {
89
+ checkAbort(signal);
90
+ let count = 0;
91
+ for await (const row of inputRows(capture.rows(signal ? { signal } : {}), signal)) {
92
+ checkAbort(signal);
93
+ if (!row || typeof row.id !== "string" || !row.cells || typeof row.cells !== "object")
94
+ throw new TypeError("Invalid Canopy export record.");
95
+ diagnostics(row.diagnostics, row.id);
96
+ const rowStyle = tone(row.tone, row.id), result = [];
97
+ for (const spec of specs) {
98
+ if (!Object.hasOwn(row.cells, spec.id))
99
+ throw new TypeError("Canopy record is missing column " + spec.id + ".");
100
+ const cell = row.cells[spec.id];
101
+ if (!cell || typeof cell !== "object" || typeof cell.text !== "string" ||
102
+ (cell.value !== null && !["string", "number", "boolean"].includes(typeof cell.value)) ||
103
+ (typeof cell.value === "number" && (!Number.isFinite(cell.value) || Math.abs(cell.value) > Number.MAX_SAFE_INTEGER)))
104
+ throw new TypeError("A portable Canopy GridExportCell with scalar value and resolved text is required.");
105
+ diagnostics(cell.diagnostics, row.id, spec.id);
106
+ let value = values === "display" ? cell.text : cell.value;
107
+ if (format === "xlsx" && values === "raw" && spec.kind === "datetime" && typeof value === "string")
108
+ value = datetime(value, dateMode, clock);
109
+ const cellStyle = tone(cell.tone, row.id, spec.id), presentation = rowStyle || cellStyle ? { ...rowStyle, ...cellStyle } : undefined;
110
+ // CSV has no presentation or link metadata: emit its selected scalar directly.
111
+ // This also avoids a frozen wrapper for every cell in large CSV captures.
112
+ result.push(format === "csv" ? value : new ExportCell(value, { text: cell.text, ...(presentation ? { presentation } : {}), ...(cell.link === undefined ? {} : { link: cell.link }) }));
113
+ }
114
+ if (rowCount !== null && count >= rowCount)
115
+ throw new TypeError("Canopy capture exceeded its declared recordCount.");
116
+ count++;
117
+ yield result;
118
+ }
119
+ if (rowCount !== null && count !== rowCount)
120
+ throw new TypeError("Canopy capture did not produce its declared recordCount.");
121
+ } });
122
+ }
@@ -0,0 +1,83 @@
1
+ import type { CellPresentation, ColumnSettings, ExportLimits, ExportProgress, ExportValue } from "../../core/index.js";
2
+ import type { ExportLink } from "../../core/links.js";
3
+ import type { CsvOptions } from "../../csv/index.js";
4
+ import type { XlsxOptions } from "../../xlsx/index.js";
5
+ import type { PdfOptions } from "../../pdf/index.js";
6
+ /** Structural portable capture. CanopyX owns queries, selection, presenters and revision validation. */
7
+ export interface CanopyExportCell {
8
+ readonly value: string | number | boolean | null;
9
+ readonly text: string;
10
+ readonly tone?: string;
11
+ readonly link?: ExportLink;
12
+ readonly diagnostics?: readonly string[];
13
+ }
14
+ export interface CanopyExportColumn {
15
+ readonly id: string;
16
+ readonly title: string;
17
+ readonly kind: "text" | "number" | "datetime";
18
+ readonly width?: {
19
+ readonly unit: "css-px";
20
+ readonly preferred: number;
21
+ readonly minimum: number;
22
+ readonly maximum?: number;
23
+ };
24
+ readonly wrap?: boolean;
25
+ readonly alignment?: "left" | "right";
26
+ readonly diagnostics?: readonly string[];
27
+ }
28
+ export interface CanopyExportRow {
29
+ readonly id: string;
30
+ readonly cells: Readonly<Record<string, CanopyExportCell>>;
31
+ readonly tone?: string;
32
+ readonly diagnostics?: readonly string[];
33
+ }
34
+ export interface CanopyCapture {
35
+ readonly request: {
36
+ readonly columns: readonly CanopyExportColumn[];
37
+ readonly recordCount: number | null;
38
+ readonly values: "raw" | "display";
39
+ readonly presentation: "text" | "semantic";
40
+ readonly timeZone: "utc" | "local";
41
+ readonly revision: string;
42
+ };
43
+ /** Fresh serial enumeration. The signal must reach the source's in-flight page requests. */
44
+ rows(options?: {
45
+ readonly signal?: AbortSignal;
46
+ }): AsyncIterable<CanopyExportRow>;
47
+ }
48
+ export type CanopyFormat = "xlsx" | "csv" | "pdf";
49
+ export interface CanopyDiagnostic {
50
+ readonly code: string;
51
+ readonly rowId?: string;
52
+ readonly columnId?: string;
53
+ }
54
+ export interface CanopySourceOptions {
55
+ /** Map semantic tones explicitly; CSS and DOM rules are never inferred. Cell tone overrides row tone. */
56
+ readonly tones?: Readonly<Record<string, CellPresentation>>;
57
+ /** Selected-column overrides. Unselected IDs are ignored; widths use Excel zero-character units, not CSS pixels. */
58
+ readonly columnOptions?: Readonly<Record<string, Omit<Partial<ColumnSettings>, "header" | "type">>>;
59
+ /** XLSX/PDF reject unsupported presentation by default. CSV defaults to text because it has no visual styling. */
60
+ readonly unsupportedPresentation?: "reject" | "text";
61
+ /** XLSX: preserve uses typed Dates where exact and literal ISO text for greater precision. */
62
+ readonly datetime?: "preserve" | "typed" | "text";
63
+ /** The same clock used by the XLSX writer; defaults to the native capture's timeZone. */
64
+ readonly xlsx?: Pick<XlsxOptions, "dateMode">;
65
+ readonly signal?: AbortSignal;
66
+ /** Synchronous notification; throwing aborts enumeration. No unbounded diagnostic list is retained. */
67
+ readonly onDiagnostic?: (diagnostic: CanopyDiagnostic) => void;
68
+ }
69
+ /** Each call to rows opens an independent native capture enumeration. No whole-table matrix is retained. */
70
+ export interface CanopyExport {
71
+ readonly columns: readonly (ColumnSettings & {
72
+ readonly key: string;
73
+ })[];
74
+ readonly rowCount: number | null;
75
+ rows(): AsyncIterable<readonly ExportValue[]>;
76
+ }
77
+ export interface CanopyWriteOptions extends CanopySourceOptions {
78
+ readonly limits?: ExportLimits;
79
+ readonly onProgress?: (progress: ExportProgress) => void;
80
+ readonly xlsx?: Omit<XlsxOptions, "columns" | "signal" | "onProgress">;
81
+ readonly csv?: Omit<CsvOptions, "columns" | "signal" | "onProgress" | "valueMode">;
82
+ readonly pdf?: Omit<PdfOptions, "columns" | "signal" | "onProgress">;
83
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,27 @@
1
+ /** @internal Runtime-checked calls across the optional third-party API boundary. */
2
+ export function call(owner, name, ...args) {
3
+ const fn = member(owner, name);
4
+ if (typeof fn !== "function")
5
+ throw new TypeError("DataTables API requires " + name + "().");
6
+ return Reflect.apply(fn, owner, args);
7
+ }
8
+ /** @internal */
9
+ export function member(owner, name) {
10
+ return owner != null && (typeof owner === "object" || typeof owner === "function")
11
+ ? owner[name] : undefined;
12
+ }
13
+ /** @internal */
14
+ export function array(value) {
15
+ const result = Array.isArray(value) ? value : call(value, "toArray");
16
+ if (!Array.isArray(result))
17
+ throw new TypeError("DataTables API must return an array.");
18
+ return result;
19
+ }
20
+ /** @internal */
21
+ export function indexes(value) {
22
+ return array(call(value, "indexes")).map(index => {
23
+ if (!Number.isSafeInteger(index) || index < 0)
24
+ throw new TypeError("Invalid DataTables index.");
25
+ return index;
26
+ });
27
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,65 @@
1
+ import { ExportCell, assertExportValue } from "../../core/presentation.js";
2
+ import { tableSpans } from "../../internal/table-spans.js";
3
+ import { member } from "./api.js";
4
+ /** @internal */
5
+ export function value(input) {
6
+ assertExportValue(input);
7
+ return input;
8
+ }
9
+ /** @internal */
10
+ export function text(input) {
11
+ const scalar = value(input);
12
+ return String(scalar instanceof ExportCell ? scalar.text ?? scalar.value ?? "" : scalar ?? "");
13
+ }
14
+ /** @internal Horizontal hierarchy maps to the existing shared Column.groups contract. */
15
+ export function headings(structure, leaf, mode) {
16
+ const groups = leaf.map(() => []);
17
+ if (mode === "leaf" || !Array.isArray(structure) || !structure.length)
18
+ return { rows: [leaf.map(value)], groups };
19
+ if (mode === "structured") {
20
+ const cells = structure.map((row) => {
21
+ if (!Array.isArray(row))
22
+ throw new TypeError("Invalid DataTables heading structure.");
23
+ return row.map((cell) => cell == null ? null : Object.freeze({ value: value(member(cell, "title")),
24
+ columnSpan: member(cell, "colspan"), rowSpan: member(cell, "rowspan") }));
25
+ });
26
+ tableSpans(cells, leaf.length);
27
+ return { rows: cells.map(row => row.map(cell => cell?.value ?? "")), groups, structure: Object.freeze(cells.map(row => Object.freeze(row))) };
28
+ }
29
+ const rows = structure.map((source, level) => {
30
+ if (!Array.isArray(source) || source.length !== leaf.length)
31
+ throw new TypeError("Invalid DataTables heading structure.");
32
+ const row = leaf.map(() => "");
33
+ for (let index = 0; index < source.length;) {
34
+ const cell = source[index];
35
+ const span = member(cell, "colspan"), height = member(cell, "rowspan");
36
+ if (cell == null || height !== 1 || !Number.isInteger(span) || span < 1 || index + span > leaf.length)
37
+ throw new TypeError("Grouped export requires horizontal header spans; select headings: 'leaf' for vertical spans.");
38
+ if (level === structure.length - 1 && span !== 1)
39
+ throw new TypeError("Grouped export requires one leaf header per column.");
40
+ const title = text(member(cell, "title"));
41
+ row[index] = title;
42
+ if (span !== 1 && !title)
43
+ throw new TypeError("Blank spanning headings require headings: 'leaf'.");
44
+ for (let covered = index; covered < index + span; covered++) {
45
+ if (covered !== index && source[covered] != null)
46
+ throw new TypeError("Invalid overlapping DataTables heading cells.");
47
+ if (level < structure.length - 1)
48
+ groups[covered].push(title);
49
+ }
50
+ index += span;
51
+ }
52
+ return row;
53
+ });
54
+ // The shared layout merges equal adjacent group paths. Reject distinct source cells
55
+ // that would otherwise become one merge instead of changing their structure silently.
56
+ for (let level = 0; level < rows.length - 1; level++) {
57
+ const source = structure[level];
58
+ for (let index = 1; index < source.length; index++) {
59
+ if (source[index] != null && groups[index][level] &&
60
+ JSON.stringify(groups[index].slice(0, level + 1)) === JSON.stringify(groups[index - 1].slice(0, level + 1)))
61
+ throw new TypeError("Adjacent separate headings with equal group paths require headings: 'leaf'.");
62
+ }
63
+ }
64
+ return { rows, groups };
65
+ }
@@ -0,0 +1,12 @@
1
+ import type { OutputDestination, ExportResult } from "../../core/index.js";
2
+ import type { DataTablesApi, DataTablesButtonOptions, DataTablesHost, DataTablesWriteOptions } from "./types.js";
3
+ export { createDataTablesExport } from "./snapshot.js";
4
+ export { ExportCell } from "../../core/presentation.js";
5
+ export { PdfFont } from "../../pdf/font.js";
6
+ export type { DataTablesApi, DataTablesHost, DataTablesOptions, DataTablesExportOptions, DataTablesFormat, DataTablesCellContext, DataTablesExport, DataTablesWriteOptions, DataTablesButtonOptions } from "./types.js";
7
+ /** Write directly to a caller-owned destination. Failed destinations own disposal of their partial bytes. */
8
+ export declare function writeDataTableTo(host: DataTablesHost, table: DataTablesApi, format: "xlsx" | "csv" | "pdf", destination: OutputDestination, options?: DataTablesWriteOptions): Promise<ExportResult>;
9
+ /** Return a browser/worker/Node Blob. Use writeDataTableTo to avoid retaining the completed file in memory. */
10
+ export declare function exportDataTable(host: DataTablesHost, table: DataTablesApi, format: "xlsx" | "csv" | "pdf", options?: DataTablesWriteOptions): Promise<Blob>;
11
+ /** Register opt-in Buttons entries; no import-time registration, DataTables import or jQuery dependency. */
12
+ export declare function registerDataTablesButtons(host: DataTablesHost, options?: DataTablesButtonOptions): void;