@oxog/printkit 1.0.0 → 1.1.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/dist/index.d.cts CHANGED
@@ -1,192 +1,5 @@
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;
10
- right?: number | string;
11
- bottom?: number | string;
12
- left?: number | string;
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;
23
- pageSize?: PageSize;
24
- orientation?: Orientation;
25
- margin?: number | MarginOptions;
26
- header?: string | HeaderFooterFn;
27
- footer?: string | HeaderFooterFn;
28
- styles?: string | string[];
29
- styleSheets?: string[];
30
- copyStyles?: boolean;
31
- pageBreakBefore?: string;
32
- pageBreakAfter?: string;
33
- avoidBreakInside?: string;
34
- removeAfterPrint?: boolean;
35
- printBackground?: boolean;
36
- onBeforePrint?: () => void | Promise<void>;
37
- onAfterPrint?: () => void;
38
- onError?: (error: PrintError$1) => void;
39
- }
40
- type PrintTarget = HTMLElement | string | HTMLElement[] | string[];
41
- interface Printer {
42
- print(target: PrintTarget, options?: PrintOptions): Promise<void>;
43
- printHTML(html: string, options?: PrintOptions): Promise<void>;
44
- printURL(url: string, options?: PrintOptions): Promise<void>;
45
- printImage(src: string | HTMLImageElement, options?: PrintOptions): Promise<void>;
46
- printImages(sources: (string | HTMLImageElement)[], options?: PrintOptions): Promise<void>;
47
- printJSON(data: unknown, options?: PrintJSONOptions): Promise<void>;
48
- printTable(data: TableData, options?: PrintTableOptions): Promise<void>;
49
- setDefaultOptions(options: PrintOptions): void;
50
- getDefaultOptions(): PrintOptions;
51
- destroy(): void;
52
- }
53
- interface PreviewOptions extends PrintOptions {
54
- modal?: ModalOptions;
55
- toolbar?: ToolbarOptions;
56
- onPrint?: () => void;
57
- onDownload?: () => void;
58
- onClose?: () => void;
59
- }
60
- interface ModalOptions {
61
- width?: string | number;
62
- height?: string | number;
63
- showToolbar?: boolean;
64
- showPageNumbers?: boolean;
65
- zoom?: number;
66
- className?: string;
67
- }
68
- interface ToolbarOptions {
69
- print?: boolean;
70
- download?: boolean;
71
- zoom?: boolean;
72
- navigation?: boolean;
73
- close?: boolean;
74
- }
75
- interface PrintPreview {
76
- open(): void;
77
- close(): void;
78
- print(): Promise<void>;
79
- download(filename?: string): Promise<void>;
80
- setZoom(level: number): void;
81
- getZoom(): number;
82
- zoomIn(): void;
83
- zoomOut(): void;
84
- resetZoom(): void;
85
- nextPage(): void;
86
- prevPage(): void;
87
- goToPage(page: number): void;
88
- getCurrentPage(): number;
89
- getTotalPages(): number;
90
- isOpen(): boolean;
91
- destroy(): void;
92
- }
93
- interface PDFOptions extends PrintOptions {
94
- quality?: number;
95
- scale?: number;
96
- metadata?: PDFMetadata;
97
- onProgress?: (progress: number) => void;
98
- }
99
- interface PDFMetadata {
100
- title?: string;
101
- author?: string;
102
- subject?: string;
103
- keywords?: string[];
104
- creator?: string;
105
- creationDate?: Date;
106
- }
107
- interface PDFExporter {
108
- toBlob(target: PrintTarget, options?: PDFOptions): Promise<Blob>;
109
- toBase64(target: PrintTarget, options?: PDFOptions): Promise<string>;
110
- toDataURL(target: PrintTarget, options?: PDFOptions): Promise<string>;
111
- download(target: PrintTarget, filename: string, options?: PDFOptions): Promise<void>;
112
- downloadHTML(html: string, filename: string, options?: PDFOptions): Promise<void>;
113
- }
114
- type JobPriority = 'low' | 'normal' | 'high';
115
- type JobStatus = 'pending' | 'printing' | 'completed' | 'failed';
116
- interface PrintJob {
117
- id: string;
118
- content: PrintTarget;
119
- options?: PrintOptions;
120
- priority?: JobPriority;
121
- status: JobStatus;
122
- error?: Error;
123
- createdAt: Date;
124
- completedAt?: Date;
125
- }
126
- type NewPrintJob = Omit<PrintJob, 'id' | 'status' | 'createdAt'>;
127
- type QueueEvent = 'jobStart' | 'jobComplete' | 'jobError' | 'queueComplete' | 'queuePause' | 'queueResume';
128
- type QueueEventHandler<E extends QueueEvent> = E extends 'jobError' ? (job: PrintJob, error: Error) => void : E extends 'jobStart' | 'jobComplete' ? (job: PrintJob) => void : () => void;
129
- interface PrintQueue {
130
- add(job: NewPrintJob): string;
131
- remove(jobId: string): boolean;
132
- clear(): void;
133
- getJob(jobId: string): PrintJob | undefined;
134
- getJobs(): PrintJob[];
135
- getPendingJobs(): PrintJob[];
136
- printNext(): Promise<void>;
137
- printAll(): Promise<void>;
138
- pause(): void;
139
- resume(): void;
140
- on<E extends QueueEvent>(event: E, handler: QueueEventHandler<E>): () => void;
141
- off<E extends QueueEvent>(event: E, handler: QueueEventHandler<E>): void;
142
- destroy(): void;
143
- }
144
- interface TableData {
145
- headers: string[];
146
- rows: (string | number)[][];
147
- caption?: string;
148
- }
149
- interface PrintTableOptions extends PrintOptions {
150
- tableStyles?: string;
151
- headerStyles?: string;
152
- cellStyles?: string;
153
- stripedRows?: boolean;
154
- bordered?: boolean;
155
- }
156
- interface PrintJSONOptions extends PrintOptions {
157
- indent?: number;
158
- syntaxHighlight?: boolean;
159
- collapsible?: boolean;
160
- }
161
- interface FormatOptions {
162
- removeScripts?: boolean;
163
- removeInputs?: boolean;
164
- inlineStyles?: boolean;
165
- removeHidden?: boolean;
166
- }
167
- interface PageOptions {
168
- pageSize?: PageSize;
169
- margin?: number | MarginOptions;
170
- orientation?: Orientation;
171
- }
172
- type PrintErrorCode = 'PRINT_NOT_SUPPORTED' | 'ELEMENT_NOT_FOUND' | 'IFRAME_LOAD_FAILED' | 'PDF_EXPORT_FAILED' | 'STYLE_LOAD_FAILED' | 'CANCELLED' | 'UNKNOWN';
173
- interface PrintError$1 extends Error {
174
- code: PrintErrorCode;
175
- target?: PrintTarget | undefined;
176
- }
177
- interface Dimensions {
178
- width: string;
179
- height: string;
180
- }
181
- interface PrintDocument {
182
- content: string;
183
- styles: string;
184
- header?: string;
185
- footer?: string;
186
- pageSize: Dimensions;
187
- margins: Required<MarginOptions>;
188
- title: string;
189
- }
1
+ import { P as PrintOptions, a as Printer, b as PrintTarget, c as PreviewOptions, d as PrintPreview, e as PDFExporter, f as PrintQueue, g as PageSize, O as Orientation, D as Dimensions, h as PageSizeName, M as MarginOptions, H as HeaderFooterFn, i as PageInfo } from './errors-B6q-4bX_.cjs';
2
+ export { A as AVOID_BREAK_CLASS, t as BREAK_AFTER_CLASS, B as BREAK_BEFORE_CLASS, C as CustomSize, S as FormatOptions, J as JobPriority, G as JobStatus, y as ModalOptions, N as NewPrintJob, E as PDFMetadata, z as PDFOptions, r as PRINT_HIDE_CLASS, s as PRINT_ONLY_CLASS, U as PageOptions, X as PrintDocument, u as PrintError, V as PrintErrorCode, W as PrintErrorType, R as PrintJSONOptions, F as PrintJob, L as PrintTableOptions, Q as QueueEvent, I as QueueEventHandler, K as TableData, T as ToolbarOptions, n as avoidBreak, q as breakAfter, o as breakBefore, m as calculatePages, v as createPrintError, l as getAllDefaultStyles, k as getBaseDocumentStyles, j as getDefaultPrintStyles, w as isPrintError, p as pageBreak, x as wrapError } from './errors-B6q-4bX_.cjs';
190
3
 
