Clamp mouseclick coordinates to target element bounds
Listen for mouseup events from window as well as target element

Pressing an holding a mouse button and then moving the mouse out of the
canvas before releasing meant that onmouseup was never triggered.
Capture mouse events and filter irrelevant ones