@oxog/printkit 1.0.0 → 1.1.1
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 +85 -18
- package/dist/chunk-E7TXCY3N.cjs +491 -0
- package/dist/chunk-E7TXCY3N.cjs.map +1 -0
- package/dist/chunk-N44HS34F.js +491 -0
- package/dist/chunk-N44HS34F.js.map +1 -0
- package/dist/errors-COjJm-gl.d.cts +291 -0
- package/dist/errors-COjJm-gl.d.ts +291 -0
- package/dist/index.cjs +1 -486
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +32 -273
- package/dist/index.d.ts +32 -273
- package/dist/index.js +1 -486
- package/dist/index.js.map +1 -1
- package/dist/react.cjs +1 -486
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +10 -125
- package/dist/react.d.ts +10 -125
- package/dist/react.js +1 -486
- package/dist/react.js.map +1 -1
- package/package.json +19 -11
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
type PageSizeName = 'A3' | 'A4' | 'A5' | 'Letter' | 'Legal' | 'Tabloid';
|
|
2
|
+
interface CustomSize {
|
|
3
|
+
width: number | string;
|
|
4
|
+
height: number | string;
|
|
5
|
+
}
|
|
6
|
+
type PageSize = PageSizeName | CustomSize;
|
|
7
|
+
type Orientation = 'portrait' | 'landscape';
|
|
8
|
+
interface MarginOptions {
|
|
9
|
+
top?: number | string | undefined;
|
|
10
|
+
right?: number | string | undefined;
|
|
11
|
+
bottom?: number | string | undefined;
|
|
12
|
+
left?: number | string | undefined;
|
|
13
|
+
}
|
|
14
|
+
interface PageInfo {
|
|
15
|
+
pageNumber: number;
|
|
16
|
+
totalPages: number;
|
|
17
|
+
title: string;
|
|
18
|
+
date: Date;
|
|
19
|
+
}
|
|
20
|
+
type HeaderFooterFn = (info: PageInfo) => string;
|
|
21
|
+
interface PrintOptions {
|
|
22
|
+
title?: string | undefined;
|
|
23
|
+
pageSize?: PageSize | undefined;
|
|
24
|
+
orientation?: Orientation | undefined;
|
|
25
|
+
margin?: number | string | MarginOptions | undefined;
|
|
26
|
+
/**
|
|
27
|
+
* Header template (HTML string with `{title}`, `{date}`, `{time}`, `{page}`
|
|
28
|
+
* and `{pages}` placeholders) or a function returning HTML.
|
|
29
|
+
*
|
|
30
|
+
* When printing, a string with `{page}`/`{pages}` is shown on every page
|
|
31
|
+
* with the real numbers through CSS `@page` margin boxes (as text) in
|
|
32
|
+
* browsers that support them (Chromium 131+). In other browsers, and for
|
|
33
|
+
* templates without those placeholders or function templates, the header
|
|
34
|
+
* is printed once at the top of the document; `{page}`/`{pages}` are left
|
|
35
|
+
* empty and function templates receive page 1 of 1.
|
|
36
|
+
*
|
|
37
|
+
* PDF export draws it on every page with the real page number and count.
|
|
38
|
+
*/
|
|
39
|
+
header?: string | HeaderFooterFn | undefined;
|
|
40
|
+
/** Footer template, see `header`. */
|
|
41
|
+
footer?: string | HeaderFooterFn | undefined;
|
|
42
|
+
styles?: string | string[] | undefined;
|
|
43
|
+
styleSheets?: string[] | undefined;
|
|
44
|
+
copyStyles?: boolean | undefined;
|
|
45
|
+
pageBreakBefore?: string | undefined;
|
|
46
|
+
pageBreakAfter?: string | undefined;
|
|
47
|
+
avoidBreakInside?: string | undefined;
|
|
48
|
+
removeAfterPrint?: boolean | undefined;
|
|
49
|
+
/** Print background colours and images (default true); false removes them from every element */
|
|
50
|
+
printBackground?: boolean | undefined;
|
|
51
|
+
onBeforePrint?: (() => void | Promise<void>) | undefined;
|
|
52
|
+
onAfterPrint?: (() => void) | undefined;
|
|
53
|
+
onError?: ((error: PrintError$1) => void) | undefined;
|
|
54
|
+
}
|
|
55
|
+
type PrintTarget = HTMLElement | string | HTMLElement[] | string[];
|
|
56
|
+
interface Printer {
|
|
57
|
+
print(target: PrintTarget, options?: PrintOptions): Promise<void>;
|
|
58
|
+
printHTML(html: string, options?: PrintOptions): Promise<void>;
|
|
59
|
+
printURL(url: string, options?: PrintOptions): Promise<void>;
|
|
60
|
+
printImage(src: string | HTMLImageElement, options?: PrintOptions | undefined): Promise<void>;
|
|
61
|
+
printImages(sources: (string | HTMLImageElement)[], options?: PrintOptions | undefined): Promise<void>;
|
|
62
|
+
printJSON(data: unknown, options?: PrintJSONOptions): Promise<void>;
|
|
63
|
+
printTable(data: TableData, options?: PrintTableOptions): Promise<void>;
|
|
64
|
+
setDefaultOptions(options: PrintOptions): void;
|
|
65
|
+
getDefaultOptions(): PrintOptions;
|
|
66
|
+
destroy(): void;
|
|
67
|
+
}
|
|
68
|
+
interface PreviewOptions extends PrintOptions {
|
|
69
|
+
modal?: ModalOptions | undefined;
|
|
70
|
+
toolbar?: ToolbarOptions | undefined;
|
|
71
|
+
onPrint?: (() => void) | undefined;
|
|
72
|
+
onDownload?: (() => void) | undefined;
|
|
73
|
+
onClose?: (() => void) | undefined;
|
|
74
|
+
}
|
|
75
|
+
interface ModalOptions {
|
|
76
|
+
width?: string | number | undefined;
|
|
77
|
+
height?: string | number | undefined;
|
|
78
|
+
showToolbar?: boolean | undefined;
|
|
79
|
+
showPageNumbers?: boolean | undefined;
|
|
80
|
+
zoom?: number | undefined;
|
|
81
|
+
className?: string | undefined;
|
|
82
|
+
}
|
|
83
|
+
interface ToolbarOptions {
|
|
84
|
+
print?: boolean | undefined;
|
|
85
|
+
download?: boolean | undefined;
|
|
86
|
+
zoom?: boolean | undefined;
|
|
87
|
+
navigation?: boolean | undefined;
|
|
88
|
+
close?: boolean | undefined;
|
|
89
|
+
}
|
|
90
|
+
interface PrintPreview {
|
|
91
|
+
open(): void;
|
|
92
|
+
close(): void;
|
|
93
|
+
print(): Promise<void>;
|
|
94
|
+
download(filename?: string): Promise<void>;
|
|
95
|
+
setZoom(level: number): void;
|
|
96
|
+
getZoom(): number;
|
|
97
|
+
zoomIn(): void;
|
|
98
|
+
zoomOut(): void;
|
|
99
|
+
resetZoom(): void;
|
|
100
|
+
nextPage(): void;
|
|
101
|
+
prevPage(): void;
|
|
102
|
+
goToPage(page: number): void;
|
|
103
|
+
getCurrentPage(): number;
|
|
104
|
+
getTotalPages(): number;
|
|
105
|
+
isOpen(): boolean;
|
|
106
|
+
destroy(): void;
|
|
107
|
+
}
|
|
108
|
+
interface PDFOptions extends PrintOptions {
|
|
109
|
+
quality?: number | undefined;
|
|
110
|
+
scale?: number | undefined;
|
|
111
|
+
metadata?: PDFMetadata | undefined;
|
|
112
|
+
onProgress?: ((progress: number) => void) | undefined;
|
|
113
|
+
}
|
|
114
|
+
interface PDFMetadata {
|
|
115
|
+
title?: string | undefined;
|
|
116
|
+
author?: string | undefined;
|
|
117
|
+
subject?: string | undefined;
|
|
118
|
+
keywords?: string[] | undefined;
|
|
119
|
+
creator?: string | undefined;
|
|
120
|
+
creationDate?: Date | undefined;
|
|
121
|
+
}
|
|
122
|
+
interface PDFExporter {
|
|
123
|
+
toBlob(target: PrintTarget, options?: PDFOptions): Promise<Blob>;
|
|
124
|
+
toBase64(target: PrintTarget, options?: PDFOptions): Promise<string>;
|
|
125
|
+
toDataURL(target: PrintTarget, options?: PDFOptions): Promise<string>;
|
|
126
|
+
download(target: PrintTarget, filename: string, options?: PDFOptions | undefined): Promise<void>;
|
|
127
|
+
downloadHTML(html: string, filename: string, options?: PDFOptions | undefined): Promise<void>;
|
|
128
|
+
}
|
|
129
|
+
type JobPriority = 'low' | 'normal' | 'high';
|
|
130
|
+
type JobStatus = 'pending' | 'printing' | 'completed' | 'failed';
|
|
131
|
+
interface PrintJob {
|
|
132
|
+
id: string;
|
|
133
|
+
content: PrintTarget;
|
|
134
|
+
options?: PrintOptions | undefined;
|
|
135
|
+
priority?: JobPriority | undefined;
|
|
136
|
+
/** Number of automatic retries after a failed attempt (default 0) */
|
|
137
|
+
retries?: number | undefined;
|
|
138
|
+
/** Number of attempts made so far */
|
|
139
|
+
attempts?: number | undefined;
|
|
140
|
+
status: JobStatus;
|
|
141
|
+
error?: Error | undefined;
|
|
142
|
+
createdAt: Date;
|
|
143
|
+
completedAt?: Date | undefined;
|
|
144
|
+
}
|
|
145
|
+
type NewPrintJob = Omit<PrintJob, 'id' | 'status' | 'createdAt' | 'attempts'>;
|
|
146
|
+
type QueueEvent = 'jobStart' | 'jobComplete' | 'jobError' | 'queueComplete' | 'queuePause' | 'queueResume';
|
|
147
|
+
type QueueEventHandler<E extends QueueEvent> = E extends 'jobError' ? (job: PrintJob, error: Error) => void : E extends 'jobStart' | 'jobComplete' ? (job: PrintJob) => void : () => void;
|
|
148
|
+
interface PrintQueue {
|
|
149
|
+
add(job: NewPrintJob): string;
|
|
150
|
+
remove(jobId: string): boolean;
|
|
151
|
+
/** Puts a failed job back in the queue; returns false if it is not a failed job */
|
|
152
|
+
retry(jobId: string): boolean;
|
|
153
|
+
clear(): void;
|
|
154
|
+
getJob(jobId: string): PrintJob | undefined;
|
|
155
|
+
getJobs(): PrintJob[];
|
|
156
|
+
getPendingJobs(): PrintJob[];
|
|
157
|
+
printNext(): Promise<void>;
|
|
158
|
+
printAll(): Promise<void>;
|
|
159
|
+
pause(): void;
|
|
160
|
+
resume(): void;
|
|
161
|
+
on<E extends QueueEvent>(event: E, handler: QueueEventHandler<E>): () => void;
|
|
162
|
+
off<E extends QueueEvent>(event: E, handler: QueueEventHandler<E>): void;
|
|
163
|
+
destroy(): void;
|
|
164
|
+
}
|
|
165
|
+
interface TableData {
|
|
166
|
+
headers: string[];
|
|
167
|
+
rows: (string | number)[][];
|
|
168
|
+
caption?: string | undefined;
|
|
169
|
+
}
|
|
170
|
+
interface PrintTableOptions extends PrintOptions {
|
|
171
|
+
tableStyles?: string | undefined;
|
|
172
|
+
headerStyles?: string | undefined;
|
|
173
|
+
cellStyles?: string | undefined;
|
|
174
|
+
stripedRows?: boolean | undefined;
|
|
175
|
+
bordered?: boolean | undefined;
|
|
176
|
+
}
|
|
177
|
+
interface PrintJSONOptions extends PrintOptions {
|
|
178
|
+
indent?: number | undefined;
|
|
179
|
+
syntaxHighlight?: boolean | undefined;
|
|
180
|
+
/**
|
|
181
|
+
* @deprecated Has no effect: printed output cannot be collapsed. Accepted
|
|
182
|
+
* for compatibility and will be removed in the next major version.
|
|
183
|
+
*/
|
|
184
|
+
collapsible?: boolean | undefined;
|
|
185
|
+
}
|
|
186
|
+
interface FormatOptions {
|
|
187
|
+
removeScripts?: boolean | undefined;
|
|
188
|
+
removeInputs?: boolean | undefined;
|
|
189
|
+
inlineStyles?: boolean | undefined;
|
|
190
|
+
removeHidden?: boolean | undefined;
|
|
191
|
+
}
|
|
192
|
+
interface PageOptions {
|
|
193
|
+
pageSize?: PageSize | undefined;
|
|
194
|
+
margin?: number | string | MarginOptions | undefined;
|
|
195
|
+
orientation?: Orientation | undefined;
|
|
196
|
+
}
|
|
197
|
+
type PrintErrorCode = 'PRINT_NOT_SUPPORTED' | 'ELEMENT_NOT_FOUND' | 'IFRAME_LOAD_FAILED' | 'PDF_EXPORT_FAILED' | 'STYLE_LOAD_FAILED' | 'CANCELLED' | 'UNKNOWN';
|
|
198
|
+
interface PrintError$1 extends Error {
|
|
199
|
+
code: PrintErrorCode;
|
|
200
|
+
target?: PrintTarget | undefined;
|
|
201
|
+
}
|
|
202
|
+
interface Dimensions {
|
|
203
|
+
width: string;
|
|
204
|
+
height: string;
|
|
205
|
+
}
|
|
206
|
+
interface PrintDocument {
|
|
207
|
+
content: string;
|
|
208
|
+
styles: string;
|
|
209
|
+
header?: string | undefined;
|
|
210
|
+
footer?: string | undefined;
|
|
211
|
+
pageSize: Dimensions;
|
|
212
|
+
margins: Required<MarginOptions>;
|
|
213
|
+
title: string;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* CSS class to hide elements when printing
|
|
218
|
+
*/
|
|
219
|
+
declare const PRINT_HIDE_CLASS = "print-hide";
|
|
220
|
+
/**
|
|
221
|
+
* CSS class to show elements only when printing
|
|
222
|
+
*/
|
|
223
|
+
declare const PRINT_ONLY_CLASS = "print-only";
|
|
224
|
+
/**
|
|
225
|
+
* Default print styles
|
|
226
|
+
*/
|
|
227
|
+
declare function getDefaultPrintStyles(): string;
|
|
228
|
+
/**
|
|
229
|
+
* Builds base document styles
|
|
230
|
+
*/
|
|
231
|
+
declare function getBaseDocumentStyles(): string;
|
|
232
|
+
/**
|
|
233
|
+
* Combines all default styles
|
|
234
|
+
*/
|
|
235
|
+
declare function getAllDefaultStyles(): string;
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* CSS class for page break before
|
|
239
|
+
*/
|
|
240
|
+
declare const BREAK_BEFORE_CLASS = "print-break-before";
|
|
241
|
+
/**
|
|
242
|
+
* CSS class for page break after
|
|
243
|
+
*/
|
|
244
|
+
declare const BREAK_AFTER_CLASS = "print-break-after";
|
|
245
|
+
/**
|
|
246
|
+
* CSS class to avoid break inside
|
|
247
|
+
*/
|
|
248
|
+
declare const AVOID_BREAK_CLASS = "print-avoid-break";
|
|
249
|
+
/**
|
|
250
|
+
* Creates a page break element
|
|
251
|
+
*/
|
|
252
|
+
declare function pageBreak(): HTMLDivElement;
|
|
253
|
+
/**
|
|
254
|
+
* Marks an element to avoid page breaks inside
|
|
255
|
+
*/
|
|
256
|
+
declare function avoidBreak(element: HTMLElement): void;
|
|
257
|
+
/**
|
|
258
|
+
* Marks an element to break before
|
|
259
|
+
*/
|
|
260
|
+
declare function breakBefore(element: HTMLElement): void;
|
|
261
|
+
/**
|
|
262
|
+
* Marks an element to break after
|
|
263
|
+
*/
|
|
264
|
+
declare function breakAfter(element: HTMLElement): void;
|
|
265
|
+
/**
|
|
266
|
+
* Calculates estimated page count based on content height
|
|
267
|
+
*/
|
|
268
|
+
declare function calculatePages(contentHeight: number, pageHeight: number, marginTop?: number, marginBottom?: number): number;
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* Custom error class for print operations
|
|
272
|
+
*/
|
|
273
|
+
declare class PrintError extends Error implements PrintError$1 {
|
|
274
|
+
readonly code: PrintErrorCode;
|
|
275
|
+
readonly target?: PrintTarget | undefined;
|
|
276
|
+
constructor(code: PrintErrorCode, message: string, target?: PrintTarget | undefined);
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Creates a PrintError with the appropriate message
|
|
280
|
+
*/
|
|
281
|
+
declare function createPrintError(code: PrintErrorCode, details?: string, target?: PrintTarget): PrintError;
|
|
282
|
+
/**
|
|
283
|
+
* Type guard to check if an error is a PrintError
|
|
284
|
+
*/
|
|
285
|
+
declare function isPrintError(error: unknown): error is PrintError;
|
|
286
|
+
/**
|
|
287
|
+
* Wraps an unknown error as a PrintError
|
|
288
|
+
*/
|
|
289
|
+
declare function wrapError(error: unknown, target?: PrintTarget): PrintError;
|
|
290
|
+
|
|
291
|
+
export { AVOID_BREAK_CLASS as A, BREAK_BEFORE_CLASS as B, type CustomSize as C, type Dimensions as D, type PDFMetadata as E, type PrintJob as F, type JobStatus as G, type HeaderFooterFn as H, type QueueEventHandler as I, type JobPriority as J, type TableData as K, type PrintTableOptions as L, type MarginOptions as M, type NewPrintJob as N, type Orientation as O, type PrintOptions as P, type QueueEvent as Q, type PrintJSONOptions as R, type FormatOptions as S, type ToolbarOptions as T, type PageOptions as U, type PrintErrorCode as V, type PrintError$1 as W, type PrintDocument as X, type Printer as a, type PrintTarget as b, type PreviewOptions as c, type PrintPreview as d, type PDFExporter as e, type PrintQueue as f, type PageSize as g, type PageSizeName as h, type PageInfo as i, getDefaultPrintStyles as j, getBaseDocumentStyles as k, getAllDefaultStyles as l, calculatePages as m, avoidBreak as n, breakBefore as o, pageBreak as p, breakAfter as q, PRINT_HIDE_CLASS as r, PRINT_ONLY_CLASS as s, BREAK_AFTER_CLASS as t, PrintError as u, createPrintError as v, isPrintError as w, wrapError as x, type ModalOptions as y, type PDFOptions as z };
|
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
type PageSizeName = 'A3' | 'A4' | 'A5' | 'Letter' | 'Legal' | 'Tabloid';
|
|
2
|
+
interface CustomSize {
|
|
3
|
+
width: number | string;
|
|
4
|
+
height: number | string;
|
|
5
|
+
}
|
|
6
|
+
type PageSize = PageSizeName | CustomSize;
|
|
7
|
+
type Orientation = 'portrait' | 'landscape';
|
|
8
|
+
interface MarginOptions {
|
|
9
|
+
top?: number | string | undefined;
|
|
10
|
+
right?: number | string | undefined;
|
|
11
|
+
bottom?: number | string | undefined;
|
|
12
|
+
left?: number | string | undefined;
|
|
13
|
+
}
|
|
14
|
+
interface PageInfo {
|
|
15
|
+
pageNumber: number;
|
|
16
|
+
totalPages: number;
|
|
17
|
+
title: string;
|
|
18
|
+
date: Date;
|
|
19
|
+
}
|
|
20
|
+
type HeaderFooterFn = (info: PageInfo) => string;
|
|
21
|
+
interface PrintOptions {
|
|
22
|
+
title?: string | undefined;
|
|
23
|
+
pageSize?: PageSize | undefined;
|
|
24
|
+
orientation?: Orientation | undefined;
|
|
25
|
+
margin?: number | string | MarginOptions | undefined;
|
|
26
|
+
/**
|
|
27
|
+
* Header template (HTML string with `{title}`, `{date}`, `{time}`, `{page}`
|
|
28
|
+
* and `{pages}` placeholders) or a function returning HTML.
|
|
29
|
+
*
|
|
30
|
+
* When printing, a string with `{page}`/`{pages}` is shown on every page
|
|
31
|
+
* with the real numbers through CSS `@page` margin boxes (as text) in
|
|
32
|
+
* browsers that support them (Chromium 131+). In other browsers, and for
|
|
33
|
+
* templates without those placeholders or function templates, the header
|
|
34
|
+
* is printed once at the top of the document; `{page}`/`{pages}` are left
|
|
35
|
+
* empty and function templates receive page 1 of 1.
|
|
36
|
+
*
|
|
37
|
+
* PDF export draws it on every page with the real page number and count.
|
|
38
|
+
*/
|
|
39
|
+
header?: string | HeaderFooterFn | undefined;
|
|
40
|
+
/** Footer template, see `header`. */
|
|
41
|
+
footer?: string | HeaderFooterFn | undefined;
|
|
42
|
+
styles?: string | string[] | undefined;
|
|
43
|
+
styleSheets?: string[] | undefined;
|
|
44
|
+
copyStyles?: boolean | undefined;
|
|
45
|
+
pageBreakBefore?: string | undefined;
|
|
46
|
+
pageBreakAfter?: string | undefined;
|
|
47
|
+
avoidBreakInside?: string | undefined;
|
|
48
|
+
removeAfterPrint?: boolean | undefined;
|
|
49
|
+
/** Print background colours and images (default true); false removes them from every element */
|
|
50
|
+
printBackground?: boolean | undefined;
|
|
51
|
+
onBeforePrint?: (() => void | Promise<void>) | undefined;
|
|
52
|
+
onAfterPrint?: (() => void) | undefined;
|
|
53
|
+
onError?: ((error: PrintError$1) => void) | undefined;
|
|
54
|
+
}
|
|
55
|
+
type PrintTarget = HTMLElement | string | HTMLElement[] | string[];
|
|
56
|
+
interface Printer {
|
|
57
|
+
print(target: PrintTarget, options?: PrintOptions): Promise<void>;
|
|
58
|
+
printHTML(html: string, options?: PrintOptions): Promise<void>;
|
|
59
|
+
printURL(url: string, options?: PrintOptions): Promise<void>;
|
|
60
|
+
printImage(src: string | HTMLImageElement, options?: PrintOptions | undefined): Promise<void>;
|
|
61
|
+
printImages(sources: (string | HTMLImageElement)[], options?: PrintOptions | undefined): Promise<void>;
|
|
62
|
+
printJSON(data: unknown, options?: PrintJSONOptions): Promise<void>;
|
|
63
|
+
printTable(data: TableData, options?: PrintTableOptions): Promise<void>;
|
|
64
|
+
setDefaultOptions(options: PrintOptions): void;
|
|
65
|
+
getDefaultOptions(): PrintOptions;
|
|
66
|
+
destroy(): void;
|
|
67
|
+
}
|
|
68
|
+
interface PreviewOptions extends PrintOptions {
|
|
69
|
+
modal?: ModalOptions | undefined;
|
|
70
|
+
toolbar?: ToolbarOptions | undefined;
|
|
71
|
+
onPrint?: (() => void) | undefined;
|
|
72
|
+
onDownload?: (() => void) | undefined;
|
|
73
|
+
onClose?: (() => void) | undefined;
|
|
74
|
+
}
|
|
75
|
+
interface ModalOptions {
|
|
76
|
+
width?: string | number | undefined;
|
|
77
|
+
height?: string | number | undefined;
|
|
78
|
+
showToolbar?: boolean | undefined;
|
|
79
|
+
showPageNumbers?: boolean | undefined;
|
|
80
|
+
zoom?: number | undefined;
|
|
81
|
+
className?: string | undefined;
|
|
82
|
+
}
|
|
83
|
+
interface ToolbarOptions {
|
|
84
|
+
print?: boolean | undefined;
|
|
85
|
+
download?: boolean | undefined;
|
|
86
|
+
zoom?: boolean | undefined;
|
|
87
|
+
navigation?: boolean | undefined;
|
|
88
|
+
close?: boolean | undefined;
|
|
89
|
+
}
|
|
90
|
+
interface PrintPreview {
|
|
91
|
+
open(): void;
|
|
92
|
+
close(): void;
|
|
93
|
+
print(): Promise<void>;
|
|
94
|
+
download(filename?: string): Promise<void>;
|
|
95
|
+
setZoom(level: number): void;
|
|
96
|
+
getZoom(): number;
|
|
97
|
+
zoomIn(): void;
|
|
98
|
+
zoomOut(): void;
|
|
99
|
+
resetZoom(): void;
|
|
100
|
+
nextPage(): void;
|
|
101
|
+
prevPage(): void;
|
|
102
|
+
goToPage(page: number): void;
|
|
103
|
+
getCurrentPage(): number;
|
|
104
|
+
getTotalPages(): number;
|
|
105
|
+
isOpen(): boolean;
|
|
106
|
+
destroy(): void;
|
|
107
|
+
}
|
|
108
|
+
interface PDFOptions extends PrintOptions {
|
|
109
|
+
quality?: number | undefined;
|
|
110
|
+
scale?: number | undefined;
|
|
111
|
+
metadata?: PDFMetadata | undefined;
|
|
112
|
+
onProgress?: ((progress: number) => void) | undefined;
|
|
113
|
+
}
|
|
114
|
+
interface PDFMetadata {
|
|
115
|
+
title?: string | undefined;
|
|
116
|
+
author?: string | undefined;
|
|
117
|
+
subject?: string | undefined;
|
|
118
|
+
keywords?: string[] | undefined;
|
|
119
|
+
creator?: string | undefined;
|
|
120
|
+
creationDate?: Date | undefined;
|
|
121
|
+
}
|
|
122
|
+
interface PDFExporter {
|
|
123
|
+
toBlob(target: PrintTarget, options?: PDFOptions): Promise<Blob>;
|
|
124
|
+
toBase64(target: PrintTarget, options?: PDFOptions): Promise<string>;
|
|
125
|
+
toDataURL(target: PrintTarget, options?: PDFOptions): Promise<string>;
|
|
126
|
+
download(target: PrintTarget, filename: string, options?: PDFOptions | undefined): Promise<void>;
|
|
127
|
+
downloadHTML(html: string, filename: string, options?: PDFOptions | undefined): Promise<void>;
|
|
128
|
+
}
|
|
129
|
+
type JobPriority = 'low' | 'normal' | 'high';
|
|
130
|
+
type JobStatus = 'pending' | 'printing' | 'completed' | 'failed';
|
|
131
|
+
interface PrintJob {
|
|
132
|
+
id: string;
|
|
133
|
+
content: PrintTarget;
|
|
134
|
+
options?: PrintOptions | undefined;
|
|
135
|
+
priority?: JobPriority | undefined;
|
|
136
|
+
/** Number of automatic retries after a failed attempt (default 0) */
|
|
137
|
+
retries?: number | undefined;
|
|
138
|
+
/** Number of attempts made so far */
|
|
139
|
+
attempts?: number | undefined;
|
|
140
|
+
status: JobStatus;
|
|
141
|
+
error?: Error | undefined;
|
|
142
|
+
createdAt: Date;
|
|
143
|
+
completedAt?: Date | undefined;
|
|
144
|
+
}
|
|
145
|
+
type NewPrintJob = Omit<PrintJob, 'id' | 'status' | 'createdAt' | 'attempts'>;
|
|
146
|
+
type QueueEvent = 'jobStart' | 'jobComplete' | 'jobError' | 'queueComplete' | 'queuePause' | 'queueResume';
|
|
147
|
+
type QueueEventHandler<E extends QueueEvent> = E extends 'jobError' ? (job: PrintJob, error: Error) => void : E extends 'jobStart' | 'jobComplete' ? (job: PrintJob) => void : () => void;
|
|
148
|
+
interface PrintQueue {
|
|
149
|
+
add(job: NewPrintJob): string;
|
|
150
|
+
remove(jobId: string): boolean;
|
|
151
|
+
/** Puts a failed job back in the queue; returns false if it is not a failed job */
|
|
152
|
+
retry(jobId: string): boolean;
|
|
153
|
+
clear(): void;
|
|
154
|
+
getJob(jobId: string): PrintJob | undefined;
|
|
155
|
+
getJobs(): PrintJob[];
|
|
156
|
+
getPendingJobs(): PrintJob[];
|
|
157
|
+
printNext(): Promise<void>;
|
|
158
|
+
printAll(): Promise<void>;
|
|
159
|
+
pause(): void;
|
|
160
|
+
resume(): void;
|
|
161
|
+
on<E extends QueueEvent>(event: E, handler: QueueEventHandler<E>): () => void;
|
|
162
|
+
off<E extends QueueEvent>(event: E, handler: QueueEventHandler<E>): void;
|
|
163
|
+
destroy(): void;
|
|
164
|
+
}
|
|
165
|
+
interface TableData {
|
|
166
|
+
headers: string[];
|
|
167
|
+
rows: (string | number)[][];
|
|
168
|
+
caption?: string | undefined;
|
|
169
|
+
}
|
|
170
|
+
interface PrintTableOptions extends PrintOptions {
|
|
171
|
+
tableStyles?: string | undefined;
|
|
172
|
+
headerStyles?: string | undefined;
|
|
173
|
+
cellStyles?: string | undefined;
|
|
174
|
+
stripedRows?: boolean | undefined;
|
|
175
|
+
bordered?: boolean | undefined;
|
|
176
|
+
}
|
|
177
|
+
interface PrintJSONOptions extends PrintOptions {
|
|
178
|
+
indent?: number | undefined;
|
|
179
|
+
syntaxHighlight?: boolean | undefined;
|
|
180
|
+
/**
|
|
181
|
+
* @deprecated Has no effect: printed output cannot be collapsed. Accepted
|
|
182
|
+
* for compatibility and will be removed in the next major version.
|
|
183
|
+
*/
|
|
184
|
+
collapsible?: boolean | undefined;
|
|
185
|
+
}
|
|
186
|
+
interface FormatOptions {
|
|
187
|
+
removeScripts?: boolean | undefined;
|
|
188
|
+
removeInputs?: boolean | undefined;
|
|
189
|
+
inlineStyles?: boolean | undefined;
|
|
190
|
+
removeHidden?: boolean | undefined;
|
|
191
|
+
}
|
|
192
|
+
interface PageOptions {
|
|
193
|
+
pageSize?: PageSize | undefined;
|
|
194
|
+
margin?: number | string | MarginOptions | undefined;
|
|
195
|
+
orientation?: Orientation | undefined;
|
|
196
|
+
}
|
|
197
|
+
type PrintErrorCode = 'PRINT_NOT_SUPPORTED' | 'ELEMENT_NOT_FOUND' | 'IFRAME_LOAD_FAILED' | 'PDF_EXPORT_FAILED' | 'STYLE_LOAD_FAILED' | 'CANCELLED' | 'UNKNOWN';
|
|
198
|
+
interface PrintError$1 extends Error {
|
|
199
|
+
code: PrintErrorCode;
|
|
200
|
+
target?: PrintTarget | undefined;
|
|
201
|
+
}
|
|
202
|
+
interface Dimensions {
|
|
203
|
+
width: string;
|
|
204
|
+
height: string;
|
|
205
|
+
}
|
|
206
|
+
interface PrintDocument {
|
|
207
|
+
content: string;
|
|
208
|
+
styles: string;
|
|
209
|
+
header?: string | undefined;
|
|
210
|
+
footer?: string | undefined;
|
|
211
|
+
pageSize: Dimensions;
|
|
212
|
+
margins: Required<MarginOptions>;
|
|
213
|
+
title: string;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* CSS class to hide elements when printing
|
|
218
|
+
*/
|
|
219
|
+
declare const PRINT_HIDE_CLASS = "print-hide";
|
|
220
|
+
/**
|
|
221
|
+
* CSS class to show elements only when printing
|
|
222
|
+
*/
|
|
223
|
+
declare const PRINT_ONLY_CLASS = "print-only";
|
|
224
|
+
/**
|
|
225
|
+
* Default print styles
|
|
226
|
+
*/
|
|
227
|
+
declare function getDefaultPrintStyles(): string;
|
|
228
|
+
/**
|
|
229
|
+
* Builds base document styles
|
|
230
|
+
*/
|
|
231
|
+
declare function getBaseDocumentStyles(): string;
|
|
232
|
+
/**
|
|
233
|
+
* Combines all default styles
|
|
234
|
+
*/
|
|
235
|
+
declare function getAllDefaultStyles(): string;
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* CSS class for page break before
|
|
239
|
+
*/
|
|
240
|
+
declare const BREAK_BEFORE_CLASS = "print-break-before";
|
|
241
|
+
/**
|
|
242
|
+
* CSS class for page break after
|
|
243
|
+
*/
|
|
244
|
+
declare const BREAK_AFTER_CLASS = "print-break-after";
|
|
245
|
+
/**
|
|
246
|
+
* CSS class to avoid break inside
|
|
247
|
+
*/
|
|
248
|
+
declare const AVOID_BREAK_CLASS = "print-avoid-break";
|
|
249
|
+
/**
|
|
250
|
+
* Creates a page break element
|
|
251
|
+
*/
|
|
252
|
+
declare function pageBreak(): HTMLDivElement;
|
|
253
|
+
/**
|
|
254
|
+
* Marks an element to avoid page breaks inside
|
|
255
|
+
*/
|
|
256
|
+
declare function avoidBreak(element: HTMLElement): void;
|
|
257
|
+
/**
|
|
258
|
+
* Marks an element to break before
|
|
259
|
+
*/
|
|
260
|
+
declare function breakBefore(element: HTMLElement): void;
|
|
261
|
+
/**
|
|
262
|
+
* Marks an element to break after
|
|
263
|
+
*/
|
|
264
|
+
declare function breakAfter(element: HTMLElement): void;
|
|
265
|
+
/**
|
|
266
|
+
* Calculates estimated page count based on content height
|
|
267
|
+
*/
|
|
268
|
+
declare function calculatePages(contentHeight: number, pageHeight: number, marginTop?: number, marginBottom?: number): number;
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* Custom error class for print operations
|
|
272
|
+
*/
|
|
273
|
+
declare class PrintError extends Error implements PrintError$1 {
|
|
274
|
+
readonly code: PrintErrorCode;
|
|
275
|
+
readonly target?: PrintTarget | undefined;
|
|
276
|
+
constructor(code: PrintErrorCode, message: string, target?: PrintTarget | undefined);
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Creates a PrintError with the appropriate message
|
|
280
|
+
*/
|
|
281
|
+
declare function createPrintError(code: PrintErrorCode, details?: string, target?: PrintTarget): PrintError;
|
|
282
|
+
/**
|
|
283
|
+
* Type guard to check if an error is a PrintError
|
|
284
|
+
*/
|
|
285
|
+
declare function isPrintError(error: unknown): error is PrintError;
|
|
286
|
+
/**
|
|
287
|
+
* Wraps an unknown error as a PrintError
|
|
288
|
+
*/
|
|
289
|
+
declare function wrapError(error: unknown, target?: PrintTarget): PrintError;
|
|
290
|
+
|
|
291
|
+
export { AVOID_BREAK_CLASS as A, BREAK_BEFORE_CLASS as B, type CustomSize as C, type Dimensions as D, type PDFMetadata as E, type PrintJob as F, type JobStatus as G, type HeaderFooterFn as H, type QueueEventHandler as I, type JobPriority as J, type TableData as K, type PrintTableOptions as L, type MarginOptions as M, type NewPrintJob as N, type Orientation as O, type PrintOptions as P, type QueueEvent as Q, type PrintJSONOptions as R, type FormatOptions as S, type ToolbarOptions as T, type PageOptions as U, type PrintErrorCode as V, type PrintError$1 as W, type PrintDocument as X, type Printer as a, type PrintTarget as b, type PreviewOptions as c, type PrintPreview as d, type PDFExporter as e, type PrintQueue as f, type PageSize as g, type PageSizeName as h, type PageInfo as i, getDefaultPrintStyles as j, getBaseDocumentStyles as k, getAllDefaultStyles as l, calculatePages as m, avoidBreak as n, breakBefore as o, pageBreak as p, breakAfter as q, PRINT_HIDE_CLASS as r, PRINT_ONLY_CLASS as s, BREAK_AFTER_CLASS as t, PrintError as u, createPrintError as v, isPrintError as w, wrapError as x, type ModalOptions as y, type PDFOptions as z };
|