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