@ohos-ports/vi-canvas-mock 1.0.0-beta.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/README.md +6 -0
- package/lib/classes/CanvasGradient.js +24 -0
- package/lib/classes/CanvasPattern.js +15 -0
- package/lib/classes/CanvasRenderingContext2D.js +1246 -0
- package/lib/classes/DOMMatrix.js +192 -0
- package/lib/classes/ImageBitmap.js +25 -0
- package/lib/classes/ImageData.js +61 -0
- package/lib/classes/Path2D.js +34 -0
- package/lib/classes/TextMetrics.js +27 -0
- package/lib/index.js +26 -0
- package/lib/mock/createCanvasEvent.js +28 -0
- package/lib/mock/createImageBitmap.js +48 -0
- package/lib/mock/prototype.js +108 -0
- package/lib/window.js +66 -0
- package/package.json +36 -0
- package/types/index.d.ts +96 -0
package/README.md
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
# vi-canvas-mock
|
|
2
|
+
|
|
3
|
+
This is a fork of [jest-canvas-mock](https://github.com/hustcc/jest-canvas-mock) replacing the use of Jest to Vitest to have a zero Jest dependancy canvas mock.
|
|
4
|
+
The code and the mock was develop by @hustcc i simpli replace jest with vi.
|
|
5
|
+
|
|
6
|
+
Thanks for the work @hustcc <3
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _mooColor = require("moo-color");
|
|
8
|
+
class CanvasGradient {
|
|
9
|
+
constructor() {
|
|
10
|
+
this.addColorStop = vi.fn(this.addColorStop.bind(this));
|
|
11
|
+
}
|
|
12
|
+
addColorStop(offset, color) {
|
|
13
|
+
const numoffset = Number(offset);
|
|
14
|
+
if (!Number.isFinite(numoffset) || numoffset < 0 || numoffset > 1) {
|
|
15
|
+
throw new DOMException('IndexSizeError', "Failed to execute 'addColorStop' on 'CanvasGradient': The provided value ('" + numoffset + "') is outside the range (0.0, 1.0)");
|
|
16
|
+
}
|
|
17
|
+
try {
|
|
18
|
+
new _mooColor.MooColor(color);
|
|
19
|
+
} catch (e) {
|
|
20
|
+
throw new SyntaxError("Failed to execute 'addColorStop' on 'CanvasGradient': The value provided ('" + color + "') could not be parsed as a color.");
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.default = CanvasGradient;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
class CanvasPattern {
|
|
8
|
+
constructor() {
|
|
9
|
+
this.setTransform = vi.fn(this.setTransform.bind(this));
|
|
10
|
+
}
|
|
11
|
+
setTransform(value) {
|
|
12
|
+
if (arguments.length > 0 && !(value instanceof Object)) throw new TypeError("Failed to execute 'setTransform' on 'CanvasPattern': parameter 1 ('transform') is not an object.");
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.default = CanvasPattern;
|