1 | const HTMLElement = require('./HTMLElement');
|
2 | const {createCanvas} = require('canvas');
|
3 |
|
4 | const canvas = new WeakMap;
|
5 |
|
6 | class HTMLCanvasElement extends HTMLElement {
|
7 | constructor(ownerDocument) {
|
8 | super(ownerDocument, 'canvas');
|
9 | canvas.set(this, createCanvas(300, 150));
|
10 | }
|
11 | get width() {
|
12 | return canvas.get(this).width;
|
13 | }
|
14 | set width(value) {
|
15 | this.setAttribute('width', value);
|
16 | canvas.get(this).width = value;
|
17 | }
|
18 | get height() {
|
19 | return canvas.get(this).height;
|
20 | }
|
21 | set height(value) {
|
22 | this.setAttribute('height', value);
|
23 | canvas.get(this).height = value;
|
24 | }
|
25 | getContext(type) {
|
26 | return canvas.get(this).getContext(type);
|
27 | }
|
28 | toDataURL(...args) {
|
29 | return canvas.get(this).toDataURL(...args);
|
30 | }
|
31 | }
|
32 |
|
33 | module.exports = HTMLCanvasElement;
|