@syncfusion/ej2-image-editor 20.4.48 → 20.4.51

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,11 +1,11 @@
1
1
  /*!
2
2
  * filename: ej2-image-editor.min.js
3
- * version : 20.4.48
3
+ * version : 20.4.51
4
4
  * Copyright Syncfusion Inc. 2001 - 2020. All rights reserved.
5
5
  * Use of this code is subject to the terms of our license.
6
6
  * A copy of the current license can be obtained at any time by e-mailing
7
7
  * licensing@syncfusion.com. Any infringement will be prosecuted under
8
8
  * applicable laws.
9
9
  */
10
- this.ej=this.ej||{},this.ej.imageeditor=function(t,e,i,s,o,a){"use strict";var n=function(){var t=function(e,i){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var i in e)e.hasOwnProperty(i)&&(t[i]=e[i])})(e,i)};return function(e,i){function s(){this.constructor=e}t(e,i),e.prototype=null===i?Object.create(i):(s.prototype=i.prototype,new s)}}(),r=function(t,e,i,s){var o,a=arguments.length,n=a<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(t,e,i,s);else for(var r=t.length-1;r>=0;r--)(o=t[r])&&(n=(a<3?o(n):a>3?o(e,i,n):o(e,i))||n);return a>3&&n&&Object.defineProperty(e,i,n),n},h=function(t){function i(){return null!==t&&t.apply(this,arguments)||this}return n(i,t),r([e.Property(null)],i.prototype,"brightness",void 0),r([e.Property(null)],i.prototype,"contrast",void 0),r([e.Property(null)],i.prototype,"hue",void 0),r([e.Property(null)],i.prototype,"saturation",void 0),r([e.Property(null)],i.prototype,"exposure",void 0),r([e.Property(null)],i.prototype,"opacity",void 0),r([e.Property(null)],i.prototype,"blur",void 0),i}(e.ChildProperty),l=function(t){function l(e,i){var s=t.call(this,e,i)||this;return s.degree=0,s.isUndoRedo=!1,s.dragCanvas=!1,s.dragElement="",s.keyHistory="",s.tempKeyHistory="",s.mouseDownPoint={x:0,y:0},s.previousPoint={x:0,y:0},s.dragPoint={startX:0,startY:0,endX:0,endY:0},s.diffPoint={x:0,y:0},s.oldPoint={},s.objColl=[],s.undoRedoColl=[],s.isImageLoaded=!1,s.strokeSettings={strokeColor:"#fff",fillColor:"",strokeWidth:null},s.tempStrokeSettings={strokeColor:"#fff",fillColor:"",strokeWidth:null},s.textSettings={text:"Enter Text",fontFamily:"Arial",fontSize:null,fontRatio:null,bold:!1,italic:!1,underline:!1},s.tempTextSettings={text:"Enter Text",fontFamily:"Arial",fontSize:null,fontRatio:null,bold:!1,italic:!1,underline:!1},s.toolbarHeight=46,s.togglePan=!1,s.disablePan=!1,s.currFlipState="",s.touchEndPoint={},s.undoRedoStep=0,s.togglePen=!1,s.currentToolbar="main",s.textStartPoints={x:0,y:0},s.fontSizeColl=[],s.textRow=1,s.activeObj={activePoint:{startX:0,startY:0,endX:0,endY:0,width:0,height:0},flipObjColl:[]},s.tempActiveObj={activePoint:{startX:0,startY:0,endX:0,endY:0,width:0,height:0},flipObjColl:[]},s.currObjType={shape:"",isDragging:!1,isActiveObj:!1,isText:!1,isInitialText:!1,isLine:!1,isInitialLine:!1,isCustomCrop:!1,isZoomed:!1,isUndoZoom:!1,isUndoAction:!1,isFiltered:!1,isSave:!1},s.defToolbarItems=[],s.isTimer=!1,s.isFirstMove=!1,s.startTouches=[],s.tempTouches=[],s.adjustmentLevel={brightness:0,contrast:0,hue:0,opacity:100,saturation:0,blur:0,exposure:0,sharpen:!1,bw:!1},s.tempAdjustmentLevel={brightness:0,contrast:0,hue:0,opacity:100,saturation:0,blur:0,exposure:0,sharpen:!1,bw:!1},s.adjustmentValue="",s.initialAdjustmentValue="",s.tempAdjustmentValue="",s.currentFilter="",s.tempFilter="",s.canvasFilter="brightness(1) contrast(100%) hue-rotate(0deg) saturate(100%) opacity(1) blur(0px) sepia(0%) grayscale(0%) invert(0%)",s.tempUndoRedoColl=[],s.tempUndoRedoStep=0,s.zoomFactor=0,s.tempZoomFactor=0,s.destLeft=0,s.destTop=0,s.srcLeft=0,s.srcTop=0,s.cropDestPoints={startX:0,startY:0,width:0,height:0},s.flipColl=[],s.isReverseRotate=!1,s.isReverseFlip=!1,s.isPreventDragging=!1,s.isRotateZoom=!1,s.rotateFlipColl=[],s.isCircleCrop=!1,s.rotatedDestPoints={startX:0,startY:0,width:0,height:0},s.croppedDegree=0,s.isFreehandDrawingPoint=!1,s.isFreehandDrawEditing=!1,s.tempFreeHandDrawEditingStyles={strokeColor:null,fillColor:null,strokeWidth:null},s.totalPannedInternalPoint={x:0,y:0},s.totalPannedClientPoint={x:0,y:0},s.totalPannedPoint={x:0,y:0},s.isCropTab=!1,s.cropZoomFactor=0,s.defaultZoomFactor=0,s.fileName="",s.isBrightnessAdjusted=!1,s.isInitialLoading=!1,s.freehandDrawObj={lastWidth:0,lastVelocity:0,time:0,pointX:0,pointY:0},s.points=[],s.pointColl={},s.pointCounter=0,s.freehandCounter=0,s.isFreehandDrawing=!1,s.tempFreehandCounter=0,s.lastPan={x:0,y:0},s.selectedFreehandColor="#42a5f5",s.isFreehandDrawCustomized=!1,s.isShapeInserted=!1,s.isAllowCropPan=!1,s.tempPannedPoint={x:0,y:0},s.cropObj={cropZoom:0,defaultZoom:0,totalPannedPoint:{x:0,y:0},totalPannedClientPoint:{x:0,y:0},totalPannedInternalPoint:{x:0,y:0},activeObj:{},rotateFlipColl:[],degree:0,currFlipState:"",destPoints:{startX:0,startY:0,width:0,height:0},srcPoints:{startX:0,startY:0,width:0,height:0}},s.afterCropActions=[],s.isCancelAction=!1,s.isFreehandPointMoved=!1,s.isTouch=!1,s.freehandDownPoint={x:0,y:0},s.tempFlipPanPoint={x:0,y:0},s.currentFreehandDrawIndex=0,s.tempCurrentFreehandDrawIndex=0,s.preventZoomBtn=!1,s.cancelObjColl=[],s.cancelPointColl=[],s.rotatedFlipCropSelection=!1,s}n(l,t),c=l,l.prototype.preRender=function(){this.element.id=this.element.id||e.getUniqueID("ej2-image-editor"),e.Browser.isDevice&&this.element.classList.add("e-device"),this.themeColl={Bootstrap5:{primaryColor:"#0d6efd",secondaryColor:"#fff"},Bootstrap5Dark:{primaryColor:"#0d6efd",secondaryColor:"#fff"},Tailwind:{primaryColor:"#4f46e5",secondaryColor:"#fff"},TailwindDark:{primaryColor:"#22d3ee",secondaryColor:"#fff"},Fluent:{primaryColor:"#0078d4",secondaryColor:"#fff"},FluentDark:{primaryColor:"#0078d4",secondaryColor:"#fff"},Bootstrap4:{primaryColor:"#007bff",secondaryColor:"#fff"},Bootstrap:{primaryColor:"#317ab9",secondaryColor:"#fff"},BootstrapDark:{primaryColor:"#317ab9",secondaryColor:"#fff"},Material:{primaryColor:"#e3165b",secondaryColor:"#fff"},MaterialDark:{primaryColor:"#00b0ff",secondaryColor:"#fff"},Fabric:{primaryColor:"#0078d6",secondaryColor:"#fff"},FabricDark:{primaryColor:"#0074cc",secondaryColor:"#fff"},Highcontrast:{primaryColor:"#000000",secondaryColor:"#fff"}},this.defaultLocale={Crop:"Crop",ZoomIn:"Zoom In",ZoomOut:"Zoom Out",Undo:"Undo",Redo:"Redo",Transform:"Transform",Annotation:"Annotation",Finetune:"Finetune",Brightness:"Brightness",Contrast:"Contrast",Hue:"Hue",Saturation:"Saturation",Opacity:"Opacity",Blur:"Blur",Sharpen:"Sharpen",Exposure:"Exposure",Filter:"Filter",Default:"Default",Chrome:"Chrome",Cold:"Cold",Warm:"Warm",Grayscale:"Grayscale",BlackAndWhite:"Black and White",Sepia:"Sepia",Invert:"Invert",Text:"Add Text",Pen:"Pen",Reset:"Reset",Save:"Save",Select:"Select",RotateLeft:"Rotate Left",RotateRight:"Rotate Right",HorizontalFlip:"Horizontal Flip",VerticalFlip:"Vertical Flip",OK:"OK",Cancel:"Cancel",FillColor:"Fill Color",StrokeColor:"Stroke Color",StrokeWidth:"Stroke Width",FontFamily:"Font Family",FontStyle:"Font Style",FontSize:"Font Size",FontColor:"Font Color",Pan:"Pan",Move:"Move",Load:"Load",Custom:"Custom",Square:"Square",Circle:"Circle",Ellipse:"Ellipse",Rectangle:"Rectangle",Line:"Line",Bold:"Bold",Italic:"Italic",BoldItalic:"Bold Italic",XSmall:"X-Small",Small:"Small",Medium:"Medium",Large:"Large",XLarge:"X-Large",ABC:"ABC",Browse:"Browse"},this.l10n=new e.L10n("image-editor",this.defaultLocale,this.locale)},l.prototype.render=function(){this.initialize()},l.prototype.getModuleName=function(){return"image-editor"},l.prototype.getPersistData=function(){return this.addOnPersist([])},l.prototype.onPropertyChanged=function(t,i){for(var s=0,o=Object.keys(t);s<o.length;s++)switch(o[s]){case"cssClass":i.cssClass&&e.removeClass([this.element],i.cssClass.replace(/\s+/g," ").trim().split(" ")),t.cssClass&&e.addClass([this.element],t.cssClass.replace(/\s+/g," ").trim().split(" "));break;case"disabled":t.disabled?(this.element.classList.add("e-disabled"),this.unwireEvent()):(this.element.classList.remove("e-disabled"),this.wireEvent());break;case"height":this.element.style.height=t.height;break;case"width":this.element.style.width=t.width;break;case"theme":t.theme&&(this.updateTheme(),this.upperContext.strokeStyle=this.themeColl[this.theme].primaryColor,this.upperContext.fillStyle=this.themeColl[this.theme].secondaryColor);break;case"finetuneSettings":t.finetuneSettings&&(this.finetuneSettings=t.finetuneSettings,this.updateFinetunes());break;case"locale":t.locale&&(this.l10n.setLocale(t.locale),this.refreshToolbar("main"));break;case"allowUndoRedo":t.allowUndoRedo?this.allowUndoRedo=!0:this.allowUndoRedo=!1,this.refreshToolbar("main")}},l.prototype.destroy=function(){var i=[];this.element.removeAttribute("tabindex"),this.cssClass&&(i=i.concat(this.cssClass.replace(/\s+/g," ").trim().split(" "))),e.removeClass([this.element],i),this.element.getAttribute("class")||this.element.removeAttribute("class"),this.destroySubComponents(),this.unwireEvent(),t.prototype.destroy.call(this),this.element.innerHTML="",this.trigger("destroyed")},l.prototype.initialize=function(){this.updateFinetunes(),this.createToolbar(),this.createContextualToolbar(),this.createCanvas(),this.wireEvent(),this.lowerContext.filter=this.canvasFilter=this.initialAdjustmentValue=this.adjustmentValue=this.getDefaultFilter(),this.cssClass&&e.addClass([this.element],this.cssClass.replace(/\s+/g," ").trim().split(" ")),this.element&&a.createSpinner({target:this.element})},l.prototype.getDefaultFilter=function(){return"brightness(1) contrast(100%) hue-rotate(0deg) saturate(100%) opacity(1) blur(0px) sepia(0%) grayscale(0%) invert(0%)"},l.prototype.updateFinetunes=function(){this.finetuneSettings&&(this.finetuneSettings.brightness&&(this.adjustmentLevel.brightness=this.finetuneSettings.brightness.defaultValue,this.tempAdjustmentLevel.brightness=this.finetuneSettings.brightness.defaultValue),this.finetuneSettings.contrast&&(this.adjustmentLevel.contrast=this.finetuneSettings.contrast.defaultValue,this.tempAdjustmentLevel.contrast=this.finetuneSettings.contrast.defaultValue),this.finetuneSettings.hue&&(this.adjustmentLevel.hue=this.finetuneSettings.hue.defaultValue,this.tempAdjustmentLevel.hue=this.finetuneSettings.hue.defaultValue),this.finetuneSettings.saturation&&(this.adjustmentLevel.saturation=this.finetuneSettings.saturation.defaultValue,this.tempAdjustmentLevel.saturation=this.finetuneSettings.saturation.defaultValue),this.finetuneSettings.exposure&&(this.adjustmentLevel.exposure=this.finetuneSettings.exposure.defaultValue,this.tempAdjustmentLevel.exposure=this.finetuneSettings.exposure.defaultValue),this.finetuneSettings.opacity&&(this.adjustmentLevel.opacity=this.finetuneSettings.opacity.defaultValue,this.tempAdjustmentLevel.opacity=this.finetuneSettings.opacity.defaultValue),this.finetuneSettings.blur&&(this.adjustmentLevel.blur=this.finetuneSettings.blur.defaultValue,this.tempAdjustmentLevel.blur=this.finetuneSettings.blur.defaultValue),this.isInitialLoading=!0)},l.prototype.initializeFilter=function(){this.setBrightness(this.adjustmentLevel.brightness),this.setContrast(this.adjustmentLevel.contrast),this.setHue(this.adjustmentLevel.hue),this.setSaturation(this.adjustmentLevel.saturation),this.setExposure(this.adjustmentLevel.exposure),this.setOpacity(this.adjustmentLevel.opacity),this.setBlur(this.adjustmentLevel.blur)},l.prototype.wireEvent=function(){e.EventHandler.add(document,"keydown",this.keyDownEventHandler,this),e.EventHandler.add(document,"keypress",this.keyUpEventHandler,this),e.EventHandler.add(this.upperCanvas,"mousedown",this.mouseDownEventHandler,this),e.EventHandler.add(this.upperCanvas,"mousemove",this.mouseMoveEventHandler,this),e.EventHandler.add(this.upperCanvas,"mouseup",this.mouseUpEventHandler,this),e.EventHandler.add(document,"mouseup",this.mouseUpEventHandler,this),e.EventHandler.add(this.lowerCanvas,"mousedown",this.canvasMouseDownHandler,this),e.EventHandler.add(this.lowerCanvas,"mousemove",this.canvasMouseMoveHandler,this),e.EventHandler.add(this.lowerCanvas,"mouseup",this.canvasMouseUpHandler,this),e.EventHandler.add(document,"mouseup",this.canvasMouseUpHandler,this),e.EventHandler.add(this.upperCanvas,"touchstart",this.touchStartHandler,this),e.EventHandler.add(this.lowerCanvas,"touchstart",this.touchStartHandler,this),e.EventHandler.add(this.upperCanvas,"dblclick",this.findTextPoint,this),e.EventHandler.add(this.textArea,"mousedown",this.findTextPoint,this),e.EventHandler.add(this.lowerCanvas,"mousewheel DOMMouseScroll",this.handleScroll,this),e.EventHandler.add(this.upperCanvas,"mousewheel DOMMouseScroll",this.handleScroll,this),window.addEventListener("resize",this.windowResizeHandler.bind(this)),e.Browser.isIos||"safari"===e.Browser.info.name||screen.orientation.addEventListener("change",this.screenOrientation.bind(this))},l.prototype.unwireEvent=function(){e.EventHandler.remove(document,"keydown",this.keyDownEventHandler),e.EventHandler.remove(document,"keypress",this.keyUpEventHandler),e.EventHandler.remove(this.upperCanvas,"mousedown",this.mouseDownEventHandler),e.EventHandler.remove(this.upperCanvas,"mousemove",this.mouseMoveEventHandler),e.EventHandler.remove(this.upperCanvas,"mouseup",this.mouseUpEventHandler),e.EventHandler.remove(document,"mouseup",this.mouseUpEventHandler),e.EventHandler.remove(this.lowerCanvas,"mousedown",this.canvasMouseDownHandler),e.EventHandler.remove(this.lowerCanvas,"mousemove",this.canvasMouseMoveHandler),e.EventHandler.remove(this.lowerCanvas,"mouseup",this.canvasMouseUpHandler),e.EventHandler.remove(document,"mouseup",this.canvasMouseUpHandler)},l.prototype.destroySubComponents=function(){for(var t=this.element.querySelectorAll("input.e-control"),i=this.element.querySelectorAll("button.e-control"),s=0,o=t.length;s<o;s++)t[s].classList.contains("e-color-picker")&&(e.getComponent(t[s],"color-picker").destroy(),e.detach(e.select("input#"+t[s].id,this.element)));for(var s=0,o=i.length;s<o;s++)i[s].classList.contains("e-dropdown-btn")?(e.getComponent(i[s],"dropdown-btn").destroy(),e.detach(e.select("button#"+i[s].id,this.element))):i[s].classList.contains("e-btn")&&(e.getComponent(i[s],"btn").destroy(),e.detach(e.select("button#"+i[s].id,this.element)))},l.prototype.updateTheme=function(){""!==this.theme&&(this.theme=this.toPascalCase(this.theme))},l.prototype.toPascalCase=function(t){var i=[];e.isNullOrUndefined(t)||(i=t.toLowerCase().split("-"));for(var s=0;s<i.length;s++)i[s]=i[s].charAt(0).toUpperCase()+i[s].slice(1);return i.join("")},l.prototype.createCanvas=function(){this.element.style.boxSizing="border-box";var t=this.toolbarHeight;this.element.style.width=this.width,this.element.style.height=this.height;var e=this.element.appendChild(this.createElement("div",{id:this.element.id+"_canvasWrapper",className:"e-canvas-wrapper",attrs:{style:"height:"+(this.element.offsetHeight-t-2)+"px; width:"+(this.element.offsetWidth-2)+"px; position: relative; overflow: hidden; margin: 0 auto;"}}));this.lowerCanvas=e.appendChild(this.createElement("canvas",{id:this.element.id+"_lowerCanvas",attrs:{name:"canvasImage"}})),this.upperCanvas=e.appendChild(this.createElement("canvas",{id:this.element.id+"_upperCanvas",attrs:{name:"canvasImage"}})),this.inMemoryCanvas=this.createElement("canvas",{id:this.element.id+"_inMemoryCanvas",attrs:{name:"canvasImage"}}),this.textArea=e.appendChild(this.createElement("textarea",{id:this.element.id+"_textArea",className:"e-textarea",attrs:{name:"textArea"}})),this.textArea.setAttribute("spellcheck","false"),this.lowerCanvas.style.width=this.upperCanvas.style.width=this.inMemoryCanvas.style.width="100%",this.lowerCanvas.style.height=this.upperCanvas.style.height=this.inMemoryCanvas.style.height="100%",this.upperCanvas.style.position=this.lowerCanvas.style.position=this.textArea.style.position="absolute",this.textArea.style.backgroundColor="transparent",this.textArea.style.display="none",this.textArea.style.resize="none",this.lowerContext=this.lowerCanvas.getContext("2d"),this.baseImg=this.createElement("img",{id:this.element.id+"_orgImg",attrs:{name:"Image",crossorigin:"anonymous"}}),this.upperCanvas.style.cursor="default",this.upperCanvas.style.display="none",this.upperContext=this.upperCanvas.getContext("2d"),this.inMemoryContext=this.inMemoryCanvas.getContext("2d")},l.prototype.createToolbar=function(){var t=this;if(e.isNullOrUndefined(this.toolbar)||!e.isNullOrUndefined(this.toolbar)&&this.toolbar.length>0){if(this.element.appendChild(this.createElement("div",{id:this.element.id+"_toolbarArea",className:"e-toolbar-area"})),this.toolbarTemplate)this.toolbarTemplateFn();else{var s={cssClass:"e-image-upload",align:"Left",type:"Input",tooltipText:this.l10n.getConstant("Browse"),template:new o.Uploader({allowedExtensions:".jpg, .jpeg, .png,.svg"})};e.isNullOrUndefined(this.defToolbarItems)&&(this.defToolbarItems=[]),this.defToolbarItems.push(s);var a=document.getElementById(this.element.id+"_toolbarArea"),n=this.createElement("div",{id:this.element.id+"_toolbar"});a.appendChild(n);var r=[{cssClass:"e-image-upload",align:"Left",type:"Input",tooltipText:this.l10n.getConstant("Browse"),template:new o.Uploader({allowedExtensions:".jpg, .jpeg, .png,.svg",selected:function(){e.Browser.isDevice?(t.defToolbarItems.length>0&&!e.isNullOrUndefined(document.getElementById(t.element.id+"_toolbar"))&&e.getComponent(document.getElementById(t.element.id+"_toolbar"),"toolbar").destroy(),e.isNullOrUndefined(document.getElementById(t.element.id+"_bottomToolbar"))||e.getComponent(document.getElementById(t.element.id+"_bottomToolbar"),"toolbar").destroy(),t.initToolbarItem(!1,e.Browser.isDevice,null),t.createBottomToolbar()):(t.defToolbarItems.length>0&&!e.isNullOrUndefined(document.getElementById(t.element.id+"_toolbar"))&&e.getComponent(document.getElementById(t.element.id+"_toolbar"),"toolbar").destroy(),t.initToolbarItem(!1,!1,null))}})}];new i.Toolbar({items:r,width:"100%",created:function(){t.trigger("toolbarCreated",{toolbarType:"main"})},clicked:this.defToolbarClicked.bind(this)},"#"+this.element.id+"_toolbar"),this.createLeftToolbarControls()}e.isNullOrUndefined(document.getElementById(this.element.id+"_toolbar"))||(this.toolbarHeight=document.getElementById(this.element.id+"_toolbar").clientHeight)}else this.toolbarHeight=0},l.prototype.createContextualToolbar=function(){if(e.isNullOrUndefined(this.toolbar)||!e.isNullOrUndefined(this.toolbar)&&this.toolbar.length>0){this.element.appendChild(this.createElement("div",{id:this.element.id+"_contextualToolbarArea",className:"e-contextual-toolbar-wrapper e-hide",attrs:{style:"position: absolute;"}}));var t=document.getElementById(this.element.id+"_contextualToolbarArea"),i=this.createElement("div",{id:this.element.id+"_contextualToolbar"});t.appendChild(i)}},l.prototype.updateContextualToolbar=function(t,i){if(this.toolbarTemplate)this.toolbarTemplateFn();else{var s=this.element.querySelector("#"+this.element.id+"_toolbarArea"),o=this.element.querySelector("#"+this.element.id+"_contextualToolbarArea");if(o.classList.remove("e-hide"),o.style.left=s.offsetLeft+"px","filter"===t?(document.getElementById(this.element.id+"_toolbar")&&this.defToolbarItems.length>0&&e.getComponent(document.getElementById(this.element.id+"_toolbar"),"toolbar").destroy(),e.Browser.isDevice?this.initToolbarItem(!1,!0,!0):this.initToolbarItem(!0,null,null),this.refreshSlider(),this.initFilterToolbarItem()):(document.querySelector("#"+this.element.id+"_contextualToolbar").classList.contains("e-control")&&e.getComponent(document.getElementById(this.element.id+"_contextualToolbar"),"toolbar").destroy(),this.refreshSlider(),this.renderSlider(i)),e.Browser.isDevice){var a=o.offsetHeight,n=this.element.querySelector("#"+this.element.id+"_canvasWrapper").offsetHeight;o.style.top=this.toolbarHeight+n-a+"px"}else o.style.top=this.toolbarHeight+"px"}},l.prototype.createBottomToolbar=function(){if(e.isNullOrUndefined(this.toolbar)||!e.isNullOrUndefined(this.toolbar)&&this.toolbar.length>0){if(this.element.appendChild(this.createElement("div",{id:this.element.id+"_bottomToolbarArea",className:"e-bottom-toolbar"})),!this.toolbarTemplate){document.getElementById(this.element.id+"_canvasWrapper").style.height=this.element.offsetHeight-2*this.toolbarHeight-3+"px";var t=document.getElementById(this.element.id+"_bottomToolbarArea"),i=this.createElement("div",{id:this.element.id+"_bottomToolbar"});t.appendChild(i)}this.initBottomToolbar()}},l.prototype.initBottomToolbar=function(){var t=this;if(e.isNullOrUndefined(this.toolbar)||!e.isNullOrUndefined(this.toolbar)&&this.toolbar.length>0)if(this.toolbarTemplate)this.toolbarTemplateFn();else{var s=this.getMainToolbarItem();new i.Toolbar({items:s,width:"100%",created:function(){t.renderAnnotationBtn(),t.renderCropBtn(),t.renderTransformBtn(),t.trigger("toolbarCreated",{toolbarType:"main"})},clicked:this.defToolbarClicked.bind(this)},"#"+this.element.id+"_bottomToolbar"),this.defToolbarItems.length>0&&!e.isNullOrUndefined(document.getElementById(this.element.id+"_bottomToolbar"))&&e.getComponent(this.element.id+"_bottomToolbar","toolbar").refreshOverflow()}},l.prototype.toolbarTemplateFn=function(){var t,e=this.element.id+"_toolbar",i=this.element.querySelector("#"+this.element.id+"_toolbarArea");if(this.toolbarTemplate){if(this.toolbarFn=this.templateParser(this.toolbarTemplate),this.isReact)t=this.toolbarFn({type:"toolbar"},this,"Template",e)[0];else if(this.isAngular){var s=this.toolbarFn({type:"toolbar"},this,"Template",e);t=3===s[0].nodeType?s[1]:s[0]}else t=this.toolbarFn({type:"toolbar"},this,"Template",e)[0];i.appendChild(t),this.renderReactTemplates()}},l.prototype.templateParser=function(t){if(t)try{return document.querySelectorAll(t).length?e.compile(document.querySelector(t).innerHTML.trim()):e.compile(t)}catch(i){return e.compile(t)}},l.prototype.getLeftToolbarItem=function(t){var i=[];t||(i.push({cssClass:"e-image-upload",align:"Left",type:"Input",template:new o.Uploader({allowedExtensions:".jpg, .jpeg, .png,.svg"})}),i.push({visible:!1,cssClass:"e-image-position e-btn e-flat",tooltipText:this.l10n.getConstant("Browse"),align:"Left"})),this.allowUndoRedo&&((e.isNullOrUndefined(this.toolbar)||!e.isNullOrUndefined(this.toolbar)&&this.toolbar.indexOf("Undo")>-1)&&i.push({id:this.element.id+"_undo",prefixIcon:"e-icons e-undo",cssClass:"top-icon e-undo",tooltipText:this.l10n.getConstant("Undo"),align:"Left"}),(e.isNullOrUndefined(this.toolbar)||!e.isNullOrUndefined(this.toolbar)&&this.toolbar.indexOf("Redo")>-1)&&i.push({id:this.element.id+"_redo",prefixIcon:"e-icons e-redo",cssClass:"top-icon e-redo",tooltipText:this.l10n.getConstant("Redo"),align:"Left"})),this.preventZoomBtn||((e.isNullOrUndefined(this.toolbar)||!e.isNullOrUndefined(this.toolbar)&&this.toolbar.indexOf("ZoomOut")>-1)&&i.push({id:this.element.id+"_zoomOut",prefixIcon:"e-icons e-zoom-out",cssClass:"top-icon e-dec-zoom",tooltipText:this.l10n.getConstant("ZoomOut"),align:"Left"}),(e.isNullOrUndefined(this.toolbar)||!e.isNullOrUndefined(this.toolbar)&&this.toolbar.indexOf("ZoomIn")>-1)&&i.push({id:this.element.id+"_zoomIn",prefixIcon:"e-icons e-zoom-in",cssClass:"top-icon e-inc-zoom",tooltipText:this.l10n.getConstant("ZoomIn"),align:"Left"}));for(var s=this.processToolbar("left"),a=0,n=s.length;a<n;a++)i.push(s[a]);return i},l.prototype.getRightToolbarItem=function(t){var i=[];t&&(i.push({id:this.element.id+"_ok",prefixIcon:"e-icons e-check",cssClass:"top-icon e-tick",tooltipText:this.l10n.getConstant("OK"),align:"Right"}),i.push({id:this.element.id+"_cancel",prefixIcon:"e-icons e-close",cssClass:"top-icon e-save",tooltipText:this.l10n.getConstant("Cancel"),align:"Right"})),(e.isNullOrUndefined(this.toolbar)||!e.isNullOrUndefined(this.toolbar)&&this.toolbar.indexOf("Reset")>-1)&&i.push({id:this.element.id+"_reset",prefixIcon:"e-icons e-btn-reset",cssClass:"top-icon e-img-reset",tooltipText:this.l10n.getConstant("Reset"),align:"Right"}),t||(e.isNullOrUndefined(this.toolbar)||!e.isNullOrUndefined(this.toolbar)&&this.toolbar.indexOf("Save")>-1)&&i.push({id:this.element.id+"_save",prefixIcon:"e-icons e-btn-save",cssClass:"top-icon e-save",tooltipText:this.l10n.getConstant("Save"),align:"Right",template:'<button id="'+this.element.id+'_saveBtn"></button>'});for(var s=this.processToolbar("right"),o=0,a=s.length;o<a;o++)i.push(s[o]);return i},l.prototype.getMainToolbarItem=function(t){var i=[];(e.isNullOrUndefined(this.toolbar)||!e.isNullOrUndefined(this.toolbar)&&this.toolbar.indexOf("Crop")>-1)&&i.push({id:this.element.id+"_crop",tooltipText:this.l10n.getConstant("Crop"),align:"Center",template:'<button id="'+this.element.id+'_cropBtn"></button>'}),(e.isNullOrUndefined(this.toolbar)||!e.isNullOrUndefined(this.toolbar)&&this.toolbar.indexOf("Annotate")>-1)&&i.push({id:this.element.id+"_annotation",tooltipText:this.l10n.getConstant("Annotation"),align:"Center",template:'<button id="'+this.element.id+'_annotationBtn"></button>'}),(e.isNullOrUndefined(this.toolbar)||!e.isNullOrUndefined(this.toolbar)&&this.toolbar.indexOf("Transform")>-1)&&i.push({id:this.element.id+"_transform",tooltipText:this.l10n.getConstant("Transform"),align:"Center",template:'<button id="'+this.element.id+'_transformBtn"></button>'}),(e.isNullOrUndefined(this.toolbar)||!e.isNullOrUndefined(this.toolbar)&&this.toolbar.indexOf("Finetune")>-1)&&i.push({id:this.element.id+"_adjustment",prefixIcon:"e-icons e-adjustment",cssClass:"top-icon e-adjustment",tooltipText:this.l10n.getConstant("Finetune"),align:"Center"}),(e.isNullOrUndefined(this.toolbar)||!e.isNullOrUndefined(this.toolbar)&&this.toolbar.indexOf("Filter")>-1)&&i.push({id:this.element.id+"_filter",prefixIcon:"e-icons e-filters",cssClass:"top-icon e-filters",tooltipText:this.l10n.getConstant("Filter"),align:"Center"});for(var s=this.processToolbar("center"),o=0,a=s.length;o<a;o++)i.push(s[o]);return t&&(i.push({id:this.element.id+"_ok",prefixIcon:"e-icons e-check",cssClass:"top-icon e-tick",tooltipText:this.l10n.getConstant("OK"),align:"Right"}),i.push({id:this.element.id+"_cancel",prefixIcon:"e-icons e-close",cssClass:"top-icon e-save",tooltipText:this.l10n.getConstant("Cancel"),align:"Right"})),i},l.prototype.getZoomToolbarItem=function(){return[]},l.prototype.processToolbar=function(t){var i=[];if(this.toolbar)for(var s=0,o=this.toolbar.length;s<o;s++)"object"==typeof this.toolbar[s]&&(e.isNullOrUndefined(this.toolbar[s].align)?"left"===t&&i.push(this.toolbar[s]):this.toolbar[s].align.toLowerCase()===t&&i.push(this.toolbar[s]));return i},l.prototype.processSubToolbar=function(t){var e=[];if(t)for(var i=0,s=t.length;i<s;i++)"object"==typeof t[i]&&(t[i].align="Center",e.push(t[i]));return e},l.prototype.isToolbar=function(){return e.isNullOrUndefined(this.toolbar)||!e.isNullOrUndefined(this.toolbar)&&this.toolbar.length>0||!e.isNullOrUndefined(this.toolbarTemplate)},l.prototype.initToolbarItem=function(t,s,o){var a=this;if(this.isToolbar()){var n=this.getLeftToolbarItem(o),r=this.getRightToolbarItem(o),h=this.getMainToolbarItem(t),l=this.getZoomToolbarItem();this.defToolbarItems=s?n.concat(r):n.concat(h,r,l),new i.Toolbar({width:"100%",items:this.defToolbarItems,clicked:this.defToolbarClicked.bind(this),created:function(){s||(a.renderAnnotationBtn(),a.renderCropBtn(),a.renderTransformBtn()),a.renderSaveBtn(),a.trigger("toolbarCreated",{toolbarType:"main"})}},"#"+this.element.id+"_toolbar"),this.createLeftToolbarControls(),this.enableDisableToolbarBtn(),this.isToolbar()&&!e.isNullOrUndefined(document.getElementById(this.element.id+"_toolbar"))&&e.getComponent(this.element.id+"_toolbar","toolbar").refreshOverflow()}},l.prototype.enableDisableToolbarBtn=function(){var t=document.querySelector("#"+this.element.id+"_undo");e.isNullOrUndefined(t)||0!==this.undoRedoStep?e.isNullOrUndefined(t)||(t.classList.remove("e-disabled"),t.parentElement.classList.remove("e-overlay")):(t.classList.add("e-disabled"),t.parentElement.classList.add("e-overlay"));var i=document.querySelector("#"+this.element.id+"_redo");e.isNullOrUndefined(i)||this.undoRedoStep!==this.undoRedoColl.length?!e.isNullOrUndefined(i)&&0===this.undoRedoStep&&this.undoRedoColl.length>0?(i.classList.remove("e-disabled"),i.parentElement.classList.remove("e-overlay")):e.isNullOrUndefined(i)||(i.classList.remove("e-disabled"),i.parentElement.classList.remove("e-overlay")):(i.classList.add("e-disabled"),i.parentElement.classList.add("e-overlay"));var s=document.querySelector("#"+this.element.id+"_zoomIn");!e.isNullOrUndefined(s)&&this.zoomFactor>=5?(s.classList.add("e-disabled"),s.parentElement.classList.add("e-overlay")):e.isNullOrUndefined(s)||(s.classList.remove("e-disabled"),s.parentElement.classList.remove("e-overlay"));var o=document.querySelector("#"+this.element.id+"_zoomOut");e.isNullOrUndefined(o)||0!==this.zoomFactor?e.isNullOrUndefined(o)||(o.classList.remove("e-disabled"),o.parentElement.classList.remove("e-overlay")):(o.classList.add("e-disabled"),o.parentElement.classList.add("e-overlay"));var a=document.querySelector("#"+this.element.id+"_pan");e.isNullOrUndefined(a)||0!==this.zoomFactor?e.isNullOrUndefined(a)||(a.style.display="block"):a.style.display="none"},l.prototype.createLeftToolbarControls=function(){if(void 0!==this.defToolbarItems&&this.defToolbarItems.length>0&&!e.isNullOrUndefined(document.getElementById(this.element.id+"_toolbar"))){var t=document.getElementById(this.element.id+"_toolbar").querySelector(".e-image-upload");if(t){var i=t.getElementsByTagName("input")[0],s=t.getElementsByTagName("button")[0];s.className="e-tbar-btn e-tbtn-txt e-btn top-icon",s.innerHTML="",s.appendChild(this.createElement("span",{className:"e-btn-icon e-icons e-upload-icon e-icon-left"})),i.onchange=this.fileSelect.bind(this,i)}}},l.prototype.cropSelectedState=function(){e.isNullOrUndefined(this.activeObj.shape)||"crop"!==this.activeObj.shape.split("-")[0]||this.okBtn()},l.prototype.renderAnnotationBtn=function(){var t=this,i=this,o=[];(e.isNullOrUndefined(this.toolbar)||!e.isNullOrUndefined(this.toolbar)&&this.toolbar.indexOf("Pen")>-1)&&o.push({text:this.l10n.getConstant("Pen"),id:"pen",iconCss:"e-icons e-free-pen"}),(e.isNullOrUndefined(this.toolbar)||!e.isNullOrUndefined(this.toolbar)&&this.toolbar.indexOf("Line")>-1)&&o.push({text:this.l10n.getConstant("Line"),id:"line",iconCss:"e-icons e-line"}),(e.isNullOrUndefined(this.toolbar)||!e.isNullOrUndefined(this.toolbar)&&this.toolbar.indexOf("Rectangle")>-1)&&o.push({text:this.l10n.getConstant("Rectangle"),id:"rectangle",iconCss:"e-icons e-rectangle"}),(e.isNullOrUndefined(this.toolbar)||!e.isNullOrUndefined(this.toolbar)&&this.toolbar.indexOf("Ellipse")>-1)&&o.push({text:this.l10n.getConstant("Ellipse"),id:"ellipse",iconCss:"e-icons e-circle"}),(e.isNullOrUndefined(this.toolbar)||!e.isNullOrUndefined(this.toolbar)&&this.toolbar.indexOf("Text")>-1)&&o.push({text:this.l10n.getConstant("Text"),id:"text",iconCss:"e-icons e-add-text"});var a=new s.DropDownButton({items:o,iconCss:"e-icons e-annotation",cssClass:"e-image-popup",open:function(i){t.currObjType.isUndoAction&&t.refreshUndoRedoColl(),e.Browser.isDevice&&(i.element.parentElement.style.top=a.element.getBoundingClientRect().top-i.element.parentElement.offsetHeight+"px")},select:function(e){t.cropSelectedState();var s,o=!1;switch(void 0!==t.activeObj.shape&&(s=t.activeObj.shape.split("-")),void 0===s&&t.currObjType.isCustomCrop?o=!0:void 0!==s&&"crop"===s[0]&&(o=!0),t.currObjType.isCustomCrop=!1,(o||t.togglePan)&&(t.refreshActiveObj(),t.upperContext.clearRect(0,0,t.upperCanvas.width,t.upperCanvas.height),t.refreshToolbar("main")),e.item.id){case"pen":i.tempFreehandCounter=i.freehandCounter,i.tempCurrentFreehandDrawIndex=i.currentFreehandDrawIndex,i.currentToolbar="pen",t.freeHandDraw(!0);break;case"text":i.currentToolbar="text",t.drawShapeText();break;default:i.currentToolbar="shapes",i.drawShape(e.item.id.toLowerCase())}t.updateToolbarItems()}});a.appendTo("#"+this.element.id+"_annotationBtn")},l.prototype.renderCropBtn=function(){var t=this,i=[];(e.isNullOrUndefined(this.toolbar)||!e.isNullOrUndefined(this.toolbar)&&this.toolbar.indexOf("CustomSelection")>-1)&&i.push({text:this.l10n.getConstant("Custom"),id:"custom",iconCss:"e-icons e-custom"}),(e.isNullOrUndefined(this.toolbar)||!e.isNullOrUndefined(this.toolbar)&&this.toolbar.indexOf("CircleSelection")>-1)&&i.push({text:this.l10n.getConstant("Circle"),id:"circle",iconCss:"e-icons e-circle"}),(e.isNullOrUndefined(this.toolbar)||!e.isNullOrUndefined(this.toolbar)&&this.toolbar.indexOf("SquareSelection")>-1)&&i.push({text:this.l10n.getConstant("Square"),id:"square",iconCss:"e-icons e-square"}),(e.isNullOrUndefined(this.toolbar)||!e.isNullOrUndefined(this.toolbar)&&this.toolbar.indexOf("RatioSelection")>-1)&&(i.push({text:"3:2",id:"3:2",iconCss:"e-icons e-custom-a"}),i.push({text:"4:3",id:"4:3",iconCss:"e-icons e-custom-b"}),i.push({text:"5:4",id:"5:4",iconCss:"e-icons e-custom-c"}),i.push({text:"7:5",id:"7:5",iconCss:"e-icons e-custom-d"}),i.push({text:"16:9",id:"16:9",iconCss:"e-icons e-custom-e"}));var o=new s.DropDownButton({open:function(i){t.currObjType.isUndoAction&&t.refreshUndoRedoColl(),t.togglePan&&t.cancelPan(),e.Browser.isDevice&&(i.element.parentElement.style.top=o.element.getBoundingClientRect().top-i.element.parentElement.offsetHeight+"px"),!e.isNullOrUndefined(t.activeObj.shape)&&t.activeObj.shape.split("-").length>1&&document.getElementById(t.activeObj.shape.split("-")[1]).classList.add("e-selected")},items:i,select:this.cropSelect.bind(this),iconCss:"e-icons e-select",cssClass:"e-image-popup"});o.appendTo("#"+this.element.id+"_cropBtn")},l.prototype.renderTransformBtn=function(){var t=this,i=[];(e.isNullOrUndefined(this.toolbar)||!e.isNullOrUndefined(this.toolbar)&&this.toolbar.indexOf("RotateLeft")>-1)&&i.push({text:this.l10n.getConstant("RotateLeft"),id:"rotateleft",iconCss:"e-icons e-anti-clock-wise"}),(e.isNullOrUndefined(this.toolbar)||!e.isNullOrUndefined(this.toolbar)&&this.toolbar.indexOf("RotateRight")>-1)&&i.push({text:this.l10n.getConstant("RotateRight"),id:"rotateright",iconCss:"e-icons e-clock-wise"}),(e.isNullOrUndefined(this.toolbar)||!e.isNullOrUndefined(this.toolbar)&&this.toolbar.indexOf("FlipHorizontal")>-1)&&i.push({text:this.l10n.getConstant("HorizontalFlip"),id:"horizontalflip",iconCss:"e-icons e-horizontal-flip"}),(e.isNullOrUndefined(this.toolbar)||!e.isNullOrUndefined(this.toolbar)&&this.toolbar.indexOf("FlipVertical")>-1)&&i.push({text:this.l10n.getConstant("VerticalFlip"),id:"verticalflip",iconCss:"e-icons e-vertical-flip"});var o=new s.DropDownButton({open:function(i){if(t.currObjType.isUndoAction&&t.refreshUndoRedoColl(),e.Browser.isDevice){var s=i.element.parentElement.offsetHeight;i.element.parentElement.style.display="none",i.element.parentElement.style.top=o.element.getBoundingClientRect().top-s+"px",i.element.parentElement.style.display="block"}},items:i,select:this.transformSelect.bind(this),iconCss:"e-icons e-transform",cssClass:"e-image-popup"});o.appendTo("#"+this.element.id+"_transformBtn")},l.prototype.renderSaveBtn=function(){var t=e.getInstance(document.getElementById(this.element.id),c),i=[{text:"JPEG",id:"jpeg"},{text:"PNG",id:"png"},{text:"SVG",id:"svg"}];document.getElementById(this.element.id+"_saveBtn")&&new s.DropDownButton({items:i,cssClass:"e-caret-hide e-image-popup",iconCss:"e-icons e-save",select:function(e){t.export(e.item.text)}}).appendTo("#"+this.element.id+"_saveBtn")},l.prototype.cropSelect=function(t){this.isCropTab=!0,this.zoomFactor=this.cropZoomFactor;var i=this.activeObj,s=t.item.id;this.currentToolbar="crop",this.currSelectionPoint=null,this.select(s),this.refreshToolbar("main",!0,!0),this.refreshDropDownBtn(!0),this.undoRedoColl.push({operation:"selectionTransform",value:null,currentObj:e.extend([],this.objColl,[],!0),previousObj:e.extend([],this.objColl,[],!0),previousSelectionObj:e.extend({},i,{},!0),currentSelectionObj:e.extend({},this.activeObj,{},!0),zoomFactor:this.zoomFactor,sharpen:this.adjustmentLevel.sharpen,bw:this.adjustmentLevel.bw}),this.undoRedoStep++,this.enableDisableToolbarBtn()},l.prototype.transformSelect=function(t){this.cropSelectedState(),this.currentSelectionPoint=null,this.performTransformation(t.item.id),this.afterCropActions.push(t.item.id)},l.prototype.performTransformation=function(t){var e=this.defaultZoomFactor,i=this.isUndoRedo;0!==this.defaultZoomFactor&&(this.isUndoRedo=!0,this.defaultZoomFactor>0?this.zoom(-this.defaultZoomFactor):this.zoom(Math.abs(this.defaultZoomFactor)),this.isUndoRedo=i),this.updateTransform(t),0!==e&&(this.isUndoRedo=!0,this.zoom(e),this.isUndoRedo=i)},l.prototype.updateTransform=function(t){switch(t){case"rotateleft":this.rotate(-90);break;case"rotateright":this.rotate(90);break;case"horizontalflip":this.flip("Horizontal");break;case"verticalflip":this.flip("Vertical")}},l.prototype.getShapesToolbarItem=function(t){var i=[];t.indexOf("fillColor")>-1&&i.push({prefixIcon:"e-icons e-copy",id:this.element.id+"_fillcolor",cssClass:"top-icon e-fill",tooltipText:this.l10n.getConstant("FillColor"),align:"Center",type:"Input",template:'<button id="'+this.element.id+'_fillColorBtn"></button>'}),t.indexOf("strokeColor")>-1&&i.push({prefixIcon:"e-icons e-copy",id:this.element.id+"_strokecolor",cssClass:"top-icon e-stroke",tooltipText:this.l10n.getConstant("StrokeColor"),align:"Center",type:"Input",template:'<button id="'+this.element.id+'_borderColorBtn"></button>'}),t.indexOf("strokeWidth")>-1&&i.push({id:this.element.id+"_strokeWidth",cssClass:"top-icon e-size",tooltipText:"Stroke Width",align:"Center",type:"Input",template:'<button id="'+this.element.id+'_borderWidthBtn"></button>'});for(var s=this.processSubToolbar(t),o=0,a=s.length;o<a;o++)i.push(s[o]);return e.Browser.isDevice||(i.push({id:this.element.id+"_ok",prefixIcon:"e-icons e-check",cssClass:"top-icon e-tick",tooltipText:this.l10n.getConstant("OK"),align:"Right"}),i.push({id:this.element.id+"_cancel",prefixIcon:"e-icons e-close",cssClass:"top-icon e-save",tooltipText:this.l10n.getConstant("Cancel"),align:"Right"})),i},l.prototype.initShapesToolbarItem=function(t){var s=this,o=this.getLeftToolbarItem(),a=this.getRightToolbarItem(),n=this.getShapesToolbarItem(t),r=this.getZoomToolbarItem();e.Browser.isDevice?this.defToolbarItems=n:this.defToolbarItems=o.concat(r,n,a);var h=new i.Toolbar({width:"100%",items:this.defToolbarItems,clicked:this.defToolbarClicked.bind(this),created:function(){s.createShapeColor(t),s.createShapeBtn(t),e.Browser.isDevice||s.renderSaveBtn(),s.trigger("toolbarCreated",{toolbarType:"shapes"}),e.Browser.isDevice?s.defToolbarItems.length>0&&!e.isNullOrUndefined(document.getElementById(s.element.id+"_bottomToolbar"))&&h.refreshOverflow():(s.createLeftToolbarControls(),s.defToolbarItems.length>0&&!e.isNullOrUndefined(document.getElementById(s.element.id+"_toolbar"))&&h.refreshOverflow())}});e.Browser.isDevice?h.appendTo("#"+this.element.id+"_bottomToolbar"):h.appendTo("#"+this.element.id+"_toolbar"),this.enableDisableToolbarBtn()},l.prototype.createShapeColor=function(t){var i=this,a=this;if(t.indexOf("fillColor")>-1){this.element.querySelector(".e-template.e-fill").appendChild(this.createElement("input",{id:this.element.id+"_shape_fill"}));var n=new o.ColorPicker({modeSwitcher:!1,noColor:!0,value:"",showButtons:!1,mode:"Palette",cssClass:"e-shape-fill-color",change:function(t){i.pushActItemIntoObj();var s=e.extend([],i.objColl,[],!0);i.objColl.pop(),a.activeObj.strokeSettings.fillColor=t.currentValue.hex,a.strokeSettings.fillColor=a.activeObj.strokeSettings.fillColor,i.objColl.push(i.activeObj),a.undoRedoColl.push({operation:"shapeTransform",value:null,currentObj:e.extend([],a.objColl,[],!0),previousObj:s,zoomFactor:a.zoomFactor,sharpen:a.adjustmentLevel.sharpen,bw:a.adjustmentLevel.bw}),a.undoRedoStep++,a.redrawShape(a.objColl[a.objColl.length-1]),""===t.currentValue.rgba?r.element.children[0].classList.add("e-nocolor-item"):(r.element.children[0].classList.remove("e-nocolor-item"),r.element.children[0].style.backgroundColor=t.currentValue.rgba),r.toggle()}},"#"+this.element.id+"_shape_fill"),r=new s.DropDownButton({open:function(t){e.Browser.isDevice&&(t.element.parentElement.style.top=r.element.getBoundingClientRect().top-t.element.parentElement.offsetHeight+"px",t.element.parentElement.style.left=i.element.offsetLeft+"px")},target:".e-shape-fill-color",iconCss:"e-dropdownbtn-preview"},"#"+this.element.id+"_fillColorBtn");n.inline=!0,this.element.querySelector(".e-fill.e-template .e-dropdownbtn-preview").classList.add("e-nocolor-item")}if(t.indexOf("strokeColor")>-1){this.element.querySelector(".e-template.e-stroke").appendChild(this.createElement("input",{id:this.element.id+"_shape_stroke"}));var h=new o.ColorPicker({modeSwitcher:!1,noColor:!1,value:"#fff",showButtons:!1,mode:"Palette",cssClass:"e-shape-stroke-color",change:function(t){i.pushActItemIntoObj();var s=e.extend([],i.objColl,[],!0);i.objColl.pop(),a.activeObj.strokeSettings.strokeColor=t.currentValue.hex,a.strokeSettings.strokeColor=a.activeObj.strokeSettings.strokeColor,a.togglePen||(i.objColl.push(i.activeObj),a.undoRedoColl.push({operation:"shapeTransform",value:null,currentObj:e.extend([],a.objColl,[],!0),previousObj:s,zoomFactor:a.zoomFactor,sharpen:a.adjustmentLevel.sharpen,bw:a.adjustmentLevel.bw}),a.undoRedoStep++,a.redrawShape(a.objColl[a.objColl.length-1])),l.element.children[0].style.backgroundColor=t.currentValue.rgba,l.toggle()}},"#"+this.element.id+"_shape_stroke"),l=new s.DropDownButton({open:function(t){e.Browser.isDevice&&(t.element.parentElement.style.top=l.element.getBoundingClientRect().top-t.element.parentElement.offsetHeight+"px",t.element.parentElement.style.left=i.element.offsetLeft+"px")},target:".e-shape-stroke-color",iconCss:"e-dropdownbtn-preview"},"#"+this.element.id+"_borderColorBtn");h.inline=!0,this.element.querySelector(".e-stroke.e-template .e-dropdownbtn-preview").style.background="#fff"}},l.prototype.createShapeBtn=function(t){var i=this,o=[{id:"1",text:this.l10n.getConstant("XSmall")},{id:"2",text:this.l10n.getConstant("Small")},{id:"3",text:this.l10n.getConstant("Medium")},{id:"4",text:this.l10n.getConstant("Large")},{id:"5",text:this.l10n.getConstant("XLarge")}];if(t.indexOf("strokeWidth")>-1){var a=document.getElementById(this.element.id+"_borderWidthBtn"),n=document.createElement("span");n.innerHTML=this.l10n.getConstant("Small"),n.className="e-shape-stroke-width",a.appendChild(n);var r=new s.DropDownButton({items:o,open:function(t){e.Browser.isDevice&&(t.element.parentElement.style.top=r.element.getBoundingClientRect().top-t.element.parentElement.offsetHeight+"px");var i=n.innerHTML;""!==i&&t.element.querySelector('[aria-label = "'+i+'"]').classList.add("e-selected-btn")},select:function(t){i.pushActItemIntoObj();var s=e.extend([],i.objColl,[],!0);i.objColl.pop(),n.textContent=t.item.text,i.activeObj.strokeSettings.strokeWidth=parseInt(t.item.id,10),i.activeObj.strokeSettings.strokeWidth*=2,i.strokeSettings.strokeWidth=i.activeObj.strokeSettings.strokeWidth,i.objColl.push(i.activeObj),i.undoRedoColl.push({operation:"shapeTransform",value:null,currentObj:e.extend([],i.objColl,[],!0),previousObj:s,zoomFactor:i.zoomFactor,sharpen:i.adjustmentLevel.sharpen,bw:i.adjustmentLevel.bw}),i.undoRedoStep++,i.redrawShape(i.objColl[i.objColl.length-1]),e.Browser.isDevice?e.isNullOrUndefined(document.getElementById(i.element.id+"_bottomToolbar"))||e.getComponent(i.element.id+"_bottomToolbar","toolbar").refreshOverflow():e.isNullOrUndefined(document.getElementById(i.element.id+"_toolbar"))||e.getComponent(i.element.id+"_toolbar","toolbar").refreshOverflow()}});r.appendTo("#"+this.element.id+"_borderWidthBtn")}},l.prototype.getTextToolbarItem=function(t){var i=[];t.indexOf("fontFamily")>-1&&i.push({id:this.element.id+"_fontFamily",cssClass:"top-icon e-img-font-family",tooltipText:this.l10n.getConstant("FontFamily"),align:"Center",template:'<button id="'+this.element.id+'_fontFamilyBtn"></button>'}),t.indexOf("fontStyle")>-1&&i.push({id:this.element.id+"_fontStyle",cssClass:"top-icon e-img-font-style",tooltipText:this.l10n.getConstant("FontStyle"),align:"Center",template:'<button id="'+this.element.id+'_fontStyleBtn"></button>'}),t.indexOf("fontSize")>-1&&i.push({id:this.element.id+"_fontSize",cssClass:"top-icon e-img-font-size",tooltipText:this.l10n.getConstant("FontSize"),align:"Center",template:'<button id="'+this.element.id+'_fontSizeBtn"></button>'}),t.indexOf("fontColor")>-1&&i.push({cssClass:"top-icon e-text-font-color",id:this.element.id+"_text_strokecolor",tooltipText:this.l10n.getConstant("FontColor"),align:"Center",type:"Input",template:'<button id="'+this.element.id+'_fontColorBtn"></button>'});for(var s=this.processSubToolbar(t),o=0,a=s.length;o<a;o++)i.push(s[o]);return e.Browser.isDevice||(i.push({id:this.element.id+"_ok",prefixIcon:"e-icons e-check",cssClass:"top-icon e-tick",tooltipText:this.l10n.getConstant("OK"),align:"Right"}),i.push({id:this.element.id+"_cancel",prefixIcon:"e-icons e-close",cssClass:"top-icon e-save",tooltipText:this.l10n.getConstant("Cancel"),align:"Right"})),i},l.prototype.getFontFamilyItems=function(){return e.Browser.isDevice?[{id:"arial",text:"ABC"},{id:"calibri",text:"ABC"},{id:"georgia",text:"ABC"},{id:"roboto",text:"ABC"},{id:"tahoma",text:"ABC"}]:[{id:"arial",text:"Arial"},{id:"calibri",text:"Calibri"},{id:"georgia",text:"Georgia"},{id:"roboto",text:"Roboto"},{id:"tahoma",text:"Tahoma"}]},l.prototype.getFontSizeItems=function(){return e.Browser.isDevice?[{id:"default",text:this.l10n.getConstant("ABC")},{id:"bold",text:this.l10n.getConstant("ABC")},{id:"italic",text:this.l10n.getConstant("ABC")},{id:"bolditalic",text:this.l10n.getConstant("ABC")}]:[{id:"default",text:this.l10n.getConstant("Default")},{id:"bold",text:this.l10n.getConstant("Bold")},{id:"italic",text:this.l10n.getConstant("Italic")},{id:"bolditalic",text:this.l10n.getConstant("BoldItalic")}]},l.prototype.initTextToolbarItem=function(t){var s=this,o=this.getLeftToolbarItem(),a=this.getRightToolbarItem(),n=this.getTextToolbarItem(t),r=this.getZoomToolbarItem();e.Browser.isDevice?this.defToolbarItems=n:this.defToolbarItems=o.concat(r,n,a);var h=new i.Toolbar({width:"100%",items:this.defToolbarItems,clicked:this.defToolbarClicked.bind(this),created:function(){s.createTextColor(t),s.createTextBtn(t),e.Browser.isDevice||s.renderSaveBtn(),s.trigger("toolbarCreated",{toolbarType:"text"}),e.Browser.isDevice?s.defToolbarItems.length>0&&!e.isNullOrUndefined(document.getElementById(s.element.id+"_bottomToolbar"))&&h.refreshOverflow():(s.createLeftToolbarControls(),s.defToolbarItems.length>0&&!e.isNullOrUndefined(document.getElementById(s.element.id+"_toolbar"))&&h.refreshOverflow())}});e.Browser.isDevice?h.appendTo("#"+this.element.id+"_bottomToolbar"):h.appendTo("#"+this.element.id+"_toolbar"),this.enableDisableToolbarBtn()},l.prototype.createTextColor=function(t){var i=this,a=this;if(t.indexOf("fontColor")>-1){this.element.querySelector(".e-template.e-text-font-color").appendChild(this.createElement("input",{id:this.element.id+"_text_font"}));var n=new o.ColorPicker({modeSwitcher:!1,value:"#fff",showButtons:!1,mode:"Palette",cssClass:"e-text-fontt-color",change:function(t){i.pushActItemIntoObj();var s=e.extend([],i.objColl,[],!0);if(i.objColl.pop(),"none"===a.textArea.style.display)a.strokeSettings.strokeColor=a.activeObj.strokeSettings.strokeColor=t.currentValue.hex,a.togglePen||(i.objColl.push(i.activeObj),a.undoRedoColl.push({operation:"shapeTransform",value:null,currentObj:e.extend([],a.objColl,[],!0),previousObj:s,zoomFactor:a.zoomFactor,sharpen:a.adjustmentLevel.sharpen,bw:a.adjustmentLevel.bw}),a.undoRedoStep++,a.redrawShape(a.objColl[a.objColl.length-1]));else if("block"===a.textArea.style.display){a.textArea.style.color=t.currentValue.hex;var o=a.activeObj.strokeSettings.strokeColor;a.activeObj.strokeSettings.strokeColor=t.currentValue.hex,i.objColl.push(i.activeObj),i.undoRedoColl.push({operation:"textTransform",value:null,currentObj:e.extend([],i.objColl,[],!0),previousObj:s,zoomFactor:a.zoomFactor,sharpen:a.adjustmentLevel.sharpen,bw:a.adjustmentLevel.bw}),i.undoRedoStep++,i.objColl.pop(),a.activeObj.strokeSettings.strokeColor=o}else a.togglePen||(i.objColl.push(i.activeObj),a.undoRedoColl.push({operation:"shapeTransform",value:null,currentObj:e.extend([],a.objColl,[],!0),previousObj:s,zoomFactor:a.zoomFactor,sharpen:a.adjustmentLevel.sharpen,bw:a.adjustmentLevel.bw}),a.undoRedoStep++,a.redrawShape(a.objColl[a.objColl.length-1]));r.element.children[0].style.backgroundColor=t.currentValue.rgba,r.toggle()}},"#"+this.element.id+"_text_font"),r=new s.DropDownButton({open:function(t){e.Browser.isDevice&&(t.element.parentElement.style.top=r.element.getBoundingClientRect().top-t.element.parentElement.offsetHeight+"px",t.element.parentElement.style.left=i.element.offsetLeft+"px")},target:".e-text-fontt-color",iconCss:"e-dropdownbtn-preview"},"#"+this.element.id+"_fontColorBtn");n.inline=!0,this.element.querySelector(".e-text-font-color.e-template .e-dropdownbtn-preview").style.background="#fff"}},l.prototype.pushActItemIntoObj=function(){if("none"===this.textArea.style.display)this.objColl.push(this.activeObj);else{var t=e.extend({},this.activeObj,{},!0);this.setTextBoxStylesToActObj(),this.objColl.push(this.activeObj),this.activeObj=t}},l.prototype.createTextBtn=function(t){var i=this;if(t.indexOf("fontFamily")>-1){var o=document.getElementById(this.element.id+"_fontFamilyBtn"),a=document.createElement("span");e.Browser.isDevice?(a.innerHTML="ABC",a.setAttribute("style","font-family: arial")):a.innerHTML="Arial",a.className="e-text-font-family",o.appendChild(a);var n=new s.DropDownButton({items:this.getFontFamilyItems(),cssClass:"e-font-family",createPopupOnClick:!0,beforeItemRender:function(t){t.element.setAttribute("style","font-family:"+t.element.id)},open:function(t){e.Browser.isDevice&&(t.element.parentElement.style.top=n.element.getBoundingClientRect().top-t.element.parentElement.offsetHeight+"px");var s;s="block"===i.textArea.style.display?i.textArea.style.fontFamily:i.activeObj.textSettings.fontFamily,t.element.querySelector('[id *= "'+s.toLowerCase()+'"]').classList.add("e-selected-btn")},select:function(t){i.pushActItemIntoObj();var s=e.extend([],i.objColl,[],!0);if(i.objColl.pop(),a.textContent=t.item.text,e.Browser.isDevice&&a.setAttribute("style","font-family:"+t.item.id),"block"===i.textArea.style.display){i.updateFontRatio(i.activeObj,!0);var o=i.activeObj.textSettings.fontFamily;i.activeObj.textSettings.fontFamily=i.toPascalCase(t.item.id),i.redrawText(),i.objColl.push(i.activeObj),i.undoRedoColl.push({operation:"textTransform",value:null,currentObj:e.extend([],i.objColl,[],!0),previousObj:s,zoomFactor:i.zoomFactor,sharpen:i.adjustmentLevel.sharpen,bw:i.adjustmentLevel.bw}),i.undoRedoStep++,i.objColl.pop(),i.upperContext.clearRect(0,0,i.upperCanvas.width,i.upperCanvas.height);var n=i.activeObj.activePoint.width+.25*i.activeObj.textSettings.fontSize;i.textArea.style.width=n+"px",i.textArea.style.fontFamily=i.toPascalCase(t.item.id),i.activeObj.textSettings.fontFamily=o,i.updateFontStyles()}else i.updateFontRatio(i.activeObj),i.textSettings.fontFamily=i.activeObj.textSettings.fontFamily=i.toPascalCase(t.item.id),i.redrawText(),i.objColl.push(i.activeObj),i.undoRedoColl.push({operation:"shapeTransform",value:null,currentObj:e.extend([],i.objColl,[],!0),previousObj:s,zoomFactor:i.zoomFactor,sharpen:i.adjustmentLevel.sharpen,bw:i.adjustmentLevel.bw}),i.undoRedoStep++,i.redrawShape(i.objColl[i.objColl.length-1])}});n.appendTo("#"+this.element.id+"_fontFamilyBtn")}if(t.indexOf("fontStyle")>-1){var r=document.getElementById(this.element.id+"_fontStyleBtn"),h=document.createElement("span");e.Browser.isDevice?h.innerHTML=this.l10n.getConstant("ABC"):h.innerHTML=this.l10n.getConstant("Default"),h.className="e-text-font-style",r.appendChild(h);var l=new s.DropDownButton({items:this.getFontSizeItems(),cssClass:"e-font-style",createPopupOnClick:!0,beforeItemRender:function(t){e.Browser.isDevice&&("bold"===t.element.id?t.element.setAttribute("style","font-weight: bold"):"italic"===t.element.id?t.element.setAttribute("style","font-style: italic"):"bolditalic"===t.element.id&&t.element.setAttribute("style","font-style: italic;font-weight: bold"))},open:function(t){var s="default";"block"===i.textArea.style.display?("bold"===i.textArea.style.fontWeight&&(s="bold"),"italic"===i.textArea.style.fontStyle&&(s=s.replace("default",""),s+="italic")):(i.activeObj.textSettings.bold&&(s="bold"),i.activeObj.textSettings.italic&&(s=s.replace("default",""),s+="italic")),e.Browser.isDevice&&(t.element.parentElement.style.top=l.element.getBoundingClientRect().top-t.element.parentElement.offsetHeight+"px"),t.element.querySelector('[id *= "'+s+'"]').classList.add("e-selected-btn")},select:function(t){e.Browser.isDevice?("bold"===t.item.id?h.setAttribute("style","font-weight: bold"):"italic"===t.item.id?h.setAttribute("style","font-style: italic"):"bolditalic"===t.item.id&&h.setAttribute("style","font-style: italic;font-weight: bold"),i.applyFontStyle(t.item.id)):(h.textContent=t.item.text,i.applyFontStyle(t.item.id))}});l.appendTo("#"+this.element.id+"_fontStyleBtn")}if(t.indexOf("fontSize")>-1){var c=document.getElementById(this.element.id+"_fontSizeBtn"),d=document.createElement("span"),p=this.getFontSizes();d.innerHTML=p[0].text,d.className="e-text-font-size",c.appendChild(d);var v=new s.DropDownButton({cssClass:"e-font-size",items:p,open:function(t){e.Browser.isDevice&&(t.element.parentElement.style.top=v.element.getBoundingClientRect().top-t.element.parentElement.offsetHeight+"px");var i=d.innerHTML;t.element.querySelector('[aria-label *= "'+i+'"]').classList.add("e-selected-btn")},select:function(t){i.pushActItemIntoObj();var s=e.extend([],i.objColl,[],!0);if(i.objColl.pop(),d.textContent=t.item.text,"block"===i.textArea.style.display){i.updateFontRatio(i.activeObj,!0);var o=i.activeObj.textSettings.fontSize;i.activeObj.textSettings.fontSize=parseInt(i.fontSizeColl[parseInt(t.item.text,10)-1].text,10),i.objColl.push(i.activeObj),i.undoRedoColl.push({operation:"textTransform",value:null,currentObj:e.extend([],i.objColl,[],!0),previousObj:s,zoomFactor:i.zoomFactor,sharpen:i.adjustmentLevel.sharpen,bw:i.adjustmentLevel.bw}),i.undoRedoStep++,i.objColl.pop();var a="";"bold"===i.textArea.style.fontWeight&&(a="bold "),"italic"===i.textArea.style.fontStyle&&(a="italic "),"bold"===i.textArea.style.fontWeight&&"italic"===i.textArea.style.fontStyle&&(a="italic bold "),i.upperContext.font=a+i.activeObj.textSettings.fontSize+"px "+i.textArea.style.fontFamily;var n=i.textArea.value.split("\n"),r=i.getMaxText(!0),h=i.upperContext.measureText(r).width+.5*i.activeObj.textSettings.fontSize;i.textArea.style.width=h+"px",i.textArea.style.height=n.length*(i.activeObj.textSettings.fontSize+.25*i.activeObj.textSettings.fontSize)+"px",i.activeObj.textSettings.fontSize=o,i.upperContext.font=i.activeObj.textSettings.fontSize+"px "+i.activeObj.textSettings.fontFamily,i.textArea.style.fontSize=parseInt(i.fontSizeColl[parseInt(t.item.text,10)-1].text,10)+"px","georgia"===i.textArea.style.fontFamily&&(i.textArea.style.width=parseFloat(i.textArea.style.width)+parseFloat(i.textArea.style.fontSize)+"px")}else{i.updateFontRatio(i.activeObj),i.textSettings.fontSize=i.activeObj.textSettings.fontSize=parseInt(i.fontSizeColl[parseInt(t.item.text,10)-1].text,10),i.upperContext.font=i.activeObj.textSettings.fontSize+"px "+i.activeObj.textSettings.fontFamily;var n=i.activeObj.keyHistory.split("\n"),r=i.getMaxText(),h=i.upperContext.measureText(r).width+.5*i.activeObj.textSettings.fontSize,l=n.length*(i.activeObj.textSettings.fontSize+.25*i.activeObj.textSettings.fontSize);i.setTextSelection(h,l),i.updateActiveObject(i.activeObj.activePoint,i.activeObj),i.redrawText(),i.objColl.push(i.activeObj),i.undoRedoColl.push({operation:"shapeTransform",value:null,currentObj:e.extend([],i.objColl,[],!0),previousObj:s,zoomFactor:i.zoomFactor,sharpen:i.adjustmentLevel.sharpen,bw:i.adjustmentLevel.bw}),i.undoRedoStep++,i.redrawShape(i.objColl[i.objColl.length-1])}}});v.appendTo("#"+this.element.id+"_fontSizeBtn")}},l.prototype.getFontSizes=function(){var t=[];this.fontSizeColl=[];var e;e=0===this.degree||this.degree%180==0?this.destWidth/25:this.destHeight/25;for(var i=1;i<=10;i++)this.fontSizeColl.push({text:(i*Math.round(e/2)).toString()}),t.push({text:i.toString()});return t},l.prototype.getTextAreaWidth=function(t){var e=this.activeObj.textSettings.bold,i=this.activeObj.textSettings.italic;switch(t){case"default":this.activeObj.textSettings.bold=!1,this.activeObj.textSettings.italic=!1;break;case"bold":this.activeObj.textSettings.bold=!0,this.activeObj.textSettings.italic=!1;break;case"italic":this.activeObj.textSettings.bold=!1,this.activeObj.textSettings.italic=!0;break;case"bolditalic":this.activeObj.textSettings.bold=!0,this.activeObj.textSettings.italic=!0}this.updateFontStyles();var s;return s="none"===this.textArea.style.display?this.upperContext.measureText(this.activeObj.keyHistory).width+.5*this.activeObj.textSettings.fontSize:this.upperContext.measureText(this.textArea.value).width+.5*this.activeObj.textSettings.fontSize,this.activeObj.textSettings.bold=e,this.activeObj.textSettings.italic=i,s},l.prototype.updateUndoRedoObj=function(t){this.objColl.push(this.activeObj),this.undoRedoColl.push({operation:"shapeTransform",value:null,currentObj:e.extend([],this.objColl,[],!0),previousObj:t,zoomFactor:this.zoomFactor,sharpen:this.adjustmentLevel.sharpen,bw:this.adjustmentLevel.bw}),this.undoRedoStep++,this.redrawShape(this.objColl[this.objColl.length-1])},l.prototype.updateObjColl=function(t,i){var s=this.activeObj.textSettings.bold,o=this.activeObj.textSettings.italic;switch(t){case"default":this.activeObj.textSettings.bold=!1,this.activeObj.textSettings.italic=!1;break;case"bold":this.activeObj.textSettings.bold=!0,this.activeObj.textSettings.italic=!1;break;case"italic":this.activeObj.textSettings.bold=!1,this.activeObj.textSettings.italic=!0;break;case"bolditalic":this.activeObj.textSettings.bold=!0,this.activeObj.textSettings.italic=!0}this.objColl.push(this.activeObj),this.undoRedoColl.push({operation:"textTransform",value:null,currentObj:e.extend([],this.objColl,[],!0),previousObj:i,zoomFactor:this.zoomFactor,sharpen:this.adjustmentLevel.sharpen,bw:this.adjustmentLevel.bw}),this.undoRedoStep++,this.objColl.pop(),this.activeObj.textSettings.bold=s,this.activeObj.textSettings.italic=o},l.prototype.applyFontStyle=function(t){this.pushActItemIntoObj();var i=e.extend([],this.objColl,[],!0);switch(this.objColl.pop(),"none"===this.textArea.style.display?this.updateFontRatio(this.activeObj):this.updateFontRatio(this.activeObj,!0),t){case"default":if("block"===this.textArea.style.display){s=this.getTextAreaWidth(t);this.textArea.style.width=s+"px",this.textArea.style.fontWeight="normal",this.textArea.style.fontStyle="normal",this.updateObjColl(t,i)}else this.textSettings.bold=this.activeObj.textSettings.bold=!1,this.textSettings.italic=this.activeObj.textSettings.italic=!1,this.redrawText(),this.updateUndoRedoObj(i);break;case"bold":if("block"===this.textArea.style.display){s=this.getTextAreaWidth(t);this.textArea.style.width=s+"px",this.textArea.style.fontWeight="bold",this.textArea.style.fontStyle="normal",this.updateObjColl(t,i)}else this.textSettings.bold=this.activeObj.textSettings.bold=!0,this.textSettings.italic=this.activeObj.textSettings.italic=!1,this.redrawText(),this.updateUndoRedoObj(i);break;case"italic":if("block"===this.textArea.style.display){s=this.getTextAreaWidth(t);this.textArea.style.width=s+"px",this.textArea.style.fontWeight="normal",this.textArea.style.fontStyle="italic",this.updateObjColl(t,i)}else this.textSettings.bold=this.activeObj.textSettings.bold=!1,this.textSettings.italic=this.activeObj.textSettings.italic=!0,this.redrawText(),this.updateUndoRedoObj(i);break;case"bolditalic":if("block"===this.textArea.style.display){var s=this.getTextAreaWidth(t);this.textArea.style.width=s+"px",this.textArea.style.fontWeight="bold",this.textArea.style.fontStyle="italic",this.updateObjColl(t,i)}else this.textSettings.bold=this.activeObj.textSettings.bold=!0,this.textSettings.italic=this.activeObj.textSettings.italic=!0,this.redrawText(),this.updateUndoRedoObj(i)}},l.prototype.initZoomToolbarItem=function(){var t=this,s=this.getLeftToolbarItem(),o=this.getRightToolbarItem(),a=this.getZoomToolbarItem();this.defToolbarItems=s.concat(a,o),new i.Toolbar({width:"100%",items:this.defToolbarItems,clicked:this.defToolbarClicked.bind(this),created:function(){t.renderSaveBtn(),t.trigger("toolbarCreated",{toolbarType:"zoom"})}},"#"+this.element.id+"_toolbar"),this.createLeftToolbarControls(),this.enableDisableToolbarBtn(),this.defToolbarItems.length>0&&!e.isNullOrUndefined(document.getElementById(this.element.id+"_toolbar"))&&e.getComponent(this.element.id+"_toolbar","toolbar").refreshOverflow()},l.prototype.refreshUndoRedoColl=function(){this.undoRedoColl=this.undoRedoColl.slice(0,this.undoRedoStep),this.isUndoRedo=this.currObjType.isUndoAction=!1,this.enableDisableToolbarBtn()},l.prototype.applyPreviewFilter=function(){e.isNullOrUndefined(document.querySelector("#"+this.element.id+"_sliderWrapper"))&&!this.currObjType.isFiltered||(this.initialAdjustmentValue=this.canvasFilter=this.lowerContext.filter,this.currObjType.isFiltered=!1)},l.prototype.contextualToolbarClicked=function(t){var e=this.element.querySelector(".e-contextual-toolbar-wrapper .e-toolbar-item.e-selected");e&&e.classList.remove("e-selected"),document.getElementById(t.item.id+"Canvas").parentElement.parentElement.classList.add("e-selected"),this.currObjType.isFiltered=!0;var i=t.item.id.replace(this.element.id,"").split("_")[1],s={filter:this.toPascalCase(i)};this.trigger("imageFiltering",s),this.setFilter(i.toLowerCase()),this.currentFilter=t.item.id,this.enableDisableToolbarBtn()},l.prototype.defToolbarClicked=function(t){var i=!1;this.element.querySelector(".e-contextual-toolbar-wrapper")&&(this.element.querySelector(".e-contextual-toolbar-wrapper").classList.contains("e-hide")||(i=!0),this.element.querySelector(".e-contextual-toolbar-wrapper").classList.add("e-hide"));var s,o,a,n=t.item.id.replace(this.element.id+"_","").toLowerCase(),r=e.getInstance(document.getElementById(this.element.id),c),h=!1;void 0!==this.activeObj.shape&&(a=this.activeObj.shape.split("-")),void 0===a&&this.currObjType.isCustomCrop?h=!0:void 0!==a&&"crop"===a[0]&&(h=!0);var l=!1,d=!1,p=!1,v=document.querySelector("#"+this.element.id+"_zoomOut");!e.isNullOrUndefined(v)&&v.classList.contains("e-disabled")&&(l=!0);var b=document.querySelector("#"+this.element.id+"_adjustment");!e.isNullOrUndefined(b)&&b.classList.contains("e-disabled")&&(p=!0);var u=document.querySelector("#"+this.element.id+"_filter");if(!e.isNullOrUndefined(u)&&u.classList.contains("e-disabled")&&(d=!0),this.enableDisableToolbarBtn(),!this.disabled)switch(n){case"zoomin":this.isFreehandDrawEditing&&this.applyFreehandDraw(),this.applyPreviewFilter(),this.currObjType.isFiltered=!1,this.currObjType.isUndoAction&&this.refreshUndoRedoColl(),this.togglePen&&(this.currObjType.isZoomed=!0,this.freeHandDraw(!1)),this.currentSelectionPoint=null,r.zoom(.1);break;case"zoomout":l||(this.isFreehandDrawEditing&&this.applyFreehandDraw(),this.applyPreviewFilter(),this.currObjType.isFiltered=!1,this.currObjType.isUndoAction&&this.refreshUndoRedoColl(),this.togglePen&&(this.currObjType.isZoomed=!0,this.freeHandDraw(!1)),this.currentSelectionPoint=null,r.zoom(-.1));break;case"pan":this.currObjType.isCustomCrop=this.currObjType.isFiltered=!1,this.currObjType.isUndoAction&&this.refreshUndoRedoColl(),h&&(this.currObjType.isCustomCrop=!1,this.refreshActiveObj(),this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),this.refreshToolbar("main")),this.togglePan?(this.cancelPan(),this.disablePan=!0,"pen"===this.currentToolbar&&this.freeHandDraw(!0)):(o=this.element.querySelector(".e-img-pan .e-btn"),e.isNullOrUndefined(o)||o.classList.add("e-selected-btn"),r.pan(!0),this.disablePan=!1),s=document.querySelector("#"+this.element.id+"_zoomIn"),!e.isNullOrUndefined(s)&&this.zoomFactor>=5?(s.classList.add("e-disabled"),s.parentElement.classList.add("e-overlay")):e.isNullOrUndefined(s)||(s.classList.remove("e-disabled"),s.parentElement.classList.remove("e-overlay")),this.refreshToolbar("main");break;case"cancel":this.performCancel(i);break;case"ok":this.okBtn(),this.refreshDropDownBtn(!1),this.currentToolbar="main";break;case"crop":e.isNullOrUndefined(this.currSelectionPoint)||(this.select("Custom"),this.refreshToolbar("main",!0,!0),e.getComponent(this.element.querySelector("#"+this.element.id+"_cropBtn"),"dropdown-btn").toggle(),e.isNullOrUndefined(this.activeObj.shape)||document.getElementById(this.activeObj.shape.split("-")[1]).classList.add("e-selected"));break;case"reset":r.reset(),this.currentToolbar="main";break;case"undo":this.callUndo();break;case"redo":this.callRedo();break;case"adjustment":p||(this.refreshToolbar("adjustment"),this.setTempFilterProperties(),this.openSlider("brightness"));break;case"brightness":case"contrast":case"hue":case"saturation":case"opacity":case"blur":case"exposure":this.openSlider(n);break;case"filter":d||(this.refreshToolbar("filter"),this.setTempFilterProperties());break;case"default":case"chrome":case"cold":case"warm":case"grayscale":case"blackandwhite":case"sepia":case"invert":case"sharpen":this.currObjType.isFiltered=!0,this.setFilter(n)}this.trigger("toolbarItemClicked",t)},l.prototype.performCancel=function(t){t=t||!1,this.isFreehandDrawEditing?this.cancelFreehandDraw():"block"===this.textArea.style.display?(this.textArea.style.display="none",this.textArea.value="",this.textArea.style.transform="",this.activeObj.strokeSettings=this.tempStrokeSettings,this.activeObj.textSettings=this.tempTextSettings):!e.isNullOrUndefined(document.querySelector("#"+this.element.id+"_sliderWrapper"))||this.currObjType.isFiltered?(this.lowerContext.filter=this.adjustmentValue=this.initialAdjustmentValue=this.tempAdjustmentValue,this.lowerContext.filter.split(" ").length>1&&"1"===this.lowerContext.filter.split(" ")[0].split("(")[1].split(")")[0]&&(this.isBrightnessAdjusted=!1),this.currentFilter=this.tempFilter,this.lowerContext.clearRect(0,0,this.lowerCanvas.width,this.lowerCanvas.height),this.redrawImgWithObj(),this.currObjType.isFiltered=!1,this.adjustmentLevel=e.extend({},this.tempAdjustmentLevel,{},!0),this.element.querySelector(".e-contextual-toolbar-wrapper").classList.add("e-hide"),this.undoRedoColl=e.extend([],this.tempUndoRedoColl,[],!0),this.undoRedoStep=this.tempUndoRedoStep,this.upperCanvas.style.cursor="default",this.currObjType.isCustomCrop=!1,this.tempStrokeSettings={strokeColor:"#fff",fillColor:"",strokeWidth:null},this.callMainToolbar()):t?this.callMainToolbar():(this.cancelItems(),this.togglePan=this.dragCanvas=!1),this.enableDisableToolbarBtn(),this.refreshDropDownBtn(!1),this.currentToolbar="main"},l.prototype.applyShape=function(){e.isNullOrUndefined(this.activeObj.shape)||"rectangle"!==this.activeObj.shape&&"ellipse"!==this.activeObj.shape&&"line"!==this.activeObj.shape&&"text"!==this.activeObj.shape||(this.redrawActObj(),this.refreshActiveObj(),this.currentToolbar="main",this.refreshToolbar("main"))},l.prototype.applyFreehandDraw=function(){"#42a5f5"===this.pointColl[this.freehandDrawSelectedIndex].strokeColor&&(this.pointColl[this.freehandDrawSelectedIndex].strokeColor=this.tempFreeHandDrawEditingStyles.strokeColor),this.selectedFreehandColor="#42a5f5",this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),this.lowerContext.clearRect(0,0,this.lowerCanvas.width,this.lowerCanvas.height),this.renderImage(),this.refreshToolbar("main"),this.pointColl[this.freehandDrawSelectedIndex].isSelected=!1,this.isFreehandDrawEditing=this.isFreehandDrawingPoint=!1,this.freehandDrawHoveredIndex=this.freehandDrawSelectedIndex=null},l.prototype.cancelFreehandDraw=function(){this.selectedFreehandColor="#42a5f5",this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height);for(var t=0;t<this.freehandCounter;t++)this.pointColl[t].strokeColor=this.tempFreeHandDrawEditingStyles.strokeColor,this.pointColl[t].strokeWidth=this.tempFreeHandDrawEditingStyles.strokeWidth;this.pointCounter=0,this.pointColl[this.freehandDrawSelectedIndex].isSelected=!1,this.freehandDrawHoveredIndex=this.freehandDrawSelectedIndex=null,this.isFreehandDrawEditing=this.isFreehandDrawingPoint=!1,this.tempFreeHandDrawEditingStyles={strokeColor:null,strokeWidth:null,fillColor:null},this.refreshToolbar("main")},l.prototype.openSlider=function(t){this.unselectBtn(),this.currObjType.isFiltered=!0,this.refreshToolbar("color",null,null,null,t),document.getElementById(this.element.id+"_"+t).classList.add("e-selected-btn")},l.prototype.setTempFilterProperties=function(){this.upperCanvas.style.display="block",this.cropSelectedState(),this.lowerContext.filter=this.initialAdjustmentValue,this.tempAdjustmentValue=this.lowerContext.filter,this.tempAdjustmentLevel=e.extend({},this.adjustmentLevel,{},!0),this.tempFilter=this.currentFilter,this.tempUndoRedoColl=e.extend([],this.undoRedoColl,[],!0),this.tempUndoRedoStep=this.undoRedoStep},l.prototype.okBtn=function(){var t,i=!1;void 0!==this.activeObj.shape&&(t=this.activeObj.shape.split("-")),void 0===t&&this.currObjType.isCustomCrop?i=!0:void 0!==t&&"crop"===t[0]&&(i=!0);var s=this.element.querySelector(".e-contextual-toolbar-wrapper .e-toolbar-item.e-selected");s&&(this.currentFilter=s.children[0].children[0].id.replace("Canvas","")),i?this.crop():this.togglePen?this.freeHandDraw(!1):"block"===this.textArea.style.display?this.redrawActObj():!e.isNullOrUndefined(document.querySelector("#"+this.element.id+"_sliderWrapper"))||this.currObjType.isFiltered?(this.initialAdjustmentValue=this.canvasFilter=this.lowerContext.filter,this.currObjType.isFiltered=!1):this.isFreehandDrawEditing?this.applyFreehandDraw():this.applyActObj(),this.callMainToolbar(!1),this.isCropTab=!1,this.zoomFactor=this.defaultZoomFactor},l.prototype.updateBrightnessFilter=function(){var t=this.lowerContext.filter.split(" ");if(this.isBrightnessAdjusted&&t.length>0&&!e.isNullOrUndefined(t[4])){var i=parseFloat(t[4].split("(")[1]);t[4]="opacity("+(i-.3)+")",this.lowerContext.filter=t.join(" ")}},l.prototype.isFreehandDrawIndex=function(t){for(var e=!1,i=0;i<this.freehandCounter;i++)if(parseInt(this.pointColl[i].id.split("_")[1],10)-1===t){e=!0;break}return e},l.prototype.deleteFreehandDraw=function(t,i){if(this.isFreehandDrawIndex(t)){this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height);var s=e.extend({},this.pointColl,{},!0);this.pointColl={};var o=0;if(e.isNullOrUndefined(i))for(a=0;a<this.freehandCounter;a++)a!==t&&(this.pointColl[o]=s[a],o++);else for(var a=0;a<this.freehandCounter;a++)parseInt(s[a].id.split("_")[1],10)-1!==t&&(this.pointColl[o]=s[a],o++);this.freehandCounter-=1,this.freehandDrawHoveredIndex=this.freehandDrawSelectedIndex=null,this.isFreehandDrawEditing=this.isFreehandDrawingPoint=!1,this.renderImage(),this.refreshToolbar("main")}},l.prototype.unselectBtn=function(){document.querySelector("#"+this.element.id+"_brightness").classList.contains("e-selected-btn")?document.querySelector("#"+this.element.id+"_brightness").classList.remove("e-selected-btn"):document.querySelector("#"+this.element.id+"_contrast").classList.contains("e-selected-btn")?document.querySelector("#"+this.element.id+"_contrast").classList.remove("e-selected-btn"):document.querySelector("#"+this.element.id+"_hue").classList.contains("e-selected-btn")?document.querySelector("#"+this.element.id+"_hue").classList.remove("e-selected-btn"):document.querySelector("#"+this.element.id+"_saturation").classList.contains("e-selected-btn")?document.querySelector("#"+this.element.id+"_saturation").classList.remove("e-selected-btn"):document.querySelector("#"+this.element.id+"_opacity").classList.contains("e-selected-btn")?document.querySelector("#"+this.element.id+"_opacity").classList.remove("e-selected-btn"):document.querySelector("#"+this.element.id+"_blur").classList.contains("e-selected-btn")?document.querySelector("#"+this.element.id+"_blur").classList.remove("e-selected-btn"):document.querySelector("#"+this.element.id+"_exposure").classList.contains("e-selected-btn")&&document.querySelector("#"+this.element.id+"_exposure").classList.remove("e-selected-btn")},l.prototype.callUndo=function(){this.currObjType.isFiltered=!1,this.togglePan||this.callMainToolbar(!1,!1),0===this.zoomFactor&&(this.dragCanvas=this.togglePan=!1,this.callMainToolbar(!1,!1)),this.element.querySelector(".e-contextual-toolbar-wrapper")&&this.element.querySelector(".e-contextual-toolbar-wrapper").classList.add("e-hide"),this.togglePen&&(this.togglePen=!1,this.upperCanvas.style.cursor="default",this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height)),this.undo()},l.prototype.callRedo=function(){this.currObjType.isFiltered=!1,this.togglePan||this.callMainToolbar(!1,!1),0===this.zoomFactor&&(this.dragCanvas=this.togglePan=!1,this.callMainToolbar(!1,!1)),this.redo()},l.prototype.refreshSlider=function(){var t=document.querySelector("#"+this.element.id+"_sliderWrapper"),i=document.querySelector(".e-slider"),s=document.querySelector("#"+this.element.id+"_headWrapper");s&&(s.style.display="none"),e.isNullOrUndefined(t)||e.isNullOrUndefined(i)||(i.ej2_instances[0].destroy(),t.remove())},l.prototype.iterateObjColl=function(){for(var t=0;t<this.objColl.length;t++)this.apply(this.objColl[t].shape,this.objColl[t]),this.refreshActiveObj()},l.prototype.updateAdjustment=function(t,i,s){this.lowerContext.clearRect(0,0,this.lowerCanvas.width,this.lowerCanvas.height);var o,a,n=this.lowerContext.filter.split(" "),r=[];void 0!==n[4]&&(o=parseFloat(n[4].split("(")[1])),void 0!==n[0]&&(a=parseFloat(n[0].split("(")[1]));var h=this.getFilterValue(this.adjustmentLevel.brightness),l=this.getFilterValue(this.adjustmentLevel.saturation);if("brightness"!==t&&"contrast"!==t&&"hue"!==t&&"saturation"!==t&&"exposure"!==t&&"opacity"!==t&&"blur"!==t&&e.isNullOrUndefined(s)&&(this.adjustmentLevel.sharpen||this.adjustmentLevel.bw)){this.isUndoRedo=!0;var c=this.lowerContext.filter;this.lowerContext.filter="none",this.iterateObjColl(),this.freehandRedraw(this.lowerContext),this.lowerContext.filter=c,this.isUndoRedo=!1}1!==h&&(n[4]="opacity("+(o-.3)+")");var d,p,v,b,u;switch(t){case"brightness":100!==parseFloat(n[3].split("(")[1])&&(i+=.1),n[0]="brightness("+i+")",this.adjustmentValue=n.join(" ");break;case"contrast":n[1]="contrast("+i+"%)",this.adjustmentValue=n.join(" ");break;case"hue":n[2]="hue-rotate("+i+"deg)",this.adjustmentValue=n.join(" ");break;case"saturation":n[3]="saturate("+i+"%)",1!==l&&(n[0]="brightness("+(a+.1)+")"),this.adjustmentValue=n.join(" ");break;case"opacity":1!==parseFloat(n[0].split("(")[1])&&(i-=.2),n[4]="opacity("+i+")",this.adjustmentValue=n.join(" ");break;case"blur":n[5]="blur("+i+"px)",this.adjustmentValue=n.join(" ");break;case"exposure":1!==h&&(n[4]="opacity("+(o-.3)+")"),i>1?(i-=1,i+=h):i<1&&(i=h-(i=1-i)),n[0]="brightness("+i+")",this.adjustmentValue=n.join(" ");break;case"chrome":d=this.getSaturationFilterValue(this.adjustmentLevel.saturation),i=(d*=100)+.4*d,n[3]="saturate("+i+"%)",r=this.adjustmentValue.split(" "),n[0]=r[0],n[1]=r[1],n[2]=r[2],n[4]=r[4],n[5]=r[5],n[6]="sepia(0%)",n[7]="grayscale(0%)",n[8]="invert(0%)";break;case"cold":p=this.getFilterValue(this.adjustmentLevel.brightness),i=.9*(p*=100),n[0]="brightness("+i+"%)",b=this.getFilterValue(this.adjustmentLevel.contrast),i=(b*=100)+.5*b,n[1]="contrast("+i+"%)",u=this.getSaturationFilterValue(this.adjustmentLevel.saturation),i=u*=100,n[3]="saturate("+i+"%)",r=this.adjustmentValue.split(" "),n[2]=r[2],n[4]=r[4],n[5]=r[5],n[6]="sepia(0%)",n[7]="grayscale(0%)",n[8]="invert(0%)";break;case"warm":v=this.getSaturationFilterValue(this.adjustmentLevel.saturation),i=(v*=100)+.4*v,n[3]="saturate("+i+"%)",n[6]="sepia(25%)",r=this.adjustmentValue.split(" "),n[0]=r[0],n[1]=r[1],n[2]=r[2],n[4]=r[4],n[5]=r[5],n[7]="grayscale(0%)",n[8]="invert(0%)";break;case"grayscale":n[7]="grayscale(100%)",r=this.adjustmentValue.split(" "),n[0]=r[0],n[1]=r[1],n[2]=r[2],n[3]=r[3],n[4]=r[4],n[5]=r[5],n[6]="sepia(0%)",n[8]="invert(0%)";break;case"sepia":n[6]="sepia(100%)",r=this.adjustmentValue.split(" "),n[0]=r[0],n[1]=r[1],n[2]=r[2],n[3]=r[3],n[4]=r[4],n[5]=r[5],n[7]="grayscale(0%)",n[8]="invert(0%)";break;case"invert":n[8]="invert(100%)",r=this.adjustmentValue.split(" "),n[0]=r[0],n[1]=r[1],n[2]=r[2],n[3]=r[3],n[4]=r[4],n[5]=r[5],n[6]="sepia(0%)",n[7]="grayscale(0%)"}if("sharpen"!==t&&"blackandwhite"!==t){e.isNullOrUndefined(s)&&("default"===t&&(n=this.getDefaultCurrentFilter(n)),this.lowerContext.filter=n.join(" ")),n=this.setTempFilterValue(h,s,n,t),this.isRotateZoom=!0,this.updateCurrentTransformedState("initial"),this.lowerContext.drawImage(this.baseImg,this.srcLeft,this.srcTop,this.srcWidth,this.srcHeight,this.destLeft,this.destTop,this.destWidth,this.destHeight),this.updateCurrentTransformedState("reverse"),this.isRotateZoom=!1,1!==h?n[4]="opacity("+o+")":1!==l&&(n[0]="brightness("+a+")"),"exposure"===t&&1!==h&&(n[0]="brightness("+a+")"),"saturation"===t&&1!==l&&(n[0]="brightness("+a+")"),n=this.setTempFilterValue(h,s,n,t),e.isNullOrUndefined(s)&&(this.lowerContext.filter=this.initialAdjustmentValue=n.join(" "));var C=this.lowerContext.filter;this.lowerContext.filter=this.getDefaultFilter(),this.iterateObjColl(),this.freehandRedraw(this.lowerContext),this.lowerContext.filter=C,(!e.isNullOrUndefined(this.currSelectionPoint)&&"crop-circle"===this.currSelectionPoint.shape||this.isCircleCrop)&&this.cropCircle(this.lowerContext),this.isBrightnessAdjusted=1!==h}return n.join(" ")},l.prototype.autoEnablePan=function(){0===this.zoomFactor?(this.dragCanvas=this.togglePan=!1,this.callMainToolbar(!1,!0),this.pan(!1),this.disablePan=!1):this.disablePan?this.disablePan&&this.pan(!1):this.pan(!0)},l.prototype.setTempFilterValue=function(t,e,i,s){if(e&&1!==t){var o=this.lowerContext.filter.split(" ");o[4]=i[4],this.lowerContext.filter=o.join(" ")}else e&&"default"===s&&(i=this.getDefaultCurrentFilter(i));return i},l.prototype.getDefaultCurrentFilter=function(t){var e=this.adjustmentValue.split(" ");return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t[4]=e[4],t[5]=e[5],t[6]="sepia(0%)",t[7]="grayscale(0%)",t[8]="invert(0%)",t},l.prototype.renderSlider=function(t){var i=document.querySelector("#"+this.element.id+"_contextualToolbarArea"),s=document.querySelector("#"+this.element.id+"_headWrapper"),o=document.querySelector("#"+this.element.id+"_labelWrapper");s?s.style.display="block":o=(s=i.appendChild(this.createElement("div",{id:this.element.id+"_headWrapper",styles:"position: relative"}))).appendChild(this.createElement("label",{id:this.element.id+"_labelWrapper",styles:e.Browser.isDevice?"position: absolute; top: 25%; left: calc(50% - 150px); font-size: 15px; text-transform: capitalize; font-weight: 400;":"position: absolute; top: 25%; left: calc(50% - 226px); font-size: 15px; text-transform: capitalize; font-weight: 400;"})),o.textContent=this.l10n.getConstant(this.toPascalCase(t));var a,n,r,h=s.appendChild(this.createElement("div",{id:this.element.id+"_sliderWrapper",styles:"position: absolute"})),l=this.getCurrAdjustmentValue(t);"brightness"===t||"contrast"===t||"saturation"===t||"exposure"===t?(this.finetuneSettings?"brightness"===t&&this.finetuneSettings.brightness?(a=this.finetuneSettings.brightness.min,n=this.finetuneSettings.brightness.max):"contrast"===t&&this.finetuneSettings.contrast?(a=this.finetuneSettings.contrast.min,n=this.finetuneSettings.contrast.max):"saturation"===t&&this.finetuneSettings.saturation?(a=this.finetuneSettings.saturation.min,n=this.finetuneSettings.saturation.max):"exposure"===t&&this.finetuneSettings.exposure?(a=this.finetuneSettings.exposure.min,n=this.finetuneSettings.exposure.max):(a=-100,n=100):(a=-100,n=100),r=this.createSlider(a,n,l,t)):"hue"!==t&&"blur"!==t&&"opacity"!==t||(this.finetuneSettings?"hue"===t&&this.finetuneSettings.hue?(a=this.finetuneSettings.hue.min,n=this.finetuneSettings.hue.max):"blur"===t&&this.finetuneSettings.blur?(a=this.finetuneSettings.blur.min,n=this.finetuneSettings.blur.max):"opacity"===t&&this.finetuneSettings.opacity?(a=this.finetuneSettings.opacity.min,n=this.finetuneSettings.opacity.max):(a=0,n=100):(a=0,n=100),r=this.createSlider(a,n,l,t)),r.appendTo("#"+this.element.id+"_sliderWrapper"),h.style.left=(parseFloat(i.style.width)-parseFloat(r.width))/2+"px"},l.prototype.createSlider=function(t,i,s,a){var n=this;return new o.Slider({value:s,tooltip:{isVisible:!0,placement:"Before",showOn:"Always"},type:"MinRange",min:t,max:i,step:10,width:e.Browser.isDevice?"200px":"300px",cssClass:"e-slider",change:function(t){n.setCurrAdjustmentValue(a,t.value),n.enableDisableToolbarBtn()}})},l.prototype.getCurrAdjustmentValue=function(t){var e;switch(t){case"brightness":e=this.adjustmentLevel.brightness;break;case"contrast":e=this.adjustmentLevel.contrast;break;case"hue":e=this.adjustmentLevel.hue;break;case"saturation":e=this.adjustmentLevel.saturation;break;case"opacity":e=this.adjustmentLevel.opacity;break;case"blur":e=this.adjustmentLevel.blur;break;case"exposure":e=this.adjustmentLevel.exposure}return e},l.prototype.setCurrAdjustmentValue=function(t,e){var i={finetune:this.toPascalCase(t),value:e};switch(this.trigger("finetuneValueChanging",i),t){case"brightness":this.setBrightness(e);break;case"contrast":this.setContrast(e);break;case"hue":this.setHue(e);break;case"saturation":this.setSaturation(e);break;case"opacity":this.setOpacity(e);break;case"blur":this.setBlur(e);break;case"exposure":this.setExposure(e)}},l.prototype.cancelPan=function(){this.applyActObj();var t=this.element.querySelector(".e-img-pan .e-btn");e.isNullOrUndefined(t)||t.classList.remove("e-selected-btn"),this.pan(!1)},l.prototype.callMainToolbar=function(t,e){this.refreshToolbar("main",t,!1,e)},l.prototype.setCurrSelectionPoints=function(t){if(this.srcLeft=0,this.srcTop=0,this.srcWidth=this.baseImg.width,this.srcHeight=this.baseImg.height,this.destLeft=this.cropDestPoints.startX,this.destTop=this.cropDestPoints.startY,this.destWidth=this.cropDestPoints.width,this.destHeight=this.cropDestPoints.height,this.lowerContext.clearRect(0,0,this.lowerCanvas.width,this.lowerCanvas.height),t&&this.setDestinationPoints(),this.currentTransformedState("initial"),0!==this.croppedDegree||0!==this.degree||e.isNullOrUndefined(this.currSelectionPoint)||"crop-circle"===this.currSelectionPoint.shape||"crop-square"===this.currSelectionPoint.shape||(this.destLeft=this.cropDestPoints.startX,this.destTop=this.cropDestPoints.startY,this.destWidth=this.cropDestPoints.width,this.destHeight=this.cropDestPoints.height),0===this.degree&&(this.destLeft+=this.totalPannedInternalPoint.x,this.destTop+=this.totalPannedInternalPoint.y),this.updateBrightnessFilter(),this.lowerContext.drawImage(this.baseImg,this.srcLeft,this.srcTop,this.srcWidth,this.srcHeight,this.destLeft,this.destTop,this.destWidth,this.destHeight),this.currentTransformedState("reverse",null,null,!0),e.isNullOrUndefined(this.cropObj.activeObj.shape)){var i=this.lowerContext.filter;this.lowerContext.filter="none",this.iterateObjColl(),this.freehandRedraw(this.lowerContext),this.lowerContext.filter=i}else this.setCropObj();this.currSelectionPoint=null},l.prototype.updateObjAndFreeHandDrawColl=function(){for(var t=0;t<this.objColl.length;t++)this.objColl[t].imageRatio={startX:(this.objColl[t].activePoint.startX-this.destLeft)/this.destWidth,startY:(this.objColl[t].activePoint.startY-this.destTop)/this.destHeight,endX:(this.objColl[t].activePoint.endX-this.destLeft)/this.destWidth,endY:(this.objColl[t].activePoint.endY-this.destTop)/this.destHeight,width:this.destWidth/this.objColl[t].activePoint.width,height:this.destHeight/this.objColl[t].activePoint.height},this.refreshActiveObj();for(var i=0;i<this.freehandCounter;i++){this.points=e.extend([],this.pointColl[i].points,[]),this.pointCounter=0;for(var s=this.points.length,o=0;o<s;o++)this.points[o].ratioX=(this.points[o].x-this.destLeft)/this.destWidth,this.points[o].ratioY=(this.points[o].y-this.destTop)/this.destHeight}},l.prototype.cancelItems=function(){var t,i=!1;if(void 0!==this.activeObj.shape&&(t=this.activeObj.shape.split("-")),void 0===t&&this.currObjType.isCustomCrop?i=!0:void 0!==t&&"crop"===t[0]&&(i=!0),i&&this.isCropTab&&(this.isCropTab=!1,this.zoomFactor=this.defaultZoomFactor),this.togglePen){this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),this.togglePen=!1,this.upperCanvas.style.cursor="default";var s=e.extend([],this.pointColl,[],!0);this.pointColl={};for(var o=0;o<this.tempFreehandCounter;o++)this.pointColl[o]=s[o];this.freehandCounter=this.tempFreehandCounter,this.currentFreehandDrawIndex=this.tempCurrentFreehandDrawIndex}else if("text"===this.activeObj.shape)e.isNullOrUndefined(this.activeObj.currIndex)?(this.refreshActiveObj(),this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height)):(this.activeObj.strokeSettings=this.tempStrokeSettings,this.activeObj.textSettings=this.tempTextSettings,"Enter Text"===this.activeObj.keyHistory&&this.activeObj.activePoint.startX===this.textStartPoints.x&&this.activeObj.activePoint.startY===this.textStartPoints.y?(this.refreshActiveObj(),this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),this.textSettings=this.tempTextSettings,this.strokeSettings=this.tempStrokeSettings,this.drawShapeText(),this.applyActObj()):(this.redrawText(),this.redrawShape(this.activeObj),i||void 0===this.activeObj.topLeftCircle||this.applyActObj(),this.clearSelection())),this.tempTextSettings={text:"Enter Text",fontFamily:"Arial",fontSize:null,fontRatio:null,bold:!1,italic:!1,underline:!1};else if("rectangle"===this.activeObj.shape||"ellipse"===this.activeObj.shape||"line"===this.activeObj.shape)e.isNullOrUndefined(this.activeObj.currIndex)?(this.refreshActiveObj(),this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height)):(this.activeObj.strokeSettings=this.tempStrokeSettings,this.redrawShape(this.activeObj),this.applyActObj());else if(this.zoomFactor!==this.tempZoomFactor||i&&e.isNullOrUndefined(this.currSelectionPoint)){var a=this.cropZoomFactor-this.tempZoomFactor;if(this.zoomFactor=this.cropZoomFactor,e.isNullOrUndefined(this.cropObj.activeObj.shape)&&(0===this.degree&&0===this.totalPannedPoint.x&&0===this.totalPannedPoint.y||0!==this.degree&&0===this.totalPannedInternalPoint.x&&0===this.totalPannedInternalPoint.y&&0===this.totalPannedClientPoint.x&&0===this.totalPannedClientPoint.y))return this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),this.refreshActiveObj(),a>0?this.zoom(-a):this.zoom(Math.abs(a)),this.cropZoomFactor=this.tempZoomFactor,this.currObjType.isCustomCrop=!1,this.upperCanvas.style.cursor="default",this.currObjType.isCustomCrop=!1,this.tempStrokeSettings={strokeColor:"#fff",fillColor:"",strokeWidth:null},void this.callMainToolbar();if(e.isNullOrUndefined(this.cropObj.activeObj.shape)){if(0===this.degree){var n=e.extend({},this.activeObj,{});this.destLeft+=-this.totalPannedPoint.x,this.destTop+=-this.totalPannedPoint.y,this.drawPannImage({x:-this.totalPannedPoint.x,y:-this.totalPannedPoint.y},this.getCurrentPanRegion()),this.updateFlipPan(n),this.totalPannedPoint={x:0,y:0}}else this.totalPannedClientPoint={x:-this.totalPannedClientPoint.x,y:-this.totalPannedClientPoint.y},this.totalPannedInternalPoint={x:-this.totalPannedInternalPoint.x,y:-this.totalPannedInternalPoint.y},this.rotatePan(!0),this.totalPannedClientPoint={x:0,y:0},this.totalPannedInternalPoint={x:0,y:0},this.currentPannedPoint={x:0,y:0};this.refreshActiveObj(),this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),a>0?this.zoom(-a):this.zoom(Math.abs(a))}else{this.isCancelAction=!0,this.objColl=[],this.pointColl=[];var r=this.freehandCounter;this.freehandCounter=0;var h=e.extend({},this.cropObj,{}),l=e.extend([],this.afterCropActions,{},!0);this.setCropObj(),this.cropImg(),this.cropObj=h,this.afterCropActions=l,this.objColl=e.extend([],this.cancelObjColl,[],!0),this.pointColl=e.extend([],this.cancelPointColl,[],!0),this.freehandCounter=r,this.iterateObjColl(),this.freehandRedraw(this.lowerContext),this.clearOuterCanvas(this.lowerContext),this.isCircleCrop&&this.cropCircle(this.lowerContext),this.isCancelAction=!1}this.zoomFactor=this.defaultZoomFactor,this.enableDisableToolbarBtn()}else this.refreshActiveObj(),this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height);this.upperCanvas.style.cursor="default",this.currObjType.isCustomCrop=!1,this.tempStrokeSettings={strokeColor:"#fff",fillColor:"",strokeWidth:null},this.callMainToolbar()},l.prototype.freehandDownHandler=function(t,i){this.freehandDrawObj.time=(new Date).getTime(),this.isFreehandDrawing=!0,"mousedown"===t.type?this.freehandDownPoint={x:t.clientX,y:t.clientY}:this.freehandDownPoint={x:t.touches[0].clientX,y:t.touches[0].clientY},this.isFreehandPointMoved=!1,e.EventHandler.add(i,"mousemove touchmove",this.freehandMoveHandler,this)},l.prototype.freehandUpHandler=function(t,i,s){var o=i.getBoundingClientRect();e.EventHandler.remove(i,"mousemove touchmove",this.freehandMoveHandler),0===this.points.length&&("mouseup"===t.type?this.processPoint(t.clientX-o.left,t.clientY-o.top,!0,s):this.isFreehandPointMoved||this.processPoint(this.freehandDownPoint.x-o.left,this.freehandDownPoint.y-o.top,!0,s)),s.closePath(),this.pointColl[this.freehandCounter]={},this.pointColl[this.freehandCounter].points=e.extend([],this.points),this.pointColl[this.freehandCounter].strokeColor=this.activeObj.strokeSettings.strokeColor,this.pointColl[this.freehandCounter].strokeWidth=this.penStrokeWidth,this.pointColl[this.freehandCounter].flipState=this.currFlipState,this.pointColl[this.freehandCounter].id="pen_"+(this.currentFreehandDrawIndex+1),this.points=[],this.pointCounter=0,this.freehandCounter++,this.currentFreehandDrawIndex++,this.isFreehandDrawing=!1;var a=e.extend([],this.pointColl,[],!0);this.pointColl={};for(var n=0;n<this.freehandCounter-1;n++)this.pointColl[n]=a[n];var r=e.extend([],this.pointColl,[],!0);this.updateUndoRedoColl("freehanddraw",null,r,a,this.zoomFactor),this.pointColl=a},l.prototype.freehandMoveHandler=function(t){this.isFreehandPointMoved=!0;var e,i,s=this.upperCanvas.getBoundingClientRect();"mousemove"===t.type?(e=t.clientX-s.left,i=t.clientY-s.top):(e=t.touches[0].clientX-s.left,i=t.touches[0].clientY-s.top),this.isFreehandDrawing&&this.processPoint(e,i,!1,this.upperContext)},l.prototype.processPoint=function(t,i,s,o){var a,n,r,h,l=this.point(t,i,(new Date).getTime()),c=!!(l=this.points.length>0&&this.points[this.points.length-1])&&this.distanceTo(l)<=5;if(!l||!l||!c||s){if(this.freehandDrawObj.time=(new Date).getTime(),this.points.push({x:t,y:i,ratioX:(t-this.destLeft)/this.destWidth,ratioY:(i-this.destTop)/this.destHeight,time:this.freehandDrawObj.time}),this.points.length>3){a=this.calcCurveControlPoints(this.points[this.pointCounter+0],this.points[this.pointCounter+1],this.points[this.pointCounter+2]).controlPoint2,n=this.calcCurveControlPoints(this.points[this.pointCounter+1],this.points[this.pointCounter+2],this.points[this.pointCounter+3]).controlPoint1,r=this.points[this.pointCounter+1],h=this.points[this.pointCounter+2];var d=.5,p=5;e.isNullOrUndefined(this.penStrokeWidth)||(d=p=this.penStrokeWidth),this.startDraw(o,a,n,r,h,d,p),this.pointCounter++}if(s){a=n=r=h={x:t,y:i,time:(new Date).getTime()};var d=.5,p=5;e.isNullOrUndefined(this.penStrokeWidth)||(d=p=this.penStrokeWidth),this.startDraw(o,a,n,r,h,d,p)}}},l.prototype.calcCurveControlPoints=function(t,e,i){e||(e=t),i||(i=e);var s=t.x-e.x,o=t.y-e.y,a=e.x-i.x,n=e.y-i.y,r={x:(t.x+e.x)/2,y:(t.y+e.y)/2},h={x:(e.x+i.x)/2,y:(e.y+i.y)/2},l=Math.sqrt(s*s+o*o),c=Math.sqrt(a*a+n*n),d=r.x-h.x,p=r.y-h.y,v=c/(l+c),b={x:h.x+d*v,y:h.y+p*v},u=e.x-b.x,C=e.y-b.y;return{controlPoint1:this.point(r.x+u,r.y+C,0),controlPoint2:this.point(h.x+u,h.y+C,0)}},l.prototype.point=function(t,e,i){return this.freehandDrawObj.pointX=t,this.freehandDrawObj.pointY=e,{x:this.freehandDrawObj.pointX,y:this.freehandDrawObj.pointY,time:i}},l.prototype.startDraw=function(t,e,i,s,o,a,n){var r;r=.7*(r=this.pointVelocity(s))+(1-.7)*this.freehandDrawObj.lastVelocity;var h=Math.max(n/1.7,a);this.drawCurve(this.freehandDrawObj.time,h,t,e,i,s,o,n),this.freehandDrawObj.lastVelocity=r,this.freehandDrawObj.time=h},l.prototype.pointVelocity=function(t){return this.freehandDrawObj.time!==t.time?this.distanceTo(t)/(this.freehandDrawObj.time-t.time):0},l.prototype.distanceTo=function(t){return Math.sqrt(Math.pow(this.freehandDrawObj.pointX-t.x,2)+Math.pow(this.freehandDrawObj.pointY-t.y,2))},l.prototype.drawCurve=function(t,e,i,s,o,a,n,r){var h,l,c,d,p,v,b,u,C,f,g=e-t,j=this.bezierLength(s,o,a,n),O=2*Math.ceil(j);for(i.beginPath(),l=0;l<O;l++)p=(d=(c=l/O)*c)*c,C=(u=(b=(v=1-c)*v)*v)*a.x,C+=3*b*c*s.x,C+=3*v*d*o.x,C+=p*n.x,f=u*a.y,f+=3*b*c*s.y,f+=3*v*d*o.y,f+=p*n.y,h=Math.min(t+p*g,r),this.drawArc(C,f,h,i);i.closePath(),i.fill()},l.prototype.bezierLength=function(t,e,i,s){var o,a,n,r,h,l,c,d,p=0;for(o=0;o<=10;o++)a=o/10,n=this.bezierPoint(a,i.x,t.x,e.x,s.x),r=this.bezierPoint(a,i.y,t.y,e.y,s.y),o>0&&(c=n-h,d=r-l,p+=Math.sqrt(c*c+d*d)),h=n,l=r;return p},l.prototype.bezierPoint=function(t,e,i,s,o){return e*(1-t)*(1-t)*(1-t)+3*i*(1-t)*(1-t)*t+3*s*(1-t)*t*t+o*t*t*t},l.prototype.drawArc=function(t,e,i,s){(t>this.destLeft&&e>this.destTop&&t<this.destLeft+this.destWidth&&e<this.destTop+this.destHeight||s!==this.lowerContext&&s!==this.upperContext)&&(s.moveTo(t,e),s.arc(t,e,i,0,2*Math.PI,!1))},l.prototype.freehandRedraw=function(t,i){var s=t.filter;t.filter="none",e.isNullOrUndefined(i)||(this.pointColl[this.freehandCounter]={},this.pointColl[this.freehandCounter].points=i,this.pointColl[this.freehandCounter].strokeColor=this.activeObj.strokeSettings.strokeColor,this.pointColl[this.freehandCounter].strokeWidth=this.penStrokeWidth,this.pointColl[this.freehandCounter].flipState=this.currFlipState,this.freehandCounter++);for(var o=0;o<this.freehandCounter;o++){this.points=e.extend([],this.pointColl[o].points),this.pointCounter=0;var a=this.points.length,n=void 0,r=void 0,h=void 0,l=void 0,c=void 0,d=void 0;a>0&&(t.fillStyle=this.pointColl[o].strokeColor,c=d=this.penStrokeWidth=this.pointColl[o].strokeWidth),1===a&&(n=r=h=l=this.points[0],this.startDraw(t,n,r,h,l,c,d));for(var p=0;p<a-3;p++)this.points[p+1]&&this.points[p+2]&&this.points[p+2]&&(n=this.calcCurveControlPoints(this.points[p+0],this.points[p+1],this.points[p+2]).controlPoint2,r=this.calcCurveControlPoints(this.points[p+1],this.points[p+2],this.points[p+3]).controlPoint1,h=this.points[p+1],l=this.points[p+2],this.startDraw(t,n,r,h,l,c,d));t.closePath()}t.filter=s},l.prototype.redrawImgWithObj=function(){this.lowerContext.filter=this.canvasFilter,this.getCurrentFlipState(),this.isCircleCrop&&this.cropCircle(this.lowerContext);var t=this.lowerContext.filter;this.lowerContext.filter=this.getDefaultFilter(),this.iterateObjColl(),this.freehandRedraw(this.lowerContext),this.lowerContext.filter=t},l.prototype.refreshToolbar=function(t,i,s,o,a){if(this.isImageLoaded){var n={toolbarType:t};switch("filter"!==t&&"color"!==t&&(document.getElementById(this.element.id+"_toolbar")&&this.defToolbarItems.length>0&&e.getComponent(document.getElementById(this.element.id+"_toolbar"),"toolbar").destroy(),document.getElementById(this.element.id+"_bottomToolbar")&&this.defToolbarItems.length>0&&document.getElementById(this.element.id+"_bottomToolbar").className.indexOf("e-control")>-1&&e.getComponent(document.getElementById(this.element.id+"_bottomToolbar"),"toolbar").destroy()),this.refreshSlider(),t){case"main":e.Browser.isDevice?s?this.initToolbarItem(!1,!0,!0):this.initToolbarItem(!1,!0,null):e.Browser.isDevice&&!o||this.initToolbarItem(i,e.Browser.isDevice,null),e.Browser.isDevice&&this.initBottomToolbar();break;case"shapes":e.Browser.isDevice&&this.initToolbarItem(!1,!0,!0),"line"===this.activeObj.shape?n.toolbarItems=["strokeColor","strokeWidth"]:n.toolbarItems=["fillColor","strokeColor","strokeWidth"],this.trigger("toolbarUpdating",n),this.initShapesToolbarItem(n.toolbarItems);break;case"text":e.Browser.isDevice&&this.initToolbarItem(!1,!0,!0),n.toolbarItems=["fontFamily","fontStyle","fontSize","fontColor"],this.trigger("toolbarUpdating",n),this.initTextToolbarItem(n.toolbarItems);break;case"pen":e.Browser.isDevice&&this.initToolbarItem(!1,!0,!0),n.toolbarItems=["strokeColor","strokeWidth"],this.trigger("toolbarUpdating",n),this.initPenToolbarItem(n.toolbarItems);break;case"pan":this.initZoomToolbarItem();break;case"adjustment":e.Browser.isDevice&&this.initToolbarItem(!1,!0,!0),this.initAdjustmentToolbarItem();break;case"filter":this.updateContextualToolbar(t);break;case"color":this.updateContextualToolbar(t,a)}this.refreshDropDownBtn(s)}},l.prototype.getAdjustmentToolbarItem=function(){var t=[];(e.isNullOrUndefined(this.toolbar)||!e.isNullOrUndefined(this.toolbar)&&this.toolbar.indexOf("Brightness")>-1)&&t.push({id:this.element.id+"_brightness",prefixIcon:"e-icons e-brightness",cssClass:"top-icon e-brightness",tooltipText:this.l10n.getConstant("Brightness"),align:"Center"}),(e.isNullOrUndefined(this.toolbar)||!e.isNullOrUndefined(this.toolbar)&&this.toolbar.indexOf("Contrast")>-1)&&t.push({id:this.element.id+"_contrast",prefixIcon:"e-icons e-contrast",cssClass:"top-icon e-contrast",tooltipText:this.l10n.getConstant("Contrast"),align:"Center"}),(e.isNullOrUndefined(this.toolbar)||!e.isNullOrUndefined(this.toolbar)&&this.toolbar.indexOf("Hue")>-1)&&t.push({id:this.element.id+"_hue",prefixIcon:"e-icons e-fade",cssClass:"top-icon e-fade",tooltipText:this.l10n.getConstant("Hue"),align:"Center"}),(e.isNullOrUndefined(this.toolbar)||!e.isNullOrUndefined(this.toolbar)&&this.toolbar.indexOf("Saturation")>-1)&&t.push({id:this.element.id+"_saturation",prefixIcon:"e-icons e-saturation",cssClass:"top-icon e-saturation",tooltipText:this.l10n.getConstant("Saturation"),align:"Center"}),(e.isNullOrUndefined(this.toolbar)||!e.isNullOrUndefined(this.toolbar)&&this.toolbar.indexOf("Exposure")>-1)&&t.push({id:this.element.id+"_exposure",prefixIcon:"e-icons e-grain",cssClass:"top-icon e-grain",tooltipText:this.l10n.getConstant("Exposure"),align:"Center"}),(e.isNullOrUndefined(this.toolbar)||!e.isNullOrUndefined(this.toolbar)&&this.toolbar.indexOf("Opacity")>-1)&&t.push({id:this.element.id+"_opacity",prefixIcon:"e-icons e-opacity",cssClass:"top-icon e-opacity",tooltipText:this.l10n.getConstant("Opacity"),align:"Center"}),(e.isNullOrUndefined(this.toolbar)||!e.isNullOrUndefined(this.toolbar)&&this.toolbar.indexOf("Blur")>-1)&&t.push({id:this.element.id+"_blur",prefixIcon:"e-icons e-tint",cssClass:"top-icon e-tint",tooltipText:this.l10n.getConstant("Blur"),align:"Center"});for(var i=this.processToolbar("center"),s=0,o=i.length;s<o;s++)t.push(i[s]);return e.Browser.isDevice||(t.push({id:this.element.id+"_ok",prefixIcon:"e-icons e-check",cssClass:"top-icon e-tick",tooltipText:this.l10n.getConstant("OK"),align:"Right"}),t.push({id:this.element.id+"_cancel",prefixIcon:"e-icons e-close",cssClass:"top-icon e-save",tooltipText:this.l10n.getConstant("Cancel"),align:"Right"})),t},l.prototype.getFilterToolbarItem=function(){var t=[];(e.isNullOrUndefined(this.toolbar)||!e.isNullOrUndefined(this.toolbar)&&this.toolbar.indexOf("Default")>-1)&&t.push({id:this.element.id+"_default",prefixIcon:"e-icons e-none",cssClass:"top-icon e-none",tooltipText:this.l10n.getConstant("Default"),align:"Center",template:'<div class="filterwrapper" style="box-sizing: content-box;"><canvas id='+this.element.id+'_defaultCanvas></canvas><div style="text-align:center;"><span>'+this.l10n.getConstant("Default")+"</span></div></div>"}),(e.isNullOrUndefined(this.toolbar)||!e.isNullOrUndefined(this.toolbar)&&this.toolbar.indexOf("Chrome")>-1)&&t.push({id:this.element.id+"_chrome",prefixIcon:"e-icons e-none",cssClass:"top-icon e-none",tooltipText:this.l10n.getConstant("Chrome"),align:"Center",template:'<div class="filterwrapper" style="box-sizing: content-box;"><canvas id='+this.element.id+'_chromeCanvas></canvas><div style="text-align:center;"><span>'+this.l10n.getConstant("Chrome")+"</span></div></div>"}),(e.isNullOrUndefined(this.toolbar)||!e.isNullOrUndefined(this.toolbar)&&this.toolbar.indexOf("Cold")>-1)&&t.push({id:this.element.id+"_cold",prefixIcon:"e-icons e-none",cssClass:"top-icon e-none",tooltipText:this.l10n.getConstant("Cold"),align:"Center",template:'<div class="filterwrapper" style="box-sizing: content-box;"><canvas id='+this.element.id+'_coldCanvas></canvas><div style="text-align:center;"><span>'+this.l10n.getConstant("Cold")+"</span></div></div>"}),(e.isNullOrUndefined(this.toolbar)||!e.isNullOrUndefined(this.toolbar)&&this.toolbar.indexOf("Warm")>-1)&&t.push({id:this.element.id+"_warm",prefixIcon:"e-icons e-none",cssClass:"top-icon e-none",tooltipText:this.l10n.getConstant("Warm"),align:"Center",template:'<div class="filterwrapper" style="box-sizing: content-box;"><canvas id='+this.element.id+'_warmCanvas></canvas><div style="text-align:center;"><span>'+this.l10n.getConstant("Warm")+"</span></div></div>"}),(e.isNullOrUndefined(this.toolbar)||!e.isNullOrUndefined(this.toolbar)&&this.toolbar.indexOf("Grayscale")>-1)&&t.push({id:this.element.id+"_grayscale",prefixIcon:"e-icons e-none",cssClass:"top-icon e-none",tooltipText:this.l10n.getConstant("Grayscale"),align:"Center",template:'<div class="filterwrapper" style="box-sizing: content-box;"><canvas id='+this.element.id+'_grayscaleCanvas></canvas><div style="text-align:center;"><span>'+this.l10n.getConstant("Grayscale")+"</span></div></div>"}),(e.isNullOrUndefined(this.toolbar)||!e.isNullOrUndefined(this.toolbar)&&this.toolbar.indexOf("Sepia")>-1)&&t.push({id:this.element.id+"_sepia",prefixIcon:"e-icons e-none",cssClass:"top-icon e-none",tooltipText:this.l10n.getConstant("Sepia"),align:"Center",template:'<div class="filterwrapper" style="box-sizing: content-box;"><canvas id='+this.element.id+'_sepiaCanvas></canvas><div style="text-align:center;"><span>'+this.l10n.getConstant("Sepia")+"</span></div></div>"}),(e.isNullOrUndefined(this.toolbar)||!e.isNullOrUndefined(this.toolbar)&&this.toolbar.indexOf("Invert")>-1)&&t.push({id:this.element.id+"_invert",prefixIcon:"e-icons e-none",cssClass:"top-icon e-none",tooltipText:this.l10n.getConstant("Invert"),align:"Center",template:'<div class="filterwrapper" style="box-sizing: content-box;"><canvas id='+this.element.id+'_invertCanvas></canvas><div style="text-align:center;"><span>'+this.l10n.getConstant("Invert")+"</span></div></div>"});for(var i=this.processToolbar("center"),s=0,o=i.length;s<o;s++)t.push(i[s]);return t},l.prototype.getPenToolbarItem=function(t){var i=[];t.indexOf("strokeColor")>-1&&i.push({prefixIcon:"e-icons e-copy",id:this.element.id+"_pen_strokecolor",cssClass:"top-icon e-pen-stroke-color",tooltipText:this.l10n.getConstant("StrokeColor"),align:"Center",type:"Input",template:'<button id="'+this.element.id+'_penColorBtn"></button>'}),t.indexOf("strokeWidth")>-1&&i.push({prefixIcon:"e-icons e-copy",cssClass:"top-icon e-size",tooltipText:this.l10n.getConstant("StrokeWidth"),align:"Center",type:"Input",template:'<button id="'+this.element.id+'_penStrokeWidth"></button>'});for(var s=this.processSubToolbar(t),o=0,a=s.length;o<a;o++)i.push(s[o]);return e.Browser.isDevice||(i.push({id:this.element.id+"_ok",prefixIcon:"e-icons e-check",cssClass:"top-icon e-tick",tooltipText:this.l10n.getConstant("OK"),align:"Right"}),i.push({id:this.element.id+"_cancel",prefixIcon:"e-icons e-close",cssClass:"top-icon e-save",tooltipText:this.l10n.getConstant("Cancel"),align:"Right"})),i},l.prototype.initPenToolbarItem=function(t){var s=this,o=this.getLeftToolbarItem(),a=this.getRightToolbarItem(),n=this.getPenToolbarItem(t),r=this.getZoomToolbarItem();e.Browser.isDevice?this.defToolbarItems=n:this.defToolbarItems=o.concat(r,n,a);var h=new i.Toolbar({width:"100%",items:this.defToolbarItems,clicked:this.defToolbarClicked.bind(this),created:function(){s.createPenColor(t),s.createPenBtn(t),e.Browser.isDevice||s.renderSaveBtn(),s.trigger("toolbarCreated",{toolbarType:"pen"}),e.Browser.isDevice?s.defToolbarItems.length>0&&!e.isNullOrUndefined(document.getElementById(s.element.id+"_toolbar"))&&h.refreshOverflow():(s.createLeftToolbarControls(),s.defToolbarItems.length>0&&!e.isNullOrUndefined(document.getElementById(s.element.id+"_toolbar"))&&h.refreshOverflow())}});e.Browser.isDevice?h.appendTo("#"+this.element.id+"_bottomToolbar"):h.appendTo("#"+this.element.id+"_toolbar"),this.enableDisableToolbarBtn()},l.prototype.createPenColor=function(t){var i=this,a=this;if(t.indexOf("strokeColor")>-1){this.element.querySelector(".e-template.e-pen-stroke-color").appendChild(this.createElement("input",{id:this.element.id+"_pen_stroke"}));var n=new o.ColorPicker({modeSwitcher:!1,value:"#fff",showButtons:!1,mode:"Palette",cssClass:"e-pen-color",change:function(t){var s=e.extend([],i.pointColl,[],!0);i.updateFreehandDrawColorChange();var o=e.extend([],i.pointColl,[],!0);i.pointColl=s,a.isFreehandDrawCustomized=!0,a.activeObj.strokeSettings.strokeColor=a.selectedFreehandColor=t.currentValue.hex,i.isFreehandDrawEditing?(i.upperContext.clearRect(0,0,i.upperCanvas.width,i.upperCanvas.height),i.pointColl[i.freehandDrawSelectedIndex].strokeColor=t.currentValue.hex,i.hoverFreehandraw(t.currentValue.hex),i.updateUndoRedoColl("freehanddrawCustomized",null,o,i.pointColl,i.zoomFactor)):a.togglePen||a.redrawShape(i.activeObj),r.element.children[0].style.backgroundColor=t.currentValue.rgba,r.toggle()}},"#"+this.element.id+"_pen_stroke"),r=new s.DropDownButton({open:function(t){e.Browser.isDevice&&(t.element.parentElement.style.top=r.element.getBoundingClientRect().top-t.element.parentElement.offsetHeight+"px",t.element.parentElement.style.left=i.element.offsetLeft+"px")},target:".e-pen-color",iconCss:"e-dropdownbtn-preview"},"#"+this.element.id+"_penColorBtn");n.inline=!0,!e.isNullOrUndefined(this.freehandDrawSelectedIndex)&&this.freehandDrawSelectedIndex>-1?this.element.querySelector(".e-pen-stroke-color.e-template .e-dropdownbtn-preview").style.background="#42a5f5"===this.selectedFreehandColor?this.tempFreeHandDrawEditingStyles.strokeColor:this.pointColl[this.freehandDrawSelectedIndex].strokeColor:this.element.querySelector(".e-pen-stroke-color.e-template .e-dropdownbtn-preview").style.background="#fff"}},l.prototype.createPenBtn=function(t){var i=this,o=[{id:"1",text:this.l10n.getConstant("XSmall")},{id:"2",text:this.l10n.getConstant("Small")},{id:"3",text:this.l10n.getConstant("Medium")},{id:"4",text:this.l10n.getConstant("Large")},{id:"5",text:this.l10n.getConstant("XLarge")}];if(t.indexOf("strokeWidth")>-1){var a=document.getElementById(this.element.id+"_penStrokeWidth"),n=document.createElement("span");!e.isNullOrUndefined(this.freehandDrawSelectedIndex)&&this.freehandDrawSelectedIndex>-1?n.innerHTML=this.getPenStroke(this.pointColl[this.freehandDrawSelectedIndex].strokeWidth):n.innerHTML=this.l10n.getConstant("Small"),n.className="e-pen-stroke-width",a.appendChild(n);var r=new s.DropDownButton({items:o,open:function(t){e.Browser.isDevice&&(t.element.parentElement.style.top=r.element.getBoundingClientRect().top-t.element.parentElement.offsetHeight+"px");var i=n.innerHTML;t.element.querySelector('[aria-label = "'+i+'"]').classList.add("e-selected-btn")},select:function(t){var s=e.extend([],i.pointColl,[],!0);i.updateFreehandDrawColorChange();var o=e.extend([],i.pointColl,[],!0);i.pointColl=s,i.isFreehandDrawCustomized=!0,n.textContent=t.item.text,i.setPenStroke(t.item.id),i.isFreehandDrawEditing&&(i.upperContext.clearRect(0,0,i.upperCanvas.width,i.upperCanvas.height),i.hoverFreehandraw(null,i.penStrokeWidth),i.pointColl[i.freehandDrawSelectedIndex].strokeWidth=i.penStrokeWidth,i.updateUndoRedoColl("freehanddrawCustomized",null,o,i.pointColl,i.zoomFactor)),e.Browser.isDevice?e.isNullOrUndefined(document.getElementById(i.element.id+"_bottomToolbar"))||e.getComponent(i.element.id+"_bottomToolbar","toolbar").refreshOverflow():e.isNullOrUndefined(document.getElementById(i.element.id+"_toolbar"))||e.getComponent(i.element.id+"_toolbar","toolbar").refreshOverflow()}});r.appendTo("#"+this.element.id+"_penStrokeWidth")}},l.prototype.updateFreehandDrawColorChange=function(){e.isNullOrUndefined(this.freehandDrawSelectedIndex)||e.isNullOrUndefined(this.pointColl[this.freehandDrawSelectedIndex])||"#42a5f5"!==this.pointColl[this.freehandDrawSelectedIndex].strokeColor||(this.pointColl[this.freehandDrawSelectedIndex].strokeColor=this.tempFreeHandDrawEditingStyles.strokeColor)},l.prototype.setPenStroke=function(t){switch(parseInt(t,10)){case 1:this.penStrokeWidth=1;break;case 2:this.penStrokeWidth=2;break;case 3:this.penStrokeWidth=3;break;case 4:this.penStrokeWidth=4;break;case 5:this.penStrokeWidth=5}},l.prototype.getPenStroke=function(t){var e="";return 1===t?e=this.l10n.getConstant("XSmall"):2===t?e=this.l10n.getConstant("Small"):3===t?e=this.l10n.getConstant("Medium"):4===t?e=this.l10n.getConstant("Large"):5===t&&(e=this.l10n.getConstant("XLarge")),e},l.prototype.initAdjustmentToolbarItem=function(){var t=this,s=this.getLeftToolbarItem(null),o=this.getRightToolbarItem(),a=this.getAdjustmentToolbarItem(),n=this.getZoomToolbarItem();e.Browser.isDevice?this.defToolbarItems=a:this.defToolbarItems=s.concat(n,a,o);var r=new i.Toolbar({width:"100%",items:this.defToolbarItems,clicked:this.defToolbarClicked.bind(this),created:function(){e.Browser.isDevice||t.renderSaveBtn(),e.Browser.isDevice?t.defToolbarItems.length>0&&!e.isNullOrUndefined(document.getElementById(t.element.id+"_toolbar"))&&r.refreshOverflow():(t.createLeftToolbarControls(),t.defToolbarItems.length>0&&!e.isNullOrUndefined(document.getElementById(t.element.id+"_toolbar"))&&r.refreshOverflow())}});e.Browser.isDevice?r.appendTo("#"+this.element.id+"_bottomToolbar"):r.appendTo("#"+this.element.id+"_toolbar"),this.enableDisableToolbarBtn()},l.prototype.initFilterToolbarItem=function(){var t=this,s=this.getFilterToolbarItem();document.querySelector("#"+this.element.id+"_contextualToolbar").classList.contains("e-control")&&e.getComponent(document.getElementById(this.element.id+"_contextualToolbar"),"toolbar").destroy();var o=new i.Toolbar({width:"100%",items:s,clicked:this.contextualToolbarClicked.bind(this),created:function(){t.createCanvasFilter(),""===t.currentFilter&&(t.currentFilter=t.element.id+"_default");var e=document.querySelector("#"+t.element.id+"_headWrapper");e&&(e.style.display="none"),document.getElementById(t.currentFilter+"Canvas").parentElement.parentElement.classList.add("e-selected"),t.enableDisableToolbarBtn(),o.refreshOverflow()}});o.appendTo("#"+this.element.id+"_contextualToolbar")},l.prototype.getCurrentCanvasData=function(){var t=this.lowerContext.filter;this.lowerContext.filter="none";var i=e.extend([],this.objColl,null,!0);this.objColl=[],this.renderImage();var s=this.lowerContext.getImageData(this.destLeft,this.destTop,this.destWidth,this.destHeight);return this.objColl=i,this.iterateObjColl(),this.lowerContext.filter=t,s},l.prototype.createCanvasFilter=function(){var t=this.getCurrentCanvasData();this.inMemoryCanvas.width=t.width,this.inMemoryCanvas.height=t.height,this.inMemoryContext.putImageData(t,0,0);var e=document.querySelector("#"+this.element.id+"_defaultCanvas"),i=e.getContext("2d");e.style.width="100px",e.style.height="100px",i.filter=this.updateAdjustment("default",null,!0),i.drawImage(this.inMemoryCanvas,0,0,300,150);var s=document.querySelector("#"+this.element.id+"_chromeCanvas");i=s.getContext("2d"),s.style.width="100px",s.style.height="100px",i.filter=this.updateAdjustment("chrome",null,!0),i.drawImage(this.inMemoryCanvas,0,0,300,150);var o=document.querySelector("#"+this.element.id+"_coldCanvas");i=o.getContext("2d"),o.style.width="100px",o.style.height="100px",i.filter=this.updateAdjustment("cold",null,!0),i.drawImage(this.inMemoryCanvas,0,0,300,150);var a=document.querySelector("#"+this.element.id+"_warmCanvas");i=a.getContext("2d"),a.style.width="100px",a.style.height="100px",i.filter=this.updateAdjustment("warm",null,!0),i.drawImage(this.inMemoryCanvas,0,0,300,150);var n=document.querySelector("#"+this.element.id+"_grayscaleCanvas");i=n.getContext("2d"),n.style.width="100px",n.style.height="100px",i.filter=this.updateAdjustment("grayscale",null,!0),i.drawImage(this.inMemoryCanvas,0,0,300,150);var r=document.querySelector("#"+this.element.id+"_sepiaCanvas");i=r.getContext("2d"),r.style.width="100px",r.style.height="100px",i.filter=this.updateAdjustment("sepia",null,!0),i.drawImage(this.inMemoryCanvas,0,0,300,150);var h=document.querySelector("#"+this.element.id+"_invertCanvas");i=h.getContext("2d"),h.style.width="100px",h.style.height="100px",i.filter=this.updateAdjustment("invert",null,!0),i.drawImage(this.inMemoryCanvas,0,0,300,150)},l.prototype.callUpdateCurrentTransformedState=function(){var t=e.extend([],this.objColl,[],!0),i=e.extend({},this.activeObj,{},!0);this.objColl=[],this.refreshActiveObj(),this.isRotateZoom=!0,this.updateCurrentTransformedState("initial"),0===this.degree&&this.rotateFlipColl.length>0&&(this.destLeft+=this.totalPannedPoint.x,this.destTop+=this.totalPannedPoint.y),this.destLeft+=this.totalPannedInternalPoint.x,this.destTop+=this.totalPannedInternalPoint.y;var s=this.lowerContext.filter;this.updateBrightnessFilter(),this.lowerContext.drawImage(this.baseImg,this.srcLeft,this.srcTop,this.srcWidth,this.srcHeight,this.destLeft,this.destTop,this.destWidth,this.destHeight),this.updateCurrentTransformedState("reverse"),0===this.degree&&this.rotateFlipColl.length>0&&(this.destLeft+=this.totalPannedPoint.x,this.destTop+=this.totalPannedPoint.y),this.isRotateZoom=!1,this.objColl=t;var o=this.togglePen;this.togglePen=!1,this.lowerContext.filter="none",this.iterateObjColl(),this.destLeft+=this.totalPannedInternalPoint.x,this.destTop+=this.totalPannedInternalPoint.y,this.freehandRedraw(this.lowerContext),this.destLeft-=this.totalPannedInternalPoint.x,this.destTop-=this.totalPannedInternalPoint.y,this.togglePen=o,this.lowerContext.filter=s,this.activeObj=i},l.prototype.updateCurrentTransformedState=function(t,i,s){this.rotateFlipColl.length>0&&("initial"===t&&(this.reverseTransformedState(),e.isNullOrUndefined(i)&&this.setDestinationPoints()),this.currentTransformedState(t,null,null,s)),(this.isCircleCrop||!e.isNullOrUndefined(this.currSelectionPoint)&&"crop-circle"===this.currSelectionPoint.shape)&&(s&&(this.destLeft+=this.totalPannedClientPoint.x,this.destTop+=this.totalPannedClientPoint.y),this.cropCircle(this.lowerContext),s&&(this.destLeft-=this.totalPannedClientPoint.x,this.destTop-=this.totalPannedClientPoint.y))},l.prototype.reverseTransformedState=function(){this.lowerContext.setTransform(1,0,0,1,0,0)},l.prototype.currentTransformedState=function(t,i,s,o){s=s||this.lowerContext,"initial"===t?this.iterateRotateFlipColl(s,t):"reverse"===t&&(this.iterateRotateFlipColl(s,t),this.setClientTransformedDimension(i),(this.isCircleCrop||!e.isNullOrUndefined(this.currSelectionPoint)&&"crop-circle"===this.currSelectionPoint.shape&&e.isNullOrUndefined(o))&&(o&&(this.destLeft+=this.totalPannedClientPoint.x,this.destTop+=this.totalPannedClientPoint.y),this.cropCircle(this.lowerContext),o&&(this.destLeft-=this.totalPannedClientPoint.x,this.destTop-=this.totalPannedClientPoint.y)))},l.prototype.iterateRotateFlipColl=function(t,e){if("initial"===e)for(i=0;i<this.rotateFlipColl.length;i++)this.setTransform(t,this.rotateFlipColl[i]);else if("reverse"===e)for(var i=this.rotateFlipColl.length-1;i>=0;i--)this.setTransform(t,this.rotateFlipColl[i],!0)},l.prototype.setTransform=function(t,i,s){switch(s&&90===i?i=-90:s&&-90===i&&(i=90),"horizontal"===i&&this.degree%90==0&&this.degree%180!=0?i="vertical":"vertical"===i&&this.degree%90==0&&this.degree%180!=0&&(i="horizontal"),this.isReverseRotate=this.isReverseFlip=!0,e.isNullOrUndefined(s)&&t.clearRect(0,0,t.canvas.width,t.canvas.height),i){case 90:case-90:t.translate(t.canvas.width/2,t.canvas.height/2),t.rotate(Math.PI/180*i),t.translate(-t.canvas.width/2,-t.canvas.height/2);break;case"horizontal":t.translate(t.canvas.width,0),t.scale(-1,1);break;case"vertical":t.translate(0,t.canvas.height),t.scale(1,-1)}this.isReverseRotate=this.isReverseFlip=!1},l.prototype.isObjInsideCropRegion=function(t){var e=!1;return t.activePoint.startX>=this.destLeft&&t.activePoint.endX<=this.destLeft+this.destWidth?e=!0:t.activePoint.startX<=this.destLeft&&t.activePoint.endX>=this.destLeft?e=!0:t.activePoint.startX<=this.destLeft+this.destWidth&&t.activePoint.endX>=this.destLeft+this.destWidth?e=!0:t.activePoint.startY>=this.destTop&&t.activePoint.endY<=this.destTop+this.destHeight?e=!0:t.activePoint.startY<=this.destTop&&t.activePoint.endY>=this.destTop?e=!0:t.activePoint.startY<=this.destTop+this.destHeight&&t.activePoint.endY>=this.destTop+this.destHeight&&(e=!0),e},l.prototype.panFreehandDrawColl=function(t,i,s){for(var o=0;o<this.freehandCounter;o++){this.points=e.extend([],this.pointColl[o].points,[]),this.pointCounter=0;for(var a=this.points.length,n=0;n<a;n++)""===s||"vertical"===s?this.points[n].x+=t:this.points[n].x-=t,""===s||"horizontal"===s?this.points[n].y+=i:this.points[n].y-=i}this.freehandRedraw(this.lowerContext)},l.prototype.panObjColl=function(t,e,i){for(var s=0;s<this.objColl.length;s++){""===i||"vertical"===i?(this.objColl[s].activePoint.startX+=t,this.objColl[s].activePoint.endX+=t):(this.objColl[s].activePoint.startX-=t,this.objColl[s].activePoint.endX-=t),""===i||"horizontal"===i?(this.objColl[s].activePoint.startY+=e,this.objColl[s].activePoint.endY+=e):(this.objColl[s].activePoint.startY-=e,this.objColl[s].activePoint.endY-=e),this.objColl[s].activePoint.width=this.objColl[s].activePoint.endX-this.objColl[s].activePoint.startX,this.objColl[s].activePoint.height=this.objColl[s].activePoint.endY-this.objColl[s].activePoint.startY,this.updateActiveObject(this.objColl[s].activePoint,this.objColl[s]);var o=this.lowerContext.filter;this.lowerContext.filter="none",this.apply(this.objColl[s].shape,this.objColl[s]),this.lowerContext.filter=o,this.refreshActiveObj()}},l.prototype.cropObjColl=function(){if(this.objColl.length>0)for(var t=0;t<this.objColl.length;t++)this.objColl[t].imageRatio={startX:(this.objColl[t].activePoint.startX-this.activeObj.activePoint.startX)/this.activeObj.activePoint.width,startY:(this.objColl[t].activePoint.startY-this.activeObj.activePoint.startY)/this.activeObj.activePoint.height,endX:(this.objColl[t].activePoint.endX-this.activeObj.activePoint.startX)/this.activeObj.activePoint.width,endY:(this.objColl[t].activePoint.endY-this.activeObj.activePoint.startY)/this.activeObj.activePoint.height,width:this.activeObj.activePoint.width/this.objColl[t].activePoint.width,height:this.activeObj.activePoint.height/this.objColl[t].activePoint.height},"text"===this.objColl[t].shape&&(this.objColl[t].textSettings.fontRatio=this.objColl[t].activePoint.width/this.objColl[t].textSettings.fontSize)},l.prototype.cropFreehandDrawColl=function(){for(var t=0;t<this.freehandCounter;t++){this.points=e.extend([],this.pointColl[t].points,[]),this.pointCounter=0;for(var i=this.points.length,s=0;s<i;s++)this.points[s].ratioX=(this.points[s].x-this.activeObj.activePoint.startX)/this.activeObj.activePoint.width,this.points[s].ratioY=(this.points[s].y-this.activeObj.activePoint.startY)/this.activeObj.activePoint.height}},l.prototype.hoverFreehandraw=function(t,i){var s=this.upperContext,o=-1;o=this.freehandDrawHoveredIndex>-1?this.freehandDrawHoveredIndex:this.freehandDrawSelectedIndex,this.points=e.extend([],this.pointColl[o].points),this.pointCounter=0;var a,n,r,h,l=this.points.length,c=0,d=0;s.fillStyle=t||"#42a5f5",s.strokeStyle="#fff",c=d=this.penStrokeWidth=i||this.pointColl[o].strokeWidth;for(var p=0;p<l-3;p++)this.points[p+1]&&this.points[p+2]&&this.points[p+2]&&(a=this.calcCurveControlPoints(this.points[p+0],this.points[p+1],this.points[p+2]).controlPoint2,n=this.calcCurveControlPoints(this.points[p+1],this.points[p+2],this.points[p+3]).controlPoint1,r=this.points[p+1],h=this.points[p+2],this.startDraw(s,a,n,r,h,c,d)),1===l&&(a=n=r=h=this.points[0],this.startDraw(s,a,n,r,h,c,d));s.closePath()},l.prototype.flipFreehandrawColl=function(t){if("horizontal"===t.toLowerCase()){for(o=0;o<this.freehandCounter;o++)if(this.pointColl[o].shapeFlip!==this.currFlipState){this.points=e.extend([],this.pointColl[o].points,[]),this.pointCounter=0;for(var i=this.points.length,s=0;s<i;s++)this.points[s].x<=this.destLeft+this.destWidth/2?this.points[s].x=this.destLeft+this.destWidth-(this.points[s].x-this.destLeft):this.points[s].x>=this.destLeft+this.destWidth/2&&(this.points[s].x=this.destLeft+(this.destLeft+this.destWidth-this.points[s].x)),this.points[s].ratioX=(this.points[s].x-this.destLeft)/this.destWidth,this.points[s].ratioY=(this.points[s].y-this.destTop)/this.destHeight;this.pointColl[o].shapeFlip=this.currFlipState}}else for(var o=0;o<this.freehandCounter;o++)if(this.pointColl[o].shapeFlip!==this.currFlipState){this.points=e.extend([],this.pointColl[o].points,[]),this.pointCounter=0;for(var i=this.points.length,s=0;s<i;s++)this.points[s].y<=this.destTop+this.destHeight/2?this.points[s].y=this.destTop+this.destHeight-(this.points[s].y-this.destTop):this.points[s].y>=this.destTop+this.destHeight/2&&(this.points[s].y=this.destTop+(this.destTop+this.destHeight-this.points[s].y)),this.points[s].ratioX=(this.points[s].x-this.destLeft)/this.destWidth,this.points[s].ratioY=(this.points[s].y-this.destTop)/this.destHeight;this.pointColl[o].shapeFlip=this.currFlipState}},l.prototype.rotateFreehandDrawColl=function(){for(s=0;s<this.freehandCounter;s++){this.points=e.extend([],this.pointColl[s].points,[]),this.pointCounter=0;for(var t=this.points.length,i=0;i<t;i++)this.points[i].y=this.destTop+this.destHeight*this.points[i].ratioX,this.points[i].x=this.destLeft+this.destWidth-this.destWidth*this.points[i].ratioY}for(var s=0;s<this.freehandCounter;s++){this.points=e.extend([],this.pointColl[s].points,[]),this.pointCounter=0;for(var t=this.points.length,i=0;i<t;i++)this.points[i].ratioX=(this.points[i].x-this.destLeft)/this.destWidth,this.points[i].ratioY=(this.points[i].y-this.destTop)/this.destHeight}},l.prototype.zoomFreehandDrawColl=function(){for(var t=0;t<this.freehandCounter;t++){this.points=e.extend([],this.pointColl[t].points,[]),this.pointCounter=0;for(var i=this.points.length,s=0;s<i;s++)this.points[s].x=this.zoomX(this.points[s].ratioX),this.points[s].y=this.zoomY(this.points[s].ratioY)}this.freehandRedraw(this.lowerContext)},l.prototype.zoomX=function(t){return t*this.destWidth+this.destLeft},l.prototype.zoomY=function(t){return t*this.destHeight+this.destTop},l.prototype.zoomObjColl=function(t){for(var i=0;i<this.objColl.length;i++)if(this.objColl[i].activePoint.startX=this.objColl[i].imageRatio.startX*this.destWidth+this.destLeft,this.objColl[i].activePoint.startY=this.objColl[i].imageRatio.startY*this.destHeight+this.destTop,this.objColl[i].activePoint.endX=this.objColl[i].imageRatio.endX*this.destWidth+this.destLeft,this.objColl[i].activePoint.endY=this.objColl[i].imageRatio.endY*this.destHeight+this.destTop,this.objColl[i].activePoint.width=this.objColl[i].activePoint.endX-this.objColl[i].activePoint.startX,this.objColl[i].activePoint.height=this.objColl[i].activePoint.endY-this.objColl[i].activePoint.startY,"text"===this.objColl[i].shape&&this.updateFontSize(this.objColl[i]),this.updateActiveObject(this.objColl[i].activePoint,this.objColl[i]),e.isNullOrUndefined(t)){var s=this.lowerContext.filter;this.lowerContext.filter="none",this.apply(this.objColl[i].shape,this.objColl[i]),this.refreshActiveObj(),this.lowerContext.filter=s}},l.prototype.calcRatio=function(){var t,e;return 0===this.degree||this.degree%180==0?(t=this.baseImg.width/this.destWidth,e=this.baseImg.height/this.destHeight):(t=this.baseImg.height/this.destWidth,e=this.baseImg.width/this.destHeight),{width:t,height:e}},l.prototype.drawCustomSelection=function(t){this.currObjType.isCustomCrop=!0,this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),this.currObjType.shape=this.activeObj.shape=t.toLowerCase(),0===this.zoomFactor?this.destLeft>=0&&this.destTop>=0?(this.activeObj.activePoint.startX=this.destLeft,this.activeObj.activePoint.startY=this.destTop,this.activeObj.activePoint.endX=this.destLeft+this.destWidth,this.activeObj.activePoint.endY=this.destTop+this.destHeight):this.destLeft>=0?(this.activeObj.activePoint.startX=this.destLeft,this.activeObj.activePoint.startY=7.5,this.activeObj.activePoint.endX=this.destLeft+this.destWidth,this.activeObj.activePoint.endY=this.lowerCanvas.height-15):this.destTop>=0?(this.activeObj.activePoint.startX=7.5,this.activeObj.activePoint.startY=this.destTop,this.activeObj.activePoint.endX=this.lowerCanvas.width-15,this.activeObj.activePoint.endY=this.destTop+this.destHeight):(this.activeObj.activePoint.startX=7.5,this.activeObj.activePoint.startY=7.5,this.activeObj.activePoint.endX=this.lowerCanvas.width-15,this.activeObj.activePoint.endY=this.lowerCanvas.height-15):(this.destLeft>0?this.activeObj.activePoint.startX=this.destLeft:this.activeObj.activePoint.startX=7.5,this.destTop>0?this.activeObj.activePoint.startY=this.destTop:this.activeObj.activePoint.startY=7.5,this.destLeft+this.destWidth+15<this.lowerCanvas.width?this.activeObj.activePoint.endX=this.destLeft+this.destWidth-15:this.activeObj.activePoint.endX=this.lowerCanvas.width-15,this.destTop+this.destHeight+15<this.lowerCanvas.height?this.activeObj.activePoint.endY=this.destTop+this.destHeight-15:this.activeObj.activePoint.endY=this.lowerCanvas.height-15),this.activeObj.activePoint.startX<this.destLeft&&(this.activeObj.activePoint.startX=this.destLeft),this.activeObj.activePoint.startY<this.destTop&&(this.activeObj.activePoint.startY=this.destTop),this.activeObj.activePoint.endX>this.destLeft+this.destWidth&&(this.activeObj.activePoint.endX=this.destLeft+this.destWidth),this.activeObj.activePoint.endY>this.destTop+this.destHeight&&(this.activeObj.activePoint.endY=this.destTop+this.destHeight),this.activeObj.activePoint.startX===this.destLeft&&this.destLeft+this.destWidth>this.lowerCanvas.clientWidth&&(this.activeObj.activePoint.endX=this.lowerCanvas.clientWidth-15),this.activeObj.activePoint.startY===this.destTop&&this.destTop+this.destHeight>this.lowerCanvas.clientHeight&&(this.activeObj.activePoint.endY=this.lowerCanvas.clientHeight-15),this.activeObj.activePoint.width=this.activeObj.activePoint.endX-this.activeObj.activePoint.startX,this.activeObj.activePoint.height=this.activeObj.activePoint.endY-this.activeObj.activePoint.startY,this.updateActiveObject(this.activeObj.activePoint,this.activeObj),this.drawObject("duplicate",this.activeObj,null,null,!0)},l.prototype.clearOuterCanvas=function(t){var e=this.destLeft,i=this.destTop;if(""!==this.currFlipState&&(this.destLeft=this.lowerCanvas.clientWidth-(this.destWidth+this.destLeft),this.destTop=this.lowerCanvas.clientHeight-(this.destHeight+this.destTop)),this.destWidth<this.lowerCanvas.width){var s=this.destLeft>0?this.destLeft:0;t.clearRect(0,0,s,this.lowerCanvas.height),t.clearRect(this.destLeft+this.destWidth,0,s,this.lowerCanvas.height)}if(this.destHeight<this.lowerCanvas.height){var o=this.destTop>0?this.destTop:0;t.clearRect(0,0,this.lowerCanvas.width,o),t.clearRect(0,this.destTop+this.destHeight,this.lowerCanvas.width,o)}""!==this.currFlipState&&(this.destLeft=e,this.destTop=i)},l.prototype.cropCircle=function(t,i,s){s&&""!==this.currFlipState&&this.setTransform(t,this.currFlipState),t.globalCompositeOperation="destination-in",t.beginPath(),e.isNullOrUndefined(i)?t.arc(this.destLeft+this.destWidth/2,this.destTop+this.destHeight/2,this.destWidth/2,0,2*Math.PI):t.arc(this.destWidth/2,this.destHeight/2,this.destWidth/2,0,2*Math.PI),t.closePath(),t.fill(),t.restore(),t.globalCompositeOperation="source-over",this.currObjType.isActiveObj=this.isCircleCrop=!0,s&&""!==this.currFlipState&&this.setTransform(t,this.currFlipState)},l.prototype.updateCropObj=function(){this.afterCropActions=[],this.cropObj.cropZoom=this.cropZoomFactor,this.cropObj.defaultZoom=this.defaultZoomFactor,this.cropObj.totalPannedPoint=e.extend({},this.totalPannedPoint,{},!0),this.cropObj.totalPannedClientPoint=e.extend({},this.totalPannedClientPoint,{},!0),this.cropObj.totalPannedInternalPoint=e.extend({},this.totalPannedInternalPoint,{},!0),this.cropObj.activeObj=e.extend({},this.activeObj,{},!0),this.cropObj.rotateFlipColl=e.extend([],this.rotateFlipColl,[],!0),this.cropObj.degree=this.degree,this.cropObj.currFlipState=this.currFlipState,this.cropObj.destPoints={startX:this.destLeft,startY:this.destTop,endX:0,endY:0,width:this.destWidth,height:this.destHeight},this.cropObj.srcPoints={startX:this.srcLeft,startY:this.srcTop,endX:0,endY:0,width:this.srcWidth,height:this.srcHeight}},l.prototype.setCropObj=function(){this.cropZoomFactor=this.zoomFactor=this.cropObj.cropZoom,this.defaultZoomFactor=this.cropObj.defaultZoom,this.totalPannedPoint=e.extend({},this.cropObj.totalPannedPoint,{},!0),this.totalPannedClientPoint=e.extend({},this.cropObj.totalPannedClientPoint,{},!0),this.totalPannedInternalPoint=e.extend({},this.cropObj.totalPannedInternalPoint,{},!0),this.rotateFlipColl=e.extend([],this.cropObj.rotateFlipColl,[],!0),this.degree=this.cropObj.degree,this.currFlipState=this.cropObj.currFlipState,this.destLeft=this.cropObj.destPoints.startX,this.destTop=this.cropObj.destPoints.startY,this.destWidth=this.cropObj.destPoints.width,this.destHeight=this.cropObj.destPoints.height,this.srcLeft=this.cropObj.srcPoints.startX,this.srcTop=this.cropObj.srcPoints.startY,this.srcWidth=this.cropObj.srcPoints.width,this.srcHeight=this.cropObj.srcPoints.height,this.drawCropSelectionImage(),0!==this.degree&&(this.isCircleCrop=!1,e.isNullOrUndefined(this.currSelectionPoint)||(this.currSelectionPoint.shape=""),this.currentPannedPoint={x:0,y:0},this.rotatePan()),this.activeObj=e.extend({},this.cropObj.activeObj,{},!0),this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),this.drawObject("duplicate");var t=e.extend({},this.cropObj.activeObj,{},!0),i=!1;if(this.afterCropActions.length>0){i=!0;var s=e.extend([],this.objColl,{},!0),o=e.extend([],this.pointColl,{},!0),a=this.freehandCounter;this.objColl=[],this.pointColl=[],this.freehandCounter=0;var n=this.isCircleCrop,r=e.extend({},this.currSelectionPoint,{},!0);this.currSelectionPoint=null,this.isCircleCrop=!1;for(var h=!1,l=0;l<this.afterCropActions.length;l++)this.degree%90!=0||this.degree%180==0||"horizontalflip"!==this.afterCropActions[l]&&"verticalflip"!==this.afterCropActions[l]||(this.rotatedFlipCropSelection=!0),this.updateTransform(this.afterCropActions[l]),"horizontalflip"!==this.afterCropActions[l]&&"verticalflip"!==this.afterCropActions[l]||(0===this.degree&&(this.destLeft+=this.totalPannedPoint.x,this.destTop+=this.totalPannedPoint.y),h=!0);this.isCircleCrop=n,this.currSelectionPoint=r;var c={startX:this.destLeft,startY:this.destTop,width:this.destWidth,height:this.destHeight};if(t=e.extend({},this.activeObj,{},!0),this.refreshActiveObj(),this.objColl=s,this.pointColl=o,this.freehandCounter=a,this.rotateFlipColl.length>1&&"string"==typeof this.rotateFlipColl[this.rotateFlipColl.length-1]?(this.iterateObjColl(),this.freehandRedraw(this.lowerContext)):(this.rotateFlipColl.length>1&&"number"==typeof this.rotateFlipColl[this.rotateFlipColl.length-1]||this.rotateFlipColl.length>=0)&&(this.destLeft=t.activePoint.startX,this.destTop=t.activePoint.startY,this.destWidth=t.activePoint.width,this.destHeight=t.activePoint.height,this.zoomObjColl(),this.zoomFreehandDrawColl()),this.destLeft=c.startX,this.destTop=c.startY,this.destWidth=c.width,this.destHeight=c.height,this.totalPannedPoint={x:0,y:0},this.totalPannedClientPoint={x:0,y:0},this.totalPannedInternalPoint={x:0,y:0},this.activeObj=t,this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),this.drawObject("duplicate"),this.cropObj.degree!==this.degree&&(this.cropZoomFactor=this.zoomFactor=0),this.updateObjAndFreeHandDrawColl(),h){if(0===this.degree){var d=e.extend({},this.currSelectionPoint,{},!0);this.currSelectionPoint=null,this.isCircleCrop=!1,this.drawPannImage({x:0,y:0},this.getCurrentPanRegion()),this.updateFlipPan(t),this.isCircleCrop=n,this.currSelectionPoint=d}this.activeObj=t,this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),this.drawObject("duplicate")}this.rotatedFlipCropSelection&&(this.rotatedFlipCropSelection=!1)}this.isCancelAction||i||(this.setDestPointsForFlipState(),this.updateObjAndFreeHandDrawColl(),this.zoomFreehandDrawColl(),this.destLeft=this.cropObj.destPoints.startX,this.destTop=this.cropObj.destPoints.startY),this.activeObj=t},l.prototype.drawCropSelectionImage=function(){var t=this.lowerContext.filter;this.upperContext.clearRect(0,0,this.lowerCanvas.width,this.lowerCanvas.height),this.lowerContext.clearRect(0,0,this.lowerCanvas.width,this.lowerCanvas.height),this.reverseTransformedState(),this.iterateRotateFlipColl(this.lowerContext,"initial"),this.updateBrightnessFilter(),this.lowerContext.drawImage(this.baseImg,this.srcLeft,this.srcTop,this.srcWidth,this.srcHeight,this.destLeft,this.destTop,this.destWidth,this.destHeight),this.iterateRotateFlipColl(this.lowerContext,"reverse");var i=e.extend({},this.cropObj.activeObj,{},!0);if(this.lowerContext.filter="none",this.isCancelAction)this.zoomObjColl(),this.zoomFreehandDrawColl();else{this.destLeft=this.cropObj.destPoints.startX,this.destTop=this.cropObj.destPoints.startY,this.destWidth=this.cropObj.destPoints.width,this.destHeight=this.cropObj.destPoints.height,this.srcLeft=this.cropObj.srcPoints.startX,this.srcTop=this.cropObj.srcPoints.startY,this.srcWidth=this.cropObj.srcPoints.width,this.srcHeight=this.cropObj.srcPoints.height;var s={startX:this.destLeft,startY:this.destTop,width:this.destWidth,height:this.destHeight};this.destLeft=this.cropObj.activeObj.activePoint.startX,this.destTop=this.cropObj.activeObj.activePoint.startY,this.destWidth=this.cropObj.activeObj.activePoint.width,this.destHeight=this.cropObj.activeObj.activePoint.height,this.zoomObjColl(),this.zoomFreehandDrawColl(),this.destLeft=s.startX,this.destTop=s.startY,this.destWidth=s.width,this.destHeight=s.height}this.activeObj=i,this.lowerContext.filter=t},l.prototype.cropImg=function(t){if(e.isNullOrUndefined(t)&&(this.croppedDegree=this.degree),e.isNullOrUndefined(t)&&0!==this.degree)this.updateCropObj(),this.rotateCrop();else if(e.isNullOrUndefined(t)&&""!==this.currFlipState)this.updateCropObj(),this.flipCrop();else{this.tempZoomFactor=this.zoomFactor;var i=this.calcRatio();!e.isNullOrUndefined(t)&&t||(this.updateCropObj(),this.resetPanPoints(),this.updateImageRatioForActObj(),this.currSelectionPoint=e.extend({},this.activeObj,{},!0),this.cropDestPoints={startX:this.destLeft,startY:this.destTop,width:this.destWidth,height:this.destHeight});var s=this.calcMaxDimension(this.activeObj.activePoint.width*i.width,this.activeObj.activePoint.height*i.height);this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),this.lowerContext.clearRect(0,0,this.lowerCanvas.width,this.lowerCanvas.height),this.srcLeft=this.activeObj.activePoint.startX*i.width-this.destLeft*i.width,this.srcTop=this.activeObj.activePoint.startY*i.height-this.destTop*i.height,this.srcWidth=this.activeObj.activePoint.width*i.width,this.srcHeight=this.activeObj.activePoint.height*i.height,this.destLeft=(this.lowerCanvas.clientWidth-s.width)/2,this.destTop=(this.lowerCanvas.clientHeight-s.height)/2,this.destWidth=s.width,this.destHeight=s.height;var o=this.lowerContext.filter;this.updateBrightnessFilter(),this.lowerContext.drawImage(this.baseImg,this.srcLeft,this.srcTop,this.srcWidth,this.srcHeight,this.destLeft,this.destTop,this.destWidth,this.destHeight),this.lowerContext.filter="none";var a=e.extend({},this.activeObj,{},!0);this.cropObjColl(),this.zoomObjColl();for(var n=0;n<this.objColl.length;n++)this.isObjInsideCropRegion(this.objColl[n])&&(this.apply(this.objColl[n].shape,this.objColl[n]),this.refreshActiveObj());this.activeObj=a,this.cropFreehandDrawColl(),this.zoomFreehandDrawColl(),this.clearOuterCanvas(this.lowerContext),this.clearOuterCanvas(this.upperContext),"crop-circle"===this.currSelectionPoint.shape?this.cropCircle(this.lowerContext):this.isCircleCrop=!1,this.lowerContext.filter=o,this.refreshActiveObj(),this.currObjType.isCustomCrop=!1,this.pan(!1),this.defaultZoomFactor=0}},l.prototype.updateImageRatioForActObj=function(){this.activeObj.imageRatio={startX:(this.activeObj.activePoint.startX-this.destLeft)/this.destWidth,startY:(this.activeObj.activePoint.startY-this.destTop)/this.destHeight,endX:(this.activeObj.activePoint.endX-this.destLeft)/this.destWidth,endY:(this.activeObj.activePoint.endY-this.destTop)/this.destHeight,width:this.destWidth/this.activeObj.activePoint.width,height:this.destHeight/this.activeObj.activePoint.height}},l.prototype.drawImgToCanvas=function(t){this.lowerContext.clearRect(0,0,this.lowerCanvas.width,this.lowerCanvas.height),this.destWidth=t.width,this.destHeight=t.height,this.isInitialLoading&&(this.initializeFilter(),this.isInitialLoading=!1);var i=this.lowerContext.filter;this.updateBrightnessFilter(),this.lowerContext.drawImage(this.baseImg,this.srcLeft,this.srcTop,this.srcWidth,this.srcHeight,this.destLeft,this.destTop,this.destWidth,this.destHeight),(!e.isNullOrUndefined(this.currSelectionPoint)&&"crop-circle"===this.currSelectionPoint.shape||this.isCircleCrop)&&this.cropCircle(this.lowerContext),this.lowerContext.filter=i},l.prototype.limitPan=function(){this.activeObj.activePoint&&(this.destLeft>this.activeObj.activePoint.startX&&(this.destLeft=this.activeObj.activePoint.startX),this.destTop>this.activeObj.activePoint.startY&&(this.destTop=this.activeObj.activePoint.startY),this.destLeft+this.destWidth<this.activeObj.activePoint.endX&&(this.destLeft=this.activeObj.activePoint.endX-this.destWidth),this.destTop+this.destHeight<this.activeObj.activePoint.endY&&(this.destTop=this.activeObj.activePoint.endY-this.destHeight))},l.prototype.updatePanPoints=function(t){var i=this.destLeft,s=this.destTop,o=this.panMove.x-this.tempPanMove.x,a=this.panMove.y-this.tempPanMove.y;if(""===t)this.destLeft+=o,this.destTop+=a,this.limitPan();else if("horizontal"===t){n=e.extend({},this.activeObj,{},!0);this.updateFlipActiveObj(t),o=this.tempPanMove.x-this.panMove.x,this.destLeft+=o,this.destTop+=a,this.limitPan(),this.activeObj=n}else if("vertical"===t){n=e.extend({},this.activeObj,{},!0);this.updateFlipActiveObj(t),a=this.tempPanMove.y-this.panMove.y,this.destLeft+=o,this.destTop+=a,this.limitPan(),this.activeObj=n}else if("horizontalVertical"===t){n=e.extend({},this.activeObj,{},!0);this.updateFlipActiveObj(t),o=this.tempPanMove.x-this.panMove.x,this.destLeft+=o,this.destTop-=a,this.limitPan(),this.activeObj=n}else if("verticalHorizontal"===t){var n=e.extend({},this.activeObj,{},!0);this.updateFlipActiveObj(t),a=this.tempPanMove.y-this.panMove.y,this.destLeft-=o,this.destTop+=a,this.limitPan(),this.activeObj=n}return{x:this.destLeft-i,y:this.destTop-s}},l.prototype.setCurrentPanRegion=function(t,e){var i=t;return""===t?"horizontal"===e?i="horizontal":"vertical"===e&&(i="vertical"):"horizontal"===t?"horizontal"===e?i="horizontalVertical":"vertical"===e?i="verticalHorizontal":90===e?i="vertical":-90===e&&(i="horizontal"):"vertical"===t?"horizontal"===e?i="horizontalVertical":"vertical"===e?i="verticalHorizontal":90===e?i="horizontal":-90===e&&(i="vertical"):"horizontal"===e?i="vertical":"vertical"===e&&(i="horizontal"),i},l.prototype.getCurrentPanRegion=function(){for(var t="",e=0;e<this.rotateFlipColl.length;e++)t=this.setCurrentPanRegion(t,this.rotateFlipColl[e]);return t},l.prototype.drawPannImage=function(t,i){this.lowerContext.clearRect(0,0,this.lowerCanvas.width,this.lowerCanvas.height),this.updateBrightnessFilter(),this.lowerContext.drawImage(this.baseImg,this.srcLeft,this.srcTop,this.srcWidth,this.srcHeight,this.destLeft,this.destTop,this.destWidth,this.destHeight),(!e.isNullOrUndefined(this.currSelectionPoint)&&"crop-circle"===this.currSelectionPoint.shape||this.isCircleCrop)&&this.cropCircle(this.lowerContext,null,!0),this.lowerContext.filter="none",this.panObjColl(t.x,t.y,i),this.panFreehandDrawColl(t.x,t.y,i),this.isCircleCrop&&this.cropCircle(this.lowerContext,null,!0)},l.prototype.drawPannedImage=function(t,i){var s=!1;e.isNullOrUndefined(this.activeObj.shape)&&(s=!0,this.activeObj.activePoint={startX:this.destLeft,startY:this.destTop,endX:this.destLeft+this.destWidth,endY:this.destTop+this.destHeight},this.activeObj.activePoint.startX<0&&(this.activeObj.activePoint.startX=0),this.activeObj.activePoint.startY<0&&(this.activeObj.activePoint.startY=0),this.activeObj.activePoint.endX>this.lowerCanvas.width&&(this.activeObj.activePoint.endX=this.lowerCanvas.width),this.activeObj.activePoint.endY>this.lowerCanvas.height&&(this.activeObj.activePoint.endY=this.lowerCanvas.height),this.activeObj.activePoint.width=this.activeObj.activePoint.endX-this.activeObj.activePoint.startX,this.activeObj.activePoint.height=this.activeObj.activePoint.endY-this.activeObj.activePoint.startY,this.activeObj.shape="crop-custom",this.activeObj.strokeSettings=this.strokeSettings,this.updateActiveObject(this.activeObj.activePoint,this.activeObj),this.isCropTab=!0);var o=this.getCurrentPanRegion();if(0===this.degree){var a=void 0;a=e.isNullOrUndefined(t)&&e.isNullOrUndefined(i)?this.updatePanPoints(o):{x:t,y:i},this.totalPannedPoint.x+=a.x,this.totalPannedPoint.y+=a.y;var n=e.extend({},this.activeObj,{},!0),r=this.lowerContext.filter;this.drawPannImage(a,o),this.lowerContext.filter=r,this.tempPanMove=e.extend({},this.panMove,{},!0),this.activeObj=e.extend({},n,{},!0),this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),e.isNullOrUndefined(this.activeObj.shape)||this.drawObject("duplicate",this.activeObj),this.updateFlipPan(n)}else{var h=this.currFlipState;this.isCropTab=!0,e.isNullOrUndefined(t)&&e.isNullOrUndefined(i)?this.currentPannedPoint=this.updatePanPoints(o):this.currentPannedPoint={x:t,y:i},this.currFlipState=h,this.rotatePan(),this.isCropTab=!1,this.tempPanMove=e.extend({},this.panMove,{},!0)}s&&(this.refreshActiveObj(),this.isCropTab=!1,this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height))},l.prototype.updateFlipPan=function(t){if(""!==this.currFlipState){var i=this.lowerContext.filter;this.refreshActiveObj(),this.rotatedFlip(),this.lowerContext.filter="none",this.freehandRedraw(this.lowerContext),this.lowerContext.filter=i,this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),e.isNullOrUndefined(t)||this.drawObject("duplicate",t)}},l.prototype.updateFlipActiveObj=function(t){"horizontal"===t?(this.activeObj.activePoint.startX>this.lowerCanvas.width/2?this.activeObj.activePoint.endX=this.lowerCanvas.width/2-(this.activeObj.activePoint.startX-this.lowerCanvas.width/2):this.activeObj.activePoint.endX=this.lowerCanvas.width/2+(this.lowerCanvas.width/2-this.activeObj.activePoint.startX),this.activeObj.activePoint.startX=this.activeObj.activePoint.endX-this.activeObj.activePoint.width):"vertical"===t?(this.activeObj.activePoint.startX>this.lowerCanvas.width/2?this.activeObj.activePoint.endY=this.lowerCanvas.height/2-(this.activeObj.activePoint.startY-this.lowerCanvas.height/2):this.activeObj.activePoint.endY=this.lowerCanvas.height/2+(this.lowerCanvas.height/2-this.activeObj.activePoint.startY),this.activeObj.activePoint.startY=this.activeObj.activePoint.endY-this.activeObj.activePoint.height):"verticalHorizontal"!==t&&"horizontalVertical"!==t||(this.activeObj.activePoint.startX>this.lowerCanvas.width/2?(this.activeObj.activePoint.endX=this.lowerCanvas.width/2-(this.activeObj.activePoint.startX-this.lowerCanvas.width/2),this.activeObj.activePoint.endY=this.lowerCanvas.height/2-(this.activeObj.activePoint.startY-this.lowerCanvas.height/2)):(this.activeObj.activePoint.endX=this.lowerCanvas.width/2+(this.lowerCanvas.width/2-this.activeObj.activePoint.startX),this.activeObj.activePoint.endY=this.lowerCanvas.height/2+(this.lowerCanvas.height/2-this.activeObj.activePoint.startY)),this.activeObj.activePoint.startX=this.activeObj.activePoint.endX-this.activeObj.activePoint.width,this.activeObj.activePoint.startY=this.activeObj.activePoint.endY-this.activeObj.activePoint.height),this.updateActiveObject(this.activeObj.activePoint,this.activeObj)},l.prototype.resetPanPoints=function(){this.totalPannedPoint={x:0,y:0},this.totalPannedClientPoint={x:0,y:0},this.totalPannedInternalPoint={x:0,y:0}},l.prototype.flipCrop=function(){this.isReverseFlip=!0,this.totalPannedPoint.x+=this.tempFlipPanPoint.x,this.totalPannedPoint.y+=this.tempFlipPanPoint.y;var t=this.currFlipState,i=this.flipColl;this.flipColl=[],this.updateImageRatioForActObj(),this.currSelectionPoint=e.extend({},this.activeObj,{},!0),this.lowerContext.clearRect(0,0,this.lowerCanvas.width,this.lowerCanvas.height),this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height);var s=this.lowerContext.filter;this.updateBrightnessFilter(),e.isNullOrUndefined(this.tempPannedPoint)||0!==this.totalPannedPoint.x||0!==this.totalPannedPoint.y||(this.totalPannedPoint=e.extend({},this.tempPannedPoint,{},!0),this.tempPannedPoint={x:0,y:0});var o=!0;e.isNullOrUndefined(this.activeObj.shape)||"crop"!==this.activeObj.shape.split("-")[0]||0!==this.zoomFactor||0===this.cropObj.cropZoom||(o=!1),0===this.zoomFactor&&o&&(this.totalPannedPoint.x>0?this.destLeft-=Math.abs(this.totalPannedPoint.x):this.destLeft+=Math.abs(this.totalPannedPoint.x),this.totalPannedPoint.y>0?this.destTop-=Math.abs(this.totalPannedPoint.y):this.destTop+=Math.abs(this.totalPannedPoint.y)),this.lowerContext.drawImage(this.baseImg,this.srcLeft,this.srcTop,this.srcWidth,this.srcHeight,this.destLeft,this.destTop,this.destWidth,this.destHeight);var a=this.destLeft,n=this.destTop;"horizontal"===this.currFlipState&&this.zoomFactor>0&&0!==this.totalPannedPoint.x?this.destLeft=a-this.totalPannedPoint.x:"vertical"===this.currFlipState&&this.zoomFactor>0&&0!==this.totalPannedPoint.y&&(this.destTop=n-this.totalPannedPoint.y),this.updateImageRatioForActObj(),this.objColl.push(this.activeObj);for(r=0;r<this.objColl.length;r++)this.objColl[r].shapeFlip="";for(r=0;r<this.freehandCounter;r++)this.pointColl[r].shapeFlip="";this.redrawObj(this.getCurrentPanRegion()),this.flipFreehandrawColl(this.currFlipState),0===this.zoomFactor&&o&&("horizontal"===this.getCurrentPanRegion()?(this.panObjColl(this.totalPannedPoint.x,-this.totalPannedPoint.y,this.getCurrentPanRegion()),this.panFreehandDrawColl(this.totalPannedPoint.x,-this.totalPannedPoint.y,this.getCurrentPanRegion())):"vertical"===this.getCurrentPanRegion()?(this.panObjColl(-this.totalPannedPoint.x,this.totalPannedPoint.y,this.getCurrentPanRegion()),this.panFreehandDrawColl(-this.totalPannedPoint.x,this.totalPannedPoint.y,this.getCurrentPanRegion())):(this.panObjColl(-this.totalPannedPoint.x,-this.totalPannedPoint.y,this.getCurrentPanRegion()),this.panFreehandDrawColl(-this.totalPannedPoint.x,-this.totalPannedPoint.y,this.getCurrentPanRegion()))),this.activeObj=e.extend({},this.objColl[this.objColl.length-1],{},!0),this.objColl.pop(),this.drawObject("duplicate"),this.destLeft=a,this.destTop=n,this.cropImg(!0),this.updateCurrentTransformedState("initial"),this.setDestinationPoints(),this.updateBrightnessFilter(),this.lowerContext.drawImage(this.baseImg,this.srcLeft,this.srcTop,this.srcWidth,this.srcHeight,this.destLeft,this.destTop,this.destWidth,this.destHeight),this.lowerContext.filter=s,this.isRotateZoom=!1,this.updateCurrentTransformedState("reverse"),""===t&&""!==this.currFlipState&&(t=this.currFlipState),this.currFlipState=t,this.flipColl=i,this.lowerContext.filter="none";for(r=0;r<this.objColl.length;r++)this.objColl[r].shapeFlip="";for(var r=0;r<this.freehandCounter;r++)this.pointColl[r].shapeFlip="";this.redrawObj(this.getCurrentPanRegion()),this.flipFreehandrawColl(this.currFlipState),this.iterateObjColl(),this.freehandRedraw(this.lowerContext),this.lowerContext.filter=s,(!e.isNullOrUndefined(this.currSelectionPoint)&&"crop-circle"===this.currSelectionPoint.shape||this.isCircleCrop)&&this.cropCircle(this.lowerContext),this.refreshActiveObj(),this.clearOuterCanvas(this.lowerContext),this.clearOuterCanvas(this.upperContext),this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),this.isReverseFlip=!1,this.resetPanPoints()},l.prototype.rotateCrop=function(){var t="";e.isNullOrUndefined(this.activeObj.shape)||(t=this.activeObj.shape);var i=this.degree;this.degree%90==0&&this.degree%180!=0&&(this.rotatedDestPoints.startX=this.destLeft,this.rotatedDestPoints.startY=this.destTop,this.rotatedDestPoints.width=this.destWidth,this.rotatedDestPoints.height=this.destHeight,this.rotatedDestPoints.startX-=this.totalPannedClientPoint.x,this.rotatedDestPoints.startY-=this.totalPannedClientPoint.y),this.updateImageRatioForActObj(),this.currSelectionPoint=e.extend({},this.activeObj,{},!0),this.objColl.push(this.activeObj),this.activeObj=e.extend({},this.objColl[this.objColl.length-1],{},!0),this.reverseTransformedState(),this.setClientTransformedDimension(),this.lowerContext.clearRect(0,0,this.lowerCanvas.width,this.lowerCanvas.height);var s=this.lowerContext.filter;this.updateBrightnessFilter(),this.lowerContext.drawImage(this.baseImg,this.srcLeft,this.srcTop,this.srcWidth,this.srcHeight,this.destLeft,this.destTop,this.destWidth,this.destHeight),this.lowerContext.filter=s;var o=0;90===i||-270===i?o=3:180===i||-180===i?o=2:270!==i&&-90!==i||(o=1);for(r=0;r<o;r++)this.rotateObjColl(),this.rotateFreehandDrawColl();var a=e.extend({},this.objColl[this.objColl.length-1],{},!0);if(""!==this.currFlipState){for(var n="",r=0;r<this.objColl.length;r++)this.objColl[r].shapeFlip="";"horizontal"===this.currFlipState?(n=this.degree%90==0&&this.degree%180!=0?"vertical":"horizontal",this.redrawObj(n)):"vertical"===this.currFlipState&&(n=this.degree%90==0&&this.degree%180!=0?"horizontal":"vertical",this.redrawObj(n));for(r=0;r<this.freehandCounter;r++)this.pointColl[r].shapeFlip="";"horizontal"===this.currFlipState?(n=this.degree%90==0&&this.degree%180!=0?"vertical":"horizontal",this.flipFreehandrawColl(n)):"vertical"===this.currFlipState&&(n=this.degree%90==0&&this.degree%180!=0?"horizontal":"vertical",this.flipFreehandrawColl(n))}this.zoomFreehandDrawColl(),this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),this.drawObject("duplicate",a),this.objColl.pop(),this.degree=0,this.cropImg(!0),this.isReverseRotate=!0,this.reverseTransformedState(),this.degree=i,this.setDestinationPoints(),this.currentTransformedState("initial"),this.updateBrightnessFilter(),this.lowerContext.drawImage(this.baseImg,this.srcLeft,this.srcTop,this.srcWidth,this.srcHeight,this.destLeft,this.destTop,this.destWidth,this.destHeight),this.lowerContext.filter=s,this.currentTransformedState("reverse"),o=0,90===i||-270===i?o=1:180===i||-180===i?o=2:270!==i&&-90!==i||(o=3);for(r=0;r<o;r++)this.rotateObjColl(),this.rotateFreehandDrawColl();if(""!==this.currFlipState){for(r=0;r<this.objColl.length;r++)this.objColl[r].shapeFlip="";"horizontal"===this.currFlipState?this.redrawObj("horizontal"):"vertical"===this.currFlipState&&this.redrawObj("vertical");for(r=0;r<this.freehandCounter;r++)this.pointColl[r].shapeFlip="";"horizontal"===this.currFlipState?this.flipFreehandrawColl("horizontal"):"vertical"===this.currFlipState&&this.flipFreehandrawColl("vertical")}this.isReverseRotate=!1,"crop-circle"===t&&this.cropCircle(this.lowerContext),this.lowerContext.filter="none";for(r=0;r<this.objColl.length;r++)this.isObjInsideCropRegion(this.objColl[r])&&(this.apply(this.objColl[r].shape,this.objColl[r]),this.refreshActiveObj());this.zoomFreehandDrawColl(),this.lowerContext.filter=s,this.clearOuterCanvas(this.lowerContext),this.clearOuterCanvas(this.upperContext),"crop-circle"===t&&this.cropCircle(this.lowerContext),this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),this.resetPanPoints()},l.prototype.updateRotatePanPoints=function(){this.degree%90==0&&this.degree%180!=0?90===this.degree||-270===this.degree?(this.destLeft+=this.currentPannedPoint.y,this.destTop-=this.currentPannedPoint.x):270!==this.degree&&-90!==this.degree||(this.destLeft-=this.currentPannedPoint.y,this.destTop+=this.currentPannedPoint.x):180===this.degree||-180===this.degree?(this.destLeft-=this.currentPannedPoint.x,this.destTop-=this.currentPannedPoint.y):(this.destLeft+=this.currentPannedPoint.x,this.destTop+=this.currentPannedPoint.y)},l.prototype.rotatePan=function(t){this.isReverseRotate=!0;var i,s=this.degree;e.isNullOrUndefined(this.activeObj.activePoint)||e.isNullOrUndefined(this.activeObj.shape)||(i=e.extend({},this.activeObj,{},!0));var o=e.extend([],this.objColl,[],!0);this.objColl=[],this.refreshActiveObj(),this.isRotateZoom=!0,this.updateCurrentTransformedState("initial");var a=this.destLeft,n=this.destTop;this.isCropTab&&(this.destLeft+=this.totalPannedInternalPoint.x,this.destTop+=this.totalPannedInternalPoint.y),this.updateRotatePanPoints(),this.isCropTab&&(this.totalPannedInternalPoint.x=this.destLeft-a,this.totalPannedInternalPoint.y=this.destTop-n);var r=this.lowerContext.filter;this.updateBrightnessFilter(),this.lowerContext.drawImage(this.baseImg,this.srcLeft,this.srcTop,this.srcWidth,this.srcHeight,this.destLeft,this.destTop,this.destWidth,this.destHeight),this.isRotateZoom=!1,this.updateCurrentTransformedState("reverse",!0,!0);var h=this.destLeft,l=this.destTop;this.destLeft+=this.totalPannedClientPoint.x,this.destTop+=this.totalPannedClientPoint.y,this.destLeft+=this.currentPannedPoint.x,this.destTop+=this.currentPannedPoint.y,this.totalPannedClientPoint.x=this.destLeft-h,this.totalPannedClientPoint.y=this.destTop-l,this.objColl=o,this.degree=s,this.objColl=e.extend([],o,[],!0),this.lowerContext.filter="none";var c=this.getCurrentPanRegion();t&&(this.currentPannedPoint=e.extend({},this.totalPannedClientPoint,{},!0)),this.panObjColl(this.currentPannedPoint.x,this.currentPannedPoint.y,c),this.panFreehandDrawColl(this.currentPannedPoint.x,this.currentPannedPoint.y,c),this.lowerContext.filter=r,this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),this.activeObj=e.extend({},i,{},!0),e.isNullOrUndefined(this.activeObj.activePoint)||this.drawObject("duplicate",this.activeObj,null,null,!0),this.isReverseRotate=!1},l.prototype.rotateZoom=function(t){var i=Math.pow(10,1);Math.round(this.zoomFactor*i)/i==.1&&-.1===t?this.zoomFactor=0:this.zoomFactor+=t,this.isCropTab?this.cropZoomFactor=this.zoomFactor:this.defaultZoomFactor=this.zoomFactor;var s=e.extend([],this.objColl,[],!0),o=e.extend({},this.activeObj,{},!0);this.objColl=[],this.refreshActiveObj(),this.updateCurrentTransformedState("initial"),this.isRotateZoom=!0,this.setDestinationPoints();var a=this.lowerContext.filter;this.updateBrightnessFilter(),this.lowerContext.drawImage(this.baseImg,this.srcLeft,this.srcTop,this.srcWidth,this.srcHeight,this.destLeft,this.destTop,this.destWidth,this.destHeight),this.lowerContext.filter=a,this.isRotateZoom=!1,this.updateCurrentTransformedState("reverse"),this.objColl=s,this.activeObj=o},l.prototype.drawZoomImgToCanvas=function(t,e){var i=Math.pow(10,1);Math.round(this.zoomFactor*i)/i==.1&&-.1===t?this.zoomFactor=0:this.zoomFactor+=t,this.isCropTab?this.cropZoomFactor+=t:this.defaultZoomFactor=this.zoomFactor;var s={width:0,height:0};this.isCropTab?s=this.cropZoom(t,e):((s=this.calcMaxDimension(this.srcWidth,this.srcHeight)).width+=s.width*this.zoomFactor,s.height+=s.height*this.zoomFactor,this.destLeft=(this.lowerCanvas.clientWidth-s.width)/2,this.destTop=(this.lowerCanvas.clientHeight-s.height)/2),this.drawImgToCanvas(s)},l.prototype.cropZoom=function(t,i){var s=this.destLeft,o=this.destTop,a={width:0,height:0};return 0===this.srcLeft||0===this.srcTop?a=e.isNullOrUndefined(i)?this.setZoomDimension(t,null):this.setZoomDimension(t,i):((a=this.degree%90==0&&this.degree%180!=0?this.calcMaxDimension(this.srcHeight,this.srcWidth):this.calcMaxDimension(this.srcWidth,this.srcHeight)).width+=a.width*this.zoomFactor,a.height+=a.height*this.zoomFactor),this.destLeft=s-(a.width-this.destWidth)/2,this.destTop=o-(a.height-this.destHeight)/2,e.isNullOrUndefined(i)||(this.destLeft>i.activePoint.startX&&(this.destLeft=i.activePoint.startX),this.destTop>i.activePoint.startY&&(this.destTop=i.activePoint.startY),this.destLeft+a.width<i.activePoint.endX&&(this.destLeft=i.activePoint.endX-a.width),this.destTop+a.height<i.activePoint.endY&&(this.destTop=i.activePoint.endY-a.height)),a},l.prototype.updateCanvas=function(){var t={fileName:this.fileName,fileType:this.fileType};this.srcWidth=this.baseImg.width,this.srcHeight=this.baseImg.height;var e=this.calcMaxDimension(this.srcWidth,this.srcHeight);this.destLeft=(this.lowerCanvas.clientWidth-e.width)/2,this.destTop=(this.lowerCanvas.clientHeight-e.height)/2,this.drawImgToCanvas(e),this.cropDestPoints={startX:this.destLeft,startY:this.destTop,width:this.destWidth,height:this.destHeight};var i=this.lowerContext.filter;this.lowerContext.filter="none",this.iterateObjColl(),this.zoomFreehandDrawColl(),this.lowerContext.filter=i,this.destWidth>0&&this.destHeight>0&&(this.isImageLoaded=!0),this.isUndoRedo&&""!==this.currFlipState&&this.flip(this.toPascalCase(this.currFlipState)),this.disabled&&this.element.setAttribute("class","e-disabled"),this.trigger("fileOpened",t)},l.prototype.imageOnLoad=function(t){var i=this;this.baseImg.src=t,this.baseImg.onload=function(){i.lowerContext.drawImage(i.baseImg,0,0,i.lowerCanvas.width,i.lowerCanvas.height),a.hideSpinner(i.element),i.element.style.opacity="1",i.updateCanvas(),i.currObjType.isUndoZoom&&(i.currObjType.isUndoZoom=!1,i.lowerCanvas.style.display="block"),i.isUndoRedo=!1,e.Browser.isDevice?(!i.isToolbar()||e.isNullOrUndefined(document.getElementById(i.element.id+"_toolbar"))||e.isNullOrUndefined(e.getComponent(document.getElementById(i.element.id+"_toolbar"),"toolbar"))||e.getComponent(document.getElementById(i.element.id+"_toolbar"),"toolbar").destroy(),e.isNullOrUndefined(document.getElementById(i.element.id+"_bottomToolbar"))||e.isNullOrUndefined(e.getComponent(document.getElementById(i.element.id+"_bottomToolbar"),"toolbar"))||e.getComponent(document.getElementById(i.element.id+"_bottomToolbar"),"toolbar").destroy(),i.initToolbarItem(!1,e.Browser.isDevice,null),i.createBottomToolbar()):(!i.isToolbar()||e.isNullOrUndefined(document.getElementById(i.element.id+"_toolbar"))||e.isNullOrUndefined(e.getComponent(document.getElementById(i.element.id+"_toolbar"),"toolbar"))||e.getComponent(document.getElementById(i.element.id+"_toolbar"),"toolbar").destroy(),i.initToolbarItem(!1,!1,null))}},l.prototype.refreshActiveObj=function(){this.activeObj={},this.activeObj.activePoint={startX:0,startY:0,endX:0,endY:0,width:0,height:0},this.activeObj.flipObjColl=[],this.activeObj.strokeSettings=this.strokeSettings,this.activeObj.textSettings=this.textSettings},l.prototype.redrawText=function(){this.activeObj.textSettings.bold&&(this.upperContext.font="bold "+this.activeObj.textSettings.fontSize+"px "+this.activeObj.textSettings.fontFamily),this.activeObj.textSettings.italic&&(this.upperContext.font="bold "+this.activeObj.textSettings.fontSize+"px "+this.activeObj.textSettings.fontFamily),this.activeObj.textSettings.bold&&this.activeObj.textSettings.italic&&(this.upperContext.font="italic bold "+this.activeObj.textSettings.fontSize+"px "+this.activeObj.textSettings.fontFamily),this.activeObj.textSettings.bold||this.activeObj.textSettings.italic||(this.upperContext.font=this.activeObj.textSettings.fontSize+"px "+this.activeObj.textSettings.fontFamily);var t=this.activeObj.keyHistory.split("\n"),e="block"===this.textArea.style.display?this.getMaxText(!0):this.getMaxText(),i=this.upperContext.measureText(e).width+.5*this.activeObj.textSettings.fontSize,s=t.length*(this.activeObj.textSettings.fontSize+.25*this.activeObj.textSettings.fontSize);this.setTextSelection(i,s),this.updateActiveObject(this.activeObj.activePoint,this.activeObj),this.redrawShape(this.activeObj)},l.prototype.setTextSelection=function(t,e){var i=this.degree;(i=0===this.activeObj.shapeDegree?this.degree:this.degree-this.activeObj.shapeDegree)<0&&(i=360+i);for(var s=0;s<this.activeObj.flipObjColl.length;s++)0===i?"horizontal"===this.activeObj.flipObjColl[s].toLowerCase()?this.activeObj.activePoint={startX:this.activeObj.activePoint.endX-t,startY:this.activeObj.activePoint.startY,endX:this.activeObj.activePoint.endX,endY:this.activeObj.activePoint.startY+(e||0)}:"vertical"===this.activeObj.flipObjColl[s].toLowerCase()?(this.activeObj.activePoint.startY=this.activeObj.activePoint.endY-e,this.activeObj.activePoint={startX:this.activeObj.activePoint.startX,startY:this.activeObj.activePoint.startY,endX:this.activeObj.activePoint.startX+(t||0),endY:this.activeObj.activePoint.endY}):this.activeObj.activePoint={startX:this.activeObj.activePoint.startX,startY:this.activeObj.activePoint.startY,endX:this.activeObj.activePoint.startX+(t||0),endY:this.activeObj.activePoint.startY+(e||0)}:90===i?"vertical"===this.activeObj.flipObjColl[s].toLowerCase()?(this.activeObj.activePoint.startX=this.activeObj.activePoint.endX-e,this.activeObj.activePoint={startX:this.activeObj.activePoint.startX,startY:this.activeObj.activePoint.endY-t,endX:this.activeObj.activePoint.endX,endY:this.activeObj.activePoint.endY}):"horizontal"===this.activeObj.flipObjColl[s].toLowerCase()?(this.activeObj.activePoint.endX=this.activeObj.activePoint.startX+e,this.activeObj.activePoint={startX:this.activeObj.activePoint.startX,startY:this.activeObj.activePoint.startY,endX:this.activeObj.activePoint.endX,endY:this.activeObj.activePoint.startY+(t||0)}):(this.activeObj.activePoint.startX=this.activeObj.activePoint.endX-e,this.activeObj.activePoint={startX:this.activeObj.activePoint.startX,startY:this.activeObj.activePoint.startY,endX:this.activeObj.activePoint.endX,endY:this.activeObj.activePoint.startY+(t||0)}):180===i?"horizontal"===this.activeObj.flipObjColl[s].toLowerCase()?(this.activeObj.activePoint.startY=this.activeObj.activePoint.endY-e,this.activeObj.activePoint={startX:this.activeObj.activePoint.startX,startY:this.activeObj.activePoint.startY,endX:this.activeObj.activePoint.startX+t,endY:this.activeObj.activePoint.endY}):"vertical"===this.activeObj.flipObjColl[s].toLowerCase()?(this.activeObj.activePoint.endY=this.activeObj.activePoint.startY+e,this.activeObj.activePoint={endX:this.activeObj.activePoint.endX,endY:this.activeObj.activePoint.endY,startX:this.activeObj.activePoint.endX-(t||0),startY:this.activeObj.activePoint.startY}):this.activeObj.activePoint={endX:this.activeObj.activePoint.endX,endY:this.activeObj.activePoint.endY,startX:this.activeObj.activePoint.endX-(t||0),startY:this.activeObj.activePoint.endY-(e||0)}:270===i&&("vertical"===this.activeObj.flipObjColl[s].toLowerCase()?this.activeObj.activePoint={startX:this.activeObj.activePoint.startX,startY:this.activeObj.activePoint.startY,endX:this.activeObj.activePoint.startX+e,endY:this.activeObj.activePoint.startY+(t||0)}:"horizontal"===this.activeObj.flipObjColl[s].toLowerCase()?(this.activeObj.activePoint.startX=this.activeObj.activePoint.endX-e,this.activeObj.activePoint={startX:this.activeObj.activePoint.startX,startY:this.activeObj.activePoint.endY-(t||0),endX:this.activeObj.activePoint.endX,endY:this.activeObj.activePoint.endY}):(this.activeObj.activePoint.endX=this.activeObj.activePoint.startX+e,this.activeObj.activePoint={startX:this.activeObj.activePoint.startX,startY:this.activeObj.activePoint.endY-(t||0),endX:this.activeObj.activePoint.endX,endY:this.activeObj.activePoint.endY}));0===this.activeObj.flipObjColl.length&&(0===i?this.activeObj.activePoint={startX:this.activeObj.activePoint.startX,startY:this.activeObj.activePoint.startY,endX:this.activeObj.activePoint.startX+(t||0),endY:this.activeObj.activePoint.startY+(e||0)}:90===i?(this.activeObj.activePoint.startX=this.activeObj.activePoint.endX-e,this.activeObj.activePoint={startX:this.activeObj.activePoint.startX,startY:this.activeObj.activePoint.startY,endX:this.activeObj.activePoint.endX,endY:this.activeObj.activePoint.startY+(t||0)}):180===i?this.activeObj.activePoint={endX:this.activeObj.activePoint.endX,endY:this.activeObj.activePoint.endY,startX:this.activeObj.activePoint.endX-(t||0),startY:this.activeObj.activePoint.endY-(e||0)}:270===i&&(this.activeObj.activePoint.endX=this.activeObj.activePoint.startX+e,this.activeObj.activePoint={startX:this.activeObj.activePoint.startX,startY:this.activeObj.activePoint.endY-(t||0),endX:this.activeObj.activePoint.endX,endY:this.activeObj.activePoint.endY})),this.activeObj.activePoint.width=this.activeObj.activePoint.endX-this.activeObj.activePoint.startX,this.activeObj.activePoint.height=this.activeObj.activePoint.endY-this.activeObj.activePoint.startY,360!==this.degree&&-360!==this.degree||(this.degree=0)},l.prototype.updateUndoRedoColl=function(t,e,i,s,o,a,n){this.isInitialLoading||(this.undoRedoStep++,this.undoRedoColl.push({operation:t,value:e,previousObj:i,currentObj:s,zoomFactor:o,sharpen:a,bw:n}),this.undoRedoColl.length>16&&(this.undoRedoColl.splice(0,1),this.undoRedoStep--),this.enableDisableToolbarBtn())},l.prototype.fileSelect=function(t,i){a.showSpinner(this.element),this.element.style.opacity="0.5";var s=i.target.files[0];this.isImageLoaded&&(this.isImageLoaded=!1,this.reset()),e.isNullOrUndefined(this.toolbarTemplate)&&(this.reset(),this.update()),this.fileName=t.value.split("\\")[t.value.split("\\").length-1],this.fileName=this.fileName.split(".")[0];var o=window.URL.createObjectURL(s);this.imageOnLoad(o.toString()),t.value=""},l.prototype.findTextPoint=function(t){if("text"===this.activeObj.shape){this.textArea.style.transformOrigin="0 0";var e=void 0,i="";if((e=0===this.activeObj.shapeDegree?this.degree:this.degree-this.activeObj.shapeDegree)<0&&(e=360+e),this.activeObj.flipObjColl.length>0)for(var s=0;s<this.activeObj.flipObjColl.length;s++)i+=0!==e&&e%90==0&&180!==e?"horizontal"===this.activeObj.flipObjColl[s].toLowerCase()?"scale(1, -1)":"scale(-1, 1)":"horizontal"===this.activeObj.flipObjColl[s].toLowerCase()?"scale(-1, 1)":"scale(1, -1)","horizontal"===this.activeObj.flipObjColl[s].toLowerCase()?this.textArea.style.transform="rotate("+e+"deg)"+i:"vertical"===this.activeObj.flipObjColl[s].toLowerCase()&&(this.textArea.style.transform="rotate("+e+"deg)"+i);else this.textArea.style.transform="rotate("+e+"deg)";this.findTextTarget(t)}},l.prototype.getStrokeWidth=function(t){var e;switch(parseInt(t,10)/2){case 1:e=this.l10n.getConstant("XSmall");break;case 2:e=this.l10n.getConstant("Small");break;case 3:e=this.l10n.getConstant("Medium");break;case 4:e=this.l10n.getConstant("Large");break;case 5:e=this.l10n.getConstant("XLarge")}return e},l.prototype.updateToolbarItems=function(){var t=this.element.querySelector(".e-fill.e-template .e-dropdownbtn-preview"),i=this.element.querySelector(".e-stroke.e-template .e-dropdownbtn-preview"),s=this.element.querySelector(".e-text-font-color.e-template .e-dropdownbtn-preview"),o=this.element.querySelector(".e-pen-stroke-color.e-template .e-dropdownbtn-preview"),a=this.element.querySelector(".e-shape-stroke-width"),n=this.element.querySelector(".e-text-font-family"),r=this.element.querySelector(".e-text-font-size"),h=this.element.querySelector(".e-text-font-style");if(t&&(""===this.activeObj.strokeSettings.fillColor?t.classList.add("e-nocolor-item"):(t.classList.remove("e-nocolor-item"),t.style.background=this.activeObj.strokeSettings.fillColor),e.getComponent(this.element.id+"_shape_fill","colorpicker").value=this.activeObj.strokeSettings.fillColor+"ff"),i&&(i.style.background=this.activeObj.strokeSettings.strokeColor,e.getComponent(this.element.id+"_shape_stroke","colorpicker").value=this.activeObj.strokeSettings.strokeColor+"ff"),s&&(s.style.background=this.activeObj.strokeSettings.strokeColor,e.getComponent(this.element.id+"_text_font","colorpicker").value=this.activeObj.strokeSettings.strokeColor+"ff"),o&&(o.style.background=this.activeObj.strokeSettings.strokeColor,e.getComponent(this.element.id+"_pen_stroke","colorpicker").value=this.activeObj.strokeSettings.strokeColor+"ff"),n&&(e.Browser.isDevice?n.setAttribute("style","font-family:"+this.activeObj.textSettings.fontFamily.toLowerCase()):n.textContent=this.activeObj.textSettings.fontFamily),r)for(var l=0;l<this.fontSizeColl.length;l++)if(parseInt(this.fontSizeColl[l].text,10)>=Math.round(this.activeObj.textSettings.fontSize)){r.textContent=(l+1).toString();break}if(h&&(e.Browser.isDevice?this.activeObj.textSettings.bold||this.activeObj.textSettings.italic?this.activeObj.textSettings.bold&&this.activeObj.textSettings.italic?h.setAttribute("style","font-style: italic;font-weight: bold"):this.activeObj.textSettings.bold?h.setAttribute("style","font-weight: bold"):h.setAttribute("style","font-style: italic"):h.setAttribute("style",""):this.activeObj.textSettings.bold||this.activeObj.textSettings.italic?this.activeObj.textSettings.bold&&this.activeObj.textSettings.italic?h.textContent="Bold Italic":this.activeObj.textSettings.bold?h.textContent="Bold":h.textContent="Italic":h.textContent="Default"),a){var c=Math.round(this.activeObj.strokeSettings.strokeWidth).toString();a.textContent=this.getStrokeWidth(c)}},l.prototype.setTimer=function(t){!this.isTimer&&this.timer>10&&(this.findTextPoint(t),e.Browser.isDevice&&this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height))},l.prototype.targetTouches=function(t){return[{x:t[0].pageX,y:t[0].pageY},{x:t[1].pageX,y:t[1].pageY}]},l.prototype.calculateScale=function(t,e){var i=this.getDistance(t[0],t[1]);return this.getDistance(e[0],e[1])/i},l.prototype.getDistance=function(t,i){var s=0,o=0;return e.isNullOrUndefined(t)||e.isNullOrUndefined(i)||(s=t.x-i.x,o=t.y-i.y),Math.sqrt(s*s+o*o)},l.prototype.setXYPoints=function(t){t.preventDefault();var e,i;"mousedown"===t.type?(e=t.clientX,i=t.clientY):(this.touchEndPoint.x=e=t.touches[0].clientX,this.touchEndPoint.y=i=t.touches[0].clientY);var s=this.lowerCanvas.getBoundingClientRect();return e-=s.left,i-=s.top,{x:e,y:i}},l.prototype.touchStartHandler=function(t){t.preventDefault(),2===t.touches.length?this.isFirstMove=!0:(this.timer=setTimeout(this.setTimer.bind(this),1e3,t),this.mouseDownEventHandler(t)),e.EventHandler.add(this.lowerCanvas,"touchend",this.mouseUpEventHandler,this),e.EventHandler.add(this.lowerCanvas,"touchmove",this.mouseMoveEventHandler,this),e.EventHandler.add(this.upperCanvas,"touchend",this.mouseUpEventHandler,this),e.EventHandler.add(this.upperCanvas,"touchmove",this.mouseMoveEventHandler,this)},l.prototype.isShapeTouch=function(t,e){var i=!1;if("touchstart"===t.type){this.redrawActObj();var s=this.setXYPoints(t),o=s.x,a=s.y;i=this.findTargetObj(o,a,e)}return i},l.prototype.isFreehandDrawTouch=function(t,e){var i=!1;if("touchstart"===t.type&&!e){this.redrawActObj();var s=this.setXYPoints(t),o=s.x,a=s.y;this.setCursor(o,a),this.isFreehandDrawingPoint&&(i=!0)}return i},l.prototype.selectFreehandDraw=function(t){if(this.isFreehandDrawEditing=!0,!e.isNullOrUndefined(t)||0===t){if(!this.isFreehandDrawIndex(t))return;this.freehandDrawSelectedIndex=this.freehandDrawHoveredIndex=t,this.hoverFreehandraw(),this.upperCanvas.style.cursor="pointer"}this.freehandDrawSelectedIndex=this.freehandDrawHoveredIndex,this.pointColl[this.freehandDrawSelectedIndex].isSelected=!0,"#42a5f5"!==this.pointColl[this.freehandDrawHoveredIndex].strokeColor&&(this.tempFreeHandDrawEditingStyles.strokeColor=this.pointColl[this.freehandDrawHoveredIndex].strokeColor),this.tempFreeHandDrawEditingStyles.strokeWidth=this.pointColl[this.freehandDrawHoveredIndex].strokeWidth,this.isFreehandDrawEditing?this.refreshToolbar("pen"):this.okBtn()},l.prototype.closeContextualToolbar=function(){var t=!1;return(e.isNullOrUndefined(this.element.querySelector("#"+this.element.id+"_contextualToolbar"))||this.element.querySelector("#"+this.element.id+"_contextualToolbar").parentElement.classList.contains("e-hide"))&&(e.isNullOrUndefined(this.element.querySelector("#"+this.element.id+"_headWrapper"))||this.element.querySelector("#"+this.element.id+"_headWrapper").parentElement.classList.contains("e-hide"))||(this.element.querySelector(".e-contextual-toolbar-wrapper").classList.add("e-hide"),this.okBtn(),this.refreshToolbar("main"),t=!0),t},l.prototype.mouseDownEventHandler=function(t){if("touchstart"===t.type&&(this.isTouch=!0),"touchstart"!==t.type||t.currentTarget!==this.lowerCanvas||this.isImageLoaded){var i,s=!1,o=!0;if(void 0!==this.activeObj.shape&&(i=this.activeObj.shape.split("-")),void 0!==i&&"crop"===i[0]&&(s=!0),s&&(this.dragCanvas=this.togglePan=!0),s&&this.dragCanvas){var a=(l=this.setXYPoints(t)).x,n=l.y;this.setCursor(a,n),"move"!==this.upperCanvas.style.cursor&&"crosshair"!==this.upperCanvas.style.cursor&&"default"!==this.upperCanvas.style.cursor&&"grab"!==this.upperCanvas.style.cursor&&(o=!1)}var r=this.isShapeTouch(t,s),h=this.isFreehandDrawTouch(t,s);if(r||this.togglePen||s||(this.refreshToolbar("main"),this.closeContextualToolbar()),!this.dragCanvas||!o||"grab"!==this.upperCanvas.style.cursor&&!this.isTouch||r||h||this.togglePen){var l=this.setXYPoints(t),a=l.x,n=l.y;if(this.redrawActObj(a,n),this.isFreehandDrawingPoint||this.isFreehandDrawCustomized&&!this.togglePen){if(!e.isNullOrUndefined(this.freehandDrawSelectedIndex)&&this.freehandDrawSelectedIndex!==this.freehandDrawHoveredIndex){var c=this.freehandDrawHoveredIndex;if(this.okBtn(),this.isFreehandDrawCustomized=!1,this.freehandDrawHoveredIndex=c,this.freehandDrawHoveredIndex>-1){d="#fff"===this.pointColl[this.freehandDrawHoveredIndex].strokeColor?"#42a5f5":this.pointColl[this.freehandDrawHoveredIndex].strokeColor;this.hoverFreehandraw(d,this.pointColl[this.freehandDrawHoveredIndex].strokeWidth)}}if(!e.isNullOrUndefined(this.freehandDrawHoveredIndex)&&this.freehandDrawHoveredIndex>-1)this.selectFreehandDraw();else if(this.freehandDrawSelectedIndex){this.okBtn();var d=this.pointColl[this.freehandDrawSelectedIndex].strokeColor;this.hoverFreehandraw(d,this.pointColl[this.freehandDrawSelectedIndex].strokeWidth)}}else if(this.isFreehandDrawEditing&&this.cancelFreehandDraw(),this.closeContextualToolbar(),this.isFreehandDrawEditing=!1,("crosshair"===this.upperCanvas.style.cursor||e.Browser.isDevice&&this.togglePen)&&(this.togglePen?(e.isNullOrUndefined(this.activeObj.strokeSettings)&&(this.activeObj.strokeSettings=this.strokeSettings),e.isNullOrUndefined(this.penStrokeWidth)&&(this.penStrokeWidth=2),this.upperContext.strokeStyle=this.activeObj.strokeSettings.strokeColor,this.upperContext.fillStyle=this.activeObj.strokeSettings.strokeColor,this.freehandDownHandler(t,this.upperCanvas)):(this.refreshActiveObj(),this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height)),this.currObjType.isActiveObj=!1,this.dragElement="",this.dragPoint.startX=this.dragPoint.startY=this.dragPoint.endX=this.dragPoint.endY=0),"crosshair"!==this.upperCanvas.style.cursor&&"touchstart"===t.type.toLowerCase()||this.currObjType.isActiveObj&&"default"!==this.upperCanvas.style.cursor&&!this.togglePen?(this.currObjType.isUndoAction&&this.refreshUndoRedoColl(),this.findTarget(a,n,t.type)):""!==this.currObjType.shape&&!this.currObjType.isCustomCrop||this.togglePen||"default"===this.upperCanvas.style.cursor||this.setActivePoint(a,n),!e.isNullOrUndefined(this.activeObj)){var p,v=!1;void 0!==this.activeObj.shape&&(p=this.activeObj.shape.split("-")),void 0===p&&(this.currObjType.isCustomCrop||this.togglePen)?v=!0:void 0!==p&&"crop"===p[0]&&(v=!0),"rectangle"===this.activeObj.shape||"ellipse"===this.activeObj.shape||"line"===this.activeObj.shape?this.refreshToolbar("shapes"):"text"===this.activeObj.shape?this.refreshToolbar("text"):v||this.callMainToolbar(),this.updateToolbarItems()}}else this.isFreehandDrawEditing&&this.applyFreehandDraw(),this.applyShape(),this.canvasMouseDownHandler(t);this.isShapeInserted=!1,this.tempActiveObj=e.extend({},this.activeObj,{},!0)}},l.prototype.mouseMoveEventHandler=function(t){if(t.preventDefault(),"touchmove"===t.type&&2===t.touches.length){if(this.isFirstMove)this.startTouches=this.targetTouches(t.touches),this.tempTouches=[],this.tempTouches.push({x:t.touches[0].clientX||t.touches[0].pageX-this.lowerCanvas.offsetLeft,y:t.touches[0].clientY||t.touches[0].pageY-this.lowerCanvas.offsetTop}),this.tempTouches.push({x:t.touches[1].clientX||t.touches[1].pageX-this.lowerCanvas.offsetLeft,y:t.touches[1].clientY||t.touches[1].pageY-this.lowerCanvas.offsetTop});else{var i=t.touches[0].clientX||t.touches[0].pageX-this.lowerCanvas.offsetLeft,s=t.touches[0].clientY||t.touches[0].pageY-this.lowerCanvas.offsetTop,o=t.touches[1].clientX||t.touches[1].pageX-this.lowerCanvas.offsetLeft,a=t.touches[1].clientY||t.touches[1].pageY-this.lowerCanvas.offsetTop,n=this.calculateScale(this.startTouches,this.targetTouches(t.touches));this.tempTouches[0].x!==i&&this.tempTouches[0].y!==s&&this.tempTouches[1].x!==o&&this.tempTouches[1].y!==a&&(n>1?this.zoom(1.1):this.zoom(-1.1),this.tempTouches=[],this.tempTouches.push({x:t.touches[0].clientX||t.touches[0].pageX-this.lowerCanvas.offsetLeft,y:t.touches[0].clientY||t.touches[0].pageY-this.lowerCanvas.offsetTop}),this.tempTouches.push({x:t.touches[1].clientX||t.touches[1].pageX-this.lowerCanvas.offsetLeft,y:t.touches[1].clientY||t.touches[1].pageY-this.lowerCanvas.offsetTop}))}return void(this.isFirstMove=!1)}"none"===this.textArea.style.display&&(this.isTimer=!0);var r,h;"mousemove"===t.type?(r=t.clientX,h=t.clientY):(this.touchEndPoint.x=r=t.touches[0].clientX,this.touchEndPoint.y=h=t.touches[0].clientY);var l=this.lowerCanvas.getBoundingClientRect();r-=l.left,h-=l.top,this.canvasMouseMoveHandler(t);var c,d=!1;void 0!==this.activeObj.shape&&(c=this.activeObj.shape.split("-")),void 0!==c&&"crop"===c[0]&&(d=!0),d&&this.zoomFactor>0&&this.disableZoomOutBtn(),(this.currObjType.isActiveObj&&(void 0!==this.activeObj.activePoint||this.objColl.length>0)&&!this.dragCanvas||void 0!==this.activeObj.activePoint)&&""===this.dragElement&&(this.setCursor(r,h),e.isNullOrUndefined(this.activeObj.activePoint)||0!==this.activeObj.activePoint.width||"default"===this.upperCanvas.style.cursor||"move"===this.upperCanvas.style.cursor||"crosshair"===this.upperCanvas.style.cursor||"grab"===this.upperCanvas.style.cursor||"pointer"===this.upperCanvas.style.cursor||(this.upperCanvas.style.cursor="move"),this.findTarget(r,h,t.type)),this.currObjType.isDragging&&(this.upperContext.clearRect(0,0,this.lowerCanvas.width,this.lowerCanvas.height),this.updateActivePoint(r,h,d),this.isPreventDragging?(this.activeObj.activePoint.startX>this.destLeft&&this.activeObj.activePoint.endX<this.destLeft+this.destWidth&&this.activeObj.activePoint.startY>this.destTop&&this.activeObj.activePoint.endY<this.destTop+this.destHeight&&(this.isPreventDragging=!1),this.drawObject("duplicate",null,null,null,!0)):this.drawObject("duplicate"),d&&(this.dragCanvas=this.togglePan=!0))},l.prototype.mouseUpEventHandler=function(t){"touchstart"===t.type&&(this.isTouch=!1),t.preventDefault(),this.togglePan&&this.canvasMouseUpHandler(t);var i,s;"mouseup"===t.type?(i=t.clientX,s=t.clientY):(i=this.touchEndPoint.x,s=this.touchEndPoint.y);var o=this.lowerCanvas.getBoundingClientRect();i-=o.left,s-=o.top,"touchend"===t.type&&(this.startTouches=this.tempTouches=[],this.isFirstMove=!1,"none"===this.textArea.style.display&&(this.isTimer=!1,this.timer=0));var a,n=!1;void 0!==this.activeObj.shape&&(a=this.activeObj.shape.split("-")),void 0!==a&&"crop"===a[0]&&(n=!0),t.currentTarget===this.upperCanvas&&(this.currObjType.shape=this.currObjType.shape.toLowerCase(),this.togglePen||this.dragCanvas?n&&!this.togglePen&&JSON.stringify(this.activeObj.activePoint)!==JSON.stringify(this.tempActiveObj.activePoint)&&(this.undoRedoColl.push({operation:"selectionTransform",value:null,currentObj:e.extend([],this.objColl,[],!0),previousObj:this.objColl,zoomFactor:this.zoomFactor,currentSelectionObj:e.extend([],this.activeObj,{},!0),previousSelectionObj:e.extend([],this.tempActiveObj,{},!0),sharpen:this.adjustmentLevel.sharpen,bw:this.adjustmentLevel.bw}),this.undoRedoStep++):(e.isNullOrUndefined(this.tempObjColl)||0===this.activeObj.activePoint.width||(this.objColl.push(this.activeObj),JSON.stringify(this.activeObj.activePoint)!==JSON.stringify(this.tempActiveObj.activePoint)&&(this.undoRedoColl.push({operation:"shapeTransform",value:null,currentObj:e.extend([],this.objColl,[],!0),previousObj:this.tempObjColl,zoomFactor:this.zoomFactor,sharpen:this.adjustmentLevel.sharpen,bw:this.adjustmentLevel.bw}),this.undoRedoStep++),this.redrawShape(this.objColl[this.objColl.length-1]),this.tempObjColl=void 0),this.isFreehandDrawEditing||this.applyCurrActObj(i,s))),this.togglePen&&t.currentTarget===this.upperCanvas?this.freehandUpHandler(t,this.upperCanvas,this.upperContext):this.currObjType.shape="",this.dragElement="",this.currObjType.isInitialLine=this.currObjType.isDragging=!1,this.oldPoint.x=void 0,this.oldPoint.y=void 0},l.prototype.keyDownEventHandler=function(t){var i,s=this,o={},a={fileName:this.fileName,fileType:this.fileType,cancel:!1};switch(t.key){case t.ctrlKey&&"s":this.trigger("beforeSave",a,function(t){a.cancel||s.export(t.fileType,t.fileName)}),t.preventDefault(),t.stopImmediatePropagation();break;case t.ctrlKey&&"z":this.allowUndoRedo&&this.callUndo();break;case t.ctrlKey&&"y":this.allowUndoRedo&&this.callRedo();break;case"Delete":if(this.isFreehandDrawEditing){this.updateFreehandDrawColorChange();n=e.extend([],this.pointColl,[],!0);this.deleteFreehandDraw(this.freehandDrawHoveredIndex),this.updateUndoRedoColl("delete","freehanddraw",n,this.pointColl,this.zoomFactor)}else if("none"===this.textArea.style.display){this.objColl.push(this.activeObj);var n=e.extend([],this.objColl,[],!0);this.objColl.pop(),o={action:"delete",previousShapeSettings:this.updatePreviousShapeSettings(),currentShapeSettings:null},this.keyHistory="",this.clearSelection(),this.trigger("shapeChanging",o),this.refreshToolbar("main"),this.updateUndoRedoColl("delete","shape",n,this.objColl,this.zoomFactor)}break;case"Escape":this.togglePan?(this.refreshToolbar(this.currentToolbar),this.pan(!1)):"block"===this.textArea.style.display?this.redrawActObj():this.performCancel();break;case"Enter":void 0!==this.activeObj.shape&&(i=this.activeObj.shape.split("-")),void 0!==this.activeObj.horTopLine&&void 0!==this.activeObj.shape&&"crop"===i[0]&&this.crop();break;default:e.Browser.isDevice&&"block"===this.textArea.style.display&&setTimeout(this.textKeyDown.bind(this),1,t)}},l.prototype.keyUpEventHandler=function(t){"block"===this.textArea.style.display&&t.target.id===this.element.id+"_textArea"&&setTimeout(this.textKeyDown.bind(this),1,t)},l.prototype.canvasMouseDownHandler=function(t){t.preventDefault();var i,s;"mousedown"===t.type?(i=t.offsetX||t.pageX-this.lowerCanvas.offsetLeft,s=t.offsetY||t.pageY-this.lowerCanvas.offsetTop):(i=t.touches[0].clientX||t.touches[0].pageX-this.lowerCanvas.offsetLeft,s=t.touches[0].clientY||t.touches[0].pageY-this.lowerCanvas.offsetTop);var o=this.lowerCanvas.getBoundingClientRect();i-=o.left,s-=o.top,this.panDown={x:i,y:s},this.lastPan={x:this.destLeft,y:this.destTop},e.isNullOrUndefined(this.tempPanMove)&&(this.tempPanMove={x:i,y:s})},l.prototype.canvasMouseMoveHandler=function(t){this.dragCanvas?this.lowerCanvas.style.cursor="grab":(this.dragCanvas=this.togglePan=!1,this.lowerCanvas.style.cursor=this.upperCanvas.style.cursor="default");var e,i;"mousemove"===t.type?(e=t.offsetX||t.pageX-this.lowerCanvas.offsetLeft,i=t.offsetY||t.pageY-this.lowerCanvas.offsetTop):(e=t.touches[0].clientX||t.touches[0].pageX-this.lowerCanvas.offsetLeft,i=t.touches[0].clientY||t.touches[0].pageY-this.lowerCanvas.offsetTop);var s=this.lowerCanvas.getBoundingClientRect();e-=s.left,i-=s.top,this.panMove={x:e,y:i},this.panDown&&this.panMove&&this.togglePan&&this.dragCanvas&&this.drawPannedImage()},l.prototype.canvasMouseUpHandler=function(t){t.preventDefault(),this.togglePan&&this.panDown&&this.panMove&&this.togglePan&&this.dragCanvas&&(this.panDown=null,this.panMove=null,this.tempPanMove=null,this.updateUndoRedoColl("pan",null,{x:this.lastPan.x,y:this.lastPan.y},{x:this.destLeft,y:this.destTop})),this.currObjType.isDragging=!1},l.prototype.handleScroll=function(t){var e,i,s=!1;"mousewheel"===t.type&&(e=t.clientX,i=t.clientY);var o=this.lowerCanvas.getBoundingClientRect();e-=o.left,i-=o.top,e>this.destLeft&&e<this.destLeft+this.destWidth&&i>this.destTop&&i<this.destTop+this.destHeight&&(s=!0),!0===t.ctrlKey&&s&&t.preventDefault()},l.prototype.textKeyDown=function(t){"\r"===String.fromCharCode(t.which)&&(this.textRow+=1),this.textArea.setAttribute("rows",this.textRow.toString()),this.textArea.style.height="auto",this.textArea.style.height=this.textArea.scrollHeight+"px",this.setTextBoxWidth(t),e.Browser.isDevice&&(this.textArea.style.width=parseFloat(this.textArea.style.width)+this.textArea.style.fontSize+"px");var i=this.textArea.value.split("\n");this.textRow=i.length,this.textArea.setAttribute("rows",this.textRow.toString())},l.prototype.adjustToScreen=function(){var t=this;this.element.querySelector("#"+this.element.id+"_contextualToolbar").parentElement.classList.contains("e-hide")&&(e.isNullOrUndefined(this.element.querySelector("#"+this.element.id+"_headWrapper"))||this.element.querySelector("#"+this.element.id+"_headWrapper").parentElement.classList.contains("e-hide"))||(this.element.querySelector(".e-contextual-toolbar-wrapper").classList.add("e-hide"),this.okBtn(),this.refreshToolbar("main"));var i,s=!1;void 0!==this.activeObj.shape&&(i=this.activeObj.shape.split("-")),void 0!==i&&"crop"===i[0]&&(s=!0,this.updateImageRatioForActObj(),this.objColl.push(this.activeObj),this.refreshActiveObj()),"block"===this.textArea.style.display&&this.redrawActObj();var o=this.lowerContext.filter;this.update(),this.applyActObj(),this.refreshActiveObj(),this.lowerContext.filter=this.initialAdjustmentValue=o,this.isImageLoaded&&(a.showSpinner(this.element),this.element.style.opacity="0.5"),this.lowerContext.clearRect(0,0,this.lowerCanvas.width,this.lowerCanvas.height),this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height);var n=document.querySelector("#"+this.element.id+"_canvasWrapper");e.isNullOrUndefined(n)||(n.style.width=this.element.offsetWidth+"px",n.style.height=this.element.offsetHeight+"px",e.Browser.isDevice?n.style.height=parseFloat(n.style.height)-2*this.toolbarHeight-3+"px":n.style.height=parseFloat(n.style.height)-this.toolbarHeight-3+"px");var r=this.calcMaxDimension(this.srcWidth,this.srcHeight);if(this.defaultZoomFactor>0&&(r.width+=r.width*this.defaultZoomFactor,r.height+=r.height*this.defaultZoomFactor),this.destLeft=(this.lowerCanvas.clientWidth-r.width)/2,this.destTop=(this.lowerCanvas.clientHeight-r.height)/2,0===this.degree&&""===this.currFlipState)this.defaultZoomFactor>0&&(this.destLeft+=this.totalPannedPoint.x,this.destTop+=this.totalPannedPoint.y),this.drawImgToCanvas(r);else{this.drawImgToCanvas(r),this.updateCurrentTransformedState("initial");var h=this.lowerContext.filter;this.updateBrightnessFilter(),this.lowerContext.drawImage(this.baseImg,this.srcLeft,this.srcTop,this.srcWidth,this.srcHeight,this.destLeft,this.destTop,this.destWidth,this.destHeight),this.lowerContext.filter=h,this.updateCurrentTransformedState("reverse")}if(this.zoomObjColl(),this.zoomFreehandDrawColl(),this.isCircleCrop&&this.cropCircle(this.lowerContext),a.hideSpinner(this.element),this.element.style.opacity="1",this.defToolbarItems.length>0&&!e.isNullOrUndefined(document.getElementById(this.element.id+"_toolbar"))&&(e.getComponent(t.element.id+"_toolbar","toolbar").refreshOverflow(),e.isNullOrUndefined(this.element.querySelector(".e-contextual-toolbar-wrapper"))||this.element.querySelector(".e-contextual-toolbar-wrapper").classList.add("e-hide")),this.refreshActiveObj(),this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),s&&(this.activeObj=e.extend({},this.objColl[this.objColl.length-1],null,!0),this.objColl.pop(),this.drawObject("duplicate",this.activeObj)),(0!==this.degree||""!==this.currFlipState)&&this.defaultZoomFactor>0){var l=e.extend({},this.totalPannedPoint,null,!0),c=e.extend({},this.totalPannedInternalPoint,null,!0),d=e.extend({},this.totalPannedClientPoint,null,!0);this.zoom(.1),this.zoom(-.1),0===this.degree?(this.destLeft+=l.x,this.destTop+=l.y,this.totalPannedPoint=l,this.updateFlipPan()):(this.totalPannedInternalPoint=c,this.totalPannedClientPoint=d,this.currentPannedPoint={x:0,y:0},this.isCropTab=!0,this.rotatePan(),this.isCropTab=!1)}else 0!==this.degree&&this.cropZoomFactor>0&&(this.zoomFactor=this.cropZoomFactor=0,this.enableDisableToolbarBtn())},l.prototype.screenOrientation=function(){e.Browser.isDevice&&setTimeout(this.adjustToScreen.bind(this),100)},l.prototype.windowResizeHandler=function(){e.Browser.isDevice||this.adjustToScreen()},l.prototype.updatePreviousShapeSettings=function(){var t=[];return"text"!==this.activeObj.shape||e.isNullOrUndefined(this.activeObj.textSettings)||(this.activeObj.textSettings.bold&&t.push("bold"),this.activeObj.textSettings.italic&&t.push("italic"),this.activeObj.textSettings.underline&&t.push("underline")),{id:e.isNullOrUndefined(this.activeObj.currIndex)?null:this.activeObj.currIndex,type:this.toPascalCase(this.activeObj.shape),startX:this.activeObj.activePoint.startX,startY:this.activeObj.activePoint.startY,width:this.activeObj.activePoint.width,height:this.activeObj.activePoint.height,strokeColor:e.isNullOrUndefined(this.activeObj.strokeSettings)?null:this.activeObj.strokeSettings.strokeColor,strokeWidth:e.isNullOrUndefined(this.activeObj.strokeSettings)?null:this.activeObj.strokeSettings.strokeWidth,fillColor:e.isNullOrUndefined(this.activeObj.strokeSettings)?null:this.activeObj.strokeSettings.fillColor,radius:"ellipse"===this.activeObj.shape?this.activeObj.activePoint.width/2:null,length:"line"===this.activeObj.shape?this.activeObj.activePoint.width:null,text:"text"===this.activeObj.shape?e.isNullOrUndefined(this.activeObj.keyHistory)?null:this.activeObj.keyHistory:null,fontSize:"text"===this.activeObj.shape?e.isNullOrUndefined(this.activeObj.textSettings)?null:this.activeObj.textSettings.fontSize:null,fontStyle:"text"===this.activeObj.shape?t:null,color:"text"===this.activeObj.shape?e.isNullOrUndefined(this.activeObj.strokeSettings)?null:this.activeObj.strokeSettings.strokeColor:null}},l.prototype.disableZoomOutBtn=function(){var t=!1,i=document.querySelector("#"+this.element.id+"_zoomOut"),s=this.destLeft,o=this.destTop,a=this.destWidth,n=this.destHeight;return 0!==this.degree&&180!==this.degree||(e.isNullOrUndefined(this.activeObj.shape)?this.setZoomDimension(-.1,null):(this.setZoomDimension(-.1,this.activeObj),this.destLeft>this.activeObj.activePoint.startX||this.destTop>this.activeObj.activePoint.startY||this.destLeft+this.destWidth<this.activeObj.activePoint.endX||this.destTop+this.destHeight<this.activeObj.activePoint.endY?(i.classList.add("e-disabled"),i.parentElement.classList.add("e-overlay"),t=!0):(i.classList.remove("e-disabled"),i.parentElement.classList.remove("e-overlay"),t=!1))),this.destLeft=s,this.destTop=o,this.destWidth=a,this.destHeight=n,t},l.prototype.setZoomDimension=function(t,i){var s={width:0,height:0};return s=this.degree%90==0&&this.degree%180!=0?this.calcMaxDimension(this.srcHeight,this.srcWidth):this.calcMaxDimension(this.srcWidth,this.srcHeight),s.width+=s.width*this.zoomFactor,s.height+=s.height*this.zoomFactor,this.destLeft+=(this.destWidth-s.width)/2,this.destTop+=(this.destHeight-s.height)/2,t<0&&!e.isNullOrUndefined(i)?(this.destLeft>i.activePoint.startX&&(this.destLeft=i.activePoint.startX),this.destTop>i.activePoint.startY&&(this.destTop=i.activePoint.startY),this.destLeft+s.width<i.activePoint.startX+i.activePoint.width&&(this.destLeft=this.destLeft+(i.activePoint.startX+i.activePoint.width)-(this.destLeft+s.width)),this.destTop+s.height<i.activePoint.startY+i.activePoint.height&&(this.destTop=this.destTop+(i.activePoint.startY+i.activePoint.height)-(this.destTop+s.height))):t<0&&e.isNullOrUndefined(i)&&(this.destLeft>0&&(this.destLeft=0),this.destTop>0&&(this.destTop=0),this.destLeft+s.width<this.lowerCanvas.width&&(this.destLeft=this.lowerCanvas.width-this.destWidth),this.destTop+s.height<this.lowerCanvas.height&&(this.destTop=this.lowerCanvas.height-this.destHeight)),s},l.prototype.applyCurrActObj=function(t,i){var s=!1,o=e.extend({},this.activeObj,{},!0);if(!e.isNullOrUndefined(o.activePoint)&&(t>=Math.floor(o.activePoint.startX)&&t<=Math.ceil(o.activePoint.endX)&&i>=Math.floor(o.activePoint.startY)&&i<=Math.ceil(o.activePoint.endY)&&(s=!0),!s)){if(this.updateImageRatioForActObj(),void 0===this.activeObj.horTopLine||0===this.activeObj.horTopLine.startX||0===this.activeObj.horTopLine.endX||this.currObjType.isCustomCrop||""===this.currObjType.shape||this.objColl.push(e.extend({},this.activeObj,{},!0)),"text"===this.activeObj.shape||"ellipse"===this.currObjType.shape||"rectangle"===this.currObjType.shape||"line"===this.currObjType.shape){var a=this.lowerContext.filter;this.lowerContext.filter=this.getDefaultFilter();for(var n=0;n<this.objColl.length;n++)this.isObjInsideCropRegion(this.objColl[n])&&(this.apply(this.objColl[n].shape,this.objColl[n]),this.refreshActiveObj());this.zoomFreehandDrawColl(),this.lowerContext.filter=a,this.apply("shape"),this.clearOuterCanvas(this.lowerContext),this.clearOuterCanvas(this.upperContext),this.isCircleCrop&&this.cropCircle(this.lowerContext)}this.refreshToolbar("main")}},l.prototype.updateTextFromTextArea=function(){this.activeObj.keyHistory!==this.textArea.value&&this.updateUndoRedoColl("text",this.objColl,this.activeObj.keyHistory,this.textArea.value,this.zoomFactor,this.adjustmentLevel.sharpen,this.adjustmentLevel.bw),this.activeObj.keyHistory=this.textArea.value,this.textArea.style.display="none",this.textArea.value="",this.updateFontStyles();var t=this.upperContext.measureText(this.activeObj.keyHistory).width+.5*this.activeObj.textSettings.fontSize,e=this.activeObj.textSettings.fontSize+.25*this.activeObj.textSettings.fontSize,i=this.activeObj.keyHistory.split("\n");if(i.length>1){e*=i.length;for(var s=[],o=0;o<i.length;o++)s.push(this.upperContext.measureText(i[o]).width+.5*this.activeObj.textSettings.fontSize);t=Math.max.apply(Math,s)}this.setTextSelection(t,e),this.updateActiveObject(this.activeObj.activePoint,this.activeObj),this.updateImageRatioForActObj()},l.prototype.setTextBoxStylesToActObj=function(){this.activeObj.textSettings.fontFamily=this.textArea.style.fontFamily,this.activeObj.strokeSettings.strokeColor=this.textArea.style.color,"bold"===this.textArea.style.fontWeight?this.activeObj.textSettings.bold=!0:this.activeObj.textSettings.bold=!1,"italic"===this.textArea.style.fontStyle?this.activeObj.textSettings.italic=!0:this.activeObj.textSettings.italic=!1,this.activeObj.textSettings.fontSize=parseFloat(this.textArea.style.fontSize)},l.prototype.redrawActObj=function(t,e){var i;void 0!==this.activeObj.shape&&(i=this.activeObj.shape.split("-")),void 0!==this.activeObj.horTopLine&&void 0!==this.activeObj.shape&&"crop"!==i[0]&&("block"===this.textArea.style.display?(this.setTextBoxStylesToActObj(),this.updateFontRatio(this.activeObj,!0),t&&e?t!==this.activeObj.activePoint.startX&&e!==this.activeObj.activePoint.startY&&(this.updateTextFromTextArea(),this.applyActObj()):(this.updateTextFromTextArea(),this.apply(this.activeObj.shape,this.activeObj),this.objColl.push(this.activeObj),this.refreshActiveObj(),this.textArea.style.transform="",this.refreshToolbar("main"))):this.applyActObj())},l.prototype.setTextBoxPos=function(t,e,i,s,o){var a={x:s,y:o};return 0===e?"horizontal"===i.toLowerCase()?(a.x=t.activePoint.endX,a.y=t.activePoint.startY):"vertical"===i.toLowerCase()?(a.x=t.activePoint.startX,a.y=t.activePoint.endY):(a.x=t.activePoint.startX,a.y=t.activePoint.startY):90===e?"horizontal"===i.toLowerCase()?(a.x=t.activePoint.startX,a.y=t.activePoint.startY):"vertical"===i.toLowerCase()?(a.x=t.activePoint.endX,a.y=t.activePoint.endY):(a.x=t.activePoint.endX,a.y=t.activePoint.startY):180===e?"horizontal"===i.toLowerCase()?(a.x=t.activePoint.startX,a.y=t.activePoint.endY):"vertical"===i.toLowerCase()?(a.x=t.activePoint.endX,a.y=t.activePoint.startY):(a.x=t.activePoint.endX,a.y=t.activePoint.endY):270===e&&("horizontal"===i.toLowerCase()?(a.x=t.activePoint.endX,a.y=t.activePoint.endY):"vertical"===i.toLowerCase()?(a.x=t.activePoint.startX,a.y=t.activePoint.startY):(a.x=t.activePoint.startX,a.y=t.activePoint.endY)),a},l.prototype.setTextBoxPoints=function(t,e,i,s,o){var a={x:s,y:o};return 0===e?"horizontal"===t.flipObjColl[0].toLowerCase()?"horizontal"===i.toLowerCase()?(a.x=t.activePoint.startX,a.y=t.activePoint.startY):"vertical"===i.toLowerCase()&&(a.x=t.activePoint.endX,a.y=t.activePoint.endY):"horizontal"===i.toLowerCase()?(a.x=t.activePoint.endX,a.y=t.activePoint.endY):"vertical"===i.toLowerCase()&&(a.x=t.activePoint.endX,a.y=t.activePoint.startY):90===e?"horizontal"===t.flipObjColl[0].toLowerCase()?"horizontal"===i.toLowerCase()?(a.x=t.activePoint.endX,a.y=t.activePoint.endY):"vertical"===i.toLowerCase()&&(a.x=t.activePoint.startX,a.y=t.activePoint.endY):"horizontal"===i.toLowerCase()?(a.x=t.activePoint.startX,a.y=t.activePoint.endY):"vertical"===i.toLowerCase()&&(a.x=t.activePoint.startX,a.y=t.activePoint.startY):180===e?"horizontal"===t.flipObjColl[0].toLowerCase()?"horizontal"===i.toLowerCase()?(a.x=t.activePoint.startX,a.y=t.activePoint.startY):"vertical"===i.toLowerCase()&&(a.x=t.activePoint.startX,a.y=t.activePoint.startY):"horizontal"===i.toLowerCase()?(a.x=t.activePoint.startX,a.y=t.activePoint.startY):"vertical"===i.toLowerCase()&&(a.x=t.activePoint.startX,a.y=t.activePoint.endY):270===e&&("horizontal"===t.flipObjColl[0].toLowerCase()?"horizontal"===i.toLowerCase()?(a.x=t.activePoint.startX,a.y=t.activePoint.startY):"vertical"===i.toLowerCase()&&(a.x=t.activePoint.endX,a.y=t.activePoint.startY):"horizontal"===i.toLowerCase()?(a.x=t.activePoint.endX,a.y=t.activePoint.startY):"vertical"===i.toLowerCase()&&(a.x=t.activePoint.endX,a.y=t.activePoint.endY)),a},l.prototype.findTextTarget=function(t){var i,s;if("dblclick"===t.type?(i=t.clientX,s=t.clientY):"touchstart"===t.type&&(this.touchEndPoint.x=i=t.touches[0].clientX,this.touchEndPoint.y=s=t.touches[0].clientY),this.preventZoomBtn=!0,this.refreshToolbar("text"),this.preventZoomBtn=!1,this.updateToolbarItems(),e.isNullOrUndefined(i)||e.isNullOrUndefined(s)){if("block"===this.textArea.style.display&&""!==this.selectedText()&&"mousedown"===t.type){r=this.textArea.value;this.textArea.value+="a",this.textArea.value=r}}else{var o=this.lowerCanvas.getBoundingClientRect();i-=o.left,s-=o.top;var a=void 0,n="";(a=0===this.activeObj.shapeDegree?this.degree:this.degree-this.activeObj.shapeDegree)<0&&(a=360+a),n=""===this.activeObj.textFlip?this.activeObj.textFlip===this.currFlipState?"":this.currFlipState:this.activeObj.textFlip===this.currFlipState?"":""===this.currFlipState?this.activeObj.textFlip:this.currFlipState;var r=void 0;if("none"===this.textArea.style.display){r=e.extend({},this.activeObj,{},!0);for(var h=0;h<this.objColl.length;h++)JSON.stringify(this.activeObj)===JSON.stringify(this.objColl[h])&&this.objColl.splice(h,1);this.refreshActiveObj(),this.lowerContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),this.redrawImgWithObj(),(!e.isNullOrUndefined(this.currSelectionPoint)&&"crop-circle"===this.currSelectionPoint.shape||this.isCircleCrop)&&this.cropCircle(this.lowerContext),this.activeObj=r,this.updateFontStyles();var l=e.extend({},this.activeObj,{},!0);if(i>=l.activePoint.startX-2*l.topLeftCircle.radius&&i<=l.activePoint.endX+2*l.topLeftCircle.radius&&s>=l.activePoint.startY-2*l.topLeftCircle.radius&&s<=l.activePoint.endY+2*l.topLeftCircle.radius){if(this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),4===l.flipObjColl.length&&(l.flipObjColl=[],n=""),""===n&&l.flipObjColl.length>1&&(n=l.flipObjColl[l.flipObjColl.length-1]),l.flipObjColl.length<=1)i=(c=this.setTextBoxPos(l,a,n,i,s)).x,s=c.y;else{var c=this.setTextBoxPoints(l,a,n,i,s);i=c.x,s=c.y}this.textArea.style.display="block",this.textArea.style.left=i+"px",this.textArea.style.top=s+"px",this.textArea.style.fontFamily=l.textSettings.fontFamily,this.textArea.style.fontSize=l.textSettings.fontSize+"px",this.textArea.style.color=l.strokeSettings.strokeColor,this.textArea.style.fontWeight=l.textSettings.bold?"bold":"normal",this.textArea.style.fontStyle=l.textSettings.italic?"italic":"normal",this.textArea.style.border="2px solid "+this.themeColl[this.theme].primaryColor,this.textArea.value=l.keyHistory,this.textArea.style.overflow="hidden",this.textArea.style.height="auto",this.textArea.focus(),a%90==0&&a%180!=0&&0!==a?(this.zoomFactor,this.textArea.style.width=l.activePoint.height+"px",this.textArea.style.height=l.activePoint.width+"px"):(this.zoomFactor,this.textArea.style.width=l.activePoint.width+"px",this.textArea.style.height=l.activePoint.height+"px"),this.setTextBoxWidth(),this.flipColl.length<=1&&this.setTextBoxHeight()}else this.applyActObj()}}},l.prototype.selectedText=function(){var t=this.textArea.selectionStart,e=this.textArea.selectionEnd;return this.textArea.value.substring(t,e)},l.prototype.setTextBoxHeight=function(){var t,i,s="",o=e.extend({},this.activeObj,{},!0);(i=0===o.shapeDegree?this.degree:this.degree-o.shapeDegree)<0&&(i=360+i),s=""===o.textFlip?o.textFlip===this.currFlipState?"":this.currFlipState:o.textFlip===this.currFlipState?"":""===this.currFlipState?o.textFlip:this.currFlipState,0===i?"vertical"===s.toLowerCase()?this.textArea.style.maxHeight=this.destHeight-(this.destHeight-parseFloat(this.textArea.style.top))+"px":(t=parseFloat(this.textArea.style.top)-this.destTop,this.textArea.style.maxHeight=this.destHeight-t+"px"):90===i?"horizontal"===s.toLowerCase()?this.textArea.style.maxHeight=this.destWidth-(parseFloat(this.textArea.style.left)-this.destLeft)+"px":this.textArea.style.maxHeight=parseFloat(this.textArea.style.left)-this.destLeft+"px":180===i?"vertical"===s.toLowerCase()?(t=parseFloat(this.textArea.style.top)-this.destTop,this.textArea.style.maxHeight=this.destHeight-t+"px"):this.textArea.style.maxHeight=parseFloat(this.textArea.style.top)-this.destTop+"px":270===i&&("horizontal"===s.toLowerCase()?this.textArea.style.maxHeight=parseFloat(this.textArea.style.left)-this.destLeft+"px":this.textArea.style.maxHeight=this.destWidth-(parseFloat(this.textArea.style.left)-this.destLeft)+"px")},l.prototype.setTextBoxWidth=function(t){var i=this.getMaxText(!0);"block"===this.textArea.style.display?this.updateFontStyles(!0):this.updateFontStyles();var s,o=this.upperContext.measureText(i).width+parseFloat(this.textArea.style.fontSize)/2,a=t?this.upperContext.measureText(String.fromCharCode(t.which)).width:0,n=e.extend({},this.activeObj,{},!0),r="";(s=0===n.shapeDegree?this.degree:this.degree-n.shapeDegree)<0&&(s=360+s),r=n.shapeFlip!==this.currFlipState?"":this.currFlipState,(!e.isNullOrUndefined(t)&&parseFloat(this.textArea.style.width)<o+a||e.isNullOrUndefined(t))&&(0===s?"horizontal"===r.toLowerCase()?parseFloat(this.textArea.style.left)-this.destLeft-o-a>0&&(this.textArea.style.width=o+a+"px"):this.destWidth-(parseFloat(this.textArea.style.left)-this.destLeft)>o+a&&(this.textArea.style.width=o+a+"px"):90===s?"vertical"===r.toLowerCase()?parseFloat(this.textArea.style.top)-this.destTop-o-a>0&&(this.textArea.style.width=o+a+"px"):this.destWidth-(parseFloat(this.textArea.style.top)-this.destTop)>o+a&&(this.textArea.style.width=o+a+"px"):180===s?"horizontal"===r.toLowerCase()?this.destWidth-(parseFloat(this.textArea.style.left)-this.destLeft)>o+a&&(this.textArea.style.width=o+a+"px"):parseFloat(this.textArea.style.left)-this.destLeft-o-a>0&&(this.textArea.style.width=o+a+"px"):270===s&&("vertical"===r.toLowerCase()?this.destHeight-(parseFloat(this.textArea.style.top)-this.destTop)>o+a&&(this.textArea.style.width=o+a+"px"):parseFloat(this.textArea.style.top)-this.destTop-o-a>0&&(this.textArea.style.width=o+a+"px")))},l.prototype.setActivePoint=function(t,i){if(!e.isNullOrUndefined(this.activeObj.activePoint))if(this.currObjType.isText){var s=t||0,o=i||this.activeObj.textSettings.fontSize;void 0===this.activeObj.textSettings.fontSize&&(this.activeObj.textSettings.fontSize=.1*Math.abs(this.baseImg.width-this.baseImg.height)),this.setTextSelection(s,o),this.mouseDownPoint.x=this.activeObj.activePoint.endX,this.mouseDownPoint.y=this.activeObj.activePoint.endY,void 0!==this.activeObj.horTopLine&&(this.activeObj.activePoint=e.extend({},this.activeObj.activePoint,{},!0)),this.drawObject("duplicate")}else if(t&&i)this.activeObj.activePoint.startX=this.mouseDownPoint.x=t,this.activeObj.activePoint.startY=this.mouseDownPoint.y=i,this.currObjType.isDragging=!0;else{var a=this.activeObj;this.activeObj.activePoint={startX:a.horTopLine.startX,startY:a.horTopLine.startY,endX:a.horTopLine.endX,endY:a.horTopLine.endY},this.activeObj.activePoint.width=this.activeObj.activePoint.endX-this.activeObj.activePoint.startX,this.activeObj.activePoint.height=this.activeObj.activePoint.endY-this.activeObj.activePoint.startY}},l.prototype.setDragWidth=function(t){var e=t;if(e>=0)for(i=0;i<e&&(t=e-i,this.activeObj.activePoint.startX+=t,this.activeObj.activePoint.endX+=t,!(this.activeObj.activePoint.startX>=this.destLeft&&this.activeObj.activePoint.endX<=this.destLeft+this.destWidth));i++)this.activeObj.activePoint.startX-=t,this.activeObj.activePoint.endX-=t;else for(var i=1;i<Math.abs(e)&&(t=e+i,this.activeObj.activePoint.startX+=t,this.activeObj.activePoint.endX+=t,!(this.activeObj.activePoint.startX>=this.destLeft&&this.activeObj.activePoint.endX<=this.destLeft+this.destWidth));i++)this.activeObj.activePoint.startX-=t,this.activeObj.activePoint.endX-=t},l.prototype.setDragHeight=function(t){var e=t;if(e>=0)for(i=1;i<e&&(t=e-i,this.activeObj.activePoint.startY+=t,this.activeObj.activePoint.endY+=t,!(this.activeObj.activePoint.startY>=this.destTop&&this.activeObj.activePoint.endY<=this.destTop+this.destHeight));i++)this.activeObj.activePoint.startY-=t,this.activeObj.activePoint.endY-=t;else for(var i=0;i<Math.abs(e)&&(t=e+i,this.activeObj.activePoint.startY+=t,this.activeObj.activePoint.endY+=t,!(this.activeObj.activePoint.startY>=this.destTop&&this.activeObj.activePoint.endY<=this.destTop+this.destHeight));i++)this.activeObj.activePoint.startY-=t,this.activeObj.activePoint.endY-=t},l.prototype.triggerShapeChange=function(t,e,i){this.activeObj.activePoint.width=this.activeObj.activePoint.endX-this.activeObj.activePoint.startX,this.activeObj.activePoint.height=this.activeObj.activePoint.endY-this.activeObj.activePoint.startY;var s=this.updatePreviousShapeSettings();t.currentShapeSettings=s,e.currentShapeSettings=s,"resize"===i?(this.trigger("shapeChanging",t),this.updateShapeChangeEventArgs(t.currentShapeSettings)):(this.trigger("shapeChanging",e),this.updateShapeChangeEventArgs(e.currentShapeSettings))},l.prototype.updateActivePoint=function(t,e,i){var s=this.calcMaxDimension(this.activeObj.activePoint.width,this.activeObj.activePoint.height),o=this.updatePreviousShapeSettings(),a={action:"resize",previousShapeSettings:o},n={action:"move",previousShapeSettings:o};switch("text"===this.activeObj.shape&&""!==this.dragElement&&this.updateFontRatio(this.activeObj),this.dragElement.toLowerCase()){case"nw-resize":this.updateNWPoints(t,e,s),this.triggerShapeChange(a,n,"resize");break;case"n-resize":this.updateNPoints(t,e),this.triggerShapeChange(a,n,"resize");break;case"ne-resize":this.updateNEPoints(t,e,s),this.triggerShapeChange(a,n,"resize");break;case"w-resize":this.updateWPoints(t,e),this.triggerShapeChange(a,n,"resize");break;case"e-resize":this.updateEPoints(t,e),this.triggerShapeChange(a,n,"resize");break;case"sw-resize":this.updateSWPoints(t,e,s),this.triggerShapeChange(a,n,"resize");break;case"s-resize":this.updateSPoints(t,e),this.triggerShapeChange(a,n,"resize");break;case"se-resize":this.updateSEPoints(t,e,s),this.triggerShapeChange(a,n,"resize");break;default:if(!i&&!this.currObjType.isCustomCrop){if(this.dragPoint.startX){var r=this.dragPoint.endX-this.previousPoint.x,h=this.dragPoint.endY-this.previousPoint.y;this.activeObj.activePoint.startX+=r,this.activeObj.activePoint.endX+=r,this.activeObj.activePoint.startY+=h,this.activeObj.activePoint.endY+=h,!this.isPreventDragging&&(this.activeObj.activePoint.startX<this.destLeft||this.activeObj.activePoint.startY<this.destTop||this.activeObj.activePoint.endX>this.destLeft+this.destWidth||this.activeObj.activePoint.endY>this.destTop+this.destHeight)&&(this.activeObj.activePoint.startX-=r,this.activeObj.activePoint.endX-=r,this.activeObj.activePoint.startY-=h,this.activeObj.activePoint.endY-=h,this.setDragWidth(r),this.setDragHeight(h))}else this.activeObj.activePoint.startX=t<this.mouseDownPoint.x?t:this.mouseDownPoint.x,this.activeObj.activePoint.startY=e<this.mouseDownPoint.y?e:this.mouseDownPoint.y,t=t<this.mouseDownPoint.x?this.mouseDownPoint.x:t,e=e<this.mouseDownPoint.y?this.mouseDownPoint.y:e,this.activeObj.activePoint.endX=t,this.activeObj.activePoint.endY=e;this.triggerShapeChange(a,n,"move")}}},l.prototype.preventDraggingInvertly=function(){this.isPreventDragging||(this.activeObj.activePoint.startX<this.destLeft&&(this.activeObj.activePoint.startX=this.destLeft),this.activeObj.activePoint.startY<this.destTop&&(this.activeObj.activePoint.startY=this.destTop),this.activeObj.activePoint.endX>this.destLeft+this.destWidth&&(this.activeObj.activePoint.endX=this.destLeft+this.destWidth),this.activeObj.activePoint.endY>this.destTop+this.destHeight&&(this.activeObj.activePoint.endY=this.destTop+this.destHeight))},l.prototype.updateNWPoints=function(t,i,s){var o,a,n,r,h=this.diffPoint.x,l=this.diffPoint.y,c=e.extend({},this.activeObj,null,!0);if("text"===this.activeObj.shape)void 0===this.oldPoint.x&&void 0===this.oldPoint.y?(this.diffPoint.x=this.activeObj.activePoint.startX-t,this.diffPoint.y=this.activeObj.activePoint.startY-i):(this.diffPoint.x=this.oldPoint.x-t,this.diffPoint.y=this.oldPoint.y-i),this.oldPoint.x=t,this.oldPoint.y=i,r=(this.diffPoint.x<=h&&this.diffPoint.y>=l?Math.min(this.diffPoint.x,this.diffPoint.y):Math.max(this.diffPoint.x,this.diffPoint.y))/10,this.activeObj.activePoint.startX-=s.width/100*r,this.activeObj.activePoint.startY-=s.height/100*r,this.activeObj.activePoint.width=this.activeObj.activePoint.endX-this.activeObj.activePoint.startX,this.activeObj.activePoint.height=this.activeObj.activePoint.endY-this.activeObj.activePoint.startY,this.updateFontSize(this.activeObj);else{var d=void 0;if(void 0!==this.activeObj.shape&&(d=this.activeObj.shape.split("-")),"crop-custom"===this.activeObj.shape||void 0!==this.activeObj.shape&&"crop"!==d[0]){if(this.activeObj.activePoint.startX=t,this.activeObj.activePoint.startY=i,this.activeObj.activePoint.startX>this.activeObj.activePoint.endX){p=this.activeObj.activePoint.startX;this.activeObj.activePoint.startX=this.activeObj.activePoint.endX,this.activeObj.activePoint.endX=p,this.dragElement="ne-resize"}if(this.activeObj.activePoint.startY>this.activeObj.activePoint.endY){var p=this.activeObj.activePoint.startY;this.activeObj.activePoint.startY=this.activeObj.activePoint.endY,this.activeObj.activePoint.endY=p,this.dragElement="sw-resize"}this.preventDraggingInvertly()}else if(this.activeObj.activePoint.startX<t&&this.activeObj.activePoint.startY<i){o=t-this.activeObj.activePoint.startX,a=i-this.activeObj.activePoint.startY,n=Math.min(o,a);u=this.getScaleRatio(n);this.activeObj.activePoint.startX+=u.x,this.activeObj.activePoint.startY+=u.y;var v=this.destLeft>0?this.destLeft:0,b=this.destTop>0?this.destTop:0;(this.activeObj.activePoint.startX<v||this.activeObj.activePoint.startY<b)&&(this.activeObj.activePoint.startX-=u.x,this.activeObj.activePoint.startY-=u.y)}else{o=this.activeObj.activePoint.startX-t,a=i-this.activeObj.activePoint.endY,n=Math.max(o,a);var u=this.getScaleRatio(n);this.activeObj.activePoint.startX-=u.x,this.activeObj.activePoint.startY-=u.y;var v=this.destLeft>0?this.destLeft:0,C=this.destTop>0?this.destTop:0;(this.activeObj.activePoint.startX<v||this.activeObj.activePoint.startY<C)&&(this.activeObj.activePoint.startX+=u.x,this.activeObj.activePoint.startY+=u.y)}this.activeObj.activePoint.width=this.activeObj.activePoint.endX-this.activeObj.activePoint.startX,this.activeObj.activePoint.height=this.activeObj.activePoint.endY-this.activeObj.activePoint.startY,this.preventInverseResize(c)}},l.prototype.updateNPoints=function(t,e){var i,s,o;if("text"!==this.activeObj.shape){var a=void 0;if(void 0!==this.activeObj.shape&&(a=this.activeObj.shape.split("-")),"crop-custom"===this.activeObj.shape||void 0!==this.activeObj.shape&&"crop"!==a[0]){if(this.activeObj.activePoint.startY=e,this.activeObj.activePoint.height=this.activeObj.activePoint.endY-this.activeObj.activePoint.startY,this.activeObj.activePoint.startY>this.activeObj.activePoint.endY){var n=this.activeObj.activePoint.startY;this.activeObj.activePoint.startY=this.activeObj.activePoint.endY,this.activeObj.activePoint.endY=n,this.dragElement="s-resize"}this.preventDraggingInvertly()}else{if(this.activeObj.activePoint.endX>t&&this.activeObj.activePoint.startY<e){i=this.activeObj.activePoint.endX-t,s=e-this.activeObj.activePoint.startY,o=Math.min(i,s);r=this.getScaleRatio(o);this.activeObj.activePoint.endX-=r.x,this.activeObj.activePoint.startY+=r.y,(this.activeObj.activePoint.endX>this.destLeft+this.destWidth||this.activeObj.activePoint.startY<this.destTop)&&(this.activeObj.activePoint.endX+=r.x,this.activeObj.activePoint.startY-=r.y)}else{i=t-this.activeObj.activePoint.endX,s=this.activeObj.activePoint.startY-e,o=Math.max(i,s);var r=this.getScaleRatio(o);this.activeObj.activePoint.endX+=r.x,this.activeObj.activePoint.startY-=r.y,(this.activeObj.activePoint.endX>this.destLeft+this.destWidth||this.activeObj.activePoint.startY<this.destTop)&&(this.activeObj.activePoint.endX-=r.x,this.activeObj.activePoint.startY+=r.y)}this.activeObj.activePoint.width=this.activeObj.activePoint.endX-this.activeObj.activePoint.startX,this.activeObj.activePoint.height=this.activeObj.activePoint.endY-this.activeObj.activePoint.startY}}},l.prototype.updateNEPoints=function(t,i,s){var o,a,n,r,h=this.diffPoint.x,l=this.diffPoint.y,c=e.extend({},this.activeObj,null,!0);if("text"===this.activeObj.shape)void 0===this.oldPoint.x&&void 0===this.oldPoint.y?(this.diffPoint.x=t-this.activeObj.activePoint.endX,this.diffPoint.y=this.activeObj.activePoint.startY-i):(this.diffPoint.x=t-this.oldPoint.x,this.diffPoint.y=this.oldPoint.y-i),this.oldPoint.x=t,this.oldPoint.y=i,r=(this.diffPoint.x<=h&&this.diffPoint.y>=l?Math.min(this.diffPoint.x,this.diffPoint.y):Math.max(this.diffPoint.x,this.diffPoint.y))/10,this.activeObj.activePoint.endX+=s.width/100*r,this.activeObj.activePoint.startY-=s.height/100*r,this.activeObj.activePoint.width=this.activeObj.activePoint.endX-this.activeObj.activePoint.startX,this.activeObj.activePoint.height=this.activeObj.activePoint.endY-this.activeObj.activePoint.startY,this.updateFontSize(this.activeObj);else{var d=void 0;if(void 0!==this.activeObj.shape&&(d=this.activeObj.shape.split("-")),this.currObjType.isCustomCrop||void 0!==this.activeObj.shape&&"crop"!==d[0]){if(this.activeObj.activePoint.endX=t,this.activeObj.activePoint.startY=i,this.activeObj.activePoint.endX<this.activeObj.activePoint.startX){p=this.activeObj.activePoint.endX;this.activeObj.activePoint.endX=this.activeObj.activePoint.startX,this.activeObj.activePoint.startX=p,this.dragElement="nw-resize"}if(this.activeObj.activePoint.startY>this.activeObj.activePoint.endY){var p=this.activeObj.activePoint.startY;this.activeObj.activePoint.startY=this.activeObj.activePoint.endY,this.activeObj.activePoint.endY=p,this.dragElement="se-resize"}this.preventDraggingInvertly()}else if(this.activeObj.activePoint.endX>t&&this.activeObj.activePoint.startY<i){o=this.activeObj.activePoint.endX-t,a=i-this.activeObj.activePoint.startY,n=Math.min(o,a);u=this.getScaleRatio(n);this.activeObj.activePoint.endX-=u.x,this.activeObj.activePoint.startY+=u.y;var v=this.destLeft+this.destWidth<this.lowerCanvas.width?this.destLeft+this.destWidth:this.lowerCanvas.width,b=this.destTop>0?this.destTop:0;(this.activeObj.activePoint.endX>v||this.activeObj.activePoint.startY<b)&&(this.activeObj.activePoint.endX+=u.x,this.activeObj.activePoint.startY-=u.y)}else{o=t-this.activeObj.activePoint.endX,a=this.activeObj.activePoint.startY-i,n=Math.max(o,a);var u=this.getScaleRatio(n);this.activeObj.activePoint.endX+=u.x,this.activeObj.activePoint.startY-=u.y;var v=this.destLeft+this.destWidth<this.lowerCanvas.width?this.destLeft+this.destWidth:this.lowerCanvas.width,b=this.destTop>0?this.destTop:0;(this.activeObj.activePoint.endX>v||this.activeObj.activePoint.startY<b)&&(this.activeObj.activePoint.endX-=u.x,this.activeObj.activePoint.startY+=u.y)}this.activeObj.activePoint.width=this.activeObj.activePoint.endX-this.activeObj.activePoint.startX,this.activeObj.activePoint.height=this.activeObj.activePoint.endY-this.activeObj.activePoint.startY,this.preventInverseResize(c)}},l.prototype.updateWPoints=function(t,e){var i,s,o;if("text"!==this.activeObj.shape){var a=void 0;if(void 0!==this.activeObj.shape&&(a=this.activeObj.shape.split("-")),"crop-custom"===this.activeObj.shape||void 0!==this.activeObj.shape&&"crop"!==a[0]){if(this.activeObj.activePoint.startX=t,this.activeObj.activePoint.width=this.activeObj.activePoint.endX-this.activeObj.activePoint.startX,this.activeObj.activePoint.startX>this.activeObj.activePoint.endX){var n=this.activeObj.activePoint.startX;this.activeObj.activePoint.startX=this.activeObj.activePoint.endX,this.activeObj.activePoint.endX=n,this.dragElement="e-resize"}this.preventDraggingInvertly()}else{if(this.activeObj.activePoint.startX<t&&this.activeObj.activePoint.endY>e){i=t-this.activeObj.activePoint.startX,s=this.activeObj.activePoint.endY-e,o=Math.min(i,s);r=this.getScaleRatio(o);this.activeObj.activePoint.startX+=r.x,this.activeObj.activePoint.endY-=r.y,(this.activeObj.activePoint.startX<this.destLeft||this.activeObj.activePoint.endY>this.destTop+this.destHeight)&&(this.activeObj.activePoint.startX-=r.x,this.activeObj.activePoint.endY+=r.y)}else{i=this.activeObj.activePoint.startX-t,s=e-this.activeObj.activePoint.endY,o=Math.max(i,s);var r=this.getScaleRatio(o);this.activeObj.activePoint.startX-=r.x,this.activeObj.activePoint.endY+=r.y,(this.activeObj.activePoint.startX<this.destLeft||this.activeObj.activePoint.endY>this.destTop+this.destHeight)&&(this.activeObj.activePoint.startX+=r.x,this.activeObj.activePoint.endY-=r.y)}this.activeObj.activePoint.width=this.activeObj.activePoint.endX-this.activeObj.activePoint.startX,this.activeObj.activePoint.height=this.activeObj.activePoint.endY-this.activeObj.activePoint.startY}}},l.prototype.updateEPoints=function(t,e){var i,s,o;if("text"!==this.activeObj.shape){var a=void 0;if(void 0!==this.activeObj.shape&&(a=this.activeObj.shape.split("-")),"crop-custom"===this.activeObj.shape||void 0!==this.activeObj.shape&&"crop"!==a[0]){if(this.activeObj.activePoint.endX=t,this.activeObj.activePoint.width=this.activeObj.activePoint.endX-this.activeObj.activePoint.startX,this.activeObj.activePoint.endX<this.activeObj.activePoint.startX){var n=this.activeObj.activePoint.endX;this.activeObj.activePoint.endX=this.activeObj.activePoint.startX,this.activeObj.activePoint.startX=n,this.dragElement="w-resize"}this.preventDraggingInvertly()}else{if(this.activeObj.activePoint.endX>t&&this.activeObj.activePoint.endY>e){i=this.activeObj.activePoint.endX-t,s=this.activeObj.activePoint.endY-e,o=Math.min(i,s);r=this.getScaleRatio(o);this.activeObj.activePoint.endX-=r.x,this.activeObj.activePoint.endY-=r.y,(this.activeObj.activePoint.endX>this.destLeft+this.destWidth||this.activeObj.activePoint.endY>this.destTop+this.destHeight)&&(this.activeObj.activePoint.endX+=r.x,this.activeObj.activePoint.endY+=r.y)}else{i=t-this.activeObj.activePoint.endX,s=e-this.activeObj.activePoint.endY,o=Math.max(i,s);var r=this.getScaleRatio(o);this.activeObj.activePoint.endX+=r.x,this.activeObj.activePoint.endY+=r.y,(this.activeObj.activePoint.endX>this.destLeft+this.destWidth||this.activeObj.activePoint.endY>this.destTop+this.destHeight)&&(this.activeObj.activePoint.endX-=r.x,this.activeObj.activePoint.endY-=r.y)}this.activeObj.activePoint.width=this.activeObj.activePoint.endX-this.activeObj.activePoint.startX,this.activeObj.activePoint.height=this.activeObj.activePoint.endY-this.activeObj.activePoint.startY}}},l.prototype.updateSWPoints=function(t,i,s){var o,a,n,r,h=this.diffPoint.x,l=this.diffPoint.y,c=e.extend({},this.activeObj,null,!0);if("text"===this.activeObj.shape)void 0===this.oldPoint.x&&void 0===this.oldPoint.y?(this.diffPoint.x=this.activeObj.activePoint.startX-t,this.diffPoint.y=i-this.activeObj.activePoint.endY):(this.diffPoint.x=this.oldPoint.x-t,this.diffPoint.y=i-this.oldPoint.y),this.oldPoint.x=t,this.oldPoint.y=i,r=(this.diffPoint.x<=h&&this.diffPoint.y>=l?Math.min(this.diffPoint.x,this.diffPoint.y):Math.max(this.diffPoint.x,this.diffPoint.y))/10,this.activeObj.activePoint.startX-=s.width/100*r,this.activeObj.activePoint.endY+=s.height/100*r,this.activeObj.activePoint.width=this.activeObj.activePoint.endX-this.activeObj.activePoint.startX,this.activeObj.activePoint.height=this.activeObj.activePoint.endY-this.activeObj.activePoint.startY,this.updateFontSize(this.activeObj);else{var d=void 0;if(void 0!==this.activeObj.shape&&(d=this.activeObj.shape.split("-")),"crop-custom"===this.activeObj.shape||void 0!==this.activeObj.shape&&"crop"!==d[0]){if(this.activeObj.activePoint.startX=t,this.activeObj.activePoint.endY=i,this.activeObj.activePoint.startX>this.activeObj.activePoint.endX){p=this.activeObj.activePoint.startX;this.activeObj.activePoint.startX=this.activeObj.activePoint.endX,this.activeObj.activePoint.endX=p,this.dragElement="se-resize"}if(this.activeObj.activePoint.endY<this.activeObj.activePoint.startY){var p=this.activeObj.activePoint.endY;this.activeObj.activePoint.endY=this.activeObj.activePoint.startY,this.activeObj.activePoint.startY=p,this.dragElement="nw-resize"}this.preventDraggingInvertly()}else if(this.activeObj.activePoint.startX<t&&this.activeObj.activePoint.endY>i){o=t-this.activeObj.activePoint.startX,a=this.activeObj.activePoint.endY-i,n=Math.min(o,a);u=this.getScaleRatio(n);this.activeObj.activePoint.startX+=u.x,this.activeObj.activePoint.endY-=u.y;var v=this.destLeft>0?this.destLeft:0,b=this.destTop+this.destHeight<this.lowerCanvas.height?this.destTop+this.destHeight:this.lowerCanvas.height;(this.activeObj.activePoint.startX<v||this.activeObj.activePoint.endY>b)&&(this.activeObj.activePoint.startX-=u.x,this.activeObj.activePoint.endY+=u.y)}else{o=this.activeObj.activePoint.startX-t,a=i-this.activeObj.activePoint.endY,n=Math.max(o,a);var u=this.getScaleRatio(n);this.activeObj.activePoint.startX-=u.x,this.activeObj.activePoint.endY+=u.y;var v=this.destLeft>0?this.destLeft:0,b=this.destTop+this.destHeight<this.lowerCanvas.height?this.destTop+this.destHeight:this.lowerCanvas.height;(this.activeObj.activePoint.startX<v||this.activeObj.activePoint.endY>b)&&(this.activeObj.activePoint.startX+=u.x,this.activeObj.activePoint.endY-=u.y)}this.activeObj.activePoint.width=this.activeObj.activePoint.endX-this.activeObj.activePoint.startX,this.activeObj.activePoint.height=this.activeObj.activePoint.endY-this.activeObj.activePoint.startY,this.preventInverseResize(c)}},l.prototype.updateSPoints=function(t,e){var i,s,o;if("text"!==this.activeObj.shape){var a=void 0;if(void 0!==this.activeObj.shape&&(a=this.activeObj.shape.split("-")),"crop-custom"===this.activeObj.shape||void 0!==this.activeObj.shape&&"crop"!==a[0]){if(this.activeObj.activePoint.endY=e,this.activeObj.activePoint.height=this.activeObj.activePoint.endY-this.activeObj.activePoint.startY,this.activeObj.activePoint.endY<this.activeObj.activePoint.startY){var n=this.activeObj.activePoint.endY;this.activeObj.activePoint.endY=this.activeObj.activePoint.startY,this.activeObj.activePoint.startY=n,this.dragElement="n-resize"}this.preventDraggingInvertly()}else{if(this.activeObj.activePoint.endX>t&&this.activeObj.activePoint.endY>e){i=this.activeObj.activePoint.endX-t,s=this.activeObj.activePoint.endY-e,o=Math.min(i,s);r=this.getScaleRatio(o);this.activeObj.activePoint.endX-=r.x,this.activeObj.activePoint.endY-=r.y,(this.activeObj.activePoint.endX>this.destLeft+this.destWidth||this.activeObj.activePoint.endY>this.destTop+this.destHeight)&&(this.activeObj.activePoint.endX+=r.x,this.activeObj.activePoint.endY+=r.y)}else{i=t-this.activeObj.activePoint.endX,s=e-this.activeObj.activePoint.endY,o=Math.max(i,s);var r=this.getScaleRatio(o);this.activeObj.activePoint.endX+=r.x,this.activeObj.activePoint.endY+=r.x,(this.activeObj.activePoint.endX>this.destLeft+this.destWidth||this.activeObj.activePoint.endY>this.destTop+this.destHeight)&&(this.activeObj.activePoint.endX-=r.x,this.activeObj.activePoint.endY-=r.y)}this.activeObj.activePoint.width=this.activeObj.activePoint.endX-this.activeObj.activePoint.startX,this.activeObj.activePoint.height=this.activeObj.activePoint.endY-this.activeObj.activePoint.startY}}},l.prototype.updateSEPoints=function(t,i,s){var o,a,n,r,h=this.diffPoint.x,l=this.diffPoint.y,c=e.extend({},this.activeObj,null,!0);if("text"===this.activeObj.shape)void 0===this.oldPoint.x&&void 0===this.oldPoint.y?(this.diffPoint.x=t-this.activeObj.activePoint.endX,this.diffPoint.y=i-this.activeObj.activePoint.endY):(this.diffPoint.x=t-this.oldPoint.x,this.diffPoint.y=i-this.oldPoint.y),this.oldPoint.x=t,this.oldPoint.y=i,r=(this.diffPoint.x>=h&&this.diffPoint.y>=l?Math.max(this.diffPoint.x,this.diffPoint.y):Math.min(this.diffPoint.x,this.diffPoint.y))/10,this.activeObj.activePoint.endX+=s.width/50*r,this.activeObj.activePoint.endY+=s.height/50*r,this.activeObj.activePoint.width=this.activeObj.activePoint.endX-this.activeObj.activePoint.startX,this.activeObj.activePoint.height=this.activeObj.activePoint.endY-this.activeObj.activePoint.startY,this.updateFontSize(this.activeObj);else{var d=void 0;if(void 0!==this.activeObj.shape&&(d=this.activeObj.shape.split("-")),"crop-custom"===this.activeObj.shape||void 0!==this.activeObj.shape&&"crop"!==d[0]){if(this.activeObj.activePoint.endX=t,this.activeObj.activePoint.endY=i,this.activeObj.activePoint.endX<this.activeObj.activePoint.startX){p=this.activeObj.activePoint.endX;this.activeObj.activePoint.endX=this.activeObj.activePoint.startX,this.activeObj.activePoint.startX=p,this.dragElement="sw-resize"}if(this.activeObj.activePoint.endY<this.activeObj.activePoint.startY){var p=this.activeObj.activePoint.endY;this.activeObj.activePoint.endY=this.activeObj.activePoint.startY,this.activeObj.activePoint.startY=p,this.dragElement="ne-resize"}this.preventDraggingInvertly()}else if(this.activeObj.activePoint.endX>t&&this.activeObj.activePoint.endY>i){o=this.activeObj.activePoint.endX-t,a=this.activeObj.activePoint.endY-i,n=Math.min(o,a);u=this.getScaleRatio(n);this.activeObj.activePoint.endX-=u.x,this.activeObj.activePoint.endY-=u.y;var v=this.destLeft+this.destWidth<this.lowerCanvas.width?this.destLeft+this.destWidth:this.lowerCanvas.width,b=this.destTop+this.destHeight<this.lowerCanvas.height?this.destTop+this.destHeight:this.lowerCanvas.height;(this.activeObj.activePoint.endX>v||this.activeObj.activePoint.endY>b)&&(this.activeObj.activePoint.endX+=u.x,this.activeObj.activePoint.endY+=u.y)}else{o=t-this.activeObj.activePoint.endX,a=i-this.activeObj.activePoint.endY,n=Math.max(o,a);var u=this.getScaleRatio(n);this.activeObj.activePoint.endX+=u.x,this.activeObj.activePoint.endY+=u.y;var v=this.destLeft+this.destWidth<this.lowerCanvas.width?this.destLeft+this.destWidth:this.lowerCanvas.width,b=this.destTop+this.destHeight<this.lowerCanvas.height?this.destTop+this.destHeight:this.lowerCanvas.height;(this.activeObj.activePoint.endX>v||this.activeObj.activePoint.endY>b)&&(this.activeObj.activePoint.endX-=u.x,this.activeObj.activePoint.endY-=u.y)}this.activeObj.activePoint.width=this.activeObj.activePoint.endX-this.activeObj.activePoint.startX,this.activeObj.activePoint.height=this.activeObj.activePoint.endY-this.activeObj.activePoint.startY,this.preventInverseResize(c)}},l.prototype.updateFontRatio=function(t,i){var s;s=0===t.shapeDegree?this.degree:this.degree-t.shapeDegree,e.isNullOrUndefined(i)?t.textSettings.fontRatio=0===s||180===s?t.activePoint.width/t.textSettings.fontSize:t.activePoint.height/t.textSettings.fontSize:i&&(t.textSettings.fontRatio=0===s||180===s?this.textArea.clientWidth/parseFloat(this.textArea.style.fontSize):this.textArea.clientHeight/parseFloat(this.textArea.style.fontSize))},l.prototype.updateFontSize=function(t){var e;e=0===t.shapeDegree?this.degree:this.degree-t.shapeDegree,t.textSettings.fontSize=0===e||180===e?t.activePoint.width/t.textSettings.fontRatio:t.activePoint.height/t.textSettings.fontRatio},l.prototype.preventInverseResize=function(t){this.activeObj.activePoint.width<0&&(this.activeObj.activePoint.width=0,this.activeObj.activePoint.startX=t.activePoint.startX,this.activeObj.activePoint.endX=t.activePoint.endX),this.activeObj.activePoint.height<0&&(this.activeObj.activePoint.height=0,this.activeObj.activePoint.startY=t.activePoint.startY,this.activeObj.activePoint.endY=t.activePoint.endY)},l.prototype.getScaleRatio=function(t){var e={x:t,y:t};if("crop-custom"!==this.activeObj.shape&&"crop-circle"!==this.activeObj.shape&&"crop-square"!==this.activeObj.shape){var i=this.activeObj.shape.split("-");i=i[1].split(":");var s=t/parseInt(i[1],10);e.x=s*parseInt(i[0],10),e.y=s*parseInt(i[1],10)}return e},l.prototype.getMaxText=function(t,i){e.isNullOrUndefined(i)&&(i=t?this.textArea.value:this.activeObj.keyHistory);for(var s,o=i.split("\n"),a=o[0].length,n=o[0],r=1;r<o.length;r++)(s=o[r].length)>a&&(n=o[r],a=s);return n},l.prototype.setDragLimit=function(){this.activeObj.activePoint&&(this.activeObj.activePoint.startX<this.destLeft?(this.activeObj.activePoint.startX=this.destLeft,this.activeObj.activePoint.endX=this.activeObj.activePoint.startX+this.activeObj.activePoint.width):this.activeObj.activePoint.endX>this.destLeft+this.destWidth&&(this.activeObj.activePoint.endX=this.destLeft+this.destWidth,this.activeObj.activePoint.startX=this.activeObj.activePoint.endX-this.activeObj.activePoint.width),this.activeObj.activePoint.startY<this.destTop?this.activeObj.activePoint.startY=this.destTop:this.activeObj.activePoint.endY>this.destTop+this.destHeight&&(this.activeObj.activePoint.endY=this.destTop+this.destHeight,this.activeObj.activePoint.startY=this.activeObj.activePoint.endY-this.activeObj.activePoint.height),this.activeObj.activePoint.width=this.activeObj.activePoint.endX-this.activeObj.activePoint.startX,this.activeObj.activePoint.height=this.activeObj.activePoint.endY-this.activeObj.activePoint.startY)},l.prototype.lineDraw=function(){this.activeObj.activePoint.height<10?(this.activeObj.activePoint.startY-=10,this.activeObj.activePoint.endY+=10,this.activeObj.lineDraw="horizontal"):this.activeObj.activePoint.width<10?(this.activeObj.activePoint.startX-=10,this.activeObj.activePoint.endX+=10,this.activeObj.lineDraw="vertical"):this.currObjType.isInitialLine&&(this.activeObj.lineDraw="normal",this.currObjType.isInitialLine=!1),this.activeObj.activePoint.width=this.activeObj.activePoint.endX-this.activeObj.activePoint.startX,this.activeObj.activePoint.height=this.activeObj.activePoint.endY-this.activeObj.activePoint.startY},l.prototype.shapeCircle=function(t,e,i){t.strokeStyle=this.themeColl[this.theme].primaryColor,t.clearRect(0,0,this.lowerCanvas.width,this.lowerCanvas.height),t.fillStyle="rgb(0, 0, 0, 0.5)",t.fillRect(0,0,this.lowerCanvas.width,this.lowerCanvas.height);var s=t.lineWidth;t.lineWidth=2,t.beginPath(),t.ellipse(this.activeObj.horTopLine.startX+e/2,this.activeObj.horTopLine.startY+i/2,e/2,i/2,0,0,2*Math.PI,!1),t.stroke(),t.closePath(),t.save(),t.beginPath(),t.arc((this.activeObj.activePoint.endX-this.activeObj.activePoint.startX)/2+this.activeObj.activePoint.startX,(this.activeObj.activePoint.endY-this.activeObj.activePoint.startY)/2+this.activeObj.activePoint.startY,this.activeObj.activePoint.width/2,0,2*Math.PI),t.closePath(),t.clip(),t.clearRect(0,0,this.lowerCanvas.width,this.lowerCanvas.height),t.restore(),t.lineWidth=s,this.drawOuterSelection(t,!0),this.currObjType.shape=""},l.prototype.drawOuterSelection=function(t,i){var s;t.lineWidth=.5,void 0!==this.activeObj.shape&&(s=this.activeObj.shape.split("-"));var o=e.extend({},this.activeObj,{},!0);void 0!==this.activeObj.shape&&(s=this.activeObj.shape.split("-")),(void 0===s||"crop"!==s[0])&&void 0!==this.activeObj.shape||i||(this.upperContext.fillStyle="rgb(0, 0, 0, 0.5)",this.upperContext.fillRect(0,0,this.lowerCanvas.width,this.lowerCanvas.height),this.upperContext.clearRect(this.activeObj.activePoint.startX,this.activeObj.activePoint.startY,this.activeObj.activePoint.width,this.activeObj.activePoint.height)),t.strokeStyle=this.themeColl[this.theme].primaryColor,t.fillStyle=this.themeColl[this.theme].secondaryColor,"rectangle"!==this.activeObj.shape&&(t.beginPath(),t.rect(o.activePoint.startX,o.activePoint.startY,o.activePoint.width,o.activePoint.height),t.stroke(),t.closePath()),t.lineWidth*=2,t.beginPath(),t.moveTo(o.topLeftCircle.startX,o.topLeftCircle.startY),t.arc(o.topLeftCircle.startX,o.topLeftCircle.startY,o.topLeftCircle.radius,0,2*Math.PI),t.moveTo(o.topRightCircle.startX,o.topRightCircle.startY),t.arc(o.topRightCircle.startX,o.topRightCircle.startY,o.topRightCircle.radius,0,2*Math.PI),t.moveTo(o.bottomLeftCircle.startX,o.bottomLeftCircle.startY),t.arc(o.bottomLeftCircle.startX,o.bottomLeftCircle.startY,o.bottomLeftCircle.radius,0,2*Math.PI),t.moveTo(o.bottomRightCircle.startX,o.bottomRightCircle.startY),t.arc(o.bottomRightCircle.startX,o.bottomRightCircle.startY,o.bottomRightCircle.radius,0,2*Math.PI),t.stroke(),t.fill(),t.closePath(),t.lineWidth/=2,void 0!==s&&"crop"===s[0]||"text"===this.activeObj.shape||this.drawCenterCircles(t),this.activeObj=e.extend({},o,{},!0)},l.prototype.drawObject=function(t,i,s,o,a,n){var r;if("original"===t.toLowerCase()?r=this.lowerContext:"duplicate"===t.toLowerCase()?r=this.upperContext:e.isNullOrUndefined(n)||(r=n),a||e.isNullOrUndefined(this.activeObj.shape)||this.setDragLimit(),this.currObjType.isLine&&"original"!==t&&!i&&this.lineDraw(),"crop"===this.currObjType.shape.split("-")[0].toLowerCase()&&s&&this.drawCropRatio(),o&&(this.activeObj.activePoint.startX=o.startX,this.activeObj.activePoint.startY=o.startY,this.activeObj.activePoint.endX=o.endX,this.activeObj.activePoint.endY=o.endY,this.activeObj.activePoint.width=o.width,this.activeObj.activePoint.height=o.height),e.isNullOrUndefined(this.activeObj.strokeSettings)&&(this.activeObj.strokeSettings=this.strokeSettings),e.isNullOrUndefined(this.activeObj.strokeSettings.strokeWidth)&&(this.activeObj.strokeSettings.strokeWidth=4),i&&(this.activeObj=e.extend({},i,{},!0)),this.updateActiveObject(),this.currObjType.isText&&(this.activeObj.keyHistory=this.keyHistory),"original"!==t.toLowerCase()){var h=!1;this.activeObj.shape&&"crop"===this.activeObj.shape.split("-")[0]&&(h=!0),h&&(this.upperContext.fillStyle="rgb(0, 0, 0, 0.5)",this.upperContext.fillRect(0,0,this.lowerCanvas.width,this.lowerCanvas.height),this.upperContext.clearRect(this.activeObj.activePoint.startX,this.activeObj.activePoint.startY,this.activeObj.activePoint.width,this.activeObj.activePoint.height)),r!==this.lowerContext&&r!==this.upperContext||this.drawOuterSelection(r)}this.currObjType.isActiveObj=!0,i?this.drawShapeObj(t,i.shape,n):""!==this.keyHistory&&this.currObjType.isText?this.drawShapeObj(t,"text",n):this.activeObj.shape?this.drawShapeObj(t,this.activeObj.shape,n):this.drawShapeObj(t,void 0,n),this.isAllowCropPan&&(this.isAllowCropPan=!1,this.tempPanMove=e.extend({},this.panMove,{},!0),this.currentPannedPoint=this.updatePanPoints(this.getCurrentPanRegion()),this.rotatePan())},l.prototype.rotateShape=function(t){t.beginPath(),t.moveTo(this.activeObj.horTopLine.startX,this.activeObj.horTopLine.startY),t.lineTo(this.activeObj.horTopLine.endX,this.activeObj.horTopLine.endY),t.moveTo(this.activeObj.horBottomLine.startX,this.activeObj.horBottomLine.startY),t.lineTo(this.activeObj.horBottomLine.endX,this.activeObj.horBottomLine.endY),t.moveTo(this.activeObj.verLeftLine.startX,this.activeObj.verLeftLine.startY),t.lineTo(this.activeObj.verLeftLine.endX,this.activeObj.verLeftLine.endY),t.moveTo(this.activeObj.verRightLine.startX,this.activeObj.verRightLine.startY),t.lineTo(this.activeObj.verRightLine.endX,this.activeObj.verRightLine.endY),t.stroke()},l.prototype.updateActiveObject=function(t,i,s,o,a){t=t||e.extend({},this.activeObj.activePoint,{},!0),i=i||e.extend({},this.activeObj,{},!0),t.width=t.endX-t.startX,t.height=t.endY-t.startY,o=o||0,a=a||0;var n=t.width/2,r=t.height/2;i.horTopLine={startX:t.startX+o,startY:t.startY-a,endX:t.endX+o,endY:t.endY+a},i.horBottomLine={startX:t.startX-o,startY:t.endY-a,endX:t.endX-o,endY:t.endY+a},i.verLeftLine={startX:t.startX+o,startY:t.startY-a,endX:t.startX-a,endY:t.endY-a},i.verRightLine={startX:t.endX+o,startY:t.startY+a,endX:t.endX-o,endY:t.endY+a},i.topLeftCircle={startX:t.startX,startY:t.startY,radius:i.horTopLine.endX?7.5:0},i.topCenterCircle={startX:t.startX+n,startY:t.startY,radius:i.horTopLine.endX?7.5:0},i.topRightCircle={startX:t.endX,startY:t.startY,radius:i.horTopLine.endX?7.5:0},i.centerLeftCircle={startX:t.startX,startY:t.startY+r,radius:i.horTopLine.endX?7.5:0},i.centerRightCircle={startX:t.endX,startY:t.startY+r,radius:i.horTopLine.endX?7.5:0},i.bottomLeftCircle={startX:t.startX,startY:t.endY,radius:i.horTopLine.endX?7.5:0},i.bottomCenterCircle={startX:t.startX+n,startY:t.endY,radius:i.horTopLine.endX?7.5:0},i.bottomRightCircle={startX:t.endX,startY:t.endY,radius:i.horTopLine.endX?7.5:0},i.activePoint=t,e.isNullOrUndefined(s)&&(this.activeObj=e.extend({},i,{},!0))},l.prototype.drawShapeObj=function(t,i,s){var o=void 0!==i?i:this.currObjType.shape;this.currObjType.shape=o;var a;"original"===t.toLowerCase()?a=this.lowerContext:"duplicate"===t.toLowerCase()?a=this.upperContext:e.isNullOrUndefined(s)||(a=s),"rectangle"!==this.currObjType.shape.toLowerCase()&&"ellipse"!==this.currObjType.shape.toLowerCase()&&"line"!==this.currObjType.shape.toLowerCase()||(this.activeObj.shape=this.currObjType.shape),a.strokeStyle=this.activeObj.strokeSettings.strokeColor,a.fillStyle="text"===i||"freehanddraw"===i?this.activeObj.strokeSettings.strokeColor:this.activeObj.strokeSettings.fillColor;var n=this.activeObj.activePoint.width/3,r=this.activeObj.activePoint.height/3,h=this.activeObj.activePoint.endX-this.activeObj.activePoint.startX,l=this.activeObj.activePoint.endY-this.activeObj.activePoint.startY;switch(this.currObjType.shape.toLowerCase()){case"rectangle":this.drawSquareLines(a),a===this.upperContext&&this.drawOuterSelection(a);break;case"ellipse":h=Math.abs(h),l=Math.abs(l),a.beginPath(),a.ellipse(this.activeObj.activePoint.startX+h/2,this.activeObj.activePoint.startY+l/2,h/2,l/2,0,0,2*Math.PI,!1),""!==this.activeObj.strokeSettings.fillColor&&(a.fillStyle=this.activeObj.strokeSettings.fillColor,a.fill()),a.ellipse(this.activeObj.activePoint.startX+h/2,this.activeObj.activePoint.startY+l/2,Math.abs(h/2-this.activeObj.strokeSettings.strokeWidth),Math.abs(l/2-this.activeObj.strokeSettings.strokeWidth),0,0,2*Math.PI,!1),a.fillStyle=this.activeObj.strokeSettings.strokeColor,a.fill("evenodd"),a.closePath(),a===this.upperContext&&this.drawOuterSelection(a);break;case"crop-circle":a===this.lowerContext&&(a=this.upperContext),this.shapeCircle(a,h,l);break;case"line":this.shapeLine(a,h,l),a===this.upperContext&&this.drawOuterSelection(a);break;case"text":this.shapeText(a);break;case"crop-square":case"crop-3:4":case"crop-4:3":case"crop-6:9":case"crop-9:6":case"crop-9:16":case"crop-16:9":a===this.lowerContext&&(a=this.upperContext),this.drawSelection(n,r),this.currObjType.shape="";break;default:this.drawSelection(n,r)}},l.prototype.shapeLine=function(t,e,i){var s,o,a,n,r;0===(r=0===this.activeObj.shapeDegree?this.degree:this.degree-this.activeObj.shapeDegree)||r%180==0?(s=this.activeObj.activePoint.startX,o=this.activeObj.activePoint.startY+i/2,a=this.activeObj.activePoint.endX,n=this.activeObj.activePoint.startY+i/2):(s=this.activeObj.activePoint.startX+e/2,o=this.activeObj.activePoint.startY,a=this.activeObj.activePoint.startX+e/2,n=this.activeObj.activePoint.endY);var h=t.lineWidth;switch(t.lineWidth=this.activeObj.strokeSettings.strokeWidth,t.beginPath(),this.activeObj.lineDraw.toLowerCase()){case"horizontal":case"vertical":t.moveTo(s,o),t.lineTo(a,n);break;case"normal":t.moveTo(this.activeObj.horTopLine.startX,this.activeObj.horTopLine.startY),t.lineTo(this.activeObj.horBottomLine.endX,this.activeObj.horBottomLine.endY)}t.stroke(),t.lineWidth=h},l.prototype.shapeText=function(t){for(var e=this.activeObj.keyHistory.split("\n"),i=((this.activeObj.textSettings.fontSize+.25*this.activeObj.textSettings.fontSize)*e.length-this.activeObj.textSettings.fontSize*e.length)/e.length,s=0;s<e.length;s++){var o=e[s],a=(s+1)*this.activeObj.textSettings.fontSize*.85+s*i;-360===this.degree&&(this.degree=0),0===this.degree||180===this.degree?this.activeObj.textSettings.fontSize>this.activeObj.activePoint.height&&(this.activeObj.textSettings.fontSize=this.activeObj.activePoint.height-.1*this.activeObj.activePoint.height):this.activeObj.textSettings.fontSize>this.activeObj.activePoint.width&&(this.activeObj.textSettings.fontSize=this.activeObj.activePoint.width-.1*this.activeObj.activePoint.width),t.strokeStyle=this.activeObj.strokeSettings.strokeColor,t.fillStyle=this.activeObj.strokeSettings.strokeColor;var n="";this.activeObj.textSettings.bold&&(n="bold "),this.activeObj.textSettings.italic&&(n="italic "),this.activeObj.textSettings.bold&&this.activeObj.textSettings.italic&&(n="italic bold "),t.font=n+this.activeObj.textSettings.fontSize+"px "+this.activeObj.textSettings.fontFamily,4===this.activeObj.flipObjColl.length&&(this.activeObj.flipObjColl=[]);for(var r=0;r<this.activeObj.flipObjColl.length;r++)"horizontal"===this.activeObj.flipObjColl[r].toLowerCase()?(t.translate(t.canvas.width,0),t.scale(-1,1),this.updateActPoint("horizontal",t)):"vertical"===this.activeObj.flipObjColl[r].toLowerCase()&&(t.translate(0,t.canvas.height),t.scale(1,-1),this.updateActPoint("vertical",t));this.activeObj.shapeDegree!==this.degree?this.rotateText(t):t.fillText(o,this.activeObj.activePoint.startX+.1*this.activeObj.textSettings.fontSize,this.activeObj.activePoint.startY+a);for(var h=0;h<this.activeObj.flipObjColl.length;h++)"horizontal"===this.activeObj.flipObjColl[h].toLowerCase()?(t.translate(t.canvas.width,0),t.scale(-1,1),this.updateActPoint("horizontal",t)):"vertical"===this.activeObj.flipObjColl[h].toLowerCase()&&(t.translate(0,t.canvas.height),t.scale(1,-1),this.updateActPoint("vertical",t))}this.currObjType.isText=!1},l.prototype.updateActPoint=function(t,e){"horizontal"===t.toLowerCase()?this.activeObj.activePoint.startX<=e.canvas.width/2?(this.activeObj.activePoint.startX=e.canvas.width/2+(e.canvas.width/2-this.activeObj.activePoint.endX),this.activeObj.activePoint.endX=this.activeObj.activePoint.startX+this.activeObj.activePoint.width,this.updateActiveObject(this.activeObj.activePoint,this.activeObj)):this.activeObj.activePoint.startX>=e.canvas.width/2&&(this.activeObj.activePoint.startX=e.canvas.width-this.activeObj.activePoint.endX,this.activeObj.activePoint.endX=this.activeObj.activePoint.startX+this.activeObj.activePoint.width,this.updateActiveObject(this.activeObj.activePoint,this.activeObj)):"vertical"===t.toLowerCase()&&(this.activeObj.activePoint.startY<=e.canvas.height/2?(this.activeObj.activePoint.startY=e.canvas.height/2+(e.canvas.height/2-this.activeObj.activePoint.endY),this.activeObj.activePoint.endY=this.activeObj.activePoint.startY+this.activeObj.activePoint.height,this.updateActiveObject(this.activeObj.activePoint,this.activeObj)):this.activeObj.activePoint.startY>=e.canvas.height/2&&(this.activeObj.activePoint.startY=e.canvas.height-this.activeObj.activePoint.endY,this.activeObj.activePoint.endY=this.activeObj.activePoint.startY+this.activeObj.activePoint.height,this.updateActiveObject(this.activeObj.activePoint,this.activeObj)))},l.prototype.drawSquareLines=function(t){var e;void 0!==this.activeObj.shape&&(e=this.activeObj.shape.split("-")),"crop"===e[0]?t.strokeStyle="#fff":t.strokeStyle=this.activeObj.strokeSettings.strokeColor,t.beginPath(),t.rect(this.activeObj.activePoint.startX,this.activeObj.activePoint.startY,this.activeObj.activePoint.width,this.activeObj.activePoint.height),""!==this.activeObj.strokeSettings.fillColor&&(t.fillStyle=this.activeObj.strokeSettings.fillColor,t.fill()),t.rect(this.activeObj.activePoint.startX+this.activeObj.strokeSettings.strokeWidth,this.activeObj.activePoint.startY+this.activeObj.strokeSettings.strokeWidth,this.activeObj.activePoint.width-2*this.activeObj.strokeSettings.strokeWidth,this.activeObj.activePoint.height-2*this.activeObj.strokeSettings.strokeWidth),t.fillStyle=this.activeObj.strokeSettings.strokeColor,t.fill("evenodd"),t.closePath()},l.prototype.drawSelection=function(t,e){this.upperContext.strokeStyle=this.themeColl[this.theme].primaryColor,this.upperContext.beginPath(),this.activeObj.horTopInnerLine={startX:this.activeObj.activePoint.startX,startY:this.activeObj.activePoint.startY+e,endX:this.activeObj.activePoint.endX,endY:this.activeObj.activePoint.endY+e},this.activeObj.horBottomInnerLine={startX:this.activeObj.activePoint.startX,startY:this.activeObj.activePoint.startY+2*e,endX:this.activeObj.activePoint.endX,endY:this.activeObj.activePoint.endY+2*e},this.activeObj.verLeftInnerLine={startX:this.activeObj.activePoint.startX+t,startY:this.activeObj.activePoint.startY,endX:this.activeObj.activePoint.startX+t,endY:this.activeObj.activePoint.endY},this.activeObj.verRightInnerLine={startX:this.activeObj.activePoint.startX+2*t,startY:this.activeObj.activePoint.startY,endX:this.activeObj.activePoint.startX+2*t,endY:this.activeObj.activePoint.endY},this.upperContext.moveTo(this.activeObj.horTopInnerLine.startX,this.activeObj.horTopInnerLine.startY),this.upperContext.lineTo(this.activeObj.horTopInnerLine.endX,this.activeObj.horTopInnerLine.startY),this.upperContext.moveTo(this.activeObj.horBottomInnerLine.startX,this.activeObj.horBottomInnerLine.startY),this.upperContext.lineTo(this.activeObj.horBottomInnerLine.endX,this.activeObj.horBottomInnerLine.startY),this.upperContext.moveTo(this.activeObj.verLeftInnerLine.startX,this.activeObj.verLeftInnerLine.startY),this.upperContext.lineTo(this.activeObj.verLeftInnerLine.endX,this.activeObj.verLeftInnerLine.endY),this.upperContext.moveTo(this.activeObj.verRightInnerLine.startX,this.activeObj.verRightInnerLine.startY),this.upperContext.lineTo(this.activeObj.verRightInnerLine.endX,this.activeObj.verRightInnerLine.endY),this.upperContext.stroke(),this.upperContext.closePath()},l.prototype.drawCenterCircles=function(t){t.lineWidth*=2,t.beginPath(),t.moveTo(this.activeObj.topCenterCircle.startX,this.activeObj.topCenterCircle.startY),t.arc(this.activeObj.topCenterCircle.startX,this.activeObj.topCenterCircle.startY,this.activeObj.topCenterCircle.radius,0,2*Math.PI),t.moveTo(this.activeObj.centerLeftCircle.startX,this.activeObj.centerLeftCircle.startY),t.arc(this.activeObj.centerLeftCircle.startX,this.activeObj.centerLeftCircle.startY,this.activeObj.centerLeftCircle.radius,0,2*Math.PI),t.moveTo(this.activeObj.centerRightCircle.startX,this.activeObj.centerRightCircle.startY),t.arc(this.activeObj.centerRightCircle.startX,this.activeObj.centerRightCircle.startY,this.activeObj.centerRightCircle.radius,0,2*Math.PI),t.moveTo(this.activeObj.bottomCenterCircle.startX,this.activeObj.bottomCenterCircle.startY),t.arc(this.activeObj.bottomCenterCircle.startX,this.activeObj.bottomCenterCircle.startY,this.activeObj.bottomCenterCircle.radius,0,2*Math.PI),t.stroke(),t.fill(),t.closePath(),t.lineWidth/=2},l.prototype.findTarget=function(t,e,i){if("mousedown"===i.toLowerCase()||"touchstart"===i.toLowerCase()){var s=!1;this.activeObj.shape&&"crop"===this.activeObj.shape.split("-")[0]&&(s=!0),this.findTargetObj(t,e,s),this.updateCursorStyles(t,e,i)}else switch(this.dragElement.toLowerCase()){case"nw-resize":this.activeObj.topLeftCircle.startX=t,this.activeObj.topLeftCircle.startY=e;break;case"n-resize":this.activeObj.topCenterCircle.startX=t,this.activeObj.topCenterCircle.startY=e;break;case"ne-resize":this.activeObj.topRightCircle.startX=t,this.activeObj.topRightCircle.startY=e;break;case"w-resize":this.activeObj.centerLeftCircle.startX=t,this.activeObj.centerLeftCircle.startY=e;break;case"e-resize":this.activeObj.centerRightCircle.startX=t,this.activeObj.centerRightCircle.startY=e;break;case"sw-resize":this.activeObj.bottomLeftCircle.startX=t,this.activeObj.bottomLeftCircle.startY=e;break;case"s-resize":this.activeObj.bottomCenterCircle.startX=t,this.activeObj.bottomCenterCircle.startY=e;break;case"se-resize":this.activeObj.bottomRightCircle.startX=t,this.activeObj.bottomRightCircle.startY=e;break;default:this.dragPoint.startX&&this.dragPoint.startY&&(this.previousPoint.x=this.dragPoint.endX,this.previousPoint.y=this.dragPoint.endY,this.dragPoint.endX=t,this.dragPoint.endY=e)}},l.prototype.findTargetObj=function(t,i,s){var o;if(0!==this.objColl.length&&!this.currObjType.isCustomCrop&&!s){for(var a=0,n=void 0,r=0;r<this.objColl.length;r++){var h=e.extend({},this.objColl[r],{},!0);t>=h.activePoint.startX-2*h.topLeftCircle.radius&&t<=h.activePoint.endX+2*h.topLeftCircle.radius&&i>=h.activePoint.startY-2*h.topLeftCircle.radius&&i<=h.activePoint.endY+2*h.topLeftCircle.radius&&(this.isTouch||"move"===this.upperCanvas.style.cursor||"grab"===this.upperCanvas.style.cursor||this.isShapeInserted?(0===a||a>t-h.activePoint.startX)&&(a=t-this.objColl[r].activePoint.startX,n=r):this.objColl[r].currIndex===this.tempActiveObj.currIndex&&(n=r))}if(e.isNullOrUndefined(n))this.refreshActiveObj(),o=!1;else{this.tempObjColl=e.extend([],this.objColl,[],!0),this.currObjType.isCustomCrop=!1,this.activeObj=e.extend({},this.objColl[n],{},!0);var l=e.extend({},this.objColl[n],{},!0);if(this.objColl.splice(n,1),0===this.degree){this.lowerContext.clearRect(0,0,this.lowerCanvas.width,this.lowerCanvas.height),this.updateBrightnessFilter(),this.lowerContext.drawImage(this.baseImg,this.srcLeft,this.srcTop,this.srcWidth,this.srcHeight,this.destLeft,this.destTop,this.destWidth,this.destHeight);var c=this.lowerContext.filter;this.lowerContext.filter="none",this.iterateObjColl(),this.activeObj=e.extend({},c,{},!0),this.freehandRedraw(this.lowerContext),this.lowerContext.filter=c,this.getCurrentFlipState()}else this.callUpdateCurrentTransformedState(),this.freehandRedraw(this.lowerContext);this.clearOuterCanvas(this.lowerContext),(!e.isNullOrUndefined(this.currSelectionPoint)&&"crop-circle"===this.currSelectionPoint.shape||this.isCircleCrop)&&this.cropCircle(this.lowerContext),this.setActivePoint(),this.activeObj=e.extend({},l,{},!0),this.tempStrokeSettings=e.extend({},this.activeObj.strokeSettings,{},!0),this.tempTextSettings=e.extend({},this.activeObj.textSettings,{},!0);var d=this.updatePreviousShapeSettings(),p={action:"select",previousShapeSettings:d,currentShapeSettings:d};this.trigger("shapeChanging",p),this.updateShapeChangeEventArgs(p.currentShapeSettings),this.activeObj.activePoint&&(this.drawObject("duplicate",this.activeObj,null,null,!0),this.activeObj.activePoint.startX<this.destLeft?this.isPreventDragging=!0:this.activeObj.activePoint.endX>this.destLeft+this.destWidth?this.isPreventDragging=!0:this.activeObj.activePoint.startY<this.destTop?this.isPreventDragging=!0:this.activeObj.activePoint.endY>this.destTop+this.destHeight&&(this.isPreventDragging=!0)),o=!0}}return o},l.prototype.getCurrentFlipState=function(){if(0!==this.rotateFlipColl.length){var t=e.extend({},this.totalPannedInternalPoint,{},!0);this.callUpdateCurrentTransformedState(),this.totalPannedInternalPoint=t}else this.callUpdateCurrentTransformedState()},l.prototype.rotateDegree=function(t){this.lowerContext.save(),this.lowerContext.clearRect(0,0,this.lowerCanvas.width,this.lowerCanvas.height),this.lowerContext.translate(this.lowerCanvas.width/2,this.lowerCanvas.height/2),this.lowerContext.rotate(Math.PI/180*t),this.lowerContext.translate(-this.lowerCanvas.width/2,-this.lowerCanvas.height/2);var e=this.lowerContext.filter;this.updateBrightnessFilter(),this.lowerContext.drawImage(this.baseImg,this.srcLeft,this.srcTop,this.srcWidth,this.srcHeight,this.destLeft,this.destTop,this.destWidth,this.destHeight),this.lowerContext.filter=e,this.lowerContext.translate(this.lowerCanvas.width/2,this.lowerCanvas.height/2),this.lowerContext.rotate(Math.PI/180*-t),this.lowerContext.translate(-this.lowerCanvas.width/2,-this.lowerCanvas.height/2),this.lowerContext.restore()},l.prototype.updateCursorStyles=function(t,i,s){var o=!1;""===this.activeObj.keyHistory||void 0!==this.activeObj.shape||this.currObjType.isCustomCrop||this.currObjType.isLine||!this.currObjType.isText||(this.activeObj.shape="text");var a=e.extend({},this.activeObj,{},!0);e.isNullOrUndefined(a.topLeftCircle)||(t>=a.topLeftCircle.startX-2*a.topLeftCircle.radius&&t<=a.topLeftCircle.startX+2*a.topLeftCircle.radius&&i>=a.topLeftCircle.startY-2*a.topLeftCircle.radius&&i<=a.topLeftCircle.startY+2*a.topLeftCircle.radius&&"nw-resize"!==this.dragElement?(a.topLeftCircle.startX=a.topLeftCircle.startY=0,this.upperCanvas.style.cursor="nw-resize",o=!0,this.dragElement=this.upperCanvas.style.cursor):t>=a.topCenterCircle.startX-2*a.topLeftCircle.radius&&t<=a.topCenterCircle.startX+2*a.topLeftCircle.radius&&i>=a.topCenterCircle.startY-2*a.topLeftCircle.radius&&i<=a.topCenterCircle.startY+2*a.topLeftCircle.radius&&"n-resize"!==this.dragElement?(a.topCenterCircle.startX=a.topCenterCircle.startY=0,this.upperCanvas.style.cursor="n-resize",o=!0,this.dragElement=this.upperCanvas.style.cursor):t>=a.topRightCircle.startX-2*a.topLeftCircle.radius&&t<=a.topRightCircle.startX+2*a.topLeftCircle.radius&&i>=a.topRightCircle.startY-2*a.topLeftCircle.radius&&i<=a.topRightCircle.startY+2*a.topLeftCircle.radius&&"ne-resize"!==this.dragElement?(a.topRightCircle.startX=a.topRightCircle.startY=0,this.upperCanvas.style.cursor="ne-resize",o=!0,this.dragElement=this.upperCanvas.style.cursor):t>=a.centerLeftCircle.startX-2*a.topLeftCircle.radius&&t<=a.centerLeftCircle.startX+2*a.topLeftCircle.radius&&i>=a.centerLeftCircle.startY-2*a.topLeftCircle.radius&&i<=a.centerLeftCircle.startY+2*a.topLeftCircle.radius&&"w-resize"!==this.dragElement?(a.centerLeftCircle.startX=a.centerLeftCircle.startY=0,this.upperCanvas.style.cursor="w-resize",o=!0,this.dragElement=this.upperCanvas.style.cursor):t>=a.centerRightCircle.startX-2*a.topLeftCircle.radius&&t<=a.centerRightCircle.startX+2*a.topLeftCircle.radius&&i>=a.centerRightCircle.startY-2*a.topLeftCircle.radius&&i<=a.centerRightCircle.startY+2*a.topLeftCircle.radius&&"e-resize"!==this.dragElement?(a.centerRightCircle.startX=a.centerRightCircle.startY=0,this.upperCanvas.style.cursor="e-resize",o=!0,this.dragElement=this.upperCanvas.style.cursor):t>=a.bottomLeftCircle.startX-2*a.topLeftCircle.radius&&t<=a.bottomLeftCircle.startX+2*a.topLeftCircle.radius&&i>=a.bottomLeftCircle.startY-2*a.topLeftCircle.radius&&i<=a.bottomLeftCircle.startY+2*a.topLeftCircle.radius&&"sw-resize"!==this.dragElement?(a.bottomLeftCircle.startX=a.bottomLeftCircle.startY=0,this.upperCanvas.style.cursor="sw-resize",o=!0,this.dragElement=this.upperCanvas.style.cursor):t>=a.bottomCenterCircle.startX-2*a.topLeftCircle.radius&&t<=a.bottomCenterCircle.startX+2*a.topLeftCircle.radius&&i>=a.bottomCenterCircle.startY-2*a.topLeftCircle.radius&&i<=a.bottomCenterCircle.startY+2*a.topLeftCircle.radius&&"s-resize"!==this.dragElement?(a.bottomCenterCircle.startX=a.bottomCenterCircle.startY=0,this.upperCanvas.style.cursor="s-resize",o=!0,this.dragElement=this.upperCanvas.style.cursor):t>=a.bottomRightCircle.startX-2*a.topLeftCircle.radius&&t<=a.bottomRightCircle.startX+2*a.topLeftCircle.radius&&i>=a.bottomRightCircle.startY-2*a.topLeftCircle.radius&&i<=a.bottomRightCircle.startY+2*a.topLeftCircle.radius&&"se-resize"!==this.dragElement?(a.bottomRightCircle.startX=a.bottomRightCircle.startY=0,this.upperCanvas.style.cursor="se-resize",o=!0,this.dragElement=this.upperCanvas.style.cursor):(this.dragPoint.startX=this.previousPoint.x=this.dragPoint.endX=t,this.dragPoint.startY=this.previousPoint.y=this.dragPoint.endY=i),this.previousPoint.x=this.previousPoint.y=this.diffPoint.x=this.diffPoint.y=0,"touchstart"===s?(o||t>=a.activePoint.startX&&t<=a.activePoint.endX&&i>=a.activePoint.startY&&i<=a.activePoint.endY)&&(this.currObjType.isDragging=!0):this.currObjType.isDragging=!0)},l.prototype.drawCropRatio=function(){var t,i,s,o;switch(this.zoomFactor>0&&!e.isNullOrUndefined(this.currentSelectionPoint)?(this.destLeft+this.destLeft+this.destWidth<=this.lowerCanvas.clientWidth?(s=this.destWidth,this.destLeft<0&&(s+=2*this.destLeft)):s=this.lowerCanvas.clientWidth,this.destTop+this.destTop+this.destHeight<=this.lowerCanvas.clientHeight?(o=this.destHeight,this.destTop<0&&(o+=2*this.destTop)):o=this.lowerCanvas.clientHeight,0!==this.degree&&(this.isAllowCropPan=!0)):(s=this.destWidth,o=this.destHeight,this.destLeft<0&&(s+=this.destLeft),this.destTop<0&&(o+=this.destTop),"crop-square"!==this.currObjType.shape.toLowerCase()&&"crop-circle"!==this.currObjType.shape.toLowerCase()&&(this.destLeft+this.destWidth>this.lowerCanvas.width&&(s-=this.destLeft+this.destWidth-this.lowerCanvas.width),this.destTop+this.destHeight>this.lowerCanvas.height&&(o-=this.destTop+this.destHeight-this.lowerCanvas.height))),this.currObjType.shape.toLowerCase()){case"crop-square":case"crop-circle":this.setDragDirection(s,o),s===this.destWidth&&o===this.destHeight&&(this.activeObj.activePoint.startX+=this.destLeft,this.activeObj.activePoint.startY+=this.destTop,this.activeObj.activePoint.endX+=this.destLeft,this.activeObj.activePoint.endY+=this.destTop),this.lowerCanvas.width>this.lowerCanvas.height?(this.activeObj.activePoint.height=this.activeObj.activePoint.endY-this.activeObj.activePoint.startY,this.activeObj.activePoint.width=this.activeObj.activePoint.height,this.activeObj.activePoint.endX=this.activeObj.activePoint.startX+this.activeObj.activePoint.width):(this.activeObj.activePoint.width=this.activeObj.activePoint.endX-this.activeObj.activePoint.startX,this.activeObj.activePoint.height=this.activeObj.activePoint.width,this.activeObj.activePoint.endY=this.activeObj.activePoint.startY+this.activeObj.activePoint.height);break;case"crop-3:2":t=3,i=2;break;case"crop-4:3":t=4,i=3;break;case"crop-5:4":t=5,i=4;break;case"crop-7:5":t=7,i=5;break;case"crop-16:9":t=16,i=9}if(void 0!==t&&void 0!==i&&(this.calcShapeRatio(t,i,s,o),s===this.destWidth&&o===this.destHeight&&this.updatePoints()),!e.isNullOrUndefined(this.currentSelectionPoint)){if(this.activeObj.activePoint.startX<this.currentSelectionPoint.activePoint.startX){a=this.currentSelectionPoint.activePoint.startX-this.activeObj.activePoint.startX;this.activeObj.activePoint.startX+=a,this.activeObj.activePoint.endX+=a}if(this.activeObj.activePoint.startY<this.currentSelectionPoint.activePoint.startY){a=this.currentSelectionPoint.activePoint.startY-this.activeObj.activePoint.startY;this.activeObj.activePoint.startY+=a,this.activeObj.activePoint.endY+=a}if(this.activeObj.activePoint.endX>this.currentSelectionPoint.activePoint.endX){a=this.activeObj.activePoint.endX-this.currentSelectionPoint.activePoint.endX;this.activeObj.activePoint.startX-=a,this.activeObj.activePoint.endX-=a}if(this.activeObj.activePoint.endY>this.currentSelectionPoint.activePoint.endY){a=this.activeObj.activePoint.endY-this.currentSelectionPoint.activePoint.endY;this.activeObj.activePoint.startY-=a,this.activeObj.activePoint.endY-=a}this.activeObj.activePoint.startX=(this.lowerCanvas.clientWidth-this.activeObj.activePoint.width)/2,this.activeObj.activePoint.startY=(this.lowerCanvas.clientHeight-this.activeObj.activePoint.height)/2,this.activeObj.activePoint.endX=this.activeObj.activePoint.startX+this.activeObj.activePoint.width,this.activeObj.activePoint.endY=this.activeObj.activePoint.startY+this.activeObj.activePoint.height}if(0===this.zoomFactor){if(this.activeObj.activePoint.startX<this.destLeft){a=this.destLeft-this.activeObj.activePoint.startX+7.5;this.activeObj.activePoint.startX+=a,this.activeObj.activePoint.endX+=a}if(this.activeObj.activePoint.startY<this.destTop){var a=this.destTop-this.activeObj.activePoint.startY+7.5;this.activeObj.activePoint.startY+=a,this.activeObj.activePoint.endY+=a}this.activeObj.activePoint.width=this.activeObj.activePoint.endX-this.activeObj.activePoint.startX,this.activeObj.activePoint.height=this.activeObj.activePoint.endY-this.activeObj.activePoint.startY}},l.prototype.setDragDirection=function(t,e){this.destWidth>this.destHeight?(this.activeObj.activePoint.startX=this.dragPoint.startX=t/2-e/2+7.5,this.activeObj.activePoint.startY=this.dragPoint.startY=e/2-e/2+7.5,this.activeObj.activePoint.endX=t/2+e/2-7.5,this.activeObj.activePoint.endY=e/2+e/2-7.5):(this.activeObj.activePoint.startY=this.dragPoint.startX=e/2-t/2+7.5,this.activeObj.activePoint.endY=e/2+t/2-7.5,this.activeObj.activePoint.startX=this.dragPoint.startX=7.5,this.activeObj.activePoint.endX=t-7.5)},l.prototype.updatePoints=function(){this.activeObj.activePoint.startX+=this.destLeft,this.activeObj.activePoint.startY+=this.destTop,this.activeObj.activePoint.endX+=this.destLeft,this.activeObj.activePoint.endY+=this.destTop,this.activeObj.activePoint.width=this.activeObj.activePoint.endX-this.activeObj.activePoint.startX,this.activeObj.activePoint.height=this.activeObj.activePoint.endY-this.activeObj.activePoint.startY},l.prototype.calcShapeRatio=function(t,e,i,s){for(var o=i,a=s,n=t/e,r=o>=a?o:a,h=r*n,l=r,c=this.getScale(h,o),d=[],p=0;p<2;p++)0===p?d.push(h*c):d.push(l*c);h=d[0],l=d[1];for(var v=this.getScale(l,a),b=[],p=0;p<2;p++)0===p?b.push(h*v):b.push(l*v);h=b[0],l=b[1],this.activeObj.activePoint.width=h,this.activeObj.activePoint.height=l,this.activeObj.activePoint.startX=7.5+(this.dragPoint.startX=(o-h)/2),this.activeObj.activePoint.startY=7.5+(this.dragPoint.startY=(a-l)/2),this.activeObj.activePoint.endX=(o-h)/2+h-7.5,this.activeObj.activePoint.endY=(a-l)/2+l-7.5,this.activeObj.activePoint.startX<this.destLeft&&this.destLeft+this.destWidth>this.lowerCanvas.clientWidth&&(this.activeObj.activePoint.startX=this.destLeft,this.activeObj.activePoint.endX=this.activeObj.activePoint.startX+h),this.activeObj.activePoint.startY<this.destTop&&this.destTop+this.destHeight>this.lowerCanvas.clientHeight&&(this.activeObj.activePoint.startY=this.destTop,this.activeObj.activePoint.endY=this.activeObj.activePoint.startY+l),this.activeObj.activePoint.width=this.activeObj.activePoint.endX-this.activeObj.activePoint.startX,this.activeObj.activePoint.height=this.activeObj.activePoint.endY-this.activeObj.activePoint.startY},l.prototype.getScale=function(t,e){return t>e?e/t:1},l.prototype.calcMaxDimension=function(t,i){var s=this.element.clientWidth,o=this.element.clientHeight-this.toolbarHeight;o=e.Browser.isDevice?o-this.toolbarHeight:o;var a=(s-=30)/t,n=(o-=30)/i,r=Math.min(t,s),h=Math.min(i,o);return a<1&&a<n?(r=t*a,h=i*a):n<1&&n<a&&(r=t*n,h=i*n),{width:r,height:h}},l.prototype.setMaximumDimension=function(t,e){var i,s;t%90==0&&t%180!=0?(i=this.baseImg.height,s=this.baseImg.width):t%180!=0&&0!==t||(i=this.baseImg.width,s=this.baseImg.height),e.width=i,e.height=s;var o=this.calcMaxDimension(i,s);e.style.maxWidth=o.width+"px",e.style.maxHeight=o.height+"px"},l.prototype.setCursor=function(t,i){var s,o=!1;if(void 0!==this.activeObj.horTopLine){void 0!==this.activeObj.shape&&(s=this.activeObj.shape.split("-")),void 0===s&&this.currObjType.isCustomCrop?o=!0:void 0!==s&&"crop"===s[0]&&(o=!0),!o&&this.togglePan&&(this.lowerCanvas.style.cursor=this.upperCanvas.style.cursor="grab");var a=this.upperCanvas.style.cursor,n=e.extend({},this.activeObj,{},!0);t>=n.topLeftCircle.startX-2*n.topLeftCircle.radius&&t<=n.topLeftCircle.startX+2*n.topLeftCircle.radius&&i>=n.topLeftCircle.startY-2*n.topLeftCircle.radius&&i<=n.topLeftCircle.startY+2*n.topLeftCircle.radius?this.upperCanvas.style.cursor="nw-resize":t>=n.topCenterCircle.startX-2*n.topLeftCircle.radius&&t<=n.topCenterCircle.startX+2*n.topLeftCircle.radius&&i>=n.topCenterCircle.startY-2*n.topLeftCircle.radius&&i<=n.topCenterCircle.startY+2*n.topLeftCircle.radius?this.upperCanvas.style.cursor="n-resize":t>=n.topRightCircle.startX-2*n.topLeftCircle.radius&&t<=n.topRightCircle.startX+2*n.topLeftCircle.radius&&i>=n.topRightCircle.startY-2*n.topLeftCircle.radius&&i<=n.topRightCircle.startY+2*n.topLeftCircle.radius?this.upperCanvas.style.cursor="ne-resize":t>=n.centerLeftCircle.startX-2*n.topLeftCircle.radius&&t<=n.centerLeftCircle.startX+2*n.topLeftCircle.radius&&i>=n.centerLeftCircle.startY-2*n.topLeftCircle.radius&&i<=n.centerLeftCircle.startY+2*n.topLeftCircle.radius?this.upperCanvas.style.cursor="w-resize":t>=n.centerRightCircle.startX-2*n.topLeftCircle.radius&&t<=n.centerRightCircle.startX+2*n.topLeftCircle.radius&&i>=n.centerRightCircle.startY-2*n.topLeftCircle.radius&&i<=n.centerRightCircle.startY+2*n.topLeftCircle.radius?this.upperCanvas.style.cursor="e-resize":t>=n.bottomLeftCircle.startX-2*n.topLeftCircle.radius&&t<=n.bottomLeftCircle.startX+2*n.topLeftCircle.radius&&i>=n.bottomLeftCircle.startY-2*n.topLeftCircle.radius&&i<=n.bottomLeftCircle.startY+2*n.topLeftCircle.radius?this.upperCanvas.style.cursor="sw-resize":t>=n.bottomCenterCircle.startX-2*n.topLeftCircle.radius&&t<=n.bottomCenterCircle.startX+2*n.topLeftCircle.radius&&i>=n.bottomCenterCircle.startY-2*n.topLeftCircle.radius&&i<=n.bottomCenterCircle.startY+2*n.topLeftCircle.radius?this.upperCanvas.style.cursor="s-resize":t>=n.bottomRightCircle.startX-2*n.topLeftCircle.radius&&t<=n.bottomRightCircle.startX+2*n.topLeftCircle.radius&&i>=n.bottomRightCircle.startY-2*n.topLeftCircle.radius&&i<=n.bottomRightCircle.startY+2*n.topLeftCircle.radius?this.upperCanvas.style.cursor="se-resize":t>=n.activePoint.startX&&t<=n.activePoint.endX&&i>=n.activePoint.startY&&i<=n.activePoint.endY?this.upperCanvas.style.cursor=o?"grab":"move":(this.currObjType.isCustomCrop&&(this.upperCanvas.style.cursor="crosshair"),this.upperCanvas.style.cursor="default"),"default"===a&&"default"===this.upperCanvas.style.cursor&&o&&(this.upperCanvas.style.cursor="grab"),"grab"===a&&"default"===this.upperCanvas.style.cursor&&(this.upperCanvas.style.cursor="grab")}else this.togglePan&&!this.togglePen?this.lowerCanvas.style.cursor=this.upperCanvas.style.cursor="grab":this.currObjType.isCustomCrop||this.togglePen?this.upperCanvas.style.cursor="crosshair":this.upperCanvas.style.cursor="default";if("default"===this.upperCanvas.style.cursor||"grab"===this.upperCanvas.style.cursor){a=this.upperCanvas.style.cursor;this.objColl.length>0&&("grab"!==this.upperCanvas.style.cursor||!o)&&this.setCursorFromObj(t,i,this.objColl),"grab"===a&&"default"===this.upperCanvas.style.cursor&&(this.upperCanvas.style.cursor="grab")}"default"!==this.upperCanvas.style.cursor&&"grab"!==this.upperCanvas.style.cursor||e.isNullOrUndefined(this.pointColl[0])||"grab"===this.upperCanvas.style.cursor&&o||this.setCursorForFreehandDrawing(t,i)},l.prototype.setCursorForFreehandDrawing=function(t,i){var s=!1;this.freehandDrawHoveredIndex=-1;for(var o=0;o<this.freehandCounter;o++){this.points=e.extend([],this.pointColl[o].points,[]),this.pointCounter=0;for(var a=this.points.length,n=0;n<a;n++)if(0!==n){var r=!1;if(e.isNullOrUndefined(this.points[n-1])||e.isNullOrUndefined(this.points[n])||(r=this.isInside(t,i,this.points[n-1].x,this.points[n-1].y,this.points[n].x,this.points[n].y)),r){this.isFreehandDrawingPoint=!0,this.freehandDrawHoveredIndex=o,this.hoverFreehandraw(),this.upperCanvas.style.cursor="pointer",s=!0;break}if(!this.isFreehandDrawEditing||this.pointColl[o].isSelected){if(this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),e.isNullOrUndefined(this.activeObj.shape)||"none"!==this.textArea.style.display||this.drawObject("duplicate",this.activeObj),this.isFreehandDrawEditing){h=this.pointColl[o].strokeColor=this.selectedFreehandColor;this.hoverFreehandraw(h,this.pointColl[o].strokeWidth)}else this.freehandDrawHoveredIndex=null;this.isFreehandDrawingPoint=!1}}else{if(t>this.points[n].x-this.pointColl[o].strokeWidth&&t<this.points[n].x+this.pointColl[o].strokeWidth&&i>this.points[n].y-this.pointColl[o].strokeWidth&&i<this.points[n].y+this.pointColl[o].strokeWidth){this.isFreehandDrawingPoint=!0,this.freehandDrawHoveredIndex=o,this.hoverFreehandraw(),this.upperCanvas.style.cursor="pointer",s=!0;break}if(!this.isFreehandDrawEditing||this.pointColl[o].isSelected){if(this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),e.isNullOrUndefined(this.activeObj.shape)||"none"!==this.textArea.style.display||this.drawObject("duplicate",this.activeObj),this.isFreehandDrawEditing){var h="#fff"===this.pointColl[o].strokeColor?"#42a5f5":this.pointColl[o].strokeColor;this.hoverFreehandraw(h,this.pointColl[o].strokeWidth)}this.isFreehandDrawingPoint=!1}}if(s)break}},l.prototype.setCursorFromObj=function(t,i,s){for(var o=0;o<s.length;o++){var a=e.extend({},s[o],{},!0);if(t>=a.topLeftCircle.startX-2*a.topLeftCircle.radius&&t<=a.topLeftCircle.startX+2*a.topLeftCircle.radius&&i>=a.topLeftCircle.startY-2*a.topLeftCircle.radius&&i<=a.topLeftCircle.startY+2*a.topLeftCircle.radius){this.upperCanvas.style.cursor="nw-resize";break}if(t>=a.topCenterCircle.startX-2*a.topLeftCircle.radius&&t<=a.topCenterCircle.startX+2*a.topLeftCircle.radius&&i>=a.topCenterCircle.startY-2*a.topLeftCircle.radius&&i<=a.topCenterCircle.startY+2*a.topLeftCircle.radius){this.upperCanvas.style.cursor="n-resize";break}if(t>=a.topRightCircle.startX-2*a.topLeftCircle.radius&&t<=a.topRightCircle.startX+2*a.topLeftCircle.radius&&i>=a.topRightCircle.startY-2*a.topLeftCircle.radius&&i<=a.topRightCircle.startY+2*a.topLeftCircle.radius){this.upperCanvas.style.cursor="ne-resize";break}if(t>=a.centerLeftCircle.startX-2*a.topLeftCircle.radius&&t<=a.centerLeftCircle.startX+2*a.topLeftCircle.radius&&i>=a.centerLeftCircle.startY-2*a.topLeftCircle.radius&&i<=a.centerLeftCircle.startY+2*a.topLeftCircle.radius){this.upperCanvas.style.cursor="w-resize";break}if(t>=a.centerRightCircle.startX-2*a.topLeftCircle.radius&&t<=a.centerRightCircle.startX+2*a.topLeftCircle.radius&&i>=a.centerRightCircle.startY-2*a.topLeftCircle.radius&&i<=a.centerRightCircle.startY+2*a.topLeftCircle.radius){this.upperCanvas.style.cursor="e-resize";break}if(t>=a.bottomLeftCircle.startX-2*a.topLeftCircle.radius&&t<=a.bottomLeftCircle.startX+2*a.topLeftCircle.radius&&i>=a.bottomLeftCircle.startY-2*a.topLeftCircle.radius&&i<=a.bottomLeftCircle.startY+2*a.topLeftCircle.radius){this.upperCanvas.style.cursor="sw-resize";break}if(t>=a.bottomCenterCircle.startX-2*a.topLeftCircle.radius&&t<=a.bottomCenterCircle.startX+2*a.topLeftCircle.radius&&i>=a.bottomCenterCircle.startY-2*a.topLeftCircle.radius&&i<=a.bottomCenterCircle.startY+2*a.topLeftCircle.radius){this.upperCanvas.style.cursor="s-resize";break}if(t>=a.bottomRightCircle.startX-2*a.topLeftCircle.radius&&t<=a.bottomRightCircle.startX+2*a.topLeftCircle.radius&&i>=a.bottomRightCircle.startY-2*a.topLeftCircle.radius&&i<=a.bottomRightCircle.startY+2*a.topLeftCircle.radius){this.upperCanvas.style.cursor="se-resize";break}if(t>=a.activePoint.startX&&t<=a.activePoint.endX&&i>=a.activePoint.startY&&i<=a.activePoint.endY){this.upperCanvas.style.cursor="move";break}this.currObjType.isCustomCrop&&(this.upperCanvas.style.cursor="crosshair"),this.upperCanvas.style.cursor="default"}},l.prototype.isInside=function(t,e,i,s,o,a){var n=Math.min(i,o),r=Math.max(i,o),h=Math.min(s,a),l=Math.max(s,a);return n<=t&&t<=r&&h<=e&&e<=l},l.prototype.refreshDropDownBtn=function(t){if(!e.isNullOrUndefined(t)){var i=document.querySelector("#"+this.element.id+"_annotationBtn");e.isNullOrUndefined(i)||(t?(i.classList.add("e-disabled"),i.parentElement.classList.add("e-overlay")):(i.classList.remove("e-disabled"),i.parentElement.classList.remove("e-overlay")),e.getComponent(i,"dropdown-btn").disabled=t);var s=document.querySelector("#"+this.element.id+"_transformBtn");e.isNullOrUndefined(s)||(t?(s.classList.add("e-disabled"),s.parentElement.classList.add("e-overlay")):(s.classList.remove("e-disabled"),s.parentElement.classList.remove("e-overlay")),e.getComponent(s,"dropdown-btn").disabled=t);var o=document.querySelector("#"+this.element.id+"_adjustment");e.isNullOrUndefined(o)||(t?(o.classList.add("e-disabled"),o.parentElement.classList.add("e-overlay")):(o.classList.remove("e-disabled"),o.parentElement.classList.remove("e-overlay")),e.getComponent(o,"btn").disabled=t);var a=document.querySelector("#"+this.element.id+"_filter");e.isNullOrUndefined(a)||(t?(a.classList.add("e-disabled"),a.parentElement.classList.add("e-overlay")):(a.classList.remove("e-disabled"),a.parentElement.classList.remove("e-overlay")),e.getComponent(a,"btn").disabled=t)}},l.prototype.downloadImg=function(t,e){var i=document.createElement("a");i.href=t,i.target="_parent",i.download=e,(document.body||document.documentElement).appendChild(i),i.click(),i.parentNode.removeChild(i)},l.prototype.toSVGImg=function(t){a.showSpinner(this.element),this.element.style.opacity="0.5";var e=this.exportChangesToCanvas(),i=e.toDataURL();a.hideSpinner(this.element),this.element.style.opacity="1";var s=document.createElementNS("http://www.w3.org/2000/svg","svg");s.setAttribute("width",e.style.maxWidth),s.setAttribute("height",e.style.maxHeight);var o=document.createElementNS("http://www.w3.org/2000/svg","image");o.setAttributeNS(null,"height",e.height.toString()),o.setAttributeNS(null,"width",e.width.toString()),o.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",i),s.appendChild(o);var n='<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="'+e.width+'" height="'+e.height+'">'+s.innerHTML+"</svg>",r="data:image/svg+xml;base64,"+btoa(n);return null===t?r:(this.downloadImg(r,t+".svg"),null)},l.prototype.toBlobFn=function(t,e){var i=this;a.showSpinner(this.element),this.element.style.opacity="0.5",this.exportChangesToCanvas().toBlob(function(s){var o=URL.createObjectURL(s);i.downloadImg(o,t+"."+e),a.hideSpinner(i.element),i.element.style.opacity="1"},"image/png")},l.prototype.exportChangesToCanvas=function(){var t=this.calcRatio(),i=this.lowerContext.filter;if("none"!==this.lowerContext.filter){var s=this.lowerContext.filter.split(" "),o=parseFloat(s[5].split("(")[1]);o*=(t.width+t.height)/2,s[5]="blur("+o+"px)",this.lowerContext.filter=s.join(" ")}var a,n=this.createElement("canvas",{id:this.element.id+"_tempCanvas",attrs:{name:"canvasImage"}}),r=n.getContext("2d");if(r.filter=this.lowerContext.filter,e.isNullOrUndefined(this.currSelectionPoint)){n.width=this.baseImg.width,n.height=this.baseImg.height,a=this.calcMaxDimension(this.baseImg.width,this.baseImg.height),n.style.maxWidth=a.width+"px",n.style.maxHeight=a.height+"px",r.filter=this.lowerContext.filter;h=this.lowerContext.filter;this.updateBrightnessFilter(),r.drawImage(this.baseImg,this.srcLeft,this.srcTop,this.srcWidth,this.srcHeight,0,0,this.baseImg.width,this.baseImg.height),this.lowerContext.filter=h}else{n.width=this.destWidth,n.height=this.destHeight,r.filter=this.lowerContext.filter;h=this.lowerContext.filter;this.updateBrightnessFilter(),r.drawImage(this.baseImg,this.srcLeft,this.srcTop,this.srcWidth,this.srcHeight,0,0,this.destWidth,this.destHeight),this.lowerContext.filter=h}if(0===this.degree&&""===this.currFlipState||(this.updateSaveContext(r),this.exportTransformedImage(r)),this.objColl.length>0){var h=r.filter;r.filter="none";for(var l=e.extend([],this.objColl,[],!0),c=0;c<this.objColl.length;c++)this.objColl[c].activePoint.startX-=this.destLeft,this.objColl[c].activePoint.startY-=this.destTop,this.objColl[c].activePoint.endX-=this.destLeft,this.objColl[c].activePoint.endY-=this.destTop,this.objColl[c].activePoint.width=this.objColl[c].activePoint.endX-this.objColl[c].activePoint.startX,this.objColl[c].activePoint.height=this.objColl[c].activePoint.endY-this.objColl[c].activePoint.startY,e.isNullOrUndefined(this.currSelectionPoint)&&(this.objColl[c].activePoint.startX*=t.width,this.objColl[c].activePoint.startY*=t.height,this.objColl[c].activePoint.endX*=t.width,this.objColl[c].activePoint.endY*=t.height,this.objColl[c].activePoint.width=this.objColl[c].activePoint.endX-this.objColl[c].activePoint.startX,this.objColl[c].activePoint.height=this.objColl[c].activePoint.endY-this.objColl[c].activePoint.startY,this.objColl[c].strokeSettings.strokeWidth*=(t.width+t.height)/2,"text"===this.objColl[c].shape&&(this.objColl[c].textSettings.fontSize*=(t.width+t.height)/2)),this.drawObject("saveContext",this.objColl[c],null,null,!0,r);r.filter=h,this.refreshActiveObj(),this.objColl=l}if(this.freehandCounter>0){for(var d=e.extend({},this.pointColl,{},!0),p=0;p<this.freehandCounter;p++){this.points=e.extend([],this.pointColl[p].points,[]),this.pointCounter=0;var v=this.points.length;if(e.isNullOrUndefined(this.currSelectionPoint)){this.pointColl[p].strokeWidth*=(t.width+t.height)/2;for(b=0;b<v;b++)this.points[b].x=(this.points[b].x-this.destLeft)*t.width,this.points[b].y=(this.points[b].y-this.destTop)*t.height}else for(var b=0;b<v;b++)this.points[b].x-=this.destLeft,this.points[b].y-=this.destTop}this.freehandRedraw(r),this.pointColl=d}return this.isCircleCrop&&this.cropCircle(r,!0),this.lowerContext.filter=i,n},l.prototype.exportTransformedImage=function(t){for(var e=this.degree,i=0;i<this.rotateFlipColl.length;i++)"number"==typeof this.rotateFlipColl[i]?this.exportRotate(t,this.rotateFlipColl[i]):"horizontal"===this.rotateFlipColl[i]?this.exportHorizontalFlip(t):"vertical"===this.rotateFlipColl[i]&&this.exportVerticalFlip(t);this.degree=e},l.prototype.exportRotate=function(t,i){e.isNullOrUndefined(this.currSelectionPoint)?(this.setMaximumDimension(this.degree,t.canvas),t.translate(t.canvas.width/2,t.canvas.height/2),t.rotate(Math.PI/180*i),t.drawImage(this.inMemoryCanvas,this.srcLeft,this.srcTop,this.srcWidth,this.srcHeight,-t.canvas.height/2,-t.canvas.width/2,t.canvas.height,t.canvas.width)):(t.translate(t.canvas.width/2,t.canvas.height/2),t.rotate(Math.PI/180*i),t.drawImage(this.inMemoryCanvas,-t.canvas.height/2,-t.canvas.width/2,t.canvas.height,t.canvas.width)),this.updateSaveContext(t)},l.prototype.exportHorizontalFlip=function(t){t.translate(t.canvas.width,0),t.scale(-1,1),t.drawImage(this.inMemoryCanvas,0,0),this.updateSaveContext(t)},l.prototype.exportVerticalFlip=function(t){t.translate(0,t.canvas.height),t.scale(1,-1),t.drawImage(this.inMemoryCanvas,0,0),this.updateSaveContext(t)},l.prototype.updateSaveContext=function(t){t.setTransform(1,0,0,1,0,0);var e=t.getImageData(0,0,t.canvas.width,t.canvas.height);this.inMemoryCanvas.width=e.width,this.inMemoryCanvas.height=e.height,this.inMemoryContext.putImageData(e,0,0)},l.prototype.addLetter=function(t){if("none"===this.textArea.style.display&&(this.currObjType.isText||"text"===this.activeObj.shape)){"Backspace"===t?this.keyHistory=this.keyHistory.slice(0,-1):this.keyHistory+=t,this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),this.updateFontStyles();var e=this.upperContext.measureText(this.keyHistory+this.tempKeyHistory).width+.5*this.activeObj.textSettings.fontSize,i=this.activeObj.textSettings.fontSize+.25*this.activeObj.textSettings.fontSize;this.upperContext.fillText(this.keyHistory+this.tempKeyHistory,this.activeObj.activePoint.startX,this.activeObj.activePoint.startY+this.activeObj.textSettings.fontSize),this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),this.currObjType.isText=!0,this.setActivePoint(e,i)}},l.prototype.updateFontStyles=function(t){this.upperContext.strokeStyle=this.activeObj.strokeSettings.strokeColor,this.upperContext.fillStyle=this.activeObj.strokeSettings.strokeColor;var e="";this.activeObj.textSettings.bold&&(e="bold "),this.activeObj.textSettings.italic&&(e="italic "),this.activeObj.textSettings.bold&&this.activeObj.textSettings.italic&&(e="italic bold ");var i=t?parseFloat(this.textArea.style.fontSize):this.activeObj.textSettings.fontSize,s="block"===this.textArea.style.display?this.textArea.style.fontFamily:this.activeObj.textSettings.fontFamily;this.upperContext.font=e+i+"px "+s},l.prototype.textFlipDegree=function(t,e,i){for(var s=this.activeObj.keyHistory.split("\n"),o=(this.activeObj.textSettings.fontSize*s.length-this.activeObj.textSettings.fontSize*s.length)/s.length,a=.85*this.activeObj.textSettings.fontSize+o,n=0;n<s.length;n++){var r=s[n];n>0&&(1===n&&(a-=.85*this.activeObj.textSettings.fontSize),a+=this.activeObj.textSettings.fontSize+.15*this.activeObj.textSettings.fontSize),t.fillText(r,e+.15*this.activeObj.textSettings.fontSize,i+a+(n>0?.25*this.activeObj.textSettings.fontSize:.35*-this.activeObj.textSettings.fontSize))}},l.prototype.rotateText=function(t){var e,i=this.activeObj.activePoint.startX,s=this.activeObj.activePoint.startY;if((e=0===this.activeObj.shapeDegree?this.degree:this.degree-this.activeObj.shapeDegree)<0&&(e=360+e),e%360!=0||-360===this.degree&&""!==this.currFlipState)e%90==0&&e%180!=0?(t.translate(this.lowerCanvas.width/2,this.lowerCanvas.height/2),t.rotate(Math.PI/180*e),t.translate(-this.lowerCanvas.height/2,-this.lowerCanvas.width/2),e%90==0&&e%270!=0?(s=this.lowerCanvas.width-this.activeObj.activePoint.endX+.4*this.activeObj.textSettings.fontSize,i=this.activeObj.activePoint.startY):e%270==0&&(i=this.lowerCanvas.height-this.activeObj.activePoint.endY,s=this.activeObj.activePoint.startX+.4*this.activeObj.textSettings.fontSize),this.textFlipDegree(t,i,s),t.translate(this.lowerCanvas.height/2,this.lowerCanvas.width/2),t.rotate(Math.PI/180*-e),t.translate(-this.lowerCanvas.width/2,-this.lowerCanvas.height/2)):(t.translate(this.lowerCanvas.width/2,this.lowerCanvas.height/2),t.rotate(Math.PI/180*e),i=this.lowerCanvas.width-this.activeObj.activePoint.endX,s=this.lowerCanvas.height-this.activeObj.activePoint.endY+.4*this.activeObj.textSettings.fontSize,t.translate(-this.lowerCanvas.width/2,-this.lowerCanvas.height/2),this.textFlipDegree(t,i,s),t.translate(this.lowerCanvas.width/2,this.lowerCanvas.height/2),t.rotate(Math.PI/180*-e),t.translate(-this.lowerCanvas.width/2,-this.lowerCanvas.height/2));else{i=this.activeObj.activePoint.startX+.15*this.activeObj.textSettings.fontSize,s=this.activeObj.activePoint.startY+(this.activeObj.activePoint.endY-this.activeObj.activePoint.startY);for(var o=this.activeObj.keyHistory.split("\n"),a=0;a<o.length;a++)s=this.activeObj.activePoint.startY+(a*this.activeObj.textSettings.fontSize+.25*this.activeObj.textSettings.fontSize),t.fillText(o[a],i,s)}360!==this.degree&&-360!==this.degree||(this.degree=0)},l.prototype.redrawObj=function(t){if(this.objColl.length>0)if("horizontal"===t||"vertical"===t||"Horizontal"===t||"Vertical"===t||"horizontalVertical"===t||"verticalHorizontal"===t)this.updateCurrentActiveObjPoint(t.toLowerCase());else if("number"==typeof t){this.updateCurrentActiveObjPoint(t);var e=this.lowerContext.filter;this.lowerContext.filter=this.getDefaultFilter();for(var i=0;i<this.objColl.length;i++)"crop"!==this.objColl[i].shape.split("-")[0]&&this.apply(this.objColl[i].shape,this.objColl[i]);this.lowerContext.filter=e}},l.prototype.updateCurrentActiveObjPoint=function(t){for(var i,s=0;s<this.objColl.length;s++)if(this.activeObj.shape===this.objColl[s].shape&&this.activeObj.activePoint.startX===this.objColl[s].activePoint.startX&&this.activeObj.activePoint.startY===this.objColl[s].activePoint.startY&&this.activeObj.activePoint.endX===this.objColl[s].activePoint.endX&&this.activeObj.activePoint.endY===this.objColl[s].activePoint.endY&&this.activeObj.currIndex===this.objColl[s].currIndex){i=s;break}if("horizontal"===t||"vertical"===t||"Horizontal"===t||"Vertical"===t||"horizontalvertical"===t||"verticalhorizontal"===t){if("horizontal"===t||"Horizontal"===t)for(o=0;o<this.objColl.length;o++)this.objColl[o].shapeFlip!==this.currFlipState&&(this.objColl[o].activePoint.startX<=this.destLeft+this.destWidth/2?(this.objColl[o].activePoint.endX=this.destLeft+this.destWidth-(this.objColl[o].activePoint.startX-this.destLeft),this.objColl[o].activePoint.startX=this.objColl[o].activePoint.endX-this.objColl[o].activePoint.width,this.updateActiveObject(this.objColl[o].activePoint,this.objColl[o])):this.objColl[o].activePoint.startX>=this.destLeft+this.destWidth/2&&(this.objColl[o].activePoint.startX=this.destLeft+(this.destLeft+this.destWidth-this.objColl[o].activePoint.endX),this.objColl[o].activePoint.endX=this.objColl[o].activePoint.startX+this.objColl[o].activePoint.width,this.updateActiveObject(this.objColl[o].activePoint,this.objColl[o])),this.objColl[o].imageRatio={startX:(this.objColl[o].activePoint.startX-this.destLeft)/this.destWidth,startY:(this.objColl[o].activePoint.startY-this.destTop)/this.destHeight,endX:(this.objColl[o].activePoint.endX-this.destLeft)/this.destWidth,endY:(this.objColl[o].activePoint.endY-this.destTop)/this.destHeight,width:this.destWidth/this.objColl[o].activePoint.width,height:this.destHeight/this.objColl[o].activePoint.height},this.objColl[o].shapeFlip=this.currFlipState);else if("vertical"===t||"Vertical"===t)for(o=0;o<this.objColl.length;o++)this.objColl[o].shapeFlip!==this.currFlipState&&(this.objColl[o].activePoint.startY<=this.destTop+this.destHeight/2?(this.objColl[o].activePoint.endY=this.destTop+this.destHeight-(this.objColl[o].activePoint.startY-this.destTop),this.objColl[o].activePoint.startY=this.objColl[o].activePoint.endY-this.objColl[o].activePoint.height,this.updateActiveObject(this.objColl[o].activePoint,this.objColl[o])):this.objColl[o].activePoint.startY>=this.lowerCanvas.height/2&&(this.objColl[o].activePoint.startY=this.destTop+(this.destTop+this.destHeight-this.objColl[o].activePoint.endY),this.objColl[o].activePoint.endY=this.objColl[o].activePoint.startY+this.objColl[o].activePoint.height,this.updateActiveObject(this.objColl[o].activePoint,this.objColl[o])),this.objColl[o].imageRatio={startX:(this.objColl[o].activePoint.startX-this.destLeft)/this.destWidth,startY:(this.objColl[o].activePoint.startY-this.destTop)/this.destHeight,endX:(this.objColl[o].activePoint.endX-this.destLeft)/this.destWidth,endY:(this.objColl[o].activePoint.endY-this.destTop)/this.destHeight,width:this.destWidth/this.objColl[o].activePoint.width,height:this.destHeight/this.objColl[o].activePoint.height},this.objColl[o].shapeFlip=this.currFlipState);else if("verticalhorizontal"===t||"horizontalvertical"===t)for(o=0;o<this.objColl.length;o++)this.objColl[o].shapeFlip!==this.currFlipState&&(this.objColl[o].activePoint.startX<=this.destLeft+this.destWidth/2?(this.objColl[o].activePoint.endX=this.destLeft+this.destWidth-(this.objColl[o].activePoint.startX-this.destLeft),this.objColl[o].activePoint.startX=this.objColl[o].activePoint.endX-this.objColl[o].activePoint.width,this.updateActiveObject(this.objColl[o].activePoint,this.objColl[o])):this.objColl[o].activePoint.startX>=this.destLeft+this.destWidth/2&&(this.objColl[o].activePoint.startX=this.destLeft+(this.destLeft+this.destWidth-this.objColl[o].activePoint.endX),this.objColl[o].activePoint.endX=this.objColl[o].activePoint.startX+this.objColl[o].activePoint.width,this.updateActiveObject(this.objColl[o].activePoint,this.objColl[o])),this.objColl[o].activePoint.startY<=this.destTop+this.destHeight/2?(this.objColl[o].activePoint.endY=this.destTop+this.destHeight-(this.objColl[o].activePoint.startY-this.destTop),this.objColl[o].activePoint.startY=this.objColl[o].activePoint.endY-this.objColl[o].activePoint.height,this.updateActiveObject(this.objColl[o].activePoint,this.objColl[o])):this.objColl[o].activePoint.startY>=this.lowerCanvas.height/2&&(this.objColl[o].activePoint.startY=this.destTop+(this.destTop+this.destHeight-this.objColl[o].activePoint.endY),this.objColl[o].activePoint.endY=this.objColl[o].activePoint.startY+this.objColl[o].activePoint.height,this.updateActiveObject(this.objColl[o].activePoint,this.objColl[o])),this.objColl[o].imageRatio={startX:(this.objColl[o].activePoint.startX-this.destLeft)/this.destWidth,startY:(this.objColl[o].activePoint.startY-this.destTop)/this.destHeight,endX:(this.objColl[o].activePoint.endX-this.destLeft)/this.destWidth,endY:(this.objColl[o].activePoint.endY-this.destTop)/this.destHeight,width:this.destWidth/this.objColl[o].activePoint.width,height:this.destHeight/this.objColl[o].activePoint.height},this.objColl[o].shapeFlip=this.currFlipState);void 0!==i&&(this.activeObj=e.extend({},this.objColl[i],{},!0))}else if(90===t)this.rotateObjColl();else if(-90===t)for(o=0;o<3;o++)this.rotateObjColl();else if("number"==typeof t)if(t>0)this.rotateObjColl();else for(var o=0;o<3;o++)this.rotateObjColl()},l.prototype.rotateObjColl=function(){for(t=0;t<this.objColl.length;t++)this.objColl[t].activePoint.startY=this.destTop+this.destHeight*this.objColl[t].imageRatio.startX,this.objColl[t].activePoint.endY=this.destTop+this.destHeight*this.objColl[t].imageRatio.endX,this.objColl[t].activePoint.startX=this.destLeft+this.destWidth-this.destWidth*this.objColl[t].imageRatio.endY,this.objColl[t].activePoint.endX=this.destLeft+this.destWidth-this.destWidth*this.objColl[t].imageRatio.startY,this.objColl[t].activePoint.width=this.objColl[t].activePoint.endX-this.objColl[t].activePoint.startX,this.objColl[t].activePoint.height=this.objColl[t].activePoint.endY-this.objColl[t].activePoint.startY,this.updateFontSize(this.objColl[t]);for(t=0;t<this.objColl.length;t++)this.updateActiveObject(this.objColl[t].activePoint,this.objColl[t]);for(var t=0;t<this.objColl.length;t++)this.objColl[t].imageRatio={startX:(this.objColl[t].activePoint.startX-this.destLeft)/this.destWidth,startY:(this.objColl[t].activePoint.startY-this.destTop)/this.destHeight,endX:(this.objColl[t].activePoint.endX-this.destLeft)/this.destWidth,endY:(this.objColl[t].activePoint.endY-this.destTop)/this.destHeight,width:this.destWidth/this.objColl[t].activePoint.width,height:this.destHeight/this.objColl[t].activePoint.height}},l.prototype.setTextFontSize=function(t){if("text"===t.shape){var e=this.getMaxText(null,t.keyHistory),i=void 0;i=0===t.shapeDegree?this.degree:this.degree-t.shapeDegree;var s=2;1===e.length&&(s=1),t.textSettings.fontSize=0===i||180===i||-180===i?t.activePoint.width/e.length*s:t.activePoint.height/e.length*s}},l.prototype.redrawShape=function(t){for(var e=0;e<this.objColl.length;e++)if(JSON.stringify(t)===JSON.stringify(this.objColl[e])){this.objColl.splice(e,1);break}this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),this.isPreventDragging?(this.activeObj.activePoint.startX>this.destLeft&&(this.isPreventDragging=!1),this.drawObject("duplicate",null,null,null,!0)):this.drawObject("duplicate",null,null,null,!0)},l.prototype.applyActObj=function(){var t=!1;if(void 0!==this.activeObj.shape&&"text"===this.activeObj.shape&&""===this.activeObj.keyHistory)this.refreshActiveObj(),this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height);else{var i=void 0,s=!1;if(void 0!==this.activeObj.shape&&(i=this.activeObj.shape.split("-")),void 0===i&&this.currObjType.isCustomCrop?s=!0:void 0!==i&&"crop"===i[0]&&(s=!0),!e.isNullOrUndefined(this.activeObj.shape)&&!s){for(n=0;n<this.objColl.length;n++)if(JSON.stringify(this.activeObj)===JSON.stringify(this.objColl[n])){t=!0;break}if(!t){e.isNullOrUndefined(this.activeObj.currIndex)&&(this.activeObj.currIndex="shape_"+(this.objColl.length+1)),this.updateImageRatioForActObj();var o=this.activeObj.currIndex.split("_"),a=this.objColl.splice(0,parseInt(o[1],10)-1);a.push(e.extend({},this.activeObj,{},!0));for(var n=0;n<this.objColl.length;n++)a.push(this.objColl[n]);this.objColl=a,a=[],this.refreshActiveObj(),this.lowerContext.clearRect(0,0,this.lowerCanvas.width,this.lowerCanvas.height),this.redrawImgWithObj(),this.clearOuterCanvas(this.lowerContext),this.clearOuterCanvas(this.upperContext),this.currObjType.shape="",this.refreshActiveObj(),this.isCircleCrop&&this.cropCircle(this.lowerContext)}}}},l.prototype.apply=function(t,i,s){if(!this.disabled)if(this.togglePen&&!this.currObjType.isCustomCrop){var o=this.destLeft,a=this.destTop,n=this.destWidth,r=this.destHeight;this.callUpdateCurrentTransformedState();var h=this.lowerContext.filter;this.lowerContext.filter="none",this.togglePen=!1,this.iterateObjColl(),this.freehandRedraw(this.lowerContext),this.togglePen=!1,(this.isCircleCrop||!e.isNullOrUndefined(this.currSelectionPoint)&&"crop-circle"===this.currSelectionPoint.shape)&&this.cropCircle(this.lowerContext),this.destLeft=o,this.destTop=a,this.destWidth=n,this.destHeight=r,this.lowerContext.filter=h}else s=s||"original",this.currObjType.shape=void 0!==t?t:this.currObjType.shape,""!==this.currObjType.shape&&(this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),this.drawObject(s,i),this.activeObj.shape=this.currObjType.shape.toLowerCase(),t||""===this.currObjType.shape||this.currObjType.isCustomCrop||this.objColl.push(e.extend({},this.activeObj,{},!0)),this.keyHistory="")},l.prototype.setCenterPoints=function(t,e,i){var s,o;t&&e&&i?(s=e,o=i):(s=this.activeObj.activePoint.width,o=this.activeObj.activePoint.height),this.activeObj.activePoint.startX=this.lowerCanvas.width/2-s/2,this.activeObj.activePoint.startY=this.lowerCanvas.height/2-o/2,this.activeObj.activePoint.endX=this.lowerCanvas.width/2+s/2,this.activeObj.activePoint.endY=this.lowerCanvas.height/2+o/2,t&&e&&i&&(this.textStartPoints.x=this.activeObj.activePoint.startX,this.textStartPoints.y=this.activeObj.activePoint.startY)},l.prototype.drawShape=function(t,i,s,o,a,n,r){if(!this.disabled&&this.isImageLoaded){this.redrawActObj();var h=e.extend([],this.objColl,[],!0);if(this.togglePen=!1,this.keyHistory="",this.upperCanvas.style.display="block",this.refreshActiveObj(),this.currObjType.shape=t,"freehanddraw"!==this.currObjType.shape.toLowerCase()&&""!==this.currObjType.shape.toLowerCase()){this.activeObj.shape=this.currObjType.shape.toLowerCase(),this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),e.isNullOrUndefined(this.activeObj.strokeSettings)&&(this.activeObj.strokeSettings=this.strokeSettings),this.activeObj.strokeSettings.strokeWidth=i||this.activeObj.strokeSettings.strokeWidth,this.activeObj.strokeSettings.strokeColor=s||this.activeObj.strokeSettings.strokeColor,this.activeObj.strokeSettings.fillColor=o||this.activeObj.strokeSettings.fillColor;var l=this.destWidth>100?100:this.destWidth/2,c=this.destHeight>100?100:this.destHeight/2;this.activeObj.activePoint.width=l,this.activeObj.activePoint.height=c,"line"===this.currObjType.shape.toLowerCase()?(this.activeObj.lineDraw="horizontal",this.activeObj.activePoint.height/=2):"rectangle"===this.currObjType.shape.toLowerCase()&&(this.activeObj.activePoint.width+=this.activeObj.activePoint.width/2),"ellipse"===this.currObjType.shape.toLowerCase()&&n&&(this.activeObj.activePoint.width=2*n,this.activeObj.activePoint.height=2*r),n&&r&&(this.activeObj.activePoint.width=n,this.activeObj.activePoint.height=r),e.isNullOrUndefined(a)?this.setCenterPoints():(this.activeObj.activePoint.startX=a.x,this.activeObj.activePoint.startY=a.y,this.activeObj.activePoint.endX=this.activeObj.activePoint.startX+this.activeObj.activePoint.width,this.activeObj.activePoint.endY=this.activeObj.activePoint.startY+this.activeObj.activePoint.height),this.currObjType.isDragging=this.currObjType.isCustomCrop=!1,this.activeObj.shapeDegree=this.degree,this.activeObj.shapeFlip=this.currFlipState,this.activeObj.flipObjColl=[];var d=this.updatePreviousShapeSettings(),p={action:"insert",previousShapeSettings:d,currentShapeSettings:d};this.trigger("shapeChanging",p),this.updateShapeChangeEventArgs(p.currentShapeSettings),this.drawObject("duplicate"),this.isShapeInserted=!0,this.updateUndoRedoObj(h),this.refreshToolbar("shapes")}}},l.prototype.drawShapeText=function(t,i,s,o,a,n,r,h){if(!this.disabled&&this.isImageLoaded){"freehanddraw"===this.currObjType.shape&&(this.apply(),this.upperCanvas.style.cursor="default",this.currObjType.shape=""),this.togglePen=!1,this.redrawActObj();var l=e.extend([],this.objColl,[],!0);this.keyHistory="",this.refreshActiveObj(),this.activeObj.shape="text",this.currObjType.isCustomCrop=!1,this.currObjType.isText=this.currObjType.isInitialText=!0,this.upperCanvas.style.display="block",this.currObjType.shape=this.activeObj.shape="text",e.isNullOrUndefined(this.activeObj.textSettings)&&(this.activeObj.textSettings=this.textSettings),e.isNullOrUndefined(this.activeObj.strokeSettings)&&(this.activeObj.strokeSettings=this.strokeSettings),this.activeObj.strokeSettings.strokeColor=n||this.activeObj.strokeSettings.strokeColor,this.activeObj.textSettings.text=t||this.activeObj.textSettings.text,this.activeObj.textSettings.fontFamily=i||this.activeObj.textSettings.fontFamily,this.activeObj.textSettings.text=t||this.activeObj.textSettings.text,this.activeObj.textSettings.fontFamily=i||this.activeObj.textSettings.fontFamily,this.activeObj.textSettings.fontSize=s||this.activeObj.textSettings.fontSize,this.activeObj.textSettings.bold=o||this.activeObj.textSettings.bold,this.activeObj.textSettings.italic=a||this.activeObj.textSettings.italic,e.isNullOrUndefined(this.activeObj.textSettings.fontSize)&&(this.lowerCanvas.width>this.lowerCanvas.height?this.activeObj.textSettings.fontSize=Math.floor(this.lowerCanvas.width/20):this.activeObj.textSettings.fontSize=Math.floor(this.lowerCanvas.height/20),this.activeObj.textSettings.fontSize<20&&(this.activeObj.textSettings.fontSize=20)),this.destWidth<100?this.activeObj.textSettings.fontSize=Math.floor(this.destWidth/20):this.destHeight<100&&(this.activeObj.textSettings.fontSize=Math.floor(this.destHeight/20)),this.activeObj.shapeDegree=this.degree,this.activeObj.shapeFlip=this.currFlipState,this.activeObj.flipObjColl=[],this.updateFontStyles();var c=this.upperContext.measureText(this.activeObj.textSettings.text).width+.5*this.activeObj.textSettings.fontSize,d=this.activeObj.textSettings.fontSize+.25*this.activeObj.textSettings.fontSize;e.isNullOrUndefined(r)||e.isNullOrUndefined(h)?this.setCenterPoints(!0,c,d):(this.activeObj.activePoint.startX=r,this.activeObj.activePoint.startY=h,this.activeObj.activePoint.endX=this.activeObj.activePoint.startX+c,this.activeObj.activePoint.endY=this.activeObj.activePoint.startY+d);var p=this.updatePreviousShapeSettings(),v={action:"insert",previousShapeSettings:p,currentShapeSettings:p};this.trigger("shapeChanging",v),this.updateShapeChangeEventArgs(v.currentShapeSettings),this.addLetter(this.activeObj.textSettings.text),this.activeObj.textFlip=this.currFlipState,this.updateFontRatio(this.activeObj),this.objColl.push(this.activeObj),this.undoRedoColl.push({operation:"shapeTransform",value:null,currentObj:e.extend([],this.objColl,[],!0),previousObj:l,zoomFactor:this.zoomFactor,sharpen:this.adjustmentLevel.sharpen,bw:this.adjustmentLevel.bw}),this.undoRedoStep++,this.redrawShape(this.objColl[this.objColl.length-1]),this.isShapeInserted=!0,this.refreshToolbar("text")}},l.prototype.updateShapeChangeEventArgs=function(t){if(this.activeObj.currIndex=t.id,this.activeObj.activePoint.startX=t.startX,this.activeObj.activePoint.startY=t.startY,this.activeObj.activePoint.width=t.width,this.activeObj.activePoint.height=t.height,this.activeObj.strokeSettings.strokeColor=t.strokeColor,this.activeObj.strokeSettings.fillColor=t.fillColor,"ellipse"===this.activeObj.shape&&(this.activeObj.activePoint.width=t.radius/2),"line"===this.activeObj.shape&&(this.activeObj.activePoint.width=t.length),"text"===this.activeObj.shape&&(this.activeObj.keyHistory=t.text),"text"===this.activeObj.shape&&(this.activeObj.textSettings.fontSize=t.fontSize),"text"===this.activeObj.shape&&(this.activeObj.strokeSettings.strokeColor=t.color),"text"===this.activeObj.shape&&!e.isNullOrUndefined(this.activeObj.textSettings))for(var i=0;i<t.fontStyle.length;i++)"bold"===t.fontStyle[i]?this.activeObj.textSettings.bold=!0:"italic"===t.fontStyle[i]?this.activeObj.textSettings.italic=!0:"underline"===t.fontStyle[i]&&(this.activeObj.textSettings.underline=!0)},l.prototype.getObjDetails=function(t){var e={};return e.id=t.currIndex,e.type=this.toPascalCase(t.shape),e.startX=t.activePoint.startX,e.startY=t.activePoint.startY,"rectangle"===t.shape?(e.width=t.activePoint.width,e.height=t.activePoint.height,e.strokeColor=t.strokeSettings.strokeColor,e.fillColor=t.strokeSettings.fillColor,e.strokeWidth=t.strokeSettings.strokeWidth):"ellipse"===t.shape?(e.radius=t.activePoint.width/2,e.strokeColor=t.strokeSettings.strokeColor,e.fillColor=t.strokeSettings.fillColor,e.strokeWidth=t.strokeSettings.strokeWidth):"line"===t.shape?(e.length=t.activePoint.width,e.strokeColor=t.strokeSettings.strokeColor,e.strokeWidth=t.strokeSettings.strokeWidth):"text"===t.shape&&(e.text=t.keyHistory,e.fontSize=t.textSettings.fontSize,e.color=t.strokeSettings.strokeColor,e.fontStyle=[],t.textSettings.bold&&e.fontStyle.push("bold"),t.textSettings.italic&&e.fontStyle.push("italic")),e},l.prototype.getFreehandDrawDetails=function(t){var i={};return i.id=this.pointColl[t].id,i.type="FreehandDraw",i.points=e.extend([],this.pointColl[t].points),i.strokeColor=this.pointColl[t].strokeColor,i.strokeWidth=this.pointColl[t].strokeWidth,i},l.prototype.isPointsInRange=function(t,e){var i=!1;return t>=0&&e>=0&&t<=this.lowerCanvas.width&&e<=this.lowerCanvas.width&&(i=!0),i},l.prototype.clearActObj=function(){"none"===this.textArea.style.display&&(this.refreshActiveObj(),this.applyActObj(),this.refreshActiveObj(),this.currObjType.isCustomCrop=!1)},l.prototype.applyPenDraw=function(){"freehanddraw"===this.currObjType.shape&&(this.apply(),this.upperCanvas.style.cursor="default",this.currObjType.shape=""),this.clearActObj()},l.prototype.drawRotatedImage=function(t){0===t?this.degree=0:this.degree+=t,360!==this.degree&&-360!==this.degree||(this.degree=0),this.setDestinationPoints();var i=e.extend([],this.objColl,[],!0),s=e.extend({},this.activeObj,{},!0);if(this.objColl=[],this.refreshActiveObj(),this.isReverseRotate||this.updateCurrentTransformedState("initial"),this.rotateDegree(t),this.isReverseRotate||(this.updateCurrentTransformedState("reverse"),this.rotateFlipColl.push(t)),1===this.rotateFlipColl.length&&this.setClientTransformedDimension(),this.objColl=e.extend([],i,[],!0),this.activeObj=e.extend({},s,{},!0),this.isCircleCrop&&this.cropCircle(this.lowerContext),this.redrawObj(t),this.refreshActiveObj(),t>0)this.rotateFreehandDrawColl();else for(var o=0;o<3;o++)this.rotateFreehandDrawColl();this.freehandRedraw(this.lowerContext)},l.prototype.setClientTransformedDimension=function(t){if(this.degree%90==0&&this.degree%180!=0){this.destLeft=(this.lowerCanvas.width-this.destHeight)/2,this.destTop=(this.lowerCanvas.height-this.destWidth)/2;var i=this.destWidth;this.destWidth=this.destHeight,this.destHeight=i}else e.isNullOrUndefined(t)&&(this.destLeft=(this.lowerCanvas.width-this.destWidth)/2,this.destTop=(this.lowerCanvas.height-this.destHeight)/2)},l.prototype.popForDefaultTransformedState=function(){for(var t=0,e=0,i=0,s=0,o=0;o<this.rotateFlipColl.length;o++)90===this.rotateFlipColl[o]?(e=0,i=0,s=0,4===++t&&(this.rotateFlipColl.pop(),this.rotateFlipColl.pop(),this.rotateFlipColl.pop(),this.rotateFlipColl.pop())):-90===this.rotateFlipColl[o]?(t=0,i=0,s=0,4===++e&&(this.rotateFlipColl.pop(),this.rotateFlipColl.pop(),this.rotateFlipColl.pop(),this.rotateFlipColl.pop())):"horizontal"===this.rotateFlipColl[o]?(e=0,t=0,s=0,2===++i&&(this.rotateFlipColl.pop(),this.rotateFlipColl.pop())):"vertical"===this.rotateFlipColl[o]&&(i=0,e=0,t=0,2===++s&&(this.rotateFlipColl.pop(),this.rotateFlipColl.pop()))},l.prototype.popForDefaultFlipState=function(){for(var t=0;t<this.rotateFlipColl.length;t++)e.isNullOrUndefined(this.rotateFlipColl[t+3])||("horizontal"===this.rotateFlipColl[t]&&"vertical"===this.rotateFlipColl[t+1]&&"horizontal"===this.rotateFlipColl[t+2]&&"vertical"===this.rotateFlipColl[t+3]?(this.rotateFlipColl.pop(),this.rotateFlipColl.pop(),this.rotateFlipColl.pop(),this.rotateFlipColl.pop()):"vertical"===this.rotateFlipColl[t]&&"horizontal"===this.rotateFlipColl[t+1]&&"vertical"===this.rotateFlipColl[t+2]&&"horizontal"===this.rotateFlipColl[t+3]&&(this.rotateFlipColl.pop(),this.rotateFlipColl.pop(),this.rotateFlipColl.pop(),this.rotateFlipColl.pop()))},l.prototype.popForDefaultRotateState=function(){for(var t=0;t<this.rotateFlipColl.length;t++)e.isNullOrUndefined(this.rotateFlipColl[t+1])||(90===this.rotateFlipColl[t]&&-90===this.rotateFlipColl[t+1]?(this.rotateFlipColl.pop(),this.rotateFlipColl.pop()):-90===this.rotateFlipColl[t]&&90===this.rotateFlipColl[t+1]&&(this.rotateFlipColl.pop(),this.rotateFlipColl.pop()))},l.prototype.alignRotateFlipColl=function(){this.popForDefaultTransformedState(),this.popForDefaultFlipState(),this.popForDefaultRotateState(),0===this.rotateFlipColl.length&&(this.degree=0,this.currFlipState="")},l.prototype.updateFlipColl=function(t){if(0===this.flipColl.length?this.flipColl.push(t):"direction"===this.flipColl[this.flipColl.length-1]?this.flipColl.pop():this.flipColl.push(t),this.flipColl.length>=4)if("horizontal"===this.flipColl[this.flipColl.length-1]&&"vertical"===this.flipColl[this.flipColl.length-2]&&"horizontal"===this.flipColl[this.flipColl.length-3]&&"vertical"===this.flipColl[this.flipColl.length-4])for(e=0;e<4;e++)this.flipColl.pop();else if("vertical"===this.flipColl[this.flipColl.length-1]&&"horizontal"===this.flipColl[this.flipColl.length-2]&&"vertical"===this.flipColl[this.flipColl.length-3]&&"horizontal"===this.flipColl[this.flipColl.length-4])for(var e=0;e<4;e++)this.flipColl.pop()},l.prototype.horizontalFlip=function(){this.lowerContext.translate(this.lowerContext.canvas.width,0),this.lowerContext.scale(-1,1),this.upperContext.translate(this.upperContext.canvas.width,0),this.upperContext.scale(-1,1)},l.prototype.verticalFlip=function(){this.lowerContext.translate(0,this.lowerContext.canvas.height),this.lowerContext.scale(1,-1),this.upperContext.translate(0,this.upperContext.canvas.height),this.upperContext.scale(1,-1)},l.prototype.updateFlipState=function(t){"horizontal"===t&&this.degree%90==0&&this.degree%180!=0?this.verticalFlip():"vertical"===t&&this.degree%90==0&&this.degree%180!=0?this.horizontalFlip():"horizontal"===t?this.horizontalFlip():"vertical"===t&&this.verticalFlip()},l.prototype.setDestinationPoints=function(){var t;this.degree%90==0&&this.degree%180!=0?(t=this.calcMaxDimension(this.srcHeight,this.srcWidth),this.isRotateZoom&&(t.width+=t.width*this.zoomFactor,t.height+=t.height*this.zoomFactor,this.destWidth=t.height,this.destHeight=t.width),this.destLeft=(this.lowerCanvas.clientWidth-t.height)/2,this.destTop=(this.lowerCanvas.clientHeight-t.width)/2,this.destWidth=t.height,this.destHeight=t.width):(t=this.calcMaxDimension(this.srcWidth,this.srcHeight),this.isRotateZoom&&(t.width+=t.width*this.zoomFactor,t.height+=t.height*this.zoomFactor,this.destWidth=t.width,this.destHeight=t.height),this.destLeft=(this.lowerCanvas.clientWidth-t.width)/2,this.destTop=(this.lowerCanvas.clientHeight-t.height)/2,this.destWidth=t.width,this.destHeight=t.height)},l.prototype.rotatedFlip=function(){this.isReverseFlip=!0;var t=this.currFlipState,i=this.flipColl,s=e.extend([],this.objColl,[],!0),o=e.extend({},this.activeObj,{},!0);this.flipColl=[],this.objColl=[],this.refreshActiveObj(),this.currentTransformedState("initial");var a=this.lowerContext.filter;this.updateBrightnessFilter(),this.lowerContext.drawImage(this.baseImg,this.srcLeft,this.srcTop,this.srcWidth,this.srcHeight,this.destLeft,this.destTop,this.destWidth,this.destHeight),this.lowerContext.filter=a,this.currentTransformedState("reverse",!0),""===t&&""!==this.currFlipState&&(t=this.currFlipState),this.currFlipState=t,this.flipColl=i,this.objColl=e.extend([],s,[],!0),this.lowerContext.filter="none",this.iterateObjColl(),this.lowerContext.filter=a,0!==o.activePoint.width&&(this.activeObj=e.extend({},o,{},!0)),this.isReverseFlip=!1},l.prototype.getFilterValue=function(t){return 0===t?1:1+.5*t/100},l.prototype.setFilterValue=function(t){var e;return e=1===t?0:100*(t-1)/.5,Math.round(e)},l.prototype.getSaturationFilterValue=function(t){return 0===t?1:1+t/100},l.prototype.setSaturationFilterValue=function(t){var e;return e=1===t?0:100*(t-1),Math.round(e)},l.prototype.getBlackAndWhiteData=function(t){for(var e=0;e<t.data.length;e+=4){var i=0;t.data[e]+t.data[e+1]+t.data[e+2]>383&&(i=255),t.data[e]=i,t.data[e+1]=i,t.data[e+2]=i,t.data[e+3]=255}return t},l.prototype.setBrightness=function(t){this.applyPenDraw(),this.adjustmentLevel.brightness=t,t=this.getFilterValue(t);var e=this.lowerContext.filter;this.updateAdjustment("brightness",t),this.updateUndoRedoColl("brightness",t,e,this.lowerContext.filter,this.zoomFactor,this.adjustmentLevel.sharpen,this.adjustmentLevel.bw)},l.prototype.setContrast=function(t){this.applyPenDraw(),this.adjustmentLevel.contrast=t;var e=this.lowerContext.filter;t=this.getFilterValue(t),t*=100,this.updateAdjustment("contrast",t),this.updateUndoRedoColl("contrast",t,e,this.lowerContext.filter,this.zoomFactor,this.adjustmentLevel.sharpen,this.adjustmentLevel.bw)},l.prototype.setHue=function(t){this.applyPenDraw(),this.adjustmentLevel.hue=t,t*=3;var e=this.lowerContext.filter;this.updateAdjustment("hue",t),this.updateUndoRedoColl("hue",t,e,this.lowerContext.filter,this.zoomFactor,this.adjustmentLevel.sharpen,this.adjustmentLevel.bw)},l.prototype.setSaturation=function(t){this.applyPenDraw(),this.adjustmentLevel.saturation=t,t=this.getSaturationFilterValue(t),t*=100;var e=this.lowerContext.filter;this.updateAdjustment("saturation",t),this.updateUndoRedoColl("saturation",t,e,this.lowerContext.filter,this.zoomFactor,this.adjustmentLevel.sharpen,this.adjustmentLevel.bw)},l.prototype.setOpacity=function(t){this.applyPenDraw(),this.adjustmentLevel.opacity=t,t>=50?t/=100:40===t?t=.45:30===t?t=.4:20===t?t=.35:10===t?t=.3:0===t&&(t=.25);var e=this.lowerContext.filter;this.updateAdjustment("opacity",t),this.updateUndoRedoColl("opacity",t,e,this.lowerContext.filter,this.zoomFactor,this.adjustmentLevel.sharpen,this.adjustmentLevel.bw)},l.prototype.setBlur=function(t){this.applyPenDraw(),this.adjustmentLevel.blur=t,t/=20,t+=.5;var e=this.lowerContext.filter;this.updateAdjustment("blur",t),this.updateUndoRedoColl("blur",t,e,this.lowerContext.filter,this.zoomFactor,this.adjustmentLevel.sharpen,this.adjustmentLevel.bw)},l.prototype.setExposure=function(t){this.applyPenDraw(),this.adjustmentLevel.exposure=t,t=this.getFilterValue(t);var e=this.lowerContext.filter;this.updateAdjustment("exposure",t),this.updateUndoRedoColl("exposure",t,e,this.lowerContext.filter,this.zoomFactor,this.adjustmentLevel.sharpen,this.adjustmentLevel.bw)},l.prototype.setFilter=function(t){t=t.toLowerCase(),this.applyPenDraw();var e=this.lowerContext.filter,i=this.currentFilter;this.updateAdjustment(t,null),this.updateUndoRedoColl(t,i,e,this.lowerContext.filter,this.zoomFactor,this.adjustmentLevel.sharpen,this.adjustmentLevel.bw)},l.prototype.renderImage=function(){var t=this.lowerContext.filter;this.applyActObj(),this.upperContext.clearRect(0,0,this.lowerCanvas.width,this.lowerCanvas.height),this.lowerContext.clearRect(0,0,this.lowerCanvas.width,this.lowerCanvas.height),this.updateCurrentTransformedState("initial"),this.updateBrightnessFilter(),this.lowerContext.drawImage(this.baseImg,this.srcLeft,this.srcTop,this.srcWidth,this.srcHeight,this.destLeft,this.destTop,this.destWidth,this.destHeight),this.updateCurrentTransformedState("reverse"),this.lowerContext.filter="none",this.iterateObjColl(),this.freehandRedraw(this.lowerContext),this.lowerContext.filter=t,(this.isCircleCrop||!e.isNullOrUndefined(this.currSelectionPoint)&&"crop-circle"===this.currSelectionPoint.shape)&&this.cropCircle(this.lowerContext)},l.prototype.updateTextBox=function(t){this.upperContext.clearRect(0,0,this.lowerCanvas.width,this.lowerCanvas.height),this.lowerContext.clearRect(0,0,this.lowerCanvas.width,this.lowerCanvas.height),this.redrawImgWithObj(),this.textArea.style.display="block",this.textArea.style.fontFamily=t.textSettings.fontFamily,this.textArea.style.fontSize=t.textSettings.fontSize+"px",this.textArea.style.color=t.strokeSettings.strokeColor,this.textArea.style.fontWeight=t.textSettings.bold?"bold":"normal",this.textArea.style.fontStyle=t.textSettings.italic?"italic":"normal",this.textArea.style.border="2px solid "+this.themeColl[this.theme].primaryColor,this.textArea.value=t.keyHistory,this.activeObj=e.extend({},t,{},!0),this.updateFontStyles(),this.textArea.style.width=this.activeObj.activePoint.width+"px"},l.prototype.setAdjustment=function(t){this.lowerContext.clearRect(0,0,this.lowerCanvas.width,this.lowerCanvas.height);var e,i,s=this.lowerContext.filter.split(" ");switch(t){case"brightness":i=s[0].split("("),e=parseFloat(i[1].split(")")[0]),this.adjustmentLevel.brightness=this.setFilterValue(e);break;case"contrast":i=s[1].split("("),e=parseFloat(i[1].split(")")[0]),e/=100,this.adjustmentLevel.contrast=this.setFilterValue(e);break;case"hue":i=s[2].split("("),e=parseFloat(i[1].split(")")[0]),e/=3,this.adjustmentLevel.hue=e;break;case"saturation":i=s[3].split("("),e=parseFloat(i[1].split(")")[0]),e/=100,this.adjustmentLevel.saturation=this.setSaturationFilterValue(e);break;case"opacity":i=s[4].split("("),.45===(e=parseFloat(i[1].split(")")[0]))?e=40:.4===e?e=30:.35===e?e=20:.3===e?e=10:.25===e?e=0:e*=100,this.adjustmentLevel.opacity=e;break;case"blur":i=s[5].split("("),e=parseFloat(i[1].split(")")[0]),e*=20,this.adjustmentLevel.blur=e;break;case"exposure":i=s[0].split("("),e=parseFloat(i[1].split(")")[0]),this.adjustmentLevel.exposure=this.setFilterValue(e)}this.callUpdateCurrentTransformedState()},l.prototype.updateFilter=function(t){var e=this.element.querySelector(".e-contextual-toolbar-wrapper .e-toolbar-item.e-selected");e&&e.classList.remove("e-selected");var i=document.getElementById(t.value+"Canvas");i&&i.parentElement.classList.add("e-selected"),this.currentFilter=t.value,this.lowerContext.filter=this.canvasFilter=t.previousObj,this.lowerContext.clearRect(0,0,this.lowerCanvas.width,this.lowerCanvas.height),this.isUndoRedo=!0,this.redrawImgWithObj()},l.prototype.drawNewSelection=function(t,e,i,s,o){var a,n="crop-"+t;"crop-custom"===n.toLowerCase()?(""===this.currObjType.shape&&this.drawCustomSelection("crop-custom"),e&&i&&(this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),this.currObjType.shape=this.activeObj.shape=n.toLowerCase(),this.activeObj.activePoint.startX=e,this.activeObj.activePoint.startY=i,this.activeObj.activePoint.endX=this.lowerCanvas.width,this.activeObj.activePoint.endY=this.lowerCanvas.height,this.activeObj.activePoint.width=this.activeObj.activePoint.endX-this.activeObj.activePoint.startX,this.activeObj.activePoint.height=this.activeObj.activePoint.endY-this.activeObj.activePoint.startY,this.drawObject("duplicate"))):"crop-canvas"===n.toLowerCase()?(this.upperCanvas.style.display="none",this.dragCanvas=!0):(this.currObjType.isCustomCrop=!1,this.currObjType.shape=n.toLowerCase(),s&&o?a={startX:e,startY:i,endX:e+s,endY:i+o,width:s,height:o}:s&&"crop-circle"===n&&(a={startX:e,startY:i,endX:e+s,endY:i+s,width:s,height:s}),this.activeObj.shape=n.toLowerCase(),this.drawObject("duplicate",null,!0,a))},l.prototype.clearSelection=function(){!this.disabled&&this.isImageLoaded&&(this.togglePen=!1,this.refreshActiveObj(),this.dragElement="",this.dragPoint.startX=this.dragPoint.startY=this.dragPoint.endX=this.dragPoint.endY=0,this.currObjType.shape="",this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),this.currObjType.isActiveObj=!0,this.currObjType.isCustomCrop=!1,this.upperCanvas.style.cursor="default")},l.prototype.crop=function(){var t=!1;if(!this.disabled&&this.isImageLoaded){this.currObjType.isUndoAction&&this.refreshUndoRedoColl();var e=void 0,i={startPoint:{x:this.activeObj.activePoint.startX,y:this.activeObj.activePoint.startY},endPoint:{x:this.activeObj.activePoint.endX,y:this.activeObj.activePoint.endY}};if(this.trigger("cropping",i),void 0!==this.activeObj.shape&&(e=this.activeObj.shape.split("-")),!this.disabled&&void 0!==this.activeObj.horTopLine&&(this.currObjType.isCustomCrop||"crop"===e[0])){t=!0;var s=this.activeObj.shape;this.cropImg(),this.zoomFactor=0,this.enableDisableToolbarBtn(),this.updateUndoRedoColl("crop",s)}}return t},l.prototype.flip=function(t){if(!this.disabled&&this.isImageLoaded){var i=this.zoomFactor,s={direction:t};this.trigger("flipping",s);var o=[],a=void 0;e.isNullOrUndefined(this.activeObj.activePoint)||(void 0!==this.activeObj.shape&&(o=this.activeObj.shape.split("-")),(this.currObjType.isCustomCrop||"crop"===o[0])&&(a=this.currObjType.isCustomCrop?"custom":o[1],this.updateImageRatioForActObj(),this.objColl.push(this.activeObj),this.refreshActiveObj())),this.redrawActObj(),this.lowerContext.clearRect(0,0,this.lowerCanvas.height,this.lowerCanvas.width),this.lowerContext.clearRect(0,0,this.lowerCanvas.width,this.lowerCanvas.height),this.upperContext.clearRect(0,0,this.lowerCanvas.height,this.lowerCanvas.width),this.upperContext.clearRect(0,0,this.lowerCanvas.width,this.lowerCanvas.height);var n=e.extend([],this.objColl,[],!0),r=e.extend({},this.activeObj,{},!0);this.objColl=[],this.refreshActiveObj(),this.isReverseFlip||this.updateCurrentTransformedState("initial"),"horizontal"===t.toLowerCase()?(this.updateFlipState(t.toLowerCase()),"horizontal"===this.currFlipState.toLowerCase()?this.currFlipState="":this.currFlipState="horizontal"):(this.updateFlipState(t.toLowerCase()),"vertical"===this.currFlipState.toLowerCase()?this.currFlipState="":this.currFlipState="vertical"),this.rotatedFlipCropSelection&&(this.destLeft+=this.totalPannedInternalPoint.x,this.destTop+=this.totalPannedInternalPoint.y);var h=this.lowerContext.filter;this.updateBrightnessFilter(),this.lowerContext.drawImage(this.baseImg,this.srcLeft,this.srcTop,this.srcWidth,this.srcHeight,this.destLeft,this.destTop,this.destWidth,this.destHeight),this.lowerContext.filter=h,this.updateFlipState(t.toLowerCase()),this.isReverseFlip||(this.updateCurrentTransformedState("reverse"),this.updateFlipColl(t.toLocaleLowerCase()),this.rotateFlipColl.push(t.toLowerCase())),1===this.rotateFlipColl.length&&this.setClientTransformedDimension(),this.isCircleCrop&&this.cropCircle(this.lowerContext),this.objColl=e.extend([],n,[],!0),this.activeObj=e.extend({},r,{},!0);for(var l=0,c=this.objColl.length;l<c;l++)0===this.objColl[l].flipObjColl.length?this.objColl[l].flipObjColl.push(t):this.objColl[l].flipObjColl[this.objColl[l].flipObjColl.length-1]===t?this.objColl[l].flipObjColl.pop():this.objColl[l].flipObjColl.push(t);this.redrawObj(t.toLowerCase());var d=this.lowerContext.filter;this.lowerContext.filter=this.getDefaultFilter(),this.iterateObjColl(),e.isNullOrUndefined(this.currSelectionPoint)||(n=e.extend([],this.objColl,[],!0),this.objColl=[],this.objColl.push(this.currSelectionPoint),this.redrawObj(t.toLowerCase()),this.currSelectionPoint=e.extend({},this.objColl[0],{},!0),this.objColl=n),"horizontal"===t.toLowerCase()||"vertical"===t.toLowerCase()?(this.flipFreehandrawColl(t.toLowerCase()),this.freehandRedraw(this.lowerContext)):this.freehandRedraw(this.lowerContext),this.lowerContext.filter=d,this.refreshActiveObj(),this.isUndoRedo||this.updateUndoRedoColl("flip",t,this.objColl,null,i,this.adjustmentLevel.sharpen,this.adjustmentLevel.bw),this.isUndoRedo=!1,this.clearOuterCanvas(this.lowerContext),this.clearOuterCanvas(this.upperContext),e.isNullOrUndefined(a)||(this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),this.activeObj=e.extend({},this.objColl[this.objColl.length-1],{},!0),this.objColl.pop(),this.drawObject("duplicate",this.activeObj),this.isReverseFlip||this.refreshToolbar("main",!0,!0)),e.isNullOrUndefined(this.activeObj.shape)&&!this.isReverseFlip?this.refreshToolbar("main"):this.isReverseFlip||this.refreshToolbar("main",!0,!0),this.alignRotateFlipColl()}},l.prototype.getImageData=function(){return this.lowerContext.getImageData(this.destLeft,this.destTop,this.destWidth,this.destHeight)},l.prototype.open=function(t){if(!this.disabled){a.showSpinner(this.element),this.element.style.opacity="0.5";var i=document.querySelector("#"+this.element.id+"_currPos");if(i&&(i.style.display="none"),0===this.defToolbarItems.length&&e.isNullOrUndefined(document.getElementById(this.element.id+"_toolbar"))&&(this.toolbarHeight=0),e.isNullOrUndefined(this.toolbarTemplate)&&(this.reset(),this.update()),this.degree=0,this.zoomFactor=0,this.isImageLoaded=!1,this.currSelectionPoint=null,"string"===typeof t){var s=t.split(".");s.length>1?(s=s[s.length-2].split("/"),this.fileName=s[s.length-1]):this.fileName="ImageEditor",this.imageOnLoad(t)}else this.fileName="ImageEditor",this.lowerCanvas=document.querySelector("#"+this.element.id+"_lowerCanvas"),this.upperCanvas=document.querySelector("#"+this.element.id+"_upperCanvas"),this.lowerContext=this.lowerCanvas.getContext("2d"),this.upperContext=this.upperCanvas.getContext("2d"),this.lowerContext.clearRect(0,0,this.lowerCanvas.width,this.lowerCanvas.height),this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),this.inMemoryContext.clearRect(0,0,this.inMemoryCanvas.width,this.inMemoryCanvas.height),this.inMemoryCanvas.width=this.baseImg.width=t.width,this.inMemoryCanvas.height=this.baseImg.height=t.height,this.inMemoryContext.putImageData(t,0,0),this.baseImg.src=this.inMemoryCanvas.toDataURL()}},l.prototype.reset=function(){this.disabled||(this.inMemoryContext.clearRect(0,0,this.lowerCanvas.width,this.lowerCanvas.height),this.inMemoryContext.clearRect(0,0,this.lowerCanvas.height,this.lowerCanvas.width),this.lowerContext.clearRect(0,0,this.lowerCanvas.width,this.lowerCanvas.height),this.lowerContext.clearRect(0,0,this.lowerCanvas.height,this.lowerCanvas.width),this.upperContext.clearRect(0,0,this.lowerCanvas.width,this.lowerCanvas.height),this.upperContext.clearRect(0,0,this.lowerCanvas.height,this.lowerCanvas.width),this.lowerContext.filter=this.getDefaultFilter(),this.refreshActiveObj(),this.refreshToolbar("main"),e.Browser.isDevice&&document.getElementById(this.element.id+"_bottomToolbar")&&(e.getComponent(document.getElementById(this.element.id+"_bottomToolbar"),"toolbar").destroy(),this.createBottomToolbar()),this.objColl=[],this.isImageLoaded=!1,this.degree=this.undoRedoStep=0,this.keyHistory=this.currFlipState="",this.upperCanvas.style.display="none",this.togglePan=this.togglePen=!1,this.upperCanvas.style.cursor=this.lowerCanvas.style.cursor="default",this.undoRedoColl=[],this.dragCanvas=this.isUndoRedo=!1,this.tempKeyHistory="",this.lowerContext.lineWidth=this.upperContext.lineWidth=void 0,this.touchEndPoint={},this.currentToolbar="main",this.textStartPoints={x:0,y:0},this.fontSizeColl=[],this.textArea.value=this.textArea.textContent="",this.textArea.style.display="none",this.strokeSettings={strokeColor:"#fff",fillColor:"",strokeWidth:null},this.textSettings={text:"Enter Text",fontFamily:"Arial",fontSize:null,fontRatio:null,bold:!1,italic:!1,underline:!1},this.tempStrokeSettings={strokeColor:"#fff",fillColor:"",strokeWidth:null},this.tempTextSettings={text:"Enter Text",fontFamily:"Arial",fontSize:null,fontRatio:null,bold:!1,italic:!1,underline:!1},this.timer=void 0,this.penStrokeWidth=void 0,this.currObjType.isUndoAction=!1,this.undoRedoStep=0,this.tempObjColl=void 0,this.adjustmentLevel={brightness:0,contrast:0,hue:0,opacity:100,saturation:0,blur:0,exposure:0,sharpen:!1,bw:!1},this.tempAdjustmentLevel={brightness:0,contrast:0,hue:0,opacity:100,saturation:0,blur:0,exposure:0,sharpen:!1,bw:!1},this.canvasFilter=this.currentFilter=this.tempAdjustmentValue="",this.lowerContext.filter=this.initialAdjustmentValue=this.adjustmentValue=this.getDefaultFilter(),this.destLeft=this.destTop=this.srcLeft=this.srcTop=0,this.destWidth=this.destHeight=this.srcWidth=this.srcHeight=null,this.currSelectionPoint=null,this.cropDestPoints={startX:0,startY:0,width:0,height:0},this.panDown=null,this.panMove=null,this.tempPanMove=null,this.flipColl=[],this.freehandDrawObj.time=this.freehandDrawObj.lastVelocity=0,this.freehandDrawObj.pointX=this.freehandDrawObj.pointY=0,this.points=[],this.pointColl={},this.pointCounter=this.freehandCounter=this.tempFreehandCounter=this.tempCurrentFreehandDrawIndex=0,this.isFreehandDrawing=!1,this.isReverseRotate=this.isReverseFlip=this.isPreventDragging=this.isRotateZoom=!1,this.currentPannedPoint=null,this.fileType=void 0,this.rotateFlipColl=[],this.isCircleCrop=!1,this.isCropTab=!1,this.rotatedDestPoints={startX:0,startY:0,width:0,height:0},this.croppedDegree=0,this.freehandDrawHoveredIndex=this.freehandDrawSelectedIndex=null,this.isFreehandDrawingPoint=this.isFreehandDrawEditing=!1,this.tempFreeHandDrawEditingStyles={strokeColor:null,fillColor:null,strokeWidth:null},this.totalPannedInternalPoint={x:0,y:0},this.totalPannedClientPoint={x:0,y:0},this.lowerCanvas.style.left=this.upperCanvas.style.left="",this.lowerCanvas.style.top=this.upperCanvas.style.top="",this.lowerCanvas.style.maxWidth=this.upperCanvas.style.maxWidth="",this.lowerCanvas.style.maxHeight=this.upperCanvas.style.maxHeight="",this.currentSelectionPoint=null,this.totalPannedPoint={x:0,y:0},this.fileName="",this.isBrightnessAdjusted=this.isInitialLoading=!1,this.defaultZoomFactor=this.cropZoomFactor=this.zoomFactor=0,this.tempActObj=null,this.lastPan={x:0,y:0},this.selectedFreehandColor="#42a5f5",this.isFreehandDrawCustomized=!1,this.isShapeInserted=!1,this.tempActObj=void 0,this.lastPan={x:0,y:0},this.currObjType={shape:"",isDragging:!1,isActiveObj:!1,isText:!1,isInitialText:!1,isLine:!1,isInitialLine:!1,isCustomCrop:!1,isZoomed:!1,isUndoZoom:!1,isUndoAction:!1,isFiltered:!1,isSave:!1},this.isAllowCropPan=!1,this.tempPannedPoint={x:0,y:0},this.cropObj={cropZoom:0,defaultZoom:0,totalPannedPoint:{x:0,y:0},totalPannedClientPoint:{x:0,y:0},totalPannedInternalPoint:{x:0,y:0},activeObj:{},rotateFlipColl:[],degree:0,currFlipState:"",destPoints:{startX:0,startY:0,width:0,height:0},srcPoints:{startX:0,startY:0,width:0,height:0}},this.afterCropActions=[],this.isCancelAction=this.preventZoomBtn=this.isFreehandPointMoved=!1,this.isTouch=!1,this.freehandDownPoint={x:0,y:0},this.tempFlipPanPoint={x:0,y:0},this.currentFreehandDrawIndex=0,this.tempCurrentFreehandDrawIndex=0,this.cancelObjColl=[],this.cancelPointColl=[],this.updateCanvas(),this.refreshDropDownBtn(!1),this.enableDisableToolbarBtn())},l.prototype.rotate=function(t){var i=!1;if(!this.disabled&&this.isImageLoaded&&t%90==0){i=!0;var s={degree:t};this.trigger("rotating",s);var o=[],a=void 0;e.isNullOrUndefined(this.activeObj.activePoint)||e.isNullOrUndefined(this.activeObj.shape)||(void 0!==this.activeObj.shape&&(o=this.activeObj.shape.split("-")),(this.currObjType.isCustomCrop||"crop"===o[0])&&(a=this.currObjType.isCustomCrop?"custom":o[1],this.updateImageRatioForActObj(),this.objColl.push(this.activeObj),this.refreshActiveObj())),this.redrawActObj(),this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height);var n=this.zoomFactor;this.drawRotatedImage(t),this.clearOuterCanvas(this.lowerContext),this.clearOuterCanvas(this.upperContext),e.isNullOrUndefined(a)||(this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),this.activeObj=e.extend({},this.objColl[this.objColl.length-1],{},!0),this.objColl.pop(),this.drawObject("duplicate",this.activeObj),this.isReverseRotate||this.refreshToolbar("main",!0,!0)),this.isUndoRedo||this.updateUndoRedoColl("rotate",t,this.objColl,null,n,this.adjustmentLevel.sharpen,this.adjustmentLevel.bw),this.isUndoRedo=!1,e.isNullOrUndefined(this.activeObj.shape)&&!this.isReverseRotate?this.refreshToolbar("main"):this.isReverseRotate||this.refreshToolbar("main",!0,!0),this.alignRotateFlipColl()}return i},l.prototype.export=function(t,e){var i=this;if(!this.disabled&&this.isImageLoaded){this.isFreehandDrawEditing&&this.applyFreehandDraw(),this.togglePen&&(this.currObjType.isZoomed=!0,this.apply()),"block"===this.textArea.style.display&&this.redrawActObj(),this.applyActObj(),this.lowerContext.filter=this.canvasFilter,t=t||"Png",this.redrawActObj();var s={cancel:!1,fileName:e||this.fileName,fileType:t},o={fileName:e||this.fileName,fileType:t};this.trigger("beforeSave",s,function(s){s.cancel||(i.currObjType.isSave=!0,e=s.fileName?s.fileName:e,"svg"===t.toLowerCase()?(e=e||i.fileName,i.toSVGImg(e)):(t.toLowerCase(),e=e||i.fileName,i.toBlobFn(e,t.toLowerCase())),i.trigger("saved",o),i.refreshToolbar("main"),i.lowerCanvas.style.left=i.upperCanvas.style.left="",i.lowerCanvas.style.top=i.upperCanvas.style.top="",i.lowerCanvas.style.maxWidth=i.upperCanvas.style.maxWidth="",i.lowerCanvas.style.maxHeight=i.upperCanvas.style.maxHeight="")})}},l.prototype.select=function(t,i,s,o,a){if(!this.disabled&&this.isImageLoaded){this.zoomFactor>0&&!e.isNullOrUndefined(this.activeObj.shape)&&"crop"===this.activeObj.shape.split("-")[0]&&e.isNullOrUndefined(this.currentSelectionPoint)&&(this.currentSelectionPoint=e.extend({},this.activeObj,{},!0));var n=!1,r=void 0;if(void 0!==this.activeObj.shape&&(r=this.activeObj.shape.split("-")),void 0===r&&this.currObjType.isCustomCrop?n=!0:void 0!==r&&"crop"===r[0]&&(n=!0),this.redrawActObj(),this.refreshActiveObj(),this.keyHistory="",this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),this.upperCanvas.style.display="block",!e.isNullOrUndefined(this.currSelectionPoint)||this.defaultZoomFactor>0||0!==this.degree&&0!==this.totalPannedInternalPoint.x&&0!==this.totalPannedInternalPoint.y&&!n){if(this.isCircleCrop=!1,this.defaultZoomFactor>0){var h=this.zoomFactor=this.defaultZoomFactor;this.isCropTab=!1;for(var l=0;l<10*h;l++)this.zoom(-.1);this.resetPanPoints()}this.cancelObjColl=e.extend([],this.objColl,[],!0),this.cancelPointColl=e.extend([],this.pointColl,[],!0),this.isCropTab=!0,this.setCurrSelectionPoints(!0),this.zoomFactor=this.cropZoomFactor,e.isNullOrUndefined(this.cropObj.activeObj.shape)&&this.drawNewSelection(t,i,s,o,a)}else"custom"===t&&(this.currObjType.shape=""),this.drawNewSelection(t,i,s,o,a)}},l.prototype.freeHandDraw=function(t){t?(this.points=[],this.refreshActiveObj(),this.togglePen=!0,this.upperCanvas.style.cursor="crosshair",this.upperCanvas.style.display="block",e.isNullOrUndefined(this.activeObj.strokeSettings)&&(this.activeObj.strokeSettings=this.strokeSettings),e.isNullOrUndefined(this.activeObj.strokeSettings.strokeWidth)&&(this.activeObj.strokeSettings.strokeWidth=4),this.refreshToolbar("pen")):(this.upperCanvas.style.cursor="default",this.apply(),this.refreshToolbar("main"),this.currentToolbar="main",this.isFreehandDrawCustomized=!1)},l.prototype.freehandDraw=function(t){!this.disabled&&this.isImageLoaded&&this.freeHandDraw(t)},l.prototype.pan=function(t){!this.disabled&&this.isImageLoaded&&(t?(this.togglePan=!0,this.redrawActObj(),this.dragCanvas=!0,this.lowerCanvas.style.cursor=this.upperCanvas.style.cursor="grab",this.panDown=null):(this.dragCanvas=this.togglePan=this.currObjType.isCustomCrop=!1,this.lowerCanvas.style.cursor=this.upperCanvas.style.cursor="default"))},l.prototype.setDestPointsForFlipState=function(t){""!==this.getCurrentPanRegion()&&("horizontal"===this.getCurrentPanRegion()?this.destLeft=this.lowerCanvas.clientWidth-(this.destWidth+this.destLeft):"vertical"===this.getCurrentPanRegion()?this.destTop=this.lowerCanvas.clientHeight-(this.destHeight+this.destTop):(this.destLeft=this.lowerCanvas.clientWidth-(this.destWidth+this.destLeft),this.destTop=this.lowerCanvas.clientHeight-(this.destHeight+this.destTop)),e.isNullOrUndefined(t)||this.updateObjAndFreeHandDrawColl())},l.prototype.zoom=function(t){if(!this.disabled&&this.isImageLoaded){if(0===this.zoomFactor&&t<0||this.zoomFactor>5&&t>0||this.zoomFactor>0&&t<0&&this.disableZoomOutBtn())return;var i=void 0,s=void 0,o=!1;void 0!==this.activeObj.shape&&(i=this.activeObj.shape.split("-")),void 0!==i&&"crop"===i[0]?(s=e.extend({},this.activeObj,{},!0),this.isCropTab=!0):e.isNullOrUndefined(this.activeObj.shape)||"crop"===i[0]||(o=!0),this.redrawActObj(),this.refreshActiveObj(),this.upperContext.clearRect(0,0,this.lowerCanvas.width,this.lowerCanvas.height),this.lowerContext.filter=this.canvasFilter,this.upperCanvas.style.cursor="default";var a=void 0,n=e.extend([],this.objColl,[],!0);if(a=3.75===t||1===t?.1:-3.75===t?-.1:t,this.isCropTab||(0!==this.degree&&(this.redrawActObj(),this.currentPannedPoint={x:0,y:0},this.rotatePan()),this.setDestPointsForFlipState(!0)),0===this.degree)this.drawZoomImgToCanvas(t,s),""!==this.getCurrentPanRegion()&&(this.tempFlipPanPoint.x+=this.totalPannedPoint.x,this.tempFlipPanPoint.y+=this.totalPannedPoint.y,n=e.extend([],this.objColl,[],!0),this.objColl=[],this.rotatedFlip(),0===this.totalPannedPoint.x&&0===this.totalPannedPoint.y||(this.totalPannedPoint={x:0,y:0}),0===this.tempPannedPoint.x&&0===this.tempPannedPoint.y||(this.tempPannedPoint={x:0,y:0}));else if(this.updateObjAndFreeHandDrawColl(),this.totalPannedClientPoint={x:0,y:0},this.totalPannedInternalPoint={x:0,y:0},this.rotateZoom(t),""!==this.getCurrentPanRegion()){r=this.lowerContext.filter;this.lowerContext.filter="none",this.zoomObjColl(),this.zoomFreehandDrawColl(),this.lowerContext.filter=r}if(""===this.getCurrentPanRegion()){r=this.lowerContext.filter;this.lowerContext.filter="none",this.zoomObjColl(),this.zoomFreehandDrawColl(),this.lowerContext.filter=r}else if(0===this.degree){var r=this.lowerContext.filter;this.lowerContext.filter="none";var h=this.destLeft,l=this.destTop;this.setDestPointsForFlipState(),this.objColl=n,this.zoomObjColl(),this.zoomFreehandDrawColl(),this.destLeft=h,this.destTop=l,this.lowerContext.filter=r}(!e.isNullOrUndefined(this.currSelectionPoint)&&"crop-circle"===this.currSelectionPoint.shape||this.isCircleCrop)&&this.cropCircle(this.lowerContext),this.clearOuterCanvas(this.lowerContext),this.refreshActiveObj(),e.isNullOrUndefined(s)||(this.activeObj=e.extend({},s,{},!0),this.drawObject("duplicate",this.activeObj),"crop"===this.currentToolbar?this.refreshToolbar("main",!0,!0):this.refreshToolbar(this.currentToolbar,!0,!0),0===this.zoomFactor&&(this.currSelectionPoint=null)),this.isUndoRedo||this.updateUndoRedoColl("zoom",a,this.objColl,null,this.zoomFactor,this.adjustmentLevel.sharpen,this.adjustmentLevel.bw),this.isUndoRedo=!1;var c=document.querySelector("#"+this.element.id+"_zoomOut");e.isNullOrUndefined(c)||0!==this.zoomFactor?e.isNullOrUndefined(c)||(c.classList.remove("e-disabled"),c.parentElement.classList.remove("e-overlay")):(c.classList.add("e-disabled"),c.parentElement.classList.add("e-overlay")),this.togglePan||this.callMainToolbar(!1,!0),this.autoEnablePan(),e.isNullOrUndefined(s)||(this.activeObj=e.extend({},s,{},!0)),"crop-custom"===this.activeObj.shape&&(this.currObjType.isCustomCrop=!0),e.isNullOrUndefined(this.activeObj.activePoint)||this.activeObj.activePoint.width,"crop"!==this.currentToolbar&&e.isNullOrUndefined(s)?(this.refreshToolbar("main"),this.currentToolbar="main"):this.refreshToolbar("main",!0,!0);var d=this.element.querySelector(".e-img-pan .e-btn");!e.isNullOrUndefined(d)&&this.togglePan?d.classList.add("e-selected-btn"):e.isNullOrUndefined(d)||d.classList.remove("e-selected-btn"),o&&(this.activeObj=e.extend({},this.objColl[this.objColl.length-1],{},!0),this.objColl.pop(),this.drawObject("duplicate",this.activeObj),"text"===this.activeObj.shape?this.refreshToolbar("text"):this.refreshToolbar("shapes"),this.updateToolbarItems())}},l.prototype.drawEllipse=function(t,e,i,s,o,a,n){var r=!1,h=this.isPointsInRange(t,e);if(!this.disabled&&this.isImageLoaded&&h){r=!0,this.redrawActObj(),this.activeObj.shape="ellipse","freehanddraw"===this.currObjType.shape&&(this.apply(),this.upperCanvas.style.cursor="default",this.currObjType.shape=""),this.currObjType.isCustomCrop=!1;var l={x:t,y:e};this.drawShape("ellipse",o,a,n,l,i,s)}return r},l.prototype.drawLine=function(t,e,i,s,o,a){var n=!1,r=this.isPointsInRange(t,e);if(!this.disabled&&this.isImageLoaded&&r){n=!0,this.redrawActObj(),this.activeObj.shape="line","freehanddraw"===this.currObjType.shape&&(this.apply(),this.upperCanvas.style.cursor="default",this.currObjType.shape=""),this.currObjType.isCustomCrop=!1;var h={x:t,y:e},l=i-t,c=s-e;this.drawShape("line",o,a,null,h,l,c)}return n},l.prototype.drawRectangle=function(t,e,i,s,o,a,n){var r=!1,h=this.isPointsInRange(t,e);if(!this.disabled&&this.isImageLoaded&&h){r=!0,this.redrawActObj(),this.activeObj.shape="rectangle","freehanddraw"===this.currObjType.shape&&(this.apply(),this.upperCanvas.style.cursor="default",this.currObjType.shape=""),this.currObjType.isCustomCrop=!1;var l={x:t,y:e};this.drawShape("rectangle",o,a,n,l,i,s)}return r},l.prototype.drawText=function(t,e,i,s,o,a,n,r){var h=!1,l=this.isPointsInRange(t,e);return!this.disabled&&this.isImageLoaded&&l&&(h=!0,this.drawShapeText(i,s,o,a,n,r,t,e)),h},l.prototype.selectShape=function(t){var i=!1;if(!this.disabled&&this.isImageLoaded)if(this.applyActObj(),"shape"===t.split("_")[0]){for(var s=void 0,o=0;o<this.objColl.length;o++)if(this.objColl[o].currIndex===t){s=e.extend({},this.objColl[o],{},!0);break}e.isNullOrUndefined(s)?i=!1:(i=!0,this.activeObj=s,this.lowerContext.filter=this.canvasFilter,this.redrawShape(this.activeObj),"text"===this.activeObj.shape?this.refreshToolbar("text"):"pen"===this.activeObj.shape?this.refreshToolbar("pen"):this.refreshToolbar("shapes"),this.updateToolbarItems())}else"pen"===t.split("_")[0]&&(this.isFreehandDrawEditing&&this.okBtn(),this.isFreehandDrawIndex(parseInt(t.split("_")[1],10)-1)?(i=!0,this.selectFreehandDraw(parseInt(t.split("_")[1],10)-1),this.updateToolbarItems()):i=!1);return i},l.prototype.deleteShape=function(t){if(!this.disabled&&this.isImageLoaded){if(this.applyActObj(),"shape"===t.split("_")[0]){for(var e=0;e<this.objColl.length;e++)if(this.objColl[e].currIndex===t){this.objColl.splice(e,1);break}}else"pen"===t.split("_")[0]&&this.isFreehandDrawIndex(parseInt(t.split("_")[1],10)-1)&&this.deleteFreehandDraw(parseInt(t.split("_")[1],10)-1,!0);this.lowerContext.filter=this.canvasFilter,this.lowerContext.clearRect(0,0,this.lowerCanvas.width,this.lowerCanvas.height),this.redrawImgWithObj(),this.refreshToolbar("main")}},l.prototype.getShapeSetting=function(t){var i;if(!this.disabled&&this.isImageLoaded)if(this.applyActObj(),"shape"===t.split("_")[0]){for(var s=void 0,o=0;o<this.objColl.length;o++)if(this.objColl[o].currIndex===t){s=e.extend({},this.objColl[o],{},!0);break}i=this.getObjDetails(s)}else"pen"===t.split("_")[0]&&(i=this.getFreehandDrawDetails(parseInt(t.split("_")[1],10)-1));return i},l.prototype.getShapeSettings=function(){var t=[];if(!this.disabled&&this.isImageLoaded){this.applyActObj();for(e=0;e<this.objColl.length;e++){i=this.getObjDetails(this.objColl[e]);t.push(i)}for(var e=0;e<this.freehandCounter;e++){var i=this.getFreehandDrawDetails(e);t.push(i)}}return t},l.prototype.update=function(){var t=document.querySelector("#"+this.element.id+"_canvasWrapper");e.isNullOrUndefined(t)||(t.style.width=this.element.offsetWidth-2+"px"),this.lowerCanvas.width=this.upperCanvas.width=this.element.offsetWidth-2,e.Browser.isDevice?(e.isNullOrUndefined(t)||(t.style.height=this.element.offsetHeight-2*this.toolbarHeight-5+"px"),this.lowerCanvas.height=this.upperCanvas.height=this.element.offsetHeight-2*this.toolbarHeight-5):(e.isNullOrUndefined(t)||(t.style.height=this.element.offsetHeight-this.toolbarHeight-3+"px"),this.lowerCanvas.height=this.upperCanvas.height=this.element.offsetHeight-this.toolbarHeight-3),this.lowerContext.filter=this.canvasFilter=this.initialAdjustmentValue=this.adjustmentValue=this.getDefaultFilter(),this.lowerContext.clearRect(0,0,this.lowerCanvas.width,this.lowerCanvas.height),this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height)},l.prototype.finetuneImage=function(t,e){if(!this.disabled&&this.isImageLoaded){switch(t.toLowerCase()){case"brightness":this.setBrightness(e);break;case"contrast":this.setContrast(e);break;case"hue":this.setHue(e);break;case"saturation":this.setSaturation(e);break;case"opacity":this.setOpacity(e);break;case"blur":this.setBlur(e);break;case"exposure":this.setExposure(e)}this.canvasFilter=this.lowerContext.filter}},l.prototype.applyImageFilter=function(t){!this.disabled&&this.isImageLoaded&&(this.setFilter(t.toString()),this.canvasFilter=this.lowerContext.filter)},l.prototype.undo=function(){if(!this.disabled&&this.isImageLoaded&&this.undoRedoStep>0){e.isNullOrUndefined(this.activeObj.shape)?this.refreshToolbar("main"):this.refreshToolbar("shapes"),0!==this.activeObj.activePoint.width&&(this.tempActObj=this.activeObj),this.undoRedoStep--,this.enableDisableToolbarBtn(),this.isUndoRedo=!0,this.lowerContext.filter=this.canvasFilter;var t=this.undoRedoColl[this.undoRedoStep];this.undoRedoColl.length===this.undoRedoStep?this.currObjType.isUndoAction=!1:this.currObjType.isUndoAction=!0,"textTransform"!==t.operation&&"block"===this.textArea.style.display&&(this.textArea.style.display="none"),this.element.querySelector(".e-contextual-toolbar-wrapper").classList.add("e-hide");var i=void 0,s=void 0,o=[],a=void 0,n="";switch(t.operation){case"rotate":90===t.value?n="rotateleft":-90===t.value&&(n="rotateright"),this.performTransformation(n);break;case"flip":"horizontal"===t.value.toLowerCase()?n="horizontalflip":"vertical"===t.value.toLowerCase()&&(n="verticalflip"),this.performTransformation(n);break;case"zoom":0===this.zoomFactor&&0!==t.zoomFactor&&(this.zoomFactor=t.zoomFactor),this.zoom(-t.value),this.isUndoRedo=!0;break;case"pan":i=this.destLeft,s=this.destTop,this.destLeft=t.previousObj.x,this.destTop=t.previousObj.y,i+=this.destLeft,s+=this.destTop,this.drawPannedImage(i,s);break;case"crop":e.isNullOrUndefined(this.currSelectionPoint)||(o=e.extend([],this.undoRedoColl,[],!0),this.select("Custom"),this.refreshToolbar("main",!0,!0),e.getComponent(this.element.querySelector("#"+this.element.id+"_cropBtn"),"dropdown-btn").toggle(),this.undoRedoColl=o,this.enableDisableToolbarBtn());break;case"freehanddraw":this.pointColl=t.previousObj,this.freehandCounter--,this.lowerContext.clearRect(0,0,this.lowerCanvas.width,this.lowerCanvas.height),this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),this.isUndoRedo=!0,this.redrawImgWithObj();break;case"freehanddrawCustomized":this.pointColl=t.previousObj,this.lowerContext.clearRect(0,0,this.lowerCanvas.width,this.lowerCanvas.height),this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),this.isUndoRedo=!0,this.redrawImgWithObj();break;case"delete":"freehanddraw"===t.value?(this.pointColl=t.previousObj,this.freehandCounter++):"shape"===t.value&&(this.objColl=t.previousObj),this.lowerContext.clearRect(0,0,this.lowerCanvas.width,this.lowerCanvas.height),this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),this.isUndoRedo=!0,this.redrawImgWithObj();break;case"selectionTransform":this.activeObj=e.extend({},t.previousSelectionObj,{},!0),this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),0!==this.activeObj.activePoint.width&&0!==this.activeObj.activePoint.height?(this.drawObject("duplicate",this.activeObj),this.refreshToolbar("main",!0,!0)):this.refreshToolbar("main"),this.currObjType.isCustomCrop=!1;break;case"shapeTransform":this.objColl=e.extend([],t.previousObj,[],!0),this.lowerContext.clearRect(0,0,this.lowerCanvas.width,this.lowerCanvas.height),this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),this.isUndoRedo=!0,this.redrawImgWithObj(),this.refreshActiveObj();break;case"textTransform":this.objColl=e.extend([],t.previousObj,[],!0);for(r=0;r<t.previousObj.length;r++)if(this.tempActObj.currIndex===t.previousObj[r].currIndex){a=e.extend({},t.previousObj[r],{},!0),this.objColl.splice(r,1);break}e.isNullOrUndefined(a)||this.updateTextBox(a);break;case"text":if(e.isNullOrUndefined(this.tempActObj)||(this.activeObj=e.extend({},this.tempActObj,{},!0)),0===t.value.length&&1===this.objColl.length)this.tempActObj=e.extend({},this.objColl[0],{},!0);else for(var r=0;r<this.objColl.length;r++){if(!e.isNullOrUndefined(this.objColl[r])&&e.isNullOrUndefined(t.value[r])){this.tempActObj=e.extend({},t.value[r],{},!0);break}if(t.value[r].currIndex!==this.objColl[r].currIndex){this.tempActObj=e.extend({},this.objColl[r],{},!0);break}}this.activeObj=e.extend({},this.tempActObj,{},!0),this.objColl=e.extend([],t.value,[],!0),this.lowerContext.clearRect(0,0,this.lowerCanvas.width,this.lowerCanvas.height),this.isUndoRedo=!0,this.redrawImgWithObj(),this.textArea.style.display="block",this.textArea.value=t.previousObj;break;case"brightness":case"contrast":case"hue":case"saturation":case"opacity":case"blur":case"exposure":this.lowerContext.filter=this.canvasFilter=t.previousObj,this.lowerContext.filter.split(" ").length>1&&"1"===this.lowerContext.filter.split(" ")[0].split("(")[1].split(")")[0]&&(this.isBrightnessAdjusted=!1),this.setAdjustment(t.operation),this.isUndoRedo=!0;break;case"default":case"chrome":case"cold":case"warm":case"grayscale":case"sepia":case"invert":this.updateFilter(t)}}},l.prototype.redo=function(){if(!this.disabled&&this.isImageLoaded&&this.undoRedoStep<this.undoRedoColl.length){e.isNullOrUndefined(this.activeObj.shape)?this.refreshToolbar("main"):this.refreshToolbar("shapes"),this.undoRedoStep++,this.enableDisableToolbarBtn(),this.isUndoRedo=!0,this.lowerContext.filter=this.canvasFilter;var t=this.undoRedoColl[this.undoRedoStep-1];this.undoRedoColl.length===this.undoRedoStep?this.currObjType.isUndoAction=!1:this.currObjType.isUndoAction=!0,"textTransform"!==t.operation&&"block"===this.textArea.style.display&&(this.textArea.style.display="none"),this.element.querySelector(".e-contextual-toolbar-wrapper").classList.add("e-hide");var i=this.element.querySelector(".e-contextual-toolbar-wrapper .e-toolbar-item.e-selected"),s=void 0,o=void 0,a=void 0,n=void 0,r="",h=void 0;switch(t.operation){case"rotate":90===t.value?r="rotateright":-90===t.value&&(r="rotateleft"),this.performTransformation(r);break;case"flip":"horizontal"===t.value.toLowerCase()?r="horizontalflip":"vertical"===t.value.toLowerCase()&&(r="verticalflip"),this.performTransformation(r);break;case"zoom":this.zoom(t.value);break;case"pan":s=this.destLeft,o=this.destTop,this.destLeft=t.currentObj.x,this.destTop=t.currentObj.y,s+=this.destLeft,o+=this.destTop,this.drawPannedImage(s,o);break;case"crop":this.cropImg(),this.refreshToolbar("main");break;case"freehanddraw":this.pointColl=t.currentObj,this.freehandCounter++,this.lowerContext.clearRect(0,0,this.lowerCanvas.width,this.lowerCanvas.height),this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),this.isUndoRedo=!0,this.redrawImgWithObj();break;case"freehanddrawCustomized":this.pointColl=t.currentObj,this.lowerContext.clearRect(0,0,this.lowerCanvas.width,this.lowerCanvas.height),this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),this.isUndoRedo=!0,this.redrawImgWithObj();break;case"delete":"freehanddraw"===t.value?(this.pointColl=t.currentObj,this.freehandCounter--):"shape"===t.value&&(this.objColl=t.currentObj),this.lowerContext.clearRect(0,0,this.lowerCanvas.width,this.lowerCanvas.height),this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),this.isUndoRedo=!0,this.redrawImgWithObj();break;case"selectionTransform":this.zoomFactor!==t.zoomFactor&&(this.zoomFactor>0?this.zoom(-this.zoomFactor):this.zoom(Math.abs(this.zoomFactor))),this.activeObj=e.extend({},t.currentSelectionObj,{},!0),this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),0!==this.activeObj.activePoint.width&&0!==this.activeObj.activePoint.height?(this.drawObject("duplicate",this.activeObj),this.refreshToolbar("main",!0,!0)):this.refreshToolbar("main");break;case"shapeTransform":this.objColl=e.extend([],t.currentObj,[],!0),this.lowerContext.clearRect(0,0,this.lowerCanvas.width,this.lowerCanvas.height),this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),this.isUndoRedo=!0,this.redrawImgWithObj(),this.refreshActiveObj();break;case"textTransform":this.objColl=e.extend([],t.currentObj,[],!0);for(var l=0;l<t.previousObj.length;l++)if(this.tempActObj.currIndex===t.currentObj[l].currIndex){h=e.extend({},t.currentObj[l],{},!0),this.objColl.splice(l,1);break}e.isNullOrUndefined(h)||this.updateTextBox(h);break;case"text":e.isNullOrUndefined(this.tempActObj)||(this.activeObj=e.extend({},this.tempActObj,{},!0)),this.objColl=e.extend([],t.value,[],!0),this.lowerContext.clearRect(0,0,this.lowerCanvas.width,this.lowerCanvas.height),this.isUndoRedo=!0,this.redrawImgWithObj(),this.textArea.style.display="block",this.textArea.value=t.currentObj,a=e.extend([],this.undoRedoColl,[],!0),n=this.undoRedoStep,this.redrawActObj(),this.undoRedoColl=a,this.undoRedoStep=n,this.textArea.style.display="none",this.textArea.value="";break;case"brightness":case"contrast":case"hue":case"saturation":case"opacity":case"blur":case"exposure":this.lowerContext.filter=this.canvasFilter=t.currentObj,this.setAdjustment(t.operation);break;case"default":case"chrome":case"cold":case"warm":case"grayscale":case"sepia":case"invert":i&&i.classList.remove("e-selected"),document.getElementById(this.element.id+"_"+t.operation+"Canvas")&&document.getElementById(this.element.id+"_"+t.operation+"Canvas").parentElement.classList.add("e-selected"),this.currentFilter=this.element.id+"_"+t.operation,this.lowerContext.filter=this.canvasFilter=t.currentObj,this.lowerContext.clearRect(0,0,this.lowerCanvas.width,this.lowerCanvas.height),this.redrawImgWithObj()}this.undoRedoStep===this.undoRedoColl.length&&(this.isUndoRedo=!1)}};var c;return r([e.Property("")],l.prototype,"cssClass",void 0),r([e.Property(!1)],l.prototype,"disabled",void 0),r([e.Property("100%")],l.prototype,"height",void 0),r([e.Property("Bootstrap5")],l.prototype,"theme",void 0),r([e.Property()],l.prototype,"toolbar",void 0),r([e.Property()],l.prototype,"toolbarTemplate",void 0),r([e.Property("100%")],l.prototype,"width",void 0),r([e.Property(!1)],l.prototype,"allowUndoRedo",void 0),r([e.Property(!1)],l.prototype,"isReadOnly",void 0),r([e.Property(!1)],l.prototype,"enableRtl",void 0),r([e.Property(!1)],l.prototype,"enablePersistence",void 0),r([e.Complex({},h)],l.prototype,"finetuneSettings",void 0),r([e.Event()],l.prototype,"beforeSave",void 0),r([e.Event()],l.prototype,"created",void 0),r([e.Event()],l.prototype,"destroyed",void 0),r([e.Event()],l.prototype,"zooming",void 0),r([e.Event()],l.prototype,"panning",void 0),r([e.Event()],l.prototype,"cropping",void 0),r([e.Event()],l.prototype,"rotating",void 0),r([e.Event()],l.prototype,"flipping",void 0),r([e.Event()],l.prototype,"shapeChanging",void 0),r([e.Event()],l.prototype,"fileOpened",void 0),r([e.Event()],l.prototype,"saved",void 0),r([e.Event()],l.prototype,"toolbarCreated",void 0),r([e.Event()],l.prototype,"toolbarUpdating",void 0),r([e.Event()],l.prototype,"toolbarItemClicked",void 0),r([e.Event()],l.prototype,"imageFiltering",void 0),r([e.Event()],l.prototype,"finetuneValueChanging",void 0),l=c=r([e.NotifyPropertyChanges],l)}(e.Component);return t.FinetuneSettings=h,t.ImageEditor=l,t}({},ej.base,ej.navigations,ej.splitbuttons,ej.inputs,ej.popups),this.ejs=ej;
10
+ this.ej=this.ej||{},this.ej.imageeditor=function(t,e,i,s,o,a){"use strict";var n=function(){var t=function(e,i){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var i in e)e.hasOwnProperty(i)&&(t[i]=e[i])})(e,i)};return function(e,i){function s(){this.constructor=e}t(e,i),e.prototype=null===i?Object.create(i):(s.prototype=i.prototype,new s)}}(),r=function(t,e,i,s){var o,a=arguments.length,n=a<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(t,e,i,s);else for(var r=t.length-1;r>=0;r--)(o=t[r])&&(n=(a<3?o(n):a>3?o(e,i,n):o(e,i))||n);return a>3&&n&&Object.defineProperty(e,i,n),n},h=function(t){function i(){return null!==t&&t.apply(this,arguments)||this}return n(i,t),r([e.Property(null)],i.prototype,"brightness",void 0),r([e.Property(null)],i.prototype,"contrast",void 0),r([e.Property(null)],i.prototype,"hue",void 0),r([e.Property(null)],i.prototype,"saturation",void 0),r([e.Property(null)],i.prototype,"exposure",void 0),r([e.Property(null)],i.prototype,"opacity",void 0),r([e.Property(null)],i.prototype,"blur",void 0),i}(e.ChildProperty),l=function(t){function l(e,i){var s=t.call(this,e,i)||this;return s.degree=0,s.isUndoRedo=!1,s.dragCanvas=!1,s.dragElement="",s.keyHistory="",s.tempKeyHistory="",s.mouseDownPoint={x:0,y:0},s.previousPoint={x:0,y:0},s.dragPoint={startX:0,startY:0,endX:0,endY:0},s.diffPoint={x:0,y:0},s.oldPoint={},s.objColl=[],s.undoRedoColl=[],s.isImageLoaded=!1,s.strokeSettings={strokeColor:"#fff",fillColor:"",strokeWidth:null},s.tempStrokeSettings={strokeColor:"#fff",fillColor:"",strokeWidth:null},s.textSettings={text:"Enter Text",fontFamily:"Arial",fontSize:null,fontRatio:null,bold:!1,italic:!1,underline:!1},s.tempTextSettings={text:"Enter Text",fontFamily:"Arial",fontSize:null,fontRatio:null,bold:!1,italic:!1,underline:!1},s.toolbarHeight=46,s.togglePan=!1,s.disablePan=!1,s.currFlipState="",s.touchEndPoint={},s.undoRedoStep=0,s.togglePen=!1,s.currentToolbar="main",s.textStartPoints={x:0,y:0},s.fontSizeColl=[],s.textRow=1,s.activeObj={activePoint:{startX:0,startY:0,endX:0,endY:0,width:0,height:0},flipObjColl:[]},s.tempActiveObj={activePoint:{startX:0,startY:0,endX:0,endY:0,width:0,height:0},flipObjColl:[]},s.currObjType={shape:"",isDragging:!1,isActiveObj:!1,isText:!1,isInitialText:!1,isLine:!1,isInitialLine:!1,isCustomCrop:!1,isZoomed:!1,isUndoZoom:!1,isUndoAction:!1,isFiltered:!1,isSave:!1},s.defToolbarItems=[],s.isTimer=!1,s.isFirstMove=!1,s.startTouches=[],s.tempTouches=[],s.adjustmentLevel={brightness:0,contrast:0,hue:0,opacity:100,saturation:0,blur:0,exposure:0,sharpen:!1,bw:!1},s.tempAdjustmentLevel={brightness:0,contrast:0,hue:0,opacity:100,saturation:0,blur:0,exposure:0,sharpen:!1,bw:!1},s.adjustmentValue="",s.initialAdjustmentValue="",s.tempAdjustmentValue="",s.currentFilter="",s.tempFilter="",s.canvasFilter="brightness(1) contrast(100%) hue-rotate(0deg) saturate(100%) opacity(1) blur(0px) sepia(0%) grayscale(0%) invert(0%)",s.tempUndoRedoColl=[],s.tempUndoRedoStep=0,s.zoomFactor=0,s.tempZoomFactor=0,s.destLeft=0,s.destTop=0,s.srcLeft=0,s.srcTop=0,s.cropDestPoints={startX:0,startY:0,width:0,height:0},s.flipColl=[],s.isReverseRotate=!1,s.isReverseFlip=!1,s.isPreventDragging=!1,s.isRotateZoom=!1,s.rotateFlipColl=[],s.isCircleCrop=!1,s.rotatedDestPoints={startX:0,startY:0,width:0,height:0},s.croppedDegree=0,s.isFreehandDrawingPoint=!1,s.isFreehandDrawEditing=!1,s.tempFreeHandDrawEditingStyles={strokeColor:null,fillColor:null,strokeWidth:null},s.totalPannedInternalPoint={x:0,y:0},s.totalPannedClientPoint={x:0,y:0},s.totalPannedPoint={x:0,y:0},s.isCropTab=!1,s.cropZoomFactor=0,s.defaultZoomFactor=0,s.fileName="",s.isBrightnessAdjusted=!1,s.isInitialLoading=!1,s.freehandDrawObj={lastWidth:0,lastVelocity:0,time:0,pointX:0,pointY:0},s.points=[],s.pointColl={},s.pointCounter=0,s.freehandCounter=0,s.isFreehandDrawing=!1,s.tempFreehandCounter=0,s.lastPan={x:0,y:0},s.selectedFreehandColor="#42a5f5",s.isFreehandDrawCustomized=!1,s.isShapeInserted=!1,s.isAllowCropPan=!1,s.tempPannedPoint={x:0,y:0},s.cropObj={cropZoom:0,defaultZoom:0,totalPannedPoint:{x:0,y:0},totalPannedClientPoint:{x:0,y:0},totalPannedInternalPoint:{x:0,y:0},tempFlipPanPoint:{x:0,y:0},activeObj:{},rotateFlipColl:[],degree:0,currFlipState:"",destPoints:{startX:0,startY:0,width:0,height:0},srcPoints:{startX:0,startY:0,width:0,height:0},filter:""},s.afterCropActions=[],s.isCancelAction=!1,s.isFreehandPointMoved=!1,s.isTouch=!1,s.freehandDownPoint={x:0,y:0},s.tempFlipPanPoint={x:0,y:0},s.currentFreehandDrawIndex=0,s.tempCurrentFreehandDrawIndex=0,s.preventZoomBtn=!1,s.cancelObjColl=[],s.cancelPointColl=[],s.rotatedFlipCropSelection=!1,s}n(l,t),c=l,l.prototype.preRender=function(){this.element.id=this.element.id||e.getUniqueID("ej2-image-editor"),e.Browser.isDevice&&this.element.classList.add("e-device"),this.themeColl={Bootstrap5:{primaryColor:"#0d6efd",secondaryColor:"#fff"},Bootstrap5Dark:{primaryColor:"#0d6efd",secondaryColor:"#fff"},Tailwind:{primaryColor:"#4f46e5",secondaryColor:"#fff"},TailwindDark:{primaryColor:"#22d3ee",secondaryColor:"#fff"},Fluent:{primaryColor:"#0078d4",secondaryColor:"#fff"},FluentDark:{primaryColor:"#0078d4",secondaryColor:"#fff"},Bootstrap4:{primaryColor:"#007bff",secondaryColor:"#fff"},Bootstrap:{primaryColor:"#317ab9",secondaryColor:"#fff"},BootstrapDark:{primaryColor:"#317ab9",secondaryColor:"#fff"},Material:{primaryColor:"#e3165b",secondaryColor:"#fff"},MaterialDark:{primaryColor:"#00b0ff",secondaryColor:"#fff"},Fabric:{primaryColor:"#0078d6",secondaryColor:"#fff"},FabricDark:{primaryColor:"#0074cc",secondaryColor:"#fff"},Highcontrast:{primaryColor:"#000000",secondaryColor:"#fff"}},this.defaultLocale={Crop:"Crop",ZoomIn:"Zoom In",ZoomOut:"Zoom Out",Undo:"Undo",Redo:"Redo",Transform:"Transform",Annotation:"Annotation",Finetune:"Finetune",Brightness:"Brightness",Contrast:"Contrast",Hue:"Hue",Saturation:"Saturation",Opacity:"Opacity",Blur:"Blur",Sharpen:"Sharpen",Exposure:"Exposure",Filter:"Filter",Default:"Default",Chrome:"Chrome",Cold:"Cold",Warm:"Warm",Grayscale:"Grayscale",BlackAndWhite:"Black and White",Sepia:"Sepia",Invert:"Invert",Text:"Add Text",Pen:"Pen",Reset:"Reset",Save:"Save",Select:"Select",RotateLeft:"Rotate Left",RotateRight:"Rotate Right",HorizontalFlip:"Horizontal Flip",VerticalFlip:"Vertical Flip",OK:"OK",Cancel:"Cancel",FillColor:"Fill Color",StrokeColor:"Stroke Color",StrokeWidth:"Stroke Width",FontFamily:"Font Family",FontStyle:"Font Style",FontSize:"Font Size",FontColor:"Font Color",Pan:"Pan",Move:"Move",Load:"Load",Custom:"Custom",Square:"Square",Circle:"Circle",Ellipse:"Ellipse",Rectangle:"Rectangle",Line:"Line",Bold:"Bold",Italic:"Italic",BoldItalic:"Bold Italic",XSmall:"X-Small",Small:"Small",Medium:"Medium",Large:"Large",XLarge:"X-Large",ABC:"ABC",Browse:"Browse"},this.l10n=new e.L10n("image-editor",this.defaultLocale,this.locale)},l.prototype.render=function(){this.initialize()},l.prototype.getModuleName=function(){return"image-editor"},l.prototype.getPersistData=function(){return this.addOnPersist([])},l.prototype.onPropertyChanged=function(t,i){for(var s=0,o=Object.keys(t);s<o.length;s++)switch(o[s]){case"cssClass":i.cssClass&&e.removeClass([this.element],i.cssClass.replace(/\s+/g," ").trim().split(" ")),t.cssClass&&e.addClass([this.element],t.cssClass.replace(/\s+/g," ").trim().split(" "));break;case"disabled":t.disabled?(this.element.classList.add("e-disabled"),this.unwireEvent()):(this.element.classList.remove("e-disabled"),this.wireEvent());break;case"height":this.element.style.height=t.height;break;case"width":this.element.style.width=t.width;break;case"theme":t.theme&&(this.updateTheme(),this.upperContext.strokeStyle=this.themeColl[this.theme].primaryColor,this.upperContext.fillStyle=this.themeColl[this.theme].secondaryColor);break;case"finetuneSettings":t.finetuneSettings&&(this.finetuneSettings=t.finetuneSettings,this.updateFinetunes());break;case"locale":t.locale&&(this.l10n.setLocale(t.locale),this.refreshToolbar("main"));break;case"allowUndoRedo":t.allowUndoRedo?this.allowUndoRedo=!0:this.allowUndoRedo=!1,this.refreshToolbar("main")}},l.prototype.destroy=function(){var i=[];this.element.removeAttribute("tabindex"),this.cssClass&&(i=i.concat(this.cssClass.replace(/\s+/g," ").trim().split(" "))),e.removeClass([this.element],i),this.element.getAttribute("class")||this.element.removeAttribute("class"),this.destroySubComponents(),this.unwireEvent(),t.prototype.destroy.call(this),this.element.innerHTML=""},l.prototype.initialize=function(){this.updateFinetunes(),this.createToolbar(),this.createContextualToolbar(),this.createCanvas(),this.wireEvent(),this.lowerContext.filter=this.canvasFilter=this.initialAdjustmentValue=this.adjustmentValue=this.getDefaultFilter(),this.cssClass&&e.addClass([this.element],this.cssClass.replace(/\s+/g," ").trim().split(" ")),this.element&&a.createSpinner({target:this.element})},l.prototype.getDefaultFilter=function(){return"brightness(1) contrast(100%) hue-rotate(0deg) saturate(100%) opacity(1) blur(0px) sepia(0%) grayscale(0%) invert(0%)"},l.prototype.updateFinetunes=function(){this.finetuneSettings&&(this.finetuneSettings.brightness&&(this.adjustmentLevel.brightness=this.finetuneSettings.brightness.defaultValue,this.tempAdjustmentLevel.brightness=this.finetuneSettings.brightness.defaultValue),this.finetuneSettings.contrast&&(this.adjustmentLevel.contrast=this.finetuneSettings.contrast.defaultValue,this.tempAdjustmentLevel.contrast=this.finetuneSettings.contrast.defaultValue),this.finetuneSettings.hue&&(this.adjustmentLevel.hue=this.finetuneSettings.hue.defaultValue,this.tempAdjustmentLevel.hue=this.finetuneSettings.hue.defaultValue),this.finetuneSettings.saturation&&(this.adjustmentLevel.saturation=this.finetuneSettings.saturation.defaultValue,this.tempAdjustmentLevel.saturation=this.finetuneSettings.saturation.defaultValue),this.finetuneSettings.exposure&&(this.adjustmentLevel.exposure=this.finetuneSettings.exposure.defaultValue,this.tempAdjustmentLevel.exposure=this.finetuneSettings.exposure.defaultValue),this.finetuneSettings.opacity&&(this.adjustmentLevel.opacity=this.finetuneSettings.opacity.defaultValue,this.tempAdjustmentLevel.opacity=this.finetuneSettings.opacity.defaultValue),this.finetuneSettings.blur&&(this.adjustmentLevel.blur=this.finetuneSettings.blur.defaultValue,this.tempAdjustmentLevel.blur=this.finetuneSettings.blur.defaultValue),this.isInitialLoading=!0)},l.prototype.initializeFilter=function(){this.setBrightness(this.adjustmentLevel.brightness),this.setContrast(this.adjustmentLevel.contrast),this.setHue(this.adjustmentLevel.hue),this.setSaturation(this.adjustmentLevel.saturation),this.setExposure(this.adjustmentLevel.exposure),this.setOpacity(this.adjustmentLevel.opacity),this.setBlur(this.adjustmentLevel.blur)},l.prototype.wireEvent=function(){e.EventHandler.add(document,"keydown",this.keyDownEventHandler,this),e.EventHandler.add(document,"keypress",this.keyUpEventHandler,this),e.EventHandler.add(this.upperCanvas,"mousedown",this.mouseDownEventHandler,this),e.EventHandler.add(this.upperCanvas,"mousemove",this.mouseMoveEventHandler,this),e.EventHandler.add(this.upperCanvas,"mouseup",this.mouseUpEventHandler,this),e.EventHandler.add(document,"mouseup",this.mouseUpEventHandler,this),e.EventHandler.add(this.lowerCanvas,"mousedown",this.canvasMouseDownHandler,this),e.EventHandler.add(this.lowerCanvas,"mousemove",this.canvasMouseMoveHandler,this),e.EventHandler.add(this.lowerCanvas,"mouseup",this.canvasMouseUpHandler,this),e.EventHandler.add(document,"mouseup",this.canvasMouseUpHandler,this),e.EventHandler.add(this.upperCanvas,"touchstart",this.touchStartHandler,this),e.EventHandler.add(this.lowerCanvas,"touchstart",this.touchStartHandler,this),e.EventHandler.add(this.upperCanvas,"dblclick",this.findTextPoint,this),e.EventHandler.add(this.textArea,"mousedown",this.findTextPoint,this),e.EventHandler.add(this.lowerCanvas,"mousewheel DOMMouseScroll",this.handleScroll,this),e.EventHandler.add(this.upperCanvas,"mousewheel DOMMouseScroll",this.handleScroll,this),window.addEventListener("resize",this.windowResizeHandler.bind(this)),e.Browser.isIos||"safari"===e.Browser.info.name||screen.orientation.addEventListener("change",this.screenOrientation.bind(this))},l.prototype.unwireEvent=function(){e.EventHandler.remove(document,"keydown",this.keyDownEventHandler),e.EventHandler.remove(document,"keypress",this.keyUpEventHandler),e.EventHandler.remove(this.upperCanvas,"mousedown",this.mouseDownEventHandler),e.EventHandler.remove(this.upperCanvas,"mousemove",this.mouseMoveEventHandler),e.EventHandler.remove(this.upperCanvas,"mouseup",this.mouseUpEventHandler),e.EventHandler.remove(document,"mouseup",this.mouseUpEventHandler),e.EventHandler.remove(this.lowerCanvas,"mousedown",this.canvasMouseDownHandler),e.EventHandler.remove(this.lowerCanvas,"mousemove",this.canvasMouseMoveHandler),e.EventHandler.remove(this.lowerCanvas,"mouseup",this.canvasMouseUpHandler),e.EventHandler.remove(document,"mouseup",this.canvasMouseUpHandler)},l.prototype.destroySubComponents=function(){for(var t=this.element.querySelectorAll("input.e-control"),i=this.element.querySelectorAll("button.e-control"),s=0,o=t.length;s<o;s++)t[s].classList.contains("e-color-picker")&&(e.getComponent(t[s],"color-picker").destroy(),e.detach(e.select("input#"+t[s].id,this.element)));for(var s=0,o=i.length;s<o;s++)i[s].classList.contains("e-dropdown-btn")?(e.getComponent(i[s],"dropdown-btn").destroy(),e.detach(e.select("button#"+i[s].id,this.element))):i[s].classList.contains("e-btn")&&(e.getComponent(i[s],"btn").destroy(),e.detach(e.select("button#"+i[s].id,this.element)))},l.prototype.updateTheme=function(){""!==this.theme&&(this.theme=this.toPascalCase(this.theme))},l.prototype.toPascalCase=function(t){var i=[];e.isNullOrUndefined(t)||(i=t.toLowerCase().split("-"));for(var s=0;s<i.length;s++)i[s]=i[s].charAt(0).toUpperCase()+i[s].slice(1);return i.join("")},l.prototype.createCanvas=function(){this.element.style.boxSizing="border-box";var t=this.toolbarHeight;this.element.style.width=this.width,this.element.style.height=this.height;var e=this.element.appendChild(this.createElement("div",{id:this.element.id+"_canvasWrapper",className:"e-canvas-wrapper",attrs:{style:"height:"+(this.element.offsetHeight-t-2)+"px; width:"+(this.element.offsetWidth-2)+"px; position: relative; overflow: hidden; margin: 0 auto;"}}));this.lowerCanvas=e.appendChild(this.createElement("canvas",{id:this.element.id+"_lowerCanvas",attrs:{name:"canvasImage"}})),this.upperCanvas=e.appendChild(this.createElement("canvas",{id:this.element.id+"_upperCanvas",attrs:{name:"canvasImage"}})),this.inMemoryCanvas=this.createElement("canvas",{id:this.element.id+"_inMemoryCanvas",attrs:{name:"canvasImage"}}),this.textArea=e.appendChild(this.createElement("textarea",{id:this.element.id+"_textArea",className:"e-textarea",attrs:{name:"textArea"}})),this.textArea.setAttribute("spellcheck","false"),this.lowerCanvas.style.width=this.upperCanvas.style.width=this.inMemoryCanvas.style.width="100%",this.lowerCanvas.style.height=this.upperCanvas.style.height=this.inMemoryCanvas.style.height="100%",this.upperCanvas.style.position=this.lowerCanvas.style.position=this.textArea.style.position="absolute",this.textArea.style.backgroundColor="transparent",this.textArea.style.display="none",this.textArea.style.resize="none",this.lowerContext=this.lowerCanvas.getContext("2d"),this.baseImg=this.createElement("img",{id:this.element.id+"_orgImg",attrs:{name:"Image",crossorigin:"anonymous"}}),this.upperCanvas.style.cursor="default",this.upperCanvas.style.display="none",this.upperContext=this.upperCanvas.getContext("2d"),this.inMemoryContext=this.inMemoryCanvas.getContext("2d")},l.prototype.createToolbar=function(){var t=this;if(e.isNullOrUndefined(this.toolbar)||!e.isNullOrUndefined(this.toolbar)&&this.toolbar.length>0){if(this.element.appendChild(this.createElement("div",{id:this.element.id+"_toolbarArea",className:"e-toolbar-area"})),this.toolbarTemplate)this.toolbarTemplateFn();else{var s={cssClass:"e-image-upload",align:"Left",type:"Input",tooltipText:this.l10n.getConstant("Browse"),template:new o.Uploader({allowedExtensions:".jpg, .jpeg, .png,.svg"})};e.isNullOrUndefined(this.defToolbarItems)&&(this.defToolbarItems=[]),this.defToolbarItems.push(s);var a=document.getElementById(this.element.id+"_toolbarArea"),n=this.createElement("div",{id:this.element.id+"_toolbar"});a.appendChild(n);var r=[{cssClass:"e-image-upload",align:"Left",type:"Input",tooltipText:this.l10n.getConstant("Browse"),template:new o.Uploader({allowedExtensions:".jpg, .jpeg, .png,.svg",selected:function(){e.Browser.isDevice?(t.defToolbarItems.length>0&&!e.isNullOrUndefined(document.getElementById(t.element.id+"_toolbar"))&&e.getComponent(document.getElementById(t.element.id+"_toolbar"),"toolbar").destroy(),e.isNullOrUndefined(document.getElementById(t.element.id+"_bottomToolbar"))||e.getComponent(document.getElementById(t.element.id+"_bottomToolbar"),"toolbar").destroy(),t.initToolbarItem(!1,e.Browser.isDevice,null),t.createBottomToolbar()):(t.defToolbarItems.length>0&&!e.isNullOrUndefined(document.getElementById(t.element.id+"_toolbar"))&&e.getComponent(document.getElementById(t.element.id+"_toolbar"),"toolbar").destroy(),t.initToolbarItem(!1,!1,null))}})}];new i.Toolbar({items:r,width:"100%",created:function(){t.trigger("toolbarCreated",{toolbarType:"main"})},clicked:this.defToolbarClicked.bind(this)},"#"+this.element.id+"_toolbar"),this.createLeftToolbarControls()}e.isNullOrUndefined(document.getElementById(this.element.id+"_toolbar"))||(this.toolbarHeight=document.getElementById(this.element.id+"_toolbar").clientHeight)}else this.toolbarHeight=0},l.prototype.createContextualToolbar=function(){if(e.isNullOrUndefined(this.toolbar)||!e.isNullOrUndefined(this.toolbar)&&this.toolbar.length>0){this.element.appendChild(this.createElement("div",{id:this.element.id+"_contextualToolbarArea",className:"e-contextual-toolbar-wrapper e-hide",attrs:{style:"position: absolute;"}}));var t=document.getElementById(this.element.id+"_contextualToolbarArea"),i=this.createElement("div",{id:this.element.id+"_contextualToolbar"});t.appendChild(i)}},l.prototype.updateContextualToolbar=function(t,i){if(this.toolbarTemplate)this.toolbarTemplateFn();else{var s=this.element.querySelector("#"+this.element.id+"_toolbarArea"),o=this.element.querySelector("#"+this.element.id+"_contextualToolbarArea");if(o.classList.remove("e-hide"),o.style.left=s.offsetLeft+"px","filter"===t?(document.getElementById(this.element.id+"_toolbar")&&this.defToolbarItems.length>0&&e.getComponent(document.getElementById(this.element.id+"_toolbar"),"toolbar").destroy(),e.Browser.isDevice?this.initToolbarItem(!1,!0,!0):this.initToolbarItem(!0,null,null),this.refreshSlider(),this.initFilterToolbarItem()):(document.querySelector("#"+this.element.id+"_contextualToolbar").classList.contains("e-control")&&e.getComponent(document.getElementById(this.element.id+"_contextualToolbar"),"toolbar").destroy(),this.refreshSlider(),this.renderSlider(i)),e.Browser.isDevice){var a=o.offsetHeight,n=this.element.querySelector("#"+this.element.id+"_canvasWrapper").offsetHeight;o.style.top=this.toolbarHeight+n-a+"px"}else o.style.top=this.toolbarHeight+"px"}},l.prototype.createBottomToolbar=function(){if(e.isNullOrUndefined(this.toolbar)||!e.isNullOrUndefined(this.toolbar)&&this.toolbar.length>0){if(this.element.appendChild(this.createElement("div",{id:this.element.id+"_bottomToolbarArea",className:"e-bottom-toolbar"})),!this.toolbarTemplate){document.getElementById(this.element.id+"_canvasWrapper").style.height=this.element.offsetHeight-2*this.toolbarHeight-3+"px";var t=document.getElementById(this.element.id+"_bottomToolbarArea"),i=this.createElement("div",{id:this.element.id+"_bottomToolbar"});t.appendChild(i)}this.initBottomToolbar()}},l.prototype.initBottomToolbar=function(){var t=this;if(e.isNullOrUndefined(this.toolbar)||!e.isNullOrUndefined(this.toolbar)&&this.toolbar.length>0)if(this.toolbarTemplate)this.toolbarTemplateFn();else{var s=this.getMainToolbarItem();new i.Toolbar({items:s,width:"100%",created:function(){t.renderAnnotationBtn(),t.renderCropBtn(),t.renderTransformBtn(),t.trigger("toolbarCreated",{toolbarType:"main"})},clicked:this.defToolbarClicked.bind(this)},"#"+this.element.id+"_bottomToolbar"),this.defToolbarItems.length>0&&!e.isNullOrUndefined(document.getElementById(this.element.id+"_bottomToolbar"))&&e.getComponent(this.element.id+"_bottomToolbar","toolbar").refreshOverflow()}},l.prototype.toolbarTemplateFn=function(){var t,e=this.element.id+"_toolbar",i=this.element.querySelector("#"+this.element.id+"_toolbarArea");if(this.toolbarTemplate){if(this.toolbarFn=this.templateParser(this.toolbarTemplate),this.isReact)t=this.toolbarFn({type:"toolbar"},this,"Template",e)[0];else if(this.isAngular){var s=this.toolbarFn({type:"toolbar"},this,"Template",e);t=3===s[0].nodeType?s[1]:s[0]}else t=this.toolbarFn({type:"toolbar"},this,"Template",e)[0];i.appendChild(t),this.renderReactTemplates()}},l.prototype.templateParser=function(t){if(t)try{return document.querySelectorAll(t).length?e.compile(document.querySelector(t).innerHTML.trim()):e.compile(t)}catch(i){return e.compile(t)}},l.prototype.getLeftToolbarItem=function(t){var i=[];t||(i.push({cssClass:"e-image-upload",align:"Left",type:"Input",template:new o.Uploader({allowedExtensions:".jpg, .jpeg, .png,.svg"})}),i.push({visible:!1,cssClass:"e-image-position e-btn e-flat",tooltipText:this.l10n.getConstant("Browse"),align:"Left"})),this.allowUndoRedo&&((e.isNullOrUndefined(this.toolbar)||!e.isNullOrUndefined(this.toolbar)&&this.toolbar.indexOf("Undo")>-1)&&i.push({id:this.element.id+"_undo",prefixIcon:"e-icons e-undo",cssClass:"top-icon e-undo",tooltipText:this.l10n.getConstant("Undo"),align:"Left"}),(e.isNullOrUndefined(this.toolbar)||!e.isNullOrUndefined(this.toolbar)&&this.toolbar.indexOf("Redo")>-1)&&i.push({id:this.element.id+"_redo",prefixIcon:"e-icons e-redo",cssClass:"top-icon e-redo",tooltipText:this.l10n.getConstant("Redo"),align:"Left"})),this.preventZoomBtn||((e.isNullOrUndefined(this.toolbar)||!e.isNullOrUndefined(this.toolbar)&&this.toolbar.indexOf("ZoomOut")>-1)&&i.push({id:this.element.id+"_zoomOut",prefixIcon:"e-icons e-zoom-out",cssClass:"top-icon e-dec-zoom",tooltipText:this.l10n.getConstant("ZoomOut"),align:"Left"}),(e.isNullOrUndefined(this.toolbar)||!e.isNullOrUndefined(this.toolbar)&&this.toolbar.indexOf("ZoomIn")>-1)&&i.push({id:this.element.id+"_zoomIn",prefixIcon:"e-icons e-zoom-in",cssClass:"top-icon e-inc-zoom",tooltipText:this.l10n.getConstant("ZoomIn"),align:"Left"}));for(var s=this.processToolbar("left"),a=0,n=s.length;a<n;a++)i.push(s[a]);return i},l.prototype.getRightToolbarItem=function(t){var i=[];t&&(i.push({id:this.element.id+"_ok",prefixIcon:"e-icons e-check",cssClass:"top-icon e-tick",tooltipText:this.l10n.getConstant("OK"),align:"Right"}),i.push({id:this.element.id+"_cancel",prefixIcon:"e-icons e-close",cssClass:"top-icon e-save",tooltipText:this.l10n.getConstant("Cancel"),align:"Right"})),(e.isNullOrUndefined(this.toolbar)||!e.isNullOrUndefined(this.toolbar)&&this.toolbar.indexOf("Reset")>-1)&&i.push({id:this.element.id+"_reset",prefixIcon:"e-icons e-btn-reset",cssClass:"top-icon e-img-reset",tooltipText:this.l10n.getConstant("Reset"),align:"Right"}),t||(e.isNullOrUndefined(this.toolbar)||!e.isNullOrUndefined(this.toolbar)&&this.toolbar.indexOf("Save")>-1)&&i.push({id:this.element.id+"_save",prefixIcon:"e-icons e-btn-save",cssClass:"top-icon e-save",tooltipText:this.l10n.getConstant("Save"),align:"Right",template:'<button id="'+this.element.id+'_saveBtn"></button>'});for(var s=this.processToolbar("right"),o=0,a=s.length;o<a;o++)i.push(s[o]);return i},l.prototype.getMainToolbarItem=function(t){var i=[];(e.isNullOrUndefined(this.toolbar)||!e.isNullOrUndefined(this.toolbar)&&this.toolbar.indexOf("Crop")>-1)&&i.push({id:this.element.id+"_crop",tooltipText:this.l10n.getConstant("Crop"),align:"Center",template:'<button id="'+this.element.id+'_cropBtn"></button>'}),(e.isNullOrUndefined(this.toolbar)||!e.isNullOrUndefined(this.toolbar)&&this.toolbar.indexOf("Annotate")>-1)&&i.push({id:this.element.id+"_annotation",tooltipText:this.l10n.getConstant("Annotation"),align:"Center",template:'<button id="'+this.element.id+'_annotationBtn"></button>'}),(e.isNullOrUndefined(this.toolbar)||!e.isNullOrUndefined(this.toolbar)&&this.toolbar.indexOf("Transform")>-1)&&i.push({id:this.element.id+"_transform",tooltipText:this.l10n.getConstant("Transform"),align:"Center",template:'<button id="'+this.element.id+'_transformBtn"></button>'}),(e.isNullOrUndefined(this.toolbar)||!e.isNullOrUndefined(this.toolbar)&&this.toolbar.indexOf("Finetune")>-1)&&i.push({id:this.element.id+"_adjustment",prefixIcon:"e-icons e-adjustment",cssClass:"top-icon e-adjustment",tooltipText:this.l10n.getConstant("Finetune"),align:"Center"}),(e.isNullOrUndefined(this.toolbar)||!e.isNullOrUndefined(this.toolbar)&&this.toolbar.indexOf("Filter")>-1)&&i.push({id:this.element.id+"_filter",prefixIcon:"e-icons e-filters",cssClass:"top-icon e-filters",tooltipText:this.l10n.getConstant("Filter"),align:"Center"});for(var s=this.processToolbar("center"),o=0,a=s.length;o<a;o++)i.push(s[o]);return t&&(i.push({id:this.element.id+"_ok",prefixIcon:"e-icons e-check",cssClass:"top-icon e-tick",tooltipText:this.l10n.getConstant("OK"),align:"Right"}),i.push({id:this.element.id+"_cancel",prefixIcon:"e-icons e-close",cssClass:"top-icon e-save",tooltipText:this.l10n.getConstant("Cancel"),align:"Right"})),i},l.prototype.getZoomToolbarItem=function(){return[]},l.prototype.processToolbar=function(t){var i=[];if(this.toolbar)for(var s=0,o=this.toolbar.length;s<o;s++)"object"==typeof this.toolbar[s]&&(e.isNullOrUndefined(this.toolbar[s].align)?"left"===t&&i.push(this.toolbar[s]):this.toolbar[s].align.toLowerCase()===t&&i.push(this.toolbar[s]));return i},l.prototype.processSubToolbar=function(t){var e=[];if(t)for(var i=0,s=t.length;i<s;i++)"object"==typeof t[i]&&(t[i].align="Center",e.push(t[i]));return e},l.prototype.isToolbar=function(){return e.isNullOrUndefined(this.toolbar)||!e.isNullOrUndefined(this.toolbar)&&this.toolbar.length>0||!e.isNullOrUndefined(this.toolbarTemplate)},l.prototype.initToolbarItem=function(t,s,o){var a=this;if(this.isToolbar()){var n=this.getLeftToolbarItem(o),r=this.getRightToolbarItem(o),h=this.getMainToolbarItem(t),l=this.getZoomToolbarItem();this.defToolbarItems=s?n.concat(r):n.concat(h,r,l),new i.Toolbar({width:"100%",items:this.defToolbarItems,clicked:this.defToolbarClicked.bind(this),created:function(){s||(a.renderAnnotationBtn(),a.renderCropBtn(),a.renderTransformBtn()),a.renderSaveBtn(),a.trigger("toolbarCreated",{toolbarType:"main"})}},"#"+this.element.id+"_toolbar"),this.createLeftToolbarControls(),this.enableDisableToolbarBtn(),this.isToolbar()&&!e.isNullOrUndefined(document.getElementById(this.element.id+"_toolbar"))&&e.getComponent(this.element.id+"_toolbar","toolbar").refreshOverflow()}},l.prototype.enableDisableToolbarBtn=function(){var t=document.querySelector("#"+this.element.id+"_undo");e.isNullOrUndefined(t)||0!==this.undoRedoStep?e.isNullOrUndefined(t)||(t.classList.remove("e-disabled"),t.parentElement.classList.remove("e-overlay")):(t.classList.add("e-disabled"),t.parentElement.classList.add("e-overlay"));var i=document.querySelector("#"+this.element.id+"_redo");e.isNullOrUndefined(i)||this.undoRedoStep!==this.undoRedoColl.length?!e.isNullOrUndefined(i)&&0===this.undoRedoStep&&this.undoRedoColl.length>0?(i.classList.remove("e-disabled"),i.parentElement.classList.remove("e-overlay")):e.isNullOrUndefined(i)||(i.classList.remove("e-disabled"),i.parentElement.classList.remove("e-overlay")):(i.classList.add("e-disabled"),i.parentElement.classList.add("e-overlay"));var s=document.querySelector("#"+this.element.id+"_zoomIn");!e.isNullOrUndefined(s)&&this.zoomFactor>=2?(s.classList.add("e-disabled"),s.parentElement.classList.add("e-overlay")):e.isNullOrUndefined(s)||(s.classList.remove("e-disabled"),s.parentElement.classList.remove("e-overlay"));var o=document.querySelector("#"+this.element.id+"_zoomOut");e.isNullOrUndefined(o)||0!==this.zoomFactor?e.isNullOrUndefined(o)||(o.classList.remove("e-disabled"),o.parentElement.classList.remove("e-overlay")):(o.classList.add("e-disabled"),o.parentElement.classList.add("e-overlay"));var a=document.querySelector("#"+this.element.id+"_pan");e.isNullOrUndefined(a)||0!==this.zoomFactor?e.isNullOrUndefined(a)||(a.style.display="block"):a.style.display="none"},l.prototype.createLeftToolbarControls=function(){if(void 0!==this.defToolbarItems&&this.defToolbarItems.length>0&&!e.isNullOrUndefined(document.getElementById(this.element.id+"_toolbar"))){var t=document.getElementById(this.element.id+"_toolbar").querySelector(".e-image-upload");if(t){var i=t.getElementsByTagName("input")[0],s=t.getElementsByTagName("button")[0];s.className="e-tbar-btn e-tbtn-txt e-btn top-icon",s.innerHTML="",s.appendChild(this.createElement("span",{className:"e-btn-icon e-icons e-upload-icon e-icon-left"})),i.onchange=this.fileSelect.bind(this,i)}}},l.prototype.cropSelectedState=function(){e.isNullOrUndefined(this.activeObj.shape)||"crop"!==this.activeObj.shape.split("-")[0]||this.okBtn()},l.prototype.renderAnnotationBtn=function(){var t=this,i=this,o=[];(e.isNullOrUndefined(this.toolbar)||!e.isNullOrUndefined(this.toolbar)&&this.toolbar.indexOf("Pen")>-1)&&o.push({text:this.l10n.getConstant("Pen"),id:"pen",iconCss:"e-icons e-free-pen"}),(e.isNullOrUndefined(this.toolbar)||!e.isNullOrUndefined(this.toolbar)&&this.toolbar.indexOf("Line")>-1)&&o.push({text:this.l10n.getConstant("Line"),id:"line",iconCss:"e-icons e-line"}),(e.isNullOrUndefined(this.toolbar)||!e.isNullOrUndefined(this.toolbar)&&this.toolbar.indexOf("Rectangle")>-1)&&o.push({text:this.l10n.getConstant("Rectangle"),id:"rectangle",iconCss:"e-icons e-rectangle"}),(e.isNullOrUndefined(this.toolbar)||!e.isNullOrUndefined(this.toolbar)&&this.toolbar.indexOf("Ellipse")>-1)&&o.push({text:this.l10n.getConstant("Ellipse"),id:"ellipse",iconCss:"e-icons e-circle"}),(e.isNullOrUndefined(this.toolbar)||!e.isNullOrUndefined(this.toolbar)&&this.toolbar.indexOf("Text")>-1)&&o.push({text:this.l10n.getConstant("Text"),id:"text",iconCss:"e-icons e-add-text"});var a=new s.DropDownButton({items:o,iconCss:"e-icons e-annotation",cssClass:"e-image-popup",open:function(i){t.currObjType.isUndoAction&&t.refreshUndoRedoColl(),e.Browser.isDevice&&(i.element.parentElement.style.top=a.element.getBoundingClientRect().top-i.element.parentElement.offsetHeight+"px")},select:function(e){t.cropSelectedState();var s,o=!1;switch(void 0!==t.activeObj.shape&&(s=t.activeObj.shape.split("-")),void 0===s&&t.currObjType.isCustomCrop?o=!0:void 0!==s&&"crop"===s[0]&&(o=!0),t.currObjType.isCustomCrop=!1,(o||t.togglePan)&&(t.refreshActiveObj(),t.upperContext.clearRect(0,0,t.upperCanvas.width,t.upperCanvas.height),t.refreshToolbar("main")),e.item.id){case"pen":i.tempFreehandCounter=i.freehandCounter,i.tempCurrentFreehandDrawIndex=i.currentFreehandDrawIndex,i.currentToolbar="pen",t.freeHandDraw(!0);break;case"text":i.currentToolbar="text",t.drawShapeText();break;default:i.currentToolbar="shapes",i.drawShape(e.item.id.toLowerCase())}t.updateToolbarItems()}});a.appendTo("#"+this.element.id+"_annotationBtn")},l.prototype.renderCropBtn=function(){var t=this,i=[];(e.isNullOrUndefined(this.toolbar)||!e.isNullOrUndefined(this.toolbar)&&this.toolbar.indexOf("CustomSelection")>-1)&&i.push({text:this.l10n.getConstant("Custom"),id:"custom",iconCss:"e-icons e-custom"}),(e.isNullOrUndefined(this.toolbar)||!e.isNullOrUndefined(this.toolbar)&&this.toolbar.indexOf("CircleSelection")>-1)&&i.push({text:this.l10n.getConstant("Circle"),id:"circle",iconCss:"e-icons e-circle"}),(e.isNullOrUndefined(this.toolbar)||!e.isNullOrUndefined(this.toolbar)&&this.toolbar.indexOf("SquareSelection")>-1)&&i.push({text:this.l10n.getConstant("Square"),id:"square",iconCss:"e-icons e-square"}),(e.isNullOrUndefined(this.toolbar)||!e.isNullOrUndefined(this.toolbar)&&this.toolbar.indexOf("RatioSelection")>-1)&&(i.push({text:"3:2",id:"3:2",iconCss:"e-icons e-custom-a"}),i.push({text:"4:3",id:"4:3",iconCss:"e-icons e-custom-b"}),i.push({text:"5:4",id:"5:4",iconCss:"e-icons e-custom-c"}),i.push({text:"7:5",id:"7:5",iconCss:"e-icons e-custom-d"}),i.push({text:"16:9",id:"16:9",iconCss:"e-icons e-custom-e"}));var o=new s.DropDownButton({open:function(i){t.currObjType.isUndoAction&&t.refreshUndoRedoColl(),t.togglePan&&t.cancelPan(),e.Browser.isDevice&&(i.element.parentElement.style.top=o.element.getBoundingClientRect().top-i.element.parentElement.offsetHeight+"px"),!e.isNullOrUndefined(t.activeObj.shape)&&t.activeObj.shape.split("-").length>1&&document.getElementById(t.activeObj.shape.split("-")[1]).classList.add("e-selected")},items:i,select:this.cropSelect.bind(this),iconCss:"e-icons e-select",cssClass:"e-image-popup"});o.appendTo("#"+this.element.id+"_cropBtn")},l.prototype.renderTransformBtn=function(){var t=this,i=[];(e.isNullOrUndefined(this.toolbar)||!e.isNullOrUndefined(this.toolbar)&&this.toolbar.indexOf("RotateLeft")>-1)&&i.push({text:this.l10n.getConstant("RotateLeft"),id:"rotateleft",iconCss:"e-icons e-anti-clock-wise"}),(e.isNullOrUndefined(this.toolbar)||!e.isNullOrUndefined(this.toolbar)&&this.toolbar.indexOf("RotateRight")>-1)&&i.push({text:this.l10n.getConstant("RotateRight"),id:"rotateright",iconCss:"e-icons e-clock-wise"}),(e.isNullOrUndefined(this.toolbar)||!e.isNullOrUndefined(this.toolbar)&&this.toolbar.indexOf("FlipHorizontal")>-1)&&i.push({text:this.l10n.getConstant("HorizontalFlip"),id:"horizontalflip",iconCss:"e-icons e-horizontal-flip"}),(e.isNullOrUndefined(this.toolbar)||!e.isNullOrUndefined(this.toolbar)&&this.toolbar.indexOf("FlipVertical")>-1)&&i.push({text:this.l10n.getConstant("VerticalFlip"),id:"verticalflip",iconCss:"e-icons e-vertical-flip"});var o=new s.DropDownButton({open:function(i){if(t.currObjType.isUndoAction&&t.refreshUndoRedoColl(),e.Browser.isDevice){var s=i.element.parentElement.offsetHeight;i.element.parentElement.style.display="none",i.element.parentElement.style.top=o.element.getBoundingClientRect().top-s+"px",i.element.parentElement.style.display="block"}},items:i,select:this.transformSelect.bind(this),iconCss:"e-icons e-transform",cssClass:"e-image-popup"});o.appendTo("#"+this.element.id+"_transformBtn")},l.prototype.renderSaveBtn=function(){var t=e.getInstance(document.getElementById(this.element.id),c),i=[{text:"JPEG",id:"jpeg"},{text:"PNG",id:"png"},{text:"SVG",id:"svg"}];document.getElementById(this.element.id+"_saveBtn")&&new s.DropDownButton({items:i,cssClass:"e-caret-hide e-image-popup",iconCss:"e-icons e-save",select:function(e){t.export(e.item.text)}}).appendTo("#"+this.element.id+"_saveBtn")},l.prototype.cropSelect=function(t){this.isCropTab=!0,this.zoomFactor=this.cropZoomFactor;var i=e.extend({},this.cropObj,{},!0),s=this.getCurrentObj();s.objColl=e.extend([],this.objColl,[],!0),s.pointColl=e.extend([],this.pointColl,[],!0),s.afterCropActions=this.afterCropActions;var o=t.item.id;this.currentToolbar="crop",this.currSelectionPoint=null,this.select(o),this.refreshToolbar("main",!0,!0),this.refreshDropDownBtn(!0),this.updateUndoRedoColl("selectionTransform",s,s.objColl,s.pointColl,i),this.enableDisableToolbarBtn()},l.prototype.transformSelect=function(t){this.cropSelectedState(),this.currentSelectionPoint=null,this.performTransformation(t.item.id)},l.prototype.performTransformation=function(t){var i=this.defaultZoomFactor,s=this.isUndoRedo,o=e.extend({},this.cropObj,{},!0);if(0!==this.defaultZoomFactor&&(this.transformCurrentObj=this.getCurrentObj(),this.transformCurrentObj.objColl=e.extend([],this.objColl,null,!0),this.transformCurrentObj.pointColl=e.extend({},this.pointColl,null,!0),this.transformCurrentObj.afterCropActions=e.extend([],this.afterCropActions,[],!0),this.isUndoRedo=!0,this.defaultZoomFactor>0?this.zoom(-this.defaultZoomFactor):this.zoom(Math.abs(this.defaultZoomFactor)),this.isUndoRedo=s),this.updateTransform(t),0!==i){this.isUndoRedo=!0,this.zoom(i),this.isUndoRedo=s;var a="";"rotateleft"===t||"rotateright"===t?a="rotate":"horizontalflip"!==t&&"verticalflip"!==t||(a="flip"),this.updateUndoRedoColl(a,this.transformCurrentObj,this.transformCurrentObj.objColl,this.transformCurrentObj.pointColl,o),this.transformCurrentObj=null}},l.prototype.updateTransform=function(t){switch(t.toLowerCase()){case"rotateleft":this.rotate(-90);break;case"rotateright":this.rotate(90);break;case"horizontalflip":this.flip("Horizontal");break;case"verticalflip":this.flip("Vertical")}},l.prototype.getShapesToolbarItem=function(t){var i=[];t.indexOf("fillColor")>-1&&i.push({prefixIcon:"e-icons e-copy",id:this.element.id+"_fillcolor",cssClass:"top-icon e-fill",tooltipText:this.l10n.getConstant("FillColor"),align:"Center",type:"Input",template:'<button id="'+this.element.id+'_fillColorBtn"></button>'}),t.indexOf("strokeColor")>-1&&i.push({prefixIcon:"e-icons e-copy",id:this.element.id+"_strokecolor",cssClass:"top-icon e-stroke",tooltipText:this.l10n.getConstant("StrokeColor"),align:"Center",type:"Input",template:'<button id="'+this.element.id+'_borderColorBtn"></button>'}),t.indexOf("strokeWidth")>-1&&i.push({id:this.element.id+"_strokeWidth",cssClass:"top-icon e-size",tooltipText:"Stroke Width",align:"Center",type:"Input",template:'<button id="'+this.element.id+'_borderWidthBtn"></button>'});for(var s=this.processSubToolbar(t),o=0,a=s.length;o<a;o++)i.push(s[o]);return e.Browser.isDevice||(i.push({id:this.element.id+"_ok",prefixIcon:"e-icons e-check",cssClass:"top-icon e-tick",tooltipText:this.l10n.getConstant("OK"),align:"Right"}),i.push({id:this.element.id+"_cancel",prefixIcon:"e-icons e-close",cssClass:"top-icon e-save",tooltipText:this.l10n.getConstant("Cancel"),align:"Right"})),i},l.prototype.initShapesToolbarItem=function(t){var s=this,o=this.getLeftToolbarItem(),a=this.getRightToolbarItem(),n=this.getShapesToolbarItem(t),r=this.getZoomToolbarItem();e.Browser.isDevice?this.defToolbarItems=n:this.defToolbarItems=o.concat(r,n,a);var h=new i.Toolbar({width:"100%",items:this.defToolbarItems,clicked:this.defToolbarClicked.bind(this),created:function(){s.createShapeColor(t),s.createShapeBtn(t),e.Browser.isDevice||s.renderSaveBtn(),s.trigger("toolbarCreated",{toolbarType:"shapes"}),e.Browser.isDevice?s.defToolbarItems.length>0&&!e.isNullOrUndefined(document.getElementById(s.element.id+"_bottomToolbar"))&&h.refreshOverflow():(s.createLeftToolbarControls(),s.defToolbarItems.length>0&&!e.isNullOrUndefined(document.getElementById(s.element.id+"_toolbar"))&&h.refreshOverflow())}});e.Browser.isDevice?h.appendTo("#"+this.element.id+"_bottomToolbar"):h.appendTo("#"+this.element.id+"_toolbar"),this.enableDisableToolbarBtn()},l.prototype.createShapeColor=function(t){var i=this,a=this;if(t.indexOf("fillColor")>-1){this.element.querySelector(".e-template.e-fill").appendChild(this.createElement("input",{id:this.element.id+"_shape_fill"}));var n=new o.ColorPicker({modeSwitcher:!1,noColor:!0,value:"",showButtons:!1,mode:"Palette",cssClass:"e-shape-fill-color",change:function(t){i.pushActItemIntoObj();var s=e.extend({},i.cropObj,{},!0),o=i.getCurrentObj();o.objColl=e.extend([],i.objColl,[],!0),o.pointColl=e.extend([],i.pointColl,[],!0),o.afterCropActions=e.extend([],i.afterCropActions,[],!0),i.objColl.pop(),a.activeObj.strokeSettings.fillColor=t.currentValue.hex,a.strokeSettings.fillColor=a.activeObj.strokeSettings.fillColor,i.objColl.push(i.activeObj),i.updateUndoRedoColl("shapeTransform",o,o.objColl,o.pointColl,s),a.redrawShape(a.objColl[a.objColl.length-1]),""===t.currentValue.rgba?r.element.children[0].classList.add("e-nocolor-item"):(r.element.children[0].classList.remove("e-nocolor-item"),r.element.children[0].style.backgroundColor=t.currentValue.rgba),r.toggle()}},"#"+this.element.id+"_shape_fill"),r=new s.DropDownButton({open:function(t){e.Browser.isDevice&&(t.element.parentElement.style.top=r.element.getBoundingClientRect().top-t.element.parentElement.offsetHeight+"px",t.element.parentElement.style.left=i.element.offsetLeft+"px")},target:".e-shape-fill-color",iconCss:"e-dropdownbtn-preview"},"#"+this.element.id+"_fillColorBtn");n.inline=!0,this.element.querySelector(".e-fill.e-template .e-dropdownbtn-preview").classList.add("e-nocolor-item")}if(t.indexOf("strokeColor")>-1){this.element.querySelector(".e-template.e-stroke").appendChild(this.createElement("input",{id:this.element.id+"_shape_stroke"}));var h=new o.ColorPicker({modeSwitcher:!1,noColor:!1,value:"#fff",showButtons:!1,mode:"Palette",cssClass:"e-shape-stroke-color",change:function(t){i.pushActItemIntoObj();var s=e.extend({},i.cropObj,{},!0),o=i.getCurrentObj();o.objColl=e.extend([],i.objColl,[],!0),o.pointColl=e.extend([],i.pointColl,[],!0),o.afterCropActions=e.extend([],i.afterCropActions,[],!0),i.objColl.pop(),a.activeObj.strokeSettings.strokeColor=t.currentValue.hex,a.strokeSettings.strokeColor=a.activeObj.strokeSettings.strokeColor,a.togglePen||(i.objColl.push(i.activeObj),a.updateUndoRedoColl("shapeTransform",o,o.objColl,o.pointColl,s),a.redrawShape(a.objColl[a.objColl.length-1])),l.element.children[0].style.backgroundColor=t.currentValue.rgba,l.toggle()}},"#"+this.element.id+"_shape_stroke"),l=new s.DropDownButton({open:function(t){e.Browser.isDevice&&(t.element.parentElement.style.top=l.element.getBoundingClientRect().top-t.element.parentElement.offsetHeight+"px",t.element.parentElement.style.left=i.element.offsetLeft+"px")},target:".e-shape-stroke-color",iconCss:"e-dropdownbtn-preview"},"#"+this.element.id+"_borderColorBtn");h.inline=!0,this.element.querySelector(".e-stroke.e-template .e-dropdownbtn-preview").style.background="#fff"}},l.prototype.createShapeBtn=function(t){var i=this,o=[{id:"1",text:this.l10n.getConstant("XSmall")},{id:"2",text:this.l10n.getConstant("Small")},{id:"3",text:this.l10n.getConstant("Medium")},{id:"4",text:this.l10n.getConstant("Large")},{id:"5",text:this.l10n.getConstant("XLarge")}];if(t.indexOf("strokeWidth")>-1){var a=document.getElementById(this.element.id+"_borderWidthBtn"),n=document.createElement("span");n.innerHTML=this.l10n.getConstant("Small"),n.className="e-shape-stroke-width",a.appendChild(n);var r=new s.DropDownButton({items:o,open:function(t){e.Browser.isDevice&&(t.element.parentElement.style.top=r.element.getBoundingClientRect().top-t.element.parentElement.offsetHeight+"px");var i=n.innerHTML;""!==i&&t.element.querySelector('[aria-label = "'+i+'"]').classList.add("e-selected-btn")},select:function(t){i.pushActItemIntoObj();var s=e.extend({},i.cropObj,{},!0),o=i.getCurrentObj();o.objColl=e.extend([],i.objColl,[],!0),o.pointColl=e.extend([],i.pointColl,[],!0),o.afterCropActions=e.extend([],i.afterCropActions,[],!0),i.objColl.pop(),n.textContent=t.item.text,i.activeObj.strokeSettings.strokeWidth=parseInt(t.item.id,10),i.activeObj.strokeSettings.strokeWidth*=2,i.strokeSettings.strokeWidth=i.activeObj.strokeSettings.strokeWidth,i.objColl.push(i.activeObj),i.updateUndoRedoColl("shapeTransform",o,o.objColl,o.pointColl,s),i.redrawShape(i.objColl[i.objColl.length-1]),e.Browser.isDevice?e.isNullOrUndefined(document.getElementById(i.element.id+"_bottomToolbar"))||e.getComponent(i.element.id+"_bottomToolbar","toolbar").refreshOverflow():e.isNullOrUndefined(document.getElementById(i.element.id+"_toolbar"))||e.getComponent(i.element.id+"_toolbar","toolbar").refreshOverflow()}});r.appendTo("#"+this.element.id+"_borderWidthBtn")}},l.prototype.getTextToolbarItem=function(t){var i=[];t.indexOf("fontFamily")>-1&&i.push({id:this.element.id+"_fontFamily",cssClass:"top-icon e-img-font-family",tooltipText:this.l10n.getConstant("FontFamily"),align:"Center",template:'<button id="'+this.element.id+'_fontFamilyBtn"></button>'}),t.indexOf("fontStyle")>-1&&i.push({id:this.element.id+"_fontStyle",cssClass:"top-icon e-img-font-style",tooltipText:this.l10n.getConstant("FontStyle"),align:"Center",template:'<button id="'+this.element.id+'_fontStyleBtn"></button>'}),t.indexOf("fontSize")>-1&&i.push({id:this.element.id+"_fontSize",cssClass:"top-icon e-img-font-size",tooltipText:this.l10n.getConstant("FontSize"),align:"Center",template:'<button id="'+this.element.id+'_fontSizeBtn"></button>'}),t.indexOf("fontColor")>-1&&i.push({cssClass:"top-icon e-text-font-color",id:this.element.id+"_text_strokecolor",tooltipText:this.l10n.getConstant("FontColor"),align:"Center",type:"Input",template:'<button id="'+this.element.id+'_fontColorBtn"></button>'});for(var s=this.processSubToolbar(t),o=0,a=s.length;o<a;o++)i.push(s[o]);return e.Browser.isDevice||(i.push({id:this.element.id+"_ok",prefixIcon:"e-icons e-check",cssClass:"top-icon e-tick",tooltipText:this.l10n.getConstant("OK"),align:"Right"}),i.push({id:this.element.id+"_cancel",prefixIcon:"e-icons e-close",cssClass:"top-icon e-save",tooltipText:this.l10n.getConstant("Cancel"),align:"Right"})),i},l.prototype.getFontFamilyItems=function(){return e.Browser.isDevice?[{id:"arial",text:"ABC"},{id:"calibri",text:"ABC"},{id:"georgia",text:"ABC"},{id:"roboto",text:"ABC"},{id:"tahoma",text:"ABC"}]:[{id:"arial",text:"Arial"},{id:"calibri",text:"Calibri"},{id:"georgia",text:"Georgia"},{id:"roboto",text:"Roboto"},{id:"tahoma",text:"Tahoma"}]},l.prototype.getFontSizeItems=function(){return e.Browser.isDevice?[{id:"default",text:this.l10n.getConstant("ABC")},{id:"bold",text:this.l10n.getConstant("ABC")},{id:"italic",text:this.l10n.getConstant("ABC")},{id:"bolditalic",text:this.l10n.getConstant("ABC")}]:[{id:"default",text:this.l10n.getConstant("Default")},{id:"bold",text:this.l10n.getConstant("Bold")},{id:"italic",text:this.l10n.getConstant("Italic")},{id:"bolditalic",text:this.l10n.getConstant("BoldItalic")}]},l.prototype.initTextToolbarItem=function(t){var s=this,o=this.getLeftToolbarItem(),a=this.getRightToolbarItem(),n=this.getTextToolbarItem(t),r=this.getZoomToolbarItem();e.Browser.isDevice?this.defToolbarItems=n:this.defToolbarItems=o.concat(r,n,a);var h=new i.Toolbar({width:"100%",items:this.defToolbarItems,clicked:this.defToolbarClicked.bind(this),created:function(){s.createTextColor(t),s.createTextBtn(t),e.Browser.isDevice||s.renderSaveBtn(),s.trigger("toolbarCreated",{toolbarType:"text"}),e.Browser.isDevice?s.defToolbarItems.length>0&&!e.isNullOrUndefined(document.getElementById(s.element.id+"_bottomToolbar"))&&h.refreshOverflow():(s.createLeftToolbarControls(),s.defToolbarItems.length>0&&!e.isNullOrUndefined(document.getElementById(s.element.id+"_toolbar"))&&h.refreshOverflow())}});e.Browser.isDevice?h.appendTo("#"+this.element.id+"_bottomToolbar"):h.appendTo("#"+this.element.id+"_toolbar"),this.enableDisableToolbarBtn()},l.prototype.createTextColor=function(t){var i=this,a=this;if(t.indexOf("fontColor")>-1){this.element.querySelector(".e-template.e-text-font-color").appendChild(this.createElement("input",{id:this.element.id+"_text_font"}));var n=new o.ColorPicker({modeSwitcher:!1,value:"#fff",showButtons:!1,mode:"Palette",cssClass:"e-text-fontt-color",change:function(t){i.pushActItemIntoObj();var s=e.extend({},i.cropObj,{},!0),o=i.getCurrentObj();if(o.objColl=e.extend([],i.objColl,[],!0),o.pointColl=e.extend([],i.pointColl,[],!0),o.afterCropActions=e.extend([],i.afterCropActions,[],!0),i.objColl.pop(),"none"===a.textArea.style.display)a.strokeSettings.strokeColor=a.activeObj.strokeSettings.strokeColor=t.currentValue.hex,a.togglePen||(i.objColl.push(i.activeObj),a.updateUndoRedoColl("shapeTransform",o,o.objColl,o.pointColl,s),a.redrawShape(a.objColl[a.objColl.length-1]));else if("block"===a.textArea.style.display){a.textArea.style.color=t.currentValue.hex;var n=a.activeObj.strokeSettings.strokeColor;a.activeObj.strokeSettings.strokeColor=t.currentValue.hex,i.objColl.push(i.activeObj),i.updateUndoRedoColl("textAreaCustomization",o,o.objColl,o.pointColl,s),i.objColl.pop(),a.activeObj.strokeSettings.strokeColor=n}else a.togglePen||(i.objColl.push(i.activeObj),i.updateUndoRedoColl("shapeTransform",o,o.objColl,o.pointColl,s),a.redrawShape(a.objColl[a.objColl.length-1]));r.element.children[0].style.backgroundColor=t.currentValue.rgba,r.toggle()}},"#"+this.element.id+"_text_font"),r=new s.DropDownButton({open:function(t){e.Browser.isDevice&&(t.element.parentElement.style.top=r.element.getBoundingClientRect().top-t.element.parentElement.offsetHeight+"px",t.element.parentElement.style.left=i.element.offsetLeft+"px")},target:".e-text-fontt-color",iconCss:"e-dropdownbtn-preview"},"#"+this.element.id+"_fontColorBtn");n.inline=!0,this.element.querySelector(".e-text-font-color.e-template .e-dropdownbtn-preview").style.background="#fff"}},l.prototype.pushActItemIntoObj=function(){if("none"===this.textArea.style.display)this.objColl.push(this.activeObj);else{var t=e.extend({},this.activeObj,{},!0);this.setTextBoxStylesToActObj(),this.objColl.push(this.activeObj),this.activeObj=t}},l.prototype.createTextBtn=function(t){var i=this;if(t.indexOf("fontFamily")>-1){var o=document.getElementById(this.element.id+"_fontFamilyBtn"),a=document.createElement("span");e.Browser.isDevice?(a.innerHTML="ABC",a.setAttribute("style","font-family: arial")):a.innerHTML="Arial",a.className="e-text-font-family",o.appendChild(a);var n=new s.DropDownButton({items:this.getFontFamilyItems(),cssClass:"e-font-family",createPopupOnClick:!0,beforeItemRender:function(t){t.element.setAttribute("style","font-family:"+t.element.id)},open:function(t){e.Browser.isDevice&&(t.element.parentElement.style.top=n.element.getBoundingClientRect().top-t.element.parentElement.offsetHeight+"px");var s;s="block"===i.textArea.style.display?i.textArea.style.fontFamily:i.activeObj.textSettings.fontFamily,t.element.querySelector('[id *= "'+s.toLowerCase()+'"]').classList.add("e-selected-btn")},select:function(t){i.pushActItemIntoObj();var s=e.extend([],i.objColl,[],!0),o=e.extend({},i.cropObj,{},!0),n=i.getCurrentObj();if(n.objColl=e.extend([],i.objColl,[],!0),n.pointColl=e.extend([],i.pointColl,[],!0),n.afterCropActions=e.extend([],i.afterCropActions,[],!0),i.objColl.pop(),a.textContent=t.item.text,e.Browser.isDevice&&a.setAttribute("style","font-family:"+t.item.id),"block"===i.textArea.style.display){i.updateFontRatio(i.activeObj,!0);var r=i.activeObj.textSettings.fontFamily;i.activeObj.textSettings.fontFamily=i.toPascalCase(t.item.id),i.redrawText(),i.objColl.push(i.activeObj),i.updateUndoRedoColl("textAreaCustomization",n,n.objColl,n.pointColl,o),i.objColl.pop(),i.upperContext.clearRect(0,0,i.upperCanvas.width,i.upperCanvas.height);var h=i.activeObj.activePoint.width+.25*i.activeObj.textSettings.fontSize;i.textArea.style.width=h+"px",i.textArea.style.fontFamily=i.toPascalCase(t.item.id),i.activeObj.textSettings.fontFamily=r,i.updateFontStyles()}else i.updateFontRatio(i.activeObj),i.textSettings.fontFamily=i.activeObj.textSettings.fontFamily=i.toPascalCase(t.item.id),i.redrawText(),i.objColl.push(i.activeObj),i.updateUndoRedoColl("shapeTransform",n,s,e.extend([],i.pointColl,[],!0),o),i.redrawShape(i.objColl[i.objColl.length-1])}});n.appendTo("#"+this.element.id+"_fontFamilyBtn")}if(t.indexOf("fontStyle")>-1){var r=document.getElementById(this.element.id+"_fontStyleBtn"),h=document.createElement("span");e.Browser.isDevice?h.innerHTML=this.l10n.getConstant("ABC"):h.innerHTML=this.l10n.getConstant("Default"),h.className="e-text-font-style",r.appendChild(h);var l=new s.DropDownButton({items:this.getFontSizeItems(),cssClass:"e-font-style",createPopupOnClick:!0,beforeItemRender:function(t){e.Browser.isDevice&&("bold"===t.element.id?t.element.setAttribute("style","font-weight: bold"):"italic"===t.element.id?t.element.setAttribute("style","font-style: italic"):"bolditalic"===t.element.id&&t.element.setAttribute("style","font-style: italic;font-weight: bold"))},open:function(t){var s="default";"block"===i.textArea.style.display?("bold"===i.textArea.style.fontWeight&&(s="bold"),"italic"===i.textArea.style.fontStyle&&(s=s.replace("default",""),s+="italic")):(i.activeObj.textSettings.bold&&(s="bold"),i.activeObj.textSettings.italic&&(s=s.replace("default",""),s+="italic")),e.Browser.isDevice&&(t.element.parentElement.style.top=l.element.getBoundingClientRect().top-t.element.parentElement.offsetHeight+"px"),t.element.querySelector('[id *= "'+s+'"]').classList.add("e-selected-btn")},select:function(t){e.Browser.isDevice?("bold"===t.item.id?h.setAttribute("style","font-weight: bold"):"italic"===t.item.id?h.setAttribute("style","font-style: italic"):"bolditalic"===t.item.id&&h.setAttribute("style","font-style: italic;font-weight: bold"),i.applyFontStyle(t.item.id)):(h.textContent=t.item.text,i.applyFontStyle(t.item.id))}});l.appendTo("#"+this.element.id+"_fontStyleBtn")}if(t.indexOf("fontSize")>-1){var c=document.getElementById(this.element.id+"_fontSizeBtn"),d=document.createElement("span"),p=this.getFontSizes();d.innerHTML=p[0].text,d.className="e-text-font-size",c.appendChild(d);var v=new s.DropDownButton({cssClass:"e-font-size",items:p,open:function(t){e.Browser.isDevice&&(t.element.parentElement.style.top=v.element.getBoundingClientRect().top-t.element.parentElement.offsetHeight+"px");var i=d.innerHTML;t.element.querySelector('[aria-label *= "'+i+'"]').classList.add("e-selected-btn")},select:function(t){i.pushActItemIntoObj();var s=e.extend({},i.cropObj,{},!0),o=i.getCurrentObj();if(o.objColl=e.extend([],i.objColl,[],!0),o.pointColl=e.extend([],i.pointColl,[],!0),o.afterCropActions=e.extend([],i.afterCropActions,[],!0),i.objColl.pop(),d.textContent=t.item.text,"block"===i.textArea.style.display){i.updateFontRatio(i.activeObj,!0);var a=i.activeObj.textSettings.fontSize;i.activeObj.textSettings.fontSize=parseInt(i.fontSizeColl[parseInt(t.item.text,10)-1].text,10),i.objColl.push(i.activeObj),i.updateUndoRedoColl("textAreaCustomization",o,o.objColl,o.pointColl,s),i.objColl.pop();var n="";"bold"===i.textArea.style.fontWeight&&(n="bold "),"italic"===i.textArea.style.fontStyle&&(n="italic "),"bold"===i.textArea.style.fontWeight&&"italic"===i.textArea.style.fontStyle&&(n="italic bold "),i.upperContext.font=n+i.activeObj.textSettings.fontSize+"px "+i.textArea.style.fontFamily;var r=i.textArea.value.split("\n"),h=i.getMaxText(!0),l=i.upperContext.measureText(h).width+.5*i.activeObj.textSettings.fontSize;i.textArea.style.width=l+"px",i.textArea.style.height=r.length*(i.activeObj.textSettings.fontSize+.25*i.activeObj.textSettings.fontSize)+"px",i.activeObj.textSettings.fontSize=a,i.upperContext.font=i.activeObj.textSettings.fontSize+"px "+i.activeObj.textSettings.fontFamily,i.textArea.style.fontSize=parseInt(i.fontSizeColl[parseInt(t.item.text,10)-1].text,10)+"px","georgia"===i.textArea.style.fontFamily&&(i.textArea.style.width=parseFloat(i.textArea.style.width)+parseFloat(i.textArea.style.fontSize)+"px")}else{i.updateFontRatio(i.activeObj),i.textSettings.fontSize=i.activeObj.textSettings.fontSize=parseInt(i.fontSizeColl[parseInt(t.item.text,10)-1].text,10),i.upperContext.font=i.activeObj.textSettings.fontSize+"px "+i.activeObj.textSettings.fontFamily;var r=i.activeObj.keyHistory.split("\n"),h=i.getMaxText(),l=i.upperContext.measureText(h).width+.5*i.activeObj.textSettings.fontSize,c=r.length*(i.activeObj.textSettings.fontSize+.25*i.activeObj.textSettings.fontSize);i.setTextSelection(l,c),i.updateActiveObject(i.activeObj.activePoint,i.activeObj),i.redrawText(),i.objColl.push(i.activeObj),i.updateUndoRedoColl("shapeTransform",o,o.objColl,o.pointColl,s),i.redrawShape(i.objColl[i.objColl.length-1])}}});v.appendTo("#"+this.element.id+"_fontSizeBtn")}},l.prototype.getFontSizes=function(){var t=[];this.fontSizeColl=[];var e;e=0===this.degree||this.degree%180==0?this.destWidth/25:this.destHeight/25;for(var i=1;i<=10;i++)this.fontSizeColl.push({text:(i*Math.round(e/2)).toString()}),t.push({text:i.toString()});return t},l.prototype.getTextAreaWidth=function(t){var e=this.activeObj.textSettings.bold,i=this.activeObj.textSettings.italic;switch(t){case"default":this.activeObj.textSettings.bold=!1,this.activeObj.textSettings.italic=!1;break;case"bold":this.activeObj.textSettings.bold=!0,this.activeObj.textSettings.italic=!1;break;case"italic":this.activeObj.textSettings.bold=!1,this.activeObj.textSettings.italic=!0;break;case"bolditalic":this.activeObj.textSettings.bold=!0,this.activeObj.textSettings.italic=!0}this.updateFontStyles();var s;return s="none"===this.textArea.style.display?this.upperContext.measureText(this.activeObj.keyHistory).width+.5*this.activeObj.textSettings.fontSize:this.upperContext.measureText(this.textArea.value).width+.5*this.activeObj.textSettings.fontSize,this.activeObj.textSettings.bold=e,this.activeObj.textSettings.italic=i,s},l.prototype.updateUndoRedoObj=function(t){if(this.allowUndoRedo){this.objColl.push(this.activeObj);var i=e.extend({},this.cropObj,{},!0),s=this.getCurrentObj();s.objColl=e.extend([],this.objColl,[],!0),s.pointColl=e.extend([],this.pointColl,[],!0),s.afterCropActions=e.extend([],this.afterCropActions,[],!0),this.undoRedoColl.push({operation:"shapeTransform",previousObj:s,currentObj:s,previousObjColl:t,currentObjColl:s.objColl,previousPointColl:s.pointColl,currentPointColl:s.pointColl,previousCropObj:i,currentCropObj:i}),this.undoRedoStep++,this.redrawShape(this.objColl[this.objColl.length-1])}},l.prototype.updateObjColl=function(t,i){var s=e.extend({},this.cropObj,{},!0),o=this.getCurrentObj();o.objColl=e.extend([],this.objColl,[],!0),o.pointColl=e.extend([],this.pointColl,[],!0),o.afterCropActions=e.extend([],this.afterCropActions,[],!0);var a=this.activeObj.textSettings.bold,n=this.activeObj.textSettings.italic;switch(t){case"default":this.activeObj.textSettings.bold=!1,this.activeObj.textSettings.italic=!1;break;case"bold":this.activeObj.textSettings.bold=!0,this.activeObj.textSettings.italic=!1;break;case"italic":this.activeObj.textSettings.bold=!1,this.activeObj.textSettings.italic=!0;break;case"bolditalic":this.activeObj.textSettings.bold=!0,this.activeObj.textSettings.italic=!0}this.objColl.push(this.activeObj),this.updateUndoRedoColl("textAreaCustomization",o,o.objColl,o.pointColl,s),this.objColl.pop(),this.activeObj.textSettings.bold=a,this.activeObj.textSettings.italic=n},l.prototype.applyFontStyle=function(t){this.pushActItemIntoObj();var i=e.extend([],this.objColl,[],!0);switch(this.objColl.pop(),"none"===this.textArea.style.display?this.updateFontRatio(this.activeObj):this.updateFontRatio(this.activeObj,!0),t){case"default":if("block"===this.textArea.style.display){s=this.getTextAreaWidth(t);this.textArea.style.width=s+"px",this.textArea.style.fontWeight="normal",this.textArea.style.fontStyle="normal",this.updateObjColl(t,i)}else this.textSettings.bold=this.activeObj.textSettings.bold=!1,this.textSettings.italic=this.activeObj.textSettings.italic=!1,this.redrawText(),this.updateUndoRedoObj(i);break;case"bold":if("block"===this.textArea.style.display){s=this.getTextAreaWidth(t);this.textArea.style.width=s+"px",this.textArea.style.fontWeight="bold",this.textArea.style.fontStyle="normal",this.updateObjColl(t,i)}else this.textSettings.bold=this.activeObj.textSettings.bold=!0,this.textSettings.italic=this.activeObj.textSettings.italic=!1,this.redrawText(),this.updateUndoRedoObj(i);break;case"italic":if("block"===this.textArea.style.display){s=this.getTextAreaWidth(t);this.textArea.style.width=s+"px",this.textArea.style.fontWeight="normal",this.textArea.style.fontStyle="italic",this.updateObjColl(t,i)}else this.textSettings.bold=this.activeObj.textSettings.bold=!1,this.textSettings.italic=this.activeObj.textSettings.italic=!0,this.redrawText(),this.updateUndoRedoObj(i);break;case"bolditalic":if("block"===this.textArea.style.display){var s=this.getTextAreaWidth(t);this.textArea.style.width=s+"px",this.textArea.style.fontWeight="bold",this.textArea.style.fontStyle="italic",this.updateObjColl(t,i)}else this.textSettings.bold=this.activeObj.textSettings.bold=!0,this.textSettings.italic=this.activeObj.textSettings.italic=!0,this.redrawText(),this.updateUndoRedoObj(i)}},l.prototype.initZoomToolbarItem=function(){var t=this,s=this.getLeftToolbarItem(),o=this.getRightToolbarItem(),a=this.getZoomToolbarItem();this.defToolbarItems=s.concat(a,o),new i.Toolbar({width:"100%",items:this.defToolbarItems,clicked:this.defToolbarClicked.bind(this),created:function(){t.renderSaveBtn(),t.trigger("toolbarCreated",{toolbarType:"zoom"})}},"#"+this.element.id+"_toolbar"),this.createLeftToolbarControls(),this.enableDisableToolbarBtn(),this.defToolbarItems.length>0&&!e.isNullOrUndefined(document.getElementById(this.element.id+"_toolbar"))&&e.getComponent(this.element.id+"_toolbar","toolbar").refreshOverflow()},l.prototype.refreshUndoRedoColl=function(){this.undoRedoColl=this.undoRedoColl.slice(0,this.undoRedoStep),this.isUndoRedo=this.currObjType.isUndoAction=!1,this.enableDisableToolbarBtn()},l.prototype.applyPreviewFilter=function(){e.isNullOrUndefined(document.querySelector("#"+this.element.id+"_sliderWrapper"))&&!this.currObjType.isFiltered||(this.initialAdjustmentValue=this.canvasFilter=this.lowerContext.filter,this.currObjType.isFiltered=!1)},l.prototype.contextualToolbarClicked=function(t){var e=this.element.querySelector(".e-contextual-toolbar-wrapper .e-toolbar-item.e-selected");e&&e.classList.remove("e-selected"),document.getElementById(t.item.id+"Canvas").parentElement.parentElement.classList.add("e-selected"),this.currObjType.isFiltered=!0;var i=t.item.id.replace(this.element.id,"").split("_")[1],s={filter:this.toPascalCase(i)};this.trigger("imageFiltering",s),this.setFilter(i.toLowerCase()),this.currentFilter=t.item.id,this.enableDisableToolbarBtn()},l.prototype.defToolbarClicked=function(t){var i=!1;this.element.querySelector(".e-contextual-toolbar-wrapper")&&(this.element.querySelector(".e-contextual-toolbar-wrapper").classList.contains("e-hide")||(i=!0),this.element.querySelector(".e-contextual-toolbar-wrapper").classList.add("e-hide"));var s,o,a,n=t.item.id.replace(this.element.id+"_","").toLowerCase(),r=e.getInstance(document.getElementById(this.element.id),c),h=!1;void 0!==this.activeObj.shape&&(a=this.activeObj.shape.split("-")),void 0===a&&this.currObjType.isCustomCrop?h=!0:void 0!==a&&"crop"===a[0]&&(h=!0);var l=!1,d=!1,p=!1,v=document.querySelector("#"+this.element.id+"_zoomOut");!e.isNullOrUndefined(v)&&v.classList.contains("e-disabled")&&(l=!0);var b=document.querySelector("#"+this.element.id+"_adjustment");!e.isNullOrUndefined(b)&&b.classList.contains("e-disabled")&&(p=!0);var u=document.querySelector("#"+this.element.id+"_filter");if(!e.isNullOrUndefined(u)&&u.classList.contains("e-disabled")&&(d=!0),this.enableDisableToolbarBtn(),!this.disabled)switch(n){case"zoomin":this.isFreehandDrawEditing&&this.applyFreehandDraw(),this.applyPreviewFilter(),this.currObjType.isFiltered=!1,this.currObjType.isUndoAction&&this.refreshUndoRedoColl(),this.togglePen&&(this.currObjType.isZoomed=!0,this.freeHandDraw(!1)),this.currentSelectionPoint=null,r.zoom(.1);break;case"zoomout":l||(this.isFreehandDrawEditing&&this.applyFreehandDraw(),this.applyPreviewFilter(),this.currObjType.isFiltered=!1,this.currObjType.isUndoAction&&this.refreshUndoRedoColl(),this.togglePen&&(this.currObjType.isZoomed=!0,this.freeHandDraw(!1)),this.currentSelectionPoint=null,r.zoom(-.1));break;case"pan":this.currObjType.isCustomCrop=this.currObjType.isFiltered=!1,this.currObjType.isUndoAction&&this.refreshUndoRedoColl(),h&&(this.currObjType.isCustomCrop=!1,this.refreshActiveObj(),this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),this.refreshToolbar("main")),this.togglePan?(this.cancelPan(),this.disablePan=!0,"pen"===this.currentToolbar&&this.freeHandDraw(!0)):(o=this.element.querySelector(".e-img-pan .e-btn"),e.isNullOrUndefined(o)||o.classList.add("e-selected-btn"),r.pan(!0),this.disablePan=!1),s=document.querySelector("#"+this.element.id+"_zoomIn"),!e.isNullOrUndefined(s)&&this.zoomFactor>=2?(s.classList.add("e-disabled"),s.parentElement.classList.add("e-overlay")):e.isNullOrUndefined(s)||(s.classList.remove("e-disabled"),s.parentElement.classList.remove("e-overlay")),this.refreshToolbar("main");break;case"cancel":this.performCancel(i);break;case"ok":this.okBtn(),this.refreshDropDownBtn(!1),this.currentToolbar="main";break;case"crop":e.isNullOrUndefined(this.currSelectionPoint)||(this.currObjType.isUndoAction&&this.refreshUndoRedoColl(),e.isNullOrUndefined(this.cropObj.activeObj.shape)||this.select(this.cropObj.activeObj.shape),this.refreshToolbar("main",!0,!0),e.getComponent(this.element.querySelector("#"+this.element.id+"_cropBtn"),"dropdown-btn").toggle(),e.isNullOrUndefined(this.activeObj.shape)||document.getElementById(this.activeObj.shape.split("-")[1]).classList.add("e-selected"));break;case"reset":r.reset(),this.currentToolbar="main";break;case"adjustment":p||(this.refreshToolbar("adjustment"),this.setTempFilterProperties(),this.openSlider("brightness"));break;case"brightness":case"contrast":case"hue":case"saturation":case"opacity":case"blur":case"exposure":this.openSlider(n);break;case"filter":d||(this.refreshToolbar("filter"),this.setTempFilterProperties());break;case"default":case"chrome":case"cold":case"warm":case"grayscale":case"blackandwhite":case"sepia":case"invert":case"sharpen":this.currObjType.isUndoAction&&this.refreshUndoRedoColl(),this.currObjType.isFiltered=!0,this.setFilter(n)}this.trigger("toolbarItemClicked",t)},l.prototype.performCancel=function(t){t=t||!1,this.isFreehandDrawEditing?this.cancelFreehandDraw():"block"===this.textArea.style.display?(this.textArea.style.display="none",this.textArea.value="",this.textArea.style.transform="",this.activeObj.strokeSettings=this.tempStrokeSettings,this.activeObj.textSettings=this.tempTextSettings):!e.isNullOrUndefined(document.querySelector("#"+this.element.id+"_sliderWrapper"))||this.currObjType.isFiltered?(this.lowerContext.filter=this.adjustmentValue=this.initialAdjustmentValue=this.tempAdjustmentValue,this.lowerContext.filter.split(" ").length>1&&"1"===this.lowerContext.filter.split(" ")[0].split("(")[1].split(")")[0]&&(this.isBrightnessAdjusted=!1),this.currentFilter=this.tempFilter,this.lowerContext.clearRect(0,0,this.lowerCanvas.width,this.lowerCanvas.height),this.redrawImgWithObj(),this.currObjType.isFiltered=!1,this.adjustmentLevel=e.extend({},this.tempAdjustmentLevel,{},!0),this.element.querySelector(".e-contextual-toolbar-wrapper").classList.add("e-hide"),this.undoRedoStep=this.tempUndoRedoStep,this.upperCanvas.style.cursor="default",this.currObjType.isCustomCrop=!1,this.tempStrokeSettings={strokeColor:"#fff",fillColor:"",strokeWidth:null},this.callMainToolbar()):t?this.callMainToolbar():(this.cancelItems(),this.togglePan=this.dragCanvas=!1),this.enableDisableToolbarBtn(),this.refreshDropDownBtn(!1),this.currentToolbar="main"},l.prototype.applyShape=function(){e.isNullOrUndefined(this.activeObj.shape)||"rectangle"!==this.activeObj.shape&&"ellipse"!==this.activeObj.shape&&"line"!==this.activeObj.shape&&"text"!==this.activeObj.shape||(this.redrawActObj(),this.refreshActiveObj(),this.currentToolbar="main",this.refreshToolbar("main"))},l.prototype.applyFreehandDraw=function(){"#42a5f5"===this.pointColl[this.freehandDrawSelectedIndex].strokeColor&&(this.pointColl[this.freehandDrawSelectedIndex].strokeColor=this.tempFreeHandDrawEditingStyles.strokeColor),this.selectedFreehandColor="#42a5f5",this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),this.lowerContext.clearRect(0,0,this.lowerCanvas.width,this.lowerCanvas.height),this.renderImage(),this.refreshToolbar("main"),e.isNullOrUndefined(this.pointColl[this.freehandDrawSelectedIndex])||(this.pointColl[this.freehandDrawSelectedIndex].isSelected=!1),this.isFreehandDrawEditing=this.isFreehandDrawingPoint=!1,this.freehandDrawHoveredIndex=this.freehandDrawSelectedIndex=null},l.prototype.cancelFreehandDraw=function(){this.selectedFreehandColor="#42a5f5",this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height);for(var t=0;t<this.freehandCounter;t++)this.pointColl[t].strokeColor=this.tempFreeHandDrawEditingStyles.strokeColor,this.pointColl[t].strokeWidth=this.tempFreeHandDrawEditingStyles.strokeWidth;this.pointCounter=0,e.isNullOrUndefined(this.pointColl[this.freehandDrawSelectedIndex])||(this.pointColl[this.freehandDrawSelectedIndex].isSelected=!1),this.freehandDrawHoveredIndex=this.freehandDrawSelectedIndex=this.freehandDrawSelectedId=null,this.isFreehandDrawEditing=this.isFreehandDrawingPoint=!1,this.tempFreeHandDrawEditingStyles={strokeColor:null,strokeWidth:null,fillColor:null},this.refreshToolbar("main")},l.prototype.openSlider=function(t){this.unselectBtn(),this.currObjType.isFiltered=!0,this.refreshToolbar("color",null,null,null,t),document.getElementById(this.element.id+"_"+t).classList.add("e-selected-btn")},l.prototype.setTempFilterProperties=function(){this.upperCanvas.style.display="block",this.cropSelectedState(),this.lowerContext.filter=this.initialAdjustmentValue,this.tempAdjustmentValue=this.lowerContext.filter,this.tempAdjustmentLevel=e.extend({},this.adjustmentLevel,{},!0),this.tempFilter=this.currentFilter,this.tempUndoRedoColl=e.extend([],this.undoRedoColl,[],!0),this.tempUndoRedoStep=this.undoRedoStep},l.prototype.okBtn=function(){var t,i=!1;void 0!==this.activeObj.shape&&(t=this.activeObj.shape.split("-")),void 0===t&&this.currObjType.isCustomCrop?i=!0:void 0!==t&&"crop"===t[0]&&(i=!0);var s=this.element.querySelector(".e-contextual-toolbar-wrapper .e-toolbar-item.e-selected");s&&(this.currentFilter=s.children[0].children[0].id.replace("Canvas","")),i?this.crop():this.togglePen?this.freeHandDraw(!1):"block"===this.textArea.style.display?this.redrawActObj():!e.isNullOrUndefined(document.querySelector("#"+this.element.id+"_sliderWrapper"))||this.currObjType.isFiltered?(this.initialAdjustmentValue=this.canvasFilter=this.lowerContext.filter,this.currObjType.isFiltered=!1):this.isFreehandDrawEditing?this.applyFreehandDraw():this.applyActObj(),this.callMainToolbar(!1),this.isCropTab=!1,this.zoomFactor=this.defaultZoomFactor},l.prototype.updateBrightnessFilter=function(){var t=this.lowerContext.filter.split(" ");if(this.isBrightnessAdjusted&&t.length>0&&!e.isNullOrUndefined(t[4])){var i=parseFloat(t[4].split("(")[1]);t[4]="opacity("+(i-.3)+")",this.lowerContext.filter=t.join(" ")}},l.prototype.isFreehandDrawIndex=function(t){for(var e=!1,i=0;i<this.freehandCounter;i++)if(parseInt(this.pointColl[i].id.split("_")[1],10)-1===t){e=!0;break}return e},l.prototype.deleteFreehandDraw=function(t,i){if(this.isFreehandDrawIndex(t)){this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height);var s=e.extend({},this.pointColl,{},!0);this.pointColl={};var o=0;if(e.isNullOrUndefined(i))for(a=0;a<this.freehandCounter;a++)a!==t&&(this.pointColl[o]=s[a],o++);else for(var a=0;a<this.freehandCounter;a++)parseInt(s[a].id.split("_")[1],10)-1!==t&&(this.pointColl[o]=s[a],o++);this.freehandCounter-=1,this.freehandDrawHoveredIndex=this.freehandDrawSelectedIndex=null,this.isFreehandDrawEditing=this.isFreehandDrawingPoint=!1,this.renderImage(),this.refreshToolbar("main")}},l.prototype.unselectBtn=function(){document.querySelector("#"+this.element.id+"_brightness").classList.contains("e-selected-btn")?document.querySelector("#"+this.element.id+"_brightness").classList.remove("e-selected-btn"):document.querySelector("#"+this.element.id+"_contrast").classList.contains("e-selected-btn")?document.querySelector("#"+this.element.id+"_contrast").classList.remove("e-selected-btn"):document.querySelector("#"+this.element.id+"_hue").classList.contains("e-selected-btn")?document.querySelector("#"+this.element.id+"_hue").classList.remove("e-selected-btn"):document.querySelector("#"+this.element.id+"_saturation").classList.contains("e-selected-btn")?document.querySelector("#"+this.element.id+"_saturation").classList.remove("e-selected-btn"):document.querySelector("#"+this.element.id+"_opacity").classList.contains("e-selected-btn")?document.querySelector("#"+this.element.id+"_opacity").classList.remove("e-selected-btn"):document.querySelector("#"+this.element.id+"_blur").classList.contains("e-selected-btn")?document.querySelector("#"+this.element.id+"_blur").classList.remove("e-selected-btn"):document.querySelector("#"+this.element.id+"_exposure").classList.contains("e-selected-btn")&&document.querySelector("#"+this.element.id+"_exposure").classList.remove("e-selected-btn")},l.prototype.callUndo=function(){this.currObjType.isFiltered=!1,this.togglePan||this.callMainToolbar(!1,!1),0===this.zoomFactor&&(this.dragCanvas=this.togglePan=!1,this.callMainToolbar(!1,!1)),this.element.querySelector(".e-contextual-toolbar-wrapper")&&this.element.querySelector(".e-contextual-toolbar-wrapper").classList.add("e-hide"),this.togglePen&&(this.togglePen=!1,this.upperCanvas.style.cursor="default",this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height)),this.undo()},l.prototype.callRedo=function(){this.currObjType.isFiltered=!1,this.togglePan||this.callMainToolbar(!1,!1),0===this.zoomFactor&&(this.dragCanvas=this.togglePan=!1,this.callMainToolbar(!1,!1)),this.redo()},l.prototype.refreshSlider=function(){var t=document.querySelector("#"+this.element.id+"_sliderWrapper"),i=document.querySelector(".e-slider"),s=document.querySelector("#"+this.element.id+"_headWrapper");s&&(s.style.display="none"),e.isNullOrUndefined(t)||e.isNullOrUndefined(i)||(i.ej2_instances[0].destroy(),t.remove())},l.prototype.iterateObjColl=function(){for(var t=0;t<this.objColl.length;t++)this.apply(this.objColl[t].shape,this.objColl[t]),this.refreshActiveObj()},l.prototype.updateAdjustment=function(t,i,s){this.lowerContext.clearRect(0,0,this.lowerCanvas.width,this.lowerCanvas.height);var o,a,n=this.lowerContext.filter.split(" "),r=[];void 0!==n[4]&&(o=parseFloat(n[4].split("(")[1])),void 0!==n[0]&&(a=parseFloat(n[0].split("(")[1]));var h=this.getFilterValue(this.adjustmentLevel.brightness),l=this.getFilterValue(this.adjustmentLevel.saturation);if("brightness"!==t&&"contrast"!==t&&"hue"!==t&&"saturation"!==t&&"exposure"!==t&&"opacity"!==t&&"blur"!==t&&e.isNullOrUndefined(s)&&(this.adjustmentLevel.sharpen||this.adjustmentLevel.bw)){this.isUndoRedo=!0;var c=this.lowerContext.filter;this.lowerContext.filter="none",this.iterateObjColl(),this.freehandRedraw(this.lowerContext),this.lowerContext.filter=c,this.isUndoRedo=!1}1!==h&&(n[4]="opacity("+(o-.3)+")");var d,p,v,b,u;switch(t){case"brightness":100!==parseFloat(n[3].split("(")[1])&&(i+=.1),n[0]="brightness("+i+")",this.adjustmentValue=n.join(" ");break;case"contrast":n[1]="contrast("+i+"%)",this.adjustmentValue=n.join(" ");break;case"hue":n[2]="hue-rotate("+i+"deg)",this.adjustmentValue=n.join(" ");break;case"saturation":n[3]="saturate("+i+"%)",1!==l&&(n[0]="brightness("+(a+.1)+")"),this.adjustmentValue=n.join(" ");break;case"opacity":1!==parseFloat(n[0].split("(")[1])&&(i-=.2),n[4]="opacity("+i+")",this.adjustmentValue=n.join(" ");break;case"blur":n[5]="blur("+i+"px)",this.adjustmentValue=n.join(" ");break;case"exposure":1!==h&&(n[4]="opacity("+(o-.3)+")"),i>1?(i-=1,i+=h):i<1&&(i=h-(i=1-i)),n[0]="brightness("+i+")",this.adjustmentValue=n.join(" ");break;case"chrome":d=this.getSaturationFilterValue(this.adjustmentLevel.saturation),i=(d*=100)+.4*d,n[3]="saturate("+i+"%)",r=this.adjustmentValue.split(" "),n[0]=r[0],n[1]=r[1],n[2]=r[2],n[4]=r[4],n[5]=r[5],n[6]="sepia(0%)",n[7]="grayscale(0%)",n[8]="invert(0%)";break;case"cold":p=this.getFilterValue(this.adjustmentLevel.brightness),i=.9*(p*=100),n[0]="brightness("+i+"%)",b=this.getFilterValue(this.adjustmentLevel.contrast),i=(b*=100)+.5*b,n[1]="contrast("+i+"%)",u=this.getSaturationFilterValue(this.adjustmentLevel.saturation),i=u*=100,n[3]="saturate("+i+"%)",r=this.adjustmentValue.split(" "),n[2]=r[2],n[4]=r[4],n[5]=r[5],n[6]="sepia(0%)",n[7]="grayscale(0%)",n[8]="invert(0%)";break;case"warm":v=this.getSaturationFilterValue(this.adjustmentLevel.saturation),i=(v*=100)+.4*v,n[3]="saturate("+i+"%)",n[6]="sepia(25%)",r=this.adjustmentValue.split(" "),n[0]=r[0],n[1]=r[1],n[2]=r[2],n[4]=r[4],n[5]=r[5],n[7]="grayscale(0%)",n[8]="invert(0%)";break;case"grayscale":n[7]="grayscale(100%)",r=this.adjustmentValue.split(" "),n[0]=r[0],n[1]=r[1],n[2]=r[2],n[3]=r[3],n[4]=r[4],n[5]=r[5],n[6]="sepia(0%)",n[8]="invert(0%)";break;case"sepia":n[6]="sepia(100%)",r=this.adjustmentValue.split(" "),n[0]=r[0],n[1]=r[1],n[2]=r[2],n[3]=r[3],n[4]=r[4],n[5]=r[5],n[7]="grayscale(0%)",n[8]="invert(0%)";break;case"invert":n[8]="invert(100%)",r=this.adjustmentValue.split(" "),n[0]=r[0],n[1]=r[1],n[2]=r[2],n[3]=r[3],n[4]=r[4],n[5]=r[5],n[6]="sepia(0%)",n[7]="grayscale(0%)"}if("sharpen"!==t&&"blackandwhite"!==t){e.isNullOrUndefined(s)&&("default"===t&&(n=this.getDefaultCurrentFilter(n)),this.lowerContext.filter=n.join(" ")),n=this.setTempFilterValue(h,s,n,t),this.isRotateZoom=!0,this.updateCurrentTransformedState("initial"),this.lowerContext.drawImage(this.baseImg,this.srcLeft,this.srcTop,this.srcWidth,this.srcHeight,this.destLeft,this.destTop,this.destWidth,this.destHeight),this.updateCurrentTransformedState("reverse"),this.isRotateZoom=!1,1!==h?n[4]="opacity("+o+")":1!==l&&(n[0]="brightness("+a+")"),"exposure"===t&&1!==h&&(n[0]="brightness("+a+")"),"saturation"===t&&1!==l&&(n[0]="brightness("+a+")"),n=this.setTempFilterValue(h,s,n,t),e.isNullOrUndefined(s)&&(this.lowerContext.filter=this.initialAdjustmentValue=n.join(" "));var C=this.lowerContext.filter;this.lowerContext.filter=this.getDefaultFilter(),this.iterateObjColl(),this.freehandRedraw(this.lowerContext),this.lowerContext.filter=C,(!e.isNullOrUndefined(this.currSelectionPoint)&&"crop-circle"===this.currSelectionPoint.shape||this.isCircleCrop)&&this.cropCircle(this.lowerContext),this.isBrightnessAdjusted=1!==h}return n.join(" ")},l.prototype.autoEnablePan=function(){0===this.zoomFactor?(this.dragCanvas=this.togglePan=!1,this.callMainToolbar(!1,!0),this.pan(!1),this.disablePan=!1):this.disablePan?this.disablePan&&this.pan(!1):this.pan(!0)},l.prototype.setTempFilterValue=function(t,e,i,s){if(e&&1!==t){var o=this.lowerContext.filter.split(" ");o[4]=i[4],this.lowerContext.filter=o.join(" ")}else e&&"default"===s&&(i=this.getDefaultCurrentFilter(i));return i},l.prototype.getDefaultCurrentFilter=function(t){var e=this.adjustmentValue.split(" ");return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t[4]=e[4],t[5]=e[5],t[6]="sepia(0%)",t[7]="grayscale(0%)",t[8]="invert(0%)",t},l.prototype.renderSlider=function(t){var i=document.querySelector("#"+this.element.id+"_contextualToolbarArea"),s=document.querySelector("#"+this.element.id+"_headWrapper"),o=document.querySelector("#"+this.element.id+"_labelWrapper");s?s.style.display="block":o=(s=i.appendChild(this.createElement("div",{id:this.element.id+"_headWrapper",styles:"position: relative"}))).appendChild(this.createElement("label",{id:this.element.id+"_labelWrapper",styles:e.Browser.isDevice?"position: absolute; top: 25%; left: calc(50% - 150px); font-size: 15px; text-transform: capitalize; font-weight: 400;":"position: absolute; top: 25%; left: calc(50% - 226px); font-size: 15px; text-transform: capitalize; font-weight: 400;"})),o.textContent=this.l10n.getConstant(this.toPascalCase(t));var a,n,r,h=s.appendChild(this.createElement("div",{id:this.element.id+"_sliderWrapper",styles:"position: absolute"})),l=this.getCurrAdjustmentValue(t);"brightness"===t||"contrast"===t||"saturation"===t||"exposure"===t?(this.finetuneSettings?"brightness"===t&&this.finetuneSettings.brightness?(a=this.finetuneSettings.brightness.min,n=this.finetuneSettings.brightness.max):"contrast"===t&&this.finetuneSettings.contrast?(a=this.finetuneSettings.contrast.min,n=this.finetuneSettings.contrast.max):"saturation"===t&&this.finetuneSettings.saturation?(a=this.finetuneSettings.saturation.min,n=this.finetuneSettings.saturation.max):"exposure"===t&&this.finetuneSettings.exposure?(a=this.finetuneSettings.exposure.min,n=this.finetuneSettings.exposure.max):(a=-100,n=100):(a=-100,n=100),r=this.createSlider(a,n,l,t)):"hue"!==t&&"blur"!==t&&"opacity"!==t||(this.finetuneSettings?"hue"===t&&this.finetuneSettings.hue?(a=this.finetuneSettings.hue.min,n=this.finetuneSettings.hue.max):"blur"===t&&this.finetuneSettings.blur?(a=this.finetuneSettings.blur.min,n=this.finetuneSettings.blur.max):"opacity"===t&&this.finetuneSettings.opacity?(a=this.finetuneSettings.opacity.min,n=this.finetuneSettings.opacity.max):(a=0,n=100):(a=0,n=100),r=this.createSlider(a,n,l,t)),r.appendTo("#"+this.element.id+"_sliderWrapper"),h.style.left=(parseFloat(i.style.width)-parseFloat(r.width))/2+"px"},l.prototype.createSlider=function(t,i,s,a){var n=this;return new o.Slider({value:s,tooltip:{isVisible:!0,placement:"Before",showOn:"Always"},type:"MinRange",min:t,max:i,step:10,width:e.Browser.isDevice?"200px":"300px",cssClass:"e-slider",change:function(t){n.currObjType.isUndoAction&&n.refreshUndoRedoColl(),n.setCurrAdjustmentValue(a,t.value),n.enableDisableToolbarBtn()}})},l.prototype.getCurrAdjustmentValue=function(t){var e;switch(t){case"brightness":e=this.adjustmentLevel.brightness;break;case"contrast":e=this.adjustmentLevel.contrast;break;case"hue":e=this.adjustmentLevel.hue;break;case"saturation":e=this.adjustmentLevel.saturation;break;case"opacity":e=this.adjustmentLevel.opacity;break;case"blur":e=this.adjustmentLevel.blur;break;case"exposure":e=this.adjustmentLevel.exposure}return e},l.prototype.setCurrAdjustmentValue=function(t,e){var i={finetune:this.toPascalCase(t),value:e};switch(this.trigger("finetuneValueChanging",i),t){case"brightness":this.setBrightness(e);break;case"contrast":this.setContrast(e);break;case"hue":this.setHue(e);break;case"saturation":this.setSaturation(e);break;case"opacity":this.setOpacity(e);break;case"blur":this.setBlur(e);break;case"exposure":this.setExposure(e)}},l.prototype.cancelPan=function(){this.applyActObj();var t=this.element.querySelector(".e-img-pan .e-btn");e.isNullOrUndefined(t)||t.classList.remove("e-selected-btn"),this.pan(!1)},l.prototype.callMainToolbar=function(t,e){this.refreshToolbar("main",t,!1,e)},l.prototype.setCurrSelectionPoints=function(t){if(this.srcLeft=0,this.srcTop=0,this.srcWidth=this.baseImg.width,this.srcHeight=this.baseImg.height,this.destLeft=this.cropDestPoints.startX,this.destTop=this.cropDestPoints.startY,this.destWidth=this.cropDestPoints.width,this.destHeight=this.cropDestPoints.height,this.lowerContext.clearRect(0,0,this.lowerCanvas.width,this.lowerCanvas.height),t&&this.setDestinationPoints(),this.currentTransformedState("initial"),0!==this.croppedDegree||0!==this.degree||e.isNullOrUndefined(this.currSelectionPoint)||"crop-circle"===this.currSelectionPoint.shape||"crop-square"===this.currSelectionPoint.shape||(this.destLeft=this.cropDestPoints.startX,this.destTop=this.cropDestPoints.startY,this.destWidth=this.cropDestPoints.width,this.destHeight=this.cropDestPoints.height),0===this.degree&&(this.destLeft+=this.totalPannedInternalPoint.x,this.destTop+=this.totalPannedInternalPoint.y),this.updateBrightnessFilter(),this.lowerContext.drawImage(this.baseImg,this.srcLeft,this.srcTop,this.srcWidth,this.srcHeight,this.destLeft,this.destTop,this.destWidth,this.destHeight),this.currentTransformedState("reverse",null,null,!0),e.isNullOrUndefined(this.cropObj.activeObj.shape)){var i=this.lowerContext.filter;this.lowerContext.filter="none",this.iterateObjColl(),this.freehandRedraw(this.lowerContext),this.lowerContext.filter=i,this.currSelectionPoint=null}else{if(this.cropObj.cropZoom>0){var s=e.extend([],this.objColl,null,!0),o=e.extend([],this.pointColl,null,!0);this.objColl=[],this.pointColl=[],this.freehandCounter=0,this.zoom(this.cropObj.cropZoom),this.objColl=s,this.pointColl=o,this.freehandCounter=this.pointColl.length,this.currSelectionPoint=e.extend({},this.cropObj.activeObj,null,!0),""!==this.cropObj.currFlipState&&(this.cropObj.totalPannedPoint.x+=this.cropObj.tempFlipPanPoint.x,this.cropObj.totalPannedPoint.y+=this.cropObj.tempFlipPanPoint.y)}var a={startX:this.destLeft,startY:this.destTop,width:this.destWidth,height:this.destHeight};this.destLeft=this.currSelectionPoint.activePoint.startX,this.destTop=this.currSelectionPoint.activePoint.startY,this.destWidth=this.currSelectionPoint.activePoint.width,this.destHeight=this.currSelectionPoint.activePoint.height,this.zoomObjColl(),this.zoomFreehandDrawColl(),this.destLeft=a.startX,this.destTop=a.startY,this.destWidth=a.width,this.destHeight=a.height,this.updatePannedRegion(),this.updateObjAndFreeHandDrawColl();var n=e.extend([],this.objColl,null,!0),r=e.extend([],this.pointColl,null,!0);this.objColl=[],this.pointColl=[],this.freehandCounter=0,this.setCurrentObj();var h=e.extend({},this.activeObj,null,!0);this.refreshActiveObj(),this.objColl=n,this.pointColl=r,this.freehandCounter=this.pointColl.length,this.zoomObjColl(),this.zoomFreehandDrawColl(),this.currSelectionPoint=null,0===this.degree&&this.drawPannImage({x:0,y:0}),this.activeObj=h,this.drawObject("duplicate")}},l.prototype.updatePannedRegion=function(){var t=0===this.degree?this.cropObj.totalPannedPoint:this.cropObj.totalPannedClientPoint;this.currFlipState===this.cropObj.currFlipState?(this.panObjColl(-t.x,-t.y,""),this.panFreehandDrawColl(-t.x,-t.y,"")):"horizontal"===this.currFlipState&&""===this.cropObj.currFlipState||"vertical"===this.currFlipState&&""===this.cropObj.currFlipState?(this.panObjColl(-t.x,-t.y,""),this.panFreehandDrawColl(-t.x,-t.y,"")):""===this.currFlipState&&"horizontal"===this.cropObj.currFlipState?(this.panObjColl(t.x,-t.y,""),this.panFreehandDrawColl(t.x,-t.y,"")):""===this.currFlipState&&"vertical"===this.cropObj.currFlipState&&(this.panObjColl(-t.x,t.y,""),this.panFreehandDrawColl(-t.x,t.y,""))},l.prototype.updateObjAndFreeHandDrawColl=function(){for(var t=0;t<this.objColl.length;t++)this.objColl[t].imageRatio={startX:(this.objColl[t].activePoint.startX-this.destLeft)/this.destWidth,startY:(this.objColl[t].activePoint.startY-this.destTop)/this.destHeight,endX:(this.objColl[t].activePoint.endX-this.destLeft)/this.destWidth,endY:(this.objColl[t].activePoint.endY-this.destTop)/this.destHeight,width:this.destWidth/this.objColl[t].activePoint.width,height:this.destHeight/this.objColl[t].activePoint.height},this.refreshActiveObj();for(var i=0;i<this.freehandCounter;i++){this.points=e.extend([],this.pointColl[i].points,[]),this.pointCounter=0;for(var s=this.points.length,o=0;o<s;o++)this.points[o].ratioX=(this.points[o].x-this.destLeft)/this.destWidth,this.points[o].ratioY=(this.points[o].y-this.destTop)/this.destHeight}},l.prototype.cancelItems=function(){var t,i=!1;if(void 0!==this.activeObj.shape&&(t=this.activeObj.shape.split("-")),void 0===t&&this.currObjType.isCustomCrop?i=!0:void 0!==t&&"crop"===t[0]&&(i=!0),i&&this.isCropTab&&(this.isCropTab=!1,this.zoomFactor=this.defaultZoomFactor),this.togglePen){this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),this.togglePen=!1,this.upperCanvas.style.cursor="default";var s=e.extend([],this.pointColl,[],!0);this.pointColl={};for(var o=0;o<this.tempFreehandCounter;o++)this.pointColl[o]=s[o];this.freehandCounter=this.tempFreehandCounter,this.currentFreehandDrawIndex=this.tempCurrentFreehandDrawIndex}else if("text"===this.activeObj.shape)e.isNullOrUndefined(this.activeObj.currIndex)?(this.refreshActiveObj(),this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height)):(this.activeObj.strokeSettings=this.tempStrokeSettings,this.activeObj.textSettings=this.tempTextSettings,"Enter Text"===this.activeObj.keyHistory&&this.activeObj.activePoint.startX===this.textStartPoints.x&&this.activeObj.activePoint.startY===this.textStartPoints.y?(this.refreshActiveObj(),this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),this.textSettings=this.tempTextSettings,this.strokeSettings=this.tempStrokeSettings,this.drawShapeText(),this.applyActObj()):(this.redrawText(),this.redrawShape(this.activeObj),i||void 0===this.activeObj.topLeftCircle||this.applyActObj(),this.clearSelection())),this.tempTextSettings={text:"Enter Text",fontFamily:"Arial",fontSize:null,fontRatio:null,bold:!1,italic:!1,underline:!1};else if("rectangle"===this.activeObj.shape||"ellipse"===this.activeObj.shape||"line"===this.activeObj.shape)e.isNullOrUndefined(this.activeObj.currIndex)?(this.refreshActiveObj(),this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height)):(this.activeObj.strokeSettings=this.tempStrokeSettings,this.redrawShape(this.activeObj),this.applyActObj());else if(this.zoomFactor!==this.tempZoomFactor||i&&e.isNullOrUndefined(this.currSelectionPoint)){var a=this.cropZoomFactor-this.tempZoomFactor;if(this.zoomFactor=this.cropZoomFactor,e.isNullOrUndefined(this.cropObj.activeObj.shape)&&(0===this.degree&&0===this.totalPannedPoint.x&&0===this.totalPannedPoint.y||0!==this.degree&&0===this.totalPannedInternalPoint.x&&0===this.totalPannedInternalPoint.y&&0===this.totalPannedClientPoint.x&&0===this.totalPannedClientPoint.y))return this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),this.refreshActiveObj(),a>0?this.zoom(-a):this.zoom(Math.abs(a)),this.cropZoomFactor=this.tempZoomFactor,this.currObjType.isCustomCrop=!1,this.upperCanvas.style.cursor="default",this.currObjType.isCustomCrop=!1,this.tempStrokeSettings={strokeColor:"#fff",fillColor:"",strokeWidth:null},void this.callMainToolbar();if(e.isNullOrUndefined(this.cropObj.activeObj.shape)){if(0===this.degree){var n=e.extend({},this.activeObj,{});this.destLeft+=-this.totalPannedPoint.x,this.destTop+=-this.totalPannedPoint.y,this.drawPannImage({x:-this.totalPannedPoint.x,y:-this.totalPannedPoint.y}),this.updateFlipPan(n),this.totalPannedPoint={x:0,y:0}}else this.totalPannedClientPoint={x:-this.totalPannedClientPoint.x,y:-this.totalPannedClientPoint.y},this.totalPannedInternalPoint={x:-this.totalPannedInternalPoint.x,y:-this.totalPannedInternalPoint.y},this.rotatePan(!0),this.totalPannedClientPoint={x:0,y:0},this.totalPannedInternalPoint={x:0,y:0},this.currentPannedPoint={x:0,y:0};this.refreshActiveObj(),this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),a>0?this.zoom(-a):this.zoom(Math.abs(a)),this.cropZoomFactor=this.tempZoomFactor}else{this.isCancelAction=!0,this.objColl=[],this.pointColl=[];var r=this.freehandCounter;this.freehandCounter=0;var h=e.extend({},this.cropObj,{}),l=e.extend([],this.afterCropActions,{},!0);this.setCurrentObj(),this.cropImg(),this.cropObj=h,this.afterCropActions=l,this.objColl=e.extend([],this.cancelObjColl,[],!0),this.pointColl=e.extend([],this.cancelPointColl,[],!0),this.freehandCounter=r,this.iterateObjColl(),this.freehandRedraw(this.lowerContext),this.clearOuterCanvas(this.lowerContext),this.isCircleCrop&&this.cropCircle(this.lowerContext),this.isCancelAction=!1}this.zoomFactor=this.defaultZoomFactor,this.enableDisableToolbarBtn()}else this.refreshActiveObj(),this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height);this.upperCanvas.style.cursor="default",this.currObjType.isCustomCrop=!1,this.tempStrokeSettings={strokeColor:"#fff",fillColor:"",strokeWidth:null},this.callMainToolbar()},l.prototype.freehandDownHandler=function(t,i){this.freehandDrawObj.time=(new Date).getTime(),this.isFreehandDrawing=!0,"mousedown"===t.type?this.freehandDownPoint={x:t.clientX,y:t.clientY}:this.freehandDownPoint={x:t.touches[0].clientX,y:t.touches[0].clientY},this.isFreehandPointMoved=!1,e.EventHandler.add(i,"mousemove touchmove",this.freehandMoveHandler,this)},l.prototype.freehandUpHandler=function(t,i,s){var o=i.getBoundingClientRect();e.EventHandler.remove(i,"mousemove touchmove",this.freehandMoveHandler),0===this.points.length&&("mouseup"===t.type?this.processPoint(t.clientX-o.left,t.clientY-o.top,!0,s):this.isFreehandPointMoved||this.processPoint(this.freehandDownPoint.x-o.left,this.freehandDownPoint.y-o.top,!0,s)),s.closePath();var a=e.extend({},this.cropObj,{},!0),n=this.getCurrentObj();n.objColl=e.extend([],this.objColl,[],!0),n.pointColl=e.extend([],this.pointColl,[],!0),n.afterCropActions=e.extend([],this.afterCropActions,[],!0),this.pointColl[this.freehandCounter]={},this.pointColl[this.freehandCounter].points=e.extend([],this.points),this.pointColl[this.freehandCounter].strokeColor=this.activeObj.strokeSettings.strokeColor,this.pointColl[this.freehandCounter].strokeWidth=this.penStrokeWidth,this.pointColl[this.freehandCounter].flipState=this.currFlipState,this.pointColl[this.freehandCounter].id="pen_"+(this.currentFreehandDrawIndex+1),this.points=[],this.pointCounter=0,this.freehandCounter++,this.currentFreehandDrawIndex++,this.isFreehandDrawing=!1,this.updateUndoRedoColl("freehanddraw",n,n.objColl,n.pointColl,a)},l.prototype.freehandMoveHandler=function(t){this.isFreehandPointMoved=!0;var e,i,s=this.upperCanvas.getBoundingClientRect();"mousemove"===t.type?(e=t.clientX-s.left,i=t.clientY-s.top):(e=t.touches[0].clientX-s.left,i=t.touches[0].clientY-s.top),this.isFreehandDrawing&&this.processPoint(e,i,!1,this.upperContext)},l.prototype.processPoint=function(t,i,s,o){var a,n,r,h,l=this.point(t,i,(new Date).getTime()),c=!!(l=this.points.length>0&&this.points[this.points.length-1])&&this.distanceTo(l)<=5;if(!l||!l||!c||s){if(this.freehandDrawObj.time=(new Date).getTime(),this.points.push({x:t,y:i,ratioX:(t-this.destLeft)/this.destWidth,ratioY:(i-this.destTop)/this.destHeight,time:this.freehandDrawObj.time}),this.points.length>3){a=this.calcCurveControlPoints(this.points[this.pointCounter+0],this.points[this.pointCounter+1],this.points[this.pointCounter+2]).controlPoint2,n=this.calcCurveControlPoints(this.points[this.pointCounter+1],this.points[this.pointCounter+2],this.points[this.pointCounter+3]).controlPoint1,r=this.points[this.pointCounter+1],h=this.points[this.pointCounter+2];var d=.5,p=5;e.isNullOrUndefined(this.penStrokeWidth)||(d=p=this.penStrokeWidth),this.startDraw(o,a,n,r,h,d,p),this.pointCounter++}if(s){a=n=r=h={x:t,y:i,time:(new Date).getTime()};var d=.5,p=5;e.isNullOrUndefined(this.penStrokeWidth)||(d=p=this.penStrokeWidth),this.startDraw(o,a,n,r,h,d,p)}}},l.prototype.calcCurveControlPoints=function(t,e,i){e||(e=t),i||(i=e);var s=t.x-e.x,o=t.y-e.y,a=e.x-i.x,n=e.y-i.y,r={x:(t.x+e.x)/2,y:(t.y+e.y)/2},h={x:(e.x+i.x)/2,y:(e.y+i.y)/2},l=Math.sqrt(s*s+o*o),c=Math.sqrt(a*a+n*n),d=r.x-h.x,p=r.y-h.y,v=c/(l+c),b={x:h.x+d*v,y:h.y+p*v},u=e.x-b.x,C=e.y-b.y;return{controlPoint1:this.point(r.x+u,r.y+C,0),controlPoint2:this.point(h.x+u,h.y+C,0)}},l.prototype.point=function(t,e,i){return this.freehandDrawObj.pointX=t,this.freehandDrawObj.pointY=e,{x:this.freehandDrawObj.pointX,y:this.freehandDrawObj.pointY,time:i}},l.prototype.startDraw=function(t,e,i,s,o,a,n){var r;r=.7*(r=this.pointVelocity(s))+(1-.7)*this.freehandDrawObj.lastVelocity;var h=Math.max(n/1.7,a);this.drawCurve(this.freehandDrawObj.time,h,t,e,i,s,o,n),this.freehandDrawObj.lastVelocity=r,this.freehandDrawObj.time=h},l.prototype.pointVelocity=function(t){return this.freehandDrawObj.time!==t.time?this.distanceTo(t)/(this.freehandDrawObj.time-t.time):0},l.prototype.distanceTo=function(t){return Math.sqrt(Math.pow(this.freehandDrawObj.pointX-t.x,2)+Math.pow(this.freehandDrawObj.pointY-t.y,2))},l.prototype.drawCurve=function(t,e,i,s,o,a,n,r){var h,l,c,d,p,v,b,u,C,f,g=e-t,j=this.bezierLength(s,o,a,n),O=2*Math.ceil(j);for(i.beginPath(),l=0;l<O;l++)p=(d=(c=l/O)*c)*c,C=(u=(b=(v=1-c)*v)*v)*a.x,C+=3*b*c*s.x,C+=3*v*d*o.x,C+=p*n.x,f=u*a.y,f+=3*b*c*s.y,f+=3*v*d*o.y,f+=p*n.y,h=Math.min(t+p*g,r),this.drawArc(C,f,h,i);i.closePath(),i.fill()},l.prototype.bezierLength=function(t,e,i,s){var o,a,n,r,h,l,c,d,p=0;for(o=0;o<=10;o++)a=o/10,n=this.bezierPoint(a,i.x,t.x,e.x,s.x),r=this.bezierPoint(a,i.y,t.y,e.y,s.y),o>0&&(c=n-h,d=r-l,p+=Math.sqrt(c*c+d*d)),h=n,l=r;return p},l.prototype.bezierPoint=function(t,e,i,s,o){return e*(1-t)*(1-t)*(1-t)+3*i*(1-t)*(1-t)*t+3*s*(1-t)*t*t+o*t*t*t},l.prototype.drawArc=function(t,e,i,s){(t>this.destLeft&&e>this.destTop&&t<this.destLeft+this.destWidth&&e<this.destTop+this.destHeight||s!==this.lowerContext&&s!==this.upperContext)&&(s.moveTo(t,e),s.arc(t,e,i,0,2*Math.PI,!1))},l.prototype.freehandRedraw=function(t,i){var s=t.filter;t.filter="none",e.isNullOrUndefined(i)||(this.pointColl[this.freehandCounter]={},this.pointColl[this.freehandCounter].points=i,this.pointColl[this.freehandCounter].strokeColor=this.activeObj.strokeSettings.strokeColor,this.pointColl[this.freehandCounter].strokeWidth=this.penStrokeWidth,this.pointColl[this.freehandCounter].flipState=this.currFlipState,this.freehandCounter++);for(var o=0;o<this.freehandCounter;o++){this.points=e.extend([],this.pointColl[o].points),this.pointCounter=0;var a=this.points.length,n=void 0,r=void 0,h=void 0,l=void 0,c=void 0,d=void 0;a>0&&(t.fillStyle=this.pointColl[o].strokeColor,c=d=this.penStrokeWidth=this.pointColl[o].strokeWidth),1===a&&(n=r=h=l=this.points[0],this.startDraw(t,n,r,h,l,c,d));for(var p=0;p<a-3;p++)this.points[p+1]&&this.points[p+2]&&this.points[p+2]&&(n=this.calcCurveControlPoints(this.points[p+0],this.points[p+1],this.points[p+2]).controlPoint2,r=this.calcCurveControlPoints(this.points[p+1],this.points[p+2],this.points[p+3]).controlPoint1,h=this.points[p+1],l=this.points[p+2],this.startDraw(t,n,r,h,l,c,d));t.closePath()}t.filter=s},l.prototype.redrawImgWithObj=function(){this.lowerContext.filter=this.canvasFilter,this.getCurrentFlipState(),this.isCircleCrop&&this.cropCircle(this.lowerContext);var t=this.lowerContext.filter;this.lowerContext.filter=this.getDefaultFilter(),this.iterateObjColl(),this.freehandRedraw(this.lowerContext),this.lowerContext.filter=t},l.prototype.refreshToolbar=function(t,i,s,o,a){if(this.isImageLoaded){var n={toolbarType:t};switch("filter"!==t&&"color"!==t&&(document.getElementById(this.element.id+"_toolbar")&&this.defToolbarItems.length>0&&e.getComponent(document.getElementById(this.element.id+"_toolbar"),"toolbar").destroy(),document.getElementById(this.element.id+"_bottomToolbar")&&this.defToolbarItems.length>0&&document.getElementById(this.element.id+"_bottomToolbar").className.indexOf("e-control")>-1&&e.getComponent(document.getElementById(this.element.id+"_bottomToolbar"),"toolbar").destroy()),this.refreshSlider(),t){case"main":e.Browser.isDevice?s?this.initToolbarItem(!1,!0,!0):this.initToolbarItem(!1,!0,null):e.Browser.isDevice&&!o||this.initToolbarItem(i,e.Browser.isDevice,null),e.Browser.isDevice&&this.initBottomToolbar();break;case"shapes":e.Browser.isDevice&&this.initToolbarItem(!1,!0,!0),"line"===this.activeObj.shape?n.toolbarItems=["strokeColor","strokeWidth"]:n.toolbarItems=["fillColor","strokeColor","strokeWidth"],this.trigger("toolbarUpdating",n),this.initShapesToolbarItem(n.toolbarItems);break;case"text":e.Browser.isDevice&&this.initToolbarItem(!1,!0,!0),n.toolbarItems=["fontFamily","fontStyle","fontSize","fontColor"],this.trigger("toolbarUpdating",n),this.initTextToolbarItem(n.toolbarItems);break;case"pen":e.Browser.isDevice&&this.initToolbarItem(!1,!0,!0),n.toolbarItems=["strokeColor","strokeWidth"],this.trigger("toolbarUpdating",n),this.initPenToolbarItem(n.toolbarItems);break;case"pan":this.initZoomToolbarItem();break;case"adjustment":e.Browser.isDevice&&this.initToolbarItem(!1,!0,!0),this.initAdjustmentToolbarItem();break;case"filter":this.updateContextualToolbar(t);break;case"color":this.updateContextualToolbar(t,a)}this.refreshDropDownBtn(s)}},l.prototype.getAdjustmentToolbarItem=function(){var t=[];(e.isNullOrUndefined(this.toolbar)||!e.isNullOrUndefined(this.toolbar)&&this.toolbar.indexOf("Brightness")>-1)&&t.push({id:this.element.id+"_brightness",prefixIcon:"e-icons e-brightness",cssClass:"top-icon e-brightness",tooltipText:this.l10n.getConstant("Brightness"),align:"Center"}),(e.isNullOrUndefined(this.toolbar)||!e.isNullOrUndefined(this.toolbar)&&this.toolbar.indexOf("Contrast")>-1)&&t.push({id:this.element.id+"_contrast",prefixIcon:"e-icons e-contrast",cssClass:"top-icon e-contrast",tooltipText:this.l10n.getConstant("Contrast"),align:"Center"}),(e.isNullOrUndefined(this.toolbar)||!e.isNullOrUndefined(this.toolbar)&&this.toolbar.indexOf("Hue")>-1)&&t.push({id:this.element.id+"_hue",prefixIcon:"e-icons e-fade",cssClass:"top-icon e-fade",tooltipText:this.l10n.getConstant("Hue"),align:"Center"}),(e.isNullOrUndefined(this.toolbar)||!e.isNullOrUndefined(this.toolbar)&&this.toolbar.indexOf("Saturation")>-1)&&t.push({id:this.element.id+"_saturation",prefixIcon:"e-icons e-saturation",cssClass:"top-icon e-saturation",tooltipText:this.l10n.getConstant("Saturation"),align:"Center"}),(e.isNullOrUndefined(this.toolbar)||!e.isNullOrUndefined(this.toolbar)&&this.toolbar.indexOf("Exposure")>-1)&&t.push({id:this.element.id+"_exposure",prefixIcon:"e-icons e-grain",cssClass:"top-icon e-grain",tooltipText:this.l10n.getConstant("Exposure"),align:"Center"}),(e.isNullOrUndefined(this.toolbar)||!e.isNullOrUndefined(this.toolbar)&&this.toolbar.indexOf("Opacity")>-1)&&t.push({id:this.element.id+"_opacity",prefixIcon:"e-icons e-opacity",cssClass:"top-icon e-opacity",tooltipText:this.l10n.getConstant("Opacity"),align:"Center"}),(e.isNullOrUndefined(this.toolbar)||!e.isNullOrUndefined(this.toolbar)&&this.toolbar.indexOf("Blur")>-1)&&t.push({id:this.element.id+"_blur",prefixIcon:"e-icons e-tint",cssClass:"top-icon e-tint",tooltipText:this.l10n.getConstant("Blur"),align:"Center"});for(var i=this.processToolbar("center"),s=0,o=i.length;s<o;s++)t.push(i[s]);return e.Browser.isDevice||(t.push({id:this.element.id+"_ok",prefixIcon:"e-icons e-check",cssClass:"top-icon e-tick",tooltipText:this.l10n.getConstant("OK"),align:"Right"}),t.push({id:this.element.id+"_cancel",prefixIcon:"e-icons e-close",cssClass:"top-icon e-save",tooltipText:this.l10n.getConstant("Cancel"),align:"Right"})),t},l.prototype.getFilterToolbarItem=function(){var t=[];(e.isNullOrUndefined(this.toolbar)||!e.isNullOrUndefined(this.toolbar)&&this.toolbar.indexOf("Default")>-1)&&t.push({id:this.element.id+"_default",prefixIcon:"e-icons e-none",cssClass:"top-icon e-none",tooltipText:this.l10n.getConstant("Default"),align:"Center",template:'<div class="filterwrapper" style="box-sizing: content-box;"><canvas id='+this.element.id+'_defaultCanvas></canvas><div style="text-align:center;"><span>'+this.l10n.getConstant("Default")+"</span></div></div>"}),(e.isNullOrUndefined(this.toolbar)||!e.isNullOrUndefined(this.toolbar)&&this.toolbar.indexOf("Chrome")>-1)&&t.push({id:this.element.id+"_chrome",prefixIcon:"e-icons e-none",cssClass:"top-icon e-none",tooltipText:this.l10n.getConstant("Chrome"),align:"Center",template:'<div class="filterwrapper" style="box-sizing: content-box;"><canvas id='+this.element.id+'_chromeCanvas></canvas><div style="text-align:center;"><span>'+this.l10n.getConstant("Chrome")+"</span></div></div>"}),(e.isNullOrUndefined(this.toolbar)||!e.isNullOrUndefined(this.toolbar)&&this.toolbar.indexOf("Cold")>-1)&&t.push({id:this.element.id+"_cold",prefixIcon:"e-icons e-none",cssClass:"top-icon e-none",tooltipText:this.l10n.getConstant("Cold"),align:"Center",template:'<div class="filterwrapper" style="box-sizing: content-box;"><canvas id='+this.element.id+'_coldCanvas></canvas><div style="text-align:center;"><span>'+this.l10n.getConstant("Cold")+"</span></div></div>"}),(e.isNullOrUndefined(this.toolbar)||!e.isNullOrUndefined(this.toolbar)&&this.toolbar.indexOf("Warm")>-1)&&t.push({id:this.element.id+"_warm",prefixIcon:"e-icons e-none",cssClass:"top-icon e-none",tooltipText:this.l10n.getConstant("Warm"),align:"Center",template:'<div class="filterwrapper" style="box-sizing: content-box;"><canvas id='+this.element.id+'_warmCanvas></canvas><div style="text-align:center;"><span>'+this.l10n.getConstant("Warm")+"</span></div></div>"}),(e.isNullOrUndefined(this.toolbar)||!e.isNullOrUndefined(this.toolbar)&&this.toolbar.indexOf("Grayscale")>-1)&&t.push({id:this.element.id+"_grayscale",prefixIcon:"e-icons e-none",cssClass:"top-icon e-none",tooltipText:this.l10n.getConstant("Grayscale"),align:"Center",template:'<div class="filterwrapper" style="box-sizing: content-box;"><canvas id='+this.element.id+'_grayscaleCanvas></canvas><div style="text-align:center;"><span>'+this.l10n.getConstant("Grayscale")+"</span></div></div>"}),(e.isNullOrUndefined(this.toolbar)||!e.isNullOrUndefined(this.toolbar)&&this.toolbar.indexOf("Sepia")>-1)&&t.push({id:this.element.id+"_sepia",prefixIcon:"e-icons e-none",cssClass:"top-icon e-none",tooltipText:this.l10n.getConstant("Sepia"),align:"Center",template:'<div class="filterwrapper" style="box-sizing: content-box;"><canvas id='+this.element.id+'_sepiaCanvas></canvas><div style="text-align:center;"><span>'+this.l10n.getConstant("Sepia")+"</span></div></div>"}),(e.isNullOrUndefined(this.toolbar)||!e.isNullOrUndefined(this.toolbar)&&this.toolbar.indexOf("Invert")>-1)&&t.push({id:this.element.id+"_invert",prefixIcon:"e-icons e-none",cssClass:"top-icon e-none",tooltipText:this.l10n.getConstant("Invert"),align:"Center",template:'<div class="filterwrapper" style="box-sizing: content-box;"><canvas id='+this.element.id+'_invertCanvas></canvas><div style="text-align:center;"><span>'+this.l10n.getConstant("Invert")+"</span></div></div>"});for(var i=this.processToolbar("center"),s=0,o=i.length;s<o;s++)t.push(i[s]);return t},l.prototype.getPenToolbarItem=function(t){var i=[];t.indexOf("strokeColor")>-1&&i.push({prefixIcon:"e-icons e-copy",id:this.element.id+"_pen_strokecolor",cssClass:"top-icon e-pen-stroke-color",tooltipText:this.l10n.getConstant("StrokeColor"),align:"Center",type:"Input",template:'<button id="'+this.element.id+'_penColorBtn"></button>'}),t.indexOf("strokeWidth")>-1&&i.push({prefixIcon:"e-icons e-copy",cssClass:"top-icon e-size",tooltipText:this.l10n.getConstant("StrokeWidth"),align:"Center",type:"Input",template:'<button id="'+this.element.id+'_penStrokeWidth"></button>'});for(var s=this.processSubToolbar(t),o=0,a=s.length;o<a;o++)i.push(s[o]);return e.Browser.isDevice||(i.push({id:this.element.id+"_ok",prefixIcon:"e-icons e-check",cssClass:"top-icon e-tick",tooltipText:this.l10n.getConstant("OK"),align:"Right"}),i.push({id:this.element.id+"_cancel",prefixIcon:"e-icons e-close",cssClass:"top-icon e-save",tooltipText:this.l10n.getConstant("Cancel"),align:"Right"})),i},l.prototype.initPenToolbarItem=function(t){var s=this,o=this.getLeftToolbarItem(),a=this.getRightToolbarItem(),n=this.getPenToolbarItem(t),r=this.getZoomToolbarItem();e.Browser.isDevice?this.defToolbarItems=n:this.defToolbarItems=o.concat(r,n,a);var h=new i.Toolbar({width:"100%",items:this.defToolbarItems,clicked:this.defToolbarClicked.bind(this),created:function(){s.createPenColor(t),s.createPenBtn(t),e.Browser.isDevice||s.renderSaveBtn(),s.trigger("toolbarCreated",{toolbarType:"pen"}),e.Browser.isDevice?s.defToolbarItems.length>0&&!e.isNullOrUndefined(document.getElementById(s.element.id+"_toolbar"))&&h.refreshOverflow():(s.createLeftToolbarControls(),s.defToolbarItems.length>0&&!e.isNullOrUndefined(document.getElementById(s.element.id+"_toolbar"))&&h.refreshOverflow())}});e.Browser.isDevice?h.appendTo("#"+this.element.id+"_bottomToolbar"):h.appendTo("#"+this.element.id+"_toolbar"),this.enableDisableToolbarBtn()},l.prototype.createPenColor=function(t){var i=this,a=this;if(t.indexOf("strokeColor")>-1){this.element.querySelector(".e-template.e-pen-stroke-color").appendChild(this.createElement("input",{id:this.element.id+"_pen_stroke"}));var n=new o.ColorPicker({modeSwitcher:!1,value:"#fff",showButtons:!1,mode:"Palette",cssClass:"e-pen-color",change:function(t){var s=e.extend([],i.pointColl,[],!0);i.updateFreehandDrawColorChange();var o=e.extend({},i.cropObj,{},!0),n=i.getCurrentObj();n.objColl=e.extend([],i.objColl,[],!0),n.pointColl=e.extend([],i.pointColl,[],!0),n.afterCropActions=e.extend([],i.afterCropActions,[],!0),i.pointColl=s,a.isFreehandDrawCustomized=!0,a.activeObj.strokeSettings.strokeColor=a.selectedFreehandColor=t.currentValue.hex,i.isFreehandDrawEditing?(i.upperContext.clearRect(0,0,i.upperCanvas.width,i.upperCanvas.height),i.pointColl[i.freehandDrawSelectedIndex].strokeColor=t.currentValue.hex,i.hoverFreehandraw(t.currentValue.hex),i.updateUndoRedoColl("freehanddrawCustomized",n,n.objColl,n.pointColl,o)):a.togglePen||a.redrawShape(i.activeObj),r.element.children[0].style.backgroundColor=t.currentValue.rgba,r.toggle()}},"#"+this.element.id+"_pen_stroke"),r=new s.DropDownButton({open:function(t){e.Browser.isDevice&&(t.element.parentElement.style.top=r.element.getBoundingClientRect().top-t.element.parentElement.offsetHeight+"px",t.element.parentElement.style.left=i.element.offsetLeft+"px")},target:".e-pen-color",iconCss:"e-dropdownbtn-preview"},"#"+this.element.id+"_penColorBtn");n.inline=!0,!e.isNullOrUndefined(this.freehandDrawSelectedIndex)&&this.freehandDrawSelectedIndex>-1?this.element.querySelector(".e-pen-stroke-color.e-template .e-dropdownbtn-preview").style.background="#42a5f5"===this.selectedFreehandColor?this.tempFreeHandDrawEditingStyles.strokeColor:this.pointColl[this.freehandDrawSelectedIndex].strokeColor:this.element.querySelector(".e-pen-stroke-color.e-template .e-dropdownbtn-preview").style.background="#fff"}},l.prototype.createPenBtn=function(t){var i=this,o=[{id:"1",text:this.l10n.getConstant("XSmall")},{id:"2",text:this.l10n.getConstant("Small")},{id:"3",text:this.l10n.getConstant("Medium")},{id:"4",text:this.l10n.getConstant("Large")},{id:"5",text:this.l10n.getConstant("XLarge")}];if(t.indexOf("strokeWidth")>-1){var a=document.getElementById(this.element.id+"_penStrokeWidth"),n=document.createElement("span");!e.isNullOrUndefined(this.freehandDrawSelectedIndex)&&this.freehandDrawSelectedIndex>-1?n.innerHTML=this.getPenStroke(this.pointColl[this.freehandDrawSelectedIndex].strokeWidth):n.innerHTML=this.l10n.getConstant("Small"),n.className="e-pen-stroke-width",a.appendChild(n);var r=new s.DropDownButton({items:o,open:function(t){e.Browser.isDevice&&(t.element.parentElement.style.top=r.element.getBoundingClientRect().top-t.element.parentElement.offsetHeight+"px");var i=n.innerHTML;t.element.querySelector('[aria-label = "'+i+'"]').classList.add("e-selected-btn")},select:function(t){var s=e.extend([],i.pointColl,[],!0);i.updateFreehandDrawColorChange();var o=e.extend({},i.cropObj,{},!0),a=i.getCurrentObj();a.objColl=e.extend([],i.objColl,[],!0),a.pointColl=e.extend([],i.pointColl,[],!0),a.afterCropActions=e.extend([],i.afterCropActions,[],!0),i.pointColl=s,i.isFreehandDrawCustomized=!0,n.textContent=t.item.text,i.setPenStroke(t.item.id),i.isFreehandDrawEditing&&(i.upperContext.clearRect(0,0,i.upperCanvas.width,i.upperCanvas.height),i.hoverFreehandraw(null,i.penStrokeWidth),i.pointColl[i.freehandDrawSelectedIndex].strokeWidth=i.penStrokeWidth,i.updateUndoRedoColl("freehanddrawCustomized",a,a.objColl,a.pointColl,o)),e.Browser.isDevice?e.isNullOrUndefined(document.getElementById(i.element.id+"_bottomToolbar"))||e.getComponent(i.element.id+"_bottomToolbar","toolbar").refreshOverflow():e.isNullOrUndefined(document.getElementById(i.element.id+"_toolbar"))||e.getComponent(i.element.id+"_toolbar","toolbar").refreshOverflow()}});r.appendTo("#"+this.element.id+"_penStrokeWidth")}},l.prototype.updateFreehandDrawColorChange=function(){e.isNullOrUndefined(this.freehandDrawSelectedIndex)||e.isNullOrUndefined(this.pointColl[this.freehandDrawSelectedIndex])||"#42a5f5"!==this.pointColl[this.freehandDrawSelectedIndex].strokeColor||(this.pointColl[this.freehandDrawSelectedIndex].strokeColor=this.tempFreeHandDrawEditingStyles.strokeColor)},l.prototype.setPenStroke=function(t){switch(parseInt(t,10)){case 1:this.penStrokeWidth=1;break;case 2:this.penStrokeWidth=2;break;case 3:this.penStrokeWidth=3;break;case 4:this.penStrokeWidth=4;break;case 5:this.penStrokeWidth=5}},l.prototype.getPenStroke=function(t){var e="";return 1===t?e=this.l10n.getConstant("XSmall"):2===t?e=this.l10n.getConstant("Small"):3===t?e=this.l10n.getConstant("Medium"):4===t?e=this.l10n.getConstant("Large"):5===t&&(e=this.l10n.getConstant("XLarge")),e},l.prototype.initAdjustmentToolbarItem=function(){var t=this,s=this.getLeftToolbarItem(null),o=this.getRightToolbarItem(),a=this.getAdjustmentToolbarItem(),n=this.getZoomToolbarItem();e.Browser.isDevice?this.defToolbarItems=a:this.defToolbarItems=s.concat(n,a,o);var r=new i.Toolbar({width:"100%",items:this.defToolbarItems,clicked:this.defToolbarClicked.bind(this),created:function(){e.Browser.isDevice||t.renderSaveBtn(),e.Browser.isDevice?t.defToolbarItems.length>0&&!e.isNullOrUndefined(document.getElementById(t.element.id+"_toolbar"))&&r.refreshOverflow():(t.createLeftToolbarControls(),t.defToolbarItems.length>0&&!e.isNullOrUndefined(document.getElementById(t.element.id+"_toolbar"))&&r.refreshOverflow())}});e.Browser.isDevice?r.appendTo("#"+this.element.id+"_bottomToolbar"):r.appendTo("#"+this.element.id+"_toolbar"),this.enableDisableToolbarBtn()},l.prototype.initFilterToolbarItem=function(){var t=this,s=this.getFilterToolbarItem();document.querySelector("#"+this.element.id+"_contextualToolbar").classList.contains("e-control")&&e.getComponent(document.getElementById(this.element.id+"_contextualToolbar"),"toolbar").destroy();var o=new i.Toolbar({width:"100%",items:s,clicked:this.contextualToolbarClicked.bind(this),created:function(){t.createCanvasFilter(),""===t.currentFilter&&(t.currentFilter=t.element.id+"_default");var e=document.querySelector("#"+t.element.id+"_headWrapper");e&&(e.style.display="none"),document.getElementById(t.currentFilter+"Canvas").parentElement.parentElement.classList.add("e-selected"),t.enableDisableToolbarBtn(),o.refreshOverflow()}});o.appendTo("#"+this.element.id+"_contextualToolbar")},l.prototype.getCurrentCanvasData=function(){var t=this.lowerContext.filter;this.lowerContext.filter="none";var i=e.extend([],this.objColl,null,!0);this.objColl=[],this.renderImage();var s=this.lowerContext.getImageData(this.destLeft,this.destTop,this.destWidth,this.destHeight);return this.objColl=i,this.iterateObjColl(),this.lowerContext.filter=t,s},l.prototype.createCanvasFilter=function(){var t=this.getCurrentCanvasData();this.inMemoryCanvas.width=t.width,this.inMemoryCanvas.height=t.height,this.inMemoryContext.putImageData(t,0,0);var e=document.querySelector("#"+this.element.id+"_defaultCanvas"),i=e.getContext("2d");e.style.width="100px",e.style.height="100px",i.filter=this.updateAdjustment("default",null,!0),i.drawImage(this.inMemoryCanvas,0,0,300,150);var s=document.querySelector("#"+this.element.id+"_chromeCanvas");i=s.getContext("2d"),s.style.width="100px",s.style.height="100px",i.filter=this.updateAdjustment("chrome",null,!0),i.drawImage(this.inMemoryCanvas,0,0,300,150);var o=document.querySelector("#"+this.element.id+"_coldCanvas");i=o.getContext("2d"),o.style.width="100px",o.style.height="100px",i.filter=this.updateAdjustment("cold",null,!0),i.drawImage(this.inMemoryCanvas,0,0,300,150);var a=document.querySelector("#"+this.element.id+"_warmCanvas");i=a.getContext("2d"),a.style.width="100px",a.style.height="100px",i.filter=this.updateAdjustment("warm",null,!0),i.drawImage(this.inMemoryCanvas,0,0,300,150);var n=document.querySelector("#"+this.element.id+"_grayscaleCanvas");i=n.getContext("2d"),n.style.width="100px",n.style.height="100px",i.filter=this.updateAdjustment("grayscale",null,!0),i.drawImage(this.inMemoryCanvas,0,0,300,150);var r=document.querySelector("#"+this.element.id+"_sepiaCanvas");i=r.getContext("2d"),r.style.width="100px",r.style.height="100px",i.filter=this.updateAdjustment("sepia",null,!0),i.drawImage(this.inMemoryCanvas,0,0,300,150);var h=document.querySelector("#"+this.element.id+"_invertCanvas");i=h.getContext("2d"),h.style.width="100px",h.style.height="100px",i.filter=this.updateAdjustment("invert",null,!0),i.drawImage(this.inMemoryCanvas,0,0,300,150)},l.prototype.callUpdateCurrentTransformedState=function(){var t=e.extend([],this.objColl,[],!0),i=e.extend({},this.activeObj,{},!0);this.objColl=[],this.refreshActiveObj(),this.isRotateZoom=!0,this.updateCurrentTransformedState("initial"),0===this.degree&&this.rotateFlipColl.length>0&&(this.destLeft+=this.totalPannedPoint.x,this.destTop+=this.totalPannedPoint.y),this.destLeft+=this.totalPannedInternalPoint.x,this.destTop+=this.totalPannedInternalPoint.y;var s=this.lowerContext.filter;0===this.degree&&this.setDestPointsForFlipState(),this.updateBrightnessFilter(),this.lowerContext.drawImage(this.baseImg,this.srcLeft,this.srcTop,this.srcWidth,this.srcHeight,this.destLeft,this.destTop,this.destWidth,this.destHeight),this.updateCurrentTransformedState("reverse"),0===this.degree&&this.rotateFlipColl.length>0&&(this.destLeft+=this.totalPannedPoint.x,this.destTop+=this.totalPannedPoint.y),this.isRotateZoom=!1,this.objColl=t;var o=this.togglePen;this.togglePen=!1,this.lowerContext.filter="none",this.iterateObjColl(),this.destLeft+=this.totalPannedInternalPoint.x,this.destTop+=this.totalPannedInternalPoint.y,this.freehandRedraw(this.lowerContext),this.destLeft-=this.totalPannedInternalPoint.x,this.destTop-=this.totalPannedInternalPoint.y,this.togglePen=o,this.lowerContext.filter=s,this.activeObj=i},l.prototype.updateCurrentTransformedState=function(t,i,s){this.rotateFlipColl.length>0&&("initial"===t&&(this.reverseTransformedState(),e.isNullOrUndefined(i)&&this.setDestinationPoints()),this.currentTransformedState(t,null,null,s)),(this.isCircleCrop||!e.isNullOrUndefined(this.currSelectionPoint)&&"crop-circle"===this.currSelectionPoint.shape)&&(s&&(this.destLeft+=this.totalPannedClientPoint.x,this.destTop+=this.totalPannedClientPoint.y),this.cropCircle(this.lowerContext),s&&(this.destLeft-=this.totalPannedClientPoint.x,this.destTop-=this.totalPannedClientPoint.y))},l.prototype.reverseTransformedState=function(){this.lowerContext.setTransform(1,0,0,1,0,0)},l.prototype.currentTransformedState=function(t,i,s,o){s=s||this.lowerContext,"initial"===t?this.iterateRotateFlipColl(s,t):"reverse"===t&&(this.iterateRotateFlipColl(s,t),this.setClientTransformedDimension(i),(this.isCircleCrop||!e.isNullOrUndefined(this.currSelectionPoint)&&"crop-circle"===this.currSelectionPoint.shape&&e.isNullOrUndefined(o))&&(o&&(this.destLeft+=this.totalPannedClientPoint.x,this.destTop+=this.totalPannedClientPoint.y),this.cropCircle(this.lowerContext),o&&(this.destLeft-=this.totalPannedClientPoint.x,this.destTop-=this.totalPannedClientPoint.y)))},l.prototype.iterateRotateFlipColl=function(t,e){if("initial"===e)for(i=0;i<this.rotateFlipColl.length;i++)this.setTransform(t,this.rotateFlipColl[i]);else if("reverse"===e)for(var i=this.rotateFlipColl.length-1;i>=0;i--)this.setTransform(t,this.rotateFlipColl[i],!0)},l.prototype.setTransform=function(t,i,s){switch(s&&90===i?i=-90:s&&-90===i&&(i=90),"horizontal"===i&&this.degree%90==0&&this.degree%180!=0?i="vertical":"vertical"===i&&this.degree%90==0&&this.degree%180!=0&&(i="horizontal"),this.isReverseRotate=this.isReverseFlip=!0,e.isNullOrUndefined(s)&&t.clearRect(0,0,t.canvas.width,t.canvas.height),i){case 90:case-90:t.translate(t.canvas.width/2,t.canvas.height/2),t.rotate(Math.PI/180*i),t.translate(-t.canvas.width/2,-t.canvas.height/2);break;case"horizontal":t.translate(t.canvas.width,0),t.scale(-1,1);break;case"vertical":t.translate(0,t.canvas.height),t.scale(1,-1)}this.isReverseRotate=this.isReverseFlip=!1},l.prototype.isObjInsideCropRegion=function(t){var e=!1;return t.activePoint.startX>=this.destLeft&&t.activePoint.endX<=this.destLeft+this.destWidth?e=!0:t.activePoint.startX<=this.destLeft&&t.activePoint.endX>=this.destLeft?e=!0:t.activePoint.startX<=this.destLeft+this.destWidth&&t.activePoint.endX>=this.destLeft+this.destWidth?e=!0:t.activePoint.startY>=this.destTop&&t.activePoint.endY<=this.destTop+this.destHeight?e=!0:t.activePoint.startY<=this.destTop&&t.activePoint.endY>=this.destTop?e=!0:t.activePoint.startY<=this.destTop+this.destHeight&&t.activePoint.endY>=this.destTop+this.destHeight&&(e=!0),e},l.prototype.panFreehandDrawColl=function(t,i,s){for(var o=0;o<this.freehandCounter;o++){this.points=e.extend([],this.pointColl[o].points,[]),this.pointCounter=0;for(var a=this.points.length,n=0;n<a;n++)""===s||"vertical"===s?this.points[n].x+=t:this.points[n].x-=t,""===s||"horizontal"===s?this.points[n].y+=i:this.points[n].y-=i}this.freehandRedraw(this.lowerContext)},l.prototype.panObjColl=function(t,e,i){for(var s=0;s<this.objColl.length;s++){""===i||"vertical"===i?(this.objColl[s].activePoint.startX+=t,this.objColl[s].activePoint.endX+=t):(this.objColl[s].activePoint.startX-=t,this.objColl[s].activePoint.endX-=t),""===i||"horizontal"===i?(this.objColl[s].activePoint.startY+=e,this.objColl[s].activePoint.endY+=e):(this.objColl[s].activePoint.startY-=e,this.objColl[s].activePoint.endY-=e),this.objColl[s].activePoint.width=this.objColl[s].activePoint.endX-this.objColl[s].activePoint.startX,this.objColl[s].activePoint.height=this.objColl[s].activePoint.endY-this.objColl[s].activePoint.startY,this.updateActiveObject(this.objColl[s].activePoint,this.objColl[s]);var o=this.lowerContext.filter;this.lowerContext.filter="none",this.apply(this.objColl[s].shape,this.objColl[s]),this.lowerContext.filter=o,this.refreshActiveObj()}},l.prototype.cropObjColl=function(){if(this.objColl.length>0)for(var t=0;t<this.objColl.length;t++)this.objColl[t].imageRatio={startX:(this.objColl[t].activePoint.startX-this.activeObj.activePoint.startX)/this.activeObj.activePoint.width,startY:(this.objColl[t].activePoint.startY-this.activeObj.activePoint.startY)/this.activeObj.activePoint.height,endX:(this.objColl[t].activePoint.endX-this.activeObj.activePoint.startX)/this.activeObj.activePoint.width,endY:(this.objColl[t].activePoint.endY-this.activeObj.activePoint.startY)/this.activeObj.activePoint.height,width:this.activeObj.activePoint.width/this.objColl[t].activePoint.width,height:this.activeObj.activePoint.height/this.objColl[t].activePoint.height},"text"===this.objColl[t].shape&&(this.objColl[t].textSettings.fontRatio=this.objColl[t].activePoint.width/this.objColl[t].textSettings.fontSize)},l.prototype.cropFreehandDrawColl=function(){for(var t=0;t<this.freehandCounter;t++){this.points=e.extend([],this.pointColl[t].points,[]),this.pointCounter=0;for(var i=this.points.length,s=0;s<i;s++)this.points[s].ratioX=(this.points[s].x-this.activeObj.activePoint.startX)/this.activeObj.activePoint.width,this.points[s].ratioY=(this.points[s].y-this.activeObj.activePoint.startY)/this.activeObj.activePoint.height}},l.prototype.hoverFreehandraw=function(t,i){var s=this.upperContext,o=-1;o=this.freehandDrawHoveredIndex>-1?this.freehandDrawHoveredIndex:this.freehandDrawSelectedIndex,this.points=e.extend([],this.pointColl[o].points),this.pointCounter=0;var a,n,r,h,l=this.points.length,c=0,d=0;s.fillStyle=t||"#42a5f5",s.strokeStyle="#fff",c=d=this.penStrokeWidth=i||this.pointColl[o].strokeWidth,1===l&&(a=n=r=h=this.points[0],this.startDraw(s,a,n,r,h,c,d));for(var p=0;p<l-3;p++)this.points[p+1]&&this.points[p+2]&&this.points[p+2]&&(a=this.calcCurveControlPoints(this.points[p+0],this.points[p+1],this.points[p+2]).controlPoint2,n=this.calcCurveControlPoints(this.points[p+1],this.points[p+2],this.points[p+3]).controlPoint1,r=this.points[p+1],h=this.points[p+2],this.startDraw(s,a,n,r,h,c,d));s.closePath()},l.prototype.pointsHorizontalFlip=function(){for(var t=0;t<this.freehandCounter;t++)if(this.pointColl[t].shapeFlip!==this.currFlipState){this.points=e.extend([],this.pointColl[t].points,[]),this.pointCounter=0;for(var i=this.points.length,s=0;s<i;s++)this.points[s].x<=this.destLeft+this.destWidth/2?this.points[s].x=this.destLeft+this.destWidth-(this.points[s].x-this.destLeft):this.points[s].x>=this.destLeft+this.destWidth/2&&(this.points[s].x=this.destLeft+(this.destLeft+this.destWidth-this.points[s].x)),this.points[s].ratioX=(this.points[s].x-this.destLeft)/this.destWidth,this.points[s].ratioY=(this.points[s].y-this.destTop)/this.destHeight;this.pointColl[t].shapeFlip=this.currFlipState}},l.prototype.pointsVerticalFlip=function(){for(var t=0;t<this.freehandCounter;t++)if(this.pointColl[t].shapeFlip!==this.currFlipState){this.points=e.extend([],this.pointColl[t].points,[]),this.pointCounter=0;for(var i=this.points.length,s=0;s<i;s++)this.points[s].y<=this.destTop+this.destHeight/2?this.points[s].y=this.destTop+this.destHeight-(this.points[s].y-this.destTop):this.points[s].y>=this.destTop+this.destHeight/2&&(this.points[s].y=this.destTop+(this.destTop+this.destHeight-this.points[s].y)),this.points[s].ratioX=(this.points[s].x-this.destLeft)/this.destWidth,this.points[s].ratioY=(this.points[s].y-this.destTop)/this.destHeight;this.pointColl[t].shapeFlip=this.currFlipState}},l.prototype.flipFreehandrawColl=function(t){if("horizontal"===t.toLowerCase())this.pointsHorizontalFlip();else if("vertical"===t.toLowerCase())this.pointsVerticalFlip();else{this.pointsHorizontalFlip();for(var e=0;e<this.freehandCounter;e++)this.pointColl[e].shapeFlip="";this.pointsVerticalFlip()}},l.prototype.rotateFreehandDrawColl=function(){for(s=0;s<this.freehandCounter;s++){this.points=e.extend([],this.pointColl[s].points,[]),this.pointCounter=0;for(var t=this.points.length,i=0;i<t;i++)this.points[i].y=this.destTop+this.destHeight*this.points[i].ratioX,this.points[i].x=this.destLeft+this.destWidth-this.destWidth*this.points[i].ratioY}for(var s=0;s<this.freehandCounter;s++){this.points=e.extend([],this.pointColl[s].points,[]),this.pointCounter=0;for(var t=this.points.length,i=0;i<t;i++)this.points[i].ratioX=(this.points[i].x-this.destLeft)/this.destWidth,this.points[i].ratioY=(this.points[i].y-this.destTop)/this.destHeight}},l.prototype.zoomFreehandDrawColl=function(t){for(var i=0;i<this.freehandCounter;i++){this.points=e.extend([],this.pointColl[i].points,[]),this.pointCounter=0;for(var s=this.points.length,o=0;o<s;o++)this.points[o].x=this.zoomX(this.points[o].ratioX),this.points[o].y=this.zoomY(this.points[o].ratioY)}e.isNullOrUndefined(t)&&this.freehandRedraw(this.lowerContext)},l.prototype.zoomX=function(t){return t*this.destWidth+this.destLeft},l.prototype.zoomY=function(t){return t*this.destHeight+this.destTop},l.prototype.zoomObjColl=function(t){for(var i=0;i<this.objColl.length;i++)if(this.objColl[i].activePoint.startX=this.objColl[i].imageRatio.startX*this.destWidth+this.destLeft,this.objColl[i].activePoint.startY=this.objColl[i].imageRatio.startY*this.destHeight+this.destTop,this.objColl[i].activePoint.endX=this.objColl[i].imageRatio.endX*this.destWidth+this.destLeft,this.objColl[i].activePoint.endY=this.objColl[i].imageRatio.endY*this.destHeight+this.destTop,this.objColl[i].activePoint.width=this.objColl[i].activePoint.endX-this.objColl[i].activePoint.startX,this.objColl[i].activePoint.height=this.objColl[i].activePoint.endY-this.objColl[i].activePoint.startY,"text"===this.objColl[i].shape&&this.updateFontSize(this.objColl[i]),this.updateActiveObject(this.objColl[i].activePoint,this.objColl[i]),e.isNullOrUndefined(t)){var s=this.lowerContext.filter;this.lowerContext.filter="none",this.apply(this.objColl[i].shape,this.objColl[i]),this.refreshActiveObj(),this.lowerContext.filter=s}},l.prototype.calcRatio=function(){var t,e;return 0===this.degree||this.degree%180==0?(t=this.baseImg.width/this.destWidth,e=this.baseImg.height/this.destHeight):(t=this.baseImg.height/this.destWidth,e=this.baseImg.width/this.destHeight),{width:t,height:e}},l.prototype.drawCustomSelection=function(t){this.currObjType.isCustomCrop=!0,this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),this.currObjType.shape=this.activeObj.shape=t.toLowerCase(),0===this.zoomFactor?this.destLeft>=0&&this.destTop>=0?(this.activeObj.activePoint.startX=this.destLeft,this.activeObj.activePoint.startY=this.destTop,this.activeObj.activePoint.endX=this.destLeft+this.destWidth,this.activeObj.activePoint.endY=this.destTop+this.destHeight):this.destLeft>=0?(this.activeObj.activePoint.startX=this.destLeft,this.activeObj.activePoint.startY=7.5,this.activeObj.activePoint.endX=this.destLeft+this.destWidth,this.activeObj.activePoint.endY=this.lowerCanvas.height-15):this.destTop>=0?(this.activeObj.activePoint.startX=7.5,this.activeObj.activePoint.startY=this.destTop,this.activeObj.activePoint.endX=this.lowerCanvas.width-15,this.activeObj.activePoint.endY=this.destTop+this.destHeight):(this.activeObj.activePoint.startX=7.5,this.activeObj.activePoint.startY=7.5,this.activeObj.activePoint.endX=this.lowerCanvas.width-15,this.activeObj.activePoint.endY=this.lowerCanvas.height-15):(this.destLeft>0?this.activeObj.activePoint.startX=this.destLeft:this.activeObj.activePoint.startX=7.5,this.destTop>0?this.activeObj.activePoint.startY=this.destTop:this.activeObj.activePoint.startY=7.5,this.destLeft+this.destWidth+15<this.lowerCanvas.width?this.activeObj.activePoint.endX=this.destLeft+this.destWidth-15:this.activeObj.activePoint.endX=this.lowerCanvas.width-15,this.destTop+this.destHeight+15<this.lowerCanvas.height?this.activeObj.activePoint.endY=this.destTop+this.destHeight-15:this.activeObj.activePoint.endY=this.lowerCanvas.height-15),this.activeObj.activePoint.startX<this.destLeft&&(this.activeObj.activePoint.startX=this.destLeft),this.activeObj.activePoint.startY<this.destTop&&(this.activeObj.activePoint.startY=this.destTop),this.activeObj.activePoint.endX>this.destLeft+this.destWidth&&(this.activeObj.activePoint.endX=this.destLeft+this.destWidth),this.activeObj.activePoint.endY>this.destTop+this.destHeight&&(this.activeObj.activePoint.endY=this.destTop+this.destHeight),this.activeObj.activePoint.startX===this.destLeft&&this.destLeft+this.destWidth>this.lowerCanvas.clientWidth&&(this.activeObj.activePoint.endX=this.lowerCanvas.clientWidth-15),this.activeObj.activePoint.startY===this.destTop&&this.destTop+this.destHeight>this.lowerCanvas.clientHeight&&(this.activeObj.activePoint.endY=this.lowerCanvas.clientHeight-15),this.activeObj.activePoint.width=this.activeObj.activePoint.endX-this.activeObj.activePoint.startX,this.activeObj.activePoint.height=this.activeObj.activePoint.endY-this.activeObj.activePoint.startY,this.updateActiveObject(this.activeObj.activePoint,this.activeObj),this.drawObject("duplicate",this.activeObj,null,null,!0)},l.prototype.clearOuterCanvas=function(t){var e=this.destLeft,i=this.destTop;if(""!==this.currFlipState&&(this.destLeft=this.lowerCanvas.clientWidth-(this.destWidth+this.destLeft),this.destTop=this.lowerCanvas.clientHeight-(this.destHeight+this.destTop)),this.destWidth<this.lowerCanvas.width){var s=this.destLeft>0?this.destLeft:0;t.clearRect(0,0,s,this.lowerCanvas.height),t.clearRect(this.destLeft+this.destWidth,0,s,this.lowerCanvas.height)}if(this.destHeight<this.lowerCanvas.height){var o=this.destTop>0?this.destTop:0;t.clearRect(0,0,this.lowerCanvas.width,o),t.clearRect(0,this.destTop+this.destHeight,this.lowerCanvas.width,o)}""!==this.currFlipState&&(this.destLeft=e,this.destTop=i)},l.prototype.cropCircle=function(t,i,s){s&&""!==this.currFlipState&&this.setTransform(t,this.currFlipState),t.globalCompositeOperation="destination-in",t.beginPath(),e.isNullOrUndefined(i)?t.arc(this.destLeft+this.destWidth/2,this.destTop+this.destHeight/2,this.destWidth/2,0,2*Math.PI):t.arc(this.destWidth/2,this.destHeight/2,this.destWidth/2,0,2*Math.PI),t.closePath(),t.fill(),t.restore(),t.globalCompositeOperation="source-over",this.currObjType.isActiveObj=this.isCircleCrop=!0,s&&""!==this.currFlipState&&this.setTransform(t,this.currFlipState)},l.prototype.updateCropObj=function(){this.afterCropActions=[];var t=this.getCurrentObj();this.cropObj=e.extend({},t,{},!0)},l.prototype.setCurrentObj=function(t){var i=!!t;t=t||this.cropObj,this.cropZoomFactor=t.cropZoom,this.defaultZoomFactor=t.defaultZoom,i&&(e.isNullOrUndefined(t.activeObj.shape)||"crop"!==t.activeObj.shape.split("-")[0])?this.zoomFactor=t.defaultZoom:this.zoomFactor=t.cropZoom,this.totalPannedPoint=e.extend({},t.totalPannedPoint,{},!0),this.totalPannedClientPoint=e.extend({},t.totalPannedClientPoint,{},!0),this.totalPannedInternalPoint=e.extend({},t.totalPannedInternalPoint,{},!0),this.tempFlipPanPoint=e.extend({},t.tempFlipPanPoint,{},!0),this.rotateFlipColl=e.extend([],t.rotateFlipColl,[],!0),this.degree=t.degree,this.currFlipState=t.currFlipState,this.destLeft=t.destPoints.startX,this.destTop=t.destPoints.startY,this.destWidth=t.destPoints.width,this.destHeight=t.destPoints.height,this.srcLeft=t.srcPoints.startX,this.srcTop=t.srcPoints.startY,this.srcWidth=t.srcPoints.width,this.srcHeight=t.srcPoints.height,this.lowerContext.filter=t.filter,this.lowerContext.filter.split(" ").length>1&&("1"===this.lowerContext.filter.split(" ")[0].split("(")[1].split(")")[0]?this.isBrightnessAdjusted=!1:this.isBrightnessAdjusted=!0);var s=this.isCircleCrop,o=e.extend({},this.currSelectionPoint,{},!0);this.currSelectionPoint=null,this.isCircleCrop=!1,this.drawCropSelectionImage(t,!1),0!==this.degree&&(this.currentPannedPoint={x:0,y:0},this.rotatePan()),this.activeObj=e.extend({},t.activeObj,{},!0),this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),0!==this.activeObj.activePoint.width&&0!==this.activeObj.activePoint.height&&this.drawObject("duplicate");var a=e.extend({},t.activeObj,{},!0),n=!1;this.afterCropActions=this.alignRotateFlipColl(this.afterCropActions);var r=e.extend([],this.afterCropActions,[],!0);if(!i&&r.length>0){n=!0;for(var h=0;h<r.length;h++)this.degree%90!=0||this.degree%180==0||"horizontalflip"!==r[h]&&"verticalflip"!==r[h]||(this.rotatedFlipCropSelection=!0),this.updateTransform(r[h]),"horizontalflip"!==r[h]&&"verticalflip"!==r[h]||1===r.length&&(this.activeObj=e.extend({},this.cropObj.activeObj,{},!0),this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),this.drawObject("duplicate"));a=e.extend({},this.activeObj,{},!0),this.totalPannedPoint={x:0,y:0},this.totalPannedClientPoint={x:0,y:0},this.totalPannedInternalPoint={x:0,y:0},this.activeObj=a,this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),0!==this.activeObj.activePoint.width&&0!==this.activeObj.activePoint.height&&this.drawObject("duplicate"),t.degree!==this.degree&&(this.cropZoomFactor=this.zoomFactor=0),this.updateObjAndFreeHandDrawColl(),this.rotatedFlipCropSelection&&(this.rotatedFlipCropSelection=!1)}this.afterCropActions=r,this.isCancelAction||n||(this.updateObjAndFreeHandDrawColl(),this.zoomFreehandDrawColl(),this.destLeft=t.destPoints.startX,this.destTop=t.destPoints.startY),this.activeObj=a,this.isCircleCrop=s,this.currSelectionPoint=o},l.prototype.drawCropSelectionImage=function(t,i){var s=this.lowerContext.filter;this.upperContext.clearRect(0,0,this.lowerCanvas.width,this.lowerCanvas.height),this.lowerContext.clearRect(0,0,this.lowerCanvas.width,this.lowerCanvas.height),this.reverseTransformedState(),i?this.updateCurrentTransformedState("initial"):this.iterateRotateFlipColl(this.lowerContext,"initial"),this.setDestPointsForFlipState(),this.updateBrightnessFilter(),this.lowerContext.drawImage(this.baseImg,this.srcLeft,this.srcTop,this.srcWidth,this.srcHeight,this.destLeft,this.destTop,this.destWidth,this.destHeight),i?this.updateCurrentTransformedState("reverse"):this.iterateRotateFlipColl(this.lowerContext,"reverse"),this.destLeft=this.cropObj.destPoints.startX,this.destTop=this.cropObj.destPoints.startY;var o=e.extend({},t.activeObj,{},!0);if(this.lowerContext.filter="none",this.isCancelAction)this.zoomObjColl(),this.zoomFreehandDrawColl();else{this.destLeft=t.destPoints.startX,this.destTop=t.destPoints.startY,this.destWidth=t.destPoints.width,this.destHeight=t.destPoints.height,this.srcLeft=t.srcPoints.startX,this.srcTop=t.srcPoints.startY,this.srcWidth=t.srcPoints.width,this.srcHeight=t.srcPoints.height;var a={startX:this.destLeft,startY:this.destTop,width:this.destWidth,height:this.destHeight};this.destLeft=t.activeObj.activePoint.startX,this.destTop=t.activeObj.activePoint.startY,this.destWidth=t.activeObj.activePoint.width,this.destHeight=t.activeObj.activePoint.height,this.zoomObjColl(),this.zoomFreehandDrawColl(),this.destLeft=a.startX,this.destTop=a.startY,this.destWidth=a.width,this.destHeight=a.height}this.activeObj=o,this.lowerContext.filter=s},l.prototype.cropImg=function(t){if(e.isNullOrUndefined(t)&&(this.croppedDegree=this.degree),e.isNullOrUndefined(t)&&0!==this.degree)this.updateCropObj(),this.currDestinationPoint={startX:this.destLeft,startY:this.destTop,width:this.destWidth,height:this.destHeight},this.rotateCrop();else if(e.isNullOrUndefined(t)&&""!==this.currFlipState)this.updateCropObj(),this.currDestinationPoint={startX:this.destLeft,startY:this.destTop,width:this.destWidth,height:this.destHeight},this.flipCrop();else{this.tempZoomFactor=this.zoomFactor;var i=this.calcRatio();!e.isNullOrUndefined(t)&&t||(this.updateCropObj(),this.resetPanPoints(),this.updateImageRatioForActObj(),this.currDestinationPoint={startX:this.destLeft,startY:this.destTop,width:this.destWidth,height:this.destHeight},this.currSelectionPoint=e.extend({},this.activeObj,{},!0),this.cropDestPoints={startX:this.destLeft,startY:this.destTop,width:this.destWidth,height:this.destHeight});var s=this.calcMaxDimension(this.activeObj.activePoint.width*i.width,this.activeObj.activePoint.height*i.height);this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),this.lowerContext.clearRect(0,0,this.lowerCanvas.width,this.lowerCanvas.height),this.srcLeft=this.activeObj.activePoint.startX*i.width-this.destLeft*i.width,this.srcTop=this.activeObj.activePoint.startY*i.height-this.destTop*i.height,this.srcWidth=this.activeObj.activePoint.width*i.width,this.srcHeight=this.activeObj.activePoint.height*i.height,this.destLeft=(this.lowerCanvas.clientWidth-s.width)/2,this.destTop=(this.lowerCanvas.clientHeight-s.height)/2,this.destWidth=s.width,this.destHeight=s.height;var o=this.lowerContext.filter;this.updateBrightnessFilter(),this.lowerContext.drawImage(this.baseImg,this.srcLeft,this.srcTop,this.srcWidth,this.srcHeight,this.destLeft,this.destTop,this.destWidth,this.destHeight),this.lowerContext.filter="none";var a=e.extend({},this.activeObj,{},!0);this.cropObjColl(),this.zoomObjColl();for(var n=0;n<this.objColl.length;n++)this.isObjInsideCropRegion(this.objColl[n])&&(this.apply(this.objColl[n].shape,this.objColl[n]),this.refreshActiveObj());this.activeObj=a,this.cropFreehandDrawColl(),this.zoomFreehandDrawColl(),this.clearOuterCanvas(this.lowerContext),this.clearOuterCanvas(this.upperContext),"crop-circle"===this.currSelectionPoint.shape?this.cropCircle(this.lowerContext):this.isCircleCrop=!1,this.lowerContext.filter=o,this.refreshActiveObj(),this.currObjType.isCustomCrop=!1,this.pan(!1),this.defaultZoomFactor=0}},l.prototype.updateImageRatioForActObj=function(){this.activeObj.imageRatio={startX:(this.activeObj.activePoint.startX-this.destLeft)/this.destWidth,startY:(this.activeObj.activePoint.startY-this.destTop)/this.destHeight,endX:(this.activeObj.activePoint.endX-this.destLeft)/this.destWidth,endY:(this.activeObj.activePoint.endY-this.destTop)/this.destHeight,width:this.destWidth/this.activeObj.activePoint.width,height:this.destHeight/this.activeObj.activePoint.height}},l.prototype.drawImgToCanvas=function(t){this.lowerContext.clearRect(0,0,this.lowerCanvas.width,this.lowerCanvas.height),this.destWidth=t.width,this.destHeight=t.height,this.isInitialLoading&&(this.initializeFilter(),this.isInitialLoading=!1);var i=this.lowerContext.filter;this.updateBrightnessFilter(),this.lowerContext.drawImage(this.baseImg,this.srcLeft,this.srcTop,this.srcWidth,this.srcHeight,this.destLeft,this.destTop,this.destWidth,this.destHeight),(!e.isNullOrUndefined(this.currSelectionPoint)&&"crop-circle"===this.currSelectionPoint.shape||this.isCircleCrop)&&this.cropCircle(this.lowerContext),this.lowerContext.filter=i},l.prototype.limitPan=function(){this.activeObj.activePoint&&(this.destLeft>this.activeObj.activePoint.startX&&(this.destLeft=this.activeObj.activePoint.startX),this.destTop>this.activeObj.activePoint.startY&&(this.destTop=this.activeObj.activePoint.startY),this.destLeft+this.destWidth<this.activeObj.activePoint.endX&&(this.destLeft=this.activeObj.activePoint.endX-this.destWidth),this.destTop+this.destHeight<this.activeObj.activePoint.endY&&(this.destTop=this.activeObj.activePoint.endY-this.destHeight))},l.prototype.updatePanPoints=function(t){var i=this.destLeft,s=this.destTop,o=this.panMove.x-this.tempPanMove.x,a=this.panMove.y-this.tempPanMove.y;if(""===t)this.destLeft+=o,this.destTop+=a,this.limitPan();else if("horizontal"===t){n=e.extend({},this.activeObj,{},!0);this.updateFlipActiveObj(t),o=this.tempPanMove.x-this.panMove.x,this.destLeft+=o,this.destTop+=a,this.limitPan(),this.activeObj=n}else if("vertical"===t){n=e.extend({},this.activeObj,{},!0);this.updateFlipActiveObj(t),a=this.tempPanMove.y-this.panMove.y,this.destLeft+=o,this.destTop+=a,this.limitPan(),this.activeObj=n}else if("horizontalVertical"===t){n=e.extend({},this.activeObj,{},!0);this.updateFlipActiveObj(t),o=this.tempPanMove.x-this.panMove.x,this.destLeft+=o,this.destTop-=a,this.limitPan(),this.activeObj=n}else if("verticalHorizontal"===t){var n=e.extend({},this.activeObj,{},!0);this.updateFlipActiveObj(t),a=this.tempPanMove.y-this.panMove.y,this.destLeft-=o,this.destTop+=a,this.limitPan(),this.activeObj=n}return{x:this.destLeft-i,y:this.destTop-s}},l.prototype.setCurrentPanRegion=function(t,e){var i=t;return""===t?"horizontal"===e?i="horizontal":"vertical"===e&&(i="vertical"):"horizontal"===t?"horizontal"===e?i="horizontalVertical":"vertical"===e?i="verticalHorizontal":90===e?i="vertical":-90===e&&(i="horizontal"):"vertical"===t?"horizontal"===e?i="horizontalVertical":"vertical"===e?i="verticalHorizontal":90===e?i="horizontal":-90===e&&(i="vertical"):"horizontal"===e?i="vertical":"vertical"===e&&(i="horizontal"),i},l.prototype.getCurrentPanRegion=function(){for(var t="",e=0;e<this.rotateFlipColl.length;e++)t=this.setCurrentPanRegion(t,this.rotateFlipColl[e]);return t},l.prototype.drawPannImage=function(t){var i={startX:this.destLeft,startY:this.destTop,width:this.destWidth,height:this.destHeight};this.lowerContext.clearRect(0,0,this.lowerCanvas.width,this.lowerCanvas.height),this.updateCurrentTransformedState("initial"),this.destLeft=i.startX,this.destTop=i.startY,this.destWidth=i.width,this.destHeight=i.height,this.setDestPointsForFlipState(),this.updateBrightnessFilter(),this.lowerContext.drawImage(this.baseImg,this.srcLeft,this.srcTop,this.srcWidth,this.srcHeight,this.destLeft,this.destTop,this.destWidth,this.destHeight),(!e.isNullOrUndefined(this.currSelectionPoint)&&"crop-circle"===this.currSelectionPoint.shape||this.isCircleCrop)&&this.cropCircle(this.lowerContext,null,!0),this.updateCurrentTransformedState("reverse"),this.destLeft=i.startX,this.destTop=i.startY,this.destWidth=i.width,this.destHeight=i.height,this.lowerContext.filter="none",this.panObjColl(t.x,t.y,""),this.panFreehandDrawColl(t.x,t.y,""),this.isCircleCrop&&this.cropCircle(this.lowerContext,null,!0)},l.prototype.drawPannedImage=function(t,i){var s={startPoint:this.panDown,endPoint:this.panMove};this.trigger("panning",s);var o=!1;if(e.isNullOrUndefined(this.activeObj.shape)&&(o=!0,this.activeObj.activePoint={startX:this.destLeft,startY:this.destTop,endX:this.destLeft+this.destWidth,endY:this.destTop+this.destHeight},this.activeObj.activePoint.startX<0&&(this.activeObj.activePoint.startX=0),this.activeObj.activePoint.startY<0&&(this.activeObj.activePoint.startY=0),this.activeObj.activePoint.endX>this.lowerCanvas.width&&(this.activeObj.activePoint.endX=this.lowerCanvas.width),this.activeObj.activePoint.endY>this.lowerCanvas.height&&(this.activeObj.activePoint.endY=this.lowerCanvas.height),this.activeObj.activePoint.width=this.activeObj.activePoint.endX-this.activeObj.activePoint.startX,this.activeObj.activePoint.height=this.activeObj.activePoint.endY-this.activeObj.activePoint.startY,this.activeObj.shape="crop-custom",this.activeObj.strokeSettings=this.strokeSettings,this.updateActiveObject(this.activeObj.activePoint,this.activeObj),this.isCropTab=!0),0===this.degree){var a=void 0;a=e.isNullOrUndefined(t)&&e.isNullOrUndefined(i)?this.updatePanPoints(""):{x:t,y:i},this.totalPannedPoint.x+=a.x,this.totalPannedPoint.y+=a.y;var n=e.extend({},this.activeObj,{},!0),r=this.lowerContext.filter;this.drawPannImage(a),this.lowerContext.filter=r,this.tempPanMove=e.extend({},this.panMove,{},!0),this.activeObj=e.extend({},n,{},!0),this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),e.isNullOrUndefined(this.activeObj.shape)||this.drawObject("duplicate",this.activeObj)}else{var h=this.currFlipState;this.isCropTab=!0,e.isNullOrUndefined(t)&&e.isNullOrUndefined(i)?this.currentPannedPoint=this.updatePanPoints(""):this.currentPannedPoint={x:t,y:i},this.currFlipState=h,this.rotatePan(),this.isCropTab=!1,this.tempPanMove=e.extend({},this.panMove,{},!0)}o&&(this.refreshActiveObj(),this.isCropTab=!1,this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height))},l.prototype.updateFlipPan=function(t){if(""!==this.currFlipState){var i=this.lowerContext.filter;this.refreshActiveObj(),this.rotatedFlip(),this.lowerContext.filter="none",this.freehandRedraw(this.lowerContext),this.lowerContext.filter=i,this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),e.isNullOrUndefined(t)||this.drawObject("duplicate",t)}},l.prototype.updateFlipActiveObj=function(t){"horizontal"===t?(this.activeObj.activePoint.startX>this.lowerCanvas.width/2?this.activeObj.activePoint.endX=this.lowerCanvas.width/2-(this.activeObj.activePoint.startX-this.lowerCanvas.width/2):this.activeObj.activePoint.endX=this.lowerCanvas.width/2+(this.lowerCanvas.width/2-this.activeObj.activePoint.startX),this.activeObj.activePoint.startX=this.activeObj.activePoint.endX-this.activeObj.activePoint.width):"vertical"===t?(this.activeObj.activePoint.startX>this.lowerCanvas.width/2?this.activeObj.activePoint.endY=this.lowerCanvas.height/2-(this.activeObj.activePoint.startY-this.lowerCanvas.height/2):this.activeObj.activePoint.endY=this.lowerCanvas.height/2+(this.lowerCanvas.height/2-this.activeObj.activePoint.startY),this.activeObj.activePoint.startY=this.activeObj.activePoint.endY-this.activeObj.activePoint.height):"verticalHorizontal"!==t&&"horizontalVertical"!==t||(this.activeObj.activePoint.startX>this.lowerCanvas.width/2?(this.activeObj.activePoint.endX=this.lowerCanvas.width/2-(this.activeObj.activePoint.startX-this.lowerCanvas.width/2),this.activeObj.activePoint.endY=this.lowerCanvas.height/2-(this.activeObj.activePoint.startY-this.lowerCanvas.height/2)):(this.activeObj.activePoint.endX=this.lowerCanvas.width/2+(this.lowerCanvas.width/2-this.activeObj.activePoint.startX),this.activeObj.activePoint.endY=this.lowerCanvas.height/2+(this.lowerCanvas.height/2-this.activeObj.activePoint.startY)),this.activeObj.activePoint.startX=this.activeObj.activePoint.endX-this.activeObj.activePoint.width,this.activeObj.activePoint.startY=this.activeObj.activePoint.endY-this.activeObj.activePoint.height),this.updateActiveObject(this.activeObj.activePoint,this.activeObj)},l.prototype.resetPanPoints=function(){this.totalPannedPoint={x:0,y:0},this.totalPannedClientPoint={x:0,y:0},this.totalPannedInternalPoint={x:0,y:0}},l.prototype.flipCrop=function(){this.isReverseFlip=!0,this.totalPannedPoint.x+=this.tempFlipPanPoint.x,this.totalPannedPoint.y+=this.tempFlipPanPoint.y;var t=this.currFlipState,i=this.flipColl;if(this.flipColl=[],this.updateImageRatioForActObj(),this.objColl.push(this.activeObj),this.zoomFactor>0){for(var s=this.zoomFactor,o=this.isUndoRedo,a=0;a<10*s;a++)this.isUndoRedo=!0,this.zoom(-.1);this.isUndoRedo=o,this.resetPanPoints()}this.currSelectionPoint=e.extend({},this.objColl[this.objColl.length-1],{},!0),this.lowerContext.clearRect(0,0,this.lowerCanvas.width,this.lowerCanvas.height),this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height);var n=this.lowerContext.filter;this.updateBrightnessFilter(),this.lowerContext.drawImage(this.baseImg,this.srcLeft,this.srcTop,this.srcWidth,this.srcHeight,this.destLeft,this.destTop,this.destWidth,this.destHeight);for(a=0;a<this.objColl.length;a++)this.objColl[a].shapeFlip="";for(a=0;a<this.freehandCounter;a++)this.pointColl[a].shapeFlip="";this.redrawObj(this.getCurrentPanRegion()),this.flipFreehandrawColl(this.getCurrentPanRegion()),this.activeObj=e.extend({},this.objColl[this.objColl.length-1],{},!0),this.objColl.pop(),this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),this.drawObject("duplicate"),this.cropImg(!0),this.isReverseRotate=!0,this.reverseTransformedState(),this.setDestinationPoints(),this.currentTransformedState("initial"),this.updateBrightnessFilter(),this.lowerContext.drawImage(this.baseImg,this.srcLeft,this.srcTop,this.srcWidth,this.srcHeight,this.destLeft,this.destTop,this.destWidth,this.destHeight),this.lowerContext.filter=n,this.isRotateZoom=!1,this.updateCurrentTransformedState("reverse"),this.currFlipState=t,this.flipColl=i,this.lowerContext.filter="none";for(a=0;a<this.objColl.length;a++)this.objColl[a].shapeFlip="";for(a=0;a<this.freehandCounter;a++)this.pointColl[a].shapeFlip="";this.redrawObj(this.getCurrentPanRegion()),this.flipFreehandrawColl(this.getCurrentPanRegion()),this.zoomObjColl(),this.zoomFreehandDrawColl(),this.lowerContext.filter=n,(!e.isNullOrUndefined(this.currSelectionPoint)&&"crop-circle"===this.currSelectionPoint.shape||this.isCircleCrop)&&this.cropCircle(this.lowerContext),this.refreshActiveObj(),this.clearOuterCanvas(this.lowerContext),this.clearOuterCanvas(this.upperContext),this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),this.isReverseFlip=!1,this.resetPanPoints(),this.tempFlipPanPoint={x:0,y:0}},l.prototype.rotateCrop=function(){var t="";e.isNullOrUndefined(this.activeObj.shape)||(t=this.activeObj.shape);var i=this.degree;this.degree%90==0&&this.degree%180!=0&&(this.rotatedDestPoints.startX=this.destLeft,this.rotatedDestPoints.startY=this.destTop,this.rotatedDestPoints.width=this.destWidth,this.rotatedDestPoints.height=this.destHeight,this.rotatedDestPoints.startX-=this.totalPannedClientPoint.x,this.rotatedDestPoints.startY-=this.totalPannedClientPoint.y),this.updateImageRatioForActObj(),this.currSelectionPoint=e.extend({},this.activeObj,{},!0),this.objColl.push(this.activeObj),this.activeObj=e.extend({},this.objColl[this.objColl.length-1],{},!0),this.reverseTransformedState(),this.setClientTransformedDimension(),this.lowerContext.clearRect(0,0,this.lowerCanvas.width,this.lowerCanvas.height);var s=this.lowerContext.filter;this.updateBrightnessFilter(),this.lowerContext.drawImage(this.baseImg,this.srcLeft,this.srcTop,this.srcWidth,this.srcHeight,this.destLeft,this.destTop,this.destWidth,this.destHeight),this.lowerContext.filter=s;var o=0;90===i||-270===i?o=3:180===i||-180===i?o=2:270!==i&&-90!==i||(o=1);for(r=0;r<o;r++)this.rotateObjColl(),this.rotateFreehandDrawColl();var a=e.extend({},this.objColl[this.objColl.length-1],{},!0);if(""!==this.currFlipState){for(r=0;r<this.objColl.length;r++)this.objColl[r].shapeFlip="";for(r=0;r<this.freehandCounter;r++)this.pointColl[r].shapeFlip="";n=this.getCurrentCropState("initial");this.redrawObj(n),this.flipFreehandrawColl(n)}this.zoomObjColl(),this.zoomFreehandDrawColl(),a=e.extend({},this.objColl[this.objColl.length-1],{},!0),this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),this.drawObject("duplicate",a),this.objColl.pop(),this.degree=0,this.cropImg(!0),this.isReverseRotate=!0,this.reverseTransformedState(),this.degree=i,this.setDestinationPoints(),this.currentTransformedState("initial"),this.updateBrightnessFilter(),this.lowerContext.drawImage(this.baseImg,this.srcLeft,this.srcTop,this.srcWidth,this.srcHeight,this.destLeft,this.destTop,this.destWidth,this.destHeight),this.lowerContext.filter=s,this.currentTransformedState("reverse"),o=0,90===i||-270===i?o=1:180===i||-180===i?o=2:270!==i&&-90!==i||(o=3);for(r=0;r<o;r++)this.rotateObjColl(),this.rotateFreehandDrawColl();if(""!==this.getCurrentPanRegion()){for(r=0;r<this.objColl.length;r++)this.objColl[r].shapeFlip="";for(r=0;r<this.freehandCounter;r++)this.pointColl[r].shapeFlip="";var n=this.getCurrentCropState("reverse");this.redrawObj(n),this.flipFreehandrawColl(n)}this.isReverseRotate=!1,"crop-circle"===t&&this.cropCircle(this.lowerContext),this.lowerContext.filter="none";for(var r=0;r<this.objColl.length;r++)this.isObjInsideCropRegion(this.objColl[r])&&(this.apply(this.objColl[r].shape,this.objColl[r]),this.refreshActiveObj());this.zoomFreehandDrawColl(),this.lowerContext.filter=s,this.clearOuterCanvas(this.lowerContext),this.clearOuterCanvas(this.upperContext),"crop-circle"===t&&this.cropCircle(this.lowerContext),this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),this.resetPanPoints()},l.prototype.getCurrentCropState=function(t,e){var i="",s=[];if("initial"===t)if(180===this.degree||-180===this.degree)i=this.flipColl.length>1?this.getCurrentPanRegion():this.currFlipState;else{for(var o=0;o<this.rotateFlipColl.length;o++)"number"==typeof this.rotateFlipColl[o]?s.push("number"):"string"==typeof this.rotateFlipColl[o]&&s.push("string");s.length>1&&"string"===s[s.length-1]&&"number"===s[s.length-2]?"horizontal"===this.currFlipState?i="vertical":"vertical"===this.currFlipState&&(i="horizontal"):s.length>1&&"number"===s[s.length-1]&&"string"===s[s.length-2]&&(i=this.flipColl.length>1?this.getCurrentPanRegion():this.currFlipState)}else i=this.getCurrentPanRegion(),!e&&this.isInitialRotate()||-90!==this.degree&&-270!==this.degree||("horizontal"===i?i="vertical":"vertical"===i&&(i="horizontal"));return""===i&&(i=this.flipColl.length>1?this.getCurrentPanRegion():this.currFlipState),i},l.prototype.isInitialRotate=function(){var t=!1;return this.rotateFlipColl.length>0&&"number"==typeof this.rotateFlipColl[0]&&(t=!0),t},l.prototype.updateRotatePanPoints=function(){var t="";t=this.isInitialRotate()&&this.degree<0?this.getCurrentCropState("reverse",!0):this.getCurrentPanRegion(),this.degree%90==0&&this.degree%180!=0?90===this.degree||-90===this.degree&&("horizontal"===t||"vertical"===t)||-270===this.degree&&(""===t||"verticalHorizontal"===t||"horizontalVertical"===t)?""===t?(this.destLeft+=this.currentPannedPoint.y,this.destTop-=this.currentPannedPoint.x):"horizontal"===t?(this.destLeft+=this.currentPannedPoint.y,this.destTop+=this.currentPannedPoint.x):"vertical"===t?(this.destLeft-=this.currentPannedPoint.y,this.destTop-=this.currentPannedPoint.x):(this.destLeft-=this.currentPannedPoint.y,this.destTop+=this.currentPannedPoint.x):270!==this.degree&&(-270!==this.degree||"horizontal"!==t&&"vertical"!==t)&&(-90!==this.degree||""!==t&&"verticalHorizontal"!==t&&"horizontalVertical"!==t)||(""===t?(this.destLeft-=this.currentPannedPoint.y,this.destTop+=this.currentPannedPoint.x):"horizontal"===t?(this.destLeft-=this.currentPannedPoint.y,this.destTop-=this.currentPannedPoint.x):"vertical"===t?(this.destLeft+=this.currentPannedPoint.y,this.destTop+=this.currentPannedPoint.x):(this.destLeft+=this.currentPannedPoint.y,this.destTop-=this.currentPannedPoint.x)):180!==this.degree&&-180!==this.degree||(""===t?(this.destLeft-=this.currentPannedPoint.x,this.destTop-=this.currentPannedPoint.y):"horizontal"===t?(this.destLeft+=this.currentPannedPoint.x,this.destTop-=this.currentPannedPoint.y):"vertical"===t?(this.destLeft-=this.currentPannedPoint.x,this.destTop+=this.currentPannedPoint.y):(this.destLeft+=this.currentPannedPoint.x,this.destTop+=this.currentPannedPoint.y))},l.prototype.rotatePan=function(t,i){this.isReverseRotate=!0;var s,o=this.degree;e.isNullOrUndefined(this.activeObj.activePoint)||e.isNullOrUndefined(this.activeObj.shape)||(s=e.extend({},this.activeObj,{},!0));var a=e.extend([],this.objColl,[],!0),n=e.extend([],this.pointColl,[],!0);this.objColl=[],this.pointColl=[],this.freehandCounter=0,this.refreshActiveObj(),this.isRotateZoom=!0,this.updateCurrentTransformedState("initial");var r=this.destLeft,h=this.destTop;this.isCropTab&&(this.destLeft+=this.totalPannedInternalPoint.x,this.destTop+=this.totalPannedInternalPoint.y),this.updateRotatePanPoints(),this.isCropTab&&(this.totalPannedInternalPoint.x=this.destLeft-r,this.totalPannedInternalPoint.y=this.destTop-h);var l=this.lowerContext.filter;this.updateBrightnessFilter(),this.lowerContext.drawImage(this.baseImg,this.srcLeft,this.srcTop,this.srcWidth,this.srcHeight,this.destLeft,this.destTop,this.destWidth,this.destHeight),this.isRotateZoom=!1,this.updateCurrentTransformedState("reverse",!0,!0);var c=this.destLeft,d=this.destTop;this.destLeft+=this.totalPannedClientPoint.x,this.destTop+=this.totalPannedClientPoint.y,this.destLeft+=this.currentPannedPoint.x,this.destTop+=this.currentPannedPoint.y,this.totalPannedClientPoint.x=this.destLeft-c,this.totalPannedClientPoint.y=this.destTop-d,this.objColl=a,this.pointColl=n,this.freehandCounter=this.pointColl.length,this.degree=o,this.lowerContext.filter="none",t&&(i?(this.totalPannedClientPoint.x=-this.totalPannedClientPoint.x,this.totalPannedClientPoint.y=-this.totalPannedClientPoint.y,this.currentPannedPoint=e.extend({},this.totalPannedClientPoint,{},!0),this.totalPannedClientPoint={x:0,y:0},this.destLeft+=this.currentPannedPoint.x,this.destTop+=this.currentPannedPoint.y):this.currentPannedPoint=e.extend({},this.totalPannedClientPoint,{},!0)),this.panObjColl(this.currentPannedPoint.x,this.currentPannedPoint.y,""),this.panFreehandDrawColl(this.currentPannedPoint.x,this.currentPannedPoint.y,""),this.lowerContext.filter=l,this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),this.activeObj=e.extend({},s,{},!0),e.isNullOrUndefined(this.activeObj.activePoint)||this.drawObject("duplicate",this.activeObj,null,null,!0),this.isReverseRotate=!1},l.prototype.rotateZoom=function(t){var i=Math.pow(10,1);Math.round(this.zoomFactor*i)/i==.1&&-.1===t?this.zoomFactor=0:this.zoomFactor+=t,this.isCropTab?this.cropZoomFactor=this.zoomFactor:this.defaultZoomFactor=this.zoomFactor;var s=e.extend([],this.objColl,[],!0),o=e.extend({},this.activeObj,{},!0);this.objColl=[],this.refreshActiveObj(),this.updateCurrentTransformedState("initial"),this.isRotateZoom=!0,this.setDestinationPoints();var a=this.lowerContext.filter;this.updateBrightnessFilter(),this.lowerContext.drawImage(this.baseImg,this.srcLeft,this.srcTop,this.srcWidth,this.srcHeight,this.destLeft,this.destTop,this.destWidth,this.destHeight),this.lowerContext.filter=a,this.isRotateZoom=!1,this.updateCurrentTransformedState("reverse"),this.objColl=s,this.activeObj=o},l.prototype.drawZoomImgToCanvas=function(t,e){var i=Math.pow(10,1);Math.round(this.zoomFactor*i)/i==.1&&-.1===t?this.zoomFactor=0:this.zoomFactor+=t,this.isCropTab?this.cropZoomFactor=this.zoomFactor:this.defaultZoomFactor=this.zoomFactor;var s={width:0,height:0};this.isCropTab?s=this.cropZoom(t,e):((s=this.calcMaxDimension(this.srcWidth,this.srcHeight)).width+=s.width*this.zoomFactor,s.height+=s.height*this.zoomFactor,this.destLeft=(this.lowerCanvas.clientWidth-s.width)/2,this.destTop=(this.lowerCanvas.clientHeight-s.height)/2),this.drawImgToCanvas(s)},l.prototype.cropZoom=function(t,i){var s=this.destLeft,o=this.destTop,a={width:0,height:0};return 0===this.srcLeft||0===this.srcTop?a=e.isNullOrUndefined(i)?this.setZoomDimension(t,null):this.setZoomDimension(t,i):((a=this.degree%90==0&&this.degree%180!=0?this.calcMaxDimension(this.srcHeight,this.srcWidth):this.calcMaxDimension(this.srcWidth,this.srcHeight)).width+=a.width*this.zoomFactor,a.height+=a.height*this.zoomFactor),this.destLeft=s-(a.width-this.destWidth)/2,this.destTop=o-(a.height-this.destHeight)/2,s=this.destLeft,o=this.destTop,e.isNullOrUndefined(i)||(this.destLeft>i.activePoint.startX&&(this.destLeft=i.activePoint.startX,0===this.degree&&(this.totalPannedPoint.x-=s-this.destLeft)),this.destTop>i.activePoint.startY&&(this.destTop=i.activePoint.startY,0===this.degree&&(this.totalPannedPoint.y-=o-this.destTop)),this.destLeft+a.width<i.activePoint.endX&&(this.destLeft=i.activePoint.endX-a.width,0===this.degree&&(this.totalPannedPoint.x-=s-this.destLeft)),this.destTop+a.height<i.activePoint.endY&&(this.destTop=i.activePoint.endY-a.height,0===this.degree&&(this.totalPannedPoint.y-=o-this.destTop))),a},l.prototype.updateCanvas=function(){var t={fileName:this.fileName,fileType:this.fileType};this.srcWidth=this.baseImg.width,this.srcHeight=this.baseImg.height;var e=this.calcMaxDimension(this.srcWidth,this.srcHeight);this.destLeft=(this.lowerCanvas.clientWidth-e.width)/2,this.destTop=(this.lowerCanvas.clientHeight-e.height)/2,this.drawImgToCanvas(e),this.cropDestPoints={startX:this.destLeft,startY:this.destTop,width:this.destWidth,height:this.destHeight};var i=this.lowerContext.filter;this.lowerContext.filter="none",this.iterateObjColl(),this.zoomFreehandDrawColl(),this.lowerContext.filter=i,this.destWidth>0&&this.destHeight>0&&(this.isImageLoaded=!0),this.isUndoRedo&&""!==this.currFlipState&&this.flip(this.toPascalCase(this.currFlipState)),this.disabled&&this.element.setAttribute("class","e-disabled"),this.trigger("fileOpened",t)},l.prototype.imageOnLoad=function(t){var i=this;this.baseImg.src=t,this.baseImg.onload=function(){i.lowerContext.drawImage(i.baseImg,0,0,i.lowerCanvas.width,i.lowerCanvas.height),a.hideSpinner(i.element),i.element.style.opacity="1",i.updateCanvas(),i.currObjType.isUndoZoom&&(i.currObjType.isUndoZoom=!1,i.lowerCanvas.style.display="block"),i.isUndoRedo=!1,e.Browser.isDevice?(!i.isToolbar()||e.isNullOrUndefined(document.getElementById(i.element.id+"_toolbar"))||e.isNullOrUndefined(e.getComponent(document.getElementById(i.element.id+"_toolbar"),"toolbar"))||e.getComponent(document.getElementById(i.element.id+"_toolbar"),"toolbar").destroy(),e.isNullOrUndefined(document.getElementById(i.element.id+"_bottomToolbar"))||e.isNullOrUndefined(e.getComponent(document.getElementById(i.element.id+"_bottomToolbar"),"toolbar"))||e.getComponent(document.getElementById(i.element.id+"_bottomToolbar"),"toolbar").destroy(),i.initToolbarItem(!1,e.Browser.isDevice,null),i.createBottomToolbar()):(!i.isToolbar()||e.isNullOrUndefined(document.getElementById(i.element.id+"_toolbar"))||e.isNullOrUndefined(e.getComponent(document.getElementById(i.element.id+"_toolbar"),"toolbar"))||e.getComponent(document.getElementById(i.element.id+"_toolbar"),"toolbar").destroy(),i.initToolbarItem(!1,!1,null))}},l.prototype.refreshActiveObj=function(){this.activeObj={},this.activeObj.activePoint={startX:0,startY:0,endX:0,endY:0,width:0,height:0},this.activeObj.flipObjColl=[],this.activeObj.strokeSettings=this.strokeSettings,this.activeObj.textSettings=this.textSettings},l.prototype.redrawText=function(){this.activeObj.textSettings.bold&&(this.upperContext.font="bold "+this.activeObj.textSettings.fontSize+"px "+this.activeObj.textSettings.fontFamily),this.activeObj.textSettings.italic&&(this.upperContext.font="bold "+this.activeObj.textSettings.fontSize+"px "+this.activeObj.textSettings.fontFamily),this.activeObj.textSettings.bold&&this.activeObj.textSettings.italic&&(this.upperContext.font="italic bold "+this.activeObj.textSettings.fontSize+"px "+this.activeObj.textSettings.fontFamily),this.activeObj.textSettings.bold||this.activeObj.textSettings.italic||(this.upperContext.font=this.activeObj.textSettings.fontSize+"px "+this.activeObj.textSettings.fontFamily);var t=this.activeObj.keyHistory.split("\n"),e="block"===this.textArea.style.display?this.getMaxText(!0):this.getMaxText(),i=this.upperContext.measureText(e).width+.5*this.activeObj.textSettings.fontSize,s=t.length*(this.activeObj.textSettings.fontSize+.25*this.activeObj.textSettings.fontSize);this.setTextSelection(i,s),this.updateActiveObject(this.activeObj.activePoint,this.activeObj),this.redrawShape(this.activeObj)},l.prototype.setTextSelection=function(t,e){var i=this.degree;(i=0===this.activeObj.shapeDegree?this.degree:this.degree-this.activeObj.shapeDegree)<0&&(i=360+i);for(var s=0;s<this.activeObj.flipObjColl.length;s++)0===i?"horizontal"===this.activeObj.flipObjColl[s].toLowerCase()?this.activeObj.activePoint={startX:this.activeObj.activePoint.endX-t,startY:this.activeObj.activePoint.startY,endX:this.activeObj.activePoint.endX,endY:this.activeObj.activePoint.startY+(e||0)}:"vertical"===this.activeObj.flipObjColl[s].toLowerCase()?(this.activeObj.activePoint.startY=this.activeObj.activePoint.endY-e,this.activeObj.activePoint={startX:this.activeObj.activePoint.startX,startY:this.activeObj.activePoint.startY,endX:this.activeObj.activePoint.startX+(t||0),endY:this.activeObj.activePoint.endY}):this.activeObj.activePoint={startX:this.activeObj.activePoint.startX,startY:this.activeObj.activePoint.startY,endX:this.activeObj.activePoint.startX+(t||0),endY:this.activeObj.activePoint.startY+(e||0)}:90===i?"vertical"===this.activeObj.flipObjColl[s].toLowerCase()?(this.activeObj.activePoint.startX=this.activeObj.activePoint.endX-e,this.activeObj.activePoint={startX:this.activeObj.activePoint.startX,startY:this.activeObj.activePoint.endY-t,endX:this.activeObj.activePoint.endX,endY:this.activeObj.activePoint.endY}):"horizontal"===this.activeObj.flipObjColl[s].toLowerCase()?(this.activeObj.activePoint.endX=this.activeObj.activePoint.startX+e,this.activeObj.activePoint={startX:this.activeObj.activePoint.startX,startY:this.activeObj.activePoint.startY,endX:this.activeObj.activePoint.endX,endY:this.activeObj.activePoint.startY+(t||0)}):(this.activeObj.activePoint.startX=this.activeObj.activePoint.endX-e,this.activeObj.activePoint={startX:this.activeObj.activePoint.startX,startY:this.activeObj.activePoint.startY,endX:this.activeObj.activePoint.endX,endY:this.activeObj.activePoint.startY+(t||0)}):180===i?"horizontal"===this.activeObj.flipObjColl[s].toLowerCase()?(this.activeObj.activePoint.startY=this.activeObj.activePoint.endY-e,this.activeObj.activePoint={startX:this.activeObj.activePoint.startX,startY:this.activeObj.activePoint.startY,endX:this.activeObj.activePoint.startX+t,endY:this.activeObj.activePoint.endY}):"vertical"===this.activeObj.flipObjColl[s].toLowerCase()?(this.activeObj.activePoint.endY=this.activeObj.activePoint.startY+e,this.activeObj.activePoint={endX:this.activeObj.activePoint.endX,endY:this.activeObj.activePoint.endY,startX:this.activeObj.activePoint.endX-(t||0),startY:this.activeObj.activePoint.startY}):this.activeObj.activePoint={endX:this.activeObj.activePoint.endX,endY:this.activeObj.activePoint.endY,startX:this.activeObj.activePoint.endX-(t||0),startY:this.activeObj.activePoint.endY-(e||0)}:270===i&&("vertical"===this.activeObj.flipObjColl[s].toLowerCase()?this.activeObj.activePoint={startX:this.activeObj.activePoint.startX,startY:this.activeObj.activePoint.startY,endX:this.activeObj.activePoint.startX+e,endY:this.activeObj.activePoint.startY+(t||0)}:"horizontal"===this.activeObj.flipObjColl[s].toLowerCase()?(this.activeObj.activePoint.startX=this.activeObj.activePoint.endX-e,this.activeObj.activePoint={startX:this.activeObj.activePoint.startX,startY:this.activeObj.activePoint.endY-(t||0),endX:this.activeObj.activePoint.endX,endY:this.activeObj.activePoint.endY}):(this.activeObj.activePoint.endX=this.activeObj.activePoint.startX+e,this.activeObj.activePoint={startX:this.activeObj.activePoint.startX,startY:this.activeObj.activePoint.endY-(t||0),endX:this.activeObj.activePoint.endX,endY:this.activeObj.activePoint.endY}));0===this.activeObj.flipObjColl.length&&(0===i?this.activeObj.activePoint={startX:this.activeObj.activePoint.startX,startY:this.activeObj.activePoint.startY,endX:this.activeObj.activePoint.startX+(t||0),endY:this.activeObj.activePoint.startY+(e||0)}:90===i?(this.activeObj.activePoint.startX=this.activeObj.activePoint.endX-e,this.activeObj.activePoint={startX:this.activeObj.activePoint.startX,startY:this.activeObj.activePoint.startY,endX:this.activeObj.activePoint.endX,endY:this.activeObj.activePoint.startY+(t||0)}):180===i?this.activeObj.activePoint={endX:this.activeObj.activePoint.endX,endY:this.activeObj.activePoint.endY,startX:this.activeObj.activePoint.endX-(t||0),startY:this.activeObj.activePoint.endY-(e||0)}:270===i&&(this.activeObj.activePoint.endX=this.activeObj.activePoint.startX+e,this.activeObj.activePoint={startX:this.activeObj.activePoint.startX,startY:this.activeObj.activePoint.endY-(t||0),endX:this.activeObj.activePoint.endX,endY:this.activeObj.activePoint.endY})),this.activeObj.activePoint.width=this.activeObj.activePoint.endX-this.activeObj.activePoint.startX,this.activeObj.activePoint.height=this.activeObj.activePoint.endY-this.activeObj.activePoint.startY,360!==this.degree&&-360!==this.degree||(this.degree=0)},l.prototype.getCurrentObj=function(){var t={cropZoom:0,defaultZoom:0,totalPannedPoint:{x:0,y:0},totalPannedClientPoint:{x:0,y:0},totalPannedInternalPoint:{x:0,y:0},tempFlipPanPoint:{x:0,y:0},activeObj:{},rotateFlipColl:[],degree:0,currFlipState:"",destPoints:{startX:0,startY:0,width:0,height:0},srcPoints:{startX:0,startY:0,width:0,height:0},filter:""};return t.cropZoom=this.cropZoomFactor,t.defaultZoom=this.defaultZoomFactor,t.totalPannedPoint=e.extend({},this.totalPannedPoint,{},!0),t.totalPannedClientPoint=e.extend({},this.totalPannedClientPoint,{},!0),t.totalPannedInternalPoint=e.extend({},this.totalPannedInternalPoint,{},!0),t.tempFlipPanPoint=e.extend({},this.tempFlipPanPoint,{},!0),t.activeObj=e.extend({},this.activeObj,{},!0),t.rotateFlipColl=e.extend([],this.rotateFlipColl,[],!0),t.degree=this.degree,t.currFlipState=this.currFlipState,t.destPoints={startX:this.destLeft,startY:this.destTop,endX:0,endY:0,width:this.destWidth,height:this.destHeight},t.srcPoints={startX:this.srcLeft,startY:this.srcTop,endX:0,endY:0,width:this.srcWidth,height:this.srcHeight},t.filter=this.lowerContext.filter,t},l.prototype.updateUndoRedoColl=function(t,i,s,o,a,n,r,h){if(!this.isInitialLoading&&this.allowUndoRedo){this.currObjType.isUndoAction&&this.refreshUndoRedoColl(),this.undoRedoStep++;var l=this.getCurrentObj();l.objColl=e.extend([],this.objColl,[],!0),l.pointColl=e.extend([],this.pointColl,[],!0),l.afterCropActions=e.extend([],this.afterCropActions,[],!0),this.undoRedoColl.push({operation:t,previousObj:i,currentObj:l,previousObjColl:s,currentObjColl:l.objColl,previousPointColl:o,currentPointColl:l.pointColl,previousCropObj:a,currentCropObj:e.extend({},this.cropObj,{},!0),previousText:n,currentText:r,filter:h}),this.undoRedoColl.length>16&&(this.undoRedoColl.splice(0,1),this.undoRedoStep--),this.enableDisableToolbarBtn()}},l.prototype.fileSelect=function(t,i){a.showSpinner(this.element),this.element.style.opacity="0.5";var s=i.target.files[0];this.isImageLoaded&&(this.isImageLoaded=!1,this.reset()),e.isNullOrUndefined(this.toolbarTemplate)&&(this.reset(),this.update()),this.fileName=t.value.split("\\")[t.value.split("\\").length-1],this.fileName=this.fileName.split(".")[0];var o=window.URL.createObjectURL(s);this.imageOnLoad(o.toString()),t.value=""},l.prototype.findTextPoint=function(t){if("text"===this.activeObj.shape){this.textArea.style.transformOrigin="0 0";var e=void 0,i="";if((e=0===this.activeObj.shapeDegree?this.degree:this.degree-this.activeObj.shapeDegree)<0&&(e=360+e),this.activeObj.flipObjColl.length>0)for(var s=0;s<this.activeObj.flipObjColl.length;s++)i+=0!==e&&e%90==0&&180!==e?"horizontal"===this.activeObj.flipObjColl[s].toLowerCase()?"scale(1, -1)":"scale(-1, 1)":"horizontal"===this.activeObj.flipObjColl[s].toLowerCase()?"scale(-1, 1)":"scale(1, -1)","horizontal"===this.activeObj.flipObjColl[s].toLowerCase()?this.textArea.style.transform="rotate("+e+"deg)"+i:"vertical"===this.activeObj.flipObjColl[s].toLowerCase()&&(this.textArea.style.transform="rotate("+e+"deg)"+i);else this.textArea.style.transform="rotate("+e+"deg)";this.findTextTarget(t)}},l.prototype.getStrokeWidth=function(t){var e;switch(parseInt(t,10)/2){case 1:e=this.l10n.getConstant("XSmall");break;case 2:e=this.l10n.getConstant("Small");break;case 3:e=this.l10n.getConstant("Medium");break;case 4:e=this.l10n.getConstant("Large");break;case 5:e=this.l10n.getConstant("XLarge")}return e},l.prototype.updateToolbarItems=function(){var t=this.element.querySelector(".e-fill.e-template .e-dropdownbtn-preview"),i=this.element.querySelector(".e-stroke.e-template .e-dropdownbtn-preview"),s=this.element.querySelector(".e-text-font-color.e-template .e-dropdownbtn-preview"),o=this.element.querySelector(".e-pen-stroke-color.e-template .e-dropdownbtn-preview"),a=this.element.querySelector(".e-shape-stroke-width"),n=this.element.querySelector(".e-text-font-family"),r=this.element.querySelector(".e-text-font-size"),h=this.element.querySelector(".e-text-font-style");if(t&&(""===this.activeObj.strokeSettings.fillColor?t.classList.add("e-nocolor-item"):(t.classList.remove("e-nocolor-item"),t.style.background=this.activeObj.strokeSettings.fillColor),e.getComponent(this.element.id+"_shape_fill","colorpicker").value=this.activeObj.strokeSettings.fillColor+"ff"),i&&(i.style.background=this.activeObj.strokeSettings.strokeColor,e.getComponent(this.element.id+"_shape_stroke","colorpicker").value=this.activeObj.strokeSettings.strokeColor+"ff"),s&&(s.style.background=this.activeObj.strokeSettings.strokeColor,e.getComponent(this.element.id+"_text_font","colorpicker").value=this.activeObj.strokeSettings.strokeColor+"ff"),o&&(o.style.background=this.activeObj.strokeSettings.strokeColor,e.getComponent(this.element.id+"_pen_stroke","colorpicker").value=this.activeObj.strokeSettings.strokeColor+"ff"),n&&(e.Browser.isDevice?n.setAttribute("style","font-family:"+this.activeObj.textSettings.fontFamily.toLowerCase()):n.textContent=this.activeObj.textSettings.fontFamily),r)for(var l=0;l<this.fontSizeColl.length;l++)if(parseInt(this.fontSizeColl[l].text,10)>=Math.round(this.activeObj.textSettings.fontSize)){r.textContent=(l+1).toString();break}if(h&&(e.Browser.isDevice?this.activeObj.textSettings.bold||this.activeObj.textSettings.italic?this.activeObj.textSettings.bold&&this.activeObj.textSettings.italic?h.setAttribute("style","font-style: italic;font-weight: bold"):this.activeObj.textSettings.bold?h.setAttribute("style","font-weight: bold"):h.setAttribute("style","font-style: italic"):h.setAttribute("style",""):this.activeObj.textSettings.bold||this.activeObj.textSettings.italic?this.activeObj.textSettings.bold&&this.activeObj.textSettings.italic?h.textContent="Bold Italic":this.activeObj.textSettings.bold?h.textContent="Bold":h.textContent="Italic":h.textContent="Default"),a){var c=Math.round(this.activeObj.strokeSettings.strokeWidth).toString();a.textContent=this.getStrokeWidth(c)}},l.prototype.setTimer=function(t){!this.isTimer&&this.timer>10&&(this.findTextPoint(t),e.Browser.isDevice&&this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height))},l.prototype.targetTouches=function(t){return[{x:t[0].pageX,y:t[0].pageY},{x:t[1].pageX,y:t[1].pageY}]},l.prototype.calculateScale=function(t,e){var i=this.getDistance(t[0],t[1]);return this.getDistance(e[0],e[1])/i},l.prototype.getDistance=function(t,i){var s=0,o=0;return e.isNullOrUndefined(t)||e.isNullOrUndefined(i)||(s=t.x-i.x,o=t.y-i.y),Math.sqrt(s*s+o*o)},l.prototype.setXYPoints=function(t){t.preventDefault();var e,i;"mousedown"===t.type?(e=t.clientX,i=t.clientY):(this.touchEndPoint.x=e=t.touches[0].clientX,this.touchEndPoint.y=i=t.touches[0].clientY);var s=this.lowerCanvas.getBoundingClientRect();return e-=s.left,i-=s.top,{x:e,y:i}},l.prototype.touchStartHandler=function(t){t.preventDefault(),2===t.touches.length?this.isFirstMove=!0:(this.timer=setTimeout(this.setTimer.bind(this),1e3,t),this.mouseDownEventHandler(t)),e.EventHandler.add(this.lowerCanvas,"touchend",this.mouseUpEventHandler,this),e.EventHandler.add(this.lowerCanvas,"touchmove",this.mouseMoveEventHandler,this),e.EventHandler.add(this.upperCanvas,"touchend",this.mouseUpEventHandler,this),e.EventHandler.add(this.upperCanvas,"touchmove",this.mouseMoveEventHandler,this)},l.prototype.isShapeTouch=function(t,e){var i=!1;if("touchstart"===t.type){this.redrawActObj();var s=this.setXYPoints(t),o=s.x,a=s.y;i=this.findTargetObj(o,a,e)}return i},l.prototype.isFreehandDrawTouch=function(t,e){var i=!1;if("touchstart"===t.type&&!e){this.redrawActObj();var s=this.setXYPoints(t),o=s.x,a=s.y;this.setCursor(o,a),this.isFreehandDrawingPoint&&(i=!0)}return i},l.prototype.selectFreehandDraw=function(t){if(this.isFreehandDrawEditing=!0,!e.isNullOrUndefined(t)||0===t){if(!this.isFreehandDrawIndex(t))return;this.freehandDrawSelectedIndex=this.freehandDrawHoveredIndex=t,this.hoverFreehandraw(),this.upperCanvas.style.cursor="pointer"}this.freehandDrawSelectedIndex=this.freehandDrawHoveredIndex,this.pointColl[this.freehandDrawSelectedIndex].isSelected=!0,this.freehandDrawSelectedId=this.pointColl[this.freehandDrawSelectedIndex].id,"#42a5f5"!==this.pointColl[this.freehandDrawHoveredIndex].strokeColor&&(this.tempFreeHandDrawEditingStyles.strokeColor=this.pointColl[this.freehandDrawHoveredIndex].strokeColor),this.tempFreeHandDrawEditingStyles.strokeWidth=this.pointColl[this.freehandDrawHoveredIndex].strokeWidth,this.isFreehandDrawEditing?this.refreshToolbar("pen"):this.okBtn()},l.prototype.closeContextualToolbar=function(){var t=!1;return(e.isNullOrUndefined(this.element.querySelector("#"+this.element.id+"_contextualToolbar"))||this.element.querySelector("#"+this.element.id+"_contextualToolbar").parentElement.classList.contains("e-hide"))&&(e.isNullOrUndefined(this.element.querySelector("#"+this.element.id+"_headWrapper"))||this.element.querySelector("#"+this.element.id+"_headWrapper").parentElement.classList.contains("e-hide"))||(this.element.querySelector(".e-contextual-toolbar-wrapper").classList.add("e-hide"),this.okBtn(),this.refreshToolbar("main"),t=!0),t},l.prototype.mouseDownEventHandler=function(t){if("touchstart"===t.type&&(this.isTouch=!0),"touchstart"!==t.type||t.currentTarget!==this.lowerCanvas||this.isImageLoaded){var i,s=!1,o=!0;if(void 0!==this.activeObj.shape&&(i=this.activeObj.shape.split("-")),void 0!==i&&"crop"===i[0]&&(s=!0),s&&(this.dragCanvas=this.togglePan=!0),s&&this.dragCanvas){var a=(l=this.setXYPoints(t)).x,n=l.y;this.setCursor(a,n),"move"!==this.upperCanvas.style.cursor&&"crosshair"!==this.upperCanvas.style.cursor&&"default"!==this.upperCanvas.style.cursor&&"grab"!==this.upperCanvas.style.cursor&&(o=!1)}var r=this.isShapeTouch(t,s),h=this.isFreehandDrawTouch(t,s);if(r||this.togglePen||s||(this.refreshToolbar("main"),this.closeContextualToolbar()),!this.dragCanvas||!o||"grab"!==this.upperCanvas.style.cursor&&!this.isTouch||r||h||this.togglePen){var l=this.setXYPoints(t),a=l.x,n=l.y;if(this.redrawActObj(a,n),this.isFreehandDrawingPoint||this.isFreehandDrawCustomized&&!this.togglePen){if(!e.isNullOrUndefined(this.freehandDrawSelectedIndex)&&this.freehandDrawSelectedIndex!==this.freehandDrawHoveredIndex){var c=this.freehandDrawHoveredIndex;if(this.okBtn(),this.isFreehandDrawCustomized=!1,this.freehandDrawHoveredIndex=c,this.freehandDrawHoveredIndex>-1){d="#fff"===this.pointColl[this.freehandDrawHoveredIndex].strokeColor?"#42a5f5":this.pointColl[this.freehandDrawHoveredIndex].strokeColor;this.hoverFreehandraw(d,this.pointColl[this.freehandDrawHoveredIndex].strokeWidth)}}if(!e.isNullOrUndefined(this.freehandDrawHoveredIndex)&&this.freehandDrawHoveredIndex>-1)this.selectFreehandDraw();else if(this.freehandDrawSelectedIndex){this.okBtn();var d=this.pointColl[this.freehandDrawSelectedIndex].strokeColor;this.hoverFreehandraw(d,this.pointColl[this.freehandDrawSelectedIndex].strokeWidth)}}else if(this.isFreehandDrawEditing&&this.cancelFreehandDraw(),this.closeContextualToolbar(),this.isFreehandDrawEditing=!1,("crosshair"===this.upperCanvas.style.cursor||e.Browser.isDevice&&this.togglePen)&&(this.togglePen?(e.isNullOrUndefined(this.activeObj.strokeSettings)&&(this.activeObj.strokeSettings=this.strokeSettings),e.isNullOrUndefined(this.penStrokeWidth)&&(this.penStrokeWidth=2),this.upperContext.strokeStyle=this.activeObj.strokeSettings.strokeColor,this.upperContext.fillStyle=this.activeObj.strokeSettings.strokeColor,this.freehandDownHandler(t,this.upperCanvas)):(this.refreshActiveObj(),this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height)),this.currObjType.isActiveObj=!1,this.dragElement="",this.dragPoint.startX=this.dragPoint.startY=this.dragPoint.endX=this.dragPoint.endY=0),"crosshair"!==this.upperCanvas.style.cursor&&"touchstart"===t.type.toLowerCase()||this.currObjType.isActiveObj&&"default"!==this.upperCanvas.style.cursor&&!this.togglePen?(this.currObjType.isUndoAction&&this.refreshUndoRedoColl(),this.findTarget(a,n,t.type)):""!==this.currObjType.shape&&!this.currObjType.isCustomCrop||this.togglePen||"default"===this.upperCanvas.style.cursor||this.setActivePoint(a,n),!e.isNullOrUndefined(this.activeObj)){var p,v=!1;void 0!==this.activeObj.shape&&(p=this.activeObj.shape.split("-")),void 0===p&&(this.currObjType.isCustomCrop||this.togglePen)?v=!0:void 0!==p&&"crop"===p[0]&&(v=!0),"rectangle"===this.activeObj.shape||"ellipse"===this.activeObj.shape||"line"===this.activeObj.shape?this.refreshToolbar("shapes"):"text"===this.activeObj.shape?this.refreshToolbar("text"):v||this.callMainToolbar(),this.updateToolbarItems()}}else this.isFreehandDrawEditing&&this.applyFreehandDraw(),this.applyShape(),this.canvasMouseDownHandler(t);this.isShapeInserted=!1,this.tempActiveObj=e.extend({},this.activeObj,{},!0)}},l.prototype.mouseMoveEventHandler=function(t){if(t.preventDefault(),"touchmove"===t.type&&2===t.touches.length){if(this.isFirstMove)this.startTouches=this.targetTouches(t.touches),this.tempTouches=[],this.tempTouches.push({x:t.touches[0].clientX||t.touches[0].pageX-this.lowerCanvas.offsetLeft,y:t.touches[0].clientY||t.touches[0].pageY-this.lowerCanvas.offsetTop}),this.tempTouches.push({x:t.touches[1].clientX||t.touches[1].pageX-this.lowerCanvas.offsetLeft,y:t.touches[1].clientY||t.touches[1].pageY-this.lowerCanvas.offsetTop});else{var i=t.touches[0].clientX||t.touches[0].pageX-this.lowerCanvas.offsetLeft,s=t.touches[0].clientY||t.touches[0].pageY-this.lowerCanvas.offsetTop,o=t.touches[1].clientX||t.touches[1].pageX-this.lowerCanvas.offsetLeft,a=t.touches[1].clientY||t.touches[1].pageY-this.lowerCanvas.offsetTop,n=this.calculateScale(this.startTouches,this.targetTouches(t.touches));this.tempTouches[0].x!==i&&this.tempTouches[0].y!==s&&this.tempTouches[1].x!==o&&this.tempTouches[1].y!==a&&(n>1?this.zoom(1.1):this.zoom(-1.1),this.tempTouches=[],this.tempTouches.push({x:t.touches[0].clientX||t.touches[0].pageX-this.lowerCanvas.offsetLeft,y:t.touches[0].clientY||t.touches[0].pageY-this.lowerCanvas.offsetTop}),this.tempTouches.push({x:t.touches[1].clientX||t.touches[1].pageX-this.lowerCanvas.offsetLeft,y:t.touches[1].clientY||t.touches[1].pageY-this.lowerCanvas.offsetTop}))}return void(this.isFirstMove=!1)}"none"===this.textArea.style.display&&(this.isTimer=!0);var r,h;"mousemove"===t.type?(r=t.clientX,h=t.clientY):(this.touchEndPoint.x=r=t.touches[0].clientX,this.touchEndPoint.y=h=t.touches[0].clientY);var l=this.lowerCanvas.getBoundingClientRect();r-=l.left,h-=l.top,this.canvasMouseMoveHandler(t);var c,d=!1;void 0!==this.activeObj.shape&&(c=this.activeObj.shape.split("-")),void 0!==c&&"crop"===c[0]&&(d=!0),d&&this.zoomFactor>0&&this.disableZoomOutBtn(),(this.currObjType.isActiveObj&&(void 0!==this.activeObj.activePoint||this.objColl.length>0)&&!this.dragCanvas||void 0!==this.activeObj.activePoint)&&""===this.dragElement&&(this.setCursor(r,h),e.isNullOrUndefined(this.activeObj.activePoint)||0!==this.activeObj.activePoint.width||"default"===this.upperCanvas.style.cursor||"move"===this.upperCanvas.style.cursor||"crosshair"===this.upperCanvas.style.cursor||"grab"===this.upperCanvas.style.cursor||"pointer"===this.upperCanvas.style.cursor||(this.upperCanvas.style.cursor="move"),this.findTarget(r,h,t.type)),this.currObjType.isDragging&&(this.upperContext.clearRect(0,0,this.lowerCanvas.width,this.lowerCanvas.height),this.updateActivePoint(r,h,d),this.isPreventDragging?(this.activeObj.activePoint.startX>this.destLeft&&this.activeObj.activePoint.endX<this.destLeft+this.destWidth&&this.activeObj.activePoint.startY>this.destTop&&this.activeObj.activePoint.endY<this.destTop+this.destHeight&&(this.isPreventDragging=!1),this.drawObject("duplicate",null,null,null,!0)):this.drawObject("duplicate"),d&&(this.dragCanvas=this.togglePan=!0))},l.prototype.mouseUpEventHandler=function(t){"touchstart"===t.type&&(this.isTouch=!1),t.preventDefault(),this.togglePan&&this.canvasMouseUpHandler(t);var i,s;"mouseup"===t.type?(i=t.clientX,s=t.clientY):(i=this.touchEndPoint.x,s=this.touchEndPoint.y);var o=this.lowerCanvas.getBoundingClientRect();i-=o.left,s-=o.top,"touchend"===t.type&&(this.startTouches=this.tempTouches=[],this.isFirstMove=!1,"none"===this.textArea.style.display&&(this.isTimer=!1,this.timer=0));var a,n=!1;if(void 0!==this.activeObj.shape&&(a=this.activeObj.shape.split("-")),void 0!==a&&"crop"===a[0]&&(n=!0),t.currentTarget===this.upperCanvas){this.currObjType.shape=this.currObjType.shape.toLowerCase();var r=e.extend({},this.cropObj,{},!0),h=this.getCurrentObj();h.objColl=e.extend([],this.objColl,[],!0),h.pointColl=e.extend([],this.pointColl,[],!0),h.afterCropActions=e.extend([],this.afterCropActions,[],!0),this.togglePen||n?n&&!this.togglePen&&JSON.stringify(this.activeObj.activePoint)!==JSON.stringify(this.tempActiveObj.activePoint)&&(h.activeObj=e.extend([],this.tempActiveObj,{},!0),this.updateUndoRedoColl("selectionTransform",h,h.objColl,h.pointColl,r)):(e.isNullOrUndefined(this.tempObjColl)||0===this.activeObj.activePoint.width||(this.objColl.push(this.activeObj),JSON.stringify(this.activeObj.activePoint)!==JSON.stringify(this.tempActiveObj.activePoint)&&this.updateUndoRedoColl("shapeTransform",h,this.tempObjColl,h.pointColl,r),this.redrawShape(this.objColl[this.objColl.length-1]),this.tempObjColl=void 0),this.isFreehandDrawEditing||this.applyCurrActObj(i,s))}this.togglePen&&t.currentTarget===this.upperCanvas?this.freehandUpHandler(t,this.upperCanvas,this.upperContext):this.currObjType.shape="",this.dragElement="",this.currObjType.isInitialLine=this.currObjType.isDragging=!1,this.oldPoint.x=void 0,this.oldPoint.y=void 0},l.prototype.keyDownEventHandler=function(t){var i,s=this,o={},a={fileName:this.fileName,fileType:this.fileType,cancel:!1};switch(t.key){case t.ctrlKey&&"s":this.trigger("beforeSave",a,function(t){a.cancel||s.export(t.fileType,t.fileName)}),t.preventDefault(),t.stopImmediatePropagation();break;case"Delete":if(this.isFreehandDrawEditing){this.updateFreehandDrawColorChange();n=e.extend({},this.cropObj,{},!0);(r=this.getCurrentObj()).objColl=e.extend([],this.objColl,[],!0),r.pointColl=e.extend([],this.pointColl,[],!0),r.afterCropActions=e.extend([],this.afterCropActions,[],!0),this.deleteFreehandDraw(parseInt(this.freehandDrawSelectedId.split("_")[1],10)-1,!0),this.updateUndoRedoColl("deleteFreehandDrawing",r,r.objColl,r.pointColl,n)}else if("none"===this.textArea.style.display){this.objColl.push(this.activeObj);var n=e.extend({},this.cropObj,{},!0),r=this.getCurrentObj();r.objColl=e.extend([],this.objColl,[],!0),r.pointColl=e.extend([],this.pointColl,[],!0),r.afterCropActions=e.extend([],this.afterCropActions,[],!0),this.objColl.pop(),o={action:"delete",previousShapeSettings:this.updatePreviousShapeSettings(),currentShapeSettings:null},this.keyHistory="",this.clearSelection(),this.trigger("shapeChanging",o),this.refreshToolbar("main"),this.updateUndoRedoColl("deleteObj",r,r.objColl,r.pointColl,n)}break;case"Escape":this.togglePan?(this.refreshToolbar(this.currentToolbar),this.pan(!1)):"block"===this.textArea.style.display?this.redrawActObj():this.performCancel();break;case"Enter":void 0!==this.activeObj.shape&&(i=this.activeObj.shape.split("-")),void 0!==this.activeObj.horTopLine&&void 0!==this.activeObj.shape&&"crop"===i[0]&&this.crop();break;default:e.Browser.isDevice&&"block"===this.textArea.style.display&&setTimeout(this.textKeyDown.bind(this),1,t)}},l.prototype.keyUpEventHandler=function(t){"block"===this.textArea.style.display&&t.target.id===this.element.id+"_textArea"&&setTimeout(this.textKeyDown.bind(this),1,t)},l.prototype.canvasMouseDownHandler=function(t){t.preventDefault();var i,s;"mousedown"===t.type?(i=t.offsetX||t.pageX-this.lowerCanvas.offsetLeft,s=t.offsetY||t.pageY-this.lowerCanvas.offsetTop):(i=t.touches[0].clientX||t.touches[0].pageX-this.lowerCanvas.offsetLeft,s=t.touches[0].clientY||t.touches[0].pageY-this.lowerCanvas.offsetTop);var o=this.lowerCanvas.getBoundingClientRect();i-=o.left,s-=o.top,this.panDown={x:i,y:s},this.lastPan={x:this.destLeft,y:this.destTop},e.isNullOrUndefined(this.tempPanMove)&&(this.tempPanMove={x:i,y:s},this.panStartObj=this.getCurrentObj(),this.panStartObj.objColl=e.extend([],this.objColl,[],!0),this.panStartObj.pointColl=e.extend([],this.pointColl,[],!0),this.panStartObj.afterCropActions=this.afterCropActions)},l.prototype.canvasMouseMoveHandler=function(t){this.dragCanvas?this.lowerCanvas.style.cursor="grab":(this.dragCanvas=this.togglePan=!1,this.lowerCanvas.style.cursor=this.upperCanvas.style.cursor="default");var e,i;"mousemove"===t.type?(e=t.offsetX||t.pageX-this.lowerCanvas.offsetLeft,i=t.offsetY||t.pageY-this.lowerCanvas.offsetTop):(e=t.touches[0].clientX||t.touches[0].pageX-this.lowerCanvas.offsetLeft,i=t.touches[0].clientY||t.touches[0].pageY-this.lowerCanvas.offsetTop);var s=this.lowerCanvas.getBoundingClientRect();e-=s.left,i-=s.top,this.panMove={x:e,y:i},this.panDown&&this.panMove&&this.togglePan&&this.dragCanvas&&this.drawPannedImage()},l.prototype.canvasMouseUpHandler=function(t){if(t.preventDefault(),this.togglePan&&this.panDown&&this.panMove&&this.togglePan&&this.dragCanvas){var i=e.extend({},this.cropObj,{},!0);this.updateUndoRedoColl("pan",this.panStartObj,this.panStartObj.objColl,this.panStartObj.pointColl,i),this.panDown=null,this.panMove=null,this.tempPanMove=null,this.panStartObj=null}this.currObjType.isDragging=!1},l.prototype.handleScroll=function(t){var e,i,s=!1;"mousewheel"===t.type&&(e=t.clientX,i=t.clientY);var o=this.lowerCanvas.getBoundingClientRect();e-=o.left,i-=o.top,e>this.destLeft&&e<this.destLeft+this.destWidth&&i>this.destTop&&i<this.destTop+this.destHeight&&(s=!0),!0===t.ctrlKey&&s&&t.preventDefault()},l.prototype.textKeyDown=function(t){"\r"===String.fromCharCode(t.which)&&(this.textRow+=1),this.textArea.setAttribute("rows",this.textRow.toString()),this.textArea.style.height="auto",this.textArea.style.height=this.textArea.scrollHeight+"px",this.setTextBoxWidth(t),e.Browser.isDevice&&(this.textArea.style.width=parseFloat(this.textArea.style.width)+this.textArea.style.fontSize+"px");var i=this.textArea.value.split("\n");this.textRow=i.length,this.textArea.setAttribute("rows",this.textRow.toString())},l.prototype.adjustToScreen=function(){var t=this;(e.isNullOrUndefined(this.element.querySelector("#"+this.element.id+"_contextualToolbar"))||this.element.querySelector("#"+this.element.id+"_contextualToolbar").parentElement.classList.contains("e-hide"))&&(e.isNullOrUndefined(this.element.querySelector("#"+this.element.id+"_headWrapper"))||this.element.querySelector("#"+this.element.id+"_headWrapper").parentElement.classList.contains("e-hide"))||(this.element.querySelector(".e-contextual-toolbar-wrapper").classList.add("e-hide"),this.okBtn(),this.refreshToolbar("main"));var i,s=!1;void 0!==this.activeObj.shape&&(i=this.activeObj.shape.split("-")),void 0!==i&&"crop"===i[0]&&(s=!0,this.updateImageRatioForActObj(),this.objColl.push(this.activeObj),this.refreshActiveObj()),"block"===this.textArea.style.display&&this.redrawActObj();var o=this.lowerContext.filter;this.update(),this.applyActObj(),this.refreshActiveObj(),this.lowerContext.filter=this.initialAdjustmentValue=o,this.isImageLoaded&&(a.showSpinner(this.element),this.element.style.opacity="0.5"),this.lowerContext.clearRect(0,0,this.lowerCanvas.width,this.lowerCanvas.height),this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height);var n=document.querySelector("#"+this.element.id+"_canvasWrapper");e.isNullOrUndefined(n)||(n.style.width=this.element.offsetWidth+"px",n.style.height=this.element.offsetHeight+"px",e.Browser.isDevice?n.style.height=parseFloat(n.style.height)-2*this.toolbarHeight-3+"px":n.style.height=parseFloat(n.style.height)-this.toolbarHeight-3+"px");var r=this.calcMaxDimension(this.srcWidth,this.srcHeight);if(this.defaultZoomFactor>0&&(r.width+=r.width*this.defaultZoomFactor,r.height+=r.height*this.defaultZoomFactor),this.destLeft=(this.lowerCanvas.clientWidth-r.width)/2,this.destTop=(this.lowerCanvas.clientHeight-r.height)/2,0===this.degree&&""===this.currFlipState)this.defaultZoomFactor>0&&(this.destLeft+=this.totalPannedPoint.x,this.destTop+=this.totalPannedPoint.y),this.drawImgToCanvas(r);else{this.drawImgToCanvas(r),this.updateCurrentTransformedState("initial");var h=this.lowerContext.filter;this.updateBrightnessFilter(),this.lowerContext.drawImage(this.baseImg,this.srcLeft,this.srcTop,this.srcWidth,this.srcHeight,this.destLeft,this.destTop,this.destWidth,this.destHeight),this.lowerContext.filter=h,this.updateCurrentTransformedState("reverse")}if(this.zoomObjColl(),this.zoomFreehandDrawColl(),this.isCircleCrop&&this.cropCircle(this.lowerContext),a.hideSpinner(this.element),this.element.style.opacity="1",this.defToolbarItems.length>0&&!e.isNullOrUndefined(document.getElementById(this.element.id+"_toolbar"))&&(e.getComponent(t.element.id+"_toolbar","toolbar").refreshOverflow(),e.isNullOrUndefined(this.element.querySelector(".e-contextual-toolbar-wrapper"))||this.element.querySelector(".e-contextual-toolbar-wrapper").classList.add("e-hide")),this.refreshActiveObj(),this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),s&&(this.activeObj=e.extend({},this.objColl[this.objColl.length-1],null,!0),this.objColl.pop(),this.drawObject("duplicate",this.activeObj)),(0!==this.degree||""!==this.currFlipState)&&this.defaultZoomFactor>0){var l=e.extend({},this.totalPannedPoint,null,!0),c=e.extend({},this.totalPannedInternalPoint,null,!0),d=e.extend({},this.totalPannedClientPoint,null,!0);this.zoom(.1),this.zoom(-.1),0===this.degree?(this.destLeft+=l.x,this.destTop+=l.y,this.totalPannedPoint=l,this.updateFlipPan()):(this.totalPannedInternalPoint=c,this.totalPannedClientPoint=d,this.currentPannedPoint={x:0,y:0},this.isCropTab=!0,this.rotatePan(),this.isCropTab=!1)}else 0!==this.degree&&this.cropZoomFactor>0&&(this.zoomFactor=this.cropZoomFactor=0,this.enableDisableToolbarBtn())},l.prototype.screenOrientation=function(){e.Browser.isDevice&&setTimeout(this.adjustToScreen.bind(this),100)},l.prototype.windowResizeHandler=function(){e.Browser.isDevice||this.adjustToScreen()},l.prototype.updatePreviousShapeSettings=function(){var t=[];return"text"!==this.activeObj.shape||e.isNullOrUndefined(this.activeObj.textSettings)||(this.activeObj.textSettings.bold&&t.push("bold"),this.activeObj.textSettings.italic&&t.push("italic"),this.activeObj.textSettings.underline&&t.push("underline")),{id:e.isNullOrUndefined(this.activeObj.currIndex)?null:this.activeObj.currIndex,type:this.toPascalCase(this.activeObj.shape),startX:this.activeObj.activePoint.startX,startY:this.activeObj.activePoint.startY,width:this.activeObj.activePoint.width,height:this.activeObj.activePoint.height,strokeColor:e.isNullOrUndefined(this.activeObj.strokeSettings)?null:this.activeObj.strokeSettings.strokeColor,strokeWidth:e.isNullOrUndefined(this.activeObj.strokeSettings)?null:this.activeObj.strokeSettings.strokeWidth,fillColor:e.isNullOrUndefined(this.activeObj.strokeSettings)?null:this.activeObj.strokeSettings.fillColor,radius:"ellipse"===this.activeObj.shape?this.activeObj.activePoint.width/2:null,length:"line"===this.activeObj.shape?this.activeObj.activePoint.width:null,text:"text"===this.activeObj.shape?e.isNullOrUndefined(this.activeObj.keyHistory)?null:this.activeObj.keyHistory:null,fontSize:"text"===this.activeObj.shape?e.isNullOrUndefined(this.activeObj.textSettings)?null:this.activeObj.textSettings.fontSize:null,fontStyle:"text"===this.activeObj.shape?t:null,color:"text"===this.activeObj.shape?e.isNullOrUndefined(this.activeObj.strokeSettings)?null:this.activeObj.strokeSettings.strokeColor:null}},l.prototype.disableZoomOutBtn=function(){var t=!1,i=document.querySelector("#"+this.element.id+"_zoomOut"),s=this.destLeft,o=this.destTop,a=this.destWidth,n=this.destHeight;return 0!==this.degree&&180!==this.degree||(e.isNullOrUndefined(this.activeObj.shape)?this.setZoomDimension(-.1,null):(this.setZoomDimension(-.1,this.activeObj),this.destLeft>this.activeObj.activePoint.startX||this.destTop>this.activeObj.activePoint.startY||this.destLeft+this.destWidth<this.activeObj.activePoint.endX||this.destTop+this.destHeight<this.activeObj.activePoint.endY?(i.classList.add("e-disabled"),i.parentElement.classList.add("e-overlay"),t=!0):(i.classList.remove("e-disabled"),i.parentElement.classList.remove("e-overlay"),t=!1))),this.destLeft=s,this.destTop=o,this.destWidth=a,this.destHeight=n,t},l.prototype.setZoomDimension=function(t,i){var s={width:0,height:0};return s=this.degree%90==0&&this.degree%180!=0?this.calcMaxDimension(this.srcHeight,this.srcWidth):this.calcMaxDimension(this.srcWidth,this.srcHeight),s.width+=s.width*this.zoomFactor,s.height+=s.height*this.zoomFactor,this.destLeft+=(this.destWidth-s.width)/2,this.destTop+=(this.destHeight-s.height)/2,t<0&&!e.isNullOrUndefined(i)?(this.destLeft>i.activePoint.startX&&(this.destLeft=i.activePoint.startX),this.destTop>i.activePoint.startY&&(this.destTop=i.activePoint.startY),this.destLeft+s.width<i.activePoint.startX+i.activePoint.width&&(this.destLeft=this.destLeft+(i.activePoint.startX+i.activePoint.width)-(this.destLeft+s.width)),this.destTop+s.height<i.activePoint.startY+i.activePoint.height&&(this.destTop=this.destTop+(i.activePoint.startY+i.activePoint.height)-(this.destTop+s.height))):t<0&&e.isNullOrUndefined(i)&&(this.destLeft>0&&(this.destLeft=0),this.destTop>0&&(this.destTop=0),this.destLeft+s.width<this.lowerCanvas.width&&(this.destLeft=this.lowerCanvas.width-this.destWidth),this.destTop+s.height<this.lowerCanvas.height&&(this.destTop=this.lowerCanvas.height-this.destHeight)),s},l.prototype.applyCurrActObj=function(t,i){var s=!1,o=e.extend({},this.activeObj,{},!0);if(!e.isNullOrUndefined(o.activePoint)&&(t>=Math.floor(o.activePoint.startX)&&t<=Math.ceil(o.activePoint.endX)&&i>=Math.floor(o.activePoint.startY)&&i<=Math.ceil(o.activePoint.endY)&&(s=!0),!s)){if(this.updateImageRatioForActObj(),void 0===this.activeObj.horTopLine||0===this.activeObj.horTopLine.startX||0===this.activeObj.horTopLine.endX||this.currObjType.isCustomCrop||""===this.currObjType.shape||this.objColl.push(e.extend({},this.activeObj,{},!0)),"text"===this.activeObj.shape||"ellipse"===this.currObjType.shape||"rectangle"===this.currObjType.shape||"line"===this.currObjType.shape){var a=this.lowerContext.filter;this.lowerContext.filter=this.getDefaultFilter();for(var n=0;n<this.objColl.length;n++)this.isObjInsideCropRegion(this.objColl[n])&&(this.apply(this.objColl[n].shape,this.objColl[n]),this.refreshActiveObj());this.zoomFreehandDrawColl(),this.lowerContext.filter=a,this.apply("shape"),this.clearOuterCanvas(this.lowerContext),this.clearOuterCanvas(this.upperContext),this.isCircleCrop&&this.cropCircle(this.lowerContext)}this.refreshToolbar("main")}},l.prototype.updateTextFromTextArea=function(){if(this.activeObj.keyHistory!==this.textArea.value){var t=e.extend({},this.cropObj,{},!0),i=this.getCurrentObj();i.objColl=e.extend([],this.objColl,[],!0),i.pointColl=e.extend([],this.pointColl,[],!0),i.afterCropActions=e.extend([],this.afterCropActions,[],!0),this.updateUndoRedoColl("text",i,i.objColl,i.pointColl,t,this.activeObj.keyHistory,this.textArea.value)}this.activeObj.keyHistory=this.textArea.value,this.textArea.style.display="none",this.textArea.value="",this.updateFontStyles();var s=this.upperContext.measureText(this.activeObj.keyHistory).width+.5*this.activeObj.textSettings.fontSize,o=this.activeObj.textSettings.fontSize+.25*this.activeObj.textSettings.fontSize,a=this.activeObj.keyHistory.split("\n");if(a.length>1){o*=a.length;for(var n=[],r=0;r<a.length;r++)n.push(this.upperContext.measureText(a[r]).width+.5*this.activeObj.textSettings.fontSize);s=Math.max.apply(Math,n)}this.setTextSelection(s,o),this.updateActiveObject(this.activeObj.activePoint,this.activeObj),this.updateImageRatioForActObj()},l.prototype.setTextBoxStylesToActObj=function(){this.activeObj.textSettings.fontFamily=this.textArea.style.fontFamily,this.activeObj.strokeSettings.strokeColor=this.textArea.style.color,"bold"===this.textArea.style.fontWeight?this.activeObj.textSettings.bold=!0:this.activeObj.textSettings.bold=!1,"italic"===this.textArea.style.fontStyle?this.activeObj.textSettings.italic=!0:this.activeObj.textSettings.italic=!1,this.activeObj.textSettings.fontSize=parseFloat(this.textArea.style.fontSize)},l.prototype.redrawActObj=function(t,e){var i;void 0!==this.activeObj.shape&&(i=this.activeObj.shape.split("-")),void 0!==this.activeObj.horTopLine&&void 0!==this.activeObj.shape&&"crop"!==i[0]&&("block"===this.textArea.style.display?(this.setTextBoxStylesToActObj(),this.updateFontRatio(this.activeObj,!0),t&&e?t!==this.activeObj.activePoint.startX&&e!==this.activeObj.activePoint.startY&&(this.updateTextFromTextArea(),this.applyActObj()):(this.updateTextFromTextArea(),this.apply(this.activeObj.shape,this.activeObj),this.objColl.push(this.activeObj),this.refreshActiveObj(),this.textArea.style.transform="",this.refreshToolbar("main"))):this.applyActObj())},l.prototype.setTextBoxPos=function(t,e,i,s,o){var a={x:s,y:o};return 0===e?"horizontal"===i.toLowerCase()?(a.x=t.activePoint.endX,a.y=t.activePoint.startY):"vertical"===i.toLowerCase()?(a.x=t.activePoint.startX,a.y=t.activePoint.endY):(a.x=t.activePoint.startX,a.y=t.activePoint.startY):90===e?"horizontal"===i.toLowerCase()?(a.x=t.activePoint.startX,a.y=t.activePoint.startY):"vertical"===i.toLowerCase()?(a.x=t.activePoint.endX,a.y=t.activePoint.endY):(a.x=t.activePoint.endX,a.y=t.activePoint.startY):180===e?"horizontal"===i.toLowerCase()?(a.x=t.activePoint.startX,a.y=t.activePoint.endY):"vertical"===i.toLowerCase()?(a.x=t.activePoint.endX,a.y=t.activePoint.startY):(a.x=t.activePoint.endX,a.y=t.activePoint.endY):270===e&&("horizontal"===i.toLowerCase()?(a.x=t.activePoint.endX,a.y=t.activePoint.endY):"vertical"===i.toLowerCase()?(a.x=t.activePoint.startX,a.y=t.activePoint.startY):(a.x=t.activePoint.startX,a.y=t.activePoint.endY)),a},l.prototype.setTextBoxPoints=function(t,e,i,s,o){var a={x:s,y:o};return 0===e?"horizontal"===t.flipObjColl[0].toLowerCase()?"horizontal"===i.toLowerCase()?(a.x=t.activePoint.startX,a.y=t.activePoint.startY):"vertical"===i.toLowerCase()&&(a.x=t.activePoint.endX,a.y=t.activePoint.endY):"horizontal"===i.toLowerCase()?(a.x=t.activePoint.endX,a.y=t.activePoint.endY):"vertical"===i.toLowerCase()&&(a.x=t.activePoint.endX,a.y=t.activePoint.startY):90===e?"horizontal"===t.flipObjColl[0].toLowerCase()?"horizontal"===i.toLowerCase()?(a.x=t.activePoint.endX,a.y=t.activePoint.endY):"vertical"===i.toLowerCase()&&(a.x=t.activePoint.startX,a.y=t.activePoint.endY):"horizontal"===i.toLowerCase()?(a.x=t.activePoint.startX,a.y=t.activePoint.endY):"vertical"===i.toLowerCase()&&(a.x=t.activePoint.startX,a.y=t.activePoint.startY):180===e?"horizontal"===t.flipObjColl[0].toLowerCase()?"horizontal"===i.toLowerCase()?(a.x=t.activePoint.startX,a.y=t.activePoint.startY):"vertical"===i.toLowerCase()&&(a.x=t.activePoint.startX,a.y=t.activePoint.startY):"horizontal"===i.toLowerCase()?(a.x=t.activePoint.startX,a.y=t.activePoint.startY):"vertical"===i.toLowerCase()&&(a.x=t.activePoint.startX,a.y=t.activePoint.endY):270===e&&("horizontal"===t.flipObjColl[0].toLowerCase()?"horizontal"===i.toLowerCase()?(a.x=t.activePoint.startX,a.y=t.activePoint.startY):"vertical"===i.toLowerCase()&&(a.x=t.activePoint.endX,a.y=t.activePoint.startY):"horizontal"===i.toLowerCase()?(a.x=t.activePoint.endX,a.y=t.activePoint.startY):"vertical"===i.toLowerCase()&&(a.x=t.activePoint.endX,a.y=t.activePoint.endY)),a},l.prototype.findTextTarget=function(t){var i,s;if("dblclick"===t.type?(i=t.clientX,s=t.clientY):"touchstart"===t.type&&(this.touchEndPoint.x=i=t.touches[0].clientX,this.touchEndPoint.y=s=t.touches[0].clientY),this.preventZoomBtn=!0,this.refreshToolbar("text"),this.preventZoomBtn=!1,this.updateToolbarItems(),e.isNullOrUndefined(i)||e.isNullOrUndefined(s)){if("block"===this.textArea.style.display&&""!==this.selectedText()&&"mousedown"===t.type){r=this.textArea.value;this.textArea.value+="a",this.textArea.value=r}}else{var o=this.lowerCanvas.getBoundingClientRect();i-=o.left,s-=o.top;var a=void 0,n="";(a=0===this.activeObj.shapeDegree?this.degree:this.degree-this.activeObj.shapeDegree)<0&&(a=360+a),n=""===this.activeObj.textFlip?this.activeObj.textFlip===this.currFlipState?"":this.currFlipState:this.activeObj.textFlip===this.currFlipState?"":""===this.currFlipState?this.activeObj.textFlip:this.currFlipState;var r=void 0;if("none"===this.textArea.style.display){r=e.extend({},this.activeObj,{},!0);for(var h=0;h<this.objColl.length;h++)JSON.stringify(this.activeObj)===JSON.stringify(this.objColl[h])&&this.objColl.splice(h,1);this.refreshActiveObj(),this.lowerContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),this.redrawImgWithObj(),(!e.isNullOrUndefined(this.currSelectionPoint)&&"crop-circle"===this.currSelectionPoint.shape||this.isCircleCrop)&&this.cropCircle(this.lowerContext),this.activeObj=r,this.updateFontStyles();var l=e.extend({},this.activeObj,{},!0);if(i>=l.activePoint.startX-2*l.topLeftCircle.radius&&i<=l.activePoint.endX+2*l.topLeftCircle.radius&&s>=l.activePoint.startY-2*l.topLeftCircle.radius&&s<=l.activePoint.endY+2*l.topLeftCircle.radius){if(this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),4===l.flipObjColl.length&&(l.flipObjColl=[],n=""),""===n&&l.flipObjColl.length>1&&(n=l.flipObjColl[l.flipObjColl.length-1]),l.flipObjColl.length<=1)i=(c=this.setTextBoxPos(l,a,n,i,s)).x,s=c.y;else{var c=this.setTextBoxPoints(l,a,n,i,s);i=c.x,s=c.y}this.textArea.style.display="block",this.textArea.style.left=i+"px",this.textArea.style.top=s+"px",this.textArea.style.fontFamily=l.textSettings.fontFamily,this.textArea.style.fontSize=l.textSettings.fontSize+"px",this.textArea.style.color=l.strokeSettings.strokeColor,this.textArea.style.fontWeight=l.textSettings.bold?"bold":"normal",this.textArea.style.fontStyle=l.textSettings.italic?"italic":"normal",this.textArea.style.border="2px solid "+this.themeColl[this.theme].primaryColor,this.textArea.value=l.keyHistory,this.textArea.style.overflow="hidden",this.textArea.style.height="auto",this.textArea.focus(),a%90==0&&a%180!=0&&0!==a?(this.zoomFactor,this.textArea.style.width=l.activePoint.height+"px",this.textArea.style.height=l.activePoint.width+"px"):(this.zoomFactor,this.textArea.style.width=l.activePoint.width+"px",this.textArea.style.height=l.activePoint.height+"px"),this.setTextBoxWidth(),this.flipColl.length<=1&&this.setTextBoxHeight()}else this.applyActObj()}}},l.prototype.selectedText=function(){var t=this.textArea.selectionStart,e=this.textArea.selectionEnd;return this.textArea.value.substring(t,e)},l.prototype.setTextBoxHeight=function(){var t,i,s="",o=e.extend({},this.activeObj,{},!0);(i=0===o.shapeDegree?this.degree:this.degree-o.shapeDegree)<0&&(i=360+i),s=""===o.textFlip?o.textFlip===this.currFlipState?"":this.currFlipState:o.textFlip===this.currFlipState?"":""===this.currFlipState?o.textFlip:this.currFlipState,0===i?"vertical"===s.toLowerCase()?this.textArea.style.maxHeight=this.destHeight-(this.destHeight-parseFloat(this.textArea.style.top))+"px":(t=parseFloat(this.textArea.style.top)-this.destTop,this.textArea.style.maxHeight=this.destHeight-t+"px"):90===i?"horizontal"===s.toLowerCase()?this.textArea.style.maxHeight=this.destWidth-(parseFloat(this.textArea.style.left)-this.destLeft)+"px":this.textArea.style.maxHeight=parseFloat(this.textArea.style.left)-this.destLeft+"px":180===i?"vertical"===s.toLowerCase()?(t=parseFloat(this.textArea.style.top)-this.destTop,this.textArea.style.maxHeight=this.destHeight-t+"px"):this.textArea.style.maxHeight=parseFloat(this.textArea.style.top)-this.destTop+"px":270===i&&("horizontal"===s.toLowerCase()?this.textArea.style.maxHeight=parseFloat(this.textArea.style.left)-this.destLeft+"px":this.textArea.style.maxHeight=this.destWidth-(parseFloat(this.textArea.style.left)-this.destLeft)+"px")},l.prototype.setTextBoxWidth=function(t){var i=this.getMaxText(!0);"block"===this.textArea.style.display?this.updateFontStyles(!0):this.updateFontStyles();var s,o=this.upperContext.measureText(i).width+parseFloat(this.textArea.style.fontSize)/2,a=t?this.upperContext.measureText(String.fromCharCode(t.which)).width:0,n=e.extend({},this.activeObj,{},!0),r="";(s=0===n.shapeDegree?this.degree:this.degree-n.shapeDegree)<0&&(s=360+s),r=n.shapeFlip!==this.currFlipState?"":this.currFlipState,(!e.isNullOrUndefined(t)&&parseFloat(this.textArea.style.width)<o+a||e.isNullOrUndefined(t))&&(0===s?"horizontal"===r.toLowerCase()?parseFloat(this.textArea.style.left)-this.destLeft-o-a>0&&(this.textArea.style.width=o+a+"px"):this.destWidth-(parseFloat(this.textArea.style.left)-this.destLeft)>o+a&&(this.textArea.style.width=o+a+"px"):90===s?"vertical"===r.toLowerCase()?parseFloat(this.textArea.style.top)-this.destTop-o-a>0&&(this.textArea.style.width=o+a+"px"):this.destWidth-(parseFloat(this.textArea.style.top)-this.destTop)>o+a&&(this.textArea.style.width=o+a+"px"):180===s?"horizontal"===r.toLowerCase()?this.destWidth-(parseFloat(this.textArea.style.left)-this.destLeft)>o+a&&(this.textArea.style.width=o+a+"px"):parseFloat(this.textArea.style.left)-this.destLeft-o-a>0&&(this.textArea.style.width=o+a+"px"):270===s&&("vertical"===r.toLowerCase()?this.destHeight-(parseFloat(this.textArea.style.top)-this.destTop)>o+a&&(this.textArea.style.width=o+a+"px"):parseFloat(this.textArea.style.top)-this.destTop-o-a>0&&(this.textArea.style.width=o+a+"px")))},l.prototype.setActivePoint=function(t,i){if(!e.isNullOrUndefined(this.activeObj.activePoint))if(this.currObjType.isText){var s=t||0,o=i||this.activeObj.textSettings.fontSize;void 0===this.activeObj.textSettings.fontSize&&(this.activeObj.textSettings.fontSize=.1*Math.abs(this.baseImg.width-this.baseImg.height)),this.setTextSelection(s,o),this.mouseDownPoint.x=this.activeObj.activePoint.endX,this.mouseDownPoint.y=this.activeObj.activePoint.endY,void 0!==this.activeObj.horTopLine&&(this.activeObj.activePoint=e.extend({},this.activeObj.activePoint,{},!0)),this.drawObject("duplicate")}else if(t&&i)this.activeObj.activePoint.startX=this.mouseDownPoint.x=t,this.activeObj.activePoint.startY=this.mouseDownPoint.y=i,this.currObjType.isDragging=!0;else{var a=this.activeObj;this.activeObj.activePoint={startX:a.horTopLine.startX,startY:a.horTopLine.startY,endX:a.horTopLine.endX,endY:a.horTopLine.endY},this.activeObj.activePoint.width=this.activeObj.activePoint.endX-this.activeObj.activePoint.startX,this.activeObj.activePoint.height=this.activeObj.activePoint.endY-this.activeObj.activePoint.startY}},l.prototype.setDragWidth=function(t){var e=t;if(e>=0)for(i=0;i<e&&(t=e-i,this.activeObj.activePoint.startX+=t,this.activeObj.activePoint.endX+=t,!(this.activeObj.activePoint.startX>=this.destLeft&&this.activeObj.activePoint.endX<=this.destLeft+this.destWidth));i++)this.activeObj.activePoint.startX-=t,this.activeObj.activePoint.endX-=t;else for(var i=1;i<Math.abs(e)&&(t=e+i,this.activeObj.activePoint.startX+=t,this.activeObj.activePoint.endX+=t,!(this.activeObj.activePoint.startX>=this.destLeft&&this.activeObj.activePoint.endX<=this.destLeft+this.destWidth));i++)this.activeObj.activePoint.startX-=t,this.activeObj.activePoint.endX-=t},l.prototype.setDragHeight=function(t){var e=t;if(e>=0)for(i=1;i<e&&(t=e-i,this.activeObj.activePoint.startY+=t,this.activeObj.activePoint.endY+=t,!(this.activeObj.activePoint.startY>=this.destTop&&this.activeObj.activePoint.endY<=this.destTop+this.destHeight));i++)this.activeObj.activePoint.startY-=t,this.activeObj.activePoint.endY-=t;else for(var i=0;i<Math.abs(e)&&(t=e+i,this.activeObj.activePoint.startY+=t,this.activeObj.activePoint.endY+=t,!(this.activeObj.activePoint.startY>=this.destTop&&this.activeObj.activePoint.endY<=this.destTop+this.destHeight));i++)this.activeObj.activePoint.startY-=t,this.activeObj.activePoint.endY-=t},l.prototype.triggerShapeChange=function(t,e,i){this.activeObj.activePoint.width=this.activeObj.activePoint.endX-this.activeObj.activePoint.startX,this.activeObj.activePoint.height=this.activeObj.activePoint.endY-this.activeObj.activePoint.startY;var s=this.updatePreviousShapeSettings();t.currentShapeSettings=s,e.currentShapeSettings=s,"resize"===i?(this.trigger("shapeChanging",t),this.updateShapeChangeEventArgs(t.currentShapeSettings)):(this.trigger("shapeChanging",e),this.updateShapeChangeEventArgs(e.currentShapeSettings))},l.prototype.updateActivePoint=function(t,e,i){var s=this.calcMaxDimension(this.activeObj.activePoint.width,this.activeObj.activePoint.height),o=this.updatePreviousShapeSettings(),a={action:"resize",previousShapeSettings:o},n={action:"move",previousShapeSettings:o};switch("text"===this.activeObj.shape&&""!==this.dragElement&&this.updateFontRatio(this.activeObj),this.dragElement.toLowerCase()){case"nw-resize":this.updateNWPoints(t,e,s),this.triggerShapeChange(a,n,"resize");break;case"n-resize":this.updateNPoints(t,e),this.triggerShapeChange(a,n,"resize");break;case"ne-resize":this.updateNEPoints(t,e,s),this.triggerShapeChange(a,n,"resize");break;case"w-resize":this.updateWPoints(t,e),this.triggerShapeChange(a,n,"resize");break;case"e-resize":this.updateEPoints(t,e),this.triggerShapeChange(a,n,"resize");break;case"sw-resize":this.updateSWPoints(t,e,s),this.triggerShapeChange(a,n,"resize");break;case"s-resize":this.updateSPoints(t,e),this.triggerShapeChange(a,n,"resize");break;case"se-resize":this.updateSEPoints(t,e,s),this.triggerShapeChange(a,n,"resize");break;default:if(!i&&!this.currObjType.isCustomCrop){if(this.dragPoint.startX){var r=this.dragPoint.endX-this.previousPoint.x,h=this.dragPoint.endY-this.previousPoint.y;this.activeObj.activePoint.startX+=r,this.activeObj.activePoint.endX+=r,this.activeObj.activePoint.startY+=h,this.activeObj.activePoint.endY+=h,!this.isPreventDragging&&(this.activeObj.activePoint.startX<this.destLeft||this.activeObj.activePoint.startY<this.destTop||this.activeObj.activePoint.endX>this.destLeft+this.destWidth||this.activeObj.activePoint.endY>this.destTop+this.destHeight)&&(this.activeObj.activePoint.startX-=r,this.activeObj.activePoint.endX-=r,this.activeObj.activePoint.startY-=h,this.activeObj.activePoint.endY-=h,this.setDragWidth(r),this.setDragHeight(h))}else this.activeObj.activePoint.startX=t<this.mouseDownPoint.x?t:this.mouseDownPoint.x,this.activeObj.activePoint.startY=e<this.mouseDownPoint.y?e:this.mouseDownPoint.y,t=t<this.mouseDownPoint.x?this.mouseDownPoint.x:t,e=e<this.mouseDownPoint.y?this.mouseDownPoint.y:e,this.activeObj.activePoint.endX=t,this.activeObj.activePoint.endY=e;this.triggerShapeChange(a,n,"move")}}},l.prototype.preventDraggingInvertly=function(){this.isPreventDragging||(this.activeObj.activePoint.startX<this.destLeft&&(this.activeObj.activePoint.startX=this.destLeft),this.activeObj.activePoint.startY<this.destTop&&(this.activeObj.activePoint.startY=this.destTop),this.activeObj.activePoint.endX>this.destLeft+this.destWidth&&(this.activeObj.activePoint.endX=this.destLeft+this.destWidth),this.activeObj.activePoint.endY>this.destTop+this.destHeight&&(this.activeObj.activePoint.endY=this.destTop+this.destHeight))},l.prototype.updateNWPoints=function(t,i,s){var o,a,n,r,h=this.diffPoint.x,l=this.diffPoint.y,c=e.extend({},this.activeObj,null,!0);if("text"===this.activeObj.shape)void 0===this.oldPoint.x&&void 0===this.oldPoint.y?(this.diffPoint.x=this.activeObj.activePoint.startX-t,this.diffPoint.y=this.activeObj.activePoint.startY-i):(this.diffPoint.x=this.oldPoint.x-t,this.diffPoint.y=this.oldPoint.y-i),this.oldPoint.x=t,this.oldPoint.y=i,r=(this.diffPoint.x<=h&&this.diffPoint.y>=l?Math.min(this.diffPoint.x,this.diffPoint.y):Math.max(this.diffPoint.x,this.diffPoint.y))/10,this.activeObj.activePoint.startX-=s.width/100*r,this.activeObj.activePoint.startY-=s.height/100*r,this.activeObj.activePoint.width=this.activeObj.activePoint.endX-this.activeObj.activePoint.startX,this.activeObj.activePoint.height=this.activeObj.activePoint.endY-this.activeObj.activePoint.startY,this.updateFontSize(this.activeObj);else{var d=void 0;if(void 0!==this.activeObj.shape&&(d=this.activeObj.shape.split("-")),"crop-custom"===this.activeObj.shape||void 0!==this.activeObj.shape&&"crop"!==d[0]){if(this.activeObj.activePoint.startX=t,this.activeObj.activePoint.startY=i,this.activeObj.activePoint.startX>this.activeObj.activePoint.endX){p=this.activeObj.activePoint.startX;this.activeObj.activePoint.startX=this.activeObj.activePoint.endX,this.activeObj.activePoint.endX=p,this.dragElement="ne-resize"}if(this.activeObj.activePoint.startY>this.activeObj.activePoint.endY){var p=this.activeObj.activePoint.startY;this.activeObj.activePoint.startY=this.activeObj.activePoint.endY,this.activeObj.activePoint.endY=p,this.dragElement="sw-resize"}this.preventDraggingInvertly()}else if(this.activeObj.activePoint.startX<t&&this.activeObj.activePoint.startY<i){o=t-this.activeObj.activePoint.startX,a=i-this.activeObj.activePoint.startY,n=Math.min(o,a);u=this.getScaleRatio(n);this.activeObj.activePoint.startX+=u.x,this.activeObj.activePoint.startY+=u.y;var v=this.destLeft>0?this.destLeft:0,b=this.destTop>0?this.destTop:0;(this.activeObj.activePoint.startX<v||this.activeObj.activePoint.startY<b)&&(this.activeObj.activePoint.startX-=u.x,this.activeObj.activePoint.startY-=u.y)}else{o=this.activeObj.activePoint.startX-t,a=i-this.activeObj.activePoint.endY,n=Math.max(o,a);var u=this.getScaleRatio(n);this.activeObj.activePoint.startX-=u.x,this.activeObj.activePoint.startY-=u.y;var v=this.destLeft>0?this.destLeft:0,C=this.destTop>0?this.destTop:0;(this.activeObj.activePoint.startX<v||this.activeObj.activePoint.startY<C)&&(this.activeObj.activePoint.startX+=u.x,this.activeObj.activePoint.startY+=u.y)}this.activeObj.activePoint.width=this.activeObj.activePoint.endX-this.activeObj.activePoint.startX,this.activeObj.activePoint.height=this.activeObj.activePoint.endY-this.activeObj.activePoint.startY,this.preventInverseResize(c)}},l.prototype.updateNPoints=function(t,e){var i,s,o;if("text"!==this.activeObj.shape){var a=void 0;if(void 0!==this.activeObj.shape&&(a=this.activeObj.shape.split("-")),"crop-custom"===this.activeObj.shape||void 0!==this.activeObj.shape&&"crop"!==a[0]){if(this.activeObj.activePoint.startY=e,this.activeObj.activePoint.height=this.activeObj.activePoint.endY-this.activeObj.activePoint.startY,this.activeObj.activePoint.startY>this.activeObj.activePoint.endY){var n=this.activeObj.activePoint.startY;this.activeObj.activePoint.startY=this.activeObj.activePoint.endY,this.activeObj.activePoint.endY=n,this.dragElement="s-resize"}this.preventDraggingInvertly()}else{if(this.activeObj.activePoint.endX>t&&this.activeObj.activePoint.startY<e){i=this.activeObj.activePoint.endX-t,s=e-this.activeObj.activePoint.startY,o=Math.min(i,s);r=this.getScaleRatio(o);this.activeObj.activePoint.endX-=r.x,this.activeObj.activePoint.startY+=r.y,(this.activeObj.activePoint.endX>this.destLeft+this.destWidth||this.activeObj.activePoint.startY<this.destTop)&&(this.activeObj.activePoint.endX+=r.x,this.activeObj.activePoint.startY-=r.y)}else{i=t-this.activeObj.activePoint.endX,s=this.activeObj.activePoint.startY-e,o=Math.max(i,s);var r=this.getScaleRatio(o);this.activeObj.activePoint.endX+=r.x,this.activeObj.activePoint.startY-=r.y,(this.activeObj.activePoint.endX>this.destLeft+this.destWidth||this.activeObj.activePoint.startY<this.destTop)&&(this.activeObj.activePoint.endX-=r.x,this.activeObj.activePoint.startY+=r.y)}this.activeObj.activePoint.width=this.activeObj.activePoint.endX-this.activeObj.activePoint.startX,this.activeObj.activePoint.height=this.activeObj.activePoint.endY-this.activeObj.activePoint.startY}}},l.prototype.updateNEPoints=function(t,i,s){var o,a,n,r,h=this.diffPoint.x,l=this.diffPoint.y,c=e.extend({},this.activeObj,null,!0);if("text"===this.activeObj.shape)void 0===this.oldPoint.x&&void 0===this.oldPoint.y?(this.diffPoint.x=t-this.activeObj.activePoint.endX,this.diffPoint.y=this.activeObj.activePoint.startY-i):(this.diffPoint.x=t-this.oldPoint.x,this.diffPoint.y=this.oldPoint.y-i),this.oldPoint.x=t,this.oldPoint.y=i,r=(this.diffPoint.x<=h&&this.diffPoint.y>=l?Math.min(this.diffPoint.x,this.diffPoint.y):Math.max(this.diffPoint.x,this.diffPoint.y))/10,this.activeObj.activePoint.endX+=s.width/100*r,this.activeObj.activePoint.startY-=s.height/100*r,this.activeObj.activePoint.width=this.activeObj.activePoint.endX-this.activeObj.activePoint.startX,this.activeObj.activePoint.height=this.activeObj.activePoint.endY-this.activeObj.activePoint.startY,this.updateFontSize(this.activeObj);else{var d=void 0;if(void 0!==this.activeObj.shape&&(d=this.activeObj.shape.split("-")),this.currObjType.isCustomCrop||void 0!==this.activeObj.shape&&"crop"!==d[0]){if(this.activeObj.activePoint.endX=t,this.activeObj.activePoint.startY=i,this.activeObj.activePoint.endX<this.activeObj.activePoint.startX){p=this.activeObj.activePoint.endX;this.activeObj.activePoint.endX=this.activeObj.activePoint.startX,this.activeObj.activePoint.startX=p,this.dragElement="nw-resize"}if(this.activeObj.activePoint.startY>this.activeObj.activePoint.endY){var p=this.activeObj.activePoint.startY;this.activeObj.activePoint.startY=this.activeObj.activePoint.endY,this.activeObj.activePoint.endY=p,this.dragElement="se-resize"}this.preventDraggingInvertly()}else if(this.activeObj.activePoint.endX>t&&this.activeObj.activePoint.startY<i){o=this.activeObj.activePoint.endX-t,a=i-this.activeObj.activePoint.startY,n=Math.min(o,a);u=this.getScaleRatio(n);this.activeObj.activePoint.endX-=u.x,this.activeObj.activePoint.startY+=u.y;var v=this.destLeft+this.destWidth<this.lowerCanvas.width?this.destLeft+this.destWidth:this.lowerCanvas.width,b=this.destTop>0?this.destTop:0;(this.activeObj.activePoint.endX>v||this.activeObj.activePoint.startY<b)&&(this.activeObj.activePoint.endX+=u.x,this.activeObj.activePoint.startY-=u.y)}else{o=t-this.activeObj.activePoint.endX,a=this.activeObj.activePoint.startY-i,n=Math.max(o,a);var u=this.getScaleRatio(n);this.activeObj.activePoint.endX+=u.x,this.activeObj.activePoint.startY-=u.y;var v=this.destLeft+this.destWidth<this.lowerCanvas.width?this.destLeft+this.destWidth:this.lowerCanvas.width,b=this.destTop>0?this.destTop:0;(this.activeObj.activePoint.endX>v||this.activeObj.activePoint.startY<b)&&(this.activeObj.activePoint.endX-=u.x,this.activeObj.activePoint.startY+=u.y)}this.activeObj.activePoint.width=this.activeObj.activePoint.endX-this.activeObj.activePoint.startX,this.activeObj.activePoint.height=this.activeObj.activePoint.endY-this.activeObj.activePoint.startY,this.preventInverseResize(c)}},l.prototype.updateWPoints=function(t,e){var i,s,o;if("text"!==this.activeObj.shape){var a=void 0;if(void 0!==this.activeObj.shape&&(a=this.activeObj.shape.split("-")),"crop-custom"===this.activeObj.shape||void 0!==this.activeObj.shape&&"crop"!==a[0]){if(this.activeObj.activePoint.startX=t,this.activeObj.activePoint.width=this.activeObj.activePoint.endX-this.activeObj.activePoint.startX,this.activeObj.activePoint.startX>this.activeObj.activePoint.endX){var n=this.activeObj.activePoint.startX;this.activeObj.activePoint.startX=this.activeObj.activePoint.endX,this.activeObj.activePoint.endX=n,this.dragElement="e-resize"}this.preventDraggingInvertly()}else{if(this.activeObj.activePoint.startX<t&&this.activeObj.activePoint.endY>e){i=t-this.activeObj.activePoint.startX,s=this.activeObj.activePoint.endY-e,o=Math.min(i,s);r=this.getScaleRatio(o);this.activeObj.activePoint.startX+=r.x,this.activeObj.activePoint.endY-=r.y,(this.activeObj.activePoint.startX<this.destLeft||this.activeObj.activePoint.endY>this.destTop+this.destHeight)&&(this.activeObj.activePoint.startX-=r.x,this.activeObj.activePoint.endY+=r.y)}else{i=this.activeObj.activePoint.startX-t,s=e-this.activeObj.activePoint.endY,o=Math.max(i,s);var r=this.getScaleRatio(o);this.activeObj.activePoint.startX-=r.x,this.activeObj.activePoint.endY+=r.y,(this.activeObj.activePoint.startX<this.destLeft||this.activeObj.activePoint.endY>this.destTop+this.destHeight)&&(this.activeObj.activePoint.startX+=r.x,this.activeObj.activePoint.endY-=r.y)}this.activeObj.activePoint.width=this.activeObj.activePoint.endX-this.activeObj.activePoint.startX,this.activeObj.activePoint.height=this.activeObj.activePoint.endY-this.activeObj.activePoint.startY}}},l.prototype.updateEPoints=function(t,e){var i,s,o;if("text"!==this.activeObj.shape){var a=void 0;if(void 0!==this.activeObj.shape&&(a=this.activeObj.shape.split("-")),"crop-custom"===this.activeObj.shape||void 0!==this.activeObj.shape&&"crop"!==a[0]){if(this.activeObj.activePoint.endX=t,this.activeObj.activePoint.width=this.activeObj.activePoint.endX-this.activeObj.activePoint.startX,this.activeObj.activePoint.endX<this.activeObj.activePoint.startX){var n=this.activeObj.activePoint.endX;this.activeObj.activePoint.endX=this.activeObj.activePoint.startX,this.activeObj.activePoint.startX=n,this.dragElement="w-resize"}this.preventDraggingInvertly()}else{if(this.activeObj.activePoint.endX>t&&this.activeObj.activePoint.endY>e){i=this.activeObj.activePoint.endX-t,s=this.activeObj.activePoint.endY-e,o=Math.min(i,s);r=this.getScaleRatio(o);this.activeObj.activePoint.endX-=r.x,this.activeObj.activePoint.endY-=r.y,(this.activeObj.activePoint.endX>this.destLeft+this.destWidth||this.activeObj.activePoint.endY>this.destTop+this.destHeight)&&(this.activeObj.activePoint.endX+=r.x,this.activeObj.activePoint.endY+=r.y)}else{i=t-this.activeObj.activePoint.endX,s=e-this.activeObj.activePoint.endY,o=Math.max(i,s);var r=this.getScaleRatio(o);this.activeObj.activePoint.endX+=r.x,this.activeObj.activePoint.endY+=r.y,(this.activeObj.activePoint.endX>this.destLeft+this.destWidth||this.activeObj.activePoint.endY>this.destTop+this.destHeight)&&(this.activeObj.activePoint.endX-=r.x,this.activeObj.activePoint.endY-=r.y)}this.activeObj.activePoint.width=this.activeObj.activePoint.endX-this.activeObj.activePoint.startX,this.activeObj.activePoint.height=this.activeObj.activePoint.endY-this.activeObj.activePoint.startY}}},l.prototype.updateSWPoints=function(t,i,s){var o,a,n,r,h=this.diffPoint.x,l=this.diffPoint.y,c=e.extend({},this.activeObj,null,!0);if("text"===this.activeObj.shape)void 0===this.oldPoint.x&&void 0===this.oldPoint.y?(this.diffPoint.x=this.activeObj.activePoint.startX-t,this.diffPoint.y=i-this.activeObj.activePoint.endY):(this.diffPoint.x=this.oldPoint.x-t,this.diffPoint.y=i-this.oldPoint.y),this.oldPoint.x=t,this.oldPoint.y=i,r=(this.diffPoint.x<=h&&this.diffPoint.y>=l?Math.min(this.diffPoint.x,this.diffPoint.y):Math.max(this.diffPoint.x,this.diffPoint.y))/10,this.activeObj.activePoint.startX-=s.width/100*r,this.activeObj.activePoint.endY+=s.height/100*r,this.activeObj.activePoint.width=this.activeObj.activePoint.endX-this.activeObj.activePoint.startX,this.activeObj.activePoint.height=this.activeObj.activePoint.endY-this.activeObj.activePoint.startY,this.updateFontSize(this.activeObj);else{var d=void 0;if(void 0!==this.activeObj.shape&&(d=this.activeObj.shape.split("-")),"crop-custom"===this.activeObj.shape||void 0!==this.activeObj.shape&&"crop"!==d[0]){if(this.activeObj.activePoint.startX=t,this.activeObj.activePoint.endY=i,this.activeObj.activePoint.startX>this.activeObj.activePoint.endX){p=this.activeObj.activePoint.startX;this.activeObj.activePoint.startX=this.activeObj.activePoint.endX,this.activeObj.activePoint.endX=p,this.dragElement="se-resize"}if(this.activeObj.activePoint.endY<this.activeObj.activePoint.startY){var p=this.activeObj.activePoint.endY;this.activeObj.activePoint.endY=this.activeObj.activePoint.startY,this.activeObj.activePoint.startY=p,this.dragElement="nw-resize"}this.preventDraggingInvertly()}else if(this.activeObj.activePoint.startX<t&&this.activeObj.activePoint.endY>i){o=t-this.activeObj.activePoint.startX,a=this.activeObj.activePoint.endY-i,n=Math.min(o,a);u=this.getScaleRatio(n);this.activeObj.activePoint.startX+=u.x,this.activeObj.activePoint.endY-=u.y;var v=this.destLeft>0?this.destLeft:0,b=this.destTop+this.destHeight<this.lowerCanvas.height?this.destTop+this.destHeight:this.lowerCanvas.height;(this.activeObj.activePoint.startX<v||this.activeObj.activePoint.endY>b)&&(this.activeObj.activePoint.startX-=u.x,this.activeObj.activePoint.endY+=u.y)}else{o=this.activeObj.activePoint.startX-t,a=i-this.activeObj.activePoint.endY,n=Math.max(o,a);var u=this.getScaleRatio(n);this.activeObj.activePoint.startX-=u.x,this.activeObj.activePoint.endY+=u.y;var v=this.destLeft>0?this.destLeft:0,b=this.destTop+this.destHeight<this.lowerCanvas.height?this.destTop+this.destHeight:this.lowerCanvas.height;(this.activeObj.activePoint.startX<v||this.activeObj.activePoint.endY>b)&&(this.activeObj.activePoint.startX+=u.x,this.activeObj.activePoint.endY-=u.y)}this.activeObj.activePoint.width=this.activeObj.activePoint.endX-this.activeObj.activePoint.startX,this.activeObj.activePoint.height=this.activeObj.activePoint.endY-this.activeObj.activePoint.startY,this.preventInverseResize(c)}},l.prototype.updateSPoints=function(t,e){var i,s,o;if("text"!==this.activeObj.shape){var a=void 0;if(void 0!==this.activeObj.shape&&(a=this.activeObj.shape.split("-")),"crop-custom"===this.activeObj.shape||void 0!==this.activeObj.shape&&"crop"!==a[0]){if(this.activeObj.activePoint.endY=e,this.activeObj.activePoint.height=this.activeObj.activePoint.endY-this.activeObj.activePoint.startY,this.activeObj.activePoint.endY<this.activeObj.activePoint.startY){var n=this.activeObj.activePoint.endY;this.activeObj.activePoint.endY=this.activeObj.activePoint.startY,this.activeObj.activePoint.startY=n,this.dragElement="n-resize"}this.preventDraggingInvertly()}else{if(this.activeObj.activePoint.endX>t&&this.activeObj.activePoint.endY>e){i=this.activeObj.activePoint.endX-t,s=this.activeObj.activePoint.endY-e,o=Math.min(i,s);r=this.getScaleRatio(o);this.activeObj.activePoint.endX-=r.x,this.activeObj.activePoint.endY-=r.y,(this.activeObj.activePoint.endX>this.destLeft+this.destWidth||this.activeObj.activePoint.endY>this.destTop+this.destHeight)&&(this.activeObj.activePoint.endX+=r.x,this.activeObj.activePoint.endY+=r.y)}else{i=t-this.activeObj.activePoint.endX,s=e-this.activeObj.activePoint.endY,o=Math.max(i,s);var r=this.getScaleRatio(o);this.activeObj.activePoint.endX+=r.x,this.activeObj.activePoint.endY+=r.x,(this.activeObj.activePoint.endX>this.destLeft+this.destWidth||this.activeObj.activePoint.endY>this.destTop+this.destHeight)&&(this.activeObj.activePoint.endX-=r.x,this.activeObj.activePoint.endY-=r.y)}this.activeObj.activePoint.width=this.activeObj.activePoint.endX-this.activeObj.activePoint.startX,this.activeObj.activePoint.height=this.activeObj.activePoint.endY-this.activeObj.activePoint.startY}}},l.prototype.updateSEPoints=function(t,i,s){var o,a,n,r,h=this.diffPoint.x,l=this.diffPoint.y,c=e.extend({},this.activeObj,null,!0);if("text"===this.activeObj.shape)void 0===this.oldPoint.x&&void 0===this.oldPoint.y?(this.diffPoint.x=t-this.activeObj.activePoint.endX,this.diffPoint.y=i-this.activeObj.activePoint.endY):(this.diffPoint.x=t-this.oldPoint.x,this.diffPoint.y=i-this.oldPoint.y),this.oldPoint.x=t,this.oldPoint.y=i,r=(this.diffPoint.x>=h&&this.diffPoint.y>=l?Math.max(this.diffPoint.x,this.diffPoint.y):Math.min(this.diffPoint.x,this.diffPoint.y))/10,this.activeObj.activePoint.endX+=s.width/50*r,this.activeObj.activePoint.endY+=s.height/50*r,this.activeObj.activePoint.width=this.activeObj.activePoint.endX-this.activeObj.activePoint.startX,this.activeObj.activePoint.height=this.activeObj.activePoint.endY-this.activeObj.activePoint.startY,this.updateFontSize(this.activeObj);else{var d=void 0;if(void 0!==this.activeObj.shape&&(d=this.activeObj.shape.split("-")),"crop-custom"===this.activeObj.shape||void 0!==this.activeObj.shape&&"crop"!==d[0]){if(this.activeObj.activePoint.endX=t,this.activeObj.activePoint.endY=i,this.activeObj.activePoint.endX<this.activeObj.activePoint.startX){p=this.activeObj.activePoint.endX;this.activeObj.activePoint.endX=this.activeObj.activePoint.startX,this.activeObj.activePoint.startX=p,this.dragElement="sw-resize"}if(this.activeObj.activePoint.endY<this.activeObj.activePoint.startY){var p=this.activeObj.activePoint.endY;this.activeObj.activePoint.endY=this.activeObj.activePoint.startY,this.activeObj.activePoint.startY=p,this.dragElement="ne-resize"}this.preventDraggingInvertly()}else if(this.activeObj.activePoint.endX>t&&this.activeObj.activePoint.endY>i){o=this.activeObj.activePoint.endX-t,a=this.activeObj.activePoint.endY-i,n=Math.min(o,a);u=this.getScaleRatio(n);this.activeObj.activePoint.endX-=u.x,this.activeObj.activePoint.endY-=u.y;var v=this.destLeft+this.destWidth<this.lowerCanvas.width?this.destLeft+this.destWidth:this.lowerCanvas.width,b=this.destTop+this.destHeight<this.lowerCanvas.height?this.destTop+this.destHeight:this.lowerCanvas.height;(this.activeObj.activePoint.endX>v||this.activeObj.activePoint.endY>b)&&(this.activeObj.activePoint.endX+=u.x,this.activeObj.activePoint.endY+=u.y)}else{o=t-this.activeObj.activePoint.endX,a=i-this.activeObj.activePoint.endY,n=Math.max(o,a);var u=this.getScaleRatio(n);this.activeObj.activePoint.endX+=u.x,this.activeObj.activePoint.endY+=u.y;var v=this.destLeft+this.destWidth<this.lowerCanvas.width?this.destLeft+this.destWidth:this.lowerCanvas.width,b=this.destTop+this.destHeight<this.lowerCanvas.height?this.destTop+this.destHeight:this.lowerCanvas.height;(this.activeObj.activePoint.endX>v||this.activeObj.activePoint.endY>b)&&(this.activeObj.activePoint.endX-=u.x,this.activeObj.activePoint.endY-=u.y)}this.activeObj.activePoint.width=this.activeObj.activePoint.endX-this.activeObj.activePoint.startX,this.activeObj.activePoint.height=this.activeObj.activePoint.endY-this.activeObj.activePoint.startY,this.preventInverseResize(c)}},l.prototype.updateFontRatio=function(t,i){var s;s=0===t.shapeDegree?this.degree:this.degree-t.shapeDegree,e.isNullOrUndefined(i)?t.textSettings.fontRatio=0===s||180===s?t.activePoint.width/t.textSettings.fontSize:t.activePoint.height/t.textSettings.fontSize:i&&(t.textSettings.fontRatio=0===s||180===s?this.textArea.clientWidth/parseFloat(this.textArea.style.fontSize):this.textArea.clientHeight/parseFloat(this.textArea.style.fontSize))},l.prototype.updateFontSize=function(t){var e;e=0===t.shapeDegree?this.degree:this.degree-t.shapeDegree,t.textSettings.fontSize=0===e||180===e?t.activePoint.width/t.textSettings.fontRatio:t.activePoint.height/t.textSettings.fontRatio},l.prototype.preventInverseResize=function(t){this.activeObj.activePoint.width<0&&(this.activeObj.activePoint.width=0,this.activeObj.activePoint.startX=t.activePoint.startX,this.activeObj.activePoint.endX=t.activePoint.endX),this.activeObj.activePoint.height<0&&(this.activeObj.activePoint.height=0,this.activeObj.activePoint.startY=t.activePoint.startY,this.activeObj.activePoint.endY=t.activePoint.endY)},l.prototype.getScaleRatio=function(t){var e={x:t,y:t};if("crop-custom"!==this.activeObj.shape&&"crop-circle"!==this.activeObj.shape&&"crop-square"!==this.activeObj.shape){var i=this.activeObj.shape.split("-");i=i[1].split(":");var s=t/parseInt(i[1],10);e.x=s*parseInt(i[0],10),e.y=s*parseInt(i[1],10)}return e},l.prototype.getMaxText=function(t,i){e.isNullOrUndefined(i)&&(i=t?this.textArea.value:this.activeObj.keyHistory);for(var s,o=i.split("\n"),a=o[0].length,n=o[0],r=1;r<o.length;r++)(s=o[r].length)>a&&(n=o[r],a=s);return n},l.prototype.setDragLimit=function(){this.activeObj.activePoint&&(this.activeObj.activePoint.startX<this.destLeft?(this.activeObj.activePoint.startX=this.destLeft,this.activeObj.activePoint.endX=this.activeObj.activePoint.startX+this.activeObj.activePoint.width):this.activeObj.activePoint.endX>this.destLeft+this.destWidth&&(this.activeObj.activePoint.endX=this.destLeft+this.destWidth,this.activeObj.activePoint.startX=this.activeObj.activePoint.endX-this.activeObj.activePoint.width),this.activeObj.activePoint.startY<this.destTop?this.activeObj.activePoint.startY=this.destTop:this.activeObj.activePoint.endY>this.destTop+this.destHeight&&(this.activeObj.activePoint.endY=this.destTop+this.destHeight,this.activeObj.activePoint.startY=this.activeObj.activePoint.endY-this.activeObj.activePoint.height),this.activeObj.activePoint.width=this.activeObj.activePoint.endX-this.activeObj.activePoint.startX,this.activeObj.activePoint.height=this.activeObj.activePoint.endY-this.activeObj.activePoint.startY)},l.prototype.lineDraw=function(){this.activeObj.activePoint.height<10?(this.activeObj.activePoint.startY-=10,this.activeObj.activePoint.endY+=10,this.activeObj.lineDraw="horizontal"):this.activeObj.activePoint.width<10?(this.activeObj.activePoint.startX-=10,this.activeObj.activePoint.endX+=10,this.activeObj.lineDraw="vertical"):this.currObjType.isInitialLine&&(this.activeObj.lineDraw="normal",this.currObjType.isInitialLine=!1),this.activeObj.activePoint.width=this.activeObj.activePoint.endX-this.activeObj.activePoint.startX,this.activeObj.activePoint.height=this.activeObj.activePoint.endY-this.activeObj.activePoint.startY},l.prototype.shapeCircle=function(t,e,i){t.strokeStyle=this.themeColl[this.theme].primaryColor,t.clearRect(0,0,this.lowerCanvas.width,this.lowerCanvas.height),t.fillStyle="rgb(0, 0, 0, 0.5)",t.fillRect(0,0,this.lowerCanvas.width,this.lowerCanvas.height);var s=t.lineWidth;t.lineWidth=2,t.beginPath(),t.ellipse(this.activeObj.horTopLine.startX+e/2,this.activeObj.horTopLine.startY+i/2,e/2,i/2,0,0,2*Math.PI,!1),t.stroke(),t.closePath(),t.save(),t.beginPath(),t.arc((this.activeObj.activePoint.endX-this.activeObj.activePoint.startX)/2+this.activeObj.activePoint.startX,(this.activeObj.activePoint.endY-this.activeObj.activePoint.startY)/2+this.activeObj.activePoint.startY,this.activeObj.activePoint.width/2,0,2*Math.PI),t.closePath(),t.clip(),t.clearRect(0,0,this.lowerCanvas.width,this.lowerCanvas.height),t.restore(),t.lineWidth=s,this.drawOuterSelection(t,!0),this.currObjType.shape=""},l.prototype.drawOuterSelection=function(t,i){var s;t.lineWidth=.5,void 0!==this.activeObj.shape&&(s=this.activeObj.shape.split("-"));var o=e.extend({},this.activeObj,{},!0);void 0!==this.activeObj.shape&&(s=this.activeObj.shape.split("-")),(void 0===s||"crop"!==s[0])&&void 0!==this.activeObj.shape||i||(this.upperContext.fillStyle="rgb(0, 0, 0, 0.5)",this.upperContext.fillRect(0,0,this.lowerCanvas.width,this.lowerCanvas.height),this.upperContext.clearRect(this.activeObj.activePoint.startX,this.activeObj.activePoint.startY,this.activeObj.activePoint.width,this.activeObj.activePoint.height)),t.strokeStyle=this.themeColl[this.theme].primaryColor,t.fillStyle=this.themeColl[this.theme].secondaryColor,"rectangle"!==this.activeObj.shape&&(t.beginPath(),t.rect(o.activePoint.startX,o.activePoint.startY,o.activePoint.width,o.activePoint.height),t.stroke(),t.closePath()),t.lineWidth*=2,t.beginPath(),t.moveTo(o.topLeftCircle.startX,o.topLeftCircle.startY),t.arc(o.topLeftCircle.startX,o.topLeftCircle.startY,o.topLeftCircle.radius,0,2*Math.PI),t.moveTo(o.topRightCircle.startX,o.topRightCircle.startY),t.arc(o.topRightCircle.startX,o.topRightCircle.startY,o.topRightCircle.radius,0,2*Math.PI),t.moveTo(o.bottomLeftCircle.startX,o.bottomLeftCircle.startY),t.arc(o.bottomLeftCircle.startX,o.bottomLeftCircle.startY,o.bottomLeftCircle.radius,0,2*Math.PI),t.moveTo(o.bottomRightCircle.startX,o.bottomRightCircle.startY),t.arc(o.bottomRightCircle.startX,o.bottomRightCircle.startY,o.bottomRightCircle.radius,0,2*Math.PI),t.stroke(),t.fill(),t.closePath(),t.lineWidth/=2,void 0!==s&&"crop"===s[0]||"text"===this.activeObj.shape||this.drawCenterCircles(t),this.activeObj=e.extend({},o,{},!0)},l.prototype.drawObject=function(t,i,s,o,a,n){this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height);var r;if("original"===t.toLowerCase()?r=this.lowerContext:"duplicate"===t.toLowerCase()?r=this.upperContext:e.isNullOrUndefined(n)||(r=n),a||e.isNullOrUndefined(this.activeObj.shape)||this.setDragLimit(),this.currObjType.isLine&&"original"!==t&&!i&&this.lineDraw(),"crop"===this.currObjType.shape.split("-")[0].toLowerCase()&&s&&this.drawCropRatio(),o&&(this.activeObj.activePoint.startX=o.startX,this.activeObj.activePoint.startY=o.startY,this.activeObj.activePoint.endX=o.endX,this.activeObj.activePoint.endY=o.endY,this.activeObj.activePoint.width=o.width,this.activeObj.activePoint.height=o.height),e.isNullOrUndefined(this.activeObj.strokeSettings)&&(this.activeObj.strokeSettings=this.strokeSettings),e.isNullOrUndefined(this.activeObj.strokeSettings.strokeWidth)&&(this.activeObj.strokeSettings.strokeWidth=4),i&&(this.activeObj=e.extend({},i,{},!0)),this.updateActiveObject(),this.currObjType.isText&&(this.activeObj.keyHistory=this.keyHistory),"original"!==t.toLowerCase()){var h=!1;this.activeObj.shape&&"crop"===this.activeObj.shape.split("-")[0]&&(h=!0),h&&(this.upperContext.fillStyle="rgb(0, 0, 0, 0.5)",this.upperContext.fillRect(0,0,this.lowerCanvas.width,this.lowerCanvas.height),this.upperContext.clearRect(this.activeObj.activePoint.startX,this.activeObj.activePoint.startY,this.activeObj.activePoint.width,this.activeObj.activePoint.height)),r!==this.lowerContext&&r!==this.upperContext||this.drawOuterSelection(r)}this.currObjType.isActiveObj=!0,i?this.drawShapeObj(t,i.shape,n):""!==this.keyHistory&&this.currObjType.isText?this.drawShapeObj(t,"text",n):this.activeObj.shape?this.drawShapeObj(t,this.activeObj.shape,n):this.drawShapeObj(t,void 0,n),this.isAllowCropPan&&(this.isAllowCropPan=!1,this.tempPanMove=e.extend({},this.panMove,{},!0),this.currentPannedPoint=this.updatePanPoints(this.getCurrentPanRegion()),this.rotatePan())},l.prototype.rotateShape=function(t){t.beginPath(),t.moveTo(this.activeObj.horTopLine.startX,this.activeObj.horTopLine.startY),t.lineTo(this.activeObj.horTopLine.endX,this.activeObj.horTopLine.endY),t.moveTo(this.activeObj.horBottomLine.startX,this.activeObj.horBottomLine.startY),t.lineTo(this.activeObj.horBottomLine.endX,this.activeObj.horBottomLine.endY),t.moveTo(this.activeObj.verLeftLine.startX,this.activeObj.verLeftLine.startY),t.lineTo(this.activeObj.verLeftLine.endX,this.activeObj.verLeftLine.endY),t.moveTo(this.activeObj.verRightLine.startX,this.activeObj.verRightLine.startY),t.lineTo(this.activeObj.verRightLine.endX,this.activeObj.verRightLine.endY),t.stroke()},l.prototype.updateActiveObject=function(t,i,s,o,a){t=t||e.extend({},this.activeObj.activePoint,{},!0),i=i||e.extend({},this.activeObj,{},!0),t.width=t.endX-t.startX,t.height=t.endY-t.startY,o=o||0,a=a||0;var n=t.width/2,r=t.height/2;i.horTopLine={startX:t.startX+o,startY:t.startY-a,endX:t.endX+o,endY:t.endY+a},i.horBottomLine={startX:t.startX-o,startY:t.endY-a,endX:t.endX-o,endY:t.endY+a},i.verLeftLine={startX:t.startX+o,startY:t.startY-a,endX:t.startX-a,endY:t.endY-a},i.verRightLine={startX:t.endX+o,startY:t.startY+a,endX:t.endX-o,endY:t.endY+a},i.topLeftCircle={startX:t.startX,startY:t.startY,radius:i.horTopLine.endX?7.5:0},i.topCenterCircle={startX:t.startX+n,startY:t.startY,radius:i.horTopLine.endX?7.5:0},i.topRightCircle={startX:t.endX,startY:t.startY,radius:i.horTopLine.endX?7.5:0},i.centerLeftCircle={startX:t.startX,startY:t.startY+r,radius:i.horTopLine.endX?7.5:0},i.centerRightCircle={startX:t.endX,startY:t.startY+r,radius:i.horTopLine.endX?7.5:0},i.bottomLeftCircle={startX:t.startX,startY:t.endY,radius:i.horTopLine.endX?7.5:0},i.bottomCenterCircle={startX:t.startX+n,startY:t.endY,radius:i.horTopLine.endX?7.5:0},i.bottomRightCircle={startX:t.endX,startY:t.endY,radius:i.horTopLine.endX?7.5:0},i.activePoint=t,e.isNullOrUndefined(s)&&(this.activeObj=e.extend({},i,{},!0))},l.prototype.drawShapeObj=function(t,i,s){var o=void 0!==i?i:this.currObjType.shape;this.currObjType.shape=o;var a;"original"===t.toLowerCase()?a=this.lowerContext:"duplicate"===t.toLowerCase()?a=this.upperContext:e.isNullOrUndefined(s)||(a=s),"rectangle"!==this.currObjType.shape.toLowerCase()&&"ellipse"!==this.currObjType.shape.toLowerCase()&&"line"!==this.currObjType.shape.toLowerCase()||(this.activeObj.shape=this.currObjType.shape),a.strokeStyle=this.activeObj.strokeSettings.strokeColor,a.fillStyle="text"===i||"freehanddraw"===i?this.activeObj.strokeSettings.strokeColor:this.activeObj.strokeSettings.fillColor;var n=this.activeObj.activePoint.width/3,r=this.activeObj.activePoint.height/3,h=this.activeObj.activePoint.endX-this.activeObj.activePoint.startX,l=this.activeObj.activePoint.endY-this.activeObj.activePoint.startY;switch(this.currObjType.shape.toLowerCase()){case"rectangle":this.drawSquareLines(a),a===this.upperContext&&this.drawOuterSelection(a);break;case"ellipse":h=Math.abs(h),l=Math.abs(l),a.beginPath(),a.ellipse(this.activeObj.activePoint.startX+h/2,this.activeObj.activePoint.startY+l/2,h/2,l/2,0,0,2*Math.PI,!1),""!==this.activeObj.strokeSettings.fillColor&&(a.fillStyle=this.activeObj.strokeSettings.fillColor,a.fill()),a.ellipse(this.activeObj.activePoint.startX+h/2,this.activeObj.activePoint.startY+l/2,Math.abs(h/2-this.activeObj.strokeSettings.strokeWidth),Math.abs(l/2-this.activeObj.strokeSettings.strokeWidth),0,0,2*Math.PI,!1),a.fillStyle=this.activeObj.strokeSettings.strokeColor,a.fill("evenodd"),a.closePath(),a===this.upperContext&&this.drawOuterSelection(a);break;case"crop-circle":a===this.lowerContext&&(a=this.upperContext),this.shapeCircle(a,h,l);break;case"line":this.shapeLine(a,h,l),a===this.upperContext&&this.drawOuterSelection(a);break;case"text":this.shapeText(a);break;case"crop-square":case"crop-3:4":case"crop-4:3":case"crop-6:9":case"crop-9:6":case"crop-9:16":case"crop-16:9":a===this.lowerContext&&(a=this.upperContext),this.drawSelection(n,r),this.currObjType.shape="";break;default:this.drawSelection(n,r)}},l.prototype.shapeLine=function(t,e,i){var s,o,a,n,r;0===(r=0===this.activeObj.shapeDegree?this.degree:this.degree-this.activeObj.shapeDegree)||r%180==0?(s=this.activeObj.activePoint.startX,o=this.activeObj.activePoint.startY+i/2,a=this.activeObj.activePoint.endX,n=this.activeObj.activePoint.startY+i/2):(s=this.activeObj.activePoint.startX+e/2,o=this.activeObj.activePoint.startY,a=this.activeObj.activePoint.startX+e/2,n=this.activeObj.activePoint.endY);var h=t.lineWidth;switch(t.lineWidth=this.activeObj.strokeSettings.strokeWidth,t.beginPath(),this.activeObj.lineDraw.toLowerCase()){case"horizontal":case"vertical":t.moveTo(s,o),t.lineTo(a,n);break;case"normal":t.moveTo(this.activeObj.horTopLine.startX,this.activeObj.horTopLine.startY),t.lineTo(this.activeObj.horBottomLine.endX,this.activeObj.horBottomLine.endY)}t.stroke(),t.lineWidth=h},l.prototype.shapeText=function(t){for(var e=this.activeObj.keyHistory.split("\n"),i=((this.activeObj.textSettings.fontSize+.25*this.activeObj.textSettings.fontSize)*e.length-this.activeObj.textSettings.fontSize*e.length)/e.length,s=0;s<e.length;s++){var o=e[s],a=(s+1)*this.activeObj.textSettings.fontSize*.85+s*i;-360===this.degree&&(this.degree=0),0===this.degree||180===this.degree?this.activeObj.textSettings.fontSize>this.activeObj.activePoint.height&&(this.activeObj.textSettings.fontSize=this.activeObj.activePoint.height-.1*this.activeObj.activePoint.height):this.activeObj.textSettings.fontSize>this.activeObj.activePoint.width&&(this.activeObj.textSettings.fontSize=this.activeObj.activePoint.width-.1*this.activeObj.activePoint.width),t.strokeStyle=this.activeObj.strokeSettings.strokeColor,t.fillStyle=this.activeObj.strokeSettings.strokeColor;var n="";this.activeObj.textSettings.bold&&(n="bold "),this.activeObj.textSettings.italic&&(n="italic "),this.activeObj.textSettings.bold&&this.activeObj.textSettings.italic&&(n="italic bold "),t.font=n+this.activeObj.textSettings.fontSize+"px "+this.activeObj.textSettings.fontFamily,4===this.activeObj.flipObjColl.length&&(this.activeObj.flipObjColl=[]);for(var r=0;r<this.activeObj.flipObjColl.length;r++)"horizontal"===this.activeObj.flipObjColl[r].toLowerCase()?(t.translate(t.canvas.width,0),t.scale(-1,1),this.updateActPoint("horizontal",t)):"vertical"===this.activeObj.flipObjColl[r].toLowerCase()&&(t.translate(0,t.canvas.height),t.scale(1,-1),this.updateActPoint("vertical",t));this.activeObj.shapeDegree!==this.degree?this.rotateText(t):t.fillText(o,this.activeObj.activePoint.startX+.1*this.activeObj.textSettings.fontSize,this.activeObj.activePoint.startY+a);for(var h=0;h<this.activeObj.flipObjColl.length;h++)"horizontal"===this.activeObj.flipObjColl[h].toLowerCase()?(t.translate(t.canvas.width,0),t.scale(-1,1),this.updateActPoint("horizontal",t)):"vertical"===this.activeObj.flipObjColl[h].toLowerCase()&&(t.translate(0,t.canvas.height),t.scale(1,-1),this.updateActPoint("vertical",t))}this.currObjType.isText=!1},l.prototype.updateActPoint=function(t,e){"horizontal"===t.toLowerCase()?this.activeObj.activePoint.startX<=e.canvas.width/2?(this.activeObj.activePoint.startX=e.canvas.width/2+(e.canvas.width/2-this.activeObj.activePoint.endX),this.activeObj.activePoint.endX=this.activeObj.activePoint.startX+this.activeObj.activePoint.width,this.updateActiveObject(this.activeObj.activePoint,this.activeObj)):this.activeObj.activePoint.startX>=e.canvas.width/2&&(this.activeObj.activePoint.startX=e.canvas.width-this.activeObj.activePoint.endX,this.activeObj.activePoint.endX=this.activeObj.activePoint.startX+this.activeObj.activePoint.width,this.updateActiveObject(this.activeObj.activePoint,this.activeObj)):"vertical"===t.toLowerCase()&&(this.activeObj.activePoint.startY<=e.canvas.height/2?(this.activeObj.activePoint.startY=e.canvas.height/2+(e.canvas.height/2-this.activeObj.activePoint.endY),this.activeObj.activePoint.endY=this.activeObj.activePoint.startY+this.activeObj.activePoint.height,this.updateActiveObject(this.activeObj.activePoint,this.activeObj)):this.activeObj.activePoint.startY>=e.canvas.height/2&&(this.activeObj.activePoint.startY=e.canvas.height-this.activeObj.activePoint.endY,this.activeObj.activePoint.endY=this.activeObj.activePoint.startY+this.activeObj.activePoint.height,this.updateActiveObject(this.activeObj.activePoint,this.activeObj)))},l.prototype.drawSquareLines=function(t){var e;void 0!==this.activeObj.shape&&(e=this.activeObj.shape.split("-")),"crop"===e[0]?t.strokeStyle="#fff":t.strokeStyle=this.activeObj.strokeSettings.strokeColor,t.beginPath(),t.rect(this.activeObj.activePoint.startX,this.activeObj.activePoint.startY,this.activeObj.activePoint.width,this.activeObj.activePoint.height),""!==this.activeObj.strokeSettings.fillColor&&(t.fillStyle=this.activeObj.strokeSettings.fillColor,t.fill()),t.rect(this.activeObj.activePoint.startX+this.activeObj.strokeSettings.strokeWidth,this.activeObj.activePoint.startY+this.activeObj.strokeSettings.strokeWidth,this.activeObj.activePoint.width-2*this.activeObj.strokeSettings.strokeWidth,this.activeObj.activePoint.height-2*this.activeObj.strokeSettings.strokeWidth),t.fillStyle=this.activeObj.strokeSettings.strokeColor,t.fill("evenodd"),t.closePath()},l.prototype.drawSelection=function(t,e){this.upperContext.strokeStyle=this.themeColl[this.theme].primaryColor,this.upperContext.beginPath(),this.activeObj.horTopInnerLine={startX:this.activeObj.activePoint.startX,startY:this.activeObj.activePoint.startY+e,endX:this.activeObj.activePoint.endX,endY:this.activeObj.activePoint.endY+e},this.activeObj.horBottomInnerLine={startX:this.activeObj.activePoint.startX,startY:this.activeObj.activePoint.startY+2*e,endX:this.activeObj.activePoint.endX,endY:this.activeObj.activePoint.endY+2*e},this.activeObj.verLeftInnerLine={startX:this.activeObj.activePoint.startX+t,startY:this.activeObj.activePoint.startY,endX:this.activeObj.activePoint.startX+t,endY:this.activeObj.activePoint.endY},this.activeObj.verRightInnerLine={startX:this.activeObj.activePoint.startX+2*t,startY:this.activeObj.activePoint.startY,endX:this.activeObj.activePoint.startX+2*t,endY:this.activeObj.activePoint.endY},this.upperContext.moveTo(this.activeObj.horTopInnerLine.startX,this.activeObj.horTopInnerLine.startY),this.upperContext.lineTo(this.activeObj.horTopInnerLine.endX,this.activeObj.horTopInnerLine.startY),this.upperContext.moveTo(this.activeObj.horBottomInnerLine.startX,this.activeObj.horBottomInnerLine.startY),this.upperContext.lineTo(this.activeObj.horBottomInnerLine.endX,this.activeObj.horBottomInnerLine.startY),this.upperContext.moveTo(this.activeObj.verLeftInnerLine.startX,this.activeObj.verLeftInnerLine.startY),this.upperContext.lineTo(this.activeObj.verLeftInnerLine.endX,this.activeObj.verLeftInnerLine.endY),this.upperContext.moveTo(this.activeObj.verRightInnerLine.startX,this.activeObj.verRightInnerLine.startY),this.upperContext.lineTo(this.activeObj.verRightInnerLine.endX,this.activeObj.verRightInnerLine.endY),this.upperContext.stroke(),this.upperContext.closePath()},l.prototype.drawCenterCircles=function(t){t.lineWidth*=2,t.beginPath(),t.moveTo(this.activeObj.topCenterCircle.startX,this.activeObj.topCenterCircle.startY),t.arc(this.activeObj.topCenterCircle.startX,this.activeObj.topCenterCircle.startY,this.activeObj.topCenterCircle.radius,0,2*Math.PI),t.moveTo(this.activeObj.centerLeftCircle.startX,this.activeObj.centerLeftCircle.startY),t.arc(this.activeObj.centerLeftCircle.startX,this.activeObj.centerLeftCircle.startY,this.activeObj.centerLeftCircle.radius,0,2*Math.PI),t.moveTo(this.activeObj.centerRightCircle.startX,this.activeObj.centerRightCircle.startY),t.arc(this.activeObj.centerRightCircle.startX,this.activeObj.centerRightCircle.startY,this.activeObj.centerRightCircle.radius,0,2*Math.PI),t.moveTo(this.activeObj.bottomCenterCircle.startX,this.activeObj.bottomCenterCircle.startY),t.arc(this.activeObj.bottomCenterCircle.startX,this.activeObj.bottomCenterCircle.startY,this.activeObj.bottomCenterCircle.radius,0,2*Math.PI),t.stroke(),t.fill(),t.closePath(),t.lineWidth/=2},l.prototype.findTarget=function(t,e,i){if("mousedown"===i.toLowerCase()||"touchstart"===i.toLowerCase()){var s=!1;this.activeObj.shape&&"crop"===this.activeObj.shape.split("-")[0]&&(s=!0),this.findTargetObj(t,e,s),this.updateCursorStyles(t,e,i)}else switch(this.dragElement.toLowerCase()){case"nw-resize":this.activeObj.topLeftCircle.startX=t,this.activeObj.topLeftCircle.startY=e;break;case"n-resize":this.activeObj.topCenterCircle.startX=t,this.activeObj.topCenterCircle.startY=e;break;case"ne-resize":this.activeObj.topRightCircle.startX=t,this.activeObj.topRightCircle.startY=e;break;case"w-resize":this.activeObj.centerLeftCircle.startX=t,this.activeObj.centerLeftCircle.startY=e;break;case"e-resize":this.activeObj.centerRightCircle.startX=t,this.activeObj.centerRightCircle.startY=e;break;case"sw-resize":this.activeObj.bottomLeftCircle.startX=t,this.activeObj.bottomLeftCircle.startY=e;break;case"s-resize":this.activeObj.bottomCenterCircle.startX=t,this.activeObj.bottomCenterCircle.startY=e;break;case"se-resize":this.activeObj.bottomRightCircle.startX=t,this.activeObj.bottomRightCircle.startY=e;break;default:this.dragPoint.startX&&this.dragPoint.startY&&(this.previousPoint.x=this.dragPoint.endX,this.previousPoint.y=this.dragPoint.endY,this.dragPoint.endX=t,this.dragPoint.endY=e)}},l.prototype.findTargetObj=function(t,i,s){var o;if(0!==this.objColl.length&&!this.currObjType.isCustomCrop&&!s){for(var a=0,n=void 0,r=0;r<this.objColl.length;r++){var h=e.extend({},this.objColl[r],{},!0);t>=h.activePoint.startX-2*h.topLeftCircle.radius&&t<=h.activePoint.endX+2*h.topLeftCircle.radius&&i>=h.activePoint.startY-2*h.topLeftCircle.radius&&i<=h.activePoint.endY+2*h.topLeftCircle.radius&&(this.isTouch||"move"===this.upperCanvas.style.cursor||"grab"===this.upperCanvas.style.cursor||this.isShapeInserted?(0===a||a>t-h.activePoint.startX)&&(a=t-this.objColl[r].activePoint.startX,n=r):this.objColl[r].currIndex===this.tempActiveObj.currIndex&&(n=r))}if(e.isNullOrUndefined(n))this.refreshActiveObj(),o=!1;else{this.tempObjColl=e.extend([],this.objColl,[],!0),this.currObjType.isCustomCrop=!1,this.activeObj=e.extend({},this.objColl[n],{},!0);var l=e.extend({},this.objColl[n],{},!0);if(this.objColl.splice(n,1),0===this.degree){this.lowerContext.clearRect(0,0,this.lowerCanvas.width,this.lowerCanvas.height),this.updateBrightnessFilter(),this.lowerContext.drawImage(this.baseImg,this.srcLeft,this.srcTop,this.srcWidth,this.srcHeight,this.destLeft,this.destTop,this.destWidth,this.destHeight);var c=this.lowerContext.filter;this.lowerContext.filter="none",this.iterateObjColl(),this.activeObj=e.extend({},c,{},!0),this.freehandRedraw(this.lowerContext),this.lowerContext.filter=c,this.getCurrentFlipState()}else this.callUpdateCurrentTransformedState(),this.freehandRedraw(this.lowerContext);this.clearOuterCanvas(this.lowerContext),(!e.isNullOrUndefined(this.currSelectionPoint)&&"crop-circle"===this.currSelectionPoint.shape||this.isCircleCrop)&&this.cropCircle(this.lowerContext),this.setActivePoint(),this.activeObj=e.extend({},l,{},!0),this.tempStrokeSettings=e.extend({},this.activeObj.strokeSettings,{},!0),this.tempTextSettings=e.extend({},this.activeObj.textSettings,{},!0);var d=this.updatePreviousShapeSettings(),p={action:"select",previousShapeSettings:d,currentShapeSettings:d};this.trigger("shapeChanging",p),this.updateShapeChangeEventArgs(p.currentShapeSettings),this.activeObj.activePoint&&(this.drawObject("duplicate",this.activeObj,null,null,!0),this.activeObj.activePoint.startX<this.destLeft?this.isPreventDragging=!0:this.activeObj.activePoint.endX>this.destLeft+this.destWidth?this.isPreventDragging=!0:this.activeObj.activePoint.startY<this.destTop?this.isPreventDragging=!0:this.activeObj.activePoint.endY>this.destTop+this.destHeight&&(this.isPreventDragging=!0)),o=!0}}return o},l.prototype.getCurrentFlipState=function(){if(0!==this.rotateFlipColl.length){var t=e.extend({},this.totalPannedInternalPoint,{},!0);this.callUpdateCurrentTransformedState(),this.totalPannedInternalPoint=t}else this.callUpdateCurrentTransformedState()},l.prototype.rotateDegree=function(t){this.lowerContext.save(),this.lowerContext.clearRect(0,0,this.lowerCanvas.width,this.lowerCanvas.height),this.lowerContext.translate(this.lowerCanvas.width/2,this.lowerCanvas.height/2),this.lowerContext.rotate(Math.PI/180*t),this.lowerContext.translate(-this.lowerCanvas.width/2,-this.lowerCanvas.height/2);var e=this.lowerContext.filter;this.updateBrightnessFilter(),this.lowerContext.drawImage(this.baseImg,this.srcLeft,this.srcTop,this.srcWidth,this.srcHeight,this.destLeft,this.destTop,this.destWidth,this.destHeight),this.lowerContext.filter=e,this.lowerContext.translate(this.lowerCanvas.width/2,this.lowerCanvas.height/2),this.lowerContext.rotate(Math.PI/180*-t),this.lowerContext.translate(-this.lowerCanvas.width/2,-this.lowerCanvas.height/2),this.lowerContext.restore()},l.prototype.updateCursorStyles=function(t,i,s){var o=!1;""===this.activeObj.keyHistory||void 0!==this.activeObj.shape||this.currObjType.isCustomCrop||this.currObjType.isLine||!this.currObjType.isText||(this.activeObj.shape="text");var a=e.extend({},this.activeObj,{},!0);e.isNullOrUndefined(a.topLeftCircle)||(t>=a.topLeftCircle.startX-2*a.topLeftCircle.radius&&t<=a.topLeftCircle.startX+2*a.topLeftCircle.radius&&i>=a.topLeftCircle.startY-2*a.topLeftCircle.radius&&i<=a.topLeftCircle.startY+2*a.topLeftCircle.radius&&"nw-resize"!==this.dragElement?(a.topLeftCircle.startX=a.topLeftCircle.startY=0,this.upperCanvas.style.cursor="nw-resize",o=!0,this.dragElement=this.upperCanvas.style.cursor):t>=a.topCenterCircle.startX-2*a.topLeftCircle.radius&&t<=a.topCenterCircle.startX+2*a.topLeftCircle.radius&&i>=a.topCenterCircle.startY-2*a.topLeftCircle.radius&&i<=a.topCenterCircle.startY+2*a.topLeftCircle.radius&&"n-resize"!==this.dragElement?(a.topCenterCircle.startX=a.topCenterCircle.startY=0,this.upperCanvas.style.cursor="n-resize",o=!0,this.dragElement=this.upperCanvas.style.cursor):t>=a.topRightCircle.startX-2*a.topLeftCircle.radius&&t<=a.topRightCircle.startX+2*a.topLeftCircle.radius&&i>=a.topRightCircle.startY-2*a.topLeftCircle.radius&&i<=a.topRightCircle.startY+2*a.topLeftCircle.radius&&"ne-resize"!==this.dragElement?(a.topRightCircle.startX=a.topRightCircle.startY=0,this.upperCanvas.style.cursor="ne-resize",o=!0,this.dragElement=this.upperCanvas.style.cursor):t>=a.centerLeftCircle.startX-2*a.topLeftCircle.radius&&t<=a.centerLeftCircle.startX+2*a.topLeftCircle.radius&&i>=a.centerLeftCircle.startY-2*a.topLeftCircle.radius&&i<=a.centerLeftCircle.startY+2*a.topLeftCircle.radius&&"w-resize"!==this.dragElement?(a.centerLeftCircle.startX=a.centerLeftCircle.startY=0,this.upperCanvas.style.cursor="w-resize",o=!0,this.dragElement=this.upperCanvas.style.cursor):t>=a.centerRightCircle.startX-2*a.topLeftCircle.radius&&t<=a.centerRightCircle.startX+2*a.topLeftCircle.radius&&i>=a.centerRightCircle.startY-2*a.topLeftCircle.radius&&i<=a.centerRightCircle.startY+2*a.topLeftCircle.radius&&"e-resize"!==this.dragElement?(a.centerRightCircle.startX=a.centerRightCircle.startY=0,this.upperCanvas.style.cursor="e-resize",o=!0,this.dragElement=this.upperCanvas.style.cursor):t>=a.bottomLeftCircle.startX-2*a.topLeftCircle.radius&&t<=a.bottomLeftCircle.startX+2*a.topLeftCircle.radius&&i>=a.bottomLeftCircle.startY-2*a.topLeftCircle.radius&&i<=a.bottomLeftCircle.startY+2*a.topLeftCircle.radius&&"sw-resize"!==this.dragElement?(a.bottomLeftCircle.startX=a.bottomLeftCircle.startY=0,this.upperCanvas.style.cursor="sw-resize",o=!0,this.dragElement=this.upperCanvas.style.cursor):t>=a.bottomCenterCircle.startX-2*a.topLeftCircle.radius&&t<=a.bottomCenterCircle.startX+2*a.topLeftCircle.radius&&i>=a.bottomCenterCircle.startY-2*a.topLeftCircle.radius&&i<=a.bottomCenterCircle.startY+2*a.topLeftCircle.radius&&"s-resize"!==this.dragElement?(a.bottomCenterCircle.startX=a.bottomCenterCircle.startY=0,this.upperCanvas.style.cursor="s-resize",o=!0,this.dragElement=this.upperCanvas.style.cursor):t>=a.bottomRightCircle.startX-2*a.topLeftCircle.radius&&t<=a.bottomRightCircle.startX+2*a.topLeftCircle.radius&&i>=a.bottomRightCircle.startY-2*a.topLeftCircle.radius&&i<=a.bottomRightCircle.startY+2*a.topLeftCircle.radius&&"se-resize"!==this.dragElement?(a.bottomRightCircle.startX=a.bottomRightCircle.startY=0,this.upperCanvas.style.cursor="se-resize",o=!0,this.dragElement=this.upperCanvas.style.cursor):(this.dragPoint.startX=this.previousPoint.x=this.dragPoint.endX=t,this.dragPoint.startY=this.previousPoint.y=this.dragPoint.endY=i),this.previousPoint.x=this.previousPoint.y=this.diffPoint.x=this.diffPoint.y=0,"touchstart"===s?(o||t>=a.activePoint.startX&&t<=a.activePoint.endX&&i>=a.activePoint.startY&&i<=a.activePoint.endY)&&(this.currObjType.isDragging=!0):this.currObjType.isDragging=!0)},l.prototype.drawCropRatio=function(){var t,i,s,o;switch(this.zoomFactor>0&&!e.isNullOrUndefined(this.currentSelectionPoint)?(this.destLeft+this.destLeft+this.destWidth<=this.lowerCanvas.clientWidth?(s=this.destWidth,this.destLeft<0&&(s+=2*this.destLeft)):s=this.lowerCanvas.clientWidth,this.destTop+this.destTop+this.destHeight<=this.lowerCanvas.clientHeight?(o=this.destHeight,this.destTop<0&&(o+=2*this.destTop)):o=this.lowerCanvas.clientHeight,0!==this.degree&&(this.isAllowCropPan=!0)):(s=this.destWidth,o=this.destHeight,this.destLeft<0&&(s+=this.destLeft),this.destTop<0&&(o+=this.destTop),"crop-square"!==this.currObjType.shape.toLowerCase()&&"crop-circle"!==this.currObjType.shape.toLowerCase()&&(this.destLeft+this.destWidth>this.lowerCanvas.width&&(s-=this.destLeft+this.destWidth-this.lowerCanvas.width),this.destTop+this.destHeight>this.lowerCanvas.height&&(o-=this.destTop+this.destHeight-this.lowerCanvas.height))),this.currObjType.shape.toLowerCase()){case"crop-square":case"crop-circle":this.setDragDirection(s,o),s===this.destWidth&&o===this.destHeight&&(this.activeObj.activePoint.startX+=this.destLeft,this.activeObj.activePoint.startY+=this.destTop,this.activeObj.activePoint.endX+=this.destLeft,this.activeObj.activePoint.endY+=this.destTop),this.lowerCanvas.width>this.lowerCanvas.height?(this.activeObj.activePoint.height=this.activeObj.activePoint.endY-this.activeObj.activePoint.startY,this.activeObj.activePoint.width=this.activeObj.activePoint.height,this.activeObj.activePoint.endX=this.activeObj.activePoint.startX+this.activeObj.activePoint.width):(this.activeObj.activePoint.width=this.activeObj.activePoint.endX-this.activeObj.activePoint.startX,this.activeObj.activePoint.height=this.activeObj.activePoint.width,this.activeObj.activePoint.endY=this.activeObj.activePoint.startY+this.activeObj.activePoint.height);break;case"crop-3:2":t=3,i=2;break;case"crop-4:3":t=4,i=3;break;case"crop-5:4":t=5,i=4;break;case"crop-7:5":t=7,i=5;break;case"crop-16:9":t=16,i=9}if(void 0!==t&&void 0!==i&&(this.calcShapeRatio(t,i,s,o),s===this.destWidth&&o===this.destHeight&&this.updatePoints()),!e.isNullOrUndefined(this.currentSelectionPoint)){if(this.activeObj.activePoint.startX<this.currentSelectionPoint.activePoint.startX){a=this.currentSelectionPoint.activePoint.startX-this.activeObj.activePoint.startX;this.activeObj.activePoint.startX+=a,this.activeObj.activePoint.endX+=a}if(this.activeObj.activePoint.startY<this.currentSelectionPoint.activePoint.startY){a=this.currentSelectionPoint.activePoint.startY-this.activeObj.activePoint.startY;this.activeObj.activePoint.startY+=a,this.activeObj.activePoint.endY+=a}if(this.activeObj.activePoint.endX>this.currentSelectionPoint.activePoint.endX){a=this.activeObj.activePoint.endX-this.currentSelectionPoint.activePoint.endX;this.activeObj.activePoint.startX-=a,this.activeObj.activePoint.endX-=a}if(this.activeObj.activePoint.endY>this.currentSelectionPoint.activePoint.endY){a=this.activeObj.activePoint.endY-this.currentSelectionPoint.activePoint.endY;this.activeObj.activePoint.startY-=a,this.activeObj.activePoint.endY-=a}this.activeObj.activePoint.startX=(this.lowerCanvas.clientWidth-this.activeObj.activePoint.width)/2,this.activeObj.activePoint.startY=(this.lowerCanvas.clientHeight-this.activeObj.activePoint.height)/2,this.activeObj.activePoint.endX=this.activeObj.activePoint.startX+this.activeObj.activePoint.width,this.activeObj.activePoint.endY=this.activeObj.activePoint.startY+this.activeObj.activePoint.height}if(0===this.zoomFactor){if(this.activeObj.activePoint.startX<this.destLeft){a=this.destLeft-this.activeObj.activePoint.startX+7.5;this.activeObj.activePoint.startX+=a,this.activeObj.activePoint.endX+=a}if(this.activeObj.activePoint.startY<this.destTop){var a=this.destTop-this.activeObj.activePoint.startY+7.5;this.activeObj.activePoint.startY+=a,this.activeObj.activePoint.endY+=a}this.activeObj.activePoint.width=this.activeObj.activePoint.endX-this.activeObj.activePoint.startX,this.activeObj.activePoint.height=this.activeObj.activePoint.endY-this.activeObj.activePoint.startY}},l.prototype.setDragDirection=function(t,e){this.destWidth>this.destHeight?(this.activeObj.activePoint.startX=this.dragPoint.startX=t/2-e/2+7.5,this.activeObj.activePoint.startY=this.dragPoint.startY=e/2-e/2+7.5,this.activeObj.activePoint.endX=t/2+e/2-7.5,this.activeObj.activePoint.endY=e/2+e/2-7.5):(this.activeObj.activePoint.startY=this.dragPoint.startX=e/2-t/2+7.5,this.activeObj.activePoint.endY=e/2+t/2-7.5,this.activeObj.activePoint.startX=this.dragPoint.startX=7.5,this.activeObj.activePoint.endX=t-7.5)},l.prototype.updatePoints=function(){this.activeObj.activePoint.startX+=this.destLeft,this.activeObj.activePoint.startY+=this.destTop,this.activeObj.activePoint.endX+=this.destLeft,this.activeObj.activePoint.endY+=this.destTop,this.activeObj.activePoint.width=this.activeObj.activePoint.endX-this.activeObj.activePoint.startX,this.activeObj.activePoint.height=this.activeObj.activePoint.endY-this.activeObj.activePoint.startY},l.prototype.calcShapeRatio=function(t,e,i,s){for(var o=i,a=s,n=t/e,r=o>=a?o:a,h=r*n,l=r,c=this.getScale(h,o),d=[],p=0;p<2;p++)0===p?d.push(h*c):d.push(l*c);h=d[0],l=d[1];for(var v=this.getScale(l,a),b=[],p=0;p<2;p++)0===p?b.push(h*v):b.push(l*v);h=b[0],l=b[1],this.activeObj.activePoint.width=h,this.activeObj.activePoint.height=l,this.activeObj.activePoint.startX=7.5+(this.dragPoint.startX=(o-h)/2),this.activeObj.activePoint.startY=7.5+(this.dragPoint.startY=(a-l)/2),this.activeObj.activePoint.endX=(o-h)/2+h-7.5,this.activeObj.activePoint.endY=(a-l)/2+l-7.5,this.activeObj.activePoint.startX<this.destLeft&&this.destLeft+this.destWidth>this.lowerCanvas.clientWidth&&(this.activeObj.activePoint.startX=this.destLeft,this.activeObj.activePoint.endX=this.activeObj.activePoint.startX+h),this.activeObj.activePoint.startY<this.destTop&&this.destTop+this.destHeight>this.lowerCanvas.clientHeight&&(this.activeObj.activePoint.startY=this.destTop,this.activeObj.activePoint.endY=this.activeObj.activePoint.startY+l),this.activeObj.activePoint.width=this.activeObj.activePoint.endX-this.activeObj.activePoint.startX,this.activeObj.activePoint.height=this.activeObj.activePoint.endY-this.activeObj.activePoint.startY},l.prototype.getScale=function(t,e){return t>e?e/t:1},l.prototype.calcMaxDimension=function(t,i){var s=this.element.clientWidth,o=this.element.clientHeight-this.toolbarHeight;o=e.Browser.isDevice?o-this.toolbarHeight:o;var a=(s-=30)/t,n=(o-=30)/i,r=Math.min(t,s),h=Math.min(i,o);return a<1&&a<n?(r=t*a,h=i*a):n<1&&n<a&&(r=t*n,h=i*n),{width:r,height:h}},l.prototype.setMaximumDimension=function(t,e){var i,s;t%90==0&&t%180!=0?(i=this.baseImg.height,s=this.baseImg.width):t%180!=0&&0!==t||(i=this.baseImg.width,s=this.baseImg.height),e.width=i,e.height=s;var o=this.calcMaxDimension(i,s);e.style.maxWidth=o.width+"px",e.style.maxHeight=o.height+"px"},l.prototype.setCursor=function(t,i){var s,o=!1;if(void 0!==this.activeObj.horTopLine){void 0!==this.activeObj.shape&&(s=this.activeObj.shape.split("-")),void 0===s&&this.currObjType.isCustomCrop?o=!0:void 0!==s&&"crop"===s[0]&&(o=!0),!o&&this.togglePan&&(this.lowerCanvas.style.cursor=this.upperCanvas.style.cursor="grab");var a=this.upperCanvas.style.cursor,n=e.extend({},this.activeObj,{},!0);t>=n.topLeftCircle.startX-2*n.topLeftCircle.radius&&t<=n.topLeftCircle.startX+2*n.topLeftCircle.radius&&i>=n.topLeftCircle.startY-2*n.topLeftCircle.radius&&i<=n.topLeftCircle.startY+2*n.topLeftCircle.radius?this.upperCanvas.style.cursor="nw-resize":t>=n.topCenterCircle.startX-2*n.topLeftCircle.radius&&t<=n.topCenterCircle.startX+2*n.topLeftCircle.radius&&i>=n.topCenterCircle.startY-2*n.topLeftCircle.radius&&i<=n.topCenterCircle.startY+2*n.topLeftCircle.radius?this.upperCanvas.style.cursor="n-resize":t>=n.topRightCircle.startX-2*n.topLeftCircle.radius&&t<=n.topRightCircle.startX+2*n.topLeftCircle.radius&&i>=n.topRightCircle.startY-2*n.topLeftCircle.radius&&i<=n.topRightCircle.startY+2*n.topLeftCircle.radius?this.upperCanvas.style.cursor="ne-resize":t>=n.centerLeftCircle.startX-2*n.topLeftCircle.radius&&t<=n.centerLeftCircle.startX+2*n.topLeftCircle.radius&&i>=n.centerLeftCircle.startY-2*n.topLeftCircle.radius&&i<=n.centerLeftCircle.startY+2*n.topLeftCircle.radius?this.upperCanvas.style.cursor="w-resize":t>=n.centerRightCircle.startX-2*n.topLeftCircle.radius&&t<=n.centerRightCircle.startX+2*n.topLeftCircle.radius&&i>=n.centerRightCircle.startY-2*n.topLeftCircle.radius&&i<=n.centerRightCircle.startY+2*n.topLeftCircle.radius?this.upperCanvas.style.cursor="e-resize":t>=n.bottomLeftCircle.startX-2*n.topLeftCircle.radius&&t<=n.bottomLeftCircle.startX+2*n.topLeftCircle.radius&&i>=n.bottomLeftCircle.startY-2*n.topLeftCircle.radius&&i<=n.bottomLeftCircle.startY+2*n.topLeftCircle.radius?this.upperCanvas.style.cursor="sw-resize":t>=n.bottomCenterCircle.startX-2*n.topLeftCircle.radius&&t<=n.bottomCenterCircle.startX+2*n.topLeftCircle.radius&&i>=n.bottomCenterCircle.startY-2*n.topLeftCircle.radius&&i<=n.bottomCenterCircle.startY+2*n.topLeftCircle.radius?this.upperCanvas.style.cursor="s-resize":t>=n.bottomRightCircle.startX-2*n.topLeftCircle.radius&&t<=n.bottomRightCircle.startX+2*n.topLeftCircle.radius&&i>=n.bottomRightCircle.startY-2*n.topLeftCircle.radius&&i<=n.bottomRightCircle.startY+2*n.topLeftCircle.radius?this.upperCanvas.style.cursor="se-resize":t>=n.activePoint.startX&&t<=n.activePoint.endX&&i>=n.activePoint.startY&&i<=n.activePoint.endY?this.upperCanvas.style.cursor=o?"grab":"move":(this.currObjType.isCustomCrop&&(this.upperCanvas.style.cursor="crosshair"),this.upperCanvas.style.cursor="default"),"default"===a&&"default"===this.upperCanvas.style.cursor&&o&&(this.upperCanvas.style.cursor="grab"),"grab"===a&&"default"===this.upperCanvas.style.cursor&&(this.upperCanvas.style.cursor="grab")}else this.togglePan&&!this.togglePen?this.lowerCanvas.style.cursor=this.upperCanvas.style.cursor="grab":this.currObjType.isCustomCrop||this.togglePen?this.upperCanvas.style.cursor="crosshair":this.upperCanvas.style.cursor="default";if("default"===this.upperCanvas.style.cursor||"grab"===this.upperCanvas.style.cursor){a=this.upperCanvas.style.cursor;this.objColl.length>0&&("grab"!==this.upperCanvas.style.cursor||!o)&&this.setCursorFromObj(t,i,this.objColl),"grab"===a&&"default"===this.upperCanvas.style.cursor&&(this.upperCanvas.style.cursor="grab")}"default"!==this.upperCanvas.style.cursor&&"grab"!==this.upperCanvas.style.cursor||e.isNullOrUndefined(this.pointColl[0])||"grab"===this.upperCanvas.style.cursor&&o||this.setCursorForFreehandDrawing(t,i)},l.prototype.setCursorForFreehandDrawing=function(t,i){var s=!1;this.freehandDrawHoveredIndex=-1;for(var o=0;o<this.freehandCounter;o++){this.points=e.extend([],this.pointColl[o].points,[]),this.pointCounter=0;for(var a=this.points.length,n=0;n<a;n++)if(0!==n){var r=!1;if(e.isNullOrUndefined(this.points[n-1])||e.isNullOrUndefined(this.points[n])||(r=this.isInside(t,i,this.points[n-1].x,this.points[n-1].y,this.points[n].x,this.points[n].y)),r){this.isFreehandDrawingPoint=!0,this.freehandDrawHoveredIndex=o,this.hoverFreehandraw(),this.upperCanvas.style.cursor="pointer",s=!0;break}if(!this.isFreehandDrawEditing||this.pointColl[o].isSelected){if(this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),e.isNullOrUndefined(this.activeObj.shape)||"none"!==this.textArea.style.display||this.drawObject("duplicate",this.activeObj),this.isFreehandDrawEditing){h=this.pointColl[o].strokeColor=this.selectedFreehandColor;this.hoverFreehandraw(h,this.pointColl[o].strokeWidth)}else this.freehandDrawHoveredIndex=null;this.isFreehandDrawingPoint=!1}}else{if(t>this.points[n].x-this.pointColl[o].strokeWidth&&t<this.points[n].x+this.pointColl[o].strokeWidth&&i>this.points[n].y-this.pointColl[o].strokeWidth&&i<this.points[n].y+this.pointColl[o].strokeWidth){this.isFreehandDrawingPoint=!0,this.freehandDrawHoveredIndex=o,this.hoverFreehandraw(),this.upperCanvas.style.cursor="pointer",s=!0;break}if(!this.isFreehandDrawEditing||this.pointColl[o].isSelected){if(this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),e.isNullOrUndefined(this.activeObj.shape)||"none"!==this.textArea.style.display||this.drawObject("duplicate",this.activeObj),this.isFreehandDrawEditing){var h="#fff"===this.pointColl[o].strokeColor?"#42a5f5":this.pointColl[o].strokeColor;this.hoverFreehandraw(h,this.pointColl[o].strokeWidth)}this.isFreehandDrawingPoint=!1}}if(s)break}},l.prototype.setCursorFromObj=function(t,i,s){for(var o=0;o<s.length;o++){var a=e.extend({},s[o],{},!0);if(t>=a.topLeftCircle.startX-2*a.topLeftCircle.radius&&t<=a.topLeftCircle.startX+2*a.topLeftCircle.radius&&i>=a.topLeftCircle.startY-2*a.topLeftCircle.radius&&i<=a.topLeftCircle.startY+2*a.topLeftCircle.radius){this.upperCanvas.style.cursor="nw-resize";break}if(t>=a.topCenterCircle.startX-2*a.topLeftCircle.radius&&t<=a.topCenterCircle.startX+2*a.topLeftCircle.radius&&i>=a.topCenterCircle.startY-2*a.topLeftCircle.radius&&i<=a.topCenterCircle.startY+2*a.topLeftCircle.radius){this.upperCanvas.style.cursor="n-resize";break}if(t>=a.topRightCircle.startX-2*a.topLeftCircle.radius&&t<=a.topRightCircle.startX+2*a.topLeftCircle.radius&&i>=a.topRightCircle.startY-2*a.topLeftCircle.radius&&i<=a.topRightCircle.startY+2*a.topLeftCircle.radius){this.upperCanvas.style.cursor="ne-resize";break}if(t>=a.centerLeftCircle.startX-2*a.topLeftCircle.radius&&t<=a.centerLeftCircle.startX+2*a.topLeftCircle.radius&&i>=a.centerLeftCircle.startY-2*a.topLeftCircle.radius&&i<=a.centerLeftCircle.startY+2*a.topLeftCircle.radius){this.upperCanvas.style.cursor="w-resize";break}if(t>=a.centerRightCircle.startX-2*a.topLeftCircle.radius&&t<=a.centerRightCircle.startX+2*a.topLeftCircle.radius&&i>=a.centerRightCircle.startY-2*a.topLeftCircle.radius&&i<=a.centerRightCircle.startY+2*a.topLeftCircle.radius){this.upperCanvas.style.cursor="e-resize";break}if(t>=a.bottomLeftCircle.startX-2*a.topLeftCircle.radius&&t<=a.bottomLeftCircle.startX+2*a.topLeftCircle.radius&&i>=a.bottomLeftCircle.startY-2*a.topLeftCircle.radius&&i<=a.bottomLeftCircle.startY+2*a.topLeftCircle.radius){this.upperCanvas.style.cursor="sw-resize";break}if(t>=a.bottomCenterCircle.startX-2*a.topLeftCircle.radius&&t<=a.bottomCenterCircle.startX+2*a.topLeftCircle.radius&&i>=a.bottomCenterCircle.startY-2*a.topLeftCircle.radius&&i<=a.bottomCenterCircle.startY+2*a.topLeftCircle.radius){this.upperCanvas.style.cursor="s-resize";break}if(t>=a.bottomRightCircle.startX-2*a.topLeftCircle.radius&&t<=a.bottomRightCircle.startX+2*a.topLeftCircle.radius&&i>=a.bottomRightCircle.startY-2*a.topLeftCircle.radius&&i<=a.bottomRightCircle.startY+2*a.topLeftCircle.radius){this.upperCanvas.style.cursor="se-resize";break}if(t>=a.activePoint.startX&&t<=a.activePoint.endX&&i>=a.activePoint.startY&&i<=a.activePoint.endY){this.upperCanvas.style.cursor="move";break}this.currObjType.isCustomCrop&&(this.upperCanvas.style.cursor="crosshair"),this.upperCanvas.style.cursor="default"}},l.prototype.isInside=function(t,e,i,s,o,a){var n=Math.min(i,o),r=Math.max(i,o),h=Math.min(s,a),l=Math.max(s,a);return n<=t&&t<=r&&h<=e&&e<=l},l.prototype.refreshDropDownBtn=function(t){if(!e.isNullOrUndefined(t)){var i=document.querySelector("#"+this.element.id+"_annotationBtn");e.isNullOrUndefined(i)||(t?(i.classList.add("e-disabled"),i.parentElement.classList.add("e-overlay")):(i.classList.remove("e-disabled"),i.parentElement.classList.remove("e-overlay")),e.getComponent(i,"dropdown-btn").disabled=t);var s=document.querySelector("#"+this.element.id+"_transformBtn");e.isNullOrUndefined(s)||(t?(s.classList.add("e-disabled"),s.parentElement.classList.add("e-overlay")):(s.classList.remove("e-disabled"),s.parentElement.classList.remove("e-overlay")),e.getComponent(s,"dropdown-btn").disabled=t);var o=document.querySelector("#"+this.element.id+"_adjustment");e.isNullOrUndefined(o)||(t?(o.classList.add("e-disabled"),o.parentElement.classList.add("e-overlay")):(o.classList.remove("e-disabled"),o.parentElement.classList.remove("e-overlay")),e.getComponent(o,"btn").disabled=t);var a=document.querySelector("#"+this.element.id+"_filter");e.isNullOrUndefined(a)||(t?(a.classList.add("e-disabled"),a.parentElement.classList.add("e-overlay")):(a.classList.remove("e-disabled"),a.parentElement.classList.remove("e-overlay")),e.getComponent(a,"btn").disabled=t)}},l.prototype.downloadImg=function(t,e){var i=document.createElement("a");i.href=t,i.target="_parent",i.download=e,(document.body||document.documentElement).appendChild(i),i.click(),i.parentNode.removeChild(i)},l.prototype.toSVGImg=function(t){a.showSpinner(this.element),this.element.style.opacity="0.5";var e=this.exportChangesToCanvas(),i=e.toDataURL();a.hideSpinner(this.element),this.element.style.opacity="1";var s=document.createElementNS("http://www.w3.org/2000/svg","svg");s.setAttribute("width",e.style.maxWidth),s.setAttribute("height",e.style.maxHeight);var o=document.createElementNS("http://www.w3.org/2000/svg","image");o.setAttributeNS(null,"height",e.height.toString()),o.setAttributeNS(null,"width",e.width.toString()),o.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",i),s.appendChild(o);var n='<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="'+e.width+'" height="'+e.height+'">'+s.innerHTML+"</svg>",r="data:image/svg+xml;base64,"+btoa(n);return null===t?r:(this.downloadImg(r,t+".svg"),null)},l.prototype.toBlobFn=function(t,e){var i=this;a.showSpinner(this.element),this.element.style.opacity="0.5",this.exportChangesToCanvas().toBlob(function(s){var o=URL.createObjectURL(s);i.downloadImg(o,t+"."+e),a.hideSpinner(i.element),i.element.style.opacity="1"},"image/png")},l.prototype.exportChangesToCanvas=function(){var t=this.calcRatio(),i=this.lowerContext.filter;if("none"!==this.lowerContext.filter){var s=this.lowerContext.filter.split(" "),o=parseFloat(s[5].split("(")[1]);o*=(t.width+t.height)/2,s[5]="blur("+o+"px)",this.lowerContext.filter=s.join(" ")}var a,n=this.createElement("canvas",{id:this.element.id+"_tempCanvas",attrs:{name:"canvasImage"}}),r=n.getContext("2d");if(r.filter=this.lowerContext.filter,e.isNullOrUndefined(this.currSelectionPoint)){n.width=this.baseImg.width,n.height=this.baseImg.height,a=this.calcMaxDimension(this.baseImg.width,this.baseImg.height),n.style.maxWidth=a.width+"px",n.style.maxHeight=a.height+"px",r.filter=this.lowerContext.filter;h=this.lowerContext.filter;this.updateBrightnessFilter(),r.drawImage(this.baseImg,this.srcLeft,this.srcTop,this.srcWidth,this.srcHeight,0,0,this.baseImg.width,this.baseImg.height),this.lowerContext.filter=h}else{n.width=this.destWidth,n.height=this.destHeight,r.filter=this.lowerContext.filter;h=this.lowerContext.filter;this.updateBrightnessFilter(),r.drawImage(this.baseImg,this.srcLeft,this.srcTop,this.srcWidth,this.srcHeight,0,0,this.destWidth,this.destHeight),this.lowerContext.filter=h}if(0===this.degree&&""===this.currFlipState||(this.updateSaveContext(r),this.exportTransformedImage(r)),this.objColl.length>0){var h=r.filter;r.filter="none";for(var l=e.extend([],this.objColl,[],!0),c=0;c<this.objColl.length;c++)this.objColl[c].activePoint.startX-=this.destLeft,this.objColl[c].activePoint.startY-=this.destTop,this.objColl[c].activePoint.endX-=this.destLeft,this.objColl[c].activePoint.endY-=this.destTop,this.objColl[c].activePoint.width=this.objColl[c].activePoint.endX-this.objColl[c].activePoint.startX,this.objColl[c].activePoint.height=this.objColl[c].activePoint.endY-this.objColl[c].activePoint.startY,e.isNullOrUndefined(this.currSelectionPoint)&&(this.objColl[c].activePoint.startX*=t.width,this.objColl[c].activePoint.startY*=t.height,this.objColl[c].activePoint.endX*=t.width,this.objColl[c].activePoint.endY*=t.height,this.objColl[c].activePoint.width=this.objColl[c].activePoint.endX-this.objColl[c].activePoint.startX,this.objColl[c].activePoint.height=this.objColl[c].activePoint.endY-this.objColl[c].activePoint.startY,this.objColl[c].strokeSettings.strokeWidth*=(t.width+t.height)/2,"text"===this.objColl[c].shape&&(this.objColl[c].textSettings.fontSize*=(t.width+t.height)/2)),this.drawObject("saveContext",this.objColl[c],null,null,!0,r);r.filter=h,this.refreshActiveObj(),this.objColl=l}if(this.freehandCounter>0){for(var d=e.extend({},this.pointColl,{},!0),p=0;p<this.freehandCounter;p++){this.points=e.extend([],this.pointColl[p].points,[]),this.pointCounter=0;var v=this.points.length;if(e.isNullOrUndefined(this.currSelectionPoint)){this.pointColl[p].strokeWidth*=(t.width+t.height)/2;for(b=0;b<v;b++)this.points[b].x=(this.points[b].x-this.destLeft)*t.width,this.points[b].y=(this.points[b].y-this.destTop)*t.height}else for(var b=0;b<v;b++)this.points[b].x-=this.destLeft,this.points[b].y-=this.destTop}this.freehandRedraw(r),this.pointColl=d}return this.isCircleCrop&&this.cropCircle(r,!0),this.lowerContext.filter=i,n},l.prototype.exportTransformedImage=function(t){for(var e=this.degree,i=0;i<this.rotateFlipColl.length;i++)"number"==typeof this.rotateFlipColl[i]?this.exportRotate(t,this.rotateFlipColl[i]):"horizontal"===this.rotateFlipColl[i]?this.exportHorizontalFlip(t):"vertical"===this.rotateFlipColl[i]&&this.exportVerticalFlip(t);this.degree=e},l.prototype.exportRotate=function(t,i){e.isNullOrUndefined(this.currSelectionPoint)?(this.setMaximumDimension(this.degree,t.canvas),t.translate(t.canvas.width/2,t.canvas.height/2),t.rotate(Math.PI/180*i),t.drawImage(this.inMemoryCanvas,this.srcLeft,this.srcTop,this.srcWidth,this.srcHeight,-t.canvas.height/2,-t.canvas.width/2,t.canvas.height,t.canvas.width)):(t.translate(t.canvas.width/2,t.canvas.height/2),t.rotate(Math.PI/180*i),t.drawImage(this.inMemoryCanvas,-t.canvas.height/2,-t.canvas.width/2,t.canvas.height,t.canvas.width)),this.updateSaveContext(t)},l.prototype.exportHorizontalFlip=function(t){t.translate(t.canvas.width,0),t.scale(-1,1),t.drawImage(this.inMemoryCanvas,0,0),this.updateSaveContext(t)},l.prototype.exportVerticalFlip=function(t){t.translate(0,t.canvas.height),t.scale(1,-1),t.drawImage(this.inMemoryCanvas,0,0),this.updateSaveContext(t)},l.prototype.updateSaveContext=function(t){t.setTransform(1,0,0,1,0,0);var e=t.getImageData(0,0,t.canvas.width,t.canvas.height);this.inMemoryCanvas.width=e.width,this.inMemoryCanvas.height=e.height,this.inMemoryContext.putImageData(e,0,0)},l.prototype.addLetter=function(t){if("none"===this.textArea.style.display&&(this.currObjType.isText||"text"===this.activeObj.shape)){"Backspace"===t?this.keyHistory=this.keyHistory.slice(0,-1):this.keyHistory+=t,this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),this.updateFontStyles();var e=this.upperContext.measureText(this.keyHistory+this.tempKeyHistory).width+.5*this.activeObj.textSettings.fontSize,i=this.activeObj.textSettings.fontSize+.25*this.activeObj.textSettings.fontSize;this.upperContext.fillText(this.keyHistory+this.tempKeyHistory,this.activeObj.activePoint.startX,this.activeObj.activePoint.startY+this.activeObj.textSettings.fontSize),this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),this.currObjType.isText=!0,this.setActivePoint(e,i)}},l.prototype.updateFontStyles=function(t){this.upperContext.strokeStyle=this.activeObj.strokeSettings.strokeColor,this.upperContext.fillStyle=this.activeObj.strokeSettings.strokeColor;var e="";this.activeObj.textSettings.bold&&(e="bold "),this.activeObj.textSettings.italic&&(e="italic "),this.activeObj.textSettings.bold&&this.activeObj.textSettings.italic&&(e="italic bold ");var i=t?parseFloat(this.textArea.style.fontSize):this.activeObj.textSettings.fontSize,s="block"===this.textArea.style.display?this.textArea.style.fontFamily:this.activeObj.textSettings.fontFamily;this.upperContext.font=e+i+"px "+s},l.prototype.textFlipDegree=function(t,e,i){for(var s=this.activeObj.keyHistory.split("\n"),o=(this.activeObj.textSettings.fontSize*s.length-this.activeObj.textSettings.fontSize*s.length)/s.length,a=.85*this.activeObj.textSettings.fontSize+o,n=0;n<s.length;n++){var r=s[n];n>0&&(1===n&&(a-=.85*this.activeObj.textSettings.fontSize),a+=this.activeObj.textSettings.fontSize+.15*this.activeObj.textSettings.fontSize),t.fillText(r,e+.15*this.activeObj.textSettings.fontSize,i+a+(n>0?.25*this.activeObj.textSettings.fontSize:.35*-this.activeObj.textSettings.fontSize))}},l.prototype.rotateText=function(t){var e,i=this.activeObj.activePoint.startX,s=this.activeObj.activePoint.startY;if((e=0===this.activeObj.shapeDegree?this.degree:this.degree-this.activeObj.shapeDegree)<0&&(e=360+e),e%360!=0||-360===this.degree&&""!==this.currFlipState)e%90==0&&e%180!=0?(t.translate(this.lowerCanvas.width/2,this.lowerCanvas.height/2),t.rotate(Math.PI/180*e),t.translate(-this.lowerCanvas.height/2,-this.lowerCanvas.width/2),e%90==0&&e%270!=0?(s=this.lowerCanvas.width-this.activeObj.activePoint.endX+.4*this.activeObj.textSettings.fontSize,i=this.activeObj.activePoint.startY):e%270==0&&(i=this.lowerCanvas.height-this.activeObj.activePoint.endY,s=this.activeObj.activePoint.startX+.4*this.activeObj.textSettings.fontSize),this.textFlipDegree(t,i,s),t.translate(this.lowerCanvas.height/2,this.lowerCanvas.width/2),t.rotate(Math.PI/180*-e),t.translate(-this.lowerCanvas.width/2,-this.lowerCanvas.height/2)):(t.translate(this.lowerCanvas.width/2,this.lowerCanvas.height/2),t.rotate(Math.PI/180*e),i=this.lowerCanvas.width-this.activeObj.activePoint.endX,s=this.lowerCanvas.height-this.activeObj.activePoint.endY+.4*this.activeObj.textSettings.fontSize,t.translate(-this.lowerCanvas.width/2,-this.lowerCanvas.height/2),this.textFlipDegree(t,i,s),t.translate(this.lowerCanvas.width/2,this.lowerCanvas.height/2),t.rotate(Math.PI/180*-e),t.translate(-this.lowerCanvas.width/2,-this.lowerCanvas.height/2));else{i=this.activeObj.activePoint.startX+.15*this.activeObj.textSettings.fontSize,s=this.activeObj.activePoint.startY+(this.activeObj.activePoint.endY-this.activeObj.activePoint.startY);for(var o=this.activeObj.keyHistory.split("\n"),a=0;a<o.length;a++)s=this.activeObj.activePoint.startY+(a*this.activeObj.textSettings.fontSize+.25*this.activeObj.textSettings.fontSize),t.fillText(o[a],i,s)}360!==this.degree&&-360!==this.degree||(this.degree=0)},l.prototype.redrawObj=function(t){if(this.objColl.length>0)if("horizontal"===t||"vertical"===t||"Horizontal"===t||"Vertical"===t||"horizontalVertical"===t||"verticalHorizontal"===t)this.updateCurrentActiveObjPoint(t.toLowerCase());else if("number"==typeof t){this.updateCurrentActiveObjPoint(t);var e=this.lowerContext.filter;this.lowerContext.filter=this.getDefaultFilter();for(var i=0;i<this.objColl.length;i++)"crop"!==this.objColl[i].shape.split("-")[0]&&this.apply(this.objColl[i].shape,this.objColl[i]);this.lowerContext.filter=e}},l.prototype.updateCurrentActiveObjPoint=function(t){for(var i,s=0;s<this.objColl.length;s++)if(this.activeObj.shape===this.objColl[s].shape&&this.activeObj.activePoint.startX===this.objColl[s].activePoint.startX&&this.activeObj.activePoint.startY===this.objColl[s].activePoint.startY&&this.activeObj.activePoint.endX===this.objColl[s].activePoint.endX&&this.activeObj.activePoint.endY===this.objColl[s].activePoint.endY&&this.activeObj.currIndex===this.objColl[s].currIndex){i=s;break}if("horizontal"===t||"vertical"===t||"Horizontal"===t||"Vertical"===t||"horizontalvertical"===t||"verticalhorizontal"===t){if("horizontal"===t||"Horizontal"===t)for(o=0;o<this.objColl.length;o++)this.objColl[o].shapeFlip!==this.currFlipState&&(this.objColl[o].activePoint.startX<=this.destLeft+this.destWidth/2?(this.objColl[o].activePoint.endX=this.destLeft+this.destWidth-(this.objColl[o].activePoint.startX-this.destLeft),this.objColl[o].activePoint.startX=this.objColl[o].activePoint.endX-this.objColl[o].activePoint.width,this.updateActiveObject(this.objColl[o].activePoint,this.objColl[o])):this.objColl[o].activePoint.startX>=this.destLeft+this.destWidth/2&&(this.objColl[o].activePoint.startX=this.destLeft+(this.destLeft+this.destWidth-this.objColl[o].activePoint.endX),this.objColl[o].activePoint.endX=this.objColl[o].activePoint.startX+this.objColl[o].activePoint.width,this.updateActiveObject(this.objColl[o].activePoint,this.objColl[o])),this.objColl[o].imageRatio={startX:(this.objColl[o].activePoint.startX-this.destLeft)/this.destWidth,startY:(this.objColl[o].activePoint.startY-this.destTop)/this.destHeight,endX:(this.objColl[o].activePoint.endX-this.destLeft)/this.destWidth,endY:(this.objColl[o].activePoint.endY-this.destTop)/this.destHeight,width:this.destWidth/this.objColl[o].activePoint.width,height:this.destHeight/this.objColl[o].activePoint.height},this.objColl[o].shapeFlip=this.currFlipState);else if("vertical"===t||"Vertical"===t)for(o=0;o<this.objColl.length;o++)this.objColl[o].shapeFlip!==this.currFlipState&&(this.objColl[o].activePoint.startY<=this.destTop+this.destHeight/2?(this.objColl[o].activePoint.endY=this.destTop+this.destHeight-(this.objColl[o].activePoint.startY-this.destTop),this.objColl[o].activePoint.startY=this.objColl[o].activePoint.endY-this.objColl[o].activePoint.height,this.updateActiveObject(this.objColl[o].activePoint,this.objColl[o])):this.objColl[o].activePoint.startY>=this.lowerCanvas.height/2&&(this.objColl[o].activePoint.startY=this.destTop+(this.destTop+this.destHeight-this.objColl[o].activePoint.endY),this.objColl[o].activePoint.endY=this.objColl[o].activePoint.startY+this.objColl[o].activePoint.height,this.updateActiveObject(this.objColl[o].activePoint,this.objColl[o])),this.objColl[o].imageRatio={startX:(this.objColl[o].activePoint.startX-this.destLeft)/this.destWidth,startY:(this.objColl[o].activePoint.startY-this.destTop)/this.destHeight,endX:(this.objColl[o].activePoint.endX-this.destLeft)/this.destWidth,endY:(this.objColl[o].activePoint.endY-this.destTop)/this.destHeight,width:this.destWidth/this.objColl[o].activePoint.width,height:this.destHeight/this.objColl[o].activePoint.height},this.objColl[o].shapeFlip=this.currFlipState);else if("verticalhorizontal"===t||"horizontalvertical"===t)for(o=0;o<this.objColl.length;o++)this.objColl[o].shapeFlip!==this.currFlipState&&(this.objColl[o].activePoint.startX<=this.destLeft+this.destWidth/2?(this.objColl[o].activePoint.endX=this.destLeft+this.destWidth-(this.objColl[o].activePoint.startX-this.destLeft),this.objColl[o].activePoint.startX=this.objColl[o].activePoint.endX-this.objColl[o].activePoint.width,this.updateActiveObject(this.objColl[o].activePoint,this.objColl[o])):this.objColl[o].activePoint.startX>=this.destLeft+this.destWidth/2&&(this.objColl[o].activePoint.startX=this.destLeft+(this.destLeft+this.destWidth-this.objColl[o].activePoint.endX),this.objColl[o].activePoint.endX=this.objColl[o].activePoint.startX+this.objColl[o].activePoint.width,this.updateActiveObject(this.objColl[o].activePoint,this.objColl[o])),this.objColl[o].activePoint.startY<=this.destTop+this.destHeight/2?(this.objColl[o].activePoint.endY=this.destTop+this.destHeight-(this.objColl[o].activePoint.startY-this.destTop),this.objColl[o].activePoint.startY=this.objColl[o].activePoint.endY-this.objColl[o].activePoint.height,this.updateActiveObject(this.objColl[o].activePoint,this.objColl[o])):this.objColl[o].activePoint.startY>=this.lowerCanvas.height/2&&(this.objColl[o].activePoint.startY=this.destTop+(this.destTop+this.destHeight-this.objColl[o].activePoint.endY),this.objColl[o].activePoint.endY=this.objColl[o].activePoint.startY+this.objColl[o].activePoint.height,this.updateActiveObject(this.objColl[o].activePoint,this.objColl[o])),this.objColl[o].imageRatio={startX:(this.objColl[o].activePoint.startX-this.destLeft)/this.destWidth,startY:(this.objColl[o].activePoint.startY-this.destTop)/this.destHeight,endX:(this.objColl[o].activePoint.endX-this.destLeft)/this.destWidth,endY:(this.objColl[o].activePoint.endY-this.destTop)/this.destHeight,width:this.destWidth/this.objColl[o].activePoint.width,height:this.destHeight/this.objColl[o].activePoint.height},this.objColl[o].shapeFlip=this.currFlipState);void 0!==i&&(this.activeObj=e.extend({},this.objColl[i],{},!0))}else if(90===t)this.rotateObjColl();else if(-90===t)for(o=0;o<3;o++)this.rotateObjColl();else if("number"==typeof t)if(t>0)this.rotateObjColl();else for(var o=0;o<3;o++)this.rotateObjColl()},l.prototype.rotateObjColl=function(){for(t=0;t<this.objColl.length;t++)this.objColl[t].activePoint.startY=this.destTop+this.destHeight*this.objColl[t].imageRatio.startX,this.objColl[t].activePoint.endY=this.destTop+this.destHeight*this.objColl[t].imageRatio.endX,this.objColl[t].activePoint.startX=this.destLeft+this.destWidth-this.destWidth*this.objColl[t].imageRatio.endY,this.objColl[t].activePoint.endX=this.destLeft+this.destWidth-this.destWidth*this.objColl[t].imageRatio.startY,this.objColl[t].activePoint.width=this.objColl[t].activePoint.endX-this.objColl[t].activePoint.startX,this.objColl[t].activePoint.height=this.objColl[t].activePoint.endY-this.objColl[t].activePoint.startY,this.updateFontSize(this.objColl[t]);for(t=0;t<this.objColl.length;t++)this.updateActiveObject(this.objColl[t].activePoint,this.objColl[t]);for(var t=0;t<this.objColl.length;t++)this.objColl[t].imageRatio={startX:(this.objColl[t].activePoint.startX-this.destLeft)/this.destWidth,startY:(this.objColl[t].activePoint.startY-this.destTop)/this.destHeight,endX:(this.objColl[t].activePoint.endX-this.destLeft)/this.destWidth,endY:(this.objColl[t].activePoint.endY-this.destTop)/this.destHeight,width:this.destWidth/this.objColl[t].activePoint.width,height:this.destHeight/this.objColl[t].activePoint.height}},l.prototype.redrawShape=function(t){for(var e=0;e<this.objColl.length;e++)if(JSON.stringify(t)===JSON.stringify(this.objColl[e])){this.objColl.splice(e,1);break}this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),this.isPreventDragging?(this.activeObj.activePoint.startX>this.destLeft&&(this.isPreventDragging=!1),this.drawObject("duplicate",null,null,null,!0)):this.drawObject("duplicate",null,null,null,!0)},l.prototype.applyActObj=function(){var t=!1;if(void 0!==this.activeObj.shape&&"text"===this.activeObj.shape&&""===this.activeObj.keyHistory)this.refreshActiveObj(),this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height);else{var i=void 0,s=!1;if(void 0!==this.activeObj.shape&&(i=this.activeObj.shape.split("-")),void 0===i&&this.currObjType.isCustomCrop?s=!0:void 0!==i&&"crop"===i[0]&&(s=!0),!e.isNullOrUndefined(this.activeObj.shape)&&!s){for(n=0;n<this.objColl.length;n++)if(JSON.stringify(this.activeObj)===JSON.stringify(this.objColl[n])){t=!0;break}if(!t){e.isNullOrUndefined(this.activeObj.currIndex)&&(this.activeObj.currIndex="shape_"+(this.objColl.length+1)),this.updateImageRatioForActObj();var o=this.activeObj.currIndex.split("_"),a=this.objColl.splice(0,parseInt(o[1],10)-1);a.push(e.extend({},this.activeObj,{},!0));for(var n=0;n<this.objColl.length;n++)a.push(this.objColl[n]);this.objColl=a,a=[],this.refreshActiveObj(),this.lowerContext.clearRect(0,0,this.lowerCanvas.width,this.lowerCanvas.height),this.redrawImgWithObj(),this.clearOuterCanvas(this.lowerContext),this.clearOuterCanvas(this.upperContext),this.currObjType.shape="",this.refreshActiveObj(),this.isCircleCrop&&this.cropCircle(this.lowerContext)}}}},l.prototype.apply=function(t,i,s){if(!this.disabled)if(this.togglePen&&!this.currObjType.isCustomCrop){var o=this.destLeft,a=this.destTop,n=this.destWidth,r=this.destHeight;this.callUpdateCurrentTransformedState();var h=this.lowerContext.filter;this.lowerContext.filter="none",this.togglePen=!1,this.iterateObjColl(),this.freehandRedraw(this.lowerContext),this.togglePen=!1,(this.isCircleCrop||!e.isNullOrUndefined(this.currSelectionPoint)&&"crop-circle"===this.currSelectionPoint.shape)&&this.cropCircle(this.lowerContext),this.destLeft=o,this.destTop=a,this.destWidth=n,this.destHeight=r,this.lowerContext.filter=h}else s=s||"original",this.currObjType.shape=void 0!==t?t:this.currObjType.shape,""!==this.currObjType.shape&&(this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),this.drawObject(s,i),this.activeObj.shape=this.currObjType.shape.toLowerCase(),t||""===this.currObjType.shape||this.currObjType.isCustomCrop||this.objColl.push(e.extend({},this.activeObj,{},!0)),this.keyHistory="")},l.prototype.setCenterPoints=function(t,e,i){var s,o;t&&e&&i?(s=e,o=i):(s=this.activeObj.activePoint.width,o=this.activeObj.activePoint.height),this.activeObj.activePoint.startX=this.lowerCanvas.width/2-s/2,this.activeObj.activePoint.startY=this.lowerCanvas.height/2-o/2,this.activeObj.activePoint.endX=this.lowerCanvas.width/2+s/2,this.activeObj.activePoint.endY=this.lowerCanvas.height/2+o/2,t&&e&&i&&(this.textStartPoints.x=this.activeObj.activePoint.startX,this.textStartPoints.y=this.activeObj.activePoint.startY)},l.prototype.drawShape=function(t,i,s,o,a,n,r){if(!this.disabled&&this.isImageLoaded){this.redrawActObj();var h=e.extend([],this.objColl,[],!0);if(this.togglePen=!1,this.keyHistory="",this.upperCanvas.style.display="block",this.refreshActiveObj(),this.currObjType.shape=t,"freehanddraw"!==this.currObjType.shape.toLowerCase()&&""!==this.currObjType.shape.toLowerCase()){this.activeObj.shape=this.currObjType.shape.toLowerCase(),this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),e.isNullOrUndefined(this.activeObj.strokeSettings)&&(this.activeObj.strokeSettings=this.strokeSettings),this.activeObj.strokeSettings.strokeWidth=i||this.activeObj.strokeSettings.strokeWidth,this.activeObj.strokeSettings.strokeColor=s||this.activeObj.strokeSettings.strokeColor,this.activeObj.strokeSettings.fillColor=o||this.activeObj.strokeSettings.fillColor;var l=this.destWidth>100?100:this.destWidth/2,c=this.destHeight>100?100:this.destHeight/2;this.activeObj.activePoint.width=l,this.activeObj.activePoint.height=c,"line"===this.currObjType.shape.toLowerCase()?(this.activeObj.lineDraw="horizontal",this.activeObj.activePoint.height/=2):"rectangle"===this.currObjType.shape.toLowerCase()&&(this.activeObj.activePoint.width+=this.activeObj.activePoint.width/2),"ellipse"===this.currObjType.shape.toLowerCase()&&n&&(this.activeObj.activePoint.width=2*n,this.activeObj.activePoint.height=2*r),n&&r&&(this.activeObj.activePoint.width=n,this.activeObj.activePoint.height=r),e.isNullOrUndefined(a)?this.setCenterPoints():(this.activeObj.activePoint.startX=a.x,this.activeObj.activePoint.startY=a.y,this.activeObj.activePoint.endX=this.activeObj.activePoint.startX+this.activeObj.activePoint.width,this.activeObj.activePoint.endY=this.activeObj.activePoint.startY+this.activeObj.activePoint.height),this.currObjType.isDragging=this.currObjType.isCustomCrop=!1,this.activeObj.shapeDegree=this.degree,this.activeObj.shapeFlip=this.currFlipState,this.activeObj.flipObjColl=[];var d=this.updatePreviousShapeSettings(),p={action:"insert",previousShapeSettings:d,currentShapeSettings:d};this.trigger("shapeChanging",p),this.updateShapeChangeEventArgs(p.currentShapeSettings),this.drawObject("duplicate"),this.isShapeInserted=!0,this.updateUndoRedoObj(h),this.refreshToolbar("shapes")}}},l.prototype.drawShapeText=function(t,i,s,o,a,n,r,h){if(!this.disabled&&this.isImageLoaded){"freehanddraw"===this.currObjType.shape&&(this.apply(),this.upperCanvas.style.cursor="default",this.currObjType.shape=""),this.togglePen=!1,this.redrawActObj();var l=this.getCurrentObj();l.objColl=e.extend([],this.objColl,[],!0),l.pointColl=e.extend([],this.pointColl,[],!0),l.afterCropActions=e.extend([],this.afterCropActions,[],!0),this.keyHistory="",this.refreshActiveObj(),this.activeObj.shape="text",this.currObjType.isCustomCrop=!1,this.currObjType.isText=this.currObjType.isInitialText=!0,this.upperCanvas.style.display="block",this.currObjType.shape=this.activeObj.shape="text",e.isNullOrUndefined(this.activeObj.textSettings)&&(this.activeObj.textSettings=this.textSettings),e.isNullOrUndefined(this.activeObj.strokeSettings)&&(this.activeObj.strokeSettings=this.strokeSettings),this.activeObj.strokeSettings.strokeColor=n||this.activeObj.strokeSettings.strokeColor,this.activeObj.textSettings.text=t||this.activeObj.textSettings.text,this.activeObj.textSettings.fontFamily=i||this.activeObj.textSettings.fontFamily,this.activeObj.textSettings.text=t||this.activeObj.textSettings.text,this.activeObj.textSettings.fontFamily=i||this.activeObj.textSettings.fontFamily,this.activeObj.textSettings.fontSize=s||this.activeObj.textSettings.fontSize,this.activeObj.textSettings.bold=o||this.activeObj.textSettings.bold,this.activeObj.textSettings.italic=a||this.activeObj.textSettings.italic,e.isNullOrUndefined(this.activeObj.textSettings.fontSize)&&(this.lowerCanvas.width>this.lowerCanvas.height?this.activeObj.textSettings.fontSize=Math.floor(this.lowerCanvas.width/20):this.activeObj.textSettings.fontSize=Math.floor(this.lowerCanvas.height/20),this.activeObj.textSettings.fontSize<20&&(this.activeObj.textSettings.fontSize=20)),this.destWidth<100?this.activeObj.textSettings.fontSize=Math.floor(this.destWidth/20):this.destHeight<100&&(this.activeObj.textSettings.fontSize=Math.floor(this.destHeight/20)),this.activeObj.shapeDegree=this.degree,this.activeObj.shapeFlip=this.currFlipState,this.activeObj.flipObjColl=[],this.updateFontStyles();var c=this.upperContext.measureText(this.activeObj.textSettings.text).width+.5*this.activeObj.textSettings.fontSize,d=this.activeObj.textSettings.fontSize+.25*this.activeObj.textSettings.fontSize;e.isNullOrUndefined(r)||e.isNullOrUndefined(h)?this.setCenterPoints(!0,c,d):(this.activeObj.activePoint.startX=r,this.activeObj.activePoint.startY=h,this.activeObj.activePoint.endX=this.activeObj.activePoint.startX+c,this.activeObj.activePoint.endY=this.activeObj.activePoint.startY+d);var p=this.updatePreviousShapeSettings(),v={action:"insert",previousShapeSettings:p,currentShapeSettings:p};this.trigger("shapeChanging",v),this.updateShapeChangeEventArgs(v.currentShapeSettings),this.addLetter(this.activeObj.textSettings.text),this.activeObj.textFlip=this.currFlipState,this.updateFontRatio(this.activeObj),this.objColl.push(this.activeObj);var b=e.extend({},this.cropObj,{},!0);this.updateUndoRedoColl("shapeTransform",l,l.objColl,l.pointColl,b),this.redrawShape(this.objColl[this.objColl.length-1]),this.isShapeInserted=!0,this.refreshToolbar("text")}},l.prototype.updateShapeChangeEventArgs=function(t){if(this.activeObj.currIndex=t.id,this.activeObj.activePoint.startX=t.startX,this.activeObj.activePoint.startY=t.startY,this.activeObj.activePoint.width=t.width,this.activeObj.activePoint.height=t.height,this.activeObj.strokeSettings.strokeColor=t.strokeColor,this.activeObj.strokeSettings.fillColor=t.fillColor,"ellipse"===this.activeObj.shape&&(this.activeObj.activePoint.width=t.radius/2),"line"===this.activeObj.shape&&(this.activeObj.activePoint.width=t.length),"text"===this.activeObj.shape&&(this.activeObj.keyHistory=t.text),"text"===this.activeObj.shape&&(this.activeObj.textSettings.fontSize=t.fontSize),"text"===this.activeObj.shape&&(this.activeObj.strokeSettings.strokeColor=t.color),"text"===this.activeObj.shape&&!e.isNullOrUndefined(this.activeObj.textSettings))for(var i=0;i<t.fontStyle.length;i++)"bold"===t.fontStyle[i]?this.activeObj.textSettings.bold=!0:"italic"===t.fontStyle[i]?this.activeObj.textSettings.italic=!0:"underline"===t.fontStyle[i]&&(this.activeObj.textSettings.underline=!0)},l.prototype.getObjDetails=function(t){var e={};return e.id=t.currIndex,e.type=this.toPascalCase(t.shape),e.startX=t.activePoint.startX,e.startY=t.activePoint.startY,"rectangle"===t.shape?(e.width=t.activePoint.width,e.height=t.activePoint.height,e.strokeColor=t.strokeSettings.strokeColor,e.fillColor=t.strokeSettings.fillColor,e.strokeWidth=t.strokeSettings.strokeWidth):"ellipse"===t.shape?(e.radius=t.activePoint.width/2,e.strokeColor=t.strokeSettings.strokeColor,e.fillColor=t.strokeSettings.fillColor,e.strokeWidth=t.strokeSettings.strokeWidth):"line"===t.shape?(e.length=t.activePoint.width,e.strokeColor=t.strokeSettings.strokeColor,e.strokeWidth=t.strokeSettings.strokeWidth):"text"===t.shape&&(e.text=t.keyHistory,e.fontSize=t.textSettings.fontSize,e.color=t.strokeSettings.strokeColor,e.fontStyle=[],t.textSettings.bold&&e.fontStyle.push("bold"),t.textSettings.italic&&e.fontStyle.push("italic")),e},l.prototype.getFreehandDrawDetails=function(t){var i={};return i.id=this.pointColl[t].id,i.type="FreehandDraw",i.points=e.extend([],this.pointColl[t].points),i.strokeColor=this.pointColl[t].strokeColor,i.strokeWidth=this.pointColl[t].strokeWidth,i},l.prototype.isPointsInRange=function(t,e){var i=!1;return t>=0&&e>=0&&t<=this.lowerCanvas.width&&e<=this.lowerCanvas.width&&(i=!0),i},l.prototype.clearActObj=function(){"none"===this.textArea.style.display&&(this.refreshActiveObj(),this.applyActObj(),this.refreshActiveObj(),this.currObjType.isCustomCrop=!1)},l.prototype.applyPenDraw=function(){"freehanddraw"===this.currObjType.shape&&(this.apply(),this.upperCanvas.style.cursor="default",this.currObjType.shape=""),this.clearActObj()},l.prototype.drawRotatedImage=function(t){0===t?this.degree=0:this.degree+=t,360!==this.degree&&-360!==this.degree||(this.degree=0),this.setDestinationPoints();var i=e.extend([],this.objColl,[],!0),s=e.extend({},this.activeObj,{},!0);if(this.objColl=[],this.refreshActiveObj(),this.isReverseRotate||this.updateCurrentTransformedState("initial"),this.rotateDegree(t),this.isReverseRotate||(this.updateCurrentTransformedState("reverse"),this.rotateFlipColl.push(t)),1===this.rotateFlipColl.length&&this.setClientTransformedDimension(),this.objColl=e.extend([],i,[],!0),this.activeObj=e.extend({},s,{},!0),this.isCircleCrop&&this.cropCircle(this.lowerContext),this.redrawObj(t),this.refreshActiveObj(),t>0)this.rotateFreehandDrawColl();else for(var o=0;o<3;o++)this.rotateFreehandDrawColl();this.freehandRedraw(this.lowerContext),this.updateCurrSelectionPoint(t)},l.prototype.updateCurrSelectionPoint=function(t){if(!e.isNullOrUndefined(this.currSelectionPoint)&&!e.isNullOrUndefined(this.currDestinationPoint)){var i=e.extend({},this.activeObj,{},!0),s=e.extend([],this.objColl,[],!0),o={startX:this.srcLeft,startY:this.srcTop,width:this.srcWidth,height:this.srcHeight},a={startX:this.destLeft,startY:this.destTop,width:this.destWidth,height:this.destHeight};this.objColl=[],this.objColl.push(e.extend({},this.currSelectionPoint,{},!0)),this.srcLeft=0,this.srcTop=0,this.srcWidth=this.baseImg.width,this.srcHeight=this.baseImg.height,this.destLeft=this.currDestinationPoint.startX,this.destTop=this.currDestinationPoint.startY,this.destWidth=this.currDestinationPoint.width,this.destHeight=this.currDestinationPoint.height,"number"==typeof t&&(this.setDestinationPoints(),this.setClientTransformedDimension()),this.objColl[0].shapeFlip="",this.redrawObj(t),this.currSelectionPoint=e.extend({},this.objColl[0],{},!0),this.currDestinationPoint={startX:this.destLeft,startY:this.destTop,width:this.destWidth,height:this.destHeight},this.objColl=s,this.activeObj=i,this.srcLeft=o.startX,this.srcTop=o.startY,this.srcWidth=o.width,this.srcHeight=o.height,this.destLeft=a.startX,this.destTop=a.startY,this.destWidth=a.width,this.destHeight=a.height}},l.prototype.setClientTransformedDimension=function(t){if(this.degree%90==0&&this.degree%180!=0){this.destLeft=(this.lowerCanvas.width-this.destHeight)/2,this.destTop=(this.lowerCanvas.height-this.destWidth)/2;var i=this.destWidth;this.destWidth=this.destHeight,this.destHeight=i}else e.isNullOrUndefined(t)&&(this.destLeft=(this.lowerCanvas.width-this.destWidth)/2,this.destTop=(this.lowerCanvas.height-this.destHeight)/2)},l.prototype.popForDefaultTransformedState=function(t){for(var e=0,i=0,s=0,o=0,a=0;a<t.length;a++)90===t[a]||"rotateRight"===t[a]?(i=0,s=0,o=0,4===++e&&(t.pop(),t.pop(),t.pop(),t.pop())):-90===t[a]||"rotateLeft"===t[a]?(e=0,s=0,o=0,4===++i&&(t.pop(),t.pop(),t.pop(),t.pop())):"horizontal"===t[a]||"horizontalflip"===t[a]?(i=0,e=0,o=0,2===++s&&(t.pop(),t.pop())):"vertical"!==t[a]&&"verticalflip"!==t[a]||(s=0,i=0,e=0,2===++o&&(t.pop(),t.pop()));return t},l.prototype.popForDefaultFlipState=function(t){for(var i=0;i<t.length;i++)e.isNullOrUndefined(t[i+3])||("horizontal"!==t[i]&&"horizontalFlip"!==t[i]||"vertical"!==t[i+1]&&"verticalFlip"!==t[i]||"horizontal"!==t[i+2]&&"horizontalFlip"!==t[i]||"vertical"!==t[i+3]&&"verticalFlip"!==t[i]?"vertical"!==t[i]&&"verticalFlip"!==t[i]||"horizontal"!==t[i+1]&&"horizontalFlip"!==t[i+1]||"vertical"!==t[i+2]&&"verticalFlip"!==t[i]||"horizontal"!==t[i+3]&&"horizontalFlip"!==t[i]||(t.pop(),t.pop(),t.pop(),t.pop()):(t.pop(),t.pop(),t.pop(),t.pop()));return t},l.prototype.popForDefaultRotateState=function(t){for(var i=0;i<t.length;i++)e.isNullOrUndefined(t[i+1])||(90!==t[i]&&"rotateRight"!==t[i]||-90!==t[i+1]&&"rotateLeft"!==t[i]?-90!==t[i]&&"rotateLeft"!==t[i]||90!==t[i+1]&&"rotateRight"!==t[i]||(t.pop(),t.pop()):(t.pop(),t.pop()));return t},l.prototype.alignRotateFlipColl=function(t,e){return t=this.popForDefaultTransformedState(t),t=this.popForDefaultFlipState(t),0===(t=this.popForDefaultRotateState(t)).length&&e&&(this.degree=0,this.currFlipState=""),t},l.prototype.updateFlipColl=function(t){if(0===this.flipColl.length?this.flipColl.push(t):"direction"===this.flipColl[this.flipColl.length-1]?this.flipColl.pop():this.flipColl.push(t),this.flipColl.length>=4)if("horizontal"===this.flipColl[this.flipColl.length-1]&&"vertical"===this.flipColl[this.flipColl.length-2]&&"horizontal"===this.flipColl[this.flipColl.length-3]&&"vertical"===this.flipColl[this.flipColl.length-4])for(e=0;e<4;e++)this.flipColl.pop();else if("vertical"===this.flipColl[this.flipColl.length-1]&&"horizontal"===this.flipColl[this.flipColl.length-2]&&"vertical"===this.flipColl[this.flipColl.length-3]&&"horizontal"===this.flipColl[this.flipColl.length-4])for(var e=0;e<4;e++)this.flipColl.pop()},l.prototype.horizontalFlip=function(){this.lowerContext.translate(this.lowerContext.canvas.width,0),this.lowerContext.scale(-1,1),this.upperContext.translate(this.upperContext.canvas.width,0),this.upperContext.scale(-1,1)},l.prototype.verticalFlip=function(){this.lowerContext.translate(0,this.lowerContext.canvas.height),this.lowerContext.scale(1,-1),this.upperContext.translate(0,this.upperContext.canvas.height),this.upperContext.scale(1,-1)},l.prototype.updateFlipState=function(t){"horizontal"===t&&this.degree%90==0&&this.degree%180!=0?this.verticalFlip():"vertical"===t&&this.degree%90==0&&this.degree%180!=0?this.horizontalFlip():"horizontal"===t?this.horizontalFlip():"vertical"===t&&this.verticalFlip()},l.prototype.setDestinationPoints=function(){var t;this.degree%90==0&&this.degree%180!=0?(t=this.calcMaxDimension(this.srcHeight,this.srcWidth),this.isRotateZoom&&(t.width+=t.width*this.zoomFactor,t.height+=t.height*this.zoomFactor,this.destWidth=t.height,this.destHeight=t.width),this.destLeft=(this.lowerCanvas.clientWidth-t.height)/2,this.destTop=(this.lowerCanvas.clientHeight-t.width)/2,this.destWidth=t.height,this.destHeight=t.width):(t=this.calcMaxDimension(this.srcWidth,this.srcHeight),this.isRotateZoom&&(t.width+=t.width*this.zoomFactor,t.height+=t.height*this.zoomFactor,this.destWidth=t.width,this.destHeight=t.height),this.destLeft=(this.lowerCanvas.clientWidth-t.width)/2,this.destTop=(this.lowerCanvas.clientHeight-t.height)/2,this.destWidth=t.width,this.destHeight=t.height)},l.prototype.rotatedFlip=function(){this.isReverseFlip=!0;var t=this.currFlipState,i=this.flipColl,s=e.extend([],this.objColl,[],!0),o=e.extend({},this.activeObj,{},!0);this.flipColl=[],this.objColl=[],this.refreshActiveObj(),this.currentTransformedState("initial");var a=this.lowerContext.filter;this.updateBrightnessFilter(),this.lowerContext.drawImage(this.baseImg,this.srcLeft,this.srcTop,this.srcWidth,this.srcHeight,this.destLeft,this.destTop,this.destWidth,this.destHeight),this.lowerContext.filter=a,this.currentTransformedState("reverse",!0),""===t&&""!==this.currFlipState&&(t=this.currFlipState),this.currFlipState=t,this.flipColl=i,this.objColl=e.extend([],s,[],!0),this.lowerContext.filter="none",this.iterateObjColl(),this.lowerContext.filter=a,0!==o.activePoint.width&&(this.activeObj=e.extend({},o,{},!0)),this.isReverseFlip=!1},l.prototype.getFilterValue=function(t){return 0===t?1:1+.5*t/100},l.prototype.setFilterValue=function(t){var e;return e=1===t?0:100*(t-1)/.5,Math.round(e)},l.prototype.getSaturationFilterValue=function(t){return 0===t?1:1+t/100},l.prototype.setSaturationFilterValue=function(t){var e;return e=1===t?0:100*(t-1),Math.round(e)},l.prototype.getBlackAndWhiteData=function(t){for(var e=0;e<t.data.length;e+=4){var i=0;t.data[e]+t.data[e+1]+t.data[e+2]>383&&(i=255),t.data[e]=i,t.data[e+1]=i,t.data[e+2]=i,t.data[e+3]=255}return t},l.prototype.setBrightness=function(t){this.applyPenDraw(),this.adjustmentLevel.brightness=t,t=this.getFilterValue(t);var i=e.extend({},this.cropObj,{},!0),s=this.getCurrentObj();s.objColl=e.extend([],this.objColl,[],!0),s.pointColl=e.extend([],this.pointColl,[],!0),s.afterCropActions=e.extend([],this.afterCropActions,[],!0),this.updateAdjustment("brightness",t),this.updateUndoRedoColl("brightness",s,s.objColl,s.pointColl,i)},l.prototype.setContrast=function(t){this.applyPenDraw(),this.adjustmentLevel.contrast=t,t=this.getFilterValue(t),t*=100;var i=e.extend({},this.cropObj,{},!0),s=this.getCurrentObj();s.objColl=e.extend([],this.objColl,[],!0),s.pointColl=e.extend([],this.pointColl,[],!0),s.afterCropActions=e.extend([],this.afterCropActions,[],!0),this.updateAdjustment("contrast",t),this.updateUndoRedoColl("contrast",s,s.objColl,s.pointColl,i)},l.prototype.setHue=function(t){this.applyPenDraw(),this.adjustmentLevel.hue=t,t*=3;var i=e.extend({},this.cropObj,{},!0),s=this.getCurrentObj();s.objColl=e.extend([],this.objColl,[],!0),s.pointColl=e.extend([],this.pointColl,[],!0),s.afterCropActions=e.extend([],this.afterCropActions,[],!0),this.updateAdjustment("hue",t),this.updateUndoRedoColl("hue",s,s.objColl,s.pointColl,i)},l.prototype.setSaturation=function(t){this.applyPenDraw(),this.adjustmentLevel.saturation=t,t=this.getSaturationFilterValue(t),t*=100;var i=e.extend({},this.cropObj,{},!0),s=this.getCurrentObj();s.objColl=e.extend([],this.objColl,[],!0),s.pointColl=e.extend([],this.pointColl,[],!0),s.afterCropActions=e.extend([],this.afterCropActions,[],!0),this.updateAdjustment("saturation",t),this.updateUndoRedoColl("saturation",s,s.objColl,s.pointColl,i)},l.prototype.setOpacity=function(t){this.applyPenDraw(),this.adjustmentLevel.opacity=t,t>=50?t/=100:40===t?t=.45:30===t?t=.4:20===t?t=.35:10===t?t=.3:0===t&&(t=.25);var i=e.extend({},this.cropObj,{},!0),s=this.getCurrentObj();s.objColl=e.extend([],this.objColl,[],!0),s.pointColl=e.extend([],this.pointColl,[],!0),s.afterCropActions=e.extend([],this.afterCropActions,[],!0),this.updateAdjustment("opacity",t),this.updateUndoRedoColl("opacity",s,s.objColl,s.pointColl,i)},l.prototype.setBlur=function(t){this.applyPenDraw(),this.adjustmentLevel.blur=t,t/=20,t+=.5;var i=e.extend({},this.cropObj,{},!0),s=this.getCurrentObj();s.objColl=e.extend([],this.objColl,[],!0),s.pointColl=e.extend([],this.pointColl,[],!0),s.afterCropActions=e.extend([],this.afterCropActions,[],!0),this.updateAdjustment("blur",t),this.updateUndoRedoColl("blur",s,s.objColl,s.pointColl,i)},l.prototype.setExposure=function(t){this.applyPenDraw(),this.adjustmentLevel.exposure=t,t=this.getFilterValue(t);var i=e.extend({},this.cropObj,{},!0),s=this.getCurrentObj();s.objColl=e.extend([],this.objColl,[],!0),s.pointColl=e.extend([],this.pointColl,[],!0),s.afterCropActions=e.extend([],this.afterCropActions,[],!0),this.updateAdjustment("exposure",t),this.updateUndoRedoColl("exposure",s,s.objColl,s.pointColl,i)},l.prototype.setFilter=function(t){t=t.toLowerCase(),this.applyPenDraw();var i=this.currentFilter,s=e.extend({},this.cropObj,{},!0),o=this.getCurrentObj();o.objColl=e.extend([],this.objColl,[],!0),o.pointColl=e.extend([],this.pointColl,[],!0),o.afterCropActions=e.extend([],this.afterCropActions,[],!0),this.updateAdjustment(t,null),this.updateUndoRedoColl(t,o,o.objColl,o.pointColl,s,null,null,i)},l.prototype.renderImage=function(){var t=this.lowerContext.filter;this.applyActObj(),this.upperContext.clearRect(0,0,this.lowerCanvas.width,this.lowerCanvas.height),this.lowerContext.clearRect(0,0,this.lowerCanvas.width,this.lowerCanvas.height),this.updateCurrentTransformedState("initial"),this.updateBrightnessFilter(),this.lowerContext.drawImage(this.baseImg,this.srcLeft,this.srcTop,this.srcWidth,this.srcHeight,this.destLeft,this.destTop,this.destWidth,this.destHeight),this.updateCurrentTransformedState("reverse"),this.lowerContext.filter="none",this.iterateObjColl(),this.freehandRedraw(this.lowerContext),this.lowerContext.filter=t,(this.isCircleCrop||!e.isNullOrUndefined(this.currSelectionPoint)&&"crop-circle"===this.currSelectionPoint.shape)&&this.cropCircle(this.lowerContext)},l.prototype.updateTextBox=function(t){this.upperContext.clearRect(0,0,this.lowerCanvas.width,this.lowerCanvas.height),this.lowerContext.clearRect(0,0,this.lowerCanvas.width,this.lowerCanvas.height),this.redrawImgWithObj(),this.textArea.style.display="block",this.textArea.style.fontFamily=t.textSettings.fontFamily,this.textArea.style.fontSize=t.textSettings.fontSize+"px",this.textArea.style.color=t.strokeSettings.strokeColor,this.textArea.style.fontWeight=t.textSettings.bold?"bold":"normal",this.textArea.style.fontStyle=t.textSettings.italic?"italic":"normal",this.textArea.style.border="2px solid "+this.themeColl[this.theme].primaryColor,this.textArea.value=t.keyHistory,this.activeObj=e.extend({},t,{},!0),this.updateFontStyles(),this.textArea.style.width=this.activeObj.activePoint.width+"px"},l.prototype.drawNewSelection=function(t,e,i,s,o){var a,n="crop-"+t;"crop-custom"===n.toLowerCase()?(""===this.currObjType.shape&&this.drawCustomSelection("crop-custom"),e&&i&&(this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),this.currObjType.shape=this.activeObj.shape=n.toLowerCase(),this.activeObj.activePoint.startX=e,this.activeObj.activePoint.startY=i,this.activeObj.activePoint.endX=this.lowerCanvas.width,this.activeObj.activePoint.endY=this.lowerCanvas.height,this.activeObj.activePoint.width=this.activeObj.activePoint.endX-this.activeObj.activePoint.startX,this.activeObj.activePoint.height=this.activeObj.activePoint.endY-this.activeObj.activePoint.startY,this.drawObject("duplicate"))):"crop-canvas"===n.toLowerCase()?(this.upperCanvas.style.display="none",this.dragCanvas=!0):(this.currObjType.isCustomCrop=!1,this.currObjType.shape=n.toLowerCase(),s&&o?a={startX:e,startY:i,endX:e+s,endY:i+o,width:s,height:o}:s&&"crop-circle"===n&&(a={startX:e,startY:i,endX:e+s,endY:i+s,width:s,height:s}),this.activeObj.shape=n.toLowerCase(),this.drawObject("duplicate",null,!0,a))},l.prototype.setDestPointsForFlipState=function(t){""!==this.getCurrentPanRegion()&&("horizontal"===this.getCurrentPanRegion()?this.destLeft=this.lowerCanvas.clientWidth-(this.destWidth+this.destLeft):"vertical"===this.getCurrentPanRegion()?this.destTop=this.lowerCanvas.clientHeight-(this.destHeight+this.destTop):(this.destLeft=this.lowerCanvas.clientWidth-(this.destWidth+this.destLeft),this.destTop=this.lowerCanvas.clientHeight-(this.destHeight+this.destTop)))},l.prototype.performUndoDefaultAction=function(t){this.lowerContext.filter=t.previousObj.filter,this.objColl=[],this.pointColl=[],this.freehandCounter=0,this.setCurrentObj(t.previousObj),this.destLeft=t.previousObj.destPoints.startX,this.destTop=t.previousObj.destPoints.startY;var i=e.extend({},this.activeObj,{},!0);this.objColl=e.extend([],t.previousObjColl,[],!0),this.pointColl=e.extend([],t.previousPointColl,[],!0),this.freehandCounter=this.pointColl.length,this.lowerContext.filter="none",this.iterateObjColl(),this.freehandRedraw(this.lowerContext),this.lowerContext.filter=t.previousObj.filter,this.activeObj=i,this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),0!==this.activeObj.activePoint.width&&0!==this.activeObj.activePoint.height&&this.drawObject("duplicate")},l.prototype.setAdjustment=function(t){var e,i,s=this.lowerContext.filter.split(" ");switch(t){case"brightness":i=s[0].split("("),e=parseFloat(i[1].split(")")[0]),this.adjustmentLevel.brightness=this.setFilterValue(e);break;case"contrast":i=s[1].split("("),e=parseFloat(i[1].split(")")[0]),e/=100,this.adjustmentLevel.contrast=this.setFilterValue(e);break;case"hue":i=s[2].split("("),e=parseFloat(i[1].split(")")[0]),e/=3,this.adjustmentLevel.hue=e;break;case"saturation":i=s[3].split("("),e=parseFloat(i[1].split(")")[0]),e/=100,this.adjustmentLevel.saturation=this.setSaturationFilterValue(e);break;case"opacity":i=s[4].split("("),.45===(e=parseFloat(i[1].split(")")[0]))?e=40:.4===e?e=30:.35===e?e=20:.3===e?e=10:.25===e?e=0:e*=100,this.adjustmentLevel.opacity=e;break;case"blur":i=s[5].split("("),e=parseFloat(i[1].split(")")[0]),e*=20,this.adjustmentLevel.blur=e;break;case"exposure":i=s[0].split("("),e=parseFloat(i[1].split(")")[0]),this.adjustmentLevel.exposure=this.setFilterValue(e)}},l.prototype.updateFilter=function(t,i){if("default"===t||"chrome"===t||"cold"===t||"warm"===t||"grayscale"===t||"blackandwhite"===t||"sepia"===t||"invert"===t||"sharpen"===t){var s=this.element.querySelector(".e-contextual-toolbar-wrapper .e-toolbar-item.e-selected");s&&s.classList.remove("e-selected");var o=document.getElementById(this.element.id+"_"+t+"Canvas");o&&o.parentElement.classList.add("e-selected"),e.isNullOrUndefined(i)?this.currentFilter=this.element.id+"_"+t:this.currentFilter=i}},l.prototype.clearSelection=function(){!this.disabled&&this.isImageLoaded&&(this.togglePen=!1,this.refreshActiveObj(),this.dragElement="",this.dragPoint.startX=this.dragPoint.startY=this.dragPoint.endX=this.dragPoint.endY=0,this.currObjType.shape="",this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),this.currObjType.isActiveObj=!0,this.currObjType.isCustomCrop=!1,this.upperCanvas.style.cursor="default")},l.prototype.crop=function(){var t=!1;if(!this.disabled&&this.isImageLoaded){this.currObjType.isUndoAction&&this.refreshUndoRedoColl();var i=void 0,s={startPoint:{x:this.activeObj.activePoint.startX,y:this.activeObj.activePoint.startY},endPoint:{x:this.activeObj.activePoint.endX,y:this.activeObj.activePoint.endY}};if(this.trigger("cropping",s),void 0!==this.activeObj.shape&&(i=this.activeObj.shape.split("-")),!this.disabled&&void 0!==this.activeObj.horTopLine&&(this.currObjType.isCustomCrop||"crop"===i[0])){t=!0;var o=e.extend({},this.cropObj,{},!0),a=this.getCurrentObj();a.objColl=e.extend([],this.objColl,[],!0),a.pointColl=e.extend([],this.pointColl,[],!0),a.afterCropActions=e.extend([],this.afterCropActions,[],!0),this.cropImg(),this.zoomFactor=0,this.enableDisableToolbarBtn(),this.updateUndoRedoColl("crop",a,a.objColl,a.pointColl,o)}}return t},l.prototype.flip=function(t){if(!this.disabled&&this.isImageLoaded){var i={direction:t};this.trigger("flipping",i);var s=e.extend({},this.cropObj,{},!0),o=void 0;e.isNullOrUndefined(this.transformCurrentObj)&&((o=this.getCurrentObj()).objColl=e.extend([],this.objColl,null,!0),o.pointColl=e.extend({},this.pointColl,null,!0),o.afterCropActions=e.extend([],this.afterCropActions,[],!0)),this.afterCropActions.push("horizontal"===t.toLowerCase()?"horizontalflip":"verticalflip");var a=[],n=void 0;e.isNullOrUndefined(this.activeObj.activePoint)||(void 0!==this.activeObj.shape&&(a=this.activeObj.shape.split("-")),(this.currObjType.isCustomCrop||"crop"===a[0])&&(n=this.currObjType.isCustomCrop?"custom":a[1],this.updateImageRatioForActObj(),this.objColl.push(this.activeObj),this.refreshActiveObj())),this.redrawActObj(),this.lowerContext.clearRect(0,0,this.lowerCanvas.height,this.lowerCanvas.width),this.lowerContext.clearRect(0,0,this.lowerCanvas.width,this.lowerCanvas.height),this.upperContext.clearRect(0,0,this.lowerCanvas.height,this.lowerCanvas.width),this.upperContext.clearRect(0,0,this.lowerCanvas.width,this.lowerCanvas.height);var r=e.extend([],this.objColl,[],!0),h=e.extend({},this.activeObj,{},!0);this.objColl=[],this.refreshActiveObj(),this.isReverseFlip||this.updateCurrentTransformedState("initial"),"horizontal"===t.toLowerCase()?(this.updateFlipState(t.toLowerCase()),"horizontal"===this.currFlipState.toLowerCase()?this.currFlipState="":this.currFlipState="horizontal"):(this.updateFlipState(t.toLowerCase()),"vertical"===this.currFlipState.toLowerCase()?this.currFlipState="":this.currFlipState="vertical"),this.rotatedFlipCropSelection&&(this.destLeft+=this.totalPannedInternalPoint.x,this.destTop+=this.totalPannedInternalPoint.y);var l=this.lowerContext.filter;this.updateBrightnessFilter(),this.lowerContext.drawImage(this.baseImg,this.srcLeft,this.srcTop,this.srcWidth,this.srcHeight,this.destLeft,this.destTop,this.destWidth,this.destHeight),this.lowerContext.filter=l,this.updateFlipState(t.toLowerCase()),this.isReverseFlip||(this.updateCurrentTransformedState("reverse"),this.updateFlipColl(t.toLocaleLowerCase()),this.rotateFlipColl.push(t.toLowerCase())),1===this.rotateFlipColl.length&&(""===this.getCurrentPanRegion()?this.setClientTransformedDimension():this.setDestPointsForFlipState()),this.isCircleCrop&&this.cropCircle(this.lowerContext),this.objColl=e.extend([],r,[],!0),this.activeObj=e.extend({},h,{},!0);for(var c=0,d=this.objColl.length;c<d;c++)0===this.objColl[c].flipObjColl.length?this.objColl[c].flipObjColl.push(t):this.objColl[c].flipObjColl[this.objColl[c].flipObjColl.length-1]===t?this.objColl[c].flipObjColl.pop():this.objColl[c].flipObjColl.push(t);this.redrawObj(t.toLowerCase());var p=this.lowerContext.filter;this.lowerContext.filter=this.getDefaultFilter(),this.iterateObjColl(),e.isNullOrUndefined(this.currSelectionPoint)||(r=e.extend([],this.objColl,[],!0),this.objColl=[],this.objColl.push(this.currSelectionPoint),this.redrawObj(t.toLowerCase()),this.currSelectionPoint=e.extend({},this.objColl[0],{},!0),this.objColl=r),"horizontal"===t.toLowerCase()||"vertical"===t.toLowerCase()?(this.flipFreehandrawColl(t.toLowerCase()),this.freehandRedraw(this.lowerContext)):this.freehandRedraw(this.lowerContext),this.lowerContext.filter=p,this.refreshActiveObj(),this.updateCurrSelectionPoint(t.toLowerCase()),!this.isUndoRedo&&e.isNullOrUndefined(this.transformCurrentObj)&&this.updateUndoRedoColl("flip",o,o.objColl,o.pointColl,s),this.isUndoRedo=!1,this.clearOuterCanvas(this.lowerContext),this.clearOuterCanvas(this.upperContext),e.isNullOrUndefined(n)||(this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),this.activeObj=e.extend({},this.objColl[this.objColl.length-1],{},!0),this.objColl.pop(),this.drawObject("duplicate",this.activeObj),this.isReverseFlip||this.refreshToolbar("main",!0,!0)),e.isNullOrUndefined(this.activeObj.shape)&&!this.isReverseFlip?this.refreshToolbar("main"):this.isReverseFlip||this.refreshToolbar("main",!0,!0),this.rotateFlipColl=this.alignRotateFlipColl(this.rotateFlipColl,!0)}},l.prototype.getImageData=function(){return this.lowerContext.getImageData(this.destLeft,this.destTop,this.destWidth,this.destHeight)},l.prototype.open=function(t){if(!this.disabled){a.showSpinner(this.element),this.element.style.opacity="0.5";var i=document.querySelector("#"+this.element.id+"_currPos");if(i&&(i.style.display="none"),0===this.defToolbarItems.length&&e.isNullOrUndefined(document.getElementById(this.element.id+"_toolbar"))&&(this.toolbarHeight=0),e.isNullOrUndefined(this.toolbarTemplate)&&(this.reset(),this.update()),this.degree=0,this.zoomFactor=0,this.isImageLoaded=!1,this.currSelectionPoint=null,"string"===typeof t){var s=t.split(".");s.length>1?(s=s[s.length-2].split("/"),this.fileName=s[s.length-1]):this.fileName="ImageEditor",this.imageOnLoad(t)}else this.fileName="ImageEditor",this.lowerCanvas=document.querySelector("#"+this.element.id+"_lowerCanvas"),this.upperCanvas=document.querySelector("#"+this.element.id+"_upperCanvas"),this.lowerContext=this.lowerCanvas.getContext("2d"),this.upperContext=this.upperCanvas.getContext("2d"),this.lowerContext.clearRect(0,0,this.lowerCanvas.width,this.lowerCanvas.height),this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),this.inMemoryContext.clearRect(0,0,this.inMemoryCanvas.width,this.inMemoryCanvas.height),this.inMemoryCanvas.width=this.baseImg.width=t.width,this.inMemoryCanvas.height=this.baseImg.height=t.height,this.inMemoryContext.putImageData(t,0,0),this.baseImg.src=this.inMemoryCanvas.toDataURL()}},l.prototype.reset=function(){this.disabled||(this.inMemoryContext.clearRect(0,0,this.lowerCanvas.width,this.lowerCanvas.height),this.inMemoryContext.clearRect(0,0,this.lowerCanvas.height,this.lowerCanvas.width),this.lowerContext.clearRect(0,0,this.lowerCanvas.width,this.lowerCanvas.height),this.lowerContext.clearRect(0,0,this.lowerCanvas.height,this.lowerCanvas.width),this.upperContext.clearRect(0,0,this.lowerCanvas.width,this.lowerCanvas.height),this.upperContext.clearRect(0,0,this.lowerCanvas.height,this.lowerCanvas.width),this.lowerContext.filter=this.getDefaultFilter(),this.refreshActiveObj(),this.refreshToolbar("main"),e.Browser.isDevice&&document.getElementById(this.element.id+"_bottomToolbar")&&(e.getComponent(document.getElementById(this.element.id+"_bottomToolbar"),"toolbar").destroy(),this.createBottomToolbar()),this.objColl=[],this.isImageLoaded=!1,this.degree=this.undoRedoStep=0,this.keyHistory=this.currFlipState="",this.upperCanvas.style.display="none",this.togglePan=this.togglePen=!1,this.upperCanvas.style.cursor=this.lowerCanvas.style.cursor="default",this.undoRedoColl=[],this.dragCanvas=this.isUndoRedo=!1,this.tempKeyHistory="",this.lowerContext.lineWidth=this.upperContext.lineWidth=void 0,this.touchEndPoint={},this.currentToolbar="main",this.textStartPoints={x:0,y:0},this.fontSizeColl=[],this.textArea.value=this.textArea.textContent="",this.textArea.style.display="none",this.strokeSettings={strokeColor:"#fff",fillColor:"",strokeWidth:null},this.textSettings={text:"Enter Text",fontFamily:"Arial",fontSize:null,fontRatio:null,bold:!1,italic:!1,underline:!1},this.tempStrokeSettings={strokeColor:"#fff",fillColor:"",strokeWidth:null},this.tempTextSettings={text:"Enter Text",fontFamily:"Arial",fontSize:null,fontRatio:null,bold:!1,italic:!1,underline:!1},this.timer=void 0,this.penStrokeWidth=void 0,this.currObjType.isUndoAction=!1,this.undoRedoStep=0,this.tempObjColl=void 0,this.adjustmentLevel={brightness:0,contrast:0,hue:0,opacity:100,saturation:0,blur:0,exposure:0,sharpen:!1,bw:!1},this.tempAdjustmentLevel={brightness:0,contrast:0,hue:0,opacity:100,saturation:0,blur:0,exposure:0,sharpen:!1,bw:!1},this.canvasFilter=this.currentFilter=this.tempAdjustmentValue="",this.lowerContext.filter=this.initialAdjustmentValue=this.adjustmentValue=this.getDefaultFilter(),this.destLeft=this.destTop=this.srcLeft=this.srcTop=0,this.destWidth=this.destHeight=this.srcWidth=this.srcHeight=null,this.currSelectionPoint=null,this.cropDestPoints={startX:0,startY:0,width:0,height:0},this.panDown=null,this.panMove=null,this.tempPanMove=null,this.flipColl=[],this.freehandDrawObj.time=this.freehandDrawObj.lastVelocity=0,this.freehandDrawObj.pointX=this.freehandDrawObj.pointY=0,this.points=[],this.pointColl={},this.pointCounter=this.freehandCounter=this.tempFreehandCounter=this.tempCurrentFreehandDrawIndex=0,this.isFreehandDrawing=!1,this.isReverseRotate=this.isReverseFlip=this.isPreventDragging=this.isRotateZoom=!1,this.currentPannedPoint=null,this.fileType=void 0,this.rotateFlipColl=[],this.isCircleCrop=!1,this.isCropTab=!1,this.rotatedDestPoints={startX:0,startY:0,width:0,height:0},this.croppedDegree=0,this.freehandDrawHoveredIndex=this.freehandDrawSelectedIndex=null,this.isFreehandDrawingPoint=this.isFreehandDrawEditing=!1,this.tempFreeHandDrawEditingStyles={strokeColor:null,fillColor:null,strokeWidth:null},this.totalPannedInternalPoint={x:0,y:0},this.totalPannedClientPoint={x:0,y:0},this.lowerCanvas.style.left=this.upperCanvas.style.left="",this.lowerCanvas.style.top=this.upperCanvas.style.top="",this.lowerCanvas.style.maxWidth=this.upperCanvas.style.maxWidth="",this.lowerCanvas.style.maxHeight=this.upperCanvas.style.maxHeight="",this.currentSelectionPoint=null,this.totalPannedPoint={x:0,y:0},this.fileName="",this.isBrightnessAdjusted=this.isInitialLoading=!1,this.defaultZoomFactor=this.cropZoomFactor=this.zoomFactor=0,this.tempActObj=null,this.lastPan={x:0,y:0},this.selectedFreehandColor="#42a5f5",this.isFreehandDrawCustomized=!1,this.isShapeInserted=!1,this.isAllowCropPan=!1,this.tempPannedPoint={x:0,y:0},this.currObjType={shape:"",isDragging:!1,isActiveObj:!1,isText:!1,isInitialText:!1,isLine:!1,isInitialLine:!1,isCustomCrop:!1,isZoomed:!1,isUndoZoom:!1,isUndoAction:!1,isFiltered:!1,isSave:!1},this.cropObj={cropZoom:0,defaultZoom:0,totalPannedPoint:{x:0,y:0},totalPannedClientPoint:{x:0,y:0},totalPannedInternalPoint:{x:0,y:0},tempFlipPanPoint:{x:0,y:0},activeObj:{},rotateFlipColl:[],degree:0,currFlipState:"",destPoints:{startX:0,startY:0,width:0,height:0},srcPoints:{startX:0,startY:0,width:0,height:0},filter:""},this.afterCropActions=[],this.isCancelAction=this.preventZoomBtn=this.isFreehandPointMoved=!1,this.isTouch=!1,this.freehandDownPoint={x:0,y:0},this.tempFlipPanPoint={x:0,y:0},this.currentFreehandDrawIndex=0,this.tempCurrentFreehandDrawIndex=0,this.cancelObjColl=[],this.cancelPointColl=[],this.freehandDrawSelectedId=null,this.transformCurrentObj=null,this.rotatedFlipCropSelection=!1,this.panStartObj=null,this.currDestinationPoint=null,this.updateCanvas(),this.refreshDropDownBtn(!1),this.enableDisableToolbarBtn())},l.prototype.rotate=function(t){var i=!1;if(!this.disabled&&this.isImageLoaded&&t%90==0){i=!0;var s={degree:t};this.trigger("rotating",s);var o=e.extend({},this.cropObj,{},!0),a=void 0;e.isNullOrUndefined(this.transformCurrentObj)&&((a=this.getCurrentObj()).objColl=e.extend([],this.objColl,null,!0),a.pointColl=e.extend({},this.pointColl,null,!0),a.afterCropActions=e.extend([],this.afterCropActions,[],!0)),this.afterCropActions.push(90===t?"rotateRight":"rotateLeft");var n=[],r=void 0;e.isNullOrUndefined(this.activeObj.activePoint)||e.isNullOrUndefined(this.activeObj.shape)||(void 0!==this.activeObj.shape&&(n=this.activeObj.shape.split("-")),(this.currObjType.isCustomCrop||"crop"===n[0])&&(r=this.currObjType.isCustomCrop?"custom":n[1],this.updateImageRatioForActObj(),this.objColl.push(this.activeObj),this.refreshActiveObj())),this.redrawActObj(),this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),this.drawRotatedImage(t),this.clearOuterCanvas(this.lowerContext),this.clearOuterCanvas(this.upperContext),e.isNullOrUndefined(r)||(this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),this.activeObj=e.extend({},this.objColl[this.objColl.length-1],{},!0),this.objColl.pop(),this.drawObject("duplicate",this.activeObj),this.isReverseRotate||this.refreshToolbar("main",!0,!0)),!this.isUndoRedo&&e.isNullOrUndefined(this.transformCurrentObj)&&this.updateUndoRedoColl("rotate",a,a.objColl,a.pointColl,o),this.isUndoRedo=!1,e.isNullOrUndefined(this.activeObj.shape)&&!this.isReverseRotate?this.refreshToolbar("main"):this.isReverseRotate||this.refreshToolbar("main",!0,!0),this.rotateFlipColl=this.alignRotateFlipColl(this.rotateFlipColl,!0)}return i},l.prototype.export=function(t,e){var i=this;if(!this.disabled&&this.isImageLoaded){this.isFreehandDrawEditing&&this.applyFreehandDraw(),this.togglePen&&(this.currObjType.isZoomed=!0,this.apply()),"block"===this.textArea.style.display&&this.redrawActObj(),this.applyActObj(),this.lowerContext.filter=this.canvasFilter,t=t||"Png",this.redrawActObj();var s={cancel:!1,fileName:e||this.fileName,fileType:t},o={fileName:e||this.fileName,fileType:t};this.trigger("beforeSave",s,function(s){s.cancel||(i.currObjType.isSave=!0,e=s.fileName?s.fileName:e,"svg"===t.toLowerCase()?(e=e||i.fileName,i.toSVGImg(e)):(t.toLowerCase(),e=e||i.fileName,i.toBlobFn(e,t.toLowerCase())),i.trigger("saved",o),i.refreshToolbar("main"),i.lowerCanvas.style.left=i.upperCanvas.style.left="",i.lowerCanvas.style.top=i.upperCanvas.style.top="",i.lowerCanvas.style.maxWidth=i.upperCanvas.style.maxWidth="",i.lowerCanvas.style.maxHeight=i.upperCanvas.style.maxHeight="")})}},l.prototype.select=function(t,i,s,o,a){if(!this.disabled&&this.isImageLoaded){this.zoomFactor>0&&!e.isNullOrUndefined(this.activeObj.shape)&&"crop"===this.activeObj.shape.split("-")[0]&&e.isNullOrUndefined(this.currentSelectionPoint)&&(this.currentSelectionPoint=e.extend({},this.activeObj,{},!0));var n=!1,r=void 0;void 0!==this.activeObj.shape&&(r=this.activeObj.shape.split("-")),void 0===r&&this.currObjType.isCustomCrop?n=!0:void 0!==r&&"crop"===r[0]&&(n=!0);var h=e.extend({},this.cropObj,{},!0),l=this.getCurrentObj();if(l.objColl=e.extend([],this.objColl,[],!0),l.pointColl=e.extend([],this.pointColl,[],!0),l.afterCropActions=e.extend([],this.afterCropActions,[],!0),this.redrawActObj(),this.refreshActiveObj(),this.keyHistory="",this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),this.upperCanvas.style.display="block",!e.isNullOrUndefined(this.currSelectionPoint)||this.defaultZoomFactor>0||0!==this.degree&&0!==this.totalPannedInternalPoint.x&&0!==this.totalPannedInternalPoint.y&&!n){if(this.isCircleCrop=!1,this.defaultZoomFactor>0){var c=this.zoomFactor=this.defaultZoomFactor;this.isCropTab=!1;for(var d=this.isUndoRedo,p=0;p<10*c;p++)this.isUndoRedo=!0,this.zoom(-.1);this.isUndoRedo=d,this.resetPanPoints()}this.cancelObjColl=e.extend([],this.objColl,[],!0),this.cancelPointColl=e.extend([],this.pointColl,[],!0),this.updateObjAndFreeHandDrawColl(),this.isCropTab=!0,this.setCurrSelectionPoints(!0),this.zoomFactor=this.cropZoomFactor,e.isNullOrUndefined(this.cropObj.activeObj.shape)?this.drawNewSelection(t,i,s,o,a):this.updateUndoRedoColl("crop-selection",l,l.objColl,l.pointColl,h)}else"custom"===t&&(this.currObjType.shape=""),this.drawNewSelection(t,i,s,o,a)}},l.prototype.freeHandDraw=function(t){t?(this.points=[],this.refreshActiveObj(),this.togglePen=!0,this.upperCanvas.style.cursor="crosshair",this.upperCanvas.style.display="block",e.isNullOrUndefined(this.activeObj.strokeSettings)&&(this.activeObj.strokeSettings=this.strokeSettings),e.isNullOrUndefined(this.activeObj.strokeSettings.strokeWidth)&&(this.activeObj.strokeSettings.strokeWidth=4),this.refreshToolbar("pen")):(this.upperCanvas.style.cursor="default",this.apply(),this.refreshToolbar("main"),this.currentToolbar="main",this.isFreehandDrawCustomized=!1)},l.prototype.freehandDraw=function(t){!this.disabled&&this.isImageLoaded&&this.freeHandDraw(t)},l.prototype.pan=function(t){!this.disabled&&this.isImageLoaded&&(t?(this.togglePan=!0,this.redrawActObj(),this.dragCanvas=!0,this.lowerCanvas.style.cursor=this.upperCanvas.style.cursor="grab",this.panDown=null):(this.dragCanvas=this.togglePan=this.currObjType.isCustomCrop=!1,this.lowerCanvas.style.cursor=this.upperCanvas.style.cursor="default"))},l.prototype.zoom=function(t){if(!this.disabled&&this.isImageLoaded){if(0===this.zoomFactor&&t<0||this.zoomFactor>2&&t>0||this.zoomFactor>0&&t<0&&this.disableZoomOutBtn())return;var i=void 0,s=void 0,o=!1;void 0!==this.activeObj.shape&&(i=this.activeObj.shape.split("-")),void 0!==i&&"crop"===i[0]?(s=e.extend({},this.activeObj,{},!0),this.isCropTab=!0):e.isNullOrUndefined(this.activeObj.shape)||"crop"===i[0]||(o=!0);var a=void 0,n=void 0;this.isCropTab&&!e.isNullOrUndefined(s)?(n=this.cropZoomFactor,a={x:this.activeObj.activePoint.startX+this.activeObj.activePoint.width/2,y:this.activeObj.activePoint.startY+this.activeObj.activePoint.height/2}):(n=this.defaultZoomFactor,a={x:this.lowerCanvas.clientWidth/2,y:this.lowerCanvas.clientHeight/2});var r={zoomPoint:a,zoomLevel:n};this.trigger("zooming",r);var h=e.extend({},this.cropObj,{},!0),l=this.getCurrentObj();l.objColl=e.extend([],this.objColl,[],!0),l.pointColl=e.extend([],this.pointColl,[],!0),l.afterCropActions=e.extend([],this.afterCropActions,[],!0),this.redrawActObj(),this.refreshActiveObj(),this.upperContext.clearRect(0,0,this.lowerCanvas.width,this.lowerCanvas.height),this.lowerContext.filter=this.canvasFilter,this.upperCanvas.style.cursor="default";var c=e.extend([],this.objColl,[],!0);if(this.isCropTab||(0!==this.degree&&(this.redrawActObj(),this.currentPannedPoint={x:0,y:0},this.rotatePan(!0,!0)),this.updateObjAndFreeHandDrawColl()),0===this.degree){if(this.drawZoomImgToCanvas(t,s),""!==this.getCurrentPanRegion()){this.tempFlipPanPoint.x+=this.totalPannedPoint.x,this.tempFlipPanPoint.y+=this.totalPannedPoint.y,c=e.extend([],this.objColl,[],!0),this.objColl=[];var d=this.destLeft,p=this.destTop;this.setDestPointsForFlipState(),this.rotatedFlip(),this.destLeft=d,this.destTop=p,this.objColl=c,this.zoomObjColl(),this.zoomFreehandDrawColl(),this.updateObjAndFreeHandDrawColl()}0!==this.zoomFactor||this.isCropTab||(this.totalPannedPoint={x:0,y:0})}else if(this.updateObjAndFreeHandDrawColl(),this.totalPannedClientPoint={x:0,y:0},this.totalPannedInternalPoint={x:0,y:0},this.rotateZoom(t),""!==this.getCurrentPanRegion()){v=this.lowerContext.filter;this.lowerContext.filter="none",this.zoomObjColl(),this.zoomFreehandDrawColl(),this.lowerContext.filter=v}if(""===this.getCurrentPanRegion()){var v=this.lowerContext.filter;this.lowerContext.filter="none",this.zoomObjColl(),this.zoomFreehandDrawColl(),this.lowerContext.filter=v}(!e.isNullOrUndefined(this.currSelectionPoint)&&"crop-circle"===this.currSelectionPoint.shape||this.isCircleCrop)&&this.cropCircle(this.lowerContext),this.clearOuterCanvas(this.lowerContext),this.refreshActiveObj(),e.isNullOrUndefined(s)||(this.activeObj=e.extend({},s,{},!0),this.drawObject("duplicate",this.activeObj),0===this.zoomFactor&&(this.currSelectionPoint=null)),this.isUndoRedo||this.updateUndoRedoColl("zoom",l,l.objColl,l.pointColl,h),this.isUndoRedo=!1;var b=document.querySelector("#"+this.element.id+"_zoomOut");e.isNullOrUndefined(b)||0!==this.zoomFactor?e.isNullOrUndefined(b)||(b.classList.remove("e-disabled"),b.parentElement.classList.remove("e-overlay")):(b.classList.add("e-disabled"),b.parentElement.classList.add("e-overlay")),this.autoEnablePan(),e.isNullOrUndefined(s)||(this.activeObj=e.extend({},s,{},!0)),"crop-custom"===this.activeObj.shape&&(this.currObjType.isCustomCrop=!0);var u=this.element.querySelector(".e-img-pan .e-btn");!e.isNullOrUndefined(u)&&this.togglePan?u.classList.add("e-selected-btn"):e.isNullOrUndefined(u)||u.classList.remove("e-selected-btn"),o&&(this.activeObj=e.extend({},this.objColl[this.objColl.length-1],{},!0),this.objColl.pop(),this.drawObject("duplicate",this.activeObj),this.updateToolbarItems())}},l.prototype.drawEllipse=function(t,e,i,s,o,a,n){var r=!1,h=this.isPointsInRange(t,e);if(!this.disabled&&this.isImageLoaded&&h){r=!0,this.redrawActObj(),this.activeObj.shape="ellipse","freehanddraw"===this.currObjType.shape&&(this.apply(),this.upperCanvas.style.cursor="default",this.currObjType.shape=""),this.currObjType.isCustomCrop=!1;var l={x:t,y:e};this.drawShape("ellipse",o,a,n,l,i,s)}return r},l.prototype.drawLine=function(t,e,i,s,o,a){var n=!1,r=this.isPointsInRange(t,e);if(!this.disabled&&this.isImageLoaded&&r){n=!0,this.redrawActObj(),this.activeObj.shape="line","freehanddraw"===this.currObjType.shape&&(this.apply(),this.upperCanvas.style.cursor="default",this.currObjType.shape=""),this.currObjType.isCustomCrop=!1;var h={x:t,y:e},l=i-t,c=s-e;this.drawShape("line",o,a,null,h,l,c)}return n},l.prototype.drawRectangle=function(t,e,i,s,o,a,n){var r=!1,h=this.isPointsInRange(t,e);if(!this.disabled&&this.isImageLoaded&&h){r=!0,this.redrawActObj(),this.activeObj.shape="rectangle","freehanddraw"===this.currObjType.shape&&(this.apply(),this.upperCanvas.style.cursor="default",this.currObjType.shape=""),this.currObjType.isCustomCrop=!1;var l={x:t,y:e};this.drawShape("rectangle",o,a,n,l,i,s)}return r},l.prototype.drawText=function(t,e,i,s,o,a,n,r){var h=!1,l=this.isPointsInRange(t,e);return!this.disabled&&this.isImageLoaded&&l&&(h=!0,this.drawShapeText(i,s,o,a,n,r,t,e)),h},l.prototype.selectShape=function(t){var i=!1;if(!this.disabled&&this.isImageLoaded)if(this.applyActObj(),"shape"===t.split("_")[0]){for(var s=void 0,o=0;o<this.objColl.length;o++)if(this.objColl[o].currIndex===t){s=e.extend({},this.objColl[o],{},!0);break}e.isNullOrUndefined(s)?i=!1:(i=!0,this.activeObj=s,this.lowerContext.filter=this.canvasFilter,this.redrawShape(this.activeObj),"text"===this.activeObj.shape?this.refreshToolbar("text"):"pen"===this.activeObj.shape?this.refreshToolbar("pen"):this.refreshToolbar("shapes"),this.updateToolbarItems())}else"pen"===t.split("_")[0]&&(this.isFreehandDrawEditing&&this.okBtn(),this.isFreehandDrawIndex(parseInt(t.split("_")[1],10)-1)?(i=!0,this.selectFreehandDraw(parseInt(t.split("_")[1],10)-1),this.updateToolbarItems()):i=!1);return i},l.prototype.deleteShape=function(t){if(!this.disabled&&this.isImageLoaded){if(this.applyActObj(),"shape"===t.split("_")[0]){for(var e=0;e<this.objColl.length;e++)if(this.objColl[e].currIndex===t){this.objColl.splice(e,1);break}}else"pen"===t.split("_")[0]&&this.isFreehandDrawIndex(parseInt(t.split("_")[1],10)-1)&&this.deleteFreehandDraw(parseInt(t.split("_")[1],10)-1,!0);this.lowerContext.filter=this.canvasFilter,this.lowerContext.clearRect(0,0,this.lowerCanvas.width,this.lowerCanvas.height),this.redrawImgWithObj(),this.refreshToolbar("main")}},l.prototype.getShapeSetting=function(t){var i;if(!this.disabled&&this.isImageLoaded)if(this.applyActObj(),"shape"===t.split("_")[0]){for(var s=void 0,o=0;o<this.objColl.length;o++)if(this.objColl[o].currIndex===t){s=e.extend({},this.objColl[o],{},!0);break}i=this.getObjDetails(s)}else"pen"===t.split("_")[0]&&(i=this.getFreehandDrawDetails(parseInt(t.split("_")[1],10)-1));return i},l.prototype.getShapeSettings=function(){var t=[];if(!this.disabled&&this.isImageLoaded){this.applyActObj();for(e=0;e<this.objColl.length;e++){i=this.getObjDetails(this.objColl[e]);t.push(i)}for(var e=0;e<this.freehandCounter;e++){var i=this.getFreehandDrawDetails(e);t.push(i)}}return t},l.prototype.update=function(){var t=document.querySelector("#"+this.element.id+"_canvasWrapper");e.isNullOrUndefined(t)||(t.style.width=this.element.offsetWidth-2+"px"),this.lowerCanvas.width=this.upperCanvas.width=this.element.offsetWidth-2,e.Browser.isDevice?(e.isNullOrUndefined(t)||(t.style.height=this.element.offsetHeight-2*this.toolbarHeight-5+"px"),this.lowerCanvas.height=this.upperCanvas.height=this.element.offsetHeight-2*this.toolbarHeight-5):(e.isNullOrUndefined(t)||(t.style.height=this.element.offsetHeight-this.toolbarHeight-3+"px"),this.lowerCanvas.height=this.upperCanvas.height=this.element.offsetHeight-this.toolbarHeight-3),this.lowerContext.filter=this.canvasFilter=this.initialAdjustmentValue=this.adjustmentValue=this.getDefaultFilter(),this.lowerContext.clearRect(0,0,this.lowerCanvas.width,this.lowerCanvas.height),this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height)},l.prototype.finetuneImage=function(t,e){if(!this.disabled&&this.isImageLoaded){switch(t.toLowerCase()){case"brightness":this.setBrightness(e);break;case"contrast":this.setContrast(e);break;case"hue":this.setHue(e);break;case"saturation":this.setSaturation(e);break;case"opacity":this.setOpacity(e);break;case"blur":this.setBlur(e);break;case"exposure":this.setExposure(e)}this.canvasFilter=this.lowerContext.filter}},l.prototype.applyImageFilter=function(t){!this.disabled&&this.isImageLoaded&&(this.setFilter(t.toString()),this.canvasFilter=this.lowerContext.filter)},l.prototype.undo=function(){if(!this.disabled&&this.isImageLoaded&&this.undoRedoStep>0){e.isNullOrUndefined(this.activeObj.shape)?this.refreshToolbar("main"):this.refreshToolbar("shapes"),e.isNullOrUndefined(this.activeObj.activePoint)||0===this.activeObj.activePoint.width||(this.tempActObj=this.activeObj),this.refreshActiveObj(),this.undoRedoStep--,this.enableDisableToolbarBtn(),this.isUndoRedo=!0;var t=this.undoRedoColl[this.undoRedoStep];this.undoRedoColl.length===this.undoRedoStep?this.currObjType.isUndoAction=!1:this.currObjType.isUndoAction=!0,"textAreaCustomization"!==t.operation&&"block"===this.textArea.style.display&&(this.textArea.style.display="none"),this.element.querySelector(".e-contextual-toolbar-wrapper").classList.add("e-hide"),this.isCancelAction=!0;var i=void 0;switch(this.cropObj=e.extend({},t.previousCropObj,{},!0),this.afterCropActions=t.previousObj.afterCropActions,this.lowerContext.filter=this.canvasFilter=t.previousObj.filter,t.operation){case"shapeTransform":this.objColl=e.extend([],t.previousObjColl,[],!0),this.lowerContext.clearRect(0,0,this.lowerCanvas.width,this.lowerCanvas.height),this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),this.isUndoRedo=!0,this.redrawImgWithObj(),this.refreshActiveObj();break;case"freehanddraw":this.pointColl=t.previousPointColl,this.freehandCounter=this.pointColl.length,this.lowerContext.clearRect(0,0,this.lowerCanvas.width,this.lowerCanvas.height),this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),this.isUndoRedo=!0,this.redrawImgWithObj();break;case"freehanddrawCustomized":this.pointColl=t.previousPointColl,this.lowerContext.clearRect(0,0,this.lowerCanvas.width,this.lowerCanvas.height),this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),this.isUndoRedo=!0,this.redrawImgWithObj();break;case"deleteFreehandDrawing":case"deleteObj":"deleteFreehandDrawing"===t.operation?(this.pointColl=t.previousPointColl,this.freehandCounter=this.pointColl.length):"deleteObj"===t.operation&&(this.objColl=t.previousObjColl),this.lowerContext.clearRect(0,0,this.lowerCanvas.width,this.lowerCanvas.height),this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),this.isUndoRedo=!0,this.redrawImgWithObj();break;case"selectionTransform":this.activeObj=e.extend({},t.previousObj.activeObj,{},!0),this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),0!==this.activeObj.activePoint.width&&0!==this.activeObj.activePoint.height?(this.drawObject("duplicate",this.activeObj),this.refreshToolbar("main",!0,!0)):(this.refreshToolbar("main"),this.performUndoDefaultAction(t)),this.currObjType.isCustomCrop=!1;break;case"textAreaCustomization":this.objColl=e.extend([],t.previousObjColl,[],!0);for(s=0;s<t.previousObjColl.length;s++){if(e.isNullOrUndefined(this.tempActObj)){i=e.extend({},t.previousObjColl[t.previousObjColl.length-1],{},!0),this.objColl.splice(s,1);break}if(this.tempActObj.currIndex===t.previousObjColl[s].currIndex){i=e.extend({},t.previousObjColl[s],{},!0),this.objColl.splice(s,1);break}}e.isNullOrUndefined(i)||this.updateTextBox(i);break;case"text":if(e.isNullOrUndefined(this.tempActObj)||(this.activeObj=e.extend({},this.tempActObj,{},!0)),0===t.previousObjColl.length&&1===this.objColl.length)this.tempActObj=e.extend({},this.objColl[0],{},!0);else for(var s=0;s<this.objColl.length;s++){if(!e.isNullOrUndefined(this.objColl[s])&&e.isNullOrUndefined(t.previousObjColl[s])){this.tempActObj=e.extend({},this.objColl[s],{},!0);break}if(t.previousObjColl[s].currIndex!==this.objColl[s].currIndex){this.tempActObj=e.extend({},this.objColl[s],{},!0);break}}this.activeObj=e.extend({},this.tempActObj,{},!0),this.objColl=e.extend([],t.previousObjColl,[],!0),this.lowerContext.clearRect(0,0,this.lowerCanvas.width,this.lowerCanvas.height),this.isUndoRedo=!0,this.redrawImgWithObj(),e.isNullOrUndefined(this.activeObj)||0===this.activeObj.activePoint.width||0===this.activeObj.activePoint.height?(this.textArea.style.display="block",this.textArea.value=t.previousText):this.drawObject("duplicate");break;default:this.performUndoDefaultAction(t),this.setAdjustment(t.operation),this.updateFilter(t.operation,t.filter)}this.clearOuterCanvas(this.lowerContext),this.isCircleCrop&&"crop"!==t.operation&&this.cropCircle(this.lowerContext),this.zoomFactor>0&&(this.dragCanvas=!0),this.isCancelAction=!1,e.isNullOrUndefined(this.activeObj.shape)||"crop"!==this.activeObj.shape.split("-")[0]?this.refreshToolbar("main"):this.refreshToolbar("main",!0,!0)}},l.prototype.redo=function(){if(!this.disabled&&this.isImageLoaded&&this.undoRedoStep<this.undoRedoColl.length){e.isNullOrUndefined(this.activeObj.shape)?this.refreshToolbar("main"):this.refreshToolbar("shapes"),this.undoRedoStep++,this.enableDisableToolbarBtn(),this.isUndoRedo=!0;var t=this.undoRedoColl[this.undoRedoStep-1];this.undoRedoColl.length===this.undoRedoStep?this.currObjType.isUndoAction=!1:this.currObjType.isUndoAction=!0,"textAreaCustomization"!==t.operation&&"block"===this.textArea.style.display&&(this.textArea.style.display="none"),this.element.querySelector(".e-contextual-toolbar-wrapper").classList.add("e-hide"),this.isCancelAction=!0,this.cropObj=e.extend({},t.currentCropObj,{},!0),this.afterCropActions=t.currentObj.afterCropActions,this.lowerContext.filter=this.canvasFilter=t.currentObj.filter;var i=void 0,s=void 0,o=void 0;switch(t.operation){case"shapeTransform":this.objColl=e.extend([],t.currentObjColl,[],!0),this.lowerContext.clearRect(0,0,this.lowerCanvas.width,this.lowerCanvas.height),this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),this.isUndoRedo=!0,this.redrawImgWithObj(),this.refreshActiveObj();break;case"freehanddraw":this.pointColl=t.currentPointColl,this.freehandCounter=this.pointColl.length,this.lowerContext.clearRect(0,0,this.lowerCanvas.width,this.lowerCanvas.height),this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),this.isUndoRedo=!0,this.redrawImgWithObj();break;case"freehanddrawCustomized":this.pointColl=t.currentPointColl,this.lowerContext.clearRect(0,0,this.lowerCanvas.width,this.lowerCanvas.height),this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),this.isUndoRedo=!0,this.redrawImgWithObj();break;case"deleteFreehandDrawing":case"deleteObj":"deleteFreehandDrawing"===t.operation?(this.pointColl=t.currentPointColl,this.freehandCounter=this.pointColl.length):"deleteObj"===t.operation&&(this.objColl=t.currentObjColl),this.lowerContext.clearRect(0,0,this.lowerCanvas.width,this.lowerCanvas.height),this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),this.isUndoRedo=!0,this.redrawImgWithObj();break;case"selectionTransform":this.activeObj=e.extend({},t.currentObj.activeObj,{},!0),this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),0!==this.activeObj.activePoint.width&&0!==this.activeObj.activePoint.height?(this.drawObject("duplicate",this.activeObj),this.refreshToolbar("main",!0,!0)):this.refreshToolbar("main"),this.currObjType.isCustomCrop=!1;break;case"textAreaCustomization":this.objColl=e.extend([],t.currentObjColl,[],!0);for(a=0;a<t.currentObjColl.length;a++){if(e.isNullOrUndefined(this.tempActObj)){i=e.extend({},t.currentObjColl[t.currentObjColl.length-1],{},!0),this.objColl.splice(a,1);break}if(this.tempActObj.currIndex===t.currentObjColl[a].currIndex){i=e.extend({},t.currentObjColl[a],{},!0),this.objColl.splice(a,1);break}}e.isNullOrUndefined(i)||this.updateTextBox(i);break;case"text":if(e.isNullOrUndefined(this.tempActObj)||(this.activeObj=e.extend({},this.tempActObj,{},!0)),0===t.previousObjColl.length&&1===this.objColl.length)this.tempActObj=e.extend({},this.objColl[0],{},!0);else for(var a=0;a<this.objColl.length;a++){if(!e.isNullOrUndefined(this.objColl[a])&&e.isNullOrUndefined(t.previousObjColl[a])){this.tempActObj=e.extend({},this.objColl[a],{},!0);break}if(t.previousObjColl[a].currIndex!==this.objColl[a].currIndex){this.tempActObj=e.extend({},this.objColl[a],{},!0);break}}this.objColl=e.extend([],t.currentObjColl,[],!0),this.lowerContext.clearRect(0,0,this.lowerCanvas.width,this.lowerCanvas.height),this.isUndoRedo=!0,this.redrawImgWithObj(),e.isNullOrUndefined(this.tempActObj)||(this.activeObj=e.extend({},this.tempActObj,{},!0)),this.textArea.style.display="block",this.textArea.value=t.currentText,s=e.extend([],this.undoRedoColl,[],!0),o=this.undoRedoStep,this.redrawActObj(),this.undoRedoColl=s,this.undoRedoStep=o,this.textArea.style.display="none",this.textArea.value="",this.redrawActObj();break;default:this.objColl=[],this.pointColl=[],this.freehandCounter=0,this.setCurrentObj(t.currentObj),this.destLeft=t.currentObj.destPoints.startX,this.destTop=t.currentObj.destPoints.startY,i=e.extend({},this.activeObj,{},!0),this.objColl=e.extend([],t.currentObjColl,[],!0),this.pointColl=e.extend([],t.currentPointColl,[],!0),this.freehandCounter=this.pointColl.length,this.lowerContext.filter="none",this.iterateObjColl(),this.freehandRedraw(this.lowerContext),this.lowerContext.filter=t.currentObj.filter,this.activeObj=i,this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),0!==this.activeObj.activePoint.width&&0!==this.activeObj.activePoint.height&&this.drawObject("duplicate"),this.setAdjustment(t.operation),this.updateFilter(t.operation)}this.clearOuterCanvas(this.lowerContext),this.isCircleCrop&&this.cropCircle(this.lowerContext),this.zoomFactor>0&&(this.dragCanvas=!0),this.isCancelAction=!1,this.undoRedoStep===this.undoRedoColl.length&&(this.isUndoRedo=!1),e.isNullOrUndefined(this.activeObj.shape)||"crop"!==this.activeObj.shape.split("-")[0]?this.refreshToolbar("main"):this.refreshToolbar("main",!0,!0)}};var c;return r([e.Property("")],l.prototype,"cssClass",void 0),r([e.Property(!1)],l.prototype,"disabled",void 0),r([e.Property("100%")],l.prototype,"height",void 0),r([e.Property("Bootstrap5")],l.prototype,"theme",void 0),r([e.Property()],l.prototype,"toolbar",void 0),r([e.Property()],l.prototype,"toolbarTemplate",void 0),r([e.Property("100%")],l.prototype,"width",void 0),r([e.Property(!1)],l.prototype,"allowUndoRedo",void 0),r([e.Property(!1)],l.prototype,"isReadOnly",void 0),r([e.Property(!1)],l.prototype,"enableRtl",void 0),r([e.Property(!1)],l.prototype,"enablePersistence",void 0),r([e.Complex({},h)],l.prototype,"finetuneSettings",void 0),r([e.Event()],l.prototype,"beforeSave",void 0),r([e.Event()],l.prototype,"created",void 0),r([e.Event()],l.prototype,"destroyed",void 0),r([e.Event()],l.prototype,"zooming",void 0),r([e.Event()],l.prototype,"panning",void 0),r([e.Event()],l.prototype,"cropping",void 0),r([e.Event()],l.prototype,"rotating",void 0),r([e.Event()],l.prototype,"flipping",void 0),r([e.Event()],l.prototype,"shapeChanging",void 0),r([e.Event()],l.prototype,"fileOpened",void 0),r([e.Event()],l.prototype,"saved",void 0),r([e.Event()],l.prototype,"toolbarCreated",void 0),r([e.Event()],l.prototype,"toolbarUpdating",void 0),r([e.Event()],l.prototype,"toolbarItemClicked",void 0),r([e.Event()],l.prototype,"imageFiltering",void 0),r([e.Event()],l.prototype,"finetuneValueChanging",void 0),l=c=r([e.NotifyPropertyChanges],l)}(e.Component);return t.FinetuneSettings=h,t.ImageEditor=l,t}({},ej.base,ej.navigations,ej.splitbuttons,ej.inputs,ej.popups),this.ejs=ej;
11
11
  //# sourceMappingURL=ej2-image-editor.min.js.map