From 3b807a968c34b83c5b445471d2dd860fcb7b7f85 Mon Sep 17 00:00:00 2001 From: Andras Schmelczer Date: Thu, 11 Jun 2026 20:32:14 +0100 Subject: [PATCH] Fix iOS cursor offset --- js/CanvasHandler.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/js/CanvasHandler.js b/js/CanvasHandler.js index 2a9d5cc..5b80ff6 100644 --- a/js/CanvasHandler.js +++ b/js/CanvasHandler.js @@ -38,6 +38,14 @@ class CanvasHandler { return unit * Math.sqrt(this.width * this.height); } + clientToCanvas(clientX, clientY) { + const rect = this.canvas.getBoundingClientRect(); + return [ + ((clientX - rect.left) / rect.width) * this.width, + ((clientY - rect.top) / rect.height) * this.height, + ]; + } + get width() { return this.canvas.width / window.devicePixelRatio; }