Skip to content

Commit

Permalink
refactor const let var
Browse files Browse the repository at this point in the history
  • Loading branch information
tbo47 committed Oct 10, 2024
1 parent e9b8d84 commit 4509d15
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 33 deletions.
5 changes: 2 additions & 3 deletions src/Container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -458,15 +458,14 @@ export abstract class Container<
width: 0,
height: 0,
};
const that = this;
this.children?.forEach(function (child) {
this.children?.forEach((child) => {
// skip invisible children
if (!child.visible()) {
return;
}

const rect = child.getClientRect({
relativeTo: that,
relativeTo: this,
skipShadow: config.skipShadow,
skipStroke: config.skipStroke,
});
Expand Down
10 changes: 4 additions & 6 deletions src/Context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
15 changes: 6 additions & 9 deletions src/Factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand All @@ -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);
Expand All @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/PointerEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export function setPointerCapture(pointerId: number, shape: Shape | Stage) {
}
}

export function releaseCapture(pointerId: number, target?: Shape | Stage) {
export function releaseCapture(pointerId: number) {
const shape = Captures.get(pointerId);

if (!shape) return;
Expand Down
22 changes: 8 additions & 14 deletions src/Shape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 4509d15

Please sign in to comment.