Merge pull request #1838 from tbo47/refactor-cont-let
Some checks failed
Test Browser / build (16.x) (push) Has been cancelled
Test NodeJS / build (16.x) (push) Has been cancelled

refactor const let var
This commit is contained in:
Anton Lavrenov 2024-10-28 13:41:22 -05:00 committed by GitHub
commit e47d54889c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 49 additions and 65 deletions

View File

@ -6,14 +6,12 @@ import { IRect } from './types';
import type { Node } from './Node';
function simplifyArray(arr: Array<any>) {
let retArr: Array<any> = [],
const retArr: Array<any> = [],
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)) {

View File

@ -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;
}

View File

@ -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;

View File

@ -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) {

View File

@ -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

View File

@ -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];

View File

@ -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) {

View File

@ -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);

View File

@ -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