@varlet/touch-emulator 3.14.1 → 3.15.0-alpha.1776572752298
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 +72 -102
- package/package.json +3 -3
package/iife.js
CHANGED
|
@@ -1,103 +1,73 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
touchEvent.shiftKey = shiftKey;
|
|
74
|
-
touchEvent.touches = getActiveTouches(mouseEvent);
|
|
75
|
-
touchEvent.targetTouches = getActiveTouches(mouseEvent);
|
|
76
|
-
touchEvent.changedTouches = createTouchListWithEvent(mouseEvent);
|
|
77
|
-
eventTarget.dispatchEvent(touchEvent);
|
|
78
|
-
}
|
|
79
|
-
function onMouse(mouseEvent, touchType) {
|
|
80
|
-
const { type, target } = mouseEvent;
|
|
81
|
-
initiated = isMousedown(type) ? true : isMouseup(type) ? false : initiated;
|
|
82
|
-
if (isMousemove(type) && !initiated) {
|
|
83
|
-
return;
|
|
84
|
-
}
|
|
85
|
-
if (isUpdateTarget(type)) {
|
|
86
|
-
eventTarget = target;
|
|
87
|
-
}
|
|
88
|
-
triggerTouch(touchType, mouseEvent);
|
|
89
|
-
if (isMouseup(type)) {
|
|
90
|
-
eventTarget = null;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
function createTouchEmulator() {
|
|
94
|
-
window.addEventListener("mousedown", (event) => onMouse(event, "touchstart"), true);
|
|
95
|
-
window.addEventListener("mousemove", (event) => onMouse(event, "touchmove"), true);
|
|
96
|
-
window.addEventListener("mouseup", (event) => onMouse(event, "touchend"), true);
|
|
97
|
-
}
|
|
98
|
-
if (inBrowser && !supportTouch) {
|
|
99
|
-
createTouchEmulator();
|
|
100
|
-
}
|
|
101
|
-
var varlet_touch_emulator_default = {};
|
|
102
|
-
return __toCommonJS(varlet_touch_emulator_exports);
|
|
1
|
+
var VarletTouchEmulator = (function() {
|
|
2
|
+
//#region index.js
|
|
3
|
+
const inBrowser = typeof window !== "undefined";
|
|
4
|
+
const supportTouch = inBrowser && "ontouchstart" in window;
|
|
5
|
+
let initiated = false;
|
|
6
|
+
let eventTarget;
|
|
7
|
+
const isMousedown = (eventType) => eventType === "mousedown";
|
|
8
|
+
const isMousemove = (eventType) => eventType === "mousemove";
|
|
9
|
+
const isMouseup = (eventType) => eventType === "mouseup";
|
|
10
|
+
const isUpdateTarget = (eventType) => isMousedown(eventType) || !eventTarget || eventTarget && !eventTarget.dispatchEvent;
|
|
11
|
+
function Touch(target, identifier, mouseEvent) {
|
|
12
|
+
const { clientX, clientY, screenX, screenY, pageX, pageY } = mouseEvent;
|
|
13
|
+
this.identifier = identifier;
|
|
14
|
+
this.target = target;
|
|
15
|
+
this.clientX = clientX;
|
|
16
|
+
this.clientY = clientY;
|
|
17
|
+
this.screenX = screenX;
|
|
18
|
+
this.screenY = screenY;
|
|
19
|
+
this.pageX = pageX;
|
|
20
|
+
this.pageY = pageY;
|
|
21
|
+
}
|
|
22
|
+
function createTouchList() {
|
|
23
|
+
const touchList = [];
|
|
24
|
+
touchList.item = function(index) {
|
|
25
|
+
return this[index] || null;
|
|
26
|
+
};
|
|
27
|
+
touchList.identifiedTouch = function(id) {
|
|
28
|
+
return this[id + 1] || null;
|
|
29
|
+
};
|
|
30
|
+
return touchList;
|
|
31
|
+
}
|
|
32
|
+
function createTouchListWithEvent(mouseEvent) {
|
|
33
|
+
const touchList = createTouchList();
|
|
34
|
+
touchList.push(new Touch(eventTarget, 1, mouseEvent));
|
|
35
|
+
return touchList;
|
|
36
|
+
}
|
|
37
|
+
function getActiveTouches(mouseEvent) {
|
|
38
|
+
const { type } = mouseEvent;
|
|
39
|
+
if (isMouseup(type)) return createTouchList();
|
|
40
|
+
return createTouchListWithEvent(mouseEvent);
|
|
41
|
+
}
|
|
42
|
+
function triggerTouch(touchType, mouseEvent) {
|
|
43
|
+
const { altKey, ctrlKey, metaKey, shiftKey } = mouseEvent;
|
|
44
|
+
const touchEvent = new Event(touchType, {
|
|
45
|
+
bubbles: true,
|
|
46
|
+
cancelable: true
|
|
47
|
+
});
|
|
48
|
+
touchEvent.altKey = altKey;
|
|
49
|
+
touchEvent.ctrlKey = ctrlKey;
|
|
50
|
+
touchEvent.metaKey = metaKey;
|
|
51
|
+
touchEvent.shiftKey = shiftKey;
|
|
52
|
+
touchEvent.touches = getActiveTouches(mouseEvent);
|
|
53
|
+
touchEvent.targetTouches = getActiveTouches(mouseEvent);
|
|
54
|
+
touchEvent.changedTouches = createTouchListWithEvent(mouseEvent);
|
|
55
|
+
eventTarget.dispatchEvent(touchEvent);
|
|
56
|
+
}
|
|
57
|
+
function onMouse(mouseEvent, touchType) {
|
|
58
|
+
const { type, target } = mouseEvent;
|
|
59
|
+
initiated = isMousedown(type) ? true : isMouseup(type) ? false : initiated;
|
|
60
|
+
if (isMousemove(type) && !initiated) return;
|
|
61
|
+
if (isUpdateTarget(type)) eventTarget = target;
|
|
62
|
+
triggerTouch(touchType, mouseEvent);
|
|
63
|
+
if (isMouseup(type)) eventTarget = null;
|
|
64
|
+
}
|
|
65
|
+
function createTouchEmulator() {
|
|
66
|
+
window.addEventListener("mousedown", (event) => onMouse(event, "touchstart"), true);
|
|
67
|
+
window.addEventListener("mousemove", (event) => onMouse(event, "touchmove"), true);
|
|
68
|
+
window.addEventListener("mouseup", (event) => onMouse(event, "touchend"), true);
|
|
69
|
+
}
|
|
70
|
+
if (inBrowser && !supportTouch) createTouchEmulator();
|
|
71
|
+
//#endregion
|
|
72
|
+
return {};
|
|
103
73
|
})();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@varlet/touch-emulator",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.15.0-alpha.1776572752298",
|
|
4
4
|
"description": "touch-emulator",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"emulator",
|
|
@@ -24,9 +24,9 @@
|
|
|
24
24
|
"index.js"
|
|
25
25
|
],
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"
|
|
27
|
+
"vite-plus": "0.1.18"
|
|
28
28
|
},
|
|
29
29
|
"scripts": {
|
|
30
|
-
"build": "
|
|
30
|
+
"build": "vp pack && node build.js"
|
|
31
31
|
}
|
|
32
32
|
}
|