UNPKG

14.6 kBTypeScriptView Raw
1/// <reference types="node" />
2
3declare module '@react-pdf/renderer' {
4 import * as React from 'react';
5
6 namespace ReactPDF {
7 export interface Style {
8 //Flexbox
9
10 alignContent?: 'flex-start' | 'flex-end' | 'center' | 'stretch' | 'space-between' | 'space-around',
11 alignItems?: 'flex-start' | 'flex-end' | 'center' | 'stretch' | 'baseline',
12 alignSelf?: 'auto' | 'flex-start' | 'flex-end' | 'center' | 'baseline' | 'stretch',
13 flex?: number,
14 flexDirection?: 'row' | 'row-reverse' | 'column' | 'column-reverse',
15 flexWrap?: 'nowrap' | 'wrap' | 'wrap-reverse',
16 flexFlow?: number,
17 flexGrow?: number,
18 flexShrink?: number,
19 flexBasis?: number,
20 justifyContent?: 'space-around' | 'space-between',
21 order?: number,
22
23 // Layout?:never,
24
25 bottom?: number | string,
26 display?: 'flex' | 'none',
27 left?: number,
28 position?: 'absolute' | 'relative',
29 right?: number,
30 top?: number,
31
32 // Dimension?:never,
33
34 height?: number | string,
35 maxHeight?: number | string,
36 maxWidth?: number | string,
37 minHeight?: number | string,
38 minWidth?: number | string,
39 width?: number | string,
40
41 // Color?:never,
42
43 backgroundColor?: string,
44 color?: string,
45 opacity?: number,
46
47 // Text?:never,
48
49 fontSize?: number,
50 fontFamily?: string,
51 fontStyle?: string | 'normal',
52 fontWeight?: number | 'thin' | 'hairline' | 'ultralight' | 'extralight' | 'light' | 'normal' | 'medium' | 'semibold' | 'demibold' | 'bold' | 'ultrabold' | 'extrabold' | 'heavy' | 'black',
53 letterSpacing?: number, //?
54 lineHeight?: number,
55 maxLines?: number, //?
56 textAlign?: 'left' | 'right', //?
57 textDecoration?: 'line-through' | 'underline',
58 textDecorationColor?: string,
59 textDecorationStyle?: "dashed" | "dotted" | "solid" | string, //?
60 textIndent?: any, //?
61 textOverflow?: any, //?
62 textTransform?: 'capitalize' | 'lowercase' | 'uppercase',
63
64 // Sizing/positioning?:never,
65
66 objectFit?: string,
67 objectPosition?: number | string,
68 objectPositionX?: number | string,
69 objectPositionY?: number | string,
70
71 // Margin/padding?:never,
72
73 margin?: number | string,
74 marginHorizontal?: number | string,
75 marginVertical?: number | string,
76 marginTop?: number | string,
77 marginRight?: number | string,
78 marginBottom?: number | string,
79 marginLeft?: number | string,
80 padding?: number | string,
81 paddingHorizontal?: number | string,
82 paddingVertical?: number | string,
83 paddingTop?: number | string,
84 paddingRight?: number | string,
85 paddingBottom?: number | string,
86 paddingLeft?: number | string,
87
88 // Transformations?:never,
89
90 transform?: string,
91 transformOrigin?: number | string,
92 transformOriginX?: number | string,
93 transformOriginY?: number | string,
94
95 // Borders?:never,
96
97 border?: number | string,
98 borderTop?: number | string,
99 borderTopColor?: string,
100 borderTopStyle?: "dashed" | "dotted" | "solid", // ?
101 borderTopWidth?: number | string,
102 borderRight?: never,
103 borderRightColor?: string,
104 borderRightStyle?: "dashed" | "dotted" | "solid", //?
105 borderRightWidth?: number | string,
106 borderBottom?: number | string,
107 borderBottomColor?: string,
108 borderBottomStyle?: "dashed" | "dotted" | "solid", //?
109 borderBottomWidth?: number | string,
110 borderLeft?: number | string,
111 borderLeftColor?: string,
112 borderLeftStyle?: "dashed" | "dotted" | "solid", //?
113 borderLeftWidth?: number | string,
114 borderTopLeftRadius?: number | string,
115 borderTopRightRadius?: number | string,
116 borderBottomRightRadius?: number | string,
117 borderBottomLeftRadius?: number | string,
118 }
119
120 interface Styles {
121 [key: string]: Style;
122 }
123
124 type Orientation = 'portrait' | 'landscape';
125
126 interface DocumentProps {
127 title?: string;
128 author?: string;
129 subject?: string;
130 keywords?: string;
131 creator?: string;
132 producer?: string;
133 onRender?: () => any;
134 }
135
136 /**
137 * This component represent the PDF document itself. It must be the root
138 * of your tree element structure, and under no circumstances should it be
139 * used as children of another react-pdf component. In addition, it should
140 * only have childs of type <Page />.
141 */
142 class Document extends React.Component<DocumentProps> {}
143
144 interface NodeProps {
145 style?: Style | Style[];
146 /**
147 * Render component in all wrapped pages.
148 * @see https://react-pdf.org/advanced#fixed-components
149 */
150 fixed?: boolean;
151 /**
152 * Force the wrapping algorithm to start a new page when rendering the
153 * element.
154 * @see https://react-pdf.org/advanced#page-breaks
155 */
156 break?: boolean;
157 }
158
159 interface PageProps extends NodeProps {
160 /**
161 * Enable page wrapping for this page.
162 * @see https://react-pdf.org/components#page-wrapping
163 */
164 wrap?: boolean;
165 debug?: boolean;
166 size?: string | [number, number] | { width: number; height: number };
167 orientation?: Orientation;
168 ruler?: boolean;
169 rulerSteps?: number;
170 verticalRuler?: boolean;
171 verticalRulerSteps?: number;
172 horizontalRuler?: boolean;
173 horizontalRulerSteps?: number;
174 }
175
176 /**
177 * Represents single page inside the PDF document, or a subset of them if
178 * using the wrapping feature. A <Document /> can contain as many pages as
179 * you want, but ensure not rendering a page inside any component besides
180 * Document.
181 */
182 class Page extends React.Component<PageProps> {}
183
184 interface ViewProps extends NodeProps {
185 /**
186 * Enable/disable page wrapping for element.
187 * @see https://react-pdf.org/components#page-wrapping
188 */
189 wrap?: boolean;
190 debug?: boolean;
191 render?: (props: { pageNumber: number }) => React.ReactNode;
192 children?: React.ReactNode;
193 }
194
195 /**
196 * The most fundamental component for building a UI and is designed to be
197 * nested inside other views and can have 0 to many children.
198 */
199 class View extends React.Component<ViewProps> {}
200
201 type HTTPMethod = 'GET' | 'HEAD' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
202
203 type SourceObject =
204 | string
205 | { data: Buffer; format: 'png' | 'jpg' }
206 | { uri: string; method: HTTPMethod; body: any; headers: any };
207
208 interface BaseImageProps extends NodeProps {
209 debug?: boolean;
210 cache?: boolean;
211 safePath?: string;
212 allowDangerousPaths?: boolean;
213 }
214
215 interface ImageWithSrcProp extends BaseImageProps {
216 src: SourceObject;
217 }
218
219 interface ImageWithSourceProp extends BaseImageProps {
220 source: SourceObject;
221 }
222
223 type ImageProps = ImageWithSrcProp | ImageWithSourceProp;
224
225 /**
226 * A React component for displaying network or local (Node only) JPG or
227 * PNG images, as well as base64 encoded image strings.
228 */
229 class Image extends React.Component<ImageProps> {}
230
231 interface TextProps extends NodeProps {
232 /**
233 * Enable/disable page wrapping for element.
234 * @see https://react-pdf.org/components#page-wrapping
235 */
236 wrap?: boolean;
237 debug?: boolean;
238 render?: (props: {
239 pageNumber: number;
240 totalPages: number;
241 }) => React.ReactNode;
242 children?: React.ReactNode;
243 /**
244 * How much hyphenated breaks should be avoided.
245 */
246 hyphenationCallback?: number;
247 }
248
249 /**
250 * A React component for displaying text. Text supports nesting of other
251 * Text or Link components to create inline styling.
252 */
253 class Text extends React.Component<TextProps> {}
254
255 interface LinkProps extends NodeProps {
256 /**
257 * Enable/disable page wrapping for element.
258 * @see https://react-pdf.org/components#page-wrapping
259 */
260 wrap?: boolean;
261 debug?: boolean;
262 src: string;
263 children?: React.ReactNode;
264 }
265
266 /**
267 * A React component for displaying an hyperlink. Link’s can be nested
268 * inside a Text component, or being inside any other valid primitive.
269 */
270 class Link extends React.Component<LinkProps> {}
271
272 interface NoteProps extends NodeProps {
273 children: string;
274 }
275
276 class Note extends React.Component<NoteProps> {}
277
278 interface CanvasProps extends NodeProps {
279 debug?: boolean;
280 paint: (
281 painter: any,
282 availableWidth: number,
283 availableHeight: number
284 ) => null;
285 }
286
287 class Canvas extends React.Component<CanvasProps> {}
288
289 interface BlobProviderParams {
290 blob: Blob | null;
291 url: string | null;
292 loading: boolean;
293 error: Error | null;
294 }
295 interface BlobProviderProps {
296 document: React.ReactElement<DocumentProps>;
297 children: (params: BlobProviderParams) => React.ReactNode;
298 }
299
300 /**
301 * Easy and declarative way of getting document's blob data without
302 * showing it on screen.
303 * @see https://react-pdf.org/advanced#on-the-fly-rendering
304 * @platform web
305 */
306 class BlobProvider extends React.Component<BlobProviderProps> {}
307
308 interface PDFViewerProps {
309 width?: number | string;
310 height?: number | string;
311 style?: Style | Style[];
312 className?: string;
313 children?: React.ReactElement<DocumentProps>;
314 }
315
316 /**
317 * Iframe PDF viewer for client-side generated documents.
318 * @platform web
319 */
320 class PDFViewer extends React.Component<PDFViewerProps> {}
321
322 interface PDFDownloadLinkProps {
323 document: React.ReactElement<DocumentProps>;
324 fileName?: string;
325 style?: Style | Style[];
326 className?: string;
327 children?:
328 | React.ReactNode
329 | ((params: BlobProviderParams) => React.ReactNode);
330 }
331
332 /**
333 * Anchor tag to enable generate and download PDF documents on the fly.
334 * @see https://react-pdf.org/advanced#on-the-fly-rendering
335 * @platform web
336 */
337 class PDFDownloadLink extends React.Component<PDFDownloadLinkProps> {}
338
339 type FontStyle = 'normal' | 'italic' | 'oblique';
340
341 type FontWeight =
342 | number
343 | 'thin'
344 | 'ultralight'
345 | 'light'
346 | 'normal'
347 | 'medium'
348 | 'semibold'
349 | 'bold'
350 | 'ultrabold'
351 | 'heavy';
352
353 interface FontSource {
354 src: string;
355 fontFamily: string;
356 fontStyle: FontStyle;
357 fontWeight: number;
358 data: any;
359 loading: boolean;
360 options: any;
361 }
362
363 interface FontInstance {
364 family: string;
365 sources: FontSource[];
366 }
367
368 interface EmojiSource {
369 url: string;
370 format: string;
371 }
372
373 interface FontDescriptor {
374 family: string;
375 fontStyle?: FontStyle;
376 fontWeight?: FontWeight;
377 }
378
379 interface RegisteredFont {
380 src: string;
381 loaded: boolean;
382 loading: boolean;
383 data: any;
384 [key: string]: any;
385 }
386
387 type HyphenationCallback = (
388 words: string,
389 glyphString: { [key: string]: any },
390 ) => string[];
391
392 const Font: {
393 register: (options: {
394 family: string;
395 src: string;
396 [key: string]: any;
397 } | {
398 family: string;
399 fonts: {
400 src: string;
401 fontStyle?: string;
402 fontWeight?: string | number;
403 [key: string]: any;
404 }[];
405 }) => void;
406 getEmojiSource: () => EmojiSource;
407 getRegisteredFonts: () => FontInstance[];
408 getRegisteredFontFamilies: () => string[];
409 registerEmojiSource: (emojiSource: EmojiSource) => void;
410 registerHyphenationCallback: (
411 hyphenationCallback: HyphenationCallback,
412 ) => void;
413 getHyphenationCallback: () => HyphenationCallback;
414 getFont: (fontDescriptor: FontDescriptor) => RegisteredFont | undefined;
415 load: (
416 fontDescriptor: FontDescriptor,
417 document: React.ReactElement<DocumentProps>,
418 ) => Promise<void>;
419 clear: () => void;
420 reset: () => void;
421 };
422
423 const StyleSheet: {
424 hairlineWidth: number;
425 create: (styles: Styles) => Styles;
426 resolve: (
427 style: Style,
428 container: {
429 width: number;
430 height: number;
431 orientation: Orientation;
432 },
433 ) => Style;
434 flatten: (...style: (Style[] | Style | undefined)[]) => Style;
435 absoluteFillObject: {
436 position: 'absolute';
437 left: 0;
438 right: 0;
439 top: 0;
440 bottom: 0;
441 };
442 };
443
444 const version: any;
445
446 const PDFRenderer: any;
447
448 const createInstance: (
449 element: {
450 type: string;
451 props: { [key: string]: any };
452 },
453 root?: any,
454 ) => any;
455
456 const pdf: (
457 document: React.ReactElement<DocumentProps>,
458 ) => {
459 container: any;
460 isDirty: () => boolean;
461 updateContainer: (document: React.ReactElement<any>) => void;
462 toBuffer: () => Promise<NodeJS.ReadableStream>;
463 toBlob: () => Promise<Blob>;
464 toString: () => string;
465 };
466
467 const renderToStream: (
468 document: React.ReactElement<DocumentProps>,
469 ) => Promise<NodeJS.ReadableStream>;
470
471 const renderToFile: (
472 document: React.ReactElement<DocumentProps>,
473 filePath: string,
474 callback?: (output: NodeJS.ReadableStream, filePath: string) => any,
475 ) => Promise<NodeJS.ReadableStream>;
476
477 const render: typeof renderToFile;
478 }
479
480 const Document: typeof ReactPDF.Document;
481 const Page: typeof ReactPDF.Page;
482 const View: typeof ReactPDF.View;
483 const Image: typeof ReactPDF.Image;
484 const Text: typeof ReactPDF.Text;
485 const Canvas: typeof ReactPDF.Canvas;
486 const Link: typeof ReactPDF.Link;
487 const Note: typeof ReactPDF.Note;
488 const Font: typeof ReactPDF.Font;
489 const StyleSheet: typeof ReactPDF.StyleSheet;
490 const createInstance: typeof ReactPDF.createInstance;
491 const PDFRenderer: typeof ReactPDF.PDFRenderer;
492 const version: typeof ReactPDF.version;
493 const pdf: typeof ReactPDF.pdf;
494 const PDFViewer: typeof ReactPDF.PDFViewer;
495 const BlobProvider: typeof ReactPDF.BlobProvider;
496 const PDFDownloadLink: typeof ReactPDF.PDFDownloadLink;
497
498 export default ReactPDF;
499 export {
500 Document,
501 Page,
502 View,
503 Image,
504 Text,
505 Canvas,
506 Link,
507 Note,
508 Font,
509 StyleSheet,
510 createInstance,
511 PDFRenderer,
512 version,
513 pdf,
514 PDFViewer,
515 BlobProvider,
516 PDFDownloadLink,
517 };
518}