!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("rxjs"),require("@angular/core")):"function"==typeof define&&define.amd?define("angular2-draggable",["exports","rxjs","@angular/core"],e):e(t["angular2-draggable"]={},t.rxjs,t.ng.core)}(this,function(t,i,n){"use strict";var s=function(){function r(t,e){this.x=t,this.y=e}return r.fromEvent=function(t,e){if(void 0===e&&(e=null),this.isMouseEvent(t))return new r(t.clientX,t.clientY);if(null===e||1===t.changedTouches.length)return new r(t.changedTouches[0].clientX,t.changedTouches[0].clientY);for(var i=0;ie.right,bottom:!!this.outOfBounds.bottom||t.bottom>e.bottom,left:!!this.outOfBounds.left||t.left=t.length&&(t=void 0),{value:t&&t[i++],done:!t}}}}var h=function(){function t(t,e,i,n,s){var r=this;this.parent=t,this.renderer=e,this.type=i,this.css=n,this.onMouseDown=s;var o=e.createElement("div");e.addClass(o,"ng-resizable-handle"),e.addClass(o,n),"se"===i&&e.addClass(o,"ng-resizable-diagonal"),this.parent&&t.appendChild(o),this._onResize=function(t){s(t,r)},o.addEventListener("mousedown",this._onResize,{passive:!1}),o.addEventListener("touchstart",this._onResize,{passive:!1}),this._handle=o}return t.prototype.dispose=function(){this._handle.removeEventListener("mousedown",this._onResize),this._handle.removeEventListener("touchstart",this._onResize),this.parent&&this.parent.removeChild(this._handle),this._handle=null,this._onResize=null},Object.defineProperty(t.prototype,"el",{get:function(){return this._handle},enumerable:!0,configurable:!0}),t}(),a=function(){function n(t,e){this.width=t,this.height=e}return n.getCurrent=function(t){var e=new n(0,0);if(window){var i=window.getComputedStyle(t);return i&&(e.width=parseInt(i.getPropertyValue("width"),10),e.height=parseInt(i.getPropertyValue("height"),10)),e}return console.error("Not Supported!"),null},n.copy=function(t){return new n(0,0).set(t)},n.prototype.set=function(t){return this.width=t.width,this.height=t.height,this},n}(),u=function(){function t(t,e){this.el=t,this.renderer=e,this._resizable=!0,this._handles={},this._handleType=[],this._handleResizing=null,this._direction=null,this._directionChanged=null,this._aspectRatio=0,this._containment=null,this._origMousePos=null,this._origSize=null,this._origPos=null,this._currSize=null,this._currPos=null,this._initSize=null,this._initPos=null,this._gridSize=null,this._bounding=null,this._helperBlock=null,this.draggingSub=null,this._adjusted=!1,this.rzHandles="e,s,se",this.rzAspectRatio=!1,this.rzContainment=null,this.rzGrid=null,this.rzMinWidth=null,this.rzMinHeight=null,this.rzMaxWidth=null,this.rzMaxHeight=null,this.preventDefaultEvent=!0,this.rzStart=new n.EventEmitter,this.rzResizing=new n.EventEmitter,this.rzStop=new n.EventEmitter,this._helperBlock=new r(t.nativeElement,e)}return Object.defineProperty(t.prototype,"ngResizable",{set:function(t){t!==undefined&&null!==t&&""!==t&&(this._resizable=!!t,this.updateResizable())},enumerable:!0,configurable:!0}),t.prototype.ngOnChanges=function(t){t.rzHandles&&!t.rzHandles.isFirstChange()&&this.updateResizable(),t.rzAspectRatio&&!t.rzAspectRatio.isFirstChange()&&this.updateAspectRatio(),t.rzContainment&&!t.rzContainment.isFirstChange()&&this.updateContainment()},t.prototype.ngOnInit=function(){this.updateResizable()},t.prototype.ngOnDestroy=function(){this.removeHandles(),this._containment=null,this._helperBlock.dispose(),this._helperBlock=null},t.prototype.ngAfterViewInit=function(){var t=this.el.nativeElement;this._initSize=a.getCurrent(t),this._initPos=s.getCurrent(t),this._currSize=a.copy(this._initSize),this._currPos=s.copy(this._initPos),this.updateAspectRatio(),this.updateContainment()},t.prototype.resetSize=function(){this._currSize=a.copy(this._initSize),this._currPos=s.copy(this._initPos),this.doResize()},t.prototype.getStatus=function(){return this._currPos&&this._currSize?{size:{width:this._currSize.width,height:this._currSize.height},position:{top:this._currPos.y,left:this._currPos.x}}:null},t.prototype.updateResizable=function(){var t=this.el.nativeElement;this.renderer.removeClass(t,"ng-resizable"),this.removeHandles(),this._resizable&&(this.renderer.addClass(t,"ng-resizable"),this.createHandles())},t.prototype.updateAspectRatio=function(){if("boolean"==typeof this.rzAspectRatio)this.rzAspectRatio&&this._currSize.height?this._aspectRatio=this._currSize.width/this._currSize.height:this._aspectRatio=0;else{var t=Number(this.rzAspectRatio);this._aspectRatio=isNaN(t)?0:t}},t.prototype.updateContainment=function(){this.rzContainment?"string"==typeof this.rzContainment?"parent"===this.rzContainment?this._containment=this.el.nativeElement.parentElement:this._containment=document.querySelector(this.rzContainment):this._containment=this.rzContainment:this._containment=null},t.prototype.createHandles=function(){var t,e,i,n,s;if(this.rzHandles)if("string"==typeof this.rzHandles){s="all"===this.rzHandles?["n","e","s","w","ne","se","nw","sw"]:this.rzHandles.replace(/ /g,"").toLowerCase().split(",");try{for(var r=p(s),o=r.next();!o.done;o=r.next()){var h=o.value;(d=this.createHandleByType(h,"ng-resizable-"+h))&&(this._handleType.push(h),this._handles[h]=d)}}catch(l){t={error:l}}finally{try{o&&!o.done&&(e=r["return"])&&e.call(r)}finally{if(t)throw t.error}}}else{s=Object.keys(this.rzHandles);try{for(var a=p(s),u=a.next();!u.done;u=a.next()){var d;h=u.value;(d=this.createHandleByType(h,this.rzHandles[h]))&&(this._handleType.push(h),this._handles[h]=d)}}catch(c){i={error:c}}finally{try{u&&!u.done&&(n=a["return"])&&n.call(a)}finally{if(i)throw i.error}}}},t.prototype.createHandleByType=function(t,e){var i=this.el.nativeElement;return t.match(/^(se|sw|ne|nw|n|e|s|w)$/)?new h(i,this.renderer,t,e,this.onMouseDown.bind(this)):(console.error("Invalid handle type:",t),null)},t.prototype.removeHandles=function(){var t,e;try{for(var i=p(this._handleType),n=i.next();!n.done;n=i.next()){var s=n.value;this._handles[s].dispose()}}catch(r){t={error:r}}finally{try{n&&!n.done&&(e=i["return"])&&e.call(i)}finally{if(t)throw t.error}}this._handleType=[],this._handles={}},t.prototype.onMouseDown=function(t,e){t instanceof MouseEvent&&2===t.button||(this.preventDefaultEvent&&(t.stopPropagation(),t.preventDefault()),this._handleResizing||(this._origMousePos=s.fromEvent(t),this.startResize(e),this.subscribeEvents()))},t.prototype.subscribeEvents=function(){var e=this;this.draggingSub=i.fromEvent(document,"mousemove",{passive:!1}).subscribe(function(t){return e.onMouseMove(t)}),this.draggingSub.add(i.fromEvent(document,"touchmove",{passive:!1}).subscribe(function(t){return e.onMouseMove(t)})),this.draggingSub.add(i.fromEvent(document,"mouseup",{passive:!1}).subscribe(function(){return e.onMouseLeave()})),/msie\s|trident\//i.test(window.navigator.userAgent)||this.draggingSub.add(i.fromEvent(document,"mouseleave",{passive:!1}).subscribe(function(){return e.onMouseLeave()})),this.draggingSub.add(i.fromEvent(document,"touchend",{passive:!1}).subscribe(function(){return e.onMouseLeave()})),this.draggingSub.add(i.fromEvent(document,"touchcancel",{passive:!1}).subscribe(function(){return e.onMouseLeave()}))},t.prototype.unsubscribeEvents=function(){this.draggingSub.unsubscribe(),this.draggingSub=null},t.prototype.onMouseLeave=function(){this._handleResizing&&(this.stopResize(),this._origMousePos=null,this.unsubscribeEvents())},t.prototype.onMouseMove=function(t){this._handleResizing&&this._resizable&&this._origMousePos&&this._origPos&&this._origSize&&(this.resizeTo(s.fromEvent(t)),this.onResizing())},t.prototype.startResize=function(t){var e=this.el.nativeElement;this._origSize=a.getCurrent(e),this._origPos=s.getCurrent(e),this._currSize=a.copy(this._origSize),this._currPos=s.copy(this._origPos),this._containment&&this.getBounding(),this.getGridSize(),this._helperBlock.add(),this._handleResizing=t,this.updateDirection(),this.rzStart.emit(this.getResizingEvent())},t.prototype.stopResize=function(){this._helperBlock.remove(),this.rzStop.emit(this.getResizingEvent()),this._handleResizing=null,this._direction=null,this._origSize=null,this._origPos=null,this._containment&&this.resetBounding()},t.prototype.onResizing=function(){this.rzResizing.emit(this.getResizingEvent())},t.prototype.getResizingEvent=function(){return{host:this.el.nativeElement,handle:this._handleResizing?this._handleResizing.el:null,size:{width:this._currSize.width,height:this._currSize.height},position:{top:this._currPos.y,left:this._currPos.x},direction:o({},this._directionChanged)}},t.prototype.updateDirection=function(){this._direction={n:!!this._handleResizing.type.match(/n/),s:!!this._handleResizing.type.match(/s/),w:!!this._handleResizing.type.match(/w/),e:!!this._handleResizing.type.match(/e/)},this._directionChanged=o({},this._direction),this.rzAspectRatio&&(this._directionChanged.n&&!this._directionChanged.e&&(this._directionChanged.w=!0),this._directionChanged.s&&!this._directionChanged.w&&(this._directionChanged.e=!0),this._directionChanged.e&&!this._directionChanged.n&&(this._directionChanged.s=!0),this._directionChanged.w&&!this._directionChanged.n&&(this._directionChanged.s=!0))},t.prototype.resizeTo=function(t){t.subtract(this._origMousePos);var e=Math.round(t.x/this._gridSize.x)*this._gridSize.x,i=Math.round(t.y/this._gridSize.y)*this._gridSize.y;this._direction.n?(this._currPos.y=this._origPos.y+i,this._currSize.height=this._origSize.height-i):this._direction.s&&(this._currSize.height=this._origSize.height+i),this._direction.e?this._currSize.width=this._origSize.width+e:this._direction.w&&(this._currSize.width=this._origSize.width-e,this._currPos.x=this._origPos.x+e),this.checkBounds(),this.checkSize(),this.adjustByRatio(),this.doResize()},t.prototype.doResize=function(){var t=this.el.nativeElement;(!this._direction||this._direction.n||this._direction.s||this._aspectRatio)&&this.renderer.setStyle(t,"height",this._currSize.height+"px"),(!this._direction||this._direction.w||this._direction.e||this._aspectRatio)&&this.renderer.setStyle(t,"width",this._currSize.width+"px"),this.renderer.setStyle(t,"left",this._currPos.x+"px"),this.renderer.setStyle(t,"top",this._currPos.y+"px")},t.prototype.adjustByRatio=function(){if(this._aspectRatio&&!this._adjusted)if(this._direction.e||this._direction.w){var t=Math.floor(this._currSize.width/this._aspectRatio);this._direction.n&&(this._currPos.y+=this._currSize.height-t),this._currSize.height=t}else{var e=Math.floor(this._aspectRatio*this._currSize.height);this._direction.n&&(this._currPos.x+=this._currSize.width-e),this._currSize.width=e}},t.prototype.checkBounds=function(){if(this._containment){var t=this._bounding.width-this._bounding.pr-this._bounding.deltaL-this._bounding.translateX-this._currPos.x,e=this._bounding.height-this._bounding.pb-this._bounding.deltaT-this._bounding.translateY-this._currPos.y;if(this._direction.n&&this._currPos.y+this._bounding.translateY<0&&(this._currPos.y=-this._bounding.translateY,this._currSize.height=this._origSize.height+this._origPos.y+this._bounding.translateY),this._direction.w&&this._currPos.x+this._bounding.translateX<0&&(this._currPos.x=-this._bounding.translateX,this._currSize.width=this._origSize.width+this._origPos.x+this._bounding.translateX),this._currSize.width>t&&(this._currSize.width=t),this._currSize.height>e&&(this._currSize.height=e),this._aspectRatio){if(this._adjusted=!1,(this._direction.w||this._direction.e)&&this._currSize.width/this._aspectRatio>=e){var i=Math.floor(e*this._aspectRatio);this._direction.w&&(this._currPos.x+=this._currSize.width-i),this._currSize.width=i,this._currSize.height=e,this._adjusted=!0}if((this._direction.n||this._direction.s)&&this._currSize.height*this._aspectRatio>=t){var n=Math.floor(t/this._aspectRatio);this._direction.n&&(this._currPos.y+=this._currSize.height-n),this._currSize.width=t,this._currSize.height=n,this._adjusted=!0}}}},t.prototype.checkSize=function(){var t=this.rzMinHeight?this.rzMinHeight:1,e=this.rzMinWidth?this.rzMinWidth:1;this._currSize.heightthis.rzMaxHeight&&(this._currSize.height=this.rzMaxHeight,this._direction.n&&(this._currPos.y=this._origPos.y+(this._origSize.height-this.rzMaxHeight))),this.rzMaxWidth&&this._currSize.width>this.rzMaxWidth&&(this._currSize.width=this.rzMaxWidth,this._direction.w&&(this._currPos.x=this._origPos.x+(this._origSize.width-this.rzMaxWidth)))},t.prototype.getBounding=function(){var t=this._containment,e=window.getComputedStyle(t);if(e){var i=e.getPropertyValue("position"),n=window.getComputedStyle(this.el.nativeElement).getPropertyValue("transform").replace(/[^-\d,]/g,"").split(",");this._bounding={},this._bounding.width=t.clientWidth,this._bounding.height=t.clientHeight,this._bounding.pr=parseInt(e.getPropertyValue("padding-right"),10),this._bounding.pb=parseInt(e.getPropertyValue("padding-bottom"),10),this._bounding.deltaL=this.el.nativeElement.offsetLeft-this._currPos.x,this._bounding.deltaT=this.el.nativeElement.offsetTop-this._currPos.y,6<=n.length?(this._bounding.translateX=parseInt(n[4],10),this._bounding.translateY=parseInt(n[5],10)):(this._bounding.translateX=0,this._bounding.translateY=0),this._bounding.position=e.getPropertyValue("position"),"static"===i&&this.renderer.setStyle(t,"position","relative")}},t.prototype.resetBounding=function(){this._bounding&&"static"===this._bounding.position&&this.renderer.setStyle(this._containment,"position","relative"),this._bounding=null},t.prototype.getGridSize=function(){this._gridSize={x:1,y:1},this.rzGrid&&("number"==typeof this.rzGrid?this._gridSize={x:this.rzGrid,y:this.rzGrid}:Array.isArray(this.rzGrid)&&(this._gridSize={x:this.rzGrid[0],y:this.rzGrid[1]}))},t.decorators=[{type:n.Directive,args:[{selector:"[ngResizable]",exportAs:"ngResizable"}]}],t.ctorParameters=function(){return[{type:n.ElementRef},{type:n.Renderer2}]},t.propDecorators={ngResizable:[{type:n.Input}],rzHandles:[{type:n.Input}],rzAspectRatio:[{type:n.Input}],rzContainment:[{type:n.Input}],rzGrid:[{type:n.Input}],rzMinWidth:[{type:n.Input}],rzMinHeight:[{type:n.Input}],rzMaxWidth:[{type:n.Input}],rzMaxHeight:[{type:n.Input}],preventDefaultEvent:[{type:n.Input}],rzStart:[{type:n.Output}],rzResizing:[{type:n.Output}],rzStop:[{type:n.Output}]},t}(),d=function(){function t(){}return t.decorators=[{type:n.NgModule,args:[{imports:[],declarations:[e,u],exports:[e,u]}]}],t}();t.AngularDraggableDirective=e,t.AngularResizableDirective=u,t.AngularDraggableModule=d,t.Position=s,Object.defineProperty(t,"__esModule",{value:!0})}); //# sourceMappingURL=angular2-draggable.umd.min.js.map