@evotecit/officeimo 0.1.21 → 0.1.43
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 +39 -8
- package/bundles/officeimo-canopyx-adapter.js +56 -36
- package/bundles/officeimo-canopyx-adapter.min.js +1 -1
- package/bundles/officeimo-canopyx-adapter.min.mjs +1 -1
- package/bundles/officeimo-canopyx-adapter.mjs +42 -22
- package/bundles/officeimo-canopyx.js +420 -177
- package/bundles/officeimo-canopyx.min.js +1 -1
- package/bundles/officeimo-canopyx.min.mjs +1 -1
- package/bundles/officeimo-canopyx.mjs +346 -103
- package/bundles/officeimo-chartforgex-adapter.js +1924 -0
- package/bundles/officeimo-chartforgex-adapter.min.js +2 -0
- package/bundles/officeimo-chartforgex-adapter.min.mjs +2 -0
- package/bundles/officeimo-chartforgex-adapter.mjs +1910 -0
- package/bundles/officeimo-chartforgex.js +13594 -0
- package/bundles/officeimo-chartforgex.min.js +2 -0
- package/bundles/officeimo-chartforgex.min.mjs +2 -0
- package/bundles/officeimo-chartforgex.mjs +13487 -0
- package/bundles/officeimo-csv.js +12 -7
- package/bundles/officeimo-csv.min.js +1 -1
- package/bundles/officeimo-csv.min.mjs +1 -1
- package/bundles/officeimo-csv.mjs +8 -3
- package/bundles/officeimo-datatables-adapter.js +11 -11
- package/bundles/officeimo-datatables-adapter.min.js +1 -1
- package/bundles/officeimo-datatables-adapter.min.mjs +1 -1
- package/bundles/officeimo-datatables-adapter.mjs +7 -7
- package/bundles/officeimo-datatables.js +375 -152
- package/bundles/officeimo-datatables.min.js +1 -1
- package/bundles/officeimo-datatables.min.mjs +1 -1
- package/bundles/officeimo-datatables.mjs +311 -88
- package/bundles/officeimo-execution.js +14 -9
- package/bundles/officeimo-execution.min.js +1 -1
- package/bundles/officeimo-execution.min.mjs +1 -1
- package/bundles/officeimo-execution.mjs +8 -3
- package/bundles/officeimo-pdf.js +286 -120
- package/bundles/officeimo-pdf.min.js +1 -1
- package/bundles/officeimo-pdf.min.mjs +1 -1
- package/bundles/officeimo-pdf.mjs +244 -78
- package/bundles/officeimo-xlsx.js +93 -31
- package/bundles/officeimo-xlsx.min.js +1 -1
- package/bundles/officeimo-xlsx.min.mjs +1 -1
- package/bundles/officeimo-xlsx.mjs +75 -13
- package/bundles/officeimo.js +373 -150
- package/bundles/officeimo.min.js +1 -1
- package/bundles/officeimo.min.mjs +1 -1
- package/bundles/officeimo.mjs +312 -89
- package/dist/core/progress.js +7 -2
- package/dist/index.d.ts +1 -1
- package/dist/integrations/canopyx/index.js +9 -2
- package/dist/integrations/canopyx/source.js +26 -13
- package/dist/integrations/chartforgex/capture.d.ts +31 -0
- package/dist/integrations/chartforgex/capture.js +103 -0
- package/dist/integrations/chartforgex/index.d.ts +13 -0
- package/dist/integrations/chartforgex/index.js +88 -0
- package/dist/integrations/chartforgex/svg-drawing.d.ts +5 -0
- package/dist/integrations/chartforgex/svg-drawing.js +775 -0
- package/dist/integrations/chartforgex/svg-geometry.d.ts +23 -0
- package/dist/integrations/chartforgex/svg-geometry.js +304 -0
- package/dist/integrations/chartforgex/svg-image.d.ts +9 -0
- package/dist/integrations/chartforgex/svg-image.js +46 -0
- package/dist/integrations/chartforgex/svg-markup.d.ts +10 -0
- package/dist/integrations/chartforgex/svg-markup.js +124 -0
- package/dist/integrations/chartforgex/svg-paint.d.ts +16 -0
- package/dist/integrations/chartforgex/svg-paint.js +146 -0
- package/dist/integrations/chartforgex/types.d.ts +77 -0
- package/dist/integrations/chartforgex/types.js +1 -0
- package/dist/integrations/chartforgex/winansi.d.ts +4 -0
- package/dist/integrations/chartforgex/winansi.js +48 -0
- package/dist/integrations/chartforgex/workbook.d.ts +12 -0
- package/dist/integrations/chartforgex/workbook.js +137 -0
- package/dist/pdf/document-drawings.d.ts +1 -1
- package/dist/pdf/document-drawings.js +91 -17
- package/dist/pdf/document-images.d.ts +7 -1
- package/dist/pdf/document-images.js +59 -24
- package/dist/pdf/document-types.d.ts +3 -1
- package/dist/pdf/document.d.ts +2 -2
- package/dist/pdf/document.js +3 -1
- package/dist/pdf/drawing-types.d.ts +37 -10
- package/dist/pdf/font-resources.d.ts +1 -1
- package/dist/pdf/font-resources.js +6 -3
- package/dist/pdf/index.d.ts +1 -1
- package/dist/pdf/pages.js +15 -0
- package/dist/pdf/png.d.ts +11 -2
- package/dist/pdf/png.js +50 -23
- package/dist/pdf/session.js +3 -2
- package/dist/pdf/settings.d.ts +2 -2
- package/dist/pdf/settings.js +7 -3
- package/dist/xlsx/options.js +1 -1
- package/dist/xlsx/types.d.ts +8 -0
- package/dist/xlsx/workbook.js +6 -0
- package/dist/xlsx/worksheet.d.ts +13 -1
- package/dist/xlsx/worksheet.js +60 -9
- package/package.json +9 -2
package/dist/core/progress.js
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
/** @internal Notify synchronously; observe an accidental promise before rejecting its unsupported use. */
|
|
2
2
|
export function notifyProgress(callback, progress) {
|
|
3
|
+
notifySynchronously("onProgress", callback, progress);
|
|
4
|
+
}
|
|
5
|
+
/** @internal Run a host notification that must finish before the export continues. A returned promise is observed,
|
|
6
|
+
* so its rejection is never unhandled, and the export fails instead of reporting success before the callback ends. */
|
|
7
|
+
export function notifySynchronously(name, callback, value) {
|
|
3
8
|
if (!callback)
|
|
4
9
|
return;
|
|
5
|
-
const result = callback(
|
|
10
|
+
const result = callback(value);
|
|
6
11
|
if (result && typeof result.then === "function") {
|
|
7
12
|
void Promise.resolve(result).catch(() => { });
|
|
8
|
-
throw new TypeError("
|
|
13
|
+
throw new TypeError(name + " must be synchronous.");
|
|
9
14
|
}
|
|
10
15
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -27,6 +27,6 @@ export type { PdfTextPreflightOptions, PdfTextPreflightResult, PdfTextIssueCode
|
|
|
27
27
|
export type { PdfFontPreparationOptions } from "./pdf/index.js";
|
|
28
28
|
export type { PdfTextDirection, PdfShapingRun, PdfShapedGlyph, PdfShapedRun, PdfShapeLineRequest, PdfTextShaper } from "./pdf/index.js";
|
|
29
29
|
export type { PdfDocumentOptions, PdfDocumentBlock, PdfTableOptions, PdfTableBlock, PdfParagraphBlock, PdfParagraphStyle, PdfCaption, PdfListBlock, PdfListItem, PdfGroupBlock, PdfPageBreakBlock, PdfImageBlock, PdfRawImage, PdfJpegImage, PdfPngImage, PdfVectorBlock, PdfPathCommand, PdfTextRun, PdfText } from "./pdf/index.js";
|
|
30
|
-
export type { PdfDrawing, PdfDrawingBlock, PdfDrawingElement, PdfDrawingPath, PdfDrawingText, PdfDrawingGroup, PdfDrawingClip, PdfDrawingFont } from "./pdf/index.js";
|
|
30
|
+
export type { PdfDrawing, PdfDrawingBlock, PdfDrawingElement, PdfDrawingPath, PdfDrawingText, PdfDrawingImage, PdfDrawingGroup, PdfDrawingClip, PdfDrawingFont } from "./pdf/index.js";
|
|
31
31
|
export type { PdfSectionBlock, PdfBookmark } from "./pdf/section-types.js";
|
|
32
32
|
export type { PdfGroupedTableBlock } from "./pdf/document-types.js";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BlobByteSink, ExportCell } from "../../core/index.js";
|
|
2
|
-
import { notifyProgress } from "../../core/progress.js";
|
|
2
|
+
import { notifyProgress, notifySynchronously } from "../../core/progress.js";
|
|
3
3
|
import { captureFields } from "../../internal/capture.js";
|
|
4
4
|
import { captureCommonLimits, captureXlsxOptions, captureCsvOptions, capturePdfOptions, mergeAdapterLimits } from "../options.js";
|
|
5
5
|
import { writeXlsxTo } from "../../xlsx/index.js";
|
|
@@ -67,7 +67,14 @@ export async function writeCanopyTo(capture, format, destination, options = {})
|
|
|
67
67
|
freezeHeader: xlsx.sheet?.freezeHeader ?? (xlsx.sheet?.includeHeader !== false),
|
|
68
68
|
freezeColumns: xlsx.sheet?.freezeColumns ?? (pinned ? pinned + (grouped ? 1 : 0) : 0),
|
|
69
69
|
conditionalFormats: [...rules, ...(xlsx.sheet?.conditionalFormats ?? [])] };
|
|
70
|
-
|
|
70
|
+
// Data-cell links past Excel's per-worksheet limit keep their label; the worksheet reserves every link it cannot drop.
|
|
71
|
+
const linkFallback = canopyDiagnostics(format, { ...selected, unsupportedPresentation: "text" }), onHyperlinkOverflow = xlsx.onHyperlinkOverflow;
|
|
72
|
+
const settings = { ...xlsx, ...stream, columns: source.columns, sheet, dateMode: xlsx.dateMode ?? request.timeZone, limits: formatLimits,
|
|
73
|
+
hyperlinkOverflow: xlsx.hyperlinkOverflow ?? "drop",
|
|
74
|
+
onHyperlinkOverflow: (overflow) => {
|
|
75
|
+
notifySynchronously("onHyperlinkOverflow", onHyperlinkOverflow, overflow);
|
|
76
|
+
linkFallback({ code: "LINKS_TRUNCATED:" + overflow.dropped });
|
|
77
|
+
} };
|
|
71
78
|
if (grouped || about)
|
|
72
79
|
return writeCanopyWorkbook(source, grouped, destination, settings, capturedLabels, about);
|
|
73
80
|
return writeXlsxTo(source.rows(), destination, settings);
|
|
@@ -27,19 +27,29 @@ export function canopyIdentityValue(value) {
|
|
|
27
27
|
const original = rawIdentities.get(value);
|
|
28
28
|
return original === undefined ? value.value : original;
|
|
29
29
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
// Grids accept any number of badges. Exports keep the first labels that stay readable and fit an Excel text cell,
|
|
31
|
+
// and report how many were left out instead of failing the whole document.
|
|
32
|
+
const maximumBadges = 64, maximumCellText = 32767;
|
|
33
|
+
function badgeText(input, text) {
|
|
34
|
+
if (!Array.isArray(input))
|
|
35
|
+
throw new TypeError("Canopy cell badges must be an array of { text, tone?, title? }.");
|
|
36
|
+
let labels = "", kept = 0, dropped = 0;
|
|
34
37
|
for (const badge of input) {
|
|
35
|
-
const
|
|
36
|
-
if (typeof
|
|
37
|
-
throw new TypeError("Canopy cell badges must be
|
|
38
|
-
const label =
|
|
39
|
-
if (label)
|
|
40
|
-
|
|
38
|
+
const value = typeof badge === "string" ? badge : badge && typeof badge === "object" ? badge.text : undefined;
|
|
39
|
+
if (typeof value !== "string")
|
|
40
|
+
throw new TypeError("Canopy cell badges must be an array of { text, tone?, title? }.");
|
|
41
|
+
const label = value.trim();
|
|
42
|
+
if (!label)
|
|
43
|
+
continue;
|
|
44
|
+
const next = labels ? labels + badgeSeparator + label : label;
|
|
45
|
+
if (kept >= maximumBadges || (text ? text.length + badgeSeparator.length : 0) + next.length > maximumCellText) {
|
|
46
|
+
dropped++;
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
labels = next;
|
|
50
|
+
kept++;
|
|
41
51
|
}
|
|
42
|
-
return labels
|
|
52
|
+
return { labels: labels || undefined, dropped };
|
|
43
53
|
}
|
|
44
54
|
/** Map an immutable CanopyX record capture to a writer without querying the grid or retaining its body. */
|
|
45
55
|
export function createCanopyExport(capture, format, options = {}) {
|
|
@@ -156,11 +166,14 @@ export function prepareCanopyExport(capture, format, options = {}) {
|
|
|
156
166
|
// History captures already carry their frozen latest scalar (or null).
|
|
157
167
|
// Columns read by an emitted native rule keep the raw scalar the rule compares, so the label goes to the text only.
|
|
158
168
|
const relativeLabel = spec.kind === "text" && cell.diagnostics?.includes("relative-link") && !ruleOperands.has(spec.id);
|
|
159
|
-
const
|
|
169
|
+
const badged = cell.badges === undefined ? undefined : badgeText(cell.badges, cell.text), badges = badged?.labels;
|
|
170
|
+
if (badged?.dropped)
|
|
171
|
+
fallback({ code: "BADGES_TRUNCATED:" + badged.dropped, rowId: row.id, columnId: spec.id });
|
|
160
172
|
const text = badges ? cell.text ? cell.text + badgeSeparator + badges : badges : cell.text;
|
|
161
173
|
// Badges belong to the visible label, so a badged text cell exports that composed label rather than a raw/label hybrid.
|
|
162
174
|
// Typed columns keep their scalar, and native rule operands keep the raw value the rule compares; both carry badges in the text only.
|
|
163
|
-
|
|
175
|
+
// A cell whose badges were all left out still exports its captured label, as it would with the badges.
|
|
176
|
+
const badgedValue = (!!badges || !!badged?.dropped) && values === "raw" && !relativeLabel && spec.kind === "text" && !ruleOperands.has(spec.id);
|
|
164
177
|
let value = values === "display" || relativeLabel || badgedValue ? text : cell.value;
|
|
165
178
|
if (format === "xlsx" && values === "raw" && spec.kind === "datetime" && typeof value === "string")
|
|
166
179
|
value = datetime(value, dateMode, clock);
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { ChartForgeXCapture } from "./types.js";
|
|
2
|
+
export type ChartXKind = "date" | "number" | "category";
|
|
3
|
+
export interface PreparedPoint {
|
|
4
|
+
readonly x: Date | number | string | null;
|
|
5
|
+
/** Identity of the x value for wide layouts; null when absent. */
|
|
6
|
+
readonly key: number | string | null;
|
|
7
|
+
readonly xCaption: string | undefined;
|
|
8
|
+
readonly y: number | null;
|
|
9
|
+
readonly caption: string | undefined;
|
|
10
|
+
}
|
|
11
|
+
export interface PreparedSeries {
|
|
12
|
+
readonly id: string;
|
|
13
|
+
readonly name: string;
|
|
14
|
+
readonly unit: string | undefined;
|
|
15
|
+
readonly format: string | undefined;
|
|
16
|
+
readonly points: readonly PreparedPoint[];
|
|
17
|
+
}
|
|
18
|
+
export interface PreparedChart {
|
|
19
|
+
readonly title: string | undefined;
|
|
20
|
+
readonly description: string | undefined;
|
|
21
|
+
readonly kind: ChartXKind;
|
|
22
|
+
readonly xTitle: string;
|
|
23
|
+
readonly xFormat: string | undefined;
|
|
24
|
+
readonly yTitle: string;
|
|
25
|
+
readonly yUnit: string | undefined;
|
|
26
|
+
readonly yFormat: string | undefined;
|
|
27
|
+
readonly series: readonly PreparedSeries[];
|
|
28
|
+
readonly svg: string | undefined;
|
|
29
|
+
}
|
|
30
|
+
/** Read the capture once into owned records, so later caller mutation cannot change an export in progress. */
|
|
31
|
+
export declare function prepareChart(input: ChartForgeXCapture, maxPoints?: number): PreparedChart;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { NotSupportedError } from "../../core/errors.js";
|
|
2
|
+
function record(value, name) {
|
|
3
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
4
|
+
throw new TypeError("Chart capture " + name + " must be an object.");
|
|
5
|
+
return value;
|
|
6
|
+
}
|
|
7
|
+
function text(value, name, required = false) {
|
|
8
|
+
if (value === undefined || value === null) {
|
|
9
|
+
if (required)
|
|
10
|
+
throw new TypeError("Chart capture " + name + " is required.");
|
|
11
|
+
return undefined;
|
|
12
|
+
}
|
|
13
|
+
if (typeof value !== "string")
|
|
14
|
+
throw new TypeError("Chart capture " + name + " must be a string.");
|
|
15
|
+
return value;
|
|
16
|
+
}
|
|
17
|
+
const isoDate = /^\d{4}-\d{2}-\d{2}(?:[T ]\d{2}:\d{2}(?::\d{2}(?:\.\d{1,9})?)?)?(?:Z|[+-]\d{2}:?\d{2})?$/;
|
|
18
|
+
/** Dates without an offset are UTC wall-clock values, the way ChartForgeX serializes time axes, never the reader's local time. */
|
|
19
|
+
function isoInstant(value) {
|
|
20
|
+
const normalized = value.replace(" ", "T").replace(/([+-]\d{2})(\d{2})$/, "$1:$2").replace(/(\.\d{3})\d+/, "$1");
|
|
21
|
+
return normalized.length === 10 || /(Z|[+-]\d{2}:\d{2})$/.test(normalized) ? normalized : normalized + "Z";
|
|
22
|
+
}
|
|
23
|
+
function parseDate(value) {
|
|
24
|
+
const normalized = value.trim();
|
|
25
|
+
if (!isoDate.test(normalized))
|
|
26
|
+
return NaN;
|
|
27
|
+
const day = normalized.slice(0, 10);
|
|
28
|
+
const midnight = new Date(day + "T00:00:00Z");
|
|
29
|
+
if (!Number.isFinite(midnight.getTime()) || !midnight.toISOString().startsWith(day + "T"))
|
|
30
|
+
return NaN;
|
|
31
|
+
return Date.parse(isoInstant(normalized));
|
|
32
|
+
}
|
|
33
|
+
/** Read the capture once into owned records, so later caller mutation cannot change an export in progress. */
|
|
34
|
+
export function prepareChart(input, maxPoints = 1048575) {
|
|
35
|
+
const capture = record(input, "");
|
|
36
|
+
if (capture.version !== 1)
|
|
37
|
+
throw new NotSupportedError("Only ChartForgeX capture version 1 is supported.");
|
|
38
|
+
const axis = record(capture.x, "x"), kind = axis.kind;
|
|
39
|
+
if (kind !== "date" && kind !== "number" && kind !== "category")
|
|
40
|
+
throw new TypeError("Chart capture x.kind must be date, number or category.");
|
|
41
|
+
const yAxis = capture.y === undefined ? {} : record(capture.y, "y");
|
|
42
|
+
if (!Array.isArray(capture.series))
|
|
43
|
+
throw new TypeError("Chart capture series must be an array.");
|
|
44
|
+
let count = 0;
|
|
45
|
+
const series = Array.from(capture.series, (entry, index) => {
|
|
46
|
+
const value = record(entry, "series[" + index + "]"), points = value.points;
|
|
47
|
+
if (!Array.isArray(points))
|
|
48
|
+
throw new TypeError("Chart capture series[" + index + "].points must be an array.");
|
|
49
|
+
const pointCount = points.length;
|
|
50
|
+
if ((count += pointCount) > maxPoints)
|
|
51
|
+
throw new RangeError("Chart capture has more than " + maxPoints + " points.");
|
|
52
|
+
return {
|
|
53
|
+
id: text(value.id, "series[" + index + "].id", true), name: text(value.name, "series[" + index + "].name", true),
|
|
54
|
+
unit: text(value.unit, "series unit"), format: text(value.format, "series format"),
|
|
55
|
+
points: Array.from({ length: pointCount }, (_, point) => {
|
|
56
|
+
const item = record(points[point], "point"), where = "series[" + index + "].points[" + point + "]";
|
|
57
|
+
const y = item.y;
|
|
58
|
+
if (y !== null && y !== undefined && (typeof y !== "number" || !Number.isFinite(y)))
|
|
59
|
+
throw new TypeError(where + ".y must be a finite number or null.");
|
|
60
|
+
let x = null, key = null;
|
|
61
|
+
const source = item.x;
|
|
62
|
+
if (source !== null && source !== undefined) {
|
|
63
|
+
if (kind === "date") {
|
|
64
|
+
let time = NaN;
|
|
65
|
+
if (typeof source === "string")
|
|
66
|
+
time = parseDate(source);
|
|
67
|
+
if (typeof source === "object") {
|
|
68
|
+
try {
|
|
69
|
+
time = Date.prototype.getTime.call(source);
|
|
70
|
+
}
|
|
71
|
+
catch { /* Not a Date. */ }
|
|
72
|
+
}
|
|
73
|
+
if (!Number.isFinite(time))
|
|
74
|
+
throw new TypeError(where + ".x must be an ISO 8601 date string or a valid Date.");
|
|
75
|
+
x = new Date(time);
|
|
76
|
+
key = time;
|
|
77
|
+
}
|
|
78
|
+
else if (kind === "number") {
|
|
79
|
+
if (typeof source !== "number" || !Number.isFinite(source))
|
|
80
|
+
throw new TypeError(where + ".x must be a finite number.");
|
|
81
|
+
x = key = source;
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
if (typeof source !== "string" && typeof source !== "number")
|
|
85
|
+
throw new TypeError(where + ".x must be a category label.");
|
|
86
|
+
x = key = String(source);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return { x, key, xCaption: text(item.xCaption, where + ".xCaption"), y: y ?? null, caption: text(item.caption, where + ".caption") };
|
|
90
|
+
})
|
|
91
|
+
};
|
|
92
|
+
});
|
|
93
|
+
const svg = capture.svg;
|
|
94
|
+
const markup = svg && typeof svg === "object" ? svg.outerHTML : svg;
|
|
95
|
+
if (svg != null && typeof markup !== "string")
|
|
96
|
+
throw new TypeError("Chart capture svg must be markup or an element.");
|
|
97
|
+
return {
|
|
98
|
+
title: text(capture.title, "title"), description: text(capture.description, "description"), kind,
|
|
99
|
+
xTitle: text(axis.title, "x.title") || "X", xFormat: text(axis.format, "x.format"),
|
|
100
|
+
yTitle: text(yAxis.title, "y.title") || "Value", yUnit: text(yAxis.unit, "y.unit"), yFormat: text(yAxis.format, "y.format"),
|
|
101
|
+
series, svg: typeof markup === "string" ? markup : undefined
|
|
102
|
+
};
|
|
103
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { OutputDestination, ExportResult } from "../../core/index.js";
|
|
2
|
+
import type { PdfDrawing } from "../../pdf/index.js";
|
|
3
|
+
import type { ChartForgeXCapture, ChartForgeXFormat, ChartForgeXSvgOptions, ChartForgeXWriteOptions } from "./types.js";
|
|
4
|
+
export { PdfFont } from "../../pdf/font.js";
|
|
5
|
+
export type { ChartForgeXCapture, ChartForgeXSeries, ChartForgeXPoint, ChartForgeXAxis, ChartForgeXFormat, ChartForgeXDiagnostic, ChartForgeXSvgOptions, ChartForgeXWriteOptions } from "./types.js";
|
|
6
|
+
/** Convert chart SVG into a version 2 drawing with embedded image elements. */
|
|
7
|
+
export declare function chartForgeXDrawing(svg: string, version: 2, options?: ChartForgeXSvgOptions): PdfDrawing<2>;
|
|
8
|
+
/** Convert chart SVG into a version 1 drawing without images. */
|
|
9
|
+
export declare function chartForgeXDrawing(svg: string, options?: ChartForgeXSvgOptions): PdfDrawing;
|
|
10
|
+
/** Write a ChartForgeX capture as a typed XLSX sheet of its series, or a PDF with its title, description and vector SVG. */
|
|
11
|
+
export declare function writeChartForgeXTo(capture: ChartForgeXCapture, format: ChartForgeXFormat, destination: OutputDestination, options?: ChartForgeXWriteOptions): Promise<ExportResult>;
|
|
12
|
+
/** Export a ChartForgeX capture as a Blob. No chart runtime, browser layout or server is involved. */
|
|
13
|
+
export declare function exportChartForgeX(capture: ChartForgeXCapture, format: ChartForgeXFormat, options?: ChartForgeXWriteOptions): Promise<Blob>;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { BlobByteSink, checkAbort } from "../../core/index.js";
|
|
2
|
+
import { captureFields } from "../../internal/capture.js";
|
|
3
|
+
import { captureCommonLimits, captureXlsxOptions, mergeAdapterLimits } from "../options.js";
|
|
4
|
+
import { writeXlsxTo } from "../../xlsx/index.js";
|
|
5
|
+
import { writePdfDocumentTo } from "../../pdf/index.js";
|
|
6
|
+
import { capturePdfLimits } from "../../pdf/settings.js";
|
|
7
|
+
import { prepareChart } from "./capture.js";
|
|
8
|
+
import { svgToPdfDrawing } from "./svg-drawing.js";
|
|
9
|
+
import { chartTable } from "./workbook.js";
|
|
10
|
+
import { winAnsiText } from "./winansi.js";
|
|
11
|
+
export { PdfFont } from "../../pdf/font.js";
|
|
12
|
+
const slots = ["regular", "bold", "italic", "boldItalic"];
|
|
13
|
+
const headerFill = "E7EDF5", headerBorder = Object.freeze({ bottom: Object.freeze({ style: "thin", color: "A6B4C8" }) });
|
|
14
|
+
export function chartForgeXDrawing(svg, optionsOrVersion = {}, imageOptions = {}) {
|
|
15
|
+
const options = optionsOrVersion === 2 ? imageOptions : optionsOrVersion;
|
|
16
|
+
const selected = captureFields(options, ["unsupported", "fonts", "winAnsi", "limits", "onDiagnostic"]);
|
|
17
|
+
return optionsOrVersion === 2 ? svgToPdfDrawing(svg, selected, 2) : svgToPdfDrawing(svg, selected, 1);
|
|
18
|
+
}
|
|
19
|
+
/** Write a ChartForgeX capture as a typed XLSX sheet of its series, or a PDF with its title, description and vector SVG. */
|
|
20
|
+
export async function writeChartForgeXTo(capture, format, destination, options = {}) {
|
|
21
|
+
const selected = captureFields(options, ["layout", "signal", "limits", "onProgress", "onDiagnostic", "unsupported", "xlsx", "pdf"]);
|
|
22
|
+
if (format !== "xlsx" && format !== "pdf")
|
|
23
|
+
throw new TypeError("ChartForgeX exports are xlsx or pdf.");
|
|
24
|
+
const { signal, onProgress, onDiagnostic, unsupported } = selected, limits = captureCommonLimits(selected.limits);
|
|
25
|
+
if (unsupported !== undefined && unsupported !== "skip" && unsupported !== "reject")
|
|
26
|
+
throw new TypeError("unsupported must be skip or reject.");
|
|
27
|
+
checkAbort(signal);
|
|
28
|
+
const chart = prepareChart(capture), stream = { ...(signal ? { signal } : {}), ...(onProgress ? { onProgress } : {}) };
|
|
29
|
+
if (format === "xlsx") {
|
|
30
|
+
const input = captureFields(selected.xlsx ?? {}, ["dateMode", "compression", "creator", "created", "modified", "sheetName"]);
|
|
31
|
+
const { sheetName = "Chart data", ...workbook } = input;
|
|
32
|
+
const xlsx = captureXlsxOptions(workbook), xlsxLimits = mergeAdapterLimits(xlsx.limits, limits);
|
|
33
|
+
const table = chartTable(chart, selected.layout, xlsxLimits);
|
|
34
|
+
return writeXlsxTo(table.rows, destination, { dateMode: "utc", ...xlsx, ...stream, columns: table.columns,
|
|
35
|
+
...(chart.title === undefined ? {} : { title: chart.title }), ...(chart.description === undefined ? {} : { description: chart.description }),
|
|
36
|
+
limits: xlsxLimits,
|
|
37
|
+
sheet: { name: sheetName, headerFill, headerBorder, headerWrap: true, freezeHeader: true, autoFilter: true, boldHeader: true,
|
|
38
|
+
autoSize: { minWidth: 8, maxWidth: 48 }, ...(chart.title ? { title: { text: chart.title } } : {}) } });
|
|
39
|
+
}
|
|
40
|
+
if (chart.svg === undefined)
|
|
41
|
+
throw new TypeError("A ChartForgeX PDF needs the chart's SVG markup.");
|
|
42
|
+
const pdf = captureFields(selected.pdf ?? {}, ["pageSize", "orientation", "margins", "fonts", "tagged", "compression", "pageNumbers", "pageHeader",
|
|
43
|
+
"pageFooter", "fontSize", "limits"]);
|
|
44
|
+
const pdfLimits = mergeAdapterLimits(pdf.limits === undefined ? undefined : capturePdfLimits(pdf.limits), limits);
|
|
45
|
+
// Keep Unicode labels in the embedded regular face when an emphasis face is missing.
|
|
46
|
+
const faces = pdf.fonts === undefined ? undefined : captureFields(pdf.fonts, slots);
|
|
47
|
+
const available = faces ? slots.filter(slot => slot === "regular" || faces[slot] !== undefined) : slots;
|
|
48
|
+
const reported = new Set();
|
|
49
|
+
const report = (diagnostic) => {
|
|
50
|
+
if (reported.has(diagnostic.code))
|
|
51
|
+
return;
|
|
52
|
+
reported.add(diagnostic.code);
|
|
53
|
+
onDiagnostic?.(diagnostic);
|
|
54
|
+
};
|
|
55
|
+
const drawing = svgToPdfDrawing(chart.svg, { fonts: available, winAnsi: !faces?.regular, limits: pdfLimits, ...(unsupported ? { unsupported } : {}),
|
|
56
|
+
onDiagnostic: report }, 2, signal);
|
|
57
|
+
const paintedText = (text) => {
|
|
58
|
+
if (text === undefined)
|
|
59
|
+
return undefined;
|
|
60
|
+
if (faces?.regular)
|
|
61
|
+
return text.normalize("NFC");
|
|
62
|
+
return winAnsiText(text, () => {
|
|
63
|
+
if (unsupported === "reject")
|
|
64
|
+
throw new TypeError("Chart text needs an embedded font: supply pdf.fonts.regular.");
|
|
65
|
+
report({ code: "TEXT_SUBSTITUTED" });
|
|
66
|
+
});
|
|
67
|
+
};
|
|
68
|
+
const title = paintedText(chart.title), description = paintedText(chart.description);
|
|
69
|
+
// The figure alternative stays exact: it is Unicode metadata, not painted text.
|
|
70
|
+
const alternativeText = chart.description?.trim() ? chart.description : chart.title?.trim() ? chart.title : "Chart";
|
|
71
|
+
const blocks = [...(description ? [{ kind: "paragraph", text: description }] : []),
|
|
72
|
+
{ kind: "drawing", drawing, alignment: "center", alternativeText }];
|
|
73
|
+
return writePdfDocumentTo(blocks, destination, { orientation: drawing.width > drawing.height ? "landscape" : "portrait", pageNumbers: false,
|
|
74
|
+
...pdf, ...stream, ...(faces ? { fonts: faces } : {}), ...(title ? { title } : {}),
|
|
75
|
+
...(chart.title ? { metadataTitle: chart.title } : {}), limits: pdfLimits });
|
|
76
|
+
}
|
|
77
|
+
/** Export a ChartForgeX capture as a Blob. No chart runtime, browser layout or server is involved. */
|
|
78
|
+
export async function exportChartForgeX(capture, format, options = {}) {
|
|
79
|
+
const sink = new BlobByteSink();
|
|
80
|
+
try {
|
|
81
|
+
await writeChartForgeXTo(capture, format, sink, options);
|
|
82
|
+
return sink.toBlob(format === "xlsx" ? "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" : "application/pdf");
|
|
83
|
+
}
|
|
84
|
+
catch (error) {
|
|
85
|
+
sink.discard();
|
|
86
|
+
throw error;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { PdfDrawing } from "../../pdf/drawing-types.js";
|
|
2
|
+
import type { ChartForgeXSvgOptions } from "./types.js";
|
|
3
|
+
/** Convert a resolved chart SVG into the PDF writer's portable drawing. Lengths become points (96 px = 72 pt). */
|
|
4
|
+
export declare function svgToPdfDrawing(svg: string, options: ChartForgeXSvgOptions, version: 1, signal?: AbortSignal): PdfDrawing<1>;
|
|
5
|
+
export declare function svgToPdfDrawing(svg: string, options: ChartForgeXSvgOptions, version: 2, signal?: AbortSignal): PdfDrawing<2>;
|