Instead of having to subtract by a custom variable, you can use offsetX and offsetY from the window element to grab the mouse's position in relation to the canvas. "But that would cause errors whenever the mouse exits the canvas!" Actually, there is already a boolean tracking whether the mouse is hovering over the canvas. It's called isHovering. Simply only draw / append to currentStroke if isHovering === true.
Instead of having to subtract by a custom variable, you can use offsetX and offsetY from the window element to grab the mouse's position in relation to the canvas. "But that would cause errors whenever the mouse exits the canvas!" Actually, there is already a boolean tracking whether the mouse is hovering over the canvas. It's called
isHovering. Simply only draw / append tocurrentStrokeifisHovering === true.