191
4
  /**
192
5
  * Creates a new Printer instance
@@ -225,6 +38,20 @@ declare function isPDFSupported(): boolean;
225
38
  */
226
39
  declare function isBrowser(): boolean;
227
40
 
41
+ /**
42
+ * Sanitizes untrusted HTML so it can be written into a print document.
43
+ *
44
+ * The markup is parsed into an inert document and every element or attribute
45
+ * that can execute script is removed: `<script>`, `<iframe>`, `<object>`,
46
+ * `<embed>`, `<base>`, `<meta>`, `on*` event-handler attributes, and
47
+ * `javascript:`/`vbscript:`/non-image `data:` URLs. Text content is never
48
+ * modified.
49
+ *
50
+ * Without a DOM (e.g. during server-side rendering) the whole string is
51
+ * HTML-escaped, so the result is always safe to insert.
52
+ */
53
+ declare function sanitizeHTML(html: string): string;
54
+
228
55
  /**
229
56
  * Resolves a single element from a target (selector string or HTMLElement)
230
57
  */
@@ -238,13 +65,14 @@ declare function resolveElements(target: PrintTarget): HTMLElement[];
238
65
  */
239
66
  declare function cloneElement(element: HTMLElement): HTMLElement;
240
67
  /**
241
- * Waits for all images in an element to load
68
+ * Waits for the images in an element to finish loading (or fail).
69
+ *
70
+ * Images with `loading="lazy"` that have not started loading are not waited
71
+ * for (they may never load while off-screen); the print copy loads them
72
+ * eagerly instead. The wait never exceeds `timeout` milliseconds.
73
+ * Existing `onload`/`onerror` handlers on the page's images are left intact.
242
74
  */
