@varlet/touch-emulator 2.16.2 → 2.16.3-alpha.1694267513697

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 (2) hide show
  1. package/iife.js +80 -75
  2. package/package.json +13 -3
package/iife.js CHANGED
@@ -1,91 +1,96 @@
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
-
1
+ "use strict";
2
+ var VarletTouchEmulator = (() => {
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 varlet_touch_emulator_exports = {};
23
+ __export(varlet_touch_emulator_exports, {
24
+ default: () => varlet_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;
16
34
  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
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;
27
44
  }
28
-
29
45
  function updateTouchList(mouseEvent) {
30
- const touchList = createTouchList()
31
-
32
- touchList.push(new Touch(eventTarget, 1, mouseEvent))
33
- return touchList
46
+ const touchList = createTouchList();
47
+ touchList.push(new Touch(eventTarget, 1, mouseEvent));
48
+ return touchList;
34
49
  }
35
-
36
50
  function createTouchList() {
37
- const touchList = []
38
-
39
- touchList.item = function (index) {
40
- return this[index] || null
41
- }
42
-
43
- return touchList
51
+ const touchList = [];
52
+ touchList.item = function(index) {
53
+ return this[index] || null;
54
+ };
55
+ return touchList;
44
56
  }
45
-
46
57
  function getActiveTouches(mouseEvent) {
47
- const { type } = mouseEvent
48
- if (isMouseup(type)) return createTouchList()
49
- return updateTouchList(mouseEvent)
58
+ const { type } = mouseEvent;
59
+ if (isMouseup(type))
60
+ return createTouchList();
61
+ return updateTouchList(mouseEvent);
50
62
  }
51
-
52
63
  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)
64
+ const { altKey, ctrlKey, metaKey, shiftKey } = mouseEvent;
65
+ const touchEvent = new Event(touchType, { bubbles: true, cancelable: true });
66
+ touchEvent.altKey = altKey;
67
+ touchEvent.ctrlKey = ctrlKey;
68
+ touchEvent.metaKey = metaKey;
69
+ touchEvent.shiftKey = shiftKey;
70
+ touchEvent.touches = getActiveTouches(mouseEvent);
71
+ touchEvent.targetTouches = getActiveTouches(mouseEvent);
72
+ touchEvent.changedTouches = createTouchList();
73
+ eventTarget.dispatchEvent(touchEvent);
66
74
  }
67
-
68
75
  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
76
+ const { type, target } = mouseEvent;
77
+ initiated = isMousedown(type) ? true : isMouseup(type) ? false : initiated;
78
+ if (isMousemove(type) && !initiated)
79
+ return;
80
+ if (isUpdateTarget(type))
81
+ eventTarget = target;
82
+ triggerTouch(touchType, mouseEvent);
83
+ if (isMouseup(type))
84
+ eventTarget = null;
80
85
  }
81
-
82
86
  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)
87
+ window.addEventListener("mousedown", (event) => onMouse(event, "touchstart"), true);
88
+ window.addEventListener("mousemove", (event) => onMouse(event, "touchmove"), true);
89
+ window.addEventListener("mouseup", (event) => onMouse(event, "touchend"), true);
86
90
  }
87
-
88
91
  if (inBrowser && !supportTouch) {
89
- createTouchEmulator()
92
+ createTouchEmulator();
90
93
  }
91
- })()
94
+ var varlet_touch_emulator_default = {};
95
+ return __toCommonJS(varlet_touch_emulator_exports);
96
+ })();
package/package.json CHANGED
@@ -1,22 +1,32 @@
1
1
  {
2
2
  "name": "@varlet/touch-emulator",
3
- "version": "2.16.2",
3
+ "version": "2.16.3-alpha.1694267513697",
4
4
  "description": "touch-emulator",
5
5
  "keywords": [
6
6
  "emulator",
7
7
  "varlet"
8
8
  ],
9
9
  "type": "module",
10
+ "main": "index.js",
11
+ "module": "index.js",
12
+ "files": [
13
+ "iife.js",
14
+ "index.js"
15
+ ],
10
16
  "author": "BeADre <beadre_wang@163.com>",
11
17
  "homepage": "https://github.com/varletjs/varlet#readme",
12
18
  "license": "MIT",
13
- "main": "index.js",
14
- "module": "index.js",
15
19
  "repository": {
16
20
  "type": "git",
17
21
  "url": "git+https://github.com/varletjs/varlet.git"
18
22
  },
19
23
  "bugs": {
20
24
  "url": "https://github.com/varletjs/varlet/issues"
25
+ },
26
+ "devDependencies": {
27
+ "tsup": "7.2.0"
28
+ },
29
+ "scripts": {
30
+ "build": "tsup index.js --format iife --out-dir=. --globalName=VarletTouchEmulator && node build.js"
21
31
  }
22
32
  }