@evotecit/officeimo 0.1.5 → 0.1.19
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.
- package/README.md +15 -3
- package/bundles/officeimo-canopyx-adapter.js +1444 -0
- package/bundles/officeimo-canopyx-adapter.min.js +2 -0
- package/bundles/officeimo-canopyx-adapter.min.mjs +2 -0
- package/bundles/officeimo-canopyx-adapter.mjs +1426 -0
- package/bundles/officeimo-canopyx.js +15 -14
- package/bundles/officeimo-canopyx.min.js +2 -0
- package/bundles/officeimo-canopyx.min.mjs +2 -0
- package/bundles/officeimo-canopyx.mjs +7 -6
- package/bundles/officeimo-csv.min.js +2 -0
- package/bundles/officeimo-csv.min.mjs +2 -0
- package/bundles/officeimo-datatables-adapter.js +626 -0
- package/bundles/officeimo-datatables-adapter.min.js +2 -0
- package/bundles/officeimo-datatables-adapter.min.mjs +2 -0
- package/bundles/officeimo-datatables-adapter.mjs +617 -0
- package/bundles/officeimo-datatables.js +55 -10
- package/bundles/officeimo-datatables.min.js +2 -0
- package/bundles/officeimo-datatables.min.mjs +2 -0
- package/bundles/officeimo-datatables.mjs +51 -6
- package/bundles/officeimo-execution.min.js +2 -0
- package/bundles/officeimo-execution.min.mjs +2 -0
- package/bundles/officeimo-pdf.min.js +2 -0
- package/bundles/officeimo-pdf.min.mjs +2 -0
- package/bundles/officeimo-xlsx.min.js +2 -0
- package/bundles/officeimo-xlsx.min.mjs +2 -0
- package/bundles/officeimo.min.js +2 -0
- package/bundles/officeimo.min.mjs +2 -0
- package/bundles/officeimo.mjs +2 -1
- package/dist/integrations/canopyx/metadata.js +1 -1
- package/dist/integrations/canopyx/pdf-number.js +6 -5
- package/dist/integrations/canopyx/types.d.ts +2 -1
- package/dist/integrations/datatables/snapshot.js +51 -6
- package/package.json +6 -2
|
@@ -0,0 +1,1444 @@
|
|
|
1
|
+
// Generated by OfficeIMO.JavaScript/scripts/bundles.mjs from tsc output. MIT.
|
|
2
|
+
(function (root) {
|
|
3
|
+
"use strict";
|
|
4
|
+
const officeimo = root.OfficeIMO || (root.OfficeIMO = {});
|
|
5
|
+
const cacheKey = Symbol.for("@evotecit/officeimo/modules");
|
|
6
|
+
const _modules = officeimo[cacheKey];
|
|
7
|
+
const _core = key => { const value = _modules && _modules.get(key); if (!value) throw new Error("officeimo-canopyx-adapter.js needs officeimo.js or officeimo.min.js from the same OfficeIMO build, loaded first."); return value; };
|
|
8
|
+
const _c0 = _core("81b3d47c02b7d8443b79e02b3cfb52032d6b73d9a3fb592b777ebe028ad0ef00");
|
|
9
|
+
const _c1 = _core("6cfd3e806439f6301003a2d1699a74fdfa574d935550ab62b97b528728eaee1f");
|
|
10
|
+
const _c2 = _core("50b3c10b690ceff693c8c5f809195ba6845b20e60f408e791a750d2ecbd5c669");
|
|
11
|
+
const _c3 = _core("42faf379960e5674a6fdfa8c8fca0bb68bbd74587231248d2524d7004def3671");
|
|
12
|
+
const _c4 = _core("f0627ba89e5c8fcb376ebe3ce72dcc8d68c34952981f8703e36b8bb1a9894208");
|
|
13
|
+
const _c5 = _core("4a089607f7cbe50e13d4382d1cc4e5f6ce32c5773bbec2df84178710f54d9a38");
|
|
14
|
+
const _c6 = _core("477ff98f49343b8ec4213008254b57a60dd42d07cb9843b3791d5e5f8e295865");
|
|
15
|
+
const _c7 = _core("d6587a933b36ccfdba9a2a252389924ac8461f672b3a500082cceb5e53c8b0b6");
|
|
16
|
+
const _c8 = _core("b48bcab805d4c75294dd8d8e8dc57f96d9db3f5af31a8f0ddc6562f010f566e4");
|
|
17
|
+
const _c9 = _core("027aafa08408056b10d7d717d63d1f7c0ee20ecfc68213aa66feacc75ec525fe");
|
|
18
|
+
const _c10 = _core("0391fe35ea7d02b25804ab4d0e7543136d6bb615f368f268c74aa135f23aa6bc");
|
|
19
|
+
const _c11 = _core("732224f6995c2478cf33a6ed01f3e3d3dcccb159a731d6db9280104bd5040fc5");
|
|
20
|
+
const _c12 = _core("e88a83ca79cd099fc2de29689554c913c7d04b17018098f81c43044064fcdfb8");
|
|
21
|
+
const _c13 = _core("046b305cdccf817d847addb75a778131622de23f2840830bbe1c0c26053a68c0");
|
|
22
|
+
const _c14 = _core("87c24efeaa0f1579c19afeeb4918caeb4f8f65a88d24a246e2cfd712b37dbac3");
|
|
23
|
+
const _c15 = _core("c9fde2c438e186da56f740105fcd41c265fdfdd855a4f1b811d556a02387479b");
|
|
24
|
+
const _c16 = _core("227236fd7adc9472e188831b8f16fdc69338c4d779f2b69a8abbd8dbfa95b585");
|
|
25
|
+
const _c17 = _core("a10003e971cd5ec2cee127bc9b029a0aa06fe3d50112838929d7a04a55e177c0");
|
|
26
|
+
const _c18 = _core("5337d1e3bd5ae0c1d10a476fcd31540d20337ccf7aa93c7e9e26c2b1a7dab92b");
|
|
27
|
+
const _c19 = _core("d9c1509dff0538488752433e47cd0927ece5f93c559ad0e32dc56602dfd44596");
|
|
28
|
+
const _c20 = _core("59911f0fe023545e9e97521b268551078bdc4c5f303e446a13b7d52f905e8070");
|
|
29
|
+
const _m4 = _modules.get("7b12a415e92cc9ef7212fb3a88007cb6dc37f9f30077165d4897cfa8052f9a3c") ?? (() => {
|
|
30
|
+
const { captureFields } = _c2;
|
|
31
|
+
|
|
32
|
+
const { ExportBudget } = _c3;
|
|
33
|
+
|
|
34
|
+
const { captureCsvOptions: captureCsv } = _c4;
|
|
35
|
+
|
|
36
|
+
const { capturePdfOptions: capturePdf, capturePdfLimits, pdfLimitFields } = _c5;
|
|
37
|
+
|
|
38
|
+
const { captureWorkbookLimits, workbookLimitFields, workbookOptionFields, sheetOptionFields } = _c6;
|
|
39
|
+
|
|
40
|
+
const limitFields = [...new Set([...workbookLimitFields, ...pdfLimitFields])];
|
|
41
|
+
const portableWorkbookFields = workbookOptionFields.filter((key) => key !== "sink");
|
|
42
|
+
/** Shared adapter budgets override only explicitly supplied numeric format ceilings. */
|
|
43
|
+
function captureCommonLimits(input) {
|
|
44
|
+
return input === undefined ? undefined : new ExportBudget(captureFields(input, limitFields)).limits;
|
|
45
|
+
}
|
|
46
|
+
function mergeAdapterLimits(format, common) {
|
|
47
|
+
const result = { ...format };
|
|
48
|
+
for (const [key, value] of Object.entries(common ?? {}))
|
|
49
|
+
if (value !== undefined)
|
|
50
|
+
result[key] = value;
|
|
51
|
+
return result;
|
|
52
|
+
}
|
|
53
|
+
/** Snapshot the format owner's fields before an adapter adds captured columns and stream policy. */
|
|
54
|
+
function captureXlsxOptions(input = {}) {
|
|
55
|
+
const options = captureFields(input, [...portableWorkbookFields, "sheet"]);
|
|
56
|
+
const sheet = options.sheet && captureFields(options.sheet, [...sheetOptionFields, "name"]);
|
|
57
|
+
const footer = sheet?.footer && captureFields(sheet.footer, ["rows", "values", "totals", "style"]);
|
|
58
|
+
return { ...options, ...(sheet === undefined ? {} : { sheet: { ...sheet, ...(footer === undefined ? {} : { footer }) } }),
|
|
59
|
+
...(options.limits === undefined ? {} : { limits: captureWorkbookLimits(options.limits) }) };
|
|
60
|
+
}
|
|
61
|
+
function captureCsvOptions(input = {}) {
|
|
62
|
+
const options = captureCsv(input);
|
|
63
|
+
return { ...options, ...(options.limits === undefined ? {} : { limits: new ExportBudget(options.limits).limits }) };
|
|
64
|
+
}
|
|
65
|
+
function capturePdfOptions(input = {}) {
|
|
66
|
+
const options = capturePdf(input);
|
|
67
|
+
return { ...options, ...(options.limits === undefined ? {} : { limits: capturePdfLimits(options.limits) }) };
|
|
68
|
+
}
|
|
69
|
+
const _exports = Object.freeze({ captureCommonLimits: captureCommonLimits, mergeAdapterLimits: mergeAdapterLimits, captureXlsxOptions: captureXlsxOptions, captureCsvOptions: captureCsvOptions, capturePdfOptions: capturePdfOptions });
|
|
70
|
+
_modules.set("7b12a415e92cc9ef7212fb3a88007cb6dc37f9f30077165d4897cfa8052f9a3c", _exports);
|
|
71
|
+
return _exports;
|
|
72
|
+
})();
|
|
73
|
+
|
|
74
|
+
const _m12 = _modules.get("3d1862d8ab32171bca4b3ba5fe0bdcc073f67ce940aaff0ee735635893f86ee8") ?? (() => {
|
|
75
|
+
/** One policy for capture diagnostics and unsupported adapter mappings; callbacks stay synchronous. */
|
|
76
|
+
function canopyDiagnostics(format, options) {
|
|
77
|
+
const policy = options.unsupportedPresentation ?? (format === "csv" ? "text" : "reject"), notify = options.onDiagnostic;
|
|
78
|
+
if (policy !== "reject" && policy !== "text")
|
|
79
|
+
throw new TypeError("unsupportedPresentation must be reject or text.");
|
|
80
|
+
if (notify !== undefined && typeof notify !== "function")
|
|
81
|
+
throw new TypeError("onDiagnostic must be a synchronous function.");
|
|
82
|
+
return diagnostic => {
|
|
83
|
+
if (policy === "reject")
|
|
84
|
+
throw new TypeError("Unsupported Canopy presentation: " + diagnostic.code + (diagnostic.columnId ? " (" + diagnostic.columnId + ")" : ""));
|
|
85
|
+
const result = notify?.(Object.freeze(diagnostic));
|
|
86
|
+
if (result && typeof result.then === "function") {
|
|
87
|
+
void Promise.resolve(result).catch(() => { });
|
|
88
|
+
throw new TypeError("onDiagnostic must be synchronous.");
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
const _exports = Object.freeze({ canopyDiagnostics: canopyDiagnostics });
|
|
93
|
+
_modules.set("3d1862d8ab32171bca4b3ba5fe0bdcc073f67ce940aaff0ee735635893f86ee8", _exports);
|
|
94
|
+
return _exports;
|
|
95
|
+
})();
|
|
96
|
+
|
|
97
|
+
const _m14 = _modules.get("5e0a9bdc75106268fcdff0cc6d7778080db216c7597514163f5fe5ff8ce93be1") ?? (() => {
|
|
98
|
+
function presentation(input, axes) {
|
|
99
|
+
const { axisKey, outlineLevel, summary, grandTotal, hidden, collapsed } = input;
|
|
100
|
+
if (typeof axisKey !== "string" || !axes.has(axisKey) || !Number.isInteger(outlineLevel) || outlineLevel < 0 || outlineLevel > 7 ||
|
|
101
|
+
[summary, grandTotal, hidden, collapsed].some(flag => typeof flag !== "boolean"))
|
|
102
|
+
throw new TypeError("Invalid frozen Canopy pivot axis presentation.");
|
|
103
|
+
return Object.freeze({ level: outlineLevel, hidden: hidden, collapsed: collapsed });
|
|
104
|
+
}
|
|
105
|
+
/** Qualify the explicit pivot path before flat/grouped handling; never evaluate query or aggregate data. */
|
|
106
|
+
function canopyPivot(request) {
|
|
107
|
+
if (request.pivot === undefined)
|
|
108
|
+
return undefined;
|
|
109
|
+
const pivot = request.pivot;
|
|
110
|
+
if (!pivot || typeof pivot !== "object" || request.grouping !== undefined || !Array.isArray(request.columns) ||
|
|
111
|
+
request.scope !== "filtered" || !Number.isSafeInteger(request.recordCount) || request.recordCount < 0 ||
|
|
112
|
+
!pivot.definition || !Array.isArray(pivot.definition.rows) || pivot.definition.rows.length > 4 ||
|
|
113
|
+
!Array.isArray(pivot.definition.columns) || pivot.definition.columns.length > 2 ||
|
|
114
|
+
!Array.isArray(pivot.definition.values) || !pivot.definition.values.length || pivot.definition.values.length > 32 ||
|
|
115
|
+
pivot.definition.values.some(value => typeof value !== "string") ||
|
|
116
|
+
!Number.isSafeInteger(pivot.distinctColumns) || pivot.distinctColumns < 0 || typeof pivot.columnsLimited !== "boolean" ||
|
|
117
|
+
!Array.isArray(pivot.retainedColumns) || !Array.isArray(pivot.columnGroups))
|
|
118
|
+
throw new TypeError("Invalid explicit Canopy pivot descriptor.");
|
|
119
|
+
const axes = (nodes) => {
|
|
120
|
+
if (!Array.isArray(nodes) || nodes.length > 100001)
|
|
121
|
+
throw new TypeError("Pivot axes require bounded accepted identities.");
|
|
122
|
+
const keys = new Set();
|
|
123
|
+
for (const node of nodes) {
|
|
124
|
+
if (!node || typeof node.key !== "string" || !node.key || keys.has(node.key) || !Array.isArray(node.path) || typeof node.other !== "boolean")
|
|
125
|
+
throw new TypeError("Invalid or duplicate Canopy pivot axis identity.");
|
|
126
|
+
keys.add(node.key);
|
|
127
|
+
}
|
|
128
|
+
for (const node of nodes)
|
|
129
|
+
if (node.parent !== undefined && !keys.has(node.parent))
|
|
130
|
+
throw new TypeError("Unknown Canopy pivot parent identity.");
|
|
131
|
+
return keys;
|
|
132
|
+
};
|
|
133
|
+
const rowKeys = axes(pivot.rowAxis), columnKeys = axes(pivot.columnAxis);
|
|
134
|
+
const columns = request.columns.map((column, index) => {
|
|
135
|
+
if (index === 0 && column.axisKey === undefined && column.kind === "text")
|
|
136
|
+
return Object.freeze({ ...column });
|
|
137
|
+
const outline = presentation(column, columnKeys);
|
|
138
|
+
return Object.freeze({ ...column, outlineLevel: outline.level, hidden: outline.hidden, collapsed: outline.collapsed });
|
|
139
|
+
});
|
|
140
|
+
// Ranges are descriptor metadata, not another body. Validate them against the same ordered columns.
|
|
141
|
+
if (pivot.columnGroups.length > columns.length)
|
|
142
|
+
throw new RangeError("Pivot column group count exceeds projected columns.");
|
|
143
|
+
for (const group of pivot.columnGroups) {
|
|
144
|
+
if (!group || !columnKeys.has(group.key) || !Number.isSafeInteger(group.firstColumn) || group.firstColumn < 0 ||
|
|
145
|
+
!Number.isSafeInteger(group.columnCount) || group.columnCount < 1 || group.firstColumn + group.columnCount > columns.length ||
|
|
146
|
+
!Number.isInteger(group.depth) || group.depth < 1 || group.depth > 7 ||
|
|
147
|
+
typeof group.hidden !== "boolean" || typeof group.collapsed !== "boolean")
|
|
148
|
+
throw new TypeError("Invalid Canopy pivot column range.");
|
|
149
|
+
}
|
|
150
|
+
let current;
|
|
151
|
+
const sheet = Object.freeze({ outlineSummaryBelow: false, outlineSummaryRight: false,
|
|
152
|
+
maxOutlineLevel: 7, rowOutline: () => current,
|
|
153
|
+
columnOutlines: Object.freeze(columns.flatMap((column, firstColumn) => column.axisKey === undefined ? [] :
|
|
154
|
+
[Object.freeze({ firstColumn, columnCount: 1, level: column.outlineLevel, hidden: column.hidden, collapsed: column.collapsed })])) });
|
|
155
|
+
return Object.freeze({ columns: Object.freeze(columns), sheet,
|
|
156
|
+
observe(row) { current = presentation(row, rowKeys); } });
|
|
157
|
+
}
|
|
158
|
+
/** Per-cell formats preserve already-computed fractional percentages, ranks and differences. */
|
|
159
|
+
function pivotNumberFormat(cell) {
|
|
160
|
+
// Raw-value aggregates need no decimal declaration. Transformed values still
|
|
161
|
+
// require the producer's frozen format (especially percent scaling).
|
|
162
|
+
if (cell.mode === "value" && cell.numberFormat === undefined)
|
|
163
|
+
return undefined;
|
|
164
|
+
if (!["value", "percentGrandTotal", "percentParent", "percentColumn", "percentRow", "runningTotal", "rank", "difference", "percentChange"].includes(cell.mode ?? "") ||
|
|
165
|
+
typeof cell.numberFormat !== "string" || !cell.numberFormat.length)
|
|
166
|
+
throw new TypeError("Numeric pivot cells require a frozen mode and native numberFormat.");
|
|
167
|
+
return cell.numberFormat;
|
|
168
|
+
}
|
|
169
|
+
const _exports = Object.freeze({ canopyPivot: canopyPivot, pivotNumberFormat: pivotNumberFormat });
|
|
170
|
+
_modules.set("5e0a9bdc75106268fcdff0cc6d7778080db216c7597514163f5fe5ff8ce93be1", _exports);
|
|
171
|
+
return _exports;
|
|
172
|
+
})();
|
|
173
|
+
|
|
174
|
+
const _m15 = _modules.get("c0aee2c5df0df3e62ca31fc685243cdd4b449f083834e8d28cf92c20dfa7b27f") ?? (() => {
|
|
175
|
+
/** @internal Typed conversion follows declared datetime intent, never localized display text. */
|
|
176
|
+
function datetime(value, mode, clock) {
|
|
177
|
+
if (mode === "text")
|
|
178
|
+
return value;
|
|
179
|
+
const match = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})(?::(\d{2})(?:\.(\d+))?)?(Z|[+-]\d{2}:\d{2})$/.exec(value);
|
|
180
|
+
if (!match)
|
|
181
|
+
throw new TypeError("Canopy datetime values require an ISO timestamp with an explicit time zone.");
|
|
182
|
+
const date = new Date(value);
|
|
183
|
+
const offset = match[8] === "Z" ? 0 : (match[8][0] === "+" ? 1 : -1) * (Number(match[8].slice(1, 3)) * 60 + Number(match[8].slice(4)));
|
|
184
|
+
const year = Number(match[1]), month = Number(match[2]), day = Number(match[3]);
|
|
185
|
+
const hour = Number(match[4]), minute = Number(match[5]), second = Number(match[6] ?? "0"), fraction = match[7] ?? "";
|
|
186
|
+
// setUTCFullYear preserves years 0 through 99. Validate the calendar before allowing ISO's next-day 24:00 spelling.
|
|
187
|
+
const wall = new Date(0);
|
|
188
|
+
wall.setUTCFullYear(year, month - 1, day);
|
|
189
|
+
if (!Number.isFinite(date.getTime()) || Number(match[8].slice(1, 3)) > 23 || Number(match[8].slice(4)) > 59 ||
|
|
190
|
+
wall.getUTCFullYear() !== year || wall.getUTCMonth() + 1 !== month || wall.getUTCDate() !== day ||
|
|
191
|
+
hour > 24 || minute > 59 || second > 59 || hour === 24 && (minute !== 0 || second !== 0 || /[1-9]/.test(fraction)))
|
|
192
|
+
throw new TypeError("Invalid Canopy datetime value.");
|
|
193
|
+
wall.setUTCHours(hour, minute, second, Number((fraction + "000").slice(0, 3)));
|
|
194
|
+
if (wall.getTime() !== date.getTime() + offset * 60000)
|
|
195
|
+
throw new TypeError("Invalid Canopy datetime value.");
|
|
196
|
+
if (/[1-9]/.test(fraction.slice(3))) {
|
|
197
|
+
if (mode === "typed")
|
|
198
|
+
throw new TypeError("Typed Excel dates cannot preserve sub-millisecond precision; use datetime: preserve or text.");
|
|
199
|
+
return value;
|
|
200
|
+
}
|
|
201
|
+
const excelYear = clock === "utc" ? date.getUTCFullYear() : date.getFullYear();
|
|
202
|
+
if (excelYear < 1900 || excelYear > 9999) {
|
|
203
|
+
if (mode === "typed")
|
|
204
|
+
throw new TypeError("Typed Excel dates require years 1900 through 9999; use datetime: preserve or text.");
|
|
205
|
+
return value;
|
|
206
|
+
}
|
|
207
|
+
return date;
|
|
208
|
+
}
|
|
209
|
+
const _exports = Object.freeze({ datetime: datetime });
|
|
210
|
+
_modules.set("c0aee2c5df0df3e62ca31fc685243cdd4b449f083834e8d28cf92c20dfa7b27f", _exports);
|
|
211
|
+
return _exports;
|
|
212
|
+
})();
|
|
213
|
+
|
|
214
|
+
const _m18 = _modules.get("040752afe195985e6f2e91f8c62fc13464c455fc44034b8cef4828851e05b83d") ?? (() => {
|
|
215
|
+
/** Calibri 11, 96-DPI CSS pixels, seven-pixel maximum digit and five-pixel cell padding.
|
|
216
|
+
* Quantize to native 1/256-character units; this is a reproducible profile, not pixel-identical rendering. */
|
|
217
|
+
function canopyXlsxWidth(pixels) {
|
|
218
|
+
const width = Math.floor((pixels < 12 ? pixels / 12 : (pixels - 5) / 7) * 256) / 256;
|
|
219
|
+
if (!Number.isFinite(width) || width <= 0 || width > 255)
|
|
220
|
+
throw new RangeError("Captured width exceeds the Calibri-11 XLSX width profile.");
|
|
221
|
+
return width;
|
|
222
|
+
}
|
|
223
|
+
/** Escape literal prefixes/suffixes; no browser formatter or CSS becomes workbook code. */
|
|
224
|
+
function canopyNumberFormat(input, report, id) {
|
|
225
|
+
if (!input || typeof input !== "object" || Array.isArray(input))
|
|
226
|
+
throw new TypeError("Canopy numeric format must be an object.");
|
|
227
|
+
if (Object.keys(input).some(key => !["minimumFractionDigits", "maximumFractionDigits", "prefix", "suffix"].includes(key))) {
|
|
228
|
+
report({ code: "UNSUPPORTED_NUMBER_FORMAT", columnId: id });
|
|
229
|
+
return undefined;
|
|
230
|
+
}
|
|
231
|
+
const { minimumFractionDigits: minimum = 0, maximumFractionDigits: maximum = 3, prefix = "", suffix = "" } = input;
|
|
232
|
+
if (!Number.isInteger(minimum) || !Number.isInteger(maximum) || minimum < 0 || maximum < minimum || maximum > 10 ||
|
|
233
|
+
typeof prefix !== "string" || typeof suffix !== "string" || prefix.length > 16 || suffix.length > 16)
|
|
234
|
+
throw new TypeError("Canopy numeric fraction bounds must be ordered integers from zero through ten, with literal affixes of at most sixteen characters.");
|
|
235
|
+
const literal = (value) => value ? '"' + value.replace(/"/g, '"\\""') + '"' : "";
|
|
236
|
+
return literal(prefix) + "0" + (maximum ? "." + "0".repeat(minimum) + "#".repeat(maximum - minimum) : "") + literal(suffix);
|
|
237
|
+
}
|
|
238
|
+
/** Only a contiguous leading left pin can be represented by an Excel freeze pane. */
|
|
239
|
+
function canopyPins(columns, report) {
|
|
240
|
+
let leading = 0, ended = false;
|
|
241
|
+
for (const column of columns) {
|
|
242
|
+
const pin = column.pinned;
|
|
243
|
+
if (pin !== undefined && pin !== null && pin !== "left" && pin !== "right")
|
|
244
|
+
throw new TypeError("Invalid Canopy pin.");
|
|
245
|
+
if (!ended && pin === "left")
|
|
246
|
+
leading++;
|
|
247
|
+
else {
|
|
248
|
+
ended = true;
|
|
249
|
+
if (pin === "left" || pin === "right")
|
|
250
|
+
report({ code: "UNREPRESENTABLE_PIN:" + pin, columnId: column.id });
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
return leading;
|
|
254
|
+
}
|
|
255
|
+
const _exports = Object.freeze({ canopyXlsxWidth: canopyXlsxWidth, canopyNumberFormat: canopyNumberFormat, canopyPins: canopyPins });
|
|
256
|
+
_modules.set("040752afe195985e6f2e91f8c62fc13464c455fc44034b8cef4828851e05b83d", _exports);
|
|
257
|
+
return _exports;
|
|
258
|
+
})();
|
|
259
|
+
|
|
260
|
+
const _m13 = _modules.get("40e200b77947621ffacdfa2e1326760a78a52a7dfb6d0cbaa7c7a71607b119a2") ?? (() => {
|
|
261
|
+
const { ExportCell, checkAbort, inputRows } = _c0;
|
|
262
|
+
|
|
263
|
+
const { canopyPivot, pivotNumberFormat } = _m14;
|
|
264
|
+
|
|
265
|
+
const { datetime } = _m15;
|
|
266
|
+
|
|
267
|
+
const { captureFields } = _c2;
|
|
268
|
+
|
|
269
|
+
const { copyColumns } = _c10;
|
|
270
|
+
|
|
271
|
+
const { copyCellPresentation } = _c11;
|
|
272
|
+
|
|
273
|
+
const { canopyDiagnostics } = _m12;
|
|
274
|
+
|
|
275
|
+
const { canopyNumberFormat, canopyXlsxWidth } = _m18;
|
|
276
|
+
|
|
277
|
+
const columnFields = ["width", "format", "wrapText", "alignment", "rowHeader", "groups"];
|
|
278
|
+
const rawIdentities = new WeakMap();
|
|
279
|
+
/** @internal Grouping uses captured identity even when a detail cell displays a relative-link label. */
|
|
280
|
+
function canopyIdentityValue(value) {
|
|
281
|
+
if (!(value instanceof ExportCell))
|
|
282
|
+
return value;
|
|
283
|
+
const original = rawIdentities.get(value);
|
|
284
|
+
return original === undefined ? value.value : original;
|
|
285
|
+
}
|
|
286
|
+
/** Map an immutable CanopyX record capture to a writer without querying the grid or retaining its body. */
|
|
287
|
+
function createCanopyExport(capture, format, options = {}) {
|
|
288
|
+
return prepareCanopyExport(capture, format, options).source;
|
|
289
|
+
}
|
|
290
|
+
/** @internal Capture the input once before full-writer metadata mapping and asynchronous enumeration. */
|
|
291
|
+
function prepareCanopyExport(capture, format, options = {}) {
|
|
292
|
+
options = captureFields(options, ["tones", "columnOptions", "unsupportedPresentation", "datetime", "xlsx", "signal", "onDiagnostic"]);
|
|
293
|
+
if (format !== "xlsx" && format !== "csv" && format !== "pdf")
|
|
294
|
+
throw new TypeError("Canopy export format must be xlsx, csv or pdf.");
|
|
295
|
+
if (!capture || typeof capture.rows !== "function" || !capture.request)
|
|
296
|
+
throw new TypeError("A portable CanopyX capture with request and rows() is required.");
|
|
297
|
+
const request = captureFields(capture.request, ["columns", "recordCount", "values", "presentation", "timeZone", "revision", "scope", "total", "matched", "selection", "query", "generatedAt", "grouping", "pivot", "formatRules"]);
|
|
298
|
+
const pivot = canopyPivot(request);
|
|
299
|
+
const signal = options.signal, values = request.values;
|
|
300
|
+
if (!Array.isArray(request.columns) || !request.columns.length || (request.recordCount !== null && (!Number.isSafeInteger(request.recordCount) || request.recordCount < 0)) ||
|
|
301
|
+
(values !== "raw" && values !== "display") || (request.timeZone !== "utc" && request.timeZone !== "local") || typeof request.revision !== "string")
|
|
302
|
+
throw new TypeError("Invalid portable CanopyX capture metadata.");
|
|
303
|
+
const dateMode = options.datetime ?? "preserve", report = canopyDiagnostics(format, options);
|
|
304
|
+
// These captured presentations have a complete scalar/text projection. Report
|
|
305
|
+
// their visual loss without treating an ordinary report export as unsupported.
|
|
306
|
+
const fallback = canopyDiagnostics(format, { ...options, unsupportedPresentation: "text" });
|
|
307
|
+
const clock = options.xlsx?.dateMode ?? request.timeZone;
|
|
308
|
+
if (clock !== "utc" && clock !== "local")
|
|
309
|
+
throw new TypeError("XLSX dateMode must be utc or local.");
|
|
310
|
+
if (dateMode !== "preserve" && dateMode !== "typed" && dateMode !== "text")
|
|
311
|
+
throw new TypeError("datetime must be preserve, typed or text.");
|
|
312
|
+
const diagnostics = (items, rowId, columnId) => {
|
|
313
|
+
if (items === undefined)
|
|
314
|
+
return;
|
|
315
|
+
if (!Array.isArray(items) || items.some(item => typeof item !== "string"))
|
|
316
|
+
throw new TypeError("Canopy presentation diagnostics must be strings.");
|
|
317
|
+
for (const code of items) {
|
|
318
|
+
const diagnostic = { code, ...(rowId === undefined ? {} : { rowId }), ...(columnId === undefined ? {} : { columnId }) };
|
|
319
|
+
(code === "relative-link" || code === "history-series" ? fallback : report)(diagnostic);
|
|
320
|
+
}
|
|
321
|
+
};
|
|
322
|
+
if (request.presentation !== "text" && request.presentation !== "semantic")
|
|
323
|
+
throw new TypeError("Canopy captures must declare text or semantic presentation.");
|
|
324
|
+
const tones = new Map(Object.entries(options.tones ?? {}).map(([name, style]) => {
|
|
325
|
+
if (!style || typeof style !== "object" || Array.isArray(style))
|
|
326
|
+
throw new TypeError("Tone mappings must be portable presentation objects.");
|
|
327
|
+
return [name, copyCellPresentation(style)];
|
|
328
|
+
}));
|
|
329
|
+
const tone = (name, rowId, columnId) => {
|
|
330
|
+
if (name === undefined)
|
|
331
|
+
return undefined;
|
|
332
|
+
if (typeof name !== "string")
|
|
333
|
+
throw new TypeError("Canopy tones must be strings.");
|
|
334
|
+
const style = tones.get(name);
|
|
335
|
+
if (!style && name !== "neutral")
|
|
336
|
+
fallback({ code: "UNMAPPED_TONE:" + name, rowId, ...(columnId === undefined ? {} : { columnId }) });
|
|
337
|
+
return style;
|
|
338
|
+
};
|
|
339
|
+
const ids = new Set();
|
|
340
|
+
const specs = (pivot?.columns ?? request.columns).map(input => {
|
|
341
|
+
const fields = captureFields(input, ["id", "title", "kind", "width", "pinned", "format", "wrap", "alignment", "diagnostics"]);
|
|
342
|
+
const column = Object.freeze({ ...fields,
|
|
343
|
+
...(fields.width === undefined ? {} : { width: Object.freeze(captureFields(fields.width, ["unit", "preferred", "minimum", "maximum"])) }),
|
|
344
|
+
...(fields.format === undefined ? {} : { format: Object.freeze(captureFields(fields.format, ["minimumFractionDigits", "maximumFractionDigits", "prefix", "suffix"])) }) });
|
|
345
|
+
if (!column || typeof column.id !== "string" || !column.id || ids.has(column.id) || typeof column.title !== "string" ||
|
|
346
|
+
!["text", "number", "datetime"].includes(column.kind) ||
|
|
347
|
+
(column.wrap !== undefined && typeof column.wrap !== "boolean") || (column.alignment !== undefined && !["left", "right"].includes(column.alignment)) ||
|
|
348
|
+
(column.width !== undefined && (column.width.unit !== "css-px" || !Number.isFinite(column.width.preferred) ||
|
|
349
|
+
!Number.isFinite(column.width.minimum) || column.width.minimum <= 0 || column.width.preferred < column.width.minimum ||
|
|
350
|
+
column.width.maximum !== undefined && (!Number.isFinite(column.width.maximum) || column.width.maximum < column.width.preferred))) ||
|
|
351
|
+
(!pivot && request.presentation === "semantic" && (column.wrap === undefined || column.alignment === undefined || column.width === undefined)))
|
|
352
|
+
throw new TypeError("Invalid or duplicate Canopy export column.");
|
|
353
|
+
ids.add(column.id);
|
|
354
|
+
diagnostics(column.diagnostics, undefined, column.id);
|
|
355
|
+
const selected = Object.hasOwn(options.columnOptions ?? {}, column.id) ? options.columnOptions[column.id] : {};
|
|
356
|
+
for (const key of Object.keys(selected))
|
|
357
|
+
if (!columnFields.includes(key))
|
|
358
|
+
throw new TypeError("Unsupported Canopy column option: " + key);
|
|
359
|
+
const override = captureFields(selected, columnFields);
|
|
360
|
+
const numericFormat = (format === "xlsx" || format === "pdf") && values === "raw" && column.kind === "number" && column.format !== undefined && override.format === undefined
|
|
361
|
+
? canopyNumberFormat(column.format, report, column.id) : undefined;
|
|
362
|
+
const [captured] = copyColumns([{ ...override, key: column.id, header: column.title,
|
|
363
|
+
...(format === "xlsx" && override.width === undefined && column.width !== undefined ? { width: canopyXlsxWidth(column.width.preferred) } : {}),
|
|
364
|
+
...(override.format === undefined && numericFormat !== undefined ? { format: numericFormat } : {}),
|
|
365
|
+
...(format === "xlsx" && values === "raw" && column.kind === "datetime" && override.format === undefined ? { format: "yyyy-mm-dd hh:mm:ss.000" } : {}),
|
|
366
|
+
...(values === "raw" && column.kind === "number" ? { type: "number" } : {}),
|
|
367
|
+
// Screen nowrap is not a promise that its CSS width will survive PDF fitting.
|
|
368
|
+
// PDF defaults to lossless wrapping; an explicit writer override stays strict.
|
|
369
|
+
...(format === "pdf" ? { wrapText: override.wrapText ?? true } :
|
|
370
|
+
override.wrapText === undefined && column.wrap === undefined ? {} : { wrapText: override.wrapText ?? column.wrap }),
|
|
371
|
+
...(override.alignment === undefined && column.alignment === undefined ?
|
|
372
|
+
format === "pdf" && column.kind === "number" ? { alignment: "right" } : {} : { alignment: override.alignment ?? column.alignment }) }]);
|
|
373
|
+
return Object.freeze({ id: column.id, kind: column.kind, input: column, nativeFormatOverride: override.format, column: Object.freeze(captured) });
|
|
374
|
+
});
|
|
375
|
+
const rowCount = request.recordCount;
|
|
376
|
+
const source = Object.freeze({ columns: Object.freeze(specs.map(spec => spec.column)), rowCount, async *rows() {
|
|
377
|
+
checkAbort(signal);
|
|
378
|
+
let count = 0;
|
|
379
|
+
for await (const row of inputRows(capture.rows(signal ? { signal } : {}), signal)) {
|
|
380
|
+
checkAbort(signal);
|
|
381
|
+
if (!row || typeof row.id !== "string" || !row.cells || typeof row.cells !== "object")
|
|
382
|
+
throw new TypeError("Invalid Canopy export record.");
|
|
383
|
+
pivot?.observe(row);
|
|
384
|
+
diagnostics(row.diagnostics, row.id);
|
|
385
|
+
const rowStyle = tone(row.tone, row.id), result = [];
|
|
386
|
+
for (const spec of specs) {
|
|
387
|
+
if (!Object.hasOwn(row.cells, spec.id))
|
|
388
|
+
throw new TypeError("Canopy record is missing column " + spec.id + ".");
|
|
389
|
+
const cell = row.cells[spec.id];
|
|
390
|
+
if (!cell || typeof cell !== "object" || typeof cell.text !== "string" ||
|
|
391
|
+
(cell.value !== null && !["string", "number", "boolean"].includes(typeof cell.value)) ||
|
|
392
|
+
(typeof cell.value === "number" && (!Number.isFinite(cell.value) || Math.abs(cell.value) > Number.MAX_SAFE_INTEGER)))
|
|
393
|
+
throw new TypeError("A portable Canopy GridExportCell with scalar value and resolved text is required.");
|
|
394
|
+
diagnostics(cell.diagnostics, row.id, spec.id);
|
|
395
|
+
// A relative destination is navigation metadata, not the visible label.
|
|
396
|
+
// History captures already carry their frozen latest scalar (or null).
|
|
397
|
+
const relativeLabel = spec.kind === "text" && cell.diagnostics?.includes("relative-link");
|
|
398
|
+
let value = values === "display" || relativeLabel ? cell.text : cell.value;
|
|
399
|
+
if (format === "xlsx" && values === "raw" && spec.kind === "datetime" && typeof value === "string")
|
|
400
|
+
value = datetime(value, dateMode, clock);
|
|
401
|
+
const capturedFormat = pivot && spec.kind === "number" && cell.value !== null ? pivotNumberFormat(cell) : undefined;
|
|
402
|
+
const nativeFormat = spec.nativeFormatOverride === "" ? "General" : spec.nativeFormatOverride ?? capturedFormat;
|
|
403
|
+
const summary = format === "pdf" && pivot && (row.summary || row.grandTotal);
|
|
404
|
+
const cellStyle = tone(cell.tone, row.id, spec.id), presentation = rowStyle || cellStyle || nativeFormat || summary ? {
|
|
405
|
+
...rowStyle, ...(summary ? { bold: true } : {}), ...cellStyle,
|
|
406
|
+
...((format === "pdf" || (format === "xlsx" && pivot)) && values === "raw" && nativeFormat !== undefined ? { numberFormat: nativeFormat } : {})
|
|
407
|
+
} : undefined;
|
|
408
|
+
// CSV has no presentation or link metadata: emit its selected scalar directly.
|
|
409
|
+
// This also avoids a frozen wrapper for every cell in large CSV captures.
|
|
410
|
+
if (format === "csv")
|
|
411
|
+
result.push(value);
|
|
412
|
+
else {
|
|
413
|
+
const exported = new ExportCell(value, { text: cell.text, ...(presentation ? { presentation } : {}), ...(cell.link === undefined ? {} : { link: cell.link }) });
|
|
414
|
+
if (relativeLabel)
|
|
415
|
+
rawIdentities.set(exported, cell.value);
|
|
416
|
+
result.push(exported);
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
if (rowCount !== null && count >= rowCount)
|
|
420
|
+
throw new TypeError("Canopy capture exceeded its declared recordCount.");
|
|
421
|
+
count++;
|
|
422
|
+
yield result;
|
|
423
|
+
}
|
|
424
|
+
if (rowCount !== null && count !== rowCount)
|
|
425
|
+
throw new TypeError("Canopy capture did not produce its declared recordCount.");
|
|
426
|
+
} });
|
|
427
|
+
return Object.freeze({ source, request: Object.freeze({ ...request, columns: Object.freeze(specs.map(spec => spec.input)) }), report, tones, pivot });
|
|
428
|
+
}
|
|
429
|
+
const _exports = Object.freeze({ canopyIdentityValue: canopyIdentityValue, createCanopyExport: createCanopyExport, prepareCanopyExport: prepareCanopyExport });
|
|
430
|
+
_modules.set("40e200b77947621ffacdfa2e1326760a78a52a7dfb6d0cbaa7c7a71607b119a2", _exports);
|
|
431
|
+
return _exports;
|
|
432
|
+
})();
|
|
433
|
+
|
|
434
|
+
const _m20 = _modules.get("2b0b73e8c376d24e6a5b498c0f710966b00de0eff44f474d7b2aece7af64fa96") ?? (() => {
|
|
435
|
+
const { columnName, excelDate } = _c12;
|
|
436
|
+
|
|
437
|
+
const { captureFields } = _c2;
|
|
438
|
+
|
|
439
|
+
const { datetime } = _m15;
|
|
440
|
+
|
|
441
|
+
/** Compile only comparisons whose raw types and native encodings have a faithful bounded mapping. */
|
|
442
|
+
function canopyPredicate(request, grouped, options, root, unsupported, cellTypes) {
|
|
443
|
+
let nodes = 0;
|
|
444
|
+
const operations = { eq: "=", ne: "<>", gt: ">", ge: ">=", lt: "<", le: "<=" };
|
|
445
|
+
const numeric = (value) => {
|
|
446
|
+
const number = typeof value === "boolean" ? Number(value) : typeof value === "string" ? Number(value) : value;
|
|
447
|
+
// Use platform decimal conversion; separator/culture profiles need a diagnostic, not a second parser.
|
|
448
|
+
if (typeof value === "string") {
|
|
449
|
+
const text = value.trim().toLowerCase();
|
|
450
|
+
if (Number.parseFloat(value) !== number || ["0x", "0b", "0o"].some(prefix => text.startsWith(prefix)))
|
|
451
|
+
return unsupported("UNSUPPORTED_NUMERIC_RULE_LITERAL");
|
|
452
|
+
}
|
|
453
|
+
if (!Number.isFinite(number) || Math.abs(number) > Number.MAX_SAFE_INTEGER)
|
|
454
|
+
throw new TypeError("Canopy rule comparison values must be finite safe-range numbers.");
|
|
455
|
+
return number;
|
|
456
|
+
};
|
|
457
|
+
const date = (value) => {
|
|
458
|
+
if (options.datetime !== "typed" || (options.xlsx?.dateMode ?? request.timeZone) !== "utc")
|
|
459
|
+
return unsupported("DATETIME_RULE_REQUIRES_TYPED_UTC");
|
|
460
|
+
if (typeof value === "boolean")
|
|
461
|
+
return unsupported("UNSUPPORTED_DATETIME_RULE_LITERAL");
|
|
462
|
+
if (typeof value === "number" && !Number.isSafeInteger(value))
|
|
463
|
+
return unsupported("UNSUPPORTED_DATETIME_RULE_LITERAL");
|
|
464
|
+
try {
|
|
465
|
+
const literal = typeof value === "number" ? new Date(value).toISOString() : value;
|
|
466
|
+
const captured = datetime(literal, "typed", "utc");
|
|
467
|
+
if (!(captured instanceof Date))
|
|
468
|
+
return unsupported("UNSUPPORTED_DATETIME_RULE_LITERAL");
|
|
469
|
+
const serial = excelDate(captured, "utc");
|
|
470
|
+
if (serial === null)
|
|
471
|
+
return unsupported("UNSUPPORTED_DATETIME_RULE_LITERAL");
|
|
472
|
+
return serial;
|
|
473
|
+
}
|
|
474
|
+
catch (error) {
|
|
475
|
+
if (!(error instanceof TypeError) && !(error instanceof RangeError))
|
|
476
|
+
throw error;
|
|
477
|
+
return unsupported("UNSUPPORTED_DATETIME_RULE_LITERAL");
|
|
478
|
+
}
|
|
479
|
+
};
|
|
480
|
+
const leaf = (input) => {
|
|
481
|
+
if (++nodes > 64)
|
|
482
|
+
return unsupported("RULE_PREDICATE_LIMIT");
|
|
483
|
+
const filter = captureFields(input, ["column", "operator", "values"]), operation = operations[filter.operator];
|
|
484
|
+
if (Object.keys(filter).some(key => !["column", "operator", "values"].includes(key)))
|
|
485
|
+
return unsupported("UNSUPPORTED_RULE_FILTER_OPTIONS");
|
|
486
|
+
const index = request.columns.findIndex(column => column.id === filter.column);
|
|
487
|
+
if (index < 0)
|
|
488
|
+
return unsupported("RULE_COLUMN_NOT_EXPORTED:" + filter.column);
|
|
489
|
+
const column = request.columns[index], letter = columnName(index + 1 + (grouped ? 1 : 0));
|
|
490
|
+
const reference = "INDEX($" + letter + ":$" + letter + ",ROW())", present = "NOT(ISBLANK(" + reference + "))";
|
|
491
|
+
if (column.kind === "number")
|
|
492
|
+
cellTypes.set(index, "number");
|
|
493
|
+
if (column.kind === "datetime") {
|
|
494
|
+
if (options.datetime !== "typed" || (options.xlsx?.dateMode ?? request.timeZone) !== "utc")
|
|
495
|
+
return unsupported("DATETIME_RULE_REQUIRES_TYPED_UTC");
|
|
496
|
+
cellTypes.set(index, "date");
|
|
497
|
+
}
|
|
498
|
+
if (filter.operator === "isNull" || filter.operator === "isNotNull") {
|
|
499
|
+
if (filter.values !== undefined && filter.values.length)
|
|
500
|
+
return unsupported("UNSUPPORTED_NULL_RULE_OPERANDS");
|
|
501
|
+
return filter.operator === "isNull" ? "ISBLANK(" + reference + ")" : present;
|
|
502
|
+
}
|
|
503
|
+
if (!operation || !Array.isArray(filter.values) || filter.values.length !== 1)
|
|
504
|
+
return unsupported("UNSUPPORTED_RULE_FILTER:" + filter.operator);
|
|
505
|
+
const value = filter.values[0];
|
|
506
|
+
if (typeof value !== "string" && typeof value !== "number" && typeof value !== "boolean")
|
|
507
|
+
throw new TypeError("Canopy rule values must be portable scalars.");
|
|
508
|
+
if (column.kind === "number" || column.kind === "datetime") {
|
|
509
|
+
const operand = column.kind === "number" ? numeric(value) : date(value);
|
|
510
|
+
return "AND(" + present + ",ISNUMBER(" + reference + ")," + reference + operation + String(operand) + ")";
|
|
511
|
+
}
|
|
512
|
+
if (filter.operator !== "eq" && filter.operator !== "ne")
|
|
513
|
+
return unsupported("UNSUPPORTED_TEXT_RULE_COMPARISON");
|
|
514
|
+
// Canopy's Unicode text folding is not the native workbook's comparison contract.
|
|
515
|
+
if (typeof value === "string")
|
|
516
|
+
return unsupported("UNQUALIFIED_NATIVE_TEXT_COMPARISON");
|
|
517
|
+
const kind = typeof value === "boolean" ? "ISLOGICAL" : "ISNUMBER";
|
|
518
|
+
const literal = typeof value === "boolean" ? value ? "TRUE" : "FALSE" : String(numeric(value));
|
|
519
|
+
const sameType = kind + "(" + reference + ")", comparison = reference + operation + literal;
|
|
520
|
+
return filter.operator === "eq" ? "AND(" + present + "," + sameType + "," + comparison + ")"
|
|
521
|
+
: "AND(" + present + ",OR(NOT(" + sameType + ")," + comparison + "))";
|
|
522
|
+
};
|
|
523
|
+
const visit = (input, depth) => {
|
|
524
|
+
if (depth > 4 || ++nodes > 64)
|
|
525
|
+
return unsupported("RULE_PREDICATE_LIMIT");
|
|
526
|
+
if (!input || typeof input !== "object")
|
|
527
|
+
throw new TypeError("Canopy rule predicate must be an object.");
|
|
528
|
+
const captured = captureFields(input, ["operator", "filters", "groups"]);
|
|
529
|
+
if (captured.operator !== "and" && captured.operator !== "or")
|
|
530
|
+
return unsupported("UNSUPPORTED_RULE_BOOLEAN:" + captured.operator);
|
|
531
|
+
const filters = captured.filters ?? [], groups = captured.groups ?? [];
|
|
532
|
+
if (!Array.isArray(filters) || !Array.isArray(groups))
|
|
533
|
+
throw new TypeError("Canopy predicate filters and groups must be arrays.");
|
|
534
|
+
const terms = [];
|
|
535
|
+
for (const filter of filters)
|
|
536
|
+
terms.push(leaf(filter));
|
|
537
|
+
for (const group of groups)
|
|
538
|
+
terms.push(visit(group, depth + 1));
|
|
539
|
+
if (!terms.length)
|
|
540
|
+
return unsupported("EMPTY_RULE_PREDICATE");
|
|
541
|
+
return captured.operator.toUpperCase() + "(" + terms.join(",") + ")";
|
|
542
|
+
};
|
|
543
|
+
const formula = visit(root, 1);
|
|
544
|
+
if (formula.length > 8192)
|
|
545
|
+
return unsupported("RULE_FORMULA_LIMIT");
|
|
546
|
+
return formula;
|
|
547
|
+
}
|
|
548
|
+
const _exports = Object.freeze({ canopyPredicate: canopyPredicate });
|
|
549
|
+
_modules.set("2b0b73e8c376d24e6a5b498c0f710966b00de0eff44f474d7b2aece7af64fa96", _exports);
|
|
550
|
+
return _exports;
|
|
551
|
+
})();
|
|
552
|
+
|
|
553
|
+
const _m19 = _modules.get("eb8cf81d2a340cdb41301d59c667cef44f3ad1d6a19f717eb8137257b545115e") ?? (() => {
|
|
554
|
+
const { captureFields } = _c2;
|
|
555
|
+
|
|
556
|
+
const { canopyPredicate } = _m20;
|
|
557
|
+
|
|
558
|
+
// Stable document palette. Browser CSS variables and resolved cell.format are never interpreted.
|
|
559
|
+
const palette = {
|
|
560
|
+
info: { color: "4472C4", background: "DDEBF7", foreground: "1F4E78" },
|
|
561
|
+
success: { color: "70AD47", background: "E2F0D9", foreground: "375623" },
|
|
562
|
+
warning: { color: "FFC000", background: "FFF2CC", foreground: "9C6500" },
|
|
563
|
+
danger: { color: "C00000", background: "FFC7CE", foreground: "9C0006" }
|
|
564
|
+
};
|
|
565
|
+
class UnsupportedRule extends Error {
|
|
566
|
+
}
|
|
567
|
+
const unsupported = (message) => { throw new UnsupportedRule(message); };
|
|
568
|
+
/** Compile declarations in source order, then emit native target/aspect priorities.
|
|
569
|
+
* Data-column selectors let grouped writers exclude generated headings, subtotals and grand totals. */
|
|
570
|
+
function canopyRules(request, format, grouped, tones, report, options = {}, cellTypes) {
|
|
571
|
+
if (request.formatRules === undefined || format === "csv")
|
|
572
|
+
return [];
|
|
573
|
+
if (!Array.isArray(request.formatRules) || request.formatRules.length > 1000)
|
|
574
|
+
throw new TypeError("Canopy formatRules must be a bounded array of at most 1,000 declarations.");
|
|
575
|
+
const visuals = [], cells = [], rows = [], ids = new Set(), columns = request.columns;
|
|
576
|
+
const inputs = request.formatRules;
|
|
577
|
+
const declarations = inputs.map(input => {
|
|
578
|
+
if (!input || typeof input !== "object")
|
|
579
|
+
throw new TypeError("Canopy rule declarations must be objects.");
|
|
580
|
+
const rule = captureFields(input, ["id", "enabled", "stopIfTrue", "column", "when", "target", "style"]);
|
|
581
|
+
if (typeof rule.id !== "string" || !rule.id || ids.has(rule.id))
|
|
582
|
+
throw new TypeError("Canopy rule IDs must be unique nonempty strings.");
|
|
583
|
+
ids.add(rule.id);
|
|
584
|
+
if (rule.enabled !== undefined && typeof rule.enabled !== "boolean" || rule.stopIfTrue !== undefined && typeof rule.stopIfTrue !== "boolean")
|
|
585
|
+
throw new TypeError("Canopy rule flags must be boolean.");
|
|
586
|
+
const style = rule.style && typeof rule.style === "object" ? captureFields(rule.style, ["tone", "bar", "scale"]) : rule.style;
|
|
587
|
+
return { ...rule, style };
|
|
588
|
+
});
|
|
589
|
+
if (format === "pdf") {
|
|
590
|
+
for (const rule of declarations)
|
|
591
|
+
if (rule.enabled !== false)
|
|
592
|
+
report({ code: "PDF_NATIVE_RULE_NOT_RENDERED:" + rule.id });
|
|
593
|
+
return [];
|
|
594
|
+
}
|
|
595
|
+
const hasStops = declarations.some(rule => rule.enabled !== false && rule.stopIfTrue);
|
|
596
|
+
if (hasStops && declarations.some(rule => rule.enabled !== false && (rule.style?.bar !== undefined || rule.style?.scale !== undefined))) {
|
|
597
|
+
report({ code: "UNSUPPORTED_GLOBAL_STOP_WITH_NATIVE_VISUALS" });
|
|
598
|
+
return [];
|
|
599
|
+
}
|
|
600
|
+
const barColumns = new Set(declarations.filter(rule => rule.enabled !== false && rule.style?.bar !== undefined).map(rule => rule.column));
|
|
601
|
+
const barTone = declarations.find(rule => rule.enabled !== false && rule.target !== "row" && rule.style?.tone !== undefined && rule.column !== undefined && barColumns.has(rule.column));
|
|
602
|
+
if (barTone) {
|
|
603
|
+
// Canopy suppresses a cell tone's fill only where its bar resolves. A single native tone patch cannot express both cases.
|
|
604
|
+
report({ code: "UNSUPPORTED_CELL_TONE_WITH_DATA_BAR", columnId: barTone.column });
|
|
605
|
+
return [];
|
|
606
|
+
}
|
|
607
|
+
const priorStops = [];
|
|
608
|
+
const priorRows = [], priorCells = new Map();
|
|
609
|
+
const requiredCells = new Map();
|
|
610
|
+
const column = (id) => {
|
|
611
|
+
const index = columns.findIndex(column => column.id === id);
|
|
612
|
+
if (index < 0)
|
|
613
|
+
return unsupported("RULE_COLUMN_NOT_EXPORTED:" + id);
|
|
614
|
+
return index;
|
|
615
|
+
};
|
|
616
|
+
const numeric = (id) => {
|
|
617
|
+
if (columns[column(id)].kind !== "number")
|
|
618
|
+
unsupported("RULE_COLUMN_NOT_NUMERIC:" + id);
|
|
619
|
+
};
|
|
620
|
+
const color = (name) => {
|
|
621
|
+
const mapping = tones.get(name), value = mapping?.background ?? mapping?.color ?? palette[name]?.color;
|
|
622
|
+
if (value === undefined)
|
|
623
|
+
return unsupported("UNMAPPED_RULE_TONE:" + name);
|
|
624
|
+
return value;
|
|
625
|
+
};
|
|
626
|
+
const style = (name) => {
|
|
627
|
+
const defaults = palette[name];
|
|
628
|
+
const mapping = tones.get(name) ?? (defaults ? { background: defaults.background, color: defaults.foreground } : undefined);
|
|
629
|
+
if (!mapping)
|
|
630
|
+
return unsupported("UNMAPPED_RULE_TONE:" + name);
|
|
631
|
+
if ("alignment" in mapping || "wrapText" in mapping)
|
|
632
|
+
return unsupported("UNSUPPORTED_RULE_TONE_STYLE:" + name);
|
|
633
|
+
return {
|
|
634
|
+
...("background" in mapping && mapping.background !== undefined ? { fill: { color: mapping.background } } : {}),
|
|
635
|
+
font: { ...(mapping.color === undefined ? {} : { color: mapping.color }),
|
|
636
|
+
...("bold" in mapping && mapping.bold !== undefined ? { bold: mapping.bold } : {}),
|
|
637
|
+
...("italic" in mapping && mapping.italic !== undefined ? { italic: mapping.italic } : {}) },
|
|
638
|
+
...("numberFormat" in mapping && mapping.numberFormat !== undefined ? { numberFormat: mapping.numberFormat } : {})
|
|
639
|
+
};
|
|
640
|
+
};
|
|
641
|
+
for (const rule of declarations) {
|
|
642
|
+
if (rule.enabled === false)
|
|
643
|
+
continue;
|
|
644
|
+
try {
|
|
645
|
+
if (request.values !== "raw")
|
|
646
|
+
unsupported("NATIVE_RULE_REQUIRES_RAW_VALUES");
|
|
647
|
+
if (rule.target === "columns" || "columns" in rule && rule.columns !== undefined)
|
|
648
|
+
unsupported("UNSUPPORTED_RULE_COLUMNS_TARGET");
|
|
649
|
+
if (!rule.style || typeof rule.style !== "object" || Array.isArray(rule.style))
|
|
650
|
+
throw new TypeError("Canopy rule style must be an object.");
|
|
651
|
+
const styleInput = captureFields(rule.style, ["tone", "bar", "scale"]);
|
|
652
|
+
if (Object.keys(styleInput).some(key => !["tone", "bar", "scale"].includes(key)))
|
|
653
|
+
unsupported("UNSUPPORTED_RULE_STYLE");
|
|
654
|
+
const supplied = [styleInput.bar, styleInput.scale, styleInput.tone].filter(value => value !== undefined);
|
|
655
|
+
if (supplied.length !== 1)
|
|
656
|
+
unsupported("UNSUPPORTED_RULE_STYLE_COMBINATION");
|
|
657
|
+
if (styleInput.bar !== undefined) {
|
|
658
|
+
if (rule.column === undefined || rule.when !== undefined || rule.target === "row")
|
|
659
|
+
unsupported("UNSUPPORTED_BAR_TARGET");
|
|
660
|
+
numeric(rule.column);
|
|
661
|
+
if (rule.stopIfTrue)
|
|
662
|
+
unsupported("UNSUPPORTED_BAR_STOP");
|
|
663
|
+
const { minimum, maximum, tone = "info", showValue } = captureFields(styleInput.bar, ["minimum", "maximum", "tone", "showValue"]);
|
|
664
|
+
if (minimum === undefined || maximum === undefined)
|
|
665
|
+
return unsupported("UNBOUNDED_CANOPY_BAR");
|
|
666
|
+
if (!Number.isFinite(minimum) || !Number.isFinite(maximum) || maximum <= minimum)
|
|
667
|
+
throw new TypeError("Canopy bar bounds must be finite and increasing.");
|
|
668
|
+
visuals.push({ type: "dataBar", range: { column: rule.column }, color: color(tone),
|
|
669
|
+
minimum: { type: "number", value: minimum }, maximum: { type: "number", value: maximum }, ...(showValue === undefined ? {} : { showValue }) });
|
|
670
|
+
requiredCells.set(column(rule.column), "number");
|
|
671
|
+
}
|
|
672
|
+
else if (styleInput.scale !== undefined) {
|
|
673
|
+
if (rule.stopIfTrue)
|
|
674
|
+
unsupported("UNSUPPORTED_SCALE_STOP");
|
|
675
|
+
if (rule.column === undefined || rule.when !== undefined || rule.target === "row")
|
|
676
|
+
unsupported("UNSUPPORTED_SCALE_TARGET");
|
|
677
|
+
numeric(rule.column);
|
|
678
|
+
const { stops } = captureFields(styleInput.scale, ["stops"]);
|
|
679
|
+
if (!Array.isArray(stops) || stops.length < 2 || stops.length > 3)
|
|
680
|
+
unsupported("UNSUPPORTED_SCALE_STOPS");
|
|
681
|
+
const mapped = stops.map((input) => {
|
|
682
|
+
const stop = captureFields(input, ["type", "value", "tone"]);
|
|
683
|
+
if (!["min", "max", "number", "percent", "percentile"].includes(stop.type))
|
|
684
|
+
unsupported("UNSUPPORTED_SCALE_THRESHOLD:" + stop.type);
|
|
685
|
+
const threshold = stop.type === "min" || stop.type === "max" ? { type: stop.type }
|
|
686
|
+
: { type: stop.type, value: stop.value };
|
|
687
|
+
return { threshold, color: color(stop.tone) };
|
|
688
|
+
});
|
|
689
|
+
visuals.push({ type: "colorScale", range: { column: rule.column },
|
|
690
|
+
stops: mapped });
|
|
691
|
+
requiredCells.set(column(rule.column), "number");
|
|
692
|
+
}
|
|
693
|
+
else {
|
|
694
|
+
if (rule.when === undefined || styleInput.tone === undefined || rule.target !== "row" && rule.column === undefined)
|
|
695
|
+
unsupported("UNSUPPORTED_HIGHLIGHT_TARGET");
|
|
696
|
+
if (rule.target !== undefined && rule.target !== "row" && rule.target !== "cell")
|
|
697
|
+
unsupported("UNSUPPORTED_RULE_TARGET");
|
|
698
|
+
const range = rule.target === "row" ? { column: columns[0].id, through: columns.at(-1).id } : { column: rule.column };
|
|
699
|
+
if (rule.column !== undefined)
|
|
700
|
+
column(rule.column);
|
|
701
|
+
const ruleCells = new Map();
|
|
702
|
+
const ownPredicate = canopyPredicate(request, grouped, options, rule.when, unsupported, ruleCells);
|
|
703
|
+
const reachable = priorStops.length ? "AND(" + ownPredicate + ",NOT(OR(" + priorStops.join(",") + ")))" : ownPredicate;
|
|
704
|
+
const previous = rule.target === "row" ? priorRows : priorCells.get(rule.column) ?? [];
|
|
705
|
+
const formula = previous.length ? "AND(" + reachable + ",NOT(OR(" + previous.join(",") + ")))" : reachable;
|
|
706
|
+
if (formula.length > 8192)
|
|
707
|
+
unsupported("RULE_FORMULA_LIMIT");
|
|
708
|
+
(rule.target === "row" ? rows : cells).push({ type: "expression", range, formula, style: style(styleInput.tone) });
|
|
709
|
+
previous.push(ownPredicate);
|
|
710
|
+
if (rule.target !== "row")
|
|
711
|
+
priorCells.set(rule.column, previous);
|
|
712
|
+
for (const [column, type] of ruleCells)
|
|
713
|
+
requiredCells.set(column, type);
|
|
714
|
+
// A matched declaration still stops the row when an earlier tone on that target already won.
|
|
715
|
+
if (rule.stopIfTrue)
|
|
716
|
+
priorStops.push(ownPredicate);
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
catch (error) {
|
|
720
|
+
if (!(error instanceof UnsupportedRule))
|
|
721
|
+
throw error;
|
|
722
|
+
report({ code: error.message + ":" + rule.id, ...(rule.column === undefined ? {} : { columnId: rule.column }) });
|
|
723
|
+
if (hasStops)
|
|
724
|
+
return []; // A partial sequence cannot claim to preserve its row-global stopping behavior.
|
|
725
|
+
}
|
|
726
|
+
}
|
|
727
|
+
for (const [column, type] of requiredCells)
|
|
728
|
+
cellTypes?.set(column, type);
|
|
729
|
+
// Canopy paints cell visuals/tones over the row tint. Build masks before changing native priority order.
|
|
730
|
+
return Object.freeze([...visuals, ...cells, ...rows]);
|
|
731
|
+
}
|
|
732
|
+
const _exports = Object.freeze({ canopyRules: canopyRules });
|
|
733
|
+
_modules.set("eb8cf81d2a340cdb41301d59c667cef44f3ad1d6a19f717eb8137257b545115e", _exports);
|
|
734
|
+
return _exports;
|
|
735
|
+
})();
|
|
736
|
+
|
|
737
|
+
const _m22 = _modules.get("97b7bd3037e8060328387470a7e471b6933f1fa062e9562c7908f8ea9a29044b") ?? (() => {
|
|
738
|
+
const { createGroupedReport } = _c13;
|
|
739
|
+
|
|
740
|
+
const { checkAbort } = _c14;
|
|
741
|
+
|
|
742
|
+
const { createTotals } = _c15;
|
|
743
|
+
|
|
744
|
+
const { captureFields } = _c2;
|
|
745
|
+
|
|
746
|
+
const { datetime } = _m15;
|
|
747
|
+
|
|
748
|
+
const { canopyIdentityValue } = _m13;
|
|
749
|
+
|
|
750
|
+
const identity = (value) => value instanceof Date ? "date:" + value.getTime() : typeof value + ":" + String(value);
|
|
751
|
+
const scalar = canopyIdentityValue;
|
|
752
|
+
/** Validate captured ranges, then use the owned grouping factory and its existing writers.
|
|
753
|
+
* Only ranges, labels and at most four active aggregate vectors are retained; no detail body is buffered. */
|
|
754
|
+
function canopyGrouped(source, request, options, limits, report, format) {
|
|
755
|
+
const input = request.grouping;
|
|
756
|
+
if (input === undefined)
|
|
757
|
+
return undefined; // query.groupBy never manufactures a group snapshot.
|
|
758
|
+
if (request.values !== "raw") {
|
|
759
|
+
report({ code: "GROUPING_REQUIRES_RAW_VALUES" });
|
|
760
|
+
return undefined;
|
|
761
|
+
}
|
|
762
|
+
if (source.rowCount === null)
|
|
763
|
+
throw new TypeError("Captured grouping requires its exact scope recordCount.");
|
|
764
|
+
const grouping = captureFields(input, ["levels", "aggregates", "totals", "groups"]);
|
|
765
|
+
if (!Array.isArray(grouping.levels) || grouping.levels.length < 1 || grouping.levels.length > 4 || !Array.isArray(grouping.aggregates) || !Array.isArray(grouping.groups))
|
|
766
|
+
throw new TypeError("Canopy grouping needs one through four levels, aggregates and ordered groups.");
|
|
767
|
+
const levels = grouping.levels.map(level => Object.freeze(captureFields(level, ["column", "direction", "title"])));
|
|
768
|
+
if (levels.some(level => typeof level.column !== "string" || !level.column || level.direction !== "asc" && level.direction !== "desc") ||
|
|
769
|
+
new Set(levels.map(level => level.column)).size !== levels.length)
|
|
770
|
+
throw new TypeError("Canopy grouping levels need unique stable columns and directions.");
|
|
771
|
+
const declarations = grouping.aggregates.map(aggregate => Object.freeze(captureFields(aggregate, ["id", "column", "operation", "label"])));
|
|
772
|
+
const ids = new Set(), totals = Object.create(null);
|
|
773
|
+
const operations = { sum: "sum", count: "count", average: "average", minimum: "min", maximum: "max" };
|
|
774
|
+
for (const aggregate of declarations) {
|
|
775
|
+
if (typeof aggregate.id !== "string" || !aggregate.id || ids.has(aggregate.id))
|
|
776
|
+
throw new TypeError("Canopy aggregate IDs must be unique nonempty strings.");
|
|
777
|
+
ids.add(aggregate.id);
|
|
778
|
+
const column = source.columns.find(column => column.key === aggregate.column);
|
|
779
|
+
if (!column || column.type !== "number")
|
|
780
|
+
throw new TypeError("Canopy aggregate declarations require an exported raw numeric column.");
|
|
781
|
+
if (Object.hasOwn(totals, aggregate.column))
|
|
782
|
+
throw new TypeError("The grouped report supports one aggregate operation per column.");
|
|
783
|
+
const operation = operations[aggregate.operation];
|
|
784
|
+
if (operation === undefined) {
|
|
785
|
+
report({ code: "UNSUPPORTED_GROUP_AGGREGATE:" + aggregate.operation, columnId: aggregate.column });
|
|
786
|
+
return undefined;
|
|
787
|
+
}
|
|
788
|
+
totals[aggregate.column] = operation;
|
|
789
|
+
}
|
|
790
|
+
// Reuse the canonical operation validator rather than implementing aggregate semantics here.
|
|
791
|
+
createTotals(source.columns, totals);
|
|
792
|
+
const expected = (input) => {
|
|
793
|
+
if (!input || typeof input !== "object" || Array.isArray(input))
|
|
794
|
+
throw new TypeError("Canopy aggregate values must be an ID-keyed object.");
|
|
795
|
+
const snapshot = { ...input };
|
|
796
|
+
if (Object.keys(snapshot).some(key => !ids.has(key)) || declarations.some(aggregate => !Object.hasOwn(snapshot, aggregate.id)))
|
|
797
|
+
throw new TypeError("Canopy aggregate values must reference exactly the captured declarations.");
|
|
798
|
+
for (const value of Object.values(snapshot))
|
|
799
|
+
if (value !== null && (typeof value !== "number" || !Number.isFinite(value)))
|
|
800
|
+
throw new TypeError("Canopy aggregate values must be finite numbers or null.");
|
|
801
|
+
return Object.freeze(snapshot);
|
|
802
|
+
};
|
|
803
|
+
const grandExpected = expected(grouping.totals), byDepth = levels.map(() => []), labels = levels.map(() => new Map());
|
|
804
|
+
let groups = 0, characters = 0;
|
|
805
|
+
const ranges = (inputs, offset, end, depth) => {
|
|
806
|
+
if (!Array.isArray(inputs))
|
|
807
|
+
throw new TypeError("Canopy groups must be ordered arrays.");
|
|
808
|
+
let cursor = offset;
|
|
809
|
+
const keys = new Set(), values = new Set();
|
|
810
|
+
for (const input of inputs) {
|
|
811
|
+
const group = captureFields(input, ["key", "value", "text", "offset", "count", "aggregates", "groups"]);
|
|
812
|
+
if (!group || typeof group.key !== "string" || keys.has(group.key) || !Number.isSafeInteger(group.offset) || !Number.isSafeInteger(group.count) ||
|
|
813
|
+
group.count <= 0 || group.offset !== cursor || group.count > end - group.offset)
|
|
814
|
+
throw new TypeError("Canopy group ranges must be nonempty contiguous half-open partitions within their parent.");
|
|
815
|
+
if (group.value !== null && !["string", "number", "boolean"].includes(typeof group.value) ||
|
|
816
|
+
typeof group.value === "number" && !Number.isFinite(group.value))
|
|
817
|
+
throw new TypeError("Canopy group values must be portable finite scalars.");
|
|
818
|
+
const dateColumn = request.columns.find(column => column.id === levels[depth].column)?.kind === "datetime";
|
|
819
|
+
const value = format === "xlsx" && dateColumn && typeof group.value === "string"
|
|
820
|
+
? datetime(group.value, options.datetime ?? "preserve", options.xlsx?.dateMode ?? request.timeZone) : group.value;
|
|
821
|
+
const key = identity(value), text = group.text ?? String(group.value ?? "");
|
|
822
|
+
if (typeof text !== "string" || values.has(key))
|
|
823
|
+
throw new TypeError("A Canopy group key cannot recur within the same parent.");
|
|
824
|
+
const previousLabel = labels[depth].get(key);
|
|
825
|
+
if (previousLabel !== undefined && previousLabel !== text)
|
|
826
|
+
throw new TypeError("The same grouping value needs consistent captured text at one level.");
|
|
827
|
+
labels[depth].set(key, text);
|
|
828
|
+
keys.add(group.key);
|
|
829
|
+
values.add(key);
|
|
830
|
+
if (++groups > 1000 || (characters += group.key.length + key.length + text.length) > 1000000)
|
|
831
|
+
throw new RangeError("Canopy group metadata exceeds the existing bounded report profile.");
|
|
832
|
+
const next = group.offset + group.count;
|
|
833
|
+
byDepth[depth].push(Object.freeze({ offset: group.offset, end: next, value, text, expected: expected(group.aggregates) }));
|
|
834
|
+
if (depth + 1 < levels.length)
|
|
835
|
+
ranges(group.groups ?? [], group.offset, next, depth + 1);
|
|
836
|
+
else if (group.groups !== undefined && group.groups.length)
|
|
837
|
+
throw new TypeError("Canopy nested groups exceed their declared levels.");
|
|
838
|
+
cursor = next;
|
|
839
|
+
}
|
|
840
|
+
if (cursor !== end)
|
|
841
|
+
throw new TypeError("Canopy grouping does not cover its complete exported detail range.");
|
|
842
|
+
};
|
|
843
|
+
ranges(grouping.groups, 0, source.rowCount, 0);
|
|
844
|
+
// Validate the producer's wire arithmetic separately from the grouped writer's native formula caches.
|
|
845
|
+
// Canopy sum/average use compensated accumulation and return null without numeric inputs.
|
|
846
|
+
const wireTotals = () => {
|
|
847
|
+
const ordinary = createTotals(source.columns, totals), sums = source.columns.map(() => 0), corrections = source.columns.map(() => 0), counts = source.columns.map(() => 0);
|
|
848
|
+
return {
|
|
849
|
+
accept(values) {
|
|
850
|
+
for (let index = 0; index < values.length; index++) {
|
|
851
|
+
const value = scalar(values[index]), operation = totals[source.columns[index].key];
|
|
852
|
+
if (operation !== "sum" && operation !== "average") {
|
|
853
|
+
ordinary[index].accept(value);
|
|
854
|
+
continue;
|
|
855
|
+
}
|
|
856
|
+
if (typeof value !== "number" || !Number.isFinite(value))
|
|
857
|
+
continue;
|
|
858
|
+
counts[index] = counts[index] + 1;
|
|
859
|
+
const next = value - corrections[index], total = sums[index] + next;
|
|
860
|
+
corrections[index] = total - sums[index] - next;
|
|
861
|
+
sums[index] = total;
|
|
862
|
+
}
|
|
863
|
+
},
|
|
864
|
+
value(index) {
|
|
865
|
+
const operation = totals[source.columns[index].key];
|
|
866
|
+
return operation === "sum" || operation === "average" ? !counts[index] ? null
|
|
867
|
+
: operation === "sum" ? sums[index] : sums[index] / counts[index] : ordinary[index].value();
|
|
868
|
+
}
|
|
869
|
+
};
|
|
870
|
+
};
|
|
871
|
+
const indexes = levels.map(() => 0), active = levels.map(() => undefined);
|
|
872
|
+
const at = (depth, row) => {
|
|
873
|
+
const list = byDepth[depth];
|
|
874
|
+
while (list[indexes[depth]] && list[indexes[depth]].end <= row)
|
|
875
|
+
indexes[depth] = indexes[depth] + 1;
|
|
876
|
+
const range = list[indexes[depth]];
|
|
877
|
+
if (!range || row < range.offset || row >= range.end)
|
|
878
|
+
throw new TypeError("A detail row is outside its captured Canopy grouping.");
|
|
879
|
+
return range;
|
|
880
|
+
};
|
|
881
|
+
const verify = (actual, expected) => {
|
|
882
|
+
for (const declaration of declarations) {
|
|
883
|
+
const position = source.columns.findIndex(column => column.key === declaration.column), observed = actual.value(position), declared = expected[declaration.id];
|
|
884
|
+
// Exact producer-wire comparison retains wrong-scope rejection without rounding native caches or applying an epsilon.
|
|
885
|
+
if (observed !== declared)
|
|
886
|
+
throw new TypeError("Canopy captured aggregate differs from its consumed rows: " + declaration.id + ".");
|
|
887
|
+
}
|
|
888
|
+
};
|
|
889
|
+
const same = (actual, expected) => actual instanceof Date && expected instanceof Date
|
|
890
|
+
? actual.getTime() === expected.getTime() : actual === expected;
|
|
891
|
+
async function* rows() {
|
|
892
|
+
let index = 0;
|
|
893
|
+
const grand = wireTotals();
|
|
894
|
+
for await (const values of source.rows()) {
|
|
895
|
+
checkAbort(options.signal);
|
|
896
|
+
for (let depth = 0; depth < levels.length; depth++) {
|
|
897
|
+
const range = at(depth, index), column = source.columns.findIndex(column => column.key === levels[depth].column);
|
|
898
|
+
if (column >= 0 && !same(scalar(values[column]), range.value))
|
|
899
|
+
throw new TypeError("Canopy detail value disagrees with its captured group range.");
|
|
900
|
+
if (range.offset === index)
|
|
901
|
+
active[depth] = { range, aggregates: wireTotals() };
|
|
902
|
+
}
|
|
903
|
+
grand.accept(values);
|
|
904
|
+
for (const group of active)
|
|
905
|
+
group.aggregates.accept(values);
|
|
906
|
+
yield values;
|
|
907
|
+
index++;
|
|
908
|
+
for (let depth = levels.length - 1; depth >= 0; depth--) {
|
|
909
|
+
const group = active[depth];
|
|
910
|
+
if (group.range.end === index) {
|
|
911
|
+
verify(group.aggregates, group.range.expected);
|
|
912
|
+
active[depth] = undefined;
|
|
913
|
+
}
|
|
914
|
+
}
|
|
915
|
+
}
|
|
916
|
+
verify(grand, grandExpected);
|
|
917
|
+
}
|
|
918
|
+
// The factory's hidden fields keep raw group identity separate from projected
|
|
919
|
+
// detail labels. Never override a declared output column's value getter.
|
|
920
|
+
const groupKeys = new Set([...source.columns.map(column => column.key), ...levels.map(level => level.column)]);
|
|
921
|
+
const groupBy = levels.map((level, depth) => {
|
|
922
|
+
const column = source.columns.findIndex(column => column.key === level.column);
|
|
923
|
+
let key = level.column;
|
|
924
|
+
if (column >= 0) {
|
|
925
|
+
do {
|
|
926
|
+
key += "#raw";
|
|
927
|
+
} while (groupKeys.has(key));
|
|
928
|
+
groupKeys.add(key);
|
|
929
|
+
}
|
|
930
|
+
return { key,
|
|
931
|
+
value: (row, context) => column < 0 ? at(depth, context.rowIndex).value : scalar(row[column]),
|
|
932
|
+
label: (value) => labels[depth].get(identity(value)) ?? String(value ?? "") };
|
|
933
|
+
});
|
|
934
|
+
const sourceLimits = limits === undefined ? undefined : {
|
|
935
|
+
...(limits.maxRows === undefined ? {} : { maxRows: limits.maxRows }),
|
|
936
|
+
...(limits.maxCells === undefined ? {} : { maxCells: limits.maxCells }),
|
|
937
|
+
...(limits.maxTextCharacters === undefined ? {} : { maxTextCharacters: limits.maxTextCharacters })
|
|
938
|
+
};
|
|
939
|
+
return createGroupedReport(rows(), { columns: source.columns, groupBy, totals,
|
|
940
|
+
...(options.signal === undefined ? {} : { signal: options.signal }), ...(sourceLimits === undefined ? {} : { limits: sourceLimits }) });
|
|
941
|
+
}
|
|
942
|
+
const _exports = Object.freeze({ canopyGrouped: canopyGrouped });
|
|
943
|
+
_modules.set("97b7bd3037e8060328387470a7e471b6933f1fa062e9562c7908f8ea9a29044b", _exports);
|
|
944
|
+
return _exports;
|
|
945
|
+
})();
|
|
946
|
+
|
|
947
|
+
const _m26 = _modules.get("99b23f94e240ecbeee81dbc96909e40786623c7df225f74ae7bd4d719b15d1e8") ?? (() => {
|
|
948
|
+
const { cellText } = _c12;
|
|
949
|
+
|
|
950
|
+
const { cleanXml } = _c16;
|
|
951
|
+
|
|
952
|
+
/** Snapshot optional About metadata before enumeration. The accepted query is serialized, never evaluated. */
|
|
953
|
+
function canopyAbout(request, options) {
|
|
954
|
+
const result = [["revision", request.revision], ["recordCount", request.recordCount === null ? "unknown" : request.recordCount]];
|
|
955
|
+
if (request.scope !== undefined) {
|
|
956
|
+
if (!["filtered", "visible", "selected", "all"].includes(request.scope))
|
|
957
|
+
throw new TypeError("Invalid Canopy export scope.");
|
|
958
|
+
result.push(["scope", request.scope]);
|
|
959
|
+
}
|
|
960
|
+
for (const key of ["total", "matched"])
|
|
961
|
+
if (request[key] !== undefined) {
|
|
962
|
+
const value = request[key];
|
|
963
|
+
if (value === null) {
|
|
964
|
+
result.push([key, "unknown"]);
|
|
965
|
+
continue;
|
|
966
|
+
}
|
|
967
|
+
if (!Number.isSafeInteger(value) || value < 0)
|
|
968
|
+
throw new TypeError("Canopy metadata counts must be nonnegative safe integers.");
|
|
969
|
+
result.push([key, value]);
|
|
970
|
+
}
|
|
971
|
+
if (request.generatedAt !== undefined) {
|
|
972
|
+
if (typeof request.generatedAt !== "string" || !/^\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d(?:\.\d{1,9})?Z$/.test(request.generatedAt) || !Number.isFinite(new Date(request.generatedAt).getTime()))
|
|
973
|
+
throw new TypeError("Canopy generatedAt must be a captured UTC ISO instant.");
|
|
974
|
+
result.push(["generatedAt", request.generatedAt]);
|
|
975
|
+
}
|
|
976
|
+
if (request.selection !== undefined) {
|
|
977
|
+
if (!Array.isArray(request.selection) || request.selection.some(id => typeof id !== "string"))
|
|
978
|
+
throw new TypeError("Canopy selection metadata must contain stable string IDs.");
|
|
979
|
+
result.push(["selection", JSON.stringify(request.selection)]);
|
|
980
|
+
}
|
|
981
|
+
if (request.query !== undefined) {
|
|
982
|
+
if (!request.query || typeof request.query !== "object" || Array.isArray(request.query))
|
|
983
|
+
throw new TypeError("Canopy accepted query must be a captured object.");
|
|
984
|
+
const query = JSON.stringify(request.query);
|
|
985
|
+
if (typeof query !== "string")
|
|
986
|
+
throw new TypeError("Canopy accepted query must serialize as JSON metadata.");
|
|
987
|
+
result.push(["query", query]);
|
|
988
|
+
}
|
|
989
|
+
if (result.reduce((sum, row) => sum + row[0].length + String(row[1]).length, 0) > 65536)
|
|
990
|
+
throw new RangeError("Canopy About metadata exceeds 65,536 captured characters.");
|
|
991
|
+
// Validate known cell text before consuming details; overflow preservation and XML policy stay workbook-owned.
|
|
992
|
+
for (const [field, value] of result) {
|
|
993
|
+
cellText(field, options.invalidCharacterPolicy);
|
|
994
|
+
if (options.oversizedText === "preserve")
|
|
995
|
+
cleanXml(value, options.invalidCharacterPolicy);
|
|
996
|
+
else
|
|
997
|
+
cellText(value, options.invalidCharacterPolicy);
|
|
998
|
+
}
|
|
999
|
+
return Object.freeze(result.map(row => Object.freeze(row)));
|
|
1000
|
+
}
|
|
1001
|
+
const _exports = Object.freeze({ canopyAbout: canopyAbout });
|
|
1002
|
+
_modules.set("99b23f94e240ecbeee81dbc96909e40786623c7df225f74ae7bd4d719b15d1e8", _exports);
|
|
1003
|
+
return _exports;
|
|
1004
|
+
})();
|
|
1005
|
+
|
|
1006
|
+
const _m28 = _modules.get("ccfefc97a47cc288f2c9a2eed33fff323570e35193cedbd876ebb3e8fb78a42e") ?? (() => {
|
|
1007
|
+
const { Workbook, addGroupedXlsx } = _c7;
|
|
1008
|
+
|
|
1009
|
+
const { portableWorkbook } = _c17;
|
|
1010
|
+
|
|
1011
|
+
const { withDestination } = _c18;
|
|
1012
|
+
|
|
1013
|
+
/** Compose only the adapter's data/grouped sheet and optional metadata sheet in the existing workbook owner. */
|
|
1014
|
+
async function writeCanopyWorkbook(source, grouped, destination, options, labels, about) {
|
|
1015
|
+
const { sheet: sheetSettings = {}, columns: _columns, ...settings } = options;
|
|
1016
|
+
const { name = "Data", ...sheet } = sheetSettings;
|
|
1017
|
+
if (about && name.toLowerCase() === "about")
|
|
1018
|
+
throw new TypeError("The optional About worksheet needs a distinct data-sheet name.");
|
|
1019
|
+
if (grouped && settings.cellValueWriters !== undefined)
|
|
1020
|
+
throw new TypeError("Grouped Canopy exports use resolved source values rather than custom cellValueWriters.");
|
|
1021
|
+
return withDestination(destination, async (sink) => {
|
|
1022
|
+
const workbookOptions = { ...portableWorkbook(settings), sink };
|
|
1023
|
+
// Grouped worksheets generate native FormulaCells; flat tables keep the portable-value boundary.
|
|
1024
|
+
const book = grouped ? new Workbook(workbookOptions) : Workbook.forTable(workbookOptions);
|
|
1025
|
+
try {
|
|
1026
|
+
let rows, columns;
|
|
1027
|
+
if (grouped) {
|
|
1028
|
+
const { conditionalFormats, ...groupedSheet } = sheet;
|
|
1029
|
+
const written = await addGroupedXlsx(book, grouped, {
|
|
1030
|
+
labelColumn: { header: labels?.labelColumn?.header ?? "Group", width: 18 },
|
|
1031
|
+
subtotalLabel: labels?.subtotalLabel ?? (group => group.label + " total"),
|
|
1032
|
+
grandTotalLabel: labels?.grandTotalLabel ?? (() => "Grand total"),
|
|
1033
|
+
...(labels?.includeGrandTotal === undefined ? {} : { includeGrandTotal: labels.includeGrandTotal }),
|
|
1034
|
+
sheet: { ...groupedSheet, name }, ...(conditionalFormats === undefined ? {} : { conditionalFormats })
|
|
1035
|
+
});
|
|
1036
|
+
rows = written.rows;
|
|
1037
|
+
columns = written.columns;
|
|
1038
|
+
}
|
|
1039
|
+
else {
|
|
1040
|
+
const data = book.addWorksheet(name, { boldHeader: true, autoFilter: sheet.includeHeader !== false,
|
|
1041
|
+
autoSize: { minWidth: 6, maxWidth: 54 }, ...sheet, columns: source.columns });
|
|
1042
|
+
await data.addRows(source.rows());
|
|
1043
|
+
await data.close();
|
|
1044
|
+
rows = data.rowCount;
|
|
1045
|
+
columns = source.columns.length;
|
|
1046
|
+
}
|
|
1047
|
+
if (about) {
|
|
1048
|
+
const metadata = book.addWorksheet("About", { columns: [{ header: "Field", width: 18 }, { header: "Value", width: 72, wrapText: true }],
|
|
1049
|
+
boldHeader: true, freezeHeader: true });
|
|
1050
|
+
await metadata.addRows(about);
|
|
1051
|
+
await metadata.close();
|
|
1052
|
+
}
|
|
1053
|
+
const result = await book.finish();
|
|
1054
|
+
return { rows, columns, bytes: result.bytes };
|
|
1055
|
+
}
|
|
1056
|
+
catch (error) {
|
|
1057
|
+
await book.discard(error);
|
|
1058
|
+
throw error;
|
|
1059
|
+
}
|
|
1060
|
+
});
|
|
1061
|
+
}
|
|
1062
|
+
const _exports = Object.freeze({ writeCanopyWorkbook: writeCanopyWorkbook });
|
|
1063
|
+
_modules.set("ccfefc97a47cc288f2c9a2eed33fff323570e35193cedbd876ebb3e8fb78a42e", _exports);
|
|
1064
|
+
return _exports;
|
|
1065
|
+
})();
|
|
1066
|
+
|
|
1067
|
+
const _m34 = _modules.get("a0c020124a53cd7be15e3d53388b8393c981c3abc0f8d4aee76a442a2458457f") ?? (() => {
|
|
1068
|
+
const { ExportCell } = _c0;
|
|
1069
|
+
|
|
1070
|
+
/** Fixed numeric formats affect PDF text, not the frozen numeric value used by other writers. */
|
|
1071
|
+
function numericProfile(format) {
|
|
1072
|
+
// No declared precision: whole values (including counts) stay whole.
|
|
1073
|
+
if (format === undefined || format === "General")
|
|
1074
|
+
return { minimumFractionDigits: 0, maximumFractionDigits: 20,
|
|
1075
|
+
percent: false, grouping: false, prefix: "", suffix: "" };
|
|
1076
|
+
const match = /^((?:"[^"]*"|\\["%])*)(#,##)?0(?:\.([0#]+))?(%)?((?:"[^"]*"|\\["%])*)$/.exec(format);
|
|
1077
|
+
if (!match || (match[3]?.length ?? 0) > 10)
|
|
1078
|
+
return undefined;
|
|
1079
|
+
const literal = (text) => text.replace(/"([^"]*)"|\\(["%])/g, (_, quoted, escaped) => quoted ?? escaped);
|
|
1080
|
+
return { minimumFractionDigits: (match[3]?.match(/0/g) ?? []).length, maximumFractionDigits: match[3]?.length ?? 0,
|
|
1081
|
+
percent: !!match[4], grouping: !!match[2], prefix: literal(match[1]), suffix: literal(match[5]) };
|
|
1082
|
+
}
|
|
1083
|
+
/** Separate declared literal units before recognizing the captured numeric token. U+2212 MINUS SIGN counts as a
|
|
1084
|
+
* sign like "-": the number is re-rendered with Intl's sign, so it never becomes a literal prefix. */
|
|
1085
|
+
function capturedNumber(text, profile) {
|
|
1086
|
+
let body = text, signBeforePrefix = false;
|
|
1087
|
+
if (profile.prefix && body.startsWith(profile.prefix))
|
|
1088
|
+
body = body.slice(profile.prefix.length);
|
|
1089
|
+
else if (profile.prefix && /^[+\-\u2212]/.test(body) && body.slice(1).startsWith(profile.prefix)) {
|
|
1090
|
+
signBeforePrefix = true;
|
|
1091
|
+
body = body[0] + body.slice(1 + profile.prefix.length);
|
|
1092
|
+
}
|
|
1093
|
+
if (profile.suffix && body.endsWith(profile.suffix))
|
|
1094
|
+
body = body.slice(0, -profile.suffix.length);
|
|
1095
|
+
const match = /^([^0-9+\-\u2212]*)([+\-\u2212]?\d[\d., \u00a0\u202f]*?)([^0-9]*)$/.exec(body);
|
|
1096
|
+
return match ? { prefix: profile.prefix || match[1], number: match[2], suffix: profile.suffix || match[3], signBeforePrefix } : undefined;
|
|
1097
|
+
}
|
|
1098
|
+
/** Distinguish a captured thousands mark from a decimal, using the raw value. */
|
|
1099
|
+
function groupedInteger(numeric, value) {
|
|
1100
|
+
if (!/^[+\-\u2212]?\d{1,3}(?:,\d{3})+$/.test(numeric) && !/^[+\-\u2212]?\d{1,3}(?:\.\d{3})+$/.test(numeric))
|
|
1101
|
+
return false;
|
|
1102
|
+
const grouped = Number(numeric.replace(/[.,]/g, "").replace("\u2212", "-"));
|
|
1103
|
+
return grouped !== 0 && Math.abs(grouped - value) <= .5;
|
|
1104
|
+
}
|
|
1105
|
+
/** Choose once for the document; percent text is the strongest captured culture signal. */
|
|
1106
|
+
function documentDecimal(sample, columns) {
|
|
1107
|
+
let fallback;
|
|
1108
|
+
for (const percent of [true, false]) {
|
|
1109
|
+
for (const row of sample)
|
|
1110
|
+
for (let index = 0; index < columns.length; index++) {
|
|
1111
|
+
const cell = row[index], column = columns[index];
|
|
1112
|
+
if (!(cell instanceof ExportCell) || typeof cell.value !== "number")
|
|
1113
|
+
continue;
|
|
1114
|
+
const profile = numericProfile(cell.presentation?.numberFormat ?? column.format);
|
|
1115
|
+
if (!profile)
|
|
1116
|
+
continue;
|
|
1117
|
+
const captured = capturedNumber(cell.text ?? "", profile);
|
|
1118
|
+
if (!captured)
|
|
1119
|
+
continue;
|
|
1120
|
+
// A literal percent label is a culture signal without requesting numeric scaling.
|
|
1121
|
+
const percentageSignal = profile.percent || profile.prefix.includes("%") || profile.suffix.includes("%") || (cell.text ?? "").includes("%");
|
|
1122
|
+
if (percentageSignal !== percent)
|
|
1123
|
+
continue;
|
|
1124
|
+
const match = /([.,])(\d+)$/.exec(captured.number.trimEnd());
|
|
1125
|
+
if (match) {
|
|
1126
|
+
const numeric = captured.number;
|
|
1127
|
+
// An override changes output scaling/precision, not the captured label.
|
|
1128
|
+
if (groupedInteger(numeric, cell.value) || (percentageSignal && groupedInteger(numeric, cell.value * 100))) {
|
|
1129
|
+
fallback = match[1] === "," ? "." : ",";
|
|
1130
|
+
continue;
|
|
1131
|
+
}
|
|
1132
|
+
return match[1];
|
|
1133
|
+
}
|
|
1134
|
+
}
|
|
1135
|
+
if (fallback !== undefined)
|
|
1136
|
+
return fallback;
|
|
1137
|
+
}
|
|
1138
|
+
return ".";
|
|
1139
|
+
}
|
|
1140
|
+
/** Apply one captured numeric convention to every supported numeric cell, including later streamed rows. */
|
|
1141
|
+
function canopyPdfNumbers(sample, columns) {
|
|
1142
|
+
const formatters = new Map(), decimal = documentDecimal(sample, columns);
|
|
1143
|
+
return row => row.map((value, index) => {
|
|
1144
|
+
if (!(value instanceof ExportCell) || typeof value.value !== "number")
|
|
1145
|
+
return value;
|
|
1146
|
+
const format = value.presentation?.numberFormat ?? columns[index].format;
|
|
1147
|
+
let profile = numericProfile(format);
|
|
1148
|
+
if (!profile || value.text === "")
|
|
1149
|
+
return value;
|
|
1150
|
+
const captured = capturedNumber(value.text ?? "", profile);
|
|
1151
|
+
if (value.text && !captured)
|
|
1152
|
+
return value;
|
|
1153
|
+
// Undeclared formats normalize only plain numeric labels; a decoration
|
|
1154
|
+
// alone does not declare how the raw value was transformed for display.
|
|
1155
|
+
if ((format === undefined || format === "General") && captured && (captured.prefix.trim() || captured.suffix.trim()))
|
|
1156
|
+
return value;
|
|
1157
|
+
if (format === undefined || format === "General") {
|
|
1158
|
+
const digits = Number.isInteger(value.value) || (captured && groupedInteger(captured.number, value.value)) ? 0 :
|
|
1159
|
+
captured ? /[.,](\d+)$/.exec(captured.number.trimEnd())?.[1]?.length ?? 0 : undefined;
|
|
1160
|
+
// Retain a fractional value's captured precision, without padding an
|
|
1161
|
+
// undeclared whole aggregate merely because its display text was padded.
|
|
1162
|
+
if (digits !== undefined && digits <= 20)
|
|
1163
|
+
profile = { ...profile, minimumFractionDigits: digits, maximumFractionDigits: digits };
|
|
1164
|
+
}
|
|
1165
|
+
const key = [profile.minimumFractionDigits, profile.maximumFractionDigits, profile.grouping].join(":");
|
|
1166
|
+
let formatter = formatters.get(key);
|
|
1167
|
+
if (!formatter) {
|
|
1168
|
+
formatter = new Intl.NumberFormat(decimal === "," ? "de-DE" : "en-US", {
|
|
1169
|
+
minimumFractionDigits: profile.minimumFractionDigits, maximumFractionDigits: profile.maximumFractionDigits, useGrouping: profile.grouping
|
|
1170
|
+
});
|
|
1171
|
+
formatters.set(key, formatter);
|
|
1172
|
+
}
|
|
1173
|
+
let formatted = formatter.format(value.value * (profile.percent ? 100 : 1));
|
|
1174
|
+
if (captured?.number.startsWith("+") && !formatted.startsWith("-"))
|
|
1175
|
+
formatted = "+" + formatted;
|
|
1176
|
+
const leadingSign = captured?.signBeforePrefix ? /^[+-]/.exec(formatted)?.[0] ?? "" : "";
|
|
1177
|
+
if (leadingSign)
|
|
1178
|
+
formatted = formatted.slice(1);
|
|
1179
|
+
const prefix = captured?.prefix || profile.prefix;
|
|
1180
|
+
let suffix = captured?.suffix || profile.suffix;
|
|
1181
|
+
if (profile.percent && !profile.suffix)
|
|
1182
|
+
suffix = suffix.replace(/%/g, "");
|
|
1183
|
+
return new ExportCell(value.value, { text: leadingSign + prefix + formatted + (profile.percent ? "%" : "") + suffix,
|
|
1184
|
+
...(value.presentation ? { presentation: value.presentation } : {}), ...(value.link ? { link: value.link } : {}) });
|
|
1185
|
+
});
|
|
1186
|
+
}
|
|
1187
|
+
const _exports = Object.freeze({ canopyPdfNumbers: canopyPdfNumbers });
|
|
1188
|
+
_modules.set("a0c020124a53cd7be15e3d53388b8393c981c3abc0f8d4aee76a442a2458457f", _exports);
|
|
1189
|
+
return _exports;
|
|
1190
|
+
})();
|
|
1191
|
+
|
|
1192
|
+
const _m31 = _modules.get("dab3e04542b3619c5c937162b41068f7cb1c3021b4620987c0fb95d4bd98d8e2") ?? (() => {
|
|
1193
|
+
const { ExportCell, NotSupportedError, OfficeIMOError } = _c0;
|
|
1194
|
+
|
|
1195
|
+
const { inputRows, checkAbort, pause, taskYieldDue } = _c14;
|
|
1196
|
+
|
|
1197
|
+
const { fontProgram } = _c19;
|
|
1198
|
+
|
|
1199
|
+
const { resolveScalar, selectFont, validateFonts } = _c20;
|
|
1200
|
+
|
|
1201
|
+
const { settings } = _c5;
|
|
1202
|
+
|
|
1203
|
+
const { canopyPdfNumbers } = _m34;
|
|
1204
|
+
|
|
1205
|
+
/** A bounded lookahead is replayed once; no second capture, full-dataset copy or smaller font is needed. */
|
|
1206
|
+
async function withCanopyPdfLayout(source, captured, options, write) {
|
|
1207
|
+
const prepared = settings({ ...options, columns: source.columns }), { fontSize, padding, page, margins, limits } = prepared;
|
|
1208
|
+
options = prepared.options;
|
|
1209
|
+
validateFonts(options.fonts, limits.maxFontBytes);
|
|
1210
|
+
const available = page.width - margins.left - margins.right;
|
|
1211
|
+
const iterator = inputRows(source.rows(), options.signal)[Symbol.asyncIterator](), sample = [];
|
|
1212
|
+
let done = false, characters = 0;
|
|
1213
|
+
try {
|
|
1214
|
+
while (sample.length < Math.min(128, options.limits?.maxRows ?? 128) && characters < 262144) {
|
|
1215
|
+
const item = await iterator.next();
|
|
1216
|
+
if (item.done) {
|
|
1217
|
+
done = true;
|
|
1218
|
+
break;
|
|
1219
|
+
}
|
|
1220
|
+
sample.push(item.value);
|
|
1221
|
+
characters += item.value.reduce((n, cell) => n + (cell instanceof ExportCell ? cell.text?.length ?? 0 : String(cell ?? "").length), 0);
|
|
1222
|
+
}
|
|
1223
|
+
const format = canopyPdfNumbers(sample, source.columns), rows = sample.map(format);
|
|
1224
|
+
const measure = (text, bold = false, italic = false) => {
|
|
1225
|
+
if (text.length > limits.maxCellCharacters)
|
|
1226
|
+
throw new OfficeIMOError("RESOURCE_LIMIT", "maxCellCharacters exceeded.");
|
|
1227
|
+
const face = selectFont(options.fonts, bold, italic), program = face.font ? fontProgram(face.font) : undefined;
|
|
1228
|
+
let width = 0;
|
|
1229
|
+
for (const character of text.replace(/\t/g, " ")) {
|
|
1230
|
+
const scalar = resolveScalar(character.codePointAt(0), program, bold);
|
|
1231
|
+
if (!scalar.supported)
|
|
1232
|
+
throw new NotSupportedError(scalar.message);
|
|
1233
|
+
width += scalar.width * fontSize / 1000;
|
|
1234
|
+
}
|
|
1235
|
+
return width;
|
|
1236
|
+
};
|
|
1237
|
+
const largest = (parts, bold = false, italic = false) => parts.reduce((width, part) => Math.max(width, measure(part, bold, italic)), 0);
|
|
1238
|
+
let layout = {};
|
|
1239
|
+
// Explicit points/bands and shaping providers retain their own layout policy.
|
|
1240
|
+
if (!options.columnWidths && typeof options.wideTable !== "object" && !options.textShaper) {
|
|
1241
|
+
const minimum = source.columns.map(column => Math.min(available, largest(column.header.split(/\s+/), prepared.options.headerPresentation?.bold) + padding * 2 + .01));
|
|
1242
|
+
const natural = source.columns.map((column, index) => Math.min(available, Math.max(minimum[index], largest(column.header.split(/\r\n?|\n/), prepared.options.headerPresentation?.bold) + padding * 2 + .01)));
|
|
1243
|
+
for (const row of rows) {
|
|
1244
|
+
for (let i = 0; i < row.length; i++) {
|
|
1245
|
+
const cell = row[i], text = cell instanceof ExportCell ? cell.text ?? String(cell.value ?? "") : String(cell ?? "");
|
|
1246
|
+
const style = cell instanceof ExportCell ? cell.presentation : undefined;
|
|
1247
|
+
const line = largest(text.split(/\r\n?|\n/), style?.bold, style?.italic) + padding * 2 + .01;
|
|
1248
|
+
const word = largest(text.split(/\s+/), style?.bold, style?.italic) + padding * 2 + .01;
|
|
1249
|
+
natural[i] = Math.min(available, Math.max(natural[i], line));
|
|
1250
|
+
minimum[i] = Math.min(available, Math.max(minimum[i], captured[i].kind === "text" ? word : line));
|
|
1251
|
+
}
|
|
1252
|
+
if (taskYieldDue())
|
|
1253
|
+
await pause();
|
|
1254
|
+
checkAbort(options.signal);
|
|
1255
|
+
}
|
|
1256
|
+
const sum = minimum.reduce((total, width) => total + width, 0), widths = [...minimum];
|
|
1257
|
+
if (sum > available + .001)
|
|
1258
|
+
layout = { columnWidths: widths, wideTable: options.wideTable === "reject" ? "reject" : {
|
|
1259
|
+
mode: "bands", repeatColumns: widths[0] + Math.max(...widths.slice(1)) <= available ? [0] : []
|
|
1260
|
+
} };
|
|
1261
|
+
else {
|
|
1262
|
+
let spare = available - sum;
|
|
1263
|
+
const needs = natural.map((width, index) => Math.max(0, width - widths[index])), total = needs.reduce((n, width) => n + width, 0);
|
|
1264
|
+
for (let i = 0; i < widths.length; i++)
|
|
1265
|
+
widths[i] += total ? needs[i] * Math.min(1, spare / total) : 0;
|
|
1266
|
+
spare = available - widths.reduce((n, width) => n + width, 0);
|
|
1267
|
+
const text = captured.flatMap((column, index) => column.kind === "text" ? [index] : []);
|
|
1268
|
+
for (const i of text.length ? text : widths.map((_, index) => index))
|
|
1269
|
+
widths[i] += spare / (text.length || widths.length);
|
|
1270
|
+
layout = { columnWidths: widths };
|
|
1271
|
+
}
|
|
1272
|
+
}
|
|
1273
|
+
const replay = async function* () {
|
|
1274
|
+
for (const row of rows)
|
|
1275
|
+
yield row;
|
|
1276
|
+
while (!done) {
|
|
1277
|
+
const item = await iterator.next();
|
|
1278
|
+
if (item.done) {
|
|
1279
|
+
done = true;
|
|
1280
|
+
break;
|
|
1281
|
+
}
|
|
1282
|
+
yield format(item.value);
|
|
1283
|
+
}
|
|
1284
|
+
};
|
|
1285
|
+
return await write(replay(), layout, prepared.options);
|
|
1286
|
+
}
|
|
1287
|
+
finally {
|
|
1288
|
+
if (!done) {
|
|
1289
|
+
try {
|
|
1290
|
+
void iterator.return(undefined).catch(() => { });
|
|
1291
|
+
}
|
|
1292
|
+
catch { /* Keep the writer's original failure. */ }
|
|
1293
|
+
}
|
|
1294
|
+
}
|
|
1295
|
+
}
|
|
1296
|
+
const _exports = Object.freeze({ withCanopyPdfLayout: withCanopyPdfLayout });
|
|
1297
|
+
_modules.set("dab3e04542b3619c5c937162b41068f7cb1c3021b4620987c0fb95d4bd98d8e2", _exports);
|
|
1298
|
+
return _exports;
|
|
1299
|
+
})();
|
|
1300
|
+
|
|
1301
|
+
const _m0 = _modules.get("5e3ca0adb71a24d6f5c464db0e63a6bbd2f62d6cba70e4be37afc4518de7d0e3") ?? (() => {
|
|
1302
|
+
const { BlobByteSink, ExportCell } = _c0;
|
|
1303
|
+
|
|
1304
|
+
const { notifyProgress } = _c1;
|
|
1305
|
+
|
|
1306
|
+
const { captureFields } = _c2;
|
|
1307
|
+
|
|
1308
|
+
const { captureCommonLimits, captureXlsxOptions, captureCsvOptions, capturePdfOptions, mergeAdapterLimits } = _m4;
|
|
1309
|
+
|
|
1310
|
+
const { writeXlsxTo } = _c7;
|
|
1311
|
+
|
|
1312
|
+
const { writeCsvTo } = _c8;
|
|
1313
|
+
|
|
1314
|
+
const { writePdfTo, writeGroupedPdfTo } = _c9;
|
|
1315
|
+
|
|
1316
|
+
const { canopyDiagnostics } = _m12;
|
|
1317
|
+
|
|
1318
|
+
const { prepareCanopyExport } = _m13;
|
|
1319
|
+
|
|
1320
|
+
const { canopyPins } = _m18;
|
|
1321
|
+
|
|
1322
|
+
const { canopyRules } = _m19;
|
|
1323
|
+
|
|
1324
|
+
const { canopyGrouped } = _m22;
|
|
1325
|
+
|
|
1326
|
+
const { canopyAbout } = _m26;
|
|
1327
|
+
|
|
1328
|
+
const { writeCanopyWorkbook } = _m28;
|
|
1329
|
+
|
|
1330
|
+
const { withCanopyPdfLayout } = _m31;
|
|
1331
|
+
|
|
1332
|
+
|
|
1333
|
+
|
|
1334
|
+
|
|
1335
|
+
|
|
1336
|
+
|
|
1337
|
+
|
|
1338
|
+
/** Write a captured CanopyX grid to a caller-owned destination; partial bytes remain caller-owned on failure. */
|
|
1339
|
+
async function writeCanopyTo(capture, format, destination, options = {}) {
|
|
1340
|
+
const selected = captureFields(options, ["tones", "columnOptions", "unsupportedPresentation", "datetime", "xlsx", "csv", "pdf", "signal", "onDiagnostic", "limits", "onProgress", "grouped", "about"]);
|
|
1341
|
+
const { signal, onProgress } = selected, limits = captureCommonLimits(selected.limits);
|
|
1342
|
+
const xlsx = captureXlsxOptions(format === "xlsx" ? selected.xlsx : undefined);
|
|
1343
|
+
const csv = captureCsvOptions(format === "csv" ? selected.csv : undefined);
|
|
1344
|
+
const pdf = capturePdfOptions(format === "pdf" ? selected.pdf : undefined);
|
|
1345
|
+
const prepared = prepareCanopyExport(capture, format, { ...selected, xlsx }), { request, report, tones, pivot } = prepared;
|
|
1346
|
+
if (selected.about !== undefined && typeof selected.about !== "boolean")
|
|
1347
|
+
throw new TypeError("Canopy about must be boolean.");
|
|
1348
|
+
const labels = selected.grouped === undefined ? undefined : captureFields(selected.grouped, ["labelColumn", "subtotalLabel", "grandTotalLabel", "includeGrandTotal", "continuationLabel", "groupHeadingLevel"]);
|
|
1349
|
+
const capturedLabels = labels && { ...labels, ...(labels.labelColumn === undefined ? {} : { labelColumn: Object.freeze({ header: labels.labelColumn.header }) }) };
|
|
1350
|
+
const about = format === "xlsx" && selected.about ? canopyAbout(request, xlsx) : undefined;
|
|
1351
|
+
const ruleCellTypes = new Map();
|
|
1352
|
+
let consumed = 0;
|
|
1353
|
+
const source = Object.freeze({ ...prepared.source, async *rows() {
|
|
1354
|
+
for await (const row of prepared.source.rows()) {
|
|
1355
|
+
for (const [column, type] of ruleCellTypes) {
|
|
1356
|
+
const cell = row[column], raw = cell instanceof ExportCell ? cell.value : cell;
|
|
1357
|
+
if (raw == null || type === "number" && typeof raw === "number" && Number.isFinite(raw) || type === "date" && raw instanceof Date && Number.isFinite(raw.getTime()))
|
|
1358
|
+
continue;
|
|
1359
|
+
const code = "UNSUPPORTED_NATIVE_RULE_CELL_TYPE:" + type;
|
|
1360
|
+
report({ code, columnId: source.columns[column].key });
|
|
1361
|
+
// Text fallback cannot retract an already captured native declaration after streaming starts.
|
|
1362
|
+
throw new TypeError("Unsupported Canopy presentation: " + code + " (" + source.columns[column].key + ")");
|
|
1363
|
+
}
|
|
1364
|
+
consumed++;
|
|
1365
|
+
yield row;
|
|
1366
|
+
}
|
|
1367
|
+
} });
|
|
1368
|
+
const progress = onProgress ? { onProgress: (event) => {
|
|
1369
|
+
// About and generated group rows consume output budgets, but never become exported source details.
|
|
1370
|
+
notifyProgress(onProgress, { ...event, rows: consumed,
|
|
1371
|
+
...(event.sheetRows === undefined ? {} : { sheetRows: about !== undefined && event.sheetName === "About" ? 0 : consumed }),
|
|
1372
|
+
...(source.rowCount === null ? {} : { totalRows: source.rowCount }) });
|
|
1373
|
+
} } : {};
|
|
1374
|
+
const stream = { ...(signal ? { signal } : {}), ...progress };
|
|
1375
|
+
if (format === "xlsx") {
|
|
1376
|
+
const formatLimits = mergeAdapterLimits(xlsx.limits, limits), grouped = pivot ? undefined : canopyGrouped(source, request, { ...selected, xlsx }, formatLimits, report, format);
|
|
1377
|
+
const pinned = canopyPins(request.columns, report), rules = canopyRules(request, format, grouped !== undefined, tones, report, { ...selected, xlsx }, ruleCellTypes);
|
|
1378
|
+
if (pivot && (xlsx.sheet?.rowOutline !== undefined || xlsx.sheet?.columnOutlines !== undefined || xlsx.sheet?.maxOutlineLevel !== undefined ||
|
|
1379
|
+
xlsx.sheet?.outlineSummaryBelow !== undefined || xlsx.sheet?.outlineSummaryRight !== undefined || xlsx.sheet?.table !== undefined || xlsx.sheet?.footer !== undefined))
|
|
1380
|
+
throw new TypeError("Captured pivot metadata owns outlines and totals; worksheet overrides cannot regroup or recalculate it.");
|
|
1381
|
+
if (pivot && xlsx.cellValueWriters !== undefined)
|
|
1382
|
+
throw new TypeError("Captured pivot exports use frozen values rather than custom cellValueWriters.");
|
|
1383
|
+
const sheet = { ...xlsx.sheet, ...(pivot?.sheet ?? {}), ...(pivot ? { autoFilter: false } : {}),
|
|
1384
|
+
freezeHeader: xlsx.sheet?.freezeHeader ?? (xlsx.sheet?.includeHeader !== false),
|
|
1385
|
+
freezeColumns: xlsx.sheet?.freezeColumns ?? (pinned ? pinned + (grouped ? 1 : 0) : 0),
|
|
1386
|
+
conditionalFormats: [...rules, ...(xlsx.sheet?.conditionalFormats ?? [])] };
|
|
1387
|
+
const settings = { ...xlsx, ...stream, columns: source.columns, sheet, dateMode: xlsx.dateMode ?? request.timeZone, limits: formatLimits };
|
|
1388
|
+
if (grouped || about)
|
|
1389
|
+
return writeCanopyWorkbook(source, grouped, destination, settings, capturedLabels, about);
|
|
1390
|
+
return writeXlsxTo(source.rows(), destination, settings);
|
|
1391
|
+
}
|
|
1392
|
+
if (pivot)
|
|
1393
|
+
canopyDiagnostics(format, { ...selected, unsupportedPresentation: "text" })({ code: "PIVOT_OUTLINES_XLSX_ONLY" });
|
|
1394
|
+
if (format === "pdf") {
|
|
1395
|
+
if (pivot && pdf.footer?.totals !== undefined)
|
|
1396
|
+
throw new TypeError("Captured pivot metadata owns totals; PDF footer totals cannot recalculate it.");
|
|
1397
|
+
const formatLimits = mergeAdapterLimits(pdf.limits, limits), grouped = pivot ? undefined : canopyGrouped(source, request, selected, formatLimits, report, format);
|
|
1398
|
+
canopyRules(request, format, grouped !== undefined, tones, report, selected);
|
|
1399
|
+
// CSS pixels become points before the existing fit/band policy. Explicit PDF point widths win.
|
|
1400
|
+
const fitted = request.columns.every(column => column.width !== undefined) ? request.columns.map(column => column.width.preferred * 72 / 96) : undefined;
|
|
1401
|
+
const widths = pdf.columnWidths ?? fitted;
|
|
1402
|
+
const settings = { orientation: "landscape", wideTable: "fit", ...pdf, ...stream, limits: formatLimits };
|
|
1403
|
+
if (grouped) {
|
|
1404
|
+
if (pdf.headerRows !== undefined || pdf.footer !== undefined)
|
|
1405
|
+
throw new TypeError("Grouped Canopy PDF owns heading and summary rows.");
|
|
1406
|
+
const { headerRows: _headers, footer: _footer, ...groupedSettings } = settings;
|
|
1407
|
+
return writeGroupedPdfTo(grouped, destination, { ...groupedSettings,
|
|
1408
|
+
...(widths === undefined ? {} : { columnWidths: [72, ...widths] }),
|
|
1409
|
+
labelColumn: { header: capturedLabels?.labelColumn?.header ?? "Group", width: 12 },
|
|
1410
|
+
subtotalLabel: capturedLabels?.subtotalLabel ?? (group => group.label + " total"),
|
|
1411
|
+
grandTotalLabel: capturedLabels?.grandTotalLabel ?? (() => "Grand total"),
|
|
1412
|
+
...(capturedLabels?.includeGrandTotal === undefined ? {} : { includeGrandTotal: capturedLabels.includeGrandTotal }),
|
|
1413
|
+
...(capturedLabels?.continuationLabel === undefined ? {} : { continuationLabel: capturedLabels.continuationLabel }),
|
|
1414
|
+
...(capturedLabels?.groupHeadingLevel === undefined ? {} : { groupHeadingLevel: capturedLabels.groupHeadingLevel }) });
|
|
1415
|
+
}
|
|
1416
|
+
return withCanopyPdfLayout(prepared.source, request.columns, settings, async (rows, layout, captured) => {
|
|
1417
|
+
const counted = async function* () { for await (const row of rows) {
|
|
1418
|
+
consumed++;
|
|
1419
|
+
yield row;
|
|
1420
|
+
} };
|
|
1421
|
+
return writePdfTo(counted(), destination, { ...captured, ...layout, columns: source.columns });
|
|
1422
|
+
});
|
|
1423
|
+
}
|
|
1424
|
+
return writeCsvTo(source.rows(), destination, { ...csv, ...stream, columns: source.columns, valueMode: request.values,
|
|
1425
|
+
limits: mergeAdapterLimits(csv.limits, limits) });
|
|
1426
|
+
}
|
|
1427
|
+
/** Export an immutable native capture as a Blob without loading or registering CanopyX. */
|
|
1428
|
+
async function exportCanopy(capture, format, options = {}) {
|
|
1429
|
+
const sink = new BlobByteSink();
|
|
1430
|
+
try {
|
|
1431
|
+
await writeCanopyTo(capture, format, sink, options);
|
|
1432
|
+
return sink.toBlob(format === "xlsx" ? "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" : format === "pdf" ? "application/pdf" : "text/csv;charset=utf-8");
|
|
1433
|
+
}
|
|
1434
|
+
catch (error) {
|
|
1435
|
+
sink.discard();
|
|
1436
|
+
throw error;
|
|
1437
|
+
}
|
|
1438
|
+
}
|
|
1439
|
+
const _exports = Object.freeze({ createCanopyExport: _m13.createCanopyExport, ExportCell: _c11.ExportCell, PdfFont: _c19.PdfFont, writeCanopyTo: writeCanopyTo, exportCanopy: exportCanopy });
|
|
1440
|
+
_modules.set("5e3ca0adb71a24d6f5c464db0e63a6bbd2f62d6cba70e4be37afc4518de7d0e3", _exports);
|
|
1441
|
+
return _exports;
|
|
1442
|
+
})();
|
|
1443
|
+
Object.assign(officeimo, _m0);
|
|
1444
|
+
})(globalThis);
|