Comparing version 1.9.0 to 1.10.0
@@ -18,2 +18,3 @@ import { Client, OnDrag, GestoOptions, GestoEvents } from "./types"; | ||
private _dragFlag; | ||
private _isMouseEvent; | ||
constructor(targets: Array<Element | Window> | Element | Window, options?: GestoOptions); | ||
@@ -20,0 +21,0 @@ stop(): void; |
@@ -24,2 +24,3 @@ import { IObject } from "@daybrush/utils"; | ||
isTrusted: any; | ||
isMouseEvent: boolean; | ||
isDouble: boolean; | ||
@@ -31,2 +32,3 @@ preventDefault: () => void; | ||
isDrag: boolean; | ||
isMouseEvent: boolean; | ||
isPinch: boolean; | ||
@@ -41,2 +43,3 @@ movement: number; | ||
isClick: boolean; | ||
isMouseEvent: boolean; | ||
isDouble: boolean; | ||
@@ -43,0 +46,0 @@ datas: IObject<any>; |
@@ -7,8 +7,8 @@ /* | ||
repository: git+https://github.com/daybrush/gesto.git | ||
version: 1.9.0 | ||
version: 1.10.0 | ||
*/ | ||
'use strict'; | ||
var EventEmitter = require('@scena/event-emitter'); | ||
var utils = require('@daybrush/utils'); | ||
var EventEmitter = require('@scena/event-emitter'); | ||
@@ -89,2 +89,5 @@ /*! ***************************************************************************** | ||
} | ||
function isMouseEvent(e) { | ||
return e && (e.type.indexOf("mouse") > -1 || "button" in e || "which" in e); | ||
} | ||
function getPosition(clients, prevClients, startClients) { | ||
@@ -300,2 +303,3 @@ var length = startClients.length; | ||
_this._dragFlag = false; | ||
_this._isMouseEvent = false; | ||
@@ -358,2 +362,3 @@ _this.onDragStart = function (e, isTrusted) { | ||
_this.doubleFlag = utils.now() - _this.prevTime < 200; | ||
_this._isMouseEvent = isMouseEvent(e); | ||
@@ -363,2 +368,3 @@ var result = _this.emit("dragStart", __assign(__assign({ | ||
inputEvent: e, | ||
isMouseEvent: _this._isMouseEvent, | ||
isTrusted: isTrusted, | ||
@@ -482,2 +488,3 @@ isDouble: _this.doubleFlag | ||
isClick: !_this.isDrag, | ||
isMouseEvent: _this._isMouseEvent, | ||
inputEvent: e | ||
@@ -810,2 +817,3 @@ }, position)); | ||
isScroll: false, | ||
isMouseEvent: this._isMouseEvent, | ||
inputEvent: inputEvent | ||
@@ -812,0 +820,0 @@ }); |
@@ -7,6 +7,6 @@ /* | ||
repository: git+https://github.com/daybrush/gesto.git | ||
version: 1.9.0 | ||
version: 1.10.0 | ||
*/ | ||
import EventEmitter from '@scena/event-emitter'; | ||
import { removeEvent, now, addEvent } from '@daybrush/utils'; | ||
import EventEmitter from '@scena/event-emitter'; | ||
@@ -87,2 +87,5 @@ /*! ***************************************************************************** | ||
} | ||
function isMouseEvent(e) { | ||
return e && (e.type.indexOf("mouse") > -1 || "button" in e || "which" in e); | ||
} | ||
function getPosition(clients, prevClients, startClients) { | ||
@@ -298,2 +301,3 @@ var length = startClients.length; | ||
_this._dragFlag = false; | ||
_this._isMouseEvent = false; | ||
@@ -356,2 +360,3 @@ _this.onDragStart = function (e, isTrusted) { | ||
_this.doubleFlag = now() - _this.prevTime < 200; | ||
_this._isMouseEvent = isMouseEvent(e); | ||
@@ -361,2 +366,3 @@ var result = _this.emit("dragStart", __assign(__assign({ | ||
inputEvent: e, | ||
isMouseEvent: _this._isMouseEvent, | ||
isTrusted: isTrusted, | ||
@@ -480,2 +486,3 @@ isDouble: _this.doubleFlag | ||
isClick: !_this.isDrag, | ||
isMouseEvent: _this._isMouseEvent, | ||
inputEvent: e | ||
@@ -808,2 +815,3 @@ }, position)); | ||
isScroll: false, | ||
isMouseEvent: this._isMouseEvent, | ||
inputEvent: inputEvent | ||
@@ -810,0 +818,0 @@ }); |
@@ -7,3 +7,3 @@ /* | ||
repository: git+https://github.com/daybrush/gesto.git | ||
version: 1.9.0 | ||
version: 1.10.0 | ||
*/ | ||
@@ -67,2 +67,109 @@ (function (global, factory) { | ||
function getRad(pos1, pos2) { | ||
var distX = pos2[0] - pos1[0]; | ||
var distY = pos2[1] - pos1[1]; | ||
var rad = Math.atan2(distY, distX); | ||
return rad >= 0 ? rad : rad + Math.PI * 2; | ||
} | ||
function getRotatiion(touches) { | ||
return getRad([touches[0].clientX, touches[0].clientY], [touches[1].clientX, touches[1].clientY]) / Math.PI * 180; | ||
} | ||
function isMultiTouch(e) { | ||
return e.touches && e.touches.length >= 2; | ||
} | ||
function getEventClients(e) { | ||
if (!e) { | ||
return []; | ||
} | ||
if (e.touches) { | ||
return getClients(e.touches); | ||
} else { | ||
return [getClient(e)]; | ||
} | ||
} | ||
function isMouseEvent(e) { | ||
return e && (e.type.indexOf("mouse") > -1 || "button" in e || "which" in e); | ||
} | ||
function getPosition(clients, prevClients, startClients) { | ||
var length = startClients.length; | ||
var _a = getAverageClient(clients, length), | ||
clientX = _a.clientX, | ||
clientY = _a.clientY, | ||
originalClientX = _a.originalClientX, | ||
originalClientY = _a.originalClientY; | ||
var _b = getAverageClient(prevClients, length), | ||
prevX = _b.clientX, | ||
prevY = _b.clientY; | ||
var _c = getAverageClient(startClients, length), | ||
startX = _c.clientX, | ||
startY = _c.clientY; | ||
var deltaX = clientX - prevX; | ||
var deltaY = clientY - prevY; | ||
var distX = clientX - startX; | ||
var distY = clientY - startY; | ||
return { | ||
clientX: originalClientX, | ||
clientY: originalClientY, | ||
deltaX: deltaX, | ||
deltaY: deltaY, | ||
distX: distX, | ||
distY: distY | ||
}; | ||
} | ||
function getDist(clients) { | ||
return Math.sqrt(Math.pow(clients[0].clientX - clients[1].clientX, 2) + Math.pow(clients[0].clientY - clients[1].clientY, 2)); | ||
} | ||
function getClients(touches) { | ||
var length = Math.min(touches.length, 2); | ||
var clients = []; | ||
for (var i = 0; i < length; ++i) { | ||
clients.push(getClient(touches[i])); | ||
} | ||
return clients; | ||
} | ||
function getClient(e) { | ||
return { | ||
clientX: e.clientX, | ||
clientY: e.clientY | ||
}; | ||
} | ||
function getAverageClient(clients, length) { | ||
if (length === void 0) { | ||
length = clients.length; | ||
} | ||
var sumClient = { | ||
clientX: 0, | ||
clientY: 0, | ||
originalClientX: 0, | ||
originalClientY: 0 | ||
}; | ||
for (var i = 0; i < length; ++i) { | ||
var client = clients[i]; | ||
sumClient.originalClientX += "originalClientX" in client ? client.originalClientX : client.clientX; | ||
sumClient.originalClientY += "originalClientY" in client ? client.originalClientY : client.clientY; | ||
sumClient.clientX += client.clientX; | ||
sumClient.clientY += client.clientY; | ||
} | ||
if (!length) { | ||
return sumClient; | ||
} | ||
return { | ||
clientX: sumClient.clientX / length, | ||
clientY: sumClient.clientY / length, | ||
originalClientX: sumClient.originalClientX / length, | ||
originalClientY: sumClient.originalClientY / length | ||
}; | ||
} | ||
/* | ||
@@ -181,106 +288,2 @@ Copyright (c) 2018 Daybrush | ||
function getRad(pos1, pos2) { | ||
var distX = pos2[0] - pos1[0]; | ||
var distY = pos2[1] - pos1[1]; | ||
var rad = Math.atan2(distY, distX); | ||
return rad >= 0 ? rad : rad + Math.PI * 2; | ||
} | ||
function getRotatiion(touches) { | ||
return getRad([touches[0].clientX, touches[0].clientY], [touches[1].clientX, touches[1].clientY]) / Math.PI * 180; | ||
} | ||
function isMultiTouch(e) { | ||
return e.touches && e.touches.length >= 2; | ||
} | ||
function getEventClients(e) { | ||
if (!e) { | ||
return []; | ||
} | ||
if (e.touches) { | ||
return getClients(e.touches); | ||
} else { | ||
return [getClient(e)]; | ||
} | ||
} | ||
function getPosition(clients, prevClients, startClients) { | ||
var length = startClients.length; | ||
var _a = getAverageClient(clients, length), | ||
clientX = _a.clientX, | ||
clientY = _a.clientY, | ||
originalClientX = _a.originalClientX, | ||
originalClientY = _a.originalClientY; | ||
var _b = getAverageClient(prevClients, length), | ||
prevX = _b.clientX, | ||
prevY = _b.clientY; | ||
var _c = getAverageClient(startClients, length), | ||
startX = _c.clientX, | ||
startY = _c.clientY; | ||
var deltaX = clientX - prevX; | ||
var deltaY = clientY - prevY; | ||
var distX = clientX - startX; | ||
var distY = clientY - startY; | ||
return { | ||
clientX: originalClientX, | ||
clientY: originalClientY, | ||
deltaX: deltaX, | ||
deltaY: deltaY, | ||
distX: distX, | ||
distY: distY | ||
}; | ||
} | ||
function getDist(clients) { | ||
return Math.sqrt(Math.pow(clients[0].clientX - clients[1].clientX, 2) + Math.pow(clients[0].clientY - clients[1].clientY, 2)); | ||
} | ||
function getClients(touches) { | ||
var length = Math.min(touches.length, 2); | ||
var clients = []; | ||
for (var i = 0; i < length; ++i) { | ||
clients.push(getClient(touches[i])); | ||
} | ||
return clients; | ||
} | ||
function getClient(e) { | ||
return { | ||
clientX: e.clientX, | ||
clientY: e.clientY | ||
}; | ||
} | ||
function getAverageClient(clients, length) { | ||
if (length === void 0) { | ||
length = clients.length; | ||
} | ||
var sumClient = { | ||
clientX: 0, | ||
clientY: 0, | ||
originalClientX: 0, | ||
originalClientY: 0 | ||
}; | ||
for (var i = 0; i < length; ++i) { | ||
var client = clients[i]; | ||
sumClient.originalClientX += "originalClientX" in client ? client.originalClientX : client.clientX; | ||
sumClient.originalClientY += "originalClientY" in client ? client.originalClientY : client.clientY; | ||
sumClient.clientX += client.clientX; | ||
sumClient.clientY += client.clientY; | ||
} | ||
if (!length) { | ||
return sumClient; | ||
} | ||
return { | ||
clientX: sumClient.clientX / length, | ||
clientY: sumClient.clientY / length, | ||
originalClientX: sumClient.originalClientX / length, | ||
originalClientY: sumClient.originalClientY / length | ||
}; | ||
} | ||
/* | ||
@@ -696,2 +699,3 @@ Copyright (c) 2019 Daybrush | ||
_this._dragFlag = false; | ||
_this._isMouseEvent = false; | ||
@@ -754,2 +758,3 @@ _this.onDragStart = function (e, isTrusted) { | ||
_this.doubleFlag = now() - _this.prevTime < 200; | ||
_this._isMouseEvent = isMouseEvent(e); | ||
@@ -759,2 +764,3 @@ var result = _this.emit("dragStart", __assign(__assign({ | ||
inputEvent: e, | ||
isMouseEvent: _this._isMouseEvent, | ||
isTrusted: isTrusted, | ||
@@ -878,2 +884,3 @@ isDouble: _this.doubleFlag | ||
isClick: !_this.isDrag, | ||
isMouseEvent: _this._isMouseEvent, | ||
inputEvent: e | ||
@@ -1206,2 +1213,3 @@ }, position)); | ||
isScroll: false, | ||
isMouseEvent: this._isMouseEvent, | ||
inputEvent: inputEvent | ||
@@ -1208,0 +1216,0 @@ }); |
@@ -7,5 +7,5 @@ /* | ||
repository: git+https://github.com/daybrush/gesto.git | ||
version: 1.9.0 | ||
version: 1.10.0 | ||
*/ | ||
!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 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)};function o(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)}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 X(t){return t?t.touches?function(t){for(var n=Math.min(t.length,2),i=[],e=0;e<n;++e)i.push(a(t[e]));return i}(t.touches):[a(t)]:[]}function s(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 a(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}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(o(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(o(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}(),Y=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=s(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 s([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}(),_=["textarea","input"],n=function(c){function t(t,n){void 0===n&&(n={});var D=c.call(this)||this;D.options={},D.flag=!1,D.pinchFlag=!1,D.datas={},D.isDrag=!1,D.isPinch=!1,D.isMouse=!1,D.isTouch=!1,D.clientStores=[],D.targets=[],D.prevTime=0,D.doubleFlag=!1,D._dragFlag=!1,D.onDragStart=function(t,n){if(void 0===n&&(n=!0),D.flag||!1!==t.cancelable){var i=D.options,e=i.container,r=i.pinchOutside,o=i.preventWheelClick,s=i.preventRightClick,a=i.preventDefault,c=i.checkInput,u=D.isTouch,l=!D.flag;if(o&&(2===t.which||1===t.button)||s&&(3===t.which||2===t.button))return D.initDrag(),!1;if(l){var h=document.activeElement,g=t.target,f=g.tagName.toLowerCase(),v=-1<_.indexOf(f),d=g.isContentEditable;if(v||d){if(c||h===g)return!1;if(h&&d&&h.isContentEditable&&h.contains(g))return!1}else if((a||"touchstart"===t.type)&&h){var p=h.tagName;(h.isContentEditable||-1<_.indexOf(p))&&h.blur()}D.clientStores=[new Y(X(t))],D.flag=!0,D.isDrag=!1,D._dragFlag=!0,D.datas={},D.doubleFlag=S()-D.prevTime<200,!1===D.emit("dragStart",C(C({datas:D.datas,inputEvent:t,isTrusted:n,isDouble:D.doubleFlag},D.getCurrentStore().getPosition()),{preventDefault:function(){t.preventDefault()},preventDrag:function(){D._dragFlag=!1}}))&&D.initDrag(),D.flag&&a&&t.preventDefault()}if(!D.flag)return!1;var m=0;if(l&&u&&r&&(m=setTimeout(function(){E(e,"touchstart",D.onDragStart,{passive:!1})})),!l&&u&&r&&P(e,"touchstart",D.onDragStart),D.flag&&function(t){return t.touches&&2<=t.touches.length}(t)){if(clearTimeout(m),l&&t.touches.length!==t.changedTouches.length)return;D.pinchFlag||D.onPinchStart(t)}}},D.onDrag=function(t,n){if(D.flag){var i=X(t),e=D.moveClients(i,t,!1);if(D._dragFlag){if(D.pinchFlag||e.deltaX||e.deltaY)if(!1===D.emit("drag",C(C({},e),{isScroll:!!n,inputEvent:t})))return void D.stop();D.pinchFlag&&D.onPinch(t,i)}D.getCurrentStore().getPosition(i,!0)}},D.onDragEnd=function(t){if(D.flag){var n=D.options,i=n.pinchOutside,e=n.container;D.isTouch&&i&&P(e,"touchstart",D.onDragStart),D.pinchFlag&&D.onPinchEnd(t);var r=(null==t?void 0:t.touches)?X(t):[];0!==r.length&&D.options.keepDragging?D._addStore(new Y(r)):D.flag=!1;var o=D._getPosition(),s=S(),a=!D.isDrag&&D.doubleFlag;D.prevTime=D.isDrag||a?0:s,D.flag||(D.emit("dragEnd",C({datas:D.datas,isDouble:a,isDrag:D.isDrag,isClick:!D.isDrag,inputEvent:t},o)),D.clientStores=[])}},D.onBlur=function(){D.onDragEnd()};var i=[].concat(t);D.options=C({checkInput:!1,container:1<i.length?window:i[0],preventRightClick:!0,preventWheelClick:!0,preventDefault:!0,checkWindowBlur:!1,keepDragging:!1,pinchThreshold:0,events:["touch","mouse"]},n);var e=D.options,r=e.container,o=e.events,s=e.checkWindowBlur;if(D.isTouch=-1<o.indexOf("touch"),D.isMouse=-1<o.indexOf("mouse"),D.targets=i,D.isMouse&&(i.forEach(function(t){E(t,"mousedown",D.onDragStart)}),E(r,"mousemove",D.onDrag),E(r,"mouseup",D.onDragEnd),E(r,"contextmenu",D.onDragEnd)),s&&E(window,"blur",D.onBlur),D.isTouch){var a={passive:!1};i.forEach(function(t){E(t,"touchstart",D.onDragStart,a)}),E(r,"touchmove",D.onDrag,a),E(r,"touchend",D.onDragEnd,a),E(r,"touchcancel",D.onDragEnd,a)}return D}!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 C(C({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 Y(X(t));this.pinchFlag=!0,this._addStore(i),!1===this.emit("pinchStart",C(C({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",C(C({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",C(C({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),C(C({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 C(C({},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 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)};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 E(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 P(t,n,i,e){t.addEventListener(n,i,e)}function X(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}(),Y=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}(),_=["textarea","input"],n=function(c){function t(t,n){void 0===n&&(n={});var D=c.call(this)||this;D.options={},D.flag=!1,D.pinchFlag=!1,D.datas={},D.isDrag=!1,D.isPinch=!1,D.isMouse=!1,D.isTouch=!1,D.clientStores=[],D.targets=[],D.prevTime=0,D.doubleFlag=!1,D._dragFlag=!1,D._isMouseEvent=!1,D.onDragStart=function(t,n){if(void 0===n&&(n=!0),D.flag||!1!==t.cancelable){var i=D.options,e=i.container,r=i.pinchOutside,o=i.preventWheelClick,s=i.preventRightClick,a=i.preventDefault,c=i.checkInput,u=D.isTouch,l=!D.flag;if(o&&(2===t.which||1===t.button)||s&&(3===t.which||2===t.button))return D.initDrag(),!1;if(l){var h=document.activeElement,g=t.target,f=g.tagName.toLowerCase(),v=-1<_.indexOf(f),d=g.isContentEditable;if(v||d){if(c||h===g)return!1;if(h&&d&&h.isContentEditable&&h.contains(g))return!1}else if((a||"touchstart"===t.type)&&h){var p=h.tagName;(h.isContentEditable||-1<_.indexOf(p))&&h.blur()}D.clientStores=[new Y(E(t))],D.flag=!0,D.isDrag=!1,D._dragFlag=!0,D.datas={},D.doubleFlag=S()-D.prevTime<200,D._isMouseEvent=function(t){return t&&(-1<t.type.indexOf("mouse")||"button"in t||"which"in t)}(t),!1===D.emit("dragStart",C(C({datas:D.datas,inputEvent:t,isMouseEvent:D._isMouseEvent,isTrusted:n,isDouble:D.doubleFlag},D.getCurrentStore().getPosition()),{preventDefault:function(){t.preventDefault()},preventDrag:function(){D._dragFlag=!1}}))&&D.initDrag(),D.flag&&a&&t.preventDefault()}if(!D.flag)return!1;var m=0;if(l&&u&&r&&(m=setTimeout(function(){P(e,"touchstart",D.onDragStart,{passive:!1})})),!l&&u&&r&&X(e,"touchstart",D.onDragStart),D.flag&&function(t){return t.touches&&2<=t.touches.length}(t)){if(clearTimeout(m),l&&t.touches.length!==t.changedTouches.length)return;D.pinchFlag||D.onPinchStart(t)}}},D.onDrag=function(t,n){if(D.flag){var i=E(t),e=D.moveClients(i,t,!1);if(D._dragFlag){if(D.pinchFlag||e.deltaX||e.deltaY)if(!1===D.emit("drag",C(C({},e),{isScroll:!!n,inputEvent:t})))return void D.stop();D.pinchFlag&&D.onPinch(t,i)}D.getCurrentStore().getPosition(i,!0)}},D.onDragEnd=function(t){if(D.flag){var n=D.options,i=n.pinchOutside,e=n.container;D.isTouch&&i&&X(e,"touchstart",D.onDragStart),D.pinchFlag&&D.onPinchEnd(t);var r=(null==t?void 0:t.touches)?E(t):[];0!==r.length&&D.options.keepDragging?D._addStore(new Y(r)):D.flag=!1;var o=D._getPosition(),s=S(),a=!D.isDrag&&D.doubleFlag;D.prevTime=D.isDrag||a?0:s,D.flag||(D.emit("dragEnd",C({datas:D.datas,isDouble:a,isDrag:D.isDrag,isClick:!D.isDrag,isMouseEvent:D._isMouseEvent,inputEvent:t},o)),D.clientStores=[])}},D.onBlur=function(){D.onDragEnd()};var i=[].concat(t);D.options=C({checkInput:!1,container:1<i.length?window:i[0],preventRightClick:!0,preventWheelClick:!0,preventDefault:!0,checkWindowBlur:!1,keepDragging:!1,pinchThreshold:0,events:["touch","mouse"]},n);var e=D.options,r=e.container,o=e.events,s=e.checkWindowBlur;if(D.isTouch=-1<o.indexOf("touch"),D.isMouse=-1<o.indexOf("mouse"),D.targets=i,D.isMouse&&(i.forEach(function(t){P(t,"mousedown",D.onDragStart)}),P(r,"mousemove",D.onDrag),P(r,"mouseup",D.onDragEnd),P(r,"contextmenu",D.onDragEnd)),s&&P(window,"blur",D.onBlur),D.isTouch){var a={passive:!1};i.forEach(function(t){P(t,"touchstart",D.onDragStart,a)}),P(r,"touchmove",D.onDrag,a),P(r,"touchend",D.onDragEnd,a),P(r,"touchcancel",D.onDragEnd,a)}return D}!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 C(C({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(),X(window,"blur",this.onBlur),this.isMouse&&(t.forEach(function(t){X(t,"mousedown",n.onDragStart)}),X(i,"mousemove",this.onDrag),X(i,"mouseup",this.onDragEnd),X(i,"contextmenu",this.onDragEnd)),this.isTouch&&(t.forEach(function(t){X(t,"touchstart",n.onDragStart)}),X(i,"touchstart",this.onDragStart),X(i,"touchmove",this.onDrag),X(i,"touchend",this.onDragEnd),X(i,"touchcancel",this.onDragEnd))},n.onPinchStart=function(t){var n=this.options.pinchThreshold;if(!(this.isDrag&&this.getMovement()>n)){var i=new Y(E(t));this.pinchFlag=!0,this._addStore(i),!1===this.emit("pinchStart",C(C({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",C(C({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",C(C({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),C(C({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 C(C({},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.9.0", | ||
"version": "1.10.0", | ||
"description": "You can set up drag, pinch events in any browser.", | ||
@@ -5,0 +5,0 @@ "main": "./dist/gesto.cjs.js", |
import { Client, OnDrag, GestoOptions, GestoEvents } from "./types"; | ||
import { | ||
getEventClients, isMultiTouch, | ||
getEventClients, isMouseEvent, isMultiTouch, | ||
} from "./utils"; | ||
@@ -27,2 +27,3 @@ import EventEmitter, { TargetParam } from "@scena/event-emitter"; | ||
private _dragFlag = false; | ||
private _isMouseEvent = false; | ||
@@ -272,2 +273,3 @@ /** | ||
this.doubleFlag = now() - this.prevTime < 200; | ||
this._isMouseEvent = isMouseEvent(e); | ||
@@ -277,2 +279,3 @@ const result = this.emit("dragStart", { | ||
inputEvent: e, | ||
isMouseEvent: this._isMouseEvent, | ||
isTrusted, | ||
@@ -377,2 +380,3 @@ isDouble: this.doubleFlag, | ||
isClick: !this.isDrag, | ||
isMouseEvent: this._isMouseEvent, | ||
inputEvent: e, | ||
@@ -470,2 +474,3 @@ ...position, | ||
isScroll: false, | ||
isMouseEvent: this._isMouseEvent, | ||
inputEvent, | ||
@@ -472,0 +477,0 @@ }; |
@@ -48,2 +48,3 @@ import { IObject } from "@daybrush/utils"; | ||
isTrusted: any; | ||
isMouseEvent: boolean; | ||
isDouble: boolean; | ||
@@ -61,2 +62,3 @@ preventDefault: () => void; | ||
isDrag: boolean; | ||
isMouseEvent: boolean; | ||
isPinch: boolean; | ||
@@ -77,2 +79,3 @@ movement: number; | ||
isClick: boolean; | ||
isMouseEvent: boolean; | ||
isDouble: boolean; | ||
@@ -79,0 +82,0 @@ datas: IObject<any>; |
@@ -35,3 +35,3 @@ import { Client, Position } from "./types"; | ||
export function isMouseEvent(e: any): e is MouseEvent { | ||
return isNumber(e.button); | ||
return e && (e.type.indexOf("mouse") > -1 || "button" in e || "which" in e); | ||
} | ||
@@ -38,0 +38,0 @@ export function getPosition(clients: Client[], prevClients: Client[], startClients: Client[]): Position { |
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
286942
3624