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