jakubfiala / atrament

A small JS library for beautiful drawing and handwriting on the HTML Canvas.
http://fiala.space/atrament/demo
MIT License
1.57k stars 115 forks source link

Library should not add event listener on document #50

Closed stmn closed 4 years ago

stmn commented 4 years ago

I mean this:

document.addEventListener('mouseup', mouseUp);

If something is happening outside of canvas (for example button clicking) it should not have any side effects for canvas, but it has currently. It's just a bad behaviour. Don't you agree?

jakubfiala commented 4 years ago

@stmn thanks for asking - unfortunately here it's necessary, because if your cursor leaves the canvas mid-stroke, and then you release the mouse button, the library needs to end the stroke. If it didn't, you could release the mouse, and when you moved over the canvas again, you'd still be drawing that one original stroke.

We could also use mouseout, but then every time you accidentally leave the canvas mid-stroke, you'd end the stroke even without releasing the mouse.

Hope that makes sense!