jest-canvas-mock 2.2.0 → 2.3.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 +474 -463
- package/README.md +185 -169
- package/lib/classes/CanvasGradient.js +6 -9
- package/lib/classes/CanvasPattern.js +1 -1
- package/lib/classes/CanvasRenderingContext2D.js +173 -147
- package/lib/classes/DOMMatrix.js +9 -1
- package/lib/classes/ImageData.js +1 -1
- package/lib/classes/Path2D.js +2 -2
- package/lib/index.js +4 -4
- package/lib/mock/createCanvasEvent.js +14 -14
- package/lib/mock/createImageBitmap.js +5 -5
- package/lib/mock/prototype.js +27 -27
- package/lib/window.js +7 -7
- package/package.json +77 -70
- package/types/index.d.ts +94 -86
- package/.github/FUNDING.yml +0 -12
package/lib/classes/DOMMatrix.js
CHANGED
|
@@ -76,7 +76,7 @@ class DOMMatrix {
|
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
if (transform) {
|
|
79
|
-
throw new TypeError(
|
|
79
|
+
throw new TypeError("Failed to construct 'DOMMatrix': The sequence must contain 6 elements for a 2D matrix or 16 elements for a 3D matrix.");
|
|
80
80
|
}
|
|
81
81
|
|
|
82
82
|
this._is2D = false;
|
|
@@ -142,6 +142,14 @@ class DOMMatrix {
|
|
|
142
142
|
return this._is2D;
|
|
143
143
|
}
|
|
144
144
|
|
|
145
|
+
toFloat32Array() {
|
|
146
|
+
return new Float32Array([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]);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
toFloat64Array() {
|
|
150
|
+
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
|
+
}
|
|
152
|
+
|
|
145
153
|
}
|
|
146
154
|
|
|
147
155
|
exports.default = DOMMatrix;
|
package/lib/classes/ImageData.js
CHANGED
|
@@ -55,7 +55,7 @@ class ImageData {
|
|
|
55
55
|
if (h === 0) throw new RangeError('The height is zero or not a number.');
|
|
56
56
|
if (!Number.isFinite(w)) throw new RangeError('The width is zero or not a number.');
|
|
57
57
|
if (w === 0) throw new RangeError('The width is zero or not a number.');
|
|
58
|
-
if (arr.length !== w * h * 4) throw new RangeError(
|
|
58
|
+
if (arr.length !== w * h * 4) throw new RangeError("Source doesn'n contain the exact number of pixels needed.");
|
|
59
59
|
this._width = w;
|
|
60
60
|
this._height = h;
|
|
61
61
|
this._data = arr;
|
package/lib/classes/Path2D.js
CHANGED
|
@@ -34,8 +34,8 @@ class Path2D {
|
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
addPath(path) {
|
|
37
|
-
if (arguments.length < 1) throw new TypeError(
|
|
38
|
-
if (!(path instanceof Path2D)) throw new TypeError(
|
|
37
|
+
if (arguments.length < 1) throw new TypeError("Failed to execute 'addPath' on 'Path2D': 1 argument required, but only 0 present.");
|
|
38
|
+
if (!(path instanceof Path2D)) throw new TypeError("Failed to execute 'addPath' on 'Path2D': parameter 1 is not of type 'Path2D'.");
|
|
39
39
|
this._path = this._path.concat(path._path);
|
|
40
40
|
}
|
|
41
41
|
|
package/lib/index.js
CHANGED
|
@@ -9,9 +9,9 @@ var _window = _interopRequireDefault(require("./window"));
|
|
|
9
9
|
|
|
10
10
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
11
|
|
|
12
|
-
/**
|
|
13
|
-
* Created by hustcc 17/12/25.
|
|
14
|
-
* Contract: i@hust.cc
|
|
12
|
+
/**
|
|
13
|
+
* Created by hustcc 17/12/25.
|
|
14
|
+
* Contract: i@hust.cc
|
|
15
15
|
*/
|
|
16
16
|
// mock global window
|
|
17
17
|
// TODO: Force coverage to ignore this branch
|
|
@@ -19,5 +19,5 @@ if (typeof window !== 'undefined') {
|
|
|
19
19
|
global.window = (0, _window.default)(window);
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
const ver = "2.
|
|
22
|
+
const ver = "2.3.0";
|
|
23
23
|
exports.ver = ver;
|
|
@@ -5,20 +5,20 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = createCanvasEvent;
|
|
7
7
|
|
|
8
|
-
/**
|
|
9
|
-
* This function returns a CanvasRenderingContext2DEvent. Whenever an operation would modify the canvas
|
|
10
|
-
* context, this function should be used to generate an "event" that represents that sort of modification.
|
|
11
|
-
* This will be used to mock for snapshots.
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
* interface CanvasRenderingContext2DEvent {
|
|
15
|
-
* type: string;
|
|
16
|
-
* transform: [number, number, number, number, number, number]; // the resulting current transform
|
|
17
|
-
* props: {
|
|
18
|
-
* // if the event is a property was set, `event.props.value` would be set
|
|
19
|
-
* [propName: string]: any;
|
|
20
|
-
* };
|
|
21
|
-
* }
|
|
8
|
+
/**
|
|
9
|
+
* This function returns a CanvasRenderingContext2DEvent. Whenever an operation would modify the canvas
|
|
10
|
+
* context, this function should be used to generate an "event" that represents that sort of modification.
|
|
11
|
+
* This will be used to mock for snapshots.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* interface CanvasRenderingContext2DEvent {
|
|
15
|
+
* type: string;
|
|
16
|
+
* transform: [number, number, number, number, number, number]; // the resulting current transform
|
|
17
|
+
* props: {
|
|
18
|
+
* // if the event is a property was set, `event.props.value` would be set
|
|
19
|
+
* [propName: string]: any;
|
|
20
|
+
* };
|
|
21
|
+
* }
|
|
22
22
|
*/
|
|
23
23
|
function createCanvasEvent(type, transform, props) {
|
|
24
24
|
return {
|
|
@@ -12,17 +12,17 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
12
12
|
var _default = jest.fn(function createImageBitmap(img, sx, sy, sWidth, sHeight, options) {
|
|
13
13
|
var length = arguments.length;
|
|
14
14
|
return new Promise((resolve, reject) => {
|
|
15
|
-
if (length === 0) return reject(new TypeError(
|
|
16
|
-
if (length === 3 || length === 4) return reject(new TypeError(
|
|
15
|
+
if (length === 0) return reject(new TypeError("Failed to execute 'createImageBitmap' on 'Window': 1 argument required, but only 0 present."));
|
|
16
|
+
if (length === 3 || length === 4) return reject(new TypeError("Failed to execute 'createImageBitmap' on 'Window': Valid arities are: [1, 2, 5, 6], but " + length + ' arguments provided.'));
|
|
17
17
|
let validImage = false;
|
|
18
18
|
if (img instanceof HTMLImageElement) validImage = true;
|
|
19
19
|
if (img instanceof HTMLVideoElement) validImage = true;
|
|
20
20
|
if (img instanceof HTMLCanvasElement) validImage = true; // checking constructor name is the only reliable way to verify the object's constructing class is "blob-like"
|
|
21
21
|
|
|
22
|
-
if (img instanceof Blob || img && img.constructor && img.constructor.name ===
|
|
22
|
+
if (img instanceof Blob || img && img.constructor && img.constructor.name === 'Blob') validImage = true;
|
|
23
23
|
if (img instanceof _ImageBitmap.default) validImage = true;
|
|
24
24
|
if (img instanceof ImageData) validImage = true;
|
|
25
|
-
if (!validImage) return reject(new TypeError(
|
|
25
|
+
if (!validImage) return reject(new TypeError("Failed to execute 'createImageBitmap' on 'Window': The provided value is not of type '(HTMLImageElement or SVGImageElement or HTMLVideoElement or HTMLCanvasElement or Blob or ImageData or ImageBitmap or OffscreenCanvas)'"));
|
|
26
26
|
|
|
27
27
|
if (length >= 2) {
|
|
28
28
|
let index = 6;
|
|
@@ -35,7 +35,7 @@ var _default = jest.fn(function createImageBitmap(img, sx, sy, sWidth, sHeight,
|
|
|
35
35
|
if (length === 5) options = null;
|
|
36
36
|
|
|
37
37
|
if (options !== null && options !== void 0) {
|
|
38
|
-
if (typeof options !== 'object') throw new TypeError(
|
|
38
|
+
if (typeof options !== 'object') throw new TypeError("Failed to execute 'createImageBitmap' on 'Window': parameter " + index + " ('options') is not an object.");
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
41
|
|
package/lib/mock/prototype.js
CHANGED
|
@@ -6,23 +6,23 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.default = mockPrototype;
|
|
7
7
|
|
|
8
8
|
function mockPrototype() {
|
|
9
|
-
/**
|
|
10
|
-
* This weakmap is designed to contain all of the generated canvas contexts. It's keys are the
|
|
11
|
-
* jsdom canvases obtained by using the `this` keyword inside the `#getContext('2d')` function
|
|
12
|
-
* call. It's values are the generated `CanvasRenderingContext2D` objects.
|
|
9
|
+
/**
|
|
10
|
+
* This weakmap is designed to contain all of the generated canvas contexts. It's keys are the
|
|
11
|
+
* jsdom canvases obtained by using the `this` keyword inside the `#getContext('2d')` function
|
|
12
|
+
* call. It's values are the generated `CanvasRenderingContext2D` objects.
|
|
13
13
|
*/
|
|
14
14
|
const generatedContexts = new WeakMap();
|
|
15
|
-
/**
|
|
16
|
-
* Overrides getContext. Every test run will create a new function that overrides the current
|
|
17
|
-
* value of getContext. It attempts to preserve the original getContext function by storing it on
|
|
18
|
-
* the callback as a property.
|
|
15
|
+
/**
|
|
16
|
+
* Overrides getContext. Every test run will create a new function that overrides the current
|
|
17
|
+
* value of getContext. It attempts to preserve the original getContext function by storing it on
|
|
18
|
+
* the callback as a property.
|
|
19
19
|
*/
|
|
20
20
|
|
|
21
21
|
const getContext2D = jest.fn(function getContext2d(type) {
|
|
22
22
|
if (type === '2d') {
|
|
23
|
-
/**
|
|
24
|
-
* Contexts must be indempotent. Once they are generated, they should be returned when
|
|
25
|
-
* getContext() is called on the same canvas object multiple times.
|
|
23
|
+
/**
|
|
24
|
+
* Contexts must be indempotent. Once they are generated, they should be returned when
|
|
25
|
+
* getContext() is called on the same canvas object multiple times.
|
|
26
26
|
*/
|
|
27
27
|
if (generatedContexts.has(this)) return generatedContexts.get(this);
|
|
28
28
|
const ctx = new CanvasRenderingContext2D(this);
|
|
@@ -46,17 +46,17 @@ function mockPrototype() {
|
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
HTMLCanvasElement.prototype.getContext = getContext2D;
|
|
49
|
-
/**
|
|
50
|
-
* This function technically throws SecurityError at runtime, but it cannot be mocked, because
|
|
51
|
-
* we don't know if the canvas is tainted. These kinds of errors will be silent.
|
|
49
|
+
/**
|
|
50
|
+
* This function technically throws SecurityError at runtime, but it cannot be mocked, because
|
|
51
|
+
* we don't know if the canvas is tainted. These kinds of errors will be silent.
|
|
52
52
|
*/
|
|
53
53
|
|
|
54
54
|
const toBlobOverride = jest.fn(function toBlobOverride(callback, mimetype) {
|
|
55
|
-
if (arguments.length < 1) throw new TypeError(
|
|
56
|
-
if (typeof callback !== 'function') throw new TypeError(
|
|
57
|
-
/**
|
|
58
|
-
* Mime type must be image/jpeg or image/webp exactly for the browser to accept it, otherwise
|
|
59
|
-
* it's image/png.
|
|
55
|
+
if (arguments.length < 1) throw new TypeError("Failed to execute 'toBlob' on 'HTMLCanvasElement': 1 argument required, but only 0 present.");
|
|
56
|
+
if (typeof callback !== 'function') throw new TypeError("Failed to execute 'toBlob' on 'HTMLCanvasElement': The callback provided as parameter 1 is not a function.");
|
|
57
|
+
/**
|
|
58
|
+
* Mime type must be image/jpeg or image/webp exactly for the browser to accept it, otherwise
|
|
59
|
+
* it's image/png.
|
|
60
60
|
*/
|
|
61
61
|
|
|
62
62
|
switch (mimetype) {
|
|
@@ -69,9 +69,9 @@ function mockPrototype() {
|
|
|
69
69
|
default:
|
|
70
70
|
mimetype = 'image/png';
|
|
71
71
|
}
|
|
72
|
-
/**
|
|
73
|
-
* This section creates a blob of size width * height * 4. This is not actually valid, because
|
|
74
|
-
* jpeg size is variable, and so is png. TODO: Is there a better way to do this?
|
|
72
|
+
/**
|
|
73
|
+
* This section creates a blob of size width * height * 4. This is not actually valid, because
|
|
74
|
+
* jpeg size is variable, and so is png. TODO: Is there a better way to do this?
|
|
75
75
|
*/
|
|
76
76
|
|
|
77
77
|
|
|
@@ -90,9 +90,9 @@ function mockPrototype() {
|
|
|
90
90
|
}
|
|
91
91
|
|
|
92
92
|
HTMLCanvasElement.prototype.toBlob = toBlobOverride;
|
|
93
|
-
/**
|
|
94
|
-
* This section creates a dataurl with a validated mime type. This is not actually valid, because
|
|
95
|
-
* jpeg size is variable, and so is png. TODO: Is there a better way to do this?
|
|
93
|
+
/**
|
|
94
|
+
* This section creates a dataurl with a validated mime type. This is not actually valid, because
|
|
95
|
+
* jpeg size is variable, and so is png. TODO: Is there a better way to do this?
|
|
96
96
|
*/
|
|
97
97
|
|
|
98
98
|
const toDataURLOverride = jest.fn(function toDataURLOverride(type, encoderOptions) {
|
|
@@ -106,8 +106,8 @@ function mockPrototype() {
|
|
|
106
106
|
default:
|
|
107
107
|
type = 'image/png';
|
|
108
108
|
}
|
|
109
|
-
/**
|
|
110
|
-
* This is the smallest valid data url I could generate.
|
|
109
|
+
/**
|
|
110
|
+
* This is the smallest valid data url I could generate.
|
|
111
111
|
*/
|
|
112
112
|
|
|
113
113
|
|
package/lib/window.js
CHANGED
|
@@ -27,9 +27,9 @@ var _createImageBitmap = _interopRequireDefault(require("./mock/createImageBitma
|
|
|
27
27
|
|
|
28
28
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
29
29
|
|
|
30
|
-
/**
|
|
31
|
-
* Created by hustcc 17/12/25.
|
|
32
|
-
* Contract: i@hust.cc
|
|
30
|
+
/**
|
|
31
|
+
* Created by hustcc 17/12/25.
|
|
32
|
+
* Contract: i@hust.cc
|
|
33
33
|
*/
|
|
34
34
|
var _default = win => {
|
|
35
35
|
const d = win.document;
|
|
@@ -54,10 +54,10 @@ var _default = win => {
|
|
|
54
54
|
// if ctx not exist, mock it.
|
|
55
55
|
// just mock canvas creator.
|
|
56
56
|
|
|
57
|
-
/*
|
|
58
|
-
win.document.createElement = param => param.toString().toLowerCase() === 'canvas'
|
|
59
|
-
? createCanvas('canvas')
|
|
60
|
-
: f.call(d, param);
|
|
57
|
+
/*
|
|
58
|
+
win.document.createElement = param => param.toString().toLowerCase() === 'canvas'
|
|
59
|
+
? createCanvas('canvas')
|
|
60
|
+
: f.call(d, param);
|
|
61
61
|
*/
|
|
62
62
|
// if not exist, then mock it.
|
|
63
63
|
|
package/package.json
CHANGED
|
@@ -1,70 +1,77 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "jest-canvas-mock",
|
|
3
|
-
"version": "2.
|
|
4
|
-
"description": "Mock a canvas in your jest tests.",
|
|
5
|
-
"main": "lib/index.js",
|
|
6
|
-
"types": "types/index.d.ts",
|
|
7
|
-
"scripts": {
|
|
8
|
-
"test": "jest --no-cache",
|
|
9
|
-
"build": "babel src --out-dir lib",
|
|
10
|
-
"coveralls": "cat ./coverage/lcov.info | coveralls",
|
|
11
|
-
"prepare": "npm run build"
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
"
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
"@babel/
|
|
20
|
-
"@babel/
|
|
21
|
-
"@babel/
|
|
22
|
-
"@
|
|
23
|
-
"@commitlint/
|
|
24
|
-
"
|
|
25
|
-
"babel-
|
|
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
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "jest-canvas-mock",
|
|
3
|
+
"version": "2.3.0",
|
|
4
|
+
"description": "Mock a canvas in your jest tests.",
|
|
5
|
+
"main": "lib/index.js",
|
|
6
|
+
"types": "types/index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"test": "jest --no-cache",
|
|
9
|
+
"build": "babel src --out-dir lib",
|
|
10
|
+
"coveralls": "cat ./coverage/lcov.info | coveralls",
|
|
11
|
+
"prepare": "npm run build",
|
|
12
|
+
"prettier": "prettier --write ."
|
|
13
|
+
},
|
|
14
|
+
"dependencies": {
|
|
15
|
+
"cssfontparser": "^1.2.1",
|
|
16
|
+
"moo-color": "^1.0.2"
|
|
17
|
+
},
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"@babel/cli": "^7.8.4",
|
|
20
|
+
"@babel/core": "^7.9.0",
|
|
21
|
+
"@babel/plugin-proposal-class-properties": "^7.8.3",
|
|
22
|
+
"@babel/preset-env": "^7.9.5",
|
|
23
|
+
"@commitlint/cli": "^8.3.5",
|
|
24
|
+
"@commitlint/config-angular": "^8.3.4",
|
|
25
|
+
"babel-jest": "^25.3.0",
|
|
26
|
+
"babel-plugin-version": "^0.2.3",
|
|
27
|
+
"coveralls": "^3.0.11",
|
|
28
|
+
"husky": "^4.2.5",
|
|
29
|
+
"jest": "^25.3.0",
|
|
30
|
+
"prettier": "^2.0.4"
|
|
31
|
+
},
|
|
32
|
+
"commitlint": {
|
|
33
|
+
"extends": [
|
|
34
|
+
"@commitlint/config-angular"
|
|
35
|
+
]
|
|
36
|
+
},
|
|
37
|
+
"husky": {
|
|
38
|
+
"hooks": {
|
|
39
|
+
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS",
|
|
40
|
+
"pre-commit": "npm run prettier && npm run test && npm run build"
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
"jest": {
|
|
44
|
+
"collectCoverage": true,
|
|
45
|
+
"collectCoverageFrom": [
|
|
46
|
+
"src/classes/**/*.js",
|
|
47
|
+
"src/mock/**/*.js"
|
|
48
|
+
],
|
|
49
|
+
"setupFiles": [
|
|
50
|
+
"./src/index.js"
|
|
51
|
+
]
|
|
52
|
+
},
|
|
53
|
+
"repository": {
|
|
54
|
+
"type": "git",
|
|
55
|
+
"url": "git+https://github.com/hustcc/jest-canvas-mock.git"
|
|
56
|
+
},
|
|
57
|
+
"keywords": [
|
|
58
|
+
"mock",
|
|
59
|
+
"jest",
|
|
60
|
+
"jest-mock",
|
|
61
|
+
"echarts",
|
|
62
|
+
"canvas",
|
|
63
|
+
"test",
|
|
64
|
+
"unit"
|
|
65
|
+
],
|
|
66
|
+
"files": [
|
|
67
|
+
"CHANGELOG.md",
|
|
68
|
+
"lib/",
|
|
69
|
+
"types/"
|
|
70
|
+
],
|
|
71
|
+
"author": "hustcc",
|
|
72
|
+
"license": "MIT",
|
|
73
|
+
"bugs": {
|
|
74
|
+
"url": "https://github.com/hustcc/jest-canvas-mock/issues"
|
|
75
|
+
},
|
|
76
|
+
"homepage": "https://github.com/hustcc/jest-canvas-mock#readme"
|
|
77
|
+
}
|
package/types/index.d.ts
CHANGED
|
@@ -1,86 +1,94 @@
|
|
|
1
|
-
export interface CanvasRenderingContext2DEvent {
|
|
2
|
-
/**
|
|
3
|
-
* This is the type of canvas event that occured.
|
|
4
|
-
*/
|
|
5
|
-
type: string;
|
|
6
|
-
/**
|
|
7
|
-
* This is a six element array that contains the current state of the canvas `currentTransform`
|
|
8
|
-
* value.
|
|
9
|
-
*/
|
|
10
|
-
transform: [number, number, number, number, number, number];
|
|
11
|
-
/**
|
|
12
|
-
* These are the relevant properties related to this canvas event.
|
|
13
|
-
*/
|
|
14
|
-
props: {
|
|
15
|
-
[key: string]: any;
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
declare global {
|
|
20
|
-
interface CanvasRenderingContext2D {
|
|
21
|
-
/**
|
|
22
|
-
* Get all the events associated with this CanvasRenderingContext2D object.
|
|
23
|
-
*
|
|
24
|
-
* This method cannot be used in a production environment, only with `jest` using
|
|
25
|
-
* `jest-canvas-mock` and should only be used for testing.
|
|
26
|
-
*
|
|
27
|
-
* @example
|
|
28
|
-
* expect(ctx.__getEvents()).toMatchSnapshot();
|
|
29
|
-
*/
|
|
30
|
-
__getEvents(): CanvasRenderingContext2DEvent[];
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Clear all the events associated with this CanvasRenderingContext2D object.
|
|
34
|
-
*
|
|
35
|
-
* This method cannot be used in a production environment, only with `jest` using
|
|
36
|
-
* `jest-canvas-mock` and should only be used for testing.
|
|
37
|
-
*
|
|
38
|
-
* @example
|
|
39
|
-
* ctx.__clearEvents());
|
|
40
|
-
* expect(ctx.__getEvents()).toBe([]);
|
|
41
|
-
*/
|
|
42
|
-
__clearEvents(): void;
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Get all the successful draw calls associated with this CanvasRenderingContext2D object.
|
|
46
|
-
*
|
|
47
|
-
* This method cannot be used in a production environment, only with `jest` using
|
|
48
|
-
* `jest-canvas-mock` and should only be used for testing.
|
|
49
|
-
*
|
|
50
|
-
* @example
|
|
51
|
-
* expect(ctx.__getDrawCalls()).toMatchSnapshot();
|
|
52
|
-
*/
|
|
53
|
-
__getDrawCalls(): CanvasRenderingContext2DEvent[];
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Clear all the successful draw calls associated with this CanvasRenderingContext2D object.
|
|
57
|
-
*
|
|
58
|
-
* This method cannot be used in a production environment, only with `jest` using
|
|
59
|
-
* `jest-canvas-mock` and should only be used for testing.
|
|
60
|
-
*
|
|
61
|
-
* @example
|
|
62
|
-
* ctx.__clearDrawCalls());
|
|
63
|
-
* expect(ctx.__getDrawCalls()).toBe([]);
|
|
64
|
-
*/
|
|
65
|
-
__clearDrawCalls(): void;
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Get the current path associated with this CanvasRenderingContext2D object.
|
|
69
|
-
*
|
|
70
|
-
* This method cannot be used in a production environment, only with `jest` using
|
|
71
|
-
* `jest-canvas-mock` and should only be used for testing.
|
|
72
|
-
*
|
|
73
|
-
* @example
|
|
74
|
-
* expect(ctx.__getPath()).toMatchSnapshot();
|
|
75
|
-
*/
|
|
76
|
-
__getPath(): CanvasRenderingContext2DEvent[];
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* Clears the current path associated with this CanvasRenderingContext2D object.
|
|
80
|
-
*
|
|
81
|
-
* This method cannot be used in a production environment, only with `jest` using
|
|
82
|
-
* `jest-canvas-mock` and should be only used for testing.
|
|
83
|
-
*/
|
|
84
|
-
__clearPath(): void;
|
|
85
|
-
|
|
86
|
-
|
|
1
|
+
export interface CanvasRenderingContext2DEvent {
|
|
2
|
+
/**
|
|
3
|
+
* This is the type of canvas event that occured.
|
|
4
|
+
*/
|
|
5
|
+
type: string;
|
|
6
|
+
/**
|
|
7
|
+
* This is a six element array that contains the current state of the canvas `currentTransform`
|
|
8
|
+
* value.
|
|
9
|
+
*/
|
|
10
|
+
transform: [number, number, number, number, number, number];
|
|
11
|
+
/**
|
|
12
|
+
* These are the relevant properties related to this canvas event.
|
|
13
|
+
*/
|
|
14
|
+
props: {
|
|
15
|
+
[key: string]: any;
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
declare global {
|
|
20
|
+
interface CanvasRenderingContext2D {
|
|
21
|
+
/**
|
|
22
|
+
* Get all the events associated with this CanvasRenderingContext2D object.
|
|
23
|
+
*
|
|
24
|
+
* This method cannot be used in a production environment, only with `jest` using
|
|
25
|
+
* `jest-canvas-mock` and should only be used for testing.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* expect(ctx.__getEvents()).toMatchSnapshot();
|
|
29
|
+
*/
|
|
30
|
+
__getEvents(): CanvasRenderingContext2DEvent[];
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Clear all the events associated with this CanvasRenderingContext2D object.
|
|
34
|
+
*
|
|
35
|
+
* This method cannot be used in a production environment, only with `jest` using
|
|
36
|
+
* `jest-canvas-mock` and should only be used for testing.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ctx.__clearEvents());
|
|
40
|
+
* expect(ctx.__getEvents()).toBe([]);
|
|
41
|
+
*/
|
|
42
|
+
__clearEvents(): void;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Get all the successful draw calls associated with this CanvasRenderingContext2D object.
|
|
46
|
+
*
|
|
47
|
+
* This method cannot be used in a production environment, only with `jest` using
|
|
48
|
+
* `jest-canvas-mock` and should only be used for testing.
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* expect(ctx.__getDrawCalls()).toMatchSnapshot();
|
|
52
|
+
*/
|
|
53
|
+
__getDrawCalls(): CanvasRenderingContext2DEvent[];
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Clear all the successful draw calls associated with this CanvasRenderingContext2D object.
|
|
57
|
+
*
|
|
58
|
+
* This method cannot be used in a production environment, only with `jest` using
|
|
59
|
+
* `jest-canvas-mock` and should only be used for testing.
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ctx.__clearDrawCalls());
|
|
63
|
+
* expect(ctx.__getDrawCalls()).toBe([]);
|
|
64
|
+
*/
|
|
65
|
+
__clearDrawCalls(): void;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Get the current path associated with this CanvasRenderingContext2D object.
|
|
69
|
+
*
|
|
70
|
+
* This method cannot be used in a production environment, only with `jest` using
|
|
71
|
+
* `jest-canvas-mock` and should only be used for testing.
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* expect(ctx.__getPath()).toMatchSnapshot();
|
|
75
|
+
*/
|
|
76
|
+
__getPath(): CanvasRenderingContext2DEvent[];
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Clears the current path associated with this CanvasRenderingContext2D object.
|
|
80
|
+
*
|
|
81
|
+
* This method cannot be used in a production environment, only with `jest` using
|
|
82
|
+
* `jest-canvas-mock` and should be only used for testing.
|
|
83
|
+
*/
|
|
84
|
+
__clearPath(): void;
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Obtains the current clipping path.
|
|
88
|
+
*
|
|
89
|
+
* This method cannot be used in a production environment, only with `jest` using
|
|
90
|
+
* `jest-canvas-mock` and should be only used for testing.
|
|
91
|
+
*/
|
|
92
|
+
__getClippingRegion(): CanvasRenderingContext2DEvent[];
|
|
93
|
+
}
|
|
94
|
+
}
|
package/.github/FUNDING.yml
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
# These are supported funding model platforms
|
|
2
|
-
|
|
3
|
-
github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
|
|
4
|
-
patreon: # Replace with a single Patreon username
|
|
5
|
-
open_collective: # Replace with a single Open Collective username
|
|
6
|
-
ko_fi: # Replace with a single Ko-fi username
|
|
7
|
-
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
|
|
8
|
-
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
|
|
9
|
-
liberapay: # Replace with a single Liberapay username
|
|
10
|
-
issuehunt: # Replace with a single IssueHunt username
|
|
11
|
-
otechie: # Replace with a single Otechie username
|
|
12
|
-
custom: ['https://paypal.me/hustcc', 'https://atool.vip']
|