243
- declare function waitForImages(element: HTMLElement): Promise<void>;
244
- /**
245
- * Sanitizes HTML to prevent XSS
246
- */
247
- declare function sanitizeHTML(html: string): string;
75
+ declare function waitForImages(element: HTMLElement, timeout?: number): Promise<void>;
248
76
 
249
77
  /**
250
78
  * Injects print styles into the document head
@@ -277,27 +105,6 @@ declare function copyPageStyles(): string[];
277
105
  */
278
106
  declare function getComputedStylesCSS(element: HTMLElement): string;
279
107
 
280
- /**
281
- * CSS class to hide elements when printing
282
- */
283
- declare const PRINT_HIDE_CLASS = "print-hide";
284
- /**
285
- * CSS class to show elements only when printing
286
- */
287
- declare const PRINT_ONLY_CLASS = "print-only";
288
- /**
289
- * Default print styles
290
- */
291
- declare function getDefaultPrintStyles(): string;
292
- /**
293
- * Builds base document styles
294
- */
295
- declare function getBaseDocumentStyles(): string;
296
- /**
297
- * Combines all default styles
298
- */
299
- declare function getAllDefaultStyles(): string;
300
-
301
108
  /**
302
109
  * Standard page sizes in millimeters
303
110
  */
@@ -327,11 +134,11 @@ interface NormalizedMargins {
327
134
  /**
328
135
  * Normalizes margin options to a complete MarginOptions object
329
136
  */
330
- declare function normalizeMargins(margin?: number | MarginOptions): NormalizedMargins;
137
+ declare function normalizeMargins(margin?: number | string | MarginOptions): NormalizedMargins;
331
138
  /**
332
139
  * Gets margin values as pixels (for preview)
333
140
  */
334
- declare function getMarginsInPixels(margin?: number | MarginOptions, dpi?: number): {
141
+ declare function getMarginsInPixels(margin?: number | string | MarginOptions, dpi?: number): {
335
142
  top: number;
336
143
  right: number;
337
144
  bottom: number;
@@ -351,58 +158,4 @@ declare function replacePlaceholders(template: string, info: PageInfo): string;
351
158
  */
352
159
  declare function renderHeaderFooter(template: string | HeaderFooterFn | undefined, info: PageInfo): string;
353
160
 
354
- /**
355
- * CSS class for page break before
356
- */
357
- declare const BREAK_BEFORE_CLASS = "print-break-before";
358
- /**
359
- * CSS class for page break after
360
- */
361
- declare const BREAK_AFTER_CLASS = "print-break-after";
362
- /**
363
- * CSS class to avoid break inside
364
- */
365
- declare const AVOID_BREAK_CLASS = "print-avoid-break";
366
- /**
367
- * Creates a page break element
368
- */
369
- declare function pageBreak(): HTMLDivElement;
370
- /**
371
- * Marks an element to avoid page breaks inside
372
- */
373
- declare function avoidBreak(element: HTMLElement): void;
374
- /**
375
- * Marks an element to break before
376
- */
377
- declare function breakBefore(element: HTMLElement): void;
378
- /**
379
- * Marks an element to break after
380
- */
381
- declare function breakAfter(element: HTMLElement): void;
382
- /**
383
- * Calculates estimated page count based on content height
384
- */
385
- declare function calculatePages(contentHeight: number, pageHeight: number, marginTop?: number, marginBottom?: number): number;
386
-
387
- /**
388
- * Custom error class for print operations
389
- */
390
- declare class PrintError extends Error implements PrintError$1 {
391
- readonly code: PrintErrorCode;
392
- readonly target: PrintTarget | undefined;
393
- constructor(code: PrintErrorCode, message: string, target?: PrintTarget | undefined);
394
- }
395
- /**
396
- * Creates a PrintError with the appropriate message
397
- */
398
- declare function createPrintError(code: PrintErrorCode, details?: string, target?: PrintTarget): PrintError;
399
- /**
400
- * Type guard to check if an error is a PrintError
401
- */
402
- declare function isPrintError(error: unknown): error is PrintError;
403
- /**
404
- * Wraps an unknown error as a PrintError
405
- */
406
- declare function wrapError(error: unknown, target?: PrintTarget): PrintError;
407
-
408
- export { AVOID_BREAK_CLASS, BREAK_AFTER_CLASS, BREAK_BEFORE_CLASS, type CustomSize, type Dimensions, type FormatOptions, type HeaderFooterFn, type JobPriority, type JobStatus, type MarginOptions, type ModalOptions, type NewPrintJob, type Orientation, PAGE_SIZES, type PDFExporter, type PDFMetadata, type PDFOptions, PRINT_HIDE_CLASS, PRINT_ONLY_CLASS, type PageInfo, type PageOptions, type PageSize, type PageSizeName, type PreviewOptions, type PrintDocument, PrintError, type PrintErrorCode, type PrintError$1 as PrintErrorType, type PrintJSONOptions, type PrintJob, type PrintOptions, type PrintPreview, type PrintQueue, type PrintTableOptions, type PrintTarget, type Printer, type QueueEvent, type QueueEventHandler, type TableData, type ToolbarOptions, avoidBreak, breakAfter, breakBefore, buildStyleTag, calculatePages, cloneElement, combineStyles, copyPageStyles, createPDFExporter, createPageInfo, createPrintError, createPrintPreview, createPrintQueue, createPrinter, getAllDefaultStyles, getBaseDocumentStyles, getComputedStylesCSS, getDefaultPrintStyles, getDefaultPrinter, getMarginsInPixels, getPageDimensions, getPagePixelDimensions, injectPrintStyles, isBrowser, isPDFSupported, isPrintError, isPrintSupported, normalizeMargins, pageBreak, removeAllPrintStyles, removePrintStyles, renderHeaderFooter, replacePlaceholders, resolveElement, resolveElements, sanitizeHTML, waitForImages, wrapError };
161
+ export { Dimensions, HeaderFooterFn, MarginOptions, Orientation, PAGE_SIZES, PDFExporter, PageInfo, PageSize, PageSizeName, PreviewOptions, PrintOptions, PrintPreview, PrintQueue, PrintTarget, Printer, buildStyleTag, cloneElement, combineStyles, copyPageStyles, createPDFExporter, createPageInfo, createPrintPreview, createPrintQueue, createPrinter, getComputedStylesCSS, getDefaultPrinter, getMarginsInPixels, getPageDimensions, getPagePixelDimensions, injectPrintStyles, isBrowser, isPDFSupported, isPrintSupported, normalizeMargins, removeAllPrintStyles, removePrintStyles, renderHeaderFooter, replacePlaceholders, resolveElement, resolveElements, sanitizeHTML, waitForImages };
package/dist/index.d.ts CHANGED
@@ -1,192 +1,5 @@
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;
10
- right?: number | string;
11
- bottom?: number | string;
12
- left?: number | string;
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;
23
- pageSize?: PageSize;
24
- orientation?: Orientation;
25
- margin?: number | MarginOptions;
26
- header?: string | HeaderFooterFn;
27
- footer?: string | HeaderFooterFn;
28
- styles?: string | string[];
29
- styleSheets?: string[];
30
- copyStyles?: boolean;
31
- pageBreakBefore?: string;
32
- pageBreakAfter?: string;
33
- avoidBreakInside?: string;
34
- removeAfterPrint?: boolean;
35
- printBackground?: boolean;
36
- onBeforePrint?: () => void | Promise<void>;
37
- onAfterPrint?: () => void;
38
- onError?: (error: PrintError$1) => void;
39
- }
40
- type PrintTarget = HTMLElement | string | HTMLElement[] | string[];
41
- interface Printer {
42
- print(target: PrintTarget, options?: PrintOptions): Promise<void>;
43
- printHTML(html: string, options?: PrintOptions): Promise<void>;
44
- printURL(url: string, options?: PrintOptions): Promise<void>;
45
- printImage(src: string | HTMLImageElement, options?: PrintOptions): Promise<void>;
46
- printImages(sources: (string | HTMLImageElement)[], options?: PrintOptions): Promise<void>;
47
- printJSON(data: unknown, options?: PrintJSONOptions): Promise<void>;
48
- printTable(data: TableData, options?: PrintTableOptions): Promise<void>;
49
- setDefaultOptions(options: PrintOptions): void;
50
- getDefaultOptions(): PrintOptions;
51
- destroy(): void;
52
- }
53
- interface PreviewOptions extends PrintOptions {
54
- modal?: ModalOptions;
55
- toolbar?: ToolbarOptions;
56
- onPrint?: () => void;
57
- onDownload?: () => void;
58
- onClose?: () => void;
59
- }
60
- interface ModalOptions {
61
- width?: string | number;
62
- height?: string | number;
63
- showToolbar?: boolean;
64
- showPageNumbers?: boolean;
65
- zoom?: number;
66
- className?: string;
67
- }
68
- interface ToolbarOptions {
69
- print?: boolean;
70
- download?: boolean;
71
- zoom?: boolean;
72
- navigation?: boolean;
73
- close?: boolean;
74
- }
75
- interface PrintPreview {
76
- open(): void;
77
- close(): void;
78
- print(): Promise<void>;
79
- download(filename?: string): Promise<void>;
80
- setZoom(level: number): void;
81
- getZoom(): number;
82
- zoomIn(): void;
83
- zoomOut(): void;
84
- resetZoom(): void;
85
- nextPage(): void;
86
- prevPage(): void;
87
- goToPage(page: number): void;
88
- getCurrentPage(): number;
89
- getTotalPages(): number;
90
- isOpen(): boolean;
91
- destroy(): void;
92
- }
93
- interface PDFOptions extends PrintOptions {
94
- quality?: number;
95
- scale?: number;
96
- metadata?: PDFMetadata;
97
- onProgress?: (progress: number) => void;
98
- }
99
- interface PDFMetadata {
100
- title?: string;
101
- author?: string;
102
- subject?: string;
103
- keywords?: string[];
104
- creator?: string;
105
- creationDate?: Date;
106
- }
107
- interface PDFExporter {
108
- toBlob(target: PrintTarget, options?: PDFOptions): Promise<Blob>;
109
- toBase64(target: PrintTarget, options?: PDFOptions): Promise<string>;
110
- toDataURL(target: PrintTarget, options?: PDFOptions): Promise<string>;
111
- download(target: PrintTarget, filename: string, options?: PDFOptions): Promise<void>;
112
- downloadHTML(html: string, filename: string, options?: PDFOptions): Promise<void>;
113
- }
114
- type JobPriority = 'low' | 'normal' | 'high';
115
- type JobStatus = 'pending' | 'printing' | 'completed' | 'failed';
116
- interface PrintJob {
117
- id: string;
118
- content: PrintTarget;
119
- options?: PrintOptions;
120
- priority?: JobPriority;
121
- status: JobStatus;
122
- error?: Error;
123
- createdAt: Date;
124
- completedAt?: Date;
125
- }
126
- type NewPrintJob = Omit<PrintJob, 'id' | 'status' | 'createdAt'>;
127
- type QueueEvent = 'jobStart' | 'jobComplete' | 'jobError' | 'queueComplete' | 'queuePause' | 'queueResume';
128
- type QueueEventHandler<E extends QueueEvent> = E extends 'jobError' ? (job: PrintJob, error: Error) => void : E extends 'jobStart' | 'jobComplete' ? (job: PrintJob) => void : () => void;
129
- interface PrintQueue {
130
- add(job: NewPrintJob): string;
131
- remove(jobId: string): boolean;
132
- clear(): void;
133
- getJob(jobId: string): PrintJob | undefined;
134
- getJobs(): PrintJob[];
135
- getPendingJobs(): PrintJob[];
136
- printNext(): Promise<void>;
137
- printAll(): Promise<void>;
138
- pause(): void;
139
- resume(): void;
140
- on<E extends QueueEvent>(event: E, handler: QueueEventHandler<E>): () => void;
141
- off<E extends QueueEvent>(event: E, handler: QueueEventHandler<E>): void;
142
- destroy(): void;
143
- }
144
- interface TableData {
145
- headers: string[];
146
- rows: (string | number)[][];
147
- caption?: string;
148
- }
149
- interface PrintTableOptions extends PrintOptions {
150
- tableStyles?: string;
151
- headerStyles?: string;
152
- cellStyles?: string;
153
- stripedRows?: boolean;
154
- bordered?: boolean;
155
- }
156
- interface PrintJSONOptions extends PrintOptions {
157
- indent?: number;
158
- syntaxHighlight?: boolean;
159
- collapsible?: boolean;
160
- }
161
- interface FormatOptions {
162
- removeScripts?: boolean;
163
- removeInputs?: boolean;
164
- inlineStyles?: boolean;
165
- removeHidden?: boolean;
166
- }
167
- interface PageOptions {
168
- pageSize?: PageSize;
169
- margin?: number | MarginOptions;
170
- orientation?: Orientation;
171
- }
172
- type PrintErrorCode = 'PRINT_NOT_SUPPORTED' | 'ELEMENT_NOT_FOUND' | 'IFRAME_LOAD_FAILED' | 'PDF_EXPORT_FAILED' | 'STYLE_LOAD_FAILED' | 'CANCELLED' | 'UNKNOWN';
173
- interface PrintError$1 extends Error {
174
- code: PrintErrorCode;
175
- target?: PrintTarget | undefined;
176
- }
177
- interface Dimensions {
178
- width: string;
179
- height: string;
180
- }
181
- interface PrintDocument {
182
- content: string;
183
- styles: string;
184
- header?: string;
185
- footer?: string;
186
- pageSize: Dimensions;
187
- margins: Required<MarginOptions>;
188
- title: string;
189
- }
1
+ import { P as PrintOptions, a as Printer, b as PrintTarget, c as PreviewOptions, d as PrintPreview, e as PDFExporter, f as PrintQueue, g as PageSize, O as Orientation, D as Dimensions, h as PageSizeName, M as MarginOptions, H as HeaderFooterFn, i as PageInfo } from './errors-B6q-4bX_.js';
2
+ export { A as AVOID_BREAK_CLASS, t as BREAK_AFTER_CLASS, B as BREAK_BEFORE_CLASS, C as CustomSize, S as FormatOptions, J as JobPriority, G as JobStatus, y as ModalOptions, N as NewPrintJob, E as PDFMetadata, z as PDFOptions, r as PRINT_HIDE_CLASS, s as PRINT_ONLY_CLASS, U as PageOptions, X as PrintDocument, u as PrintError, V as PrintErrorCode, W as PrintErrorType, R as PrintJSONOptions, F as PrintJob, L as PrintTableOptions, Q as QueueEvent, I as QueueEventHandler, K as TableData, T as ToolbarOptions, n as avoidBreak, q as breakAfter, o as breakBefore, m as calculatePages, v as createPrintError, l as getAllDefaultStyles, k as getBaseDocumentStyles, j as getDefaultPrintStyles, w as isPrintError, p as pageBreak, x as wrapError } from './errors-B6q-4bX_.js';
190
3
 
191
4
  /**
192
5
  * Creates a new Printer instance
@@ -225,6 +38,20 @@ declare function isPDFSupported(): boolean;
225
38
  */
226
39
  declare function isBrowser(): boolean;
227
40
 
41
+ /**
42
+ * Sanitizes untrusted HTML so it can be written into a print document.
43
+ *
44
+ * The markup is parsed into an inert document and every element or attribute
45
+ * that can execute script is removed: `<script>`, `<iframe>`, `<object>`,
46
+ * `<embed>`, `<base>`, `<meta>`, `on*` event-handler attributes, and
47
+ * `javascript:`/`vbscript:`/non-image `data:` URLs. Text content is never
48
+ * modified.
49
+ *
50
+ * Without a DOM (e.g. during server-side rendering) the whole string is
51
+ * HTML-escaped, so the result is always safe to insert.
52
+ */
53
+ declare function sanitizeHTML(html: string): string;
54
+
228
55
  /**
229
56
  * Resolves a single element from a target (selector string or HTMLElement)
230
57
  */
@@ -238,13 +65,14 @@ declare function resolveElements(target: PrintTarget): HTMLElement[];
238
65
  */
239
66
  declare function cloneElement(element: HTMLElement): HTMLElement;
240
67
  /**
241
- * Waits for all images in an element to load
68
+ * Waits for the images in an element to finish loading (or fail).
69
+ *
70
+ * Images with `loading="lazy"` that have not started loading are not waited
71
+ * for (they may never load while off-screen); the print copy loads them
72
+ * eagerly instead. The wait never exceeds `timeout` milliseconds.
73
+ * Existing `onload`/`onerror` handlers on the page's images are left intact.
242
74
  */
243
- declare function waitForImages(element: HTMLElement): Promise<void>;
244
- /**
245
- * Sanitizes HTML to prevent XSS
246
- */
247
- declare function sanitizeHTML(html: string): string;
75
+ declare function waitForImages(element: HTMLElement, timeout?: number): Promise<void>;
248
76
 
249
77
  /**
250
78
  * Injects print styles into the document head
@@ -277,27 +105,6 @@ declare function copyPageStyles(): string[];
277
105
  */
278
106
  declare function getComputedStylesCSS(element: HTMLElement): string;
279
107
 
280
- /**
281
- * CSS class to hide elements when printing
282
- */
283
- declare const PRINT_HIDE_CLASS = "print-hide";
284
- /**
285
- * CSS class to show elements only when printing
286
- */
287
- declare const PRINT_ONLY_CLASS = "print-only";
288
- /**
289
- * Default print styles
290
- */
291
- declare function getDefaultPrintStyles(): string;
292
- /**
293
- * Builds base document styles
294
- */
295
- declare function getBaseDocumentStyles(): string;
296
- /**
297
- * Combines all default styles
298
- */
299
- declare function getAllDefaultStyles(): string;
300
-
301
108
  /**
302
109
  * Standard page sizes in millimeters
303
110
  */
@@ -327,11 +134,11 @@ interface NormalizedMargins {
327
134
  /**
328
135
  * Normalizes margin options to a complete MarginOptions object
329
136
  */
330
- declare function normalizeMargins(margin?: number | MarginOptions): NormalizedMargins;
137
+ declare function normalizeMargins(margin?: number | string | MarginOptions): NormalizedMargins;
331
138
  /**
332
139
  * Gets margin values as pixels (for preview)
333
140
  */
334
- declare function getMarginsInPixels(margin?: number | MarginOptions, dpi?: number): {
141
+ declare function getMarginsInPixels(margin?: number | string | MarginOptions, dpi?: number): {
335
142
  top: number;
336
143
  right: number;
337
144
  bottom: number;
@@ -351,58 +158,4 @@ declare function replacePlaceholders(template: string, info: PageInfo): string;
351
158
  */
352
159
  declare function renderHeaderFooter(template: string | HeaderFooterFn | undefined, info: PageInfo): string;
353
160
 
354
- /**
355
- * CSS class for page break before
356
- */
357
- declare const BREAK_BEFORE_CLASS = "print-break-before";
358
- /**
359
- * CSS class for page break after
360
- */
361
- declare const BREAK_AFTER_CLASS = "print-break-after";
362
- /**
363
- * CSS class to avoid break inside
364
- */
365
- declare const AVOID_BREAK_CLASS = "print-avoid-break";
366
- /**
367
- * Creates a page break element
368
- */
369
- declare function pageBreak(): HTMLDivElement;
370
- /**
371
- * Marks an element to avoid page breaks inside
372
- */
373
- declare function avoidBreak(element: HTMLElement): void;
374
- /**
375
- * Marks an element to break before
376
- */
377
- declare function breakBefore(element: HTMLElement): void;
378
- /**
379
- * Marks an element to break after
380
- */
381
- declare function breakAfter(element: HTMLElement): void;
382
- /**
383
- * Calculates estimated page count based on content height
384
- */
385
- declare function calculatePages(contentHeight: number, pageHeight: number, marginTop?: number, marginBottom?: number): number;
386
-
387
- /**
388
- * Custom error class for print operations
389
- */
390
- declare class PrintError extends Error implements PrintError$1 {
391
- readonly code: PrintErrorCode;
392
- readonly target: PrintTarget | undefined;
393
- constructor(code: PrintErrorCode, message: string, target?: PrintTarget | undefined);
394
- }
395
- /**
396
- * Creates a PrintError with the appropriate message
397
- */
398
- declare function createPrintError(code: PrintErrorCode, details?: string, target?: PrintTarget): PrintError;
399
- /**
400
- * Type guard to check if an error is a PrintError
401
- */
402
- declare function isPrintError(error: unknown): error is PrintError;
403
- /**
404
- * Wraps an unknown error as a PrintError
405
- */
406
- declare function wrapError(error: unknown, target?: PrintTarget): PrintError;
407
-
408
- export { AVOID_BREAK_CLASS, BREAK_AFTER_CLASS, BREAK_BEFORE_CLASS, type CustomSize, type Dimensions, type FormatOptions, type HeaderFooterFn, type JobPriority, type JobStatus, type MarginOptions, type ModalOptions, type NewPrintJob, type Orientation, PAGE_SIZES, type PDFExporter, type PDFMetadata, type PDFOptions, PRINT_HIDE_CLASS, PRINT_ONLY_CLASS, type PageInfo, type PageOptions, type PageSize, type PageSizeName, type PreviewOptions, type PrintDocument, PrintError, type PrintErrorCode, type PrintError$1 as PrintErrorType, type PrintJSONOptions, type PrintJob, type PrintOptions, type PrintPreview, type PrintQueue, type PrintTableOptions, type PrintTarget, type Printer, type QueueEvent, type QueueEventHandler, type TableData, type ToolbarOptions, avoidBreak, breakAfter, breakBefore, buildStyleTag, calculatePages, cloneElement, combineStyles, copyPageStyles, createPDFExporter, createPageInfo, createPrintError, createPrintPreview, createPrintQueue, createPrinter, getAllDefaultStyles, getBaseDocumentStyles, getComputedStylesCSS, getDefaultPrintStyles, getDefaultPrinter, getMarginsInPixels, getPageDimensions, getPagePixelDimensions, injectPrintStyles, isBrowser, isPDFSupported, isPrintError, isPrintSupported, normalizeMargins, pageBreak, removeAllPrintStyles, removePrintStyles, renderHeaderFooter, replacePlaceholders, resolveElement, resolveElements, sanitizeHTML, waitForImages, wrapError };
161
+ export { Dimensions, HeaderFooterFn, MarginOptions, Orientation, PAGE_SIZES, PDFExporter, PageInfo, PageSize, PageSizeName, PreviewOptions, PrintOptions, PrintPreview, PrintQueue, PrintTarget, Printer, buildStyleTag, cloneElement, combineStyles, copyPageStyles, createPDFExporter, createPageInfo, createPrintPreview, createPrintQueue, createPrinter, getComputedStylesCSS, getDefaultPrinter, getMarginsInPixels, getPageDimensions, getPagePixelDimensions, injectPrintStyles, isBrowser, isPDFSupported, isPrintSupported, normalizeMargins, removeAllPrintStyles, removePrintStyles, renderHeaderFooter, replacePlaceholders, resolveElement, resolveElements, sanitizeHTML, waitForImages };