-
Notifications
You must be signed in to change notification settings - Fork 1
/
PdfElements.ts
100 lines (88 loc) · 2.79 KB
/
PdfElements.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
import { Attributes } from "react";
import { PdfElement, PdfNode } from "./PdfNode.ts";
import {
ColumnProperties,
ContentAnchor,
ContentCanvas,
ContentColumns,
ContentImage,
ContentLink,
ContentOrderedList,
ContentPageReference,
ContentQr,
ContentStack,
ContentSvg,
ContentTable,
ContentText,
ContentTextReference,
ContentTocItem,
ContentUnorderedList,
OrderedListElementProperties,
Table,
TableCellProperties,
TableOfContent,
UnorderedListElementProperties,
} from "pdfmake/interfaces";
type PdfProps<P> = P & Attributes;
type PdfPropsWithChildren<P = object> = PdfProps<P> & {
children?: PdfNode;
};
type PassThroughPdfProps<P> = PdfProps<P> & {
children: PdfElement;
};
export interface PdfElements {
"pdf-text": PdfPropsWithChildren<
| Omit<ContentText, "text">
| Omit<ContentLink, "text">
| Omit<ContentAnchor, "text">
| Omit<ContentTocItem, "text">
>;
"pdf-columns": PdfPropsWithChildren<Omit<ContentColumns, "columns">>;
"pdf-stack": PdfPropsWithChildren<Omit<ContentStack, "stack">>;
"pdf-ol": PdfPropsWithChildren<Omit<ContentOrderedList, "ol">>;
"pdf-ul": PdfPropsWithChildren<Omit<ContentUnorderedList, "ul">>;
"pdf-table": PdfPropsWithChildren<Omit<ContentTable, "table">>;
"pdf-pageReference": { children: string } & Omit<
ContentPageReference,
"pageReference"
>;
"pdf-textReference": { children: string } & Omit<
ContentTextReference,
"textReference"
>;
"pdf-image": ContentImage;
"pdf-svg": ContentSvg;
"pdf-qr": ContentQr;
"pdf-canvas": ContentCanvas;
}
type RemovePdfPrefix<S> = S extends `pdf-${infer U}` ? U : never;
type ContentKey = RemovePdfPrefix<keyof PdfElements> | "body" | "title";
export interface VirtualPdfElements {
/** Maps content array. */
"pdf-array": PdfPropsWithChildren;
/** Type-safe way to pass cell-related properties to child element. */
"pdf-cell": PassThroughPdfProps<TableCellProperties>;
/** Type-safe way to pass column-related properties to child element. */
"pdf-column": PassThroughPdfProps<ColumnProperties>;
/** Type-safe way to pass list item-related properties to child element. */
"pdf-li": PassThroughPdfProps<
OrderedListElementProperties | UnorderedListElementProperties
>;
"pdf-tbody": PdfPropsWithChildren<Omit<Table, "body">>;
"pdf-toc": PdfPropsWithChildren<Omit<TableOfContent, "title">>;
}
export type PdfReconcilerIntrinsicType =
| keyof VirtualPdfElements
| keyof PdfElements;
export type VirtualContentKey =
| RemovePdfPrefix<keyof VirtualPdfElements>
| ContentKey;
export interface PdfReconcilerElement {
$__reactPdfMakeType: PdfReconcilerIntrinsicType;
[K: string]: unknown;
}
export type TextInstance = string | number;
export type PdfReconcilerNode =
| PdfReconcilerElement
| TextInstance
| Array<PdfReconcilerNode>;