diff --git a/src/Context.ts b/src/Context.ts index 3783d87a2..aeac2e07b 100644 --- a/src/Context.ts +++ b/src/Context.ts @@ -6,14 +6,12 @@ import { IRect } from './types'; import type { Node } from './Node'; function simplifyArray(arr: Array) { - let retArr: Array = [], + const retArr: Array = [], len = arr.length, - util = Util, - n, - val; + util = Util; - for (n = 0; n < len; n++) { - val = arr[n]; + for (let n = 0; n < len; n++) { + let val = arr[n]; if (util._isNumber(val)) { val = Math.round(val * 1000) / 1000; } else if (!util._isString(val)) { diff --git a/src/Factory.ts b/src/Factory.ts index f2cfcbb3d..e86117b35 100644 --- a/src/Factory.ts +++ b/src/Factory.ts @@ -52,19 +52,17 @@ export const Factory = { validator?: Function, after?: Function ) { - let len = components.length, + const len = components.length, capitalize = Util._capitalize, getter = GET + capitalize(attr), - setter = SET + capitalize(attr), - n, - component; + setter = SET + capitalize(attr); // getter constructor.prototype[getter] = function () { const ret = {}; - for (n = 0; n < len; n++) { - component = components[n]; + for (let n = 0; n < len; n++) { + const component = components[n]; ret[component] = this.getAttr(attr + capitalize(component)); } @@ -75,8 +73,7 @@ export const Factory = { // setter constructor.prototype[setter] = function (val) { - let oldVal = this.attrs[attr], - key; + const oldVal = this.attrs[attr]; if (validator) { val = validator.call(this, val); @@ -86,7 +83,7 @@ export const Factory = { basicValidator.call(this, val, attr); } - for (key in val) { + for (const key in val) { if (!val.hasOwnProperty(key)) { continue; } diff --git a/src/Shape.ts b/src/Shape.ts index 3de27c903..aec9d0643 100644 --- a/src/Shape.ts +++ b/src/Shape.ts @@ -722,31 +722,25 @@ export class Shape< * shape.drawHitFromCache(); */ drawHitFromCache(alphaThreshold = 0) { - let cachedCanvas = this._getCanvasCache(), + const cachedCanvas = this._getCanvasCache(), sceneCanvas = this._getCachedSceneCanvas(), hitCanvas = cachedCanvas.hit, hitContext = hitCanvas.getContext(), hitWidth = hitCanvas.getWidth(), - hitHeight = hitCanvas.getHeight(), - hitImageData, - hitData, - len, - rgbColorKey, - i, - alpha; + hitHeight = hitCanvas.getHeight(); hitContext.clear(); hitContext.drawImage(sceneCanvas._canvas, 0, 0, hitWidth, hitHeight); try { - hitImageData = hitContext.getImageData(0, 0, hitWidth, hitHeight); - hitData = hitImageData.data; - len = hitData.length; - rgbColorKey = Util._hexToRgb(this.colorKey); + const hitImageData = hitContext.getImageData(0, 0, hitWidth, hitHeight); + const hitData = hitImageData.data; + const len = hitData.length; + const rgbColorKey = Util._hexToRgb(this.colorKey); // replace non transparent pixels with color key - for (i = 0; i < len; i += 4) { - alpha = hitData[i + 3]; + for (let i = 0; i < len; i += 4) { + const alpha = hitData[i + 3]; if (alpha > alphaThreshold) { hitData[i] = rgbColorKey.r; hitData[i + 1] = rgbColorKey.g; diff --git a/src/filters/Blur.ts b/src/filters/Blur.ts index 98c0a42ee..4998e8e7e 100644 --- a/src/filters/Blur.ts +++ b/src/filters/Blur.ts @@ -121,19 +121,20 @@ function filterGaussBlurRGBA(imageData, radius) { pa, rbs; - let div = radius + radius + 1, + const div = radius + radius + 1, widthMinus1 = width - 1, heightMinus1 = height - 1, radiusPlus1 = radius + 1, sumFactor = (radiusPlus1 * (radiusPlus1 + 1)) / 2, stackStart = new BlurStack(), - stackEnd = null, - stack = stackStart, - stackIn: any = null, - stackOut: any = null, mul_sum = mul_table[radius], shg_sum = shg_table[radius]; + let stackEnd = null, + stack = stackStart, + stackIn: any = null, + stackOut: any = null; + for (i = 1; i < div; i++) { stack = stack.next = new BlurStack(); if (i === radiusPlus1) { diff --git a/src/filters/Brighten.ts b/src/filters/Brighten.ts index d0066f5db..d7d981b7a 100644 --- a/src/filters/Brighten.ts +++ b/src/filters/Brighten.ts @@ -13,12 +13,11 @@ import { getNumberValidator } from '../Validators'; * node.brightness(0.8); */ export const Brighten: Filter = function (imageData) { - let brightness = this.brightness() * 255, + const brightness = this.brightness() * 255, data = imageData.data, - len = data.length, - i; + len = data.length; - for (i = 0; i < len; i += 4) { + for (let i = 0; i < len; i += 4) { // red data[i] += brightness; // green diff --git a/src/filters/Contrast.ts b/src/filters/Contrast.ts index 2ebbd6a03..80ec38b40 100644 --- a/src/filters/Contrast.ts +++ b/src/filters/Contrast.ts @@ -15,14 +15,13 @@ import { getNumberValidator } from '../Validators'; export const Contrast: Filter = function (imageData) { const adjust = Math.pow((this.contrast() + 100) / 100, 2); - let data = imageData.data, - nPixels = data.length, - red = 150, + const data = imageData.data, + nPixels = data.length; + let red = 150, green = 150, - blue = 150, - i; + blue = 150; - for (i = 0; i < nPixels; i += 4) { + for (let i = 0; i < nPixels; i += 4) { red = data[i]; green = data[i + 1]; blue = data[i + 2]; diff --git a/src/filters/Emboss.ts b/src/filters/Emboss.ts index 1df3f5c49..cbeacd3cd 100644 --- a/src/filters/Emboss.ts +++ b/src/filters/Emboss.ts @@ -23,16 +23,16 @@ export const Emboss: Filter = function (imageData) { // pixastic greyLevel is between 0 and 255. I want it between 0 and 1. Also, // a max value of greyLevel yields a white emboss, and the min value yields a black // emboss. Therefore, I changed greyLevel to whiteLevel - let strength = this.embossStrength() * 10, + const strength = this.embossStrength() * 10, greyLevel = this.embossWhiteLevel() * 255, direction = this.embossDirection(), blend = this.embossBlend(), - dirY = 0, - dirX = 0, data = imageData.data, w = imageData.width, h = imageData.height, - w4 = w * 4, + w4 = w * 4; + let dirY = 0, + dirX = 0, y = h; switch (direction) { diff --git a/src/filters/Enhance.ts b/src/filters/Enhance.ts index 2159e0859..d92d68344 100644 --- a/src/filters/Enhance.ts +++ b/src/filters/Enhance.ts @@ -4,9 +4,8 @@ import { getNumberValidator } from '../Validators'; function remap(fromValue: number, fromMin: number, fromMax: number, toMin: number, toMax: number) { // Compute the range of the data - let fromRange = fromMax - fromMin, - toRange = toMax - toMin, - toValue; + const fromRange = fromMax - fromMin, + toRange = toMax - toMin; // If either range is 0, then the value can only be mapped to 1 value if (fromRange === 0) { @@ -17,7 +16,7 @@ function remap(fromValue: number, fromMin: number, fromMax: number, toMin: numbe } // (1) untranslate, (2) unscale, (3) rescale, (4) retranslate - toValue = (fromValue - fromMin) / fromRange; + let toValue = (fromValue - fromMin) / fromRange; toValue = toRange * toValue + toMin; return toValue; @@ -38,9 +37,9 @@ function remap(fromValue: number, fromMin: number, fromMax: number, toMin: numbe * node.enhance(0.4); */ export const Enhance: Filter = function (imageData) { - let data = imageData.data, - nSubPixels = data.length, - rMin = data[0], + const data = imageData.data, + nSubPixels = data.length; + let rMin = data[0], rMax = rMin, r, gMin = data[1], @@ -48,8 +47,7 @@ export const Enhance: Filter = function (imageData) { g, bMin = data[2], bMax = bMin, - b, - i; + b; // If we are not enhancing anything - don't do any computation const enhanceAmount = this.enhance(); @@ -58,7 +56,7 @@ export const Enhance: Filter = function (imageData) { } // 1st Pass - find the min and max for each channel: - for (i = 0; i < nSubPixels; i += 4) { + for (let i = 0; i < nSubPixels; i += 4) { r = data[i + 0]; if (r < rMin) { rMin = r; @@ -128,7 +126,7 @@ export const Enhance: Filter = function (imageData) { } // Pass 2 - remap everything, except the alpha - for (i = 0; i < nSubPixels; i += 4) { + for (let i = 0; i < nSubPixels; i += 4) { data[i + 0] = remap(data[i + 0], rMin, rMax, rGoalMin, rGoalMax); data[i + 1] = remap(data[i + 1], gMin, gMax, gGoalMin, gGoalMax); data[i + 2] = remap(data[i + 2], bMin, bMax, bGoalMin, bGoalMax); diff --git a/src/filters/Grayscale.ts b/src/filters/Grayscale.ts index d30ac61a4..4457a95fb 100644 --- a/src/filters/Grayscale.ts +++ b/src/filters/Grayscale.ts @@ -10,13 +10,11 @@ import { Filter } from '../Node'; * node.filters([Konva.Filters.Grayscale]); */ export const Grayscale: Filter = function (imageData) { - let data = imageData.data, - len = data.length, - i, - brightness; + const data = imageData.data, + len = data.length; - for (i = 0; i < len; i += 4) { - brightness = 0.34 * data[i] + 0.5 * data[i + 1] + 0.16 * data[i + 2]; + for (let i = 0; i < len; i += 4) { + const brightness = 0.34 * data[i] + 0.5 * data[i + 1] + 0.16 * data[i + 2]; // red data[i] = brightness; // green