@dxtmisha/scripts 0.7.10 → 0.7.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +15 -0
- package/README.md +42 -173
- package/bin/design-figma.ts +10 -0
- package/bin/design-screenshot.ts +7 -0
- package/bin/design-types.ts +3 -1
- package/package.json +12 -8
- package/src/classes/BrowserItem.ts +375 -0
- package/src/classes/Design/DesignFigma.ts +34 -0
- package/src/classes/Design/DesignScreenshot.ts +123 -0
- package/src/classes/Design/DesignTypes.ts +79 -29
- package/src/classes/FigmaApi.ts +190 -0
- package/src/classes/Properties/PropertiesConfig.ts +9 -0
- package/src/config.ts +1 -0
- package/src/library.ts +5 -1
- package/src/media/templates/componentDoc/figma/run-figma.ts +26 -0
- package/src/media/templates/packages/nitro/README.md +1 -0
- package/src/media/templates/packages/nitro/index.html +2 -0
- package/src/media/templates/packages/nitro/package.json +25 -0
- package/src/media/templates/packages/nitro/server/plugins/ui-plugin.ts +7 -0
- package/src/media/templates/packages/nitro/server/routes/api/hello.ts +13 -0
- package/src/media/templates/packages/nitro/src/App.vue +10 -0
- package/src/media/templates/packages/nitro/src/entry-client.ts +12 -0
- package/src/media/templates/packages/nitro/src/entry-server.ts +29 -0
- package/src/media/templates/packages/nitro/src/main.ts +14 -0
- package/src/media/templates/packages/nitro/src/pages/HomePage.vue +8 -0
- package/src/media/templates/packages/nitro/src/router.ts +11 -0
- package/src/media/templates/packages/nitro/src/style.scss +0 -0
- package/src/media/templates/packages/nitro/src/templates/main.html +21 -0
- package/src/media/templates/packages/nitro/src/vite-env.d.ts +11 -0
- package/src/media/templates/packages/nitro/tsconfig.app.json +15 -0
- package/src/media/templates/packages/nitro/tsconfig.json +7 -0
- package/src/media/templates/packages/nitro/tsconfig.node.json +12 -0
- package/src/media/templates/packages/nitro/vite.config.ts +17 -0
- package/src/types/configTypes.ts +3 -0
- package/src/types/figmaApiTypes.ts +337 -0
- package/src/types/screenshotTypes.ts +35 -5
- package/src/functions/takeScreenshot.ts +0 -49
|
@@ -0,0 +1,337 @@
|
|
|
1
|
+
/** Figma REST API endpoints/ Эндпоинты Figma REST API */
|
|
2
|
+
export enum FigmaApiEndpoint {
|
|
3
|
+
/** Get file content / Получить содержимое файла */
|
|
4
|
+
files = 'files/:file_key',
|
|
5
|
+
/** Get specific nodes from a file / Получить конкретные узлы из файла */
|
|
6
|
+
fileNodes = 'files/:file_key/nodes',
|
|
7
|
+
/** Get specific images from a file / Получить конкретные изображения из файла */
|
|
8
|
+
fileImages = 'images/:file_key',
|
|
9
|
+
/** Get image fills from a file / Получить заливки изображений из файла */
|
|
10
|
+
fileImageFills = 'files/:file_key/images',
|
|
11
|
+
/** Get file versions / Получить версии файла */
|
|
12
|
+
fileVersions = 'files/:file_key/versions',
|
|
13
|
+
/** Get file comments / Получить комментарии файла */
|
|
14
|
+
fileComments = 'files/:file_key/comments',
|
|
15
|
+
/** Get user information / Получить информацию о пользователе */
|
|
16
|
+
me = 'me',
|
|
17
|
+
/** Get team projects / Получить проекты команды */
|
|
18
|
+
teamProjects = 'teams/:team_id/projects',
|
|
19
|
+
/** Get project files / Получить файлы проекта */
|
|
20
|
+
projectFiles = 'projects/:project_id/files',
|
|
21
|
+
/** Get component information / Получить информацию о компоненте */
|
|
22
|
+
components = 'components/:key',
|
|
23
|
+
/** Get file components / Получить компоненты файла */
|
|
24
|
+
fileComponents = 'files/:file_key/components',
|
|
25
|
+
/** Get team components / Получить компоненты команды */
|
|
26
|
+
teamComponents = 'teams/:team_id/components',
|
|
27
|
+
/** Get component set information / Получить информацию о наборе компонентов */
|
|
28
|
+
componentSets = 'component_sets/:key',
|
|
29
|
+
/** Get file component sets / Получить наборы компонентов файла */
|
|
30
|
+
fileComponentSets = 'files/:file_key/component_sets',
|
|
31
|
+
/** Get team component sets / Получить наборы компонентов команды */
|
|
32
|
+
teamComponentSets = 'teams/:team_id/component_sets',
|
|
33
|
+
/** Get style information / Получить информацию о стиле */
|
|
34
|
+
styles = 'styles/:key',
|
|
35
|
+
/** Get file styles / Получить стили файла */
|
|
36
|
+
fileStyles = 'files/:file_key/styles',
|
|
37
|
+
/** Get team styles / Получить стили команды */
|
|
38
|
+
teamStyles = 'teams/:team_id/styles'
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Parameters for the files endpoint.
|
|
43
|
+
*
|
|
44
|
+
* Параметры для эндпоинта files.
|
|
45
|
+
*/
|
|
46
|
+
export type FigmaFilesParams = {
|
|
47
|
+
/** A specific version ID to get / Идентификатор конкретной версии для получения */
|
|
48
|
+
version?: string
|
|
49
|
+
|
|
50
|
+
/** Comma separated list of nodes that you care about in the document / Список узлов через запятую, которые вас интересуют в документе */
|
|
51
|
+
ids?: string
|
|
52
|
+
|
|
53
|
+
/** How deep into the document tree to traverse / Насколько глубоко по дереву документа нужно пройтись */
|
|
54
|
+
depth?: number
|
|
55
|
+
|
|
56
|
+
/** Set to "paths" to export vector data / Установите "paths" для экспорта векторных данных */
|
|
57
|
+
geometry?: 'paths'
|
|
58
|
+
|
|
59
|
+
/** A comma separated list of plugin IDs to include their data / Список ID плагинов через запятую для включения их данных */
|
|
60
|
+
plugin_data?: string
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Returns branch metadata for the requested file /
|
|
64
|
+
* Возвращает метаданные ветки для запрошенного файла
|
|
65
|
+
* @default false
|
|
66
|
+
*/
|
|
67
|
+
branch_data?: boolean
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Result returned by the files endpoint.
|
|
72
|
+
*
|
|
73
|
+
* Результат, возвращаемый эндпоинтом files.
|
|
74
|
+
*/
|
|
75
|
+
export type FigmaFilesResult = {
|
|
76
|
+
/** File name / Название файла */
|
|
77
|
+
name: string
|
|
78
|
+
/** User's role in the file / Роль пользователя в файле */
|
|
79
|
+
role: string
|
|
80
|
+
/** Last modified date / Дата последнего изменения */
|
|
81
|
+
lastModified: string
|
|
82
|
+
/** Editor type (figma or figjam) / Тип редактора (figma или figjam) */
|
|
83
|
+
editorType: string
|
|
84
|
+
/** URL to the file thumbnail / URL миниатюры файла */
|
|
85
|
+
thumbnailUrl: string
|
|
86
|
+
/** Version ID / Идентификатор версии */
|
|
87
|
+
version: string
|
|
88
|
+
/** The root node of the document / Корневой узел документа */
|
|
89
|
+
document: any
|
|
90
|
+
/** Map of components used in the file / Карта компонентов, используемых в файле */
|
|
91
|
+
components: Record<string, any>
|
|
92
|
+
/** Map of component sets used in the file / Карта наборов компонентов, используемых в файле */
|
|
93
|
+
componentSets: Record<string, any>
|
|
94
|
+
/** Schema version / Версия схемы */
|
|
95
|
+
schemaVersion: number
|
|
96
|
+
/** Map of styles used in the file / Карта стилей, используемых в файле */
|
|
97
|
+
styles: Record<string, any>
|
|
98
|
+
/** Main file key if this is a branch / Ключ основного файла, если это ветка */
|
|
99
|
+
mainFileKey?: string
|
|
100
|
+
/** List of branches for the file / Список веток для файла */
|
|
101
|
+
branches?: {
|
|
102
|
+
/** Branch key / Ключ ветки */
|
|
103
|
+
key: string
|
|
104
|
+
/** Branch name / Название ветки */
|
|
105
|
+
name: string
|
|
106
|
+
/** URL to the branch thumbnail / URL миниатюры ветки */
|
|
107
|
+
thumbnail_url: string
|
|
108
|
+
/** Last modified date of the branch / Дата последнего изменения ветки */
|
|
109
|
+
last_modified: string
|
|
110
|
+
/** Link access level / Уровень доступа по ссылке */
|
|
111
|
+
link_access: string
|
|
112
|
+
}[]
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Parameters for the fileNodes endpoint.
|
|
117
|
+
*
|
|
118
|
+
* Параметры для эндпоинта fileNodes.
|
|
119
|
+
*/
|
|
120
|
+
export type FigmaFileNodesParams = {
|
|
121
|
+
/** A comma separated list of node IDs to retrieve and convert / Список ID узлов через запятую для получения и преобразования */
|
|
122
|
+
ids: string
|
|
123
|
+
|
|
124
|
+
/** A specific version ID to get / Идентификатор конкретной версии для получения */
|
|
125
|
+
version?: string
|
|
126
|
+
|
|
127
|
+
/** How deep into the node tree to traverse / Насколько глубоко по дереву узлов нужно пройтись */
|
|
128
|
+
depth?: number
|
|
129
|
+
|
|
130
|
+
/** Set to "paths" to export vector data / Установите "paths" для экспорта векторных данных */
|
|
131
|
+
geometry?: 'paths'
|
|
132
|
+
|
|
133
|
+
/** A comma separated list of plugin IDs to include their data / Список ID плагинов через запятую для включения их данных */
|
|
134
|
+
plugin_data?: string
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Result returned by the fileNodes endpoint.
|
|
139
|
+
*
|
|
140
|
+
* Результат, возвращаемый эндпоинтом fileNodes.
|
|
141
|
+
*/
|
|
142
|
+
export type FigmaFileNodesResult = {
|
|
143
|
+
/** File name / Название файла */
|
|
144
|
+
name: string
|
|
145
|
+
/** User's role in the file / Роль пользователя в файле */
|
|
146
|
+
role: string
|
|
147
|
+
/** Last modified date / Дата последнего изменения */
|
|
148
|
+
lastModified: string
|
|
149
|
+
/** Editor type (figma or figjam) / Тип редактора (figma или figjam) */
|
|
150
|
+
editorType: string
|
|
151
|
+
/** URL to the file thumbnail / URL миниатюры файла */
|
|
152
|
+
thumbnailUrl: string
|
|
153
|
+
/** Error message if any / Сообщение об ошибке, если есть */
|
|
154
|
+
err?: string
|
|
155
|
+
/** Map of node IDs to node data / Карта ID узлов и данных узлов */
|
|
156
|
+
nodes: Record<string, {
|
|
157
|
+
/** The root node of the requested subtree / Корневой узел запрошенного поддерева */
|
|
158
|
+
document: any
|
|
159
|
+
/** Map of components used in the subtree / Карта компонентов, используемых в поддереве */
|
|
160
|
+
components: Record<string, any>
|
|
161
|
+
/** Map of component sets used in the subtree / Карта наборов компонентов, используемых в поддереве */
|
|
162
|
+
componentSets: Record<string, any>
|
|
163
|
+
/** Schema version / Версия схемы */
|
|
164
|
+
schemaVersion: number
|
|
165
|
+
/** Map of styles used in the subtree / Карта стилей, используемых в поддереве */
|
|
166
|
+
styles: Record<string, any>
|
|
167
|
+
}>
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Parameters for the fileImages endpoint.
|
|
172
|
+
*
|
|
173
|
+
* Параметры для эндпоинта fileImages.
|
|
174
|
+
*/
|
|
175
|
+
export type FigmaFileImagesParams = {
|
|
176
|
+
/** A comma separated list of node IDs to render / Список ID узлов через запятую для рендеринга */
|
|
177
|
+
ids: string
|
|
178
|
+
|
|
179
|
+
/** A number between 0.01 and 4, the image scaling factor / Число от 0.01 до 4, коэффициент масштабирования изображения */
|
|
180
|
+
scale?: number
|
|
181
|
+
|
|
182
|
+
/** The image output format, as a string enum / Формат вывода изображения в виде строки enum */
|
|
183
|
+
format?: 'jpg' | 'png' | 'svg' | 'pdf'
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Whether text elements are rendered as outlines (vector paths) or as <text> elements in SVGs /
|
|
187
|
+
* Визуализируются ли текстовые элементы как контуры (векторные контуры) или как элементы <text> в SVG
|
|
188
|
+
* @default true
|
|
189
|
+
*/
|
|
190
|
+
svg_outline_text?: boolean
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Whether to include id attributes for all SVG elements. Adds the layer name to the id attribute of an svg element /
|
|
194
|
+
* Включать ли атрибуты id для всех элементов SVG. Добавляет имя слоя в атрибут id элемента svg
|
|
195
|
+
* @default false
|
|
196
|
+
*/
|
|
197
|
+
svg_include_id?: boolean
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Whether to include node id attributes for all SVG elements. Adds the node id to a data-node-id attribute of an svg element /
|
|
201
|
+
* Включать ли атрибуты id узла для всех элементов SVG. Добавляет id узла в атрибут data-node-id элемента svg
|
|
202
|
+
* @default false
|
|
203
|
+
*/
|
|
204
|
+
svg_include_node_id?: boolean
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Whether to simplify inside/outside strokes and use stroke attribute if possible instead of <mask> /
|
|
208
|
+
* Упрощать ли внутренние/внешние обводки и использовать атрибут stroke, если это возможно, вместо <mask>
|
|
209
|
+
* @default true
|
|
210
|
+
*/
|
|
211
|
+
svg_simplify_stroke?: boolean
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Whether content that overlaps the node should be excluded from rendering /
|
|
215
|
+
* Должен ли контент, перекрывающий узел, быть исключен из рендеринга
|
|
216
|
+
* @default true
|
|
217
|
+
*/
|
|
218
|
+
contents_only?: boolean
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* Use the full dimensions of the node regardless of whether or not it is cropped or the space around it is empty /
|
|
222
|
+
* Использовать полные размеры узла независимо от того, обрезан он или пространство вокруг него пустое
|
|
223
|
+
* @default false
|
|
224
|
+
*/
|
|
225
|
+
use_absolute_bounds?: boolean
|
|
226
|
+
|
|
227
|
+
/** A specific version ID to use / Идентификатор конкретной версии для использования */
|
|
228
|
+
version?: string
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* Result returned by the fileImages endpoint.
|
|
233
|
+
*
|
|
234
|
+
* Результат, возвращаемый эндпоинтом fileImages.
|
|
235
|
+
*/
|
|
236
|
+
export type FigmaFileImagesResult = {
|
|
237
|
+
/** Error message if the request failed / Сообщение об ошибке, если запрос не удался */
|
|
238
|
+
err: string | null
|
|
239
|
+
/** A mapping from node IDs to URLs of the rendered images / Сопоставление ID узлов с URL-адресами отрендеренных изображений */
|
|
240
|
+
images: Record<string, string>
|
|
241
|
+
/** Status code of the response / Код статуса ответа */
|
|
242
|
+
status: number
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* Result returned by the fileStyles endpoint.
|
|
247
|
+
*
|
|
248
|
+
* Результат, возвращаемый эндпоинтом fileStyles.
|
|
249
|
+
*/
|
|
250
|
+
export type FigmaFileStylesResult = {
|
|
251
|
+
/** Status code of the response / Код статуса ответа */
|
|
252
|
+
status: number
|
|
253
|
+
/** Whether an error occurred / Произошла ли ошибка */
|
|
254
|
+
error: boolean
|
|
255
|
+
/** Metadata container / Контейнер метаданных */
|
|
256
|
+
meta: {
|
|
257
|
+
/** List of styles in the file / Список стилей в файле */
|
|
258
|
+
styles: {
|
|
259
|
+
/** The unique identifier of the style / Уникальный идентификатор стиля */
|
|
260
|
+
key: string
|
|
261
|
+
/** The key of the file the style lives in / Ключ файла, в котором находится стиль */
|
|
262
|
+
file_key: string
|
|
263
|
+
/** The node ID that corresponds to the style / ID узла, соответствующий стилю */
|
|
264
|
+
node_id: string
|
|
265
|
+
/** The type of style (FILL, TEXT, EFFECT, or GRID) / Тип стиля (FILL, TEXT, EFFECT или GRID) */
|
|
266
|
+
style_type: 'FILL' | 'TEXT' | 'EFFECT' | 'GRID'
|
|
267
|
+
/** URL to a thumbnail image of the style / URL-адрес миниатюры стиля */
|
|
268
|
+
thumbnail_url: string
|
|
269
|
+
/** Name of the style / Название стиля */
|
|
270
|
+
name: string
|
|
271
|
+
/** Description of the style / Описание стиля */
|
|
272
|
+
description: string
|
|
273
|
+
/** Date the style was last updated / Дата последнего обновления стиля */
|
|
274
|
+
updated_at: string
|
|
275
|
+
/** Date the style was created / Дата создания стиля */
|
|
276
|
+
created_at: string
|
|
277
|
+
/** A sortable string for the style's position / Строка для сортировки позиции стиля */
|
|
278
|
+
sort_position: string
|
|
279
|
+
/** The user who created the style / Пользователь, создавший стиль */
|
|
280
|
+
user: {
|
|
281
|
+
/** User's ID / ID пользователя */
|
|
282
|
+
id: string
|
|
283
|
+
/** User's handle / Никнейм пользователя */
|
|
284
|
+
handle: string
|
|
285
|
+
/** URL to the user's avatar / URL-адрес аватара пользователя */
|
|
286
|
+
img_url: string
|
|
287
|
+
}
|
|
288
|
+
}[]
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* Result returned by the styles endpoint.
|
|
294
|
+
*
|
|
295
|
+
* Результат, возвращаемый эндпоинтом styles.
|
|
296
|
+
*/
|
|
297
|
+
export type FigmaStylesResult = {
|
|
298
|
+
/** Status code of the response / Код статуса ответа */
|
|
299
|
+
status: number
|
|
300
|
+
/** Whether an error occurred / Произошла ли ошибка */
|
|
301
|
+
error: boolean
|
|
302
|
+
/** Metadata about the style / Метаданные о стиле */
|
|
303
|
+
meta: {
|
|
304
|
+
/** The unique identifier of the style / Уникальный идентификатор стиля */
|
|
305
|
+
key: string
|
|
306
|
+
/** The key of the file the style lives in / Ключ файла, в котором находится стиль */
|
|
307
|
+
file_key: string
|
|
308
|
+
/** The node ID that corresponds to the style / ID узла, соответствующий стилю */
|
|
309
|
+
node_id: string
|
|
310
|
+
/** The type of style (FILL, TEXT, EFFECT, or GRID) / Тип стиля (FILL, TEXT, EFFECT или GRID) */
|
|
311
|
+
style_type: 'FILL' | 'TEXT' | 'EFFECT' | 'GRID'
|
|
312
|
+
/** URL to a thumbnail image of the style / URL-адрес миниатюры стиля */
|
|
313
|
+
thumbnail_url: string
|
|
314
|
+
/** Name of the style / Название стиля */
|
|
315
|
+
name: string
|
|
316
|
+
/** Description of the style / Описание стиля */
|
|
317
|
+
description: string
|
|
318
|
+
/** Date the style was last updated / Дата последнего обновления стиля */
|
|
319
|
+
updated_at: string
|
|
320
|
+
/** Date the style was created / Дата создания стиля */
|
|
321
|
+
created_at: string
|
|
322
|
+
/** A sortable string for the style's position / Строка для сортировки позиции стиля */
|
|
323
|
+
sort_position: string
|
|
324
|
+
/** The user who created the style / Пользователь, создавший стиль */
|
|
325
|
+
user: {
|
|
326
|
+
/** User's ID / ID пользователя */
|
|
327
|
+
id: string
|
|
328
|
+
/** User's handle / Никнейм пользователя */
|
|
329
|
+
handle: string
|
|
330
|
+
/** URL to the user's avatar / URL-адрес аватара пользователя */
|
|
331
|
+
img_url: string
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
/** Base URL for Figma REST API / Базовый URL для Figma REST API */
|
|
337
|
+
export const FIGMA_API_URL: string = 'https://api.figma.com/v1/'
|
|
@@ -1,5 +1,22 @@
|
|
|
1
|
+
import { type PuppeteerLifeCycleEvent } from 'puppeteer'
|
|
2
|
+
|
|
3
|
+
/** Options for page sizes/ Опции для размеров страницы */
|
|
4
|
+
export interface ScreenshotMetrics {
|
|
5
|
+
/** Width of the page/ Ширина страницы */
|
|
6
|
+
width: number
|
|
7
|
+
/** Height of the page/ Высота страницы */
|
|
8
|
+
height: number
|
|
9
|
+
}
|
|
10
|
+
|
|
1
11
|
/** Options for taking screenshots/ Опции для создания скриншотов */
|
|
2
12
|
export interface ScreenshotOptions {
|
|
13
|
+
/** Additional arguments for browser launch/ Дополнительные аргументы для запуска браузера */
|
|
14
|
+
args?: string[]
|
|
15
|
+
/** When to consider navigation succeeded/ Когда считать навигацию успешной */
|
|
16
|
+
waitUntil?: PuppeteerLifeCycleEvent | PuppeteerLifeCycleEvent[]
|
|
17
|
+
/** Timeout for loading the page/ Таймаут для загрузки страницы */
|
|
18
|
+
timeout?: number
|
|
19
|
+
|
|
3
20
|
/** Width of the screenshot/ Ширина скриншота */
|
|
4
21
|
width?: number
|
|
5
22
|
/** Height of the screenshot/ Высота скриншота */
|
|
@@ -12,14 +29,27 @@ export interface ScreenshotOptions {
|
|
|
12
29
|
fullPage?: boolean
|
|
13
30
|
}
|
|
14
31
|
|
|
15
|
-
/** Default screenshot
|
|
16
|
-
export const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
32
|
+
/** Default screenshot args/ Стандартные аргументы для запуска браузера */
|
|
33
|
+
export const SCREENSHOT_ARGS = [
|
|
34
|
+
'--no-sandbox',
|
|
35
|
+
'--disable-setuid-sandbox',
|
|
36
|
+
'--disable-dev-shm-usage'
|
|
37
|
+
]
|
|
20
38
|
|
|
21
39
|
/** Default screenshot format/ Стандартный формат скриншотов */
|
|
22
40
|
export const SCREENSHOT_FORMAT = 'webp'
|
|
23
41
|
|
|
42
|
+
/** Default screenshot heights/ Стандартные высоты скриншотов */
|
|
43
|
+
export const SCREENSHOT_HEIGHTS = 1080
|
|
44
|
+
|
|
24
45
|
/** Default screenshot quality/ Стандартное качество скриншотов */
|
|
25
46
|
export const SCREENSHOT_QUALITY = 80
|
|
47
|
+
|
|
48
|
+
/** Default screenshot timeout/ Стандартный таймаут для загрузки страницы */
|
|
49
|
+
export const SCREENSHOT_TIMEOUT = 320_000
|
|
50
|
+
|
|
51
|
+
/** Default wait until condition/ Стандартное условие ожидания загрузки */
|
|
52
|
+
export const SCREENSHOT_WAIT_UNTIL: PuppeteerLifeCycleEvent[] = ['networkidle0', 'domcontentloaded']
|
|
53
|
+
|
|
54
|
+
/** Default screenshot widths/ Стандартные ширины скриншотов */
|
|
55
|
+
export const SCREENSHOT_WIDTHS = 1920
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import puppeteer from 'puppeteer'
|
|
2
|
-
import {
|
|
3
|
-
SCREENSHOT_FORMAT,
|
|
4
|
-
SCREENSHOT_HEIGHTS,
|
|
5
|
-
SCREENSHOT_QUALITY,
|
|
6
|
-
SCREENSHOT_WIDTHS,
|
|
7
|
-
type ScreenshotOptions
|
|
8
|
-
} from '../types/screenshotTypes'
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Takes a screenshot of the given URL.
|
|
12
|
-
*
|
|
13
|
-
* Делает скриншот по указанному URL.
|
|
14
|
-
* @param url URL to capture/URL для захвата
|
|
15
|
-
* @param outputPath Path to save the screenshot/Путь для сохранения скриншота
|
|
16
|
-
* @param options Additional options for screenshot/Дополнительные опции для скриншота
|
|
17
|
-
*/
|
|
18
|
-
export async function takeScreenshot(
|
|
19
|
-
url: string,
|
|
20
|
-
outputPath: string,
|
|
21
|
-
options: ScreenshotOptions = {}
|
|
22
|
-
): Promise<void> {
|
|
23
|
-
const {
|
|
24
|
-
width = SCREENSHOT_WIDTHS,
|
|
25
|
-
height = SCREENSHOT_HEIGHTS,
|
|
26
|
-
format = SCREENSHOT_FORMAT,
|
|
27
|
-
quality = SCREENSHOT_QUALITY,
|
|
28
|
-
fullPage = true
|
|
29
|
-
} = options
|
|
30
|
-
|
|
31
|
-
const browser = await puppeteer.launch()
|
|
32
|
-
const page = await browser.newPage()
|
|
33
|
-
|
|
34
|
-
try {
|
|
35
|
-
await page.setViewport({ width, height })
|
|
36
|
-
await page.goto(url, { waitUntil: 'networkidle2' })
|
|
37
|
-
|
|
38
|
-
await page.screenshot({
|
|
39
|
-
path: outputPath,
|
|
40
|
-
fullPage,
|
|
41
|
-
type: format,
|
|
42
|
-
quality
|
|
43
|
-
})
|
|
44
|
-
} catch (error) {
|
|
45
|
-
console.error('Error taking screenshot:', error)
|
|
46
|
-
} finally {
|
|
47
|
-
await browser.close()
|
|
48
|
-
}
|
|
49
|
-
}
|