Skip to content

Commit 82cfa19

Browse files
committed
1.2.7
*Fixed canvas being misaligned with touch inputs
1 parent df32c95 commit 82cfa19

2 files changed

Lines changed: 19 additions & 8 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "Budibase-Signature-Plugin",
3-
"version": "1.2.5",
3+
"version": "1.2.7",
44
"description": "A plugin that allows signatures to be created and saved in budibase",
55
"license": "MIT",
66
"svelte": "index.js",

src/Canvas.svelte

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@
4848
4949
const handleStart = (({ offsetX: x, offsetY: y }) => {
5050
if (!inBuilder){
51+
const { top, left } = canvas.getBoundingClientRect()
52+
t = top
53+
l = left
5154
if(color === background) {
5255
context.clearRect(0, 0, width, height)
5356
} else {
@@ -66,15 +69,23 @@
6669
6770
const handleMove = (({ offsetX: x1, offsetY: y1 }) => {
6871
if (!inBuilder){
72+
const { top, left } = canvas.getBoundingClientRect()
73+
t = top
74+
l = left
6975
if(!isDrawing) return
7076
7177
const { x, y } = start
72-
context.beginPath()
73-
context.moveTo(x, y)
74-
context.lineTo(x1, y1)
75-
context.closePath()
76-
context.stroke()
77-
78+
79+
if (x >= 0){
80+
if (y >= 0){
81+
context.beginPath()
82+
context.moveTo(x, y)
83+
context.lineTo(x1, y1)
84+
context.closePath()
85+
context.stroke()
86+
}
87+
}
88+
7889
start = { x: x1, y: y1 }
7990
}
8091
})
@@ -161,7 +172,7 @@
161172
style:background
162173
bind:this={canvas}
163174
on:mousedown={handleStart}
164-
on:touchstart={e => {
175+
on:touchstart|preventDefault={e => {
165176
const { clientX, clientY } = e.touches[0]
166177
handleStart({
167178
offsetX: clientX - l,

0 commit comments

Comments
 (0)