any-touch
Advanced tools
Comparing version 1.0.6 to 1.0.7
@@ -512,4 +512,6 @@ (function (global, factory) { | ||
var _this = this; | ||
var stopPropagation = function () { return event.stopPropagation(); }; | ||
var preventDefault = function () { return event.preventDefault(); }; | ||
if (canPreventDefault(event, this.options)) { | ||
event.preventDefault(); | ||
preventDefault(); | ||
} | ||
@@ -538,3 +540,3 @@ var input = this._$inputCreatorMap[event.type](event); | ||
recognizer.recognize(computed_1, function (type) { | ||
var payload = __assign(__assign({}, computed_1), { type: type, baseType: recognizer.name }); | ||
var payload = __assign(__assign({}, computed_1), { type: type, name: recognizer.name, stopPropagation: stopPropagation, preventDefault: preventDefault }); | ||
Object === null || Object === void 0 ? void 0 : Object.freeze(payload); | ||
@@ -585,3 +587,3 @@ if (void 0 === _this.beforeEachHook) { | ||
}; | ||
AnyTouch.version = '1.0.5'; | ||
AnyTouch.version = '1.0.6'; | ||
AnyTouch._$recognizers = []; | ||
@@ -600,4 +602,4 @@ AnyTouch._$recognizerMap = {}; | ||
function resetStatus (recognizer) { | ||
if (-1 !== [STATUS_END, STATUS_CANCELLED, STATUS_RECOGNIZED, STATUS_FAILED].indexOf(recognizer._$status)) { | ||
recognizer._$status = STATUS_POSSIBLE; | ||
if (-1 !== [STATUS_END, STATUS_CANCELLED, STATUS_RECOGNIZED, STATUS_FAILED].indexOf(recognizer.status)) { | ||
recognizer.status = STATUS_POSSIBLE; | ||
} | ||
@@ -647,9 +649,9 @@ } | ||
var stage = computed.stage; | ||
recognizer._$status = flow(isVaild, recognizer._$status, stage); | ||
recognizer._$isRecognized = [STATUS_START, STATUS_MOVE].includes(recognizer._$status); | ||
var name = recognizer.name, status = recognizer._$status, isRecognized = recognizer._$isRecognized; | ||
recognizer.status = flow(isVaild, recognizer.status, stage); | ||
recognizer._$isRecognized = [STATUS_START, STATUS_MOVE].includes(recognizer.status); | ||
var name = recognizer.name, status = recognizer.status, isRecognized = recognizer._$isRecognized; | ||
if (isRecognized) { | ||
emit(name); | ||
} | ||
if (isRecognized || [STATUS_END, STATUS_CANCELLED].includes(recognizer._$status)) { | ||
if (isRecognized || [STATUS_END, STATUS_CANCELLED].includes(recognizer.status)) { | ||
emit(name + status); | ||
@@ -664,3 +666,3 @@ } | ||
this._$isRecognized = false; | ||
this._$status = STATUS_POSSIBLE; | ||
this.status = STATUS_POSSIBLE; | ||
this.computeFunctions = []; | ||
@@ -904,3 +906,3 @@ this.options = options; | ||
return; | ||
this._$status = STATUS_POSSIBLE; | ||
this.status = STATUS_POSSIBLE; | ||
if (this._$test(computed)) { | ||
@@ -915,3 +917,3 @@ clearTimeout(this._$countDownToFailTimer); | ||
if (0 === this._$tapCount % this.options.tapTimes) { | ||
this._$status = STATUS_RECOGNIZED; | ||
this.status = STATUS_RECOGNIZED; | ||
emit(this.options.name, __assign(__assign({}, computed), { tapCount: this._$tapCount })); | ||
@@ -926,3 +928,3 @@ this._$reset(); | ||
this._$reset(); | ||
this._$status = STATUS_FAILED; | ||
this.status = STATUS_FAILED; | ||
} | ||
@@ -933,3 +935,3 @@ }; | ||
this._$countDownToFailTimer = setTimeout(function () { | ||
_this._$status = STATUS_FAILED; | ||
_this.status = STATUS_FAILED; | ||
_this._$reset(); | ||
@@ -1031,10 +1033,10 @@ }, this.options.waitNextTapTime); | ||
this._timeoutId = setTimeout(function () { | ||
_this._$status = STATUS_RECOGNIZED; | ||
_this.status = STATUS_RECOGNIZED; | ||
emit(_this.options.name); | ||
}, this.options.minPressTime); | ||
} | ||
else if (INPUT_END === stage && STATUS_RECOGNIZED === this._$status) { | ||
else if (INPUT_END === stage && STATUS_RECOGNIZED === this.status) { | ||
emit("" + this.options.name + DIRECTION_UP); | ||
} | ||
else if (STATUS_RECOGNIZED !== this._$status) { | ||
else if (STATUS_RECOGNIZED !== this.status) { | ||
var deltaTime = computed.timestamp - startInput.timestamp; | ||
@@ -1044,3 +1046,3 @@ if (!this._$test(computed) || | ||
this._$cancel(); | ||
this._$status = STATUS_FAILED; | ||
this.status = STATUS_FAILED; | ||
} | ||
@@ -1047,0 +1049,0 @@ } |
@@ -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;T(t,this.options)&&t.preventDefault();var a=this._$inputCreatorMap[t.type](t);if(void 0!==a){var s="at:"+a.stage;this.emit("at",a),this.emit(s,a);var u=this.options.domEvents;if(!1!==u){var c=t.target;null!==c&&($(c,n(n({},a),{type:"at"}),u),$(c,n(n({},a),{type:s}),u))}var p=a;for(var h in this._$computeFunctionMap)Object.assign(p,this._$computeFunctionMap[h](p));var v=function(t){if(t.disabled)return"continue";t.recognize(p,(function(e){var i=n(n({},p),{type:e,baseType:t.name});null==Object||Object.freeze(i),void 0===o.beforeEachHook?E(o,i):o.beforeEachHook(t,o._$recognizerMap,(function(){E(o,i)}))}))};try{for(var l=i(this._$recognizers),f=l.next();!f.done;f=l.next()){v(f.value)}}catch(t){e={error:t}}finally{try{f&&!f.done&&(r=l.return)&&r.call(l)}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.5",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 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})); |
{ | ||
"name": "any-touch", | ||
"version": "1.0.6", | ||
"version": "1.0.7", | ||
"description": "一个小巧的手势库", | ||
@@ -25,10 +25,10 @@ "unpkg": "dist/any-touch.umd.min.js", | ||
"dependencies": { | ||
"@any-touch/core": "^1.0.6", | ||
"@any-touch/pan": "^1.0.6", | ||
"@any-touch/pinch": "^1.0.6", | ||
"@any-touch/press": "^1.0.6", | ||
"@any-touch/rotate": "^1.0.6", | ||
"@any-touch/swipe": "^1.0.6", | ||
"@any-touch/tap": "^1.0.6", | ||
"any-event": "^1.0.6", | ||
"@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", | ||
"tslib": "^1.9.3" | ||
@@ -42,3 +42,3 @@ }, | ||
"sideEffects": false, | ||
"gitHead": "ce583217caf3a34eb5aa0267b855a92a9ca9c043" | ||
"gitHead": "fa8e0eb63d3f306ad6f381ec6bac173c70559e5b" | ||
} |
@@ -19,3 +19,3 @@ # 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) | ||
<summary>查看二维码</summary> | ||
<img src="https://p1-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/b84d3a068b7f4ee0a41f94237997bfb7~tplv-k3u1fbpfcp-zoom-1.image" /> | ||
<img src="https://user-images.githubusercontent.com/8264787/104836031-a55ca780-58e5-11eb-936a-7e2d1a05ee86.png" /> | ||
</details> | ||
@@ -35,2 +35,4 @@ | ||
[:wave: 还支持哪些手势?](#还支持哪些手势) | ||
[:bulb: API & 高级技巧](docs/API.md) | ||
@@ -54,2 +56,3 @@ | ||
## 快速开始 | ||
**HTML中引入** | ||
```html | ||
@@ -59,3 +62,3 @@ <h1 id="box">hello world</h1> | ||
<script> | ||
const el = doucument.getElementById('box'); | ||
const el = document.getElementById('box'); | ||
const at = new AnyTouch(el); | ||
@@ -65,6 +68,6 @@ at.on('tap', e => console.log('e包含位置等信息',e)); | ||
``` | ||
**或者:** | ||
**或者, 使用NPM** | ||
```javascript | ||
import AnyTouch from 'any-touch'; | ||
const el = doucument.getElementById('box'); | ||
const el = document.getElementById('box'); | ||
const at = new AnyTouch(el); | ||
@@ -75,2 +78,3 @@ at.on('pan', e => console.log('e包含位移/速度/方向等信息',e)) | ||
## 兼容vue语法 | ||
@@ -96,3 +100,3 @@ | ||
const at= new AnyTouch(this.$el); | ||
this.on('hook:destroyed', ()=>{at.destroy()}); | ||
this.$on('hook:destroyed', ()=>{at.destroy()}); | ||
} | ||
@@ -142,3 +146,3 @@ }; | ||
## 按需加载 | ||
**默认any-touch支持所有手势**, 为了"**减小体积**"和"**提升效率**", 提供了按需加载. | ||
**默认any-touch支持所有手势**, 为了**更小的体积**, 提供了按需加载. | ||
@@ -180,2 +184,23 @@ ```javascript | ||
## 还支持哪些手势? | ||
除了上面说的6大类手势外, 还细分了更多手势: | ||
|手势名|说明| | ||
|---|---| | ||
|pressup|按压松开| | ||
|panstart|拖拽开始| | ||
|panmove|拖拽中| | ||
|panend|拖拽结束| | ||
|pinchstart|缩放开始| | ||
|pinchmove|缩放中| | ||
|pinchend|缩放结束| | ||
|rotatestart|旋转开始| | ||
|rotatemove|旋转中| | ||
|rotateend|旋转结束| | ||
```javascript | ||
at.on('panstart', e=>{ | ||
console.log('拖拽开始了!'); | ||
}); | ||
``` | ||
[:rocket: 返回目录](#目录) | ||
@@ -203,2 +228,9 @@ | ||
### 移动端尽量使用tap代理click | ||
在移动端touchstart比click先触发, 所以touchstart阶段的preventDefault会阻止click触发, 恰恰any-touch默认在touchstart中使用了`preventDefault`, 用来阻止了浏览器默认事件的触发,比如click和页面滚动. | ||
如果移动端非要使用click做如下设置 | ||
```javascript | ||
const at = new AnyTouch(el, { preventDefault: false }); | ||
``` | ||
[:rocket: 返回目录](#目录) |
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
74473
1166
227
Updated@any-touch/core@^1.0.7
Updated@any-touch/pan@^1.0.7
Updated@any-touch/pinch@^1.0.7
Updated@any-touch/press@^1.0.7
Updated@any-touch/rotate@^1.0.7
Updated@any-touch/swipe@^1.0.7
Updated@any-touch/tap@^1.0.7
Updatedany-event@^1.0.7