@odopod/odo-draggable
Advanced tools
Comparing version 1.0.2 to 1.0.3
@@ -673,2 +673,3 @@ (function (global, factory) { | ||
this.pointer.isEnabled = enabled; | ||
this.element.classList.toggle(settings.Classes.GRABBABLE, enabled); | ||
} | ||
@@ -675,0 +676,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-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)}function r(t){n(t.width>0,"containing element's width is zero"),n(t.height>0,"containing element's height is zero")}t=t&&t.hasOwnProperty("default")?t.default:t,e=e&&e.hasOwnProperty("default")?e.default:e;var s={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}},a=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},h=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}}(),l=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)},p=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},u=function(t){function n(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};a(this,n);var s=p(this,t.call(this));return s.element=e,s.options=Object.assign({},n.Defaults,r),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(n.Classes.GRABBABLE),s._listen(),s}return l(n,t),n.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)},n.prototype._saveDimensions=function(){this._container=o.style.getSize(this.element),r(this._container),this._relativeZero=this._getRelativeZero()},n.prototype._getRelativeZero=function(){return o.Coordinate.difference(this._getDraggablePosition(),this._getOffsetCorrection())},n.prototype._getDraggablePosition=function(){var t=this.element.getBoundingClientRect();return new o.Coordinate(t.left,t.top)},n.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)},n.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))},n._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)},n.prototype._limitX=function(t){return n._limitValue(t,this.limits.left,this.limits.width)},n.prototype._limitY=function(t){return n._limitValue(t,this.limits.top,this.limits.height)},n.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)},n.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)},n.prototype._getNewLimitedPosition=function(t){var e=o.Coordinate.sum(this._relativeZero,t);return new o.Coordinate(this._limitX(e.x),this._limitY(e.y))},n.prototype._handleDragStart=function(t){this._stopThrow(),this._saveDimensions(),this._currentPosition=this._relativeZero,this._emitEvent(this._createEvent(n.EventType.START,t)),this.element.classList.add(n.Classes.GRABBING)},n.prototype._handleDragMove=function(t){this._currentPosition=this._getNewLimitedPosition(this.pointer.delta),this._emitEvent(this._createEvent(n.EventType.MOVE,t)),this.pointer._isDeactivated||this._applyPosition()},n.prototype._handleDragEnd=function(t){this._emitEvent(this._createEvent(n.EventType.END,t)),this.element.classList.remove(n.Classes.GRABBING),this.options.isThrowable&&this.pointer.hasVelocity(t.currentVelocity,0)&&this._throw(t.currentVelocity,t.delta)},n.prototype._throw=function(t,e){this._delta=e,this._throwVelocity=o.Coordinate.scale(t,this.options.amplifier),this._animateThrow()},n.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())},n.prototype._stopThrow=function(){this._delta=new o.Coordinate,this._throwVelocity=new o.Coordinate,cancelAnimationFrame(this._requestId)},n.prototype._emitSettled=function(){this._emitEvent(new i.Event({type:n.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)}}))},n.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)}})},n.prototype._applyPosition=function(t){var i=this._getElementPosition(t);return this.element.style[e.Dom.TRANSFORM]="translate("+i.x+"%,"+i.y+"%)",this._currentPosition},n.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},n.prototype.setPosition=function(t,e){return this.update(),this._applyPosition(new o.Coordinate(t,e))},n.prototype.setLimits=function(t){this.limits=t},n.prototype.update=function(){this._saveDimensions()},n.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(n.Classes.GRABBABLE),this._parentEl=null,this.element=null},n.prototype._emitEvent=function(t){return this.emit(t.type,t),t.defaultPrevented},h(n,[{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}}]),n}(t);return Object.assign(u,s),u}); | ||
!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}); | ||
//# sourceMappingURL=odo-draggable.min.js.map |
{ | ||
"name": "@odopod/odo-draggable", | ||
"description": "A class for versatile, performant draggability.", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"main": "dist/odo-draggable.js", | ||
@@ -6,0 +6,0 @@ "odoModule": "src/draggable.js", |
@@ -479,2 +479,3 @@ import TinyEmitter from 'tiny-emitter'; | ||
this.pointer.isEnabled = enabled; | ||
this.element.classList.toggle(settings.Classes.GRABBABLE, enabled); | ||
} | ||
@@ -481,0 +482,0 @@ |
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
96541
1075