-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbrowser-types.ts
236 lines (224 loc) · 6.12 KB
/
browser-types.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
import { BrowserOptions, ChromeArgOptions, LaunchOptions, PuppeteerLifeCycleEvent } from 'puppeteer-core'
import { LaunchOptions as PlayLaunchOptions } from 'playwright-chromium'
import { Keys, Optional, Undef } from './standard-types'
import { ThemePattern } from './enum-types'
import { RouteOptions } from './domain-types'
import { IMAGE_CONTENT, IMAGE_ENCODING } from '../src/constants/constants'
//--------------------------------------------------------------------------------------------------
/**
* ImageContentType
* @desc Type representing supported image contents
*/
export type ImageContentType = Keys<typeof IMAGE_CONTENT>
/**
* ImageEncodingType
* @desc Type representing supported image encodings
*/
export type ImageEncodingType = Keys<typeof IMAGE_ENCODING>
//--------------------------------------------------------------------------------------------------
/**
* BrowserType
* @desc Type representing supported browsers
*/
export enum BrowserType {
chromium = 'chromium',
firefox = 'firefox',
}
//--------------------------------------------------------------------------------------------------
/**
* ChromeBrowserOptions
* @desc Type representing chrome browser options
*/
export type ChromeBrowserOptions = LaunchOptions & ChromeArgOptions & BrowserOptions
//--------------------------------------------------------------------------------------------------
/**
* PageOptions
* @desc Type representing page configuration options
*/
export type PageOptions<T> = {
/**
* Page referer.
*/
readonly referer?: Undef<string>
/**
* Page loading timeout.
*/
readonly timeout?: Undef<number>
/**
* Page loading timeout by DOM event.
*/
readonly waitUntil?: T
}
/**
* PuppeteerPageOptions
* @desc Type representing puppeteer page configuration options
*/
export type PuppeteerPageOptions = PageOptions<PuppeteerLifeCycleEvent | PuppeteerLifeCycleEvent[]>
/**
* PlaywrightPageOptions
* @desc Type representing playwright page configuration options
*/
export type PlaywrightPageOptions = PageOptions<'load' | 'domcontentloaded' | 'networkidle'>
/**
* GeneralPageOptions
* @desc Type representing general page configuration options
*/
export type GeneralPageOptions = PuppeteerPageOptions | PlaywrightPageOptions
//--------------------------------------------------------------------------------------------------
/**
* LocationOptions
* @desc Type representing location options
*/
export type LocationOptions = {
/**
* Generated image name.
*/
readonly name: string
/**
* Generated image path.
*/
readonly path: string
}
//--------------------------------------------------------------------------------------------------
/**
* ImageOptions
* @desc Type representing image options
*/
export type ImageOptions = {
/**
* Page width in pixels.
*/
readonly width: number
/**
* Page height in pixels.
*/
readonly height: number
/**
* Device scale factor.
*/
readonly deviceScaleFactor?: number
}
//--------------------------------------------------------------------------------------------------
/**
* ImageClipOptions
* @desc Type representing image clip options
*/
export type ImageClipOptions = {
/**
* page clip start X-position in pixels.
*/
readonly x: number
/**
* page clip start Y-position in pixels.
*/
readonly y: number
/**
* page clip width in pixels.
*/
readonly width: number
/**
* page clip height in pixels.
*/
readonly height: number
}
//--------------------------------------------------------------------------------------------------
/**
* ScreenshotOptions
* @desc Type representing screenshot options
*/
export type ScreenshotOptions = {
/**
* Image configuration options.
*/
readonly imageOptions?: Partial<ImageOptions>
/**
* Image clip configuration options.
*/
readonly imageClipOptions?: Partial<ImageClipOptions>
/**
* Play browser launch options.
*/
readonly playLaunchOptions?: Partial<PlayLaunchOptions>
/**
* Page configuration options.
*/
readonly pageOptions?: Partial<GeneralPageOptions>
/**
* Browser configuration options.
*/
readonly browserOptions?: Partial<ChromeBrowserOptions>
/**
* Image location options.
*/
readonly locationOptions?: Partial<LocationOptions>
/**
* Image resource options.
*/
readonly resourceOptions?: Partial<ResourceOptions>
}
//--------------------------------------------------------------------------------------------------
/**
* ThemeOptions
* @desc Type representing theme options
*/
export type ThemeOptions = {
/**
* Page theme
*/
readonly theme: Optional<ThemePattern>
}
//--------------------------------------------------------------------------------------------------
/**
* ResourceOptions
* @desc Type representing resource options
*/
export type ResourceOptions = {
/**
* Enable/disable full page view port for screenshot.
*/
readonly fullPage?: boolean
/**
* Screenshot image quality (0-100).
*/
readonly quality?: number
/**
* Omit screenshot background.
*/
readonly omitBackground?: boolean
/**
* Page selector to fetch by
*/
readonly selector: string
/**
* Image content type.
*/
readonly type: ImageContentType
/**
* Image content transfer encoding.
*/
readonly encoding: ImageEncodingType
}
//--------------------------------------------------------------------------------------------------
/**
* RequestOptions
* @desc Type representing request options
*/
export type RequestOptions = {
/**
* Parsed image url.
*/
readonly routeOptions: RouteOptions
/**
* Parsed image options.
*/
readonly imageOptions?: ImageOptions
/**
* Parsed resource options.
*/
readonly resourceOptions?: ResourceOptions
/**
* Parsed page options.
*/
readonly pageOptions?: GeneralPageOptions
}
//--------------------------------------------------------------------------------------------------