@varlet/touch-emulator 2.0.0-alpha.1663499244572 → 2.0.0-alpha.1664031123039

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 (4) hide show
  1. package/LICENCE +21 -21
  2. package/iife.js +91 -91
  3. package/index.js +91 -91
  4. package/package.json +1 -1
package/LICENCE CHANGED
@@ -1,21 +1,21 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2020 varlet
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 varlet
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/iife.js CHANGED
@@ -1,91 +1,91 @@
1
- ;(() => {
2
- const inBrowser = typeof window !== 'undefined'
3
- const supportTouch = inBrowser && 'ontouchstart' in window
4
- let initiated = false
5
- let eventTarget
6
-
7
- const isMousedown = (eventType) => eventType === 'mousedown'
8
-
9
- const isMousemove = (eventType) => eventType === 'mousemove'
10
-
11
- const isMouseup = (eventType) => eventType === 'mouseup'
12
-
13
- const isUpdateTarget = (eventType) =>
14
- isMousedown(eventType) || !eventTarget || (eventTarget && !eventTarget.dispatchEvent)
15
-
16
- function Touch(target, identifier, mouseEvent) {
17
- const { clientX, clientY, screenX, screenY, pageX, pageY } = mouseEvent
18
-
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()
31
-
32
- touchList.push(new Touch(eventTarget, 1, mouseEvent))
33
- return touchList
34
- }
35
-
36
- function createTouchList() {
37
- const touchList = []
38
-
39
- touchList.item = function (index) {
40
- return this[index] || null
41
- }
42
-
43
- return touchList
44
- }
45
-
46
- function getActiveTouches(mouseEvent) {
47
- const { type } = mouseEvent
48
- if (isMouseup(type)) return createTouchList()
49
- return updateTouchList(mouseEvent)
50
- }
51
-
52
- function triggerTouch(touchType, mouseEvent) {
53
- const { altKey, ctrlKey, metaKey, shiftKey } = mouseEvent
54
- const touchEvent = new Event(touchType, { bubbles: true, cancelable: true })
55
-
56
- touchEvent.altKey = altKey
57
- touchEvent.ctrlKey = ctrlKey
58
- touchEvent.metaKey = metaKey
59
- touchEvent.shiftKey = shiftKey
60
-
61
- touchEvent.touches = getActiveTouches(mouseEvent)
62
- touchEvent.targetTouches = getActiveTouches(mouseEvent)
63
- touchEvent.changedTouches = createTouchList()
64
-
65
- eventTarget.dispatchEvent(touchEvent)
66
- }
67
-
68
- function onMouse(mouseEvent, touchType) {
69
- const { type, target } = mouseEvent
70
-
71
- initiated = isMousedown(type) ? true : isMouseup(type) ? false : initiated
72
-
73
- if (isMousemove(type) && !initiated) return
74
-
75
- if (isUpdateTarget(type)) eventTarget = target
76
-
77
- triggerTouch(touchType, mouseEvent)
78
-
79
- if (isMouseup(type)) eventTarget = null
80
- }
81
-
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
- })()
1
+ ;(() => {
2
+ const inBrowser = typeof window !== 'undefined'
3
+ const supportTouch = inBrowser && 'ontouchstart' in window
4
+ let initiated = false
5
+ let eventTarget
6
+
7
+ const isMousedown = (eventType) => eventType === 'mousedown'
8
+
9
+ const isMousemove = (eventType) => eventType === 'mousemove'
10
+
11
+ const isMouseup = (eventType) => eventType === 'mouseup'
12
+
13
+ const isUpdateTarget = (eventType) =>
14
+ isMousedown(eventType) || !eventTarget || (eventTarget && !eventTarget.dispatchEvent)
15
+
16
+ function Touch(target, identifier, mouseEvent) {
17
+ const { clientX, clientY, screenX, screenY, pageX, pageY } = mouseEvent
18
+
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()
31
+
32
+ touchList.push(new Touch(eventTarget, 1, mouseEvent))
33
+ return touchList
34
+ }
35
+
36
+ function createTouchList() {
37
+ const touchList = []
38
+
39
+ touchList.item = function (index) {
40
+ return this[index] || null
41
+ }
42
+
43
+ return touchList
44
+ }
45
+
46
+ function getActiveTouches(mouseEvent) {
47
+ const { type } = mouseEvent
48
+ if (isMouseup(type)) return createTouchList()
49
+ return updateTouchList(mouseEvent)
50
+ }
51
+
52
+ function triggerTouch(touchType, mouseEvent) {
53
+ const { altKey, ctrlKey, metaKey, shiftKey } = mouseEvent
54
+ const touchEvent = new Event(touchType, { bubbles: true, cancelable: true })
55
+
56
+ touchEvent.altKey = altKey
57
+ touchEvent.ctrlKey = ctrlKey
58
+ touchEvent.metaKey = metaKey
59
+ touchEvent.shiftKey = shiftKey
60
+
61
+ touchEvent.touches = getActiveTouches(mouseEvent)
62
+ touchEvent.targetTouches = getActiveTouches(mouseEvent)
63
+ touchEvent.changedTouches = createTouchList()
64
+
65
+ eventTarget.dispatchEvent(touchEvent)
66
+ }
67
+
68
+ function onMouse(mouseEvent, touchType) {
69
+ const { type, target } = mouseEvent
70
+
71
+ initiated = isMousedown(type) ? true : isMouseup(type) ? false : initiated
72
+
73
+ if (isMousemove(type) && !initiated) return
74
+
75
+ if (isUpdateTarget(type)) eventTarget = target
76
+
77
+ triggerTouch(touchType, mouseEvent)
78
+
79
+ if (isMouseup(type)) eventTarget = null
80
+ }
81
+
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
+ })()
package/index.js CHANGED
@@ -1,91 +1,91 @@
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 updateTouchList(mouseEvent) {
29
- const touchList = createTouchList()
30
-
31
- touchList.push(new Touch(eventTarget, 1, mouseEvent))
32
- return touchList
33
- }
34
-
35
- function createTouchList() {
36
- const touchList = []
37
-
38
- touchList.item = function (index) {
39
- return this[index] || null
40
- }
41
-
42
- return touchList
43
- }
44
-
45
- function getActiveTouches(mouseEvent) {
46
- const { type } = mouseEvent
47
- if (isMouseup(type)) return createTouchList()
48
- return updateTouchList(mouseEvent)
49
- }
50
-
51
- function triggerTouch(touchType, mouseEvent) {
52
- const { altKey, ctrlKey, metaKey, shiftKey } = mouseEvent
53
- const touchEvent = new Event(touchType, { bubbles: true, cancelable: true })
54
-
55
- touchEvent.altKey = altKey
56
- touchEvent.ctrlKey = ctrlKey
57
- touchEvent.metaKey = metaKey
58
- touchEvent.shiftKey = shiftKey
59
-
60
- touchEvent.touches = getActiveTouches(mouseEvent)
61
- touchEvent.targetTouches = getActiveTouches(mouseEvent)
62
- touchEvent.changedTouches = createTouchList()
63
-
64
- eventTarget.dispatchEvent(touchEvent)
65
- }
66
-
67
- function onMouse(mouseEvent, touchType) {
68
- const { type, target } = mouseEvent
69
-
70
- initiated = isMousedown(type) ? true : isMouseup(type) ? false : initiated
71
-
72
- if (isMousemove(type) && !initiated) return
73
-
74
- if (isUpdateTarget(type)) eventTarget = target
75
-
76
- triggerTouch(touchType, mouseEvent)
77
-
78
- if (isMouseup(type)) eventTarget = null
79
- }
80
-
81
- function createTouchEmulator() {
82
- window.addEventListener('mousedown', (event) => onMouse(event, 'touchstart'), true)
83
- window.addEventListener('mousemove', (event) => onMouse(event, 'touchmove'), true)
84
- window.addEventListener('mouseup', (event) => onMouse(event, 'touchend'), true)
85
- }
86
-
87
- if (inBrowser && !supportTouch) {
88
- createTouchEmulator()
89
- }
90
-
91
- export default {}
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 updateTouchList(mouseEvent) {
29
+ const touchList = createTouchList()
30
+
31
+ touchList.push(new Touch(eventTarget, 1, mouseEvent))
32
+ return touchList
33
+ }
34
+
35
+ function createTouchList() {
36
+ const touchList = []
37
+
38
+ touchList.item = function (index) {
39
+ return this[index] || null
40
+ }
41
+
42
+ return touchList
43
+ }
44
+
45
+ function getActiveTouches(mouseEvent) {
46
+ const { type } = mouseEvent
47
+ if (isMouseup(type)) return createTouchList()
48
+ return updateTouchList(mouseEvent)
49
+ }
50
+
51
+ function triggerTouch(touchType, mouseEvent) {
52
+ const { altKey, ctrlKey, metaKey, shiftKey } = mouseEvent
53
+ const touchEvent = new Event(touchType, { bubbles: true, cancelable: true })
54
+
55
+ touchEvent.altKey = altKey
56
+ touchEvent.ctrlKey = ctrlKey
57
+ touchEvent.metaKey = metaKey
58
+ touchEvent.shiftKey = shiftKey
59
+
60
+ touchEvent.touches = getActiveTouches(mouseEvent)
61
+ touchEvent.targetTouches = getActiveTouches(mouseEvent)
62
+ touchEvent.changedTouches = createTouchList()
63
+
64
+ eventTarget.dispatchEvent(touchEvent)
65
+ }
66
+
67
+ function onMouse(mouseEvent, touchType) {
68
+ const { type, target } = mouseEvent
69
+
70
+ initiated = isMousedown(type) ? true : isMouseup(type) ? false : initiated
71
+
72
+ if (isMousemove(type) && !initiated) return
73
+
74
+ if (isUpdateTarget(type)) eventTarget = target
75
+
76
+ triggerTouch(touchType, mouseEvent)
77
+
78
+ if (isMouseup(type)) eventTarget = null
79
+ }
80
+
81
+ function createTouchEmulator() {
82
+ window.addEventListener('mousedown', (event) => onMouse(event, 'touchstart'), true)
83
+ window.addEventListener('mousemove', (event) => onMouse(event, 'touchmove'), true)
84
+ window.addEventListener('mouseup', (event) => onMouse(event, 'touchend'), true)
85
+ }
86
+
87
+ if (inBrowser && !supportTouch) {
88
+ createTouchEmulator()
89
+ }
90
+
91
+ export default {}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@varlet/touch-emulator",
3
- "version": "2.0.0-alpha.1663499244572",
3
+ "version": "2.0.0-alpha.1664031123039",
4
4
  "description": "touch-emulator",
5
5
  "keywords": [
6
6
  "emulator",