jest-canvas-mock 2.2.0 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +474 -463
- package/README.md +185 -169
- package/lib/classes/CanvasGradient.js +6 -9
- package/lib/classes/CanvasPattern.js +1 -1
- package/lib/classes/CanvasRenderingContext2D.js +173 -147
- package/lib/classes/DOMMatrix.js +9 -1
- package/lib/classes/ImageData.js +1 -1
- package/lib/classes/Path2D.js +2 -2
- package/lib/index.js +4 -4
- package/lib/mock/createCanvasEvent.js +14 -14
- package/lib/mock/createImageBitmap.js +5 -5
- package/lib/mock/prototype.js +27 -27
- package/lib/window.js +7 -7
- package/package.json +77 -70
- package/types/index.d.ts +94 -86
- package/.github/FUNDING.yml +0 -12
|
@@ -9,37 +9,19 @@ 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
|
-
|
|
21
|
-
|
|
22
|
-
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
23
|
-
|
|
24
|
-
function parseCSSColor(value) {
|
|
25
|
-
const result = (0, _parseColor.default)(value);
|
|
18
|
+
var _Path2D = _interopRequireDefault(require("./Path2D"));
|
|
26
19
|
|
|
27
|
-
|
|
28
|
-
return 'rgba(' + result.rgba.join(', ') + ')';
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
if (result.hex) {
|
|
32
|
-
const hex = result.hex; // shorthand #ABC
|
|
20
|
+
var _mooColor = require("moo-color");
|
|
33
21
|
|
|
34
|
-
|
|
35
|
-
return '#' + hex[1] + hex[3] + hex[5];
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
return result.hex;
|
|
39
|
-
}
|
|
22
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
40
23
|
|
|
41
|
-
|
|
42
|
-
}
|
|
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; }
|
|
43
25
|
|
|
44
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'];
|
|
45
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'];
|
|
@@ -47,58 +29,76 @@ const compositeOperations = ['source-over', 'source-in', 'source-out', 'source-a
|
|
|
47
29
|
function getTransformSlice(ctx) {
|
|
48
30
|
return ctx._transformStack[ctx._stackIndex].slice();
|
|
49
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
|
+
|
|
36
|
+
|
|
37
|
+
function serializeColor(value) {
|
|
38
|
+
return value.getAlpha() === 1 ? value.toHex() : value.toRgb();
|
|
39
|
+
}
|
|
50
40
|
|
|
51
41
|
class CanvasRenderingContext2D {
|
|
52
|
-
/**
|
|
53
|
-
* Every time a function call would result in a drawing operation, it should be added to this array.
|
|
54
|
-
* This goes for only draw call functions.
|
|
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.
|
|
55
45
|
*/
|
|
56
46
|
__getDrawCalls() {
|
|
57
47
|
return this._drawCalls.slice();
|
|
58
48
|
}
|
|
59
|
-
/**
|
|
60
|
-
* Clear the list of draw calls
|
|
49
|
+
/**
|
|
50
|
+
* Clear the list of draw calls
|
|
61
51
|
*/
|
|
62
52
|
|
|
63
53
|
|
|
64
54
|
__clearDrawCalls() {
|
|
65
55
|
this._drawCalls = [];
|
|
66
56
|
}
|
|
67
|
-
/**
|
|
68
|
-
* Every time a function call results in something that would have modified the state of the context,
|
|
69
|
-
* an event is added to this array. This goes for every property set, and draw call.
|
|
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.
|
|
70
60
|
*/
|
|
71
61
|
|
|
72
62
|
|
|
73
63
|
__getEvents() {
|
|
74
64
|
return this._events.slice();
|
|
75
65
|
}
|
|
76
|
-
/**
|
|
77
|
-
* Clear the list of events
|
|
66
|
+
/**
|
|
67
|
+
* Clear the list of events
|
|
78
68
|
*/
|
|
79
69
|
|
|
80
70
|
|
|
81
71
|
__clearEvents() {
|
|
82
72
|
this._events = [];
|
|
83
73
|
}
|
|
84
|
-
/**
|
|
85
|
-
* This array keeps track of the current path, so that fill and stroke operations can store the
|
|
86
|
-
* path.
|
|
74
|
+
/**
|
|
75
|
+
* This array keeps track of the current path, so that fill and stroke operations can store the
|
|
76
|
+
* path.
|
|
87
77
|
*/
|
|
88
78
|
|
|
89
79
|
|
|
90
80
|
__getPath() {
|
|
91
81
|
return this._path.slice();
|
|
92
82
|
}
|
|
93
|
-
/**
|
|
94
|
-
* Clear the path and reset it to a single beginPath event.
|
|
83
|
+
/**
|
|
84
|
+
* Clear the path and reset it to a single beginPath event.
|
|
95
85
|
*/
|
|
96
86
|
|
|
97
87
|
|
|
98
88
|
__clearPath() {
|
|
99
|
-
const event = (0, _createCanvasEvent.default)('beginPath', getTransformSlice(this), {});
|
|
89
|
+
const event = (0, _createCanvasEvent.default)('beginPath', getTransformSlice(this), {}); // The clipping path should start after the initial beginPath instruction
|
|
90
|
+
|
|
91
|
+
this._clipIndex = 1;
|
|
100
92
|
this._path = [event];
|
|
101
93
|
}
|
|
94
|
+
/**
|
|
95
|
+
* Get the current clipping region.
|
|
96
|
+
*/
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
__getClippingRegion() {
|
|
100
|
+
return this._clipStack[this._stackIndex];
|
|
101
|
+
}
|
|
102
102
|
|
|
103
103
|
constructor(canvas) {
|
|
104
104
|
_defineProperty(this, "_drawCalls", []);
|
|
@@ -109,7 +109,7 @@ class CanvasRenderingContext2D {
|
|
|
109
109
|
|
|
110
110
|
_defineProperty(this, "_directionStack", ['inherit']);
|
|
111
111
|
|
|
112
|
-
_defineProperty(this, "_fillStyleStack", ['#
|
|
112
|
+
_defineProperty(this, "_fillStyleStack", ['#000000']);
|
|
113
113
|
|
|
114
114
|
_defineProperty(this, "_filterStack", ['none']);
|
|
115
115
|
|
|
@@ -145,7 +145,7 @@ class CanvasRenderingContext2D {
|
|
|
145
145
|
|
|
146
146
|
_defineProperty(this, "_stackIndex", 0);
|
|
147
147
|
|
|
148
|
-
_defineProperty(this, "_strokeStyleStack", ['#
|
|
148
|
+
_defineProperty(this, "_strokeStyleStack", ['#000000']);
|
|
149
149
|
|
|
150
150
|
_defineProperty(this, "_textAlignStack", ['start']);
|
|
151
151
|
|
|
@@ -153,6 +153,10 @@ class CanvasRenderingContext2D {
|
|
|
153
153
|
|
|
154
154
|
_defineProperty(this, "_transformStack", [[1, 0, 0, 1, 0, 0]]);
|
|
155
155
|
|
|
156
|
+
_defineProperty(this, "_clipStack", [[]]);
|
|
157
|
+
|
|
158
|
+
_defineProperty(this, "_clipIndex", 1);
|
|
159
|
+
|
|
156
160
|
testFuncs.forEach(key => {
|
|
157
161
|
this[key] = jest.fn(CanvasRenderingContext2D.prototype[key].bind(this));
|
|
158
162
|
});
|
|
@@ -170,8 +174,8 @@ class CanvasRenderingContext2D {
|
|
|
170
174
|
label,
|
|
171
175
|
role
|
|
172
176
|
} = options;
|
|
173
|
-
if (!path && !id) throw new DOMException('ConstraintError',
|
|
174
|
-
if (fillRule && fillRule !== 'evenodd' && fillRule !== 'nonzero') throw new TypeError(
|
|
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.");
|
|
175
179
|
|
|
176
180
|
this._events.push((0, _createCanvasEvent.default)('addHitRegion', getTransformSlice(this), {
|
|
177
181
|
path,
|
|
@@ -186,7 +190,7 @@ class CanvasRenderingContext2D {
|
|
|
186
190
|
}
|
|
187
191
|
|
|
188
192
|
arc(x, y, radius, startAngle, endAngle, anticlockwise = false) {
|
|
189
|
-
if (arguments.length < 5) throw new TypeError(
|
|
193
|
+
if (arguments.length < 5) throw new TypeError("Failed to execute 'arc' on '" + this.constructor.name + "': 5 arguments required, but only " + arguments.length + ' present.');
|
|
190
194
|
const xResult = Number(x);
|
|
191
195
|
const yResult = Number(y);
|
|
192
196
|
const radiusResult = Number(radius);
|
|
@@ -195,7 +199,7 @@ class CanvasRenderingContext2D {
|
|
|
195
199
|
const anticlockwiseResult = Boolean(anticlockwise); // quick is finite check
|
|
196
200
|
|
|
197
201
|
if (!Number.isFinite(xResult + yResult + radiusResult + startAngleResult + endAngleResult)) return;
|
|
198
|
-
if (Number(radius) < 0) throw new DOMException('IndexSizeError',
|
|
202
|
+
if (Number(radius) < 0) throw new DOMException('IndexSizeError', "Failed to execute 'arc' on '" + this.constructor.name + "': The radius provided (" + radius + ') is negative.');
|
|
199
203
|
const event = (0, _createCanvasEvent.default)('arc', getTransformSlice(this), {
|
|
200
204
|
x: xResult,
|
|
201
205
|
y: yResult,
|
|
@@ -211,14 +215,14 @@ class CanvasRenderingContext2D {
|
|
|
211
215
|
}
|
|
212
216
|
|
|
213
217
|
arcTo(cpx1, cpy1, cpx2, cpy2, radius) {
|
|
214
|
-
if (arguments.length < 5) throw new DOMException('IndexSizeError',
|
|
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.');
|
|
215
219
|
const cpx1Result = Number(cpx1);
|
|
216
220
|
const cpy1Result = Number(cpy1);
|
|
217
221
|
const cpx2Result = Number(cpx2);
|
|
218
222
|
const cpy2Result = Number(cpy2);
|
|
219
223
|
const radiusResult = Number(radius);
|
|
220
224
|
if (!Number.isFinite(cpx1Result + cpx2Result + cpy1Result + cpy2Result + radiusResult)) return;
|
|
221
|
-
if (radiusResult < 0) throw new TypeError(
|
|
225
|
+
if (radiusResult < 0) throw new TypeError("Failed to execute 'arcTo' on '" + this.constructor.name + "': The radius provided (" + radius + ') is negative.');
|
|
222
226
|
const event = (0, _createCanvasEvent.default)('arcTo', getTransformSlice(this), {
|
|
223
227
|
cpx1: cpx1Result,
|
|
224
228
|
cpy1: cpy1Result,
|
|
@@ -240,7 +244,7 @@ class CanvasRenderingContext2D {
|
|
|
240
244
|
}
|
|
241
245
|
|
|
242
246
|
bezierCurveTo(cpx1, cpy1, cpx2, cpy2, x, y) {
|
|
243
|
-
if (arguments.length < 6) throw new TypeError(
|
|
247
|
+
if (arguments.length < 6) throw new TypeError("Failed to execute 'bezierCurveTo' on '" + this.constructor.name + "': 6 arguments required, but only " + arguments.length + ' present.');
|
|
244
248
|
const cpx1Result = Number(cpx1);
|
|
245
249
|
const cpy1Result = Number(cpy1);
|
|
246
250
|
const cpx2Result = Number(cpx2);
|
|
@@ -273,7 +277,7 @@ class CanvasRenderingContext2D {
|
|
|
273
277
|
}
|
|
274
278
|
|
|
275
279
|
clearRect(x, y, width, height) {
|
|
276
|
-
if (arguments.length < 4) throw new TypeError(
|
|
280
|
+
if (arguments.length < 4) throw new TypeError("Failed to execute 'clearRect' on '" + this.constructor.name + "': 4 arguments required, but only " + arguments.length + ' present.');
|
|
277
281
|
const xResult = Number(x);
|
|
278
282
|
const yResult = Number(y);
|
|
279
283
|
const widthResult = Number(width);
|
|
@@ -290,22 +294,34 @@ class CanvasRenderingContext2D {
|
|
|
290
294
|
|
|
291
295
|
this._drawCalls.push(event);
|
|
292
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
|
+
|
|
293
302
|
|
|
294
303
|
clip(path, fillRule) {
|
|
304
|
+
let clipPath;
|
|
305
|
+
|
|
295
306
|
if (arguments.length === 0) {
|
|
296
307
|
fillRule = 'nonzero';
|
|
297
308
|
path = this._path.slice();
|
|
309
|
+
clipPath = path.slice(this._clipIndex);
|
|
310
|
+
this._clipIndex = path.length;
|
|
298
311
|
} else {
|
|
299
312
|
if (arguments.length === 1) fillRule = 'nonzero';
|
|
300
313
|
|
|
301
|
-
if (path instanceof
|
|
314
|
+
if (path instanceof _Path2D.default) {
|
|
302
315
|
fillRule = String(fillRule);
|
|
303
|
-
if (fillRule !== 'nonzero' && fillRule !== 'evenodd') throw new TypeError(
|
|
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.");
|
|
304
317
|
path = path._path.slice();
|
|
318
|
+
clipPath = path;
|
|
305
319
|
} else {
|
|
306
320
|
fillRule = String(path);
|
|
307
|
-
if (fillRule !== 'nonzero' && fillRule !== 'evenodd') throw new TypeError(
|
|
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.");
|
|
308
322
|
path = this._path.slice();
|
|
323
|
+
clipPath = path.slice(this._clipIndex);
|
|
324
|
+
this._clipIndex = path.length;
|
|
309
325
|
}
|
|
310
326
|
}
|
|
311
327
|
|
|
@@ -317,6 +333,9 @@ class CanvasRenderingContext2D {
|
|
|
317
333
|
this._path.push(event);
|
|
318
334
|
|
|
319
335
|
this._events.push(event);
|
|
336
|
+
|
|
337
|
+
const currentClip = this._clipStack[this._stackIndex];
|
|
338
|
+
this._clipStack[this._stackIndex] = currentClip.concat(clipPath);
|
|
320
339
|
}
|
|
321
340
|
|
|
322
341
|
closePath() {
|
|
@@ -328,8 +347,8 @@ class CanvasRenderingContext2D {
|
|
|
328
347
|
}
|
|
329
348
|
|
|
330
349
|
createImageData(width, height) {
|
|
331
|
-
if (arguments.length < 1) throw new TypeError(
|
|
332
|
-
if (!(width instanceof ImageData)) throw new TypeError(
|
|
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'.");
|
|
333
352
|
let result = new ImageData(width.width, width.height);
|
|
334
353
|
result.data.set(width.data);
|
|
335
354
|
const event = (0, _createCanvasEvent.default)('createImageData', getTransformSlice(this), {
|
|
@@ -343,8 +362,8 @@ class CanvasRenderingContext2D {
|
|
|
343
362
|
} else {
|
|
344
363
|
width = Math.abs(Number(width));
|
|
345
364
|
height = Math.abs(Number(height));
|
|
346
|
-
if (!Number.isFinite(width) || width === 0) throw new TypeError(
|
|
347
|
-
if (!Number.isFinite(height) || height === 0) throw new TypeError(
|
|
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.");
|
|
348
367
|
const event = (0, _createCanvasEvent.default)('createImageData', getTransformSlice(this), {
|
|
349
368
|
width,
|
|
350
369
|
height
|
|
@@ -357,12 +376,12 @@ class CanvasRenderingContext2D {
|
|
|
357
376
|
}
|
|
358
377
|
|
|
359
378
|
createLinearGradient(x0, y0, x1, y1) {
|
|
360
|
-
if (arguments.length < 4) throw new TypeError(
|
|
379
|
+
if (arguments.length < 4) throw new TypeError("Failed to execute 'createLinearGradient' on '" + this.constructor.name + "': 4 arguments required, but only " + arguments.length + ' present.');
|
|
361
380
|
const x0Result = Number(x0);
|
|
362
381
|
const y0Result = Number(y0);
|
|
363
382
|
const x1Result = Number(x1);
|
|
364
383
|
const y1Result = Number(y1);
|
|
365
|
-
if (!Number.isFinite(x0Result + y0Result + x1Result + y1Result)) throw new TypeError(
|
|
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.");
|
|
366
385
|
const event = (0, _createCanvasEvent.default)('createLinearGradient', getTransformSlice(this), {
|
|
367
386
|
x0: x0Result,
|
|
368
387
|
y0: y0Result,
|
|
@@ -376,7 +395,7 @@ class CanvasRenderingContext2D {
|
|
|
376
395
|
}
|
|
377
396
|
|
|
378
397
|
createPattern(image, type) {
|
|
379
|
-
if (arguments.length === 1) throw new TypeError(
|
|
398
|
+
if (arguments.length === 1) throw new TypeError("Failed to execute 'createPattern' on '" + this.constructor.name + "': 2 arguments required, but only 1 present.");
|
|
380
399
|
if (type === null) type = 'repeat';
|
|
381
400
|
if (type === '') type = 'repeat';
|
|
382
401
|
|
|
@@ -387,7 +406,7 @@ class CanvasRenderingContext2D {
|
|
|
387
406
|
});
|
|
388
407
|
|
|
389
408
|
if (image instanceof ImageBitmap) {
|
|
390
|
-
if (image._closed) throw new DOMException('InvalidStateError',
|
|
409
|
+
if (image._closed) throw new DOMException('InvalidStateError', "Failed to execute 'createPattern' on 'CanvasRenderingContext2D': The image source is detached.");
|
|
391
410
|
|
|
392
411
|
this._events.push(event);
|
|
393
412
|
|
|
@@ -412,23 +431,23 @@ class CanvasRenderingContext2D {
|
|
|
412
431
|
return new _CanvasPattern.default();
|
|
413
432
|
}
|
|
414
433
|
} else {
|
|
415
|
-
throw new TypeError(
|
|
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'.");
|
|
416
435
|
}
|
|
417
436
|
|
|
418
|
-
throw new TypeError(
|
|
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)'");
|
|
419
438
|
}
|
|
420
439
|
|
|
421
440
|
createRadialGradient(x0, y0, r0, x1, y1, r1) {
|
|
422
|
-
if (arguments.length < 6) throw new TypeError(
|
|
441
|
+
if (arguments.length < 6) throw new TypeError("Failed to execute 'createRadialGradient' on '" + this.constructor.name + "': 6 arguments required, but only " + arguments.length + ' present.');
|
|
423
442
|
const x0Result = Number(x0);
|
|
424
443
|
const y0Result = Number(y0);
|
|
425
444
|
const r0Result = Number(r0);
|
|
426
445
|
const x1Result = Number(x1);
|
|
427
446
|
const y1Result = Number(y1);
|
|
428
447
|
const r1Result = Number(r1);
|
|
429
|
-
if (!Number.isFinite(x0Result + y0Result + r0Result + x1Result + y1Result + r1Result)) throw new TypeError(
|
|
430
|
-
if (r0Result < 0) throw new DOMException('IndexSizeError',
|
|
431
|
-
if (r1Result < 0) throw new DOMException('IndexSizeError',
|
|
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.");
|
|
432
451
|
const event = (0, _createCanvasEvent.default)('createRadialGradient', getTransformSlice(this), {
|
|
433
452
|
x0: x0Result,
|
|
434
453
|
y0: y0Result,
|
|
@@ -484,15 +503,15 @@ class CanvasRenderingContext2D {
|
|
|
484
503
|
}
|
|
485
504
|
|
|
486
505
|
drawFocusIfNeeded(path, element) {
|
|
487
|
-
if (arguments.length === 0) throw new TypeError(
|
|
488
|
-
if (arguments.length === 2 && !(path instanceof
|
|
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'.");
|
|
489
508
|
|
|
490
509
|
if (arguments.length === 1) {
|
|
491
510
|
element = path;
|
|
492
511
|
path = null;
|
|
493
512
|
}
|
|
494
513
|
|
|
495
|
-
if (!(element instanceof Element)) throw new TypeError(
|
|
514
|
+
if (!(element instanceof Element)) throw new TypeError("Failed to execute 'drawFocusIfNeeded' on '" + this.constructor.name + "': parameter " + arguments.length + " is not of type 'Element'.");
|
|
496
515
|
const event = (0, _createCanvasEvent.default)('drawFocusIfNeeded', getTransformSlice(this), {
|
|
497
516
|
path: path ? path._path : null,
|
|
498
517
|
element
|
|
@@ -502,20 +521,19 @@ class CanvasRenderingContext2D {
|
|
|
502
521
|
}
|
|
503
522
|
|
|
504
523
|
drawImage(img, sx, sy, sWidth, sHeight, dx, dy, dWidth, dHeight) {
|
|
505
|
-
if (arguments.length < 3) throw new TypeError(
|
|
506
|
-
if (arguments.length === 4 || arguments.length > 5 && arguments.length < 9) throw new TypeError(
|
|
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.");
|
|
507
526
|
let valid = false;
|
|
508
527
|
if (img instanceof HTMLImageElement) valid = true;
|
|
509
|
-
;
|
|
510
528
|
|
|
511
529
|
if (img instanceof ImageBitmap) {
|
|
512
|
-
if (img._closed) throw new DOMException('InvalidStateError',
|
|
530
|
+
if (img._closed) throw new DOMException('InvalidStateError', "DOMException: Failed to execute 'drawImage' on 'CanvasRenderingContext2D': The image source is detached.");
|
|
513
531
|
valid = true;
|
|
514
532
|
}
|
|
515
533
|
|
|
516
534
|
if (img instanceof HTMLVideoElement) valid = true;
|
|
517
535
|
if (img instanceof HTMLCanvasElement) valid = true;
|
|
518
|
-
if (!valid) throw new TypeError(
|
|
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)'");
|
|
519
537
|
const sxResult = Number(sx);
|
|
520
538
|
const syResult = Number(sy);
|
|
521
539
|
const sWidthResult = Number(sWidth);
|
|
@@ -575,7 +593,7 @@ class CanvasRenderingContext2D {
|
|
|
575
593
|
}
|
|
576
594
|
|
|
577
595
|
ellipse(x, y, radiusX, radiusY, rotation, startAngle, endAngle, anticlockwise = false) {
|
|
578
|
-
if (arguments.length < 7) throw new TypeError(
|
|
596
|
+
if (arguments.length < 7) throw new TypeError("Failed to execute 'ellipse' on '" + this.constructor.name + "': 6 arguments required, but only " + arguments.length + ' present.');
|
|
579
597
|
const xResult = Number(x);
|
|
580
598
|
const yResult = Number(y);
|
|
581
599
|
const radiusXResult = Number(radiusX);
|
|
@@ -585,8 +603,8 @@ class CanvasRenderingContext2D {
|
|
|
585
603
|
const endAngleResult = Number(endAngle);
|
|
586
604
|
const anticlockwiseResult = Boolean(anticlockwise);
|
|
587
605
|
if (!Number.isFinite(xResult + yResult + radiusXResult + radiusYResult + rotationResult + startAngleResult + endAngleResult)) return;
|
|
588
|
-
if (Number(radiusX) < 0) throw new DOMException('IndexSizeError',
|
|
589
|
-
if (Number(radiusY) < 0) throw new DOMException('IndexSizeError',
|
|
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.');
|
|
590
608
|
const event = (0, _createCanvasEvent.default)('ellipse', getTransformSlice(this), {
|
|
591
609
|
x: xResult,
|
|
592
610
|
y: yResult,
|
|
@@ -610,13 +628,13 @@ class CanvasRenderingContext2D {
|
|
|
610
628
|
} else {
|
|
611
629
|
if (arguments.length === 1) fillRule = 'nonzero';
|
|
612
630
|
|
|
613
|
-
if (path instanceof
|
|
631
|
+
if (path instanceof _Path2D.default) {
|
|
614
632
|
fillRule = String(fillRule);
|
|
615
|
-
if (fillRule !== 'nonzero' && fillRule !== 'evenodd') throw new TypeError(
|
|
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.");
|
|
616
634
|
path = path._path.slice();
|
|
617
635
|
} else {
|
|
618
636
|
fillRule = String(path);
|
|
619
|
-
if (fillRule !== 'nonzero' && fillRule !== 'evenodd') throw new TypeError(
|
|
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.");
|
|
620
638
|
path = this._path.slice();
|
|
621
639
|
}
|
|
622
640
|
}
|
|
@@ -632,7 +650,7 @@ class CanvasRenderingContext2D {
|
|
|
632
650
|
}
|
|
633
651
|
|
|
634
652
|
fillRect(x, y, width, height) {
|
|
635
|
-
if (arguments.length < 4) throw new TypeError(
|
|
653
|
+
if (arguments.length < 4) throw new TypeError("Failed to execute 'fillRect' on '" + this.constructor.name + "': 4 arguments required, but only " + arguments.length + ' present.');
|
|
636
654
|
const xResult = Number(x);
|
|
637
655
|
const yResult = Number(y);
|
|
638
656
|
const widthResult = Number(width);
|
|
@@ -654,11 +672,12 @@ class CanvasRenderingContext2D {
|
|
|
654
672
|
let valid = false;
|
|
655
673
|
|
|
656
674
|
if (typeof value === 'string') {
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
if (result) {
|
|
675
|
+
try {
|
|
676
|
+
const result = new _mooColor.MooColor(value);
|
|
660
677
|
valid = true;
|
|
661
|
-
value = this._fillStyleStack[this._stackIndex] = result;
|
|
678
|
+
value = this._fillStyleStack[this._stackIndex] = serializeColor(result);
|
|
679
|
+
} catch (e) {
|
|
680
|
+
return;
|
|
662
681
|
}
|
|
663
682
|
} else if (value instanceof CanvasGradient || value instanceof _CanvasPattern.default) {
|
|
664
683
|
valid = true;
|
|
@@ -679,7 +698,7 @@ class CanvasRenderingContext2D {
|
|
|
679
698
|
}
|
|
680
699
|
|
|
681
700
|
fillText(text, x, y, maxWidth) {
|
|
682
|
-
if (arguments.length < 3) throw new TypeError(
|
|
701
|
+
if (arguments.length < 3) throw new TypeError("Failed to execute 'fillText' on '" + this.constructor.name + "': 3 arguments required, but only " + arguments.length + ' present.');
|
|
683
702
|
const textResult = String(text);
|
|
684
703
|
const xResult = Number(x);
|
|
685
704
|
const yResult = Number(y);
|
|
@@ -803,9 +822,9 @@ class CanvasRenderingContext2D {
|
|
|
803
822
|
}
|
|
804
823
|
|
|
805
824
|
isPointInPath(path, x, y, fillRule = 'nonzero') {
|
|
806
|
-
if (arguments.length < 2) throw new TypeError(
|
|
825
|
+
if (arguments.length < 2) throw new TypeError("Failed to execute 'isPointInPath' on '" + this.constructor.name + "': 2 arguments required, but only " + arguments.length + ' present.');
|
|
807
826
|
|
|
808
|
-
if (!(path instanceof
|
|
827
|
+
if (!(path instanceof _Path2D.default)) {
|
|
809
828
|
if (arguments.length > 2) {
|
|
810
829
|
fillRule = y;
|
|
811
830
|
}
|
|
@@ -814,12 +833,12 @@ class CanvasRenderingContext2D {
|
|
|
814
833
|
x = path;
|
|
815
834
|
}
|
|
816
835
|
|
|
817
|
-
if (fillRule !== 'nonzero' && fillRule !== 'evenodd') throw new TypeError(
|
|
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.");
|
|
818
837
|
const event = (0, _createCanvasEvent.default)('isPointInPath', getTransformSlice(this), {
|
|
819
838
|
x: Number(x),
|
|
820
839
|
y: Number(y),
|
|
821
840
|
fillRule,
|
|
822
|
-
path: path instanceof
|
|
841
|
+
path: path instanceof _Path2D.default ? path._path.slice() : this._path.slice()
|
|
823
842
|
});
|
|
824
843
|
|
|
825
844
|
this._events.push(event);
|
|
@@ -828,9 +847,9 @@ class CanvasRenderingContext2D {
|
|
|
828
847
|
}
|
|
829
848
|
|
|
830
849
|
isPointInStroke(path, x, y) {
|
|
831
|
-
if (arguments.length < 2) throw new TypeError(
|
|
850
|
+
if (arguments.length < 2) throw new TypeError("Failed to execute 'isPointInStroke' on '" + this.constructor.name + "': 2 arguments required, but only " + arguments.length + ' present.');
|
|
832
851
|
|
|
833
|
-
if (!(path instanceof
|
|
852
|
+
if (!(path instanceof _Path2D.default)) {
|
|
834
853
|
y = x;
|
|
835
854
|
x = path;
|
|
836
855
|
}
|
|
@@ -838,7 +857,7 @@ class CanvasRenderingContext2D {
|
|
|
838
857
|
const event = (0, _createCanvasEvent.default)('isPointInPath', getTransformSlice(this), {
|
|
839
858
|
x: Number(x),
|
|
840
859
|
y: Number(y),
|
|
841
|
-
path: path instanceof
|
|
860
|
+
path: path instanceof _Path2D.default ? path._path.slice() : this._path.slice()
|
|
842
861
|
});
|
|
843
862
|
|
|
844
863
|
this._events.push(event);
|
|
@@ -894,7 +913,7 @@ class CanvasRenderingContext2D {
|
|
|
894
913
|
}
|
|
895
914
|
|
|
896
915
|
lineTo(x, y) {
|
|
897
|
-
if (arguments.length < 2) throw new TypeError(
|
|
916
|
+
if (arguments.length < 2) throw new TypeError("Failed to execute 'lineTo' on '" + this.constructor.name + "': 2 arguments required, but only " + arguments.length + ' present.');
|
|
898
917
|
const xResult = Number(x);
|
|
899
918
|
const yResult = Number(y);
|
|
900
919
|
if (!Number.isFinite(xResult + yResult)) return;
|
|
@@ -926,7 +945,7 @@ class CanvasRenderingContext2D {
|
|
|
926
945
|
}
|
|
927
946
|
|
|
928
947
|
measureText(text) {
|
|
929
|
-
if (arguments.length < 1) throw new TypeError(
|
|
948
|
+
if (arguments.length < 1) throw new TypeError("Failed to execute 'measureText' on '" + this.constructor.name + "': 1 argument required, but only 0 present.");
|
|
930
949
|
text = text == null ? '' : text;
|
|
931
950
|
text = text.toString();
|
|
932
951
|
const event = (0, _createCanvasEvent.default)('measureText', getTransformSlice(this), {
|
|
@@ -956,7 +975,7 @@ class CanvasRenderingContext2D {
|
|
|
956
975
|
}
|
|
957
976
|
|
|
958
977
|
moveTo(x, y) {
|
|
959
|
-
if (arguments.length < 2) throw new TypeError(
|
|
978
|
+
if (arguments.length < 2) throw new TypeError("Failed to execute 'moveTo' on '" + this.constructor.name + "': 2 arguments required, but only " + arguments.length + ' present.');
|
|
960
979
|
const xResult = Number(x);
|
|
961
980
|
const yResult = Number(y);
|
|
962
981
|
if (!Number.isFinite(x + y)) return;
|
|
@@ -971,9 +990,9 @@ class CanvasRenderingContext2D {
|
|
|
971
990
|
}
|
|
972
991
|
|
|
973
992
|
putImageData(data, x, y, dirtyX, dirtyY, dirtyWidth, dirtyHeight) {
|
|
974
|
-
if (arguments.length < 3) throw new TypeError(
|
|
975
|
-
if (arguments.length > 3 && arguments.length < 7) throw new TypeError(
|
|
976
|
-
if (!(data instanceof ImageData)) throw new TypeError(
|
|
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'.");
|
|
977
996
|
const xResult = Number(x);
|
|
978
997
|
const yResult = Number(y);
|
|
979
998
|
const dirtyXResult = Number(dirtyX);
|
|
@@ -1000,7 +1019,7 @@ class CanvasRenderingContext2D {
|
|
|
1000
1019
|
}
|
|
1001
1020
|
|
|
1002
1021
|
quadraticCurveTo(cpx, cpy, x, y) {
|
|
1003
|
-
if (arguments.length < 4) throw new TypeError(
|
|
1022
|
+
if (arguments.length < 4) throw new TypeError("Failed to execute 'quadraticCurveTo' on '" + this.constructor.name + "': 4 arguments required, but only " + arguments.length + ' present.');
|
|
1004
1023
|
const cpxResult = Number(cpx);
|
|
1005
1024
|
const cpyResult = Number(cpy);
|
|
1006
1025
|
const xResult = Number(x);
|
|
@@ -1017,7 +1036,7 @@ class CanvasRenderingContext2D {
|
|
|
1017
1036
|
}
|
|
1018
1037
|
|
|
1019
1038
|
rect(x, y, width, height) {
|
|
1020
|
-
if (arguments.length < 4) throw new TypeError(
|
|
1039
|
+
if (arguments.length < 4) throw new TypeError("Failed to execute 'rect' on '" + this.constructor.name + "': 4 arguments required, but only " + arguments.length + ' present.');
|
|
1021
1040
|
if (!Number.isFinite(x + y + width + height)) return;
|
|
1022
1041
|
const xResult = Number(x);
|
|
1023
1042
|
const yResult = Number(y);
|
|
@@ -1036,7 +1055,7 @@ class CanvasRenderingContext2D {
|
|
|
1036
1055
|
}
|
|
1037
1056
|
|
|
1038
1057
|
removeHitRegion(id) {
|
|
1039
|
-
if (arguments.length < 1) throw new TypeError(
|
|
1058
|
+
if (arguments.length < 1) throw new TypeError("Failed to execute 'removeHitRegion' on '" + this.constructor.name + "': 1 argument required, but only " + arguments.length + ' present.');
|
|
1040
1059
|
const event = (0, _createCanvasEvent.default)('removeHitRegion', getTransformSlice(this), {
|
|
1041
1060
|
id
|
|
1042
1061
|
});
|
|
@@ -1117,7 +1136,7 @@ class CanvasRenderingContext2D {
|
|
|
1117
1136
|
}
|
|
1118
1137
|
|
|
1119
1138
|
rotate(angle) {
|
|
1120
|
-
if (arguments.length < 1) throw new TypeError(
|
|
1139
|
+
if (arguments.length < 1) throw new TypeError("Failed to execute 'rotate' on '" + this.constructor.name + "': 1 argument required, but only 0 present.");
|
|
1121
1140
|
angle = Number(angle);
|
|
1122
1141
|
if (!Number.isFinite(angle)) return;
|
|
1123
1142
|
const a = this._transformStack[this._stackIndex][0];
|
|
@@ -1138,58 +1157,62 @@ class CanvasRenderingContext2D {
|
|
|
1138
1157
|
}
|
|
1139
1158
|
|
|
1140
1159
|
save() {
|
|
1141
|
-
this.
|
|
1160
|
+
const stackIndex = this._stackIndex;
|
|
1161
|
+
|
|
1162
|
+
this._transformStack.push(this._transformStack[stackIndex].slice());
|
|
1142
1163
|
|
|
1143
|
-
this._directionStack.push(this._directionStack[
|
|
1164
|
+
this._directionStack.push(this._directionStack[stackIndex]);
|
|
1144
1165
|
|
|
1145
|
-
this._fillStyleStack.push(this._fillStyleStack[
|
|
1166
|
+
this._fillStyleStack.push(this._fillStyleStack[stackIndex]);
|
|
1146
1167
|
|
|
1147
|
-
this._filterStack.push(this._filterStack[
|
|
1168
|
+
this._filterStack.push(this._filterStack[stackIndex]);
|
|
1148
1169
|
|
|
1149
|
-
this._fontStack.push(this._fontStack[
|
|
1170
|
+
this._fontStack.push(this._fontStack[stackIndex]);
|
|
1150
1171
|
|
|
1151
|
-
this._globalAlphaStack.push(this._globalAlphaStack[
|
|
1172
|
+
this._globalAlphaStack.push(this._globalAlphaStack[stackIndex]);
|
|
1152
1173
|
|
|
1153
|
-
this._globalCompositeOperationStack.push(this._globalCompositeOperationStack[
|
|
1174
|
+
this._globalCompositeOperationStack.push(this._globalCompositeOperationStack[stackIndex]);
|
|
1154
1175
|
|
|
1155
|
-
this._imageSmoothingEnabledStack.push(this._imageSmoothingEnabledStack[
|
|
1176
|
+
this._imageSmoothingEnabledStack.push(this._imageSmoothingEnabledStack[stackIndex]);
|
|
1156
1177
|
|
|
1157
|
-
this._imageSmoothingQualityStack.push(this._imageSmoothingQualityStack[
|
|
1178
|
+
this._imageSmoothingQualityStack.push(this._imageSmoothingQualityStack[stackIndex]);
|
|
1158
1179
|
|
|
1159
|
-
this._lineCapStack.push(this._lineCapStack[
|
|
1180
|
+
this._lineCapStack.push(this._lineCapStack[stackIndex]);
|
|
1160
1181
|
|
|
1161
|
-
this._lineDashStack.push(this._lineDashStack[
|
|
1182
|
+
this._lineDashStack.push(this._lineDashStack[stackIndex]);
|
|
1162
1183
|
|
|
1163
|
-
this._lineDashOffsetStack.push(this._lineDashOffsetStack[
|
|
1184
|
+
this._lineDashOffsetStack.push(this._lineDashOffsetStack[stackIndex]);
|
|
1164
1185
|
|
|
1165
|
-
this._lineJoinStack.push(this._lineJoinStack[
|
|
1186
|
+
this._lineJoinStack.push(this._lineJoinStack[stackIndex]);
|
|
1166
1187
|
|
|
1167
|
-
this._lineWidthStack.push(this._lineWidthStack[
|
|
1188
|
+
this._lineWidthStack.push(this._lineWidthStack[stackIndex]);
|
|
1168
1189
|
|
|
1169
|
-
this._miterLimitStack.push(this._miterLimitStack[
|
|
1190
|
+
this._miterLimitStack.push(this._miterLimitStack[stackIndex]);
|
|
1170
1191
|
|
|
1171
|
-
this._shadowBlurStack.push(this._shadowBlurStack[
|
|
1192
|
+
this._shadowBlurStack.push(this._shadowBlurStack[stackIndex]);
|
|
1172
1193
|
|
|
1173
|
-
this._shadowColorStack.push(this._shadowColorStack[
|
|
1194
|
+
this._shadowColorStack.push(this._shadowColorStack[stackIndex]);
|
|
1174
1195
|
|
|
1175
|
-
this._shadowOffsetXStack.push(this._shadowOffsetXStack[
|
|
1196
|
+
this._shadowOffsetXStack.push(this._shadowOffsetXStack[stackIndex]);
|
|
1176
1197
|
|
|
1177
|
-
this._shadowOffsetYStack.push(this._shadowOffsetYStack[
|
|
1198
|
+
this._shadowOffsetYStack.push(this._shadowOffsetYStack[stackIndex]);
|
|
1178
1199
|
|
|
1179
|
-
this._strokeStyleStack.push(this._strokeStyleStack[
|
|
1200
|
+
this._strokeStyleStack.push(this._strokeStyleStack[stackIndex]);
|
|
1180
1201
|
|
|
1181
|
-
this._textAlignStack.push(this._textAlignStack[
|
|
1202
|
+
this._textAlignStack.push(this._textAlignStack[stackIndex]);
|
|
1182
1203
|
|
|
1183
|
-
this._textBaselineStack.push(this._textBaselineStack[
|
|
1204
|
+
this._textBaselineStack.push(this._textBaselineStack[stackIndex]);
|
|
1184
1205
|
|
|
1185
|
-
this.
|
|
1206
|
+
this._clipStack.push(this._clipStack[stackIndex].slice());
|
|
1207
|
+
|
|
1208
|
+
this._stackIndex = stackIndex + 1;
|
|
1186
1209
|
const event = (0, _createCanvasEvent.default)('save', getTransformSlice(this), {});
|
|
1187
1210
|
|
|
1188
1211
|
this._events.push(event);
|
|
1189
1212
|
}
|
|
1190
1213
|
|
|
1191
1214
|
scale(x, y) {
|
|
1192
|
-
if (arguments.length < 2) throw new TypeError(
|
|
1215
|
+
if (arguments.length < 2) throw new TypeError("Failed to execute 'scale' on '" + this.constructor.name + "': 2 arguments required, but only " + arguments.length + ' present.');
|
|
1193
1216
|
const xResult = Number(x);
|
|
1194
1217
|
const yResult = Number(y);
|
|
1195
1218
|
|
|
@@ -1208,7 +1231,7 @@ class CanvasRenderingContext2D {
|
|
|
1208
1231
|
}
|
|
1209
1232
|
|
|
1210
1233
|
scrollPathIntoView(path) {
|
|
1211
|
-
if (arguments.length > 0 && path instanceof
|
|
1234
|
+
if (arguments.length > 0 && path instanceof _Path2D.default) path = path._path.slice();else path = this._path.slice();
|
|
1212
1235
|
const event = (0, _createCanvasEvent.default)('scrollPathIntoView', getTransformSlice(this), {
|
|
1213
1236
|
path
|
|
1214
1237
|
});
|
|
@@ -1218,7 +1241,7 @@ class CanvasRenderingContext2D {
|
|
|
1218
1241
|
|
|
1219
1242
|
setLineDash(lineDash) {
|
|
1220
1243
|
const isSequence = [Array, Int8Array, Uint8Array, Int16Array, Uint16Array, Int32Array, Uint32Array, Float32Array, Float64Array].reduce((left, right) => left || lineDash instanceof right, false);
|
|
1221
|
-
if (!isSequence) throw new TypeError(
|
|
1244
|
+
if (!isSequence) throw new TypeError("Failed to execute 'setLineDash' on '" + this.constructor.name + "': The provided value cannot be converted to a sequence.");
|
|
1222
1245
|
let result = [];
|
|
1223
1246
|
|
|
1224
1247
|
for (let i = 0; i < lineDash.length; i++) {
|
|
@@ -1257,10 +1280,10 @@ class CanvasRenderingContext2D {
|
|
|
1257
1280
|
e = transform.e;
|
|
1258
1281
|
f = transform.f;
|
|
1259
1282
|
} else {
|
|
1260
|
-
throw new TypeError(
|
|
1283
|
+
throw new TypeError("Failed to execute 'setTransform' on '" + this.constructor.name + "': parameter " + a + " ('transform') is not an object.");
|
|
1261
1284
|
}
|
|
1262
1285
|
} else if (arguments.length < 6) {
|
|
1263
|
-
throw new TypeError(
|
|
1286
|
+
throw new TypeError("Failed to execute 'setTransform' on '" + this.constructor.name + "': Valid arities are: [0, 1, 6], but " + arguments.length + ' arguments provided.');
|
|
1264
1287
|
}
|
|
1265
1288
|
|
|
1266
1289
|
a = Number(a);
|
|
@@ -1307,16 +1330,18 @@ class CanvasRenderingContext2D {
|
|
|
1307
1330
|
|
|
1308
1331
|
set shadowColor(value) {
|
|
1309
1332
|
if (typeof value === 'string') {
|
|
1310
|
-
|
|
1333
|
+
try {
|
|
1334
|
+
const result = new _mooColor.MooColor(value);
|
|
1335
|
+
value = this._shadowColorStack[this._stackIndex] = serializeColor(result);
|
|
1336
|
+
} catch (e) {
|
|
1337
|
+
return;
|
|
1338
|
+
}
|
|
1311
1339
|
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
value: result
|
|
1316
|
-
});
|
|
1340
|
+
const event = (0, _createCanvasEvent.default)('shadowColor', getTransformSlice(this), {
|
|
1341
|
+
value
|
|
1342
|
+
});
|
|
1317
1343
|
|
|
1318
|
-
|
|
1319
|
-
}
|
|
1344
|
+
this._events.push(event);
|
|
1320
1345
|
}
|
|
1321
1346
|
}
|
|
1322
1347
|
|
|
@@ -1362,7 +1387,7 @@ class CanvasRenderingContext2D {
|
|
|
1362
1387
|
if (arguments.length === 0) {
|
|
1363
1388
|
path = this._path.slice();
|
|
1364
1389
|
} else {
|
|
1365
|
-
if (!(path instanceof
|
|
1390
|
+
if (!(path instanceof _Path2D.default)) throw new TypeError("Failed to execute 'stroke' on '" + this.constructor.name + "': parameter 1 is not of type 'Path2D'.");
|
|
1366
1391
|
path = path._path.slice();
|
|
1367
1392
|
}
|
|
1368
1393
|
|
|
@@ -1376,7 +1401,7 @@ class CanvasRenderingContext2D {
|
|
|
1376
1401
|
}
|
|
1377
1402
|
|
|
1378
1403
|
strokeRect(x, y, width, height) {
|
|
1379
|
-
if (arguments.length < 4) throw new TypeError(
|
|
1404
|
+
if (arguments.length < 4) throw new TypeError("Failed to execute 'strokeRect' on '" + this.constructor.name + "': 4 arguments required, but only " + arguments.length + ' present.');
|
|
1380
1405
|
x = Number(x);
|
|
1381
1406
|
y = Number(y);
|
|
1382
1407
|
width = Number(width);
|
|
@@ -1398,11 +1423,12 @@ class CanvasRenderingContext2D {
|
|
|
1398
1423
|
let valid = false;
|
|
1399
1424
|
|
|
1400
1425
|
if (typeof value === 'string') {
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
if (result) {
|
|
1426
|
+
try {
|
|
1427
|
+
const result = new _mooColor.MooColor(value);
|
|
1404
1428
|
valid = true;
|
|
1405
|
-
value = this._strokeStyleStack[this._stackIndex] = result;
|
|
1429
|
+
value = this._strokeStyleStack[this._stackIndex] = serializeColor(result);
|
|
1430
|
+
} catch (e) {
|
|
1431
|
+
return;
|
|
1406
1432
|
}
|
|
1407
1433
|
} else if (value instanceof CanvasGradient || value instanceof _CanvasPattern.default) {
|
|
1408
1434
|
valid = true;
|
|
@@ -1423,7 +1449,7 @@ class CanvasRenderingContext2D {
|
|
|
1423
1449
|
}
|
|
1424
1450
|
|
|
1425
1451
|
strokeText(text, x, y, maxWidth) {
|
|
1426
|
-
if (arguments.length < 3) throw new TypeError(
|
|
1452
|
+
if (arguments.length < 3) throw new TypeError("Failed to execute 'strokeText' on '" + this.constructor.name + "': 3 arguments required, but only " + arguments.length + ' present.');
|
|
1427
1453
|
const textResult = String(text);
|
|
1428
1454
|
const xResult = Number(x);
|
|
1429
1455
|
const yResult = Number(y);
|
|
@@ -1473,7 +1499,7 @@ class CanvasRenderingContext2D {
|
|
|
1473
1499
|
}
|
|
1474
1500
|
|
|
1475
1501
|
transform(a, b, c, d, e, f) {
|
|
1476
|
-
if (arguments.length < 6) throw new TypeError(
|
|
1502
|
+
if (arguments.length < 6) throw new TypeError("Failed to execute 'transform' on '" + this.constructor.name + "': 6 arguments required, but only " + arguments.length + ' present.');
|
|
1477
1503
|
a = Number(a);
|
|
1478
1504
|
b = Number(b);
|
|
1479
1505
|
c = Number(c);
|
|
@@ -1506,7 +1532,7 @@ class CanvasRenderingContext2D {
|
|
|
1506
1532
|
}
|
|
1507
1533
|
|
|
1508
1534
|
translate(x, y) {
|
|
1509
|
-
if (arguments.length < 2) throw new TypeError(
|
|
1535
|
+
if (arguments.length < 2) throw new TypeError("Failed to execute 'translate' on '" + this.constructor.name + "': 2 arguments required, but only " + arguments.length + ' present.');
|
|
1510
1536
|
const xResult = Number(x);
|
|
1511
1537
|
const yResult = Number(y);
|
|
1512
1538
|
const a = this._transformStack[this._stackIndex][0];
|