@oxog/printkit 1.0.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.
@@ -0,0 +1,495 @@
1
+ import * as React from 'react';
2
+ import React__default, { ReactNode, RefObject, CSSProperties, ButtonHTMLAttributes } from 'react';
3
+
4
+ type PageSizeName = 'A3' | 'A4' | 'A5' | 'Letter' | 'Legal' | 'Tabloid';
5
+ interface CustomSize {
6
+ width: number | string;
7
+ height: number | string;
8
+ }
9
+ type PageSize = PageSizeName | CustomSize;
10
+ type Orientation = 'portrait' | 'landscape';
11
+ interface MarginOptions {
12
+ top?: number | string;
13
+ right?: number | string;
14
+ bottom?: number | string;
15
+ left?: number | string;
16
+ }
17
+ interface PageInfo {
18
+ pageNumber: number;
19
+ totalPages: number;
20
+ title: string;
21
+ date: Date;
22
+ }
23
+ type HeaderFooterFn = (info: PageInfo) => string;
24
+ interface PrintOptions {
25
+ title?: string;
26
+ pageSize?: PageSize;
27
+ orientation?: Orientation;
28
+ margin?: number | MarginOptions;
29
+ header?: string | HeaderFooterFn;
30
+ footer?: string | HeaderFooterFn;
31
+ styles?: string | string[];
32
+ styleSheets?: string[];
33
+ copyStyles?: boolean;
34
+ pageBreakBefore?: string;
35
+ pageBreakAfter?: string;
36
+ avoidBreakInside?: string;
37
+ removeAfterPrint?: boolean;
38
+ printBackground?: boolean;
39
+ onBeforePrint?: () => void | Promise<void>;
40
+ onAfterPrint?: () => void;
41
+ onError?: (error: PrintError$1) => void;
42
+ }
43
+ type PrintTarget = HTMLElement | string | HTMLElement[] | string[];
44
+ interface PreviewOptions extends PrintOptions {
45
+ modal?: ModalOptions;
46
+ toolbar?: ToolbarOptions;
47
+ onPrint?: () => void;
48
+ onDownload?: () => void;
49
+ onClose?: () => void;
50
+ }
51
+ interface ModalOptions {
52
+ width?: string | number;
53
+ height?: string | number;
54
+ showToolbar?: boolean;
55
+ showPageNumbers?: boolean;
56
+ zoom?: number;
57
+ className?: string;
58
+ }
59
+ interface ToolbarOptions {
60
+ print?: boolean;
61
+ download?: boolean;
62
+ zoom?: boolean;
63
+ navigation?: boolean;
64
+ close?: boolean;
65
+ }
66
+ interface PDFOptions extends PrintOptions {
67
+ quality?: number;
68
+ scale?: number;
69
+ metadata?: PDFMetadata;
70
+ onProgress?: (progress: number) => void;
71
+ }
72
+ interface PDFMetadata {
73
+ title?: string;
74
+ author?: string;
75
+ subject?: string;
76
+ keywords?: string[];
77
+ creator?: string;
78
+ creationDate?: Date;
79
+ }
80
+ interface TableData {
81
+ headers: string[];
82
+ rows: (string | number)[][];
83
+ caption?: string;
84
+ }
85
+ type PrintErrorCode = 'PRINT_NOT_SUPPORTED' | 'ELEMENT_NOT_FOUND' | 'IFRAME_LOAD_FAILED' | 'PDF_EXPORT_FAILED' | 'STYLE_LOAD_FAILED' | 'CANCELLED' | 'UNKNOWN';
86
+ interface PrintError$1 extends Error {
87
+ code: PrintErrorCode;
88
+ target?: PrintTarget | undefined;
89
+ }
90
+
91
+ /**
92
+ * PrintProvider props
93
+ */
94
+ interface PrintProviderProps {
95
+ /**
96
+ * Default print options for all print operations
97
+ */
98
+ defaultOptions?: PrintOptions;
99
+ /**
100
+ * Child components
101
+ */
102
+ children: ReactNode;
103
+ }
104
+ /**
105
+ * Provider component for print functionality
106
+ */
107
+ declare function PrintProvider({ defaultOptions: initialOptions, children, }: PrintProviderProps): React__default.JSX.Element;
108
+
109
+ /**
110
+ * Print context value type
111
+ */
112
+ interface PrintContextValue {
113
+ defaultOptions: PrintOptions;
114
+ setDefaultOptions: (options: PrintOptions) => void;
115
+ }
116
+ /**
117
+ * Print context
118
+ */
119
+ declare const PrintContext: React.Context<PrintContextValue | null>;
120
+ /**
121
+ * Hook to access print context
122
+ */
123
+ declare function usePrintContext(): PrintContextValue;
124
+
125
+ /**
126
+ * Custom error class for print operations
127
+ */
128
+ declare class PrintError extends Error implements PrintError$1 {
129
+ readonly code: PrintErrorCode;
130
+ readonly target: PrintTarget | undefined;
131
+ constructor(code: PrintErrorCode, message: string, target?: PrintTarget | undefined);
132
+ }
133
+
134
+ /**
135
+ * usePrint hook result
136
+ */
137
+ interface UsePrintResult {
138
+ /**
139
+ * Print function
140
+ */
141
+ print: (target: PrintTarget, options?: PrintOptions) => Promise<void>;
142
+ /**
143
+ * Print HTML string
144
+ */
145
+ printHTML: (html: string, options?: PrintOptions) => Promise<void>;
146
+ /**
147
+ * Print URL content
148
+ */
149
+ printURL: (url: string, options?: PrintOptions) => Promise<void>;
150
+ /**
151
+ * Whether a print operation is in progress
152
+ */
153
+ isPrinting: boolean;
154
+ /**
155
+ * Error from the last print operation
156
+ */
157
+ error: PrintError | null;
158
+ /**
159
+ * Clear the error state
160
+ */
161
+ clearError: () => void;
162
+ }
163
+ /**
164
+ * Hook for printing
165
+ */
166
+ declare function usePrint(options?: PrintOptions): UsePrintResult;
167
+
168
+ /**
169
+ * usePrintPreview hook result
170
+ */
171
+ interface UsePrintPreviewResult {
172
+ /**
173
+ * Open the preview modal
174
+ */
175
+ open: () => void;
176
+ /**
177
+ * Close the preview modal
178
+ */
179
+ close: () => void;
180
+ /**
181
+ * Whether the preview is open
182
+ */
183
+ isOpen: boolean;
184
+ /**
185
+ * Print from the preview
186
+ */
187
+ print: () => Promise<void>;
188
+ /**
189
+ * Download from the preview
190
+ */
191
+ download: (filename?: string) => Promise<void>;
192
+ /**
193
+ * Current page number
194
+ */
195
+ currentPage: number;
196
+ /**
197
+ * Total number of pages
198
+ */
199
+ totalPages: number;
200
+ /**
201
+ * Current zoom level
202
+ */
203
+ zoom: number;
204
+ /**
205
+ * Set the zoom level
206
+ */
207
+ setZoom: (level: number) => void;
208
+ /**
209
+ * Zoom in
210
+ */
211
+ zoomIn: () => void;
212
+ /**
213
+ * Zoom out
214
+ */
215
+ zoomOut: () => void;
216
+ /**
217
+ * Reset zoom to 100%
218
+ */
219
+ resetZoom: () => void;
220
+ /**
221
+ * Go to next page
222
+ */
223
+ nextPage: () => void;
224
+ /**
225
+ * Go to previous page
226
+ */
227
+ prevPage: () => void;
228
+ /**
229
+ * Go to a specific page
230
+ */
231
+ goToPage: (page: number) => void;
232
+ }
233
+ /**
234
+ * Hook for print preview functionality
235
+ */
236
+ declare function usePrintPreview(ref: RefObject<HTMLElement>, options?: PreviewOptions): UsePrintPreviewResult;
237
+
238
+ /**
239
+ * usePDF hook result
240
+ */
241
+ interface UsePDFResult {
242
+ /**
243
+ * Download target as PDF
244
+ */
245
+ download: (target: PrintTarget, filename: string, options?: PDFOptions) => Promise<void>;
246
+ /**
247
+ * Convert target to Blob
248
+ */
249
+ toBlob: (target: PrintTarget, options?: PDFOptions) => Promise<Blob>;
250
+ /**
251
+ * Convert target to base64 string
252
+ */
253
+ toBase64: (target: PrintTarget, options?: PDFOptions) => Promise<string>;
254
+ /**
255
+ * Convert target to data URL
256
+ */
257
+ toDataURL: (target: PrintTarget, options?: PDFOptions) => Promise<string>;
258
+ /**
259
+ * Whether an export operation is in progress
260
+ */
261
+ isExporting: boolean;
262
+ /**
263
+ * Progress percentage (0-100)
264
+ */
265
+ progress: number;
266
+ /**
267
+ * Error from the last export operation
268
+ */
269
+ error: PrintError | null;
270
+ /**
271
+ * Clear the error state
272
+ */
273
+ clearError: () => void;
274
+ }
275
+ /**
276
+ * Hook for PDF export functionality
277
+ */
278
+ declare function usePDF(options?: PDFOptions): UsePDFResult;
279
+
280
+ /**
281
+ * Printable component props
282
+ */
283
+ interface PrintableProps extends PrintOptions {
284
+ /**
285
+ * Content to be printed
286
+ */
287
+ children: ReactNode;
288
+ /**
289
+ * Additional class name
290
+ */
291
+ className?: string;
292
+ /**
293
+ * Inline styles
294
+ */
295
+ style?: CSSProperties;
296
+ /**
297
+ * ID for the printable container
298
+ */
299
+ id?: string;
300
+ }
301
+ /**
302
+ * Printable component ref methods
303
+ */
304
+ interface PrintableRef {
305
+ /**
306
+ * Print the content
307
+ */
308
+ print: (options?: PrintOptions) => Promise<void>;
309
+ /**
310
+ * Get the container element
311
+ */
312
+ getElement: () => HTMLDivElement | null;
313
+ }
314
+ /**
315
+ * Component that wraps content and makes it printable
316
+ */
317
+ declare const Printable: React__default.ForwardRefExoticComponent<PrintableProps & React__default.RefAttributes<PrintableRef>>;
318
+
319
+ /**
320
+ * Render prop for PrintButton
321
+ */
322
+ interface PrintButtonRenderProps {
323
+ print: () => Promise<void>;
324
+ isPrinting: boolean;
325
+ error: PrintError | null;
326
+ }
327
+ /**
328
+ * PrintButton component props
329
+ */
330
+ interface PrintButtonProps extends Omit<ButtonHTMLAttributes<HTMLButtonElement>, 'children'> {
331
+ /**
332
+ * Target element or selector to print
333
+ */
334
+ target?: PrintTarget;
335
+ /**
336
+ * Reference to the target element
337
+ */
338
+ targetRef?: RefObject<HTMLElement>;
339
+ /**
340
+ * Print options
341
+ */
342
+ options?: PrintOptions;
343
+ /**
344
+ * Button content
345
+ */
346
+ children?: ReactNode;
347
+ /**
348
+ * Render prop for custom rendering
349
+ */
350
+ render?: (props: PrintButtonRenderProps) => ReactNode;
351
+ /**
352
+ * Callback when print starts
353
+ */
354
+ onPrintStart?: () => void;
355
+ /**
356
+ * Callback when print completes
357
+ */
358
+ onPrintComplete?: () => void;
359
+ /**
360
+ * Callback when print fails
361
+ */
362
+ onPrintError?: (error: PrintError) => void;
363
+ }
364
+ /**
365
+ * Button component that triggers print
366
+ */
367
+ declare function PrintButton({ target, targetRef, options, children, render, onPrintStart, onPrintComplete, onPrintError, disabled, onClick, ...buttonProps }: PrintButtonProps): React__default.JSX.Element;
368
+
369
+ /**
370
+ * PrintPreview component props
371
+ */
372
+ interface PrintPreviewProps extends PreviewOptions {
373
+ /**
374
+ * Target element or selector to preview
375
+ */
376
+ target?: PrintTarget;
377
+ /**
378
+ * Reference to the target element
379
+ */
380
+ targetRef?: RefObject<HTMLElement>;
381
+ /**
382
+ * Trigger element that opens the preview
383
+ */
384
+ trigger?: ReactNode;
385
+ /**
386
+ * Whether the preview is controlled externally
387
+ */
388
+ isOpen?: boolean;
389
+ /**
390
+ * Callback when preview closes
391
+ */
392
+ onClose?: () => void;
393
+ /**
394
+ * Callback when print is triggered from preview
395
+ */
396
+ onPrint?: () => void;
397
+ /**
398
+ * Callback when download is triggered from preview
399
+ */
400
+ onDownload?: () => void;
401
+ }
402
+ /**
403
+ * Component for print preview modal
404
+ */
405
+ declare function PrintPreview({ target, targetRef, trigger, isOpen: controlledIsOpen, onClose: onCloseProp, onPrint: onPrintProp, onDownload: onDownloadProp, ...previewOptions }: PrintPreviewProps): React__default.JSX.Element | null;
406
+
407
+ /**
408
+ * PageBreak component props
409
+ */
410
+ interface PageBreakProps {
411
+ /**
412
+ * Additional class name
413
+ */
414
+ className?: string;
415
+ }
416
+ /**
417
+ * Component that creates a page break
418
+ */
419
+ declare function PageBreak({ className }: PageBreakProps): React__default.JSX.Element;
420
+
421
+ /**
422
+ * PrintOnly component props
423
+ */
424
+ interface PrintOnlyProps {
425
+ /**
426
+ * Content to show only when printing
427
+ */
428
+ children: ReactNode;
429
+ /**
430
+ * Additional class name
431
+ */
432
+ className?: string;
433
+ /**
434
+ * Inline styles (will be applied during print)
435
+ */
436
+ style?: CSSProperties;
437
+ /**
438
+ * HTML tag to use
439
+ */
440
+ as?: keyof JSX.IntrinsicElements;
441
+ }
442
+ /**
443
+ * Component that shows content only when printing
444
+ */
445
+ declare function PrintOnly({ children, className, style, as: Component, }: PrintOnlyProps): React__default.JSX.Element;
446
+
447
+ /**
448
+ * NoPrint component props
449
+ */
450
+ interface NoPrintProps {
451
+ /**
452
+ * Content to hide when printing
453
+ */
454
+ children: ReactNode;
455
+ /**
456
+ * Additional class name
457
+ */
458
+ className?: string;
459
+ /**
460
+ * Inline styles
461
+ */
462
+ style?: CSSProperties;
463
+ /**
464
+ * HTML tag to use
465
+ */
466
+ as?: keyof JSX.IntrinsicElements;
467
+ }
468
+ /**
469
+ * Component that hides content when printing
470
+ */
471
+ declare function NoPrint({ children, className, style, as: Component, }: NoPrintProps): React__default.JSX.Element;
472
+
473
+ /**
474
+ * CSS class to hide elements when printing
475
+ */
476
+ declare const PRINT_HIDE_CLASS = "print-hide";
477
+ /**
478
+ * CSS class to show elements only when printing
479
+ */
480
+ declare const PRINT_ONLY_CLASS = "print-only";
481
+
482
+ /**
483
+ * CSS class for page break before
484
+ */
485
+ declare const BREAK_BEFORE_CLASS = "print-break-before";
486
+ /**
487
+ * CSS class for page break after
488
+ */
489
+ declare const BREAK_AFTER_CLASS = "print-break-after";
490
+ /**
491
+ * CSS class to avoid break inside
492
+ */
493
+ declare const AVOID_BREAK_CLASS = "print-avoid-break";
494
+
495
+ export { AVOID_BREAK_CLASS, BREAK_AFTER_CLASS, BREAK_BEFORE_CLASS, NoPrint, type NoPrintProps, type Orientation, type PDFOptions, PRINT_HIDE_CLASS, PRINT_ONLY_CLASS, PageBreak, type PageBreakProps, type PageSize, type PreviewOptions, PrintButton, type PrintButtonProps, type PrintButtonRenderProps, PrintContext, type PrintContextValue, PrintOnly, type PrintOnlyProps, type PrintOptions, PrintPreview, type PrintPreviewProps, PrintProvider, type PrintProviderProps, type PrintTarget, Printable, type PrintableProps, type PrintableRef, type TableData, type UsePDFResult, type UsePrintPreviewResult, type UsePrintResult, usePDF, usePrint, usePrintContext, usePrintPreview };