jest-canvas-mock 2.3.1 → 2.4.0
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 +9 -0
- package/README.md +3 -1
- package/lib/classes/DOMMatrix.js +92 -0
- package/lib/classes/Path2D.js +2 -1
- package/lib/index.js +2 -2
- package/package.json +3 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# CHANGELOG
|
|
2
2
|
|
|
3
|
+
## Version 2.4.0
|
|
4
|
+
|
|
5
|
+
- fix(window): avoid global.window redefinition (#91)
|
|
6
|
+
- feat: add translate, translateSelf, scale and scaleSelf to DOMMatrix (#83)
|
|
7
|
+
- optimize(Path2D): replace reassign-concat with for-push (#76)
|
|
8
|
+
- test: add test for vis @antv/g2plot (#79)
|
|
9
|
+
- fix(setLineDash): rename parameter value to segments (#74)
|
|
10
|
+
- fix(clip): delete clipping region with restore (#73)
|
|
11
|
+
|
|
3
12
|
## Version 2.3.0
|
|
4
13
|
|
|
5
14
|
- Added Prettier code style
|
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
> Mock `canvas` when run unit test cases with jest. For more browser environment, you can use [jest-electron](https://github.com/hustcc/jest-electron) for real browser runtime.
|
|
4
4
|
|
|
5
|
-
[](https://github.com/hustcc/jest-canvas-mock/actions/workflows/build.yml)
|
|
6
6
|
[](https://coveralls.io/github/hustcc/jest-canvas-mock)
|
|
7
7
|
[](https://www.npmjs.com/package/jest-canvas-mock)
|
|
8
8
|
[](https://www.npmjs.com/package/jest-canvas-mock)
|
|
@@ -179,6 +179,8 @@ canvas.toDataURL.mockReturnValueOnce(
|
|
|
179
179
|
- [@jtenner](https://github.com/jtenner)
|
|
180
180
|
- [@evanoc0](https://github.com/evanoc0)
|
|
181
181
|
- [@lekha](https://github.com/lekha)
|
|
182
|
+
- [@yonatankra](https://github.com/yonatankra)
|
|
183
|
+
- [@LitoMore](https://github.com/LitoMore)
|
|
182
184
|
|
|
183
185
|
## License
|
|
184
186
|
|
package/lib/classes/DOMMatrix.js
CHANGED
|
@@ -7,6 +7,35 @@ exports.default = void 0;
|
|
|
7
7
|
|
|
8
8
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
9
9
|
|
|
10
|
+
function sumMultipleOfMatricesCells(matrix1Array, matrix2Array, {
|
|
11
|
+
i,
|
|
12
|
+
j
|
|
13
|
+
}) {
|
|
14
|
+
let sum = 0;
|
|
15
|
+
|
|
16
|
+
for (let k = 0; k < 4; k++) {
|
|
17
|
+
const matrix1Index = j - 1 + k * 4;
|
|
18
|
+
const matrix2Index = (i - 1) * 4 + k;
|
|
19
|
+
sum += matrix1Array[matrix1Index] * matrix2Array[matrix2Index];
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return sum;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function multiplyMatrices(leftMatrix, rightMatrix) {
|
|
26
|
+
const leftMatrixArray = leftMatrix.toFloat64Array();
|
|
27
|
+
const rightMatrixArray = rightMatrix.toFloat64Array();
|
|
28
|
+
|
|
29
|
+
for (let i = 1; i <= 4; i++) {
|
|
30
|
+
for (let j = 1; j <= 4; j++) {
|
|
31
|
+
leftMatrix[`m${i}${j}`] = sumMultipleOfMatricesCells(leftMatrixArray, rightMatrixArray, {
|
|
32
|
+
i,
|
|
33
|
+
j
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
10
39
|
class DOMMatrix {
|
|
11
40
|
constructor(transform) {
|
|
12
41
|
_defineProperty(this, "_is2D", true);
|
|
@@ -150,6 +179,69 @@ class DOMMatrix {
|
|
|
150
179
|
return new Float64Array([this.m11, this.m12, this.m13, this.m14, this.m21, this.m22, this.m23, this.m24, this.m31, this.m32, this.m33, this.m34, this.m41, this.m42, this.m43, this.m44]);
|
|
151
180
|
}
|
|
152
181
|
|
|
182
|
+
translateSelf(x, y, z) {
|
|
183
|
+
const tx = Number(x),
|
|
184
|
+
ty = Number(y),
|
|
185
|
+
tz = isNaN(Number(z)) ? 0 : Number(z);
|
|
186
|
+
const translationMatrix = new DOMMatrix();
|
|
187
|
+
translationMatrix.m41 = tx;
|
|
188
|
+
translationMatrix.m42 = ty;
|
|
189
|
+
translationMatrix.m43 = tz;
|
|
190
|
+
multiplyMatrices(this, translationMatrix);
|
|
191
|
+
|
|
192
|
+
if (tz) {
|
|
193
|
+
this._is2D = false;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
return this;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
translate(x, y, z) {
|
|
200
|
+
let translatedMatrix;
|
|
201
|
+
|
|
202
|
+
if (this.is2D) {
|
|
203
|
+
translatedMatrix = new DOMMatrix([this.a, this.b, this.c, this.d, this.e, this.f]);
|
|
204
|
+
} else {
|
|
205
|
+
translatedMatrix = new DOMMatrix(this.toFloat32Array());
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
return translatedMatrix.translateSelf(x, y, z);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
scaleSelf(scaleX, scaleY, scaleZ, originX, originY, originZ) {
|
|
212
|
+
const sx = Number(scaleX),
|
|
213
|
+
sy = isNaN(Number(scaleY)) ? sx : Number(scaleY),
|
|
214
|
+
sz = isNaN(Number(scaleZ)) ? 1 : Number(scaleZ);
|
|
215
|
+
const ox = isNaN(Number(originX)) ? 0 : Number(originX),
|
|
216
|
+
oy = isNaN(Number(originY)) ? 0 : Number(originY),
|
|
217
|
+
oz = isNaN(Number(originZ)) ? 0 : Number(originZ);
|
|
218
|
+
this.translateSelf(ox, oy, oz);
|
|
219
|
+
const scaleMatrix = new DOMMatrix();
|
|
220
|
+
scaleMatrix.m11 = sx;
|
|
221
|
+
scaleMatrix.m22 = sy;
|
|
222
|
+
scaleMatrix.m33 = sz;
|
|
223
|
+
multiplyMatrices(this, scaleMatrix);
|
|
224
|
+
this.translateSelf(-ox, -oy, -oz);
|
|
225
|
+
|
|
226
|
+
if (Math.abs(sz) !== 1) {
|
|
227
|
+
this._is2D = false;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
return this;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
scale(scaleX, scaleY, scaleZ, originX, originY, originZ) {
|
|
234
|
+
let scaledMatrix;
|
|
235
|
+
|
|
236
|
+
if (this.is2D) {
|
|
237
|
+
scaledMatrix = new DOMMatrix([this.a, this.b, this.c, this.d, this.e, this.f]);
|
|
238
|
+
} else {
|
|
239
|
+
scaledMatrix = new DOMMatrix(this.toFloat32Array());
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
return scaledMatrix.scaleSelf(scaleX, scaleY, scaleZ, originX, originY, originZ);
|
|
243
|
+
}
|
|
244
|
+
|
|
153
245
|
}
|
|
154
246
|
|
|
155
247
|
exports.default = DOMMatrix;
|
package/lib/classes/Path2D.js
CHANGED
|
@@ -36,7 +36,8 @@ class Path2D {
|
|
|
36
36
|
addPath(path) {
|
|
37
37
|
if (arguments.length < 1) throw new TypeError("Failed to execute 'addPath' on 'Path2D': 1 argument required, but only 0 present.");
|
|
38
38
|
if (!(path instanceof Path2D)) throw new TypeError("Failed to execute 'addPath' on 'Path2D': parameter 1 is not of type 'Path2D'.");
|
|
39
|
-
|
|
39
|
+
|
|
40
|
+
for (let i = 0; i < path._path.length; i++) this._path.push(path._path[i]);
|
|
40
41
|
}
|
|
41
42
|
|
|
42
43
|
}
|
package/lib/index.js
CHANGED
|
@@ -16,8 +16,8 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
16
16
|
// mock global window
|
|
17
17
|
// TODO: Force coverage to ignore this branch
|
|
18
18
|
if (typeof window !== 'undefined') {
|
|
19
|
-
|
|
19
|
+
(0, _window.default)(global.window);
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
const ver = "2.
|
|
22
|
+
const ver = "2.4.0";
|
|
23
23
|
exports.ver = ver;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "jest-canvas-mock",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.0",
|
|
4
4
|
"description": "Mock a canvas in your jest tests.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "types/index.d.ts",
|
|
@@ -48,7 +48,8 @@
|
|
|
48
48
|
"src/mock/**/*.js"
|
|
49
49
|
],
|
|
50
50
|
"setupFiles": [
|
|
51
|
-
"./src/index.js"
|
|
51
|
+
"./src/index.js",
|
|
52
|
+
"./__mocks__/worker.js"
|
|
52
53
|
]
|
|
53
54
|
},
|
|
54
55
|
"repository": {
|