-
Notifications
You must be signed in to change notification settings - Fork 54
/
index.d.ts
310 lines (291 loc) · 9.89 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
// Type definitions for looks-same 5.0
// Project: https://github.com/gemini-testing/looks-same/releases
// Definitions by: xcatliu <https://github.com/xcatliu>
/// <reference types="node"/>
// https://stackoverflow.com/questions/44058101/typescript-declare-third-party-modules
declare module looksSame {
/**
* coordinate bounds
*/
export interface CoordBounds {
/**
* X-coordinate of upper left corner
*/
left: number;
/**
* Y-coordinate of upper left corner
*/
top: number;
/**
* X-coordinate of bottom right corner
*/
right: number;
/**
* Y-coordinate of bottom right corner
*/
bottom: number;
}
/**
* bounded image
*/
export interface BoundedImage {
/**
* image path or buffer
*/
source: string | Buffer;
/**
* bounding coordinates
*/
boundingBox: CoordBounds;
}
export interface DiffImage {
/**
* Width of the diff image
*/
width: number;
/**
* Height of the diff image
*/
height: number;
/**
* Save the diff image
* Path should be specified with image extension
*/
save: (path: string) => Promise<void>;
/**
* Create buffer of the diff image
* If you need to save the image, consider using `save` method
* Shoud not be mixed with `save` method
*/
createBuffer: (extension: "png" | "raw") => Promise<Buffer>;
}
interface LooksSameBaseResult {
/**
* true if images are equal, false - otherwise
*/
equal: boolean;
/**
* diff bounds for not equal images
*/
diffBounds: CoordBounds;
/**
* diff clusters for not equal images
*/
diffClusters: CoordBounds[];
}
interface LooksSameCreateDiffImageResult extends LooksSameBaseResult {
differentPixels: number;
totalPixels: number;
}
interface LooksSameWithNoDiffResult extends LooksSameCreateDiffImageResult {
equal: true;
diffImage: null;
}
interface LooksSameWithExistingDiffResult extends LooksSameCreateDiffImageResult {
equal: false;
diffImage: DiffImage;
}
/**
* The result obtained from the function.
*/
export type LooksSameResult<T = false> = T extends true ? (LooksSameWithNoDiffResult | LooksSameWithExistingDiffResult) : LooksSameBaseResult;
/**
* The options passed to looksSame function
*/
export interface LooksSameOptions {
/**
* By default, it will detect only noticeable differences. If you wish to detect any difference, use strict options.
*/
strict?: boolean;
/**
* You can also adjust the ΔE value that will be treated as error in non-strict mode.
*/
tolerance?: number;
/**
* Some devices can have different proportion between physical and logical screen resolutions also known as pixel ratio.
* Default value for this proportion is 1.
* This param also affects the comparison result, so it can be set manually with pixelRatio option.
*/
pixelRatio?: number;
/**
* Text caret in text input elements it is a pain for visual regression tasks, because it is always blinks.
* These diffs will be ignored by default. You can use `ignoreCaret` option with `false` value to disable ignoring such diffs.
* In that way text caret will be marked as diffs.
*/
ignoreCaret?: boolean;
/**
* Some images has difference while comparing because of antialiasing.
* These diffs will be ignored by default. You can use ignoreAntialiasing option with false value to disable ignoring such diffs.
* In that way antialiased pixels will be marked as diffs.
*/
ignoreAntialiasing?: boolean;
/**
* Sometimes the antialiasing algorithm can work incorrectly due to some features of the browser rendering engine.
* Use the option antialiasingTolerance to make the algorithm less strict.
* With this option you can specify the minimum difference in brightness (zero by default)
* between the darkest/lightest pixel (which is adjacent to the antialiasing pixel) and theirs adjacent pixels.
*
* We recommend that you don't increase this value above 10. If you need to increase more than 10 then this is definitely not antialiasing.
*/
antialiasingTolerance?: number;
/**
* Responsible for diff area which will be returned when comparing images.
* Diff bounds will contain the whole diff if stopOnFirstFail is false and only first diff pixel - otherwise.
*/
stopOnFirstFail?: boolean;
/**
* Responsible for diff bounds clustering
*/
shouldCluster?: boolean;
/**
* Radius for every diff cluster
*/
clustersSize?: number;
/**
* If you need both to compare images and create diff image
*/
createDiffImage?: boolean
}
export interface GetDiffAreaOptions {
/**
* Strict comparsion
*/
strict?: boolean;
/**
* ΔE value that will be treated as error in non-strict mode
*/
tolerance?: number;
/**
* Some devices can have different proportion between physical and logical screen resolutions also known as pixel ratio.
*/
pixelRatio?: number;
/**
* Ability to ignore text caret
*/
ignoreCaret?: boolean;
/**
* Ability to ignore antialiasing
*/
ignoreAntialiasing?: boolean;
/**
* Makes the search algorithm of the antialiasing less strict
*/
antialiasingTolerance?: number;
/**
* Responsible for diff area which will be returned when comparing images.
*/
stopOnFirstFail?: boolean;
/**
* Responsible for diff bounds clustering
*/
shouldCluster?: boolean;
/**
* Radius for every diff cluster
*/
clustersSize?: number;
}
/**
* The options passed to looksSame.createDiff function without diff
*/
export interface CreateDiffAsBufferOptions {
/**
* The baseline image
*/
reference: string | Buffer | BoundedImage;
/**
* The current image
*/
current: string | Buffer | BoundedImage;
/**
* Color to highlight the differences
* e.g. '#ff00ff'
*/
highlightColor: string;
/**
* Strict comparsion
*/
strict?: boolean;
/**
* ΔE value that will be treated as error in non-strict mode
*/
tolerance?: number;
/**
* Makes the search algorithm of the antialiasing less strict
*/
antialiasingTolerance?: number;
/**
* Ability to ignore antialiasing
*/
ignoreAntialiasing?: boolean;
/**
* Ability to ignore text caret
*/
ignoreCaret?: boolean;
}
/**
* The options passed to looksSame.createDiff function
*/
export interface CreateDiffOptions extends CreateDiffAsBufferOptions {
/**
* The diff image path to store
*/
diff: string;
}
/**
* Pass to looksSame.colors function
*/
export interface Color {
/**
* Red
*/
R: number;
/**
* Green
*/
G: number;
/**
* Blue
*/
B: number;
}
export function getDiffArea(
image1: string | Buffer | BoundedImage,
image2: string | Buffer | BoundedImage
): Promise<CoordBounds | null>;
export function getDiffArea(
image1: string | Buffer | BoundedImage,
image2: string | Buffer | BoundedImage,
opts: GetDiffAreaOptions
): Promise<CoordBounds | null>;
export function createDiff(options: CreateDiffOptions): Promise<null>;
export function createDiff(options: CreateDiffAsBufferOptions): Promise<Buffer>;
/**
* Compare two colors
* @param color1 The first color
* @param color2 The second color
* @param options The options passed to looksSame.colors function
*/
export function colors(color1: Color, color2: Color): boolean;
export function colors(color1: Color, color2: Color, options: { tolerance: number }): boolean;
}
/**
* Compare two images with options
* @param image1 The first image
* @param image2 The second image
* @param options The options passed to looksSame function
*/
declare function looksSame(
image1: string | Buffer | looksSame.BoundedImage,
image2: string | Buffer | looksSame.BoundedImage,
options?: looksSame.LooksSameOptions & { createDiffImage?: false },
): Promise<looksSame.LooksSameResult<false>>;
declare function looksSame(
image1: string | Buffer | looksSame.BoundedImage,
image2: string | Buffer | looksSame.BoundedImage,
options: looksSame.LooksSameOptions & { createDiffImage: true },
): Promise<looksSame.LooksSameResult<true>>;
/**
* Node.js library for comparing PNG-images, taking into account human color perception.
* It is created specially for the needs of visual regression testing for gemini utility, but can be used for other purposes.
*/
export = looksSame;