any-touch
Advanced tools
Comparing version 1.0.7 to 1.0.8
@@ -367,3 +367,4 @@ (function (global, factory) { | ||
var TOUCH_EVENTS = [TOUCH_START, TOUCH_MOVE, TOUCH_END, TOUCH_CANCEL]; | ||
function bindElement (el, catchEvent, options) { | ||
function bindElement (el, catchEvent, options, _a) { | ||
var _b = __read(_a === void 0 ? [window, window] : _a, 2), mousemoveTarget = _b[0], mouseupTarget = _b[1]; | ||
TOUCH_EVENTS.forEach(function (eventName) { | ||
@@ -373,4 +374,4 @@ el.addEventListener(eventName, catchEvent, options); | ||
el.addEventListener(MOUSE_DOWN, catchEvent, options); | ||
window.addEventListener(MOUSE_MOVE, catchEvent, options); | ||
window.addEventListener(MOUSE_UP, catchEvent, options); | ||
mousemoveTarget.addEventListener(MOUSE_MOVE, catchEvent, options); | ||
mouseupTarget.addEventListener(MOUSE_UP, catchEvent, options); | ||
return function () { | ||
@@ -381,4 +382,4 @@ TOUCH_EVENTS.forEach(function (eventName) { | ||
el.removeEventListener(MOUSE_DOWN, catchEvent, options); | ||
window.removeEventListener(MOUSE_MOVE, catchEvent, options); | ||
window.removeEventListener(MOUSE_UP, catchEvent, options); | ||
mousemoveTarget.removeEventListener(MOUSE_MOVE, catchEvent, options); | ||
mouseupTarget.removeEventListener(MOUSE_UP, catchEvent, options); | ||
}; | ||
@@ -455,3 +456,5 @@ } | ||
preventDefault: true, | ||
preventDefaultExclude: /^(?:INPUT|TEXTAREA|BUTTON|SELECT)$/ | ||
preventDefaultExclude: /^(?:INPUT|TEXTAREA|BUTTON|SELECT)$/, | ||
mousemoveTarget: window, | ||
mouseupTarget: window | ||
}; | ||
@@ -497,3 +500,3 @@ var AnyTouch = (function (_super) { | ||
catch (_b) { } | ||
_this.on('unbind', bindElement(el, _this.catchEvent.bind(_this), !_this.options.preventDefault && supportsPassive_1 ? { passive: true } : false)); | ||
_this.on('unbind', bindElement(el, _this.catchEvent.bind(_this), !_this.options.preventDefault && supportsPassive_1 ? { passive: true } : false, [_this.options.mousemoveTarget, _this.options.mouseupTarget])); | ||
} | ||
@@ -590,3 +593,3 @@ return _this; | ||
}; | ||
AnyTouch.version = '1.0.6'; | ||
AnyTouch.version = '1.0.7'; | ||
AnyTouch._$recognizers = []; | ||
@@ -593,0 +596,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)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",v="move",l=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(),v=_(i)||_(r),l=v.x,f=v.y,d=o.currentTarget;return Object.assign(t,{id:e,x:l,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:l-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,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(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 M=["touchstart","touchmove",c,p];function b(t,e,n){var r,o,a=null==n?void 0:n.name;if(void 0===a||void 0===t._$recognizerMap[a]){var s=new e(n);try{for(var u=i(s.computeFunctions),c=u.next();!c.done;c=u.next()){var p=c.value,h=p._id;void 0===t._$computeFunctionMap[h]&&(t._$computeFunctionMap[h]="version"in t?p:p())}}catch(t){r={error:t}}finally{try{c&&!c.done&&(o=u.return)&&o.call(u)}finally{if(r)throw r.error}}t._$recognizerMap[s.name]=s,t._$recognizers.push(t._$recognizerMap[s.name])}}function x(t,e){var n,o;if(void 0===e)t._$recognizers=[],t._$recognizerMap={};else try{for(var a=i(t._$recognizers.entries()),s=a.next();!s.done;s=a.next()){var u=r(s.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{s&&!s.done&&(o=a.return)&&o.call(a)}finally{if(n)throw n.error}}}function E(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&&($(r,e,t.options.domEvents),$(r,n(n({},e),{_type:e.type,type:"at:after"}),t.options.domEvents))}var w={domEvents:{bubbles:!0,cancelable:!0},preventDefault:!0,preventDefaultExclude:/^(?:INPUT|TEXTAREA|BUTTON|SELECT)$/},L=function(t){function r(e,i){var o,a=t.call(this)||this;for(var s in a._$computeFunctionMap={},a._$recognizerMap={},a._$recognizers=[],a.el=e,a.options=n(n({},w),i),r._$computeFunctionMap)a._$computeFunctionMap[s]=r._$computeFunctionMap[s]();a._$recognizerMap=r._$recognizerMap,a._$recognizers=r._$recognizers;var h,v,l,f,d=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})}}(a.el),m=(v=!1,l=null,f=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?(l=a,v=!0,e="start"):v&&("mousemove"===r?e="move":"mouseup"===r&&(s=[],e=u,v=!1));var c=h||[{clientX:n,clientY:i,target:a}];if(h=[{clientX:n,clientY:i,target:a}],void 0!==e)return f({stage:e,changedPoints:c,points:s,target:l,targets:[l],nativeEvent:t})});if(a._$inputCreatorMap=((o={}).touchstart=d,o.touchmove=d,o[c]=d,o[p]=d,o.mousedown=m,o.mousemove=m,o.mouseup=m,o),void 0!==e){e.style.webkitTapHighlightColor="rgba(0,0,0,0)";var y=!1;try{var _={};Object.defineProperty(_,"passive",{get:function(){y=!0}}),window.addEventListener("_",(function(){}),_)}catch(t){}a.on("unbind",function(t,e,n){return M.forEach((function(i){t.addEventListener(i,e,n)})),t.addEventListener("mousedown",e,n),window.addEventListener("mousemove",e,n),window.addEventListener("mouseup",e,n),function(){M.forEach((function(n){t.removeEventListener(n,e)})),t.removeEventListener("mousedown",e,n),window.removeEventListener("mousemove",e,n),window.removeEventListener("mouseup",e,n)}}(e,a.catchEvent.bind(a),!(a.options.preventDefault||!y)&&{passive:!0}))}return a}return e(r,t),r.prototype.target=function(t){var e=this;return{on:function(n,i){e.on(n,i,(function(e){var n=e.targets;return e.target===t&&n.every((function(e){return t.contains(e)}))}))}}},r.prototype.catchEvent=function(t){var e,r,o=this,a=function(){return t.stopPropagation()},s=function(){return t.preventDefault()};T(t,this.options)&&s();var u=this._$inputCreatorMap[t.type](t);if(void 0!==u){var c="at:"+u.stage;this.emit("at",u),this.emit(c,u);var p=this.options.domEvents;if(!1!==p){var h=t.target;null!==h&&($(h,n(n({},u),{type:"at"}),p),$(h,n(n({},u),{type:c}),p))}var v=u;for(var l in this._$computeFunctionMap)Object.assign(v,this._$computeFunctionMap[l](v));var f=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});null==Object||Object.freeze(i),void 0===o.beforeEachHook?E(o,i):o.beforeEachHook(t,o._$recognizerMap,(function(){E(o,i)}))}))};try{for(var d=i(this._$recognizers),m=d.next();!m.done;m=d.next()){f(m.value)}}catch(t){e={error:t}}finally{try{m&&!m.done&&(r=d.return)&&r.call(d)}finally{if(e)throw e.error}}}},r.prototype.use=function(t,e){b(this,t,e)},r.prototype.removeUse=function(t){x(this,t)},r.prototype.beforeEach=function(t){this.beforeEachHook=t},r.prototype.get=function(t){return this._$recognizerMap[t]},r.prototype.set=function(t){this.options=n(n({},this.options),t)},r.prototype.destroy=function(){this.emit("unbind"),this.listenersMap={}},r.version="1.0.6",r._$recognizers=[],r._$recognizerMap={},r._$computeFunctionMap={},r.use=function(t,e){b(r,t,e)},r.removeUse=function(t){x(r,t)},r}(o);function P(t){-1!==[l,m,f,d].indexOf(t.status)&&(t.status="p")}function z(t,e,n){var i=t._$test(e);P(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=v,o[u]=l,o[s]=m,o),i[v]=(a={},a.move=v,a[u]=l,a[s]=m,a),i),0:(c={},c[h]=(p={},p.move=d,p[u]=l,p[s]=m,p),c[v]=(f={},f.start=d,f.move=d,f[u]=l,f[s]=m,f),c)}[Number(t)][e];return void 0!==y&&y[n]||e}(i,t.status,r),t._$isRecognized=[h,v].includes(t.status);var o=t.name,a=t.status,c=t._$isRecognized;return c&&n(o),(c||[l,m].includes(t.status))&&n(o+a),i}var O=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}(),S=function(t){return Math.sqrt(t.x*t.x+t.y*t.y)},F=function(t){return t/Math.PI*180},D=function(t,e){var n=function(t,e){var n=S(t)*S(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),F(n)},X=function(t,e){return Math.abs(t)>=Math.abs(e)?0<t?"right":"left":0<e?"down":"up"};function A(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:A(n),prevV:A(e),activeV:A(t)}}function V(){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(D(r,n));return{angle:Math.round(D(r,i)),deltaAngle:o,_vs:e}}}}function Y(){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(F(Math.acos(Math.abs(n)/o)))}return{deltaX:n,deltaY:i,deltaXYAngle:r}}}function j(){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(S({x:i,y:r})),t=X(e,n)),{displacementX:e,displacementY:n,distanceX:i,distanceY:r,distance:o,overallDirection:t}}}function C(){var t=0;return function(e){return"start"===e.stage&&(t=e.pointLength),{maxPointLength:t}}}function N(){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(S(r)/S(n));return{scale:y(S(r)/S(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=X(c,p)||t,e=a}}return{velocityX:n,velocityY:i,speedX:r,speedY:o,direction:t}}}V._id="a",Y._id="b",j._id="c",C._id="d",N._id="e",R._id="f";var U={name:"tap",pointLength:1,tapTimes:1,waitNextTapTime:300,maxDistance:2,maxDistanceFromPrevTap:9,maxPressTime:250},k=function(t){function i(e){var i=t.call(this,n(n({},U),e))||this;return i.computeFunctions=[j,C],i._$tapCount=0,i}return e(i,t),i.prototype._isValidDistanceFromPrevTap=function(t){if(void 0!==this._$prevTapPoint){var e=S({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}(O),H={name:"pan",threshold:10,pointLength:1},B=function(t){function i(e){var i=t.call(this,n(n({},H),e))||this;return i.computeFunctions=[R,j,Y],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&&z(this,t,e)&&e(this.options.name+t.direction)},i}(O),q={name:"swipe",threshold:10,velocity:.3,pointLength:1},G=function(t){function i(e){var i=t.call(this,n(n({},q),e))||this;return i.computeFunctions=[j,R,C],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}(O),Z={name:"press",pointLength:1,maxDistance:9,minPressTime:251},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.recognize=function(t,e){var n=this,i=t.stage,r=t.startInput,o=t.pointLength;if("start"===i&&this._$isValidPointLength(o))P(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}(O),K={name:"pinch",threshold:0,pointLength:2},Q=function(t){function i(e){var i=t.call(this,n(n({},K),e))||this;return i.computeFunctions=[N],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){z(this,t,e)},i}(O),W={name:"rotate",threshold:0,pointLength:2},tt=function(t){function i(e){var i=t.call(this,n(n({},W),e))||this;return i.computeFunctions=[V],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){z(this,t,e)},i}(O);return L.use(k),L.use(B),L.use(G),L.use(J),L.use(Q),L.use(tt),L.Tap=k,L.Pan=B,L.Swipe=G,L.Press=J,L.Pinch=Q,L.Rotate=tt,L.STATUS_POSSIBLE="p",L.STATUS_START=h,L.STATUS_MOVE=v,L.STATUS_END=l,L.STATUS_CANCELLED=m,L.STATUS_FAILED=d,L.STATUS_RECOGNIZED=f,L})); | ||
!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 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&&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 o(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var i,o,r=n.call(t),a=[];try{for(;(void 0===e||e-- >0)&&!(i=r.next()).done;)a.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 a}var r=function(){function t(){this.listenersMap={}}return t.prototype.on=function(t,e,n){var o,r,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){o={error:t}}finally{try{u&&!u.done&&(r=s.return)&&r.call(s)}finally{if(o)throw o.error}}return this},t.prototype.emit=function(t,e){var n,o,r=this.listenersMap[t];if(void 0!==r&&0<r.length)try{for(var a=i(r),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&&(o=a.return)&&o.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,v="start",h="move",l=u,f="r",d="f",m=s;function y(t){return Math.round(100*t)/100}function g(){var t,e,i,o,r=0;return function(a){if(t=e,void 0!==a){var c=function(t,e){var n=t.stage,i=t.points,o=t.changedPoints,r=t.nativeEvent,a=i.length,c="start"===n,p=u===n&&0===a||s===n,v=Date.now(),h=_(i)||_(o),l=h.x,f=h.y,d=r.currentTarget;return Object.assign(t,{id:e,x:l,y:f,timestamp:v,isStart:c,isEnd:p,pointLength:a,currentTarget:d,getOffset:function(t){void 0===t&&(t=d);var e=t.getBoundingClientRect();return{x:l-Math.round(e.left),y:f-Math.round(e.top)}}})}(a,r=Number.MAX_SAFE_INTEGER>r?++r:1);e=c;var p=c.isStart,v=c.pointLength;return p&&(i=c,t=void 0,o=1<v?c:void 0),n(n({},c),{prevInput:t,startMultiInput:o,startInput:i})}}}function _(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 T(t,e,n){e.target,e.currentTarget;var i,o=e.type,r=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 document.createEvent?(i=document.createEvent("HTMLEvents")).initEvent(o,null==n?void 0:n.bubbles,null==n?void 0:n.cancelable):i=new Event(o,n),Object.assign(i,r,{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 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 M=["touchstart","touchmove",c,p];function b(t,e,n){var o,r,a=null==n?void 0:n.name;if(void 0===a||void 0===t._$recognizerMap[a]){var s=new e(n);try{for(var u=i(s.computeFunctions),c=u.next();!c.done;c=u.next()){var p=c.value,v=p._id;void 0===t._$computeFunctionMap[v]&&(t._$computeFunctionMap[v]="version"in t?p:p())}}catch(t){o={error:t}}finally{try{c&&!c.done&&(r=u.return)&&r.call(u)}finally{if(o)throw o.error}}t._$recognizerMap[s.name]=s,t._$recognizers.push(t._$recognizerMap[s.name])}}function x(t,e){var n,r;if(void 0===e)t._$recognizers=[],t._$recognizerMap={};else try{for(var a=i(t._$recognizers.entries()),s=a.next();!s.done;s=a.next()){var u=o(s.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{s&&!s.done&&(r=a.return)&&r.call(a)}finally{if(n)throw n.error}}}function E(t,e){var i=e.type,o=e.target;t.emit(i,e),t.emit("at:after",e),t.options.domEvents&&void 0!==t.el&&null!==o&&(T(o,e,t.options.domEvents),T(o,n(n({},e),{_type:e.type,type:"at:after"}),t.options.domEvents))}var w={domEvents:{bubbles:!0,cancelable:!0},preventDefault:!0,preventDefaultExclude:/^(?:INPUT|TEXTAREA|BUTTON|SELECT)$/,mousemoveTarget:window,mouseupTarget:window},L=function(t){function r(e,i){var a,s=t.call(this)||this;for(var v in s._$computeFunctionMap={},s._$recognizerMap={},s._$recognizers=[],s.el=e,s.options=n(n({},w),i),r._$computeFunctionMap)s._$computeFunctionMap[v]=r._$computeFunctionMap[v]();s._$recognizerMap=r._$recognizerMap,s._$recognizers=r._$recognizers;var h,l,f,d,m=function(t){var e=g();return function(n){var i=[],o=[];Array.from(n.touches).forEach((function(e){var n=e.clientX,r=e.clientY,a=e.target;(null==t?void 0:t.contains(a))&&(i.push(a),o.push({clientX:n,clientY:r,target:a}))}));var r=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:r,points:o,nativeEvent:n,target:n.target,targets:i})}}(s.el),y=(l=!1,f=null,d=g(),function(t){var e,n=t.clientX,i=t.clientY,o=t.type,r=t.button,a=t.target,s=[{clientX:n,clientY:i,target:a}];"mousedown"===o&&0===r?(f=a,l=!0,e="start"):l&&("mousemove"===o?e="move":"mouseup"===o&&(s=[],e=u,l=!1));var c=h||[{clientX:n,clientY:i,target:a}];if(h=[{clientX:n,clientY:i,target:a}],void 0!==e)return d({stage:e,changedPoints:c,points:s,target:f,targets:[f],nativeEvent:t})});if(s._$inputCreatorMap=((a={}).touchstart=m,a.touchmove=m,a[c]=m,a[p]=m,a.mousedown=y,a.mousemove=y,a.mouseup=y,a),void 0!==e){e.style.webkitTapHighlightColor="rgba(0,0,0,0)";var _=!1;try{var T={};Object.defineProperty(T,"passive",{get:function(){_=!0}}),window.addEventListener("_",(function(){}),T)}catch(t){}s.on("unbind",function(t,e,n,i){var r=o(void 0===i?[window,window]:i,2),a=r[0],s=r[1];return M.forEach((function(i){t.addEventListener(i,e,n)})),t.addEventListener("mousedown",e,n),a.addEventListener("mousemove",e,n),s.addEventListener("mouseup",e,n),function(){M.forEach((function(n){t.removeEventListener(n,e)})),t.removeEventListener("mousedown",e,n),a.removeEventListener("mousemove",e,n),s.removeEventListener("mouseup",e,n)}}(e,s.catchEvent.bind(s),!(s.options.preventDefault||!_)&&{passive:!0},[s.options.mousemoveTarget,s.options.mouseupTarget]))}return s}return e(r,t),r.prototype.target=function(t){var e=this;return{on:function(n,i){e.on(n,i,(function(e){var n=e.targets;return e.target===t&&n.every((function(e){return t.contains(e)}))}))}}},r.prototype.catchEvent=function(t){var e,o,r=this,a=function(){return t.stopPropagation()},s=function(){return t.preventDefault()};$(t,this.options)&&s();var u=this._$inputCreatorMap[t.type](t);if(void 0!==u){var c="at:"+u.stage;this.emit("at",u),this.emit(c,u);var p=this.options.domEvents;if(!1!==p){var v=t.target;null!==v&&(T(v,n(n({},u),{type:"at"}),p),T(v,n(n({},u),{type:c}),p))}var h=u;for(var l in this._$computeFunctionMap)Object.assign(h,this._$computeFunctionMap[l](h));var f=function(t){if(t.disabled)return"continue";t.recognize(h,(function(e){var i=n(n({},h),{type:e,name:t.name,stopPropagation:a,preventDefault:s});null==Object||Object.freeze(i),void 0===r.beforeEachHook?E(r,i):r.beforeEachHook(t,r._$recognizerMap,(function(){E(r,i)}))}))};try{for(var d=i(this._$recognizers),m=d.next();!m.done;m=d.next()){f(m.value)}}catch(t){e={error:t}}finally{try{m&&!m.done&&(o=d.return)&&o.call(d)}finally{if(e)throw e.error}}}},r.prototype.use=function(t,e){b(this,t,e)},r.prototype.removeUse=function(t){x(this,t)},r.prototype.beforeEach=function(t){this.beforeEachHook=t},r.prototype.get=function(t){return this._$recognizerMap[t]},r.prototype.set=function(t){this.options=n(n({},this.options),t)},r.prototype.destroy=function(){this.emit("unbind"),this.listenersMap={}},r.version="1.0.7",r._$recognizers=[],r._$recognizerMap={},r._$computeFunctionMap={},r.use=function(t,e){b(r,t,e)},r.removeUse=function(t){x(r,t)},r}(r);function P(t){-1!==[l,m,f,d].indexOf(t.status)&&(t.status="p")}function z(t,e,n){var i=t._$test(e);P(t);var o=e.stage;t.status=function(t,e,n){var i,o,r,a,c,p,f,y={1:(i={},i.p=(o={},o.move=v,o[u]=d,o[s]=d,o),i[v]=(r={},r.move=h,r[u]=l,r[s]=m,r),i[h]=(a={},a.move=h,a[u]=l,a[s]=m,a),i),0:(c={},c[v]=(p={},p.move=d,p[u]=l,p[s]=m,p),c[h]=(f={},f.start=d,f.move=d,f[u]=l,f[s]=m,f),c)}[Number(t)][e];return void 0!==y&&y[n]||e}(i,t.status,o),t._$isRecognized=[v,h].includes(t.status);var r=t.name,a=t.status,c=t._$isRecognized;return c&&n(r),(c||[l,m].includes(t.status))&&n(r+a),i}var O=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}(),S=function(t){return Math.sqrt(t.x*t.x+t.y*t.y)},F=function(t){return t/Math.PI*180},D=function(t,e){var n=function(t,e){var n=S(t)*S(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),F(n)},X=function(t,e){return Math.abs(t)>=Math.abs(e)?0<t?"right":"left":0<e?"down":"up"};function A(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:A(n),prevV:A(e),activeV:A(t)}}function V(){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,o=e.activeV,r=Math.round(D(o,n));return{angle:Math.round(D(o,i)),deltaAngle:r,_vs:e}}}}function Y(){return 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(F(Math.acos(Math.abs(n)/r)))}return{deltaX:n,deltaY:i,deltaXYAngle:o}}}function j(){var t,e=0,n=0,i=0,o=0,r=0;return function(a){var s=a.stage,u=a.startInput;return"start"===s?(e=0,n=0,i=0,o=0,r=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),o=Math.abs(n),r=Math.round(S({x:i,y:o})),t=X(e,n)),{displacementX:e,displacementY:n,distanceX:i,distanceY:o,distance:r,overallDirection:t}}}function C(){var t=0;return function(e){return"start"===e.stage&&(t=e.pointLength),{maxPointLength:t}}}function N(){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,o=e.activeV,r=y(S(o)/S(n));return{scale:y(S(o)/S(i)),deltaScale:r,_vs:e}}}}function R(){var t,e,n=0,i=0,o=0,r=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;o=Math.round(c/u*100)/100,r=Math.round(p/u*100)/100,n=Math.abs(o),i=Math.abs(r),t=X(c,p)||t,e=a}}return{velocityX:n,velocityY:i,speedX:o,speedY:r,direction:t}}}V._id="a",Y._id="b",j._id="c",C._id="d",N._id="e",R._id="f";var U={name:"tap",pointLength:1,tapTimes:1,waitNextTapTime:300,maxDistance:2,maxDistanceFromPrevTap:9,maxPressTime:250},k=function(t){function i(e){var i=t.call(this,n(n({},U),e))||this;return i.computeFunctions=[j,C],i._$tapCount=0,i}return e(i,t),i.prototype._isValidDistanceFromPrevTap=function(t){if(void 0!==this._$prevTapPoint){var e=S({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,o=t.x,r=t.y;u===i&&(this.status="p",this._$test(t)?(clearTimeout(this._$countDownToFailTimer),this._isValidDistanceFromPrevTap({x:o,y:r})&&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,o=t.maxPointLength,r=t.distance;return o===this.options.pointLength&&0===n&&this.options.maxDistance>=r&&this.options.maxPressTime>i},i}(O),H={name:"pan",threshold:10,pointLength:1},B=function(t){function i(e){var i=t.call(this,n(n({},H),e))||this;return i.computeFunctions=[R,j,Y],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&&z(this,t,e)&&e(this.options.name+t.direction)},i}(O),q={name:"swipe",threshold:10,velocity:.3,pointLength:1},G=function(t){function i(e){var i=t.call(this,n(n({},q),e))||this;return i.computeFunctions=[j,R,C],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,o=t.distance;return this.options.pointLength===i&&this.options.threshold<o&&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}(O),Z={name:"press",pointLength:1,maxDistance:9,minPressTime:251},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.recognize=function(t,e){var n=this,i=t.stage,o=t.startInput,r=t.pointLength;if("start"===i&&this._$isValidPointLength(r))P(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-o.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}(O),K={name:"pinch",threshold:0,pointLength:2},Q=function(t){function i(e){var i=t.call(this,n(n({},K),e))||this;return i.computeFunctions=[N],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){z(this,t,e)},i}(O),W={name:"rotate",threshold:0,pointLength:2},tt=function(t){function i(e){var i=t.call(this,n(n({},W),e))||this;return i.computeFunctions=[V],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){z(this,t,e)},i}(O);return L.use(k),L.use(B),L.use(G),L.use(J),L.use(Q),L.use(tt),L.Tap=k,L.Pan=B,L.Swipe=G,L.Press=J,L.Pinch=Q,L.Rotate=tt,L.STATUS_POSSIBLE="p",L.STATUS_START=v,L.STATUS_MOVE=h,L.STATUS_END=l,L.STATUS_CANCELLED=m,L.STATUS_FAILED=d,L.STATUS_RECOGNIZED=f,L})); |
{ | ||
"name": "any-touch", | ||
"version": "1.0.7", | ||
"version": "1.0.8", | ||
"description": "一个小巧的手势库", | ||
@@ -25,10 +25,10 @@ "unpkg": "dist/any-touch.umd.min.js", | ||
"dependencies": { | ||
"@any-touch/core": "^1.0.7", | ||
"@any-touch/pan": "^1.0.7", | ||
"@any-touch/pinch": "^1.0.7", | ||
"@any-touch/press": "^1.0.7", | ||
"@any-touch/rotate": "^1.0.7", | ||
"@any-touch/swipe": "^1.0.7", | ||
"@any-touch/tap": "^1.0.7", | ||
"any-event": "^1.0.7", | ||
"@any-touch/core": "^1.0.8", | ||
"@any-touch/pan": "^1.0.8", | ||
"@any-touch/pinch": "^1.0.8", | ||
"@any-touch/press": "^1.0.8", | ||
"@any-touch/rotate": "^1.0.8", | ||
"@any-touch/swipe": "^1.0.8", | ||
"@any-touch/tap": "^1.0.8", | ||
"any-event": "^1.0.8", | ||
"tslib": "^1.9.3" | ||
@@ -42,3 +42,3 @@ }, | ||
"sideEffects": false, | ||
"gitHead": "fa8e0eb63d3f306ad6f381ec6bac173c70559e5b" | ||
"gitHead": "091b35dbc61d8d29ce3d3958ecad249521c12bb4" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
74885
1170
Updated@any-touch/core@^1.0.8
Updated@any-touch/pan@^1.0.8
Updated@any-touch/pinch@^1.0.8
Updated@any-touch/press@^1.0.8
Updated@any-touch/rotate@^1.0.8
Updated@any-touch/swipe@^1.0.8
Updated@any-touch/tap@^1.0.8
Updatedany-event@^1.0.8