@maple-design/touch-emulator-vue 0.0.0-stage → 1.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/iife.js +103 -0
- package/index.js +104 -0
- package/package.json +34 -3
- package/README.md +0 -3
package/iife.js
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var MapleTouchEmulator = (() => {
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
|
|
21
|
+
// index.js
|
|
22
|
+
var touch_emulator_exports = {};
|
|
23
|
+
__export(touch_emulator_exports, {
|
|
24
|
+
default: () => touch_emulator_default
|
|
25
|
+
});
|
|
26
|
+
var inBrowser = typeof window !== "undefined";
|
|
27
|
+
var supportTouch = inBrowser && "ontouchstart" in window;
|
|
28
|
+
var initiated = false;
|
|
29
|
+
var eventTarget;
|
|
30
|
+
var isMousedown = (eventType) => eventType === "mousedown";
|
|
31
|
+
var isMousemove = (eventType) => eventType === "mousemove";
|
|
32
|
+
var isMouseup = (eventType) => eventType === "mouseup";
|
|
33
|
+
var isUpdateTarget = (eventType) => isMousedown(eventType) || !eventTarget || eventTarget && !eventTarget.dispatchEvent;
|
|
34
|
+
function Touch(target, identifier, mouseEvent) {
|
|
35
|
+
const { clientX, clientY, screenX, screenY, pageX, pageY } = mouseEvent;
|
|
36
|
+
this.identifier = identifier;
|
|
37
|
+
this.target = target;
|
|
38
|
+
this.clientX = clientX;
|
|
39
|
+
this.clientY = clientY;
|
|
40
|
+
this.screenX = screenX;
|
|
41
|
+
this.screenY = screenY;
|
|
42
|
+
this.pageX = pageX;
|
|
43
|
+
this.pageY = pageY;
|
|
44
|
+
}
|
|
45
|
+
function createTouchList() {
|
|
46
|
+
const touchList = [];
|
|
47
|
+
touchList.item = function(index) {
|
|
48
|
+
return this[index] || null;
|
|
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));
|
|
58
|
+
return touchList;
|
|
59
|
+
}
|
|
60
|
+
function getActiveTouches(mouseEvent) {
|
|
61
|
+
const { type } = mouseEvent;
|
|
62
|
+
if (isMouseup(type)) {
|
|
63
|
+
return createTouchList();
|
|
64
|
+
}
|
|
65
|
+
return createTouchListWithEvent(mouseEvent);
|
|
66
|
+
}
|
|
67
|
+
function triggerTouch(touchType, mouseEvent) {
|
|
68
|
+
const { altKey, ctrlKey, metaKey, shiftKey } = mouseEvent;
|
|
69
|
+
const touchEvent = new Event(touchType, { bubbles: true, cancelable: true });
|
|
70
|
+
touchEvent.altKey = altKey;
|
|
71
|
+
touchEvent.ctrlKey = ctrlKey;
|
|
72
|
+
touchEvent.metaKey = metaKey;
|
|
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 touch_emulator_default = {};
|
|
102
|
+
return __toCommonJS(touch_emulator_exports);
|
|
103
|
+
})();
|
package/index.js
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
const inBrowser = typeof window !== 'undefined'
|
|
2
|
+
const supportTouch = inBrowser && 'ontouchstart' in window
|
|
3
|
+
let initiated = false
|
|
4
|
+
let eventTarget
|
|
5
|
+
|
|
6
|
+
const isMousedown = (eventType) => eventType === 'mousedown'
|
|
7
|
+
|
|
8
|
+
const isMousemove = (eventType) => eventType === 'mousemove'
|
|
9
|
+
|
|
10
|
+
const isMouseup = (eventType) => eventType === 'mouseup'
|
|
11
|
+
|
|
12
|
+
const isUpdateTarget = (eventType) =>
|
|
13
|
+
isMousedown(eventType) || !eventTarget || (eventTarget && !eventTarget.dispatchEvent)
|
|
14
|
+
|
|
15
|
+
function Touch(target, identifier, mouseEvent) {
|
|
16
|
+
const { clientX, clientY, screenX, screenY, pageX, pageY } = mouseEvent
|
|
17
|
+
|
|
18
|
+
this.identifier = identifier
|
|
19
|
+
this.target = target
|
|
20
|
+
this.clientX = clientX
|
|
21
|
+
this.clientY = clientY
|
|
22
|
+
this.screenX = screenX
|
|
23
|
+
this.screenY = screenY
|
|
24
|
+
this.pageX = pageX
|
|
25
|
+
this.pageY = pageY
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function createTouchList() {
|
|
29
|
+
const touchList = []
|
|
30
|
+
|
|
31
|
+
touchList.item = function (index) {
|
|
32
|
+
return this[index] || null
|
|
33
|
+
}
|
|
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))
|
|
45
|
+
return touchList
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function getActiveTouches(mouseEvent) {
|
|
49
|
+
const { type } = mouseEvent
|
|
50
|
+
|
|
51
|
+
if (isMouseup(type)) {
|
|
52
|
+
return createTouchList()
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return createTouchListWithEvent(mouseEvent)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function triggerTouch(touchType, mouseEvent) {
|
|
59
|
+
const { altKey, ctrlKey, metaKey, shiftKey } = mouseEvent
|
|
60
|
+
const touchEvent = new Event(touchType, { bubbles: true, cancelable: true })
|
|
61
|
+
|
|
62
|
+
touchEvent.altKey = altKey
|
|
63
|
+
touchEvent.ctrlKey = ctrlKey
|
|
64
|
+
touchEvent.metaKey = metaKey
|
|
65
|
+
touchEvent.shiftKey = shiftKey
|
|
66
|
+
|
|
67
|
+
touchEvent.touches = getActiveTouches(mouseEvent)
|
|
68
|
+
touchEvent.targetTouches = getActiveTouches(mouseEvent)
|
|
69
|
+
touchEvent.changedTouches = createTouchListWithEvent(mouseEvent)
|
|
70
|
+
|
|
71
|
+
eventTarget.dispatchEvent(touchEvent)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function onMouse(mouseEvent, touchType) {
|
|
75
|
+
const { type, target } = mouseEvent
|
|
76
|
+
|
|
77
|
+
initiated = isMousedown(type) ? true : isMouseup(type) ? false : initiated
|
|
78
|
+
|
|
79
|
+
if (isMousemove(type) && !initiated) {
|
|
80
|
+
return
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (isUpdateTarget(type)) {
|
|
84
|
+
eventTarget = target
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
triggerTouch(touchType, mouseEvent)
|
|
88
|
+
|
|
89
|
+
if (isMouseup(type)) {
|
|
90
|
+
eventTarget = null
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function createTouchEmulator() {
|
|
95
|
+
window.addEventListener('mousedown', (event) => onMouse(event, 'touchstart'), true)
|
|
96
|
+
window.addEventListener('mousemove', (event) => onMouse(event, 'touchmove'), true)
|
|
97
|
+
window.addEventListener('mouseup', (event) => onMouse(event, 'touchend'), true)
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if (inBrowser && !supportTouch) {
|
|
101
|
+
createTouchEmulator()
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export default {}
|
package/package.json
CHANGED
|
@@ -1,6 +1,37 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@maple-design/touch-emulator-vue",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "1.1.0",
|
|
4
|
+
"description": "touch-emulator",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"emulator",
|
|
7
|
+
"maple"
|
|
8
|
+
],
|
|
9
|
+
"homepage": "https://github.com/loca-spirit/maple-design-mobile#readme",
|
|
10
|
+
"bugs": {
|
|
11
|
+
"url": "https://github.com/loca-spirit/maple-design-mobile/issues"
|
|
12
|
+
},
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git+https://github.com/loca-spirit/maple-design-mobile.git",
|
|
16
|
+
"directory": "packages/touch-emulator"
|
|
17
|
+
},
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"author": "BeADre <beadre_wang@163.com>",
|
|
20
|
+
"type": "module",
|
|
21
|
+
"main": "index.js",
|
|
22
|
+
"module": "index.js",
|
|
23
|
+
"files": [
|
|
24
|
+
"iife.js",
|
|
25
|
+
"index.js"
|
|
26
|
+
],
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"tsup": "7.2.0"
|
|
29
|
+
},
|
|
30
|
+
"publishConfig": {
|
|
31
|
+
"access": "public",
|
|
32
|
+
"registry": "https://registry.npmjs.org/"
|
|
33
|
+
},
|
|
34
|
+
"scripts": {
|
|
35
|
+
"build": "tsup index.js --format iife --out-dir=. --globalName=MapleTouchEmulator && node build.js"
|
|
36
|
+
}
|
|
6
37
|
}
|
package/README.md
DELETED