Socket
Socket
Sign inDemoInstall

jest-webgl-canvas-mock

Package Overview
Dependencies
3
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.2.3 to 2.5.0

55

CHANGELOG.md
# CHANGELOG
# Version 2.1.0
## Version 2.5.0
- feat: export a function to re-initialize mocks (#98)
- docs: fix some typos (#104)
- fix: copy & paste mistake: toBlob -> toDataURL (#101)
- chore: add Contributors LitoMore (#94)
## Version 2.4.0
- fix(window): avoid global.window redefinition (#91)
- feat: add translate, translateSelf, scale and scaleSelf to DOMMatrix (#83)
- optimize(Path2D): replace reassign-concat with for-push (#76)
- test: add test for vis @antv/g2plot (#79)
- fix(setLineDash): rename parameter value to segments (#74)
- fix(clip): delete clipping region with restore (#73)
## Version 2.3.0
- Added Prettier code style
- Deleted .npmignore and switched to `package.json` files field
- Added [CONTRIBUTING](./CONTRIBUTING.md) and [CODE_OF_CONDUCT](./CODE_OF_CONDUCT.md) docs
- Switched to `moo-color` for color parsing
- Added contributors to markdown document
- New Contributor [@evanoc0](https://github.com/evanoc0)
## Version 2.2.0
- Bug: Slice canvas transform value when pushing (#50)
- Remove support for node 6 and 7
- switch babel env to target node 8
- add support for node 13
- update package versions
- fix lineWidth bug
## Version 2.1.1
- Feature: Support for ImageData instantiation using a source array (#45)
## Version 2.1.0
This minor version bump now has some major snapshot support but is backwards compatible.

@@ -28,9 +66,9 @@

# Version 2.0.0
## Version 2.0.0
Just publish a stable version.
# Version 2.0.0-beta.1
## Version 2.0.0-beta.1
## Class Instances
### Class Instances

@@ -47,3 +85,3 @@ The Version 2.0.0-beta.1 of `jest-canvas-mock` is a complete overhaul of the mocking strategy entirely. Originally, the `canvas.getCanvas('2d')` method would return a single object that contained a set of methods without any property definitions. This caused problems for people who wanted to use `jest` to test and verify `instanceof` checks.

## Bound Mock Functions
### Bound Mock Functions

@@ -65,3 +103,3 @@ When each `CanvasRenderingContext2D` object is created, all the methods are properly mocked with the `jest.fn()` method, and bound to the instance. It's still possible to verify that a function was called on the context. The main difference now is that the methods actually perform runtime checks on the passed parameters.

# Parsing Colors and Fonts, Saving, Restoring
### Parsing Colors and Fonts, Saving, Restoring

@@ -101,3 +139,3 @@ Another really big change is that the mocking strategy now attempts to conform to the html living specification. In order to do this, two packages were added as dependencies so that css colors and fonts can be more properly parsed. This is not perfect, and any problems with the color parser or font parser should be reported in the Issues tab.

## CanvasRenderingContext2D prototype
### CanvasRenderingContext2D prototype

@@ -374,3 +412,3 @@ - Implemented Stack Properties for the following items:

## Other Changes By File
### Other Changes By File

@@ -456,2 +494,1 @@ - src/CanvasGradient.js

- sets `width` property to `text.length`

56

lib/classes/CanvasGradient.js

@@ -6,44 +6,20 @@ "use strict";

});
exports["default"] = void 0;
var _parseColor = _interopRequireDefault(require("parse-color"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
var CanvasGradient =
/*#__PURE__*/
function () {
function CanvasGradient() {
_classCallCheck(this, CanvasGradient);
exports.default = void 0;
var _mooColor = require("moo-color");
class CanvasGradient {
constructor() {
this.addColorStop = jest.fn(this.addColorStop.bind(this));
}
_createClass(CanvasGradient, [{
key: "addColorStop",
value: function addColorStop(offset, color) {
var numoffset = Number(offset);
var colorstr = String(color);
if (!Number.isFinite(numoffset) || numoffset < 0 || numoffset > 1) {
throw new DOMException('IndexSizeError', 'Failed to execute \'addColorStop\' on \'CanvasGradient\': The provided value (\'' + numoffset + '\') is outside the range (0.0, 1.0)');
}
var output = (0, _parseColor["default"])(colorstr);
if (!output.hex) {
throw new SyntaxError('Failed to execute \'addColorStop\' on \'CanvasGradient\': The value provided (\'' + color + '\') could not be parsed as a color.');
}
addColorStop(offset, color) {
const numoffset = Number(offset);
if (!Number.isFinite(numoffset) || numoffset < 0 || numoffset > 1) {
throw new DOMException('IndexSizeError', "Failed to execute 'addColorStop' on 'CanvasGradient': The provided value ('" + numoffset + "') is outside the range (0.0, 1.0)");
}
}]);
return CanvasGradient;
}();
exports["default"] = CanvasGradient;
try {
new _mooColor.MooColor(color);
} catch (e) {
throw new SyntaxError("Failed to execute 'addColorStop' on 'CanvasGradient': The value provided ('" + color + "') could not be parsed as a color.");
}
}
}
exports.default = CanvasGradient;

@@ -6,29 +6,11 @@ "use strict";

});
exports["default"] = void 0;
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
var CanvasPattern =
/*#__PURE__*/
function () {
function CanvasPattern() {
_classCallCheck(this, CanvasPattern);
exports.default = void 0;
class CanvasPattern {
constructor() {
this.setTransform = jest.fn(this.setTransform.bind(this));
}
_createClass(CanvasPattern, [{
key: "setTransform",
value: function setTransform(value) {
if (arguments.length > 0 && !(value instanceof Object)) throw new TypeError('Failed to execute \'setTransform\' on \'CanvasPattern\': parameter 1 (\'transform\') is not an object.');
}
}]);
return CanvasPattern;
}();
exports["default"] = CanvasPattern;
setTransform(value) {
if (arguments.length > 0 && !(value instanceof Object)) throw new TypeError("Failed to execute 'setTransform' on 'CanvasPattern': parameter 1 ('transform') is not an object.");
}
}
exports.default = CanvasPattern;

@@ -6,60 +6,80 @@ "use strict";

});
exports["default"] = void 0;
exports.default = void 0;
var _DOMMatrix = _interopRequireDefault(require("./DOMMatrix"));
var _CanvasPattern = _interopRequireDefault(require("./CanvasPattern"));
var _parseColor = _interopRequireDefault(require("parse-color"));
var _cssfontparser = _interopRequireDefault(require("cssfontparser"));
var _TextMetrics = _interopRequireDefault(require("./TextMetrics"));
var _createCanvasEvent = _interopRequireDefault(require("../mock/createCanvasEvent"));
var _Path2D = _interopRequireDefault(require("./Path2D"));
var _mooColor = require("moo-color");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
const testFuncs = ['setLineDash', 'getLineDash', 'setTransform', 'getTransform', 'getImageData', 'save', 'restore', 'createPattern', 'createRadialGradient', 'addHitRegion', 'arc', 'arcTo', 'beginPath', 'clip', 'closePath', 'scale', 'stroke', 'clearHitRegions', 'clearRect', 'fillRect', 'strokeRect', 'rect', 'resetTransform', 'translate', 'moveTo', 'lineTo', 'bezierCurveTo', 'createLinearGradient', 'ellipse', 'measureText', 'rotate', 'drawImage', 'drawFocusIfNeeded', 'isPointInPath', 'isPointInStroke', 'putImageData', 'strokeText', 'fillText', 'quadraticCurveTo', 'removeHitRegion', 'fill', 'transform', 'scrollPathIntoView', 'createImageData'];
const compositeOperations = ['source-over', 'source-in', 'source-out', 'source-atop', 'destination-over', 'destination-in', 'destination-out', 'destination-atop', 'lighter', 'copy', 'xor', 'multiply', 'screen', 'overlay', 'darken', 'lighten', 'color-dodge', 'color-burn', 'hard-light', 'soft-light', 'difference', 'exclusion', 'hue', 'saturation', 'color', 'luminosity'];
function getTransformSlice(ctx) {
return ctx._transformStack[ctx._stackIndex].slice();
}
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
/**
* Returns the string serialization of a CSS color, according to https://www.w3.org/TR/2dcontext/#serialization-of-a-color
*/
function serializeColor(value) {
return value.getAlpha() === 1 ? value.toHex() : value.toRgb();
}
class CanvasRenderingContext2D {
__getDrawCalls() {
return this._drawCalls.slice();
}
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/**
* Clear the list of draw calls
*/
__clearDrawCalls() {
this._drawCalls = [];
}
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
/**
* Every time a function call results in something that would have modified the state of the context,
* an event is added to this array. This goes for every property set, and draw call.
*/
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
__getEvents() {
return this._events.slice();
}
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; }
/**
* Clear the list of events
*/
__clearEvents() {
this._events = [];
}
// import HTMLCanvasElement from "./HTMLCanvasElement";
function parseCSSColor(value) {
var result = (0, _parseColor["default"])(value);
/**
* This array keeps track of the current path, so that fill and stroke operations can store the
* path.
*/
if (result.rgba && result.rgba[3] !== 1) {
return 'rgba(' + result.rgba.join(', ') + ')';
__getPath() {
return this._path.slice();
}
if (result.hex) {
var hex = result.hex; // shorthand #ABC
/**
* Clear the path and reset it to a single beginPath event.
*/
__clearPath() {
const event = (0, _createCanvasEvent.default)('beginPath', getTransformSlice(this), {});
// The clipping path should start after the initial beginPath instruction
this._clipIndex = 1;
this._path = [event];
}
if (hex[1] === hex[2] && hex[3] === hex[4] && hex[5] === hex[6]) {
return '#' + hex[1] + hex[3] + hex[5];
}
return result.hex;
/**
* Get the current clipping region.
*/
__getClippingRegion() {
return this._clipStack[this._stackIndex];
}
return void 0;
}
var testFuncs = ['setLineDash', 'getLineDash', 'setTransform', 'getTransform', 'getImageData', 'save', 'restore', 'createPattern', 'createRadialGradient', 'addHitRegion', 'arc', 'arcTo', 'beginPath', 'clip', 'closePath', 'scale', 'stroke', 'clearHitRegions', 'clearRect', 'fillRect', 'strokeRect', 'rect', 'resetTransform', 'translate', 'moveTo', 'lineTo', 'bezierCurveTo', 'createLinearGradient', 'ellipse', 'measureText', 'rotate', 'drawImage', 'drawFocusIfNeeded', 'isPointInPath', 'isPointInStroke', 'putImageData', 'strokeText', 'fillText', 'quadraticCurveTo', 'removeHitRegion', 'fill', 'transform', 'scrollPathIntoView', 'createImageData'];
var compositeOperations = ['source-over', 'source-in', 'source-out', 'source-atop', 'destination-over', 'destination-in', 'destination-out', 'destination-atop', 'lighter', 'copy', 'xor', 'multiply', 'screen', 'overlay', 'darken', 'lighten', 'color-dodge', 'color-burn', 'hard-light', 'soft-light', 'difference', 'exclusion', 'hue', 'saturation', 'color', 'luminosity'];
function getTransformSlice(ctx) {
return ctx._transformStack[ctx._stackIndex].slice();
}
var CanvasRenderingContext2D =
/*#__PURE__*/
function () {
_createClass(CanvasRenderingContext2D, [{
key: "__getDrawCalls",
constructor(canvas, contextAttributes) {
/**

@@ -69,86 +89,36 @@ * Every time a function call would result in a drawing operation, it should be added to this array.

*/
value: function __getDrawCalls() {
return this._drawCalls.slice();
}
/**
* Every time a function call results in something that would have modified the state of the context,
* an event is added to this array. This goes for every property set, and draw call.
*/
}, {
key: "__getEvents",
value: function __getEvents(ctx) {
return this._events.slice();
}
/**
* This array keeps track of the current path, so that fill and stroke operations can store the
* path.
*/
}, {
key: "__getPath",
value: function __getPath(ctx) {
return ctx._path.slice();
}
}]);
function CanvasRenderingContext2D(canvas, contextAttributes) {
var _this = this;
_classCallCheck(this, CanvasRenderingContext2D);
_defineProperty(this, "_drawCalls", []);
_defineProperty(this, "_events", []);
_defineProperty(this, "_path", [(0, _createCanvasEvent["default"])('beginPath', [1, 0, 0, 1, 0, 0], {})]);
_defineProperty(this, "_path", [(0, _createCanvasEvent.default)('beginPath', [1, 0, 0, 1, 0, 0], {})]);
_defineProperty(this, "_directionStack", ['inherit']);
_defineProperty(this, "_fillStyleStack", ['#000']);
_defineProperty(this, "_fillStyleStack", ['#000000']);
_defineProperty(this, "_filterStack", ['none']);
_defineProperty(this, "_fontStack", ['10px sans-serif']);
_defineProperty(this, "_globalAlphaStack", [1.0]);
_defineProperty(this, "_globalCompositeOperationStack", ['source-over']);
_defineProperty(this, "_imageSmoothingEnabledStack", [true]);
_defineProperty(this, "_imageSmoothingQualityStack", ['low']);
_defineProperty(this, "_lineCapStack", ['butt']);
_defineProperty(this, "_lineDashOffsetStack", [0]);
_defineProperty(this, "_lineDashStack", [[]]);
_defineProperty(this, "_lineJoinStack", ['miter']);
_defineProperty(this, "_lineWidthStack", [1]);
_defineProperty(this, "_miterLimitStack", [10]);
_defineProperty(this, "_shadowBlurStack", [0]);
_defineProperty(this, "_shadowColorStack", ['rgba(0, 0, 0, 0)']);
_defineProperty(this, "_shadowOffsetXStack", [0]);
_defineProperty(this, "_shadowOffsetYStack", [0]);
_defineProperty(this, "_stackIndex", 0);
_defineProperty(this, "_strokeStyleStack", ['#000']);
_defineProperty(this, "_strokeStyleStack", ['#000000']);
_defineProperty(this, "_textAlignStack", ['start']);
_defineProperty(this, "_textBaselineStack", ['alphabetic']);
_defineProperty(this, "_transformStack", [[1, 0, 0, 1, 0, 0]]);
testFuncs.forEach(function (key) {
_this[key] = jest.fn(CanvasRenderingContext2D.prototype[key].bind(_this));
_defineProperty(this, "_clipStack", [[]]);
/**
* This index points to the next path item that should be written to the clipStack
* when ctx.clip() is called.
*/
_defineProperty(this, "_clipIndex", 1);
testFuncs.forEach(key => {
this[key] = jest.fn(CanvasRenderingContext2D.prototype[key].bind(this));
});

@@ -158,1430 +128,1125 @@ this._canvas = canvas;

}
addHitRegion(options = {}) {
const {
path,
fillRule,
id,
parentID,
cursor,
control,
label,
role
} = options;
if (!path && !id) throw new DOMException('ConstraintError', "Failed to execute 'addHitRegion' on '" + this.constructor.name + "': Both id and control are null.");
if (fillRule && fillRule !== 'evenodd' && fillRule !== 'nonzero') throw new TypeError("Failed to execute 'addHitRegion' on '" + this.constructor.name + "': The provided value '" + fillRule + "' is not a valid enum value of type CanvasFillRule.");
this._events.push((0, _createCanvasEvent.default)('addHitRegion', getTransformSlice(this), {
path,
fillRule,
id,
parentID,
cursor,
control,
label,
role
}));
}
getContextAttributes() {
return this._contextAttributes;
}
arc(x, y, radius, startAngle, endAngle, anticlockwise = false) {
if (arguments.length < 5) throw new TypeError("Failed to execute 'arc' on '" + this.constructor.name + "': 5 arguments required, but only " + arguments.length + ' present.');
const xResult = Number(x);
const yResult = Number(y);
const radiusResult = Number(radius);
const startAngleResult = Number(startAngle);
const endAngleResult = Number(endAngle);
const anticlockwiseResult = Boolean(anticlockwise);
_createClass(CanvasRenderingContext2D, [{
key: "addHitRegion",
value: function addHitRegion() {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var path = options.path,
fillRule = options.fillRule,
id = options.id,
parentID = options.parentID,
cursor = options.cursor,
control = options.control,
label = options.label,
role = options.role;
if (!path && !id) throw new DOMException('ConstraintError', 'Failed to execute \'addHitRegion\' on \'' + this.constructor.name + '\': Both id and control are null.');
if (fillRule && fillRule !== 'evenodd' && fillRule !== 'nonzero') throw new TypeError('Failed to execute \'addHitRegion\' on \'' + this.constructor.name + '\': The provided value \'' + fillRule + '\' is not a valid enum value of type CanvasFillRule.');
this._events.push((0, _createCanvasEvent["default"])('addHitRegion', getTransformSlice(this), {
path: path,
fillRule: fillRule,
id: id,
parentID: parentID,
cursor: cursor,
control: control,
label: label,
role: role
}));
// quick is finite check
if (!Number.isFinite(xResult + yResult + radiusResult + startAngleResult + endAngleResult)) return;
if (Number(radius) < 0) throw new DOMException('IndexSizeError', "Failed to execute 'arc' on '" + this.constructor.name + "': The radius provided (" + radius + ') is negative.');
const event = (0, _createCanvasEvent.default)('arc', getTransformSlice(this), {
x: xResult,
y: yResult,
radius: radiusResult,
startAngle: startAngleResult,
endAngle: endAngleResult,
anticlockwise: anticlockwiseResult
});
this._path.push(event);
this._events.push(event);
}
arcTo(cpx1, cpy1, cpx2, cpy2, radius) {
if (arguments.length < 5) throw new DOMException('IndexSizeError', "Failed to execute 'arcTo' on '" + this.constructor.name + "': 5 arguments required, but only " + arguments.length + ' present.');
const cpx1Result = Number(cpx1);
const cpy1Result = Number(cpy1);
const cpx2Result = Number(cpx2);
const cpy2Result = Number(cpy2);
const radiusResult = Number(radius);
if (!Number.isFinite(cpx1Result + cpx2Result + cpy1Result + cpy2Result + radiusResult)) return;
if (radiusResult < 0) throw new TypeError("Failed to execute 'arcTo' on '" + this.constructor.name + "': The radius provided (" + radius + ') is negative.');
const event = (0, _createCanvasEvent.default)('arcTo', getTransformSlice(this), {
cpx1: cpx1Result,
cpy1: cpy1Result,
cpx2: cpx2Result,
cpy2: cpy2Result,
radius: radiusResult
});
this._path.push(event);
this._events.push(event);
}
beginPath() {
this.__clearPath();
// push the generated beginPath to the event list
this._events.push(this._path[0]);
}
bezierCurveTo(cpx1, cpy1, cpx2, cpy2, x, y) {
if (arguments.length < 6) throw new TypeError("Failed to execute 'bezierCurveTo' on '" + this.constructor.name + "': 6 arguments required, but only " + arguments.length + ' present.');
const cpx1Result = Number(cpx1);
const cpy1Result = Number(cpy1);
const cpx2Result = Number(cpx2);
const cpy2Result = Number(cpy2);
const xResult = Number(x);
const yResult = Number(y);
if (!Number.isFinite(cpx1Result + cpy1Result + cpx2Result + cpy2Result + xResult + yResult)) return;
const event = (0, _createCanvasEvent.default)('bezierCurveTo', getTransformSlice(this), {
cpx1,
cpy1,
cpx2,
cpy2,
x,
y
});
this._path.push(event);
this._events.push(event);
}
get canvas() {
return this._canvas;
}
clearHitRegions() {
const event = (0, _createCanvasEvent.default)('clearHitRegions', getTransformSlice(this), {});
this._events.push(event);
}
clearRect(x, y, width, height) {
if (arguments.length < 4) throw new TypeError("Failed to execute 'clearRect' on '" + this.constructor.name + "': 4 arguments required, but only " + arguments.length + ' present.');
const xResult = Number(x);
const yResult = Number(y);
const widthResult = Number(width);
const heightResult = Number(height);
if (!Number.isFinite(x + y + width + height)) return;
const event = (0, _createCanvasEvent.default)('clearRect', getTransformSlice(this), {
x: xResult,
y: yResult,
width: widthResult,
height: heightResult
});
this._events.push(event);
this._drawCalls.push(event);
}
clip(path, fillRule) {
let clipPath;
if (arguments.length === 0) {
fillRule = 'nonzero';
path = this._path.slice();
clipPath = path.slice(this._clipIndex);
this._clipIndex = path.length;
} else {
if (arguments.length === 1) fillRule = 'nonzero';
if (path instanceof _Path2D.default) {
fillRule = String(fillRule);
if (fillRule !== 'nonzero' && fillRule !== 'evenodd') throw new TypeError("Failed to execute 'clip' on '" + this.constructor.name + "': The provided value '" + fillRule + "' is not a valid enum value of type CanvasFillRule.");
path = path._path.slice();
clipPath = path;
} else {
fillRule = String(path);
if (fillRule !== 'nonzero' && fillRule !== 'evenodd') throw new TypeError("Failed to execute 'clip' on '" + this.constructor.name + "': The provided value '" + fillRule + "' is not a valid enum value of type CanvasFillRule.");
path = this._path.slice();
clipPath = path.slice(this._clipIndex);
this._clipIndex = path.length;
}
}
}, {
key: "getContextAttributes",
value: function getContextAttributes() {
return this._contextAttributes;
}
}, {
key: "arc",
value: function arc(x, y, radius, startAngle, endAngle) {
var anticlockwise = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : false;
if (arguments.length < 5) throw new TypeError('Failed to execute \'arc\' on \'' + this.constructor.name + '\': 5 arguments required, but only ' + arguments.length + ' present.');
var xResult = Number(x);
var yResult = Number(y);
var radiusResult = Number(radius);
var startAngleResult = Number(startAngle);
var endAngleResult = Number(endAngle);
var anticlockwiseResult = Boolean(anticlockwise); // quick is finite check
if (!Number.isFinite(xResult + yResult + radiusResult + startAngleResult + endAngleResult)) return;
if (Number(radius) < 0) throw new DOMException('IndexSizeError', 'Failed to execute \'arc\' on \'' + this.constructor.name + '\': The radius provided (' + radius + ') is negative.');
var event = (0, _createCanvasEvent["default"])('arc', getTransformSlice(this), {
x: xResult,
y: yResult,
radius: radiusResult,
startAngle: startAngleResult,
endAngle: endAngleResult,
anticlockwise: anticlockwiseResult
const event = (0, _createCanvasEvent.default)('clip', getTransformSlice(this), {
path,
fillRule
});
this._path.push(event);
this._events.push(event);
const currentClip = this._clipStack[this._stackIndex];
this._clipStack[this._stackIndex] = currentClip.concat(clipPath);
}
closePath() {
const event = (0, _createCanvasEvent.default)('closePath', getTransformSlice(this), {});
this._events.push(event);
this._path.push(event);
}
createImageData(width, height) {
if (arguments.length < 1) throw new TypeError("Failed to execute 'createImageData' on '" + this.constructor.name + "': 1 argument required, but only 0 present.");else if (arguments.length === 1) {
if (!(width instanceof ImageData)) throw new TypeError("Failed to execute 'createImageData' on '" + this.constructor.name + "': parameter 1 is not of type 'ImageData'.");
let result = new ImageData(width.width, width.height);
result.data.set(width.data);
const event = (0, _createCanvasEvent.default)('createImageData', getTransformSlice(this), {
width: width.width,
height: width.height
});
this._path.push(event);
this._events.push(event);
}
}, {
key: "arcTo",
value: function arcTo(cpx1, cpy1, cpx2, cpy2, radius) {
if (arguments.length < 5) throw new DOMException('IndexSizeError', 'Failed to execute \'arcTo\' on \'' + this.constructor.name + '\': 5 arguments required, but only ' + arguments.length + ' present.');
var cpx1Result = Number(cpx1);
var cpy1Result = Number(cpy1);
var cpx2Result = Number(cpx2);
var cpy2Result = Number(cpy2);
var radiusResult = Number(radius);
if (!Number.isFinite(cpx1Result + cpx2Result + cpy1Result + cpy2Result + radiusResult)) return;
if (radiusResult < 0) throw new TypeError('Failed to execute \'arcTo\' on \'' + this.constructor.name + '\': The radius provided (' + radius + ') is negative.');
var event = (0, _createCanvasEvent["default"])('arcTo', getTransformSlice(this), {
cpx1: cpx1Result,
cpy1: cpy1Result,
cpx2: cpx2Result,
cpy2: cpy2Result,
radius: radiusResult
return result;
} else {
width = Math.abs(Number(width));
height = Math.abs(Number(height));
if (!Number.isFinite(width) || width === 0) throw new TypeError("Failed to execute 'createImageData' on '" + this.constructor.name + "': The source width is 0.");
if (!Number.isFinite(height) || height === 0) throw new TypeError("Failed to execute 'createImageData' on '" + this.constructor.name + "': The source height is 0.");
const event = (0, _createCanvasEvent.default)('createImageData', getTransformSlice(this), {
width,
height
});
this._path.push(event);
this._events.push(event);
return new ImageData(width, height);
}
}, {
key: "beginPath",
value: function beginPath() {
var event = (0, _createCanvasEvent["default"])('beginPath', getTransformSlice(this), {});
this._path = [event];
this._events.push(event);
}
}, {
key: "bezierCurveTo",
value: function bezierCurveTo(cpx1, cpy1, cpx2, cpy2, x, y) {
if (arguments.length < 6) throw new TypeError('Failed to execute \'bezierCurveTo\' on \'' + this.constructor.name + '\': 6 arguments required, but only ' + arguments.length + ' present.');
var cpx1Result = Number(cpx1);
var cpy1Result = Number(cpy1);
var cpx2Result = Number(cpx2);
var cpy2Result = Number(cpy2);
var xResult = Number(x);
var yResult = Number(y);
if (!Number.isFinite(cpx1Result + cpy1Result + cpx2Result + cpy2Result + xResult + yResult)) return;
var event = (0, _createCanvasEvent["default"])('bezierCurveTo', getTransformSlice(this), {
cpx1: cpx1,
cpy1: cpy1,
cpx2: cpx2,
cpy2: cpy2,
x: x,
y: y
}
createLinearGradient(x0, y0, x1, y1) {
if (arguments.length < 4) throw new TypeError("Failed to execute 'createLinearGradient' on '" + this.constructor.name + "': 4 arguments required, but only " + arguments.length + ' present.');
const x0Result = Number(x0);
const y0Result = Number(y0);
const x1Result = Number(x1);
const y1Result = Number(y1);
if (!Number.isFinite(x0Result + y0Result + x1Result + y1Result)) throw new TypeError("Failed to execute 'createLinearGradient' on '" + this.constructor.name + "': The provided double value is non-finite.");
const event = (0, _createCanvasEvent.default)('createLinearGradient', getTransformSlice(this), {
x0: x0Result,
y0: y0Result,
x1: x1Result,
y1: y1Result
});
this._events.push(event);
return new CanvasGradient();
}
createPattern(image, type) {
if (arguments.length === 1) throw new TypeError("Failed to execute 'createPattern' on '" + this.constructor.name + "': 2 arguments required, but only 1 present.");
if (type === null) type = 'repeat';
if (type === '') type = 'repeat';
if (type === 'repeat' || type === 'repeat-x' || type === 'repeat-y' || type === 'no-repeat') {
const event = (0, _createCanvasEvent.default)('createPattern', getTransformSlice(this), {
image,
type
});
this._path.push(event);
this._events.push(event);
if (image instanceof ImageBitmap) {
if (image._closed) throw new DOMException('InvalidStateError', "Failed to execute 'createPattern' on 'CanvasRenderingContext2D': The image source is detached.");
this._events.push(event);
return new _CanvasPattern.default();
}
if (image instanceof HTMLImageElement) {
this._events.push(event);
return new _CanvasPattern.default();
}
if (image instanceof HTMLVideoElement) {
this._events.push(event);
return new _CanvasPattern.default();
}
if (image instanceof HTMLCanvasElement) {
this._events.push(event);
return new _CanvasPattern.default();
}
} else {
throw new TypeError("Failed to execute 'createPattern' on '" + this.constructor.name + "': The provided type ('" + type + "') is not one of 'repeat', 'no-repeat', 'repeat-x', or 'repeat-y'.");
}
}, {
key: "clearHitRegions",
value: function clearHitRegions() {
var event = (0, _createCanvasEvent["default"])('clearHitRegions', getTransformSlice(this), {});
this._events.push(event);
}
}, {
key: "clearRect",
value: function clearRect(x, y, width, height) {
if (arguments.length < 4) throw new TypeError('Failed to execute \'clearRect\' on \'' + this.constructor.name + '\': 4 arguments required, but only ' + arguments.length + ' present.');
var xResult = Number(x);
var yResult = Number(y);
var widthResult = Number(width);
var heightResult = Number(height);
if (!Number.isFinite(x + y + width + height)) return;
var event = (0, _createCanvasEvent["default"])('clearRect', getTransformSlice(this), {
x: xResult,
y: yResult,
width: widthResult,
height: heightResult
throw new TypeError("Failed to execute 'createPattern' on '" + this.constructor.name + "': The provided value is not of type '(CSSImageValue or HTMLImageElement or SVGImageElement or HTMLVideoElement or HTMLCanvasElement or ImageBitmap or OffscreenCanvas)'");
}
createRadialGradient(x0, y0, r0, x1, y1, r1) {
if (arguments.length < 6) throw new TypeError("Failed to execute 'createRadialGradient' on '" + this.constructor.name + "': 6 arguments required, but only " + arguments.length + ' present.');
const x0Result = Number(x0);
const y0Result = Number(y0);
const r0Result = Number(r0);
const x1Result = Number(x1);
const y1Result = Number(y1);
const r1Result = Number(r1);
if (!Number.isFinite(x0Result + y0Result + r0Result + x1Result + y1Result + r1Result)) throw new TypeError("Failed to execute 'createRadialGradient' on '" + this.constructor.name + "': The provided double value is non-finite.");
if (r0Result < 0) throw new DOMException('IndexSizeError', "Failed to execute 'createRadialGradient' on '" + this.constructor.name + "': The r0 provided is less than 0.");
if (r1Result < 0) throw new DOMException('IndexSizeError', "Failed to execute 'createRadialGradient' on '" + this.constructor.name + "': The r1 provided is less than 0.");
const event = (0, _createCanvasEvent.default)('createRadialGradient', getTransformSlice(this), {
x0: x0Result,
y0: y0Result,
r0: r0Result,
x1: x1Result,
y1: y1Result,
r1: r1Result
});
this._events.push(event);
return new CanvasGradient();
}
set currentTransform(value) {
if (value instanceof _DOMMatrix.default) {
this._transformStack[this._stackIndex][0] = value.a;
this._transformStack[this._stackIndex][1] = value.b;
this._transformStack[this._stackIndex][2] = value.c;
this._transformStack[this._stackIndex][3] = value.d;
this._transformStack[this._stackIndex][4] = value.e;
this._transformStack[this._stackIndex][5] = value.f;
const event = (0, _createCanvasEvent.default)('currentTransform', getTransformSlice(this), {
a: value.a,
b: value.b,
c: value.c,
d: value.d,
e: value.e,
f: value.f
});
this._events.push(event);
this._drawCalls.push(event);
}
}, {
key: "clip",
value: function clip(path, fillRule) {
if (arguments.length === 0) {
fillRule = 'nonzero';
path = this._path.slice();
} else {
if (arguments.length === 1) fillRule = 'nonzero';
if (path instanceof Path2D) {
fillRule = String(fillRule);
if (fillRule !== 'nonzero' && fillRule !== 'evenodd') throw new TypeError('Failed to execute \'clip\' on \'' + this.constructor.name + '\': The provided value \'' + fillRule + '\' is not a valid enum value of type CanvasFillRule.');
path = path._path.slice();
} else {
fillRule = String(path);
if (fillRule !== 'nonzero' && fillRule !== 'evenodd') throw new TypeError('Failed to execute \'clip\' on \'' + this.constructor.name + '\': The provided value \'' + fillRule + '\' is not a valid enum value of type CanvasFillRule.');
path = this._path.slice();
}
}
var event = (0, _createCanvasEvent["default"])('clip', getTransformSlice(this), {
path: path,
fillRule: fillRule
}
get currentTransform() {
return new _DOMMatrix.default(this._transformStack[this._stackIndex]);
}
set direction(value) {
if (value === 'rtl' || value === 'ltr' || value === 'inherit') {
this._directionStack[this._stackIndex] = value;
const event = (0, _createCanvasEvent.default)('direction', getTransformSlice(this), {
value
});
this._path.push(event);
this._events.push(event);
}
}, {
key: "closePath",
value: function closePath() {
var event = (0, _createCanvasEvent["default"])('closePath', getTransformSlice(this), {});
this._events.push(event);
this._path.push(event);
}
get direction() {
return this._directionStack[this._stackIndex];
}
drawFocusIfNeeded(path, element) {
if (arguments.length === 0) throw new TypeError("Failed to execute 'drawFocusIfNeeded' on '" + this.constructor.name + "': 1 argument required, but only 0 present.");
if (arguments.length === 2 && !(path instanceof _Path2D.default)) throw new TypeError("Failed to execute 'drawFocusIfNeeded' on '" + this.constructor.name + "': parameter 1 is not of type 'Path2D'.");
if (arguments.length === 1) {
element = path;
path = null;
}
}, {
key: "createImageData",
value: function createImageData(width, height) {
if (arguments.length < 1) throw new TypeError('Failed to execute \'createImageData\' on \'' + this.constructor.name + '\': 1 argument required, but only 0 present.');else if (arguments.length === 1) {
if (!(width instanceof ImageData)) throw new TypeError('Failed to execute \'createImageData\' on \'' + this.constructor.name + '\': parameter 1 is not of type \'ImageData\'.');
var result = new ImageData(width.width, width.height);
result.data.set(width.data);
var event = (0, _createCanvasEvent["default"])('createImageData', getTransformSlice(this), {
width: width.width,
height: width.height
});
this._events.push(event);
return result;
} else {
width = Math.abs(Number(width));
height = Math.abs(Number(height));
if (!Number.isFinite(width) || width === 0) throw new TypeError('Failed to execute \'createImageData\' on \'' + this.constructor.name + '\': The source width is 0.');
if (!Number.isFinite(height) || height === 0) throw new TypeError('Failed to execute \'createImageData\' on \'' + this.constructor.name + '\': The source height is 0.');
var _event = (0, _createCanvasEvent["default"])('createImageData', getTransformSlice(this), {
width: width,
height: height
});
this._events.push(_event);
return new ImageData(width, height);
}
if (!(element instanceof Element)) throw new TypeError("Failed to execute 'drawFocusIfNeeded' on '" + this.constructor.name + "': parameter " + arguments.length + " is not of type 'Element'.");
const event = (0, _createCanvasEvent.default)('drawFocusIfNeeded', getTransformSlice(this), {
path: path ? path._path : null,
element
});
this._events.push(event);
}
drawImage(img, sx, sy, sWidth, sHeight, dx, dy, dWidth, dHeight) {
if (arguments.length < 3) throw new TypeError("Failed to execute 'drawImage' on '" + this.constructor.name + "': 3 arguments required, but only " + arguments.length + ' present.');
if (arguments.length === 4 || arguments.length > 5 && arguments.length < 9) throw new TypeError("Failed to execute 'drawImage' on '" + this.constructor.name + "': Valid arities are: [3, 5, 9], but 4 arguments provided.");
let valid = false;
if (img instanceof HTMLImageElement) valid = true;
if (img instanceof ImageBitmap) {
if (img._closed) throw new DOMException('InvalidStateError', "DOMException: Failed to execute 'drawImage' on 'CanvasRenderingContext2D': The image source is detached.");
valid = true;
}
}, {
key: "createLinearGradient",
value: function createLinearGradient(x0, y0, x1, y1) {
if (arguments.length < 4) throw new TypeError('Failed to execute \'createLinearGradient\' on \'' + this.constructor.name + '\': 4 arguments required, but only ' + arguments.length + ' present.');
var x0Result = Number(x0);
var y0Result = Number(y0);
var x1Result = Number(x1);
var y1Result = Number(y1);
if (!Number.isFinite(x0Result + y0Result + x1Result + y1Result)) throw new TypeError('Failed to execute \'createLinearGradient\' on \'' + this.constructor.name + '\': The provided double value is non-finite.');
var event = (0, _createCanvasEvent["default"])('createLinearGradient', getTransformSlice(this), {
x0: x0Result,
y0: y0Result,
x1: x1Result,
y1: y1Result
});
this._events.push(event);
return new CanvasGradient();
if (img instanceof HTMLVideoElement) valid = true;
if (img instanceof HTMLCanvasElement) valid = true;
if (!valid) throw new TypeError("Failed to execute 'drawImage' on '" + this.constructor.name + "': The provided value is not of type '(CSSImageValue or HTMLImageElement or SVGImageElement or HTMLVideoElement or HTMLCanvasElement or ImageBitmap or OffscreenCanvas)'");
const sxResult = Number(sx);
const syResult = Number(sy);
const sWidthResult = Number(sWidth);
const sHeightResult = Number(sHeight);
const dxResult = Number(dx);
const dyResult = Number(dy);
const dWidthResult = Number(dWidth);
const dHeightResult = Number(dHeight);
if (arguments.length === 3) {
if (!Number.isFinite(sxResult + syResult)) return;
sx = 0;
sy = 0;
sWidth = img.width;
sHeight = img.height;
dx = sxResult;
dy = syResult;
dWidth = img.width;
dHeight = img.height;
} else if (arguments.length === 5) {
if (!Number.isFinite(sxResult + syResult + sWidthResult + sHeightResult)) return;
sx = 0;
sy = 0;
sWidth = img.width;
sHeight = img.height;
dx = sxResult;
dy = syResult;
dWidth = sWidth;
dHeight = sHeight;
} else {
if (!Number.isFinite(sx + sy + sWidth + sHeight + dx + dy + dWidth + dHeight)) return;
sx = sxResult;
sy = syResult;
sWidth = sWidthResult;
sHeight = sHeightResult;
dx = dxResult;
dy = dyResult;
dWidth = dWidthResult;
dHeight = dHeightResult;
}
}, {
key: "createPattern",
value: function createPattern(image, type) {
if (arguments.length === 1) throw new TypeError('Failed to execute \'createPattern\' on \'' + this.constructor.name + '\': 2 arguments required, but only 1 present.');
if (type === null) type = 'repeat';
if (type === '') type = 'repeat';
if (type === 'repeat' || type === 'repeat-x' || type === 'repeat-y' || type === 'no-repeat') {
var event = (0, _createCanvasEvent["default"])('createPattern', getTransformSlice(this), {
image: image,
type: type
});
if (image instanceof ImageBitmap) {
if (image._closed) throw new DOMException('InvalidStateError', 'Failed to execute \'createPattern\' on \'CanvasRenderingContext2D\': The image source is detached.');
this._events.push(event);
return new _CanvasPattern["default"]();
}
if (image instanceof HTMLImageElement) {
this._events.push(event);
return new _CanvasPattern["default"]();
}
if (image instanceof HTMLVideoElement) {
this._events.push(event);
return new _CanvasPattern["default"]();
}
if (image instanceof HTMLCanvasElement) {
this._events.push(event);
return new _CanvasPattern["default"]();
}
const event = (0, _createCanvasEvent.default)('drawImage', getTransformSlice(this), {
img,
sx,
sy,
sWidth,
sHeight,
dx,
dy,
dWidth,
dHeight
});
this._events.push(event);
this._drawCalls.push(event);
}
ellipse(x, y, radiusX, radiusY, rotation, startAngle, endAngle, anticlockwise = false) {
if (arguments.length < 7) throw new TypeError("Failed to execute 'ellipse' on '" + this.constructor.name + "': 6 arguments required, but only " + arguments.length + ' present.');
const xResult = Number(x);
const yResult = Number(y);
const radiusXResult = Number(radiusX);
const radiusYResult = Number(radiusY);
const rotationResult = Number(rotation);
const startAngleResult = Number(startAngle);
const endAngleResult = Number(endAngle);
const anticlockwiseResult = Boolean(anticlockwise);
if (!Number.isFinite(xResult + yResult + radiusXResult + radiusYResult + rotationResult + startAngleResult + endAngleResult)) return;
if (Number(radiusX) < 0) throw new DOMException('IndexSizeError', "Failed to execute 'ellipse' on '" + this.constructor.name + "': The major-axis radius provided (" + radiusX + ') is negative.');
if (Number(radiusY) < 0) throw new DOMException('IndexSizeError', "Failed to execute 'ellipse' on '" + this.constructor.name + "': The minor-axis radius provided (" + radiusY + ') is negative.');
const event = (0, _createCanvasEvent.default)('ellipse', getTransformSlice(this), {
x: xResult,
y: yResult,
radiusX: radiusXResult,
radiusY: radiusYResult,
rotation: rotationResult,
startAngle: startAngleResult,
endAngle: endAngleResult,
anticlockwise: anticlockwiseResult
});
this._path.push(event);
this._events.push(event);
}
fill(path, fillRule) {
if (arguments.length === 0) {
fillRule = 'nonzero';
path = this._path.slice();
} else {
if (arguments.length === 1) fillRule = 'nonzero';
if (path instanceof _Path2D.default) {
fillRule = String(fillRule);
if (fillRule !== 'nonzero' && fillRule !== 'evenodd') throw new TypeError("Failed to execute 'clip' on '" + this.constructor.name + "': The provided value '" + fillRule + "' is not a valid enum value of type CanvasFillRule.");
path = path._path.slice();
} else {
throw new TypeError('Failed to execute \'createPattern\' on \'' + this.constructor.name + '\': The provided type (\'' + type + '\') is not one of \'repeat\', \'no-repeat\', \'repeat-x\', or \'repeat-y\'.');
fillRule = String(path);
if (fillRule !== 'nonzero' && fillRule !== 'evenodd') throw new TypeError("Failed to execute 'clip' on '" + this.constructor.name + "': The provided value '" + fillRule + "' is not a valid enum value of type CanvasFillRule.");
path = this._path.slice();
}
throw new TypeError('Failed to execute \'createPattern\' on \'' + this.constructor.name + '\': The provided value is not of type \'(CSSImageValue or HTMLImageElement or SVGImageElement or HTMLVideoElement or HTMLCanvasElement or ImageBitmap or OffscreenCanvas)\'');
}
}, {
key: "createRadialGradient",
value: function createRadialGradient(x0, y0, r0, x1, y1, r1) {
if (arguments.length < 6) throw new TypeError('Failed to execute \'createRadialGradient\' on \'' + this.constructor.name + '\': 6 arguments required, but only ' + arguments.length + ' present.');
var x0Result = Number(x0);
var y0Result = Number(y0);
var r0Result = Number(r0);
var x1Result = Number(x1);
var y1Result = Number(y1);
var r1Result = Number(r1);
if (!Number.isFinite(x0Result + y0Result + r0Result + x1Result + y1Result + r1Result)) throw new TypeError('Failed to execute \'createRadialGradient\' on \'' + this.constructor.name + '\': The provided double value is non-finite.');
if (r0Result < 0) throw new DOMException('IndexSizeError', 'Failed to execute \'createRadialGradient\' on \'' + this.constructor.name + '\': The r0 provided is less than 0.');
if (r1Result < 0) throw new DOMException('IndexSizeError', 'Failed to execute \'createRadialGradient\' on \'' + this.constructor.name + '\': The r1 provided is less than 0.');
var event = (0, _createCanvasEvent["default"])('createRadialGradient', getTransformSlice(this), {
x0: x0Result,
y0: y0Result,
r0: r0Result,
x1: x1Result,
y1: y1Result,
r1: r1Result
});
this._events.push(event);
return new CanvasGradient();
}
}, {
key: "drawFocusIfNeeded",
value: function drawFocusIfNeeded(path, element) {
if (arguments.length === 0) throw new TypeError('Failed to execute \'drawFocusIfNeeded\' on \'' + this.constructor.name + '\': 1 argument required, but only 0 present.');
if (arguments.length === 2 && !(path instanceof Path2D)) throw new TypeError('Failed to execute \'drawFocusIfNeeded\' on \'' + this.constructor.name + '\': parameter 1 is not of type \'Path2D\'.');
if (arguments.length === 1) {
element = path;
path = null;
}
if (!(element instanceof Element)) throw new TypeError('Failed to execute \'drawFocusIfNeeded\' on \'' + this.constructor.name + '\': parameter ' + arguments.length + ' is not of type \'Element\'.');
var event = (0, _createCanvasEvent["default"])('drawFocusIfNeeded', getTransformSlice(this), {
path: path ? path._path : null,
element: element
});
this._events.push(event);
}
}, {
key: "drawImage",
value: function drawImage(img, sx, sy, sWidth, sHeight, dx, dy, dWidth, dHeight) {
if (arguments.length < 3) throw new TypeError('Failed to execute \'drawImage\' on \'' + this.constructor.name + '\': 3 arguments required, but only ' + arguments.length + ' present.');
if (arguments.length === 4 || arguments.length > 5 && arguments.length < 9) throw new TypeError('Failed to execute \'drawImage\' on \'' + this.constructor.name + '\': Valid arities are: [3, 5, 9], but 4 arguments provided.');
var valid = false;
if (img instanceof HTMLImageElement) valid = true;
;
if (img instanceof ImageBitmap) {
if (img._closed) throw new DOMException('InvalidStateError', 'DOMException: Failed to execute \'drawImage\' on \'CanvasRenderingContext2D\': The image source is detached.');
const event = (0, _createCanvasEvent.default)('fill', getTransformSlice(this), {
path,
fillRule
});
this._events.push(event);
this._drawCalls.push(event);
}
fillRect(x, y, width, height) {
if (arguments.length < 4) throw new TypeError("Failed to execute 'fillRect' on '" + this.constructor.name + "': 4 arguments required, but only " + arguments.length + ' present.');
const xResult = Number(x);
const yResult = Number(y);
const widthResult = Number(width);
const heightResult = Number(height);
if (!Number.isFinite(x + y + width + height)) return;
const event = (0, _createCanvasEvent.default)('fillRect', getTransformSlice(this), {
x: xResult,
y: yResult,
width: widthResult,
height: heightResult
});
this._events.push(event);
this._drawCalls.push(event);
}
set fillStyle(value) {
let valid = false;
if (typeof value === 'string') {
try {
const result = new _mooColor.MooColor(value);
valid = true;
value = this._fillStyleStack[this._stackIndex] = serializeColor(result);
} catch (e) {
return;
}
if (img instanceof HTMLVideoElement) valid = true;
if (img instanceof HTMLCanvasElement) valid = true;
if (!valid) throw new TypeError('Failed to execute \'drawImage\' on \'' + this.constructor.name + '\': The provided value is not of type \'(CSSImageValue or HTMLImageElement or SVGImageElement or HTMLVideoElement or HTMLCanvasElement or ImageBitmap or OffscreenCanvas)\'');
var sxResult = Number(sx);
var syResult = Number(sy);
var sWidthResult = Number(sWidth);
var sHeightResult = Number(sHeight);
var dxResult = Number(dx);
var dyResult = Number(dy);
var dWidthResult = Number(dWidth);
var dHeightResult = Number(dHeight);
if (arguments.length === 3) {
if (!Number.isFinite(sxResult + syResult)) return;
sx = 0;
sy = 0;
sWidth = img.width;
sHeight = img.height;
dx = sxResult;
dy = syResult;
dWidth = img.width;
dHeight = img.height;
} else if (arguments.length === 5) {
if (!Number.isFinite(sxResult + syResult + sWidthResult + sHeightResult)) return;
sx = 0;
sy = 0;
sWidth = img.width;
sHeight = img.height;
dx = sxResult;
dy = syResult;
dWidth = sWidth;
dHeight = sHeight;
} else {
if (!Number.isFinite(sx + sy + sWidth + sHeight + dx + dy + dWidth + dHeight)) return;
sx = sxResult;
sy = syResult;
sWidth = sWidthResult;
sHeight = sHeightResult;
dx = dxResult;
dy = dyResult;
dWidth = dWidthResult;
dHeight = dHeightResult;
}
var event = (0, _createCanvasEvent["default"])('drawImage', getTransformSlice(this), {
img: img,
sx: sx,
sy: sy,
sWidth: sWidth,
sHeight: sHeight,
dx: dx,
dy: dy,
dWidth: dWidth,
dHeight: dHeight
});
this._events.push(event);
this._drawCalls.push(event);
} else if (value instanceof CanvasGradient || value instanceof _CanvasPattern.default) {
valid = true;
this._fillStyleStack[this._stackIndex] = value;
}
}, {
key: "ellipse",
value: function ellipse(x, y, radiusX, radiusY, rotation, startAngle, endAngle) {
var anticlockwise = arguments.length > 7 && arguments[7] !== undefined ? arguments[7] : false;
if (arguments.length < 7) throw new TypeError('Failed to execute \'ellipse\' on \'' + this.constructor.name + '\': 6 arguments required, but only ' + arguments.length + ' present.');
var xResult = Number(x);
var yResult = Number(y);
var radiusXResult = Number(radiusX);
var radiusYResult = Number(radiusY);
var rotationResult = Number(rotation);
var startAngleResult = Number(startAngle);
var endAngleResult = Number(endAngle);
var anticlockwiseResult = Boolean(anticlockwise);
if (!Number.isFinite(xResult + yResult + radiusXResult + radiusYResult + rotationResult + startAngleResult + endAngleResult)) return;
if (Number(radiusX) < 0) throw new DOMException('IndexSizeError', 'Failed to execute \'ellipse\' on \'' + this.constructor.name + '\': The major-axis radius provided (' + radiusX + ') is negative.');
if (Number(radiusY) < 0) throw new DOMException('IndexSizeError', 'Failed to execute \'ellipse\' on \'' + this.constructor.name + '\': The minor-axis radius provided (' + radiusY + ') is negative.');
var event = (0, _createCanvasEvent["default"])('ellipse', getTransformSlice(this), {
x: xResult,
y: yResult,
radiusX: radiusXResult,
radiusY: radiusYResult,
rotation: rotationResult,
startAngle: startAngleResult,
endAngle: endAngleResult,
anticlockwise: anticlockwiseResult
if (valid) {
const event = (0, _createCanvasEvent.default)('fillStyle', getTransformSlice(this), {
value
});
this._path.push(event);
this._events.push(event);
}
}, {
key: "fill",
value: function fill(path, fillRule) {
if (arguments.length === 0) {
fillRule = 'nonzero';
path = this._path.slice();
} else {
if (arguments.length === 1) fillRule = 'nonzero';
if (path instanceof Path2D) {
fillRule = String(fillRule);
if (fillRule !== 'nonzero' && fillRule !== 'evenodd') throw new TypeError('Failed to execute \'clip\' on \'' + this.constructor.name + '\': The provided value \'' + fillRule + '\' is not a valid enum value of type CanvasFillRule.');
path = path._path.slice();
} else {
fillRule = String(path);
if (fillRule !== 'nonzero' && fillRule !== 'evenodd') throw new TypeError('Failed to execute \'clip\' on \'' + this.constructor.name + '\': The provided value \'' + fillRule + '\' is not a valid enum value of type CanvasFillRule.');
path = this._path.slice();
}
}
var event = (0, _createCanvasEvent["default"])('fill', getTransformSlice(this), {
path: path,
fillRule: fillRule
}
get fillStyle() {
return this._fillStyleStack[this._stackIndex];
}
fillText(text, x, y, maxWidth) {
if (arguments.length < 3) throw new TypeError("Failed to execute 'fillText' on '" + this.constructor.name + "': 3 arguments required, but only " + arguments.length + ' present.');
const textResult = String(text);
const xResult = Number(x);
const yResult = Number(y);
const maxWidthResult = Number(maxWidth);
if (arguments.length === 3 && !Number.isFinite(xResult + yResult)) return;
if (arguments.length > 3 && !Number.isFinite(xResult + yResult + maxWidthResult)) return;
const event = (0, _createCanvasEvent.default)('fillText', getTransformSlice(this), {
text: textResult,
x: xResult,
y: yResult,
maxWidth: arguments.length === 3 ? null : maxWidthResult
});
this._events.push(event);
this._drawCalls.push(event);
}
set filter(value) {
if (value === '') value = 'none';
value = this._filterStack[this._stackIndex] = typeof value === 'string' ? value : 'none';
const event = (0, _createCanvasEvent.default)('filter', getTransformSlice(this), {
value
});
this._events.push(event);
}
get filter() {
return this._filterStack[this._stackIndex];
}
set font(value) {
let ex;
try {
const result = (0, _cssfontparser.default)(value);
value = this._fontStack[this._stackIndex] = result.toString();
const event = (0, _createCanvasEvent.default)('font', getTransformSlice(this), {
value
});
this._events.push(event);
this._drawCalls.push(event);
}
}, {
key: "fillRect",
value: function fillRect(x, y, width, height) {
if (arguments.length < 4) throw new TypeError('Failed to execute \'fillRect\' on \'' + this.constructor.name + '\': 4 arguments required, but only ' + arguments.length + ' present.');
var xResult = Number(x);
var yResult = Number(y);
var widthResult = Number(width);
var heightResult = Number(height);
if (!Number.isFinite(x + y + width + height)) return;
var event = (0, _createCanvasEvent["default"])('fillRect', getTransformSlice(this), {
x: xResult,
y: yResult,
width: widthResult,
height: heightResult
} catch (ex) {}
}
get font() {
return this._fontStack[this._stackIndex];
}
getImageData() {
return new ImageData(this._canvas.width, this._canvas.height);
}
getLineDash() {
return this._lineDashStack[this._stackIndex];
}
getTransform() {
return new _DOMMatrix.default(this._transformStack[this._stackIndex]);
}
set globalAlpha(value) {
value = Number(value);
if (!Number.isFinite(value)) return;
if (value < 0) return;
if (value > 1) return;
this._globalAlphaStack[this._stackIndex] = value;
const event = (0, _createCanvasEvent.default)('globalAlpha', getTransformSlice(this), {
value
});
this._events.push(event);
}
get globalAlpha() {
return this._globalAlphaStack[this._stackIndex];
}
set globalCompositeOperation(value) {
if (compositeOperations.indexOf(value) !== -1) {
this._globalCompositeOperationStack[this._stackIndex] = value;
const event = (0, _createCanvasEvent.default)('globalCompositeOperation', getTransformSlice(this), {
value
});
this._events.push(event);
this._drawCalls.push(event);
}
}, {
key: "fillText",
value: function fillText(text, x, y, maxWidth) {
if (arguments.length < 3) throw new TypeError('Failed to execute \'fillText\' on \'' + this.constructor.name + '\': 3 arguments required, but only ' + arguments.length + ' present.');
var textResult = String(text);
var xResult = Number(x);
var yResult = Number(y);
var maxWidthResult = Number(maxWidth);
if (arguments.length === 3 && !Number.isFinite(xResult + yResult)) return;
if (arguments.length > 3 && !Number.isFinite(xResult + yResult + maxWidthResult)) return;
var event = (0, _createCanvasEvent["default"])('fillText', getTransformSlice(this), {
text: textResult,
x: xResult,
y: yResult,
maxWidth: arguments.length === 3 ? null : maxWidthResult
}
get globalCompositeOperation() {
return this._globalCompositeOperationStack[this._stackIndex];
}
set imageSmoothingEnabled(value) {
value = this._imageSmoothingEnabledStack[this._stackIndex] = Boolean(value);
const event = (0, _createCanvasEvent.default)('imageSmoothingEnabled', getTransformSlice(this), {
value
});
this._events.push(event);
}
get imageSmoothingEnabled() {
return this._imageSmoothingEnabledStack[this._stackIndex];
}
set imageSmoothingQuality(value) {
if (value === 'high' || value === 'medium' || value === 'low') {
this._imageSmoothingQualityStack[this._stackIndex] = value;
const event = (0, _createCanvasEvent.default)('imageSmoothingQuality', getTransformSlice(this), {
value
});
this._events.push(event);
this._drawCalls.push(event);
}
}, {
key: "getImageData",
value: function getImageData() {
return new ImageData(this._canvas.width, this._canvas.height);
}
get imageSmoothingQuality() {
return this._imageSmoothingQualityStack[this._stackIndex];
}
isPointInPath(path, x, y, fillRule = 'nonzero') {
if (arguments.length < 2) throw new TypeError("Failed to execute 'isPointInPath' on '" + this.constructor.name + "': 2 arguments required, but only " + arguments.length + ' present.');
if (!(path instanceof _Path2D.default)) {
if (arguments.length > 2) {
fillRule = y;
}
y = x;
x = path;
}
}, {
key: "getLineDash",
value: function getLineDash() {
return this._lineDashStack[this._stackIndex];
}
}, {
key: "getTransform",
value: function getTransform() {
return new _DOMMatrix["default"](this._transformStack[this._stackIndex]);
}
}, {
key: "isPointInPath",
value: function isPointInPath(path, x, y) {
var fillRule = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'nonzero';
if (arguments.length < 2) throw new TypeError('Failed to execute \'isPointInPath\' on \'' + this.constructor.name + '\': 2 arguments required, but only ' + arguments.length + ' present.');
if (fillRule !== 'nonzero' && fillRule !== 'evenodd') throw new TypeError("Failed to execute 'isPointInPath' on '" + this.constructor.name + "': The provided value '" + fillRule + "' is not a valid enum value of type CanvasFillRule.");
const event = (0, _createCanvasEvent.default)('isPointInPath', getTransformSlice(this), {
x: Number(x),
y: Number(y),
fillRule,
path: path instanceof _Path2D.default ? path._path.slice() : this._path.slice()
});
this._events.push(event);
return false; // return false in a mocking environment, unless I can verify a point is actually within the path
}
if (!(path instanceof Path2D)) {
if (arguments.length > 2) {
fillRule = y;
}
y = x;
x = path;
}
if (fillRule !== 'nonzero' && fillRule !== 'evenodd') throw new TypeError('Failed to execute \'isPointInPath\' on \'' + this.constructor.name + '\': The provided value \'' + fillRule + '\' is not a valid enum value of type CanvasFillRule.');
var event = (0, _createCanvasEvent["default"])('isPointInPath', getTransformSlice(this), {
x: Number(x),
y: Number(y),
fillRule: fillRule,
path: path instanceof Path2D ? path._path.slice() : this._path.slice()
});
this._events.push(event);
return false; // return false in a mocking environment, unless I can verify a point is actually within the path
isPointInStroke(path, x, y) {
if (arguments.length < 2) throw new TypeError("Failed to execute 'isPointInStroke' on '" + this.constructor.name + "': 2 arguments required, but only " + arguments.length + ' present.');
if (!(path instanceof _Path2D.default)) {
y = x;
x = path;
}
}, {
key: "isPointInStroke",
value: function isPointInStroke(path, x, y) {
if (arguments.length < 2) throw new TypeError('Failed to execute \'isPointInStroke\' on \'' + this.constructor.name + '\': 2 arguments required, but only ' + arguments.length + ' present.');
const event = (0, _createCanvasEvent.default)('isPointInPath', getTransformSlice(this), {
x: Number(x),
y: Number(y),
path: path instanceof _Path2D.default ? path._path.slice() : this._path.slice()
});
this._events.push(event);
return false; // return false in a mocking environment, unless I can verify a point is actually within the path
}
if (!(path instanceof Path2D)) {
y = x;
x = path;
}
var event = (0, _createCanvasEvent["default"])('isPointInPath', getTransformSlice(this), {
x: Number(x),
y: Number(y),
path: path instanceof Path2D ? path._path.slice() : this._path.slice()
set lineCap(value) {
if (value === 'butt' || value === 'round' || value === 'square') {
this._lineCapStack[this._stackIndex] = value;
const event = (0, _createCanvasEvent.default)('lineCap', getTransformSlice(this), {
value
});
this._events.push(event);
return false; // return false in a mocking environment, unless I can verify a point is actually within the path
}
}, {
key: "lineTo",
value: function lineTo(x, y) {
if (arguments.length < 2) throw new TypeError('Failed to execute \'lineTo\' on \'' + this.constructor.name + '\': 2 arguments required, but only ' + arguments.length + ' present.');
var xResult = Number(x);
var yResult = Number(y);
if (!Number.isFinite(xResult + yResult)) return;
var event = (0, _createCanvasEvent["default"])('lineTo', getTransformSlice(this), {
x: xResult,
y: yResult
}
get lineCap() {
return this._lineCapStack[this._stackIndex];
}
set lineDashOffset(value) {
const result = Number(value);
if (Number.isFinite(result)) {
this._lineDashOffsetStack[this._stackIndex] = result;
const event = (0, _createCanvasEvent.default)('lineDashOffset', getTransformSlice(this), {
value
});
this._events.push(event);
this._path.push(event);
}
}, {
key: "measureText",
value: function measureText(text) {
if (arguments.length < 1) throw new TypeError('Failed to execute \'measureText\' on \'' + this.constructor.name + '\': 1 argument required, but only 0 present.');
text = text == null ? '' : text;
text = text.toString();
var event = (0, _createCanvasEvent["default"])('measureText', getTransformSlice(this), {
text: text
}
get lineDashOffset() {
return this._lineDashOffsetStack[this._stackIndex];
}
set lineJoin(value) {
if (value === 'round' || value === 'bevel' || value === 'miter') {
this._lineJoinStack[this._stackIndex] = value;
const event = (0, _createCanvasEvent.default)('lineJoin', getTransformSlice(this), {
value
});
this._events.push(event);
return new _TextMetrics["default"](text);
}
}, {
key: "moveTo",
value: function moveTo(x, y) {
if (arguments.length < 2) throw new TypeError('Failed to execute \'moveTo\' on \'' + this.constructor.name + '\': 2 arguments required, but only ' + arguments.length + ' present.');
var xResult = Number(x);
var yResult = Number(y);
if (!Number.isFinite(x + y)) return;
var event = (0, _createCanvasEvent["default"])('moveTo', getTransformSlice(this), {
x: xResult,
y: yResult
}
get lineJoin() {
return this._lineJoinStack[this._stackIndex];
}
lineTo(x, y) {
if (arguments.length < 2) throw new TypeError("Failed to execute 'lineTo' on '" + this.constructor.name + "': 2 arguments required, but only " + arguments.length + ' present.');
const xResult = Number(x);
const yResult = Number(y);
if (!Number.isFinite(xResult + yResult)) return;
const event = (0, _createCanvasEvent.default)('lineTo', getTransformSlice(this), {
x: xResult,
y: yResult
});
this._events.push(event);
this._path.push(event);
}
set lineWidth(value) {
const result = Number(value);
if (Number.isFinite(result) && result > 0) {
this._lineWidthStack[this._stackIndex] = result;
const event = (0, _createCanvasEvent.default)('lineWidth', getTransformSlice(this), {
value: result
});
this._events.push(event);
this._path.push(event);
}
}, {
key: "putImageData",
value: function putImageData(data, x, y, dirtyX, dirtyY, dirtyWidth, dirtyHeight) {
if (arguments.length < 3) throw new TypeError('Failed to execute \'putImageData\' on \'' + this.constructor.name + '\': 3 arguments required, but only ' + arguments.length + ' present.');
if (arguments.length > 3 && arguments.length < 7) throw new TypeError('Failed to execute \'putImageData\' on \'' + this.constructor.name + '\': Valid arities are: [3, 7], but ' + arguments.length + ' arguments provided.');
if (!(data instanceof ImageData)) throw new TypeError('Failed to execute \'putImageData\' on \'' + this.constructor.name + '\': parameter 1 is not of type \'ImageData\'.');
var xResult = Number(x);
var yResult = Number(y);
var dirtyXResult = Number(dirtyX);
var dirtyYResult = Number(dirtyY);
var dirtyWidthResult = Number(dirtyWidth);
var dirtyHeightResult = Number(dirtyHeight);
if (arguments.length === 3) {
if (!Number.isFinite(xResult + yResult)) return;
} else {
if (!Number.isFinite(xResult + yResult + dirtyXResult + dirtyYResult + dirtyWidthResult + dirtyHeightResult)) return;
}
var event = (0, _createCanvasEvent["default"])('putImageData', getTransformSlice(this), {
x: xResult,
y: yResult,
dirtyX: dirtyXResult,
dirtyY: dirtyYResult,
dirtyWidth: dirtyWidthResult,
dirtyHeight: dirtyHeightResult
}
get lineWidth() {
return this._lineWidthStack[this._stackIndex];
}
measureText(text) {
if (arguments.length < 1) throw new TypeError("Failed to execute 'measureText' on '" + this.constructor.name + "': 1 argument required, but only 0 present.");
text = text == null ? '' : text;
text = text.toString();
const event = (0, _createCanvasEvent.default)('measureText', getTransformSlice(this), {
text
});
this._events.push(event);
return new _TextMetrics.default(text);
}
set miterLimit(value) {
const result = Number(value);
if (Number.isFinite(result) && result > 0) {
this._miterLimitStack[this._stackIndex] = result;
const event = (0, _createCanvasEvent.default)('lineWidth', getTransformSlice(this), {
value: result
});
this._events.push(event);
}
}, {
key: "quadraticCurveTo",
value: function quadraticCurveTo(cpx, cpy, x, y) {
if (arguments.length < 4) throw new TypeError('Failed to execute \'quadraticCurveTo\' on \'' + this.constructor.name + '\': 4 arguments required, but only ' + arguments.length + ' present.');
var cpxResult = Number(cpx);
var cpyResult = Number(cpy);
var xResult = Number(x);
var yResult = Number(y);
if (!Number.isFinite(cpxResult + cpyResult + xResult + yResult)) return;
var event = (0, _createCanvasEvent["default"])('quadraticCurveTo', getTransformSlice(this), {
cpx: cpxResult,
cpy: cpyResult,
}
get miterLimit() {
return this._miterLimitStack[this._stackIndex];
}
moveTo(x, y) {
if (arguments.length < 2) throw new TypeError("Failed to execute 'moveTo' on '" + this.constructor.name + "': 2 arguments required, but only " + arguments.length + ' present.');
const xResult = Number(x);
const yResult = Number(y);
if (!Number.isFinite(x + y)) return;
const event = (0, _createCanvasEvent.default)('moveTo', getTransformSlice(this), {
x: xResult,
y: yResult
});
this._events.push(event);
this._path.push(event);
}
putImageData(data, x, y, dirtyX, dirtyY, dirtyWidth, dirtyHeight) {
if (arguments.length < 3) throw new TypeError("Failed to execute 'putImageData' on '" + this.constructor.name + "': 3 arguments required, but only " + arguments.length + ' present.');
if (arguments.length > 3 && arguments.length < 7) throw new TypeError("Failed to execute 'putImageData' on '" + this.constructor.name + "': Valid arities are: [3, 7], but " + arguments.length + ' arguments provided.');
if (!(data instanceof ImageData)) throw new TypeError("Failed to execute 'putImageData' on '" + this.constructor.name + "': parameter 1 is not of type 'ImageData'.");
const xResult = Number(x);
const yResult = Number(y);
const dirtyXResult = Number(dirtyX);
const dirtyYResult = Number(dirtyY);
const dirtyWidthResult = Number(dirtyWidth);
const dirtyHeightResult = Number(dirtyHeight);
if (arguments.length === 3) {
if (!Number.isFinite(xResult + yResult)) return;
} else {
if (!Number.isFinite(xResult + yResult + dirtyXResult + dirtyYResult + dirtyWidthResult + dirtyHeightResult)) return;
}
const event = (0, _createCanvasEvent.default)('putImageData', getTransformSlice(this), {
x: xResult,
y: yResult,
dirtyX: dirtyXResult,
dirtyY: dirtyYResult,
dirtyWidth: dirtyWidthResult,
dirtyHeight: dirtyHeightResult
});
this._events.push(event);
}
quadraticCurveTo(cpx, cpy, x, y) {
if (arguments.length < 4) throw new TypeError("Failed to execute 'quadraticCurveTo' on '" + this.constructor.name + "': 4 arguments required, but only " + arguments.length + ' present.');
const cpxResult = Number(cpx);
const cpyResult = Number(cpy);
const xResult = Number(x);
const yResult = Number(y);
if (!Number.isFinite(cpxResult + cpyResult + xResult + yResult)) return;
const event = (0, _createCanvasEvent.default)('quadraticCurveTo', getTransformSlice(this), {
cpx: cpxResult,
cpy: cpyResult,
x: xResult,
y: yResult
});
this._events.push(event);
}
rect(x, y, width, height) {
if (arguments.length < 4) throw new TypeError("Failed to execute 'rect' on '" + this.constructor.name + "': 4 arguments required, but only " + arguments.length + ' present.');
if (!Number.isFinite(x + y + width + height)) return;
const xResult = Number(x);
const yResult = Number(y);
const widthResult = Number(width);
const heightResult = Number(height);
const event = (0, _createCanvasEvent.default)('rect', getTransformSlice(this), {
x: xResult,
y: yResult,
width: widthResult,
height: heightResult
});
this._events.push(event);
this._path.push(event);
}
removeHitRegion(id) {
if (arguments.length < 1) throw new TypeError("Failed to execute 'removeHitRegion' on '" + this.constructor.name + "': 1 argument required, but only " + arguments.length + ' present.');
const event = (0, _createCanvasEvent.default)('removeHitRegion', getTransformSlice(this), {
id
});
this._events.push(event);
}
resetTransform() {
this._transformStack[this._stackIndex][0] = 1;
this._transformStack[this._stackIndex][1] = 0;
this._transformStack[this._stackIndex][2] = 0;
this._transformStack[this._stackIndex][3] = 1;
this._transformStack[this._stackIndex][4] = 0;
this._transformStack[this._stackIndex][5] = 0;
const event = (0, _createCanvasEvent.default)('resetTransform', getTransformSlice(this), {
a: 1,
b: 0,
c: 0,
d: 1,
e: 0,
f: 0
});
this._events.push(event);
}
restore() {
if (this._stackIndex <= 0) return;
this._transformStack.pop();
this._clipStack.pop();
this._directionStack.pop();
this._fillStyleStack.pop();
this._filterStack.pop();
this._fontStack.pop();
this._globalAlphaStack.pop();
this._globalCompositeOperationStack.pop();
this._imageSmoothingEnabledStack.pop();
this._imageSmoothingQualityStack.pop();
this._lineCapStack.pop();
this._lineDashStack.pop();
this._lineDashOffsetStack.pop();
this._lineJoinStack.pop();
this._lineWidthStack.pop();
this._miterLimitStack.pop();
this._shadowBlurStack.pop();
this._shadowColorStack.pop();
this._shadowOffsetXStack.pop();
this._shadowOffsetYStack.pop();
this._strokeStyleStack.pop();
this._textAlignStack.pop();
this._textBaselineStack.pop();
this._stackIndex -= 1;
const event = (0, _createCanvasEvent.default)('restore', getTransformSlice(this), {});
this._events.push(event);
}
rotate(angle) {
if (arguments.length < 1) throw new TypeError("Failed to execute 'rotate' on '" + this.constructor.name + "': 1 argument required, but only 0 present.");
angle = Number(angle);
if (!Number.isFinite(angle)) return;
const a = this._transformStack[this._stackIndex][0];
const b = this._transformStack[this._stackIndex][1];
const c = this._transformStack[this._stackIndex][2];
const d = this._transformStack[this._stackIndex][3];
const cos = Math.cos(angle);
const sin = Math.sin(angle);
this._transformStack[this._stackIndex][0] = a * cos + c * sin;
this._transformStack[this._stackIndex][1] = b * cos + d * sin;
this._transformStack[this._stackIndex][2] = c * cos - a * sin;
this._transformStack[this._stackIndex][3] = d * cos - b * sin;
const event = (0, _createCanvasEvent.default)('rotate', getTransformSlice(this), {
angle
});
this._events.push(event);
}
save() {
const stackIndex = this._stackIndex;
this._transformStack.push(this._transformStack[stackIndex].slice());
this._directionStack.push(this._directionStack[stackIndex]);
this._fillStyleStack.push(this._fillStyleStack[stackIndex]);
this._filterStack.push(this._filterStack[stackIndex]);
this._fontStack.push(this._fontStack[stackIndex]);
this._globalAlphaStack.push(this._globalAlphaStack[stackIndex]);
this._globalCompositeOperationStack.push(this._globalCompositeOperationStack[stackIndex]);
this._imageSmoothingEnabledStack.push(this._imageSmoothingEnabledStack[stackIndex]);
this._imageSmoothingQualityStack.push(this._imageSmoothingQualityStack[stackIndex]);
this._lineCapStack.push(this._lineCapStack[stackIndex]);
this._lineDashStack.push(this._lineDashStack[stackIndex]);
this._lineDashOffsetStack.push(this._lineDashOffsetStack[stackIndex]);
this._lineJoinStack.push(this._lineJoinStack[stackIndex]);
this._lineWidthStack.push(this._lineWidthStack[stackIndex]);
this._miterLimitStack.push(this._miterLimitStack[stackIndex]);
this._shadowBlurStack.push(this._shadowBlurStack[stackIndex]);
this._shadowColorStack.push(this._shadowColorStack[stackIndex]);
this._shadowOffsetXStack.push(this._shadowOffsetXStack[stackIndex]);
this._shadowOffsetYStack.push(this._shadowOffsetYStack[stackIndex]);
this._strokeStyleStack.push(this._strokeStyleStack[stackIndex]);
this._textAlignStack.push(this._textAlignStack[stackIndex]);
this._textBaselineStack.push(this._textBaselineStack[stackIndex]);
this._clipStack.push(this._clipStack[stackIndex].slice());
this._stackIndex = stackIndex + 1;
const event = (0, _createCanvasEvent.default)('save', getTransformSlice(this), {});
this._events.push(event);
}
scale(x, y) {
if (arguments.length < 2) throw new TypeError("Failed to execute 'scale' on '" + this.constructor.name + "': 2 arguments required, but only " + arguments.length + ' present.');
const xResult = Number(x);
const yResult = Number(y);
if (Number.isFinite(xResult) && Number.isFinite(yResult)) {
this._transformStack[this._stackIndex][0] *= xResult;
this._transformStack[this._stackIndex][1] *= xResult;
this._transformStack[this._stackIndex][2] *= yResult;
this._transformStack[this._stackIndex][3] *= yResult;
const event = (0, _createCanvasEvent.default)('scale', getTransformSlice(this), {
x: xResult,
y: yResult
});
this._events.push(event);
}
}, {
key: "rect",
value: function rect(x, y, width, height) {
if (arguments.length < 4) throw new TypeError('Failed to execute \'rect\' on \'' + this.constructor.name + '\': 4 arguments required, but only ' + arguments.length + ' present.');
if (!Number.isFinite(x + y + width + height)) return;
var xResult = Number(x);
var yResult = Number(y);
var widthResult = Number(width);
var heightResult = Number(height);
var event = (0, _createCanvasEvent["default"])('rect', getTransformSlice(this), {
x: xResult,
y: yResult,
width: widthResult,
height: heightResult
});
this._events.push(event);
this._path.push(event);
}
}, {
key: "removeHitRegion",
value: function removeHitRegion(id) {
if (arguments.length < 1) throw new TypeError('Failed to execute \'removeHitRegion\' on \'' + this.constructor.name + '\': 1 argument required, but only ' + arguments.length + ' present.');
var event = (0, _createCanvasEvent["default"])('removeHitRegion', getTransformSlice(this), {
id: id
});
this._events.push(event);
}
}, {
key: "resetTransform",
value: function resetTransform() {
this._transformStack[this._stackIndex][0] = 1;
this._transformStack[this._stackIndex][1] = 0;
this._transformStack[this._stackIndex][2] = 0;
this._transformStack[this._stackIndex][3] = 1;
this._transformStack[this._stackIndex][4] = 0;
this._transformStack[this._stackIndex][5] = 0;
var event = (0, _createCanvasEvent["default"])('resetTransform', getTransformSlice(this), {
a: 1,
b: 0,
c: 0,
d: 1,
e: 0,
f: 0
});
this._events.push(event);
}
}, {
key: "restore",
value: function restore() {
if (this._stackIndex <= 0) return;
this._transformStack.pop();
this._directionStack.pop();
this._fillStyleStack.pop();
this._filterStack.pop();
this._fontStack.pop();
this._globalAlphaStack.pop();
this._globalCompositeOperationStack.pop();
this._imageSmoothingEnabledStack.pop();
this._imageSmoothingQualityStack.pop();
this._lineCapStack.pop();
this._lineDashStack.pop();
this._lineDashOffsetStack.pop();
this._lineJoinStack.pop();
this._lineWidthStack.pop();
this._miterLimitStack.pop();
this._shadowBlurStack.pop();
this._shadowColorStack.pop();
this._shadowOffsetXStack.pop();
this._shadowOffsetYStack.pop();
this._strokeStyleStack.pop();
this._textAlignStack.pop();
this._textBaselineStack.pop();
this._stackIndex -= 1;
var event = (0, _createCanvasEvent["default"])('restore', getTransformSlice(this), {});
this._events.push(event);
}
}, {
key: "rotate",
value: function rotate(angle) {
if (arguments.length < 1) throw new TypeError('Failed to execute \'rotate\' on \'' + this.constructor.name + '\': 1 argument required, but only 0 present.');
angle = Number(angle);
if (!Number.isFinite(angle)) return;
var a = this._transformStack[this._stackIndex][0];
var b = this._transformStack[this._stackIndex][1];
var c = this._transformStack[this._stackIndex][2];
var d = this._transformStack[this._stackIndex][3];
var cos = Math.cos(angle);
var sin = Math.sin(angle);
this._transformStack[this._stackIndex][0] = a * cos + c * sin;
this._transformStack[this._stackIndex][1] = b * cos + d * sin;
this._transformStack[this._stackIndex][2] = c * cos - a * sin;
this._transformStack[this._stackIndex][3] = d * cos - b * sin;
var event = (0, _createCanvasEvent["default"])('rotate', getTransformSlice(this), {
angle: angle
});
this._events.push(event);
}
}, {
key: "save",
value: function save() {
this._transformStack.push(this._transformStack[this._stackIndex]);
this._directionStack.push(this._directionStack[this._stackIndex]);
this._fillStyleStack.push(this._fillStyleStack[this._stackIndex]);
this._filterStack.push(this._filterStack[this._stackIndex]);
this._fontStack.push(this._fontStack[this._stackIndex]);
this._globalAlphaStack.push(this._globalAlphaStack[this._stackIndex]);
this._globalCompositeOperationStack.push(this._globalCompositeOperationStack[this._stackIndex]);
this._imageSmoothingEnabledStack.push(this._imageSmoothingEnabledStack[this._stackIndex]);
this._imageSmoothingQualityStack.push(this._imageSmoothingQualityStack[this._stackIndex]);
this._lineCapStack.push(this._lineCapStack[this._stackIndex]);
this._lineDashStack.push(this._lineDashStack[this._stackIndex]);
this._lineDashOffsetStack.push(this._lineDashOffsetStack[this._stackIndex]);
this._lineJoinStack.push(this._lineJoinStack[this._stackIndex]);
this._lineWidthStack.push(this._lineWidthStack[this.stackIndex]);
this._miterLimitStack.push(this._miterLimitStack[this._stackIndex]);
this._shadowBlurStack.push(this._shadowBlurStack[this._stackIndex]);
this._shadowColorStack.push(this._shadowColorStack[this._stackIndex]);
this._shadowOffsetXStack.push(this._shadowOffsetXStack[this._stackIndex]);
this._shadowOffsetYStack.push(this._shadowOffsetYStack[this._stackIndex]);
this._strokeStyleStack.push(this._strokeStyleStack[this._stackIndex]);
this._textAlignStack.push(this._textAlignStack[this._stackIndex]);
this._textBaselineStack.push(this._textBaselineStack[this._stackIndex]);
this._stackIndex += 1;
var event = (0, _createCanvasEvent["default"])('save', getTransformSlice(this), {});
this._events.push(event);
}
}, {
key: "scale",
value: function scale(x, y) {
if (arguments.length < 2) throw new TypeError('Failed to execute \'scale\' on \'' + this.constructor.name + '\': 2 arguments required, but only ' + arguments.length + ' present.');
var xResult = Number(x);
var yResult = Number(y);
if (Number.isFinite(xResult) && Number.isFinite(yResult)) {
this._transformStack[this._stackIndex][0] *= xResult;
this._transformStack[this._stackIndex][1] *= xResult;
this._transformStack[this._stackIndex][2] *= yResult;
this._transformStack[this._stackIndex][3] *= yResult;
var event = (0, _createCanvasEvent["default"])('scale', getTransformSlice(this), {
x: xResult,
y: yResult
});
this._events.push(event);
}
scrollPathIntoView(path) {
if (arguments.length > 0 && path instanceof _Path2D.default) path = path._path.slice();else path = this._path.slice();
const event = (0, _createCanvasEvent.default)('scrollPathIntoView', getTransformSlice(this), {
path
});
this._events.push(event);
}
setLineDash(lineDash) {
const isSequence = [Array, Int8Array, Uint8Array, Int16Array, Uint16Array, Int32Array, Uint32Array, Float32Array, Float64Array].reduce((left, right) => left || lineDash instanceof right, false);
if (!isSequence) throw new TypeError("Failed to execute 'setLineDash' on '" + this.constructor.name + "': The provided value cannot be converted to a sequence.");
let result = [];
for (let i = 0; i < lineDash.length; i++) {
const value = Number(lineDash[i]);
if (Number.isFinite(value) && value >= 0) {
result.push(value);
} else {
return;
}
}
}, {
key: "scrollPathIntoView",
value: function scrollPathIntoView(path) {
if (arguments.length > 0 && path instanceof Path2D) path = path._path.slice();else path = this._path.slice();
var event = (0, _createCanvasEvent["default"])('scrollPathIntoView', getTransformSlice(this), {
path: path
});
this._events.push(event);
}
}, {
key: "setLineDash",
value: function setLineDash(lineDash) {
var isSequence = [Array, Int8Array, Uint8Array, Int16Array, Uint16Array, Int32Array, Uint32Array, Float32Array, Float64Array].reduce(function (left, right) {
return left || lineDash instanceof right;
}, false);
if (!isSequence) throw new TypeError('Failed to execute \'setLineDash\' on \'' + this.constructor.name + '\': The provided value cannot be converted to a sequence.');
var result = [];
for (var i = 0; i < lineDash.length; i++) {
var value = Number(lineDash[i]);
if (Number.isFinite(value) && value >= 0) {
result.push(value);
} else {
return;
}
result = this._lineDashStack[this._stackIndex] = result.length % 2 === 1 ? result.concat(result) : result;
const event = (0, _createCanvasEvent.default)('setLineDash', getTransformSlice(this), {
segments: result.slice()
});
this._events.push(event);
}
setTransform(a, b, c, d, e, f) {
if (arguments.length === 0) {
a = 1;
b = 0;
c = 0;
d = 1;
e = 0;
f = 0;
} else if (arguments.length === 1) {
if (a instanceof _DOMMatrix.default) {
let transform = a;
a = transform.a;
b = transform.b;
c = transform.c;
d = transform.d;
e = transform.e;
f = transform.f;
} else {
throw new TypeError("Failed to execute 'setTransform' on '" + this.constructor.name + "': parameter " + a + " ('transform') is not an object.");
}
result = this._lineDashStack[this._stackIndex] = result.length % 2 === 1 ? result.concat(result) : result;
var event = (0, _createCanvasEvent["default"])('setLineDash', getTransformSlice(this), {
value: result.slice()
});
this._events.push(event);
} else if (arguments.length < 6) {
throw new TypeError("Failed to execute 'setTransform' on '" + this.constructor.name + "': Valid arities are: [0, 1, 6], but " + arguments.length + ' arguments provided.');
}
}, {
key: "setTransform",
value: function setTransform(a, b, c, d, e, f) {
if (arguments.length === 0) {
a = 1;
b = 0;
c = 0;
d = 1;
e = 0;
f = 0;
} else if (arguments.length === 1) {
if (a instanceof _DOMMatrix["default"]) {
var transform = a;
a = transform.a;
b = transform.b;
c = transform.c;
d = transform.d;
e = transform.e;
f = transform.f;
} else {
throw new TypeError('Failed to execute \'setTransform\' on \'' + this.constructor.name + '\': parameter ' + a + ' (\'transform\') is not an object.');
}
} else if (arguments.length < 6) {
throw new TypeError('Failed to execute \'setTransform\' on \'' + this.constructor.name + '\': Valid arities are: [0, 1, 6], but ' + arguments.length + ' arguments provided.');
}
a = Number(a);
b = Number(b);
c = Number(c);
d = Number(d);
e = Number(e);
f = Number(f);
if (!Number.isFinite(a + b + c + d + e + f)) return;
this._transformStack[this._stackIndex][0] = a;
this._transformStack[this._stackIndex][1] = b;
this._transformStack[this._stackIndex][2] = c;
this._transformStack[this._stackIndex][3] = d;
this._transformStack[this._stackIndex][4] = e;
this._transformStack[this._stackIndex][5] = f;
var event = (0, _createCanvasEvent["default"])('setTransform', getTransformSlice(this), {
a: a,
b: b,
c: c,
d: d,
e: e,
f: f
a = Number(a);
b = Number(b);
c = Number(c);
d = Number(d);
e = Number(e);
f = Number(f);
if (!Number.isFinite(a + b + c + d + e + f)) return;
this._transformStack[this._stackIndex][0] = a;
this._transformStack[this._stackIndex][1] = b;
this._transformStack[this._stackIndex][2] = c;
this._transformStack[this._stackIndex][3] = d;
this._transformStack[this._stackIndex][4] = e;
this._transformStack[this._stackIndex][5] = f;
const event = (0, _createCanvasEvent.default)('setTransform', getTransformSlice(this), {
a,
b,
c,
d,
e,
f
});
this._events.push(event);
}
set shadowBlur(value) {
const result = Number(value);
if (Number.isFinite(result) && result > 0) {
this._shadowBlurStack[this._stackIndex] = result;
const event = (0, _createCanvasEvent.default)('shadowBlur', getTransformSlice(this), {
value: result
});
this._events.push(event);
}
}, {
key: "stroke",
value: function stroke(path) {
if (arguments.length === 0) {
path = this._path.slice();
} else {
if (!(path instanceof Path2D)) throw new TypeError('Failed to execute \'stroke\' on \'' + this.constructor.name + '\': parameter 1 is not of type \'Path2D\'.');
path = path._path.slice();
}
get shadowBlur() {
return this._shadowBlurStack[this._stackIndex];
}
set shadowColor(value) {
if (typeof value === 'string') {
try {
const result = new _mooColor.MooColor(value);
value = this._shadowColorStack[this._stackIndex] = serializeColor(result);
} catch (e) {
return;
}
var event = (0, _createCanvasEvent["default"])('stroke', getTransformSlice(this), {
path: path
const event = (0, _createCanvasEvent.default)('shadowColor', getTransformSlice(this), {
value
});
this._events.push(event);
this._drawCalls.push(event);
}
}, {
key: "strokeRect",
value: function strokeRect(x, y, width, height) {
if (arguments.length < 4) throw new TypeError('Failed to execute \'strokeRect\' on \'' + this.constructor.name + '\': 4 arguments required, but only ' + arguments.length + ' present.');
x = Number(x);
y = Number(y);
width = Number(width);
height = Number(height);
if (!Number.isFinite(x + y + width + height)) return;
var event = (0, _createCanvasEvent["default"])('strokeRect', getTransformSlice(this), {
x: x,
y: y,
width: width,
height: height
}
get shadowColor() {
return this._shadowColorStack[this._stackIndex];
}
set shadowOffsetX(value) {
const result = Number(value);
if (Number.isFinite(result)) {
this._shadowOffsetXStack[this._stackIndex] = result;
const event = (0, _createCanvasEvent.default)('shadowOffsetX', getTransformSlice(this), {
value: result
});
this._events.push(event);
this._drawCalls.push(event);
}
}, {
key: "strokeText",
value: function strokeText(text, x, y, maxWidth) {
if (arguments.length < 3) throw new TypeError('Failed to execute \'strokeText\' on \'' + this.constructor.name + '\': 3 arguments required, but only ' + arguments.length + ' present.');
var textResult = String(text);
var xResult = Number(x);
var yResult = Number(y);
var maxWidthResult = Number(maxWidth);
if (arguments.length === 3 && !Number.isFinite(xResult + yResult)) return;
if (arguments.length > 3 && !Number.isFinite(xResult + yResult + maxWidthResult)) return;
var event = (0, _createCanvasEvent["default"])('strokeText', getTransformSlice(this), {
text: textResult,
x: xResult,
y: yResult,
maxWidth: arguments.length === 3 ? null : maxWidthResult
}
get shadowOffsetX() {
return this._shadowOffsetXStack[this._stackIndex];
}
set shadowOffsetY(value) {
const result = Number(value);
if (Number.isFinite(result)) {
this._shadowOffsetXStack[this._stackIndex] = result;
const event = (0, _createCanvasEvent.default)('shadowOffsetY', getTransformSlice(this), {
value: result
});
this._events.push(event);
this._drawCalls.push(event);
}
}, {
key: "transform",
value: function transform(a, b, c, d, e, f) {
if (arguments.length < 6) throw new TypeError('Failed to execute \'transform\' on \'' + this.constructor.name + '\': 6 arguments required, but only ' + arguments.length + ' present.');
a = Number(a);
b = Number(b);
c = Number(c);
d = Number(d);
e = Number(e);
f = Number(f);
if (!Number.isFinite(a + b + c + d + e + f)) return;
var sa = this._transformStack[this._stackIndex][0];
var sb = this._transformStack[this._stackIndex][1];
var sc = this._transformStack[this._stackIndex][2];
var sd = this._transformStack[this._stackIndex][3];
var se = this._transformStack[this._stackIndex][4];
var sf = this._transformStack[this._stackIndex][5];
this._transformStack[this._stackIndex][0] = sa * a + sc * b;
this._transformStack[this._stackIndex][1] = sb * a + sd * b;
this._transformStack[this._stackIndex][2] = sa * c + sc * d;
this._transformStack[this._stackIndex][3] = sb * c + sd * d;
this._transformStack[this._stackIndex][4] = sa * e + sc * f + se;
this._transformStack[this._stackIndex][5] = sb * e + sd * f + sf;
var event = (0, _createCanvasEvent["default"])('transform', getTransformSlice(this), {
a: a,
b: b,
c: c,
d: d,
e: e,
f: f
});
this._events.push(event);
}
get shadowOffsetY() {
return this._shadowOffsetXStack[this._stackIndex];
}
stroke(path) {
if (arguments.length === 0) {
path = this._path.slice();
} else {
if (!(path instanceof _Path2D.default)) throw new TypeError("Failed to execute 'stroke' on '" + this.constructor.name + "': parameter 1 is not of type 'Path2D'.");
path = path._path.slice();
}
}, {
key: "translate",
value: function translate(x, y) {
if (arguments.length < 2) throw new TypeError('Failed to execute \'translate\' on \'' + this.constructor.name + '\': 2 arguments required, but only ' + arguments.length + ' present.');
var xResult = Number(x);
var yResult = Number(y);
var a = this._transformStack[this._stackIndex][0];
var b = this._transformStack[this._stackIndex][1];
var c = this._transformStack[this._stackIndex][2];
var d = this._transformStack[this._stackIndex][3];
if (Number.isFinite(xResult + yResult)) {
this._transformStack[this._stackIndex][4] += a * xResult + c * yResult;
this._transformStack[this._stackIndex][5] += b * xResult + d * yResult;
var event = (0, _createCanvasEvent["default"])('translate', getTransformSlice(this), {
x: xResult,
y: yResult
});
this._events.push(event);
}
}
}, {
key: "canvas",
get: function get() {
return this._canvas;
}
}, {
key: "currentTransform",
set: function set(value) {
if (value instanceof _DOMMatrix["default"]) {
this._transformStack[this._stackIndex][0] = value.a;
this._transformStack[this._stackIndex][1] = value.b;
this._transformStack[this._stackIndex][2] = value.c;
this._transformStack[this._stackIndex][3] = value.d;
this._transformStack[this._stackIndex][4] = value.e;
this._transformStack[this._stackIndex][5] = value.f;
var event = (0, _createCanvasEvent["default"])('currentTransform', getTransformSlice(this), {
a: value.a,
b: value.b,
c: value.c,
d: value.d,
e: value.e,
f: value.f
});
this._events.push(event);
}
},
get: function get() {
return new _DOMMatrix["default"](this._transformStack[this._stackIndex]);
}
}, {
key: "direction",
set: function set(value) {
if (value === 'rtl' || value === 'ltr' || value === 'inherit') {
this._directionStack[this._stackIndex] = value;
var event = (0, _createCanvasEvent["default"])('direction', getTransformSlice(this), {
value: value
});
this._events.push(event);
}
},
get: function get() {
return this._directionStack[this._stackIndex];
}
}, {
key: "fillStyle",
set: function set(value) {
var valid = false;
if (typeof value === 'string') {
var result = parseCSSColor(value);
if (result) {
valid = true;
value = this._fillStyleStack[this._stackIndex] = result;
}
} else if (value instanceof CanvasGradient || value instanceof _CanvasPattern["default"]) {
const event = (0, _createCanvasEvent.default)('stroke', getTransformSlice(this), {
path
});
this._events.push(event);
this._drawCalls.push(event);
}
strokeRect(x, y, width, height) {
if (arguments.length < 4) throw new TypeError("Failed to execute 'strokeRect' on '" + this.constructor.name + "': 4 arguments required, but only " + arguments.length + ' present.');
x = Number(x);
y = Number(y);
width = Number(width);
height = Number(height);
if (!Number.isFinite(x + y + width + height)) return;
const event = (0, _createCanvasEvent.default)('strokeRect', getTransformSlice(this), {
x,
y,
width,
height
});
this._events.push(event);
this._drawCalls.push(event);
}
set strokeStyle(value) {
let valid = false;
if (typeof value === 'string') {
try {
const result = new _mooColor.MooColor(value);
valid = true;
this._fillStyleStack[this._stackIndex] = value;
value = this._strokeStyleStack[this._stackIndex] = serializeColor(result);
} catch (e) {
return;
}
if (valid) {
var event = (0, _createCanvasEvent["default"])('fillStyle', getTransformSlice(this), {
value: value
});
this._events.push(event);
}
},
get: function get() {
return this._fillStyleStack[this._stackIndex];
} else if (value instanceof CanvasGradient || value instanceof _CanvasPattern.default) {
valid = true;
this._strokeStyleStack[this._stackIndex] = value;
}
}, {
key: "filter",
set: function set(value) {
if (value === '') value = 'none';
value = this._filterStack[this._stackIndex] = typeof value === 'string' ? value : 'none';
var event = (0, _createCanvasEvent["default"])('filter', getTransformSlice(this), {
value: value
if (valid) {
const event = (0, _createCanvasEvent.default)('strokeStyle', getTransformSlice(this), {
value
});
this._events.push(event);
},
get: function get() {
return this._filterStack[this._stackIndex];
}
}, {
key: "font",
set: function set(value) {
var ex;
try {
var result = (0, _cssfontparser["default"])(value);
value = this._fontStack[this._stackIndex] = result.toString();
var event = (0, _createCanvasEvent["default"])('font', getTransformSlice(this), {
value: value
});
this._events.push(event);
} catch (ex) {}
},
get: function get() {
return this._fontStack[this._stackIndex];
}
get strokeStyle() {
return this._strokeStyleStack[this._stackIndex];
}
strokeText(text, x, y, maxWidth) {
if (arguments.length < 3) throw new TypeError("Failed to execute 'strokeText' on '" + this.constructor.name + "': 3 arguments required, but only " + arguments.length + ' present.');
const textResult = String(text);
const xResult = Number(x);
const yResult = Number(y);
const maxWidthResult = Number(maxWidth);
if (arguments.length === 3 && !Number.isFinite(xResult + yResult)) return;
if (arguments.length > 3 && !Number.isFinite(xResult + yResult + maxWidthResult)) return;
const event = (0, _createCanvasEvent.default)('strokeText', getTransformSlice(this), {
text: textResult,
x: xResult,
y: yResult,
maxWidth: arguments.length === 3 ? null : maxWidthResult
});
this._events.push(event);
this._drawCalls.push(event);
}
set textAlign(value) {
if (value === 'left' || value === 'right' || value === 'center' || value === 'start' || value === 'end') {
this._textAlignStack[this._stackIndex] = value;
const event = (0, _createCanvasEvent.default)('textAlign', getTransformSlice(this), {
value
});
this._events.push(event);
}
}, {
key: "globalAlpha",
set: function set(value) {
value = Number(value);
if (!Number.isFinite(value)) return;
if (value < 0) return;
if (value > 1) return;
this._globalAlphaStack[this._stackIndex] = value;
var event = (0, _createCanvasEvent["default"])('globalAlpha', getTransformSlice(this), {
value: value
}
get textAlign() {
return this._textAlignStack[this._stackIndex];
}
set textBaseline(value) {
if (value === 'top' || value === 'hanging' || value === 'middle' || value === 'alphabetic' || value === 'ideographic' || value === 'bottom') {
this._textBaselineStack[this._stackIndex] = value;
const event = (0, _createCanvasEvent.default)('textBaseline', getTransformSlice(this), {
value
});
this._events.push(event);
},
get: function get() {
return this._globalAlphaStack[this._stackIndex];
}
}, {
key: "globalCompositeOperation",
set: function set(value) {
if (compositeOperations.indexOf(value) !== -1) {
this._globalCompositeOperationStack[this._stackIndex] = value;
var event = (0, _createCanvasEvent["default"])('globalCompositeOperation', getTransformSlice(this), {
value: value
});
this._events.push(event);
}
},
get: function get() {
return this._globalCompositeOperationStack[this._stackIndex];
}
}, {
key: "imageSmoothingEnabled",
set: function set(value) {
value = this._imageSmoothingEnabledStack[this._stackIndex] = Boolean(value);
var event = (0, _createCanvasEvent["default"])('imageSmoothingEnabled', getTransformSlice(this), {
value: value
}
get textBaseline() {
return this._textBaselineStack[this._stackIndex];
}
transform(a, b, c, d, e, f) {
if (arguments.length < 6) throw new TypeError("Failed to execute 'transform' on '" + this.constructor.name + "': 6 arguments required, but only " + arguments.length + ' present.');
a = Number(a);
b = Number(b);
c = Number(c);
d = Number(d);
e = Number(e);
f = Number(f);
if (!Number.isFinite(a + b + c + d + e + f)) return;
const sa = this._transformStack[this._stackIndex][0];
const sb = this._transformStack[this._stackIndex][1];
const sc = this._transformStack[this._stackIndex][2];
const sd = this._transformStack[this._stackIndex][3];
const se = this._transformStack[this._stackIndex][4];
const sf = this._transformStack[this._stackIndex][5];
this._transformStack[this._stackIndex][0] = sa * a + sc * b;
this._transformStack[this._stackIndex][1] = sb * a + sd * b;
this._transformStack[this._stackIndex][2] = sa * c + sc * d;
this._transformStack[this._stackIndex][3] = sb * c + sd * d;
this._transformStack[this._stackIndex][4] = sa * e + sc * f + se;
this._transformStack[this._stackIndex][5] = sb * e + sd * f + sf;
const event = (0, _createCanvasEvent.default)('transform', getTransformSlice(this), {
a,
b,
c,
d,
e,
f
});
this._events.push(event);
}
translate(x, y) {
if (arguments.length < 2) throw new TypeError("Failed to execute 'translate' on '" + this.constructor.name + "': 2 arguments required, but only " + arguments.length + ' present.');
const xResult = Number(x);
const yResult = Number(y);
const a = this._transformStack[this._stackIndex][0];
const b = this._transformStack[this._stackIndex][1];
const c = this._transformStack[this._stackIndex][2];
const d = this._transformStack[this._stackIndex][3];
if (Number.isFinite(xResult + yResult)) {
this._transformStack[this._stackIndex][4] += a * xResult + c * yResult;
this._transformStack[this._stackIndex][5] += b * xResult + d * yResult;
const event = (0, _createCanvasEvent.default)('translate', getTransformSlice(this), {
x: xResult,
y: yResult
});
this._events.push(event);
},
get: function get() {
return this._imageSmoothingEnabledStack[this._stackIndex];
}
}, {
key: "imageSmoothingQuality",
set: function set(value) {
if (value === 'high' || value === 'medium' || value === 'low') {
this._imageSmoothingQualityStack[this._stackIndex] = value;
var event = (0, _createCanvasEvent["default"])('imageSmoothingQuality', getTransformSlice(this), {
value: value
});
this._events.push(event);
}
},
get: function get() {
return this._imageSmoothingQualityStack[this._stackIndex];
}
}, {
key: "lineCap",
set: function set(value) {
if (value === 'butt' || value === 'round' || value === 'square') {
this._lineCapStack[this._stackIndex] = value;
var event = (0, _createCanvasEvent["default"])('lineCap', getTransformSlice(this), {
value: value
});
this._events.push(event);
}
},
get: function get() {
return this._lineCapStack[this._stackIndex];
}
}, {
key: "lineDashOffset",
set: function set(value) {
var result = Number(value);
if (Number.isFinite(result)) {
this._lineDashOffsetStack[this._stackIndex] = result;
var event = (0, _createCanvasEvent["default"])('lineDashOffset', getTransformSlice(this), {
value: value
});
this._events.push(event);
}
},
get: function get() {
return this._lineDashOffsetStack[this._stackIndex];
}
}, {
key: "lineJoin",
set: function set(value) {
if (value === 'round' || value === 'bevel' || value === 'miter') {
this._lineJoinStack[this._stackIndex] = value;
var event = (0, _createCanvasEvent["default"])('lineJoin', getTransformSlice(this), {
value: value
});
this._events.push(event);
}
},
get: function get() {
return this._lineJoinStack[this._stackIndex];
}
}, {
key: "lineWidth",
set: function set(value) {
var result = Number(value);
if (Number.isFinite(result) && result > 0) {
this._lineWidthStack[this._stackIndex] = result;
var event = (0, _createCanvasEvent["default"])('lineWidth', getTransformSlice(this), {
value: result
});
this._events.push(event);
}
},
get: function get() {
return this._lineWidthStack[this._stackIndex];
}
}, {
key: "miterLimit",
set: function set(value) {
var result = Number(value);
if (Number.isFinite(result) && result > 0) {
this._miterLimitStack[this._stackIndex] = result;
var event = (0, _createCanvasEvent["default"])('lineWidth', getTransformSlice(this), {
value: result
});
this._events.push(event);
}
},
get: function get() {
return this._miterLimitStack[this._stackIndex];
}
}, {
key: "shadowBlur",
set: function set(value) {
var result = Number(value);
if (Number.isFinite(result) && result > 0) {
this._shadowBlurStack[this._stackIndex] = result;
var event = (0, _createCanvasEvent["default"])('shadowBlur', getTransformSlice(this), {
value: result
});
this._events.push(event);
}
},
get: function get() {
return this._shadowBlurStack[this._stackIndex];
}
}, {
key: "shadowColor",
set: function set(value) {
if (typeof value === 'string') {
var result = parseCSSColor(value);
if (result) {
this._shadowColorStack[this._stackIndex] = result;
var event = (0, _createCanvasEvent["default"])('shadowColor', getTransformSlice(this), {
value: result
});
this._events.push(event);
}
}
},
get: function get() {
return this._shadowColorStack[this._stackIndex];
}
}, {
key: "shadowOffsetX",
set: function set(value) {
var result = Number(value);
if (Number.isFinite(result)) {
this._shadowOffsetXStack[this._stackIndex] = result;
var event = (0, _createCanvasEvent["default"])('shadowOffsetX', getTransformSlice(this), {
value: result
});
this._events.push(event);
}
},
get: function get() {
return this._shadowOffsetXStack[this._stackIndex];
}
}, {
key: "shadowOffsetY",
set: function set(value) {
var result = Number(value);
if (Number.isFinite(result)) {
this._shadowOffsetXStack[this._stackIndex] = result;
var event = (0, _createCanvasEvent["default"])('shadowOffsetY', getTransformSlice(this), {
value: result
});
this._events.push(event);
}
},
get: function get() {
return this._shadowOffsetXStack[this._stackIndex];
}
}, {
key: "strokeStyle",
set: function set(value) {
var valid = false;
if (typeof value === 'string') {
var result = parseCSSColor(value);
if (result) {
valid = true;
value = this._strokeStyleStack[this._stackIndex] = result;
}
} else if (value instanceof CanvasGradient || value instanceof _CanvasPattern["default"]) {
valid = true;
this._strokeStyleStack[this._stackIndex] = value;
}
if (valid) {
var event = (0, _createCanvasEvent["default"])('strokeStyle', getTransformSlice(this), {
value: value
});
this._events.push(event);
}
},
get: function get() {
return this._strokeStyleStack[this._stackIndex];
}
}, {
key: "textAlign",
set: function set(value) {
if (value === 'left' || value === 'right' || value === 'center' || value === 'start' || value === 'end') {
this._textAlignStack[this._stackIndex] = value;
var event = (0, _createCanvasEvent["default"])('textAlign', getTransformSlice(this), {
value: value
});
this._events.push(event);
}
},
get: function get() {
return this._textAlignStack[this._stackIndex];
}
}, {
key: "textBaseline",
set: function set(value) {
if (value === 'top' || value === 'hanging' || value === 'middle' || value === 'alphabetic' || value === 'ideographic' || value === 'bottom') {
this._textBaselineStack[this._stackIndex] = value;
var event = (0, _createCanvasEvent["default"])('textBaseline', getTransformSlice(this), {
value: value
});
this._events.push(event);
}
},
get: function get() {
return this._textBaselineStack[this._stackIndex];
}
}]);
return CanvasRenderingContext2D;
}();
exports["default"] = CanvasRenderingContext2D;
}
}
exports.default = CanvasRenderingContext2D;

@@ -6,52 +6,49 @@ "use strict";

});
exports["default"] = void 0;
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
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; }
var DOMMatrix =
/*#__PURE__*/
function () {
function DOMMatrix(transform) {
_classCallCheck(this, DOMMatrix);
exports.default = void 0;
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
function sumMultipleOfMatricesCells(matrix1Array, matrix2Array, {
i,
j
}) {
let sum = 0;
for (let k = 0; k < 4; k++) {
const matrix1Index = j - 1 + k * 4;
const matrix2Index = (i - 1) * 4 + k;
sum += matrix1Array[matrix1Index] * matrix2Array[matrix2Index];
}
return sum;
}
function multiplyMatrices(leftMatrix, rightMatrix) {
const leftMatrixArray = leftMatrix.toFloat64Array();
const rightMatrixArray = rightMatrix.toFloat64Array();
for (let i = 1; i <= 4; i++) {
for (let j = 1; j <= 4; j++) {
leftMatrix[`m${i}${j}`] = sumMultipleOfMatricesCells(leftMatrixArray, rightMatrixArray, {
i,
j
});
}
}
}
class DOMMatrix {
constructor(transform) {
_defineProperty(this, "_is2D", true);
_defineProperty(this, "m11", 1.0);
_defineProperty(this, "m12", 0.0);
_defineProperty(this, "m13", 0.0);
_defineProperty(this, "m14", 0.0);
_defineProperty(this, "m21", 0.0);
_defineProperty(this, "m22", 1.0);
_defineProperty(this, "m23", 0.0);
_defineProperty(this, "m24", 0.0);
_defineProperty(this, "m31", 0.0);
_defineProperty(this, "m32", 0.0);
_defineProperty(this, "m33", 1.0);
_defineProperty(this, "m34", 0.0);
_defineProperty(this, "m41", 0.0);
_defineProperty(this, "m42", 0.0);
_defineProperty(this, "m43", 0.0);
_defineProperty(this, "m44", 1.0);
if (transform && transform.length === 6) {

@@ -67,3 +64,2 @@ this.m11 = transform[0];

}
if (transform && transform.length === 16) {

@@ -89,77 +85,111 @@ this.m11 = transform[0];

}
if (transform) {
throw new TypeError('Failed to construct \'DOMMatrix\': The sequence must contain 6 elements for a 2D matrix or 16 elements for a 3D matrix.');
throw new TypeError("Failed to construct 'DOMMatrix': The sequence must contain 6 elements for a 2D matrix or 16 elements for a 3D matrix.");
}
this._is2D = false;
}
_createClass(DOMMatrix, [{
key: "isIdentity",
get: function get() {
if (this._is2D) {
return this.m11 == 1.0 && this.m12 == 0.0 && this.m21 == 0.0 && this.m22 == 1.0 && this.m41 == 0.0 && this.m42 == 0.0;
} else {
return this.m11 = 1.0 && this.m12 === 0.0 && this.m13 === 0.0 && this.m14 === 0.0 && this.m21 === 0.0 && this.m22 === 1.0 && this.m23 === 0.0 && this.m24 === 0.0 && this.m31 === 0.0 && this.m32 === 0.0 && this.m33 === 1.0 && this.m34 === 0.0 && this.m41 === 0.0 && this.m42 === 0.0 && this.m43 === 0.0 && this.m44 === 1.0;
}
get isIdentity() {
if (this._is2D) {
return this.m11 == 1.0 && this.m12 == 0.0 && this.m21 == 0.0 && this.m22 == 1.0 && this.m41 == 0.0 && this.m42 == 0.0;
} else {
return this.m11 = 1.0 && this.m12 === 0.0 && this.m13 === 0.0 && this.m14 === 0.0 && this.m21 === 0.0 && this.m22 === 1.0 && this.m23 === 0.0 && this.m24 === 0.0 && this.m31 === 0.0 && this.m32 === 0.0 && this.m33 === 1.0 && this.m34 === 0.0 && this.m41 === 0.0 && this.m42 === 0.0 && this.m43 === 0.0 && this.m44 === 1.0;
}
}, {
key: "a",
get: function get() {
return this.m11;
},
set: function set(value) {
this.m11 = value;
}
get a() {
return this.m11;
}
set a(value) {
this.m11 = value;
}
get b() {
return this.m12;
}
set b(value) {
this.m12 = value;
}
get c() {
return this.m21;
}
set c(value) {
this.m21 = value;
}
get d() {
return this.m22;
}
set d(value) {
this.m22 = value;
}
get e() {
return this.m41;
}
set e(value) {
this.m41 = value;
}
get f() {
return this.m42;
}
set f(value) {
this.m42 = value;
}
get is2D() {
return this._is2D;
}
toFloat32Array() {
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]);
}
toFloat64Array() {
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]);
}
translateSelf(x, y, z) {
const tx = Number(x),
ty = Number(y),
tz = isNaN(Number(z)) ? 0 : Number(z);
const translationMatrix = new DOMMatrix();
translationMatrix.m41 = tx;
translationMatrix.m42 = ty;
translationMatrix.m43 = tz;
multiplyMatrices(this, translationMatrix);
if (tz) {
this._is2D = false;
}
}, {
key: "b",
get: function get() {
return this.m12;
},
set: function set(value) {
this.m12 = value;
return this;
}
translate(x, y, z) {
let translatedMatrix;
if (this.is2D) {
translatedMatrix = new DOMMatrix([this.a, this.b, this.c, this.d, this.e, this.f]);
} else {
translatedMatrix = new DOMMatrix(this.toFloat32Array());
}
}, {
key: "c",
get: function get() {
return this.m21;
},
set: function set(value) {
this.m21 = value;
return translatedMatrix.translateSelf(x, y, z);
}
scaleSelf(scaleX, scaleY, scaleZ, originX, originY, originZ) {
const sx = Number(scaleX),
sy = isNaN(Number(scaleY)) ? sx : Number(scaleY),
sz = isNaN(Number(scaleZ)) ? 1 : Number(scaleZ);
const ox = isNaN(Number(originX)) ? 0 : Number(originX),
oy = isNaN(Number(originY)) ? 0 : Number(originY),
oz = isNaN(Number(originZ)) ? 0 : Number(originZ);
this.translateSelf(ox, oy, oz);
const scaleMatrix = new DOMMatrix();
scaleMatrix.m11 = sx;
scaleMatrix.m22 = sy;
scaleMatrix.m33 = sz;
multiplyMatrices(this, scaleMatrix);
this.translateSelf(-ox, -oy, -oz);
if (Math.abs(sz) !== 1) {
this._is2D = false;
}
}, {
key: "d",
get: function get() {
return this.m22;
},
set: function set(value) {
this.m22 = value;
return this;
}
scale(scaleX, scaleY, scaleZ, originX, originY, originZ) {
let scaledMatrix;
if (this.is2D) {
scaledMatrix = new DOMMatrix([this.a, this.b, this.c, this.d, this.e, this.f]);
} else {
scaledMatrix = new DOMMatrix(this.toFloat32Array());
}
}, {
key: "e",
get: function get() {
return this.m41;
},
set: function set(value) {
this.m41 = value;
}
}, {
key: "f",
get: function get() {
return this.m42;
},
set: function set(value) {
this.m42 = value;
}
}, {
key: "is2D",
get: function get() {
return this._is2D;
}
}]);
return DOMMatrix;
}();
exports["default"] = DOMMatrix;
return scaledMatrix.scaleSelf(scaleX, scaleY, scaleZ, originX, originY, originZ);
}
}
exports.default = DOMMatrix;

@@ -6,19 +6,14 @@ "use strict";

});
exports["default"] = void 0;
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
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; }
var Image = function Image(width, height) {
_classCallCheck(this, Image);
_defineProperty(this, "width", 0);
_defineProperty(this, "height", 0);
this.width = width;
this.height = height;
};
exports["default"] = Image;
exports.default = void 0;
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
class Image {
constructor(width, height) {
_defineProperty(this, "width", 0);
_defineProperty(this, "height", 0);
this.width = width;
this.height = height;
}
}
exports.default = Image;

@@ -6,24 +6,11 @@ "use strict";

});
exports["default"] = void 0;
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
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; }
var ImageBitmap =
/*#__PURE__*/
function () {
function ImageBitmap(width, height) {
_classCallCheck(this, ImageBitmap);
exports.default = void 0;
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
class ImageBitmap {
constructor(width, height) {
_defineProperty(this, "width", 0);
_defineProperty(this, "height", 0);
_defineProperty(this, "_closed", false);
this.width = width;

@@ -33,15 +20,8 @@ this.height = height;

}
_createClass(ImageBitmap, [{
key: "close",
value: function close() {
this.width = 0;
this.height = 0;
this._closed = true;
}
}]);
return ImageBitmap;
}();
exports["default"] = ImageBitmap;
close() {
this.width = 0;
this.height = 0;
this._closed = true;
}
}
exports.default = ImageBitmap;

@@ -6,53 +6,57 @@ "use strict";

});
exports["default"] = void 0;
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
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; }
var ImageData =
/*#__PURE__*/
function () {
_createClass(ImageData, [{
key: "width",
get: function get() {
return this._width;
}
}, {
key: "height",
get: function get() {
return this._height;
}
}, {
key: "data",
get: function get() {
return this._data;
}
}]);
function ImageData(width, height) {
_classCallCheck(this, ImageData);
exports.default = void 0;
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
class ImageData {
get width() {
return this._width;
}
get height() {
return this._height;
}
get data() {
return this._data;
}
constructor(arr, w, h) {
_defineProperty(this, "_width", 0);
_defineProperty(this, "_height", 0);
_defineProperty(this, "_data", null);
if (!Number.isFinite(height)) throw new TypeError('The source height is zero or not a number.');
if (height === 0) throw new TypeError('The source height is zero or not a number.');
if (!Number.isFinite(width)) throw new TypeError('The source width is zero or not a number.');
if (width === 0) throw new TypeError('The source height is zero or not a number.');
this._width = width;
this._height = height;
this._data = new Uint8ClampedArray(width * height * 4);
if (arguments.length === 2) {
if (arr instanceof Uint8ClampedArray) {
if (arr.length === 0) throw new RangeError('Source length must be a positive multiple of 4.');
if (arr.length % 4 !== 0) throw new RangeError('Source length must be a positive multiple of 4.');
if (!Number.isFinite(w)) throw new RangeError('The width is zero or not a number.');
if (w === 0) throw new RangeError('The width is zero or not a number.');
this._width = w;
this._height = arr.length / 4 / w;
this._data = arr;
} else {
const width = arr;
const height = w;
if (!Number.isFinite(height)) throw new RangeError('The height is zero or not a number.');
if (height === 0) throw new RangeError('The height is zero or not a number.');
if (!Number.isFinite(width)) throw new RangeError('The width is zero or not a number.');
if (width === 0) throw new RangeError('The width is zero or not a number.');
this._width = width;
this._height = height;
this._data = new Uint8ClampedArray(width * height * 4);
}
} else if (arguments.length === 3) {
if (!(arr instanceof Uint8ClampedArray)) throw new TypeError('First argument must be a Uint8ClampedArray when using 3 arguments.');
if (arr.length === 0) throw new RangeError('Source length must be a positive multiple of 4.');
if (arr.length % 4 !== 0) throw new RangeError('Source length must be a positive multiple of 4.');
if (!Number.isFinite(h)) throw new RangeError('The height is zero or not a number.');
if (h === 0) throw new RangeError('The height is zero or not a number.');
if (!Number.isFinite(w)) throw new RangeError('The width is zero or not a number.');
if (w === 0) throw new RangeError('The width is zero or not a number.');
if (arr.length !== w * h * 4) throw new RangeError("Source doesn'n contain the exact number of pixels needed.");
this._width = w;
this._height = h;
this._data = arr;
} else {
throw new TypeError('Wrong number of arguments provided.');
}
}
return ImageData;
}();
exports["default"] = ImageData;
}
exports.default = ImageData;

@@ -6,56 +6,30 @@ "use strict";

});
exports["default"] = void 0;
exports.default = void 0;
var _CanvasRenderingContext2D = _interopRequireDefault(require("./CanvasRenderingContext2D"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
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; }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
// Path2D.prototype
var Path2DFunc = ['addPath'];
var borrowedFromCanvas = ['closePath', 'moveTo', 'lineTo', 'bezierCurveTo', 'quadraticCurveTo', 'arc', 'arcTo', 'ellipse', 'rect'];
var Path2D =
/*#__PURE__*/
function () {
function Path2D() {
var _this = this;
_classCallCheck(this, Path2D);
const Path2DFunc = ['addPath'];
const borrowedFromCanvas = ['closePath', 'moveTo', 'lineTo', 'bezierCurveTo', 'quadraticCurveTo', 'arc', 'arcTo', 'ellipse', 'rect'];
class Path2D {
constructor() {
_defineProperty(this, "_path", []);
_defineProperty(this, "_events", []);
_defineProperty(this, "_stackIndex", 0);
_defineProperty(this, "_transformStack", [[1, 0, 0, 1, 0, 0]]);
borrowedFromCanvas.forEach(function (key) {
_this[key] = jest.fn(_CanvasRenderingContext2D["default"].prototype[key].bind(_this));
borrowedFromCanvas.forEach(key => {
this[key] = jest.fn(_CanvasRenderingContext2D.default.prototype[key].bind(this));
});
Path2DFunc.forEach(function (key) {
_this[key] = jest.fn(_this[key].bind(_this));
Path2DFunc.forEach(key => {
this[key] = jest.fn(this[key].bind(this));
});
}
_createClass(Path2D, [{
key: "addPath",
value: function addPath(path) {
if (arguments.length < 1) throw new TypeError('Failed to execute \'addPath\' on \'Path2D\': 1 argument required, but only 0 present.');
if (!(path instanceof Path2D)) throw new TypeError('Failed to execute \'addPath\' on \'Path2D\': parameter 1 is not of type \'Path2D\'.');
this._path = this._path.concat(path._path);
}
}]);
return Path2D;
}();
exports["default"] = Path2D;
addPath(path) {
if (arguments.length < 1) throw new TypeError("Failed to execute 'addPath' on 'Path2D': 1 argument required, but only 0 present.");
if (!(path instanceof Path2D)) throw new TypeError("Failed to execute 'addPath' on 'Path2D': parameter 1 is not of type 'Path2D'.");
for (let i = 0; i < path._path.length; i++) this._path.push(path._path[i]);
}
}
exports.default = Path2D;

@@ -6,38 +6,23 @@ "use strict";

});
exports["default"] = void 0;
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
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; }
var TextMetrics = function TextMetrics(text) {
_classCallCheck(this, TextMetrics);
_defineProperty(this, "width", 0);
_defineProperty(this, "actualBoundingBoxLeft", 0);
_defineProperty(this, "actualBoundingBoxRight", 0);
_defineProperty(this, "fontBoundingBoxAscent", 0);
_defineProperty(this, "fontBoundingBoxDescent", 0);
_defineProperty(this, "actualBoundingBoxAscent", 0);
_defineProperty(this, "actualBoundingBoxDescent", 0);
_defineProperty(this, "emHeightAscent", 0);
_defineProperty(this, "emHeightDescent", 0);
_defineProperty(this, "hangingBaseline", 0);
_defineProperty(this, "alphabeticBaseline", 0);
_defineProperty(this, "ideographicBaseline", 0);
this.width = text.length;
};
exports["default"] = TextMetrics;
exports.default = void 0;
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
class TextMetrics {
constructor(text) {
_defineProperty(this, "width", 0);
_defineProperty(this, "actualBoundingBoxLeft", 0);
_defineProperty(this, "actualBoundingBoxRight", 0);
_defineProperty(this, "fontBoundingBoxAscent", 0);
_defineProperty(this, "fontBoundingBoxDescent", 0);
_defineProperty(this, "actualBoundingBoxAscent", 0);
_defineProperty(this, "actualBoundingBoxDescent", 0);
_defineProperty(this, "emHeightAscent", 0);
_defineProperty(this, "emHeightDescent", 0);
_defineProperty(this, "hangingBaseline", 0);
_defineProperty(this, "alphabeticBaseline", 0);
_defineProperty(this, "ideographicBaseline", 0);
this.width = text.length;
}
}
exports.default = TextMetrics;

@@ -6,358 +6,348 @@ "use strict";

});
exports["default"] = void 0;
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
var testFuncs = ['activeTexture', 'attachShader', 'bindAttribLocation', 'bindBuffer', 'bindFramebuffer', 'bindRenderbuffer', 'bindTexture', 'blendColor', 'blendEquation', 'blendEquationSeparate', 'blendFunc', 'blendFuncSeparate', 'bufferData', 'bufferSubData', 'checkFramebufferStatus', 'clear', 'clearColor', 'clearDepth', 'clearStencil', 'colorMask', 'compileShader', 'compressedTexImage2D', 'compressedTexSubImage2D', 'copyTexImage2D', 'copyTexSubImage2D', 'createBuffer', 'createFramebuffer', 'createProgram', 'createRenderbuffer', 'createShader', 'createTexture', 'cullFace', 'deleteBuffer', 'deleteFramebuffer', 'deleteProgram', 'deleteRenderbuffer', 'deleteShader', 'deleteTexture', 'depthFunc', 'depthMask', 'depthRange', 'detachShader', 'disable', 'disableVertexAttribArray', 'drawArrays', 'drawElements', 'enable', 'enableVertexAttribArray', 'finish', 'flush', 'framebufferRenderbuffer', 'framebufferTexture2D', 'frontFace', 'generateMipmap', 'getActiveAttrib', 'getActiveUniform', 'getAttachedShaders', 'getAttribLocation', 'getBufferParameter', 'getError', 'getFramebufferAttachmentParameter', 'getProgramParameter', 'getProgramInfoLog', 'getRenderbufferParameter', 'getShaderParameter', 'getShaderInfoLog', 'getShaderPrecisionFormat', 'getShaderSource', 'getSupportedExtensions', 'getTexParameter', 'getUniform', 'getUniformLocation', 'getVertexAttrib', 'getVertexAttribOffset', 'hint', 'isBuffer', 'isContextLost', 'isEnabled', 'isFramebuffer', 'isProgram', 'isRenderbuffer', 'isShader', 'isTexture', 'lineWidth', 'linkProgram', 'pixelStorei', 'polygonOffset', 'readPixels', 'renderbufferStorage', 'sampleCoverage', 'scissor', 'shaderSource', 'stencilFunc', 'stencilFuncSeparate', 'stencilMask', 'stencilMaskSeparate', 'stencilOp', 'stencilOpSeparate', 'texParameterf', 'texParameteri', 'texImage2D', 'texSubImage2D', 'uniform1f', 'uniform1fv', 'uniform1i', 'uniform1iv', 'uniform2f', 'uniform2fv', 'uniform2i', 'uniform2iv', 'uniform3f', 'uniform3fv', 'uniform3i', 'uniform3iv', 'uniform4f', 'uniform4fv', 'uniform4i', 'uniform4iv', 'uniformMatrix2fv', 'uniformMatrix3fv', 'uniformMatrix4fv', 'useProgram', 'validateProgram', 'vertexAttrib1f', 'vertexAttrib1fv', 'vertexAttrib2f', 'vertexAttrib2fv', 'vertexAttrib3f', 'vertexAttrib3fv', 'vertexAttrib4f', 'vertexAttrib4fv', 'vertexAttribPointer', 'viewport'];
var mockEnums = {
'DEPTH_BUFFER_BIT': 256,
'STENCIL_BUFFER_BIT': 1024,
'COLOR_BUFFER_BIT': 16384,
'POINTS': 0,
'LINES': 1,
'LINE_LOOP': 2,
'LINE_STRIP': 3,
'TRIANGLES': 4,
'TRIANGLE_STRIP': 5,
'TRIANGLE_FAN': 6,
'ZERO': 0,
'ONE': 1,
'SRC_COLOR': 768,
'ONE_MINUS_SRC_COLOR': 769,
'SRC_ALPHA': 770,
'ONE_MINUS_SRC_ALPHA': 771,
'DST_ALPHA': 772,
'ONE_MINUS_DST_ALPHA': 773,
'DST_COLOR': 774,
'ONE_MINUS_DST_COLOR': 775,
'SRC_ALPHA_SATURATE': 776,
'FUNC_ADD': 32774,
'BLEND_EQUATION': 32777,
'BLEND_EQUATION_RGB': 32777,
'BLEND_EQUATION_ALPHA': 34877,
'FUNC_SUBTRACT': 32778,
'FUNC_REVERSE_SUBTRACT': 32779,
'BLEND_DST_RGB': 32968,
'BLEND_SRC_RGB': 32969,
'BLEND_DST_ALPHA': 32970,
'BLEND_SRC_ALPHA': 32971,
'CONSTANT_COLOR': 32769,
'ONE_MINUS_CONSTANT_COLOR': 32770,
'CONSTANT_ALPHA': 32771,
'ONE_MINUS_CONSTANT_ALPHA': 32772,
'BLEND_COLOR': 32773,
'ARRAY_BUFFER': 34962,
'ELEMENT_ARRAY_BUFFER': 34963,
'ARRAY_BUFFER_BINDING': 34964,
'ELEMENT_ARRAY_BUFFER_BINDING': 34965,
'STREAM_DRAW': 35040,
'STATIC_DRAW': 35044,
'DYNAMIC_DRAW': 35048,
'BUFFER_SIZE': 34660,
'BUFFER_USAGE': 34661,
'CURRENT_VERTEX_ATTRIB': 34342,
'FRONT': 1028,
'BACK': 1029,
'FRONT_AND_BACK': 1032,
'TEXTURE_2D': 3553,
'CULL_FACE': 2884,
'BLEND': 3042,
'DITHER': 3024,
'STENCIL_TEST': 2960,
'DEPTH_TEST': 2929,
'SCISSOR_TEST': 3089,
'POLYGON_OFFSET_FILL': 32823,
'SAMPLE_ALPHA_TO_COVERAGE': 32926,
'SAMPLE_COVERAGE': 32928,
'NO_ERROR': 0,
'INVALID_ENUM': 1280,
'INVALID_VALUE': 1281,
'INVALID_OPERATION': 1282,
'OUT_OF_MEMORY': 1285,
'CW': 2304,
'CCW': 2305,
'LINE_WIDTH': 2849,
'ALIASED_POINT_SIZE_RANGE': 33901,
'ALIASED_LINE_WIDTH_RANGE': 33902,
'CULL_FACE_MODE': 2885,
'FRONT_FACE': 2886,
'DEPTH_RANGE': 2928,
'DEPTH_WRITEMASK': 2930,
'DEPTH_CLEAR_VALUE': 2931,
'DEPTH_FUNC': 2932,
'STENCIL_CLEAR_VALUE': 2961,
'STENCIL_FUNC': 2962,
'STENCIL_FAIL': 2964,
'STENCIL_PASS_DEPTH_FAIL': 2965,
'STENCIL_PASS_DEPTH_PASS': 2966,
'STENCIL_REF': 2967,
'STENCIL_VALUE_MASK': 2963,
'STENCIL_WRITEMASK': 2968,
'STENCIL_BACK_FUNC': 34816,
'STENCIL_BACK_FAIL': 34817,
'STENCIL_BACK_PASS_DEPTH_FAIL': 34818,
'STENCIL_BACK_PASS_DEPTH_PASS': 34819,
'STENCIL_BACK_REF': 36003,
'STENCIL_BACK_VALUE_MASK': 36004,
'STENCIL_BACK_WRITEMASK': 36005,
'VIEWPORT': 2978,
'SCISSOR_BOX': 3088,
'COLOR_CLEAR_VALUE': 3106,
'COLOR_WRITEMASK': 3107,
'UNPACK_ALIGNMENT': 3317,
'PACK_ALIGNMENT': 3333,
'MAX_TEXTURE_SIZE': 3379,
'MAX_VIEWPORT_DIMS': 3386,
'SUBPIXEL_BITS': 3408,
'RED_BITS': 3410,
'GREEN_BITS': 3411,
'BLUE_BITS': 3412,
'ALPHA_BITS': 3413,
'DEPTH_BITS': 3414,
'STENCIL_BITS': 3415,
'POLYGON_OFFSET_UNITS': 10752,
'POLYGON_OFFSET_FACTOR': 32824,
'TEXTURE_BINDING_2D': 32873,
'SAMPLE_BUFFERS': 32936,
'SAMPLES': 32937,
'SAMPLE_COVERAGE_VALUE': 32938,
'SAMPLE_COVERAGE_INVERT': 32939,
'COMPRESSED_TEXTURE_FORMATS': 34467,
'DONT_CARE': 4352,
'FASTEST': 4353,
'NICEST': 4354,
'GENERATE_MIPMAP_HINT': 33170,
'BYTE': 5120,
'UNSIGNED_BYTE': 5121,
'SHORT': 5122,
'UNSIGNED_SHORT': 5123,
'INT': 5124,
'UNSIGNED_INT': 5125,
'FLOAT': 5126,
'DEPTH_COMPONENT': 6402,
'ALPHA': 6406,
'RGB': 6407,
'RGBA': 6408,
'LUMINANCE': 6409,
'LUMINANCE_ALPHA': 6410,
'UNSIGNED_SHORT_4_4_4_4': 32819,
'UNSIGNED_SHORT_5_5_5_1': 32820,
'UNSIGNED_SHORT_5_6_5': 33635,
'FRAGMENT_SHADER': 35632,
'VERTEX_SHADER': 35633,
'MAX_VERTEX_ATTRIBS': 34921,
'MAX_VERTEX_UNIFORM_VECTORS': 36347,
'MAX_VARYING_VECTORS': 36348,
'MAX_COMBINED_TEXTURE_IMAGE_UNITS': 35661,
'MAX_VERTEX_TEXTURE_IMAGE_UNITS': 35660,
'MAX_TEXTURE_IMAGE_UNITS': 34930,
'MAX_FRAGMENT_UNIFORM_VECTORS': 36349,
'SHADER_TYPE': 35663,
'DELETE_STATUS': 35712,
'LINK_STATUS': 35714,
'VALIDATE_STATUS': 35715,
'ATTACHED_SHADERS': 35717,
'ACTIVE_UNIFORMS': 35718,
'ACTIVE_ATTRIBUTES': 35721,
'SHADING_LANGUAGE_VERSION': 35724,
'CURRENT_PROGRAM': 35725,
'NEVER': 512,
'LESS': 513,
'EQUAL': 514,
'LEQUAL': 515,
'GREATER': 516,
'NOTEQUAL': 517,
'GEQUAL': 518,
'ALWAYS': 519,
'KEEP': 7680,
'REPLACE': 7681,
'INCR': 7682,
'DECR': 7683,
'INVERT': 5386,
'INCR_WRAP': 34055,
'DECR_WRAP': 34056,
'VENDOR': 7936,
'RENDERER': 7937,
'VERSION': 7938,
'NEAREST': 9728,
'LINEAR': 9729,
'NEAREST_MIPMAP_NEAREST': 9984,
'LINEAR_MIPMAP_NEAREST': 9985,
'NEAREST_MIPMAP_LINEAR': 9986,
'LINEAR_MIPMAP_LINEAR': 9987,
'TEXTURE_MAG_FILTER': 10240,
'TEXTURE_MIN_FILTER': 10241,
'TEXTURE_WRAP_S': 10242,
'TEXTURE_WRAP_T': 10243,
'TEXTURE': 5890,
'TEXTURE_CUBE_MAP': 34067,
'TEXTURE_BINDING_CUBE_MAP': 34068,
'TEXTURE_CUBE_MAP_POSITIVE_X': 34069,
'TEXTURE_CUBE_MAP_NEGATIVE_X': 34070,
'TEXTURE_CUBE_MAP_POSITIVE_Y': 34071,
'TEXTURE_CUBE_MAP_NEGATIVE_Y': 34072,
'TEXTURE_CUBE_MAP_POSITIVE_Z': 34073,
'TEXTURE_CUBE_MAP_NEGATIVE_Z': 34074,
'MAX_CUBE_MAP_TEXTURE_SIZE': 34076,
'TEXTURE0': 33984,
'TEXTURE1': 33985,
'TEXTURE2': 33986,
'TEXTURE3': 33987,
'TEXTURE4': 33988,
'TEXTURE5': 33989,
'TEXTURE6': 33990,
'TEXTURE7': 33991,
'TEXTURE8': 33992,
'TEXTURE9': 33993,
'TEXTURE10': 33994,
'TEXTURE11': 33995,
'TEXTURE12': 33996,
'TEXTURE13': 33997,
'TEXTURE14': 33998,
'TEXTURE15': 33999,
'TEXTURE16': 34000,
'TEXTURE17': 34001,
'TEXTURE18': 34002,
'TEXTURE19': 34003,
'TEXTURE20': 34004,
'TEXTURE21': 34005,
'TEXTURE22': 34006,
'TEXTURE23': 34007,
'TEXTURE24': 34008,
'TEXTURE25': 34009,
'TEXTURE26': 34010,
'TEXTURE27': 34011,
'TEXTURE28': 34012,
'TEXTURE29': 34013,
'TEXTURE30': 34014,
'TEXTURE31': 34015,
'ACTIVE_TEXTURE': 34016,
'REPEAT': 10497,
'CLAMP_TO_EDGE': 33071,
'MIRRORED_REPEAT': 33648,
'FLOAT_VEC2': 35664,
'FLOAT_VEC3': 35665,
'FLOAT_VEC4': 35666,
'INT_VEC2': 35667,
'INT_VEC3': 35668,
'INT_VEC4': 35669,
'BOOL': 35670,
'BOOL_VEC2': 35671,
'BOOL_VEC3': 35672,
'BOOL_VEC4': 35673,
'FLOAT_MAT2': 35674,
'FLOAT_MAT3': 35675,
'FLOAT_MAT4': 35676,
'SAMPLER_2D': 35678,
'SAMPLER_CUBE': 35680,
'VERTEX_ATTRIB_ARRAY_ENABLED': 34338,
'VERTEX_ATTRIB_ARRAY_SIZE': 34339,
'VERTEX_ATTRIB_ARRAY_STRIDE': 34340,
'VERTEX_ATTRIB_ARRAY_TYPE': 34341,
'VERTEX_ATTRIB_ARRAY_NORMALIZED': 34922,
'VERTEX_ATTRIB_ARRAY_POINTER': 34373,
'VERTEX_ATTRIB_ARRAY_BUFFER_BINDING': 34975,
'IMPLEMENTATION_COLOR_READ_TYPE': 35738,
'IMPLEMENTATION_COLOR_READ_FORMAT': 35739,
'COMPILE_STATUS': 35713,
'LOW_FLOAT': 36336,
'MEDIUM_FLOAT': 36337,
'HIGH_FLOAT': 36338,
'LOW_INT': 36339,
'MEDIUM_INT': 36340,
'HIGH_INT': 36341,
'FRAMEBUFFER': 36160,
'RENDERBUFFER': 36161,
'RGBA4': 32854,
'RGB5_A1': 32855,
'RGB565': 36194,
'DEPTH_COMPONENT16': 33189,
'STENCIL_INDEX': 6401,
'STENCIL_INDEX8': 36168,
'DEPTH_STENCIL': 34041,
'RENDERBUFFER_WIDTH': 36162,
'RENDERBUFFER_HEIGHT': 36163,
'RENDERBUFFER_INTERNAL_FORMAT': 36164,
'RENDERBUFFER_RED_SIZE': 36176,
'RENDERBUFFER_GREEN_SIZE': 36177,
'RENDERBUFFER_BLUE_SIZE': 36178,
'RENDERBUFFER_ALPHA_SIZE': 36179,
'RENDERBUFFER_DEPTH_SIZE': 36180,
'RENDERBUFFER_STENCIL_SIZE': 36181,
'FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE': 36048,
'FRAMEBUFFER_ATTACHMENT_OBJECT_NAME': 36049,
'FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL': 36050,
'FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE': 36051,
'COLOR_ATTACHMENT0': 36064,
'DEPTH_ATTACHMENT': 36096,
'STENCIL_ATTACHMENT': 36128,
'DEPTH_STENCIL_ATTACHMENT': 33306,
'NONE': 0,
'FRAMEBUFFER_COMPLETE': 36053,
'FRAMEBUFFER_INCOMPLETE_ATTACHMENT': 36054,
'FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT': 36055,
'FRAMEBUFFER_INCOMPLETE_DIMENSIONS': 36057,
'FRAMEBUFFER_UNSUPPORTED': 36061,
'FRAMEBUFFER_BINDING': 36006,
'RENDERBUFFER_BINDING': 36007,
'MAX_RENDERBUFFER_SIZE': 34024,
'INVALID_FRAMEBUFFER_OPERATION': 1286,
'UNPACK_FLIP_Y_WEBGL': 37440,
'UNPACK_PREMULTIPLY_ALPHA_WEBGL': 37441,
'CONTEXT_LOST_WEBGL': 37442,
'UNPACK_COLORSPACE_CONVERSION_WEBGL': 37443,
'BROWSER_DEFAULT_WEBGL': 37444
exports.default = void 0;
const testFuncs = ['activeTexture', 'attachShader', 'bindAttribLocation', 'bindBuffer', 'bindFramebuffer', 'bindRenderbuffer', 'bindTexture', 'blendColor', 'blendEquation', 'blendEquationSeparate', 'blendFunc', 'blendFuncSeparate', 'bufferData', 'bufferSubData', 'checkFramebufferStatus', 'clear', 'clearColor', 'clearDepth', 'clearStencil', 'colorMask', 'compileShader', 'compressedTexImage2D', 'compressedTexSubImage2D', 'copyTexImage2D', 'copyTexSubImage2D', 'createBuffer', 'createFramebuffer', 'createProgram', 'createRenderbuffer', 'createShader', 'createTexture', 'cullFace', 'deleteBuffer', 'deleteFramebuffer', 'deleteProgram', 'deleteRenderbuffer', 'deleteShader', 'deleteTexture', 'depthFunc', 'depthMask', 'depthRange', 'detachShader', 'disable', 'disableVertexAttribArray', 'drawArrays', 'drawElements', 'enable', 'enableVertexAttribArray', 'finish', 'flush', 'framebufferRenderbuffer', 'framebufferTexture2D', 'frontFace', 'generateMipmap', 'getActiveAttrib', 'getActiveUniform', 'getAttachedShaders', 'getAttribLocation', 'getBufferParameter', 'getError', 'getFramebufferAttachmentParameter', 'getProgramParameter', 'getProgramInfoLog', 'getRenderbufferParameter', 'getShaderParameter', 'getShaderInfoLog', 'getShaderPrecisionFormat', 'getShaderSource', 'getSupportedExtensions', 'getTexParameter', 'getUniform', 'getUniformLocation', 'getVertexAttrib', 'getVertexAttribOffset', 'hint', 'isBuffer', 'isContextLost', 'isEnabled', 'isFramebuffer', 'isProgram', 'isRenderbuffer', 'isShader', 'isTexture', 'lineWidth', 'linkProgram', 'pixelStorei', 'polygonOffset', 'readPixels', 'renderbufferStorage', 'sampleCoverage', 'scissor', 'shaderSource', 'stencilFunc', 'stencilFuncSeparate', 'stencilMask', 'stencilMaskSeparate', 'stencilOp', 'stencilOpSeparate', 'texParameterf', 'texParameteri', 'texImage2D', 'texSubImage2D', 'uniform1f', 'uniform1fv', 'uniform1i', 'uniform1iv', 'uniform2f', 'uniform2fv', 'uniform2i', 'uniform2iv', 'uniform3f', 'uniform3fv', 'uniform3i', 'uniform3iv', 'uniform4f', 'uniform4fv', 'uniform4i', 'uniform4iv', 'uniformMatrix2fv', 'uniformMatrix3fv', 'uniformMatrix4fv', 'useProgram', 'validateProgram', 'vertexAttrib1f', 'vertexAttrib1fv', 'vertexAttrib2f', 'vertexAttrib2fv', 'vertexAttrib3f', 'vertexAttrib3fv', 'vertexAttrib4f', 'vertexAttrib4fv', 'vertexAttribPointer', 'viewport'];
const mockEnums = {
DEPTH_BUFFER_BIT: 256,
STENCIL_BUFFER_BIT: 1024,
COLOR_BUFFER_BIT: 16384,
POINTS: 0,
LINES: 1,
LINE_LOOP: 2,
LINE_STRIP: 3,
TRIANGLES: 4,
TRIANGLE_STRIP: 5,
TRIANGLE_FAN: 6,
ZERO: 0,
ONE: 1,
SRC_COLOR: 768,
ONE_MINUS_SRC_COLOR: 769,
SRC_ALPHA: 770,
ONE_MINUS_SRC_ALPHA: 771,
DST_ALPHA: 772,
ONE_MINUS_DST_ALPHA: 773,
DST_COLOR: 774,
ONE_MINUS_DST_COLOR: 775,
SRC_ALPHA_SATURATE: 776,
FUNC_ADD: 32774,
BLEND_EQUATION: 32777,
BLEND_EQUATION_RGB: 32777,
BLEND_EQUATION_ALPHA: 34877,
FUNC_SUBTRACT: 32778,
FUNC_REVERSE_SUBTRACT: 32779,
BLEND_DST_RGB: 32968,
BLEND_SRC_RGB: 32969,
BLEND_DST_ALPHA: 32970,
BLEND_SRC_ALPHA: 32971,
CONSTANT_COLOR: 32769,
ONE_MINUS_CONSTANT_COLOR: 32770,
CONSTANT_ALPHA: 32771,
ONE_MINUS_CONSTANT_ALPHA: 32772,
BLEND_COLOR: 32773,
ARRAY_BUFFER: 34962,
ELEMENT_ARRAY_BUFFER: 34963,
ARRAY_BUFFER_BINDING: 34964,
ELEMENT_ARRAY_BUFFER_BINDING: 34965,
STREAM_DRAW: 35040,
STATIC_DRAW: 35044,
DYNAMIC_DRAW: 35048,
BUFFER_SIZE: 34660,
BUFFER_USAGE: 34661,
CURRENT_VERTEX_ATTRIB: 34342,
FRONT: 1028,
BACK: 1029,
FRONT_AND_BACK: 1032,
TEXTURE_2D: 3553,
CULL_FACE: 2884,
BLEND: 3042,
DITHER: 3024,
STENCIL_TEST: 2960,
DEPTH_TEST: 2929,
SCISSOR_TEST: 3089,
POLYGON_OFFSET_FILL: 32823,
SAMPLE_ALPHA_TO_COVERAGE: 32926,
SAMPLE_COVERAGE: 32928,
NO_ERROR: 0,
INVALID_ENUM: 1280,
INVALID_VALUE: 1281,
INVALID_OPERATION: 1282,
OUT_OF_MEMORY: 1285,
CW: 2304,
CCW: 2305,
LINE_WIDTH: 2849,
ALIASED_POINT_SIZE_RANGE: 33901,
ALIASED_LINE_WIDTH_RANGE: 33902,
CULL_FACE_MODE: 2885,
FRONT_FACE: 2886,
DEPTH_RANGE: 2928,
DEPTH_WRITEMASK: 2930,
DEPTH_CLEAR_VALUE: 2931,
DEPTH_FUNC: 2932,
STENCIL_CLEAR_VALUE: 2961,
STENCIL_FUNC: 2962,
STENCIL_FAIL: 2964,
STENCIL_PASS_DEPTH_FAIL: 2965,
STENCIL_PASS_DEPTH_PASS: 2966,
STENCIL_REF: 2967,
STENCIL_VALUE_MASK: 2963,
STENCIL_WRITEMASK: 2968,
STENCIL_BACK_FUNC: 34816,
STENCIL_BACK_FAIL: 34817,
STENCIL_BACK_PASS_DEPTH_FAIL: 34818,
STENCIL_BACK_PASS_DEPTH_PASS: 34819,
STENCIL_BACK_REF: 36003,
STENCIL_BACK_VALUE_MASK: 36004,
STENCIL_BACK_WRITEMASK: 36005,
VIEWPORT: 2978,
SCISSOR_BOX: 3088,
COLOR_CLEAR_VALUE: 3106,
COLOR_WRITEMASK: 3107,
UNPACK_ALIGNMENT: 3317,
PACK_ALIGNMENT: 3333,
MAX_TEXTURE_SIZE: 3379,
MAX_VIEWPORT_DIMS: 3386,
SUBPIXEL_BITS: 3408,
RED_BITS: 3410,
GREEN_BITS: 3411,
BLUE_BITS: 3412,
ALPHA_BITS: 3413,
DEPTH_BITS: 3414,
STENCIL_BITS: 3415,
POLYGON_OFFSET_UNITS: 10752,
POLYGON_OFFSET_FACTOR: 32824,
TEXTURE_BINDING_2D: 32873,
SAMPLE_BUFFERS: 32936,
SAMPLES: 32937,
SAMPLE_COVERAGE_VALUE: 32938,
SAMPLE_COVERAGE_INVERT: 32939,
COMPRESSED_TEXTURE_FORMATS: 34467,
DONT_CARE: 4352,
FASTEST: 4353,
NICEST: 4354,
GENERATE_MIPMAP_HINT: 33170,
BYTE: 5120,
UNSIGNED_BYTE: 5121,
SHORT: 5122,
UNSIGNED_SHORT: 5123,
INT: 5124,
UNSIGNED_INT: 5125,
FLOAT: 5126,
DEPTH_COMPONENT: 6402,
ALPHA: 6406,
RGB: 6407,
RGBA: 6408,
LUMINANCE: 6409,
LUMINANCE_ALPHA: 6410,
UNSIGNED_SHORT_4_4_4_4: 32819,
UNSIGNED_SHORT_5_5_5_1: 32820,
UNSIGNED_SHORT_5_6_5: 33635,
FRAGMENT_SHADER: 35632,
VERTEX_SHADER: 35633,
MAX_VERTEX_ATTRIBS: 34921,
MAX_VERTEX_UNIFORM_VECTORS: 36347,
MAX_VARYING_VECTORS: 36348,
MAX_COMBINED_TEXTURE_IMAGE_UNITS: 35661,
MAX_VERTEX_TEXTURE_IMAGE_UNITS: 35660,
MAX_TEXTURE_IMAGE_UNITS: 34930,
MAX_FRAGMENT_UNIFORM_VECTORS: 36349,
SHADER_TYPE: 35663,
DELETE_STATUS: 35712,
LINK_STATUS: 35714,
VALIDATE_STATUS: 35715,
ATTACHED_SHADERS: 35717,
ACTIVE_UNIFORMS: 35718,
ACTIVE_ATTRIBUTES: 35721,
SHADING_LANGUAGE_VERSION: 35724,
CURRENT_PROGRAM: 35725,
NEVER: 512,
LESS: 513,
EQUAL: 514,
LEQUAL: 515,
GREATER: 516,
NOTEQUAL: 517,
GEQUAL: 518,
ALWAYS: 519,
KEEP: 7680,
REPLACE: 7681,
INCR: 7682,
DECR: 7683,
INVERT: 5386,
INCR_WRAP: 34055,
DECR_WRAP: 34056,
VENDOR: 7936,
RENDERER: 7937,
VERSION: 7938,
NEAREST: 9728,
LINEAR: 9729,
NEAREST_MIPMAP_NEAREST: 9984,
LINEAR_MIPMAP_NEAREST: 9985,
NEAREST_MIPMAP_LINEAR: 9986,
LINEAR_MIPMAP_LINEAR: 9987,
TEXTURE_MAG_FILTER: 10240,
TEXTURE_MIN_FILTER: 10241,
TEXTURE_WRAP_S: 10242,
TEXTURE_WRAP_T: 10243,
TEXTURE: 5890,
TEXTURE_CUBE_MAP: 34067,
TEXTURE_BINDING_CUBE_MAP: 34068,
TEXTURE_CUBE_MAP_POSITIVE_X: 34069,
TEXTURE_CUBE_MAP_NEGATIVE_X: 34070,
TEXTURE_CUBE_MAP_POSITIVE_Y: 34071,
TEXTURE_CUBE_MAP_NEGATIVE_Y: 34072,
TEXTURE_CUBE_MAP_POSITIVE_Z: 34073,
TEXTURE_CUBE_MAP_NEGATIVE_Z: 34074,
MAX_CUBE_MAP_TEXTURE_SIZE: 34076,
TEXTURE0: 33984,
TEXTURE1: 33985,
TEXTURE2: 33986,
TEXTURE3: 33987,
TEXTURE4: 33988,
TEXTURE5: 33989,
TEXTURE6: 33990,
TEXTURE7: 33991,
TEXTURE8: 33992,
TEXTURE9: 33993,
TEXTURE10: 33994,
TEXTURE11: 33995,
TEXTURE12: 33996,
TEXTURE13: 33997,
TEXTURE14: 33998,
TEXTURE15: 33999,
TEXTURE16: 34000,
TEXTURE17: 34001,
TEXTURE18: 34002,
TEXTURE19: 34003,
TEXTURE20: 34004,
TEXTURE21: 34005,
TEXTURE22: 34006,
TEXTURE23: 34007,
TEXTURE24: 34008,
TEXTURE25: 34009,
TEXTURE26: 34010,
TEXTURE27: 34011,
TEXTURE28: 34012,
TEXTURE29: 34013,
TEXTURE30: 34014,
TEXTURE31: 34015,
ACTIVE_TEXTURE: 34016,
REPEAT: 10497,
CLAMP_TO_EDGE: 33071,
MIRRORED_REPEAT: 33648,
FLOAT_VEC2: 35664,
FLOAT_VEC3: 35665,
FLOAT_VEC4: 35666,
INT_VEC2: 35667,
INT_VEC3: 35668,
INT_VEC4: 35669,
BOOL: 35670,
BOOL_VEC2: 35671,
BOOL_VEC3: 35672,
BOOL_VEC4: 35673,
FLOAT_MAT2: 35674,
FLOAT_MAT3: 35675,
FLOAT_MAT4: 35676,
SAMPLER_2D: 35678,
SAMPLER_CUBE: 35680,
VERTEX_ATTRIB_ARRAY_ENABLED: 34338,
VERTEX_ATTRIB_ARRAY_SIZE: 34339,
VERTEX_ATTRIB_ARRAY_STRIDE: 34340,
VERTEX_ATTRIB_ARRAY_TYPE: 34341,
VERTEX_ATTRIB_ARRAY_NORMALIZED: 34922,
VERTEX_ATTRIB_ARRAY_POINTER: 34373,
VERTEX_ATTRIB_ARRAY_BUFFER_BINDING: 34975,
IMPLEMENTATION_COLOR_READ_TYPE: 35738,
IMPLEMENTATION_COLOR_READ_FORMAT: 35739,
COMPILE_STATUS: 35713,
LOW_FLOAT: 36336,
MEDIUM_FLOAT: 36337,
HIGH_FLOAT: 36338,
LOW_INT: 36339,
MEDIUM_INT: 36340,
HIGH_INT: 36341,
FRAMEBUFFER: 36160,
RENDERBUFFER: 36161,
RGBA4: 32854,
RGB5_A1: 32855,
RGB565: 36194,
DEPTH_COMPONENT16: 33189,
STENCIL_INDEX: 6401,
STENCIL_INDEX8: 36168,
DEPTH_STENCIL: 34041,
RENDERBUFFER_WIDTH: 36162,
RENDERBUFFER_HEIGHT: 36163,
RENDERBUFFER_INTERNAL_FORMAT: 36164,
RENDERBUFFER_RED_SIZE: 36176,
RENDERBUFFER_GREEN_SIZE: 36177,
RENDERBUFFER_BLUE_SIZE: 36178,
RENDERBUFFER_ALPHA_SIZE: 36179,
RENDERBUFFER_DEPTH_SIZE: 36180,
RENDERBUFFER_STENCIL_SIZE: 36181,
FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE: 36048,
FRAMEBUFFER_ATTACHMENT_OBJECT_NAME: 36049,
FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL: 36050,
FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE: 36051,
COLOR_ATTACHMENT0: 36064,
DEPTH_ATTACHMENT: 36096,
STENCIL_ATTACHMENT: 36128,
DEPTH_STENCIL_ATTACHMENT: 33306,
NONE: 0,
FRAMEBUFFER_COMPLETE: 36053,
FRAMEBUFFER_INCOMPLETE_ATTACHMENT: 36054,
FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT: 36055,
FRAMEBUFFER_INCOMPLETE_DIMENSIONS: 36057,
FRAMEBUFFER_UNSUPPORTED: 36061,
FRAMEBUFFER_BINDING: 36006,
RENDERBUFFER_BINDING: 36007,
MAX_RENDERBUFFER_SIZE: 34024,
INVALID_FRAMEBUFFER_OPERATION: 1286,
UNPACK_FLIP_Y_WEBGL: 37440,
UNPACK_PREMULTIPLY_ALPHA_WEBGL: 37441,
CONTEXT_LOST_WEBGL: 37442,
UNPACK_COLORSPACE_CONVERSION_WEBGL: 37443,
BROWSER_DEFAULT_WEBGL: 37444
};
var mockExtensions = {
const mockExtensions = {
// ratified
'OES_texture_float': {},
'OES_texture_half_float': {},
'WEBGL_lose_context': {
restoreContext: function restoreContext() {},
loseContext: function loseContext() {}
OES_texture_float: {},
OES_texture_half_float: {},
WEBGL_lose_context: {
restoreContext() {},
loseContext() {}
},
'OES_standard_derivatives': {},
'OES_vertex_array_object': {
createVertexArrayOES: function createVertexArrayOES() {},
bindVertexArrayOES: function bindVertexArrayOES(param) {},
deleteVertexArrayOES: function deleteVertexArrayOES(param) {}
OES_standard_derivatives: {},
OES_vertex_array_object: {
createVertexArrayOES() {},
bindVertexArrayOES(param) {},
deleteVertexArrayOES(param) {}
},
'WEBGL_debug_renderer_info': null,
'WEBGL_debug_shaders': null,
'WEBGL_compressed_texture_s3tc': null,
'WEBGL_depth_texture': {},
'OES_element_index_uint': {},
'EXT_texture_filter_anisotropic': null,
'EXT_frag_depth': {},
'WEBGL_draw_buffers': {},
'ANGLE_instanced_arrays': null,
'OES_texture_float_linear': null,
'OES_texture_half_float_linear': null,
'EXT_blend_minmax': null,
'EXT_shader_texture_lod': null,
WEBGL_debug_renderer_info: null,
WEBGL_debug_shaders: null,
WEBGL_compressed_texture_s3tc: null,
WEBGL_depth_texture: {},
OES_element_index_uint: {},
EXT_texture_filter_anisotropic: null,
EXT_frag_depth: {},
WEBGL_draw_buffers: {},
ANGLE_instanced_arrays: null,
OES_texture_float_linear: null,
OES_texture_half_float_linear: null,
EXT_blend_minmax: {},
EXT_shader_texture_lod: null,
// community
'WEBGL_compressed_texture_atc': null,
'WEBGL_compressed_texture_pvrtc': null,
'EXT_color_buffer_half_float': null,
'WEBGL_color_buffer_float': null,
'EXT_sRGB': null,
'WEBGL_compressed_texture_etc1': null
WEBGL_compressed_texture_atc: null,
WEBGL_compressed_texture_pvrtc: null,
EXT_color_buffer_half_float: null,
WEBGL_color_buffer_float: null,
EXT_sRGB: null,
WEBGL_compressed_texture_etc1: null
};
var mockParams = {
34930: 16 // MAX_TEXTURE_IMAGE_UNITS
const mockParams = {
[mockEnums['MAX_TEXTURE_IMAGE_UNITS']]: 16,
[mockEnums['VERSION']]: 'WebGL 2.0 (OpenGL ES 3.0 Chromium)',
[mockEnums['SCISSOR_BOX']]: new Int32Array([0, 0, 300, 150]),
[mockEnums['VIEWPORT']]: new Int32Array([0, 0, 300, 150])
};
var WebGLRenderingContext =
/*#__PURE__*/
function () {
function WebGLRenderingContext(canvas, contextAttributes) {
_classCallCheck(this, WebGLRenderingContext);
class WebGLRenderingContext {
constructor(canvas, contextAttributes) {
this._contextAttributes = contextAttributes;
testFuncs.forEach(function (key) {
testFuncs.forEach(key => {
WebGLRenderingContext.prototype[key] = function () {

@@ -367,3 +357,3 @@ return key === 'getSupportedExtensions' ? [] : {};

});
Object.keys(mockEnums).forEach(function (key) {
Object.keys(mockEnums).forEach(key => {
WebGLRenderingContext.prototype[key] = mockEnums[key];

@@ -373,23 +363,19 @@ });

}
_createClass(WebGLRenderingContext, [{
key: "getExtension",
value: function getExtension(ext) {
return mockExtensions[ext];
}
}, {
key: "getParameter",
value: function getParameter(param) {
return mockParams[param];
}
}, {
key: "getContextAttributes",
value: function getContextAttributes() {
return this._contextAttributes;
}
}]);
return WebGLRenderingContext;
}();
exports["default"] = WebGLRenderingContext;
getExtension(ext) {
return mockExtensions[ext];
}
getParameter(param) {
return mockParams[param];
}
getContextAttributes() {
return this._contextAttributes;
}
getShaderPrecisionFormat() {
return {
rangeMin: 127,
rangeMax: 127,
precision: 23
};
}
}
exports.default = WebGLRenderingContext;

@@ -6,8 +6,6 @@ "use strict";

});
exports.setupJestCanvasMock = setupJestCanvasMock;
exports.ver = void 0;
var _window = _interopRequireDefault(require("./window"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**

@@ -17,9 +15,12 @@ * Created by hustcc 17/12/25.

*/
// mock global window
// TODO: Force coverage to ignore this branch
if (typeof window !== 'undefined') {
global.window = (0, _window["default"])(window);
(0, _window.default)(global.window);
}
var ver = "0.2.3";
exports.ver = ver;
const ver = "2.5.0";
exports.ver = ver;
function setupJestCanvasMock(window) {
(0, _window.default)(window || global.window);
}

@@ -6,4 +6,3 @@ "use strict";

});
exports["default"] = createCanvasEvent;
exports.default = createCanvasEvent;
/**

@@ -26,6 +25,6 @@ * This function returns a CanvasRenderingContext2DEvent. Whenever an operation would modify the canvas

return {
type: type,
transform: transform,
props: props
type,
transform,
props
};
}

@@ -6,28 +6,21 @@ "use strict";

});
exports["default"] = void 0;
exports.default = void 0;
var _ImageBitmap = _interopRequireDefault(require("../classes/ImageBitmap"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var _default = jest.fn(function createImageBitmap(img, sx, sy, sWidth, sHeight, options) {
var length = arguments.length;
return new Promise(function (resolve, reject) {
if (length === 0) return reject(new TypeError('Failed to execute \'createImageBitmap\' on \'Window\': 1 argument required, but only 0 present.'));
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.'));
var validImage = false;
return new Promise((resolve, reject) => {
if (length === 0) return reject(new TypeError("Failed to execute 'createImageBitmap' on 'Window': 1 argument required, but only 0 present."));
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.'));
let validImage = false;
if (img instanceof HTMLImageElement) validImage = true;
if (img instanceof HTMLVideoElement) validImage = true;
if (img instanceof HTMLCanvasElement) validImage = true; // checking constructor name is the only reliable way to verify the object's constructing class is "blob-like"
if (img instanceof Blob || img && img.constructor && img.constructor.name === "Blob") validImage = true;
if (img instanceof _ImageBitmap["default"]) validImage = true;
if (img instanceof HTMLCanvasElement) validImage = true;
// checking constructor name is the only reliable way to verify the object's constructing class is "blob-like"
if (img instanceof Blob || img && img.constructor && img.constructor.name === 'Blob') validImage = true;
if (img instanceof _ImageBitmap.default) validImage = true;
if (img instanceof ImageData) validImage = true;
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)\''));
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)'"));
if (length >= 2) {
var index = 6;
let index = 6;
if (length === 2) {

@@ -37,10 +30,7 @@ index = 2;

}
if (length === 5) options = null;
if (options !== null && options !== void 0) {
if (_typeof(options) !== 'object') throw new TypeError('Failed to execute \'createImageBitmap\' on \'Window\': parameter ' + index + ' (\'options\') is not an object.');
if (typeof options !== 'object') throw new TypeError("Failed to execute 'createImageBitmap' on 'Window': parameter " + index + " ('options') is not an object.");
}
}
if (length >= 5) {

@@ -57,7 +47,5 @@ sWidth = Number(sWidth);

}
return resolve(new _ImageBitmap["default"](sWidth, sHeight));
return resolve(new _ImageBitmap.default(sWidth, sHeight));
});
});
exports["default"] = _default;
exports.default = _default;

@@ -6,10 +6,6 @@ "use strict";

});
exports["default"] = mockPrototype;
exports.default = mockPrototype;
var _CanvasRenderingContext2D = _interopRequireDefault(require("../classes/CanvasRenderingContext2D"));
var _WebGLRenderingContext = _interopRequireDefault(require("../classes/WebGLRenderingContext"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function mockPrototype() {

@@ -21,3 +17,3 @@ /**

*/
var generatedContexts = new WeakMap();
const generatedContexts = new WeakMap();
/**

@@ -28,11 +24,10 @@ * Overrides getContext. Every test run will create a new function that overrides the current

*/
function getContext(type, options) {
if (type === '2d') {
/**
* Contexts must be indempotent. Once they are generated, they should be returned when
* Contexts must be idempotent. Once they are generated, they should be returned when
* getContext() is called on the same canvas object multiple times.
*/
if (generatedContexts.has(this)) return generatedContexts.get(this);
var ctx = new _CanvasRenderingContext2D["default"](this, options);
const ctx = new _CanvasRenderingContext2D.default(this, options);
generatedContexts.set(this, ctx);

@@ -42,14 +37,11 @@ return ctx;

if (generatedContexts.has(this)) return generatedContexts.get(this);
var _ctx = new _WebGLRenderingContext["default"](this, options);
generatedContexts.set(this, _ctx);
return _ctx;
const ctx = new _WebGLRenderingContext.default(this, options);
generatedContexts.set(this, ctx);
return ctx;
}
return getContext.internal.call(this, type, options);
}
getContext.internal = HTMLCanvasElement.prototype.getContext;
HTMLCanvasElement.prototype.getContext = getContext;
/**

@@ -59,6 +51,6 @@ * This function technically throws SecurityError at runtime, but it cannot be mocked, because

*/
const toBlobOverride = jest.fn(function toBlobOverride(callback, mimetype) {
if (arguments.length < 1) throw new TypeError("Failed to execute 'toBlob' on 'HTMLCanvasElement': 1 argument required, but only 0 present.");
if (typeof callback !== 'function') throw new TypeError("Failed to execute 'toBlob' on 'HTMLCanvasElement': The callback provided as parameter 1 is not a function.");
var toBlobOverride = jest.fn(function toBlobOverride(callback, mimetype) {
if (arguments.length < 1) throw new TypeError('Failed to execute \'toBlob\' on \'HTMLCanvasElement\': 1 argument required, but only 0 present.');
if (typeof callback !== 'function') throw new TypeError('Failed to execute \'toBlob\' on \'HTMLCanvasElement\': The callback provided as parameter 1 is not a function.');
/**

@@ -68,13 +60,11 @@ * Mime type must be image/jpeg or image/webp exactly for the browser to accept it, otherwise

*/
switch (mimetype) {
case 'image/webp':
break;
case 'image/jpeg':
break;
default:
mimetype = 'image/png';
}
/**

@@ -84,14 +74,9 @@ * This section creates a blob of size width * height * 4. This is not actually valid, because

*/
var length = this.width * this.height * 4;
var data = new Uint8Array(length);
var blob = new window.Blob([data], {
const length = this.width * this.height * 4;
const data = new Uint8Array(length);
const blob = new window.Blob([data], {
type: mimetype
});
setTimeout(function () {
return callback(blob);
}, 0);
setTimeout(() => callback(blob), 0);
});
if (!jest.isMockFunction(HTMLCanvasElement.prototype.toBlob)) {

@@ -102,4 +87,4 @@ toBlobOverride.internal = HTMLCanvasElement.prototype.toBlob;

}
HTMLCanvasElement.prototype.toBlob = toBlobOverride;
HTMLCanvasElement.prototype.toBlob = toBlobOverride;
/**

@@ -109,29 +94,23 @@ * This section creates a dataurl with a validated mime type. This is not actually valid, because

*/
var toDataURLOverride = jest.fn(function toDataURLOverride(type, encoderOptions) {
const toDataURLOverride = jest.fn(function toDataURLOverride(type, encoderOptions) {
switch (type) {
case 'image/jpeg':
break;
case 'image/webp':
break;
default:
type = 'image/png';
}
/**
* This is the smallest valid data url I could generate.
*/
return 'data:' + type + ';base64,00';
});
if (!jest.isMockFunction(HTMLCanvasElement.prototype.toDataURL)) {
toDataURLOverride.internal = HTMLCanvasElement.prototype.toDataURL;
} else {
toDataURLOverride.internal = HTMLCanvasElement.prototype.toBlob.internal;
toDataURLOverride.internal = HTMLCanvasElement.prototype.toDataURL.internal;
}
HTMLCanvasElement.prototype.toDataURL = toDataURLOverride;
}

@@ -6,30 +6,16 @@ "use strict";

});
exports["default"] = void 0;
exports.default = void 0;
var _Path2D = _interopRequireDefault(require("./classes/Path2D"));
var _CanvasGradient = _interopRequireDefault(require("./classes/CanvasGradient"));
var _CanvasPattern = _interopRequireDefault(require("./classes/CanvasPattern"));
var _CanvasRenderingContext2D = _interopRequireDefault(require("./classes/CanvasRenderingContext2D"));
var _DOMMatrix = _interopRequireDefault(require("./classes/DOMMatrix"));
var _ImageData = _interopRequireDefault(require("./classes/ImageData"));
var _TextMetrics = _interopRequireDefault(require("./classes/TextMetrics"));
var _ImageBitmap = _interopRequireDefault(require("./classes/ImageBitmap"));
var _prototype = _interopRequireDefault(require("./mock/prototype"));
var _createImageBitmap = _interopRequireDefault(require("./mock/createImageBitmap"));
var _Image = _interopRequireDefault(require("./classes/Image"));
var _WebGLRenderingContext = _interopRequireDefault(require("./classes/WebGLRenderingContext"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**

@@ -39,7 +25,9 @@ * Created by hustcc 17/12/25.

*/
var _default = function _default(win) {
var d = win.document;
var f = win.document.createElement; // jsdom@11.6.2 || jest@^22.0.0, console.error in Function getContext();
var _default = win => {
const d = win.document;
const f = win.document.createElement;
// jsdom@11.6.2 || jest@^22.0.0, console.error in Function getContext();
// https://github.com/jsdom/jsdom/blob/4c7698f760fc64f20b2a0ddff450eddbdd193176/lib/jsdom/living/nodes/HTMLCanvasElement-impl.js#L55-L58
// cosole.error will make ci error.
// console.error will make ci error.
// try {

@@ -62,3 +50,2 @@ // // get the context 2d.

// just mock canvas creator.
/*

@@ -70,17 +57,17 @@ win.document.createElement = param => param.toString().toLowerCase() === 'canvas'

// if not exist, then mock it.
if (!win.Path2D) win.Path2D = _Path2D.default;
if (!win.CanvasGradient) win.CanvasGradient = _CanvasGradient.default;
if (!win.CanvasPattern) win.CanvasPattern = _CanvasPattern.default;
if (!win.CanvasRenderingContext2D) win.CanvasRenderingContext2D = _CanvasRenderingContext2D.default;
if (!win.DOMMatrix) win.DOMMatrix = _DOMMatrix.default;
if (!win.ImageData) win.ImageData = _ImageData.default;
if (!win.TextMetrics) win.TextMetrics = _TextMetrics.default;
if (!win.ImageBitmap) win.ImageBitmap = _ImageBitmap.default;
if (!win.createImageBitmap) win.createImageBitmap = _createImageBitmap.default;
if (!win.Image) win.Image = _Image.default;
if (!win.HTMLImageElement) win.HTMLImageElement = _Image.default;
if (!win.HTMLVideoElement) win.HTMLVideoElement = _Image.default;
if (!win.Path2D) win.Path2D = _Path2D["default"];
if (!win.CanvasGradient) win.CanvasGradient = _CanvasGradient["default"];
if (!win.CanvasPattern) win.CanvasPattern = _CanvasPattern["default"];
if (!win.CanvasRenderingContext2D) win.CanvasRenderingContext2D = _CanvasRenderingContext2D["default"];
if (!win.DOMMatrix) win.DOMMatrix = _DOMMatrix["default"];
if (!win.ImageData) win.ImageData = _ImageData["default"];
if (!win.TextMetrics) win.TextMetrics = _TextMetrics["default"];
if (!win.ImageBitmap) win.ImageBitmap = _ImageBitmap["default"];
if (!win.createImageBitmap) win.createImageBitmap = _createImageBitmap["default"];
if (!win.Image) win.Image = _Image["default"];
if (!win.HTMLImageElement) win.HTMLImageElement = _Image["default"];
if (!win.HTMLVideoElement) win.HTMLVideoElement = _Image["default"]; // WebGL 1.0
if (!win.WebGLRenderingContext) win.WebGLRenderingContext = _WebGLRenderingContext["default"];
// WebGL 1.0
if (!win.WebGLRenderingContext) win.WebGLRenderingContext = _WebGLRenderingContext.default;
if (!win.WebGLActiveInfo) win.WebGLActiveInfo = function () {};

@@ -97,6 +84,5 @@ if (!win.WebGLBuffer) win.WebGLBuffer = function () {};

if (!win.WebGLUniformLocation) win.WebGLUniformLocation = function () {};
(0, _prototype["default"])();
(0, _prototype.default)();
return win;
};
exports["default"] = _default;
exports.default = _default;
{
"name": "jest-webgl-canvas-mock",
"version": "0.2.3",
"version": "2.5.0",
"description": "Mock both 2D and WebGL contexts in Jest.",

@@ -13,21 +13,23 @@ "main": "lib/index.js",

"build": "babel src --out-dir lib",
"coveralls": "cat ./coverage/lcov.info | coveralls",
"prepare": "npm run build"
"prepare": "npm run build",
"prettier": "prettier --write ."
},
"dependencies": {
"cssfontparser": "^1.2.1",
"parse-color": "^1.0.0"
"moo-color": "^1.0.2"
},
"devDependencies": {
"@babel/cli": "^7.4.4",
"@babel/core": "^7.4.4",
"@babel/plugin-proposal-class-properties": "^7.4.4",
"@babel/preset-env": "^7.4.4",
"@commitlint/cli": "^7.5.2",
"@commitlint/config-angular": "^7.5.0",
"babel-jest": "^24.8.0",
"@antv/g2plot": "^2.3.11",
"@babel/cli": "^7.8.4",
"@babel/core": "^7.9.0",
"@babel/plugin-proposal-class-properties": "^7.8.3",
"@babel/preset-env": "^7.9.5",
"@commitlint/cli": "^17.6.1",
"@commitlint/config-angular": "^17.6.1",
"babel-jest": "^25.3.0",
"babel-plugin-version": "^0.2.3",
"coveralls": "^3.0.3",
"husky": "^2.2.0",
"jest": "^24.8.0"
"husky": "^4.2.5",
"jest": "^29.5.0",
"jest-environment-jsdom": "^29.5.0",
"prettier": "^2.0.4"
},

@@ -42,6 +44,7 @@ "commitlint": {

"commit-msg": "commitlint -E HUSKY_GIT_PARAMS",
"pre-commit": "npm run test && npm run build"
"pre-commit": "npm run prettier && npm run test && npm run build"
}
},
"jest": {
"testEnvironment": "jsdom",
"collectCoverage": true,

@@ -53,3 +56,4 @@ "collectCoverageFrom": [

"setupFiles": [
"./src/index.js"
"./src/index.js",
"./__mocks__/worker.js"
]

@@ -75,2 +79,7 @@ },

],
"files": [
"CHANGELOG.md",
"lib/",
"types/"
],
"author": "adamfsk",

@@ -77,0 +86,0 @@ "license": "MIT",

# jest-webgl-canvas-mock
> Mock `canvas` and `WebGL` when running unit test cases with jest.
> Mock `canvas` and `WebGL` 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.
[![Build Status](https://travis-ci.org/adamfsk/jest-webgl-canvas-mock.svg?branch=master)](https://travis-ci.org/adamfsk/jest-webgl-canvas-mock)
[![Coverage Status](https://coveralls.io/repos/github/adamfsk/jest-webgl-canvas-mock/badge.svg?branch=master)](https://coveralls.io/github/adamfsk/jest-webgl-canvas-mock)
[![Build Status](https://github.com/adamfsk/jest-webgl-canvas-mock/workflows/build/badge.svg)](https://github.com/adamfsk/jest-webgl-canvas-mock/actions/workflows/build.yml)
[![npm](https://img.shields.io/npm/v/jest-webgl-canvas-mock.svg)](https://www.npmjs.com/package/jest-webgl-canvas-mock)

@@ -12,3 +11,5 @@ [![npm](https://img.shields.io/npm/dm/jest-webgl-canvas-mock.svg)](https://www.npmjs.com/package/jest-webgl-canvas-mock)

This project is a simple merge of [jest-canvas-mock](https://github.com/hustcc/jest-canvas-mock) with [webgl-mock](https://github.com/kbirk/webgl-mock) so that both 2d and webgl contexts can be tested in jest. As such, the only tests provided are those from the original projects.
This project is a simple merge of [jest-canvas-mock](https://github.com/hustcc/jest-canvas-mock) with
[webgl-mock](https://github.com/kbirk/webgl-mock) so that both 2d and webgl contexts can be tested in jest.
As such, the only tests provided are those from the original projects.

@@ -27,3 +28,2 @@ The current goal of this project is simply to make any tests using `pixi.js` work in jest.

## Setup

@@ -53,3 +53,2 @@

## Setup file

@@ -78,2 +77,16 @@

## Reset
If you reset the jest mocks (for example, with `jest.resetAllMocks()`), you can
call `setupJestCanvasMock()` to re-create it.
```
import { setupJestCanvasMock } from 'jest-webgl-canvas-mock';
beforeEach(() => {
jest.resetAllMocks();
setupJestCanvasMock();
});
```
## Mock Strategy

@@ -98,3 +111,3 @@

```ts
expect(() => ctx.arc("10", "10", "20", "0", "6.14")).not.toThrow();
expect(() => ctx.arc('10', '10', '20', '0', '6.14')).not.toThrow();
```

@@ -107,4 +120,4 @@

```ts
expect(() => ctx.fill("invalid!")).toThrow(TypeError);
expect(() => ctx.fill(new Path2D(), "invalid!")).toThrow(TypeError);
expect(() => ctx.fill('invalid!')).toThrow(TypeError);
expect(() => ctx.fill(new Path2D(), 'invalid!')).toThrow(TypeError);
```

@@ -114,7 +127,7 @@

# Snapshots
## Snapshots
There are multiple ways to validate canvas state. There are currently three `static` methods attached
to the `CanvasRenderingContext2D` class. The first way to use this feature is by using the `__getEvents`
method.
There are multiple ways to validate canvas state using snapshots. There are currently three methods
attached to the `CanvasRenderingContext2D` class. The first way to use this feature is by using the
`__getEvents` method.

@@ -148,3 +161,3 @@ ```ts

The third way is to inspect all of the success draw calls submitted to the context.
The third way is to inspect all of the successful draw calls submitted to the context.

@@ -162,2 +175,23 @@ ```ts

In some cases it may be useful to clear the events or draw calls that have already been logged.
```ts
// Clear events
ctx.__clearEvents();
// Clear draw calls
ctx.__clearDrawCalls();
```
Finally, it's possible to inspect the clipping region calls by using the `__getClippingRegion`
function.
```ts
const clippingRegion = ctx.__getClippingRegion();
expect(clippingRegion).toMatchSnapshot();
```
The clipping region cannot be cleared because it's based on the stack values and when the `.clip()`
function is called.
## Override default mock return value

@@ -173,4 +207,13 @@

## Contributors
- [@hustcc](https://github.com/hustcc)
- [@jtenner](https://github.com/jtenner)
- [@evanoc0](https://github.com/evanoc0)
- [@lekha](https://github.com/lekha)
- [@yonatankra](https://github.com/yonatankra)
- [@LitoMore](https://github.com/LitoMore)
## License
MIT

@@ -0,4 +1,6 @@

export function setupJestCanvasMock(window?: Window) {}
export interface CanvasRenderingContext2DEvent {
/**
* This is the type of canvas event that occured.
* This is the type of canvas event that occurred.
*/

@@ -33,2 +35,14 @@ type: string;

/**
* Clear all the events associated with this CanvasRenderingContext2D object.
*
* This method cannot be used in a production environment, only with `jest` using
* `jest-canvas-mock` and should only be used for testing.
*
* @example
* ctx.__clearEvents());
* expect(ctx.__getEvents()).toBe([]);
*/
__clearEvents(): void;
/**
* Get all the successful draw calls associated with this CanvasRenderingContext2D object.

@@ -45,2 +59,14 @@ *

/**
* Clear all the successful draw calls associated with this CanvasRenderingContext2D object.
*
* This method cannot be used in a production environment, only with `jest` using
* `jest-canvas-mock` and should only be used for testing.
*
* @example
* ctx.__clearDrawCalls());
* expect(ctx.__getDrawCalls()).toBe([]);
*/
__clearDrawCalls(): void;
/**
* Get the current path associated with this CanvasRenderingContext2D object.

@@ -55,2 +81,18 @@ *

__getPath(): CanvasRenderingContext2DEvent[];
/**
* Clears the current path associated with this CanvasRenderingContext2D object.
*
* This method cannot be used in a production environment, only with `jest` using
* `jest-canvas-mock` and should be only used for testing.
*/
__clearPath(): void;
/**
* Obtains the current clipping path.
*
* This method cannot be used in a production environment, only with `jest` using
* `jest-canvas-mock` and should be only used for testing.
*/
__getClippingRegion(): CanvasRenderingContext2DEvent[];
}

@@ -57,0 +99,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc