-
Notifications
You must be signed in to change notification settings - Fork 26
/
ijaboCropTool.min.js
7 lines (7 loc) · 47.9 KB
/
ijaboCropTool.min.js
1
2
3
4
5
6
7
/**
* ijaboCropTool : Jquery Plugin
* By [ Callixte MB. DUSENGE a.k.a Duson ]
* File : ijaboCropTool.min.js
* 03-02-2021
*/
function _versTask(t,i){return t+i+0+1}var _html="<div class='dreat'><span>No Found!</span></div>",swipe_gallery=function(t){this.$el=void 0!==t?t:$(document),this.link_class="swipe_gallery",this.numbers_class="swipe-gallery-count",this.list=[],this.index=0,this.category="",this.popup=null,this.overlay=null,this.vertical_treshold=.99,this.horizontal_treshold=.8,this.working=!1,this.pic_scroll=null,this.overlay_template='<div class="gray-overlay"></div>',this.template='<div class="gallery-popup"> <div class="gallery-next"></div> <div class="gallery-prev"></div> <div class="gallery-close-big"></div> <div class="gallery-images-outer-wrap"> <div class="gallery-images-wrap"> </div> </div> </div>',this.loader_template='<div class="gallery-loader-wrap"> <div class="gallery-loader"> <div class="bar1"></div> <div class="bar2"></div> <div class="bar3"></div> <div class="bar4"></div> <div class="bar5"></div> <div class="bar6"></div> <div class="bar7"></div> <div class="bar8"></div> </div> </div>'};swipe_gallery.prototype={init:function(){this.get_lists(),this.set_links(),this.set_numbers(),this.pic_scroll=new scroller},isTouchDevice:function(){return $.support.touch},isAndroid:function(){return navigator.userAgent.toLowerCase().indexOf("android")>-1},format_template:function(t,i){var e=t;for(var a in i){var n=new RegExp("{"+a+"}","gi");e=e.replace(n,i[a])}return e},show:function(t,i){this.isAndroid()&&$(document).scrollTop(0).bind("scroll.gallery",function(){$(document).scrollTop()>0&&$(document).scrollTop(0)});if(this.isset(this.list[i])){this.index=this.get_index(t,i),this.category=i;var e=$(this.overlay_template);e.css("opacity",0),$("body").prepend(e),e.fadeTo("normal",.9),this.overlay=e;var a=$(this.format_template(this.template,{title:this.list[i][this.index].title}));$(document).bind("keydown.gallery",$.proxy(function(t){switch(t.which){case 39:this.next();break;case 37:this.prev();break;case 27:this.close()}},this)),$(document).bind("mousewheel",$.proxy(function(t,i){switch(i>0?"Up":"Down"){case"Down":this.next();break;case"Up":this.prev()}return!1},this)),this.pic_scroll.tap=$.proxy(this.handleTap,this),this.pic_scroll.tap_treshold=.01,this.pic_scroll.scrollable_element=a.find(".gallery-images-wrap"),this.pic_scroll.scroller_elemets=a,this.pic_scroll.fixed_stop_width=$(window).width(),this.pic_scroll.max_stops=this.list[i].length-1,this.pic_scroll.bind_events(),this.pic_scroll.center_to_index(this.index),this.pic_scroll.after_stop=$.proxy(function(t){this.index=t,$.proxy(this.show_hide_btns,this)()},this),a.css("opacity",0),$("body").prepend(a),a.fadeTo("normal",1),this.popup=a,this.set_top(),this.loading_show(),this.show_hide_btns(),this.make_all_img_element(this.index,i,function(){})}},handleTap:function(t){var i=$(t);i.hasClass("gallery-next")?this.next():i.hasClass("gallery-prev")?this.prev():i.hasClass("gallery-close-big")&&this.close()},make_all_img_element:function(t,i,e){var a=this.popup.find(".gallery-images-wrap"),n=this.list[i].length-1,o=$('<div class="gallery-image-wrap-box"> <div class="gallery-image-wrap"> <div class="gallery-image">'+this.loader_template+'</div> <div class="gallery-image-bottom"> <div class="gallery-count"></div> <div class="gallery-image-title"></div> </div> </div> </div>').width($(window).width()).css({"min-height":"10px"}),r=o.clone();if(r.find(".gallery-image-title").html(this.list[i][t].title),r.find(".gallery-count").html(t+1+"/"+(n+1)),a.width((n+1)*$(window).width()).html(r),this.preload_image(this.list[i][t].src,$.proxy(function(t){r.find(".gallery-loader-wrap").remove(),r.find(".gallery-image").append(t);var i=this.get_image_size(t);$(t).height(i.height),$(t).width(i.width),$(t).show(),r.find(".gallery-image-wrap").width(i.width),this.set_top(t)},this)),t<n)for(var s=t+1;s<=n;s++)$.proxy(function(t){var e=o.clone();e.find(".gallery-image-title").html(this.list[i][t].title),e.find(".gallery-count").html(t+1+"/"+(n+1)),a.append(e),this.preload_image(this.list[i][t].src,$.proxy(function(t){e.find(".gallery-loader-wrap").remove(),e.find(".gallery-image").append(t);var i=this.get_image_size(t);t.height(i.height),t.width(i.width),t.show(),e.find(".gallery-image-wrap").width(i.width),this.set_top(t)},this))},this)(s);if(t>0)for(var h=t-1;h>=0;h--)$.proxy(function(t){var e=o.clone();e.find(".gallery-image-title").html(this.list[i][t].title),e.find(".gallery-count").html(t+1+"/"+(n+1)),a.prepend(e),this.preload_image(this.list[i][t].src,$.proxy(function(t){e.find(".gallery-loader-wrap").remove(),e.find(".gallery-image").append(t);var i=this.get_image_size(t);t.height(i.height),t.width(i.width),t.show(),e.find(".gallery-image-wrap").width(i.width),this.set_top(t)},this))},this)(h);e()},close:function(){this.popup.remove(),this.overlay.remove(),this.popup=null,this.overlay=null,this.pic_scroll.after_stop=function(){},$(document).unbind("keydown.gallery"),$(document).unbind("mousewheel"),$(document).unbind("scroll.gallery")},show_hide_btns:function(){var t=this.list[this.category].length-1;this.index>=t?this.popup.find(".gallery-next").hide():this.popup.find(".gallery-next").show(),this.index<=0?this.popup.find(".gallery-prev").hide():this.popup.find(".gallery-prev").show()},next:function(){this.index+1<this.list[this.category].length&&(this.index++,this.pic_scroll.next(),$.proxy(this.show_hide_btns,this)())},prev:function(){this.index-1>=0&&(this.index--,this.pic_scroll.previous(),$.proxy(this.show_hide_btns,this)())},get_image_size:function(t){var i=t.outerHeight(),e=t.outerWidth(),a=e/i,n=$(window).height(),o=$(window).width(),r=$(t).parents(".gallery-image-wrap").eq(0).find(".gallery-image-bottom").outerHeight();return r>.5*n&&(r=.5*n),n*this.vertical_treshold<i+r&&(e=(i=n*this.vertical_treshold-r)*a),o*this.horizontal_treshold<e&&(i=(e=o*this.horizontal_treshold)/a),e<0&&(e=0),i<0&&(i=0),{width:e,height:i}},preload_image:function(t,i){$("<img />").load(function(){i($(this))}).attr("src",t)},set_top:function(t){var i=$(t).parents(".gallery-image-wrap").eq(0),e=i.find(".gallery-image-bottom").outerHeight(),a=e>.5*$(window).height()?.5*$(window).height():e,n=i.find(".gallery-image").outerHeight()+a,o=$(window).height()/2-n/2;o<0&&(o=0),i.css({"margin-top":o+"px"})},set_img_box_width:function(){this.popup.find(".gallery-image-wrap-box").width($(window).width()),this.popup.find(".gallery-images-wrap").width($(window).width()*this.list[this.category].length),this.pic_scroll.fixed_stop_width=$(window).width(),this.pic_scroll.center_to_index()},get_index:function(t,i){var e=0;if(this.isset(this.list[i])){var a=this.list[i];for(var n in a)a[n].src==t&&(e=n)}return parseInt(e,10)},isset:function(t){return void 0!==t},set_links:function(){var t=this;$("."+this.link_class,this.$el).click(function(i){i.preventDefault(),t.show($(this).attr("href"),$(this).attr("data-category"))})},set_numbers:function(){var t=this;$("."+this.numbers_class,this.$el).each(function(){var i=$(this).attr("data-src"),e=$(this).attr("data-category"),a=t.list[e].length,n=t.get_index(i,e)+1;$(this).html(n+"/"+a)})},get_lists:function(){var t=this;$("."+this.link_class,this.$el).each(function(){var i=$(this).attr("href"),e=$(this).attr("data-title"),a=$(this).attr("data-category");t.isset(t.list[a])||(t.list[a]=[]),t.list[a].push({src:i,title:e})})},loading_show:function(){var t=$(this.loader_template);this.popup.find(".gallery-image").prepend(t)},loading_hide:function(){this.popup.find(".gallery-loader-wrap").remove()},resize:function(){if($(".gallery-popup").length>0){var t=this.popup.find(".gallery-image img"),i=this;t.css({visibility:"hidden",width:"auto",height:"auto"}),t.each(function(){var t=i.get_image_size($(this));$(this).css({width:t.width+"px",height:t.height+"px",visibility:"visible"}),$(this).parents(".gallery-image-wrap").eq(0).width(t.width),i.set_top($(this)),i.set_img_box_width()})}}},function(t,i){"object"==typeof exports&&"undefined"!=typeof module?module.exports=i():"function"==typeof define&&define.amd?define(i):(t=t||self).ijaboCropper=i()}(this,function(){"use strict";function t(i){return(t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(i)}function i(t,i){for(var e=0;e<i.length;e++){var a=i[e];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(t,a.key,a)}}function e(t,i){var e=Object.keys(t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(t);i&&(a=a.filter(function(i){return Object.getOwnPropertyDescriptor(t,i).enumerable})),e.push.apply(e,a)}return e}function a(t){for(var i=1;i<arguments.length;i++){var a=null!=arguments[i]?arguments[i]:{};i%2?e(a,!0).forEach(function(i){var e,n,o;e=t,o=a[n=i],n in e?Object.defineProperty(e,n,{value:o,enumerable:!0,configurable:!0,writable:!0}):e[n]=o}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(a)):e(a).forEach(function(i){Object.defineProperty(t,i,Object.getOwnPropertyDescriptor(a,i))})}return t}function n(t){return function(t){if(Array.isArray(t)){for(var i=0,e=new Array(t.length);i<t.length;i++)e[i]=t[i];return e}}(t)||function(t){if(Symbol.iterator in Object(t)||"[object Arguments]"===Object.prototype.toString.call(t))return Array.from(t)}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance")}()}var o="undefined"!=typeof window&&void 0!==window.document,r=o?window:{},s=o&&"ontouchstart"in r.document.documentElement,h=o&&"PointerEvent"in r,l="cropper",c="all",d="crop",p="move",u="zoom",g="e",m="w",f="s",v="n",w="ne",y="nw",b="se",x="sw",C="".concat(l,"-crop"),M="".concat(l,"-disabled"),D="".concat(l,"-hidden"),_="".concat(l,"-hide"),k="".concat(l,"-invisible"),B="".concat(l,"-modal"),T="".concat(l,"-move"),$="".concat(l,"Action"),E="".concat(l,"Preview"),O="crop",j="move",N="none",W="crop",H="cropend",z="cropmove",L="cropstart",R="dblclick",Y=h?"pointerdown":s?"touchstart":"mousedown",A=h?"pointermove":s?"touchmove":"mousemove",X=h?"pointerup pointercancel":s?"touchend touchcancel":"mouseup",S="ready",I="zoom",P="image/jpeg",U=/^e|w|s|n|se|sw|ne|nw|all|crop|move|zoom$/,q=/^data:/,F=/^data:image\/jpeg;base64,/,Q=/^img|canvas$/i,K={viewMode:0,dragMode:O,initialAspectRatio:NaN,aspectRatio:NaN,data:null,preview:"",responsive:!0,restore:!0,checkCrossOrigin:!0,checkOrientation:!0,modal:!0,guides:!0,center:!0,highlight:!0,background:!0,autoCrop:!0,autoCropArea:.8,movable:!0,rotatable:!0,scalable:!0,zoomable:!0,zoomOnTouch:!0,zoomOnWheel:!0,wheelZoomRatio:.1,cropBoxMovable:!0,cropBoxResizable:!0,toggleDragModeOnDblclick:!0,minCanvasWidth:0,minCanvasHeight:0,minCropBoxWidth:0,minCropBoxHeight:0,minContainerWidth:200,minContainerHeight:100,ready:null,cropstart:null,cropmove:null,cropend:null,crop:null,zoom:null},Z=Number.isNaN||r.isNaN;function G(t){return"number"==typeof t&&!Z(t)}var V=function(t){return 0<t&&t<1/0};function J(t){return void 0===t}function tt(i){return"object"===t(i)&&null!==i}var it=Object.prototype.hasOwnProperty;function et(t){if(!tt(t))return!1;try{var i=t.constructor,e=i.prototype;return i&&e&&it.call(e,"isPrototypeOf")}catch(t){return!1}}function at(t){return"function"==typeof t}var nt=Array.prototype.slice;function ot(t){return Array.from?Array.from(t):nt.call(t)}function rt(t,i){return t&&at(i)&&(Array.isArray(t)||G(t.length)?ot(t).forEach(function(e,a){i.call(t,e,a,t)}):tt(t)&&Object.keys(t).forEach(function(e){i.call(t,t[e],e,t)})),t}var st=Object.assign||function(t){for(var i=arguments.length,e=new Array(1<i?i-1:0),a=1;a<i;a++)e[a-1]=arguments[a];return tt(t)&&0<e.length&&e.forEach(function(i){tt(i)&&Object.keys(i).forEach(function(e){t[e]=i[e]})}),t},ht=/\.\d*(?:0|9){12}\d*$/;function lt(t,i){var e=1<arguments.length&&void 0!==i?i:1e11;return ht.test(t)?Math.round(t*e)/e:t}var ct=/^width|height|left|top|marginLeft|marginTop$/;function dt(t,i){var e=t.style;rt(i,function(t,i){ct.test(i)&&G(t)&&(t="".concat(t,"px")),e[i]=t})}function pt(t,i){if(i)if(G(t.length))rt(t,function(t){pt(t,i)});else if(t.classList)t.classList.add(i);else{var e=t.className.trim();e?e.indexOf(i)<0&&(t.className="".concat(e," ").concat(i)):t.className=i}}function ut(t,i){i&&(G(t.length)?rt(t,function(t){ut(t,i)}):t.classList?t.classList.remove(i):0<=t.className.indexOf(i)&&(t.className=t.className.replace(i,"")))}function gt(t,i,e){i&&(G(t.length)?rt(t,function(t){gt(t,i,e)}):e?pt(t,i):ut(t,i))}var mt=/([a-z\d])([A-Z])/g;function ft(t){return t.replace(mt,"$1-$2").toLowerCase()}function vt(t,i){return tt(t[i])?t[i]:t.dataset?t.dataset[i]:t.getAttribute("data-".concat(ft(i)))}function wt(t,i,e){tt(e)?t[i]=e:t.dataset?t.dataset[i]=e:t.setAttribute("data-".concat(ft(i)),e)}var yt=/\s\s*/,bt=function(){var t=!1;if(o){var i=!1,e=function(){},a=Object.defineProperty({},"once",{get:function(){return t=!0,i},set:function(t){i=t}});r.addEventListener("test",e,a),r.removeEventListener("test",e,a)}return t}();function xt(t,i,e,a){var n=3<arguments.length&&void 0!==a?a:{},o=e;i.trim().split(yt).forEach(function(i){if(!bt){var a=t.listeners;a&&a[i]&&a[i][e]&&(o=a[i][e],delete a[i][e],0===Object.keys(a[i]).length&&delete a[i],0===Object.keys(a).length&&delete t.listeners)}t.removeEventListener(i,o,n)})}function Ct(t,i,e,a){var n=3<arguments.length&&void 0!==a?a:{},o=e;i.trim().split(yt).forEach(function(i){if(n.once&&!bt){var a=t.listeners,r=void 0===a?{}:a;o=function(){delete r[i][e],t.removeEventListener(i,o,n);for(var a=arguments.length,s=new Array(a),h=0;h<a;h++)s[h]=arguments[h];e.apply(t,s)},r[i]||(r[i]={}),r[i][e]&&t.removeEventListener(i,r[i][e],n),r[i][e]=o,t.listeners=r}t.addEventListener(i,o,n)})}function Mt(t,i,e){var a;return at(Event)&&at(CustomEvent)?a=new CustomEvent(i,{detail:e,bubbles:!0,cancelable:!0}):(a=document.createEvent("CustomEvent")).initCustomEvent(i,!0,!0,e),t.dispatchEvent(a)}function Dt(t){var i=t.getBoundingClientRect();return{left:i.left+(window.pageXOffset-document.documentElement.clientLeft),top:i.top+(window.pageYOffset-document.documentElement.clientTop)}}var _t=r.location,kt=/^(\w+:)\/\/([^:\/?#]*):?(\d*)/i;function Bt(t){var i=t.match(kt);return null!==i&&(i[1]!==_t.protocol||i[2]!==_t.hostname||i[3]!==_t.port)}function Tt(t){var i="timestamp=".concat((new Date).getTime());return t+(-1===t.indexOf("?")?"?":"&")+i}function $t(t){var i=t.rotate,e=t.scaleX,a=t.scaleY,n=t.translateX,o=t.translateY,r=[];G(n)&&0!==n&&r.push("translateX(".concat(n,"px)")),G(o)&&0!==o&&r.push("translateY(".concat(o,"px)")),G(i)&&0!==i&&r.push("rotate(".concat(i,"deg)")),G(e)&&1!==e&&r.push("scaleX(".concat(e,")")),G(a)&&1!==a&&r.push("scaleY(".concat(a,")"));var s=r.length?r.join(" "):"none";return{WebkitTransform:s,msTransform:s,transform:s}}function Et(t,i){var e=t.pageX,n=t.pageY,o={endX:e,endY:n};return i?o:a({startX:e,startY:n},o)}function Ot(t,i){var e=t.aspectRatio,a=t.height,n=t.width,o=1<arguments.length&&void 0!==i?i:"contain",r=V(n),s=V(a);if(r&&s){var h=a*e;"contain"===o&&n<h||"cover"===o&&h<n?a=n/e:n=a*e}else r?a=n/e:s&&(n=a*e);return{width:n,height:a}}var jt=String.fromCharCode,Nt=/^data:.*,/;var Wt={render:function(){this.initContainer(),this.initCanvas(),this.initCropBox(),this.renderCanvas(),this.cropped&&this.renderCropBox()},initContainer:function(){var t=this.element,i=this.options,e=this.container,a=this.cropper;pt(a,D),ut(t,D);var n={width:Math.max(e.offsetWidth,Number(i.minContainerWidth)||200),height:Math.max(e.offsetHeight,Number(i.minContainerHeight)||100)};dt(a,{width:(this.containerData=n).width,height:n.height}),pt(t,D),ut(a,D)},initCanvas:function(){var t=this.containerData,i=this.imageData,e=this.options.viewMode,a=Math.abs(i.rotate)%180==90,n=a?i.naturalHeight:i.naturalWidth,o=a?i.naturalWidth:i.naturalHeight,r=n/o,s=t.width,h=t.height;t.height*r>t.width?3===e?s=t.height*r:h=t.width/r:3===e?h=t.width/r:s=t.height*r;var l={aspectRatio:r,naturalWidth:n,naturalHeight:o,width:s,height:h};l.left=(t.width-s)/2,l.top=(t.height-h)/2,l.oldLeft=l.left,l.oldTop=l.top,this.canvasData=l,this.limited=1===e||2===e,this.limitCanvas(!0,!0),this.initialImageData=st({},i),this.initialCanvasData=st({},l)},limitCanvas:function(t,i){var e=this.options,a=this.containerData,n=this.canvasData,o=this.cropBoxData,r=e.viewMode,s=n.aspectRatio,h=this.cropped&&o;if(t){var l=Number(e.minCanvasWidth)||0,c=Number(e.minCanvasHeight)||0;1<r?(l=Math.max(l,a.width),c=Math.max(c,a.height),3===r&&(l<c*s?l=c*s:c=l/s)):0<r&&(l?l=Math.max(l,h?o.width:0):c?c=Math.max(c,h?o.height:0):h&&((l=o.width)<(c=o.height)*s?l=c*s:c=l/s));var d=Ot({aspectRatio:s,width:l,height:c});l=d.width,c=d.height,n.minWidth=l,n.minHeight=c,n.maxWidth=1/0,n.maxHeight=1/0}if(i)if((h?0:1)<r){var p=a.width-n.width,u=a.height-n.height;n.minLeft=Math.min(0,p),n.minTop=Math.min(0,u),n.maxLeft=Math.max(0,p),n.maxTop=Math.max(0,u),h&&this.limited&&(n.minLeft=Math.min(o.left,o.left+(o.width-n.width)),n.minTop=Math.min(o.top,o.top+(o.height-n.height)),n.maxLeft=o.left,n.maxTop=o.top,2===r&&(n.width>=a.width&&(n.minLeft=Math.min(0,p),n.maxLeft=Math.max(0,p)),n.height>=a.height&&(n.minTop=Math.min(0,u),n.maxTop=Math.max(0,u))))}else n.minLeft=-n.width,n.minTop=-n.height,n.maxLeft=a.width,n.maxTop=a.height},renderCanvas:function(t,i){var e=this.canvasData,a=this.imageData;if(i){var n=function(t){var i=t.width,e=t.height,a=t.degree;if(90==(a=Math.abs(a)%180))return{width:e,height:i};var n=a%90*Math.PI/180,o=Math.sin(n),r=Math.cos(n),s=i*r+e*o,h=i*o+e*r;return 90<a?{width:h,height:s}:{width:s,height:h}}({width:a.naturalWidth*Math.abs(a.scaleX||1),height:a.naturalHeight*Math.abs(a.scaleY||1),degree:a.rotate||0}),o=n.width,r=n.height,s=e.width*(o/e.naturalWidth),h=e.height*(r/e.naturalHeight);e.left-=(s-e.width)/2,e.top-=(h-e.height)/2,e.width=s,e.height=h,e.aspectRatio=o/r,e.naturalWidth=o,e.naturalHeight=r,this.limitCanvas(!0,!1)}(e.width>e.maxWidth||e.width<e.minWidth)&&(e.left=e.oldLeft),(e.height>e.maxHeight||e.height<e.minHeight)&&(e.top=e.oldTop),e.width=Math.min(Math.max(e.width,e.minWidth),e.maxWidth),e.height=Math.min(Math.max(e.height,e.minHeight),e.maxHeight),this.limitCanvas(!1,!0),e.left=Math.min(Math.max(e.left,e.minLeft),e.maxLeft),e.top=Math.min(Math.max(e.top,e.minTop),e.maxTop),e.oldLeft=e.left,e.oldTop=e.top,dt(this.canvas,st({width:e.width,height:e.height},$t({translateX:e.left,translateY:e.top}))),this.renderImage(t),this.cropped&&this.limited&&this.limitCropBox(!0,!0)},renderImage:function(t){var i=this.canvasData,e=this.imageData,a=e.naturalWidth*(i.width/i.naturalWidth),n=e.naturalHeight*(i.height/i.naturalHeight);st(e,{width:a,height:n,left:(i.width-a)/2,top:(i.height-n)/2}),dt(this.image,st({width:e.width,height:e.height},$t(st({translateX:e.left,translateY:e.top},e)))),t&&this.output()},initCropBox:function(){var t=this.options,i=this.canvasData,e=t.aspectRatio||t.initialAspectRatio,a=Number(t.autoCropArea)||.8,n={width:i.width,height:i.height};e&&(i.height*e>i.width?n.height=n.width/e:n.width=n.height*e),this.cropBoxData=n,this.limitCropBox(!0,!0),n.width=Math.min(Math.max(n.width,n.minWidth),n.maxWidth),n.height=Math.min(Math.max(n.height,n.minHeight),n.maxHeight),n.width=Math.max(n.minWidth,n.width*a),n.height=Math.max(n.minHeight,n.height*a),n.left=i.left+(i.width-n.width)/2,n.top=i.top+(i.height-n.height)/2,n.oldLeft=n.left,n.oldTop=n.top,this.initialCropBoxData=st({},n)},limitCropBox:function(t,i){var e=this.options,a=this.containerData,n=this.canvasData,o=this.cropBoxData,r=this.limited,s=e.aspectRatio;if(t){var h=Number(e.minCropBoxWidth)||0,l=Number(e.minCropBoxHeight)||0,c=r?Math.min(a.width,n.width,n.width+n.left,a.width-n.left):a.width,d=r?Math.min(a.height,n.height,n.height+n.top,a.height-n.top):a.height;h=Math.min(h,a.width),l=Math.min(l,a.height),s&&(h&&l?h<l*s?l=h/s:h=l*s:h?l=h/s:l&&(h=l*s),c<d*s?d=c/s:c=d*s),o.minWidth=Math.min(h,c),o.minHeight=Math.min(l,d),o.maxWidth=c,o.maxHeight=d}i&&(r?(o.minLeft=Math.max(0,n.left),o.minTop=Math.max(0,n.top),o.maxLeft=Math.min(a.width,n.left+n.width)-o.width,o.maxTop=Math.min(a.height,n.top+n.height)-o.height):(o.minLeft=0,o.minTop=0,o.maxLeft=a.width-o.width,o.maxTop=a.height-o.height))},renderCropBox:function(){var t=this.options,i=this.containerData,e=this.cropBoxData;(e.width>e.maxWidth||e.width<e.minWidth)&&(e.left=e.oldLeft),(e.height>e.maxHeight||e.height<e.minHeight)&&(e.top=e.oldTop),e.width=Math.min(Math.max(e.width,e.minWidth),e.maxWidth),e.height=Math.min(Math.max(e.height,e.minHeight),e.maxHeight),this.limitCropBox(!1,!0),e.left=Math.min(Math.max(e.left,e.minLeft),e.maxLeft),e.top=Math.min(Math.max(e.top,e.minTop),e.maxTop),e.oldLeft=e.left,e.oldTop=e.top,t.movable&&t.cropBoxMovable&&wt(this.face,$,e.width>=i.width&&e.height>=i.height?p:c),dt(this.cropBox,st({width:e.width,height:e.height},$t({translateX:e.left,translateY:e.top}))),this.cropped&&this.limited&&this.limitCanvas(!0,!0),this.disabled||this.output()},output:function(){this.preview(),Mt(this.element,W,this.getData())}},Ht={initPreview:function(){var t=this.element,i=this.crossOrigin,e=this.options.preview,a=i?this.crossOriginUrl:this.url,n=t.alt||"The image to preview",o=document.createElement("img");if(i&&(o.crossOrigin=i),o.src=a,o.alt=n,this.viewBox.appendChild(o),this.viewBoxImage=o,e){var r=e;"string"==typeof e?r=t.ownerDocument.querySelectorAll(e):e.querySelector&&(r=[e]),rt(this.previews=r,function(t){var e=document.createElement("img");wt(t,E,{width:t.offsetWidth,height:t.offsetHeight,html:t.innerHTML}),i&&(e.crossOrigin=i),e.src=a,e.alt=n,e.style.cssText='display:block;width:100%;height:auto;min-width:0!important;min-height:0!important;max-width:none!important;max-height:none!important;image-orientation:0deg!important;"',t.innerHTML="",t.appendChild(e)})}},resetPreview:function(){rt(this.previews,function(t){var i=vt(t,E);dt(t,{width:i.width,height:i.height}),t.innerHTML=i.html,function(t,i){if(tt(t[i]))try{delete t[i]}catch(e){t[i]=void 0}else if(t.dataset)try{delete t.dataset[i]}catch(e){t.dataset[i]=void 0}else t.removeAttribute("data-".concat(ft(i)))}(t,E)})},preview:function(){var t=this.imageData,i=this.canvasData,e=this.cropBoxData,a=e.width,n=e.height,o=t.width,r=t.height,s=e.left-i.left-t.left,h=e.top-i.top-t.top;this.cropped&&!this.disabled&&(dt(this.viewBoxImage,st({width:o,height:r},$t(st({translateX:-s,translateY:-h},t)))),rt(this.previews,function(i){var e=vt(i,E),l=e.width,c=e.height,d=l,p=c,u=1;a&&(p=n*(u=l/a)),n&&c<p&&(d=a*(u=c/n),p=c),dt(i,{width:d,height:p}),dt(i.getElementsByTagName("img")[0],st({width:o*u,height:r*u},$t(st({translateX:-s*u,translateY:-h*u},t))))}))}},zt={bind:function(){var t=this.element,i=this.options,e=this.cropper;at(i.cropstart)&&Ct(t,L,i.cropstart),at(i.cropmove)&&Ct(t,z,i.cropmove),at(i.cropend)&&Ct(t,H,i.cropend),at(i.crop)&&Ct(t,W,i.crop),at(i.zoom)&&Ct(t,I,i.zoom),Ct(e,Y,this.onCropStart=this.cropStart.bind(this)),i.zoomable&&i.zoomOnWheel&&Ct(e,"wheel",this.onWheel=this.wheel.bind(this),{passive:!1,capture:!0}),i.toggleDragModeOnDblclick&&Ct(e,R,this.onDblclick=this.dblclick.bind(this)),Ct(t.ownerDocument,A,this.onCropMove=this.cropMove.bind(this)),Ct(t.ownerDocument,X,this.onCropEnd=this.cropEnd.bind(this)),i.responsive&&Ct(window,"resize",this.onResize=this.resize.bind(this))},unbind:function(){var t=this.element,i=this.options,e=this.cropper;at(i.cropstart)&&xt(t,L,i.cropstart),at(i.cropmove)&&xt(t,z,i.cropmove),at(i.cropend)&&xt(t,H,i.cropend),at(i.crop)&&xt(t,W,i.crop),at(i.zoom)&&xt(t,I,i.zoom),xt(e,Y,this.onCropStart),i.zoomable&&i.zoomOnWheel&&xt(e,"wheel",this.onWheel,{passive:!1,capture:!0}),i.toggleDragModeOnDblclick&&xt(e,R,this.onDblclick),xt(t.ownerDocument,A,this.onCropMove),xt(t.ownerDocument,X,this.onCropEnd),i.responsive&&xt(window,"resize",this.onResize)}},Lt={resize:function(){var t=this.options,i=this.container,e=this.containerData,a=Number(t.minContainerWidth)||200,n=Number(t.minContainerHeight)||100;if(!(this.disabled||e.width<=a||e.height<=n)){var o,r,s=i.offsetWidth/e.width;1==s&&i.offsetHeight===e.height||(t.restore&&(o=this.getCanvasData(),r=this.getCropBoxData()),this.render(),t.restore&&(this.setCanvasData(rt(o,function(t,i){o[i]=t*s})),this.setCropBoxData(rt(r,function(t,i){r[i]=t*s}))))}},dblclick:function(){var t,i;this.disabled||this.options.dragMode===N||this.setDragMode((t=this.dragBox,i=C,(t.classList?t.classList.contains(i):-1<t.className.indexOf(i))?j:O))},wheel:function(t){var i=this,e=Number(this.options.wheelZoomRatio)||.1,a=1;this.disabled||(t.preventDefault(),this.wheeling||(this.wheeling=!0,setTimeout(function(){i.wheeling=!1},50),t.deltaY?a=0<t.deltaY?1:-1:t.wheelDelta?a=-t.wheelDelta/120:t.detail&&(a=0<t.detail?1:-1),this.zoom(-a*e,t)))},cropStart:function(t){var i=t.buttons,e=t.button;if(!(this.disabled||("mousedown"===t.type||"pointerdown"===t.type&&"mouse"===t.pointerType)&&(G(i)&&1!==i||G(e)&&0!==e||t.ctrlKey))){var a,n=this.options,o=this.pointers;t.changedTouches?rt(t.changedTouches,function(t){o[t.identifier]=Et(t)}):o[t.pointerId||0]=Et(t),a=1<Object.keys(o).length&&n.zoomable&&n.zoomOnTouch?u:vt(t.target,$),U.test(a)&&!1!==Mt(this.element,L,{originalEvent:t,action:a})&&(t.preventDefault(),this.action=a,this.cropping=!1,a===d&&(this.cropping=!0,pt(this.dragBox,B)))}},cropMove:function(t){var i=this.action;if(!this.disabled&&i){var e=this.pointers;t.preventDefault(),!1!==Mt(this.element,z,{originalEvent:t,action:i})&&(t.changedTouches?rt(t.changedTouches,function(t){st(e[t.identifier]||{},Et(t,!0))}):st(e[t.pointerId||0]||{},Et(t,!0)),this.change(t))}},cropEnd:function(t){if(!this.disabled){var i=this.action,e=this.pointers;t.changedTouches?rt(t.changedTouches,function(t){delete e[t.identifier]}):delete e[t.pointerId||0],i&&(t.preventDefault(),Object.keys(e).length||(this.action=""),this.cropping&&(this.cropping=!1,gt(this.dragBox,B,this.cropped&&this.options.modal)),Mt(this.element,H,{originalEvent:t,action:i}))}}},Rt={change:function(t){var i,e=this.options,n=this.canvasData,o=this.containerData,r=this.cropBoxData,s=this.pointers,h=this.action,l=e.aspectRatio,C=r.left,M=r.top,_=r.width,k=r.height,B=C+_,T=M+k,$=0,E=0,O=o.width,j=o.height,N=!0;function W(t){switch(t){case g:B+z.x>O&&(z.x=O-B);break;case m:C+z.x<$&&(z.x=$-C);break;case v:M+z.y<E&&(z.y=E-M);break;case f:T+z.y>j&&(z.y=j-T)}}!l&&t.shiftKey&&(l=_&&k?_/k:1),this.limited&&($=r.minLeft,E=r.minTop,O=$+Math.min(o.width,n.width,n.left+n.width),j=E+Math.min(o.height,n.height,n.top+n.height));var H=s[Object.keys(s)[0]],z={x:H.endX-H.startX,y:H.endY-H.startY};switch(h){case c:C+=z.x,M+=z.y;break;case g:if(0<=z.x&&(O<=B||l&&(M<=E||j<=T))){N=!1;break}W(g),(_+=z.x)<0&&(h=m,C-=_=-_),l&&(k=_/l,M+=(r.height-k)/2);break;case v:if(z.y<=0&&(M<=E||l&&(C<=$||O<=B))){N=!1;break}W(v),k-=z.y,M+=z.y,k<0&&(h=f,M-=k=-k),l&&(_=k*l,C+=(r.width-_)/2);break;case m:if(z.x<=0&&(C<=$||l&&(M<=E||j<=T))){N=!1;break}W(m),_-=z.x,C+=z.x,_<0&&(h=g,C-=_=-_),l&&(k=_/l,M+=(r.height-k)/2);break;case f:if(0<=z.y&&(j<=T||l&&(C<=$||O<=B))){N=!1;break}W(f),(k+=z.y)<0&&(h=v,M-=k=-k),l&&(_=k*l,C+=(r.width-_)/2);break;case w:if(l){if(z.y<=0&&(M<=E||O<=B)){N=!1;break}W(v),k-=z.y,M+=z.y,_=k*l}else W(v),W(g),0<=z.x?B<O?_+=z.x:z.y<=0&&M<=E&&(N=!1):_+=z.x,z.y<=0?E<M&&(k-=z.y,M+=z.y):(k-=z.y,M+=z.y);_<0&&k<0?(h=x,M-=k=-k,C-=_=-_):_<0?(h=y,C-=_=-_):k<0&&(h=b,M-=k=-k);break;case y:if(l){if(z.y<=0&&(M<=E||C<=$)){N=!1;break}W(v),k-=z.y,M+=z.y,_=k*l,C+=r.width-_}else W(v),W(m),z.x<=0?$<C?(_-=z.x,C+=z.x):z.y<=0&&M<=E&&(N=!1):(_-=z.x,C+=z.x),z.y<=0?E<M&&(k-=z.y,M+=z.y):(k-=z.y,M+=z.y);_<0&&k<0?(h=b,M-=k=-k,C-=_=-_):_<0?(h=w,C-=_=-_):k<0&&(h=x,M-=k=-k);break;case x:if(l){if(z.x<=0&&(C<=$||j<=T)){N=!1;break}W(m),_-=z.x,C+=z.x,k=_/l}else W(f),W(m),z.x<=0?$<C?(_-=z.x,C+=z.x):0<=z.y&&j<=T&&(N=!1):(_-=z.x,C+=z.x),0<=z.y?T<j&&(k+=z.y):k+=z.y;_<0&&k<0?(h=w,M-=k=-k,C-=_=-_):_<0?(h=b,C-=_=-_):k<0&&(h=y,M-=k=-k);break;case b:if(l){if(0<=z.x&&(O<=B||j<=T)){N=!1;break}W(g),k=(_+=z.x)/l}else W(f),W(g),0<=z.x?B<O?_+=z.x:0<=z.y&&j<=T&&(N=!1):_+=z.x,0<=z.y?T<j&&(k+=z.y):k+=z.y;_<0&&k<0?(h=y,M-=k=-k,C-=_=-_):_<0?(h=x,C-=_=-_):k<0&&(h=w,M-=k=-k);break;case p:this.move(z.x,z.y),N=!1;break;case u:this.zoom(function(t){var i=a({},t),e=[];return rt(t,function(t,a){delete i[a],rt(i,function(i){var a=Math.abs(t.startX-i.startX),n=Math.abs(t.startY-i.startY),o=Math.abs(t.endX-i.endX),r=Math.abs(t.endY-i.endY),s=Math.sqrt(a*a+n*n),h=(Math.sqrt(o*o+r*r)-s)/s;e.push(h)})}),e.sort(function(t,i){return Math.abs(t)<Math.abs(i)}),e[0]}(s),t),N=!1;break;case d:if(!z.x||!z.y){N=!1;break}i=Dt(this.cropper),C=H.startX-i.left,M=H.startY-i.top,_=r.minWidth,k=r.minHeight,0<z.x?h=0<z.y?b:w:z.x<0&&(C-=_,h=0<z.y?x:y),z.y<0&&(M-=k),this.cropped||(ut(this.cropBox,D),this.cropped=!0,this.limited&&this.limitCropBox(!0,!0))}N&&(r.width=_,r.height=k,r.left=C,r.top=M,this.action=h,this.renderCropBox()),rt(s,function(t){t.startX=t.endX,t.startY=t.endY})}},Yt={crop:function(){return!this.ready||this.cropped||this.disabled||(this.cropped=!0,this.limitCropBox(!0,!0),this.options.modal&&pt(this.dragBox,B),ut(this.cropBox,D),this.setCropBoxData(this.initialCropBoxData)),this},reset:function(){return this.ready&&!this.disabled&&(this.imageData=st({},this.initialImageData),this.canvasData=st({},this.initialCanvasData),this.cropBoxData=st({},this.initialCropBoxData),this.renderCanvas(),this.cropped&&this.renderCropBox()),this},clear:function(){return this.cropped&&!this.disabled&&(st(this.cropBoxData,{left:0,top:0,width:0,height:0}),this.cropped=!1,this.renderCropBox(),this.limitCanvas(!0,!0),this.renderCanvas(),ut(this.dragBox,B),pt(this.cropBox,D)),this},replace:function(t,i){var e=1<arguments.length&&void 0!==i&&i;return!this.disabled&&t&&(this.isImg&&(this.element.src=t),e?(this.url=t,this.image.src=t,this.ready&&(this.viewBoxImage.src=t,rt(this.previews,function(i){i.getElementsByTagName("img")[0].src=t}))):(this.isImg&&(this.replaced=!0),this.options.data=null,this.uncreate(),this.load(t))),this},enable:function(){return this.ready&&this.disabled&&(this.disabled=!1,ut(this.cropper,M)),this},disable:function(){return this.ready&&!this.disabled&&(this.disabled=!0,pt(this.cropper,M)),this},destroy:function(){var t=this.element;return t[l]&&(t[l]=void 0,this.isImg&&this.replaced&&(t.src=this.originalUrl),this.uncreate()),this},move:function(t,i){var e=1<arguments.length&&void 0!==i?i:t,a=this.canvasData,n=a.left,o=a.top;return this.moveTo(J(t)?t:n+Number(t),J(e)?e:o+Number(e))},moveTo:function(t,i){var e=1<arguments.length&&void 0!==i?i:t,a=this.canvasData,n=!1;return t=Number(t),e=Number(e),this.ready&&!this.disabled&&this.options.movable&&(G(t)&&(a.left=t,n=!0),G(e)&&(a.top=e,n=!0),n&&this.renderCanvas(!0)),this},zoom:function(t,i){var e=this.canvasData;return t=(t=Number(t))<0?1/(1-t):1+t,this.zoomTo(e.width*t/e.naturalWidth,null,i)},zoomTo:function(t,i,e){var a=this.options,n=this.canvasData,o=n.width,r=n.height,s=n.naturalWidth,h=n.naturalHeight;if(0<=(t=Number(t))&&this.ready&&!this.disabled&&a.zoomable){var l=s*t,c=h*t;if(!1===Mt(this.element,I,{ratio:t,oldRatio:o/s,originalEvent:e}))return this;if(e){var d=this.pointers,p=Dt(this.cropper),u=d&&Object.keys(d).length?function(t){var i=0,e=0,a=0;return rt(d,function(t){var n=t.startX,o=t.startY;i+=n,e+=o,a+=1}),{pageX:i/=a,pageY:e/=a}}():{pageX:e.pageX,pageY:e.pageY};n.left-=(l-o)*((u.pageX-p.left-n.left)/o),n.top-=(c-r)*((u.pageY-p.top-n.top)/r)}else et(i)&&G(i.x)&&G(i.y)?(n.left-=(l-o)*((i.x-n.left)/o),n.top-=(c-r)*((i.y-n.top)/r)):(n.left-=(l-o)/2,n.top-=(c-r)/2);n.width=l,n.height=c,this.renderCanvas(!0)}return this},rotate:function(t){return this.rotateTo((this.imageData.rotate||0)+Number(t))},rotateTo:function(t){return G(t=Number(t))&&this.ready&&!this.disabled&&this.options.rotatable&&(this.imageData.rotate=t%360,this.renderCanvas(!0,!0)),this},scaleX:function(t){var i=this.imageData.scaleY;return this.scale(t,G(i)?i:1)},scaleY:function(t){var i=this.imageData.scaleX;return this.scale(G(i)?i:1,t)},scale:function(t,i){var e=1<arguments.length&&void 0!==i?i:t,a=this.imageData,n=!1;return t=Number(t),e=Number(e),this.ready&&!this.disabled&&this.options.scalable&&(G(t)&&(a.scaleX=t,n=!0),G(e)&&(a.scaleY=e,n=!0),n&&this.renderCanvas(!0,!0)),this},getData:function(t){var i,e=0<arguments.length&&void 0!==t&&t,a=this.options,n=this.imageData,o=this.canvasData,r=this.cropBoxData;if(this.ready&&this.cropped){i={x:r.left-o.left,y:r.top-o.top,width:r.width,height:r.height};var s=n.width/n.naturalWidth;if(rt(i,function(t,e){i[e]=t/s}),e){var h=Math.round(i.y+i.height),l=Math.round(i.x+i.width);i.x=Math.round(i.x),i.y=Math.round(i.y),i.width=l-i.x,i.height=h-i.y}}else i={x:0,y:0,width:0,height:0};return a.rotatable&&(i.rotate=n.rotate||0),a.scalable&&(i.scaleX=n.scaleX||1,i.scaleY=n.scaleY||1),i},setData:function(t){var i=this.options,e=this.imageData,a=this.canvasData,n={};if(this.ready&&!this.disabled&&et(t)){var o=!1;i.rotatable&&G(t.rotate)&&t.rotate!==e.rotate&&(e.rotate=t.rotate,o=!0),i.scalable&&(G(t.scaleX)&&t.scaleX!==e.scaleX&&(e.scaleX=t.scaleX,o=!0),G(t.scaleY)&&t.scaleY!==e.scaleY&&(e.scaleY=t.scaleY,o=!0)),o&&this.renderCanvas(!0,!0);var r=e.width/e.naturalWidth;G(t.x)&&(n.left=t.x*r+a.left),G(t.y)&&(n.top=t.y*r+a.top),G(t.width)&&(n.width=t.width*r),G(t.height)&&(n.height=t.height*r),this.setCropBoxData(n)}return this},getContainerData:function(){return this.ready?st({},this.containerData):{}},getImageData:function(){return this.sized?st({},this.imageData):{}},getCanvasData:function(){var t=this.canvasData,i={};return this.ready&&rt(["left","top","width","height","naturalWidth","naturalHeight"],function(e){i[e]=t[e]}),i},setCanvasData:function(t){var i=this.canvasData,e=i.aspectRatio;return this.ready&&!this.disabled&&et(t)&&(G(t.left)&&(i.left=t.left),G(t.top)&&(i.top=t.top),G(t.width)?(i.width=t.width,i.height=t.width/e):G(t.height)&&(i.height=t.height,i.width=t.height*e),this.renderCanvas(!0)),this},getCropBoxData:function(){var t,i=this.cropBoxData;return this.ready&&this.cropped&&(t={left:i.left,top:i.top,width:i.width,height:i.height}),t||{}},setCropBoxData:function(t){var i,e,a=this.cropBoxData,n=this.options.aspectRatio;return this.ready&&this.cropped&&!this.disabled&&et(t)&&(G(t.left)&&(a.left=t.left),G(t.top)&&(a.top=t.top),G(t.width)&&t.width!==a.width&&(i=!0,a.width=t.width),G(t.height)&&t.height!==a.height&&(e=!0,a.height=t.height),n&&(i?a.height=a.width/n:e&&(a.width=a.height*n)),this.renderCropBox()),this},getCroppedCanvas:function(t){var i=0<arguments.length&&void 0!==t?t:{};if(!this.ready||!window.HTMLCanvasElement)return null;var e=this.canvasData,a=function(t,i,e,a){var o=i.aspectRatio,r=i.naturalWidth,s=i.naturalHeight,h=i.rotate,l=void 0===h?0:h,c=i.scaleX,d=void 0===c?1:c,p=i.scaleY,u=void 0===p?1:p,g=e.aspectRatio,m=e.naturalWidth,f=e.naturalHeight,v=a.fillColor,w=void 0===v?"transparent":v,y=a.imageSmoothingEnabled,b=void 0===y||y,x=a.imageSmoothingQuality,C=void 0===x?"low":x,M=a.maxWidth,D=void 0===M?1/0:M,_=a.maxHeight,k=void 0===_?1/0:_,B=a.minWidth,T=void 0===B?0:B,$=a.minHeight,E=void 0===$?0:$,O=document.createElement("canvas"),j=O.getContext("2d"),N=Ot({aspectRatio:g,width:D,height:k}),W=Ot({aspectRatio:g,width:T,height:E},"cover"),H=Math.min(N.width,Math.max(W.width,m)),z=Math.min(N.height,Math.max(W.height,f)),L=Ot({aspectRatio:o,width:D,height:k}),R=Ot({aspectRatio:o,width:T,height:E},"cover"),Y=Math.min(L.width,Math.max(R.width,r)),A=Math.min(L.height,Math.max(R.height,s)),X=[-Y/2,-A/2,Y,A];return O.width=lt(H),O.height=lt(z),j.fillStyle=w,j.fillRect(0,0,H,z),j.save(),j.translate(H/2,z/2),j.rotate(l*Math.PI/180),j.scale(d,u),j.imageSmoothingEnabled=b,j.imageSmoothingQuality=C,j.drawImage.apply(j,[t].concat(n(X.map(function(t){return Math.floor(lt(t))})))),j.restore(),O}(this.image,this.imageData,e,i);if(!this.cropped)return a;var o=this.getData(),r=o.x,s=o.y,h=o.width,l=o.height,c=a.width/Math.floor(e.naturalWidth);1!=c&&(r*=c,s*=c,h*=c,l*=c);var d=h/l,p=Ot({aspectRatio:d,width:i.maxWidth||1/0,height:i.maxHeight||1/0}),u=Ot({aspectRatio:d,width:i.minWidth||0,height:i.minHeight||0},"cover"),g=Ot({aspectRatio:d,width:i.width||(1!=c?a.width:h),height:i.height||(1!=c?a.height:l)}),m=g.width,f=g.height;m=Math.min(p.width,Math.max(u.width,m)),f=Math.min(p.height,Math.max(u.height,f));var v=document.createElement("canvas"),w=v.getContext("2d");v.width=lt(m),v.height=lt(f),w.fillStyle=i.fillColor||"transparent",w.fillRect(0,0,m,f);var y=i.imageSmoothingEnabled,b=void 0===y||y,x=i.imageSmoothingQuality;w.imageSmoothingEnabled=b,x&&(w.imageSmoothingQuality=x);var C,M,D,_,k,B,T=a.width,$=a.height,E=r,O=s;E<=-h||T<E?k=D=C=E=0:E<=0?(D=-E,E=0,k=C=Math.min(T,h+E)):E<=T&&(D=0,k=C=Math.min(h,T-E)),C<=0||O<=-l||$<O?B=_=M=O=0:O<=0?(_=-O,O=0,B=M=Math.min($,l+O)):O<=$&&(_=0,B=M=Math.min(l,$-O));var j=[E,O,C,M];if(0<k&&0<B){var N=m/h;j.push(D*N,_*N,k*N,B*N)}return w.drawImage.apply(w,[a].concat(n(j.map(function(t){return Math.floor(lt(t))})))),v},setAspectRatio:function(t){var i=this.options;return this.disabled||J(t)||(i.aspectRatio=Math.max(0,t)||NaN,this.ready&&(this.initCropBox(),this.cropped&&this.renderCropBox())),this},setDragMode:function(t){var i=this.options,e=this.dragBox,a=this.face;if(this.ready&&!this.disabled){var n=t===O,o=i.movable&&t===j;t=n||o?t:N,i.dragMode=t,wt(e,$,t),gt(e,C,n),gt(e,T,o),i.cropBoxMovable||(wt(a,$,t),gt(a,C,n),gt(a,T,o))}return this}},At=r.ijaboCropper,Xt=function(){function t(i){var e=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{};if(function(i,e){if(!(i instanceof t))throw new TypeError("Cannot call a class as a function")}(this),!i||!Q.test(i.tagName))throw new Error("The first argument is required and must be an <img> or <canvas> element.");this.element=i,this.options=st({},K,et(e)&&e),this.cropped=!1,this.disabled=!1,this.pointers={},this.ready=!1,this.reloading=!1,this.replaced=!1,this.sized=!1,this.sizing=!1,this.init()}return function(t,e,a){e&&i(t.prototype,e),a&&i(t,a)}(t,[{key:"init",value:function(){var t,i=this.element,e=i.tagName.toLowerCase();if(!i[l]){if(i[l]=this,"img"===e){if(this.isImg=!0,t=i.getAttribute("src")||"",!(this.originalUrl=t))return;t=i.src}else"canvas"===e&&window.HTMLCanvasElement&&(t=i.toDataURL());this.load(t)}}},{key:"load",value:function(t){var i=this;if(t){this.url=t,this.imageData={};var e=this.element,a=this.options;if(a.rotatable||a.scalable||(a.checkOrientation=!1),a.checkOrientation&&window.ArrayBuffer)if(q.test(t))F.test(t)?this.read(function(t){var i=t.replace(Nt,""),e=atob(i),a=new ArrayBuffer(e.length),n=new Uint8Array(a);return rt(n,function(t,i){n[i]=e.charCodeAt(i)}),a}(t)):this.clone();else{var n=new XMLHttpRequest,o=this.clone.bind(this);this.reloading=!0,(this.xhr=n).onabort=o,n.onerror=o,n.ontimeout=o,n.onprogress=function(){n.getResponseHeader("content-type")!==P&&n.abort()},n.onload=function(){i.read(n.response)},n.onloadend=function(){i.reloading=!1,i.xhr=null},a.checkCrossOrigin&&Bt(t)&&e.crossOrigin&&(t=Tt(t)),n.open("GET",t),n.responseType="arraybuffer",n.withCredentials="use-credentials"===e.crossOrigin,n.send()}else this.clone()}}},{key:"read",value:function(t){var i=this.options,e=this.imageData,a=function(t){var i,e=new DataView(t);try{var a,n,o;if(255===e.getUint8(0)&&216===e.getUint8(1))for(var r=e.byteLength,s=2;s+1<r;){if(255===e.getUint8(s)&&225===e.getUint8(s+1)){n=s;break}s+=1}if(n){var h=n+10;if("Exif"===function(t,i,e){var a="";e+=i;for(var n=i;n<e;n+=1)a+=jt(t.getUint8(n));return a}(e,n+4,4)){var l=e.getUint16(h);if(((a=18761===l)||19789===l)&&42===e.getUint16(h+2,a)){var c=e.getUint32(h+4,a);8<=c&&(o=h+c)}}}if(o){var d,p,u=e.getUint16(o,a);for(p=0;p<u;p+=1)if(d=o+12*p+2,274===e.getUint16(d,a)){d+=8,i=e.getUint16(d,a),e.setUint16(d,1,a);break}}}catch(t){i=1}return i}(t),n=0,o=1,r=1;if(1<a){this.url=function(t,i){for(var e=[],a=new Uint8Array(t);0<a.length;)e.push(jt.apply(null,ot(a.subarray(0,8192)))),a=a.subarray(8192);return"data:".concat("image/jpeg",";base64,").concat(btoa(e.join("")))}(t);var s=function(t){var i=0,e=1,a=1;switch(t){case 2:e=-1;break;case 3:i=-180;break;case 4:a=-1;break;case 5:i=90,a=-1;break;case 6:i=90;break;case 7:i=90,e=-1;break;case 8:i=-90}return{rotate:i,scaleX:e,scaleY:a}}(a);n=s.rotate,o=s.scaleX,r=s.scaleY}i.rotatable&&(e.rotate=n),i.scalable&&(e.scaleX=o,e.scaleY=r),this.clone()}},{key:"clone",value:function(){var t=this.element,i=this.url,e=t.crossOrigin,a=i;this.options.checkCrossOrigin&&Bt(i)&&(e=e||"anonymous",a=Tt(i)),this.crossOrigin=e,this.crossOriginUrl=a;var n=document.createElement("img");e&&(n.crossOrigin=e),n.src=a||i,n.alt=t.alt||"The image to crop",(this.image=n).onload=this.start.bind(this),n.onerror=this.stop.bind(this),pt(n,_),t.parentNode.insertBefore(n,t.nextSibling)}},{key:"start",value:function(){var t=this,i=this.image;function e(i,e){st(t.imageData,{naturalWidth:i,naturalHeight:e,aspectRatio:i/e}),t.sizing=!1,t.sized=!0,t.build()}i.onload=null,i.onerror=null,this.sizing=!0;var a=r.navigator&&/(?:iPad|iPhone|iPod).*?AppleWebKit/i.test(r.navigator.userAgent);if(!i.naturalWidth||a){var n=document.createElement("img"),o=document.body||document.documentElement;(this.sizingImage=n).onload=function(){e(n.width,n.height),a||o.removeChild(n)},n.src=i.src,a||(n.style.cssText="left:0;max-height:none!important;max-width:none!important;min-height:0!important;min-width:0!important;opacity:0;position:absolute;top:0;z-index:-1;",o.appendChild(n))}else e(i.naturalWidth,i.naturalHeight)}},{key:"stop",value:function(){var t=this.image;t.onload=null,t.onerror=null,t.parentNode.removeChild(t),this.image=null}},{key:"build",value:function(){if(this.sized&&!this.ready){var t=this.element,i=this.options,e=this.image,a=t.parentNode,n=document.createElement("div");n.innerHTML='<div class="cropper-container" touch-action="none"><div class="cropper-wrap-box"><div class="cropper-canvas"></div></div><div class="cropper-drag-box"></div><div class="cropper-crop-box"><span class="cropper-view-box"></span><span class="cropper-dashed dashed-h"></span><span class="cropper-dashed dashed-v"></span><span class="cropper-center"></span><span class="cropper-face"></span><span class="cropper-line line-e" data-cropper-action="e"></span><span class="cropper-line line-n" data-cropper-action="n"></span><span class="cropper-line line-w" data-cropper-action="w"></span><span class="cropper-line line-s" data-cropper-action="s"></span><span class="cropper-point point-e" data-cropper-action="e"></span><span class="cropper-point point-n" data-cropper-action="n"></span><span class="cropper-point point-w" data-cropper-action="w"></span><span class="cropper-point point-s" data-cropper-action="s"></span><span class="cropper-point point-ne" data-cropper-action="ne"></span><span class="cropper-point point-nw" data-cropper-action="nw"></span><span class="cropper-point point-sw" data-cropper-action="sw"></span><span class="cropper-point point-se" data-cropper-action="se"></span></div></div>';var o=n.querySelector(".".concat(l,"-container")),r=o.querySelector(".".concat(l,"-canvas")),s=o.querySelector(".".concat(l,"-drag-box")),h=o.querySelector(".".concat(l,"-crop-box")),d=h.querySelector(".".concat(l,"-face"));this.container=a,this.cropper=o,this.canvas=r,this.dragBox=s,this.cropBox=h,this.viewBox=o.querySelector(".".concat(l,"-view-box")),this.face=d,r.appendChild(e),pt(t,D),a.insertBefore(o,t.nextSibling),this.isImg||ut(e,_),this.initPreview(),this.bind(),i.initialAspectRatio=Math.max(0,i.initialAspectRatio)||NaN,i.aspectRatio=Math.max(0,i.aspectRatio)||NaN,i.viewMode=Math.max(0,Math.min(3,Math.round(i.viewMode)))||0,pt(h,D),i.guides||pt(h.getElementsByClassName("".concat(l,"-dashed")),D),i.center||pt(h.getElementsByClassName("".concat(l,"-center")),D),i.background&&pt(o,"".concat(l,"-bg")),i.highlight||pt(d,k),i.cropBoxMovable&&(pt(d,T),wt(d,$,c)),i.cropBoxResizable||(pt(h.getElementsByClassName("".concat(l,"-line")),D),pt(h.getElementsByClassName("".concat(l,"-point")),D)),this.render(),this.ready=!0,this.setDragMode(i.dragMode),i.autoCrop&&this.crop(),this.setData(i.data),at(i.ready)&&Ct(t,S,i.ready,{once:!0}),Mt(t,S)}}},{key:"unbuild",value:function(){this.ready&&(this.ready=!1,this.unbind(),this.resetPreview(),this.cropper.parentNode.removeChild(this.cropper),ut(this.element,D))}},{key:"uncreate",value:function(){this.ready?(this.unbuild(),this.ready=!1,this.cropped=!1):this.sizing?(this.sizingImage.onload=null,this.sizing=!1,this.sized=!1):this.reloading?(this.xhr.onabort=null,this.xhr.abort()):this.image&&this.stop()}}],[{key:"noConflict",value:function(){return window.ijaboCropper=At,t}},{key:"setDefaults",value:function(t){st(K,et(t)&&t)}}]),t}();return st(Xt.prototype,Wt,Ht,zt,Lt,Rt,Yt),Xt}),function(t,i,e,a){function n(t,i){return"#"+t.replace(/^#/,"").replace(/../g,t=>("0"+Math.min(255,Math.max(0,parseInt(t,16)+i)).toString(16)).substr(-2))}function o(t){return t=t.replace(/^#/,""),(299*parseInt(t.substr(0,2),16)+587*parseInt(t.substr(2,2),16)+144*parseInt(t.substr(4,2),16))/1e3>=148?"black":"white"}const r=(t,...i)=>"function"==typeof t&&t(...i);t.fn.ijaboCropTool=function(i){const a=i.allowedExtensions||null,s=i.processUrl||null,h=i.withCSRF||null,l=i.preview||null,c=i.fileName||null,d=i.buttonsColor||null,p=i.setRatio||1,u=i.buttonsText||["CROP","CANCEL"];t(this).val(""),t(this).change(function(g){g.preventDefault();const m=t(this)[0].files[0],f=t(this);var v=m.name.toLowerCase(),w=v.substring(v.lastIndexOf(".")+1);if(null==a&&-1==t.inArray(w,["jpg","png","jpeg"]))r(i.onError,"Invalid file type",f),t(f).val("");else if(null!=a&&-1==t.inArray(w,i.allowedExtensions))r(i.onError,"Invalid file type",f),t(f).val("");else{t(e).on("click",".ijabo-cropper-closeBtn",function(i){i.preventDefault(),t(f).val(""),t(".ijabo-cropper-modal").remove()});var y='<div class="ijabo-cropper-modal"><div class="ijabo-cropper-container" style="box-shadow:0 0 2px 0px rgba(100, 100, 100, .4);"><img id="jcropImg" src="" alt=""></div><form class="action-buttons" action="" method="post" id="cropped-image-form"><div class="cropped-image-code" id="cropped-image-code" style="height: 1px;opacity: 0;display: none;"></div><button type="submit" id="ijabo-cropper-cropBtn" class="ijabo-cropper-cropBtn">'+u[0]+'</button><button type="button" class="ijabo-cropper-closeBtn">'+u[1]+"</button></form></div>";if(t("body").append(y),t(".ijabo-cropper-modal").addClass("open"),null!=d){var b=t("button.ijabo-cropper-cropBtn"),x=t("button.ijabo-cropper-closeBtn"),C=d[0],M=d[1],D=d[2];b.css({color:o(C),"background-color":C}).on("hover",function(){t(this).css("background-color",n(C,D))}).on("mouseleave",function(){t(this).css("background-color",C)}),x.css({color:o(M),"background-color":M}).on("hover",function(){t(this).css("background-color",n(M,D))}).on("mouseleave",function(){t(this).css("background-color",M)})}const a=new FileReader;a.onload=function(a){const n=new Image,o=a.target.result;n.src=o,n.onload=function(a){const n=this.height;this.width;t("#jcropImg").attr("src",o);var d=e.querySelector("#jcropImg"),u=(e.getElementById("ijabo-cropper-cropBtn"),new ijaboCropper(d,{aspectRatio:p,viewMode:1}));t(".ijabo-cropper-cropBtn").click(function(a){a.preventDefault();var n=u.getCroppedCanvas().toDataURL();if(null==s)r(i.onError,"You must define process URL",f);else{var o=e.getElementById("cropped-image-form"),d=n.split(";"),p=d[0].split(":")[1],g=function(t,i,e){i=i||"",e=e||512;for(var a=atob(t),n=[],o=0;o<a.length;o+=e){for(var r=a.slice(o,o+e),s=new Array(r.length),h=0;h<r.length;h++)s[h]=r.charCodeAt(h);var l=new Uint8Array(s);n.push(l)}return new Blob(n,{type:i})}(d[1].split(",")[1],p),m=t(f).attr("name"),v=new FormData(o);null!=h&&v.append(h[0],h[1]),v.append("ijaboCropToolFile",1);var w="";""!=m&&null!=m||null!=c?(w=""!=m&&""==m||null==c?m:c,v.append(w,g),t.ajax({url:s,data:v,type:"POST",contentType:!1,processData:!1,cache:!1,dataType:"json",success:function(e){1==e.status&&(t(f).val(""),t(".ijabo-cropper-modal").remove(),null!=l&&t(l).each(function(){t(this).attr("src",n)}),r(i.onSuccess,e.msg,f,1))},error:function(t,e){r(i.onError,"Something went wrong for processing on server side",f,0)}})):r(i.onError,"You must define file name attribute",f)}})}},a.readAsDataURL(m)}})}}($,window,document);