@evotecit/officeimo 0.1.2 → 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 +59 -51
- package/bundles/officeimo-canopyx.js +1553 -314
- package/bundles/officeimo-canopyx.mjs +1497 -269
- package/bundles/officeimo-csv.js +18 -15
- package/bundles/officeimo-csv.mjs +16 -13
- package/bundles/officeimo-datatables.js +463 -301
- package/bundles/officeimo-datatables.mjs +420 -259
- package/bundles/officeimo-pdf.js +148 -65
- package/bundles/officeimo-pdf.mjs +124 -41
- package/bundles/officeimo-xlsx.js +177 -101
- package/bundles/officeimo-xlsx.mjs +149 -74
- package/bundles/officeimo.js +461 -299
- package/bundles/officeimo.mjs +419 -258
- package/dist/csv/index.js +16 -13
- package/dist/integrations/canopyx/diagnostics.d.ts +3 -0
- package/dist/integrations/canopyx/diagnostics.js +17 -0
- package/dist/integrations/canopyx/grouping.d.ts +6 -0
- package/dist/integrations/canopyx/grouping.js +198 -0
- package/dist/integrations/canopyx/index.d.ts +2 -2
- package/dist/integrations/canopyx/index.js +89 -15
- package/dist/integrations/canopyx/metadata.d.ts +4 -0
- package/dist/integrations/canopyx/metadata.js +51 -0
- 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/presentation.d.ts +8 -0
- package/dist/integrations/canopyx/presentation.js +40 -0
- package/dist/integrations/canopyx/rule-predicates.d.ts +3 -0
- package/dist/integrations/canopyx/rule-predicates.js +110 -0
- package/dist/integrations/canopyx/rules.d.ts +6 -0
- package/dist/integrations/canopyx/rules.js +176 -0
- package/dist/integrations/canopyx/source.js +69 -31
- package/dist/integrations/canopyx/types.d.ts +134 -10
- package/dist/integrations/canopyx/workbook.d.ts +6 -0
- package/dist/integrations/canopyx/workbook.js +52 -0
- package/dist/opc/index.js +9 -0
- package/dist/pdf/font-resources.js +33 -14
- package/dist/pdf/pages.js +60 -14
- package/dist/pdf/table-band-flow.js +7 -2
- package/dist/pdf/table-band-plan.js +9 -1
- package/dist/pdf/table-layout.js +6 -2
- package/dist/pdf/table-structure.js +9 -8
- 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,50 +1,57 @@
|
|
|
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";
|
|
5
6
|
import { copyCellPresentation } from "../../core/presentation.js";
|
|
7
|
+
import { canopyDiagnostics } from "./diagnostics.js";
|
|
8
|
+
import { canopyNumberFormat, canopyXlsxWidth } from "./presentation.js";
|
|
6
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
|
+
}
|
|
7
18
|
/** Map an immutable CanopyX record capture to a writer without querying the grid or retaining its body. */
|
|
8
19
|
export function createCanopyExport(capture, format, options = {}) {
|
|
20
|
+
return prepareCanopyExport(capture, format, options).source;
|
|
21
|
+
}
|
|
22
|
+
/** @internal Capture the input once before full-writer metadata mapping and asynchronous enumeration. */
|
|
23
|
+
export function prepareCanopyExport(capture, format, options = {}) {
|
|
9
24
|
options = captureFields(options, ["tones", "columnOptions", "unsupportedPresentation", "datetime", "xlsx", "signal", "onDiagnostic"]);
|
|
10
25
|
if (format !== "xlsx" && format !== "csv" && format !== "pdf")
|
|
11
26
|
throw new TypeError("Canopy export format must be xlsx, csv or pdf.");
|
|
12
27
|
if (!capture || typeof capture.rows !== "function" || !capture.request)
|
|
13
28
|
throw new TypeError("A portable CanopyX capture with request and rows() is required.");
|
|
14
|
-
const
|
|
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);
|
|
31
|
+
const signal = options.signal, values = request.values;
|
|
15
32
|
if (!Array.isArray(request.columns) || !request.columns.length || (request.recordCount !== null && (!Number.isSafeInteger(request.recordCount) || request.recordCount < 0)) ||
|
|
16
33
|
(values !== "raw" && values !== "display") || (request.timeZone !== "utc" && request.timeZone !== "local") || typeof request.revision !== "string")
|
|
17
34
|
throw new TypeError("Invalid portable CanopyX capture metadata.");
|
|
18
|
-
const
|
|
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" });
|
|
19
39
|
const clock = options.xlsx?.dateMode ?? request.timeZone;
|
|
20
40
|
if (clock !== "utc" && clock !== "local")
|
|
21
41
|
throw new TypeError("XLSX dateMode must be utc or local.");
|
|
22
|
-
if (policy !== "reject" && policy !== "text")
|
|
23
|
-
throw new TypeError("unsupportedPresentation must be reject or text.");
|
|
24
42
|
if (dateMode !== "preserve" && dateMode !== "typed" && dateMode !== "text")
|
|
25
43
|
throw new TypeError("datetime must be preserve, typed or text.");
|
|
26
|
-
if (notify !== undefined && typeof notify !== "function")
|
|
27
|
-
throw new TypeError("onDiagnostic must be a synchronous function.");
|
|
28
|
-
const report = (diagnostic) => {
|
|
29
|
-
if (policy === "reject")
|
|
30
|
-
throw new TypeError("Unsupported Canopy presentation: " + diagnostic.code + (diagnostic.columnId ? " (" + diagnostic.columnId + ")" : ""));
|
|
31
|
-
const result = notify?.(Object.freeze(diagnostic));
|
|
32
|
-
if (result && typeof result.then === "function") {
|
|
33
|
-
void Promise.resolve(result).catch(() => { });
|
|
34
|
-
throw new TypeError("onDiagnostic must be synchronous.");
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
44
|
const diagnostics = (items, rowId, columnId) => {
|
|
38
45
|
if (items === undefined)
|
|
39
46
|
return;
|
|
40
47
|
if (!Array.isArray(items) || items.some(item => typeof item !== "string"))
|
|
41
48
|
throw new TypeError("Canopy presentation diagnostics must be strings.");
|
|
42
|
-
for (const code of items)
|
|
43
|
-
|
|
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
|
+
}
|
|
44
53
|
};
|
|
45
|
-
if (request.presentation
|
|
46
|
-
report({ code: "TEXT_ONLY_CAPTURE" });
|
|
47
|
-
else if (request.presentation !== "semantic")
|
|
54
|
+
if (request.presentation !== "text" && request.presentation !== "semantic")
|
|
48
55
|
throw new TypeError("Canopy captures must declare text or semantic presentation.");
|
|
49
56
|
const tones = new Map(Object.entries(options.tones ?? {}).map(([name, style]) => {
|
|
50
57
|
if (!style || typeof style !== "object" || Array.isArray(style))
|
|
@@ -57,19 +64,23 @@ export function createCanopyExport(capture, format, options = {}) {
|
|
|
57
64
|
if (typeof name !== "string")
|
|
58
65
|
throw new TypeError("Canopy tones must be strings.");
|
|
59
66
|
const style = tones.get(name);
|
|
60
|
-
if (!style)
|
|
61
|
-
|
|
67
|
+
if (!style && name !== "neutral")
|
|
68
|
+
fallback({ code: "UNMAPPED_TONE:" + name, rowId, ...(columnId === undefined ? {} : { columnId }) });
|
|
62
69
|
return style;
|
|
63
70
|
};
|
|
64
71
|
const ids = new Set();
|
|
65
|
-
const specs = request.columns.map(
|
|
72
|
+
const specs = (pivot?.columns ?? request.columns).map(input => {
|
|
73
|
+
const fields = captureFields(input, ["id", "title", "kind", "width", "pinned", "format", "wrap", "alignment", "diagnostics"]);
|
|
74
|
+
const column = Object.freeze({ ...fields,
|
|
75
|
+
...(fields.width === undefined ? {} : { width: Object.freeze(captureFields(fields.width, ["unit", "preferred", "minimum", "maximum"])) }),
|
|
76
|
+
...(fields.format === undefined ? {} : { format: Object.freeze(captureFields(fields.format, ["minimumFractionDigits", "maximumFractionDigits", "prefix", "suffix"])) }) });
|
|
66
77
|
if (!column || typeof column.id !== "string" || !column.id || ids.has(column.id) || typeof column.title !== "string" ||
|
|
67
78
|
!["text", "number", "datetime"].includes(column.kind) ||
|
|
68
79
|
(column.wrap !== undefined && typeof column.wrap !== "boolean") || (column.alignment !== undefined && !["left", "right"].includes(column.alignment)) ||
|
|
69
80
|
(column.width !== undefined && (column.width.unit !== "css-px" || !Number.isFinite(column.width.preferred) ||
|
|
70
81
|
!Number.isFinite(column.width.minimum) || column.width.minimum <= 0 || column.width.preferred < column.width.minimum ||
|
|
71
82
|
column.width.maximum !== undefined && (!Number.isFinite(column.width.maximum) || column.width.maximum < column.width.preferred))) ||
|
|
72
|
-
(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)))
|
|
73
84
|
throw new TypeError("Invalid or duplicate Canopy export column.");
|
|
74
85
|
ids.add(column.id);
|
|
75
86
|
diagnostics(column.diagnostics, undefined, column.id);
|
|
@@ -78,20 +89,30 @@ export function createCanopyExport(capture, format, options = {}) {
|
|
|
78
89
|
if (!columnFields.includes(key))
|
|
79
90
|
throw new TypeError("Unsupported Canopy column option: " + key);
|
|
80
91
|
const override = captureFields(selected, columnFields);
|
|
92
|
+
const numericFormat = (format === "xlsx" || format === "pdf") && values === "raw" && column.kind === "number" && column.format !== undefined && override.format === undefined
|
|
93
|
+
? canopyNumberFormat(column.format, report, column.id) : undefined;
|
|
81
94
|
const [captured] = copyColumns([{ ...override, key: column.id, header: column.title,
|
|
95
|
+
...(format === "xlsx" && override.width === undefined && column.width !== undefined ? { width: canopyXlsxWidth(column.width.preferred) } : {}),
|
|
96
|
+
...(override.format === undefined && numericFormat !== undefined ? { format: numericFormat } : {}),
|
|
97
|
+
...(format === "xlsx" && values === "raw" && column.kind === "datetime" && override.format === undefined ? { format: "yyyy-mm-dd hh:mm:ss.000" } : {}),
|
|
82
98
|
...(values === "raw" && column.kind === "number" ? { type: "number" } : {}),
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
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) });
|
|
86
106
|
});
|
|
87
107
|
const rowCount = request.recordCount;
|
|
88
|
-
|
|
108
|
+
const source = Object.freeze({ columns: Object.freeze(specs.map(spec => spec.column)), rowCount, async *rows() {
|
|
89
109
|
checkAbort(signal);
|
|
90
110
|
let count = 0;
|
|
91
111
|
for await (const row of inputRows(capture.rows(signal ? { signal } : {}), signal)) {
|
|
92
112
|
checkAbort(signal);
|
|
93
113
|
if (!row || typeof row.id !== "string" || !row.cells || typeof row.cells !== "object")
|
|
94
114
|
throw new TypeError("Invalid Canopy export record.");
|
|
115
|
+
pivot?.observe(row);
|
|
95
116
|
diagnostics(row.diagnostics, row.id);
|
|
96
117
|
const rowStyle = tone(row.tone, row.id), result = [];
|
|
97
118
|
for (const spec of specs) {
|
|
@@ -103,13 +124,29 @@ export function createCanopyExport(capture, format, options = {}) {
|
|
|
103
124
|
(typeof cell.value === "number" && (!Number.isFinite(cell.value) || Math.abs(cell.value) > Number.MAX_SAFE_INTEGER)))
|
|
104
125
|
throw new TypeError("A portable Canopy GridExportCell with scalar value and resolved text is required.");
|
|
105
126
|
diagnostics(cell.diagnostics, row.id, spec.id);
|
|
106
|
-
|
|
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;
|
|
107
131
|
if (format === "xlsx" && values === "raw" && spec.kind === "datetime" && typeof value === "string")
|
|
108
132
|
value = datetime(value, dateMode, clock);
|
|
109
|
-
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;
|
|
110
140
|
// CSV has no presentation or link metadata: emit its selected scalar directly.
|
|
111
141
|
// This also avoids a frozen wrapper for every cell in large CSV captures.
|
|
112
|
-
|
|
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
|
+
}
|
|
113
150
|
}
|
|
114
151
|
if (rowCount !== null && count >= rowCount)
|
|
115
152
|
throw new TypeError("Canopy capture exceeded its declared recordCount.");
|
|
@@ -119,4 +156,5 @@ export function createCanopyExport(capture, format, options = {}) {
|
|
|
119
156
|
if (rowCount !== null && count !== rowCount)
|
|
120
157
|
throw new TypeError("Canopy capture did not produce its declared recordCount.");
|
|
121
158
|
} });
|
|
159
|
+
return Object.freeze({ source, request: Object.freeze({ ...request, columns: Object.freeze(specs.map(spec => spec.input)) }), report, tones, pivot });
|
|
122
160
|
}
|
|
@@ -2,16 +2,26 @@ import type { CellPresentation, ColumnSettings, ExportLimits, ExportProgress, Ex
|
|
|
2
2
|
import type { ExportLink } from "../../core/links.js";
|
|
3
3
|
import type { CsvOptions } from "../../csv/index.js";
|
|
4
4
|
import type { XlsxOptions } from "../../xlsx/index.js";
|
|
5
|
-
import type { PdfOptions } from "../../pdf/index.js";
|
|
5
|
+
import type { PdfOptions, GroupedPdfOptions } from "../../pdf/index.js";
|
|
6
6
|
/** Structural portable capture. CanopyX owns queries, selection, presenters and revision validation. */
|
|
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[];
|
|
13
16
|
}
|
|
14
|
-
|
|
17
|
+
/** CanopyX's declarative numeric intent; this is never parsed as native Excel syntax. */
|
|
18
|
+
export interface CanopyNumberFormat {
|
|
19
|
+
readonly minimumFractionDigits?: number;
|
|
20
|
+
readonly maximumFractionDigits?: number;
|
|
21
|
+
readonly prefix?: string;
|
|
22
|
+
readonly suffix?: string;
|
|
23
|
+
}
|
|
24
|
+
export interface CanopyExportColumn extends Partial<CanopyPivotAxisPresentation> {
|
|
15
25
|
readonly id: string;
|
|
16
26
|
readonly title: string;
|
|
17
27
|
readonly kind: "text" | "number" | "datetime";
|
|
@@ -21,16 +31,116 @@ export interface CanopyExportColumn {
|
|
|
21
31
|
readonly minimum: number;
|
|
22
32
|
readonly maximum?: number;
|
|
23
33
|
};
|
|
34
|
+
readonly pinned?: "left" | "right" | null;
|
|
35
|
+
readonly format?: CanopyNumberFormat;
|
|
24
36
|
readonly wrap?: boolean;
|
|
25
37
|
readonly alignment?: "left" | "right";
|
|
26
38
|
readonly diagnostics?: readonly string[];
|
|
27
39
|
}
|
|
28
|
-
export interface CanopyExportRow {
|
|
40
|
+
export interface CanopyExportRow extends Partial<CanopyPivotAxisPresentation> {
|
|
29
41
|
readonly id: string;
|
|
30
42
|
readonly cells: Readonly<Record<string, CanopyExportCell>>;
|
|
31
43
|
readonly tone?: string;
|
|
32
44
|
readonly diagnostics?: readonly string[];
|
|
33
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
|
+
}
|
|
84
|
+
/** Captured half-open detail ranges, never ranges from a different export scope. */
|
|
85
|
+
export interface CanopyExportGroup {
|
|
86
|
+
readonly key: string;
|
|
87
|
+
readonly value: string | number | boolean | null;
|
|
88
|
+
readonly text?: string;
|
|
89
|
+
readonly offset: number;
|
|
90
|
+
readonly count: number;
|
|
91
|
+
readonly aggregates: Readonly<Record<string, number | null>>;
|
|
92
|
+
readonly groups?: readonly CanopyExportGroup[];
|
|
93
|
+
}
|
|
94
|
+
export interface CanopyExportGrouping {
|
|
95
|
+
readonly levels: readonly {
|
|
96
|
+
readonly column: string;
|
|
97
|
+
readonly direction: "asc" | "desc";
|
|
98
|
+
readonly title?: string;
|
|
99
|
+
}[];
|
|
100
|
+
readonly aggregates: readonly {
|
|
101
|
+
readonly id: string;
|
|
102
|
+
readonly column: string;
|
|
103
|
+
readonly operation: string;
|
|
104
|
+
readonly label?: string;
|
|
105
|
+
}[];
|
|
106
|
+
readonly totals: Readonly<Record<string, number | null>>;
|
|
107
|
+
readonly groups: readonly CanopyExportGroup[];
|
|
108
|
+
}
|
|
109
|
+
export interface CanopyRuleFilter {
|
|
110
|
+
readonly column: string;
|
|
111
|
+
/** Native numeric/typed-UTC-date comparisons and null tests are bounded; unrepresentable type/culture profiles need explicit text fallback. */
|
|
112
|
+
readonly operator: string;
|
|
113
|
+
readonly values?: readonly (string | number | boolean)[];
|
|
114
|
+
}
|
|
115
|
+
export interface CanopyRulePredicate {
|
|
116
|
+
readonly operator: string;
|
|
117
|
+
readonly filters?: readonly CanopyRuleFilter[];
|
|
118
|
+
readonly groups?: readonly CanopyRulePredicate[];
|
|
119
|
+
}
|
|
120
|
+
export interface CanopyFormatRule {
|
|
121
|
+
readonly id: string;
|
|
122
|
+
readonly enabled?: boolean;
|
|
123
|
+
readonly stopIfTrue?: boolean;
|
|
124
|
+
readonly column?: string;
|
|
125
|
+
readonly when?: CanopyRulePredicate;
|
|
126
|
+
readonly target?: "row" | "cell" | "columns";
|
|
127
|
+
readonly style: {
|
|
128
|
+
readonly tone?: string;
|
|
129
|
+
readonly bar?: {
|
|
130
|
+
readonly minimum?: number;
|
|
131
|
+
readonly maximum?: number;
|
|
132
|
+
readonly tone?: string;
|
|
133
|
+
readonly showValue?: boolean;
|
|
134
|
+
};
|
|
135
|
+
readonly scale?: {
|
|
136
|
+
readonly stops: readonly {
|
|
137
|
+
readonly type: string;
|
|
138
|
+
readonly value?: number;
|
|
139
|
+
readonly tone: string;
|
|
140
|
+
}[];
|
|
141
|
+
};
|
|
142
|
+
};
|
|
143
|
+
}
|
|
34
144
|
export interface CanopyCapture {
|
|
35
145
|
readonly request: {
|
|
36
146
|
readonly columns: readonly CanopyExportColumn[];
|
|
@@ -39,6 +149,17 @@ export interface CanopyCapture {
|
|
|
39
149
|
readonly presentation: "text" | "semantic";
|
|
40
150
|
readonly timeZone: "utc" | "local";
|
|
41
151
|
readonly revision: string;
|
|
152
|
+
readonly scope?: "filtered" | "selected" | "all";
|
|
153
|
+
readonly total?: number | null;
|
|
154
|
+
readonly matched?: number | null;
|
|
155
|
+
readonly selection?: readonly string[];
|
|
156
|
+
/** The actual accepted export query. OfficeIMO never evaluates or substitutes a live-view query. */
|
|
157
|
+
readonly query?: object;
|
|
158
|
+
readonly generatedAt?: string;
|
|
159
|
+
readonly grouping?: CanopyExportGrouping;
|
|
160
|
+
/** Explicit pre-aggregated projection; never interpreted as ordinary grouped records. */
|
|
161
|
+
readonly pivot?: CanopyPivotDescriptor;
|
|
162
|
+
readonly formatRules?: readonly CanopyFormatRule[];
|
|
42
163
|
};
|
|
43
164
|
/** Fresh serial enumeration. The signal must reach the source's in-flight page requests. */
|
|
44
165
|
rows(options?: {
|
|
@@ -52,21 +173,18 @@ export interface CanopyDiagnostic {
|
|
|
52
173
|
readonly columnId?: string;
|
|
53
174
|
}
|
|
54
175
|
export interface CanopySourceOptions {
|
|
55
|
-
/** Map semantic tones explicitly;
|
|
176
|
+
/** Map semantic tones explicitly; canonical neutral defaults to no override. Cell tone overrides row tone. */
|
|
56
177
|
readonly tones?: Readonly<Record<string, CellPresentation>>;
|
|
57
|
-
/** Selected-column overrides. Unselected IDs are ignored
|
|
178
|
+
/** Selected-column overrides. Unselected IDs are ignored. Native format overrides remain literal Excel syntax. */
|
|
58
179
|
readonly columnOptions?: Readonly<Record<string, Omit<Partial<ColumnSettings>, "header" | "type">>>;
|
|
59
|
-
/**
|
|
180
|
+
/** Genuine unsupported effects reject by default in XLSX/PDF; text accepts them with diagnostics. */
|
|
60
181
|
readonly unsupportedPresentation?: "reject" | "text";
|
|
61
|
-
/** XLSX: preserve uses typed Dates where exact and literal ISO text for greater precision. */
|
|
62
182
|
readonly datetime?: "preserve" | "typed" | "text";
|
|
63
|
-
/** The same clock used by the XLSX writer; defaults to the native capture's timeZone. */
|
|
64
183
|
readonly xlsx?: Pick<XlsxOptions, "dateMode">;
|
|
65
184
|
readonly signal?: AbortSignal;
|
|
66
|
-
/** Synchronous notification; throwing aborts enumeration. No unbounded diagnostic list is retained. */
|
|
67
185
|
readonly onDiagnostic?: (diagnostic: CanopyDiagnostic) => void;
|
|
68
186
|
}
|
|
69
|
-
/**
|
|
187
|
+
/** Flat, reusable typed rows. Full writers additionally map captured groups and native rules. */
|
|
70
188
|
export interface CanopyExport {
|
|
71
189
|
readonly columns: readonly (ColumnSettings & {
|
|
72
190
|
readonly key: string;
|
|
@@ -80,4 +198,10 @@ export interface CanopyWriteOptions extends CanopySourceOptions {
|
|
|
80
198
|
readonly xlsx?: Omit<XlsxOptions, "columns" | "signal" | "onProgress">;
|
|
81
199
|
readonly csv?: Omit<CsvOptions, "columns" | "signal" | "onProgress" | "valueMode">;
|
|
82
200
|
readonly pdf?: Omit<PdfOptions, "columns" | "signal" | "onProgress">;
|
|
201
|
+
/** Existing grouped-writer callbacks. Omitted labels use the documented English defaults. */
|
|
202
|
+
readonly grouped?: Partial<Pick<GroupedPdfOptions, "subtotalLabel" | "grandTotalLabel" | "includeGrandTotal" | "continuationLabel" | "groupHeadingLevel">> & {
|
|
203
|
+
readonly labelColumn?: Pick<ColumnSettings, "header">;
|
|
204
|
+
};
|
|
205
|
+
/** Add a metadata worksheet containing only captured export metadata and its accepted query. */
|
|
206
|
+
readonly about?: boolean;
|
|
83
207
|
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { XlsxOptions } from "../../xlsx/index.js";
|
|
2
|
+
import type { GroupedReportSource } from "../../core/grouped-report.js";
|
|
3
|
+
import type { ExportResult, OutputDestination } from "../../core/index.js";
|
|
4
|
+
import type { CanopyExport, CanopyWriteOptions } from "./types.js";
|
|
5
|
+
/** Compose only the adapter's data/grouped sheet and optional metadata sheet in the existing workbook owner. */
|
|
6
|
+
export declare function writeCanopyWorkbook(source: CanopyExport, grouped: GroupedReportSource | undefined, destination: OutputDestination, options: XlsxOptions, labels: CanopyWriteOptions["grouped"], about: readonly (readonly [string, string | number])[] | undefined): Promise<ExportResult>;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { Workbook, addGroupedXlsx } from "../../xlsx/index.js";
|
|
2
|
+
import { portableWorkbook } from "../../xlsx/portable.js";
|
|
3
|
+
import { withDestination } from "../../core/sinks.js";
|
|
4
|
+
/** Compose only the adapter's data/grouped sheet and optional metadata sheet in the existing workbook owner. */
|
|
5
|
+
export async function writeCanopyWorkbook(source, grouped, destination, options, labels, about) {
|
|
6
|
+
const { sheet: sheetSettings = {}, columns: _columns, ...settings } = options;
|
|
7
|
+
const { name = "Data", ...sheet } = sheetSettings;
|
|
8
|
+
if (about && name.toLowerCase() === "about")
|
|
9
|
+
throw new TypeError("The optional About worksheet needs a distinct data-sheet name.");
|
|
10
|
+
if (grouped && settings.cellValueWriters !== undefined)
|
|
11
|
+
throw new TypeError("Grouped Canopy exports use resolved source values rather than custom cellValueWriters.");
|
|
12
|
+
return withDestination(destination, async (sink) => {
|
|
13
|
+
const workbookOptions = { ...portableWorkbook(settings), sink };
|
|
14
|
+
// Grouped worksheets generate native FormulaCells; flat tables keep the portable-value boundary.
|
|
15
|
+
const book = grouped ? new Workbook(workbookOptions) : Workbook.forTable(workbookOptions);
|
|
16
|
+
try {
|
|
17
|
+
let rows, columns;
|
|
18
|
+
if (grouped) {
|
|
19
|
+
const { conditionalFormats, ...groupedSheet } = sheet;
|
|
20
|
+
const written = await addGroupedXlsx(book, grouped, {
|
|
21
|
+
labelColumn: { header: labels?.labelColumn?.header ?? "Group", width: 18 },
|
|
22
|
+
subtotalLabel: labels?.subtotalLabel ?? (group => group.label + " total"),
|
|
23
|
+
grandTotalLabel: labels?.grandTotalLabel ?? (() => "Grand total"),
|
|
24
|
+
...(labels?.includeGrandTotal === undefined ? {} : { includeGrandTotal: labels.includeGrandTotal }),
|
|
25
|
+
sheet: { ...groupedSheet, name }, ...(conditionalFormats === undefined ? {} : { conditionalFormats })
|
|
26
|
+
});
|
|
27
|
+
rows = written.rows;
|
|
28
|
+
columns = written.columns;
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
const data = book.addWorksheet(name, { boldHeader: true, autoFilter: sheet.includeHeader !== false,
|
|
32
|
+
autoSize: { minWidth: 6, maxWidth: 54 }, ...sheet, columns: source.columns });
|
|
33
|
+
await data.addRows(source.rows());
|
|
34
|
+
await data.close();
|
|
35
|
+
rows = data.rowCount;
|
|
36
|
+
columns = source.columns.length;
|
|
37
|
+
}
|
|
38
|
+
if (about) {
|
|
39
|
+
const metadata = book.addWorksheet("About", { columns: [{ header: "Field", width: 18 }, { header: "Value", width: 72, wrapText: true }],
|
|
40
|
+
boldHeader: true, freezeHeader: true });
|
|
41
|
+
await metadata.addRows(about);
|
|
42
|
+
await metadata.close();
|
|
43
|
+
}
|
|
44
|
+
const result = await book.finish();
|
|
45
|
+
return { rows, columns, bytes: result.bytes };
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
await book.discard(error);
|
|
49
|
+
throw error;
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
}
|
package/dist/opc/index.js
CHANGED
|
@@ -65,7 +65,16 @@ export class OpcPackage {
|
|
|
65
65
|
throw new OfficeIMOError("INVALID_STATE", "OPC package is finalized."); }
|
|
66
66
|
reserve(uri, type) {
|
|
67
67
|
this.open();
|
|
68
|
+
// OPC part names become ZIP entry names. Reject oversized and deeply nested
|
|
69
|
+
// names before collecting every ancestor prefix.
|
|
70
|
+
if (typeof uri === "string" && uri.length > 65536)
|
|
71
|
+
throw new OfficeIMOError("RESOURCE_LIMIT", "OPC part name exceeds the ZIP entry-name limit.");
|
|
68
72
|
uri = partUri(uri);
|
|
73
|
+
let depth = 0;
|
|
74
|
+
for (let index = 0; index < uri.length; index++) {
|
|
75
|
+
if (uri[index] === "/" && ++depth > 64)
|
|
76
|
+
throw new OfficeIMOError("RESOURCE_LIMIT", "OPC part name exceeds the directory-depth limit.");
|
|
77
|
+
}
|
|
69
78
|
if (/\/_rels(?:\/|$)/i.test(uri) || uri.toLowerCase() === "/[content_types].xml")
|
|
70
79
|
throw new TypeError("Package metadata part names are reserved.");
|
|
71
80
|
const key = uri.toLowerCase();
|
|
@@ -3,7 +3,8 @@ import { fontProgram } from "./font.js";
|
|
|
3
3
|
import { resolveScalar, selectFont, standardCode, validateFonts } from "./font-support.js";
|
|
4
4
|
import { pdfNumber, unicodeHex } from "./objects.js";
|
|
5
5
|
import { checkAbort, pause, taskYieldDue } from "../core/iteration.js";
|
|
6
|
-
const
|
|
6
|
+
const hexBytes = Object.freeze(Array.from({ length: 256 }, (_, byte) => byte.toString(16).padStart(2, "0")));
|
|
7
|
+
function cidHex(cid) { return hexBytes[cid >>> 8] + hexBytes[cid & 255]; }
|
|
7
8
|
export class PdfFontResource {
|
|
8
9
|
index;
|
|
9
10
|
bold;
|
|
@@ -34,12 +35,16 @@ export class PdfFontResource {
|
|
|
34
35
|
width(scalar) {
|
|
35
36
|
if (this.shared)
|
|
36
37
|
return this.shared.width(scalar);
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
38
|
+
if (this.program) {
|
|
39
|
+
const existing = this.mappings.get(scalar);
|
|
40
|
+
if (existing)
|
|
41
|
+
return existing.width;
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
const standard = this.standardWidths.get(scalar);
|
|
45
|
+
if (standard !== undefined)
|
|
46
|
+
return standard;
|
|
47
|
+
}
|
|
43
48
|
const resolved = resolveScalar(scalar, this.program, this.bold);
|
|
44
49
|
if (!resolved.supported) {
|
|
45
50
|
if (resolved.code === "unpaired-surrogate")
|
|
@@ -52,7 +57,8 @@ export class PdfFontResource {
|
|
|
52
57
|
}
|
|
53
58
|
if (this.mappings.size >= 65535)
|
|
54
59
|
throw new OfficeIMOError("RESOURCE_LIMIT", "A PDF font supports at most 65,535 distinct Unicode scalars.");
|
|
55
|
-
const
|
|
60
|
+
const cid = this.mappings.size + 1;
|
|
61
|
+
const mapping = { cid, hex: cidHex(cid), glyph: resolved.glyph, width: resolved.width, text: String.fromCodePoint(scalar) };
|
|
56
62
|
this.mappings.set(scalar, mapping);
|
|
57
63
|
return mapping.width;
|
|
58
64
|
}
|
|
@@ -65,8 +71,20 @@ export class PdfFontResource {
|
|
|
65
71
|
let hex = "";
|
|
66
72
|
for (const char of text) {
|
|
67
73
|
const cp = char.codePointAt(0);
|
|
68
|
-
this.
|
|
69
|
-
|
|
74
|
+
if (this.program) {
|
|
75
|
+
let mapping = this.mappings.get(cp);
|
|
76
|
+
// Layout normally registered the scalar already; validate only a newly painted scalar.
|
|
77
|
+
if (!mapping) {
|
|
78
|
+
this.width(cp);
|
|
79
|
+
mapping = this.mappings.get(cp);
|
|
80
|
+
}
|
|
81
|
+
hex += mapping.hex;
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
if (!this.standardWidths.has(cp))
|
|
85
|
+
this.width(cp);
|
|
86
|
+
hex += hexBytes[standardCode(cp)];
|
|
87
|
+
}
|
|
70
88
|
}
|
|
71
89
|
return "<" + hex + ">";
|
|
72
90
|
}
|
|
@@ -81,10 +99,11 @@ export class PdfFontResource {
|
|
|
81
99
|
if (!mapping) {
|
|
82
100
|
if (this.mappings.size >= 65535)
|
|
83
101
|
throw new OfficeIMOError("RESOURCE_LIMIT", "A PDF font supports at most 65,535 distinct CID mappings.");
|
|
84
|
-
|
|
102
|
+
const cid = this.mappings.size + 1;
|
|
103
|
+
mapping = { cid, hex: cidHex(cid), glyph, width: this.program.widths[glyph], text };
|
|
85
104
|
this.mappings.set(key, mapping);
|
|
86
105
|
}
|
|
87
|
-
return "<" + mapping.
|
|
106
|
+
return "<" + mapping.hex + ">";
|
|
88
107
|
}
|
|
89
108
|
async write(objects, compression) {
|
|
90
109
|
checkAbort(this.signal);
|
|
@@ -133,7 +152,7 @@ export class PdfFontResource {
|
|
|
133
152
|
const batch = mapped.slice(i, i + 100);
|
|
134
153
|
cmap += batch.length + " beginbfchar\n";
|
|
135
154
|
for (const [, m] of batch)
|
|
136
|
-
cmap += "<" + m.
|
|
155
|
+
cmap += "<" + m.hex + "> <" + unicodeHex(m.text) + ">\n";
|
|
137
156
|
cmap += "endbfchar\n";
|
|
138
157
|
if (taskYieldDue())
|
|
139
158
|
await pause();
|
|
@@ -184,7 +203,7 @@ export class PdfFontResources {
|
|
|
184
203
|
if (!found)
|
|
185
204
|
this.explicitSelections.set(explicit, selections);
|
|
186
205
|
}
|
|
187
|
-
const key =
|
|
206
|
+
const key = (bold ? 2 : 0) | (italic ? 1 : 0), existing = selections.get(key);
|
|
188
207
|
if (existing)
|
|
189
208
|
return existing;
|
|
190
209
|
const { font, syntheticBold, syntheticItalic } = explicit ? { font: explicit, syntheticBold: bold, syntheticItalic: italic } : selectFont(this.fonts, bold, italic);
|