From 1eb10c56864efe4598fb2a60bbc03a3ed60e7262 Mon Sep 17 00:00:00 2001 From: Caleb Evans Date: Wed, 29 May 2024 18:20:24 -0700 Subject: [PATCH] Streamline variable declarations further --- src/jcanvas.ts | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/src/jcanvas.ts b/src/jcanvas.ts index f968cd5..2541cb4 100644 --- a/src/jcanvas.ts +++ b/src/jcanvas.ts @@ -429,8 +429,6 @@ function _closePath( ctx: CanvasRenderingContext2D, params: JCanvasObject ) { - let data; - // Optionally close path if (params.closed) { ctx.closePath(); @@ -489,7 +487,7 @@ function _closePath( // Mask shape if chosen if (params.mask) { // Retrieve canvas data - data = _getCanvasData(canvas); + const data = _getCanvasData(canvas); _enableMasking(ctx, data, params); } } @@ -874,13 +872,12 @@ $.fn.getEventHooks = function getEventHooks() { // Set event hooks for the selected canvases $.fn.setEventHooks = function setEventHooks(eventHooks) { const $canvases = this; - let data; for (let e = 0; e < $canvases.length; e += 1) { const canvas = $canvases[e]; if (!_isCanvas(canvas)) { continue; } - data = _getCanvasData(canvas); + const data = _getCanvasData(canvas); extendObject(data.eventHooks, eventHooks); } return $canvases; @@ -1303,10 +1300,9 @@ $.fn.removeLayerFromGroup = function removeLayerFromGroup(layerId, groupName) { // Get topmost layer that intersects with event coordinates function _getIntersectingLayer(data: JCanvasInternalData) { - let layer: JCanvasLayer | null, mask: JCanvasObject, m; - // Store the topmost layer - layer = null; + let layer: JCanvasLayer | null = null; + let mask: JCanvasObject; // Get the topmost layer whose visible area intersects event coordinates for (let i = data.intersecting.length - 1; i >= 0; i -= 1) { @@ -1317,7 +1313,7 @@ function _getIntersectingLayer(data: JCanvasInternalData) { if (layer._masks) { // Search previous masks to ensure // layer is visible at event coordinates - for (m = layer._masks.length - 1; m >= 0; m -= 1) { + for (let m = layer._masks.length - 1; m >= 0; m -= 1) { mask = layer._masks[m]; // If mask does not intersect event coordinates if (!mask.intersects) { @@ -1608,10 +1604,7 @@ $.fn.drawLayers = function drawLayers(args) { let isImageLayer: boolean = false; // The layer index from which to start redrawing the canvas - let index = params.index; - if (!index) { - index = 0; - } + const index = params.index || 0; for (let e = 0; e < $canvases.length; e += 1) { const canvas = $canvases[e];