Comparing version 1.8.0 to 1.8.1
@@ -7,3 +7,3 @@ /* | ||
repository: git+https://github.com/daybrush/gesto.git | ||
version: 1.8.0 | ||
version: 1.8.1 | ||
*/ | ||
@@ -79,2 +79,6 @@ 'use strict'; | ||
function getEventClients(e) { | ||
if (!e) { | ||
return []; | ||
} | ||
if (e.touches) { | ||
@@ -354,3 +358,3 @@ return getClients(e.touches); | ||
var result = _this.emit("dragStart", __assign({ | ||
var result = _this.emit("dragStart", __assign(__assign({ | ||
datas: _this.datas, | ||
@@ -360,3 +364,3 @@ inputEvent: e, | ||
isDouble: _this.doubleFlag | ||
}, _this.getCurrentStore().getPosition(), { | ||
}, _this.getCurrentStore().getPosition()), { | ||
preventDefault: function () { | ||
@@ -419,3 +423,3 @@ e.preventDefault(); | ||
if (_this.pinchFlag || result.deltaX || result.deltaY) { | ||
var dragResult = _this.emit("drag", __assign({}, result, { | ||
var dragResult = _this.emit("drag", __assign(__assign({}, result), { | ||
isScroll: !!isScroll, | ||
@@ -457,3 +461,3 @@ inputEvent: e | ||
var clients = getEventClients(e); | ||
var clients = (e === null || e === void 0 ? void 0 : e.touches) ? getEventClients(e) : []; | ||
var clientsLength = clients.length; | ||
@@ -665,5 +669,5 @@ | ||
__proto.getCurrentEvent = function (inputEvent) { | ||
return __assign({ | ||
return __assign(__assign({ | ||
datas: this.datas | ||
}, this._getPosition(), { | ||
}, this._getPosition()), { | ||
movement: this.getMovement(), | ||
@@ -729,7 +733,7 @@ isDrag: this.isDrag, | ||
var result = this.emit("pinchStart", __assign({ | ||
var result = this.emit("pinchStart", __assign(__assign({ | ||
datas: this.datas, | ||
angle: store.getAngle(), | ||
touches: this.getCurrentStore().getPositions() | ||
}, store.getPosition(), { | ||
}, store.getPosition()), { | ||
inputEvent: e | ||
@@ -750,3 +754,3 @@ })); | ||
this.isPinch = true; | ||
this.emit("pinch", __assign({ | ||
this.emit("pinch", __assign(__assign({ | ||
datas: this.datas, | ||
@@ -759,3 +763,3 @@ movement: this.getMovement(clients), | ||
distance: store.getDistance(clients) | ||
}, store.getPosition(clients), { | ||
}, store.getPosition(clients)), { | ||
inputEvent: e | ||
@@ -774,7 +778,7 @@ })); | ||
var store = this.getCurrentStore(); | ||
this.emit("pinchEnd", __assign({ | ||
this.emit("pinchEnd", __assign(__assign({ | ||
datas: this.datas, | ||
isPinch: isPinch, | ||
touches: store.getPositions() | ||
}, store.getPosition(), { | ||
}, store.getPosition()), { | ||
inputEvent: e | ||
@@ -803,5 +807,5 @@ })); | ||
return __assign({ | ||
return __assign(__assign({ | ||
datas: this.datas | ||
}, position, { | ||
}, position), { | ||
movement: this.getMovement(clients), | ||
@@ -832,3 +836,3 @@ isDrag: this.isDrag, | ||
return __assign({}, position, { | ||
return __assign(__assign({}, position), { | ||
distX: distX, | ||
@@ -835,0 +839,0 @@ distY: distY |
@@ -7,3 +7,3 @@ /* | ||
repository: git+https://github.com/daybrush/gesto.git | ||
version: 1.8.0 | ||
version: 1.8.1 | ||
*/ | ||
@@ -77,2 +77,6 @@ import EventEmitter from '@scena/event-emitter'; | ||
function getEventClients(e) { | ||
if (!e) { | ||
return []; | ||
} | ||
if (e.touches) { | ||
@@ -352,3 +356,3 @@ return getClients(e.touches); | ||
var result = _this.emit("dragStart", __assign({ | ||
var result = _this.emit("dragStart", __assign(__assign({ | ||
datas: _this.datas, | ||
@@ -358,3 +362,3 @@ inputEvent: e, | ||
isDouble: _this.doubleFlag | ||
}, _this.getCurrentStore().getPosition(), { | ||
}, _this.getCurrentStore().getPosition()), { | ||
preventDefault: function () { | ||
@@ -417,3 +421,3 @@ e.preventDefault(); | ||
if (_this.pinchFlag || result.deltaX || result.deltaY) { | ||
var dragResult = _this.emit("drag", __assign({}, result, { | ||
var dragResult = _this.emit("drag", __assign(__assign({}, result), { | ||
isScroll: !!isScroll, | ||
@@ -455,3 +459,3 @@ inputEvent: e | ||
var clients = getEventClients(e); | ||
var clients = (e === null || e === void 0 ? void 0 : e.touches) ? getEventClients(e) : []; | ||
var clientsLength = clients.length; | ||
@@ -663,5 +667,5 @@ | ||
__proto.getCurrentEvent = function (inputEvent) { | ||
return __assign({ | ||
return __assign(__assign({ | ||
datas: this.datas | ||
}, this._getPosition(), { | ||
}, this._getPosition()), { | ||
movement: this.getMovement(), | ||
@@ -727,7 +731,7 @@ isDrag: this.isDrag, | ||
var result = this.emit("pinchStart", __assign({ | ||
var result = this.emit("pinchStart", __assign(__assign({ | ||
datas: this.datas, | ||
angle: store.getAngle(), | ||
touches: this.getCurrentStore().getPositions() | ||
}, store.getPosition(), { | ||
}, store.getPosition()), { | ||
inputEvent: e | ||
@@ -748,3 +752,3 @@ })); | ||
this.isPinch = true; | ||
this.emit("pinch", __assign({ | ||
this.emit("pinch", __assign(__assign({ | ||
datas: this.datas, | ||
@@ -757,3 +761,3 @@ movement: this.getMovement(clients), | ||
distance: store.getDistance(clients) | ||
}, store.getPosition(clients), { | ||
}, store.getPosition(clients)), { | ||
inputEvent: e | ||
@@ -772,7 +776,7 @@ })); | ||
var store = this.getCurrentStore(); | ||
this.emit("pinchEnd", __assign({ | ||
this.emit("pinchEnd", __assign(__assign({ | ||
datas: this.datas, | ||
isPinch: isPinch, | ||
touches: store.getPositions() | ||
}, store.getPosition(), { | ||
}, store.getPosition()), { | ||
inputEvent: e | ||
@@ -801,5 +805,5 @@ })); | ||
return __assign({ | ||
return __assign(__assign({ | ||
datas: this.datas | ||
}, position, { | ||
}, position), { | ||
movement: this.getMovement(clients), | ||
@@ -830,3 +834,3 @@ isDrag: this.isDrag, | ||
return __assign({}, position, { | ||
return __assign(__assign({}, position), { | ||
distX: distX, | ||
@@ -833,0 +837,0 @@ distY: distY |
@@ -7,3 +7,3 @@ /* | ||
repository: git+https://github.com/daybrush/gesto.git | ||
version: 1.8.0 | ||
version: 1.8.1 | ||
*/ | ||
@@ -80,2 +80,6 @@ (function (global, factory) { | ||
function getEventClients(e) { | ||
if (!e) { | ||
return []; | ||
} | ||
if (e.touches) { | ||
@@ -749,3 +753,3 @@ return getClients(e.touches); | ||
var result = _this.emit("dragStart", __assign({ | ||
var result = _this.emit("dragStart", __assign(__assign({ | ||
datas: _this.datas, | ||
@@ -755,3 +759,3 @@ inputEvent: e, | ||
isDouble: _this.doubleFlag | ||
}, _this.getCurrentStore().getPosition(), { | ||
}, _this.getCurrentStore().getPosition()), { | ||
preventDefault: function () { | ||
@@ -814,3 +818,3 @@ e.preventDefault(); | ||
if (_this.pinchFlag || result.deltaX || result.deltaY) { | ||
var dragResult = _this.emit("drag", __assign({}, result, { | ||
var dragResult = _this.emit("drag", __assign(__assign({}, result), { | ||
isScroll: !!isScroll, | ||
@@ -852,3 +856,3 @@ inputEvent: e | ||
var clients = getEventClients(e); | ||
var clients = (e === null || e === void 0 ? void 0 : e.touches) ? getEventClients(e) : []; | ||
var clientsLength = clients.length; | ||
@@ -1060,5 +1064,5 @@ | ||
__proto.getCurrentEvent = function (inputEvent) { | ||
return __assign({ | ||
return __assign(__assign({ | ||
datas: this.datas | ||
}, this._getPosition(), { | ||
}, this._getPosition()), { | ||
movement: this.getMovement(), | ||
@@ -1124,7 +1128,7 @@ isDrag: this.isDrag, | ||
var result = this.emit("pinchStart", __assign({ | ||
var result = this.emit("pinchStart", __assign(__assign({ | ||
datas: this.datas, | ||
angle: store.getAngle(), | ||
touches: this.getCurrentStore().getPositions() | ||
}, store.getPosition(), { | ||
}, store.getPosition()), { | ||
inputEvent: e | ||
@@ -1145,3 +1149,3 @@ })); | ||
this.isPinch = true; | ||
this.emit("pinch", __assign({ | ||
this.emit("pinch", __assign(__assign({ | ||
datas: this.datas, | ||
@@ -1154,3 +1158,3 @@ movement: this.getMovement(clients), | ||
distance: store.getDistance(clients) | ||
}, store.getPosition(clients), { | ||
}, store.getPosition(clients)), { | ||
inputEvent: e | ||
@@ -1169,7 +1173,7 @@ })); | ||
var store = this.getCurrentStore(); | ||
this.emit("pinchEnd", __assign({ | ||
this.emit("pinchEnd", __assign(__assign({ | ||
datas: this.datas, | ||
isPinch: isPinch, | ||
touches: store.getPositions() | ||
}, store.getPosition(), { | ||
}, store.getPosition()), { | ||
inputEvent: e | ||
@@ -1198,5 +1202,5 @@ })); | ||
return __assign({ | ||
return __assign(__assign({ | ||
datas: this.datas | ||
}, position, { | ||
}, position), { | ||
movement: this.getMovement(clients), | ||
@@ -1227,3 +1231,3 @@ isDrag: this.isDrag, | ||
return __assign({}, position, { | ||
return __assign(__assign({}, position), { | ||
distX: distX, | ||
@@ -1230,0 +1234,0 @@ distY: distY |
@@ -7,5 +7,5 @@ /* | ||
repository: git+https://github.com/daybrush/gesto.git | ||
version: 1.8.0 | ||
version: 1.8.1 | ||
*/ | ||
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(t=t||self).Gesto=n()}(this,function(){"use strict";var e=function(t,n){return(e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,n){t.__proto__=n}||function(t,n){for(var i in n)n.hasOwnProperty(i)&&(t[i]=n[i])})(t,n)};var D=function(){return(D=Object.assign||function(t){for(var n,i=1,e=arguments.length;i<e;i++)for(var r in n=arguments[i])Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r]);return t}).apply(this,arguments)};function i(t){return function(t,n){var i=n[0]-t[0],e=n[1]-t[1],r=Math.atan2(e,i);return 0<=r?r:r+2*Math.PI}([t[0].clientX,t[0].clientY],[t[1].clientX,t[1].clientY])/Math.PI*180}function C(t){return t.touches?function(t){for(var n=Math.min(t.length,2),i=[],e=0;e<n;++e)i.push(s(t[e]));return i}(t.touches):[s(t)]}function o(t,n,i){var e=i.length,r=f(t,e),o=r.clientX,s=r.clientY,a=r.originalClientX,c=r.originalClientY,u=f(n,e),l=u.clientX,h=u.clientY,g=f(i,e);return{clientX:a,clientY:c,deltaX:o-l,deltaY:s-h,distX:o-g.clientX,distY:s-g.clientY}}function r(t){return Math.sqrt(Math.pow(t[0].clientX-t[1].clientX,2)+Math.pow(t[0].clientY-t[1].clientY,2))}function s(t){return{clientX:t.clientX,clientY:t.clientY}}function f(t,n){void 0===n&&(n=t.length);for(var i={clientX:0,clientY:0,originalClientX:0,originalClientY:0},e=0;e<n;++e){var r=t[e];i.originalClientX+="originalClientX"in r?r.originalClientX:r.clientX,i.originalClientY+="originalClientY"in r?r.originalClientY:r.clientY,i.clientX+=r.clientX,i.clientY+=r.clientY}return n?{clientX:i.clientX/n,clientY:i.clientY/n,originalClientX:i.originalClientX/n,originalClientY:i.originalClientY/n}:i}function a(t){return t&&"object"==typeof t}function S(){return Date.now?Date.now():(new Date).getTime()}function E(t,n,i,e){t.addEventListener(n,i,e)}function P(t,n,i){t.removeEventListener(n,i)}var c=function(){return(c=Object.assign||function(t){for(var n,i=1,e=arguments.length;i<e;i++)for(var r in n=arguments[i])Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r]);return t}).apply(this,arguments)};var t=function(){function t(){this._events={}}var n=t.prototype;return n.on=function(t,n){if(a(t))for(var i in t)this.on(i,t[i]);else this._addEvent(t,n,{});return this},n.off=function(t,n){if(t)if(a(t))for(var i in t)this.off(i);else if(n){var e=this._events[t];if(e){var r=function(t,n,i){void 0===i&&(i=-1);for(var e=t.length,r=0;r<e;++r)if(n(t[r],r,t))return r;return i}(e,function(t){return t.listener===n});-1<r&&e.splice(r,1)}}else this._events[t]=[];else this._events={};return this},n.once=function(n,t){var i=this;return t&&this._addEvent(n,t,{once:!0}),new Promise(function(t){i._addEvent(n,t,{once:!0})})},n.emit=function(n,i){var e=this;void 0===i&&(i={});var t=this._events[n];if(!n||!t)return!0;var r=!1;return i.eventType=n,i.stop=function(){r=!0},i.currentTarget=this,function(){for(var t=0,n=0,i=arguments.length;n<i;n++)t+=arguments[n].length;var e=Array(t),r=0;for(n=0;n<i;n++)for(var o=arguments[n],s=0,a=o.length;s<a;s++,r++)e[r]=o[s];return e}(t).forEach(function(t){t.listener(i),t.once&&e.off(n,t.listener)}),!r},n.trigger=function(t,n){return void 0===n&&(n={}),this.emit(t,n)},n._addEvent=function(t,n,i){var e=this._events;e[t]=e[t]||[],e[t].push(c({listener:n},i))},t}(),X=function(){function t(t){this.prevClients=[],this.startClients=[],this.movement=0,this.length=0,this.startClients=t,this.prevClients=t,this.length=t.length}var n=t.prototype;return n.getAngle=function(t){return void 0===t&&(t=this.prevClients),i(t)},n.getRotation=function(t){return void 0===t&&(t=this.prevClients),i(t)-i(this.startClients)},n.getPosition=function(t,n){void 0===t&&(t=this.prevClients);var i=o(t||this.prevClients,this.prevClients,this.startClients),e=i.deltaX,r=i.deltaY;return this.movement+=Math.sqrt(e*e+r*r),this.prevClients=t,i},n.getPositions=function(i){void 0===i&&(i=this.prevClients);var e=this.prevClients;return this.startClients.map(function(t,n){return o([i[n]],[e[n]],[t])})},n.getMovement=function(t){var n=this.movement;if(!t)return n;var i=f(t,this.length),e=f(this.prevClients,this.length),r=i.clientX-e.clientX,o=i.clientY-e.clientY;return Math.sqrt(r*r+o*o)+n},n.getDistance=function(t){return void 0===t&&(t=this.prevClients),r(t)},n.getScale=function(t){return void 0===t&&(t=this.prevClients),r(t)/r(this.startClients)},n.move=function(n,i){this.startClients.forEach(function(t){t.clientX-=n,t.clientY-=i})},t}(),Y=["textarea","input"],n=function(c){function t(t,n){void 0===n&&(n={});var m=c.call(this)||this;m.options={},m.flag=!1,m.pinchFlag=!1,m.datas={},m.isDrag=!1,m.isPinch=!1,m.isMouse=!1,m.isTouch=!1,m.clientStores=[],m.targets=[],m.prevTime=0,m.doubleFlag=!1,m._dragFlag=!1,m.onDragStart=function(t,n){if(void 0===n&&(n=!0),m.flag||!1!==t.cancelable){var i=m.options,e=i.container,r=i.pinchOutside,o=i.preventRightClick,s=i.preventDefault,a=i.checkInput,c=m.isTouch,u=!m.flag;if(u){var l=document.activeElement,h=t.target,g=h.tagName.toLowerCase(),f=-1<Y.indexOf(g),v=h.isContentEditable;if(f||v){if(a||l===h)return!1;if(l&&v&&l.isContentEditable&&l.contains(h))return!1}else if((s||"touchstart"===t.type)&&l){var d=l.tagName;(l.isContentEditable||-1<Y.indexOf(d))&&l.blur()}if(m.clientStores=[new X(C(t))],m.flag=!0,m.isDrag=!1,m._dragFlag=!0,m.datas={},o&&(3===t.which||2===t.button))return m.initDrag(),!1;m.doubleFlag=S()-m.prevTime<200,!1===m.emit("dragStart",D({datas:m.datas,inputEvent:t,isTrusted:n,isDouble:m.doubleFlag},m.getCurrentStore().getPosition(),{preventDefault:function(){t.preventDefault()},preventDrag:function(){m._dragFlag=!1}}))&&m.initDrag(),m.flag&&s&&t.preventDefault()}if(!m.flag)return!1;var p=0;if(u&&c&&r&&(p=setTimeout(function(){E(e,"touchstart",m.onDragStart,{passive:!1})})),!u&&c&&r&&P(e,"touchstart",m.onDragStart),m.flag&&function(t){return t.touches&&2<=t.touches.length}(t)){if(clearTimeout(p),u&&t.touches.length!==t.changedTouches.length)return;m.pinchFlag||m.onPinchStart(t)}}},m.onDrag=function(t,n){if(m.flag){var i=C(t),e=m.moveClients(i,t,!1);if(m._dragFlag){if(m.pinchFlag||e.deltaX||e.deltaY)if(!1===m.emit("drag",D({},e,{isScroll:!!n,inputEvent:t})))return void m.stop();m.pinchFlag&&m.onPinch(t,i)}m.getCurrentStore().getPosition(i,!0)}},m.onDragEnd=function(t){if(m.flag){var n=m.options,i=n.pinchOutside,e=n.container;m.isTouch&&i&&P(e,"touchstart",m.onDragStart),m.pinchFlag&&m.onPinchEnd(t);var r=C(t);0!==r.length&&m.options.keepDragging?m._addStore(new X(r)):m.flag=!1;var o=m._getPosition(),s=S(),a=!m.isDrag&&m.doubleFlag;m.prevTime=m.isDrag||a?0:s,m.flag||(m.emit("dragEnd",D({datas:m.datas,isDouble:a,isDrag:m.isDrag,isClick:!m.isDrag,inputEvent:t},o)),m.clientStores=[])}},m.onBlur=function(){m.onDragEnd()};var i=[].concat(t);m.options=D({checkInput:!1,container:1<i.length?window:i[0],preventRightClick:!0,preventDefault:!0,checkWindowBlur:!1,keepDragging:!1,pinchThreshold:0,events:["touch","mouse"]},n);var e=m.options,r=e.container,o=e.events,s=e.checkWindowBlur;if(m.isTouch=-1<o.indexOf("touch"),m.isMouse=-1<o.indexOf("mouse"),m.targets=i,m.isMouse&&(i.forEach(function(t){E(t,"mousedown",m.onDragStart)}),E(r,"mousemove",m.onDrag),E(r,"mouseup",m.onDragEnd),E(r,"contextmenu",m.onDragEnd)),s&&E(window,"blur",m.onBlur),m.isTouch){var a={passive:!1};i.forEach(function(t){E(t,"touchstart",m.onDragStart,a)}),E(r,"touchmove",m.onDrag,a),E(r,"touchend",m.onDragEnd,a),E(r,"touchcancel",m.onDragEnd,a)}return m}!function(t,n){function i(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(i.prototype=n.prototype,new i)}(t,c);var n=t.prototype;return n.stop=function(){this.isDrag=!1,this.flag=!1,this.clientStores=[],this.datas={}},n.getMovement=function(t){return this.getCurrentStore().getMovement(t)+this.clientStores.slice(1).reduce(function(t,n){return t+n.movement},0)},n.isDragging=function(){return this.isDrag},n.isFlag=function(){return this.flag},n.isPinchFlag=function(){return this.pinchFlag},n.isDoubleFlag=function(){return this.doubleFlag},n.isPinching=function(){return this.isPinch},n.scrollBy=function(t,n,i,e){void 0===e&&(e=!0),this.flag&&(this.clientStores[0].move(t,n),e&&this.onDrag(i,!0))},n.move=function(t,n){var e=t[0],r=t[1],i=this.getCurrentStore().prevClients;return this.moveClients(i.map(function(t){var n=t.clientX,i=t.clientY;return{clientX:n+e,clientY:i+r,originalClientX:n,originalClientY:i}}),n,!0)},n.triggerDragStart=function(t){this.onDragStart(t,!1)},n.setEventDatas=function(t){var n=this.datas;for(var i in t)n[i]=t[i];return this},n.getCurrentEvent=function(t){return D({datas:this.datas},this._getPosition(),{movement:this.getMovement(),isDrag:this.isDrag,isPinch:this.isPinch,isScroll:!1,inputEvent:t})},n.getEventDatas=function(){return this.datas},n.unset=function(){var n=this,t=this.targets,i=this.options.container;this.off(),P(window,"blur",this.onBlur),this.isMouse&&(t.forEach(function(t){P(t,"mousedown",n.onDragStart)}),P(i,"mousemove",this.onDrag),P(i,"mouseup",this.onDragEnd),P(i,"contextmenu",this.onDragEnd)),this.isTouch&&(t.forEach(function(t){P(t,"touchstart",n.onDragStart)}),P(i,"touchstart",this.onDragStart),P(i,"touchmove",this.onDrag),P(i,"touchend",this.onDragEnd),P(i,"touchcancel",this.onDragEnd))},n.onPinchStart=function(t){var n=this.options.pinchThreshold;if(!(this.isDrag&&this.getMovement()>n)){var i=new X(C(t));this.pinchFlag=!0,this._addStore(i),!1===this.emit("pinchStart",D({datas:this.datas,angle:i.getAngle(),touches:this.getCurrentStore().getPositions()},i.getPosition(),{inputEvent:t}))&&(this.pinchFlag=!1)}},n.onPinch=function(t,n){if(this.flag&&this.pinchFlag&&!(n.length<2)){var i=this.getCurrentStore();this.isPinch=!0,this.emit("pinch",D({datas:this.datas,movement:this.getMovement(n),angle:i.getAngle(n),rotation:i.getRotation(n),touches:i.getPositions(n),scale:i.getScale(n),distance:i.getDistance(n)},i.getPosition(n),{inputEvent:t}))}},n.onPinchEnd=function(t){if(this.pinchFlag){var n=this.isPinch;this.isPinch=!1,this.pinchFlag=!1;var i=this.getCurrentStore();this.emit("pinchEnd",D({datas:this.datas,isPinch:n,touches:i.getPositions()},i.getPosition(),{inputEvent:t}))}},n.initDrag=function(){this.clientStores=[],this.pinchFlag=!1,this.doubleFlag=!1,this.prevTime=0,this.flag=!1},n.getCurrentStore=function(){return this.clientStores[0]},n.moveClients=function(t,n,i){var e=this._getPosition(t,i);return(e.deltaX||e.deltaY)&&(this.isDrag=!0),D({datas:this.datas},e,{movement:this.getMovement(t),isDrag:this.isDrag,isPinch:this.isPinch,isScroll:!1,inputEvent:n})},n._addStore=function(t){this.clientStores.splice(0,0,t)},n._getPosition=function(t,n){var i=this.getCurrentStore().getPosition(t,n),e=this.clientStores.slice(1).reduce(function(t,n){var i=n.getPosition();return t.distX+=i.distX,t.distY+=i.distY,t},i),r=e.distX,o=e.distY;return D({},i,{distX:r,distY:o})},t}(t),u={default:n};for(var l in u)n[l]=u[l];return n}); | ||
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(t=t||self).Gesto=n()}(this,function(){"use strict";var e=function(t,n){return(e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,n){t.__proto__=n}||function(t,n){for(var i in n)n.hasOwnProperty(i)&&(t[i]=n[i])})(t,n)};var D=function(){return(D=Object.assign||function(t){for(var n,i=1,e=arguments.length;i<e;i++)for(var r in n=arguments[i])Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r]);return t}).apply(this,arguments)};function i(t){return function(t,n){var i=n[0]-t[0],e=n[1]-t[1],r=Math.atan2(e,i);return 0<=r?r:r+2*Math.PI}([t[0].clientX,t[0].clientY],[t[1].clientX,t[1].clientY])/Math.PI*180}function C(t){return t?t.touches?function(t){for(var n=Math.min(t.length,2),i=[],e=0;e<n;++e)i.push(s(t[e]));return i}(t.touches):[s(t)]:[]}function o(t,n,i){var e=i.length,r=f(t,e),o=r.clientX,s=r.clientY,a=r.originalClientX,c=r.originalClientY,u=f(n,e),l=u.clientX,h=u.clientY,g=f(i,e);return{clientX:a,clientY:c,deltaX:o-l,deltaY:s-h,distX:o-g.clientX,distY:s-g.clientY}}function r(t){return Math.sqrt(Math.pow(t[0].clientX-t[1].clientX,2)+Math.pow(t[0].clientY-t[1].clientY,2))}function s(t){return{clientX:t.clientX,clientY:t.clientY}}function f(t,n){void 0===n&&(n=t.length);for(var i={clientX:0,clientY:0,originalClientX:0,originalClientY:0},e=0;e<n;++e){var r=t[e];i.originalClientX+="originalClientX"in r?r.originalClientX:r.clientX,i.originalClientY+="originalClientY"in r?r.originalClientY:r.clientY,i.clientX+=r.clientX,i.clientY+=r.clientY}return n?{clientX:i.clientX/n,clientY:i.clientY/n,originalClientX:i.originalClientX/n,originalClientY:i.originalClientY/n}:i}function a(t){return t&&"object"==typeof t}function S(){return Date.now?Date.now():(new Date).getTime()}function E(t,n,i,e){t.addEventListener(n,i,e)}function P(t,n,i){t.removeEventListener(n,i)}var c=function(){return(c=Object.assign||function(t){for(var n,i=1,e=arguments.length;i<e;i++)for(var r in n=arguments[i])Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r]);return t}).apply(this,arguments)};var t=function(){function t(){this._events={}}var n=t.prototype;return n.on=function(t,n){if(a(t))for(var i in t)this.on(i,t[i]);else this._addEvent(t,n,{});return this},n.off=function(t,n){if(t)if(a(t))for(var i in t)this.off(i);else if(n){var e=this._events[t];if(e){var r=function(t,n,i){void 0===i&&(i=-1);for(var e=t.length,r=0;r<e;++r)if(n(t[r],r,t))return r;return i}(e,function(t){return t.listener===n});-1<r&&e.splice(r,1)}}else this._events[t]=[];else this._events={};return this},n.once=function(n,t){var i=this;return t&&this._addEvent(n,t,{once:!0}),new Promise(function(t){i._addEvent(n,t,{once:!0})})},n.emit=function(n,i){var e=this;void 0===i&&(i={});var t=this._events[n];if(!n||!t)return!0;var r=!1;return i.eventType=n,i.stop=function(){r=!0},i.currentTarget=this,function(){for(var t=0,n=0,i=arguments.length;n<i;n++)t+=arguments[n].length;var e=Array(t),r=0;for(n=0;n<i;n++)for(var o=arguments[n],s=0,a=o.length;s<a;s++,r++)e[r]=o[s];return e}(t).forEach(function(t){t.listener(i),t.once&&e.off(n,t.listener)}),!r},n.trigger=function(t,n){return void 0===n&&(n={}),this.emit(t,n)},n._addEvent=function(t,n,i){var e=this._events;e[t]=e[t]||[],e[t].push(c({listener:n},i))},t}(),X=function(){function t(t){this.prevClients=[],this.startClients=[],this.movement=0,this.length=0,this.startClients=t,this.prevClients=t,this.length=t.length}var n=t.prototype;return n.getAngle=function(t){return void 0===t&&(t=this.prevClients),i(t)},n.getRotation=function(t){return void 0===t&&(t=this.prevClients),i(t)-i(this.startClients)},n.getPosition=function(t,n){void 0===t&&(t=this.prevClients);var i=o(t||this.prevClients,this.prevClients,this.startClients),e=i.deltaX,r=i.deltaY;return this.movement+=Math.sqrt(e*e+r*r),this.prevClients=t,i},n.getPositions=function(i){void 0===i&&(i=this.prevClients);var e=this.prevClients;return this.startClients.map(function(t,n){return o([i[n]],[e[n]],[t])})},n.getMovement=function(t){var n=this.movement;if(!t)return n;var i=f(t,this.length),e=f(this.prevClients,this.length),r=i.clientX-e.clientX,o=i.clientY-e.clientY;return Math.sqrt(r*r+o*o)+n},n.getDistance=function(t){return void 0===t&&(t=this.prevClients),r(t)},n.getScale=function(t){return void 0===t&&(t=this.prevClients),r(t)/r(this.startClients)},n.move=function(n,i){this.startClients.forEach(function(t){t.clientX-=n,t.clientY-=i})},t}(),Y=["textarea","input"],n=function(c){function t(t,n){void 0===n&&(n={});var m=c.call(this)||this;m.options={},m.flag=!1,m.pinchFlag=!1,m.datas={},m.isDrag=!1,m.isPinch=!1,m.isMouse=!1,m.isTouch=!1,m.clientStores=[],m.targets=[],m.prevTime=0,m.doubleFlag=!1,m._dragFlag=!1,m.onDragStart=function(t,n){if(void 0===n&&(n=!0),m.flag||!1!==t.cancelable){var i=m.options,e=i.container,r=i.pinchOutside,o=i.preventRightClick,s=i.preventDefault,a=i.checkInput,c=m.isTouch,u=!m.flag;if(u){var l=document.activeElement,h=t.target,g=h.tagName.toLowerCase(),f=-1<Y.indexOf(g),v=h.isContentEditable;if(f||v){if(a||l===h)return!1;if(l&&v&&l.isContentEditable&&l.contains(h))return!1}else if((s||"touchstart"===t.type)&&l){var d=l.tagName;(l.isContentEditable||-1<Y.indexOf(d))&&l.blur()}if(m.clientStores=[new X(C(t))],m.flag=!0,m.isDrag=!1,m._dragFlag=!0,m.datas={},o&&(3===t.which||2===t.button))return m.initDrag(),!1;m.doubleFlag=S()-m.prevTime<200,!1===m.emit("dragStart",D(D({datas:m.datas,inputEvent:t,isTrusted:n,isDouble:m.doubleFlag},m.getCurrentStore().getPosition()),{preventDefault:function(){t.preventDefault()},preventDrag:function(){m._dragFlag=!1}}))&&m.initDrag(),m.flag&&s&&t.preventDefault()}if(!m.flag)return!1;var p=0;if(u&&c&&r&&(p=setTimeout(function(){E(e,"touchstart",m.onDragStart,{passive:!1})})),!u&&c&&r&&P(e,"touchstart",m.onDragStart),m.flag&&function(t){return t.touches&&2<=t.touches.length}(t)){if(clearTimeout(p),u&&t.touches.length!==t.changedTouches.length)return;m.pinchFlag||m.onPinchStart(t)}}},m.onDrag=function(t,n){if(m.flag){var i=C(t),e=m.moveClients(i,t,!1);if(m._dragFlag){if(m.pinchFlag||e.deltaX||e.deltaY)if(!1===m.emit("drag",D(D({},e),{isScroll:!!n,inputEvent:t})))return void m.stop();m.pinchFlag&&m.onPinch(t,i)}m.getCurrentStore().getPosition(i,!0)}},m.onDragEnd=function(t){if(m.flag){var n=m.options,i=n.pinchOutside,e=n.container;m.isTouch&&i&&P(e,"touchstart",m.onDragStart),m.pinchFlag&&m.onPinchEnd(t);var r=(null==t?void 0:t.touches)?C(t):[];0!==r.length&&m.options.keepDragging?m._addStore(new X(r)):m.flag=!1;var o=m._getPosition(),s=S(),a=!m.isDrag&&m.doubleFlag;m.prevTime=m.isDrag||a?0:s,m.flag||(m.emit("dragEnd",D({datas:m.datas,isDouble:a,isDrag:m.isDrag,isClick:!m.isDrag,inputEvent:t},o)),m.clientStores=[])}},m.onBlur=function(){m.onDragEnd()};var i=[].concat(t);m.options=D({checkInput:!1,container:1<i.length?window:i[0],preventRightClick:!0,preventDefault:!0,checkWindowBlur:!1,keepDragging:!1,pinchThreshold:0,events:["touch","mouse"]},n);var e=m.options,r=e.container,o=e.events,s=e.checkWindowBlur;if(m.isTouch=-1<o.indexOf("touch"),m.isMouse=-1<o.indexOf("mouse"),m.targets=i,m.isMouse&&(i.forEach(function(t){E(t,"mousedown",m.onDragStart)}),E(r,"mousemove",m.onDrag),E(r,"mouseup",m.onDragEnd),E(r,"contextmenu",m.onDragEnd)),s&&E(window,"blur",m.onBlur),m.isTouch){var a={passive:!1};i.forEach(function(t){E(t,"touchstart",m.onDragStart,a)}),E(r,"touchmove",m.onDrag,a),E(r,"touchend",m.onDragEnd,a),E(r,"touchcancel",m.onDragEnd,a)}return m}!function(t,n){function i(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(i.prototype=n.prototype,new i)}(t,c);var n=t.prototype;return n.stop=function(){this.isDrag=!1,this.flag=!1,this.clientStores=[],this.datas={}},n.getMovement=function(t){return this.getCurrentStore().getMovement(t)+this.clientStores.slice(1).reduce(function(t,n){return t+n.movement},0)},n.isDragging=function(){return this.isDrag},n.isFlag=function(){return this.flag},n.isPinchFlag=function(){return this.pinchFlag},n.isDoubleFlag=function(){return this.doubleFlag},n.isPinching=function(){return this.isPinch},n.scrollBy=function(t,n,i,e){void 0===e&&(e=!0),this.flag&&(this.clientStores[0].move(t,n),e&&this.onDrag(i,!0))},n.move=function(t,n){var e=t[0],r=t[1],i=this.getCurrentStore().prevClients;return this.moveClients(i.map(function(t){var n=t.clientX,i=t.clientY;return{clientX:n+e,clientY:i+r,originalClientX:n,originalClientY:i}}),n,!0)},n.triggerDragStart=function(t){this.onDragStart(t,!1)},n.setEventDatas=function(t){var n=this.datas;for(var i in t)n[i]=t[i];return this},n.getCurrentEvent=function(t){return D(D({datas:this.datas},this._getPosition()),{movement:this.getMovement(),isDrag:this.isDrag,isPinch:this.isPinch,isScroll:!1,inputEvent:t})},n.getEventDatas=function(){return this.datas},n.unset=function(){var n=this,t=this.targets,i=this.options.container;this.off(),P(window,"blur",this.onBlur),this.isMouse&&(t.forEach(function(t){P(t,"mousedown",n.onDragStart)}),P(i,"mousemove",this.onDrag),P(i,"mouseup",this.onDragEnd),P(i,"contextmenu",this.onDragEnd)),this.isTouch&&(t.forEach(function(t){P(t,"touchstart",n.onDragStart)}),P(i,"touchstart",this.onDragStart),P(i,"touchmove",this.onDrag),P(i,"touchend",this.onDragEnd),P(i,"touchcancel",this.onDragEnd))},n.onPinchStart=function(t){var n=this.options.pinchThreshold;if(!(this.isDrag&&this.getMovement()>n)){var i=new X(C(t));this.pinchFlag=!0,this._addStore(i),!1===this.emit("pinchStart",D(D({datas:this.datas,angle:i.getAngle(),touches:this.getCurrentStore().getPositions()},i.getPosition()),{inputEvent:t}))&&(this.pinchFlag=!1)}},n.onPinch=function(t,n){if(this.flag&&this.pinchFlag&&!(n.length<2)){var i=this.getCurrentStore();this.isPinch=!0,this.emit("pinch",D(D({datas:this.datas,movement:this.getMovement(n),angle:i.getAngle(n),rotation:i.getRotation(n),touches:i.getPositions(n),scale:i.getScale(n),distance:i.getDistance(n)},i.getPosition(n)),{inputEvent:t}))}},n.onPinchEnd=function(t){if(this.pinchFlag){var n=this.isPinch;this.isPinch=!1,this.pinchFlag=!1;var i=this.getCurrentStore();this.emit("pinchEnd",D(D({datas:this.datas,isPinch:n,touches:i.getPositions()},i.getPosition()),{inputEvent:t}))}},n.initDrag=function(){this.clientStores=[],this.pinchFlag=!1,this.doubleFlag=!1,this.prevTime=0,this.flag=!1},n.getCurrentStore=function(){return this.clientStores[0]},n.moveClients=function(t,n,i){var e=this._getPosition(t,i);return(e.deltaX||e.deltaY)&&(this.isDrag=!0),D(D({datas:this.datas},e),{movement:this.getMovement(t),isDrag:this.isDrag,isPinch:this.isPinch,isScroll:!1,inputEvent:n})},n._addStore=function(t){this.clientStores.splice(0,0,t)},n._getPosition=function(t,n){var i=this.getCurrentStore().getPosition(t,n),e=this.clientStores.slice(1).reduce(function(t,n){var i=n.getPosition();return t.distX+=i.distX,t.distY+=i.distY,t},i),r=e.distX,o=e.distY;return D(D({},i),{distX:r,distY:o})},t}(t),u={default:n};for(var l in u)n[l]=u[l];return n}); | ||
//# sourceMappingURL=gesto.min.js.map |
{ | ||
"name": "gesto", | ||
"version": "1.8.0", | ||
"version": "1.8.1", | ||
"description": "You can set up drag, pinch events in any browser.", | ||
@@ -48,3 +48,3 @@ "main": "./dist/gesto.cjs.js", | ||
"tslint": "^5.15.0", | ||
"typescript": "^3.4.2" | ||
"typescript": "^4.6.4" | ||
}, | ||
@@ -51,0 +51,0 @@ "dependencies": { |
@@ -340,3 +340,3 @@ import { Client, OnDrag, GestoOptions, GestoEvents } from "./types"; | ||
} | ||
const clients = getEventClients(e); | ||
const clients = e?.touches ? getEventClients(e) : []; | ||
const clientsLength = clients.length; | ||
@@ -343,0 +343,0 @@ |
@@ -26,3 +26,5 @@ import { Client, Position } from "./types"; | ||
export function getEventClients(e: any): Client[] { | ||
if (e.touches) { | ||
if (!e) { | ||
return []; | ||
} if (e.touches) { | ||
return getClients(e.touches); | ||
@@ -29,0 +31,0 @@ } else { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
279980
3561