jest-canvas-mock 2.1.0 → 2.1.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/CHANGELOG.md +4 -0
- package/lib/classes/ImageData.js +36 -8
- package/lib/index.js +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/lib/classes/ImageData.js
CHANGED
|
@@ -33,7 +33,7 @@ function () {
|
|
|
33
33
|
}
|
|
34
34
|
}]);
|
|
35
35
|
|
|
36
|
-
function ImageData(
|
|
36
|
+
function ImageData(arr, w, h) {
|
|
37
37
|
_classCallCheck(this, ImageData);
|
|
38
38
|
|
|
39
39
|
_defineProperty(this, "_width", 0);
|
|
@@ -42,13 +42,41 @@ function () {
|
|
|
42
42
|
|
|
43
43
|
_defineProperty(this, "_data", null);
|
|
44
44
|
|
|
45
|
-
if (
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
45
|
+
if (arguments.length === 2) {
|
|
46
|
+
if (arr instanceof Uint8ClampedArray) {
|
|
47
|
+
if (arr.length === 0) throw new RangeError('Source length must be a positive multiple of 4.');
|
|
48
|
+
if (arr.length % 4 !== 0) throw new RangeError('Source length must be a positive multiple of 4.');
|
|
49
|
+
if (!Number.isFinite(w)) throw new RangeError('The width is zero or not a number.');
|
|
50
|
+
if (w === 0) throw new RangeError('The width is zero or not a number.');
|
|
51
|
+
this._width = w;
|
|
52
|
+
this._height = arr.length / 4 / w;
|
|
53
|
+
this._data = arr;
|
|
54
|
+
} else {
|
|
55
|
+
var width = arr;
|
|
56
|
+
var height = w;
|
|
57
|
+
if (!Number.isFinite(height)) throw new RangeError('The height is zero or not a number.');
|
|
58
|
+
if (height === 0) throw new RangeError('The height is zero or not a number.');
|
|
59
|
+
if (!Number.isFinite(width)) throw new RangeError('The width is zero or not a number.');
|
|
60
|
+
if (width === 0) throw new RangeError('The width is zero or not a number.');
|
|
61
|
+
this._width = width;
|
|
62
|
+
this._height = height;
|
|
63
|
+
this._data = new Uint8ClampedArray(width * height * 4);
|
|
64
|
+
}
|
|
65
|
+
} else if (arguments.length === 3) {
|
|
66
|
+
if (!(arr instanceof Uint8ClampedArray)) throw new TypeError('First argument must be a Uint8ClampedArray when using 3 arguments.');
|
|
67
|
+
if (arr.length === 0) throw new RangeError('Source length must be a positive multiple of 4.');
|
|
68
|
+
if (arr.length % 4 !== 0) throw new RangeError('Source length must be a positive multiple of 4.');
|
|
69
|
+
if (!Number.isFinite(h)) throw new RangeError('The height is zero or not a number.');
|
|
70
|
+
if (h === 0) throw new RangeError('The height is zero or not a number.');
|
|
71
|
+
if (!Number.isFinite(w)) throw new RangeError('The width is zero or not a number.');
|
|
72
|
+
if (w === 0) throw new RangeError('The width is zero or not a number.');
|
|
73
|
+
if (arr.length !== w * h * 4) throw new RangeError('Source doesn\'n contain the exact number of pixels needed.');
|
|
74
|
+
this._width = w;
|
|
75
|
+
this._height = h;
|
|
76
|
+
this._data = arr;
|
|
77
|
+
} else {
|
|
78
|
+
throw new TypeError('Wrong number of arguments provided.');
|
|
79
|
+
}
|
|
52
80
|
}
|
|
53
81
|
|
|
54
82
|
return ImageData;
|
package/lib/index.js
CHANGED