@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 @@
1
+ export {};
@@ -0,0 +1,16 @@
1
+ /** @internal Recognize native Date values across iframe realms without trusting a string tag. */
2
+ export function isDate(value) {
3
+ if (value === null || typeof value !== "object")
4
+ return false;
5
+ try {
6
+ // Ordinary rows take the cheap negative path. A custom string tag can be an
7
+ // accessor: use the native brand check directly without reading that tag.
8
+ if (!(value instanceof Date) && !(Symbol.toStringTag in value) && Object.prototype.toString.call(value) !== "[object Date]")
9
+ return false;
10
+ Date.prototype.getTime.call(value);
11
+ return true;
12
+ }
13
+ catch {
14
+ return false;
15
+ }
16
+ }
@@ -0,0 +1,12 @@
1
+ /** Stable machine-readable failures for document and package operations. */
2
+ export type ErrorCode = "NOT_SUPPORTED" | "INVALID_XML" | "INVALID_PART_URI" | "INVALID_STATE" | "ZIP64_REQUIRED" | "PLATFORM_UNAVAILABLE" | "RESOURCE_LIMIT";
3
+ export declare class OfficeIMOError extends Error {
4
+ readonly code: ErrorCode;
5
+ static [Symbol.hasInstance](value: unknown): boolean;
6
+ constructor(code: ErrorCode, message: string, options?: ErrorOptions);
7
+ }
8
+ export declare class NotSupportedError extends OfficeIMOError {
9
+ readonly feature: string;
10
+ static [Symbol.hasInstance](value: unknown): boolean;
11
+ constructor(feature: string);
12
+ }
@@ -0,0 +1,31 @@
1
+ const errorBrand = Symbol.for("@evotecit/officeimo/OfficeIMOError");
2
+ const unsupportedBrand = Symbol.for("@evotecit/officeimo/NotSupportedError");
3
+ export class OfficeIMOError extends Error {
4
+ code;
5
+ static [Symbol.hasInstance](value) {
6
+ // Inherited checks on user subclasses must retain their own prototype identity.
7
+ if (this !== OfficeIMOError)
8
+ return Function.prototype[Symbol.hasInstance].call(this, value);
9
+ return !!value && typeof value === "object" && value[errorBrand] === true;
10
+ }
11
+ constructor(code, message, options) {
12
+ super(message, options);
13
+ this.code = code;
14
+ Object.defineProperty(this, errorBrand, { value: true });
15
+ this.name = "OfficeIMOError";
16
+ }
17
+ }
18
+ export class NotSupportedError extends OfficeIMOError {
19
+ feature;
20
+ static [Symbol.hasInstance](value) {
21
+ if (this !== NotSupportedError)
22
+ return Function.prototype[Symbol.hasInstance].call(this, value);
23
+ return !!value && typeof value === "object" && value[unsupportedBrand] === true;
24
+ }
25
+ constructor(feature) {
26
+ super("NOT_SUPPORTED", feature + " is not supported yet.");
27
+ this.feature = feature;
28
+ Object.defineProperty(this, unsupportedBrand, { value: true });
29
+ this.name = "NotSupportedError";
30
+ }
31
+ }
@@ -0,0 +1,87 @@
1
+ import type { CellValue, Column, ExportLimits } from "./index.js";
2
+ import type { ExportValue } from "./presentation.js";
3
+ import type { TotalOperation } from "../internal/totals.js";
4
+ export type { TotalOperation } from "../internal/totals.js";
5
+ /** Source-row position and stable grouping field, independent of visible export columns. */
6
+ export interface GroupedReportValueContext {
7
+ readonly rowIndex: number;
8
+ /** Zero-based grouping depth. */
9
+ readonly level: number;
10
+ readonly key: string;
11
+ }
12
+ /** One grouping level. Declared column keys reuse their projected value; hidden fields need a getter. */
13
+ export interface GroupedReportLevel<T = never> {
14
+ readonly key: string;
15
+ readonly value?: (row: T, context: GroupedReportValueContext) => CellValue;
16
+ /** Synchronous display text; defaults to scalar text, an ISO UTC date, or empty text for null.
17
+ * Identity always uses the typed value. */
18
+ readonly label?: (value: CellValue) => string;
19
+ }
20
+ /** A bounded, one-pass hierarchy of rows already ordered into contiguous groups.
21
+ * Every column needs a unique stable key; translated headings never select data or totals. */
22
+ export interface GroupedReportOptions<T = never> {
23
+ readonly columns: readonly Column<T>[];
24
+ /** One to four levels, outermost first. Hidden grouping fields never become output columns. */
25
+ readonly groupBy: string | readonly (string | GroupedReportLevel<T>)[];
26
+ /** Numeric metrics must declare type:"number" and resolve to finite numbers or null. Count ignores null cells. */
27
+ readonly totals?: Readonly<Record<string, TotalOperation>>;
28
+ /** Single-level shorthand. For a hierarchy, set each descriptor's label instead. */
29
+ readonly groupLabel?: (value: CellValue) => string;
30
+ /** Maximum opened groups across all depths, retained for recurrence detection. Defaults to 1,000. */
31
+ readonly maxGroups?: number;
32
+ /** Cumulative UTF-16 characters in retained group identifiers and captured labels. Defaults to 1,000,000. */
33
+ readonly maxGroupKeyCharacters?: number;
34
+ readonly signal?: AbortSignal;
35
+ /** Source row, cell and text ceilings. Byte-output limits belong to the selected format writer. */
36
+ readonly limits?: Pick<ExportLimits, "maxRows" | "maxCells" | "maxTextCharacters">;
37
+ }
38
+ export interface GroupedReportSummary {
39
+ /** All accepted body rows, including rows with null or nonnumeric values. */
40
+ readonly rows: number;
41
+ /** All opened groups across every hierarchy level. */
42
+ readonly groups: number;
43
+ /** Column-order totals. Columns without an operation have null totals. */
44
+ readonly totals: readonly (number | null)[];
45
+ }
46
+ /** A typed group within its parent. Labels are presentation and never select data or totals. */
47
+ export interface GroupedReportGroup {
48
+ readonly groupIndex: number;
49
+ readonly key: CellValue;
50
+ readonly label: string;
51
+ /** Zero-based grouping depth. */
52
+ readonly level: number;
53
+ }
54
+ /** Shared events consumed by grouped XLSX and PDF writers, without buffering a group's body. */
55
+ export type GroupedReportEvent = ({
56
+ readonly kind: "groupStart";
57
+ readonly path: readonly GroupedReportGroup[];
58
+ } & GroupedReportGroup) | {
59
+ readonly kind: "row";
60
+ readonly values: readonly ExportValue[];
61
+ readonly rowIndex: number;
62
+ readonly groupIndex: number;
63
+ readonly path: readonly GroupedReportGroup[];
64
+ } | ({
65
+ readonly kind: "groupEnd";
66
+ readonly rows: number;
67
+ readonly totals: readonly (number | null)[];
68
+ readonly path: readonly GroupedReportGroup[];
69
+ } & GroupedReportGroup) | ({
70
+ readonly kind: "complete";
71
+ } & GroupedReportSummary);
72
+ declare const groupedReportSource: unique symbol;
73
+ export interface GroupedReportSource {
74
+ /** Factory-owned source. Call createGroupedReport rather than implementing its event protocol. */
75
+ readonly [groupedReportSource]: true;
76
+ /** Captured portable metadata in export order. Values have already been projected into positional rows. */
77
+ readonly columns: readonly Column<readonly ExportValue[]>[];
78
+ /** Captured stable grouping keys, outermost first. */
79
+ readonly groupBy: readonly string[];
80
+ readonly totals: Readonly<Record<string, TotalOperation>>;
81
+ /** Consume exactly once. Disposing or failing a writer returns the original row iterator. */
82
+ readonly events: AsyncIterable<GroupedReportEvent>;
83
+ }
84
+ /** Group a preordered row source once. Closed-group recurrence within the same parent rejects.
85
+ * Equality is locale independent: strings are exact, numbers and booleans retain their types, dates compare
86
+ * by UTC instant, and null/undefined share one group. No sorting or complete group-body retention occurs. */
87
+ export declare function createGroupedReport<T>(rows: Iterable<T> | AsyncIterable<T>, options: GroupedReportOptions<T>): GroupedReportSource;
@@ -0,0 +1,252 @@
1
+ import { ExportCell, assertScalar } from "./presentation.js";
2
+ import { isDate } from "./dates.js";
3
+ import { checkAbort, inputRows, pause, taskYieldDue } from "./iteration.js";
4
+ import { ExportBudget } from "./limits.js";
5
+ import { OfficeIMOError } from "./errors.js";
6
+ import { copyColumns, createRowProjector } from "../internal/rows.js";
7
+ import { createTotals } from "../internal/totals.js";
8
+ import { copyExportValue } from "../internal/export-values.js";
9
+ const sources = new WeakMap();
10
+ /** @internal Writers accept the owned immutable event source rather than trusting caller-authored event protocols. */
11
+ export function assertGroupedReportSource(value) {
12
+ if (!value || typeof value !== "object" || !sources.has(value))
13
+ throw new TypeError("Create grouped report sources with createGroupedReport.");
14
+ }
15
+ /** @internal The consuming writer's signal reaches pending source reads as well as destination writes. */
16
+ export function groupedReportEvents(source, signal) {
17
+ assertGroupedReportSource(source);
18
+ return { async *[Symbol.asyncIterator]() {
19
+ const operation = groupedReportOperation(source, signal);
20
+ try {
21
+ yield* operation.events;
22
+ }
23
+ finally {
24
+ operation.dispose();
25
+ }
26
+ } };
27
+ }
28
+ /** @internal Share cancellation between original source reads and destination writes; callers dispose in finally. */
29
+ export function groupedReportOperation(source, signal) {
30
+ assertGroupedReportSource(source);
31
+ const factory = sources.get(source), linked = linkedSignals(factory.signal, signal);
32
+ return { signal: linked.signal, events: factory.events(linked.signal), dispose: linked.dispose };
33
+ }
34
+ function linkedSignals(source, consumer) {
35
+ if (!source || !consumer || source === consumer)
36
+ return { signal: source ?? consumer, dispose() { } };
37
+ const controller = new AbortController(), abortSource = () => controller.abort(source.reason), abortConsumer = () => controller.abort(consumer.reason);
38
+ source.addEventListener("abort", abortSource, { once: true });
39
+ consumer.addEventListener("abort", abortConsumer, { once: true });
40
+ if (source.aborted)
41
+ abortSource();
42
+ else if (consumer.aborted)
43
+ abortConsumer();
44
+ return { signal: controller.signal, dispose() { source.removeEventListener("abort", abortSource); consumer.removeEventListener("abort", abortConsumer); } };
45
+ }
46
+ function maximum(value, fallback, name) {
47
+ const result = value ?? fallback;
48
+ if (!Number.isSafeInteger(result) || result < 0)
49
+ throw new RangeError(name + " must be a nonnegative safe integer.");
50
+ return result;
51
+ }
52
+ function scalar(value) { return value instanceof ExportCell ? value.value : value; }
53
+ function identity(value) {
54
+ if (value == null)
55
+ return { key: null, id: "null", text: "" };
56
+ if (isDate(value)) {
57
+ const time = Date.prototype.getTime.call(value);
58
+ if (!Number.isFinite(time))
59
+ throw new TypeError("A group key date must be valid.");
60
+ return { key: new Date(time), id: "date:" + time, text: new Date(time).toISOString() };
61
+ }
62
+ if (typeof value === "number" && !Number.isFinite(value))
63
+ throw new TypeError("A numeric group key must be finite.");
64
+ const text = String(value);
65
+ return { key: value, id: typeof value + ":" + text, text };
66
+ }
67
+ function eventKey(value) { return isDate(value) ? new Date(Date.prototype.getTime.call(value)) : value; }
68
+ function result(aggregates) {
69
+ return Object.freeze(aggregates.map(aggregate => aggregate.operation === undefined ? null : aggregate.value()));
70
+ }
71
+ function groupingLevels(input, keys, groupLabel) {
72
+ const selected = typeof input === "string" ? [input] : Array.isArray(input) ? Array.from(input) : undefined;
73
+ if (!selected || selected.length < 1 || selected.length > 4)
74
+ throw new TypeError("groupBy must declare between one and four grouping levels.");
75
+ if (groupLabel !== undefined && typeof groupLabel !== "function")
76
+ throw new TypeError("groupLabel must be a synchronous function.");
77
+ if (groupLabel && selected.length !== 1)
78
+ throw new TypeError("groupLabel is only available for one grouping level; use descriptor labels for a hierarchy.");
79
+ const seen = new Set();
80
+ return Object.freeze(selected.map(level => {
81
+ if (typeof level !== "string" && (!level || typeof level !== "object" || Array.isArray(level)))
82
+ throw new TypeError("A grouping level must name a stable column key or provide a descriptor.");
83
+ // Supported structural fields, including prototype accessors, are captured once.
84
+ const { key, value, label } = typeof level === "string" ? { key: level, value: undefined, label: undefined } : level;
85
+ if (typeof key !== "string" || !key.length || seen.has(key))
86
+ throw new TypeError("Grouping levels need unique, nonempty stable keys.");
87
+ seen.add(key);
88
+ if (value !== undefined && typeof value !== "function")
89
+ throw new TypeError("Grouping value getters must be synchronous functions.");
90
+ if (label !== undefined && typeof label !== "function")
91
+ throw new TypeError("Grouping labels must be synchronous functions.");
92
+ if (label && groupLabel)
93
+ throw new TypeError("Specify either groupLabel or the grouping descriptor label.");
94
+ const column = keys.indexOf(key);
95
+ if (column >= 0 && value !== undefined)
96
+ throw new TypeError("A declared grouping column reuses its projected value; do not provide another value getter.");
97
+ if (column < 0 && value === undefined)
98
+ throw new TypeError("groupBy must name a declared stable column key; hidden grouping fields need an explicit value getter.");
99
+ return Object.freeze({ key, column, value, label: label ?? groupLabel });
100
+ }));
101
+ }
102
+ /** Copy date keys on every event so a consumer cannot mutate later hierarchy decisions. */
103
+ function groupPath(active) {
104
+ return Object.freeze(active.map(({ group }) => Object.freeze({ ...group, key: eventKey(group.key) })));
105
+ }
106
+ function labelText(format, key, fallback) {
107
+ if (!format)
108
+ return fallback;
109
+ const formatted = format(eventKey(key));
110
+ if (typeof formatted?.then === "function")
111
+ void Promise.resolve(formatted).catch(() => { });
112
+ if (typeof formatted !== "string")
113
+ throw new TypeError("Grouping labels must return synchronous text.");
114
+ return formatted;
115
+ }
116
+ /** Group a preordered row source once. Closed-group recurrence within the same parent rejects.
117
+ * Equality is locale independent: strings are exact, numbers and booleans retain their types, dates compare
118
+ * by UTC instant, and null/undefined share one group. No sorting or complete group-body retention occurs. */
119
+ export function createGroupedReport(rows, options) {
120
+ if (!options || typeof options !== "object")
121
+ throw new TypeError("Grouped report options are required.");
122
+ // Capture configuration before validation so accessors cannot select different columns in later stages.
123
+ const { columns: selected, groupBy, totals: selectedTotals, groupLabel, maxGroups: requestedGroups, maxGroupKeyCharacters: requestedCharacters, signal: sourceSignal, limits } = options;
124
+ if (limits !== undefined && (!limits || typeof limits !== "object" || Array.isArray(limits)))
125
+ throw new TypeError("Grouped source limits must be an object.");
126
+ if (limits !== undefined && "maxOutputBytes" in limits)
127
+ throw new TypeError("Set maxOutputBytes on the format writer, not the grouped source.");
128
+ if (!Array.isArray(selected) || !selected.length)
129
+ throw new TypeError("A grouped report needs declared columns.");
130
+ const columns = copyColumns(selected);
131
+ const keys = columns.map(column => column.key);
132
+ if (keys.some(key => typeof key !== "string" || key.length === 0) || new Set(keys).size !== keys.length)
133
+ throw new TypeError("Grouped report columns need unique, nonempty stable keys.");
134
+ const levels = groupingLevels(groupBy, keys, groupLabel);
135
+ const totals = Object.freeze({ ...selectedTotals });
136
+ const grand = createTotals(columns, totals);
137
+ for (let column = 0; column < columns.length; column++)
138
+ if (grand[column].operation !== undefined && columns[column].type !== "number")
139
+ throw new TypeError("Grouped numeric totals require a column declared with type:number.");
140
+ const maxGroups = maximum(requestedGroups, 1000, "maxGroups");
141
+ const maxCharacters = maximum(requestedCharacters, 1000000, "maxGroupKeyCharacters");
142
+ const budget = new ExportBudget(limits);
143
+ const portable = Object.freeze(columns.map(column => {
144
+ const { value: _getter, ...metadata } = column;
145
+ return Object.freeze(metadata);
146
+ }));
147
+ for (const column of columns) {
148
+ budget.cell(column.header);
149
+ for (const group of column.groups ?? [])
150
+ budget.reserve(0, group.length);
151
+ Object.freeze(column);
152
+ }
153
+ let consumed = false;
154
+ const eventsFor = (signal) => Object.freeze({ [Symbol.asyncIterator]() {
155
+ if (consumed)
156
+ throw new TypeError("A grouped report source can be consumed only once.");
157
+ consumed = true;
158
+ return iterate(signal);
159
+ } });
160
+ const events = eventsFor(sourceSignal);
161
+ async function* iterate(signal) {
162
+ const project = createRowProjector(columns, undefined, signal);
163
+ const seen = new Set(), active = [];
164
+ let characters = 0, rowCount = 0, groups = 0;
165
+ for await (const input of inputRows(rows, signal)) {
166
+ // Copy positional input once before the shared projector validates and inspects its values.
167
+ const snapshot = Array.isArray(input) ? Array.from(input) : input;
168
+ const projected = project(snapshot, rowCount), values = [];
169
+ for (let column = 0; column < columns.length; column++)
170
+ values.push(copyExportValue(projected[column]) ?? null);
171
+ checkAbort(signal);
172
+ const next = levels.map((level, index) => {
173
+ checkAbort(signal);
174
+ const value = level.column >= 0 ? scalar(values[level.column]) : level.value(snapshot, Object.freeze({ rowIndex: rowCount, level: index, key: level.key }));
175
+ assertScalar(value);
176
+ checkAbort(signal);
177
+ return identity(value);
178
+ });
179
+ budget.row(rowCount + 1);
180
+ for (let column = 0; column < values.length; column++) {
181
+ const value = values[column], raw = scalar(value);
182
+ if (grand[column].operation !== undefined && raw != null && (typeof raw !== "number" || !Number.isFinite(raw)))
183
+ throw new TypeError("Grouped numeric metrics must resolve to finite numbers or null.");
184
+ budget.cell(raw);
185
+ if (value instanceof ExportCell && value.text !== undefined)
186
+ budget.reserve(0, value.text.length);
187
+ }
188
+ let common = 0;
189
+ while (common < active.length && active[common].id === next[common].id)
190
+ common++;
191
+ const pending = [];
192
+ for (let level = common; level < levels.length; level++) {
193
+ const value = next[level], parent = pending.at(-1) ?? active[level - 1];
194
+ // Parent indexes are generated integers, so scalar strings containing delimiters cannot collide.
195
+ const scopedId = (parent?.group.groupIndex ?? -1) + ":" + value.id;
196
+ if (seen.has(scopedId))
197
+ throw new TypeError("Grouped rows must be contiguous; a closed group key occurred again within the same parent.");
198
+ if (groups === maxGroups)
199
+ throw new OfficeIMOError("RESOURCE_LIMIT", "maxGroups exceeded.");
200
+ const label = labelText(levels[level].label, value.key, value.text);
201
+ checkAbort(signal);
202
+ const nextCharacters = characters + scopedId.length + label.length;
203
+ if (!Number.isSafeInteger(nextCharacters) || nextCharacters > maxCharacters)
204
+ throw new OfficeIMOError("RESOURCE_LIMIT", "maxGroupKeyCharacters exceeded.");
205
+ budget.reserve(0, label.length);
206
+ pending.push({ id: value.id, group: Object.freeze({ groupIndex: groups, key: value.key, label, level }),
207
+ rows: 0, aggregates: createTotals(columns, totals) });
208
+ characters = nextCharacters;
209
+ seen.add(scopedId);
210
+ groups++;
211
+ }
212
+ while (active.length > common) {
213
+ checkAbort(signal);
214
+ const path = groupPath(active), ending = active.pop();
215
+ yield Object.freeze({ kind: "groupEnd", ...path.at(-1), path, rows: ending.rows, totals: result(ending.aggregates) });
216
+ }
217
+ for (const opening of pending) {
218
+ checkAbort(signal);
219
+ active.push(opening);
220
+ const path = groupPath(active);
221
+ yield Object.freeze({ kind: "groupStart", ...path.at(-1), path });
222
+ }
223
+ for (let column = 0; column < values.length; column++) {
224
+ const raw = scalar(values[column]);
225
+ for (const group of active)
226
+ group.aggregates[column].accept(raw);
227
+ grand[column].accept(raw);
228
+ }
229
+ for (const group of active)
230
+ group.rows++;
231
+ checkAbort(signal);
232
+ yield Object.freeze({ kind: "row", values: Object.freeze(values), rowIndex: rowCount,
233
+ groupIndex: active.at(-1).group.groupIndex, path: groupPath(active) });
234
+ rowCount++;
235
+ if (taskYieldDue()) {
236
+ await pause();
237
+ checkAbort(signal);
238
+ }
239
+ }
240
+ checkAbort(signal);
241
+ while (active.length) {
242
+ checkAbort(signal);
243
+ const path = groupPath(active), ending = active.pop();
244
+ yield Object.freeze({ kind: "groupEnd", ...path.at(-1), path, rows: ending.rows, totals: result(ending.aggregates) });
245
+ }
246
+ checkAbort(signal);
247
+ yield Object.freeze({ kind: "complete", rows: rowCount, groups, totals: result(grand) });
248
+ }
249
+ const source = Object.freeze({ columns: portable, groupBy: Object.freeze(levels.map(level => level.key)), totals, events });
250
+ sources.set(source, { signal: sourceSignal, events: eventsFor });
251
+ return source;
252
+ }
@@ -0,0 +1,74 @@
1
+ export { OfficeIMOError, NotSupportedError } from "./errors.js";
2
+ export type { ErrorCode } from "./errors.js";
3
+ export { BlobByteSink, ChunkedTextSink, writeBytes } from "./sinks.js";
4
+ export type { ByteSink, ByteSource, ByteWriter, OutputDestination } from "./sinks.js";
5
+ export type { ExportLimits } from "./limits.js";
6
+ export { ExportCell } from "./presentation.js";
7
+ export type { CellPresentation, ExportCellOptions, ExportValue } from "./presentation.js";
8
+ export type { ExportLink } from "./links.js";
9
+ export type { TableSpanCell, TableSpanRows } from "./table.js";
10
+ export type { BooleanText } from "./value-text.js";
11
+ export { createGroupedReport } from "./grouped-report.js";
12
+ export type { GroupedReportSource, GroupedReportEvent, GroupedReportOptions, GroupedReportSummary, GroupedReportValueContext, GroupedReportLevel, GroupedReportGroup } from "./grouped-report.js";
13
+ export { checkAbort, withAbort, inputRows, pause } from "./iteration.js";
14
+ /** Plain values never interpret strings as formulas. */
15
+ export type CellValue = string | number | boolean | Date | null | undefined;
16
+ export type Row = readonly import("./presentation.js").ExportValue[] | Readonly<Record<string, import("./presentation.js").ExportValue>>;
17
+ export type Rows = Iterable<Row> | AsyncIterable<Row>;
18
+ export type Alignment = "left" | "center" | "right" | "fill" | "justify" | "distributed";
19
+ /** Metadata shared by tabular writers. Format modules interpret their own presentation options. */
20
+ export interface ColumnSettings {
21
+ readonly header: string;
22
+ readonly width?: number;
23
+ readonly type?: "string" | "number" | "boolean" | "date" | (string & {});
24
+ readonly format?: string;
25
+ readonly wrapText?: boolean;
26
+ readonly alignment?: Alignment;
27
+ /** Explicitly identifies each detail record in tagged PDF tables. Other formats retain their existing cells and presentation. */
28
+ readonly rowHeader?: boolean;
29
+ /** Contiguous shared prefixes form merged heading rows above the leaf headers. */
30
+ readonly groups?: readonly string[];
31
+ }
32
+ /** Zero-based position in the exported data, independent of titles and headings. */
33
+ export interface ColumnValueContext {
34
+ readonly rowIndex: number;
35
+ readonly columnIndex: number;
36
+ readonly column: ColumnSettings & {
37
+ readonly key?: string;
38
+ };
39
+ readonly sheetName?: string;
40
+ /** One-based Excel coordinate, when the destination is a worksheet. */
41
+ readonly worksheetRow?: number;
42
+ }
43
+ /** Select a literal object key, or explicitly compute a value. Array rows remain positional unless every column has a getter. */
44
+ export type Column<T = never> = import("../internal/columns.js").ProjectedColumn<T, import("./presentation.js").ExportValue>;
45
+ /** Counts for one completed table export. Rows exclude generated headings and footers. */
46
+ export interface ExportResult {
47
+ readonly rows: number;
48
+ readonly columns: number;
49
+ readonly bytes: number;
50
+ }
51
+ export interface ExportProgress {
52
+ readonly phase: "rows" | "complete";
53
+ readonly rows: number;
54
+ readonly sheetName?: string;
55
+ /** Completed rows in the named worksheet; rows remains the workbook-wide total. */
56
+ readonly sheetRows?: number;
57
+ readonly totalRows?: number;
58
+ readonly bytes?: number;
59
+ }
60
+ export interface StreamOptions {
61
+ readonly signal?: AbortSignal;
62
+ readonly limits?: import("./limits.js").ExportLimits;
63
+ /** Synchronous notification; throwing fails the operation. */
64
+ readonly onProgress?: (progress: ExportProgress) => void;
65
+ }
66
+ /** Feature detection has no import-time DOM or compressor side effects. */
67
+ export declare function detectFeatures(): {
68
+ blob: boolean;
69
+ streams: boolean;
70
+ deflateRaw: boolean;
71
+ download: boolean;
72
+ };
73
+ /** Browser download helper. Workers and Node should deliver the Blob themselves. */
74
+ export declare function saveBlob(blob: Blob, fileName: string): void;
@@ -0,0 +1,37 @@
1
+ export { OfficeIMOError, NotSupportedError } from "./errors.js";
2
+ export { BlobByteSink, ChunkedTextSink, writeBytes } from "./sinks.js";
3
+ export { ExportCell } from "./presentation.js";
4
+ export { createGroupedReport } from "./grouped-report.js";
5
+ export { checkAbort, withAbort, inputRows, pause } from "./iteration.js";
6
+ import { OfficeIMOError } from "./errors.js";
7
+ /** Feature detection has no import-time DOM or compressor side effects. */
8
+ export function detectFeatures() {
9
+ let deflateRaw = false;
10
+ if (typeof CompressionStream === "function") {
11
+ try {
12
+ new CompressionStream("deflate-raw");
13
+ deflateRaw = true;
14
+ }
15
+ catch { /* stored fallback */ }
16
+ }
17
+ return { blob: typeof Blob === "function", streams: typeof WritableStream === "function", deflateRaw,
18
+ download: typeof document !== "undefined" && typeof URL.createObjectURL === "function" };
19
+ }
20
+ /** Browser download helper. Workers and Node should deliver the Blob themselves. */
21
+ export function saveBlob(blob, fileName) {
22
+ if (!(blob instanceof Blob) || typeof fileName !== "string" || !fileName)
23
+ throw new TypeError("A Blob and file name are required.");
24
+ if (typeof document === "undefined" || typeof URL.createObjectURL !== "function")
25
+ throw new OfficeIMOError("PLATFORM_UNAVAILABLE", "saveBlob requires a browser document and object URLs.");
26
+ const url = URL.createObjectURL(blob), link = document.createElement("a");
27
+ try {
28
+ link.href = url;
29
+ link.download = fileName;
30
+ document.body.append(link);
31
+ link.click();
32
+ }
33
+ finally {
34
+ link.remove();
35
+ setTimeout(() => URL.revokeObjectURL(url), 30000);
36
+ }
37
+ }
@@ -0,0 +1,7 @@
1
+ export declare function checkAbort(signal?: AbortSignal): void;
2
+ /** Race a pending producer or sink operation without leaving abort listeners behind. */
3
+ export declare function withAbort<T>(promise: PromiseLike<T>, signal?: AbortSignal): Promise<T>;
4
+ /** Consume once; return the iterator on failure or cancellation. Pass the signal to I/O producers too. */
5
+ export declare function inputRows<T>(input: Iterable<T> | AsyncIterable<T>, signal?: AbortSignal): AsyncGenerator<T>;
6
+ /** Yield a task so input, rendering and cancellation can run without nested timer delays. */
7
+ export declare function pause(): Promise<void>;