any-touch
Advanced tools
Comparing version 2.0.0-alpha.0 to 2.0.0-alpha.1
@@ -1022,3 +1022,3 @@ (function (global, factory) { | ||
} | ||
default_1.version = '1.0.14'; | ||
default_1.version = '2.0.0-alpha.0'; | ||
default_1.STATE_POSSIBLE = STATE.POSSIBLE; | ||
@@ -1025,0 +1025,0 @@ default_1.STATE_START = STATE.START; |
@@ -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){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}var n=function(){return(n=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var i in e=arguments[n])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t}).apply(this,arguments)};function r(t){var e="function"==typeof Symbol&&Symbol.iterator,n=e&&t[e],r=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}var i=function(){function t(){this.__map={}}return t.prototype.beforeEach=function(t){this.__interceptor=t},t.prototype.on=function(t,e){var n,i,o=Array.isArray(t)?t:[t];try{for(var a=r(o),u=a.next();!u.done;u=a.next()){var c=u.value;this.__map[c]=this.__map[c]||[];var s=this.__map[c];s&&s.push(e)}}catch(t){n={error:t}}finally{try{u&&!u.done&&(i=a.return)&&i.call(a)}finally{if(n)throw n.error}}return this},t.prototype.emit=function(t,e){var n=this;void 0!==this.__interceptor?this.__interceptor(this,(function(){n.__emit(t,e)})):this.__emit(t,e)},t.prototype.__emit=function(t,e){var n,i,o=this.__map[t];if(Array.isArray(o)&&(null==o?void 0:o.length))try{for(var a=r(o),u=a.next();!u.done;u=a.next()){(0,u.value)(e)}}catch(t){n={error:t}}finally{try{u&&!u.done&&(i=a.return)&&i.call(a)}finally{if(n)throw n.error}}this.event=e},t.prototype.off=function(t,e){var n=this.__map[t];if(void 0!==n)if(void 0===e)delete this.__map[t];else{var r=n.findIndex((function(t){return t===e}));n.splice(r,1)}},t.prototype.destroy=function(){this.__map={}},t}(),o=Object.prototype.toString;var a,u,c="cancel",s="end",p="touch"+s,v="touch"+c;!function(t){t[t.POSSIBLE=0]="POSSIBLE",t[t.RECOGNIZED=1]="RECOGNIZED",t[t.FAILED=2]="FAILED",t[t.CANCELLED=3]="CANCELLED",t[t.START=4]="START",t[t.MOVE=5]="MOVE",t[t.END=1]="END"}(a||(a={}));var f=((u={})[a.START]="start",u[a.MOVE]="move",u[a.END]=s,u[a.CANCELLED]=c,u);function l(t){return f[t]}function h(t,e,n){var r,i,o,u,p,v,f,l={1:(r={},r[a.POSSIBLE]=(i={},i.move=a.START,i),r[a.START]=(o={},o.move=a.MOVE,o[s]=a.END,o[c]=a.CANCELLED,o),r[a.MOVE]=(u={},u.move=a.MOVE,u[s]=a.END,u[c]=a.CANCELLED,u),r),0:(p={},p[a.START]=(v={},v.move=a.FAILED,v[s]=a.END,v[c]=a.CANCELLED,v),p[a.MOVE]=(f={},f.start=a.FAILED,f.move=a.FAILED,f[s]=a.END,f[c]=a.CANCELLED,f),p)}[Number(t)][e];return void 0!==l&&l[n]||a.POSSIBLE}function m(t){[a.RECOGNIZED,a.CANCELLED,a.FAILED].includes(t.state)&&(t.state=a.POSSIBLE)}function d(t){return[a.START,a.MOVE].includes(t)}function E(t){if(t.disabled)return t.state=a.POSSIBLE,!0}function y(t,e){return n(n(n({},t),e),{state:a.POSSIBLE,disabled:!1})}function g(t){return Math.round(100*t)/100}function L(){var t,e,r,i,o=0;return function(a){if(t=e,void 0!==a){var u=function(t,e){var n=t.phase,r=t.points,i=t.changedPoints,o=t.nativeEvent,a=r.length,u="start"===n,p=s===n&&0===a||c===n,v=Date.now(),f=_(r)||_(i),l=f.x,h=f.y,m=o.currentTarget;return Object.assign(t,{id:e,x:l,y:h,timestamp:v,isStart:u,isEnd:p,pointLength:a,currentTarget:m,getOffset:function(t){void 0===t&&(t=m);var e=t.getBoundingClientRect();return{x:l-Math.round(e.left),y:h-Math.round(e.top)}}})}(a,o=Number.MAX_SAFE_INTEGER>o?++o:1);e=u;var p=u.isStart,v=u.pointLength;return p&&(r=u,t=void 0,i=1<v?u:void 0),n(n({},u),{prevInput:t,startMultiInput:i,startInput:r})}}}function _(t){var e=t.length;if(0<e){if(1===e){var n=t[0],r=n.clientX,i=n.clientY;return{x:Math.round(r),y:Math.round(i)}}var o=t.reduce((function(t,e){return t.x+=e.clientX,t.y+=e.clientY,t}),{x:0,y:0});return{x:Math.round(o.x/e),y:Math.round(o.y/e)}}}function T(t,e,n,r){n.target,n.currentTarget,n.type;var i,o=function(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(r=Object.getOwnPropertySymbols(t);i<r.length;i++)e.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(t,r[i])&&(n[r[i]]=t[r[i]])}return n}(n,["target","currentTarget","type"]);return document.createEvent?(i=document.createEvent("HTMLEvents")).initEvent(t,null==r?void 0:r.bubbles,null==r?void 0:r.cancelable):i=new Event(t,r),Object.assign(i,o,{match:function(){return n.targets&&0<n.targets.length&&n.targets.every((function(t){return i.currentTarget.contains(t)}))}}),e.dispatchEvent(i)}function x(t,e){var n,r=e.preventDefault;return n=r,"[object Function]"===o.call(n)?r(t):!!r}var O=["touchstart","touchmove",p,v];var b={domEvents:{bubbles:!0,cancelable:!0},preventDefault:function(t){if(t.target&&"tagName"in t.target){var e=t.target.tagName;return!/^(?:INPUT|TEXTAREA|BUTTON|SELECT)$/.test(e)}return!1}},D=function(t){function i(e,r){var i,o=t.call(this)||this;o.__computeFunctionList=[],o.__computeFunctionCreatorList=[],o.__plugins=[],o.el=e,o.__options=n(n({},b),r);var a,u,c,f,l=function(t){var e=L();return function(n){var r=[],i=[];Array.from(n.touches).forEach((function(e){var n=e.clientX,o=e.clientY,a=e.target;(null==t?void 0:t.contains(a))&&(r.push(a),i.push({clientX:n,clientY:o,target:a}))}));var o=Array.from(n.changedTouches).map((function(t){return{clientX:t.clientX,clientY:t.clientY,target:t.target}}));return e({phase:n.type.replace("touch",""),changedPoints:o,points:i,nativeEvent:n,target:n.target,targets:r})}}(o.el),h=(u=!1,c=null,f=L(),function(t){var e,n=t.clientX,r=t.clientY,i=t.type,o=t.button,p=t.target,v=[{clientX:n,clientY:r,target:p}];if("mousedown"===i&&0===o)c=p,u=!0,e="start";else{if(!u)return;"mousemove"===i?e="move":"mouseup"===i&&(v=[],e=s,u=!1)}var l=a||[{clientX:n,clientY:r,target:p}];if(a=[{clientX:n,clientY:r,target:p}],void 0!==e)return f({phase:e,changedPoints:l,points:v,target:c,targets:[c],nativeEvent:t})});if(o.__inputCreatorMap=((i={}).touchstart=l,i.touchmove=l,i[p]=l,i[v]=l,i.mousedown=h,i.mousemove=h,i.mouseup=h,i),void 0!==e){e.style.webkitTapHighlightColor="rgba(0,0,0,0)";var m=!1;try{var d={};Object.defineProperty(d,"passive",{get:function(){m=!0}}),window.addEventListener("_",(function(){}),d)}catch(t){}o.on("u",function(t,e,n){return O.forEach((function(r){t.addEventListener(r,e,n)})),t.addEventListener("mousedown",e,n),window.addEventListener("mousemove",e,n),window.addEventListener("mouseup",e,n),function(){O.forEach((function(n){t.removeEventListener(n,e)})),t.removeEventListener("mousedown",e,n),window.removeEventListener("mousemove",e,n),window.removeEventListener("mouseup",e,n)}}(e,o.catchEvent.bind(o),!(!1!==o.__options.preventDefault||!m)&&{passive:!0}))}return o}return e(i,t),i.prototype.use=function(t,e){this.__plugins.push(t(this,e))},i.prototype.catchEvent=function(t){var e=this.__inputCreatorMap[t.type](t);if(void 0!==e){var r=function(){return t.preventDefault()};x(t,this.__options)&&r(),this.emit("input",e),this.emit2("at:"+e.phase,e,{});var i={};this.__computeFunctionList.forEach((function(t){var n=t(e,i);if(void 0!==n)for(var r in n)i[r]=n[r]})),this.emit("computed",n(n(n({},e),i),{stopPropagation:function(){return t.stopPropagation()},stopImmediatePropagation:function(){return t.stopImmediatePropagation()},preventDefault:r}))}},i.prototype.compute=function(t,e){var n,i;try{for(var o=r(t),a=o.next();!a.done;a=o.next()){var u=a.value;this.__computeFunctionCreatorList.includes(u)||(this.__computeFunctionCreatorList.push(u),this.__computeFunctionList.push(u()))}}catch(t){n={error:t}}finally{try{a&&!a.done&&(i=o.return)&&i.call(o)}finally{if(n)throw n.error}}this.on("computed",e)},i.prototype.beforeEach=function(e){var r=this;t.prototype.beforeEach.call(this,(function(t,i){var o;void 0===(null===(o=t.c)||void 0===o?void 0:o.name)?i():e(n(n({},t.c),{event:r.event}),i)}))},i.prototype.get=function(t){var e,n;try{for(var i=r(this.__plugins),o=i.next();!o.done;o=i.next()){var a=o.value;if(t===a.name)return a}}catch(t){e={error:t}}finally{try{o&&!o.done&&(n=i.return)&&n.call(i)}finally{if(e)throw e.error}}},i.prototype.set=function(t){this.__options=n(n({},this.__options),t)},i.prototype.emit2=function(t,e,r){this.c=r,this.emit(t,n(n({},e),{type:t}));var i=e.target,o=this.__options.domEvents;o&&void 0!==this.el&&i&&T(t,i,e,o)},i.prototype.destroy=function(){this.emit("u"),t.prototype.destroy.call(this)},i}(i),A=function(t){return Math.sqrt(t.x*t.x+t.y*t.y)},S=function(t){return t/Math.PI*180},I=function(t,e){var n=function(t,e){var n=A(t)*A(e);if(0===n)return 0;var r=function(t,e){return t.x*e.x+t.y*e.y}(t,e)/n;return r>1&&(r=1),Math.acos(r)}(t,e);return function(t,e){return t.x*e.y-e.x*t.y}(t,e)>0&&(n*=-1),S(n)},M=function(t,e){return Math.abs(t)>=Math.abs(e)?0<t?"right":"left":0<e?"down":"up"};function w(){var t=0,e=0;return function(n,r){var i=r.prevVecotr,o=r.startVecotr,a=r.activeVecotr;return a&&(e=Math.round(I(a,i)),t=Math.round(I(a,o))),{angle:t,deltaAngle:e}}}function C(){return function(t){var e=t.prevInput,n=0,r=0,i=0;if(void 0!==e&&(n=t.x-e.x,r=t.y-e.y,0!==n||0!==r)){var o=Math.sqrt(Math.pow(n,2)+Math.pow(r,2));i=Math.round(S(Math.acos(Math.abs(n)/o)))}return{deltaX:n,deltaY:r,deltaXYAngle:i}}}function N(){var t,e=0,n=0,r=0,i=0,o=0;return function(a){var u=a.phase,c=a.startInput;return"start"===u?(e=0,n=0,r=0,i=0,o=0):"move"===u&&(e=Math.round(a.points[0].clientX-c.points[0].clientX),n=Math.round(a.points[0].clientY-c.points[0].clientY),r=Math.abs(e),i=Math.abs(n),o=Math.round(A({x:r,y:i})),t=M(e,n)),{displacementX:e,displacementY:n,distanceX:r,distanceY:i,distance:o,overallDirection:t}}}function P(){var t=1,e=1;return function(n,r){var i=r.prevVecotr,o=r.startVecotr,a=r.activeVecotr;return a&&(t=g(A(a)/A(i)),e=g(A(a)/A(o))),{scale:e,deltaScale:t}}}function X(){var t,e,n=0,r=0,i=0,o=0;return function(a){if(void 0!==a){e=e||a.startInput;var u=a.timestamp-e.timestamp;if(16<u){var c=a.x-e.x,s=a.y-e.y;i=Math.round(c/u*100)/100,o=Math.round(s/u*100)/100,n=Math.abs(i),r=Math.abs(o),t=M(c,s)||t,e=a}}return{velocityX:n,velocityY:r,speedX:i,speedY:o,direction:t}}}function R(){var t=0;return function(e){return"start"===e.phase&&(t=e.pointLength),{maxPointLength:t}}}function F(t){return{x:t.points[1].clientX-t.points[0].clientX,y:t.points[1].clientY-t.points[0].clientY}}function Y(){var t,e,n;return function(r){var i=r.prevInput,o=r.startMultiInput;return void 0!==o&&void 0!==i&&r.id!==o.id&&1<i.pointLength&&1<r.pointLength&&(t=F(o),e=F(i),n=F(r)),{startVecotr:t,prevVecotr:e,activeVecotr:n}}}var V={name:"tap",pointLength:1,tapTimes:1,waitNextTapTime:300,maxDistance:2,maxDistanceFromPrevTap:9,maxPressTime:250};function j(t,e){var n,r,i,o=y(V,e),u=0;function c(){u=0,n=void 0,r=void 0}return t.compute([N,R],(function(e){if(!E(o)){var p,v,f,l,h=e.phase,m=e.x,d=e.y;if(s===h)o.state=a.POSSIBLE,p=e.startInput,v=e.pointLength,f=e.timestamp-p.timestamp,l=e.distance,e.maxPointLength===o.pointLength&&0===v&&o.maxDistance>=l&&o.maxPressTime>f?(clearTimeout(i),function(t,e){if(void 0!==n){var r=A({x:t.x-n.x,y:t.y-n.y});return n=t,e.maxDistanceFromPrevTap>=r}return n=t,!0}({x:m,y:d},o)&&function(t){var e=performance.now();if(void 0===r)return r=e,!0;var n=e-r;return r=e,n<t}(o.waitNextTapTime)?u++:u=1,0==u%o.tapTimes?(o.state=a.RECOGNIZED,t.emit2(o.name,e,o),c()):i=setTimeout((function(){o.state=a.FAILED,c()}),o.waitNextTapTime)):(c(),o.state=a.FAILED)}})),o}var B={name:"pan",threshold:10,pointLength:1};function G(t,e){var n=y(B,e);return t.compute([X,N,C],(function(e){if(m(n),!E(n)){var r,i,o,a,u,c=(r=e.pointLength,i=e.distance,o=e.direction,a=e.phase,(d(u=n.state)||n.threshold<=i)&&n.pointLength===r&&void 0!==o||d(u)&&s===a);if(n.state=h(c,n.state,e.phase),c){var p=n.name;t.emit2(p,e,n),t.emit2(p+l(n.state),e,n)}}})),n}var Z={name:"swipe",threshold:10,velocity:.3,pointLength:1};function q(t,e){var n=y(Z,e);return t.compute([N,X,R],(function(e){if(n.state=a.POSSIBLE,!n.disabled&&function(){if(s!==e.phase)return!1;var t=e.velocityX,r=e.velocityY,i=e.distance;return e.maxPointLength===n.pointLength&&0===e.points.length&&n.threshold<i&&n.velocity<Math.max(t,r)}()){var r=n.name;n.state=a.RECOGNIZED,t.emit2(r,e,n),t.emit2(r+e.direction,e,n)}})),n}var H={name:"press",pointLength:1,maxDistance:9,minPressTime:251};function U(t,e){var n=y(H,e),r=0;return t.compute([N],(function(e){if(!E(n)){var i,o=e.phase,u=e.startInput,p=e.pointLength;if("start"===o&&n.pointLength===p)m(n),clearTimeout(r),r=setTimeout((function(){n.state=a.RECOGNIZED,t.emit2(n.name,e,n)}),n.minPressTime);else if(s===o&&a.RECOGNIZED===n.state)t.emit2(n.name+"up",e,n);else if(a.RECOGNIZED!==n.state){var v=e.timestamp-u.timestamp;(!((i=e.distance)&&n.maxDistance>i)||n.minPressTime>v&&[s,c].includes(o))&&(clearTimeout(r),n.state=a.FAILED)}}})),n}var k={name:"pinch",threshold:0,pointLength:2};function $(t,e){var n=y(k,e);return t.compute([Y,P],(function(e){if(m(n),!E(n)){var r,i,o,a,u=(r=e.pointLength,i=e.scale,o=e.deltaScale,a=e.phase,n.pointLength===r&&(void 0!==i&&void 0!==o&&n.threshold<Math.abs(i-1)||d(n.state))||d(n.state)&&[s,c].includes(a));n.state=h(u,n.state,e.phase);var p=n.name;u&&t.emit2(p,e,n);var v=l(n.state);v&&t.emit2(p+v,e,n)}})),n}var z={name:"rotate",threshold:0,pointLength:2};function J(t,e){var n=y(z,e);return t.compute([Y,w],(function(e){if(!E(n)){m(n);var r,i,o,a=(r=e.pointLength,i=e.angle,o=e.phase,n.pointLength===r&&(n.threshold<Math.abs(i)||d(n.state))||d(n.state)&&[s,c].includes(o));n.state=h(a,n.state,e.phase);var u=n.name;a&&t.emit2(u,e,n);var p=l(n.state);p&&t.emit2(u+p,e,n)}})),n}return function(t){function n(e,n){var r=t.call(this,e,n)||this;return r.use(j),r.use(G),r.use(q),r.use(U),r.use($),r.use(J),r}return e(n,t),n.version="1.0.14",n.STATE_POSSIBLE=a.POSSIBLE,n.STATE_START=a.START,n.STATE_MOVE=a.MOVE,n.STATE_END=a.END,n.STATE_CANCELLED=a.CANCELLED,n.STATE_FAILED=a.FAILED,n.STATE_RECOGNIZED=a.RECOGNIZED,n.tap=j,n.pan=G,n.swipe=q,n.press=U,n.rotate=J,n.pinch=$,n}(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)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])})(e,n)};function e(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}var n=function(){return(n=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var i in e=arguments[n])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t}).apply(this,arguments)};function r(t){var e="function"==typeof Symbol&&Symbol.iterator,n=e&&t[e],r=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}var i=function(){function t(){this.__map={}}return t.prototype.beforeEach=function(t){this.__interceptor=t},t.prototype.on=function(t,e){var n,i,o=Array.isArray(t)?t:[t];try{for(var a=r(o),u=a.next();!u.done;u=a.next()){var c=u.value;this.__map[c]=this.__map[c]||[];var s=this.__map[c];s&&s.push(e)}}catch(t){n={error:t}}finally{try{u&&!u.done&&(i=a.return)&&i.call(a)}finally{if(n)throw n.error}}return this},t.prototype.emit=function(t,e){var n=this;void 0!==this.__interceptor?this.__interceptor(this,(function(){n.__emit(t,e)})):this.__emit(t,e)},t.prototype.__emit=function(t,e){var n,i,o=this.__map[t];if(Array.isArray(o)&&(null==o?void 0:o.length))try{for(var a=r(o),u=a.next();!u.done;u=a.next()){(0,u.value)(e)}}catch(t){n={error:t}}finally{try{u&&!u.done&&(i=a.return)&&i.call(a)}finally{if(n)throw n.error}}this.event=e},t.prototype.off=function(t,e){var n=this.__map[t];if(void 0!==n)if(void 0===e)delete this.__map[t];else{var r=n.findIndex((function(t){return t===e}));n.splice(r,1)}},t.prototype.destroy=function(){this.__map={}},t}(),o=Object.prototype.toString;var a,u,c="cancel",s="end",p="touch"+s,v="touch"+c;!function(t){t[t.POSSIBLE=0]="POSSIBLE",t[t.RECOGNIZED=1]="RECOGNIZED",t[t.FAILED=2]="FAILED",t[t.CANCELLED=3]="CANCELLED",t[t.START=4]="START",t[t.MOVE=5]="MOVE",t[t.END=1]="END"}(a||(a={}));var f=((u={})[a.START]="start",u[a.MOVE]="move",u[a.END]=s,u[a.CANCELLED]=c,u);function l(t){return f[t]}function h(t,e,n){var r,i,o,u,p,v,f,l={1:(r={},r[a.POSSIBLE]=(i={},i.move=a.START,i),r[a.START]=(o={},o.move=a.MOVE,o[s]=a.END,o[c]=a.CANCELLED,o),r[a.MOVE]=(u={},u.move=a.MOVE,u[s]=a.END,u[c]=a.CANCELLED,u),r),0:(p={},p[a.START]=(v={},v.move=a.FAILED,v[s]=a.END,v[c]=a.CANCELLED,v),p[a.MOVE]=(f={},f.start=a.FAILED,f.move=a.FAILED,f[s]=a.END,f[c]=a.CANCELLED,f),p)}[Number(t)][e];return void 0!==l&&l[n]||a.POSSIBLE}function m(t){[a.RECOGNIZED,a.CANCELLED,a.FAILED].includes(t.state)&&(t.state=a.POSSIBLE)}function d(t){return[a.START,a.MOVE].includes(t)}function E(t){if(t.disabled)return t.state=a.POSSIBLE,!0}function y(t,e){return n(n(n({},t),e),{state:a.POSSIBLE,disabled:!1})}function g(t){return Math.round(100*t)/100}function L(){var t,e,r,i,o=0;return function(a){if(t=e,void 0!==a){var u=function(t,e){var n=t.phase,r=t.points,i=t.changedPoints,o=t.nativeEvent,a=r.length,u="start"===n,p=s===n&&0===a||c===n,v=Date.now(),f=_(r)||_(i),l=f.x,h=f.y,m=o.currentTarget;return Object.assign(t,{id:e,x:l,y:h,timestamp:v,isStart:u,isEnd:p,pointLength:a,currentTarget:m,getOffset:function(t){void 0===t&&(t=m);var e=t.getBoundingClientRect();return{x:l-Math.round(e.left),y:h-Math.round(e.top)}}})}(a,o=Number.MAX_SAFE_INTEGER>o?++o:1);e=u;var p=u.isStart,v=u.pointLength;return p&&(r=u,t=void 0,i=1<v?u:void 0),n(n({},u),{prevInput:t,startMultiInput:i,startInput:r})}}}function _(t){var e=t.length;if(0<e){if(1===e){var n=t[0],r=n.clientX,i=n.clientY;return{x:Math.round(r),y:Math.round(i)}}var o=t.reduce((function(t,e){return t.x+=e.clientX,t.y+=e.clientY,t}),{x:0,y:0});return{x:Math.round(o.x/e),y:Math.round(o.y/e)}}}function T(t,e,n,r){n.target,n.currentTarget,n.type;var i,o=function(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(r=Object.getOwnPropertySymbols(t);i<r.length;i++)e.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(t,r[i])&&(n[r[i]]=t[r[i]])}return n}(n,["target","currentTarget","type"]);return document.createEvent?(i=document.createEvent("HTMLEvents")).initEvent(t,null==r?void 0:r.bubbles,null==r?void 0:r.cancelable):i=new Event(t,r),Object.assign(i,o,{match:function(){return n.targets&&0<n.targets.length&&n.targets.every((function(t){return i.currentTarget.contains(t)}))}}),e.dispatchEvent(i)}function x(t,e){var n,r=e.preventDefault;return n=r,"[object Function]"===o.call(n)?r(t):!!r}var O=["touchstart","touchmove",p,v];var b={domEvents:{bubbles:!0,cancelable:!0},preventDefault:function(t){if(t.target&&"tagName"in t.target){var e=t.target.tagName;return!/^(?:INPUT|TEXTAREA|BUTTON|SELECT)$/.test(e)}return!1}},D=function(t){function i(e,r){var i,o=t.call(this)||this;o.__computeFunctionList=[],o.__computeFunctionCreatorList=[],o.__plugins=[],o.el=e,o.__options=n(n({},b),r);var a,u,c,f,l=function(t){var e=L();return function(n){var r=[],i=[];Array.from(n.touches).forEach((function(e){var n=e.clientX,o=e.clientY,a=e.target;(null==t?void 0:t.contains(a))&&(r.push(a),i.push({clientX:n,clientY:o,target:a}))}));var o=Array.from(n.changedTouches).map((function(t){return{clientX:t.clientX,clientY:t.clientY,target:t.target}}));return e({phase:n.type.replace("touch",""),changedPoints:o,points:i,nativeEvent:n,target:n.target,targets:r})}}(o.el),h=(u=!1,c=null,f=L(),function(t){var e,n=t.clientX,r=t.clientY,i=t.type,o=t.button,p=t.target,v=[{clientX:n,clientY:r,target:p}];if("mousedown"===i&&0===o)c=p,u=!0,e="start";else{if(!u)return;"mousemove"===i?e="move":"mouseup"===i&&(v=[],e=s,u=!1)}var l=a||[{clientX:n,clientY:r,target:p}];if(a=[{clientX:n,clientY:r,target:p}],void 0!==e)return f({phase:e,changedPoints:l,points:v,target:c,targets:[c],nativeEvent:t})});if(o.__inputCreatorMap=((i={}).touchstart=l,i.touchmove=l,i[p]=l,i[v]=l,i.mousedown=h,i.mousemove=h,i.mouseup=h,i),void 0!==e){e.style.webkitTapHighlightColor="rgba(0,0,0,0)";var m=!1;try{var d={};Object.defineProperty(d,"passive",{get:function(){m=!0}}),window.addEventListener("_",(function(){}),d)}catch(t){}o.on("u",function(t,e,n){return O.forEach((function(r){t.addEventListener(r,e,n)})),t.addEventListener("mousedown",e,n),window.addEventListener("mousemove",e,n),window.addEventListener("mouseup",e,n),function(){O.forEach((function(n){t.removeEventListener(n,e)})),t.removeEventListener("mousedown",e,n),window.removeEventListener("mousemove",e,n),window.removeEventListener("mouseup",e,n)}}(e,o.catchEvent.bind(o),!(!1!==o.__options.preventDefault||!m)&&{passive:!0}))}return o}return e(i,t),i.prototype.use=function(t,e){this.__plugins.push(t(this,e))},i.prototype.catchEvent=function(t){var e=this.__inputCreatorMap[t.type](t);if(void 0!==e){var r=function(){return t.preventDefault()};x(t,this.__options)&&r(),this.emit("input",e),this.emit2("at:"+e.phase,e,{});var i={};this.__computeFunctionList.forEach((function(t){var n=t(e,i);if(void 0!==n)for(var r in n)i[r]=n[r]})),this.emit("computed",n(n(n({},e),i),{stopPropagation:function(){return t.stopPropagation()},stopImmediatePropagation:function(){return t.stopImmediatePropagation()},preventDefault:r}))}},i.prototype.compute=function(t,e){var n,i;try{for(var o=r(t),a=o.next();!a.done;a=o.next()){var u=a.value;this.__computeFunctionCreatorList.includes(u)||(this.__computeFunctionCreatorList.push(u),this.__computeFunctionList.push(u()))}}catch(t){n={error:t}}finally{try{a&&!a.done&&(i=o.return)&&i.call(o)}finally{if(n)throw n.error}}this.on("computed",e)},i.prototype.beforeEach=function(e){var r=this;t.prototype.beforeEach.call(this,(function(t,i){var o;void 0===(null===(o=t.c)||void 0===o?void 0:o.name)?i():e(n(n({},t.c),{event:r.event}),i)}))},i.prototype.get=function(t){var e,n;try{for(var i=r(this.__plugins),o=i.next();!o.done;o=i.next()){var a=o.value;if(t===a.name)return a}}catch(t){e={error:t}}finally{try{o&&!o.done&&(n=i.return)&&n.call(i)}finally{if(e)throw e.error}}},i.prototype.set=function(t){this.__options=n(n({},this.__options),t)},i.prototype.emit2=function(t,e,r){this.c=r,this.emit(t,n(n({},e),{type:t}));var i=e.target,o=this.__options.domEvents;o&&void 0!==this.el&&i&&T(t,i,e,o)},i.prototype.destroy=function(){this.emit("u"),t.prototype.destroy.call(this)},i}(i),A=function(t){return Math.sqrt(t.x*t.x+t.y*t.y)},S=function(t){return t/Math.PI*180},I=function(t,e){var n=function(t,e){var n=A(t)*A(e);if(0===n)return 0;var r=function(t,e){return t.x*e.x+t.y*e.y}(t,e)/n;return r>1&&(r=1),Math.acos(r)}(t,e);return function(t,e){return t.x*e.y-e.x*t.y}(t,e)>0&&(n*=-1),S(n)},M=function(t,e){return Math.abs(t)>=Math.abs(e)?0<t?"right":"left":0<e?"down":"up"};function w(){var t=0,e=0;return function(n,r){var i=r.prevVecotr,o=r.startVecotr,a=r.activeVecotr;return a&&(e=Math.round(I(a,i)),t=Math.round(I(a,o))),{angle:t,deltaAngle:e}}}function C(){return function(t){var e=t.prevInput,n=0,r=0,i=0;if(void 0!==e&&(n=t.x-e.x,r=t.y-e.y,0!==n||0!==r)){var o=Math.sqrt(Math.pow(n,2)+Math.pow(r,2));i=Math.round(S(Math.acos(Math.abs(n)/o)))}return{deltaX:n,deltaY:r,deltaXYAngle:i}}}function N(){var t,e=0,n=0,r=0,i=0,o=0;return function(a){var u=a.phase,c=a.startInput;return"start"===u?(e=0,n=0,r=0,i=0,o=0):"move"===u&&(e=Math.round(a.points[0].clientX-c.points[0].clientX),n=Math.round(a.points[0].clientY-c.points[0].clientY),r=Math.abs(e),i=Math.abs(n),o=Math.round(A({x:r,y:i})),t=M(e,n)),{displacementX:e,displacementY:n,distanceX:r,distanceY:i,distance:o,overallDirection:t}}}function P(){var t=1,e=1;return function(n,r){var i=r.prevVecotr,o=r.startVecotr,a=r.activeVecotr;return a&&(t=g(A(a)/A(i)),e=g(A(a)/A(o))),{scale:e,deltaScale:t}}}function X(){var t,e,n=0,r=0,i=0,o=0;return function(a){if(void 0!==a){e=e||a.startInput;var u=a.timestamp-e.timestamp;if(16<u){var c=a.x-e.x,s=a.y-e.y;i=Math.round(c/u*100)/100,o=Math.round(s/u*100)/100,n=Math.abs(i),r=Math.abs(o),t=M(c,s)||t,e=a}}return{velocityX:n,velocityY:r,speedX:i,speedY:o,direction:t}}}function R(){var t=0;return function(e){return"start"===e.phase&&(t=e.pointLength),{maxPointLength:t}}}function F(t){return{x:t.points[1].clientX-t.points[0].clientX,y:t.points[1].clientY-t.points[0].clientY}}function Y(){var t,e,n;return function(r){var i=r.prevInput,o=r.startMultiInput;return void 0!==o&&void 0!==i&&r.id!==o.id&&1<i.pointLength&&1<r.pointLength&&(t=F(o),e=F(i),n=F(r)),{startVecotr:t,prevVecotr:e,activeVecotr:n}}}var V={name:"tap",pointLength:1,tapTimes:1,waitNextTapTime:300,maxDistance:2,maxDistanceFromPrevTap:9,maxPressTime:250};function j(t,e){var n,r,i,o=y(V,e),u=0;function c(){u=0,n=void 0,r=void 0}return t.compute([N,R],(function(e){if(!E(o)){var p,v,f,l,h=e.phase,m=e.x,d=e.y;if(s===h)o.state=a.POSSIBLE,p=e.startInput,v=e.pointLength,f=e.timestamp-p.timestamp,l=e.distance,e.maxPointLength===o.pointLength&&0===v&&o.maxDistance>=l&&o.maxPressTime>f?(clearTimeout(i),function(t,e){if(void 0!==n){var r=A({x:t.x-n.x,y:t.y-n.y});return n=t,e.maxDistanceFromPrevTap>=r}return n=t,!0}({x:m,y:d},o)&&function(t){var e=performance.now();if(void 0===r)return r=e,!0;var n=e-r;return r=e,n<t}(o.waitNextTapTime)?u++:u=1,0==u%o.tapTimes?(o.state=a.RECOGNIZED,t.emit2(o.name,e,o),c()):i=setTimeout((function(){o.state=a.FAILED,c()}),o.waitNextTapTime)):(c(),o.state=a.FAILED)}})),o}var B={name:"pan",threshold:10,pointLength:1};function G(t,e){var n=y(B,e);return t.compute([X,N,C],(function(e){if(m(n),!E(n)){var r,i,o,a,u,c=(r=e.pointLength,i=e.distance,o=e.direction,a=e.phase,(d(u=n.state)||n.threshold<=i)&&n.pointLength===r&&void 0!==o||d(u)&&s===a);if(n.state=h(c,n.state,e.phase),c){var p=n.name;t.emit2(p,e,n),t.emit2(p+l(n.state),e,n)}}})),n}var Z={name:"swipe",threshold:10,velocity:.3,pointLength:1};function q(t,e){var n=y(Z,e);return t.compute([N,X,R],(function(e){if(n.state=a.POSSIBLE,!n.disabled&&function(){if(s!==e.phase)return!1;var t=e.velocityX,r=e.velocityY,i=e.distance;return e.maxPointLength===n.pointLength&&0===e.points.length&&n.threshold<i&&n.velocity<Math.max(t,r)}()){var r=n.name;n.state=a.RECOGNIZED,t.emit2(r,e,n),t.emit2(r+e.direction,e,n)}})),n}var H={name:"press",pointLength:1,maxDistance:9,minPressTime:251};function U(t,e){var n=y(H,e),r=0;return t.compute([N],(function(e){if(!E(n)){var i,o=e.phase,u=e.startInput,p=e.pointLength;if("start"===o&&n.pointLength===p)m(n),clearTimeout(r),r=setTimeout((function(){n.state=a.RECOGNIZED,t.emit2(n.name,e,n)}),n.minPressTime);else if(s===o&&a.RECOGNIZED===n.state)t.emit2(n.name+"up",e,n);else if(a.RECOGNIZED!==n.state){var v=e.timestamp-u.timestamp;(!((i=e.distance)&&n.maxDistance>i)||n.minPressTime>v&&[s,c].includes(o))&&(clearTimeout(r),n.state=a.FAILED)}}})),n}var k={name:"pinch",threshold:0,pointLength:2};function $(t,e){var n=y(k,e);return t.compute([Y,P],(function(e){if(m(n),!E(n)){var r,i,o,a,u=(r=e.pointLength,i=e.scale,o=e.deltaScale,a=e.phase,n.pointLength===r&&(void 0!==i&&void 0!==o&&n.threshold<Math.abs(i-1)||d(n.state))||d(n.state)&&[s,c].includes(a));n.state=h(u,n.state,e.phase);var p=n.name;u&&t.emit2(p,e,n);var v=l(n.state);v&&t.emit2(p+v,e,n)}})),n}var z={name:"rotate",threshold:0,pointLength:2};function J(t,e){var n=y(z,e);return t.compute([Y,w],(function(e){if(!E(n)){m(n);var r,i,o,a=(r=e.pointLength,i=e.angle,o=e.phase,n.pointLength===r&&(n.threshold<Math.abs(i)||d(n.state))||d(n.state)&&[s,c].includes(o));n.state=h(a,n.state,e.phase);var u=n.name;a&&t.emit2(u,e,n);var p=l(n.state);p&&t.emit2(u+p,e,n)}})),n}return function(t){function n(e,n){var r=t.call(this,e,n)||this;return r.use(j),r.use(G),r.use(q),r.use(U),r.use($),r.use(J),r}return e(n,t),n.version="2.0.0-alpha.0",n.STATE_POSSIBLE=a.POSSIBLE,n.STATE_START=a.START,n.STATE_MOVE=a.MOVE,n.STATE_END=a.END,n.STATE_CANCELLED=a.CANCELLED,n.STATE_FAILED=a.FAILED,n.STATE_RECOGNIZED=a.RECOGNIZED,n.tap=j,n.pan=G,n.swipe=q,n.press=U,n.rotate=J,n.pinch=$,n}(D)})); |
@@ -1,1 +0,1 @@ | ||
import{__extends as o}from"tslib";import r from"@any-touch/core";import t from"@any-touch/tap";import E from"@any-touch/pan";import p from"@any-touch/swipe";import a from"@any-touch/press";import e from"@any-touch/pinch";import i from"@any-touch/rotate";import{STATE as n}from"@any-touch/shared";var u=function(r){function u(o,n){var u=r.call(this,o,n)||this;return u.use(t),u.use(E),u.use(p),u.use(a),u.use(e),u.use(i),u}return o(u,r),u.version="1.0.14",u.STATE_POSSIBLE=n.POSSIBLE,u.STATE_START=n.START,u.STATE_MOVE=n.MOVE,u.STATE_END=n.END,u.STATE_CANCELLED=n.CANCELLED,u.STATE_FAILED=n.FAILED,u.STATE_RECOGNIZED=n.RECOGNIZED,u.tap=t,u.pan=E,u.swipe=p,u.press=a,u.rotate=i,u.pinch=e,u}(r);export default u; | ||
import{__extends as o}from"tslib";import r from"@any-touch/core";import t from"@any-touch/tap";import E from"@any-touch/pan";import a from"@any-touch/swipe";import p from"@any-touch/press";import e from"@any-touch/pinch";import i from"@any-touch/rotate";import{STATE as n}from"@any-touch/shared";var u=function(r){function u(o,n){var u=r.call(this,o,n)||this;return u.use(t),u.use(E),u.use(a),u.use(p),u.use(e),u.use(i),u}return o(u,r),u.version="2.0.0-alpha.0",u.STATE_POSSIBLE=n.POSSIBLE,u.STATE_START=n.START,u.STATE_MOVE=n.MOVE,u.STATE_END=n.END,u.STATE_CANCELLED=n.CANCELLED,u.STATE_FAILED=n.FAILED,u.STATE_RECOGNIZED=n.RECOGNIZED,u.tap=t,u.pan=E,u.swipe=a,u.press=p,u.rotate=i,u.pinch=e,u}(r);export default u; |
@@ -1,1 +0,1 @@ | ||
"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var r=require("tslib"),t=e(require("@any-touch/core")),u=e(require("@any-touch/tap")),T=e(require("@any-touch/pan")),E=e(require("@any-touch/swipe")),n=e(require("@any-touch/press")),i=e(require("@any-touch/pinch")),s=e(require("@any-touch/rotate")),a=require("@any-touch/shared"),o=function(e){function t(r,t){var a=e.call(this,r,t)||this;return a.use(u),a.use(T),a.use(E),a.use(n),a.use(i),a.use(s),a}return r.__extends(t,e),t.version="1.0.14",t.STATE_POSSIBLE=a.STATE.POSSIBLE,t.STATE_START=a.STATE.START,t.STATE_MOVE=a.STATE.MOVE,t.STATE_END=a.STATE.END,t.STATE_CANCELLED=a.STATE.CANCELLED,t.STATE_FAILED=a.STATE.FAILED,t.STATE_RECOGNIZED=a.STATE.RECOGNIZED,t.tap=u,t.pan=T,t.swipe=E,t.press=n,t.rotate=s,t.pinch=i,t}(t);exports.default=o; | ||
"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var r=require("tslib"),t=e(require("@any-touch/core")),u=e(require("@any-touch/tap")),T=e(require("@any-touch/pan")),E=e(require("@any-touch/swipe")),n=e(require("@any-touch/press")),a=e(require("@any-touch/pinch")),i=e(require("@any-touch/rotate")),s=require("@any-touch/shared"),o=function(e){function t(r,t){var s=e.call(this,r,t)||this;return s.use(u),s.use(T),s.use(E),s.use(n),s.use(a),s.use(i),s}return r.__extends(t,e),t.version="2.0.0-alpha.0",t.STATE_POSSIBLE=s.STATE.POSSIBLE,t.STATE_START=s.STATE.START,t.STATE_MOVE=s.STATE.MOVE,t.STATE_END=s.STATE.END,t.STATE_CANCELLED=s.STATE.CANCELLED,t.STATE_FAILED=s.STATE.FAILED,t.STATE_RECOGNIZED=s.STATE.RECOGNIZED,t.tap=u,t.pan=T,t.swipe=E,t.press=n,t.rotate=i,t.pinch=a,t}(t);exports.default=o; |
{ | ||
"name": "any-touch", | ||
"version": "2.0.0-alpha.0", | ||
"version": "2.0.0-alpha.1", | ||
"description": "一个小巧的手势库", | ||
@@ -25,10 +25,10 @@ "unpkg": "dist/any-touch.umd.min.js", | ||
"dependencies": { | ||
"@any-touch/core": "^2.0.0-alpha.0", | ||
"@any-touch/pan": "^2.0.0-alpha.0", | ||
"@any-touch/pinch": "^2.0.0-alpha.0", | ||
"@any-touch/press": "^2.0.0-alpha.0", | ||
"@any-touch/rotate": "^2.0.0-alpha.0", | ||
"@any-touch/swipe": "^2.0.0-alpha.0", | ||
"@any-touch/tap": "^2.0.0-alpha.0", | ||
"any-event": "^2.0.0-alpha.0", | ||
"@any-touch/core": "^2.0.0-alpha.1", | ||
"@any-touch/pan": "^2.0.0-alpha.1", | ||
"@any-touch/pinch": "^2.0.0-alpha.1", | ||
"@any-touch/press": "^2.0.0-alpha.1", | ||
"@any-touch/rotate": "^2.0.0-alpha.1", | ||
"@any-touch/swipe": "^2.0.0-alpha.1", | ||
"@any-touch/tap": "^2.0.0-alpha.1", | ||
"any-event": "^2.0.0-alpha.1", | ||
"tslib": "^2.3.1" | ||
@@ -42,3 +42,3 @@ }, | ||
"sideEffects": false, | ||
"gitHead": "3fb899bb8ad845ab52fa4a932cc895637e173723" | ||
"gitHead": "a5497dd4d042aeb09ea9c6d0414ed36fbe9c7105" | ||
} |
@@ -13,2 +13,43 @@ # any-touch [![NPM Version][npm-image]][npm-url] [![NPM Downloads][downloads-image]][downloads-url] [![size-image]][size-url] [![codecov](https://codecov.io/gh/any86/any-touch/branch/master/graph/badge.svg)](https://codecov.io/gh/any86/any-touch) [![CircleCI](https://circleci.com/gh/any86/any-touch.svg?style=svg)](https://circleci.com/gh/any86/any-touch) | ||
[🔥 文档地址](https://github.com/any86/any-touch#any-touch-----) | ||
- 支持 PC 端 / 移动端 / 微信小程序. | ||
- 默认加载**6 个手势**, 也可按需加载手势, 核心**1kb**, 完整**4kb**. | ||
- **无依赖, 不限于 Vue / React / Angular等...** | ||
## 演示 | ||
<details> | ||
<summary>查看二维码</summary> | ||
<img src="https://user-images.githubusercontent.com/8264787/104836031-a55ca780-58e5-11eb-936a-7e2d1a05ee86.png" /> | ||
</details> | ||
[直接访问](https://any86.github.io/any-touch) | ||
## 安装 | ||
```javascript | ||
npm i -S any-touch | ||
``` | ||
## CDN | ||
```html | ||
<script src="https://unpkg.com/any-touch/dist/any-touch.umd.min.js"></script> | ||
<script> | ||
console.log(AnyTouch.version); // 2.x.x | ||
</script> | ||
``` | ||
## 快速开始 | ||
```javascript | ||
import AnyTouch from 'any-touch'; | ||
const el = document.getElementById('box'); | ||
const at = new AnyTouch(el); | ||
// e包含位移/速度/方向等信息 | ||
at.on('pan', (e) => console.log(e)); | ||
``` | ||
[🚀 更多文档](https://github.com/any86/any-touch#any-touch-----) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
63771
54
0