any-touch
Advanced tools
Comparing version 0.6.2-beta.2 to 0.6.3-beta.0
@@ -475,124 +475,115 @@ (function (global, factory) { | ||
}; | ||
var createAnyTouch = function (Recognizers) { | ||
var AnyTouch = (function (_super) { | ||
__extends(AnyTouch, _super); | ||
function AnyTouch(el, options) { | ||
var _this = _super.call(this) || this; | ||
_this.recognizerMap = {}; | ||
_this.recognizers = []; | ||
_this.el = el; | ||
_this.input = new default_1$3(); | ||
_this.options = __assign(__assign({}, DEFAULT_OPTIONS), options); | ||
_this.recognizerMap = AnyTouch.recognizerMap; | ||
_this.recognizers = AnyTouch.recognizers; | ||
if (void 0 !== el) { | ||
el.style.webkitTapHighlightColor = 'rgba(0,0,0,0)'; | ||
var supportsPassive_1 = false; | ||
try { | ||
var opts = {}; | ||
Object.defineProperty(opts, 'passive', ({ | ||
get: function get() { | ||
supportsPassive_1 = true; | ||
} | ||
})); | ||
window.addEventListener('_', function () { return void 0; }, opts); | ||
} | ||
catch (_a) { } | ||
var unbindEl = bindElement(el, _this.catchEvent.bind(_this), !_this.options.isPreventDefault && supportsPassive_1 ? { passive: true } : false); | ||
_this.on('unbindEl', unbindEl); | ||
var AnyTouch = (function (_super) { | ||
__extends(AnyTouch, _super); | ||
function AnyTouch(el, options) { | ||
var _this = _super.call(this) || this; | ||
_this.recognizerMap = {}; | ||
_this.recognizers = []; | ||
_this.el = el; | ||
_this.input = new default_1$3(); | ||
_this.options = __assign(__assign({}, DEFAULT_OPTIONS), options); | ||
_this.recognizerMap = AnyTouch.recognizerMap; | ||
_this.recognizers = AnyTouch.recognizers; | ||
if (void 0 !== el) { | ||
el.style.webkitTapHighlightColor = 'rgba(0,0,0,0)'; | ||
var supportsPassive_1 = false; | ||
try { | ||
var opts = {}; | ||
Object.defineProperty(opts, 'passive', ({ | ||
get: function get() { | ||
supportsPassive_1 = true; | ||
} | ||
})); | ||
window.addEventListener('_', function () { return void 0; }, opts); | ||
} | ||
return _this; | ||
catch (_a) { } | ||
var unbindEl = bindElement(el, _this.catchEvent.bind(_this), !_this.options.isPreventDefault && supportsPassive_1 ? { passive: true } : false); | ||
_this.on('unbindEl', unbindEl); | ||
} | ||
AnyTouch.prototype.use = function (Recognizer, options) { | ||
use(this, Recognizer, options); | ||
}; | ||
AnyTouch.prototype.removeUse = function (name) { | ||
removeUse(this, name); | ||
}; | ||
AnyTouch.prototype.catchEvent = function (event) { | ||
var e_1, _a; | ||
var _this = this; | ||
if (canPreventDefault(event, this.options)) { | ||
event.preventDefault(); | ||
return _this; | ||
} | ||
AnyTouch.prototype.use = function (Recognizer, options) { | ||
use(this, Recognizer, options); | ||
}; | ||
AnyTouch.prototype.removeUse = function (name) { | ||
removeUse(this, name); | ||
}; | ||
AnyTouch.prototype.catchEvent = function (event) { | ||
var e_1, _a; | ||
var _this = this; | ||
if (canPreventDefault(event, this.options)) { | ||
event.preventDefault(); | ||
} | ||
var input = this.input.transform(event); | ||
if (void 0 !== input) { | ||
var AT_TOUCH = "at:" + TOUCH; | ||
var AT_TOUCH_WITH_STATUS = AT_TOUCH + input.inputType; | ||
this.emit(AT_TOUCH, input); | ||
this.emit(AT_TOUCH_WITH_STATUS, input); | ||
if (false !== this.options.domEvents) { | ||
var target = event.target; | ||
if (null !== target) { | ||
dispatchDomEvent(target, __assign(__assign({}, input), { type: AT_TOUCH }), this.options.domEvents); | ||
dispatchDomEvent(target, __assign(__assign({}, input), { type: AT_TOUCH_WITH_STATUS }), this.options.domEvents); | ||
} | ||
} | ||
var input = this.input.transform(event); | ||
if (void 0 !== input) { | ||
var AT_TOUCH = "at:" + TOUCH; | ||
var AT_TOUCH_WITH_STATUS = AT_TOUCH + input.inputType; | ||
this.emit(AT_TOUCH, input); | ||
this.emit(AT_TOUCH_WITH_STATUS, input); | ||
if (false !== this.options.domEvents) { | ||
var target = event.target; | ||
if (null !== target) { | ||
dispatchDomEvent(target, __assign(__assign({}, input), { type: AT_TOUCH }), this.options.domEvents); | ||
dispatchDomEvent(target, __assign(__assign({}, input), { type: AT_TOUCH_WITH_STATUS }), this.options.domEvents); | ||
var computedGroup = {}; | ||
var _loop_1 = function (recognizer) { | ||
if (recognizer.disabled) | ||
return "continue"; | ||
recognizer.input = input; | ||
recognizer.computedGroup = computedGroup; | ||
recognizer.recognize(input, function (type, ev) { | ||
var payload = __assign(__assign(__assign({}, input), ev), { type: type, baseType: recognizer.name }); | ||
Object.freeze(payload); | ||
if (void 0 === _this.beforeEachHook) { | ||
emit2(_this, payload); | ||
} | ||
} | ||
var computedGroup = {}; | ||
var _loop_1 = function (recognizer) { | ||
if (recognizer.disabled) | ||
return "continue"; | ||
recognizer.input = input; | ||
recognizer.computedGroup = computedGroup; | ||
recognizer.recognize(input, function (type, ev) { | ||
var payload = __assign(__assign(__assign({}, input), ev), { type: type, baseType: recognizer.name }); | ||
Object.freeze(payload); | ||
if (void 0 === _this.beforeEachHook) { | ||
else { | ||
_this.beforeEachHook(recognizer, function () { | ||
emit2(_this, payload); | ||
} | ||
else { | ||
_this.beforeEachHook(recognizer, function () { | ||
emit2(_this, payload); | ||
}); | ||
} | ||
}); | ||
computedGroup = recognizer.computedGroup; | ||
}; | ||
try { | ||
for (var _b = __values(this.recognizers), _c = _b.next(); !_c.done; _c = _b.next()) { | ||
var recognizer = _c.value; | ||
_loop_1(recognizer); | ||
}); | ||
} | ||
}); | ||
computedGroup = recognizer.computedGroup; | ||
}; | ||
try { | ||
for (var _b = __values(this.recognizers), _c = _b.next(); !_c.done; _c = _b.next()) { | ||
var recognizer = _c.value; | ||
_loop_1(recognizer); | ||
} | ||
catch (e_1_1) { e_1 = { error: e_1_1 }; } | ||
finally { | ||
try { | ||
if (_c && !_c.done && (_a = _b.return)) _a.call(_b); | ||
} | ||
finally { if (e_1) throw e_1.error; } | ||
} | ||
catch (e_1_1) { e_1 = { error: e_1_1 }; } | ||
finally { | ||
try { | ||
if (_c && !_c.done && (_a = _b.return)) _a.call(_b); | ||
} | ||
finally { if (e_1) throw e_1.error; } | ||
} | ||
}; | ||
AnyTouch.prototype.beforeEach = function (hook) { | ||
this.beforeEachHook = hook; | ||
}; | ||
AnyTouch.prototype.get = function (name) { | ||
return this.recognizerMap[name]; | ||
}; | ||
AnyTouch.prototype.set = function (options) { | ||
this.options = __assign(__assign({}, this.options), options); | ||
}; | ||
AnyTouch.prototype.destroy = function () { | ||
this.emit('unbindEl'); | ||
this.callbackMap = {}; | ||
}; | ||
AnyTouch.version = '0.6.2-beta.1'; | ||
AnyTouch.recognizers = []; | ||
AnyTouch.recognizerMap = {}; | ||
AnyTouch.use = function (Recognizer, options) { | ||
use(AnyTouch, Recognizer, options); | ||
}; | ||
AnyTouch.removeUse = function (recognizerName) { | ||
removeUse(AnyTouch, recognizerName); | ||
}; | ||
return AnyTouch; | ||
}(AnyEvent)); | ||
if (void 0 !== Recognizers) { | ||
Recognizers.forEach(function (Recognizer) { | ||
AnyTouch.use(Recognizer); | ||
}); | ||
} | ||
} | ||
}; | ||
AnyTouch.prototype.beforeEach = function (hook) { | ||
this.beforeEachHook = hook; | ||
}; | ||
AnyTouch.prototype.get = function (name) { | ||
return this.recognizerMap[name]; | ||
}; | ||
AnyTouch.prototype.set = function (options) { | ||
this.options = __assign(__assign({}, this.options), options); | ||
}; | ||
AnyTouch.prototype.destroy = function () { | ||
this.emit('unbindEl'); | ||
this.callbackMap = {}; | ||
}; | ||
AnyTouch.version = '0.6.2-beta.4'; | ||
AnyTouch.recognizers = []; | ||
AnyTouch.recognizerMap = {}; | ||
AnyTouch.use = function (Recognizer, options) { | ||
use(AnyTouch, Recognizer, options); | ||
}; | ||
AnyTouch.removeUse = function (recognizerName) { | ||
removeUse(AnyTouch, recognizerName); | ||
}; | ||
return AnyTouch; | ||
}; | ||
createAnyTouch(); | ||
}(AnyEvent)); | ||
function emit2(at, payload) { | ||
@@ -1162,3 +1153,8 @@ var type = payload.type, target = payload.target; | ||
var AnyTouch = createAnyTouch([default_1$a, default_1$b, default_1$c, default_1$d, default_1$e, default_1$f]); | ||
AnyTouch.use(default_1$a); | ||
AnyTouch.use(default_1$b); | ||
AnyTouch.use(default_1$c); | ||
AnyTouch.use(default_1$d); | ||
AnyTouch.use(default_1$e); | ||
AnyTouch.use(default_1$f); | ||
AnyTouch.Tap = default_1$a; | ||
@@ -1165,0 +1161,0 @@ AnyTouch.Pan = default_1$b; |
@@ -1,1 +0,1 @@ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t=t||self).AnyTouch=e()}(this,(function(){"use strict";var t=function(e,n){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(e,n)};function e(e,n){function i(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(i.prototype=n.prototype,new i)}var n=function(){return(n=Object.assign||function(t){for(var e,n=1,i=arguments.length;n<i;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t}).apply(this,arguments)};function i(t){var e="function"==typeof Symbol&&t[Symbol.iterator],n=0;return e?e.call(t):{next:function(){return t&&n>=t.length&&(t=void 0),{value:t&&t[n++],done:!t}}}}function o(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var i,o,r=n.call(t),s=[];try{for(;(void 0===e||e-- >0)&&!(i=r.next()).done;)s.push(i.value)}catch(t){o={error:t}}finally{try{i&&!i.done&&(n=r.return)&&n.call(r)}finally{if(o)throw o.error}}return s}function r(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(o(arguments[e]));return t}var s=function(){function t(){this.callbackMap={}}return t.prototype.target=function(t){var e=this;return{on:function(n,i){e.on(n,i,{target:t})}}},t.prototype.on=function(t,e,n){var i=(void 0===n?{}:n).target;void 0===this.callbackMap[t]&&(this.callbackMap[t]=[]),void 0!==i&&(e.target=i),this.callbackMap[t].push(e)},t.prototype.off=function(t,e){var n=this.callbackMap[t];if(void 0!==n)if(void 0===e)delete this.callbackMap[t];else{var i=n.findIndex((function(t){return t===e}));n.splice(i,1)}},t.prototype.emit=function(t,e){var n,o,r=this.callbackMap[t],s=(e||{}).targets;if(void 0!==r&&0<r.length){var a=function(t){var n=t.target;void 0!==n&&void 0!==s&&s.every((function(t){return n.contains(t)}))?t(e):void 0===n&&t(e)};try{for(var c=i(r),u=c.next();!u.done;u=c.next()){a(u.value)}}catch(t){n={error:t}}finally{try{u&&!u.done&&(o=c.return)&&o.call(c)}finally{if(n)throw n.error}}return!0}return!1},t.prototype.destroy=function(){this.callbackMap={}},t}(),a=Object.prototype.toString;var c="cancel",u="end",p="touch"+u,h="touch"+c,l="ontouchstart"in window,d="start",v="move",f=u,m="r",y="f",g=c;function T(t){return Math.round(100*t)/100}var b=function(){},M=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return e(n,t),n.prototype.load=function(t){var e=[],n=Array.from(t.touches).map((function(t){var n=t.clientX,i=t.clientY,o=t.target;return e.push(o),{clientX:n,clientY:i,target:o}})),i=Array.from(t.changedTouches).map((function(t){return{clientX:t.clientX,clientY:t.clientY,target:t.target}}));return{inputType:t.type.replace("touch",""),changedPoints:i,points:n,nativeEvent:t,target:t.target,targets:e}},n}(b),x=function(t){function n(){var e=t.call(this)||this;return e.target=null,e.isPressed=!1,e}return e(n,t),n.prototype.load=function(t){var e,n=t.clientX,i=t.clientY,o=t.type,r=t.button,s=t.target,a=[{clientX:n,clientY:i,target:s}];"mousedown"===o&&0===r?(this.target=s,this.isPressed=!0,e="start"):this.isPressed&&("mousemove"===o?e="move":"mouseup"===o&&(a=[],e=u,this.isPressed=!1));var c=this.prevPoints||[{clientX:n,clientY:i,target:s}];if(this.prevPoints=[{clientX:n,clientY:i,target:s}],void 0!==e)return{inputType:e,changedPoints:c,points:a,target:this.target,targets:[this.target],nativeEvent:t}},n}(b),E=function(){function t(){var t=l?M:x;this.adapter=new t,this.id=0}return t.prototype.transform=function(t){this.prevInput=this.activeInput;var e=this.adapter.load(t);if(void 0!==e){if(function(t){var e=!1,n=t.nativeEvent.currentTarget;window!==n&&document!==n&&null!==n&&t.points.forEach((function(t){var i=t.target;n.contains(i)||(e=!0)}));return e}(e))return;var i=Number.MAX_SAFE_INTEGER>this.id?++this.id:1,o=function(t){var e=t.inputType,i=t.points,o=t.changedPoints,r=t.nativeEvent,s=i.length,a="start"===e,p=u===e&&0===s||c===e,h=performance.now(),l=P(i)||P(o),d=l.x,v=l.y,f=r.currentTarget;return n(n({},t),{x:d,y:v,timestamp:h,isStart:a,isEnd:p,pointLength:s,currentTarget:f,getOffset:function(t){void 0===t&&(t=f);var e=t.getBoundingClientRect();return{x:d-Math.round(e.left),y:v-Math.round(e.top)}}})}(n(n({},e),{id:i}));this.activeInput=o;var r=o.isStart,s=o.pointLength;return r&&(this.startInput=o,this.prevInput=void 0,this.startMultiInput=1<s?o:void 0),n(n({},o),{prevInput:this.prevInput,startMultiInput:this.startMultiInput,startInput:this.startInput})}},t}();function P(t){var e=t.length;if(0<e){if(1===e){var n=t[0],i=n.clientX,o=n.clientY;return{x:Math.round(i),y:Math.round(o)}}var r=t.reduce((function(t,e){return t.x+=e.clientX,t.y+=e.clientY,t}),{x:0,y:0});return{x:Math.round(r.x/e),y:Math.round(r.y/e)}}}function w(t,e,n){e.target,e.currentTarget;var i,o,r,s=e.type,a=function(t,e){var n={};for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&e.indexOf(i)<0&&(n[i]=t[i]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(i=Object.getOwnPropertySymbols(t);o<i.length;o++)e.indexOf(i[o])<0&&Object.prototype.propertyIsEnumerable.call(t,i[o])&&(n[i[o]]=t[i[o]])}return n}(e,["target","currentTarget","type"]);return void 0!==Event?r=new Event(s,n):(r=document.createEvent("HTMLEvents")).initEvent(s,null===(i=n)||void 0===i?void 0:i.bubbles,null===(o=n)||void 0===o?void 0:o.cancelable),Object.assign(r,a,{match:function(){return e.targets.every((function(t){return r.currentTarget.contains(t)}))}}),t.dispatchEvent(r)}function L(t,e){if(!e.isPreventDefault)return!1;var n,i=!0;if(null!==t.target){var o=e.preventDefaultExclude;if(n=o,"[object RegExp]"===a.call(n)){if("tagName"in t.target){var r=t.target.tagName;i=!o.test(r)}}else(function(t){return"[object Function]"===a.call(t)})(o)&&(i=!o(t))}return i}var X=["touchstart","touchmove",p,h];function Y(t,e,n){var i,o=null===(i=n)||void 0===i?void 0:i.name;if(void 0===o||void 0===t.recognizerMap[o]){var r=new e(n);t.recognizerMap[r.name]=r,r.recognizerMap=t.recognizerMap,t.recognizers.push(t.recognizerMap[r.name])}}function _(t,e){var n,r;if(void 0===e)t.recognizers=[],t.recognizerMap={};else try{for(var s=i(t.recognizers.entries()),a=s.next();!a.done;a=s.next()){var c=o(a.value,2),u=c[0];if(e===c[1].options.name){t.recognizers.splice(u,1),delete t.recognizerMap[e];break}}}catch(t){n={error:t}}finally{try{a&&!a.done&&(r=s.return)&&r.call(s)}finally{if(n)throw n.error}}}var I={domEvents:{bubbles:!0,cancelable:!0},isPreventDefault:!0,preventDefaultExclude:/^(?:INPUT|TEXTAREA|BUTTON|SELECT)$/},z=function(t){var o=function(t){function o(e,i){var r=t.call(this)||this;if(r.recognizerMap={},r.recognizers=[],r.el=e,r.input=new E,r.options=n(n({},I),i),r.recognizerMap=o.recognizerMap,r.recognizers=o.recognizers,void 0!==e){e.style.webkitTapHighlightColor="rgba(0,0,0,0)";var s=!1;try{var a={};Object.defineProperty(a,"passive",{get:function(){s=!0}}),window.addEventListener("_",(function(){}),a)}catch(t){}var c=function(t,e,n){return l?(X.forEach((function(i){t.addEventListener(i,e,n)})),function(){X.forEach((function(n){t.removeEventListener(n,e)}))}):(t.addEventListener("mousedown",e,n),window.addEventListener("mousemove",e,n),window.addEventListener("mouseup",e,n),function(){t.removeEventListener("mousedown",e),window.removeEventListener("mousemove",e),window.removeEventListener("mouseup",e)})}(e,r.catchEvent.bind(r),!(r.options.isPreventDefault||!s)&&{passive:!0});r.on("unbindEl",c)}return r}return e(o,t),o.prototype.use=function(t,e){Y(this,t,e)},o.prototype.removeUse=function(t){_(this,t)},o.prototype.catchEvent=function(t){var e,o,r=this;L(t,this.options)&&t.preventDefault();var s=this.input.transform(t);if(void 0!==s){var a="at:touch"+s.inputType;if(this.emit("at:touch",s),this.emit(a,s),!1!==this.options.domEvents){var c=t.target;null!==c&&(w(c,n(n({},s),{type:"at:touch"}),this.options.domEvents),w(c,n(n({},s),{type:a}),this.options.domEvents))}var u={},p=function(t){if(t.disabled)return"continue";t.input=s,t.computedGroup=u,t.recognize(s,(function(e,i){var o=n(n(n({},s),i),{type:e,baseType:t.name});Object.freeze(o),void 0===r.beforeEachHook?D(r,o):r.beforeEachHook(t,(function(){D(r,o)}))})),u=t.computedGroup};try{for(var h=i(this.recognizers),l=h.next();!l.done;l=h.next()){p(l.value)}}catch(t){e={error:t}}finally{try{l&&!l.done&&(o=h.return)&&o.call(h)}finally{if(e)throw e.error}}}},o.prototype.beforeEach=function(t){this.beforeEachHook=t},o.prototype.get=function(t){return this.recognizerMap[t]},o.prototype.set=function(t){this.options=n(n({},this.options),t)},o.prototype.destroy=function(){this.emit("unbindEl"),this.callbackMap={}},o.version="0.6.2-beta.1",o.recognizers=[],o.recognizerMap={},o.use=function(t,e){Y(o,t,e)},o.removeUse=function(t){_(o,t)},o}(s);return void 0!==t&&t.forEach((function(t){o.use(t)})),o};function D(t,e){var i=e.type,o=e.target;t.emit("at:after",e),t.emit(i,e),!1!==t.options.domEvents&&void 0!==t.el&&null!=o&&(w(o,e,t.options.domEvents),w(o,n(n({},e),{type:"at:after"}),t.options.domEvents))}function S(t){-1!==[f,g,m,y].indexOf(t.status)&&(t.status="p")}function V(t,e,n){var i=t.test(e);S(t);var o=e.inputType;t.status=function(t,e,n){var i,o,r,s,a,p,h,l={1:(i={},i.p=(o={},o.move=d,o),i[d]=(r={},r.move=v,r[u]=f,r[c]=g,r),i[v]=(s={},s.move=v,s[u]=f,s[c]=g,s),i),0:(a={},a[d]=(p={},p.move=g,p[u]=f,p[c]=g,p),a[v]=(h={},h.start=y,h.move=g,h[u]=f,h[c]=g,h),a)};return void 0!==l[Number(t)][e]&&l[Number(t)][e][n]||e}(i,t.status,o);var r=t.computed;t.isRecognized=[d,v].includes(t.status);var s=t.name,a=t.status,p=t.isRecognized;return p&&n(s,r),(p||[f,g].includes(t.status))&&n(s+a,r),i}z();var O=function(){function t(t){this.options=t,this.name=this.options.name,this.disabled=!1,this.status="p",this.isRecognized=!1,this.computed={},this.computedGroup={},this.usedComputeFunctionMap={},this.recognizerMap={}}return t.prototype.set=function(t){return void 0!==t&&(this.options=n(n({},this.options),t)),this},t.prototype.isValidPointLength=function(t){return 0===this.options.pointLength||this.options.pointLength===t},t.prototype.compute=function(t){for(var e,o,s,a=[],c=1;c<arguments.length;c++)a[c-1]=arguments[c];var u=Object.create(null);try{for(var p=i(t),h=p.next();!h.done;h=p.next()){var l=h.value,d=l._id,v=this,f=v.computedGroup,m=v.usedComputeFunctionMap;void 0===m[d]&&(m[d]=new l),f[d]=f[d]||(s=m[d]).compute.apply(s,r(a)),u=n(n({},u),f[d])}}catch(t){e={error:t}}finally{try{h&&!h.done&&(o=p.return)&&o.call(p)}finally{if(e)throw e.error}}return this.computed=u,u},t}(),C=function(t){return Math.sqrt(t.x*t.x+t.y*t.y)},A=function(t){return t/Math.PI*180},j=function(t,e){var n=function(t,e){var n=C(t)*C(e);if(0===n)return 0;var i=function(t,e){return t.x*e.x+t.y*e.y}(t,e)/n;return i>1&&(i=1),Math.acos(i)}(t,e);return function(t,e){return t.x*e.y-e.x*t.y}(t,e)>0&&(n*=-1),A(n)},F=function(t,e){return t===e?"none":Math.abs(t)>Math.abs(e)?0<t?"right":"left":0<e?"down":"up"};var k=function(){function t(){}return t.prototype.compute=function(t){var e=t.prevInput,n=0,i=0,o=0;if(void 0!==e&&(n=t.x-e.x,i=t.y-e.y,0!==n||0!==i)){var r=Math.sqrt(Math.pow(n,2)+Math.pow(i,2));o=Math.round(A(Math.acos(Math.abs(n)/r)))}return{deltaX:n,deltaY:i,deltaXYAngle:o}},t._id="ComputeDeltaXY",t}(),N=function(){function t(){this.displacementX=0,this.displacementY=0,this.distanceX=0,this.distanceY=0,this.distance=0,this.overallDirection="none"}return t.prototype.compute=function(t){var e=t.inputType,n=t.startInput;"start"===e?(this.displacementX=0,this.displacementY=0,this.distanceX=0,this.distanceY=0,this.distance=0,this.overallDirection="none"):"move"===e&&(this.displacementX=Math.round(t.points[0].clientX-n.points[0].clientX),this.displacementY=Math.round(t.points[0].clientY-n.points[0].clientY),this.distanceX=Math.abs(this.displacementX),this.distanceY=Math.abs(this.displacementY),this.distance=Math.round(C({x:this.distanceX,y:this.distanceY})),this.overallDirection=F(this.displacementX,this.displacementY));var i=this;return{displacementX:i.displacementX,displacementY:i.displacementY,distanceX:i.distanceX,distanceY:i.distanceY,distance:i.distance,overallDirection:i.overallDirection}},t._id="ComputeDistance",t}(),R=function(){function t(){this.maxPointLength=0}return t.prototype.compute=function(t){return"start"===t.inputType&&(this.maxPointLength=t.pointLength),{maxPointLength:this.maxPointLength}},t._id="ComputeMaxLength",t}();var U=function(){function t(){this.velocityX=0,this.velocityY=0,this.speedX=0,this.speedY=0}return t.prototype.compute=function(t){if(void 0!==t){var e=t.inputType;this._lastValidInput=this._lastValidInput||t.startInput;var n=t.timestamp-this._lastValidInput.timestamp;if("move"===e&&16<n){var i=t.x-this._lastValidInput.x,o=t.y-this._lastValidInput.y;this.speedX=Math.round(i/n*100)/100,this.speedY=Math.round(o/n*100)/100,this.velocityX=Math.abs(this.speedX),this.velocityY=Math.abs(this.speedY),this.direction=F(i,o)||this.direction,this._lastValidInput=t}}var r=this;return{velocityX:r.velocityX,velocityY:r.velocityY,speedX:r.speedX,speedY:r.speedY,direction:r.direction}},t._id="ComputeVAndDir",t}();function G(t){return{x:t.points[1].clientX-t.points[0].clientX,y:t.points[1].clientY-t.points[0].clientY}}var H=function(){function t(){}return t.prototype.compute=function(t){var e=t.prevInput,n=t.startMultiInput;if(void 0!==n&&void 0!==e&&t.id!==n.id&&1<t.pointLength)return{startV:G(n),prevV:G(e),activeV:G(t)}},t._id="ComputeVectorForMutli",t}(),B={name:"tap",pointLength:1,tapTimes:1,waitNextTapTime:300,maxDistance:2,maxDistanceFromPrevTap:9,maxPressTime:250},q=function(t){function i(e){var i=t.call(this,n(n({},B),e))||this;return i.tapCount=0,i}return e(i,t),i.prototype._isValidDistanceFromPrevTap=function(t){if(void 0!==this.prevTapPoint){var e=C({x:t.x-this.prevTapPoint.x,y:t.y-this.prevTapPoint.y});return this.prevTapPoint=t,this.options.maxDistanceFromPrevTap>=e}return this.prevTapPoint=t,!0},i.prototype._isValidInterval=function(){var t=performance.now();if(void 0===this.prevTapTime)return this.prevTapTime=t,!0;var e=t-this.prevTapTime;return this.prevTapTime=t,e<this.options.waitNextTapTime},i.prototype.recognize=function(t,e){var i=t.inputType,o=t.x,r=t.y;this.computed=this.compute([R,N],t),u===i&&(this.status="p",this.test(t)?(this.cancelCountDownToFail(),this._isValidDistanceFromPrevTap({x:o,y:r})&&this._isValidInterval()?this.tapCount++:this.tapCount=1,0==this.tapCount%this.options.tapTimes?(this.status=m,e(this.options.name,n(n({},this.computed),{tapCount:this.tapCount})),this.reset()):this.countDownToFail()):(this.reset(),this.status=y))},i.prototype.countDownToFail=function(){var t=this;this._countDownToFailTimer=setTimeout((function(){t.status=y,t.reset()}),this.options.waitNextTapTime)},i.prototype.cancelCountDownToFail=function(){clearTimeout(this._countDownToFailTimer)},i.prototype.reset=function(){this.tapCount=0,this.prevTapPoint=void 0,this.prevTapTime=void 0},i.prototype.test=function(t){var e=t.startInput,n=t.timestamp-e.timestamp,i=this.computed,o=i.maxPointLength,r=i.distance;return o===this.options.pointLength&&this.options.maxDistance>=r&&this.options.maxPressTime>n},i}(O),Z={name:"pan",threshold:10,pointLength:1},$=function(t){function i(e){return t.call(this,n(n({},Z),e))||this}return e(i,t),i.prototype.test=function(t){var e=t.pointLength,n=this.computed.distance;return(this.isRecognized||this.options.threshold<n)&&this.isValidPointLength(e)},i.prototype.recognize=function(t,e){if(this.computed=this.compute([U,N,k],t),V(this,t,e)){t.inputType;e(this.options.name+this.computed.direction,this.computed)}},i}(O),J={name:"swipe",threshold:10,velocity:.3,pointLength:1},K=function(t){function i(e){return t.call(this,n(n({},J),e))||this}return e(i,t),i.prototype.test=function(t){var e=t.inputType;if(u!==e)return!1;var n=this.computed,i=n.velocityX,o=n.velocityY,r=n.maxPointLength,s=n.distance;return this.options.pointLength===r&&this.options.threshold<s&&this.options.velocity<Math.max(i,o)},i.prototype.recognize=function(t,e){this.computed=this.compute([R,U,N],t),this.test(t)&&(e(this.options.name,this.computed),e(this.options.name+this.computed.direction,this.computed))},i}(O),Q={name:"press",pointLength:1,maxDistance:9,minPressTime:251},W=function(t){function i(e){return t.call(this,n(n({},Q),e))||this}return e(i,t),i.prototype.recognize=function(t,e){var n=this,i=t.inputType,o=t.startInput,r=t.pointLength;if("start"===i&&this.isValidPointLength(r))S(this),this.cancel(),this._timeoutId=setTimeout((function(){n.status=m,e(n.options.name,t)}),this.options.minPressTime);else if(u===i&&m===this.status)e(this.options.name+"up",this.computed);else{var s=t.timestamp-o.timestamp;(!this.test(t)||this.options.minPressTime>s&&[u,c].includes(i))&&(this.cancel(),this.status=y)}},i.prototype.test=function(t){t.pointLength;this.computed=this.compute([N],t);var e=this.computed.distance;return this.options.maxDistance>e},i.prototype.cancel=function(){clearTimeout(this._timeoutId)},i}(O),tt={name:"pinch",threshold:0,pointLength:2},et=function(t){function i(e){return t.call(this,n(n({},tt),e))||this}return e(i,t),i.prototype.test=function(t){var e=t.pointLength,n=this.computed.scale;return this.isValidPointLength(e)&&void 0!==n&&(this.options.threshold<Math.abs(n-1)||this.isRecognized)},i.prototype.recognize=function(t,e){var i,o,r,s,a,c=this.compute([H],t);"activeV"in c&&(this.computed=n(n({},this.computed),(o=(i=c).startV,r=i.prevV,s=i.activeV,a=T(C(s)/C(r)),{scale:T(C(s)/C(o)),deltaScale:a}))),V(this,t,e)},i}(O),nt={name:"rotate",threshold:0,pointLength:2},it=function(t){function i(e){return t.call(this,n(n({},nt),e))||this}return e(i,t),i.prototype.test=function(t){var e=t.pointLength,n=this.computed.angle;return this.isValidPointLength(e)&&(this.options.threshold<Math.abs(n)||this.isRecognized)},i.prototype.recognize=function(t,e){var i,o,r,s,a,c=this.compute([H],t);"activeV"in c&&(this.computed=n(n({},this.computed),(o=(i=c).startV,r=i.prevV,s=i.activeV,a=Math.round(j(s,r)),{angle:Math.round(j(s,o)),deltaAngle:a}))),V(this,t,e)},i}(O),ot=z([q,$,K,W,et,it]);return ot.Tap=q,ot.Pan=$,ot.Swipe=K,ot.Press=W,ot.Pinch=et,ot.Rotate=it,ot.STATUS_POSSIBLE="p",ot.STATUS_START=d,ot.STATUS_MOVE=v,ot.STATUS_END=f,ot.STATUS_CANCELLED=g,ot.STATUS_FAILED=y,ot.STATUS_RECOGNIZED=m,ot})); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t=t||self).AnyTouch=e()}(this,(function(){"use strict";var t=function(e,n){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(e,n)};function e(e,n){function i(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(i.prototype=n.prototype,new i)}var n=function(){return(n=Object.assign||function(t){for(var e,n=1,i=arguments.length;n<i;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t}).apply(this,arguments)};function i(t){var e="function"==typeof Symbol&&t[Symbol.iterator],n=0;return e?e.call(t):{next:function(){return t&&n>=t.length&&(t=void 0),{value:t&&t[n++],done:!t}}}}function o(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var i,o,r=n.call(t),s=[];try{for(;(void 0===e||e-- >0)&&!(i=r.next()).done;)s.push(i.value)}catch(t){o={error:t}}finally{try{i&&!i.done&&(n=r.return)&&n.call(r)}finally{if(o)throw o.error}}return s}function r(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(o(arguments[e]));return t}var s=function(){function t(){this.callbackMap={}}return t.prototype.target=function(t){var e=this;return{on:function(n,i){e.on(n,i,{target:t})}}},t.prototype.on=function(t,e,n){var i=(void 0===n?{}:n).target;void 0===this.callbackMap[t]&&(this.callbackMap[t]=[]),void 0!==i&&(e.target=i),this.callbackMap[t].push(e)},t.prototype.off=function(t,e){var n=this.callbackMap[t];if(void 0!==n)if(void 0===e)delete this.callbackMap[t];else{var i=n.findIndex((function(t){return t===e}));n.splice(i,1)}},t.prototype.emit=function(t,e){var n,o,r=this.callbackMap[t],s=(e||{}).targets;if(void 0!==r&&0<r.length){var a=function(t){var n=t.target;void 0!==n&&void 0!==s&&s.every((function(t){return n.contains(t)}))?t(e):void 0===n&&t(e)};try{for(var u=i(r),c=u.next();!c.done;c=u.next()){a(c.value)}}catch(t){n={error:t}}finally{try{c&&!c.done&&(o=u.return)&&o.call(u)}finally{if(n)throw n.error}}return!0}return!1},t.prototype.destroy=function(){this.callbackMap={}},t}(),a=Object.prototype.toString;var u="cancel",c="end",p="touch"+c,h="touch"+u,l="ontouchstart"in window,d="start",v="move",f=c,m="r",y="f",g=u;function T(t){return Math.round(100*t)/100}var b=function(){},M=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return e(n,t),n.prototype.load=function(t){var e=[],n=Array.from(t.touches).map((function(t){var n=t.clientX,i=t.clientY,o=t.target;return e.push(o),{clientX:n,clientY:i,target:o}})),i=Array.from(t.changedTouches).map((function(t){return{clientX:t.clientX,clientY:t.clientY,target:t.target}}));return{inputType:t.type.replace("touch",""),changedPoints:i,points:n,nativeEvent:t,target:t.target,targets:e}},n}(b),x=function(t){function n(){var e=t.call(this)||this;return e.target=null,e.isPressed=!1,e}return e(n,t),n.prototype.load=function(t){var e,n=t.clientX,i=t.clientY,o=t.type,r=t.button,s=t.target,a=[{clientX:n,clientY:i,target:s}];"mousedown"===o&&0===r?(this.target=s,this.isPressed=!0,e="start"):this.isPressed&&("mousemove"===o?e="move":"mouseup"===o&&(a=[],e=c,this.isPressed=!1));var u=this.prevPoints||[{clientX:n,clientY:i,target:s}];if(this.prevPoints=[{clientX:n,clientY:i,target:s}],void 0!==e)return{inputType:e,changedPoints:u,points:a,target:this.target,targets:[this.target],nativeEvent:t}},n}(b),E=function(){function t(){var t=l?M:x;this.adapter=new t,this.id=0}return t.prototype.transform=function(t){this.prevInput=this.activeInput;var e=this.adapter.load(t);if(void 0!==e){if(function(t){var e=!1,n=t.nativeEvent.currentTarget;window!==n&&document!==n&&null!==n&&t.points.forEach((function(t){var i=t.target;n.contains(i)||(e=!0)}));return e}(e))return;var i=Number.MAX_SAFE_INTEGER>this.id?++this.id:1,o=function(t){var e=t.inputType,i=t.points,o=t.changedPoints,r=t.nativeEvent,s=i.length,a="start"===e,p=c===e&&0===s||u===e,h=performance.now(),l=P(i)||P(o),d=l.x,v=l.y,f=r.currentTarget;return n(n({},t),{x:d,y:v,timestamp:h,isStart:a,isEnd:p,pointLength:s,currentTarget:f,getOffset:function(t){void 0===t&&(t=f);var e=t.getBoundingClientRect();return{x:d-Math.round(e.left),y:v-Math.round(e.top)}}})}(n(n({},e),{id:i}));this.activeInput=o;var r=o.isStart,s=o.pointLength;return r&&(this.startInput=o,this.prevInput=void 0,this.startMultiInput=1<s?o:void 0),n(n({},o),{prevInput:this.prevInput,startMultiInput:this.startMultiInput,startInput:this.startInput})}},t}();function P(t){var e=t.length;if(0<e){if(1===e){var n=t[0],i=n.clientX,o=n.clientY;return{x:Math.round(i),y:Math.round(o)}}var r=t.reduce((function(t,e){return t.x+=e.clientX,t.y+=e.clientY,t}),{x:0,y:0});return{x:Math.round(r.x/e),y:Math.round(r.y/e)}}}function w(t,e,n){e.target,e.currentTarget;var i,o,r,s=e.type,a=function(t,e){var n={};for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&e.indexOf(i)<0&&(n[i]=t[i]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(i=Object.getOwnPropertySymbols(t);o<i.length;o++)e.indexOf(i[o])<0&&Object.prototype.propertyIsEnumerable.call(t,i[o])&&(n[i[o]]=t[i[o]])}return n}(e,["target","currentTarget","type"]);return void 0!==Event?r=new Event(s,n):(r=document.createEvent("HTMLEvents")).initEvent(s,null===(i=n)||void 0===i?void 0:i.bubbles,null===(o=n)||void 0===o?void 0:o.cancelable),Object.assign(r,a,{match:function(){return e.targets.every((function(t){return r.currentTarget.contains(t)}))}}),t.dispatchEvent(r)}function L(t,e){if(!e.isPreventDefault)return!1;var n,i=!0;if(null!==t.target){var o=e.preventDefaultExclude;if(n=o,"[object RegExp]"===a.call(n)){if("tagName"in t.target){var r=t.target.tagName;i=!o.test(r)}}else(function(t){return"[object Function]"===a.call(t)})(o)&&(i=!o(t))}return i}var X=["touchstart","touchmove",p,h];function Y(t,e,n){var i,o=null===(i=n)||void 0===i?void 0:i.name;if(void 0===o||void 0===t.recognizerMap[o]){var r=new e(n);t.recognizerMap[r.name]=r,r.recognizerMap=t.recognizerMap,t.recognizers.push(t.recognizerMap[r.name])}}function _(t,e){var n,r;if(void 0===e)t.recognizers=[],t.recognizerMap={};else try{for(var s=i(t.recognizers.entries()),a=s.next();!a.done;a=s.next()){var u=o(a.value,2),c=u[0];if(e===u[1].options.name){t.recognizers.splice(c,1),delete t.recognizerMap[e];break}}}catch(t){n={error:t}}finally{try{a&&!a.done&&(r=s.return)&&r.call(s)}finally{if(n)throw n.error}}}var I={domEvents:{bubbles:!0,cancelable:!0},isPreventDefault:!0,preventDefaultExclude:/^(?:INPUT|TEXTAREA|BUTTON|SELECT)$/},z=function(t){function o(e,i){var r=t.call(this)||this;if(r.recognizerMap={},r.recognizers=[],r.el=e,r.input=new E,r.options=n(n({},I),i),r.recognizerMap=o.recognizerMap,r.recognizers=o.recognizers,void 0!==e){e.style.webkitTapHighlightColor="rgba(0,0,0,0)";var s=!1;try{var a={};Object.defineProperty(a,"passive",{get:function(){s=!0}}),window.addEventListener("_",(function(){}),a)}catch(t){}var u=function(t,e,n){return l?(X.forEach((function(i){t.addEventListener(i,e,n)})),function(){X.forEach((function(n){t.removeEventListener(n,e)}))}):(t.addEventListener("mousedown",e,n),window.addEventListener("mousemove",e,n),window.addEventListener("mouseup",e,n),function(){t.removeEventListener("mousedown",e),window.removeEventListener("mousemove",e),window.removeEventListener("mouseup",e)})}(e,r.catchEvent.bind(r),!(r.options.isPreventDefault||!s)&&{passive:!0});r.on("unbindEl",u)}return r}return e(o,t),o.prototype.use=function(t,e){Y(this,t,e)},o.prototype.removeUse=function(t){_(this,t)},o.prototype.catchEvent=function(t){var e,o,r=this;L(t,this.options)&&t.preventDefault();var s=this.input.transform(t);if(void 0!==s){var a="at:touch"+s.inputType;if(this.emit("at:touch",s),this.emit(a,s),!1!==this.options.domEvents){var u=t.target;null!==u&&(w(u,n(n({},s),{type:"at:touch"}),this.options.domEvents),w(u,n(n({},s),{type:a}),this.options.domEvents))}var c={},p=function(t){if(t.disabled)return"continue";t.input=s,t.computedGroup=c,t.recognize(s,(function(e,i){var o=n(n(n({},s),i),{type:e,baseType:t.name});Object.freeze(o),void 0===r.beforeEachHook?D(r,o):r.beforeEachHook(t,(function(){D(r,o)}))})),c=t.computedGroup};try{for(var h=i(this.recognizers),l=h.next();!l.done;l=h.next()){p(l.value)}}catch(t){e={error:t}}finally{try{l&&!l.done&&(o=h.return)&&o.call(h)}finally{if(e)throw e.error}}}},o.prototype.beforeEach=function(t){this.beforeEachHook=t},o.prototype.get=function(t){return this.recognizerMap[t]},o.prototype.set=function(t){this.options=n(n({},this.options),t)},o.prototype.destroy=function(){this.emit("unbindEl"),this.callbackMap={}},o.version="0.6.2-beta.4",o.recognizers=[],o.recognizerMap={},o.use=function(t,e){Y(o,t,e)},o.removeUse=function(t){_(o,t)},o}(s);function D(t,e){var i=e.type,o=e.target;t.emit("at:after",e),t.emit(i,e),!1!==t.options.domEvents&&void 0!==t.el&&null!=o&&(w(o,e,t.options.domEvents),w(o,n(n({},e),{type:"at:after"}),t.options.domEvents))}function S(t){-1!==[f,g,m,y].indexOf(t.status)&&(t.status="p")}function V(t,e,n){var i=t.test(e);S(t);var o=e.inputType;t.status=function(t,e,n){var i,o,r,s,a,p,h,l={1:(i={},i.p=(o={},o.move=d,o),i[d]=(r={},r.move=v,r[c]=f,r[u]=g,r),i[v]=(s={},s.move=v,s[c]=f,s[u]=g,s),i),0:(a={},a[d]=(p={},p.move=g,p[c]=f,p[u]=g,p),a[v]=(h={},h.start=y,h.move=g,h[c]=f,h[u]=g,h),a)};return void 0!==l[Number(t)][e]&&l[Number(t)][e][n]||e}(i,t.status,o);var r=t.computed;t.isRecognized=[d,v].includes(t.status);var s=t.name,a=t.status,p=t.isRecognized;return p&&n(s,r),(p||[f,g].includes(t.status))&&n(s+a,r),i}var O=function(){function t(t){this.options=t,this.name=this.options.name,this.disabled=!1,this.status="p",this.isRecognized=!1,this.computed={},this.computedGroup={},this.usedComputeFunctionMap={},this.recognizerMap={}}return t.prototype.set=function(t){return void 0!==t&&(this.options=n(n({},this.options),t)),this},t.prototype.isValidPointLength=function(t){return 0===this.options.pointLength||this.options.pointLength===t},t.prototype.compute=function(t){for(var e,o,s,a=[],u=1;u<arguments.length;u++)a[u-1]=arguments[u];var c=Object.create(null);try{for(var p=i(t),h=p.next();!h.done;h=p.next()){var l=h.value,d=l._id,v=this,f=v.computedGroup,m=v.usedComputeFunctionMap;void 0===m[d]&&(m[d]=new l),f[d]=f[d]||(s=m[d]).compute.apply(s,r(a)),c=n(n({},c),f[d])}}catch(t){e={error:t}}finally{try{h&&!h.done&&(o=p.return)&&o.call(p)}finally{if(e)throw e.error}}return this.computed=c,c},t}(),C=function(t){return Math.sqrt(t.x*t.x+t.y*t.y)},A=function(t){return t/Math.PI*180},j=function(t,e){var n=function(t,e){var n=C(t)*C(e);if(0===n)return 0;var i=function(t,e){return t.x*e.x+t.y*e.y}(t,e)/n;return i>1&&(i=1),Math.acos(i)}(t,e);return function(t,e){return t.x*e.y-e.x*t.y}(t,e)>0&&(n*=-1),A(n)},F=function(t,e){return t===e?"none":Math.abs(t)>Math.abs(e)?0<t?"right":"left":0<e?"down":"up"};var k=function(){function t(){}return t.prototype.compute=function(t){var e=t.prevInput,n=0,i=0,o=0;if(void 0!==e&&(n=t.x-e.x,i=t.y-e.y,0!==n||0!==i)){var r=Math.sqrt(Math.pow(n,2)+Math.pow(i,2));o=Math.round(A(Math.acos(Math.abs(n)/r)))}return{deltaX:n,deltaY:i,deltaXYAngle:o}},t._id="ComputeDeltaXY",t}(),N=function(){function t(){this.displacementX=0,this.displacementY=0,this.distanceX=0,this.distanceY=0,this.distance=0,this.overallDirection="none"}return t.prototype.compute=function(t){var e=t.inputType,n=t.startInput;"start"===e?(this.displacementX=0,this.displacementY=0,this.distanceX=0,this.distanceY=0,this.distance=0,this.overallDirection="none"):"move"===e&&(this.displacementX=Math.round(t.points[0].clientX-n.points[0].clientX),this.displacementY=Math.round(t.points[0].clientY-n.points[0].clientY),this.distanceX=Math.abs(this.displacementX),this.distanceY=Math.abs(this.displacementY),this.distance=Math.round(C({x:this.distanceX,y:this.distanceY})),this.overallDirection=F(this.displacementX,this.displacementY));var i=this;return{displacementX:i.displacementX,displacementY:i.displacementY,distanceX:i.distanceX,distanceY:i.distanceY,distance:i.distance,overallDirection:i.overallDirection}},t._id="ComputeDistance",t}(),R=function(){function t(){this.maxPointLength=0}return t.prototype.compute=function(t){return"start"===t.inputType&&(this.maxPointLength=t.pointLength),{maxPointLength:this.maxPointLength}},t._id="ComputeMaxLength",t}();var U=function(){function t(){this.velocityX=0,this.velocityY=0,this.speedX=0,this.speedY=0}return t.prototype.compute=function(t){if(void 0!==t){var e=t.inputType;this._lastValidInput=this._lastValidInput||t.startInput;var n=t.timestamp-this._lastValidInput.timestamp;if("move"===e&&16<n){var i=t.x-this._lastValidInput.x,o=t.y-this._lastValidInput.y;this.speedX=Math.round(i/n*100)/100,this.speedY=Math.round(o/n*100)/100,this.velocityX=Math.abs(this.speedX),this.velocityY=Math.abs(this.speedY),this.direction=F(i,o)||this.direction,this._lastValidInput=t}}var r=this;return{velocityX:r.velocityX,velocityY:r.velocityY,speedX:r.speedX,speedY:r.speedY,direction:r.direction}},t._id="ComputeVAndDir",t}();function G(t){return{x:t.points[1].clientX-t.points[0].clientX,y:t.points[1].clientY-t.points[0].clientY}}var H=function(){function t(){}return t.prototype.compute=function(t){var e=t.prevInput,n=t.startMultiInput;if(void 0!==n&&void 0!==e&&t.id!==n.id&&1<t.pointLength)return{startV:G(n),prevV:G(e),activeV:G(t)}},t._id="ComputeVectorForMutli",t}(),B={name:"tap",pointLength:1,tapTimes:1,waitNextTapTime:300,maxDistance:2,maxDistanceFromPrevTap:9,maxPressTime:250},q=function(t){function i(e){var i=t.call(this,n(n({},B),e))||this;return i.tapCount=0,i}return e(i,t),i.prototype._isValidDistanceFromPrevTap=function(t){if(void 0!==this.prevTapPoint){var e=C({x:t.x-this.prevTapPoint.x,y:t.y-this.prevTapPoint.y});return this.prevTapPoint=t,this.options.maxDistanceFromPrevTap>=e}return this.prevTapPoint=t,!0},i.prototype._isValidInterval=function(){var t=performance.now();if(void 0===this.prevTapTime)return this.prevTapTime=t,!0;var e=t-this.prevTapTime;return this.prevTapTime=t,e<this.options.waitNextTapTime},i.prototype.recognize=function(t,e){var i=t.inputType,o=t.x,r=t.y;this.computed=this.compute([R,N],t),c===i&&(this.status="p",this.test(t)?(this.cancelCountDownToFail(),this._isValidDistanceFromPrevTap({x:o,y:r})&&this._isValidInterval()?this.tapCount++:this.tapCount=1,0==this.tapCount%this.options.tapTimes?(this.status=m,e(this.options.name,n(n({},this.computed),{tapCount:this.tapCount})),this.reset()):this.countDownToFail()):(this.reset(),this.status=y))},i.prototype.countDownToFail=function(){var t=this;this._countDownToFailTimer=setTimeout((function(){t.status=y,t.reset()}),this.options.waitNextTapTime)},i.prototype.cancelCountDownToFail=function(){clearTimeout(this._countDownToFailTimer)},i.prototype.reset=function(){this.tapCount=0,this.prevTapPoint=void 0,this.prevTapTime=void 0},i.prototype.test=function(t){var e=t.startInput,n=t.timestamp-e.timestamp,i=this.computed,o=i.maxPointLength,r=i.distance;return o===this.options.pointLength&&this.options.maxDistance>=r&&this.options.maxPressTime>n},i}(O),Z={name:"pan",threshold:10,pointLength:1},$=function(t){function i(e){return t.call(this,n(n({},Z),e))||this}return e(i,t),i.prototype.test=function(t){var e=t.pointLength,n=this.computed.distance;return(this.isRecognized||this.options.threshold<n)&&this.isValidPointLength(e)},i.prototype.recognize=function(t,e){if(this.computed=this.compute([U,N,k],t),V(this,t,e)){t.inputType;e(this.options.name+this.computed.direction,this.computed)}},i}(O),J={name:"swipe",threshold:10,velocity:.3,pointLength:1},K=function(t){function i(e){return t.call(this,n(n({},J),e))||this}return e(i,t),i.prototype.test=function(t){var e=t.inputType;if(c!==e)return!1;var n=this.computed,i=n.velocityX,o=n.velocityY,r=n.maxPointLength,s=n.distance;return this.options.pointLength===r&&this.options.threshold<s&&this.options.velocity<Math.max(i,o)},i.prototype.recognize=function(t,e){this.computed=this.compute([R,U,N],t),this.test(t)&&(e(this.options.name,this.computed),e(this.options.name+this.computed.direction,this.computed))},i}(O),Q={name:"press",pointLength:1,maxDistance:9,minPressTime:251},W=function(t){function i(e){return t.call(this,n(n({},Q),e))||this}return e(i,t),i.prototype.recognize=function(t,e){var n=this,i=t.inputType,o=t.startInput,r=t.pointLength;if("start"===i&&this.isValidPointLength(r))S(this),this.cancel(),this._timeoutId=setTimeout((function(){n.status=m,e(n.options.name,t)}),this.options.minPressTime);else if(c===i&&m===this.status)e(this.options.name+"up",this.computed);else{var s=t.timestamp-o.timestamp;(!this.test(t)||this.options.minPressTime>s&&[c,u].includes(i))&&(this.cancel(),this.status=y)}},i.prototype.test=function(t){t.pointLength;this.computed=this.compute([N],t);var e=this.computed.distance;return this.options.maxDistance>e},i.prototype.cancel=function(){clearTimeout(this._timeoutId)},i}(O),tt={name:"pinch",threshold:0,pointLength:2},et=function(t){function i(e){return t.call(this,n(n({},tt),e))||this}return e(i,t),i.prototype.test=function(t){var e=t.pointLength,n=this.computed.scale;return this.isValidPointLength(e)&&void 0!==n&&(this.options.threshold<Math.abs(n-1)||this.isRecognized)},i.prototype.recognize=function(t,e){var i,o,r,s,a,u=this.compute([H],t);"activeV"in u&&(this.computed=n(n({},this.computed),(o=(i=u).startV,r=i.prevV,s=i.activeV,a=T(C(s)/C(r)),{scale:T(C(s)/C(o)),deltaScale:a}))),V(this,t,e)},i}(O),nt={name:"rotate",threshold:0,pointLength:2},it=function(t){function i(e){return t.call(this,n(n({},nt),e))||this}return e(i,t),i.prototype.test=function(t){var e=t.pointLength,n=this.computed.angle;return this.isValidPointLength(e)&&(this.options.threshold<Math.abs(n)||this.isRecognized)},i.prototype.recognize=function(t,e){var i,o,r,s,a,u=this.compute([H],t);"activeV"in u&&(this.computed=n(n({},this.computed),(o=(i=u).startV,r=i.prevV,s=i.activeV,a=Math.round(j(s,r)),{angle:Math.round(j(s,o)),deltaAngle:a}))),V(this,t,e)},i}(O);return z.use(q),z.use($),z.use(K),z.use(W),z.use(et),z.use(it),z.Tap=q,z.Pan=$,z.Swipe=K,z.Press=W,z.Pinch=et,z.Rotate=it,z.STATUS_POSSIBLE="p",z.STATUS_START=d,z.STATUS_MOVE=v,z.STATUS_END=f,z.STATUS_CANCELLED=g,z.STATUS_FAILED=y,z.STATUS_RECOGNIZED=m,z})); |
@@ -1,11 +0,2 @@ | ||
import Tap from '@any-touch/tap'; | ||
import Pan from '@any-touch/pan'; | ||
import Swipe from '@any-touch/swipe'; | ||
import Press from '@any-touch/press'; | ||
import Pinch from '@any-touch/pinch'; | ||
import Rotate from '@any-touch/rotate'; | ||
export declare const Core: any; | ||
export { Tap, Pan, Swipe, Press, Pinch, Rotate }; | ||
export { STATUS_POSSIBLE, STATUS_START, STATUS_MOVE, STATUS_END, STATUS_CANCELLED, STATUS_FAILED, STATUS_RECOGNIZED } from '@any-touch/shared'; | ||
import AnyTouch from './UMD'; | ||
import AnyTouch from '@any-touch/core'; | ||
export default AnyTouch; |
@@ -7,3 +7,3 @@ 'use strict'; | ||
var core = require('@any-touch/core'); | ||
var AnyTouch = _interopDefault(require('@any-touch/core')); | ||
var Tap = _interopDefault(require('@any-touch/tap')); | ||
@@ -17,3 +17,8 @@ var Pan = _interopDefault(require('@any-touch/pan')); | ||
var AnyTouch = core.createAnyTouch([Tap, Pan, Swipe, Press, Pinch, Rotate]); | ||
AnyTouch.use(Tap); | ||
AnyTouch.use(Pan); | ||
AnyTouch.use(Swipe); | ||
AnyTouch.use(Press); | ||
AnyTouch.use(Pinch); | ||
AnyTouch.use(Rotate); | ||
AnyTouch.Tap = Tap; | ||
@@ -33,53 +38,2 @@ AnyTouch.Pan = Pan; | ||
var Core = core.createAnyTouch(); | ||
exports.Tap = Tap; | ||
exports.Pan = Pan; | ||
exports.Swipe = Swipe; | ||
exports.Press = Press; | ||
exports.Pinch = Pinch; | ||
exports.Rotate = Rotate; | ||
Object.defineProperty(exports, 'STATUS_CANCELLED', { | ||
enumerable: true, | ||
get: function () { | ||
return shared.STATUS_CANCELLED; | ||
} | ||
}); | ||
Object.defineProperty(exports, 'STATUS_END', { | ||
enumerable: true, | ||
get: function () { | ||
return shared.STATUS_END; | ||
} | ||
}); | ||
Object.defineProperty(exports, 'STATUS_FAILED', { | ||
enumerable: true, | ||
get: function () { | ||
return shared.STATUS_FAILED; | ||
} | ||
}); | ||
Object.defineProperty(exports, 'STATUS_MOVE', { | ||
enumerable: true, | ||
get: function () { | ||
return shared.STATUS_MOVE; | ||
} | ||
}); | ||
Object.defineProperty(exports, 'STATUS_POSSIBLE', { | ||
enumerable: true, | ||
get: function () { | ||
return shared.STATUS_POSSIBLE; | ||
} | ||
}); | ||
Object.defineProperty(exports, 'STATUS_RECOGNIZED', { | ||
enumerable: true, | ||
get: function () { | ||
return shared.STATUS_RECOGNIZED; | ||
} | ||
}); | ||
Object.defineProperty(exports, 'STATUS_START', { | ||
enumerable: true, | ||
get: function () { | ||
return shared.STATUS_START; | ||
} | ||
}); | ||
exports.Core = Core; | ||
exports.default = AnyTouch; |
@@ -1,18 +0,16 @@ | ||
import { createAnyTouch } from '@any-touch/core'; | ||
import AnyTouch from '@any-touch/core'; | ||
import Tap from '@any-touch/tap'; | ||
export { default as Tap } from '@any-touch/tap'; | ||
import Pan from '@any-touch/pan'; | ||
export { default as Pan } from '@any-touch/pan'; | ||
import Swipe from '@any-touch/swipe'; | ||
export { default as Swipe } from '@any-touch/swipe'; | ||
import Press from '@any-touch/press'; | ||
export { default as Press } from '@any-touch/press'; | ||
import Pinch from '@any-touch/pinch'; | ||
export { default as Pinch } from '@any-touch/pinch'; | ||
import Rotate from '@any-touch/rotate'; | ||
export { default as Rotate } from '@any-touch/rotate'; | ||
import { STATUS_POSSIBLE, STATUS_START, STATUS_MOVE, STATUS_END, STATUS_CANCELLED, STATUS_FAILED, STATUS_RECOGNIZED } from '@any-touch/shared'; | ||
export { STATUS_CANCELLED, STATUS_END, STATUS_FAILED, STATUS_MOVE, STATUS_POSSIBLE, STATUS_RECOGNIZED, STATUS_START } from '@any-touch/shared'; | ||
var AnyTouch = createAnyTouch([Tap, Pan, Swipe, Press, Pinch, Rotate]); | ||
AnyTouch.use(Tap); | ||
AnyTouch.use(Pan); | ||
AnyTouch.use(Swipe); | ||
AnyTouch.use(Press); | ||
AnyTouch.use(Pinch); | ||
AnyTouch.use(Rotate); | ||
AnyTouch.Tap = Tap; | ||
@@ -32,5 +30,2 @@ AnyTouch.Pan = Pan; | ||
var Core = createAnyTouch(); | ||
export default AnyTouch; | ||
export { Core }; |
@@ -1,1 +0,1 @@ | ||
"use strict";function _interopDefault(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var core=require("@any-touch/core"),Tap=_interopDefault(require("@any-touch/tap")),Pan=_interopDefault(require("@any-touch/pan")),Swipe=_interopDefault(require("@any-touch/swipe")),Press=_interopDefault(require("@any-touch/press")),Pinch=_interopDefault(require("@any-touch/pinch")),Rotate=_interopDefault(require("@any-touch/rotate")),shared=require("@any-touch/shared"),AnyTouch=core.createAnyTouch([Tap,Pan,Swipe,Press,Pinch,Rotate]);AnyTouch.Tap=Tap,AnyTouch.Pan=Pan,AnyTouch.Swipe=Swipe,AnyTouch.Press=Press,AnyTouch.Pinch=Pinch,AnyTouch.Rotate=Rotate,AnyTouch.STATUS_POSSIBLE=shared.STATUS_POSSIBLE,AnyTouch.STATUS_START=shared.STATUS_START,AnyTouch.STATUS_MOVE=shared.STATUS_MOVE,AnyTouch.STATUS_END=shared.STATUS_END,AnyTouch.STATUS_CANCELLED=shared.STATUS_CANCELLED,AnyTouch.STATUS_FAILED=shared.STATUS_FAILED,AnyTouch.STATUS_RECOGNIZED=shared.STATUS_RECOGNIZED;var Core=core.createAnyTouch();exports.Tap=Tap,exports.Pan=Pan,exports.Swipe=Swipe,exports.Press=Press,exports.Pinch=Pinch,exports.Rotate=Rotate,Object.defineProperty(exports,"STATUS_CANCELLED",{enumerable:!0,get:function(){return shared.STATUS_CANCELLED}}),Object.defineProperty(exports,"STATUS_END",{enumerable:!0,get:function(){return shared.STATUS_END}}),Object.defineProperty(exports,"STATUS_FAILED",{enumerable:!0,get:function(){return shared.STATUS_FAILED}}),Object.defineProperty(exports,"STATUS_MOVE",{enumerable:!0,get:function(){return shared.STATUS_MOVE}}),Object.defineProperty(exports,"STATUS_POSSIBLE",{enumerable:!0,get:function(){return shared.STATUS_POSSIBLE}}),Object.defineProperty(exports,"STATUS_RECOGNIZED",{enumerable:!0,get:function(){return shared.STATUS_RECOGNIZED}}),Object.defineProperty(exports,"STATUS_START",{enumerable:!0,get:function(){return shared.STATUS_START}}),exports.Core=Core,exports.default=AnyTouch; | ||
"use strict";function _interopDefault(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var AnyTouch=_interopDefault(require("@any-touch/core")),Tap=_interopDefault(require("@any-touch/tap")),Pan=_interopDefault(require("@any-touch/pan")),Swipe=_interopDefault(require("@any-touch/swipe")),Press=_interopDefault(require("@any-touch/press")),Pinch=_interopDefault(require("@any-touch/pinch")),Rotate=_interopDefault(require("@any-touch/rotate")),shared=require("@any-touch/shared");AnyTouch.use(Tap),AnyTouch.use(Pan),AnyTouch.use(Swipe),AnyTouch.use(Press),AnyTouch.use(Pinch),AnyTouch.use(Rotate),AnyTouch.Tap=Tap,AnyTouch.Pan=Pan,AnyTouch.Swipe=Swipe,AnyTouch.Press=Press,AnyTouch.Pinch=Pinch,AnyTouch.Rotate=Rotate,AnyTouch.STATUS_POSSIBLE=shared.STATUS_POSSIBLE,AnyTouch.STATUS_START=shared.STATUS_START,AnyTouch.STATUS_MOVE=shared.STATUS_MOVE,AnyTouch.STATUS_END=shared.STATUS_END,AnyTouch.STATUS_CANCELLED=shared.STATUS_CANCELLED,AnyTouch.STATUS_FAILED=shared.STATUS_FAILED,AnyTouch.STATUS_RECOGNIZED=shared.STATUS_RECOGNIZED,exports.default=AnyTouch; |
{ | ||
"name": "any-touch", | ||
"version": "0.6.2-beta.2", | ||
"version": "0.6.3-beta.0", | ||
"description": "一个小巧的手势库", | ||
@@ -25,10 +25,10 @@ "unpkg": "dist/any-touch.umd.min.js", | ||
"dependencies": { | ||
"@any-touch/core": "^0.6.2-beta.2", | ||
"@any-touch/pan": "^0.6.2-beta.2", | ||
"@any-touch/pinch": "^0.6.2-beta.2", | ||
"@any-touch/press": "^0.6.2-beta.2", | ||
"@any-touch/rotate": "^0.6.2-beta.2", | ||
"@any-touch/swipe": "^0.6.2-beta.2", | ||
"@any-touch/tap": "^0.6.2-beta.2", | ||
"any-event": "^0.6.2-beta.2", | ||
"@any-touch/core": "^0.6.3-beta.0", | ||
"@any-touch/pan": "^0.6.3-beta.0", | ||
"@any-touch/pinch": "^0.6.3-beta.0", | ||
"@any-touch/press": "^0.6.3-beta.0", | ||
"@any-touch/rotate": "^0.6.3-beta.0", | ||
"@any-touch/swipe": "^0.6.3-beta.0", | ||
"@any-touch/tap": "^0.6.3-beta.0", | ||
"any-event": "^0.6.3-beta.0", | ||
"tslib": "^1.9.3" | ||
@@ -42,3 +42,3 @@ }, | ||
"sideEffects": false, | ||
"gitHead": "4c4f96f614f85af7f96e334528981159a040446a" | ||
"gitHead": "8d5f17faa86ccfb5091086bb38012659af614dec" | ||
} |
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
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
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
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
72581
9
1261
+ Added@any-touch/compute@0.6.3-beta.0(transitive)
+ Added@any-touch/core@0.6.3-beta.0(transitive)
+ Added@any-touch/pan@0.6.3-beta.0(transitive)
+ Added@any-touch/pinch@0.6.3-beta.0(transitive)
+ Added@any-touch/press@0.6.3-beta.0(transitive)
+ Added@any-touch/recognizer@0.6.3-beta.0(transitive)
+ Added@any-touch/rotate@0.6.3-beta.0(transitive)
+ Added@any-touch/shared@0.6.3-beta.0(transitive)
+ Added@any-touch/swipe@0.6.3-beta.0(transitive)
+ Added@any-touch/tap@0.6.3-beta.0(transitive)
+ Added@any-touch/vector@0.6.3-beta.0(transitive)
+ Addedany-event@0.6.3-beta.0(transitive)
- Removed@any-touch/compute@0.6.2-beta.2(transitive)
- Removed@any-touch/core@0.6.2-beta.2(transitive)
- Removed@any-touch/pan@0.6.2-beta.2(transitive)
- Removed@any-touch/pinch@0.6.2-beta.2(transitive)
- Removed@any-touch/press@0.6.2-beta.2(transitive)
- Removed@any-touch/recognizer@0.6.2-beta.2(transitive)
- Removed@any-touch/rotate@0.6.2-beta.2(transitive)
- Removed@any-touch/shared@0.6.2-beta.2(transitive)
- Removed@any-touch/swipe@0.6.2-beta.2(transitive)
- Removed@any-touch/tap@0.6.2-beta.2(transitive)
- Removed@any-touch/vector@0.6.2-beta.2(transitive)
- Removedany-event@0.6.2-beta.2(transitive)
Updated@any-touch/pan@^0.6.3-beta.0
Updated@any-touch/tap@^0.6.3-beta.0
Updatedany-event@^0.6.3-beta.0