|
1 | | -[![test][test-badge]][test] |
| 1 | +[![test][test-badge]][test] |
2 | 2 |
|
3 | | -# pointerdriver |
| 3 | +# pointerdriver |
4 | 4 |
|
5 | | -> Synthesizes and dispatches events. |
6 | | -> Mimics the event stream as if it were executed |
7 | | -> by an actual human driving the interaction. |
| 5 | +Synthesize pointer, touch, and gesture events on any page. |
8 | 6 |
|
9 | | -```sh |
10 | | -npm i github:TheProfs/pointerdriver |
| 7 | +```bash |
| 8 | +npx github:TheProfs/pointerdriver |
11 | 9 | ``` |
12 | 10 |
|
13 | | -## Usage |
| 11 | +## Import in browser console |
| 12 | + |
| 13 | +Open your project in the browser, |
| 14 | +then paste in the DevTools console: |
14 | 15 |
|
15 | 16 | ```js |
16 | | -import { |
17 | | - DragMotion, GlideMotion, StrokeMotion, |
18 | | - PinchMotion, TwistMotion |
19 | | -} from 'pointerdriver' |
| 17 | +const { |
| 18 | + DragMotion, GlideMotion, StrokeMotion, |
| 19 | + PinchMotion, TwistMotion |
| 20 | +} = await import('http://127.0.0.1:5619/pointerdriver.js') |
| 21 | +``` |
| 22 | + |
| 23 | +## Drive the page |
20 | 24 |
|
| 25 | +```js |
21 | 26 | await new DragMotion(document.querySelector('#el'), [ |
22 | 27 | [30, 50, 0], |
23 | 28 | [60, 80, 16], |
24 | 29 | ]).perform() |
25 | 30 |
|
26 | | -await new PinchMotion(document.querySelector('#el'), 2, { |
27 | | - x: 60, y: 80 |
| 31 | +await new PinchMotion(document.querySelector('#el'), 2, { |
| 32 | + x: 60, y: 80 |
28 | 33 | }).perform() |
29 | 34 |
|
30 | | -await new TwistMotion(document.querySelector('#el'), 45, { |
31 | | - x: 60, y: 80 |
| 35 | +await new TwistMotion(document.querySelector('#el'), 45, { |
| 36 | + x: 60, y: 80 |
32 | 37 | }).perform() |
33 | 38 | ``` |
34 | 39 |
|
35 | | -- `DragMotion`, `GlideMotion` and `StrokeMotion` take points as `[x, y, ms]`. |
36 | | -- `ms` is the timestamp offset since the start of the motion; and must be |
37 | | - *monotonically increasing* and *non-negative*. |
38 | | -- `PinchMotion` takes `scale` and `{ x, y, distance, steps }`. |
39 | | -- `TwistMotion` takes `degrees` and `{ x, y, radius, steps }` (can be negative). |
| 40 | +| Motion | Device | Gesture | |
| 41 | +|--------|--------|---------| |
| 42 | +| `DragMotion` | mouse | drag across surface | |
| 43 | +| `GlideMotion` | finger | finger draw on surface | |
| 44 | +| `StrokeMotion` | pen | stylus stroke on surface | |
| 45 | +| `PinchMotion` | 2 fingers | pinch together/apart | |
| 46 | +| `TwistMotion` | 2 fingers | rotate around center | |
40 | 47 |
|
41 | | -## Spec |
| 48 | +- `DragMotion`, `GlideMotion` and `StrokeMotion` |
| 49 | + take points as `[x, y, ms]`. |
| 50 | +- `ms` is the timestamp offset since the start of the motion; |
| 51 | + must be *monotonically increasing* and *non-negative*. |
| 52 | +- `PinchMotion` takes `scale` and `{ x, y, distance, steps }`. |
| 53 | +- `TwistMotion` takes `degrees` and `{ x, y, radius, steps }`. |
42 | 54 |
|
43 | | -Full spec: `docs/spec/spec.md`. |
| 55 | +## Demo |
44 | 56 |
|
45 | | -## Server |
| 57 | +A PaperJS sketch-pad for testing motions visually. |
46 | 58 |
|
47 | | -Run a local static server: |
| 59 | +1. Start the pointerdriver server: `npx github:TheProfs/pointerdriver` |
| 60 | +2. Start the demo: `cd docs/demo && npm start` |
| 61 | +3. Open the demo in a browser. |
| 62 | +4. Import `pointerdriver` in the browser console (see above). |
| 63 | +5. Drive the `<canvas>` with motions. |
48 | 64 |
|
49 | | -```bash |
50 | | -npx github:TheProfs/pointerdriver |
51 | | -``` |
| 65 | +## Spec |
52 | 66 |
|
53 | | -Open `http://127.0.0.1:5619/`. |
| 67 | +Full spec: `docs/spec/spec.md`. |
54 | 68 |
|
55 | | -## Test |
| 69 | +## Run tests |
56 | 70 |
|
57 | 71 | ```bash |
58 | 72 | npm test |
59 | 73 | ``` |
60 | 74 |
|
61 | | -## License |
| 75 | +## License |
62 | 76 |
|
63 | | -MIT |
| 77 | +[MIT][license] |
64 | 78 |
|
65 | | -[test-badge]: https://github.com/TheProfs/pointerdriver/actions/workflows/test.yml/badge.svg |
| 79 | +[test-badge]: https://github.com/TheProfs/pointerdriver/actions/workflows/test.yml/badge.svg |
66 | 80 | [test]: https://github.com/TheProfs/pointerdriver/actions/workflows/test.yml |
| 81 | +[license]: https://opensource.org/licenses/MIT |
0 commit comments