touchsweep
Advanced tools
Comparing version 2.0.0 to 2.0.1
@@ -1,14 +0,8 @@ | ||
(function (factory) { | ||
if (typeof module === "object" && typeof module.exports === "object") { | ||
var v = factory(require, exports); | ||
if (v !== undefined) module.exports = v; | ||
} | ||
else if (typeof define === "function" && define.amd) { | ||
define(["require", "exports"], factory); | ||
} | ||
})(function (require, exports) { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : | ||
typeof define === 'function' && define.amd ? define(['exports'], factory) : | ||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.Touchsweep = {})); | ||
})(this, (function (exports) { 'use strict'; | ||
exports.TouchSwipeEventType = void 0; | ||
var TouchSwipeEventType; | ||
(function (TouchSwipeEventType) { | ||
@@ -20,3 +14,3 @@ TouchSwipeEventType["tap"] = "tap"; | ||
TouchSwipeEventType["right"] = "swiperight"; | ||
})(TouchSwipeEventType = exports.TouchSwipeEventType || (exports.TouchSwipeEventType = {})); | ||
})(exports.TouchSwipeEventType || (exports.TouchSwipeEventType = {})); | ||
var TouchSweep = /** @class */ (function () { | ||
@@ -73,16 +67,23 @@ function TouchSweep(element, data, threshold) { | ||
var _a = this.coords, startX = _a.startX, startY = _a.startY, endX = _a.endX, endY = _a.endY; | ||
if (endX < startX && Math.abs(endX - startX) > threshold) { | ||
return TouchSwipeEventType.left; | ||
var distanceX = Math.abs(endX - startX); | ||
var distanceY = Math.abs(endY - startY); | ||
var isSwipeX = distanceX > distanceY; | ||
if (isSwipeX) { | ||
if (endX < startX && distanceX > threshold) { | ||
return exports.TouchSwipeEventType.left; | ||
} | ||
if (endX > startX && distanceX > threshold) { | ||
return exports.TouchSwipeEventType.right; | ||
} | ||
} | ||
if (endX > startX && Math.abs(endX - startX) > threshold) { | ||
return TouchSwipeEventType.right; | ||
else { | ||
if (endY < startY && distanceY > threshold) { | ||
return exports.TouchSwipeEventType.up; | ||
} | ||
if (endY > startY && distanceY > threshold) { | ||
return exports.TouchSwipeEventType.down; | ||
} | ||
} | ||
if (endY < startY && Math.abs(endY - startY) > threshold) { | ||
return TouchSwipeEventType.up; | ||
} | ||
if (endY > startY && Math.abs(endY - startY) > threshold) { | ||
return TouchSwipeEventType.down; | ||
} | ||
if (endY === startY && endX === startX) { | ||
return TouchSwipeEventType.tap; | ||
return exports.TouchSwipeEventType.tap; | ||
} | ||
@@ -103,4 +104,8 @@ return ''; | ||
}()); | ||
exports.default = TouchSweep; | ||
}); | ||
//# sourceMappingURL=touchsweep.js.map | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
})); | ||
//# sourceMappingURL=touchsweep.js.map |
{ | ||
"name": "touchsweep", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"description": "Super tiny vanilla JS module to detect swipe direction", | ||
@@ -30,12 +30,15 @@ "keywords": [ | ||
"clean": "rm -rf dist && rm -rf demo/dist", | ||
"build": "yarn clean && tsc --skipLibCheck && yarn copy" | ||
"build": "yarn clean && rollup -c && yarn copy" | ||
}, | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"@typescript-eslint/eslint-plugin": "5.38.1", | ||
"@typescript-eslint/parser": "5.38.1", | ||
"eslint": "8.24.0", | ||
"@rollup/plugin-commonjs": "23.0.2", | ||
"@rollup/plugin-typescript": "9.0.2", | ||
"@typescript-eslint/eslint-plugin": "5.42.0", | ||
"@typescript-eslint/parser": "5.42.0", | ||
"eslint": "8.26.0", | ||
"eslint-config-prettier": "8.5.0", | ||
"rollup": "3.2.5", | ||
"typescript": "4.8.4" | ||
} | ||
} |
@@ -75,19 +75,24 @@ export const enum TouchSwipeEventType { | ||
const { startX, startY, endX, endY } = this.coords; | ||
const distanceX = Math.abs(endX - startX); | ||
const distanceY = Math.abs(endY - startY); | ||
const isSwipeX = distanceX > distanceY; | ||
if (endX < startX && Math.abs(endX - startX) > threshold) { | ||
return TouchSwipeEventType.left; | ||
} | ||
if (isSwipeX) { | ||
if (endX < startX && distanceX > threshold) { | ||
return TouchSwipeEventType.left; | ||
} | ||
if (endX > startX && Math.abs(endX - startX) > threshold) { | ||
return TouchSwipeEventType.right; | ||
} | ||
if (endX > startX && distanceX > threshold) { | ||
return TouchSwipeEventType.right; | ||
} | ||
} else { | ||
if (endY < startY && distanceY > threshold) { | ||
return TouchSwipeEventType.up; | ||
} | ||
if (endY < startY && Math.abs(endY - startY) > threshold) { | ||
return TouchSwipeEventType.up; | ||
if (endY > startY && distanceY > threshold) { | ||
return TouchSwipeEventType.down; | ||
} | ||
} | ||
if (endY > startY && Math.abs(endY - startY) > threshold) { | ||
return TouchSwipeEventType.down; | ||
} | ||
if (endY === startY && endX === startX) { | ||
@@ -94,0 +99,0 @@ return TouchSwipeEventType.tap; |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
23503
218
0
8