@checkly/playwright-core 1.48.24-beta.0 → 1.48.24-beta.1
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/lib/vite/recorder/assets/{codeMirrorModule-xqJWdfrS.js → codeMirrorModule-d0KhC1qL.js} +11 -11
- package/lib/vite/recorder/assets/{index-DDT9w7gI.js → index-Bxxcmxlu.js} +2 -2
- package/lib/vite/recorder/index.html +1 -1
- package/lib/vite/traceViewer/embedded.html +3 -3
- package/lib/vite/traceViewer/index.html +3 -3
- package/lib/vite/traceViewer/recorder.html +2 -2
- package/lib/vite/traceViewer/uiMode.html +3 -3
- package/package.json +1 -1
- package/lib/client/clientStackTrace.js +0 -65
- package/lib/client/fileUtils.js +0 -31
- package/lib/client/platform.js +0 -71
- package/lib/client/timeoutSettings.js +0 -65
- package/lib/client/webSocket.js +0 -106
- package/lib/server/callLog.js +0 -79
- package/lib/server/harBackend.js +0 -157
- package/lib/server/localUtils.js +0 -203
- package/lib/server/recorder/chat.js +0 -177
- package/lib/server/storageScript.js +0 -160
- package/lib/server/timeoutSettings.js +0 -74
- package/lib/server/utils/ascii.js +0 -31
- package/lib/server/utils/comparators.js +0 -159
- package/lib/server/utils/crypto.js +0 -171
- package/lib/server/utils/debug.js +0 -38
- package/lib/server/utils/debugLogger.js +0 -93
- package/lib/server/utils/env.js +0 -53
- package/lib/server/utils/eventsHelper.js +0 -38
- package/lib/server/utils/expectUtils.js +0 -33
- package/lib/server/utils/fileUtils.js +0 -204
- package/lib/server/utils/happyEyeballs.js +0 -209
- package/lib/server/utils/hostPlatform.js +0 -145
- package/lib/server/utils/httpServer.js +0 -233
- package/lib/server/utils/image_tools/colorUtils.js +0 -98
- package/lib/server/utils/image_tools/compare.js +0 -108
- package/lib/server/utils/image_tools/imageChannel.js +0 -70
- package/lib/server/utils/image_tools/stats.js +0 -102
- package/lib/server/utils/linuxUtils.js +0 -58
- package/lib/server/utils/network.js +0 -160
- package/lib/server/utils/nodePlatform.js +0 -140
- package/lib/server/utils/pipeTransport.js +0 -82
- package/lib/server/utils/processLauncher.js +0 -248
- package/lib/server/utils/profiler.js +0 -52
- package/lib/server/utils/socksProxy.js +0 -570
- package/lib/server/utils/spawnAsync.js +0 -45
- package/lib/server/utils/task.js +0 -58
- package/lib/server/utils/userAgent.js +0 -91
- package/lib/server/utils/wsServer.js +0 -128
- package/lib/server/utils/zipFile.js +0 -75
- package/lib/server/utils/zones.js +0 -54
- package/lib/utils/isomorphic/ariaSnapshot.js +0 -392
- package/lib/utils/isomorphic/assert.js +0 -25
- package/lib/utils/isomorphic/colors.js +0 -65
- package/lib/utils/isomorphic/headers.js +0 -52
- package/lib/utils/isomorphic/manualPromise.js +0 -107
- package/lib/utils/isomorphic/multimap.js +0 -73
- package/lib/utils/isomorphic/rtti.js +0 -41
- package/lib/utils/isomorphic/semaphore.js +0 -51
- package/lib/utils/isomorphic/stackTrace.js +0 -169
- package/lib/utils/isomorphic/time.js +0 -25
- package/lib/utils/isomorphic/timeoutRunner.js +0 -66
- package/lib/utils/isomorphic/types.js +0 -5
- package/lib/utils.js +0 -447
|
@@ -1,233 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.HttpServer = void 0;
|
|
7
|
-
var _fs = _interopRequireDefault(require("fs"));
|
|
8
|
-
var _path = _interopRequireDefault(require("path"));
|
|
9
|
-
var _utilsBundle = require("../../utilsBundle");
|
|
10
|
-
var _crypto = require("./crypto");
|
|
11
|
-
var _assert = require("../../utils/isomorphic/assert");
|
|
12
|
-
var _manualPromise = require("../../utils/isomorphic/manualPromise");
|
|
13
|
-
var _network = require("./network");
|
|
14
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
15
|
-
/**
|
|
16
|
-
* Copyright (c) Microsoft Corporation.
|
|
17
|
-
*
|
|
18
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
19
|
-
* you may not use this file except in compliance with the License.
|
|
20
|
-
* You may obtain a copy of the License at
|
|
21
|
-
*
|
|
22
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
23
|
-
*
|
|
24
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
25
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
26
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
27
|
-
* See the License for the specific language governing permissions and
|
|
28
|
-
* limitations under the License.
|
|
29
|
-
*/
|
|
30
|
-
|
|
31
|
-
class HttpServer {
|
|
32
|
-
constructor() {
|
|
33
|
-
this._server = void 0;
|
|
34
|
-
this._urlPrefixPrecise = '';
|
|
35
|
-
this._urlPrefixHumanReadable = '';
|
|
36
|
-
this._port = 0;
|
|
37
|
-
this._started = false;
|
|
38
|
-
this._routes = [];
|
|
39
|
-
this._wsGuid = void 0;
|
|
40
|
-
this._server = (0, _network.createHttpServer)(this._onRequest.bind(this));
|
|
41
|
-
}
|
|
42
|
-
server() {
|
|
43
|
-
return this._server;
|
|
44
|
-
}
|
|
45
|
-
routePrefix(prefix, handler) {
|
|
46
|
-
this._routes.push({
|
|
47
|
-
prefix,
|
|
48
|
-
handler
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
routePath(path, handler) {
|
|
52
|
-
this._routes.push({
|
|
53
|
-
exact: path,
|
|
54
|
-
handler
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
port() {
|
|
58
|
-
return this._port;
|
|
59
|
-
}
|
|
60
|
-
async _tryStart(port, host) {
|
|
61
|
-
const errorPromise = new _manualPromise.ManualPromise();
|
|
62
|
-
const errorListener = error => errorPromise.reject(error);
|
|
63
|
-
this._server.on('error', errorListener);
|
|
64
|
-
try {
|
|
65
|
-
this._server.listen(port, host);
|
|
66
|
-
await Promise.race([new Promise(cb => this._server.once('listening', cb)), errorPromise]);
|
|
67
|
-
} finally {
|
|
68
|
-
this._server.removeListener('error', errorListener);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
createWebSocket(transport, guid) {
|
|
72
|
-
(0, _assert.assert)(!this._wsGuid, 'can only create one main websocket transport per server');
|
|
73
|
-
this._wsGuid = guid || (0, _crypto.createGuid)();
|
|
74
|
-
const wss = new _utilsBundle.wsServer({
|
|
75
|
-
server: this._server,
|
|
76
|
-
path: '/' + this._wsGuid
|
|
77
|
-
});
|
|
78
|
-
wss.on('connection', ws => {
|
|
79
|
-
transport.onconnect();
|
|
80
|
-
transport.sendEvent = (method, params) => ws.send(JSON.stringify({
|
|
81
|
-
method,
|
|
82
|
-
params
|
|
83
|
-
}));
|
|
84
|
-
transport.close = () => ws.close();
|
|
85
|
-
ws.on('message', async message => {
|
|
86
|
-
const {
|
|
87
|
-
id,
|
|
88
|
-
method,
|
|
89
|
-
params
|
|
90
|
-
} = JSON.parse(String(message));
|
|
91
|
-
try {
|
|
92
|
-
const result = await transport.dispatch(method, params);
|
|
93
|
-
ws.send(JSON.stringify({
|
|
94
|
-
id,
|
|
95
|
-
result
|
|
96
|
-
}));
|
|
97
|
-
} catch (e) {
|
|
98
|
-
ws.send(JSON.stringify({
|
|
99
|
-
id,
|
|
100
|
-
error: String(e)
|
|
101
|
-
}));
|
|
102
|
-
}
|
|
103
|
-
});
|
|
104
|
-
ws.on('close', () => transport.onclose());
|
|
105
|
-
ws.on('error', () => transport.onclose());
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
wsGuid() {
|
|
109
|
-
return this._wsGuid;
|
|
110
|
-
}
|
|
111
|
-
async start(options = {}) {
|
|
112
|
-
(0, _assert.assert)(!this._started, 'server already started');
|
|
113
|
-
this._started = true;
|
|
114
|
-
const host = options.host || 'localhost';
|
|
115
|
-
if (options.preferredPort) {
|
|
116
|
-
try {
|
|
117
|
-
await this._tryStart(options.preferredPort, host);
|
|
118
|
-
} catch (e) {
|
|
119
|
-
if (!e || !e.message || !e.message.includes('EADDRINUSE')) throw e;
|
|
120
|
-
await this._tryStart(undefined, host);
|
|
121
|
-
}
|
|
122
|
-
} else {
|
|
123
|
-
await this._tryStart(options.port, host);
|
|
124
|
-
}
|
|
125
|
-
const address = this._server.address();
|
|
126
|
-
(0, _assert.assert)(address, 'Could not bind server socket');
|
|
127
|
-
if (typeof address === 'string') {
|
|
128
|
-
this._urlPrefixPrecise = address;
|
|
129
|
-
this._urlPrefixHumanReadable = address;
|
|
130
|
-
} else {
|
|
131
|
-
this._port = address.port;
|
|
132
|
-
const resolvedHost = address.family === 'IPv4' ? address.address : `[${address.address}]`;
|
|
133
|
-
this._urlPrefixPrecise = `http://${resolvedHost}:${address.port}`;
|
|
134
|
-
this._urlPrefixHumanReadable = `http://${host}:${address.port}`;
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
async stop() {
|
|
138
|
-
await new Promise(cb => this._server.close(cb));
|
|
139
|
-
}
|
|
140
|
-
urlPrefix(purpose) {
|
|
141
|
-
return purpose === 'human-readable' ? this._urlPrefixHumanReadable : this._urlPrefixPrecise;
|
|
142
|
-
}
|
|
143
|
-
serveFile(request, response, absoluteFilePath, headers) {
|
|
144
|
-
try {
|
|
145
|
-
for (const [name, value] of Object.entries(headers || {})) response.setHeader(name, value);
|
|
146
|
-
if (request.headers.range) this._serveRangeFile(request, response, absoluteFilePath);else this._serveFile(response, absoluteFilePath);
|
|
147
|
-
return true;
|
|
148
|
-
} catch (e) {
|
|
149
|
-
return false;
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
_serveFile(response, absoluteFilePath) {
|
|
153
|
-
const content = _fs.default.readFileSync(absoluteFilePath);
|
|
154
|
-
response.statusCode = 200;
|
|
155
|
-
const contentType = _utilsBundle.mime.getType(_path.default.extname(absoluteFilePath)) || 'application/octet-stream';
|
|
156
|
-
response.setHeader('Content-Type', contentType);
|
|
157
|
-
response.setHeader('Content-Length', content.byteLength);
|
|
158
|
-
response.end(content);
|
|
159
|
-
}
|
|
160
|
-
_serveRangeFile(request, response, absoluteFilePath) {
|
|
161
|
-
const range = request.headers.range;
|
|
162
|
-
if (!range || !range.startsWith('bytes=') || range.includes(', ') || [...range].filter(char => char === '-').length !== 1) {
|
|
163
|
-
response.statusCode = 400;
|
|
164
|
-
return response.end('Bad request');
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
// Parse the range header: https://datatracker.ietf.org/doc/html/rfc7233#section-2.1
|
|
168
|
-
const [startStr, endStr] = range.replace(/bytes=/, '').split('-');
|
|
169
|
-
|
|
170
|
-
// Both start and end (when passing to fs.createReadStream) and the range header are inclusive and start counting at 0.
|
|
171
|
-
let start;
|
|
172
|
-
let end;
|
|
173
|
-
const size = _fs.default.statSync(absoluteFilePath).size;
|
|
174
|
-
if (startStr !== '' && endStr === '') {
|
|
175
|
-
// No end specified: use the whole file
|
|
176
|
-
start = +startStr;
|
|
177
|
-
end = size - 1;
|
|
178
|
-
} else if (startStr === '' && endStr !== '') {
|
|
179
|
-
// No start specified: calculate start manually
|
|
180
|
-
start = size - +endStr;
|
|
181
|
-
end = size - 1;
|
|
182
|
-
} else {
|
|
183
|
-
start = +startStr;
|
|
184
|
-
end = +endStr;
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
// Handle unavailable range request
|
|
188
|
-
if (Number.isNaN(start) || Number.isNaN(end) || start >= size || end >= size || start > end) {
|
|
189
|
-
// Return the 416 Range Not Satisfiable: https://datatracker.ietf.org/doc/html/rfc7233#section-4.4
|
|
190
|
-
response.writeHead(416, {
|
|
191
|
-
'Content-Range': `bytes */${size}`
|
|
192
|
-
});
|
|
193
|
-
return response.end();
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
// Sending Partial Content: https://datatracker.ietf.org/doc/html/rfc7233#section-4.1
|
|
197
|
-
response.writeHead(206, {
|
|
198
|
-
'Content-Range': `bytes ${start}-${end}/${size}`,
|
|
199
|
-
'Accept-Ranges': 'bytes',
|
|
200
|
-
'Content-Length': end - start + 1,
|
|
201
|
-
'Content-Type': _utilsBundle.mime.getType(_path.default.extname(absoluteFilePath))
|
|
202
|
-
});
|
|
203
|
-
const readable = _fs.default.createReadStream(absoluteFilePath, {
|
|
204
|
-
start,
|
|
205
|
-
end
|
|
206
|
-
});
|
|
207
|
-
readable.pipe(response);
|
|
208
|
-
}
|
|
209
|
-
_onRequest(request, response) {
|
|
210
|
-
if (request.method === 'OPTIONS') {
|
|
211
|
-
response.writeHead(200);
|
|
212
|
-
response.end();
|
|
213
|
-
return;
|
|
214
|
-
}
|
|
215
|
-
request.on('error', () => response.end());
|
|
216
|
-
try {
|
|
217
|
-
if (!request.url) {
|
|
218
|
-
response.end();
|
|
219
|
-
return;
|
|
220
|
-
}
|
|
221
|
-
const url = new URL('http://localhost' + request.url);
|
|
222
|
-
for (const route of this._routes) {
|
|
223
|
-
if (route.exact && url.pathname === route.exact && route.handler(request, response)) return;
|
|
224
|
-
if (route.prefix && url.pathname.startsWith(route.prefix) && route.handler(request, response)) return;
|
|
225
|
-
}
|
|
226
|
-
response.statusCode = 404;
|
|
227
|
-
response.end();
|
|
228
|
-
} catch (e) {
|
|
229
|
-
response.end();
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
exports.HttpServer = HttpServer;
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.blendWithWhite = blendWithWhite;
|
|
7
|
-
exports.colorDeltaE94 = colorDeltaE94;
|
|
8
|
-
exports.rgb2gray = rgb2gray;
|
|
9
|
-
exports.srgb2xyz = srgb2xyz;
|
|
10
|
-
exports.xyz2lab = xyz2lab;
|
|
11
|
-
/**
|
|
12
|
-
* Copyright (c) Microsoft Corporation.
|
|
13
|
-
*
|
|
14
|
-
* Licensed under the Apache License, Version 2.0 (the 'License");
|
|
15
|
-
* you may not use this file except in compliance with the License.
|
|
16
|
-
* You may obtain a copy of the License at
|
|
17
|
-
*
|
|
18
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
19
|
-
*
|
|
20
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
21
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
22
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
23
|
-
* See the License for the specific language governing permissions and
|
|
24
|
-
* limitations under the License.
|
|
25
|
-
*/
|
|
26
|
-
|
|
27
|
-
function blendWithWhite(c, a) {
|
|
28
|
-
return 255 + (c - 255) * a;
|
|
29
|
-
}
|
|
30
|
-
function rgb2gray(r, g, b) {
|
|
31
|
-
// NOTE: this is the exact integer formula from SSIM.js.
|
|
32
|
-
// See https://github.com/obartra/ssim/blob/ca8e3c6a6ff5f4f2e232239e0c3d91806f3c97d5/src/matlab/rgb2gray.ts#L56
|
|
33
|
-
return 77 * r + 150 * g + 29 * b + 128 >> 8;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// Perceived color difference defined by CIE94.
|
|
37
|
-
// See https://en.wikipedia.org/wiki/Color_difference#CIE94
|
|
38
|
-
//
|
|
39
|
-
// The result of 1.0 is a "just-noticeable difference".
|
|
40
|
-
//
|
|
41
|
-
// Other results interpretation (taken from http://zschuessler.github.io/DeltaE/learn/):
|
|
42
|
-
// < 1.0 Not perceptible by human eyes.
|
|
43
|
-
// 1-2 Perceptible through close observation.
|
|
44
|
-
// 2-10 Perceptible at a glance.
|
|
45
|
-
// 11-49 Colors are more similar than opposite
|
|
46
|
-
// 100 Colors are exact opposite
|
|
47
|
-
function colorDeltaE94(rgb1, rgb2) {
|
|
48
|
-
const [l1, a1, b1] = xyz2lab(srgb2xyz(rgb1));
|
|
49
|
-
const [l2, a2, b2] = xyz2lab(srgb2xyz(rgb2));
|
|
50
|
-
const deltaL = l1 - l2;
|
|
51
|
-
const deltaA = a1 - a2;
|
|
52
|
-
const deltaB = b1 - b2;
|
|
53
|
-
const c1 = Math.sqrt(a1 ** 2 + b1 ** 2);
|
|
54
|
-
const c2 = Math.sqrt(a2 ** 2 + b2 ** 2);
|
|
55
|
-
const deltaC = c1 - c2;
|
|
56
|
-
let deltaH = deltaA ** 2 + deltaB ** 2 - deltaC ** 2;
|
|
57
|
-
deltaH = deltaH < 0 ? 0 : Math.sqrt(deltaH);
|
|
58
|
-
// The k1, k2, kL, kC, kH values for "graphic arts" applications.
|
|
59
|
-
// See https://en.wikipedia.org/wiki/Color_difference#CIE94
|
|
60
|
-
const k1 = 0.045;
|
|
61
|
-
const k2 = 0.015;
|
|
62
|
-
const kL = 1;
|
|
63
|
-
const kC = 1;
|
|
64
|
-
const kH = 1;
|
|
65
|
-
const sC = 1.0 + k1 * c1;
|
|
66
|
-
const sH = 1.0 + k2 * c1;
|
|
67
|
-
const sL = 1;
|
|
68
|
-
return Math.sqrt((deltaL / sL / kL) ** 2 + (deltaC / sC / kC) ** 2 + (deltaH / sH / kH) ** 2);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
// sRGB -> 1-normalized XYZ (i.e. Y ∈ [0, 1]) with D65 illuminant
|
|
72
|
-
// See https://en.wikipedia.org/wiki/SRGB#From_sRGB_to_CIE_XYZ
|
|
73
|
-
function srgb2xyz(rgb) {
|
|
74
|
-
let r = rgb[0] / 255;
|
|
75
|
-
let g = rgb[1] / 255;
|
|
76
|
-
let b = rgb[2] / 255;
|
|
77
|
-
r = r > 0.04045 ? Math.pow((r + 0.055) / 1.055, 2.4) : r / 12.92;
|
|
78
|
-
g = g > 0.04045 ? Math.pow((g + 0.055) / 1.055, 2.4) : g / 12.92;
|
|
79
|
-
b = b > 0.04045 ? Math.pow((b + 0.055) / 1.055, 2.4) : b / 12.92;
|
|
80
|
-
return [r * 0.4124 + g * 0.3576 + b * 0.1805, r * 0.2126 + g * 0.7152 + b * 0.0722, r * 0.0193 + g * 0.1192 + b * 0.9505];
|
|
81
|
-
}
|
|
82
|
-
const sigma_pow2 = 6 * 6 / 29 / 29;
|
|
83
|
-
const sigma_pow3 = 6 * 6 * 6 / 29 / 29 / 29;
|
|
84
|
-
|
|
85
|
-
// 1-normalized CIE XYZ with D65 to L*a*b*
|
|
86
|
-
// See https://en.wikipedia.org/wiki/CIELAB_color_space#From_CIEXYZ_to_CIELAB
|
|
87
|
-
function xyz2lab(xyz) {
|
|
88
|
-
const x = xyz[0] / 0.950489;
|
|
89
|
-
const y = xyz[1];
|
|
90
|
-
const z = xyz[2] / 1.088840;
|
|
91
|
-
const fx = x > sigma_pow3 ? x ** (1 / 3) : x / 3 / sigma_pow2 + 4 / 29;
|
|
92
|
-
const fy = y > sigma_pow3 ? y ** (1 / 3) : y / 3 / sigma_pow2 + 4 / 29;
|
|
93
|
-
const fz = z > sigma_pow3 ? z ** (1 / 3) : z / 3 / sigma_pow2 + 4 / 29;
|
|
94
|
-
const l = 116 * fy - 16;
|
|
95
|
-
const a = 500 * (fx - fy);
|
|
96
|
-
const b = 200 * (fy - fz);
|
|
97
|
-
return [l, a, b];
|
|
98
|
-
}
|
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.compare = compare;
|
|
7
|
-
var _colorUtils = require("./colorUtils");
|
|
8
|
-
var _imageChannel = require("./imageChannel");
|
|
9
|
-
var _stats = require("./stats");
|
|
10
|
-
/**
|
|
11
|
-
* Copyright (c) Microsoft Corporation.
|
|
12
|
-
*
|
|
13
|
-
* Licensed under the Apache License, Version 2.0 (the 'License");
|
|
14
|
-
* you may not use this file except in compliance with the License.
|
|
15
|
-
* You may obtain a copy of the License at
|
|
16
|
-
*
|
|
17
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
18
|
-
*
|
|
19
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
20
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
21
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
22
|
-
* See the License for the specific language governing permissions and
|
|
23
|
-
* limitations under the License.
|
|
24
|
-
*/
|
|
25
|
-
|
|
26
|
-
const SSIM_WINDOW_RADIUS = 15;
|
|
27
|
-
const VARIANCE_WINDOW_RADIUS = 1;
|
|
28
|
-
function drawPixel(width, data, x, y, r, g, b) {
|
|
29
|
-
const idx = (y * width + x) * 4;
|
|
30
|
-
data[idx + 0] = r;
|
|
31
|
-
data[idx + 1] = g;
|
|
32
|
-
data[idx + 2] = b;
|
|
33
|
-
data[idx + 3] = 255;
|
|
34
|
-
}
|
|
35
|
-
function compare(actual, expected, diff, width, height, options = {}) {
|
|
36
|
-
const {
|
|
37
|
-
maxColorDeltaE94 = 1.0
|
|
38
|
-
} = options;
|
|
39
|
-
const paddingSize = Math.max(VARIANCE_WINDOW_RADIUS, SSIM_WINDOW_RADIUS);
|
|
40
|
-
const paddingColorEven = [255, 0, 255];
|
|
41
|
-
const paddingColorOdd = [0, 255, 0];
|
|
42
|
-
const [r1, g1, b1] = _imageChannel.ImageChannel.intoRGB(width, height, expected, {
|
|
43
|
-
paddingSize,
|
|
44
|
-
paddingColorEven,
|
|
45
|
-
paddingColorOdd
|
|
46
|
-
});
|
|
47
|
-
const [r2, g2, b2] = _imageChannel.ImageChannel.intoRGB(width, height, actual, {
|
|
48
|
-
paddingSize,
|
|
49
|
-
paddingColorEven,
|
|
50
|
-
paddingColorOdd
|
|
51
|
-
});
|
|
52
|
-
const noop = (x, y) => {};
|
|
53
|
-
const drawRedPixel = diff ? (x, y) => drawPixel(width, diff, x - paddingSize, y - paddingSize, 255, 0, 0) : noop;
|
|
54
|
-
const drawYellowPixel = diff ? (x, y) => drawPixel(width, diff, x - paddingSize, y - paddingSize, 255, 255, 0) : noop;
|
|
55
|
-
const drawGrayPixel = diff ? (x, y) => {
|
|
56
|
-
const gray = (0, _colorUtils.rgb2gray)(r1.get(x, y), g1.get(x, y), b1.get(x, y));
|
|
57
|
-
const value = (0, _colorUtils.blendWithWhite)(gray, 0.1);
|
|
58
|
-
drawPixel(width, diff, x - paddingSize, y - paddingSize, value, value, value);
|
|
59
|
-
} : noop;
|
|
60
|
-
let fastR, fastG, fastB;
|
|
61
|
-
let diffCount = 0;
|
|
62
|
-
for (let y = paddingSize; y < r1.height - paddingSize; ++y) {
|
|
63
|
-
for (let x = paddingSize; x < r1.width - paddingSize; ++x) {
|
|
64
|
-
// Fast-path: equal pixels.
|
|
65
|
-
if (r1.get(x, y) === r2.get(x, y) && g1.get(x, y) === g2.get(x, y) && b1.get(x, y) === b2.get(x, y)) {
|
|
66
|
-
drawGrayPixel(x, y);
|
|
67
|
-
continue;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
// Compare pixel colors using the dE94 color difference formulae.
|
|
71
|
-
// The dE94 is normalized so that the value of 1.0 is the "just-noticeable-difference".
|
|
72
|
-
// Color difference below 1.0 is not noticeable to a human eye, so we can disregard it.
|
|
73
|
-
// See https://en.wikipedia.org/wiki/Color_difference
|
|
74
|
-
const delta = (0, _colorUtils.colorDeltaE94)([r1.get(x, y), g1.get(x, y), b1.get(x, y)], [r2.get(x, y), g2.get(x, y), b2.get(x, y)]);
|
|
75
|
-
if (delta <= maxColorDeltaE94) {
|
|
76
|
-
drawGrayPixel(x, y);
|
|
77
|
-
continue;
|
|
78
|
-
}
|
|
79
|
-
if (!fastR || !fastG || !fastB) {
|
|
80
|
-
fastR = new _stats.FastStats(r1, r2);
|
|
81
|
-
fastG = new _stats.FastStats(g1, g2);
|
|
82
|
-
fastB = new _stats.FastStats(b1, b2);
|
|
83
|
-
}
|
|
84
|
-
const [varX1, varY1] = r1.boundXY(x - VARIANCE_WINDOW_RADIUS, y - VARIANCE_WINDOW_RADIUS);
|
|
85
|
-
const [varX2, varY2] = r1.boundXY(x + VARIANCE_WINDOW_RADIUS, y + VARIANCE_WINDOW_RADIUS);
|
|
86
|
-
const var1 = fastR.varianceC1(varX1, varY1, varX2, varY2) + fastG.varianceC1(varX1, varY1, varX2, varY2) + fastB.varianceC1(varX1, varY1, varX2, varY2);
|
|
87
|
-
const var2 = fastR.varianceC2(varX1, varY1, varX2, varY2) + fastG.varianceC2(varX1, varY1, varX2, varY2) + fastB.varianceC2(varX1, varY1, varX2, varY2);
|
|
88
|
-
// if this pixel is a part of a flood fill of a 3x3 square of either of the images, then it cannot be
|
|
89
|
-
// anti-aliasing pixel so it must be a pixel difference.
|
|
90
|
-
if (var1 === 0 || var2 === 0) {
|
|
91
|
-
drawRedPixel(x, y);
|
|
92
|
-
++diffCount;
|
|
93
|
-
continue;
|
|
94
|
-
}
|
|
95
|
-
const [ssimX1, ssimY1] = r1.boundXY(x - SSIM_WINDOW_RADIUS, y - SSIM_WINDOW_RADIUS);
|
|
96
|
-
const [ssimX2, ssimY2] = r1.boundXY(x + SSIM_WINDOW_RADIUS, y + SSIM_WINDOW_RADIUS);
|
|
97
|
-
const ssimRGB = ((0, _stats.ssim)(fastR, ssimX1, ssimY1, ssimX2, ssimY2) + (0, _stats.ssim)(fastG, ssimX1, ssimY1, ssimX2, ssimY2) + (0, _stats.ssim)(fastB, ssimX1, ssimY1, ssimX2, ssimY2)) / 3.0;
|
|
98
|
-
const isAntialiased = ssimRGB >= 0.99;
|
|
99
|
-
if (isAntialiased) {
|
|
100
|
-
drawYellowPixel(x, y);
|
|
101
|
-
} else {
|
|
102
|
-
drawRedPixel(x, y);
|
|
103
|
-
++diffCount;
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
return diffCount;
|
|
108
|
-
}
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.ImageChannel = void 0;
|
|
7
|
-
var _colorUtils = require("./colorUtils");
|
|
8
|
-
/**
|
|
9
|
-
* Copyright (c) Microsoft Corporation.
|
|
10
|
-
*
|
|
11
|
-
* Licensed under the Apache License, Version 2.0 (the 'License");
|
|
12
|
-
* you may not use this file except in compliance with the License.
|
|
13
|
-
* You may obtain a copy of the License at
|
|
14
|
-
*
|
|
15
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
16
|
-
*
|
|
17
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
18
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
19
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
20
|
-
* See the License for the specific language governing permissions and
|
|
21
|
-
* limitations under the License.
|
|
22
|
-
*/
|
|
23
|
-
|
|
24
|
-
class ImageChannel {
|
|
25
|
-
static intoRGB(width, height, data, options = {}) {
|
|
26
|
-
const {
|
|
27
|
-
paddingSize = 0,
|
|
28
|
-
paddingColorOdd = [255, 0, 255],
|
|
29
|
-
paddingColorEven = [0, 255, 0]
|
|
30
|
-
} = options;
|
|
31
|
-
const newWidth = width + 2 * paddingSize;
|
|
32
|
-
const newHeight = height + 2 * paddingSize;
|
|
33
|
-
const r = new Uint8Array(newWidth * newHeight);
|
|
34
|
-
const g = new Uint8Array(newWidth * newHeight);
|
|
35
|
-
const b = new Uint8Array(newWidth * newHeight);
|
|
36
|
-
for (let y = 0; y < newHeight; ++y) {
|
|
37
|
-
for (let x = 0; x < newWidth; ++x) {
|
|
38
|
-
const index = y * newWidth + x;
|
|
39
|
-
if (y >= paddingSize && y < newHeight - paddingSize && x >= paddingSize && x < newWidth - paddingSize) {
|
|
40
|
-
const offset = ((y - paddingSize) * width + (x - paddingSize)) * 4;
|
|
41
|
-
const alpha = data[offset + 3] === 255 ? 1 : data[offset + 3] / 255;
|
|
42
|
-
r[index] = (0, _colorUtils.blendWithWhite)(data[offset], alpha);
|
|
43
|
-
g[index] = (0, _colorUtils.blendWithWhite)(data[offset + 1], alpha);
|
|
44
|
-
b[index] = (0, _colorUtils.blendWithWhite)(data[offset + 2], alpha);
|
|
45
|
-
} else {
|
|
46
|
-
const color = (y + x) % 2 === 0 ? paddingColorEven : paddingColorOdd;
|
|
47
|
-
r[index] = color[0];
|
|
48
|
-
g[index] = color[1];
|
|
49
|
-
b[index] = color[2];
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
return [new ImageChannel(newWidth, newHeight, r), new ImageChannel(newWidth, newHeight, g), new ImageChannel(newWidth, newHeight, b)];
|
|
54
|
-
}
|
|
55
|
-
constructor(width, height, data) {
|
|
56
|
-
this.data = void 0;
|
|
57
|
-
this.width = void 0;
|
|
58
|
-
this.height = void 0;
|
|
59
|
-
this.data = data;
|
|
60
|
-
this.width = width;
|
|
61
|
-
this.height = height;
|
|
62
|
-
}
|
|
63
|
-
get(x, y) {
|
|
64
|
-
return this.data[y * this.width + x];
|
|
65
|
-
}
|
|
66
|
-
boundXY(x, y) {
|
|
67
|
-
return [Math.min(Math.max(x, 0), this.width - 1), Math.min(Math.max(y, 0), this.height - 1)];
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
exports.ImageChannel = ImageChannel;
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.FastStats = void 0;
|
|
7
|
-
exports.ssim = ssim;
|
|
8
|
-
/**
|
|
9
|
-
* Copyright (c) Microsoft Corporation.
|
|
10
|
-
*
|
|
11
|
-
* Licensed under the Apache License, Version 2.0 (the 'License");
|
|
12
|
-
* you may not use this file except in compliance with the License.
|
|
13
|
-
* You may obtain a copy of the License at
|
|
14
|
-
*
|
|
15
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
16
|
-
*
|
|
17
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
18
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
19
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
20
|
-
* See the License for the specific language governing permissions and
|
|
21
|
-
* limitations under the License.
|
|
22
|
-
*/
|
|
23
|
-
|
|
24
|
-
// Image channel has a 8-bit depth.
|
|
25
|
-
const DYNAMIC_RANGE = 2 ** 8 - 1;
|
|
26
|
-
function ssim(stats, x1, y1, x2, y2) {
|
|
27
|
-
const mean1 = stats.meanC1(x1, y1, x2, y2);
|
|
28
|
-
const mean2 = stats.meanC2(x1, y1, x2, y2);
|
|
29
|
-
const var1 = stats.varianceC1(x1, y1, x2, y2);
|
|
30
|
-
const var2 = stats.varianceC2(x1, y1, x2, y2);
|
|
31
|
-
const cov = stats.covariance(x1, y1, x2, y2);
|
|
32
|
-
const c1 = (0.01 * DYNAMIC_RANGE) ** 2;
|
|
33
|
-
const c2 = (0.03 * DYNAMIC_RANGE) ** 2;
|
|
34
|
-
return (2 * mean1 * mean2 + c1) * (2 * cov + c2) / (mean1 ** 2 + mean2 ** 2 + c1) / (var1 + var2 + c2);
|
|
35
|
-
}
|
|
36
|
-
class FastStats {
|
|
37
|
-
constructor(c1, c2) {
|
|
38
|
-
this.c1 = void 0;
|
|
39
|
-
this.c2 = void 0;
|
|
40
|
-
this._partialSumC1 = void 0;
|
|
41
|
-
this._partialSumC2 = void 0;
|
|
42
|
-
this._partialSumMult = void 0;
|
|
43
|
-
this._partialSumSq1 = void 0;
|
|
44
|
-
this._partialSumSq2 = void 0;
|
|
45
|
-
this.c1 = c1;
|
|
46
|
-
this.c2 = c2;
|
|
47
|
-
const {
|
|
48
|
-
width,
|
|
49
|
-
height
|
|
50
|
-
} = c1;
|
|
51
|
-
this._partialSumC1 = new Array(width * height);
|
|
52
|
-
this._partialSumC2 = new Array(width * height);
|
|
53
|
-
this._partialSumSq1 = new Array(width * height);
|
|
54
|
-
this._partialSumSq2 = new Array(width * height);
|
|
55
|
-
this._partialSumMult = new Array(width * height);
|
|
56
|
-
const recalc = (mx, idx, initial, x, y) => {
|
|
57
|
-
mx[idx] = initial;
|
|
58
|
-
if (y > 0) mx[idx] += mx[(y - 1) * width + x];
|
|
59
|
-
if (x > 0) mx[idx] += mx[y * width + x - 1];
|
|
60
|
-
if (x > 0 && y > 0) mx[idx] -= mx[(y - 1) * width + x - 1];
|
|
61
|
-
};
|
|
62
|
-
for (let y = 0; y < height; ++y) {
|
|
63
|
-
for (let x = 0; x < width; ++x) {
|
|
64
|
-
const idx = y * width + x;
|
|
65
|
-
recalc(this._partialSumC1, idx, this.c1.data[idx], x, y);
|
|
66
|
-
recalc(this._partialSumC2, idx, this.c2.data[idx], x, y);
|
|
67
|
-
recalc(this._partialSumSq1, idx, this.c1.data[idx] * this.c1.data[idx], x, y);
|
|
68
|
-
recalc(this._partialSumSq2, idx, this.c2.data[idx] * this.c2.data[idx], x, y);
|
|
69
|
-
recalc(this._partialSumMult, idx, this.c1.data[idx] * this.c2.data[idx], x, y);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
_sum(partialSum, x1, y1, x2, y2) {
|
|
74
|
-
const width = this.c1.width;
|
|
75
|
-
let result = partialSum[y2 * width + x2];
|
|
76
|
-
if (y1 > 0) result -= partialSum[(y1 - 1) * width + x2];
|
|
77
|
-
if (x1 > 0) result -= partialSum[y2 * width + x1 - 1];
|
|
78
|
-
if (x1 > 0 && y1 > 0) result += partialSum[(y1 - 1) * width + x1 - 1];
|
|
79
|
-
return result;
|
|
80
|
-
}
|
|
81
|
-
meanC1(x1, y1, x2, y2) {
|
|
82
|
-
const N = (y2 - y1 + 1) * (x2 - x1 + 1);
|
|
83
|
-
return this._sum(this._partialSumC1, x1, y1, x2, y2) / N;
|
|
84
|
-
}
|
|
85
|
-
meanC2(x1, y1, x2, y2) {
|
|
86
|
-
const N = (y2 - y1 + 1) * (x2 - x1 + 1);
|
|
87
|
-
return this._sum(this._partialSumC2, x1, y1, x2, y2) / N;
|
|
88
|
-
}
|
|
89
|
-
varianceC1(x1, y1, x2, y2) {
|
|
90
|
-
const N = (y2 - y1 + 1) * (x2 - x1 + 1);
|
|
91
|
-
return (this._sum(this._partialSumSq1, x1, y1, x2, y2) - this._sum(this._partialSumC1, x1, y1, x2, y2) ** 2 / N) / N;
|
|
92
|
-
}
|
|
93
|
-
varianceC2(x1, y1, x2, y2) {
|
|
94
|
-
const N = (y2 - y1 + 1) * (x2 - x1 + 1);
|
|
95
|
-
return (this._sum(this._partialSumSq2, x1, y1, x2, y2) - this._sum(this._partialSumC2, x1, y1, x2, y2) ** 2 / N) / N;
|
|
96
|
-
}
|
|
97
|
-
covariance(x1, y1, x2, y2) {
|
|
98
|
-
const N = (y2 - y1 + 1) * (x2 - x1 + 1);
|
|
99
|
-
return (this._sum(this._partialSumMult, x1, y1, x2, y2) - this._sum(this._partialSumC1, x1, y1, x2, y2) * this._sum(this._partialSumC2, x1, y1, x2, y2) / N) / N;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
exports.FastStats = FastStats;
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.getLinuxDistributionInfoSync = getLinuxDistributionInfoSync;
|
|
7
|
-
var _fs = _interopRequireDefault(require("fs"));
|
|
8
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
|
-
/**
|
|
10
|
-
* Copyright 2017 Google Inc. All rights reserved.
|
|
11
|
-
* Modifications copyright (c) Microsoft Corporation.
|
|
12
|
-
*
|
|
13
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
14
|
-
* you may not use this file except in compliance with the License.
|
|
15
|
-
* You may obtain a copy of the License at
|
|
16
|
-
*
|
|
17
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
18
|
-
*
|
|
19
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
20
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
21
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
22
|
-
* See the License for the specific language governing permissions and
|
|
23
|
-
* limitations under the License.
|
|
24
|
-
*/
|
|
25
|
-
|
|
26
|
-
let didFailToReadOSRelease = false;
|
|
27
|
-
let osRelease;
|
|
28
|
-
function getLinuxDistributionInfoSync() {
|
|
29
|
-
if (process.platform !== 'linux') return undefined;
|
|
30
|
-
if (!osRelease && !didFailToReadOSRelease) {
|
|
31
|
-
try {
|
|
32
|
-
var _fields$get, _fields$get2;
|
|
33
|
-
// List of /etc/os-release values for different distributions could be
|
|
34
|
-
// found here: https://gist.github.com/aslushnikov/8ceddb8288e4cf9db3039c02e0f4fb75
|
|
35
|
-
const osReleaseText = _fs.default.readFileSync('/etc/os-release', 'utf8');
|
|
36
|
-
const fields = parseOSReleaseText(osReleaseText);
|
|
37
|
-
osRelease = {
|
|
38
|
-
id: (_fields$get = fields.get('id')) !== null && _fields$get !== void 0 ? _fields$get : '',
|
|
39
|
-
version: (_fields$get2 = fields.get('version_id')) !== null && _fields$get2 !== void 0 ? _fields$get2 : ''
|
|
40
|
-
};
|
|
41
|
-
} catch (e) {
|
|
42
|
-
didFailToReadOSRelease = true;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
return osRelease;
|
|
46
|
-
}
|
|
47
|
-
function parseOSReleaseText(osReleaseText) {
|
|
48
|
-
const fields = new Map();
|
|
49
|
-
for (const line of osReleaseText.split('\n')) {
|
|
50
|
-
const tokens = line.split('=');
|
|
51
|
-
const name = tokens.shift();
|
|
52
|
-
let value = tokens.join('=').trim();
|
|
53
|
-
if (value.startsWith('"') && value.endsWith('"')) value = value.substring(1, value.length - 1);
|
|
54
|
-
if (!name) continue;
|
|
55
|
-
fields.set(name.toLowerCase(), value);
|
|
56
|
-
}
|
|
57
|
-
return fields;
|
|
58
|
-
}
|