jest-canvas-mock 2.1.0 → 2.3.0

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