Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

gesto

Package Overview
Dependencies
Maintainers
1
Versions
49
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gesto - npm Package Compare versions

Comparing version 1.8.1 to 1.9.0

1

declaration/types.d.ts

@@ -69,2 +69,3 @@ import { IObject } from "@daybrush/utils";

preventRightClick?: boolean;
preventWheelClick?: boolean;
preventDefault?: boolean;

@@ -71,0 +72,0 @@ pinchThreshold?: number;

@@ -7,2 +7,3 @@ import { Client, Position } from "./types";

export declare function getEventClients(e: any): Client[];
export declare function isMouseEvent(e: any): e is MouseEvent;
export declare function getPosition(clients: Client[], prevClients: Client[], startClients: Client[]): Position;

@@ -9,0 +10,0 @@ export declare function getDist(clients: Client[]): number;

19

dist/gesto.cjs.js

@@ -7,8 +7,8 @@ /*

repository: git+https://github.com/daybrush/gesto.git
version: 1.8.1
version: 1.9.0
*/
'use strict';
var utils = require('@daybrush/utils');
var EventEmitter = require('@scena/event-emitter');
var utils = require('@daybrush/utils');

@@ -312,2 +312,3 @@ /*! *****************************************************************************

pinchOutside = _a.pinchOutside,
preventWheelClick = _a.preventWheelClick,
preventRightClick = _a.preventRightClick,

@@ -319,2 +320,8 @@ preventDefault = _a.preventDefault,

if (preventWheelClick && (e.which === 2 || e.button === 1) || preventRightClick && (e.which === 3 || e.button === 2)) {
_this.initDrag();
return false;
}
if (isDragStart) {

@@ -350,9 +357,2 @@ var activeElement = document.activeElement;

_this.datas = {};
if (preventRightClick && (e.which === 3 || e.button === 2)) {
_this.initDrag();
return false;
}
_this.doubleFlag = utils.now() - _this.prevTime < 200;

@@ -497,2 +497,3 @@

preventRightClick: true,
preventWheelClick: true,
preventDefault: true,

@@ -499,0 +500,0 @@ checkWindowBlur: false,

@@ -7,6 +7,6 @@ /*

repository: git+https://github.com/daybrush/gesto.git
version: 1.8.1
version: 1.9.0
*/
import { removeEvent, now, addEvent } from '@daybrush/utils';
import EventEmitter from '@scena/event-emitter';
import { removeEvent, now, addEvent } from '@daybrush/utils';

@@ -310,2 +310,3 @@ /*! *****************************************************************************

pinchOutside = _a.pinchOutside,
preventWheelClick = _a.preventWheelClick,
preventRightClick = _a.preventRightClick,

@@ -317,2 +318,8 @@ preventDefault = _a.preventDefault,

if (preventWheelClick && (e.which === 2 || e.button === 1) || preventRightClick && (e.which === 3 || e.button === 2)) {
_this.initDrag();
return false;
}
if (isDragStart) {

@@ -348,9 +355,2 @@ var activeElement = document.activeElement;

_this.datas = {};
if (preventRightClick && (e.which === 3 || e.button === 2)) {
_this.initDrag();
return false;
}
_this.doubleFlag = now() - _this.prevTime < 200;

@@ -495,2 +495,3 @@

preventRightClick: true,
preventWheelClick: true,
preventDefault: true,

@@ -497,0 +498,0 @@ checkWindowBlur: false,

@@ -7,3 +7,3 @@ /*

repository: git+https://github.com/daybrush/gesto.git
version: 1.8.1
version: 1.9.0
*/

@@ -67,106 +67,2 @@ (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 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
};
}
/*

@@ -285,2 +181,106 @@ 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
};
}
/*

@@ -709,2 +709,3 @@ Copyright (c) 2019 Daybrush

pinchOutside = _a.pinchOutside,
preventWheelClick = _a.preventWheelClick,
preventRightClick = _a.preventRightClick,

@@ -716,2 +717,8 @@ preventDefault = _a.preventDefault,

if (preventWheelClick && (e.which === 2 || e.button === 1) || preventRightClick && (e.which === 3 || e.button === 2)) {
_this.initDrag();
return false;
}
if (isDragStart) {

@@ -747,9 +754,2 @@ var activeElement = document.activeElement;

_this.datas = {};
if (preventRightClick && (e.which === 3 || e.button === 2)) {
_this.initDrag();
return false;
}
_this.doubleFlag = now() - _this.prevTime < 200;

@@ -894,2 +894,3 @@

preventRightClick: true,
preventWheelClick: true,
preventDefault: true,

@@ -896,0 +897,0 @@ checkWindowBlur: false,

@@ -7,5 +7,5 @@ /*

repository: git+https://github.com/daybrush/gesto.git
version: 1.8.1
version: 1.9.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 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});
!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});
//# sourceMappingURL=gesto.min.js.map
{
"name": "gesto",
"version": "1.8.1",
"version": "1.9.0",
"description": "You can set up drag, pinch events in any browser.",

@@ -5,0 +5,0 @@ "main": "./dist/gesto.cjs.js",

@@ -38,2 +38,3 @@ import { Client, OnDrag, GestoOptions, GestoEvents } from "./types";

preventRightClick: true,
preventWheelClick: true,
preventDefault: true,

@@ -218,6 +219,21 @@ checkWindowBlur: false,

}
const { container, pinchOutside, preventRightClick, preventDefault, checkInput } = this.options;
const {
container,
pinchOutside,
preventWheelClick,
preventRightClick,
preventDefault,
checkInput,
} = this.options;
const isTouch = this.isTouch;
const isDragStart = !this.flag;
if (
(preventWheelClick && (e.which === 2 || e.button === 1))
|| (preventRightClick && (e.which === 3 || e.button === 2))
) {
this.initDrag();
return false;
}
if (isDragStart) {

@@ -256,6 +272,2 @@ const activeElement = document.activeElement as HTMLElement;

if (preventRightClick && (e.which === 3 || e.button === 2)) {
this.initDrag();
return false;
}
this.doubleFlag = now() - this.prevTime < 200;

@@ -262,0 +274,0 @@

@@ -131,2 +131,6 @@ import { IObject } from "@daybrush/utils";

preventRightClick?: boolean;
/**
* @default true
*/
preventWheelClick?: boolean;
preventDefault?: boolean;

@@ -133,0 +137,0 @@ /**

import { Client, Position } from "./types";
import { IArrayFormat } from "@daybrush/utils";
import { IArrayFormat, isNumber } from "@daybrush/utils";

@@ -34,2 +34,5 @@ export function getRad(pos1: number[], pos2: number[]) {

}
export function isMouseEvent(e: any): e is MouseEvent {
return isNumber(e.button);
}
export function getPosition(clients: Client[], prevClients: Client[], startClients: Client[]): Position {

@@ -36,0 +39,0 @@ const length = startClients.length;

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc