@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.
Files changed (2) hide show
  1. package/iife.js +72 -102
  2. package/package.json +3 -3
package/iife.js CHANGED
@@ -1,103 +1,73 @@
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;
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 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.14.1",
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
- "tsup": "7.2.0"
27
+ "vite-plus": "0.1.18"
28
28
  },
29
29
  "scripts": {
30
- "build": "tsup index.js --format iife --out-dir=. --globalName=VarletTouchEmulator && node build.js"
30
+ "build": "vp pack && node build.js"
31
31
  }
32
32
  }