@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,104 @@
1
+ import { NotSupportedError } from "../core/errors.js";
2
+ import { cleanXml, escapeXml } from "../xml/index.js";
3
+ const formulaCells = new WeakSet();
4
+ const nestedAggregateCells = new WeakSet();
5
+ /** Reject external references and identify nested total functions without evaluating Excel expressions. */
6
+ function inspectReferences(formula) {
7
+ let subtotal = false;
8
+ const identifier = /[\p{L}_\\][\p{L}\p{N}\p{M}_.\\]*/uy;
9
+ for (let i = 0; i < formula.length; i++) {
10
+ const character = formula[i];
11
+ if (character === '"') {
12
+ // Excel string literals double their embedded quotes. Their text is not a reference token.
13
+ while (++i < formula.length)
14
+ if (formula[i] === '"') {
15
+ if (formula[i + 1] !== '"')
16
+ break;
17
+ i++;
18
+ }
19
+ }
20
+ else if (character === "'") {
21
+ let quoted = "";
22
+ while (++i < formula.length) {
23
+ if (formula[i] === "'") {
24
+ if (formula[i + 1] !== "'")
25
+ break;
26
+ i++;
27
+ }
28
+ quoted += formula[i];
29
+ }
30
+ if (formula.slice(i + 1).trimStart().startsWith("!") && /[\[\]]/.test(quoted))
31
+ throw new NotSupportedError("external-workbook formulas");
32
+ }
33
+ else if (character === "[") {
34
+ let depth = 1;
35
+ while (++i < formula.length && depth) {
36
+ // Apostrophes escape special characters in table-column captions.
37
+ if (formula[i] === "'") {
38
+ i++;
39
+ continue;
40
+ }
41
+ if (formula[i] === "[")
42
+ depth++;
43
+ else if (formula[i] === "]")
44
+ depth--;
45
+ }
46
+ if (/^[A-Za-z0-9_.]*!/.test(formula.slice(i)))
47
+ throw new NotSupportedError("external-workbook formulas");
48
+ i--;
49
+ }
50
+ else if (character === "|")
51
+ throw new NotSupportedError("DDE formulas");
52
+ else {
53
+ identifier.lastIndex = i;
54
+ const token = identifier.exec(formula);
55
+ if (token) {
56
+ if (["SUBTOTAL", "AGGREGATE", "_XLFN.AGGREGATE"].includes(token[0].toUpperCase()) && /^\s*\(/.test(formula.slice(identifier.lastIndex)))
57
+ subtotal = true;
58
+ i = identifier.lastIndex - 1;
59
+ }
60
+ }
61
+ }
62
+ return subtotal;
63
+ }
64
+ function captureFormula(value) {
65
+ if (typeof value !== "string")
66
+ throw new TypeError("Formula text must be a string.");
67
+ const text = value.trim().replace(/^=/, "");
68
+ if (!text.trim() || text.length > 8192)
69
+ throw new RangeError("Formulas require 1 through 8,192 characters.");
70
+ // Text stripping could change a calculation, so formulas always reject invalid XML characters.
71
+ cleanXml(text, "reject");
72
+ return { text, subtotal: inspectReferences(text) };
73
+ }
74
+ /** An authored XLSX storage expression and its initial numeric or blank result. Future functions retain their required _xlfn prefixes; the writer does not evaluate or normalize function names. */
75
+ export class FormulaCell {
76
+ cachedValue;
77
+ style;
78
+ static [Symbol.hasInstance](value) {
79
+ return value !== null && typeof value === "object" && formulaCells.has(value);
80
+ }
81
+ formula;
82
+ constructor(formula, cachedValue, style) {
83
+ this.cachedValue = cachedValue;
84
+ this.style = style;
85
+ const captured = captureFormula(formula);
86
+ this.formula = captured.text;
87
+ if (cachedValue !== null && (typeof cachedValue !== "number" || !Number.isFinite(cachedValue)))
88
+ throw new TypeError("Formula caches must be finite numbers or null for a blank result.");
89
+ if (style !== undefined && (!Number.isSafeInteger(style) || style < 0))
90
+ throw new RangeError("Formula style indexes must be nonnegative safe integers.");
91
+ formulaCells.add(this);
92
+ if (captured.subtotal)
93
+ nestedAggregateCells.add(this);
94
+ Object.freeze(this);
95
+ }
96
+ }
97
+ /** @internal Excel excludes cells containing SUBTOTAL or AGGREGATE expressions from a generated SUBTOTAL. */
98
+ export function isSubtotalFormula(cell) { return nestedAggregateCells.has(cell); }
99
+ /** @internal The worksheet owns the cell coordinate, style and cumulative formula budget. */
100
+ export function formulaXml(cell) {
101
+ if (!(cell instanceof FormulaCell))
102
+ throw new TypeError("Formula cells must be created with FormulaCell.");
103
+ return "<f>" + escapeXml(cell.formula, "reject") + "</f><v>" + (cell.cachedValue ?? "") + "</v>";
104
+ }
@@ -0,0 +1,61 @@
1
+ import type { ColumnSettings } from "../core/index.js";
2
+ import type { GroupedReportEvent, GroupedReportGroup, GroupedReportSummary } from "../core/grouped-report.js";
3
+ import type { PortableCellStyle, PortableSheetOptions } from "./portable.js";
4
+ import type { ConditionalFormat } from "./conditional-types.js";
5
+ import type { ListValidation } from "./validation-types.js";
6
+ import type { Worksheet } from "./worksheet.js";
7
+ import type { DataRowRange } from "./data-row-ranges.js";
8
+ type GroupEnd = Extract<GroupedReportEvent, {
9
+ readonly kind: "groupEnd";
10
+ }>;
11
+ type Complete = Extract<GroupedReportEvent, {
12
+ readonly kind: "complete";
13
+ }>;
14
+ type GroupedSheet = Omit<PortableSheetOptions, "columns" | "headerRows" | "footer" | "table" | "autoFilter" | "mergedCells" | "hyperlinks" | "conditionalFormats" | "dataValidation" | "rowStyle" | "cellStyle" | "rowOutline" | "maxOutlineLevel">;
15
+ /** Layout for one grouped analysis worksheet in a caller-owned workbook. */
16
+ export interface GroupedXlsxSheetOptions {
17
+ /** A separate label column preserves every visible typed data column. */
18
+ readonly labelColumn: Pick<ColumnSettings, "header" | "width" | "wrapText" | "alignment">;
19
+ readonly subtotalLabel: (group: GroupEnd) => string;
20
+ readonly grandTotalLabel: (summary: Complete) => string;
21
+ readonly includeGrandTotal?: boolean;
22
+ /** Hidden outline details remain included in the native SUBTOTAL calculations. */
23
+ readonly collapseGroups?: boolean;
24
+ readonly sheet?: GroupedSheet & {
25
+ readonly name?: string;
26
+ };
27
+ readonly groupStyle?: PortableCellStyle;
28
+ readonly subtotalStyle?: PortableCellStyle;
29
+ readonly grandTotalStyle?: PortableCellStyle;
30
+ /** Data-only ranges use stable data-column keys or one-based visible data-column numbers. A1 ranges and the generated label column are excluded. */
31
+ readonly conditionalFormats?: readonly ConditionalFormat[];
32
+ /** Inline editing lists apply only to detail rows, using the same data-column selectors. */
33
+ readonly dataValidation?: readonly ListValidation[];
34
+ }
35
+ /** Stable one-based physical coordinates for one generated group and its body. */
36
+ export interface GroupedXlsxGroupRows extends GroupedReportGroup {
37
+ readonly path: readonly GroupedReportGroup[];
38
+ readonly rows: number;
39
+ /** The shared source's column-order aggregates, without reaggregating worksheet cells. */
40
+ readonly totals: readonly (number | null)[];
41
+ readonly startRow: number;
42
+ readonly firstDetailRow: number;
43
+ readonly lastDetailRow: number;
44
+ readonly summaryRow: number;
45
+ }
46
+ /** A completed analysis worksheet; the owning workbook remains open for sibling sheets and finalization. */
47
+ export interface GroupedXlsxWorksheet {
48
+ readonly worksheet: Worksheet;
49
+ /** Accepted source details, excluding generated headings and summaries. */
50
+ readonly rows: number;
51
+ /** Includes the generated label column. */
52
+ readonly columns: number;
53
+ /** Ordered physical detail runs, excluding all generated headings and summaries. Their count is bounded by the source's maxGroups. */
54
+ readonly detailRanges: readonly DataRowRange[];
55
+ /** Opening order, bounded by the source's maxGroups across all hierarchy levels. */
56
+ readonly groups: readonly GroupedXlsxGroupRows[];
57
+ /** The same one-pass source's complete aggregates, including when the grand-total row is omitted. */
58
+ readonly grandSummary: GroupedReportSummary;
59
+ readonly grandTotalRow?: number;
60
+ }
61
+ export {};
@@ -0,0 +1,79 @@
1
+ import { assertGroupedReportSource } from "../core/grouped-report.js";
2
+ import { captureFields } from "../internal/capture.js";
3
+ import { OfficeIMOError } from "../core/errors.js";
4
+ import { fields } from "./differential-styles.js";
5
+ import { sheetOptionFields } from "./options.js";
6
+ import { portableSheet } from "./portable.js";
7
+ import { resolveDataColumn } from "./ranges.js";
8
+ import { copyStylePatch } from "./styles.js";
9
+ /** @internal */
10
+ export const groupedOptionFields = ["labelColumn", "subtotalLabel", "grandTotalLabel", "includeGrandTotal", "collapseGroups", "sheet", "groupStyle", "subtotalStyle", "grandTotalStyle", "conditionalFormats", "dataValidation"];
11
+ const unsupported = ["columns", "headerRows", "footer", "table", "mergedCells", "hyperlinks", "conditionalFormats", "dataValidation", "rowStyle", "cellStyle", "rowOutline", "maxOutlineLevel"];
12
+ function detailColumn(report, selector) {
13
+ return resolveDataColumn(report.columns, selector, "Grouped detail") + 1;
14
+ }
15
+ function conditionalRules(report, rules, maximum) {
16
+ if (rules === undefined)
17
+ return undefined;
18
+ if (!Array.isArray(rules))
19
+ throw new TypeError("conditionalFormats must be an array.");
20
+ if (rules.length > maximum)
21
+ throw new OfficeIMOError("RESOURCE_LIMIT", "maxConditionalFormats exceeded.");
22
+ return rules.map(input => {
23
+ const rule = captureFields(input, ["type", "range", "style", "stopIfTrue", "operator", "value", "values", "formula", "stops", "color", "minimum", "maximum", "showValue"]);
24
+ const inputRange = rule.range;
25
+ if (typeof inputRange === "string")
26
+ throw new TypeError("Grouped conditional formats require detail-column selectors rather than A1 or generated-row ranges.");
27
+ fields(inputRange, ["column", "through"], "grouped conditional range");
28
+ const range = captureFields(inputRange, ["column", "through"]);
29
+ return { ...rule, range: { column: detailColumn(report, range.column), ...(range.through === undefined ? {} : { through: detailColumn(report, range.through) }) } };
30
+ });
31
+ }
32
+ function validationRules(report, rules, maximum) {
33
+ if (rules === undefined)
34
+ return undefined;
35
+ if (!Array.isArray(rules))
36
+ throw new TypeError("dataValidation must be an array.");
37
+ if (rules.length > maximum)
38
+ throw new OfficeIMOError("RESOURCE_LIMIT", "maxDataValidations exceeded.");
39
+ return rules.map(input => {
40
+ const rule = captureFields(input, ["type", "column", "items", "allowBlank", "showErrorMessage", "errorStyle", "errorTitle", "errorMessage"]);
41
+ return { ...rule, column: detailColumn(report, rule.column) };
42
+ });
43
+ }
44
+ /** @internal Capture options before creating a worksheet or touching a one-pass source. */
45
+ export function prepareGroupedSheet(report, configuration, maxConditionalFormats = 1000, maxDataValidations = 1000) {
46
+ assertGroupedReportSource(report);
47
+ if (!configuration || typeof configuration !== "object")
48
+ throw new TypeError("Grouped XLSX options require host-authored labels.");
49
+ const options = captureFields(configuration, groupedOptionFields);
50
+ const sheet = captureFields(options.sheet ?? {}, [...sheetOptionFields, "name"]);
51
+ if (!options.labelColumn || typeof options.labelColumn !== "object")
52
+ throw new TypeError("Grouped XLSX needs a leading label column.");
53
+ const labelColumn = captureFields(options.labelColumn, ["header", "width", "wrapText", "alignment"]);
54
+ if (typeof labelColumn.header !== "string")
55
+ throw new TypeError("The leading label column needs a string header.");
56
+ for (const label of [options.subtotalLabel, options.grandTotalLabel])
57
+ if (typeof label !== "function")
58
+ throw new TypeError("Grouped summary labels must be functions.");
59
+ for (const flag of [options.includeGrandTotal, options.collapseGroups])
60
+ if (flag !== undefined && typeof flag !== "boolean")
61
+ throw new TypeError("Grouped XLSX flags must be booleans.");
62
+ for (const key of unsupported)
63
+ if (sheet[key] !== undefined)
64
+ throw new TypeError("Grouped XLSX owns worksheet " + key + ".");
65
+ if (sheet.autoFilter !== undefined && sheet.autoFilter !== false)
66
+ throw new TypeError("Grouped summary rows cannot use a native table or autofilter.");
67
+ for (const style of [options.groupStyle, options.subtotalStyle, options.grandTotalStyle])
68
+ if (style !== undefined)
69
+ portableSheet({ alternatingRowStyle: style });
70
+ for (const column of report.columns)
71
+ if (Object.prototype.hasOwnProperty.call(report.totals, column.key) && column.type !== "number")
72
+ throw new TypeError("Editable grouped totals require explicitly numeric columns.");
73
+ const conditionalFormats = conditionalRules(report, options.conditionalFormats, maxConditionalFormats), dataValidation = validationRules(report, options.dataValidation, maxDataValidations);
74
+ return { ...options, labelColumn, sheet: portableSheet(sheet),
75
+ ...(conditionalFormats === undefined ? {} : { conditionalFormats }), ...(dataValidation === undefined ? {} : { dataValidation }),
76
+ ...(options.groupStyle ? { groupStyle: copyStylePatch(options.groupStyle) } : {}),
77
+ ...(options.subtotalStyle ? { subtotalStyle: copyStylePatch(options.subtotalStyle) } : {}),
78
+ ...(options.grandTotalStyle ? { grandTotalStyle: copyStylePatch(options.grandTotalStyle) } : {}) };
79
+ }
@@ -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 {};