prosthetic-hand 2.0.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/lib/Finger.js +8 -3
- package/lib/Hand.js +39 -8
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -15,7 +15,7 @@ npm install prosthetic-hand
|
|
|
15
15
|
import Hand from 'prosthetic-hand';
|
|
16
16
|
|
|
17
17
|
const hand = new Hand();
|
|
18
|
-
const finger =
|
|
18
|
+
const finger = hand.growFinger('pointer', { pointerType: 'touch', pressure: 0.9 });
|
|
19
19
|
|
|
20
20
|
finger
|
|
21
21
|
.wait(500)
|
package/lib/Finger.js
CHANGED
|
@@ -6,7 +6,7 @@ import * as capabilities from './Capabilities.js';
|
|
|
6
6
|
// Self-incrementing identifier for touch ID and pointer ID.
|
|
7
7
|
// Fingers can either keep the same ID for their life, or request a new
|
|
8
8
|
// ID whenever they go down.
|
|
9
|
-
var fingerIdSequence =
|
|
9
|
+
var fingerIdSequence = 1000;
|
|
10
10
|
|
|
11
11
|
// 🖐️class Finger
|
|
12
12
|
// Represents a finger, capable of performing single touch/pointer/mouse synthetic
|
|
@@ -334,7 +334,10 @@ export default class Finger {
|
|
|
334
334
|
|
|
335
335
|
if (previousState.x !== this._state.x || previousState.y !== this._state.y) {
|
|
336
336
|
evType = 'move'
|
|
337
|
-
|
|
337
|
+
|
|
338
|
+
this._currentTarget =
|
|
339
|
+
this._hand._capturedTargets.get(this._id) ??
|
|
340
|
+
document.elementFromPoint(this._state.x, this._state.y);
|
|
338
341
|
}
|
|
339
342
|
/// TODO: Detect over/out events when the event target changes.
|
|
340
343
|
|
|
@@ -345,7 +348,9 @@ export default class Finger {
|
|
|
345
348
|
// TODO: Optionally reset the finger ID and grab a fresh one
|
|
346
349
|
|
|
347
350
|
this._graphic.style.display = 'block';
|
|
348
|
-
this._touchTargetWhenDowned = this._currentTarget =
|
|
351
|
+
this._touchTargetWhenDowned = this._currentTarget =
|
|
352
|
+
this._hand._capturedTargets.get(this._id) ??
|
|
353
|
+
document.elementFromPoint(this._state.x, this._state.y);
|
|
349
354
|
evType = 'down';
|
|
350
355
|
}
|
|
351
356
|
|
package/lib/Hand.js
CHANGED
|
@@ -3,11 +3,11 @@ import Finger from './Finger.js';
|
|
|
3
3
|
import * as capabilities from './Capabilities.js';
|
|
4
4
|
|
|
5
5
|
const TimingMode = {
|
|
6
|
-
Interval: 'INTERVAL',
|
|
7
|
-
Minimal: 'MINIMAL',
|
|
8
|
-
Instant: 'INSTANT',
|
|
9
|
-
Frame: 'FRAME',
|
|
10
|
-
FastFrame: 'FAST_FRAME'
|
|
6
|
+
Interval: Symbol('INTERVAL'),
|
|
7
|
+
Minimal: Symbol('MINIMAL'),
|
|
8
|
+
Instant: Symbol('INSTANT'),
|
|
9
|
+
Frame: Symbol('FRAME'),
|
|
10
|
+
FastFrame: Symbol('FAST_FRAME')
|
|
11
11
|
};
|
|
12
12
|
|
|
13
13
|
// 🖐️class Hand
|
|
@@ -34,7 +34,7 @@ export default class Hand {
|
|
|
34
34
|
this._fingers = [];
|
|
35
35
|
|
|
36
36
|
this._fingersAreIdle = true;
|
|
37
|
-
|
|
37
|
+
this._capturedTargets = new Map(),
|
|
38
38
|
|
|
39
39
|
/// TODO: Timing modes: minimal, interval, frames
|
|
40
40
|
|
|
@@ -261,7 +261,14 @@ export default class Hand {
|
|
|
261
261
|
// Fire all `MouseEvent`s and `PointerEvent`s
|
|
262
262
|
events.forEach( ev => {
|
|
263
263
|
// console.log('Dispatching: ', ev.type);
|
|
264
|
-
|
|
264
|
+
let el;
|
|
265
|
+
if (this._capturedTargets.has(ev.pointerId)) {
|
|
266
|
+
el = this._capturedTargets.get(ev.pointerId);
|
|
267
|
+
} else {
|
|
268
|
+
el = document.elementFromPoint(ev.clientX, ev.clientY);
|
|
269
|
+
this._hookProstheticCapture(el);
|
|
270
|
+
}
|
|
271
|
+
el.dispatchEvent(ev);
|
|
265
272
|
});
|
|
266
273
|
|
|
267
274
|
|
|
@@ -493,8 +500,32 @@ export default class Hand {
|
|
|
493
500
|
}
|
|
494
501
|
}
|
|
495
502
|
|
|
496
|
-
|
|
503
|
+
|
|
504
|
+
_hookProstheticCapture(el) {
|
|
505
|
+
if (el.__prostheticPointerCapture) { return; }
|
|
506
|
+
|
|
507
|
+
const captureFn = el.setPointerCapture;
|
|
508
|
+
const releaseFn = el.releasePointerCapture;
|
|
509
|
+
el.setPointerCapture = ((id)=> {
|
|
510
|
+
if (id >= 1000) {
|
|
511
|
+
console.log('capture', id, el)
|
|
512
|
+
this._capturedTargets.set(id, el);
|
|
513
|
+
} else
|
|
514
|
+
return captureFn.call(el, id);
|
|
515
|
+
} );
|
|
516
|
+
|
|
517
|
+
el.releasePointerCapture = ((id)=> {
|
|
518
|
+
if (this._capturedTargets.get(id) === el) {
|
|
519
|
+
console.log('release', id, el)
|
|
520
|
+
this._capturedTargets.delete(id);
|
|
521
|
+
} else
|
|
522
|
+
return releaseFn.call(el, id);
|
|
523
|
+
} );
|
|
524
|
+
|
|
525
|
+
el.__prostheticPointerCapture = true;
|
|
526
|
+
}
|
|
497
527
|
|
|
498
528
|
|
|
529
|
+
}
|
|
499
530
|
|
|
500
531
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "prosthetic-hand",
|
|
4
|
-
"version": "2.
|
|
4
|
+
"version": "2.1.0",
|
|
5
5
|
"description": "Automate synthetic touch/pointer events",
|
|
6
6
|
"exports": "./lib/Hand.js",
|
|
7
7
|
"files": [
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
},
|
|
14
14
|
"repository": {
|
|
15
15
|
"type": "git",
|
|
16
|
-
"url": "https://github.com/
|
|
16
|
+
"url": "https://github.com/Leaflet/prosthetic-hand/.git"
|
|
17
17
|
},
|
|
18
18
|
"author": "Iván Sánchez Ortega <ivan@sanchezortega.es>",
|
|
19
19
|
"license": "Beerware",
|