!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("react"),require("react-dom"),require("react-bootstrap")):"function"==typeof define&&define.amd?define(["react","react-dom","react-bootstrap"],t):"object"==typeof exports?exports.ReactAvatarCropper=t(require("react"),require("react-dom"),require("react-bootstrap")):e.ReactAvatarCropper=t(e.react,e["react-dom"],e["react-bootstrap"])}(this,function(e,t,r){return function(e){function t(o){if(r[o])return r[o].exports;var n=r[o]={exports:{},id:o,loaded:!1};return e[o].call(n.exports,n,n.exports,t),n.loaded=!0,n.exports}var r={};return t.m=e,t.c=r,t.p="",t(0)}([function(e,t,r){e.exports=r(1)},function(e,t,r){"use strict";function o(e){return e&&e.__esModule?e:{"default":e}}function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}Object.defineProperty(t,"__esModule",{value:!0});var a=function(){function e(e,t){for(var r=0;r<t.length;r++){var o=t[r];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}return function(t,r,o){return r&&e(t.prototype,r),o&&e(t,o),t}}(),s=function(e,t,r){for(var o=!0;o;){var n=e,i=t,a=r;o=!1,null===n&&(n=Function.prototype);var s=Object.getOwnPropertyDescriptor(n,i);if(void 0!==s){if("value"in s)return s.value;var u=s.get;if(void 0===u)return;return u.call(a)}var p=Object.getPrototypeOf(n);if(null===p)return;e=p,t=i,r=a,o=!0,s=p=void 0}};r(2);var u=r(6),p=o(u),c=r(7),d=o(c),l=r(8),h=r(9),f=r(10),m=o(f),g=function(e,t,r){(0,m["default"])(!isNaN(parseInt(e[t])),"Invalid "+t+" '"+e.size+"' sent to '"+r+"'. Requires an\n    int or string capable of conversion to an int.\n    Check the render method of == '"+r+"'. == ")},v=function(e){function t(){n(this,t),s(Object.getPrototypeOf(t.prototype),"constructor",this).call(this),this.state={dragging:!1,image:{},mouse:{x:null,y:null},preview:null,zoom:1},this.listeners=[]}return i(t,e),a(t,[{key:"fitImageToCanvas",value:function(e,t){var r,o,n=this.props.height/this.props.width,i=t/e;if(n>i){r=this.props.height;var a=r/t;o=e*a}else{o=this.props.width;var a=o/e;r=t*a}return{width:o,height:r}}},{key:"prepareImage",value:function(e){var t=this,r=new Image;(0,h.isDataURL)(e)||(r.crossOrigin="anonymous"),r.onload=function(){var e=t.fitImageToCanvas(r.width,r.height);e.resource=r,e.x=0,e.y=0,t.setState({dragging:!1,image:e,preview:t.toDataURL()})},r.src=e}},{key:"mouseDownListener",value:function(e){this.setState({image:this.state.image,dragging:!0,mouse:{x:null,y:null}})}},{key:"preventSelection",value:function(e){if(this.state.dragging)return e.preventDefault(),!1}},{key:"mouseUpListener",value:function(e){this.setState({dragging:!1,preview:this.toDataURL()})}},{key:"mouseMoveListener",value:function(e){if(this.state.dragging){var t=e.clientX,r=e.clientY,o=this.state.image.x,n=this.state.image.y,i=this.state.image;if(this.state.mouse.x&&this.state.mouse.y){var a=this.state.mouse.x-t,s=this.state.mouse.y-r,u=this.boundedCoords(o,n,a,s);i.x=u.x,i.y=u.y}this.setState({image:this.state.image,mouse:{x:t,y:r}})}}},{key:"boundedCoords",value:function(e,t,r,o){var n=e-r,i=t-o,a=this.state.image.width*this.state.zoom,s=(a-this.state.image.width)/2,u=(this.state.image.x-s,this.props.width);e=n-s>0?s:n<-a+u?u-a:n;var p=this.state.image.height*this.state.zoom,c=(p-this.state.image.height)/2,d=(this.state.image.y-c,this.props.height);return t=i-c>0?c:i<-p+d?d-p:i,{x:e,y:t}}},{key:"componentDidMount",value:function(){var e=this,t=d["default"].findDOMNode(this.refs.canvas);t.getContext("2d");this.prepareImage(this.props.image),this.listeners={mousemove:function(t){return e.mouseMoveListener(t)},mouseup:function(t){return e.mouseUpListener(t)},mousedown:function(t){return e.mouseDownListener(t)}},window.addEventListener("mousemove",this.listeners.mousemove,!1),window.addEventListener("mouseup",this.listeners.mouseup,!1),t.addEventListener("mousedown",this.listeners.mousedown,!1),document.onselectstart=function(t){return e.preventSelection(t)}}},{key:"componentWillUnmount",value:function(){var e=d["default"].findDOMNode(this.refs.canvas);window.removeEventListener("mousemove",this.listeners.mousemove),window.removeEventListener("mouseup",this.listeners.mouseup),e.removeEventListener("mousedown",this.listeners.mousedown)}},{key:"componentDidUpdate",value:function(){var e=d["default"].findDOMNode(this.refs.canvas).getContext("2d");e.clearRect(0,0,this.props.width,this.props.height),this.addImageToCanvas(e,this.state.image)}},{key:"addImageToCanvas",value:function(e,t){if(t.resource){e.save(),e.globalCompositeOperation="destination-over";var r=this.state.image.width*this.state.zoom,o=this.state.image.height*this.state.zoom,n=t.x-(r-this.state.image.width)/2,i=t.y-(o-this.state.image.height)/2;n=Math.min(n,0),i=Math.min(i,0),i=o+i>=this.props.height?i:i+(this.props.height-(o+i)),n=r+n>=this.props.width?n:n+(this.props.width-(r+n)),e.drawImage(t.resource,n,i,t.width*this.state.zoom,t.height*this.state.zoom),e.restore()}}},{key:"toDataURL",value:function(){var e=document.createElement("canvas"),t=e.getContext("2d");return e.width=this.props.width,e.height=this.props.height,this.addImageToCanvas(t,{resource:this.state.image.resource,x:this.state.image.x,y:this.state.image.y,height:this.state.image.height,width:this.state.image.width}),e.toDataURL()}},{key:"handleCrop",value:function(){var e=this.toDataURL();this.props.onCrop(e)}},{key:"handleZoomUpdate",value:function(){var e=this.state;e.zoom=d["default"].findDOMNode(this.refs.zoom).value,this.setState({newstate:e})}},{key:"render",value:function(){return p["default"].createElement("div",{className:"AvatarCropper-canvas"},p["default"].createElement("div",{className:"row"},p["default"].createElement("canvas",{ref:"canvas",width:this.props.width,height:this.props.height})),p["default"].createElement("div",{className:"row"},p["default"].createElement("input",{type:"range",name:"zoom",ref:"zoom",onChange:this.handleZoomUpdate.bind(this),style:{width:this.props.width},min:"1",max:"3",step:"0.01",defaultValue:"1"})),p["default"].createElement("div",{className:"modal-footer"},p["default"].createElement(l.Button,{onClick:this.props.onRequestHide},this.props.closeButtonCopy),p["default"].createElement(l.Button,{bsStyle:"primary",onClick:this.handleCrop.bind(this)},this.props.cropButtonCopy)))}}]),t}(p["default"].Component);v.propTypes={image:p["default"].PropTypes.string.isRequired,width:g,height:g,zoom:g},v.defaultProps={width:400,height:400,zoom:1};var y=function(e){function t(){n(this,t),s(Object.getPrototypeOf(t.prototype),"constructor",this).call(this)}return i(t,e),a(t,[{key:"handleZoomUpdate",value:function(){var e=d["default"].findDOMNode(this.refs.zoom).value;this.setState({zoom:e})}},{key:"render",value:function(){return p["default"].createElement(l.Modal,{title:"Crop It",bsSize:this.props.modalSize,onHide:this.props.onRequestHide,show:this.props.cropperOpen,backdrop:!1},p["default"].createElement("div",{className:"modal-body"},p["default"].createElement("div",{className:"AvatarCropper-base"},p["default"].createElement(v,{image:this.props.image,width:this.props.width,height:this.props.height,onCrop:this.props.onCrop,onRequestHide:this.props.onRequestHide,closeButtonCopy:this.props.closeButtonCopy,cropButtonCopy:this.props.cropButtonCopy}))))}}]),t}(p["default"].Component);y.propTypes={image:p["default"].PropTypes.string.isRequired,onCrop:p["default"].PropTypes.func.isRequired,closeButtonCopy:p["default"].PropTypes.string,cropButtonCopy:p["default"].PropTypes.string,width:g,height:g,modalSize:p["default"].PropTypes.oneOf(["lg","large","sm","small"]),onRequestHide:p["default"].PropTypes.func.isRequired},y.defaultProps={width:400,height:400,modalSize:"large",closeButtonCopy:"Close",cropButtonCopy:"Crop and Save"},t["default"]=y,e.exports=t["default"]},function(e,t,r){var o=r(3);"string"==typeof o&&(o=[[e.id,o,""]]);r(5)(o,{});o.locals&&(e.exports=o.locals)},function(e,t,r){t=e.exports=r(4)(),t.push([e.id,".AvatarCropper-base{text-align:center}.AvatarCropper-base input[type=range]{display:inline-block;-webkit-appearance:none;padding:20px 0;border:1px solid #fff;width:400px}.AvatarCropper-base input[type=range]::-webkit-slider-runnable-track{width:400px;height:5px;background:#ddd;border:none;border-radius:3px}.AvatarCropper-base input[type=range]::-webkit-slider-thumb{-webkit-appearance:none;border:none;height:16px;width:16px;border-radius:50%;background:#454545;margin-top:-4px}.AvatarCropper-base input[type=range]:focus{outline:0}.AvatarCropper-base input[type=range]:focus::-webkit-slider-runnable-track{background:#ccc}.AvatarCropper-base input[type=range]::-moz-range-track{width:400px;height:5px;background:#ddd;border:none;border-radius:3px}.AvatarCropper-base input[type=range]::-moz-range-thumb{border:none;height:16px;width:16px;border-radius:50%;background:#454545}.AvatarCropper-base input[type=range]:-moz-focusring{outline:#fff solid 1px;outline-offset:-1px}.AvatarCropper-base input[type=range]::-ms-track{width:400px;height:5px;background:0 0;border-color:transparent;border-width:6px 0;color:transparent}.AvatarCropper-base input[type=range]::-ms-fill-lower{background:#777;border-radius:10px}.AvatarCropper-base input[type=range]::-ms-fill-upper{background:#ddd;border-radius:10px}.AvatarCropper-base input[type=range]::-ms-thumb{border:none;height:16px;width:16px;border-radius:50%;background:#454545}.AvatarCropper-base input[type=range]:focus::-ms-fill-lower{background:#888}.AvatarCropper-base input[type=range]:focus::-ms-fill-upper{background:#ccc}.AvatarCropper-base canvas{cursor:move}",""])},function(e,t){e.exports=function(){var e=[];return e.toString=function(){for(var e=[],t=0;t<this.length;t++){var r=this[t];r[2]?e.push("@media "+r[2]+"{"+r[1]+"}"):e.push(r[1])}return e.join("")},e.i=function(t,r){"string"==typeof t&&(t=[[null,t,""]]);for(var o={},n=0;n<this.length;n++){var i=this[n][0];"number"==typeof i&&(o[i]=!0)}for(n=0;n<t.length;n++){var a=t[n];"number"==typeof a[0]&&o[a[0]]||(r&&!a[2]?a[2]=r:r&&(a[2]="("+a[2]+") and ("+r+")"),e.push(a))}},e}},function(e,t,r){function o(e,t){for(var r=0;r<e.length;r++){var o=e[r],n=d[o.id];if(n){n.refs++;for(var i=0;i<n.parts.length;i++)n.parts[i](o.parts[i]);for(;i<o.parts.length;i++)n.parts.push(s(o.parts[i],t))}else{for(var a=[],i=0;i<o.parts.length;i++)a.push(s(o.parts[i],t));d[o.id]={id:o.id,refs:1,parts:a}}}}function n(e){for(var t=[],r={},o=0;o<e.length;o++){var n=e[o],i=n[0],a=n[1],s=n[2],u=n[3],p={css:a,media:s,sourceMap:u};r[i]?r[i].parts.push(p):t.push(r[i]={id:i,parts:[p]})}return t}function i(){var e=document.createElement("style"),t=f();return e.type="text/css",t.appendChild(e),e}function a(){var e=document.createElement("link"),t=f();return e.rel="stylesheet",t.appendChild(e),e}function s(e,t){var r,o,n;if(t.singleton){var s=g++;r=m||(m=i()),o=u.bind(null,r,s,!1),n=u.bind(null,r,s,!0)}else e.sourceMap&&"function"==typeof URL&&"function"==typeof URL.createObjectURL&&"function"==typeof URL.revokeObjectURL&&"function"==typeof Blob&&"function"==typeof btoa?(r=a(),o=c.bind(null,r),n=function(){r.parentNode.removeChild(r),r.href&&URL.revokeObjectURL(r.href)}):(r=i(),o=p.bind(null,r),n=function(){r.parentNode.removeChild(r)});return o(e),function(t){if(t){if(t.css===e.css&&t.media===e.media&&t.sourceMap===e.sourceMap)return;o(e=t)}else n()}}function u(e,t,r,o){var n=r?"":o.css;if(e.styleSheet)e.styleSheet.cssText=v(t,n);else{var i=document.createTextNode(n),a=e.childNodes;a[t]&&e.removeChild(a[t]),a.length?e.insertBefore(i,a[t]):e.appendChild(i)}}function p(e,t){var r=t.css,o=t.media;t.sourceMap;if(o&&e.setAttribute("media",o),e.styleSheet)e.styleSheet.cssText=r;else{for(;e.firstChild;)e.removeChild(e.firstChild);e.appendChild(document.createTextNode(r))}}function c(e,t){var r=t.css,o=(t.media,t.sourceMap);o&&(r+="\n/*# sourceMappingURL=data:application/json;base64,"+btoa(unescape(encodeURIComponent(JSON.stringify(o))))+" */");var n=new Blob([r],{type:"text/css"}),i=e.href;e.href=URL.createObjectURL(n),i&&URL.revokeObjectURL(i)}var d={},l=function(e){var t;return function(){return"undefined"==typeof t&&(t=e.apply(this,arguments)),t}},h=l(function(){return/msie [6-9]\b/.test(window.navigator.userAgent.toLowerCase())}),f=l(function(){return document.head||document.getElementsByTagName("head")[0]}),m=null,g=0;e.exports=function(e,t){t=t||{},"undefined"==typeof t.singleton&&(t.singleton=h());var r=n(e);return o(r,t),function(e){for(var i=[],a=0;a<r.length;a++){var s=r[a],u=d[s.id];u.refs--,i.push(u)}if(e){var p=n(e);o(p,t)}for(var a=0;a<i.length;a++){var u=i[a];if(0===u.refs){for(var c=0;c<u.parts.length;c++)u.parts[c]();delete d[u.id]}}}};var v=function(){var e=[];return function(t,r){return e[t]=r,e.filter(Boolean).join("\n")}}()},function(t,r){t.exports=e},function(e,r){e.exports=t},function(e,t){e.exports=r},function(e,t){"use strict";function r(e){return!!e.match(r.regex)}Object.defineProperty(t,"__esModule",{value:!0}),t.isDataURL=r,r.regex=/^\s*data:([a-z]+\/[a-z]+(;[a-z\-]+\=[a-z\-]+)?)?(;base64)?,[a-z0-9\!\$\&\'\,\(\)\*\+\,\;\=\-\.\_\~\:\@\/\?\%\s]*\s*$/i},function(e,t,r){(function(t){"use strict";var r=function(){};"production"!==t.env.NODE_ENV&&(r=function(e,t,r){var o=arguments.length;r=new Array(o>2?o-2:0);for(var n=2;n<o;n++)r[n-2]=arguments[n];if(void 0===t)throw new Error("`warning(condition, format, ...args)` requires a warning message argument");if(t.length<10||/^[s\W]*$/.test(t))throw new Error("The warning format should be able to uniquely identify this warning. Please, use a more descriptive format than: "+t);if(!e){var i=0,a="Warning: "+t.replace(/%s/g,function(){return r[i++]});"undefined"!=typeof console&&console.error(a);try{throw new Error(a)}catch(s){}}}),e.exports=r}).call(t,r(11))},function(e,t){function r(){throw new Error("setTimeout has not been defined")}function o(){throw new Error("clearTimeout has not been defined")}function n(e){if(c===setTimeout)return setTimeout(e,0);if((c===r||!c)&&setTimeout)return c=setTimeout,setTimeout(e,0);try{return c(e,0)}catch(t){try{return c.call(null,e,0)}catch(t){return c.call(this,e,0)}}}function i(e){if(d===clearTimeout)return clearTimeout(e);if((d===o||!d)&&clearTimeout)return d=clearTimeout,clearTimeout(e);try{return d(e)}catch(t){try{return d.call(null,e)}catch(t){return d.call(this,e)}}}function a(){m&&h&&(m=!1,h.length?f=h.concat(f):g=-1,f.length&&s())}function s(){if(!m){var e=n(a);m=!0;for(var t=f.length;t;){for(h=f,f=[];++g<t;)h&&h[g].run();g=-1,t=f.length}h=null,m=!1,i(e)}}function u(e,t){this.fun=e,this.array=t}function p(){}var c,d,l=e.exports={};!function(){try{c="function"==typeof setTimeout?setTimeout:r}catch(e){c=r}try{d="function"==typeof clearTimeout?clearTimeout:o}catch(e){d=o}}();var h,f=[],m=!1,g=-1;l.nextTick=function(e){var t=new Array(arguments.length-1);if(arguments.length>1)for(var r=1;r<arguments.length;r++)t[r-1]=arguments[r];f.push(new u(e,t)),1!==f.length||m||n(s)},u.prototype.run=function(){this.fun.apply(null,this.array)},l.title="browser",l.browser=!0,l.env={},l.argv=[],l.version="",l.versions={},l.on=p,l.addListener=p,l.once=p,l.off=p,l.removeListener=p,l.removeAllListeners=p,l.emit=p,l.binding=function(e){throw new Error("process.binding is not supported")},l.cwd=function(){return"/"},l.chdir=function(e){throw new Error("process.chdir is not supported")},l.umask=function(){return 0}}])});