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.11 to 1.0.12

2

dist/any-touch.umd.js

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

};
AnyTouch.version = '1.0.10';
AnyTouch.version = '1.0.11';
AnyTouch._$Recognizers = [];

@@ -591,0 +591,0 @@ AnyTouch._$computeFunctionMap = {};

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

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

"dependencies": {
"@any-touch/core": "^1.0.11",
"@any-touch/pan": "^1.0.11",
"@any-touch/pinch": "^1.0.11",
"@any-touch/press": "^1.0.11",
"@any-touch/rotate": "^1.0.11",
"@any-touch/swipe": "^1.0.11",
"@any-touch/tap": "^1.0.11",
"any-event": "^1.0.11",
"@any-touch/core": "^1.0.12",
"@any-touch/pan": "^1.0.12",
"@any-touch/pinch": "^1.0.12",
"@any-touch/press": "^1.0.12",
"@any-touch/rotate": "^1.0.12",
"@any-touch/swipe": "^1.0.12",
"@any-touch/tap": "^1.0.12",
"any-event": "^1.0.12",
"tslib": "^1.9.3"

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

"sideEffects": false,
"gitHead": "ccf43609e58361faa102eb278c1ae6518b0b586c"
"gitHead": "ac34054ccf1ef99c76d20ad33d838ba4855be90f"
}
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