Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

any-touch

Package Overview
Dependencies
Maintainers
1
Versions
149
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

any-touch - npm Package Compare versions

Comparing version 2.1.2 to 2.1.3

17

dist/any-touch.umd.js

@@ -442,6 +442,7 @@ (function (global, factory) {

var _this = _super.call(this) || this;
_this.v = '2.1.1';
_this.v = '2.1.2';
_this.__computeFunctionList = [];
_this.__computeFunctionCreatorList = [];
_this.__pluginContexts = [];
_this.__isIgnoreMouse = false;
_this.el = el;

@@ -498,2 +499,16 @@ _this.c = {};

}
else {
if ('touchstart' === event.type) {
this.__isIgnoreMouse = true;
}
else if ('touchmove' === event.type) {
this.__isIgnoreMouse = false;
}
if (this.__isIgnoreMouse && event.type.startsWith('mouse')) {
if ('mouseup' === event.type) {
this.__isIgnoreMouse = false;
}
return;
}
}
this.emit(TYPE_INPUT, input);

@@ -500,0 +515,0 @@ this.emit2("at:".concat(input.phase), input, {});

2

dist/any-touch.umd.min.js

@@ -1,2 +0,2 @@

!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).AnyTouch=e()}(this,(function(){"use strict";var t=function(e,n){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},t(e,n)};function e(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}var n=function(){return n=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var i in e=arguments[n])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t},n.apply(this,arguments)};function r(t){var e="function"==typeof Symbol&&Symbol.iterator,n=e&&t[e],r=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}var i=function(){function t(){this.__map={}}return t.prototype.beforeEach=function(t){this.__interceptor=t},t.prototype.on=function(t,e){var n,i,o=Array.isArray(t)?t:[t];try{for(var a=r(o),u=a.next();!u.done;u=a.next()){var c=u.value;this.__map[c]=this.__map[c]||[];var s=this.__map[c];s&&s.push(e)}}catch(t){n={error:t}}finally{try{u&&!u.done&&(i=a.return)&&i.call(a)}finally{if(n)throw n.error}}return this},t.prototype.emit=function(t,e,n){var r=this;void 0!==this.__interceptor?this.__interceptor(t,(function(){r.__emit(t,e),n&&n()})):(this.__emit(t,e),n&&n())},t.prototype.__emit=function(t,e){var n,i,o=this.__map[t];if(Array.isArray(o)&&(null==o?void 0:o.length))try{for(var a=r(o),u=a.next();!u.done;u=a.next()){(0,u.value)(e,t)}}catch(t){n={error:t}}finally{try{u&&!u.done&&(i=a.return)&&i.call(a)}finally{if(n)throw n.error}}this.event=e},t.prototype.off=function(t,e){var n=this.__map[t];if(void 0!==n)if(void 0===e)delete this.__map[t];else{var r=n.findIndex((function(t){return t===e}));n.splice(r,1)}},t.prototype.destroy=function(){this.__map={}},t}(),o="touchstart",a="touchmove",u="touchend",c="touchcancel",s="mouseup",p="mousemove",f="mousedown";var v,h="start",l="move",m="cancel",d="end",y=((v={})[4]=h,v[5]=l,v[1]=d,v[3]=m,v);function g(t){return y[t]}function _(t,e,n){var r,i,o,a,u,c,s,p={1:(r={},r[0]=(i={},i.move=4,i),r[4]=(o={},o.move=5,o[d]=1,o[m]=3,o),r[5]=(a={},a.move=5,a[d]=1,a[m]=3,a),r),0:(u={},u[4]=(c={},c.move=2,c[d]=1,c[m]=3,c),u[5]=(s={},s.start=2,s.move=2,s[d]=1,s[m]=3,s),u)}[Number(t)][e];return void 0!==p&&p[n]||0}function T(t){[1,3,2].includes(t.state)&&(t.state=0)}function x(t){return[5,1,3].includes(t)}function E(t){if(t.disabled)return t.state=0,!0}function b(t,e){return n(n(n({},t),e),{state:0,disabled:!1})}function L(t){return Math.round(100*t)/100}function M(){var t,e,r,i,o=0;return function(a){if(t=e,void 0!==a){var u=function(t,e){var n=t.phase,r=t.points,i=t.changedPoints,o=t.nativeEvent,a=r.length,u=h===n,c=d===n&&0===a||m===n,s=Date.now(),p=w(r)||w(i),f=p.x,v=p.y,l=o.currentTarget;return Object.assign(t,{id:e,x:f,y:v,timestamp:s,isStart:u,isEnd:c,pointLength:a,currentTarget:l,getOffset:function(t){void 0===t&&(t=l);var e=t.getBoundingClientRect();return{x:f-Math.round(e.left),y:v-Math.round(e.top)}}})}(a,o=Number.MAX_SAFE_INTEGER>o?++o:1);e=u;var c=u.isStart,s=u.pointLength;return c&&(r=u,t=void 0,i=1<s?u:void 0),n(n({},u),{prevInput:t,startMultiInput:i,startInput:r})}}}function w(t){var e=t.length;if(0<e){if(1===e){var n=t[0],r=n.clientX,i=n.clientY;return{x:Math.round(r),y:Math.round(i)}}var o=t.reduce((function(t,e){return t.x+=e.clientX,t.y+=e.clientY,t}),{x:0,y:0});return{x:Math.round(o.x/e),y:Math.round(o.y/e)}}}function A(t,e,n,r){var i,o={};for(var a in n)["target","currentTarget","type"].includes(a)||(o[a]=n[a]);return document.createEvent?(i=document.createEvent("HTMLEvents")).initEvent(t,null==r?void 0:r.bubbles,null==r?void 0:r.cancelable):i=new Event(t,r),Object.assign(i,o,{match:function(){return n.targets&&0<n.targets.length&&n.targets.every((function(t){return i.currentTarget.contains(t)}))}}),e.dispatchEvent(i)}function P(t,e){var n,r=e.preventDefault;return n=r,"[object Function]"===Object.prototype.toString.call(n)?r(t):!!r}var X=[o,a,u,c,f],S=[p,s];var Y="computed",I={domEvents:{bubbles:!0,cancelable:!0},preventDefault:function(t){if(t.target&&"tagName"in t.target){var e=t.target.tagName;return!/^(?:INPUT|TEXTAREA|BUTTON|SELECT)$/.test(e)}return!1}},O="at:after",D=function(t){function i(e,r){var i,o=t.call(this)||this;o.v="2.1.1",o.__computeFunctionList=[],o.__computeFunctionCreatorList=[],o.__pluginContexts=[],o.el=e,o.c={},o.__options=n(n({},I),r);var a,u,c,v,h=function(t){var e=M();return function(n){var r=[],i=[];Array.from(n.touches).forEach((function(e){var n=e.clientX,o=e.clientY,a=e.target;(null==t?void 0:t.contains(a))&&(r.push(a),i.push({clientX:n,clientY:o,target:a}))}));var o=Array.from(n.changedTouches).map((function(t){return{clientX:t.clientX,clientY:t.clientY,target:t.target}}));return e({phase:n.type.replace("touch",""),changedPoints:o,points:i,nativeEvent:n,target:n.target,targets:r})}}(o.el),l=(u=!1,c=null,v=M(),function(t){var e,n=t.clientX,r=t.clientY,i=t.type,o=t.button,h=t.target,l=[{clientX:n,clientY:r,target:h}];if(f===i&&0===o)c=h,u=!0,e="start";else{if(!u)return;p===i?e="move":s===i&&(l=[],e="end",u=!1)}var m=a||[{clientX:n,clientY:r,target:h}];if(a=[{clientX:n,clientY:r,target:h}],void 0!==e)return v({phase:e,changedPoints:m,points:l,target:c,targets:[c],nativeEvent:t})});if(o.__inputCreatorMap=((i={}).touchstart=h,i.touchmove=h,i.touchend=h,i.touchcancel=h,i.mousedown=l,i.mousemove=l,i.mouseup=l,i),o.on(O,(function(t){var e=t.target,n=t.__type,r=o.__options.domEvents;r&&void 0!==o.el&&e&&(A(n,e,t,r),A(O,e,t,r))})),void 0!==e){e.style.webkitTapHighlightColor="rgba(0,0,0,0)";var m=!1;try{var d={};Object.defineProperty(d,"passive",{get:function(){m=!0}}),window.addEventListener("_",(function(){}),d)}catch(t){}o.on("u",function(t,e,n){return X.forEach((function(r){t.addEventListener(r,e,n)})),S.forEach((function(t){window.addEventListener(t,e,n)})),function(){X.forEach((function(n){t.removeEventListener(n,e)})),S.forEach((function(t){window.removeEventListener(t,e)}))}}(e,o.catchEvent.bind(o),!1===o.__options.preventDefault&&m?{passive:!0}:{passive:!1}))}return o}return e(i,t),i.prototype.use=function(t,e){this.__pluginContexts.push(t(this,e))},i.prototype.catchEvent=function(t){var e=this.__inputCreatorMap[t.type](t);if(void 0!==e){var r=function(){return t.preventDefault()};P(t,this.__options)&&r(),this.emit("input",e),this.emit2("at:".concat(e.phase),e,{});var i={};this.__computeFunctionList.forEach((function(t){var n=t(e,i);if(void 0!==n)for(var r in n)i[r]=n[r]})),this.emit(Y,n(n(n({},e),i),{stopPropagation:function(){return t.stopPropagation()},stopImmediatePropagation:function(){return t.stopImmediatePropagation()},preventDefault:r}))}},i.prototype.compute=function(t,e){var n,i;try{for(var o=r(t),a=o.next();!a.done;a=o.next()){var u=a.value;this.__computeFunctionCreatorList.includes(u)||(this.__computeFunctionCreatorList.push(u),this.__computeFunctionList.push(u()))}}catch(t){n={error:t}}finally{try{a&&!a.done&&(i=o.return)&&i.call(o)}finally{if(n)throw n.error}}this.on(Y,e)},i.prototype.beforeEach=function(e){var n=this;t.prototype.beforeEach.call(this,(function(t,r){var i;(null===(i=n.c)||void 0===i?void 0:i.name)?e(t,r):r()}))},i.prototype.get=function(t){return this.__pluginContexts.find((function(e){return t===e.name}))},i.prototype.set=function(t){this.__options=n(n({},this.__options),t)},i.prototype.emit2=function(t,e,r){var i=this;this.c=r,this.emit(t,n(n({},e),{type:t}),(function(){i.emit(O,n(n({},e),{name:t,__type:t}))}))},i.prototype.destroy=function(){this.emit("u"),t.prototype.destroy.call(this)},i}(i),C=function(t){return Math.sqrt(t.x*t.x+t.y*t.y)},N=function(t){return t/Math.PI*180},j=function(t,e){var n=function(t,e){var n=C(t)*C(e);if(0===n)return 0;var r=function(t,e){return t.x*e.x+t.y*e.y}(t,e)/n;return r>1&&(r=1),Math.acos(r)}(t,e);return function(t,e){return t.x*e.y-e.x*t.y}(t,e)>0&&(n*=-1),N(n)},F=function(t,e){if(0!==t||0!==e)return Math.abs(t)>=Math.abs(e)?0<t?"right":"left":0<e?"down":"up"};function V(){var t=0,e=0;return function(n,r){var i=r.prevVecotr,o=r.startVecotr,a=r.activeVecotr;return a&&(e=Math.round(j(a,i)),t=Math.round(j(a,o))),{angle:t,deltaAngle:e}}}function R(){return function(t){var e=t.prevInput,n=0,r=0,i=0;if(void 0!==e&&(n=t.x-e.x,r=t.y-e.y,0!==n||0!==r)){var o=Math.sqrt(Math.pow(n,2)+Math.pow(r,2));i=Math.round(N(Math.acos(Math.abs(n)/o)))}return{deltaX:n,deltaY:r,deltaXYAngle:i}}}function B(){var t,e=0,n=0,r=0,i=0,o=0;return function(a){var u=a.phase,c=a.startInput;return h===u?(e=0,n=0,r=0,i=0,o=0):l===u&&(e=Math.round(a.points[0].clientX-c.points[0].clientX),n=Math.round(a.points[0].clientY-c.points[0].clientY),r=Math.abs(e),i=Math.abs(n),o=Math.round(C({x:r,y:i})),t=F(e,n)),{displacementX:e,displacementY:n,distanceX:r,distanceY:i,distance:o,overallDirection:t}}}function q(){var t=1;return function(e,n){var r=1,i=n.prevVecotr,o=n.startVecotr,a=n.activeVecotr;return a&&(r=L(C(a)/C(i)),t=L(C(a)/C(o))),{scale:t,deltaScale:r}}}function G(){var t,e,n=0,r=0,i=0,o=0;return function(a){if(void 0!==a){e=e||a.startInput;var u=a.timestamp-e.timestamp;if(16<u){var c=a.x-e.x,s=a.y-e.y;i=Math.round(c/u*100)/100,o=Math.round(s/u*100)/100,n=Math.abs(i),r=Math.abs(o),t=F(c,s),e=a}}return{velocityX:n,velocityY:r,speedX:i,speedY:o,direction:t}}}function H(){var t=0;return function(e){var n=e.phase;return h===n&&(t=e.pointLength),{maxPointLength:t}}}function U(t){return{x:t.points[1].clientX-t.points[0].clientX,y:t.points[1].clientY-t.points[0].clientY}}function k(){var t,e,n;return function(r){var i=r.prevInput,o=r.startMultiInput;return void 0!==o&&void 0!==i&&r.id!==o.id&&1<i.pointLength&&1<r.pointLength?(t=U(o),e=U(i),n=U(r)):n=void 0,{startVecotr:t,prevVecotr:e,activeVecotr:n}}}var Z={name:"tap",pointLength:1,tapTimes:1,waitNextTapTime:300,maxDistance:2,maxDistanceFromPrevTap:9,maxPressTime:250};function $(t,e){var n,r,i,o=b(Z,e),a=0;function u(){a=0,n=void 0,r=void 0}return t.compute([B,H],(function(e){if(!E(o)){var c,s,p,f,v=e.phase,h=e.x,l=e.y;if(d===v)o.state=0,c=e.startInput,s=e.pointLength,p=e.timestamp-c.timestamp,f=e.distance,e.maxPointLength===o.pointLength&&0===s&&o.maxDistance>=f&&o.maxPressTime>p?(clearTimeout(i),function(t,e){if(void 0!==n){var r=C({x:t.x-n.x,y:t.y-n.y});return n=t,e.maxDistanceFromPrevTap>=r}return n=t,!0}({x:h,y:l},o)&&function(t){var e=performance.now();if(void 0===r)return r=e,!0;var n=e-r;return r=e,n<t}(o.waitNextTapTime)?a++:a=1,0==a%o.tapTimes?(o.state=1,t.emit2(o.name,e,o),u()):i=setTimeout((function(){o.state=2,u()}),o.waitNextTapTime)):(u(),o.state=2)}})),o}var z={name:"pan",threshold:10,pointLength:1};function J(t,e){var n=b(z,e);return t.compute([G,B,R],(function(e){if(T(n),!E(n)){var r,i,o=(r=e.pointLength,i=e.distance,n.pointLength===r&&n.threshold<=i);if(n.state=_(o,n.state,e.phase),o||x(n.state)){var a=n.name;t.emit2(a,e,n),t.emit2(a+g(n.state),e,n),![d,m].includes(e.phase)&&e.direction&&t.emit2(a+e.direction,e,n)}}})),n}var K={name:"swipe",threshold:10,velocity:.3,pointLength:1};function Q(t,e){var n=b(K,e);return t.compute([B,G,H],(function(e){if(n.state=0,!n.disabled&&function(){if(d!==e.phase)return!1;var t=e.velocityX,r=e.velocityY,i=e.distance;return e.maxPointLength===n.pointLength&&0===e.points.length&&n.threshold<i&&n.velocity<Math.max(t,r)}()){var r=n.name;n.state=1,t.emit2(r,e,n),t.emit2(r+e.direction,e,n)}})),n}var W={name:"press",pointLength:1,maxDistance:9,minPressTime:251};function tt(t,e){var n=b(W,e),r=0;return t.compute([B],(function(e){if(!E(n)){var i,o=e.phase,a=e.startInput,u=e.pointLength;if(h===o&&n.pointLength===u)T(n),clearTimeout(r),r=setTimeout((function(){n.state=1,t.emit2(n.name,e,n)}),n.minPressTime);else if(d===o&&1===n.state)t.emit2("".concat(n.name).concat("up"),e,n);else if(1!==n.state){var c=e.timestamp-a.timestamp;(!((i=e.distance)&&n.maxDistance>i)||n.minPressTime>c&&[d,m].includes(o))&&(clearTimeout(r),n.state=2)}}})),n}var et={name:"pinch",threshold:0,pointLength:2};function nt(t,e){var n=b(et,e);return t.compute([k,q],(function(e){if(T(n),!E(n)){var r,i,o=(r=e.pointLength,i=e.scale,e.deltaScale,e.phase,n.pointLength===r&&n.threshold<Math.abs(i-1));n.state=_(o,n.state,e.phase);var a=n.name;if(o||x(n.state)){t.emit2(a,e,n);var u=e.deltaScale;1!==u&&t.emit2(a+(1<u?"in":"out"),e,n)}var c=g(n.state);c&&t.emit2(a+c,e,n)}})),n}var rt={name:"rotate",threshold:0,pointLength:2};function it(t,e){var n=b(rt,e);return t.compute([k,V],(function(e){if(!E(n)){T(n);var r,i,o=(r=e.pointLength,i=e.angle,n.pointLength===r&&n.threshold<Math.abs(i));n.state=_(o,n.state,e.phase);var a=n.name;(o||x(n.state))&&t.emit2(a,e,n);var u=g(n.state);u&&t.emit2(a+u,e,n)}})),n}function ot(t){t.use($,{name:"doubletap",tapTimes:2});var e,n=t.get("doubletap");return t.beforeEach((function(t,r){"tap"===t?(clearTimeout(e),e=setTimeout((function(){[0,2].includes(n.state)&&r()}),300)):r()})),n}return function(t){function n(e,n){var r=t.call(this,e,n)||this;return r.use($),r.use(J),r.use(Q),r.use(tt),r.use(nt),r.use(it),r}return e(n,t),n.STATE_POSSIBLE=0,n.STATE_START=4,n.STATE_MOVE=5,n.STATE_END=1,n.STATE_CANCELLED=3,n.STATE_FAILED=2,n.STATE_RECOGNIZED=1,n.tap=$,n.pan=J,n.swipe=Q,n.press=tt,n.rotate=it,n.pinch=nt,n.doubletap=ot,n}(D)}));
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).AnyTouch=e()}(this,(function(){"use strict";var t=function(e,n){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},t(e,n)};function e(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}var n=function(){return n=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var i in e=arguments[n])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t},n.apply(this,arguments)};function r(t){var e="function"==typeof Symbol&&Symbol.iterator,n=e&&t[e],r=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}var i=function(){function t(){this.__map={}}return t.prototype.beforeEach=function(t){this.__interceptor=t},t.prototype.on=function(t,e){var n,i,o=Array.isArray(t)?t:[t];try{for(var a=r(o),u=a.next();!u.done;u=a.next()){var c=u.value;this.__map[c]=this.__map[c]||[];var s=this.__map[c];s&&s.push(e)}}catch(t){n={error:t}}finally{try{u&&!u.done&&(i=a.return)&&i.call(a)}finally{if(n)throw n.error}}return this},t.prototype.emit=function(t,e,n){var r=this;void 0!==this.__interceptor?this.__interceptor(t,(function(){r.__emit(t,e),n&&n()})):(this.__emit(t,e),n&&n())},t.prototype.__emit=function(t,e){var n,i,o=this.__map[t];if(Array.isArray(o)&&(null==o?void 0:o.length))try{for(var a=r(o),u=a.next();!u.done;u=a.next()){(0,u.value)(e,t)}}catch(t){n={error:t}}finally{try{u&&!u.done&&(i=a.return)&&i.call(a)}finally{if(n)throw n.error}}this.event=e},t.prototype.off=function(t,e){var n=this.__map[t];if(void 0!==n)if(void 0===e)delete this.__map[t];else{var r=n.findIndex((function(t){return t===e}));n.splice(r,1)}},t.prototype.destroy=function(){this.__map={}},t}(),o="touchstart",a="touchmove",u="touchend",c="touchcancel",s="mouseup",p="mousemove",f="mousedown";var v,h="start",l="move",m="cancel",d="end",y=((v={})[4]=h,v[5]=l,v[1]=d,v[3]=m,v);function g(t){return y[t]}function _(t,e,n){var r,i,o,a,u,c,s,p={1:(r={},r[0]=(i={},i.move=4,i),r[4]=(o={},o.move=5,o[d]=1,o[m]=3,o),r[5]=(a={},a.move=5,a[d]=1,a[m]=3,a),r),0:(u={},u[4]=(c={},c.move=2,c[d]=1,c[m]=3,c),u[5]=(s={},s.start=2,s.move=2,s[d]=1,s[m]=3,s),u)}[Number(t)][e];return void 0!==p&&p[n]||0}function T(t){[1,3,2].includes(t.state)&&(t.state=0)}function x(t){return[5,1,3].includes(t)}function E(t){if(t.disabled)return t.state=0,!0}function b(t,e){return n(n(n({},t),e),{state:0,disabled:!1})}function M(t){return Math.round(100*t)/100}function L(){var t,e,r,i,o=0;return function(a){if(t=e,void 0!==a){var u=function(t,e){var n=t.phase,r=t.points,i=t.changedPoints,o=t.nativeEvent,a=r.length,u=h===n,c=d===n&&0===a||m===n,s=Date.now(),p=w(r)||w(i),f=p.x,v=p.y,l=o.currentTarget;return Object.assign(t,{id:e,x:f,y:v,timestamp:s,isStart:u,isEnd:c,pointLength:a,currentTarget:l,getOffset:function(t){void 0===t&&(t=l);var e=t.getBoundingClientRect();return{x:f-Math.round(e.left),y:v-Math.round(e.top)}}})}(a,o=Number.MAX_SAFE_INTEGER>o?++o:1);e=u;var c=u.isStart,s=u.pointLength;return c&&(r=u,t=void 0,i=1<s?u:void 0),n(n({},u),{prevInput:t,startMultiInput:i,startInput:r})}}}function w(t){var e=t.length;if(0<e){if(1===e){var n=t[0],r=n.clientX,i=n.clientY;return{x:Math.round(r),y:Math.round(i)}}var o=t.reduce((function(t,e){return t.x+=e.clientX,t.y+=e.clientY,t}),{x:0,y:0});return{x:Math.round(o.x/e),y:Math.round(o.y/e)}}}function A(t,e,n,r){var i,o={};for(var a in n)["target","currentTarget","type"].includes(a)||(o[a]=n[a]);return document.createEvent?(i=document.createEvent("HTMLEvents")).initEvent(t,null==r?void 0:r.bubbles,null==r?void 0:r.cancelable):i=new Event(t,r),Object.assign(i,o,{match:function(){return n.targets&&0<n.targets.length&&n.targets.every((function(t){return i.currentTarget.contains(t)}))}}),e.dispatchEvent(i)}function I(t,e){var n,r=e.preventDefault;return n=r,"[object Function]"===Object.prototype.toString.call(n)?r(t):!!r}var P=[o,a,u,c,f],X=[p,s];var S="computed",Y={domEvents:{bubbles:!0,cancelable:!0},preventDefault:function(t){if(t.target&&"tagName"in t.target){var e=t.target.tagName;return!/^(?:INPUT|TEXTAREA|BUTTON|SELECT)$/.test(e)}return!1}},O="at:after",D=function(t){function i(e,r){var i,o=t.call(this)||this;o.v="2.1.2",o.__computeFunctionList=[],o.__computeFunctionCreatorList=[],o.__pluginContexts=[],o.__isIgnoreMouse=!1,o.el=e,o.c={},o.__options=n(n({},Y),r);var a,u,c,v,h=function(t){var e=L();return function(n){var r=[],i=[];Array.from(n.touches).forEach((function(e){var n=e.clientX,o=e.clientY,a=e.target;(null==t?void 0:t.contains(a))&&(r.push(a),i.push({clientX:n,clientY:o,target:a}))}));var o=Array.from(n.changedTouches).map((function(t){return{clientX:t.clientX,clientY:t.clientY,target:t.target}}));return e({phase:n.type.replace("touch",""),changedPoints:o,points:i,nativeEvent:n,target:n.target,targets:r})}}(o.el),l=(u=!1,c=null,v=L(),function(t){var e,n=t.clientX,r=t.clientY,i=t.type,o=t.button,h=t.target,l=[{clientX:n,clientY:r,target:h}];if(f===i&&0===o)c=h,u=!0,e="start";else{if(!u)return;p===i?e="move":s===i&&(l=[],e="end",u=!1)}var m=a||[{clientX:n,clientY:r,target:h}];if(a=[{clientX:n,clientY:r,target:h}],void 0!==e)return v({phase:e,changedPoints:m,points:l,target:c,targets:[c],nativeEvent:t})});if(o.__inputCreatorMap=((i={}).touchstart=h,i.touchmove=h,i.touchend=h,i.touchcancel=h,i.mousedown=l,i.mousemove=l,i.mouseup=l,i),o.on(O,(function(t){var e=t.target,n=t.__type,r=o.__options.domEvents;r&&void 0!==o.el&&e&&(A(n,e,t,r),A(O,e,t,r))})),void 0!==e){e.style.webkitTapHighlightColor="rgba(0,0,0,0)";var m=!1;try{var d={};Object.defineProperty(d,"passive",{get:function(){m=!0}}),window.addEventListener("_",(function(){}),d)}catch(t){}o.on("u",function(t,e,n){return P.forEach((function(r){t.addEventListener(r,e,n)})),X.forEach((function(t){window.addEventListener(t,e,n)})),function(){P.forEach((function(n){t.removeEventListener(n,e)})),X.forEach((function(t){window.removeEventListener(t,e)}))}}(e,o.catchEvent.bind(o),!1===o.__options.preventDefault&&m?{passive:!0}:{passive:!1}))}return o}return e(i,t),i.prototype.use=function(t,e){this.__pluginContexts.push(t(this,e))},i.prototype.catchEvent=function(t){var e=this.__inputCreatorMap[t.type](t);if(void 0!==e){var r=function(){return t.preventDefault()};if(I(t,this.__options))r();else if("touchstart"===t.type?this.__isIgnoreMouse=!0:"touchmove"===t.type&&(this.__isIgnoreMouse=!1),this.__isIgnoreMouse&&t.type.startsWith("mouse"))return void("mouseup"===t.type&&(this.__isIgnoreMouse=!1));this.emit("input",e),this.emit2("at:".concat(e.phase),e,{});var i={};this.__computeFunctionList.forEach((function(t){var n=t(e,i);if(void 0!==n)for(var r in n)i[r]=n[r]})),this.emit(S,n(n(n({},e),i),{stopPropagation:function(){return t.stopPropagation()},stopImmediatePropagation:function(){return t.stopImmediatePropagation()},preventDefault:r}))}},i.prototype.compute=function(t,e){var n,i;try{for(var o=r(t),a=o.next();!a.done;a=o.next()){var u=a.value;this.__computeFunctionCreatorList.includes(u)||(this.__computeFunctionCreatorList.push(u),this.__computeFunctionList.push(u()))}}catch(t){n={error:t}}finally{try{a&&!a.done&&(i=o.return)&&i.call(o)}finally{if(n)throw n.error}}this.on(S,e)},i.prototype.beforeEach=function(e){var n=this;t.prototype.beforeEach.call(this,(function(t,r){var i;(null===(i=n.c)||void 0===i?void 0:i.name)?e(t,r):r()}))},i.prototype.get=function(t){return this.__pluginContexts.find((function(e){return t===e.name}))},i.prototype.set=function(t){this.__options=n(n({},this.__options),t)},i.prototype.emit2=function(t,e,r){var i=this;this.c=r,this.emit(t,n(n({},e),{type:t}),(function(){i.emit(O,n(n({},e),{name:t,__type:t}))}))},i.prototype.destroy=function(){this.emit("u"),t.prototype.destroy.call(this)},i}(i),C=function(t){return Math.sqrt(t.x*t.x+t.y*t.y)},N=function(t){return t/Math.PI*180},j=function(t,e){var n=function(t,e){var n=C(t)*C(e);if(0===n)return 0;var r=function(t,e){return t.x*e.x+t.y*e.y}(t,e)/n;return r>1&&(r=1),Math.acos(r)}(t,e);return function(t,e){return t.x*e.y-e.x*t.y}(t,e)>0&&(n*=-1),N(n)},F=function(t,e){if(0!==t||0!==e)return Math.abs(t)>=Math.abs(e)?0<t?"right":"left":0<e?"down":"up"};function V(){var t=0,e=0;return function(n,r){var i=r.prevVecotr,o=r.startVecotr,a=r.activeVecotr;return a&&(e=Math.round(j(a,i)),t=Math.round(j(a,o))),{angle:t,deltaAngle:e}}}function R(){return function(t){var e=t.prevInput,n=0,r=0,i=0;if(void 0!==e&&(n=t.x-e.x,r=t.y-e.y,0!==n||0!==r)){var o=Math.sqrt(Math.pow(n,2)+Math.pow(r,2));i=Math.round(N(Math.acos(Math.abs(n)/o)))}return{deltaX:n,deltaY:r,deltaXYAngle:i}}}function B(){var t,e=0,n=0,r=0,i=0,o=0;return function(a){var u=a.phase,c=a.startInput;return h===u?(e=0,n=0,r=0,i=0,o=0):l===u&&(e=Math.round(a.points[0].clientX-c.points[0].clientX),n=Math.round(a.points[0].clientY-c.points[0].clientY),r=Math.abs(e),i=Math.abs(n),o=Math.round(C({x:r,y:i})),t=F(e,n)),{displacementX:e,displacementY:n,distanceX:r,distanceY:i,distance:o,overallDirection:t}}}function q(){var t=1;return function(e,n){var r=1,i=n.prevVecotr,o=n.startVecotr,a=n.activeVecotr;return a&&(r=M(C(a)/C(i)),t=M(C(a)/C(o))),{scale:t,deltaScale:r}}}function G(){var t,e,n=0,r=0,i=0,o=0;return function(a){if(void 0!==a){e=e||a.startInput;var u=a.timestamp-e.timestamp;if(16<u){var c=a.x-e.x,s=a.y-e.y;i=Math.round(c/u*100)/100,o=Math.round(s/u*100)/100,n=Math.abs(i),r=Math.abs(o),t=F(c,s),e=a}}return{velocityX:n,velocityY:r,speedX:i,speedY:o,direction:t}}}function H(){var t=0;return function(e){var n=e.phase;return h===n&&(t=e.pointLength),{maxPointLength:t}}}function U(t){return{x:t.points[1].clientX-t.points[0].clientX,y:t.points[1].clientY-t.points[0].clientY}}function k(){var t,e,n;return function(r){var i=r.prevInput,o=r.startMultiInput;return void 0!==o&&void 0!==i&&r.id!==o.id&&1<i.pointLength&&1<r.pointLength?(t=U(o),e=U(i),n=U(r)):n=void 0,{startVecotr:t,prevVecotr:e,activeVecotr:n}}}var W={name:"tap",pointLength:1,tapTimes:1,waitNextTapTime:300,maxDistance:2,maxDistanceFromPrevTap:9,maxPressTime:250};function Z(t,e){var n,r,i,o=b(W,e),a=0;function u(){a=0,n=void 0,r=void 0}return t.compute([B,H],(function(e){if(!E(o)){var c,s,p,f,v=e.phase,h=e.x,l=e.y;if(d===v)o.state=0,c=e.startInput,s=e.pointLength,p=e.timestamp-c.timestamp,f=e.distance,e.maxPointLength===o.pointLength&&0===s&&o.maxDistance>=f&&o.maxPressTime>p?(clearTimeout(i),function(t,e){if(void 0!==n){var r=C({x:t.x-n.x,y:t.y-n.y});return n=t,e.maxDistanceFromPrevTap>=r}return n=t,!0}({x:h,y:l},o)&&function(t){var e=performance.now();if(void 0===r)return r=e,!0;var n=e-r;return r=e,n<t}(o.waitNextTapTime)?a++:a=1,0==a%o.tapTimes?(o.state=1,t.emit2(o.name,e,o),u()):i=setTimeout((function(){o.state=2,u()}),o.waitNextTapTime)):(u(),o.state=2)}})),o}var $={name:"pan",threshold:10,pointLength:1};function z(t,e){var n=b($,e);return t.compute([G,B,R],(function(e){if(T(n),!E(n)){var r,i,o=(r=e.pointLength,i=e.distance,n.pointLength===r&&n.threshold<=i);if(n.state=_(o,n.state,e.phase),o||x(n.state)){var a=n.name;t.emit2(a,e,n),t.emit2(a+g(n.state),e,n),![d,m].includes(e.phase)&&e.direction&&t.emit2(a+e.direction,e,n)}}})),n}var J={name:"swipe",threshold:10,velocity:.3,pointLength:1};function K(t,e){var n=b(J,e);return t.compute([B,G,H],(function(e){if(n.state=0,!n.disabled&&function(){if(d!==e.phase)return!1;var t=e.velocityX,r=e.velocityY,i=e.distance;return e.maxPointLength===n.pointLength&&0===e.points.length&&n.threshold<i&&n.velocity<Math.max(t,r)}()){var r=n.name;n.state=1,t.emit2(r,e,n),t.emit2(r+e.direction,e,n)}})),n}var Q={name:"press",pointLength:1,maxDistance:9,minPressTime:251};function tt(t,e){var n=b(Q,e),r=0;return t.compute([B],(function(e){if(!E(n)){var i,o=e.phase,a=e.startInput,u=e.pointLength;if(h===o&&n.pointLength===u)T(n),clearTimeout(r),r=setTimeout((function(){n.state=1,t.emit2(n.name,e,n)}),n.minPressTime);else if(d===o&&1===n.state)t.emit2("".concat(n.name).concat("up"),e,n);else if(1!==n.state){var c=e.timestamp-a.timestamp;(!((i=e.distance)&&n.maxDistance>i)||n.minPressTime>c&&[d,m].includes(o))&&(clearTimeout(r),n.state=2)}}})),n}var et={name:"pinch",threshold:0,pointLength:2};function nt(t,e){var n=b(et,e);return t.compute([k,q],(function(e){if(T(n),!E(n)){var r,i,o=(r=e.pointLength,i=e.scale,e.deltaScale,e.phase,n.pointLength===r&&n.threshold<Math.abs(i-1));n.state=_(o,n.state,e.phase);var a=n.name;if(o||x(n.state)){t.emit2(a,e,n);var u=e.deltaScale;1!==u&&t.emit2(a+(1<u?"in":"out"),e,n)}var c=g(n.state);c&&t.emit2(a+c,e,n)}})),n}var rt={name:"rotate",threshold:0,pointLength:2};function it(t,e){var n=b(rt,e);return t.compute([k,V],(function(e){if(!E(n)){T(n);var r,i,o=(r=e.pointLength,i=e.angle,n.pointLength===r&&n.threshold<Math.abs(i));n.state=_(o,n.state,e.phase);var a=n.name;(o||x(n.state))&&t.emit2(a,e,n);var u=g(n.state);u&&t.emit2(a+u,e,n)}})),n}function ot(t){t.use(Z,{name:"doubletap",tapTimes:2});var e,n=t.get("doubletap");return t.beforeEach((function(t,r){"tap"===t?(clearTimeout(e),e=setTimeout((function(){[0,2].includes(n.state)&&r()}),300)):r()})),n}return function(t){function n(e,n){var r=t.call(this,e,n)||this;return r.use(Z),r.use(z),r.use(K),r.use(tt),r.use(nt),r.use(it),r}return e(n,t),n.STATE_POSSIBLE=0,n.STATE_START=4,n.STATE_MOVE=5,n.STATE_END=1,n.STATE_CANCELLED=3,n.STATE_FAILED=2,n.STATE_RECOGNIZED=1,n.tap=Z,n.pan=z,n.swipe=K,n.press=tt,n.rotate=it,n.pinch=nt,n.doubletap=ot,n}(D)}));
//# sourceMappingURL=any-touch.umd.min.js.map
{
"name": "any-touch",
"version": "2.1.2",
"version": "2.1.3",
"description": "一个小巧的手势库",

@@ -25,11 +25,11 @@ "unpkg": "dist/any-touch.umd.min.js",

"dependencies": {
"@any-touch/core": "^2.1.2",
"@any-touch/doubletap": "^2.1.2",
"@any-touch/pan": "^2.1.2",
"@any-touch/pinch": "^2.1.2",
"@any-touch/press": "^2.1.2",
"@any-touch/rotate": "^2.1.2",
"@any-touch/swipe": "^2.1.2",
"@any-touch/tap": "^2.1.2",
"any-event": "^2.1.2",
"@any-touch/core": "^2.1.3",
"@any-touch/doubletap": "^2.1.3",
"@any-touch/pan": "^2.1.3",
"@any-touch/pinch": "^2.1.3",
"@any-touch/press": "^2.1.3",
"@any-touch/rotate": "^2.1.3",
"@any-touch/swipe": "^2.1.3",
"@any-touch/tap": "^2.1.3",
"any-event": "^2.1.3",
"tslib": "^2.3.1"

@@ -43,3 +43,3 @@ },

"sideEffects": false,
"gitHead": "addeef26823e8840b1915cacd995b3026299e5b5"
"gitHead": "d443bd60d69ef085a8088f239dc905060d5e7c06"
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc