@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,16 @@
1
+ import type { ExportResult, OutputDestination } from "../core/index.js";
2
+ import type { GroupedReportSource } from "../core/grouped-report.js";
3
+ import { Workbook } from "./workbook.js";
4
+ import type { WorkbookOptions } from "./types.js";
5
+ import type { GroupedXlsxSheetOptions, GroupedXlsxWorksheet } from "./grouped-layout.js";
6
+ export type { GroupedXlsxSheetOptions, GroupedXlsxWorksheet, GroupedXlsxGroupRows } from "./grouped-layout.js";
7
+ /** Convenience-writer settings plus the same composable analysis worksheet contract. */
8
+ export interface GroupedXlsxOptions extends Omit<WorkbookOptions, "sink" | "cellValueWriters">, GroupedXlsxSheetOptions {
9
+ }
10
+ /** Add one ordered analysis worksheet, preserving the workbook's styles, budgets, destination and sibling sheets.
11
+ * The returned worksheet is closed; finalize the workbook only after adding any remaining sheets. */
12
+ export declare function addGroupedXlsx(book: Workbook, report: GroupedReportSource, options: GroupedXlsxSheetOptions): Promise<GroupedXlsxWorksheet>;
13
+ /** Write one ordered grouped source to editable Excel outlines and finite native SUBTOTAL formulas. */
14
+ export declare function writeGroupedXlsx(report: GroupedReportSource, options: GroupedXlsxOptions): Promise<Blob>;
15
+ /** Await accepted bytes; the caller retains its sink, partial bytes and stream lifetime. Counts exclude generated summary rows. */
16
+ export declare function writeGroupedXlsxTo(report: GroupedReportSource, destination: OutputDestination, options: GroupedXlsxOptions): Promise<ExportResult>;
@@ -0,0 +1,161 @@
1
+ import { groupedReportOperation } from "../core/grouped-report.js";
2
+ import { checkAbort, withAbort } from "../core/iteration.js";
3
+ import { withDestination } from "../core/sinks.js";
4
+ import { captureFields } from "../internal/capture.js";
5
+ import { Workbook } from "./workbook.js";
6
+ import { FormulaCell } from "./formula.js";
7
+ import { columnName } from "./values.js";
8
+ import { captureWorkbookLimits, workbookOptionFields } from "./options.js";
9
+ import { retainDataRowRanges } from "./data-row-ranges.js";
10
+ import { groupedOptionFields, prepareGroupedSheet } from "./grouped-layout.js";
11
+ const subtotalOperations = { average: 1, count: 2, max: 4, min: 5, sum: 9 };
12
+ function label(value) {
13
+ if (typeof value?.then === "function")
14
+ void Promise.resolve(value).catch(() => { });
15
+ if (typeof value !== "string")
16
+ throw new TypeError("Grouped summary labels must return strings.");
17
+ return value;
18
+ }
19
+ /** SUBTOTAL ignores nested subtotal expressions; functions 1..11 include collapsed outline details. */
20
+ function subtotal(operation, letter, first, last, cached) {
21
+ const range = letter + first + ":" + letter + last;
22
+ const expression = "SUBTOTAL(" + subtotalOperations[operation] + "," + range + ")";
23
+ return new FormulaCell(operation === "average" || operation === "min" || operation === "max"
24
+ ? "IF(SUBTOTAL(2," + range + ")=0,\"\"," + expression + ")" : expression, cached, operation === "count" ? 0 : undefined);
25
+ }
26
+ async function append(book, report, options, operation, accepted) {
27
+ checkAbort(operation.signal);
28
+ const { labelColumn, subtotalLabel, grandTotalLabel, includeGrandTotal, collapseGroups, sheet: sheetOptions, groupStyle, subtotalStyle, grandTotalStyle, conditionalFormats, dataValidation } = options;
29
+ let rows = 0, current;
30
+ const groups = [], stack = [], detailRanges = [];
31
+ let firstDetail = 0, lastDetail = 0, grandTotalRow;
32
+ let grandSummary;
33
+ const { name = "Data", ...sheetSettings } = sheetOptions ?? {};
34
+ const columns = [{ ...labelColumn, type: "string" }, ...report.columns];
35
+ const styles = { groupStart: groupStyle ?? { font: { bold: true } }, groupEnd: subtotalStyle ?? { font: { bold: true } }, complete: grandTotalStyle ?? { font: { bold: true } } };
36
+ const sheet = book.addWorksheet(name, { boldHeader: true, autoSize: { minWidth: 6, maxWidth: 54 }, ...sheetSettings, columns,
37
+ ...(conditionalFormats === undefined ? {} : { conditionalFormats }), ...(dataValidation === undefined ? {} : { dataValidation }),
38
+ maxOutlineLevel: report.groupBy.length,
39
+ rowStyle: () => current && current.kind !== "row" ? styles[current.kind] : undefined,
40
+ rowOutline: () => {
41
+ if (!current || current.kind === "complete")
42
+ return undefined;
43
+ const level = current.kind === "row" ? current.path.length : current.level;
44
+ return { level, hidden: !!collapseGroups && level > 0, collapsed: !!collapseGroups && current.kind === "groupEnd" };
45
+ } });
46
+ retainDataRowRanges(sheet, detailRanges);
47
+ const operations = report.columns.map(column => Object.prototype.hasOwnProperty.call(report.totals, column.key) ? report.totals[column.key] : undefined);
48
+ async function* values() {
49
+ for await (const event of operation.events) {
50
+ current = event;
51
+ const worksheetRow = sheet.rowCount + sheet.headerRowCount + 1;
52
+ if (event.kind === "groupStart") {
53
+ const group = { groupIndex: event.groupIndex, level: event.level, key: event.key, label: event.label, path: event.path,
54
+ rows: 0, totals: Object.freeze([]), startRow: worksheetRow, firstDetailRow: 0, lastDetailRow: 0, summaryRow: 0 };
55
+ groups.push(group);
56
+ stack.push(group);
57
+ yield [event.label, ...report.columns.map(() => null)];
58
+ }
59
+ else if (event.kind === "row") {
60
+ rows++;
61
+ accepted?.(rows);
62
+ firstDetail ||= worksheetRow;
63
+ lastDetail = worksheetRow;
64
+ const previous = detailRanges.at(-1);
65
+ if (previous && previous.lastRow + 1 === worksheetRow)
66
+ previous.lastRow = worksheetRow;
67
+ else
68
+ detailRanges.push({ firstRow: worksheetRow, lastRow: worksheetRow });
69
+ for (const group of stack) {
70
+ group.firstDetailRow ||= worksheetRow;
71
+ group.lastDetailRow = worksheetRow;
72
+ }
73
+ yield [null, ...event.values];
74
+ }
75
+ else if (event.kind === "groupEnd") {
76
+ const group = stack.pop();
77
+ group.summaryRow = worksheetRow;
78
+ group.rows = event.rows;
79
+ group.totals = event.totals;
80
+ yield [label(subtotalLabel(event)), ...operations.map((operation, index) => operation
81
+ ? subtotal(operation, columnName(index + 2), group.firstDetailRow, group.lastDetailRow, event.totals[index]) : null)];
82
+ }
83
+ else {
84
+ grandSummary = Object.freeze({ rows: event.rows, groups: event.groups, totals: event.totals });
85
+ if (includeGrandTotal !== false) {
86
+ grandTotalRow = worksheetRow;
87
+ // An empty source still retains numeric sum/count and blank average/min/max.
88
+ yield [label(grandTotalLabel(event)), ...operations.map((operation, index) => operation
89
+ ? firstDetail ? subtotal(operation, columnName(index + 2), firstDetail, lastDetail, event.totals[index]) : event.totals[index] : null)];
90
+ }
91
+ }
92
+ }
93
+ }
94
+ try {
95
+ checkAbort(operation.signal);
96
+ await withAbort(sheet.addRows(values()), operation.signal);
97
+ // Grouped coordinates and native editing ranges cannot change after the result is returned.
98
+ await withAbort(sheet.close(), operation.signal);
99
+ return Object.freeze({ worksheet: sheet, rows, columns: columns.length,
100
+ detailRanges: Object.freeze(detailRanges.map(range => Object.freeze({ ...range }))),
101
+ groups: Object.freeze(groups.map(group => Object.freeze({ ...group }))), grandSummary: grandSummary,
102
+ ...(grandTotalRow === undefined ? {} : { grandTotalRow }) });
103
+ }
104
+ catch (error) {
105
+ await book.discard(error);
106
+ throw error;
107
+ }
108
+ }
109
+ /** Add one ordered analysis worksheet, preserving the workbook's styles, budgets, destination and sibling sheets.
110
+ * The returned worksheet is closed; finalize the workbook only after adding any remaining sheets. */
111
+ export async function addGroupedXlsx(book, report, options) {
112
+ const prepared = prepareGroupedSheet(report, options, book.settings.limits?.maxConditionalFormats ?? 1000, book.availableDataValidations), operation = groupedReportOperation(report, book.settings.signal);
113
+ try {
114
+ return await append(book, report, prepared, operation);
115
+ }
116
+ finally {
117
+ operation.dispose();
118
+ }
119
+ }
120
+ function prepare(report, configuration) {
121
+ if (!configuration || typeof configuration !== "object")
122
+ throw new TypeError("Grouped XLSX options require host-authored labels.");
123
+ const options = captureFields(configuration, [...workbookOptionFields, ...groupedOptionFields]);
124
+ if (options.sink !== undefined || options.cellValueWriters !== undefined)
125
+ throw new TypeError("Grouped XLSX owns its destination and uses already resolved source values.");
126
+ const limits = options.limits === undefined ? undefined : captureWorkbookLimits(options.limits);
127
+ return { ...options, ...(limits === undefined ? {} : { limits }),
128
+ ...prepareGroupedSheet(report, options, limits?.maxConditionalFormats ?? 1000, limits?.maxDataValidations ?? 1000) };
129
+ }
130
+ async function write(report, options, sink) {
131
+ const { labelColumn: _labelColumn, subtotalLabel: _subtotalLabel, grandTotalLabel: _grandTotalLabel, includeGrandTotal: _includeGrandTotal, collapseGroups: _collapseGroups, sheet: _sheet, groupStyle: _groupStyle, subtotalStyle: _subtotalStyle, grandTotalStyle: _grandTotalStyle, conditionalFormats: _conditionalFormats, dataValidation: _dataValidation, onProgress, ...settings } = options;
132
+ const operation = groupedReportOperation(report, settings.signal);
133
+ let rows = 0, book;
134
+ const progress = onProgress ? (event) => onProgress({ ...event, rows, ...(event.sheetRows === undefined ? {} : { sheetRows: rows }) }) : undefined;
135
+ try {
136
+ book = new Workbook({ ...settings, ...(operation.signal ? { signal: operation.signal } : {}), ...(progress ? { onProgress: progress } : {}), ...(sink ? { sink } : {}) });
137
+ const result = await append(book, report, options, operation, accepted => { rows = accepted; });
138
+ if (sink) {
139
+ const completion = await book.finish();
140
+ return { result: { rows, columns: result.columns, bytes: completion.bytes } };
141
+ }
142
+ const blob = await book.toBlob();
143
+ return { blob, result: { rows, columns: result.columns, bytes: blob.size } };
144
+ }
145
+ catch (error) {
146
+ await book?.discard(error);
147
+ throw error;
148
+ }
149
+ finally {
150
+ operation.dispose();
151
+ }
152
+ }
153
+ /** Write one ordered grouped source to editable Excel outlines and finite native SUBTOTAL formulas. */
154
+ export async function writeGroupedXlsx(report, options) {
155
+ return (await write(report, prepare(report, options))).blob;
156
+ }
157
+ /** Await accepted bytes; the caller retains its sink, partial bytes and stream lifetime. Counts exclude generated summary rows. */
158
+ export async function writeGroupedXlsxTo(report, destination, options) {
159
+ const prepared = prepare(report, options);
160
+ return withDestination(destination, async (sink) => (await write(report, prepared, sink)).result);
161
+ }
@@ -0,0 +1,24 @@
1
+ export { Workbook } from "./workbook.js";
2
+ export { writeXlsx, writeXlsxTo } from "./write.js";
3
+ export { writeGroupedXlsx, writeGroupedXlsxTo, addGroupedXlsx } from "./grouped.js";
4
+ export type { GroupedXlsxOptions, GroupedXlsxSheetOptions, GroupedXlsxWorksheet, GroupedXlsxGroupRows } from "./grouped.js";
5
+ export type { RowOutline } from "./types.js";
6
+ export { createGroupedReport } from "../core/grouped-report.js";
7
+ export type { GroupedReportSource, GroupedReportOptions, GroupedReportEvent, GroupedReportSummary, GroupedReportValueContext, GroupedReportLevel, GroupedReportGroup } from "../core/grouped-report.js";
8
+ export type { XlsxOptions } from "./write.js";
9
+ export type { XlsxColumn } from "./types.js";
10
+ export { Worksheet } from "./worksheet.js";
11
+ export type { PortableCellStyle, PortableSheetOptions, PortableWorkbookOptions } from "./portable.js";
12
+ export { Cell } from "./values.js";
13
+ export { FormulaCell } from "./formula.js";
14
+ export type { ListValidation } from "./validation-types.js";
15
+ export { StyleRegistry, NumberFormats } from "./styles.js";
16
+ export type { Font, Fill, Border, BorderEdge, BorderLineStyle, CellStyle } from "./styles.js";
17
+ export type { WorkbookOptions, WorkbookLimits, XlsxExportResult, SheetOptions, ReportTitle, TableOptions, AutoSizeOptions, FooterOptions, TotalOperation, PrintOptions, RowStyleContext, CellStyleContext, ExtraPart, CellValueWriter, CellWriterContext, XlsxRow, XlsxRows } from "./types.js";
18
+ export type { Hyperlink, WorksheetImage, WorksheetAnchor } from "./attachments.js";
19
+ export type { ChartType, ChartData, ChartSeries, ChartColumn, ChartRangeSeries, ChartRangeData, ChartDataLabels, ChartCategoryAxis, ChartValueAxis, WorksheetChart } from "./chart-types.js";
20
+ export type { ConditionalFormat, ConditionalRange, ConditionalStyle, ConditionalOperator, ConditionalThreshold, ConditionalColorStop } from "./conditional-types.js";
21
+ export { saveBlob } from "../core/index.js";
22
+ export { ExportCell } from "../core/presentation.js";
23
+ export type { CellPresentation, ExportValue } from "../core/presentation.js";
24
+ export type { CellValue, Column, ColumnValueContext, Row, Rows, StreamOptions, ExportProgress, ExportResult, OutputDestination } from "../core/index.js";
@@ -0,0 +1,10 @@
1
+ export { Workbook } from "./workbook.js";
2
+ export { writeXlsx, writeXlsxTo } from "./write.js";
3
+ export { writeGroupedXlsx, writeGroupedXlsxTo, addGroupedXlsx } from "./grouped.js";
4
+ export { createGroupedReport } from "../core/grouped-report.js";
5
+ export { Worksheet } from "./worksheet.js";
6
+ export { Cell } from "./values.js";
7
+ export { FormulaCell } from "./formula.js";
8
+ export { StyleRegistry, NumberFormats } from "./styles.js";
9
+ export { saveBlob } from "../core/index.js";
10
+ export { ExportCell } from "../core/presentation.js";
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,186 @@
1
+ import { ExportCell } from "../core/presentation.js";
2
+ import { isDate } from "../core/dates.js";
3
+ import { Cell, cellText, columnName } from "./values.js";
4
+ import { FormulaCell } from "./formula.js";
5
+ import { escapeOoxmlAttribute } from "../xml/index.js";
6
+ import { MergeRegions } from "./regions.js";
7
+ import { OfficeIMOError } from "../core/errors.js";
8
+ import { createTotals } from "../internal/totals.js";
9
+ import { StructuredRows } from "./structured-rows.js";
10
+ /** @internal A computed formula with a numeric cache; no public arbitrary-formula input. */
11
+ export class ComputedTotal {
12
+ value;
13
+ formula;
14
+ operation;
15
+ constructor(value, formula, operation) {
16
+ this.value = value;
17
+ this.formula = formula;
18
+ this.operation = operation;
19
+ }
20
+ }
21
+ /** @internal Bounded report layout and incremental numeric aggregates. */
22
+ export class ReportLayout {
23
+ columns;
24
+ options;
25
+ headings;
26
+ merges;
27
+ headerRows;
28
+ firstHeaderRow;
29
+ regions;
30
+ widths;
31
+ sampleRows;
32
+ structuredFooter;
33
+ footerRows;
34
+ mergeCount;
35
+ aggregates;
36
+ constructor(columns, options, policy, maximumMerges = 10000, maximumSampleCells = 100000) {
37
+ this.columns = columns;
38
+ this.options = options;
39
+ const titleRows = options.title === undefined ? 0 : 1;
40
+ if (options.title !== undefined) {
41
+ if (!columns.length)
42
+ throw new TypeError("Report titles require declared columns.");
43
+ if (typeof options.title.text !== "string")
44
+ throw new TypeError("Report title text must be a string.");
45
+ cellText(options.title.text, policy);
46
+ if (options.title.height !== undefined && (!Number.isFinite(options.title.height) || options.title.height <= 0 || options.title.height > 409))
47
+ throw new RangeError("Title height must be positive and at most 409 points.");
48
+ }
49
+ const depth = Math.max(0, ...columns.map(c => c.groups?.length ?? 0));
50
+ if (options.headerRows === undefined) {
51
+ if (depth > 16)
52
+ throw new RangeError("Grouped headings support at most 16 levels.");
53
+ if (depth && options.includeHeader === false)
54
+ throw new TypeError("Grouped headings require leaf headers.");
55
+ }
56
+ const headings = [], merges = [];
57
+ if (titleRows && columns.length > 1)
58
+ merges.push("A1:" + columnName(columns.length) + "1");
59
+ if (options.headerRows !== undefined && options.includeHeader !== false) {
60
+ const structured = new StructuredRows(options.headerRows, columns.length);
61
+ if ((options.table || options.autoFilter) && !structured.matchesLeaf(columns.map(c => c.header)))
62
+ throw new TypeError("Native tables and autofilters require an unmerged final heading row matching the declared leaf headers.");
63
+ headings.push(...structured.values);
64
+ merges.push(...structured.merges(titleRows));
65
+ }
66
+ else if (options.includeHeader !== false) {
67
+ for (let level = 0; level < depth; level++) {
68
+ const values = columns.map(c => c.groups?.[level] ?? "");
69
+ for (const value of values)
70
+ cellText(value, policy);
71
+ for (let first = 0; first < columns.length;) {
72
+ let last = first;
73
+ const prefix = JSON.stringify(columns[first].groups?.slice(0, level + 1));
74
+ while (last + 1 < columns.length && values[first] && JSON.stringify(columns[last + 1].groups?.slice(0, level + 1)) === prefix)
75
+ last++;
76
+ if (last > first) {
77
+ merges.push(columnName(first + 1) + (level + 1 + titleRows) + ":" + columnName(last + 1) + (level + 1 + titleRows));
78
+ for (let i = first + 1; i <= last; i++)
79
+ values[i] = "";
80
+ }
81
+ first = last + 1;
82
+ }
83
+ headings.push(values);
84
+ }
85
+ if (columns.length)
86
+ headings.push(columns.map(c => c.header));
87
+ }
88
+ this.headerRows = titleRows + headings.length;
89
+ this.firstHeaderRow = columns.length && options.includeHeader !== false ? titleRows + 1 : 0;
90
+ if (options.mergedCells !== undefined && !Array.isArray(options.mergedCells))
91
+ throw new TypeError("Merged ranges must be an array.");
92
+ if (options.footer?.rows !== undefined && (options.footer.values !== undefined || options.footer.totals !== undefined))
93
+ throw new TypeError("Structured footer rows cannot accompany footer values or totals.");
94
+ this.structuredFooter = options.footer?.rows === undefined ? undefined : new StructuredRows(options.footer.rows, columns.length);
95
+ this.footerRows = this.structuredFooter?.values.length ?? (options.footer ? 1 : 0);
96
+ this.mergeCount = merges.length + (options.mergedCells?.length ?? 0) + (this.structuredFooter?.mergeCount ?? 0);
97
+ if (this.mergeCount > maximumMerges)
98
+ throw new OfficeIMOError("RESOURCE_LIMIT", "maxMergedRanges exceeded.");
99
+ this.regions = new MergeRegions([...merges, ...(options.mergedCells ?? [])], columns.length, maximumMerges);
100
+ if (options.table)
101
+ for (const ref of options.mergedCells ?? [])
102
+ if (Number(ref.split(":")[1].match(/\d+$/)[0]) >= this.headerRows)
103
+ throw new TypeError("Merged ranges cannot intersect a native table.");
104
+ this.headings = headings;
105
+ this.merges = this.regions.references;
106
+ const sizing = options.autoSize;
107
+ this.sampleRows = sizing ? sizing.sampleRows ?? Math.min(100, Math.floor(maximumSampleCells / Math.max(1, columns.length))) : 0;
108
+ if (!Number.isInteger(this.sampleRows) || this.sampleRows < 0 || this.sampleRows > 1048576)
109
+ throw new RangeError("Width sampling must use from 0 through 1,048,576 rows within its buffer budgets.");
110
+ const min = sizing?.minWidth ?? 8, max = sizing?.maxWidth ?? 60;
111
+ if (!Number.isFinite(min) || !Number.isFinite(max) || min < 0 || min > max || max > 255)
112
+ throw new RangeError("Width bounds must satisfy 0 <= minWidth <= maxWidth <= 255.");
113
+ this.widths = columns.map(c => c.width ?? (sizing ? Math.max(min, Math.min(max, c.header.length + 2)) : undefined));
114
+ if (options.footer?.values && options.footer.values.length > columns.length)
115
+ throw new RangeError("Footer has more values than declared columns.");
116
+ this.aggregates = createTotals(columns, options.footer?.totals);
117
+ if (options.print)
118
+ validatePrint(options.print, policy);
119
+ }
120
+ /** Resolve appended footer coordinates only after the streamed data row count is known. */
121
+ finalRegions(rows, maximumMerges) {
122
+ return this.structuredFooter ? new MergeRegions([...this.merges, ...this.structuredFooter.merges(this.headerRows + rows)], this.columns.length, maximumMerges) : this.regions;
123
+ }
124
+ sample(values) {
125
+ const min = this.options.autoSize?.minWidth ?? 8, max = this.options.autoSize?.maxWidth ?? 60;
126
+ values.forEach((value, i) => {
127
+ if (!this.columns[i] || this.columns[i].width !== undefined)
128
+ return;
129
+ const raw = value instanceof FormulaCell ? value.cachedValue : value instanceof ExportCell ? value.text ?? value.value : value instanceof Cell ? value.value : value;
130
+ const text = isDate(raw) ? Number.isFinite(raw.getTime()) ? raw.toISOString() : "" : raw == null ? "" : String(raw);
131
+ // Inspect at most a small prefix. A single long value cannot make a huge sampling allocation.
132
+ const length = Math.max(0, ...text.slice(0, Math.ceil(max * 4)).split(/\r?\n/).map(line => [...line].length));
133
+ this.widths[i] = Math.max(this.widths[i] ?? min, Math.min(max, length + 2));
134
+ });
135
+ }
136
+ accept(index, value) {
137
+ this.aggregates[index].accept(value);
138
+ }
139
+ footer(rows) {
140
+ return this.columns.map((_, i) => {
141
+ const total = this.aggregates[i], operation = total.operation;
142
+ if (!operation)
143
+ return this.options.footer?.values?.[i];
144
+ const value = total.value();
145
+ return new ComputedTotal(value, totalFormula(operation, columnName(i + 1), this.headerRows, rows), operation);
146
+ });
147
+ }
148
+ }
149
+ /** @internal Worksheet formulas and native table metadata must describe the same calculation. */
150
+ export function totalFormula(operation, letter, headerRows, rows) {
151
+ const code = { sum: 109, count: 102, average: 101, min: 105, max: 104 }[operation];
152
+ const guarded = ["average", "min", "max"].includes(operation);
153
+ const range = letter + (headerRows + 1) + ":" + letter + (headerRows + rows), subtotal = "SUBTOTAL(" + code + "," + range + ")";
154
+ return !rows ? guarded ? '""' : "0" : guarded ? 'IF(SUBTOTAL(102,' + range + ')=0,"",' + subtotal + ')' : subtotal;
155
+ }
156
+ function validatePrint(options, policy) {
157
+ if (options.paper !== undefined && !["A4", "Letter"].includes(options.paper))
158
+ throw new TypeError("Print paper must be A4 or Letter.");
159
+ if (options.orientation !== undefined && !["portrait", "landscape"].includes(options.orientation))
160
+ throw new TypeError("Invalid print orientation.");
161
+ for (const value of [options.fitToWidth, options.fitToHeight])
162
+ if (value !== undefined && (!Number.isInteger(value) || value < 0 || value > 32767))
163
+ throw new RangeError("Print fit dimensions must be integers from 0 through 32,767.");
164
+ for (const value of Object.values(options.margins ?? {}))
165
+ if (!Number.isFinite(value) || value < 0 || value > 10)
166
+ throw new RangeError("Print margins must be from 0 through 10 inches.");
167
+ for (const text of [options.header, options.footer])
168
+ if (text !== undefined) {
169
+ if (typeof text !== "string" || text.length > 250)
170
+ throw new TypeError("Print header/footer must be strings of at most 250 UTF-16 units.");
171
+ cellText(text, policy);
172
+ if (("&C" + text.replace(/&/g, "&&")).length > 255)
173
+ throw new RangeError("Encoded print header/footer exceeds Excel's 255-character limit.");
174
+ }
175
+ }
176
+ /** @internal XML follows the worksheet schema's pageMargins/pageSetup/headerFooter order. */
177
+ export function printXml(options, policy) {
178
+ if (!options)
179
+ return "";
180
+ const margins = { left: .25, right: .25, top: .5, bottom: .5, header: .2, footer: .2, ...options.margins };
181
+ return '<pageMargins' + Object.entries(margins).map(([key, value]) => ' ' + key + '="' + value + '"').join("") + '/>' +
182
+ '<pageSetup paperSize="' + (options.paper === "Letter" ? 1 : 9) + '" orientation="' + (options.orientation ?? "landscape") + '" fitToWidth="' + (options.fitToWidth ?? 1) + '" fitToHeight="' + (options.fitToHeight ?? 0) + '"/>' +
183
+ (options.header !== undefined || options.footer !== undefined ? '<headerFooter>' +
184
+ (options.header === undefined ? "" : '<oddHeader>' + escapeOoxmlAttribute("&C" + options.header.replace(/&/g, "&&"), policy) + '</oddHeader>') +
185
+ (options.footer === undefined ? "" : '<oddFooter>' + escapeOoxmlAttribute("&C" + options.footer.replace(/&/g, "&&"), policy) + '</oddFooter>') + '</headerFooter>' : "");
186
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,16 @@
1
+ import { captureFields } from "../internal/capture.js";
2
+ /** @internal The workbook owner captures these settings before validation or adapter merging. */
3
+ export const workbookOptionFields = ["signal", "onProgress", "limits", "sink", "dateMode", "compression", "invalidCharacterPolicy", "appProperties", "cellValueWriters", "oversizedText", "creator", "title", "subject", "description", "created", "modified"];
4
+ /** @internal Worksheet settings also used by the portable sheet owner. */
5
+ export const sheetOptionFields = ["columns", "includeHeader", "headerRows", "freezeHeader", "autoFilter", "boldHeader", "headerFill", "headerStyle", "alternatingRowStyle", "rowStyle", "cellStyle", "rowOutline", "maxOutlineLevel", "rowHeight", "headerHeight", "defaultColumnWidth", "freezeColumns", "table", "autoSize", "footer", "print", "title", "mergedCells", "hyperlinks", "conditionalFormats", "dataValidation"];
6
+ /** @internal Includes inherited format-specific ceilings before a wrapper combines stream settings. */
7
+ export const workbookLimitFields = ["maxRows", "maxCells", "maxTextCharacters", "maxOutputBytes", "maxStyles", "maxSheets", "maxOverflowCharacters", "maxHyperlinks", "maxImageBytes", "maxBufferedCells", "maxBufferedCharacters", "maxMergedRanges", "maxConditionalFormats", "maxDifferentialStyles", "maxCharts", "maxChartPoints", "maxChartTextCharacters", "maxFormulaCharacters", "maxDataValidations", "maxValidationTextCharacters"];
8
+ /** @internal Capture the workbook's known ceilings without dropping supported prototype fields. */
9
+ export function captureWorkbookLimits(limits) {
10
+ return captureFields(limits, workbookLimitFields);
11
+ }
12
+ /** @internal One immutable-input capture for direct workbooks and thin portable writers. */
13
+ export function captureWorkbookOptions(options) {
14
+ const captured = captureFields(options, workbookOptionFields);
15
+ return { ...captured, ...(captured.limits === undefined ? {} : { limits: captureWorkbookLimits(captured.limits) }) };
16
+ }
@@ -0,0 +1,27 @@
1
+ import type { ExportValue } from "../core/presentation.js";
2
+ import type { CellStyle, Font, Fill, Border } from "./styles.js";
3
+ import type { WorkbookOptions, SheetOptions, CellWriterContext, RowStyleContext, CellStyleContext, ReportTitle, FooterOptions } from "./types.js";
4
+ /** Style definitions that do not refer to a workbook's component indexes. */
5
+ export interface PortableCellStyle extends Omit<CellStyle, "font" | "fill" | "border" | "numberFormat"> {
6
+ readonly font?: Font;
7
+ readonly fill?: Fill;
8
+ readonly border?: Border;
9
+ readonly numberFormat?: string;
10
+ }
11
+ /** Settings for writers that own their workbook and accept resolved portable values. */
12
+ export interface PortableWorkbookOptions extends Omit<WorkbookOptions, "sink" | "cellValueWriters"> {
13
+ readonly cellValueWriters?: Readonly<Record<string, (value: import("../core/index.js").CellValue, context: CellWriterContext) => ExportValue>>;
14
+ }
15
+ /** Report layout and presentation without workbook-local style or Cell indexes. */
16
+ export interface PortableSheetOptions extends Omit<SheetOptions, "columns" | "headerStyle" | "alternatingRowStyle" | "rowStyle" | "cellStyle" | "title" | "footer"> {
17
+ readonly alternatingRowStyle?: PortableCellStyle;
18
+ readonly rowStyle?: (context: RowStyleContext) => PortableCellStyle | undefined;
19
+ readonly cellStyle?: (context: CellStyleContext) => PortableCellStyle | undefined;
20
+ readonly title?: Omit<ReportTitle, "style"> & {
21
+ readonly style?: PortableCellStyle;
22
+ };
23
+ readonly footer?: Omit<FooterOptions, "values" | "style"> & {
24
+ readonly values?: readonly ExportValue[];
25
+ readonly style?: PortableCellStyle;
26
+ };
27
+ }
@@ -0,0 +1,44 @@
1
+ import { ExportCell, assertScalar } from "../core/presentation.js";
2
+ import { captureWorkbookOptions, sheetOptionFields } from "./options.js";
3
+ import { captureFields } from "../internal/capture.js";
4
+ function style(patch) {
5
+ for (const component of ["font", "fill", "border", "numberFormat"])
6
+ if (typeof patch?.[component] === "number")
7
+ throw new TypeError("Workbook-local style indexes require the advanced Workbook API; use style definitions.");
8
+ return patch;
9
+ }
10
+ function value(result) {
11
+ if (!(result instanceof ExportCell))
12
+ assertScalar(result);
13
+ return result;
14
+ }
15
+ /** @internal Qualify the portable boundary before source/destination activity. */
16
+ export function portableSheet(options = {}) {
17
+ options = captureFields(options, sheetOptionFields);
18
+ if (options.headerStyle !== undefined)
19
+ throw new TypeError("Workbook-local header styles require the advanced Workbook API; use boldHeader and headerFill.");
20
+ style(options.alternatingRowStyle);
21
+ style(options.title?.style);
22
+ style(options.footer?.style);
23
+ options.footer?.values?.forEach(value);
24
+ const rowStyle = options.rowStyle, cellStyle = options.cellStyle;
25
+ for (const callback of [rowStyle, cellStyle])
26
+ if (callback !== undefined && typeof callback !== "function")
27
+ throw new TypeError("Style callbacks must be functions.");
28
+ return { ...options, ...(rowStyle ? { rowStyle: (context) => style(rowStyle(context)) } : {}),
29
+ ...(cellStyle ? { cellStyle: (context) => style(cellStyle(context)) } : {}) };
30
+ }
31
+ /** @internal Keep custom writers inside the same portable value contract. */
32
+ export function portableWorkbook(options = {}) {
33
+ options = captureWorkbookOptions(options);
34
+ const writers = options.cellValueWriters;
35
+ if (!writers)
36
+ return options;
37
+ const wrapped = Object.create(null);
38
+ for (const [type, writer] of Object.entries(writers)) {
39
+ if (typeof writer !== "function")
40
+ throw new TypeError("Cell value writers must be functions.");
41
+ wrapped[type] = (input, context) => value(writer(input, context));
42
+ }
43
+ return { ...options, cellValueWriters: wrapped };
44
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,60 @@
1
+ import { OfficeIMOError } from "../core/errors.js";
2
+ import { cleanXml } from "../xml/index.js";
3
+ /** @internal Overflow is deliberately bounded: ZIP worksheet entries cannot be interleaved. */
4
+ export class TextOverflow {
5
+ sheetName;
6
+ maximum;
7
+ policy;
8
+ reserve;
9
+ entries = [];
10
+ characters = 0;
11
+ rows = 0;
12
+ constructor(sheetName, maximum, policy, reserve) {
13
+ this.sheetName = sheetName;
14
+ this.maximum = maximum;
15
+ this.policy = policy;
16
+ this.reserve = reserve;
17
+ }
18
+ add(sheet, cell, value) {
19
+ const text = cleanXml(value, this.policy);
20
+ if (this.characters + text.length > this.maximum)
21
+ throw new OfficeIMOError("RESOURCE_LIMIT", "maxOverflowCharacters exceeded; use CSV or raise the bounded preservation limit.");
22
+ let parts = 0;
23
+ for (const _ of splitText(text)) {
24
+ void _;
25
+ parts++;
26
+ }
27
+ if (this.rows + parts > 1048575)
28
+ throw new OfficeIMOError("RESOURCE_LIMIT", "Text overflow exceeds the worksheet row limit.");
29
+ this.reserve(parts * 5, text.length + parts * (sheet.length + cell.length), this.rows + parts);
30
+ const first = this.rows + 2;
31
+ this.entries.push({ sheet, cell, text, first, parts });
32
+ this.rows += parts;
33
+ this.characters += text.length;
34
+ const marker = "\n[Full text: " + this.sheetName + "!D" + first + "; " + parts + " parts]";
35
+ return { preview: clipText(text, 32767 - marker.length) + marker, location: "'" + this.sheetName.replace(/'/g, "''") + "'!D" + first };
36
+ }
37
+ *values() {
38
+ for (const entry of this.entries) {
39
+ let part = 0;
40
+ for (const text of splitText(entry.text))
41
+ yield [entry.sheet, entry.cell, ++part, text, entry.parts];
42
+ }
43
+ }
44
+ clear() { this.entries = []; this.characters = 0; this.rows = 0; }
45
+ }
46
+ /** @internal Clip at a UTF-16 boundary without splitting a valid supplementary character. */
47
+ export function clipText(text, maximum) {
48
+ let end = Math.min(maximum, text.length);
49
+ if (end < text.length && /[\ud800-\udbff]/.test(text[end - 1] ?? ""))
50
+ end--;
51
+ return text.slice(0, end);
52
+ }
53
+ function* splitText(text) {
54
+ let offset = 0;
55
+ while (offset < text.length) {
56
+ const part = clipText(text.slice(offset, offset + 32768), 32767);
57
+ offset += part.length;
58
+ yield part;
59
+ }
60
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,24 @@
1
+ import { columnName } from "./values.js";
2
+ /** @internal Data-column selectors use stable keys or one-based worksheet columns. */
3
+ export function resolveDataColumn(columns, value, context = "Data") {
4
+ if (typeof value === "string") {
5
+ const matches = columns.flatMap((column, index) => column.key === value ? [index + 1] : []);
6
+ if (matches.length !== 1)
7
+ throw new TypeError(context + " column keys must identify exactly one declared column.");
8
+ return matches[0];
9
+ }
10
+ if (!Number.isInteger(value) || value < 1 || value > columns.length)
11
+ throw new RangeError(context + " column numbers must be one-based and within declared columns.");
12
+ return value;
13
+ }
14
+ /** @internal Formula references use literal final worksheet names and finite physical coordinates. */
15
+ export function qualifiedColumnRange(sheetName, column, firstRow, rows) {
16
+ if (!Number.isSafeInteger(firstRow) || firstRow < 1 || !Number.isSafeInteger(rows) || rows < 1 || firstRow + rows - 1 > 1048576)
17
+ throw new RangeError("A data range must fit within Excel's worksheet rows.");
18
+ const letter = columnName(column);
19
+ return "'" + sheetName.replace(/'/g, "''") + "'!$" + letter + "$" + firstRow + ":$" + letter + "$" + (firstRow + rows - 1);
20
+ }
21
+ /** @internal A series header is a single cell rather than a one-cell range. */
22
+ export function qualifiedCell(sheetName, column, row) {
23
+ return qualifiedColumnRange(sheetName, column, row, 1).split(":")[0];
24
+ }
@@ -0,0 +1 @@
1
+ export {};