|
| 1 | +/* eslint-disable @typescript-eslint/no-var-requires, @typescript-eslint/restrict-plus-operands, @typescript-eslint/explicit-member-accessibility */ |
1 | 2 | // @ts-nocheck |
2 | 3 | const { browser, getFontHeight, InternalCanvas, textWrap } = require('./util/util'); |
3 | 4 |
|
@@ -310,11 +311,11 @@ class Canvas { |
310 | 311 | */ |
311 | 312 | addResponsiveText(text, dx, dy, maxWidth) { |
312 | 313 | const [, style = '', size, font] = /(\w+ )?(\d+)(.+)/.exec(this.context.font); |
313 | | - const currentSize = parseInt(size); |
| 314 | + const currentSize = parseInt(size, 10); |
314 | 315 | const { width } = this.measureText(text); |
315 | 316 | const newLength = maxWidth > width ? currentSize : (maxWidth / width) * currentSize; |
316 | 317 | return this |
317 | | - .setTextFont(style + newLength + font) |
| 318 | + .setTextFont(`${style}${newLength}${font}`) |
318 | 319 | .addText(text, dx, dy); |
319 | 320 | } |
320 | 321 |
|
@@ -465,7 +466,7 @@ class Canvas { |
465 | 466 | */ |
466 | 467 | setTextSize(size) { |
467 | 468 | const [, style = '', font] = /(\w+ )?(?:\d+)(.+)/.exec(this.context.font); |
468 | | - return this.setTextFont(style + size + font); |
| 469 | + return this.setTextFont(`${style}${size}${font}`); |
469 | 470 | } |
470 | 471 |
|
471 | 472 | /** |
@@ -580,7 +581,7 @@ class Canvas { |
580 | 581 | if (options.type === 'round') this.createRoundClip(dx + options.radius, dy + options.radius, options.radius); |
581 | 582 | else if (options.type === 'bevel') this.createBeveledClip(dx, dy, width, height, options.radius); |
582 | 583 | } |
583 | | - this._resolveImage(imageOrBuffer, (image) => this.context.drawImage(image, ...args)); |
| 584 | + this._resolveImage(imageOrBuffer, image => this.context.drawImage(image, ...args)); |
584 | 585 | if (options.restore) this.restore(); |
585 | 586 | return this; |
586 | 587 | } |
@@ -617,7 +618,7 @@ class Canvas { |
617 | 618 | if (restore) this.save(); |
618 | 619 | const diameter = radius * 2; |
619 | 620 | this.createRoundClip(dx, dy, radius); |
620 | | - this._resolveImage(imageOrBuffer, (image) => this.context.drawImage(image, dx - radius, dy - radius, diameter, diameter)); |
| 621 | + this._resolveImage(imageOrBuffer, image => this.context.drawImage(image, dx - radius, dy - radius, diameter, diameter)); |
621 | 622 | if (restore) this.restore(); |
622 | 623 | return this; |
623 | 624 | } |
@@ -647,7 +648,8 @@ class Canvas { |
647 | 648 | * @chainable |
648 | 649 | */ |
649 | 650 | addCircle(dx, dy, radius) { |
650 | | - return this.save().createRoundPath(dx, dy, radius).fill().restore(); |
| 651 | + return this.save().createRoundPath(dx, dy, radius).fill() |
| 652 | + .restore(); |
651 | 653 | } |
652 | 654 |
|
653 | 655 | /** |
@@ -703,7 +705,8 @@ class Canvas { |
703 | 705 | * .toBuffer(); |
704 | 706 | */ |
705 | 707 | addBeveledRect(...args) { |
706 | | - return this.save().createBeveledPath(...args).fill().restore(); |
| 708 | + return this.save().createBeveledPath(...args).fill() |
| 709 | + .restore(); |
707 | 710 | } |
708 | 711 |
|
709 | 712 | /** |
@@ -926,7 +929,7 @@ class Canvas { |
926 | 929 | * @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/createPattern |
927 | 930 | */ |
928 | 931 | createPattern(imageOrBuffer, repetition, callback) { |
929 | | - this._resolveImage(imageOrBuffer, (image) => callback(this.context.createPattern(image, repetition))); |
| 932 | + this._resolveImage(imageOrBuffer, image => callback(this.context.createPattern(image, repetition))); |
930 | 933 | return this; |
931 | 934 | } |
932 | 935 |
|
@@ -956,8 +959,9 @@ class Canvas { |
956 | 959 | */ |
957 | 960 | createLinearGradient(x0, y0, x1, y1, steps = []) { |
958 | 961 | const gradient = this.context.createLinearGradient(x0, y0, x1, y1); |
959 | | - for (let i = 0; i < steps.length; i++) |
960 | | - gradient.addColorStop(steps[i].position, steps[i].color); |
| 962 | + for (const step of steps) { |
| 963 | + gradient.addColorStop(step.position, step.color); |
| 964 | + } |
961 | 965 |
|
962 | 966 | return gradient; |
963 | 967 | } |
@@ -1002,8 +1006,9 @@ class Canvas { |
1002 | 1006 | */ |
1003 | 1007 | createRadialGradient(x0, y0, r0, x1, y1, r1, steps = []) { |
1004 | 1008 | const gradient = this.context.createRadialGradient(x0, y0, r0, x1, y1, r1); |
1005 | | - for (let i = 0; i < steps.length; i++) |
1006 | | - gradient.addColorStop(steps[i].position, steps[i].color); |
| 1009 | + for (const step of steps) { |
| 1010 | + gradient.addColorStop(step.position, step.color); |
| 1011 | + } |
1007 | 1012 |
|
1008 | 1013 | return gradient; |
1009 | 1014 | } |
@@ -1470,7 +1475,7 @@ class Canvas { |
1470 | 1475 | * @returns {Promise<Blob>} |
1471 | 1476 | */ |
1472 | 1477 | toBlobAsync(...args) { |
1473 | | - return new Promise((resolve) => this.canvas.toBlob(resolve, ...args)); |
| 1478 | + return new Promise(resolve => this.canvas.toBlob(resolve, ...args)); |
1474 | 1479 | } |
1475 | 1480 |
|
1476 | 1481 | /** |
@@ -1570,10 +1575,13 @@ class Canvas { |
1570 | 1575 | * @returns {Canvas} |
1571 | 1576 | */ |
1572 | 1577 | static registerFont(path, family) { |
1573 | | - if (typeof InternalCanvas.registerFont !== 'function') |
| 1578 | + if (typeof InternalCanvas.registerFont !== 'function') { |
1574 | 1579 | throw new Error('registerFont is not supported in this version of node-canvas, please install node-canvas 2.x.'); |
1575 | | - if (!family) |
| 1580 | + } |
| 1581 | + |
| 1582 | + if (!family) { |
1576 | 1583 | throw new TypeError('A family must be specified for registerFont.'); |
| 1584 | + } |
1577 | 1585 |
|
1578 | 1586 | InternalCanvas.registerFont(path, family.constructor === Object ? family : { family }); |
1579 | 1587 | return Canvas; |
|
0 commit comments