Skip to content

Commit 2e69efd

Browse files
committed
build: small code refactoring
1 parent 0d5a5d6 commit 2e69efd

1 file changed

Lines changed: 20 additions & 13 deletions

File tree

engine/src/Core/Canvas.ts

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -404,13 +404,18 @@ export class Canvas {
404404
this.element = canvas;
405405
this.element.ariaHidden = "true";
406406
this._originalStyle = deepExtend({}, this.element.style) as Record<string, string | null>;
407-
this._standardSize.height = canvas.offsetHeight;
408-
this._standardSize.width = canvas.offsetWidth;
407+
408+
const standardSize = this._standardSize;
409+
410+
standardSize.height = canvas.offsetHeight;
411+
standardSize.width = canvas.offsetWidth;
409412

410413
const pxRatio = this.container.retina.pixelRatio;
411414

412-
this.size.height = this._standardSize.height * pxRatio;
413-
this.size.width = this._standardSize.width * pxRatio;
415+
const retinaSize = this.size;
416+
417+
retinaSize.height = standardSize.height * pxRatio;
418+
retinaSize.width = standardSize.width * pxRatio;
414419

415420
this._context = this.element.getContext("2d");
416421

@@ -459,29 +464,31 @@ export class Canvas {
459464
}
460465

461466
const container = this.container,
462-
size = container.canvas._standardSize,
467+
currentSize = container.canvas._standardSize,
463468
newSize = {
464469
width: this.element.offsetWidth,
465470
height: this.element.offsetHeight,
466471
};
467472

468-
if (newSize.height === size.height && newSize.width === size.width) {
473+
if (newSize.height === currentSize.height && newSize.width === currentSize.width) {
469474
return false;
470475
}
471476

472-
const oldSize = { ...size },
477+
const oldSize = { ...currentSize },
473478
pxRatio = container.retina.pixelRatio;
474479

475-
this._standardSize.height = newSize.height;
476-
this._standardSize.width = newSize.width;
480+
currentSize.height = newSize.height;
481+
currentSize.width = newSize.width;
482+
483+
const retinaSize = this.size;
477484

478-
this.element.width = this.size.width = this._standardSize.width * pxRatio;
479-
this.element.height = this.size.height = this._standardSize.height * pxRatio;
485+
this.element.width = retinaSize.width = currentSize.width * pxRatio;
486+
this.element.height = retinaSize.height = currentSize.height * pxRatio;
480487

481488
if (this.container.started) {
482489
container.particles.setResizeFactor({
483-
width: size.width / oldSize.width,
484-
height: size.height / oldSize.height,
490+
width: currentSize.width / oldSize.width,
491+
height: currentSize.height / oldSize.height,
485492
});
486493
}
487494

0 commit comments

Comments
 (0)