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 1.0.0 to 1.0.1

2

dist/any-touch.umd.js

@@ -568,3 +568,3 @@ (function (global, factory) {

};
AnyTouch.version = '0.6.3-beta.0';
AnyTouch.version = '1.0.1';
AnyTouch.recognizers = [];

@@ -571,0 +571,0 @@ AnyTouch.recognizerMap = {};

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

!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t=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)e.hasOwnProperty(n)&&(t[n]=e[n])})(e,n)};function e(e,n){function i(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(i.prototype=n.prototype,new i)}var n=function(){return(n=Object.assign||function(t){for(var e,n=1,i=arguments.length;n<i;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t}).apply(this,arguments)};function i(t){var e="function"==typeof Symbol&&t[Symbol.iterator],n=0;return e?e.call(t):{next:function(){return t&&n>=t.length&&(t=void 0),{value:t&&t[n++],done:!t}}}}function o(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var i,o,r=n.call(t),s=[];try{for(;(void 0===e||e-- >0)&&!(i=r.next()).done;)s.push(i.value)}catch(t){o={error:t}}finally{try{i&&!i.done&&(n=r.return)&&n.call(r)}finally{if(o)throw o.error}}return s}function r(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(o(arguments[e]));return t}var s=function(){function t(){this.listenersMap={}}return t.prototype.target=function(t){var e=this;return{on:function(n,i){e.on(n,i,{target:t})}}},t.prototype.on=function(t,e,n){var i=(void 0===n?{}:n).target;void 0===this.listenersMap[t]&&(this.listenersMap[t]=[]),void 0!==i&&(e.target=i),this.listenersMap[t].push(e)},t.prototype.off=function(t,e){var n=this.listenersMap[t];if(void 0!==n)if(void 0===e)delete this.listenersMap[t];else{var i=n.findIndex((function(t){return t===e}));n.splice(i,1)}},t.prototype.emit=function(t,e,n){var o,r;void 0===n&&(n=function(){return!0});var s=this.listenersMap[t];if(void 0!==s&&0<s.length)try{for(var a=i(s),u=a.next();!u.done;u=a.next()){var c=u.value;n({target:c.target})&&c(e)}}catch(t){o={error:t}}finally{try{u&&!u.done&&(r=a.return)&&r.call(a)}finally{if(o)throw o.error}}},t.prototype.destroy=function(){this.listenersMap={}},t}(),a=Object.prototype.toString;var u="cancel",c="end",p="touch"+c,h="touch"+u,l="ontouchstart"in window,d="start",v="move",f=c,m="r",y="f",g=u;function T(t){return Math.round(100*t)/100}var M=function(){},x=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return e(n,t),n.prototype.load=function(t){var e=[],n=Array.from(t.touches).map((function(t){var n=t.clientX,i=t.clientY,o=t.target;return e.push(o),{clientX:n,clientY:i,target:o}})),i=Array.from(t.changedTouches).map((function(t){return{clientX:t.clientX,clientY:t.clientY,target:t.target}}));return{inputType:t.type.replace("touch",""),changedPoints:i,points:n,nativeEvent:t,target:t.target,targets:e}},n}(M),b=function(t){function n(){var e=t.call(this)||this;return e.target=null,e.isPressed=!1,e}return e(n,t),n.prototype.load=function(t){var e,n=t.clientX,i=t.clientY,o=t.type,r=t.button,s=t.target,a=[{clientX:n,clientY:i,target:s}];"mousedown"===o&&0===r?(this.target=s,this.isPressed=!0,e="start"):this.isPressed&&("mousemove"===o?e="move":"mouseup"===o&&(a=[],e=c,this.isPressed=!1));var u=this.prevPoints||[{clientX:n,clientY:i,target:s}];if(this.prevPoints=[{clientX:n,clientY:i,target:s}],void 0!==e)return{inputType:e,changedPoints:u,points:a,target:this.target,targets:[this.target],nativeEvent:t}},n}(M),E=function(){function t(){var t=l?x:b;this.adapter=new t,this.id=0}return t.prototype.transform=function(t){this.prevInput=this.activeInput;var e=this.adapter.load(t);if(void 0!==e){var i=Number.MAX_SAFE_INTEGER>this.id?++this.id:1,o=function(t){var e=t.inputType,i=t.points,o=t.changedPoints,r=t.nativeEvent,s=i.length,a="start"===e,p=c===e&&0===s||u===e,h=performance.now(),l=P(i)||P(o),d=l.x,v=l.y,f=r.currentTarget;return n(n({},t),{x:d,y:v,timestamp:h,isStart:a,isEnd:p,pointLength:s,currentTarget:f,getOffset:function(t){void 0===t&&(t=f);var e=t.getBoundingClientRect();return{x:d-Math.round(e.left),y:v-Math.round(e.top)}}})}(n(n({},e),{id:i}));this.activeInput=o;var r=o.isStart,s=o.pointLength;return r&&(this.startInput=o,this.prevInput=void 0,this.startMultiInput=1<s?o:void 0),n(n({},o),{prevInput:this.prevInput,startMultiInput:this.startMultiInput,startInput:this.startInput})}},t}();function P(t){var e=t.length;if(0<e){if(1===e){var n=t[0],i=n.clientX,o=n.clientY;return{x:Math.round(i),y:Math.round(o)}}var r=t.reduce((function(t,e){return t.x+=e.clientX,t.y+=e.clientY,t}),{x:0,y:0});return{x:Math.round(r.x/e),y:Math.round(r.y/e)}}}function w(t,e,n){e.target,e.currentTarget;var i,o,r,s=e.type,a=function(t,e){var n={};for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&e.indexOf(i)<0&&(n[i]=t[i]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(i=Object.getOwnPropertySymbols(t);o<i.length;o++)e.indexOf(i[o])<0&&Object.prototype.propertyIsEnumerable.call(t,i[o])&&(n[i[o]]=t[i[o]])}return n}(e,["target","currentTarget","type"]);return void 0!==Event?r=new Event(s,n):(r=document.createEvent("HTMLEvents")).initEvent(s,null===(i=n)||void 0===i?void 0:i.bubbles,null===(o=n)||void 0===o?void 0:o.cancelable),Object.assign(r,a,{match:function(){return e.targets.every((function(t){return r.currentTarget.contains(t)}))}}),t.dispatchEvent(r)}function L(t,e){if(!e.isPreventDefault)return!1;var n,i=!0;if(null!==t.target){var o=e.preventDefaultExclude;if(n=o,"[object RegExp]"===a.call(n)){if("tagName"in t.target){var r=t.target.tagName;i=!o.test(r)}}else(function(t){return"[object Function]"===a.call(t)})(o)&&(i=!o(t))}return i}var X=["touchstart","touchmove",p,h];function Y(t,e,n){var i,o=null===(i=n)||void 0===i?void 0:i.name;if(void 0===o||void 0===t.recognizerMap[o]){var r=new e(n);t.recognizerMap[r.name]=r,r.recognizerMap=t.recognizerMap,t.recognizers.push(t.recognizerMap[r.name])}}function _(t,e){var n,r;if(void 0===e)t.recognizers=[],t.recognizerMap={};else try{for(var s=i(t.recognizers.entries()),a=s.next();!a.done;a=s.next()){var u=o(a.value,2),c=u[0];if(e===u[1].options.name){t.recognizers.splice(c,1),delete t.recognizerMap[e];break}}}catch(t){n={error:t}}finally{try{a&&!a.done&&(r=s.return)&&r.call(s)}finally{if(n)throw n.error}}}function I(t,e){var i=e.type,o=e.target,r=e.targets;t.emit(i,e,(function(t){var e;if(void 0!==(null===(e=t)||void 0===e?void 0:e.target)){var n=t.target;return r.every((function(t){return n.contains(t)}))}return!0}));t.emit("at:after",e),t.options.domEvents&&void 0!==t.el&&null!==o&&(w(o,e,t.options.domEvents),w(o,n(n({},e),{type:"at:after"}),t.options.domEvents))}var z={domEvents:{bubbles:!0,cancelable:!0},isPreventDefault:!0,preventDefaultExclude:/^(?:INPUT|TEXTAREA|BUTTON|SELECT)$/},D=function(t){function o(e,i){var r=t.call(this)||this;if(r.recognizerMap={},r.recognizers=[],r.el=e,r.input=new E,r.options=n(n({},z),i),r.recognizerMap=o.recognizerMap,r.recognizers=o.recognizers,void 0!==e){e.style.webkitTapHighlightColor="rgba(0,0,0,0)";var s=!1;try{var a={};Object.defineProperty(a,"passive",{get:function(){s=!0}}),window.addEventListener("_",(function(){}),a)}catch(t){}r.on("unbind",function(t,e,n){return l?(X.forEach((function(i){t.addEventListener(i,e,n)})),function(){X.forEach((function(n){t.removeEventListener(n,e)}))}):(t.addEventListener("mousedown",e,n),window.addEventListener("mousemove",e,n),window.addEventListener("mouseup",e,n),function(){t.removeEventListener("mousedown",e),window.removeEventListener("mousemove",e),window.removeEventListener("mouseup",e)})}(e,r.catchEvent.bind(r),!(r.options.isPreventDefault||!s)&&{passive:!0}))}return r}return e(o,t),o.prototype.use=function(t,e){Y(this,t,e)},o.prototype.removeUse=function(t){_(this,t)},o.prototype.catchEvent=function(t){var e,o,r=this;L(t,this.options)&&t.preventDefault();var s=this.input.transform(t);if(void 0!==s){var a="at:touch"+s.inputType;this.emit("at:touch",s),this.emit(a,s);var u=this.options.domEvents;if(!1!==u){var c=t.target;null!==c&&(w(c,n(n({},s),{type:"at:touch"}),u),w(c,n(n({},s),{type:a}),u))}var p={},h=function(t){if(t.disabled)return"continue";t.input=s,t.computedGroup=p,t.recognize(s,(function(e,i){var o=n(n(n({},s),i),{type:e,baseType:t.name});Object.freeze(o),void 0===r.beforeEachHook?I(r,o):r.beforeEachHook(t,(function(){I(r,o)}))})),p=t.computedGroup};try{for(var l=i(this.recognizers),d=l.next();!d.done;d=l.next()){h(d.value)}}catch(t){e={error:t}}finally{try{d&&!d.done&&(o=l.return)&&o.call(l)}finally{if(e)throw e.error}}}},o.prototype.beforeEach=function(t){this.beforeEachHook=t},o.prototype.get=function(t){return this.recognizerMap[t]},o.prototype.set=function(t){this.options=n(n({},this.options),t)},o.prototype.destroy=function(){this.emit("unbind"),this.listenersMap={}},o.version="0.6.3-beta.0",o.recognizers=[],o.recognizerMap={},o.use=function(t,e){Y(o,t,e)},o.removeUse=function(t){_(o,t)},o}(s);function S(t){-1!==[f,g,m,y].indexOf(t.status)&&(t.status="p")}function V(t,e,n){var i=t.test(e);S(t);var o=e.inputType;t.status=function(t,e,n){var i,o,r,s,a,p,h,l={1:(i={},i.p=(o={},o.move=d,o),i[d]=(r={},r.move=v,r[c]=f,r[u]=g,r),i[v]=(s={},s.move=v,s[c]=f,s[u]=g,s),i),0:(a={},a[d]=(p={},p.move=g,p[c]=f,p[u]=g,p),a[v]=(h={},h.start=y,h.move=g,h[c]=f,h[u]=g,h),a)};return void 0!==l[Number(t)][e]&&l[Number(t)][e][n]||e}(i,t.status,o);var r=t.computed;t.isRecognized=[d,v].includes(t.status);var s=t.name,a=t.status,p=t.isRecognized;return p&&n(s,r),(p||[f,g].includes(t.status))&&n(s+a,r),i}var O=function(){function t(t){this.options=t,this.name=this.options.name,this.disabled=!1,this.status="p",this.isRecognized=!1,this.computed={},this.computedGroup={},this.usedComputeFunctionMap={},this.recognizerMap={}}return t.prototype.set=function(t){return void 0!==t&&(this.options=n(n({},this.options),t)),this},t.prototype.isValidPointLength=function(t){return 0===this.options.pointLength||this.options.pointLength===t},t.prototype.compute=function(t){for(var e,o,s,a=[],u=1;u<arguments.length;u++)a[u-1]=arguments[u];var c=Object.create(null);try{for(var p=i(t),h=p.next();!h.done;h=p.next()){var l=h.value,d=l._id,v=this,f=v.computedGroup,m=v.usedComputeFunctionMap;void 0===m[d]&&(m[d]=new l),f[d]=f[d]||(s=m[d]).compute.apply(s,r(a)),c=n(n({},c),f[d])}}catch(t){e={error:t}}finally{try{h&&!h.done&&(o=p.return)&&o.call(p)}finally{if(e)throw e.error}}return this.computed=c,c},t}(),C=function(t){return Math.sqrt(t.x*t.x+t.y*t.y)},A=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 i=function(t,e){return t.x*e.x+t.y*e.y}(t,e)/n;return i>1&&(i=1),Math.acos(i)}(t,e);return function(t,e){return t.x*e.y-e.x*t.y}(t,e)>0&&(n*=-1),A(n)},F=function(t,e){return t===e?"none":Math.abs(t)>Math.abs(e)?0<t?"right":"left":0<e?"down":"up"};var N=function(){function t(){}return t.prototype.compute=function(t){var e=t.prevInput,n=0,i=0,o=0;if(void 0!==e&&(n=t.x-e.x,i=t.y-e.y,0!==n||0!==i)){var r=Math.sqrt(Math.pow(n,2)+Math.pow(i,2));o=Math.round(A(Math.acos(Math.abs(n)/r)))}return{deltaX:n,deltaY:i,deltaXYAngle:o}},t._id="ComputeDeltaXY",t}(),R=function(){function t(){this.displacementX=0,this.displacementY=0,this.distanceX=0,this.distanceY=0,this.distance=0,this.overallDirection="none"}return t.prototype.compute=function(t){var e=t.inputType,n=t.startInput;"start"===e?(this.displacementX=0,this.displacementY=0,this.distanceX=0,this.distanceY=0,this.distance=0,this.overallDirection="none"):"move"===e&&(this.displacementX=Math.round(t.points[0].clientX-n.points[0].clientX),this.displacementY=Math.round(t.points[0].clientY-n.points[0].clientY),this.distanceX=Math.abs(this.displacementX),this.distanceY=Math.abs(this.displacementY),this.distance=Math.round(C({x:this.distanceX,y:this.distanceY})),this.overallDirection=F(this.displacementX,this.displacementY));var i=this;return{displacementX:i.displacementX,displacementY:i.displacementY,distanceX:i.distanceX,distanceY:i.distanceY,distance:i.distance,overallDirection:i.overallDirection}},t._id="ComputeDistance",t}(),U=function(){function t(){this.maxPointLength=0}return t.prototype.compute=function(t){return"start"===t.inputType&&(this.maxPointLength=t.pointLength),{maxPointLength:this.maxPointLength}},t._id="ComputeMaxLength",t}();var G=function(){function t(){this.velocityX=0,this.velocityY=0,this.speedX=0,this.speedY=0}return t.prototype.compute=function(t){if(void 0!==t){var e=t.inputType;this._lastValidInput=this._lastValidInput||t.startInput;var n=t.timestamp-this._lastValidInput.timestamp;if("move"===e&&16<n){var i=t.x-this._lastValidInput.x,o=t.y-this._lastValidInput.y;this.speedX=Math.round(i/n*100)/100,this.speedY=Math.round(o/n*100)/100,this.velocityX=Math.abs(this.speedX),this.velocityY=Math.abs(this.speedY),this.direction=F(i,o)||this.direction,this._lastValidInput=t}}var r=this;return{velocityX:r.velocityX,velocityY:r.velocityY,speedX:r.speedX,speedY:r.speedY,direction:r.direction}},t._id="ComputeVAndDir",t}();function k(t){return{x:t.points[1].clientX-t.points[0].clientX,y:t.points[1].clientY-t.points[0].clientY}}var H=function(){function t(){}return t.prototype.compute=function(t){var e=t.prevInput,n=t.startMultiInput;if(void 0!==n&&void 0!==e&&t.id!==n.id&&1<t.pointLength)return{startV:k(n),prevV:k(e),activeV:k(t)}},t._id="ComputeVectorForMutli",t}(),B={name:"tap",pointLength:1,tapTimes:1,waitNextTapTime:300,maxDistance:2,maxDistanceFromPrevTap:9,maxPressTime:250},q=function(t){function i(e){var i=t.call(this,n(n({},B),e))||this;return i.tapCount=0,i}return e(i,t),i.prototype._isValidDistanceFromPrevTap=function(t){if(void 0!==this.prevTapPoint){var e=C({x:t.x-this.prevTapPoint.x,y:t.y-this.prevTapPoint.y});return this.prevTapPoint=t,this.options.maxDistanceFromPrevTap>=e}return this.prevTapPoint=t,!0},i.prototype._isValidInterval=function(){var t=performance.now();if(void 0===this.prevTapTime)return this.prevTapTime=t,!0;var e=t-this.prevTapTime;return this.prevTapTime=t,e<this.options.waitNextTapTime},i.prototype.recognize=function(t,e){var i=t.inputType,o=t.x,r=t.y;this.computed=this.compute([U,R],t),c===i&&(this.status="p",this.test(t)?(this.cancelCountDownToFail(),this._isValidDistanceFromPrevTap({x:o,y:r})&&this._isValidInterval()?this.tapCount++:this.tapCount=1,0==this.tapCount%this.options.tapTimes?(this.status=m,e(this.options.name,n(n({},this.computed),{tapCount:this.tapCount})),this.reset()):this.countDownToFail()):(this.reset(),this.status=y))},i.prototype.countDownToFail=function(){var t=this;this._countDownToFailTimer=setTimeout((function(){t.status=y,t.reset()}),this.options.waitNextTapTime)},i.prototype.cancelCountDownToFail=function(){clearTimeout(this._countDownToFailTimer)},i.prototype.reset=function(){this.tapCount=0,this.prevTapPoint=void 0,this.prevTapTime=void 0},i.prototype.test=function(t){var e=t.startInput,n=t.timestamp-e.timestamp,i=this.computed,o=i.maxPointLength,r=i.distance;return o===this.options.pointLength&&this.options.maxDistance>=r&&this.options.maxPressTime>n},i}(O),Z={name:"pan",threshold:10,pointLength:1},$=function(t){function i(e){return t.call(this,n(n({},Z),e))||this}return e(i,t),i.prototype.test=function(t){var e=t.pointLength,n=this.computed.distance;return(this.isRecognized||this.options.threshold<n)&&this.isValidPointLength(e)},i.prototype.recognize=function(t,e){if(this.computed=this.compute([G,R,N],t),V(this,t,e)){t.inputType;e(this.options.name+this.computed.direction,this.computed)}},i}(O),J={name:"swipe",threshold:10,velocity:.3,pointLength:1},K=function(t){function i(e){return t.call(this,n(n({},J),e))||this}return e(i,t),i.prototype.test=function(t){var e=t.inputType;if(c!==e)return!1;var n=this.computed,i=n.velocityX,o=n.velocityY,r=n.maxPointLength,s=n.distance;return this.options.pointLength===r&&this.options.threshold<s&&this.options.velocity<Math.max(i,o)},i.prototype.recognize=function(t,e){this.computed=this.compute([U,G,R],t),this.test(t)&&(e(this.options.name,this.computed),e(this.options.name+this.computed.direction,this.computed))},i}(O),Q={name:"press",pointLength:1,maxDistance:9,minPressTime:251},W=function(t){function i(e){return t.call(this,n(n({},Q),e))||this}return e(i,t),i.prototype.recognize=function(t,e){var n=this,i=t.inputType,o=t.startInput,r=t.pointLength;if("start"===i&&this.isValidPointLength(r))S(this),this.cancel(),this._timeoutId=setTimeout((function(){n.status=m,e(n.options.name,t)}),this.options.minPressTime);else if(c===i&&m===this.status)e(this.options.name+"up",this.computed);else{var s=t.timestamp-o.timestamp;(!this.test(t)||this.options.minPressTime>s&&[c,u].includes(i))&&(this.cancel(),this.status=y)}},i.prototype.test=function(t){t.pointLength;this.computed=this.compute([R],t);var e=this.computed.distance;return this.options.maxDistance>e},i.prototype.cancel=function(){clearTimeout(this._timeoutId)},i}(O),tt={name:"pinch",threshold:0,pointLength:2},et=function(t){function i(e){return t.call(this,n(n({},tt),e))||this}return e(i,t),i.prototype.test=function(t){var e=t.pointLength,n=this.computed.scale;return this.isValidPointLength(e)&&void 0!==n&&(this.options.threshold<Math.abs(n-1)||this.isRecognized)},i.prototype.recognize=function(t,e){var i,o,r,s,a,u=this.compute([H],t);"activeV"in u&&(this.computed=n(n({},this.computed),(o=(i=u).startV,r=i.prevV,s=i.activeV,a=T(C(s)/C(r)),{scale:T(C(s)/C(o)),deltaScale:a}))),V(this,t,e)},i}(O),nt={name:"rotate",threshold:0,pointLength:2},it=function(t){function i(e){return t.call(this,n(n({},nt),e))||this}return e(i,t),i.prototype.test=function(t){var e=t.pointLength,n=this.computed.angle;return this.isValidPointLength(e)&&(this.options.threshold<Math.abs(n)||this.isRecognized)},i.prototype.recognize=function(t,e){var i,o,r,s,a,u=this.compute([H],t);"activeV"in u&&(this.computed=n(n({},this.computed),(o=(i=u).startV,r=i.prevV,s=i.activeV,a=Math.round(j(s,r)),{angle:Math.round(j(s,o)),deltaAngle:a}))),V(this,t,e)},i}(O);return D.use(q),D.use($),D.use(K),D.use(W),D.use(et),D.use(it),D.Tap=q,D.Pan=$,D.Swipe=K,D.Press=W,D.Pinch=et,D.Rotate=it,D.STATUS_POSSIBLE="p",D.STATUS_START=d,D.STATUS_MOVE=v,D.STATUS_END=f,D.STATUS_CANCELLED=g,D.STATUS_FAILED=y,D.STATUS_RECOGNIZED=m,D}));
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t=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)e.hasOwnProperty(n)&&(t[n]=e[n])})(e,n)};function e(e,n){function i(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(i.prototype=n.prototype,new i)}var n=function(){return(n=Object.assign||function(t){for(var e,n=1,i=arguments.length;n<i;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t}).apply(this,arguments)};function i(t){var e="function"==typeof Symbol&&t[Symbol.iterator],n=0;return e?e.call(t):{next:function(){return t&&n>=t.length&&(t=void 0),{value:t&&t[n++],done:!t}}}}function o(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var i,o,r=n.call(t),s=[];try{for(;(void 0===e||e-- >0)&&!(i=r.next()).done;)s.push(i.value)}catch(t){o={error:t}}finally{try{i&&!i.done&&(n=r.return)&&n.call(r)}finally{if(o)throw o.error}}return s}function r(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(o(arguments[e]));return t}var s=function(){function t(){this.listenersMap={}}return t.prototype.target=function(t){var e=this;return{on:function(n,i){e.on(n,i,{target:t})}}},t.prototype.on=function(t,e,n){var i=(void 0===n?{}:n).target;void 0===this.listenersMap[t]&&(this.listenersMap[t]=[]),void 0!==i&&(e.target=i),this.listenersMap[t].push(e)},t.prototype.off=function(t,e){var n=this.listenersMap[t];if(void 0!==n)if(void 0===e)delete this.listenersMap[t];else{var i=n.findIndex((function(t){return t===e}));n.splice(i,1)}},t.prototype.emit=function(t,e,n){var o,r;void 0===n&&(n=function(){return!0});var s=this.listenersMap[t];if(void 0!==s&&0<s.length)try{for(var a=i(s),u=a.next();!u.done;u=a.next()){var c=u.value;n({target:c.target})&&c(e)}}catch(t){o={error:t}}finally{try{u&&!u.done&&(r=a.return)&&r.call(a)}finally{if(o)throw o.error}}},t.prototype.destroy=function(){this.listenersMap={}},t}(),a=Object.prototype.toString;var u="cancel",c="end",p="touch"+c,h="touch"+u,l="ontouchstart"in window,d="start",v="move",f=c,m="r",y="f",g=u;function T(t){return Math.round(100*t)/100}var M=function(){},x=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return e(n,t),n.prototype.load=function(t){var e=[],n=Array.from(t.touches).map((function(t){var n=t.clientX,i=t.clientY,o=t.target;return e.push(o),{clientX:n,clientY:i,target:o}})),i=Array.from(t.changedTouches).map((function(t){return{clientX:t.clientX,clientY:t.clientY,target:t.target}}));return{inputType:t.type.replace("touch",""),changedPoints:i,points:n,nativeEvent:t,target:t.target,targets:e}},n}(M),b=function(t){function n(){var e=t.call(this)||this;return e.target=null,e.isPressed=!1,e}return e(n,t),n.prototype.load=function(t){var e,n=t.clientX,i=t.clientY,o=t.type,r=t.button,s=t.target,a=[{clientX:n,clientY:i,target:s}];"mousedown"===o&&0===r?(this.target=s,this.isPressed=!0,e="start"):this.isPressed&&("mousemove"===o?e="move":"mouseup"===o&&(a=[],e=c,this.isPressed=!1));var u=this.prevPoints||[{clientX:n,clientY:i,target:s}];if(this.prevPoints=[{clientX:n,clientY:i,target:s}],void 0!==e)return{inputType:e,changedPoints:u,points:a,target:this.target,targets:[this.target],nativeEvent:t}},n}(M),E=function(){function t(){var t=l?x:b;this.adapter=new t,this.id=0}return t.prototype.transform=function(t){this.prevInput=this.activeInput;var e=this.adapter.load(t);if(void 0!==e){var i=Number.MAX_SAFE_INTEGER>this.id?++this.id:1,o=function(t){var e=t.inputType,i=t.points,o=t.changedPoints,r=t.nativeEvent,s=i.length,a="start"===e,p=c===e&&0===s||u===e,h=performance.now(),l=P(i)||P(o),d=l.x,v=l.y,f=r.currentTarget;return n(n({},t),{x:d,y:v,timestamp:h,isStart:a,isEnd:p,pointLength:s,currentTarget:f,getOffset:function(t){void 0===t&&(t=f);var e=t.getBoundingClientRect();return{x:d-Math.round(e.left),y:v-Math.round(e.top)}}})}(n(n({},e),{id:i}));this.activeInput=o;var r=o.isStart,s=o.pointLength;return r&&(this.startInput=o,this.prevInput=void 0,this.startMultiInput=1<s?o:void 0),n(n({},o),{prevInput:this.prevInput,startMultiInput:this.startMultiInput,startInput:this.startInput})}},t}();function P(t){var e=t.length;if(0<e){if(1===e){var n=t[0],i=n.clientX,o=n.clientY;return{x:Math.round(i),y:Math.round(o)}}var r=t.reduce((function(t,e){return t.x+=e.clientX,t.y+=e.clientY,t}),{x:0,y:0});return{x:Math.round(r.x/e),y:Math.round(r.y/e)}}}function w(t,e,n){e.target,e.currentTarget;var i,o,r,s=e.type,a=function(t,e){var n={};for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&e.indexOf(i)<0&&(n[i]=t[i]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(i=Object.getOwnPropertySymbols(t);o<i.length;o++)e.indexOf(i[o])<0&&Object.prototype.propertyIsEnumerable.call(t,i[o])&&(n[i[o]]=t[i[o]])}return n}(e,["target","currentTarget","type"]);return void 0!==Event?r=new Event(s,n):(r=document.createEvent("HTMLEvents")).initEvent(s,null===(i=n)||void 0===i?void 0:i.bubbles,null===(o=n)||void 0===o?void 0:o.cancelable),Object.assign(r,a,{match:function(){return e.targets.every((function(t){return r.currentTarget.contains(t)}))}}),t.dispatchEvent(r)}function L(t,e){if(!e.isPreventDefault)return!1;var n,i=!0;if(null!==t.target){var o=e.preventDefaultExclude;if(n=o,"[object RegExp]"===a.call(n)){if("tagName"in t.target){var r=t.target.tagName;i=!o.test(r)}}else(function(t){return"[object Function]"===a.call(t)})(o)&&(i=!o(t))}return i}var X=["touchstart","touchmove",p,h];function Y(t,e,n){var i,o=null===(i=n)||void 0===i?void 0:i.name;if(void 0===o||void 0===t.recognizerMap[o]){var r=new e(n);t.recognizerMap[r.name]=r,r.recognizerMap=t.recognizerMap,t.recognizers.push(t.recognizerMap[r.name])}}function _(t,e){var n,r;if(void 0===e)t.recognizers=[],t.recognizerMap={};else try{for(var s=i(t.recognizers.entries()),a=s.next();!a.done;a=s.next()){var u=o(a.value,2),c=u[0];if(e===u[1].options.name){t.recognizers.splice(c,1),delete t.recognizerMap[e];break}}}catch(t){n={error:t}}finally{try{a&&!a.done&&(r=s.return)&&r.call(s)}finally{if(n)throw n.error}}}function I(t,e){var i=e.type,o=e.target,r=e.targets;t.emit(i,e,(function(t){var e;if(void 0!==(null===(e=t)||void 0===e?void 0:e.target)){var n=t.target;return r.every((function(t){return n.contains(t)}))}return!0}));t.emit("at:after",e),t.options.domEvents&&void 0!==t.el&&null!==o&&(w(o,e,t.options.domEvents),w(o,n(n({},e),{type:"at:after"}),t.options.domEvents))}var z={domEvents:{bubbles:!0,cancelable:!0},isPreventDefault:!0,preventDefaultExclude:/^(?:INPUT|TEXTAREA|BUTTON|SELECT)$/},D=function(t){function o(e,i){var r=t.call(this)||this;if(r.recognizerMap={},r.recognizers=[],r.el=e,r.input=new E,r.options=n(n({},z),i),r.recognizerMap=o.recognizerMap,r.recognizers=o.recognizers,void 0!==e){e.style.webkitTapHighlightColor="rgba(0,0,0,0)";var s=!1;try{var a={};Object.defineProperty(a,"passive",{get:function(){s=!0}}),window.addEventListener("_",(function(){}),a)}catch(t){}r.on("unbind",function(t,e,n){return l?(X.forEach((function(i){t.addEventListener(i,e,n)})),function(){X.forEach((function(n){t.removeEventListener(n,e)}))}):(t.addEventListener("mousedown",e,n),window.addEventListener("mousemove",e,n),window.addEventListener("mouseup",e,n),function(){t.removeEventListener("mousedown",e),window.removeEventListener("mousemove",e),window.removeEventListener("mouseup",e)})}(e,r.catchEvent.bind(r),!(r.options.isPreventDefault||!s)&&{passive:!0}))}return r}return e(o,t),o.prototype.use=function(t,e){Y(this,t,e)},o.prototype.removeUse=function(t){_(this,t)},o.prototype.catchEvent=function(t){var e,o,r=this;L(t,this.options)&&t.preventDefault();var s=this.input.transform(t);if(void 0!==s){var a="at:touch"+s.inputType;this.emit("at:touch",s),this.emit(a,s);var u=this.options.domEvents;if(!1!==u){var c=t.target;null!==c&&(w(c,n(n({},s),{type:"at:touch"}),u),w(c,n(n({},s),{type:a}),u))}var p={},h=function(t){if(t.disabled)return"continue";t.input=s,t.computedGroup=p,t.recognize(s,(function(e,i){var o=n(n(n({},s),i),{type:e,baseType:t.name});Object.freeze(o),void 0===r.beforeEachHook?I(r,o):r.beforeEachHook(t,(function(){I(r,o)}))})),p=t.computedGroup};try{for(var l=i(this.recognizers),d=l.next();!d.done;d=l.next()){h(d.value)}}catch(t){e={error:t}}finally{try{d&&!d.done&&(o=l.return)&&o.call(l)}finally{if(e)throw e.error}}}},o.prototype.beforeEach=function(t){this.beforeEachHook=t},o.prototype.get=function(t){return this.recognizerMap[t]},o.prototype.set=function(t){this.options=n(n({},this.options),t)},o.prototype.destroy=function(){this.emit("unbind"),this.listenersMap={}},o.version="1.0.1",o.recognizers=[],o.recognizerMap={},o.use=function(t,e){Y(o,t,e)},o.removeUse=function(t){_(o,t)},o}(s);function S(t){-1!==[f,g,m,y].indexOf(t.status)&&(t.status="p")}function V(t,e,n){var i=t.test(e);S(t);var o=e.inputType;t.status=function(t,e,n){var i,o,r,s,a,p,h,l={1:(i={},i.p=(o={},o.move=d,o),i[d]=(r={},r.move=v,r[c]=f,r[u]=g,r),i[v]=(s={},s.move=v,s[c]=f,s[u]=g,s),i),0:(a={},a[d]=(p={},p.move=g,p[c]=f,p[u]=g,p),a[v]=(h={},h.start=y,h.move=g,h[c]=f,h[u]=g,h),a)};return void 0!==l[Number(t)][e]&&l[Number(t)][e][n]||e}(i,t.status,o);var r=t.computed;t.isRecognized=[d,v].includes(t.status);var s=t.name,a=t.status,p=t.isRecognized;return p&&n(s,r),(p||[f,g].includes(t.status))&&n(s+a,r),i}var O=function(){function t(t){this.options=t,this.name=this.options.name,this.disabled=!1,this.status="p",this.isRecognized=!1,this.computed={},this.computedGroup={},this.usedComputeFunctionMap={},this.recognizerMap={}}return t.prototype.set=function(t){return void 0!==t&&(this.options=n(n({},this.options),t)),this},t.prototype.isValidPointLength=function(t){return 0===this.options.pointLength||this.options.pointLength===t},t.prototype.compute=function(t){for(var e,o,s,a=[],u=1;u<arguments.length;u++)a[u-1]=arguments[u];var c=Object.create(null);try{for(var p=i(t),h=p.next();!h.done;h=p.next()){var l=h.value,d=l._id,v=this,f=v.computedGroup,m=v.usedComputeFunctionMap;void 0===m[d]&&(m[d]=new l),f[d]=f[d]||(s=m[d]).compute.apply(s,r(a)),c=n(n({},c),f[d])}}catch(t){e={error:t}}finally{try{h&&!h.done&&(o=p.return)&&o.call(p)}finally{if(e)throw e.error}}return this.computed=c,c},t}(),C=function(t){return Math.sqrt(t.x*t.x+t.y*t.y)},A=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 i=function(t,e){return t.x*e.x+t.y*e.y}(t,e)/n;return i>1&&(i=1),Math.acos(i)}(t,e);return function(t,e){return t.x*e.y-e.x*t.y}(t,e)>0&&(n*=-1),A(n)},F=function(t,e){return t===e?"none":Math.abs(t)>Math.abs(e)?0<t?"right":"left":0<e?"down":"up"};var N=function(){function t(){}return t.prototype.compute=function(t){var e=t.prevInput,n=0,i=0,o=0;if(void 0!==e&&(n=t.x-e.x,i=t.y-e.y,0!==n||0!==i)){var r=Math.sqrt(Math.pow(n,2)+Math.pow(i,2));o=Math.round(A(Math.acos(Math.abs(n)/r)))}return{deltaX:n,deltaY:i,deltaXYAngle:o}},t._id="ComputeDeltaXY",t}(),R=function(){function t(){this.displacementX=0,this.displacementY=0,this.distanceX=0,this.distanceY=0,this.distance=0,this.overallDirection="none"}return t.prototype.compute=function(t){var e=t.inputType,n=t.startInput;"start"===e?(this.displacementX=0,this.displacementY=0,this.distanceX=0,this.distanceY=0,this.distance=0,this.overallDirection="none"):"move"===e&&(this.displacementX=Math.round(t.points[0].clientX-n.points[0].clientX),this.displacementY=Math.round(t.points[0].clientY-n.points[0].clientY),this.distanceX=Math.abs(this.displacementX),this.distanceY=Math.abs(this.displacementY),this.distance=Math.round(C({x:this.distanceX,y:this.distanceY})),this.overallDirection=F(this.displacementX,this.displacementY));var i=this;return{displacementX:i.displacementX,displacementY:i.displacementY,distanceX:i.distanceX,distanceY:i.distanceY,distance:i.distance,overallDirection:i.overallDirection}},t._id="ComputeDistance",t}(),U=function(){function t(){this.maxPointLength=0}return t.prototype.compute=function(t){return"start"===t.inputType&&(this.maxPointLength=t.pointLength),{maxPointLength:this.maxPointLength}},t._id="ComputeMaxLength",t}();var G=function(){function t(){this.velocityX=0,this.velocityY=0,this.speedX=0,this.speedY=0}return t.prototype.compute=function(t){if(void 0!==t){var e=t.inputType;this._lastValidInput=this._lastValidInput||t.startInput;var n=t.timestamp-this._lastValidInput.timestamp;if("move"===e&&16<n){var i=t.x-this._lastValidInput.x,o=t.y-this._lastValidInput.y;this.speedX=Math.round(i/n*100)/100,this.speedY=Math.round(o/n*100)/100,this.velocityX=Math.abs(this.speedX),this.velocityY=Math.abs(this.speedY),this.direction=F(i,o)||this.direction,this._lastValidInput=t}}var r=this;return{velocityX:r.velocityX,velocityY:r.velocityY,speedX:r.speedX,speedY:r.speedY,direction:r.direction}},t._id="ComputeVAndDir",t}();function k(t){return{x:t.points[1].clientX-t.points[0].clientX,y:t.points[1].clientY-t.points[0].clientY}}var H=function(){function t(){}return t.prototype.compute=function(t){var e=t.prevInput,n=t.startMultiInput;if(void 0!==n&&void 0!==e&&t.id!==n.id&&1<t.pointLength)return{startV:k(n),prevV:k(e),activeV:k(t)}},t._id="ComputeVectorForMutli",t}(),B={name:"tap",pointLength:1,tapTimes:1,waitNextTapTime:300,maxDistance:2,maxDistanceFromPrevTap:9,maxPressTime:250},q=function(t){function i(e){var i=t.call(this,n(n({},B),e))||this;return i.tapCount=0,i}return e(i,t),i.prototype._isValidDistanceFromPrevTap=function(t){if(void 0!==this.prevTapPoint){var e=C({x:t.x-this.prevTapPoint.x,y:t.y-this.prevTapPoint.y});return this.prevTapPoint=t,this.options.maxDistanceFromPrevTap>=e}return this.prevTapPoint=t,!0},i.prototype._isValidInterval=function(){var t=performance.now();if(void 0===this.prevTapTime)return this.prevTapTime=t,!0;var e=t-this.prevTapTime;return this.prevTapTime=t,e<this.options.waitNextTapTime},i.prototype.recognize=function(t,e){var i=t.inputType,o=t.x,r=t.y;this.computed=this.compute([U,R],t),c===i&&(this.status="p",this.test(t)?(this.cancelCountDownToFail(),this._isValidDistanceFromPrevTap({x:o,y:r})&&this._isValidInterval()?this.tapCount++:this.tapCount=1,0==this.tapCount%this.options.tapTimes?(this.status=m,e(this.options.name,n(n({},this.computed),{tapCount:this.tapCount})),this.reset()):this.countDownToFail()):(this.reset(),this.status=y))},i.prototype.countDownToFail=function(){var t=this;this._countDownToFailTimer=setTimeout((function(){t.status=y,t.reset()}),this.options.waitNextTapTime)},i.prototype.cancelCountDownToFail=function(){clearTimeout(this._countDownToFailTimer)},i.prototype.reset=function(){this.tapCount=0,this.prevTapPoint=void 0,this.prevTapTime=void 0},i.prototype.test=function(t){var e=t.startInput,n=t.timestamp-e.timestamp,i=this.computed,o=i.maxPointLength,r=i.distance;return o===this.options.pointLength&&this.options.maxDistance>=r&&this.options.maxPressTime>n},i}(O),Z={name:"pan",threshold:10,pointLength:1},$=function(t){function i(e){return t.call(this,n(n({},Z),e))||this}return e(i,t),i.prototype.test=function(t){var e=t.pointLength,n=this.computed.distance;return(this.isRecognized||this.options.threshold<n)&&this.isValidPointLength(e)},i.prototype.recognize=function(t,e){if(this.computed=this.compute([G,R,N],t),V(this,t,e)){t.inputType;e(this.options.name+this.computed.direction,this.computed)}},i}(O),J={name:"swipe",threshold:10,velocity:.3,pointLength:1},K=function(t){function i(e){return t.call(this,n(n({},J),e))||this}return e(i,t),i.prototype.test=function(t){var e=t.inputType;if(c!==e)return!1;var n=this.computed,i=n.velocityX,o=n.velocityY,r=n.maxPointLength,s=n.distance;return this.options.pointLength===r&&this.options.threshold<s&&this.options.velocity<Math.max(i,o)},i.prototype.recognize=function(t,e){this.computed=this.compute([U,G,R],t),this.test(t)&&(e(this.options.name,this.computed),e(this.options.name+this.computed.direction,this.computed))},i}(O),Q={name:"press",pointLength:1,maxDistance:9,minPressTime:251},W=function(t){function i(e){return t.call(this,n(n({},Q),e))||this}return e(i,t),i.prototype.recognize=function(t,e){var n=this,i=t.inputType,o=t.startInput,r=t.pointLength;if("start"===i&&this.isValidPointLength(r))S(this),this.cancel(),this._timeoutId=setTimeout((function(){n.status=m,e(n.options.name,t)}),this.options.minPressTime);else if(c===i&&m===this.status)e(this.options.name+"up",this.computed);else{var s=t.timestamp-o.timestamp;(!this.test(t)||this.options.minPressTime>s&&[c,u].includes(i))&&(this.cancel(),this.status=y)}},i.prototype.test=function(t){t.pointLength;this.computed=this.compute([R],t);var e=this.computed.distance;return this.options.maxDistance>e},i.prototype.cancel=function(){clearTimeout(this._timeoutId)},i}(O),tt={name:"pinch",threshold:0,pointLength:2},et=function(t){function i(e){return t.call(this,n(n({},tt),e))||this}return e(i,t),i.prototype.test=function(t){var e=t.pointLength,n=this.computed.scale;return this.isValidPointLength(e)&&void 0!==n&&(this.options.threshold<Math.abs(n-1)||this.isRecognized)},i.prototype.recognize=function(t,e){var i,o,r,s,a,u=this.compute([H],t);"activeV"in u&&(this.computed=n(n({},this.computed),(o=(i=u).startV,r=i.prevV,s=i.activeV,a=T(C(s)/C(r)),{scale:T(C(s)/C(o)),deltaScale:a}))),V(this,t,e)},i}(O),nt={name:"rotate",threshold:0,pointLength:2},it=function(t){function i(e){return t.call(this,n(n({},nt),e))||this}return e(i,t),i.prototype.test=function(t){var e=t.pointLength,n=this.computed.angle;return this.isValidPointLength(e)&&(this.options.threshold<Math.abs(n)||this.isRecognized)},i.prototype.recognize=function(t,e){var i,o,r,s,a,u=this.compute([H],t);"activeV"in u&&(this.computed=n(n({},this.computed),(o=(i=u).startV,r=i.prevV,s=i.activeV,a=Math.round(j(s,r)),{angle:Math.round(j(s,o)),deltaAngle:a}))),V(this,t,e)},i}(O);return D.use(q),D.use($),D.use(K),D.use(W),D.use(et),D.use(it),D.Tap=q,D.Pan=$,D.Swipe=K,D.Press=W,D.Pinch=et,D.Rotate=it,D.STATUS_POSSIBLE="p",D.STATUS_START=d,D.STATUS_MOVE=v,D.STATUS_END=f,D.STATUS_CANCELLED=g,D.STATUS_FAILED=y,D.STATUS_RECOGNIZED=m,D}));
{
"name": "any-touch",
"version": "1.0.0",
"version": "1.0.1",
"description": "一个小巧的手势库",

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

"dependencies": {
"@any-touch/core": "^1.0.0",
"@any-touch/pan": "^0.6.3-beta.0",
"@any-touch/pinch": "^0.6.3-beta.0",
"@any-touch/press": "^0.6.3-beta.0",
"@any-touch/rotate": "^0.6.3-beta.0",
"@any-touch/swipe": "^0.6.3-beta.0",
"@any-touch/tap": "^1.0.0",
"any-event": "^1.0.0",
"@any-touch/core": "^1.0.1",
"@any-touch/pan": "^1.0.1",
"@any-touch/pinch": "^1.0.1",
"@any-touch/press": "^1.0.1",
"@any-touch/rotate": "^1.0.1",
"@any-touch/swipe": "^1.0.1",
"@any-touch/tap": "^1.0.1",
"any-event": "^1.0.1",
"tslib": "^1.9.3"

@@ -42,3 +42,3 @@ },

"sideEffects": false,
"gitHead": "960b6a0c10c62c957c46616256532789c8080069"
"gitHead": "daec688784b1b67c7e427a0b474deae8773f54e6"
}
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