@evotecit/officeimo 0.1.3 → 0.1.4
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 +18 -4
- package/bundles/officeimo-canopyx.js +669 -274
- package/bundles/officeimo-canopyx.mjs +627 -236
- package/bundles/officeimo-datatables.js +309 -233
- package/bundles/officeimo-datatables.mjs +280 -205
- package/bundles/officeimo-xlsx.js +177 -101
- package/bundles/officeimo-xlsx.mjs +149 -74
- package/bundles/officeimo.js +308 -232
- package/bundles/officeimo.mjs +279 -204
- package/dist/integrations/canopyx/grouping.js +15 -5
- package/dist/integrations/canopyx/index.d.ts +1 -1
- package/dist/integrations/canopyx/index.js +23 -6
- package/dist/integrations/canopyx/pdf-layout.d.ts +5 -0
- package/dist/integrations/canopyx/pdf-layout.js +97 -0
- package/dist/integrations/canopyx/pdf-number.d.ts +3 -0
- package/dist/integrations/canopyx/pdf-number.js +64 -0
- package/dist/integrations/canopyx/pivot.d.ts +15 -0
- package/dist/integrations/canopyx/pivot.js +67 -0
- package/dist/integrations/canopyx/source.js +50 -14
- package/dist/integrations/canopyx/types.d.ts +45 -2
- package/dist/opc/index.js +9 -0
- package/dist/xlsx/index.d.ts +1 -1
- package/dist/xlsx/options.js +1 -1
- package/dist/xlsx/outlines.d.ts +3 -0
- package/dist/xlsx/outlines.js +39 -0
- package/dist/xlsx/types.d.ts +9 -0
- package/dist/xlsx/values.js +11 -2
- package/dist/xlsx/workbook.js +2 -0
- package/dist/xlsx/worksheet.js +14 -6
- package/package.json +2 -2
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { createGroupedReport } from "../../core/grouped-report.js";
|
|
2
|
-
import { ExportCell } from "../../core/presentation.js";
|
|
3
2
|
import { checkAbort } from "../../core/iteration.js";
|
|
4
3
|
import { createTotals } from "../../internal/totals.js";
|
|
5
4
|
import { captureFields } from "../../internal/capture.js";
|
|
6
5
|
import { datetime } from "./dates.js";
|
|
6
|
+
import { canopyIdentityValue } from "./source.js";
|
|
7
7
|
const identity = (value) => value instanceof Date ? "date:" + value.getTime() : typeof value + ":" + String(value);
|
|
8
|
-
const scalar =
|
|
8
|
+
const scalar = canopyIdentityValue;
|
|
9
9
|
/** Validate captured ranges, then use the owned grouping factory and its existing writers.
|
|
10
10
|
* Only ranges, labels and at most four active aggregate vectors are retained; no detail body is buffered. */
|
|
11
11
|
export function canopyGrouped(source, request, options, limits, report, format) {
|
|
@@ -172,10 +172,20 @@ export function canopyGrouped(source, request, options, limits, report, format)
|
|
|
172
172
|
}
|
|
173
173
|
verify(grand, grandExpected);
|
|
174
174
|
}
|
|
175
|
+
// The factory's hidden fields keep raw group identity separate from projected
|
|
176
|
+
// detail labels. Never override a declared output column's value getter.
|
|
177
|
+
const groupKeys = new Set([...source.columns.map(column => column.key), ...levels.map(level => level.column)]);
|
|
175
178
|
const groupBy = levels.map((level, depth) => {
|
|
176
|
-
const
|
|
177
|
-
|
|
178
|
-
|
|
179
|
+
const column = source.columns.findIndex(column => column.key === level.column);
|
|
180
|
+
let key = level.column;
|
|
181
|
+
if (column >= 0) {
|
|
182
|
+
do {
|
|
183
|
+
key += "#raw";
|
|
184
|
+
} while (groupKeys.has(key));
|
|
185
|
+
groupKeys.add(key);
|
|
186
|
+
}
|
|
187
|
+
return { key,
|
|
188
|
+
value: (row, context) => column < 0 ? at(depth, context.rowIndex).value : scalar(row[column]),
|
|
179
189
|
label: (value) => labels[depth].get(identity(value)) ?? String(value ?? "") };
|
|
180
190
|
});
|
|
181
191
|
const sourceLimits = limits === undefined ? undefined : {
|
|
@@ -3,7 +3,7 @@ import type { CanopyCapture, CanopyFormat, CanopyWriteOptions } from "./types.js
|
|
|
3
3
|
export { createCanopyExport } from "./source.js";
|
|
4
4
|
export { ExportCell } from "../../core/presentation.js";
|
|
5
5
|
export { PdfFont } from "../../pdf/font.js";
|
|
6
|
-
export type { CanopyCapture, CanopyExportCell, CanopyExportColumn, CanopyExportRow, CanopyExport, CanopyFormat, CanopyDiagnostic, CanopySourceOptions, CanopyWriteOptions, CanopyNumberFormat, CanopyExportGroup, CanopyExportGrouping, CanopyRuleFilter, CanopyRulePredicate, CanopyFormatRule } from "./types.js";
|
|
6
|
+
export type { CanopyCapture, CanopyExportCell, CanopyExportColumn, CanopyExportRow, CanopyExport, CanopyFormat, CanopyDiagnostic, CanopySourceOptions, CanopyWriteOptions, CanopyPivotAxisPresentation, CanopyPivotAxis, CanopyPivotColumnGroup, CanopyPivotDescriptor, CanopyNumberFormat, CanopyExportGroup, CanopyExportGrouping, CanopyRuleFilter, CanopyRulePredicate, CanopyFormatRule } from "./types.js";
|
|
7
7
|
/** Write a captured CanopyX grid to a caller-owned destination; partial bytes remain caller-owned on failure. */
|
|
8
8
|
export declare function writeCanopyTo(capture: CanopyCapture, format: CanopyFormat, destination: OutputDestination, options?: CanopyWriteOptions): Promise<ExportResult>;
|
|
9
9
|
/** Export an immutable native capture as a Blob without loading or registering CanopyX. */
|
|
@@ -5,12 +5,14 @@ import { captureCommonLimits, captureXlsxOptions, captureCsvOptions, capturePdfO
|
|
|
5
5
|
import { writeXlsxTo } from "../../xlsx/index.js";
|
|
6
6
|
import { writeCsvTo } from "../../csv/index.js";
|
|
7
7
|
import { writePdfTo, writeGroupedPdfTo } from "../../pdf/index.js";
|
|
8
|
+
import { canopyDiagnostics } from "./diagnostics.js";
|
|
8
9
|
import { prepareCanopyExport } from "./source.js";
|
|
9
10
|
import { canopyPins } from "./presentation.js";
|
|
10
11
|
import { canopyRules } from "./rules.js";
|
|
11
12
|
import { canopyGrouped } from "./grouping.js";
|
|
12
13
|
import { canopyAbout } from "./metadata.js";
|
|
13
14
|
import { writeCanopyWorkbook } from "./workbook.js";
|
|
15
|
+
import { withCanopyPdfLayout } from "./pdf-layout.js";
|
|
14
16
|
export { createCanopyExport } from "./source.js";
|
|
15
17
|
export { ExportCell } from "../../core/presentation.js";
|
|
16
18
|
export { PdfFont } from "../../pdf/font.js";
|
|
@@ -21,7 +23,7 @@ export async function writeCanopyTo(capture, format, destination, options = {})
|
|
|
21
23
|
const xlsx = captureXlsxOptions(format === "xlsx" ? selected.xlsx : undefined);
|
|
22
24
|
const csv = captureCsvOptions(format === "csv" ? selected.csv : undefined);
|
|
23
25
|
const pdf = capturePdfOptions(format === "pdf" ? selected.pdf : undefined);
|
|
24
|
-
const prepared = prepareCanopyExport(capture, format, { ...selected, xlsx }), { request, report, tones } = prepared;
|
|
26
|
+
const prepared = prepareCanopyExport(capture, format, { ...selected, xlsx }), { request, report, tones, pivot } = prepared;
|
|
25
27
|
if (selected.about !== undefined && typeof selected.about !== "boolean")
|
|
26
28
|
throw new TypeError("Canopy about must be boolean.");
|
|
27
29
|
const labels = selected.grouped === undefined ? undefined : captureFields(selected.grouped, ["labelColumn", "subtotalLabel", "grandTotalLabel", "includeGrandTotal", "continuationLabel", "groupHeadingLevel"]);
|
|
@@ -52,9 +54,14 @@ export async function writeCanopyTo(capture, format, destination, options = {})
|
|
|
52
54
|
} } : {};
|
|
53
55
|
const stream = { ...(signal ? { signal } : {}), ...progress };
|
|
54
56
|
if (format === "xlsx") {
|
|
55
|
-
const formatLimits = mergeAdapterLimits(xlsx.limits, limits), grouped = canopyGrouped(source, request, { ...selected, xlsx }, formatLimits, report, format);
|
|
57
|
+
const formatLimits = mergeAdapterLimits(xlsx.limits, limits), grouped = pivot ? undefined : canopyGrouped(source, request, { ...selected, xlsx }, formatLimits, report, format);
|
|
56
58
|
const pinned = canopyPins(request.columns, report), rules = canopyRules(request, format, grouped !== undefined, tones, report, { ...selected, xlsx }, ruleCellTypes);
|
|
57
|
-
|
|
59
|
+
if (pivot && (xlsx.sheet?.rowOutline !== undefined || xlsx.sheet?.columnOutlines !== undefined || xlsx.sheet?.maxOutlineLevel !== undefined ||
|
|
60
|
+
xlsx.sheet?.outlineSummaryBelow !== undefined || xlsx.sheet?.outlineSummaryRight !== undefined || xlsx.sheet?.table !== undefined || xlsx.sheet?.footer !== undefined))
|
|
61
|
+
throw new TypeError("Captured pivot metadata owns outlines and totals; worksheet overrides cannot regroup or recalculate it.");
|
|
62
|
+
if (pivot && xlsx.cellValueWriters !== undefined)
|
|
63
|
+
throw new TypeError("Captured pivot exports use frozen values rather than custom cellValueWriters.");
|
|
64
|
+
const sheet = { ...xlsx.sheet, ...(pivot?.sheet ?? {}), ...(pivot ? { autoFilter: false } : {}),
|
|
58
65
|
freezeHeader: xlsx.sheet?.freezeHeader ?? (xlsx.sheet?.includeHeader !== false),
|
|
59
66
|
freezeColumns: xlsx.sheet?.freezeColumns ?? (pinned ? pinned + (grouped ? 1 : 0) : 0),
|
|
60
67
|
conditionalFormats: [...rules, ...(xlsx.sheet?.conditionalFormats ?? [])] };
|
|
@@ -63,13 +70,17 @@ export async function writeCanopyTo(capture, format, destination, options = {})
|
|
|
63
70
|
return writeCanopyWorkbook(source, grouped, destination, settings, capturedLabels, about);
|
|
64
71
|
return writeXlsxTo(source.rows(), destination, settings);
|
|
65
72
|
}
|
|
73
|
+
if (pivot)
|
|
74
|
+
canopyDiagnostics(format, { ...selected, unsupportedPresentation: "text" })({ code: "PIVOT_OUTLINES_XLSX_ONLY" });
|
|
66
75
|
if (format === "pdf") {
|
|
67
|
-
|
|
76
|
+
if (pivot && pdf.footer?.totals !== undefined)
|
|
77
|
+
throw new TypeError("Captured pivot metadata owns totals; PDF footer totals cannot recalculate it.");
|
|
78
|
+
const formatLimits = mergeAdapterLimits(pdf.limits, limits), grouped = pivot ? undefined : canopyGrouped(source, request, selected, formatLimits, report, format);
|
|
68
79
|
canopyRules(request, format, grouped !== undefined, tones, report, selected);
|
|
69
80
|
// CSS pixels become points before the existing fit/band policy. Explicit PDF point widths win.
|
|
70
81
|
const fitted = request.columns.every(column => column.width !== undefined) ? request.columns.map(column => column.width.preferred * 72 / 96) : undefined;
|
|
71
82
|
const widths = pdf.columnWidths ?? fitted;
|
|
72
|
-
const settings = {
|
|
83
|
+
const settings = { orientation: "landscape", wideTable: "fit", ...pdf, ...stream, limits: formatLimits };
|
|
73
84
|
if (grouped) {
|
|
74
85
|
if (pdf.headerRows !== undefined || pdf.footer !== undefined)
|
|
75
86
|
throw new TypeError("Grouped Canopy PDF owns heading and summary rows.");
|
|
@@ -83,7 +94,13 @@ export async function writeCanopyTo(capture, format, destination, options = {})
|
|
|
83
94
|
...(capturedLabels?.continuationLabel === undefined ? {} : { continuationLabel: capturedLabels.continuationLabel }),
|
|
84
95
|
...(capturedLabels?.groupHeadingLevel === undefined ? {} : { groupHeadingLevel: capturedLabels.groupHeadingLevel }) });
|
|
85
96
|
}
|
|
86
|
-
return
|
|
97
|
+
return withCanopyPdfLayout(prepared.source, request.columns, settings, async (rows, layout, captured) => {
|
|
98
|
+
const counted = async function* () { for await (const row of rows) {
|
|
99
|
+
consumed++;
|
|
100
|
+
yield row;
|
|
101
|
+
} };
|
|
102
|
+
return writePdfTo(counted(), destination, { ...captured, ...layout, columns: source.columns });
|
|
103
|
+
});
|
|
87
104
|
}
|
|
88
105
|
return writeCsvTo(source.rows(), destination, { ...csv, ...stream, columns: source.columns, valueMode: request.values,
|
|
89
106
|
limits: mergeAdapterLimits(csv.limits, limits) });
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { ExportValue, ExportResult } from "../../core/index.js";
|
|
2
|
+
import type { PdfOptions } from "../../pdf/index.js";
|
|
3
|
+
import type { CanopyExport, CanopyExportColumn } from "./types.js";
|
|
4
|
+
/** A bounded lookahead is replayed once; no second capture, full-dataset copy or smaller font is needed. */
|
|
5
|
+
export declare function withCanopyPdfLayout(source: CanopyExport, captured: readonly CanopyExportColumn[], options: Omit<PdfOptions, "columns">, write: (rows: AsyncIterable<readonly ExportValue[]>, layout: Pick<PdfOptions, "columnWidths" | "wideTable">, capturedOptions: Omit<PdfOptions, "columns">) => Promise<ExportResult>): Promise<ExportResult>;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { ExportCell, NotSupportedError, OfficeIMOError } from "../../core/index.js";
|
|
2
|
+
import { inputRows, checkAbort, pause, taskYieldDue } from "../../core/iteration.js";
|
|
3
|
+
import { fontProgram } from "../../pdf/font.js";
|
|
4
|
+
import { resolveScalar, selectFont, validateFonts } from "../../pdf/font-support.js";
|
|
5
|
+
import { settings } from "../../pdf/settings.js";
|
|
6
|
+
import { canopyPdfNumbers } from "./pdf-number.js";
|
|
7
|
+
/** A bounded lookahead is replayed once; no second capture, full-dataset copy or smaller font is needed. */
|
|
8
|
+
export async function withCanopyPdfLayout(source, captured, options, write) {
|
|
9
|
+
const prepared = settings({ ...options, columns: source.columns }), { fontSize, padding, page, margins, limits } = prepared;
|
|
10
|
+
options = prepared.options;
|
|
11
|
+
validateFonts(options.fonts, limits.maxFontBytes);
|
|
12
|
+
const available = page.width - margins.left - margins.right;
|
|
13
|
+
const iterator = inputRows(source.rows(), options.signal)[Symbol.asyncIterator](), sample = [];
|
|
14
|
+
let done = false, characters = 0;
|
|
15
|
+
try {
|
|
16
|
+
while (sample.length < Math.min(128, options.limits?.maxRows ?? 128) && characters < 262144) {
|
|
17
|
+
const item = await iterator.next();
|
|
18
|
+
if (item.done) {
|
|
19
|
+
done = true;
|
|
20
|
+
break;
|
|
21
|
+
}
|
|
22
|
+
sample.push(item.value);
|
|
23
|
+
characters += item.value.reduce((n, cell) => n + (cell instanceof ExportCell ? cell.text?.length ?? 0 : String(cell ?? "").length), 0);
|
|
24
|
+
}
|
|
25
|
+
const format = canopyPdfNumbers(sample, source.columns), rows = sample.map(format);
|
|
26
|
+
const measure = (text, bold = false, italic = false) => {
|
|
27
|
+
if (text.length > limits.maxCellCharacters)
|
|
28
|
+
throw new OfficeIMOError("RESOURCE_LIMIT", "maxCellCharacters exceeded.");
|
|
29
|
+
const face = selectFont(options.fonts, bold, italic), program = face.font ? fontProgram(face.font) : undefined;
|
|
30
|
+
let width = 0;
|
|
31
|
+
for (const character of text.replace(/\t/g, " ")) {
|
|
32
|
+
const scalar = resolveScalar(character.codePointAt(0), program, bold);
|
|
33
|
+
if (!scalar.supported)
|
|
34
|
+
throw new NotSupportedError(scalar.message);
|
|
35
|
+
width += scalar.width * fontSize / 1000;
|
|
36
|
+
}
|
|
37
|
+
return width;
|
|
38
|
+
};
|
|
39
|
+
const largest = (parts, bold = false, italic = false) => parts.reduce((width, part) => Math.max(width, measure(part, bold, italic)), 0);
|
|
40
|
+
let layout = {};
|
|
41
|
+
// Explicit points/bands and shaping providers retain their own layout policy.
|
|
42
|
+
if (!options.columnWidths && typeof options.wideTable !== "object" && !options.textShaper) {
|
|
43
|
+
const minimum = source.columns.map(column => Math.min(available, largest(column.header.split(/\s+/), prepared.options.headerPresentation?.bold) + padding * 2 + .01));
|
|
44
|
+
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)));
|
|
45
|
+
for (const row of rows) {
|
|
46
|
+
for (let i = 0; i < row.length; i++) {
|
|
47
|
+
const cell = row[i], text = cell instanceof ExportCell ? cell.text ?? String(cell.value ?? "") : String(cell ?? "");
|
|
48
|
+
const style = cell instanceof ExportCell ? cell.presentation : undefined;
|
|
49
|
+
const line = largest(text.split(/\r\n?|\n/), style?.bold, style?.italic) + padding * 2 + .01;
|
|
50
|
+
const word = largest(text.split(/\s+/), style?.bold, style?.italic) + padding * 2 + .01;
|
|
51
|
+
natural[i] = Math.min(available, Math.max(natural[i], line));
|
|
52
|
+
minimum[i] = Math.min(available, Math.max(minimum[i], captured[i].kind === "text" ? word : line));
|
|
53
|
+
}
|
|
54
|
+
if (taskYieldDue())
|
|
55
|
+
await pause();
|
|
56
|
+
checkAbort(options.signal);
|
|
57
|
+
}
|
|
58
|
+
const sum = minimum.reduce((total, width) => total + width, 0), widths = [...minimum];
|
|
59
|
+
if (sum > available + .001)
|
|
60
|
+
layout = { columnWidths: widths, wideTable: options.wideTable === "reject" ? "reject" : {
|
|
61
|
+
mode: "bands", repeatColumns: widths[0] + Math.max(...widths.slice(1)) <= available ? [0] : []
|
|
62
|
+
} };
|
|
63
|
+
else {
|
|
64
|
+
let spare = available - sum;
|
|
65
|
+
const needs = natural.map((width, index) => Math.max(0, width - widths[index])), total = needs.reduce((n, width) => n + width, 0);
|
|
66
|
+
for (let i = 0; i < widths.length; i++)
|
|
67
|
+
widths[i] += total ? needs[i] * Math.min(1, spare / total) : 0;
|
|
68
|
+
spare = available - widths.reduce((n, width) => n + width, 0);
|
|
69
|
+
const text = captured.flatMap((column, index) => column.kind === "text" ? [index] : []);
|
|
70
|
+
for (const i of text.length ? text : widths.map((_, index) => index))
|
|
71
|
+
widths[i] += spare / (text.length || widths.length);
|
|
72
|
+
layout = { columnWidths: widths };
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
const replay = async function* () {
|
|
76
|
+
for (const row of rows)
|
|
77
|
+
yield row;
|
|
78
|
+
while (!done) {
|
|
79
|
+
const item = await iterator.next();
|
|
80
|
+
if (item.done) {
|
|
81
|
+
done = true;
|
|
82
|
+
break;
|
|
83
|
+
}
|
|
84
|
+
yield format(item.value);
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
return await write(replay(), layout, prepared.options);
|
|
88
|
+
}
|
|
89
|
+
finally {
|
|
90
|
+
if (!done) {
|
|
91
|
+
try {
|
|
92
|
+
void iterator.return(undefined).catch(() => { });
|
|
93
|
+
}
|
|
94
|
+
catch { /* Keep the writer's original failure. */ }
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { ExportValue, ColumnSettings } from "../../core/index.js";
|
|
2
|
+
/** Preserve the captured decimal convention across a column, including whole percentages without a separator. */
|
|
3
|
+
export declare function canopyPdfNumbers(sample: readonly (readonly ExportValue[])[], columns: readonly ColumnSettings[]): (row: readonly ExportValue[]) => readonly ExportValue[];
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { ExportCell } from "../../core/index.js";
|
|
2
|
+
/** Fixed numeric formats affect PDF text, not the frozen numeric value used by other writers. */
|
|
3
|
+
function numericProfile(format) {
|
|
4
|
+
if (format === undefined)
|
|
5
|
+
return undefined;
|
|
6
|
+
const match = /^((?:"[^"\\]*")*)(#,##)?0(?:\.([0#]+))?(%)?((?:"[^"\\]*")*)$/.exec(format);
|
|
7
|
+
if (!match || (match[3]?.length ?? 0) > 10)
|
|
8
|
+
return undefined;
|
|
9
|
+
return { minimumFractionDigits: (match[3]?.match(/0/g) ?? []).length, maximumFractionDigits: match[3]?.length ?? 0,
|
|
10
|
+
percent: !!match[4], grouping: !!match[2], prefix: match[1].replace(/"/g, ""), suffix: match[5].replace(/"/g, "") };
|
|
11
|
+
}
|
|
12
|
+
/** Preserve the captured decimal convention across a column, including whole percentages without a separator. */
|
|
13
|
+
export function canopyPdfNumbers(sample, columns) {
|
|
14
|
+
const formatters = new Map();
|
|
15
|
+
const decimal = columns.map((column, index) => {
|
|
16
|
+
let fallback = ".";
|
|
17
|
+
for (const row of sample) {
|
|
18
|
+
const cell = row[index];
|
|
19
|
+
if (!(cell instanceof ExportCell) || typeof cell.value !== "number")
|
|
20
|
+
continue;
|
|
21
|
+
const profile = numericProfile(cell.presentation?.numberFormat ?? column.format);
|
|
22
|
+
if (!profile?.maximumFractionDigits)
|
|
23
|
+
continue;
|
|
24
|
+
const match = /([.,])(\d+)[^\d.,]*$/.exec(cell.text ?? "");
|
|
25
|
+
if (match && match[2].length <= profile.maximumFractionDigits) {
|
|
26
|
+
const numeric = /([+-]?\d[\d.,]*)[^\d]*$/.exec(cell.text ?? "")?.[1] ?? "";
|
|
27
|
+
const scaled = cell.value * (profile.percent ? 100 : 1);
|
|
28
|
+
if (/^[+-]?\d{1,3}(?:,\d{3})+$/.test(numeric) || /^[+-]?\d{1,3}(?:\.\d{3})+$/.test(numeric)) {
|
|
29
|
+
if (Math.abs(Number(numeric.replace(/[.,]/g, "")) - scaled) < .5) {
|
|
30
|
+
fallback = match[1] === "," ? "." : ",";
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return match[1];
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return fallback;
|
|
38
|
+
});
|
|
39
|
+
return row => row.map((value, index) => {
|
|
40
|
+
if (!(value instanceof ExportCell) || typeof value.value !== "number")
|
|
41
|
+
return value;
|
|
42
|
+
const profile = numericProfile(value.presentation?.numberFormat ?? columns[index].format);
|
|
43
|
+
if (!profile)
|
|
44
|
+
return value;
|
|
45
|
+
const captured = /^([^0-9+-]*)([+-]?\d[\d., \u00a0\u202f]*?)([^0-9]*)$/.exec(value.text ?? "");
|
|
46
|
+
if (value.text && !captured)
|
|
47
|
+
return value;
|
|
48
|
+
const key = [decimal[index], profile.minimumFractionDigits, profile.maximumFractionDigits, profile.grouping].join(":");
|
|
49
|
+
let formatter = formatters.get(key);
|
|
50
|
+
if (!formatter) {
|
|
51
|
+
formatter = new Intl.NumberFormat(decimal[index] === "," ? "de-DE" : "en-US", {
|
|
52
|
+
minimumFractionDigits: profile.minimumFractionDigits, maximumFractionDigits: profile.maximumFractionDigits, useGrouping: profile.grouping
|
|
53
|
+
});
|
|
54
|
+
formatters.set(key, formatter);
|
|
55
|
+
}
|
|
56
|
+
const formatted = formatter.format(value.value * (profile.percent ? 100 : 1));
|
|
57
|
+
const prefix = profile.prefix || captured?.[1] || "";
|
|
58
|
+
let suffix = profile.suffix || captured?.[3] || "";
|
|
59
|
+
if (profile.percent && !profile.suffix)
|
|
60
|
+
suffix = suffix.replace(/%/g, "");
|
|
61
|
+
return new ExportCell(value.value, { text: prefix + formatted + (profile.percent ? "%" : "") + suffix,
|
|
62
|
+
...(value.presentation ? { presentation: value.presentation } : {}), ...(value.link ? { link: value.link } : {}) });
|
|
63
|
+
});
|
|
64
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { PortableSheetOptions } from "../../xlsx/index.js";
|
|
2
|
+
import type { CanopyCapture, CanopyExportColumn, CanopyExportRow } from "./types.js";
|
|
3
|
+
/** One serial enumeration's current metadata; the worksheet serializes each yielded row before requesting the next. */
|
|
4
|
+
export interface CanopyPivotMapping {
|
|
5
|
+
readonly columns: readonly CanopyExportColumn[];
|
|
6
|
+
readonly sheet: PortableSheetOptions;
|
|
7
|
+
observe(row: CanopyExportRow): void;
|
|
8
|
+
}
|
|
9
|
+
/** Qualify the explicit pivot path before flat/grouped handling; never evaluate query or aggregate data. */
|
|
10
|
+
export declare function canopyPivot(request: CanopyCapture["request"]): CanopyPivotMapping | undefined;
|
|
11
|
+
/** Per-cell formats preserve already-computed fractional percentages, ranks and differences. */
|
|
12
|
+
export declare function pivotNumberFormat(cell: {
|
|
13
|
+
readonly mode?: string;
|
|
14
|
+
readonly numberFormat?: string;
|
|
15
|
+
}): string;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
function presentation(input, axes) {
|
|
2
|
+
const { axisKey, outlineLevel, summary, grandTotal, hidden, collapsed } = input;
|
|
3
|
+
if (typeof axisKey !== "string" || !axes.has(axisKey) || !Number.isInteger(outlineLevel) || outlineLevel < 0 || outlineLevel > 7 ||
|
|
4
|
+
[summary, grandTotal, hidden, collapsed].some(flag => typeof flag !== "boolean"))
|
|
5
|
+
throw new TypeError("Invalid frozen Canopy pivot axis presentation.");
|
|
6
|
+
return Object.freeze({ level: outlineLevel, hidden: hidden, collapsed: collapsed });
|
|
7
|
+
}
|
|
8
|
+
/** Qualify the explicit pivot path before flat/grouped handling; never evaluate query or aggregate data. */
|
|
9
|
+
export function canopyPivot(request) {
|
|
10
|
+
if (request.pivot === undefined)
|
|
11
|
+
return undefined;
|
|
12
|
+
const pivot = request.pivot;
|
|
13
|
+
if (!pivot || typeof pivot !== "object" || request.grouping !== undefined || !Array.isArray(request.columns) ||
|
|
14
|
+
request.scope !== "filtered" || !Number.isSafeInteger(request.recordCount) || request.recordCount < 0 ||
|
|
15
|
+
!pivot.definition || !Array.isArray(pivot.definition.rows) || pivot.definition.rows.length > 4 ||
|
|
16
|
+
!Array.isArray(pivot.definition.columns) || pivot.definition.columns.length > 2 ||
|
|
17
|
+
!Array.isArray(pivot.definition.values) || !pivot.definition.values.length || pivot.definition.values.length > 32 ||
|
|
18
|
+
pivot.definition.values.some(value => typeof value !== "string") ||
|
|
19
|
+
!Number.isSafeInteger(pivot.distinctColumns) || pivot.distinctColumns < 0 || typeof pivot.columnsLimited !== "boolean" ||
|
|
20
|
+
!Array.isArray(pivot.retainedColumns) || !Array.isArray(pivot.columnGroups))
|
|
21
|
+
throw new TypeError("Invalid explicit Canopy pivot descriptor.");
|
|
22
|
+
const axes = (nodes) => {
|
|
23
|
+
if (!Array.isArray(nodes) || nodes.length > 100001)
|
|
24
|
+
throw new TypeError("Pivot axes require bounded accepted identities.");
|
|
25
|
+
const keys = new Set();
|
|
26
|
+
for (const node of nodes) {
|
|
27
|
+
if (!node || typeof node.key !== "string" || !node.key || keys.has(node.key) || !Array.isArray(node.path) || typeof node.other !== "boolean")
|
|
28
|
+
throw new TypeError("Invalid or duplicate Canopy pivot axis identity.");
|
|
29
|
+
keys.add(node.key);
|
|
30
|
+
}
|
|
31
|
+
for (const node of nodes)
|
|
32
|
+
if (node.parent !== undefined && !keys.has(node.parent))
|
|
33
|
+
throw new TypeError("Unknown Canopy pivot parent identity.");
|
|
34
|
+
return keys;
|
|
35
|
+
};
|
|
36
|
+
const rowKeys = axes(pivot.rowAxis), columnKeys = axes(pivot.columnAxis);
|
|
37
|
+
const columns = request.columns.map((column, index) => {
|
|
38
|
+
if (index === 0 && column.axisKey === undefined && column.kind === "text")
|
|
39
|
+
return Object.freeze({ ...column });
|
|
40
|
+
const outline = presentation(column, columnKeys);
|
|
41
|
+
return Object.freeze({ ...column, outlineLevel: outline.level, hidden: outline.hidden, collapsed: outline.collapsed });
|
|
42
|
+
});
|
|
43
|
+
// Ranges are descriptor metadata, not another body. Validate them against the same ordered columns.
|
|
44
|
+
if (pivot.columnGroups.length > columns.length)
|
|
45
|
+
throw new RangeError("Pivot column group count exceeds projected columns.");
|
|
46
|
+
for (const group of pivot.columnGroups) {
|
|
47
|
+
if (!group || !columnKeys.has(group.key) || !Number.isSafeInteger(group.firstColumn) || group.firstColumn < 0 ||
|
|
48
|
+
!Number.isSafeInteger(group.columnCount) || group.columnCount < 1 || group.firstColumn + group.columnCount > columns.length ||
|
|
49
|
+
!Number.isInteger(group.depth) || group.depth < 1 || group.depth > 7 ||
|
|
50
|
+
typeof group.hidden !== "boolean" || typeof group.collapsed !== "boolean")
|
|
51
|
+
throw new TypeError("Invalid Canopy pivot column range.");
|
|
52
|
+
}
|
|
53
|
+
let current;
|
|
54
|
+
const sheet = Object.freeze({ outlineSummaryBelow: false, outlineSummaryRight: false,
|
|
55
|
+
maxOutlineLevel: 7, rowOutline: () => current,
|
|
56
|
+
columnOutlines: Object.freeze(columns.flatMap((column, firstColumn) => column.axisKey === undefined ? [] :
|
|
57
|
+
[Object.freeze({ firstColumn, columnCount: 1, level: column.outlineLevel, hidden: column.hidden, collapsed: column.collapsed })])) });
|
|
58
|
+
return Object.freeze({ columns: Object.freeze(columns), sheet,
|
|
59
|
+
observe(row) { current = presentation(row, rowKeys); } });
|
|
60
|
+
}
|
|
61
|
+
/** Per-cell formats preserve already-computed fractional percentages, ranks and differences. */
|
|
62
|
+
export function pivotNumberFormat(cell) {
|
|
63
|
+
if (!["value", "percentGrandTotal", "percentParent", "percentColumn", "percentRow", "runningTotal", "rank", "difference", "percentChange"].includes(cell.mode ?? "") ||
|
|
64
|
+
typeof cell.numberFormat !== "string" || !cell.numberFormat.length)
|
|
65
|
+
throw new TypeError("Numeric pivot cells require a frozen mode and native numberFormat.");
|
|
66
|
+
return cell.numberFormat;
|
|
67
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ExportCell, checkAbort, inputRows } from "../../core/index.js";
|
|
2
|
+
import { canopyPivot, pivotNumberFormat } from "./pivot.js";
|
|
2
3
|
import { datetime } from "./dates.js";
|
|
3
4
|
import { captureFields } from "../../internal/capture.js";
|
|
4
5
|
import { copyColumns } from "../../internal/rows.js";
|
|
@@ -6,6 +7,14 @@ import { copyCellPresentation } from "../../core/presentation.js";
|
|
|
6
7
|
import { canopyDiagnostics } from "./diagnostics.js";
|
|
7
8
|
import { canopyNumberFormat, canopyXlsxWidth } from "./presentation.js";
|
|
8
9
|
const columnFields = ["width", "format", "wrapText", "alignment", "rowHeader", "groups"];
|
|
10
|
+
const rawIdentities = new WeakMap();
|
|
11
|
+
/** @internal Grouping uses captured identity even when a detail cell displays a relative-link label. */
|
|
12
|
+
export function canopyIdentityValue(value) {
|
|
13
|
+
if (!(value instanceof ExportCell))
|
|
14
|
+
return value;
|
|
15
|
+
const original = rawIdentities.get(value);
|
|
16
|
+
return original === undefined ? value.value : original;
|
|
17
|
+
}
|
|
9
18
|
/** Map an immutable CanopyX record capture to a writer without querying the grid or retaining its body. */
|
|
10
19
|
export function createCanopyExport(capture, format, options = {}) {
|
|
11
20
|
return prepareCanopyExport(capture, format, options).source;
|
|
@@ -17,12 +26,16 @@ export function prepareCanopyExport(capture, format, options = {}) {
|
|
|
17
26
|
throw new TypeError("Canopy export format must be xlsx, csv or pdf.");
|
|
18
27
|
if (!capture || typeof capture.rows !== "function" || !capture.request)
|
|
19
28
|
throw new TypeError("A portable CanopyX capture with request and rows() is required.");
|
|
20
|
-
const request = captureFields(capture.request, ["columns", "recordCount", "values", "presentation", "timeZone", "revision", "scope", "total", "matched", "selection", "query", "generatedAt", "grouping", "formatRules"]);
|
|
29
|
+
const request = captureFields(capture.request, ["columns", "recordCount", "values", "presentation", "timeZone", "revision", "scope", "total", "matched", "selection", "query", "generatedAt", "grouping", "pivot", "formatRules"]);
|
|
30
|
+
const pivot = canopyPivot(request);
|
|
21
31
|
const signal = options.signal, values = request.values;
|
|
22
32
|
if (!Array.isArray(request.columns) || !request.columns.length || (request.recordCount !== null && (!Number.isSafeInteger(request.recordCount) || request.recordCount < 0)) ||
|
|
23
33
|
(values !== "raw" && values !== "display") || (request.timeZone !== "utc" && request.timeZone !== "local") || typeof request.revision !== "string")
|
|
24
34
|
throw new TypeError("Invalid portable CanopyX capture metadata.");
|
|
25
35
|
const dateMode = options.datetime ?? "preserve", report = canopyDiagnostics(format, options);
|
|
36
|
+
// These captured presentations have a complete scalar/text projection. Report
|
|
37
|
+
// their visual loss without treating an ordinary report export as unsupported.
|
|
38
|
+
const fallback = canopyDiagnostics(format, { ...options, unsupportedPresentation: "text" });
|
|
26
39
|
const clock = options.xlsx?.dateMode ?? request.timeZone;
|
|
27
40
|
if (clock !== "utc" && clock !== "local")
|
|
28
41
|
throw new TypeError("XLSX dateMode must be utc or local.");
|
|
@@ -33,8 +46,10 @@ export function prepareCanopyExport(capture, format, options = {}) {
|
|
|
33
46
|
return;
|
|
34
47
|
if (!Array.isArray(items) || items.some(item => typeof item !== "string"))
|
|
35
48
|
throw new TypeError("Canopy presentation diagnostics must be strings.");
|
|
36
|
-
for (const code of items)
|
|
37
|
-
|
|
49
|
+
for (const code of items) {
|
|
50
|
+
const diagnostic = { code, ...(rowId === undefined ? {} : { rowId }), ...(columnId === undefined ? {} : { columnId }) };
|
|
51
|
+
(code === "relative-link" || code === "history-series" ? fallback : report)(diagnostic);
|
|
52
|
+
}
|
|
38
53
|
};
|
|
39
54
|
if (request.presentation !== "text" && request.presentation !== "semantic")
|
|
40
55
|
throw new TypeError("Canopy captures must declare text or semantic presentation.");
|
|
@@ -50,11 +65,11 @@ export function prepareCanopyExport(capture, format, options = {}) {
|
|
|
50
65
|
throw new TypeError("Canopy tones must be strings.");
|
|
51
66
|
const style = tones.get(name);
|
|
52
67
|
if (!style && name !== "neutral")
|
|
53
|
-
|
|
68
|
+
fallback({ code: "UNMAPPED_TONE:" + name, rowId, ...(columnId === undefined ? {} : { columnId }) });
|
|
54
69
|
return style;
|
|
55
70
|
};
|
|
56
71
|
const ids = new Set();
|
|
57
|
-
const specs = request.columns.map(input => {
|
|
72
|
+
const specs = (pivot?.columns ?? request.columns).map(input => {
|
|
58
73
|
const fields = captureFields(input, ["id", "title", "kind", "width", "pinned", "format", "wrap", "alignment", "diagnostics"]);
|
|
59
74
|
const column = Object.freeze({ ...fields,
|
|
60
75
|
...(fields.width === undefined ? {} : { width: Object.freeze(captureFields(fields.width, ["unit", "preferred", "minimum", "maximum"])) }),
|
|
@@ -65,7 +80,7 @@ export function prepareCanopyExport(capture, format, options = {}) {
|
|
|
65
80
|
(column.width !== undefined && (column.width.unit !== "css-px" || !Number.isFinite(column.width.preferred) ||
|
|
66
81
|
!Number.isFinite(column.width.minimum) || column.width.minimum <= 0 || column.width.preferred < column.width.minimum ||
|
|
67
82
|
column.width.maximum !== undefined && (!Number.isFinite(column.width.maximum) || column.width.maximum < column.width.preferred))) ||
|
|
68
|
-
(request.presentation === "semantic" && (column.wrap === undefined || column.alignment === undefined || column.width === undefined)))
|
|
83
|
+
(!pivot && request.presentation === "semantic" && (column.wrap === undefined || column.alignment === undefined || column.width === undefined)))
|
|
69
84
|
throw new TypeError("Invalid or duplicate Canopy export column.");
|
|
70
85
|
ids.add(column.id);
|
|
71
86
|
diagnostics(column.diagnostics, undefined, column.id);
|
|
@@ -74,16 +89,20 @@ export function prepareCanopyExport(capture, format, options = {}) {
|
|
|
74
89
|
if (!columnFields.includes(key))
|
|
75
90
|
throw new TypeError("Unsupported Canopy column option: " + key);
|
|
76
91
|
const override = captureFields(selected, columnFields);
|
|
77
|
-
const numericFormat = format === "xlsx" && values === "raw" && column.kind === "number" && column.format !== undefined && override.format === undefined
|
|
92
|
+
const numericFormat = (format === "xlsx" || format === "pdf") && values === "raw" && column.kind === "number" && column.format !== undefined && override.format === undefined
|
|
78
93
|
? canopyNumberFormat(column.format, report, column.id) : undefined;
|
|
79
94
|
const [captured] = copyColumns([{ ...override, key: column.id, header: column.title,
|
|
80
95
|
...(format === "xlsx" && override.width === undefined && column.width !== undefined ? { width: canopyXlsxWidth(column.width.preferred) } : {}),
|
|
81
96
|
...(override.format === undefined && numericFormat !== undefined ? { format: numericFormat } : {}),
|
|
82
97
|
...(format === "xlsx" && values === "raw" && column.kind === "datetime" && override.format === undefined ? { format: "yyyy-mm-dd hh:mm:ss.000" } : {}),
|
|
83
98
|
...(values === "raw" && column.kind === "number" ? { type: "number" } : {}),
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
99
|
+
// Screen nowrap is not a promise that its CSS width will survive PDF fitting.
|
|
100
|
+
// PDF defaults to lossless wrapping; an explicit writer override stays strict.
|
|
101
|
+
...(format === "pdf" ? { wrapText: override.wrapText ?? true } :
|
|
102
|
+
override.wrapText === undefined && column.wrap === undefined ? {} : { wrapText: override.wrapText ?? column.wrap }),
|
|
103
|
+
...(override.alignment === undefined && column.alignment === undefined ?
|
|
104
|
+
format === "pdf" && column.kind === "number" ? { alignment: "right" } : {} : { alignment: override.alignment ?? column.alignment }) }]);
|
|
105
|
+
return Object.freeze({ id: column.id, kind: column.kind, input: column, nativeFormatOverride: override.format, column: Object.freeze(captured) });
|
|
87
106
|
});
|
|
88
107
|
const rowCount = request.recordCount;
|
|
89
108
|
const source = Object.freeze({ columns: Object.freeze(specs.map(spec => spec.column)), rowCount, async *rows() {
|
|
@@ -93,6 +112,7 @@ export function prepareCanopyExport(capture, format, options = {}) {
|
|
|
93
112
|
checkAbort(signal);
|
|
94
113
|
if (!row || typeof row.id !== "string" || !row.cells || typeof row.cells !== "object")
|
|
95
114
|
throw new TypeError("Invalid Canopy export record.");
|
|
115
|
+
pivot?.observe(row);
|
|
96
116
|
diagnostics(row.diagnostics, row.id);
|
|
97
117
|
const rowStyle = tone(row.tone, row.id), result = [];
|
|
98
118
|
for (const spec of specs) {
|
|
@@ -104,13 +124,29 @@ export function prepareCanopyExport(capture, format, options = {}) {
|
|
|
104
124
|
(typeof cell.value === "number" && (!Number.isFinite(cell.value) || Math.abs(cell.value) > Number.MAX_SAFE_INTEGER)))
|
|
105
125
|
throw new TypeError("A portable Canopy GridExportCell with scalar value and resolved text is required.");
|
|
106
126
|
diagnostics(cell.diagnostics, row.id, spec.id);
|
|
107
|
-
|
|
127
|
+
// A relative destination is navigation metadata, not the visible label.
|
|
128
|
+
// History captures already carry their frozen latest scalar (or null).
|
|
129
|
+
const relativeLabel = spec.kind === "text" && cell.diagnostics?.includes("relative-link");
|
|
130
|
+
let value = values === "display" || relativeLabel ? cell.text : cell.value;
|
|
108
131
|
if (format === "xlsx" && values === "raw" && spec.kind === "datetime" && typeof value === "string")
|
|
109
132
|
value = datetime(value, dateMode, clock);
|
|
110
|
-
const
|
|
133
|
+
const capturedFormat = pivot && spec.kind === "number" && cell.value !== null ? pivotNumberFormat(cell) : undefined;
|
|
134
|
+
const nativeFormat = capturedFormat === undefined ? undefined : spec.nativeFormatOverride === "" ? "General" : spec.nativeFormatOverride ?? capturedFormat;
|
|
135
|
+
const summary = format === "pdf" && pivot && (row.summary || row.grandTotal);
|
|
136
|
+
const cellStyle = tone(cell.tone, row.id, spec.id), presentation = rowStyle || cellStyle || nativeFormat || summary ? {
|
|
137
|
+
...rowStyle, ...(summary ? { bold: true } : {}), ...cellStyle,
|
|
138
|
+
...((format === "xlsx" || format === "pdf") && values === "raw" && nativeFormat !== undefined ? { numberFormat: nativeFormat } : {})
|
|
139
|
+
} : undefined;
|
|
111
140
|
// CSV has no presentation or link metadata: emit its selected scalar directly.
|
|
112
141
|
// This also avoids a frozen wrapper for every cell in large CSV captures.
|
|
113
|
-
|
|
142
|
+
if (format === "csv")
|
|
143
|
+
result.push(value);
|
|
144
|
+
else {
|
|
145
|
+
const exported = new ExportCell(value, { text: cell.text, ...(presentation ? { presentation } : {}), ...(cell.link === undefined ? {} : { link: cell.link }) });
|
|
146
|
+
if (relativeLabel)
|
|
147
|
+
rawIdentities.set(exported, cell.value);
|
|
148
|
+
result.push(exported);
|
|
149
|
+
}
|
|
114
150
|
}
|
|
115
151
|
if (rowCount !== null && count >= rowCount)
|
|
116
152
|
throw new TypeError("Canopy capture exceeded its declared recordCount.");
|
|
@@ -120,5 +156,5 @@ export function prepareCanopyExport(capture, format, options = {}) {
|
|
|
120
156
|
if (rowCount !== null && count !== rowCount)
|
|
121
157
|
throw new TypeError("Canopy capture did not produce its declared recordCount.");
|
|
122
158
|
} });
|
|
123
|
-
return Object.freeze({ source, request: Object.freeze({ ...request, columns: Object.freeze(specs.map(spec => spec.input)) }), report, tones });
|
|
159
|
+
return Object.freeze({ source, request: Object.freeze({ ...request, columns: Object.freeze(specs.map(spec => spec.input)) }), report, tones, pivot });
|
|
124
160
|
}
|
|
@@ -7,6 +7,9 @@ import type { PdfOptions, GroupedPdfOptions } from "../../pdf/index.js";
|
|
|
7
7
|
export interface CanopyExportCell {
|
|
8
8
|
readonly value: string | number | boolean | null;
|
|
9
9
|
readonly text: string;
|
|
10
|
+
/** Frozen pivot display semantics; values are already computed by CanopyX. */
|
|
11
|
+
readonly mode?: "value" | "percentGrandTotal" | "percentParent" | "percentColumn" | "percentRow" | "runningTotal" | "rank" | "difference" | "percentChange";
|
|
12
|
+
readonly numberFormat?: string;
|
|
10
13
|
readonly tone?: string;
|
|
11
14
|
readonly link?: ExportLink;
|
|
12
15
|
readonly diagnostics?: readonly string[];
|
|
@@ -18,7 +21,7 @@ export interface CanopyNumberFormat {
|
|
|
18
21
|
readonly prefix?: string;
|
|
19
22
|
readonly suffix?: string;
|
|
20
23
|
}
|
|
21
|
-
export interface CanopyExportColumn {
|
|
24
|
+
export interface CanopyExportColumn extends Partial<CanopyPivotAxisPresentation> {
|
|
22
25
|
readonly id: string;
|
|
23
26
|
readonly title: string;
|
|
24
27
|
readonly kind: "text" | "number" | "datetime";
|
|
@@ -34,12 +37,50 @@ export interface CanopyExportColumn {
|
|
|
34
37
|
readonly alignment?: "left" | "right";
|
|
35
38
|
readonly diagnostics?: readonly string[];
|
|
36
39
|
}
|
|
37
|
-
export interface CanopyExportRow {
|
|
40
|
+
export interface CanopyExportRow extends Partial<CanopyPivotAxisPresentation> {
|
|
38
41
|
readonly id: string;
|
|
39
42
|
readonly cells: Readonly<Record<string, CanopyExportCell>>;
|
|
40
43
|
readonly tone?: string;
|
|
41
44
|
readonly diagnostics?: readonly string[];
|
|
42
45
|
}
|
|
46
|
+
/** Opaque accepted-axis identity and frozen presentation; titles never determine identity. */
|
|
47
|
+
export interface CanopyPivotAxisPresentation {
|
|
48
|
+
readonly axisKey: string;
|
|
49
|
+
readonly outlineLevel: number;
|
|
50
|
+
readonly summary: boolean;
|
|
51
|
+
readonly grandTotal: boolean;
|
|
52
|
+
readonly collapsed: boolean;
|
|
53
|
+
readonly hidden: boolean;
|
|
54
|
+
}
|
|
55
|
+
export interface CanopyPivotAxis {
|
|
56
|
+
readonly key: string;
|
|
57
|
+
readonly parent?: string;
|
|
58
|
+
readonly path: readonly (string | number | boolean | null)[];
|
|
59
|
+
readonly other: boolean;
|
|
60
|
+
}
|
|
61
|
+
export interface CanopyPivotColumnGroup {
|
|
62
|
+
readonly key: string;
|
|
63
|
+
readonly parent?: string;
|
|
64
|
+
readonly firstColumn: number;
|
|
65
|
+
readonly columnCount: number;
|
|
66
|
+
readonly depth: number;
|
|
67
|
+
readonly collapsed: boolean;
|
|
68
|
+
readonly hidden: boolean;
|
|
69
|
+
}
|
|
70
|
+
/** Full-query pivot metadata. Projected columns and repeatable rows remain in the capture. */
|
|
71
|
+
export interface CanopyPivotDescriptor {
|
|
72
|
+
readonly definition: {
|
|
73
|
+
readonly rows: readonly object[];
|
|
74
|
+
readonly columns: readonly object[];
|
|
75
|
+
readonly values: readonly string[];
|
|
76
|
+
};
|
|
77
|
+
readonly rowAxis: readonly CanopyPivotAxis[];
|
|
78
|
+
readonly columnAxis: readonly CanopyPivotAxis[];
|
|
79
|
+
readonly columnGroups: readonly CanopyPivotColumnGroup[];
|
|
80
|
+
readonly distinctColumns: number;
|
|
81
|
+
readonly retainedColumns: readonly (readonly (string | number | boolean | null)[])[];
|
|
82
|
+
readonly columnsLimited: boolean;
|
|
83
|
+
}
|
|
43
84
|
/** Captured half-open detail ranges, never ranges from a different export scope. */
|
|
44
85
|
export interface CanopyExportGroup {
|
|
45
86
|
readonly key: string;
|
|
@@ -116,6 +157,8 @@ export interface CanopyCapture {
|
|
|
116
157
|
readonly query?: object;
|
|
117
158
|
readonly generatedAt?: string;
|
|
118
159
|
readonly grouping?: CanopyExportGrouping;
|
|
160
|
+
/** Explicit pre-aggregated projection; never interpreted as ordinary grouped records. */
|
|
161
|
+
readonly pivot?: CanopyPivotDescriptor;
|
|
119
162
|
readonly formatRules?: readonly CanopyFormatRule[];
|
|
120
163
|
};
|
|
121
164
|
/** Fresh serial enumeration. The signal must reach the source's in-flight page requests. */
|