"use strict";YUI.add("crop-box",function(t){t.cropbox=t.Base.create("crop-box",t.Base,[],{initializer:function(t){this.options=t,this.state={},this.render()},render:function(){return this.imageBox=t.one(this.options.imageBox),this.thumbBox=this.imageBox.one(this.options.thumbBox),this.spinner=this.imageBox.one(this.options.spinner),this.initObject(),this},initObject:function(){var e=this;this.spinner.show(),this.image=new Image,this.image.onload=function(){e.spinner.hide(),e.setBackground(),e.imageBox.on("mousedown",e.imgMouseDown,e),e.imageBox.on("mousemove",e.imgMouseMove,e),e.mouseup=t.one("body").on("mouseup",e.imgMouseUp,e),t.UA.gecko>0?e.imageBox.on("DOMMouseScroll",e.zoomImage,e):e.imageBox.on("mousewheel",e.zoomImage,e)},this.image.src=this.options.imgSrc},setBackground:function(){this.ratio||(this.ratio=1);var t=parseInt(this.image.width)*this.ratio,e=parseInt(this.image.height)*this.ratio,i=(this.imageBox.get("clientWidth")-t)/2,o=(this.imageBox.get("clientHeight")-e)/2;this.imageBox.setAttribute("style","background-image: url("+this.image.src+"); background-size: "+t+"px "+e+"px; background-position: "+i+"px "+o+"px; background-repeat: no-repeat")},imgMouseDown:function(t){t.stopImmediatePropagation(),this.state.dragable=!0,this.state.mouseX=t.clientX,this.state.mouseY=t.clientY},imgMouseMove:function(t){if(t.stopImmediatePropagation(),this.state.dragable){var e=t.clientX-this.state.mouseX,i=t.clientY-this.state.mouseY,o=this.imageBox.getStyle("backgroundPosition").split(" "),s=e+parseInt(o[0]),a=i+parseInt(o[1]);this.imageBox.setStyle("backgroundPosition",s+"px "+a+"px"),this.state.mouseX=t.clientX,this.state.mouseY=t.clientY}},imgMouseUp:function(t){t.stopImmediatePropagation(),this.state.dragable=!1},zoomImage:function(t){this.ratio*=t.wheelDelta>0?1.1:.9,this.setBackground()},getDataURL:function(){var t=this.thumbBox.get("clientWidth"),e=this.thumbBox.get("clientHeight"),i=document.createElement("canvas"),o=this.imageBox.getStyle("backgroundPosition").split(" "),s=this.imageBox.getStyle("backgroundSize").split(" "),a=parseInt(o[0])-this.imageBox.get("clientWidth")/2+t/2,n=parseInt(o[1])-this.imageBox.get("clientHeight")/2+e/2,g=parseInt(s[0]),h=parseInt(s[1]),r=parseInt(this.image.height),m=parseInt(this.image.width);i.width=t,i.height=e;var u=i.getContext("2d");u.drawImage(this.image,0,0,m,r,a,n,g,h);var c=i.toDataURL("image/png");return c},getBlob:function(){for(var t=this.getDataURL(),e=t.replace("data:image/png;base64,",""),i=atob(e),o=[],s=0;s<i.length;s++)o.push(i.charCodeAt(s));return new Blob([new Uint8Array(o)],{type:"image/png"})},zoomIn:function(){this.ratio*=1.1,this.setBackground()},zoomOut:function(){this.ratio*=.9,this.setBackground()},destructor:function(){this.mouseup&&this.mouseup.detach()}})},"1.0",{requires:["node","base"]});