Skip to content

Commit 79f38e1

Browse files
committed
feat: restrctured in oop
1 parent f41ba27 commit 79f38e1

27 files changed

Lines changed: 1184 additions & 607 deletions

File tree

README.md

Lines changed: 114 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,63 +8,150 @@ Synthesize pointer, touch, and gesture events on any page.
88
npx github:TheProfs/pointerdriver
99
```
1010

11-
## Import in browser console
11+
> [!NOTE]
12+
> LLM Agents **must** read the `pointerdriver` skill first.
13+
> Ask your LLM to run: `pointerdriver --skill` and study it carefully.
1214
13-
Open your project in the browser,
14-
then paste in the DevTools console:
15+
## How it works:
16+
17+
1. Run your project however you want.
18+
We're assuming it's running on `localhost:3000`
19+
2. Run a pointerdriver server with `npx github:TheProfs/pointerdriver`
20+
3. Go in your browser console and run:
1521

1622
```js
1723
const {
1824
DragMotion, GlideMotion, StrokeMotion,
19-
PinchMotion, TwistMotion
25+
PinchMotion, TwistMotion, SwipeMotion
2026
} = await import('http://127.0.0.1:5619/pointerdriver.js')
2127
```
2228

23-
## Drive the page
29+
This loads `pointerdriver` and allows executing any of the following motions:
30+
31+
## Motions
32+
33+
Create a motion by running: `new Motion(arguments).perform()`.
34+
35+
A motion is a *human-maneuver*;
36+
Regardless of the arguments you use for it, a motion eventually
37+
generates the exact sequence of events that would be generated
38+
from a real device.
39+
40+
41+
### `DragMotion(el, points)`
42+
43+
Mouse drag across a surface.
44+
45+
| Param | Description |
46+
|----------|--------------------------------------------|
47+
| `el` | target element |
48+
| `points` | `[x, y, ms][]`; `ms` monotonic and `>= 0` |
2449

2550
```js
2651
await new DragMotion(document.querySelector('#el'), [
2752
[30, 50, 0],
2853
[60, 80, 16],
2954
]).perform()
55+
```
56+
57+
### `GlideMotion(el, points)`
58+
59+
Finger draw on a surface.
60+
61+
| Param | Description |
62+
|----------|--------------------------------------------|
63+
| `el` | target element |
64+
| `points` | `[x, y, ms][]`; `ms` monotonic and `>= 0` |
3065

66+
```js
67+
await new GlideMotion(document.querySelector('#el'), [
68+
[30, 50, 0],
69+
[60, 80, 16],
70+
]).perform()
71+
```
72+
73+
### `StrokeMotion(el, points)`
74+
75+
Pen stylus stroke on a surface.
76+
77+
| Param | Description |
78+
|----------|--------------------------------------------|
79+
| `el` | target element |
80+
| `points` | `[x, y, ms][]`; `ms` monotonic and `>= 0` |
81+
82+
```js
83+
await new StrokeMotion(document.querySelector('#el'), [
84+
[30, 50, 0],
85+
[60, 80, 16],
86+
]).perform()
87+
```
88+
89+
### `PinchMotion(el, scale, { x, y, distance, steps })`
90+
91+
Two-finger pinch together or apart.
92+
93+
| Param | Default | Description |
94+
|------------|---------|--------------------------|
95+
| `el` | | target element |
96+
| `scale` | | target scale factor |
97+
| `x`, `y` | | gesture center |
98+
| `distance` | `100` | initial finger gap in px |
99+
| `steps` | `20` | interpolation frames |
100+
101+
```js
31102
await new PinchMotion(document.querySelector('#el'), 2, {
32103
x: 60, y: 80
33104
}).perform()
105+
```
34106

107+
### `TwistMotion(el, degrees, { x, y, radius, steps })`
108+
109+
Two-finger rotation around a center point.
110+
111+
| Param | Default | Description |
112+
|-----------|---------|-----------------------------|
113+
| `el` | | target element |
114+
| `degrees` | `45` | rotation angle |
115+
| `x`, `y` | | gesture center |
116+
| `radius` | `80` | finger distance from center |
117+
| `steps` | `20` | interpolation frames |
118+
119+
```js
35120
await new TwistMotion(document.querySelector('#el'), 45, {
36121
x: 60, y: 80
37122
}).perform()
38123
```
39124

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 |
125+
### `SwipeMotion(el, distance, { x, y, angle, separation, steps })`
126+
127+
Two-finger parallel drag.
47128

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 }`.
129+
| Param | Default | Description |
130+
|--------------|---------|---------------------------|
131+
| `el` | | target element |
132+
| `distance` | | travel distance in px |
133+
| `x`, `y` | | gesture center |
134+
| `angle` | `0` | direction in degrees |
135+
| `separation` | `40` | gap between fingers in px |
136+
| `steps` | `20` | interpolation frames |
137+
138+
```js
139+
await new SwipeMotion(document.querySelector('#el'), 200, {
140+
x: 60, y: 80
141+
}).perform()
142+
```
54143

55-
## Demo
144+
## Notes:
56145

57-
A PaperJS sketch-pad for testing motions visually.
146+
- The module server only serves `/pointerdriver.js` and `/src/*/index.js`.
147+
- It sets permissive CORS headers so you can import it from any page.
58148

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.
149+
## HTTPS pages
64150

65-
## Spec
151+
If the target page is HTTPS,
152+
importing pointerdriver from HTTP is blocked as mixed content.
153+
Serve pointerdriver over HTTPS (see `bin/skill.md` for one approach).
66154

67-
Full spec: `docs/spec/spec.md`.
68155

69156
## Run tests
70157

0 commit comments

Comments
 (0)