Comparing version 1.11.0 to 1.11.1
@@ -19,2 +19,3 @@ import { Client, OnDrag, GestoOptions, GestoEvents } from "./types"; | ||
private _isMouseEvent; | ||
private _isSecondaryButton; | ||
constructor(targets: Array<Element | Window> | Element | Window, options?: GestoOptions); | ||
@@ -21,0 +22,0 @@ stop(): void; |
@@ -25,2 +25,3 @@ import { IObject } from "@daybrush/utils"; | ||
isMouseEvent: boolean; | ||
isSecondaryButton: boolean; | ||
isDouble: boolean; | ||
@@ -33,2 +34,3 @@ preventDefault: () => void; | ||
isMouseEvent: boolean; | ||
isSecondaryButton: boolean; | ||
isPinch: boolean; | ||
@@ -44,2 +46,3 @@ movement: number; | ||
isMouseEvent: boolean; | ||
isSecondaryButton: boolean; | ||
isDouble: boolean; | ||
@@ -46,0 +49,0 @@ datas: IObject<any>; |
@@ -7,3 +7,3 @@ /* | ||
repository: git+https://github.com/daybrush/gesto.git | ||
version: 1.11.0 | ||
version: 1.11.1 | ||
*/ | ||
@@ -303,2 +303,3 @@ 'use strict'; | ||
_this._isMouseEvent = false; | ||
_this._isSecondaryButton = false; | ||
@@ -325,2 +326,3 @@ _this.onDragStart = function (e, isTrusted) { | ||
var isDragStart = !_this.flag; | ||
_this._isSecondaryButton = e.which === 3 || e.button === 2; | ||
@@ -374,2 +376,3 @@ if (preventWheelClick && (e.which === 2 || e.button === 1) || preventRightClick && (e.which === 3 || e.button === 2)) { | ||
isMouseEvent: _this._isMouseEvent, | ||
isSecondaryButton: _this._isSecondaryButton, | ||
isTrusted: isTrusted, | ||
@@ -507,2 +510,3 @@ isDouble: _this.doubleFlag | ||
isMouseEvent: _this._isMouseEvent, | ||
isSecondaryButton: _this._isSecondaryButton, | ||
inputEvent: e | ||
@@ -857,2 +861,3 @@ }, position)); | ||
isMouseEvent: this._isMouseEvent, | ||
isSecondaryButton: this._isSecondaryButton, | ||
inputEvent: inputEvent | ||
@@ -859,0 +864,0 @@ }); |
@@ -7,3 +7,3 @@ /* | ||
repository: git+https://github.com/daybrush/gesto.git | ||
version: 1.11.0 | ||
version: 1.11.1 | ||
*/ | ||
@@ -301,2 +301,3 @@ import EventEmitter from '@scena/event-emitter'; | ||
_this._isMouseEvent = false; | ||
_this._isSecondaryButton = false; | ||
@@ -323,2 +324,3 @@ _this.onDragStart = function (e, isTrusted) { | ||
var isDragStart = !_this.flag; | ||
_this._isSecondaryButton = e.which === 3 || e.button === 2; | ||
@@ -372,2 +374,3 @@ if (preventWheelClick && (e.which === 2 || e.button === 1) || preventRightClick && (e.which === 3 || e.button === 2)) { | ||
isMouseEvent: _this._isMouseEvent, | ||
isSecondaryButton: _this._isSecondaryButton, | ||
isTrusted: isTrusted, | ||
@@ -505,2 +508,3 @@ isDouble: _this.doubleFlag | ||
isMouseEvent: _this._isMouseEvent, | ||
isSecondaryButton: _this._isSecondaryButton, | ||
inputEvent: e | ||
@@ -855,2 +859,3 @@ }, position)); | ||
isMouseEvent: this._isMouseEvent, | ||
isSecondaryButton: this._isSecondaryButton, | ||
inputEvent: inputEvent | ||
@@ -857,0 +862,0 @@ }); |
@@ -7,3 +7,3 @@ /* | ||
repository: git+https://github.com/daybrush/gesto.git | ||
version: 1.11.0 | ||
version: 1.11.1 | ||
*/ | ||
@@ -699,2 +699,3 @@ (function (global, factory) { | ||
_this._isMouseEvent = false; | ||
_this._isSecondaryButton = false; | ||
@@ -721,2 +722,3 @@ _this.onDragStart = function (e, isTrusted) { | ||
var isDragStart = !_this.flag; | ||
_this._isSecondaryButton = e.which === 3 || e.button === 2; | ||
@@ -770,2 +772,3 @@ if (preventWheelClick && (e.which === 2 || e.button === 1) || preventRightClick && (e.which === 3 || e.button === 2)) { | ||
isMouseEvent: _this._isMouseEvent, | ||
isSecondaryButton: _this._isSecondaryButton, | ||
isTrusted: isTrusted, | ||
@@ -903,2 +906,3 @@ isDouble: _this.doubleFlag | ||
isMouseEvent: _this._isMouseEvent, | ||
isSecondaryButton: _this._isSecondaryButton, | ||
inputEvent: e | ||
@@ -1253,2 +1257,3 @@ }, position)); | ||
isMouseEvent: this._isMouseEvent, | ||
isSecondaryButton: this._isSecondaryButton, | ||
inputEvent: inputEvent | ||
@@ -1255,0 +1260,0 @@ }); |
@@ -7,5 +7,5 @@ /* | ||
repository: git+https://github.com/daybrush/gesto.git | ||
version: 1.11.0 | ||
version: 1.11.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 S=function(){return(S=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 _(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,l=f(n,e),u=l.clientX,h=l.clientY,g=f(i,e);return{clientX:a,clientY:c,deltaX:o-u,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 P(){return Date.now?Date.now():(new Date).getTime()}function X(t,n,i,e){t.addEventListener(n,i,e)}function Y(t,n,i,e){t.removeEventListener(n,i,e)}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}(),w=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}(),M=["textarea","input"],n=function(c){function t(t,n){void 0===n&&(n={});var E=c.call(this)||this;E.options={},E.flag=!1,E.pinchFlag=!1,E.datas={},E.isDrag=!1,E.isPinch=!1,E.isMouse=!1,E.isTouch=!1,E.clientStores=[],E.targets=[],E.prevTime=0,E.doubleFlag=!1,E._dragFlag=!1,E._isMouseEvent=!1,E.onDragStart=function(t,n){if(void 0===n&&(n=!0),E.flag||!1!==t.cancelable){var i=E.options,e=i.container,r=i.pinchOutside,o=i.preventWheelClick,s=i.preventRightClick,a=i.preventDefault,c=i.checkInput,l=i.preventClickEventOnDragStart,u=i.preventClickEventOnDrag,h=E.isTouch,g=!E.flag;if(o&&(2===t.which||1===t.button)||s&&(3===t.which||2===t.button))return E.initDrag(),!1;if(g){var f=document.activeElement,v=t.target,d=v.tagName.toLowerCase(),p=-1<M.indexOf(d),C=v.isContentEditable;if(p||C){if(c||f===v)return!1;if(f&&C&&f.isContentEditable&&f.contains(v))return!1}else if((a||"touchstart"===t.type)&&f){var m=f.tagName;(f.isContentEditable||-1<M.indexOf(m))&&f.blur()}(l||u)&&X(window,"click",E._onClick,!0),E.clientStores=[new w(_(t))],E.flag=!0,E.isDrag=!1,E._dragFlag=!0,E.datas={},E.doubleFlag=P()-E.prevTime<200,E._isMouseEvent=function(t){return t&&(-1<t.type.indexOf("mouse")||"button"in t||"which"in t)}(t),!1===E.emit("dragStart",S(S({datas:E.datas,inputEvent:t,isMouseEvent:E._isMouseEvent,isTrusted:n,isDouble:E.doubleFlag},E.getCurrentStore().getPosition()),{preventDefault:function(){t.preventDefault()},preventDrag:function(){E._dragFlag=!1}}))&&E.initDrag(),E.flag&&a&&t.preventDefault()}if(!E.flag)return!1;var D=0;if(g&&h&&r&&(D=setTimeout(function(){X(e,"touchstart",E.onDragStart,{passive:!1})})),!g&&h&&r&&Y(e,"touchstart",E.onDragStart),E.flag&&function(t){return t.touches&&2<=t.touches.length}(t)){if(clearTimeout(D),g&&t.touches.length!==t.changedTouches.length)return;E.pinchFlag||E.onPinchStart(t)}}},E.onDrag=function(t,n){if(E.flag){var i=_(t),e=E.moveClients(i,t,!1);if(E._dragFlag){if(E.pinchFlag||e.deltaX||e.deltaY)if(!1===E.emit("drag",S(S({},e),{isScroll:!!n,inputEvent:t})))return void E.stop();E.pinchFlag&&E.onPinch(t,i)}E.getCurrentStore().getPosition(i,!0)}},E.onDragEnd=function(t){if(E.flag){var n=E.options,i=n.pinchOutside,e=n.container,r=n.preventClickEventOnDrag,o=n.preventClickEventOnDragStart,s=E.isDrag;(r||o)&&requestAnimationFrame(function(){E._allowClickEvent()}),r&&!s&&E._allowClickEvent(),E.isTouch&&i&&Y(e,"touchstart",E.onDragStart),E.pinchFlag&&E.onPinchEnd(t);var a=(null==t?void 0:t.touches)?_(t):[];0!==a.length&&E.options.keepDragging?E._addStore(new w(a)):E.flag=!1;var c=E._getPosition(),l=P(),u=!s&&E.doubleFlag;E.prevTime=s||u?0:l,E.flag||(E.emit("dragEnd",S({datas:E.datas,isDouble:u,isDrag:s,isClick:!s,isMouseEvent:E._isMouseEvent,inputEvent:t},c)),E.clientStores=[])}},E.onBlur=function(){E.onDragEnd()},E._allowClickEvent=function(){Y(window,"click",E._onClick,!0)},E._onClick=function(t){t.stopPropagation(),t.preventDefault()},E._onContextMenu=function(t){E.options.preventRightClick?E.onDragEnd(t):t.preventDefault()};var i=[].concat(t);E.options=S({checkInput:!1,container:1<i.length?window:i[0],preventRightClick:!0,preventWheelClick:!0,preventClickEventOnDragStart:!1,preventClickEventOnDrag:!1,preventDefault:!0,checkWindowBlur:!1,keepDragging:!1,pinchThreshold:0,events:["touch","mouse"]},n);var e=E.options,r=e.container,o=e.events,s=e.checkWindowBlur;if(E.isTouch=-1<o.indexOf("touch"),E.isMouse=-1<o.indexOf("mouse"),E.targets=i,E.isMouse&&(i.forEach(function(t){X(t,"mousedown",E.onDragStart)}),X(r,"mousemove",E.onDrag),X(r,"mouseup",E.onDragEnd),X(r,"contextmenu",E._onContextMenu)),s&&X(window,"blur",E.onBlur),E.isTouch){var a={passive:!1};i.forEach(function(t){X(t,"touchstart",E.onDragStart,a)}),X(r,"touchmove",E.onDrag,a),X(r,"touchend",E.onDragEnd,a),X(r,"touchcancel",E.onDragEnd,a)}return E}!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 S(S({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(),Y(window,"blur",this.onBlur),this.isMouse&&(t.forEach(function(t){Y(t,"mousedown",n.onDragStart)}),Y(i,"mousemove",this.onDrag),Y(i,"mouseup",this.onDragEnd),Y(i,"contextmenu",this._onContextMenu)),this.isTouch&&(t.forEach(function(t){Y(t,"touchstart",n.onDragStart)}),Y(i,"touchstart",this.onDragStart),Y(i,"touchmove",this.onDrag),Y(i,"touchend",this.onDragEnd),Y(i,"touchcancel",this.onDragEnd))},n.onPinchStart=function(t){var n=this.options.pinchThreshold;if(!(this.isDrag&&this.getMovement()>n)){var i=new w(_(t));this.pinchFlag=!0,this._addStore(i),!1===this.emit("pinchStart",S(S({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",S(S({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",S(S({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),S(S({datas:this.datas},e),{movement:this.getMovement(t),isDrag:this.isDrag,isPinch:this.isPinch,isScroll:!1,isMouseEvent:this._isMouseEvent,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 S(S({},i),{distX:r,distY:o})},t}(t),l={default:n};for(var u in l)n[u]=l[u];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 S=function(){return(S=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 _(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 P(){return Date.now?Date.now():(new Date).getTime()}function X(t,n,i,e){t.addEventListener(n,i,e)}function Y(t,n,i,e){t.removeEventListener(n,i,e)}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}(),w=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 E=c.call(this)||this;E.options={},E.flag=!1,E.pinchFlag=!1,E.datas={},E.isDrag=!1,E.isPinch=!1,E.isMouse=!1,E.isTouch=!1,E.clientStores=[],E.targets=[],E.prevTime=0,E.doubleFlag=!1,E._dragFlag=!1,E._isMouseEvent=!1,E._isSecondaryButton=!1,E.onDragStart=function(t,n){if(void 0===n&&(n=!0),E.flag||!1!==t.cancelable){var i=E.options,e=i.container,r=i.pinchOutside,o=i.preventWheelClick,s=i.preventRightClick,a=i.preventDefault,c=i.checkInput,u=i.preventClickEventOnDragStart,l=i.preventClickEventOnDrag,h=E.isTouch,g=!E.flag;if(E._isSecondaryButton=3===t.which||2===t.button,o&&(2===t.which||1===t.button)||s&&(3===t.which||2===t.button))return E.initDrag(),!1;if(g){var f=document.activeElement,v=t.target,d=v.tagName.toLowerCase(),p=-1<y.indexOf(d),C=v.isContentEditable;if(p||C){if(c||f===v)return!1;if(f&&C&&f.isContentEditable&&f.contains(v))return!1}else if((a||"touchstart"===t.type)&&f){var m=f.tagName;(f.isContentEditable||-1<y.indexOf(m))&&f.blur()}(u||l)&&X(window,"click",E._onClick,!0),E.clientStores=[new w(_(t))],E.flag=!0,E.isDrag=!1,E._dragFlag=!0,E.datas={},E.doubleFlag=P()-E.prevTime<200,E._isMouseEvent=function(t){return t&&(-1<t.type.indexOf("mouse")||"button"in t||"which"in t)}(t),!1===E.emit("dragStart",S(S({datas:E.datas,inputEvent:t,isMouseEvent:E._isMouseEvent,isSecondaryButton:E._isSecondaryButton,isTrusted:n,isDouble:E.doubleFlag},E.getCurrentStore().getPosition()),{preventDefault:function(){t.preventDefault()},preventDrag:function(){E._dragFlag=!1}}))&&E.initDrag(),E.flag&&a&&t.preventDefault()}if(!E.flag)return!1;var D=0;if(g&&h&&r&&(D=setTimeout(function(){X(e,"touchstart",E.onDragStart,{passive:!1})})),!g&&h&&r&&Y(e,"touchstart",E.onDragStart),E.flag&&function(t){return t.touches&&2<=t.touches.length}(t)){if(clearTimeout(D),g&&t.touches.length!==t.changedTouches.length)return;E.pinchFlag||E.onPinchStart(t)}}},E.onDrag=function(t,n){if(E.flag){var i=_(t),e=E.moveClients(i,t,!1);if(E._dragFlag){if(E.pinchFlag||e.deltaX||e.deltaY)if(!1===E.emit("drag",S(S({},e),{isScroll:!!n,inputEvent:t})))return void E.stop();E.pinchFlag&&E.onPinch(t,i)}E.getCurrentStore().getPosition(i,!0)}},E.onDragEnd=function(t){if(E.flag){var n=E.options,i=n.pinchOutside,e=n.container,r=n.preventClickEventOnDrag,o=n.preventClickEventOnDragStart,s=E.isDrag;(r||o)&&requestAnimationFrame(function(){E._allowClickEvent()}),r&&!s&&E._allowClickEvent(),E.isTouch&&i&&Y(e,"touchstart",E.onDragStart),E.pinchFlag&&E.onPinchEnd(t);var a=(null==t?void 0:t.touches)?_(t):[];0!==a.length&&E.options.keepDragging?E._addStore(new w(a)):E.flag=!1;var c=E._getPosition(),u=P(),l=!s&&E.doubleFlag;E.prevTime=s||l?0:u,E.flag||(E.emit("dragEnd",S({datas:E.datas,isDouble:l,isDrag:s,isClick:!s,isMouseEvent:E._isMouseEvent,isSecondaryButton:E._isSecondaryButton,inputEvent:t},c)),E.clientStores=[])}},E.onBlur=function(){E.onDragEnd()},E._allowClickEvent=function(){Y(window,"click",E._onClick,!0)},E._onClick=function(t){t.stopPropagation(),t.preventDefault()},E._onContextMenu=function(t){E.options.preventRightClick?E.onDragEnd(t):t.preventDefault()};var i=[].concat(t);E.options=S({checkInput:!1,container:1<i.length?window:i[0],preventRightClick:!0,preventWheelClick:!0,preventClickEventOnDragStart:!1,preventClickEventOnDrag:!1,preventDefault:!0,checkWindowBlur:!1,keepDragging:!1,pinchThreshold:0,events:["touch","mouse"]},n);var e=E.options,r=e.container,o=e.events,s=e.checkWindowBlur;if(E.isTouch=-1<o.indexOf("touch"),E.isMouse=-1<o.indexOf("mouse"),E.targets=i,E.isMouse&&(i.forEach(function(t){X(t,"mousedown",E.onDragStart)}),X(r,"mousemove",E.onDrag),X(r,"mouseup",E.onDragEnd),X(r,"contextmenu",E._onContextMenu)),s&&X(window,"blur",E.onBlur),E.isTouch){var a={passive:!1};i.forEach(function(t){X(t,"touchstart",E.onDragStart,a)}),X(r,"touchmove",E.onDrag,a),X(r,"touchend",E.onDragEnd,a),X(r,"touchcancel",E.onDragEnd,a)}return E}!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 S(S({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(),Y(window,"blur",this.onBlur),this.isMouse&&(t.forEach(function(t){Y(t,"mousedown",n.onDragStart)}),Y(i,"mousemove",this.onDrag),Y(i,"mouseup",this.onDragEnd),Y(i,"contextmenu",this._onContextMenu)),this.isTouch&&(t.forEach(function(t){Y(t,"touchstart",n.onDragStart)}),Y(i,"touchstart",this.onDragStart),Y(i,"touchmove",this.onDrag),Y(i,"touchend",this.onDragEnd),Y(i,"touchcancel",this.onDragEnd))},n.onPinchStart=function(t){var n=this.options.pinchThreshold;if(!(this.isDrag&&this.getMovement()>n)){var i=new w(_(t));this.pinchFlag=!0,this._addStore(i),!1===this.emit("pinchStart",S(S({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",S(S({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",S(S({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),S(S({datas:this.datas},e),{movement:this.getMovement(t),isDrag:this.isDrag,isPinch:this.isPinch,isScroll:!1,isMouseEvent:this._isMouseEvent,isSecondaryButton:this._isSecondaryButton,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 S(S({},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.11.0", | ||
"version": "1.11.1", | ||
"description": "You can set up drag, pinch events in any browser.", | ||
@@ -5,0 +5,0 @@ "main": "./dist/gesto.cjs.js", |
@@ -28,2 +28,3 @@ import { Client, OnDrag, GestoOptions, GestoEvents } from "./types"; | ||
private _isMouseEvent = false; | ||
private _isSecondaryButton = false; | ||
@@ -235,2 +236,4 @@ /** | ||
this._isSecondaryButton = e.which === 3 || e.button === 2; | ||
if ( | ||
@@ -288,2 +291,3 @@ (preventWheelClick && (e.which === 2 || e.button === 1)) | ||
isMouseEvent: this._isMouseEvent, | ||
isSecondaryButton: this._isSecondaryButton, | ||
isTrusted, | ||
@@ -405,2 +409,3 @@ isDouble: this.doubleFlag, | ||
isMouseEvent: this._isMouseEvent, | ||
isSecondaryButton: this._isSecondaryButton, | ||
inputEvent: e, | ||
@@ -499,2 +504,3 @@ ...position, | ||
isMouseEvent: this._isMouseEvent, | ||
isSecondaryButton: this._isSecondaryButton, | ||
inputEvent, | ||
@@ -501,0 +507,0 @@ }; |
@@ -49,2 +49,3 @@ import { IObject } from "@daybrush/utils"; | ||
isMouseEvent: boolean; | ||
isSecondaryButton: boolean; | ||
isDouble: boolean; | ||
@@ -63,2 +64,3 @@ preventDefault: () => void; | ||
isMouseEvent: boolean; | ||
isSecondaryButton: boolean; | ||
isPinch: boolean; | ||
@@ -80,2 +82,3 @@ movement: number; | ||
isMouseEvent: boolean; | ||
isSecondaryButton: boolean; | ||
isDouble: boolean; | ||
@@ -82,0 +85,0 @@ datas: IObject<any>; |
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
304829
3809