@checkly/playwright-core 1.51.17-beta.1 → 1.51.17-beta.3

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.
Files changed (113) hide show
  1. package/lib/checkly/checklyFileSystem.js +44 -0
  2. package/lib/checkly/secretsFilter.js +5 -10
  3. package/lib/escapeRegExp.js +30 -0
  4. package/lib/generated/bindingsControllerSource.js +7 -0
  5. package/lib/generated/clockSource.js +1 -2
  6. package/lib/generated/consoleApiSource.js +1 -2
  7. package/lib/generated/injectedScriptSource.js +1 -2
  8. package/lib/generated/pollingRecorderSource.js +1 -2
  9. package/lib/generated/storageScriptSource.js +7 -0
  10. package/lib/generated/utilityScriptSource.js +1 -2
  11. package/lib/generated/webSocketMockSource.js +1 -2
  12. package/lib/secretsFilter.js +131 -0
  13. package/lib/server/bidi/third_party/bidiCommands.d.js +22 -0
  14. package/lib/server/bidi/third_party/bidiProtocolCore.js +152 -0
  15. package/lib/server/bidi/third_party/bidiProtocolPermissions.js +42 -0
  16. package/lib/server/chromium/protocol.d.js +16 -0
  17. package/lib/server/firefox/protocol.d.js +16 -0
  18. package/lib/server/har/harRecorder.js +4 -2
  19. package/lib/server/pageBinding.js +88 -0
  20. package/lib/server/recorder/recorderSignalProcessor.js +83 -0
  21. package/lib/server/registry/index.d.ts +86 -0
  22. package/lib/server/trace/recorder/tracing.js +9 -20
  23. package/lib/server/utils/fileUtils.js +65 -2
  24. package/lib/server/webkit/protocol.d.js +16 -0
  25. package/lib/utils/isomorphic/builtins.js +90 -0
  26. package/lib/utils/isomorphic/protocolFormatter.js +68 -0
  27. package/lib/utils/isomorphic/protocolMetainfo.js +321 -0
  28. package/lib/utils/isomorphic/utilityScriptSerializers.js +251 -0
  29. package/lib/vite/recorder/assets/codeMirrorModule-B9YMkrwa.js +24 -0
  30. package/lib/vite/recorder/assets/codeMirrorModule-C3UTv-Ge.css +1 -0
  31. package/lib/vite/recorder/assets/index-ELPgmkwA.js +184 -0
  32. package/lib/vite/recorder/assets/index-eHBmevrY.css +1 -0
  33. package/lib/vite/recorder/index.html +2 -2
  34. package/lib/vite/traceViewer/assets/codeMirrorModule-gU1OOCQO.js +24 -0
  35. package/lib/vite/traceViewer/assets/defaultSettingsView-B5n_FjMx.js +1 -0
  36. package/lib/vite/traceViewer/assets/inspectorTab-6Tru8Mn_.js +235 -0
  37. package/lib/vite/traceViewer/assets/workbench-B_Nj4NA2.js +25 -0
  38. package/lib/vite/traceViewer/assets/xtermModule-BoAIEibi.js +9 -0
  39. package/lib/vite/traceViewer/codeMirrorModule.C3UTv-Ge.css +1 -0
  40. package/lib/vite/traceViewer/defaultSettingsView.CO3FR0CX.css +1 -0
  41. package/lib/vite/traceViewer/embedded.DpNPH6mk.js +2 -0
  42. package/lib/vite/traceViewer/embedded.html +6 -6
  43. package/lib/vite/traceViewer/embedded.mLhjB5IF.css +1 -0
  44. package/lib/vite/traceViewer/index.CFOW-Ezb.css +1 -0
  45. package/lib/vite/traceViewer/index.CuE3SYGw.js +2 -0
  46. package/lib/vite/traceViewer/index.html +8 -8
  47. package/lib/vite/traceViewer/inspectorTab.CXDulcFG.css +1 -0
  48. package/lib/vite/traceViewer/recorder.BD-uZJs7.js +2 -0
  49. package/lib/vite/traceViewer/recorder.html +4 -4
  50. package/lib/vite/traceViewer/recorder.tn0RQdqM.css +0 -0
  51. package/lib/vite/traceViewer/uiMode.BatfzHMG.css +1 -0
  52. package/lib/vite/traceViewer/uiMode.DHrNgddz.js +5 -0
  53. package/lib/vite/traceViewer/uiMode.html +8 -8
  54. package/lib/vite/traceViewer/workbench.B9vIAzH9.css +1 -0
  55. package/lib/vite/traceViewer/xtermModule.Beg8tuEN.css +32 -0
  56. package/package.json +1 -1
  57. package/lib/common/socksProxy.js +0 -569
  58. package/lib/common/timeoutSettings.js +0 -73
  59. package/lib/common/types.js +0 -5
  60. package/lib/image_tools/colorUtils.js +0 -98
  61. package/lib/image_tools/compare.js +0 -108
  62. package/lib/image_tools/imageChannel.js +0 -70
  63. package/lib/image_tools/stats.js +0 -102
  64. package/lib/protocol/transport.js +0 -82
  65. package/lib/third_party/diff_match_patch.js +0 -2222
  66. package/lib/utils/ascii.js +0 -31
  67. package/lib/utils/comparators.js +0 -171
  68. package/lib/utils/crypto.js +0 -174
  69. package/lib/utils/debug.js +0 -46
  70. package/lib/utils/debugLogger.js +0 -91
  71. package/lib/utils/env.js +0 -49
  72. package/lib/utils/eventsHelper.js +0 -38
  73. package/lib/utils/happy-eyeballs.js +0 -210
  74. package/lib/utils/headers.js +0 -52
  75. package/lib/utils/hostPlatform.js +0 -133
  76. package/lib/utils/httpServer.js +0 -237
  77. package/lib/utils/linuxUtils.js +0 -78
  78. package/lib/utils/manualPromise.js +0 -109
  79. package/lib/utils/multimap.js +0 -75
  80. package/lib/utils/network.js +0 -160
  81. package/lib/utils/processLauncher.js +0 -248
  82. package/lib/utils/profiler.js +0 -53
  83. package/lib/utils/rtti.js +0 -44
  84. package/lib/utils/semaphore.js +0 -51
  85. package/lib/utils/spawnAsync.js +0 -45
  86. package/lib/utils/task.js +0 -58
  87. package/lib/utils/time.js +0 -37
  88. package/lib/utils/traceUtils.js +0 -44
  89. package/lib/utils/userAgent.js +0 -105
  90. package/lib/utils/wsServer.js +0 -127
  91. package/lib/utils/zipFile.js +0 -75
  92. package/lib/vite/recorder/assets/codeMirrorModule-DrMbgOIo.js +0 -16684
  93. package/lib/vite/recorder/assets/codeMirrorModule-DuST8d_k.css +0 -344
  94. package/lib/vite/recorder/assets/index-5NM3V7eb.css +0 -2524
  95. package/lib/vite/recorder/assets/index-CT-scFHn.js +0 -16848
  96. package/lib/vite/traceViewer/assets/codeMirrorModule-CB-2okZ8.js +0 -16684
  97. package/lib/vite/traceViewer/assets/defaultSettingsView-CBiB4avC.js +0 -217
  98. package/lib/vite/traceViewer/assets/inspectorTab-CwgfffWb.js +0 -25143
  99. package/lib/vite/traceViewer/assets/workbench-CWZselvp.js +0 -2470
  100. package/lib/vite/traceViewer/assets/xtermModule-Es_gt_u7.js +0 -5994
  101. package/lib/vite/traceViewer/codeMirrorModule.DuST8d_k.css +0 -344
  102. package/lib/vite/traceViewer/defaultSettingsView.Dp3b_92q.css +0 -41
  103. package/lib/vite/traceViewer/embedded.BeldSa2G.css +0 -68
  104. package/lib/vite/traceViewer/embedded.gzudoghF.js +0 -106
  105. package/lib/vite/traceViewer/index.DilotR1h.js +0 -314
  106. package/lib/vite/traceViewer/index.QewjJ85u.css +0 -131
  107. package/lib/vite/traceViewer/inspectorTab.DnGm18kV.css +0 -3178
  108. package/lib/vite/traceViewer/recorder.DLgqV9db.css +0 -15
  109. package/lib/vite/traceViewer/recorder.DVrkq3Um.js +0 -551
  110. package/lib/vite/traceViewer/uiMode.C9_OcpPU.js +0 -1756
  111. package/lib/vite/traceViewer/uiMode.c5ORgcrX.css +0 -1424
  112. package/lib/vite/traceViewer/workbench.xUZSA8PY.css +0 -787
  113. package/lib/vite/traceViewer/xtermModule.EsaqrrTX.css +0 -209
