Skip to content

Commit

Permalink
Merge pull request #1830 from tbo47/var-to-const-or-let
Browse files Browse the repository at this point in the history
var to const or let
  • Loading branch information
lavrton authored Oct 9, 2024
2 parents f153853 + cb85f72 commit 16bd91b
Show file tree
Hide file tree
Showing 49 changed files with 720 additions and 721 deletions.
2 changes: 1 addition & 1 deletion src/Animation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ export class Animation {
}
}

for (let key in layerHash) {
for (const key in layerHash) {
if (!layerHash.hasOwnProperty(key)) {
continue;
}
Expand Down
3 changes: 1 addition & 2 deletions src/BezierFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,6 @@ export const cValues = [
export const binomialCoefficients = [[1], [1, 1], [1, 2, 1], [1, 3, 3, 1]];

export const getCubicArcLength = (xs: number[], ys: number[], t: number) => {
let z: number;
let sum: number;
let correctedT: number;

Expand All @@ -702,7 +701,7 @@ export const getCubicArcLength = (xs: number[], ys: number[], t: number) => {

const n = 20;

z = t / 2;
const z = t / 2;
sum = 0;
for (let i = 0; i < n; i++) {
correctedT = z * tValues[n][i] + z;
Expand Down
18 changes: 9 additions & 9 deletions src/Canvas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ import { Factory } from './Factory';
import { getNumberValidator } from './Validators';

// calculate pixel ratio
var _pixelRatio;
let _pixelRatio;
function getDevicePixelRatio() {
if (_pixelRatio) {
return _pixelRatio;
}
var canvas = Util.createCanvasElement();
var context = canvas.getContext('2d') as any;
const canvas = Util.createCanvasElement();
const context = canvas.getContext('2d') as any;
_pixelRatio = (function () {
var devicePixelRatio = Konva._global.devicePixelRatio || 1,
const devicePixelRatio = Konva._global.devicePixelRatio || 1,
backingStoreRatio =
context.webkitBackingStorePixelRatio ||
context.mozBackingStorePixelRatio ||
Expand Down Expand Up @@ -55,9 +55,9 @@ export class Canvas {
isCache = false;

constructor(config: ICanvasConfig) {
var conf = config || {};
const conf = config || {};

var pixelRatio =
const pixelRatio =
conf.pixelRatio || Konva.pixelRatio || getDevicePixelRatio();

this.pixelRatio = pixelRatio;
Expand Down Expand Up @@ -86,7 +86,7 @@ export class Canvas {
return this.pixelRatio;
}
setPixelRatio(pixelRatio) {
var previousRatio = this.pixelRatio;
const previousRatio = this.pixelRatio;
this.pixelRatio = pixelRatio;
this.setSize(
this.getWidth() / previousRatio,
Expand All @@ -98,15 +98,15 @@ export class Canvas {
this.width = this._canvas.width = width * this.pixelRatio;
this._canvas.style.width = width + 'px';

var pixelRatio = this.pixelRatio,
const pixelRatio = this.pixelRatio,
_context = this.getContext()._context;
_context.scale(pixelRatio, pixelRatio);
}
setHeight(height) {
// take into account pixel ratio
this.height = this._canvas.height = height * this.pixelRatio;
this._canvas.style.height = height + 'px';
var pixelRatio = this.pixelRatio,
const pixelRatio = this.pixelRatio,
_context = this.getContext()._context;
_context.scale(pixelRatio, pixelRatio);
}
Expand Down
58 changes: 29 additions & 29 deletions src/Container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export abstract class Container<
}

const children = this.children || [];
var results: Array<ChildType> = [];
const results: Array<ChildType> = [];
children.forEach(function (child) {
if (filterFunc(child)) {
results.push(child);
Expand Down Expand Up @@ -128,7 +128,7 @@ export abstract class Container<
return this;
}
if (children.length > 1) {
for (var i = 0; i < children.length; i++) {
for (let i = 0; i < children.length; i++) {
this.add(children[i]);
}
return this;
Expand Down Expand Up @@ -223,14 +223,14 @@ export abstract class Container<
findOne<ChildNode extends Node = Node>(
selector: string | Function
): ChildNode | undefined {
var result = this._generalFind<ChildNode>(selector, true);
const result = this._generalFind<ChildNode>(selector, true);
return result.length > 0 ? result[0] : undefined;
}
_generalFind<ChildNode extends Node>(
selector: string | Function,
findOne: boolean
) {
var retArr: Array<ChildNode> = [];
const retArr: Array<ChildNode> = [];

this._descendants((node) => {
const valid = node._isMatch(selector);
Expand Down Expand Up @@ -265,7 +265,7 @@ export abstract class Container<
}
// extenders
toObject() {
var obj = Node.prototype.toObject.call(this);
const obj = Node.prototype.toObject.call(this);

obj.children = [];

Expand All @@ -283,7 +283,7 @@ export abstract class Container<
* @param {Konva.Node} node
*/
isAncestorOf(node: Node) {
var parent = node.getParent();
let parent = node.getParent();
while (parent) {
if (parent._id === this._id) {
return true;
Expand All @@ -295,7 +295,7 @@ export abstract class Container<
}
clone(obj?: any) {
// call super method
var node = Node.prototype.clone.call(this, obj);
const node = Node.prototype.clone.call(this, obj);

this.getChildren().forEach(function (no) {
node.add(no.clone());
Expand All @@ -316,7 +316,7 @@ export abstract class Container<
* @returns {Array} array of shapes
*/
getAllIntersections(pos) {
var arr: Shape[] = [];
const arr: Shape[] = [];

this.find<Shape>('Shape').forEach((shape) => {
if (shape.isVisible() && shape.intersects(pos)) {
Expand Down Expand Up @@ -344,20 +344,20 @@ export abstract class Container<
this._requestDraw();
}
drawScene(can?: SceneCanvas, top?: Node, bufferCanvas?: SceneCanvas) {
var layer = this.getLayer()!,
const layer = this.getLayer()!,
canvas = can || (layer && layer.getCanvas()),
context = canvas && canvas.getContext(),
cachedCanvas = this._getCanvasCache(),
cachedSceneCanvas = cachedCanvas && cachedCanvas.scene;

var caching = canvas && canvas.isCache;
const caching = canvas && canvas.isCache;
if (!this.isVisible() && !caching) {
return this;
}

if (cachedSceneCanvas) {
context.save();
var m = this.getAbsoluteTransform(top).getMatrix();
const m = this.getAbsoluteTransform(top).getMatrix();
context.transform(m[0], m[1], m[2], m[3], m[4], m[5]);
this._drawCachedSceneCanvas(context);
context.restore();
Expand All @@ -371,15 +371,15 @@ export abstract class Container<
return this;
}

var layer = this.getLayer()!,
const layer = this.getLayer()!,
canvas = can || (layer && layer.hitCanvas),
context = canvas && canvas.getContext(),
cachedCanvas = this._getCanvasCache(),
cachedHitCanvas = cachedCanvas && cachedCanvas.hit;

if (cachedHitCanvas) {
context.save();
var m = this.getAbsoluteTransform(top).getMatrix();
const m = this.getAbsoluteTransform(top).getMatrix();
context.transform(m[0], m[1], m[2], m[3], m[4], m[5]);
this._drawCachedHitCanvas(context);
context.restore();
Expand All @@ -389,7 +389,7 @@ export abstract class Container<
return this;
}
_drawChildren(drawMethod, canvas, top, bufferCanvas?) {
var context = canvas && canvas.getContext(),
const context = canvas && canvas.getContext(),
clipWidth = this.clipWidth(),
clipHeight = this.clipHeight(),
clipFunc = this.clipFunc(),
Expand All @@ -401,24 +401,24 @@ export abstract class Container<

if (hasClip) {
context.save();
var transform = this.getAbsoluteTransform(top);
var m = transform.getMatrix();
const transform = this.getAbsoluteTransform(top);
let m = transform.getMatrix();
context.transform(m[0], m[1], m[2], m[3], m[4], m[5]);
context.beginPath();
let clipArgs;
if (clipFunc) {
clipArgs = clipFunc.call(this, context, this);
} else {
var clipX = this.clipX();
var clipY = this.clipY();
const clipX = this.clipX();
const clipY = this.clipY();
context.rect(clipX || 0, clipY || 0, clipWidth, clipHeight);
}
context.clip.apply(context, clipArgs);
m = transform.copy().invert().getMatrix();
context.transform(m[0], m[1], m[2], m[3], m[4], m[5]);
}

var hasComposition =
const hasComposition =
!selfCache &&
this.globalCompositeOperation() !== 'source-over' &&
drawMethod === 'drawScene';
Expand Down Expand Up @@ -448,24 +448,24 @@ export abstract class Container<
relativeTo?: Container<Node>;
} = {}
): IRect {
var skipTransform = config.skipTransform;
var relativeTo = config.relativeTo;
const skipTransform = config.skipTransform;
const relativeTo = config.relativeTo;

var minX, minY, maxX, maxY;
var selfRect = {
let minX, minY, maxX, maxY;
let selfRect = {
x: Infinity,
y: Infinity,
width: 0,
height: 0,
};
var that = this;
const that = this;
this.children?.forEach(function (child) {
// skip invisible children
if (!child.visible()) {
return;
}

var rect = child.getClientRect({
const rect = child.getClientRect({
relativeTo: that,
skipShadow: config.skipShadow,
skipStroke: config.skipStroke,
Expand All @@ -491,10 +491,10 @@ export abstract class Container<
});

// if child is group we need to make sure it has visible shapes inside
var shapes = this.find('Shape');
var hasVisible = false;
for (var i = 0; i < shapes.length; i++) {
var shape = shapes[i];
const shapes = this.find('Shape');
let hasVisible = false;
for (let i = 0; i < shapes.length; i++) {
const shape = shapes[i];
if (shape._isVisible(this)) {
hasVisible = true;
break;
Expand Down
Loading

0 comments on commit 16bd91b

Please sign in to comment.