-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtypes.d.ts
164 lines (164 loc) · 3.6 KB
/
types.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
import { PDFFont, Color, Grayscale, RGB, CMYK } from "pdf-lib";
export type Alignment = "left" | "center" | "right";
export type GenColumnWidthOptions = {
columnWidthMode: "equal" | "auto" | "wrapHeader";
availableWidth: number;
tableData: CellContent[][];
font: PDFFont;
headerFont?: PDFFont;
headerTextSize?: number;
textSize: number;
borderWidth: number;
horizontalMargin: number;
headerHorizontalMargin: number;
hasHeader: boolean;
};
export interface CustomStyledText {
type: "text";
text: string;
alignment?: Alignment;
font?: PDFFont;
textSize?: number;
textColor?: Color;
}
export interface LinkBase {
type: "link";
url?: string;
page?: number;
text: string;
alignment?: Alignment;
font?: PDFFont;
textSize?: number;
textColor?: Color;
}
export type Link = LinkBase &
(
| {
url: string;
}
| {
page: number;
}
);
export interface ImageBase {
type: "image";
src?: string;
data?: Uint8Array;
width: number;
height: number;
alignment?: Alignment;
horizontalMargin?: number;
}
export type Image = ImageBase &
(
| {
src: string;
}
| {
data: Uint8Array;
}
);
export type CellElement = string | Link | Image | CustomStyledText;
export type CellContent = CellElement | Array<CellElement>;
export interface TableObject {
rows: {
[key: string]: CellElement[] | undefined;
}[];
columns: {
title: string;
key: string;
}[];
}
export interface TableDataConverterValidatorInput {
data: CellContent[][] | TableObject;
hasHeader: boolean;
fillEmpty?: boolean;
}
type ColorDeepPartial =
| DeepPartial<Grayscale>
| DeepPartial<RGB>
| DeepPartial<CMYK>;
export type DrawTableOptionsDeepPartial = {
[K in Exclude<
keyof DrawTableOptions,
"textColor" | "linkColor"
>]?: DeepPartial<DrawTableOptions[K]>;
} & {
textColor?: ColorDeepPartial;
linkColor?: ColorDeepPartial;
};
type CompatibleColorPartial = {
[P in keyof Color]: Color[P] | ColorDeepPartial[P] | undefined;
};
export type CompatibleDrawTableOptions = {
[K in Exclude<keyof DrawTableOptions, "textColor" | "linkColor">]?:
| DrawTableOptions[K]
| DrawTableOptionsDeepPartial[K];
} & {
textColor?: CompatibleColorPartial;
linkColor?: CompatibleColorPartial;
};
export type DeepPartial<T> = {
[P in keyof T]?: T[P] extends object
? T[P] extends Array<infer U>
? Array<DeepPartial<U>>
: DeepPartial<T[P]>
: T[P];
};
export interface DrawTableOptions {
textSize: number;
textColor: Color;
contentAlignment: Alignment;
font: PDFFont;
linkColor: Color;
lineHeight: number;
column: ColumnOptions;
row: RowOptions;
header: HeaderOptions;
title: TitleOptions;
border: BorderOptions;
pageMargin: PageMarginOptions;
contentMargin: ContentMarginOptions;
fillUndefCells: boolean;
}
export interface HeaderOptions {
hasHeaderRow: boolean;
font: PDFFont;
textSize: number;
textColor: Color;
backgroundColor: Color;
contentAlignment: Alignment;
}
export type ColumnOptions = {
widthMode: "equal" | "auto" | "wrapHeader";
overrideWidths: number[];
};
export interface RowOptions {
overrideHeights: number[];
}
export interface TitleOptions {
text: string;
textSize: number;
font: PDFFont;
textColor: Color;
alignment: Alignment;
}
export interface BorderOptions {
color: Color;
width: number;
}
export interface PageMarginOptions {
bottom: number;
right: number;
}
export interface ContentMarginOptions {
horizontal: number;
vertical: number;
}
export interface TableDimensions {
endX: number;
endY: number;
width: number;
height: number;
}
export {};