@@ -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,82 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.PipeTransport = void 0;
7
- var _utils = require("../utils");
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 PipeTransport {
25
- constructor(pipeWrite, pipeRead, closeable, endian = 'le') {
26
- this._pipeWrite = void 0;
27
- this._data = Buffer.from([]);
28
- this._waitForNextTask = (0, _utils.makeWaitForNextTask)();
29
- this._closed = false;
30
- this._bytesLeft = 0;
31
- this.onmessage = void 0;
32
- this.onclose = void 0;
33
- this._endian = void 0;
34
- this._closeableStream = void 0;
35
- this._pipeWrite = pipeWrite;
36
- this._endian = endian;
37
- this._closeableStream = closeable;
38
- pipeRead.on('data', buffer => this._dispatch(buffer));
39
- pipeRead.on('close', () => {
40
- this._closed = true;
41
- if (this.onclose) this.onclose();
42
- });
43
- this.onmessage = undefined;
44
- this.onclose = undefined;
45
- }
46
- send(message) {
47
- if (this._closed) throw new Error('Pipe has been closed');
48
- const data = Buffer.from(message, 'utf-8');
49
- const dataLength = Buffer.alloc(4);
50
- if (this._endian === 'be') dataLength.writeUInt32BE(data.length, 0);else dataLength.writeUInt32LE(data.length, 0);
51
- this._pipeWrite.write(dataLength);
52
- this._pipeWrite.write(data);
53
- }
54
- close() {
55
- // Let it throw.
56
- this._closeableStream.close();
57
- }
58
- _dispatch(buffer) {
59
- this._data = Buffer.concat([this._data, buffer]);
60
- while (true) {
61
- if (!this._bytesLeft && this._data.length < 4) {
62
- // Need more data.
63
- break;
64
- }
65
- if (!this._bytesLeft) {
66
- this._bytesLeft = this._endian === 'be' ? this._data.readUInt32BE(0) : this._data.readUInt32LE(0);
67
- this._data = this._data.slice(4);
68
- }
69
- if (!this._bytesLeft || this._data.length < this._bytesLeft) {
70
- // Need more data.
71
- break;
72
- }
73
- const message = this._data.slice(0, this._bytesLeft);
74
- this._data = this._data.slice(this._bytesLeft);
75
- this._bytesLeft = 0;
76
- this._waitForNextTask(() => {
77
- if (this.onmessage) this.onmessage(message.toString('utf-8'));
78
- });
79
- }
80
- }
81
- }
82
- exports.PipeTransport = PipeTransport;