text: /*! ngImgCropExtended v0.5.0 License: MIT */!function(){var e=angular.module("ngImgCrop",[]);e.factory("cropAreaCircle",["cropArea",function(e){var t=function(){e.apply(this,arguments),this._boxResizeBaseSize=30,this._boxResizeNormalRatio=.9,this._boxResizeHoverRatio=1.2,this._iconMoveNormalRatio=.9,this._iconMoveHoverRatio=1.2,this._boxResizeNormalSize=this._boxResizeBaseSize*this._boxResizeNormalRatio,this._boxResizeHoverSize=this._boxResizeBaseSize*this._boxResizeHoverRatio,this._posDragStartX=0,this._posDragStartY=0,this._posResizeStartX=0,this._posResizeStartY=0,this._posResizeStartSize=0,this._boxResizeIsHover=!1,this._areaIsHover=!1,this._boxResizeIsDragging=!1,this._areaIsDragging=!1};return t.prototype=new e,t.prototype.getType=function(){return"circle"},t.prototype._calcCirclePerimeterCoords=function(e){var t=this._size.w/2,i=e*(Math.PI/180),r=this.getCenterPoint().x+t*Math.cos(i),n=this.getCenterPoint().y+t*Math.sin(i);return[r,n]},t.prototype._calcResizeIconCenterCoords=function(){return this._calcCirclePerimeterCoords(-45)},t.prototype._isCoordWithinArea=function(e){return Math.sqrt((e[0]-this.getCenterPoint().x)*(e[0]-this.getCenterPoint().x)+(e[1]-this.getCenterPoint().y)*(e[1]-this.getCenterPoint().y))<this._size.w/2},t.prototype._isCoordWithinBoxResize=function(e){var t=this._calcResizeIconCenterCoords(),i=this._boxResizeHoverSize/2;return e[0]>t[0]-i&&e[0]<t[0]+i&&e[1]>t[1]-i&&e[1]<t[1]+i},t.prototype._drawArea=function(e,t,i){e.arc(t.x,t.y,i.w/2,0,2*Math.PI)},t.prototype.draw=function(){e.prototype.draw.apply(this,arguments);var t=this.getCenterPoint();this._cropCanvas.drawIconMove([t.x,t.y],this._areaIsHover?this._iconMoveHoverRatio:this._iconMoveNormalRatio),this._cropCanvas.drawIconResizeBoxNESW(this._calcResizeIconCenterCoords(),this._boxResizeBaseSize,this._boxResizeIsHover?this._boxResizeHoverRatio:this._boxResizeNormalRatio)},t.prototype.processMouseMove=function(e,t){var i="default",r=!1;if(this._boxResizeIsHover=!1,this._areaIsHover=!1,this._areaIsDragging)this.setCenterPoint({x:e-this._posDragStartX,y:t-this._posDragStartY}),this._areaIsHover=!0,i="move",r=!0,this._events.trigger("area-move");else if(this._boxResizeIsDragging){i="nesw-resize";var n,o,a;o=e-this._posResizeStartX,a=this._posResizeStartY-t,n=o>a?this._posResizeStartSize.w+2*a:this._posResizeStartSize.w+2*o;var s=(this.getCenterPoint(),{}),h={};s.x=this.getCenterPoint().x-.5*n,h.x=this.getCenterPoint().x+.5*n,s.y=this.getCenterPoint().y-.5*n,h.y=this.getCenterPoint().y+.5*n,this.setSizeByCorners(s,h),this._boxResizeIsHover=!0,r=!0,this._events.trigger("area-resize")}else this._isCoordWithinBoxResize([e,t])?(i="nesw-resize",this._areaIsHover=!1,this._boxResizeIsHover=!0,r=!0):this._isCoordWithinArea([e,t])&&(i="move",this._areaIsHover=!0,r=!0);return angular.element(this._ctx.canvas).css({cursor:i}),r},t.prototype.processMouseDown=function(e,t){if(this._isCoordWithinBoxResize([e,t]))this._areaIsDragging=!1,this._areaIsHover=!1,this._boxResizeIsDragging=!0,this._boxResizeIsHover=!0,this._posResizeStartX=e,this._posResizeStartY=t,this._posResizeStartSize=this._size,this._events.trigger("area-resize-start");else if(this._isCoordWithinArea([e,t])){this._areaIsDragging=!0,this._areaIsHover=!0,this._boxResizeIsDragging=!1,this._boxResizeIsHover=!1;var i=this.getCenterPoint();this._posDragStartX=e-i.x,this._posDragStartY=t-i.y,this._events.trigger("area-move-start")}},t.prototype.processMouseUp=function(){this._areaIsDragging&&(this._areaIsDragging=!1,this._events.trigger("area-move-end")),this._boxResizeIsDragging&&(this._boxResizeIsDragging=!1,this._events.trigger("area-resize-end")),this._areaIsHover=!1,this._boxResizeIsHover=!1,this._posDragStartX=0,this._posDragStartY=0},t}]),e.factory("cropAreaRectangle",["cropArea",function(e){var t=function(){e.apply(this,arguments),this._resizeCtrlBaseRadius=15,this._resizeCtrlNormalRatio=.75,this._resizeCtrlHoverRatio=1,this._iconMoveNormalRatio=.9,this._iconMoveHoverRatio=1.2,this._resizeCtrlNormalRadius=this._resizeCtrlBaseRadius*this._resizeCtrlNormalRatio,this._resizeCtrlHoverRadius=this._resizeCtrlBaseRadius*this._resizeCtrlHoverRatio,this._posDragStartX=0,this._posDragStartY=0,this._posResizeStartX=0,this._posResizeStartY=0,this._posResizeStartSize={w:0,h:0},this._resizeCtrlIsHover=-1,this._areaIsHover=!1,this._resizeCtrlIsDragging=-1,this._areaIsDragging=!1};return t.prototype=new e,t.prototype.getType=function(){return"rectangle"},t.prototype._calcRectangleCorners=function(){var e=this.getSize(),t=this.getSouthEastBound();return[[e.x,e.y],[t.x,e.y],[e.x,t.y],[t.x,t.y]]},t.prototype._calcRectangleDimensions=function(){var e=this.getSize(),t=this.getSouthEastBound();return{left:e.x,top:e.y,right:t.x,bottom:t.y}},t.prototype._isCoordWithinArea=function(e){var t=this._calcRectangleDimensions();return e[0]>=t.left&&e[0]<=t.right&&e[1]>=t.top&&e[1]<=t.bottom},t.prototype._isCoordWithinResizeCtrl=function(e){for(var t=this._calcRectangleCorners(),i=-1,r=0,n=t.length;n>r;r++){var o=t[r];if(e[0]>o[0]-this._resizeCtrlHoverRadius-15&&e[0]<o[0]+this._resizeCtrlHoverRadius+15&&e[1]>o[1]-this._resizeCtrlHoverRadius-15&&e[1]<o[1]+this._resizeCtrlHoverRadius+15){i=r;break}}return i},t.prototype._drawArea=function(e,t,i){e.rect(i.x,i.y,i.w,i.h)},t.prototype.draw=function(){e.prototype.draw.apply(this,arguments);var t=this.getCenterPoint();this._cropCanvas.drawIconMove([t.x,t.y],this._areaIsHover?this._iconMoveHoverRatio:this._iconMoveNormalRatio);for(var i=this._calcRectangleCorners(),r=0,n=i.length;n>r;r++){var o=i[r];this._cropCanvas.drawIconResizeCircle(o,this._resizeCtrlBaseRadius,this._resizeCtrlIsHover===r?this._resizeCtrlHoverRatio:this._resizeCtrlNormalRatio)}},t.prototype.processMouseMove=function(e,t){var i="default",r=!1;if(this._resizeCtrlIsHover=-1,this._areaIsHover=!1,this._areaIsDragging)this.setCenterPoint({x:e-this._posDragStartX,y:t-this._posDragStartY}),this._areaIsHover=!0,i="move",r=!0,this._events.trigger("area-move");else if(this._resizeCtrlIsDragging>-1){var n=this.getSize(),o=this.getSouthEastBound(),a=e;switch(this._resizeCtrlIsDragging){case 0:this._aspect&&(a=o.x-(o.y-t)*this._aspect),this.setSizeByCorners({x:a,y:t},{x:o.x,y:o.y}),i="nwse-resize";break;case 1:this._aspect&&(a=n.x+(o.y-t)*this._aspect),this.setSizeByCorners({x:n.x,y:t},{x:a,y:o.y}),i="nesw-resize";break;case 2:this._aspect&&(a=o.x-(t-n.y)*this._aspect),this.setSizeByCorners({x:a,y:n.y},{x:o.x,y:t}),i="nesw-resize";break;case 3:this._aspect&&(a=n.x+(t-n.y)*this._aspect),this.setSizeByCorners({x:n.x,y:n.y},{x:a,y:t}),i="nwse-resize"}this._resizeCtrlIsHover=this._resizeCtrlIsDragging,r=!0,this._events.trigger("area-resize")}else{var s=this._isCoordWithinResizeCtrl([e,t]);if(s>-1){switch(s){case 0:i="nwse-resize";break;case 1:i="nesw-resize";break;case 2:i="nesw-resize";break;case 3:i="nwse-resize"}this._areaIsHover=!1,this._resizeCtrlIsHover=s,r=!0}else this._isCoordWithinArea([e,t])&&(i="move",this._areaIsHover=!0,r=!0)}return angular.element(this._ctx.canvas).css({cursor:i}),r},t.prototype.isEdited=function(){return!(this._ctx.canvas.width===this._calcRectangleDimensions().right-this._calcRectangleDimensions().left+30&&this._ctx.canvas.height===this._calcRectangleDimensions().bottom+30-this._calcRectangleDimensions().top)},t.prototype.processMouseDown=function(e,t){var i=this._isCoordWithinResizeCtrl([e,t]);if(i>-1)this._areaIsDragging=!1,this._areaIsHover=!1,this._resizeCtrlIsDragging=i,this._resizeCtrlIsHover=i,this._posResizeStartX=e,this._posResizeStartY=t,this._posResizeStartSize=this._size,this._events.trigger("area-resize-start");else if(this._isCoordWithinArea([e,t])){this._areaIsDragging=!0,this._areaIsHover=!0,this._resizeCtrlIsDragging=-1,this._resizeCtrlIsHover=-1;var r=this.getCenterPoint();this._posDragStartX=e-r.x,this._posDragStartY=t-r.y,this._events.trigger("area-move-start")}},t.prototype.processMouseUp=function(){this._areaIsDragging&&(this._areaIsDragging=!1,this._events.trigger("area-move-end")),this._resizeCtrlIsDragging>-1&&(this._resizeCtrlIsDragging=-1,this._events.trigger("area-resize-end")),this._areaIsHover=!1,this._resizeCtrlIsHover=-1,this._posDragStartX=0,this._posDragStartY=0},t}]),e.factory("cropAreaSquare",["cropArea",function(e){var t=function(){e.apply(this,arguments),this._resizeCtrlBaseRadius=15,this._resizeCtrlNormalRatio=.75,this._resizeCtrlHoverRatio=1,this._iconMoveNormalRatio=.9,this._iconMoveHoverRatio=1.2,this._resizeCtrlNormalRadius=this._resizeCtrlBaseRadius*this._resizeCtrlNormalRatio,this._resizeCtrlHoverRadius=this._resizeCtrlBaseRadius*this._resizeCtrlHoverRatio,this._posDragStartX=0,this._posDragStartY=0,this._posResizeStartX=0,this._posResizeStartY=0,this._posResizeStartSize=0,this._resizeCtrlIsHover=-1,this._areaIsHover=!1,this._resizeCtrlIsDragging=-1,this._areaIsDragging=!1};return t.prototype=new e,t.prototype.getType=function(){return"square"},t.prototype.getInitSize=function(){var e=this._ctx.canvas.width-30;return e>this._ctx.canvas.height-30&&(e=this._ctx.canvas.height-30),this._processSize({w:e,h:e})},t.prototype.isEdited=function(){return!(this._ctx.canvas.width===this._calcRectangleDimensions().right-this._calcRectangleDimensions().left+30&&this._ctx.canvas.height===this._calcRectangleDimensions().bottom+30-this._calcRectangleDimensions().top)},t.prototype._calcSquareCorners=function(){var e=this.getSize(),t=this.getSouthEastBound();return[[e.x,e.y],[t.x,e.y],[e.x,t.y],[t.x,t.y]]},t.prototype._calcSquareDimensions=function(){var e=this.getSize(),t=this.getSouthEastBound();return{left:e.x,top:e.y,right:t.x,bottom:t.y}},t.prototype._isCoordWithinArea=function(e){var t=this._calcSquareDimensions();return e[0]>=t.left&&e[0]<=t.right&&e[1]>=t.top&&e[1]<=t.bottom},t.prototype._isCoordWithinResizeCtrl=function(e){for(var t=this._calcSquareCorners(),i=-1,r=0,n=t.length;n>r;r++){var o=t[r];if(e[0]>o[0]-this._resizeCtrlHoverRadius-15&&e[0]<o[0]+this._resizeCtrlHoverRadius+15&&e[1]>o[1]-this._resizeCtrlHoverRadius-15&&e[1]<o[1]+this._resizeCtrlHoverRadius+15){i=r;break}}return i},t.prototype._drawArea=function(e,t,i){e.rect(i.x,i.y,i.w,i.h)},t.prototype.draw=function(){e.prototype.draw.apply(this,arguments);var t=this.getCenterPoint();this._cropCanvas.drawIconMove([t.x,t.y],this._areaIsHover?this._iconMoveHoverRatio:this._iconMoveNormalRatio);for(var i=this._calcSquareCorners(),r=0,n=i.length;n>r;r++){var o=i[r];this._cropCanvas.drawIconResizeCircle(o,this._resizeCtrlBaseRadius,this._resizeCtrlIsHover===r?this._resizeCtrlHoverRatio:this._resizeCtrlNormalRatio)}},t.prototype.processMouseMove=function(e,t){var i="default",r=!1;if(this._resizeCtrlIsHover=-1,this._areaIsHover=!1,this._areaIsDragging)this.setCenterPoint({x:e-this._posDragStartX,y:t-this._posDragStartY}),this._areaIsHover=!0,i="move",r=!0,this._events.trigger("area-move");else if(this._resizeCtrlIsDragging>-1){var n,o;switch(this._resizeCtrlIsDragging){case 0:n=-1,o=-1,i="nwse-resize";break;case 1:n=1,o=-1,i="nesw-resize";break;case 2:n=-1,o=1,i="nesw-resize";break;case 3:n=1,o=1,i="nwse-resize"}var a,s=(e-this._posResizeStartX)*n,h=(t-this._posResizeStartY)*o;a=s>h?this._posResizeStartSize.w+h:this._posResizeStartSize.w+s;var c=Math.max(this._minSize.w,a),u={},l={},g={},f={},d=this.getSize(),p=this.getSouthEastBound();switch(this._resizeCtrlIsDragging){case 0:u.x=p.x-c,u.y=p.y-c,u.y>0&&this.setSizeByCorners(u,{x:p.x,y:p.y}),i="nwse-resize";break;case 1:s>=0&&h>=0?(f.x=d.x+c,f.y=p.y-c):(0>s||0>h)&&(f.x=d.x+c,f.y=p.y-c),f.y>0&&this.setSizeByCorners({x:d.x,y:f.y},{x:f.x,y:p.y}),i="nesw-resize";break;case 2:s>=0&&h>=0?(g.x=p.x-c,g.y=d.y+c):(0>=s||0>=h)&&(g.x=p.x-c,g.y=d.y+c),g.y<this._ctx.canvas.height&&this.setSizeByCorners({x:g.x,y:d.y},{x:p.x,y:g.y}),i="nesw-resize";break;case 3:l.x=d.x+c,l.y=d.y+c,l.y<this._ctx.canvas.height&&this.setSizeByCorners({x:d.x,y:d.y},l),i="nwse-resize"}this._resizeCtrlIsHover=this._resizeCtrlIsDragging,r=!0,this._events.trigger("area-resize")}else{var v=this._isCoordWithinResizeCtrl([e,t]);if(v>-1){switch(v){case 0:i="nwse-resize";break;case 1:i="nesw-resize";break;case 2:i="nesw-resize";break;case 3:i="nwse-resize"}this._areaIsHover=!1,this._resizeCtrlIsHover=v,r=!0}else this._isCoordWithinArea([e,t])&&(i="move",this._areaIsHover=!0,r=!0)}return angular.element(this._ctx.canvas).css({cursor:i}),r},t.prototype.processMouseDown=function(e,t){var i=this._isCoordWithinResizeCtrl([e,t]);if(i>-1)this._areaIsDragging=!1,this._areaIsHover=!1,this._resizeCtrlIsDragging=i,this._resizeCtrlIsHover=i,this._posResizeStartX=e,this._posResizeStartY=t,this._posResizeStartSize=this._size,this._events.trigger("area-resize-start");else if(this._isCoordWithinArea([e,t])){this._areaIsDragging=!0,this._areaIsHover=!0,this._resizeCtrlIsDragging=-1,this._resizeCtrlIsHover=-1;var r=this.getCenterPoint();this._posDragStartX=e-r.x,this._posDragStartY=t-r.y,this._events.trigger("area-move-start")}},t.prototype.processMouseUp=function(){this._areaIsDragging&&(this._areaIsDragging=!1,this._events.trigger("area-move-end")),this._resizeCtrlIsDragging>-1&&(this._resizeCtrlIsDragging=-1,this._events.trigger("area-resize-end")),this._areaIsHover=!1,this._resizeCtrlIsHover=-1,this._posDragStartX=0,this._posDragStartY=0},t}]),e.factory("cropArea",["cropCanvas",function(e){var t=function(t,i){this._ctx=t,this._events=i,this._minSize={x:0,y:0,w:80,h:80},this._initSize=void 0,this._forceAspectRatio=!1,this._aspect=null,this._cropCanvas=new e(t),this._image=new Image,this._size={x:0,y:0,w:150,h:150},this.zoom=0};return t.prototype.getImage=function(){return this._image},t.prototype.setImage=function(e){this._image=e},t.prototype.setForceAspectRatio=function(e){this._forceAspectRatio=e},t.prototype.setAspect=function(e){this._aspect=e},t.prototype.getCanvasSize=function(){return{w:this._ctx.canvas.width,h:this._ctx.canvas.height}},t.prototype.getZoom=function(){return this.zoom},t.prototype.getSize=function(){return this._size.z=this.zoom,this._size},t.prototype.setSize=function(e){e=this._processSize(e),this._size=this._preventBoundaryCollision(e)},t.prototype.setSizeByCorners=function(e,t){var i={x:e.x,y:e.y,w:t.x-e.x,h:t.y-e.y};this.setSize(i)},t.prototype.getSouthEastBound=function(){return this._southEastBound(this.getSize())},t.prototype.setMinSize=function(e){this._minSize=this._processSize(e),this.setSize(this._minSize)},t.prototype.getMinSize=function(){return this._minSize},t.prototype.getCenterPoint=function(){var e=this.getSize();return{x:e.x+e.w/2,y:e.y+e.h/2}},t.prototype.filterMargin=function(e,t){return e.x-t.w/2<15&&(e.x=t.w/2+15),e.y-t.h/2<15&&(e.y=t.h/2+15),e.x+t.w/2>this._ctx.canvas.width-15&&(e.x=this._ctx.canvas.width-15-t.w/2),e.y+t.h/2>this._ctx.canvas.height-15&&(e.y=this._ctx.canvas.height-15-t.h/2),e},t.prototype.setCenterPoint=function(e){var t=this.getSize();e=this.filterMargin(e,t),this.setSize({x:e.x-t.w/2,y:e.y-t.h/2,w:t.w,h:t.h})},t.prototype.setInitSize=function(e){this._initSize=this._processSize(e),this.setSize(this._initSize)},t.prototype.getInitSize=function(){return this._processSize({w:this._ctx.canvas.width-30,h:this._ctx.canvas.height-30})},t.prototype.getType=function(){return"circle"},t.prototype._preventBoundaryCollision=function(e){var t=this._ctx.canvas.height-15,i=this._ctx.canvas.width-15,r={x:e.x,y:e.y},n=this._southEastBound(e);r.x<15&&(r.x=15),r.y<15&&("square"===this.getType()&&(e.h-=15-r.y),r.y=15),n.x>i&&(n.x=i),n.y>t&&("square"===this.getType()&&(e.h-=n.y-t),n.y=t);var o=this._forceAspectRatio?e.w:n.x-r.x,a=this._forceAspectRatio?e.h:n.y-r.y;this._aspect&&(o=a*this._aspect,r.x+o>i&&(o=i-r.x,a=o/this._aspect,this._minSize.w>o&&(o=this._minSize.w),this._minSize.h>a&&(a=this._minSize.h),r.x=i-o),r.y+a>t&&(r.y=t-a)),this._forceAspectRatio&&(o=a,r.x+o>i&&(o=i-r.x,o<this._minSize.w&&(o=this._minSize.w),a=o));var s={x:r.x,y:r.y,w:o,h:a};return s.w<this._minSize.w&&!this._forceAspectRatio&&(s.w=this._minSize.w,n=this._southEastBound(s),n.x>i&&(n.x=i,r.x=Math.max(n.x-i,n.x-this._minSize.w),s={x:r.x,y:r.y,w:n.x-r.x,h:n.y-r.y})),s.h<this._minSize.h&&!this._forceAspectRatio&&(s.h=this._minSize.h,n=this._southEastBound(s),n.y>t&&(n.y=t,r.y=Math.max(n.y-t,n.y-this._minSize.h),s={x:r.x,y:r.y,w:n.x-r.x,h:n.y-r.y})),this._forceAspectRatio&&(n=this._southEastBound(s),n.y>t&&(s.y=t-s.h),n.x>i&&(s.x=i-s.w)),s},t.prototype._dontDragOutside=function(){var e=this._ctx.canvas.height-15,t=this._ctx.canvas.width-15;this._width>t&&(this._width=t),this._height>e&&(this._height=e),this._x<this._width/2&&(this._x=this._width/2),this._x>t-this._width/2&&(this._x=t-this._width/2),this._y<this._height/2&&(this._y=this._height/2),this._y>e-this._height/2&&(this._y=e-this._height/2)},t.prototype._drawArea=function(){},t.prototype._processSize=function(e){"number"==typeof e&&(e={w:e,h:e});var t=e.w;return this._aspect&&(t=e.h*this._aspect),{x:e.x||this.getSize().x,y:e.y||this.getSize().y,w:t||this._minSize.w,h:e.h||this._minSize.h}},t.prototype._southEastBound=function(e){return{x:e.x+e.w,y:e.y+e.h}},t.prototype.draw=function(){this._cropCanvas.drawCropArea(this._image,this.getCenterPoint(),this._size,this._drawArea,this.zoom)},t.prototype.processMouseMove=function(){},t.prototype.processMouseDown=function(){},t.prototype.processMouseUp=function(){},t}]),e.factory("cropCanvas",[function(){var e=[[-.5,-2],[-3,-4.5],[-.5,-7],[-7,-7],[-7,-.5],[-4.5,-3],[-2,-.5]],t=[[.5,-2],[3,-4.5],[.5,-7],[7,-7],[7,-.5],[4.5,-3],[2,-.5]],i=[[-.5,2],[-3,4.5],[-.5,7],[-7,7],[-7,.5],[-4.5,3],[-2,.5]],r=[[.5,2],[3,4.5],[.5,7],[7,7],[7,.5],[4.5,3],[2,.5]],n=[[-1.5,-2.5],[-1.5,-6],[-5,-6],[0,-11],[5,-6],[1.5,-6],[1.5,-2.5]],o=[[-2.5,-1.5],[-6,-1.5],[-6,-5],[-11,0],[-6,5],[-6,1.5],[-2.5,1.5]],a=[[-1.5,2.5],[-1.5,6],[-5,6],[0,11],[5,6],[1.5,6],[1.5,2.5]],s=[[2.5,-1.5],[6,-1.5],[6,-5],[11,0],[6,5],[6,1.5],[2.5,1.5]],h={areaOutline:"#0072e1",resizeBoxStroke:"#0072e1",resizeBoxFill:"#fff",resizeBoxArrowFill:"#0072e1",resizeCircleStroke:"#0072e1",resizeCircleFill:"#fff",moveIconFill:"#0072e1"};return function(c){var u=function(e,t,i){return[i*e[0]+t[0],i*e[1]+t[1]]},l=function(e,t,i,r){c.save(),c.fillStyle=t,c.beginPath();var n,o=u(e[0],i,r);c.moveTo(o[0],o[1]);for(var a in e)a>0&&(n=u(e[a],i,r),c.lineTo(n[0],n[1]));c.lineTo(o[0],o[1]),c.fill(),c.closePath(),c.restore()};this.drawIconMove=function(e,t){l(n,h.moveIconFill,e,t),l(o,h.moveIconFill,e,t),l(a,h.moveIconFill,e,t),l(s,h.moveIconFill,e,t)},this.drawIconResizeCircle=function(e,t,i){var r=t*i;c.save(),c.strokeStyle=h.resizeCircleStroke,c.lineWidth=2,c.fillStyle=h.resizeCircleFill,c.beginPath(),c.arc(e[0],e[1],r,0,2*Math.PI),c.fill(),c.stroke(),c.closePath(),c.restore()},this.drawIconResizeBoxBase=function(e,t,i){var r=t*i;c.save(),c.strokeStyle=h.resizeBoxStroke,c.lineWidth=2,c.fillStyle=h.resizeBoxFill,c.fillRect(e[0]-r/2,e[1]-r/2,r,r),c.strokeRect(e[0]-r/2,e[1]-r/2,r,r),c.restore()},this.drawIconResizeBoxNESW=function(e,r,n){this.drawIconResizeBoxBase(e,r,n),l(t,h.resizeBoxArrowFill,e,n),l(i,h.resizeBoxArrowFill,e,n)},this.drawIconResizeBoxNWSE=function(t,i,n){this.drawIconResizeBoxBase(t,i,n),l(e,h.resizeBoxArrowFill,t,n),l(r,h.resizeBoxArrowFill,t,n)},this.drawCropArea=function(e,t,i,r){var n=Math.abs(e.width/(c.canvas.width-30)),o=Math.abs(e.height/(c.canvas.height-30)),a=Math.abs(t.x-i.w/2),s=Math.abs(t.y-i.h/2);c.save(),c.strokeStyle=h.areaOutline,c.lineWidth=2,c.beginPath(),r(c,t,i),c.stroke(),c.clip(),i.w>0&&c.drawImage(e,(a-15)*n,(s-15)*o,Math.abs(i.w*n),Math.abs(i.h*o),a,s,i.w,i.h),c.beginPath(),r(c,t,i),c.stroke(),c.clip(),c.restore()}}}]),e.service("cropEXIF",[function(){function e(e){return!!e.exifdata}function t(e,t){t=t||e.match(/^data\:([^\;]+)\;base64,/im)[1]||"",e=e.replace(/^data\:([^\;]+)\;base64,/gim,"");for(var i=atob(e),r=i.length,n=new ArrayBuffer(r),o=new Uint8Array(n),a=0;r>a;a++)o[a]=i.charCodeAt(a);return n}function i(e,t){var i=new XMLHttpRequest;i.open("GET",e,!0),i.responseType="blob",i.onload=function(){(200==this.status||0===this.status)&&t(this.response)},i.send()}function r(e,r){function a(t){var i=n(t),a=o(t);e.exifdata=i||{},e.iptcdata=a||{},r&&r.call(e)}if(e.src)if(/^data\:/i.test(e.src)){var s=t(e.src);a(s)}else if(/^blob\:/i.test(e.src)){var h=new FileReader;h.onload=function(e){a(e.target.result)},i(e.src,function(e){h.readAsArrayBuffer(e)})}else{var c=new XMLHttpRequest;c.onload=function(){if(200!=this.status&&0!==this.status)throw"Could not load image";a(c.response),c=null},c.open("GET",e.src,!0),c.responseType="arraybuffer",c.send(null)}else if(window.FileReader&&(e instanceof window.Blob||e instanceof window.File)){var h=new FileReader;h.onload=function(e){l&&console.log("Got file of length "+e.target.result.byteLength),a(e.target.result)},h.readAsArrayBuffer(e)}}function n(e){var t=new DataView(e);if(l&&console.log("Got file of length "+e.byteLength),255!=t.getUint8(0)||216!=t.getUint8(1))return l&&console.log("Not a valid JPEG"),!1;for(var i,r=2,n=e.byteLength;n>r;){if(255!=t.getUint8(r))return l&&console.log("Not a valid marker at offset "+r+", found: "+t.getUint8(r)),!1;if(i=t.getUint8(r+1),l&&console.log(i),225==i)return l&&console.log("Found 0xFFE1 marker"),u(t,r+4,t.getUint16(r+2)-2);r+=2+t.getUint16(r+2)}}function o(e){var t=new DataView(e);if(l&&console.log("Got file of length "+e.byteLength),255!=t.getUint8(0)||216!=t.getUint8(1))return l&&console.log("Not a valid JPEG"),!1;for(var i=2,r=e.byteLength,n=function(e,t){return 56===e.getUint8(t)&&66===e.getUint8(t+1)&&73===e.getUint8(t+2)&&77===e.getUint8(t+3)&&4===e.getUint8(t+4)&&4===e.getUint8(t+5)};r>i;){if(n(t,i)){var o=t.getUint8(i+7);o%2!==0&&(o+=1),0===o&&(o=4);var s=i+8+o,h=t.getUint16(i+6+o);return a(e,s,h)}i++}}function a(e,t,i){for(var r,n,o,a,s,h=new DataView(e),u={},l=t;t+i>l;)28===h.getUint8(l)&&2===h.getUint8(l+1)&&(a=h.getUint8(l+2),a in v&&(o=h.getInt16(l+3),s=o+5,n=v[a],r=c(h,l+5,o),u.hasOwnProperty(n)?u[n]instanceof Array?u[n].push(r):u[n]=[u[n],r]:u[n]=r)),l++;return u}function s(e,t,i,r,n){var o,a,s,c=e.getUint16(i,!n),u={};for(s=0;c>s;s++)o=i+12*s+2,a=r[e.getUint16(o,!n)],!a&&l&&console.log("Unknown tag: "+e.getUint16(o,!n)),u[a]=h(e,o,t,i,n);return u}function h(e,t,i,r,n){var o,a,s,h,u,l,g=e.getUint16(t+2,!n),f=e.getUint32(t+4,!n),d=e.getUint32(t+8,!n)+i;switch(g){case 1:case 7:if(1==f)return e.getUint8(t+8,!n);for(o=f>4?d:t+8,a=[],h=0;f>h;h++)a[h]=e.getUint8(o+h);return a;case 2:return o=f>4?d:t+8,c(e,o,f-1);case 3:if(1==f)return e.getUint16(t+8,!n);for(o=f>2?d:t+8,a=[],h=0;f>h;h++)a[h]=e.getUint16(o+2*h,!n);return a;case 4:if(1==f)return e.getUint32(t+8,!n);for(a=[],h=0;f>h;h++)a[h]=e.getUint32(d+4*h,!n);return a;case 5:if(1==f)return u=e.getUint32(d,!n),l=e.getUint32(d+4,!n),s=new Number(u/l),s.numerator=u,s.denominator=l,s;for(a=[],h=0;f>h;h++)u=e.getUint32(d+8*h,!n),l=e.getUint32(d+4+8*h,!n),a[h]=new Number(u/l),a[h].numerator=u,a[h].denominator=l;return a;case 9:if(1==f)return e.getInt32(t+8,!n);for(a=[],h=0;f>h;h++)a[h]=e.getInt32(d+4*h,!n);return a;case 10:if(1==f)return e.getInt32(d,!n)/e.getInt32(d+4,!n);for(a=[],h=0;f>h;h++)a[h]=e.getInt32(d+8*h,!n)/e.getInt32(d+4+8*h,!n);return a}}function c(e,t,i){for(var r="",n=t;t+i>n;n++)r+=String.fromCharCode(e.getUint8(n));return r}function u(e,t){if("Exif"!=c(e,t,4))return l&&console.log("Not valid EXIF data! "+c(e,t,4)),!1;var i,r,n,o,a,h=t+6;if(18761==e.getUint16(h))i=!1;else{if(19789!=e.getUint16(h))return l&&console.log("Not valid TIFF data! (no 0x4949 or 0x4D4D)"),!1;i=!0}if(42!=e.getUint16(h+2,!i))return l&&console.log("Not valid TIFF data! (no 0x002A)"),!1;var u=e.getUint32(h+4,!i);if(8>u)return l&&console.log("Not valid TIFF data! (First offset less than 8)",e.getUint32(h+4,!i)),!1;if(r=s(e,h,h+u,f,i),r.ExifIFDPointer){o=s(e,h,h+r.ExifIFDPointer,g,i);for(n in o){switch(n){case"LightSource":case"Flash":case"MeteringMode":case"ExposureProgram":case"SensingMethod":case"SceneCaptureType":case"SceneType":case"CustomRendered":case"WhiteBalance":case"GainControl":case"Contrast":case"Saturation":case"Sharpness":case"SubjectDistanceRange":case"FileSource":o[n]=p[n][o[n]];break;case"ExifVersion":case"FlashpixVersion":o[n]=String.fromCharCode(o[n][0],o[n][1],o[n][2],o[n][3]);break;case"ComponentsConfiguration":o[n]=p.Components[o[n][0]]+p.Components[o[n][1]]+p.Components[o[n][2]]+p.Components[o[n][3]]}r[n]=o[n]}}if(r.GPSInfoIFDPointer){a=s(e,h,h+r.GPSInfoIFDPointer,d,i);for(n in a){switch(n){case"GPSVersionID":a[n]=a[n][0]+"."+a[n][1]+"."+a[n][2]+"."+a[n][3]}r[n]=a[n]}}return r}var l=!1,g=this.Tags={36864:"ExifVersion",40960:"FlashpixVersion",40961:"ColorSpace",40962:"PixelXDimension",40963:"PixelYDimension",37121:"ComponentsConfiguration",37122:"CompressedBitsPerPixel",37500:"MakerNote",37510:"UserComment",40964:"RelatedSoundFile",36867:"DateTimeOriginal",36868:"DateTimeDigitized",37520:"SubsecTime",37521:"SubsecTimeOriginal",37522:"SubsecTimeDigitized",33434:"ExposureTime",33437:"FNumber",34850:"ExposureProgram",34852:"SpectralSensitivity",34855:"ISOSpeedRatings",34856:"OECF",37377:"ShutterSpeedValue",37378:"ApertureValue",37379:"BrightnessValue",37380:"ExposureBias",37381:"MaxApertureValue",37382:"SubjectDistance",37383:"MeteringMode",37384:"LightSource",37385:"Flash",37396:"SubjectArea",37386:"FocalLength",41483:"FlashEnergy",41484:"SpatialFrequencyResponse",41486:"FocalPlaneXResolution",41487:"FocalPlaneYResolution",41488:"FocalPlaneResolutionUnit",41492:"SubjectLocation",41493:"ExposureIndex",41495:"SensingMethod",41728:"FileSource",41729:"SceneType",41730:"CFAPattern",41985:"CustomRendered",41986:"ExposureMode",41987:"WhiteBalance",41988:"DigitalZoomRation",41989:"FocalLengthIn35mmFilm",41990:"SceneCaptureType",41991:"GainControl",41992:"Contrast",41993:"Saturation",41994:"Sharpness",41995:"DeviceSettingDescription",41996:"SubjectDistanceRange",40965:"InteroperabilityIFDPointer",42016:"ImageUniqueID"},f=this.TiffTags={256:"ImageWidth",257:"ImageHeight",34665:"ExifIFDPointer",34853:"GPSInfoIFDPointer",40965:"InteroperabilityIFDPointer",258:"BitsPerSample",259:"Compression",262:"PhotometricInterpretation",274:"Orientation",277:"SamplesPerPixel",284:"PlanarConfiguration",530:"YCbCrSubSampling",531:"YCbCrPositioning",282:"XResolution",283:"YResolution",296:"ResolutionUnit",273:"StripOffsets",278:"RowsPerStrip",279:"StripByteCounts",513:"JPEGInterchangeFormat",514:"JPEGInterchangeFormatLength",301:"TransferFunction",318:"WhitePoint",319:"PrimaryChromaticities",529:"YCbCrCoefficients",532:"ReferenceBlackWhite",306:"DateTime",270:"ImageDescription",271:"Make",272:"Model",305:"Software",315:"Artist",33432:"Copyright"},d=this.GPSTags={0:"GPSVersionID",1:"GPSLatitudeRef",2:"GPSLatitude",3:"GPSLongitudeRef",4:"GPSLongitude",5:"GPSAltitudeRef",6:"GPSAltitude",7:"GPSTimeStamp",8:"GPSSatellites",9:"GPSStatus",10:"GPSMeasureMode",11:"GPSDOP",12:"GPSSpeedRef",13:"GPSSpeed",14:"GPSTrackRef",15:"GPSTrack",16:"GPSImgDirectionRef",17:"GPSImgDirection",18:"GPSMapDatum",19:"GPSDestLatitudeRef",20:"GPSDestLatitude",21:"GPSDestLongitudeRef",22:"GPSDestLongitude",23:"GPSDestBearingRef",24:"GPSDestBearing",25:"GPSDestDistanceRef",26:"GPSDestDistance",27:"GPSProcessingMethod",28:"GPSAreaInformation",29:"GPSDateStamp",30:"GPSDifferential"},p=this.StringValues={ExposureProgram:{0:"Not defined",1:"Manual",2:"Normal program",3:"Aperture priority",4:"Shutter priority",5:"Creative program",6:"Action program",7:"Portrait mode",8:"Landscape mode"},MeteringMode:{0:"Unknown",1:"Average",2:"CenterWeightedAverage",3:"Spot",4:"MultiSpot",5:"Pattern",6:"Partial",255:"Other"},LightSource:{0:"Unknown",1:"Daylight",2:"Fluorescent",3:"Tungsten (incandescent light)",4:"Flash",9:"Fine weather",10:"Cloudy weather",11:"Shade",12:"Daylight fluorescent (D 5700 - 7100K)",13:"Day white fluorescent (N 4600 - 5400K)",14:"Cool white fluorescent (W 3900 - 4500K)",15:"White fluorescent (WW 3200 - 3700K)",17:"Standard light A",18:"Standard light B",19:"Standard light C",20:"D55",21:"D65",22:"D75",23:"D50",24:"ISO studio tungsten",255:"Other"},Flash:{0:"Flash did not fire",1:"Flash fired",5:"Strobe return light not detected",7:"Strobe return light detected",9:"Flash fired, compulsory flash mode",13:"Flash fired, compulsory flash mode, return light not detected",15:"Flash fired, compulsory flash mode, return light detected",16:"Flash did not fire, compulsory flash mode",24:"Flash did not fire, auto mode",25:"Flash fired, auto mode",29:"Flash fired, auto mode, return light not detected",31:"Flash fired, auto mode, return light detected",32:"No flash function",65:"Flash fired, red-eye reduction mode",69:"Flash fired, red-eye reduction mode, return light not detected",71:"Flash fired, red-eye reduction mode, return light detected",73:"Flash fired, compulsory flash mode, red-eye reduction mode",77:"Flash fired, compulsory flash mode, red-eye reduction mode, return light not detected",79:"Flash fired, compulsory flash mode, red-eye reduction mode, return light detected",89:"Flash fired, auto mode, red-eye reduction mode",93:"Flash fired, auto mode, return light not detected, red-eye reduction mode",95:"Flash fired, auto mode, return light detected, red-eye reduction mode"},SensingMethod:{1:"Not defined",2:"One-chip color area sensor",3:"Two-chip color area sensor",4:"Three-chip color area sensor",5:"Color sequential area sensor",7:"Trilinear sensor",8:"Color sequential linear sensor"},SceneCaptureType:{0:"Standard",1:"Landscape",2:"Portrait",3:"Night scene"},SceneType:{1:"Directly photographed"},CustomRendered:{0:"Normal process",1:"Custom process"},WhiteBalance:{0:"Auto white balance",1:"Manual white balance"},GainControl:{0:"None",1:"Low gain up",2:"High gain up",3:"Low gain down",4:"High gain down"},Contrast:{0:"Normal",1:"Soft",2:"Hard"},Saturation:{0:"Normal",1:"Low saturation",2:"High saturation"},Sharpness:{0:"Normal",1:"Soft",2:"Hard"},SubjectDistanceRange:{0:"Unknown",1:"Macro",2:"Close view",3:"Distant view"},FileSource:{3:"DSC"},Components:{0:"",1:"Y",2:"Cb",3:"Cr",4:"R",5:"G",6:"B"}},v={120:"caption",110:"credit",25:"keywords",55:"dateCreated",80:"byline",85:"bylineTitle",122:"captionWriter",105:"headline",116:"copyright",15:"category"};this.getData=function(t,i){return(t instanceof Image||t instanceof HTMLImageElement)&&!t.complete?!1:(e(t)?i&&i.call(t):r(t,i),!0)},this.getTag=function(t,i){return e(t)?t.exifdata[i]:void 0},this.getAllTags=function(t){if(!e(t))return{};var i,r=t.exifdata,n={};for(i in r)r.hasOwnProperty(i)&&(n[i]=r[i]);return n},this.pretty=function(t){if(!e(t))return"";var i,r=t.exifdata,n="";for(i in r)r.hasOwnProperty(i)&&(n+="object"==typeof r[i]?r[i]instanceof Number?i+" : "+r[i]+" ["+r[i].numerator+"/"+r[i].denominator+"]\r\n":i+" : ["+r[i].length+" values]\r\n":i+" : "+r[i]+"\r\n");return n},this.readFromBinaryFile=function(e){return n(e)}}]),e.factory("cropHost",["$document","$q","cropAreaCircle","cropAreaSquare","cropAreaRectangle","cropEXIF",function(e,t,i,r,n,o){var a=function(e){var t=e.getBoundingClientRect(),i=document.body,r=document.documentElement,n=window.pageYOffset||r.scrollTop||i.scrollTop,o=window.pageXOffset||r.scrollLeft||i.scrollLeft,a=r.clientTop||i.clientTop||0,s=r.clientLeft||i.clientLeft||0,h=t.top+n-a,c=t.left+o-s;return{top:Math.round(h),left:Math.round(c)}};return function(s,h,c){function u(){l.clearRect(0,0,l.canvas.width,l.canvas.height);var e=l.canvas.width,t=l.canvas.height;null!==g&&(l.drawImage(g,15,15,e-30,t-30),l.save(),l.fillStyle="rgba(0, 0, 0, 0.65)",l.fillRect(15,15,l.canvas.width-30,l.canvas.height-30),l.restore(),f.draw())}var l=null,g=null,f=null,d=this,p=[100,100],v=[300,300],m=[],y={w:200,h:200},w=null,S="image/png",_=null,z=!1,x=function(){if(null!==g){f.setImage(g);var e=[g.width,g.height],t=g.width/g.height,i=e;i[0]>v[0]?(i[0]=v[0],i[1]=i[0]/t):i[0]<p[0]&&(i[0]=p[0],i[1]=i[0]/t),i[1]>v[1]?(i[1]=v[1],i[0]=i[1]*t):i[1]<p[1]&&(i[1]=p[1],i[0]=i[1]*t),s.prop("width",i[0]).prop("height",i[1]).css({"margin-left":-i[0]/2+"px","margin-top":-i[1]/2+"px"});var r=l.canvas.width,n=l.canvas.height,o=d.getAreaType();("circle"===o||"square"===o)&&(n=r),void 0!==f.getInitSize()?f.setSize({w:f.getInitSize().w,h:f.getInitSize().h}):f.setSize({w:Math.min(200,r/2),h:Math.min(200,n/2)}),f.setCenterPoint({x:l.canvas.width/2,y:l.canvas.height/2})
  }else s.prop("width",0).prop("height",0).css({"margin-top":0});u()},C=function(e){return angular.isDefined(e.changedTouches)?e.changedTouches:e.originalEvent.changedTouches},I=function(e){return angular.isDefined(e.changedTouches)?e.changedTouches.length>=2:!1},b=function(e){if(null!==g){var t,i,r=a(l.canvas);I(event)||("touchmove"===e.type?(t=C(e)[0].pageX,i=C(e)[0].pageY):(t=e.pageX,i=e.pageY),f.processMouseMove(t-r.left,i-r.top)),u()}},R=function(e){if(e.preventDefault(),e.stopPropagation(),null!==g){var t,i,r=a(l.canvas);"touchstart"===e.type?(t=C(e)[0].pageX,i=C(e)[0].pageY):(t=e.pageX,i=e.pageY),f.processMouseDown(t-r.left,i-r.top),u()}},D=function(e){if(null!==g){var t,i,r=a(l.canvas);"touchend"===e.type?(t=C(e)[0].pageX,i=C(e)[0].pageY):(t=e.pageX,i=e.pageY),f.processMouseUp(t-r.left,i-r.top),u()}},P=function(e){var t,i,r=e,n=f.getCenterPoint(),o={dataURI:null,imageData:null};if(i=angular.element("<canvas></canvas>")[0],t=i.getContext("2d"),i.width=r.w,i.height=r.h,null!==g){var a=(n.x-f.getSize().w/2)*(g.width/l.canvas.width),s=(n.y-f.getSize().h/2)*(g.height/l.canvas.height),h=f.getSize().w*(g.width/l.canvas.width),c=f.getSize().h*(g.height/l.canvas.height);if(z)t.drawImage(g,a,s,h,c,0,0,r.w,r.h);else{var u,d,p=h/c;p>1?(d=r.w,u=d/p):(u=r.h,d=u*p),t.drawImage(g,a,s,h,c,0,0,Math.round(d),Math.round(u))}o.dataURI=null!==_?i.toDataURL(S,_):i.toDataURL(S)}return o};this.getResultImage=function(){if(0==m.length)return P(this.getResultImageSize());for(var e=[],t=0;t<m.length;t++)e.push({dataURI:P(m[t]).dataURI,w:m[t].w,h:m[t].h});return e},this.getResultImageDataBlob=function(){var e,i,r=f.getCenterPoint(),n=this.getResultImageSize(),o=t.defer();if(i=angular.element("<canvas></canvas>")[0],e=i.getContext("2d"),i.width=n.w,i.height=n.h,null!==g){var a=(r.x-f.getSize().w/2)*(g.width/l.canvas.width),s=(r.y-f.getSize().h/2)*(g.height/l.canvas.height),h=f.getSize().w*(g.width/l.canvas.width),c=f.getSize().h*(g.height/l.canvas.height);if(z)e.drawImage(g,a,s,h,c,0,0,n.w,n.h);else{var u,d,p=h/c;p>1?(d=n.w,u=d/p):(u=n.h,d=u*p),e.drawImage(g,a,s,h,c,0,0,Math.round(d),Math.round(u))}}return i.toBlob(function(e){o.resolve(e)},S),o.promise},this.getAreaCoords=function(){return f.getSize()},this.isEdited=function(){return f.isEdited()},this.setNewImageSource=function(e){if(g=null,x(),c.trigger("image-updated"),e){var t=new Image;"http"===e.substring(0,4).toLowerCase()&&(t.crossOrigin="anonymous"),t.onload=function(){c.trigger("load-done"),o.getData(t,function(){var e=o.getTag(t,"Orientation");if([3,6,8].indexOf(e)>-1){var i=document.createElement("canvas"),r=i.getContext("2d"),n=t.width,a=t.height,s=0,h=0,u=0,l=0,f=0;switch(l=n,f=a,e){case 3:s=-t.width,h=-t.height,u=180;break;case 6:n=t.height,a=t.width,h=-t.height,u=90;break;case 8:n=t.height,a=t.width,s=-t.width,u=270}var d=1e3;if(n>d||a>d){var p=0;n>d?(p=d/n,n=d,a=p*a):a>d&&(p=d/a,a=d,n=p*n),h=p*h,s=p*s,l=p*l,f=p*f}i.width=n,i.height=a,r.rotate(u*Math.PI/180),r.drawImage(t,s,h,l,f),g=new Image,g.src=i.toDataURL(S)}else g=t;x(),c.trigger("image-updated")})},t.onerror=function(){c.trigger("load-error")},c.trigger("load-start"),t.src=e instanceof window.Blob?URL.createObjectURL(e):e}},this.setMaxDimensions=function(e,t){if(v=[e,t],null!==g){var i=l.canvas.width,r=l.canvas.height,n=[g.width,g.height],o=g.width/g.height,a=n;a[0]>v[0]?(a[0]=v[0],a[1]=a[0]/o):a[0]<p[0]&&(a[0]=p[0],a[1]=a[0]/o),a[1]>v[1]?(a[1]=v[1],a[0]=a[1]*o):a[1]<p[1]&&(a[1]=p[1],a[0]=a[1]*o),s.prop("width",a[0]).prop("height",a[1]).css({"margin-left":-a[0]/2+"px","margin-top":-a[1]/2+"px"});var h=l.canvas.width/i,c=l.canvas.height/r,d=Math.min(h,c);f.setSize({w:f.getSize().w*d,h:f.getSize().h*d});var m=f.getCenterPoint();f.setCenterPoint({x:m.x*h,y:m.y*c})}else s.prop("width",0).prop("height",0).css({"margin-top":0});u()},this.setAreaMinSize=function(e){angular.isUndefined(e)||(e="number"==typeof e||"string"==typeof e?{w:parseInt(parseInt(e),10),h:parseInt(parseInt(e),10)}:{w:parseInt(e.w,10),h:parseInt(e.h,10)},isNaN(e.w)||isNaN(e.h)||(f.setMinSize(e),u()))},this.setAreaMinRelativeSize=function(e){if(null!==g){var t=f.getCanvasSize();if(angular.isUndefined(e))return;"number"==typeof e||"string"==typeof e?(w={w:e,h:e},e={w:t.w/(g.width/parseInt(parseInt(e),10)),h:t.h/(g.height/parseInt(parseInt(e),10))}):(w=e,e={w:t.w/(g.width/parseInt(parseInt(e.w),10)),h:t.h/(g.height/parseInt(parseInt(e.h),10))}),isNaN(e.w)||isNaN(e.h)||(f.setMinSize(e),u())}},this.setAreaInitSize=function(e){angular.isUndefined(e)||(e="number"==typeof e||"string"==typeof e?{w:parseInt(parseInt(e),10),h:parseInt(parseInt(e),10)}:{w:parseInt(e.w,10),h:parseInt(e.h,10)},isNaN(e.w)||isNaN(e.h)||(f.setInitSize(e),u()))},this.getResultImageSize=function(){if("selection"==y)return f.getSize();if("max"==y){var e=1;g&&l&&l.canvas&&(e=g.width/l.canvas.width);var t={w:e*f.getSize().w,h:e*f.getSize().h};return w&&(t.w<w.w&&(t.w=w.w),t.h<w.h&&(t.h=w.h)),t}return y},this.setResultImageSize=function(e){if(angular.isArray(e))return m=e.slice(),e={w:parseInt(e[0].w,10),h:parseInt(e[0].h,10)},void 0;if(!angular.isUndefined(e)){if(angular.isString(e))return y=e,void 0;angular.isNumber(e)&&(e=parseInt(e,10),e={w:e,h:e}),e={w:parseInt(e.w,10),h:parseInt(e.h,10)},isNaN(e.w)||isNaN(e.h)||(y=e,u())}},this.setResultImageFormat=function(e){S=e},this.setResultImageQuality=function(e){e=parseFloat(e),!isNaN(e)&&e>=0&&1>=e&&(_=e)},this.getAreaType=function(){return f.getType()},this.setAreaType=function(e){var t=f.getCenterPoint(),o=f.getSize(),a=f.getMinSize(),s=t.x,h=t.y,d=i;"square"===e?d=r:"rectangle"===e&&(d=n),f=new d(l,c),f.setMinSize(a),f.setSize(o),"square"===e||"circle"===e?(z=!0,f.setForceAspectRatio(!0)):(z=!1,f.setForceAspectRatio(!1)),f.setCenterPoint({x:s,y:h}),null!==g&&f.setImage(g),u()},this.getDominantColor=function(e){var i=new Image,r=new ColorThief,n=null,o=t.defer();return i.src=e,i.onload=function(){n=r.getColor(i),o.resolve(n)},o.promise},this.getPalette=function(e){var i=new Image,r=new ColorThief,n=null,o=t.defer();return i.src=e,i.onload=function(){n=r.getPalette(i,colorPaletteLength),o.resolve(n)},o.promise},this.setPaletteColorLength=function(e){colorPaletteLength=e},this.setAspect=function(e){f.setAspect(e);var t=f.getMinSize();t.w=t.h*e,f.setMinSize(t);var i=f.getSize();i.w=i.h*e,f.setSize(i)},l=s[0].getContext("2d"),f=new i(l,c),e.on("mousemove",b),s.on("mousedown",R),e.on("mouseup",D),e.on("touchmove",b),s.on("touchstart",R),e.on("touchend",D),this.destroy=function(){e.off("mousemove",b),s.off("mousedown",R),e.off("mouseup",D),e.off("touchmove",b),s.off("touchstart",R),e.off("touchend",D),s.remove()}}}]),e.factory("cropPubSub",[function(){return function(){var e={};this.on=function(t,i){return t.split(" ").forEach(function(t){e[t]||(e[t]=[]),e[t].push(i)}),this},this.trigger=function(t,i){return angular.forEach(e[t],function(e){e.call(null,i)}),this}}}]),e.directive("imgCrop",["$timeout","cropHost","cropPubSub",function(e,t,i){return{restrict:"E",scope:{image:"=",resultImage:"=",resultArrayImage:"=?",resultBlob:"=?",urlBlob:"=?",chargement:"=?",cropject:"=?",edited:"=?",changeOnFly:"=?",liveView:"=?",areaCoords:"=?",areaType:"@",areaMinSize:"=?",areaInitSize:"=?",areaMinRelativeSize:"=?",resultImageSize:"=?",resultImageFormat:"=?",resultImageQuality:"=?",aspectRatio:"=?",dominantColor:"=?",paletteColor:"=?",paletteColorLength:"=?",onChange:"&",onLoadBegin:"&",onLoadDone:"&",onLoadError:"&"},template:"<canvas></canvas>",controller:["$scope",function(e){e.events=new i}],link:function(i,r){i.liveView&&"boolean"==typeof i.liveView.block?i.liveView.render=function(e){a(i,!0,e)}:i.liveView={block:!1};var n=i.events,o=new t(r.find("canvas"),{},n),a=function(e){""!==e.image&&(s(e),h(e))},s=function(e){var t=o.getAreaCoords();e.areaCoords=t},h=function(e){var t=o.getAreaCoords();e.cropject={cropWidth:t.w,cropHeight:t.h,cropTop:t.y,cropLeft:t.x}},c=function(t){return function(){e(function(){i.$apply(function(e){t(e)})})}};null==i.chargement&&(i.chargement="Chargement");var u=function(){r.append('<div class="loading"><span>'+i.chargement+"...</span></div>")};n.on("load-start",c(function(e){e.onLoadBegin({})})).on("load-done",c(function(e){angular.element(r.children()[r.children().length-1]).remove(),o.setAreaMinRelativeSize(e.areaMinRelativeSize),e.onLoadDone({})})).on("load-error",c(function(e){e.onLoadError({})})).on("area-move area-resize",c(function(e){e.edited=o.isEdited(),e.changeOnFly&&a(e)})).on("area-move-end area-resize-end image-updated",c(function(e){a(e)})),i.$watch("image",function(t){t&&u(),e(function(){o.setNewImageSource(i.image)},100)}),i.$watch("areaType",function(){o.setAreaType(i.areaType),a(i)}),i.$watch("areaMinSize",function(){o.setAreaMinSize(i.areaMinSize),a(i)}),i.$watch("areaMinRelativeSize",function(){""!==i.image&&(o.setAreaMinRelativeSize(i.areaMinRelativeSize),a(i))}),i.$watch("areaInitSize",function(){o.setAreaInitSize(i.areaInitSize),a(i)}),i.$watch("resultImageFormat",function(){o.setResultImageFormat(i.resultImageFormat),a(i)}),i.$watch("resultImageQuality",function(){o.setResultImageQuality(i.resultImageQuality),a(i)}),i.$watch("resultImageSize",function(){o.setResultImageSize(i.resultImageSize),a(i)}),i.$watch("paletteColorLength",function(){o.setPaletteColorLength(i.paletteColorLength)}),i.$watch("aspectRatio",function(){"string"==typeof i.aspectRatio&&""!=i.aspectRatio&&(i.aspectRatio=parseInt(i.aspectRatio)),i.aspectRatio&&o.setAspect(i.aspectRatio)}),i.$watch(function(){return[r[0].clientWidth,r[0].clientHeight]},function(e){o.setMaxDimensions(e[0],e[1]),a(i)},!0),i.$on("$destroy",function(){o.destroy()})}}}]),function(e){"use strict";var t,i=e.Uint8Array,r=e.HTMLCanvasElement,n=r&&r.prototype,o=/\s*;\s*base64\s*(?:;|$)/i,a="toDataURL",s=function(e){for(var r,n,o,a=e.length,s=new i(a/4*3|0),h=0,c=0,u=[0,0],l=0,g=0;a--;)n=e.charCodeAt(h++),r=t[n-43],255!==r&&r!==o&&(u[1]=u[0],u[0]=n,g=g<<6|r,l++,4===l&&(s[c++]=g>>>16,61!==u[1]&&(s[c++]=g>>>8),61!==u[0]&&(s[c++]=g),l=0));return s};i&&(t=new i([62,-1,-1,-1,63,52,53,54,55,56,57,58,59,60,61,-1,-1,-1,0,-1,-1,-1,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,-1,-1,-1,-1,-1,-1,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51])),r&&!n.toBlob&&(n.toBlob=function(e,t){if(t||(t="image/png"),this.mozGetAsFile)return e(this.mozGetAsFile("canvas",t)),void 0;if(this.msToBlob&&/^\s*image\/png\s*(?:$|;)/i.test(t))return e(this.msToBlob()),void 0;var r,n=Array.prototype.slice.call(arguments,1),h=this[a].apply(this,n),c=h.indexOf(","),u=h.substring(c+1),l=o.test(h.substring(0,c));Blob.fake?(r=new Blob,r.encoding=l?"base64":"URI",r.data=u,r.size=u.length):i&&(r=l?new Blob([s(u)],{type:t}):new Blob([decodeURIComponent(u)],{type:t})),"undefined"!=typeof e&&e(r)},n.toBlobHD=n.toDataURLHD?function(){a="toDataURLHD";var e=this.toBlob();return a="toDataURL",e}:n.toBlob)}("undefined"!=typeof self&&self||"undefined"!=typeof window&&window||this.content||this),function(){var e=function(e){this.canvas=document.createElement("canvas"),this.context=this.canvas.getContext("2d"),document.body.appendChild(this.canvas),this.width=this.canvas.width=e.width,this.height=this.canvas.height=e.height,this.context.drawImage(e,0,0,this.width,this.height)};e.prototype.clear=function(){this.context.clearRect(0,0,this.width,this.height)},e.prototype.update=function(e){this.context.putImageData(e,0,0)},e.prototype.getPixelCount=function(){return this.width*this.height},e.prototype.getImageData=function(){return this.context.getImageData(0,0,this.width,this.height)},e.prototype.removeCanvas=function(){this.canvas.parentNode.removeChild(this.canvas)};var t=function(){};if(t.prototype.getColor=function(e,t){var i=this.getPalette(e,5,t),r=i[0];return r},t.prototype.getPalette=function(t,i,n){"undefined"==typeof i&&(i=10),("undefined"==typeof n||1>n)&&(n=10);for(var o,a,s,h,c,u=new e(t),l=u.getImageData(),g=l.data,f=u.getPixelCount(),d=[],p=0;f>p;p+=n)o=4*p,a=g[o+0],s=g[o+1],h=g[o+2],c=g[o+3],c>=125&&(a>250&&s>250&&h>250||d.push([a,s,h]));var v=r.quantize(d,i),m=v?v.palette():null;return u.removeCanvas(),m},!i)var i={map:function(e,t){var i={};return t?e.map(function(e,r){return i.index=r,t.call(i,e)}):e.slice()},naturalOrder:function(e,t){return t>e?-1:e>t?1:0},sum:function(e,t){var i={};return e.reduce(t?function(e,r,n){return i.index=n,e+t.call(i,r)}:function(e,t){return e+t},0)},max:function(e,t){return Math.max.apply(null,t?i.map(e,t):e)}};var r=function(){function e(e,t,i){return(e<<2*c)+(t<<c)+i}function t(e){function t(){i.sort(e),r=!0}var i=[],r=!1;return{push:function(e){i.push(e),r=!1},peek:function(e){return r||t(),void 0===e&&(e=i.length-1),i[e]},pop:function(){return r||t(),i.pop()},size:function(){return i.length},map:function(e){return i.map(e)},debug:function(){return r||t(),i}}}function r(e,t,i,r,n,o,a){var s=this;s.r1=e,s.r2=t,s.g1=i,s.g2=r,s.b1=n,s.b2=o,s.histo=a}function n(){this.vboxes=new t(function(e,t){return i.naturalOrder(e.vbox.count()*e.vbox.volume(),t.vbox.count()*t.vbox.volume())})}function o(t){var i,r,n,o,a=1<<3*c,s=new Array(a);return t.forEach(function(t){r=t[0]>>u,n=t[1]>>u,o=t[2]>>u,i=e(r,n,o),s[i]=(s[i]||0)+1}),s}function a(e,t){var i,n,o,a=1e6,s=0,h=1e6,c=0,l=1e6,g=0;return e.forEach(function(e){i=e[0]>>u,n=e[1]>>u,o=e[2]>>u,a>i?a=i:i>s&&(s=i),h>n?h=n:n>c&&(c=n),l>o?l=o:o>g&&(g=o)}),new r(a,s,h,c,l,g,t)}function s(t,r){function n(e){var t,i,n,o,a,s=e+"1",h=e+"2",u=0;for(c=r[s];c<=r[h];c++)if(p[c]>d/2){for(n=r.copy(),o=r.copy(),t=c-r[s],i=r[h]-c,a=i>=t?Math.min(r[h]-1,~~(c+i/2)):Math.max(r[s],~~(c-1-t/2));!p[a];)a++;for(u=v[a];!u&&p[a-1];)u=v[--a];return n[h]=a,o[s]=n[h]+1,[n,o]}}if(r.count()){var o=r.r2-r.r1+1,a=r.g2-r.g1+1,s=r.b2-r.b1+1,h=i.max([o,a,s]);if(1==r.count())return[r.copy()];var c,u,l,g,f,d=0,p=[],v=[];if(h==o)for(c=r.r1;c<=r.r2;c++){for(g=0,u=r.g1;u<=r.g2;u++)for(l=r.b1;l<=r.b2;l++)f=e(c,u,l),g+=t[f]||0;d+=g,p[c]=d}else if(h==a)for(c=r.g1;c<=r.g2;c++){for(g=0,u=r.r1;u<=r.r2;u++)for(l=r.b1;l<=r.b2;l++)f=e(u,c,l),g+=t[f]||0;d+=g,p[c]=d}else for(c=r.b1;c<=r.b2;c++){for(g=0,u=r.r1;u<=r.r2;u++)for(l=r.g1;l<=r.g2;l++)f=e(u,l,c),g+=t[f]||0;d+=g,p[c]=d}return p.forEach(function(e,t){v[t]=d-e}),h==o?n("r"):h==a?n("g"):n("b")}}function h(e,r){function h(e,t){for(var i,r=1,n=0;l>n;)if(i=e.pop(),i.count()){var o=s(c,i),a=o[0],h=o[1];if(!a)return;if(e.push(a),h&&(e.push(h),r++),r>=t)return;if(n++>l)return}else e.push(i),n++}if(!e.length||2>r||r>256)return!1;var c=o(e),u=0;c.forEach(function(){u++});var f=a(e,c),d=new t(function(e,t){return i.naturalOrder(e.count(),t.count())});d.push(f),h(d,g*r);for(var p=new t(function(e,t){return i.naturalOrder(e.count()*e.volume(),t.count()*t.volume())});d.size();)p.push(d.pop());h(p,r-p.size());for(var v=new n;p.size();)v.push(p.pop());return v}var c=5,u=8-c,l=1e3,g=.75;return r.prototype={volume:function(e){var t=this;return(!t._volume||e)&&(t._volume=(t.r2-t.r1+1)*(t.g2-t.g1+1)*(t.b2-t.b1+1)),t._volume},count:function(t){var i=this,r=i.histo;if(!i._count_set||t){var n,o,a,s=0;for(n=i.r1;n<=i.r2;n++)for(o=i.g1;o<=i.g2;o++)for(a=i.b1;a<=i.b2;a++)index=e(n,o,a),s+=r[index]||0;i._count=s,i._count_set=!0}return i._count},copy:function(){var e=this;return new r(e.r1,e.r2,e.g1,e.g2,e.b1,e.b2,e.histo)},avg:function(t){var i=this,r=i.histo;if(!i._avg||t){var n,o,a,s,h,u=0,l=1<<8-c,g=0,f=0,d=0;for(o=i.r1;o<=i.r2;o++)for(a=i.g1;a<=i.g2;a++)for(s=i.b1;s<=i.b2;s++)h=e(o,a,s),n=r[h]||0,u+=n,g+=n*(o+.5)*l,f+=n*(a+.5)*l,d+=n*(s+.5)*l;i._avg=u?[~~(g/u),~~(f/u),~~(d/u)]:[~~(l*(i.r1+i.r2+1)/2),~~(l*(i.g1+i.g2+1)/2),~~(l*(i.b1+i.b2+1)/2)]}return i._avg},contains:function(e){var t=this,i=e[0]>>u;return gval=e[1]>>u,bval=e[2]>>u,i>=t.r1&&i<=t.r2&&gval>=t.g1&&gval<=t.g2&&bval>=t.b1&&bval<=t.b2}},n.prototype={push:function(e){this.vboxes.push({vbox:e,color:e.avg()})},palette:function(){return this.vboxes.map(function(e){return e.color})},size:function(){return this.vboxes.size()},map:function(e){for(var t=this.vboxes,i=0;i<t.size();i++)if(t.peek(i).vbox.contains(e))return t.peek(i).color;return this.nearest(e)},nearest:function(e){for(var t,i,r,n=this.vboxes,o=0;o<n.size();o++)i=Math.sqrt(Math.pow(e[0]-n.peek(o).color[0],2)+Math.pow(e[1]-n.peek(o).color[1],2)+Math.pow(e[2]-n.peek(o).color[2],2)),(t>i||void 0===t)&&(t=i,r=n.peek(o).color);return r},forcebw:function(){var e=this.vboxes;e.sort(function(e,t){return i.naturalOrder(i.sum(e.color),i.sum(t.color))});var t=e[0].color;t[0]<5&&t[1]<5&&t[2]<5&&(e[0].color=[0,0,0]);var r=e.length-1,n=e[r].color;n[0]>251&&n[1]>251&&n[2]>251&&(e[r].color=[255,255,255])}},{quantize:h}}();"function"==typeof define&&define.amd?define([],function(){return t}):"object"==typeof exports?module.exports=t:this.ColorThief=t}.call(this)}(),function(){function e(e){return!!e.exifdata}function t(e,t){t=t||e.match(/^data\:([^\;]+)\;base64,/im)[1]||"",e=e.replace(/^data\:([^\;]+)\;base64,/gim,"");for(var i=atob(e),r=i.length,n=new ArrayBuffer(r),o=new Uint8Array(n),a=0;r>a;a++)o[a]=i.charCodeAt(a);return n}function i(e,t){var i=new XMLHttpRequest;i.open("GET",e,!0),i.responseType="blob",i.onload=function(){(200==this.status||0===this.status)&&t(this.response)},i.send()}function r(e,r){function n(t){var i=o(t),n=a(t);e.exifdata=i||{},e.iptcdata=n||{},r&&r.call(e)}if(e.src)if(/^data\:/i.test(e.src)){var s=t(e.src);n(s)}else if(/^blob\:/i.test(e.src)){var h=new FileReader;h.onload=function(e){n(e.target.result)},i(e.src,function(e){h.readAsArrayBuffer(e)})}else{var c=new XMLHttpRequest;c.onload=function(){if(200!=this.status&&0!==this.status)throw"Could not load image";n(c.response),c=null},c.open("GET",e.src,!0),c.responseType="arraybuffer",c.send(null)}else if(window.FileReader&&(e instanceof window.Blob||e instanceof window.File)){var h=new FileReader;h.onload=function(e){g&&console.log("Got file of length "+e.target.result.byteLength),n(e.target.result)},h.readAsArrayBuffer(e)}}function o(e){var t=new DataView(e);if(g&&console.log("Got file of length "+e.byteLength),255!=t.getUint8(0)||216!=t.getUint8(1))return g&&console.log("Not a valid JPEG"),!1;for(var i,r=2,n=e.byteLength;n>r;){if(255!=t.getUint8(r))return g&&console.log("Not a valid marker at offset "+r+", found: "+t.getUint8(r)),!1;if(i=t.getUint8(r+1),g&&console.log(i),225==i)return g&&console.log("Found 0xFFE1 marker"),l(t,r+4,t.getUint16(r+2)-2);r+=2+t.getUint16(r+2)}}function a(e){var t=new DataView(e);if(g&&console.log("Got file of length "+e.byteLength),255!=t.getUint8(0)||216!=t.getUint8(1))return g&&console.log("Not a valid JPEG"),!1;for(var i=2,r=e.byteLength,n=function(e,t){return 56===e.getUint8(t)&&66===e.getUint8(t+1)&&73===e.getUint8(t+2)&&77===e.getUint8(t+3)&&4===e.getUint8(t+4)&&4===e.getUint8(t+5)};r>i;){if(n(t,i)){var o=t.getUint8(i+7);o%2!==0&&(o+=1),0===o&&(o=4);var a=i+8+o,h=t.getUint16(i+6+o);return s(e,a,h)}i++}}function s(e,t,i){for(var r,n,o,a,s,h=new DataView(e),c={},l=t;t+i>l;)28===h.getUint8(l)&&2===h.getUint8(l+1)&&(a=h.getUint8(l+2),a in w&&(o=h.getInt16(l+3),s=o+5,n=w[a],r=u(h,l+5,o),c.hasOwnProperty(n)?c[n]instanceof Array?c[n].push(r):c[n]=[c[n],r]:c[n]=r)),l++;return c}function h(e,t,i,r,n){var o,a,s,h=e.getUint16(i,!n),u={};for(s=0;h>s;s++)o=i+12*s+2,a=r[e.getUint16(o,!n)],!a&&g&&console.log("Unknown tag: "+e.getUint16(o,!n)),u[a]=c(e,o,t,i,n);return u}function c(e,t,i,r,n){var o,a,s,h,c,l,g=e.getUint16(t+2,!n),f=e.getUint32(t+4,!n),d=e.getUint32(t+8,!n)+i;switch(g){case 1:case 7:if(1==f)return e.getUint8(t+8,!n);for(o=f>4?d:t+8,a=[],h=0;f>h;h++)a[h]=e.getUint8(o+h);return a;case 2:return o=f>4?d:t+8,u(e,o,f-1);case 3:if(1==f)return e.getUint16(t+8,!n);for(o=f>2?d:t+8,a=[],h=0;f>h;h++)a[h]=e.getUint16(o+2*h,!n);return a;case 4:if(1==f)return e.getUint32(t+8,!n);for(a=[],h=0;f>h;h++)a[h]=e.getUint32(d+4*h,!n);return a;case 5:if(1==f)return c=e.getUint32(d,!n),l=e.getUint32(d+4,!n),s=new Number(c/l),s.numerator=c,s.denominator=l,s;for(a=[],h=0;f>h;h++)c=e.getUint32(d+8*h,!n),l=e.getUint32(d+4+8*h,!n),a[h]=new Number(c/l),a[h].numerator=c,a[h].denominator=l;return a;case 9:if(1==f)return e.getInt32(t+8,!n);for(a=[],h=0;f>h;h++)a[h]=e.getInt32(d+4*h,!n);return a;case 10:if(1==f)return e.getInt32(d,!n)/e.getInt32(d+4,!n);for(a=[],h=0;f>h;h++)a[h]=e.getInt32(d+8*h,!n)/e.getInt32(d+4+8*h,!n);return a}}function u(e,t,i){var r="";for(n=t;t+i>n;n++)r+=String.fromCharCode(e.getUint8(n));return r}function l(e,t){if("Exif"!=u(e,t,4))return g&&console.log("Not valid EXIF data! "+u(e,t,4)),!1;var i,r,n,o,a,s=t+6;if(18761==e.getUint16(s))i=!1;else{if(19789!=e.getUint16(s))return g&&console.log("Not valid TIFF data! (no 0x4949 or 0x4D4D)"),!1;i=!0}if(42!=e.getUint16(s+2,!i))return g&&console.log("Not valid TIFF data! (no 0x002A)"),!1;var c=e.getUint32(s+4,!i);if(8>c)return g&&console.log("Not valid TIFF data! (First offset less than 8)",e.getUint32(s+4,!i)),!1;if(r=h(e,s,s+c,v,i),r.ExifIFDPointer){o=h(e,s,s+r.ExifIFDPointer,p,i);for(n in o){switch(n){case"LightSource":case"Flash":case"MeteringMode":case"ExposureProgram":case"SensingMethod":case"SceneCaptureType":case"SceneType":case"CustomRendered":case"WhiteBalance":case"GainControl":case"Contrast":case"Saturation":case"Sharpness":case"SubjectDistanceRange":case"FileSource":o[n]=y[n][o[n]];break;case"ExifVersion":case"FlashpixVersion":o[n]=String.fromCharCode(o[n][0],o[n][1],o[n][2],o[n][3]);break;case"ComponentsConfiguration":o[n]=y.Components[o[n][0]]+y.Components[o[n][1]]+y.Components[o[n][2]]+y.Components[o[n][3]]}r[n]=o[n]}}if(r.GPSInfoIFDPointer){a=h(e,s,s+r.GPSInfoIFDPointer,m,i);for(n in a){switch(n){case"GPSVersionID":a[n]=a[n][0]+"."+a[n][1]+"."+a[n][2]+"."+a[n][3]}r[n]=a[n]}}return r}var g=!1,f=this,d=function(e){return e instanceof d?e:this instanceof d?(this.EXIFwrapped=e,void 0):new d(e)};"undefined"!=typeof exports?("undefined"!=typeof module&&module.exports&&(exports=module.exports=d),exports.EXIF=d):f.EXIF=d;var p=d.Tags={36864:"ExifVersion",40960:"FlashpixVersion",40961:"ColorSpace",40962:"PixelXDimension",40963:"PixelYDimension",37121:"ComponentsConfiguration",37122:"CompressedBitsPerPixel",37500:"MakerNote",37510:"UserComment",40964:"RelatedSoundFile",36867:"DateTimeOriginal",36868:"DateTimeDigitized",37520:"SubsecTime",37521:"SubsecTimeOriginal",37522:"SubsecTimeDigitized",33434:"ExposureTime",33437:"FNumber",34850:"ExposureProgram",34852:"SpectralSensitivity",34855:"ISOSpeedRatings",34856:"OECF",37377:"ShutterSpeedValue",37378:"ApertureValue",37379:"BrightnessValue",37380:"ExposureBias",37381:"MaxApertureValue",37382:"SubjectDistance",37383:"MeteringMode",37384:"LightSource",37385:"Flash",37396:"SubjectArea",37386:"FocalLength",41483:"FlashEnergy",41484:"SpatialFrequencyResponse",41486:"FocalPlaneXResolution",41487:"FocalPlaneYResolution",41488:"FocalPlaneResolutionUnit",41492:"SubjectLocation",41493:"ExposureIndex",41495:"SensingMethod",41728:"FileSource",41729:"SceneType",41730:"CFAPattern",41985:"CustomRendered",41986:"ExposureMode",41987:"WhiteBalance",41988:"DigitalZoomRation",41989:"FocalLengthIn35mmFilm",41990:"SceneCaptureType",41991:"GainControl",41992:"Contrast",41993:"Saturation",41994:"Sharpness",41995:"DeviceSettingDescription",41996:"SubjectDistanceRange",40965:"InteroperabilityIFDPointer",42016:"ImageUniqueID"},v=d.TiffTags={256:"ImageWidth",257:"ImageHeight",34665:"ExifIFDPointer",34853:"GPSInfoIFDPointer",40965:"InteroperabilityIFDPointer",258:"BitsPerSample",259:"Compression",262:"PhotometricInterpretation",274:"Orientation",277:"SamplesPerPixel",284:"PlanarConfiguration",530:"YCbCrSubSampling",531:"YCbCrPositioning",282:"XResolution",283:"YResolution",296:"ResolutionUnit",273:"StripOffsets",278:"RowsPerStrip",279:"StripByteCounts",513:"JPEGInterchangeFormat",514:"JPEGInterchangeFormatLength",301:"TransferFunction",318:"WhitePoint",319:"PrimaryChromaticities",529:"YCbCrCoefficients",532:"ReferenceBlackWhite",306:"DateTime",270:"ImageDescription",271:"Make",272:"Model",305:"Software",315:"Artist",33432:"Copyright"},m=d.GPSTags={0:"GPSVersionID",1:"GPSLatitudeRef",2:"GPSLatitude",3:"GPSLongitudeRef",4:"GPSLongitude",5:"GPSAltitudeRef",6:"GPSAltitude",7:"GPSTimeStamp",8:"GPSSatellites",9:"GPSStatus",10:"GPSMeasureMode",11:"GPSDOP",12:"GPSSpeedRef",13:"GPSSpeed",14:"GPSTrackRef",15:"GPSTrack",16:"GPSImgDirectionRef",17:"GPSImgDirection",18:"GPSMapDatum",19:"GPSDestLatitudeRef",20:"GPSDestLatitude",21:"GPSDestLongitudeRef",22:"GPSDestLongitude",23:"GPSDestBearingRef",24:"GPSDestBearing",25:"GPSDestDistanceRef",26:"GPSDestDistance",27:"GPSProcessingMethod",28:"GPSAreaInformation",29:"GPSDateStamp",30:"GPSDifferential"},y=d.StringValues={ExposureProgram:{0:"Not defined",1:"Manual",2:"Normal program",3:"Aperture priority",4:"Shutter priority",5:"Creative program",6:"Action program",7:"Portrait mode",8:"Landscape mode"},MeteringMode:{0:"Unknown",1:"Average",2:"CenterWeightedAverage",3:"Spot",4:"MultiSpot",5:"Pattern",6:"Partial",255:"Other"},LightSource:{0:"Unknown",1:"Daylight",2:"Fluorescent",3:"Tungsten (incandescent light)",4:"Flash",9:"Fine weather",10:"Cloudy weather",11:"Shade",12:"Daylight fluorescent (D 5700 - 7100K)",13:"Day white fluorescent (N 4600 - 5400K)",14:"Cool white fluorescent (W 3900 - 4500K)",15:"White fluorescent (WW 3200 - 3700K)",17:"Standard light A",18:"Standard light B",19:"Standard light C",20:"D55",21:"D65",22:"D75",23:"D50",24:"ISO studio tungsten",255:"Other"},Flash:{0:"Flash did not fire",1:"Flash fired",5:"Strobe return light not detected",7:"Strobe return light detected",9:"Flash fired, compulsory flash mode",13:"Flash fired, compulsory flash mode, return light not detected",15:"Flash fired, compulsory flash mode, return light detected",16:"Flash did not fire, compulsory flash mode",24:"Flash did not fire, auto mode",25:"Flash fired, auto mode",29:"Flash fired, auto mode, return light not detected",31:"Flash fired, auto mode, return light detected",32:"No flash function",65:"Flash fired, red-eye reduction mode",69:"Flash fired, red-eye reduction mode, return light not detected",71:"Flash fired, red-eye reduction mode, return light detected",73:"Flash fired, compulsory flash mode, red-eye reduction mode",77:"Flash fired, compulsory flash mode, red-eye reduction mode, return light not detected",79:"Flash fired, compulsory flash mode, red-eye reduction mode, return light detected",89:"Flash fired, auto mode, red-eye reduction mode",93:"Flash fired, auto mode, return light not detected, red-eye reduction mode",95:"Flash fired, auto mode, return light detected, red-eye reduction mode"},SensingMethod:{1:"Not defined",2:"One-chip color area sensor",3:"Two-chip color area sensor",4:"Three-chip color area sensor",5:"Color sequential area sensor",7:"Trilinear sensor",8:"Color sequential linear sensor"},SceneCaptureType:{0:"Standard",1:"Landscape",2:"Portrait",3:"Night scene"},SceneType:{1:"Directly photographed"},CustomRendered:{0:"Normal process",1:"Custom process"},WhiteBalance:{0:"Auto white balance",1:"Manual white balance"},GainControl:{0:"None",1:"Low gain up",2:"High gain up",3:"Low gain down",4:"High gain down"},Contrast:{0:"Normal",1:"Soft",2:"Hard"},Saturation:{0:"Normal",1:"Low saturation",2:"High saturation"},Sharpness:{0:"Normal",1:"Soft",2:"Hard"},SubjectDistanceRange:{0:"Unknown",1:"Macro",2:"Close view",3:"Distant view"},FileSource:{3:"DSC"},Components:{0:"",1:"Y",2:"Cb",3:"Cr",4:"R",5:"G",6:"B"}},w={120:"caption",110:"credit",25:"keywords",55:"dateCreated",80:"byline",85:"bylineTitle",122:"captionWriter",105:"headline",116:"copyright",15:"category"};d.getData=function(t,i){return(t instanceof Image||t instanceof HTMLImageElement)&&!t.complete?!1:(e(t)?i&&i.call(t):r(t,i),!0)},d.getTag=function(t,i){return e(t)?t.exifdata[i]:void 0},d.getAllTags=function(t){if(!e(t))return{};var i,r=t.exifdata,n={};for(i in r)r.hasOwnProperty(i)&&(n[i]=r[i]);return n},d.pretty=function(t){if(!e(t))return"";var i,r=t.exifdata,n="";for(i in r)r.hasOwnProperty(i)&&(n+="object"==typeof r[i]?r[i]instanceof Number?i+" : "+r[i]+" ["+r[i].numerator+"/"+r[i].denominator+"]\r\n":i+" : ["+r[i].length+" values]\r\n":i+" : "+r[i]+"\r\n");return n},d.readFromBinaryFile=function(e){return o(e)},"function"==typeof define&&define.amd&&define("exif-js",[],function(){return d})}.call(this),function(){function e(e){var t=e.naturalWidth,i=e.naturalHeight;if(t*i>1048576){var r=document.createElement("canvas");r.width=r.height=1;var n=r.getContext("2d");return n.drawImage(e,-t+1,0),0===n.getImageData(0,0,1,1).data[3]}return!1}function t(e,t,i){var r=document.createElement("canvas");r.width=1,r.height=i;var n=r.getContext("2d");n.drawImage(e,0,0);for(var o=n.getImageData(0,0,1,i).data,a=0,s=i,h=i;h>a;){var c=o[4*(h-1)+3];0===c?s=h:a=h,h=s+a>>1}var u=h/i;return 0===u?1:u}function i(e,t,i){var n=document.createElement("canvas");return r(e,n,t,i),n.toDataURL("image/jpeg",t.quality||.8)}function r(i,r,o,a){var s=i.naturalWidth,h=i.naturalHeight;if(s+h){var c=o.width,u=o.height,l=r.getContext("2d");l.save(),n(r,l,c,u,o.orientation);var g=e(i);g&&(s/=2,h/=2);var f=1024,d=document.createElement("canvas");d.width=d.height=f;for(var p=d.getContext("2d"),v=a?t(i,s,h):1,m=Math.ceil(f*c/s),y=Math.ceil(f*u/h/v),w=0,S=0;h>w;){for(var _=0,z=0;s>_;)p.clearRect(0,0,f,f),p.drawImage(i,-_,-w),l.drawImage(d,0,0,f,f,z,S,m,y),_+=f,z+=m;w+=f,S+=y}l.restore(),d=p=null}}function n(e,t,i,r,n){switch(n){case 5:case 6:case 7:case 8:e.width=r,e.height=i;break;default:e.width=i,e.height=r}switch(n){case 2:t.translate(i,0),t.scale(-1,1);break;case 3:t.translate(i,r),t.rotate(Math.PI);break;case 4:t.translate(0,r),t.scale(1,-1);break;case 5:t.rotate(.5*Math.PI),t.scale(1,-1);break;case 6:t.rotate(.5*Math.PI),t.translate(0,-r);break;case 7:t.rotate(.5*Math.PI),t.translate(i,-r),t.scale(-1,1);break;case 8:t.rotate(-.5*Math.PI),t.translate(-i,0)}}function o(e){if(window.Blob&&e instanceof Blob){if(!a)throw Error("No createObjectURL function found to create blob url");var t=new Image;t.src=a.createObjectURL(e),this.blob=e,e=t}if(!e.naturalWidth&&!e.naturalHeight){var i=this;e.onload=e.onerror=function(){var e=i.imageLoadListeners;if(e){i.imageLoadListeners=null;for(var t=0,r=e.length;r>t;t++)e[t]()}},this.imageLoadListeners=[]}this.srcImage=e}var a=window.URL&&window.URL.createObjectURL?window.URL:window.webkitURL&&window.webkitURL.createObjectURL?window.webkitURL:null;o.prototype.render=function(e,t,n){if(this.imageLoadListeners){var o=this;return this.imageLoadListeners.push(function(){o.render(e,t,n)}),void 0}t=t||{};var s=this.srcImage.naturalWidth,h=this.srcImage.naturalHeight,c=t.width,u=t.height,l=t.maxWidth,g=t.maxHeight,f=!this.blob||"image/jpeg"===this.blob.type;c&&!u?u=h*c/s<<0:u&&!c?c=s*u/h<<0:(c=s,u=h),l&&c>l&&(c=l,u=h*c/s<<0),g&&u>g&&(u=g,c=s*u/h<<0);var d={width:c,height:u};for(var p in t)d[p]=t[p];var v=e.tagName.toLowerCase();"img"===v?e.src=i(this.srcImage,d,f):"canvas"===v&&r(this.srcImage,e,d,f),"function"==typeof this.onrender&&this.onrender(e),n&&n(),this.blob&&(this.blob=null,a.revokeObjectURL(this.srcImage.src))},"function"==typeof define&&define.amd?define([],function(){return o}):"object"==typeof exports?module.exports=o:this.MegaPixImage=o}(),function(){var e=function(e){this.canvas=document.createElement("canvas"),this.context=this.canvas.getContext("2d"),document.body.appendChild(this.canvas),this.width=this.canvas.width=e.width,this.height=this.canvas.height=e.height,this.context.drawImage(e,0,0,this.width,this.height)};e.prototype.clear=function(){this.context.clearRect(0,0,this.width,this.height)},e.prototype.update=function(e){this.context.putImageData(e,0,0)},e.prototype.getPixelCount=function(){return this.width*this.height},e.prototype.getImageData=function(){return this.context.getImageData(0,0,this.width,this.height)},e.prototype.removeCanvas=function(){this.canvas.parentNode.removeChild(this.canvas)};var t=function(){};if(t.prototype.getColor=function(e,t){var i=this.getPalette(e,5,t),r=i[0];return r},t.prototype.getPalette=function(t,i,n){"undefined"==typeof i&&(i=10),("undefined"==typeof n||1>n)&&(n=10);for(var o,a,s,h,c,u=new e(t),l=u.getImageData(),g=l.data,f=u.getPixelCount(),d=[],p=0;f>p;p+=n)o=4*p,a=g[o+0],s=g[o+1],h=g[o+2],c=g[o+3],c>=125&&(a>250&&s>250&&h>250||d.push([a,s,h]));
  var v=r.quantize(d,i),m=v?v.palette():null;return u.removeCanvas(),m},!i)var i={map:function(e,t){var i={};return t?e.map(function(e,r){return i.index=r,t.call(i,e)}):e.slice()},naturalOrder:function(e,t){return t>e?-1:e>t?1:0},sum:function(e,t){var i={};return e.reduce(t?function(e,r,n){return i.index=n,e+t.call(i,r)}:function(e,t){return e+t},0)},max:function(e,t){return Math.max.apply(null,t?i.map(e,t):e)}};var r=function(){function e(e,t,i){return(e<<2*c)+(t<<c)+i}function t(e){function t(){i.sort(e),r=!0}var i=[],r=!1;return{push:function(e){i.push(e),r=!1},peek:function(e){return r||t(),void 0===e&&(e=i.length-1),i[e]},pop:function(){return r||t(),i.pop()},size:function(){return i.length},map:function(e){return i.map(e)},debug:function(){return r||t(),i}}}function r(e,t,i,r,n,o,a){var s=this;s.r1=e,s.r2=t,s.g1=i,s.g2=r,s.b1=n,s.b2=o,s.histo=a}function n(){this.vboxes=new t(function(e,t){return i.naturalOrder(e.vbox.count()*e.vbox.volume(),t.vbox.count()*t.vbox.volume())})}function o(t){var i,r,n,o,a=1<<3*c,s=new Array(a);return t.forEach(function(t){r=t[0]>>u,n=t[1]>>u,o=t[2]>>u,i=e(r,n,o),s[i]=(s[i]||0)+1}),s}function a(e,t){var i,n,o,a=1e6,s=0,h=1e6,c=0,l=1e6,g=0;return e.forEach(function(e){i=e[0]>>u,n=e[1]>>u,o=e[2]>>u,a>i?a=i:i>s&&(s=i),h>n?h=n:n>c&&(c=n),l>o?l=o:o>g&&(g=o)}),new r(a,s,h,c,l,g,t)}function s(t,r){function n(e){var t,i,n,o,a,s=e+"1",h=e+"2",u=0;for(c=r[s];c<=r[h];c++)if(p[c]>d/2){for(n=r.copy(),o=r.copy(),t=c-r[s],i=r[h]-c,a=i>=t?Math.min(r[h]-1,~~(c+i/2)):Math.max(r[s],~~(c-1-t/2));!p[a];)a++;for(u=v[a];!u&&p[a-1];)u=v[--a];return n[h]=a,o[s]=n[h]+1,[n,o]}}if(r.count()){var o=r.r2-r.r1+1,a=r.g2-r.g1+1,s=r.b2-r.b1+1,h=i.max([o,a,s]);if(1==r.count())return[r.copy()];var c,u,l,g,f,d=0,p=[],v=[];if(h==o)for(c=r.r1;c<=r.r2;c++){for(g=0,u=r.g1;u<=r.g2;u++)for(l=r.b1;l<=r.b2;l++)f=e(c,u,l),g+=t[f]||0;d+=g,p[c]=d}else if(h==a)for(c=r.g1;c<=r.g2;c++){for(g=0,u=r.r1;u<=r.r2;u++)for(l=r.b1;l<=r.b2;l++)f=e(u,c,l),g+=t[f]||0;d+=g,p[c]=d}else for(c=r.b1;c<=r.b2;c++){for(g=0,u=r.r1;u<=r.r2;u++)for(l=r.g1;l<=r.g2;l++)f=e(u,l,c),g+=t[f]||0;d+=g,p[c]=d}return p.forEach(function(e,t){v[t]=d-e}),h==o?n("r"):h==a?n("g"):n("b")}}function h(e,r){function h(e,t){for(var i,r=1,n=0;l>n;)if(i=e.pop(),i.count()){var o=s(c,i),a=o[0],h=o[1];if(!a)return;if(e.push(a),h&&(e.push(h),r++),r>=t)return;if(n++>l)return}else e.push(i),n++}if(!e.length||2>r||r>256)return!1;var c=o(e),u=0;c.forEach(function(){u++});var f=a(e,c),d=new t(function(e,t){return i.naturalOrder(e.count(),t.count())});d.push(f),h(d,g*r);for(var p=new t(function(e,t){return i.naturalOrder(e.count()*e.volume(),t.count()*t.volume())});d.size();)p.push(d.pop());h(p,r-p.size());for(var v=new n;p.size();)v.push(p.pop());return v}var c=5,u=8-c,l=1e3,g=.75;return r.prototype={volume:function(e){var t=this;return(!t._volume||e)&&(t._volume=(t.r2-t.r1+1)*(t.g2-t.g1+1)*(t.b2-t.b1+1)),t._volume},count:function(t){var i=this,r=i.histo;if(!i._count_set||t){var n,o,a,s=0;for(n=i.r1;n<=i.r2;n++)for(o=i.g1;o<=i.g2;o++)for(a=i.b1;a<=i.b2;a++)index=e(n,o,a),s+=r[index]||0;i._count=s,i._count_set=!0}return i._count},copy:function(){var e=this;return new r(e.r1,e.r2,e.g1,e.g2,e.b1,e.b2,e.histo)},avg:function(t){var i=this,r=i.histo;if(!i._avg||t){var n,o,a,s,h,u=0,l=1<<8-c,g=0,f=0,d=0;for(o=i.r1;o<=i.r2;o++)for(a=i.g1;a<=i.g2;a++)for(s=i.b1;s<=i.b2;s++)h=e(o,a,s),n=r[h]||0,u+=n,g+=n*(o+.5)*l,f+=n*(a+.5)*l,d+=n*(s+.5)*l;i._avg=u?[~~(g/u),~~(f/u),~~(d/u)]:[~~(l*(i.r1+i.r2+1)/2),~~(l*(i.g1+i.g2+1)/2),~~(l*(i.b1+i.b2+1)/2)]}return i._avg},contains:function(e){var t=this,i=e[0]>>u;return gval=e[1]>>u,bval=e[2]>>u,i>=t.r1&&i<=t.r2&&gval>=t.g1&&gval<=t.g2&&bval>=t.b1&&bval<=t.b2}},n.prototype={push:function(e){this.vboxes.push({vbox:e,color:e.avg()})},palette:function(){return this.vboxes.map(function(e){return e.color})},size:function(){return this.vboxes.size()},map:function(e){for(var t=this.vboxes,i=0;i<t.size();i++)if(t.peek(i).vbox.contains(e))return t.peek(i).color;return this.nearest(e)},nearest:function(e){for(var t,i,r,n=this.vboxes,o=0;o<n.size();o++)i=Math.sqrt(Math.pow(e[0]-n.peek(o).color[0],2)+Math.pow(e[1]-n.peek(o).color[1],2)+Math.pow(e[2]-n.peek(o).color[2],2)),(t>i||void 0===t)&&(t=i,r=n.peek(o).color);return r},forcebw:function(){var e=this.vboxes;e.sort(function(e,t){return i.naturalOrder(i.sum(e.color),i.sum(t.color))});var t=e[0].color;t[0]<5&&t[1]<5&&t[2]<5&&(e[0].color=[0,0,0]);var r=e.length-1,n=e[r].color;n[0]>251&&n[1]>251&&n[2]>251&&(e[r].color=[255,255,255])}},{quantize:h}}();"function"==typeof define&&define.amd?define([],function(){return t}):"object"==typeof exports?module.exports=t:this.ColorThief=t}.call(this);