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

@odopod/odo-pointer

Package Overview
Dependencies
Maintainers
3
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@odopod/odo-pointer - npm Package Compare versions

Comparing version 1.0.3 to 1.1.0

dist/odo-pointer.esm.js

18

dist/odo-pointer.js
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('tiny-emitter'), require('@odopod/odo-device'), require('@odopod/odo-helpers')) :
typeof define === 'function' && define.amd ? define(['tiny-emitter', '@odopod/odo-device', '@odopod/odo-helpers'], factory) :
(global.OdoPointer = factory(global.TinyEmitter,global.OdoDevice,global.OdoHelpers));
}(this, (function (TinyEmitter,OdoDevice,odoHelpers) { 'use strict';
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('@odopod/odo-device'), require('@odopod/odo-helpers'), require('tiny-emitter')) :
typeof define === 'function' && define.amd ? define(['@odopod/odo-device', '@odopod/odo-helpers', 'tiny-emitter'], factory) :
(global.OdoPointer = factory(global.OdoDevice,global.OdoHelpers,global.TinyEmitter));
}(this, (function (OdoDevice,odoHelpers,TinyEmitter) { 'use strict';
OdoDevice = OdoDevice && OdoDevice.hasOwnProperty('default') ? OdoDevice['default'] : OdoDevice;
TinyEmitter = TinyEmitter && TinyEmitter.hasOwnProperty('default') ? TinyEmitter['default'] : TinyEmitter;
OdoDevice = OdoDevice && OdoDevice.hasOwnProperty('default') ? OdoDevice['default'] : OdoDevice;

@@ -522,3 +522,3 @@ var settings = {

} else if (_this._shouldPreventDefault && OdoDevice.HAS_TOUCH_EVENTS) {
window.addEventListener(odoHelpers.events.TOUCHMOVE, odoHelpers.utilities.noop);
window.addEventListener(odoHelpers.events.TOUCHMOVE, odoHelpers.noop);
}

@@ -921,4 +921,4 @@

var maxVelocity = Pointer.MAX_VELOCITY;
this.velocity.x = odoHelpers.math.clamp(delta.x / elapsed, -maxVelocity, maxVelocity);
this.velocity.y = odoHelpers.math.clamp(delta.y / elapsed, -maxVelocity, maxVelocity);
this.velocity.x = odoHelpers.clamp(delta.x / elapsed, -maxVelocity, maxVelocity);
this.velocity.y = odoHelpers.clamp(delta.y / elapsed, -maxVelocity, maxVelocity);

@@ -982,3 +982,3 @@ this._hasTrackedVelocity = true;

} else if (this._shouldPreventDefault && OdoDevice.HAS_TOUCH_EVENTS) {
window.removeEventListener(odoHelpers.events.TOUCHMOVE, odoHelpers.utilities.noop);
window.removeEventListener(odoHelpers.events.TOUCHMOVE, odoHelpers.noop);
}

@@ -985,0 +985,0 @@

@@ -1,2 +0,2 @@

!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("tiny-emitter"),require("@odopod/odo-device"),require("@odopod/odo-helpers")):"function"==typeof define&&define.amd?define(["tiny-emitter","@odopod/odo-device","@odopod/odo-helpers"],e):t.OdoPointer=e(t.TinyEmitter,t.OdoDevice,t.OdoHelpers)}(this,function(t,e,i){"use strict";t=t&&t.hasOwnProperty("default")?t.default:t;var n={EventType:{START:"odopointer:start",MOVE:"odopointer:move",END:"odopointer:end"},Direction:{RIGHT:"right",LEFT:"left",UP:"up",DOWN:"down",NONE:"no_movement"},TouchActionSupport:{x:(e=e&&e.hasOwnProperty("default")?e.default:e).prefixed("touchAction","pan-y"),y:e.prefixed("touchAction","pan-x"),xy:e.prefixed("touchAction","none")},TouchAction:{x:"pan-y",y:"pan-x",xy:"none"},Axis:{X:"x",Y:"y",BOTH:"xy"},Defaults:{axis:"xy",preventEventDefault:!0},MAX_VELOCITY:12,VELOCITY_INTERVAL:100,SWIPE_VELOCITY:.6,LOCK_THRESHOLD:6,DRAG_THRESHOLD:5},s=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},o=function(){function t(t,e){for(var i=0;i<e.length;i++){var n=e[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}return function(e,i,n){return i&&t(e.prototype,i),n&&t(e,n),e}}(),r=function(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e};function a(t){return t===n.Axis.X}function h(t){return t===n.Axis.Y}function c(t){return t===n.Axis.BOTH}function d(t){return t!==n.Direction.NONE}function u(t){return Number.isFinite(t)?t:0}function v(t,e,i,n,s){return t-e>0?i:t-e<0?n:s}function l(t,e){return Math.abs(t.x-e.x)>=Math.abs(t.y-e.y)?v(t.x,e.x,n.Direction.LEFT,n.Direction.RIGHT,n.Direction.NONE):v(t.y,e.y,n.Direction.UP,n.Direction.DOWN,n.Direction.NONE)}var p=function(){function t(e){var o,r,v,p,_,E,T,y,f,D,O,g,x,m,L,C,A;s(this,t),this.type=e.type,this.target=e.target,this.currentTarget=e.currentTarget,this.start=e.start,this.end=e.end,this.delta=e.delta,this.deltaTime=e.deltaTime,this.velocity=(o=this.deltaTime,r=this.delta.x,v=this.delta.y,new i.Coordinate(u(r/o),u(v/o))),this.currentVelocity=e.currentVelocity,this.distance=i.Coordinate.distance(e.start,e.end),this.direction=l(e.start,e.end),this.isDirectionOnAxis=(p=e.axis,_=this.direction,E=a(p)&&(_===n.Direction.LEFT||_===n.Direction.RIGHT),T=h(p)&&(_===n.Direction.UP||_===n.Direction.DOWN),y=c(p)&&d(_),E||T||y),this.didMoveOnAxis=(f=e.axis,D=this.direction,O=this.delta.x,g=this.delta.y,a(f)&&Math.abs(O)>0||h(f)&&Math.abs(g)>0||c(f)&&d(D)),this.axisDirection=(x=e.axis,m=e.start,L=e.end,C=Object.assign({},m),A=Object.assign({},L),a(x)?(C.y=0,A.y=0):h(x)&&(C.x=0,A.x=0),l(C,A)),this.position=e.position,this.defaultPrevented=!1}return t.prototype.preventDefault=function(){this.defaultPrevented=!0},t}(),_=function(t){function n(o){var a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};s(this,n);var h=r(this,t.call(this));if(!o||1!==o.nodeType)throw new TypeError("OdoPointer requires an element.");var c=Object.assign({},n.Defaults,a);h._shouldPreventDefault=c.preventEventDefault,h._el=o,h.pageStart=new i.Coordinate,h.page=new i.Coordinate,h.delta=new i.Coordinate,h._lastPosition=new i.Coordinate,h._friction=1,h.axis=c.axis,h.hasDragged=!1,h._isLocked=!1,h._isDeactivated=!1,h._enabled=!0,h._velocityTrackerId=null,h.startTime=0,h.deltaTime=0,h._lastTime=0,h.velocity=new i.Coordinate,h._hasTrackedVelocity=!1,h.dragEventTarget=document;var d=n.TouchActionSupport[h.axis];return h._isTouchActionSupported=!!d,h._shouldPreventDefault&&h._isTouchActionSupported?h.element.style[d]=n.TouchAction[h.axis]:h._shouldPreventDefault&&e.HAS_TOUCH_EVENTS&&window.addEventListener(i.events.TOUCHMOVE,i.utilities.noop),h.listen(),h}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}(n,t),n.prototype.listen=function(){this._onStart=this._handleDragStart.bind(this),e.HAS_POINTER_EVENTS?this._el.addEventListener(i.events.POINTERDOWN,this._onStart):(this._el.addEventListener(i.events.MOUSEDOWN,this._onStart),e.HAS_TOUCH_EVENTS&&this._el.addEventListener(i.events.TOUCHSTART,this._onStart)),this._el.addEventListener(i.events.DRAGSTART,n._preventDefault)},n.prototype.isXAxis=function(){return this.axis===n.Axis.X},n.prototype.isYAxis=function(){return this.axis===n.Axis.Y},n.prototype.isBothAxis=function(){return this.axis===n.Axis.BOTH},n.prototype.applyFriction=function(t){return t.scale(this.friction)},n.prototype._canStartDrag=function(t){return this.isEnabled&&(n.isTouchEvent(t)||0===t.button)},n.prototype._canContinueDrag=function(){return this.isEnabled&&!this._isDeactivated},n.prototype._handleDragStart=function(t){(clearInterval(this._velocityTrackerId),this._canStartDrag(t))&&(this._setDragStartValues(n._getPageCoordinate(t)),this._emitEvent(this._createEvent(n.EventType.START,t))||(this._addDragHandlers(t.type),this._velocityTrackerId=setInterval(this._trackVelocity.bind(this),n.VELOCITY_INTERVAL)))},n.prototype._handleDragMove=function(t){this._canContinueDrag()&&(this._setDragMoveValues(n._getPageCoordinate(t)),this._emitEvent(this._createEvent(n.EventType.MOVE,t))||!this._shouldPreventDefault||this._isTouchActionSupported||this._finishDragMove(t))},n.prototype._finishDragMove=function(t){this._maybeLock(),this._maybeDeactivate(),this._isLocked&&t.preventDefault(),this._isDeactivated&&(clearInterval(this._velocityTrackerId),this.velocity.x=0,this.velocity.y=0)},n.prototype._handleDragEnd=function(t){clearInterval(this._velocityTrackerId),this.deltaTime=Date.now()-this.startTime,this._hasTrackedVelocity||this._trackVelocity(),this._removeDragHandlers();var e=this._createEvent(n.EventType.END,t);e.isCancelEvent=n._isCancelEvent(t),this._emitEvent(e)&&t.preventDefault(),this.hasDragged=!1,this._isDeactivated=!1,this._isLocked=!1},n.prototype._setDragStartValues=function(t){this.pageStart=t,this.page=t,this._lastPosition=t,this.delta=new i.Coordinate,this.velocity=new i.Coordinate,this._hasTrackedVelocity=!1,this.startTime=Date.now(),this._lastTime=Date.now(),this.deltaTime=0},n.prototype._setDragMoveValues=function(t){var e=i.Coordinate.difference(t,this.page);this.applyFriction(e),this.delta.translate(e),this.page=t,this.deltaTime=Date.now()-this.startTime,this.hasDragged=!0},n.prototype._maybeLock=function(){this._isLocked||(this._isLocked=this._shouldLock(this.delta))},n.prototype._maybeDeactivate=function(){this._isDeactivated||(this._isDeactivated=this._shouldDeactivate(this.delta))},n.prototype._shouldLock=function(t){var e=this.isXAxis()&&Math.abs(t.x)>n.LOCK_THRESHOLD,i=this.isYAxis()&&Math.abs(t.y)>n.LOCK_THRESHOLD;return this.isBothAxis()||e||i},n.prototype._shouldDeactivate=function(t){var e=this.isXAxis()&&Math.abs(t.y)>n.DRAG_THRESHOLD,i=this.isYAxis()&&Math.abs(t.x)>n.DRAG_THRESHOLD;return!this._isLocked&&(this.isBothAxis()||e||i)},n.prototype._createEvent=function(t,e){return new n.Event({type:t,pointerId:this.id,currentTarget:this.element,target:e.target,axis:this.axis,deltaTime:this.deltaTime,delta:this.delta,start:this.pageStart,end:this.page,currentVelocity:this.velocity})},n.prototype._addDragHandlers=function(t){var e=this.dragEventTarget;switch(this._onMove=this._handleDragMove.bind(this),this._onEnd=this._handleDragEnd.bind(this),t){case i.events.POINTERDOWN:e.addEventListener(i.events.POINTERMOVE,this._onMove),e.addEventListener(i.events.POINTERUP,this._onEnd),e.addEventListener(i.events.POINTERCANCEL,this._onEnd);break;case i.events.MOUSEDOWN:e.addEventListener(i.events.MOUSEMOVE,this._onMove),e.addEventListener(i.events.MOUSEUP,this._onEnd);break;case i.events.TOUCHSTART:e.addEventListener(i.events.TOUCHMOVE,this._onMove),e.addEventListener(i.events.TOUCHEND,this._onEnd),e.addEventListener(i.events.TOUCHCANCEL,this._onEnd)}},n.prototype._removeDragHandlers=function(){var t=this.dragEventTarget;t.removeEventListener(i.events.POINTERMOVE,this._onMove),t.removeEventListener(i.events.POINTERUP,this._onEnd),t.removeEventListener(i.events.POINTERCANCEL,this._onEnd),t.removeEventListener(i.events.MOUSEMOVE,this._onMove),t.removeEventListener(i.events.MOUSEUP,this._onEnd),t.removeEventListener(i.events.TOUCHMOVE,this._onMove),t.removeEventListener(i.events.TOUCHEND,this._onEnd),t.removeEventListener(i.events.TOUCHCANCEL,this._onEnd)},n.prototype._trackVelocity=function(){var t=Date.now(),e=t-this._lastTime,s=i.Coordinate.difference(this.page,this._lastPosition);this.applyFriction(s),this._lastTime=t,this._lastPosition=this.page;var o=n.MAX_VELOCITY;this.velocity.x=i.math.clamp(s.x/e,-o,o),this.velocity.y=i.math.clamp(s.y/e,-o,o),this._hasTrackedVelocity=!0},n.prototype.hasVelocity=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:n.SWIPE_VELOCITY;return this.isYAxis()?Math.abs(t.y)>e:this.isXAxis()?Math.abs(t.x)>e:Math.abs(t.x)>e||Math.abs(t.y)>e},n.prototype._emitEvent=function(t){return this.emit(t.type,t),t.defaultPrevented},n.prototype.dispose=function(){clearInterval(this._velocityTrackerId),this._removeDragHandlers(),this._el.removeEventListener(i.events.POINTERDOWN,this._onStart),this._el.removeEventListener(i.events.MOUSEDOWN,this._onStart),this._el.removeEventListener(i.events.TOUCHSTART,this._onStart),this._isTouchActionSupported?this._el.style[n.TouchActionSupport[this.axis]]="":this._shouldPreventDefault&&e.HAS_TOUCH_EVENTS&&window.removeEventListener(i.events.TOUCHMOVE,i.utilities.noop),this._el=null,this.dragEventTarget=null},n.isTouchEvent=function(t){return!!t.changedTouches},n._isCancelEvent=function(t){return t.type===i.events.POINTERCANCEL||t.type===i.events.TOUCHCANCEL},n._getPageCoordinate=function(t){var e=void 0;return e=n.isTouchEvent(t)?t.changedTouches[0]:t,new i.Coordinate(e.pageX,e.pageY)},n._preventDefault=function(t){t.preventDefault()},o(n,[{key:"element",get:function(){return this._el}},{key:"isEnabled",get:function(){return this._enabled},set:function(t){this._enabled=t}},{key:"friction",get:function(){return this._friction},set:function(t){this._friction=t}}]),n}(t);return Object.assign(_,n),_.Event=p,_});
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("@odopod/odo-device"),require("@odopod/odo-helpers"),require("tiny-emitter")):"function"==typeof define&&define.amd?define(["@odopod/odo-device","@odopod/odo-helpers","tiny-emitter"],e):t.OdoPointer=e(t.OdoDevice,t.OdoHelpers,t.TinyEmitter)}(this,function(t,e,i){"use strict";t=t&&t.hasOwnProperty("default")?t.default:t,i=i&&i.hasOwnProperty("default")?i.default:i;var n={EventType:{START:"odopointer:start",MOVE:"odopointer:move",END:"odopointer:end"},Direction:{RIGHT:"right",LEFT:"left",UP:"up",DOWN:"down",NONE:"no_movement"},TouchActionSupport:{x:t.prefixed("touchAction","pan-y"),y:t.prefixed("touchAction","pan-x"),xy:t.prefixed("touchAction","none")},TouchAction:{x:"pan-y",y:"pan-x",xy:"none"},Axis:{X:"x",Y:"y",BOTH:"xy"},Defaults:{axis:"xy",preventEventDefault:!0},MAX_VELOCITY:12,VELOCITY_INTERVAL:100,SWIPE_VELOCITY:.6,LOCK_THRESHOLD:6,DRAG_THRESHOLD:5},s=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},o=function(){function t(t,e){for(var i=0;i<e.length;i++){var n=e[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}return function(e,i,n){return i&&t(e.prototype,i),n&&t(e,n),e}}(),r=function(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e};function a(t){return t===n.Axis.X}function h(t){return t===n.Axis.Y}function c(t){return t===n.Axis.BOTH}function d(t){return t!==n.Direction.NONE}function u(t){return Number.isFinite(t)?t:0}function v(t,e,i,n,s){return t-e>0?i:t-e<0?n:s}function l(t,e){return Math.abs(t.x-e.x)>=Math.abs(t.y-e.y)?v(t.x,e.x,n.Direction.LEFT,n.Direction.RIGHT,n.Direction.NONE):v(t.y,e.y,n.Direction.UP,n.Direction.DOWN,n.Direction.NONE)}var p=function(){function t(i){var o,r,v,p,_,E,T,f;s(this,t),this.type=i.type,this.target=i.target,this.currentTarget=i.currentTarget,this.start=i.start,this.end=i.end,this.delta=i.delta,this.deltaTime=i.deltaTime,this.velocity=(o=this.deltaTime,r=this.delta.x,v=this.delta.y,new e.Coordinate(u(r/o),u(v/o))),this.currentVelocity=i.currentVelocity,this.distance=e.Coordinate.distance(i.start,i.end),this.direction=l(i.start,i.end),this.isDirectionOnAxis=(p=i.axis,_=this.direction,E=a(p)&&(_===n.Direction.LEFT||_===n.Direction.RIGHT),T=h(p)&&(_===n.Direction.UP||_===n.Direction.DOWN),f=c(p)&&d(_),E||T||f),this.didMoveOnAxis=function(t,e,i,n){return a(t)&&Math.abs(i)>0||h(t)&&Math.abs(n)>0||c(t)&&d(e)}(i.axis,this.direction,this.delta.x,this.delta.y),this.axisDirection=function(t,e,i){var n=Object.assign({},e),s=Object.assign({},i);return a(t)?(n.y=0,s.y=0):h(t)&&(n.x=0,s.x=0),l(n,s)}(i.axis,i.start,i.end),this.position=i.position,this.defaultPrevented=!1}return t.prototype.preventDefault=function(){this.defaultPrevented=!0},t}(),_=function(i){function n(o){var a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};s(this,n);var h=r(this,i.call(this));if(!o||1!==o.nodeType)throw new TypeError("OdoPointer requires an element.");var c=Object.assign({},n.Defaults,a);h._shouldPreventDefault=c.preventEventDefault,h._el=o,h.pageStart=new e.Coordinate,h.page=new e.Coordinate,h.delta=new e.Coordinate,h._lastPosition=new e.Coordinate,h._friction=1,h.axis=c.axis,h.hasDragged=!1,h._isLocked=!1,h._isDeactivated=!1,h._enabled=!0,h._velocityTrackerId=null,h.startTime=0,h.deltaTime=0,h._lastTime=0,h.velocity=new e.Coordinate,h._hasTrackedVelocity=!1,h.dragEventTarget=document;var d=n.TouchActionSupport[h.axis];return h._isTouchActionSupported=!!d,h._shouldPreventDefault&&h._isTouchActionSupported?h.element.style[d]=n.TouchAction[h.axis]:h._shouldPreventDefault&&t.HAS_TOUCH_EVENTS&&window.addEventListener(e.events.TOUCHMOVE,e.noop),h.listen(),h}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}(n,i),n.prototype.listen=function(){this._onStart=this._handleDragStart.bind(this),t.HAS_POINTER_EVENTS?this._el.addEventListener(e.events.POINTERDOWN,this._onStart):(this._el.addEventListener(e.events.MOUSEDOWN,this._onStart),t.HAS_TOUCH_EVENTS&&this._el.addEventListener(e.events.TOUCHSTART,this._onStart)),this._el.addEventListener(e.events.DRAGSTART,n._preventDefault)},n.prototype.isXAxis=function(){return this.axis===n.Axis.X},n.prototype.isYAxis=function(){return this.axis===n.Axis.Y},n.prototype.isBothAxis=function(){return this.axis===n.Axis.BOTH},n.prototype.applyFriction=function(t){return t.scale(this.friction)},n.prototype._canStartDrag=function(t){return this.isEnabled&&(n.isTouchEvent(t)||0===t.button)},n.prototype._canContinueDrag=function(){return this.isEnabled&&!this._isDeactivated},n.prototype._handleDragStart=function(t){(clearInterval(this._velocityTrackerId),this._canStartDrag(t))&&(this._setDragStartValues(n._getPageCoordinate(t)),this._emitEvent(this._createEvent(n.EventType.START,t))||(this._addDragHandlers(t.type),this._velocityTrackerId=setInterval(this._trackVelocity.bind(this),n.VELOCITY_INTERVAL)))},n.prototype._handleDragMove=function(t){this._canContinueDrag()&&(this._setDragMoveValues(n._getPageCoordinate(t)),this._emitEvent(this._createEvent(n.EventType.MOVE,t))||!this._shouldPreventDefault||this._isTouchActionSupported||this._finishDragMove(t))},n.prototype._finishDragMove=function(t){this._maybeLock(),this._maybeDeactivate(),this._isLocked&&t.preventDefault(),this._isDeactivated&&(clearInterval(this._velocityTrackerId),this.velocity.x=0,this.velocity.y=0)},n.prototype._handleDragEnd=function(t){clearInterval(this._velocityTrackerId),this.deltaTime=Date.now()-this.startTime,this._hasTrackedVelocity||this._trackVelocity(),this._removeDragHandlers();var e=this._createEvent(n.EventType.END,t);e.isCancelEvent=n._isCancelEvent(t),this._emitEvent(e)&&t.preventDefault(),this.hasDragged=!1,this._isDeactivated=!1,this._isLocked=!1},n.prototype._setDragStartValues=function(t){this.pageStart=t,this.page=t,this._lastPosition=t,this.delta=new e.Coordinate,this.velocity=new e.Coordinate,this._hasTrackedVelocity=!1,this.startTime=Date.now(),this._lastTime=Date.now(),this.deltaTime=0},n.prototype._setDragMoveValues=function(t){var i=e.Coordinate.difference(t,this.page);this.applyFriction(i),this.delta.translate(i),this.page=t,this.deltaTime=Date.now()-this.startTime,this.hasDragged=!0},n.prototype._maybeLock=function(){this._isLocked||(this._isLocked=this._shouldLock(this.delta))},n.prototype._maybeDeactivate=function(){this._isDeactivated||(this._isDeactivated=this._shouldDeactivate(this.delta))},n.prototype._shouldLock=function(t){var e=this.isXAxis()&&Math.abs(t.x)>n.LOCK_THRESHOLD,i=this.isYAxis()&&Math.abs(t.y)>n.LOCK_THRESHOLD;return this.isBothAxis()||e||i},n.prototype._shouldDeactivate=function(t){var e=this.isXAxis()&&Math.abs(t.y)>n.DRAG_THRESHOLD,i=this.isYAxis()&&Math.abs(t.x)>n.DRAG_THRESHOLD;return!this._isLocked&&(this.isBothAxis()||e||i)},n.prototype._createEvent=function(t,e){return new n.Event({type:t,pointerId:this.id,currentTarget:this.element,target:e.target,axis:this.axis,deltaTime:this.deltaTime,delta:this.delta,start:this.pageStart,end:this.page,currentVelocity:this.velocity})},n.prototype._addDragHandlers=function(t){var i=this.dragEventTarget;switch(this._onMove=this._handleDragMove.bind(this),this._onEnd=this._handleDragEnd.bind(this),t){case e.events.POINTERDOWN:i.addEventListener(e.events.POINTERMOVE,this._onMove),i.addEventListener(e.events.POINTERUP,this._onEnd),i.addEventListener(e.events.POINTERCANCEL,this._onEnd);break;case e.events.MOUSEDOWN:i.addEventListener(e.events.MOUSEMOVE,this._onMove),i.addEventListener(e.events.MOUSEUP,this._onEnd);break;case e.events.TOUCHSTART:i.addEventListener(e.events.TOUCHMOVE,this._onMove),i.addEventListener(e.events.TOUCHEND,this._onEnd),i.addEventListener(e.events.TOUCHCANCEL,this._onEnd)}},n.prototype._removeDragHandlers=function(){var t=this.dragEventTarget;t.removeEventListener(e.events.POINTERMOVE,this._onMove),t.removeEventListener(e.events.POINTERUP,this._onEnd),t.removeEventListener(e.events.POINTERCANCEL,this._onEnd),t.removeEventListener(e.events.MOUSEMOVE,this._onMove),t.removeEventListener(e.events.MOUSEUP,this._onEnd),t.removeEventListener(e.events.TOUCHMOVE,this._onMove),t.removeEventListener(e.events.TOUCHEND,this._onEnd),t.removeEventListener(e.events.TOUCHCANCEL,this._onEnd)},n.prototype._trackVelocity=function(){var t=Date.now(),i=t-this._lastTime,s=e.Coordinate.difference(this.page,this._lastPosition);this.applyFriction(s),this._lastTime=t,this._lastPosition=this.page;var o=n.MAX_VELOCITY;this.velocity.x=e.clamp(s.x/i,-o,o),this.velocity.y=e.clamp(s.y/i,-o,o),this._hasTrackedVelocity=!0},n.prototype.hasVelocity=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:n.SWIPE_VELOCITY;return this.isYAxis()?Math.abs(t.y)>e:this.isXAxis()?Math.abs(t.x)>e:Math.abs(t.x)>e||Math.abs(t.y)>e},n.prototype._emitEvent=function(t){return this.emit(t.type,t),t.defaultPrevented},n.prototype.dispose=function(){clearInterval(this._velocityTrackerId),this._removeDragHandlers(),this._el.removeEventListener(e.events.POINTERDOWN,this._onStart),this._el.removeEventListener(e.events.MOUSEDOWN,this._onStart),this._el.removeEventListener(e.events.TOUCHSTART,this._onStart),this._isTouchActionSupported?this._el.style[n.TouchActionSupport[this.axis]]="":this._shouldPreventDefault&&t.HAS_TOUCH_EVENTS&&window.removeEventListener(e.events.TOUCHMOVE,e.noop),this._el=null,this.dragEventTarget=null},n.isTouchEvent=function(t){return!!t.changedTouches},n._isCancelEvent=function(t){return t.type===e.events.POINTERCANCEL||t.type===e.events.TOUCHCANCEL},n._getPageCoordinate=function(t){var i=void 0;return i=n.isTouchEvent(t)?t.changedTouches[0]:t,new e.Coordinate(i.pageX,i.pageY)},n._preventDefault=function(t){t.preventDefault()},o(n,[{key:"element",get:function(){return this._el}},{key:"isEnabled",get:function(){return this._enabled},set:function(t){this._enabled=t}},{key:"friction",get:function(){return this._friction},set:function(t){this._friction=t}}]),n}(i);return Object.assign(_,n),_.Event=p,_});
//# sourceMappingURL=odo-pointer.min.js.map
{
"name": "@odopod/odo-pointer",
"description": "An abstraction for pointer, mouse, and touch events.",
"version": "1.0.3",
"version": "1.1.0",
"main": "dist/odo-pointer.js",
"module": "dist/odo-pointer.esm.js",
"odoModule": "src/pointer.js",
"sideEffects": false,
"author": "Odopod",

@@ -15,4 +17,4 @@ "contributors": [

"dependencies": {
"@odopod/odo-device": "^1.0.3",
"@odopod/odo-helpers": "^1.0.3",
"@odopod/odo-device": "^1.1.0",
"@odopod/odo-helpers": "^2.0.0",
"tiny-emitter": "^2.0.1"

@@ -24,4 +26,3 @@ },

"dist",
"src",
"index.js"
"src"
],

@@ -28,0 +29,0 @@ "odoKeywords": [

@@ -9,3 +9,8 @@ /**

import OdoDevice from '@odopod/odo-device';
import { Coordinate, events, math, utilities } from '@odopod/odo-helpers';
import {
clamp,
Coordinate,
events,
noop,
} from '@odopod/odo-helpers';
import settings from './settings';

@@ -174,3 +179,3 @@ import PointerEvent from './pointer-event';

} else if (this._shouldPreventDefault && OdoDevice.HAS_TOUCH_EVENTS) {
window.addEventListener(events.TOUCHMOVE, utilities.noop);
window.addEventListener(events.TOUCHMOVE, noop);
}

@@ -567,4 +572,4 @@

const maxVelocity = Pointer.MAX_VELOCITY;
this.velocity.x = math.clamp(delta.x / elapsed, -maxVelocity, maxVelocity);
this.velocity.y = math.clamp(delta.y / elapsed, -maxVelocity, maxVelocity);
this.velocity.x = clamp(delta.x / elapsed, -maxVelocity, maxVelocity);
this.velocity.y = clamp(delta.y / elapsed, -maxVelocity, maxVelocity);

@@ -620,3 +625,3 @@ this._hasTrackedVelocity = true;

} else if (this._shouldPreventDefault && OdoDevice.HAS_TOUCH_EVENTS) {
window.removeEventListener(events.TOUCHMOVE, utilities.noop);
window.removeEventListener(events.TOUCHMOVE, noop);
}

@@ -623,0 +628,0 @@

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