Comparing version 1.16.0 to 1.17.0
@@ -186,3 +186,13 @@ import { IObject } from "@daybrush/utils"; | ||
pinchOutside?: boolean; | ||
/** | ||
* Prevent dragging of `input`, `textarea`, and contenteditable. | ||
* @default false | ||
*/ | ||
checkInput?: boolean; | ||
/** | ||
* Whether to drag the focused input | ||
* If `checkInput` is true, this option is not applied. | ||
* @default false | ||
*/ | ||
dragFocusedInput?: boolean; | ||
checkWindowBlur?: boolean; | ||
@@ -189,0 +199,0 @@ } |
@@ -7,3 +7,3 @@ /* | ||
repository: git+https://github.com/daybrush/gesto.git | ||
version: 1.16.0 | ||
version: 1.17.0 | ||
*/ | ||
@@ -247,3 +247,3 @@ 'use strict'; | ||
} | ||
var _a = _this.options, container = _a.container, pinchOutside = _a.pinchOutside, preventWheelClick = _a.preventWheelClick, preventRightClick = _a.preventRightClick, preventDefault = _a.preventDefault, checkInput = _a.checkInput, preventClickEventOnDragStart = _a.preventClickEventOnDragStart, preventClickEventOnDrag = _a.preventClickEventOnDrag, preventClickEventByCondition = _a.preventClickEventByCondition; | ||
var _a = _this.options, container = _a.container, pinchOutside = _a.pinchOutside, preventWheelClick = _a.preventWheelClick, preventRightClick = _a.preventRightClick, preventDefault = _a.preventDefault, checkInput = _a.checkInput, dragFocusedInput = _a.dragFocusedInput, preventClickEventOnDragStart = _a.preventClickEventOnDragStart, preventClickEventOnDrag = _a.preventClickEventOnDrag, preventClickEventByCondition = _a.preventClickEventByCondition; | ||
var isTouch = _this.isTouch; | ||
@@ -265,3 +265,3 @@ var isDragStart = !_this.flag; | ||
if (hasInput || hasContentEditable) { | ||
if (checkInput || activeElement === target) { | ||
if (checkInput || (!dragFocusedInput && activeElement === target)) { | ||
// force false or already focused. | ||
@@ -268,0 +268,0 @@ return false; |
@@ -7,3 +7,3 @@ /* | ||
repository: git+https://github.com/daybrush/gesto.git | ||
version: 1.16.0 | ||
version: 1.17.0 | ||
*/ | ||
@@ -245,3 +245,3 @@ import EventEmitter from '@scena/event-emitter'; | ||
} | ||
var _a = _this.options, container = _a.container, pinchOutside = _a.pinchOutside, preventWheelClick = _a.preventWheelClick, preventRightClick = _a.preventRightClick, preventDefault = _a.preventDefault, checkInput = _a.checkInput, preventClickEventOnDragStart = _a.preventClickEventOnDragStart, preventClickEventOnDrag = _a.preventClickEventOnDrag, preventClickEventByCondition = _a.preventClickEventByCondition; | ||
var _a = _this.options, container = _a.container, pinchOutside = _a.pinchOutside, preventWheelClick = _a.preventWheelClick, preventRightClick = _a.preventRightClick, preventDefault = _a.preventDefault, checkInput = _a.checkInput, dragFocusedInput = _a.dragFocusedInput, preventClickEventOnDragStart = _a.preventClickEventOnDragStart, preventClickEventOnDrag = _a.preventClickEventOnDrag, preventClickEventByCondition = _a.preventClickEventByCondition; | ||
var isTouch = _this.isTouch; | ||
@@ -263,3 +263,3 @@ var isDragStart = !_this.flag; | ||
if (hasInput || hasContentEditable) { | ||
if (checkInput || activeElement === target) { | ||
if (checkInput || (!dragFocusedInput && activeElement === target)) { | ||
// force false or already focused. | ||
@@ -266,0 +266,0 @@ return false; |
@@ -7,3 +7,3 @@ /* | ||
repository: git+https://github.com/daybrush/gesto.git | ||
version: 1.16.0 | ||
version: 1.17.0 | ||
*/ | ||
@@ -636,3 +636,3 @@ (function (global, factory) { | ||
} | ||
var _a = _this.options, container = _a.container, pinchOutside = _a.pinchOutside, preventWheelClick = _a.preventWheelClick, preventRightClick = _a.preventRightClick, preventDefault = _a.preventDefault, checkInput = _a.checkInput, preventClickEventOnDragStart = _a.preventClickEventOnDragStart, preventClickEventOnDrag = _a.preventClickEventOnDrag, preventClickEventByCondition = _a.preventClickEventByCondition; | ||
var _a = _this.options, container = _a.container, pinchOutside = _a.pinchOutside, preventWheelClick = _a.preventWheelClick, preventRightClick = _a.preventRightClick, preventDefault = _a.preventDefault, checkInput = _a.checkInput, dragFocusedInput = _a.dragFocusedInput, preventClickEventOnDragStart = _a.preventClickEventOnDragStart, preventClickEventOnDrag = _a.preventClickEventOnDrag, preventClickEventByCondition = _a.preventClickEventByCondition; | ||
var isTouch = _this.isTouch; | ||
@@ -654,3 +654,3 @@ var isDragStart = !_this.flag; | ||
if (hasInput || hasContentEditable) { | ||
if (checkInput || activeElement === target) { | ||
if (checkInput || (!dragFocusedInput && activeElement === target)) { | ||
// force false or already focused. | ||
@@ -657,0 +657,0 @@ return false; |
@@ -7,5 +7,5 @@ /* | ||
repository: git+https://github.com/daybrush/gesto.git | ||
version: 1.16.0 | ||
version: 1.17.0 | ||
*/ | ||
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(t="undefined"!=typeof globalThis?globalThis:t||self).Gesto=n()}(this,(function(){"use strict";var t=function(n,e){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,n){t.__proto__=n}||function(t,n){for(var e in n)n.hasOwnProperty(e)&&(t[e]=n[e])},t(n,e)};var n=function(){return n=Object.assign||function(t){for(var n,e=1,i=arguments.length;e<i;e++)for(var o in n=arguments[e])Object.prototype.hasOwnProperty.call(n,o)&&(t[o]=n[o]);return t},n.apply(this,arguments)};function e(t){return 180*(n=[t[0].clientX,t[0].clientY],e=[t[1].clientX,t[1].clientY],i=e[0]-n[0],o=e[1]-n[1],((r=Math.atan2(o,i))>=0?r:r+2*Math.PI)/Math.PI);var n,e,i,o,r}function i(t){return t?t.touches?function(t){for(var n=Math.min(t.length,2),e=[],i=0;i<n;++i)e.push(s(t[i]));return e}(t.touches):[s(t)]:[]}function o(t,n,e){var i=e.length,o=a(t,i),r=o.clientX,s=o.clientY,u=o.originalClientX,c=o.originalClientY,l=a(n,i),h=l.clientX,v=l.clientY,p=a(e,i);return{clientX:u,clientY:c,deltaX:r-h,deltaY:s-v,distX:r-p.clientX,distY:s-p.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 a(t,n){void 0===n&&(n=t.length);for(var e={clientX:0,clientY:0,originalClientX:0,originalClientY:0},i=0;i<n;++i){var o=t[i];e.originalClientX+="originalClientX"in o?o.originalClientX:o.clientX,e.originalClientY+="originalClientY"in o?o.originalClientY:o.clientY,e.clientX+=o.clientX,e.clientY+=o.clientY}return n?{clientX:e.clientX/n,clientY:e.clientY/n,originalClientX:e.originalClientX/n,originalClientY:e.originalClientY/n}:e}function u(t){return t&&"object"==typeof t}function c(){return Date.now?Date.now():(new Date).getTime()}function l(t,n,e,i){t.addEventListener(n,e,i)}function h(t,n,e,i){t.removeEventListener(n,e,i)}var v=function(){return v=Object.assign||function(t){for(var n,e=1,i=arguments.length;e<i;e++)for(var o in n=arguments[e])Object.prototype.hasOwnProperty.call(n,o)&&(t[o]=n[o]);return t},v.apply(this,arguments)};var p=function(){function t(){this._events={}}var n=t.prototype;return n.on=function(t,n){if(u(t))for(var e in t)this.on(e,t[e]);else this._addEvent(t,n,{});return this},n.off=function(t,n){if(t)if(u(t))for(var e in t)this.off(e);else if(n){var i=this._events[t];if(i){var o=function(t,n,e){void 0===e&&(e=-1);for(var i=t.length,o=0;o<i;++o)if(n(t[o],o,t))return o;return e}(i,(function(t){return t.listener===n}));o>-1&&i.splice(o,1)}}else this._events[t]=[];else this._events={};return this},n.once=function(t,n){var e=this;return n&&this._addEvent(t,n,{once:!0}),new Promise((function(n){e._addEvent(t,n,{once:!0})}))},n.emit=function(t,n){var e=this;void 0===n&&(n={});var i=this._events[t];if(!t||!i)return!0;var o=!1;return n.eventType=t,n.stop=function(){o=!0},n.currentTarget=this,function(){for(var t=0,n=0,e=arguments.length;n<e;n++)t+=arguments[n].length;var i=Array(t),o=0;for(n=0;n<e;n++)for(var r=arguments[n],s=0,a=r.length;s<a;s++,o++)i[o]=r[s];return i}(i).forEach((function(i){i.listener(n),i.once&&e.off(t,i.listener)})),!o},n.trigger=function(t,n){return void 0===n&&(n={}),this.emit(t,n)},n._addEvent=function(t,n,e){var i=this._events;i[t]=i[t]||[],i[t].push(v({listener:n},e))},t}(),g=p,f=function(){function t(t){this.prevClients=[],this.startClients=[],this.movement=0,this.length=0,this.startClients=t,this.prevClients=t,this.length=t.length}return t.prototype.getAngle=function(t){return void 0===t&&(t=this.prevClients),e(t)},t.prototype.getRotation=function(t){return void 0===t&&(t=this.prevClients),e(t)-e(this.startClients)},t.prototype.getPosition=function(t,n){void 0===t&&(t=this.prevClients);var e=o(t||this.prevClients,this.prevClients,this.startClients),i=e.deltaX,r=e.deltaY;return this.movement+=Math.sqrt(i*i+r*r),this.prevClients=t,e},t.prototype.getPositions=function(t){void 0===t&&(t=this.prevClients);var n=this.prevClients;return this.startClients.map((function(e,i){return o([t[i]],[n[i]],[e])}))},t.prototype.getMovement=function(t){var n=this.movement;if(!t)return n;var e=a(t,this.length),i=a(this.prevClients,this.length),o=e.clientX-i.clientX,r=e.clientY-i.clientY;return Math.sqrt(o*o+r*r)+n},t.prototype.getDistance=function(t){return void 0===t&&(t=this.prevClients),r(t)},t.prototype.getScale=function(t){return void 0===t&&(t=this.prevClients),r(t)/r(this.startClients)},t.prototype.move=function(t,n){this.startClients.forEach((function(e){e.clientX-=t,e.clientY-=n})),this.prevClients.forEach((function(e){e.clientX-=t,e.clientY-=n}))},t}(),d=["textarea","input"],E=function(e){function o(t,o){void 0===o&&(o={});var r=e.call(this)||this;r.options={},r.flag=!1,r.pinchFlag=!1,r.data={},r.isDrag=!1,r.isPinch=!1,r.isMouse=!1,r.isTouch=!1,r.clientStores=[],r.targets=[],r.prevTime=0,r.doubleFlag=!1,r._dragFlag=!1,r._isTrusted=!1,r._isMouseEvent=!1,r._isSecondaryButton=!1,r._preventMouseEvent=!1,r._prevInputEvent=null,r.onDragStart=function(t,e){if(void 0===e&&(e=!0),r.flag||!1!==t.cancelable){var o=r.options,s=o.container,a=o.pinchOutside,u=o.preventWheelClick,v=o.preventRightClick,p=o.preventDefault,g=o.checkInput,E=o.preventClickEventOnDragStart,C=o.preventClickEventOnDrag,_=o.preventClickEventByCondition,D=r.isTouch,m=!r.flag;if(r._isSecondaryButton=3===t.which||2===t.button,u&&(2===t.which||1===t.button)||v&&(3===t.which||2===t.button))return r.stop(),!1;if(m){var y=document.activeElement,S=t.target;if(S){var M=S.tagName.toLowerCase(),P=d.indexOf(M)>-1,X=S.isContentEditable;if(P||X){if(g||y===S)return!1;if(y&&X&&y.isContentEditable&&y.contains(S))return!1}else if((p||"touchstart"===t.type)&&y){var Y=y.tagName.toLowerCase();(y.isContentEditable||d.indexOf(Y)>-1)&&y.blur()}(E||C||_)&&l(window,"click",r._onClick,!0)}r.clientStores=[new f(i(t))],r.flag=!0,r.isDrag=!1,r._isTrusted=e,r._dragFlag=!0,r._prevInputEvent=t,r.data={},r.doubleFlag=c()-r.prevTime<200,r._isMouseEvent=function(t){return t&&(t.type.indexOf("mouse")>-1||"button"in t)}(t),!r._isMouseEvent&&r._preventMouseEvent&&(r._preventMouseEvent=!1),!1===(r._preventMouseEvent||r.emit("dragStart",n(n({data:r.data,datas:r.data,inputEvent:t,isMouseEvent:r._isMouseEvent,isSecondaryButton:r._isSecondaryButton,isTrusted:e,isDouble:r.doubleFlag},r.getCurrentStore().getPosition()),{preventDefault:function(){t.preventDefault()},preventDrag:function(){r._dragFlag=!1}})))&&r.stop(),r._isMouseEvent&&r.flag&&p&&t.preventDefault()}if(!r.flag)return!1;var w=0;if(m?(r._attchDragEvent(),D&&a&&(w=setTimeout((function(){l(s,"touchstart",r.onDragStart,{passive:!1})})))):D&&a&&h(s,"touchstart",r.onDragStart),r.flag&&function(t){return t.touches&&t.touches.length>=2}(t)){if(clearTimeout(w),m&&t.touches.length!==t.changedTouches.length)return;r.pinchFlag||r.onPinchStart(t)}}},r.onDrag=function(t,e){if(r.flag){var o=r.options.preventDefault;!r._isMouseEvent&&o&&t.preventDefault(),r._prevInputEvent=t;var s=i(t),a=r.moveClients(s,t,!1);if(r._dragFlag){if(r.pinchFlag||a.deltaX||a.deltaY)if(!1===(r._preventMouseEvent||r.emit("drag",n(n({},a),{isScroll:!!e,inputEvent:t}))))return void r.stop();r.pinchFlag&&r.onPinch(t,s)}r.getCurrentStore().getPosition(s,!0)}},r.onDragEnd=function(t){if(r.flag){var e=r.options,o=e.pinchOutside,s=e.container,a=e.preventClickEventOnDrag,u=e.preventClickEventOnDragStart,l=e.preventClickEventByCondition,v=r.isDrag;(a||u||l)&&requestAnimationFrame((function(){r._allowClickEvent()})),l||u||!a||v||r._allowClickEvent(),r.isTouch&&o&&h(s,"touchstart",r.onDragStart),r.pinchFlag&&r.onPinchEnd(t);var p=(null==t?void 0:t.touches)?i(t):[];0!==p.length&&r.options.keepDragging?r._addStore(new f(p)):r.flag=!1;var g=r._getPosition(),d=c(),E=!v&&r.doubleFlag;r._prevInputEvent=null,r.prevTime=v||E?0:d,r.flag||(r._dettachDragEvent(),r._preventMouseEvent||r.emit("dragEnd",n({data:r.data,datas:r.data,isDouble:E,isDrag:v,isClick:!v,isMouseEvent:r._isMouseEvent,isSecondaryButton:r._isSecondaryButton,inputEvent:t,isTrusted:r._isTrusted},g)),r.clientStores=[],r._isMouseEvent||(r._preventMouseEvent=!0,requestAnimationFrame((function(){requestAnimationFrame((function(){r._preventMouseEvent=!1}))}))))}},r.onBlur=function(){r.onDragEnd()},r._allowClickEvent=function(){h(window,"click",r._onClick,!0)},r._onClick=function(t){r._allowClickEvent(),r._preventMouseEvent=!1;var n=r.options.preventClickEventByCondition;(null==n?void 0:n(t))||(t.stopPropagation(),t.preventDefault())},r._onContextMenu=function(t){r.options.preventRightClick?r.onDragEnd(t):t.preventDefault()},r._passCallback=function(){};var s=[].concat(t);r.options=n({checkInput:!1,container:s.length>1?window:s[0],preventRightClick:!0,preventWheelClick:!0,preventClickEventOnDragStart:!1,preventClickEventOnDrag:!1,preventClickEventByCondition:null,preventDefault:!0,checkWindowBlur:!1,keepDragging:!1,pinchThreshold:0,events:["touch","mouse"]},o);var a=r.options,u=a.container,v=a.events,p=a.checkWindowBlur;if(r.isTouch=v.indexOf("touch")>-1,r.isMouse=v.indexOf("mouse")>-1,r.targets=s,r.isMouse&&(s.forEach((function(t){l(t,"mousedown",r.onDragStart),l(t,"mousemove",r._passCallback)})),l(u,"contextmenu",r._onContextMenu)),p&&l(window,"blur",r.onBlur),r.isTouch){var g={passive:!1};s.forEach((function(t){l(t,"touchstart",r.onDragStart,g),l(t,"touchmove",r._passCallback,g)}))}return r}return function(n,e){function i(){this.constructor=n}t(n,e),n.prototype=null===e?Object.create(e):(i.prototype=e.prototype,new i)}(o,e),o.prototype.stop=function(){this.isDrag=!1,this.data={},this.clientStores=[],this.pinchFlag=!1,this.doubleFlag=!1,this.prevTime=0,this.flag=!1,this._allowClickEvent(),this._dettachDragEvent()},o.prototype.getMovement=function(t){return this.getCurrentStore().getMovement(t)+this.clientStores.slice(1).reduce((function(t,n){return t+n.movement}),0)},o.prototype.isDragging=function(){return this.isDrag},o.prototype.isFlag=function(){return this.flag},o.prototype.isPinchFlag=function(){return this.pinchFlag},o.prototype.isDoubleFlag=function(){return this.doubleFlag},o.prototype.isPinching=function(){return this.isPinch},o.prototype.scrollBy=function(t,n,e,i){void 0===i&&(i=!0),this.flag&&(this.clientStores[0].move(t,n),i&&this.onDrag(e,!0))},o.prototype.move=function(t,n){var e=t[0],i=t[1],o=this.getCurrentStore().prevClients;return this.moveClients(o.map((function(t){var n=t.clientX,o=t.clientY;return{clientX:n+e,clientY:o+i,originalClientX:n,originalClientY:o}})),n,!0)},o.prototype.triggerDragStart=function(t){this.onDragStart(t,!1)},o.prototype.setEventData=function(t){var n=this.data;for(var e in t)n[e]=t[e];return this},o.prototype.setEventDatas=function(t){return this.setEventData(t)},o.prototype.getCurrentEvent=function(t){return void 0===t&&(t=this._prevInputEvent),n(n({data:this.data,datas:this.data},this._getPosition()),{movement:this.getMovement(),isDrag:this.isDrag,isPinch:this.isPinch,isScroll:!1,inputEvent:t})},o.prototype.getEventData=function(){return this.data},o.prototype.getEventDatas=function(){return this.data},o.prototype.unset=function(){var t=this,n=this.targets,e=this.options.container;this.off(),h(window,"blur",this.onBlur),this.isMouse&&(n.forEach((function(n){h(n,"mousedown",t.onDragStart)})),h(e,"contextmenu",this._onContextMenu)),this.isTouch&&(n.forEach((function(n){h(n,"touchstart",t.onDragStart)})),h(e,"touchstart",this.onDragStart)),this._prevInputEvent=null,this._allowClickEvent(),this._dettachDragEvent()},o.prototype.onPinchStart=function(t){var e=this,o=this.options.pinchThreshold;if(!(this.isDrag&&this.getMovement()>o)){var r=new f(i(t));this.pinchFlag=!0,this._addStore(r),!1===this.emit("pinchStart",n(n({data:this.data,datas:this.data,angle:r.getAngle(),touches:this.getCurrentStore().getPositions()},r.getPosition()),{inputEvent:t,isTrusted:this._isTrusted,preventDefault:function(){t.preventDefault()},preventDrag:function(){e._dragFlag=!1}}))&&(this.pinchFlag=!1)}},o.prototype.onPinch=function(t,e){if(this.flag&&this.pinchFlag&&!(e.length<2)){var i=this.getCurrentStore();this.isPinch=!0,this.emit("pinch",n(n({data:this.data,datas:this.data,movement:this.getMovement(e),angle:i.getAngle(e),rotation:i.getRotation(e),touches:i.getPositions(e),scale:i.getScale(e),distance:i.getDistance(e)},i.getPosition(e)),{inputEvent:t,isTrusted:this._isTrusted}))}},o.prototype.onPinchEnd=function(t){if(this.pinchFlag){var e=this.isPinch;this.isPinch=!1,this.pinchFlag=!1;var i=this.getCurrentStore();this.emit("pinchEnd",n(n({data:this.data,datas:this.data,isPinch:e,touches:i.getPositions()},i.getPosition()),{inputEvent:t}))}},o.prototype.getCurrentStore=function(){return this.clientStores[0]},o.prototype.moveClients=function(t,e,i){var o=this._getPosition(t,i),r=this.isDrag;(o.deltaX||o.deltaY)&&(this.isDrag=!0);var s=!1;return!r&&this.isDrag&&(s=!0),n(n({data:this.data,datas:this.data},o),{movement:this.getMovement(t),isDrag:this.isDrag,isPinch:this.isPinch,isScroll:!1,isMouseEvent:this._isMouseEvent,isSecondaryButton:this._isSecondaryButton,inputEvent:e,isTrusted:this._isTrusted,isFirstDrag:s})},o.prototype._addStore=function(t){this.clientStores.splice(0,0,t)},o.prototype._getPosition=function(t,e){var i=this.getCurrentStore().getPosition(t,e),o=this.clientStores.slice(1).reduce((function(t,n){var e=n.getPosition();return t.distX+=e.distX,t.distY+=e.distY,t}),i),r=o.distX,s=o.distY;return n(n({},i),{distX:r,distY:s})},o.prototype._attchDragEvent=function(){var t=this.options.container,n={passive:!1};this.isMouse&&(l(t,"mousemove",this.onDrag),l(t,"mouseup",this.onDragEnd)),this.isTouch&&(l(t,"touchmove",this.onDrag,n),l(t,"touchend",this.onDragEnd,n),l(t,"touchcancel",this.onDragEnd,n))},o.prototype._dettachDragEvent=function(){var t=this.options.container;this.isMouse&&(h(t,"mousemove",this.onDrag),h(t,"mouseup",this.onDragEnd)),this.isTouch&&(h(t,"touchstart",this.onDragStart),h(t,"touchmove",this.onDrag),h(t,"touchend",this.onDragEnd),h(t,"touchcancel",this.onDragEnd))},o}(g),C={__proto__:null,default:E};for(var _ in C)E[_]=C[_];return E})); | ||
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(t="undefined"!=typeof globalThis?globalThis:t||self).Gesto=n()}(this,(function(){"use strict";var t=function(n,e){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,n){t.__proto__=n}||function(t,n){for(var e in n)n.hasOwnProperty(e)&&(t[e]=n[e])},t(n,e)};var n=function(){return n=Object.assign||function(t){for(var n,e=1,i=arguments.length;e<i;e++)for(var o in n=arguments[e])Object.prototype.hasOwnProperty.call(n,o)&&(t[o]=n[o]);return t},n.apply(this,arguments)};function e(t){return 180*(n=[t[0].clientX,t[0].clientY],e=[t[1].clientX,t[1].clientY],i=e[0]-n[0],o=e[1]-n[1],((r=Math.atan2(o,i))>=0?r:r+2*Math.PI)/Math.PI);var n,e,i,o,r}function i(t){return t?t.touches?function(t){for(var n=Math.min(t.length,2),e=[],i=0;i<n;++i)e.push(s(t[i]));return e}(t.touches):[s(t)]:[]}function o(t,n,e){var i=e.length,o=a(t,i),r=o.clientX,s=o.clientY,u=o.originalClientX,c=o.originalClientY,l=a(n,i),h=l.clientX,v=l.clientY,p=a(e,i);return{clientX:u,clientY:c,deltaX:r-h,deltaY:s-v,distX:r-p.clientX,distY:s-p.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 a(t,n){void 0===n&&(n=t.length);for(var e={clientX:0,clientY:0,originalClientX:0,originalClientY:0},i=0;i<n;++i){var o=t[i];e.originalClientX+="originalClientX"in o?o.originalClientX:o.clientX,e.originalClientY+="originalClientY"in o?o.originalClientY:o.clientY,e.clientX+=o.clientX,e.clientY+=o.clientY}return n?{clientX:e.clientX/n,clientY:e.clientY/n,originalClientX:e.originalClientX/n,originalClientY:e.originalClientY/n}:e}function u(t){return t&&"object"==typeof t}function c(){return Date.now?Date.now():(new Date).getTime()}function l(t,n,e,i){t.addEventListener(n,e,i)}function h(t,n,e,i){t.removeEventListener(n,e,i)}var v=function(){return v=Object.assign||function(t){for(var n,e=1,i=arguments.length;e<i;e++)for(var o in n=arguments[e])Object.prototype.hasOwnProperty.call(n,o)&&(t[o]=n[o]);return t},v.apply(this,arguments)};var p=function(){function t(){this._events={}}var n=t.prototype;return n.on=function(t,n){if(u(t))for(var e in t)this.on(e,t[e]);else this._addEvent(t,n,{});return this},n.off=function(t,n){if(t)if(u(t))for(var e in t)this.off(e);else if(n){var i=this._events[t];if(i){var o=function(t,n,e){void 0===e&&(e=-1);for(var i=t.length,o=0;o<i;++o)if(n(t[o],o,t))return o;return e}(i,(function(t){return t.listener===n}));o>-1&&i.splice(o,1)}}else this._events[t]=[];else this._events={};return this},n.once=function(t,n){var e=this;return n&&this._addEvent(t,n,{once:!0}),new Promise((function(n){e._addEvent(t,n,{once:!0})}))},n.emit=function(t,n){var e=this;void 0===n&&(n={});var i=this._events[t];if(!t||!i)return!0;var o=!1;return n.eventType=t,n.stop=function(){o=!0},n.currentTarget=this,function(){for(var t=0,n=0,e=arguments.length;n<e;n++)t+=arguments[n].length;var i=Array(t),o=0;for(n=0;n<e;n++)for(var r=arguments[n],s=0,a=r.length;s<a;s++,o++)i[o]=r[s];return i}(i).forEach((function(i){i.listener(n),i.once&&e.off(t,i.listener)})),!o},n.trigger=function(t,n){return void 0===n&&(n={}),this.emit(t,n)},n._addEvent=function(t,n,e){var i=this._events;i[t]=i[t]||[],i[t].push(v({listener:n},e))},t}(),g=p,f=function(){function t(t){this.prevClients=[],this.startClients=[],this.movement=0,this.length=0,this.startClients=t,this.prevClients=t,this.length=t.length}return t.prototype.getAngle=function(t){return void 0===t&&(t=this.prevClients),e(t)},t.prototype.getRotation=function(t){return void 0===t&&(t=this.prevClients),e(t)-e(this.startClients)},t.prototype.getPosition=function(t,n){void 0===t&&(t=this.prevClients);var e=o(t||this.prevClients,this.prevClients,this.startClients),i=e.deltaX,r=e.deltaY;return this.movement+=Math.sqrt(i*i+r*r),this.prevClients=t,e},t.prototype.getPositions=function(t){void 0===t&&(t=this.prevClients);var n=this.prevClients;return this.startClients.map((function(e,i){return o([t[i]],[n[i]],[e])}))},t.prototype.getMovement=function(t){var n=this.movement;if(!t)return n;var e=a(t,this.length),i=a(this.prevClients,this.length),o=e.clientX-i.clientX,r=e.clientY-i.clientY;return Math.sqrt(o*o+r*r)+n},t.prototype.getDistance=function(t){return void 0===t&&(t=this.prevClients),r(t)},t.prototype.getScale=function(t){return void 0===t&&(t=this.prevClients),r(t)/r(this.startClients)},t.prototype.move=function(t,n){this.startClients.forEach((function(e){e.clientX-=t,e.clientY-=n})),this.prevClients.forEach((function(e){e.clientX-=t,e.clientY-=n}))},t}(),d=["textarea","input"],E=function(e){function o(t,o){void 0===o&&(o={});var r=e.call(this)||this;r.options={},r.flag=!1,r.pinchFlag=!1,r.data={},r.isDrag=!1,r.isPinch=!1,r.isMouse=!1,r.isTouch=!1,r.clientStores=[],r.targets=[],r.prevTime=0,r.doubleFlag=!1,r._dragFlag=!1,r._isTrusted=!1,r._isMouseEvent=!1,r._isSecondaryButton=!1,r._preventMouseEvent=!1,r._prevInputEvent=null,r.onDragStart=function(t,e){if(void 0===e&&(e=!0),r.flag||!1!==t.cancelable){var o=r.options,s=o.container,a=o.pinchOutside,u=o.preventWheelClick,v=o.preventRightClick,p=o.preventDefault,g=o.checkInput,E=o.dragFocusedInput,C=o.preventClickEventOnDragStart,_=o.preventClickEventOnDrag,D=o.preventClickEventByCondition,m=r.isTouch,y=!r.flag;if(r._isSecondaryButton=3===t.which||2===t.button,u&&(2===t.which||1===t.button)||v&&(3===t.which||2===t.button))return r.stop(),!1;if(y){var S=document.activeElement,M=t.target;if(M){var P=M.tagName.toLowerCase(),X=d.indexOf(P)>-1,Y=M.isContentEditable;if(X||Y){if(g||!E&&S===M)return!1;if(S&&Y&&S.isContentEditable&&S.contains(M))return!1}else if((p||"touchstart"===t.type)&&S){var w=S.tagName.toLowerCase();(S.isContentEditable||d.indexOf(w)>-1)&&S.blur()}(C||_||D)&&l(window,"click",r._onClick,!0)}r.clientStores=[new f(i(t))],r.flag=!0,r.isDrag=!1,r._isTrusted=e,r._dragFlag=!0,r._prevInputEvent=t,r.data={},r.doubleFlag=c()-r.prevTime<200,r._isMouseEvent=function(t){return t&&(t.type.indexOf("mouse")>-1||"button"in t)}(t),!r._isMouseEvent&&r._preventMouseEvent&&(r._preventMouseEvent=!1),!1===(r._preventMouseEvent||r.emit("dragStart",n(n({data:r.data,datas:r.data,inputEvent:t,isMouseEvent:r._isMouseEvent,isSecondaryButton:r._isSecondaryButton,isTrusted:e,isDouble:r.doubleFlag},r.getCurrentStore().getPosition()),{preventDefault:function(){t.preventDefault()},preventDrag:function(){r._dragFlag=!1}})))&&r.stop(),r._isMouseEvent&&r.flag&&p&&t.preventDefault()}if(!r.flag)return!1;var k=0;if(y?(r._attchDragEvent(),m&&a&&(k=setTimeout((function(){l(s,"touchstart",r.onDragStart,{passive:!1})})))):m&&a&&h(s,"touchstart",r.onDragStart),r.flag&&function(t){return t.touches&&t.touches.length>=2}(t)){if(clearTimeout(k),y&&t.touches.length!==t.changedTouches.length)return;r.pinchFlag||r.onPinchStart(t)}}},r.onDrag=function(t,e){if(r.flag){var o=r.options.preventDefault;!r._isMouseEvent&&o&&t.preventDefault(),r._prevInputEvent=t;var s=i(t),a=r.moveClients(s,t,!1);if(r._dragFlag){if(r.pinchFlag||a.deltaX||a.deltaY)if(!1===(r._preventMouseEvent||r.emit("drag",n(n({},a),{isScroll:!!e,inputEvent:t}))))return void r.stop();r.pinchFlag&&r.onPinch(t,s)}r.getCurrentStore().getPosition(s,!0)}},r.onDragEnd=function(t){if(r.flag){var e=r.options,o=e.pinchOutside,s=e.container,a=e.preventClickEventOnDrag,u=e.preventClickEventOnDragStart,l=e.preventClickEventByCondition,v=r.isDrag;(a||u||l)&&requestAnimationFrame((function(){r._allowClickEvent()})),l||u||!a||v||r._allowClickEvent(),r.isTouch&&o&&h(s,"touchstart",r.onDragStart),r.pinchFlag&&r.onPinchEnd(t);var p=(null==t?void 0:t.touches)?i(t):[];0!==p.length&&r.options.keepDragging?r._addStore(new f(p)):r.flag=!1;var g=r._getPosition(),d=c(),E=!v&&r.doubleFlag;r._prevInputEvent=null,r.prevTime=v||E?0:d,r.flag||(r._dettachDragEvent(),r._preventMouseEvent||r.emit("dragEnd",n({data:r.data,datas:r.data,isDouble:E,isDrag:v,isClick:!v,isMouseEvent:r._isMouseEvent,isSecondaryButton:r._isSecondaryButton,inputEvent:t,isTrusted:r._isTrusted},g)),r.clientStores=[],r._isMouseEvent||(r._preventMouseEvent=!0,requestAnimationFrame((function(){requestAnimationFrame((function(){r._preventMouseEvent=!1}))}))))}},r.onBlur=function(){r.onDragEnd()},r._allowClickEvent=function(){h(window,"click",r._onClick,!0)},r._onClick=function(t){r._allowClickEvent(),r._preventMouseEvent=!1;var n=r.options.preventClickEventByCondition;(null==n?void 0:n(t))||(t.stopPropagation(),t.preventDefault())},r._onContextMenu=function(t){r.options.preventRightClick?r.onDragEnd(t):t.preventDefault()},r._passCallback=function(){};var s=[].concat(t);r.options=n({checkInput:!1,container:s.length>1?window:s[0],preventRightClick:!0,preventWheelClick:!0,preventClickEventOnDragStart:!1,preventClickEventOnDrag:!1,preventClickEventByCondition:null,preventDefault:!0,checkWindowBlur:!1,keepDragging:!1,pinchThreshold:0,events:["touch","mouse"]},o);var a=r.options,u=a.container,v=a.events,p=a.checkWindowBlur;if(r.isTouch=v.indexOf("touch")>-1,r.isMouse=v.indexOf("mouse")>-1,r.targets=s,r.isMouse&&(s.forEach((function(t){l(t,"mousedown",r.onDragStart),l(t,"mousemove",r._passCallback)})),l(u,"contextmenu",r._onContextMenu)),p&&l(window,"blur",r.onBlur),r.isTouch){var g={passive:!1};s.forEach((function(t){l(t,"touchstart",r.onDragStart,g),l(t,"touchmove",r._passCallback,g)}))}return r}return function(n,e){function i(){this.constructor=n}t(n,e),n.prototype=null===e?Object.create(e):(i.prototype=e.prototype,new i)}(o,e),o.prototype.stop=function(){this.isDrag=!1,this.data={},this.clientStores=[],this.pinchFlag=!1,this.doubleFlag=!1,this.prevTime=0,this.flag=!1,this._allowClickEvent(),this._dettachDragEvent()},o.prototype.getMovement=function(t){return this.getCurrentStore().getMovement(t)+this.clientStores.slice(1).reduce((function(t,n){return t+n.movement}),0)},o.prototype.isDragging=function(){return this.isDrag},o.prototype.isFlag=function(){return this.flag},o.prototype.isPinchFlag=function(){return this.pinchFlag},o.prototype.isDoubleFlag=function(){return this.doubleFlag},o.prototype.isPinching=function(){return this.isPinch},o.prototype.scrollBy=function(t,n,e,i){void 0===i&&(i=!0),this.flag&&(this.clientStores[0].move(t,n),i&&this.onDrag(e,!0))},o.prototype.move=function(t,n){var e=t[0],i=t[1],o=this.getCurrentStore().prevClients;return this.moveClients(o.map((function(t){var n=t.clientX,o=t.clientY;return{clientX:n+e,clientY:o+i,originalClientX:n,originalClientY:o}})),n,!0)},o.prototype.triggerDragStart=function(t){this.onDragStart(t,!1)},o.prototype.setEventData=function(t){var n=this.data;for(var e in t)n[e]=t[e];return this},o.prototype.setEventDatas=function(t){return this.setEventData(t)},o.prototype.getCurrentEvent=function(t){return void 0===t&&(t=this._prevInputEvent),n(n({data:this.data,datas:this.data},this._getPosition()),{movement:this.getMovement(),isDrag:this.isDrag,isPinch:this.isPinch,isScroll:!1,inputEvent:t})},o.prototype.getEventData=function(){return this.data},o.prototype.getEventDatas=function(){return this.data},o.prototype.unset=function(){var t=this,n=this.targets,e=this.options.container;this.off(),h(window,"blur",this.onBlur),this.isMouse&&(n.forEach((function(n){h(n,"mousedown",t.onDragStart)})),h(e,"contextmenu",this._onContextMenu)),this.isTouch&&(n.forEach((function(n){h(n,"touchstart",t.onDragStart)})),h(e,"touchstart",this.onDragStart)),this._prevInputEvent=null,this._allowClickEvent(),this._dettachDragEvent()},o.prototype.onPinchStart=function(t){var e=this,o=this.options.pinchThreshold;if(!(this.isDrag&&this.getMovement()>o)){var r=new f(i(t));this.pinchFlag=!0,this._addStore(r),!1===this.emit("pinchStart",n(n({data:this.data,datas:this.data,angle:r.getAngle(),touches:this.getCurrentStore().getPositions()},r.getPosition()),{inputEvent:t,isTrusted:this._isTrusted,preventDefault:function(){t.preventDefault()},preventDrag:function(){e._dragFlag=!1}}))&&(this.pinchFlag=!1)}},o.prototype.onPinch=function(t,e){if(this.flag&&this.pinchFlag&&!(e.length<2)){var i=this.getCurrentStore();this.isPinch=!0,this.emit("pinch",n(n({data:this.data,datas:this.data,movement:this.getMovement(e),angle:i.getAngle(e),rotation:i.getRotation(e),touches:i.getPositions(e),scale:i.getScale(e),distance:i.getDistance(e)},i.getPosition(e)),{inputEvent:t,isTrusted:this._isTrusted}))}},o.prototype.onPinchEnd=function(t){if(this.pinchFlag){var e=this.isPinch;this.isPinch=!1,this.pinchFlag=!1;var i=this.getCurrentStore();this.emit("pinchEnd",n(n({data:this.data,datas:this.data,isPinch:e,touches:i.getPositions()},i.getPosition()),{inputEvent:t}))}},o.prototype.getCurrentStore=function(){return this.clientStores[0]},o.prototype.moveClients=function(t,e,i){var o=this._getPosition(t,i),r=this.isDrag;(o.deltaX||o.deltaY)&&(this.isDrag=!0);var s=!1;return!r&&this.isDrag&&(s=!0),n(n({data:this.data,datas:this.data},o),{movement:this.getMovement(t),isDrag:this.isDrag,isPinch:this.isPinch,isScroll:!1,isMouseEvent:this._isMouseEvent,isSecondaryButton:this._isSecondaryButton,inputEvent:e,isTrusted:this._isTrusted,isFirstDrag:s})},o.prototype._addStore=function(t){this.clientStores.splice(0,0,t)},o.prototype._getPosition=function(t,e){var i=this.getCurrentStore().getPosition(t,e),o=this.clientStores.slice(1).reduce((function(t,n){var e=n.getPosition();return t.distX+=e.distX,t.distY+=e.distY,t}),i),r=o.distX,s=o.distY;return n(n({},i),{distX:r,distY:s})},o.prototype._attchDragEvent=function(){var t=this.options.container,n={passive:!1};this.isMouse&&(l(t,"mousemove",this.onDrag),l(t,"mouseup",this.onDragEnd)),this.isTouch&&(l(t,"touchmove",this.onDrag,n),l(t,"touchend",this.onDragEnd,n),l(t,"touchcancel",this.onDragEnd,n))},o.prototype._dettachDragEvent=function(){var t=this.options.container;this.isMouse&&(h(t,"mousemove",this.onDrag),h(t,"mouseup",this.onDragEnd)),this.isTouch&&(h(t,"touchstart",this.onDragStart),h(t,"touchmove",this.onDrag),h(t,"touchend",this.onDragEnd),h(t,"touchcancel",this.onDragEnd))},o}(g),C={__proto__:null,default:E};for(var _ in C)E[_]=C[_];return E})); | ||
//# sourceMappingURL=gesto.min.js.map |
{ | ||
"name": "gesto", | ||
"version": "1.16.0", | ||
"version": "1.17.0", | ||
"description": "You can set up drag, pinch events in any browser.", | ||
@@ -5,0 +5,0 @@ "main": "./dist/gesto.cjs.js", |
@@ -251,2 +251,3 @@ import { Client, OnDrag, GestoOptions, GestoEvents } from "./types"; | ||
checkInput, | ||
dragFocusedInput, | ||
preventClickEventOnDragStart, | ||
@@ -279,3 +280,3 @@ preventClickEventOnDrag, | ||
if (hasInput || hasContentEditable) { | ||
if (checkInput || activeElement === target) { | ||
if (checkInput || (!dragFocusedInput && activeElement === target)) { | ||
// force false or already focused. | ||
@@ -282,0 +283,0 @@ return false; |
@@ -186,3 +186,13 @@ import { IObject } from "@daybrush/utils"; | ||
pinchOutside?: boolean; | ||
/** | ||
* Prevent dragging of `input`, `textarea`, and contenteditable. | ||
* @default false | ||
*/ | ||
checkInput?: boolean; | ||
/** | ||
* Whether to drag the focused input | ||
* If `checkInput` is true, this option is not applied. | ||
* @default false | ||
*/ | ||
dragFocusedInput?: boolean; | ||
checkWindowBlur?: boolean; | ||
@@ -189,0 +199,0 @@ |
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
337904
4086