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

@odopod/odo-draggable

Package Overview
Dependencies
Maintainers
3
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@odopod/odo-draggable - npm Package Compare versions

Comparing version 1.0.3 to 1.0.4

2

dist/odo-draggable.min.js

@@ -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-pointer"),require("@odopod/odo-helpers")):"function"==typeof define&&define.amd?define(["tiny-emitter","@odopod/odo-device","@odopod/odo-pointer","@odopod/odo-helpers"],e):t.OdoDraggable=e(t.TinyEmitter,t.OdoDevice,t.OdoPointer,t.OdoHelpers)}(this,function(t,e,i,o){"use strict";function n(t,e){if(!t)throw new Error(e)}t=t&&t.hasOwnProperty("default")?t.default:t,e=e&&e.hasOwnProperty("default")?e.default:e;var r={EventType:{START:"ododraggable:start",MOVE:"ododraggable:move",END:"ododraggable:end",SETTLE:"ododraggable:throwsettle"},Classes:{GRABBABLE:"grabbable",GRABBING:"grabbing"},Defaults:{axis:(i=i&&i.hasOwnProperty("default")?i.default:i).Axis.X,amplifier:24,velocityStop:.08,throwFriction:.94,isThrowable:!1}},s=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},a=function(){function t(t,e){for(var i=0;i<e.length;i++){var o=e[i];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,o.key,o)}}return function(e,i,o){return i&&t(e.prototype,i),o&&t(e,o),e}}(),h=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},l=function(t){function l(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};s(this,l);var r=h(this,t.call(this));return r.element=e,r.options=Object.assign({},l.Defaults,n),r._parentEl=e.parentNode,r._currentPosition=new o.Coordinate,r._relativeZero=new o.Coordinate,r._throwVelocity=new o.Coordinate,r._delta=new o.Coordinate,r._requestId=0,r._container={width:0,height:0},r.limits=new o.math.Rect(NaN,NaN,NaN,NaN),r.pointer=new i(e,{axis:r.options.axis}),r.element.classList.add(l.Classes.GRABBABLE),r._listen(),r}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)}(l,t),l.prototype._listen=function(){this._onStart=this._handleDragStart.bind(this),this._onMove=this._handleDragMove.bind(this),this._onEnd=this._handleDragEnd.bind(this),this.pointer.on(i.EventType.START,this._onStart),this.pointer.on(i.EventType.MOVE,this._onMove),this.pointer.on(i.EventType.END,this._onEnd)},l.prototype._saveDimensions=function(){this._container=o.style.getSize(this.element),function(t){n(t.width>0,"containing element's width is zero"),n(t.height>0,"containing element's height is zero")}(this._container),this._relativeZero=this._getRelativeZero()},l.prototype._getRelativeZero=function(){return o.Coordinate.difference(this._getDraggablePosition(),this._getOffsetCorrection())},l.prototype._getDraggablePosition=function(){var t=this.element.getBoundingClientRect();return new o.Coordinate(t.left,t.top)},l.prototype._getOffsetCorrection=function(){var t=this._parentEl.getBoundingClientRect(),e=o.style.getPaddingBox(this._parentEl),i=o.style.getMarginBox(this.element),n=i.left+e.left+t.left,r=i.top+e.top+t.top;return new o.Coordinate(n,r)},l.prototype._setCurrentPosition=function(t){this.pointer.applyFriction(t);var e=this._limitX(t.x/100*this._parentEl.offsetWidth),i=this._limitY(t.y/100*this._parentEl.offsetHeight);this._currentPosition=this._getAxisCoordinate(Math.round(e),Math.round(i))},l._limitValue=function(t,e,i){var n=o.utilities.defaultsTo(e,null,!Number.isNaN(e)),r=o.utilities.defaultsTo(i,0,!Number.isNaN(i)),s=o.utilities.defaultsTo(n+r,1/0,null!==n),a=o.utilities.defaultsTo(n,-1/0,null!==n);return o.math.clamp(t,a,s)},l.prototype._limitX=function(t){return l._limitValue(t,this.limits.left,this.limits.width)},l.prototype._limitY=function(t){return l._limitValue(t,this.limits.top,this.limits.height)},l.prototype._getElementPosition=function(t){t&&this._setCurrentPosition(t);var e=this._currentPosition.x/this._container.width*100,i=this._currentPosition.y/this._container.height*100;return this._getAxisCoordinate(e,i)},l.prototype._getAxisCoordinate=function(t,e){return this.pointer.isXAxis()?new o.Coordinate(t,0):this.pointer.isYAxis()?new o.Coordinate(0,e):new o.Coordinate(t,e)},l.prototype._getNewLimitedPosition=function(t){var e=o.Coordinate.sum(this._relativeZero,t);return new o.Coordinate(this._limitX(e.x),this._limitY(e.y))},l.prototype._handleDragStart=function(t){this._stopThrow(),this._saveDimensions(),this._currentPosition=this._relativeZero,this._emitEvent(this._createEvent(l.EventType.START,t)),this.element.classList.add(l.Classes.GRABBING)},l.prototype._handleDragMove=function(t){this._currentPosition=this._getNewLimitedPosition(this.pointer.delta),this._emitEvent(this._createEvent(l.EventType.MOVE,t)),this.pointer._isDeactivated||this._applyPosition()},l.prototype._handleDragEnd=function(t){this._emitEvent(this._createEvent(l.EventType.END,t)),this.element.classList.remove(l.Classes.GRABBING),this.options.isThrowable&&this.pointer.hasVelocity(t.currentVelocity,0)&&this._throw(t.currentVelocity,t.delta)},l.prototype._throw=function(t,e){this._delta=e,this._throwVelocity=o.Coordinate.scale(t,this.options.amplifier),this._animateThrow()},l.prototype._animateThrow=function(){this.pointer.hasVelocity(this._throwVelocity,this.options.velocityStop)?(this._currentPosition=this._getNewLimitedPosition(this._delta),this._applyPosition(),this._delta.translate(this._throwVelocity),this._throwVelocity.scale(this.options.throwFriction),this._requestId=requestAnimationFrame(this._animateThrow.bind(this))):(this._currentPosition.x=Math.round(this._currentPosition.x),this._currentPosition.y=Math.round(this._currentPosition.y),this._applyPosition(),this._emitSettled())},l.prototype._stopThrow=function(){this._delta=new o.Coordinate,this._throwVelocity=new o.Coordinate,cancelAnimationFrame(this._requestId)},l.prototype._emitSettled=function(){this._emitEvent(new i.Event({type:l.EventType.SETTLE,target:this.element,axis:this.pointer.axis,deltaTime:Date.now()-this.pointer.startTime,delta:o.Coordinate.difference(this._relativeZero,this._currentPosition),start:this._relativeZero,end:this._currentPosition,currentVelocity:this._throwVelocity,position:{pixel:this.getPosition(),percent:this.getPosition(!0)}}))},l.prototype._createEvent=function(t,e){return new i.Event({type:t,target:e.target,currentTarget:this.element,axis:this.pointer.axis,deltaTime:this.pointer.deltaTime,delta:o.Coordinate.difference(this._currentPosition,this._relativeZero),start:this._relativeZero,end:this._currentPosition,currentVelocity:this.pointer.velocity,position:{pixel:this.getPosition(),percent:this.getPosition(!0)}})},l.prototype._applyPosition=function(t){var i=this._getElementPosition(t);return this.element.style[e.Dom.TRANSFORM]="translate("+i.x+"%,"+i.y+"%)",this._currentPosition},l.prototype.getPosition=function(t){return t?new o.Coordinate(this._currentPosition.x/this._parentEl.offsetWidth*100,this._currentPosition.y/this._parentEl.offsetHeight*100):this._currentPosition},l.prototype.setPosition=function(t,e){return this.update(),this._applyPosition(new o.Coordinate(t,e))},l.prototype.setLimits=function(t){this.limits=t},l.prototype.update=function(){this._saveDimensions()},l.prototype.dispose=function(){this.pointer.off(i.EventType.START,this._onStart),this.pointer.off(i.EventType.MOVE,this._onMove),this.pointer.off(i.EventType.END,this._onEnd),this.pointer.dispose(),this.element.classList.remove(l.Classes.GRABBABLE),this._parentEl=null,this.element=null},l.prototype._emitEvent=function(t){return this.emit(t.type,t),t.defaultPrevented},a(l,[{key:"friction",get:function(){return this.pointer.friction},set:function(t){this.pointer.friction=t}},{key:"isEnabled",get:function(){return this.pointer.isEnabled},set:function(t){this.pointer.isEnabled=t,this.element.classList.toggle(r.Classes.GRABBABLE,t)}}]),l}(t);return Object.assign(l,r),l});
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("tiny-emitter"),require("@odopod/odo-device"),require("@odopod/odo-pointer"),require("@odopod/odo-helpers")):"function"==typeof define&&define.amd?define(["tiny-emitter","@odopod/odo-device","@odopod/odo-pointer","@odopod/odo-helpers"],e):t.OdoDraggable=e(t.TinyEmitter,t.OdoDevice,t.OdoPointer,t.OdoHelpers)}(this,function(t,e,i,o){"use strict";t=t&&t.hasOwnProperty("default")?t.default:t,e=e&&e.hasOwnProperty("default")?e.default:e;var n={EventType:{START:"ododraggable:start",MOVE:"ododraggable:move",END:"ododraggable:end",SETTLE:"ododraggable:throwsettle"},Classes:{GRABBABLE:"grabbable",GRABBING:"grabbing"},Defaults:{axis:(i=i&&i.hasOwnProperty("default")?i.default:i).Axis.X,amplifier:24,velocityStop:.08,throwFriction:.94,isThrowable:!1}},r=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},s=function(){function t(t,e){for(var i=0;i<e.length;i++){var o=e[i];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,o.key,o)}}return function(e,i,o){return i&&t(e.prototype,i),o&&t(e,o),e}}(),a=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 h(t,e){if(!t)throw new Error(e)}var l=function(t){function l(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};r(this,l);var s=a(this,t.call(this));return s.element=e,s.options=Object.assign({},l.Defaults,n),s._parentEl=e.parentNode,s._currentPosition=new o.Coordinate,s._relativeZero=new o.Coordinate,s._throwVelocity=new o.Coordinate,s._delta=new o.Coordinate,s._requestId=0,s._container={width:0,height:0},s.limits=new o.math.Rect(NaN,NaN,NaN,NaN),s.pointer=new i(e,{axis:s.options.axis}),s.element.classList.add(l.Classes.GRABBABLE),s._listen(),s}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)}(l,t),l.prototype._listen=function(){this._onStart=this._handleDragStart.bind(this),this._onMove=this._handleDragMove.bind(this),this._onEnd=this._handleDragEnd.bind(this),this.pointer.on(i.EventType.START,this._onStart),this.pointer.on(i.EventType.MOVE,this._onMove),this.pointer.on(i.EventType.END,this._onEnd)},l.prototype._saveDimensions=function(){var t;this._container=o.style.getSize(this.element),h((t=this._container).width>0,"containing element's width is zero"),h(t.height>0,"containing element's height is zero"),this._relativeZero=this._getRelativeZero()},l.prototype._getRelativeZero=function(){return o.Coordinate.difference(this._getDraggablePosition(),this._getOffsetCorrection())},l.prototype._getDraggablePosition=function(){var t=this.element.getBoundingClientRect();return new o.Coordinate(t.left,t.top)},l.prototype._getOffsetCorrection=function(){var t=this._parentEl.getBoundingClientRect(),e=o.style.getPaddingBox(this._parentEl),i=o.style.getMarginBox(this.element),n=i.left+e.left+t.left,r=i.top+e.top+t.top;return new o.Coordinate(n,r)},l.prototype._setCurrentPosition=function(t){this.pointer.applyFriction(t);var e=this._limitX(t.x/100*this._parentEl.offsetWidth),i=this._limitY(t.y/100*this._parentEl.offsetHeight);this._currentPosition=this._getAxisCoordinate(Math.round(e),Math.round(i))},l._limitValue=function(t,e,i){var n=o.utilities.defaultsTo(e,null,!Number.isNaN(e)),r=o.utilities.defaultsTo(i,0,!Number.isNaN(i)),s=o.utilities.defaultsTo(n+r,1/0,null!==n),a=o.utilities.defaultsTo(n,-1/0,null!==n);return o.math.clamp(t,a,s)},l.prototype._limitX=function(t){return l._limitValue(t,this.limits.left,this.limits.width)},l.prototype._limitY=function(t){return l._limitValue(t,this.limits.top,this.limits.height)},l.prototype._getElementPosition=function(t){t&&this._setCurrentPosition(t);var e=this._currentPosition.x/this._container.width*100,i=this._currentPosition.y/this._container.height*100;return this._getAxisCoordinate(e,i)},l.prototype._getAxisCoordinate=function(t,e){return this.pointer.isXAxis()?new o.Coordinate(t,0):this.pointer.isYAxis()?new o.Coordinate(0,e):new o.Coordinate(t,e)},l.prototype._getNewLimitedPosition=function(t){var e=o.Coordinate.sum(this._relativeZero,t);return new o.Coordinate(this._limitX(e.x),this._limitY(e.y))},l.prototype._handleDragStart=function(t){this._stopThrow(),this._saveDimensions(),this._currentPosition=this._relativeZero,this._emitEvent(this._createEvent(l.EventType.START,t)),this.element.classList.add(l.Classes.GRABBING)},l.prototype._handleDragMove=function(t){this._currentPosition=this._getNewLimitedPosition(this.pointer.delta),this._emitEvent(this._createEvent(l.EventType.MOVE,t)),this.pointer._isDeactivated||this._applyPosition()},l.prototype._handleDragEnd=function(t){this._emitEvent(this._createEvent(l.EventType.END,t)),this.element.classList.remove(l.Classes.GRABBING),this.options.isThrowable&&this.pointer.hasVelocity(t.currentVelocity,0)&&this._throw(t.currentVelocity,t.delta)},l.prototype._throw=function(t,e){this._delta=e,this._throwVelocity=o.Coordinate.scale(t,this.options.amplifier),this._animateThrow()},l.prototype._animateThrow=function(){this.pointer.hasVelocity(this._throwVelocity,this.options.velocityStop)?(this._currentPosition=this._getNewLimitedPosition(this._delta),this._applyPosition(),this._delta.translate(this._throwVelocity),this._throwVelocity.scale(this.options.throwFriction),this._requestId=requestAnimationFrame(this._animateThrow.bind(this))):(this._currentPosition.x=Math.round(this._currentPosition.x),this._currentPosition.y=Math.round(this._currentPosition.y),this._applyPosition(),this._emitSettled())},l.prototype._stopThrow=function(){this._delta=new o.Coordinate,this._throwVelocity=new o.Coordinate,cancelAnimationFrame(this._requestId)},l.prototype._emitSettled=function(){this._emitEvent(new i.Event({type:l.EventType.SETTLE,target:this.element,axis:this.pointer.axis,deltaTime:Date.now()-this.pointer.startTime,delta:o.Coordinate.difference(this._relativeZero,this._currentPosition),start:this._relativeZero,end:this._currentPosition,currentVelocity:this._throwVelocity,position:{pixel:this.getPosition(),percent:this.getPosition(!0)}}))},l.prototype._createEvent=function(t,e){return new i.Event({type:t,target:e.target,currentTarget:this.element,axis:this.pointer.axis,deltaTime:this.pointer.deltaTime,delta:o.Coordinate.difference(this._currentPosition,this._relativeZero),start:this._relativeZero,end:this._currentPosition,currentVelocity:this.pointer.velocity,position:{pixel:this.getPosition(),percent:this.getPosition(!0)}})},l.prototype._applyPosition=function(t){var i=this._getElementPosition(t);return this.element.style[e.Dom.TRANSFORM]="translate("+i.x+"%,"+i.y+"%)",this._currentPosition},l.prototype.getPosition=function(t){return t?new o.Coordinate(this._currentPosition.x/this._parentEl.offsetWidth*100,this._currentPosition.y/this._parentEl.offsetHeight*100):this._currentPosition},l.prototype.setPosition=function(t,e){return this.update(),this._applyPosition(new o.Coordinate(t,e))},l.prototype.setLimits=function(t){this.limits=t},l.prototype.update=function(){this._saveDimensions()},l.prototype.dispose=function(){this.pointer.off(i.EventType.START,this._onStart),this.pointer.off(i.EventType.MOVE,this._onMove),this.pointer.off(i.EventType.END,this._onEnd),this.pointer.dispose(),this.element.classList.remove(l.Classes.GRABBABLE),this._parentEl=null,this.element=null},l.prototype._emitEvent=function(t){return this.emit(t.type,t),t.defaultPrevented},s(l,[{key:"friction",get:function(){return this.pointer.friction},set:function(t){this.pointer.friction=t}},{key:"isEnabled",get:function(){return this.pointer.isEnabled},set:function(t){this.pointer.isEnabled=t,this.element.classList.toggle(n.Classes.GRABBABLE,t)}}]),l}(t);return Object.assign(l,n),l});
//# sourceMappingURL=odo-draggable.min.js.map
{
"name": "@odopod/odo-draggable",
"description": "A class for versatile, performant draggability.",
"version": "1.0.3",
"version": "1.0.4",
"main": "dist/odo-draggable.js",

@@ -15,5 +15,5 @@ "odoModule": "src/draggable.js",

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

@@ -39,3 +39,3 @@ },

"license": "MIT",
"repository": "odopod/odo",
"repository": "odopod/code-library",
"scripts": {

@@ -42,0 +42,0 @@ "test": "gulp code-quality test"

@@ -23,2 +23,2 @@ # Odo Draggable

[permalink]: https://code.odopod.com/odo-draggable/
[permalink]: http://code.odopod.com/odo-draggable/

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