jest-canvas-mock 2.1.2 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports["default"] = void 0;
6
+ exports.default = void 0;
7
7
 
8
8
  var _DOMMatrix = _interopRequireDefault(require("./DOMMatrix"));
9
9
 
@@ -17,25 +17,19 @@ var _TextMetrics = _interopRequireDefault(require("./TextMetrics"));
17
17
 
18
18
  var _createCanvasEvent = _interopRequireDefault(require("../mock/createCanvasEvent"));
19
19
 
20
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
21
-
22
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
23
-
24
- 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); } }
25
-
26
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
20
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
27
21
 
28
22
  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; }
29
23
 
30
24
  function parseCSSColor(value) {
31
- var result = (0, _parseColor["default"])(value);
25
+ const result = (0, _parseColor.default)(value);
32
26
 
33
27
  if (result.rgba && result.rgba[3] !== 1) {
34
28
  return 'rgba(' + result.rgba.join(', ') + ')';
35
29
  }
36
30
 
37
31
  if (result.hex) {
38
- var hex = result.hex; // shorthand #ABC
32
+ const hex = result.hex; // shorthand #ABC
39
33
 
40
34
  if (hex[1] === hex[2] && hex[3] === hex[4] && hex[5] === hex[6]) {
41
35
  return '#' + hex[1] + hex[3] + hex[5];
@@ -47,58 +41,71 @@ function parseCSSColor(value) {
47
41
  return void 0;
48
42
  }
49
43
 
50
- 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'];
51
- 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'];
44
+ 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'];
45
+ 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'];
52
46
 
53
47
  function getTransformSlice(ctx) {
54
48
  return ctx._transformStack[ctx._stackIndex].slice();
55
49
  }
56
50
 
57
- var CanvasRenderingContext2D =
58
- /*#__PURE__*/
59
- function () {
60
- _createClass(CanvasRenderingContext2D, [{
61
- key: "__getDrawCalls",
62
-
63
- /**
64
- * Every time a function call would result in a drawing operation, it should be added to this array.
65
- * This goes for only draw call functions.
66
- */
67
- value: function __getDrawCalls() {
68
- return this._drawCalls.slice();
69
- }
70
- /**
71
- * Every time a function call results in something that would have modified the state of the context,
72
- * an event is added to this array. This goes for every property set, and draw call.
73
- */
74
-
75
- }, {
76
- key: "__getEvents",
77
- value: function __getEvents() {
78
- return this._events.slice();
79
- }
80
- /**
81
- * This array keeps track of the current path, so that fill and stroke operations can store the
82
- * path.
83
- */
84
-
85
- }, {
86
- key: "__getPath",
87
- value: function __getPath() {
88
- return this._path.slice();
89
- }
90
- }]);
51
+ class CanvasRenderingContext2D {
52
+ /**
53
+ * Every time a function call would result in a drawing operation, it should be added to this array.
54
+ * This goes for only draw call functions.
55
+ */
56
+ __getDrawCalls() {
57
+ return this._drawCalls.slice();
58
+ }
59
+ /**
60
+ * Clear the list of draw calls
61
+ */
62
+
63
+
64
+ __clearDrawCalls() {
65
+ this._drawCalls = [];
66
+ }
67
+ /**
68
+ * Every time a function call results in something that would have modified the state of the context,
69
+ * an event is added to this array. This goes for every property set, and draw call.
70
+ */
71
+
72
+
73
+ __getEvents() {
74
+ return this._events.slice();
75
+ }
76
+ /**
77
+ * Clear the list of events
78
+ */
79
+
80
+
81
+ __clearEvents() {
82
+ this._events = [];
83
+ }
84
+ /**
85
+ * This array keeps track of the current path, so that fill and stroke operations can store the
86
+ * path.
87
+ */
88
+
89
+
90
+ __getPath() {
91
+ return this._path.slice();
92
+ }
93
+ /**
94
+ * Clear the path and reset it to a single beginPath event.
95
+ */
91
96
 
92
- function CanvasRenderingContext2D(canvas) {
93
- var _this = this;
94
97
 
95
- _classCallCheck(this, CanvasRenderingContext2D);
98
+ __clearPath() {
99
+ const event = (0, _createCanvasEvent.default)('beginPath', getTransformSlice(this), {});
100
+ this._path = [event];
101
+ }
96
102
 
103
+ constructor(canvas) {
97
104
  _defineProperty(this, "_drawCalls", []);
98
105
 
99
106
  _defineProperty(this, "_events", []);
100
107
 
101
- _defineProperty(this, "_path", [(0, _createCanvasEvent["default"])('beginPath', [1, 0, 0, 1, 0, 0], {})]);
108
+ _defineProperty(this, "_path", [(0, _createCanvasEvent.default)('beginPath', [1, 0, 0, 1, 0, 0], {})]);
102
109
 
103
110
  _defineProperty(this, "_directionStack", ['inherit']);
104
111
 
@@ -146,1432 +153,1379 @@ function () {
146
153
 
147
154
  _defineProperty(this, "_transformStack", [[1, 0, 0, 1, 0, 0]]);
148
155
 
149
- testFuncs.forEach(function (key) {
150
- _this[key] = jest.fn(CanvasRenderingContext2D.prototype[key].bind(_this));
156
+ testFuncs.forEach(key => {
157
+ this[key] = jest.fn(CanvasRenderingContext2D.prototype[key].bind(this));
151
158
  });
152
159
  this._canvas = canvas;
153
160
  }
154
161
 
155
- _createClass(CanvasRenderingContext2D, [{
156
- key: "addHitRegion",
157
- value: function addHitRegion() {
158
- var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
159
- var path = options.path,
160
- fillRule = options.fillRule,
161
- id = options.id,
162
- parentID = options.parentID,
163
- cursor = options.cursor,
164
- control = options.control,
165
- label = options.label,
166
- role = options.role;
167
- if (!path && !id) throw new DOMException('ConstraintError', 'Failed to execute \'addHitRegion\' on \'' + this.constructor.name + '\': Both id and control are null.');
168
- 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.');
169
-
170
- this._events.push((0, _createCanvasEvent["default"])('addHitRegion', getTransformSlice(this), {
171
- path: path,
172
- fillRule: fillRule,
173
- id: id,
174
- parentID: parentID,
175
- cursor: cursor,
176
- control: control,
177
- label: label,
178
- role: role
179
- }));
180
- }
181
- }, {
182
- key: "arc",
183
- value: function arc(x, y, radius, startAngle, endAngle) {
184
- var anticlockwise = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : false;
185
- if (arguments.length < 5) throw new TypeError('Failed to execute \'arc\' on \'' + this.constructor.name + '\': 5 arguments required, but only ' + arguments.length + ' present.');
186
- var xResult = Number(x);
187
- var yResult = Number(y);
188
- var radiusResult = Number(radius);
189
- var startAngleResult = Number(startAngle);
190
- var endAngleResult = Number(endAngle);
191
- var anticlockwiseResult = Boolean(anticlockwise); // quick is finite check
192
-
193
- if (!Number.isFinite(xResult + yResult + radiusResult + startAngleResult + endAngleResult)) return;
194
- if (Number(radius) < 0) throw new DOMException('IndexSizeError', 'Failed to execute \'arc\' on \'' + this.constructor.name + '\': The radius provided (' + radius + ') is negative.');
195
- var event = (0, _createCanvasEvent["default"])('arc', getTransformSlice(this), {
196
- x: xResult,
197
- y: yResult,
198
- radius: radiusResult,
199
- startAngle: startAngleResult,
200
- endAngle: endAngleResult,
201
- anticlockwise: anticlockwiseResult
202
- });
162
+ addHitRegion(options = {}) {
163
+ const {
164
+ path,
165
+ fillRule,
166
+ id,
167
+ parentID,
168
+ cursor,
169
+ control,
170
+ label,
171
+ role
172
+ } = options;
173
+ if (!path && !id) throw new DOMException('ConstraintError', 'Failed to execute \'addHitRegion\' on \'' + this.constructor.name + '\': Both id and control are null.');
174
+ 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.');
175
+
176
+ this._events.push((0, _createCanvasEvent.default)('addHitRegion', getTransformSlice(this), {
177
+ path,
178
+ fillRule,
179
+ id,
180
+ parentID,
181
+ cursor,
182
+ control,
183
+ label,
184
+ role
185
+ }));
186
+ }
203
187
 
204
- this._path.push(event);
188
+ arc(x, y, radius, startAngle, endAngle, anticlockwise = false) {
189
+ if (arguments.length < 5) throw new TypeError('Failed to execute \'arc\' on \'' + this.constructor.name + '\': 5 arguments required, but only ' + arguments.length + ' present.');
190
+ const xResult = Number(x);
191
+ const yResult = Number(y);
192
+ const radiusResult = Number(radius);
193
+ const startAngleResult = Number(startAngle);
194
+ const endAngleResult = Number(endAngle);
195
+ const anticlockwiseResult = Boolean(anticlockwise); // quick is finite check
196
+
197
+ if (!Number.isFinite(xResult + yResult + radiusResult + startAngleResult + endAngleResult)) return;
198
+ if (Number(radius) < 0) throw new DOMException('IndexSizeError', 'Failed to execute \'arc\' on \'' + this.constructor.name + '\': The radius provided (' + radius + ') is negative.');
199
+ const event = (0, _createCanvasEvent.default)('arc', getTransformSlice(this), {
200
+ x: xResult,
201
+ y: yResult,
202
+ radius: radiusResult,
203
+ startAngle: startAngleResult,
204
+ endAngle: endAngleResult,
205
+ anticlockwise: anticlockwiseResult
206
+ });
205
207
 
206
- this._events.push(event);
207
- }
208
- }, {
209
- key: "arcTo",
210
- value: function arcTo(cpx1, cpy1, cpx2, cpy2, radius) {
211
- if (arguments.length < 5) throw new DOMException('IndexSizeError', 'Failed to execute \'arcTo\' on \'' + this.constructor.name + '\': 5 arguments required, but only ' + arguments.length + ' present.');
212
- var cpx1Result = Number(cpx1);
213
- var cpy1Result = Number(cpy1);
214
- var cpx2Result = Number(cpx2);
215
- var cpy2Result = Number(cpy2);
216
- var radiusResult = Number(radius);
217
- if (!Number.isFinite(cpx1Result + cpx2Result + cpy1Result + cpy2Result + radiusResult)) return;
218
- if (radiusResult < 0) throw new TypeError('Failed to execute \'arcTo\' on \'' + this.constructor.name + '\': The radius provided (' + radius + ') is negative.');
219
- var event = (0, _createCanvasEvent["default"])('arcTo', getTransformSlice(this), {
220
- cpx1: cpx1Result,
221
- cpy1: cpy1Result,
222
- cpx2: cpx2Result,
223
- cpy2: cpy2Result,
224
- radius: radiusResult
225
- });
208
+ this._path.push(event);
226
209
 
227
- this._path.push(event);
210
+ this._events.push(event);
211
+ }
228
212
 
229
- this._events.push(event);
230
- }
231
- }, {
232
- key: "beginPath",
233
- value: function beginPath() {
234
- var event = (0, _createCanvasEvent["default"])('beginPath', getTransformSlice(this), {});
235
- this._path = [event];
213
+ arcTo(cpx1, cpy1, cpx2, cpy2, radius) {
214
+ if (arguments.length < 5) throw new DOMException('IndexSizeError', 'Failed to execute \'arcTo\' on \'' + this.constructor.name + '\': 5 arguments required, but only ' + arguments.length + ' present.');
215
+ const cpx1Result = Number(cpx1);
216
+ const cpy1Result = Number(cpy1);
217
+ const cpx2Result = Number(cpx2);
218
+ const cpy2Result = Number(cpy2);
219
+ const radiusResult = Number(radius);
220
+ if (!Number.isFinite(cpx1Result + cpx2Result + cpy1Result + cpy2Result + radiusResult)) return;
221
+ if (radiusResult < 0) throw new TypeError('Failed to execute \'arcTo\' on \'' + this.constructor.name + '\': The radius provided (' + radius + ') is negative.');
222
+ const event = (0, _createCanvasEvent.default)('arcTo', getTransformSlice(this), {
223
+ cpx1: cpx1Result,
224
+ cpy1: cpy1Result,
225
+ cpx2: cpx2Result,
226
+ cpy2: cpy2Result,
227
+ radius: radiusResult
228
+ });
236
229
 
237
- this._events.push(event);
238
- }
239
- }, {
240
- key: "bezierCurveTo",
241
- value: function bezierCurveTo(cpx1, cpy1, cpx2, cpy2, x, y) {
242
- if (arguments.length < 6) throw new TypeError('Failed to execute \'bezierCurveTo\' on \'' + this.constructor.name + '\': 6 arguments required, but only ' + arguments.length + ' present.');
243
- var cpx1Result = Number(cpx1);
244
- var cpy1Result = Number(cpy1);
245
- var cpx2Result = Number(cpx2);
246
- var cpy2Result = Number(cpy2);
247
- var xResult = Number(x);
248
- var yResult = Number(y);
249
- if (!Number.isFinite(cpx1Result + cpy1Result + cpx2Result + cpy2Result + xResult + yResult)) return;
250
- var event = (0, _createCanvasEvent["default"])('bezierCurveTo', getTransformSlice(this), {
251
- cpx1: cpx1,
252
- cpy1: cpy1,
253
- cpx2: cpx2,
254
- cpy2: cpy2,
255
- x: x,
256
- y: y
257
- });
230
+ this._path.push(event);
258
231
 
259
- this._path.push(event);
232
+ this._events.push(event);
233
+ }
260
234
 
261
- this._events.push(event);
262
- }
263
- }, {
264
- key: "clearHitRegions",
265
- value: function clearHitRegions() {
266
- var event = (0, _createCanvasEvent["default"])('clearHitRegions', getTransformSlice(this), {});
235
+ beginPath() {
236
+ this.__clearPath(); // push the generated beginPath to the event list
267
237
 
268
- this._events.push(event);
269
- }
270
- }, {
271
- key: "clearRect",
272
- value: function clearRect(x, y, width, height) {
273
- if (arguments.length < 4) throw new TypeError('Failed to execute \'clearRect\' on \'' + this.constructor.name + '\': 4 arguments required, but only ' + arguments.length + ' present.');
274
- var xResult = Number(x);
275
- var yResult = Number(y);
276
- var widthResult = Number(width);
277
- var heightResult = Number(height);
278
- if (!Number.isFinite(x + y + width + height)) return;
279
- var event = (0, _createCanvasEvent["default"])('clearRect', getTransformSlice(this), {
280
- x: xResult,
281
- y: yResult,
282
- width: widthResult,
283
- height: heightResult
284
- });
285
238
 
286
- this._events.push(event);
239
+ this._events.push(this._path[0]);
240
+ }
287
241
 
288
- this._drawCalls.push(event);
289
- }
290
- }, {
291
- key: "clip",
292
- value: function clip(path, fillRule) {
293
- if (arguments.length === 0) {
294
- fillRule = 'nonzero';
295
- path = this._path.slice();
296
- } else {
297
- if (arguments.length === 1) fillRule = 'nonzero';
298
-
299
- if (path instanceof Path2D) {
300
- fillRule = String(fillRule);
301
- 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.');
302
- path = path._path.slice();
303
- } else {
304
- fillRule = String(path);
305
- 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.');
306
- path = this._path.slice();
307
- }
308
- }
242
+ bezierCurveTo(cpx1, cpy1, cpx2, cpy2, x, y) {
243
+ if (arguments.length < 6) throw new TypeError('Failed to execute \'bezierCurveTo\' on \'' + this.constructor.name + '\': 6 arguments required, but only ' + arguments.length + ' present.');
244
+ const cpx1Result = Number(cpx1);
245
+ const cpy1Result = Number(cpy1);
246
+ const cpx2Result = Number(cpx2);
247
+ const cpy2Result = Number(cpy2);
248
+ const xResult = Number(x);
249
+ const yResult = Number(y);
250
+ if (!Number.isFinite(cpx1Result + cpy1Result + cpx2Result + cpy2Result + xResult + yResult)) return;
251
+ const event = (0, _createCanvasEvent.default)('bezierCurveTo', getTransformSlice(this), {
252
+ cpx1,
253
+ cpy1,
254
+ cpx2,
255
+ cpy2,
256
+ x,
257
+ y
258
+ });
309
259
 
310
- var event = (0, _createCanvasEvent["default"])('clip', getTransformSlice(this), {
311
- path: path,
312
- fillRule: fillRule
313
- });
260
+ this._path.push(event);
314
261
 
315
- this._path.push(event);
262
+ this._events.push(event);
263
+ }
316
264
 
317
- this._events.push(event);
318
- }
319
- }, {
320
- key: "closePath",
321
- value: function closePath() {
322
- var event = (0, _createCanvasEvent["default"])('closePath', getTransformSlice(this), {});
265
+ get canvas() {
266
+ return this._canvas;
267
+ }
323
268
 
324
- this._events.push(event);
269
+ clearHitRegions() {
270
+ const event = (0, _createCanvasEvent.default)('clearHitRegions', getTransformSlice(this), {});
325
271
 
326
- this._path.push(event);
327
- }
328
- }, {
329
- key: "createImageData",
330
- value: function createImageData(width, height) {
331
- 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) {
332
- if (!(width instanceof ImageData)) throw new TypeError('Failed to execute \'createImageData\' on \'' + this.constructor.name + '\': parameter 1 is not of type \'ImageData\'.');
333
- var result = new ImageData(width.width, width.height);
334
- result.data.set(width.data);
335
- var event = (0, _createCanvasEvent["default"])('createImageData', getTransformSlice(this), {
336
- width: width.width,
337
- height: width.height
338
- });
272
+ this._events.push(event);
273
+ }
339
274
 
340
- this._events.push(event);
275
+ clearRect(x, y, width, height) {
276
+ if (arguments.length < 4) throw new TypeError('Failed to execute \'clearRect\' on \'' + this.constructor.name + '\': 4 arguments required, but only ' + arguments.length + ' present.');
277
+ const xResult = Number(x);
278
+ const yResult = Number(y);
279
+ const widthResult = Number(width);
280
+ const heightResult = Number(height);
281
+ if (!Number.isFinite(x + y + width + height)) return;
282
+ const event = (0, _createCanvasEvent.default)('clearRect', getTransformSlice(this), {
283
+ x: xResult,
284
+ y: yResult,
285
+ width: widthResult,
286
+ height: heightResult
287
+ });
341
288
 
342
- return result;
343
- } else {
344
- width = Math.abs(Number(width));
345
- height = Math.abs(Number(height));
346
- if (!Number.isFinite(width) || width === 0) throw new TypeError('Failed to execute \'createImageData\' on \'' + this.constructor.name + '\': The source width is 0.');
347
- if (!Number.isFinite(height) || height === 0) throw new TypeError('Failed to execute \'createImageData\' on \'' + this.constructor.name + '\': The source height is 0.');
348
-
349
- var _event = (0, _createCanvasEvent["default"])('createImageData', getTransformSlice(this), {
350
- width: width,
351
- height: height
352
- });
289
+ this._events.push(event);
290
+
291
+ this._drawCalls.push(event);
292
+ }
353
293
 
354
- this._events.push(_event);
294
+ clip(path, fillRule) {
295
+ if (arguments.length === 0) {
296
+ fillRule = 'nonzero';
297
+ path = this._path.slice();
298
+ } else {
299
+ if (arguments.length === 1) fillRule = 'nonzero';
355
300
 
356
- return new ImageData(width, height);
301
+ if (path instanceof Path2D) {
302
+ fillRule = String(fillRule);
303
+ 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.');
304
+ path = path._path.slice();
305
+ } else {
306
+ fillRule = String(path);
307
+ 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.');
308
+ path = this._path.slice();
357
309
  }
358
310
  }
359
- }, {
360
- key: "createLinearGradient",
361
- value: function createLinearGradient(x0, y0, x1, y1) {
362
- if (arguments.length < 4) throw new TypeError('Failed to execute \'createLinearGradient\' on \'' + this.constructor.name + '\': 4 arguments required, but only ' + arguments.length + ' present.');
363
- var x0Result = Number(x0);
364
- var y0Result = Number(y0);
365
- var x1Result = Number(x1);
366
- var y1Result = Number(y1);
367
- 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.');
368
- var event = (0, _createCanvasEvent["default"])('createLinearGradient', getTransformSlice(this), {
369
- x0: x0Result,
370
- y0: y0Result,
371
- x1: x1Result,
372
- y1: y1Result
311
+
312
+ const event = (0, _createCanvasEvent.default)('clip', getTransformSlice(this), {
313
+ path,
314
+ fillRule
315
+ });
316
+
317
+ this._path.push(event);
318
+
319
+ this._events.push(event);
320
+ }
321
+
322
+ closePath() {
323
+ const event = (0, _createCanvasEvent.default)('closePath', getTransformSlice(this), {});
324
+
325
+ this._events.push(event);
326
+
327
+ this._path.push(event);
328
+ }
329
+
330
+ createImageData(width, height) {
331
+ 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) {
332
+ if (!(width instanceof ImageData)) throw new TypeError('Failed to execute \'createImageData\' on \'' + this.constructor.name + '\': parameter 1 is not of type \'ImageData\'.');
333
+ let result = new ImageData(width.width, width.height);
334
+ result.data.set(width.data);
335
+ const event = (0, _createCanvasEvent.default)('createImageData', getTransformSlice(this), {
336
+ width: width.width,
337
+ height: width.height
338
+ });
339
+
340
+ this._events.push(event);
341
+
342
+ return result;
343
+ } else {
344
+ width = Math.abs(Number(width));
345
+ height = Math.abs(Number(height));
346
+ if (!Number.isFinite(width) || width === 0) throw new TypeError('Failed to execute \'createImageData\' on \'' + this.constructor.name + '\': The source width is 0.');
347
+ if (!Number.isFinite(height) || height === 0) throw new TypeError('Failed to execute \'createImageData\' on \'' + this.constructor.name + '\': The source height is 0.');
348
+ const event = (0, _createCanvasEvent.default)('createImageData', getTransformSlice(this), {
349
+ width,
350
+ height
373
351
  });
374
352
 
375
353
  this._events.push(event);
376
354
 
377
- return new CanvasGradient();
355
+ return new ImageData(width, height);
378
356
  }
379
- }, {
380
- key: "createPattern",
381
- value: function createPattern(image, type) {
382
- if (arguments.length === 1) throw new TypeError('Failed to execute \'createPattern\' on \'' + this.constructor.name + '\': 2 arguments required, but only 1 present.');
383
- if (type === null) type = 'repeat';
384
- if (type === '') type = 'repeat';
385
-
386
- if (type === 'repeat' || type === 'repeat-x' || type === 'repeat-y' || type === 'no-repeat') {
387
- var event = (0, _createCanvasEvent["default"])('createPattern', getTransformSlice(this), {
388
- image: image,
389
- type: type
390
- });
357
+ }
391
358
 
392
- if (image instanceof ImageBitmap) {
393
- if (image._closed) throw new DOMException('InvalidStateError', 'Failed to execute \'createPattern\' on \'CanvasRenderingContext2D\': The image source is detached.');
359
+ createLinearGradient(x0, y0, x1, y1) {
360
+ if (arguments.length < 4) throw new TypeError('Failed to execute \'createLinearGradient\' on \'' + this.constructor.name + '\': 4 arguments required, but only ' + arguments.length + ' present.');
361
+ const x0Result = Number(x0);
362
+ const y0Result = Number(y0);
363
+ const x1Result = Number(x1);
364
+ const y1Result = Number(y1);
365
+ 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.');
366
+ const event = (0, _createCanvasEvent.default)('createLinearGradient', getTransformSlice(this), {
367
+ x0: x0Result,
368
+ y0: y0Result,
369
+ x1: x1Result,
370
+ y1: y1Result
371
+ });
394
372
 
395
- this._events.push(event);
373
+ this._events.push(event);
396
374
 
397
- return new _CanvasPattern["default"]();
398
- }
375
+ return new CanvasGradient();
376
+ }
399
377
 
400
- if (image instanceof HTMLImageElement) {
401
- this._events.push(event);
378
+ createPattern(image, type) {
379
+ if (arguments.length === 1) throw new TypeError('Failed to execute \'createPattern\' on \'' + this.constructor.name + '\': 2 arguments required, but only 1 present.');
380
+ if (type === null) type = 'repeat';
381
+ if (type === '') type = 'repeat';
402
382
 
403
- return new _CanvasPattern["default"]();
404
- }
383
+ if (type === 'repeat' || type === 'repeat-x' || type === 'repeat-y' || type === 'no-repeat') {
384
+ const event = (0, _createCanvasEvent.default)('createPattern', getTransformSlice(this), {
385
+ image,
386
+ type
387
+ });
405
388
 
406
- if (image instanceof HTMLVideoElement) {
407
- this._events.push(event);
389
+ if (image instanceof ImageBitmap) {
390
+ if (image._closed) throw new DOMException('InvalidStateError', 'Failed to execute \'createPattern\' on \'CanvasRenderingContext2D\': The image source is detached.');
408
391
 
409
- return new _CanvasPattern["default"]();
410
- }
392
+ this._events.push(event);
411
393
 
412
- if (image instanceof HTMLCanvasElement) {
413
- this._events.push(event);
394
+ return new _CanvasPattern.default();
395
+ }
414
396
 
415
- return new _CanvasPattern["default"]();
416
- }
417
- } else {
418
- 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\'.');
397
+ if (image instanceof HTMLImageElement) {
398
+ this._events.push(event);
399
+
400
+ return new _CanvasPattern.default();
419
401
  }
420
402
 
421
- 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)\'');
422
- }
423
- }, {
424
- key: "createRadialGradient",
425
- value: function createRadialGradient(x0, y0, r0, x1, y1, r1) {
426
- if (arguments.length < 6) throw new TypeError('Failed to execute \'createRadialGradient\' on \'' + this.constructor.name + '\': 6 arguments required, but only ' + arguments.length + ' present.');
427
- var x0Result = Number(x0);
428
- var y0Result = Number(y0);
429
- var r0Result = Number(r0);
430
- var x1Result = Number(x1);
431
- var y1Result = Number(y1);
432
- var r1Result = Number(r1);
433
- 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.');
434
- if (r0Result < 0) throw new DOMException('IndexSizeError', 'Failed to execute \'createRadialGradient\' on \'' + this.constructor.name + '\': The r0 provided is less than 0.');
435
- if (r1Result < 0) throw new DOMException('IndexSizeError', 'Failed to execute \'createRadialGradient\' on \'' + this.constructor.name + '\': The r1 provided is less than 0.');
436
- var event = (0, _createCanvasEvent["default"])('createRadialGradient', getTransformSlice(this), {
437
- x0: x0Result,
438
- y0: y0Result,
439
- r0: r0Result,
440
- x1: x1Result,
441
- y1: y1Result,
442
- r1: r1Result
443
- });
403
+ if (image instanceof HTMLVideoElement) {
404
+ this._events.push(event);
444
405
 
445
- this._events.push(event);
406
+ return new _CanvasPattern.default();
407
+ }
446
408
 
447
- return new CanvasGradient();
448
- }
449
- }, {
450
- key: "drawFocusIfNeeded",
451
- value: function drawFocusIfNeeded(path, element) {
452
- if (arguments.length === 0) throw new TypeError('Failed to execute \'drawFocusIfNeeded\' on \'' + this.constructor.name + '\': 1 argument required, but only 0 present.');
453
- 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\'.');
454
-
455
- if (arguments.length === 1) {
456
- element = path;
457
- path = null;
409
+ if (image instanceof HTMLCanvasElement) {
410
+ this._events.push(event);
411
+
412
+ return new _CanvasPattern.default();
458
413
  }
414
+ } else {
415
+ 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\'.');
416
+ }
417
+
418
+ 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)\'');
419
+ }
420
+
421
+ createRadialGradient(x0, y0, r0, x1, y1, r1) {
422
+ if (arguments.length < 6) throw new TypeError('Failed to execute \'createRadialGradient\' on \'' + this.constructor.name + '\': 6 arguments required, but only ' + arguments.length + ' present.');
423
+ const x0Result = Number(x0);
424
+ const y0Result = Number(y0);
425
+ const r0Result = Number(r0);
426
+ const x1Result = Number(x1);
427
+ const y1Result = Number(y1);
428
+ const r1Result = Number(r1);
429
+ 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.');
430
+ if (r0Result < 0) throw new DOMException('IndexSizeError', 'Failed to execute \'createRadialGradient\' on \'' + this.constructor.name + '\': The r0 provided is less than 0.');
431
+ if (r1Result < 0) throw new DOMException('IndexSizeError', 'Failed to execute \'createRadialGradient\' on \'' + this.constructor.name + '\': The r1 provided is less than 0.');
432
+ const event = (0, _createCanvasEvent.default)('createRadialGradient', getTransformSlice(this), {
433
+ x0: x0Result,
434
+ y0: y0Result,
435
+ r0: r0Result,
436
+ x1: x1Result,
437
+ y1: y1Result,
438
+ r1: r1Result
439
+ });
440
+
441
+ this._events.push(event);
459
442
 
460
- if (!(element instanceof Element)) throw new TypeError('Failed to execute \'drawFocusIfNeeded\' on \'' + this.constructor.name + '\': parameter ' + arguments.length + ' is not of type \'Element\'.');
461
- var event = (0, _createCanvasEvent["default"])('drawFocusIfNeeded', getTransformSlice(this), {
462
- path: path ? path._path : null,
463
- element: element
443
+ return new CanvasGradient();
444
+ }
445
+
446
+ set currentTransform(value) {
447
+ if (value instanceof _DOMMatrix.default) {
448
+ this._transformStack[this._stackIndex][0] = value.a;
449
+ this._transformStack[this._stackIndex][1] = value.b;
450
+ this._transformStack[this._stackIndex][2] = value.c;
451
+ this._transformStack[this._stackIndex][3] = value.d;
452
+ this._transformStack[this._stackIndex][4] = value.e;
453
+ this._transformStack[this._stackIndex][5] = value.f;
454
+ const event = (0, _createCanvasEvent.default)('currentTransform', getTransformSlice(this), {
455
+ a: value.a,
456
+ b: value.b,
457
+ c: value.c,
458
+ d: value.d,
459
+ e: value.e,
460
+ f: value.f
464
461
  });
465
462
 
466
463
  this._events.push(event);
467
464
  }
468
- }, {
469
- key: "drawImage",
470
- value: function drawImage(img, sx, sy, sWidth, sHeight, dx, dy, dWidth, dHeight) {
471
- if (arguments.length < 3) throw new TypeError('Failed to execute \'drawImage\' on \'' + this.constructor.name + '\': 3 arguments required, but only ' + arguments.length + ' present.');
472
- 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.');
473
- var valid = false;
474
- if (img instanceof HTMLImageElement) valid = true;
475
- ;
476
-
477
- if (img instanceof ImageBitmap) {
478
- if (img._closed) throw new DOMException('InvalidStateError', 'DOMException: Failed to execute \'drawImage\' on \'CanvasRenderingContext2D\': The image source is detached.');
479
- valid = true;
480
- }
465
+ }
481
466
 
482
- if (img instanceof HTMLVideoElement) valid = true;
483
- if (img instanceof HTMLCanvasElement) valid = true;
484
- 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)\'');
485
- var sxResult = Number(sx);
486
- var syResult = Number(sy);
487
- var sWidthResult = Number(sWidth);
488
- var sHeightResult = Number(sHeight);
489
- var dxResult = Number(dx);
490
- var dyResult = Number(dy);
491
- var dWidthResult = Number(dWidth);
492
- var dHeightResult = Number(dHeight);
493
-
494
- if (arguments.length === 3) {
495
- if (!Number.isFinite(sxResult + syResult)) return;
496
- sx = 0;
497
- sy = 0;
498
- sWidth = img.width;
499
- sHeight = img.height;
500
- dx = sxResult;
501
- dy = syResult;
502
- dWidth = img.width;
503
- dHeight = img.height;
504
- } else if (arguments.length === 5) {
505
- if (!Number.isFinite(sxResult + syResult + sWidthResult + sHeightResult)) return;
506
- sx = 0;
507
- sy = 0;
508
- sWidth = img.width;
509
- sHeight = img.height;
510
- dx = sxResult;
511
- dy = syResult;
512
- dWidth = sWidth;
513
- dHeight = sHeight;
514
- } else {
515
- if (!Number.isFinite(sx + sy + sWidth + sHeight + dx + dy + dWidth + dHeight)) return;
516
- sx = sxResult;
517
- sy = syResult;
518
- sWidth = sWidthResult;
519
- sHeight = sHeightResult;
520
- dx = dxResult;
521
- dy = dyResult;
522
- dWidth = dWidthResult;
523
- dHeight = dHeightResult;
524
- }
467
+ get currentTransform() {
468
+ return new _DOMMatrix.default(this._transformStack[this._stackIndex]);
469
+ }
525
470
 
526
- var event = (0, _createCanvasEvent["default"])('drawImage', getTransformSlice(this), {
527
- img: img,
528
- sx: sx,
529
- sy: sy,
530
- sWidth: sWidth,
531
- sHeight: sHeight,
532
- dx: dx,
533
- dy: dy,
534
- dWidth: dWidth,
535
- dHeight: dHeight
471
+ set direction(value) {
472
+ if (value === 'rtl' || value === 'ltr' || value === 'inherit') {
473
+ this._directionStack[this._stackIndex] = value;
474
+ const event = (0, _createCanvasEvent.default)('direction', getTransformSlice(this), {
475
+ value
536
476
  });
537
477
 
538
478
  this._events.push(event);
539
-
540
- this._drawCalls.push(event);
541
479
  }
542
- }, {
543
- key: "ellipse",
544
- value: function ellipse(x, y, radiusX, radiusY, rotation, startAngle, endAngle) {
545
- var anticlockwise = arguments.length > 7 && arguments[7] !== undefined ? arguments[7] : false;
546
- if (arguments.length < 7) throw new TypeError('Failed to execute \'ellipse\' on \'' + this.constructor.name + '\': 6 arguments required, but only ' + arguments.length + ' present.');
547
- var xResult = Number(x);
548
- var yResult = Number(y);
549
- var radiusXResult = Number(radiusX);
550
- var radiusYResult = Number(radiusY);
551
- var rotationResult = Number(rotation);
552
- var startAngleResult = Number(startAngle);
553
- var endAngleResult = Number(endAngle);
554
- var anticlockwiseResult = Boolean(anticlockwise);
555
- if (!Number.isFinite(xResult + yResult + radiusXResult + radiusYResult + rotationResult + startAngleResult + endAngleResult)) return;
556
- if (Number(radiusX) < 0) throw new DOMException('IndexSizeError', 'Failed to execute \'ellipse\' on \'' + this.constructor.name + '\': The major-axis radius provided (' + radiusX + ') is negative.');
557
- if (Number(radiusY) < 0) throw new DOMException('IndexSizeError', 'Failed to execute \'ellipse\' on \'' + this.constructor.name + '\': The minor-axis radius provided (' + radiusY + ') is negative.');
558
- var event = (0, _createCanvasEvent["default"])('ellipse', getTransformSlice(this), {
559
- x: xResult,
560
- y: yResult,
561
- radiusX: radiusXResult,
562
- radiusY: radiusYResult,
563
- rotation: rotationResult,
564
- startAngle: startAngleResult,
565
- endAngle: endAngleResult,
566
- anticlockwise: anticlockwiseResult
567
- });
480
+ }
568
481
 
569
- this._path.push(event);
482
+ get direction() {
483
+ return this._directionStack[this._stackIndex];
484
+ }
570
485
 
571
- this._events.push(event);
486
+ drawFocusIfNeeded(path, element) {
487
+ if (arguments.length === 0) throw new TypeError('Failed to execute \'drawFocusIfNeeded\' on \'' + this.constructor.name + '\': 1 argument required, but only 0 present.');
488
+ 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\'.');
489
+
490
+ if (arguments.length === 1) {
491
+ element = path;
492
+ path = null;
572
493
  }
573
- }, {
574
- key: "fill",
575
- value: function fill(path, fillRule) {
576
- if (arguments.length === 0) {
577
- fillRule = 'nonzero';
578
- path = this._path.slice();
494
+
495
+ if (!(element instanceof Element)) throw new TypeError('Failed to execute \'drawFocusIfNeeded\' on \'' + this.constructor.name + '\': parameter ' + arguments.length + ' is not of type \'Element\'.');
496
+ const event = (0, _createCanvasEvent.default)('drawFocusIfNeeded', getTransformSlice(this), {
497
+ path: path ? path._path : null,
498
+ element
499
+ });
500
+
501
+ this._events.push(event);
502
+ }
503
+
504
+ drawImage(img, sx, sy, sWidth, sHeight, dx, dy, dWidth, dHeight) {
505
+ if (arguments.length < 3) throw new TypeError('Failed to execute \'drawImage\' on \'' + this.constructor.name + '\': 3 arguments required, but only ' + arguments.length + ' present.');
506
+ 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.');
507
+ let valid = false;
508
+ if (img instanceof HTMLImageElement) valid = true;
509
+ ;
510
+
511
+ if (img instanceof ImageBitmap) {
512
+ if (img._closed) throw new DOMException('InvalidStateError', 'DOMException: Failed to execute \'drawImage\' on \'CanvasRenderingContext2D\': The image source is detached.');
513
+ valid = true;
514
+ }
515
+
516
+ if (img instanceof HTMLVideoElement) valid = true;
517
+ if (img instanceof HTMLCanvasElement) valid = true;
518
+ 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)\'');
519
+ const sxResult = Number(sx);
520
+ const syResult = Number(sy);
521
+ const sWidthResult = Number(sWidth);
522
+ const sHeightResult = Number(sHeight);
523
+ const dxResult = Number(dx);
524
+ const dyResult = Number(dy);
525
+ const dWidthResult = Number(dWidth);
526
+ const dHeightResult = Number(dHeight);
527
+
528
+ if (arguments.length === 3) {
529
+ if (!Number.isFinite(sxResult + syResult)) return;
530
+ sx = 0;
531
+ sy = 0;
532
+ sWidth = img.width;
533
+ sHeight = img.height;
534
+ dx = sxResult;
535
+ dy = syResult;
536
+ dWidth = img.width;
537
+ dHeight = img.height;
538
+ } else if (arguments.length === 5) {
539
+ if (!Number.isFinite(sxResult + syResult + sWidthResult + sHeightResult)) return;
540
+ sx = 0;
541
+ sy = 0;
542
+ sWidth = img.width;
543
+ sHeight = img.height;
544
+ dx = sxResult;
545
+ dy = syResult;
546
+ dWidth = sWidth;
547
+ dHeight = sHeight;
548
+ } else {
549
+ if (!Number.isFinite(sx + sy + sWidth + sHeight + dx + dy + dWidth + dHeight)) return;
550
+ sx = sxResult;
551
+ sy = syResult;
552
+ sWidth = sWidthResult;
553
+ sHeight = sHeightResult;
554
+ dx = dxResult;
555
+ dy = dyResult;
556
+ dWidth = dWidthResult;
557
+ dHeight = dHeightResult;
558
+ }
559
+
560
+ const event = (0, _createCanvasEvent.default)('drawImage', getTransformSlice(this), {
561
+ img,
562
+ sx,
563
+ sy,
564
+ sWidth,
565
+ sHeight,
566
+ dx,
567
+ dy,
568
+ dWidth,
569
+ dHeight
570
+ });
571
+
572
+ this._events.push(event);
573
+
574
+ this._drawCalls.push(event);
575
+ }
576
+
577
+ ellipse(x, y, radiusX, radiusY, rotation, startAngle, endAngle, anticlockwise = false) {
578
+ if (arguments.length < 7) throw new TypeError('Failed to execute \'ellipse\' on \'' + this.constructor.name + '\': 6 arguments required, but only ' + arguments.length + ' present.');
579
+ const xResult = Number(x);
580
+ const yResult = Number(y);
581
+ const radiusXResult = Number(radiusX);
582
+ const radiusYResult = Number(radiusY);
583
+ const rotationResult = Number(rotation);
584
+ const startAngleResult = Number(startAngle);
585
+ const endAngleResult = Number(endAngle);
586
+ const anticlockwiseResult = Boolean(anticlockwise);
587
+ if (!Number.isFinite(xResult + yResult + radiusXResult + radiusYResult + rotationResult + startAngleResult + endAngleResult)) return;
588
+ if (Number(radiusX) < 0) throw new DOMException('IndexSizeError', 'Failed to execute \'ellipse\' on \'' + this.constructor.name + '\': The major-axis radius provided (' + radiusX + ') is negative.');
589
+ if (Number(radiusY) < 0) throw new DOMException('IndexSizeError', 'Failed to execute \'ellipse\' on \'' + this.constructor.name + '\': The minor-axis radius provided (' + radiusY + ') is negative.');
590
+ const event = (0, _createCanvasEvent.default)('ellipse', getTransformSlice(this), {
591
+ x: xResult,
592
+ y: yResult,
593
+ radiusX: radiusXResult,
594
+ radiusY: radiusYResult,
595
+ rotation: rotationResult,
596
+ startAngle: startAngleResult,
597
+ endAngle: endAngleResult,
598
+ anticlockwise: anticlockwiseResult
599
+ });
600
+
601
+ this._path.push(event);
602
+
603
+ this._events.push(event);
604
+ }
605
+
606
+ fill(path, fillRule) {
607
+ if (arguments.length === 0) {
608
+ fillRule = 'nonzero';
609
+ path = this._path.slice();
610
+ } else {
611
+ if (arguments.length === 1) fillRule = 'nonzero';
612
+
613
+ if (path instanceof Path2D) {
614
+ fillRule = String(fillRule);
615
+ 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.');
616
+ path = path._path.slice();
579
617
  } else {
580
- if (arguments.length === 1) fillRule = 'nonzero';
581
-
582
- if (path instanceof Path2D) {
583
- fillRule = String(fillRule);
584
- 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.');
585
- path = path._path.slice();
586
- } else {
587
- fillRule = String(path);
588
- 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.');
589
- path = this._path.slice();
590
- }
618
+ fillRule = String(path);
619
+ 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.');
620
+ path = this._path.slice();
591
621
  }
622
+ }
592
623
 
593
- var event = (0, _createCanvasEvent["default"])('fill', getTransformSlice(this), {
594
- path: path,
595
- fillRule: fillRule
596
- });
624
+ const event = (0, _createCanvasEvent.default)('fill', getTransformSlice(this), {
625
+ path,
626
+ fillRule
627
+ });
597
628
 
598
- this._events.push(event);
629
+ this._events.push(event);
599
630
 
600
- this._drawCalls.push(event);
601
- }
602
- }, {
603
- key: "fillRect",
604
- value: function fillRect(x, y, width, height) {
605
- if (arguments.length < 4) throw new TypeError('Failed to execute \'fillRect\' on \'' + this.constructor.name + '\': 4 arguments required, but only ' + arguments.length + ' present.');
606
- var xResult = Number(x);
607
- var yResult = Number(y);
608
- var widthResult = Number(width);
609
- var heightResult = Number(height);
610
- if (!Number.isFinite(x + y + width + height)) return;
611
- var event = (0, _createCanvasEvent["default"])('fillRect', getTransformSlice(this), {
612
- x: xResult,
613
- y: yResult,
614
- width: widthResult,
615
- height: heightResult
616
- });
631
+ this._drawCalls.push(event);
632
+ }
617
633
 
618
- this._events.push(event);
634
+ fillRect(x, y, width, height) {
635
+ if (arguments.length < 4) throw new TypeError('Failed to execute \'fillRect\' on \'' + this.constructor.name + '\': 4 arguments required, but only ' + arguments.length + ' present.');
636
+ const xResult = Number(x);
637
+ const yResult = Number(y);
638
+ const widthResult = Number(width);
639
+ const heightResult = Number(height);
640
+ if (!Number.isFinite(x + y + width + height)) return;
641
+ const event = (0, _createCanvasEvent.default)('fillRect', getTransformSlice(this), {
642
+ x: xResult,
643
+ y: yResult,
644
+ width: widthResult,
645
+ height: heightResult
646
+ });
619
647
 
620
- this._drawCalls.push(event);
621
- }
622
- }, {
623
- key: "fillText",
624
- value: function fillText(text, x, y, maxWidth) {
625
- if (arguments.length < 3) throw new TypeError('Failed to execute \'fillText\' on \'' + this.constructor.name + '\': 3 arguments required, but only ' + arguments.length + ' present.');
626
- var textResult = String(text);
627
- var xResult = Number(x);
628
- var yResult = Number(y);
629
- var maxWidthResult = Number(maxWidth);
630
- if (arguments.length === 3 && !Number.isFinite(xResult + yResult)) return;
631
- if (arguments.length > 3 && !Number.isFinite(xResult + yResult + maxWidthResult)) return;
632
- var event = (0, _createCanvasEvent["default"])('fillText', getTransformSlice(this), {
633
- text: textResult,
634
- x: xResult,
635
- y: yResult,
636
- maxWidth: arguments.length === 3 ? null : maxWidthResult
637
- });
648
+ this._events.push(event);
638
649
 
639
- this._events.push(event);
650
+ this._drawCalls.push(event);
651
+ }
640
652
 
641
- this._drawCalls.push(event);
642
- }
643
- }, {
644
- key: "getImageData",
645
- value: function getImageData() {
646
- return new ImageData(this._canvas.width, this._canvas.height);
647
- }
648
- }, {
649
- key: "getLineDash",
650
- value: function getLineDash() {
651
- return this._lineDashStack[this._stackIndex];
652
- }
653
- }, {
654
- key: "getTransform",
655
- value: function getTransform() {
656
- return new _DOMMatrix["default"](this._transformStack[this._stackIndex]);
657
- }
658
- }, {
659
- key: "isPointInPath",
660
- value: function isPointInPath(path, x, y) {
661
- var fillRule = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'nonzero';
662
- if (arguments.length < 2) throw new TypeError('Failed to execute \'isPointInPath\' on \'' + this.constructor.name + '\': 2 arguments required, but only ' + arguments.length + ' present.');
663
-
664
- if (!(path instanceof Path2D)) {
665
- if (arguments.length > 2) {
666
- fillRule = y;
667
- }
668
-
669
- y = x;
670
- x = path;
653
+ set fillStyle(value) {
654
+ let valid = false;
655
+
656
+ if (typeof value === 'string') {
657
+ const result = parseCSSColor(value);
658
+
659
+ if (result) {
660
+ valid = true;
661
+ value = this._fillStyleStack[this._stackIndex] = result;
671
662
  }
663
+ } else if (value instanceof CanvasGradient || value instanceof _CanvasPattern.default) {
664
+ valid = true;
665
+ this._fillStyleStack[this._stackIndex] = value;
666
+ }
672
667
 
673
- 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.');
674
- var event = (0, _createCanvasEvent["default"])('isPointInPath', getTransformSlice(this), {
675
- x: Number(x),
676
- y: Number(y),
677
- fillRule: fillRule,
678
- path: path instanceof Path2D ? path._path.slice() : this._path.slice()
668
+ if (valid) {
669
+ const event = (0, _createCanvasEvent.default)('fillStyle', getTransformSlice(this), {
670
+ value
679
671
  });
680
672
 
681
673
  this._events.push(event);
682
-
683
- return false; // return false in a mocking environment, unless I can verify a point is actually within the path
684
674
  }
685
- }, {
686
- key: "isPointInStroke",
687
- value: function isPointInStroke(path, x, y) {
688
- if (arguments.length < 2) throw new TypeError('Failed to execute \'isPointInStroke\' on \'' + this.constructor.name + '\': 2 arguments required, but only ' + arguments.length + ' present.');
689
-
690
- if (!(path instanceof Path2D)) {
691
- y = x;
692
- x = path;
693
- }
675
+ }
676
+
677
+ get fillStyle() {
678
+ return this._fillStyleStack[this._stackIndex];
679
+ }
680
+
681
+ fillText(text, x, y, maxWidth) {
682
+ if (arguments.length < 3) throw new TypeError('Failed to execute \'fillText\' on \'' + this.constructor.name + '\': 3 arguments required, but only ' + arguments.length + ' present.');
683
+ const textResult = String(text);
684
+ const xResult = Number(x);
685
+ const yResult = Number(y);
686
+ const maxWidthResult = Number(maxWidth);
687
+ if (arguments.length === 3 && !Number.isFinite(xResult + yResult)) return;
688
+ if (arguments.length > 3 && !Number.isFinite(xResult + yResult + maxWidthResult)) return;
689
+ const event = (0, _createCanvasEvent.default)('fillText', getTransformSlice(this), {
690
+ text: textResult,
691
+ x: xResult,
692
+ y: yResult,
693
+ maxWidth: arguments.length === 3 ? null : maxWidthResult
694
+ });
695
+
696
+ this._events.push(event);
697
+
698
+ this._drawCalls.push(event);
699
+ }
700
+
701
+ set filter(value) {
702
+ if (value === '') value = 'none';
703
+ value = this._filterStack[this._stackIndex] = typeof value === 'string' ? value : 'none';
704
+ const event = (0, _createCanvasEvent.default)('filter', getTransformSlice(this), {
705
+ value
706
+ });
707
+
708
+ this._events.push(event);
709
+ }
710
+
711
+ get filter() {
712
+ return this._filterStack[this._stackIndex];
713
+ }
714
+
715
+ set font(value) {
716
+ let ex;
694
717
 
695
- var event = (0, _createCanvasEvent["default"])('isPointInPath', getTransformSlice(this), {
696
- x: Number(x),
697
- y: Number(y),
698
- path: path instanceof Path2D ? path._path.slice() : this._path.slice()
718
+ try {
719
+ const result = (0, _cssfontparser.default)(value);
720
+ value = this._fontStack[this._stackIndex] = result.toString();
721
+ const event = (0, _createCanvasEvent.default)('font', getTransformSlice(this), {
722
+ value
699
723
  });
700
724
 
701
725
  this._events.push(event);
726
+ } catch (ex) {}
727
+ }
702
728
 
703
- return false; // return false in a mocking environment, unless I can verify a point is actually within the path
704
- }
705
- }, {
706
- key: "lineTo",
707
- value: function lineTo(x, y) {
708
- if (arguments.length < 2) throw new TypeError('Failed to execute \'lineTo\' on \'' + this.constructor.name + '\': 2 arguments required, but only ' + arguments.length + ' present.');
709
- var xResult = Number(x);
710
- var yResult = Number(y);
711
- if (!Number.isFinite(xResult + yResult)) return;
712
- var event = (0, _createCanvasEvent["default"])('lineTo', getTransformSlice(this), {
713
- x: xResult,
714
- y: yResult
729
+ get font() {
730
+ return this._fontStack[this._stackIndex];
731
+ }
732
+
733
+ getImageData() {
734
+ return new ImageData(this._canvas.width, this._canvas.height);
735
+ }
736
+
737
+ getLineDash() {
738
+ return this._lineDashStack[this._stackIndex];
739
+ }
740
+
741
+ getTransform() {
742
+ return new _DOMMatrix.default(this._transformStack[this._stackIndex]);
743
+ }
744
+
745
+ set globalAlpha(value) {
746
+ value = Number(value);
747
+ if (!Number.isFinite(value)) return;
748
+ if (value < 0) return;
749
+ if (value > 1) return;
750
+ this._globalAlphaStack[this._stackIndex] = value;
751
+ const event = (0, _createCanvasEvent.default)('globalAlpha', getTransformSlice(this), {
752
+ value
753
+ });
754
+
755
+ this._events.push(event);
756
+ }
757
+
758
+ get globalAlpha() {
759
+ return this._globalAlphaStack[this._stackIndex];
760
+ }
761
+
762
+ set globalCompositeOperation(value) {
763
+ if (compositeOperations.indexOf(value) !== -1) {
764
+ this._globalCompositeOperationStack[this._stackIndex] = value;
765
+ const event = (0, _createCanvasEvent.default)('globalCompositeOperation', getTransformSlice(this), {
766
+ value
715
767
  });
716
768
 
717
769
  this._events.push(event);
718
-
719
- this._path.push(event);
720
770
  }
721
- }, {
722
- key: "measureText",
723
- value: function measureText(text) {
724
- if (arguments.length < 1) throw new TypeError('Failed to execute \'measureText\' on \'' + this.constructor.name + '\': 1 argument required, but only 0 present.');
725
- text = text == null ? '' : text;
726
- text = text.toString();
727
- var event = (0, _createCanvasEvent["default"])('measureText', getTransformSlice(this), {
728
- text: text
771
+ }
772
+
773
+ get globalCompositeOperation() {
774
+ return this._globalCompositeOperationStack[this._stackIndex];
775
+ }
776
+
777
+ set imageSmoothingEnabled(value) {
778
+ value = this._imageSmoothingEnabledStack[this._stackIndex] = Boolean(value);
779
+ const event = (0, _createCanvasEvent.default)('imageSmoothingEnabled', getTransformSlice(this), {
780
+ value
781
+ });
782
+
783
+ this._events.push(event);
784
+ }
785
+
786
+ get imageSmoothingEnabled() {
787
+ return this._imageSmoothingEnabledStack[this._stackIndex];
788
+ }
789
+
790
+ set imageSmoothingQuality(value) {
791
+ if (value === 'high' || value === 'medium' || value === 'low') {
792
+ this._imageSmoothingQualityStack[this._stackIndex] = value;
793
+ const event = (0, _createCanvasEvent.default)('imageSmoothingQuality', getTransformSlice(this), {
794
+ value
729
795
  });
730
796
 
731
797
  this._events.push(event);
798
+ }
799
+ }
800
+
801
+ get imageSmoothingQuality() {
802
+ return this._imageSmoothingQualityStack[this._stackIndex];
803
+ }
732
804
 
733
- return new _TextMetrics["default"](text);
805
+ isPointInPath(path, x, y, fillRule = 'nonzero') {
806
+ if (arguments.length < 2) throw new TypeError('Failed to execute \'isPointInPath\' on \'' + this.constructor.name + '\': 2 arguments required, but only ' + arguments.length + ' present.');
807
+
808
+ if (!(path instanceof Path2D)) {
809
+ if (arguments.length > 2) {
810
+ fillRule = y;
811
+ }
812
+
813
+ y = x;
814
+ x = path;
734
815
  }
735
- }, {
736
- key: "moveTo",
737
- value: function moveTo(x, y) {
738
- if (arguments.length < 2) throw new TypeError('Failed to execute \'moveTo\' on \'' + this.constructor.name + '\': 2 arguments required, but only ' + arguments.length + ' present.');
739
- var xResult = Number(x);
740
- var yResult = Number(y);
741
- if (!Number.isFinite(x + y)) return;
742
- var event = (0, _createCanvasEvent["default"])('moveTo', getTransformSlice(this), {
743
- x: xResult,
744
- y: yResult
745
- });
746
816
 
747
- this._events.push(event);
817
+ 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.');
818
+ const event = (0, _createCanvasEvent.default)('isPointInPath', getTransformSlice(this), {
819
+ x: Number(x),
820
+ y: Number(y),
821
+ fillRule,
822
+ path: path instanceof Path2D ? path._path.slice() : this._path.slice()
823
+ });
824
+
825
+ this._events.push(event);
826
+
827
+ return false; // return false in a mocking environment, unless I can verify a point is actually within the path
828
+ }
748
829
 
749
- this._path.push(event);
830
+ isPointInStroke(path, x, y) {
831
+ if (arguments.length < 2) throw new TypeError('Failed to execute \'isPointInStroke\' on \'' + this.constructor.name + '\': 2 arguments required, but only ' + arguments.length + ' present.');
832
+
833
+ if (!(path instanceof Path2D)) {
834
+ y = x;
835
+ x = path;
750
836
  }
751
- }, {
752
- key: "putImageData",
753
- value: function putImageData(data, x, y, dirtyX, dirtyY, dirtyWidth, dirtyHeight) {
754
- if (arguments.length < 3) throw new TypeError('Failed to execute \'putImageData\' on \'' + this.constructor.name + '\': 3 arguments required, but only ' + arguments.length + ' present.');
755
- 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.');
756
- if (!(data instanceof ImageData)) throw new TypeError('Failed to execute \'putImageData\' on \'' + this.constructor.name + '\': parameter 1 is not of type \'ImageData\'.');
757
- var xResult = Number(x);
758
- var yResult = Number(y);
759
- var dirtyXResult = Number(dirtyX);
760
- var dirtyYResult = Number(dirtyY);
761
- var dirtyWidthResult = Number(dirtyWidth);
762
- var dirtyHeightResult = Number(dirtyHeight);
763
-
764
- if (arguments.length === 3) {
765
- if (!Number.isFinite(xResult + yResult)) return;
766
- } else {
767
- if (!Number.isFinite(xResult + yResult + dirtyXResult + dirtyYResult + dirtyWidthResult + dirtyHeightResult)) return;
768
- }
769
837
 
770
- var event = (0, _createCanvasEvent["default"])('putImageData', getTransformSlice(this), {
771
- x: xResult,
772
- y: yResult,
773
- dirtyX: dirtyXResult,
774
- dirtyY: dirtyYResult,
775
- dirtyWidth: dirtyWidthResult,
776
- dirtyHeight: dirtyHeightResult
838
+ const event = (0, _createCanvasEvent.default)('isPointInPath', getTransformSlice(this), {
839
+ x: Number(x),
840
+ y: Number(y),
841
+ path: path instanceof Path2D ? path._path.slice() : this._path.slice()
842
+ });
843
+
844
+ this._events.push(event);
845
+
846
+ return false; // return false in a mocking environment, unless I can verify a point is actually within the path
847
+ }
848
+
849
+ set lineCap(value) {
850
+ if (value === 'butt' || value === 'round' || value === 'square') {
851
+ this._lineCapStack[this._stackIndex] = value;
852
+ const event = (0, _createCanvasEvent.default)('lineCap', getTransformSlice(this), {
853
+ value
777
854
  });
778
855
 
779
856
  this._events.push(event);
780
857
  }
781
- }, {
782
- key: "quadraticCurveTo",
783
- value: function quadraticCurveTo(cpx, cpy, x, y) {
784
- if (arguments.length < 4) throw new TypeError('Failed to execute \'quadraticCurveTo\' on \'' + this.constructor.name + '\': 4 arguments required, but only ' + arguments.length + ' present.');
785
- var cpxResult = Number(cpx);
786
- var cpyResult = Number(cpy);
787
- var xResult = Number(x);
788
- var yResult = Number(y);
789
- if (!Number.isFinite(cpxResult + cpyResult + xResult + yResult)) return;
790
- var event = (0, _createCanvasEvent["default"])('quadraticCurveTo', getTransformSlice(this), {
791
- cpx: cpxResult,
792
- cpy: cpyResult,
793
- x: xResult,
794
- y: yResult
858
+ }
859
+
860
+ get lineCap() {
861
+ return this._lineCapStack[this._stackIndex];
862
+ }
863
+
864
+ set lineDashOffset(value) {
865
+ const result = Number(value);
866
+
867
+ if (Number.isFinite(result)) {
868
+ this._lineDashOffsetStack[this._stackIndex] = result;
869
+ const event = (0, _createCanvasEvent.default)('lineDashOffset', getTransformSlice(this), {
870
+ value
795
871
  });
796
872
 
797
873
  this._events.push(event);
798
874
  }
799
- }, {
800
- key: "rect",
801
- value: function rect(x, y, width, height) {
802
- if (arguments.length < 4) throw new TypeError('Failed to execute \'rect\' on \'' + this.constructor.name + '\': 4 arguments required, but only ' + arguments.length + ' present.');
803
- if (!Number.isFinite(x + y + width + height)) return;
804
- var xResult = Number(x);
805
- var yResult = Number(y);
806
- var widthResult = Number(width);
807
- var heightResult = Number(height);
808
- var event = (0, _createCanvasEvent["default"])('rect', getTransformSlice(this), {
809
- x: xResult,
810
- y: yResult,
811
- width: widthResult,
812
- height: heightResult
875
+ }
876
+
877
+ get lineDashOffset() {
878
+ return this._lineDashOffsetStack[this._stackIndex];
879
+ }
880
+
881
+ set lineJoin(value) {
882
+ if (value === 'round' || value === 'bevel' || value === 'miter') {
883
+ this._lineJoinStack[this._stackIndex] = value;
884
+ const event = (0, _createCanvasEvent.default)('lineJoin', getTransformSlice(this), {
885
+ value
813
886
  });
814
887
 
815
888
  this._events.push(event);
816
-
817
- this._path.push(event);
818
889
  }
819
- }, {
820
- key: "removeHitRegion",
821
- value: function removeHitRegion(id) {
822
- if (arguments.length < 1) throw new TypeError('Failed to execute \'removeHitRegion\' on \'' + this.constructor.name + '\': 1 argument required, but only ' + arguments.length + ' present.');
823
- var event = (0, _createCanvasEvent["default"])('removeHitRegion', getTransformSlice(this), {
824
- id: id
890
+ }
891
+
892
+ get lineJoin() {
893
+ return this._lineJoinStack[this._stackIndex];
894
+ }
895
+
896
+ lineTo(x, y) {
897
+ if (arguments.length < 2) throw new TypeError('Failed to execute \'lineTo\' on \'' + this.constructor.name + '\': 2 arguments required, but only ' + arguments.length + ' present.');
898
+ const xResult = Number(x);
899
+ const yResult = Number(y);
900
+ if (!Number.isFinite(xResult + yResult)) return;
901
+ const event = (0, _createCanvasEvent.default)('lineTo', getTransformSlice(this), {
902
+ x: xResult,
903
+ y: yResult
904
+ });
905
+
906
+ this._events.push(event);
907
+
908
+ this._path.push(event);
909
+ }
910
+
911
+ set lineWidth(value) {
912
+ const result = Number(value);
913
+
914
+ if (Number.isFinite(result) && result > 0) {
915
+ this._lineWidthStack[this._stackIndex] = result;
916
+ const event = (0, _createCanvasEvent.default)('lineWidth', getTransformSlice(this), {
917
+ value: result
825
918
  });
826
919
 
827
920
  this._events.push(event);
828
921
  }
829
- }, {
830
- key: "resetTransform",
831
- value: function resetTransform() {
832
- this._transformStack[this._stackIndex][0] = 1;
833
- this._transformStack[this._stackIndex][1] = 0;
834
- this._transformStack[this._stackIndex][2] = 0;
835
- this._transformStack[this._stackIndex][3] = 1;
836
- this._transformStack[this._stackIndex][4] = 0;
837
- this._transformStack[this._stackIndex][5] = 0;
838
- var event = (0, _createCanvasEvent["default"])('resetTransform', getTransformSlice(this), {
839
- a: 1,
840
- b: 0,
841
- c: 0,
842
- d: 1,
843
- e: 0,
844
- f: 0
922
+ }
923
+
924
+ get lineWidth() {
925
+ return this._lineWidthStack[this._stackIndex];
926
+ }
927
+
928
+ measureText(text) {
929
+ if (arguments.length < 1) throw new TypeError('Failed to execute \'measureText\' on \'' + this.constructor.name + '\': 1 argument required, but only 0 present.');
930
+ text = text == null ? '' : text;
931
+ text = text.toString();
932
+ const event = (0, _createCanvasEvent.default)('measureText', getTransformSlice(this), {
933
+ text
934
+ });
935
+
936
+ this._events.push(event);
937
+
938
+ return new _TextMetrics.default(text);
939
+ }
940
+
941
+ set miterLimit(value) {
942
+ const result = Number(value);
943
+
944
+ if (Number.isFinite(result) && result > 0) {
945
+ this._miterLimitStack[this._stackIndex] = result;
946
+ const event = (0, _createCanvasEvent.default)('lineWidth', getTransformSlice(this), {
947
+ value: result
845
948
  });
846
949
 
847
950
  this._events.push(event);
848
951
  }
849
- }, {
850
- key: "restore",
851
- value: function restore() {
852
- if (this._stackIndex <= 0) return;
952
+ }
853
953
 
854
- this._transformStack.pop();
954
+ get miterLimit() {
955
+ return this._miterLimitStack[this._stackIndex];
956
+ }
855
957
 
856
- this._directionStack.pop();
958
+ moveTo(x, y) {
959
+ if (arguments.length < 2) throw new TypeError('Failed to execute \'moveTo\' on \'' + this.constructor.name + '\': 2 arguments required, but only ' + arguments.length + ' present.');
960
+ const xResult = Number(x);
961
+ const yResult = Number(y);
962
+ if (!Number.isFinite(x + y)) return;
963
+ const event = (0, _createCanvasEvent.default)('moveTo', getTransformSlice(this), {
964
+ x: xResult,
965
+ y: yResult
966
+ });
857
967
 
858
- this._fillStyleStack.pop();
968
+ this._events.push(event);
859
969
 
860
- this._filterStack.pop();
970
+ this._path.push(event);
971
+ }
861
972
 
862
- this._fontStack.pop();
973
+ putImageData(data, x, y, dirtyX, dirtyY, dirtyWidth, dirtyHeight) {
974
+ if (arguments.length < 3) throw new TypeError('Failed to execute \'putImageData\' on \'' + this.constructor.name + '\': 3 arguments required, but only ' + arguments.length + ' present.');
975
+ 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.');
976
+ if (!(data instanceof ImageData)) throw new TypeError('Failed to execute \'putImageData\' on \'' + this.constructor.name + '\': parameter 1 is not of type \'ImageData\'.');
977
+ const xResult = Number(x);
978
+ const yResult = Number(y);
979
+ const dirtyXResult = Number(dirtyX);
980
+ const dirtyYResult = Number(dirtyY);
981
+ const dirtyWidthResult = Number(dirtyWidth);
982
+ const dirtyHeightResult = Number(dirtyHeight);
983
+
984
+ if (arguments.length === 3) {
985
+ if (!Number.isFinite(xResult + yResult)) return;
986
+ } else {
987
+ if (!Number.isFinite(xResult + yResult + dirtyXResult + dirtyYResult + dirtyWidthResult + dirtyHeightResult)) return;
988
+ }
863
989
 
864
- this._globalAlphaStack.pop();
990
+ const event = (0, _createCanvasEvent.default)('putImageData', getTransformSlice(this), {
991
+ x: xResult,
992
+ y: yResult,
993
+ dirtyX: dirtyXResult,
994
+ dirtyY: dirtyYResult,
995
+ dirtyWidth: dirtyWidthResult,
996
+ dirtyHeight: dirtyHeightResult
997
+ });
865
998
 
866
- this._globalCompositeOperationStack.pop();
999
+ this._events.push(event);
1000
+ }
867
1001
 
868
- this._imageSmoothingEnabledStack.pop();
1002
+ quadraticCurveTo(cpx, cpy, x, y) {
1003
+ if (arguments.length < 4) throw new TypeError('Failed to execute \'quadraticCurveTo\' on \'' + this.constructor.name + '\': 4 arguments required, but only ' + arguments.length + ' present.');
1004
+ const cpxResult = Number(cpx);
1005
+ const cpyResult = Number(cpy);
1006
+ const xResult = Number(x);
1007
+ const yResult = Number(y);
1008
+ if (!Number.isFinite(cpxResult + cpyResult + xResult + yResult)) return;
1009
+ const event = (0, _createCanvasEvent.default)('quadraticCurveTo', getTransformSlice(this), {
1010
+ cpx: cpxResult,
1011
+ cpy: cpyResult,
1012
+ x: xResult,
1013
+ y: yResult
1014
+ });
869
1015
 
870
- this._imageSmoothingQualityStack.pop();
1016
+ this._events.push(event);
1017
+ }
871
1018
 
872
- this._lineCapStack.pop();
1019
+ rect(x, y, width, height) {
1020
+ if (arguments.length < 4) throw new TypeError('Failed to execute \'rect\' on \'' + this.constructor.name + '\': 4 arguments required, but only ' + arguments.length + ' present.');
1021
+ if (!Number.isFinite(x + y + width + height)) return;
1022
+ const xResult = Number(x);
1023
+ const yResult = Number(y);
1024
+ const widthResult = Number(width);
1025
+ const heightResult = Number(height);
1026
+ const event = (0, _createCanvasEvent.default)('rect', getTransformSlice(this), {
1027
+ x: xResult,
1028
+ y: yResult,
1029
+ width: widthResult,
1030
+ height: heightResult
1031
+ });
873
1032
 
874
- this._lineDashStack.pop();
1033
+ this._events.push(event);
875
1034
 
876
- this._lineDashOffsetStack.pop();
1035
+ this._path.push(event);
1036
+ }
877
1037
 
878
- this._lineJoinStack.pop();
1038
+ removeHitRegion(id) {
1039
+ if (arguments.length < 1) throw new TypeError('Failed to execute \'removeHitRegion\' on \'' + this.constructor.name + '\': 1 argument required, but only ' + arguments.length + ' present.');
1040
+ const event = (0, _createCanvasEvent.default)('removeHitRegion', getTransformSlice(this), {
1041
+ id
1042
+ });
879
1043
 
880
- this._lineWidthStack.pop();
1044
+ this._events.push(event);
1045
+ }
881
1046
 
882
- this._miterLimitStack.pop();
1047
+ resetTransform() {
1048
+ this._transformStack[this._stackIndex][0] = 1;
1049
+ this._transformStack[this._stackIndex][1] = 0;
1050
+ this._transformStack[this._stackIndex][2] = 0;
1051
+ this._transformStack[this._stackIndex][3] = 1;
1052
+ this._transformStack[this._stackIndex][4] = 0;
1053
+ this._transformStack[this._stackIndex][5] = 0;
1054
+ const event = (0, _createCanvasEvent.default)('resetTransform', getTransformSlice(this), {
1055
+ a: 1,
1056
+ b: 0,
1057
+ c: 0,
1058
+ d: 1,
1059
+ e: 0,
1060
+ f: 0
1061
+ });
883
1062
 
884
- this._shadowBlurStack.pop();
1063
+ this._events.push(event);
1064
+ }
885
1065
 
886
- this._shadowColorStack.pop();
1066
+ restore() {
1067
+ if (this._stackIndex <= 0) return;
887
1068
 
888
- this._shadowOffsetXStack.pop();
1069
+ this._transformStack.pop();
889
1070
 
890
- this._shadowOffsetYStack.pop();
1071
+ this._directionStack.pop();
891
1072
 
892
- this._strokeStyleStack.pop();
1073
+ this._fillStyleStack.pop();
893
1074
 
894
- this._textAlignStack.pop();
1075
+ this._filterStack.pop();
895
1076
 
896
- this._textBaselineStack.pop();
1077
+ this._fontStack.pop();
897
1078
 
898
- this._stackIndex -= 1;
899
- var event = (0, _createCanvasEvent["default"])('restore', getTransformSlice(this), {});
1079
+ this._globalAlphaStack.pop();
900
1080
 
901
- this._events.push(event);
902
- }
903
- }, {
904
- key: "rotate",
905
- value: function rotate(angle) {
906
- if (arguments.length < 1) throw new TypeError('Failed to execute \'rotate\' on \'' + this.constructor.name + '\': 1 argument required, but only 0 present.');
907
- angle = Number(angle);
908
- if (!Number.isFinite(angle)) return;
909
- var a = this._transformStack[this._stackIndex][0];
910
- var b = this._transformStack[this._stackIndex][1];
911
- var c = this._transformStack[this._stackIndex][2];
912
- var d = this._transformStack[this._stackIndex][3];
913
- var cos = Math.cos(angle);
914
- var sin = Math.sin(angle);
915
- this._transformStack[this._stackIndex][0] = a * cos + c * sin;
916
- this._transformStack[this._stackIndex][1] = b * cos + d * sin;
917
- this._transformStack[this._stackIndex][2] = c * cos - a * sin;
918
- this._transformStack[this._stackIndex][3] = d * cos - b * sin;
919
- var event = (0, _createCanvasEvent["default"])('rotate', getTransformSlice(this), {
920
- angle: angle
921
- });
1081
+ this._globalCompositeOperationStack.pop();
922
1082
 
923
- this._events.push(event);
924
- }
925
- }, {
926
- key: "save",
927
- value: function save() {
928
- this._transformStack.push(this._transformStack[this._stackIndex]);
1083
+ this._imageSmoothingEnabledStack.pop();
929
1084
 
930
- this._directionStack.push(this._directionStack[this._stackIndex]);
1085
+ this._imageSmoothingQualityStack.pop();
931
1086
 
932
- this._fillStyleStack.push(this._fillStyleStack[this._stackIndex]);
1087
+ this._lineCapStack.pop();
933
1088
 
934
- this._filterStack.push(this._filterStack[this._stackIndex]);
1089
+ this._lineDashStack.pop();
935
1090
 
936
- this._fontStack.push(this._fontStack[this._stackIndex]);
1091
+ this._lineDashOffsetStack.pop();
937
1092
 
938
- this._globalAlphaStack.push(this._globalAlphaStack[this._stackIndex]);
1093
+ this._lineJoinStack.pop();
939
1094
 
940
- this._globalCompositeOperationStack.push(this._globalCompositeOperationStack[this._stackIndex]);
1095
+ this._lineWidthStack.pop();
941
1096
 
942
- this._imageSmoothingEnabledStack.push(this._imageSmoothingEnabledStack[this._stackIndex]);
1097
+ this._miterLimitStack.pop();
943
1098
 
944
- this._imageSmoothingQualityStack.push(this._imageSmoothingQualityStack[this._stackIndex]);
1099
+ this._shadowBlurStack.pop();
945
1100
 
946
- this._lineCapStack.push(this._lineCapStack[this._stackIndex]);
1101
+ this._shadowColorStack.pop();
947
1102
 
948
- this._lineDashStack.push(this._lineDashStack[this._stackIndex]);
1103
+ this._shadowOffsetXStack.pop();
949
1104
 
950
- this._lineDashOffsetStack.push(this._lineDashOffsetStack[this._stackIndex]);
1105
+ this._shadowOffsetYStack.pop();
951
1106
 
952
- this._lineJoinStack.push(this._lineJoinStack[this._stackIndex]);
1107
+ this._strokeStyleStack.pop();
953
1108
 
954
- this._lineWidthStack.push(this._lineWidthStack[this.stackIndex]);
1109
+ this._textAlignStack.pop();
955
1110
 
956
- this._miterLimitStack.push(this._miterLimitStack[this._stackIndex]);
1111
+ this._textBaselineStack.pop();
957
1112
 
958
- this._shadowBlurStack.push(this._shadowBlurStack[this._stackIndex]);
1113
+ this._stackIndex -= 1;
1114
+ const event = (0, _createCanvasEvent.default)('restore', getTransformSlice(this), {});
959
1115
 
960
- this._shadowColorStack.push(this._shadowColorStack[this._stackIndex]);
1116
+ this._events.push(event);
1117
+ }
961
1118
 
962
- this._shadowOffsetXStack.push(this._shadowOffsetXStack[this._stackIndex]);
1119
+ rotate(angle) {
1120
+ if (arguments.length < 1) throw new TypeError('Failed to execute \'rotate\' on \'' + this.constructor.name + '\': 1 argument required, but only 0 present.');
1121
+ angle = Number(angle);
1122
+ if (!Number.isFinite(angle)) return;
1123
+ const a = this._transformStack[this._stackIndex][0];
1124
+ const b = this._transformStack[this._stackIndex][1];
1125
+ const c = this._transformStack[this._stackIndex][2];
1126
+ const d = this._transformStack[this._stackIndex][3];
1127
+ const cos = Math.cos(angle);
1128
+ const sin = Math.sin(angle);
1129
+ this._transformStack[this._stackIndex][0] = a * cos + c * sin;
1130
+ this._transformStack[this._stackIndex][1] = b * cos + d * sin;
1131
+ this._transformStack[this._stackIndex][2] = c * cos - a * sin;
1132
+ this._transformStack[this._stackIndex][3] = d * cos - b * sin;
1133
+ const event = (0, _createCanvasEvent.default)('rotate', getTransformSlice(this), {
1134
+ angle
1135
+ });
963
1136
 
964
- this._shadowOffsetYStack.push(this._shadowOffsetYStack[this._stackIndex]);
1137
+ this._events.push(event);
1138
+ }
965
1139
 
966
- this._strokeStyleStack.push(this._strokeStyleStack[this._stackIndex]);
1140
+ save() {
1141
+ this._transformStack.push(this._transformStack[this._stackIndex].slice());
967
1142
 
968
- this._textAlignStack.push(this._textAlignStack[this._stackIndex]);
1143
+ this._directionStack.push(this._directionStack[this._stackIndex]);
969
1144
 
970
- this._textBaselineStack.push(this._textBaselineStack[this._stackIndex]);
1145
+ this._fillStyleStack.push(this._fillStyleStack[this._stackIndex]);
971
1146
 
972
- this._stackIndex += 1;
973
- var event = (0, _createCanvasEvent["default"])('save', getTransformSlice(this), {});
1147
+ this._filterStack.push(this._filterStack[this._stackIndex]);
974
1148
 
975
- this._events.push(event);
976
- }
977
- }, {
978
- key: "scale",
979
- value: function scale(x, y) {
980
- if (arguments.length < 2) throw new TypeError('Failed to execute \'scale\' on \'' + this.constructor.name + '\': 2 arguments required, but only ' + arguments.length + ' present.');
981
- var xResult = Number(x);
982
- var yResult = Number(y);
983
-
984
- if (Number.isFinite(xResult) && Number.isFinite(yResult)) {
985
- this._transformStack[this._stackIndex][0] *= xResult;
986
- this._transformStack[this._stackIndex][1] *= xResult;
987
- this._transformStack[this._stackIndex][2] *= yResult;
988
- this._transformStack[this._stackIndex][3] *= yResult;
989
- var event = (0, _createCanvasEvent["default"])('scale', getTransformSlice(this), {
990
- x: xResult,
991
- y: yResult
992
- });
1149
+ this._fontStack.push(this._fontStack[this._stackIndex]);
993
1150
 
994
- this._events.push(event);
995
- }
996
- }
997
- }, {
998
- key: "scrollPathIntoView",
999
- value: function scrollPathIntoView(path) {
1000
- if (arguments.length > 0 && path instanceof Path2D) path = path._path.slice();else path = this._path.slice();
1001
- var event = (0, _createCanvasEvent["default"])('scrollPathIntoView', getTransformSlice(this), {
1002
- path: path
1003
- });
1151
+ this._globalAlphaStack.push(this._globalAlphaStack[this._stackIndex]);
1004
1152
 
1005
- this._events.push(event);
1006
- }
1007
- }, {
1008
- key: "setLineDash",
1009
- value: function setLineDash(lineDash) {
1010
- var isSequence = [Array, Int8Array, Uint8Array, Int16Array, Uint16Array, Int32Array, Uint32Array, Float32Array, Float64Array].reduce(function (left, right) {
1011
- return left || lineDash instanceof right;
1012
- }, false);
1013
- if (!isSequence) throw new TypeError('Failed to execute \'setLineDash\' on \'' + this.constructor.name + '\': The provided value cannot be converted to a sequence.');
1014
- var result = [];
1015
-
1016
- for (var i = 0; i < lineDash.length; i++) {
1017
- var value = Number(lineDash[i]);
1018
-
1019
- if (Number.isFinite(value) && value >= 0) {
1020
- result.push(value);
1021
- } else {
1022
- return;
1023
- }
1024
- }
1153
+ this._globalCompositeOperationStack.push(this._globalCompositeOperationStack[this._stackIndex]);
1025
1154
 
1026
- result = this._lineDashStack[this._stackIndex] = result.length % 2 === 1 ? result.concat(result) : result;
1027
- var event = (0, _createCanvasEvent["default"])('setLineDash', getTransformSlice(this), {
1028
- value: result.slice()
1029
- });
1155
+ this._imageSmoothingEnabledStack.push(this._imageSmoothingEnabledStack[this._stackIndex]);
1030
1156
 
1031
- this._events.push(event);
1032
- }
1033
- }, {
1034
- key: "setTransform",
1035
- value: function setTransform(a, b, c, d, e, f) {
1036
- if (arguments.length === 0) {
1037
- a = 1;
1038
- b = 0;
1039
- c = 0;
1040
- d = 1;
1041
- e = 0;
1042
- f = 0;
1043
- } else if (arguments.length === 1) {
1044
- if (a instanceof _DOMMatrix["default"]) {
1045
- var transform = a;
1046
- a = transform.a;
1047
- b = transform.b;
1048
- c = transform.c;
1049
- d = transform.d;
1050
- e = transform.e;
1051
- f = transform.f;
1052
- } else {
1053
- throw new TypeError('Failed to execute \'setTransform\' on \'' + this.constructor.name + '\': parameter ' + a + ' (\'transform\') is not an object.');
1054
- }
1055
- } else if (arguments.length < 6) {
1056
- throw new TypeError('Failed to execute \'setTransform\' on \'' + this.constructor.name + '\': Valid arities are: [0, 1, 6], but ' + arguments.length + ' arguments provided.');
1057
- }
1157
+ this._imageSmoothingQualityStack.push(this._imageSmoothingQualityStack[this._stackIndex]);
1058
1158
 
1059
- a = Number(a);
1060
- b = Number(b);
1061
- c = Number(c);
1062
- d = Number(d);
1063
- e = Number(e);
1064
- f = Number(f);
1065
- if (!Number.isFinite(a + b + c + d + e + f)) return;
1066
- this._transformStack[this._stackIndex][0] = a;
1067
- this._transformStack[this._stackIndex][1] = b;
1068
- this._transformStack[this._stackIndex][2] = c;
1069
- this._transformStack[this._stackIndex][3] = d;
1070
- this._transformStack[this._stackIndex][4] = e;
1071
- this._transformStack[this._stackIndex][5] = f;
1072
- var event = (0, _createCanvasEvent["default"])('setTransform', getTransformSlice(this), {
1073
- a: a,
1074
- b: b,
1075
- c: c,
1076
- d: d,
1077
- e: e,
1078
- f: f
1079
- });
1159
+ this._lineCapStack.push(this._lineCapStack[this._stackIndex]);
1080
1160
 
1081
- this._events.push(event);
1082
- }
1083
- }, {
1084
- key: "stroke",
1085
- value: function stroke(path) {
1086
- if (arguments.length === 0) {
1087
- path = this._path.slice();
1088
- } else {
1089
- if (!(path instanceof Path2D)) throw new TypeError('Failed to execute \'stroke\' on \'' + this.constructor.name + '\': parameter 1 is not of type \'Path2D\'.');
1090
- path = path._path.slice();
1091
- }
1161
+ this._lineDashStack.push(this._lineDashStack[this._stackIndex]);
1092
1162
 
1093
- var event = (0, _createCanvasEvent["default"])('stroke', getTransformSlice(this), {
1094
- path: path
1095
- });
1163
+ this._lineDashOffsetStack.push(this._lineDashOffsetStack[this._stackIndex]);
1096
1164
 
1097
- this._events.push(event);
1165
+ this._lineJoinStack.push(this._lineJoinStack[this._stackIndex]);
1098
1166
 
1099
- this._drawCalls.push(event);
1100
- }
1101
- }, {
1102
- key: "strokeRect",
1103
- value: function strokeRect(x, y, width, height) {
1104
- if (arguments.length < 4) throw new TypeError('Failed to execute \'strokeRect\' on \'' + this.constructor.name + '\': 4 arguments required, but only ' + arguments.length + ' present.');
1105
- x = Number(x);
1106
- y = Number(y);
1107
- width = Number(width);
1108
- height = Number(height);
1109
- if (!Number.isFinite(x + y + width + height)) return;
1110
- var event = (0, _createCanvasEvent["default"])('strokeRect', getTransformSlice(this), {
1111
- x: x,
1112
- y: y,
1113
- width: width,
1114
- height: height
1115
- });
1167
+ this._lineWidthStack.push(this._lineWidthStack[this._stackIndex]);
1116
1168
 
1117
- this._events.push(event);
1169
+ this._miterLimitStack.push(this._miterLimitStack[this._stackIndex]);
1118
1170
 
1119
- this._drawCalls.push(event);
1120
- }
1121
- }, {
1122
- key: "strokeText",
1123
- value: function strokeText(text, x, y, maxWidth) {
1124
- if (arguments.length < 3) throw new TypeError('Failed to execute \'strokeText\' on \'' + this.constructor.name + '\': 3 arguments required, but only ' + arguments.length + ' present.');
1125
- var textResult = String(text);
1126
- var xResult = Number(x);
1127
- var yResult = Number(y);
1128
- var maxWidthResult = Number(maxWidth);
1129
- if (arguments.length === 3 && !Number.isFinite(xResult + yResult)) return;
1130
- if (arguments.length > 3 && !Number.isFinite(xResult + yResult + maxWidthResult)) return;
1131
- var event = (0, _createCanvasEvent["default"])('strokeText', getTransformSlice(this), {
1132
- text: textResult,
1133
- x: xResult,
1134
- y: yResult,
1135
- maxWidth: arguments.length === 3 ? null : maxWidthResult
1136
- });
1171
+ this._shadowBlurStack.push(this._shadowBlurStack[this._stackIndex]);
1137
1172
 
1138
- this._events.push(event);
1173
+ this._shadowColorStack.push(this._shadowColorStack[this._stackIndex]);
1139
1174
 
1140
- this._drawCalls.push(event);
1141
- }
1142
- }, {
1143
- key: "transform",
1144
- value: function transform(a, b, c, d, e, f) {
1145
- if (arguments.length < 6) throw new TypeError('Failed to execute \'transform\' on \'' + this.constructor.name + '\': 6 arguments required, but only ' + arguments.length + ' present.');
1146
- a = Number(a);
1147
- b = Number(b);
1148
- c = Number(c);
1149
- d = Number(d);
1150
- e = Number(e);
1151
- f = Number(f);
1152
- if (!Number.isFinite(a + b + c + d + e + f)) return;
1153
- var sa = this._transformStack[this._stackIndex][0];
1154
- var sb = this._transformStack[this._stackIndex][1];
1155
- var sc = this._transformStack[this._stackIndex][2];
1156
- var sd = this._transformStack[this._stackIndex][3];
1157
- var se = this._transformStack[this._stackIndex][4];
1158
- var sf = this._transformStack[this._stackIndex][5];
1159
- this._transformStack[this._stackIndex][0] = sa * a + sc * b;
1160
- this._transformStack[this._stackIndex][1] = sb * a + sd * b;
1161
- this._transformStack[this._stackIndex][2] = sa * c + sc * d;
1162
- this._transformStack[this._stackIndex][3] = sb * c + sd * d;
1163
- this._transformStack[this._stackIndex][4] = sa * e + sc * f + se;
1164
- this._transformStack[this._stackIndex][5] = sb * e + sd * f + sf;
1165
- var event = (0, _createCanvasEvent["default"])('transform', getTransformSlice(this), {
1166
- a: a,
1167
- b: b,
1168
- c: c,
1169
- d: d,
1170
- e: e,
1171
- f: f
1175
+ this._shadowOffsetXStack.push(this._shadowOffsetXStack[this._stackIndex]);
1176
+
1177
+ this._shadowOffsetYStack.push(this._shadowOffsetYStack[this._stackIndex]);
1178
+
1179
+ this._strokeStyleStack.push(this._strokeStyleStack[this._stackIndex]);
1180
+
1181
+ this._textAlignStack.push(this._textAlignStack[this._stackIndex]);
1182
+
1183
+ this._textBaselineStack.push(this._textBaselineStack[this._stackIndex]);
1184
+
1185
+ this._stackIndex += 1;
1186
+ const event = (0, _createCanvasEvent.default)('save', getTransformSlice(this), {});
1187
+
1188
+ this._events.push(event);
1189
+ }
1190
+
1191
+ scale(x, y) {
1192
+ if (arguments.length < 2) throw new TypeError('Failed to execute \'scale\' on \'' + this.constructor.name + '\': 2 arguments required, but only ' + arguments.length + ' present.');
1193
+ const xResult = Number(x);
1194
+ const yResult = Number(y);
1195
+
1196
+ if (Number.isFinite(xResult) && Number.isFinite(yResult)) {
1197
+ this._transformStack[this._stackIndex][0] *= xResult;
1198
+ this._transformStack[this._stackIndex][1] *= xResult;
1199
+ this._transformStack[this._stackIndex][2] *= yResult;
1200
+ this._transformStack[this._stackIndex][3] *= yResult;
1201
+ const event = (0, _createCanvasEvent.default)('scale', getTransformSlice(this), {
1202
+ x: xResult,
1203
+ y: yResult
1172
1204
  });
1173
1205
 
1174
1206
  this._events.push(event);
1175
1207
  }
1176
- }, {
1177
- key: "translate",
1178
- value: function translate(x, y) {
1179
- if (arguments.length < 2) throw new TypeError('Failed to execute \'translate\' on \'' + this.constructor.name + '\': 2 arguments required, but only ' + arguments.length + ' present.');
1180
- var xResult = Number(x);
1181
- var yResult = Number(y);
1182
- var a = this._transformStack[this._stackIndex][0];
1183
- var b = this._transformStack[this._stackIndex][1];
1184
- var c = this._transformStack[this._stackIndex][2];
1185
- var d = this._transformStack[this._stackIndex][3];
1186
-
1187
- if (Number.isFinite(xResult + yResult)) {
1188
- this._transformStack[this._stackIndex][4] += a * xResult + c * yResult;
1189
- this._transformStack[this._stackIndex][5] += b * xResult + d * yResult;
1190
- var event = (0, _createCanvasEvent["default"])('translate', getTransformSlice(this), {
1191
- x: xResult,
1192
- y: yResult
1193
- });
1208
+ }
1194
1209
 
1195
- this._events.push(event);
1196
- }
1197
- }
1198
- }, {
1199
- key: "canvas",
1200
- get: function get() {
1201
- return this._canvas;
1202
- }
1203
- }, {
1204
- key: "currentTransform",
1205
- set: function set(value) {
1206
- if (value instanceof _DOMMatrix["default"]) {
1207
- this._transformStack[this._stackIndex][0] = value.a;
1208
- this._transformStack[this._stackIndex][1] = value.b;
1209
- this._transformStack[this._stackIndex][2] = value.c;
1210
- this._transformStack[this._stackIndex][3] = value.d;
1211
- this._transformStack[this._stackIndex][4] = value.e;
1212
- this._transformStack[this._stackIndex][5] = value.f;
1213
- var event = (0, _createCanvasEvent["default"])('currentTransform', getTransformSlice(this), {
1214
- a: value.a,
1215
- b: value.b,
1216
- c: value.c,
1217
- d: value.d,
1218
- e: value.e,
1219
- f: value.f
1220
- });
1210
+ scrollPathIntoView(path) {
1211
+ if (arguments.length > 0 && path instanceof Path2D) path = path._path.slice();else path = this._path.slice();
1212
+ const event = (0, _createCanvasEvent.default)('scrollPathIntoView', getTransformSlice(this), {
1213
+ path
1214
+ });
1221
1215
 
1222
- this._events.push(event);
1223
- }
1224
- },
1225
- get: function get() {
1226
- return new _DOMMatrix["default"](this._transformStack[this._stackIndex]);
1227
- }
1228
- }, {
1229
- key: "direction",
1230
- set: function set(value) {
1231
- if (value === 'rtl' || value === 'ltr' || value === 'inherit') {
1232
- this._directionStack[this._stackIndex] = value;
1233
- var event = (0, _createCanvasEvent["default"])('direction', getTransformSlice(this), {
1234
- value: value
1235
- });
1216
+ this._events.push(event);
1217
+ }
1236
1218
 
1237
- this._events.push(event);
1219
+ setLineDash(lineDash) {
1220
+ const isSequence = [Array, Int8Array, Uint8Array, Int16Array, Uint16Array, Int32Array, Uint32Array, Float32Array, Float64Array].reduce((left, right) => left || lineDash instanceof right, false);
1221
+ if (!isSequence) throw new TypeError('Failed to execute \'setLineDash\' on \'' + this.constructor.name + '\': The provided value cannot be converted to a sequence.');
1222
+ let result = [];
1223
+
1224
+ for (let i = 0; i < lineDash.length; i++) {
1225
+ const value = Number(lineDash[i]);
1226
+
1227
+ if (Number.isFinite(value) && value >= 0) {
1228
+ result.push(value);
1229
+ } else {
1230
+ return;
1238
1231
  }
1239
- },
1240
- get: function get() {
1241
- return this._directionStack[this._stackIndex];
1242
1232
  }
1243
- }, {
1244
- key: "fillStyle",
1245
- set: function set(value) {
1246
- var valid = false;
1247
-
1248
- if (typeof value === 'string') {
1249
- var result = parseCSSColor(value);
1250
-
1251
- if (result) {
1252
- valid = true;
1253
- value = this._fillStyleStack[this._stackIndex] = result;
1254
- }
1255
- } else if (value instanceof CanvasGradient || value instanceof _CanvasPattern["default"]) {
1256
- valid = true;
1257
- this._fillStyleStack[this._stackIndex] = value;
1258
- }
1259
1233
 
1260
- if (valid) {
1261
- var event = (0, _createCanvasEvent["default"])('fillStyle', getTransformSlice(this), {
1262
- value: value
1263
- });
1234
+ result = this._lineDashStack[this._stackIndex] = result.length % 2 === 1 ? result.concat(result) : result;
1235
+ const event = (0, _createCanvasEvent.default)('setLineDash', getTransformSlice(this), {
1236
+ value: result.slice()
1237
+ });
1264
1238
 
1265
- this._events.push(event);
1239
+ this._events.push(event);
1240
+ }
1241
+
1242
+ setTransform(a, b, c, d, e, f) {
1243
+ if (arguments.length === 0) {
1244
+ a = 1;
1245
+ b = 0;
1246
+ c = 0;
1247
+ d = 1;
1248
+ e = 0;
1249
+ f = 0;
1250
+ } else if (arguments.length === 1) {
1251
+ if (a instanceof _DOMMatrix.default) {
1252
+ let transform = a;
1253
+ a = transform.a;
1254
+ b = transform.b;
1255
+ c = transform.c;
1256
+ d = transform.d;
1257
+ e = transform.e;
1258
+ f = transform.f;
1259
+ } else {
1260
+ throw new TypeError('Failed to execute \'setTransform\' on \'' + this.constructor.name + '\': parameter ' + a + ' (\'transform\') is not an object.');
1266
1261
  }
1267
- },
1268
- get: function get() {
1269
- return this._fillStyleStack[this._stackIndex];
1270
- }
1271
- }, {
1272
- key: "filter",
1273
- set: function set(value) {
1274
- if (value === '') value = 'none';
1275
- value = this._filterStack[this._stackIndex] = typeof value === 'string' ? value : 'none';
1276
- var event = (0, _createCanvasEvent["default"])('filter', getTransformSlice(this), {
1277
- value: value
1262
+ } else if (arguments.length < 6) {
1263
+ throw new TypeError('Failed to execute \'setTransform\' on \'' + this.constructor.name + '\': Valid arities are: [0, 1, 6], but ' + arguments.length + ' arguments provided.');
1264
+ }
1265
+
1266
+ a = Number(a);
1267
+ b = Number(b);
1268
+ c = Number(c);
1269
+ d = Number(d);
1270
+ e = Number(e);
1271
+ f = Number(f);
1272
+ if (!Number.isFinite(a + b + c + d + e + f)) return;
1273
+ this._transformStack[this._stackIndex][0] = a;
1274
+ this._transformStack[this._stackIndex][1] = b;
1275
+ this._transformStack[this._stackIndex][2] = c;
1276
+ this._transformStack[this._stackIndex][3] = d;
1277
+ this._transformStack[this._stackIndex][4] = e;
1278
+ this._transformStack[this._stackIndex][5] = f;
1279
+ const event = (0, _createCanvasEvent.default)('setTransform', getTransformSlice(this), {
1280
+ a,
1281
+ b,
1282
+ c,
1283
+ d,
1284
+ e,
1285
+ f
1286
+ });
1287
+
1288
+ this._events.push(event);
1289
+ }
1290
+
1291
+ set shadowBlur(value) {
1292
+ const result = Number(value);
1293
+
1294
+ if (Number.isFinite(result) && result > 0) {
1295
+ this._shadowBlurStack[this._stackIndex] = result;
1296
+ const event = (0, _createCanvasEvent.default)('shadowBlur', getTransformSlice(this), {
1297
+ value: result
1278
1298
  });
1279
1299
 
1280
1300
  this._events.push(event);
1281
- },
1282
- get: function get() {
1283
- return this._filterStack[this._stackIndex];
1284
1301
  }
1285
- }, {
1286
- key: "font",
1287
- set: function set(value) {
1288
- var ex;
1289
-
1290
- try {
1291
- var result = (0, _cssfontparser["default"])(value);
1292
- value = this._fontStack[this._stackIndex] = result.toString();
1293
- var event = (0, _createCanvasEvent["default"])('font', getTransformSlice(this), {
1294
- value: value
1302
+ }
1303
+
1304
+ get shadowBlur() {
1305
+ return this._shadowBlurStack[this._stackIndex];
1306
+ }
1307
+
1308
+ set shadowColor(value) {
1309
+ if (typeof value === 'string') {
1310
+ const result = parseCSSColor(value);
1311
+
1312
+ if (result) {
1313
+ this._shadowColorStack[this._stackIndex] = result;
1314
+ const event = (0, _createCanvasEvent.default)('shadowColor', getTransformSlice(this), {
1315
+ value: result
1295
1316
  });
1296
1317
 
1297
1318
  this._events.push(event);
1298
- } catch (ex) {}
1299
- },
1300
- get: function get() {
1301
- return this._fontStack[this._stackIndex];
1319
+ }
1302
1320
  }
1303
- }, {
1304
- key: "globalAlpha",
1305
- set: function set(value) {
1306
- value = Number(value);
1307
- if (!Number.isFinite(value)) return;
1308
- if (value < 0) return;
1309
- if (value > 1) return;
1310
- this._globalAlphaStack[this._stackIndex] = value;
1311
- var event = (0, _createCanvasEvent["default"])('globalAlpha', getTransformSlice(this), {
1312
- value: value
1321
+ }
1322
+
1323
+ get shadowColor() {
1324
+ return this._shadowColorStack[this._stackIndex];
1325
+ }
1326
+
1327
+ set shadowOffsetX(value) {
1328
+ const result = Number(value);
1329
+
1330
+ if (Number.isFinite(result)) {
1331
+ this._shadowOffsetXStack[this._stackIndex] = result;
1332
+ const event = (0, _createCanvasEvent.default)('shadowOffsetX', getTransformSlice(this), {
1333
+ value: result
1313
1334
  });
1314
1335
 
1315
1336
  this._events.push(event);
1316
- },
1317
- get: function get() {
1318
- return this._globalAlphaStack[this._stackIndex];
1319
1337
  }
1320
- }, {
1321
- key: "globalCompositeOperation",
1322
- set: function set(value) {
1323
- if (compositeOperations.indexOf(value) !== -1) {
1324
- this._globalCompositeOperationStack[this._stackIndex] = value;
1325
- var event = (0, _createCanvasEvent["default"])('globalCompositeOperation', getTransformSlice(this), {
1326
- value: value
1327
- });
1338
+ }
1328
1339
 
1329
- this._events.push(event);
1330
- }
1331
- },
1332
- get: function get() {
1333
- return this._globalCompositeOperationStack[this._stackIndex];
1334
- }
1335
- }, {
1336
- key: "imageSmoothingEnabled",
1337
- set: function set(value) {
1338
- value = this._imageSmoothingEnabledStack[this._stackIndex] = Boolean(value);
1339
- var event = (0, _createCanvasEvent["default"])('imageSmoothingEnabled', getTransformSlice(this), {
1340
- value: value
1340
+ get shadowOffsetX() {
1341
+ return this._shadowOffsetXStack[this._stackIndex];
1342
+ }
1343
+
1344
+ set shadowOffsetY(value) {
1345
+ const result = Number(value);
1346
+
1347
+ if (Number.isFinite(result)) {
1348
+ this._shadowOffsetXStack[this._stackIndex] = result;
1349
+ const event = (0, _createCanvasEvent.default)('shadowOffsetY', getTransformSlice(this), {
1350
+ value: result
1341
1351
  });
1342
1352
 
1343
1353
  this._events.push(event);
1344
- },
1345
- get: function get() {
1346
- return this._imageSmoothingEnabledStack[this._stackIndex];
1347
1354
  }
1348
- }, {
1349
- key: "imageSmoothingQuality",
1350
- set: function set(value) {
1351
- if (value === 'high' || value === 'medium' || value === 'low') {
1352
- this._imageSmoothingQualityStack[this._stackIndex] = value;
1353
- var event = (0, _createCanvasEvent["default"])('imageSmoothingQuality', getTransformSlice(this), {
1354
- value: value
1355
- });
1355
+ }
1356
1356
 
1357
- this._events.push(event);
1358
- }
1359
- },
1360
- get: function get() {
1361
- return this._imageSmoothingQualityStack[this._stackIndex];
1362
- }
1363
- }, {
1364
- key: "lineCap",
1365
- set: function set(value) {
1366
- if (value === 'butt' || value === 'round' || value === 'square') {
1367
- this._lineCapStack[this._stackIndex] = value;
1368
- var event = (0, _createCanvasEvent["default"])('lineCap', getTransformSlice(this), {
1369
- value: value
1370
- });
1357
+ get shadowOffsetY() {
1358
+ return this._shadowOffsetXStack[this._stackIndex];
1359
+ }
1371
1360
 
1372
- this._events.push(event);
1373
- }
1374
- },
1375
- get: function get() {
1376
- return this._lineCapStack[this._stackIndex];
1361
+ stroke(path) {
1362
+ if (arguments.length === 0) {
1363
+ path = this._path.slice();
1364
+ } else {
1365
+ if (!(path instanceof Path2D)) throw new TypeError('Failed to execute \'stroke\' on \'' + this.constructor.name + '\': parameter 1 is not of type \'Path2D\'.');
1366
+ path = path._path.slice();
1377
1367
  }
1378
- }, {
1379
- key: "lineDashOffset",
1380
- set: function set(value) {
1381
- var result = Number(value);
1382
-
1383
- if (Number.isFinite(result)) {
1384
- this._lineDashOffsetStack[this._stackIndex] = result;
1385
- var event = (0, _createCanvasEvent["default"])('lineDashOffset', getTransformSlice(this), {
1386
- value: value
1387
- });
1388
1368
 
1389
- this._events.push(event);
1390
- }
1391
- },
1392
- get: function get() {
1393
- return this._lineDashOffsetStack[this._stackIndex];
1394
- }
1395
- }, {
1396
- key: "lineJoin",
1397
- set: function set(value) {
1398
- if (value === 'round' || value === 'bevel' || value === 'miter') {
1399
- this._lineJoinStack[this._stackIndex] = value;
1400
- var event = (0, _createCanvasEvent["default"])('lineJoin', getTransformSlice(this), {
1401
- value: value
1402
- });
1369
+ const event = (0, _createCanvasEvent.default)('stroke', getTransformSlice(this), {
1370
+ path
1371
+ });
1403
1372
 
1404
- this._events.push(event);
1405
- }
1406
- },
1407
- get: function get() {
1408
- return this._lineJoinStack[this._stackIndex];
1409
- }
1410
- }, {
1411
- key: "lineWidth",
1412
- set: function set(value) {
1413
- var result = Number(value);
1414
-
1415
- if (Number.isFinite(result) && result > 0) {
1416
- this._lineWidthStack[this._stackIndex] = result;
1417
- var event = (0, _createCanvasEvent["default"])('lineWidth', getTransformSlice(this), {
1418
- value: result
1419
- });
1373
+ this._events.push(event);
1420
1374
 
1421
- this._events.push(event);
1422
- }
1423
- },
1424
- get: function get() {
1425
- return this._lineWidthStack[this._stackIndex];
1426
- }
1427
- }, {
1428
- key: "miterLimit",
1429
- set: function set(value) {
1430
- var result = Number(value);
1431
-
1432
- if (Number.isFinite(result) && result > 0) {
1433
- this._miterLimitStack[this._stackIndex] = result;
1434
- var event = (0, _createCanvasEvent["default"])('lineWidth', getTransformSlice(this), {
1435
- value: result
1436
- });
1375
+ this._drawCalls.push(event);
1376
+ }
1437
1377
 
1438
- this._events.push(event);
1439
- }
1440
- },
1441
- get: function get() {
1442
- return this._miterLimitStack[this._stackIndex];
1443
- }
1444
- }, {
1445
- key: "shadowBlur",
1446
- set: function set(value) {
1447
- var result = Number(value);
1448
-
1449
- if (Number.isFinite(result) && result > 0) {
1450
- this._shadowBlurStack[this._stackIndex] = result;
1451
- var event = (0, _createCanvasEvent["default"])('shadowBlur', getTransformSlice(this), {
1452
- value: result
1453
- });
1378
+ strokeRect(x, y, width, height) {
1379
+ if (arguments.length < 4) throw new TypeError('Failed to execute \'strokeRect\' on \'' + this.constructor.name + '\': 4 arguments required, but only ' + arguments.length + ' present.');
1380
+ x = Number(x);
1381
+ y = Number(y);
1382
+ width = Number(width);
1383
+ height = Number(height);
1384
+ if (!Number.isFinite(x + y + width + height)) return;
1385
+ const event = (0, _createCanvasEvent.default)('strokeRect', getTransformSlice(this), {
1386
+ x,
1387
+ y,
1388
+ width,
1389
+ height
1390
+ });
1454
1391
 
1455
- this._events.push(event);
1456
- }
1457
- },
1458
- get: function get() {
1459
- return this._shadowBlurStack[this._stackIndex];
1460
- }
1461
- }, {
1462
- key: "shadowColor",
1463
- set: function set(value) {
1464
- if (typeof value === 'string') {
1465
- var result = parseCSSColor(value);
1466
-
1467
- if (result) {
1468
- this._shadowColorStack[this._stackIndex] = result;
1469
- var event = (0, _createCanvasEvent["default"])('shadowColor', getTransformSlice(this), {
1470
- value: result
1471
- });
1472
-
1473
- this._events.push(event);
1474
- }
1475
- }
1476
- },
1477
- get: function get() {
1478
- return this._shadowColorStack[this._stackIndex];
1479
- }
1480
- }, {
1481
- key: "shadowOffsetX",
1482
- set: function set(value) {
1483
- var result = Number(value);
1484
-
1485
- if (Number.isFinite(result)) {
1486
- this._shadowOffsetXStack[this._stackIndex] = result;
1487
- var event = (0, _createCanvasEvent["default"])('shadowOffsetX', getTransformSlice(this), {
1488
- value: result
1489
- });
1392
+ this._events.push(event);
1490
1393
 
1491
- this._events.push(event);
1394
+ this._drawCalls.push(event);
1395
+ }
1396
+
1397
+ set strokeStyle(value) {
1398
+ let valid = false;
1399
+
1400
+ if (typeof value === 'string') {
1401
+ const result = parseCSSColor(value);
1402
+
1403
+ if (result) {
1404
+ valid = true;
1405
+ value = this._strokeStyleStack[this._stackIndex] = result;
1492
1406
  }
1493
- },
1494
- get: function get() {
1495
- return this._shadowOffsetXStack[this._stackIndex];
1407
+ } else if (value instanceof CanvasGradient || value instanceof _CanvasPattern.default) {
1408
+ valid = true;
1409
+ this._strokeStyleStack[this._stackIndex] = value;
1496
1410
  }
1497
- }, {
1498
- key: "shadowOffsetY",
1499
- set: function set(value) {
1500
- var result = Number(value);
1501
-
1502
- if (Number.isFinite(result)) {
1503
- this._shadowOffsetXStack[this._stackIndex] = result;
1504
- var event = (0, _createCanvasEvent["default"])('shadowOffsetY', getTransformSlice(this), {
1505
- value: result
1506
- });
1507
1411
 
1508
- this._events.push(event);
1509
- }
1510
- },
1511
- get: function get() {
1512
- return this._shadowOffsetXStack[this._stackIndex];
1412
+ if (valid) {
1413
+ const event = (0, _createCanvasEvent.default)('strokeStyle', getTransformSlice(this), {
1414
+ value
1415
+ });
1416
+
1417
+ this._events.push(event);
1513
1418
  }
1514
- }, {
1515
- key: "strokeStyle",
1516
- set: function set(value) {
1517
- var valid = false;
1518
-
1519
- if (typeof value === 'string') {
1520
- var result = parseCSSColor(value);
1521
-
1522
- if (result) {
1523
- valid = true;
1524
- value = this._strokeStyleStack[this._stackIndex] = result;
1525
- }
1526
- } else if (value instanceof CanvasGradient || value instanceof _CanvasPattern["default"]) {
1527
- valid = true;
1528
- this._strokeStyleStack[this._stackIndex] = value;
1529
- }
1419
+ }
1530
1420
 
1531
- if (valid) {
1532
- var event = (0, _createCanvasEvent["default"])('strokeStyle', getTransformSlice(this), {
1533
- value: value
1534
- });
1421
+ get strokeStyle() {
1422
+ return this._strokeStyleStack[this._stackIndex];
1423
+ }
1535
1424
 
1536
- this._events.push(event);
1537
- }
1538
- },
1539
- get: function get() {
1540
- return this._strokeStyleStack[this._stackIndex];
1425
+ strokeText(text, x, y, maxWidth) {
1426
+ if (arguments.length < 3) throw new TypeError('Failed to execute \'strokeText\' on \'' + this.constructor.name + '\': 3 arguments required, but only ' + arguments.length + ' present.');
1427
+ const textResult = String(text);
1428
+ const xResult = Number(x);
1429
+ const yResult = Number(y);
1430
+ const maxWidthResult = Number(maxWidth);
1431
+ if (arguments.length === 3 && !Number.isFinite(xResult + yResult)) return;
1432
+ if (arguments.length > 3 && !Number.isFinite(xResult + yResult + maxWidthResult)) return;
1433
+ const event = (0, _createCanvasEvent.default)('strokeText', getTransformSlice(this), {
1434
+ text: textResult,
1435
+ x: xResult,
1436
+ y: yResult,
1437
+ maxWidth: arguments.length === 3 ? null : maxWidthResult
1438
+ });
1439
+
1440
+ this._events.push(event);
1441
+
1442
+ this._drawCalls.push(event);
1443
+ }
1444
+
1445
+ set textAlign(value) {
1446
+ if (value === 'left' || value === 'right' || value === 'center' || value === 'start' || value === 'end') {
1447
+ this._textAlignStack[this._stackIndex] = value;
1448
+ const event = (0, _createCanvasEvent.default)('textAlign', getTransformSlice(this), {
1449
+ value
1450
+ });
1451
+
1452
+ this._events.push(event);
1541
1453
  }
1542
- }, {
1543
- key: "textAlign",
1544
- set: function set(value) {
1545
- if (value === 'left' || value === 'right' || value === 'center' || value === 'start' || value === 'end') {
1546
- this._textAlignStack[this._stackIndex] = value;
1547
- var event = (0, _createCanvasEvent["default"])('textAlign', getTransformSlice(this), {
1548
- value: value
1549
- });
1454
+ }
1550
1455
 
1551
- this._events.push(event);
1552
- }
1553
- },
1554
- get: function get() {
1555
- return this._textAlignStack[this._stackIndex];
1456
+ get textAlign() {
1457
+ return this._textAlignStack[this._stackIndex];
1458
+ }
1459
+
1460
+ set textBaseline(value) {
1461
+ if (value === 'top' || value === 'hanging' || value === 'middle' || value === 'alphabetic' || value === 'ideographic' || value === 'bottom') {
1462
+ this._textBaselineStack[this._stackIndex] = value;
1463
+ const event = (0, _createCanvasEvent.default)('textBaseline', getTransformSlice(this), {
1464
+ value
1465
+ });
1466
+
1467
+ this._events.push(event);
1556
1468
  }
1557
- }, {
1558
- key: "textBaseline",
1559
- set: function set(value) {
1560
- if (value === 'top' || value === 'hanging' || value === 'middle' || value === 'alphabetic' || value === 'ideographic' || value === 'bottom') {
1561
- this._textBaselineStack[this._stackIndex] = value;
1562
- var event = (0, _createCanvasEvent["default"])('textBaseline', getTransformSlice(this), {
1563
- value: value
1564
- });
1469
+ }
1565
1470
 
1566
- this._events.push(event);
1567
- }
1568
- },
1569
- get: function get() {
1570
- return this._textBaselineStack[this._stackIndex];
1471
+ get textBaseline() {
1472
+ return this._textBaselineStack[this._stackIndex];
1473
+ }
1474
+
1475
+ transform(a, b, c, d, e, f) {
1476
+ if (arguments.length < 6) throw new TypeError('Failed to execute \'transform\' on \'' + this.constructor.name + '\': 6 arguments required, but only ' + arguments.length + ' present.');
1477
+ a = Number(a);
1478
+ b = Number(b);
1479
+ c = Number(c);
1480
+ d = Number(d);
1481
+ e = Number(e);
1482
+ f = Number(f);
1483
+ if (!Number.isFinite(a + b + c + d + e + f)) return;
1484
+ const sa = this._transformStack[this._stackIndex][0];
1485
+ const sb = this._transformStack[this._stackIndex][1];
1486
+ const sc = this._transformStack[this._stackIndex][2];
1487
+ const sd = this._transformStack[this._stackIndex][3];
1488
+ const se = this._transformStack[this._stackIndex][4];
1489
+ const sf = this._transformStack[this._stackIndex][5];
1490
+ this._transformStack[this._stackIndex][0] = sa * a + sc * b;
1491
+ this._transformStack[this._stackIndex][1] = sb * a + sd * b;
1492
+ this._transformStack[this._stackIndex][2] = sa * c + sc * d;
1493
+ this._transformStack[this._stackIndex][3] = sb * c + sd * d;
1494
+ this._transformStack[this._stackIndex][4] = sa * e + sc * f + se;
1495
+ this._transformStack[this._stackIndex][5] = sb * e + sd * f + sf;
1496
+ const event = (0, _createCanvasEvent.default)('transform', getTransformSlice(this), {
1497
+ a,
1498
+ b,
1499
+ c,
1500
+ d,
1501
+ e,
1502
+ f
1503
+ });
1504
+
1505
+ this._events.push(event);
1506
+ }
1507
+
1508
+ translate(x, y) {
1509
+ if (arguments.length < 2) throw new TypeError('Failed to execute \'translate\' on \'' + this.constructor.name + '\': 2 arguments required, but only ' + arguments.length + ' present.');
1510
+ const xResult = Number(x);
1511
+ const yResult = Number(y);
1512
+ const a = this._transformStack[this._stackIndex][0];
1513
+ const b = this._transformStack[this._stackIndex][1];
1514
+ const c = this._transformStack[this._stackIndex][2];
1515
+ const d = this._transformStack[this._stackIndex][3];
1516
+
1517
+ if (Number.isFinite(xResult + yResult)) {
1518
+ this._transformStack[this._stackIndex][4] += a * xResult + c * yResult;
1519
+ this._transformStack[this._stackIndex][5] += b * xResult + d * yResult;
1520
+ const event = (0, _createCanvasEvent.default)('translate', getTransformSlice(this), {
1521
+ x: xResult,
1522
+ y: yResult
1523
+ });
1524
+
1525
+ this._events.push(event);
1571
1526
  }
1572
- }]);
1527
+ }
1573
1528
 
1574
- return CanvasRenderingContext2D;
1575
- }();
1529
+ }
1576
1530
 
1577
- exports["default"] = CanvasRenderingContext2D;
1531
+ exports.default = CanvasRenderingContext2D;