@varlet/touch-emulator 1.24.6 → 1.24.9

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.
Files changed (3) hide show
  1. package/iife.js +68 -68
  2. package/index.js +68 -68
  3. package/package.json +2 -1
package/iife.js CHANGED
@@ -1,92 +1,92 @@
1
- const inBrowser = typeof window !== 'undefined'
2
- const supportTouch = inBrowser && 'ontouchstart' in window
3
- let initiated = false
4
- let eventTarget
1
+ ;(() => {
2
+ const inBrowser = typeof window !== 'undefined'
3
+ const supportTouch = inBrowser && 'ontouchstart' in window
4
+ let initiated = false
5
+ let eventTarget
5
6
 
6
- const isMousedown = (eventType) => eventType === 'mousedown'
7
+ const isMousedown = (eventType) => eventType === 'mousedown'
7
8
 
8
- const isMousemove = (eventType) => eventType === 'mousemove'
9
+ const isMousemove = (eventType) => eventType === 'mousemove'
9
10
 
10
- const isMouseup = (eventType) => eventType === 'mouseup'
11
+ const isMouseup = (eventType) => eventType === 'mouseup'
11
12
 
12
- const isUpdateTarget = (eventType) =>
13
- isMousedown(eventType) || !eventTarget || (eventTarget && !eventTarget.dispatchEvent)
13
+ const isUpdateTarget = (eventType) =>
14
+ isMousedown(eventType) || !eventTarget || (eventTarget && !eventTarget.dispatchEvent)
14
15
 
15
- function Touch(target, identifier, mouseEvent) {
16
- const { clientX, clientY, screenX, screenY, pageX, pageY } = mouseEvent
16
+ function Touch(target, identifier, mouseEvent) {
17
+ const { clientX, clientY, screenX, screenY, pageX, pageY } = mouseEvent
17
18
 
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 updateTouchList(mouseEvent) {
29
- const touchList = createTouchList()
30
-
31
- touchList.push(new Touch(eventTarget, 1, mouseEvent))
32
- return touchList
33
- }
19
+ this.identifier = identifier
20
+ this.target = target
21
+ this.clientX = clientX
22
+ this.clientY = clientY
23
+ this.screenX = screenX
24
+ this.screenY = screenY
25
+ this.pageX = pageX
26
+ this.pageY = pageY
27
+ }
34
28
 
35
- function createTouchList() {
36
- const touchList = []
29
+ function updateTouchList(mouseEvent) {
30
+ const touchList = createTouchList()
37
31
 
38
- touchList.item = function (index) {
39
- return this[index] || null
32
+ touchList.push(new Touch(eventTarget, 1, mouseEvent))
33
+ return touchList
40
34
  }
41
35
 
42
- return touchList
43
- }
36
+ function createTouchList() {
37
+ const touchList = []
44
38
 
45
- function getActiveTouches(mouseEvent) {
46
- const { type } = mouseEvent
47
- if (isMouseup(type)) return createTouchList()
48
- return updateTouchList(mouseEvent)
49
- }
39
+ touchList.item = function (index) {
40
+ return this[index] || null
41
+ }
42
+
43
+ return touchList
44
+ }
50
45
 
51
- function triggerTouch(touchType, mouseEvent) {
52
- const { altKey, ctrlKey, metaKey, shiftKey } = mouseEvent
53
- const touchEvent = document.createEvent('Event')
54
- touchEvent.initEvent(touchType, true, true)
46
+ function getActiveTouches(mouseEvent) {
47
+ const { type } = mouseEvent
48
+ if (isMouseup(type)) return createTouchList()
49
+ return updateTouchList(mouseEvent)
50
+ }
55
51
 
56
- touchEvent.altKey = altKey
57
- touchEvent.ctrlKey = ctrlKey
58
- touchEvent.metaKey = metaKey
59
- touchEvent.shiftKey = shiftKey
52
+ function triggerTouch(touchType, mouseEvent) {
53
+ const { altKey, ctrlKey, metaKey, shiftKey } = mouseEvent
54
+ const touchEvent = document.createEvent('Event')
55
+ touchEvent.initEvent(touchType, true, true)
60
56
 
61
- touchEvent.touches = getActiveTouches(mouseEvent)
62
- touchEvent.targetTouches = getActiveTouches(mouseEvent)
63
- touchEvent.changedTouches = createTouchList(mouseEvent)
57
+ touchEvent.altKey = altKey
58
+ touchEvent.ctrlKey = ctrlKey
59
+ touchEvent.metaKey = metaKey
60
+ touchEvent.shiftKey = shiftKey
64
61
 
65
- eventTarget.dispatchEvent(touchEvent)
66
- }
62
+ touchEvent.touches = getActiveTouches(mouseEvent)
63
+ touchEvent.targetTouches = getActiveTouches(mouseEvent)
64
+ touchEvent.changedTouches = createTouchList(mouseEvent)
67
65
 
68
- function onMouse(mouseEvent, touchType) {
69
- const { type, target } = mouseEvent
66
+ eventTarget.dispatchEvent(touchEvent)
67
+ }
70
68
 
71
- initiated = isMousedown(type) ? true : isMouseup(type) ? false : initiated
69
+ function onMouse(mouseEvent, touchType) {
70
+ const { type, target } = mouseEvent
72
71
 
73
- if (isMousemove(type) && !initiated) return
72
+ initiated = isMousedown(type) ? true : isMouseup(type) ? false : initiated
74
73
 
75
- if (isUpdateTarget(type)) eventTarget = target
74
+ if (isMousemove(type) && !initiated) return
76
75
 
77
- triggerTouch(touchType, mouseEvent)
76
+ if (isUpdateTarget(type)) eventTarget = target
78
77
 
79
- if (isMouseup(type)) eventTarget = null
80
- }
78
+ triggerTouch(touchType, mouseEvent)
81
79
 
82
- function createTouchEmulator() {
83
- window.addEventListener('mousedown', (event) => onMouse(event, 'touchstart'), true)
84
- window.addEventListener('mousemove', (event) => onMouse(event, 'touchmove'), true)
85
- window.addEventListener('mouseup', (event) => onMouse(event, 'touchend'), true)
86
- }
80
+ if (isMouseup(type)) eventTarget = null
81
+ }
87
82
 
88
- if (inBrowser && !supportTouch) {
89
- createTouchEmulator()
90
- }
83
+ function createTouchEmulator() {
84
+ window.addEventListener('mousedown', (event) => onMouse(event, 'touchstart'), true)
85
+ window.addEventListener('mousemove', (event) => onMouse(event, 'touchmove'), true)
86
+ window.addEventListener('mouseup', (event) => onMouse(event, 'touchend'), true)
87
+ }
91
88
 
92
- module.exports = {}
89
+ if (inBrowser && !supportTouch) {
90
+ createTouchEmulator()
91
+ }
92
+ })()
package/index.js CHANGED
@@ -1,92 +1,92 @@
1
- ;(() => {
2
- const inBrowser = typeof window !== 'undefined'
3
- const supportTouch = inBrowser && 'ontouchstart' in window
4
- let initiated = false
5
- let eventTarget
1
+ const inBrowser = typeof window !== 'undefined'
2
+ const supportTouch = inBrowser && 'ontouchstart' in window
3
+ let initiated = false
4
+ let eventTarget
6
5
 
7
- const isMousedown = (eventType) => eventType === 'mousedown'
6
+ const isMousedown = (eventType) => eventType === 'mousedown'
8
7
 
9
- const isMousemove = (eventType) => eventType === 'mousemove'
8
+ const isMousemove = (eventType) => eventType === 'mousemove'
10
9
 
11
- const isMouseup = (eventType) => eventType === 'mouseup'
10
+ const isMouseup = (eventType) => eventType === 'mouseup'
12
11
 
13
- const isUpdateTarget = (eventType) =>
14
- isMousedown(eventType) || !eventTarget || (eventTarget && !eventTarget.dispatchEvent)
12
+ const isUpdateTarget = (eventType) =>
13
+ isMousedown(eventType) || !eventTarget || (eventTarget && !eventTarget.dispatchEvent)
15
14
 
16
- function Touch(target, identifier, mouseEvent) {
17
- const { clientX, clientY, screenX, screenY, pageX, pageY } = mouseEvent
15
+ function Touch(target, identifier, mouseEvent) {
16
+ const { clientX, clientY, screenX, screenY, pageX, pageY } = mouseEvent
18
17
 
19
- this.identifier = identifier
20
- this.target = target
21
- this.clientX = clientX
22
- this.clientY = clientY
23
- this.screenX = screenX
24
- this.screenY = screenY
25
- this.pageX = pageX
26
- this.pageY = pageY
27
- }
28
-
29
- function updateTouchList(mouseEvent) {
30
- const touchList = createTouchList()
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
+ }
31
27
 
32
- touchList.push(new Touch(eventTarget, 1, mouseEvent))
33
- return touchList
34
- }
28
+ function updateTouchList(mouseEvent) {
29
+ const touchList = createTouchList()
35
30
 
36
- function createTouchList() {
37
- const touchList = []
31
+ touchList.push(new Touch(eventTarget, 1, mouseEvent))
32
+ return touchList
33
+ }
38
34
 
39
- touchList.item = function (index) {
40
- return this[index] || null
41
- }
35
+ function createTouchList() {
36
+ const touchList = []
42
37
 
43
- return touchList
38
+ touchList.item = function (index) {
39
+ return this[index] || null
44
40
  }
45
41
 
46
- function getActiveTouches(mouseEvent) {
47
- const { type } = mouseEvent
48
- if (isMouseup(type)) return createTouchList()
49
- return updateTouchList(mouseEvent)
50
- }
42
+ return touchList
43
+ }
51
44
 
52
- function triggerTouch(touchType, mouseEvent) {
53
- const { altKey, ctrlKey, metaKey, shiftKey } = mouseEvent
54
- const touchEvent = document.createEvent('Event')
55
- touchEvent.initEvent(touchType, true, true)
45
+ function getActiveTouches(mouseEvent) {
46
+ const { type } = mouseEvent
47
+ if (isMouseup(type)) return createTouchList()
48
+ return updateTouchList(mouseEvent)
49
+ }
56
50
 
57
- touchEvent.altKey = altKey
58
- touchEvent.ctrlKey = ctrlKey
59
- touchEvent.metaKey = metaKey
60
- touchEvent.shiftKey = shiftKey
51
+ function triggerTouch(touchType, mouseEvent) {
52
+ const { altKey, ctrlKey, metaKey, shiftKey } = mouseEvent
53
+ const touchEvent = document.createEvent('Event')
54
+ touchEvent.initEvent(touchType, true, true)
61
55
 
62
- touchEvent.touches = getActiveTouches(mouseEvent)
63
- touchEvent.targetTouches = getActiveTouches(mouseEvent)
64
- touchEvent.changedTouches = createTouchList(mouseEvent)
56
+ touchEvent.altKey = altKey
57
+ touchEvent.ctrlKey = ctrlKey
58
+ touchEvent.metaKey = metaKey
59
+ touchEvent.shiftKey = shiftKey
65
60
 
66
- eventTarget.dispatchEvent(touchEvent)
67
- }
61
+ touchEvent.touches = getActiveTouches(mouseEvent)
62
+ touchEvent.targetTouches = getActiveTouches(mouseEvent)
63
+ touchEvent.changedTouches = createTouchList(mouseEvent)
68
64
 
69
- function onMouse(mouseEvent, touchType) {
70
- const { type, target } = mouseEvent
65
+ eventTarget.dispatchEvent(touchEvent)
66
+ }
71
67
 
72
- initiated = isMousedown(type) ? true : isMouseup(type) ? false : initiated
68
+ function onMouse(mouseEvent, touchType) {
69
+ const { type, target } = mouseEvent
73
70
 
74
- if (isMousemove(type) && !initiated) return
71
+ initiated = isMousedown(type) ? true : isMouseup(type) ? false : initiated
75
72
 
76
- if (isUpdateTarget(type)) eventTarget = target
73
+ if (isMousemove(type) && !initiated) return
77
74
 
78
- triggerTouch(touchType, mouseEvent)
75
+ if (isUpdateTarget(type)) eventTarget = target
79
76
 
80
- if (isMouseup(type)) eventTarget = null
81
- }
77
+ triggerTouch(touchType, mouseEvent)
82
78
 
83
- function createTouchEmulator() {
84
- window.addEventListener('mousedown', (event) => onMouse(event, 'touchstart'), true)
85
- window.addEventListener('mousemove', (event) => onMouse(event, 'touchmove'), true)
86
- window.addEventListener('mouseup', (event) => onMouse(event, 'touchend'), true)
87
- }
79
+ if (isMouseup(type)) eventTarget = null
80
+ }
88
81
 
89
- if (inBrowser && !supportTouch) {
90
- createTouchEmulator()
91
- }
92
- })()
82
+ function createTouchEmulator() {
83
+ window.addEventListener('mousedown', (event) => onMouse(event, 'touchstart'), true)
84
+ window.addEventListener('mousemove', (event) => onMouse(event, 'touchmove'), true)
85
+ window.addEventListener('mouseup', (event) => onMouse(event, 'touchend'), true)
86
+ }
87
+
88
+ if (inBrowser && !supportTouch) {
89
+ createTouchEmulator()
90
+ }
91
+
92
+ export default {}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@varlet/touch-emulator",
3
- "version": "1.24.6",
3
+ "version": "1.24.9",
4
4
  "description": "touch-emulator",
5
5
  "keywords": [
6
6
  "emulator",
@@ -10,6 +10,7 @@
10
10
  "homepage": "https://github.com/varletjs/varlet#readme",
11
11
  "license": "MIT",
12
12
  "main": "index.js",
13
+ "module": "index.js",
13
14
  "repository": {
14
15
  "type": "git",
15
16
  "url": "git+https://github.com/varletjs/varlet.git"