@reportwright/engine 0.12.1 → 0.13.0
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/CHANGELOG.md +78 -0
- package/README.md +79 -0
- package/THIRD-PARTY-NOTICES.md +52 -0
- package/dist/index.js +5727 -4524
- package/dist/pdfstreamworker.js +2 -2
- package/dist/types/packages/engine/entry.d.ts +70 -2
- package/dist/types/src/engine/data/index.d.ts +14 -1
- package/dist/types/src/engine/expr/evaluate.d.ts +1 -0
- package/dist/types/src/engine/index.d.ts +11 -3
- package/dist/types/src/engine/lazylibs.d.ts +46 -0
- package/dist/types/src/engine/notices.d.ts +1 -0
- package/dist/types/src/engine/options.d.ts +10 -0
- package/dist/types/src/engine/schema/report.schema.d.ts +3 -0
- package/dist/types/src/engine/stream.d.ts +30 -35
- package/dist/types/src/engine/text/fonts.d.ts +30 -5
- package/dist/types/src/engine/text/measure.d.ts +4 -0
- package/dist/types/src/engine/text/standard.d.ts +42 -0
- package/dist/types/src/exporters/docx.d.ts +14 -0
- package/dist/types/src/exporters/officestream.d.ts +27 -0
- package/dist/types/src/exporters/pdf.d.ts +5 -3
- package/dist/types/src/exporters/pdfstandard.d.ts +23 -0
- package/dist/types/src/exporters/pdfstream.d.ts +13 -6
- package/dist/types/src/exporters/subset.d.ts +14 -0
- package/dist/types/src/exporters/xlsxstream.d.ts +22 -0
- package/package.json +5 -3
- package/report.d.ts +1 -0
- package/schema.json +3 -0
package/dist/pdfstreamworker.js
CHANGED
|
@@ -21,7 +21,7 @@ parentPort.on('message', async (/** @type {any} */ job) => {
|
|
|
21
21
|
const m = await render(job.def, { ...job.opts, fontStore, sources: { __rows: { rows: job.rows } }, pageWindow: job.pageWindow });
|
|
22
22
|
// a writer of its own for the names and glyphs (nothing is written): the pages' links name pages by placeholder
|
|
23
23
|
const rec = createPdfStream({ write() {} }, { fontStore });
|
|
24
|
-
const env = paintEnv(rec, fontStore, { drillBase: job.drillBase, pageRef: (i) => `@@P${i}
|
|
24
|
+
const env = paintEnv(rec, fontStore, { drillBase: job.drillBase, pageRef: (i) => `@@P${i}@@`, embedAll: job.embedAll });
|
|
25
25
|
const pages = [], transfer = [];
|
|
26
26
|
for (let k = 0; k < Math.min(job.keep, m.pages.length); k++) {
|
|
27
27
|
const pg = m.pages[k];
|
|
@@ -31,7 +31,7 @@ parentPort.on('message', async (/** @type {any} */ job) => {
|
|
|
31
31
|
pages.push({ deflated: z, annots, width: pg.width, height: pg.height, firstRow: pg.firstRow, rowHead: pg.rowHead, headLevel: pg.headLevel });
|
|
32
32
|
}
|
|
33
33
|
parentPort.postMessage({ id: job.id, count: m.pages.length, nextFirst: m.pages[job.keep]?.firstRow, pages, used: rec.used(),
|
|
34
|
-
shaped: [...env.shaped].map(([k, g]) => [k, [...g]]), bookmarks: m.bookmarks, headings: m.headings, warnings: m.warnings, ms: Date.now() - t0 }, transfer);
|
|
34
|
+
shaped: [...env.shaped].map(([k, g]) => [k, [...g]]), embedded: [...env.embedded || []], bookmarks: m.bookmarks, headings: m.headings, warnings: m.warnings, ms: Date.now() - t0 }, transfer);
|
|
35
35
|
} catch (e) {
|
|
36
36
|
parentPort.postMessage({ id: job.id, error: { message: String(/** @type {any} */ (e)?.message || e), status: /** @type {any} */ (e)?.status, timeout: /** @type {any} */ (e)?.timeout } });
|
|
37
37
|
}
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
export function defaultFontStore(opts?: {
|
|
9
9
|
fontsUrl?: string;
|
|
10
10
|
}): FontStore;
|
|
11
|
+
export function render(def0: any, opts?: import("../../src/engine/index.js").RenderOptions): Promise<any>;
|
|
11
12
|
/**
|
|
12
13
|
* @typedef {Omit<NonNullable<Parameters<typeof exportPdfFull>[2]>, 'subset' | 'pdfa'> & {
|
|
13
14
|
* fonts?: FontStore, subset?: false | NonNullable<Parameters<typeof exportPdfFull>[2]>['subset'],
|
|
@@ -50,13 +51,16 @@ export function exportPptx(model: any, options?: NonNullable<Parameters<typeof e
|
|
|
50
51
|
}, ...args: any[]): Promise<Uint8Array>;
|
|
51
52
|
/**
|
|
52
53
|
* @typedef {RenderOptions & Omit<PdfOptions, 'fonts'> & { fonts?: FontStore, tagged?: { lang?: string, maxElements?: number },
|
|
53
|
-
* window?: number, parallel?: number, maxRows?: number, id?: string, presorted?: boolean,
|
|
54
|
+
* window?: number, parallel?: number, maxRows?: number, id?: string, presorted?: boolean, signal?: AbortSignal,
|
|
54
55
|
* spill?: false | { dir?: string, maxMB?: number }, sorter?: (cmp: (a: any, b: any) => number) => any }} PdfStreamOptions
|
|
55
56
|
* render()'s options and exportPdf's, plus: window (rows laid out at once, 1000), parallel (Node: worker threads
|
|
56
57
|
* that lay out and paint pages, opt-in; the file is the same, each thread costs memory), maxRows (rows read,
|
|
57
58
|
* 5,000,000), id (the file ID). presorted: the rows come in the report's order (its sort, its groups together), so
|
|
58
59
|
* they are not sorted, only checked as they pass (a row out of order stops the export). spill: where a sort's runs go
|
|
59
60
|
* (Node: the system temp folder, 2 GB at most; false sorts in memory); in a browser a sort is in memory.
|
|
61
|
+
* timeoutMs: the whole export's time limit, waits for the sink included (504, code 'ETIMEDOUT'). signal: an
|
|
62
|
+
* AbortSignal that stops the export at its next wait (rejects with the signal's reason, an AbortError); sqlRows gets
|
|
63
|
+
* it as its third argument ({ signal }) so a database cursor can cancel its query.
|
|
60
64
|
*/
|
|
61
65
|
/**
|
|
62
66
|
* Report definition → PDF written to a sink as it is made, for reports too large to hold as a page model: a flowing
|
|
@@ -77,6 +81,66 @@ export function exportPdfStream(def: any, options: PdfStreamOptions, sink: {
|
|
|
77
81
|
warnings: string[];
|
|
78
82
|
why?: string;
|
|
79
83
|
}>;
|
|
84
|
+
/**
|
|
85
|
+
* Report definition → .docx written to a sink as its pages are laid out (exportPdfStream's sink, timeoutMs, signal,
|
|
86
|
+
* window, maxRows, sqlRows and spill): a flowing table report is never held whole; any other report is rendered whole
|
|
87
|
+
* and written in one piece (the result's why says why).
|
|
88
|
+
* @param {any} def @param {RenderOptions & { fonts?: FontStore, title?: string, lang?: string, figures?: boolean, timeoutMs?: number, signal?: AbortSignal,
|
|
89
|
+
* window?: number, maxRows?: number, spill?: false | { dir?: string, maxMB?: number } }} options
|
|
90
|
+
* @param {{ write(bytes: Uint8Array): any, once?: (ev: string, cb: () => void) => any }} sink not closed
|
|
91
|
+
* @returns {Promise<{ streamed: boolean, pages?: number, warnings: string[], why?: string }>}
|
|
92
|
+
*/
|
|
93
|
+
export function exportDocxStream(def: any, options: RenderOptions & {
|
|
94
|
+
fonts?: FontStore;
|
|
95
|
+
title?: string;
|
|
96
|
+
lang?: string;
|
|
97
|
+
figures?: boolean;
|
|
98
|
+
timeoutMs?: number;
|
|
99
|
+
signal?: AbortSignal;
|
|
100
|
+
window?: number;
|
|
101
|
+
maxRows?: number;
|
|
102
|
+
spill?: false | {
|
|
103
|
+
dir?: string;
|
|
104
|
+
maxMB?: number;
|
|
105
|
+
};
|
|
106
|
+
}, sink: {
|
|
107
|
+
write(bytes: Uint8Array): any;
|
|
108
|
+
once?: (ev: string, cb: () => void) => any;
|
|
109
|
+
}): Promise<{
|
|
110
|
+
streamed: boolean;
|
|
111
|
+
pages?: number;
|
|
112
|
+
warnings: string[];
|
|
113
|
+
why?: string;
|
|
114
|
+
}>;
|
|
115
|
+
/**
|
|
116
|
+
* Report definition → .xlsx written to a sink row by row (exportPdfStream's sink, timeoutMs, signal, maxRows, sqlRows
|
|
117
|
+
* and spill); any other report is rendered whole and written in one piece (the result's why says why).
|
|
118
|
+
* @param {any} def @param {RenderOptions & { fonts?: FontStore, title?: string, currency?: string, formulas?: boolean, timeoutMs?: number, signal?: AbortSignal,
|
|
119
|
+
* maxRows?: number, spill?: false | { dir?: string, maxMB?: number } }} options
|
|
120
|
+
* @param {{ write(bytes: Uint8Array): any, once?: (ev: string, cb: () => void) => any }} sink not closed
|
|
121
|
+
* @returns {Promise<{ streamed: boolean, rows?: number, warnings: string[], why?: string }>}
|
|
122
|
+
*/
|
|
123
|
+
export function exportXlsxStream(def: any, options: RenderOptions & {
|
|
124
|
+
fonts?: FontStore;
|
|
125
|
+
title?: string;
|
|
126
|
+
currency?: string;
|
|
127
|
+
formulas?: boolean;
|
|
128
|
+
timeoutMs?: number;
|
|
129
|
+
signal?: AbortSignal;
|
|
130
|
+
maxRows?: number;
|
|
131
|
+
spill?: false | {
|
|
132
|
+
dir?: string;
|
|
133
|
+
maxMB?: number;
|
|
134
|
+
};
|
|
135
|
+
}, sink: {
|
|
136
|
+
write(bytes: Uint8Array): any;
|
|
137
|
+
once?: (ev: string, cb: () => void) => any;
|
|
138
|
+
}): Promise<{
|
|
139
|
+
streamed: boolean;
|
|
140
|
+
rows?: number;
|
|
141
|
+
warnings: string[];
|
|
142
|
+
why?: string;
|
|
143
|
+
}>;
|
|
80
144
|
export { validate } from "../../src/engine/schema/validate.js";
|
|
81
145
|
export { exportHtml } from "../../src/exporters/html.js";
|
|
82
146
|
export { exportCsv } from "../../src/exporters/csv.js";
|
|
@@ -103,6 +167,9 @@ export type PdfOptions = Omit<NonNullable<Parameters<typeof exportPdfFull>[2]>,
|
|
|
103
167
|
* 5,000,000), id (the file ID). presorted: the rows come in the report's order (its sort, its groups together), so
|
|
104
168
|
* they are not sorted, only checked as they pass (a row out of order stops the export). spill: where a sort's runs go
|
|
105
169
|
* (Node: the system temp folder, 2 GB at most; false sorts in memory); in a browser a sort is in memory.
|
|
170
|
+
* timeoutMs: the whole export's time limit, waits for the sink included (504, code 'ETIMEDOUT'). signal: an
|
|
171
|
+
* AbortSignal that stops the export at its next wait (rejects with the signal's reason, an AbortError); sqlRows gets
|
|
172
|
+
* it as its third argument ({ signal }) so a database cursor can cancel its query.
|
|
106
173
|
*/
|
|
107
174
|
export type PdfStreamOptions = RenderOptions & Omit<PdfOptions, "fonts"> & {
|
|
108
175
|
fonts?: FontStore;
|
|
@@ -115,6 +182,7 @@ export type PdfStreamOptions = RenderOptions & Omit<PdfOptions, "fonts"> & {
|
|
|
115
182
|
maxRows?: number;
|
|
116
183
|
id?: string;
|
|
117
184
|
presorted?: boolean;
|
|
185
|
+
signal?: AbortSignal;
|
|
118
186
|
spill?: false | {
|
|
119
187
|
dir?: string;
|
|
120
188
|
maxMB?: number;
|
|
@@ -134,6 +202,6 @@ import { paintEnv } from '../../src/exporters/pdfstream.js';
|
|
|
134
202
|
import { latin1 } from '../../src/exporters/pdfpaint.js';
|
|
135
203
|
import { exportPdf as exportPdfFull } from '../../src/exporters/pdf.js';
|
|
136
204
|
export { fontFile, createSubsetter };
|
|
137
|
-
export {
|
|
205
|
+
export { FontStore, ITEMS, parameterOptions, resolveParameters } from "../../src/engine/index.js";
|
|
138
206
|
export { blankReport, blankDashboard } from "../../src/engine/schema/template.js";
|
|
139
207
|
export { tableFor, matrixFor } from "../../src/designer/tableGen.js";
|
|
@@ -13,13 +13,26 @@ export function jsonPathRows(obj: any, path: any): {
|
|
|
13
13
|
* A raw value as the field's type. Numbers in text are read the locale's way ("12,5" and "1.234,56" in de-DE, "1,234.5"
|
|
14
14
|
* and "(1,234)" in en-US); dates without a zone are the wall clock of the report's zone. A value that does not read
|
|
15
15
|
* is null, and opt.bad hears of it (the data set warns once).
|
|
16
|
-
* @param {any} v @param {string} type @param {{ locale?: string, timeZone?: string, bad?: (v: any) => void }} [opt]
|
|
16
|
+
* @param {any} v @param {string} type @param {{ locale?: string, timeZone?: string, bad?: (v: any) => void, empty?: () => void }} [opt]
|
|
17
17
|
*/
|
|
18
18
|
export function coerce(v: any, type: string, opt?: {
|
|
19
19
|
locale?: string;
|
|
20
20
|
timeZone?: string;
|
|
21
21
|
bad?: (v: any) => void;
|
|
22
|
+
empty?: () => void;
|
|
22
23
|
}): any;
|
|
24
|
+
/**
|
|
25
|
+
* Counts, per field, the values that do not read as the field's type (and the empty ones), for one warning per field.
|
|
26
|
+
* Shared by the whole render (buildDataSets) and the streaming export, which both type rows with coerce().
|
|
27
|
+
* @param {string} dsName @param {(msg: string) => void} warn
|
|
28
|
+
*/
|
|
29
|
+
export function badValues(dsName: string, warn: (msg: string) => void): {
|
|
30
|
+
/** the row being typed, 1-based */
|
|
31
|
+
at: (n: number) => void;
|
|
32
|
+
/** coerce() options for one field, on top of base */
|
|
33
|
+
opt: (fd: any, base: any) => any;
|
|
34
|
+
done: () => void;
|
|
35
|
+
};
|
|
23
36
|
/**
|
|
24
37
|
* Guess field names and types from sample rows. A string that looks like an ISO date (2024-01-31, 2024-01-31T10:00Z)
|
|
25
38
|
* becomes a date field; dates: false (a data set's detectDates: false) keeps it text. To keep one field as text,
|
|
@@ -92,6 +92,7 @@ export const OVER_TIME: "The report ran past its time limit.";
|
|
|
92
92
|
export const ROW_PARENT: WeakMap<object, any>;
|
|
93
93
|
/** The aggregates a streaming export folds row by row (aggregator). */
|
|
94
94
|
export const FOLDS: Set<string>;
|
|
95
|
+
export function isAggregate(name: any): boolean;
|
|
95
96
|
export namespace FUNCTIONS {
|
|
96
97
|
function format(ctx: any, v: any, f: any): any;
|
|
97
98
|
function upper(ctx: any, s: any): any;
|
|
@@ -70,8 +70,6 @@ export class ReportError extends Error {
|
|
|
70
70
|
constructor(msg: string, extra?: object);
|
|
71
71
|
}
|
|
72
72
|
export const BAND_ITEMS: 250000;
|
|
73
|
-
/** The start of the warning for CJK text without the optional CJK fonts (the viewer opens its warnings for it). */
|
|
74
|
-
export const NO_CJK_FONTS: "Text in Japanese/Chinese/Korean needs the optional CJK fonts: npm i @reportwright/fonts-cjk, then npx reportwright-fonts-cjk (npm); in the app, npm run fonts:cjk";
|
|
75
73
|
/**
|
|
76
74
|
* Options for render(). All optional.
|
|
77
75
|
*/
|
|
@@ -90,6 +88,10 @@ export type RenderOptions = {
|
|
|
90
88
|
* the fonts; share one across renders (a new one loads them again)
|
|
91
89
|
*/
|
|
92
90
|
fontStore?: import("./text/fonts.js").FontStore;
|
|
91
|
+
/**
|
|
92
|
+
* the viewer: load only the core face up front; the other bundled faces when the layout first needs one
|
|
93
|
+
*/
|
|
94
|
+
lazyFonts?: boolean;
|
|
93
95
|
/**
|
|
94
96
|
* loads a font the store does not have
|
|
95
97
|
*/
|
|
@@ -174,6 +176,11 @@ export type RenderOptions = {
|
|
|
174
176
|
* the zone dates show in, when the report sets none
|
|
175
177
|
*/
|
|
176
178
|
timeZone?: string;
|
|
179
|
+
/**
|
|
180
|
+
* the engine package's render() warns once (model.warnings, and the console once
|
|
181
|
+
* per process) when a data set has more rows than this, pointing at exportPdfStream (default 100000; 0 or false: no warning)
|
|
182
|
+
*/
|
|
183
|
+
largeReportRows?: number | false;
|
|
177
184
|
/**
|
|
178
185
|
* internal (subreports): the width the child body is laid out to
|
|
179
186
|
*/
|
|
@@ -232,8 +239,9 @@ export type RenderOptions = {
|
|
|
232
239
|
} | null)[];
|
|
233
240
|
};
|
|
234
241
|
};
|
|
242
|
+
import { NO_CJK_FONTS } from './notices.js';
|
|
235
243
|
import { FontStore } from './text/fonts.js';
|
|
236
244
|
import { TextMeasurer } from './text/measure.js';
|
|
237
245
|
import { ITEMS } from './items/index.js';
|
|
238
246
|
import { finishText } from './text/measure.js';
|
|
239
|
-
export { FontStore, TextMeasurer, ITEMS, finishText };
|
|
247
|
+
export { NO_CJK_FONTS, FontStore, TextMeasurer, ITEMS, finishText };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* pdf-lib and fontkit, loaded on first use rather than at import: evaluating them was most of the engine's import time
|
|
3
|
+
* (about 110 ms and 180 ms on an M2). await loadFontkit() (a font is parsed) or loadPdfLib() (exportPdf) first; the
|
|
4
|
+
* bindings below are set then (ES modules' live bindings: `import { PDFName } from './lazylibs.js'` sees them).
|
|
5
|
+
* Node: require() (both are CommonJS; import() of one costs ~60 ms more, its named exports read by Node's CJS lexer
|
|
6
|
+
* through every re-exported file). Elsewhere (a bundler, a browser): import(), which a bundler may split into a chunk.
|
|
7
|
+
*/
|
|
8
|
+
/** @typedef {typeof import('pdf-lib')} PdfLib */
|
|
9
|
+
/** @typedef {import('pdf-lib').PDFDocument} PDFDocument */
|
|
10
|
+
/** @typedef {import('pdf-lib').PDFName} PDFName */
|
|
11
|
+
/** @typedef {import('pdf-lib').PDFString} PDFString */
|
|
12
|
+
/** @typedef {import('pdf-lib').PDFHexString} PDFHexString */
|
|
13
|
+
/** @typedef {import('pdf-lib').PDFRawStream} PDFRawStream */
|
|
14
|
+
/** @typedef {import('pdf-lib').PDFStream} PDFStream */
|
|
15
|
+
/** @typedef {import('pdf-lib').PDFArray} PDFArray */
|
|
16
|
+
/** @typedef {import('pdf-lib').PDFDict} PDFDict */
|
|
17
|
+
/** @typedef {import('pdf-lib').PDFNumber} PDFNumber */
|
|
18
|
+
/** @typedef {import('pdf-lib').PDFBool} PDFBool */
|
|
19
|
+
/** @type {any} @pdf-lib/fontkit */ export let fontkit: any;
|
|
20
|
+
export type PDFDocument = import("pdf-lib").PDFDocument;
|
|
21
|
+
/** @type {PdfLib['PDFDocument']} */ export let PDFDocument: PdfLib["PDFDocument"];
|
|
22
|
+
export type PDFName = import("pdf-lib").PDFName;
|
|
23
|
+
/** @type {PdfLib['PDFName']} */ export let PDFName: PdfLib["PDFName"];
|
|
24
|
+
export type PDFString = import("pdf-lib").PDFString;
|
|
25
|
+
/** @type {PdfLib['PDFString']} */ export let PDFString: PdfLib["PDFString"];
|
|
26
|
+
export type PDFHexString = import("pdf-lib").PDFHexString;
|
|
27
|
+
/** @type {PdfLib['PDFHexString']} */ export let PDFHexString: PdfLib["PDFHexString"];
|
|
28
|
+
export type PDFRawStream = import("pdf-lib").PDFRawStream;
|
|
29
|
+
/** @type {PdfLib['PDFRawStream']} */ export let PDFRawStream: PdfLib["PDFRawStream"];
|
|
30
|
+
export type PDFStream = import("pdf-lib").PDFStream;
|
|
31
|
+
/** @type {PdfLib['PDFStream']} */ export let PDFStream: PdfLib["PDFStream"];
|
|
32
|
+
export type PDFArray = import("pdf-lib").PDFArray;
|
|
33
|
+
/** @type {PdfLib['PDFArray']} */ export let PDFArray: PdfLib["PDFArray"];
|
|
34
|
+
export type PDFDict = import("pdf-lib").PDFDict;
|
|
35
|
+
/** @type {PdfLib['PDFDict']} */ export let PDFDict: PdfLib["PDFDict"];
|
|
36
|
+
export type PDFNumber = import("pdf-lib").PDFNumber;
|
|
37
|
+
/** @type {PdfLib['PDFNumber']} */ export let PDFNumber: PdfLib["PDFNumber"];
|
|
38
|
+
export type PDFBool = import("pdf-lib").PDFBool;
|
|
39
|
+
/** @type {PdfLib['PDFBool']} */ export let PDFBool: PdfLib["PDFBool"];
|
|
40
|
+
/** @type {PdfLib['rgb']} */ export let rgb: PdfLib["rgb"];
|
|
41
|
+
/** @type {PdfLib['pushGraphicsState']} */ export let pushGraphicsState: PdfLib["pushGraphicsState"];
|
|
42
|
+
/** @type {PdfLib['popGraphicsState']} */ export let popGraphicsState: PdfLib["popGraphicsState"];
|
|
43
|
+
/** @type {PdfLib['concatTransformationMatrix']} */ export let concatTransformationMatrix: PdfLib["concatTransformationMatrix"];
|
|
44
|
+
export function loadFontkit(): Promise<void>;
|
|
45
|
+
export function loadPdfLib(): Promise<void>;
|
|
46
|
+
export type PdfLib = typeof import("pdf-lib");
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const NO_CJK_FONTS: "Text in Japanese/Chinese/Korean needs the optional CJK fonts: npm i @reportwright/fonts-cjk, then npx reportwright-fonts-cjk (npm); in the app, npm run fonts:cjk";
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The warnings for the keys of opts that are not options, each with the nearest option (Levenshtein 2 at most) as
|
|
3
|
+
* "Did you mean". A key close to a security option (encrypt, prepare) throws instead: carrying on would write a file
|
|
4
|
+
* without the password or signature the caller asked for.
|
|
5
|
+
* @param {any} opts @param {Set<string>} [known]
|
|
6
|
+
* @returns {string[]}
|
|
7
|
+
*/
|
|
8
|
+
export function checkOptions(opts: any, known?: Set<string>): string[];
|
|
9
|
+
/** every option the three functions (and what they pass on) read */
|
|
10
|
+
export const KNOWN_OPTIONS: Set<string>;
|
|
@@ -11,45 +11,40 @@ export function memorySorter(cmp: (a: any, b: any) => number): {
|
|
|
11
11
|
* @param {any} def0 the report definition
|
|
12
12
|
* @param {{ format: 'csv'|'xlsx', parameters?: object, timeZone?: string, now?: Date, state?: any, loadReport?: (id: string) => Promise<any>,
|
|
13
13
|
* reportId?: string, fetch?: typeof fetch, baseUrl?: string, sql?: (src: any, p: any) => Promise<object[]>,
|
|
14
|
-
* sqlRows?: (src: any, p: any) => AsyncIterable<object[]>, sources?: Record<string, any>, sorter?: (cmp: (a: any, b: any) => number) => any, presorted?: boolean,
|
|
14
|
+
* sqlRows?: (src: any, p: any, o: { signal?: AbortSignal }) => AsyncIterable<object[]>, signal?: AbortSignal, sources?: Record<string, any>, sorter?: (cmp: (a: any, b: any) => number) => any, presorted?: boolean,
|
|
15
15
|
* deadline?: number, timeoutMs?: number, maxRows?: number, maxJsonRowBytes?: number, maxJsonWholeBytes?: number }} opts
|
|
16
16
|
* @returns {Promise<{ why: string } | { why?: undefined, name: string, columns: number[], title: string, timeZone: string|null, locale: string|null, currency: string|null, warnings: string[], rows: () => AsyncGenerator<any>, records: () => AsyncGenerator<any>, grouped: () => AsyncGenerator<any>, fieldList: () => Promise<any[]>, stats: { rows: number } }>}
|
|
17
17
|
*/
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
reportId?: string;
|
|
26
|
-
fetch?: typeof fetch;
|
|
27
|
-
baseUrl?: string;
|
|
28
|
-
sql?: (src: any, p: any) => Promise<object[]>;
|
|
29
|
-
sqlRows?: (src: any, p: any) => AsyncIterable<object[]>;
|
|
30
|
-
sources?: Record<string, any>;
|
|
31
|
-
sorter?: (cmp: (a: any, b: any) => number) => any;
|
|
32
|
-
presorted?: boolean;
|
|
33
|
-
deadline?: number;
|
|
34
|
-
timeoutMs?: number;
|
|
35
|
-
maxRows?: number;
|
|
36
|
-
maxJsonRowBytes?: number;
|
|
37
|
-
maxJsonWholeBytes?: number;
|
|
38
|
-
}): Promise<{
|
|
39
|
-
why: string;
|
|
18
|
+
/**
|
|
19
|
+
* The batches of a sqlRows source: an async or sync iterable of arrays of rows, each checked (a single row is a common slip).
|
|
20
|
+
* @param {Function} sqlRows @param {any} src @param {any} p @param {AbortSignal} [signal]
|
|
21
|
+
*/
|
|
22
|
+
export function sqlBatches(sqlRows: Function, src: any, p: any, signal?: AbortSignal): AsyncGenerator<any[], void, unknown>;
|
|
23
|
+
export function planStream(def0: any, opts: any): Promise<{
|
|
24
|
+
why: any;
|
|
40
25
|
} | {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
26
|
+
name: any;
|
|
27
|
+
columns: any;
|
|
28
|
+
title: any;
|
|
29
|
+
timeZone: any;
|
|
30
|
+
locale: any;
|
|
31
|
+
currency: any;
|
|
32
|
+
warnings: any[];
|
|
33
|
+
rows: () => AsyncGenerator<{
|
|
34
|
+
kind: any;
|
|
35
|
+
level: any;
|
|
36
|
+
cells: {
|
|
37
|
+
col: number;
|
|
38
|
+
value: any;
|
|
39
|
+
format: any;
|
|
40
|
+
bold: boolean;
|
|
41
|
+
span: number;
|
|
42
|
+
colIndex: number;
|
|
43
|
+
}[];
|
|
44
|
+
}, void, unknown>;
|
|
45
|
+
records: (grouped?: boolean) => AsyncGenerator<any, void, unknown>;
|
|
46
|
+
grouped: () => AsyncGenerator<any, void, unknown>;
|
|
47
|
+
fieldList: () => Promise<any>;
|
|
53
48
|
stats: {
|
|
54
49
|
rows: number;
|
|
55
50
|
};
|
|
@@ -11,12 +11,32 @@ export function setCustomFonts(list: {
|
|
|
11
11
|
weight?: number;
|
|
12
12
|
style?: string;
|
|
13
13
|
}[]): void;
|
|
14
|
+
/**
|
|
15
|
+
* The family a fontFamily value names: a registered family (any case), else the first of a CSS list that is one, else a
|
|
16
|
+
* generic name's family. Anything else is unknown: Inter, or JetBrains Mono for a monospace name, and `unknown` is the
|
|
17
|
+
* name the render warns about.
|
|
18
|
+
* @param {string} name @returns {{ family: string, unknown?: string }}
|
|
19
|
+
*/
|
|
20
|
+
export function familyOf(name: string): {
|
|
21
|
+
family: string;
|
|
22
|
+
unknown?: string;
|
|
23
|
+
};
|
|
14
24
|
/**
|
|
15
25
|
* The face for a family, weight and style, matched as CSS does: style first (italic faces when asked
|
|
16
|
-
* and there are some), then the nearest weight (CSS Fonts 4, §5.2). Unknown families use Inter
|
|
17
|
-
*
|
|
26
|
+
* and there are some), then the nearest weight (CSS Fonts 4, §5.2). Unknown families use Inter (JetBrains Mono for a
|
|
27
|
+
* monospace name), and their names go into `unknown`, for the render's warning (N39).
|
|
28
|
+
* @param {string} [family] @param {string|number} [weight] @param {string} [style] @param {Set<string>} [unknown]
|
|
29
|
+
*/
|
|
30
|
+
export function resolveFontKey(family?: string, weight?: string | number, style?: string, unknown?: Set<string>): string;
|
|
31
|
+
/**
|
|
32
|
+
* The embedded face that stands in for a standard font where one must be embedded (PDF/A, PDF/UA, form fields) and for
|
|
33
|
+
* the characters its encoding lacks: JetBrains Mono for Courier, else Inter, in the same weight and style. No
|
|
34
|
+
* metric-compatible face (Liberation, say) ships, so its widths differ. Any other key is returned as it is.
|
|
35
|
+
* @param {string} key
|
|
18
36
|
*/
|
|
19
|
-
export function
|
|
37
|
+
export function embeddedFace(key: string): string;
|
|
38
|
+
/** The name Word, Excel and PowerPoint know for a font key's family (the standard fonts by their Windows equivalents). */
|
|
39
|
+
export function officeFamily(key: any): any;
|
|
20
40
|
/** CSS description of a font key, for SVG/HTML output. */
|
|
21
41
|
export function fontCss(key: any): {
|
|
22
42
|
family: string;
|
|
@@ -45,10 +65,12 @@ export function fallbackKey(cp: any, key: any): string;
|
|
|
45
65
|
* The faces a report definition names before layout: every object with fontFamily, fontWeight or fontStyle (styles,
|
|
46
66
|
* named styles, item and rich-text styles, table and group styles), and the bold face a chart's titles use. Loaded up
|
|
47
67
|
* front, so a report that uses bold or italic lays out in one pass. Data (dataSources, inline data) is not read.
|
|
48
|
-
*
|
|
68
|
+
* Unknown family names go into `unknown` (the render warns about them).
|
|
69
|
+
* @param {any} def @param {Set<string>} [unknown] @returns {string[]} face keys
|
|
49
70
|
*/
|
|
50
|
-
export function fontsForDef(def: any): string[];
|
|
71
|
+
export function fontsForDef(def: any, unknown?: Set<string>): string[];
|
|
51
72
|
export function fontsFor(texts: any): any[];
|
|
73
|
+
export { isStandard };
|
|
52
74
|
/** The optional families (scripts/fetch-fonts-cjk.mjs). */
|
|
53
75
|
export const OPTIONAL_KEYS: string[];
|
|
54
76
|
/** family → its faces: the bundled families, then the fonts uploaded to the server (setCustomFonts). @type {Record<string, Face[]>} */
|
|
@@ -63,6 +85,7 @@ export const CORE_FONT_KEY: "Inter-Regular";
|
|
|
63
85
|
export const PRELOAD_KEYS: string[];
|
|
64
86
|
/** The HarfBuzz shaper (WASM). FontStore loads it like a font, from /fonts/harfbuzz.wasm, once text needs shaping. */
|
|
65
87
|
export const SHAPER: "harfbuzz";
|
|
88
|
+
export function standardCss(key: string): string | null;
|
|
66
89
|
export function allFontKeys(): string[];
|
|
67
90
|
/**
|
|
68
91
|
* Loads font files once and keeps the parsed fontkit objects; SHAPER loads the HarfBuzz shaper.
|
|
@@ -93,4 +116,6 @@ export type Face = {
|
|
|
93
116
|
weight: number;
|
|
94
117
|
style: "normal" | "italic";
|
|
95
118
|
file: string;
|
|
119
|
+
standard?: boolean;
|
|
96
120
|
};
|
|
121
|
+
import { isStandard } from './standard.js';
|
|
@@ -45,6 +45,10 @@ export class TextMeasurer {
|
|
|
45
45
|
missing: Set<string>;
|
|
46
46
|
/** characters no font could draw @type {Set<string>} */
|
|
47
47
|
noGlyph: Set<string>;
|
|
48
|
+
/** font names the text asked for that are not available (resolveFontKey): the render warns @type {Set<string>} */
|
|
49
|
+
unknownFonts: Set<string>;
|
|
50
|
+
/** standard-font key → the characters its encoding lacks, drawn in embeddedFace(key): the render warns @type {Map<string, Set<string>>} */
|
|
51
|
+
substituted: Map<string, Set<string>>;
|
|
48
52
|
/**
|
|
49
53
|
* The key to measure with: `key` when loaded; else (not loaded yet, or failed) the bundled face of the same weight
|
|
50
54
|
* and style when that is loaded, else the core regular face. A key not yet loaded is asked for in the next pass.
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A standard font as a fontkit-like object (unitsPerEm 1000). Loaded on first use: the metrics are about 130 KB.
|
|
3
|
+
* @param {string} key a PostScript name of STANDARD_FACES
|
|
4
|
+
*/
|
|
5
|
+
export function standardFont(key: string): Promise<{
|
|
6
|
+
standard: boolean;
|
|
7
|
+
postscriptName: string;
|
|
8
|
+
familyName: any;
|
|
9
|
+
unitsPerEm: number;
|
|
10
|
+
ascent: any;
|
|
11
|
+
descent: any;
|
|
12
|
+
capHeight: any;
|
|
13
|
+
xHeight: any;
|
|
14
|
+
italicAngle: number;
|
|
15
|
+
underlinePosition: any;
|
|
16
|
+
underlineThickness: any;
|
|
17
|
+
bbox: {
|
|
18
|
+
minX: any;
|
|
19
|
+
minY: any;
|
|
20
|
+
maxX: any;
|
|
21
|
+
maxY: any;
|
|
22
|
+
};
|
|
23
|
+
/** WinAnsi for the text fonts (Symbol and ZapfDingbats use their own built-in encodings) */
|
|
24
|
+
winAnsi: boolean;
|
|
25
|
+
widths: any[];
|
|
26
|
+
/** @param {number} cp */
|
|
27
|
+
hasGlyphForCodePoint: (cp: number) => boolean;
|
|
28
|
+
/** @param {number} cp */
|
|
29
|
+
glyphForCodePoint: (cp: number) => any;
|
|
30
|
+
getGlyph: (id: number) => any;
|
|
31
|
+
}>;
|
|
32
|
+
/**
|
|
33
|
+
* The 14 standard PDF fonts (Helvetica, Times, Courier in four faces each, Symbol, ZapfDingbats): every PDF reader has
|
|
34
|
+
* them, so a PDF names them and embeds nothing. Their metrics are Adobe's AFM files, as @pdf-lib/standard-fonts (pdf-lib's
|
|
35
|
+
* own dependency) ships them; this wraps one in the part of fontkit's font API the engine and the PDF exporters read, so
|
|
36
|
+
* layout measures with the widths the PDF's /Widths array gives. A glyph ID here is the character's code in the font's
|
|
37
|
+
* encoding (WinAnsi; Symbol and ZapfDingbats have their own), one byte; 0 = not in the encoding.
|
|
38
|
+
*/
|
|
39
|
+
/** [family, PostScript name, weight, style] */
|
|
40
|
+
export const STANDARD_FACES: (string | number)[][];
|
|
41
|
+
export const STANDARD_KEYS: Set<string>;
|
|
42
|
+
export function isStandard(key: string): boolean;
|
|
@@ -21,3 +21,17 @@ export function exportDocx(model: any, opt?: {
|
|
|
21
21
|
figures?: boolean;
|
|
22
22
|
xmlChunk?: number;
|
|
23
23
|
}): Promise<Uint8Array>;
|
|
24
|
+
/**
|
|
25
|
+
* The .docx of pages as they come (an array, or an async iterable: exportDocxStream's pages, a window at a time), its
|
|
26
|
+
* zip bytes handed to put as they are made (awaited: back-pressure). Each page's XML goes into word/document.xml's
|
|
27
|
+
* deflater once the page is converted, so neither the pages nor the document XML are held whole; the parts that name
|
|
28
|
+
* the pictures follow the document. model: the model, or a paged plan's info (width, height; locale, name).
|
|
29
|
+
* @param {Iterable<any>|AsyncIterable<any>} pages @param {{ width: number, height: number, locale?: string, name?: string }} model
|
|
30
|
+
* @param {NonNullable<Parameters<typeof exportDocx>[1]>} opt @param {(bytes: Uint8Array) => any} put
|
|
31
|
+
*/
|
|
32
|
+
export function writeDocx(pages: Iterable<any> | AsyncIterable<any>, model: {
|
|
33
|
+
width: number;
|
|
34
|
+
height: number;
|
|
35
|
+
locale?: string;
|
|
36
|
+
name?: string;
|
|
37
|
+
}, opt: NonNullable<Parameters<typeof exportDocx>[1]>, put: (bytes: Uint8Array) => any): Promise<void>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Report definition → .docx written to sink as its pages are laid out.
|
|
3
|
+
* @param {any} def @param {any} opts render()'s options and exportDocx's (fontStore, fetchImage, figures, rasterize, lang,
|
|
4
|
+
* title), plus timeoutMs or deadline, signal, window (rows laid out at once), maxRows, sorter, sqlRows as exportPdfStream
|
|
5
|
+
* @param {Sink} sink not closed
|
|
6
|
+
* @returns {Promise<StreamResult>}
|
|
7
|
+
*/
|
|
8
|
+
export function exportDocxStream(def: any, opts: any, sink: Sink): Promise<StreamResult>;
|
|
9
|
+
/**
|
|
10
|
+
* Report definition → .xlsx written to sink as its rows come.
|
|
11
|
+
* @param {any} def @param {any} opts render()'s options and exportXlsx's (currency, title, formulas, fontStore,
|
|
12
|
+
* fetchImage), plus timeoutMs or deadline, signal, maxRows, sorter, sqlRows as exportPdfStream
|
|
13
|
+
* @param {Sink} sink not closed
|
|
14
|
+
* @returns {Promise<StreamResult>}
|
|
15
|
+
*/
|
|
16
|
+
export function exportXlsxStream(def: any, opts: any, sink: Sink): Promise<StreamResult>;
|
|
17
|
+
export type Sink = {
|
|
18
|
+
write(u8: Uint8Array): any;
|
|
19
|
+
once?: (ev: string, cb: () => void) => any;
|
|
20
|
+
};
|
|
21
|
+
export type StreamResult = {
|
|
22
|
+
streamed: boolean;
|
|
23
|
+
pages?: number;
|
|
24
|
+
rows?: number;
|
|
25
|
+
warnings: string[];
|
|
26
|
+
why?: string;
|
|
27
|
+
};
|
|
@@ -9,8 +9,10 @@
|
|
|
9
9
|
* tagged?: { lang?: string }, drillBase?: string, onWarning?: (message: string) => void, timeoutMs?: number,
|
|
10
10
|
* creationDate?: Date }} [opt]
|
|
11
11
|
* subset: a HarfBuzz subsetter (see subset.js). Without it, fonts embed in full.
|
|
12
|
-
* pdfa:
|
|
13
|
-
*
|
|
12
|
+
* pdfa: a PDF/A-2b file (2a with tagged): true uses the sRGB profile of @reportwright/fonts, or pass { icc } (this
|
|
13
|
+
* function itself needs icc; the engine package fills it in). prepare: last change to the pdf-lib PDFDocument before
|
|
14
|
+
* saving (the server adds a signature placeholder there). save: pdf-lib save options. These, encrypt and PDF/A without
|
|
15
|
+
* a profile take the whole-model path in exportPdfStream; a PDF/A file with a profile streams.
|
|
14
16
|
* encrypt: { userPassword, ownerPassword, permissions } — AES-256 (see encrypt.js); not with pdfa or prepare.
|
|
15
17
|
* tagged: an accessible PDF (PDF/UA-1, see pdfua.js): structure tree, marked content, artifacts, language, title
|
|
16
18
|
* shown; with pdfa it is PDF/A-2a. Off, the file is exactly what it was.
|
|
@@ -42,4 +44,4 @@ export function exportPdf(model: any, fontStore: import("../engine/text/fonts.js
|
|
|
42
44
|
timeoutMs?: number;
|
|
43
45
|
creationDate?: Date;
|
|
44
46
|
}): any;
|
|
45
|
-
import { PDFDocument } from '
|
|
47
|
+
import { PDFDocument } from '../engine/lazylibs.js';
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/** The font dictionary's entries (pdf-lib's context.obj takes them as they are: strings become names). @param {any} f a standard font */
|
|
2
|
+
export function standardFontEntries(f: any): {
|
|
3
|
+
FirstChar: number;
|
|
4
|
+
LastChar: number;
|
|
5
|
+
Widths: any;
|
|
6
|
+
Encoding?: string;
|
|
7
|
+
Type: string;
|
|
8
|
+
Subtype: string;
|
|
9
|
+
BaseFont: any;
|
|
10
|
+
};
|
|
11
|
+
/** The same dictionary as PDF syntax. @param {any} f */
|
|
12
|
+
export function standardFontDict(f: any): string;
|
|
13
|
+
/** A literal string's body: one byte per character, escaped. @param {any} f a standard font @param {string} text */
|
|
14
|
+
export function standardLiteral(f: any, text: string): string;
|
|
15
|
+
/**
|
|
16
|
+
* A page whose standard-font text is redrawn in the embedded stand-ins (PDF/A, PDF/UA), at the standard font's glyph
|
|
17
|
+
* positions. The page and the items it changes are copies; families gets the standard families it found.
|
|
18
|
+
* @param {any} pg @param {(key: string) => any} fontOf the loaded fonts by key @param {Set<string>} families
|
|
19
|
+
*/
|
|
20
|
+
export function embeddedPage(pg: any, fontOf: (key: string) => any, families: Set<string>): any;
|
|
21
|
+
/** The warnings for the standard families a PDF/A or PDF/UA file drew in their stand-ins (a family's name is its regular face's key). @param {Set<string>} families */
|
|
22
|
+
export function embeddedWarnings(families: Set<string>): string[];
|
|
23
|
+
export function standIns(store: import("../engine/text/fonts.js").FontStore): string[];
|