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