paperjs / paper.js

The Swiss Army Knife of Vector Graphics Scripting – Scriptographer ported to JavaScript and the browser, using HTML5 Canvas. Created by @lehni & @puckey
http://paperjs.org
Other
14.49k stars 1.23k forks source link

Support w3c pointer events api #1354

Open allforabit opened 7 years ago

allforabit commented 7 years ago

It would be nice to have support for the Pointer events api: https://www.w3.org/TR/pointerevents/ With this it's possible to detect which device is being used for input, e.g. a stylus. Most browsers now support it apart from Safari. However there is a polyfill to work around this: https://github.com/jquery/PEP

ghost commented 6 years ago

Pointer Events Level 2: https://w3c.github.io/pointerevents/

sasensi commented 5 years ago

Could you elaborate more about the feature that you are thinking about (use cases, ideal API code examples, ...) ?

sberney commented 4 years ago

Pointer Events is a well designed API that supports most if not all touch capabilities that can be implemented in a browser, as it was intentionally designed to replace Touch Events and Mouse Events. It allows me to differentiate between the eraser on my Surface Book's Stylus, and its nib. It should support Apple Pencil, but I haven't verified. It supports multi-touch. It allows you to differentiate between a stylus and fingers. Here's a relevant subsection from ghost's link describing the following properties that Pointer Events makes available -- it has strictly more information:

    long        pointerId = 0;
    double      width = 1;
    double      height = 1;
    float       pressure = 0;
    float       tangentialPressure = 0;
    long        tiltX = 0;
    long        tiltY = 0;
    long        twist = 0;
    DOMString   pointerType = "";
    boolean     isPrimary = false;

Pointer Events are implemented in all the major relevant browsers. Older browser versions are less compatible, so you would likely want to allow the user to opt into one or the other -- or gracefully fall back.

For my purposes, it doesn't work to only have information available from Touch Events, since I want to make a richly interactive program. I need to have that fine grain distinguishedness between all the different kinds of input buttons, and react accordingly. (And down the line, I can see it being nice to have access to those extra tilt and twist properties.) ... I bet a lot of other people would appreciate this too. I don't know what kinds of programs other people are building, but they presumably care about user input.