@varlet/touch-emulator 2.22.0 → 2.22.1
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/iife.js +12 -8
- package/index.js +17 -10
- package/package.json +1 -1
package/iife.js
CHANGED
|
@@ -42,23 +42,27 @@ var VarletTouchEmulator = (() => {
|
|
|
42
42
|
this.pageX = pageX;
|
|
43
43
|
this.pageY = pageY;
|
|
44
44
|
}
|
|
45
|
-
function updateTouchList(mouseEvent) {
|
|
46
|
-
const touchList = createTouchList();
|
|
47
|
-
touchList.push(new Touch(eventTarget, 1, mouseEvent));
|
|
48
|
-
return touchList;
|
|
49
|
-
}
|
|
50
45
|
function createTouchList() {
|
|
51
46
|
const touchList = [];
|
|
52
47
|
touchList.item = function(index) {
|
|
53
48
|
return this[index] || null;
|
|
54
49
|
};
|
|
50
|
+
touchList.identifiedTouch = function(id) {
|
|
51
|
+
return this[id + 1] || null;
|
|
52
|
+
};
|
|
53
|
+
return touchList;
|
|
54
|
+
}
|
|
55
|
+
function createTouchListWithEvent(mouseEvent) {
|
|
56
|
+
const touchList = createTouchList();
|
|
57
|
+
touchList.push(new Touch(eventTarget, 1, mouseEvent));
|
|
55
58
|
return touchList;
|
|
56
59
|
}
|
|
57
60
|
function getActiveTouches(mouseEvent) {
|
|
58
61
|
const { type } = mouseEvent;
|
|
59
|
-
if (isMouseup(type))
|
|
62
|
+
if (isMouseup(type)) {
|
|
60
63
|
return createTouchList();
|
|
61
|
-
|
|
64
|
+
}
|
|
65
|
+
return createTouchListWithEvent(mouseEvent);
|
|
62
66
|
}
|
|
63
67
|
function triggerTouch(touchType, mouseEvent) {
|
|
64
68
|
const { altKey, ctrlKey, metaKey, shiftKey } = mouseEvent;
|
|
@@ -69,7 +73,7 @@ var VarletTouchEmulator = (() => {
|
|
|
69
73
|
touchEvent.shiftKey = shiftKey;
|
|
70
74
|
touchEvent.touches = getActiveTouches(mouseEvent);
|
|
71
75
|
touchEvent.targetTouches = getActiveTouches(mouseEvent);
|
|
72
|
-
touchEvent.changedTouches =
|
|
76
|
+
touchEvent.changedTouches = createTouchListWithEvent(mouseEvent);
|
|
73
77
|
eventTarget.dispatchEvent(touchEvent);
|
|
74
78
|
}
|
|
75
79
|
function onMouse(mouseEvent, touchType) {
|
package/index.js
CHANGED
|
@@ -25,13 +25,6 @@ function Touch(target, identifier, mouseEvent) {
|
|
|
25
25
|
this.pageY = pageY
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
function updateTouchList(mouseEvent) {
|
|
29
|
-
const touchList = createTouchList()
|
|
30
|
-
|
|
31
|
-
touchList.push(new Touch(eventTarget, 1, mouseEvent))
|
|
32
|
-
return touchList
|
|
33
|
-
}
|
|
34
|
-
|
|
35
28
|
function createTouchList() {
|
|
36
29
|
const touchList = []
|
|
37
30
|
|
|
@@ -39,13 +32,27 @@ function createTouchList() {
|
|
|
39
32
|
return this[index] || null
|
|
40
33
|
}
|
|
41
34
|
|
|
35
|
+
touchList.identifiedTouch = function (id) {
|
|
36
|
+
return this[id + 1] || null
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return touchList
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function createTouchListWithEvent(mouseEvent) {
|
|
43
|
+
const touchList = createTouchList()
|
|
44
|
+
touchList.push(new Touch(eventTarget, 1, mouseEvent))
|
|
42
45
|
return touchList
|
|
43
46
|
}
|
|
44
47
|
|
|
45
48
|
function getActiveTouches(mouseEvent) {
|
|
46
49
|
const { type } = mouseEvent
|
|
47
|
-
|
|
48
|
-
|
|
50
|
+
|
|
51
|
+
if (isMouseup(type)) {
|
|
52
|
+
return createTouchList()
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return createTouchListWithEvent(mouseEvent)
|
|
49
56
|
}
|
|
50
57
|
|
|
51
58
|
function triggerTouch(touchType, mouseEvent) {
|
|
@@ -59,7 +66,7 @@ function triggerTouch(touchType, mouseEvent) {
|
|
|
59
66
|
|
|
60
67
|
touchEvent.touches = getActiveTouches(mouseEvent)
|
|
61
68
|
touchEvent.targetTouches = getActiveTouches(mouseEvent)
|
|
62
|
-
touchEvent.changedTouches =
|
|
69
|
+
touchEvent.changedTouches = createTouchListWithEvent(mouseEvent)
|
|
63
70
|
|
|
64
71
|
eventTarget.dispatchEvent(touchEvent)
|
|
65
72
|
}
|