(function webpackUniversalModuleDefinition(root,factory){if(typeof exports==='object'&&typeof module==='object')module.exports=factory(require("jquery"));else if(typeof define==='function'&&define.amd)define(["jquery"],factory);else if(typeof exports==='object')exports["cropit"]=factory(require("jquery"));else root["cropit"]=factory(root["jQuery"]);})(this,function(__WEBPACK_EXTERNAL_MODULE_1__){return(function(modules){var installedModules={};function __webpack_require__(moduleId){if(installedModules[moduleId])return installedModules[moduleId].exports;var module=installedModules[moduleId]={exports:{},id:moduleId,loaded:false};modules[moduleId].call(module.exports,module,module.exports,__webpack_require__);module.loaded=true;return module.exports;}__webpack_require__.m=modules;__webpack_require__.c=installedModules;__webpack_require__.p="";return __webpack_require__(0);})([function(module,exports,__webpack_require__){function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{'default':obj};}var _jquery=__webpack_require__(1);var _jquery2=_interopRequireDefault(_jquery);var _cropit=__webpack_require__(2);var _cropit2=_interopRequireDefault(_cropit);var _constants=__webpack_require__(4);var _utils=__webpack_require__(6);var applyOnEach=function applyOnEach($el,callback){return $el.each(function(){var cropit=_jquery2['default'].data(this,_constants.PLUGIN_KEY);if(!cropit){return;}callback(cropit);});};var callOnFirst=function callOnFirst($el,method,options){var cropit=$el.first().data(_constants.PLUGIN_KEY);if(!cropit||!_jquery2['default'].isFunction(cropit[method])){return null;}return cropit[method](options);};var methods={init:function init(options){return this.each(function(){if(_jquery2['default'].data(this,_constants.PLUGIN_KEY)){return;}var cropit=new _cropit2['default'](_jquery2['default'],this,options);_jquery2['default'].data(this,_constants.PLUGIN_KEY,cropit);});},destroy:function destroy(){return this.each(function(){_jquery2['default'].removeData(this,_constants.PLUGIN_KEY);});},isZoomable:function isZoomable(){return callOnFirst(this,'isZoomable');},'export':function _export(options){return callOnFirst(this,'getCroppedImageData',options);},imageState:function imageState(){return callOnFirst(this,'getImageState');},imageSize:function imageSize(){return callOnFirst(this,'getImageSize');},prop:function prop(name,value){if((0,_utils.exists)(value)){return applyOnEach(this,function(cropit){cropit['set'+(0,_utils.capitalize)(name)](value);});}else{return callOnFirst(this,'get'+(0,_utils.capitalize)(name));}},disable:function disable(){return applyOnEach(this,function(cropit){cropit.disable();});},reenable:function reenable(){return applyOnEach(this,function(cropit){cropit.reenable();});}};_jquery2['default'].fn.cropit=function(method){if(methods[method]){return methods[method].apply(this,Array.prototype.slice.call(arguments,1));}else if(['imageSrc','offset','previewSize','zoom','initialZoom','exportZoom','minZoom','maxZoom'].indexOf(method)>=0){return methods.prop.apply(this,arguments);}else{return methods.init.apply(this,arguments);}};},function(module,exports){module.exports=__WEBPACK_EXTERNAL_MODULE_1__;},function(module,exports,__webpack_require__){Object.defineProperty(exports,'__esModule',{value:true});var _createClass=(function(){function defineProperties(target,props){for(var i=0;i').addClass(_constants.CLASS_NAMES.IMAGE_BACKGROUND).attr('alt','').css('position','absolute');this.$imageBgContainer=(0,_jquery2['default'])('
').addClass(_constants.CLASS_NAMES.IMAGE_BACKGROUND_CONTAINER).css({position:'absolute',zIndex:0,left:-this.imageBgBorderWidthArray[3]+window.parseInt(this.$preview.css('border-left-width')||0),top:-this.imageBgBorderWidthArray[0]+window.parseInt(this.$preview.css('border-top-width')||0),width:this.previewSize.w+this.imageBgBorderWidthArray[1]+this.imageBgBorderWidthArray[3],height:this.previewSize.h+this.imageBgBorderWidthArray[0]+this.imageBgBorderWidthArray[2]}).append(this.$imageBg);if(this.imageBgBorderWidthArray[0]>0){this.$imageBgContainer.css('overflow','hidden');}$previewContainer.css('position','relative').prepend(this.$imageBgContainer);this.$preview.css('position','relative');this.$preview.hover(function(){_this.$imageBg.addClass(_constants.CLASS_NAMES.PREVIEW_HOVERED);},function(){_this.$imageBg.removeClass(_constants.CLASS_NAMES.PREVIEW_HOVERED);});}this.setInitialZoom(this.options.initialZoom);this.imageLoaded=false;this.moveContinue=false;this.zoomer=new _Zoomer2['default']();if(this.options.allowDragNDrop){_jquery2['default'].event.props.push('dataTransfer');}this.bindListeners();if(this.options.imageState&&this.options.imageState.src){this.loadImage(this.options.imageState.src);}}},{key:'bindListeners',value:function bindListeners(){this.$fileInput.on('change.cropit',this.onFileChange.bind(this));this.$preview.on(_constants.EVENTS.PREVIEW,this.onPreviewEvent.bind(this));this.$zoomSlider.on(_constants.EVENTS.ZOOM_INPUT,this.onZoomSliderChange.bind(this));if(this.options.allowDragNDrop){this.$preview.on('dragover.cropit dragleave.cropit',this.onDragOver.bind(this));this.$preview.on('drop.cropit',this.onDrop.bind(this));}}},{key:'unbindListeners',value:function unbindListeners(){this.$fileInput.off('change.cropit');this.$preview.off(_constants.EVENTS.PREVIEW);this.$preview.off('dragover.cropit dragleave.cropit drop.cropit');this.$zoomSlider.off(_constants.EVENTS.ZOOM_INPUT);}},{key:'onFileChange',value:function onFileChange(e){this.options.onFileChange(e);if(this.$fileInput.get(0).files){this.loadFileReader(this.$fileInput.get(0).files[0]);}}},{key:'loadFileReader',value:function loadFileReader(file){var fileReader=new FileReader();if(file&&file.type.match('image')){fileReader.readAsDataURL(file);fileReader.onload=this.onFileReaderLoaded.bind(this);fileReader.onerror=this.onFileReaderError.bind(this);}else if(file){this.onFileReaderError();}}},{key:'onFileReaderLoaded',value:function onFileReaderLoaded(e){this.loadImage(e.target.result);}},{key:'onFileReaderError',value:function onFileReaderError(){this.options.onFileReaderError();}},{key:'onDragOver',value:function onDragOver(e){e.preventDefault();e.dataTransfer.dropEffect='copy';this.$preview.toggleClass(_constants.CLASS_NAMES.DRAG_HOVERED,e.type==='dragover');}},{key:'onDrop',value:function onDrop(e){var _this2=this;e.preventDefault();e.stopPropagation();var files=Array.prototype.slice.call(e.dataTransfer.files,0);files.some(function(file){if(!file.type.match('image')){return false;}_this2.loadFileReader(file);return true;});this.$preview.removeClass(_constants.CLASS_NAMES.DRAG_HOVERED);}},{key:'loadImage',value:function loadImage(imageSrc){if(!imageSrc){return;}this.options.onImageLoading();this.setImageLoadingClass();this.preImage.src=imageSrc;}},{key:'setImageSrc',value:function setImageSrc(imageSrc){this.loadImage(imageSrc);}},{key:'onPreImageLoaded',value:function onPreImageLoaded(){if(this.options.smallImage==='reject'&&(this.preImage.width*this.options.maxZoom=this.previewSize.w){ret.x=Math.min(0,Math.max(ret.x,this.previewSize.w-this.imageSize.w*this.zoom));}else{ret.x=Math.max(0,Math.min(ret.x,this.previewSize.w-this.imageSize.w*this.zoom));}if(this.imageSize.h*this.zoom>=this.previewSize.h){ret.y=Math.min(0,Math.max(ret.y,this.previewSize.h-this.imageSize.h*this.zoom));}else{ret.y=Math.max(0,Math.min(ret.y,this.previewSize.h-this.imageSize.h*this.zoom));}}ret.x=(0,_utils.round)(ret.x);ret.y=(0,_utils.round)(ret.y);return ret;}},{key:'centerImage',value:function centerImage(){if(!this.imageSize||!this.zoom){return;}this.setOffset({x:(this.previewSize.w-this.imageSize.w*this.zoom)/2,y:(this.previewSize.h-this.imageSize.h*this.zoom)/2});}},{key:'onZoomSliderChange',value:function onZoomSliderChange(){if(!this.imageLoaded){return;}this.zoomSliderPos=Number(this.$zoomSlider.val());var newZoom=this.zoomer.getZoom(this.zoomSliderPos);if(newZoom===this.zoom){return;}this.setZoom(newZoom);}},{key:'enableZoomSlider',value:function enableZoomSlider(){this.$zoomSlider.removeAttr('disabled');this.options.onZoomEnabled();}},{key:'disableZoomSlider',value:function disableZoomSlider(){this.$zoomSlider.attr('disabled',true);this.options.onZoomDisabled();}},{key:'setupZoomer',value:function setupZoomer(zoom){this.zoomer.setup({imageSize:this.imageSize,previewSize:this.previewSize,exportZoom:this.options.exportZoom,maxZoom:this.options.maxZoom,minZoom:this.options.minZoom,smallImage:this.options.smallImage});this.setZoom((0,_utils.exists)(zoom)?zoom:this.zoom);if(this.isZoomable()){this.enableZoomSlider();}else{this.disableZoomSlider();}}},{key:'setZoom',value:function setZoom(newZoom){newZoom=this.fixZoom(newZoom);var updatedWidth=(0,_utils.round)(this.imageSize.w*newZoom);var updatedHeight=(0,_utils.round)(this.imageSize.h*newZoom);if(this.imageLoaded){var oldZoom=this.zoom;var newX=this.previewSize.w/2-(this.previewSize.w/2-this.offset.x)*newZoom/oldZoom;var newY=this.previewSize.h/2-(this.previewSize.h/2-this.offset.y)*newZoom/oldZoom;this.zoom=newZoom;this.setOffset({x:newX,y:newY});}else{this.zoom=newZoom;}this.zoomSliderPos=this.zoomer.getSliderPos(this.zoom);this.$zoomSlider.val(this.zoomSliderPos);this.$preview.css('background-size',''+updatedWidth+'px '+updatedHeight+'px');if(this.options.imageBackground){this.$imageBg.css({width:updatedWidth,height:updatedHeight});}this.options.onZoomChange(newZoom);}},{key:'fixZoom',value:function fixZoom(zoom){return this.zoomer.fixZoom(zoom);}},{key:'isZoomable',value:function isZoomable(){return this.zoomer.isZoomable();}},{key:'getCroppedImageData',value:function getCroppedImageData(exportOptions){if(!this.imageSrc){return;}var exportDefaults={type:'image/png',quality:0.75,originalSize:false,fillBg:'#fff'};exportOptions=_jquery2['default'].extend({},exportDefaults,exportOptions);var exportZoom=exportOptions.originalSize?1/this.zoom:this.options.exportZoom;var zoomedSize={w:this.zoom*exportZoom*this.imageSize.w,h:this.zoom*exportZoom*this.imageSize.h};var canvas=(0,_jquery2['default'])('').attr({width:this.previewSize.w*exportZoom,height:this.previewSize.h*exportZoom}).get(0);var canvasContext=canvas.getContext('2d');if(exportOptions.type==='image/jpeg'){canvasContext.fillStyle=exportOptions.fillBg;canvasContext.fillRect(0,0,canvas.width,canvas.height);}canvasContext.drawImage(this.image,this.offset.x*exportZoom,this.offset.y*exportZoom,zoomedSize.w,zoomedSize.h);return canvas.toDataURL(exportOptions.type,exportOptions.quality);}},{key:'getImageState',value:function getImageState(){return{src:this.imageSrc,offset:this.offset,zoom:this.zoom};}},{key:'getImageSrc',value:function getImageSrc(){return this.imageSrc;}},{key:'getOffset',value:function getOffset(){return this.offset;}},{key:'getZoom',value:function getZoom(){return this.zoom;}},{key:'getImageSize',value:function getImageSize(){if(!this.imageSize){return null;}return{width:this.imageSize.w,height:this.imageSize.h};}},{key:'getInitialZoom',value:function getInitialZoom(){return this.options.initialZoom;}},{key:'setInitialZoom',value:function setInitialZoom(initialZoomOption){this.options.initialZoom=initialZoomOption;if(initialZoomOption==='min'){this.initialZoom=0;}else if(initialZoomOption==='image'){this.initialZoom=1;}else{this.initialZoom=0;}}},{key:'getExportZoom',value:function getExportZoom(){return this.options.exportZoom;}},{key:'setExportZoom',value:function setExportZoom(exportZoom){this.options.exportZoom=exportZoom;this.setupZoomer();}},{key:'getMinZoom',value:function getMinZoom(){return this.options.minZoom;}},{key:'setMinZoom',value:function setMinZoom(minZoom){this.options.minZoom=minZoom;this.setupZoomer();}},{key:'getMaxZoom',value:function getMaxZoom(){return this.options.maxZoom;}},{key:'setMaxZoom',value:function setMaxZoom(maxZoom){this.options.maxZoom=maxZoom;this.setupZoomer();}},{key:'getPreviewSize',value:function getPreviewSize(){return{width:this.previewSize.w,height:this.previewSize.h};}},{key:'setPreviewSize',value:function setPreviewSize(size){if(!size||size.width<=0||size.height<=0){return;}this.previewSize={w:size.width,h:size.height};this.$preview.css({width:this.previewSize.w,height:this.previewSize.h});if(this.options.imageBackground){this.$imageBgContainer.css({width:this.previewSize.w+this.imageBgBorderWidthArray[1]+this.imageBgBorderWidthArray[3],height:this.previewSize.h+this.imageBgBorderWidthArray[0]+this.imageBgBorderWidthArray[2]});}if(this.imageLoaded){this.setupZoomer();}}},{key:'disable',value:function disable(){this.unbindListeners();this.disableZoomSlider();this.$el.addClass(_constants.CLASS_NAMES.DISABLED);}},{key:'reenable',value:function reenable(){this.bindListeners();this.enableZoomSlider();this.$el.removeClass(_constants.CLASS_NAMES.DISABLED);}},{key:'$',value:function $(selector){if(!this.$el){return null;}return this.$el.find(selector);}}]);return Cropit;})();exports['default']=Cropit;module.exports=exports['default'];},function(module,exports){Object.defineProperty(exports,'__esModule',{value:true});var _createClass=(function(){function defineProperties(target,props){for(var i=0;i