@syncfusion/ej2-image-editor 21.2.10 → 22.1.34

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.
Files changed (105) hide show
  1. package/.eslintrc.json +1 -0
  2. package/CHANGELOG.md +6 -38
  3. package/dist/ej2-image-editor.umd.min.js +2 -2
  4. package/dist/ej2-image-editor.umd.min.js.map +1 -1
  5. package/dist/es6/ej2-image-editor.es2015.js +19163 -12410
  6. package/dist/es6/ej2-image-editor.es2015.js.map +1 -1
  7. package/dist/es6/ej2-image-editor.es5.js +19198 -12414
  8. package/dist/es6/ej2-image-editor.es5.js.map +1 -1
  9. package/dist/global/ej2-image-editor.min.js +2 -2
  10. package/dist/global/ej2-image-editor.min.js.map +1 -1
  11. package/dist/global/index.d.ts +1 -1
  12. package/package.json +11 -11
  13. package/src/image-editor/action/crop.d.ts +35 -0
  14. package/src/image-editor/action/crop.js +818 -0
  15. package/src/image-editor/action/draw.d.ts +122 -0
  16. package/src/image-editor/action/draw.js +3253 -0
  17. package/src/image-editor/action/export.d.ts +23 -0
  18. package/src/image-editor/action/export.js +364 -0
  19. package/src/image-editor/action/filter.d.ts +35 -0
  20. package/src/image-editor/action/filter.js +699 -0
  21. package/src/image-editor/action/freehand-draw.d.ts +61 -0
  22. package/src/image-editor/action/freehand-draw.js +1015 -0
  23. package/src/image-editor/action/index.d.ts +9 -0
  24. package/src/image-editor/action/index.js +9 -0
  25. package/src/image-editor/action/selection.d.ts +140 -0
  26. package/src/image-editor/action/selection.js +4689 -0
  27. package/src/image-editor/action/shape.d.ts +93 -0
  28. package/src/image-editor/action/shape.js +2657 -0
  29. package/src/image-editor/action/transform.d.ts +67 -0
  30. package/src/image-editor/action/transform.js +1670 -0
  31. package/src/image-editor/action/undo-redo.d.ts +43 -0
  32. package/src/image-editor/action/undo-redo.js +800 -0
  33. package/src/image-editor/base/enum.d.ts +189 -0
  34. package/src/image-editor/base/enum.js +198 -0
  35. package/src/image-editor/{image-editor-model.d.ts → base/image-editor-model.d.ts} +131 -43
  36. package/src/image-editor/{image-editor.d.ts → base/image-editor.d.ts} +425 -1108
  37. package/src/image-editor/base/image-editor.js +2458 -0
  38. package/src/image-editor/base/index.d.ts +4 -0
  39. package/src/image-editor/base/index.js +2 -0
  40. package/src/image-editor/base/interface.d.ts +1120 -0
  41. package/src/image-editor/base/interface.js +1 -0
  42. package/src/image-editor/index.d.ts +3 -5
  43. package/src/image-editor/index.js +3 -4
  44. package/src/image-editor/renderer/index.d.ts +1 -0
  45. package/src/image-editor/renderer/index.js +1 -0
  46. package/src/image-editor/renderer/toolbar.d.ts +105 -0
  47. package/src/image-editor/renderer/toolbar.js +3019 -0
  48. package/styles/bootstrap-dark.css +69 -3
  49. package/styles/bootstrap.css +69 -3
  50. package/styles/bootstrap4.css +69 -3
  51. package/styles/bootstrap5-dark.css +69 -3
  52. package/styles/bootstrap5.css +69 -3
  53. package/styles/fabric-dark.css +69 -3
  54. package/styles/fabric.css +69 -3
  55. package/styles/fluent-dark.css +69 -3
  56. package/styles/fluent.css +69 -3
  57. package/styles/highcontrast-light.css +69 -3
  58. package/styles/highcontrast.css +69 -7
  59. package/styles/image-editor/_layout.scss +21 -7
  60. package/styles/image-editor/_material3-dark-definition.scss +1 -0
  61. package/styles/image-editor/_material3-definition.scss +11 -0
  62. package/styles/image-editor/_theme.scss +9 -2
  63. package/styles/image-editor/bootstrap-dark.css +69 -3
  64. package/styles/image-editor/bootstrap.css +69 -3
  65. package/styles/image-editor/bootstrap4.css +69 -3
  66. package/styles/image-editor/bootstrap5-dark.css +69 -3
  67. package/styles/image-editor/bootstrap5.css +69 -3
  68. package/styles/image-editor/fabric-dark.css +69 -3
  69. package/styles/image-editor/fabric.css +69 -3
  70. package/styles/image-editor/fluent-dark.css +69 -3
  71. package/styles/image-editor/fluent.css +69 -3
  72. package/styles/image-editor/highcontrast-light.css +69 -3
  73. package/styles/image-editor/highcontrast.css +69 -7
  74. package/styles/image-editor/icons/_bootstrap-dark.scss +132 -0
  75. package/styles/image-editor/icons/_bootstrap.scss +132 -0
  76. package/styles/image-editor/icons/_bootstrap4.scss +132 -0
  77. package/styles/image-editor/icons/_bootstrap5.scss +132 -0
  78. package/styles/image-editor/icons/_fabric-dark.scss +132 -0
  79. package/styles/image-editor/icons/_fabric.scss +132 -0
  80. package/styles/image-editor/icons/_fluent.scss +132 -0
  81. package/styles/image-editor/icons/_fusionnew.scss +132 -0
  82. package/styles/image-editor/icons/_highcontrast-light.scss +132 -0
  83. package/styles/image-editor/icons/_highcontrast.scss +132 -0
  84. package/styles/image-editor/icons/_material-dark.scss +132 -0
  85. package/styles/image-editor/icons/_material.scss +132 -0
  86. package/styles/image-editor/icons/_material3-dark.scss +1 -0
  87. package/styles/image-editor/icons/_material3.scss +133 -1
  88. package/styles/image-editor/icons/_tailwind.scss +132 -0
  89. package/styles/image-editor/material-dark.css +69 -3
  90. package/styles/image-editor/material.css +69 -3
  91. package/styles/image-editor/material3-dark.css +453 -0
  92. package/styles/image-editor/material3-dark.scss +14 -0
  93. package/styles/image-editor/material3.css +509 -0
  94. package/styles/image-editor/material3.scss +14 -0
  95. package/styles/image-editor/tailwind-dark.css +69 -3
  96. package/styles/image-editor/tailwind.css +69 -3
  97. package/styles/material-dark.css +69 -3
  98. package/styles/material.css +69 -3
  99. package/styles/material3-dark.css +453 -0
  100. package/styles/material3-dark.scss +3 -0
  101. package/styles/material3.css +509 -0
  102. package/styles/material3.scss +3 -0
  103. package/styles/tailwind-dark.css +69 -3
  104. package/styles/tailwind.css +69 -3
  105. package/src/image-editor/image-editor.js +0 -14827
@@ -1,11 +1,11 @@
1
1
  /*!
2
2
  * filename: ej2-image-editor.umd.min.js
3
- * version : 21.2.10
3
+ * version : 22.1.34
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
- !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@syncfusion/ej2-base"),require("@syncfusion/ej2-navigations"),require("@syncfusion/ej2-splitbuttons"),require("@syncfusion/ej2-inputs"),require("@syncfusion/ej2-popups")):"function"==typeof define&&define.amd?define(["exports","@syncfusion/ej2-base","@syncfusion/ej2-navigations","@syncfusion/ej2-splitbuttons","@syncfusion/ej2-inputs","@syncfusion/ej2-popups"],e):e(t.ej={},t.ej2Base,t.ej2Navigations,t.ej2Splitbuttons,t.ej2Inputs,t.ej2Popups)}(this,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 i(){return null!==t&&t.apply(this,arguments)||this}return n(i,t),r([e.Property(null)],i.prototype,"zoomTrigger",void 0),r([e.Property(1)],i.prototype,"minZoomFactor",void 0),r([e.Property(10)],i.prototype,"maxZoomFactor",void 0),r([e.Property(1)],i.prototype,"zoomFactor",void 0),r([e.Property(null)],i.prototype,"zoomPoint",void 0),i}(e.ChildProperty),c=function(c){function d(t,e){var i=c.call(this,t,e)||this;return i.degree=0,i.isUndoRedo=!1,i.dragCanvas=!1,i.dragElement="",i.keyHistory="",i.tempKeyHistory="",i.mouseDownPoint={x:0,y:0},i.previousPoint={x:0,y:0},i.dragPoint={startX:0,startY:0,endX:0,endY:0},i.diffPoint={x:0,y:0},i.oldPoint={},i.objColl=[],i.undoRedoColl=[],i.isImageLoaded=!1,i.strokeSettings={strokeColor:"#fff",fillColor:"",strokeWidth:null},i.tempStrokeSettings={strokeColor:"#fff",fillColor:"",strokeWidth:null},i.textSettings={text:"Enter Text",fontFamily:"Arial",fontSize:null,fontRatio:null,bold:!1,italic:!1,underline:!1},i.tempTextSettings={text:"Enter Text",fontFamily:"Arial",fontSize:null,fontRatio:null,bold:!1,italic:!1,underline:!1},i.toolbarHeight=46,i.togglePan=!1,i.disablePan=!1,i.currFlipState="",i.touchEndPoint={},i.undoRedoStep=0,i.togglePen=!1,i.currentToolbar="main",i.textStartPoints={x:0,y:0},i.fontSizeColl=[],i.textRow=1,i.activeObj={activePoint:{startX:0,startY:0,endX:0,endY:0,width:0,height:0},flipObjColl:[],triangle:[],triangleRatio:[]},i.tempActiveObj={activePoint:{startX:0,startY:0,endX:0,endY:0,width:0,height:0},flipObjColl:[],triangle:[],triangleRatio:[]},i.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},i.defToolbarItems=[],i.isFirstMove=!1,i.startTouches=[],i.tempTouches=[],i.adjustmentLevel={brightness:0,contrast:0,hue:0,opacity:100,saturation:0,blur:0,exposure:0,sharpen:!1,bw:!1},i.tempAdjustmentLevel={brightness:0,contrast:0,hue:0,opacity:100,saturation:0,blur:0,exposure:0,sharpen:!1,bw:!1},i.adjustmentValue="",i.initialAdjustmentValue="",i.tempAdjustmentValue="",i.currentFilter="",i.tempFilter="",i.canvasFilter="brightness(1) contrast(100%) hue-rotate(0deg) saturate(100%) opacity(1) blur(0px) sepia(0%) grayscale(0%) invert(0%)",i.tempUndoRedoStep=0,i.zoomFactor=0,i.tempZoomFactor=0,i.destLeft=0,i.destTop=0,i.srcLeft=0,i.srcTop=0,i.cropDestPoints={startX:0,startY:0,width:0,height:0},i.flipColl=[],i.isReverseRotate=!1,i.isReverseFlip=!1,i.isPreventDragging=!1,i.isRotateZoom=!1,i.rotateFlipColl=[],i.currentPannedPoint={x:0,y:0},i.isCircleCrop=!1,i.rotatedDestPoints={startX:0,startY:0,width:0,height:0},i.croppedDegree=0,i.isFreehandDrawingPoint=!1,i.isFreehandDrawEditing=!1,i.tempFreeHandDrawEditingStyles={strokeColor:null,fillColor:null,strokeWidth:null},i.totalPannedInternalPoint={x:0,y:0},i.totalPannedClientPoint={x:0,y:0},i.totalPannedPoint={x:0,y:0},i.isCropTab=!1,i.cropZoomFactor=0,i.defaultZoomFactor=0,i.fileName="",i.isBrightnessAdjusted=!1,i.isInitialLoading=!1,i.freehandDrawObj={lastWidth:0,lastVelocity:0,time:0,pointX:0,pointY:0},i.points=[],i.pointColl={},i.pointCounter=0,i.freehandCounter=0,i.isFreehandDrawing=!1,i.tempFreehandCounter=0,i.selectedFreehandColor="#42a5f5",i.isFreehandDrawCustomized=!1,i.isAllowCropPan=!1,i.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:"",zoomFactor:0,previousZoomValue:0},i.afterCropActions=[],i.isCancelAction=!1,i.isFreehandPointMoved=!1,i.isTouch=!1,i.freehandDownPoint={x:0,y:0},i.tempFlipPanPoint={x:0,y:0},i.currentFreehandDrawIndex=0,i.tempCurrentFreehandDrawIndex=0,i.preventZoomBtn=!1,i.cancelObjColl=[],i.cancelPointColl=[],i.rotatedFlipCropSelection=!1,i.currToolbar="",i.currentMouseMovePoint={x:0,y:0},i.zoomType="Toolbar",i.cursorTargetObjId="",i.appliedUndoRedoColl=[],i.selPoints=[],i.selPointColl={},i.previousZoomValue=1,i.isObjSelected=!1,i.isShapeInserted=!1,i.isInitialTextEdited=!1,i.isShapeTextInserted=!1,i.isErrorImage=!1,i}n(d,c),p=d,d.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",Arrow:"Arrow",Bold:"Bold",Italic:"Italic",BoldItalic:"Bold Italic",XSmall:"X-Small",Small:"Small",Medium:"Medium",Large:"Large",XLarge:"X-Large",ABC:"ABC",Browse:"Browse",Duplicate:"Duplicate",Remove:"Remove",EditText:"Edit Text"},this.l10n=new e.L10n("image-editor",this.defaultLocale,this.locale)},d.prototype.render=function(){this.initialize()},d.prototype.getModuleName=function(){return"image-editor"},d.prototype.getPersistData=function(){return this.addOnPersist([])},d.prototype.onPropertyChanged=function(i,s){for(var o=0,a=Object.keys(i);o<a.length;o++){switch(a[o]){case"cssClass":s.cssClass&&e.removeClass([this.element],s.cssClass.replace(/\s+/g," ").trim().split(" ")),i.cssClass&&e.addClass([this.element],i.cssClass.replace(/\s+/g," ").trim().split(" "));break;case"disabled":i.disabled?(this.element.classList.add("e-disabled"),this.unwireEvent()):(this.element.classList.remove("e-disabled"),this.wireEvent());break;case"height":this.element.style.height=i.height;break;case"width":this.element.style.width=i.width;break;case"theme":i.theme&&(this.updateTheme(),this.upperContext.strokeStyle=this.themeColl[this.theme].primaryColor,this.upperContext.fillStyle=this.themeColl[this.theme].secondaryColor);break;case"finetuneSettings":i.finetuneSettings&&(this.finetuneSettings=i.finetuneSettings,this.updateFinetunes());break;case"locale":i.locale&&(this.l10n.setLocale(i.locale),this.refreshToolbar("main"));break;case"allowUndoRedo":i.allowUndoRedo?this.allowUndoRedo=!0:this.allowUndoRedo=!1,this.refreshToolbar("main");break;case"showQuickAccessToolbar":i.showQuickAccessToolbar?(this.showQuickAccessToolbar=!0,this.createQuickAccessToolbar(),this.renderQuickAccessToolbar()):(this.showQuickAccessToolbar=!1,this.destroyQuickAccessToolbar());break;case"zoomSettings":i.zoomSettings&&(this.zoomSettings.zoomTrigger=i.zoomSettings.zoomTrigger),e.isNullOrUndefined(this.zoomSettings.zoomTrigger)?(this.zoomSettings.zoomTrigger=t.ZoomTrigger.MouseWheel|t.ZoomTrigger.Pinch|t.ZoomTrigger.Toolbar|t.ZoomTrigger.Commands,this.refreshToolbar("main")):(i.zoomSettings.zoomTrigger&t.ZoomTrigger.Toolbar)===t.ZoomTrigger.Toolbar&&this.refreshToolbar("main")}}},d.prototype.destroy=function(){var t=[];this.element.removeAttribute("tabindex"),this.cssClass&&(t=t.concat(this.cssClass.replace(/\s+/g," ").trim().split(" "))),e.removeClass([this.element],t),this.element.getAttribute("class")||this.element.removeAttribute("class"),this.destroySubComponents(),this.unwireEvent(),c.prototype.destroy.call(this),this.element.innerHTML=""},d.prototype.initialize=function(){this.updateFinetunes(),this.createToolbar(),this.createContextualToolbar(),this.createCanvas(),this.createQuickAccessToolbar(),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}),e.isNullOrUndefined(this.zoomSettings.zoomTrigger)&&(this.zoomSettings.zoomTrigger=t.ZoomTrigger.MouseWheel|t.ZoomTrigger.Pinch|t.ZoomTrigger.Toolbar|t.ZoomTrigger.Commands),e.isNullOrUndefined(this.zoomSettings.zoomFactor)&&(this.zoomSettings.zoomFactor=1),e.isNullOrUndefined(this.zoomSettings.maxZoomFactor)&&(this.zoomSettings.maxZoomFactor=10)},d.prototype.getDefaultFilter=function(){return"brightness(1) contrast(100%) hue-rotate(0deg) saturate(100%) opacity(1) blur(0px) sepia(0%) grayscale(0%) invert(0%)"},d.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)},d.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)},d.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))},d.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)},d.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(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)))},d.prototype.updateTheme=function(){e.isNullOrUndefined(this.theme)||""===this.theme?this.theme="Bootstrap5":this.theme=this.toPascalCase(this.theme)},d.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("")},d.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.textArea.style.lineHeight="normal",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="block",this.upperContext=this.upperCanvas.getContext("2d"),this.inMemoryContext=this.inMemoryCanvas.getContext("2d")},d.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(){t.disabled||(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},d.prototype.createQuickAccessToolbar=function(){if(this.showQuickAccessToolbar){document.querySelector("#"+this.element.id+"_canvasWrapper").appendChild(this.createElement("div",{id:this.element.id+"_quickAccessToolbarArea",className:"e-quick-access-toolbar-area"}));var t=document.getElementById(this.element.id+"_quickAccessToolbarArea");if(t.style.position="absolute",e.isNullOrUndefined(this.activeObj)||(t.style.left=this.activeObj.activePoint.startX+"px",t.style.top=this.activeObj.activePoint.startY+"px"),t.style.width="100%",t.style.height="40px",this.quickAccessToolbarTemplate)this.quickAccessToolbarTemplateFn();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+"_quickAccessToolbarArea"),n=this.createElement("div",{id:this.element.id+"_quickAccessToolbar"});a.appendChild(n),new i.Toolbar({clicked:this.defToolbarClicked.bind(this)},"#"+this.element.id+"_quickAccessToolbar")}}},d.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)}},d.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"}},d.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()}},d.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();if(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()}}},d.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()}},d.prototype.quickAccessToolbarTemplateFn=function(){var t,e=this.element.id+"_quickAccessToolbar",i=this.element.querySelector("#"+this.element.id+"_quickAccessToolbarArea");if(this.quickAccessToolbarTemplate){if(this.quickAccessToolbarFn=this.templateParser(this.quickAccessToolbarTemplate),this.isReact)t=this.quickAccessToolbarFn({type:"toolbar"},this,"Template",e)[0];else if(this.isAngular){var s=this.quickAccessToolbarFn({type:"toolbar"},this,"Template",e);t=3===s[0].nodeType?s[1]:s[0]}else t=this.quickAccessToolbarFn({type:"toolbar"},this,"Template",e)[0];i.appendChild(t),this.renderReactTemplates()}},d.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)}},d.prototype.getLeftToolbarItem=function(i){var s=[];i||(s.push({id:this.element.id+"_upload",cssClass:"e-image-upload",align:"Left",type:"Input",template:new o.Uploader({allowedExtensions:".jpg, .jpeg, .png,.svg"})}),s.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)&&s.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)&&s.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||(this.zoomSettings.zoomTrigger&t.ZoomTrigger.Toolbar)!==t.ZoomTrigger.Toolbar||((e.isNullOrUndefined(this.toolbar)||!e.isNullOrUndefined(this.toolbar)&&this.toolbar.indexOf("ZoomOut")>-1)&&s.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)&&s.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 a=this.processToolbar("left"),n=0,r=a.length;n<r;n++)s.push(a[n]);return s},d.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},d.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},d.prototype.getZoomToolbarItem=function(){return[]},d.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},d.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},d.prototype.wireZoomBtnEvents=function(){var t=document.querySelector("#"+this.element.id+"_zoomIn"),i=document.querySelector("#"+this.element.id+"_zoomOut");e.isNullOrUndefined(t)||(t.addEventListener("mousedown",this.zoomInBtnMouseDownHandler.bind(this)),t.addEventListener("mouseup",this.zoomBtnMouseUpHandler.bind(this)),t.addEventListener("click",this.zoomInBtnClickHandler.bind(this)),t.addEventListener("touchstart",this.zoomInBtnClickHandler.bind(this))),e.isNullOrUndefined(i)||(i.addEventListener("mousedown",this.zoomOutBtnMouseDownHandler.bind(this)),i.addEventListener("mouseup",this.zoomBtnMouseUpHandler.bind(this)),i.addEventListener("click",this.zoomOutBtnClickHandler.bind(this)),t.addEventListener("touchstart",this.zoomInBtnClickHandler.bind(this)))},d.prototype.isToolbar=function(){return e.isNullOrUndefined(this.toolbar)||!e.isNullOrUndefined(this.toolbar)&&this.toolbar.length>0||!e.isNullOrUndefined(this.toolbarTemplate)},d.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();if(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.wireZoomBtnEvents(),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()}}},d.prototype.enableDisableToolbarBtn=function(){var t=document.querySelector("#"+this.element.id+"_undo");e.isNullOrUndefined(t)||0!==this.undoRedoStep?!e.isNullOrUndefined(t)&&this.undoRedoStep>0&&(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.appliedUndoRedoColl.length?!e.isNullOrUndefined(i)&&0===this.undoRedoStep&&this.appliedUndoRedoColl.length>0?(i.classList.remove("e-disabled"),i.parentElement.classList.remove("e-overlay")):!e.isNullOrUndefined(i)&&this.undoRedoStep>0&&(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.zoomSettings.zoomFactor>=this.zoomSettings.maxZoomFactor?(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"},d.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)}}},d.prototype.cropSelectedState=function(){e.isNullOrUndefined(this.activeObj.shape)||"crop"!==this.activeObj.shape.split("-")[0]||this.okBtn()},d.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(t){e.Browser.isDevice&&(t.element.parentElement.style.top=a.element.getBoundingClientRect().top-t.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.refreshMainToolbar()),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")},d.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.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")},d.prototype.renderTransformBtn=function(){var t=[];(e.isNullOrUndefined(this.toolbar)||!e.isNullOrUndefined(this.toolbar)&&this.toolbar.indexOf("RotateLeft")>-1)&&t.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)&&t.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)&&t.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)&&t.push({text:this.l10n.getConstant("VerticalFlip"),id:"verticalflip",iconCss:"e-icons e-vertical-flip"});var i=new s.DropDownButton({open:function(t){if(e.Browser.isDevice){var s=t.element.parentElement.offsetHeight;t.element.parentElement.style.display="none",t.element.parentElement.style.top=i.element.getBoundingClientRect().top-s+"px",t.element.parentElement.style.display="block"}},items:t,select:this.transformSelect.bind(this),iconCss:"e-icons e-transform",cssClass:"e-image-popup"});i.appendTo("#"+this.element.id+"_transformBtn")},d.prototype.renderSaveBtn=function(){var t=e.getInstance(document.getElementById(this.element.id),p);if(document.getElementById(this.element.id+"_saveBtn")){new s.DropDownButton({items:[{text:"JPEG",id:"jpeg"},{text:"PNG",id:"png"},{text:"SVG",id:"svg"}],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")}},d.prototype.cropSelect=function(t){this.isCropTab=!0,this.zoomFactor=this.cropZoomFactor;var e=t.item.id;this.currentToolbar="crop",this.currSelectionPoint=null,this.select(e),this.refreshToolbar("main",!0,!0),this.refreshDropDownBtn(!0),this.enableDisableToolbarBtn()},d.prototype.transformSelect=function(t){this.currObjType.isUndoAction&&this.refreshUndoRedoColl(),this.cropSelectedState(),this.currentSelectionPoint=null,this.performTransformation(t.item.id),this.updateCurrentUndoRedoColl("ok")},d.prototype.resetZoom=function(){if(0!==this.defaultZoomFactor){var t=this.isUndoRedo;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.zoomAction(-this.defaultZoomFactor):this.zoomAction(Math.abs(this.defaultZoomFactor)),this.isUndoRedo=t}},d.prototype.performTransformation=function(t){var i=this.defaultZoomFactor,s=this.isUndoRedo,o=e.extend({},this.cropObj,{},!0);if(this.resetZoom(),this.updateTransform(t),0!==i){this.isUndoRedo=!0,this.zoomAction(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}},d.prototype.updateTransform=function(e){switch(e.toLowerCase()){case"rotateleft":this.rotateImage(-90);break;case"rotateright":this.rotateImage(90);break;case"horizontalflip":this.flipImage(t.Direction.Horizontal);break;case"verticalflip":this.flipImage(t.Direction.Vertical)}},d.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},d.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),s.wireZoomBtnEvents(),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()},d.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"}},d.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();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(),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){if(!e.isNullOrUndefined(document.getElementById(i.element.id+"_bottomToolbar"))){e.getComponent(i.element.id+"_bottomToolbar","toolbar").refreshOverflow()}}else if(!e.isNullOrUndefined(document.getElementById(i.element.id+"_toolbar"))){e.getComponent(i.element.id+"_toolbar","toolbar").refreshOverflow()}}});r.appendTo("#"+this.element.id+"_borderWidthBtn")}},d.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},d.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"}]},d.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")}]},d.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),s.wireZoomBtnEvents(),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()},d.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.isInitialTextEdited=!1,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"}},d.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}},d.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.isInitialTextEdited=!1,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){i.isInitialTextEdited=!1,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.isInitialTextEdited=!1,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;r=i.activeObj.keyHistory.split("\n"),h=i.getMaxText(),l=i.upperContext.measureText(h).width+.5*i.activeObj.textSettings.fontSize;var 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")}},d.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},d.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},d.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.redrawShape(this.objColl[this.objColl.length-1])}},d.prototype.updateObjColl=function(t,i){var s=e.extend({},this.cropObj,{},!0),o=this.getCurrentObj();o.objColl=i,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},d.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){var 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){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)}},d.prototype.initZoomToolbarItem=function(){var t=this,s=this.getLeftToolbarItem(),o=this.getRightToolbarItem(),a=this.getZoomToolbarItem();if(this.defToolbarItems=s.concat(a,o),new i.Toolbar({width:"100%",items:this.defToolbarItems,clicked:this.defToolbarClicked.bind(this),created:function(){t.renderSaveBtn(),t.wireZoomBtnEvents(),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()}},d.prototype.refreshUndoRedoColl=function(){this.undoRedoColl=this.undoRedoColl.slice(0,this.undoRedoStep),this.appliedUndoRedoColl=this.appliedUndoRedoColl.slice(0,this.undoRedoStep),this.isUndoRedo=this.currObjType.isUndoAction=!1,this.enableDisableToolbarBtn()},d.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)},d.prototype.contextualToolbarClicked=function(t){var e=this.element.querySelector(".e-contextual-toolbar-wrapper .e-toolbar-item.e-selected");e&&e.classList.remove("e-selected");var i=t.item.id.replace(this.element.id,"").split("_")[1],s={filter:this.toPascalCase(i),cancel:!1};this.trigger("imageFiltering",s),s.cancel||(document.getElementById(t.item.id+"Canvas").parentElement.parentElement.classList.add("e-selected"),this.currObjType.isFiltered=!0,this.setFilter(i.toLowerCase()),this.currentFilter=t.item.id,this.enableDisableToolbarBtn())},d.prototype.zoomInBtnClickHandler=function(i){if((this.zoomSettings.zoomTrigger&t.ZoomTrigger.Toolbar)===t.ZoomTrigger.Toolbar){if(e.Browser.isDevice&&"touchstart"===i.type){if(!i.returnValue)return;i.preventDefault()}var s=document.querySelector("#"+this.element.id+"_zoomIn");e.EventHandler.trigger(s,"click"),this.isFreehandDrawEditing&&this.applyFreehandDraw(),this.applyPreviewFilter(),this.currObjType.isFiltered=!1,this.togglePen&&(this.currObjType.isZoomed=!0,this.freeHandDraw(!1),this.updateCurrentUndoRedoColl("ok")),this.currentSelectionPoint=null,this.zoomAction(.1)}},d.prototype.zoomOutBtnClickHandler=function(i){if((this.zoomSettings.zoomTrigger&t.ZoomTrigger.Toolbar)===t.ZoomTrigger.Toolbar){if(e.Browser.isDevice&&"touchstart"===i.type){if(!i.returnValue)return;i.preventDefault()}var s=document.querySelector("#"+this.element.id+"_zoomOut");e.EventHandler.trigger(s,"click"),this.isFreehandDrawEditing&&this.applyFreehandDraw(),this.applyPreviewFilter(),this.currObjType.isFiltered=!1,this.togglePen&&(this.currObjType.isZoomed=!0,this.freeHandDraw(!1),this.updateCurrentUndoRedoColl("ok")),this.currentSelectionPoint=null,this.zoomAction(-.1)}},d.prototype.zoomInBtnMouseDownHandler=function(t){t.preventDefault(),this.zoomBtnHold=setInterval(this.zoomInBtnClickHandler.bind(this),250)},d.prototype.zoomOutBtnMouseDownHandler=function(t){t.preventDefault(),this.zoomBtnHold=setInterval(this.zoomOutBtnClickHandler.bind(this),250)},d.prototype.zoomBtnMouseUpHandler=function(){clearInterval(this.zoomBtnHold),this.zoomBtnHold=0},d.prototype.defToolbarClicked=function(t){var i=!1,s=!1;if(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"),s=!0),!e.isNullOrUndefined(t.item)){var o=t.item.id.replace(this.element.id+"_","").toLowerCase(),a=e.getInstance(document.getElementById(this.element.id),p),n=!1,r=void 0,h=void 0;void 0!==this.activeObj.shape&&(h=this.activeObj.shape.split("-")),void 0===h&&this.currObjType.isCustomCrop?n=!0:void 0!==h&&"crop"===h[0]&&(n=!0);var l=!1,c=!1,d=document.querySelector("#"+this.element.id+"_zoomIn"),v=document.querySelector("#"+this.element.id+"_adjustment");!e.isNullOrUndefined(v)&&v.classList.contains("e-disabled")&&(c=!0);var u=document.querySelector("#"+this.element.id+"_filter");!e.isNullOrUndefined(u)&&u.classList.contains("e-disabled")&&(l=!0),this.enableDisableToolbarBtn();var b=void 0,C=void 0;if(!this.disabled)switch(o){case"pan":this.currObjType.isCustomCrop=this.currObjType.isFiltered=!1,this.currObjType.isUndoAction&&this.refreshUndoRedoColl(),n&&(this.currObjType.isCustomCrop=!1,this.refreshActiveObj(),this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),this.refreshMainToolbar()),this.togglePan?(this.cancelPan(),this.disablePan=!0,"pen"===this.currentToolbar&&this.freeHandDraw(!0)):(r=this.element.querySelector(".e-img-pan .e-btn"),e.isNullOrUndefined(r)||r.classList.add("e-selected-btn"),a.pan(!0),this.disablePan=!1),!e.isNullOrUndefined(d)&&this.zoomSettings.zoomFactor>=this.zoomSettings.maxZoomFactor?(d.classList.add("e-disabled"),d.parentElement.classList.add("e-overlay")):e.isNullOrUndefined(d)||(d.classList.remove("e-disabled"),d.parentElement.classList.remove("e-overlay")),this.refreshMainToolbar();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":a.reset(),this.currentToolbar="main";break;case"undo":this.callUndo();break;case"redo":this.callRedo();break;case"adjustment":c||(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(o);break;case"filter":l||(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(o);break;case"duplicate":b=e.extend({},this.activeObj,{},!0),e.isNullOrUndefined(this.activeObj.currIndex)?this.applyActObj():this.applyActObj(!0),C=e.extend([],this.objColl,[],!0),b.activePoint.startX+=10,b.activePoint.startY-=10,b.activePoint.endX+=10,b.activePoint.endY-=10,this.activeObj=b,this.updateTrianglePoints(this.activeObj),this.drawObject("duplicate"),this.updateUndoRedoObj(C),this.renderQuickAccessToolbar();break;case"remove":this.deleteItem();break;case"edittext":this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),this.renderTextArea(this.activeObj.activePoint.startX,this.activeObj.activePoint.startY,this.activeObj),e.isNullOrUndefined(document.getElementById(this.element.id+"_quickAccessToolbarArea"))||(document.getElementById(this.element.id+"_quickAccessToolbarArea").style.display="none");break;case"upload":s&&this.element.querySelector(".e-contextual-toolbar-wrapper").classList.remove("e-hide")}this.trigger("toolbarItemClicked",t)}},d.prototype.performCancel=function(t){t=t||!1,this.isFreehandDrawEditing?(this.cancelFreehandDraw(),this.destroyQuickAccessToolbar(),this.updateCurrentUndoRedoColl("cancel")):"block"===this.textArea.style.display?(this.textArea.style.display="none",this.textArea.value="",this.textArea.style.transform="",e.isNullOrUndefined(this.prevActObj)?(this.activeObj.strokeSettings=this.tempStrokeSettings,this.activeObj.textSettings=this.tempTextSettings):(this.activeObj=this.prevActObj,this.prevActObj=null),this.updateCurrentUndoRedoColl("cancel"),this.isShapeTextInserted&&this.refreshActiveObj(),this.applyActObj(!0),this.refreshMainToolbar()):!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(),this.updateCurrentUndoRedoColl("cancel")):t?this.callMainToolbar():(this.cancelItems(),this.togglePan=this.dragCanvas=!1),this.isShapeTextInserted=!1,this.refreshDropDownBtn(!1),this.currentToolbar="main"},d.prototype.applyShape=function(){e.isNullOrUndefined(this.activeObj.shape)||"rectangle"!==this.activeObj.shape&&"ellipse"!==this.activeObj.shape&&"line"!==this.activeObj.shape&&"arrow"!==this.activeObj.shape&&"text"!==this.activeObj.shape||(this.redrawActObj(),this.refreshActiveObj(),this.currentToolbar="main",this.refreshMainToolbar())},d.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.refreshMainToolbar(),e.isNullOrUndefined(this.pointColl[this.freehandDrawSelectedIndex])||(this.pointColl[this.freehandDrawSelectedIndex].isSelected=!1),this.isFreehandDrawEditing=this.isFreehandDrawingPoint=!1,this.freehandDrawHoveredIndex=this.freehandDrawSelectedIndex=null},d.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.activeObj.strokeSettings.strokeColor=this.tempFreeHandDrawEditingStyles.strokeColor,this.activeObj.strokeSettings.strokeWidth=this.penStrokeWidth=this.tempFreeHandDrawEditingStyles.strokeWidth,this.tempFreeHandDrawEditingStyles={strokeColor:null,strokeWidth:null,fillColor:null},this.refreshMainToolbar()},d.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")},d.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.tempUndoRedoStep=this.undoRedoStep},d.prototype.okBtn=function(t){var i,s=!1;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);var o=this.element.querySelector(".e-contextual-toolbar-wrapper .e-toolbar-item.e-selected");o&&(this.currentFilter=o.children[0].children[0].id.replace("Canvas","")),s?this.crop():this.togglePen?(this.freeHandDraw(!1),this.updateCurrentUndoRedoColl("ok")):"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.updateCurrentUndoRedoColl("ok")):this.isFreehandDrawEditing?(this.applyFreehandDraw(),this.destroyQuickAccessToolbar(),this.updateCurrentUndoRedoColl("ok")):this.applyActObj(t),this.callMainToolbar(!1),this.isCropTab=!1,this.zoomFactor=this.defaultZoomFactor},d.prototype.getZeroZoomPointCollValue=function(t){var i=this.getCurrentObj();i.objColl=e.extend([],this.objColl,[],!0),i.pointColl=e.extend([],this.pointColl,[],!0),i.afterCropActions=e.extend([],this.afterCropActions,[],!0);var s=e.extend([],this.pointColl,[],!0);if(this.zoomFactor>0&&t.length>0){this.pointColl=t;var o=this.isUndoRedo;if(0!==this.zoomFactor){this.isUndoRedo=this.isCropTab=!0,this.updateObjAndFreeHandDrawColl();var a=e.extend({},this.zoomSettings,null,!0);this.zoomFactor>0?this.zoomAction(-this.zoomFactor):this.zoomAction(Math.abs(this.zoomFactor)),this.zoomSettings=a,this.isCropTab=!1,this.isUndoRedo=o,s=e.extend([],this.pointColl,[],!0),this.objColl=[],this.pointColl=[],this.freehandCounter=0,this.setCurrentObj(i),this.destLeft=i.destPoints.startX,this.destTop=i.destPoints.startY,this.totalPannedPoint=i.totalPannedPoint,this.totalPannedClientPoint=i.totalPannedClientPoint,this.totalPannedInternalPoint=i.totalPannedInternalPoint,this.objColl=e.extend([],i.objColl,[],!0),this.pointColl=e.extend([],i.pointColl,[],!0),this.freehandCounter=this.pointColl.length,this.lowerContext.filter="none",this.iterateObjColl(),this.freehandRedraw(this.lowerContext),this.updateCursorPointsForFreehandDrawing(),this.lowerContext.filter=i.filter}}return s},d.prototype.getZeroZoomObjValue=function(t){var i=this.getCurrentObj();i.objColl=e.extend([],this.objColl,[],!0),i.pointColl=e.extend([],this.pointColl,[],!0),i.afterCropActions=e.extend([],this.afterCropActions,[],!0);var s=e.extend([],this.objColl,[],!0);if(this.zoomFactor>0&&t.length>0){this.objColl=t;var o=this.isUndoRedo;if(0!==this.zoomFactor){this.isUndoRedo=this.isCropTab=!0,this.updateObjAndFreeHandDrawColl();var a=e.extend({},this.zoomSettings,null,!0);this.zoomFactor>0?this.zoomAction(-this.zoomFactor):this.zoomAction(Math.abs(this.zoomFactor)),this.zoomSettings=a,this.isCropTab=!1,this.isUndoRedo=o,s=e.extend([],this.objColl,[],!0),this.objColl=[],this.pointColl=[],this.freehandCounter=0,this.setCurrentObj(i),this.destLeft=i.destPoints.startX,this.destTop=i.destPoints.startY,this.totalPannedPoint=i.totalPannedPoint,this.totalPannedClientPoint=i.totalPannedClientPoint,this.totalPannedInternalPoint=i.totalPannedInternalPoint,this.objColl=e.extend([],i.objColl,[],!0),this.pointColl=e.extend([],i.pointColl,[],!0),this.freehandCounter=this.pointColl.length,this.lowerContext.filter="none",this.iterateObjColl(),this.freehandRedraw(this.lowerContext),this.updateCursorPointsForFreehandDrawing(),this.lowerContext.filter=i.filter}}return s},d.prototype.updateCurrentUndoRedoColl=function(t){"ok"===t&&(this.isShapeTextInserted=!1,this.currObjType.isUndoAction&&this.refreshUndoRedoColl(),e.isNullOrUndefined(this.appliedUndoRedoColl[this.appliedUndoRedoColl.length-1])?e.isNullOrUndefined(this.undoRedoColl[0])||(this.undoRedoColl[this.undoRedoColl.length-1].previousCropObj=this.undoRedoColl[0].previousCropObj,this.undoRedoColl[this.undoRedoColl.length-1].previousObj=this.undoRedoColl[0].previousObj,this.undoRedoColl[this.undoRedoColl.length-1].previousObjColl=this.undoRedoColl[0].previousObjColl,this.undoRedoColl[this.undoRedoColl.length-1].previousPointColl=this.undoRedoColl[0].previousPointColl,this.undoRedoColl[this.undoRedoColl.length-1].previousText=this.undoRedoColl[0].previousText):(this.undoRedoColl[this.undoRedoColl.length-1].previousCropObj=this.appliedUndoRedoColl[this.appliedUndoRedoColl.length-1].currentCropObj,this.undoRedoColl[this.undoRedoColl.length-1].previousObj=this.appliedUndoRedoColl[this.appliedUndoRedoColl.length-1].currentObj,this.undoRedoColl[this.undoRedoColl.length-1].previousObjColl=this.appliedUndoRedoColl[this.appliedUndoRedoColl.length-1].currentObjColl,this.undoRedoColl[this.undoRedoColl.length-1].previousPointColl=this.appliedUndoRedoColl[this.appliedUndoRedoColl.length-1].currentPointColl,this.undoRedoColl[this.undoRedoColl.length-1].previousText=this.appliedUndoRedoColl[this.appliedUndoRedoColl.length-1].currentText),e.isNullOrUndefined(this.undoRedoColl[this.undoRedoColl.length-1])||(this.undoRedoColl[this.undoRedoColl.length-1].currentObjColl=this.getZeroZoomObjValue(this.undoRedoColl[this.undoRedoColl.length-1].currentObjColl),this.undoRedoColl[this.undoRedoColl.length-1].currentPointColl=this.getZeroZoomPointCollValue(this.undoRedoColl[this.undoRedoColl.length-1].currentPointColl),this.appliedUndoRedoColl.push(this.undoRedoColl[this.undoRedoColl.length-1]))),this.appliedUndoRedoColl.length>16&&this.appliedUndoRedoColl.splice(0,1),this.undoRedoColl=[],this.undoRedoColl=e.extend([],this.appliedUndoRedoColl,[],!0),"ok"===t&&(this.undoRedoStep=this.undoRedoColl.length,this.enableDisableToolbarBtn()),this.zoomFactor>0&&(this.dragCanvas=this.togglePan=!0)},d.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(" ")}},d.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},d.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(var a=0;a<this.freehandCounter;a++)a!==t&&(this.pointColl[o]=s[a],o++);else for(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.refreshMainToolbar()}},d.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")},d.prototype.callUndo=function(){this.currObjType.isFiltered=!1,0===this.zoomFactor&&(this.dragCanvas=this.togglePan=!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.appliedUndoRedoColl.length>0&&(this.undoRedoColl=e.extend([],this.appliedUndoRedoColl,[],!0)),this.undo()},d.prototype.callRedo=function(){this.currObjType.isFiltered=!1,0===this.zoomFactor&&(this.dragCanvas=this.togglePan=!1),this.appliedUndoRedoColl.length>0&&(this.undoRedoColl=e.extend([],this.appliedUndoRedoColl,[],!0)),this.redo()},d.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())},d.prototype.iterateObjColl=function(){for(var t=0;t<this.objColl.length;t++)this.apply(this.objColl[t].shape,this.objColl[t]),this.refreshActiveObj()},d.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,u,b;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+"%)",u=this.getFilterValue(this.adjustmentLevel.contrast),i=(u*=100)+.5*u,n[1]="contrast("+i+"%)",b=this.getSaturationFilterValue(this.adjustmentLevel.saturation),i=b*=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(" ")},d.prototype.autoEnablePan=function(){0===this.zoomFactor?(this.dragCanvas=this.togglePan=!1,this.pan(!1),this.disablePan=!1):this.disablePan?this.disablePan&&this.pan(!1):this.pan(!0)},d.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},d.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},d.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"},d.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()}})},d.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},d.prototype.getFinetuneOption=function(e){var i;switch(e){case"brightness":i=t.ImageFinetuneOption.Brightness;break;case"contrast":i=t.ImageFinetuneOption.Contrast;break;case"hue":i=t.ImageFinetuneOption.Hue;break;case"saturation":i=t.ImageFinetuneOption.Saturation;break;case"opacity":i=t.ImageFinetuneOption.Opacity;break;case"blur":i=t.ImageFinetuneOption.Blur;break;case"exposure":i=t.ImageFinetuneOption.Exposure}return i},d.prototype.setCurrAdjustmentValue=function(t,e){var i={finetune:this.getFinetuneOption(this.toPascalCase(t)),value:e,cancel:!1};if(this.trigger("finetuneValueChanging",i),!i.cancel)switch(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)}},d.prototype.cancelPan=function(){this.applyActObj(!0);var t=this.element.querySelector(".e-img-pan .e-btn");e.isNullOrUndefined(t)||t.classList.remove("e-selected-btn"),this.pan(!1)},d.prototype.callMainToolbar=function(t,e){this.refreshToolbar("main",t,!1,e)},d.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=this.isUndoRedo;this.isUndoRedo=!0;var o=e.extend([],this.objColl,null,!0),a=e.extend([],this.pointColl,null,!0);this.objColl=[],this.pointColl=[],this.freehandCounter=0,this.objColl.push(this.currSelectionPoint),this.currSelectionPoint=null,this.zoomAction(this.cropObj.cropZoom),this.currSelectionPoint=e.extend({},this.objColl[0],null,!0),this.objColl=o,this.pointColl=a,this.freehandCounter=this.pointColl.length,this.isUndoRedo=s}var n={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=n.startX,this.destTop=n.startY,this.destWidth=n.width,this.destHeight=n.height,0===this.cropObj.cropZoom&&this.updatePannedRegion(),this.updateObjAndFreeHandDrawColl();var r=e.extend([],this.objColl,null,!0),h=e.extend([],this.pointColl,null,!0);this.objColl=[],this.pointColl=[],this.freehandCounter=0,this.setCurrentObj();var l=e.extend({},this.activeObj,null,!0);this.refreshActiveObj(),this.objColl=r,this.pointColl=h,this.freehandCounter=this.pointColl.length,this.zoomObjColl(),this.zoomFreehandDrawColl(),this.currSelectionPoint=null,0===this.degree&&this.drawPannImage({x:0,y:0}),this.activeObj=l,this.drawObject("duplicate")}},d.prototype.updatePannedRegion=function(){var t;t=this.degree%90==0&&this.degree%180==0?e.extend({},this.cropObj.totalPannedPoint,null,!0):e.extend({},this.cropObj.totalPannedClientPoint,null,!0),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,""))},d.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}},d.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,this.activeObj.strokeSettings=this.strokeSettings=this.tempStrokeSettings,this.updateCurrentUndoRedoColl("cancel"),this.isFreehandDrawCustomized=!1}else if("text"===this.activeObj.shape){if(this.textSettings=this.tempTextSettings,this.strokeSettings=this.tempStrokeSettings,e.isNullOrUndefined(this.activeObj.currIndex))this.refreshActiveObj(),this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height);else{var a=this.appliedUndoRedoColl.length;e.isNullOrUndefined(this.prevActObj)||e.isNullOrUndefined(this.appliedUndoRedoColl[a-1])||this.appliedUndoRedoColl[a-1].currentObjColl[this.appliedUndoRedoColl[a-1].currentObjColl.length-1].currIndex!==this.prevActObj.currIndex?(this.refreshActiveObj(),this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height)):(this.activeObj=this.prevActObj,this.prevActObj=null),e.isNullOrUndefined(this.activeObj.shape)||"Enter Text"!==this.activeObj.keyHistory||this.activeObj.activePoint.startX!==this.textStartPoints.x||this.activeObj.activePoint.startY!==this.textStartPoints.y?e.isNullOrUndefined(this.activeObj.shape)||(this.redrawText(),this.redrawShape(this.activeObj),i||void 0===this.activeObj.topLeftCircle||this.applyActObj(!0),this.clearSelection()):(this.refreshActiveObj(),this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),this.drawShapeText(),this.updateCurrentUndoRedoColl("cancel"),this.applyActObj(!0))}this.destroyQuickAccessToolbar(),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||"arrow"===this.activeObj.shape){if(this.strokeSettings=this.tempStrokeSettings,e.isNullOrUndefined(this.activeObj.currIndex))this.refreshActiveObj(),this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height);else{a=this.appliedUndoRedoColl.length;e.isNullOrUndefined(this.prevActObj)||e.isNullOrUndefined(this.appliedUndoRedoColl[a-1])||this.appliedUndoRedoColl[a-1].currentObjColl[this.appliedUndoRedoColl[a-1].currentObjColl.length-1].currIndex!==this.prevActObj.currIndex?(this.refreshActiveObj(),this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height)):(this.activeObj=this.prevActObj,this.prevActObj=null,this.redrawShape(this.activeObj),this.updateCurrentUndoRedoColl("cancel"),this.applyActObj(!0))}this.destroyQuickAccessToolbar()}else if(this.zoomFactor!==this.tempZoomFactor||i&&e.isNullOrUndefined(this.currSelectionPoint)){var n=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(),n>0?this.zoomAction(-n):this.zoomAction(Math.abs(n)),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 r=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(r),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),n>0?this.zoomAction(-n):this.zoomAction(Math.abs(n)),this.cropZoomFactor=this.tempZoomFactor}else{this.isCancelAction=!0,this.objColl=[],this.pointColl=[];var h=this.freehandCounter;this.freehandCounter=0;var l=e.extend({},this.cropObj,{}),c=e.extend([],this.afterCropActions,{},!0);this.setCurrentObj(),this.cropImg(),this.cropObj=l,this.afterCropActions=c,this.objColl=e.extend([],this.cancelObjColl,[],!0),this.pointColl=e.extend([],this.cancelPointColl,[],!0),this.freehandCounter=h,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.updateCurrentUndoRedoColl("cancel");this.upperCanvas.style.cursor="default",this.currObjType.isCustomCrop=!1,this.tempStrokeSettings={strokeColor:"#fff",fillColor:"",strokeWidth:null},this.callMainToolbar()},d.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)},d.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.selPointColl[this.freehandCounter]={},this.selPointColl[this.freehandCounter].points=e.extend([],this.selPoints),this.selPoints=[],this.pointCounter=0,this.freehandCounter++,this.currentFreehandDrawIndex++,this.isFreehandDrawing=!1,this.updateUndoRedoColl("freehanddraw",n,n.objColl,n.pointColl,a)},d.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)},d.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(this.selPoints.push({x:t,y:i,ratioX:(t-this.destLeft)/this.destWidth,ratioY:(i-this.destTop)/this.destHeight,time:this.freehandDrawObj.time}),!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()};d=.5,p=5;e.isNullOrUndefined(this.penStrokeWidth)||(d=p=this.penStrokeWidth),this.startDraw(o,a,n,r,h,d,p)}}},d.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=(t.x+e.x)/2,h=(t.y+e.y)/2,l=(e.x+i.x)/2,c=(e.y+i.y)/2,d=Math.sqrt(s*s+o*o),p=Math.sqrt(a*a+n*n),v=p/(d+p),u=l+(r-l)*v,b=c+(h-c)*v,C=e.x-u,f=e.y-b;return{controlPoint1:this.point(r+C,h+f,0),controlPoint2:this.point(l+C,c+f,0)}},d.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}},d.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},d.prototype.pointVelocity=function(t){return this.freehandDrawObj.time!==t.time?this.distanceTo(t)/(this.freehandDrawObj.time-t.time):0},d.prototype.distanceTo=function(t){return Math.sqrt(Math.pow(this.freehandDrawObj.pointX-t.x,2)+Math.pow(this.freehandDrawObj.pointY-t.y,2))},d.prototype.drawCurve=function(t,e,i,s,o,a,n,r){var h,l,c,d,p,v,u,b,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=(b=(u=(v=1-c)*v)*v)*a.x,C+=3*u*c*s.x,C+=3*v*d*o.x,C+=p*n.x,f=b*a.y,f+=3*u*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()},d.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},d.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},d.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))},d.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},d.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},d.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||"arrow"===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.currToolbar=t,this.refreshDropDownBtn(s)}},d.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},d.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},d.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},d.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),s.wireZoomBtnEvents(),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()},d.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"}},d.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();if(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){if(!e.isNullOrUndefined(document.getElementById(i.element.id+"_bottomToolbar"))){e.getComponent(i.element.id+"_bottomToolbar","toolbar").refreshOverflow()}}else if(!e.isNullOrUndefined(document.getElementById(i.element.id+"_toolbar"))){e.getComponent(i.element.id+"_toolbar","toolbar").refreshOverflow()}}});r.appendTo("#"+this.element.id+"_penStrokeWidth")}},d.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)},d.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}},d.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},d.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(){t.wireZoomBtnEvents(),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()},d.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")},d.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},d.prototype.createCanvasFilter=function(){var t=this.getCurrentCanvasData();this.inMemoryCanvas.width=t.width,this.inMemoryCanvas.height=t.height,this.inMemoryContext.putImageData(t,0,0);var i,s=document.querySelector("#"+this.element.id+"_defaultCanvas");e.isNullOrUndefined(s)||(i=s.getContext("2d"),s.style.width="100px",s.style.height="100px",i.filter=this.updateAdjustment("default",null,!0),i.drawImage(this.inMemoryCanvas,0,0,300,150));var o=document.querySelector("#"+this.element.id+"_chromeCanvas");e.isNullOrUndefined(o)||(i=o.getContext("2d"),o.style.width="100px",o.style.height="100px",i.filter=this.updateAdjustment("chrome",null,!0),i.drawImage(this.inMemoryCanvas,0,0,300,150));var a=document.querySelector("#"+this.element.id+"_coldCanvas");e.isNullOrUndefined(a)||(i=a.getContext("2d"),a.style.width="100px",a.style.height="100px",i.filter=this.updateAdjustment("cold",null,!0),i.drawImage(this.inMemoryCanvas,0,0,300,150));var n=document.querySelector("#"+this.element.id+"_warmCanvas");e.isNullOrUndefined(n)||(i=n.getContext("2d"),n.style.width="100px",n.style.height="100px",i.filter=this.updateAdjustment("warm",null,!0),i.drawImage(this.inMemoryCanvas,0,0,300,150));var r=document.querySelector("#"+this.element.id+"_grayscaleCanvas");e.isNullOrUndefined(r)||(i=r.getContext("2d"),r.style.width="100px",r.style.height="100px",i.filter=this.updateAdjustment("grayscale",null,!0),i.drawImage(this.inMemoryCanvas,0,0,300,150));var h=document.querySelector("#"+this.element.id+"_sepiaCanvas");e.isNullOrUndefined(h)||(i=h.getContext("2d"),h.style.width="100px",h.style.height="100px",i.filter=this.updateAdjustment("sepia",null,!0),i.drawImage(this.inMemoryCanvas,0,0,300,150));var l=document.querySelector("#"+this.element.id+"_invertCanvas");e.isNullOrUndefined(l)||(i=l.getContext("2d"),l.style.width="100px",l.style.height="100px",i.filter=this.updateAdjustment("invert",null,!0),i.drawImage(this.inMemoryCanvas,0,0,300,150))},d.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"),this.lowerContext.clearRect(0,0,this.lowerCanvas.width,this.lowerCanvas.height),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},d.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))},d.prototype.reverseTransformedState=function(){this.lowerContext.setTransform(1,0,0,1,0,0)},d.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)))},d.prototype.iterateRotateFlipColl=function(t,e){if("initial"===e)for(var i=0;i<this.rotateFlipColl.length;i++)this.setTransform(t,this.rotateFlipColl[i]);else if("reverse"===e)for(i=this.rotateFlipColl.length-1;i>=0;i--)this.setTransform(t,this.rotateFlipColl[i],!0)},d.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},d.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},d.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}for(o=0;o<this.freehandCounter;o++)if(!e.isNullOrUndefined(this.selPointColl[o])){this.selPoints=e.extend([],this.selPointColl[o].points,[]),this.pointCounter=0;for(a=this.selPoints.length,n=0;n<a;n++)""===s||"vertical"===s?this.selPoints[n].x+=t:this.selPoints[n].x-=t,""===s||"horizontal"===s?this.selPoints[n].y+=i:this.selPoints[n].y-=i}this.freehandRedraw(this.lowerContext)},d.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]),this.updateTrianglePoints(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()}},d.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)},d.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}for(t=0;t<this.freehandCounter;t++)if(!e.isNullOrUndefined(this.selPointColl[t])){this.selPoints=e.extend([],this.selPointColl[t].points,[]),this.pointCounter=0;for(i=this.selPoints.length,s=0;s<i;s++)this.selPoints[s].ratioX=(this.selPoints[s].x-this.activeObj.activePoint.startX)/this.activeObj.activePoint.width,this.selPoints[s].ratioY=(this.selPoints[s].y-this.activeObj.activePoint.startY)/this.activeObj.activePoint.height}},d.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||this.pointColl[o].strokeColor,s.strokeStyle=s.fillStyle,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();var v=this.getSquarePointForFreehandDraw(o),u=s.lineWidth;s.lineWidth=2,s.strokeStyle=this.themeColl[this.theme].primaryColor,s.beginPath(),s.rect(v.startX,v.startY,v.width,v.height),s.stroke(),s.closePath(),s.lineWidth=u},d.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}for(t=0;t<this.freehandCounter;t++)if(!e.isNullOrUndefined(this.selPointColl[t])&&this.selPointColl[t].shapeFlip!==this.currFlipState){this.selPoints=e.extend([],this.selPointColl[t].points,[]),this.pointCounter=0;for(i=this.selPoints.length,s=0;s<i;s++)this.selPoints[s].x<=this.destLeft+this.destWidth/2?this.selPoints[s].x=this.destLeft+this.destWidth-(this.selPoints[s].x-this.destLeft):this.selPoints[s].x>=this.destLeft+this.destWidth/2&&(this.selPoints[s].x=this.destLeft+(this.destLeft+this.destWidth-this.selPoints[s].x)),this.selPoints[s].ratioX=(this.selPoints[s].x-this.destLeft)/this.destWidth,this.selPoints[s].ratioY=(this.selPoints[s].y-this.destTop)/this.destHeight}this.updateCursorPointsForFreehandDrawing()},d.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}for(t=0;t<this.freehandCounter;t++)if(!e.isNullOrUndefined(this.selPointColl[t])&&this.selPointColl[t].shapeFlip!==this.currFlipState){this.selPoints=e.extend([],this.selPointColl[t].points,[]),this.pointCounter=0;for(i=this.selPoints.length,s=0;s<i;s++)this.selPoints[s].y<=this.destTop+this.destHeight/2?this.selPoints[s].y=this.destTop+this.destHeight-(this.selPoints[s].y-this.destTop):this.selPoints[s].y>=this.destTop+this.destHeight/2&&(this.selPoints[s].y=this.destTop+(this.destTop+this.destHeight-this.selPoints[s].y)),this.selPoints[s].ratioX=(this.selPoints[s].x-this.destLeft)/this.destWidth,this.selPoints[s].ratioY=(this.selPoints[s].y-this.destTop)/this.destHeight}this.updateCursorPointsForFreehandDrawing()},d.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()}},d.prototype.rotateFreehandDrawColl=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].y=this.destTop+this.destHeight*this.points[s].ratioX,this.points[s].x=this.destLeft+this.destWidth-this.destWidth*this.points[s].ratioY}for(t=0;t<this.freehandCounter;t++){this.points=e.extend([],this.pointColl[t].points,[]),this.pointCounter=0;for(i=this.points.length,s=0;s<i;s++)this.points[s].ratioX=(this.points[s].x-this.destLeft)/this.destWidth,this.points[s].ratioY=(this.points[s].y-this.destTop)/this.destHeight}for(t=0;t<this.freehandCounter;t++)if(!e.isNullOrUndefined(this.selPointColl[t])){this.selPoints=e.extend([],this.selPointColl[t].points,[]),this.pointCounter=0;for(i=this.selPoints.length,s=0;s<i;s++)this.selPoints[s].y=this.destTop+this.destHeight*this.selPoints[s].ratioX,this.selPoints[s].x=this.destLeft+this.destWidth-this.destWidth*this.selPoints[s].ratioY}for(t=0;t<this.freehandCounter;t++)if(!e.isNullOrUndefined(this.selPointColl[t])){this.selPoints=e.extend([],this.selPointColl[t].points,[]),this.pointCounter=0;for(i=this.selPoints.length,s=0;s<i;s++)this.selPoints[s].ratioX=(this.selPoints[s].x-this.destLeft)/this.destWidth,this.selPoints[s].ratioY=(this.selPoints[s].y-this.destTop)/this.destHeight}this.updateCursorPointsForFreehandDrawing()},d.prototype.updateCursorPointsForFreehandDrawing=function(){for(var t=0;t<this.freehandCounter;t++)if(!e.isNullOrUndefined(this.selPointColl[t])){this.selPoints=e.extend([],this.selPointColl[t].points,[]),this.pointCounter=0;for(var i=this.selPoints.length,s=0;s<i;s++)this.selPoints[s].x=this.zoomX(this.selPoints[s].ratioX),this.selPoints[s].y=this.zoomY(this.selPoints[s].ratioY)}},d.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)}this.updateCursorPointsForFreehandDrawing(),e.isNullOrUndefined(t)&&this.freehandRedraw(this.lowerContext)},d.prototype.zoomX=function(t){return t*this.destWidth+this.destLeft},d.prototype.zoomY=function(t){return t*this.destHeight+this.destTop},d.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]),this.updateTrianglePoints(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}},d.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}},d.prototype.drawCustomSelection=function(t,i,s,o,a){this.currObjType.isCustomCrop=!0,this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),this.currObjType.shape=this.activeObj.shape=t.toLowerCase(),e.isNullOrUndefined(i)||e.isNullOrUndefined(s)||e.isNullOrUndefined(o)||e.isNullOrUndefined(a)?(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.activeObj.activePoint.startX=i,this.activeObj.activePoint.startY=s,this.activeObj.activePoint.endX=i+o,this.activeObj.activePoint.endY=s+a,this.activeObj.activePoint.width=o,this.activeObj.activePoint.height=a),this.updateSelectionInsert(),this.drawObject("duplicate",this.activeObj,null,null,!0)},d.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)},d.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)},d.prototype.updateCropObj=function(){this.afterCropActions=[];var t=this.getCurrentObj();this.cropObj=e.extend({},t,{},!0)},d.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.setProperties({zoomSettings:{zoomFactor:t.zoomFactor}},!0),this.previousZoomValue=t.previousZoomValue,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,o=this.isCircleCrop;e.isNullOrUndefined(this.currSelectionPoint)?s=null:(s=e.extend({},this.currSelectionPoint,{},!0),this.currSelectionPoint=null),this.isCircleCrop=!1,this.drawCropSelectionImage(t,!1),0!==this.degree&&(this.rotatePan(),this.destLeft=t.destPoints.startX,this.destTop=t.destPoints.startY,this.totalPannedClientPoint=e.extend({},t.totalPannedClientPoint,{},!0),this.totalPannedInternalPoint=e.extend({},t.totalPannedInternalPoint,{},!0)),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",null,null,null,!0);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",null,null,null,!0));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",null,null,null,!0),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=o,e.isNullOrUndefined(s)?this.currSelectionPoint=null:this.currSelectionPoint=e.extend({},s,{},!0)},d.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},d.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}},d.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}},d.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},d.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))},d.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){var 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){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}},d.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},d.prototype.getCurrentPanRegion=function(){var t="";this.rotateFlipColl=this.alignRotateFlipColl(this.rotateFlipColl,!0);for(var e=0;e<this.rotateFlipColl.length;e++)t=this.setCurrentPanRegion(t,this.rotateFlipColl[e]);return t},d.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;var s=this.lowerContext.filter;this.lowerContext.filter="none",this.panObjColl(t.x,t.y,""),this.panFreehandDrawColl(t.x,t.y,""),this.lowerContext.filter=s,this.isCircleCrop&&this.cropCircle(this.lowerContext,null,!0)},d.prototype.drawPannedImage=function(t,i){var s={startPoint:this.panDown,endPoint:this.panMove,cancel:!1};if(this.trigger("panning",s),!s.cancel){var o=!1;if(e.isNullOrUndefined(this.activeObj.shape)||"shape"!==this.activeObj.shape||this.refreshActiveObj(),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))}},d.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)}},d.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)},d.prototype.resetPanPoints=function(){this.totalPannedPoint={x:0,y:0},this.totalPannedClientPoint={x:0,y:0},this.totalPannedInternalPoint={x:0,y:0}},d.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.zoomAction(-.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}},d.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(var a=0;a<o;a++)this.rotateObjColl(),this.rotateFreehandDrawColl();var n=e.extend({},this.objColl[this.objColl.length-1],{},!0);if(""!==this.currFlipState){for(a=0;a<this.objColl.length;a++)this.objColl[a].shapeFlip="";for(a=0;a<this.freehandCounter;a++)this.pointColl[a].shapeFlip="";var r=this.getCurrentCropState("initial");this.redrawObj(r),this.flipFreehandrawColl(r)}this.zoomObjColl(),this.zoomFreehandDrawColl(),n=e.extend({},this.objColl[this.objColl.length-1],{},!0),this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),this.drawObject("duplicate",n),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(a=0;a<o;a++)this.rotateObjColl(),this.rotateFreehandDrawColl();if(""!==this.getCurrentPanRegion()){for(a=0;a<this.objColl.length;a++)this.objColl[a].shapeFlip="";for(a=0;a<this.freehandCounter;a++)this.pointColl[a].shapeFlip="";r=this.getCurrentCropState("reverse");this.redrawObj(r),this.flipFreehandrawColl(r)}this.isReverseRotate=!1,"crop-circle"===t&&this.cropCircle(this.lowerContext),this.lowerContext.filter="none";for(a=0;a<this.objColl.length;a++)this.isObjInsideCropRegion(this.objColl[a])&&(this.apply(this.objColl[a].shape,this.objColl[a]),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()},d.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},d.prototype.isInitialRotate=function(){var t=!1;return this.rotateFlipColl.length>0&&"number"==typeof this.rotateFlipColl[0]&&(t=!0),t},d.prototype.updateRotatePanPoints=function(){if(!e.isNullOrUndefined(this.currentPannedPoint)){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))}},d.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},d.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},d.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)},d.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},d.prototype.updateCanvas=function(){var t={fileName:this.fileName,fileType:this.fileType};this.srcWidth=this.baseImg.width,this.srcHeight=this.baseImg.height;var i=this.calcMaxDimension(this.srcWidth,this.srcHeight);this.destLeft=(this.lowerCanvas.clientWidth-i.width)/2,this.destTop=(this.lowerCanvas.clientHeight-i.height)/2,this.drawImgToCanvas(i),this.cropDestPoints={startX:this.destLeft,startY:this.destTop,width:this.destWidth,height:this.destHeight};var s=this.lowerContext.filter;this.lowerContext.filter="none",this.iterateObjColl(),this.zoomFreehandDrawColl(),this.lowerContext.filter=s,this.destWidth>0&&this.destHeight>0&&(this.isImageLoaded=!0),this.isUndoRedo&&""!==this.currFlipState&&this.flipImage(this.toPascalCase(this.currFlipState)),this.disabled&&this.element.setAttribute("class","e-disabled"),this.isImageLoaded&&"0.5"!==this.element.style.opacity&&this.trigger("fileOpened",t),1===this.zoomSettings.zoomFactor&&e.isNullOrUndefined(this.zoomSettings.zoomPoint)||this.zoom(this.zoomSettings.zoomFactor,this.zoomSettings.zoomPoint),e.isNullOrUndefined(this.initialZoomValue)&&(this.initialZoomValue=this.zoomSettings.zoomFactor)},d.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=i.isErrorImage=!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))},this.baseImg.onerror=function(){a.hideSpinner(i.element),i.isErrorImage=!0}},d.prototype.refreshActiveObj=function(){this.activeObj={},this.activeObj.activePoint={startX:0,startY:0,endX:0,endY:0,width:0,height:0},this.activeObj.triangle=[],this.activeObj.triangleRatio=[],this.activeObj.flipObjColl=[],this.activeObj.strokeSettings=this.strokeSettings,this.activeObj.textSettings=this.textSettings},d.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)},d.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)},d.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:"",zoomFactor:0,previousZoomValue:0,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.zoomFactor=this.zoomSettings.zoomFactor,t.previousZoomValue=this.previousZoomValue,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},d.prototype.updateUndoRedoColl=function(t,i,s,o,a,n,r,h,l){if(!this.isInitialLoading&&this.allowUndoRedo){var c=this.getCurrentObj();c.objColl=e.extend([],this.objColl,[],!0),c.pointColl=e.extend([],this.pointColl,[],!0),c.afterCropActions=e.extend([],this.afterCropActions,[],!0),this.undoRedoColl.push({operation:t,previousObj:i,currentObj:c,previousObjColl:s,currentObjColl:c.objColl,previousPointColl:o,currentPointColl:c.pointColl,previousCropObj:a,currentCropObj:e.extend({},this.cropObj,{},!0),previousText:n,currentText:r,filter:h,isCircleCrop:l}),this.enableDisableToolbarBtn()}},d.prototype.fileSelect=function(t,i){if(!this.disabled){var s=i.target.files[0],o=s;if(!e.isNullOrUndefined(o.name.split("."))&&!e.isNullOrUndefined(o.name.split(".")[1])&&"jpg"!==o.name.split(".")[1].toLowerCase()&&"jpeg"!==o.name.split(".")[1].toLowerCase()&&"png"!==o.name.split(".")[1].toLowerCase()&&"svg"!==o.name.split(".")[1].toLowerCase())return;if(a.showSpinner(this.element),this.element.style.opacity="0.5",e.isNullOrUndefined(o.name.split("."))||e.isNullOrUndefined(o.name.split(".")[1]))this.fileType=null;else{var n=this.toPascalCase(o.name.split(".")[1]);this.fileType="JPG"===n||"Jpg"===n?"Jpeg":n}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 r=window.URL.createObjectURL(s);this.imageOnLoad(r.toString()),t.value=""}},d.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)}},d.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},d.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)}},d.prototype.setTimer=function(t){this.timer>10&&(clearTimeout(this.timer),this.timer=0,this.findTextPoint(t),e.Browser.isDevice&&this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height))},d.prototype.targetTouches=function(t){var e=this.lowerCanvas.getBoundingClientRect();return[{x:t[0].pageX-e.left,y:t[0].pageY-e.top},{x:t[1].pageX-e.left,y:t[1].pageY-e.top}]},d.prototype.calculateScale=function(t,e){var i=this.getDistance(t[0],t[1]);return this.getDistance(e[0],e[1])/i},d.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)},d.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}},d.prototype.touchStartHandler=function(t){t.preventDefault(),2===t.touches.length?this.isFirstMove=!0: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)},d.prototype.getCurrentIndex=function(){for(var t,e=0;e<this.objColl.length;e++)if(this.activeObj.currIndex===this.objColl[e].currIndex){t=e;break}return t},d.prototype.isShapeClick=function(t,i){var s=!1;if(this.togglePen)return s;if(!e.isNullOrUndefined(this.activeObj.shape)&&"text"===this.activeObj.shape&&this.isShapeInserted){var o="block"===this.textArea.style.display,a=e.extend({},this.activeObj,null,!0);this.redrawActObj(null,null,!0);var n=this.setXYPoints(t),r=n.x,h=n.y;if(s=this.findTargetObj(r,h,i),i||this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),o){this.textArea.value=this.objColl[this.objColl.length-1].keyHistory,this.textArea.style.display="block",this.activeObj=a;var l=this.getCurrentIndex();e.isNullOrUndefined(l)?this.objColl.pop():this.objColl.splice(l,1)}else if(!s&&!e.isNullOrUndefined(a.shape)){this.activeObj=a;l=this.getCurrentIndex();e.isNullOrUndefined(l)||JSON.stringify(this.activeObj.activePoint)!==JSON.stringify(this.objColl[l].activePoint)?e.isNullOrUndefined(this.activeObj.currIndex)&&this.objColl.pop():this.objColl.splice(l,1)}}return s},d.prototype.isShapeTouch=function(t,i){var s=!1;if("touchstart"===t.type&&!this.togglePen){e.isNullOrUndefined(this.activeObj)||"text"!==this.activeObj.shape||(this.timer=setTimeout(this.setTimer.bind(this),1e3,t));var o="block"===this.textArea.style.display,a=e.extend({},this.activeObj,null,!0);this.redrawActObj(null,null,!0);var n=this.setXYPoints(t),r=n.x,h=n.y;if(s=this.findTargetObj(r,h,i),i||this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),o){this.textArea.value=this.objColl[this.objColl.length-1].keyHistory,this.textArea.style.display="block",this.activeObj=a;var l=this.getCurrentIndex();e.isNullOrUndefined(l)?this.objColl.pop():this.objColl.splice(l,1)}else if(!s&&!e.isNullOrUndefined(a.shape)){this.activeObj=a;l=this.getCurrentIndex();e.isNullOrUndefined(l)||JSON.stringify(this.activeObj.activePoint)!==JSON.stringify(this.objColl[l].activePoint)?e.isNullOrUndefined(this.activeObj.currIndex)&&this.objColl.pop():this.objColl.splice(l,1)}}return s},d.prototype.isFreehandDrawTouch=function(t,i){var s=!1;if("touchstart"===t.type&&!i&&!this.togglePen){var o="block"===this.textArea.style.display,a=e.extend({},this.activeObj,null,!0);this.redrawActObj(null,null,!0);var n=this.setXYPoints(t),r=n.x,h=n.y;if(this.setCursor(r,h),this.isFreehandDrawingPoint&&(s=!0),o){this.textArea.value=this.objColl[this.objColl.length-1].keyHistory,this.textArea.style.display="block",this.activeObj=a;var l=this.getCurrentIndex();e.isNullOrUndefined(l)?this.objColl.pop():this.objColl.splice(l,1)}if(!e.isNullOrUndefined(a.shape)){this.activeObj=a;l=this.getCurrentIndex();e.isNullOrUndefined(l)||JSON.stringify(this.activeObj.activePoint)!==JSON.stringify(this.objColl[l].activePoint)?e.isNullOrUndefined(this.activeObj.currIndex)&&this.objColl.pop():this.objColl.splice(l,1)}}return s},d.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.activeObj.strokeSettings.strokeColor=this.tempFreeHandDrawEditingStyles.strokeColor=this.pointColl[this.freehandDrawHoveredIndex].strokeColor),this.activeObj.strokeSettings.strokeWidth=this.tempFreeHandDrawEditingStyles.strokeWidth=this.pointColl[this.freehandDrawHoveredIndex].strokeWidth,this.isFreehandDrawEditing?this.refreshToolbar("pen"):this.okBtn()},d.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.refreshMainToolbar(),t=!0),t},d.prototype.applyObj=function(t,i){var s=!1;return e.isNullOrUndefined(this.activeObj.shape)||"rectangle"!==this.activeObj.shape&&"ellipse"!==this.activeObj.shape&&"text"!==this.activeObj.shape&&"line"!==this.activeObj.shape&&"arrow"!==this.activeObj.shape||(s=!(t>=this.activeObj.activePoint.startX-2*this.activeObj.topLeftCircle.radius&&t<=this.activeObj.activePoint.endX+2*this.activeObj.topLeftCircle.radius&&i>=this.activeObj.activePoint.startY-2*this.activeObj.topLeftCircle.radius&&i<=this.activeObj.activePoint.endY+2*this.activeObj.topLeftCircle.radius)),s},d.prototype.applyCurrShape=function(t){var i=!1;if(this.togglePen)return i;var s=e.extend({},this.activeObj,null,!0);if(this.isShapeInserted&&"text"===this.activeObj.shape&&t&&(this.isInitialTextEdited=this.isShapeTextInserted=!0),"block"===this.textArea.style.display){var o=e.extend({},this.activeObj,null,!0);this.redrawActObj(),s=e.extend({},this.objColl[this.objColl.length-1],null,!0),this.objColl.pop(),this.activeObj=e.extend({},o,null,!0),this.textArea.value=s.keyHistory,this.textArea.style.display="block";var a="rgb"===s.strokeSettings.strokeColor.split("(")[0]?this.rgbToHex(parseFloat(s.strokeSettings.strokeColor.split("(")[1].split(",")[0]),parseFloat(s.strokeSettings.strokeColor.split("(")[1].split(",")[1]),parseFloat(s.strokeSettings.strokeColor.split("(")[1].split(",")[2])):s.strokeSettings.strokeColor;"#ffffff"===a&&(a="#fff"),"#ffffff"===this.tempActiveObj.strokeSettings.strokeColor&&(this.tempActiveObj.strokeSettings.strokeColor="#fff"),s.keyHistory===this.tempActiveObj.keyHistory&&a===this.tempActiveObj.strokeSettings.strokeColor&&s.textSettings.fontFamily===this.tempActiveObj.textSettings.fontFamily&&Math.round(s.textSettings.fontSize)===Math.round(this.tempActiveObj.textSettings.fontSize)&&Math.round(s.textSettings.fontRatio)===Math.round(this.tempActiveObj.textSettings.fontRatio)&&s.textSettings.bold===this.tempActiveObj.textSettings.bold&&s.textSettings.italic===this.tempActiveObj.textSettings.italic&&s.textSettings.underline===this.tempActiveObj.textSettings.underline||(i=!0),this.isInitialTextEdited&&!i&&(i=!0,this.isInitialTextEdited=!1)}else i=JSON.stringify(s)!==JSON.stringify(this.tempActiveObj);return i},d.prototype.mouseDownEventHandler=function(t){if("touchstart"===t.type?this.isTouch=!0:this.isTouch=!1,"touchstart"!==t.type||t.currentTarget!==this.lowerCanvas||this.isImageLoaded){var i,s=!1,o=!0;void 0!==this.activeObj.shape&&(i=this.activeObj.shape.split("-")),void 0!==i&&"crop"===i[0]&&(s=!0),s&&(this.dragCanvas=this.togglePan=!0);var a={point:this.setXYPoints(t)};this.trigger("click",a);var n=a.point.x,r=a.point.y;s&&this.dragCanvas&&(this.setCursor(n,r),"move"!==this.upperCanvas.style.cursor&&"crosshair"!==this.upperCanvas.style.cursor&&"default"!==this.upperCanvas.style.cursor&&"grab"!==this.upperCanvas.style.cursor&&(o=!1)),e.isNullOrUndefined(this.activeObj.shape)?this.isObjSelected=!1:this.isObjSelected=!0;var h=this.getCurrentObj(),l=e.extend({},this.activeObj,null,!0),c=this.isShapeTouch(t,s),d=this.isFreehandDrawTouch(t,s),p=c||this.isShapeClick(t,s),v=this.applyCurrShape(p);if(this.isTouch&&!c&&!e.isNullOrUndefined(l.shape)&&!s){this.applyObj(n,r)&&(this.okBtn(!0),this.prevActObj=null);var u=e.extend({},this.cropObj,{},!0);this.updateUndoRedoColl("shapeTransform",h,h.objColl,h.pointColl,u),v&&this.updateCurrentUndoRedoColl("ok")}if(c||this.togglePen||s||(this.refreshMainToolbar(),this.closeContextualToolbar()),!this.dragCanvas||!o||"grab"!==this.upperCanvas.style.cursor&&!this.isTouch||c||d||this.togglePen){var b=this.setXYPoints(t),C=b.x,f=b.y;if(this.applyObj(C,f)&&(this.okBtn(!0),v&&this.updateCurrentUndoRedoColl("ok"),this.prevActObj=null),this.redrawActObj(C,f,!0),this.isFreehandDrawingPoint||this.isFreehandDrawCustomized&&!this.togglePen){if(!e.isNullOrUndefined(this.freehandDrawSelectedIndex)&&this.freehandDrawSelectedIndex!==this.freehandDrawHoveredIndex){var g=this.freehandDrawHoveredIndex;if(this.okBtn(),this.isFreehandDrawCustomized=!1,this.freehandDrawHoveredIndex=g,this.freehandDrawHoveredIndex>-1){var j=this.pointColl[this.freehandDrawHoveredIndex].strokeColor;this.hoverFreehandraw(j,this.pointColl[this.freehandDrawHoveredIndex].strokeWidth)}}if(!e.isNullOrUndefined(this.freehandDrawHoveredIndex)&&this.freehandDrawHoveredIndex>-1)this.selectFreehandDraw(),this.renderQuickAccessToolbar(!0);else if(this.freehandDrawSelectedIndex){this.okBtn();j=this.pointColl[this.freehandDrawSelectedIndex].strokeColor;this.hoverFreehandraw(j,this.pointColl[this.freehandDrawSelectedIndex].strokeWidth)}}else this.isFreehandDrawEditing&&(this.cancelFreehandDraw(),e.isNullOrUndefined(document.getElementById(this.element.id+"_quickAccessToolbarArea"))||(document.getElementById(this.element.id+"_quickAccessToolbarArea").style.display="none")),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(C,f,t.type)):""!==this.currObjType.shape&&!this.currObjType.isCustomCrop||this.togglePen||"default"===this.upperCanvas.style.cursor||this.setActivePoint(C,f)}else this.applyObj(n,r)&&(this.okBtn(!0),v&&this.updateCurrentUndoRedoColl("ok"),this.prevActObj=null),this.isFreehandDrawEditing&&this.applyFreehandDraw(),this.applyShape(),this.canvasMouseDownHandler(t);this.isShapeInserted=!1,this.tempActiveObj=e.extend({},this.activeObj,{},!0)}},d.prototype.mouseMoveEventHandler=function(i){i.preventDefault();var s=this.lowerCanvas.getBoundingClientRect();if("touchmove"!==i.type||2!==i.touches.length){var o,a;"mousemove"===i.type?(o=i.clientX,a=i.clientY):(this.touchEndPoint.x=o=i.touches[0].clientX,this.touchEndPoint.y=a=i.touches[0].clientY),o-=s.left,a-=s.top,this.canvasMouseMoveHandler(i);var n,r=!1;void 0!==this.activeObj.shape&&(n=this.activeObj.shape.split("-")),void 0!==n&&"crop"===n[0]&&(r=!0),r&&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(o,a),e.isNullOrUndefined(this.activeObj.activePoint)||0!==this.activeObj.activePoint.width&&(e.isNullOrUndefined(this.activeObj.currIndex)||this.cursorTargetObjId===this.activeObj.currIndex)||"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(o,a,i.type)),this.currObjType.isDragging&&(this.upperContext.clearRect(0,0,this.lowerCanvas.width,this.lowerCanvas.height),this.updateActivePoint(o,a,r),this.updateTrianglePoints(this.activeObj),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"),r&&(this.dragCanvas=this.togglePan=!0))}else{if(this.isFirstMove)this.startTouches=this.targetTouches(i.touches),this.tempTouches=[],this.tempTouches.push({x:i.touches[0].clientX||i.touches[0].pageX-this.lowerCanvas.offsetLeft-s.left,y:(i.touches[0].clientY||i.touches[0].pageY-this.lowerCanvas.offsetTop)-s.top}),this.tempTouches.push({x:(i.touches[1].clientX||i.touches[1].pageX-this.lowerCanvas.offsetLeft)-s.left,y:(i.touches[1].clientY||i.touches[1].pageY-this.lowerCanvas.offsetTop)-s.top});else{var h=(i.touches[0].clientX||i.touches[0].pageX-this.lowerCanvas.offsetLeft)-s.left,l=(i.touches[0].clientY||i.touches[0].pageY-this.lowerCanvas.offsetTop)-s.top,c=(i.touches[1].clientX||i.touches[1].pageX-this.lowerCanvas.offsetLeft)-s.left,d=(i.touches[1].clientY||i.touches[1].pageY-this.lowerCanvas.offsetTop)-s.top,p={x:h<c?c-(c-h)/2:h-(h-c)/2,y:l<d?d-(d-l)/2:l-(l-d)/2};if(this.currentMouseMovePoint.x!==p.x&&this.currentMouseMovePoint.y!==p.y){var v="";if("touchmove"===i.type&&(this.zoomSettings.zoomTrigger&t.ZoomTrigger.Pinch)===t.ZoomTrigger.Pinch){this.zoomType="Pinch";var u=this.calculateScale(this.startTouches,this.targetTouches(i.touches));this.startTouches=this.targetTouches(i.touches),u>1?v="zoomIn":u<1&&(v="zoomOut")}""!==v&&this.performPointZoom(p.x,p.y,v),this.tempTouches=[],this.tempTouches.push({x:i.touches[0].clientX||i.touches[0].pageX-this.lowerCanvas.offsetLeft,y:i.touches[0].clientY||i.touches[0].pageY-this.lowerCanvas.offsetTop}),this.tempTouches.push({x:i.touches[1].clientX||i.touches[1].pageX-this.lowerCanvas.offsetLeft,y:i.touches[1].clientY||i.touches[1].pageY-this.lowerCanvas.offsetTop}),this.currentMouseMovePoint.x=p.x,this.currentMouseMovePoint.y=p.y}}this.isFirstMove=!1}},d.prototype.mouseUpEventHandler=function(t){"touchstart"===t.type?this.isTouch=!1:"touchend"===t.type&&t.stopImmediatePropagation(),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.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();if(h.objColl=e.extend([],this.objColl,[],!0),h.pointColl=e.extend([],this.pointColl,[],!0),h.afterCropActions=e.extend([],this.afterCropActions,[],!0),this.togglePen||n||(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)),!e.isNullOrUndefined(this.activeObj)){var l,c=!1;void 0!==this.activeObj.shape&&(l=this.activeObj.shape.split("-")),void 0===l&&(this.currObjType.isCustomCrop||this.togglePen)?c=!0:void 0!==l&&"crop"===l[0]&&(c=!0),"rectangle"===this.activeObj.shape||"ellipse"===this.activeObj.shape||"line"===this.activeObj.shape||"arrow"===this.activeObj.shape?this.refreshToolbar("shapes"):"text"===this.activeObj.shape?this.refreshToolbar("text"):this.isFreehandDrawEditing?this.refreshToolbar("pen"):c||this.callMainToolbar(),this.updateToolbarItems()}}void 0!==this.activeObj.shape&&(a=this.activeObj.shape.split("-")),void 0!==a&&"crop"===a[0]&&(n=!0),e.isNullOrUndefined(this.activeObj.shape)||n||t.currentTarget!==this.upperCanvas||"none"!==this.textArea.style.display||("text"===this.activeObj.shape?this.refreshToolbar("text"):this.refreshToolbar("shapes"),this.updateToolbarItems(),this.renderQuickAccessToolbar()),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},d.prototype.getSquarePointForFreehandDraw=function(t){var i={startX:0,startY:0,endX:0,endY:0,width:0,height:0},s=e.extend([],this.selPointColl[t].points,[]);this.points=e.extend([],this.pointColl[t].points),this.pointCounter=0;for(var o=s.length,a=0;a<o;a++)0===i.startX&&0===i.startY&&0===i.endX&&0===i.endY&&(i.startX=s[a].x,i.startY=s[a].y,i.endX=s[a].x,i.endY=s[a].y),s[a].x<i.startX&&(i.startX=s[a].x),s[a].y<i.startY&&(i.startY=s[a].y),s[a].x>i.endX&&(i.endX=s[a].x),s[a].y>i.endY&&(i.endY=s[a].y);return i.startX-=this.penStrokeWidth,i.startY-=this.penStrokeWidth,i.endX+=this.penStrokeWidth,i.endY+=this.penStrokeWidth,i.width=i.endX-i.startX,i.height=i.endY-i.startY,i},d.prototype.getQuickAccessToolbarItem=function(t){var i={cancel:!1,toolbarItems:[]},s=[];e.isNullOrUndefined(t)?(s.push("Clone"),s.push("Delete"),"text"===this.activeObj.shape&&s.push("EditText")):t&&s.push("Remove"),i.toolbarItems=e.extend([],s,null,!0),this.trigger("quickAccessToolbarOpening",i);var o=[];if(i.cancel)o=[];else for(var a=0;a<i.toolbarItems.length;a++)"Clone"===i.toolbarItems[a]?o.push({id:this.element.id+"_duplicate",prefixIcon:"e-icons e-order",cssClass:"top-icon e-order",tooltipText:this.l10n.getConstant("Duplicate"),align:"Left"}):"Delete"===i.toolbarItems[a]?o.push({id:this.element.id+"_remove",prefixIcon:"e-icons e-trash",cssClass:"top-icon e-trash",tooltipText:this.l10n.getConstant("Remove"),align:"Left"}):"EditText"===i.toolbarItems[a]?o.push({id:this.element.id+"_editText",prefixIcon:"e-icons e-annotation-edit",cssClass:"top-icon e-annotation-edit",tooltipText:this.l10n.getConstant("EditText"),align:"Left"}):o.push(i.toolbarItems[a]);return o},d.prototype.renderQuickAccessToolbar=function(t){if(!e.isNullOrUndefined(this.activeObj)&&this.showQuickAccessToolbar){var s=document.getElementById(this.element.id+"_quickAccessToolbarArea");e.isNullOrUndefined(document.getElementById(this.element.id+"_quickAccessToolbarArea"))||(document.getElementById(this.element.id+"_quickAccessToolbarArea").style.display="block");var o=this.getQuickAccessToolbarItem(t);if(0===o.length)return;if(new i.Toolbar({items:o,clicked:this.defToolbarClicked.bind(this)},"#"+this.element.id+"_quickAccessToolbar"),e.isNullOrUndefined(t))s.style.left=this.activeObj.activePoint.startX+this.activeObj.activePoint.width/2-50+"px",s.style.top=this.activeObj.activePoint.startY-50+"px";else if(t){var a=this.getSquarePointForFreehandDraw(this.freehandDrawSelectedIndex);s.style.left=a.startX+a.width/2-25+"px",s.style.top=a.startY-50+"px"}}},d.prototype.deleteItem=function(){var t={};if(this.isFreehandDrawEditing){this.updateFreehandDrawColorChange();var i=e.extend({},this.cropObj,{},!0);(s=this.getCurrentObj()).objColl=e.extend([],this.objColl,[],!0),s.pointColl=e.extend([],this.pointColl,[],!0),s.afterCropActions=e.extend([],this.afterCropActions,[],!0),this.deleteFreehandDraw(parseInt(this.freehandDrawSelectedId.split("_")[1],10)-1,!0),this.updateUndoRedoColl("deleteFreehandDrawing",s,s.objColl,s.pointColl,i),this.updateCurrentUndoRedoColl("ok")}else if("none"===this.textArea.style.display){this.objColl.push(this.activeObj);var s;i=e.extend({},this.cropObj,{},!0);(s=this.getCurrentObj()).objColl=e.extend([],this.objColl,[],!0),s.pointColl=e.extend([],this.pointColl,[],!0),s.afterCropActions=e.extend([],this.afterCropActions,[],!0),this.objColl.pop(),t={action:"delete",previousShapeSettings:this.updatePreviousShapeSettings(),currentShapeSettings:null},this.keyHistory="",this.clearSelection(),this.trigger("shapeChanging",t),this.refreshMainToolbar(),e.isNullOrUndefined(s.objColl[s.objColl.length-1].currIndex)||(this.updateUndoRedoColl("deleteObj",s,s.objColl,s.pointColl,i),this.updateCurrentUndoRedoColl("ok"))}e.isNullOrUndefined(document.getElementById(this.element.id+"_quickAccessToolbarArea"))||(document.getElementById(this.element.id+"_quickAccessToolbarArea").style.display="none")},d.prototype.keyDownEventHandler=function(i){var s=this;!i.ctrlKey||"+"!==i.key&&"-"!==i.key||i.preventDefault();var o,a={fileName:this.fileName,fileType:this.fileType,cancel:!1};switch(i.key){case i.ctrlKey&&"s":this.trigger("beforeSave",a,function(t){a.cancel||s.export(t.fileType,t.fileName)}),i.preventDefault(),i.stopImmediatePropagation();break;case i.ctrlKey&&"z":this.allowUndoRedo&&this.callUndo();break;case i.ctrlKey&&"y":this.allowUndoRedo&&this.callRedo();break;case i.ctrlKey&&"+":(this.zoomSettings.zoomTrigger&t.ZoomTrigger.Commands)===t.ZoomTrigger.Commands&&(this.zoomType="Commands",this.zoomAction(.1));break;case i.ctrlKey&&"-":(this.zoomSettings.zoomTrigger&t.ZoomTrigger.Commands)===t.ZoomTrigger.Commands&&(this.zoomType="Commands",this.zoomAction(-.1));break;case"Delete":this.deleteItem();break;case"Escape":this.performCancel();break;case"Enter":void 0!==this.activeObj.shape&&(o=this.activeObj.shape.split("-")),void 0!==this.activeObj.horTopLine&&void 0!==this.activeObj.shape&&"crop"===o[0]&&this.crop();break;case"Tab":if("block"===this.textArea.style.display){var n=this.applyCurrShape(!1);this.redrawActObj(),n&&this.updateCurrentUndoRedoColl("ok")}break;default:e.Browser.isDevice&&"block"===this.textArea.style.display&&setTimeout(this.textKeyDown.bind(this),1,i)}},d.prototype.keyUpEventHandler=function(t){"block"===this.textArea.style.display&&t.target.id===this.element.id+"_textArea"&&setTimeout(this.textKeyDown.bind(this),1,t)},d.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},e.isNullOrUndefined(this.tempPanMove)&&(this.tempPanMove={x:i,y:s})},d.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()},d.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.currObjType.isDragging=!1},d.prototype.handleScroll=function(e){var i,s,o=!1;"mousewheel"===e.type&&(i=e.clientX,s=e.clientY);var a=this.lowerCanvas.getBoundingClientRect();if(i-=a.left,s-=a.top,i>this.destLeft&&i<this.destLeft+this.destWidth&&s>this.destTop&&s<this.destTop+this.destHeight&&(o=!0),e.stopPropagation(),!0===e.ctrlKey&&o){e.preventDefault(),this.isCropTab||(this.okBtn(),this.closeContextualToolbar());var n="";"mousewheel"===e.type&&(this.zoomSettings.zoomTrigger&t.ZoomTrigger.MouseWheel)===t.ZoomTrigger.MouseWheel&&(this.zoomType="MouseWheel",n=e.wheelDelta>0?"zoomIn":"zoomOut"),""!==n&&this.performPointZoom(i,s,n)}},d.prototype.performPointZoom=function(t,i,s){var o=(t-this.destLeft)/this.destWidth,a=(i-this.destTop)/this.destHeight,n=this.isUndoRedo;if(this.isUndoRedo=!0,this.setProperties({zoomSettings:{zoomPoint:{x:t,y:i}}},!0),"zoomIn"===s?this.zoomAction(.1):"zoomOut"===s&&this.zoomAction(-.1),this.isUndoRedo=n,this.zoomFactor>0){var r=this.destLeft,h=this.destTop,l=e.extend({},this.activeObj,{},!0);if(0===this.degree)this.destLeft=t-o*this.destWidth,this.destTop=i-a*this.destHeight,this.drawZoomPanImage(this.destLeft-r,this.destTop-h);else{var c=this.isCropTab;this.isCropTab=!0;var d=e.extend([],this.objColl,[],!0),p=e.extend([],this.pointColl,[],!0);this.objColl=[],this.pointColl=[],this.freehandCounter=0,this.currentPannedPoint={x:t-o*this.destWidth-r,y:i-a*this.destHeight-h},this.rotatePan(),this.isCropTab=c,this.objColl=d,this.pointColl=p,this.freehandCounter=this.pointColl.length,this.panObjColl(this.currentPannedPoint.x,this.currentPannedPoint.y,""),this.panFreehandDrawColl(this.currentPannedPoint.x,this.currentPannedPoint.y,"")}this.adjustPanning(l),this.activeObj=l,0!==this.activeObj.activePoint.width&&0!==this.activeObj.activePoint.height&&this.drawObject("duplicate",null,null,null,!0)}},d.prototype.adjustPanning=function(t){if(0!==t.activePoint.width&&0!==t.activePoint.height){var i=this.destLeft,s=this.destTop,o={x:0,y:0};if(this.destLeft>t.activePoint.startX?o.x=this.destLeft-t.activePoint.startX:this.destLeft+this.destWidth<t.activePoint.startX+t.activePoint.width&&(o.x=this.destLeft+this.destWidth-(t.activePoint.startX+t.activePoint.width)),this.destTop>t.activePoint.startY?o.y=this.destTop-t.activePoint.startY:this.destTop+this.destHeight<t.activePoint.startY+t.activePoint.height&&(o.y=this.destTop+this.destHeight-(t.activePoint.startY+t.activePoint.height)),0===this.degree)this.destLeft-=o.x,this.destTop-=o.y,this.drawZoomPanImage(this.destLeft-i,this.destTop-s);else{var a=this.isCropTab;this.isCropTab=!0;var n=e.extend([],this.objColl,[],!0),r=e.extend([],this.pointColl,[],!0);this.objColl=[],this.pointColl=[],this.freehandCounter=0,this.destLeft-=o.x,this.destTop-=o.y,this.currentPannedPoint={x:this.destLeft-i,y:this.destTop-s},this.rotatePan(),this.isCropTab=a,this.objColl=n,this.pointColl=r,this.freehandCounter=this.pointColl.length,this.panObjColl(this.currentPannedPoint.x,this.currentPannedPoint.y,""),this.panFreehandDrawColl(this.currentPannedPoint.x,this.currentPannedPoint.y,"")}}},d.prototype.drawZoomPanImage=function(t,e){this.panObjColl(t,e,""),this.panFreehandDrawColl(t,e,""),this.renderImage(!0);var i=this.calcMaxDimension(this.srcWidth,this.srcHeight);i.width+=i.width*this.zoomFactor,i.height+=i.height*this.zoomFactor,this.totalPannedPoint.x+=t,this.totalPannedPoint.y+=e,this.tempFlipPanPoint={x:0,y:0}},d.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()),this.isInitialTextEdited=!1},d.prototype.adjustToScreen=function(){(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.refreshMainToolbar(),this.destroyQuickAccessToolbar()),this.isFreehandDrawEditing&&this.destroyQuickAccessToolbar();var t=!1;void 0!==this.activeObj.shape&&(t=!0,"block"===this.textArea.style.display?(this.redrawActObj(),this.destroyQuickAccessToolbar()):(this.updateImageRatioForActObj(),this.objColl.push(this.activeObj)),this.refreshActiveObj());var i=this.lowerContext.filter;this.update(),this.applyActObj(),this.refreshActiveObj(),this.lowerContext.filter=this.initialAdjustmentValue=i,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 s=document.querySelector("#"+this.element.id+"_canvasWrapper");e.isNullOrUndefined(s)||(s.style.width=this.element.offsetWidth-2+"px",s.style.height=this.element.offsetHeight+"px",e.Browser.isDevice?s.style.height=parseFloat(s.style.height)-2*this.toolbarHeight-3+"px":s.style.height=parseFloat(s.style.height)-this.toolbarHeight-3+"px");var o=this.calcMaxDimension(this.srcWidth,this.srcHeight);if(this.defaultZoomFactor>0&&(o.width+=o.width*this.defaultZoomFactor,o.height+=o.height*this.defaultZoomFactor),this.destLeft=(this.lowerCanvas.clientWidth-o.width)/2,this.destTop=(this.lowerCanvas.clientHeight-o.height)/2,0===this.degree&&""===this.currFlipState)this.defaultZoomFactor>0&&(this.destLeft+=this.totalPannedPoint.x,this.destTop+=this.totalPannedPoint.y),this.drawImgToCanvas(o);else{this.drawImgToCanvas(o),this.updateCurrentTransformedState("initial");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),this.lowerContext.filter=n,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(this.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")}if(this.refreshActiveObj(),this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),t&&(this.activeObj=e.extend({},this.objColl[this.objColl.length-1],null,!0),this.objColl.pop(),this.drawObject("duplicate",this.activeObj),"rectangle"!==this.activeObj.shape&&"ellipse"!==this.activeObj.shape&&"text"!==this.activeObj.shape&&"line"!==this.activeObj.shape&&"arrow"!==this.activeObj.shape||this.renderQuickAccessToolbar()),this.isFreehandDrawEditing&&this.renderQuickAccessToolbar(!0),(0!==this.degree||""!==this.currFlipState)&&this.defaultZoomFactor>0){var r=e.extend({},this.totalPannedPoint,null,!0),h=e.extend({},this.totalPannedInternalPoint,null,!0),l=e.extend({},this.totalPannedClientPoint,null,!0);this.zoomAction(.1),this.zoomAction(-.1),0===this.degree?(this.destLeft+=r.x,this.destTop+=r.y,this.totalPannedPoint=r,this.updateFlipPan()):(this.totalPannedInternalPoint=h,this.totalPannedClientPoint=l,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())},d.prototype.screenOrientation=function(){e.Browser.isDevice&&setTimeout(this.adjustToScreen.bind(this),100)},d.prototype.windowResizeHandler=function(){e.Browser.isDevice||this.adjustToScreen()},d.prototype.alignTextAreaIntoCanvas=function(){var t=this.textArea.value;this.textArea.value="";for(var e=0;e<t.length;e++)this.textArea.value+=t[e],this.textArea.style.height="auto",this.textArea.style.height=this.textArea.scrollHeight+"px",this.setTextBoxWidth()},d.prototype.refreshMainToolbar=function(){"main"!==this.currToolbar&&this.refreshToolbar("main")},d.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||"arrow"===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}},d.prototype.zoomAction=function(t,i){if(!this.disabled&&this.isImageLoaded){if(0===this.zoomFactor&&t<0||this.zoomSettings.zoomFactor>=this.zoomSettings.maxZoomFactor&&t>0||this.zoomSettings.zoomFactor>this.zoomSettings.minZoomFactor&&t<0&&this.disableZoomOutBtn())return void this.zoomBtnMouseUpHandler();if(1===this.previousZoomValue)this.previousZoomValue+=t>0?10*t:10*t/2;else if(this.previousZoomValue>1)this.previousZoomValue+=10*t;else if(this.previousZoomValue<1)for(var s=10*t,o=0;o<Math.abs(s);o++)t>0?this.previousZoomValue*=2:this.previousZoomValue/=2;this.setProperties({zoomSettings:{zoomFactor:this.previousZoomValue}},!0);var a=void 0,n=void 0,r=!1;void 0!==this.activeObj.shape&&("shape"===this.activeObj.shape?this.refreshActiveObj():a=this.activeObj.shape.split("-")),void 0!==a&&"crop"===a[0]?(n=e.extend({},this.activeObj,{},!0),this.isCropTab=!0):e.isNullOrUndefined(this.activeObj.shape)||"crop"===a[0]||(r=!0),e.isNullOrUndefined(i)&&(i=this.isCropTab&&!e.isNullOrUndefined(n)?{x:this.activeObj.activePoint.startX+this.activeObj.activePoint.width/2,y:this.activeObj.activePoint.startY+this.activeObj.activePoint.height/2}:{x:this.lowerCanvas.clientWidth/2,y:this.lowerCanvas.clientHeight/2},"MouseWheel"!==this.zoomType&&"Pinch"!==this.zoomType||(i={x:this.zoomSettings.zoomPoint.x,y:this.zoomSettings.zoomPoint.y}));var h={zoomPoint:i,cancel:!1,previousZoomFactor:this.zoomSettings.zoomFactor-10*t,currentZoomFactor:this.zoomSettings.zoomFactor,zoomTrigger:this.zoomType};if(this.trigger("zooming",h),h.cancel)return;this.closeContextualToolbar(),this.redrawActObj(null,null,!0),this.refreshActiveObj(),this.upperContext.clearRect(0,0,this.lowerCanvas.width,this.lowerCanvas.height),this.lowerContext.filter=this.canvasFilter,this.upperCanvas.style.cursor="default";var l=e.extend([],this.objColl,[],!0);if(this.isCropTab||(0!==this.degree?(this.redrawActObj(),this.currentPannedPoint={x:0,y:0},this.rotatePan(!0,!0)):""!==this.currFlipState&&(this.totalPannedPoint={x:0,y:0}),this.updateObjAndFreeHandDrawColl()),0===this.degree){if(this.drawZoomImgToCanvas(t,n),""!==this.getCurrentPanRegion()){this.tempFlipPanPoint.x+=this.totalPannedPoint.x,this.tempFlipPanPoint.y+=this.totalPannedPoint.y,l=e.extend([],this.objColl,[],!0),this.objColl=[];var c=this.destLeft,d=this.destTop;this.setDestPointsForFlipState(),this.rotatedFlip(),this.destLeft=c,this.destTop=d,this.objColl=l,this.zoomObjColl(),this.zoomFreehandDrawColl(),this.updateObjAndFreeHandDrawColl()}this.zoomSettings.zoomFactor<=this.zoomSettings.minZoomFactor&&!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()){var p=this.lowerContext.filter;this.lowerContext.filter="none",this.zoomObjColl(),this.zoomFreehandDrawColl(),this.lowerContext.filter=p}var v=Math.pow(10,1);if((this.zoomSettings.zoomFactor<=this.zoomSettings.minZoomFactor||Math.round(this.zoomFactor*v)/v==2)&&(clearInterval(this.zoomBtnHold),this.zoomBtnHold=0),""===this.getCurrentPanRegion()){p=this.lowerContext.filter;this.lowerContext.filter="none",this.zoomObjColl(),this.zoomFreehandDrawColl(),this.lowerContext.filter=p}(!e.isNullOrUndefined(this.currSelectionPoint)&&"crop-circle"===this.currSelectionPoint.shape||this.isCircleCrop)&&this.cropCircle(this.lowerContext),this.clearOuterCanvas(this.lowerContext),this.refreshActiveObj(),e.isNullOrUndefined(n)||(this.activeObj=e.extend({},n,{},!0),this.drawObject("duplicate",this.activeObj),this.zoomSettings.zoomFactor<=this.zoomSettings.minZoomFactor&&(this.currSelectionPoint=null)),this.isUndoRedo=!1;var u=document.querySelector("#"+this.element.id+"_zoomOut");!e.isNullOrUndefined(u)&&this.zoomSettings.zoomFactor<=this.zoomSettings.minZoomFactor?(u.classList.add("e-disabled"),u.parentElement.classList.add("e-overlay")):e.isNullOrUndefined(u)||(u.classList.remove("e-disabled"),u.parentElement.classList.remove("e-overlay")),this.autoEnablePan(),e.isNullOrUndefined(n)||(this.activeObj=e.extend({},n,{},!0)),"crop-custom"===this.activeObj.shape&&(this.currObjType.isCustomCrop=!0);var b=this.element.querySelector(".e-img-pan .e-btn");!e.isNullOrUndefined(b)&&this.togglePan?b.classList.add("e-selected-btn"):e.isNullOrUndefined(b)||b.classList.remove("e-selected-btn"),r&&(this.activeObj=e.extend({},this.objColl[this.objColl.length-1],{},!0),this.objColl.pop(),this.drawObject("duplicate",this.activeObj),this.updateToolbarItems(),this.renderQuickAccessToolbar()),this.enableDisableToolbarBtn(),this.zoomType="Toolbar"}},d.prototype.getCurrentZoomFactor=function(t){return.1*(t-this.previousZoomValue)},d.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),e.isNullOrUndefined(i)||(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},d.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},d.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:"text"===o.shape&&""!==this.dragElement&&(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||"arrow"===this.activeObj.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,e.isNullOrUndefined(this.activeObj.shape)||this.apply(),this.clearOuterCanvas(this.lowerContext),this.clearOuterCanvas(this.upperContext),this.isCircleCrop&&this.cropCircle(this.lowerContext)}this.refreshMainToolbar()}},d.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()},d.prototype.setTextBoxStylesToActObj=function(){this.activeObj.textSettings.fontFamily=this.textArea.style.fontFamily,this.activeObj.strokeSettings.strokeColor=""!==this.textArea.style.color?this.rgbToHex(parseFloat(this.textArea.style.color.split("(")[1].split(",")[0]),parseFloat(this.textArea.style.color.split("(")[1].split(",")[1]),parseFloat(this.textArea.style.color.split("(")[1].split(",")[2])):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)},d.prototype.redrawActObj=function(t,e,i){var s;void 0!==this.activeObj.shape&&(s=this.activeObj.shape.split("-")),void 0!==this.activeObj.horTopLine&&void 0!==this.activeObj.shape&&"crop"!==s[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.refreshMainToolbar())):this.applyActObj(i))},d.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},d.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},d.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.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),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;i=(c=this.setTextBoxPoints(l,a,n,i,s)).x,s=c.y}this.renderTextArea(i,s,l)}else this.applyActObj()}}},d.prototype.renderTextArea=function(t,e,i){var s,o=this;(s=0===this.activeObj.shapeDegree?this.degree:this.degree-this.activeObj.shapeDegree)<0&&(s=360+s),this.destroyQuickAccessToolbar(),this.textArea.style.display="block",this.textArea.style.left=t+"px",this.textArea.style.top=e+"px",this.textArea.style.fontFamily=i.textSettings.fontFamily,this.textArea.style.fontSize=i.textSettings.fontSize+"px",this.textArea.style.color=i.strokeSettings.strokeColor,this.textArea.style.fontWeight=i.textSettings.bold?"bold":"normal",this.textArea.style.fontStyle=i.textSettings.italic?"italic":"normal",this.textArea.style.border="2px solid "+this.themeColl[this.theme].primaryColor,this.textArea.value=i.keyHistory,this.textArea.style.overflow="hidden",this.textArea.style.width="auto",this.textArea.style.height="auto",this.textArea.focus(),s%90==0&&s%180!=0&&0!==s?(this.zoomFactor,this.textArea.style.width=i.activePoint.height+"px",this.textArea.style.height=i.activePoint.width+"px"):(this.zoomFactor,this.textArea.style.width=i.activePoint.width+"px",this.textArea.style.height=i.activePoint.height+"px"),this.setTextBoxWidth(),this.flipColl.length<=1&&this.setTextBoxHeight(),s%90==0&&s%180!=0?parseFloat(this.textArea.style.left)+parseFloat(this.textArea.style.width)>this.destTop+this.destHeight&&this.alignTextAreaIntoCanvas():parseFloat(this.textArea.style.left)+parseFloat(this.textArea.style.width)>this.destLeft+this.destWidth&&this.alignTextAreaIntoCanvas(),this.isTouch&&setTimeout(function(){o.upperContext.clearRect(0,0,o.upperCanvas.width,o.upperCanvas.height)},550)},d.prototype.selectedText=function(){var t=this.textArea.selectionStart,e=this.textArea.selectionEnd;return this.textArea.value.substring(t,e)},d.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")},d.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.destHeight-(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")))},d.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}},d.prototype.setDragWidth=function(t){var e=t;if(e>=0)for(var 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(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},d.prototype.setDragHeight=function(t){var e=t;if(e>=0)for(var 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(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},d.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))},d.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.updateArrowDirection(this.activeObj),this.triggerShapeChange(a,n,"resize");break;case"n-resize":this.updateNPoints(t,e),this.updateArrowDirection(this.activeObj),this.triggerShapeChange(a,n,"resize");break;case"ne-resize":this.updateNEPoints(t,e,s),this.updateArrowDirection(this.activeObj),this.triggerShapeChange(a,n,"resize");break;case"w-resize":this.updateWPoints(t,e),this.updateArrowDirection(this.activeObj),this.triggerShapeChange(a,n,"resize");break;case"e-resize":this.updateEPoints(t,e),this.updateArrowDirection(this.activeObj),this.triggerShapeChange(a,n,"resize");break;case"sw-resize":this.updateSWPoints(t,e,s),this.updateArrowDirection(this.activeObj),this.triggerShapeChange(a,n,"resize");break;case"s-resize":this.updateSPoints(t,e),this.updateArrowDirection(this.activeObj),this.triggerShapeChange(a,n,"resize");break;case"se-resize":this.updateSEPoints(t,e,s),this.updateArrowDirection(this.activeObj),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")}}},d.prototype.updateArrowDirection=function(t,i,s){"arrow"===t.shape&&(t.activePoint.width<0||t.activePoint.height<0||"horizontal"===i||"vertical"===i||90===s)&&("left"===t.triangleDirection&&(t.activePoint.width<0||"horizontal"===i)?t.triangleDirection="right":"right"===t.triangleDirection&&(t.activePoint.width<0||"horizontal"===i)?t.triangleDirection="left":"top"===t.triangleDirection&&(t.activePoint.height<0||"vertical"===i)?t.triangleDirection="bottom":"bottom"===t.triangleDirection&&(t.activePoint.height<0||"vertical"===i)&&(t.triangleDirection="top"),e.isNullOrUndefined(s)||90!==s||("right"===t.triangleDirection?t.triangleDirection="bottom":"bottom"===t.triangleDirection?t.triangleDirection="left":"left"===t.triangleDirection?t.triangleDirection="top":"top"===t.triangleDirection&&(t.triangleDirection="right")))},d.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))},d.prototype.preventTextDraggingInvertly=function(){var t=!1;return 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)&&(t=!0),t},d.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.preventTextDraggingInvertly()&&(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){var 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){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);var v=this.getScaleRatio(n);this.activeObj.activePoint.startX+=v.x,this.activeObj.activePoint.startY+=v.y;var u=this.destLeft>0?this.destLeft:0,b=this.destTop>0?this.destTop:0;(this.activeObj.activePoint.startX<u||this.activeObj.activePoint.startY<b)&&(this.activeObj.activePoint.startX-=v.x,this.activeObj.activePoint.startY-=v.y)}else{o=this.activeObj.activePoint.startX-t,a=i-this.activeObj.activePoint.endY,n=Math.max(o,a);v=this.getScaleRatio(n);this.activeObj.activePoint.startX-=v.x,this.activeObj.activePoint.startY-=v.y;u=this.destLeft>0?this.destLeft:0;var C=this.destTop>0?this.destTop:0;(this.activeObj.activePoint.startX<u||this.activeObj.activePoint.startY<C)&&(this.activeObj.activePoint.startX+=v.x,this.activeObj.activePoint.startY+=v.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)}},d.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);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)}else{i=t-this.activeObj.activePoint.endX,s=this.activeObj.activePoint.startY-e,o=Math.max(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)}this.activeObj.activePoint.width=this.activeObj.activePoint.endX-this.activeObj.activePoint.startX,this.activeObj.activePoint.height=this.activeObj.activePoint.endY-this.activeObj.activePoint.startY}}},d.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.preventTextDraggingInvertly()&&(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){var 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){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);var v=this.getScaleRatio(n);this.activeObj.activePoint.endX-=v.x,this.activeObj.activePoint.startY+=v.y;var u=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>u||this.activeObj.activePoint.startY<b)&&(this.activeObj.activePoint.endX+=v.x,this.activeObj.activePoint.startY-=v.y)}else{o=t-this.activeObj.activePoint.endX,a=this.activeObj.activePoint.startY-i,n=Math.max(o,a);v=this.getScaleRatio(n);this.activeObj.activePoint.endX+=v.x,this.activeObj.activePoint.startY-=v.y;u=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>u||this.activeObj.activePoint.startY<b)&&(this.activeObj.activePoint.endX-=v.x,this.activeObj.activePoint.startY+=v.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)}},d.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);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)}else{i=this.activeObj.activePoint.startX-t,s=e-this.activeObj.activePoint.endY,o=Math.max(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)}this.activeObj.activePoint.width=this.activeObj.activePoint.endX-this.activeObj.activePoint.startX,this.activeObj.activePoint.height=this.activeObj.activePoint.endY-this.activeObj.activePoint.startY}}},d.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);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)}else{i=t-this.activeObj.activePoint.endX,s=e-this.activeObj.activePoint.endY,o=Math.max(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)}this.activeObj.activePoint.width=this.activeObj.activePoint.endX-this.activeObj.activePoint.startX,this.activeObj.activePoint.height=this.activeObj.activePoint.endY-this.activeObj.activePoint.startY}}},d.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.preventTextDraggingInvertly()&&(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){var 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){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);var v=this.getScaleRatio(n);this.activeObj.activePoint.startX+=v.x,this.activeObj.activePoint.endY-=v.y;var u=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<u||this.activeObj.activePoint.endY>b)&&(this.activeObj.activePoint.startX-=v.x,this.activeObj.activePoint.endY+=v.y)}else{o=this.activeObj.activePoint.startX-t,a=i-this.activeObj.activePoint.endY,n=Math.max(o,a);v=this.getScaleRatio(n);this.activeObj.activePoint.startX-=v.x,this.activeObj.activePoint.endY+=v.y;u=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<u||this.activeObj.activePoint.endY>b)&&(this.activeObj.activePoint.startX+=v.x,this.activeObj.activePoint.endY-=v.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)}},d.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);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)}else{i=t-this.activeObj.activePoint.endX,s=e-this.activeObj.activePoint.endY,o=Math.max(i,s);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}}},d.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.preventTextDraggingInvertly()&&(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){var 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){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);var v=this.getScaleRatio(n);this.activeObj.activePoint.endX-=v.x,this.activeObj.activePoint.endY-=v.y;var u=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>u||this.activeObj.activePoint.endY>b)&&(this.activeObj.activePoint.endX+=v.x,this.activeObj.activePoint.endY+=v.y)}else{o=t-this.activeObj.activePoint.endX,a=i-this.activeObj.activePoint.endY,n=Math.max(o,a);v=this.getScaleRatio(n);this.activeObj.activePoint.endX+=v.x,this.activeObj.activePoint.endY+=v.y;u=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>u||this.activeObj.activePoint.endY>b)&&(this.activeObj.activePoint.endX-=v.x,this.activeObj.activePoint.endY-=v.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)}},d.prototype.updateFontRatio=function(t,i){var s,o=this.getMaxText(i),a=this.upperContext.measureText(o).width+.5*this.activeObj.textSettings.fontSize,n=this.activeObj.textSettings.fontSize+.25*this.activeObj.textSettings.fontSize;s=0===t.shapeDegree?this.degree:this.degree-t.shapeDegree,e.isNullOrUndefined(i)?t.textSettings.fontRatio=0===s||180===s?a/t.textSettings.fontSize:n/t.textSettings.fontSize:i&&(t.textSettings.fontRatio=a/parseFloat(this.textArea.style.fontSize))},d.prototype.updateFontSize=function(t){var e;e=0===t.shapeDegree?this.degree:this.degree-t.shapeDegree,t.textSettings.fontSize=0===e||180===e||-180===e?t.activePoint.width/t.textSettings.fontRatio:t.activePoint.height/t.textSettings.fontRatio},d.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)},d.prototype.getScaleRatio=function(t){var i={x:t,y:t};if(!e.isNullOrUndefined(this.activeObj.shape)&&"crop-custom"!==this.activeObj.shape&&"crop-circle"!==this.activeObj.shape&&"crop-square"!==this.activeObj.shape){var s=this.activeObj.shape.split("-");if(s.length>1){s=s[1].split(":");var o=t/parseInt(s[1],10);i.x=o*parseInt(s[0],10),i.y=o*parseInt(s[1],10)}}return i},d.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},d.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)},d.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},d.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=""},d.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;var a;(a=0===o.shapeDegree?this.degree:this.degree-o.shapeDegree)<0&&(a=360+a),"arrow"===this.activeObj.shape||"line"===this.activeObj.shape?(t.beginPath(),a%90==0&&a%180!=0?(t.moveTo(o.topCenterCircle.startX,o.topCenterCircle.startY),t.lineTo(o.bottomCenterCircle.startX,o.bottomCenterCircle.startY)):(t.moveTo(o.centerLeftCircle.startX,o.centerLeftCircle.startY),t.lineTo(o.centerRightCircle.startX,o.centerRightCircle.startY)),t.stroke()):(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,a),this.activeObj=e.extend({},o,{},!0)},d.prototype.drawObject=function(t,i,s,o,a,n,r){this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height);var h;"original"===t.toLowerCase()?h=this.lowerContext:"duplicate"===t.toLowerCase()?h=this.upperContext:e.isNullOrUndefined(n)||(h=n),a||e.isNullOrUndefined(this.activeObj.shape)||this.setDragLimit(),this.currObjType.isLine&&"original"!==t&&!i&&this.lineDraw();if("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 l=!1;this.activeObj.shape&&"crop"===this.activeObj.shape.split("-")[0]&&(l=!0),l&&(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)),!e.isNullOrUndefined(r)||h!==this.lowerContext&&h!==this.upperContext||this.drawOuterSelection(h)}this.currObjType.isActiveObj=!0,i?this.drawShapeObj(t,i.shape,n,r):""!==this.keyHistory&&this.currObjType.isText?this.drawShapeObj(t,"text",n,r):this.activeObj.shape?this.drawShapeObj(t,this.activeObj.shape,n,r):this.drawShapeObj(t,void 0,n,r),this.isAllowCropPan&&(this.isAllowCropPan=!1,this.tempPanMove=e.extend({},this.panMove,{},!0),this.currentPannedPoint=this.updatePanPoints(this.getCurrentPanRegion()),this.rotatePan())},d.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))},d.prototype.drawShapeObj=function(t,i,s,o){var a=void 0!==i?i:this.currObjType.shape;this.currObjType.shape=a;var n;"original"===t.toLowerCase()?n=this.lowerContext:"duplicate"===t.toLowerCase()?n=this.upperContext:e.isNullOrUndefined(s)||(n=s),"rectangle"!==this.currObjType.shape.toLowerCase()&&"ellipse"!==this.currObjType.shape.toLowerCase()&&"line"!==this.currObjType.shape.toLowerCase()&&"arrow"!==this.activeObj.shape||(this.activeObj.shape=this.currObjType.shape),n.strokeStyle=this.activeObj.strokeSettings.strokeColor,n.fillStyle="text"===i||"freehanddraw"===i?this.activeObj.strokeSettings.strokeColor:this.activeObj.strokeSettings.fillColor;var r=this.activeObj.activePoint.width/3,h=this.activeObj.activePoint.height/3,l=this.activeObj.activePoint.endX-this.activeObj.activePoint.startX,c=this.activeObj.activePoint.endY-this.activeObj.activePoint.startY;switch(this.currObjType.shape.toLowerCase()){case"rectangle":this.drawSquareLines(n),e.isNullOrUndefined(o)&&n===this.upperContext&&this.drawOuterSelection(n);break;case"ellipse":l=Math.abs(l),c=Math.abs(c),n.beginPath(),n.ellipse(this.activeObj.activePoint.startX+l/2,this.activeObj.activePoint.startY+c/2,l/2,c/2,0,0,2*Math.PI,!1),""!==this.activeObj.strokeSettings.fillColor&&(n.fillStyle=this.activeObj.strokeSettings.fillColor,n.fill()),n.ellipse(this.activeObj.activePoint.startX+l/2,this.activeObj.activePoint.startY+c/2,Math.abs(l/2-this.activeObj.strokeSettings.strokeWidth),Math.abs(c/2-this.activeObj.strokeSettings.strokeWidth),0,0,2*Math.PI,!1),n.fillStyle=this.activeObj.strokeSettings.strokeColor,n.fill("evenodd"),n.closePath(),e.isNullOrUndefined(o)&&n===this.upperContext&&this.drawOuterSelection(n);break;case"crop-circle":n===this.lowerContext&&(n=this.upperContext),this.shapeCircle(n,l,c);break;case"line":case"arrow":this.shapeLine(n,l,c),"arrow"===this.currObjType.shape.toLowerCase()&&this.shapeArrow(n),e.isNullOrUndefined(o)&&n===this.upperContext&&this.drawOuterSelection(n);break;case"text":this.shapeText(n);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":n===this.lowerContext&&(n=this.upperContext),this.drawSelection(r,h),this.currObjType.shape="";break;default:this.drawSelection(r,h)}},d.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},d.prototype.shapeArrow=function(t){var e=t.lineWidth;switch(t.lineWidth=this.activeObj.strokeSettings.strokeWidth,t.beginPath(),t.moveTo(this.activeObj.triangle[0].x,this.activeObj.triangle[0].y),t.lineTo(this.activeObj.triangle[1].x,this.activeObj.triangle[1].y),t.lineTo(this.activeObj.triangle[2].x,this.activeObj.triangle[2].y),t.lineTo(this.activeObj.triangle[0].x,this.activeObj.triangle[0].y),t.fillStyle=t.strokeStyle,t.fill(),this.activeObj.triangleDirection){case"right":t.moveTo(this.activeObj.triangle[0].x,this.activeObj.triangle[0].y-this.activeObj.strokeSettings.strokeWidth),t.lineTo(this.activeObj.triangle[1].x+this.activeObj.strokeSettings.strokeWidth,this.activeObj.triangle[1].y),t.lineTo(this.activeObj.triangle[2].x,this.activeObj.triangle[2].y+this.activeObj.strokeSettings.strokeWidth),t.lineTo(this.activeObj.triangle[0].x,this.activeObj.triangle[0].y-this.activeObj.strokeSettings.strokeWidth);break;case"left":t.moveTo(this.activeObj.triangle[0].x,this.activeObj.triangle[0].y-this.activeObj.strokeSettings.strokeWidth),t.lineTo(this.activeObj.triangle[1].x-this.activeObj.strokeSettings.strokeWidth,this.activeObj.triangle[1].y),t.lineTo(this.activeObj.triangle[2].x,this.activeObj.triangle[2].y+this.activeObj.strokeSettings.strokeWidth),t.lineTo(this.activeObj.triangle[0].x,this.activeObj.triangle[0].y-this.activeObj.strokeSettings.strokeWidth);break;case"top":t.moveTo(this.activeObj.triangle[0].x-this.activeObj.strokeSettings.strokeWidth,this.activeObj.triangle[0].y),t.lineTo(this.activeObj.triangle[1].x,this.activeObj.triangle[1].y-this.activeObj.strokeSettings.strokeWidth),t.lineTo(this.activeObj.triangle[2].x+this.activeObj.strokeSettings.strokeWidth,this.activeObj.triangle[2].y),t.lineTo(this.activeObj.triangle[0].x-this.activeObj.strokeSettings.strokeWidth,this.activeObj.triangle[0].y);break;case"bottom":t.moveTo(this.activeObj.triangle[0].x+this.activeObj.strokeSettings.strokeWidth,this.activeObj.triangle[0].y),t.lineTo(this.activeObj.triangle[1].x,this.activeObj.triangle[1].y+this.activeObj.strokeSettings.strokeWidth),t.lineTo(this.activeObj.triangle[2].x-this.activeObj.strokeSettings.strokeWidth,this.activeObj.triangle[2].y),t.lineTo(this.activeObj.triangle[0].x+this.activeObj.strokeSettings.strokeWidth,this.activeObj.triangle[0].y)}t.fillStyle=t.strokeStyle,t.fill("evenodd"),t.closePath(),t.lineWidth=e},d.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},d.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)))},d.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()},d.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()},d.prototype.drawCenterCircles=function(t,e){t.lineWidth*=2,t.beginPath(),"arrow"===this.activeObj.shape||"line"===this.activeObj.shape?e%90==0&&e%180!=0?(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.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.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.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},d.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)}},d.prototype.findTargetObj=function(t,i,s){var o=!1;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){var c=this.lowerContext.filter;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),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&&(e.isNullOrUndefined(this.prevActObj)&&(this.prevActObj=e.extend({},this.activeObj,{},!0)),this.drawObject("duplicate",this.activeObj,null,null,!0,null,!0),this.isShapeInserted||(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},d.prototype.getCurrentFlipState=function(){if(0!==this.rotateFlipColl.length){var t=e.extend({},this.totalPannedInternalPoint,{},!0);this.callUpdateCurrentTransformedState(),this.totalPannedInternalPoint=t}else this.callUpdateCurrentTransformedState()},d.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()},d.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);if(!e.isNullOrUndefined(a.topLeftCircle)){var n;(n=0===a.shapeDegree?this.degree:this.degree-a.shapeDegree)<0&&(n=360+n),this.isObjSelected?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.dragPoint.startX=this.previousPoint.x=this.dragPoint.endX=t,this.dragPoint.startY=this.previousPoint.y=this.dragPoint.endY=i),"arrow"!==a.shape&&"line"!==a.shape||(n%90==0&&n%180!=0?"sw-resize"===this.upperCanvas.style.cursor||"se-resize"===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):"nw-resize"!==this.upperCanvas.style.cursor&&"ne-resize"!==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):"nw-resize"===this.upperCanvas.style.cursor||"sw-resize"===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):"ne-resize"!==this.upperCanvas.style.cursor&&"se-resize"!==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),"nw-resize"!==this.upperCanvas.style.cursor&&"ne-resize"!==this.upperCanvas.style.cursor&&"sw-resize"!==this.upperCanvas.style.cursor&&"se-resize"!==this.upperCanvas.style.cursor||(this.updateCursorStylesForArrow(t,i),o=!1),n%90==0&&n%180!=0?"w-resize"!==this.upperCanvas.style.cursor&&"e-resize"!==this.upperCanvas.style.cursor||(this.updateCursorStylesForArrow(t,i),o=!1):"n-resize"!==this.upperCanvas.style.cursor&&"s-resize"!==this.upperCanvas.style.cursor||(this.updateCursorStylesForArrow(t,i),o=!1)),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}},d.prototype.updateCursorStylesForArrow=function(t,e){this.upperCanvas.style.cursor="move",this.dragElement="",this.dragPoint.startX=this.previousPoint.x=this.dragPoint.endX=t,this.dragPoint.startY=this.previousPoint.y=this.dragPoint.endY=e},d.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,this.destLeft<0&&(s+=2*this.destLeft)):s=this.lowerCanvas.clientWidth-this.destLeft,this.destTop+this.destTop+this.destHeight<=this.lowerCanvas.clientHeight?(o=this.destHeight-this.destTop,this.destTop<0&&(o+=2*this.destTop)):o=this.lowerCanvas.clientHeight-this.destTop,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()),this.activeObj.activePoint.startX<this.destLeft){var 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){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},d.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)},d.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},d.prototype.calcShapeRatio=function(t,e,i,s){for(var o=i,a=s,n=o>=a?o:a,r=n*(t/e),h=n,l=this.getScale(r,o),c=[],d=0;d<2;d++)0===d?c.push(r*l):c.push(h*l);r=c[0],h=c[1];var p=this.getScale(h,a),v=[];for(d=0;d<2;d++)0===d?v.push(r*p):v.push(h*p);r=v[0],h=v[1],this.activeObj.activePoint.width=r,this.activeObj.activePoint.height=h,this.activeObj.activePoint.startX=7.5+(this.dragPoint.startX=(o-r)/2),this.activeObj.activePoint.startY=7.5+(this.dragPoint.startY=(a-h)/2),this.activeObj.activePoint.endX=(o-r)/2+r-7.5,this.activeObj.activePoint.endY=(a-h)/2+h-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+r-7.5),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+h-7.5),this.activeObj.activePoint.width=this.activeObj.activePoint.endX-this.activeObj.activePoint.startX,this.activeObj.activePoint.height=this.activeObj.activePoint.endY-this.activeObj.activePoint.startY},d.prototype.getScale=function(t,e){return t>e?e/t:1},d.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}},d.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"},d.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);this.cursorTargetObjId=n.currIndex;var r=void 0;(r=0===n.shapeDegree?this.degree:this.degree-n.shapeDegree)<0&&(r=360+r),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"),"arrow"!==n.shape&&"line"!==n.shape||(r%90==0&&r%180!=0?"sw-resize"===this.upperCanvas.style.cursor||"se-resize"===this.upperCanvas.style.cursor?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"):"nw-resize"!==this.upperCanvas.style.cursor&&"ne-resize"!==this.upperCanvas.style.cursor||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"):"nw-resize"===this.upperCanvas.style.cursor||"sw-resize"===this.upperCanvas.style.cursor?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"):"ne-resize"!==this.upperCanvas.style.cursor&&"se-resize"!==this.upperCanvas.style.cursor||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"),"nw-resize"!==this.upperCanvas.style.cursor&&"ne-resize"!==this.upperCanvas.style.cursor&&"sw-resize"!==this.upperCanvas.style.cursor&&"se-resize"!==this.upperCanvas.style.cursor||(this.upperCanvas.style.cursor="move"),r%90==0&&r%180!=0?"w-resize"!==this.upperCanvas.style.cursor&&"e-resize"!==this.upperCanvas.style.cursor||(this.upperCanvas.style.cursor="move"):"n-resize"!==this.upperCanvas.style.cursor&&"s-resize"!==this.upperCanvas.style.cursor||(this.upperCanvas.style.cursor="move")),"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)},d.prototype.setCursorForFreehandDrawing=function(t,i){var s=!1;this.freehandDrawHoveredIndex=-1;for(var o,a=0;a<this.freehandCounter;a++){o=e.extend([],this.selPointColl[a].points,[]),this.points=e.extend([],this.pointColl[a].points,[]),this.pointCounter=0;for(var n=o.length,r=0;r<n;r++)if(0!==r){var h=!1;if(e.isNullOrUndefined(o[r-1])||e.isNullOrUndefined(o[r])||(h=this.isInside(t,i,o[r-1].x,o[r-1].y,o[r].x,o[r].y)),h){this.isFreehandDrawingPoint=!0,this.freehandDrawHoveredIndex=a,this.hoverFreehandraw(),this.upperCanvas.style.cursor="pointer",s=!0;break}if(!this.isFreehandDrawEditing||this.pointColl[a].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 l=this.pointColl[a].strokeColor;this.hoverFreehandraw(l,this.pointColl[a].strokeWidth)}else this.freehandDrawHoveredIndex=null;this.isFreehandDrawingPoint=!1}}else{if(t>this.points[r].x-this.pointColl[a].strokeWidth&&t<this.points[r].x+this.pointColl[a].strokeWidth&&i>this.points[r].y-this.pointColl[a].strokeWidth&&i<this.points[r].y+this.pointColl[a].strokeWidth){this.isFreehandDrawingPoint=!0,this.freehandDrawHoveredIndex=a,this.hoverFreehandraw(),this.upperCanvas.style.cursor="pointer",s=!0;break}if(!this.isFreehandDrawEditing||this.pointColl[a].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){l=this.pointColl[a].strokeColor;this.hoverFreehandraw(l,this.pointColl[a].strokeWidth)}this.isFreehandDrawingPoint=!1}}if(s)break}},d.prototype.setCursorFromObj=function(t,i,s){for(var o=0;o<s.length;o++){var a=e.extend({},s[o],{},!0);if(this.cursorTargetObjId=a.currIndex,t>=a.topLeftCircle.startX&&t<=a.topLeftCircle.startX&&i>=a.topLeftCircle.startY&&i<=a.topLeftCircle.startY){this.upperCanvas.style.cursor="nw-resize";break}if(t>=a.topCenterCircle.startX&&t<=a.topCenterCircle.startX&&i>=a.topCenterCircle.startY&&i<=a.topCenterCircle.startY){this.upperCanvas.style.cursor="n-resize";break}if(t>=a.topRightCircle.startX&&t<=a.topRightCircle.startX&&i>=a.topRightCircle.startY&&i<=a.topRightCircle.startY){this.upperCanvas.style.cursor="ne-resize";break}if(t>=a.centerLeftCircle.startX&&t<=a.centerLeftCircle.startX&&i>=a.centerLeftCircle.startY&&i<=a.centerLeftCircle.startY){this.upperCanvas.style.cursor="w-resize";break}if(t>=a.centerRightCircle.startX&&t<=a.centerRightCircle.startX&&i>=a.centerRightCircle.startY&&i<=a.centerRightCircle.startY){this.upperCanvas.style.cursor="e-resize";break}if(t>=a.bottomLeftCircle.startX&&t<=a.bottomLeftCircle.startX&&i>=a.bottomLeftCircle.startY&&i<=a.bottomLeftCircle.startY){this.upperCanvas.style.cursor="sw-resize";break}if(t>=a.bottomCenterCircle.startX&&t<=a.bottomCenterCircle.startX&&i>=a.bottomCenterCircle.startY&&i<=a.bottomCenterCircle.startY){this.upperCanvas.style.cursor="s-resize";break}if(t>=a.bottomRightCircle.startX&&t<=a.bottomRightCircle.startX&&i>=a.bottomRightCircle.startY&&i<=a.bottomRightCircle.startY){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"}},d.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},d.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)}},d.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)},d.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)},d.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")},d.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;var 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){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(var u=0;u<v;u++)this.points[u].x=(this.points[u].x-this.destLeft)*t.width,this.points[u].y=(this.points[u].y-this.destTop)*t.height}else for(u=0;u<v;u++)this.points[u].x-=this.destLeft,this.points[u].y-=this.destTop}this.freehandRedraw(r),this.pointColl=d}return this.isCircleCrop&&this.cropCircle(r,!0),this.lowerContext.filter=i,n},d.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},d.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)},d.prototype.exportHorizontalFlip=function(t){t.translate(t.canvas.width,0),t.scale(-1,1),t.drawImage(this.inMemoryCanvas,0,0),this.updateSaveContext(t)},d.prototype.exportVerticalFlip=function(t){t.translate(0,t.canvas.height),t.scale(1,-1),t.drawImage(this.inMemoryCanvas,0,0),this.updateSaveContext(t)},d.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)},d.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)}},d.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},d.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))}},d.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)},d.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}},d.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(var 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].shapeFlip=this.currFlipState,this.updateArrowDirection(this.objColl[o],"horizontal"),this.updateTrianglePoints(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});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].shapeFlip=this.currFlipState,this.updateArrowDirection(this.objColl[o],"vertical"),this.updateTrianglePoints(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});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].shapeFlip=this.currFlipState,this.updateArrowDirection(this.objColl[o],this.currFlipState),this.updateTrianglePoints(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});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(o=0;o<3;o++)this.rotateObjColl()},d.prototype.rotateObjColl=function(){for(var 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]),"arrow"===this.objColl[t].shape&&(this.updateArrowDirection(this.objColl[t],null,90),this.updateTrianglePoints(this.objColl[t]));for(t=0;t<this.objColl.length;t++)this.updateActiveObject(this.objColl[t].activePoint,this.objColl[t]);for(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}},d.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)},d.prototype.applyActObj=function(t){var i=!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 s=void 0,o=!1;if(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),!e.isNullOrUndefined(this.activeObj.shape)&&!o&&"shape"!==this.activeObj.shape){for(var a=0;a<this.objColl.length;a++)if(JSON.stringify(this.activeObj)===JSON.stringify(this.objColl[a])){i=!0;break}if(!i){e.isNullOrUndefined(this.activeObj.currIndex)&&(this.activeObj.currIndex="shape_"+(this.objColl.length+1)),this.updateImageRatioForActObj();var n=this.activeObj.currIndex.split("_"),r=this.objColl.splice(0,parseInt(n[1],10)-1);r.push(e.extend({},this.activeObj,{},!0));for(a=0;a<this.objColl.length;a++)r.push(this.objColl[a]);this.objColl=r,r=[],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),this.destroyQuickAccessToolbar(),e.isNullOrUndefined(t)&&(this.updateCurrentUndoRedoColl("ok"),this.prevActObj=null)}}}},d.prototype.destroyQuickAccessToolbar=function(){e.isNullOrUndefined(document.getElementById(this.element.id+"_quickAccessToolbar"))||e.isNullOrUndefined(e.getComponent(document.getElementById(this.element.id+"_quickAccessToolbar"),"toolbar"))||e.getComponent(document.getElementById(this.element.id+"_quickAccessToolbar"),"toolbar").destroy(),e.isNullOrUndefined(document.getElementById(this.element.id+"_quickAccessToolbarArea"))||(document.getElementById(this.element.id+"_quickAccessToolbarArea").style.display="none")},d.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),"text"===this.activeObj.shape?(this.drawObject(s,i,null,null,!0),this.clearOuterCanvas(this.lowerContext)):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="")},d.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)},d.prototype.updateTriangleRatio=function(t){t.triangleRatio=[],t.triangleRatio.push({x:(t.triangle[0].x-this.destLeft)/this.destWidth,y:(t.triangle[0].y-this.destTop)/this.destHeight}),t.triangleRatio.push({x:(t.triangle[1].x-this.destLeft)/this.destWidth,y:(t.triangle[1].y-this.destTop)/this.destHeight}),t.triangleRatio.push({x:(t.triangle[2].x-this.destLeft)/this.destWidth,y:(t.triangle[2].y-this.destTop)/this.destHeight})},d.prototype.updateTrianglePoints=function(t){if("arrow"===t.shape){var e=void 0,i=void 0;switch((e=0===t.shapeDegree?this.degree:this.degree-t.shapeDegree)<0&&(e=360+e),i=e%90==0&&e%180!=0?t.activePoint.width:t.activePoint.height,t.triangle=[],t.triangleDirection){case"right":t.triangle.push({x:t.activePoint.endX-i,y:t.activePoint.startY}),t.triangle.push({x:t.activePoint.endX,y:t.activePoint.startY+i/2}),t.triangle.push({x:t.activePoint.endX-i,y:t.activePoint.endY});break;case"left":t.triangle.push({x:t.activePoint.startX+i,y:t.activePoint.startY}),t.triangle.push({x:t.activePoint.startX,y:t.activePoint.startY+i/2}),t.triangle.push({x:t.activePoint.startX+i,y:t.activePoint.endY});break;case"top":t.triangle.push({x:t.activePoint.startX,y:t.activePoint.startY+i}),t.triangle.push({x:t.activePoint.startX+i/2,y:t.activePoint.startY}),t.triangle.push({x:t.activePoint.startX+i,y:t.activePoint.startY+i});break;case"bottom":t.triangle.push({x:t.activePoint.endX,y:t.activePoint.endY-i}),t.triangle.push({x:t.activePoint.endX-i/2,y:t.activePoint.endY}),t.triangle.push({x:t.activePoint.endX-i,y:t.activePoint.endY-i})}this.updateTriangleRatio(t)}},d.prototype.setDimension=function(t,i){e.isNullOrUndefined(t)||e.isNullOrUndefined(i)||(this.activeObj.activePoint.width=t,this.activeObj.activePoint.height=i,"ellipse"===this.currObjType.shape.toLowerCase()&&(this.activeObj.activePoint.width=2*t,this.activeObj.activePoint.height=2*i))},d.prototype.updateUndoRedo=function(){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.objColl.push(this.activeObj),this.updateUndoRedoColl("shapeTransform",i,i.objColl,i.pointColl,t),this.objColl.pop(),this.applyActObj(),this.refreshActiveObj(),this.refreshMainToolbar()},d.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()||"arrow"===this.currObjType.shape.toLowerCase()?(this.activeObj.lineDraw="horizontal",this.activeObj.activePoint.height/=2,this.activeObj.activePoint.height-=20,"arrow"===this.currObjType.shape.toLowerCase()&&(this.activeObj.activePoint.width+=50)):"rectangle"===this.currObjType.shape.toLowerCase()&&(this.activeObj.activePoint.width+=this.activeObj.activePoint.width/2),this.setDimension(n,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),"arrow"===this.currObjType.shape.toLowerCase()&&(this.activeObj.triangleDirection="right",this.updateTrianglePoints(this.activeObj)),this.currObjType.isDragging=this.currObjType.isCustomCrop=!1,this.activeObj.shapeDegree=this.degree,this.activeObj.shapeFlip=this.currFlipState,this.activeObj.textFlip=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.setDimension(n,r),this.drawObject("duplicate"),this.renderQuickAccessToolbar(),this.isShapeInserted=!0,this.updateUndoRedoObj(h),this.refreshToolbar("shapes"),this.updateToolbarItems()}}},d.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.destWidth>this.destHeight?this.activeObj.textSettings.fontSize=this.destWidth/15:this.activeObj.textSettings.fontSize=this.destHeight/15,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 u=e.extend({},this.cropObj,{},!0);this.updateUndoRedoColl("shapeTransform",l,l.objColl,l.pointColl,u),this.redrawShape(this.objColl[this.objColl.length-1]),this.renderQuickAccessToolbar(),this.isShapeInserted=!0,this.refreshToolbar("text"),this.updateToolbarItems()}},d.prototype.updateShapeChangeEventArgs=function(t){switch(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.activePoint.endX=this.activeObj.activePoint.startX+this.activeObj.activePoint.width,this.activeObj.activePoint.endY=this.activeObj.activePoint.startY+this.activeObj.activePoint.height,this.activeObj.strokeSettings.strokeColor=t.strokeColor,this.activeObj.strokeSettings.fillColor=t.fillColor,this.activeObj.shape){case"ellipse":this.activeObj.activePoint.width=t.radius/2;break;case"line":case"arrow":this.activeObj.activePoint.width=t.length;break;case"text":this.activeObj.keyHistory=t.text,this.activeObj.textSettings.fontSize=t.fontSize,this.activeObj.strokeSettings.strokeColor=t.color}if("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)},d.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||"arrow"===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},d.prototype.getFreehandDrawDetails=function(i){var s={};return s.id=this.pointColl[i].id,s.type=t.ShapeType.FreehandDraw,s.points=e.extend([],this.pointColl[i].points),s.strokeColor=this.pointColl[i].strokeColor,s.strokeWidth=this.pointColl[i].strokeWidth,s},d.prototype.isPointsInRange=function(t,i){var s=!1;return!e.isNullOrUndefined(t)&&!e.isNullOrUndefined(i)&&t>=0&&i>=0&&t<=this.lowerCanvas.width&&i<=this.lowerCanvas.width&&(s=!0),s},d.prototype.clearActObj=function(){"none"===this.textArea.style.display&&(this.refreshActiveObj(),this.applyActObj(),this.refreshActiveObj(),this.currObjType.isCustomCrop=!1)},d.prototype.applyPenDraw=function(){"freehanddraw"===this.currObjType.shape&&(this.apply(),this.upperCanvas.style.cursor="default",this.currObjType.shape=""),this.clearActObj()},d.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)},d.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}},d.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)},d.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},d.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},d.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},d.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},d.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(var 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(e=0;e<4;e++)this.flipColl.pop()},d.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)},d.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)},d.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()},d.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)},d.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},d.prototype.getFilterValue=function(t){return 0===t?1:1+.5*t/100},d.prototype.setFilterValue=function(t){var e;return e=1===t?0:100*(t-1)/.5,Math.round(e)},d.prototype.getSaturationFilterValue=function(t){return 0===t?1:1+t/100},d.prototype.setSaturationFilterValue=function(t){var e;return e=1===t?0:100*(t-1),Math.round(e)},d.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},d.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)},d.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)},d.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)},d.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)},d.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)},d.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)},d.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)},d.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)},d.prototype.renderImage=function(t){var i=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),t?this.iterateRotateFlipColl(this.lowerContext,"initial"):(this.zoomFactor>0&&(this.isRotateZoom=!0),this.updateCurrentTransformedState("initial")),this.updateBrightnessFilter(),this.setDestPointsForFlipState(),this.lowerContext.drawImage(this.baseImg,this.srcLeft,this.srcTop,this.srcWidth,this.srcHeight,this.destLeft,this.destTop,this.destWidth,this.destHeight),this.setDestPointsForFlipState(),t?this.iterateRotateFlipColl(this.lowerContext,"reverse"):(this.updateCurrentTransformedState("reverse"),this.isRotateZoom=!1),this.lowerContext.filter="none",this.iterateObjColl(),this.freehandRedraw(this.lowerContext),this.lowerContext.filter=i,(this.isCircleCrop||!e.isNullOrUndefined(this.currSelectionPoint)&&"crop-circle"===this.currSelectionPoint.shape)&&this.cropCircle(this.lowerContext)},d.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.destroyQuickAccessToolbar(),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"},d.prototype.drawNewSelection=function(t,e,i,s,o){var a,n="crop-"+t;"crop-custom"===n.toLowerCase()?""!==this.currObjType.shape&&"crop-custom"!==this.currObjType.shape||this.drawCustomSelection("crop-custom",e,i,s,o):"crop-canvas"===n.toLowerCase()?(this.upperCanvas.style.display="block",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.updateSelectionInsert(),0===this.activeObj.activePoint.startX&&0===this.activeObj.activePoint.startY&&0===this.activeObj.activePoint.width&&0===this.activeObj.activePoint.height||(a={startX:this.activeObj.activePoint.startX,startY:this.activeObj.activePoint.startY,endX:this.activeObj.activePoint.endX,endY:this.activeObj.activePoint.endY,width:this.activeObj.activePoint.width,height:this.activeObj.activePoint.height}),this.drawObject("duplicate",null,!0,a))},d.prototype.setDestPointsForFlipState=function(){""!==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)))},d.prototype.performUndoDefaultAction=function(t){this.lowerContext.filter=t.previousObj.filter,this.objColl=[],this.pointColl=[],this.freehandCounter=0,this.setCurrentObj(t.previousObj),this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),this.refreshActiveObj(),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.zoomObjColl(),this.zoomFreehandDrawColl(),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")},d.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)}},d.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}},d.prototype.rotateImage=function(t){var i=!1;if(!this.disabled&&this.isImageLoaded&&t%90==0){var s={degree:t,cancel:!1};if(this.trigger("rotating",s),!s.cancel){i=!0;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(null,null,!0),this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),this.drawRotatedImage(t),this.clearOuterCanvas(this.lowerContext),this.clearOuterCanvas(this.upperContext),this.isCircleCrop&&this.cropCircle(this.lowerContext),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.refreshMainToolbar():this.isReverseRotate||this.refreshToolbar("main",!0,!0),this.rotateFlipColl=this.alignRotateFlipColl(this.rotateFlipColl,!0)}}return i},d.prototype.flipImage=function(t){if(!this.disabled&&this.isImageLoaded){var i={direction:t,cancel:!1};if(this.trigger("flipping",i),i.cancel)return;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(null,null,!0),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),this.isCircleCrop&&this.cropCircle(this.lowerContext),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.refreshMainToolbar():this.isReverseFlip||this.refreshToolbar("main",!0,!0),this.rotateFlipColl=this.alignRotateFlipColl(this.rotateFlipColl,!0)}},d.prototype.componentToHex=function(t){var e=t.toString(16);return 1===e.length?"0"+e:e},d.prototype.rgbToHex=function(t,e,i){return"#"+this.componentToHex(t)+this.componentToHex(e)+this.componentToHex(i)},d.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")},d.prototype.crop=function(){var t=!1;if(!this.disabled&&this.isImageLoaded){this.currObjType.isUndoAction&&this.refreshUndoRedoColl();var i=void 0,s={cancel:!1,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),!s.cancel&&(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=e.extend({},this.previousCropCurrentObj,{},!0);this.cropImg(),this.zoomFactor=0,this.updateUndoRedoColl("crop",a,a.objColl,a.pointColl,o,null,null,null,this.isCircleCrop),this.updateCurrentUndoRedoColl("ok"),this.refreshToolbar("main")}}return t},d.prototype.flip=function(t){this.flipImage(t),this.updateCurrentUndoRedoColl("ok")},d.prototype.getImageData=function(){var t=this.exportChangesToCanvas();return t.getContext("2d").getImageData(0,0,t.width,t.height)},d.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");i&&(i.style.display="none"),0===this.defToolbarItems.length&&e.isNullOrUndefined(document.getElementById(this.element.id+"_toolbar"))&&(e.isNullOrUndefined(this.toolbarTemplate)?this.toolbarHeight=0:e.isNullOrUndefined(this.element.querySelector("#"+this.element.id+"_toolbarArea"))||(this.toolbarHeight=this.element.querySelector("#"+this.element.id+"_toolbarArea").clientHeight)),this.reset(),this.update(),this.degree=0,this.zoomFactor=0,this.isImageLoaded=!1,this.currSelectionPoint=null;if("string"===typeof t){var s=t.split(".");if(s.length>1?(s=s[s.length-2].split("/"),this.fileName=s[s.length-1]):this.fileName="ImageEditor",e.isNullOrUndefined(t.split("."))||e.isNullOrUndefined(t.split(".")[2]))this.fileType=null;else{var o=this.toPascalCase(t.split(".")[2]);this.fileType="JPG"===o||"Jpg"===o?"Jpeg":o}this.imageOnLoad(t)}else this.fileName="ImageEditor",this.fileType=null,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()}},d.prototype.reset=function(){this.disabled||this.isErrorImage||(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="block",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.currToolbar="",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=this.isShapeInserted=!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={x:0,y: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=this.isErrorImage=!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.isBrightnessAdjusted=this.isInitialLoading=this.isShapeTextInserted=!1,this.defaultZoomFactor=this.cropZoomFactor=this.zoomFactor=0,this.tempActObj=null,this.currentMouseMovePoint={x:0,y:0},this.selectedFreehandColor="#42a5f5",this.isFreehandDrawCustomized=!1,this.isObjSelected=!1,this.isAllowCropPan=!1,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:"",zoomFactor:0,previousZoomValue:0,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.previousZoomValue=1,this.cancelObjColl=[],this.cancelPointColl=[],this.freehandDrawSelectedId=null,this.transformCurrentObj=null,this.rotatedFlipCropSelection=!1,this.currDestinationPoint=null,this.appliedUndoRedoColl=[],this.zoomBtnHold=null,this.zoomType="Toolbar",this.cursorTargetObjId="",this.isInitialTextEdited=!1,this.selPoints=[],this.selPointColl={},this.prevActObj=null,this.tempCurrSelectionPoint=null,e.isNullOrUndefined(this.initialZoomValue)||this.setProperties({zoomSettings:{zoomFactor:this.initialZoomValue}},!0),e.isNullOrUndefined(document.getElementById(this.element.id+"_quickAccessToolbarArea"))||(document.getElementById(this.element.id+"_quickAccessToolbarArea").style.display="none"),this.isImageLoaded=!1,this.updateCanvas(),this.isImageLoaded=!0,this.refreshDropDownBtn(!1),this.enableDisableToolbarBtn())},d.prototype.rotate=function(t){var e=this.rotateImage(t);return this.updateCurrentUndoRedoColl("ok"),e},d.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.refreshMainToolbar(),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="")})}},d.prototype.select=function(t,i,s,o,a){if(!this.disabled&&this.isImageLoaded){var n=this.getCurrentObj();n.objColl=e.extend([],this.objColl,[],!0),n.pointColl=e.extend([],this.pointColl,[],!0),n.afterCropActions=this.afterCropActions,this.previousCropCurrentObj=n,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 r=!1,h=void 0;void 0!==this.activeObj.shape&&(h=this.activeObj.shape.split("-")),void 0===h&&this.currObjType.isCustomCrop?r=!0:void 0!==h&&"crop"===h[0]&&(r=!0);var 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&&!r){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.zoomAction(-.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.isCircleCrop=!1,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)}},d.prototype.updateSelectionInsert=function(){var t=this.updatePreviousShapeSettings(),e={action:"insert",previousShapeSettings:t,currentShapeSettings:t};this.trigger("shapeChanging",e),this.updateShapeChangeEventArgs(e.currentShapeSettings)},d.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.refreshMainToolbar(),this.currentToolbar="main",this.isFreehandDrawCustomized=!1)},d.prototype.freehandDraw=function(t){!this.disabled&&this.isImageLoaded&&this.freeHandDraw(t)},d.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"))},d.prototype.zoom=function(t,i){if(!this.disabled&&this.isImageLoaded){var s=this.getCurrentZoomFactor(t);if(e.isNullOrUndefined(i))this.zoomAction(s,i);else for(var o=s>0?"zoomIn":"zoomOut",a=0;a<10*Math.abs(s);a++)this.performPointZoom(i.x,i.y,o)}},d.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),this.updateUndoRedo()}return r},d.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),this.updateUndoRedo()}return n},d.prototype.drawArrow=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="arrow","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("arrow",o,a,null,h,l,c),this.updateUndoRedo()}return n},d.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),this.updateUndoRedo()}return r},d.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),this.updateUndoRedo()),h},d.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},d.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.refreshMainToolbar()}},d.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},d.prototype.getShapeSettings=function(){var t=[];if(!this.disabled&&this.isImageLoaded){this.applyActObj();for(var e=0;e<this.objColl.length;e++){var i=this.getObjDetails(this.objColl[e]);t.push(i)}for(e=0;e<this.freehandCounter;e++){i=this.getFreehandDrawDetails(e);t.push(i)}}return t},d.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)},d.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,this.updateCurrentUndoRedoColl("ok")}},d.prototype.applyImageFilter=function(t){!this.disabled&&this.isImageLoaded&&(this.setFilter(t.toString()),this.canvasFilter=this.lowerContext.filter,this.updateCurrentUndoRedoColl("ok"))},d.prototype.undo=function(){if(!this.disabled&&this.isImageLoaded&&this.undoRedoStep>0){e.isNullOrUndefined(this.activeObj.shape)?this.refreshMainToolbar():(this.refreshToolbar("shapes"),this.updateToolbarItems()),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.zoomObjColl(),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.zoomFreehandDrawColl(),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.zoomFreehandDrawColl(),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,this.zoomFreehandDrawColl()):"deleteObj"===t.operation&&(this.objColl=t.previousObjColl,this.zoomObjColl()),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"textAreaCustomization":this.objColl=e.extend([],t.previousObjColl,[],!0),this.zoomObjColl(!0),this.lowerContext.clearRect(0,0,this.lowerCanvas.width,this.lowerCanvas.height),this.isUndoRedo=!0,this.redrawImgWithObj();for(var 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),"block"===this.textArea.style.display&&this.redrawActObj();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(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.zoomObjColl(!0),this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),this.lowerContext.clearRect(0,0,this.lowerCanvas.width,this.lowerCanvas.height),this.isUndoRedo=!0,this.redrawImgWithObj(),this.refreshActiveObj();break;default:this.performUndoDefaultAction(t),this.setAdjustment(t.operation),this.updateFilter(t.operation,t.filter)}"crop"===t.operation&&this.isCircleCrop&&(this.isCircleCrop=!1,this.tempCurrSelectionPoint=e.extend({},this.currSelectionPoint,{},!0),this.currSelectionPoint=null),!e.isNullOrUndefined(this.undoRedoColl[this.undoRedoStep-1])&&this.undoRedoColl[this.undoRedoStep-1].isCircleCrop&&(this.isCircleCrop=!0,this.cropCircle(this.lowerContext)),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.refreshMainToolbar():this.refreshToolbar("main",!0,!0),e.isNullOrUndefined(document.getElementById(this.element.id+"_quickAccessToolbarArea"))||(document.getElementById(this.element.id+"_quickAccessToolbarArea").style.display="none"),this.enableDisableToolbarBtn()}},d.prototype.redo=function(){if(!this.disabled&&this.isImageLoaded&&this.undoRedoStep<this.appliedUndoRedoColl.length){e.isNullOrUndefined(this.activeObj.shape)?this.refreshMainToolbar():(this.refreshToolbar("shapes"),this.updateToolbarItems()),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;switch(t.operation){case"shapeTransform":this.objColl=e.extend([],t.currentObjColl,[],!0),this.zoomObjColl(),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.zoomFreehandDrawColl(),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.zoomFreehandDrawColl(),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,this.zoomFreehandDrawColl()):"deleteObj"===t.operation&&(this.objColl=t.currentObjColl,this.zoomObjColl()),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"textAreaCustomization":this.objColl=e.extend([],t.currentObjColl,[],!0),this.zoomObjColl(!0),this.lowerContext.clearRect(0,0,this.lowerCanvas.width,this.lowerCanvas.height),this.isUndoRedo=!0,this.redrawImgWithObj();for(var s=0;s<t.currentObjColl.length;s++){if(e.isNullOrUndefined(this.tempActObj)){i=e.extend({},t.currentObjColl[t.currentObjColl.length-1],{},!0),this.objColl.splice(s,1);break}if(this.tempActObj.currIndex===t.currentObjColl[s].currIndex){i=e.extend({},t.currentObjColl[s],{},!0),this.objColl.splice(s,1);break}}e.isNullOrUndefined(i)||this.updateTextBox(i),"block"===this.textArea.style.display&&this.redrawActObj();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(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.objColl=e.extend([],t.currentObjColl,[],!0),this.zoomObjColl(!0),this.lowerContext.clearRect(0,0,this.lowerCanvas.width,this.lowerCanvas.height),this.isUndoRedo=!0,this.redrawImgWithObj(),this.refreshActiveObj();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.zoomObjColl(),this.zoomFreehandDrawColl(),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)}"crop"===t.operation&&t.isCircleCrop&&(this.isCircleCrop=!0,this.currSelectionPoint=e.extend({},this.tempCurrSelectionPoint,{},!0),this.tempCurrSelectionPoint=null),"crop"!==t.operation||t.isCircleCrop||(this.isCircleCrop=!1),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.refreshMainToolbar():this.refreshToolbar("main",!0,!0),e.isNullOrUndefined(document.getElementById(this.element.id+"_quickAccessToolbarArea"))||(document.getElementById(this.element.id+"_quickAccessToolbarArea").style.display="none"),this.enableDisableToolbarBtn()}},d.prototype.getImageDimension=function(){return{x:this.destLeft,y:this.destTop,width:this.destWidth,height:this.destHeight}};var p;return r([e.Property("")],d.prototype,"cssClass",void 0),r([e.Property(!1)],d.prototype,"disabled",void 0),r([e.Property("100%")],d.prototype,"height",void 0),r([e.Property("Bootstrap5")],d.prototype,"theme",void 0),r([e.Property()],d.prototype,"toolbar",void 0),r([e.Property()],d.prototype,"toolbarTemplate",void 0),r([e.Property("100%")],d.prototype,"width",void 0),r([e.Property(!0)],d.prototype,"allowUndoRedo",void 0),r([e.Property(!1)],d.prototype,"showQuickAccessToolbar",void 0),r([e.Property()],d.prototype,"quickAccessToolbarTemplate",void 0),r([e.Property(!1)],d.prototype,"isReadOnly",void 0),r([e.Property(!1)],d.prototype,"enableRtl",void 0),r([e.Property(!1)],d.prototype,"enablePersistence",void 0),r([e.Complex({},h)],d.prototype,"finetuneSettings",void 0),r([e.Complex({},l)],d.prototype,"zoomSettings",void 0),r([e.Event()],d.prototype,"beforeSave",void 0),r([e.Event()],d.prototype,"created",void 0),r([e.Event()],d.prototype,"destroyed",void 0),r([e.Event()],d.prototype,"zooming",void 0),r([e.Event()],d.prototype,"panning",void 0),r([e.Event()],d.prototype,"cropping",void 0),r([e.Event()],d.prototype,"rotating",void 0),r([e.Event()],d.prototype,"flipping",void 0),r([e.Event()],d.prototype,"shapeChanging",void 0),r([e.Event()],d.prototype,"fileOpened",void 0),r([e.Event()],d.prototype,"saved",void 0),r([e.Event()],d.prototype,"toolbarCreated",void 0),r([e.Event()],d.prototype,"toolbarUpdating",void 0),r([e.Event()],d.prototype,"toolbarItemClicked",void 0),r([e.Event()],d.prototype,"imageFiltering",void 0),r([e.Event()],d.prototype,"finetuneValueChanging",void 0),r([e.Event()],d.prototype,"click",void 0),r([e.Event()],d.prototype,"quickAccessToolbarOpening",void 0),d=p=r([e.NotifyPropertyChanges],d)}(e.Component);!function(t){t.Png="Png",t.Jpeg="Jpeg",t.Svg="Svg"}(t.FileType||(t.FileType={})),function(t){t.Horizontal="Horizontal",t.Vertical="Vertical"}(t.Direction||(t.Direction={})),function(t){t.Rectangle="Rectangle",t.Ellipse="Ellipse",t.Line="Line",t.Arrow="Arrow",t.Text="Text",t.FreehandDraw="FreehandDraw"}(t.ShapeType||(t.ShapeType={})),function(t){t[t.MouseWheel=1]="MouseWheel",t[t.Pinch=2]="Pinch",t[t.Commands=4]="Commands",t[t.Toolbar=8]="Toolbar"}(t.ZoomTrigger||(t.ZoomTrigger={})),function(t){t.Bootstrap5="Bootstrap5",t.Bootstrap5Dark="Bootstrap5Dark",t.Tailwind="Tailwind",t.TailwindDark="TailwindDark",t.Fluent="Fluent",t.FluentDark="FluentDark",t.Bootstrap4="Bootstrap4",t.Bootstrap="Bootstrap",t.BootstrapDark="BootstrapDark",t.Material="Material",t.MaterialDark="MaterialDark",t.Fabric="Fabric",t.FabricDark="FabricDark",t.Highcontrast="Highcontrast"}(t.Theme||(t.Theme={})),function(t){t.Crop="Crop",t.Transform="Transform",t.Annotate="Annotate",t.ZoomIn="ZoomIn",t.ZoomOut="ZoomOut",t.Open="Open",t.Reset="Reset",t.Save="Save",t.Pan="Pan",t.Move="Move",t.Pen="Pen",t.Line="Line",t.Arrow="Arrow",t.Rectangle="Rectangle",t.Ellipse="Ellipse",t.Text="Text",t.CustomSelection="CustomSelection",t.CircleSelection="CircleSelection",t.SquareSelection="SquareSelection",t.RatioSelection="RatioSelection",t.RotateLeft="RotateLeft",t.RotateRight="RotateRight",t.FlipHorizontal="FlipHorizontal",t.FlipVertical="FlipVertical"}(t.ImageEditorCommand||(t.ImageEditorCommand={})),function(t){t.Default="Default",t.Chrome="Chrome",t.Cold="Cold",t.Warm="Warm",t.Grayscale="Grayscale",t.Sepia="Sepia",t.Invert="Invert"}(t.ImageFilterOption||(t.ImageFilterOption={})),function(t){t.Brightness="Brightness",t.Contrast="Contrast",t.Hue="Hue",t.Saturation="Saturation",t.Exposure="Exposure",t.Opacity="Opacity",t.Blur="Blur"}(t.ImageFinetuneOption||(t.ImageFinetuneOption={})),t.FinetuneSettings=h,t.ZoomSettings=l,t.ImageEditor=c,Object.defineProperty(t,"__esModule",{value:!0})});
10
+ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@syncfusion/ej2-base"),require("@syncfusion/ej2-popups"),require("@syncfusion/ej2-navigations"),require("@syncfusion/ej2-splitbuttons"),require("@syncfusion/ej2-inputs")):"function"==typeof define&&define.amd?define(["exports","@syncfusion/ej2-base","@syncfusion/ej2-popups","@syncfusion/ej2-navigations","@syncfusion/ej2-splitbuttons","@syncfusion/ej2-inputs"],e):e(t.ej={},t.ej2Base,t.ej2Popups,t.ej2Navigations,t.ej2Splitbuttons,t.ej2Inputs)}(this,function(t,e,i,o,r,n){"use strict";var a=function(){function t(t){this.croppedDegree=0,this.cropDestPoints={startX:0,startY:0,width:0,height:0},this.tempFlipPanPoint={x:0,y:0},this.parent=t,this.addEventListener()}return t.prototype.destroy=function(){this.parent.isDestroyed||this.removeEventListener()},t.prototype.addEventListener=function(){this.parent.on("crop",this.cropping,this),this.parent.on("destroyed",this.destroy,this)},t.prototype.removeEventListener=function(){this.parent.off("crop",this.crop),this.parent.off("destroyed",this.destroy)},t.prototype.cropping=function(t){switch(this.updateCropPvtVar(),t.prop){case"cropImg":this.cropImg(t.value.isRotateCrop);break;case"cropCircle":this.cropCircle(t.value.context,t.value.isSave,t.value.isFlip);break;case"setCurrSelPoints":this.setCurrSelPoints(t.value.isSetDimension);break;case"updateRotatePan":this.updateRotatePan();break;case"crop":this.crop(t.value.obj);break;case"calcRatio":this.calcRatio(t.value.obj);break;case"isObjInImage":this.isObjInImage(t.value.obj,t.value.object);break;case"getCurrFlipState":this.getCurrFlipState(t.value.panObj);break;case"setPreviousCropCurrentObj":this.prevCropCurrObj=t.value.obj;break;case"setCropDestPoints":this.cropDestPoints=t.value.point;break;case"getTempFlipPanPoint":t.value.obj.point=this.tempFlipPanPoint;break;case"setTempFlipPanPoint":e.isNullOrUndefined(t.value.isAdd)?this.tempFlipPanPoint=t.value.point:(this.tempFlipPanPoint.x+=t.value.point.x,this.tempFlipPanPoint.y+=t.value.point.y);break;case"reset":this.reset()}},t.prototype.getModuleName=function(){return"crop"},t.prototype.updateCropPvtVar=function(){var t=this.parent;t.lowerCanvas&&(this.lowerContext=t.lowerCanvas.getContext("2d")),t.upperCanvas&&(this.upperContext=t.upperCanvas.getContext("2d"))},t.prototype.reset=function(){this.prevCropCurrObj=null,this.croppedDegree=0,this.cropDestPoints={startX:0,startY:0,width:0,height:0},this.tempFlipPanPoint={x:0,y:0}},t.prototype.cropImg=function(t){var i=this.parent,o=e.isNullOrUndefined(t),r=i.activeObj.activePoint;if(i.notify("draw",{prop:"setImageEdited",onPropertyChange:!1}),o&&(this.croppedDegree=i.transform.degree),o&&0!==i.transform.degree){this.updateCropObj();var n={startX:i.img.destLeft,startY:i.img.destTop,width:i.img.destWidth,height:i.img.destHeight};i.notify("transform",{prop:"setCurrDestinationPoint",onPropertyChange:!1,value:{point:n}}),this.rotateCrop()}else if(o&&""!==i.transform.currFlipState){this.updateCropObj();n={startX:i.img.destLeft,startY:i.img.destTop,width:i.img.destWidth,height:i.img.destHeight};i.notify("transform",{prop:"setCurrDestinationPoint",onPropertyChange:!1,value:{point:n}}),this.flipCrop()}else{i.notify("draw",{prop:"setTempZoomFactor",onPropertyChange:!1,value:{tempZoomFactor:i.transform.zoomFactor}});var a=this.calcRatio();if(o||!t){this.updateCropObj(),i.notify("draw",{prop:"resetPanPoints",onPropertyChange:!1}),i.notify("shape",{prop:"updImgRatioForActObj",onPropertyChange:!1});n={startX:i.img.destLeft,startY:i.img.destTop,width:i.img.destWidth,height:i.img.destHeight};i.notify("transform",{prop:"setCurrDestinationPoint",onPropertyChange:!1,value:{point:n}}),i.currSelectionPoint=e.extend({},i.activeObj,{},!0),this.cropDestPoints={startX:i.img.destLeft,startY:i.img.destTop,width:i.img.destWidth,height:i.img.destHeight}}var s={width:0,height:0};i.notify("transform",{prop:"calcMaxDimension",onPropertyChange:!1,value:{width:r.width*a.width,height:r.height*a.height,obj:s}});var l=s;this.upperContext.clearRect(0,0,i.upperCanvas.width,i.upperCanvas.height),this.lowerContext.clearRect(0,0,i.lowerCanvas.width,i.lowerCanvas.height),i.img.srcLeft=r.startX*a.width-i.img.destLeft*a.width,i.img.srcTop=r.startY*a.height-i.img.destTop*a.height,i.img.srcWidth=r.width*a.width,i.img.srcHeight=r.height*a.height,i.img.destLeft=(i.lowerCanvas.clientWidth-l.width)/2,i.img.destTop=(i.lowerCanvas.clientHeight-l.height)/2,i.img.destWidth=l.width,i.img.destHeight=l.height;var p=this.lowerContext.filter;i.notify("finetune",{prop:"updateBrightFilter",onPropertyChange:!1}),this.lowerContext.drawImage(i.baseImg,i.img.srcLeft,i.img.srcTop,i.img.srcWidth,i.img.srcHeight,i.img.destLeft,i.img.destTop,i.img.destWidth,i.img.destHeight),this.lowerContext.filter="none";var h=e.extend({},i.activeObj,{},!0);this.cropObjColl(),i.notify("shape",{prop:"zoomObjColl",onPropertyChange:!1,value:{isPreventApply:null}});for(var c=0,d=i.objColl.length;c<d;c++)this.isObjInImage(i.objColl[c])&&(i.notify("shape",{prop:"apply",onPropertyChange:!1,value:{shape:i.objColl[c].shape,obj:i.objColl[c],canvas:null}}),i.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}));i.activeObj=h,this.cropFreehandDrawColl(),i.notify("freehand-draw",{prop:"zoomFHDColl",onPropertyChange:!1,value:{isPreventApply:null}}),i.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.lowerContext}}),i.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.upperContext}}),"crop-circle"===i.currSelectionPoint.shape?this.cropCircle(this.lowerContext):i.isCircleCrop=!1,this.lowerContext.filter=p,i.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),i.currObjType.isCustomCrop=!1,i.pan(!1),i.transform.defaultZoomFactor=0}},t.prototype.updateCropObj=function(){this.parent.afterCropActions=[];var t={currObj:{}};this.parent.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:t}});var i=t.currObj;this.parent.cropObj=e.extend({},i,{},!0)},t.prototype.rotateCrop=function(){var t=this.parent,i=t.activeObj.shape||"",o=t.transform.degree;t.notify("shape",{prop:"updImgRatioForActObj",onPropertyChange:!1}),t.currSelectionPoint=e.extend({},t.activeObj,{},!0),t.objColl.push(t.activeObj),t.activeObj=e.extend({},t.objColl[t.objColl.length-1],{},!0),this.lowerContext.setTransform(1,0,0,1,0,0),t.notify("draw",{prop:"setClientTransDim",onPropertyChange:!1,value:{isPreventDimension:null}}),this.lowerContext.clearRect(0,0,t.lowerCanvas.width,t.lowerCanvas.height),t.transform.degree=0;var r=this.lowerContext.filter;t.notify("finetune",{prop:"updateBrightFilter",onPropertyChange:!1}),this.lowerContext.drawImage(t.baseImg,t.img.srcLeft,t.img.srcTop,t.img.srcWidth,t.img.srcHeight,t.img.destLeft,t.img.destTop,t.img.destWidth,t.img.destHeight),this.lowerContext.filter=r;var n=0;90===o||-270===o?n=3:180===o||-180===o?n=2:270!==o&&-90!==o||(n=1);for(var a=0;a<n;a++)t.notify("shape",{prop:"rotateObjColl",onPropertyChange:!1}),t.notify("freehand-draw",{prop:"rotateFhdColl",onPropertyChange:!1});var s=e.extend({},t.objColl[t.objColl.length-1],{},!0);if(""!==t.transform.currFlipState){a=0;for(var l=t.objColl.length;a<l;a++)t.objColl[a].shapeFlip="";for(a=0;a<t.freehandCounter;a++)t.pointColl[a].shapeFlip="";t.transform.degree=o;var p=this.getCurrCropState("initial");t.transform.degree=0,t.notify("shape",{prop:"redrawObj",onPropertyChange:!1,value:{degree:p}}),t.notify("freehand-draw",{prop:"flipFHDColl",onPropertyChange:!1,value:{value:p}})}t.notify("shape",{prop:"zoomObjColl",onPropertyChange:!1,value:{isPreventApply:null}}),t.notify("freehand-draw",{prop:"zoomFHDColl",onPropertyChange:!1,value:{isPreventApply:null}}),s=e.extend({},t.objColl[t.objColl.length-1],{},!0),this.upperContext.clearRect(0,0,t.upperCanvas.width,t.upperCanvas.height),t.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate",obj:s}}),t.objColl.pop(),t.transform.degree=0,this.cropImg(!0),t.notify("transform",{prop:"setReverseRotate",onPropertyChange:!1,value:{bool:!0}}),this.lowerContext.setTransform(1,0,0,1,0,0),t.transform.degree=o,t.notify("draw",{prop:"setDestPoints",onPropertyChange:!1}),t.notify("draw",{prop:"currTransState",onPropertyChange:!1,value:{type:"initial",isPreventDestination:null,context:null,isPreventCircleCrop:null}}),t.notify("finetune",{prop:"updateBrightFilter",onPropertyChange:!1}),this.lowerContext.drawImage(t.baseImg,t.img.srcLeft,t.img.srcTop,t.img.srcWidth,t.img.srcHeight,t.img.destLeft,t.img.destTop,t.img.destWidth,t.img.destHeight),this.lowerContext.filter=r,t.notify("draw",{prop:"currTransState",onPropertyChange:!1,value:{type:"reverse",isPreventDestination:null,context:null,isPreventCircleCrop:null}}),n=0,90===o||-270===o?n=1:180===o||-180===o?n=2:270!==o&&-90!==o||(n=3);for(a=0;a<n;a++)t.notify("shape",{prop:"rotateObjColl",onPropertyChange:!1}),t.notify("freehand-draw",{prop:"rotateFhdColl",onPropertyChange:!1});if(""!==this.getCurrFlipState()){for(a=0,l=t.objColl.length;a<l;a++)t.objColl[a].shapeFlip="";for(a=0;a<t.freehandCounter;a++)t.pointColl[a].shapeFlip="";p=this.getCurrCropState("reverse");t.notify("shape",{prop:"redrawObj",onPropertyChange:!1,value:{degree:p}}),t.notify("freehand-draw",{prop:"flipFHDColl",onPropertyChange:!1,value:{value:p}})}t.notify("transform",{prop:"setReverseRotate",onPropertyChange:!1,value:{bool:!1}}),this.lowerContext.filter="none";for(a=0,l=t.objColl.length;a<l;a++)this.isObjInImage(t.objColl[a])&&(t.notify("shape",{prop:"apply",onPropertyChange:!1,value:{shape:t.objColl[a].shape,obj:t.objColl[a],canvas:null}}),t.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}));t.notify("freehand-draw",{prop:"zoomFHDColl",onPropertyChange:!1,value:{isPreventApply:null}}),this.lowerContext.filter=r,t.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.lowerContext}}),t.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.upperContext}}),"crop-circle"===i&&this.cropCircle(this.lowerContext),this.upperContext.clearRect(0,0,t.upperCanvas.width,t.upperCanvas.height),t.notify("draw",{prop:"resetPanPoints",onPropertyChange:!1})},t.prototype.flipCrop=function(){var t=this.parent;t.notify("transform",{prop:"setReverseFlip",onPropertyChange:!1,value:{isReverseFlip:!0}}),t.panPoint.totalPannedPoint.x+=this.tempFlipPanPoint.x,t.panPoint.totalPannedPoint.y+=this.tempFlipPanPoint.y;var i=t.transform.currFlipState,o={flipColl:null};t.notify("transform",{prop:"getFlipColl",onPropertyChange:!1,value:{obj:o}});var r=o.flipColl;if(t.notify("transform",{prop:"setFlipColl",onPropertyChange:!1,value:{flipColl:[]}}),t.notify("shape",{prop:"updImgRatioForActObj",onPropertyChange:!1}),t.objColl.push(t.activeObj),t.transform.zoomFactor>0){for(var n=t.transform.zoomFactor,a=t.isUndoRedo,s=0;s<10*n;s++)t.isUndoRedo=!0,t.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:-.1,zoomPoint:null}});t.isUndoRedo=a,t.notify("draw",{prop:"resetPanPoints",onPropertyChange:!1})}t.currSelectionPoint=e.extend({},t.objColl[t.objColl.length-1],{},!0),this.lowerContext.clearRect(0,0,t.lowerCanvas.width,t.lowerCanvas.height),this.upperContext.clearRect(0,0,t.upperCanvas.width,t.upperCanvas.height);var l=this.lowerContext.filter;t.notify("finetune",{prop:"updateBrightFilter",onPropertyChange:!1}),this.lowerContext.drawImage(t.baseImg,t.img.srcLeft,t.img.srcTop,t.img.srcWidth,t.img.srcHeight,t.img.destLeft,t.img.destTop,t.img.destWidth,t.img.destHeight);s=0;for(var p=t.objColl.length;s<p;s++)t.objColl[s].shapeFlip="";for(s=0;s<t.freehandCounter;s++)t.pointColl[s].shapeFlip="";t.notify("shape",{prop:"redrawObj",onPropertyChange:!1,value:{degree:this.getCurrFlipState()}}),t.notify("freehand-draw",{prop:"flipFHDColl",onPropertyChange:!1,value:{value:this.getCurrFlipState()}}),t.activeObj=e.extend({},t.objColl[t.objColl.length-1],{},!0),t.objColl.pop(),this.upperContext.clearRect(0,0,t.upperCanvas.width,t.upperCanvas.height),t.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate"}}),this.cropImg(!0),t.notify("transform",{prop:"setReverseRotate",onPropertyChange:!1,value:{bool:!0}}),this.lowerContext.setTransform(1,0,0,1,0,0),t.notify("draw",{prop:"setDestPoints",onPropertyChange:!1}),t.notify("draw",{prop:"currTransState",onPropertyChange:!1,value:{type:"initial",isPreventDestination:null,context:null,isPreventCircleCrop:null}}),t.notify("finetune",{prop:"updateBrightFilter",onPropertyChange:!1}),this.lowerContext.drawImage(t.baseImg,t.img.srcLeft,t.img.srcTop,t.img.srcWidth,t.img.srcHeight,t.img.destLeft,t.img.destTop,t.img.destWidth,t.img.destHeight),this.lowerContext.filter=l,t.notify("draw",{prop:"setRotateZoom",onPropertyChange:!1,value:{isRotateZoom:!1}}),t.notify("draw",{prop:"currTransState",onPropertyChange:!1,value:{type:"reverse",isPreventDestination:null,context:null,isPreventCircleCrop:null}}),t.transform.currFlipState=i,t.notify("transform",{prop:"setFlipColl",onPropertyChange:!1,value:{flipColl:r}}),this.lowerContext.filter="none";for(s=0,p=t.objColl.length;s<p;s++)t.objColl[s].shapeFlip="";for(s=0;s<t.freehandCounter;s++)t.pointColl[s].shapeFlip="";t.notify("shape",{prop:"redrawObj",onPropertyChange:!1,value:{degree:this.getCurrFlipState()}}),t.notify("freehand-draw",{prop:"flipFHDColl",onPropertyChange:!1,value:{value:this.getCurrFlipState()}}),t.notify("shape",{prop:"zoomObjColl",onPropertyChange:!1,value:{isPreventApply:null}}),t.notify("freehand-draw",{prop:"zoomFHDColl",onPropertyChange:!1,value:{isPreventApply:null}}),this.lowerContext.filter=l,(t.currSelectionPoint&&"crop-circle"===t.currSelectionPoint.shape||t.isCircleCrop)&&this.cropCircle(this.lowerContext),t.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),t.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.lowerContext}}),t.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.upperContext}}),this.upperContext.clearRect(0,0,t.upperCanvas.width,t.upperCanvas.height),t.notify("transform",{prop:"setReverseFlip",onPropertyChange:!1,value:{isReverseFlip:!1}}),t.notify("draw",{prop:"resetPanPoints",onPropertyChange:!1}),this.tempFlipPanPoint={x:0,y:0}},t.prototype.cropObjColl=function(){var t,e,i,o=this.parent;if(o.objColl.length>0)for(var r=0,n=o.objColl.length;r<n;r++){t=o.objColl[r].activePoint,e=o.activeObj.activePoint,i=o.objColl[r].shape,o.objColl[r].imageRatio={startX:(t.startX-e.startX)/e.width,startY:(t.startY-e.startY)/e.height,endX:(t.endX-e.startX)/e.width,endY:(t.endY-e.startY)/e.height,width:e.width/t.width,height:e.height/t.height};var a=void 0,s=void 0;switch(i){case"text":s=0===(a=0===o.objColl[r].shapeDegree?this.parent.transform.degree:this.parent.transform.degree-o.objColl[r].shapeDegree)||180===Math.abs(a)?t.width:t.height,o.objColl[r].textSettings.fontRatio=s/o.objColl[r].textSettings.fontSize;break;case"line":case"arrow":this.cropPointCollection(r),"arrow"===i&&o.notify("shape",{prop:"updateArrowRatio",onPropertyChange:!1,value:{obj:o.objColl[r]}});break;case"path":this.cropPointCollection(r)}}},t.prototype.cropPointCollection=function(t){var e,i,o,r,n=this.parent,a=n.objColl[t].shape,s=n.activeObj.activePoint;"path"===a?(e=s.startX,i=s.startY,o=s.width,r=s.height):(e=n.img.destLeft,i=n.img.destTop,o=n.img.destWidth,r=n.img.destHeight);for(var l=n.objColl[t],p=0,h=l.pointColl.length;p<h;p++)l.pointColl[p].ratioX=(l.pointColl[p].x-e)/o,l.pointColl[p].ratioY=(l.pointColl[p].y-i)/r},t.prototype.cropFreehandDrawColl=function(){for(var t=this.parent,i=0;i<t.freehandCounter;i++){t.points=e.extend([],t.pointColl[i].points,[]),t.notify("freehand-draw",{prop:"setPointCounter",onPropertyChange:!1,value:{value:0}});for(var o=t.points.length,r=0;r<o;r++)t.points[r].ratioX=(t.points[r].x-t.activeObj.activePoint.startX)/t.activeObj.activePoint.width,t.points[r].ratioY=(t.points[r].y-t.activeObj.activePoint.startY)/t.activeObj.activePoint.height}t.notify("freehand-draw",{prop:"updateCropPtsForSel",onPropertyChange:!1})},t.prototype.setCurrSelPoints=function(t){var i=this.parent,o=this.cropDestPoints;if(i.img.srcLeft=0,i.img.srcTop=0,i.img.srcWidth=i.baseImg.width,i.img.srcHeight=i.baseImg.height,i.img.destLeft=o.startX,i.img.destTop=o.startY,i.img.destWidth=o.width,i.img.destHeight=o.height,this.lowerContext.clearRect(0,0,i.lowerCanvas.width,i.lowerCanvas.height),t&&i.notify("draw",{prop:"setDestPoints",onPropertyChange:!1}),i.notify("draw",{prop:"currTransState",onPropertyChange:!1,value:{type:"initial",isPreventDestination:null,context:null,isPreventCircleCrop:null}}),0===this.croppedDegree&&0===i.transform.degree&&i.currSelectionPoint&&"crop-circle"!==i.currSelectionPoint.shape&&"crop-square"!==i.currSelectionPoint.shape&&(i.img.destLeft=o.startX,i.img.destTop=o.startY,i.img.destWidth=o.width,i.img.destHeight=o.height),0===i.transform.degree&&(i.img.destLeft+=i.panPoint.totalPannedInternalPoint.x,i.img.destTop+=i.panPoint.totalPannedInternalPoint.y),i.notify("filter",{prop:"updateBrightFilter",onPropertyChange:!1}),this.lowerContext.drawImage(i.baseImg,i.img.srcLeft,i.img.srcTop,i.img.srcWidth,i.img.srcHeight,i.img.destLeft,i.img.destTop,i.img.destWidth,i.img.destHeight),i.notify("draw",{prop:"currTransState",onPropertyChange:!1,value:{type:"reverse",isPreventDestination:null,context:null,isPreventCircleCrop:!0}}),i.cropObj.activeObj.shape){var r={startX:i.img.destLeft,startY:i.img.destTop,width:i.img.destWidth,height:i.img.destHeight};i.currSelectionPoint&&i.currSelectionPoint.activePoint&&(i.img.destLeft=i.currSelectionPoint.activePoint.startX,i.img.destTop=i.currSelectionPoint.activePoint.startY,i.img.destWidth=i.currSelectionPoint.activePoint.width,i.img.destHeight=i.currSelectionPoint.activePoint.height),i.notify("shape",{prop:"zoomObjColl",onPropertyChange:!1,value:{isPreventApply:null}}),i.notify("freehand-draw",{prop:"zoomFHDColl",onPropertyChange:!1,value:{isPreventApply:null}}),i.img.destLeft=r.startX,i.img.destTop=r.startY,i.img.destWidth=r.width,i.img.destHeight=r.height,i.notify("freehand-draw",{prop:"updateFHDColl",onPropertyChange:!1});var n=e.extend([],i.objColl,null,!0),a=e.extend([],i.pointColl,null,!0);i.objColl=[],i.pointColl=[],i.freehandCounter=0;var s={selPointColl:null};i.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:s}});var l=s.selPointColl;i.notify("freehand-draw",{prop:"setSelPointColl",onPropertyChange:!1,value:{obj:{selPointColl:[]}}}),i.cropObj.filter=this.lowerContext.filter,i.notify("draw",{prop:"setCurrentObj",onPropertyChange:!1,value:{obj:null}});var p=e.extend({},i.activeObj,null,!0);i.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),i.objColl=n,i.pointColl=a,i.freehandCounter=i.pointColl.length,i.notify("freehand-draw",{prop:"setSelPointColl",onPropertyChange:!1,value:{obj:{selPointColl:l}}}),i.notify("shape",{prop:"iterateObjColl",onPropertyChange:!1}),i.notify("freehand-draw",{prop:"freehandRedraw",onPropertyChange:!1,value:{context:this.lowerContext,points:null}}),i.notify("freehand-draw",{prop:"updateFHDColl",onPropertyChange:!1}),i.notify("shape",{prop:"zoomObjColl",onPropertyChange:!1,value:{isPreventApply:null}}),i.notify("freehand-draw",{prop:"zoomFHDColl",onPropertyChange:!1,value:{isPreventApply:null}}),i.currSelectionPoint=null,0===i.transform.degree&&i.notify("transform",{prop:"drawPannImage",onPropertyChange:!1,value:{point:{x:0,y:0}}}),i.activeObj=p,i.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate"}}),i.notify("transform",{prop:"setTempPanMove",onPropertyChange:!1,value:{point:null}})}else{var h=this.lowerContext.filter;this.lowerContext.filter="none",i.notify("shape",{prop:"iterateObjColl",onPropertyChange:!1}),i.notify("freehand-draw",{prop:"freehandRedraw",onPropertyChange:!1,value:{context:this.lowerContext,points:null}}),this.lowerContext.filter=h,i.currSelectionPoint=null}},t.prototype.cropCircle=function(t,i,o){var r=this.parent;o&&""!==r.transform.currFlipState&&r.notify("draw",{prop:"setTransform",onPropertyChange:!1,value:{context:t,value:r.transform.currFlipState,isReverse:null}}),t.globalCompositeOperation="destination-in",t.beginPath();var n=e.isNullOrUndefined(i)?r.img.destLeft+r.img.destWidth/2:r.img.destWidth/2,a=e.isNullOrUndefined(i)?r.img.destTop+r.img.destHeight/2:r.img.destHeight/2,s=r.img.destWidth/2;t.arc(n,a,s,0,2*Math.PI),t.closePath(),t.fill(),t.restore(),t.globalCompositeOperation="source-over",r.currObjType.isActiveObj=r.isCircleCrop=!0,o&&""!==r.transform.currFlipState&&r.notify("draw",{prop:"setTransform",onPropertyChange:!1,value:{context:t,value:r.transform.currFlipState,isReverse:null}})},t.prototype.getCurrCropState=function(t,e){var i=this.parent,o="",r=[],n={flipColl:null};if(i.notify("transform",{prop:"getFlipColl",onPropertyChange:!1,value:{obj:n}}),"initial"===t)if(180===Math.abs(i.transform.degree))o=n.flipColl.length>1?this.getCurrFlipState():i.transform.currFlipState;else{for(var a=0,s=i.rotateFlipColl.length;a<s;a++)"number"==typeof i.rotateFlipColl[a]?r.push("number"):"string"==typeof i.rotateFlipColl[a]&&r.push("string");r.length>1&&"string"===r[r.length-1]&&"number"===r[r.length-2]?"horizontal"===i.transform.currFlipState?o="vertical":"vertical"===i.transform.currFlipState&&(o="horizontal"):r.length>1&&"number"===r[r.length-1]&&"string"===r[r.length-2]&&(o=n.flipColl.length>1?this.getCurrFlipState():i.transform.currFlipState)}else o=this.getCurrFlipState(),!e&&this.isInitialRotate()||-90!==i.transform.degree&&-270!==i.transform.degree||("horizontal"===o?o="vertical":"vertical"===o&&(o="horizontal"));return""===o&&(o=n.flipColl.length>1?this.getCurrFlipState():i.transform.currFlipState),o},t.prototype.isInitialRotate=function(){var t=!1;return this.parent.rotateFlipColl.length>0&&"number"==typeof this.parent.rotateFlipColl[0]&&(t=!0),t},t.prototype.updateRotatePan=function(){var t=this.parent;if(!e.isNullOrUndefined(t.panPoint.currentPannedPoint)){var i="";i=t.rotateFlipColl.length>0&&"number"==typeof t.rotateFlipColl[0]&&t.transform.degree<0?this.getCurrCropState("reverse",!0):this.getCurrFlipState(),t.transform.degree%90==0&&t.transform.degree%180!=0?90===t.transform.degree||-90===t.transform.degree&&("horizontal"===i||"vertical"===i)||-270===t.transform.degree&&(""===i||"verticalHorizontal"===i||"horizontalVertical"===i)?("horizontal"===i||""===i?t.img.destLeft+=t.panPoint.currentPannedPoint.y:t.img.destLeft-=t.panPoint.currentPannedPoint.y,""===i||"vertical"===i?t.img.destTop-=t.panPoint.currentPannedPoint.x:t.img.destTop+=t.panPoint.currentPannedPoint.x):270!==t.transform.degree&&(-270!==t.transform.degree||"horizontal"!==i&&"vertical"!==i)&&(-90!==t.transform.degree||""!==i&&"verticalHorizontal"!==i&&"horizontalVertical"!==i)||(""===i||"horizontal"===i?t.img.destLeft-=t.panPoint.currentPannedPoint.y:t.img.destLeft+=t.panPoint.currentPannedPoint.y,""===i||"vertical"===i?t.img.destTop+=t.panPoint.currentPannedPoint.x:t.img.destTop-=t.panPoint.currentPannedPoint.x):180!==t.transform.degree&&-180!==t.transform.degree||(""===i||"vertical"===i?t.img.destLeft-=t.panPoint.currentPannedPoint.x:t.img.destLeft+=t.panPoint.currentPannedPoint.x,""===i||"horizontal"===i?t.img.destTop-=t.panPoint.currentPannedPoint.y:t.img.destTop+=t.panPoint.currentPannedPoint.y)}},t.prototype.crop=function(t){var i=this,o=this.parent;if(!o.disabled&&o.isImageLoaded){var r={isCropToolbar:o.isCropToolbar};o.currObjType.isUndoAction&&!r.isCropToolbar&&o.notify("undo-redo",{prop:"refreshUrc",value:{bool:null}});var n={cancel:!1,startPoint:{x:o.activeObj.activePoint.startX,y:o.activeObj.activePoint.startY},endPoint:{x:o.activeObj.activePoint.endX,y:o.activeObj.activePoint.endY}};!r.isCropToolbar&&e.isBlazor()&&o.events&&!0===o.events.cropping.hasDelegate?o.dotNetRef.invokeMethodAsync("CropEventAsync","OnCrop",n).then(function(e){i.cropEvent(e,t,r)}):(r.isCropToolbar||o.trigger("cropping",n),this.cropEvent(n,t,r))}},t.prototype.cropEvent=function(t,i,o){var r,n=this.parent;if(!t.cancel&&(r=n.activeObj.shape?n.activeObj.shape.split("-"):[],!n.disabled&&n.activeObj.horTopLine&&(n.currObjType.isCustomCrop||r.length>0&&"crop"===r[0]))){i.isCrop=!0;var a=e.extend({},n.cropObj,{},!0),s=e.extend({},this.prevCropCurrObj,{},!0);this.cropImg(),n.transform.zoomFactor=0,n.zoomSettings.zoomFactor=1,n.setProperties({zoomSettings:{zoomFactor:1}},!0),n.notify("transform",{prop:"setPreviousZoomValue",onPropertyChange:!1,value:{previousZoomValue:n.zoomSettings.zoomFactor}});var l={prevCurrSelectionPoint:this.parent.prevCurrSelectionPoint};s.currSelectionPoint=e.extend({},l.prevCurrSelectionPoint,{},!0),n.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"crop",previousObj:s,previousObjColl:s.objColl,previousPointColl:s.pointColl,previousSelPointColl:s.selPointColl,previousCropObj:a,previousText:null,currentText:null,previousFilter:null,isCircleCrop:n.isCircleCrop}}),o.isCropToolbar||n.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"ok"}}),n.notify("transform",{prop:"setCropDimension",onPropertyChange:!1,value:{width:n.cropObj.destPoints.width,height:n.cropObj.destPoints.height}}),e.isBlazor()||o.isCropToolbar?o.isCropToolbar||this.parent.updateToolbar(this.parent.element,"imageLoaded"):n.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"main",isApplyBtn:!1,isCropping:!1,isZooming:null,cType:null}})}},t.prototype.calcRatio=function(t){var e,i,o=this.parent;return 0===o.transform.degree||o.transform.degree%180==0?(e=o.baseImg.width/o.img.destWidth,i=o.baseImg.height/o.img.destHeight):(e=o.baseImg.height/o.img.destWidth,i=o.baseImg.width/o.img.destHeight),t&&(t.width=e,t.height=i),{width:e,height:i}},t.prototype.isObjInImage=function(t,e){var i=this.parent,o=!1,r=t.activePoint.startX,n=t.activePoint.endX,a=t.activePoint.startY,s=t.activePoint.endY;return(r>=i.img.destLeft&&n<=i.img.destLeft+i.img.destWidth||r<=i.img.destLeft&&n>=i.img.destLeft||r<=i.img.destLeft+i.img.destWidth&&n>=i.img.destLeft+i.img.destWidth||a>=i.img.destTop&&s<=i.img.destTop+i.img.destHeight||a<=i.img.destTop&&s>=i.img.destTop||a<=i.img.destTop+i.img.destHeight&&s>=i.img.destTop+i.img.destHeight)&&(o=!0),e&&(e.isInside=o),o},t.prototype.getCurrFlipState=function(t){var e=this.parent,i={panRegion:""},o={collection:e.rotateFlipColl};e.notify("shape",{prop:"alignRotateFlipColl",onPropertyChange:!1,value:{collection:e.rotateFlipColl,isRotateFlipCollection:!0,obj:o}}),e.rotateFlipColl=o.collection;for(var r=0,n=e.rotateFlipColl.length;r<n;r++)e.notify("transform",{prop:"setCurrPanRegion",onPropertyChange:!1,value:{region:i.panRegion,type:e.rotateFlipColl[r],obj:i}});return t&&(t.panRegion=i.panRegion),i.panRegion},t}(),s=function(){function t(t){this.cancelObjColl=[],this.cancelPointColl=[],this.isInitialLoading=!1,this.fileName="",this.isErrorImage=!1,this.isShapeTextInserted=!1,this.isRotateZoom=!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.tempAdjValue="",this.tempFilter="",this.tempUndoRedoStep=0,this.tempFreehandCounter=0,this.tempCurrFhdIndex=0,this.tempZoomFactor=null,this.isCancelAction=!1,this.rotatedFlipCropSel=!1,this.zoomCrop={width:0,height:0},this.isImageEdited=!1,this.isFileChanged=!1,this.isNewPath=!1,this.arrowDimension={bar:{width:10,height:32,ratioX:null,ratioY:null},arrow:{width:24,height:24,ratioX:null,ratioY:null},arrowSolid:{width:32,height:32,ratioX:null,ratioY:null},circle:{width:10,height:10,ratioX:null,ratioY:null},square:{width:20,height:20,ratioX:null,ratioY:null}},this.parent=t,this.addEventListener()}return t.prototype.destroy=function(){this.parent.isDestroyed||this.removeEventListener()},t.prototype.addEventListener=function(){this.parent.on("draw",this.draw,this),this.parent.on("destroyed",this.destroy,this)},t.prototype.removeEventListener=function(){this.parent.off("draw",this.draw),this.parent.off("destroyed",this.destroy)},t.prototype.draw=function(t){switch(this.updatePrivateVariables(),t.prop){case"drawObject":this.drawObject(t.value.canvas,t.value.obj,t.value.isCropRatio,t.value.points,t.value.isPreventDrag,t.value.saveContext,t.value.isPreventSelection);break;case"updateActiveObject":this.updateActiveObject(t.value.actPoint,t.value.obj,t.value.isMouseMove,t.value.x,t.value.y);break;case"clearOuterCanvas":this.clearOuterCanvas(t.value.context);break;case"setDestPoints":this.setDestPoints();break;case"updateCurrTransState":this.updateCurrTransState(t.value.type,t.value.isPreventDestination,t.value.isRotatePan);break;case"currTransState":this.currTransState(t.value.type,t.value.isPreventDestination,t.value.context,t.value.isPreventCircleCrop);break;case"setTransform":this.setTransform(t.value.context,t.value.value,t.value.isReverse);break;case"render-image":this.renderImage(t.value.isMouseWheel);break;case"draw-image-to-canvas":this.drawImgToCanvas(t.value.dimension);break;case"update-canvas":this.updateCanvas();break;case"performCancel":this.performCancel(t.value.isContextualToolbar);break;case"updateFlipPan":this.updateFlipPan(t.value.tempSelectionObj);break;case"select":this.select(t.value.type,t.value.startX,t.value.startY,t.value.width,t.value.height);break;case"callUpdateCurrTransState":this.callUpdateCurrTransState();break;case"resetPanPoints":this.resetPanPoints();break;case"setClientTransDim":this.setClientTransDim(t.value.isPreventDimension);break;case"redrawImgWithObj":this.redrawImgWithObj();break;case"setCurrentObj":this.setCurrentObj(t.value.obj);break;case"performPointZoom":this.performPointZoom(t.value.x,t.value.y,t.value.type);break;case"open":this.open(t.value.data);break;case"isInitialLoading":this.isInitialLoading=t.value.isInitialLoading;break;case"isInitialLoaded":this.getInitialLoaded(t.value.object);break;case"fileSelect":this.fileSelect(t.value.inputElement,t.value.args);break;case"getFileName":t.value.obj.fileName=this.fileName,t.value.obj.fileType=this.fileType;break;case"getErrorImage":t.value.obj.isErrorImage=this.isErrorImage;break;case"getInitialZoomValue":t.value.obj.initialZoomValue=this.initZoomValue;break;case"setShapeTextInsert":this.isShapeTextInserted=t.value.bool;break;case"resetCurrentSelectionPoint":this.currSelPoint=null;break;case"setRotateZoom":this.isRotateZoom=t.value.isRotateZoom;break;case"setTempStrokeSettings":this.tempStrokeSettings=t.value.tempStrokeSettings;break;case"setTempTextSettings":this.tempTextSettings=t.value.tempTextSettings;break;case"setTempAdjustmentValue":this.tempAdjValue=t.value.tempAdjustmentValue;break;case"getTempAdjustmentValue":t.value.obj.value=this.tempAdjValue;break;case"setTempFilter":this.tempFilter=t.value.tempFilter;break;case"setTempUndoRedoStep":this.tempUndoRedoStep=t.value.tempUndoRedoStep;break;case"setTempFreehandCounter":this.tempFreehandCounter=t.value.tempFreehandCounter;break;case"setTempCurrentFreehandDrawIndex":this.tempCurrFhdIndex=t.value.tempCurrentFreehandDrawIndex;break;case"setTempZoomFactor":this.tempZoomFactor=t.value.tempZoomFactor;break;case"setCancelAction":this.isCancelAction=t.value.bool;break;case"getRotatedFlipCropSelection":t.value.bool.isSelected=this.rotatedFlipCropSel;break;case"getPrevActObj":t.value.obj.prevActObj=this.prevActObj;break;case"setPrevActObj":this.prevActObj=t.value.prevActObj;break;case"getZoomCrop":t.value.obj.width=this.zoomCrop.width,t.value.obj.height=this.zoomCrop.height;break;case"setZoomCropWidth":this.zoomCrop.width=t.value.width,this.zoomCrop.height=t.value.height;break;case"setImageEdited":this.isImageEdited=!0;break;case"reset":this.reset();break;case"dlgBtnClick":this.dlgBtnClick();break;case"dlgCloseBtnClick":this.dlgCloseBtnClick();break;case"setNewPath":this.isNewPath=t.value.bool;break;case"getNewPath":t.value.obj.isNewPath=this.isNewPath;break;case"getArrowDimension":t.value.obj.arrowDimension=this.arrowDimension;break;case"setArrowDimension":this.arrowDimension=t.value.arrowDimension}},t.prototype.getModuleName=function(){return"draw"},t.prototype.updatePrivateVariables=function(){var t=this.parent;t.lowerCanvas&&(this.lowerContext=t.lowerCanvas.getContext("2d")),t.upperCanvas&&(this.upperContext=t.upperCanvas.getContext("2d")),e.isNullOrUndefined(this.tempZoomFactor)&&(this.tempZoomFactor=t.transform.zoomFactor)},t.prototype.reset=function(){this.isInitialLoading=this.isErrorImage=this.isNewPath=!1,this.cancelObjColl=this.cancelPointColl=[],this.isShapeTextInserted=!1,this.initZoomValue=null,this.tempFilter="",this.currSelPoint=null,this.isRotateZoom=!1,this.tempAdjValue="",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.tempUndoRedoStep=this.tempFreehandCounter=this.tempCurrFhdIndex=0,this.tempZoomFactor=null,this.isCancelAction=!1,this.rotatedFlipCropSel=!1,this.prevActObj=null,this.arrowDimension={bar:{width:10,height:32,ratioX:null,ratioY:null},arrow:{width:24,height:24,ratioX:null,ratioY:null},arrowSolid:{width:32,height:32,ratioX:null,ratioY:null},circle:{width:10,height:10,ratioX:null,ratioY:null},square:{width:20,height:20,ratioX:null,ratioY:null}}},t.prototype.drawObject=function(t,i,o,r,n,a,s){var l=this.parent,p=l.activeObj.activePoint;this.upperContext.clearRect(0,0,l.upperCanvas.width,l.upperCanvas.height);var h;if("original"===t.toLowerCase()?h=this.lowerContext:"duplicate"===t.toLowerCase()?h=this.upperContext:a&&(h=a),!n&&l.activeObj.shape&&this.setDragLimit(),l.currObjType.shape){"crop"===l.currObjType.shape.split("-")[0].toLowerCase()&&o&&this.drawCropRatio()}if(r&&(p.startX=r.startX,p.startY=r.startY,p.endX=r.endX,p.endY=r.endY,p.width=r.width,p.height=r.height),e.isNullOrUndefined(l.activeObj.strokeSettings)){var c={strokeSettings:{}};l.notify("shape",{prop:"getStrokeSettings",onPropertyChange:!1,value:{obj:c}}),l.activeObj.strokeSettings=c.strokeSettings}if(e.isNullOrUndefined(l.activeObj.strokeSettings.strokeWidth)&&(l.activeObj.strokeSettings.strokeWidth=2),i&&(l.activeObj=e.extend({},i,{},!0)),this.updateActiveObject(),l.currObjType.isText){var d={keyHistory:""};l.notify("shape",{prop:"getKeyHistory",onPropertyChange:!1,value:{obj:d}}),l.activeObj.keyHistory=d.keyHistory}if("original"!==t.toLowerCase()){var v=!1;l.activeObj.shape&&"crop"===l.activeObj.shape.split("-")[0]&&(v=!0),v&&(this.upperContext.fillStyle="rgb(0, 0, 0, 0.25)",this.upperContext.fillRect(0,0,l.lowerCanvas.width,l.lowerCanvas.height),this.upperContext.clearRect(p.startX,p.startY,p.width,p.height)),!e.isNullOrUndefined(s)||h!==this.lowerContext&&h!==this.upperContext||(this.rotateContext("initial",h),this.drawOuterSelection(h),this.rotateContext("reverse",h))}l.currObjType.isActiveObj=!0;var u={keyHistory:""};l.notify("shape",{prop:"getKeyHistory",onPropertyChange:!1,value:{obj:u}}),i?this.drawShapeObj(t,i.shape,a,s):""!==u.keyHistory&&l.currObjType.isText?this.drawShapeObj(t,"text",a,s):l.activeObj.shape?this.drawShapeObj(t,l.activeObj.shape,a,s):this.drawShapeObj(t,void 0,a,s)},t.prototype.rotateContext=function(t,i){var o=this.parent,r=e.extend({},o.activeObj.activePoint,{},!0);if("line"!==o.activeObj.shape&&"arrow"!==o.activeObj.shape){var n="initial"===t?o.activeObj.rotatedAngle:-o.activeObj.rotatedAngle;i.translate(r.startX+r.width/2,r.startY+r.height/2),i.rotate(n),i.translate(-(r.startX+r.width/2),-(r.startY+r.height/2))}},t.prototype.setDragLimit=function(){var t=this.parent,e=t.activeObj.activePoint;e&&0===t.activeObj.rotatedAngle&&(e.startX<t.img.destLeft?(e.startX=t.img.destLeft,e.endX=e.startX+e.width):e.endX>t.img.destLeft+t.img.destWidth&&(e.endX=t.img.destLeft+t.img.destWidth,e.startX=e.endX-e.width),e.startY<t.img.destTop?e.startY=t.img.destTop:e.endY>t.img.destTop+t.img.destHeight&&(e.endY=t.img.destTop+t.img.destHeight,e.startY=e.endY-e.height),t.activeObj=this.updateWidthHeight(t.activeObj))},t.prototype.drawCropRatio=function(){var t,i,o,r,n=this.parent,a=n.activeObj.activePoint;if(n.transform.zoomFactor>0&&this.currSelPoint){var s=e.extend({},n.activeObj,{},!0);this.drawCustomSelection("crop-custom",null,null,null,null),n.transform.degree%90==0&&n.transform.degree%180!=0?r=o=n.activeObj.activePoint.width<n.activeObj.activePoint.height?n.activeObj.activePoint.width:n.activeObj.activePoint.height:(o=n.img.destLeft+n.img.destLeft+n.img.destWidth<=n.lowerCanvas.clientWidth?a.width:n.lowerCanvas.clientWidth-n.img.destLeft,r=n.img.destTop+n.img.destTop+n.img.destHeight<=n.lowerCanvas.clientHeight?a.height:n.lowerCanvas.clientHeight-n.img.destTop),n.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),n.activeObj=s,n.currObjType.shape=s.shape,this.upperContext.clearRect(0,0,n.upperCanvas.width,n.upperCanvas.height),n.currObjType.isCustomCrop=!1}else o=n.img.destWidth,r=n.img.destHeight,n.img.destLeft<0&&(o+=n.img.destLeft),n.img.destTop<0&&(r+=n.img.destTop),"crop-square"!==n.currObjType.shape.toLowerCase()&&"crop-circle"!==n.currObjType.shape.toLowerCase()&&(n.img.destLeft+n.img.destWidth>n.lowerCanvas.width&&(o-=n.img.destLeft+n.img.destWidth-n.lowerCanvas.width),n.img.destTop+n.img.destHeight>n.lowerCanvas.height&&(r-=n.img.destTop+n.img.destHeight-n.lowerCanvas.height));switch(n.currObjType.shape.toLowerCase()){case"crop-square":case"crop-circle":n.notify("selection",{prop:"setDragDirection",onPropertyChange:!1,value:{width:o,height:r}}),a=n.activeObj.activePoint,n.lowerCanvas.width<a.endX-a.startX&&(a.startX=7.5,a.endX=n.lowerCanvas.width-7.5),n.lowerCanvas.height<a.endY-a.startY&&(a.startY=7.5,a.endY=n.lowerCanvas.height-7.5),o===n.img.destWidth&&r===n.img.destHeight&&(a.startX+=n.img.destLeft,a.startY+=n.img.destTop,a.endX+=n.img.destLeft,a.endY+=n.img.destTop),n.lowerCanvas.width>n.lowerCanvas.height?(a.height=a.endY-a.startY,a.width=a.height,a.endX=a.startX+a.width):(a.width=a.endX-a.startX,a.height=a.width,a.endY=a.startY+a.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&&(n.notify("selection",{prop:"calcShapeRatio",onPropertyChange:!1,value:{x:t,y:i,imgWidth:o,imgHeight:r}}),o===n.img.destWidth&&r===n.img.destHeight&&this.updatePoints(),a=n.activeObj.activePoint),a.startX<n.img.destLeft){var l=n.img.destLeft-a.startX+7.5;a.startX+=l,a.endX+=l}if(a.startY<n.img.destTop){l=n.img.destTop-a.startY+7.5;a.startY+=l,a.endY+=l}n.activeObj=this.updateWidthHeight(n.activeObj),this.adjToCenter()},t.prototype.adjToCenter=function(){var t=this.parent,e=t.lowerCanvas.width/2-(t.activeObj.activePoint.endX-t.activeObj.activePoint.width/2),i=t.lowerCanvas.height/2-(t.activeObj.activePoint.endY-t.activeObj.activePoint.height/2);if(t.activeObj.activePoint.startX+=e,t.activeObj.activePoint.endX+=e,t.activeObj.activePoint.startY+=i,t.activeObj.activePoint.endY+=i,t.activeObj.activePoint.startX<(t.img.destLeft>=7.5?t.img.destLeft:7.5)){var o=(t.img.destLeft>=7.5?t.img.destLeft:0)-t.activeObj.activePoint.startX+7.5;t.activeObj.activePoint.startX+=o,t.activeObj.activePoint.endX+=o}else if(t.activeObj.activePoint.endX>t.img.destLeft+t.img.destWidth){o=t.activeObj.activePoint.endX-(t.img.destLeft+t.img.destWidth)+7.5;t.activeObj.activePoint.startX-=o,t.activeObj.activePoint.endX-=o}if(t.activeObj.activePoint.startY<(t.img.destTop>7.5?t.img.destTop:7.5)){o=(t.img.destTop>7.5?t.img.destTop:0)-t.activeObj.activePoint.startY+7.5;t.activeObj.activePoint.startY+=o,t.activeObj.activePoint.endY+=o}else if(t.activeObj.activePoint.endY>t.img.destTop+t.img.destHeight){o=t.activeObj.activePoint.endY-(t.img.destTop+t.img.destHeight)+7.5;t.activeObj.activePoint.startY-=o,t.activeObj.activePoint.endY-=o}},t.prototype.updateActiveObject=function(t,i,o,r,n){t=t||e.extend({},this.parent.activeObj.activePoint,{},!0),i=i||e.extend({},this.parent.activeObj,{},!0),t.width=t.endX-t.startX,t.height=t.endY-t.startY,r=r||0,n=n||0;var a=t.width/2,s=t.height/2;i.horTopLine={startX:t.startX+r,startY:t.startY-n,endX:t.endX+r,endY:t.endY+n},i.horBottomLine={startX:t.startX-r,startY:t.endY-n,endX:t.endX-r,endY:t.endY+n},i.verLeftLine={startX:t.startX+r,startY:t.startY-n,endX:t.startX-n,endY:t.endY-n},i.verRightLine={startX:t.endX+r,startY:t.startY+n,endX:t.endX-r,endY:t.endY+n},i.topLeftCircle={startX:t.startX,startY:t.startY,radius:i.horTopLine.endX?7.5:0},i.topCenterCircle={startX:t.startX+a,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+s,radius:i.horTopLine.endX?7.5:0},i.centerRightCircle={startX:t.endX,startY:t.startY+s,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+a,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},0===i.rotatedAngle&&(i.rotationCirclePoint={x:i.bottomCenterCircle.startX,y:i.bottomCenterCircle.startY+25},i.rotationCirclePoint.ratioX=(i.rotationCirclePoint.x-this.parent.img.destLeft)/this.parent.img.destWidth,i.rotationCirclePoint.ratioY=(i.rotationCirclePoint.y-this.parent.img.destTop)/this.parent.img.destHeight),i.activePoint=t,e.isNullOrUndefined(o)&&(this.parent.activeObj=e.extend({},i,{},!0))},t.prototype.drawOuterSelection=function(t,i){var o,r=this.parent,n=r.activeObj.activePoint;t.lineWidth=.5,void 0!==r.activeObj.shape&&(o=r.activeObj.shape.split("-"));var a=e.extend({},r.activeObj,{},!0);void 0!==r.activeObj.shape&&(o=r.activeObj.shape.split("-")),(void 0===o||"crop"!==o[0])&&void 0!==r.activeObj.shape||i||(this.upperContext.fillStyle="rgb(0, 0, 0, 0.25)",this.upperContext.fillRect(0,0,r.lowerCanvas.width,r.lowerCanvas.height),this.upperContext.clearRect(n.startX,n.startY,n.width,n.height)),t.strokeStyle=r.themeColl[r.theme].primaryColor,t.fillStyle=r.themeColl[r.theme].secondaryColor;var s;if((s=0===a.shapeDegree?r.transform.degree:r.transform.degree-a.shapeDegree)<0&&(s=360+s),"arrow"===r.activeObj.shape||"line"===r.activeObj.shape)t.beginPath(),t.moveTo(n.startX,n.startY),t.lineTo(n.endX,n.endY),t.stroke();else if("path"===r.activeObj.shape){t.beginPath();var l=e.extend({},r.activeObj,{},!0);if(t.moveTo(l.pointColl[0].x,l.pointColl[0].y),l.pointColl.length>1)for(var p=1,h=l.pointColl.length;p<h;p++)n.endX=l.pointColl[p].x,n.endY=l.pointColl[p].y,t.lineTo(n.endX,n.endY);var c={shape:null};r.notify("selection",{prop:"getCurrentDrawingShape",value:{obj:c}}),"path"===c.shape&&(r.activeObj=l),t.lineTo(n.endX,n.endY),t.stroke()}else if(t.beginPath(),t.rect(a.activePoint.startX,a.activePoint.startY,a.activePoint.width,a.activePoint.height),t.stroke(),t.closePath(),r.selectionSettings.showCircle){var d=t.strokeStyle,v=t.fillStyle;t.strokeStyle=r.selectionSettings.strokeColor,t.fillStyle=r.selectionSettings.fillColor,t.lineWidth*=2,t.beginPath(),t.moveTo(a.topLeftCircle.startX,a.topLeftCircle.startY),t.arc(a.topLeftCircle.startX,a.topLeftCircle.startY,a.topLeftCircle.radius,0,2*Math.PI),t.moveTo(a.topRightCircle.startX,a.topRightCircle.startY),t.arc(a.topRightCircle.startX,a.topRightCircle.startY,a.topRightCircle.radius,0,2*Math.PI),t.moveTo(a.bottomLeftCircle.startX,a.bottomLeftCircle.startY),t.arc(a.bottomLeftCircle.startX,a.bottomLeftCircle.startY,a.bottomLeftCircle.radius,0,2*Math.PI),t.moveTo(a.bottomRightCircle.startX,a.bottomRightCircle.startY),t.arc(a.bottomRightCircle.startX,a.bottomRightCircle.startY,a.bottomRightCircle.radius,0,2*Math.PI),t.stroke(),t.fill(),t.closePath(),t.lineWidth/=2,t.strokeStyle=d,t.fillStyle=v}if(r.selectionSettings.showCircle&&(void 0===o||"crop"!==o[0])){d=t.strokeStyle,v=t.fillStyle;t.strokeStyle=r.selectionSettings.strokeColor,t.fillStyle=r.selectionSettings.fillColor,"text"===r.activeObj.shape||this.drawCenterCircles(t),t.strokeStyle=d,t.fillStyle=v}a.rotationCircleLine=r.activeObj.rotationCircleLine,r.activeObj=e.extend({},a,{},!0)},t.prototype.drawArrowHead=function(t,e){switch(e?this.parent.activeObj.start:this.parent.activeObj.end){case"arrowSolid":e?this.arrowSolid(t,!0):this.arrowSolid(t,!1);break;case"arrow":e?this.arrow(t,!0):this.arrow(t,!1);break;case"circleSolid":e?this.arrowCircleSolid(t,!0):this.arrowCircleSolid(t,!1);break;case"circle":e?this.arrowCircle(t,!0):this.arrowCircle(t,!1);break;case"bar":e?this.arrowBar(t,!0):this.arrowBar(t,!1);break;case"square":case"squareSolid":e?this.arrowSquareStart(t):this.arrowSquareEnd(t)}},t.prototype.drawShapeObj=function(t,i,o,r){var n=this.parent,a=n.activeObj.activePoint,s=void 0!==i?i:n.currObjType.shape;n.currObjType.shape=s;var l;"original"===t.toLowerCase()?l=this.lowerContext:"duplicate"===t.toLowerCase()?l=this.upperContext:o&&(l=o),"rectangle"!==n.currObjType.shape.toLowerCase()&&"ellipse"!==n.currObjType.shape.toLowerCase()&&"line"!==n.currObjType.shape.toLowerCase()&&"arrow"!==n.activeObj.shape&&"path"!==n.activeObj.shape||(n.activeObj.shape=n.currObjType.shape),l.strokeStyle=n.activeObj.strokeSettings.strokeColor,l.fillStyle="text"===i||"freehanddraw"===i?n.activeObj.strokeSettings.strokeColor:n.activeObj.strokeSettings.fillColor;var p=a.width/3,h=a.height/3,c=a.endX-a.startX,d=a.endY-a.startY;this.rotateContext("initial",l);var v,u,g=l.fillStyle;switch(n.currObjType.shape.toLowerCase()){case"rectangle":this.drawSquareLines(l),e.isNullOrUndefined(r)&&l===this.upperContext&&this.drawOuterSelection(l);break;case"ellipse":c=Math.abs(c),d=Math.abs(d),l.beginPath(),l.ellipse(a.startX+c/2,a.startY+d/2,c/2,d/2,0,0,2*Math.PI,!1),""!==n.activeObj.strokeSettings.fillColor&&(l.fillStyle=n.activeObj.strokeSettings.fillColor,l.fill()),l.ellipse(a.startX+c/2,a.startY+d/2,Math.abs(c/2-n.activeObj.strokeSettings.strokeWidth),Math.abs(d/2-n.activeObj.strokeSettings.strokeWidth),0,0,2*Math.PI,!1),l.fillStyle=n.activeObj.strokeSettings.strokeColor,l.fill("evenodd"),l.closePath(),e.isNullOrUndefined(r)&&l===this.upperContext&&this.drawOuterSelection(l);break;case"crop-circle":l===this.lowerContext&&(l=this.upperContext),this.shapeCircle(l,c,d);break;case"line":this.shapeLine(l,a.startX,a.startY,a.endX,a.endY),e.isNullOrUndefined(r)&&l===this.upperContext&&this.drawOuterSelection(l);break;case"arrow":(v=0===n.activeObj.shapeDegree?n.transform.degree:n.transform.degree-n.activeObj.shapeDegree)<0&&(v=360+v),l.fillStyle=l.strokeStyle,e.isNullOrUndefined(n.activeObj.triangleDirection)&&(n.activeObj.triangleDirection="right"),e.isNullOrUndefined(n.activeObj.start)&&(n.activeObj.start="none"),e.isNullOrUndefined(n.activeObj.end)&&(n.activeObj.end="arrowSolid"),this.drawArrowHead(l,!0),this.drawArrowHead(l,!1),"none"===n.activeObj.end&&this.shapeLine(l,a.startX,a.startY,a.endX,a.endY),l.fillStyle=g,e.isNullOrUndefined(r)&&l===this.upperContext&&this.drawOuterSelection(l);break;case"path":if((u=e.extend({},n.activeObj,{},!0)).pointColl.length>1){var b={shape:null};if(n.notify("selection",{prop:"getCurrentDrawingShape",value:{obj:b}}),"path"===b.shape)for(var C={x:0,y:0},f=0,m=u.pointColl.length;f<m;f++)e.isNullOrUndefined(u.pointColl[f+1])?(C.x=u.activePoint.endX,C.y=u.activePoint.endY):(C.x=u.pointColl[f+1].x,C.y=u.pointColl[f+1].y),a.startX=u.pointColl[f].x,a.startY=u.pointColl[f].y,a.endX=C.x,a.endY=C.y,n.activeObj=this.updateWidthHeight(n.activeObj),this.shapeLine(l,a.startX,a.startY,a.endX,a.endY);else for(f=1,m=u.pointColl.length;f<m;f++)a.startX=u.pointColl[f-1].x,a.startY=u.pointColl[f-1].y,a.endX=u.pointColl[f].x,a.endY=u.pointColl[f].y,n.activeObj=this.updateWidthHeight(n.activeObj),this.shapeLine(l,a.startX,a.startY,a.endX,a.endY);n.activeObj=u}else this.shapeLine(l,a.startX,a.startY,a.endX,a.endY);l===this.upperContext&&this.drawOuterSelection(l);break;case"text":this.shapeText(l);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":l===this.lowerContext&&(l=this.upperContext),this.drawSelection(p,h),n.currObjType.shape="";break;default:this.drawSelection(p,h)}this.rotateContext("reverse",l)},t.prototype.updatePoints=function(){var t=this.parent;t.activeObj.activePoint.startX+=t.img.destLeft,t.activeObj.activePoint.startY+=t.img.destTop,t.activeObj.activePoint.endX+=t.img.destLeft,t.activeObj.activePoint.endY+=t.img.destTop,t.activeObj=this.updateWidthHeight(t.activeObj)},t.prototype.updateWidthHeight=function(t){return t.activePoint.width=t.activePoint.endX-t.activePoint.startX,t.activePoint.height=t.activePoint.endY-t.activePoint.startY,t},t.prototype.drawCenterCircles=function(t){var i=this.parent,o=i.activeObj.activePoint;if(t.lineWidth*=2,t.beginPath(),"arrow"===i.activeObj.shape||"line"===i.activeObj.shape)t.moveTo(o.startX,o.startY),t.arc(o.startX,o.startY,i.activeObj.topCenterCircle.radius,0,2*Math.PI),t.moveTo(o.endX,o.endY),t.arc(o.endX,o.endY,i.activeObj.bottomCenterCircle.radius,0,2*Math.PI);else if("path"===i.activeObj.shape){var r=e.extend({},i.activeObj,{},!0);if(r.pointColl.length>1)for(var n=1,a=r.pointColl.length;n<a;n++)o.startX=r.pointColl[n-1].x,o.startY=r.pointColl[n-1].y,o.endX=r.pointColl[n].x,o.endY=r.pointColl[n].y,t.moveTo(o.startX,o.startY),t.arc(o.startX,o.startY,i.activeObj.topCenterCircle.radius,0,2*Math.PI),t.moveTo(o.endX,o.endY),t.arc(o.endX,o.endY,i.activeObj.bottomCenterCircle.radius,0,2*Math.PI);var s={shape:null};i.notify("selection",{prop:"getCurrentDrawingShape",value:{obj:s}}),"path"===s.shape&&(i.activeObj=r),t.moveTo(o.startX,o.startY),t.arc(o.startX,o.startY,i.activeObj.topCenterCircle.radius,0,2*Math.PI),t.moveTo(o.endX,o.endY),t.arc(o.endX,o.endY,i.activeObj.bottomCenterCircle.radius,0,2*Math.PI)}else this.drawRotationArcLine(t),t.lineTo(i.activeObj.rotationCirclePoint.x,i.activeObj.rotationCirclePoint.y);t.stroke(),t.fill(),t.closePath(),"arrow"!==i.activeObj.shape&&"line"!==i.activeObj.shape&&"path"!==i.activeObj.shape&&(t.beginPath(),t.moveTo(i.activeObj.rotationCirclePoint.x,i.activeObj.rotationCirclePoint.y),t.arc(i.activeObj.rotationCirclePoint.x,i.activeObj.rotationCirclePoint.y,i.activeObj.bottomCenterCircle.radius,0,2*Math.PI),t.stroke(),t.fill(),t.closePath()),t.lineWidth/=2},t.prototype.drawRotationArcLine=function(t){var i=this.parent;e.isNullOrUndefined(i.activeObj.rotationCircleLine)&&(i.activeObj.rotationCircleLine=22.5);var o,r=!1,n=!1;(o=0===i.activeObj.shapeDegree?i.transform.degree:i.transform.degree-i.activeObj.shapeDegree)<0&&(o=360+o);for(var a=0,s=i.activeObj.flipObjColl.length;a<s;a++)"horizontal"===i.activeObj.flipObjColl[a].toLowerCase()?r=!0:"vertical"===i.activeObj.flipObjColl[a].toLowerCase()&&(n=!0);switch(o){case 0:case 360:n?(i.activeObj.rotationCirclePoint={x:i.activeObj.topCenterCircle.startX,y:i.activeObj.topCenterCircle.startY-i.activeObj.rotationCircleLine},t.moveTo(i.activeObj.rotationCirclePoint.x,i.activeObj.rotationCirclePoint.y+i.activeObj.rotationCircleLine)):(i.activeObj.rotationCirclePoint={x:i.activeObj.bottomCenterCircle.startX,y:i.activeObj.bottomCenterCircle.startY+i.activeObj.rotationCircleLine},t.moveTo(i.activeObj.rotationCirclePoint.x,i.activeObj.rotationCirclePoint.y-i.activeObj.rotationCircleLine));break;case 90:case-270:r?(i.activeObj.rotationCirclePoint={x:i.activeObj.centerRightCircle.startX+i.activeObj.rotationCircleLine,y:i.activeObj.centerLeftCircle.startY},t.moveTo(i.activeObj.rotationCirclePoint.x-i.activeObj.rotationCircleLine,i.activeObj.rotationCirclePoint.y)):(i.activeObj.rotationCirclePoint={x:i.activeObj.centerLeftCircle.startX-i.activeObj.rotationCircleLine,y:i.activeObj.centerLeftCircle.startY},t.moveTo(i.activeObj.rotationCirclePoint.x+i.activeObj.rotationCircleLine,i.activeObj.rotationCirclePoint.y));break;case 180:case-180:n?(i.activeObj.rotationCirclePoint={x:i.activeObj.bottomCenterCircle.startX,y:i.activeObj.bottomCenterCircle.startY+i.activeObj.rotationCircleLine},t.moveTo(i.activeObj.rotationCirclePoint.x,i.activeObj.rotationCirclePoint.y-i.activeObj.rotationCircleLine)):(i.activeObj.rotationCirclePoint={x:i.activeObj.topCenterCircle.startX,y:i.activeObj.topCenterCircle.startY-i.activeObj.rotationCircleLine},t.moveTo(i.activeObj.rotationCirclePoint.x,i.activeObj.rotationCirclePoint.y+i.activeObj.rotationCircleLine));break;case 270:case-90:r?(i.activeObj.rotationCirclePoint={x:i.activeObj.centerLeftCircle.startX-i.activeObj.rotationCircleLine,y:i.activeObj.centerLeftCircle.startY},t.moveTo(i.activeObj.rotationCirclePoint.x+i.activeObj.rotationCircleLine,i.activeObj.rotationCirclePoint.y)):(i.activeObj.rotationCirclePoint={x:i.activeObj.centerRightCircle.startX+i.activeObj.rotationCircleLine,y:i.activeObj.centerLeftCircle.startY},t.moveTo(i.activeObj.rotationCirclePoint.x-i.activeObj.rotationCircleLine,i.activeObj.rotationCirclePoint.y))}},t.prototype.drawSquareLines=function(t){var e,i=this.parent,o=i.activeObj.activePoint;void 0!==i.activeObj.shape&&(e=i.activeObj.shape.split("-")),"crop"===e[0]?t.strokeStyle="#fff":t.strokeStyle=i.activeObj.strokeSettings.strokeColor,t.beginPath(),t.rect(o.startX,o.startY,o.width,o.height),""!==i.activeObj.strokeSettings.fillColor&&(t.fillStyle=i.activeObj.strokeSettings.fillColor,t.fill()),t.rect(o.startX+i.activeObj.strokeSettings.strokeWidth,o.startY+i.activeObj.strokeSettings.strokeWidth,o.width-2*i.activeObj.strokeSettings.strokeWidth,o.height-2*i.activeObj.strokeSettings.strokeWidth),t.fillStyle=i.activeObj.strokeSettings.strokeColor,t.fill("evenodd"),t.closePath()},t.prototype.drawSelection=function(t,e){var i=this.parent,o=i.activeObj.activePoint;this.upperContext.strokeStyle=i.themeColl[i.theme].primaryColor,this.upperContext.beginPath(),i.activeObj.horTopInnerLine={startX:o.startX,startY:o.startY+e,endX:o.endX,endY:o.endY+e},i.activeObj.horBottomInnerLine={startX:o.startX,startY:o.startY+2*e,endX:o.endX,endY:o.endY+2*e},i.activeObj.verLeftInnerLine={startX:o.startX+t,startY:o.startY,endX:o.startX+t,endY:o.endY},i.activeObj.verRightInnerLine={startX:o.startX+2*t,startY:o.startY,endX:o.startX+2*t,endY:o.endY},this.upperContext.moveTo(i.activeObj.horTopInnerLine.startX,i.activeObj.horTopInnerLine.startY),this.upperContext.lineTo(i.activeObj.horTopInnerLine.endX,i.activeObj.horTopInnerLine.startY),this.upperContext.moveTo(i.activeObj.horBottomInnerLine.startX,i.activeObj.horBottomInnerLine.startY),this.upperContext.lineTo(i.activeObj.horBottomInnerLine.endX,i.activeObj.horBottomInnerLine.startY),this.upperContext.moveTo(i.activeObj.verLeftInnerLine.startX,i.activeObj.verLeftInnerLine.startY),this.upperContext.lineTo(i.activeObj.verLeftInnerLine.endX,i.activeObj.verLeftInnerLine.endY),this.upperContext.moveTo(i.activeObj.verRightInnerLine.startX,i.activeObj.verRightInnerLine.startY),this.upperContext.lineTo(i.activeObj.verRightInnerLine.endX,i.activeObj.verRightInnerLine.endY),this.upperContext.stroke(),this.upperContext.closePath()},t.prototype.shapeCircle=function(t,e,i){var o=this.parent,r=o.activeObj.activePoint;t.strokeStyle=o.themeColl[o.theme].primaryColor,t.clearRect(0,0,o.lowerCanvas.width,o.lowerCanvas.height),t.fillStyle="rgb(0, 0, 0, 0.25)",t.fillRect(0,0,o.lowerCanvas.width,o.lowerCanvas.height);var n=t.lineWidth;t.lineWidth=2,t.beginPath(),t.ellipse(o.activeObj.horTopLine.startX+e/2,o.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((r.endX-r.startX)/2+r.startX,(r.endY-r.startY)/2+r.startY,r.width/2,0,2*Math.PI),t.closePath(),t.clip(),t.clearRect(0,0,o.lowerCanvas.width,o.lowerCanvas.height),t.restore(),t.lineWidth=n,this.drawOuterSelection(t,!0),o.currObjType.shape=""},t.prototype.shapeLine=function(t,e,i,o,r){var n=t.lineWidth;t.lineWidth=this.parent.activeObj.strokeSettings.strokeWidth,t.beginPath(),t.moveTo(e,i),t.lineTo(o,r),t.stroke(),t.lineWidth=n},t.prototype.arrow=function(t,e){var i=this.parent,o=i.activeObj.activePoint;t.lineWidth=i.activeObj.strokeSettings.strokeWidth;var r=this.arrowDimension.arrow.width+i.activeObj.strokeSettings.strokeWidth,n=this.arrowDimension.arrow.height+i.activeObj.strokeSettings.strokeWidth;this.dx=o.endX-o.startX,this.dy=o.endY-o.startY,t.fillStyle=i.activeObj.strokeSettings.strokeColor;var a=Math.atan2(this.dy,this.dx);(e&&("left"===i.activeObj.triangleDirection||"right"===i.activeObj.triangleDirection)&&"arrow"===i.activeObj.start&&"none"===i.activeObj.end||"arrow"===i.activeObj.start&&"circle"!==i.activeObj.end&&"square"!==i.activeObj.end||!e&&("arrow"===i.activeObj.end&&"none"===i.activeObj.start||"circle"!==i.activeObj.start&&"square"!==i.activeObj.start))&&this.shapeLine(t,o.startX,o.startY,o.endX,o.endY),e&&"left"===i.activeObj.triangleDirection||!e&&"right"===i.activeObj.triangleDirection?(t.translate(o.endX,o.endY),t.rotate(a),this.shapeLine(t,0,0,-r,n/2),this.shapeLine(t,0,0,-r,-n/2),t.rotate(-a),t.translate(-o.endX,-o.endY)):(e&&"right"===i.activeObj.triangleDirection||!e&&"left"===i.activeObj.triangleDirection)&&(t.translate(o.startX,o.startY),t.rotate(a),this.shapeLine(t,0,0,r,n/2),this.shapeLine(t,0,0,r,-n/2),t.rotate(-a),t.translate(-o.startX,-o.startY))},t.prototype.arrowSolid=function(t,e){var i=this.parent,o=i.activeObj.activePoint,r=this.arrowDimension.arrowSolid.width+i.activeObj.strokeSettings.strokeWidth,n=this.arrowDimension.arrowSolid.height+i.activeObj.strokeSettings.strokeWidth;this.dx=o.endX-o.startX,this.dy=o.endY-o.startY;var a=Math.atan2(this.dy,this.dx);(e&&"arrowSolid"===i.activeObj.start&&"none"===i.activeObj.end||"arrowSolid"===i.activeObj.start&&"circle"!==i.activeObj.end&&"square"!==i.activeObj.end||!e&&("arrowSolid"===i.activeObj.end&&"none"===i.activeObj.start||"circle"!==i.activeObj.start&&"square"!==i.activeObj.start))&&this.shapeLine(t,o.startX,o.startY,o.endX,o.endY),e&&"left"===i.activeObj.triangleDirection||!e&&"right"===i.activeObj.triangleDirection?(t.translate(o.endX,o.endY),t.rotate(a),t.beginPath(),t.moveTo(i.activeObj.strokeSettings.strokeWidth,0),t.lineTo(n/2-r,n/2),t.lineTo(n/2-r,-n/2),t.closePath(),t.fill(),t.rotate(-a),t.translate(-o.endX,-o.endY),i.activeObj.rotatedAngle=a):(e&&"right"===i.activeObj.triangleDirection||!e&&"left"===i.activeObj.triangleDirection)&&(t.translate(o.startX,o.startY),t.rotate(a),t.beginPath(),t.moveTo(0-i.activeObj.strokeSettings.strokeWidth,0),t.lineTo(r-n/2,n/2),t.lineTo(r-n/2,-n/2),t.closePath(),t.fill(),t.rotate(-a),t.translate(-o.startX,-o.startY),i.activeObj.rotatedAngle=a)},t.prototype.arrowSquareStart=function(t){var e=this.parent,i=e.activeObj.activePoint;("square"===e.activeObj.start&&"none"===e.activeObj.end||"square"===e.activeObj.start&&"circle"!==e.activeObj.end&&"square"!==e.activeObj.start||"squareSolid"===e.activeObj.start&&"circleSolid"===e.activeObj.end)&&this.shapeLine(t,i.startX,i.startY,i.endX,i.endY),t.lineWidth=e.activeObj.strokeSettings.strokeWidth,t.beginPath(),t.fillStyle=e.activeObj.strokeSettings.strokeColor;var o=this.arrowDimension.square.width+e.activeObj.strokeSettings.strokeWidth,r=this.arrowDimension.square.height+e.activeObj.strokeSettings.strokeWidth;this.dx=i.endX-i.startX,this.dy=i.endY-i.startY;var n=Math.atan2(this.dy,this.dx);"left"===e.activeObj.triangleDirection?(t.translate(i.endX,i.endY),t.rotate(n),"squareSolid"===e.activeObj.start&&t.fillRect(r/2-o,-r/2,o,r),t.strokeRect(r/2-o,-r/2,o,r),t.rotate(-n),t.translate(-i.endX,-i.endY),this.squareStartIntersectX1=i.endX-r/2*Math.cos(n),this.squareStartIntersectY1=i.endY-r/2*Math.sin(n),"square"===e.activeObj.start&&"square"!==e.activeObj.end&&"circle"!==e.activeObj.end&&"square"!==e.activeObj.end&&this.shapeLine(t,i.startX,i.startY,this.squareStartIntersectX1,this.squareStartIntersectY1),"square"===e.activeObj.start&&"circle"===e.activeObj.end&&this.shapeLine(t,this.endCircleIntersectX1,this.endCircleIntersectY1,this.squareStartIntersectX1,this.squareStartIntersectY1),"squareSolid"===e.activeObj.start&&"squareSolid"===e.activeObj.end&&this.shapeLine(t,i.startX,i.startY,i.endX,i.endY)):"right"===e.activeObj.triangleDirection&&(t.lineWidth=e.activeObj.strokeSettings.strokeWidth,t.fillStyle=e.activeObj.strokeSettings.strokeColor,"squareSolid"===e.activeObj.start&&"squareSolid"===e.activeObj.end&&this.shapeLine(t,i.startX,i.startY,i.endX,i.endY),t.translate(i.startX,i.startY),t.rotate(n),"squareSolid"===e.activeObj.start&&t.fillRect(r/2-o,-r/2,o,r),t.strokeRect(r/2-o,-r/2,o,r),t.rotate(-n),t.translate(-i.startX,-i.startY),e.activeObj.rotatedAngle=n,this.squareStartIntersectX1=i.startX+r/2*Math.cos(n),this.squareStartIntersectY1=i.startY+r/2*Math.sin(n),"square"===e.activeObj.start&&"square"!==e.activeObj.end&&"circle"!==e.activeObj.end&&"square"!==e.activeObj.end&&this.shapeLine(t,i.endX,i.endY,this.squareStartIntersectX1,this.squareStartIntersectY1),"square"===e.activeObj.start&&"circle"===e.activeObj.end&&this.shapeLine(t,this.endCircleIntersectX1,this.endCircleIntersectY1,this.squareStartIntersectX1,this.squareStartIntersectY1))},t.prototype.arrowSquareEnd=function(t){var e=this.parent,i=e.activeObj.activePoint,o=this.arrowDimension.square.width+e.activeObj.strokeSettings.strokeWidth,r=this.arrowDimension.square.height+e.activeObj.strokeSettings.strokeWidth;this.dx=i.endX-i.startX,this.dy=i.endY-i.startY;var n=Math.atan2(this.dy,this.dx);t.lineWidth=e.activeObj.strokeSettings.strokeWidth,"right"===e.activeObj.triangleDirection?(t.fillStyle=e.activeObj.strokeSettings.strokeColor,"squareSolid"===e.activeObj.end&&"none"===e.activeObj.start&&this.shapeLine(t,i.startX,i.startY,i.endX,i.endY),t.translate(i.endX,i.endY),t.rotate(n),"squareSolid"===e.activeObj.end&&t.fillRect(r/2-o,-r/2,o,r),t.strokeRect(r/2-o,-r/2,o,r),t.rotate(-n),t.translate(-i.endX,-i.endY),e.activeObj.rotatedAngle=n,this.squareEndIntersectX1=i.endX-r/2*Math.cos(n),this.squareEndIntersectY1=i.endY-r/2*Math.sin(n),"square"===e.activeObj.end&&"square"!==e.activeObj.start&&"circle"!==e.activeObj.start&&"square"===e.activeObj.end?this.shapeLine(t,i.startX,i.startY,this.squareEndIntersectX1,this.squareEndIntersectY1):"circle"===e.activeObj.start&&"square"===e.activeObj.end?this.shapeLine(t,this.squareEndIntersectX1,this.squareEndIntersectY1,this.startCircleIntersectX1,this.startCircleIntersectY1):"square"===e.activeObj.start&&"square"===e.activeObj.end&&this.shapeLine(t,this.squareEndIntersectX1,this.squareEndIntersectY1,this.squareStartIntersectX1,this.squareStartIntersectY1)):"left"===e.activeObj.triangleDirection&&(t.translate(i.startX,i.startY),t.rotate(n),"squareSolid"===e.activeObj.end&&t.fillRect(r/2-o,-r/2,o,r),t.strokeRect(r/2-o,-r/2,o,r),t.rotate(-n),t.translate(-i.startX,-i.startY),e.activeObj.rotatedAngle=n,this.squareEndIntersectX1=i.startX+r/2*Math.cos(n),this.squareEndIntersectY1=i.startY+r/2*Math.sin(n),"square"===e.activeObj.end&&"square"!==e.activeObj.start&&"circle"!==e.activeObj.start&&"square"===e.activeObj.end?this.shapeLine(t,i.endX,i.endY,this.squareEndIntersectX1,this.squareEndIntersectY1):"circle"===e.activeObj.start&&"square"===e.activeObj.end?this.shapeLine(t,this.squareEndIntersectX1,this.squareEndIntersectY1,this.startCircleIntersectX1,this.startCircleIntersectY1):"square"===e.activeObj.start&&"square"===e.activeObj.end&&this.shapeLine(t,this.squareEndIntersectX1,this.squareEndIntersectY1,this.squareStartIntersectX1,this.squareStartIntersectY1))},t.prototype.arrowCircle=function(t,e){var i=this.parent,o=i.activeObj.activePoint;if(e&&"left"===i.activeObj.triangleDirection||!e&&"right"===i.activeObj.triangleDirection){t.lineWidth=i.activeObj.strokeSettings.strokeWidth;var r=this.arrowDimension.circle.width+i.activeObj.strokeSettings.strokeWidth;t.beginPath(),t.arc(o.endX,o.endY,r,0,2*Math.PI),t.stroke(),t.closePath(),this.dx=o.endX-o.startX,this.dy=o.endY-o.startY;var n=this.dx*this.dx+this.dy*this.dy;if((c=(h=2*(this.dx*(o.startX-o.endX)+this.dy*(o.startY-o.endY)))*h-4*n*((o.startX-o.endX)*(o.startX-o.endX)+(o.startY-o.endY)*(o.startY-o.endY)-r*r))>=0){t.fillStyle=i.activeObj.strokeSettings.strokeColor;var a=(-h-Math.sqrt(c))/(2*n),s=o.startX+this.dx*a,l=o.startY+this.dy*a;e?(this.startCircleIntersectX1=s,this.startCircleIntersectY1=l,t.beginPath(),t.fill(),t.beginPath(),"circle"===i.activeObj.start&&"circle"===i.activeObj.end?this.shapeLine(t,this.startCircleIntersectX1,this.startCircleIntersectY1,this.endCircleIntersectX1,this.endCircleIntersectY1):"circle"===i.activeObj.start&&"circle"!==i.activeObj.end&&"square"!==i.activeObj.end&&this.shapeLine(t,o.startX,o.startY,this.startCircleIntersectX1,this.startCircleIntersectY1),t.stroke(),t.closePath()):(this.endCircleIntersectX1=s,this.endCircleIntersectY1=l,"circle"===i.activeObj.end&&"circle"!==i.activeObj.start&&"square"!==i.activeObj.start&&this.shapeLine(t,o.startX,o.startY,this.endCircleIntersectX1,this.endCircleIntersectY1))}var p=Math.atan2(this.dy,this.dx);i.activeObj.rotatedAngle=p}else if(e&&"right"===i.activeObj.triangleDirection||!e&&"left"===i.activeObj.triangleDirection){t.lineWidth=i.activeObj.strokeSettings.strokeWidth;r=this.arrowDimension.circle.width+i.activeObj.strokeSettings.strokeWidth;t.beginPath(),t.arc(o.startX,o.startY,r,0,2*Math.PI),t.stroke(),t.closePath(),this.dx=o.startX-o.endX,this.dy=o.startY-o.endY;var h,c;n=this.dx*this.dx+this.dy*this.dy;if((c=(h=2*(this.dx*(o.endX-o.startX)+this.dy*(o.endY-o.startY)))*h-4*n*((o.endX-o.startX)*(o.endX-o.startX)+(o.endY-o.startY)*(o.endY-o.startY)-r*r))>=0){t.fillStyle=i.activeObj.strokeSettings.strokeColor;a=(-h-Math.sqrt(c))/(2*n),s=o.endX+this.dx*a,l=o.endY+this.dy*a;e?(this.startCircleIntersectX1=s,this.startCircleIntersectY1=l,"circle"===i.activeObj.start&&"circle"===i.activeObj.end?this.shapeLine(t,this.endCircleIntersectX1,this.endCircleIntersectY1,this.startCircleIntersectX1,this.startCircleIntersectY1):"circle"===i.activeObj.start&&"circle"!==i.activeObj.end&&"square"!==i.activeObj.end&&this.shapeLine(t,o.endX,o.endY,this.startCircleIntersectX1,this.startCircleIntersectY1)):(this.endCircleIntersectX1=s,this.endCircleIntersectY1=l,t.beginPath(),t.fill(),t.beginPath(),"circle"===i.activeObj.end&&"circle"!==i.activeObj.start&&"square"!==i.activeObj.start&&this.shapeLine(t,o.endX,o.endY,this.endCircleIntersectX1,this.endCircleIntersectY1))}p=Math.atan2(this.dy,this.dx);i.activeObj.rotatedAngle=p}},t.prototype.arrowCircleSolid=function(t,e){var i=this.parent,o=i.activeObj.activePoint;if(e&&"left"===i.activeObj.triangleDirection||!e&&"right"===i.activeObj.triangleDirection){t.lineWidth=i.activeObj.strokeSettings.strokeWidth,t.beginPath(),t.fillStyle=i.activeObj.strokeSettings.strokeColor,(e&&"circleSolid"===i.activeObj.start&&"none"===i.activeObj.end||"circleSolid"===i.activeObj.start&&"circle"!==i.activeObj.end&&"square"!==i.activeObj.end||!e&&"circleSolid"===i.activeObj.end&&"none"===i.activeObj.start)&&this.shapeLine(t,o.startX,o.startY,o.endX,o.endY);var r=this.arrowDimension.circle.width+i.activeObj.strokeSettings.strokeWidth;this.dx=o.endX-o.startX,this.dy=o.endY-o.startY,t.save(),t.beginPath(),t.arc(o.endX,o.endY,r,0,2*Math.PI),t.stroke(),t.fill(),t.closePath(),i.activeObj.rotatedAngle=Math.atan2(this.dy,this.dx)}else if(e&&"right"===i.activeObj.triangleDirection||!e&&"left"===i.activeObj.triangleDirection){t.lineWidth=i.activeObj.strokeSettings.strokeWidth,t.beginPath(),t.fillStyle=i.activeObj.strokeSettings.strokeColor,(e&&"circleSolid"===i.activeObj.start&&"none"===i.activeObj.end||"circleSolid"===i.activeObj.start&&"circle"!==i.activeObj.end&&"square"!==i.activeObj.end||!e&&"circleSolid"===i.activeObj.end&&"none"===i.activeObj.start)&&this.shapeLine(t,o.startX,o.startY,o.endX,o.endY);r=this.arrowDimension.circle.width+i.activeObj.strokeSettings.strokeWidth;this.dx=o.endX-o.startX,this.dy=o.endY-o.startY,t.save(),t.beginPath(),t.arc(o.startX,o.startY,r,0,2*Math.PI),t.stroke(),t.fill(),t.closePath(),i.activeObj.rotatedAngle=Math.atan2(this.dy,this.dx)}},t.prototype.arrowBar=function(t,e){var i=this.parent,o=i.activeObj.activePoint;if(e&&"left"===i.activeObj.triangleDirection||!e&&"right"===i.activeObj.triangleDirection){t.lineWidth=i.activeObj.strokeSettings.strokeWidth,t.beginPath(),t.fillStyle=i.activeObj.strokeSettings.strokeColor,(e&&"bar"===i.activeObj.start&&"none"===i.activeObj.end||"bar"===i.activeObj.start&&"circle"!==i.activeObj.end&&"square"!==i.activeObj.end||!e&&("bar"===i.activeObj.end&&"none"===i.activeObj.start||"bar"===i.activeObj.end&&"circle"!==i.activeObj.start&&"square"!==i.activeObj.start))&&this.shapeLine(t,o.startX,o.startY,o.endX,o.endY);var r=this.arrowDimension.bar.width+i.activeObj.strokeSettings.strokeWidth,n=this.arrowDimension.bar.height+i.activeObj.strokeSettings.strokeWidth;this.dx=o.endX-o.startX,this.dy=o.endY-o.startY;var a=Math.atan2(this.dy,this.dx);t.translate(o.endX,o.endY),t.rotate(a),t.fillRect(n/4-r,-n/2,r,n),t.rotate(-a),t.translate(-o.endX,-o.endY),i.activeObj.rotatedAngle=a}else if(e&&"right"===i.activeObj.triangleDirection||!e&&"left"===i.activeObj.triangleDirection){t.lineWidth=i.activeObj.strokeSettings.strokeWidth,t.beginPath(),t.fillStyle=i.activeObj.strokeSettings.strokeColor,(e&&"bar"===i.activeObj.start&&"none"===i.activeObj.end||"bar"===i.activeObj.start&&"circle"!==i.activeObj.end&&"square"!==i.activeObj.end||!e&&"bar"===i.activeObj.end&&"none"===i.activeObj.start)&&this.shapeLine(t,o.startX,o.startY,o.endX,o.endY);r=this.arrowDimension.bar.width+i.activeObj.strokeSettings.strokeWidth,n=this.arrowDimension.bar.height+i.activeObj.strokeSettings.strokeWidth;this.dx=o.endX-o.startX,this.dy=o.endY-o.startY;a=Math.atan2(this.dy,this.dx);t.translate(o.startX,o.startY),t.rotate(a),t.fillRect(n/4-r,-n/2,r,n),t.rotate(-a),t.translate(-o.startX,-o.startY),i.activeObj.rotatedAngle=a}},t.prototype.shapeText=function(t){for(var e=this.parent,i=e.activeObj.activePoint,o=e.activeObj.keyHistory.split("\n"),r=((e.activeObj.textSettings.fontSize+.25*e.activeObj.textSettings.fontSize)*o.length-e.activeObj.textSettings.fontSize*o.length)/o.length,n=0;n<o.length;n++){var a=o[n],s=(n+1)*e.activeObj.textSettings.fontSize*.85+n*r;-360===e.transform.degree&&(e.transform.degree=0),0===e.transform.degree||180===e.transform.degree?e.activeObj.textSettings.fontSize>i.height&&(e.activeObj.textSettings.fontSize=i.height-.1*i.height):e.activeObj.textSettings.fontSize>i.width&&(e.activeObj.textSettings.fontSize=i.width-.1*i.width),t.strokeStyle=e.activeObj.strokeSettings.strokeColor,t.fillStyle=e.activeObj.strokeSettings.strokeColor;var l="";e.activeObj.textSettings.bold&&(l="bold "),e.activeObj.textSettings.italic&&(l="italic "),e.activeObj.textSettings.bold&&e.activeObj.textSettings.italic&&(l="italic bold "),t.font=l+e.activeObj.textSettings.fontSize+"px "+e.activeObj.textSettings.fontFamily,4===e.activeObj.flipObjColl.length&&(e.activeObj.flipObjColl=[]);for(var p=0,h=e.activeObj.flipObjColl.length;p<h;p++)"horizontal"===e.activeObj.flipObjColl[p].toLowerCase()?(t.translate(t.canvas.width,0),t.scale(-1,1),this.updateActPoint("horizontal",t)):"vertical"===e.activeObj.flipObjColl[p].toLowerCase()&&(t.translate(0,t.canvas.height),t.scale(1,-1),this.updateActPoint("vertical",t));e.activeObj.shapeDegree!==e.transform.degree?this.rotateText(t):t.fillText(a,i.startX+.1*e.activeObj.textSettings.fontSize,i.startY+s);var c=0;for(h=e.activeObj.flipObjColl.length;c<h;c++)"horizontal"===e.activeObj.flipObjColl[c].toLowerCase()?(t.translate(t.canvas.width,0),t.scale(-1,1),this.updateActPoint("horizontal",t)):"vertical"===e.activeObj.flipObjColl[c].toLowerCase()&&(t.translate(0,t.canvas.height),t.scale(1,-1),this.updateActPoint("vertical",t))}e.currObjType.isText=!1},t.prototype.updateActPoint=function(t,e){var i=this.parent,o=i.activeObj.activePoint;"horizontal"===t.toLowerCase()?o.startX<=e.canvas.width/2?(o.startX=e.canvas.width/2+(e.canvas.width/2-o.endX),o.endX=o.startX+o.width,this.updateActiveObject(o,i.activeObj)):o.startX>=e.canvas.width/2&&(o.startX=e.canvas.width-o.endX,o.endX=o.startX+o.width,this.updateActiveObject(o,i.activeObj)):"vertical"===t.toLowerCase()&&(o.startY<=e.canvas.height/2?(o.startY=e.canvas.height/2+(e.canvas.height/2-o.endY),o.endY=o.startY+o.height,this.updateActiveObject(o,i.activeObj)):o.startY>=e.canvas.height/2&&(o.startY=e.canvas.height-o.endY,o.endY=o.startY+o.height,this.updateActiveObject(o,i.activeObj)))},t.prototype.rotateText=function(t){var e,i=this.parent,o=i.activeObj.activePoint.startX,r=i.activeObj.activePoint.startY,n=i.activeObj.activePoint;if((e=0===i.activeObj.shapeDegree?i.transform.degree:i.transform.degree-i.activeObj.shapeDegree)<0&&(e=360+e),e%360!=0||-360===i.transform.degree&&""!==i.transform.currFlipState)e%90==0&&e%180!=0?(t.translate(i.lowerCanvas.width/2,i.lowerCanvas.height/2),t.rotate(Math.PI/180*e),t.translate(-i.lowerCanvas.height/2,-i.lowerCanvas.width/2),e%90==0&&e%270!=0?(r=i.lowerCanvas.width-n.endX+.4*i.activeObj.textSettings.fontSize,o=n.startY):e%270==0&&(o=i.lowerCanvas.height-n.endY,r=n.startX+.4*i.activeObj.textSettings.fontSize),this.textFlipDegree(t,o,r),t.translate(i.lowerCanvas.height/2,i.lowerCanvas.width/2),t.rotate(Math.PI/180*-e),t.translate(-i.lowerCanvas.width/2,-i.lowerCanvas.height/2)):(t.translate(i.lowerCanvas.width/2,i.lowerCanvas.height/2),t.rotate(Math.PI/180*e),o=i.lowerCanvas.width-n.endX,r=i.lowerCanvas.height-n.endY+.4*i.activeObj.textSettings.fontSize,t.translate(-i.lowerCanvas.width/2,-i.lowerCanvas.height/2),this.textFlipDegree(t,o,r),t.translate(i.lowerCanvas.width/2,i.lowerCanvas.height/2),t.rotate(Math.PI/180*-e),t.translate(-i.lowerCanvas.width/2,-i.lowerCanvas.height/2));else{o=n.startX+.15*i.activeObj.textSettings.fontSize,r=n.startY+(n.endY-n.startY);for(var a=i.activeObj.keyHistory.split("\n"),s=0;s<a.length;s++)r=n.startY+(s*i.activeObj.textSettings.fontSize+.25*i.activeObj.textSettings.fontSize),t.fillText(a[s],o,r)}360!==i.transform.degree&&-360!==i.transform.degree||(i.transform.degree=0)},t.prototype.textFlipDegree=function(t,e,i){for(var o=this.parent,r=o.activeObj.keyHistory.split("\n"),n=(o.activeObj.textSettings.fontSize*r.length-o.activeObj.textSettings.fontSize*r.length)/r.length,a=.85*o.activeObj.textSettings.fontSize+n,s=0;s<r.length;s++){var l=r[s];s>0&&(1===s&&(a-=.85*o.activeObj.textSettings.fontSize),a+=o.activeObj.textSettings.fontSize+.15*o.activeObj.textSettings.fontSize),t.fillText(l,e+.15*o.activeObj.textSettings.fontSize,i+a+(s>0?.25*o.activeObj.textSettings.fontSize:.35*-o.activeObj.textSettings.fontSize))}},t.prototype.clearOuterCanvas=function(t){var e=this.parent,i=e.img.destLeft,o=e.img.destTop;if(e.img.destWidth<e.lowerCanvas.width){var r=e.img.destLeft>0?e.img.destLeft:0;t.clearRect(0,0,r,e.lowerCanvas.height),t.clearRect(e.img.destLeft+e.img.destWidth,0,r,e.lowerCanvas.height)}if(e.img.destHeight<e.lowerCanvas.height){var n=e.img.destTop>0?e.img.destTop:0;t.clearRect(0,0,e.lowerCanvas.width,n),t.clearRect(0,e.img.destTop+e.img.destHeight,e.lowerCanvas.width,n)}""!==e.transform.currFlipState&&(e.img.destLeft=i,e.img.destTop=o)},t.prototype.setDestPoints=function(){var t,e=this.parent;if(e.transform.degree%90==0&&e.transform.degree%180!=0){var i={width:0,height:0};e.notify("transform",{prop:"calcMaxDimension",onPropertyChange:!1,value:{width:e.img.srcHeight,height:e.img.srcWidth,obj:i}}),t=i,this.isRotateZoom&&(t.width+=t.width*e.transform.zoomFactor,t.height+=t.height*e.transform.zoomFactor,e.img.destWidth=t.height,e.img.destHeight=t.width),e.img.destLeft=(e.lowerCanvas.clientWidth-t.height)/2,e.img.destTop=(e.lowerCanvas.clientHeight-t.width)/2,e.img.destWidth=t.height,e.img.destHeight=t.width}else{i={width:0,height:0};e.notify("transform",{prop:"calcMaxDimension",onPropertyChange:!1,value:{width:e.img.srcWidth,height:e.img.srcHeight,obj:i}}),t=i,this.isRotateZoom&&(t.width+=t.width*e.transform.zoomFactor,t.height+=t.height*e.transform.zoomFactor,e.img.destWidth=t.width,e.img.destHeight=t.height),e.img.destLeft=(e.lowerCanvas.clientWidth-t.width)/2,e.img.destTop=(e.lowerCanvas.clientHeight-t.height)/2,e.img.destWidth=t.width,e.img.destHeight=t.height}},t.prototype.updateCurrTransState=function(t,i,o){var r=this.parent,n=r.img.destLeft,a=r.img.destTop;"initial"===t&&(this.lowerContext.setTransform(1,0,0,1,0,0),e.isNullOrUndefined(i)&&this.setDestPoints()),this.currTransState(t,null,null,o),0===r.transform.degree&&""===r.transform.currFlipState&&(r.img.destLeft=n,r.img.destTop=a),(r.isCircleCrop||r.currSelectionPoint&&"crop-circle"===r.currSelectionPoint.shape)&&(o&&(r.img.destLeft+=r.panPoint.totalPannedClientPoint.x,r.img.destTop+=r.panPoint.totalPannedClientPoint.y),r.notify("crop",{prop:"cropCircle",onPropertyChange:!1,value:{context:this.lowerContext,isSave:null,isFlip:null}}),o&&(r.img.destLeft-=r.panPoint.totalPannedClientPoint.x,r.img.destTop-=r.panPoint.totalPannedClientPoint.y))},t.prototype.currTransState=function(t,i,o,r){var n=this.parent;o=o||this.lowerContext,"initial"===t?this.setTransformColl(o,t):"reverse"===t&&(this.setTransformColl(o,t),this.setClientTransDim(i),(n.isCircleCrop||n.currSelectionPoint&&"crop-circle"===n.currSelectionPoint.shape&&e.isNullOrUndefined(r))&&(r&&(n.img.destLeft+=n.panPoint.totalPannedClientPoint.x,n.img.destTop+=n.panPoint.totalPannedClientPoint.y),n.notify("crop",{prop:"cropCircle",onPropertyChange:!1,value:{context:this.lowerContext,isSave:null,isFlip:null}}),r&&(n.img.destLeft-=n.panPoint.totalPannedClientPoint.x,n.img.destTop-=n.panPoint.totalPannedClientPoint.y)))},t.prototype.setTransformColl=function(t,e){var i=this.parent;if("initial"===e)for(var o=0,r=i.rotateFlipColl.length;o<r;o++)this.setTransform(t,i.rotateFlipColl[o]);else if("reverse"===e)for(o=i.rotateFlipColl.length-1;o>=0;o--)this.setTransform(t,i.rotateFlipColl[o],!0)},t.prototype.setTransform=function(t,i,o){var r=this.parent;switch(o&&90===i?i=-90:o&&-90===i&&(i=90),"horizontal"===i&&r.transform.degree%90==0&&r.transform.degree%180!=0?i="vertical":"vertical"===i&&r.transform.degree%90==0&&r.transform.degree%180!=0&&(i="horizontal"),r.notify("transform",{prop:"setReverseRotate",onPropertyChange:!1,value:{bool:!0}}),r.notify("transform",{prop:"setReverseFlip",onPropertyChange:!1,value:{isReverseFlip:!0}}),e.isNullOrUndefined(o)&&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)}r.notify("transform",{prop:"setReverseRotate",onPropertyChange:!1,value:{bool:!1}}),r.notify("transform",{prop:"setReverseFlip",onPropertyChange:!1,value:{isReverseFlip:!1}})},t.prototype.drawImgToCanvas=function(t){var e=this.parent;this.lowerContext.clearRect(0,0,e.lowerCanvas.width,e.lowerCanvas.height),e.img.destWidth=t.width,e.img.destHeight=t.height,this.isInitialLoading&&(e.notify("filter",{prop:"initFilter",onPropertyChange:!1}),this.isInitialLoading=!1);var i=this.lowerContext.filter;e.notify("filter",{prop:"updateBrightFilter",onPropertyChange:!1}),this.lowerContext.clearRect(0,0,e.lowerCanvas.width,e.lowerCanvas.height),this.lowerContext.drawImage(e.baseImg,e.img.srcLeft,e.img.srcTop,e.img.srcWidth,e.img.srcHeight,e.img.destLeft,e.img.destTop,e.img.destWidth,e.img.destHeight),(e.currSelectionPoint&&"crop-circle"===e.currSelectionPoint.shape||e.isCircleCrop)&&e.notify("crop",{prop:"cropCircle",onPropertyChange:!1,value:{context:this.lowerContext,isSave:null,isFlip:null}}),this.lowerContext.filter=i},t.prototype.renderImage=function(t){var e=this.parent,i=this.lowerContext.filter;e.notify("shape",{prop:"applyActObj",onPropertyChange:!1,value:{isMouseDown:null}}),this.upperContext.clearRect(0,0,e.lowerCanvas.width,e.lowerCanvas.height),this.lowerContext.clearRect(0,0,e.lowerCanvas.width,e.lowerCanvas.height),t?this.setTransformColl(this.lowerContext,"initial"):(e.transform.zoomFactor>0&&(this.isRotateZoom=!0),this.updateCurrTransState("initial")),e.notify("filter",{prop:"updateBrightFilter",onPropertyChange:!1}),e.notify("transform",{prop:"setDestPointsForFlipState",onPropertyChange:!1}),this.lowerContext.drawImage(e.baseImg,e.img.srcLeft,e.img.srcTop,e.img.srcWidth,e.img.srcHeight,e.img.destLeft,e.img.destTop,e.img.destWidth,e.img.destHeight),e.notify("transform",{prop:"setDestPointsForFlipState",onPropertyChange:!1}),t?this.setTransformColl(this.lowerContext,"reverse"):(this.updateCurrTransState("reverse"),this.isRotateZoom=!1),this.lowerContext.filter="none",e.notify("shape",{prop:"iterateObjColl",onPropertyChange:!1}),e.notify("freehand-draw",{prop:"freehandRedraw",onPropertyChange:!1,value:{context:this.lowerContext,points:null}}),this.lowerContext.filter=i,(e.isCircleCrop||e.currSelectionPoint&&"crop-circle"===e.currSelectionPoint.shape)&&e.notify("crop",{prop:"cropCircle",onPropertyChange:!1,value:{context:this.lowerContext,isSave:null,isFlip:null}})},t.prototype.imageOnLoad=function(t){var o=this,r=this.parent,n=this;r.baseImg.src=t,r.baseImg.onload=function(){if(r.notify("filter",{prop:"update-finetunes",onPropertyChange:!1}),n.lowerContext.drawImage(r.baseImg,0,0,n.parent.lowerCanvas.width,n.parent.lowerCanvas.height),i.hideSpinner(r.element),r.element.style.opacity="1",n.updateCanvas(),r.currObjType.isUndoZoom&&(r.currObjType.isUndoZoom=!1,n.parent.lowerCanvas.style.display="block"),r.isUndoRedo=o.isErrorImage=!1,e.isBlazor())r.updateToolbar(r.element,"imageLoaded","initial"),e.Browser.isDevice&&(r.element.querySelector(".e-bottom-toolbar-area").style.display="block",r.element.querySelector(".e-canvas-wrapper").style.height=r.element.offsetHeight-2*r.toolbarHeight-3+"px");else if(e.Browser.isDevice){r.notify("toolbar",{prop:"destroy-top-toolbar",onPropertyChange:!1}),r.notify("toolbar",{prop:"destroy-bottom-toolbar",onPropertyChange:!1});var t={isApplyBtn:!1,isDevice:e.Browser.isDevice,isOkBtn:null};r.notify("toolbar",{prop:"init-main-toolbar",onPropertyChange:!1,value:t}),r.notify("toolbar",{prop:"create-bottom-toolbar",onPropertyChange:!1})}else{r.notify("toolbar",{prop:"destroy-top-toolbar",onPropertyChange:!1});t={isApplyBtn:!1,isDevice:!1,isOkBtn:null};r.notify("toolbar",{prop:"init-main-toolbar",onPropertyChange:!1,value:t})}},r.baseImg.onerror=function(){i.hideSpinner(r.element),n.isErrorImage=!0}},t.prototype.updateCanvas=function(){var t=this.parent,i={fileName:this.fileName,fileType:this.fileType};t.img.srcWidth=t.baseImg.width,t.img.srcHeight=t.baseImg.height;var o={width:0,height:0};t.notify("transform",{prop:"calcMaxDimension",onPropertyChange:!1,value:{width:t.img.srcWidth,height:t.img.srcHeight,obj:o}});var r=o;t.img.destLeft=(t.lowerCanvas.clientWidth-r.width)/2,t.img.destTop=(t.lowerCanvas.clientHeight-r.height)/2,this.drawImgToCanvas(r),this.zoomCrop.width=t.img.destWidth,this.zoomCrop.height=t.img.destHeight,t.notify("transform",{prop:"setCropDimension",onPropertyChange:!1,value:{width:t.img.destWidth,height:t.img.destHeight}});var n={startX:t.img.destLeft,startY:t.img.destTop,width:t.img.destWidth,height:t.img.destHeight};t.notify("crop",{prop:"setCropDestPoints",onPropertyChange:!1,value:{point:n}});var a=this.lowerContext.filter;this.lowerContext.filter="none",t.notify("shape",{prop:"iterateObjColl",onPropertyChange:!1}),t.notify("freehand-draw",{prop:"zoomFHDColl",onPropertyChange:!1,value:{isPreventApply:null}}),this.lowerContext.filter=a,t.img.destWidth>0&&t.img.destHeight>0&&(t.isImageLoaded=!0),t.isUndoRedo&&""!==t.transform.currFlipState&&t.notify("transform",{prop:"flipImage",onPropertyChange:!1,value:{direction:t.toPascalCase(t.transform.currFlipState)}}),t.disabled&&t.element.setAttribute("class","e-disabled"),t.isImageLoaded&&"0.5"!==t.element.style.opacity&&(e.isBlazor()&&t.events&&!0===t.events.fileOpened.hasDelegate?t.dotNetRef.invokeMethodAsync("FileOpenEventAsync","FileOpened",i):t.trigger("fileOpened",i)),(1!==t.zoomSettings.zoomFactor||t.zoomSettings.zoomPoint)&&t.zoom(t.zoomSettings.zoomFactor,t.zoomSettings.zoomPoint),e.isNullOrUndefined(this.initZoomValue)&&(this.initZoomValue=t.zoomSettings.zoomFactor),this.isImageEdited=!1},t.prototype.performCancel=function(t){var i=this.parent;t=t||!1;var o={bool:!1};if(i.notify("selection",{prop:"getFreehandDrawEditing",onPropertyChange:!1,value:{obj:o}}),o.bool)i.notify("freehand-draw",{prop:"cancelFhd",onPropertyChange:!1}),e.isBlazor()?i.updateToolbar(i.element,"destroyQuickAccessToolbar"):i.notify("toolbar",{prop:"destroy-qa-toolbar",onPropertyChange:!1}),i.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"cancel"}});else if("block"===i.textArea.style.display)i.textArea.style.display="none",i.textArea.value="",i.textArea.style.transform="",this.prevActObj?(i.activeObj=this.prevActObj,this.prevActObj=null):(i.activeObj.strokeSettings=this.tempStrokeSettings,i.activeObj.textSettings=this.tempTextSettings),i.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"cancel"}}),this.isShapeTextInserted&&i.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),i.notify("shape",{prop:"applyActObj",onPropertyChange:!1,value:{isMouseDown:!0}}),e.isBlazor()?i.updateToolbar(i.element,"imageLoaded"):i.notify("toolbar",{prop:"refresh-main-toolbar",onPropertyChange:!1});else if(!e.isBlazor()&&document.querySelector("#"+i.element.id+"_sliderWrapper")||e.isBlazor()&&!i.element.querySelector(".e-ie-contextual-slider").classList.contains("e-hidden")||i.currObjType.isFiltered){this.lowerContext.filter=this.tempAdjValue,i.canvasFilter=this.tempAdjValue,i.notify("filter",{prop:"setAdjustmentValue",onPropertyChange:!1,value:{adjustmentValue:this.tempAdjValue}}),i.initialAdjustmentValue=this.tempAdjValue,this.lowerContext.filter.split(" ").length>1&&"1"===this.lowerContext.filter.split(" ")[0].split("(")[1].split(")")[0]&&i.notify("filter",{prop:"setBrightnessAdjusted",onPropertyChange:!1,value:{isBrightnessAdjusted:!1}}),i.currentFilter=this.tempFilter,this.lowerContext.clearRect(0,0,i.lowerCanvas.width,i.lowerCanvas.height),this.redrawImgWithObj(),i.currObjType.isFiltered=!1;var r={tempAdjustmentLevel:null};i.notify("filter",{prop:"getTempAdjustmentLevel",onPropertyChange:!1,value:{obj:r}}),i.notify("filter",{prop:"setAdjustmentLevel",onPropertyChange:!1,value:{adjustmentLevel:e.extend({},r.tempAdjustmentLevel,{},!0)}}),i.notify("undo-redo",{prop:"setUndoRedoStep",onPropertyChange:!1,value:{step:this.tempUndoRedoStep}}),i.upperCanvas.style.cursor=i.cursor="default",i.currObjType.isCustomCrop=!1,this.tempStrokeSettings={strokeColor:"#fff",fillColor:"",strokeWidth:null},this.clearOuterCanvas(this.lowerContext),(i.currSelectionPoint&&"crop-circle"===i.currSelectionPoint.shape||i.isCircleCrop)&&i.notify("crop",{prop:"cropCircle",onPropertyChange:!1,value:{context:this.lowerContext,isSave:null,isFlip:null}});var n={type:"main",isApplyBtn:null,isCropping:null,isZooming:null};e.isBlazor()?i.updateToolbar(i.element,"imageLoaded"):(i.element.querySelector(".e-contextual-toolbar-wrapper").classList.add("e-hide"),i.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:n})),i.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"cancel"}})}else if(t){n={type:"main",isApplyBtn:null,isCropping:null,isZooming:null};e.isBlazor()?i.updateToolbar(i.element,"imageLoaded"):i.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:n})}else this.cancelItems(),i.togglePan=!1,i.notify("selection",{prop:"setDragCanvas",value:{bool:!1}});this.isShapeTextInserted=!1,this.isNewPath=!1,e.isBlazor()||(i.notify("toolbar",{prop:"refresh-dropdown-btn",value:{isDisabled:!1}}),i.notify("toolbar",{prop:"setCurrentToolbar",value:{type:"main"}}))},t.prototype.cancelItems=function(){var t,i=this.parent,o=!1;void 0!==i.activeObj.shape&&(t=i.activeObj.shape.split("-")),void 0===t&&i.currObjType.isCustomCrop?o=!0:void 0!==t&&"crop"===t[0]&&(o=!0),o&&i.isCropTab&&(i.isCropTab=!1,i.transform.zoomFactor=i.transform.defaultZoomFactor),i.togglePen?this.cancelPen():"text"===i.activeObj.shape?this.cancelText(o):-1!==["rectangle","ellipse","line","arrow","path"].indexOf(i.activeObj.shape)?this.cancelShape():o?this.cancelSelection():i.transform.zoomFactor!==this.tempZoomFactor||o&&e.isNullOrUndefined(i.currSelectionPoint)?this.cancelZoom():(i.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),this.upperContext.clearRect(0,0,i.upperCanvas.width,i.upperCanvas.height),i.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"cancel"}})),i.notify("selection",{prop:"setCurrentDrawingShape",onPropertyChange:!1,value:{value:""}}),i.upperCanvas.style.cursor=i.cursor="default",i.currObjType.isCustomCrop=!1,this.tempStrokeSettings={strokeColor:"#fff",fillColor:"",strokeWidth:null};e.isBlazor()?i.updateToolbar(i.element,"imageLoaded"):i.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"main",isApplyBtn:null,isCropping:!1,isZooming:null}})},t.prototype.cancelPen=function(){var t=this.parent;this.upperContext.clearRect(0,0,t.upperCanvas.width,t.upperCanvas.height),t.togglePen=!1,t.upperCanvas.style.cursor=t.cursor="default";var i=e.extend([],t.pointColl,[],!0);t.pointColl={};for(var o=0;o<this.tempFreehandCounter;o++)t.pointColl[o]=i[o];t.freehandCounter=this.tempFreehandCounter,t.notify("freehand-draw",{prop:"setCurrentFreehandDrawIndex",value:{value:this.tempCurrFhdIndex}}),t.activeObj.strokeSettings=this.tempStrokeSettings,t.notify("shape",{prop:"setStrokeSettings",value:{strokeSettings:t.activeObj.strokeSettings,strokeColor:null,fillColor:null,strokeWidth:null}}),t.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"cancel"}}),t.notify("selection",{prop:"setFreehandDrawCustomized",value:{isFreehandDrawCustomized:!1}})},t.prototype.cancelText=function(t){var i=this.parent;if(i.notify("shape",{prop:"setTextSettings",onPropertyChange:!1,value:{textSettings:this.tempTextSettings,fontFamily:null,fontSize:null}}),i.notify("shape",{prop:"setStrokeSettings",value:{strokeSettings:this.tempStrokeSettings,strokeColor:null,fillColor:null,strokeWidth:null}}),e.isNullOrUndefined(i.activeObj.currIndex))i.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),this.upperContext.clearRect(0,0,i.upperCanvas.width,i.upperCanvas.height);else{var o={appliedUndoRedoColl:[]};i.notify("undo-redo",{prop:"getAppliedUndoRedoColl",value:{obj:o}});var r=o.appliedUndoRedoColl.length;this.prevActObj&&o.appliedUndoRedoColl[r-1]&&o.appliedUndoRedoColl[r-1].currentObjColl[o.appliedUndoRedoColl[r-1].currentObjColl.length-1].currIndex===this.prevActObj.currIndex?(i.activeObj=this.prevActObj,this.prevActObj=null):(i.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),this.upperContext.clearRect(0,0,i.upperCanvas.width,i.upperCanvas.height)),i.activeObj.shape&&"Enter Text"===i.activeObj.keyHistory?(i.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),this.upperContext.clearRect(0,0,i.upperCanvas.width,i.upperCanvas.height),i.notify("shape",{prop:"draw-shape-text"}),i.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"cancel"}}),i.notify("shape",{prop:"applyActObj",onPropertyChange:!1,value:{isMouseDown:!0}})):i.activeObj.shape&&(i.notify("shape",{prop:"redraw-text"}),i.notify("selection",{prop:"redrawShape",onPropertyChange:!1,value:{obj:i.activeObj}}),t||void 0===i.activeObj.topLeftCircle||i.notify("shape",{prop:"applyActObj",onPropertyChange:!1,value:{isMouseDown:!0}}),i.clearSelection())}e.isBlazor()?i.updateToolbar(i.element,"destroyQuickAccessToolbar"):i.notify("toolbar",{prop:"destroy-qa-toolbar",onPropertyChange:!1}),this.tempTextSettings={text:"Enter Text",fontFamily:"Arial",fontSize:null,fontRatio:null,bold:!1,italic:!1,underline:!1}},t.prototype.cancelShape=function(){var t=this.parent;if(t.notify("shape",{prop:"setStrokeSettings",value:{strokeSettings:this.tempStrokeSettings,strokeColor:null,fillColor:null,strokeWidth:null}}),e.isNullOrUndefined(t.activeObj.currIndex))t.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),this.upperContext.clearRect(0,0,t.upperCanvas.width,t.upperCanvas.height);else if(this.isNewPath)t.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),this.upperContext.clearRect(0,0,t.upperCanvas.width,t.upperCanvas.height),this.renderImage();else{var i={appliedUndoRedoColl:[]};t.notify("undo-redo",{prop:"getAppliedUndoRedoColl",value:{obj:i}});var o=i.appliedUndoRedoColl.length;this.prevActObj&&i.appliedUndoRedoColl[o-1]&&i.appliedUndoRedoColl[o-1].currentObjColl[i.appliedUndoRedoColl[o-1].currentObjColl.length-1].currIndex===this.prevActObj.currIndex?(t.activeObj=this.prevActObj,this.prevActObj=null,t.notify("selection",{prop:"redrawShape",onPropertyChange:!1,value:{obj:t.activeObj}}),t.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"cancel"}}),t.notify("shape",{prop:"applyActObj",onPropertyChange:!1,value:{isMouseDown:!0}})):(t.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),this.upperContext.clearRect(0,0,t.upperCanvas.width,t.upperCanvas.height))}t.currObjType.isDragging=!1,e.isBlazor()?t.updateToolbar(t.element,"destroyQuickAccessToolbar"):t.notify("toolbar",{prop:"destroy-qa-toolbar",onPropertyChange:!1})},t.prototype.cancelSelection=function(){var t=this.parent;t.cancelCropSelection&&(t.cropObj=e.extend({},t.cancelCropSelection.previousCropObj,{},!0),t.afterCropActions=t.cancelCropSelection.previousObj.afterCropActions,t.notify("undo-redo",{prop:"undoDefault",onPropertyChange:!1,value:{obj:t.cancelCropSelection}}),t.currSelectionPoint=e.extend({},t.cancelCropSelection.previousCropObj.activeObj,!0),t.currSelectionPoint&&e.isNullOrUndefined(t.currSelectionPoint.shape)&&(t.currSelectionPoint=null),this.clearOuterCanvas(this.lowerContext),(t.isCircleCrop||t.currSelectionPoint&&"crop-circle"===t.currSelectionPoint.shape)&&t.notify("crop",{prop:"cropCircle",onPropertyChange:!1,value:{context:this.lowerContext,isSave:null,isFlip:null}}))},t.prototype.cancelZoom=function(){var t=this.parent,i=t.transform.cropZoomFactor-this.tempZoomFactor;if(t.transform.zoomFactor=t.transform.cropZoomFactor,e.isNullOrUndefined(t.cropObj.activeObj.shape)&&(0===t.transform.degree&&0===t.panPoint.totalPannedPoint.x&&0===t.panPoint.totalPannedPoint.y||0!==t.transform.degree&&0===t.panPoint.totalPannedInternalPoint.x&&0===t.panPoint.totalPannedInternalPoint.y&&0===t.panPoint.totalPannedClientPoint.x&&0===t.panPoint.totalPannedClientPoint.y)){this.upperContext.clearRect(0,0,t.upperCanvas.width,t.upperCanvas.height),t.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),i>0?t.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:-i,zoomPoint:null}}):t.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:Math.abs(i),zoomPoint:null}}),t.transform.cropZoomFactor=this.tempZoomFactor,t.currObjType.isCustomCrop=!1,t.upperCanvas.style.cursor=t.cursor="default",t.currObjType.isCustomCrop=!1,this.tempStrokeSettings={strokeColor:"#fff",fillColor:"",strokeWidth:null};e.isBlazor()?t.updateToolbar(t.element,"imageLoaded"):t.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"main",isApplyBtn:null,isCropping:!1,isZooming:null}})}else{if(e.isNullOrUndefined(t.cropObj.activeObj.shape)){if(0===t.transform.degree){var o=e.extend({},t.activeObj,{});t.img.destLeft+=-t.panPoint.totalPannedPoint.x,t.img.destTop+=-t.panPoint.totalPannedPoint.y,t.notify("transform",{prop:"drawPannImage",onPropertyChange:!1,value:{point:{x:-t.panPoint.totalPannedPoint.x,y:-t.panPoint.totalPannedPoint.y}}}),this.updateFlipPan(o),t.panPoint.totalPannedPoint={x:0,y:0}}else t.panPoint.totalPannedClientPoint={x:-t.panPoint.totalPannedClientPoint.x,y:-t.panPoint.totalPannedClientPoint.y},t.panPoint.totalPannedInternalPoint={x:-t.panPoint.totalPannedInternalPoint.x,y:-t.panPoint.totalPannedInternalPoint.y},t.notify("transform",{prop:"rotatePan",onPropertyChange:!1,value:{isCropSelection:!0,isDefaultZoom:null}}),t.panPoint.totalPannedClientPoint={x:0,y:0},t.panPoint.totalPannedInternalPoint={x:0,y:0},t.panPoint.currentPannedPoint={x:0,y:0};t.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),this.upperContext.clearRect(0,0,t.upperCanvas.width,t.upperCanvas.height),i>0?t.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:-i,zoomPoint:null}}):t.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:Math.abs(i),zoomPoint:null}}),t.transform.cropZoomFactor=this.tempZoomFactor}else{this.isCancelAction=!0,t.objColl=[],t.pointColl=[];var r=t.freehandCounter;t.freehandCounter=0;var n={selPointColl:null};t.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:n}});var a=n.selPointColl;t.notify("freehand-draw",{prop:"setSelPointColl",onPropertyChange:!1,value:{obj:{selPointColl:[]}}});var s=e.extend({},t.cropObj,{}),l=e.extend([],t.afterCropActions,{},!0);this.setCurrentObj(),t.notify("crop",{prop:"cropImg",onPropertyChange:!1,value:{isRotateCrop:null}}),t.cropObj=s,t.afterCropActions=l,t.objColl=e.extend([],this.cancelObjColl,[],!0),t.pointColl=e.extend([],this.cancelPointColl,[],!0),t.freehandCounter=r,t.notify("freehand-draw",{prop:"setSelPointColl",onPropertyChange:!1,value:{obj:{selPointColl:a}}}),t.notify("shape",{prop:"iterateObjColl",onPropertyChange:!1}),t.notify("freehand-draw",{prop:"freehandRedraw",onPropertyChange:!1,value:{context:this.lowerContext,points:null}}),this.clearOuterCanvas(this.lowerContext),t.isCircleCrop&&t.notify("crop",{prop:"cropCircle",onPropertyChange:!1,value:{context:this.lowerContext,isSave:null,isFlip:null}}),this.isCancelAction=!1}t.transform.zoomFactor=t.transform.defaultZoomFactor,e.isBlazor()?t.updateToolbar(t.element,"enableDisableToolbarBtn"):t.notify("toolbar",{prop:"enable-disable-btns",onPropertyChange:!1})}},t.prototype.updateFlipPan=function(t){var e=this.parent;if(""!==e.transform.currFlipState){var i=this.lowerContext.filter;e.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),e.notify("transform",{prop:"rotatedFlip",onPropertyChange:!1}),this.lowerContext.filter="none",e.notify("freehand-draw",{prop:"freehandRedraw",onPropertyChange:!1,value:{context:this.lowerContext,points:null}}),this.lowerContext.filter=i,this.upperContext.clearRect(0,0,e.upperCanvas.width,e.upperCanvas.height),t&&this.drawObject("duplicate",t)}},t.prototype.select=function(t,i,o,r,n){var a=this.parent;if(!a.disabled&&a.isImageLoaded){var s={currObj:{}};a.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:s}});var l=s.currObj;l.objColl=e.extend([],a.objColl,[],!0),l.pointColl=e.extend([],a.pointColl,[],!0),l.afterCropActions=a.afterCropActions;var p={selPointColl:null};a.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:p}}),l.selPointColl=e.extend([],p.selPointColl,[],!0),a.notify("crop",{prop:"setPreviousCropCurrentObj",onPropertyChange:!1,value:{obj:l}}),a.transform.zoomFactor>0&&a.activeObj.shape&&"crop"===a.activeObj.shape.split("-")[0]&&e.isNullOrUndefined(this.currSelPoint)&&(this.currSelPoint=e.extend({},a.activeObj,{},!0));var h=!1,c=void 0;void 0!==a.activeObj.shape&&(c=a.activeObj.shape.split("-")),void 0===c&&a.currObjType.isCustomCrop?h=!0:void 0!==c&&"crop"===c[0]&&(h=!0);var d={currObj:{}};a.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:d}});var v=d.currObj;if(v.objColl=e.extend([],a.objColl,[],!0),v.pointColl=e.extend([],a.pointColl,[],!0),v.afterCropActions=e.extend([],a.afterCropActions,[],!0),a.notify("shape",{prop:"redrawActObj",onPropertyChange:!1,value:{x:null,y:null,isMouseDown:null}}),a.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),a.notify("shape",{prop:"setKeyHistory",onPropertyChange:!1,value:{keyHistory:""}}),this.upperContext.clearRect(0,0,a.upperCanvas.width,a.upperCanvas.height),a.upperCanvas.style.display="block",a.currSelectionPoint||0!==a.transform.defaultZoomFactor||0!==a.transform.degree&&0!==a.panPoint.totalPannedInternalPoint.x&&0!==a.panPoint.totalPannedInternalPoint.y&&!h){if(a.isCircleCrop=!1,0!==a.transform.defaultZoomFactor){var u=a.isCropTab;a.isCropTab=!1,a.notify("transform",{prop:"resetZoom",onPropertyChange:!1}),a.isCropTab=u,this.resetPanPoints()}this.cancelObjColl=e.extend([],a.objColl,[],!0),this.cancelPointColl=e.extend([],a.pointColl,[],!0),a.notify("freehand-draw",{prop:"updateFHDColl",onPropertyChange:!1}),a.isCropTab=!0,a.isCircleCrop=!1,a.notify("crop",{prop:"setCurrSelPoints",onPropertyChange:!1,value:{isSetDimension:!0}}),a.transform.zoomFactor=a.transform.cropZoomFactor,e.isNullOrUndefined(a.cropObj.activeObj.shape)&&(a.currObjType.shape="crop-"+t.toLowerCase(),this.drawNewSelection(t,i,o,r,n))}else"custom"===t&&(a.currObjType.shape=""),this.drawNewSelection(t,i,o,r,n)}},t.prototype.drawNewSelection=function(t,e,i,o,r){var n,a=this.parent,s="crop-"+t;"crop-custom"===s.toLowerCase()?""!==a.currObjType.shape&&"crop-custom"!==a.currObjType.shape||this.drawCustomSelection("crop-custom",e,i,o,r):"crop-canvas"===s.toLowerCase()?(a.upperCanvas.style.display="block",a.notify("selection",{prop:"setDragCanvas",value:{bool:!0}})):(a.currObjType.isCustomCrop=!1,a.currObjType.shape=s.toLowerCase(),o&&r?n={startX:e,startY:i,endX:e+o,endY:i+r,width:o,height:r}:o&&"crop-circle"===s&&(n={startX:e,startY:i,endX:e+o,endY:i+o,width:o,height:o}),a.activeObj.shape=s.toLowerCase(),this.updateSelectionInsert(n))},t.prototype.updateSelectionInsert=function(t){var i=this,o=this.parent,r=o.activeObj.activePoint,n={shapeSettingsObj:{}};o.notify("selection",{prop:"updatePrevShapeSettings",onPropertyChange:!1,value:{obj:n}});var a={type:o.getSelectionType(n.shapeSettingsObj.type),startX:n.shapeSettingsObj.startX,startY:n.shapeSettingsObj.startY,width:n.shapeSettingsObj.width,height:n.shapeSettingsObj.height},s={action:"insert",previousSelectionSettings:a,currentSelectionSettings:a};e.isBlazor()&&o.events&&!0===o.events.onSelectionResizeStart.hasDelegate?o.dotNetRef.invokeMethodAsync("SelectionEventAsync","OnSelectionResizeStart",s).then(function(e){o.notify("shape",{prop:"updSelChangeEventArgs",onPropertyChange:!1,value:{selectionSettings:e.currentSelectionSettings}}),"Custom"===e.currentSelectionSettings.type?i.drawObject("duplicate",o.activeObj,null,null,!0):(0===r.startX&&0===r.startY&&0===r.width&&0===r.height||(t={startX:r.startX,startY:r.startY,endX:r.endX,endY:r.endY,width:r.width,height:r.height}),i.drawObject("duplicate",null,!0,t))}):(o.trigger("selectionChanging",s),o.notify("shape",{prop:"updSelChangeEventArgs",onPropertyChange:!1,value:{selectionSettings:s.currentSelectionSettings}}),"Custom"===s.currentSelectionSettings.type?this.drawObject("duplicate",o.activeObj,null,null,!0):(0===r.startX&&0===r.startY&&0===r.width&&0===r.height||(t={startX:r.startX,startY:r.startY,endX:r.endX,endY:r.endY,width:r.width,height:r.height}),this.drawObject("duplicate",null,!0,t)))},t.prototype.drawCustomSelection=function(t,i,o,r,n){var a=this.parent,s=a.activeObj.activePoint;if(a.currObjType.isCustomCrop=!0,this.upperContext.clearRect(0,0,a.upperCanvas.width,a.upperCanvas.height),a.currObjType.shape=a.activeObj.shape=t.toLowerCase(),e.isNullOrUndefined(i)||e.isNullOrUndefined(o)||e.isNullOrUndefined(r)||e.isNullOrUndefined(n)){if(e.isNullOrUndefined(a.transform.zoomFactor)||0===a.transform.zoomFactor){var l=a.img.destLeft,p=a.img.destTop,h=a.img.destWidth,c=a.img.destHeight,d=a.lowerCanvas.width,v=a.lowerCanvas.height,u=s;l>=0&&p>=0?(u.startX=l,u.startY=p,u.endX=l+h,u.endY=p+c):l>=0?(u.startX=l,u.startY=7.5,u.endX=l+h,u.endY=v-15):p>=0?(u.startX=7.5,u.startY=p,u.endX=d-15,u.endY=p+c):(u.startX=7.5,u.startY=7.5,u.endX=d-15,u.endY=v-15)}else{var g=a.img.destLeft,b=a.img.destTop,C=a.img.destWidth,f=a.img.destHeight,m=a.lowerCanvas.width,y=a.lowerCanvas.height,P=s;P.startX=Math.max(g>0?g:7.5,g),P.startY=Math.max(b>0?b:7.5,b),P.endX=Math.min(g+C+15<m?g+C-15:m-15,g+C),P.endY=Math.min(b+f+15<y?b+f-15:y-15,b+f)}var j=a.img.destLeft,O=a.img.destTop,x=a.img.destWidth,w=a.img.destHeight,S=a.lowerCanvas.clientWidth,T=a.lowerCanvas.clientHeight,k=s;k.startX=Math.max(k.startX,j),k.startY=Math.max(k.startY,O),k.endX=Math.min(k.endX,j+x),k.endY=Math.min(k.endY,O+w),k.startX===j&&j+x>S&&(k.endX=S-15),k.startY===O&&O+w>T&&(k.endY=T-15),a.activeObj=this.updateWidthHeight(a.activeObj),this.updateActiveObject(s,a.activeObj)}else s.startX=i,s.startY=o,s.endX=i+r,s.endY=o+n,s.width=r,s.height=n;this.updateSelectionInsert()},t.prototype.callUpdateCurrTransState=function(){var t=this.parent,i=e.extend([],t.objColl,[],!0),o=e.extend({},t.activeObj,{},!0);t.objColl=[],t.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),this.isRotateZoom=!0,this.updateCurrTransState("initial"),this.lowerContext.clearRect(0,0,t.lowerCanvas.width,t.lowerCanvas.height),0===t.transform.degree&&t.rotateFlipColl.length>0&&(t.img.destLeft+=t.panPoint.totalPannedPoint.x,t.img.destTop+=t.panPoint.totalPannedPoint.y),t.img.destLeft+=t.panPoint.totalPannedInternalPoint.x,t.img.destTop+=t.panPoint.totalPannedInternalPoint.y;var r=this.lowerContext.filter;0===t.transform.degree&&t.notify("transform",{prop:"setDestPointsForFlipState",onPropertyChange:!1}),t.notify("filter",{prop:"updateBrightFilter",onPropertyChange:!1}),this.lowerContext.drawImage(t.baseImg,t.img.srcLeft,t.img.srcTop,t.img.srcWidth,t.img.srcHeight,t.img.destLeft,t.img.destTop,t.img.destWidth,t.img.destHeight),this.updateCurrTransState("reverse"),0===t.transform.degree&&t.rotateFlipColl.length>0&&(t.img.destLeft+=t.panPoint.totalPannedPoint.x,t.img.destTop+=t.panPoint.totalPannedPoint.y),this.isRotateZoom=!1,t.objColl=i;var n=t.togglePen;t.togglePen=!1,this.lowerContext.filter="none",t.notify("shape",{prop:"iterateObjColl",onPropertyChange:!1}),t.img.destLeft+=t.panPoint.totalPannedInternalPoint.x,t.img.destTop+=t.panPoint.totalPannedInternalPoint.y,t.notify("freehand-draw",{prop:"freehandRedraw",onPropertyChange:!1,value:{context:this.lowerContext,points:null}}),t.img.destLeft-=t.panPoint.totalPannedInternalPoint.x,t.img.destTop-=t.panPoint.totalPannedInternalPoint.y,t.togglePen=n,this.lowerContext.filter=r,t.activeObj=o},t.prototype.resetPanPoints=function(){this.parent.panPoint.totalPannedPoint={x:0,y:0},this.parent.panPoint.totalPannedClientPoint={x:0,y:0},this.parent.panPoint.totalPannedInternalPoint={x:0,y:0}},t.prototype.setClientTransDim=function(t){var i=this.parent;if(i.transform.degree%90==0&&i.transform.degree%180!=0){i.img.destLeft=(i.lowerCanvas.width-i.img.destHeight)/2,i.img.destTop=(i.lowerCanvas.height-i.img.destWidth)/2;var o=i.img.destWidth;i.img.destWidth=i.img.destHeight,i.img.destHeight=o}else e.isNullOrUndefined(t)&&(i.img.destLeft=(i.lowerCanvas.width-i.img.destWidth)/2,i.img.destTop=(i.lowerCanvas.height-i.img.destHeight)/2)},t.prototype.redrawImgWithObj=function(){var t=this.parent,i={canvasFilter:t.canvasFilter};if(this.lowerContext.filter=i.canvasFilter,0!==t.rotateFlipColl.length){var o=e.extend({},t.panPoint.totalPannedInternalPoint,{},!0),r={startX:t.img.destLeft,startY:t.img.destTop,width:t.img.destWidth,height:t.img.destHeight};this.callUpdateCurrTransState(),t.panPoint.totalPannedInternalPoint=o,t.img.destLeft=r.startX,t.img.destTop=r.startY,t.img.destWidth=r.width,t.img.destHeight=r.height}else this.callUpdateCurrTransState();t.isCircleCrop&&t.notify("crop",{prop:"cropCircle",onPropertyChange:!1,value:{context:this.lowerContext,isSave:null,isFlip:null}});var n=this.lowerContext.filter;this.lowerContext.filter=t.getDefaultFilter(),t.notify("shape",{prop:"iterateObjColl",onPropertyChange:!1}),t.notify("freehand-draw",{prop:"freehandRedraw",onPropertyChange:!1,value:{context:this.lowerContext,points:null}}),this.lowerContext.filter=n},t.prototype.setCurrentObj=function(t){var i=this.parent,o=!!t;t=t||i.cropObj,i.transform.cropZoomFactor=t.cropZoom,i.transform.defaultZoomFactor=t.defaultZoom,o?t.activeObj.shape&&"crop"===t.activeObj.shape.split("-")[0]?i.transform.zoomFactor=t.cropZoom:i.transform.zoomFactor=t.defaultZoom:i.transform.zoomFactor=t.cropZoom,i.setProperties({zoomSettings:{zoomFactor:t.zoomFactor}},!0),i.notify("transform",{prop:"setPreviousZoomValue",onPropertyChange:!1,value:{previousZoomValue:t.previousZoomValue}}),i.panPoint.totalPannedPoint=e.extend({},t.totalPannedPoint,{},!0),i.panPoint.totalPannedClientPoint=e.extend({},t.totalPannedClientPoint,{},!0),i.panPoint.totalPannedInternalPoint=e.extend({},t.totalPannedInternalPoint,{},!0);var r=e.extend({},t.tempFlipPanPoint,{},!0);i.notify("crop",{prop:"setTempFlipPanPoint",onPropertyChange:!1,value:{point:r}}),i.rotateFlipColl=e.extend([],t.rotateFlipColl,[],!0),i.transform.degree=t.degree,i.transform.currFlipState=t.currFlipState,i.img.destLeft=t.destPoints.startX,i.img.destTop=t.destPoints.startY,i.img.destWidth=t.destPoints.width,i.img.destHeight=t.destPoints.height,i.img.srcLeft=t.srcPoints.startX,i.img.srcTop=t.srcPoints.startY,i.img.srcWidth=t.srcPoints.width,i.img.srcHeight=t.srcPoints.height,t.afterCropActions&&(i.afterCropActions=t.afterCropActions),this.lowerContext.filter=t.filter,i.notify("filter",{prop:"setBrightnessAdjusted",onPropertyChange:!1,value:{isBrightnessAdjusted:!1}});var n,a=i.isCircleCrop;e.isNullOrUndefined(i.currSelectionPoint)?n=null:(n=e.extend({},i.currSelectionPoint,{},!0),i.currSelectionPoint=null),i.isCircleCrop=!1,this.drawCropSelectionImage(t,!1),0!==i.transform.degree&&(""===i.transform.currFlipState?i.notify("transform",{prop:"rotatePan",onPropertyChange:!1,value:{isCropSelection:null,isDefaultZoom:null}}):i.notify("transform",{prop:"drawPannedImage",value:{xDiff:0,yDiff:0}}),i.img.destLeft=t.destPoints.startX,i.img.destTop=t.destPoints.startY,i.panPoint.totalPannedClientPoint=e.extend({},t.totalPannedClientPoint,{},!0),i.panPoint.totalPannedInternalPoint=e.extend({},t.totalPannedInternalPoint,{},!0)),i.activeObj=e.extend({},t.activeObj,{},!0),this.upperContext.clearRect(0,0,i.upperCanvas.width,i.upperCanvas.height),0!==i.activeObj.activePoint.width&&0!==i.activeObj.activePoint.height&&this.drawObject("duplicate",null,null,null,!0);var s=e.extend({},t.activeObj,{},!0),l=!1;if(i.afterCropActions.length>0){var p={collection:i.afterCropActions};i.notify("shape",{prop:"alignRotateFlipColl",onPropertyChange:!1,value:{collection:i.afterCropActions,isRotateFlipCollection:null,obj:p}}),i.afterCropActions=p.collection}var h=e.extend([],i.afterCropActions,[],!0);if(!o&&h.length>0){l=!0;for(var c=0;c<h.length;c++)"horizontalflip"!==h[c]&&"verticalflip"!==h[c]||(i.activeObj=e.extend({},n,{},!0),this.rotatedFlipCropSel=!0),i.notify("transform",{prop:"updateTransform",onPropertyChange:!1,value:{text:h[c]}});s=e.extend({},i.activeObj,{},!0),this.resetPanPoints(),i.activeObj=s,this.upperContext.clearRect(0,0,i.upperCanvas.width,i.upperCanvas.height),0!==i.activeObj.activePoint.width&&0!==i.activeObj.activePoint.height&&this.drawObject("duplicate",null,null,null,!0),t.degree!==i.transform.degree&&(i.transform.cropZoomFactor=null,i.transform.zoomFactor=0),i.notify("freehand-draw",{prop:"updateFHDColl",onPropertyChange:!1}),this.rotatedFlipCropSel&&(this.rotatedFlipCropSel=!1)}i.afterCropActions=h,this.isCancelAction||l||(i.notify("freehand-draw",{prop:"updateFHDColl",onPropertyChange:!1}),i.notify("freehand-draw",{prop:"zoomFHDColl",onPropertyChange:!1,value:{isPreventApply:null}}),i.img.destLeft=t.destPoints.startX,i.img.destTop=t.destPoints.startY),i.activeObj=s,i.isCircleCrop=a,e.isNullOrUndefined(n)?i.currSelectionPoint=null:(i.currSelectionPoint=e.extend({},n,{},!0),i.currSelectionPoint&&e.isNullOrUndefined(i.currSelectionPoint.shape)&&(i.currSelectionPoint=null))},t.prototype.drawCropSelectionImage=function(t,i){var o=this.parent,r=this.lowerContext.filter;o.clearContext(this.lowerContext),o.clearContext(this.upperContext),this.lowerContext.setTransform(1,0,0,1,0,0),i?this.updateCurrTransState("initial"):this.setTransformColl(this.lowerContext,"initial"),o.notify("transform",{prop:"setDestPointsForFlipState",onPropertyChange:!1}),this.lowerContext.drawImage(o.baseImg,o.img.srcLeft,o.img.srcTop,o.img.srcWidth,o.img.srcHeight,o.img.destLeft,o.img.destTop,o.img.destWidth,o.img.destHeight),i?this.updateCurrTransState("reverse"):this.setTransformColl(this.lowerContext,"reverse"),o.img.destLeft=o.cropObj.destPoints.startX,o.img.destTop=o.cropObj.destPoints.startY;var n=e.extend({},t.activeObj,{},!0);if(this.lowerContext.filter="none",this.isCancelAction)o.notify("shape",{prop:"zoomObjColl",onPropertyChange:!1,value:{isPreventApply:null}}),o.notify("freehand-draw",{prop:"zoomFHDColl",onPropertyChange:!1,value:{isPreventApply:null}});else{o.img.destLeft=t.destPoints.startX,o.img.destTop=t.destPoints.startY,o.img.destWidth=t.destPoints.width,o.img.destHeight=t.destPoints.height,o.img.srcLeft=t.srcPoints.startX,o.img.srcTop=t.srcPoints.startY,o.img.srcWidth=t.srcPoints.width,o.img.srcHeight=t.srcPoints.height;var a={startX:o.img.destLeft,startY:o.img.destTop,width:o.img.destWidth,height:o.img.destHeight};o.img.destLeft=t.activeObj.activePoint.startX,o.img.destTop=t.activeObj.activePoint.startY,o.img.destWidth=t.activeObj.activePoint.width,o.img.destHeight=t.activeObj.activePoint.height,o.notify("shape",{prop:"zoomObjColl",onPropertyChange:!1,value:{isPreventApply:null}}),o.notify("freehand-draw",{prop:"zoomFHDColl",onPropertyChange:!1,value:{isPreventApply:null}}),o.img.destLeft=a.startX,o.img.destTop=a.startY,o.img.destWidth=a.width,o.img.destHeight=a.height}o.activeObj=n,this.lowerContext.filter=r},t.prototype.performPointZoom=function(t,i,o){var r=this.parent,n=(t-r.img.destLeft)/r.img.destWidth,a=(i-r.img.destTop)/r.img.destHeight,s=r.isUndoRedo;if(r.isUndoRedo=!0,r.setProperties({zoomSettings:{zoomPoint:{x:t,y:i}}},!0),"zoomIn"===o?r.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:.1,zoomPoint:null}}):"zoomOut"===o&&r.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:-.1,zoomPoint:null}}),r.isUndoRedo=s,r.transform.zoomFactor>0){var l=r.img.destLeft,p=r.img.destTop,h=e.extend({},r.activeObj,{},!0);if(0===r.transform.degree)r.img.destLeft=t-n*r.img.destWidth,r.img.destTop=i-a*r.img.destHeight,this.drawZoomPanImage(r.img.destLeft-l,r.img.destTop-p);else{var c=r.isCropTab;r.isCropTab=!0;var d=e.extend([],r.objColl,[],!0),v=e.extend([],r.pointColl,[],!0);r.objColl=[],r.pointColl=[],r.freehandCounter=0;var u={selPointColl:null};r.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:u}});var g=u.selPointColl;r.notify("freehand-draw",{prop:"setSelPointColl",onPropertyChange:!1,value:{obj:{selPointColl:[]}}}),r.panPoint.currentPannedPoint={x:t-n*r.img.destWidth-l,y:i-a*r.img.destHeight-p},r.notify("transform",{prop:"rotatePan",onPropertyChange:!1,value:{isCropSelection:null,isDefaultZoom:null}}),r.isCropTab=c,r.objColl=d,r.pointColl=v,r.freehandCounter=r.pointColl.length,r.notify("freehand-draw",{prop:"setSelPointColl",onPropertyChange:!1,value:{obj:{selPointColl:g}}}),r.notify("shape",{prop:"panObjColl",onPropertyChange:!1,value:{xDiff:r.panPoint.currentPannedPoint.x,yDiff:r.panPoint.currentPannedPoint.y,panRegion:""}}),r.notify("freehand-draw",{prop:"panFHDColl",onPropertyChange:!1,value:{xDiff:r.panPoint.currentPannedPoint.x,yDiff:r.panPoint.currentPannedPoint.y,panRegion:""}})}this.adjustPanning(h),r.activeObj=h,0!==r.activeObj.activePoint.width&&0!==r.activeObj.activePoint.height&&this.drawObject("duplicate",null,null,null,!0)}},t.prototype.adjustPanning=function(t){var i=this.parent;if(0!==t.activePoint.width&&0!==t.activePoint.height){var o=i.img.destLeft,r=i.img.destTop,n={x:0,y:0};if(i.img.destLeft>t.activePoint.startX?n.x=i.img.destLeft-t.activePoint.startX:i.img.destLeft+i.img.destWidth<t.activePoint.startX+t.activePoint.width&&(n.x=i.img.destLeft+i.img.destWidth-(t.activePoint.startX+t.activePoint.width)),i.img.destTop>t.activePoint.startY?n.y=i.img.destTop-t.activePoint.startY:i.img.destTop+i.img.destHeight<t.activePoint.startY+t.activePoint.height&&(n.y=i.img.destTop+i.img.destHeight-(t.activePoint.startY+t.activePoint.height)),0===i.transform.degree)i.img.destLeft-=n.x,i.img.destTop-=n.y,this.drawZoomPanImage(i.img.destLeft-o,i.img.destTop-r);else{var a=i.isCropTab;i.isCropTab=!0;var s=e.extend([],i.objColl,[],!0),l=e.extend([],i.pointColl,[],!0);i.objColl=[],i.pointColl=[],i.freehandCounter=0;var p={selPointColl:null};i.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:p}});var h=p.selPointColl;i.notify("freehand-draw",{prop:"setSelPointColl",onPropertyChange:!1,value:{obj:{selPointColl:[]}}}),i.img.destLeft-=n.x,i.img.destTop-=n.y,i.panPoint.currentPannedPoint={x:i.img.destLeft-o,y:i.img.destTop-r},i.notify("transform",{prop:"rotatePan",onPropertyChange:!1,value:{isCropSelection:null,isDefaultZoom:null}}),i.isCropTab=a,i.objColl=s,i.pointColl=l,i.freehandCounter=i.pointColl.length,i.notify("freehand-draw",{prop:"setSelPointColl",onPropertyChange:!1,value:{obj:{selPointColl:h}}}),i.notify("shape",{prop:"panObjColl",onPropertyChange:!1,value:{xDiff:i.panPoint.currentPannedPoint.x,yDiff:i.panPoint.currentPannedPoint.y,panRegion:""}}),i.notify("freehand-draw",{prop:"panFHDColl",onPropertyChange:!1,value:{xDiff:i.panPoint.currentPannedPoint.x,yDiff:i.panPoint.currentPannedPoint.y,panRegion:""}})}}},t.prototype.drawZoomPanImage=function(t,e){var i=this.parent;i.notify("shape",{prop:"panObjColl",onPropertyChange:!1,value:{xDiff:t,yDiff:e,panRegion:""}}),i.notify("freehand-draw",{prop:"panFHDColl",onPropertyChange:!1,value:{xDiff:t,yDiff:e,panRegion:""}}),this.renderImage(!0);var o={width:0,height:0};i.notify("transform",{prop:"calcMaxDimension",onPropertyChange:!1,value:{width:i.img.srcWidth,height:i.img.srcHeight,obj:o}});var r=o;r.width+=r.width*i.transform.zoomFactor,r.height+=r.height*i.transform.zoomFactor,i.panPoint.totalPannedPoint.x+=t,i.panPoint.totalPannedPoint.y+=e,i.notify("crop",{prop:"setTempFlipPanPoint",onPropertyChange:!1,value:{point:{x:0,y:0}}})},t.prototype.openNewImage=function(){var t=this.parent,o=t.inMemoryCanvas.getContext("2d");i.showSpinner(t.element),t.element.style.opacity="0.5";var r=document.querySelector("#"+t.element.id+"_currPos");r&&(r.style.display="none");var n={defToolbarItems:null};if(e.isBlazor())t.element.querySelector("#"+t.element.id+"_toolbar")?t.toolbarHeight=t.element.querySelector("#"+t.element.id+"_toolbar").clientHeight:t.toolbarHeight=0;else if(t.notify("toolbar",{prop:"getDefToolbarItems",value:{obj:n}}),0===n.defToolbarItems.length&&e.isNullOrUndefined(document.getElementById(t.element.id+"_toolbar")))if(e.isNullOrUndefined(t.toolbarTemplate))t.notify("toolbar",{prop:"setToolbarHeight",value:{height:0}});else if(t.element.querySelector("#"+t.element.id+"_toolbarArea")){var a=t.element.querySelector("#"+t.element.id+"_toolbarArea").clientHeight;t.notify("toolbar",{prop:"setToolbarHeight",value:{height:a}})}t.reset(),t.update(),t.transform.degree=0,t.transform.zoomFactor=0,t.isImageLoaded=!1,t.currSelectionPoint=null;if("string"===typeof this.openURL){var s=this.openURL.split(".");if(s.length>1?(s=s[s.length-2].split("/"),this.fileName=s[s.length-1]):this.fileName="ImageEditor",this.fileType=this.getFileExtensionFromURL(this.openURL),this.fileType){this.fileType=t.toPascalCase(this.fileType);var l=this.fileType.toLowerCase();"jpg"!==l&&"jpeg"!==l||(this.fileType="Jpeg",l="jpeg"),"jpeg"!==l&&"png"!==l&&"svg"!==l&&(this.fileType=null)}this.imageOnLoad(this.openURL)}else this.fileName="ImageEditor",this.fileType=null,t.lowerCanvas=document.querySelector("#"+t.element.id+"_lowerCanvas"),t.upperCanvas=document.querySelector("#"+t.element.id+"_upperCanvas"),this.lowerContext=t.lowerCanvas.getContext("2d"),this.upperContext=t.upperCanvas.getContext("2d"),t.clearContext(this.lowerContext),t.clearContext(this.upperContext),t.clearContext(o),t.inMemoryCanvas.width=t.baseImg.width=this.openURL.width,t.inMemoryCanvas.height=t.baseImg.height=this.openURL.height,o.putImageData(this.openURL,0,0),t.baseImg.src=t.inMemoryCanvas.toDataURL()},t.prototype.dlgBtnClick=function(){var t=this.parent;t.export(),this.isFileChanged?(t.isImageLoaded=this.isFileChanged=!1,t.reset(),this.checkToolbarTemplate(this.inputElem,this.openURL)):(this.reset(),this.openNewImage()),e.isBlazor()||e.getComponent(document.getElementById(t.element.id+"_dialog"),"dialog").destroy(),this.isImageEdited=!1},t.prototype.dlgCloseBtnClick=function(){var t=this.parent;this.baseImgSrc=t.baseImg.src,this.isFileChanged?(t.isImageLoaded=this.isFileChanged=!1,t.reset(),this.checkToolbarTemplate(this.inputElem,this.openURL)):(this.reset(),this.openNewImage()),e.isBlazor()||e.getComponent(document.getElementById(t.element.id+"_dialog"),"dialog").destroy(),this.isImageEdited=!1},t.prototype.showDialogPopup=function(){this.parent.element.querySelector("#"+this.parent.element.id+"_dialog").style.display="block";new i.Dialog({header:"Confirm Save Changes",closeOnEscape:!0,content:"<span>Do you want to save the changes you made to the image?</span>",target:document.getElementById("target"),width:"285px",isModal:!0,animationSettings:{effect:"Zoom"},close:this.dlgCloseBtnClick.bind(this),buttons:[{click:this.dlgCloseBtnClick.bind(this),buttonModel:{content:"No",iconCss:"e-icons e-close"}},{click:this.dlgBtnClick.bind(this),buttonModel:{content:"Yes",isPrimary:!0,iconCss:"e-icons e-check"}}]}).appendTo("#"+this.parent.element.id+"_dialog")},t.prototype.restoreOldImage=function(){this.parent.isImageLoaded?(this.reset(),this.openNewImage()):this.openNewImage()},t.prototype.open=function(t){this.parent.disabled||(this.openURL=t,this.restoreOldImage())},t.prototype.getInitialLoaded=function(t){t.isInitialLoaded=this.isInitialLoading},t.prototype.getFileExtensionFromURL=function(t){var e=t.lastIndexOf(".");return-1!==e?t.slice(e+1).toLowerCase():null},t.prototype.fileSelect=function(t,o){var r=this.parent;if(!r.disabled){var n=o.target.files[0],a=n,s=a.name&&a.name.split(".")[1].toLowerCase();if(s&&-1===["jpg","jpeg","png","svg"].indexOf(s))return;if(i.showSpinner(r.element),r.element.style.opacity="0.5",this.inputElem=t,s=a.name&&a.name.split(".")[1]){var l=r.toPascalCase(s);this.fileType="JPG"===l||"Jpg"===l?"Jpeg":l}else this.fileType=null;var p=window.URL.createObjectURL(n);this.openURL=p,r.isImageLoaded&&(this.isImageEdited||r.pointColl.length>0||r.objColl.length>0)?(this.isFileChanged=!0,e.isBlazor()?r.dotNetRef.invokeMethodAsync("UpdateDialog"):this.showDialogPopup()):this.checkToolbarTemplate(t,p)}},t.prototype.checkToolbarTemplate=function(t,i){var o=this.parent;e.isNullOrUndefined(o.toolbarTemplate)&&(o.reset(),o.update()),this.fileName=t.value.split("\\")[t.value.split("\\").length-1],this.fileName=this.fileName.split(".")[0],this.imageOnLoad(i.toString()),t.value=""},t}(),l=function(){function t(t){this.parent=t,this.addEventListener()}return t.prototype.destroy=function(){this.parent.isDestroyed||this.removeEventListener()},t.prototype.addEventListener=function(){this.parent.on("export",this.export,this),this.parent.on("destroyed",this.destroy,this)},t.prototype.removeEventListener=function(){this.parent.off("export",this.export),this.parent.off("destroyed",this.destroy)},t.prototype.export=function(t){if(e.isBlazor()){var i={shape:""};this.parent.notify("selection",{prop:"getCurrentDrawingShape",onPropertyChange:!1,value:{obj:i}}),""!==i.shape&&(this.parent.notify("selection",{prop:"setCurrentDrawingShape",onPropertyChange:!1,value:{value:""}}),this.parent.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}))}else this.parent.notify("toolbar",{prop:"refreshShapeDrawing",onPropertyChange:!1});switch(this.updatePvtVar(),t.prop){case"export":this.exportImg(t.value.type,t.value.fileName);break;case"exportToCanvas":this.exportToCanvas(t.value.object)}},t.prototype.getModuleName=function(){return"export"},t.prototype.updatePvtVar=function(){var t=this.parent;t.lowerCanvas&&(this.lowerContext=t.lowerCanvas.getContext("2d"))},t.prototype.exportImg=function(t,i){var o=this,r=this.parent,n={fileName:""};r.notify("draw",{prop:"getFileName",onPropertyChange:!1,value:{obj:n}});var a=n.fileName;if(!r.disabled&&r.isImageLoaded){var s={bool:!1};r.notify("selection",{prop:"getFreehandDrawEditing",onPropertyChange:!1,value:{obj:s}}),s.bool&&r.notify("freehand-draw",{prop:"applyFhd",onPropertyChange:!1}),r.togglePen&&(r.currObjType.isZoomed=!0,r.notify("shape",{prop:"apply",onPropertyChange:!1,value:{shape:null,obj:null,canvas:null}})),"block"===r.textArea.style.display&&r.notify("shape",{prop:"redrawActObj",onPropertyChange:!1,value:{x:null,y:null,isMouseDown:null}}),r.notify("shape",{prop:"applyActObj",onPropertyChange:!1,value:{isMouseDown:null}});var l={canvasFilter:this.parent.canvasFilter};this.lowerContext.filter=l.canvasFilter,t=t||"Png",r.notify("shape",{prop:"redrawActObj",onPropertyChange:!1,value:{x:null,y:null,isMouseDown:null}});var p={cancel:!1,fileName:i||a,fileType:t};e.isBlazor()&&r.events&&!0===r.events.saving.hasDelegate?r.dotNetRef.invokeMethodAsync("BeforeSaveEventAsync","BeforeSave",p).then(function(e){o.beforeSaveEvent(e,t,i,a)}):(r.trigger("beforeSave",p),this.beforeSaveEvent(p,t,i,a))}},t.prototype.beforeSaveEvent=function(t,i,o,r){var n=this.parent;if(!t.cancel){n.currObjType.isSave=!0,o=t.fileName?t.fileName:o;var a=i.toLowerCase();o=o||r,"svg"===a?this.toSVGImg(o):this.toBlobFn(o,a);var s={fileName:o||r,fileType:i};n.trigger("saved",s),e.isBlazor()||n.notify("toolbar",{prop:"refresh-main-toolbar",onPropertyChange:!1}),n.lowerCanvas.style.left=n.upperCanvas.style.left="",n.lowerCanvas.style.top=n.upperCanvas.style.top="",n.lowerCanvas.style.maxWidth=n.upperCanvas.style.maxWidth="",n.lowerCanvas.style.maxHeight=n.upperCanvas.style.maxHeight=""}},t.prototype.toSVGImg=function(t){var e=this.parent;i.showSpinner(e.element),e.element.style.opacity="0.5";var o=this.exportToCanvas(),r=o.toDataURL();i.hideSpinner(e.element),e.element.style.opacity="1";var n=document.createElementNS("http://www.w3.org/2000/svg","svg");n.setAttribute("width",o.style.maxWidth),n.setAttribute("height",o.style.maxHeight);var a=document.createElementNS("http://www.w3.org/2000/svg","image");a.setAttributeNS(null,"height",o.height.toString()),a.setAttributeNS(null,"width",o.width.toString()),a.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",r),n.appendChild(a);var s='<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="'+o.width+'" height="'+o.height+'">'+n.innerHTML+"</svg>",l="data:image/svg+xml;base64,"+btoa(s);return null===t?l:(this.downloadImg(l,t+".svg"),null)},t.prototype.toBlobFn=function(t,e){var o=this,r=this.parent;i.showSpinner(r.element),r.element.style.opacity="0.5";this.exportToCanvas().toBlob(function(n){var a=URL.createObjectURL(n);o.downloadImg(a,t+"."+e),i.hideSpinner(r.element),r.element.style.opacity="1"},"image/png")},t.prototype.exportToCanvas=function(t){var i=this.parent,o={width:0,height:0};i.notify("crop",{prop:"calcRatio",onPropertyChange:!1,value:{obj:o}});var r=o,n=this.lowerContext.filter;if("none"!==this.lowerContext.filter){var a=this.lowerContext.filter.split(" "),s=parseFloat(a[5].split("(")[1]);s*=(r.width+r.height)/2,a[5]="blur("+s+"px)",this.lowerContext.filter=a.join(" ")}var l,p=i.createElement("canvas",{id:i.element.id+"_tempCanvas",attrs:{name:"canvasImage"}}),h=p.getContext("2d");if(h.filter=this.lowerContext.filter,i.currSelectionPoint){p.width=i.img.destWidth,p.height=i.img.destHeight,h.filter=this.lowerContext.filter;var c=this.lowerContext.filter;i.notify("filter",{prop:"updateBrightFilter",onPropertyChange:!1}),h.drawImage(i.baseImg,i.img.srcLeft,i.img.srcTop,i.img.srcWidth,i.img.srcHeight,0,0,i.img.destWidth,i.img.destHeight),this.lowerContext.filter=c}else{p.width=i.baseImg.width,p.height=i.baseImg.height;var d={width:0,height:0};i.notify("transform",{prop:"calcMaxDimension",onPropertyChange:!1,value:{width:i.baseImg.width,height:i.baseImg.height,obj:d}}),l=d,p.style.maxWidth=l.width+"px",p.style.maxHeight=l.height+"px",h.filter=this.lowerContext.filter;c=this.lowerContext.filter;i.notify("filter",{prop:"updateBrightFilter",onPropertyChange:!1}),h.drawImage(i.baseImg,i.img.srcLeft,i.img.srcTop,i.img.srcWidth,i.img.srcHeight,0,0,i.baseImg.width,i.baseImg.height),this.lowerContext.filter=c}if(0===i.transform.degree&&""===i.transform.currFlipState||(this.updateSaveContext(h),this.exportTransformedImage(h)),i.objColl.length>0){c=h.filter;h.filter="none";for(var v=e.extend([],i.objColl,[],!0),u=0,g=i.objColl.length;u<g;u++){var b=i.objColl[u].activePoint;b.startX-=i.img.destLeft,b.startY-=i.img.destTop,b.endX-=i.img.destLeft,b.endY-=i.img.destTop,b.width=b.endX-b.startX,b.height=b.endY-b.startY,e.isNullOrUndefined(i.currSelectionPoint)&&(b.startX*=r.width,b.startY*=r.height,b.endX*=r.width,b.endY*=r.height,b.width=b.endX-b.startX,b.height=b.endY-b.startY,i.objColl[u].strokeSettings.strokeWidth*=(r.width+r.height)/2,"text"===i.objColl[u].shape&&(i.objColl[u].textSettings.fontSize*=(r.width+r.height)/2)),i.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"saveContext",obj:i.objColl[u],isCropRatio:null,points:null,isPreventDrag:!0,saveContext:h,isPreventSelection:null}})}h.filter=c,i.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),i.objColl=v}if(i.freehandCounter>0){for(var C=e.extend({},i.pointColl,{},!0),f=0;f<i.freehandCounter;f++){i.points=e.extend([],i.pointColl[f].points,[]),i.notify("freehand-draw",{prop:"setPointCounter",onPropertyChange:!1,value:{value:0}});g=i.points.length;if(i.currSelectionPoint)for(var m=0;m<g;m++)i.points[m].x-=i.img.destLeft,i.points[m].y-=i.img.destTop;else{i.pointColl[f].strokeWidth*=(r.width+r.height)/2;for(m=0;m<g;m++)i.points[m].x=(i.points[m].x-i.img.destLeft)*r.width,i.points[m].y=(i.points[m].y-i.img.destTop)*r.height}}i.notify("freehand-draw",{prop:"freehandRedraw",onPropertyChange:!1,value:{context:h,points:null}}),i.pointColl=C}return i.isCircleCrop&&i.notify("crop",{prop:"cropCircle",onPropertyChange:!1,value:{context:h,isSave:!0,isFlip:null}}),this.lowerContext.filter=n,t&&(t.canvas=p),p},t.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)},t.prototype.exportTransformedImage=function(t){for(var e=this.parent,i=e.transform.degree,o=0,r=e.rotateFlipColl.length;o<r;o++){var n=e.rotateFlipColl[o];"number"==typeof n?this.exportRotate(t,n):"horizontal"===n?this.exportFlip(t,!0,!1):"vertical"===n&&this.exportFlip(t,!1,!0)}e.transform.degree=i},t.prototype.exportRotate=function(t,i){var o=this.parent;e.isNullOrUndefined(o.currSelectionPoint)?(this.setMaxDim(o.transform.degree,t.canvas),t.translate(t.canvas.width/2,t.canvas.height/2),t.rotate(Math.PI/180*i),t.drawImage(o.inMemoryCanvas,o.img.srcLeft,o.img.srcTop,o.img.srcWidth,o.img.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(o.inMemoryCanvas,-t.canvas.height/2,-t.canvas.width/2,t.canvas.height,t.canvas.width)),this.updateSaveContext(t)},t.prototype.exportFlip=function(t,e,i){e&&(t.translate(t.canvas.width,0),t.scale(-1,1)),i&&(t.translate(0,t.canvas.height),t.scale(1,-1)),t.drawImage(this.parent.inMemoryCanvas,0,0),this.updateSaveContext(t)},t.prototype.updateSaveContext=function(t){var e=this.parent.inMemoryCanvas.getContext("2d");t.setTransform(1,0,0,1,0,0);var i=t.getImageData(0,0,t.canvas.width,t.canvas.height);this.parent.inMemoryCanvas.width=i.width,this.parent.inMemoryCanvas.height=i.height,e.putImageData(i,0,0)},t.prototype.setMaxDim=function(t,e){var i,o;t%90==0&&t%180!=0?(i=this.parent.baseImg.height,o=this.parent.baseImg.width):t%180!=0&&0!==t||(i=this.parent.baseImg.width,o=this.parent.baseImg.height),e.width=i,e.height=o;var r={width:0,height:0};this.parent.notify("transform",{prop:"calcMaxDimension",onPropertyChange:!1,value:{width:i,height:o,obj:r}});var n=r;e.style.maxWidth=n.width+"px",e.style.maxHeight=n.height+"px"},t}(),p=function(){function t(t){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.adjustmentValue="",this.isBrightnessAdjusted=!1,this.appliedFilter="",this.parent=t,this.addEventListener()}return t.prototype.destroy=function(){this.parent.isDestroyed||this.removeEventListener()},t.prototype.addEventListener=function(){this.parent.on("filter",this.filter,this),this.parent.on("destroyed",this.destroy,this)},t.prototype.removeEventListener=function(){this.parent.off("filter",this.filter),this.parent.off("destroyed",this.destroy)},t.prototype.filter=function(t){switch(this.updatePrivateVariables(),t.prop){case"finetuneImage":this.finetuneImage(t.value.option,t.value.value);break;case"applyImageFilter":this.setFilter(t.value.option);break;case"update-finetunes":this.updateFinetunes();break;case"updateBrightFilter":this.updateBrightFilter();break;case"set-adjustment":this.setAdjustment(t.value.operation);break;case"update-filter":this.updateFilter(t.value.operation,t.value.filter);break;case"initFilter":this.initFilter();break;case"setCurrAdjValue":this.setCurrAdjValue(t.value.type,t.value.value);break;case"updateAdj":this.updateAdj(t.value.type,t.value.value,t.value.isPreview,t.value.ctx);break;case"getCurrentObj":this.getCurrentObj(t.value.object);break;case"getAdjustmentLevel":t.value.obj.adjustmentLevel=this.adjustmentLevel;break;case"setAdjustmentLevel":this.adjustmentLevel=t.value.adjustmentLevel;break;case"getTempAdjustmentLevel":t.value.obj.tempAdjustmentLevel=this.tempAdjustmentLevel;break;case"setTempAdjustmentLevel":this.tempAdjustmentLevel=t.value.tempAdjustmentLevel;break;case"setAdjustmentValue":this.adjustmentValue=t.value.adjustmentValue;break;case"getBrightnessAdjusted":t.value.obj.isBrightnessAdjusted=this.isBrightnessAdjusted;break;case"setBrightnessAdjusted":this.isBrightnessAdjusted=t.value.isBrightnessAdjusted,this.parent.currentFilter.split("_")&&"cold"===this.parent.currentFilter.split("_")[1]&&(this.isBrightnessAdjusted=!1);break;case"reset":this.reset()}},t.prototype.updatePrivateVariables=function(){var t=this.parent;e.isNullOrUndefined(t.lowerCanvas)||(this.lowerContext=t.lowerCanvas.getContext("2d"))},t.prototype.getModuleName=function(){return"filter"},t.prototype.updateBrightFilter=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(" ")}},t.prototype.reset=function(){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.adjustmentValue=this.parent.getDefaultFilter(),this.isBrightnessAdjusted=!1,this.appliedFilter=""},t.prototype.updateFinetunes=function(){var t=this.parent,e=t.finetuneSettings;e&&(e.brightness&&(this.adjustmentLevel.brightness=e.brightness.defaultValue,this.tempAdjustmentLevel.brightness=e.brightness.defaultValue),e.contrast&&(this.adjustmentLevel.contrast=e.contrast.defaultValue,this.tempAdjustmentLevel.contrast=e.contrast.defaultValue),e.hue&&(this.adjustmentLevel.hue=e.hue.defaultValue,this.tempAdjustmentLevel.hue=e.hue.defaultValue),e.saturation&&(this.adjustmentLevel.saturation=e.saturation.defaultValue,this.tempAdjustmentLevel.saturation=e.saturation.defaultValue),e.exposure&&(this.adjustmentLevel.exposure=e.exposure.defaultValue,this.tempAdjustmentLevel.exposure=e.exposure.defaultValue),e.opacity&&(this.adjustmentLevel.opacity=e.opacity.defaultValue,this.tempAdjustmentLevel.opacity=e.opacity.defaultValue),e.blur&&(this.adjustmentLevel.blur=e.blur.defaultValue,this.tempAdjustmentLevel.blur=e.blur.defaultValue),t.notify("draw",{prop:"isInitialLoading",onPropertyChange:!1,value:{isInitialLoading:!0}}))},t.prototype.initFilter=function(){this.setFilterAdj("brightness",this.adjustmentLevel.brightness),this.setFilterAdj("contrast",this.adjustmentLevel.contrast),this.setFilterAdj("hue",this.adjustmentLevel.hue),this.setFilterAdj("saturation",this.adjustmentLevel.saturation),this.setFilterAdj("exposure",this.adjustmentLevel.exposure),this.setFilterAdj("opacity",this.adjustmentLevel.opacity),this.setFilterAdj("blur",this.adjustmentLevel.blur)},t.prototype.updateAdj=function(t,i,o,r){var n=this.parent;this.lowerContext.clearRect(0,0,n.lowerCanvas.width,n.lowerCanvas.height);var a,s,l=this.lowerContext.filter.split(" "),p=[];l[4]&&(a=parseFloat(l[4].split("(")[1])),l[0]&&(s=parseFloat(l[0].split("(")[1]));var h=this.getFilterValue(this.adjustmentLevel.brightness),c=this.getFilterValue(this.adjustmentLevel.saturation);if(-1===["brightness","contrast","hue","saturation","exposure","opacity","blur"].indexOf(t)&&e.isNullOrUndefined(o)&&(this.adjustmentLevel.sharpen||this.adjustmentLevel.bw)){n.isUndoRedo=!0;var d=this.lowerContext.filter;this.lowerContext.filter="none",n.notify("shape",{prop:"iterateObjColl",onPropertyChange:!1}),n.notify("freehand-draw",{prop:"freehandRedraw",onPropertyChange:!1,value:{context:this.lowerContext,points:null}}),this.lowerContext.filter=d,n.isUndoRedo=!1}1!==h&&(l[4]="opacity("+(a-.3)+")");var v,u,g,b,C;switch(t){case"brightness":100!==parseFloat(l[3].split("(")[1])&&(i+=.1),l[0]="brightness("+i+")",this.adjustmentValue=l.join(" ");break;case"contrast":l[1]="contrast("+i+"%)",this.adjustmentValue=l.join(" ");break;case"hue":l[2]="hue-rotate("+i+"deg)",this.adjustmentValue=l.join(" ");break;case"saturation":l[3]="saturate("+i+"%)",1!==c&&(l[0]="brightness("+(s+.09)+")"),this.adjustmentValue=l.join(" ");break;case"opacity":1!==parseFloat(l[0].split("(")[1])&&(i-=.2),l[4]="opacity("+i+")",this.adjustmentValue=l.join(" ");break;case"blur":l[5]="blur("+i+"px)",this.adjustmentValue=l.join(" ");break;case"exposure":1!==h&&(l[4]="opacity("+(a-.3)+")"),i>1?(i-=1,i+=h):i<1&&(i=h-(i=1-i)),l[0]="brightness("+i+")",this.adjustmentValue=l.join(" ");break;case"chrome":v=this.getSaturationFilterValue(this.adjustmentLevel.saturation),i=(v*=100)+.4*v,l[3]="saturate("+i+"%)",p=this.adjustmentValue.split(" "),l[0]=p[0],l[1]=p[1],l[2]=p[2],l[4]=p[4],l[5]=p[5],l[6]="sepia(0%)",l[7]="grayscale(0%)",l[8]="invert(0%)";break;case"cold":u=this.getFilterValue(this.adjustmentLevel.brightness),i=.9*(u*=100),i*=.01,l[0]="brightness("+i+")",b=this.getFilterValue(this.adjustmentLevel.contrast),i=(b*=100)+.5*b,l[1]="contrast("+i+"%)",C=this.getSaturationFilterValue(this.adjustmentLevel.saturation),i=C*=100,l[3]="saturate("+i+"%)",p=this.adjustmentValue.split(" "),l[2]=p[2],l[4]=p[4],l[5]=p[5],l[6]="sepia(0%)",l[7]="grayscale(0%)",l[8]="invert(0%)";break;case"warm":g=this.getSaturationFilterValue(this.adjustmentLevel.saturation),i=(g*=100)+.4*g,l[3]="saturate("+i+"%)",l[6]="sepia(25%)",p=this.adjustmentValue.split(" "),l[0]=p[0],l[1]=p[1],l[2]=p[2],l[4]=p[4],l[5]=p[5],l[7]="grayscale(0%)",l[8]="invert(0%)";break;case"grayscale":l[7]="grayscale(100%)",p=this.adjustmentValue.split(" "),l[0]=p[0],l[1]=p[1],l[2]=p[2],l[3]=p[3],l[4]=p[4],l[5]=p[5],l[6]="sepia(0%)",l[8]="invert(0%)";break;case"sepia":l[6]="sepia(100%)",p=this.adjustmentValue.split(" "),l[0]=p[0],l[1]=p[1],l[2]=p[2],l[3]=p[3],l[4]=p[4],l[5]=p[5],l[7]="grayscale(0%)",l[8]="invert(0%)";break;case"invert":l[8]="invert(100%)",p=this.adjustmentValue.split(" "),l[0]=p[0],l[1]=p[1],l[2]=p[2],l[3]=p[3],l[4]=p[4],l[5]=p[5],l[6]="sepia(0%)",l[7]="grayscale(0%)"}if("sharpen"!==t&&"blackandwhite"!==t){e.isNullOrUndefined(o)&&("default"===t&&(l=this.getDefaultCurrentFilter(l)),this.lowerContext.filter=l.join(" ")),l=this.setTempFilterValue(h,o,l,t),n.notify("draw",{prop:"setRotateZoom",onPropertyChange:!1,value:{isRotateZoom:!0}}),n.notify("draw",{prop:"updateCurrTransState",onPropertyChange:!1,value:{type:"initial",isPreventDestination:null,isRotatePan:null}}),this.appliedFilter=this.lowerContext.filter,this.lowerContext.drawImage(n.baseImg,n.img.srcLeft,n.img.srcTop,n.img.srcWidth,n.img.srcHeight,n.img.destLeft,n.img.destTop,n.img.destWidth,n.img.destHeight),n.notify("draw",{prop:"updateCurrTransState",onPropertyChange:!1,value:{type:"reverse",isPreventDestination:null,isRotatePan:null}}),n.notify("draw",{prop:"setRotateZoom",onPropertyChange:!1,value:{isRotateZoom:!1}}),1!==h?l[4]="opacity("+a+")":1!==c&&(l[0]="brightness("+s+")"),("exposure"===t&&1!==h||"saturation"===t&&1!==c)&&(l[0]="brightness("+s+")"),l=this.setTempFilterValue(h,o,l,t),e.isNullOrUndefined(o)&&(this.lowerContext.filter=l.join(" ")),n.initialAdjustmentValue=l.join(" ");var f=this.lowerContext.filter;this.lowerContext.filter="brightness(1) contrast(100%) hue-rotate(0deg) saturate(100%) opacity(1) blur(0px) sepia(0%) grayscale(0%) invert(0%)",n.notify("shape",{prop:"iterateObjColl",onPropertyChange:!1}),n.notify("freehand-draw",{prop:"freehandRedraw",onPropertyChange:!1,value:{context:this.lowerContext,points:null}}),this.lowerContext.filter=f,n.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.lowerContext}}),(n.currSelectionPoint&&"crop-circle"===n.currSelectionPoint.shape||n.isCircleCrop)&&n.notify("crop",{prop:"cropCircle",onPropertyChange:!1,value:{context:this.lowerContext,isSave:null,isFlip:null}}),this.isBrightnessAdjusted=1!==h}var m=l.join(" ");r&&(r.filter=m)},t.prototype.setTempFilterValue=function(t,e,i,o){if(e)if("default"===o)i=this.getDefaultCurrentFilter(i);else if(1!==t){var r=this.lowerContext.filter.split(" ");r[4]=i[4],this.lowerContext.filter=r.join(" ")}return i},t.prototype.getDefaultCurrentFilter=function(t){var e=this.adjustmentValue.split(" ");return[e[0],e[1],e[2],e[3],e[4],e[5],"sepia(0%)","grayscale(0%)","invert(0%)"]},t.prototype.getFilterValue=function(t){return 0===t?1:1+.5*t/100},t.prototype.getSaturationFilterValue=function(t){return 0===t?1:1+t/100},t.prototype.setFilterAdj=function(t,i){var o=this.parent;switch(o.notify("freehand-draw",{prop:"apply-pen-draw",onPropertyChange:!1}),this.adjustmentLevel[""+t]=i,t){case"brightness":case"contrast":case"exposure":i=this.getFilterValue(i),"contrast"===t&&(i*=100);break;case"hue":i*=3;break;case"saturation":i=100*this.getSaturationFilterValue(i);break;case"opacity":i>=50?i/=100:40===i?i=.45:30===i?i=.4:20===i?i=.35:10===i?i=.3:0===i&&(i=.25);break;case"blur":0!==i&&(i/=20,i+=.5)}var r=e.extend({},o.cropObj,{},!0),n=this.getCurrentObj();n.objColl=e.extend([],o.objColl,[],!0),n.pointColl=e.extend([],o.pointColl,[],!0),n.afterCropActions=e.extend([],o.afterCropActions,[],!0);var a={selPointColl:null};o.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:a}}),n.selPointColl=e.extend([],a.selPointColl,[],!0),this.updateAdj(t,i);var s=this.lowerContext.filter;this.lowerContext.filter=this.appliedFilter,o.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:t,previousObj:n,previousObjColl:n.objColl,previousPointColl:n.pointColl,previousSelPointColl:n.selPointColl,previousCropObj:r,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),this.lowerContext.filter=s},t.prototype.setFilter=function(t){var i=this.parent;t=t.toLowerCase(),i.notify("freehand-draw",{prop:"apply-pen-draw",onPropertyChange:!1});var o={currentFilter:this.parent.currentFilter}.currentFilter,r=e.extend({},i.cropObj,{},!0),n=this.getCurrentObj();n.objColl=e.extend([],i.objColl,[],!0),n.pointColl=e.extend([],i.pointColl,[],!0),n.afterCropActions=e.extend([],i.afterCropActions,[],!0);var a={selPointColl:null};i.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:a}}),n.selPointColl=e.extend([],a.selPointColl,[],!0),this.updateAdj(t,null);var s=this.lowerContext.filter;this.lowerContext.filter=this.appliedFilter,i.notify("draw",{prop:"setImageEdited",onPropertyChange:!1}),i.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:t,previousObj:n,previousObjColl:n.objColl,previousPointColl:n.pointColl,previousSelPointColl:n.selPointColl,previousCropObj:r,previousText:null,currentText:null,previousFilter:o,isCircleCrop:null}}),this.lowerContext.filter=s},t.prototype.setAdjustment=function(t){var e,i,o=this.lowerContext.filter.split(" ");switch(t){case"brightness":i=o[0].split("("),e=parseFloat(i[1].split(")")[0]),this.adjustmentLevel.brightness=this.setFilterValue(e);break;case"contrast":i=o[1].split("("),e=parseFloat(i[1].split(")")[0]),e/=100,this.adjustmentLevel.contrast=this.setFilterValue(e);break;case"hue":i=o[2].split("("),e=parseFloat(i[1].split(")")[0]),e/=3,this.adjustmentLevel.hue=e;break;case"saturation":i=o[3].split("("),e=parseFloat(i[1].split(")")[0]),e/=100,this.adjustmentLevel.saturation=this.setSaturationFilterValue(e);break;case"opacity":i=o[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=o[5].split("("),e=parseFloat(i[1].split(")")[0]),e*=20,this.adjustmentLevel.blur=e;break;case"exposure":i=o[0].split("("),e=parseFloat(i[1].split(")")[0]),this.adjustmentLevel.exposure=this.setFilterValue(e)}},t.prototype.setFilterValue=function(t){return Math.round(1===t?0:100*(t-1)/.5)},t.prototype.setSaturationFilterValue=function(t){return Math.round(1===t?0:100*(t-1))},t.prototype.updateFilter=function(t,e){var i=this.parent;if(-1!==["default","chrome","cold","warm","grayscale","blackandwhite","sepia","invert","sharpen"].indexOf(t)){var o=i.element.querySelector(".e-contextual-toolbar-wrapper .e-toolbar-item.e-selected");o&&o.classList.remove("e-selected");var r=document.getElementById(i.element.id+"_"+t+"Canvas");r&&r.parentElement.classList.add("e-selected"),this.parent.currentFilter=e||i.element.id+"_"+t}},t.prototype.finetuneImage=function(t,e){var i=this.parent;if(!i.disabled&&i.isImageLoaded){switch(t.toLowerCase()){case"brightness":this.setFilterAdj("brightness",e);break;case"contrast":this.setFilterAdj("contrast",e);break;case"hue":this.setFilterAdj("hue",e);break;case"saturation":this.setFilterAdj("saturation",e);break;case"opacity":this.setFilterAdj("opacity",e);break;case"blur":this.setFilterAdj("blur",e);break;case"exposure":this.setFilterAdj("exposure",e)}this.parent.canvasFilter=this.lowerContext.filter,i.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"ok"}})}},t.prototype.setCurrAdjValue=function(t,e){switch(this.parent.notify("draw",{prop:"setImageEdited",onPropertyChange:!1}),t){case"brightness":this.setFilterAdj("brightness",e);break;case"contrast":this.setFilterAdj("contrast",e);break;case"hue":this.setFilterAdj("hue",e);break;case"saturation":this.setFilterAdj("saturation",e);break;case"opacity":this.setFilterAdj("opacity",e);break;case"blur":this.setFilterAdj("blur",e);break;case"exposure":this.setFilterAdj("exposure",e)}},t.prototype.getCurrentObj=function(t){var i=this.parent,o={point:null};i.notify("crop",{prop:"getTempFlipPanPoint",value:{obj:o}});var r={previousZoomValue:null};i.notify("transform",{prop:"getPreviousZoomValue",value:{obj:r}});var n={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:"",zoomFactor:0,previousZoomValue:0,destPoints:{startX:0,startY:0,width:0,height:0},srcPoints:{startX:0,startY:0,width:0,height:0},filter:""};return n.cropZoom=i.transform.cropZoomFactor,n.defaultZoom=i.transform.defaultZoomFactor,n.zoomFactor=i.zoomSettings.zoomFactor,n.previousZoomValue=r.previousZoomValue,n.totalPannedPoint=e.extend({},i.panPoint.totalPannedPoint,{},!0),n.totalPannedClientPoint=e.extend({},i.panPoint.totalPannedClientPoint,{},!0),n.totalPannedInternalPoint=e.extend({},i.panPoint.totalPannedInternalPoint,{},!0),n.tempFlipPanPoint=e.extend({},o.point,{},!0),n.activeObj=e.extend({},i.activeObj,{},!0),n.rotateFlipColl=e.extend([],i.rotateFlipColl,[],!0),n.degree=i.transform.degree,n.currFlipState=i.transform.currFlipState,n.destPoints={startX:i.img.destLeft,startY:i.img.destTop,endX:0,endY:0,width:i.img.destWidth,height:i.img.destHeight},n.srcPoints={startX:i.img.srcLeft,startY:i.img.srcTop,endX:0,endY:0,width:i.img.srcWidth,height:i.img.srcHeight},n.filter=this.lowerContext.filter,t&&(t.currObj=n),n},t}(),h=function(){function t(t){this.fhdObj={lastWidth:0,lastVelocity:0,time:0,pointX:0,pointY:0},this.isFreehandDrawing=!1,this.freehandDownPoint={x:0,y:0},this.isFreehandPointMoved=!1,this.pointCounter=0,this.selPointColl={},this.currFHDIdx=0,this.selPoints=[],this.tempFHDStyles={strokeColor:null,fillColor:null,strokeWidth:null},this.parent=t,this.addEventListener()}return t.prototype.destroy=function(){this.parent.isDestroyed||this.removeEventListener()},t.prototype.addEventListener=function(){this.parent.on("freehand-draw",this.draw,this),this.parent.on("destroyed",this.destroy,this)},t.prototype.removeEventListener=function(){this.parent.off("freehand-draw",this.draw),this.parent.off("destroyed",this.destroy)},t.prototype.draw=function(t){switch(this.updateFhdPvtVar(),t.prop){case"hoverFhd":this.hoverFhd(t.value.strokeColor,t.value.strokeWidth);break;case"freehandDownHandler":this.freehandDownHandler(t.value.e,t.value.canvas);break;case"freehandUpHandler":this.freehandUpHandler(t.value.e,t.value.canvas,t.value.context);break;case"handle-freehand-draw":var i=parseInt(t.value.id.split("_")[1],10)-1;this.isFHDIdx(i)&&this.deleteFhd(i,!0);break;case"freehandRedraw":this.freehandRedraw(t.value.context,t.value.points);break;case"deleteFhd":i=parseInt(t.value.id.split("_")[1],10)-1;this.deleteFhd(i,!0);break;case"selectFhd":i=null;t.value.id&&(i=parseInt(t.value.id.split("_")[1],10)-1),this.selectFhd(i);break;case"applyFhd":this.applyFhd();break;case"cancelFhd":this.cancelFhd();break;case"updateFHDCurPts":this.updateFHDCurPts();break;case"rotateFhdColl":this.rotateFhdColl();break;case"flipFHDColl":this.flipFHDColl(t.value.value);break;case"panFHDColl":this.panFHDColl(t.value.xDiff,t.value.yDiff,t.value.panRegion);break;case"updateFHDColl":this.updateFHDColl();break;case"zoomFHDColl":this.zoomFHDColl(t.value.isPreventApply);break;case"apply-pen-draw":this.applyPenDraw();break;case"freeHandDraw":this.freeHandDraw(t.value.value);break;case"isFHDIdx":this.isFHDIdx(t.value.index,t.value.obj);break;case"getSqPtFD":this.getSqPtFD(t.value.idx,t.value.obj);break;case"getSelPointColl":t.value.obj.selPointColl=e.extend([],this.selPointColl);break;case"setSelPointColl":this.selPointColl=e.extend([],t.value.obj.selPointColl);break;case"setFreehandDrawHoveredIndex":this.fhdHovIdx=t.value.index;break;case"getFreehandDrawHoveredIndex":t.value.obj.index=this.fhdHovIdx;break;case"setPointCounter":this.pointCounter=t.value.value;break;case"getPenStrokeWidth":t.value.obj.penStrokeWidth=this.penStrokeWidth;break;case"setPenStrokeWidth":this.penStrokeWidth=t.value.value;break;case"getCurrentFreehandDrawIndex":t.value.obj.currentFreehandDrawIndex=this.currFHDIdx;break;case"setCurrentFreehandDrawIndex":this.currFHDIdx=t.value.value;break;case"updateCropPtsForSel":this.updateCropPtsForSel();break;case"getFreehandDrawSelectedId":t.value.obj.freehandDrawSelectedId=this.fhdSelID;break;case"resetFreehandDrawSelectedId":this.fhdSelID=null;break;case"getTempFreeHandDrawEditingStyles":t.value.obj.tempFreeHandDrawEditingStyles=this.tempFHDStyles;break;case"setFreehandSelectedIndex":this.fhdSelIdx=t.value.index;break;case"getFreehandSelectedIndex":t.value.obj.freehandSelectedIndex=this.fhdSelIdx;break;case"reset":this.reset()}},t.prototype.updateFhdPvtVar=function(){var t=this.parent;t.lowerCanvas&&(this.lowerContext=t.lowerCanvas.getContext("2d")),t.upperCanvas&&(this.upperContext=t.upperCanvas.getContext("2d"))},t.prototype.reset=function(){this.fhdObj={lastWidth:0,lastVelocity:0,time:0,pointX:0,pointY:0},this.isFreehandDrawing=this.isFreehandPointMoved=!1,this.selPoints=[],this.freehandDownPoint={x:0,y:0},this.selPointColl={},this.fhdHovIdx=null,this.pointCounter=0,this.fhdSelID=null,this.penStrokeWidth=void 0,this.currFHDIdx=0,this.fhdSelIdx=null,this.tempFHDStyles={strokeColor:null,fillColor:null,strokeWidth:null}},t.prototype.getModuleName=function(){return"freehand-draw"},t.prototype.hoverFhd=function(t,i){var o=this.parent;o.lowerCanvas=document.querySelector("#"+o.element.id+"_lowerCanvas"),this.lowerContext=o.lowerCanvas.getContext("2d"),o.upperCanvas=document.querySelector("#"+o.element.id+"_upperCanvas"),this.upperContext=o.upperCanvas.getContext("2d");var r=this.upperContext,n=-1;n=this.fhdHovIdx>-1?this.fhdHovIdx:this.fhdSelIdx,o.points=e.extend([],o.pointColl[n].points),this.pointCounter=0;var a,s,l,p,h=o.points.length,c=0,d=0;r.fillStyle=t||o.pointColl[n].strokeColor,r.strokeStyle=r.fillStyle,c=d=this.penStrokeWidth=i||o.pointColl[n].strokeWidth,1===h&&(a=s=l=p=o.points[0],this.startDraw(r,a,s,l,p,c,d));for(var v=0;v<h-3;v++)o.points[v+1]&&o.points[v+2]&&o.points[v+2]&&(a=this.calcCurveCP(o.points[v+0],o.points[v+1],o.points[v+2]).controlPoint2,s=this.calcCurveCP(o.points[v+1],o.points[v+2],o.points[v+3]).controlPoint1,l=o.points[v+1],p=o.points[v+2],this.startDraw(r,a,s,l,p,c,d));r.closePath();var u=this.getSqPtFD(n),g=r.lineWidth;r.lineWidth=2,r.strokeStyle=o.themeColl[o.theme].primaryColor,r.beginPath(),r.rect(u.startX,u.startY,u.width,u.height),r.stroke(),r.closePath(),r.lineWidth=g},t.prototype.freehandDownHandler=function(t,i){this.parent.lowerCanvas=document.querySelector("#"+this.parent.element.id+"_lowerCanvas"),this.lowerContext=this.parent.lowerCanvas.getContext("2d"),this.parent.upperCanvas=document.querySelector("#"+this.parent.element.id+"_upperCanvas"),this.upperContext=this.parent.upperCanvas.getContext("2d"),this.fhdObj.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)},t.prototype.freehandUpHandler=function(t,i,o){var r=i.getBoundingClientRect(),n=this.parent;e.EventHandler.remove(i,"mousemove touchmove",this.freehandMoveHandler),0===n.points.length&&("mouseup"===t.type?this.processPoint(t.clientX-r.left,t.clientY-r.top,!0,o):this.isFreehandPointMoved||this.processPoint(this.freehandDownPoint.x-r.left,this.freehandDownPoint.y-r.top,!0,o)),o.closePath();var a=e.extend({},n.cropObj,{},!0),s={currObj:{}};n.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:s}});var l=s.currObj;l.objColl=e.extend([],n.objColl,[],!0),l.pointColl=e.extend([],n.pointColl,[],!0),l.afterCropActions=e.extend([],n.afterCropActions,[],!0);var p={selPointColl:null};n.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:p}}),l.selPointColl=e.extend([],p.selPointColl,[],!0);var h=n.freehandCounter;n.pointColl[h]={},n.pointColl[h].points=e.extend([],n.points),n.pointColl[h].strokeColor=n.activeObj.strokeSettings.strokeColor,n.pointColl[h].strokeWidth=this.penStrokeWidth,n.pointColl[h].flipState=n.transform.currFlipState,n.pointColl[h].id="pen_"+(this.currFHDIdx+1),n.points=[],this.selPointColl[h]={},this.selPointColl[h].points=e.extend([],this.selPoints),this.selPoints=[],this.pointCounter=0,n.freehandCounter++,this.currFHDIdx++,this.isFreehandDrawing=!1,n.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"freehand-draw",previousObj:l,previousObjColl:l.objColl,previousPointColl:l.pointColl,previousSelPointColl:l.selPointColl,previousCropObj:a,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}})},t.prototype.freehandMoveHandler=function(t){this.isFreehandPointMoved=!0;var e,i,o=this.parent.upperCanvas.getBoundingClientRect();"mousemove"===t.type?(e=t.clientX-o.left,i=t.clientY-o.top):(e=t.touches[0].clientX-o.left,i=t.touches[0].clientY-o.top),this.isFreehandDrawing&&this.processPoint(e,i,!1,this.upperContext)},t.prototype.processPoint=function(t,i,o,r){var n,a,s,l,p=this.parent,h=this.point(t,i,(new Date).getTime()),c=!!(h=p.points.length>0&&p.points[p.points.length-1])&&this.distanceTo(h)<=5;if(this.selPoints.push({x:t,y:i,ratioX:(t-p.img.destLeft)/p.img.destWidth,ratioY:(i-p.img.destTop)/p.img.destHeight,time:this.fhdObj.time}),!h||!h||!c||o){if(this.fhdObj.time=(new Date).getTime(),p.points.push({x:t,y:i,ratioX:(t-p.img.destLeft)/p.img.destWidth,ratioY:(i-p.img.destTop)/p.img.destHeight,time:this.fhdObj.time}),p.points.length>3){var d=p.points[this.pointCounter],v=p.points[this.pointCounter+1],u=p.points[this.pointCounter+2],g=p.points[this.pointCounter+3];n=this.calcCurveCP(d,v,u).controlPoint2,a=this.calcCurveCP(v,u,g).controlPoint1,s=p.points[this.pointCounter+1],l=p.points[this.pointCounter+2];var b=.5,C=5;e.isNullOrUndefined(this.penStrokeWidth)||(b=C=this.penStrokeWidth),this.startDraw(r,n,a,s,l,b,C),this.pointCounter++}if(o){n=a=s=l={x:t,y:i,time:(new Date).getTime()};b=.5,C=5;e.isNullOrUndefined(this.penStrokeWidth)||(b=C=this.penStrokeWidth),this.startDraw(r,n,a,s,l,b,C)}}},t.prototype.calcCurveCP=function(t,e,i){e||(e=t),i||(i=e);var o=t.x-e.x,r=t.y-e.y,n=e.x-i.x,a=e.y-i.y,s=(t.x+e.x)/2,l=(t.y+e.y)/2,p=(e.x+i.x)/2,h=(e.y+i.y)/2,c=Math.sqrt(o*o+r*r),d=Math.sqrt(n*n+a*a),v=d/(c+d),u=p+(s-p)*v,g=h+(l-h)*v,b=e.x-u,C=e.y-g;return{controlPoint1:this.point(s+b,l+C,0),controlPoint2:this.point(p+b,h+C,0)}},t.prototype.point=function(t,e,i){return this.fhdObj.pointX=t,this.fhdObj.pointY=e,{x:this.fhdObj.pointX,y:this.fhdObj.pointY,time:i}},t.prototype.startDraw=function(t,e,i,o,r,n,a){var s;s=.7*(s=this.pointVelocity(o))+(1-.7)*this.fhdObj.lastVelocity;var l=Math.max(a/1.7,n);this.drawCurve(this.fhdObj.time,l,t,e,i,o,r,a),this.fhdObj.lastVelocity=s,this.fhdObj.time=l},t.prototype.pointVelocity=function(t){return this.fhdObj.time!==t.time?this.distanceTo(t)/(this.fhdObj.time-t.time):0},t.prototype.distanceTo=function(t){return Math.sqrt(Math.pow(this.fhdObj.pointX-t.x,2)+Math.pow(this.fhdObj.pointY-t.y,2))},t.prototype.drawCurve=function(t,e,i,o,r,n,a,s){var l,p,h,c,d,v,u,g,b,C,f=e-t,m=this.bezierLength(o,r,n,a),y=2*Math.ceil(m);for(i.beginPath(),p=0;p<y;p++)d=(c=(h=p/y)*h)*h,b=(g=(u=(v=1-h)*v)*v)*n.x,b+=3*u*h*o.x,b+=3*v*c*r.x,b+=d*a.x,C=g*n.y,C+=3*u*h*o.y,C+=3*v*c*r.y,C+=d*a.y,l=Math.min(t+d*f,s),this.drawArc(b,C,l,i);i.closePath(),i.fill()},t.prototype.bezierLength=function(t,e,i,o){var r,n,a,s,l,p,h,c,d=0;for(r=0;r<=10;r++)n=r/10,a=this.bezierPoint(n,i.x,t.x,e.x,o.x),s=this.bezierPoint(n,i.y,t.y,e.y,o.y),r>0&&(h=a-l,c=s-p,d+=Math.sqrt(h*h+c*c)),l=a,p=s;return d},t.prototype.bezierPoint=function(t,e,i,o,r){return e*(1-t)*(1-t)*(1-t)+3*i*(1-t)*(1-t)*t+3*o*(1-t)*t*t+r*t*t*t},t.prototype.drawArc=function(t,e,i,o){(t>this.parent.img.destLeft&&e>this.parent.img.destTop&&t<this.parent.img.destLeft+this.parent.img.destWidth&&e<this.parent.img.destTop+this.parent.img.destHeight||o!==this.lowerContext&&o!==this.upperContext)&&(o.moveTo(t,e),o.arc(t,e,i,0,2*Math.PI,!1))},t.prototype.freehandRedraw=function(t,i){var o=this.parent;o.lowerCanvas=document.querySelector("#"+o.element.id+"_lowerCanvas"),this.lowerContext=o.lowerCanvas.getContext("2d"),o.upperCanvas=document.querySelector("#"+o.element.id+"_upperCanvas"),this.upperContext=o.upperCanvas.getContext("2d");var r=t.filter;t.filter="none",i&&(o.pointColl[o.freehandCounter]={},o.pointColl[o.freehandCounter].points=i,o.pointColl[o.freehandCounter].strokeColor=o.activeObj.strokeSettings.strokeColor,o.pointColl[o.freehandCounter].strokeWidth=this.penStrokeWidth,o.pointColl[o.freehandCounter].flipState=o.transform.currFlipState,o.freehandCounter++);for(var n=0;n<o.freehandCounter;n++){o.points=e.extend([],o.pointColl[n].points),this.pointCounter=0;var a=o.points.length,s=void 0,l=void 0,p=void 0,h=void 0,c=void 0,d=void 0;a>0&&(t.fillStyle=o.pointColl[n].strokeColor,c=d=this.penStrokeWidth=o.pointColl[n].strokeWidth),1===a&&(s=l=p=h=o.points[0],this.startDraw(t,s,l,p,h,c,d));for(var v=0;v<a-3;v++)o.points[v+1]&&o.points[v+2]&&o.points[v+2]&&(s=this.calcCurveCP(o.points[v+0],o.points[v+1],o.points[v+2]).controlPoint2,l=this.calcCurveCP(o.points[v+1],o.points[v+2],o.points[v+3]).controlPoint1,p=o.points[v+1],h=o.points[v+2],this.startDraw(t,s,l,p,h,c,d));t.closePath()}t.filter=r},t.prototype.getSqPtFD=function(t,i){var o={startX:0,startY:0,endX:0,endY:0,width:0,height:0},r=e.extend([],this.selPointColl[t].points,[]);this.parent.points=e.extend([],this.parent.pointColl[t].points),this.pointCounter=0;for(var n=r.length,a=0;a<n;a++)0===o.startX&&0===o.startY&&0===o.endX&&0===o.endY?(o.startX=r[a].x,o.startY=r[a].y,o.endX=r[a].x,o.endY=r[a].y):(o.startX=Math.min(o.startX,r[a].x),o.startY=Math.min(o.startY,r[a].y),o.endX=Math.max(o.endX,r[a].x),o.endY=Math.max(o.endY,r[a].y));return o.startX-=this.penStrokeWidth,o.startY-=this.penStrokeWidth,o.endX+=this.penStrokeWidth,o.endY+=this.penStrokeWidth,o.width=o.endX-o.startX,o.height=o.endY-o.startY,i&&(i.activePoint=o),o},t.prototype.applyPenDraw=function(){var t=this.parent;"freehanddraw"===t.currObjType.shape&&(t.notify("shape",{prop:"apply",onPropertyChange:!1,value:{shape:null,obj:null,canvas:null}}),t.upperCanvas.style.cursor=t.cursor="default",t.currObjType.shape=""),t.notify("shape",{prop:"clearActObj"})},t.prototype.applyFhd=function(){var t=this.parent,i=t.pointColl[this.fhdSelIdx];"#42a5f5"===i.strokeColor&&(i.strokeColor=this.tempFHDStyles.strokeColor),e.isBlazor()||t.notify("toolbar",{prop:"setSelectedFreehandColor",value:{color:"#42a5f5"}}),this.upperContext.clearRect(0,0,t.upperCanvas.width,t.upperCanvas.height),this.lowerContext.clearRect(0,0,t.lowerCanvas.width,t.lowerCanvas.height),t.notify("draw",{prop:"render-image",value:{isMouseWheel:null}}),e.isBlazor()||t.notify("toolbar",{prop:"refresh-main-toolbar",onPropertyChange:!1}),i&&(i.isSelected=!1),t.notify("selection",{prop:"resetFreehandDrawVariables"}),this.fhdHovIdx=this.fhdSelIdx=null},t.prototype.cancelFhd=function(){var t=this.parent;e.isBlazor()||t.notify("toolbar",{prop:"setSelectedFreehandColor",value:{color:"#42a5f5"}}),this.upperContext.clearRect(0,0,t.upperCanvas.width,t.upperCanvas.height),this.pointCounter=0,t.pointColl[this.fhdSelIdx]&&(t.pointColl[this.fhdSelIdx].strokeColor=this.tempFHDStyles.strokeColor,t.pointColl[this.fhdSelIdx].strokeWidth=this.tempFHDStyles.strokeWidth,t.pointColl[this.fhdSelIdx].isSelected=!1),this.fhdHovIdx=this.fhdSelIdx=this.fhdSelID=null,t.notify("selection",{prop:"resetFreehandDrawVariables"}),t.activeObj.strokeSettings.strokeColor=this.tempFHDStyles.strokeColor,t.activeObj.strokeSettings.strokeWidth=this.penStrokeWidth=this.tempFHDStyles.strokeWidth,this.tempFHDStyles={strokeColor:null,strokeWidth:null,fillColor:null},e.isBlazor()||t.notify("toolbar",{prop:"refresh-main-toolbar",onPropertyChange:!1})},t.prototype.selectFhd=function(t){var i=this.parent;if(i.notify("selection",{prop:"setFreehandDrawEditing",onPropertyChange:!1,value:{bool:!0}}),t||0===t){if(!this.isFHDIdx(t))return;this.fhdSelIdx=this.fhdHovIdx=t,this.hoverFhd(),i.upperCanvas.style.cursor=i.cursor="pointer"}this.fhdSelIdx=this.fhdHovIdx,i.pointColl[this.fhdSelIdx].isSelected=!0,this.fhdSelID=i.pointColl[this.fhdSelIdx].id,"#42a5f5"!==i.pointColl[this.fhdHovIdx].strokeColor&&(i.activeObj.strokeSettings.strokeColor=this.tempFHDStyles.strokeColor=i.pointColl[this.fhdHovIdx].strokeColor),i.activeObj.strokeSettings.strokeWidth=this.tempFHDStyles.strokeWidth=i.pointColl[this.fhdHovIdx].strokeWidth;var o={bool:!1};i.notify("selection",{prop:"getFreehandDrawEditing",onPropertyChange:!1,value:{obj:o}}),o.bool?e.isBlazor()||i.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"pen",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}}):i.okBtn()},t.prototype.deleteFhd=function(t,i){var o=this.parent;if(this.isFHDIdx(t)){this.upperContext.clearRect(0,0,o.upperCanvas.width,o.upperCanvas.height);var r=e.extend({},o.pointColl,{},!0),n=e.extend({},this.selPointColl,{},!0);o.pointColl={},this.selPointColl={};var a=0;if(e.isNullOrUndefined(i))for(var s=0;s<o.freehandCounter;s++)s!==t&&(o.pointColl[a]=r[s],this.selPointColl[a]=n[s],a++);else for(s=0;s<o.freehandCounter;s++)parseInt(r[s].id.split("_")[1],10)-1!==t&&(o.pointColl[a]=r[s],this.selPointColl[a]=n[s],a++);o.freehandCounter-=1,this.fhdHovIdx=this.fhdSelIdx=null,o.notify("selection",{prop:"resetFreehandDrawVariables"}),o.notify("draw",{prop:"render-image",value:{isMouseWheel:!0}}),e.isBlazor()||o.notify("toolbar",{prop:"refresh-main-toolbar",onPropertyChange:!1})}},t.prototype.zoomX=function(t){return t*this.parent.img.destWidth+this.parent.img.destLeft},t.prototype.zoomY=function(t){return t*this.parent.img.destHeight+this.parent.img.destTop},t.prototype.zoomFHDColl=function(t){for(var i=this.parent,o=0;o<i.freehandCounter;o++){i.points=e.extend([],i.pointColl[o].points,[]),this.pointCounter=0;for(var r=i.points.length,n=0;n<r;n++)i.points[n].x=this.zoomX(i.points[n].ratioX),i.points[n].y=this.zoomY(i.points[n].ratioY)}this.updateFHDCurPts(),e.isNullOrUndefined(t)&&this.freehandRedraw(this.lowerContext,null)},t.prototype.updateFHDCurPts=function(){for(var t=this.parent,i=0;i<t.freehandCounter;i++)if(!e.isNullOrUndefined(this.selPointColl[i])){this.selPoints=e.extend([],this.selPointColl[i].points,[]),this.pointCounter=0;for(var o=this.selPoints.length,r=0;r<o;r++)this.selPoints[r].x=this.zoomX(this.selPoints[r].ratioX),this.selPoints[r].y=this.zoomY(this.selPoints[r].ratioY)}},t.prototype.rotateFhdColl=function(){for(var t=this.parent,i=0;i<t.freehandCounter;i++){t.points=e.extend([],t.pointColl[i].points,[]),this.pointCounter=0;for(var o=t.points.length,r=0;r<o;r++)t.points[r].y=t.img.destTop+t.img.destHeight*t.points[r].ratioX,t.points[r].x=t.img.destLeft+t.img.destWidth-t.img.destWidth*t.points[r].ratioY,t.points[r].ratioX=(t.points[r].x-t.img.destLeft)/t.img.destWidth,t.points[r].ratioY=(t.points[r].y-t.img.destTop)/t.img.destHeight}for(i=0;i<t.freehandCounter;i++)if(!e.isNullOrUndefined(this.selPointColl[i])){this.selPoints=e.extend([],this.selPointColl[i].points,[]),this.pointCounter=0;for(o=this.selPoints.length,r=0;r<o;r++)this.selPoints[r].y=t.img.destTop+t.img.destHeight*this.selPoints[r].ratioX,this.selPoints[r].x=t.img.destLeft+t.img.destWidth-t.img.destWidth*this.selPoints[r].ratioY,this.selPoints[r].ratioX=(this.selPoints[r].x-t.img.destLeft)/t.img.destWidth,this.selPoints[r].ratioY=(this.selPoints[r].y-t.img.destTop)/t.img.destHeight}this.updateFHDCurPts()},t.prototype.flipFHDColl=function(t){var e=t.toLowerCase();if("horizontal"===e)this.pointsHorizontalFlip();else if("vertical"===e)this.pointsVerticalFlip();else{this.pointsHorizontalFlip();for(var i=0;i<this.parent.freehandCounter;i++)this.parent.pointColl[i].shapeFlip="";this.pointsVerticalFlip()}},t.prototype.pointsHorizontalFlip=function(){for(var t=this.parent,i=0;i<t.freehandCounter;i++)if(t.pointColl[i].shapeFlip!==t.transform.currFlipState){t.points=e.extend([],t.pointColl[i].points,[]),this.pointCounter=0;for(var o=t.points.length,r=0;r<o;r++)t.points[r].x<=t.img.destLeft+t.img.destWidth/2?t.points[r].x=t.img.destLeft+t.img.destWidth-(t.points[r].x-t.img.destLeft):t.points[r].x>=t.img.destLeft+t.img.destWidth/2&&(t.points[r].x=t.img.destLeft+(t.img.destLeft+t.img.destWidth-t.points[r].x)),t.points[r].ratioX=(t.points[r].x-t.img.destLeft)/t.img.destWidth,t.points[r].ratioY=(t.points[r].y-t.img.destTop)/t.img.destHeight;t.pointColl[i].shapeFlip=t.transform.currFlipState}for(i=0;i<t.freehandCounter;i++)if(!e.isNullOrUndefined(this.selPointColl[i])&&this.selPointColl[i].shapeFlip!==t.transform.currFlipState){this.selPoints=e.extend([],this.selPointColl[i].points,[]),this.pointCounter=0;for(o=this.selPoints.length,r=0;r<o;r++)this.selPoints[r].x<=t.img.destLeft+t.img.destWidth/2?this.selPoints[r].x=t.img.destLeft+t.img.destWidth-(this.selPoints[r].x-t.img.destLeft):this.selPoints[r].x>=t.img.destLeft+t.img.destWidth/2&&(this.selPoints[r].x=t.img.destLeft+(t.img.destLeft+t.img.destWidth-this.selPoints[r].x)),this.selPoints[r].ratioX=(this.selPoints[r].x-t.img.destLeft)/t.img.destWidth,this.selPoints[r].ratioY=(this.selPoints[r].y-t.img.destTop)/t.img.destHeight}this.updateFHDCurPts()},t.prototype.pointsVerticalFlip=function(){for(var t=this.parent,i=0;i<t.freehandCounter;i++)if(t.pointColl[i].shapeFlip!==t.transform.currFlipState){t.points=e.extend([],t.pointColl[i].points,[]),this.pointCounter=0;for(var o=t.points.length,r=0;r<o;r++)t.points[r].y<=t.img.destTop+t.img.destHeight/2?t.points[r].y=t.img.destTop+t.img.destHeight-(t.points[r].y-t.img.destTop):t.points[r].y>=t.img.destTop+t.img.destHeight/2&&(t.points[r].y=t.img.destTop+(t.img.destTop+t.img.destHeight-t.points[r].y)),t.points[r].ratioX=(t.points[r].x-t.img.destLeft)/t.img.destWidth,t.points[r].ratioY=(t.points[r].y-t.img.destTop)/t.img.destHeight;t.pointColl[i].shapeFlip=t.transform.currFlipState}for(i=0;i<t.freehandCounter;i++)if(!e.isNullOrUndefined(this.selPointColl[i])&&this.selPointColl[i].shapeFlip!==t.transform.currFlipState){this.selPoints=e.extend([],this.selPointColl[i].points,[]),this.pointCounter=0;for(o=this.selPoints.length,r=0;r<o;r++)this.selPoints[r].y<=t.img.destTop+t.img.destHeight/2?this.selPoints[r].y=t.img.destTop+t.img.destHeight-(this.selPoints[r].y-t.img.destTop):this.selPoints[r].y>=t.img.destTop+t.img.destHeight/2&&(this.selPoints[r].y=t.img.destTop+(t.img.destTop+t.img.destHeight-this.selPoints[r].y)),this.selPoints[r].ratioX=(this.selPoints[r].x-t.img.destLeft)/t.img.destWidth,this.selPoints[r].ratioY=(this.selPoints[r].y-t.img.destTop)/t.img.destHeight}this.updateFHDCurPts()},t.prototype.updateFHDColl=function(){for(var t=this.parent,i=0;i<t.objColl.length;i++){if(t.objColl[i].imageRatio={startX:(t.objColl[i].activePoint.startX-t.img.destLeft)/t.img.destWidth,startY:(t.objColl[i].activePoint.startY-t.img.destTop)/t.img.destHeight,endX:(t.objColl[i].activePoint.endX-t.img.destLeft)/t.img.destWidth,endY:(t.objColl[i].activePoint.endY-t.img.destTop)/t.img.destHeight,width:t.img.destWidth/t.objColl[i].activePoint.width,height:t.img.destHeight/t.objColl[i].activePoint.height},"path"===t.objColl[i].shape)for(var o=0;o<t.objColl[i].pointColl.length;o++)t.objColl[i].pointColl[o].ratioX=(t.objColl[i].pointColl[o].x-t.img.destLeft)/t.img.destWidth,t.objColl[i].pointColl[o].ratioY=(t.objColl[i].pointColl[o].y-t.img.destTop)/t.img.destHeight;t.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1})}for(var r=0;r<t.freehandCounter;r++){t.points=e.extend([],t.pointColl[r].points,[]),this.pointCounter=0;for(var n=t.points.length,a=0;a<n;a++)t.points[a].ratioX=(t.points[a].x-t.img.destLeft)/t.img.destWidth,t.points[a].ratioY=(t.points[a].y-t.img.destTop)/t.img.destHeight}for(r=0;r<t.freehandCounter;r++)if(!e.isNullOrUndefined(this.selPointColl[r])){this.selPoints=e.extend([],this.selPointColl[r].points,[]),this.pointCounter=0;for(n=this.selPoints.length,a=0;a<n;a++)this.selPoints[a].ratioX=(this.selPoints[a].x-t.img.destLeft)/t.img.destWidth,this.selPoints[a].ratioY=(this.selPoints[a].y-t.img.destTop)/t.img.destHeight}},t.prototype.panFHDColl=function(t,i,o){for(var r=this.parent,n=0;n<r.freehandCounter;n++){r.points=e.extend([],r.pointColl[n].points,[]),this.pointCounter=0;for(var a=r.points.length,s=0;s<a;s++)""===o||"vertical"===o?r.points[s].x+=t:r.points[s].x-=t,""===o||"horizontal"===o?r.points[s].y+=i:r.points[s].y-=i}for(n=0;n<r.freehandCounter;n++)if(!e.isNullOrUndefined(this.selPointColl[n])){this.selPoints=e.extend([],this.selPointColl[n].points,[]),this.pointCounter=0;for(a=this.selPoints.length,s=0;s<a;s++)""===o||"vertical"===o?this.selPoints[s].x+=t:this.selPoints[s].x-=t,""===o||"horizontal"===o?this.selPoints[s].y+=i:this.selPoints[s].y-=i}this.freehandRedraw(this.lowerContext,null)},t.prototype.freeHandDraw=function(t){var i=this.parent;if(t){if(i.points=[],i.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),i.togglePen=!0,i.upperCanvas.style.cursor=i.cursor="crosshair",i.upperCanvas.style.display="block",e.isNullOrUndefined(i.activeObj.strokeSettings)){var o={strokeSettings:{}};i.notify("shape",{prop:"getStrokeSettings",onPropertyChange:!1,value:{obj:o}}),i.activeObj.strokeSettings=o.strokeSettings}e.isNullOrUndefined(i.activeObj.strokeSettings.strokeWidth)&&(i.activeObj.strokeSettings.strokeWidth=4),e.isBlazor()?i.updateToolbar(i.element,"pen"):i.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"pen",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}})}else i.upperCanvas.style.cursor=i.cursor="default",i.notify("shape",{prop:"apply",onPropertyChange:!1,value:{shape:null,obj:null,canvas:null}}),e.isBlazor()?i.updateToolbar(i.element,"imageLoaded"):(i.notify("toolbar",{prop:"refresh-main-toolbar",onPropertyChange:!1}),i.notify("toolbar",{prop:"setCurrentToolbar",value:{type:"main"}})),i.notify("selection",{prop:"setFreehandDrawCustomized",value:{isFreehandDrawCustomized:!1}})},t.prototype.isFHDIdx=function(t,i){for(var o=!1,r=0;r<this.parent.freehandCounter;r++)if(!e.isNullOrUndefined(this.parent.pointColl[r].id)&&parseInt(this.parent.pointColl[r].id.split("_")[1],10)-1===t){o=!0;break}return e.isNullOrUndefined(i)||(i.isIndex=o),o},t.prototype.updateCropPtsForSel=function(){for(var t=this.parent,i=0;i<t.freehandCounter;i++){var o={selPointColl:e.extend([],this.selPointColl)};if(!e.isNullOrUndefined(o.selPointColl[i])){this.selPoints=e.extend([],o.selPointColl[i].points,[]),this.pointCounter=0;for(var r=this.selPoints.length,n=0;n<r;n++)this.selPoints[n].ratioX=(this.selPoints[n].x-t.activeObj.activePoint.startX)/t.activeObj.activePoint.width,this.selPoints[n].ratioY=(this.selPoints[n].y-t.activeObj.activePoint.startY)/t.activeObj.activePoint.height}}},t}(),c=function(){function o(t){this.diffPoint={x:0,y:0},this.oldPoint={},this.isTouch=!1,this.isObjSelected=!1,this.isFhdPoint=!1,this.dragPoint={startX:0,startY:0,endX:0,endY:0},this.isShapeInserted=!1,this.tempActiveObj={activePoint:{startX:0,startY:0,endX:0,endY:0,width:0,height:0},flipObjColl:[],triangle:[],triangleRatio:[]},this.isFirstMove=!1,this.startTouches=[],this.tempTouches=[],this.currMousePoint={x:0,y:0},this.cursorTargetId="",this.isPreventDragging=!1,this.dragElement="",this.textRow=1,this.mouseDownPoint={x:0,y:0},this.previousPoint={x:0,y:0},this.zoomType="Toolbar",this.isInitialTextEdited=!1,this.dragCanvas=!1,this.isFhdCustomized=!1,this.touchEndPoint={},this.isFhdEditing=!1,this.currentDrawingShape="",this.initialPrevObj={},this.touchTime=0,this.resizedElement="",this.parent=t,this.addEventListener()}return o.prototype.destroy=function(){this.parent.isDestroyed||this.removeEventListener()},o.prototype.addEventListener=function(){this.parent.on("selection",this.selection,this),this.parent.on("destroyed",this.destroy,this)},o.prototype.removeEventListener=function(){this.parent.off("selection",this.selection),this.parent.off("destroyed",this.destroy)},o.prototype.selection=function(t){var e=this;switch(this.updatePrivateVariables(),t.prop){case"mouse-up":this.selMouseUpEvent();break;case"setCursor":this.setCursor(t.value.x,t.value.y);break;case"updateActivePoint":this.updateActivePoint(t.value.x,t.value.y,t.value.isCropSelection);break;case"updateCursorStyles":this.updateCursorStyles(t.value.x,t.value.y,t.value.type);break;case"setTextSelection":this.setTextSelection(t.value.width,t.value.height);break;case"setActivePoint":this.setActivePoint(t.value.startX,t.value.startY);break;case"clearSelection":this.clearSelection();break;case"calcShapeRatio":this.calcShapeRatio(t.value.x,t.value.y,t.value.imgWidth,t.value.imgHeight);break;case"applyCurrShape":this.applyCurrShape(t.value.isShapeClick);break;case"tab":this.performTabAction();break;case"setDragDirection":this.setDragDirection(t.value.width,t.value.height);break;case"clearUpperCanvas":this.isTouch&&setTimeout(function(){e.parent.upperCanvas.getContext("2d").clearRect(0,0,e.parent.upperCanvas.width,e.parent.upperCanvas.height)},550);break;case"resetFreehandDrawVariables":this.isFhdEditing=this.isFhdPoint=!1;break;case"isShapeInserted":this.isShapeInserted=t.value.bool;break;case"redrawShape":this.redrawShape(t.value.obj);break;case"setTextBoxStylesToActObj":this.setTextBoxStylesToActObj();break;case"mouseDownEventHandler":this.mouseDownEventHandler(t.value.e);break;case"mouseMoveEventHandler":this.mouseMoveEventHandler(t.value.e);break;case"mouseUpEventHandler":this.mouseUpEventHandler(t.value.e);break;case"canvasMouseDownHandler":this.canvasMouseDownHandler(t.value.e);break;case"canvasMouseMoveHandler":this.canvasMouseMoveHandler(t.value.e);break;case"canvasMouseUpHandler":this.canvasMouseUpHandler(t.value.e);break;case"touchStartHandler":this.touchStartHandler(t.value.e);break;case"keyDownEventHandler":this.keyDownEventHandler(t.value.e);break;case"handleScroll":this.handleScroll(t.value.e);break;case"adjustToScreen":this.adjustToScreen();break;case"textKeyDown":setTimeout(this.textKeyDown.bind(this),1,t.value.e);break;case"deleteItem":this.deleteItem();break;case"updatePrevShapeSettings":this.updatePrevShapeSettings(t.value.obj);break;case"getZoomType":t.value.obj.zoomType=this.zoomType;break;case"setZoomType":this.zoomType=t.value.zoomType;break;case"setInitialTextEdit":this.isInitialTextEdited=t.value.bool;break;case"setDragCanvas":this.dragCanvas=t.value.bool;break;case"setFreehandDrawCustomized":this.isFhdCustomized=t.value.isFreehandDrawCustomized;break;case"setTouchEndPoint":this.touchEndPoint.x=t.value.x,this.touchEndPoint.y=t.value.y;break;case"getPanDown":t.value.obj.panDown=this.panDown;break;case"setPanDown":this.panDown=t.value.panDown;break;case"getFreehandDrawEditing":t.value.obj.bool=this.isFhdEditing;break;case"setFreehandDrawEditing":this.isFhdEditing=t.value.bool;break;case"getTempActObj":t.value.obj.tempObj=this.tempActiveObj;break;case"setTempActObj":this.tempActiveObj=t.value.obj;break;case"isInside":this.isInside(t.value.x,t.value.y,t.value.z1,t.value.z2,t.value.z3,t.value.z4);break;case"setDragElement":this.dragElement=t.value.value;break;case"setObjSelected":this.isObjSelected=t.value.bool;break;case"adjustActObjForLineArrow":this.adjustActObjForLineArrow(t.value.obj);break;case"findTarget":this.findTarget(t.value.x,t.value.y,t.value.type);break;case"getCurrentFlipState":this.getCurrentFlipState();break;case"setDragWidth":this.setDragWidth(t.value.width);break;case"setDragHeight":this.setDragHeight(t.value.setDragHeight);break;case"annotate":this.currentDrawingShape=t.value.shape,"text"===t.value.shape?(this.parent.activeObj.textSettings.fontSize=100,this.parent.activeObj.keyHistory="Enter Text",this.parent.notify("shape",{prop:"initializeTextShape",onPropertyChange:!1,value:{text:null,fontFamily:null,fontSize:null,bold:null,italic:null,strokeColor:null}})):"path"===t.value.shape&&(this.parent.activeObj.pointColl=[]);break;case"getCurrentDrawingShape":t.value.obj.shape=this.currentDrawingShape;break;case"setCurrentDrawingShape":this.currentDrawingShape=t.value.value;break;case"getTransRotationPoint":this.getTransRotationPoint(t.value.obj,t.value.object);break;case"reset":this.reset()}},o.prototype.getModuleName=function(){return"selection"},o.prototype.updatePrivateVariables=function(){var t=this.parent;e.isNullOrUndefined(t.lowerCanvas)||(this.lowerContext=t.lowerCanvas.getContext("2d")),e.isNullOrUndefined(t.upperCanvas)||(this.upperContext=t.upperCanvas.getContext("2d"))},o.prototype.reset=function(){this.diffPoint={x:0,y:0},this.oldPoint={},this.isTouch=this.isObjSelected=this.isFhdPoint=this.isShapeInserted=!1,this.dragPoint={startX:0,startY:0,endX:0,endY:0},this.tempActiveObj={activePoint:{startX:0,startY:0,endX:0,endY:0,width:0,height:0},flipObjColl:[],triangle:[],triangleRatio:[]},this.isFirstMove=!1,this.cursorTargetId=this.dragElement="",this.startTouches=[],this.tempTouches=[],this.currMousePoint={x:0,y:0},this.isPreventDragging=!1,this.timer=void 0,this.tempObjColl=void 0,this.textRow=1,this.mouseDownPoint={x:0,y:0},this.previousPoint={x:0,y:0},this.zoomType="Toolbar",this.isInitialTextEdited=!1,this.dragCanvas=!1,this.isFhdCustomized=!1,this.touchEndPoint={},this.panDown=null,this.isFhdEditing=!1,this.pathAdjustedIndex=null,this.touchTime=0,this.currentDrawingShape="",this.initialPrevObj={},this.resizedElement=""},o.prototype.performTabAction=function(){if("block"===this.parent.textArea.style.display){var t=this.applyCurrShape(!1);this.parent.notify("shape",{prop:"redrawActObj",onPropertyChange:!1,value:{x:null,y:null,isMouseDown:null}}),t&&this.parent.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"ok"}})}},o.prototype.selMouseUpEvent=function(){this.oldPoint.x=void 0,this.oldPoint.y=void 0},o.prototype.getMouseCursor=function(t,i,o,r,n){var a=this.getTransRotationPoint(t),s=n?0:2*t.topLeftCircle.radius;return i>=t.topLeftCircle.startX-s&&i<=t.topLeftCircle.startX+s&&o>=t.topLeftCircle.startY-s&&o<=t.topLeftCircle.startY+s?"nw-resize":i>=t.topLeftCircle.startX-s&&i<=t.topRightCircle.startX-s&&o>=t.topCenterCircle.startY-s&&o<=t.topCenterCircle.startY+s?"n-resize":i>=t.topRightCircle.startX-s&&i<=t.topRightCircle.startX+s&&o>=t.topRightCircle.startY-s&&o<=t.topRightCircle.startY+s?"ne-resize":i>=t.centerLeftCircle.startX-s&&i<=t.centerLeftCircle.startX+s&&o>=t.topLeftCircle.startY-s&&o<=t.bottomLeftCircle.startY-s?"w-resize":i>=t.centerRightCircle.startX-s&&i<=t.centerRightCircle.startX+s&&o>=t.topRightCircle.startY-s&&o<=t.bottomRightCircle.startY-s?"e-resize":i>=t.bottomLeftCircle.startX-s&&i<=t.bottomLeftCircle.startX+s&&o>=t.bottomLeftCircle.startY-s&&o<=t.bottomLeftCircle.startY+s?"sw-resize":i>=t.bottomLeftCircle.startX-s&&i<=t.bottomRightCircle.startX-s&&o>=t.bottomCenterCircle.startY-s&&o<=t.bottomCenterCircle.startY+s?"s-resize":i>=t.bottomRightCircle.startX-s&&i<=t.bottomRightCircle.startX+s&&o>=t.bottomRightCircle.startY-s&&o<=t.bottomRightCircle.startY+s?"se-resize":i>=t.activePoint.startX&&i<=t.activePoint.endX&&o>=t.activePoint.startY&&o<=t.activePoint.endY?r?"grab":"move":!e.isNullOrUndefined(a)&&!n&&i>=a.x-(t.bottomCenterCircle.radius+2)&&i<=a.x+(t.bottomCenterCircle.radius+2)&&o>=a.y-(t.bottomCenterCircle.radius+2)&&o<=a.y+(t.bottomCenterCircle.radius+2)?"grabbing":"default"},o.prototype.setCursor=function(t,i){var o,r=this.parent,n=document.querySelector("#"+r.element.id+"_lowerCanvas"),a=document.querySelector("#"+r.element.id+"_upperCanvas"),s=!1;if(""===this.currentDrawingShape)if(r.currObjType.isDragging)""===this.dragElement?a.style.cursor=r.cursor="move":a.style.cursor=r.cursor=this.dragElement;else{if(void 0!==r.activeObj.horTopLine){void 0!==r.activeObj.shape&&(o=r.activeObj.shape.split("-")),void 0===o&&r.currObjType.isCustomCrop?s=!0:void 0!==o&&"crop"===o[0]&&(s=!0),!s&&r.togglePan&&(n.style.cursor=a.style.cursor=r.cursor="grab");var l=a.style.cursor,p=e.extend({},r.activeObj,{},!0);this.cursorTargetId=p.currIndex;var h=void 0;(h=0===p.shapeDegree?r.transform.degree:r.transform.degree-p.shapeDegree)<0&&(h=360+h),"line"===p.shape||"arrow"===p.shape?this.setCursorForLineArrow(p,t,i,a):"path"===p.shape?this.setCursorForPath(p,t,i,a):e.isNullOrUndefined(p.rotatedAngle)||0===p.rotatedAngle?(a.style.cursor=r.cursor=this.getMouseCursor(p,t,i,s,!1),"text"!==p.shape||"n-resize"!==r.cursor&&"s-resize"!==r.cursor&&"e-resize"!==r.cursor&&"w-resize"!==r.cursor||(a.style.cursor=r.cursor="move")):this.setCursorForRotatedObject(p,t,i,a),"default"===l&&"default"===r.cursor&&s&&(a.style.cursor=r.cursor="grab"),"grab"===l&&"default"===r.cursor&&(a.style.cursor=r.cursor="grab")}else r.togglePan&&!r.togglePen?n.style.cursor=a.style.cursor=r.cursor="grab":r.currObjType.isCustomCrop||r.togglePen?a.style.cursor=r.cursor="crosshair":a.style.cursor=r.cursor="default";if("default"===r.cursor||"grab"===r.cursor){l=a.style.cursor;r.objColl.length>0&&("grab"!==r.cursor||!s)&&this.setCursorFromObj(t,i,r.objColl,a,s),"grab"===l&&"default"===r.cursor&&(a.style.cursor=r.cursor="grab")}"default"!==r.cursor&&"grab"!==r.cursor||e.isNullOrUndefined(r.pointColl[0])||"grab"===r.cursor&&s||r.currObjType.isDragging||r.currObjType.isResize||this.setCursorForFreehandDrawing(t,i,a)}else a.style.cursor=r.cursor="crosshair"},o.prototype.setCursorForPath=function(t,i,o,r){this.setCursorForLineArrow(t,i,o,r);var n=this.parent;if("default"===n.cursor)for(var a=e.extend({},t,null,!0),s=!1,l=1;l<t.pointColl.length&&!s;l++){a.activePoint.startX=t.pointColl[l-1].x,a.activePoint.startY=t.pointColl[l-1].y,a.activePoint.endX=t.pointColl[l].x,a.activePoint.endY=t.pointColl[l].y,n.notify("shape",{prop:"setPointCollForLineArrow",onPropertyChange:!1,value:{obj:a}});for(var p=0;p<a.pointColl.length;p++){var h=a.pointColl[p];if(!e.isNullOrUndefined(h.x-2*t.topLeftCircle.radius)&&!e.isNullOrUndefined(h.x+2*t.topLeftCircle.radius)&&!e.isNullOrUndefined(h.y-2*t.topLeftCircle.radius)&&!e.isNullOrUndefined(h.y+2*t.topLeftCircle.radius)&&i>=h.x-2*t.topLeftCircle.radius&&i<=h.x+2*t.topLeftCircle.radius&&o>=h.y-2*t.topLeftCircle.radius&&o<=h.y+2*t.topLeftCircle.radius){r.style.cursor=n.cursor="move",s=!0;break}r.style.cursor=n.cursor="default"}}return n.cursor},o.prototype.setCursorForLineArrow=function(t,e,i,o){for(var r,n=0;n<t.pointColl.length;n++){var a=t.pointColl[n];if(e>=a.x-2*t.topLeftCircle.radius&&e<=a.x+2*t.topLeftCircle.radius&&i>=a.y-2*t.topLeftCircle.radius&&i<=a.y+2*t.topLeftCircle.radius){o.style.cursor=this.parent.cursor="move",r=n;break}o.style.cursor=this.parent.cursor="default"}return r},o.prototype.setCursorForRotatedObject=function(t,i,o,r){this.resizedElement="";var n=this.parent;if(i>=t.horTopLinePointColl[0].x-(t.bottomCenterCircle.radius+2)&&i<=t.horTopLinePointColl[0].x+(t.bottomCenterCircle.radius+2)&&o>=t.horTopLinePointColl[0].y-(t.bottomCenterCircle.radius+2)&&o<=t.horTopLinePointColl[0].y+(t.bottomCenterCircle.radius+2))r.style.cursor=n.cursor="nw-resize";else if(i>=t.horTopLinePointColl[Math.round(t.horTopLinePointColl.length/2)].x-5&&i<=t.horTopLinePointColl[Math.round(t.horTopLinePointColl.length/2)].x+5&&o>=t.horTopLinePointColl[Math.round(t.horTopLinePointColl.length/2)].y-5&&o<=t.horTopLinePointColl[Math.round(t.horTopLinePointColl.length/2)].y+5)r.style.cursor=n.cursor=this.resizedElement="n-resize";else if(i>=t.horTopLinePointColl[Math.round(t.horTopLinePointColl.length-1)].x-(t.bottomCenterCircle.radius+2)&&i<=t.horTopLinePointColl[Math.round(t.horTopLinePointColl.length-1)].x+(t.bottomCenterCircle.radius+2)&&o>=t.horTopLinePointColl[Math.round(t.horTopLinePointColl.length-1)].y-(t.bottomCenterCircle.radius+2)&&o<=t.horTopLinePointColl[Math.round(t.horTopLinePointColl.length-1)].y+(t.bottomCenterCircle.radius+2))r.style.cursor=n.cursor="ne-resize";else if(i>=t.verLeftLinePointColl[Math.round(t.verLeftLinePointColl.length/2)].x-5&&i<=t.verLeftLinePointColl[Math.round(t.verLeftLinePointColl.length/2)].x+5&&o>=t.verLeftLinePointColl[Math.round(t.verLeftLinePointColl.length/2)].y-5&&o<=t.verLeftLinePointColl[Math.round(t.verLeftLinePointColl.length/2)].y+5)r.style.cursor=n.cursor=this.resizedElement="w-resize";else if(i>=t.verRightLinePointColl[Math.round(t.verRightLinePointColl.length/2)].x-5&&i<=t.verRightLinePointColl[Math.round(t.verRightLinePointColl.length/2)].x+5&&o>=t.verRightLinePointColl[Math.round(t.verRightLinePointColl.length/2)].y-5&&o<=t.verRightLinePointColl[Math.round(t.verRightLinePointColl.length/2)].y+5)r.style.cursor=n.cursor=this.resizedElement="e-resize";else if(i>=t.horBottomLinePointColl[0].x-(t.bottomCenterCircle.radius+2)&&i<=t.horBottomLinePointColl[0].x+(t.bottomCenterCircle.radius+2)&&o>=t.horBottomLinePointColl[0].y-(t.bottomCenterCircle.radius+2)&&o<=t.horBottomLinePointColl[0].y+(t.bottomCenterCircle.radius+2))r.style.cursor=n.cursor="sw-resize";else if(i>=t.horBottomLinePointColl[Math.round(t.horBottomLinePointColl.length/2)].x-5&&i<=t.horBottomLinePointColl[Math.round(t.horBottomLinePointColl.length/2)].x+5&&o>=t.horBottomLinePointColl[Math.round(t.horBottomLinePointColl.length/2)].y-5&&o<=t.horBottomLinePointColl[Math.round(t.horBottomLinePointColl.length/2)].y+5)r.style.cursor=n.cursor=this.resizedElement="s-resize";else if(i>=t.horBottomLinePointColl[Math.round(t.horBottomLinePointColl.length-1)].x-(t.bottomCenterCircle.radius+2)&&i<=t.horBottomLinePointColl[Math.round(t.horBottomLinePointColl.length-1)].x+(t.bottomCenterCircle.radius+2)&&o>=t.horBottomLinePointColl[Math.round(t.horBottomLinePointColl.length-1)].y-(t.bottomCenterCircle.radius+2)&&o<=t.horBottomLinePointColl[Math.round(t.horBottomLinePointColl.length-1)].y+(t.bottomCenterCircle.radius+2))r.style.cursor=n.cursor="se-resize";else if(!e.isNullOrUndefined(t.rotationCirclePointColl)&&i>=t.rotationCirclePointColl.x-(t.bottomCenterCircle.radius+2)&&i<=t.rotationCirclePointColl.x+(t.bottomCenterCircle.radius+2)&&o>=t.rotationCirclePointColl.y-(t.bottomCenterCircle.radius+2)&&o<=t.rotationCirclePointColl.y+(t.bottomCenterCircle.radius+2))r.style.cursor=n.cursor="grabbing";else{r.style.cursor=n.cursor="default";this.getRectanglePoints(t.activePoint.startX,t.activePoint.startY,t.activePoint.width,t.activePoint.height,t.rotatedAngle*(180/Math.PI),i,o)&&(r.style.cursor=n.cursor="move")}if("default"===n.cursor)for(var a=0,s=t.horTopLinePointColl.length;a<s;a++)if(i>=t.horTopLinePointColl[a].x-5&&i<=t.horTopLinePointColl[a].x+5&&o>=t.horTopLinePointColl[a].y-5&&o<=t.horTopLinePointColl[a].y+5){r.style.cursor=n.cursor=this.resizedElement="n-resize";break}if("default"===n.cursor)for(a=0,s=t.horBottomLinePointColl.length;a<s;a++)if(i>=t.horBottomLinePointColl[a].x-5&&i<=t.horBottomLinePointColl[a].x+5&&o>=t.horBottomLinePointColl[a].y-5&&o<=t.horBottomLinePointColl[a].y+5){r.style.cursor=n.cursor=this.resizedElement="s-resize";break}if("default"===n.cursor)for(a=0,s=t.verLeftLinePointColl.length;a<s;a++)if(i>=t.verLeftLinePointColl[a].x-5&&i<=t.verLeftLinePointColl[a].x+5&&o>=t.verLeftLinePointColl[a].y-5&&o<=t.verLeftLinePointColl[a].y+5){r.style.cursor=n.cursor=this.resizedElement="w-resize";break}if("default"===n.cursor)for(a=0,s=t.verRightLinePointColl.length;a<s;a++)if(i>=t.verRightLinePointColl[a].x-5&&i<=t.verRightLinePointColl[a].x+5&&o>=t.verRightLinePointColl[a].y-5&&o<=t.verRightLinePointColl[a].y+5){r.style.cursor=n.cursor=this.resizedElement="e-resize";break}return this.adjustCursorStylesForRotatedState(t),n.cursor},o.prototype.adjustCursorStylesForRotatedState=function(t){var e=this.parent,i=t.rotatedAngle*(180/Math.PI);if((i=i>0?Math.floor(i):Math.ceil(i))>=92&&i<=182||i>=-178&&i<=-88){var o={"nw-resize":"ne-resize","n-resize":"s-resize","ne-resize":"nw-resize","w-resize":"e-resize","e-resize":"w-resize","sw-resize":"se-resize","s-resize":"n-resize","se-resize":"sw-resize"};e.cursor in o&&(e.cursor=o[e.cursor])}return e.upperCanvas.style.cursor=this.getResizeElement(t.rotatedAngle*(180/Math.PI),e.cursor),e.cursor},o.prototype.getResizeElement=function(t,e){var i=[];"nw-resize"===e?i=[[337.5,22.5,"nw-resize"],[22.5,67.5,"n-resize"],[67.5,112.5,"ne-resize"],[112.5,157.5,"e-resize"],[157.5,202.5,"se-resize"],[202.5,247.5,"s-resize"],[247.5,292.5,"sw-resize"],[292.5,337.5,"w-resize"]]:"n-resize"===e?i=[[337.5,22.5,"n-resize"],[22.5,67.5,"ne-resize"],[67.5,112.5,"e-resize"],[112.5,157.5,"se-resize"],[157.5,202.5,"s-resize"],[202.5,247.5,"sw-resize"],[247.5,292.5,"w-resize"],[292.5,337.5,"nw-resize"]]:"ne-resize"===e?i=[[337.5,22.5,"ne-resize"],[22.5,67.5,"e-resize"],[67.5,112.5,"se-resize"],[112.5,157.5,"s-resize"],[157.5,202.5,"sw-resize"],[202.5,247.5,"w-resize"],[247.5,292.5,"nw-resize"],[292.5,337.5,"n-resize"]]:"e-resize"===e?i=[[337.5,22.5,"e-resize"],[22.5,67.5,"se-resize"],[67.5,112.5,"s-resize"],[112.5,157.5,"sw-resize"],[157.5,202.5,"w-resize"],[202.5,247.5,"nw-resize"],[247.5,292.5,"n-resize"],[292.5,337.5,"ne-resize"]]:"se-resize"===e?i=[[337.5,22.5,"se-resize"],[22.5,67.5,"s-resize"],[67.5,112.5,"sw-resize"],[112.5,157.5,"w-resize"],[157.5,202.5,"nw-resize"],[202.5,247.5,"n-resize"],[247.5,292.5,"ne-resize"],[292.5,337.5,"e-resize"]]:"s-resize"===e?i=[[337.5,22.5,"s-resize"],[22.5,67.5,"sw-resize"],[67.5,112.5,"w-resize"],[112.5,157.5,"nw-resize"],[157.5,202.5,"n-resize"],[202.5,247.5,"ne-resize"],[247.5,292.5,"e-resize"],[292.5,337.5,"se-resize"]]:"sw-resize"===e?i=[[337.5,22.5,"sw-resize"],[22.5,67.5,"w-resize"],[67.5,112.5,"nw-resize"],[112.5,157.5,"n-resize"],[157.5,202.5,"ne-resize"],[202.5,247.5,"e-resize"],[247.5,292.5,"se-resize"],[292.5,337.5,"s-resize"]]:"w-resize"===e&&(i=[[337.5,22.5,"w-resize"],[22.5,67.5,"nw-resize"],[67.5,112.5,"n-resize"],[112.5,157.5,"ne-resize"],[157.5,202.5,"e-resize"],[202.5,247.5,"se-resize"],[247.5,292.5,"s-resize"],[292.5,337.5,"sw-resize"]]);for(var o=t<0?360-Math.abs(t):t,r=0,n=i;r<n.length;r++){var a=n[r],s=a[0],l=a[1],p=a[2];if(o>s&&o<=l||o+360>s&&o+360<=l)return p}return e},o.prototype.setCursorForFreehandDrawing=function(t,i,o){var r=o.getContext("2d"),n=this.parent,a=document.querySelector("#"+n.element.id+"_textArea"),s=!1;n.notify("freehand-draw",{prop:"setFreehandDrawHoveredIndex",onPropertyChange:!1,value:{index:-1}});for(var l,p=0;p<n.freehandCounter;p++){var h={selPointColl:{}};n.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:h}}),l=e.extend([],h.selPointColl[p].points,[]),n.points=e.extend([],n.pointColl[p].points,[]),n.notify("freehand-draw",{prop:"setPointCounter",onPropertyChange:!1,value:{value:0}});for(var c=l.length,d=0;d<c;d++)if(0!==d){var v=!1;if(l[d-1]&&l[d]&&(v=this.isInside(t,i,l[d-1].x,l[d-1].y,l[d].x,l[d].y)),v){this.isFhdPoint=!0,n.notify("freehand-draw",{prop:"setFreehandDrawHoveredIndex",onPropertyChange:!1,value:{index:p}}),n.notify("freehand-draw",{prop:"hoverFhd",onPropertyChange:!1,value:{strokeColor:null,strokeWidth:null}}),o.style.cursor=n.cursor="pointer",s=!0;break}if(!this.isFhdEditing||n.pointColl[p].isSelected){if((this.isFhdPoint||this.isFhdEditing)&&(r.clearRect(0,0,o.width,o.height),n.activeObj.shape&&"none"===a.style.display&&n.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate",obj:n.activeObj}})),this.isFhdEditing){var u=n.pointColl[p].strokeColor;n.notify("freehand-draw",{prop:"hoverFhd",onPropertyChange:!1,value:{strokeColor:u,strokeWidth:n.pointColl[p].strokeWidth}})}else n.notify("freehand-draw",{prop:"setFreehandDrawHoveredIndex",onPropertyChange:!1,value:{index:null}});this.isFhdPoint=!1}}else{if(t>n.points[d].x-n.pointColl[p].strokeWidth&&t<n.points[d].x+n.pointColl[p].strokeWidth&&i>n.points[d].y-n.pointColl[p].strokeWidth&&i<n.points[d].y+n.pointColl[p].strokeWidth){this.isFhdPoint=!0,n.notify("freehand-draw",{prop:"setFreehandDrawHoveredIndex",onPropertyChange:!1,value:{index:p}}),n.notify("freehand-draw",{prop:"hoverFhd",onPropertyChange:!1,value:{strokeColor:null,strokeWidth:null}}),o.style.cursor=n.cursor="pointer",s=!0;break}if(!this.isFhdEditing||n.pointColl[p].isSelected){if((this.isFhdPoint||this.isFhdEditing)&&(r.clearRect(0,0,o.width,o.height),e.isNullOrUndefined(n.activeObj.shape)||"none"!==a.style.display||n.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate",obj:n.activeObj}})),this.isFhdEditing){u=n.pointColl[p].strokeColor;n.notify("freehand-draw",{prop:"hoverFhd",onPropertyChange:!1,value:{strokeColor:u,strokeWidth:n.pointColl[p].strokeWidth}})}this.isFhdPoint=!1}}if(s)break}},o.prototype.setCursorFromObj=function(t,i,o,r,n){for(var a=this.parent,s=0,l=o.length;s<l;s++){if("move"===a.cursor)return;var p=e.extend({},o[s],{},!0);this.cursorTargetId=p.currIndex,"line"===p.shape||"arrow"===p.shape?this.setCursorForLineArrow(p,t,i,r):"path"===p.shape?this.setCursorForPath(p,t,i,r):e.isNullOrUndefined(p.rotatedAngle)||0===p.rotatedAngle?r.style.cursor=a.cursor=this.getMouseCursor(p,t,i,n,!0):this.setCursorForRotatedObject(p,t,i,r)}},o.prototype.isInside=function(t,e,i,o,r,n){var a=Math.min(i,r),s=Math.max(i,r),l=Math.min(o,n),p=Math.max(o,n);return a<=t&&t<=s&&l<=e&&e<=p},o.prototype.updateActivePoint=function(t,i,o){var r=this.parent,n={width:0,height:0};r.notify("transform",{prop:"calcMaxDimension",onPropertyChange:!1,value:{width:r.activeObj.activePoint.width,height:r.activeObj.activePoint.height,obj:n}});var a=n,s=this.updatePrevShapeSettings(),l={action:"resize",previousShapeSettings:s},p={action:"move",previousShapeSettings:s};e.isNullOrUndefined(this.shapeResizingArgs)&&(this.shapeResizingArgs=l),e.isNullOrUndefined(this.shapeMovingArgs)&&(this.shapeMovingArgs=p),"text"===r.activeObj.shape&&""!==this.dragElement&&r.notify("shape",{prop:"updateFontRatio",onPropertyChange:!1,value:{obj:r.activeObj,isTextArea:null}}),""===this.currentDrawingShape||""!==this.dragElement&&"move"!==this.dragElement||("line"===r.activeObj.shape||"arrow"===r.activeObj.shape||"path"===r.activeObj.shape?this.dragElement="e-resize":t>r.activeObj.activePoint.startX&&i>r.activeObj.activePoint.startY?this.dragElement="se-resize":t<r.activeObj.activePoint.startX&&i>r.activeObj.activePoint.startY?this.dragElement="sw-resize":t>r.activeObj.activePoint.startX&&i<r.activeObj.activePoint.startY?this.dragElement="ne-resize":t<r.activeObj.activePoint.startX&&i<r.activeObj.activePoint.startY&&(this.dragElement="nw-resize")),"arrow"===r.activeObj.shape&&(Math.atan2(t-r.lowerCanvas.width/2,i-r.lowerCanvas.height/2)>0?r.activeObj.rotatedAngle=-Math.atan2(t-r.lowerCanvas.width/2,i-r.lowerCanvas.height/2):r.activeObj.rotatedAngle=Math.abs(Math.atan2(t-r.lowerCanvas.width/2,i-r.lowerCanvas.height/2)));var h,c=!1,d=!1;switch(this.dragElement.toLowerCase()){case"nw-resize":this.updateNWPoints(t,i,a),r.notify("shape",{prop:"updateArrowDirection",onPropertyChange:!1,value:{obj:r.activeObj,flip:null,rotatedDegree:null}}),this.triggerShapeChange(l,p,"resize");break;case"n-resize":this.updateNPoints(t,i),r.notify("shape",{prop:"updateArrowDirection",onPropertyChange:!1,value:{obj:r.activeObj,flip:null,rotatedDegree:null}}),this.triggerShapeChange(l,p,"resize");break;case"ne-resize":this.updateNEPoints(t,i,a),r.notify("shape",{prop:"updateArrowDirection",onPropertyChange:!1,value:{obj:r.activeObj,flip:null,rotatedDegree:null}}),this.triggerShapeChange(l,p,"resize");break;case"w-resize":this.updateWPoints(t,i),r.notify("shape",{prop:"updateArrowDirection",onPropertyChange:!1,value:{obj:r.activeObj,flip:null,rotatedDegree:null}}),this.triggerShapeChange(l,p,"resize");break;case"e-resize":this.updateEPoints(t,i),r.notify("shape",{prop:"updateArrowDirection",onPropertyChange:!1,value:{obj:r.activeObj,flip:null,rotatedDegree:null}}),this.triggerShapeChange(l,p,"resize");break;case"sw-resize":this.updateSWPoints(t,i,a),r.notify("shape",{prop:"updateArrowDirection",onPropertyChange:!1,value:{obj:r.activeObj,flip:null,rotatedDegree:null}}),this.triggerShapeChange(l,p,"resize");break;case"s-resize":this.updateSPoints(t,i),r.notify("shape",{prop:"updateArrowDirection",onPropertyChange:!1,value:{obj:r.activeObj,flip:null,rotatedDegree:null}}),this.triggerShapeChange(l,p,"resize");break;case"se-resize":this.updateSEPoints(t,i,a),r.notify("shape",{prop:"updateArrowDirection",onPropertyChange:!1,value:{obj:r.activeObj,flip:null,rotatedDegree:null}}),this.triggerShapeChange(l,p,"resize");break;case"grabbing":Math.atan2(t-(r.activeObj.activePoint.startX+r.activeObj.activePoint.width/2),i-(r.activeObj.activePoint.startY+r.activeObj.activePoint.height/2))>0?r.activeObj.rotatedAngle=-Math.atan2(t-(r.activeObj.activePoint.startX+r.activeObj.activePoint.width/2),i-(r.activeObj.activePoint.startY+r.activeObj.activePoint.height/2)):r.activeObj.rotatedAngle=Math.abs(Math.atan2(t-(r.activeObj.activePoint.startX+r.activeObj.activePoint.width/2),i-(r.activeObj.activePoint.startY+r.activeObj.activePoint.height/2))),(h=0===r.activeObj.shapeDegree?r.transform.degree:r.transform.degree-r.activeObj.shapeDegree)<0&&(h=360+h);for(var v=0,u=r.activeObj.flipObjColl.length;v<u;v++)"horizontal"===r.activeObj.flipObjColl[v].toLowerCase()?c=!0:"vertical"===r.activeObj.flipObjColl[v].toLowerCase()&&(d=!0);r.activeObj.rotatedAngle-=h*(Math.PI/180),0===h||360===h?d&&(r.activeObj.rotatedAngle-=Math.PI/180*180):90===h||-270===h?c&&(r.activeObj.rotatedAngle-=Math.PI/180*180):180===h||-180===h?d&&(r.activeObj.rotatedAngle-=Math.PI/180*180):270!==h&&-90!==h||c&&(r.activeObj.rotatedAngle-=Math.PI/180*180);break;case"pathdrag":e.isNullOrUndefined(this.pathAdjustedIndex)||(r.activeObj.pointColl[this.pathAdjustedIndex].x=t,r.activeObj.pointColl[this.pathAdjustedIndex].y=i);break;default:if(!o&&!r.currObjType.isCustomCrop){if(this.dragPoint.startX){var g=this.dragPoint.endX-this.previousPoint.x,b=this.dragPoint.endY-this.previousPoint.y;if(r.activeObj.activePoint.startX+=g,r.activeObj.activePoint.endX+=g,r.activeObj.activePoint.startY+=b,r.activeObj.activePoint.endY+=b,"line"!==r.activeObj.shape&&"arrow"!==r.activeObj.shape&&r.activeObj.rotationCirclePointColl&&(r.activeObj.rotationCirclePointColl.x+=g,r.activeObj.rotationCirclePointColl.y+=b,r.activeObj.rotationCirclePoint.x+=g,r.activeObj.rotationCirclePoint.y+=b),"path"===r.activeObj.shape)for(v=0,u=r.activeObj.pointColl.length;v<u;v++)r.activeObj.pointColl[v].x+=g,r.activeObj.pointColl[v].y+=b;!this.isPreventDragging&&(r.activeObj.activePoint.startX<r.img.destLeft||r.activeObj.activePoint.startY<r.img.destTop||r.activeObj.activePoint.endX>r.img.destLeft+r.img.destWidth||r.activeObj.activePoint.endY>r.img.destTop+r.img.destHeight)&&(r.activeObj.activePoint.startX-=g,r.activeObj.activePoint.endX-=g,r.activeObj.activePoint.startY-=b,r.activeObj.activePoint.endY-=b,"line"!==r.activeObj.shape&&"arrow"!==r.activeObj.shape&&r.activeObj.rotationCirclePointColl&&(r.activeObj.rotationCirclePointColl.x-=g,r.activeObj.rotationCirclePointColl.y-=b,r.activeObj.rotationCirclePoint.x-=g,r.activeObj.rotationCirclePoint.y-=b),this.setDragWidth(g),this.setDragHeight(b))}else r.activeObj.activePoint.startX=t<this.mouseDownPoint.x?t:this.mouseDownPoint.x,r.activeObj.activePoint.startY=i<this.mouseDownPoint.y?i:this.mouseDownPoint.y,t=t<this.mouseDownPoint.x?this.mouseDownPoint.x:t,i=i<this.mouseDownPoint.y?this.mouseDownPoint.y:i,r.activeObj.activePoint.endX=t,r.activeObj.activePoint.endY=i;this.triggerShapeChange(l,p,"move")}}},o.prototype.triggerShapeChange=function(t,i,o){var r=this.parent;r.activeObj.activePoint.width=r.activeObj.activePoint.endX-r.activeObj.activePoint.startX,r.activeObj.activePoint.height=r.activeObj.activePoint.endY-r.activeObj.activePoint.startY;var n=this.updatePrevShapeSettings();if(t.currentShapeSettings=n,i.currentShapeSettings=n,"resize"===o){this.isCropSelection=!1;var a=void 0;if(void 0!==r.activeObj.shape&&(a=r.activeObj.shape.split("-")),void 0!==a&&"crop"===a[0]&&(this.isCropSelection=!0),this.isCropSelection||"resize"===this.parent.eventType||!e.isBlazor()||e.isNullOrUndefined(r.events)||!0!==this.parent.events.onShapeResizeStart.hasDelegate)if(this.isCropSelection){var s={action:t.action,previousSelectionSettings:{type:r.getSelectionType(r.activeObj.shape),startX:t.previousShapeSettings.startX,startY:t.previousShapeSettings.startY,width:t.previousShapeSettings.width,height:t.previousShapeSettings.height},currentSelectionSettings:{type:r.getSelectionType(r.activeObj.shape),startX:t.currentShapeSettings.startX,startY:t.currentShapeSettings.startY,width:t.currentShapeSettings.width,height:t.currentShapeSettings.height}};e.isNullOrUndefined(this.selectionResizingArgs)&&(this.selectionResizingArgs=s),e.isBlazor()&&e.isNullOrUndefined(this.parent.eventType)&&r.events&&!0===r.events.onSelectionResizeStart.hasDelegate?(s.action="resize-start",r.dotNetRef.invokeMethodAsync("SelectionEventAsync","OnSelectionResizeStart",s).then(function(t){r.notify("shape",{prop:"updSelChangeEventArgs",onPropertyChange:!1,value:{selectionSettings:t.currentSelectionSettings}})})):(r.trigger("selectionChanging",s),r.notify("shape",{prop:"updSelChangeEventArgs",onPropertyChange:!1,value:{selectionSettings:s.currentSelectionSettings}}))}else r.trigger("shapeChanging",t),r.notify("shape",{prop:"updateShapeChangeEventArgs",onPropertyChange:!1,value:{shapeSettings:t.currentShapeSettings}});else t.action="resize-start",r.dotNetRef.invokeMethodAsync("ShapeEventAsync","OnShapeResizeStart",t).then(function(t){r.notify("shape",{prop:"updateShapeChangeEventArgs",onPropertyChange:!1,value:{shapeSettings:t.currentShapeSettings}})})}else e.isBlazor()&&e.isNullOrUndefined(this.parent.eventType)&&r.events&&!0===r.events.onShapeDragStart.hasDelegate?(i.action="drag-start",r.dotNetRef.invokeMethodAsync("ShapeEventAsync","OnShapeDragStart",i).then(function(t){r.notify("shape",{prop:"updateShapeChangeEventArgs",onPropertyChange:!1,value:{shapeSettings:t.currentShapeSettings}})})):(r.trigger("shapeChanging",i),r.notify("shape",{prop:"updateShapeChangeEventArgs",onPropertyChange:!1,value:{shapeSettings:i.currentShapeSettings}}));this.parent.eventType=o},o.prototype.setDragWidth=function(t){var e=this.parent,i=t;if(i>=0)for(var o=0;o<i&&(t=i-o,e.activeObj.activePoint.startX+=t,e.activeObj.activePoint.endX+=t,!(e.activeObj.activePoint.startX>=e.img.destLeft&&e.activeObj.activePoint.endX<=e.img.destLeft+e.img.destWidth));o++)e.activeObj.activePoint.startX-=t,e.activeObj.activePoint.endX-=t;else for(o=1;o<Math.abs(i)&&(t=i+o,e.activeObj.activePoint.startX+=t,e.activeObj.activePoint.endX+=t,!(e.activeObj.activePoint.startX>=e.img.destLeft&&e.activeObj.activePoint.endX<=e.img.destLeft+e.img.destWidth));o++)e.activeObj.activePoint.startX-=t,e.activeObj.activePoint.endX-=t},o.prototype.setDragHeight=function(t){var e=this.parent,i=t;if(i>=0)for(var o=1;o<i&&(t=i-o,e.activeObj.activePoint.startY+=t,e.activeObj.activePoint.endY+=t,!(e.activeObj.activePoint.startY>=e.img.destTop&&e.activeObj.activePoint.endY<=e.img.destTop+e.img.destHeight));o++)e.activeObj.activePoint.startY-=t,e.activeObj.activePoint.endY-=t;else for(o=0;o<Math.abs(i)&&(t=i+o,e.activeObj.activePoint.startY+=t,e.activeObj.activePoint.endY+=t,!(e.activeObj.activePoint.startY>=e.img.destTop&&e.activeObj.activePoint.endY<=e.img.destTop+e.img.destHeight));o++)e.activeObj.activePoint.startY-=t,e.activeObj.activePoint.endY-=t},o.prototype.limitDrag=function(t){var e=this.parent,i=t?e.activeObj.activePoint.startX:e.activeObj.activePoint.endX,o=t?e.activeObj.activePoint.startY:e.activeObj.activePoint.endY,r=t?e.activeObj.activePoint.endX:e.activeObj.activePoint.startX,n=t?e.activeObj.activePoint.endY:e.activeObj.activePoint.startY;i<e.img.destLeft&&(i=e.img.destLeft),o<e.img.destTop&&(o=e.img.destTop),r>e.img.destLeft+e.img.destWidth&&(r=e.img.destLeft+e.img.destWidth),n>e.img.destTop+e.img.destHeight&&(n=e.img.destTop+e.img.destHeight),t?(e.activeObj.activePoint.startX=i,e.activeObj.activePoint.startY=o,e.activeObj.activePoint.endX=r,e.activeObj.activePoint.endY=n):(e.activeObj.activePoint.startX=r,e.activeObj.activePoint.startY=n,e.activeObj.activePoint.endX=i,e.activeObj.activePoint.endY=o)},o.prototype.preventDraggingInvertly=function(){var t=this.parent;this.isPreventDragging||0!==t.activeObj.rotatedAngle||(this.limitDrag(!0),"line"!==t.activeObj.shape&&"arrow"!==t.activeObj.shape&&"path"!==t.activeObj.shape||this.limitDrag(!1))},o.prototype.preventTextDraggingInvertly=function(){var t=this.parent,e=!1;return this.isPreventDragging||(t.activeObj.activePoint.startX<t.img.destLeft||t.activeObj.activePoint.startY<t.img.destTop||t.activeObj.activePoint.endX>t.img.destLeft+t.img.destWidth||t.activeObj.activePoint.endY>t.img.destTop+t.img.destHeight)&&(e=!0),e},o.prototype.preventInverseResize=function(t){var e=this.parent;e.activeObj.activePoint.width<0&&(e.activeObj.activePoint.width=0,e.activeObj.activePoint.startX=t.activePoint.startX,e.activeObj.activePoint.endX=t.activePoint.endX),e.activeObj.activePoint.height<0&&(e.activeObj.activePoint.height=0,e.activeObj.activePoint.startY=t.activePoint.startY,e.activeObj.activePoint.endY=t.activePoint.endY)},o.prototype.getScaleRatio=function(t){var e=this.parent,i={x:t,y:t};if(e.activeObj.shape&&"crop-custom"!==e.activeObj.shape&&"crop-circle"!==e.activeObj.shape&&"crop-square"!==e.activeObj.shape){var o=e.activeObj.shape.split("-");if(o.length>1){o=o[1].split(":");var r=t/parseInt(o[1],10);i.x=r*parseInt(o[0],10),i.y=r*parseInt(o[1],10)}}return i},o.prototype.updateNWPoints=function(t,i,o){var r,n,a,s,l=this.parent,p=this.diffPoint.x,h=this.diffPoint.y,c=e.extend({},l.activeObj,null,!0);if("text"===l.activeObj.shape)void 0===this.oldPoint.x&&void 0===this.oldPoint.y?(this.diffPoint.x=l.activeObj.activePoint.startX-t,this.diffPoint.y=l.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,s=(this.diffPoint.x<=p&&this.diffPoint.y>=h?Math.min(this.diffPoint.x,this.diffPoint.y):Math.max(this.diffPoint.x,this.diffPoint.y))/10,l.activeObj.activePoint.startX-=o.width/100*s,l.activeObj.activePoint.startY-=o.height/100*s,this.preventTextDraggingInvertly()&&(l.activeObj.activePoint.startX+=o.width/100*s,l.activeObj.activePoint.startY+=o.height/100*s),l.activeObj.activePoint.width=l.activeObj.activePoint.endX-l.activeObj.activePoint.startX,l.activeObj.activePoint.height=l.activeObj.activePoint.endY-l.activeObj.activePoint.startY,l.notify("shape",{prop:"updateFontSize",onPropertyChange:!1,value:{obj:l.activeObj}});else{var d=void 0;if(void 0!==l.activeObj.shape&&(d=l.activeObj.shape.split("-")),"crop-custom"===l.activeObj.shape||void 0!==l.activeObj.shape&&"crop"!==d[0]){if(this.adjustNWPoints(l.activeObj.activePoint,t,i,l.activeObj.rotatedAngle),l.activeObj.activePoint.startX>l.activeObj.activePoint.endX){var v=l.activeObj.activePoint.startX;l.activeObj.activePoint.startX=l.activeObj.activePoint.endX,l.activeObj.activePoint.endX=v,this.dragElement=l.upperCanvas.style.cursor=l.cursor="ne-resize"}if(l.activeObj.activePoint.startY>l.activeObj.activePoint.endY){v=l.activeObj.activePoint.startY;l.activeObj.activePoint.startY=l.activeObj.activePoint.endY,l.activeObj.activePoint.endY=v,this.dragElement=l.upperCanvas.style.cursor=l.cursor="sw-resize"}this.preventDraggingInvertly()}else if(l.activeObj.activePoint.startX<t&&l.activeObj.activePoint.startY<i){r=t-l.activeObj.activePoint.startX,n=i-l.activeObj.activePoint.startY,a=Math.min(r,n);var u=this.getScaleRatio(a);l.activeObj.activePoint.startX+=u.x,l.activeObj.activePoint.startY+=u.y;var g=l.img.destLeft>0?l.img.destLeft:0,b=l.img.destTop>0?l.img.destTop:0;(l.activeObj.activePoint.startX<g||l.activeObj.activePoint.startY<b)&&(l.activeObj.activePoint.startX-=u.x,l.activeObj.activePoint.startY-=u.y)}else{r=l.activeObj.activePoint.startX-t,n=i-l.activeObj.activePoint.endY,a=Math.max(r,n);u=this.getScaleRatio(a);l.activeObj.activePoint.startX-=u.x,l.activeObj.activePoint.startY-=u.y;g=l.img.destLeft>0?l.img.destLeft:0;var C=l.img.destTop>0?l.img.destTop:0;(l.activeObj.activePoint.startX<g||l.activeObj.activePoint.startY<C)&&(l.activeObj.activePoint.startX+=u.x,l.activeObj.activePoint.startY+=u.y)}l.activeObj.activePoint.width=l.activeObj.activePoint.endX-l.activeObj.activePoint.startX,l.activeObj.activePoint.height=l.activeObj.activePoint.endY-l.activeObj.activePoint.startY,this.preventInverseResize(c)}},o.prototype.updateNPoints=function(t,e){var i,o,r,n=this.parent;if("text"!==n.activeObj.shape){var a=void 0;if(n.activeObj.shape&&(a=n.activeObj.shape.split("-")),"crop-custom"===n.activeObj.shape||n.activeObj.shape&&"crop"!==a[0]){if("line"!==n.activeObj.shape&&"arrow"!==n.activeObj.shape&&"path"!==n.activeObj.shape&&0!==n.activeObj.rotatedAngle&&this.dragPoint.startX?(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),i=this.dragPoint.endX-this.previousPoint.x,o=this.dragPoint.endY-this.previousPoint.y,this.adjustRotationPoints(n.activeObj.activePoint,i,o,n.activeObj.rotatedAngle)):(n.activeObj.activePoint.startY=e,n.activeObj.activePoint.height=n.activeObj.activePoint.endY-n.activeObj.activePoint.startY),n.activeObj.activePoint.startY>n.activeObj.activePoint.endY){var s=n.activeObj.activePoint.startY;n.activeObj.activePoint.startY=n.activeObj.activePoint.endY,n.activeObj.activePoint.endY=s,this.dragElement=this.resizedElement="s-resize"}this.preventDraggingInvertly()}else{if(n.activeObj.activePoint.endX>t&&n.activeObj.activePoint.startY<e){i=n.activeObj.activePoint.endX-t,o=e-n.activeObj.activePoint.startY,r=Math.min(i,o);var l=this.getScaleRatio(r);n.activeObj.activePoint.endX-=l.x,n.activeObj.activePoint.startY+=l.y,(n.activeObj.activePoint.endX>n.img.destLeft+n.img.destWidth||n.activeObj.activePoint.startY<n.img.destTop)&&(n.activeObj.activePoint.endX+=l.x,n.activeObj.activePoint.startY-=l.y)}else{i=t-n.activeObj.activePoint.endX,o=n.activeObj.activePoint.startY-e,r=Math.max(i,o);l=this.getScaleRatio(r);n.activeObj.activePoint.endX+=l.x,n.activeObj.activePoint.startY-=l.y,(n.activeObj.activePoint.endX>n.img.destLeft+n.img.destWidth||n.activeObj.activePoint.startY<n.img.destTop)&&(n.activeObj.activePoint.endX-=l.x,n.activeObj.activePoint.startY+=l.y)}n.activeObj.activePoint.width=n.activeObj.activePoint.endX-n.activeObj.activePoint.startX,n.activeObj.activePoint.height=n.activeObj.activePoint.endY-n.activeObj.activePoint.startY}}},o.prototype.updateNEPoints=function(t,i,o){var r,n,a,s,l=this.parent,p=this.diffPoint.x,h=this.diffPoint.y,c=e.extend({},l.activeObj,null,!0);if("text"===l.activeObj.shape)void 0===this.oldPoint.x&&void 0===this.oldPoint.y?(this.diffPoint.x=t-l.activeObj.activePoint.endX,this.diffPoint.y=l.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,s=(this.diffPoint.x<=p&&this.diffPoint.y>=h?Math.min(this.diffPoint.x,this.diffPoint.y):Math.max(this.diffPoint.x,this.diffPoint.y))/10,l.activeObj.activePoint.endX+=o.width/100*s,l.activeObj.activePoint.startY-=o.height/100*s,this.preventTextDraggingInvertly()&&(l.activeObj.activePoint.endX-=o.width/100*s,l.activeObj.activePoint.startY+=o.height/100*s),l.activeObj.activePoint.width=l.activeObj.activePoint.endX-l.activeObj.activePoint.startX,l.activeObj.activePoint.height=l.activeObj.activePoint.endY-l.activeObj.activePoint.startY,l.notify("shape",{prop:"updateFontSize",onPropertyChange:!1,value:{obj:l.activeObj}});else{var d=void 0;if(l.activeObj.shape&&(d=l.activeObj.shape.split("-")),"crop-custom"===l.activeObj.shape||void 0!==l.activeObj.shape&&"crop"!==d[0]){if(this.adjustNEPoints(l.activeObj.activePoint,t,i,l.activeObj.rotatedAngle),l.activeObj.activePoint.endX<l.activeObj.activePoint.startX){var v=l.activeObj.activePoint.endX;l.activeObj.activePoint.endX=l.activeObj.activePoint.startX,l.activeObj.activePoint.startX=v,this.dragElement=l.upperCanvas.style.cursor=l.cursor="nw-resize"}if(l.activeObj.activePoint.startY>l.activeObj.activePoint.endY){v=l.activeObj.activePoint.startY;l.activeObj.activePoint.startY=l.activeObj.activePoint.endY,l.activeObj.activePoint.endY=v,this.dragElement=l.upperCanvas.style.cursor=l.cursor="se-resize"}this.preventDraggingInvertly()}else if(l.activeObj.activePoint.endX>t&&l.activeObj.activePoint.startY<i){r=l.activeObj.activePoint.endX-t,n=i-l.activeObj.activePoint.startY,a=Math.min(r,n);var u=this.getScaleRatio(a);l.activeObj.activePoint.endX-=u.x,l.activeObj.activePoint.startY+=u.y;var g=l.img.destLeft+l.img.destWidth<l.lowerCanvas.width?l.img.destLeft+l.img.destWidth:l.lowerCanvas.width,b=l.img.destTop>0?l.img.destTop:0;(l.activeObj.activePoint.endX>g||l.activeObj.activePoint.startY<b)&&(l.activeObj.activePoint.endX+=u.x,l.activeObj.activePoint.startY-=u.y)}else{r=t-l.activeObj.activePoint.endX,n=l.activeObj.activePoint.startY-i,a=Math.max(r,n);u=this.getScaleRatio(a);l.activeObj.activePoint.endX+=u.x,l.activeObj.activePoint.startY-=u.y;g=l.img.destLeft+l.img.destWidth<l.lowerCanvas.width?l.img.destLeft+l.img.destWidth:l.lowerCanvas.width,b=l.img.destTop>0?l.img.destTop:0;(l.activeObj.activePoint.endX>g||l.activeObj.activePoint.startY<b)&&(l.activeObj.activePoint.endX-=u.x,l.activeObj.activePoint.startY+=u.y)}l.activeObj.activePoint.width=l.activeObj.activePoint.endX-l.activeObj.activePoint.startX,l.activeObj.activePoint.height=l.activeObj.activePoint.endY-l.activeObj.activePoint.startY,this.preventInverseResize(c)}},o.prototype.updateWPoints=function(t,e){var i,o,r,n=this.parent;if("text"!==n.activeObj.shape){var a=void 0;if(n.activeObj.shape&&(a=n.activeObj.shape.split("-")),"crop-custom"===n.activeObj.shape||n.activeObj.shape&&"crop"!==a[0]){if("line"!==n.activeObj.shape&&"arrow"!==n.activeObj.shape&&"path"!==n.activeObj.shape&&0!==n.activeObj.rotatedAngle&&this.dragPoint.startX?(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),i=this.dragPoint.endX-this.previousPoint.x,o=this.dragPoint.endY-this.previousPoint.y,this.adjustRotationPoints(n.activeObj.activePoint,i,o,n.activeObj.rotatedAngle)):(n.activeObj.activePoint.startX=t,n.activeObj.activePoint.width=n.activeObj.activePoint.endX-n.activeObj.activePoint.startX),"line"===n.activeObj.shape||"arrow"===n.activeObj.shape||"path"===n.activeObj.shape)n.activeObj.activePoint.startY=e,n.activeObj.activePoint.height=n.activeObj.activePoint.endY-n.activeObj.activePoint.startY,this.adjustActObjForLineArrow()&&(this.dragElement="e-resize","right"===n.activeObj.triangleDirection?n.activeObj.triangleDirection="left":"left"===n.activeObj.triangleDirection&&(n.activeObj.triangleDirection="right"));else if(n.activeObj.activePoint.startX>n.activeObj.activePoint.endX){var s=n.activeObj.activePoint.startX;n.activeObj.activePoint.startX=n.activeObj.activePoint.endX,n.activeObj.activePoint.endX=s,this.dragElement=this.resizedElement="e-resize"}this.preventDraggingInvertly()}else{if(n.activeObj.activePoint.startX<t&&n.activeObj.activePoint.endY>e){i=t-n.activeObj.activePoint.startX,o=n.activeObj.activePoint.endY-e,r=Math.min(i,o);var l=this.getScaleRatio(r);n.activeObj.activePoint.startX+=l.x,n.activeObj.activePoint.endY-=l.y,(n.activeObj.activePoint.startX<n.img.destLeft||n.activeObj.activePoint.endY>n.img.destTop+n.img.destHeight)&&(n.activeObj.activePoint.startX-=l.x,n.activeObj.activePoint.endY+=l.y)}else{i=n.activeObj.activePoint.startX-t,o=e-n.activeObj.activePoint.endY,r=Math.max(i,o);l=this.getScaleRatio(r);n.activeObj.activePoint.startX-=l.x,n.activeObj.activePoint.endY+=l.y,(n.activeObj.activePoint.startX<n.img.destLeft||n.activeObj.activePoint.endY>n.img.destTop+n.img.destHeight)&&(n.activeObj.activePoint.startX+=l.x,n.activeObj.activePoint.endY-=l.y)}n.activeObj.activePoint.width=n.activeObj.activePoint.endX-n.activeObj.activePoint.startX,n.activeObj.activePoint.height=n.activeObj.activePoint.endY-n.activeObj.activePoint.startY}}},o.prototype.updateEPoints=function(t,e){var i,o,r,n=this.parent;if("text"!==n.activeObj.shape){var a=void 0;if(n.activeObj.shape&&(a=n.activeObj.shape.split("-")),"crop-custom"===n.activeObj.shape||n.activeObj.shape&&"crop"!==a[0]){if("line"!==n.activeObj.shape&&"arrow"!==n.activeObj.shape&&"path"!==n.activeObj.shape&&0!==n.activeObj.rotatedAngle&&this.dragPoint.startX?(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),i=this.dragPoint.endX-this.previousPoint.x,o=this.dragPoint.endY-this.previousPoint.y,this.adjustRotationPoints(n.activeObj.activePoint,i,o,n.activeObj.rotatedAngle)):(n.activeObj.activePoint.endX=t,n.activeObj.activePoint.width=n.activeObj.activePoint.endX-n.activeObj.activePoint.startX),"line"===n.activeObj.shape||"arrow"===n.activeObj.shape||"path"===n.activeObj.shape)n.activeObj.activePoint.endY=e,n.activeObj.activePoint.height=n.activeObj.activePoint.endY-n.activeObj.activePoint.startY,this.adjustActObjForLineArrow()&&(this.dragElement="w-resize","right"===n.activeObj.triangleDirection?n.activeObj.triangleDirection="left":"left"===n.activeObj.triangleDirection&&(n.activeObj.triangleDirection="right"));else if(n.activeObj.activePoint.endX<n.activeObj.activePoint.startX){var s=n.activeObj.activePoint.endX;n.activeObj.activePoint.endX=n.activeObj.activePoint.startX,n.activeObj.activePoint.startX=s,this.dragElement=this.resizedElement="w-resize"}this.preventDraggingInvertly()}else{if(n.activeObj.activePoint.endX>t&&n.activeObj.activePoint.endY>e){i=n.activeObj.activePoint.endX-t,o=n.activeObj.activePoint.endY-e,r=Math.min(i,o);var l=this.getScaleRatio(r);n.activeObj.activePoint.endX-=l.x,n.activeObj.activePoint.endY-=l.y,(n.activeObj.activePoint.endX>n.img.destLeft+n.img.destWidth||n.activeObj.activePoint.endY>n.img.destTop+n.img.destHeight)&&(n.activeObj.activePoint.endX+=l.x,n.activeObj.activePoint.endY+=l.y)}else{i=t-n.activeObj.activePoint.endX,o=e-n.activeObj.activePoint.endY,r=Math.max(i,o);l=this.getScaleRatio(r);n.activeObj.activePoint.endX+=l.x,n.activeObj.activePoint.endY+=l.y,(n.activeObj.activePoint.endX>n.img.destLeft+n.img.destWidth||n.activeObj.activePoint.endY>n.img.destTop+n.img.destHeight)&&(n.activeObj.activePoint.endX-=l.x,n.activeObj.activePoint.endY-=l.y)}n.activeObj.activePoint.width=n.activeObj.activePoint.endX-n.activeObj.activePoint.startX,n.activeObj.activePoint.height=n.activeObj.activePoint.endY-n.activeObj.activePoint.startY}}},o.prototype.updateSWPoints=function(t,i,o){var r,n,a,s,l=this.parent,p=this.diffPoint.x,h=this.diffPoint.y,c=e.extend({},l.activeObj,null,!0);if("text"===l.activeObj.shape)e.isNullOrUndefined(this.oldPoint.x)&&e.isNullOrUndefined(this.oldPoint.y)?(this.diffPoint.x=l.activeObj.activePoint.startX-t,this.diffPoint.y=i-l.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,s=(this.diffPoint.x<=p&&this.diffPoint.y>=h?Math.min(this.diffPoint.x,this.diffPoint.y):Math.max(this.diffPoint.x,this.diffPoint.y))/10,l.activeObj.activePoint.startX-=o.width/100*s,l.activeObj.activePoint.endY+=o.height/100*s,this.preventTextDraggingInvertly()&&(l.activeObj.activePoint.startX+=o.width/100*s,l.activeObj.activePoint.endY-=o.height/100*s),l.activeObj.activePoint.width=l.activeObj.activePoint.endX-l.activeObj.activePoint.startX,l.activeObj.activePoint.height=l.activeObj.activePoint.endY-l.activeObj.activePoint.startY,l.notify("shape",{prop:"updateFontSize",onPropertyChange:!1,value:{obj:l.activeObj}});else{var d=void 0;if(void 0!==l.activeObj.shape&&(d=l.activeObj.shape.split("-")),"crop-custom"===l.activeObj.shape||void 0!==l.activeObj.shape&&"crop"!==d[0]){if(this.adjustSWPoints(l.activeObj.activePoint,t,i,l.activeObj.rotatedAngle),l.activeObj.activePoint.startX>l.activeObj.activePoint.endX){var v=l.activeObj.activePoint.startX;l.activeObj.activePoint.startX=l.activeObj.activePoint.endX,l.activeObj.activePoint.endX=v,this.dragElement=l.upperCanvas.style.cursor=l.cursor="se-resize"}if(l.activeObj.activePoint.endY<l.activeObj.activePoint.startY){v=l.activeObj.activePoint.endY;l.activeObj.activePoint.endY=l.activeObj.activePoint.startY,l.activeObj.activePoint.startY=v,this.dragElement=l.upperCanvas.style.cursor=l.cursor="nw-resize"}this.preventDraggingInvertly()}else if(l.activeObj.activePoint.startX<t&&l.activeObj.activePoint.endY>i){r=t-l.activeObj.activePoint.startX,n=l.activeObj.activePoint.endY-i,a=Math.min(r,n);var u=this.getScaleRatio(a);l.activeObj.activePoint.startX+=u.x,l.activeObj.activePoint.endY-=u.y;var g=l.img.destLeft>0?l.img.destLeft:0,b=l.img.destTop+l.img.destHeight<l.lowerCanvas.height?l.img.destTop+l.img.destHeight:l.lowerCanvas.height;(l.activeObj.activePoint.startX<g||l.activeObj.activePoint.endY>b)&&(l.activeObj.activePoint.startX-=u.x,l.activeObj.activePoint.endY+=u.y)}else{r=l.activeObj.activePoint.startX-t,n=i-l.activeObj.activePoint.endY,a=Math.max(r,n);u=this.getScaleRatio(a);l.activeObj.activePoint.startX-=u.x,l.activeObj.activePoint.endY+=u.y;g=l.img.destLeft>0?l.img.destLeft:0,b=l.img.destTop+l.img.destHeight<l.lowerCanvas.height?l.img.destTop+l.img.destHeight:l.lowerCanvas.height;(l.activeObj.activePoint.startX<g||l.activeObj.activePoint.endY>b)&&(l.activeObj.activePoint.startX+=u.x,l.activeObj.activePoint.endY-=u.y)}l.activeObj.activePoint.width=l.activeObj.activePoint.endX-l.activeObj.activePoint.startX,l.activeObj.activePoint.height=l.activeObj.activePoint.endY-l.activeObj.activePoint.startY,this.preventInverseResize(c)}},o.prototype.updateSPoints=function(t,e){var i,o,r,n=this.parent;if("text"!==n.activeObj.shape){var a=void 0;if(n.activeObj.shape&&(a=n.activeObj.shape.split("-")),"crop-custom"===n.activeObj.shape||n.activeObj.shape&&"crop"!==a[0]){if("line"!==n.activeObj.shape&&"arrow"!==n.activeObj.shape&&"path"!==n.activeObj.shape&&0!==n.activeObj.rotatedAngle&&this.dragPoint.startX?(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),i=this.dragPoint.endX-this.previousPoint.x,o=this.dragPoint.endY-this.previousPoint.y,this.adjustRotationPoints(n.activeObj.activePoint,i,o,n.activeObj.rotatedAngle)):(n.activeObj.activePoint.endY=e,n.activeObj.activePoint.height=n.activeObj.activePoint.endY-n.activeObj.activePoint.startY),n.activeObj.activePoint.endY<n.activeObj.activePoint.startY){var s=n.activeObj.activePoint.endY;n.activeObj.activePoint.endY=n.activeObj.activePoint.startY,n.activeObj.activePoint.startY=s,this.dragElement=this.resizedElement="n-resize"}this.preventDraggingInvertly()}else{if(n.activeObj.activePoint.endX>t&&n.activeObj.activePoint.endY>e){i=n.activeObj.activePoint.endX-t,o=n.activeObj.activePoint.endY-e,r=Math.min(i,o);var l=this.getScaleRatio(r);n.activeObj.activePoint.endX-=l.x,n.activeObj.activePoint.endY-=l.y,(n.activeObj.activePoint.endX>n.img.destLeft+n.img.destWidth||n.activeObj.activePoint.endY>n.img.destTop+n.img.destHeight)&&(n.activeObj.activePoint.endX+=l.x,n.activeObj.activePoint.endY+=l.y)}else{i=t-n.activeObj.activePoint.endX,o=e-n.activeObj.activePoint.endY,r=Math.max(i,o);l=this.getScaleRatio(r);n.activeObj.activePoint.endX+=l.x,n.activeObj.activePoint.endY+=l.x,(n.activeObj.activePoint.endX>n.img.destLeft+n.img.destWidth||n.activeObj.activePoint.endY>n.img.destTop+n.img.destHeight)&&(n.activeObj.activePoint.endX-=l.x,n.activeObj.activePoint.endY-=l.y)}n.activeObj.activePoint.width=n.activeObj.activePoint.endX-n.activeObj.activePoint.startX,n.activeObj.activePoint.height=n.activeObj.activePoint.endY-n.activeObj.activePoint.startY}}},o.prototype.updateSEPoints=function(t,i,o){var r,n,a,s,l=this.parent,p=this.diffPoint.x,h=this.diffPoint.y,c=e.extend({},l.activeObj,null,!0);if("text"===l.activeObj.shape)void 0===this.oldPoint.x&&void 0===this.oldPoint.y?(this.diffPoint.x=t-l.activeObj.activePoint.endX,this.diffPoint.y=i-l.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,s=(this.diffPoint.x>=p&&this.diffPoint.y>=h?Math.max(this.diffPoint.x,this.diffPoint.y):Math.min(this.diffPoint.x,this.diffPoint.y))/10,l.activeObj.activePoint.endX+=o.width/50*s,l.activeObj.activePoint.endY+=o.height/50*s,this.preventTextDraggingInvertly()&&(l.activeObj.activePoint.endX-=o.width/50*s,l.activeObj.activePoint.endY-=o.height/50*s),l.activeObj.activePoint.width=l.activeObj.activePoint.endX-l.activeObj.activePoint.startX,l.activeObj.activePoint.height=l.activeObj.activePoint.endY-l.activeObj.activePoint.startY,l.notify("shape",{prop:"updateFontSize",onPropertyChange:!1,value:{obj:l.activeObj}});else{var d=void 0;if(void 0!==l.activeObj.shape&&(d=l.activeObj.shape.split("-")),"crop-custom"===l.activeObj.shape||void 0!==l.activeObj.shape&&"crop"!==d[0]){if(this.adjustSEPoints(l.activeObj.activePoint,t,i,l.activeObj.rotatedAngle),l.activeObj.activePoint.endX<l.activeObj.activePoint.startX){var v=l.activeObj.activePoint.endX;l.activeObj.activePoint.endX=l.activeObj.activePoint.startX,l.activeObj.activePoint.startX=v,this.dragElement=l.upperCanvas.style.cursor=l.cursor="sw-resize"}if(l.activeObj.activePoint.endY<l.activeObj.activePoint.startY){v=l.activeObj.activePoint.endY;l.activeObj.activePoint.endY=l.activeObj.activePoint.startY,l.activeObj.activePoint.startY=v,this.dragElement=l.upperCanvas.style.cursor=l.cursor="ne-resize"}this.preventDraggingInvertly()}else if(l.activeObj.activePoint.endX>t&&l.activeObj.activePoint.endY>i){r=l.activeObj.activePoint.endX-t,n=l.activeObj.activePoint.endY-i,a=Math.min(r,n);var u=this.getScaleRatio(a);l.activeObj.activePoint.endX-=u.x,l.activeObj.activePoint.endY-=u.y;var g=l.img.destLeft+l.img.destWidth<l.lowerCanvas.width?l.img.destLeft+l.img.destWidth:l.lowerCanvas.width,b=l.img.destTop+l.img.destHeight<l.lowerCanvas.height?l.img.destTop+l.img.destHeight:l.lowerCanvas.height;(l.activeObj.activePoint.endX>g||l.activeObj.activePoint.endY>b)&&(l.activeObj.activePoint.endX+=u.x,l.activeObj.activePoint.endY+=u.y)}else{r=t-l.activeObj.activePoint.endX,n=i-l.activeObj.activePoint.endY,a=Math.max(r,n);u=this.getScaleRatio(a);l.activeObj.activePoint.endX+=u.x,l.activeObj.activePoint.endY+=u.y;g=l.img.destLeft+l.img.destWidth<l.lowerCanvas.width?l.img.destLeft+l.img.destWidth:l.lowerCanvas.width,b=l.img.destTop+l.img.destHeight<l.lowerCanvas.height?l.img.destTop+l.img.destHeight:l.lowerCanvas.height;(l.activeObj.activePoint.endX>g||l.activeObj.activePoint.endY>b)&&(l.activeObj.activePoint.endX-=u.x,l.activeObj.activePoint.endY-=u.y)}l.activeObj.activePoint.width=l.activeObj.activePoint.endX-l.activeObj.activePoint.startX,l.activeObj.activePoint.height=l.activeObj.activePoint.endY-l.activeObj.activePoint.startY,this.preventInverseResize(c)}},o.prototype.adjustNWPoints=function(t,e,i,o){var r=t.startX+t.width/2,n=t.startY+t.height/2,a=this.rotatePoints(t.endX,t.endY,r,n,o),s=[(a[0]+e)/2,(a[1]+i)/2],l=this.rotatePoints(a[0],a[1],s[0],s[1],-o),p=this.rotatePoints(e,i,s[0],s[1],-o);return t.endX=l[0],t.endY=l[1],t.startY=p[1],t.startX=p[0],t.width=t.endX-t.startX,t.height=t.endY-t.startY,t},o.prototype.adjustNEPoints=function(t,e,i,o){var r=t.startX+t.width/2,n=t.startY+t.height/2,a=this.rotatePoints(t.startX,t.endY,r,n,o),s=[(a[0]+e)/2,(a[1]+i)/2],l=this.rotatePoints(a[0],a[1],s[0],s[1],-o),p=this.rotatePoints(e,i,s[0],s[1],-o);return t.startX=l[0],t.endY=l[1],t.width=p[0]-l[0],t.height=l[1]-p[1],t.endX=t.startX+t.width,t.startY=t.endY-t.height,t},o.prototype.adjustSWPoints=function(t,e,i,o){var r=t.startX+t.width/2,n=t.startY+t.height/2,a=this.rotatePoints(t.endX,t.startY,r,n,o),s=[(a[0]+e)/2,(a[1]+i)/2],l=this.rotatePoints(a[0],a[1],s[0],s[1],-o),p=this.rotatePoints(e,i,s[0],s[1],-o);return t.endX=l[0],t.startY=l[1],t.startX=p[0],t.endY=p[1],t.width=t.endX-t.startX,t.height=t.endY-t.startY,t},o.prototype.adjustSEPoints=function(t,e,i,o){var r=t.startX+t.width/2,n=t.startY+t.height/2,a=this.rotatePoints(t.startX,t.startY,r,n,o),s=[(a[0]+e)/2,(a[1]+i)/2],l=this.rotatePoints(a[0],a[1],s[0],s[1],-o),p=this.rotatePoints(e,i,s[0],s[1],-o);return t.startX=l[0],t.startY=l[1],t.width=p[0]-l[0],t.height=p[1]-l[1],t.endX=t.startX+t.width,t.endY=t.startY+t.height,t},o.prototype.adjustRotationPoints=function(t,e,i,o){var r=t.startX+t.width/2,n=t.startY+t.height/2;this.getResizeDirection(t,e,i,o);var a=this.rotatePoints(t.startX,t.startY,r,n,o),s=this.rotatePoints(t.endX,t.startY,r,n,o),l=this.rotatePoints(t.endX,t.endY,r,n,o),p=this.rotatePoints(t.startX,t.endY,r,n,o),h=[(a[0]+l[0])/2,(a[1]+l[1])/2],c=this.rotatePoints(a[0],a[1],h[0],h[1],-o),d=this.rotatePoints(p[0],p[1],h[0],h[1],-o),v=this.rotatePoints(s[0],s[1],h[0],h[1],-o);return t.startX=c[0],t.startY=c[1],t.endX=v[0],t.endY=d[1],t.width=t.endX-t.startX,t.height=t.endY-t.startY,t},o.prototype.rotatePoints=function(t,e,i,o,r){return[(t-i)*Math.cos(r)-(e-o)*Math.sin(r)+i,(t-i)*Math.sin(r)+(e-o)*Math.cos(r)+o]},o.prototype.setResizedValue=function(t,e,i,o){switch(t){case"x":e+=i;break;case"y":e+=o;break;case"abs-x":e+=i>0?-i:Math.abs(i);break;case"abs-y":e+=o>0?-o:Math.abs(o);break;case"y-abs-x":e+=o+(i>0?-i:Math.abs(i))/2;break;case"abs-x-abs-y":e+=(i>0?-i:Math.abs(i))+(o>0?-o:Math.abs(o))/2;break;case"abs-y-x":e+=(o>0?-o:Math.abs(o))+i/2;break;case"x-y":e+=i+o/2}return e},o.prototype.getResizeDirection=function(t,e,i,o){var r=o*(180/Math.PI),n=this.getResizedElement(r,this.resizedElement);"e-resize"===this.resizedElement?(t.width=this.setResizedValue(n,t.width,e,i),t.endX=t.width+t.startX):"n-resize"===this.resizedElement?(t.startY=this.setResizedValue(n,t.startY,e,i),t.height=t.endY-t.startY):"w-resize"===this.resizedElement?(t.startX=this.setResizedValue(n,t.startX,e,i),t.width=t.startX+t.endX):"s-resize"===this.resizedElement&&(t.height=this.setResizedValue(n,t.height,e,i),t.endY=t.height+t.startY)},o.prototype.getResizedElement=function(t,e){var i=[];"n-resize"===e?i=[[337.5,360,"y"],[0,22.5,"y"],[22.5,67.5,"y-abs-x"],[67.5,112.5,"abs-x"],[112.5,157.5,"abs-x-abs-y"],[157.5,202.5,"abs-y"],[202.5,247.5,"abs-y-x"],[247.5,292.5,"x"],[292.5,337.5,"x-y"]]:"e-resize"===e?i=[[337.5,360,"x"],[0,22.5,"x"],[22.5,67.5,"x-y"],[67.5,112.5,"y"],[112.5,157.5,"y-abs-x"],[157.5,202.5,"abs-x"],[202.5,247.5,"abs-x-abs-y"],[247.5,292.5,"abs-y"],[292.5,337.5,"abs-y-x"]]:"s-resize"===e?i=[[337.5,360,"y"],[0,22.5,"y"],[22.5,67.5,"y-abs-x"],[67.5,112.5,"abs-x"],[112.5,157.5,"abs-x-abs-y"],[157.5,202.5,"abs-y"],[202.5,247.5,"abs-y-x"],[247.5,292.5,"x"],[292.5,337.5,"x-y"]]:"w-resize"===e&&(i=[[337.5,360,"x"],[0,22.5,"x"],[22.5,67.5,"x-y"],[67.5,112.5,"y"],[112.5,157.5,"y-abs-x"],[157.5,202.5,"abs-x"],[202.5,247.5,"abs-x-abs-y"],[247.5,292.5,"abs-y"],[292.5,337.5,"abs-y-x"]]);for(var o=t<0?360-Math.abs(t):t,r=0,n=i;r<n.length;r++){var a=n[r],s=a[0],l=a[1],p=a[2];if(o>s&&o<=l||o+360>s&&o+360<=l)return p}return e},o.prototype.updateCursorStyles=function(t,i,o){var r=this.parent,n=!1;""===r.activeObj.keyHistory||void 0!==r.activeObj.shape||r.currObjType.isCustomCrop||r.currObjType.isLine||!r.currObjType.isText||(r.activeObj.shape="text");var a=e.extend({},r.activeObj,{},!0);if(!e.isNullOrUndefined(a.topLeftCircle)){var s;if((s=0===a.shapeDegree?r.transform.degree:r.transform.degree-a.shapeDegree)<0&&(s=360+s),this.isObjSelected)if("line"===a.shape||"arrow"===a.shape)n=this.updateCursorStylesForLineArrow(t,i,a);else if("path"===a.shape)n=this.updateCursorStylesForPath(t,i,a);else if(a.rotatedAngle)this.setCursorForRotatedObject(a,t,i,r.upperCanvas),"grabbing"===r.cursor?(r.upperCanvas.style.cursor=this.parent.cursor="grabbing",this.dragElement=r.cursor):"move"===r.cursor?(this.dragPoint.startX=this.previousPoint.x=this.dragPoint.endX=t,this.dragPoint.startY=this.previousPoint.y=this.dragPoint.endY=i):"default"!==r.cursor&&(n=!0,this.dragElement=r.cursor,r.currObjType.isResize=!0);else{var l=this.getTransRotationPoint(a);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,r.upperCanvas.style.cursor=r.cursor="nw-resize",n=!0,this.dragElement=r.upperCanvas.style.cursor):t>=a.topLeftCircle.startX-2*a.topLeftCircle.radius&&t<=a.topRightCircle.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,r.upperCanvas.style.cursor=r.cursor="n-resize",n=!0,this.dragElement=r.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,r.upperCanvas.style.cursor=r.cursor="ne-resize",n=!0,this.dragElement=r.upperCanvas.style.cursor):t>=a.centerLeftCircle.startX-2*a.topLeftCircle.radius&&t<=a.centerLeftCircle.startX+2*a.topLeftCircle.radius&&i>=a.topLeftCircle.startY-2*a.topLeftCircle.radius&&i<=a.bottomLeftCircle.startY-2*a.topLeftCircle.radius&&"w-resize"!==this.dragElement?(a.centerLeftCircle.startX=a.centerLeftCircle.startY=0,r.upperCanvas.style.cursor=r.cursor="w-resize",n=!0,this.dragElement=r.upperCanvas.style.cursor):t>=a.centerRightCircle.startX-2*a.topLeftCircle.radius&&t<=a.centerRightCircle.startX+2*a.topLeftCircle.radius&&i>=a.topRightCircle.startY-2*a.topLeftCircle.radius&&i<=a.bottomRightCircle.startY-2*a.topLeftCircle.radius&&"e-resize"!==this.dragElement?(a.centerRightCircle.startX=a.centerRightCircle.startY=0,r.upperCanvas.style.cursor=r.cursor="e-resize",n=!0,this.dragElement=r.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,r.upperCanvas.style.cursor=r.cursor="sw-resize",n=!0,this.dragElement=r.upperCanvas.style.cursor):t>=a.bottomLeftCircle.startX-2*a.topLeftCircle.radius&&t<=a.bottomRightCircle.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,r.upperCanvas.style.cursor=r.cursor="s-resize",n=!0,this.dragElement=r.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,r.upperCanvas.style.cursor=r.cursor="se-resize",n=!0,this.dragElement=r.upperCanvas.style.cursor):!e.isNullOrUndefined(l)&&t>=l.x-2*a.topLeftCircle.radius&&t<=l.x+2*a.topLeftCircle.radius&&i>=l.y-2*a.topLeftCircle.radius&&i<=l.y+2*a.topLeftCircle.radius&&"grabbing"!==this.dragElement?(r.upperCanvas.style.cursor=r.cursor="grabbing",this.dragElement=r.upperCanvas.style.cursor):(this.dragPoint.startX=this.previousPoint.x=this.dragPoint.endX=t,this.dragPoint.startY=this.previousPoint.y=this.dragPoint.endY=i),"text"!==a.shape||"n-resize"!==r.cursor&&"s-resize"!==r.cursor&&"e-resize"!==r.cursor&&"w-resize"!==r.cursor||(r.upperCanvas.style.cursor=r.cursor="move",this.dragElement="",this.dragPoint.startX=this.previousPoint.x=this.dragPoint.endX=t,this.dragPoint.startY=this.previousPoint.y=this.dragPoint.endY=i)}else 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"===o?n||t>=a.activePoint.startX&&t<=a.activePoint.endX&&i>=a.activePoint.startY&&i<=a.activePoint.endY||"grabbing"===this.dragElement?r.currObjType.isDragging=!0:"line"===a.shape||"arrow"===a.shape?(this.setCursorForLineArrow(a,t,i,r.upperCanvas),"move"===r.cursor&&(r.currObjType.isDragging=!0)):"path"===a.shape&&(this.setCursorForPath(a,t,i,r.upperCanvas),"move"===r.cursor&&(r.currObjType.isDragging=!0)):r.currObjType.isDragging=!0,0===a.rotatedAngle||"e-resize"!==this.dragElement&&"w-resize"!==this.dragElement&&"n-resize"!==this.dragElement&&"s-resize"!==this.dragElement||(this.dragPoint.startX=this.previousPoint.x=this.dragPoint.endX=t,this.dragPoint.startY=this.previousPoint.y=this.dragPoint.endY=i)}},o.prototype.updateCursorStylesForLineArrow=function(t,e,i){for(var o,r=!1,n=this.parent,a=0;a<5;a++)if(o=i.pointColl[a],t>=o.x-2*i.topLeftCircle.radius&&t<=o.x+2*i.topLeftCircle.radius&&e>=o.y-2*i.topLeftCircle.radius&&e<=o.y+2*i.topLeftCircle.radius){i.centerLeftCircle.startX=i.centerLeftCircle.startY=0,this.dragElement="w-resize",r=!0;break}if(!r)for(a=1;a<6;a++)if(o=i.pointColl[i.pointColl.length-a],t>=o.x-2*i.topLeftCircle.radius&&t<=o.x+2*i.topLeftCircle.radius&&e>=o.y-2*i.topLeftCircle.radius&&e<=o.y+2*i.topLeftCircle.radius){i.centerRightCircle.startX=i.centerRightCircle.startY=0,this.dragElement="e-resize",r=!0;break}if(!r)for(a=0;a<i.pointColl.length;a++){if(o=i.pointColl[a],t>=o.x-2*i.topLeftCircle.radius&&t<=o.x+2*i.topLeftCircle.radius&&e>=o.y-2*i.topLeftCircle.radius&&e<=o.y+2*i.topLeftCircle.radius){n.upperCanvas.style.cursor=n.cursor="move",this.dragPoint.startX=this.previousPoint.x=this.dragPoint.endX=t,this.dragPoint.startY=this.previousPoint.y=this.dragPoint.endY=e;break}n.upperCanvas.style.cursor=n.cursor="default"}return r},o.prototype.updateCursorStylesForPath=function(t,e,i){var o=!1;return this.pathAdjustedIndex=this.setCursorForLineArrow(i,t,e,this.parent.upperCanvas),"move"===this.parent.cursor&&(o=!0,this.dragElement="pathDrag"),o||(this.parent.upperCanvas.style.cursor=this.parent.cursor="move",this.dragPoint.startX=this.previousPoint.x=this.dragPoint.endX=t,this.dragPoint.startY=this.previousPoint.y=this.dragPoint.endY=e),o},o.prototype.setTextSelection=function(t,e){var i=this.parent,o=i.transform.degree;(o=0===i.activeObj.shapeDegree?i.transform.degree:i.transform.degree-i.activeObj.shapeDegree)<0&&(o=360+o);for(var r=0,n=i.activeObj.flipObjColl.length;r<n;r++){var a=i.activeObj.flipObjColl[r].toLowerCase();switch(o){case 0:switch(a){case"horizontal":i.activeObj.activePoint={startX:i.activeObj.activePoint.endX-t,startY:i.activeObj.activePoint.startY,endX:i.activeObj.activePoint.endX,endY:i.activeObj.activePoint.startY+(e||0)};break;case"vertical":i.activeObj.activePoint.startY=i.activeObj.activePoint.endY-e,i.activeObj.activePoint={startX:i.activeObj.activePoint.startX,startY:i.activeObj.activePoint.startY,endX:i.activeObj.activePoint.startX+(t||0),endY:i.activeObj.activePoint.endY};break;default:i.activeObj.activePoint={startX:i.activeObj.activePoint.startX,startY:i.activeObj.activePoint.startY,endX:i.activeObj.activePoint.startX+(t||0),endY:i.activeObj.activePoint.startY+(e||0)}}break;case 90:switch(a){case"horizontal":i.activeObj.activePoint.endX=i.activeObj.activePoint.startX+e,i.activeObj.activePoint={startX:i.activeObj.activePoint.startX,startY:i.activeObj.activePoint.startY,endX:i.activeObj.activePoint.endX,endY:i.activeObj.activePoint.startY+(t||0)};break;case"vertical":i.activeObj.activePoint.startX=i.activeObj.activePoint.endX-e,i.activeObj.activePoint={startX:i.activeObj.activePoint.startX,startY:i.activeObj.activePoint.endY-t,endX:i.activeObj.activePoint.endX,endY:i.activeObj.activePoint.endY};break;default:i.activeObj.activePoint.startX=i.activeObj.activePoint.endX-e,i.activeObj.activePoint={startX:i.activeObj.activePoint.startX,startY:i.activeObj.activePoint.startY,endX:i.activeObj.activePoint.endX,endY:i.activeObj.activePoint.startY+(t||0)}}break;case 180:switch(a){case"horizontal":i.activeObj.activePoint.startY=i.activeObj.activePoint.endY-e,i.activeObj.activePoint={startX:i.activeObj.activePoint.startX,startY:i.activeObj.activePoint.startY,endX:i.activeObj.activePoint.startX+t,endY:i.activeObj.activePoint.endY};break;case"vertical":i.activeObj.activePoint.endY=i.activeObj.activePoint.startY+e,i.activeObj.activePoint={endX:i.activeObj.activePoint.endX,endY:i.activeObj.activePoint.endY,startX:i.activeObj.activePoint.endX-(t||0),startY:i.activeObj.activePoint.startY};break;default:i.activeObj.activePoint={endX:i.activeObj.activePoint.endX,endY:i.activeObj.activePoint.endY,startX:i.activeObj.activePoint.endX-(t||0),startY:i.activeObj.activePoint.endY-(e||0)}}break;case 270:switch(a){case"horizontal":i.activeObj.activePoint.startX=i.activeObj.activePoint.endX-e,i.activeObj.activePoint={startX:i.activeObj.activePoint.startX,startY:i.activeObj.activePoint.endY-(t||0),endX:i.activeObj.activePoint.endX,endY:i.activeObj.activePoint.endY};break;case"vertical":i.activeObj.activePoint={startX:i.activeObj.activePoint.startX,startY:i.activeObj.activePoint.startY,endX:i.activeObj.activePoint.startX+e,endY:i.activeObj.activePoint.startY+(t||0)};break;default:i.activeObj.activePoint.endX=i.activeObj.activePoint.startX+e,i.activeObj.activePoint={startX:i.activeObj.activePoint.startX,startY:i.activeObj.activePoint.endY-(t||0),endX:i.activeObj.activePoint.endX,endY:i.activeObj.activePoint.endY}}}}if(0===i.activeObj.flipObjColl.length)switch(o){case 0:i.activeObj.activePoint={startX:i.activeObj.activePoint.startX,startY:i.activeObj.activePoint.startY,endX:i.activeObj.activePoint.startX+(t||0),endY:i.activeObj.activePoint.startY+(e||0)};break;case 90:i.activeObj.activePoint.startX=i.activeObj.activePoint.endX-e,i.activeObj.activePoint={startX:i.activeObj.activePoint.startX,startY:i.activeObj.activePoint.startY,endX:i.activeObj.activePoint.endX,endY:i.activeObj.activePoint.startY+(t||0)};break;case 180:i.activeObj.activePoint={endX:i.activeObj.activePoint.endX,endY:i.activeObj.activePoint.endY,startX:i.activeObj.activePoint.endX-(t||0),startY:i.activeObj.activePoint.endY-(e||0)};break;case 270:i.activeObj.activePoint.endX=i.activeObj.activePoint.startX+e,i.activeObj.activePoint={startX:i.activeObj.activePoint.startX,startY:i.activeObj.activePoint.endY-(t||0),endX:i.activeObj.activePoint.endX,endY:i.activeObj.activePoint.endY}}i.activeObj.activePoint.width=i.activeObj.activePoint.endX-i.activeObj.activePoint.startX,i.activeObj.activePoint.height=i.activeObj.activePoint.endY-i.activeObj.activePoint.startY,360!==i.transform.degree&&-360!==i.transform.degree||(i.transform.degree=0)},o.prototype.setActivePoint=function(t,i){var o=this.parent;if(!e.isNullOrUndefined(o.activeObj.activePoint))if(o.currObjType.isText){var r=t||0,n=i||o.activeObj.textSettings.fontSize;void 0===o.activeObj.textSettings.fontSize&&(o.activeObj.textSettings.fontSize=.1*Math.abs(o.baseImg.width-o.baseImg.height)),this.setTextSelection(r,n),this.mouseDownPoint.x=o.activeObj.activePoint.endX,this.mouseDownPoint.y=o.activeObj.activePoint.endY,void 0!==o.activeObj.horTopLine&&(o.activeObj.activePoint=e.extend({},o.activeObj.activePoint,{},!0)),o.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate"}})}else if(t&&i)o.activeObj.activePoint.startX=this.mouseDownPoint.x=t,o.activeObj.activePoint.startY=this.mouseDownPoint.y=i,o.currObjType.isDragging=!0;else{var a=o.activeObj;o.activeObj.activePoint={startX:a.horTopLine.startX,startY:a.horTopLine.startY,endX:a.horTopLine.endX,endY:a.horTopLine.endY},o.activeObj.activePoint.width=o.activeObj.activePoint.endX-o.activeObj.activePoint.startX,o.activeObj.activePoint.height=o.activeObj.activePoint.endY-o.activeObj.activePoint.startY}},o.prototype.mouseDownEventHandler=function(t){var i=this,o=this.parent;if("touchstart"===t.type?this.isTouch=!0:this.isTouch=!1,"touchstart"!==t.type||t.currentTarget!==o.lowerCanvas||o.isImageLoaded){this.isCropSelection=!1,this.isPan=!0;var r;void 0!==o.activeObj.shape&&(r=o.activeObj.shape.split("-")),void 0!==r&&"crop"===r[0]&&(this.isCropSelection=!0),this.isCropSelection&&(this.dragCanvas=o.togglePan=!0);var n={point:this.setXYPoints(t)};e.isBlazor()&&!e.isNullOrUndefined(o.events)&&!0===o.events.clicked.hasDelegate?o.dotNetRef.invokeMethodAsync("ClickEventAsync","click",n).then(function(e){i.clickEvent(e,t)}):(o.trigger("click",n),this.clickEvent(n,t))}},o.prototype.getImagePoints=function(t,e){var i=this.parent;return t<i.img.destLeft?t=i.img.destLeft:t>i.img.destLeft+i.img.destWidth&&(t=i.img.destLeft+i.img.destWidth),e<i.img.destTop?e=i.img.destTop:e>i.img.destTop+i.img.destHeight&&(e=i.img.destTop+i.img.destHeight),{x:t,y:e}},o.prototype.clickEvent=function(t,i){var o=this.parent,r=t.point.x,n=t.point.y,a=e.isNullOrUndefined(o.activeObj.shape)||"text"!==o.activeObj.shape?"default":o.cursor;if(""!==this.currentDrawingShape){var s={currObj:{}};o.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:s}}),this.initialPrevObj=s.currObj,this.initialPrevObj.objColl=e.extend([],o.objColl,[],!0),this.initialPrevObj.pointColl=e.extend([],o.pointColl,[],!0),this.initialPrevObj.afterCropActions=e.extend([],o.afterCropActions,[],!0);var l={selPointColl:null};if(o.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:l}}),this.initialPrevObj.selPointColl=e.extend([],l.selPointColl,[],!0),this.setActivePoint(r,n),"path"===this.currentDrawingShape){var p=this.getImagePoints(r,n);o.activeObj.pointColl.push({x:p.x,y:p.y}),0!==o.activeObj.activePoint.width&&0!==o.activeObj.activePoint.height&&(o.activeObj.activePoint.width=0,o.activeObj.activePoint.height=0,o.activeObj.activePoint.startX=o.activeObj.pointColl[o.activeObj.pointColl.length-1].x,o.activeObj.activePoint.startY=o.activeObj.pointColl[o.activeObj.pointColl.length-1].y)}return o.activeObj.activePoint.endX=o.activeObj.activePoint.startX,o.activeObj.activePoint.endY=o.activeObj.activePoint.startY,void(o.currObjType.isDragging=!0)}this.isCropSelection&&this.dragCanvas&&(this.setCursor(r,n),"move"!==o.cursor&&"crosshair"!==o.cursor&&"default"!==o.cursor&&"grab"!==o.cursor&&(this.isPan=!1)),e.isNullOrUndefined(o.activeObj.shape)?this.isObjSelected=!1:this.isObjSelected=!0;var h={currObj:{}};o.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:h}});var c=h.currObj,d=e.extend({},o.activeObj,null,!0),v=this.isShapeTouch(i,this.isCropSelection),u=this.isFreehandDrawTouch(i,this.isCropSelection),g=v||this.isShapeClick(i,this.isCropSelection),b=this.applyCurrShape(g);if(this.isTouch&&!v&&!e.isNullOrUndefined(d.shape)&&!this.isCropSelection){this.applyObj(r,n)&&(o.okBtn(!0),o.notify("draw",{prop:"setPrevActObj",onPropertyChange:!1,value:{prevActObj:null}}));var C=e.extend({},o.cropObj,{},!0);o.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"shapeTransform",previousObj:c,previousObjColl:c.objColl,previousPointColl:c.pointColl,previousSelPointColl:c.selPointColl,previousCropObj:C,previousText:null,currentText:null,previousFilter:null,isCircleCrop:o.isCircleCrop}}),b&&o.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"ok"}})}if(v||o.togglePen||this.isCropSelection||(e.isBlazor()?o.isImageLoaded&&o.updateToolbar(o.element,"imageLoaded","okBtnClick"):(o.notify("toolbar",{prop:"refresh-main-toolbar",onPropertyChange:!1}),o.notify("toolbar",{prop:"close-contextual-toolbar",onPropertyChange:!1}))),!this.dragCanvas||!this.isPan||"grab"!==o.cursor&&!this.isTouch||v||u||o.togglePen){var f=!1;e.isNullOrUndefined(o.activeObj.shape)||"line"!==o.activeObj.shape&&"arrow"!==o.activeObj.shape||(f=!0);var m=this.setXYPoints(i),y=m.x,P=m.y;this.applyObj(y,P)&&(o.okBtn(!0),b&&o.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"ok"}}),o.notify("draw",{prop:"setPrevActObj",onPropertyChange:!1,value:{prevActObj:null}})),o.notify("shape",{prop:"redrawActObj",onPropertyChange:!1,value:{x:y,y:P,isMouseDown:!0}});var j={index:null};o.notify("freehand-draw",{prop:"getFreehandDrawHoveredIndex",onPropertyChange:!1,value:{obj:j}});var O={freehandSelectedIndex:null};if(o.notify("freehand-draw",{prop:"getFreehandSelectedIndex",onPropertyChange:!1,value:{obj:O}}),this.isFhdPoint||this.isFhdCustomized&&!o.togglePen){if(!e.isNullOrUndefined(O.freehandSelectedIndex)&&O.freehandSelectedIndex!==j.index){var x=j.index;if(o.okBtn(),this.isFhdCustomized=!1,o.notify("freehand-draw",{prop:"setFreehandDrawHoveredIndex",onPropertyChange:!1,value:{index:x}}),j.index>-1){var w=o.pointColl[j.index].strokeColor;o.notify("freehand-draw",{prop:"hoverFhd",onPropertyChange:!1,value:{strokeColor:w,strokeWidth:o.pointColl[j.index].strokeWidth}})}}if(O.freehandSelectedIndex=null,o.notify("freehand-draw",{prop:"getFreehandSelectedIndex",onPropertyChange:!1,value:{obj:O}}),!e.isNullOrUndefined(j.index)&&j.index>-1)o.notify("freehand-draw",{prop:"selectFhd",value:{type:"ok"}}),e.isBlazor()?(o.updateToolbar(o.element,"pen"),o.updateToolbar(o.element,"quickAccessToolbar","pen")):o.notify("toolbar",{prop:"renderQAT",onPropertyChange:!1,value:{isPenEdit:!0}});else if(O.freehandSelectedIndex){o.okBtn();w=o.pointColl[O.freehandSelectedIndex].strokeColor;o.notify("freehand-draw",{prop:"hoverFhd",onPropertyChange:!1,value:{strokeColor:w,strokeWidth:o.pointColl[O.freehandSelectedIndex].strokeWidth}})}}else{if(this.isFhdEditing&&(o.notify("freehand-draw",{prop:"cancelFhd",value:{type:"ok"}}),e.isNullOrUndefined(document.getElementById(o.element.id+"_quickAccessToolbarArea"))||(document.getElementById(o.element.id+"_quickAccessToolbarArea").style.display="none")),e.isBlazor()||o.notify("toolbar",{prop:"close-contextual-toolbar",onPropertyChange:!1}),this.isFhdEditing=!1,f?this.setCursor(y,P):"default"!==a&&(o.upperCanvas.style.cursor=o.cursor=a),"crosshair"===o.cursor||e.Browser.isDevice&&o.togglePen){if(o.togglePen){if(e.isNullOrUndefined(o.activeObj.strokeSettings)){var S={strokeSettings:{}};o.notify("shape",{prop:"getStrokeSettings",onPropertyChange:!1,value:{obj:S}}),o.activeObj.strokeSettings=S.strokeSettings}var T={penStrokeWidth:null};o.notify("freehand-draw",{prop:"getPenStrokeWidth",onPropertyChange:!1,value:{obj:T}}),e.isNullOrUndefined(T.penStrokeWidth)&&o.notify("freehand-draw",{prop:"setPenStrokeWidth",onPropertyChange:!1,value:{value:2}}),this.upperContext.strokeStyle=o.activeObj.strokeSettings.strokeColor,this.upperContext.fillStyle=o.activeObj.strokeSettings.strokeColor,o.notify("freehand-draw",{prop:"freehandDownHandler",onPropertyChange:!1,value:{e:i,canvas:o.upperCanvas}})}else o.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),this.upperContext.clearRect(0,0,o.upperCanvas.width,o.upperCanvas.height);o.currObjType.isActiveObj=!1,this.dragElement="",this.dragPoint.startX=this.dragPoint.startY=this.dragPoint.endX=this.dragPoint.endY=0}"crosshair"!==o.cursor&&"touchstart"===i.type.toLowerCase()||o.currObjType.isActiveObj&&"default"!==o.cursor&&!o.togglePen?(o.currObjType.isUndoAction&&o.notify("undo-redo",{prop:"refreshUrc",value:{bool:null}}),this.findTarget(y,P,i.type)):""!==o.currObjType.shape&&!o.currObjType.isCustomCrop||o.togglePen||"default"===o.cursor||this.setActivePoint(y,P)}}else this.applyObj(r,n)&&(o.okBtn(!0),b&&o.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"ok"}}),o.notify("draw",{prop:"setPrevActObj",onPropertyChange:!1,value:{prevActObj:null}})),this.isFhdEditing&&(o.notify("freehand-draw",{prop:"applyFhd",onPropertyChange:!1}),e.isBlazor()||o.notify("toolbar",{prop:"destroy-qa-toolbar",onPropertyChange:!1})),e.isNullOrUndefined(o.activeObj.shape)||"rectangle"!==o.activeObj.shape&&"ellipse"!==o.activeObj.shape&&"line"!==o.activeObj.shape&&"arrow"!==o.activeObj.shape&&"path"!==o.activeObj.shape&&"text"!==o.activeObj.shape||(o.notify("shape",{prop:"redrawActObj",onPropertyChange:!1,value:{x:null,y:null,isMouseDown:null}}),o.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),e.isBlazor()?o.updateToolbar(o.element,"imageLoaded"):(o.notify("toolbar",{prop:"setCurrentToolbar",value:{type:"main"}}),o.notify("toolbar",{prop:"refresh-main-toolbar",onPropertyChange:!1}))),this.canvasMouseDownHandler(i);this.isShapeInserted=!1,this.tempActiveObj=e.extend({},o.activeObj,{},!0)},o.prototype.mouseMoveEventHandler=function(i){var o=this.parent,r=o.cursor,n=o.upperCanvas.style.cursor;i.preventDefault();var a=o.lowerCanvas.getBoundingClientRect();if("touchmove"!==i.type||2!==i.touches.length){var s,l;"mousemove"===i.type?(s=i.clientX,l=i.clientY):(this.touchEndPoint.x=s=i.touches[0].clientX,this.touchEndPoint.y=l=i.touches[0].clientY),s-=a.left,l-=a.top,this.canvasMouseMoveHandler(i);var p,h=!1;void 0!==o.activeObj.shape&&(p=o.activeObj.shape.split("-")),void 0!==p&&"crop"===p[0]&&(h=!0),h&&o.notify("transform",{prop:"disableZoomOutBtn",value:{isZoomOut:!0}}),o.upperCanvas.style.cursor=n,o.cursor=r,(o.currObjType.isActiveObj&&(void 0!==o.activeObj.activePoint||o.objColl.length>0)&&!this.dragCanvas||void 0!==o.activeObj.activePoint)&&""===this.dragElement&&(this.setCursor(s,l),e.isNullOrUndefined(o.activeObj.activePoint)||0!==o.activeObj.activePoint.width&&(e.isNullOrUndefined(o.activeObj.currIndex)||this.cursorTargetId===o.activeObj.currIndex)||"default"===o.cursor||"move"===o.cursor||"crosshair"===o.cursor||"grab"===o.cursor||"pointer"===o.cursor||(o.upperCanvas.style.cursor=o.cursor="move"),this.findTarget(s,l,i.type)),o.currObjType.isDragging&&(this.upperContext.clearRect(0,0,o.lowerCanvas.width,o.lowerCanvas.height),this.updateActivePoint(s,l,h),o.notify("shape",{prop:"updateTrianglePoints",onPropertyChange:!1,value:{obj:o.activeObj}}),this.isPreventDragging?(o.activeObj.activePoint.startX>o.img.destLeft&&o.activeObj.activePoint.endX<o.img.destLeft+o.img.destWidth&&o.activeObj.activePoint.startY>o.img.destTop&&o.activeObj.activePoint.endY<o.img.destTop+o.img.destHeight&&(this.isPreventDragging=!1),o.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate",obj:null,isCropRatio:null,points:null,isPreventDrag:!0,saveContext:null,isPreventSelection:null}})):o.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate",obj:null,isCropRatio:null,points:null,isPreventDrag:null,saveContext:null,isPreventSelection:null}}),h&&(this.dragCanvas=o.togglePan=!0))}else{if(this.isFirstMove)this.startTouches=this.targetTouches(i.touches),this.tempTouches=[],this.tempTouches.push({x:i.touches[0].clientX||i.touches[0].pageX-o.lowerCanvas.offsetLeft-a.left,y:(i.touches[0].clientY||i.touches[0].pageY-o.lowerCanvas.offsetTop)-a.top}),this.tempTouches.push({x:(i.touches[1].clientX||i.touches[1].pageX-o.lowerCanvas.offsetLeft)-a.left,y:(i.touches[1].clientY||i.touches[1].pageY-o.lowerCanvas.offsetTop)-a.top});else{var c=(i.touches[0].clientX||i.touches[0].pageX-o.lowerCanvas.offsetLeft)-a.left,d=(i.touches[0].clientY||i.touches[0].pageY-o.lowerCanvas.offsetTop)-a.top,v=(i.touches[1].clientX||i.touches[1].pageX-o.lowerCanvas.offsetLeft)-a.left,u=(i.touches[1].clientY||i.touches[1].pageY-o.lowerCanvas.offsetTop)-a.top,g={x:c<v?v-(v-c)/2:c-(c-v)/2,y:d<u?u-(u-d)/2:d-(d-u)/2};if(this.currMousePoint.x!==g.x&&this.currMousePoint.y!==g.y){var b="";if("touchmove"===i.type&&(o.zoomSettings.zoomTrigger&t.ZoomTrigger.Pinch)===t.ZoomTrigger.Pinch){this.zoomType="Pinch";var C=this.calculateScale(this.startTouches,this.targetTouches(i.touches));this.startTouches=this.targetTouches(i.touches),C>1?b="zoomIn":C<1&&(b="zoomOut")}""!==b&&o.notify("draw",{prop:"performPointZoom",onPropertyChange:!1,value:{x:g.x,y:g.y,type:b}}),this.tempTouches=[],this.tempTouches.push({x:i.touches[0].clientX||i.touches[0].pageX-o.lowerCanvas.offsetLeft,y:i.touches[0].clientY||i.touches[0].pageY-o.lowerCanvas.offsetTop}),this.tempTouches.push({x:i.touches[1].clientX||i.touches[1].pageX-o.lowerCanvas.offsetLeft,y:i.touches[1].clientY||i.touches[1].pageY-o.lowerCanvas.offsetTop}),this.currMousePoint.x=g.x,this.currMousePoint.y=g.y}}this.isFirstMove=!1}},o.prototype.mouseUpEventHandler=function(t){var i=this,o=this.parent;"touchstart"===t.type?this.isTouch=!1:"touchend"===t.type&&t.stopImmediatePropagation(),t.preventDefault(),o.togglePan&&this.canvasMouseUpHandler(t);var r,n;"mouseup"===t.type?(r=t.clientX,n=t.clientY):(r=this.touchEndPoint.x,n=this.touchEndPoint.y);var a=o.lowerCanvas.getBoundingClientRect();r-=a.left,n-=a.top,"touchend"===t.type&&(this.startTouches=this.tempTouches=[],this.isFirstMove=!1,"none"===o.textArea.style.display&&(this.timer=0));var s,l=!1;if(void 0!==o.activeObj.shape&&(s=o.activeObj.shape.split("-")),void 0!==s&&"crop"===s[0]&&(l=!0),e.isBlazor()&&!e.isNullOrUndefined(this.parent.eventType)){if("pan"===this.parent.eventType)e.isNullOrUndefined(o.events)||!0!==o.events.onPanEnd.hasDelegate||o.dotNetRef.invokeMethodAsync("PanEventAsync","OnPanEnd",this.parent.panEventArgs);else if("resize"===this.parent.eventType)if(this.isCropSelection||e.isNullOrUndefined(this.parent.events)||!0!==this.parent.events.onShapeResizeEnd.hasDelegate){if(!e.isNullOrUndefined(this.shapeResizingArgs)&&!e.isNullOrUndefined(this.selectionResizingArgs)&&!e.isNullOrUndefined(this.parent.events)&&!0===this.parent.events.onSelectionResizeEnd.hasDelegate){var p={type:this.parent.activeObj.shape,startX:this.shapeResizingArgs.currentShapeSettings.startX,startY:this.shapeResizingArgs.currentShapeSettings.startY,width:this.shapeResizingArgs.currentShapeSettings.width,height:this.shapeResizingArgs.currentShapeSettings.height};this.selectionResizingArgs.currentSelectionSettings=p,this.selectionResizingArgs.action="resize-end",this.parent.dotNetRef.invokeMethodAsync("SelectionEventAsync","OnSelectionResizeEnd",this.selectionResizingArgs).then(function(t){i.parent.notify("shape",{prop:"updateSelectionChangeEventArgs",onPropertyChange:!1,value:{selectionSettings:t.currentSelectionSettings}})})}}else this.shapeResizingArgs.currentShapeSettings=this.updatePrevShapeSettings(),this.shapeResizingArgs.action="resize-end",this.parent.dotNetRef.invokeMethodAsync("ShapeEventAsync","OnShapeResizeEnd",this.shapeResizingArgs).then(function(t){i.parent.notify("shape",{prop:"updateShapeChangeEventArgs",onPropertyChange:!1,value:{shapeSettings:t.currentShapeSettings}})});else e.isNullOrUndefined(this.shapeMovingArgs)||e.isNullOrUndefined(this.parent.events)||!0!==this.parent.events.onShapeDragEnd.hasDelegate||(this.shapeMovingArgs.currentShapeSettings=this.updatePrevShapeSettings(),this.shapeMovingArgs.action="drag-end",this.parent.dotNetRef.invokeMethodAsync("ShapeEventAsync","OnShapeDragEnd",this.shapeMovingArgs).then(function(t){i.parent.notify("shape",{prop:"updateShapeChangeEventArgs",onPropertyChange:!1,value:{shapeSettings:t.currentShapeSettings}})}));this.shapeResizingArgs=null,this.shapeMovingArgs=null,this.parent.panEventArgs=null,this.parent.eventType=null}if("path"!==this.currentDrawingShape){if(t.currentTarget===o.upperCanvas){if(this.pathAdjustedIndex=null,""!==this.currentDrawingShape){if("text"===this.currentDrawingShape){var h=e.extend({},o.cropObj,{},!0);o.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"shapeTransform",previousObj:this.initialPrevObj,previousObjColl:this.initialPrevObj.objColl,previousPointColl:this.initialPrevObj.pointColl,previousSelPointColl:this.initialPrevObj.selPointColl,previousCropObj:h,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}})}else o.notify("undo-redo",{prop:"updateUrObj",onPropertyChange:!1,value:{objColl:this.initialPrevObj.objColl}});this.isShapeInserted=!0,this.currentDrawingShape="",0===o.activeObj.activePoint.width&&0===o.activeObj.activePoint.height&&o.notify("draw",{prop:"performCancel",value:{isContextualToolbar:null}})}this.adjustActObjForLineArrow(),this.updPtCollForShpRot(),o.currObjType.shape=o.currObjType.shape.toLowerCase();var c=e.extend({},o.cropObj,{},!0),d={currObj:{}};o.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:d}});var v=d.currObj;v.objColl=e.extend([],o.objColl,[],!0),v.pointColl=e.extend([],o.pointColl,[],!0),v.afterCropActions=e.extend([],o.afterCropActions,[],!0);var u={selPointColl:null};if(o.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:u}}),v.selPointColl=e.extend([],u.selPointColl,[],!0),o.togglePen||l||(e.isNullOrUndefined(this.tempObjColl)||0===o.activeObj.activePoint.width||(o.objColl.push(o.activeObj),JSON.stringify(o.activeObj.activePoint)!==JSON.stringify(this.tempActiveObj.activePoint)&&o.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"shapeTransform",previousObj:v,previousObjColl:this.tempObjColl,previousPointColl:v.pointColl,previousSelPointColl:v.selPointColl,previousCropObj:c,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),this.redrawShape(o.objColl[o.objColl.length-1],!0),this.tempObjColl=void 0),this.isFhdEditing||(this.applyCurrActObj(r,n),o.currObjType.isResize=!1)),!e.isNullOrUndefined(o.activeObj)){var g,b=!1;if(void 0!==o.activeObj.shape&&(g=o.activeObj.shape.split("-")),void 0===g&&(o.currObjType.isCustomCrop||o.togglePen)?b=!0:void 0!==g&&"crop"===g[0]&&(b=!0),e.isBlazor())"rectangle"===o.activeObj.shape||"ellipse"===o.activeObj.shape||"line"===o.activeObj.shape||"arrow"===o.activeObj.shape||"path"===o.activeObj.shape?o.updateToolbar(o.element,o.activeObj.shape):"text"===o.activeObj.shape&&o.updateToolbar(o.element,"text");else{if("rectangle"===o.activeObj.shape||"ellipse"===o.activeObj.shape||"line"===o.activeObj.shape||"arrow"===o.activeObj.shape||"path"===o.activeObj.shape)o.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"shapes",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}});else if("text"===o.activeObj.shape)o.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"text",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}});else if(this.isFhdEditing)o.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"pen",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}});else if(!b){o.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"main",isApplyBtn:null,isCropping:!1,isZooming:null}})}o.notify("toolbar",{prop:"update-toolbar-items",onPropertyChange:!1})}}}void 0!==o.activeObj.shape&&(s=o.activeObj.shape.split("-")),void 0!==s&&"crop"===s[0]&&(l=!0),e.isNullOrUndefined(o.activeObj.shape)||l||t.currentTarget!==o.upperCanvas||"none"!==o.textArea.style.display||("text"===o.activeObj.shape?e.isBlazor()||o.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"text",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}}):e.isBlazor()||o.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"shapes",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}}),e.isBlazor()?o.updateToolbar(o.element,"quickAccessToolbar",o.activeObj.shape):(o.notify("toolbar",{prop:"update-toolbar-items",onPropertyChange:!1}),o.notify("toolbar",{prop:"renderQAT",onPropertyChange:!1,value:{isPenEdit:null}}))),o.togglePen&&t.currentTarget===o.upperCanvas?o.notify("freehand-draw",{prop:"freehandUpHandler",onPropertyChange:!1,value:{e:t,canvas:o.upperCanvas,context:this.upperContext}}):o.currObjType.shape="",this.dragElement="",o.currObjType.isInitialLine=o.currObjType.isDragging=!1,this.selMouseUpEvent()}},o.prototype.adjustActObjForLineArrow=function(t){var i=!1,o=this.parent;if(t=t||o.activeObj,!e.isNullOrUndefined(t.shape)&&("line"===t.shape||"arrow"===o.activeObj.shape)){var r=void 0;if(("e-resize"===this.dragElement&&t.activePoint.endX<t.activePoint.startX||"w-resize"===this.dragElement&&t.activePoint.startX>t.activePoint.endX)&&(i=!0,r=t.activePoint.startX,t.activePoint.startX=t.activePoint.endX,t.activePoint.endX=r,r=t.activePoint.startY,t.activePoint.startY=t.activePoint.endY,t.activePoint.endY=r),t.activePoint.width=Math.abs(t.activePoint.endX-t.activePoint.startX),t.activePoint.height=Math.abs(t.activePoint.endY-t.activePoint.startY),"path"!==o.activeObj.shape){o.notify("shape",{prop:"setPointCollForLineArrow",onPropertyChange:!1,value:{obj:t}});for(var n=0;n<t.pointColl.length;n++)t.pointColl[n].ratioX=(t.pointColl[n].x-o.img.destLeft)/o.img.destWidth,t.pointColl[n].ratioY=(t.pointColl[n].y-o.img.destTop)/o.img.destHeight}}return i},o.prototype.updPtCollForShpRot=function(t){var i=this.parent;if(t=t||i.activeObj,!e.isNullOrUndefined(t.shape)&&0!==t.rotatedAngle){i.notify("shape",{prop:"setPointCollForShapeRotation",onPropertyChange:!1,value:{obj:t}});for(var o=0;o<t.horTopLinePointColl.length;o++)t.horTopLinePointColl[o].ratioX=(t.horTopLinePointColl[o].x-i.img.destLeft)/i.img.destWidth,t.horTopLinePointColl[o].ratioY=(t.horTopLinePointColl[o].y-i.img.destTop)/i.img.destHeight;for(o=0;o<t.horBottomLinePointColl.length;o++)t.horBottomLinePointColl[o].ratioX=(t.horBottomLinePointColl[o].x-i.img.destLeft)/i.img.destWidth,t.horBottomLinePointColl[o].ratioY=(t.horBottomLinePointColl[o].y-i.img.destTop)/i.img.destHeight;for(o=0;o<t.verLeftLinePointColl.length;o++)t.verLeftLinePointColl[o].ratioX=(t.verLeftLinePointColl[o].x-i.img.destLeft)/i.img.destWidth,t.verLeftLinePointColl[o].ratioY=(t.verLeftLinePointColl[o].y-i.img.destTop)/i.img.destHeight;for(o=0;o<t.verRightLinePointColl.length;o++)t.verRightLinePointColl[o].ratioX=(t.verRightLinePointColl[o].x-i.img.destLeft)/i.img.destWidth,t.verRightLinePointColl[o].ratioY=(t.verRightLinePointColl[o].y-i.img.destTop)/i.img.destHeight}},o.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 o=this.parent.lowerCanvas.getBoundingClientRect();return e-=o.left,i-=o.top,{x:e,y:i}},o.prototype.getCurrentIndex=function(){for(var t,e=this.parent,i=0;i<e.objColl.length;i++)if(e.activeObj.currIndex===e.objColl[i].currIndex){t=i;break}return t},o.prototype.isShapeClick=function(t,i){var o=this.parent,r=!1;if(o.togglePen)return r;if(!e.isNullOrUndefined(o.activeObj.shape)&&"text"===o.activeObj.shape&&this.isShapeInserted){var n="block"===o.textArea.style.display,a=e.extend({},o.activeObj,null,!0);o.notify("shape",{prop:"redrawActObj",onPropertyChange:!1,value:{x:null,y:null,isMouseDown:!0}});var s=this.setXYPoints(t),l=s.x,p=s.y;if(r=this.findTargetObj(l,p,i),i||this.upperContext.clearRect(0,0,o.upperCanvas.width,o.upperCanvas.height),n){o.textArea.value=o.objColl[o.objColl.length-1].keyHistory,o.textArea.style.display="block",o.activeObj=a;var h=this.getCurrentIndex();e.isNullOrUndefined(h)?o.objColl.pop():o.objColl.splice(h,1)}else if(!r&&!e.isNullOrUndefined(a.shape)){o.activeObj=a;h=this.getCurrentIndex();e.isNullOrUndefined(h)||JSON.stringify(o.activeObj.activePoint)!==JSON.stringify(o.objColl[h].activePoint)?e.isNullOrUndefined(o.activeObj.currIndex)&&o.objColl.pop():o.objColl.splice(h,1)}}return r},o.prototype.isShapeTouch=function(t,i){var o=this.parent,r=!1;if("touchstart"===t.type&&!o.togglePen){e.isNullOrUndefined(o.activeObj)||"text"!==o.activeObj.shape||(this.timer=setTimeout(this.setTimer.bind(this),1e3,t));var n="block"===o.textArea.style.display,a=e.extend({},o.activeObj,null,!0);o.notify("shape",{prop:"redrawActObj",onPropertyChange:!1,value:{x:null,y:null,isMouseDown:!0}});var s=this.setXYPoints(t),l=s.x,p=s.y;if(r=this.findTargetObj(l,p,i),i||this.upperContext.clearRect(0,0,o.upperCanvas.width,o.upperCanvas.height),n){o.textArea.value=o.objColl[o.objColl.length-1].keyHistory,o.textArea.style.display="block",o.activeObj=a;var h=this.getCurrentIndex();e.isNullOrUndefined(h)?o.objColl.pop():o.objColl.splice(h,1)}else if(!r&&a.shape){o.activeObj=a;h=this.getCurrentIndex();i||(e.isNullOrUndefined(h)||JSON.stringify(o.activeObj.activePoint)!==JSON.stringify(o.objColl[h].activePoint)?e.isNullOrUndefined(o.activeObj.currIndex)&&o.objColl.pop():o.objColl.splice(h,1))}}return r},o.prototype.isFreehandDrawTouch=function(t,i){var o=this.parent,r=!1;if("touchstart"===t.type&&!i&&!o.togglePen){var n="block"===o.textArea.style.display,a=e.extend({},o.activeObj,null,!0);o.notify("shape",{prop:"redrawActObj",onPropertyChange:!1,value:{x:null,y:null,isMouseDown:!0}});var s=this.setXYPoints(t),l=s.x,p=s.y;if(this.setCursor(l,p),this.isFhdPoint&&(r=!0),n){o.textArea.value=o.objColl[o.objColl.length-1].keyHistory,o.textArea.style.display="block",o.activeObj=a;var h=this.getCurrentIndex();e.isNullOrUndefined(h)?o.objColl.pop():o.objColl.splice(h,1)}else if(!e.isNullOrUndefined(a.shape)){o.activeObj=a;h=this.getCurrentIndex();i||(e.isNullOrUndefined(h)||JSON.stringify(o.activeObj.activePoint)!==JSON.stringify(o.objColl[h].activePoint)?e.isNullOrUndefined(o.activeObj.currIndex)&&o.objColl.pop():o.objColl.splice(h,1))}}return r},o.prototype.applyObj=function(t,i){var o=this.parent,r=!1;return e.isNullOrUndefined(o.activeObj.shape)||"rectangle"!==o.activeObj.shape&&"ellipse"!==o.activeObj.shape&&"text"!==o.activeObj.shape&&"line"!==o.activeObj.shape&&"arrow"!==o.activeObj.shape&&"path"!==o.activeObj.shape||(r=!(t>=o.activeObj.activePoint.startX-2*o.activeObj.topLeftCircle.radius&&t<=o.activeObj.activePoint.endX+2*o.activeObj.topLeftCircle.radius&&i>=o.activeObj.activePoint.startY-2*o.activeObj.topLeftCircle.radius&&i<=o.activeObj.activePoint.endY+2*o.activeObj.topLeftCircle.radius)&&("default"===o.upperCanvas.style.cursor||"grab"===o.upperCanvas.style.cursor||"crosshair"===o.upperCanvas.style.cursor||"pointer"===o.upperCanvas.style.cursor)),r},o.prototype.applyCurrShape=function(t){var i=this.parent,o=!1;if(i.togglePen)return o;var r=e.extend({},i.activeObj,null,!0);if(this.isShapeInserted&&"text"===i.activeObj.shape&&t&&(this.isInitialTextEdited=!0,i.notify("draw",{prop:"setShapeTextInsert",onPropertyChange:!1,value:{bool:!0}})),"block"===i.textArea.style.display){var n=e.extend({},i.activeObj,null,!0);i.notify("shape",{prop:"redrawActObj",onPropertyChange:!1,value:{x:null,y:null,isMouseDown:null}}),r=e.extend({},i.objColl[i.objColl.length-1],null,!0),i.objColl.pop(),i.activeObj=e.extend({},n,null,!0),i.textArea.value=r.keyHistory,i.textArea.style.display="block";var a="rgb"===r.strokeSettings.strokeColor.split("(")[0]?this.rgbToHex(parseFloat(r.strokeSettings.strokeColor.split("(")[1].split(",")[0]),parseFloat(r.strokeSettings.strokeColor.split("(")[1].split(",")[1]),parseFloat(r.strokeSettings.strokeColor.split("(")[1].split(",")[2])):r.strokeSettings.strokeColor;"#ffffff"===a&&(a="#fff"),"#ffffff"===this.tempActiveObj.strokeSettings.strokeColor&&(this.tempActiveObj.strokeSettings.strokeColor="#fff"),r.keyHistory===this.tempActiveObj.keyHistory&&a===this.tempActiveObj.strokeSettings.strokeColor&&r.textSettings.fontFamily===this.tempActiveObj.textSettings.fontFamily&&Math.round(r.textSettings.fontSize)===Math.round(this.tempActiveObj.textSettings.fontSize)&&Math.round(r.textSettings.fontRatio)===Math.round(this.tempActiveObj.textSettings.fontRatio)&&r.textSettings.bold===this.tempActiveObj.textSettings.bold&&r.textSettings.italic===this.tempActiveObj.textSettings.italic&&r.textSettings.underline===this.tempActiveObj.textSettings.underline||(o=!0),this.isInitialTextEdited&&!o&&(o=!0,this.isInitialTextEdited=!1)}else this.tempActiveObj.activePoint.height=Math.abs(this.tempActiveObj.activePoint.height),o=JSON.stringify(r)!==JSON.stringify(this.tempActiveObj);return o},o.prototype.canvasMouseDownHandler=function(t){var i=this.parent;t.preventDefault();var o,r;"mousedown"===t.type?(o=t.offsetX||t.pageX-i.lowerCanvas.offsetLeft,r=t.offsetY||t.pageY-i.lowerCanvas.offsetTop):(o=t.touches[0].clientX||t.touches[0].pageX-i.lowerCanvas.offsetLeft,r=t.touches[0].clientY||t.touches[0].pageY-i.lowerCanvas.offsetTop);var n=i.lowerCanvas.getBoundingClientRect();o-=n.left,r-=n.top,this.panDown={x:o,y:r};var a={tempPanMove:null};i.notify("transform",{prop:"getTempPanMove",onPropertyChange:!1,value:{obj:a}}),e.isNullOrUndefined(a.tempPanMove)&&i.notify("transform",{prop:"setTempPanMove",onPropertyChange:!1,value:{point:{x:o,y:r}}})},o.prototype.canvasMouseMoveHandler=function(t){var e=this.parent;this.dragCanvas?e.lowerCanvas.style.cursor="grab":(this.dragCanvas=e.togglePan=!1,e.lowerCanvas.style.cursor=e.upperCanvas.style.cursor=e.cursor="default");var i,o;"mousemove"===t.type?(i=t.offsetX,o=t.offsetY):(i=t.touches[0].clientX||t.touches[0].pageX-e.lowerCanvas.offsetLeft,o=t.touches[0].clientY||t.touches[0].pageY-e.lowerCanvas.offsetTop);var r=e.lowerCanvas.getBoundingClientRect(),n={x:i-=r.left,y:o-=r.top};e.notify("transform",{prop:"setPanMove",onPropertyChange:!1,value:{point:{x:i,y:o}}}),this.panDown&&n&&e.togglePan&&this.dragCanvas&&e.notify("transform",{prop:"drawPannedImage",onPropertyChange:!1,value:{xDiff:null,yDiff:null}})},o.prototype.canvasMouseUpHandler=function(t){var e=this.parent;t.preventDefault();var i={panMove:null};e.notify("transform",{prop:"getPanMove",onPropertyChange:!1,value:{obj:i}}),e.togglePan&&this.panDown&&i.panMove&&e.togglePan&&this.dragCanvas&&(this.panDown=null,e.notify("transform",{prop:"setPanMove",onPropertyChange:!1,value:{point:null}}),e.notify("transform",{prop:"setTempPanMove",onPropertyChange:!1,value:{point:null}})),"path"!==this.currentDrawingShape&&(e.currObjType.isDragging=!1)},o.prototype.touchStartHandler=function(t){t.preventDefault(),0===this.touchTime?this.touchTime=(new Date).getTime():(new Date).getTime()-this.touchTime<400?(this.parent.notify("shape",{prop:"stopPathDrawing",onPropertyChange:!1,value:{e:t}}),this.touchTime=0):this.touchTime=(new Date).getTime(),2===t.touches.length?this.isFirstMove=!0:this.mouseDownEventHandler(t),e.EventHandler.add(this.parent.lowerCanvas,"touchend",this.mouseUpEventHandler,this),e.EventHandler.add(this.parent.lowerCanvas,"touchmove",this.mouseMoveEventHandler,this),e.EventHandler.add(this.parent.upperCanvas,"touchend",this.mouseUpEventHandler,this),e.EventHandler.add(this.parent.upperCanvas,"touchmove",this.mouseMoveEventHandler,this)},o.prototype.keyDownEventHandler=function(i){var o=this,r=this.parent;!i.ctrlKey||"+"!==i.key&&"-"!==i.key||i.preventDefault();var n={fileName:"",fileType:null};r.notify("draw",{prop:"getFileName",onPropertyChange:!1,value:{obj:n}});var a,s={fileName:n.fileName,fileType:n.fileType,cancel:!1};switch(i.key){case i.ctrlKey&&"s":e.isBlazor()&&!e.isNullOrUndefined(r.events)&&!0===r.events.saving.hasDelegate?r.dotNetRef.invokeMethodAsync("BeforeSaveEventAsync","BeforeSave",s).then(function(t){o.beforeSaveEvent(t,i)}):(r.trigger("beforeSave",s),this.beforeSaveEvent(s,i));break;case i.ctrlKey&&"z":r.allowUndoRedo&&r.notify("undo-redo",{prop:"call-undo"});break;case i.ctrlKey&&"y":r.allowUndoRedo&&r.notify("undo-redo",{prop:"call-redo"});break;case i.ctrlKey&&"+":(r.zoomSettings.zoomTrigger&t.ZoomTrigger.Commands)===t.ZoomTrigger.Commands&&(this.zoomType="Commands",r.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:.1,zoomPoint:null}}));break;case i.ctrlKey&&"-":(r.zoomSettings.zoomTrigger&t.ZoomTrigger.Commands)===t.ZoomTrigger.Commands&&(this.zoomType="Commands",r.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:-.1,zoomPoint:null}}));break;case"Delete":this.deleteItem();break;case"Escape":r.notify("draw",{prop:"performCancel",value:{isContextualToolbar:null}});break;case"Enter":r.activeObj.shape&&(a=r.activeObj.shape.split("-")),this.isKeyBoardCrop(i)&&r.activeObj.horTopLine&&r.activeObj.shape&&"crop"===a[0]&&r.crop();break;case"Tab":this.performTabAction();break;default:e.Browser.isDevice&&"block"===r.textArea.style.display&&setTimeout(this.textKeyDown.bind(this),1,i)}},o.prototype.isKeyBoardCrop=function(t){var i=!1,o=t.target;return o.id!==this.parent.element.id+"_ok"&&""!==o.id||e.isBlazor()||(i=!0),i},o.prototype.beforeSaveEvent=function(t,e){var i=this.parent;t.cancel||i.notify("export",{prop:"export",onPropertyChange:!1,value:{type:t.fileType,fileName:t.fileName}}),e.preventDefault(),e.stopImmediatePropagation()},o.prototype.handleScroll=function(i){var o,r,n=this.parent,a=!1;"mousewheel"===i.type&&(o=i.clientX,r=i.clientY);var s=n.lowerCanvas.getBoundingClientRect();if(o-=s.left,r-=s.top,o>n.img.destLeft&&o<n.img.destLeft+n.img.destWidth&&r>n.img.destTop&&r<n.img.destTop+n.img.destHeight&&(a=!0),i.stopPropagation(),!0===i.ctrlKey&&a){i.preventDefault(),n.isCropTab||e.isNullOrUndefined(n.activeObj.shape)||"crop"===n.activeObj.shape.split("-")[0]||(n.okBtn(),e.isBlazor()||n.notify("toolbar",{prop:"close-contextual-toolbar",onPropertyChange:!1}));var l="";"mousewheel"===i.type&&(n.zoomSettings.zoomTrigger&t.ZoomTrigger.MouseWheel)===t.ZoomTrigger.MouseWheel&&(this.zoomType="MouseWheel",l=i.wheelDelta>0?"zoomIn":"zoomOut"),""!==l&&n.notify("draw",{prop:"performPointZoom",onPropertyChange:!1,value:{x:o,y:r,type:l}})}},o.prototype.adjustToScreen=function(){var t=this.parent;if(t.isImageLoaded){(e.isNullOrUndefined(t.element.querySelector("#"+t.element.id+"_contextualToolbar"))||t.element.querySelector("#"+t.element.id+"_contextualToolbar").parentElement.classList.contains("e-hide"))&&(e.isNullOrUndefined(t.element.querySelector("#"+t.element.id+"_headWrapper"))||t.element.querySelector("#"+t.element.id+"_headWrapper").parentElement.classList.contains("e-hide"))||(t.element.querySelector(".e-contextual-toolbar-wrapper").classList.add("e-hide"),t.okBtn(),e.isBlazor()?t.updateToolbar(t.element,"imageLoaded"):(t.notify("toolbar",{prop:"refresh-main-toolbar",onPropertyChange:!1}),t.notify("toolbar",{prop:"destroy-qa-toolbar",onPropertyChange:!1}))),this.isFhdEditing&&(e.isBlazor()?t.updateToolbar(t.element,"destroyQuickAccessToolbar"):t.notify("toolbar",{prop:"destroy-qa-toolbar",onPropertyChange:!1}));var o=!1;void 0!==t.activeObj.shape&&(o=!0,"block"===t.textArea.style.display?(t.notify("shape",{prop:"redrawActObj",onPropertyChange:!1,value:{x:null,y:null,isMouseDown:null}}),e.isBlazor()?t.updateToolbar(t.element,"destroyQuickAccessToolbar"):t.notify("toolbar",{prop:"destroy-qa-toolbar",onPropertyChange:!1})):(t.notify("shape",{prop:"updImgRatioForActObj",onPropertyChange:!1}),t.objColl.push(t.activeObj)),t.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}));var r=this.lowerContext.filter;t.update(),t.notify("shape",{prop:"applyActObj",onPropertyChange:!1,value:{isMouseDown:null}}),t.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),this.lowerContext.filter=r,t.initialAdjustmentValue=r,t.isImageLoaded&&(i.showSpinner(t.element),t.element.style.opacity="0.5"),this.lowerContext.clearRect(0,0,t.lowerCanvas.width,t.lowerCanvas.height),this.upperContext.clearRect(0,0,t.upperCanvas.width,t.upperCanvas.height);var n=document.querySelector("#"+t.element.id+"_canvasWrapper");if(!e.isNullOrUndefined(n)){n.style.width=t.element.offsetWidth-2+"px",n.style.height=t.element.offsetHeight+"px";var a={toolbarHeight:e.isBlazor()?t.toolbarHeight:0};e.isBlazor()||t.notify("toolbar",{prop:"getToolbarHeight",value:{obj:a}}),e.Browser.isDevice?n.style.height=parseFloat(n.style.height)-2*a.toolbarHeight-3+"px":n.style.height=parseFloat(n.style.height)-a.toolbarHeight-3+"px"}var s={width:0,height:0};t.notify("transform",{prop:"calcMaxDimension",onPropertyChange:!1,value:{width:t.img.srcWidth,height:t.img.srcHeight,obj:s}});var l=s;if(t.transform.defaultZoomFactor>0&&(l.width+=l.width*t.transform.defaultZoomFactor,l.height+=l.height*t.transform.defaultZoomFactor),t.img.destLeft=(t.lowerCanvas.clientWidth-l.width)/2,t.img.destTop=(t.lowerCanvas.clientHeight-l.height)/2,0===t.transform.degree&&""===t.transform.currFlipState)t.transform.defaultZoomFactor>0&&(t.img.destLeft+=t.panPoint.totalPannedPoint.x,t.img.destTop+=t.panPoint.totalPannedPoint.y),t.notify("draw",{prop:"draw-image-to-canvas",value:{dimension:l}});else{t.notify("draw",{prop:"draw-image-to-canvas",value:{dimension:l}}),t.notify("draw",{prop:"updateCurrTransState",onPropertyChange:!1,value:{type:"initial",isPreventDestination:null,isRotatePan:null}});var p=this.lowerContext.filter;t.notify("filter",{prop:"updateBrightFilter",onPropertyChange:!1}),this.lowerContext.drawImage(t.baseImg,t.img.srcLeft,t.img.srcTop,t.img.srcWidth,t.img.srcHeight,t.img.destLeft,t.img.destTop,t.img.destWidth,t.img.destHeight),this.lowerContext.filter=p,t.notify("draw",{prop:"updateCurrTransState",onPropertyChange:!1,value:{type:"reverse",isPreventDestination:null,isRotatePan:null}})}t.notify("shape",{prop:"zoomObjColl",onPropertyChange:!1,value:{isPreventApply:null}}),t.notify("freehand-draw",{prop:"zoomFHDColl",onPropertyChange:!1,value:{isPreventApply:null}}),t.isCircleCrop&&t.notify("crop",{prop:"cropCircle",onPropertyChange:!1,value:{context:this.lowerContext,isSave:null,isFlip:null}}),i.hideSpinner(t.element),t.element.style.opacity="1";var h={defToolbarItems:null};if(!e.isBlazor()&&(t.notify("toolbar",{prop:"getDefToolbarItems",value:{obj:h}}),h.defToolbarItems&&h.defToolbarItems.length>0&&!e.isNullOrUndefined(document.getElementById(t.element.id+"_toolbar")))){e.getComponent(t.element.id+"_toolbar","toolbar").refreshOverflow(),e.isNullOrUndefined(t.element.querySelector(".e-contextual-toolbar-wrapper"))||t.element.querySelector(".e-contextual-toolbar-wrapper").classList.add("e-hide")}if(t.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),this.upperContext.clearRect(0,0,t.upperCanvas.width,t.upperCanvas.height),o&&(t.activeObj=e.extend({},t.objColl[t.objColl.length-1],null,!0),t.objColl.pop(),t.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate",obj:t.activeObj}}),"rectangle"!==t.activeObj.shape&&"ellipse"!==t.activeObj.shape&&"text"!==t.activeObj.shape&&"line"!==t.activeObj.shape&&"arrow"!==t.activeObj.shape&&"path"!==t.activeObj.shape||(e.isBlazor()?t.updateToolbar(t.element,"quickAccessToolbar",t.activeObj.shape):t.notify("toolbar",{prop:"renderQAT",onPropertyChange:!1,value:{isPenEdit:null}}))),this.isFhdEditing&&(e.isBlazor()?t.updateToolbar(t.element,"quickAccessToolbar","pen"):t.notify("toolbar",{prop:"renderQAT",onPropertyChange:!1,value:{isPenEdit:!0}})),(0!==t.transform.degree||""!==t.transform.currFlipState)&&t.transform.defaultZoomFactor>0){var c=e.extend({},t.panPoint.totalPannedPoint,null,!0),d=e.extend({},t.panPoint.totalPannedInternalPoint,null,!0),v=e.extend({},t.panPoint.totalPannedClientPoint,null,!0);t.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:.1,zoomPoint:null}}),t.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:-.1,zoomPoint:null}}),0===t.transform.degree?(t.img.destLeft+=c.x,t.img.destTop+=c.y,t.panPoint.totalPannedPoint=c,t.notify("draw",{prop:"updateFlipPan",value:{tempSelectionObj:null}})):(t.panPoint.totalPannedInternalPoint=d,t.panPoint.totalPannedClientPoint=v,t.panPoint.currentPannedPoint={x:0,y:0},t.isCropTab=!0,t.notify("transform",{prop:"rotatePan",onPropertyChange:!1,value:{isCropSelection:null,isDefaultZoom:null}}),t.isCropTab=!1)}else 0!==t.transform.degree&&t.transform.cropZoomFactor>0&&(t.transform.zoomFactor=0,t.transform.cropZoomFactor=null,e.isBlazor()?t.updateToolbar(t.element,"enableDisableToolbarBtn"):t.notify("toolbar",{prop:"enable-disable-btns",onPropertyChange:!1}))}},o.prototype.textKeyDown=function(t){var i=this.parent;"\r"===String.fromCharCode(t.which)&&(this.textRow+=1),i.textArea.setAttribute("rows",this.textRow.toString()),i.textArea.style.height="auto",i.textArea.style.height=i.textArea.scrollHeight+"px",i.notify("shape",{prop:"setTextBoxWidth",onPropertyChange:!1,value:{e:t}}),e.Browser.isDevice&&(i.textArea.style.width=parseFloat(i.textArea.style.width)+i.textArea.style.fontSize+"px");var o=i.textArea.value.split("\n");this.textRow=o.length,i.textArea.setAttribute("rows",this.textRow.toString()),this.isInitialTextEdited=!1},o.prototype.clearSelection=function(){var t=this.parent;!t.disabled&&t.isImageLoaded&&(t.togglePen=!1,t.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),this.dragElement="",this.dragPoint.startX=this.dragPoint.startY=this.dragPoint.endX=this.dragPoint.endY=0,t.currObjType.shape="",this.upperContext.clearRect(0,0,t.upperCanvas.width,t.upperCanvas.height),t.currObjType.isActiveObj=!0,t.currObjType.isCustomCrop=!1,t.upperCanvas.style.cursor=t.cursor="default")},o.prototype.setDragDirection=function(t,e){var i=this.parent;i.img.destWidth>i.img.destHeight?(i.activeObj.activePoint.startX=this.dragPoint.startX=t/2-e/2+7.5,i.activeObj.activePoint.startY=this.dragPoint.startY=e/2-e/2+7.5,i.activeObj.activePoint.endX=t/2+e/2-7.5,i.activeObj.activePoint.endY=e/2+e/2-7.5):(i.activeObj.activePoint.startY=this.dragPoint.startX=e/2-t/2+7.5,i.activeObj.activePoint.endY=e/2+t/2-7.5,i.activeObj.activePoint.startX=this.dragPoint.startX=7.5,i.activeObj.activePoint.endX=t-7.5)},o.prototype.calcShapeRatio=function(t,e,i,o){for(var r=this.parent,n=i,a=o,s=n>=a?n:a,l=s*(t/e),p=s,h=this.getScale(l,n),c=[],d=0;d<2;d++)0===d?c.push(l*h):c.push(p*h);l=c[0],p=c[1];var v=this.getScale(p,a),u=[];for(d=0;d<2;d++)0===d?u.push(l*v):u.push(p*v);l=u[0],p=u[1],r.activeObj.activePoint.width=l,r.activeObj.activePoint.height=p,r.activeObj.activePoint.startX=7.5+(this.dragPoint.startX=(n-l)/2),r.activeObj.activePoint.startY=7.5+(this.dragPoint.startY=(a-p)/2),r.activeObj.activePoint.endX=(n-l)/2+l-7.5,r.activeObj.activePoint.endY=(a-p)/2+p-7.5,r.activeObj.activePoint.startX<r.img.destLeft&&r.img.destLeft+r.img.destWidth>r.lowerCanvas.clientWidth&&(r.activeObj.activePoint.startX=r.img.destLeft,r.activeObj.activePoint.endX=r.activeObj.activePoint.startX+l-7.5),r.activeObj.activePoint.startY<r.img.destTop&&r.img.destTop+r.img.destHeight>r.lowerCanvas.clientHeight&&(r.activeObj.activePoint.startY=r.img.destTop,r.activeObj.activePoint.endY=r.activeObj.activePoint.startY+p-7.5),r.activeObj.activePoint.width=r.activeObj.activePoint.endX-r.activeObj.activePoint.startX,r.activeObj.activePoint.height=r.activeObj.activePoint.endY-r.activeObj.activePoint.startY},o.prototype.getScale=function(t,e){return t>e?e/t:1},o.prototype.findTarget=function(t,e,i){var o=this.parent;if("mousedown"===i.toLowerCase()||"touchstart"===i.toLowerCase()){var r=!1;o.activeObj.shape&&"crop"===o.activeObj.shape.split("-")[0]&&(r=!0),this.findTargetObj(t,e,r),this.updateCursorStyles(t,e,i)}else switch(this.dragElement.toLowerCase()){case"nw-resize":o.activeObj.topLeftCircle.startX=t,o.activeObj.topLeftCircle.startY=e;break;case"n-resize":o.activeObj.topCenterCircle.startX=t,o.activeObj.topCenterCircle.startY=e;break;case"ne-resize":o.activeObj.topRightCircle.startX=t,o.activeObj.topRightCircle.startY=e;break;case"w-resize":o.activeObj.centerLeftCircle.startX=t,o.activeObj.centerLeftCircle.startY=e;break;case"e-resize":o.activeObj.centerRightCircle.startX=t,o.activeObj.centerRightCircle.startY=e;break;case"sw-resize":o.activeObj.bottomLeftCircle.startX=t,o.activeObj.bottomLeftCircle.startY=e;break;case"s-resize":o.activeObj.bottomCenterCircle.startX=t,o.activeObj.bottomCenterCircle.startY=e;break;case"se-resize":o.activeObj.bottomRightCircle.startX=t,o.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)}},o.prototype.findTargetObj=function(t,i,o){var r=this,n=this.parent,a=!1;if(0!==n.objColl.length&&!n.currObjType.isCustomCrop&&!o){for(var s=0,l=void 0,p=0;p<n.objColl.length;p++){var h=n.upperCanvas.style.cursor;this.setCursor(t,i);var c=e.extend({},n.objColl[p],{},!0);if("line"===c.shape||"arrow"===c.shape){for(var d=0;d<c.pointColl.length;d++)if(t>=c.pointColl[d].x-2*c.topLeftCircle.radius&&t<=c.pointColl[d].x+2*c.topLeftCircle.radius&&i>=c.pointColl[d].y-2*c.topLeftCircle.radius&&i<=c.pointColl[d].y+2*c.topLeftCircle.radius){this.isTouch||"move"===n.cursor||"grab"===n.cursor||this.isShapeInserted?(0===s||s>t-c.activePoint.startX)&&(s=t-n.objColl[p].activePoint.startX,l=p):n.objColl[p].currIndex===this.tempActiveObj.currIndex&&(l=p);break}}else if("path"===c.shape){var v=this.setCursorForPath(c,t,i,n.upperCanvas);"default"!==v&&"grab"!==v&&(this.isTouch||"move"===n.cursor||"grab"===n.cursor||this.isShapeInserted?(0===s||s>t-c.activePoint.startX)&&(s=t-n.objColl[p].activePoint.startX,l=p):n.objColl[p].currIndex===this.tempActiveObj.currIndex&&(l=p))}else if(0!==c.rotatedAngle){var u=this.setCursorForRotatedObject(c,t,i,n.upperCanvas);"default"!==u&&"grab"!==u&&(this.isTouch||"move"===n.cursor||"grab"===n.cursor||this.isShapeInserted?(0===s||s>t-c.activePoint.startX)&&(s=t-n.objColl[p].activePoint.startX,l=p):n.objColl[p].currIndex===this.tempActiveObj.currIndex&&(l=p))}else{var g=this.getTransRotationPoint(c);(t>=c.activePoint.startX-2*c.topLeftCircle.radius&&t<=c.activePoint.endX+2*c.topLeftCircle.radius&&i>=c.activePoint.startY-2*c.topLeftCircle.radius&&i<=c.activePoint.endY+2*c.topLeftCircle.radius||!e.isNullOrUndefined(g)&&t>=g.x-2*c.topLeftCircle.radius&&t<=g.x+2*c.topLeftCircle.radius&&i>=g.y-2*c.topLeftCircle.radius&&i<=g.y+2*c.topLeftCircle.radius)&&(this.isTouch||"move"===h||"grabbing"===h||this.isShapeInserted||"move"===n.cursor||"grabbing"===n.cursor?(0===s||s>t-c.activePoint.startX)&&(s=t-n.objColl[p].activePoint.startX,l=p):n.objColl[p].currIndex===this.tempActiveObj.currIndex&&(l=p))}}if(e.isNullOrUndefined(l))n.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),a=!1;else{this.tempObjColl=e.extend([],n.objColl,[],!0),n.currObjType.isCustomCrop=!1,n.activeObj=e.extend({},n.objColl[l],{},!0);var b=e.extend({},n.objColl[l],{},!0);if(n.objColl.splice(l,1),0===n.transform.degree){var C=this.lowerContext.filter;this.lowerContext.clearRect(0,0,n.lowerCanvas.width,n.lowerCanvas.height),n.notify("filter",{prop:"updateBrightFilter",onPropertyChange:!1}),this.lowerContext.drawImage(n.baseImg,n.img.srcLeft,n.img.srcTop,n.img.srcWidth,n.img.srcHeight,n.img.destLeft,n.img.destTop,n.img.destWidth,n.img.destHeight),this.lowerContext.filter="none",n.notify("shape",{prop:"iterateObjColl",onPropertyChange:!1}),n.activeObj=e.extend({},C,{},!0),n.notify("freehand-draw",{prop:"freehandRedraw",onPropertyChange:!1,value:{context:this.lowerContext,points:null}}),this.lowerContext.filter=C,this.getCurrentFlipState()}else n.notify("draw",{prop:"callUpdateCurrTransState",onPropertyChange:!1}),n.notify("freehand-draw",{prop:"freehandRedraw",onPropertyChange:!1,value:{context:this.lowerContext,points:null}});n.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.lowerContext}}),(!e.isNullOrUndefined(n.currSelectionPoint)&&"crop-circle"===n.currSelectionPoint.shape||n.isCircleCrop)&&n.notify("crop",{prop:"cropCircle",onPropertyChange:!1,value:{context:this.lowerContext,isSave:null,isFlip:null}}),this.setActivePoint(),n.activeObj=e.extend({},b,{},!0);var f=e.extend({},n.activeObj.strokeSettings,{},!0);n.notify("draw",{prop:"setTempStrokeSettings",onPropertyChange:!1,value:{tempStrokeSettings:f}});var m=e.extend({},n.activeObj.textSettings,{},!0);n.notify("draw",{prop:"setTempTextSettings",onPropertyChange:!1,value:{tempTextSettings:m}});var y=this.updatePrevShapeSettings(),P={action:"select",previousShapeSettings:y,currentShapeSettings:y};"line"!==n.activeObj.shape&&"arrow"!==n.activeObj.shape||(P.currentShapeSettings.width=n.activeObj.activePoint.endX-n.activeObj.activePoint.startX,P.currentShapeSettings.height=n.activeObj.activePoint.endY-n.activeObj.activePoint.startY),this.isCropSelection=!1;var j=void 0;if(void 0!==n.activeObj.shape&&(j=n.activeObj.shape.split("-")),void 0!==j&&"crop"===j[0]&&(this.isCropSelection=!0),!this.isCropSelection&&e.isBlazor()&&e.isNullOrUndefined(this.parent.eventType)&&!e.isNullOrUndefined(n.events)&&!0===n.events.shapeChanging.hasDelegate)n.dotNetRef.invokeMethodAsync("ShapeEventAsync","OnShape",P).then(function(t){r.shapeEvent(t)});else if(this.isCropSelection){var O={action:P.action,previousSelectionSettings:{type:n.getSelectionType(n.activeObj.shape),startX:P.previousShapeSettings.startX,startY:P.previousShapeSettings.startY,width:P.previousShapeSettings.width,height:P.previousShapeSettings.height},currentSelectionSettings:{type:n.getSelectionType(n.activeObj.shape),startX:P.currentShapeSettings.startX,startY:P.currentShapeSettings.startY,width:P.currentShapeSettings.width,height:P.currentShapeSettings.height}};e.isBlazor()&&!e.isNullOrUndefined(n.events)&&!0===n.events.onSelectionResizeStart.hasDelegate?n.dotNetRef.invokeMethodAsync("SelectionEventAsync","OnSelectionResizeStart",O).then(function(t){P.currentShapeSettings.startX=t.currentSelectionSettings.startX,P.currentShapeSettings.startY=t.currentSelectionSettings.startY,P.currentShapeSettings.width=t.currentSelectionSettings.width,P.currentShapeSettings.height=t.currentSelectionSettings.height,r.shapeEvent(P)}):(n.trigger("selectionChanging",O),P.currentShapeSettings.startX=O.currentSelectionSettings.startX,P.currentShapeSettings.startY=O.currentSelectionSettings.startY,P.currentShapeSettings.width=O.currentSelectionSettings.width,P.currentShapeSettings.height=O.currentSelectionSettings.height,this.shapeEvent(P))}else n.trigger("shapeChanging",P),this.shapeEvent(P);a=!0}}return a},o.prototype.shapeEvent=function(t){var i=this.parent;if(i.notify("shape",{prop:"updateShapeChangeEventArgs",onPropertyChange:!1,value:{shapeSettings:t.currentShapeSettings}}),i.activeObj.activePoint){var o={prevActObj:null};i.notify("draw",{prop:"getPrevActObj",onPropertyChange:!1,value:{obj:o}}),e.isNullOrUndefined(o.prevActObj)&&i.notify("draw",{prop:"setPrevActObj",onPropertyChange:!1,value:{prevActObj:e.extend({},i.activeObj,{},!0)}}),i.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate",obj:i.activeObj,isCropRatio:null,points:null,isPreventDrag:!0,saveContext:null,isPreventSelection:!0}}),this.isShapeInserted||(i.activeObj.activePoint.startX<i.img.destLeft?this.isPreventDragging=!0:i.activeObj.activePoint.endX>i.img.destLeft+i.img.destWidth?this.isPreventDragging=!0:i.activeObj.activePoint.startY<i.img.destTop?this.isPreventDragging=!0:i.activeObj.activePoint.endY>i.img.destTop+i.img.destHeight&&(this.isPreventDragging=!0))}},o.prototype.targetTouches=function(t){var e=this.parent.lowerCanvas.getBoundingClientRect();return[{x:t[0].pageX-e.left,y:t[0].pageY-e.top},{x:t[1].pageX-e.left,y:t[1].pageY-e.top}]},o.prototype.calculateScale=function(t,e){var i=this.getDistance(t[0],t[1]);return this.getDistance(e[0],e[1])/i},o.prototype.getDistance=function(t,i){var o=0,r=0;return e.isNullOrUndefined(t)||e.isNullOrUndefined(i)||(o=t.x-i.x,r=t.y-i.y),Math.sqrt(o*o+r*r)},o.prototype.redrawShape=function(t,e){for(var i=this.parent,o=0,r=i.objColl.length;o<r;o++)if(JSON.stringify(t)===JSON.stringify(i.objColl[o])){i.objColl.splice(o,1);break}this.upperContext.clearRect(0,0,i.upperCanvas.width,i.upperCanvas.height),this.isPreventDragging?(i.activeObj.activePoint.startX>i.img.destLeft&&(this.isPreventDragging=!1),e&&i.activeObj.rotatedAngle,i.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate",obj:null,isCropRatio:null,points:null,isPreventDrag:!0,saveContext:null,isPreventSelection:null}})):(e&&i.activeObj.rotatedAngle,i.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate",obj:null,isCropRatio:null,points:null,isPreventDrag:!0,saveContext:null,isPreventSelection:null}}))},o.prototype.setTimer=function(t){this.timer>10&&(clearTimeout(this.timer),this.timer=0,this.parent.notify("shape",{prop:"findTextTarget",onPropertyChange:!1,value:{e:t}}),e.Browser.isDevice&&this.upperContext.clearRect(0,0,this.parent.upperCanvas.width,this.parent.upperCanvas.height))},o.prototype.applyCurrActObj=function(t,i){var o=this.parent,r=!1,n=e.extend({},o.activeObj,{},!0);if(!e.isNullOrUndefined(n.activePoint)){if(t>=Math.floor(n.activePoint.startX)&&t<=Math.ceil(n.activePoint.endX)&&i>=Math.floor(n.activePoint.startY)&&i<=Math.ceil(n.activePoint.endY))r=!0;else if("text"===n.shape&&""!==this.dragElement)r=!0;else if("line"===n.shape||"arrow"===n.shape){var a={x:n.activePoint.startX<n.activePoint.endX?n.activePoint.startX:n.activePoint.endX,y:n.activePoint.startY<n.activePoint.endY?n.activePoint.startY:n.activePoint.endY},s={x:n.activePoint.startX>n.activePoint.endX?n.activePoint.startX:n.activePoint.endX,y:n.activePoint.startY>n.activePoint.endY?n.activePoint.startY:n.activePoint.endY};t>=Math.floor(a.x)-5&&t<=Math.ceil(s.x)+5&&i>=Math.floor(a.y)-5&&i<=Math.ceil(s.y)+5&&(r=!0)}else if("path"===n.shape){"move"===(l=this.setCursorForPath(n,t,i,o.upperCanvas))&&(r=!0)}else if("grabbing"===this.dragElement)r=!0;else if(0!==n.rotatedAngle){var l;("default"!==(l=this.setCursorForRotatedObject(n,t,i,o.upperCanvas))&&"grab"!==l||"n-resize"===this.dragElement||"e-resize"===this.dragElement||"s-resize"===this.dragElement||"w-resize"===this.dragElement)&&(r=!0)}if(!r){if(e.isNullOrUndefined(o.activeObj.currIndex)&&(o.activeObj.currIndex="shape_"+(o.objColl.length+1)),o.notify("shape",{prop:"updImgRatioForActObj",onPropertyChange:!1}),void 0===o.activeObj.horTopLine||0===o.activeObj.horTopLine.startX||0===o.activeObj.horTopLine.endX||o.currObjType.isCustomCrop||""===o.currObjType.shape||o.objColl.push(e.extend({},o.activeObj,{},!0)),"text"===o.activeObj.shape||"ellipse"===o.currObjType.shape||"rectangle"===o.currObjType.shape||"line"===o.currObjType.shape||"arrow"===o.activeObj.shape||"path"===o.activeObj.shape){var p=this.lowerContext.filter;this.lowerContext.filter="brightness(1) contrast(100%) hue-rotate(0deg) saturate(100%) opacity(1) blur(0px) sepia(0%) grayscale(0%) invert(0%)";for(var h=0;h<o.objColl.length;h++){var c={isInside:!1};o.notify("crop",{prop:"isObjInImage",onPropertyChange:!1,value:{obj:o.objColl[h],object:c}}),c.isInside&&(o.notify("shape",{prop:"apply",onPropertyChange:!1,value:{shape:o.objColl[h].shape,obj:o.objColl[h],canvas:null}}),o.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}))}o.notify("freehand-draw",{prop:"zoomFHDColl",onPropertyChange:!1,value:{isPreventApply:null}}),this.lowerContext.filter=p,e.isNullOrUndefined(o.activeObj.shape)||o.notify("shape",{prop:"apply",onPropertyChange:!1,value:{shape:null,obj:null,canvas:null}}),o.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.lowerContext}}),o.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.upperContext}}),o.isCircleCrop&&o.notify("crop",{prop:"cropCircle",onPropertyChange:!1,value:{context:this.lowerContext,isSave:null,isFlip:null}})}e.isBlazor()||o.notify("toolbar",{prop:"refresh-main-toolbar",onPropertyChange:!1})}}},o.prototype.getCurrentFlipState=function(){var t=this.parent;if(0!==t.rotateFlipColl.length){var i=e.extend({},t.panPoint.totalPannedInternalPoint,{},!0);t.notify("draw",{prop:"callUpdateCurrTransState",onPropertyChange:!1}),t.panPoint.totalPannedInternalPoint=i}else t.notify("draw",{prop:"callUpdateCurrTransState",onPropertyChange:!1})},o.prototype.setTextBoxStylesToActObj=function(){var t=this.parent;t.activeObj.textSettings.fontFamily=t.textArea.style.fontFamily,t.activeObj.strokeSettings.strokeColor=""!==t.textArea.style.color?this.rgbToHex(parseFloat(t.textArea.style.color.split("(")[1].split(",")[0]),parseFloat(t.textArea.style.color.split("(")[1].split(",")[1]),parseFloat(t.textArea.style.color.split("(")[1].split(",")[2])):t.textArea.style.color,"bold"===t.textArea.style.fontWeight?t.activeObj.textSettings.bold=!0:t.activeObj.textSettings.bold=!1,"italic"===t.textArea.style.fontStyle?t.activeObj.textSettings.italic=!0:t.activeObj.textSettings.italic=!1,t.activeObj.textSettings.fontSize=parseFloat(t.textArea.style.fontSize)},o.prototype.rgbToHex=function(t,e,i){return"#"+this.componentToHex(t)+this.componentToHex(e)+this.componentToHex(i)},o.prototype.componentToHex=function(t){var e=t.toString(16);return 1===e.length?"0"+e:e},o.prototype.deleteItem=function(){var t=this.parent,i={};if(this.isFhdEditing){this.updateFreehandDrawColorChange();var o=e.extend({},t.cropObj,{},!0),r={currObj:{}};t.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:r}});(h=r.currObj).objColl=e.extend([],t.objColl,[],!0),h.pointColl=e.extend([],t.pointColl,[],!0),h.afterCropActions=e.extend([],t.afterCropActions,[],!0);var n={selPointColl:null};t.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:n}}),h.selPointColl=e.extend([],n.selPointColl,[],!0);var a={freehandDrawSelectedId:null};t.notify("freehand-draw",{prop:"getFreehandDrawSelectedId",onPropertyChange:!1,value:{obj:a}}),t.notify("freehand-draw",{prop:"deleteFhd",value:{id:a.freehandDrawSelectedId}}),t.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"deleteFreehandDrawing",previousObj:h,previousObjColl:this.tempObjColl,previousPointColl:h.pointColl,previousSelPointColl:h.selPointColl,previousCropObj:o,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),t.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"ok"}}),t.notify("freehand-draw",{prop:"resetFreehandDrawSelectedId"})}else if("none"===t.textArea.style.display){a={prevActObj:null};if(t.notify("draw",{prop:"getPrevActObj",onPropertyChange:!1,value:{obj:a}}),a.prevActObj&&(a.prevActObj.activePoint.width=Math.abs(a.prevActObj.activePoint.width),a.prevActObj.activePoint.height=Math.abs(a.prevActObj.activePoint.height)),a.prevActObj&&JSON.stringify(a.prevActObj)!==JSON.stringify(t.activeObj)){var s=t.activeObj.currIndex;t.notify("draw",{prop:"performCancel",value:{isContextualToolbar:null}});for(var l=0;l<t.objColl.length;l++)if(t.objColl[l].currIndex===s){t.objColl.splice(l,1),t.notify("draw",{prop:"render-image",value:{isMouseWheel:null}});break}}r={isNewPath:null};if(t.notify("draw",{prop:"getNewPath",value:{obj:r}}),r.isNewPath)t.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),this.upperContext.clearRect(0,0,t.upperCanvas.width,t.upperCanvas.height),t.notify("draw",{prop:"render-image",value:{isMouseWheel:null}}),e.isBlazor()?t.updateToolbar(t.element,"imageLoaded"):t.notify("toolbar",{prop:"refresh-main-toolbar",onPropertyChange:!1});else if(t.activeObj.shape){t.objColl.push(t.activeObj);o=e.extend({},t.cropObj,{},!0);var p={currObj:{}};t.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:p}});var h;(h=p.currObj).objColl=e.extend([],t.objColl,[],!0),h.pointColl=e.extend([],t.pointColl,[],!0),h.afterCropActions=e.extend([],t.afterCropActions,[],!0);n={selPointColl:null};t.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:n}}),h.selPointColl=e.extend([],n.selPointColl,[],!0),t.objColl.pop(),i={action:"delete",previousShapeSettings:this.updatePrevShapeSettings(),currentShapeSettings:null},t.notify("shape",{prop:"setKeyHistory",onPropertyChange:!1,value:{keyHistory:""}}),t.clearSelection(),e.isBlazor()&&t.events&&!0===t.events.shapeChanging.hasDelegate?t.dotNetRef.invokeMethodAsync("ShapeEventAsync","OnShape",i):(t.trigger("shapeChanging",i),e.isBlazor()||t.notify("toolbar",{prop:"refresh-main-toolbar",onPropertyChange:!1})),e.isNullOrUndefined(h.objColl[h.objColl.length-1].currIndex)||(t.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"deleteObj",previousObj:h,previousObjColl:this.tempObjColl,previousPointColl:h.pointColl,previousSelPointColl:h.selPointColl,previousCropObj:o,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),t.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"ok"}}))}t.notify("draw",{prop:"setPrevActObj",onPropertyChange:!1,value:{prevActObj:null}})}document.getElementById(t.element.id+"_quickAccessToolbarArea")&&(document.getElementById(t.element.id+"_quickAccessToolbarArea").style.display="none")},o.prototype.updateFreehandDrawColorChange=function(){var t=this.parent,i={freehandSelectedIndex:null};if(t.notify("freehand-draw",{prop:"getFreehandSelectedIndex",onPropertyChange:!1,value:{obj:i}}),!e.isNullOrUndefined(i.freehandSelectedIndex)&&!e.isNullOrUndefined(t.pointColl[i.freehandSelectedIndex])&&"#42a5f5"===t.pointColl[i.freehandSelectedIndex].strokeColor){var o={tempFreeHandDrawEditingStyles:null};t.notify("freehand-draw",{prop:"getTempFreeHandDrawEditingStyles",value:{obj:o}}),t.pointColl[i.freehandSelectedIndex].strokeColor=o.tempFreeHandDrawEditingStyles.strokeColor}},o.prototype.updatePrevShapeSettings=function(t){var i=this.parent,o=[];"text"===i.activeObj.shape&&i.activeObj.textSettings&&(i.activeObj.textSettings.bold&&o.push("bold"),i.activeObj.textSettings.italic&&o.push("italic"),i.activeObj.textSettings.underline&&o.push("underline"));var r={id:e.isNullOrUndefined(i.activeObj.currIndex)?null:i.activeObj.currIndex,type:i.toPascalCase(i.activeObj.shape),startX:i.activeObj.activePoint.startX,startY:i.activeObj.activePoint.startY,width:i.activeObj.activePoint.width,height:i.activeObj.activePoint.height,strokeColor:i.activeObj.strokeSettings?i.activeObj.strokeSettings.strokeColor:null,strokeWidth:i.activeObj.strokeSettings?i.activeObj.strokeSettings.strokeWidth:null,fillColor:i.activeObj.strokeSettings?i.activeObj.strokeSettings.fillColor:null,radius:"ellipse"===i.activeObj.shape?i.activeObj.activePoint.width/2:null,length:"line"===i.activeObj.shape||"arrow"===i.activeObj.shape?i.activeObj.activePoint.width:null,text:"text"===i.activeObj.shape&&i.activeObj.keyHistory?i.activeObj.keyHistory:null,fontSize:"text"===i.activeObj.shape&&i.activeObj.textSettings?i.activeObj.textSettings.fontSize:null,fontStyle:"text"===i.activeObj.shape?o:null,color:"text"===i.activeObj.shape&&i.activeObj.strokeSettings?i.activeObj.strokeSettings.strokeColor:null};return t&&(t.shapeSettingsObj=r),r},o.prototype.getRectanglePoints=function(t,e,i,o,r,n,a){var s=t+i/2,l=e+o/2,p=r*(Math.PI/180),h=Math.cos(p),c=Math.sin(p),d=n-s,v=a-l,u=d*h+v*c,g=-d*c+v*h,b=i/2,C=o/2;return u>=-b&&u<=b&&g>=-C&&g<=C},o.prototype.getTransRotationPoint=function(t,e){var i,o,r=!1,n=!1;(o=0===t.shapeDegree?this.parent.transform.degree:this.parent.transform.degree-t.shapeDegree)<0&&(o=360+o);for(var a=0;a<t.flipObjColl.length;a++)"horizontal"===t.flipObjColl[a].toLowerCase()?r=!0:"vertical"===t.flipObjColl[a].toLowerCase()&&(n=!0);return 0===o||360===o?i=n?{x:t.topCenterCircle.startX,y:t.topCenterCircle.startY-t.rotationCircleLine}:{x:t.bottomCenterCircle.startX,y:t.bottomCenterCircle.startY+t.rotationCircleLine}:90===o||-270===o?i=r?{x:t.centerRightCircle.startX+t.rotationCircleLine,y:t.centerLeftCircle.startY}:{x:t.centerLeftCircle.startX-t.rotationCircleLine,y:t.centerLeftCircle.startY}:180===o||-180===o?i=n?{x:t.bottomCenterCircle.startX,y:t.bottomCenterCircle.startY+t.rotationCircleLine}:{x:t.topCenterCircle.startX,y:t.topCenterCircle.startY-t.rotationCircleLine}:270!==o&&-90!==o||(i=r?{x:t.centerLeftCircle.startX-t.rotationCircleLine,y:t.centerLeftCircle.startY}:{x:t.centerRightCircle.startX+t.rotationCircleLine,y:t.centerLeftCircle.startY}),e&&(e.rotationCirclePoint=i),i},o}(),d=function(){function i(t){this.textSettings={text:"Enter Text",fontFamily:"Arial",fontSize:null,fontRatio:null,bold:!1,italic:!1,underline:!1},this.strokeSettings={strokeColor:"#fff",fillColor:"",strokeWidth:null},this.keyHistory="",this.parent=t,this.addEventListener()}return i.prototype.destroy=function(){this.parent.isDestroyed||this.removeEventListener()},i.prototype.addEventListener=function(){this.parent.on("shape",this.shape,this),this.parent.on("destroyed",this.destroy,this)},i.prototype.removeEventListener=function(){this.parent.off("shape",this.shape),this.parent.off("destroyed",this.destroy)},i.prototype.shape=function(t){switch(this.initShapePvtProps(),t.prop){case"drawEllipse":this.drawEllipse(t.value.x,t.value.y,t.value.radiusX,t.value.radiusY,t.value.strokeWidth,t.value.strokeColor,t.value.fillColor);break;case"drawLine":this.drawLine(t.value.startX,t.value.startY,t.value.endX,t.value.endY,t.value.strokeWidth,t.value.strokeColor);break;case"drawArrow":this.drawArrow(t.value.startX,t.value.startY,t.value.endX,t.value.endY,t.value.strokeWidth,t.value.strokeColor,t.value.arrowStart,t.value.arrowEnd);break;case"drawPath":this.drawPath(t.value.pointColl,t.value.strokeWidth,t.value.strokeColor);break;case"drawRectangle":this.drawRectangle(t.value.x,t.value.y,t.value.width,t.value.height,t.value.strokeWidt,t.value.strokeColor,t.value.fillColor);break;case"drawText":this.drawText(t.value.x,t.value.y,t.value.text,t.value.fontFamily,t.value.fontSize,t.value.bold,t.value.italic,t.value.color);break;case"redrawActObj":this.redrawActObj(t.value.x,t.value.y,t.value.isMouseDown);break;case"apply":this.apply(t.value.shape,t.value.obj,t.value.canvas);break;case"updateShapeChangeEventArgs":this.updateShapeChangeEventArgs(t.value.shapeSettings);break;case"updSelChangeEventArgs":this.updSelChangeEventArgs(t.value.selectionSettings);break;case"iterateObjColl":this.iterateObjColl();break;case"updImgRatioForActObj":this.updImgRatioForActObj();break;case"zoomObjColl":this.zoomObjColl(t.value.isPreventApply);break;case"redrawObj":this.redrawObj(t.value.degree);break;case"rotateObjColl":this.rotateObjColl();break;case"draw-shape-text":this.drawShapeText();break;case"redraw-text":this.redrawText();break;case"draw-shape":this.drawShape(t.value.obj,t.value.strokeWidth,t.value.strokeColor,t.value.fillColor,t.value.start,t.value.width,t.value.height);break;case"renderTextArea":this.renderTextArea(t.value.x,t.value.y,t.value.actObj);break;case"setTextBoxWidth":this.setTextBoxWidth(t.value.e);break;case"findTextTarget":this.findTextTarget(t.value.e);break;case"panObjColl":this.panObjColl(t.value.xDiff,t.value.yDiff,t.value.panRegion);break;case"updateFontStyles":this.updateFontStyles(t.value.isTextBox);break;case"applyFontStyle":this.applyFontStyle(t.value.item);break;case"updateFontRatio":this.updateFontRatio(t.value.obj,t.value.isTextArea);break;case"updateFontSize":this.updateFontSize(t.value.obj);break;case"updateObjColl":this.updateObjColl(t.value.item,t.value.objColl);break;case"pushActItemIntoObj":this.pushActItemIntoObj();break;case"clearActObj":this.clearActObj();break;case"refreshActiveObj":this.refreshActiveObj();break;case"applyActObj":this.applyActObj(t.value.isMouseDown);break;case"wireEvent":e.EventHandler.add(this.parent.upperCanvas,"dblclick",this.findTextTarget,this),e.EventHandler.add(this.parent.textArea,"mousedown",this.findTextTarget,this);break;case"unWireEvent":e.EventHandler.remove(this.parent.upperCanvas,"dblclick",this.findTextTarget),e.EventHandler.remove(this.parent.textArea,"mousedown",this.findTextTarget);break;case"getShapeSetting":this.getShapeSetting(t.value.id,t.value.obj);break;case"getShapeSettings":this.getShapeSettings(t.value.obj);break;case"isPointsInRange":this.isPointsInRange(t.value.x,t.value.y,t.value.obj);break;case"alignRotateFlipColl":this.alignRotateFlipColl(t.value.collection,t.value.isRotateFlipCollection,t.value.obj);break;case"selectShape":this.selectShape(t.value.id,t.value.obj);break;case"deleteShape":this.deleteShape(t.value.id);break;case"getMaxText":this.getMaxText(t.value.isTextBox,t.value.text,t.value.obj);break;case"setPointCollForLineArrow":t.value.obj.pointColl=this.getLinePoints(t.value.obj.activePoint.startX,t.value.obj.activePoint.startY,t.value.obj.activePoint.endX,t.value.obj.activePoint.endY);break;case"setPointCollForShapeRotation":this.setPointCollForShapeRotation(t.value.obj);break;case"setTextSettings":t.value.textSettings?this.textSettings=t.value.textSettings:t.value.fontFamily?this.textSettings.fontFamily=t.value.fontFamily:t.value.fontSize&&(this.textSettings.fontSize=t.value.fontSize);break;case"setStrokeSettings":t.value.strokeSettings?this.strokeSettings=t.value.strokeSettings:t.value.strokeColor?this.strokeSettings.strokeColor=t.value.strokeColor:t.value.fillColor?this.strokeSettings.fillColor=t.value.fillColor:t.value.strokeWidth&&(this.strokeSettings.strokeWidth=t.value.strokeWidth);break;case"getStrokeSettings":t.value.obj.strokeSettings=this.strokeSettings;break;case"setKeyHistory":this.keyHistory=t.value.keyHistory;break;case"getKeyHistory":t.value.obj.keyHistory=this.keyHistory;break;case"setTextBoxPos":this.setTextBoxPos(t.value.actObj,t.value.degree,t.value.flip,t.value.x,t.value.y);break;case"setTextBoxPoints":this.setTextBoxPoints(t.value.actObj,t.value.degree,t.value.flip,t.value.x,t.value.y);break;case"alignTextAreaIntoCanvas":this.alignTextAreaIntoCanvas();break;case"initializeTextShape":this.initializeTextShape(t.value.text,t.value.fontFamily,t.value.fontSize,t.value.bold,t.value.italic,t.value.strokeColor);break;case"stopPathDrawing":this.stopPathDrawing(t.value.e);break;case"updateArrowRatio":this.updateArrowRatio(t.value.obj);break;case"reset":this.reset()}},i.prototype.getModuleName=function(){return"shape"},i.prototype.initShapePvtProps=function(){this.parent.lowerCanvas&&(this.lowerContext=this.parent.lowerCanvas.getContext("2d")),this.parent.upperCanvas&&(this.upperContext=this.parent.upperCanvas.getContext("2d"))},i.prototype.reset=function(){this.textSettings={text:"Enter Text",fontFamily:"Arial",fontSize:null,fontRatio:null,bold:!1,italic:!1,underline:!1},this.strokeSettings={strokeColor:"#fff",fillColor:"",strokeWidth:null}},i.prototype.drawEllipse=function(t,e,i,o,r,n,a){this.initializeShape("ellipse");var s={x:t,y:e};this.drawShape("ellipse",r,n,a,s,i,o)},i.prototype.drawLine=function(t,e,i,o,r,n){this.initializeShape("line");var a={x:t,y:e},s=i-t,l=o-e;this.drawShape("line",r,n,null,a,s,l)},i.prototype.drawPath=function(t,e,i){this.initializeShape("path"),this.drawShape("path",e,i,null,null,null,null,t)},i.prototype.drawArrow=function(t,e,i,o,r,n,a,s){this.initializeShape("arrow");var l={x:t,y:e},p=i-t,h=o-e;this.drawShape("arrow",r,n,null,l,p,h,null,a,s)},i.prototype.drawRectangle=function(t,e,i,o,r,n,a){this.initializeShape("rectangle");var s={x:t,y:e};this.drawShape("rectangle",r,n,a,s,i,o)},i.prototype.drawText=function(t,e,i,o,r,n,a,s){this.drawShapeText(i,o,r,n,a,s,t,e)},i.prototype.initializeShape=function(t){this.redrawActObj(),this.parent.activeObj.shape=t,"freehanddraw"===this.parent.currObjType.shape&&(this.apply(),this.parent.upperCanvas.style.cursor=this.parent.cursor="default",this.parent.currObjType.shape=""),this.parent.currObjType.isCustomCrop=!1},i.prototype.updateWidthHeight=function(t){return t.activePoint.width=t.activePoint.endX-t.activePoint.startX,t.activePoint.height=t.activePoint.endY-t.activePoint.startY,t},i.prototype.setDimension=function(t,e){t&&e&&(this.parent.activeObj.activePoint.width=t,this.parent.activeObj.activePoint.height=e,"ellipse"===this.parent.currObjType.shape.toLowerCase()&&(this.parent.activeObj.activePoint.width=2*t,this.parent.activeObj.activePoint.height=2*e))},i.prototype.getArrowType=function(t){var e=t;if(t){e={None:"none",Arrow:"arrow",SolidArrow:"arrowSolid",Circle:"circle",SolidCircle:"circleSolid",Square:"square",SolidSquare:"squareSolid",Bar:"bar"}[""+t]}return e},i.prototype.drawShape=function(t,i,o,r,n,a,s,l,p,h){var c=this,d=this.parent;if(!d.disabled&&d.isImageLoaded){d.notify("draw",{prop:"setImageEdited",onPropertyChange:!1}),this.redrawActObj();var v=e.extend([],d.objColl,[],!0);if(d.togglePen=!1,this.keyHistory="",this.parent.upperCanvas.style.display="block",this.refreshActiveObj(),d.currObjType.shape=t,"path"===d.currObjType.shape.toLowerCase()&&e.isNullOrUndefined(l))d.activeObj.shape=d.currObjType.shape.toLowerCase(),d.activeObj.pointColl=[],d.upperCanvas.style.cursor=this.parent.cursor="crosshair",d.notify("selection",{prop:"setCurrentDrawingShape",onPropertyChange:!1,value:{value:"path"}}),e.isBlazor()||(d.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"shapes",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}}),d.notify("toolbar",{prop:"update-toolbar-items",onPropertyChange:!1}));else if("freehanddraw"!==d.currObjType.shape.toLowerCase()&&""!==d.currObjType.shape.toLowerCase()){d.activeObj.shape=d.currObjType.shape.toLowerCase(),this.upperContext.clearRect(0,0,d.upperCanvas.width,d.upperCanvas.height),e.isNullOrUndefined(d.activeObj.strokeSettings)&&(d.activeObj.strokeSettings=this.strokeSettings),"path"===d.currObjType.shape.toLowerCase()&&l&&(d.activeObj.pointColl=l),d.activeObj.strokeSettings.strokeWidth=i||d.activeObj.strokeSettings.strokeWidth,d.activeObj.strokeSettings.strokeColor=o||d.activeObj.strokeSettings.strokeColor,d.activeObj.strokeSettings.fillColor=r||d.activeObj.strokeSettings.fillColor;var u=d.img.destWidth>100?100:d.img.destWidth/2,g=d.img.destHeight>100?100:d.img.destHeight/2;d.activeObj.activePoint.width=u,d.activeObj.activePoint.height=g,"line"===d.currObjType.shape.toLowerCase()||"arrow"===d.currObjType.shape.toLowerCase()?(d.activeObj.lineDraw="horizontal",d.activeObj.activePoint.height=0,"arrow"===d.currObjType.shape.toLowerCase()&&(d.activeObj.activePoint.width+=50,d.activeObj.start=this.getArrowType(p),d.activeObj.end=this.getArrowType(h))):"rectangle"===d.currObjType.shape.toLowerCase()&&(d.activeObj.activePoint.width+=d.activeObj.activePoint.width/2),this.setDimension(a,s),n?(d.activeObj.activePoint.startX=n.x,d.activeObj.activePoint.startY=n.y,d.activeObj.activePoint.endX=d.activeObj.activePoint.startX+d.activeObj.activePoint.width,d.activeObj.activePoint.endY=d.activeObj.activePoint.startY+d.activeObj.activePoint.height):this.setCenterPoints(),this.setPointCollForLineAndArrow(),"arrow"===d.currObjType.shape.toLowerCase()&&(d.activeObj.triangleDirection="right"),d.currObjType.isDragging=d.currObjType.isCustomCrop=!1,d.activeObj.shapeDegree=d.transform.degree,d.activeObj.shapeFlip=d.transform.currFlipState,d.activeObj.textFlip=d.transform.currFlipState,d.activeObj.flipObjColl=[];var b={shapeSettingsObj:{}};d.notify("selection",{prop:"updatePrevShapeSettings",onPropertyChange:!1,value:{obj:b}});var C=b.shapeSettingsObj,f={action:"insert",previousShapeSettings:C,currentShapeSettings:C};e.isBlazor()&&d.events&&!0===d.events.shapeChanging.hasDelegate?this.parent.dotNetRef.invokeMethodAsync("ShapeEventAsync","OnShape",f).then(function(t){c.updateShapeChangeEventArgs(t.currentShapeSettings),c.setDimension(a,s),d.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate"}}),d.updateToolbar(d.element,"quickAccessToolbar","shape"),d.notify("selection",{prop:"isShapeInserted",onPropertyChange:!1,value:{bool:!0}}),d.notify("undo-redo",{prop:"updateUrObj",onPropertyChange:!1,value:{objColl:v}}),d.isPublicMethod&&d.notify("undo-redo",{prop:"updateUndoRedo",onPropertyChange:!1}),d.isPublicMethod=!1}):(d.trigger("shapeChanging",f),this.updateShapeChangeEventArgs(f.currentShapeSettings),this.setDimension(a,s),d.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate"}}),e.isBlazor()?d.updateToolbar(d.element,"quickAccessToolbar","shape"):d.notify("toolbar",{prop:"renderQAT",onPropertyChange:!1,value:{isPenEdit:null}}),d.notify("selection",{prop:"isShapeInserted",onPropertyChange:!1,value:{bool:!0}}),d.notify("undo-redo",{prop:"updateUrObj",onPropertyChange:!1,value:{objColl:v}}),d.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"shapes",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}}),d.notify("toolbar",{prop:"update-toolbar-items",onPropertyChange:!1}),d.isPublicMethod&&d.notify("undo-redo",{prop:"updateUndoRedo",onPropertyChange:!1}),d.isPublicMethod=!1)}}},i.prototype.setPointCollForLineAndArrow=function(){var t=this.parent;if(("line"===t.activeObj.shape||"arrow"===t.activeObj.shape)&&(t.activeObj.pointColl=this.getLinePoints(t.activeObj.activePoint.startX,t.activeObj.activePoint.startY,t.activeObj.activePoint.endX,t.activeObj.activePoint.endY),!e.isNullOrUndefined(t.activeObj.pointColl)))for(var i=0,o=t.activeObj.pointColl.length;i<o;i++)t.activeObj.pointColl[i].ratioX=(t.activeObj.pointColl[i].x-t.img.destLeft)/t.img.destWidth,t.activeObj.pointColl[i].ratioY=(t.activeObj.pointColl[i].y-t.img.destTop)/t.img.destHeight},i.prototype.drawShapeText=function(t,i,o,r,n,a,s,l){var p=this,h=this.parent;if(!h.disabled&&h.isImageLoaded){"freehanddraw"===h.currObjType.shape&&(this.apply(),h.upperCanvas.style.cursor=h.cursor="default",h.currObjType.shape=""),h.notify("draw",{prop:"setImageEdited",onPropertyChange:!1}),h.togglePen=!1,this.redrawActObj();var c={currObj:{}};h.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:c}}),this.prevObj=c.currObj,this.prevObj.objColl=e.extend([],h.objColl,[],!0),this.prevObj.pointColl=e.extend([],h.pointColl,[],!0),this.prevObj.afterCropActions=e.extend([],h.afterCropActions,[],!0);var d={selPointColl:null};h.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:d}}),this.prevObj.selPointColl=e.extend([],d.selPointColl,[],!0),this.refreshActiveObj(),h.activeObj.shape=h.currObjType.shape="text",h.currObjType.isCustomCrop=!1,this.initializeTextShape(t,i,o,r,n,a),h.currObjType.isText=h.currObjType.isInitialText=!0,e.isNullOrUndefined(h.activeObj.textSettings.fontSize)&&(h.img.destWidth>h.img.destHeight?h.activeObj.textSettings.fontSize=h.img.destWidth/15:h.activeObj.textSettings.fontSize=h.img.destHeight/15,h.activeObj.textSettings.fontSize<20&&(h.activeObj.textSettings.fontSize=20)),h.img.destWidth<100?h.activeObj.textSettings.fontSize=Math.floor(h.img.destWidth/20):h.img.destHeight<100&&(h.activeObj.textSettings.fontSize=Math.floor(h.img.destHeight/20)),h.activeObj.shapeDegree=h.transform.degree,h.activeObj.shapeFlip=h.transform.currFlipState,h.activeObj.flipObjColl=[],this.updateFontStyles();var v=this.upperContext.measureText(h.activeObj.textSettings.text).width+.5*h.activeObj.textSettings.fontSize,u=h.activeObj.textSettings.fontSize+.25*h.activeObj.textSettings.fontSize;e.isNullOrUndefined(s)||e.isNullOrUndefined(l)?this.setCenterPoints(!0,v,u):(h.activeObj.activePoint.startX=s,h.activeObj.activePoint.startY=l,h.activeObj.activePoint.endX=h.activeObj.activePoint.startX+v,h.activeObj.activePoint.endY=h.activeObj.activePoint.startY+u);var g={shapeSettingsObj:{}};h.notify("selection",{prop:"updatePrevShapeSettings",onPropertyChange:!1,value:{obj:g}});var b=g.shapeSettingsObj,C={action:"insert",previousShapeSettings:b,currentShapeSettings:b};e.isBlazor()&&h.events&&!0===h.events.shapeChanging.hasDelegate?h.dotNetRef.invokeMethodAsync("ShapeEventAsync","OnShape",C).then(function(t){p.drawShapeTextEvent(t),h.isPublicMethod&&h.notify("undo-redo",{prop:"updateUndoRedo",onPropertyChange:!1}),h.isPublicMethod=!1}):(h.trigger("shapeChanging",C),this.drawShapeTextEvent(C),h.isPublicMethod&&h.notify("undo-redo",{prop:"updateUndoRedo",onPropertyChange:!1}),h.isPublicMethod=!1)}},i.prototype.drawShapeTextEvent=function(t){var i=this.parent;this.updateShapeChangeEventArgs(t.currentShapeSettings),this.addLetter(i.activeObj.textSettings.text),i.activeObj.textFlip=i.transform.currFlipState,this.updateFontRatio(i.activeObj),i.objColl.push(i.activeObj);var o=e.extend({},i.cropObj,{},!0);i.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"shapeTransform",previousObj:this.prevObj,previousObjColl:this.prevObj.objColl,previousPointColl:this.prevObj.pointColl,previousSelPointColl:this.prevObj.selPointColl,previousCropObj:o,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),i.notify("selection",{prop:"redrawShape",onPropertyChange:!1,value:{obj:i.objColl[i.objColl.length-1]}}),e.isBlazor()?i.updateToolbar(i.element,"quickAccessToolbar","text"):i.notify("toolbar",{prop:"renderQAT",onPropertyChange:!1,value:{isPenEdit:null}}),i.notify("selection",{prop:"isShapeInserted",onPropertyChange:!1,value:{bool:!0}}),e.isBlazor()||(i.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"text",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}}),i.notify("toolbar",{prop:"update-toolbar-items",onPropertyChange:!1}))},i.prototype.initializeTextShape=function(t,i,o,r,n,a){var s=this.parent;this.keyHistory="",s.upperCanvas.style.display="block",e.isNullOrUndefined(s.activeObj.textSettings)&&(s.activeObj.textSettings=this.textSettings),e.isNullOrUndefined(s.activeObj.strokeSettings)&&(s.activeObj.strokeSettings=this.strokeSettings),s.activeObj.strokeSettings.strokeColor=a||s.activeObj.strokeSettings.strokeColor,s.activeObj.textSettings.text=t||s.activeObj.textSettings.text,s.activeObj.textSettings.fontFamily=i||s.activeObj.textSettings.fontFamily,s.activeObj.textSettings.fontSize=o||s.activeObj.textSettings.fontSize,s.activeObj.textSettings.bold=r||s.activeObj.textSettings.bold,s.activeObj.textSettings.italic=n||s.activeObj.textSettings.italic},i.prototype.redrawActObj=function(t,e,i){var o,r=this.parent;r.activeObj.shape&&(o=r.activeObj.shape.split("-")),r.activeObj.horTopLine&&r.activeObj.shape&&"crop"!==o[0]&&("block"===r.textArea.style.display?(r.notify("selection",{prop:"setTextBoxStylesToActObj",onPropertyChange:!1}),this.updateFontRatio(r.activeObj,!0),t&&e?t!==r.activeObj.activePoint.startX&&e!==r.activeObj.activePoint.startY&&(this.updateTextFromTextArea(),this.applyActObj()):(this.updateTextFromTextArea(),this.apply(r.activeObj.shape,r.activeObj),r.objColl.push(r.activeObj),this.refreshActiveObj(),r.textArea.style.transform="",r.notify("toolbar",{prop:"refresh-main-toolbar",onPropertyChange:!1}))):this.applyActObj(i))},i.prototype.apply=function(t,i,o){var r=this.parent;if(!r.disabled)if(r.togglePen&&!r.currObjType.isCustomCrop){var n=r.img.destLeft,a=r.img.destTop,s=r.img.destWidth,l=r.img.destHeight;r.notify("draw",{prop:"callUpdateCurrTransState",onPropertyChange:!1});var p=this.lowerContext.filter;this.lowerContext.filter="none",r.togglePen=!1,this.iterateObjColl(),r.notify("freehandDraw",{prop:"freehandRedraw",onPropertyChange:!1,value:{context:this.lowerContext,points:null}}),r.togglePen=!1,(r.isCircleCrop||r.currSelectionPoint&&"crop-circle"===r.currSelectionPoint.shape)&&r.notify("crop",{prop:"cropCircle",onPropertyChange:!1,value:{context:this.lowerContext,isSave:null,isFlip:null}}),r.img.destLeft=n,r.img.destTop=a,r.img.destWidth=s,r.img.destHeight=l,this.lowerContext.filter=p}else o=o||"original",e.isNullOrUndefined(r.activeObj.shape)&&e.isNullOrUndefined(t)?r.currObjType.shape="":r.currObjType.shape=t||r.currObjType.shape,""!==r.currObjType.shape&&(this.upperContext.clearRect(0,0,r.upperCanvas.width,r.upperCanvas.height),"text"===r.activeObj.shape?(r.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:o,obj:i,isCropRatio:null,points:null,isPreventDrag:!0,saveContext:null,isPreventSelection:null}}),r.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.lowerContext}})):r.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:o,obj:i}}),r.activeObj.shape=r.currObjType.shape.toLowerCase(),t||""===r.currObjType.shape||r.currObjType.isCustomCrop||r.objColl.push(e.extend({},r.activeObj,{},!0)),this.keyHistory="")},i.prototype.setCenterPoints=function(t,e,i){var o,r,n=this.parent;t&&e&&i?(o=e,r=i):(o=n.activeObj.activePoint.width,r=n.activeObj.activePoint.height),n.activeObj.activePoint.startX=n.lowerCanvas.width/2-o/2,n.activeObj.activePoint.startY=n.lowerCanvas.height/2-r/2,n.activeObj.activePoint.endX=n.lowerCanvas.width/2+o/2,n.activeObj.activePoint.endY=n.lowerCanvas.height/2+r/2},i.prototype.updSelChangeEventArgs=function(t){var e=this.parent;e.activeObj.activePoint.startX=t.startX,e.activeObj.activePoint.startY=t.startY,e.activeObj.activePoint.width=t.width,e.activeObj.activePoint.height=t.height,e.activeObj.activePoint.endX=e.activeObj.activePoint.startX+e.activeObj.activePoint.width,e.activeObj.activePoint.endY=e.activeObj.activePoint.startY+e.activeObj.activePoint.height},i.prototype.updateShapeChangeEventArgs=function(t){var e=this.parent;switch(e.activeObj.currIndex=t.id,e.activeObj.activePoint.startX=t.startX,e.activeObj.activePoint.startY=t.startY,e.activeObj.activePoint.width=t.width,e.activeObj.activePoint.height=t.height,e.activeObj.activePoint.endX=e.activeObj.activePoint.startX+e.activeObj.activePoint.width,e.activeObj.activePoint.endY=e.activeObj.activePoint.startY+e.activeObj.activePoint.height,e.activeObj.strokeSettings.strokeColor=t.strokeColor,e.activeObj.strokeSettings.fillColor=t.fillColor,e.activeObj.shape){case"ellipse":e.activeObj.activePoint.width=t.radius/2;break;case"line":case"arrow":e.activeObj.activePoint.width=t.length;break;case"text":e.activeObj.keyHistory=t.text,e.activeObj.textSettings.fontSize=t.fontSize,e.activeObj.strokeSettings.strokeColor=t.color}if("text"===e.activeObj.shape&&e.activeObj.textSettings)for(var i=0;i<t.fontStyle.length;i++)switch(t.fontStyle[i]){case"bold":e.activeObj.textSettings.bold=!0;break;case"italic":e.activeObj.textSettings.italic=!0;break;case"underline":e.activeObj.textSettings.underline=!0}},i.prototype.addLetter=function(t){var e=this.parent;if("none"===e.textArea.style.display&&(e.currObjType.isText||"text"===e.activeObj.shape)){"Backspace"===t?this.keyHistory=this.keyHistory.slice(0,-1):this.keyHistory+=t,this.upperContext.clearRect(0,0,e.upperCanvas.width,e.upperCanvas.height),this.updateFontStyles();var i=this.upperContext.measureText(this.keyHistory).width+.5*e.activeObj.textSettings.fontSize,o=e.activeObj.textSettings.fontSize+.25*e.activeObj.textSettings.fontSize;this.upperContext.fillText(this.keyHistory,e.activeObj.activePoint.startX,e.activeObj.activePoint.startY+e.activeObj.textSettings.fontSize),this.upperContext.clearRect(0,0,e.upperCanvas.width,e.upperCanvas.height),e.currObjType.isText=!0,e.notify("selection",{prop:"setActivePoint",onPropertyChange:!1,value:{startX:i,startY:o}})}},i.prototype.redrawText=function(){var t=this.parent,e="";t.activeObj.textSettings.bold&&(e+="bold "),t.activeObj.textSettings.italic&&(e+="italic "),this.upperContext.font=e+t.activeObj.textSettings.fontSize+"px "+t.activeObj.textSettings.fontFamily;var i=t.activeObj.keyHistory.split("\n"),o="block"===t.textArea.style.display?this.getMaxText(!0):this.getMaxText(),r=this.upperContext.measureText(o).width+.5*t.activeObj.textSettings.fontSize,n=i.length*(t.activeObj.textSettings.fontSize+.25*t.activeObj.textSettings.fontSize);t.notify("selection",{prop:"setTextSelection",onPropertyChange:!1,value:{width:r,height:n}}),t.notify("draw",{prop:"updateActiveObject",onPropertyChange:!1,value:{actPoint:t.activeObj.activePoint,obj:t.activeObj,isMouseMove:null,x:null,y:null}}),t.notify("selection",{prop:"redrawShape",onPropertyChange:!1,value:{obj:t.activeObj}})},i.prototype.updateTextFromTextArea=function(){var t=this.parent;if(t.activeObj.keyHistory!==t.textArea.value){var i=e.extend({},t.cropObj,{},!0),o={currObj:{}};t.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:o}});var r=o.currObj;r.objColl=e.extend([],t.objColl,[],!0),r.pointColl=e.extend([],t.pointColl,[],!0),r.afterCropActions=e.extend([],this.parent.afterCropActions,[],!0);var n={selPointColl:null};t.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:n}}),r.selPointColl=e.extend([],n.selPointColl,[],!0),t.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"text",previousObj:r,previousObjColl:r.objColl,previousPointColl:r.pointColl,previousSelPointColl:r.selPointColl,previousCropObj:i,previousText:t.activeObj.keyHistory,currentText:t.textArea.value,previousFilter:null,isCircleCrop:null}})}t.activeObj.keyHistory=t.textArea.value,t.textArea.style.display="none",t.textArea.value="",this.updateFontStyles();var a=this.upperContext.measureText(t.activeObj.keyHistory).width+.5*t.activeObj.textSettings.fontSize,s=t.activeObj.textSettings.fontSize+.25*this.parent.activeObj.textSettings.fontSize,l=t.activeObj.keyHistory.split("\n");if(l.length>1){s*=l.length;for(var p=[],h=0,c=l.length;h<c;h++)p.push(this.upperContext.measureText(l[h]).width+.5*t.activeObj.textSettings.fontSize);a=Math.max.apply(Math,p)}t.notify("selection",{prop:"setTextSelection",onPropertyChange:!1,value:{width:a,height:s}}),t.notify("draw",{prop:"updateActiveObject",onPropertyChange:!1,value:{actPoint:t.activeObj.activePoint,obj:t.activeObj,isMouseMove:null,x:null,y:null}}),this.updImgRatioForActObj()},i.prototype.iterateObjColl=function(){for(var t=this.parent,e=0,i=t.objColl.length;e<i;e++)this.apply(t.objColl[e].shape,t.objColl[e]),this.refreshActiveObj()},i.prototype.updImgRatioForActObj=function(){var t=this.parent;t.activeObj.imageRatio={startX:(t.activeObj.activePoint.startX-t.img.destLeft)/t.img.destWidth,startY:(t.activeObj.activePoint.startY-t.img.destTop)/t.img.destHeight,endX:(t.activeObj.activePoint.endX-t.img.destLeft)/t.img.destWidth,endY:(t.activeObj.activePoint.endY-t.img.destTop)/t.img.destHeight,width:t.img.destWidth/t.activeObj.activePoint.width,height:t.img.destHeight/t.activeObj.activePoint.height},t.activeObj.rotationCirclePointColl&&(t.activeObj.rotationCirclePointColl.ratioX=(t.activeObj.rotationCirclePointColl.x-t.img.destLeft)/t.img.destWidth,t.activeObj.rotationCirclePointColl.ratioY=(t.activeObj.rotationCirclePointColl.y-t.img.destTop)/t.img.destHeight),"path"===t.activeObj.shape?this.updatePathRatio(t.activeObj):"arrow"===t.activeObj.shape&&this.updateArrowRatio(t.activeObj)},i.prototype.zoomObjColl=function(t){for(var i=this.parent,o=0,r=i.objColl.length;o<r;o++){var n=i.objColl[o];if(n.activePoint.startX=n.imageRatio.startX*i.img.destWidth+i.img.destLeft,n.activePoint.startY=n.imageRatio.startY*i.img.destHeight+i.img.destTop,n.activePoint.endX=n.imageRatio.endX*i.img.destWidth+i.img.destLeft,n.activePoint.endY=n.imageRatio.endY*i.img.destHeight+i.img.destTop,"text"===(n=this.updateWidthHeight(n)).shape)this.updateFontSize(n);else if("line"===n.shape||"arrow"===n.shape){n.pointColl=this.getLinePoints(n.activePoint.startX,n.activePoint.startY,n.activePoint.endX,n.activePoint.endY);for(var a=0,s=n.pointColl.length;a<s;a++)n.pointColl[a].ratioX=(n.pointColl[a].x-i.img.destLeft)/i.img.destWidth,n.pointColl[a].ratioY=(n.pointColl[a].y-i.img.destTop)/i.img.destHeight;"arrow"===n.shape&&this.updateArrowSize(n)}else if("path"===n.shape){for(var l=0,p=n.pointColl.length;l<p;l++)n.pointColl[l].x=n.pointColl[l].ratioX*i.img.destWidth+i.img.destLeft,n.pointColl[l].y=n.pointColl[l].ratioY*i.img.destHeight+i.img.destTop;this.updatePathRatio(n)}if(i.notify("draw",{prop:"updateActiveObject",onPropertyChange:!1,value:{actPoint:n.activePoint,obj:n}}),e.isNullOrUndefined(t)){var h=this.lowerContext.filter;this.lowerContext.filter="none",this.apply(n.shape,n),this.refreshActiveObj(),this.lowerContext.filter=h}"line"!==n.shape&&"arrow"!==n.shape&&"path"!==n.shape&&0!==n.rotatedAngle&&(this.setPointCollForShapeRotation(n),n.rotationCirclePoint.x=n.rotationCirclePoint.ratioX*i.img.destWidth+i.img.destLeft,n.rotationCirclePoint.y=n.rotationCirclePoint.ratioY*i.img.destHeight+i.img.destTop,n.rotationCirclePointColl.x=n.rotationCirclePointColl.ratioX*i.img.destWidth+i.img.destLeft,n.rotationCirclePointColl.y=n.rotationCirclePointColl.ratioY*i.img.destHeight+i.img.destTop)}},i.prototype.redrawObj=function(t){var e=this.parent;if(this.parent.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 i=this.lowerContext.filter;this.lowerContext.filter="brightness(1) contrast(100%) hue-rotate(0deg) saturate(100%) opacity(1) blur(0px) sepia(0%) grayscale(0%) invert(0%)";for(var o=0,r=e.objColl.length;o<r;o++){"crop"!==e.objColl[o].shape.split("-")[0]&&this.apply(e.objColl[o].shape,e.objColl[o])}this.lowerContext.filter=i}},i.prototype.updateCurrentActiveObjPoint=function(t){for(var i,o=this.parent,r=0,n=o.objColl.length;r<n;r++){var a=o.objColl[r];if(o.activeObj.shape===a.shape&&o.activeObj.activePoint.startX===a.activePoint.startX&&o.activeObj.activePoint.startY===a.activePoint.startY&&o.activeObj.activePoint.endX===a.activePoint.endX&&o.activeObj.activePoint.endY===a.activePoint.endY&&o.activeObj.currIndex===a.currIndex){i=r;break}}if("horizontal"===t||"vertical"===t||"Horizontal"===t||"Vertical"===t||"horizontalvertical"===t||"verticalhorizontal"===t){if("horizontal"===t||"Horizontal"===t){var s=0;for(n=o.objColl.length;s<n;s++){(a=o.objColl[s]).shapeFlip!==o.transform.currFlipState&&(a.activePoint.startX<=o.img.destLeft+o.img.destWidth/2?(a.activePoint.endX=o.img.destLeft+o.img.destWidth-(a.activePoint.startX-o.img.destLeft),a.activePoint.startX=a.activePoint.endX-a.activePoint.width,o.notify("draw",{prop:"updateActiveObject",onPropertyChange:!1,value:{actPoint:a.activePoint,obj:a}})):a.activePoint.startX>=o.img.destLeft+o.img.destWidth/2&&(a.activePoint.startX=o.img.destLeft+(o.img.destLeft+o.img.destWidth-a.activePoint.endX),a.activePoint.endX=a.activePoint.startX+a.activePoint.width,o.notify("draw",{prop:"updateActiveObject",onPropertyChange:!1,value:{actPoint:a.activePoint,obj:a}})),"line"===a.shape||"arrow"===a.shape||"path"===a.shape?this.flipLineArrowObj(a,"horizontal"):0!==a.rotatedAngle&&(a.rotatedAngle=a.rotatedAngle+2*(Math.PI-a.rotatedAngle),a.rotationCirclePointColl.x<=o.img.destLeft+o.img.destWidth/2?a.rotationCirclePointColl.x=o.img.destLeft+o.img.destWidth-(a.rotationCirclePointColl.x-o.img.destLeft):a.rotationCirclePointColl.x>=o.img.destLeft+o.img.destWidth/2&&(a.rotationCirclePointColl.x=o.img.destLeft+(o.img.destLeft+o.img.destWidth-a.rotationCirclePointColl.x)),a.rotationCirclePointColl.ratioX=(a.rotationCirclePointColl.x-o.img.destLeft)/o.img.destWidth),a.shapeFlip=o.transform.currFlipState,a.imageRatio={startX:(a.activePoint.startX-o.img.destLeft)/o.img.destWidth,startY:(a.activePoint.startY-o.img.destTop)/o.img.destHeight,endX:(a.activePoint.endX-o.img.destLeft)/o.img.destWidth,endY:(a.activePoint.endY-o.img.destTop)/o.img.destHeight,width:o.img.destWidth/a.activePoint.width,height:o.img.destHeight/a.activePoint.height})}}else if("vertical"===t||"Vertical"===t)for(s=0;s<o.objColl.length;s++){(a=o.objColl[s]).shapeFlip!==o.transform.currFlipState&&(a.activePoint.startY<=o.img.destTop+o.img.destHeight/2?(a.activePoint.endY=o.img.destTop+o.img.destHeight-(a.activePoint.startY-o.img.destTop),a.activePoint.startY=a.activePoint.endY-a.activePoint.height,o.notify("draw",{prop:"updateActiveObject",onPropertyChange:!1,value:{actPoint:a.activePoint,obj:a}})):a.activePoint.startY>=this.parent.lowerCanvas.height/2&&(a.activePoint.startY=o.img.destTop+(o.img.destTop+o.img.destHeight-a.activePoint.endY),a.activePoint.endY=a.activePoint.startY+a.activePoint.height,o.notify("draw",{prop:"updateActiveObject",onPropertyChange:!1,value:{actPoint:a.activePoint,obj:a}})),"line"===a.shape||"arrow"===a.shape||"path"===a.shape?this.flipLineArrowObj(a,"vertical"):0!==a.rotatedAngle&&(a.rotatedAngle=-a.rotatedAngle,a.rotationCirclePointColl.y<=o.img.destTop+o.img.destHeight/2?a.rotationCirclePointColl.y=o.img.destTop+o.img.destHeight-(a.rotationCirclePointColl.y-o.img.destTop):a.rotationCirclePointColl.y>=o.img.destTop+o.img.destHeight/2&&(a.rotationCirclePointColl.y=o.img.destTop+(o.img.destTop+o.img.destHeight-a.rotationCirclePointColl.y)),a.rotationCirclePointColl.ratioY=(a.rotationCirclePointColl.y-o.img.destTop)/o.img.destHeight),a.shapeFlip=o.transform.currFlipState,a.imageRatio={startX:(a.activePoint.startX-o.img.destLeft)/o.img.destWidth,startY:(a.activePoint.startY-o.img.destTop)/o.img.destHeight,endX:(a.activePoint.endX-o.img.destLeft)/o.img.destWidth,endY:(a.activePoint.endY-o.img.destTop)/o.img.destHeight,width:o.img.destWidth/a.activePoint.width,height:o.img.destHeight/a.activePoint.height})}else if("verticalhorizontal"===t||"horizontalvertical"===t)for(s=0,n=o.objColl.length;s<n;s++){(a=o.objColl[s]).shapeFlip!==o.transform.currFlipState&&(a.activePoint.startX<=o.img.destLeft+o.img.destWidth/2?(a.activePoint.endX=o.img.destLeft+o.img.destWidth-(a.activePoint.startX-o.img.destLeft),a.activePoint.startX=a.activePoint.endX-a.activePoint.width,o.notify("draw",{prop:"updateActiveObject",onPropertyChange:!1,value:{actPoint:a.activePoint,obj:a}})):a.activePoint.startX>=o.img.destLeft+o.img.destWidth/2&&(a.activePoint.startX=o.img.destLeft+(o.img.destLeft+o.img.destWidth-a.activePoint.endX),a.activePoint.endX=a.activePoint.startX+a.activePoint.width,o.notify("draw",{prop:"updateActiveObject",onPropertyChange:!1,value:{actPoint:a.activePoint,obj:a}})),a.activePoint.startY<=o.img.destTop+o.img.destHeight/2?(a.activePoint.endY=o.img.destTop+o.img.destHeight-(a.activePoint.startY-o.img.destTop),a.activePoint.startY=a.activePoint.endY-a.activePoint.height,o.notify("draw",{prop:"updateActiveObject",onPropertyChange:!1,value:{actPoint:a.activePoint,obj:a}})):a.activePoint.startY>=this.parent.lowerCanvas.height/2&&(a.activePoint.startY=o.img.destTop+(o.img.destTop+o.img.destHeight-a.activePoint.endY),a.activePoint.endY=a.activePoint.startY+a.activePoint.height,o.notify("draw",{prop:"updateActiveObject",onPropertyChange:!1,value:{actPoint:a.activePoint,obj:a}})),"line"!==a.shape&&"arrow"!==a.shape&&"path"!==a.shape||this.flipLineArrowObj(a,t),a.shapeFlip=o.transform.currFlipState,a.imageRatio={startX:(a.activePoint.startX-o.img.destLeft)/o.img.destWidth,startY:(a.activePoint.startY-o.img.destTop)/o.img.destHeight,endX:(a.activePoint.endX-o.img.destLeft)/o.img.destWidth,endY:(a.activePoint.endY-o.img.destTop)/o.img.destHeight,width:o.img.destWidth/a.activePoint.width,height:o.img.destHeight/a.activePoint.height})}void 0!==i&&(o.activeObj=e.extend({},o.objColl[i],{},!0))}else if(90===t)this.rotateObjColl();else if(-90===t)for(s=0;s<3;s++)this.rotateObjColl();else if("number"==typeof t)if(t>0)this.rotateObjColl();else for(s=0;s<3;s++)this.rotateObjColl()},i.prototype.rotateObjColl=function(){for(var t=this.parent,e=0,i=t.objColl.length;e<i;e++){(o=t.objColl[e]).activePoint.startY=t.img.destTop+t.img.destHeight*o.imageRatio.startX,o.activePoint.endY=t.img.destTop+t.img.destHeight*o.imageRatio.endX,o.activePoint.startX=t.img.destLeft+t.img.destWidth-t.img.destWidth*o.imageRatio.endY,o.activePoint.endX=t.img.destLeft+t.img.destWidth-t.img.destWidth*o.imageRatio.startY,o=this.updateWidthHeight(t.objColl[e]),this.updateFontSize(o),"line"===o.shape||"arrow"===o.shape||"path"===o.shape?(this.rotateLineArrowObj(o),"arrow"===o.shape&&this.updateArrowSize(o)):0!==o.rotatedAngle&&(o.rotationCirclePointColl.y=t.img.destTop+t.img.destHeight*o.rotationCirclePointColl.ratioX,o.rotationCirclePointColl.x=t.img.destLeft+t.img.destWidth-t.img.destWidth*o.rotationCirclePointColl.ratioY,o.rotationCirclePointColl.ratioX=(o.rotationCirclePointColl.x-t.img.destLeft)/t.img.destWidth,o.rotationCirclePointColl.ratioY=(o.rotationCirclePointColl.y-t.img.destTop)/t.img.destHeight)}for(e=0,i=t.objColl.length;e<i;e++)t.notify("draw",{prop:"updateActiveObject",onPropertyChange:!1,value:{actPoint:t.objColl[e].activePoint,obj:t.objColl[e]}});for(e=0,i=t.objColl.length;e<i;e++){var o;(o=t.objColl[e]).imageRatio={startX:(o.activePoint.startX-t.img.destLeft)/t.img.destWidth,startY:(o.activePoint.startY-t.img.destTop)/t.img.destHeight,endX:(o.activePoint.endX-t.img.destLeft)/t.img.destWidth,endY:(o.activePoint.endY-t.img.destTop)/t.img.destHeight,width:t.img.destWidth/o.activePoint.width,height:t.img.destHeight/o.activePoint.height}}},i.prototype.rotateLineArrowObj=function(t){if(!e.isNullOrUndefined(t.pointColl)){var i=this.parent;if(t.pointColl.length>0){for(var o=0;o<t.pointColl.length;o++)t.pointColl[o].y=i.img.destTop+i.img.destHeight*t.pointColl[o].ratioX,t.pointColl[o].x=i.img.destLeft+i.img.destWidth-i.img.destWidth*t.pointColl[o].ratioY;for(o=0;o<t.pointColl.length;o++)t.pointColl[o].ratioX=(t.pointColl[o].x-i.img.destLeft)/i.img.destWidth,t.pointColl[o].ratioY=(t.pointColl[o].y-i.img.destTop)/i.img.destHeight;var r=void 0;r=e.isNullOrUndefined(t.pointColl[t.pointColl.length-2])?{x:0,y:0}:{x:t.pointColl[t.pointColl.length-2].x,y:t.pointColl[t.pointColl.length-2].y};var n=t.pointColl[t.pointColl.length-1].x-r.x,a=t.pointColl[t.pointColl.length-1].y-r.y;t.activePoint.startX=t.pointColl[0].x,t.activePoint.startY=t.pointColl[0].y,t.activePoint.endX=t.pointColl[t.pointColl.length-1].x+n/2,t.activePoint.endY=t.pointColl[t.pointColl.length-1].y+a/2,t=this.updateWidthHeight(t)}}},i.prototype.flipLineArrowObj=function(t,i){if(!e.isNullOrUndefined(t.pointColl)&&("horizontal"===i.toLowerCase()?this.lineArrowHorizontalFlip(t):"vertical"===i.toLowerCase()?this.lineArrowVerticalFlip(t):(this.lineArrowHorizontalFlip(t),t.shapeFlip="",this.lineArrowVerticalFlip(t)),t.activePoint.startX=t.pointColl[0].x,t.activePoint.startY=t.pointColl[0].y,t.activePoint.endX=t.pointColl[t.pointColl.length-1].x,t.activePoint.endY=t.pointColl[t.pointColl.length-1].y,t.activePoint.startX>t.activePoint.endX)){var o=t.activePoint.startX;t.activePoint.startX=t.activePoint.endX,t.activePoint.endX=o,o=t.activePoint.startY,t.activePoint.startY=t.activePoint.endY,t.activePoint.endY=o}},i.prototype.lineArrowHorizontalFlip=function(t){var e=this.parent;if(t.shapeFlip!==e.transform.currFlipState){for(var i=0,o=t.pointColl.length;i<o;i++){var r=t.pointColl[i];r.x<=e.img.destLeft+e.img.destWidth/2?r.x=e.img.destLeft+e.img.destWidth-(r.x-e.img.destLeft):r.x>=e.img.destLeft+e.img.destWidth/2&&(r.x=e.img.destLeft+(e.img.destLeft+e.img.destWidth-r.x)),r.ratioX=(r.x-e.img.destLeft)/e.img.destWidth,r.ratioY=(r.y-e.img.destTop)/e.img.destHeight}if("arrow"===t.shape){var n=t.start;t.start=t.end,t.end=n}t.shapeFlip=e.transform.currFlipState}},i.prototype.lineArrowVerticalFlip=function(t){var e=this.parent;if(t.shapeFlip!==e.transform.currFlipState){for(var i=0,o=t.pointColl.length;i<o;i++){var r=t.pointColl[i];r.y<=e.img.destTop+e.img.destHeight/2?r.y=e.img.destTop+e.img.destHeight-(r.y-e.img.destTop):r.y>=e.img.destTop+e.img.destHeight/2&&(r.y=e.img.destTop+(e.img.destTop+e.img.destHeight-r.y)),r.ratioX=(r.x-e.img.destLeft)/e.img.destWidth,r.ratioY=(r.y-e.img.destTop)/e.img.destHeight}t.shapeFlip=e.transform.currFlipState}},i.prototype.getRotDegOfShape=function(t){var e;return(e=0===t.shapeDegree?this.parent.transform.degree:this.parent.transform.degree-t.shapeDegree)<0&&(e=360+e),e},i.prototype.renderTextArea=function(t,i,o){var r=this.parent,n=this.getRotDegOfShape(r.activeObj);this.transformTextArea(),e.isBlazor()?r.updateToolbar(r.element,"destroyQuickAccessToolbar"):r.notify("toolbar",{prop:"destroy-qa-toolbar",onPropertyChange:!1}),r.element.querySelector("#"+r.element.id+"_duplicate")&&r.element.querySelector("#"+r.element.id+"_duplicate").classList.add("e-disabled"),r.element.querySelector("#"+r.element.id+"_remove")&&r.element.querySelector("#"+r.element.id+"_remove").classList.add("e-disabled"),r.element.querySelector("#"+r.element.id+"_editText")&&r.element.querySelector("#"+r.element.id+"_editText").classList.add("e-disabled"),r.textArea.style.display="block",r.textArea.style.left=t+"px",r.textArea.style.top=i+"px",r.textArea.style.fontFamily=o.textSettings.fontFamily,r.textArea.style.fontSize=o.textSettings.fontSize+"px",r.textArea.style.color=o.strokeSettings.strokeColor,r.textArea.style.fontWeight=o.textSettings.bold?"bold":"normal",r.textArea.style.fontStyle=o.textSettings.italic?"italic":"normal",r.textArea.style.border="2px solid "+r.themeColl[r.theme].primaryColor,r.textArea.value=o.keyHistory,r.textArea.style.overflow="hidden",r.textArea.style.width="auto",r.textArea.style.height="auto",r.textArea.focus();r.transform.zoomFactor;var a=o.activePoint,s=a.width,l=a.height;n%90==0&&n%180!=0&&0!==n?(r.textArea.style.width=l+"px",r.textArea.style.height=s+"px"):(r.textArea.style.width=s+"px",r.textArea.style.height=l+"px"),this.setTextBoxWidth();var p={flipColl:null};r.notify("transform",{prop:"getFlipColl",onPropertyChange:!1,value:{obj:p}}),p.flipColl.length<=1&&this.setTextBoxHeight(),n%90==0&&n%180!=0?parseFloat(r.textArea.style.left)+parseFloat(r.textArea.style.width)>r.img.destTop+r.img.destHeight&&this.alignTextAreaIntoCanvas():parseFloat(r.textArea.style.left)+parseFloat(r.textArea.style.width)>r.img.destLeft+r.img.destWidth&&this.alignTextAreaIntoCanvas(),r.notify("selection",{prop:"clearUpperCanvas",onPropertyChange:!1})},i.prototype.setTextBoxWidth=function(t){var i=this.parent,o=this.getMaxText(!0);"block"===i.textArea.style.display?this.updateFontStyles(!0):this.updateFontStyles();var r=this.upperContext.measureText(o).width+parseFloat(i.textArea.style.fontSize)/2,n=t?this.upperContext.measureText(String.fromCharCode(t.which)).width:0,a=e.extend({},i.activeObj,{},!0),s="",l=this.getRotDegOfShape(a);if(s=a.shapeFlip!==i.transform.currFlipState?"":i.transform.currFlipState,t&&parseFloat(i.textArea.style.width)<r+n||e.isNullOrUndefined(t))if(0===l)"horizontal"===s.toLowerCase()?parseFloat(i.textArea.style.left)-i.img.destLeft-r-n>0&&(i.textArea.style.width=r+n+"px"):i.img.destWidth-(parseFloat(i.textArea.style.left)-i.img.destLeft)>r+n&&(i.textArea.style.width=r+n+"px");else if(90===l)"vertical"===s.toLowerCase()?parseFloat(i.textArea.style.top)-i.img.destTop-r-n>0&&(i.textArea.style.width=r+n+"px"):i.img.destHeight-(parseFloat(i.textArea.style.top)-i.img.destTop)>r+n&&(i.textArea.style.width=r+n+"px");else if(180===l){var p=parseFloat(i.textArea.style.left),h=i.img.destLeft;if("horizontal"===s.toLowerCase()){i.img.destWidth-(p-h)>r+n&&(i.textArea.style.width=r+n+"px")}else{p-h-r-n>0&&(i.textArea.style.width=r+n+"px")}}else if(270===l){var c=parseFloat(i.textArea.style.top),d=i.img.destTop;if("vertical"===s.toLowerCase()){i.img.destHeight-(c-d)>r+n&&(i.textArea.style.width=r+n+"px")}else{c-d-r-n>0&&(i.textArea.style.width=r+n+"px")}}},i.prototype.setTextBoxHeight=function(){var t,i=this.parent,o=e.extend({},i.activeObj,{},!0),r="",n=this.getRotDegOfShape(o);switch(r=o.textFlip===i.transform.currFlipState?"":""===o.textFlip?i.transform.currFlipState:o.textFlip,n){case 0:"vertical"===r.toLowerCase()?i.textArea.style.maxHeight=i.img.destHeight-(i.img.destHeight-parseFloat(i.textArea.style.top))+"px":(t=parseFloat(i.textArea.style.top)-i.img.destTop,i.textArea.style.maxHeight=i.img.destHeight-t+"px");break;case 90:"horizontal"===r.toLowerCase()?i.textArea.style.maxHeight=i.img.destWidth-(parseFloat(i.textArea.style.left)-i.img.destLeft)+"px":i.textArea.style.maxHeight=parseFloat(i.textArea.style.left)-i.img.destLeft+"px";break;case 180:"vertical"===r.toLowerCase()?(t=parseFloat(i.textArea.style.top)-i.img.destTop,i.textArea.style.maxHeight=i.img.destHeight-t+"px"):i.textArea.style.maxHeight=parseFloat(i.textArea.style.top)-i.img.destTop+"px";break;case 270:"horizontal"===r.toLowerCase()?i.textArea.style.maxHeight=parseFloat(i.textArea.style.left)-i.img.destLeft+"px":i.textArea.style.maxHeight=i.img.destWidth-(parseFloat(i.textArea.style.left)-i.img.destLeft)+"px"}},i.prototype.updatePathRatio=function(t){for(var e=this.parent,i=0,o=t.pointColl.length;i<o;i++){var r=t.pointColl[i];r.ratioX=(r.x-e.img.destLeft)/e.img.destWidth,r.ratioY=(r.y-e.img.destTop)/e.img.destHeight}},i.prototype.stopPathDrawing=function(t){var i=this.parent;if("path"===i.activeObj.shape){var o={shape:null};if(i.notify("selection",{prop:"getCurrentDrawingShape",value:{obj:o}}),"path"===o.shape){var r=e.extend({},this.parent.cropObj,{},!0),n={currObj:{}};this.parent.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:n}});var a=n.currObj;a.objColl=e.extend([],this.parent.objColl,[],!0),a.pointColl=e.extend([],this.parent.pointColl,[],!0),a.afterCropActions=e.extend([],this.parent.afterCropActions,[],!0);var s={selPointColl:null};this.parent.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:s}}),a.selPointColl=e.extend([],s.selPointColl,[],!0),i.notify("selection",{prop:"setCurrentDrawingShape",value:{value:""}}),i.currObjType.isDragging=!1,"touchstart"!==t.type&&i.activeObj.pointColl.pop(),this.updatePathRatio(i.activeObj),i.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"shapeTransform",previousObj:a,previousObjColl:a.objColl,previousPointColl:a.pointColl,previousSelPointColl:a.selPointColl,previousCropObj:r,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),i.notify("selection",{prop:"mouseUpEventHandler",value:{e:t}}),i.notify("draw",{prop:"setNewPath",value:{bool:!0}}),i.objColl[i.objColl.length-1]&&i.selectShape(i.objColl[i.objColl.length-1].currIndex),e.isBlazor()?i.updateToolbar(i.element,"quickAccessToolbar",i.activeObj.shape):i.notify("toolbar",{prop:"renderQAT",onPropertyChange:!1,value:{isPenEdit:null}})}}},i.prototype.findTextTarget=function(t){var i=this.parent;if("text"===i.activeObj.shape){var o,r;if("dblclick"===t.type?(o=t.clientX,r=t.clientY):"touchstart"===t.type&&(o=t.touches[0].clientX,r=t.touches[0].clientY,i.notify("selection",{prop:"setTouchEndPoint",onPropertyChange:!1,value:{x:t.touches[0].clientX,y:t.touches[0].clientY}})),i.notify("toolbar",{prop:"setPreventZoomBtn",onPropertyChange:!1,value:{isPrevent:!0}}),i.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"text",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}}),i.notify("toolbar",{prop:"setPreventZoomBtn",onPropertyChange:!1,value:{isPrevent:!1}}),i.notify("toolbar",{prop:"update-toolbar-items",onPropertyChange:!1}),e.isNullOrUndefined(o)||e.isNullOrUndefined(r))if("block"===i.textArea.style.display&&""!==this.selectedText()&&"mousedown"===t.type){l=i.textArea.value;i.textArea.value+="a",i.textArea.value=l}else"none"===i.textArea.style.display&&(i.textArea.style.display="block");else{var n=this.parent.lowerCanvas.getBoundingClientRect();o-=n.left,r-=n.top;var a="",s=this.getRotDegOfShape(i.activeObj);a=""===i.activeObj.textFlip?i.activeObj.textFlip===i.transform.currFlipState?"":i.transform.currFlipState:i.activeObj.textFlip===i.transform.currFlipState?"":""===i.transform.currFlipState?i.activeObj.textFlip:i.transform.currFlipState;var l=void 0;if("none"===i.textArea.style.display){l=e.extend({},i.activeObj,{},!0);for(var p=0;p<i.objColl.length;p++)JSON.stringify(i.activeObj)===JSON.stringify(i.objColl[p])&&i.objColl.splice(p,1);this.refreshActiveObj(),this.upperContext.clearRect(0,0,this.parent.upperCanvas.width,this.parent.upperCanvas.height),this.lowerContext.clearRect(0,0,this.parent.upperCanvas.width,this.parent.upperCanvas.height),i.notify("draw",{prop:"redrawImgWithObj",onPropertyChange:!1}),(!e.isNullOrUndefined(i.currSelectionPoint)&&"crop-circle"===i.currSelectionPoint.shape||i.isCircleCrop)&&i.notify("crop",{prop:"cropCircle",onPropertyChange:!1,value:{context:this.lowerContext,isSave:null,isFlip:null}}),i.activeObj=l,this.updateFontStyles();var h=e.extend({},i.activeObj,{},!0);if(o>=h.activePoint.startX-2*h.topLeftCircle.radius&&o<=h.activePoint.endX+2*h.topLeftCircle.radius&&r>=h.activePoint.startY-2*h.topLeftCircle.radius&&r<=h.activePoint.endY+2*h.topLeftCircle.radius){if(this.upperContext.clearRect(0,0,this.parent.upperCanvas.width,this.parent.upperCanvas.height),4===h.flipObjColl.length&&(h.flipObjColl=[],a=""),""===a&&h.flipObjColl.length>1&&(a=h.flipObjColl[h.flipObjColl.length-1]),h.flipObjColl.length<=1){o=(c=this.setTextBoxPos(h,s,a,o,r)).x,r=c.y}else{var c;o=(c=this.setTextBoxPoints(h,s,a,o,r)).x,r=c.y}0!==i.activeObj.rotatedAngle&&(o=i.activeObj.horTopLinePointColl[0].x,r=i.activeObj.horTopLinePointColl[0].y),this.renderTextArea(o,r,h)}else this.applyActObj()}}}else this.stopPathDrawing(t)},i.prototype.setTextBoxPos=function(t,e,i,o,r){var n={x:o,y:r};switch(e){case 0:"horizontal"===i.toLowerCase()?(n.x=t.activePoint.endX,n.y=t.activePoint.startY):"vertical"===i.toLowerCase()?(n.x=t.activePoint.startX,n.y=t.activePoint.endY):(n.x=t.activePoint.startX,n.y=t.activePoint.startY);break;case 90:"horizontal"===i.toLowerCase()?(n.x=t.activePoint.startX,n.y=t.activePoint.startY):"vertical"===i.toLowerCase()?(n.x=t.activePoint.endX,n.y=t.activePoint.endY):(n.x=t.activePoint.endX,n.y=t.activePoint.startY);break;case 180:"horizontal"===i.toLowerCase()?(n.x=t.activePoint.startX,n.y=t.activePoint.endY):"vertical"===i.toLowerCase()?(n.x=t.activePoint.endX,n.y=t.activePoint.startY):(n.x=t.activePoint.endX,n.y=t.activePoint.endY);break;case 270:"horizontal"===i.toLowerCase()?(n.x=t.activePoint.endX,n.y=t.activePoint.endY):"vertical"===i.toLowerCase()?(n.x=t.activePoint.startX,n.y=t.activePoint.startY):(n.x=t.activePoint.startX,n.y=t.activePoint.endY)}return n},i.prototype.setTextBoxPoints=function(t,e,i,o,r){var n={x:o,y:r};switch(e){case 0:t.flipObjColl[0]&&"horizontal"===t.flipObjColl[0].toLowerCase()?"horizontal"===i.toLowerCase()?(n.x=t.activePoint.startX,n.y=t.activePoint.startY):"vertical"===i.toLowerCase()&&(n.x=t.activePoint.endX,n.y=t.activePoint.endY):"horizontal"===i.toLowerCase()?(n.x=t.activePoint.endX,n.y=t.activePoint.endY):"vertical"===i.toLowerCase()&&(n.x=t.activePoint.endX,n.y=t.activePoint.startY);break;case 90:t.flipObjColl[0]&&"horizontal"===t.flipObjColl[0].toLowerCase()?"horizontal"===i.toLowerCase()?(n.x=t.activePoint.endX,n.y=t.activePoint.endY):"vertical"===i.toLowerCase()&&(n.x=t.activePoint.startX,n.y=t.activePoint.endY):"horizontal"===i.toLowerCase()?(n.x=t.activePoint.startX,n.y=t.activePoint.endY):"vertical"===i.toLowerCase()&&(n.x=t.activePoint.startX,n.y=t.activePoint.startY);break;case 180:t.flipObjColl[0]&&"horizontal"===t.flipObjColl[0].toLowerCase()?"horizontal"===i.toLowerCase()?(n.x=t.activePoint.startX,n.y=t.activePoint.startY):"vertical"===i.toLowerCase()&&(n.x=t.activePoint.startX,n.y=t.activePoint.startY):"horizontal"===i.toLowerCase()?(n.x=t.activePoint.startX,n.y=t.activePoint.startY):"vertical"===i.toLowerCase()&&(n.x=t.activePoint.startX,n.y=t.activePoint.endY);break;case 270:t.flipObjColl[0]&&"horizontal"===t.flipObjColl[0].toLowerCase()?"horizontal"===i.toLowerCase()?(n.x=t.activePoint.startX,n.y=t.activePoint.startY):"vertical"===i.toLowerCase()&&(n.x=t.activePoint.endX,n.y=t.activePoint.startY):"horizontal"===i.toLowerCase()?(n.x=t.activePoint.endX,n.y=t.activePoint.startY):"vertical"===i.toLowerCase()&&(n.x=t.activePoint.endX,n.y=t.activePoint.endY)}return n},i.prototype.selectedText=function(){var t=this.parent.textArea.selectionStart,e=this.parent.textArea.selectionEnd;return this.parent.textArea.value.substring(t,e)},i.prototype.panObjColl=function(t,e,i){for(var o=this.parent,r=0,n=o.objColl.length;r<n;r++){var a=o.objColl[r];if(""===i||"vertical"===i){if(a.activePoint.startX+=t,a.activePoint.endX+=t,a.rotationCirclePointColl&&(a.rotationCirclePointColl.x+=t),"path"===a.shape)for(var s=0,l=a.pointColl.length;s<l;s++)a.pointColl[s].x+=t}else if(a.activePoint.startX-=t,a.activePoint.endX-=t,a.rotationCirclePointColl&&(a.rotationCirclePointColl.x-=t),"path"===a.shape){s=0;for(var p=a.pointColl.length;s<p;s++)a.pointColl[s].x-=t}if(""===i||"horizontal"===i){if(a.activePoint.startY+=e,a.activePoint.endY+=e,a.rotationCirclePointColl&&(a.rotationCirclePointColl.y+=e),"path"===a.shape)for(s=0;s<a.pointColl.length;s++)a.pointColl[s].y+=e}else if(a.activePoint.startY-=e,a.activePoint.endY-=e,a.rotationCirclePointColl&&(a.rotationCirclePointColl.y-=e),"path"===a.shape)for(s=0;s<a.pointColl.length;s++)a.pointColl[s].y-=e;if(a=this.updateWidthHeight(a),o.notify("draw",{prop:"updateActiveObject",onPropertyChange:!1,value:{actPoint:a.activePoint,obj:a}}),"line"===a.shape||"arrow"===a.shape){a.pointColl=this.getLinePoints(a.activePoint.startX,a.activePoint.startY,a.activePoint.endX,a.activePoint.endY);for(var h=0,c=a.pointColl.length;h<c;h++)a.pointColl[h].ratioX=(a.pointColl[h].x-o.img.destLeft)/o.img.destWidth,a.pointColl[h].ratioY=(a.pointColl[h].y-o.img.destTop)/o.img.destHeight}var d=this.lowerContext.filter;this.lowerContext.filter="none",this.apply(a.shape,a),this.lowerContext.filter=d,this.refreshActiveObj()}},i.prototype.updateFontStyles=function(t){var e=this.parent;this.upperContext.strokeStyle=e.activeObj.strokeSettings.strokeColor,this.upperContext.fillStyle=e.activeObj.strokeSettings.strokeColor;var i="";e.activeObj.textSettings.bold&&(i="bold "),e.activeObj.textSettings.italic&&(i="italic "),e.activeObj.textSettings.bold&&e.activeObj.textSettings.italic&&(i="italic bold ");var o=t?parseFloat(e.textArea.style.fontSize):e.activeObj.textSettings.fontSize,r="block"===e.textArea.style.display?e.textArea.style.fontFamily:e.activeObj.textSettings.fontFamily;this.upperContext.font=i+o+"px "+r},i.prototype.applyFontStyle=function(t){var i=this.parent;this.pushActItemIntoObj();var o=e.extend([],i.objColl,[],!0);switch(i.objColl.pop(),"none"===i.textArea.style.display?this.updateFontRatio(i.activeObj):this.updateFontRatio(i.activeObj,!0),t){case"default":this.updateFontStyle(t,o,"normal","normal");break;case"bold":this.updateFontStyle(t,o,"bold","normal");break;case"italic":this.updateFontStyle(t,o,"normal","italic");break;case"bolditalic":this.updateFontStyle(t,o,"bold","italic")}},i.prototype.updateFontStyle=function(t,e,i,o){var r=this.parent;if("block"===r.textArea.style.display){var n=this.getTextAreaWidth(t);r.textArea.style.width=n+"px",r.textArea.style.fontWeight=i,r.textArea.style.fontStyle=o,this.updateObjColl(t,e)}else this.textSettings.bold=r.activeObj.textSettings.bold="normal"!==i,this.textSettings.italic=r.activeObj.textSettings.italic="normal"!==o,this.redrawText(),r.notify("undo-redo",{prop:"updateUrObj",onPropertyChange:!1,value:{objColl:e}})},i.prototype.updateArrowRatio=function(t){var e={arrowDimension:null};this.parent.notify("draw",{prop:"getArrowDimension",onPropertyChange:!1,value:{obj:e}});var i,o=this.getRotDegOfShape(t);i=0===o||180===o||-180===o?Math.abs(t.activePoint.width):Math.abs(t.activePoint.height);for(var r,n=0,a=["bar","arrow","arrowSolid","circle","square"];n<a.length;n++){r=a[n];var s=i/e.arrowDimension[r].width,l=i/e.arrowDimension[r].height;e.arrowDimension[r].ratioX=s,e.arrowDimension[r].ratioY=l}},i.prototype.updateArrowSize=function(t){var e={arrowDimension:null};this.parent.notify("draw",{prop:"getArrowDimension",onPropertyChange:!1,value:{obj:e}});var i,o=this.getRotDegOfShape(t);i=0===o||180===o||-180===o?Math.abs(t.activePoint.width):Math.abs(t.activePoint.height);for(var r,n=0,a=["bar","arrow","arrowSolid","circle","square"];n<a.length;n++){r=a[n];var s=e.arrowDimension[r].ratioX,l=e.arrowDimension[r].ratioY;e.arrowDimension[r].width=i/s,e.arrowDimension[r].height=i/l}},i.prototype.updateFontRatio=function(t,i){var o=this.parent,r=this.getMaxText(i),n=this.upperContext.measureText(r).width+.5*o.activeObj.textSettings.fontSize,a=o.activeObj.textSettings.fontSize+.25*o.activeObj.textSettings.fontSize,s=this.getRotDegOfShape(t);e.isNullOrUndefined(i)?0===s||180===Math.abs(s)?t.textSettings.fontRatio=n/t.textSettings.fontSize:t.textSettings.fontRatio=a/t.textSettings.fontSize:i&&(t.textSettings.fontRatio=n/parseFloat(o.textArea.style.fontSize))},i.prototype.updateFontSize=function(t){var e=this.getRotDegOfShape(t);0===e||180===Math.abs(e)?t.textSettings.fontSize=t.activePoint.width/t.textSettings.fontRatio:t.textSettings.fontSize=t.activePoint.height/t.textSettings.fontRatio},i.prototype.updateObjColl=function(t,i){var o=this.parent,r=e.extend({},o.cropObj,{},!0),n={currObj:{}};o.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:n}});var a=n.currObj;a.objColl=i,a.pointColl=e.extend([],o.pointColl,[],!0),a.afterCropActions=e.extend([],o.afterCropActions,[],!0);var s={selPointColl:null};o.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:s}}),a.selPointColl=e.extend([],s.selPointColl,[],!0);var l=o.activeObj.textSettings.bold,p=o.activeObj.textSettings.italic;switch(t){case"default":o.activeObj.textSettings.bold=!1,o.activeObj.textSettings.italic=!1;break;case"bold":o.activeObj.textSettings.bold=!0,o.activeObj.textSettings.italic=!1;break;case"italic":o.activeObj.textSettings.bold=!1,o.activeObj.textSettings.italic=!0;break;case"bolditalic":o.activeObj.textSettings.bold=!0,o.activeObj.textSettings.italic=!0}o.objColl.push(o.activeObj),o.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"textAreaCustomization",previousObj:a,previousObjColl:a.objColl,previousPointColl:a.pointColl,previousSelPointColl:a.selPointColl,previousCropObj:r,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),o.objColl.pop(),o.activeObj.textSettings.bold=l,o.activeObj.textSettings.italic=p},i.prototype.pushActItemIntoObj=function(){if("none"===this.parent.textArea.style.display)this.parent.objColl.push(this.parent.activeObj);else{var t=e.extend({},this.parent.activeObj,{},!0);this.parent.notify("selection",{prop:"setTextBoxStylesToActObj",onPropertyChange:!1}),this.parent.objColl.push(this.parent.activeObj),this.parent.activeObj=t}},i.prototype.clearActObj=function(){"none"===this.parent.textArea.style.display&&(this.refreshActiveObj(),this.applyActObj(),this.refreshActiveObj(),this.parent.currObjType.isCustomCrop=!1)},i.prototype.refreshActiveObj=function(){this.parent.activeObj={},this.parent.activeObj.activePoint={startX:0,startY:0,endX:0,endY:0,width:0,height:0},this.parent.activeObj.triangle=[],this.parent.activeObj.triangleRatio=[],this.parent.activeObj.flipObjColl=[],this.parent.activeObj.strokeSettings=this.strokeSettings,this.parent.activeObj.textSettings=this.textSettings,this.parent.activeObj.rotatedAngle=0},i.prototype.applyActObj=function(t){var i=!1;if(void 0!==this.parent.activeObj.shape&&"text"===this.parent.activeObj.shape&&""===this.parent.activeObj.keyHistory)this.refreshActiveObj(),this.upperContext.clearRect(0,0,this.parent.upperCanvas.width,this.parent.upperCanvas.height);else{var o=void 0,r=!1;if(void 0!==this.parent.activeObj.shape&&(o=this.parent.activeObj.shape.split("-")),void 0===o&&this.parent.currObjType.isCustomCrop?r=!0:void 0!==o&&"crop"===o[0]&&(r=!0),this.parent.activeObj.shape&&!r&&"shape"!==this.parent.activeObj.shape){for(var n=0;n<this.parent.objColl.length;n++)if(JSON.stringify(this.parent.activeObj)===JSON.stringify(this.parent.objColl[n])){i=!0;break}if(!i){e.isNullOrUndefined(this.parent.activeObj.currIndex)&&(this.parent.activeObj.currIndex="shape_"+(this.parent.objColl.length+1)),this.updImgRatioForActObj();var a=this.parent.activeObj.currIndex.split("_"),s=this.parent.objColl.splice(0,parseInt(a[1],10)-1);s.push(e.extend({},this.parent.activeObj,{},!0));for(n=0;n<this.parent.objColl.length;n++)s.push(this.parent.objColl[n]);this.parent.objColl=s,s=[],this.refreshActiveObj(),this.lowerContext.clearRect(0,0,this.parent.lowerCanvas.width,this.parent.lowerCanvas.height),this.parent.notify("draw",{prop:"redrawImgWithObj",onPropertyChange:!1}),this.parent.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.lowerContext}}),this.parent.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.upperContext}}),this.parent.currObjType.shape="",this.refreshActiveObj(),this.parent.isCircleCrop&&this.parent.notify("crop",{prop:"cropCircle",onPropertyChange:!1,value:{context:this.lowerContext,isSave:null,isFlip:null}}),e.isBlazor()?this.parent.updateToolbar(this.parent.element,"destroyQuickAccessToolbar"):this.parent.notify("toolbar",{prop:"destroy-qa-toolbar",onPropertyChange:!1}),e.isNullOrUndefined(t)&&(this.parent.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"ok"}}),this.parent.notify("draw",{prop:"setPrevActObj",onPropertyChange:!1,value:{prevActObj:null}}))}}}},i.prototype.alignTextAreaIntoCanvas=function(){var t=this.parent,e=t.textArea.value;t.textArea.value="";for(var i=0,o=e.length;i<o;i++)t.textArea.value+=e[i],t.textArea.style.height="auto",t.textArea.style.height=t.textArea.scrollHeight+"px",this.setTextBoxWidth()},i.prototype.transformTextArea=function(){var t=this.parent;if("text"===t.activeObj.shape){t.textArea.style.transformOrigin="0 0";var e=t.activeObj.rotatedAngle*(180/Math.PI),i="",o=this.getRotDegOfShape(t.activeObj);if(t.activeObj.flipObjColl.length>0)for(var r=0;r<t.activeObj.flipObjColl.length;r++)i+=0!==o&&o%90==0&&180!==o?"horizontal"===t.activeObj.flipObjColl[r].toLowerCase()?"scale(1, -1)":"scale(-1, 1)":"horizontal"===t.activeObj.flipObjColl[r].toLowerCase()?"scale(-1, 1)":"scale(1, -1)",o+=e,"horizontal"===t.activeObj.flipObjColl[r].toLowerCase()?t.textArea.style.transform="rotate("+o+"deg)"+i:"vertical"===t.activeObj.flipObjColl[r].toLowerCase()&&(t.textArea.style.transform="rotate("+o+"deg)"+i);else o+=e,t.textArea.style.transform="rotate("+o+"deg)"}},i.prototype.getTextAreaWidth=function(t){var e=this.parent,i=e.activeObj.textSettings.bold,o=e.activeObj.textSettings.italic;switch(t){case"default":e.activeObj.textSettings.bold=!1,e.activeObj.textSettings.italic=!1;break;case"bold":e.activeObj.textSettings.bold=!0,e.activeObj.textSettings.italic=!1;break;case"italic":e.activeObj.textSettings.bold=!1,e.activeObj.textSettings.italic=!0;break;case"bolditalic":e.activeObj.textSettings.bold=!0,e.activeObj.textSettings.italic=!0}this.updateFontStyles();var r;return r="none"===e.textArea.style.display?this.upperContext.measureText(e.activeObj.keyHistory).width+.5*e.activeObj.textSettings.fontSize:this.upperContext.measureText(e.textArea.value).width+.5*e.activeObj.textSettings.fontSize,e.activeObj.textSettings.bold=i,e.activeObj.textSettings.italic=o,r},i.prototype.getObjDetails=function(t){var e=this.parent,i={};switch(i.id=t.currIndex,i.type=e.toPascalCase(t.shape),i.startX=t.activePoint.startX,i.startY=t.activePoint.startY,t.shape){case"rectangle":i.width=t.activePoint.width,i.height=t.activePoint.height,i.strokeColor=t.strokeSettings.strokeColor,i.fillColor=t.strokeSettings.fillColor,i.strokeWidth=t.strokeSettings.strokeWidth;break;case"ellipse":i.radius=t.activePoint.width/2,i.strokeColor=t.strokeSettings.strokeColor,i.fillColor=t.strokeSettings.fillColor,i.strokeWidth=t.strokeSettings.strokeWidth;break;case"line":case"arrow":i.length=t.activePoint.width,i.strokeColor=t.strokeSettings.strokeColor,i.strokeWidth=t.strokeSettings.strokeWidth;break;case"text":i.text=t.keyHistory,i.fontSize=t.textSettings.fontSize,i.color=t.strokeSettings.strokeColor,i.fontStyle=[],t.textSettings.bold&&i.fontStyle.push("bold"),t.textSettings.italic&&i.fontStyle.push("italic")}return i},i.prototype.getFreehandDrawDetails=function(i){var o=this.parent,r={};return r.id=o.pointColl[i].id,r.type=t.ShapeType.FreehandDraw,r.points=e.extend([],o.pointColl[i].points),r.strokeColor=o.pointColl[i].strokeColor,r.strokeWidth=o.pointColl[i].strokeWidth,r},i.prototype.getShapeSetting=function(t,i){var o,r=this.parent;if(!r.disabled&&r.isImageLoaded)if(this.applyActObj(),"shape"===t.split("_")[0]){for(var n,a=0,s=r.objColl.length;a<s;a++)if(r.objColl[a].currIndex===t){n=e.extend({},r.objColl[a],{},!0);break}o=this.getObjDetails(n)}else"pen"===t.split("_")[0]&&(o=this.getFreehandDrawDetails(parseInt(t.split("_")[1],10)-1));i.shapeDetails=o},i.prototype.getShapeSettings=function(t){var e=this.parent,i=[];if(!e.disabled&&e.isImageLoaded){this.applyActObj();for(var o=0,r=e.objColl.length;o<r;o++){var n=this.getObjDetails(e.objColl[o]);i.push(n)}for(o=0;o<e.freehandCounter;o++){n=this.getFreehandDrawDetails(o);i.push(n)}}t.shapeDetailsColl=i},i.prototype.isPointsInRange=function(t,i,o){var r=!1;!e.isNullOrUndefined(t)&&!e.isNullOrUndefined(i)&&t>=0&&i>=0&&t<=this.parent.lowerCanvas.width&&i<=this.parent.lowerCanvas.width&&(r=!0),o.inRange=r},i.prototype.alignRotateFlipColl=function(t,e,i){return t=this.popForDefaultTransformedState(t),t=this.popForDefaultFlipState(t),0===(t=this.popForDefaultRotateState(t)).length&&e&&(this.parent.transform.degree=0,this.parent.transform.currFlipState=""),i.collection=t,t},i.prototype.popForDefaultTransformedState=function(t){for(var e=0,i=0,o=0,r=0,n=0;n<t.length;n++)90===t[n]||"rotateRight"===t[n]?(i=0,o=0,r=0,4===++e&&(t.pop(),t.pop(),t.pop(),t.pop())):-90===t[n]||"rotateLeft"===t[n]?(e=0,o=0,r=0,4===++i&&(t.pop(),t.pop(),t.pop(),t.pop())):"horizontal"===t[n]||"Horizontal"===t[n]||"horizontalflip"===t[n]?(i=0,e=0,r=0,2===++o&&(t.pop(),t.pop())):"vertical"!==t[n]&&"Vertical"!==t[n]&&"verticalflip"!==t[n]||(o=0,i=0,e=0,2===++r&&(t.pop(),t.pop()));return t},i.prototype.popForDefaultFlipState=function(t){for(var i=0;i<t.length;i++)e.isNullOrUndefined(t[i+3])||("horizontal"!==t[i]&&"Horizontal"!==t[i]&&"horizontalFlip"!==t[i]||"vertical"!==t[i+1]&&"Vertical"!==t[i+1]&&"verticalFlip"!==t[i]||"horizontal"!==t[i+2]&&"Horizontal"!==t[i+2]&&"horizontalFlip"!==t[i]||"vertical"!==t[i+3]&&"Vertical"!==t[i+3]&&"verticalFlip"!==t[i]?"vertical"!==t[i]&&"Vertical"!==t[i]&&"verticalFlip"!==t[i]||"horizontal"!==t[i+1]&&"Horizontal"!==t[i+1]&&"horizontalFlip"!==t[i+1]||"vertical"!==t[i+2]&&"Vertical"!==t[i+2]&&"verticalFlip"!==t[i]||"horizontal"!==t[i+3]&&"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},i.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},i.prototype.selectShape=function(t,i){var o=this.parent,r=!1;if(!o.disabled&&o.isImageLoaded)if(this.applyActObj(),"shape"===t.split("_")[0]){for(var n,a=0,s=o.objColl.length;a<s;a++)if(o.objColl[a].currIndex===t){n=e.extend({},o.objColl[a],{},!0);break}if(e.isNullOrUndefined(n))r=!1;else{r=!0,o.activeObj=n;var l={canvasFilter:null};o.notify("toolbar",{prop:"getCanvasFilter",onPropertyChange:!1,value:{obj:l}}),this.lowerContext.filter=l.canvasFilter,o.notify("selection",{prop:"redrawShape",onPropertyChange:!1,value:{obj:o.activeObj}}),e.isBlazor()?"path"===o.activeObj.shape?o.updateToolbar(this.parent.element,"path","pathQuickAccessToolbar"):o.updateToolbar(o.element,"quickAccessToolbar",o.activeObj.shape):("text"===o.activeObj.shape?o.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"text",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}}):"pen"===o.activeObj.shape?o.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"pen",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}}):o.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"shapes",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}}),o.notify("toolbar",{prop:"update-toolbar-items",onPropertyChange:!1}))}}else if("pen"===t.split("_")[0]){l={bool:!1};o.notify("selection",{prop:"getFreehandDrawEditing",onPropertyChange:!1,value:{obj:l}}),l.bool&&o.okBtn();var p={isIndex:!1};o.notify("freehand-draw",{prop:"isFHDIdx",value:{index:parseInt(t.split("_")[1],10)-1,obj:p}}),p.isIndex?(r=!0,o.notify("freehand-draw",{prop:"selectFhd",value:{id:t}}),e.isBlazor()||o.notify("toolbar",{prop:"update-toolbar-items",onPropertyChange:!1})):r=!1}i.isSelected=r},i.prototype.deleteShape=function(t){var e=this.parent;if(!e.disabled&&e.isImageLoaded){if(this.applyActObj(),"shape"===t.split("_")[0]){for(var i=0,o=e.objColl.length;i<o;i++)if(e.objColl[i].currIndex===t){e.objColl.splice(i,1);break}}else"pen"===t.split("_")[0]&&e.notify("freehand-draw",{prop:"handle-freehand-draw",value:{id:t}});var r={canvasFilter:null};e.notify("toolbar",{prop:"getCanvasFilter",onPropertyChange:!1,value:{obj:r}}),this.lowerContext.filter=r.canvasFilter,this.lowerContext.clearRect(0,0,e.lowerCanvas.width,e.lowerCanvas.height),e.notify("draw",{prop:"redrawImgWithObj",onPropertyChange:!1}),e.notify("toolbar",{prop:"refresh-main-toolbar",onPropertyChange:!1})}},i.prototype.getMaxText=function(t,i,o){e.isNullOrUndefined(i)&&(i=t?this.parent.textArea.value:this.parent.activeObj.keyHistory);for(var r,n=i.split("\n"),a=n[0].length,s=n[0],l=1;l<n.length;l++)(r=n[l].length)>a&&(s=n[l],a=r);return o&&(o.maxText=s),s},i.prototype.getLinePoints=function(t,i,o,r){var n,a,s=[];if(t===o){i<r?(n=[t,i],a=[o,r]):(a=[t,i],n=[o,r]);for(var l=this.getSlope(n,a,!0),p=this.getIntercept(n,l),h=n[1];h<=a[1];h++){var c=l*h+p;s.push({x:c,y:h})}}else{t<o?(n=[t,i],a=[o,r]):(a=[t,i],n=[o,r]);for(l=this.getSlope(n,a,!1),p=this.getIntercept(n,l),c=n[0];c<=a[0];c++){h=l*c+p;s.push({x:c,y:h})}}if(Math.floor(t)===Math.floor(o)||s.length<10&&(r-i>10||i-r>10)){s=[];for(var d=Math.min(i,r),v=0;v<Math.abs(Math.floor(r)-Math.floor(i));v++)s.push({x:t,y:d+v});if(s.length>1){var u=void 0;u=e.isNullOrUndefined(s[s.length-2])?{x:0,y:0}:s[s.length-2];var g=s[s.length-1].x-u.x,b=s[s.length-1].y-u.y;s.push({x:s[s.length-1].x+g/2,y:s[s.length-1].y+b/2})}}else if(Math.floor(i)===Math.floor(r)||s.length<10&&(o-t>10||t-o>10)){s=[];for(var C=Math.min(t,o),f=0;f<Math.abs(Math.floor(o)-Math.floor(t));f++)s.push({x:C+f,y:i});if(s.length>1){u=void 0;u=e.isNullOrUndefined(s[s.length-2])?{x:0,y:0}:s[s.length-2];g=s[s.length-1].x-u.x,b=s[s.length-1].y-u.y;s.push({x:s[s.length-1].x+g/2,y:s[s.length-1].y+b/2})}}return s},i.prototype.getSlope=function(t,e,i){var o;if(i){if(t[1]===e[1])return null;o=(e[0]-t[0])/(e[1]-t[1])}else{if(t[0]===e[0])return null;o=(e[1]-t[1])/(e[0]-t[0])}return o},i.prototype.getIntercept=function(t,e){return null===e?t[0]:t[1]-e*t[0]},i.prototype.setPointCollForShapeRotation=function(t){var e=t.activePoint.startX+t.activePoint.width/2,i=t.activePoint.startY+t.activePoint.height/2,o={x:Math.cos(t.rotatedAngle)*(t.activePoint.startX-e)-Math.sin(t.rotatedAngle)*(t.activePoint.startY-i)+e,y:Math.sin(t.rotatedAngle)*(t.activePoint.startX-e)+Math.cos(t.rotatedAngle)*(t.activePoint.startY-i)+i},r={x:Math.cos(t.rotatedAngle)*(t.activePoint.endX-e)-Math.sin(t.rotatedAngle)*(t.activePoint.startY-i)+e,y:Math.sin(t.rotatedAngle)*(t.activePoint.endX-e)+Math.cos(t.rotatedAngle)*(t.activePoint.startY-i)+i},n={x:Math.cos(t.rotatedAngle)*(t.activePoint.startX-e)-Math.sin(t.rotatedAngle)*(t.activePoint.endY-i)+e,y:Math.sin(t.rotatedAngle)*(t.activePoint.startX-e)+Math.cos(t.rotatedAngle)*(t.activePoint.endY-i)+i},a={x:Math.cos(t.rotatedAngle)*(t.activePoint.endX-e)-Math.sin(t.rotatedAngle)*(t.activePoint.endY-i)+e,y:Math.sin(t.rotatedAngle)*(t.activePoint.endX-e)+Math.cos(t.rotatedAngle)*(t.activePoint.endY-i)+i};t.horTopLinePointColl=this.getLinePoints(o.x,o.y,r.x,r.y),t.horBottomLinePointColl=this.getLinePoints(n.x,n.y,a.x,a.y),t.verLeftLinePointColl=this.getLinePoints(o.x,o.y,n.x,n.y),t.verRightLinePointColl=this.getLinePoints(r.x,r.y,a.x,a.y),t.verLeftLinePointColl.reverse(),t.verRightLinePointColl.reverse();for(var s=0;s<t.horTopLinePointColl.length;s++)t.horTopLinePointColl[s].ratioX=(t.horTopLinePointColl[s].x-this.parent.img.destLeft)/this.parent.img.destWidth,t.horTopLinePointColl[s].ratioY=(t.horTopLinePointColl[s].y-this.parent.img.destTop)/this.parent.img.destHeight;for(s=0;s<t.horBottomLinePointColl.length;s++)t.horBottomLinePointColl[s].ratioX=(t.horBottomLinePointColl[s].x-this.parent.img.destLeft)/this.parent.img.destWidth,t.horBottomLinePointColl[s].ratioY=(t.horBottomLinePointColl[s].y-this.parent.img.destTop)/this.parent.img.destHeight;for(s=0;s<t.verLeftLinePointColl.length;s++)t.verLeftLinePointColl[s].ratioX=(t.verLeftLinePointColl[s].x-this.parent.img.destLeft)/this.parent.img.destWidth,t.verLeftLinePointColl[s].ratioY=(t.verLeftLinePointColl[s].y-this.parent.img.destTop)/this.parent.img.destHeight;for(s=0;s<t.verRightLinePointColl.length;s++)t.verRightLinePointColl[s].ratioX=(t.verRightLinePointColl[s].x-this.parent.img.destLeft)/this.parent.img.destWidth,t.verRightLinePointColl[s].ratioY=(t.verRightLinePointColl[s].y-this.parent.img.destTop)/this.parent.img.destHeight;if("move"!==this.parent.upperCanvas.style.cursor){var l={rotationCirclePoint:null};this.parent.notify("selection",{prop:"getTransRotationPoint",value:{obj:t,object:l}});var p=l.rotationCirclePoint;p&&(t.rotationCirclePointColl={x:Math.cos(t.rotatedAngle)*(p.x-e)-Math.sin(t.rotatedAngle)*(p.y-i)+e,y:Math.sin(t.rotatedAngle)*(p.x-e)+Math.cos(t.rotatedAngle)*(p.y-i)+i},t.rotationCirclePointColl.ratioX=(t.rotationCirclePointColl.x-this.parent.img.destLeft)/this.parent.img.destWidth,t.rotationCirclePointColl.ratioY=(t.rotationCirclePointColl.y-this.parent.img.destTop)/this.parent.img.destHeight)}},i}(),v=function(){function i(t){this.isReverseFlip=!1,this.disablePan=!1,this.isReverseRotate=!1,this.flipColl=[],this.prevZoomValue=1,this.cropDimension={width:0,height:0},this.isPreventSelect=!1,this.parent=t,this.addEventListener()}return i.prototype.destroy=function(){this.parent.isDestroyed||this.removeEventListener()},i.prototype.addEventListener=function(){this.parent.on("transform",this.transform,this),this.parent.on("destroyed",this.destroy,this)},i.prototype.removeEventListener=function(){this.parent.off("transform",this.transform),this.parent.off("destroyed",this.destroy)},i.prototype.transform=function(t){switch(this.initTransformPvtVar(),t.prop){case"rotateImage":this.rotateImage(t.value.degree);break;case"flipImage":this.flipImage(t.value.direction);break;case"setDestPointsForFlipState":this.setDestPointsForFlipState();break;case"zoomAction":this.zoomAction(t.value.zoomFactor,t.value.zoomPoint);break;case"disableZoomOutBtn":this.disableZoomOutBtn(t.value.isZoomOut);break;case"rotatedFlip":this.rotatedFlip();break;case"drawPannedImage":this.drawPannedImage(t.value.xDiff,t.value.yDiff);break;case"drawPannImage":this.drawPannImage(t.value.point);break;case"performTransformation":this.performTransformation(t.value.text);break;case"updateTransform":this.updateTransform(t.value.text);break;case"rotatePan":this.rotatePan(t.value.isCropSelection,t.value.isDefaultZoom);break;case"drawRotatedImage":this.drawRotatedImage(t.value.degree);break;case"limitPan":this.limitPan();break;case"updateFlipActiveObj":this.updateFlipActiveObj(t.value.panRegion);break;case"resetZoom":this.resetZoom();break;case"pan":this.pan(t.value.value);break;case"zoom":this.zoom(t.value.zoomFactor,t.value.zoomPoint);break;case"setCurrPanRegion":this.setCurrPanRegion(t.value.region,t.value.type,t.value.obj);break;case"rotate":this.rotate(t.value.degree,t.value.obj);break;case"flip":this.flip(t.value.direction);break;case"update":this.update();break;case"calcMaxDimension":this.calcMaxDimension(t.value.width,t.value.height,t.value.obj);break;case"updatePanPoints":this.updatePanPoints(t.value.panRegion,t.value.obj);break;case"getPanMove":t.value.obj.panMove=this.panMove;break;case"setPanMove":this.panMove=t.value.point;break;case"getTempPanMove":t.value.obj.tempPanMove=this.tempPanMove;break;case"setTempPanMove":this.tempPanMove=t.value.point;break;case"setReverseFlip":this.isReverseFlip=t.value.isReverseFlip;break;case"setDisablePan":this.disablePan=t.value.bool;break;case"setCurrDestinationPoint":this.currDestPoint=t.value.point,this.currDestPoint.startX-=this.parent.cropObj.totalPannedPoint.x,this.currDestPoint.startY-=this.parent.cropObj.totalPannedPoint.y;break;case"setReverseRotate":this.isReverseRotate=t.value.bool;break;case"getFlipColl":t.value.obj.flipColl=this.flipColl;break;case"setFlipColl":this.flipColl=t.value.flipColl;break;case"getPreviousZoomValue":t.value.obj.previousZoomValue=this.prevZoomValue;break;case"setPreviousZoomValue":this.prevZoomValue=t.value.previousZoomValue;break;case"getCropDimension":t.value.obj.cropDimension=this.cropDimension;break;case"setCropDimension":this.cropDimension.width=t.value.width,this.cropDimension.height=t.value.height;break;case"reset":this.reset()}},i.prototype.getModuleName=function(){return"transform"},i.prototype.initTransformPvtVar=function(){this.parent.lowerCanvas&&(this.lowerContext=this.parent.lowerCanvas.getContext("2d")),this.parent.upperCanvas&&(this.upperContext=this.parent.upperCanvas.getContext("2d"))},i.prototype.reset=function(){this.zoomBtnHold=null,this.tempPanMove=null,this.panMove=null,this.disablePan=!1,this.currDestPoint=null,this.isReverseRotate=!1,this.flipColl=[],this.transCurrObj=null,this.prevZoomValue=1,this.isPreventSelect=!1},i.prototype.rotateImage=function(t){var i=this,o=this.parent,r={cancel:!1,previousDegree:o.transform.degree,currentDegree:360===Math.abs(o.transform.degree+t)?0:o.transform.degree+t};this.isPreventSelect||!e.isBlazor()||e.isNullOrUndefined(o.events)||!0!==o.events.rotating.hasDelegate?(this.isPreventSelect||o.trigger("rotating",r),this.rotateEvent(r,t)):o.dotNetRef.invokeMethodAsync("RotateEventAsync","OnRotate",r).then(function(e){i.rotateEvent(e,t)})},i.prototype.rotateEvent=function(t,i){var o=this.parent;if(!t.cancel){var r=void 0;if(e.isNullOrUndefined(this.transCurrObj)){var n={currObj:{}};o.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:n}}),(r=n.currObj).objColl=e.extend([],o.objColl,null,!0),r.pointColl=e.extend({},o.pointColl,null,!0),r.afterCropActions=e.extend([],o.afterCropActions,[],!0);var a={selPointColl:null};o.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:a}}),r.selPointColl=e.extend([],a.selPointColl,[],!0)}o.afterCropActions.push(90===i?"rotateRight":"rotateLeft");var s=[],l=void 0;e.isNullOrUndefined(o.activeObj.activePoint)||e.isNullOrUndefined(o.activeObj.shape)||(void 0!==o.activeObj.shape&&(s=o.activeObj.shape.split("-")),(o.currObjType.isCustomCrop||"crop"===s[0])&&(l=o.currObjType.isCustomCrop?"custom":s[1],o.notify("shape",{prop:"updImgRatioForActObj",onPropertyChange:!1}),o.objColl.push(o.activeObj),o.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}))),o.notify("shape",{prop:"redrawActObj",onPropertyChange:!1,value:{x:null,y:null,isMouseDown:!0}}),this.upperContext.clearRect(0,0,o.upperCanvas.width,o.upperCanvas.height),this.drawRotatedImage(i),o.notify("draw",{prop:"setImageEdited",onPropertyChange:!1}),o.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.lowerContext}}),o.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.upperContext}}),o.isCircleCrop&&o.notify("crop",{prop:"cropCircle",onPropertyChange:!1,value:{context:this.lowerContext,isSave:null,isFlip:null}}),l&&(this.upperContext.clearRect(0,0,o.upperCanvas.width,o.upperCanvas.height),o.activeObj=e.extend({},o.objColl[o.objColl.length-1],{},!0),o.objColl.pop(),o.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate",obj:o.activeObj}})),o.isUndoRedo=!1;var p={collection:o.rotateFlipColl};o.notify("shape",{prop:"alignRotateFlipColl",onPropertyChange:!1,value:{collection:o.rotateFlipColl,isRotateFlipCollection:!0,obj:p}}),o.rotateFlipColl=p.collection,o.cropObj.activeObj.shape&&!this.isPreventSelect&&(this.isPreventSelect=!0,o.select("custom"),this.isPreventSelect=!1,o.setProperties({zoomSettings:{zoomFactor:1}},!0),this.prevZoomValue=o.zoomSettings.zoomFactor)}},i.prototype.drawRotatedImage=function(t){var i=this.parent;0===t?i.transform.degree=0:i.transform.degree+=t,360===Math.abs(i.transform.degree)&&(i.transform.degree=0),i.notify("draw",{prop:"setDestPoints",onPropertyChange:!1});var o=e.extend([],i.objColl,[],!0),r=e.extend({},i.activeObj,{},!0);if(i.objColl=[],i.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),this.isReverseRotate||i.notify("draw",{prop:"updateCurrTransState",onPropertyChange:!1,value:{type:"initial",isPreventDestination:null,isRotatePan:null}}),this.rotateDegree(t),this.isReverseRotate||(i.notify("draw",{prop:"updateCurrTransState",onPropertyChange:!1,value:{type:"reverse",isPreventDestination:null,isRotatePan:null}}),i.rotateFlipColl.push(t)),i.objColl=e.extend([],o,[],!0),i.activeObj=e.extend({},r,{},!0),i.isCircleCrop&&i.notify("crop",{prop:"cropCircle",onPropertyChange:!1,value:{context:this.lowerContext,isSave:null,isFlip:null}}),i.notify("shape",{prop:"redrawObj",onPropertyChange:!1,value:{degree:t}}),i.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),t>0)i.notify("freehand-draw",{prop:"rotateFhdColl",onPropertyChange:!1});else for(var n=0;n<3;n++)i.notify("freehand-draw",{prop:"rotateFhdColl",onPropertyChange:!1});i.notify("freehand-draw",{prop:"freehandRedraw",onPropertyChange:!1,value:{context:this.lowerContext,points:null}}),this.updateCurrSelectionPoint(t)},i.prototype.rotateDegree=function(t){var e=this.parent;this.lowerContext.save(),this.lowerContext.clearRect(0,0,e.lowerCanvas.width,e.lowerCanvas.height),this.lowerContext.translate(e.lowerCanvas.width/2,e.lowerCanvas.height/2),this.lowerContext.rotate(Math.PI/180*t),this.lowerContext.translate(-e.lowerCanvas.width/2,-e.lowerCanvas.height/2);var i=this.lowerContext.filter;this.parent.notify("filter",{prop:"updateBrightFilter",onPropertyChange:!1}),this.lowerContext.drawImage(this.parent.baseImg,this.parent.img.srcLeft,this.parent.img.srcTop,this.parent.img.srcWidth,this.parent.img.srcHeight,this.parent.img.destLeft,this.parent.img.destTop,this.parent.img.destWidth,this.parent.img.destHeight),this.lowerContext.filter=i,this.lowerContext.translate(e.lowerCanvas.width/2,e.lowerCanvas.height/2),this.lowerContext.rotate(Math.PI/180*-t),this.lowerContext.translate(-e.lowerCanvas.width/2,-e.lowerCanvas.height/2),this.lowerContext.restore()},i.prototype.updateCurrSelectionPoint=function(t){var i=this.parent;if(i.currSelectionPoint&&this.currDestPoint){var o=e.extend({},i.activeObj,{},!0),r=e.extend([],i.objColl,[],!0),n={startX:i.img.srcLeft,startY:i.img.srcTop,width:i.img.srcWidth,height:i.img.srcHeight},a={startX:i.img.destLeft,startY:i.img.destTop,width:i.img.destWidth,height:i.img.destHeight};i.objColl=[],i.objColl.push(e.extend({},i.currSelectionPoint,{},!0)),e.isNullOrUndefined(i.objColl[0].imageRatio)&&(i.activeObj=i.objColl[0],i.notify("shape",{prop:"updImgRatioForActObj",onPropertyChange:!1}),i.objColl[0]=i.activeObj),i.img.srcLeft=0,i.img.srcTop=0,i.img.srcWidth=i.baseImg.width,i.img.srcHeight=i.baseImg.height,i.img.destLeft=this.currDestPoint.startX,i.img.destTop=this.currDestPoint.startY,i.img.destWidth=this.currDestPoint.width,i.img.destHeight=this.currDestPoint.height,"number"==typeof t&&(i.notify("draw",{prop:"setDestPoints",onPropertyChange:!1}),i.notify("draw",{prop:"setClientTransDim",onPropertyChange:!1,value:{isPreventDimension:null}})),i.notify("shape",{prop:"redrawObj",onPropertyChange:!1,value:{degree:t}}),i.currSelectionPoint=e.extend({},i.objColl[0],{},!0),this.currDestPoint={startX:i.img.destLeft,startY:i.img.destTop,width:i.img.destWidth,height:i.img.destHeight},i.objColl=r,i.activeObj=o,i.img.srcLeft=n.startX,i.img.srcTop=n.startY,i.img.srcWidth=n.width,i.img.srcHeight=n.height,i.img.destLeft=a.startX,i.img.destTop=a.startY,i.img.destWidth=a.width,i.img.destHeight=a.height}},i.prototype.flipImage=function(t){var i=this,o=this.parent,r={direction:t,cancel:!1,previousDirection:o.toPascalCase(o.transform.currFlipState)};this.isPreventSelect||!e.isBlazor()||e.isNullOrUndefined(o.events)||!0!==o.events.flipping.hasDelegate?(this.isPreventSelect||o.trigger("flipping",r),this.flipEvent(r,t)):o.dotNetRef.invokeMethodAsync("FlipEventAsync","OnFlip",r).then(function(e){i.flipEvent(e,t)})},i.prototype.flipEvent=function(t,i){var o=this.parent;if(!t.cancel){var r;if(e.isNullOrUndefined(this.transCurrObj)){var n={currObj:{}};o.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:n}}),(r=n.currObj).objColl=e.extend([],o.objColl,null,!0),r.pointColl=e.extend({},o.pointColl,null,!0),r.afterCropActions=e.extend([],o.afterCropActions,[],!0);var a={selPointColl:null};o.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:a}}),r.selPointColl=e.extend([],a.selPointColl,[],!0)}o.afterCropActions.push("horizontal"===i.toLowerCase()?"horizontalflip":"verticalflip");var s,l=[];o.activeObj.activePoint&&(void 0!==o.activeObj.shape&&(l=o.activeObj.shape.split("-")),(o.currObjType.isCustomCrop||"crop"===l[0])&&(s=o.currObjType.isCustomCrop?"custom":l[1],o.notify("shape",{prop:"updImgRatioForActObj",onPropertyChange:!1}),o.objColl.push(o.activeObj),o.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}))),o.notify("shape",{prop:"redrawActObj",onPropertyChange:!1,value:{x:null,y:null,isMouseDown:!0}}),o.clearContext(this.lowerContext),o.clearContext(this.upperContext);var p=e.extend([],o.objColl,[],!0),h=e.extend({},o.activeObj,{},!0);o.objColl=[],o.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),this.isReverseFlip||o.notify("draw",{prop:"updateCurrTransState",onPropertyChange:!1,value:{type:"initial",isPreventDestination:null,isRotatePan:null}});var c=i.toLowerCase();this.updateFlipState(c),o.transform.currFlipState="horizontal"===c?"horizontal"===o.transform.currFlipState.toLowerCase()?"":"horizontal":"vertical"===o.transform.currFlipState.toLowerCase()?"":"vertical";var d={isSelected:null};o.notify("draw",{prop:"getRotatedFlipCropSelection",onPropertyChange:!1,value:{bool:d}}),d.isSelected&&(o.img.destLeft+=o.panPoint.totalPannedInternalPoint.x,o.img.destTop+=o.panPoint.totalPannedInternalPoint.y);var v=this.lowerContext.filter;if(o.notify("filter",{prop:"updateBrightFilter",onPropertyChange:!1}),this.lowerContext.drawImage(o.baseImg,o.img.srcLeft,o.img.srcTop,o.img.srcWidth,o.img.srcHeight,o.img.destLeft,o.img.destTop,o.img.destWidth,o.img.destHeight),this.lowerContext.filter=v,o.notify("draw",{prop:"setImageEdited",onPropertyChange:!1}),this.updateFlipState(i.toLowerCase()),this.isReverseFlip||(o.notify("draw",{prop:"updateCurrTransState",onPropertyChange:!1,value:{type:"reverse",isPreventDestination:null,isRotatePan:null}}),this.updateFlipColl(i.toLocaleLowerCase()),o.rotateFlipColl.push(i.toLowerCase())),1===o.rotateFlipColl.length){var u={panRegion:""};o.notify("crop",{prop:"getCurrFlipState",onPropertyChange:!1,value:{panObj:u}}),""===u.panRegion?o.notify("draw",{prop:"setClientTransDim",onPropertyChange:!1,value:{isPreventDimension:null}}):this.setDestPointsForFlipState()}o.isCircleCrop&&o.notify("crop",{prop:"cropCircle",onPropertyChange:!1,value:{context:this.lowerContext,isSave:null,isFlip:null}}),o.objColl=e.extend([],p,[],!0),o.activeObj=e.extend({},h,{},!0);for(var g=0,b=o.objColl.length;g<b;g++){var C=o.objColl[g].flipObjColl;0===C.length?C.push(i):C[C.length-1]===i?C.pop():C.push(i)}o.notify("shape",{prop:"redrawObj",onPropertyChange:!1,value:{degree:i.toLowerCase()}});var f=this.lowerContext.filter;this.lowerContext.filter="brightness(1) contrast(100%) hue-rotate(0deg) saturate(100%) opacity(1) blur(0px) sepia(0%) grayscale(0%) invert(0%)",o.notify("shape",{prop:"iterateObjColl",onPropertyChange:!1}),"horizontal"===i.toLowerCase()||"vertical"===i.toLowerCase()?(o.notify("freehand-draw",{prop:"flipFHDColl",onPropertyChange:!1,value:{value:i.toLowerCase()}}),o.notify("freehand-draw",{prop:"freehandRedraw",onPropertyChange:!1,value:{context:this.lowerContext,points:null}})):o.notify("freehand-draw",{prop:"freehandRedraw",onPropertyChange:!1,value:{context:this.lowerContext,points:null}}),this.lowerContext.filter=f,o.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),this.updateCurrSelectionPoint(i.toLowerCase()),o.isUndoRedo=!1,o.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.lowerContext}}),o.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.upperContext}}),o.isCircleCrop&&o.notify("crop",{prop:"cropCircle",onPropertyChange:!1,value:{context:this.lowerContext,isSave:null,isFlip:null}}),e.isNullOrUndefined(s)||(this.upperContext.clearRect(0,0,o.upperCanvas.width,o.upperCanvas.height),o.activeObj=e.extend({},o.objColl[o.objColl.length-1],{},!0),o.objColl.pop(),o.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate",obj:o.activeObj}}));var m={collection:o.rotateFlipColl};o.notify("shape",{prop:"alignRotateFlipColl",onPropertyChange:!1,value:{collection:o.rotateFlipColl,isRotateFlipCollection:!0,obj:m}}),o.rotateFlipColl=m.collection,o.cropObj.activeObj.shape&&!this.isPreventSelect&&(this.isPreventSelect=!0,o.select("custom"),this.isPreventSelect=!1,o.setProperties({zoomSettings:{zoomFactor:1}},!0),this.prevZoomValue=o.zoomSettings.zoomFactor)}},i.prototype.updateFlipState=function(t){var e=this.parent.transform.degree;"horizontal"===t?e%90==0&&e%180!=0?this.verticalFlip():this.horizontalFlip():"vertical"===t&&(e%90==0&&e%180!=0?this.horizontalFlip():this.verticalFlip())},i.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)},i.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)},i.prototype.updateFlipColl=function(t){if(!this.isPreventSelect&&(0===this.flipColl.length||this.flipColl[this.flipColl.length-1]!==t?this.flipColl.push(t):this.flipColl.pop(),this.flipColl.length>=4)){var e=this.flipColl.slice(-4);("horizontal"===e[0]&&"vertical"===e[1]&&"horizontal"===e[2]&&"vertical"===e[3]||"vertical"===e[0]&&"horizontal"===e[1]&&"vertical"===e[2]&&"horizontal"===e[3])&&this.flipColl.splice(-4)}},i.prototype.setDestPointsForFlipState=function(){var t=this.parent,e={panRegion:""};t.notify("crop",{prop:"getCurrFlipState",onPropertyChange:!1,value:{panObj:e}}),""!==e.panRegion&&("horizontal"===e.panRegion?t.img.destLeft=t.lowerCanvas.clientWidth-(t.img.destWidth+t.img.destLeft):"vertical"===e.panRegion?t.img.destTop=t.lowerCanvas.clientHeight-(t.img.destHeight+t.img.destTop):(t.img.destLeft=t.lowerCanvas.clientWidth-(t.img.destWidth+t.img.destLeft),t.img.destTop=t.lowerCanvas.clientHeight-(t.img.destHeight+t.img.destTop)))},i.prototype.zoomAction=function(t,i){var o=this,r=this.parent;if(!r.disabled&&r.isImageLoaded){if(r.zoomSettings.zoomFactor>=r.zoomSettings.maxZoomFactor&&t>0||r.zoomSettings.zoomFactor>r.zoomSettings.minZoomFactor&&t<0&&this.disableZoomOutBtn(!0)||r.zoomSettings.zoomFactor<=r.zoomSettings.minZoomFactor&&t<0)return void(e.isBlazor()||r.notify("toolbar",{prop:"zoom-up-handler",onPropertyChange:!1}));r.notify("draw",{prop:"setImageEdited",onPropertyChange:!1});var n=t;t=n>0?.1:-.1;for(var a=0;a<Math.abs(n/.1);a++)if(1===this.prevZoomValue)this.prevZoomValue+=t>0?10*t:10*t/10;else if(this.prevZoomValue>1)this.prevZoomValue+=10*t;else if(this.prevZoomValue<1){this.prevZoomValue+=10*t/10;var s=Math.pow(10,1);this.prevZoomValue=Math.round(this.prevZoomValue*s)/s}t=n,r.setProperties({zoomSettings:{zoomFactor:this.prevZoomValue}},!0);var l=void 0;this.tempActiveObj=null,this.isShape=!1,void 0!==r.activeObj.shape&&("shape"===r.activeObj.shape?r.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}):l=r.activeObj.shape.split("-")),void 0!==l&&"crop"===l[0]?(this.tempActiveObj=e.extend({},r.activeObj,{},!0),r.isCropTab=!0):e.isNullOrUndefined(r.activeObj.shape)||"crop"===l[0]||(this.isShape=!0);var p={zoomType:null};r.notify("selection",{prop:"getZoomType",onPropertyChange:!1,value:{obj:p}}),e.isNullOrUndefined(i)&&(i=r.isCropTab&&!e.isNullOrUndefined(this.tempActiveObj)?{x:r.activeObj.activePoint.startX+r.activeObj.activePoint.width/2,y:r.activeObj.activePoint.startY+r.activeObj.activePoint.height/2}:{x:r.lowerCanvas.clientWidth/2,y:r.lowerCanvas.clientHeight/2},"MouseWheel"!==p.zoomType&&"Pinch"!==p.zoomType||(i={x:r.zoomSettings.zoomPoint.x,y:r.zoomSettings.zoomPoint.y}));var h={zoomPoint:i,cancel:!1,previousZoomFactor:r.zoomSettings.zoomFactor-10*t,currentZoomFactor:r.zoomSettings.zoomFactor,zoomTrigger:p.zoomType};r.isCropToolbar||!e.isBlazor()||e.isNullOrUndefined(r.events)||!0!==r.events.zooming.hasDelegate?(r.isCropToolbar||r.trigger("zooming",h),this.zoomEvent(h,t)):r.dotNetRef.invokeMethodAsync("ZoomEventAsync","OnZoom",h).then(function(e){o.zoomEvent(e,t)})}},i.prototype.zoomEvent=function(t,i){var o=this.parent;if(!t.cancel){e.isBlazor()?o.element.querySelector(".e-contextual-toolbar-wrapper")&&!o.element.querySelector(".e-contextual-toolbar-wrapper").classList.contains("e-hidden")&&o.updateToolbar(o.element,"closeContextualToolbar"):o.notify("toolbar",{prop:"close-contextual-toolbar",onPropertyChange:!1}),o.notify("shape",{prop:"redrawActObj",onPropertyChange:!1,value:{x:null,y:null,isMouseDown:!0}}),o.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),this.upperContext.clearRect(0,0,o.lowerCanvas.width,o.lowerCanvas.height);var r={canvasFilter:this.parent.canvasFilter};this.lowerContext.filter=r.canvasFilter,o.upperCanvas.style.cursor=o.cursor="default";var n=e.extend([],o.objColl,[],!0);if(o.isCropTab||(0!==o.transform.degree?(o.notify("shape",{prop:"redrawActObj",onPropertyChange:!1,value:{x:null,y:null,isMouseDown:null}}),o.panPoint.currentPannedPoint={x:0,y:0},this.rotatePan(!0,!0)):""!==o.transform.currFlipState&&(o.panPoint.totalPannedPoint={x:0,y:0}),o.notify("freehand-draw",{prop:"updateFHDColl",onPropertyChange:!1})),0===o.transform.degree){this.drawZoomImgToCanvas(i,this.tempActiveObj);var a={panRegion:""};if(o.notify("crop",{prop:"getCurrFlipState",onPropertyChange:!1,value:{panObj:a}}),""!==a.panRegion){o.notify("crop",{prop:"setTempFlipPanPoint",onPropertyChange:!1,value:{point:o.panPoint.totalPannedPoint,isAdd:!0}}),n=e.extend([],o.objColl,[],!0),o.objColl=[];var s=o.img.destLeft,l=o.img.destTop;this.setDestPointsForFlipState(),this.rotatedFlip(),o.img.destLeft=s,o.img.destTop=l,o.objColl=n,o.notify("shape",{prop:"zoomObjColl",onPropertyChange:!1,value:{isPreventApply:null}}),o.notify("freehand-draw",{prop:"zoomFHDColl",onPropertyChange:!1,value:{isPreventApply:null}}),o.notify("freehand-draw",{prop:"updateFHDColl",onPropertyChange:!1})}o.zoomSettings.zoomFactor<=o.zoomSettings.minZoomFactor&&!o.isCropTab&&(o.panPoint.totalPannedPoint={x:0,y:0})}else{o.notify("freehand-draw",{prop:"updateFHDColl",onPropertyChange:!1}),o.panPoint.totalPannedClientPoint={x:0,y:0},o.panPoint.totalPannedInternalPoint={x:0,y:0},this.rotateZoom(i);var p={panRegion:""};if(o.notify("crop",{prop:"getCurrFlipState",onPropertyChange:!1,value:{panObj:p}}),""!==p.panRegion){var h=this.lowerContext.filter;this.lowerContext.filter="none",o.notify("shape",{prop:"zoomObjColl",onPropertyChange:!1,value:{isPreventApply:null}}),o.notify("freehand-draw",{prop:"zoomFHDColl",onPropertyChange:!1,value:{isPreventApply:null}}),this.lowerContext.filter=h}}var c=Math.pow(10,1);(o.zoomSettings.zoomFactor<=o.zoomSettings.minZoomFactor||Math.round(o.transform.zoomFactor*c)/c==2)&&(clearInterval(this.zoomBtnHold),this.zoomBtnHold=0);var d={panRegion:""};if(o.notify("crop",{prop:"getCurrFlipState",onPropertyChange:!1,value:{panObj:d}}),""===d.panRegion){h=this.lowerContext.filter;this.lowerContext.filter="none",o.notify("shape",{prop:"zoomObjColl",onPropertyChange:!1,value:{isPreventApply:null}}),o.notify("freehand-draw",{prop:"zoomFHDColl",onPropertyChange:!1,value:{isPreventApply:null}}),this.lowerContext.filter=h}(o.currSelectionPoint&&"crop-circle"===o.currSelectionPoint.shape||o.isCircleCrop)&&o.notify("crop",{prop:"cropCircle",onPropertyChange:!1,value:{context:this.lowerContext,isSave:null,isFlip:null}}),o.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.lowerContext}}),o.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),this.tempActiveObj&&(o.activeObj=e.extend({},this.tempActiveObj,{},!0),o.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate",obj:o.activeObj}}),o.zoomSettings.zoomFactor<=o.zoomSettings.minZoomFactor&&(o.currSelectionPoint=null)),o.isUndoRedo=!1;var v;e.isBlazor()?(v=o.element.querySelector("#zoomout"))&&o.zoomSettings.zoomFactor<=o.zoomSettings.minZoomFactor?v.classList.add("e-overlay"):v&&v.classList.remove("e-overlay"):(v=document.querySelector("#"+o.element.id+"_zoomOut"))&&o.zoomSettings.zoomFactor<=o.zoomSettings.minZoomFactor?(v.classList.add("e-disabled"),v.parentElement.classList.add("e-overlay")):v&&(v.classList.remove("e-disabled"),v.parentElement.classList.remove("e-overlay")),this.autoEnablePan(),e.isNullOrUndefined(this.tempActiveObj)||(o.activeObj=e.extend({},this.tempActiveObj,{},!0)),"crop-custom"===o.activeObj.shape&&(o.currObjType.isCustomCrop=!0);var u=o.element.querySelector(".e-img-pan .e-btn");u&&o.togglePan?u.classList.add("e-selected-btn"):u&&u.classList.remove("e-selected-btn"),this.isShape&&(o.activeObj=e.extend({},o.objColl[o.objColl.length-1],{},!0),o.objColl.pop(),o.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate",obj:o.activeObj,isCropRatio:null,points:null,isPreventDrag:!0,saveContext:null,isPreventSelection:null}}),e.isBlazor()||(o.notify("toolbar",{prop:"update-toolbar-items",onPropertyChange:!1}),o.notify("toolbar",{prop:"renderQAT",onPropertyChange:!1,value:{isPenEdit:null}}))),e.isBlazor()?o.updateToolbar(o.element,"enableDisableToolbarBtn"):o.notify("toolbar",{prop:"enable-disable-btns",onPropertyChange:!1}),o.notify("selection",{prop:"setZoomType",onPropertyChange:!1,value:{zoomType:"Toolbar"}})}},i.prototype.disableZoomOutBtn=function(t){var i,o=this.parent,r=!1;e.isNullOrUndefined(t)||(o.transform.zoomFactor-=.1),i=e.isBlazor()?this.parent.element.querySelector("#zoomout"):document.querySelector("#"+o.element.id+"_zoomOut");var n=o.img.destLeft,a=o.img.destTop,s=o.img.destWidth,l=o.img.destHeight;return o.activeObj.shape?(this.setZoomDimension(-.1,o.activeObj),e.isNullOrUndefined(i)||(o.img.destLeft>o.activeObj.activePoint.startX||o.img.destTop>o.activeObj.activePoint.startY||o.img.destLeft+o.img.destWidth<o.activeObj.activePoint.endX||o.img.destTop+o.img.destHeight<o.activeObj.activePoint.endY||o.zoomSettings.zoomFactor===o.zoomSettings.minZoomFactor?(e.isBlazor()?i.classList.add("e-overlay"):(i.classList.add("e-disabled"),i.parentElement.classList.add("e-overlay")),r=!0):(e.isBlazor()?i.classList.remove("e-overlay"):(i.classList.remove("e-disabled"),i.parentElement.classList.remove("e-overlay")),r=!1))):this.setZoomDimension(-.1,null),e.isNullOrUndefined(t)||(o.transform.zoomFactor+=.1),o.img.destLeft=n,o.img.destTop=a,o.img.destWidth=s,o.img.destHeight=l,r},i.prototype.drawZoomImgToCanvas=function(t,e){var i=this.parent,o=Math.pow(10,1);Math.round(i.transform.zoomFactor*o)/o==.1&&-.1===t?i.transform.zoomFactor=0:i.transform.zoomFactor+=t,i.transform[i.isCropTab?"cropZoomFactor":"defaultZoomFactor"]=i.transform.zoomFactor;var r={width:0,height:0};i.isCropTab?r=this.cropZoom(t,e):((r=this.calcMaxDimension(i.img.srcWidth,i.img.srcHeight)).width+=r.width*i.transform.zoomFactor,r.height+=r.height*i.transform.zoomFactor,i.img.destLeft=(i.lowerCanvas.clientWidth-r.width)/2,i.img.destTop=(i.lowerCanvas.clientHeight-r.height)/2),i.notify("draw",{prop:"draw-image-to-canvas",value:{dimension:r}}),r.width=this.cropDimension.width,r.height=this.cropDimension.height,r.width+=r.width*i.transform.zoomFactor,r.height+=r.height*i.transform.zoomFactor,i.notify("draw",{prop:"setZoomCropWidth",value:{width:r.width,height:r.height}})},i.prototype.rotatedFlip=function(){var t=this.parent;this.isReverseFlip=!0;var i=t.transform.currFlipState,o=this.flipColl,r=e.extend([],t.objColl,[],!0),n=e.extend({},t.activeObj,{},!0);this.flipColl=[],t.objColl=[],t.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),t.notify("draw",{prop:"currTransState",onPropertyChange:!1,value:{type:"initial",isPreventDestination:null,context:null,isPreventCircleCrop:null}});var a=this.lowerContext.filter;t.notify("filter",{prop:"updateBrightFilter",onPropertyChange:!1}),this.lowerContext.drawImage(t.baseImg,t.img.srcLeft,t.img.srcTop,t.img.srcWidth,t.img.srcHeight,t.img.destLeft,t.img.destTop,t.img.destWidth,t.img.destHeight),this.lowerContext.filter=a,t.notify("draw",{prop:"currTransState",onPropertyChange:!1,value:{type:"reverse",isPreventDestination:!0,context:null,isPreventCircleCrop:null}}),""===i&&""!==t.transform.currFlipState&&(i=t.transform.currFlipState),t.transform.currFlipState=i,this.flipColl=o,t.objColl=e.extend([],r,[],!0),this.lowerContext.filter="none",t.notify("shape",{prop:"iterateObjColl",onPropertyChange:!1}),this.lowerContext.filter=a,0!==n.activePoint.width&&(t.activeObj=e.extend({},n,{},!0)),this.isReverseFlip=!1},i.prototype.rotateZoom=function(t){var i=this.parent,o=Math.pow(10,1);Math.round(i.transform.zoomFactor*o)/o==.1&&-.1===t?i.transform.zoomFactor=0:i.transform.zoomFactor+=t,i.isCropTab?i.transform.cropZoomFactor=i.transform.zoomFactor:i.transform.defaultZoomFactor=i.transform.zoomFactor;var r=e.extend([],i.objColl,[],!0),n=e.extend({},i.activeObj,{},!0);i.objColl=[],i.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),i.notify("draw",{prop:"updateCurrTransState",onPropertyChange:!1,value:{type:"initial",isPreventDestination:null,isRotatePan:null}}),i.notify("draw",{prop:"setRotateZoom",onPropertyChange:!1,value:{isRotateZoom:!0}}),i.notify("draw",{prop:"setDestPoints",onPropertyChange:!1});var a=this.lowerContext.filter;i.notify("filter",{prop:"updateBrightFilter",onPropertyChange:!1}),this.lowerContext.drawImage(i.baseImg,i.img.srcLeft,i.img.srcTop,i.img.srcWidth,i.img.srcHeight,i.img.destLeft,i.img.destTop,i.img.destWidth,i.img.destHeight),this.lowerContext.filter=a,i.notify("draw",{prop:"setRotateZoom",onPropertyChange:!1,value:{isRotateZoom:!1}}),i.notify("draw",{prop:"updateCurrTransState",onPropertyChange:!1,value:{type:"reverse",isPreventDestination:null,isRotatePan:null}}),i.objColl=r,i.activeObj=n;var s={width:this.cropDimension.width,height:this.cropDimension.height};s.width+=s.width*i.transform.zoomFactor,s.height+=s.height*i.transform.zoomFactor,i.notify("draw",{prop:"setZoomCropWidth",value:{width:s.width,height:s.height}})},i.prototype.autoEnablePan=function(){this.parent.transform.zoomFactor<=0?(this.parent.togglePan=!1,this.parent.notify("selection",{prop:"setDragCanvas",value:{bool:!1}}),this.parent.pan(!1),this.disablePan=!1):this.parent.pan(!this.disablePan)},i.prototype.cropZoom=function(t,i){var o=this.parent,r=o.img.destLeft,n=o.img.destTop,a={width:0,height:0};return 0===o.img.srcLeft||0===o.img.srcTop?a=e.isNullOrUndefined(i)?this.setZoomDimension(t,null):this.setZoomDimension(t,i):((a=o.transform.degree%90==0&&o.transform.degree%180!=0?this.calcMaxDimension(o.img.srcHeight,o.img.srcWidth):this.calcMaxDimension(o.img.srcWidth,o.img.srcHeight)).width+=a.width*o.transform.zoomFactor,a.height+=a.height*o.transform.zoomFactor),o.img.destLeft=r-(a.width-o.img.destWidth)/2,o.img.destTop=n-(a.height-o.img.destHeight)/2,r=o.img.destLeft,n=o.img.destTop,i&&(o.img.destLeft>i.activePoint.startX&&(o.img.destLeft=i.activePoint.startX,0===o.transform.degree&&(o.panPoint.totalPannedPoint.x-=r-o.img.destLeft)),o.img.destTop>i.activePoint.startY&&(o.img.destTop=i.activePoint.startY,0===o.transform.degree&&(o.panPoint.totalPannedPoint.y-=n-o.img.destTop)),o.img.destLeft+a.width<i.activePoint.endX&&(o.img.destLeft=i.activePoint.endX-a.width,0===o.transform.degree&&(o.panPoint.totalPannedPoint.x-=r-o.img.destLeft)),o.img.destTop+a.height<i.activePoint.endY&&(o.img.destTop=i.activePoint.endY-a.height,0===o.transform.degree&&(o.panPoint.totalPannedPoint.y-=n-o.img.destTop))),a},i.prototype.setZoomDimension=function(t,i){var o=this.parent,r={width:0,height:0};if(r=o.transform.degree%90==0&&o.transform.degree%180!=0?this.calcMaxDimension(o.img.srcHeight,o.img.srcWidth):this.calcMaxDimension(o.img.srcWidth,o.img.srcHeight),r.width+=r.width*o.transform.zoomFactor,r.height+=r.height*o.transform.zoomFactor,o.img.destLeft+=(o.img.destWidth-r.width)/2,o.img.destTop+=(o.img.destHeight-r.height)/2,t<0&&i){var n=i.activePoint.startX,a=i.activePoint.startY,s=i.activePoint.width,l=i.activePoint.height,p=o.img.destLeft+r.width,h=o.img.destTop+r.height;o.img.destLeft>n&&(o.img.destLeft=n),o.img.destTop>a&&(o.img.destTop=a),p<n+s&&(o.img.destLeft=n+s-r.width),h<a+l&&(o.img.destTop=a+l-r.height)}else t<0&&e.isNullOrUndefined(i)&&(o.img.destLeft>0&&(o.img.destLeft=0),o.img.destTop>0&&(o.img.destTop=0),o.img.destLeft+r.width<o.lowerCanvas.width&&(o.img.destLeft=o.lowerCanvas.width-o.img.destWidth),o.img.destTop+r.height<o.lowerCanvas.height&&(o.img.destTop=o.lowerCanvas.height-o.img.destHeight));return r},i.prototype.drawPannedImage=function(t,i){var o=this,r=this.parent,n={panDown:null};r.notify("selection",{prop:"getPanDown",onPropertyChange:!1,value:{obj:n}});var a={startPoint:n.panDown,endPoint:this.panMove,cancel:!1};e.isBlazor()&&e.isNullOrUndefined(this.parent.eventType)&&!e.isNullOrUndefined(r.events)&&!0===r.events.onPanStart.hasDelegate?(this.parent.eventType="pan",this.parent.panEventArgs=a,r.dotNetRef.invokeMethodAsync("PanEventAsync","OnPanStart",a).then(function(e){o.panEvent(e,t,i)})):(r.trigger("panning",a),this.panEvent(a,t,i))},i.prototype.panEvent=function(t,i,o){if(!t.cancel){var r=this.parent,n=!1;if(r.activeObj.shape&&"shape"===r.activeObj.shape&&r.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),e.isNullOrUndefined(r.activeObj.shape)){n=!0,r.activeObj.activePoint={startX:r.img.destLeft,startY:r.img.destTop,endX:r.img.destLeft+r.img.destWidth,endY:r.img.destTop+r.img.destHeight};var a=r.activeObj.activePoint.startX,s=r.activeObj.activePoint.startY,l=r.activeObj.activePoint.endX,p=r.activeObj.activePoint.endY;a<0&&(r.activeObj.activePoint.startX=0),s<0&&(r.activeObj.activePoint.startY=0),l>r.lowerCanvas.width&&(r.activeObj.activePoint.endX=r.lowerCanvas.width),p>r.lowerCanvas.height&&(r.activeObj.activePoint.endY=r.lowerCanvas.height),r.activeObj.activePoint.width=r.activeObj.activePoint.endX-r.activeObj.activePoint.startX,r.activeObj.activePoint.height=r.activeObj.activePoint.endY-r.activeObj.activePoint.startY,r.activeObj.shape="crop-custom";var h={strokeSettings:{}};r.notify("shape",{prop:"getStrokeSettings",onPropertyChange:!1,value:{obj:h}}),r.activeObj.strokeSettings=h.strokeSettings,r.notify("draw",{prop:"updateActiveObject",onPropertyChange:!1,value:{actPoint:r.activeObj.activePoint,obj:r.activeObj,isMouseMove:null,x:null,y:null}}),r.isCropTab=!0}if(0===r.transform.degree){var c=void 0;c=e.isNullOrUndefined(i)&&e.isNullOrUndefined(o)?this.updatePanPoints(""):{x:i,y:o},r.panPoint.totalPannedPoint.x+=c.x,r.panPoint.totalPannedPoint.y+=c.y;var d=e.extend({},r.activeObj,{},!0),v=this.lowerContext.filter;this.drawPannImage(c),this.lowerContext.filter=v,this.tempPanMove=e.extend({},this.panMove,{},!0),r.activeObj=e.extend({},d,{},!0),this.upperContext.clearRect(0,0,r.upperCanvas.width,r.upperCanvas.height),r.activeObj.shape&&r.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate",obj:r.activeObj}})}else{var u=r.transform.currFlipState;r.isCropTab=!0,e.isNullOrUndefined(i)&&e.isNullOrUndefined(o)?r.panPoint.currentPannedPoint=this.updatePanPoints(""):r.panPoint.currentPannedPoint={x:i,y:o},r.transform.currFlipState=u,this.rotatePan(),r.isCropTab=!1,this.tempPanMove=e.extend({},this.panMove,{},!0)}n&&(r.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),r.isCropTab=!1,this.upperContext.clearRect(0,0,r.upperCanvas.width,r.upperCanvas.height))}},i.prototype.drawPannImage=function(t){var e=this.parent,i={startX:e.img.destLeft,startY:e.img.destTop,width:e.img.destWidth,height:e.img.destHeight};this.lowerContext.clearRect(0,0,e.lowerCanvas.width,e.lowerCanvas.height),e.notify("draw",{prop:"updateCurrTransState",onPropertyChange:!1,value:{type:"initial",isPreventDestination:null,isRotatePan:null}}),e.img.destLeft=i.startX,e.img.destTop=i.startY,e.img.destWidth=i.width,e.img.destHeight=i.height,this.setDestPointsForFlipState(),e.notify("filter",{prop:"updateBrightFilter",onPropertyChange:!1}),this.lowerContext.drawImage(e.baseImg,e.img.srcLeft,e.img.srcTop,e.img.srcWidth,e.img.srcHeight,e.img.destLeft,e.img.destTop,e.img.destWidth,e.img.destHeight),(e.currSelectionPoint&&"crop-circle"===e.currSelectionPoint.shape||e.isCircleCrop)&&e.notify("crop",{prop:"cropCircle",onPropertyChange:!1,value:{context:this.lowerContext,isSave:null,isFlip:!0}}),e.notify("draw",{prop:"updateCurrTransState",onPropertyChange:!1,value:{type:"reverse",isPreventDestination:null,isRotatePan:null}}),e.img.destLeft=i.startX,e.img.destTop=i.startY,e.img.destWidth=i.width,e.img.destHeight=i.height;var o=this.lowerContext.filter;this.lowerContext.filter="none",e.notify("shape",{prop:"panObjColl",onPropertyChange:!1,value:{xDiff:t.x,yDiff:t.y,panRegion:""}}),e.notify("freehand-draw",{prop:"panFHDColl",onPropertyChange:!1,value:{xDiff:t.x,yDiff:t.y,panRegion:""}}),this.lowerContext.filter=o,e.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.lowerContext}}),e.isCircleCrop&&e.notify("crop",{prop:"cropCircle",onPropertyChange:!1,value:{context:this.lowerContext,isSave:null,isFlip:!0}})},i.prototype.resetZoom=function(){var t=this.parent;if(0!==t.transform.defaultZoomFactor){var i=t.isUndoRedo,o={currObj:{}};t.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:o}}),this.transCurrObj=o.currObj,this.transCurrObj.objColl=e.extend([],t.objColl,null,!0),this.transCurrObj.pointColl=e.extend({},t.pointColl,null,!0),this.transCurrObj.afterCropActions=e.extend([],t.afterCropActions,[],!0);var r={selPointColl:null};t.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:r}}),this.transCurrObj.selPointColl=e.extend([],r.selPointColl,[],!0),t.isUndoRedo=t.isCropToolbar=!0,t.transform.defaultZoomFactor>0?this.zoomAction(-t.transform.defaultZoomFactor):this.zoomAction(Math.abs(t.transform.defaultZoomFactor)),t.isCropToolbar=!1,t.isUndoRedo=i}},i.prototype.performTransformation=function(t){var i=this.parent,o=i.transform.defaultZoomFactor,r=i.isUndoRedo,n=e.extend({},i.cropObj,{},!0);this.resetZoom(),this.updateTransform(t);for(var a=0,s=i.objColl.length;a<s;a++)if(i.objColl[a].flipObjColl.length>0){var l={collection:i.objColl[a].flipObjColl};i.notify("shape",{prop:"alignRotateFlipColl",onPropertyChange:!1,value:{collection:i.objColl[a].flipObjColl,isRotateFlipCollection:null,obj:l}}),i.objColl[a].flipObjColl=l.collection}if(0!==o){i.isUndoRedo=!0,this.zoomAction(o),i.isUndoRedo=r;var p="";"rotateleft"===t||"rotateright"===t?p="rotate":"horizontalflip"!==t&&"verticalflip"!==t||(p="flip"),i.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:p,previousObj:this.transCurrObj,previousObjColl:this.transCurrObj.objColl,previousPointColl:this.transCurrObj.pointColl,previousSelPointColl:this.transCurrObj.selPointColl,previousCropObj:n,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),this.transCurrObj=null}},i.prototype.updateTransform=function(e){switch(e.toLowerCase()){case"rotateleft":this.rotateImage(-90);break;case"rotateright":this.rotateImage(90);break;case"horizontalflip":this.flipImage(t.Direction.Horizontal);break;case"verticalflip":this.flipImage(t.Direction.Vertical)}},i.prototype.rotatePan=function(t,i){var o=this.parent;this.isReverseRotate=!0;var r,n=o.transform.degree,a={selPointColl:null};e.isNullOrUndefined(o.activeObj.activePoint)||e.isNullOrUndefined(o.activeObj.shape)||(r=e.extend({},o.activeObj,{},!0));var s=e.extend([],o.objColl,[],!0),l=e.extend([],o.pointColl,[],!0);o.objColl=[],o.pointColl=[],o.freehandCounter=0,o.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:a}});var p=a.selPointColl;o.notify("freehand-draw",{prop:"setSelPointColl",onPropertyChange:!1,value:{obj:{selPointColl:[]}}}),o.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),o.notify("draw",{prop:"setRotateZoom",onPropertyChange:!1,value:{isRotateZoom:!0}}),o.notify("draw",{prop:"updateCurrTransState",onPropertyChange:!1,value:{type:"initial",isPreventDestination:null,isRotatePan:null}});var h=o.img.destLeft,c=o.img.destTop;o.isCropTab&&(o.img.destLeft+=o.panPoint.totalPannedInternalPoint.x,o.img.destTop+=o.panPoint.totalPannedInternalPoint.y),o.notify("crop",{prop:"updateRotatePan",onPropertyChange:!1}),o.isCropTab&&(o.panPoint.totalPannedInternalPoint.x=o.img.destLeft-h,o.panPoint.totalPannedInternalPoint.y=o.img.destTop-c);var d=this.lowerContext.filter;o.notify("filter",{prop:"updateBrightFilter",onPropertyChange:!1}),this.lowerContext.drawImage(o.baseImg,o.img.srcLeft,o.img.srcTop,o.img.srcWidth,o.img.srcHeight,o.img.destLeft,o.img.destTop,o.img.destWidth,o.img.destHeight),o.notify("draw",{prop:"setRotateZoom",onPropertyChange:!1,value:{isRotateZoom:!1}}),o.notify("draw",{prop:"updateCurrTransState",onPropertyChange:!1,value:{type:"reverse",isPreventDestination:!0,isRotatePan:!0}});var v=o.img.destLeft,u=o.img.destTop;o.img.destLeft+=o.panPoint.totalPannedClientPoint.x,o.img.destTop+=o.panPoint.totalPannedClientPoint.y,o.img.destLeft+=o.panPoint.currentPannedPoint.x,o.img.destTop+=o.panPoint.currentPannedPoint.y,o.panPoint.totalPannedClientPoint.x=o.img.destLeft-v,o.panPoint.totalPannedClientPoint.y=o.img.destTop-u,o.objColl=s,o.pointColl=l,o.freehandCounter=o.pointColl.length,o.notify("freehand-draw",{prop:"setSelPointColl",onPropertyChange:!1,value:{obj:{selPointColl:p}}}),o.transform.degree=n,this.lowerContext.filter="none",t&&(i?(o.panPoint.totalPannedClientPoint.x=-o.panPoint.totalPannedClientPoint.x,o.panPoint.totalPannedClientPoint.y=-o.panPoint.totalPannedClientPoint.y,o.panPoint.currentPannedPoint=e.extend({},o.panPoint.totalPannedClientPoint,{},!0),o.panPoint.totalPannedClientPoint={x:0,y:0},o.img.destLeft+=o.panPoint.currentPannedPoint.x,o.img.destTop+=o.panPoint.currentPannedPoint.y):o.panPoint.currentPannedPoint=e.extend({},o.panPoint.totalPannedClientPoint,{},!0)),o.notify("shape",{prop:"panObjColl",onPropertyChange:!1,value:{xDiff:o.panPoint.currentPannedPoint.x,yDiff:o.panPoint.currentPannedPoint.y,panRegion:""}}),o.notify("freehand-draw",{prop:"panFHDColl",onPropertyChange:!1,value:{xDiff:o.panPoint.currentPannedPoint.x,yDiff:o.panPoint.currentPannedPoint.y,panRegion:""}}),this.lowerContext.filter=d,o.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.lowerContext}}),this.upperContext.clearRect(0,0,o.upperCanvas.width,o.upperCanvas.height),o.activeObj=e.extend({},r,{},!0),e.isNullOrUndefined(o.activeObj.activePoint)||o.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate",obj:o.activeObj,isCropRatio:null,points:null,isPreventDrag:!0,saveContext:null,isPreventSelection:null}}),this.isReverseRotate=!1},i.prototype.limitPan=function(){var t=this.parent;t.activeObj.activePoint&&(t.img.destLeft>t.activeObj.activePoint.startX&&(t.img.destLeft=t.activeObj.activePoint.startX),t.img.destTop>t.activeObj.activePoint.startY&&(t.img.destTop=t.activeObj.activePoint.startY),t.img.destLeft+t.img.destWidth<t.activeObj.activePoint.endX&&(t.img.destLeft=t.activeObj.activePoint.endX-t.img.destWidth),t.img.destTop+t.img.destHeight<t.activeObj.activePoint.endY&&(t.img.destTop=t.activeObj.activePoint.endY-t.img.destHeight))},i.prototype.updateFlipActiveObj=function(t){var e=this.parent;"horizontal"===t?(e.activeObj.activePoint.startX>e.lowerCanvas.width/2?e.activeObj.activePoint.endX=e.lowerCanvas.width/2-(e.activeObj.activePoint.startX-e.lowerCanvas.width/2):e.activeObj.activePoint.endX=e.lowerCanvas.width/2+(e.lowerCanvas.width/2-e.activeObj.activePoint.startX),e.activeObj.activePoint.startX=e.activeObj.activePoint.endX-e.activeObj.activePoint.width):"vertical"===t?(e.activeObj.activePoint.startX>e.lowerCanvas.width/2?e.activeObj.activePoint.endY=e.lowerCanvas.height/2-(e.activeObj.activePoint.startY-e.lowerCanvas.height/2):e.activeObj.activePoint.endY=e.lowerCanvas.height/2+(e.lowerCanvas.height/2-e.activeObj.activePoint.startY),e.activeObj.activePoint.startY=e.activeObj.activePoint.endY-e.activeObj.activePoint.height):"verticalHorizontal"!==t&&"horizontalVertical"!==t||(e.activeObj.activePoint.startX>e.lowerCanvas.width/2?(e.activeObj.activePoint.endX=e.lowerCanvas.width/2-(e.activeObj.activePoint.startX-e.lowerCanvas.width/2),e.activeObj.activePoint.endY=e.lowerCanvas.height/2-(e.activeObj.activePoint.startY-e.lowerCanvas.height/2)):(e.activeObj.activePoint.endX=e.lowerCanvas.width/2+(e.lowerCanvas.width/2-e.activeObj.activePoint.startX),e.activeObj.activePoint.endY=e.lowerCanvas.height/2+(e.lowerCanvas.height/2-e.activeObj.activePoint.startY)),e.activeObj.activePoint.startX=e.activeObj.activePoint.endX-e.activeObj.activePoint.width,e.activeObj.activePoint.startY=e.activeObj.activePoint.endY-e.activeObj.activePoint.height),e.notify("draw",{prop:"updateActiveObject",onPropertyChange:!1,value:{actPoint:e.activeObj.activePoint,obj:e.activeObj,isMouseMove:null,x:null,y:null}})},i.prototype.pan=function(t){var e=this.parent;!e.disabled&&e.isImageLoaded&&(t?(e.togglePan=!0,e.notify("shape",{prop:"redrawActObj",onPropertyChange:!1,value:{x:null,y:null,isMouseDown:null}}),e.notify("selection",{prop:"setDragCanvas",value:{bool:!0}}),e.lowerCanvas.style.cursor=e.upperCanvas.style.cursor=e.cursor="grab",e.notify("selection",{prop:"setPanDown",onPropertyChange:!1,value:{panDown:null}})):(e.togglePan=e.currObjType.isCustomCrop=!1,e.notify("selection",{prop:"setDragCanvas",value:{bool:!1}}),e.lowerCanvas.style.cursor=e.upperCanvas.style.cursor=e.cursor="default"))},i.prototype.zoom=function(t,i){var o=this.parent;if(!o.disabled&&o.isImageLoaded){var r=this.getCurrentZoomFactor(t);if(e.isNullOrUndefined(i))this.zoomAction(r,i);else for(var n=r>0?"zoomIn":"zoomOut",a=0;a<10*Math.abs(r);a++)o.notify("draw",{prop:"performPointZoom",onPropertyChange:!1,value:{x:i.x,y:i.y,type:n}})}},i.prototype.getCurrentZoomFactor=function(t){return.1*(t-this.prevZoomValue)},i.prototype.setCurrPanRegion=function(t,e,i){var o=t;""===t?"horizontal"===e?o="horizontal":"vertical"===e&&(o="vertical"):"horizontal"===t?"horizontal"===e?o="horizontalVertical":"vertical"===e?o="verticalHorizontal":90===e?o="vertical":-90===e&&(o="horizontal"):"vertical"===t?"horizontal"===e?o="horizontalVertical":"vertical"===e?o="verticalHorizontal":90===e?o="horizontal":-90===e&&(o="vertical"):"horizontal"===e?o="vertical":"vertical"===e&&(o="horizontal"),i.panRegion=o},i.prototype.rotate=function(t,e){var i=this.parent;!i.disabled&&i.isImageLoaded&&t%90==0&&this.rotateImage(t),e.isRotate=!1},i.prototype.flip=function(t){var e=this.parent;!e.disabled&&e.isImageLoaded&&this.flipImage(t)},i.prototype.update=function(){var t=this.parent,i=0,o=document.querySelector("#"+t.element.id+"_canvasWrapper");e.isNullOrUndefined(o)||(o.style.width=t.element.offsetWidth-2+"px"),t.lowerCanvas.width=t.upperCanvas.width=t.element.offsetWidth-2,e.isNullOrUndefined(t.toolbarTemplate)?t.element.querySelector("#"+t.element.id+"_toolbar")&&(i=t.element.querySelector("#"+t.element.id+"_toolbar").clientHeight,t.notify("toolbar",{prop:"setToolbarHeight",value:{height:i}})):t.notify("toolbar",{prop:"setToolbarHeight",value:{height:0}}),e.Browser.isDevice?(e.isNullOrUndefined(o)||(o.style.height=t.element.offsetHeight-2*i-5+"px"),t.lowerCanvas.height=t.upperCanvas.height=t.element.offsetHeight-2*i-5):(e.isNullOrUndefined(o)||(o.style.height=t.element.offsetHeight-i-3+"px"),t.lowerCanvas.height=t.upperCanvas.height=t.element.offsetHeight-i-3),this.lowerContext.filter="brightness(1) contrast(100%) hue-rotate(0deg) saturate(100%) opacity(1) blur(0px) sepia(0%) grayscale(0%) invert(0%)",t.notify("filter",{prop:"setAdjustmentValue",onPropertyChange:!1,value:{adjustmentValue:this.lowerContext.filter}}),this.parent.canvasFilter=this.lowerContext.filter,this.parent.initialAdjustmentValue=this.lowerContext.filter,this.parent.clearContext(this.lowerContext),this.parent.clearContext(this.upperContext)},i.prototype.calcMaxDimension=function(t,i,o){var r={toolbarHeight:0};e.isBlazor()?r.toolbarHeight=this.parent.toolbarHeight:this.parent.notify("toolbar",{prop:"getToolbarHeight",value:{obj:r}});var n=this.parent.element.clientWidth,a=this.parent.element.clientHeight-r.toolbarHeight;a=e.Browser.isDevice?a-r.toolbarHeight:a,n>30&&(n-=30),a>30&&(a-=30);var s=n/t,l=a/i,p=Math.min(t,n),h=Math.min(i,a);return s<1&&s<l?(p=t*s,h=i*s):l<1&&l<s&&(p=t*l,h=i*l),e.isNullOrUndefined(o)||(o.width=p,o.height=h),{width:p,height:h}},i.prototype.updatePanPoints=function(t,i){var o=this.parent,r=e.extend({},o.activeObj,{},!0),n=o.img.destLeft,a=o.img.destTop;e.isNullOrUndefined(this.tempPanMove)&&(this.tempPanMove={x:this.panMove.x,y:this.panMove.y});var s=this.panMove.x-this.tempPanMove.x,l=this.panMove.y-this.tempPanMove.y;switch(t){case"":o.img.destLeft+=s,o.img.destTop+=l;break;case"horizontal":this.updateFlipActiveObj(t),s=this.tempPanMove.x-this.panMove.x,o.img.destLeft+=s,o.img.destTop+=l;break;case"vertical":this.updateFlipActiveObj(t),l=this.tempPanMove.y-this.panMove.y,o.img.destLeft+=s,o.img.destTop+=l;break;case"horizontalVertical":this.updateFlipActiveObj(t),s=this.tempPanMove.x-this.panMove.x,o.img.destLeft+=s,o.img.destTop-=l;break;case"verticalHorizontal":this.updateFlipActiveObj(t),l=this.tempPanMove.y-this.panMove.y,o.img.destLeft-=s,o.img.destTop+=l}return this.limitPan(),o.activeObj=r,e.isNullOrUndefined(i)||(i.x=o.img.destLeft-n,i.y=o.img.destTop-a),{x:o.img.destLeft-n,y:o.img.destTop-a}},i}(),u=function(){function t(t){this.undoRedoStep=0,this.undoRedoColl=[],this.appliedUndoRedoColl=[],this.tempUndoRedoColl=[],this.tempUndoRedoStep=0,this.parent=t,this.addEventListener()}return t.prototype.destroy=function(){this.parent.isDestroyed||this.removeEventListener()},t.prototype.addEventListener=function(){this.parent.on("undo-redo",this.undoRedo,this),this.parent.on("destroyed",this.destroy,this)},t.prototype.removeEventListener=function(){this.parent.off("undo-redo",this.undoRedo),this.parent.off("destroyed",this.destroy)},t.prototype.initializeUrPvtProp=function(){e.isNullOrUndefined(this.parent.lowerCanvas)||(this.lowerContext=this.parent.lowerCanvas.getContext("2d")),e.isNullOrUndefined(this.parent.upperCanvas)||(this.upperContext=this.parent.upperCanvas.getContext("2d"))},t.prototype.undoRedo=function(t){switch(this.initializeUrPvtProp(),t.prop){case"updateUndoRedoColl":this.updateUrc(t.value.operation,t.value.previousObj,t.value.previousObjColl,t.value.previousPointColl,t.value.previousSelPointColl,t.value.previousCropObj,t.value.previousText,t.value.currentText,t.value.previousFilter,t.value.isCircleCrop);break;case"refreshUrc":this.refreshUrc(t.value.bool);break;case"updateCurrUrc":this.updateCurrUrc(t.value.type);break;case"call-undo":this.callUndo();break;case"call-redo":this.callRedo();break;case"undo":this.undo();break;case"redo":this.redo();break;case"updateUrObj":this.updateUrObj(t.value.objColl);break;case"updateUndoRedo":this.updateUndoRedo();break;case"getAppliedUndoRedoColl":t.value.obj.appliedUndoRedoColl=this.appliedUndoRedoColl;break;case"getUndoRedoStep":t.value.obj.undoRedoStep=this.undoRedoStep;break;case"setUndoRedoStep":this.undoRedoStep=t.value.step;break;case"undoDefault":this.undoDefault(t.value.obj);break;case"reset":this.reset()}},t.prototype.getModuleName=function(){return"undo-redo"},t.prototype.reset=function(){this.tempCurrSelPoint=null,this.undoRedoStep=0,this.undoRedoColl=[],this.appliedUndoRedoColl=[],this.tempActObj=null,this.tempUndoRedoColl=[],this.tempUndoRedoStep=0},t.prototype.refreshUrc=function(t){var i=this.parent;(t=t||!1)?(e.isBlazor()||i.notify("toolbar",{prop:"setEnableDisableUndoRedo",value:{isPrevent:!0}}),this.tempUndoRedoColl=e.extend([],this.appliedUndoRedoColl,[],!0),this.tempUndoRedoStep=this.undoRedoStep):e.isBlazor()||i.notify("toolbar",{prop:"setEnableDisableUndoRedo",value:{isPrevent:!1}}),this.undoRedoColl=this.undoRedoColl.slice(0,this.undoRedoStep),this.appliedUndoRedoColl=this.appliedUndoRedoColl.slice(0,this.undoRedoStep),i.isUndoRedo=i.currObjType.isUndoAction=!1,e.isBlazor()?i.updateToolbar(i.element,"enableDisableToolbarBtn"):i.notify("toolbar",{prop:"enable-disable-btns"})},t.prototype.updateCurrUrc=function(t){var i=this.parent;if(e.isBlazor()||i.notify("toolbar",{prop:"setEnableDisableUndoRedo",value:{isPrevent:!1}}),"ok"===t){i.notify("draw",{prop:"setShapeTextInsert",onPropertyChange:!1,value:{bool:!1}});var o=this.tempUndoRedoColl.length>0?e.extend([],this.tempUndoRedoColl,[],!0):e.extend([],this.undoRedoColl,[],!0),r=this.undoRedoColl[this.undoRedoColl.length-1];if(e.isNullOrUndefined(this.appliedUndoRedoColl[this.appliedUndoRedoColl.length-1])?this.undoRedoColl[0]&&(r.previousCropObj=o[0].previousCropObj,r.previousObj=o[0].previousObj,r.previousObjColl=o[0].previousObjColl,r.previousPointColl=o[0].previousPointColl,r.previousText=o[0].previousText):(r.previousCropObj=this.appliedUndoRedoColl[this.appliedUndoRedoColl.length-1].currentCropObj,r.previousObj=this.appliedUndoRedoColl[this.appliedUndoRedoColl.length-1].currentObj,r.previousObjColl=this.appliedUndoRedoColl[this.appliedUndoRedoColl.length-1].currentObjColl,r.previousPointColl=this.appliedUndoRedoColl[this.appliedUndoRedoColl.length-1].currentPointColl,r.previousText=this.appliedUndoRedoColl[this.appliedUndoRedoColl.length-1].currentText),r){var n=this.getZeroZoomObjPointValue(r.currentObjColl,r.currentPointColl);r.currentObjColl=n.obj,r.currentPointColl=n.point,this.appliedUndoRedoColl.push(r)}this.tempUndoRedoColl=[],this.tempUndoRedoStep=0}else this.tempUndoRedoColl.length>0&&(this.appliedUndoRedoColl=e.extend([],this.tempUndoRedoColl,[],!0),this.undoRedoStep=this.tempUndoRedoStep,this.tempUndoRedoColl=[],this.tempUndoRedoStep=0);this.appliedUndoRedoColl.length>16&&this.appliedUndoRedoColl.splice(0,1),this.undoRedoColl=[],this.undoRedoColl=e.extend([],this.appliedUndoRedoColl,[],!0),"ok"===t&&(this.undoRedoStep=this.undoRedoColl.length,e.isBlazor()?i.updateToolbar(i.element,"enableDisableToolbarBtn"):i.notify("toolbar",{prop:"enable-disable-btns"})),i.transform.zoomFactor>0&&(i.togglePan=!0,i.notify("selection",{prop:"setDragCanvas",value:{bool:!0}}))},t.prototype.cancelCropSelection=function(){var t,i=this.parent,o=!1;i.activeObj.shape&&(t=i.activeObj.shape.split("-")),(i.currObjType.isCustomCrop||t&&"crop"===t[0])&&(o=!0),o&&i.notify("draw",{prop:"performCancel",value:{isContextualToolbar:null}}),0===this.tempUndoRedoColl.length&&0===this.tempUndoRedoStep||(this.appliedUndoRedoColl=e.extend([],this.tempUndoRedoColl,[],!0),this.undoRedoColl=e.extend([],this.tempUndoRedoColl,[],!0),this.undoRedoStep=this.tempUndoRedoStep,this.tempUndoRedoColl=[],this.tempUndoRedoStep=0,e.isBlazor()||i.notify("toolbar",{prop:"setEnableDisableUndoRedo",value:{isPrevent:!1}}))},t.prototype.refreshToolbarActions=function(){var t=this.parent;e.isBlazor()?e.isNullOrUndefined(t.activeObj.shape)&&t.updateToolbar(t.element,"imageLoaded"):t.activeObj.shape?(t.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"shapes",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}}),t.notify("toolbar",{prop:"update-toolbar-items",onPropertyChange:!1})):t.notify("toolbar",{prop:"refresh-main-toolbar",onPropertyChange:!1})},t.prototype.applyCurrentChanges=function(){var t=this.parent;t.currObjType.isFiltered=!1,0===t.transform.zoomFactor&&(t.togglePan=!1,t.notify("selection",{prop:"setDragCanvas",value:{bool:!1}})),t.element.querySelector(".e-contextual-toolbar-wrapper")&&!e.isBlazor()&&t.element.querySelector(".e-contextual-toolbar-wrapper").classList.add("e-hide"),t.togglePen&&(t.togglePen=!1,t.upperCanvas.style.cursor=t.cursor="default",this.upperContext.clearRect(0,0,t.upperCanvas.width,t.upperCanvas.height)),this.appliedUndoRedoColl.length>0&&(this.undoRedoColl=e.extend([],this.appliedUndoRedoColl,[],!0))},t.prototype.callUndo=function(){this.applyCurrentChanges(),this.undo()},t.prototype.callRedo=function(){this.applyCurrentChanges(),this.redo()},t.prototype.undo=function(){var t=this.parent;if(this.cancelCropSelection(),!t.disabled&&t.isImageLoaded&&this.undoRedoStep>0){this.refreshToolbarActions(),e.isNullOrUndefined(t.activeObj.activePoint)||0===t.activeObj.activePoint.width||(this.tempActObj=t.activeObj),t.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),this.undoRedoStep--,e.isBlazor()?t.updateToolbar(t.element,"enableDisableToolbarBtn"):(t.notify("toolbar",{prop:"enable-disable-btns"}),t.element.querySelector(".e-contextual-toolbar-wrapper").classList.add("e-hide")),t.isUndoRedo=!0;var i=this.undoRedoColl[this.undoRedoStep];this.undoRedoColl.length===this.undoRedoStep?t.currObjType.isUndoAction=!1:t.currObjType.isUndoAction=!0,"textAreaCustomization"!==i.operation&&"block"===t.textArea.style.display&&(t.textArea.style.display="none"),t.notify("draw",{prop:"setCancelAction",onPropertyChange:!1,value:{bool:!0}});switch(t.cropObj=e.extend({},i.previousCropObj,{},!0),t.afterCropActions=i.previousObj.afterCropActions,this.lowerContext.filter=i.previousObj.filter,t.canvasFilter=this.lowerContext.filter,i.operation){case"shapeTransform":this.shapeTransform(i.previousObjColl);break;case"freehanddraw":case"freehand-draw":this.updateFreehandDraw(i.previousPointColl);break;case"freehanddrawCustomized":this.updateFreehandDrawCustomized(i.previousPointColl);break;case"deleteFreehandDrawing":case"deleteObj":this.updateDelete(i.operation,i.previousObjColl,i.previousPointColl);break;case"textAreaCustomization":this.updateTextAreaCustomization(void 0,i.previousObjColl);break;case"text":this.updateText(i.previousObjColl,!0);break;default:this.undoDefault(i),t.notify("filter",{prop:"set-adjustment",value:{operation:i.operation}}),t.notify("filter",{prop:"update-filter",value:{operation:i.operation,filter:i.filter}})}"crop"===i.operation&&(i.previousObj.currSelectionPoint&&(t.currSelectionPoint=e.extend({},i.previousObj.currSelectionPoint,{},!0),t.currSelectionPoint&&e.isNullOrUndefined(t.currSelectionPoint.shape)&&(t.currSelectionPoint=null)),t.updateCropTransformItems(),t.select("custom"),t.isCircleCrop&&(t.isCircleCrop=!1,this.tempCurrSelPoint=e.extend({},t.currSelectionPoint,{},!0),t.currSelectionPoint=null),t.notify("draw",{prop:"performCancel",value:{isContextualToolbar:null}})),this.undoRedoColl[this.undoRedoStep-1]&&this.undoRedoColl[this.undoRedoStep-1].isCircleCrop&&(t.isCircleCrop=!0,t.notify("crop",{prop:"cropCircle",onPropertyChange:!1,value:{context:this.lowerContext,isSave:null,isFlip:null}})),this.endUndoRedo(i.operation,!0)}},t.prototype.redo=function(){var t=this.parent;if(this.cancelCropSelection(),!t.disabled&&t.isImageLoaded&&this.undoRedoStep<this.appliedUndoRedoColl.length){this.refreshToolbarActions(),this.undoRedoStep++,e.isBlazor()?t.updateToolbar(t.element,"enableDisableToolbarBtn"):t.notify("toolbar",{prop:"enable-disable-btns"}),t.isUndoRedo=!0;var i=this.undoRedoColl[this.undoRedoStep-1];this.undoRedoColl.length===this.undoRedoStep?t.currObjType.isUndoAction=!1:t.currObjType.isUndoAction=!0,"textAreaCustomization"!==i.operation&&"block"===t.textArea.style.display&&(t.textArea.style.display="none"),t.notify("draw",{prop:"setCancelAction",onPropertyChange:!1,value:{bool:!0}}),t.cropObj=e.extend({},i.currentCropObj,{},!0),t.afterCropActions=i.currentObj.afterCropActions,this.lowerContext.filter=i.currentObj.filter,e.isBlazor()||t.element.querySelector(".e-contextual-toolbar-wrapper").classList.add("e-hide"),t.canvasFilter=this.lowerContext.filter;var o=void 0;switch(i.operation){case"shapeTransform":this.shapeTransform(i.currentObjColl);break;case"freehanddraw":case"freehand-draw":this.updateFreehandDraw(i.currentPointColl);break;case"freehanddrawCustomized":this.updateFreehandDrawCustomized(i.currentPointColl);break;case"deleteFreehandDrawing":case"deleteObj":this.updateDelete(i.operation,i.currentObjColl,i.currentPointColl);break;case"textAreaCustomization":this.updateTextAreaCustomization(o,i.currentObjColl);break;case"text":this.updateText(i.currentObjColl,!1);break;default:t.objColl=[],t.pointColl=[],t.freehandCounter=0,t.notify("freehand-draw",{prop:"setSelPointColl",onPropertyChange:!1,value:{obj:{selPointColl:[]}}}),t.notify("draw",{prop:"setCurrentObj",onPropertyChange:!1,value:{obj:i.currentObj}}),t.img.destLeft=i.currentObj.destPoints.startX,t.img.destTop=i.currentObj.destPoints.startY,o=e.extend({},t.activeObj,{},!0),t.objColl=e.extend([],i.currentObjColl,[],!0),t.pointColl=e.extend([],i.currentPointColl,[],!0),t.freehandCounter=t.pointColl.length,t.notify("freehand-draw",{prop:"setSelPointColl",onPropertyChange:!1,value:{obj:{selPointColl:e.extend([],i.currentSelPointColl,[],!0)}}}),this.lowerContext.filter="none",t.notify("shape",{prop:"zoomObjColl",onPropertyChange:!1,value:{isPreventApply:null}}),t.notify("freehand-draw",{prop:"zoomFHDColl",onPropertyChange:!1,value:{isPreventApply:null}}),this.lowerContext.filter=i.currentObj.filter,t.activeObj=o,this.upperContext.clearRect(0,0,t.upperCanvas.width,t.upperCanvas.height),0!==t.activeObj.activePoint.width&&0!==t.activeObj.activePoint.height&&t.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate"}}),t.notify("filter",{prop:"set-adjustment",value:{operation:i.operation}}),t.notify("filter",{prop:"update-filter",value:{operation:i.operation}})}"crop"===i.operation&&i.isCircleCrop&&(t.isCircleCrop=!0,t.currSelectionPoint=e.extend({},this.tempCurrSelPoint,{},!0),this.tempCurrSelPoint=null),"crop"!==i.operation||i.isCircleCrop||(t.isCircleCrop=!1),"crop"!==i.operation||e.isNullOrUndefined(i.currentObj.currSelectionPoint)||(t.currSelectionPoint=e.extend({},i.currentObj.currSelectionPoint,{},!0)),!e.isNullOrUndefined(t.currSelectionPoint)&&e.isNullOrUndefined(t.currSelectionPoint.shape)&&(t.currSelectionPoint=null),this.endUndoRedo(i.operation,!1)}},t.prototype.shapeTransform=function(t){var i=this.parent;i.objColl=e.extend([],t,[],!0),i.notify("shape",{prop:"zoomObjColl",onPropertyChange:!1,value:{isPreventApply:null}}),this.lowerContext.clearRect(0,0,i.lowerCanvas.width,i.lowerCanvas.height),this.upperContext.clearRect(0,0,i.upperCanvas.width,i.upperCanvas.height),i.isUndoRedo=!0,i.notify("draw",{prop:"redrawImgWithObj",onPropertyChange:!1}),i.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1})},t.prototype.updateFreehandDraw=function(t){var e=this.parent;e.pointColl=t,e.freehandCounter=e.pointColl.length,e.notify("freehand-draw",{prop:"zoomFHDColl",onPropertyChange:!1,value:{isPreventApply:null}}),this.lowerContext.clearRect(0,0,e.lowerCanvas.width,e.lowerCanvas.height),this.upperContext.clearRect(0,0,e.upperCanvas.width,e.upperCanvas.height),e.isUndoRedo=!0,e.notify("draw",{prop:"redrawImgWithObj",onPropertyChange:!1})},t.prototype.updateFreehandDrawCustomized=function(t){var e=this.parent;e.pointColl=t,e.notify("freehand-draw",{prop:"zoomFHDColl",onPropertyChange:!1,value:{isPreventApply:null}}),this.lowerContext.clearRect(0,0,e.lowerCanvas.width,e.lowerCanvas.height),this.upperContext.clearRect(0,0,e.upperCanvas.width,e.upperCanvas.height),e.isUndoRedo=!0,e.notify("draw",{prop:"redrawImgWithObj",onPropertyChange:!1})},t.prototype.updateDelete=function(t,e,i){var o=this.parent;"deleteFreehandDrawing"===t?(o.pointColl=i,o.freehandCounter=o.pointColl.length,o.notify("freehand-draw",{prop:"zoomFHDColl",onPropertyChange:!1,value:{isPreventApply:null}})):"deleteObj"===t&&(o.objColl=e,o.notify("shape",{prop:"zoomObjColl",onPropertyChange:!1,value:{isPreventApply:null}})),this.lowerContext.clearRect(0,0,o.lowerCanvas.width,o.lowerCanvas.height),this.upperContext.clearRect(0,0,o.upperCanvas.width,o.upperCanvas.height),o.isUndoRedo=!0,o.notify("draw",{prop:"redrawImgWithObj",onPropertyChange:!1})},t.prototype.updateTextAreaCustomization=function(t,i){var o=this.parent;o.objColl=e.extend([],i,[],!0),o.notify("shape",{prop:"zoomObjColl",onPropertyChange:!1,value:{isPreventApply:!0}}),this.lowerContext.clearRect(0,0,o.lowerCanvas.width,o.lowerCanvas.height),o.isUndoRedo=!0,o.notify("draw",{prop:"redrawImgWithObj",onPropertyChange:!1});for(var r=0,n=i.length;r<n;r++){if(!this.tempActObj){t=e.extend({},i[i.length-1],{},!0),o.objColl.splice(r,1);break}if(this.tempActObj.currIndex===i[r].currIndex){t=e.extend({},i[r],{},!0),o.objColl.splice(r,1);break}}t&&this.updateTextBox(t),"block"===o.textArea.style.display&&o.notify("shape",{prop:"redrawActObj",onPropertyChange:!1,value:{x:null,y:null,isMouseDown:null}})},t.prototype.updateText=function(t,i){var o=this.parent;if(this.tempActObj&&(o.activeObj=e.extend({},this.tempActObj,{},!0)),0===t.length&&1===o.objColl.length)this.tempActObj=e.extend({},o.objColl[0],{},!0);else for(var r=0;r<o.objColl.length;r++){if(o.objColl[r]&&e.isNullOrUndefined(t[r])){this.tempActObj=e.extend({},o.objColl[r],{},!0);break}if(t[r].currIndex!==o.objColl[r].currIndex){this.tempActObj=e.extend({},o.objColl[r],{},!0);break}}i&&(o.activeObj=e.extend({},this.tempActObj,{},!0)),o.objColl=e.extend([],t,[],!0),o.notify("shape",{prop:"zoomObjColl",onPropertyChange:!1,value:{isPreventApply:!0}}),this.upperContext.clearRect(0,0,o.upperCanvas.width,o.upperCanvas.height),this.lowerContext.clearRect(0,0,o.lowerCanvas.width,o.lowerCanvas.height),o.isUndoRedo=!0,o.notify("draw",{prop:"redrawImgWithObj",onPropertyChange:!1}),o.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1})},t.prototype.updateTextBox=function(t){var i=this.parent;this.upperContext.clearRect(0,0,i.lowerCanvas.width,i.lowerCanvas.height),this.lowerContext.clearRect(0,0,i.lowerCanvas.width,i.lowerCanvas.height),i.notify("draw",{prop:"redrawImgWithObj",onPropertyChange:!1}),e.isBlazor()?i.updateToolbar(i.element,"destroyQuickAccessToolbar"):i.notify("toolbar",{prop:"destroy-qa-toolbar",onPropertyChange:!1}),i.textArea.style.display="block",i.textArea.style.fontFamily=t.textSettings.fontFamily,i.textArea.style.fontSize=t.textSettings.fontSize+"px",i.textArea.style.color=t.strokeSettings.strokeColor,i.textArea.style.fontWeight=t.textSettings.bold?"bold":"normal",i.textArea.style.fontStyle=t.textSettings.italic?"italic":"normal",i.textArea.style.border="2px solid "+i.themeColl[i.theme].primaryColor,i.textArea.value=t.keyHistory,i.activeObj=e.extend({},t,{},!0),i.notify("shape",{prop:"updateFontStyles",onPropertyChange:!1,value:{isTextBox:null}}),i.textArea.style.width=i.activeObj.activePoint.width+"px"},t.prototype.undoDefault=function(t){this.lowerContext.filter=t.previousObj.filter;var i=this.parent;i.objColl=[],i.pointColl=[],i.freehandCounter=0,i.notify("freehand-draw",{prop:"setSelPointColl",onPropertyChange:!1,value:{obj:{selPointColl:[]}}}),i.notify("draw",{prop:"setCurrentObj",onPropertyChange:!1,value:{obj:t.previousObj}}),this.upperContext.clearRect(0,0,i.upperCanvas.width,i.upperCanvas.height),i.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),i.img.destLeft=t.previousObj.destPoints.startX,i.img.destTop=t.previousObj.destPoints.startY;var o=e.extend({},i.activeObj,{},!0);i.objColl=e.extend([],t.previousObjColl,[],!0),i.pointColl=e.extend([],t.previousPointColl,[],!0),i.freehandCounter=i.pointColl.length,i.notify("freehand-draw",{prop:"setSelPointColl",onPropertyChange:!1,value:{obj:{selPointColl:e.extend([],t.previousSelPointColl,[],!0)}}}),this.lowerContext.filter="none",i.notify("shape",{prop:"zoomObjColl",onPropertyChange:!1,value:{isPreventApply:null}}),i.notify("freehand-draw",{prop:"zoomFHDColl",onPropertyChange:!1,value:{isPreventApply:null}}),this.lowerContext.filter=t.previousObj.filter,i.activeObj=o,this.upperContext.clearRect(0,0,i.upperCanvas.width,i.upperCanvas.height),0!==i.activeObj.activePoint.width&&0!==i.activeObj.activePoint.height&&i.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate"}})},t.prototype.endUndoRedo=function(t,i){var o=this.parent;o.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.lowerContext}}),o.isCircleCrop&&(i&&"crop"!==t||!i)&&o.notify("crop",{prop:"cropCircle",onPropertyChange:!1,value:{context:this.lowerContext,isSave:null,isFlip:null}}),o.transform.zoomFactor>0&&o.notify("selection",{prop:"setDragCanvas",value:{bool:!0}}),o.notify("draw",{prop:"setCancelAction",onPropertyChange:!1,value:{bool:!1}}),e.isBlazor()?(e.isNullOrUndefined(o.activeObj.shape)||"crop"!==o.activeObj.shape.split("-")[0])&&(o.updateToolbar(o.element,"imageLoaded"),o.updateToolbar(o.element,"enableDisableToolbarBtn")):(o.activeObj.shape&&"crop"===o.activeObj.shape.split("-")[0]?o.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"main",isApplyBtn:!0,isCropping:!0,isZooming:null,cType:null}}):o.notify("toolbar",{prop:"refresh-main-toolbar",onPropertyChange:!1}),o.notify("toolbar",{prop:"enable-disable-btns"})),document.getElementById(o.element.id+"_quickAccessToolbarArea")&&(document.getElementById(o.element.id+"_quickAccessToolbarArea").style.display="none"),e.isBlazor()?o.updateToolbar(o.element,"enableDisableToolbarBtn"):o.notify("toolbar",{prop:"enable-disable-btns"}),0!==o.transform.degree&&o.notify("transform",{prop:"drawPannedImage",onPropertyChange:!1,value:{xDiff:0,yDiff:0}}),o.notify("filter",{prop:"setAdjustmentValue",onPropertyChange:!1,value:{adjustmentValue:this.lowerContext.filter}}),o.currObjType.isCustomCrop=!1},t.prototype.updateUrc=function(t,i,o,r,n,a,s,l,p,h){var c=this.parent,d={isInitialLoaded:!1};if(c.currObjType.isUndoAction&&this.refreshUrc(!0),c.notify("draw",{prop:"isInitialLoaded",onPropertyChange:!1,value:{object:d}}),!d.isInitialLoaded&&c.allowUndoRedo){var v={currObj:{}};c.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:v}});var u=v.currObj;u.objColl=e.extend([],c.objColl,[],!0),u.pointColl=e.extend([],c.pointColl,[],!0),u.afterCropActions=e.extend([],c.afterCropActions,[],!0);var g={selPointColl:null};c.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:g}}),u.selPointColl=e.extend([],g.selPointColl,[],!0),"crop"===t&&(u.currSelectionPoint=e.extend({},c.currSelectionPoint,{},!0)),this.undoRedoColl.push({operation:t,previousObj:i,currentObj:u,previousObjColl:o,currentObjColl:u.objColl,previousPointColl:r,currentPointColl:u.pointColl,previousSelPointColl:n,currentSelPointColl:u.selPointColl,previousCropObj:a,currentCropObj:e.extend({},c.cropObj,{},!0),previousText:s,currentText:l,filter:p,isCircleCrop:h}),e.isBlazor()?c.updateToolbar(c.element,"enableDisableToolbarBtn"):c.notify("toolbar",{prop:"enable-disable-btns",onPropertyChange:!1})}},t.prototype.updateUrObj=function(t){var i=this.parent;if(i.allowUndoRedo){i.currObjType.isUndoAction&&this.refreshUrc(!0),i.objColl.push(i.activeObj);var o=e.extend({},i.cropObj,{},!0),r={currObj:{}};i.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:r}});var n=r.currObj;n.objColl=e.extend([],i.objColl,[],!0),n.pointColl=e.extend([],i.pointColl,[],!0),n.afterCropActions=e.extend([],i.afterCropActions,[],!0);var a={selPointColl:null};i.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:a}}),n.selPointColl=e.extend([],a.selPointColl,[],!0),this.undoRedoColl.push({operation:"shapeTransform",previousObj:n,currentObj:n,previousObjColl:t,currentObjColl:n.objColl,previousPointColl:n.pointColl,currentPointColl:n.pointColl,previousSelPointColl:n.selPointColl,currentSelPointColl:n.selPointColl,previousCropObj:o,currentCropObj:o}),i.notify("selection",{prop:"redrawShape",onPropertyChange:!1,value:{obj:i.objColl[i.objColl.length-1]}})}},t.prototype.updateUndoRedo=function(){var t=this.parent,i=e.extend({},t.cropObj,{},!0),o={currObj:{}};t.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:o}});var r=o.currObj;r.objColl=e.extend([],t.objColl,[],!0),r.pointColl=e.extend([],t.pointColl,[],!0),r.afterCropActions=e.extend([],t.afterCropActions,[],!0);var n={selPointColl:null};t.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:n}}),r.selPointColl=e.extend([],n.selPointColl,[],!0),t.objColl.push(t.activeObj),this.updateUrc("shapeTransform",r,r.objColl,r.pointColl,r.selPointColl,i),t.objColl.pop(),t.notify("shape",{prop:"applyActObj",onPropertyChange:!1,value:{isMouseDown:null}}),t.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),e.isBlazor()?t.updateToolbar(t.element,"imageLoaded"):(t.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"shapes",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}}),t.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"main",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}}))},t.prototype.getZeroZoomObjPointValue=function(t,i){var o=this.parent,r={currObj:{}};o.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:r}});var n=r.currObj;n.objColl=e.extend([],o.objColl,[],!0),n.pointColl=e.extend([],o.pointColl,[],!0),n.afterCropActions=e.extend([],o.afterCropActions,[],!0);var a={selPointColl:null};o.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:a}}),n.selPointColl=e.extend([],a.selPointColl,[],!0);var s={cropDimension:null};o.notify("transform",{prop:"getCropDimension",onPropertyChange:!1,value:{obj:s}});var l=e.extend([],o.objColl,[],!0),p=e.extend([],o.pointColl,[],!0),h={arrowDimension:null};this.parent.notify("draw",{prop:"getArrowDimension",onPropertyChange:!1,value:{obj:h}});var c=e.extend({},h.arrowDimension,{},!0);if(o.transform.zoomFactor>0&&(t.length>0||i.length>0)){o.objColl=t,o.pointColl=i;var d=o.isUndoRedo;if(0!==o.transform.zoomFactor){o.isUndoRedo=o.isCropTab=!0,o.notify("freehand-draw",{prop:"updateFHDColl",onPropertyChange:!1});var v=e.extend({},o.zoomSettings,null,!0);o.transform.zoomFactor>0?o.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:-o.transform.zoomFactor,zoomPoint:null}}):o.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:Math.abs(o.transform.zoomFactor),zoomPoint:null}}),o.zoomSettings=v,o.isCropTab=!1,o.isUndoRedo=d,l=e.extend([],o.objColl,[],!0),p=e.extend([],o.pointColl,[],!0),o.objColl=[],o.pointColl=[],o.freehandCounter=0,o.notify("freehand-draw",{prop:"setSelPointColl",onPropertyChange:!1,value:{obj:{selPointColl:[]}}}),o.notify("transform",{prop:"setCropDimension",onPropertyChange:!1,value:{width:s.cropDimension.width,height:s.cropDimension.height}});var u={width:s.cropDimension.width,height:s.cropDimension.height};u.width+=u.width*n.defaultZoom,u.height+=u.height*n.defaultZoom,o.notify("draw",{prop:"setZoomCropWidth",value:{width:u.width,height:u.height}}),o.notify("draw",{prop:"setCurrentObj",onPropertyChange:!1,value:{obj:n}}),o.img.destLeft=n.destPoints.startX,o.img.destTop=n.destPoints.startY,o.panPoint.totalPannedPoint=n.totalPannedPoint,o.panPoint.totalPannedClientPoint=n.totalPannedClientPoint,o.panPoint.totalPannedInternalPoint=n.totalPannedInternalPoint,o.objColl=e.extend([],n.objColl,[],!0),o.pointColl=e.extend([],n.pointColl,[],!0),o.freehandCounter=o.pointColl.length,o.notify("draw",{prop:"setArrowDimension",onPropertyChange:!1,value:{arrowDimension:c}}),o.notify("freehand-draw",{prop:"setSelPointColl",onPropertyChange:!1,value:{obj:{selPointColl:e.extend([],n.selPointColl,[],!0)}}}),this.lowerContext.filter="none",o.notify("shape",{prop:"iterateObjColl",onPropertyChange:!1}),o.notify("freehand-draw",{prop:"freehandRedraw",onPropertyChange:!1,value:{context:this.lowerContext,points:null}}),o.notify("freehand-draw",{prop:"updateFHDCurPts",onPropertyChange:!1}),this.lowerContext.filter=n.filter,0!==o.transform.degree&&o.notify("transform",{prop:"drawPannedImage",onPropertyChange:!1,value:{xDiff:0,yDiff:0}})}}return{obj:l,point:p}},t}(),g=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 o(){this.constructor=e}t(e,i),e.prototype=null===i?Object.create(i):(o.prototype=i.prototype,new o)}}(),b=function(t,e,i,o){var r,n=arguments.length,a=n<3?e:null===o?o=Object.getOwnPropertyDescriptor(e,i):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(t,e,i,o);else for(var s=t.length-1;s>=0;s--)(r=t[s])&&(a=(n<3?r(a):n>3?r(e,i,a):r(e,i))||a);return n>3&&a&&Object.defineProperty(e,i,a),a},C=function(t){function i(){return null!==t&&t.apply(this,arguments)||this}return g(i,t),b([e.Property(null)],i.prototype,"brightness",void 0),b([e.Property(null)],i.prototype,"contrast",void 0),b([e.Property(null)],i.prototype,"hue",void 0),b([e.Property(null)],i.prototype,"saturation",void 0),b([e.Property(null)],i.prototype,"exposure",void 0),b([e.Property(null)],i.prototype,"opacity",void 0),b([e.Property(null)],i.prototype,"blur",void 0),i}(e.ChildProperty),f=function(t){function i(){return null!==t&&t.apply(this,arguments)||this}return g(i,t),b([e.Property(null)],i.prototype,"zoomTrigger",void 0),b([e.Property(1)],i.prototype,"minZoomFactor",void 0),b([e.Property(10)],i.prototype,"maxZoomFactor",void 0),b([e.Property(1)],i.prototype,"zoomFactor",void 0),b([e.Property(null)],i.prototype,"zoomPoint",void 0),i}(e.ChildProperty),m=function(t){function i(){return null!==t&&t.apply(this,arguments)||this}return g(i,t),b([e.Property(!0)],i.prototype,"showCircle",void 0),b([e.Property(null)],i.prototype,"strokeColor",void 0),b([e.Property(null)],i.prototype,"fillColor",void 0),i}(e.ChildProperty),y=function(o){function r(t,i){var r=o.call(this,t)||this;return r.isImageLoaded=!1,r.activeObj={activePoint:{startX:0,startY:0,endX:0,endY:0,width:0,height:0},flipObjColl:[],triangle:[],triangleRatio:[],rotatedAngle:0},r.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,isResize:!1},r.objColl=[],r.pointColl={},r.freehandCounter=0,r.points=[],r.togglePen=!1,r.togglePan=!1,r.img={destLeft:0,destTop:0,destWidth:0,destHeight:0,srcLeft:0,srcTop:0,srcWidth:0,srcHeight:0},r.rotateFlipColl=[],r.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:"",zoomFactor:0,previousZoomValue:0},r.afterCropActions=[],r.transform={degree:0,currFlipState:"",zoomFactor:0,cropZoomFactor:null,defaultZoomFactor:0},r.panPoint={currentPannedPoint:{x:0,y:0},totalPannedPoint:{x:0,y:0},totalPannedInternalPoint:{x:0,y:0},totalPannedClientPoint:{x:0,y:0}},r.isUndoRedo=!1,r.isCropTab=!1,r.isCircleCrop=!1,r.fontSizeColl=[],r.initialAdjustmentValue="",r.currentFilter="",r.canvasFilter="brightness(1) contrast(100%) hue-rotate(0deg) saturate(100%) opacity(1) blur(0px) sepia(0%) grayscale(0%) invert(0%)",r.toolbarHeight=0,r.isPublicMethod=!1,r.isCropToolbar=!1,r.cursor="default",e.isBlazor()?(new a(r),new s(r),new p(r),new h(r),new c(r),new d(r),new v(r),new u(r),new l(r)):(n.Inject(a,s,c,v,l,P),n.Inject(u),n.Inject(p),n.Inject(d),n.Inject(h),i&&r.appendTo(i)),r}g(r,o),n=r,r.prototype.requiredModules=function(){var t=[];return t.push({member:"crop",args:[this]}),t.push({member:"draw",args:[this]}),t.push({member:"selection",args:[this]}),t.push({member:"transform",args:[this]}),t.push({member:"export",args:[this]}),t.push({member:"toolbar-module",args:[this]}),t.push({member:"undo-redo",args:[this]}),t.push({member:"filter",args:[this]}),t.push({member:"shape",args:[this]}),t.push({member:"freehand-draw",args:[this]}),t},r.prototype.preRender=function(){this.element.id=this.element.id||e.getUniqueID("ej2-image-editor"),e.Browser.isDevice&&this.element.classList.add("e-device"),this.initializeThemeColl()},r.prototype.render=function(){this.initialize()},r.prototype.getModuleName=function(){return"image-editor"},r.prototype.getPersistData=function(){return this.addOnPersist([])},r.prototype.onPropertyChanged=function(i,o){for(var r=0,n=Object.keys(i);r<n.length;r++){switch(n[r]){case"cssClass":o.cssClass&&e.removeClass([this.element],o.cssClass.replace(/\s+/g," ").trim().split(" ")),i.cssClass&&e.addClass([this.element],i.cssClass.replace(/\s+/g," ").trim().split(" "));break;case"disabled":i.disabled?(this.element.classList.add("e-disabled"),this.unwireEvent()):(this.element.classList.remove("e-disabled"),this.wireEvent());break;case"height":this.element.style.height=i.height;break;case"width":this.element.style.width=i.width;break;case"theme":i.theme&&(e.isNullOrUndefined(this.theme)||""===this.theme?this.theme="Bootstrap5":this.theme=this.toPascalCase(this.theme),this.upperContext.strokeStyle=this.themeColl[this.theme].primaryColor,this.upperContext.fillStyle=this.themeColl[this.theme].secondaryColor);break;case"finetuneSettings":i.finetuneSettings&&(this.finetuneSettings=i.finetuneSettings,this.notify("filter",{prop:"update-finetunes"}));break;case"locale":i.locale&&(this.notify("toolbar",{prop:"setLocale",onPropertyChange:!1,value:{locale:i.locale}}),this.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"main",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}}));break;case"allowUndoRedo":i.allowUndoRedo?this.allowUndoRedo=!0:this.allowUndoRedo=!1,this.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"main",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}});break;case"showQuickAccessToolbar":i.showQuickAccessToolbar?(this.showQuickAccessToolbar=!0,this.notify("toolbar",{prop:"create-qa-toolbar",onPropertyChange:!1}),this.notify("toolbar",{prop:"renderQAT",onPropertyChange:!1,value:{isPenEdit:null}})):(this.showQuickAccessToolbar=!1,this.notify("toolbar",{prop:"destroy-qa-toolbar",onPropertyChange:!1}));break;case"zoomSettings":i.zoomSettings&&(this.zoomSettings.zoomTrigger=i.zoomSettings.zoomTrigger),e.isNullOrUndefined(this.zoomSettings.zoomTrigger)?(this.zoomSettings.zoomTrigger=t.ZoomTrigger.MouseWheel|t.ZoomTrigger.Pinch|t.ZoomTrigger.Toolbar|t.ZoomTrigger.Commands,this.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"main",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}})):(i.zoomSettings.zoomTrigger&t.ZoomTrigger.Toolbar)===t.ZoomTrigger.Toolbar&&this.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"main",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}});break;case"selectionSettings":i.selectionSettings&&(this.selectionSettings=i.selectionSettings,e.isNullOrUndefined(this.activeObj.shape)||(this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),this.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate",obj:this.activeObj}})))}}},r.prototype.destroy=function(){var t=[];this.element.removeAttribute("tabindex"),this.cssClass&&(t=t.concat(this.cssClass.replace(/\s+/g," ").trim().split(" "))),e.removeClass([this.element],t),this.element.getAttribute("class")||this.element.removeAttribute("class"),e.isBlazor()?this.element.classList.remove("e-image-editor"):(this.notify("toolbar",{prop:"destroySubComponents",onPropertyChange:!1}),this.notify("destroyed",null),o.prototype.destroy.call(this)),this.unwireEvent(),this.element.innerHTML=""},r.prototype.initialize=function(){if(e.isNullOrUndefined(this.toolbarTemplate)?(this.notify("toolbar",{prop:"create-toolbar",onPropertyChange:!1}),this.notify("toolbar",{prop:"create-contextual-toolbar",onPropertyChange:!1})):(this.element.appendChild(this.createElement("div",{id:this.element.id+"_toolbarArea",className:"e-toolbar-area"})),this.toolbarTemplateFn()),this.createCanvas(),this.showQuickAccessToolbar){document.querySelector("#"+this.element.id+"_canvasWrapper").appendChild(this.createElement("div",{id:this.element.id+"_quickAccessToolbarArea",className:"e-quick-access-toolbar-area"}));var t=document.getElementById(this.element.id+"_quickAccessToolbarArea");t.style.position="absolute",t.style.display="none",e.isNullOrUndefined(this.activeObj)||(t.style.left=this.activeObj.activePoint.startX+"px",t.style.top=this.activeObj.activePoint.startY+"px"),t.style.width="100%"}e.isNullOrUndefined(this.quickAccessToolbarTemplate)?this.notify("toolbar",{prop:"create-qa-toolbar",onPropertyChange:!1}):this.quickAccessToolbarTemplateFn(),this.wireEvent(),this.lowerContext=this.lowerCanvas.getContext("2d"),this.upperContext=this.upperCanvas.getContext("2d"),this.inMemoryContext=this.inMemoryCanvas.getContext("2d"),this.lowerContext.filter=this.getDefaultFilter(),this.notify("filter",{prop:"setAdjustmentValue",onPropertyChange:!1,value:{adjustmentValue:this.lowerContext.filter}}),this.notify("toolbar",{prop:"setCanvasFilter",onPropertyChange:!1,value:{filter:this.lowerContext.filter}}),this.notify("toolbar",{prop:"setInitialAdjustmentValue",onPropertyChange:!1,value:{value:this.lowerContext.filter}}),this.cssClass&&e.addClass([this.element],this.cssClass.replace(/\s+/g," ").trim().split(" ")),this.element&&i.createSpinner({target:this.element}),this.initializeZoomSettings()},r.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.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)),this.notify("shape",{prop:"wireEvent",onPropertyChange:!1})},r.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),e.EventHandler.remove(this.upperCanvas,"touchstart",this.touchStartHandler),e.EventHandler.remove(this.lowerCanvas,"touchstart",this.touchStartHandler),e.EventHandler.remove(this.lowerCanvas,"mousewheel DOMMouseScroll",this.handleScroll),e.EventHandler.remove(this.upperCanvas,"mousewheel DOMMouseScroll",this.handleScroll),window.removeEventListener("resize",this.windowResizeHandler.bind(this)),e.Browser.isIos||"safari"===e.Browser.info.name||screen.orientation.removeEventListener("change",this.screenOrientation.bind(this)),this.notify("shape",{prop:"unWireEvent",onPropertyChange:!1})},r.prototype.createCanvas=function(){this.element.style.boxSizing="border-box";var t={toolbarHeight:0};this.notify("toolbar",{prop:"getToolbarHeight",value:{obj:t}});var e=t.toolbarHeight;this.element.style.width=this.width,this.element.style.height=this.height;var i=this.element.appendChild(this.createElement("div",{id:this.element.id+"_canvasWrapper",className:"e-canvas-wrapper",attrs:{style:"height:"+(this.element.offsetHeight-e-2)+"px; width:"+(this.element.offsetWidth-2)+"px; position: relative; overflow: hidden; margin: 0 auto;"}}));this.lowerCanvas=i.appendChild(this.createElement("canvas",{id:this.element.id+"_lowerCanvas",attrs:{name:"canvasImage"}})),this.upperCanvas=i.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=i.appendChild(this.createElement("textarea",{id:this.element.id+"_textArea",className:"e-textarea",attrs:{name:"textArea"}}));this.element.appendChild(this.createElement("div",{id:this.element.id+"_dialog",className:"e-dialog"})).style.display="none",this.textArea.setAttribute("spellcheck","false"),this.textArea.style.lineHeight="normal",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=this.cursor="default",this.upperCanvas.style.display="block",this.upperContext=this.upperCanvas.getContext("2d")},r.prototype.touchStartHandler=function(t){this.notify("selection",{prop:"touchStartHandler",onPropertyChange:!1,value:{e:t}})},r.prototype.mouseDownEventHandler=function(t){this.notify("selection",{prop:"mouseDownEventHandler",onPropertyChange:!1,value:{e:t}})},r.prototype.mouseMoveEventHandler=function(t){this.notify("selection",{prop:"mouseMoveEventHandler",onPropertyChange:!1,value:{e:t}})},r.prototype.mouseUpEventHandler=function(t){this.notify("selection",{prop:"mouseUpEventHandler",onPropertyChange:!1,value:{e:t}})},r.prototype.keyDownEventHandler=function(t){this.notify("selection",{prop:"keyDownEventHandler",onPropertyChange:!1,value:{e:t}})},r.prototype.keyUpEventHandler=function(t){"block"===this.textArea.style.display&&t.target.id===this.element.id+"_textArea"&&this.notify("selection",{prop:"textKeyDown",value:{e:t}})},r.prototype.canvasMouseDownHandler=function(t){this.notify("selection",{prop:"canvasMouseDownHandler",onPropertyChange:!1,value:{e:t}})},r.prototype.canvasMouseMoveHandler=function(t){this.notify("selection",{prop:"canvasMouseMoveHandler",onPropertyChange:!1,value:{e:t}})},r.prototype.canvasMouseUpHandler=function(t){this.notify("selection",{prop:"canvasMouseUpHandler",onPropertyChange:!1,value:{e:t}})},r.prototype.handleScroll=function(t){this.notify("selection",{prop:"handleScroll",onPropertyChange:!1,value:{e:t}})},r.prototype.adjustToScreen=function(){this.notify("selection",{prop:"adjustToScreen",onPropertyChange:!1})},r.prototype.screenOrientation=function(){e.Browser.isDevice&&setTimeout(this.adjustToScreen.bind(this),100)},r.prototype.windowResizeHandler=function(){!e.Browser.isDevice&&this.element.classList.contains("e-image-editor")&&this.adjustToScreen()},r.prototype.notifyResetForAllModules=function(){for(var t=this.requiredModules(),e=0;e<t.length;e++)this.notify(t[e].member,{prop:"reset",onPropertyChange:!1})},r.prototype.allowShape=function(t,e){this.isPublicMethod=!0;var i={inRange:!1};return this.notify("shape",{prop:"isPointsInRange",onPropertyChange:!1,value:{x:t,y:e,obj:i}}),i.inRange},r.prototype.clearSelection=function(){this.notify("selection",{prop:"clearSelection",onPropertyChange:!1})},r.prototype.crop=function(){var t={isCrop:!1};return this.notify("crop",{prop:"crop",onPropertyChange:!1,value:{obj:t}}),t.isCrop},r.prototype.flip=function(t){this.notify("transform",{prop:"flip",value:{direction:t}}),this.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"ok"}})},r.prototype.getImageData=function(){var t={canvas:null};return this.notify("export",{prop:"exportToCanvas",value:{object:t}}),t.canvas.getContext("2d").getImageData(0,0,t.canvas.width,t.canvas.height)},r.prototype.open=function(t){this.notify("draw",{prop:"open",value:{data:t}})},r.prototype.reset=function(){var t={isErrorImage:!1};if(this.notify("draw",{prop:"getErrorImage",value:{obj:t}}),!this.disabled&&!t.isErrorImage){this.clearContext(this.inMemoryContext),this.clearContext(this.lowerContext),this.clearContext(this.upperContext),this.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),e.isBlazor()||(this.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"main",isApplyBtn:!1,isCropping:!1,isZooming:null,cType:null}}),e.Browser.isDevice&&document.getElementById(this.element.id+"_bottomToolbar")&&(e.getComponent(document.getElementById(this.element.id+"_bottomToolbar"),"toolbar").destroy(),this.notify("toolbar",{prop:"create-bottom-toolbar",onPropertyChange:!1}))),this.currObjType.isUndoAction=this.isUndoRedo=this.togglePan=this.togglePen=this.isImageLoaded=!1,this.isCircleCrop=this.isCropTab=!1,this.objColl=[],this.transform.degree=0,this.upperCanvas.style.display="block",this.transform.currFlipState="",this.upperCanvas.style.cursor=this.cursor=this.lowerCanvas.style.cursor="default",this.lowerContext.lineWidth=this.upperContext.lineWidth=void 0,this.textArea.value=this.textArea.textContent="",this.textArea.style.display="none",this.lowerContext.filter=this.canvasFilter=this.getDefaultFilter(),this.img.destLeft=this.img.destTop=this.img.srcLeft=this.img.srcTop=0,this.img.destWidth=this.img.destHeight=this.img.srcWidth=this.img.srcHeight=null,this.currSelectionPoint=null,this.panPoint.currentPannedPoint={x:0,y:0},this.rotateFlipColl=[],this.points=[],this.pointColl={},this.freehandCounter=0,this.notify("draw",{prop:"resetPanPoints"}),this.lowerCanvas.style.left=this.upperCanvas.style.left="",this.fontSizeColl=[],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.transform.defaultZoomFactor=this.transform.zoomFactor=0,this.transform.cropZoomFactor=null,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,isResize:!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:"",zoomFactor:0,previousZoomValue:0,destPoints:{startX:0,startY:0,width:0,height:0},srcPoints:{startX:0,startY:0,width:0,height:0},filter:""},this.afterCropActions=[],this.currentFilter="";var i={initialZoomValue:!1};this.notify("draw",{prop:"getInitialZoomValue",onPropertyChange:!1,value:{obj:i}}),e.isNullOrUndefined(i.initialZoomValue)||this.setProperties({zoomSettings:{zoomFactor:i.initialZoomValue}},!0),e.isNullOrUndefined(document.getElementById(this.element.id+"_quickAccessToolbarArea"))||(document.getElementById(this.element.id+"_quickAccessToolbarArea").style.display="none"),this.notifyResetForAllModules(),this.notify("filter",{prop:"update-finetunes"}),this.isImageLoaded=!1,this.notify("draw",{prop:"update-canvas",onPropertyChange:!1}),this.isImageLoaded=!0,e.isBlazor()||(e.isNullOrUndefined(this.element.querySelector(".e-contextual-toolbar-wrapper"))||this.element.querySelector(".e-contextual-toolbar-wrapper").classList.add("e-hide"),this.notify("toolbar",{prop:"refresh-dropdown-btn",value:{isDisabled:!1}}),this.notify("toolbar",{prop:"enable-disable-btns"}))}},r.prototype.rotate=function(t){var e={isRotate:!1};return this.notify("transform",{prop:"rotate",value:{degree:t,obj:e}}),this.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"ok"}}),e.isRotate},r.prototype.export=function(t,e){this.notify("export",{prop:"export",onPropertyChange:!1,value:{type:t,fileName:e}})},r.prototype.select=function(t,e,i,o,r){this.notify("draw",{prop:"select",onPropertyChange:!1,value:{type:t,startX:e,startY:i,width:o,height:r}})},r.prototype.freeHandDraw=function(t){this.notify("freehand-draw",{prop:"freeHandDraw",onPropertyChange:!1,value:{value:t}})},r.prototype.freehandDraw=function(t){!this.disabled&&this.isImageLoaded&&this.freeHandDraw(t)},r.prototype.pan=function(t){this.notify("transform",{prop:"pan",onPropertyChange:!1,value:{value:t}})},r.prototype.zoom=function(t,e){this.notify("transform",{prop:"zoom",onPropertyChange:!1,value:{zoomFactor:t,zoomPoint:e}})},r.prototype.drawEllipse=function(t,e,i,o,r,n,a){var s=!1,l=this.allowShape(t,e);return!this.disabled&&this.isImageLoaded&&l&&(s=!0,this.notify("shape",{prop:"drawEllipse",onPropertyChange:!1,value:{x:t,y:e,radiusX:i,radiusY:o,strokeWidth:r,strokeColor:n,fillColor:a}})),s},r.prototype.drawLine=function(t,e,i,o,r,n){var a=!1,s=this.allowShape(t,e);return!this.disabled&&this.isImageLoaded&&s&&(a=!0,this.notify("shape",{prop:"drawLine",onPropertyChange:!1,value:{startX:t,startY:e,endX:i,endY:o,strokeWidth:r,strokeColor:n}})),a},r.prototype.drawArrow=function(t,e,i,o,r,n,a,s){var l=!1,p=this.allowShape(t,e);return!this.disabled&&this.isImageLoaded&&p&&(l=!0,this.notify("shape",{prop:"drawArrow",onPropertyChange:!1,value:{startX:t,startY:e,endX:i,endY:o,strokeWidth:r,strokeColor:n,arrowStart:a,arrowEnd:s}})),l},r.prototype.drawPath=function(t,e,i){this.isPublicMethod=!0;var o={inRange:!1},r=!1;if(t.length>0)for(var n=0;n<t.length&&!o.inRange;n++)this.notify("shape",{prop:"isPointsInRange",onPropertyChange:!1,value:{x:t[n].x,y:t[n].y,obj:o}});return!this.disabled&&this.isImageLoaded&&o.inRange&&(r=!0,this.notify("shape",{prop:"drawPath",onPropertyChange:!1,value:{pointColl:t,strokeWidth:e,strokeColor:i}})),r},r.prototype.drawRectangle=function(t,e,i,o,r,n,a){var s=!1,l=this.allowShape(t,e);return!this.disabled&&this.isImageLoaded&&l&&(s=!0,this.notify("shape",{prop:"drawRectangle",onPropertyChange:!1,value:{x:t,y:e,width:i,height:o,strokeWidth:r,strokeColor:n,fillColor:a}})),s},r.prototype.drawText=function(t,e,i,o,r,n,a,s){var l=!1,p=this.allowShape(t,e);return!this.disabled&&this.isImageLoaded&&p&&(l=!0,this.notify("shape",{prop:"drawText",onPropertyChange:!1,value:{x:t,y:e,text:i,fontFamily:o,fontSize:r,bold:n,italic:a,color:s}})),l},r.prototype.selectShape=function(t){var e={isSelected:!1};return this.notify("shape",{prop:"selectShape",onPropertyChange:!1,value:{id:t,obj:e}}),e.isSelected},r.prototype.deleteShape=function(t){this.notify("shape",{prop:"deleteShape",onPropertyChange:!1,value:{id:t}})},r.prototype.getShapeSetting=function(t){var e={};return this.notify("shape",{prop:"getShapeSetting",onPropertyChange:!1,value:{id:t,obj:e}}),e},r.prototype.getShapeSettings=function(){var t={shapeDetailsColl:[]};return this.notify("shape",{prop:"getShapeSettings",onPropertyChange:!1,value:{obj:t}}),t.shapeDetailsColl},r.prototype.update=function(){this.notify("transform",{prop:"update"})},r.prototype.finetuneImage=function(t,e){!this.disabled&&this.isImageLoaded&&this.notify("filter",{prop:"finetuneImage",value:{value:e,option:t}})},r.prototype.applyImageFilter=function(t){!this.disabled&&this.isImageLoaded&&(this.notify("filter",{prop:"applyImageFilter",value:{option:t.toString()}}),this.canvasFilter=this.lowerContext.filter,this.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"ok"}}))},r.prototype.undo=function(){this.notify("undo-redo",{prop:"undo",onPropertyChange:!1})},r.prototype.redo=function(){this.notify("undo-redo",{prop:"redo",onPropertyChange:!1})},r.prototype.getImageDimension=function(){return{x:this.img.destLeft,y:this.img.destTop,width:this.img.destWidth,height:this.img.destHeight}},r.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 o=this.toolbarFn({type:"toolbar"},this,"Template",e);t=3===o[0].nodeType?o[1]:o[0]}else t=this.toolbarFn({type:"toolbar"},this,"Template",e)[0];i.appendChild(t),this.renderReactTemplates()}},r.prototype.quickAccessToolbarTemplateFn=function(){var t,e=this.element.id+"_quickAccessToolbar",i=this.element.querySelector("#"+this.element.id+"_quickAccessToolbarArea");if(this.quickAccessToolbarTemplate){if(this.qatFn=this.templateParser(this.quickAccessToolbarTemplate),this.isReact)t=this.qatFn({type:"toolbar"},this,"Template",e)[0];else if(this.isAngular){var o=this.qatFn({type:"toolbar"},this,"Template",e);t=3===o[0].nodeType?o[1]:o[0]}else t=this.qatFn({type:"toolbar"},this,"Template",e)[0];i.appendChild(t),this.renderReactTemplates()}},r.prototype.templateParser=function(t){if(t)try{return"function"!=typeof t&&document.querySelectorAll(t).length?e.compile(document.querySelector(t).innerHTML.trim()):e.compile(t)}catch(i){return e.compile(t)}},r.prototype.getTextFromId=function(t){return{1:"none",2:"bar",3:"arrow",4:"arrowSolid",5:"circle",6:"circleSolid",7:"square",8:"squareSolid"}[""+t]},r.prototype.getFinetuneOption=function(e){return{brightness:t.ImageFinetuneOption.Brightness,contrast:t.ImageFinetuneOption.Contrast,hue:t.ImageFinetuneOption.Hue,saturation:t.ImageFinetuneOption.Saturation,opacity:t.ImageFinetuneOption.Opacity,blur:t.ImageFinetuneOption.Blur,exposure:t.ImageFinetuneOption.Exposure}[""+e]},r.prototype.setPenStroke=function(t){this.notify("freehand-draw",{prop:"setPenStrokeWidth",onPropertyChange:!1,value:{value:parseInt(t,10)}})},r.prototype.updateFreehandDrawColorChange=function(){var t={tempFreeHandDrawEditingStyles:null};this.notify("freehand-draw",{prop:"getTempFreeHandDrawEditingStyles",value:{obj:t}}),this.notify("freehand-draw",{prop:"color-change",value:{color:t.tempFreeHandDrawEditingStyles.strokeColor}})},r.prototype.setInitialZoomState=function(){this.objColl.push(this.activeObj),this.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1});var t=this.isUndoRedo;this.isCropTab=!1,this.isUndoRedo=!0,!e.isNullOrUndefined(this.transform.cropZoomFactor)&&this.transform.cropZoomFactor>0?this.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:-this.transform.cropZoomFactor,zoomPoint:null}}):this.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:Math.abs(this.transform.cropZoomFactor),zoomPoint:null}}),this.isUndoRedo=t,this.panPoint.totalPannedPoint={x:0,y:0},this.transform.cropZoomFactor=0,this.notify("freehand-draw",{prop:"updateFHDColl",onPropertyChange:!1}),this.activeObj=e.extend({},this.objColl[this.objColl.length-1],{},!0),this.objColl.pop(),this.isCropTab=!0,this.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate",obj:this.activeObj}})},r.prototype.moveToSelectionRange=function(t,i){if(!e.isNullOrUndefined(this.activeObj.shape)&&("rotateleft"===t||"rotateright"===t)){var o=this.transform.zoomFactor;if(this.objColl.push(this.activeObj),this.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),this.transform.degree%90==0&&this.transform.degree%180!=0)if(this.objColl[this.objColl.length-1].activePoint.width<i.activePoint.height)for(var r=2;r<this.zoomSettings.maxZoomFactor;r++){if(this.objColl[this.objColl.length-1].activePoint.width>=i.activePoint.height||this.isSelectionBiggerThanCanvas(this.objColl[this.objColl.length-1])||this.isSelectionOutsideCanvas(this.objColl[this.objColl.length-1])){e.isNullOrUndefined(o)||this.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:-.1,zoomPoint:null}});break}o+=.1,this.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:o,zoomPoint:null}})}else for(r=2;r<this.zoomSettings.maxZoomFactor;r++){if(this.objColl[this.objColl.length-1].activePoint.width>=i.activePoint.height||this.isSelectionBiggerThanCanvas(this.objColl[this.objColl.length-1])||this.isSelectionOutsideCanvas(this.objColl[this.objColl.length-1])){e.isNullOrUndefined(o)||this.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:.1,zoomPoint:null}});break}o-=.1,this.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:o,zoomPoint:null}})}else if(this.objColl[this.objColl.length-1].activePoint.height<i.activePoint.width)for(r=2;r<this.zoomSettings.maxZoomFactor;r++){if(this.objColl[this.objColl.length-1].activePoint.height>=i.activePoint.width||this.isSelectionBiggerThanCanvas(this.objColl[this.objColl.length-1])||this.isSelectionOutsideCanvas(this.objColl[this.objColl.length-1])){e.isNullOrUndefined(o)||this.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:-.1,zoomPoint:null}});break}o+=.1,this.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:o,zoomPoint:null}})}else for(r=2;r<this.zoomSettings.maxZoomFactor;r++){if(this.objColl[this.objColl.length-1].activePoint.height>=i.activePoint.width||this.isSelectionBiggerThanCanvas(this.objColl[this.objColl.length-1])||this.isSelectionOutsideCanvas(this.objColl[this.objColl.length-1])){e.isNullOrUndefined(o)||this.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:.1,zoomPoint:null}});break}o-=.1,this.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:o,zoomPoint:null}})}var n=this.lowerCanvas.clientWidth/2-(this.objColl[this.objColl.length-1].activePoint.startX+this.objColl[this.objColl.length-1].activePoint.width/2),a=this.lowerCanvas.clientHeight/2-(this.objColl[this.objColl.length-1].activePoint.startY+this.objColl[this.objColl.length-1].activePoint.height/2);0===this.transform.degree?(this.img.destLeft+=n,this.img.destTop+=a,this.notify("transform",{prop:"drawPannImage",value:{point:{x:n,y:a}}})):(this.panPoint.currentPannedPoint={x:n,y:a},this.notify("transform",{prop:"drawPannedImage",value:{xDiff:n,yDiff:a}}),this.panPoint.currentPannedPoint={x:0,y:0}),this.notify("transform",{prop:"setTempPanMove",onPropertyChange:!1,value:{point:null}}),this.activeObj=e.extend({},this.objColl[this.objColl.length-1]),this.objColl.pop(),this.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate",obj:this.activeObj}})}},r.prototype.isSelectionBiggerThanCanvas=function(t){var e=!1;return(t.activePoint.startX<=this.img.destLeft||t.activePoint.startY<=this.img.destTop||t.activePoint.endX>=this.img.destLeft+this.img.destWidth||t.activePoint.endY>=this.img.destTop+this.img.destHeight)&&(e=!0),e},r.prototype.isSelectionOutsideCanvas=function(t){var e=!1;return(t.activePoint.height<this.lowerCanvas.height-this.toolbarHeight||t.activePoint.width<this.lowerCanvas.width)&&(e=!0),e},r.prototype.updateCropTransformItems=function(){this.prevCurrSelectionPoint=e.extend({},this.currSelectionPoint,{},!0);var t={currObj:{}};this.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:t}});var i=t.currObj;i.objColl=e.extend([],this.objColl,[],!0),i.pointColl=e.extend([],this.pointColl,[],!0),i.afterCropActions=e.extend([],this.afterCropActions,[],!0);var o={selPointColl:null};this.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:o}}),i.selPointColl=e.extend([],o.selPointColl,[],!0),this.cancelCropSelection={operation:"cropTransform",previousObj:i,currentObj:i,previousObjColl:i.objColl,currentObjColl:i.objColl,previousPointColl:i.pointColl,currentPointColl:i.pointColl,previousSelPointColl:i.selPointColl,currentSelPointColl:i.selPointColl,previousCropObj:e.extend({},this.cropObj,{},!0),currentCropObj:e.extend({},this.cropObj,{},!0),previousText:null,currentText:null,filter:null,isCircleCrop:this.isCircleCrop}},r.prototype.toPascalCase=function(t,i){var o=[];e.isNullOrUndefined(t)||(o=t.toLowerCase().split("-"));for(var r=0;r<o.length;r++)o[r]=o[r].charAt(0).toUpperCase()+o[r].slice(1);return e.isNullOrUndefined(i)||(i.maxText=o.join("")),o.join("")},r.prototype.getFontSizes=function(){var t=[];this.fontSizeColl=[];var e;e=0===this.transform.degree||this.transform.degree%180==0?this.img.destWidth/25:this.img.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},r.prototype.okBtn=function(t){var i,o=!1;void 0!==this.activeObj.shape&&(i=this.activeObj.shape.split("-")),void 0===i&&this.currObjType.isCustomCrop?o=!0:void 0!==i&&"crop"===i[0]&&(o=!0);var r=this.element.querySelector(".e-contextual-toolbar-wrapper .e-toolbar-item.e-selected"),n={bool:!1};if(this.notify("selection",{prop:"getFreehandDrawEditing",onPropertyChange:!1,value:{obj:n}}),r&&(this.currentFilter=r.children[0].children[0].id.replace("Canvas","")),o)this.crop();else if(this.togglePen)this.freeHandDraw(!1),this.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"ok"}});else if("block"===this.textArea.style.display)this.notify("shape",{prop:"redrawActObj",onPropertyChange:!1,value:{x:null,y:null,isMouseDown:null}}),e.isNullOrUndefined(t)&&this.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"ok"}});else if(!e.isBlazor()&&!e.isNullOrUndefined(document.querySelector("#"+this.element.id+"_sliderWrapper"))||e.isBlazor()&&!this.element.querySelector(".e-ie-contextual-slider").classList.contains("e-hidden")||this.currObjType.isFiltered){this.initialAdjustmentValue=this.canvasFilter=this.lowerContext.filter,this.currObjType.isFiltered=!1;var a={value:null};this.notify("draw",{prop:"getTempAdjustmentValue",value:{obj:a}}),a.value!==this.lowerContext.filter&&this.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"ok"}})}else n.bool?(this.notify("freehand-draw",{prop:"applyFhd",onPropertyChange:!1}),this.notify("selection",{prop:"setFreehandDrawCustomized",value:{isFreehandDrawCustomized:!1}}),e.isBlazor()?this.updateToolbar(this.element,"destroyQuickAccessToolbar"):this.notify("toolbar",{prop:"destroy-qa-toolbar"}),this.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"ok"}})):(0!==this.activeObj.activePoint.width&&0!==this.activeObj.activePoint.height||"path"===this.activeObj.shape&&this.activeObj.pointColl.length>0)&&this.notify("shape",{prop:"applyActObj",onPropertyChange:!1,value:{isMouseDown:t}});e.isBlazor()||n.isCropToolbar||this.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"main",isApplyBtn:!1,isCropping:null,isZooming:null,cType:null}}),this.notify("draw",{prop:"setNewPath",value:{bool:!1}}),this.isCropTab=!1,this.transform.zoomFactor=this.transform.defaultZoomFactor,this.notify("selection",{prop:"setCurrentDrawingShape",onPropertyChange:!1,value:{value:""}})},r.prototype.setTempFilterProperties=function(){this.upperCanvas.style.display="block",this.cropSelectedState();var t={adjustmentLevel:null};this.notify("filter",{prop:"getAdjustmentLevel",onPropertyChange:!1,value:{obj:t}}),this.lowerContext.filter=this.initialAdjustmentValue,this.notify("draw",{prop:"setTempAdjustmentValue",value:{tempAdjustmentValue:this.lowerContext.filter}}),this.notify("filter",{prop:"setTempAdjustmentLevel",onPropertyChange:!1,value:{tempAdjustmentLevel:e.extend({},t.adjustmentLevel,{},!0)}}),this.notify("draw",{prop:"setTempFilter",value:{tempFilter:this.currentFilter}});var i={undoRedoStep:null};this.notify("undo-redo",{prop:"getUndoRedoStep",value:{obj:i}}),this.notify("draw",{prop:"setTempUndoRedoStep",value:{tempUndoRedoStep:i.undoRedoStep}})},r.prototype.cropSelectedState=function(){e.isNullOrUndefined(this.activeObj.shape)||"crop"!==this.activeObj.shape.split("-")[0]||this.okBtn()},r.prototype.getCurrentCanvasData=function(){var t=this.lowerContext.filter;this.lowerContext.filter=this.canvasFilter="none";var i=e.extend([],this.objColl,null,!0);this.objColl=[],this.notify("draw",{prop:"render-image",value:{isMouseWheel:!1}});var o=this.getImageData();return e.isBlazor()||(this.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"main",isApplyBtn:!0,isCropping:!1}}),this.element.querySelector("#"+this.element.id+"_contextualToolbarArea").classList.remove("e-hide")),this.objColl=i,this.notify("shape",{prop:"iterateObjColl",onPropertyChange:!1}),this.lowerContext.filter=this.canvasFilter=t,o},r.prototype.setCurrAdjustmentValue=function(t,i){var o=this,r={finetune:this.getFinetuneOption(t),value:i,cancel:!1};if(e.isBlazor()&&!e.isNullOrUndefined(this.events)&&!0===this.events.finetuneValueChanging.hasDelegate)this.dotNetRef.invokeMethodAsync("OnFinetuneValueChangeAsync",r).then(function(e){e.cancel||o.notify("filter",{prop:"setCurrAdjValue",value:{type:t.toLowerCase(),value:i}})});else{if(this.trigger("finetuneValueChanging",r),r.cancel)return;this.notify("filter",{prop:"setCurrAdjValue",value:{type:t.toLowerCase(),value:i}})}},r.prototype.getSquarePointForRotatedShape=function(t,i){var o={startX:0,startY:0,endX:0,endY:0,width:0,height:0},r=t.activePoint.startX+t.activePoint.width/2,n=t.activePoint.startY+t.activePoint.height/2,a={x:Math.cos(t.rotatedAngle)*(t.activePoint.startX-r)-Math.sin(t.rotatedAngle)*(t.activePoint.startY-n)+r,y:Math.sin(t.rotatedAngle)*(t.activePoint.startX-r)+Math.cos(t.rotatedAngle)*(t.activePoint.startY-n)+n},s={x:Math.cos(t.rotatedAngle)*(t.activePoint.endX-r)-Math.sin(t.rotatedAngle)*(t.activePoint.startY-n)+r,y:Math.sin(t.rotatedAngle)*(t.activePoint.endX-r)+Math.cos(t.rotatedAngle)*(t.activePoint.startY-n)+n},l={x:Math.cos(t.rotatedAngle)*(t.activePoint.startX-r)-Math.sin(t.rotatedAngle)*(t.activePoint.endY-n)+r,y:Math.sin(t.rotatedAngle)*(t.activePoint.startX-r)+Math.cos(t.rotatedAngle)*(t.activePoint.endY-n)+n},p={x:Math.cos(t.rotatedAngle)*(t.activePoint.endX-r)-Math.sin(t.rotatedAngle)*(t.activePoint.endY-n)+r,y:Math.sin(t.rotatedAngle)*(t.activePoint.endX-r)+Math.cos(t.rotatedAngle)*(t.activePoint.endY-n)+n};return o.startX=a.x,o.startY=a.y,o.endX=a.x,o.endY=a.y,o.startX>s.x&&(o.startX=s.x),o.startX>l.x&&(o.startX=l.x),o.startX>p.x&&(o.startX=p.x),o.startY>s.y&&(o.startY=s.y),o.startY>l.y&&(o.startY=l.y),o.startY>p.y&&(o.startY=p.y),o.endX<s.x&&(o.endX=s.x),o.endX<l.x&&(o.endX=l.x),o.endX<p.x&&(o.endX=p.x),o.endY<s.y&&(o.endY=s.y),o.endY<l.y&&(o.endY=l.y),o.endY<p.y&&(o.endY=p.y),o.width=o.endX-o.startX,o.height=o.endY-o.startY,e.isNullOrUndefined(i)||(i.activePoint=o),o},r.prototype.getSquarePointForPath=function(t){var e={startX:0,startY:0,endX:0,endY:0,width:0,height:0};if(t.pointColl.length>0){e={startX:t.pointColl[0].x,startY:t.pointColl[0].y,endX:t.pointColl[0].x,endY:t.pointColl[0].y};for(var i=1;i<t.pointColl.length;i++)t.pointColl[i].x<e.startX&&(e.startX=t.pointColl[i].x),t.pointColl[i].y<e.startY&&(e.startY=t.pointColl[i].y),t.pointColl[i].x>e.endX&&(e.endX=t.pointColl[i].x),t.pointColl[i].y>e.endY&&(e.endY=t.pointColl[i].y);e.width=e.endX-e.startX,e.height=e.endY-e.startY}return e},r.prototype.getSelectionType=function(t){return{CropCustom:"Custom",CropSquare:"Square",CropCircle:"Circle","Crop3:2":"3:2","Crop4:3":"4:3","Crop5:4":"5:4","Crop7:5":"7:5","Crop16:9":"16:9"}[""+t]},r.prototype.clearContext=function(t){t.clearRect(0,0,t.canvas.width,t.canvas.height),t.clearRect(0,0,t.canvas.height,t.canvas.width)},r.prototype.updateArrow=function(t,i){this.notify("shape",{prop:"pushActItemIntoObj"});var o=e.extend({},this.cropObj,{},!0),r={currObj:{}};this.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:r}});var n=r.currObj;if(n.objColl=e.extend([],this.objColl,[],!0),n.pointColl=e.extend([],this.pointColl,[],!0),n.afterCropActions=e.extend([],this.afterCropActions,[],!0),this.objColl.pop(),"startArrow"===t?this.activeObj.start=this.getTextFromId(i):"endArrow"===t&&(this.activeObj.end=this.getTextFromId(i)),this.notify("shape",{prop:"setStrokeSettings",value:{strokeSettings:null,strokeColor:null,fillColor:null,strokeWidth:this.activeObj.strokeSettings.strokeWidth}}),this.objColl.push(this.activeObj),this.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"shapeTransform",previousObj:n,previousObjColl:n.objColl,previousPointColl:n.pointColl,previousCropObj:o,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),this.notify("selection",{prop:"redrawShape",value:{obj:this.objColl[this.objColl.length-1]}}),!e.isBlazor())if(e.Browser.isDevice){if(!e.isNullOrUndefined(document.getElementById(this.element.id+"_bottomToolbar"))){e.getComponent(this.element.id+"_bottomToolbar","toolbar").refreshOverflow()}}else if(!e.isNullOrUndefined(document.getElementById(this.element.id+"_toolbar"))){e.getComponent(this.element.id+"_toolbar","toolbar").refreshOverflow()}},r.prototype.updateFontFamily=function(t){this.notify("selection",{prop:"setInitialTextEdit",value:{bool:!1}}),this.notify("shape",{prop:"pushActItemIntoObj"});var i=e.extend([],this.objColl,[],!0),o=e.extend({},this.cropObj,{},!0),r={currObj:{}};this.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:r}});var n=r.currObj;n.objColl=e.extend([],this.objColl,[],!0),n.pointColl=e.extend([],this.pointColl,[],!0),n.afterCropActions=e.extend([],this.afterCropActions,[],!0);var a={selPointColl:null};if(this.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:a}}),n.selPointColl=e.extend([],a.selPointColl,[],!0),this.objColl.pop(),"block"===this.textArea.style.display){this.notify("shape",{prop:"updateFontRatio",onPropertyChange:!1,value:{obj:this.activeObj,isTextArea:!0}});var s=this.activeObj.textSettings.fontFamily;this.activeObj.textSettings.fontFamily=this.toPascalCase(t),this.notify("shape",{prop:"redraw-text"}),this.objColl.push(this.activeObj),this.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"textAreaCustomization",previousObj:n,previousObjColl:n.objColl,previousPointColl:n.pointColl,previousSelPointColl:n.selPointColl,previousCropObj:o,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),this.objColl.pop(),this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height);var l=this.activeObj.activePoint.width+.25*this.activeObj.textSettings.fontSize;this.textArea.style.width=l+"px",this.textArea.style.fontFamily=this.toPascalCase(t),this.activeObj.textSettings.fontFamily=s,this.notify("shape",{prop:"updateFontStyles",onPropertyChange:!1,value:{isTextBox:null}})}else{this.notify("shape",{prop:"updateFontRatio",onPropertyChange:!1,value:{obj:this.activeObj,isTextArea:null}});var p=this.activeObj.textSettings.fontFamily=this.toPascalCase(t);this.notify("shape",{prop:"setTextSettings",onPropertyChange:!1,value:{textSettings:null,fontFamily:p,fontSize:null}}),this.notify("shape",{prop:"redraw-text"}),this.objColl.push(this.activeObj),this.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"shapeTransform",previousObj:n,previousObjColl:i,previousPointColl:e.extend([],this.pointColl,[],!0),previousSelPointColl:n.selPointColl,previousCropObj:o,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),this.notify("selection",{prop:"redrawShape",value:{obj:this.objColl[this.objColl.length-1]}})}},r.prototype.updateFontSize=function(t){var i=t;this.notify("selection",{prop:"setInitialTextEdit",value:{bool:!1}}),this.notify("shape",{prop:"pushActItemIntoObj"});var o=e.extend({},this.cropObj,{},!0),r={currObj:{}};this.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:r}});var n=r.currObj;n.objColl=e.extend([],this.objColl,[],!0),n.pointColl=e.extend([],this.pointColl,[],!0),n.afterCropActions=e.extend([],this.afterCropActions,[],!0);var a={selPointColl:null};if(this.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:a}}),n.selPointColl=e.extend([],a.selPointColl,[],!0),this.objColl.pop(),"block"===this.textArea.style.display){this.notify("shape",{prop:"updateFontRatio",onPropertyChange:!1,value:{obj:this.activeObj,isTextArea:!0}});var s=this.activeObj.textSettings.fontSize;this.activeObj.textSettings.fontSize=parseInt(this.fontSizeColl[parseInt(i,10)-1].text,10),this.objColl.push(this.activeObj),this.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"textAreaCustomization",previousObj:n,previousObjColl:n.objColl,previousPointColl:n.pointColl,previousSelPointColl:n.selPointColl,previousCropObj:o,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),this.objColl.pop();var l="";"bold"===this.textArea.style.fontWeight&&(l="bold "),"italic"===this.textArea.style.fontStyle&&(l="italic "),"bold"===this.textArea.style.fontWeight&&"italic"===this.textArea.style.fontStyle&&(l="italic bold "),this.upperContext.font=l+this.activeObj.textSettings.fontSize+"px "+this.textArea.style.fontFamily;var p=this.textArea.value.split("\n"),h={maxText:""};this.notify("shape",{prop:"getMaxText",onPropertyChange:!1,value:{isTextBox:!0,text:null,obj:h}});var c=h.maxText,d=this.upperContext.measureText(c).width+.5*this.activeObj.textSettings.fontSize;this.textArea.style.width=d+"px",this.textArea.style.height=p.length*(this.activeObj.textSettings.fontSize+.25*this.activeObj.textSettings.fontSize)+"px",this.activeObj.textSettings.fontSize=s,this.upperContext.font=this.activeObj.textSettings.fontSize+"px "+this.activeObj.textSettings.fontFamily,this.textArea.style.fontSize=parseInt(this.fontSizeColl[parseInt(i,10)-1].text,10)+"px","georgia"===this.textArea.style.fontFamily&&(this.textArea.style.width=parseFloat(this.textArea.style.width)+parseFloat(this.textArea.style.fontSize)+"px")}else{this.notify("shape",{prop:"updateFontRatio",onPropertyChange:!1,value:{obj:this.activeObj,isTextArea:null}});var v=this.activeObj.textSettings.fontSize=parseInt(this.fontSizeColl[parseInt(i,10)-1].text,10);this.notify("shape",{prop:"setTextSettings",onPropertyChange:!1,value:{textSettings:null,fontFamily:null,fontSize:v}}),this.upperContext.font=this.activeObj.textSettings.fontSize+"px "+this.activeObj.textSettings.fontFamily;p=this.activeObj.keyHistory.split("\n"),h={maxText:""};this.notify("shape",{prop:"getMaxText",onPropertyChange:!1,value:{isTextBox:null,text:null,obj:h}});var u=h.maxText,g=(d=this.upperContext.measureText(u).width+.5*this.activeObj.textSettings.fontSize,p.length*(this.activeObj.textSettings.fontSize+.25*this.activeObj.textSettings.fontSize));this.notify("selection",{prop:"setTextSelection",onPropertyChange:!1,value:{width:d,height:g}}),this.notify("draw",{prop:"updateActiveObject",onPropertyChange:!1,value:{actPoint:this.activeObj.activePoint,obj:this.activeObj,isMouseMove:null,x:null,y:null}}),this.notify("shape",{prop:"redraw-text"}),this.objColl.push(this.activeObj),this.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"shapeTransform",previousObj:n,previousObjColl:n.objColl,previousPointColl:n.pointColl,previousSelPointColl:n.selPointColl,previousCropObj:o,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),this.notify("selection",{prop:"redrawShape",value:{obj:this.objColl[this.objColl.length-1]}})}},r.prototype.updateFontColor=function(t){this.notify("selection",{prop:"setInitialTextEdit",value:{bool:!1}}),this.notify("shape",{prop:"pushActItemIntoObj"});var i=e.extend({},this.cropObj,{},!0),o={currObj:{}};this.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:o}});var r=o.currObj;r.objColl=e.extend([],this.objColl,[],!0),r.pointColl=e.extend([],this.pointColl,[],!0),r.afterCropActions=e.extend([],this.afterCropActions,[],!0);var n={selPointColl:null};if(this.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:n}}),r.selPointColl=e.extend([],n.selPointColl,[],!0),this.objColl.pop(),"none"===this.textArea.style.display)this.activeObj.strokeSettings.strokeColor=t,this.notify("shape",{prop:"setStrokeSettings",value:{strokeSettings:null,strokeColor:this.activeObj.strokeSettings.strokeColor,fillColor:null,strokeWidth:null}}),this.togglePen||(this.objColl.push(this.activeObj),this.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"shapeTransform",previousObj:r,previousObjColl:r.objColl,previousPointColl:r.pointColl,previousSelPointColl:r.selPointColl,previousCropObj:i,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),this.notify("selection",{prop:"redrawShape",value:{obj:this.objColl[this.objColl.length-1]}}));else if("block"===this.textArea.style.display){this.textArea.style.color=t;var a=this.activeObj.strokeSettings.strokeColor;this.activeObj.strokeSettings.strokeColor=t,this.objColl.push(this.activeObj),this.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"textAreaCustomization",previousObj:r,previousObjColl:r.objColl,previousPointColl:r.pointColl,previousSelPointColl:r.selPointColl,previousCropObj:i,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),this.objColl.pop(),this.activeObj.strokeSettings.strokeColor=a}else this.togglePen||(this.objColl.push(this.activeObj),this.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"shapeTransform",previousObj:r,previousObjColl:r.objColl,previousPointColl:r.pointColl,previousSelPointColl:r.selPointColl,previousCropObj:i,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),this.notify("selection",{prop:"redrawShape",value:{obj:this.objColl[this.objColl.length-1]}}))},r.prototype.updatePenStrokeWidth=function(t){var i=e.extend([],this.pointColl,[],!0);this.updateFreehandDrawColorChange();var o=e.extend({},this.cropObj,{},!0),r={currObj:{}};this.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:r}});var n=r.currObj;n.objColl=e.extend([],this.objColl,[],!0),n.pointColl=e.extend([],this.pointColl,[],!0),n.afterCropActions=e.extend([],this.afterCropActions,[],!0);var a={selPointColl:null};this.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:a}}),n.selPointColl=e.extend([],a.selPointColl,[],!0),this.pointColl=i,this.notify("selection",{prop:"setFreehandDrawCustomized",value:{isFreehandDrawCustomized:!0}}),this.setPenStroke(t);var s={bool:!1};if(this.notify("selection",{prop:"getFreehandDrawEditing",onPropertyChange:!1,value:{obj:s}}),s.bool){var l={penStrokeWidth:null};this.notify("freehand-draw",{prop:"getPenStrokeWidth",onPropertyChange:!1,value:{obj:l}}),this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),this.notify("freehand-draw",{prop:"hoverFhd",onPropertyChange:!1,value:{strokeColor:null,strokeWidth:l.penStrokeWidth}});var p={freehandSelectedIndex:null};this.notify("freehand-draw",{prop:"getFreehandSelectedIndex",onPropertyChange:!1,value:{obj:p}}),this.pointColl[p.freehandSelectedIndex].strokeWidth=l.penStrokeWidth,this.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"freehanddrawCustomized",previousObj:n,previousObjColl:n.objColl,previousPointColl:n.pointColl,previousSelPointColl:n.selPointColl,previousCropObj:o,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}})}},r.prototype.updatePenStrokeColor=function(t){var i=e.extend([],this.pointColl,[],!0);this.updateFreehandDrawColorChange();var o=e.extend({},this.cropObj,{},!0),r={currObj:{}};this.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:r}});var n=r.currObj;n.objColl=e.extend([],this.objColl,[],!0),n.pointColl=e.extend([],this.pointColl,[],!0),n.afterCropActions=e.extend([],this.afterCropActions,[],!0);var a={selPointColl:null};this.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:a}}),n.selPointColl=e.extend([],a.selPointColl,[],!0),this.pointColl=i,this.notify("selection",{prop:"setFreehandDrawCustomized",value:{isFreehandDrawCustomized:!0}}),this.activeObj.strokeSettings.strokeColor=t;var s={bool:!1};if(this.notify("selection",{prop:"getFreehandDrawEditing",onPropertyChange:!1,value:{obj:s}}),s.bool){var l={freehandSelectedIndex:null};this.notify("freehand-draw",{prop:"getFreehandSelectedIndex",onPropertyChange:!1,value:{obj:l}}),this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),this.pointColl[l.freehandSelectedIndex].strokeColor=t,this.notify("freehand-draw",{prop:"hoverFhd",onPropertyChange:!1,value:{strokeColor:t}}),this.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"freehanddrawCustomized",previousObj:n,previousObjColl:n.objColl,previousPointColl:n.pointColl,previousSelPointColl:n.selPointColl,previousCropObj:o,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}})}else this.togglePen||this.notify("selection",{prop:"redrawShape",value:{obj:this.activeObj}})},r.prototype.updateStrokeWidth=function(t){this.notify("shape",{prop:"pushActItemIntoObj"});var i=e.extend({},this.cropObj,{},!0),o={currObj:{}};this.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:o}});var r=o.currObj;r.objColl=e.extend([],this.objColl,[],!0),r.pointColl=e.extend([],this.pointColl,[],!0),r.afterCropActions=e.extend([],this.afterCropActions,[],!0);var n={selPointColl:null};this.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:n}}),r.selPointColl=e.extend([],n.selPointColl,[],!0),this.objColl.pop(),this.activeObj.strokeSettings.strokeWidth=parseInt(t,10),this.activeObj.strokeSettings.strokeWidth*=2,this.notify("shape",{prop:"setStrokeSettings",value:{strokeSettings:null,strokeColor:null,fillColor:null,strokeWidth:this.activeObj.strokeSettings.strokeWidth}}),this.objColl.push(this.activeObj),this.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"shapeTransform",previousObj:r,previousObjColl:r.objColl,previousPointColl:r.pointColl,previousSelPointColl:r.selPointColl,previousCropObj:i,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),this.notify("selection",{prop:"redrawShape",value:{obj:this.objColl[this.objColl.length-1]}})},r.prototype.updateStrokeColor=function(t){this.notify("shape",{prop:"pushActItemIntoObj"});var i=e.extend({},this.cropObj,{},!0),o={currObj:{}};this.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:o}});var r=o.currObj;r.objColl=e.extend([],this.objColl,[],!0),r.pointColl=e.extend([],this.pointColl,[],!0),r.afterCropActions=e.extend([],this.afterCropActions,[],!0);var n={selPointColl:null};this.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:n}}),r.selPointColl=e.extend([],n.selPointColl,[],!0),this.objColl.pop(),this.activeObj.strokeSettings.strokeColor=t,this.notify("shape",{prop:"setStrokeSettings",value:{strokeSettings:null,strokeColor:this.activeObj.strokeSettings.strokeColor,fillColor:null,strokeWidth:null}}),this.togglePen||(this.objColl.push(this.activeObj),this.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"shapeTransform",previousObj:r,previousObjColl:r.objColl,previousPointColl:r.pointColl,previousSelPointColl:r.selPointColl,previousCropObj:i,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),this.notify("selection",{prop:"redrawShape",value:{obj:this.objColl[this.objColl.length-1]}}))},r.prototype.updateFillColor=function(t){this.notify("shape",{prop:"pushActItemIntoObj"});var i=e.extend({},this.cropObj,{},!0),o={currObj:{}};this.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:o}});var r=o.currObj;r.objColl=e.extend([],this.objColl,[],!0),r.pointColl=e.extend([],this.pointColl,[],!0),r.afterCropActions=e.extend([],this.afterCropActions,[],!0);var n={selPointColl:null};this.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:n}}),r.selPointColl=e.extend([],n.selPointColl,[],!0),this.objColl.pop(),this.activeObj.strokeSettings.fillColor=t,this.notify("shape",{prop:"setStrokeSettings",value:{strokeSettings:null,strokeColor:null,fillColor:this.activeObj.strokeSettings.fillColor,strokeWidth:null}}),this.objColl.push(this.activeObj),this.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"shapeTransform",previousObj:r,previousObjColl:r.objColl,previousPointColl:r.pointColl,previousSelPointColl:r.selPointColl,previousCropObj:i,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),this.notify("selection",{prop:"redrawShape",value:{obj:this.objColl[this.objColl.length-1]}})},r.prototype.pascalToSplitWords=function(t){var i=(t=t.charAt(0).toUpperCase()+t.slice(1)).match(/[A-Z][a-z]+/g);return e.isNullOrUndefined(i)?t:i.map(function(t){return t.charAt(0).toUpperCase()+t.slice(1)}).join(" ")},r.prototype.getCurrAdjustmentValue=function(t){var e={adjustmentLevel:null};this.notify("filter",{prop:"getAdjustmentLevel",onPropertyChange:!1,value:{obj:e}});return{brightness:e.adjustmentLevel.brightness,contrast:e.adjustmentLevel.contrast,hue:e.adjustmentLevel.hue,saturation:e.adjustmentLevel.saturation,opacity:e.adjustmentLevel.opacity,blur:e.adjustmentLevel.blur,exposure:e.adjustmentLevel.exposure}[""+t]},r.prototype.transformSelect=function(t){this.isCropToolbar=!0,this.setInitialZoomState();var i=e.extend({},this.activeObj,{},!0);this.cropSelectedState(),this.notify("draw",{prop:"resetCurrentSelectionPoint"}),this.notify("transform",{prop:"performTransformation",value:{text:t}}),this.moveToSelectionRange(t,i),this.isCropToolbar=!1},r.prototype.getDefaultFilter=function(){return"brightness(1) contrast(100%) hue-rotate(0deg) saturate(100%) opacity(1) blur(0px) sepia(0%) grayscale(0%) invert(0%)"},r.prototype.initializeImageEditor=function(t,o){this.element=t;var r=this.element.querySelector(".e-canvas-wrapper");e.isNullOrUndefined(this.element.querySelector("#"+this.element.id+"_toolbar"))?this.toolbarHeight=0:this.toolbarHeight=this.element.querySelector("#"+this.element.id+"_toolbar").clientHeight,r.style.height=this.element.offsetHeight-this.toolbarHeight-2+"px",r.style.width=this.element.offsetWidth-2+"px",this.lowerCanvas=this.element.querySelector(".e-lower-canvas"),this.upperCanvas=this.element.querySelector(".e-upper-canvas"),this.lowerCanvas.id=this.element.id+"_lowerCanvas",this.upperCanvas.id=this.element.id+"_upperCanvas",this.textArea=this.element.querySelector(".e-textbox"),this.inMemoryCanvas=this.createElement("canvas",{id:this.element.id+"_inMemoryCanvas",attrs:{name:"canvasImage"}}),this.upperCanvas.width=this.lowerCanvas.width=this.inMemoryCanvas.width=this.element.offsetWidth,this.upperCanvas.height=this.lowerCanvas.height=this.inMemoryCanvas.height=this.element.offsetHeight-this.toolbarHeight,this.baseImg=this.createElement("img",{id:this.element.id+"_orgImg",attrs:{name:"Image",crossorigin:"anonymous"}}),this.lowerContext=this.lowerCanvas.getContext("2d"),this.baseImg=this.createElement("img",{id:this.element.id+"_orgImg",attrs:{name:"Image",crossorigin:"anonymous"}}),this.upperContext=this.upperCanvas.getContext("2d"),this.inMemoryContext=this.inMemoryCanvas.getContext("2d"),o&&(this.dotNetRef=o),this.prerender(),this.wireEvent(),this.lowerContext.filter=this.getDefaultFilter(),this.notify("filter",{prop:"setAdjustmentValue",onPropertyChange:!1,value:{adjustmentValue:this.lowerContext.filter}}),this.canvasFilter=this.initialAdjustmentValue=this.lowerContext.filter,this.cssClass&&e.addClass([this.element],this.cssClass.replace(/\s+/g," ").trim().split(" ")),this.element&&i.createSpinner({target:this.element}),this.initializeZoomSettings()},r.prototype.prerender=function(){this.element.id=this.element.id||e.getUniqueID("ej2-image-editor"),e.Browser.isDevice&&this.element.classList.add("e-device"),this.initializeThemeColl()},r.prototype.initializeZoomSettings=function(){e.isNullOrUndefined(this.zoomSettings.zoomTrigger)&&(this.zoomSettings.zoomTrigger=t.ZoomTrigger.MouseWheel|t.ZoomTrigger.Pinch|t.ZoomTrigger.Toolbar|t.ZoomTrigger.Commands),e.isNullOrUndefined(this.selectionSettings.strokeColor)&&(this.selectionSettings.strokeColor=this.themeColl[this.theme].primaryColor),e.isNullOrUndefined(this.selectionSettings.fillColor)&&(this.selectionSettings.fillColor=this.themeColl[this.theme].secondaryColor)},r.prototype.initializeThemeColl=function(){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"},Material3:{primaryColor:"#6750a4",secondaryColor:"#fff"},Material3Dark:{primaryColor:"#d0bcff",secondaryColor:"#fff"}}},r.prototype.updateToolbar=function(t,e,i){};var n;return b([e.Property("")],r.prototype,"cssClass",void 0),b([e.Property(!1)],r.prototype,"disabled",void 0),b([e.Property("100%")],r.prototype,"height",void 0),b([e.Property("Bootstrap5")],r.prototype,"theme",void 0),b([e.Property()],r.prototype,"toolbar",void 0),b([e.Property()],r.prototype,"toolbarTemplate",void 0),b([e.Property("100%")],r.prototype,"width",void 0),b([e.Property(!0)],r.prototype,"allowUndoRedo",void 0),b([e.Property(!0)],r.prototype,"showQuickAccessToolbar",void 0),b([e.Property()],r.prototype,"quickAccessToolbarTemplate",void 0),b([e.Property(!1)],r.prototype,"isReadOnly",void 0),b([e.Property(!1)],r.prototype,"enableRtl",void 0),b([e.Property(!1)],r.prototype,"enablePersistence",void 0),b([e.Complex({},C)],r.prototype,"finetuneSettings",void 0),b([e.Complex({},f)],r.prototype,"zoomSettings",void 0),b([e.Complex({},m)],r.prototype,"selectionSettings",void 0),b([e.Event()],r.prototype,"beforeSave",void 0),b([e.Event()],r.prototype,"created",void 0),b([e.Event()],r.prototype,"destroyed",void 0),b([e.Event()],r.prototype,"zooming",void 0),b([e.Event()],r.prototype,"panning",void 0),b([e.Event()],r.prototype,"cropping",void 0),b([e.Event()],r.prototype,"rotating",void 0),b([e.Event()],r.prototype,"flipping",void 0),b([e.Event()],r.prototype,"shapeChanging",void 0),b([e.Event()],r.prototype,"selectionChanging",void 0),b([e.Event()],r.prototype,"fileOpened",void 0),b([e.Event()],r.prototype,"saved",void 0),b([e.Event()],r.prototype,"toolbarCreated",void 0),b([e.Event()],r.prototype,"toolbarUpdating",void 0),b([e.Event()],r.prototype,"toolbarItemClicked",void 0),b([e.Event()],r.prototype,"imageFiltering",void 0),b([e.Event()],r.prototype,"finetuneValueChanging",void 0),b([e.Event()],r.prototype,"click",void 0),b([e.Event()],r.prototype,"quickAccessToolbarOpen",void 0),b([e.Event()],r.prototype,"quickAccessToolbarItemClick",void 0),r=n=b([e.NotifyPropertyChanges],r)}(e.Component);!function(t){t.Png="Png",t.Jpeg="Jpeg",t.Svg="Svg"}(t.FileType||(t.FileType={})),function(t){t.Horizontal="Horizontal",t.Vertical="Vertical"}(t.Direction||(t.Direction={})),function(t){t.Rectangle="Rectangle",t.Ellipse="Ellipse",t.Line="Line",t.Arrow="Arrow",t.Path="Path",t.Text="Text",t.FreehandDraw="FreehandDraw"}(t.ShapeType||(t.ShapeType={})),function(t){t[t.MouseWheel=1]="MouseWheel",t[t.Pinch=2]="Pinch",t[t.Commands=4]="Commands",t[t.Toolbar=8]="Toolbar"}(t.ZoomTrigger||(t.ZoomTrigger={})),function(t){t.Bootstrap5="Bootstrap5",t.Bootstrap5Dark="Bootstrap5Dark",t.Tailwind="Tailwind",t.TailwindDark="TailwindDark",t.Fluent="Fluent",t.FluentDark="FluentDark",t.Bootstrap4="Bootstrap4",t.Bootstrap="Bootstrap",t.BootstrapDark="BootstrapDark",t.Material="Material",t.MaterialDark="MaterialDark",t.Fabric="Fabric",t.FabricDark="FabricDark",t.Highcontrast="Highcontrast"}(t.Theme||(t.Theme={})),function(t){t.Crop="Crop",t.Transform="Transform",t.Annotate="Annotate",t.ZoomIn="ZoomIn",t.ZoomOut="ZoomOut",t.Open="Open",t.Reset="Reset",t.Save="Save",t.Pan="Pan",t.Move="Move",t.Pen="Pen",t.Line="Line",t.Arrow="Arrow",t.Path="Path",t.Rectangle="Rectangle",t.Ellipse="Ellipse",t.Text="Text",t.CustomSelection="CustomSelection",t.CircleSelection="CircleSelection",t.SquareSelection="SquareSelection",t.RatioSelection="RatioSelection",t.RotateLeft="RotateLeft",t.RotateRight="RotateRight",t.FlipHorizontal="FlipHorizontal",t.FlipVertical="FlipVertical"}(t.ImageEditorCommand||(t.ImageEditorCommand={})),function(t){t.Default="Default",t.Chrome="Chrome",t.Cold="Cold",t.Warm="Warm",t.Grayscale="Grayscale",t.Sepia="Sepia",t.Invert="Invert"}(t.ImageFilterOption||(t.ImageFilterOption={})),function(t){t.Brightness="Brightness",t.Contrast="Contrast",t.Hue="Hue",t.Saturation="Saturation",t.Exposure="Exposure",t.Opacity="Opacity",t.Blur="Blur"}(t.ImageFinetuneOption||(t.ImageFinetuneOption={})),function(t){t.None="None",t.Arrow="Arrow",t.SolidArrow="SolidArrow",t.Circle="Circle",t.SolidCircle="SolidCircle",t.Square="Square",t.SolidSquare="SolidSquare",t.Bar="Bar"}(t.ArrowheadType||(t.ArrowheadType={}));var P=function(){function a(t){this.defToolbarItems=[],this.toolbarHeight=46,this.currToolbar="",this.preventZoomBtn=!1,this.currentToolbar="main",this.selFhdColor="#42a5f5",this.preventEnableDisableUr=!1,this.parent=t,this.addEventListener(),this.initLocale()}return a.prototype.destroy=function(){this.parent.isDestroyed||this.removeEventListener()},a.prototype.addEventListener=function(){this.parent.on("toolbar",this.toolbar,this),this.parent.on("destroyed",this.destroy,this)},a.prototype.removeEventListener=function(){this.parent.off("toolbar",this.toolbar),this.parent.off("destroyed",this.destroy)},a.prototype.initLocale=function(){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",Arrow:"Arrow",Path:"Path",Bold:"Bold",Italic:"Italic",BoldItalic:"Bold Italic",XSmall:"X-Small",Small:"Small",Medium:"Medium",Large:"Large",XLarge:"X-Large",ABC:"ABC",Browse:"Browse",Duplicate:"Duplicate",Remove:"Remove",EditText:"Edit Text",Start:"Start",End:"End",Bar:"Bar",ArrowSolid:"Arrow Solid",CircleSolid:"Circle Solid",SquareSolid:"Square Solid",None:"None",CropAndTransform:"Crop and Transform",CropSelection:"Crop Selection"},this.l10n=new e.L10n("image-editor",this.defaultLocale,this.parent.locale)},a.prototype.toolbar=function(t){switch(this.updatePrivateVariables(),t.prop){case"create-toolbar":this.createToolbar();break;case"create-contextual-toolbar":this.createContextualToolbar();break;case"update-toolbar-items":this.updateToolbarItems();break;case"refresh-toolbar":this.refreshToolbar(t.value.type,t.value.isApplyBtn,t.value.isCropping,t.value.isZooming,t.value.cType);break;case"renderQAT":this.renderQAT(t.value.isPenEdit);break;case"enable-disable-btns":this.enableDisableTbrBtn();break;case"init-main-toolbar":this.initMainToolbar(t.value.isApplyBtn,t.value.isDevice,t.value.isOkBtn);break;case"create-bottom-toolbar":this.createBottomToolbar();break;case"refresh-main-toolbar":this.refreshMainToolbar();break;case"create-qa-toolbar":this.createQuickAccessToolbar();break;case"destroy-qa-toolbar":this.destroyQuickAccessToolbar();break;case"zoom-up-handler":this.zoomBtnMouseUpHandler();break;case"refresh-dropdown-btn":this.refreshDropDownBtn(t.value.isDisabled);break;case"close-contextual-toolbar":this.closeContextualToolbar();break;case"destroy-bottom-toolbar":this.destroyBottomToolbar();break;case"destroy-top-toolbar":this.destroyTopToolbar();break;case"destroySubComponents":this.destroySubComponents();break;case"setLocale":this.l10n.setLocale(t.value.locale);break;case"setPreventZoomBtn":this.preventZoomBtn=t.value.isPrevent;break;case"getToolbarHeight":t.value.obj.toolbarHeight=this.toolbarHeight;break;case"setToolbarHeight":this.toolbarHeight=t.value.height;break;case"setCurrentToolbar":this.currentToolbar=t.value.type;break;case"setSelectedFreehandColor":this.selFhdColor=t.value.color;break;case"getCurrentFilter":t.value.obj.currentFilter=this.parent.currentFilter;break;case"setCurrentFilter":this.parent.currentFilter=t.value.filter;break;case"setInitialAdjustmentValue":this.parent.initialAdjustmentValue=t.value.value;break;case"getCanvasFilter":t.value.obj.canvasFilter=this.parent.canvasFilter;break;case"setCanvasFilter":this.parent.canvasFilter=t.value.filter;break;case"getDefToolbarItems":t.value.obj.defToolbarItems=this.defToolbarItems;break;case"getPenStroke":this.getPenStroke(t.value.value);break;case"performDefToolbarClickAction":this.performDefTbrClick(t.value.type,t.value.isContextualToolbar,t.value.isDisabledAdjustment,t.value.isDisabledFilter,t.value.isFilterFinetune);break;case"setTempFilterProperties":this.parent.setTempFilterProperties();break;case"refreshSlider":this.refreshSlider();break;case"renderSlider":this.renderSlider(t.value.type);break;case"getCurrAdjustmentValue":this.parent.getCurrAdjustmentValue(t.value.type);break;case"setCurrAdjustmentValue":this.parent.setCurrAdjustmentValue(t.value.type,t.value.value);break;case"refreshShapeDrawing":this.refreshShapeDrawing();break;case"getSquarePointForRotatedShape":this.parent.getSquarePointForRotatedShape(t.value.obj,t.value.object);break;case"getCropToolbar":t.value.obj.isCropToolbar=this.parent.isCropToolbar;break;case"getPrevCurrSelectionPoint":t.value.obj.prevCurrSelectionPoint=this.parent.prevCurrSelectionPoint;break;case"setPrevCurrSelectionPoint":this.parent.prevCurrSelectionPoint=t.value.point;break;case"updateCropTransformItems":this.parent.updateCropTransformItems();break;case"setEnableDisableUndoRedo":this.preventEnableDisableUr=t.value.isPrevent;break;case"reset":this.reset()}},a.prototype.updatePrivateVariables=function(){var t=this.parent;this.inMemoryCanvas=t.inMemoryCanvas,e.isNullOrUndefined(t.lowerCanvas)||(this.lowerContext=t.lowerCanvas.getContext("2d")),e.isNullOrUndefined(t.upperCanvas)||(this.upperContext=t.upperCanvas.getContext("2d")),e.isNullOrUndefined(this.inMemoryCanvas)||(this.inMemoryContext=this.inMemoryCanvas.getContext("2d"))},a.prototype.reset=function(){this.defToolbarItems=[],this.toolbarHeight=46,this.parent.prevCurrSelectionPoint=null,this.zoomBtnHold=null,this.currToolbar="",this.currentToolbar="main",this.selFhdColor="#42a5f5",this.parent.currentFilter="",this.preventZoomBtn=this.parent.isCropToolbar=this.preventEnableDisableUr=!1,this.parent.initialAdjustmentValue=this.parent.canvasFilter="brightness(1) contrast(100%) hue-rotate(0deg) saturate(100%) opacity(1) blur(0px) sepia(0%) grayscale(0%) invert(0%)"},a.prototype.destroyTopToolbar=function(){var t=this.parent;!this.isToolbar()||e.isNullOrUndefined(document.getElementById(t.element.id+"_toolbar"))||e.isNullOrUndefined(e.getComponent(document.getElementById(t.element.id+"_toolbar"),"toolbar"))||e.getComponent(document.getElementById(t.element.id+"_toolbar"),"toolbar").destroy()},a.prototype.destroyBottomToolbar=function(){var t=this.parent;e.isNullOrUndefined(document.getElementById(t.element.id+"_bottomToolbar"))||e.isNullOrUndefined(e.getComponent(document.getElementById(t.element.id+"_bottomToolbar"),"toolbar"))||e.getComponent(document.getElementById(t.element.id+"_bottomToolbar"),"toolbar").destroy()},a.prototype.isToolbar=function(){return e.isNullOrUndefined(this.parent.toolbar)||!e.isNullOrUndefined(this.parent.toolbar)&&this.parent.toolbar.length>0||!e.isNullOrUndefined(this.parent.toolbarTemplate)},a.prototype.createToolbar=function(){var t=this,i=this.parent;if(e.isNullOrUndefined(i.toolbar)||!e.isNullOrUndefined(i.toolbar)&&i.toolbar.length>0){i.element.appendChild(i.createElement("div",{id:i.element.id+"_toolbarArea",className:"e-toolbar-area"}));var r={cssClass:"e-image-upload",align:"Left",type:"Input",tooltipText:this.l10n.getConstant("Browse"),template:new n.Uploader({allowedExtensions:".jpg, .jpeg, .png,.svg"})};e.isNullOrUndefined(this.defToolbarItems)&&(this.defToolbarItems=[]),this.defToolbarItems.push(r);var a=document.getElementById(i.element.id+"_toolbarArea"),s=i.createElement("div",{id:i.element.id+"_toolbar"});a.appendChild(s);var l=[{cssClass:"e-image-upload",align:"Left",type:"Input",tooltipText:this.l10n.getConstant("Browse"),template:new n.Uploader({allowedExtensions:".jpg, .jpeg, .png,.svg",selected:function(){i.disabled||(e.Browser.isDevice?(t.defToolbarItems.length>0&&!e.isNullOrUndefined(document.getElementById(i.element.id+"_toolbar"))&&e.getComponent(document.getElementById(i.element.id+"_toolbar"),"toolbar").destroy(),e.isNullOrUndefined(document.getElementById(i.element.id+"_bottomToolbar"))||e.getComponent(document.getElementById(i.element.id+"_bottomToolbar"),"toolbar").destroy(),t.initMainToolbar(!1,e.Browser.isDevice,null),t.createBottomToolbar()):(t.defToolbarItems.length>0&&!e.isNullOrUndefined(document.getElementById(i.element.id+"_toolbar"))&&e.getComponent(document.getElementById(i.element.id+"_toolbar"),"toolbar").destroy(),t.initMainToolbar(!1,!1,null)))}})}];new o.Toolbar({items:l,width:"100%",created:function(){i.trigger("toolbarCreated",{toolbarType:"main"})},clicked:this.defToolbarClicked.bind(this)}).appendTo("#"+i.element.id+"_toolbar"),this.createLeftToolbarControls(),e.isNullOrUndefined(document.getElementById(i.element.id+"_toolbar"))||(this.toolbarHeight=document.getElementById(i.element.id+"_toolbar").clientHeight)}else this.toolbarHeight=0},a.prototype.createContextualToolbar=function(){var t=this.parent;if(e.isNullOrUndefined(t.toolbar)||!e.isNullOrUndefined(t.toolbar)&&t.toolbar.length>0){t.element.appendChild(t.createElement("div",{id:t.element.id+"_contextualToolbarArea",className:"e-contextual-toolbar-wrapper e-hide",attrs:{style:"position: absolute;"}}));var i=document.getElementById(t.element.id+"_contextualToolbarArea"),o=t.createElement("div",{id:t.element.id+"_contextualToolbar"});i.appendChild(o)}},a.prototype.createBottomToolbar=function(){var t=this.parent;if(e.isNullOrUndefined(t.toolbar)||!e.isNullOrUndefined(t.toolbar)&&t.toolbar.length>0){if(t.element.appendChild(t.createElement("div",{id:t.element.id+"_bottomToolbarArea",className:"e-bottom-toolbar"})),!t.toolbarTemplate){document.getElementById(t.element.id+"_canvasWrapper").style.height=t.element.offsetHeight-2*this.toolbarHeight-3+"px";var i=document.getElementById(t.element.id+"_bottomToolbarArea"),o=t.createElement("div",{id:t.element.id+"_bottomToolbar"});i.appendChild(o)}this.initBottomToolbar()}},a.prototype.createQuickAccessToolbar=function(){var t=this.parent;if(t.showQuickAccessToolbar){var i={cssClass:"e-image-upload",align:"Left",type:"Input",tooltipText:this.l10n.getConstant("Browse"),template:new n.Uploader({allowedExtensions:".jpg, .jpeg, .png,.svg"})};e.isNullOrUndefined(this.defToolbarItems)&&(this.defToolbarItems=[]),this.defToolbarItems.push(i);var r=document.getElementById(t.element.id+"_quickAccessToolbarArea"),a=t.createElement("div",{id:t.element.id+"_quickAccessToolbar"});r.appendChild(a);new o.Toolbar({clicked:this.defToolbarClicked.bind(this)}).appendTo("#"+t.element.id+"_quickAccessToolbar")}},a.prototype.initMainToolbar=function(t,i,r){var n=this,a=this.parent;if(this.isToolbar()){var s=this.getLeftToolbarItem(r),l=this.getRightToolbarItem(r),p=this.getMainToolbarItem(t),h=this.getZoomToolbarItem();this.defToolbarItems=i?s.concat(l):s.concat(p,l,h);if(new o.Toolbar({width:"100%",items:this.defToolbarItems,clicked:this.defToolbarClicked.bind(this),created:function(){i||n.renderAnnotationBtn(),n.wireZoomBtnEvents(),n.renderSaveBtn(),a.trigger("toolbarCreated",{toolbarType:"main"})}}).appendTo("#"+a.element.id+"_toolbar"),this.createLeftToolbarControls(),this.enableDisableTbrBtn(),this.isToolbar()&&!e.isNullOrUndefined(document.getElementById(a.element.id+"_toolbar"))){e.getComponent(a.element.id+"_toolbar","toolbar").refreshOverflow()}}},a.prototype.initBottomToolbar=function(){var t=this,i=this.parent;if(e.isNullOrUndefined(i.toolbar)||!e.isNullOrUndefined(i.toolbar)&&i.toolbar.length>0){var r=this.getMainToolbarItem();if(new o.Toolbar({items:r,width:"100%",created:function(){t.renderAnnotationBtn(),t.renderCropBtn(),t.renderTransformBtn(),i.trigger("toolbarCreated",{toolbarType:"main"})},clicked:this.defToolbarClicked.bind(this)}).appendTo("#"+i.element.id+"_bottomToolbar"),this.defToolbarItems.length>0&&!e.isNullOrUndefined(document.getElementById(i.element.id+"_bottomToolbar"))){e.getComponent(i.element.id+"_bottomToolbar","toolbar").refreshOverflow()}}},a.prototype.getLeftToolbarItem=function(i){var o=this.parent,r=[];i||(r.push({id:o.element.id+"_upload",cssClass:"e-image-upload",align:"Left",type:"Input",template:new n.Uploader({allowedExtensions:".jpg, .jpeg, .png,.svg"})}),r.push({visible:!1,cssClass:"e-image-position e-btn e-flat",tooltipText:this.l10n.getConstant("Browse"),align:"Left"})),o.allowUndoRedo&&((e.isNullOrUndefined(o.toolbar)||!e.isNullOrUndefined(o.toolbar)&&o.toolbar.indexOf("Undo")>-1)&&r.push({id:o.element.id+"_undo",prefixIcon:"e-icons e-undo",cssClass:"top-icon e-undo",tooltipText:this.l10n.getConstant("Undo"),align:"Left"}),(e.isNullOrUndefined(o.toolbar)||!e.isNullOrUndefined(o.toolbar)&&o.toolbar.indexOf("Redo")>-1)&&r.push({id:o.element.id+"_redo",prefixIcon:"e-icons e-redo",cssClass:"top-icon e-redo",tooltipText:this.l10n.getConstant("Redo"),align:"Left"})),this.preventZoomBtn||(o.zoomSettings.zoomTrigger&t.ZoomTrigger.Toolbar)!==t.ZoomTrigger.Toolbar||((e.isNullOrUndefined(o.toolbar)||!e.isNullOrUndefined(o.toolbar)&&o.toolbar.indexOf("ZoomOut")>-1)&&r.push({id:o.element.id+"_zoomOut",prefixIcon:"e-icons e-zoom-out",cssClass:"top-icon e-dec-zoom",tooltipText:this.l10n.getConstant("ZoomOut"),align:"Left"}),(e.isNullOrUndefined(o.toolbar)||!e.isNullOrUndefined(o.toolbar)&&o.toolbar.indexOf("ZoomIn")>-1)&&r.push({id:o.element.id+"_zoomIn",prefixIcon:"e-icons e-zoom-in",cssClass:"top-icon e-inc-zoom",tooltipText:this.l10n.getConstant("ZoomIn"),align:"Left"}));for(var a=this.processToolbar("left"),s=0,l=a.length;s<l;s++)r.push(a[s]);return r},a.prototype.getRightToolbarItem=function(t){var i=this.parent,o=[];t&&(o.push({id:i.element.id+"_ok",prefixIcon:"e-icons e-check",cssClass:"top-icon e-tick",tooltipText:this.l10n.getConstant("OK"),align:"Right"}),o.push({id:i.element.id+"_cancel",prefixIcon:"e-icons e-close",cssClass:"top-icon e-save",tooltipText:this.l10n.getConstant("Cancel"),align:"Right"})),(e.isNullOrUndefined(i.toolbar)||!e.isNullOrUndefined(i.toolbar)&&i.toolbar.indexOf("Reset")>-1)&&o.push({id:i.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(i.toolbar)||!e.isNullOrUndefined(i.toolbar)&&i.toolbar.indexOf("Save")>-1)&&o.push({id:i.element.id+"_save",prefixIcon:"e-icons e-btn-save",cssClass:"top-icon e-save",tooltipText:this.l10n.getConstant("Save"),align:"Right",template:'<button id="'+i.element.id+'_saveBtn"></button>'});for(var r=this.processToolbar("right"),n=0,a=r.length;n<a;n++)o.push(r[n]);return o},a.prototype.getMainToolbarItem=function(t){var i=this.parent,o=[];(e.isNullOrUndefined(i.toolbar)||!e.isNullOrUndefined(i.toolbar)&&i.toolbar.indexOf("Crop")>-1)&&o.push({id:i.element.id+"_cropTransform",prefixIcon:"e-icons e-crop",cssClass:"top-icon e-crop",tooltipText:this.l10n.getConstant("CropAndTransform"),align:"Center"}),(e.isNullOrUndefined(i.toolbar)||!e.isNullOrUndefined(i.toolbar)&&i.toolbar.indexOf("Annotate")>-1)&&o.push({id:i.element.id+"_annotation",tooltipText:this.l10n.getConstant("Annotation"),align:"Center",template:'<button id="'+this.parent.element.id+'_annotationBtn"></button>'}),(e.isNullOrUndefined(i.toolbar)||!e.isNullOrUndefined(i.toolbar)&&i.toolbar.indexOf("Finetune")>-1)&&o.push({id:i.element.id+"_adjustment",prefixIcon:"e-icons e-adjustment",cssClass:"top-icon e-adjustment",tooltipText:this.l10n.getConstant("Finetune"),align:"Center"}),(e.isNullOrUndefined(i.toolbar)||!e.isNullOrUndefined(i.toolbar)&&i.toolbar.indexOf("Filter")>-1)&&o.push({id:i.element.id+"_filter",prefixIcon:"e-icons e-filters",cssClass:"top-icon e-filters",tooltipText:this.l10n.getConstant("Filter"),align:"Center"});for(var r=this.processToolbar("center"),n=0,a=r.length;n<a;n++)o.push(r[n]);return t&&(o.push({id:i.element.id+"_ok",prefixIcon:"e-icons e-check",cssClass:"top-icon e-tick",tooltipText:this.l10n.getConstant("OK"),align:"Right"}),o.push({id:i.element.id+"_cancel",prefixIcon:"e-icons e-close",cssClass:"top-icon e-save",tooltipText:this.l10n.getConstant("Cancel"),align:"Right"})),o},a.prototype.getZoomToolbarItem=function(){return[]},a.prototype.updateContextualToolbar=function(t,i){var o=this.parent,r=o.element.querySelector("#"+o.element.id+"_toolbarArea"),n=o.element.querySelector("#"+o.element.id+"_contextualToolbarArea");if(n.classList.remove("e-hide"),n.style.left=r.offsetLeft+"px","filter"===t?(document.getElementById(o.element.id+"_toolbar")&&this.defToolbarItems.length>0&&e.getComponent(document.getElementById(o.element.id+"_toolbar"),"toolbar").destroy(),e.Browser.isDevice?this.initMainToolbar(!1,!0,!0):this.initMainToolbar(!0,null,null),this.refreshSlider(),this.initFilterToolbarItem()):(document.querySelector("#"+o.element.id+"_contextualToolbar").classList.contains("e-control")&&e.getComponent(document.getElementById(o.element.id+"_contextualToolbar"),"toolbar").destroy(),this.refreshSlider(),this.renderSlider(i)),e.Browser.isDevice){var a=n.offsetHeight,s=o.element.querySelector("#"+o.element.id+"_canvasWrapper").offsetHeight;n.style.top=this.toolbarHeight+s-a+"px"}else n.style.top=this.toolbarHeight+"px"},a.prototype.processToolbar=function(t){var i=this.parent,o=[];if(i.toolbar)for(var r=0,n=i.toolbar.length;r<n;r++)"object"==typeof i.toolbar[r]&&(e.isNullOrUndefined(i.toolbar[r].align)?"left"===t&&o.push(this.parent.toolbar[r]):i.toolbar[r].align.toLowerCase()===t&&o.push(i.toolbar[r]));return o},a.prototype.processSubToolbar=function(t){var e=[];if(t)for(var i=0,o=t.length;i<o;i++)"object"==typeof t[i]&&(t[i].align="Center",e.push(t[i]));return e},a.prototype.wireZoomBtnEvents=function(){var t=document.querySelector("#"+this.parent.element.id+"_zoomIn"),i=document.querySelector("#"+this.parent.element.id+"_zoomOut");e.isNullOrUndefined(t)||(t.addEventListener("mousedown",this.zoomInBtnMouseDownHandler.bind(this)),t.addEventListener("mouseup",this.zoomBtnMouseUpHandler.bind(this)),t.addEventListener("click",this.zoomInBtnClickHandler.bind(this)),t.addEventListener("touchstart",this.zoomInBtnClickHandler.bind(this))),e.isNullOrUndefined(i)||(i.addEventListener("mousedown",this.zoomOutBtnMouseDownHandler.bind(this)),i.addEventListener("mouseup",this.zoomBtnMouseUpHandler.bind(this)),i.addEventListener("click",this.zoomOutBtnClickHandler.bind(this)),t.addEventListener("touchstart",this.zoomInBtnClickHandler.bind(this)))},a.prototype.enableDisableTbrBtn=function(){var t=this.parent;if(!this.preventEnableDisableUr){var i={appliedUndoRedoColl:[]};t.notify("undo-redo",{prop:"getAppliedUndoRedoColl",value:{obj:i}});var o={undoRedoStep:null};t.notify("undo-redo",{prop:"getUndoRedoStep",value:{obj:o}});var r=document.querySelector("#"+t.element.id+"_undo");e.isNullOrUndefined(r)||0!==o.undoRedoStep?!e.isNullOrUndefined(r)&&o.undoRedoStep>0&&(r.classList.remove("e-disabled"),r.parentElement.classList.remove("e-overlay")):(r.classList.add("e-disabled"),r.parentElement.classList.add("e-overlay"));var n=document.querySelector("#"+t.element.id+"_redo");e.isNullOrUndefined(n)||o.undoRedoStep!==i.appliedUndoRedoColl.length?!e.isNullOrUndefined(n)&&0===o.undoRedoStep&&i.appliedUndoRedoColl.length>0?(n.classList.remove("e-disabled"),n.parentElement.classList.remove("e-overlay")):!e.isNullOrUndefined(n)&&o.undoRedoStep>0&&(n.classList.remove("e-disabled"),n.parentElement.classList.remove("e-overlay")):(n.classList.add("e-disabled"),n.parentElement.classList.add("e-overlay"))}var a=document.querySelector("#"+t.element.id+"_zoomIn");!e.isNullOrUndefined(a)&&t.zoomSettings.zoomFactor>=t.zoomSettings.maxZoomFactor?(a.classList.add("e-disabled"),a.parentElement.classList.add("e-overlay")):e.isNullOrUndefined(a)||(a.classList.remove("e-disabled"),a.parentElement.classList.remove("e-overlay"));var s=document.querySelector("#"+t.element.id+"_zoomOut");!e.isNullOrUndefined(s)&&t.zoomSettings.zoomFactor<=t.zoomSettings.minZoomFactor?(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 l=document.querySelector("#"+t.element.id+"_pan");!e.isNullOrUndefined(l)&&t.zoomSettings.zoomFactor<=t.zoomSettings.minZoomFactor?l.style.display="none":e.isNullOrUndefined(l)||(l.style.display="block")},a.prototype.createLeftToolbarControls=function(){var t=this.parent;if(void 0!==this.defToolbarItems&&this.defToolbarItems.length>0&&!e.isNullOrUndefined(document.getElementById(t.element.id+"_toolbar"))){var i=document.getElementById(t.element.id+"_toolbar").querySelector(".e-image-upload");if(i){var o=i.getElementsByTagName("input")[0],r=i.getElementsByTagName("button")[0];r.className="e-tbar-btn e-tbtn-txt top-icon",r.innerHTML="",r.appendChild(t.createElement("span",{className:"e-btn-icon e-icons e-upload-icon e-icon-left"})),o.onchange=this.fileSelect.bind(this,o)}}},a.prototype.fileSelect=function(t,e){this.parent.notify("draw",{prop:"fileSelect",value:{inputElement:t,args:e}})},a.prototype.renderAnnotationBtn=function(t){var i=this,o=this.parent,n=[];(e.isNullOrUndefined(o.toolbar)||!e.isNullOrUndefined(o.toolbar)&&o.toolbar.indexOf("Pen")>-1)&&n.push({text:this.l10n.getConstant("Pen"),id:"pen",iconCss:"e-icons e-free-pen"}),(e.isNullOrUndefined(o.toolbar)||!e.isNullOrUndefined(this.parent.toolbar)&&o.toolbar.indexOf("Line")>-1)&&n.push({text:this.l10n.getConstant("Line"),id:"line",iconCss:"e-icons e-line"}),(e.isNullOrUndefined(o.toolbar)||!e.isNullOrUndefined(o.toolbar)&&o.toolbar.indexOf("Rectangle")>-1)&&n.push({text:this.l10n.getConstant("Rectangle"),id:"rectangle",iconCss:"e-icons e-rectangle"}),(e.isNullOrUndefined(o.toolbar)||!e.isNullOrUndefined(o.toolbar)&&o.toolbar.indexOf("Ellipse")>-1)&&n.push({text:this.l10n.getConstant("Ellipse"),id:"ellipse",iconCss:"e-icons e-circle"}),(e.isNullOrUndefined(o.toolbar)||!e.isNullOrUndefined(toolbar)&&o.toolbar.indexOf("Arrow")>-1)&&n.push({text:this.l10n.getConstant("Arrow"),id:"arrow",iconCss:"e-icons e-arrow-right-up"}),(e.isNullOrUndefined(o.toolbar)||!e.isNullOrUndefined(o.toolbar)&&o.toolbar.indexOf("Path")>-1)&&n.push({text:this.l10n.getConstant("Path"),id:"path",iconCss:"e-icons e-critical-path"}),(e.isNullOrUndefined(o.toolbar)||!e.isNullOrUndefined(o.toolbar)&&o.toolbar.indexOf("Text")>-1)&&n.push({text:this.l10n.getConstant("Text"),id:"text",iconCss:"e-icons e-add-text"});var a={freehandDrawSelectedId:null};o.notify("freehand-draw",{prop:"getFreehandDrawSelectedId",onPropertyChange:!1,value:{obj:a}});var s=document.querySelector("#"+o.element.id+"_duplicate"),l=document.querySelector("#"+o.element.id+"_remove"),p=document.querySelector("#"+o.element.id+"_editText");0===o.activeObj.activePoint.width&&0===o.activeObj.activePoint.height&&(e.isNullOrUndefined(o.activeObj.pointColl)||!e.isNullOrUndefined(o.activeObj.pointColl)&&0===o.activeObj.pointColl.length)&&e.isNullOrUndefined(a.freehandDrawSelectedId)?(s&&s.classList.add("e-disabled"),l&&l.classList.add("e-disabled"),p&&p.classList.add("e-disabled")):(s&&s.classList.remove("e-disabled"),l&&l.classList.remove("e-disabled"),p&&p.classList.remove("e-disabled"));var h=t?this.getCurrentShapeIcon(o.activeObj.shape):"e-annotation",c=new r.DropDownButton({items:n,iconCss:"e-icons "+h,cssClass:"e-image-popup",open:function(t){e.Browser.isDevice&&(t.element.parentElement.style.top=c.element.getBoundingClientRect().top-t.element.parentElement.offsetHeight+"px"),e.isNullOrUndefined(i.parent.activeObj.shape)?i.parent.togglePen&&document.getElementById("pen").classList.add("e-selected"):document.getElementById(i.parent.activeObj.shape).classList.add("e-selected")},select:function(t){o.okBtn();var e,r=!1;void 0!==o.activeObj.shape&&(e=o.activeObj.shape.split("-")),void 0===e&&o.currObjType.isCustomCrop?r=!0:void 0!==e&&"crop"===e[0]&&(r=!0),o.currObjType.isCustomCrop=!1,(r||o.togglePan)&&(o.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),i.upperContext.clearRect(0,0,o.upperCanvas.width,o.upperCanvas.height),i.refreshToolbar("main"));var n={currentFreehandDrawIndex:null};switch(o.notify("freehand-draw",{prop:"getCurrentFreehandDrawIndex",value:{obj:n}}),c.iconCss="e-icons "+i.getCurrentShapeIcon(t.item.id),t.item.id){case"pen":o.notify("draw",{prop:"setTempFreehandCounter",value:{tempFreehandCounter:o.freehandCounter}}),o.notify("draw",{prop:"setTempCurrentFreehandDrawIndex",value:{tempCurrentFreehandDrawIndex:n.currentFreehandDrawIndex}}),i.currentToolbar="pen",o.freeHandDraw(!0);break;case"text":i.currentToolbar="text",o.notify("shape",{prop:"draw-shape-text"});break;default:i.currentToolbar="shapes",i.setInitialShapeSettings(t),o.notify("selection",{prop:"annotate",value:{shape:t.item.id}}),o.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"shapes",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}})}i.updateToolbarItems()}});c.appendTo("#"+this.parent.element.id+"_annotationBtn")},a.prototype.renderCropBtn=function(){var t=this,i=this.parent,o=[];(e.isNullOrUndefined(i.toolbar)||!e.isNullOrUndefined(i.toolbar)&&i.toolbar.indexOf("CustomSelection")>-1)&&o.push({text:this.l10n.getConstant("Custom"),id:"custom",iconCss:"e-icons e-custom"}),(e.isNullOrUndefined(i.toolbar)||!e.isNullOrUndefined(i.toolbar)&&i.toolbar.indexOf("CircleSelection")>-1)&&o.push({text:this.l10n.getConstant("Circle"),id:"circle",iconCss:"e-icons e-circle"}),(e.isNullOrUndefined(i.toolbar)||!e.isNullOrUndefined(i.toolbar)&&i.toolbar.indexOf("SquareSelection")>-1)&&o.push({text:this.l10n.getConstant("Square"),id:"square",iconCss:"e-icons e-square"}),(e.isNullOrUndefined(i.toolbar)||!e.isNullOrUndefined(i.toolbar)&&i.toolbar.indexOf("RatioSelection")>-1)&&(o.push({text:"3:2",id:"3:2",iconCss:"e-icons e-custom-a"}),o.push({text:"4:3",id:"4:3",iconCss:"e-icons e-custom-b"}),o.push({text:"5:4",id:"5:4",iconCss:"e-icons e-custom-c"}),o.push({text:"7:5",id:"7:5",iconCss:"e-icons e-custom-d"}),o.push({text:"16:9",id:"16:9",iconCss:"e-icons e-custom-e"}));var n,a;e.isNullOrUndefined(i.activeObj.shape)?e.isNullOrUndefined(i.currSelectionPoint)?(n="e-custom",a="custom"):(n=this.getCurrentShapeIcon(i.currSelectionPoint.shape),a=i.currSelectionPoint.shape):(n=this.getCurrentShapeIcon(i.activeObj.shape),a=i.activeObj.shape);var s=new r.DropDownButton({open:function(o){i.togglePan&&t.cancelPan(),e.Browser.isDevice&&(o.element.parentElement.style.top=s.element.getBoundingClientRect().top-o.element.parentElement.offsetHeight+"px"),!e.isNullOrUndefined(t.parent.activeObj.shape)&&t.parent.activeObj.shape.split("-").length>1&&document.getElementById(t.parent.activeObj.shape.split("-")[1]).classList.add("e-selected"),i.notify("transform",{prop:"disableZoomOutBtn",value:{isZoomOut:!0}})},items:o,select:function(e){t.cropSelect(e),s.iconCss="e-icons "+t.getCurrentShapeIcon("crop-"+e.item.id),s.content=i.toPascalCase(e.item.id)},iconCss:"e-icons "+n,cssClass:"e-image-popup",content:i.toPascalCase(a.replace("crop-",""))});s.appendTo("#"+this.parent.element.id+"_cropBtn")},a.prototype.renderTransformBtn=function(){var t=this.parent,i=[];(e.isNullOrUndefined(t.toolbar)||!e.isNullOrUndefined(t.toolbar)&&t.toolbar.indexOf("RotateLeft")>-1)&&i.push({text:this.l10n.getConstant("RotateLeft"),id:"rotateleft",iconCss:"e-icons e-anti-clock-wise"}),(e.isNullOrUndefined(t.toolbar)||!e.isNullOrUndefined(t.toolbar)&&t.toolbar.indexOf("RotateRight")>-1)&&i.push({text:this.l10n.getConstant("RotateRight"),id:"rotateright",iconCss:"e-icons e-clock-wise"}),(e.isNullOrUndefined(t.toolbar)||!e.isNullOrUndefined(t.toolbar)&&t.toolbar.indexOf("FlipHorizontal")>-1)&&i.push({text:this.l10n.getConstant("HorizontalFlip"),id:"horizontalflip",iconCss:"e-icons e-horizontal-flip"}),(e.isNullOrUndefined(t.toolbar)||!e.isNullOrUndefined(t.toolbar)&&t.toolbar.indexOf("FlipVertical")>-1)&&i.push({text:this.l10n.getConstant("VerticalFlip"),id:"verticalflip",iconCss:"e-icons e-vertical-flip"});var o=new r.DropDownButton({open:function(t){if(e.Browser.isDevice){var i=t.element.parentElement.offsetHeight;t.element.parentElement.style.display="none",t.element.parentElement.style.top=o.element.getBoundingClientRect().top-i+"px",t.element.parentElement.style.display="block"}},items:i,select:this.parent.transformSelect.bind(this),iconCss:"e-icons e-transform",cssClass:"e-image-popup"});o.appendTo("#"+t.element.id+"_transformBtn")},a.prototype.renderSaveBtn=function(){var t=this.parent;if(document.getElementById(this.parent.element.id+"_saveBtn")){new r.DropDownButton({items:[{text:"JPEG",id:"jpeg"},{text:"PNG",id:"png"},{text:"SVG",id:"svg"}],cssClass:"e-caret-hide e-image-popup",iconCss:"e-icons e-save",select:function(e){t.export(e.item.text)}}).appendTo("#"+this.parent.element.id+"_saveBtn")}},a.prototype.getCropTransformToolbarItem=function(){var t=this.parent,i=[];return i.push({id:t.element.id+"_crop",tooltipText:this.l10n.getConstant("CropSelection"),align:"Center",template:'<button id="'+t.element.id+'_cropBtn"></button>'}),i.push({align:"Center",type:"Separator"}),i.push({id:this.parent.element.id+"_rotateLeft",prefixIcon:"e-icons e-anti-clock-wise",tooltipText:this.l10n.getConstant("RotateLeft"),align:"Center"}),i.push({id:this.parent.element.id+"_rotateRight",prefixIcon:"e-icons e-clock-wise",tooltipText:this.l10n.getConstant("RotateRight"),align:"Center"}),i.push({align:"Center",type:"Separator"}),i.push({id:this.parent.element.id+"_horizontalFlip",prefixIcon:"e-icons e-horizontal-flip",tooltipText:this.l10n.getConstant("HorizontalFlip"),align:"Center"}),i.push({id:this.parent.element.id+"_verticalFlip",prefixIcon:"e-icons e-vertical-flip",tooltipText:this.l10n.getConstant("VerticalFlip"),align:"Center"}),e.Browser.isDevice||(i.push({id:this.parent.element.id+"_ok",prefixIcon:"e-icons e-check",cssClass:"top-icon e-tick",tooltipText:this.l10n.getConstant("OK"),align:"Right"}),i.push({id:this.parent.element.id+"_cancel",prefixIcon:"e-icons e-close",cssClass:"top-icon e-save",tooltipText:this.l10n.getConstant("Cancel"),align:"Right"})),i},a.prototype.getShapesToolbarItem=function(t){var i=this.parent,o=[];!e.isNullOrUndefined(i.toolbar)&&e.isNullOrUndefined(i.toolbar)||o.push({id:i.element.id+"_annotation",tooltipText:this.l10n.getConstant("Annotation"),align:"Center",template:'<button id="'+this.parent.element.id+'_annotationBtn"></button>'}),t.indexOf("fillColor")>-1&&o.push({prefixIcon:"e-icons e-copy",id:this.parent.element.id+"_fillcolor",cssClass:"top-icon e-fill",tooltipText:this.l10n.getConstant("FillColor"),align:"Center",type:"Input",template:'<button id="'+this.parent.element.id+'_fillColorBtn"></button>'}),t.indexOf("strokeColor")>-1&&o.push({prefixIcon:"e-icons e-copy",id:this.parent.element.id+"_strokecolor",cssClass:"top-icon e-stroke",tooltipText:this.l10n.getConstant("StrokeColor"),align:"Center",type:"Input",template:'<button id="'+this.parent.element.id+'_borderColorBtn"></button>'}),t.indexOf("strokeWidth")>-1&&o.push({id:this.parent.element.id+"_strokeWidth",cssClass:"top-icon e-size",tooltipText:"Stroke Width",align:"Center",type:"Input",template:'<button id="'+this.parent.element.id+'_borderWidthBtn"></button>'}),t.indexOf("start")>-1&&o.push({id:this.parent.element.id+"_start",cssClass:"top-icon e-size",tooltipText:"Start",align:"Center",type:"Input",template:'<button id="'+this.parent.element.id+'_startBtn"></button>'}),t.indexOf("end")>-1&&o.push({id:this.parent.element.id+"_end",cssClass:"top-icon e-size",tooltipText:"End",align:"Center",type:"Input",template:'<button id="'+this.parent.element.id+'_endBtn"></button>'}),o.push({align:"Center",type:"Separator"}),t.indexOf("duplicate")>-1&&o.push({id:i.element.id+"_duplicate",prefixIcon:"e-icons e-order",cssClass:"top-icon e-order",tooltipText:this.l10n.getConstant("Duplicate"),align:"Center"}),t.indexOf("remove")>-1&&o.push({id:i.element.id+"_remove",prefixIcon:"e-icons e-trash",cssClass:"top-icon e-trash",tooltipText:this.l10n.getConstant("Remove"),align:"Center"}),t.indexOf("text")>-1&&o.push({id:i.element.id+"_editText",prefixIcon:"e-icons e-annotation-edit",cssClass:"top-icon e-annotation-edit",tooltipText:this.l10n.getConstant("EditText"),align:"Center"});for(var r=this.processSubToolbar(t),n=0,a=r.length;n<a;n++)o.push(r[n]);if(!e.Browser.isDevice){var s={shape:null};i.notify("selection",{prop:"getCurrentDrawingShape",value:{obj:s}}),"path"!==s.shape&&(o.push({id:this.parent.element.id+"_ok",prefixIcon:"e-icons e-check",cssClass:"top-icon e-tick",tooltipText:this.l10n.getConstant("OK"),align:"Right"}),o.push({id:this.parent.element.id+"_cancel",prefixIcon:"e-icons e-close",cssClass:"top-icon e-save",tooltipText:this.l10n.getConstant("Cancel"),align:"Right"}))}return o},a.prototype.initCropTransformToolbar=function(){var t=this,i=this.getLeftToolbarItem(),r=this.getRightToolbarItem(),n=this.getCropTransformToolbarItem(),a=this.getZoomToolbarItem();e.Browser.isDevice?this.defToolbarItems=n:this.defToolbarItems=i.concat(a,n,r);var s=new o.Toolbar({width:"100%",items:this.defToolbarItems,clicked:this.defToolbarClicked.bind(this),created:function(){t.renderCropBtn(),t.wireZoomBtnEvents(),e.Browser.isDevice||t.renderSaveBtn(),t.parent.trigger("toolbarCreated",{toolbarType:"shapes"}),e.Browser.isDevice?t.defToolbarItems.length>0&&!e.isNullOrUndefined(document.getElementById(t.parent.element.id+"_bottomToolbar"))&&(s.refreshOverflow(),s.refreshOverflow(),s.refreshOverflow()):(t.createLeftToolbarControls(),t.defToolbarItems.length>0&&!e.isNullOrUndefined(document.getElementById(t.parent.element.id+"_toolbar"))&&s.refreshOverflow()),t.parent.select("custom")}});e.Browser.isDevice?s.appendTo("#"+this.parent.element.id+"_bottomToolbar"):s.appendTo("#"+this.parent.element.id+"_toolbar"),this.enableDisableTbrBtn(),this.parent.notify("transform",{prop:"disableZoomOutBtn",value:{isZoomOut:!0}})},a.prototype.getCurrentShapeIcon=function(t){var e="";switch(t){case"rectangle":e="e-rectangle";break;case"ellipse":e="e-circle";break;case"triangle":e="e-triangle";break;case"line":e="e-line";break;case"arrow":e="e-arrow-right-up";break;case"path":e="e-critical-path";break;case"text":e="e-add-text";break;case"pen":e="e-free-pen";break;case"crop-custom":e="e-custom";break;case"crop-circle":e="e-circle";break;case"crop-square":e="e-square";break;case"crop-3:2":e="e-custom-a";break;case"crop-4:3":e="e-custom-b";break;case"crop-5:4":e="e-custom-c";break;case"crop-7:5":e="e-custom-d";break;case"crop-16:9":e="e-custom-e";break;default:e="e-free-pen"}return e},a.prototype.initShapesToolbarItem=function(t){var i=this,r=this.getLeftToolbarItem(),n=this.getRightToolbarItem(),a=this.getShapesToolbarItem(t),s=this.getZoomToolbarItem();e.Browser.isDevice?this.defToolbarItems=a:this.defToolbarItems=r.concat(s,a,n);var l=new o.Toolbar({width:"100%",items:this.defToolbarItems,clicked:this.defToolbarClicked.bind(this),created:function(){i.renderAnnotationBtn(!0),i.createShapeColor(t),i.createShapeBtn(t),"arrow"===i.parent.activeObj.shape&&(i.createStartBtn(),i.createEndBtn()),i.wireZoomBtnEvents(),e.Browser.isDevice||i.renderSaveBtn(),i.parent.trigger("toolbarCreated",{toolbarType:"shapes"}),e.Browser.isDevice?i.defToolbarItems.length>0&&!e.isNullOrUndefined(document.getElementById(i.parent.element.id+"_bottomToolbar"))&&(l.refreshOverflow(),l.refreshOverflow(),l.refreshOverflow()):(i.createLeftToolbarControls(),i.defToolbarItems.length>0&&!e.isNullOrUndefined(document.getElementById(i.parent.element.id+"_toolbar"))&&l.refreshOverflow())}});e.Browser.isDevice?l.appendTo("#"+this.parent.element.id+"_bottomToolbar"):l.appendTo("#"+this.parent.element.id+"_toolbar"),this.enableDisableTbrBtn()},a.prototype.createShapeColor=function(t){var i=this,o=this.parent;if(t.indexOf("fillColor")>-1){o.element.querySelector(".e-template.e-fill").appendChild(o.createElement("input",{id:o.element.id+"_shape_fill"}));var a=new n.ColorPicker({modeSwitcher:!1,noColor:!0,value:"",showButtons:!1,mode:"Palette",cssClass:"e-shape-fill-color",change:function(t){i.parent.updateFillColor(t.currentValue.hex),""===t.currentValue.rgba?s.element.children[0].classList.add("e-nocolor-item"):(s.element.children[0].classList.remove("e-nocolor-item"),s.element.children[0].style.backgroundColor=t.currentValue.rgba),s.toggle()}},"#"+o.element.id+"_shape_fill"),s=new r.DropDownButton({open:function(t){e.Browser.isDevice&&(t.element.parentElement.style.top=s.element.getBoundingClientRect().top-t.element.parentElement.offsetHeight+"px",t.element.parentElement.style.left=o.element.offsetLeft+"px")},target:".e-shape-fill-color",iconCss:"e-dropdownbtn-preview"},"#"+this.parent.element.id+"_fillColorBtn");a.inline=!0,o.element.querySelector(".e-fill.e-template .e-dropdownbtn-preview").classList.add("e-nocolor-item")}if(t.indexOf("strokeColor")>-1){o.element.querySelector(".e-template.e-stroke").appendChild(o.createElement("input",{id:o.element.id+"_shape_stroke"}));var l=new n.ColorPicker({modeSwitcher:!1,noColor:!1,value:"#fff",showButtons:!1,mode:"Palette",cssClass:"e-shape-stroke-color",change:function(t){i.parent.updateStrokeColor(t.currentValue.hex),p.element.children[0].style.backgroundColor=t.currentValue.rgba,p.toggle()}},"#"+o.element.id+"_shape_stroke"),p=new r.DropDownButton({open:function(t){e.Browser.isDevice&&(t.element.parentElement.style.top=p.element.getBoundingClientRect().top-t.element.parentElement.offsetHeight+"px",t.element.parentElement.style.left=i.parent.element.offsetLeft+"px")},target:".e-shape-stroke-color",iconCss:"e-dropdownbtn-preview"},"#"+o.element.id+"_borderColorBtn");l.inline=!0,o.element.querySelector(".e-stroke.e-template .e-dropdownbtn-preview").style.background="#fff"}},a.prototype.createShapeBtn=function(t){var i=this,o=this.parent,n=[{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(o.element.id+"_borderWidthBtn"),s=document.createElement("span");s.innerHTML=this.l10n.getConstant("XSmall"),s.className="e-shape-stroke-width",a.appendChild(s);var l=new r.DropDownButton({items:n,open:function(t){e.Browser.isDevice&&(t.element.parentElement.style.top=l.element.getBoundingClientRect().top-t.element.parentElement.offsetHeight+"px");var i=s.innerHTML;""!==i&&t.element.querySelector('[aria-label = "'+i+'"]').classList.add("e-selected-btn")},select:function(t){if(s.textContent=t.item.text,i.parent.updateStrokeWidth(t.item.id),e.Browser.isDevice){if(!e.isNullOrUndefined(document.getElementById(i.parent.element.id+"_bottomToolbar"))){e.getComponent(i.parent.element.id+"_bottomToolbar","toolbar").refreshOverflow()}}else if(!e.isNullOrUndefined(document.getElementById(i.parent.element.id+"_toolbar"))){e.getComponent(i.parent.element.id+"_toolbar","toolbar").refreshOverflow()}}});l.appendTo("#"+o.element.id+"_borderWidthBtn")}},a.prototype.createStartBtn=function(){var t=this.parent,i=[{id:"1",text:this.l10n.getConstant("None")},{id:"2",text:this.l10n.getConstant("Bar")},{id:"3",text:this.l10n.getConstant("Arrow")},{id:"4",text:this.l10n.getConstant("ArrowSolid")},{id:"5",text:this.l10n.getConstant("Circle")},{id:"6",text:this.l10n.getConstant("CircleSolid")},{id:"7",text:this.l10n.getConstant("Square")},{id:"8",text:this.l10n.getConstant("SquareSolid")}],o=document.getElementById(t.element.id+"_startBtn"),n=document.createElement("span");e.isNullOrUndefined(this.parent.activeObj.start)&&(this.parent.activeObj.start="none"),n.innerHTML=this.parent.pascalToSplitWords(this.parent.activeObj.start),n.className="e-shape-start",o.appendChild(n);var a=new r.DropDownButton({items:i,open:function(t){e.Browser.isDevice&&(t.element.parentElement.style.top=a.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(e){n.textContent=e.item.text,t.updateArrow("startArrow",e.item.id)}});a.appendTo("#"+t.element.id+"_startBtn")},a.prototype.createEndBtn=function(){var t=this.parent,i=[{id:"1",text:this.l10n.getConstant("None")},{id:"2",text:this.l10n.getConstant("Bar")},{id:"3",text:this.l10n.getConstant("Arrow")},{id:"4",text:this.l10n.getConstant("ArrowSolid")},{id:"5",text:this.l10n.getConstant("Circle")},{id:"6",text:this.l10n.getConstant("CircleSolid")},{id:"7",text:this.l10n.getConstant("Square")},{id:"8",text:this.l10n.getConstant("SquareSolid")}],o=document.getElementById(t.element.id+"_endBtn"),n=document.createElement("span");e.isNullOrUndefined(this.parent.activeObj.end)&&(this.parent.activeObj.end="arrowSolid"),n.innerHTML=this.parent.pascalToSplitWords(this.parent.activeObj.end),n.className="e-shape-end",o.appendChild(n);var a=new r.DropDownButton({items:i,open:function(t){e.Browser.isDevice&&(t.element.parentElement.style.top=a.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(e){n.textContent=e.item.text,t.updateArrow("endArrow",e.item.id)}});a.appendTo("#"+t.element.id+"_endBtn")},a.prototype.getTextToolbarItem=function(t){var i=this.parent,o=[];!e.isNullOrUndefined(i.toolbar)&&e.isNullOrUndefined(i.toolbar)||o.push({id:i.element.id+"_annotation",tooltipText:this.l10n.getConstant("Annotation"),align:"Center",template:'<button id="'+this.parent.element.id+'_annotationBtn"></button>'}),t.indexOf("fontFamily")>-1&&o.push({id:i.element.id+"_fontFamily",cssClass:"top-icon e-img-font-family",tooltipText:this.l10n.getConstant("FontFamily"),align:"Center",template:'<button id="'+i.element.id+'_fontFamilyBtn"></button>'}),t.indexOf("fontSize")>-1&&o.push({id:i.element.id+"_fontSize",cssClass:"top-icon e-img-font-size",tooltipText:this.l10n.getConstant("FontSize"),align:"Center",template:'<button id="'+i.element.id+'_fontSizeBtn"></button>'}),t.indexOf("fontColor")>-1&&o.push({cssClass:"top-icon e-text-font-color",id:i.element.id+"_text_strokecolor",tooltipText:this.l10n.getConstant("FontColor"),align:"Center",type:"Input",template:'<button id="'+i.element.id+'_fontColorBtn"></button>'}),t.indexOf("bold")>-1&&o.push({id:i.element.id+"_bold",prefixIcon:"e-icons e-bold",cssClass:"top-icon e-bold",tooltipText:this.l10n.getConstant("Bold"),align:"Center"}),t.indexOf("italic")>-1&&o.push({id:i.element.id+"_italic",prefixIcon:"e-icons e-italic",cssClass:"top-icon e-italic",tooltipText:this.l10n.getConstant("Italic"),align:"Center"}),o.push({align:"Center",type:"Separator"}),t.indexOf("duplicate")>-1&&o.push({id:i.element.id+"_duplicate",prefixIcon:"e-icons e-order",cssClass:"top-icon e-order",tooltipText:this.l10n.getConstant("Duplicate"),align:"Center"}),t.indexOf("remove")>-1&&o.push({id:i.element.id+"_remove",prefixIcon:"e-icons e-trash",cssClass:"top-icon e-trash",tooltipText:this.l10n.getConstant("Remove"),align:"Center"}),t.indexOf("text")>-1&&o.push({id:i.element.id+"_editText",prefixIcon:"e-icons e-annotation-edit",cssClass:"top-icon e-annotation-edit",tooltipText:this.l10n.getConstant("EditText"),align:"Center"});for(var r=this.processSubToolbar(t),n=0,a=r.length;n<a;n++)o.push(r[n]);return e.Browser.isDevice||(o.push({id:i.element.id+"_ok",prefixIcon:"e-icons e-check",cssClass:"top-icon e-tick",tooltipText:this.l10n.getConstant("OK"),align:"Right"}),o.push({id:i.element.id+"_cancel",prefixIcon:"e-icons e-close",cssClass:"top-icon e-save",tooltipText:this.l10n.getConstant("Cancel"),align:"Right"})),o},a.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"}]},a.prototype.initTextToolbarItem=function(t){var i=this,r=this.parent,n=this.getLeftToolbarItem(),a=this.getRightToolbarItem(),s=this.getTextToolbarItem(t),l=this.getZoomToolbarItem();e.Browser.isDevice?this.defToolbarItems=s:this.defToolbarItems=n.concat(l,s,a);var p=new o.Toolbar({width:"100%",items:this.defToolbarItems,clicked:this.defToolbarClicked.bind(this),created:function(){i.renderAnnotationBtn(!0),i.createTextColor(t),i.createTextBtn(t),i.wireZoomBtnEvents(),e.Browser.isDevice||i.renderSaveBtn(),r.trigger("toolbarCreated",{toolbarType:"text"}),e.Browser.isDevice?i.defToolbarItems.length>0&&!e.isNullOrUndefined(document.getElementById(r.element.id+"_bottomToolbar"))&&(p.refreshOverflow(),p.refreshOverflow(),p.refreshOverflow()):(i.createLeftToolbarControls(),i.defToolbarItems.length>0&&!e.isNullOrUndefined(document.getElementById(r.element.id+"_toolbar"))&&p.refreshOverflow())}});e.Browser.isDevice?p.appendTo("#"+r.element.id+"_bottomToolbar"):p.appendTo("#"+r.element.id+"_toolbar"),this.enableDisableTbrBtn()},a.prototype.createTextColor=function(t){var i=this,o=this.parent;if(t.indexOf("fontColor")>-1&&!e.isNullOrUndefined(o.element.querySelector(".e-template.e-text-font-color"))){o.element.querySelector(".e-template.e-text-font-color").appendChild(o.createElement("input",{id:o.element.id+"_text_font"}));var a=new n.ColorPicker({modeSwitcher:!1,value:"#fff",showButtons:!1,mode:"Palette",cssClass:"e-text-fontt-color",change:function(t){i.parent.updateFontColor(t.currentValue.hex),s.element.children[0].style.backgroundColor=t.currentValue.rgba,s.toggle()}},"#"+o.element.id+"_text_font"),s=new r.DropDownButton({open:function(t){e.Browser.isDevice&&(t.element.parentElement.style.top=s.element.getBoundingClientRect().top-t.element.parentElement.offsetHeight+"px",t.element.parentElement.style.left=o.element.offsetLeft+"px")},target:".e-text-fontt-color",iconCss:"e-dropdownbtn-preview"},"#"+o.element.id+"_fontColorBtn");a.inline=!0,o.element.querySelector(".e-text-font-color.e-template .e-dropdownbtn-preview").style.background="#fff"}},a.prototype.createTextBtn=function(t){var i=this.parent;if(t.indexOf("fontFamily")>-1){var o=document.getElementById(i.element.id+"_fontFamilyBtn"),n=document.createElement("span");e.Browser.isDevice?(n.innerHTML="ABC",n.setAttribute("style","font-family: arial")):n.innerHTML="Arial",n.className="e-text-font-family",e.isNullOrUndefined(o)||o.appendChild(n);var a=new r.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=a.element.getBoundingClientRect().top-t.element.parentElement.offsetHeight+"px");var o;o="block"===i.textArea.style.display?i.textArea.style.fontFamily:i.activeObj.textSettings.fontFamily,t.element.querySelector('[id *= "'+o.toLowerCase()+'"]').classList.add("e-selected-btn")},select:function(t){n.textContent=t.item.text,e.Browser.isDevice&&n.setAttribute("style","font-family:"+t.item.id),i.updateFontFamily(t.item.id)}});a.appendTo("#"+i.element.id+"_fontFamilyBtn")}if(t.indexOf("fontSize")>-1){var s=document.getElementById(i.element.id+"_fontSizeBtn"),l=document.createElement("span"),p=i.getFontSizes();l.innerHTML=p[0].text,l.className="e-text-font-size",s.appendChild(l);var h=new r.DropDownButton({cssClass:"e-font-size",items:p,open:function(t){e.Browser.isDevice&&(t.element.parentElement.style.top=h.element.getBoundingClientRect().top-t.element.parentElement.offsetHeight+"px");var i=l.innerHTML;t.element.querySelector('[aria-label *= "'+i+'"]').classList.add("e-selected-btn")},select:function(t){l.textContent=t.item.text,i.updateFontSize(t.item.text)}});h.appendTo("#"+i.element.id+"_fontSizeBtn")}},a.prototype.refreshToolbar=function(t,i,o,r,n){if(this.parent.isImageLoaded&&!this.parent.isCropToolbar){var a={toolbarType:t};switch("filter"!==t&&"color"!==t&&(document.getElementById(this.parent.element.id+"_toolbar")&&this.defToolbarItems.length>0&&(e.getComponent(document.getElementById(this.parent.element.id+"_toolbar"),"toolbar").destroy(),document.getElementById(this.parent.element.id+"_toolbar").innerHTML=""),document.getElementById(this.parent.element.id+"_bottomToolbar")&&this.defToolbarItems.length>0&&document.getElementById(this.parent.element.id+"_bottomToolbar").className.indexOf("e-control")>-1&&(e.getComponent(document.getElementById(this.parent.element.id+"_bottomToolbar"),"toolbar").destroy(),document.getElementById(this.parent.element.id+"_bottomToolbar").innerHTML="")),this.refreshSlider(),this.parent.isCropTab=!1,t){case"main":e.Browser.isDevice?o?this.initMainToolbar(!1,!0,!0):this.initMainToolbar(!1,!0,null):e.Browser.isDevice&&!r||this.initMainToolbar(i,e.Browser.isDevice,null),e.Browser.isDevice&&this.initBottomToolbar();break;case"shapes":e.Browser.isDevice&&this.initMainToolbar(!1,!0,!0),"line"===this.parent.activeObj.shape||"path"===this.parent.activeObj.shape?a.toolbarItems=["strokeColor","strokeWidth","duplicate","remove"]:"arrow"===this.parent.activeObj.shape?a.toolbarItems=["strokeColor","strokeWidth","start","end","duplicate","remove"]:a.toolbarItems=["fillColor","strokeColor","strokeWidth","duplicate","remove"],this.parent.trigger("toolbarUpdating",a),this.initShapesToolbarItem(a.toolbarItems);break;case"text":e.Browser.isDevice&&this.initMainToolbar(!1,!0,!0),a.toolbarItems=["fontFamily","fontSize","fontColor","bold","italic","duplicate","remove","text"],this.parent.trigger("toolbarUpdating",a),this.initTextToolbarItem(a.toolbarItems);break;case"pen":e.Browser.isDevice&&this.initMainToolbar(!1,!0,!0),a.toolbarItems=["strokeColor","strokeWidth","remove"],this.parent.trigger("toolbarUpdating",a),this.initPenToolbarItem(a.toolbarItems);break;case"adjustment":e.Browser.isDevice&&this.initMainToolbar(!1,!0,!0),this.initAdjustmentToolbarItem();break;case"filter":this.updateContextualToolbar(t);break;case"color":this.updateContextualToolbar(t,n);break;case"croptransform":this.parent.isCropTab=!0,e.Browser.isDevice&&this.initMainToolbar(!1,!0,!0),this.parent.updateCropTransformItems(),this.initCropTransformToolbar()}this.currToolbar=t,this.refreshDropDownBtn(o)}},a.prototype.getAdjustmentToolbarItem=function(){var t=[];(e.isNullOrUndefined(this.parent.toolbar)||!e.isNullOrUndefined(this.parent.toolbar)&&this.parent.toolbar.indexOf("Brightness")>-1)&&t.push({id:this.parent.element.id+"_brightness",prefixIcon:"e-icons e-brightness",cssClass:"top-icon e-brightness",tooltipText:this.l10n.getConstant("Brightness"),align:"Center"}),(e.isNullOrUndefined(this.parent.toolbar)||!e.isNullOrUndefined(this.parent.toolbar)&&this.parent.toolbar.indexOf("Contrast")>-1)&&t.push({id:this.parent.element.id+"_contrast",prefixIcon:"e-icons e-contrast",cssClass:"top-icon e-contrast",tooltipText:this.l10n.getConstant("Contrast"),align:"Center"}),(e.isNullOrUndefined(this.parent.toolbar)||!e.isNullOrUndefined(this.parent.toolbar)&&this.parent.toolbar.indexOf("Hue")>-1)&&t.push({id:this.parent.element.id+"_hue",prefixIcon:"e-icons e-fade",cssClass:"top-icon e-fade",tooltipText:this.l10n.getConstant("Hue"),align:"Center"}),(e.isNullOrUndefined(this.parent.toolbar)||!e.isNullOrUndefined(this.parent.toolbar)&&this.parent.toolbar.indexOf("Saturation")>-1)&&t.push({id:this.parent.element.id+"_saturation",prefixIcon:"e-icons e-saturation",cssClass:"top-icon e-saturation",tooltipText:this.l10n.getConstant("Saturation"),align:"Center"}),(e.isNullOrUndefined(this.parent.toolbar)||!e.isNullOrUndefined(this.parent.toolbar)&&this.parent.toolbar.indexOf("Exposure")>-1)&&t.push({id:this.parent.element.id+"_exposure",prefixIcon:"e-icons e-grain",cssClass:"top-icon e-grain",tooltipText:this.l10n.getConstant("Exposure"),align:"Center"}),(e.isNullOrUndefined(this.parent.toolbar)||!e.isNullOrUndefined(this.parent.toolbar)&&this.parent.toolbar.indexOf("Opacity")>-1)&&t.push({id:this.parent.element.id+"_opacity",prefixIcon:"e-icons e-opacity",cssClass:"top-icon e-opacity",tooltipText:this.l10n.getConstant("Opacity"),align:"Center"}),(e.isNullOrUndefined(this.parent.toolbar)||!e.isNullOrUndefined(this.parent.toolbar)&&this.parent.toolbar.indexOf("Blur")>-1)&&t.push({id:this.parent.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"),o=0,r=i.length;o<r;o++)t.push(i[o]);return e.Browser.isDevice||(t.push({id:this.parent.element.id+"_ok",prefixIcon:"e-icons e-check",cssClass:"top-icon e-tick",tooltipText:this.l10n.getConstant("OK"),align:"Right"}),t.push({id:this.parent.element.id+"_cancel",prefixIcon:"e-icons e-close",cssClass:"top-icon e-save",tooltipText:this.l10n.getConstant("Cancel"),align:"Right"})),t},a.prototype.getFilterToolbarItem=function(){var t=[];(e.isNullOrUndefined(this.parent.toolbar)||!e.isNullOrUndefined(this.parent.toolbar)&&this.parent.toolbar.indexOf("Default")>-1)&&t.push({id:this.parent.element.id+"_default",prefixIcon:"e-icons e-none",cssClass:"top-icon e-none",tooltipText:this.l10n.getConstant("Default"),align:"Center",template:'<div class="filter-wrapper" style="box-sizing: content-box;"><canvas id='+this.parent.element.id+'_defaultCanvas></canvas><div style="text-align:center;"><span>'+this.l10n.getConstant("Default")+"</span></div></div>"}),(e.isNullOrUndefined(this.parent.toolbar)||!e.isNullOrUndefined(this.parent.toolbar)&&this.parent.toolbar.indexOf("Chrome")>-1)&&t.push({id:this.parent.element.id+"_chrome",prefixIcon:"e-icons e-none",cssClass:"top-icon e-none",tooltipText:this.l10n.getConstant("Chrome"),align:"Center",template:'<div class="filter-wrapper" style="box-sizing: content-box;"><canvas id='+this.parent.element.id+'_chromeCanvas></canvas><div style="text-align:center;"><span>'+this.l10n.getConstant("Chrome")+"</span></div></div>"}),(e.isNullOrUndefined(this.parent.toolbar)||!e.isNullOrUndefined(this.parent.toolbar)&&this.parent.toolbar.indexOf("Cold")>-1)&&t.push({id:this.parent.element.id+"_cold",prefixIcon:"e-icons e-none",cssClass:"top-icon e-none",tooltipText:this.l10n.getConstant("Cold"),align:"Center",template:'<div class="filter-wrapper" style="box-sizing: content-box;"><canvas id='+this.parent.element.id+'_coldCanvas></canvas><div style="text-align:center;"><span>'+this.l10n.getConstant("Cold")+"</span></div></div>"}),(e.isNullOrUndefined(this.parent.toolbar)||!e.isNullOrUndefined(this.parent.toolbar)&&this.parent.toolbar.indexOf("Warm")>-1)&&t.push({id:this.parent.element.id+"_warm",prefixIcon:"e-icons e-none",cssClass:"top-icon e-none",tooltipText:this.l10n.getConstant("Warm"),align:"Center",template:'<div class="filter-wrapper" style="box-sizing: content-box;"><canvas id='+this.parent.element.id+'_warmCanvas></canvas><div style="text-align:center;"><span>'+this.l10n.getConstant("Warm")+"</span></div></div>"}),(e.isNullOrUndefined(this.parent.toolbar)||!e.isNullOrUndefined(this.parent.toolbar)&&this.parent.toolbar.indexOf("Grayscale")>-1)&&t.push({id:this.parent.element.id+"_grayscale",prefixIcon:"e-icons e-none",cssClass:"top-icon e-none",tooltipText:this.l10n.getConstant("Grayscale"),align:"Center",template:'<div class="filter-wrapper" style="box-sizing: content-box;"><canvas id='+this.parent.element.id+'_grayscaleCanvas></canvas><div style="text-align:center;"><span>'+this.l10n.getConstant("Grayscale")+"</span></div></div>"}),(e.isNullOrUndefined(this.parent.toolbar)||!e.isNullOrUndefined(this.parent.toolbar)&&this.parent.toolbar.indexOf("Sepia")>-1)&&t.push({id:this.parent.element.id+"_sepia",prefixIcon:"e-icons e-none",cssClass:"top-icon e-none",tooltipText:this.l10n.getConstant("Sepia"),align:"Center",template:'<div class="filter-wrapper" style="box-sizing: content-box;"><canvas id='+this.parent.element.id+'_sepiaCanvas></canvas><div style="text-align:center;"><span>'+this.l10n.getConstant("Sepia")+"</span></div></div>"}),(e.isNullOrUndefined(this.parent.toolbar)||!e.isNullOrUndefined(this.parent.toolbar)&&this.parent.toolbar.indexOf("Invert")>-1)&&t.push({id:this.parent.element.id+"_invert",prefixIcon:"e-icons e-none",cssClass:"top-icon e-none",tooltipText:this.l10n.getConstant("Invert"),align:"Center",template:'<div class="filter-wrapper" style="box-sizing: content-box;"><canvas id='+this.parent.element.id+'_invertCanvas></canvas><div style="text-align:center;"><span>'+this.l10n.getConstant("Invert")+"</span></div></div>"});for(var i=this.processToolbar("center"),o=0,r=i.length;o<r;o++)t.push(i[o]);return t},a.prototype.getPenToolbarItem=function(t){var i=this.parent,o=[];!e.isNullOrUndefined(i.toolbar)&&e.isNullOrUndefined(i.toolbar)||o.push({id:i.element.id+"_annotation",tooltipText:this.l10n.getConstant("Annotation"),align:"Center",template:'<button id="'+this.parent.element.id+'_annotationBtn"></button>'}),t.indexOf("strokeColor")>-1&&o.push({prefixIcon:"e-icons e-copy",id:this.parent.element.id+"_pen_strokecolor",cssClass:"top-icon e-pen-stroke-color",tooltipText:this.l10n.getConstant("StrokeColor"),align:"Center",type:"Input",template:'<button id="'+this.parent.element.id+'_penColorBtn"></button>'}),t.indexOf("strokeWidth")>-1&&o.push({prefixIcon:"e-icons e-copy",cssClass:"top-icon e-size",tooltipText:this.l10n.getConstant("StrokeWidth"),align:"Center",type:"Input",template:'<button id="'+this.parent.element.id+'_penStrokeWidth"></button>'}),o.push({align:"Center",type:"Separator"}),t.indexOf("remove")>-1&&o.push({id:i.element.id+"_remove",prefixIcon:"e-icons e-trash",cssClass:"top-icon e-trash",tooltipText:this.l10n.getConstant("Remove"),align:"Center"});for(var r=this.processSubToolbar(t),n=0,a=r.length;n<a;n++)o.push(r[n]);return e.Browser.isDevice||(o.push({id:this.parent.element.id+"_ok",prefixIcon:"e-icons e-check",cssClass:"top-icon e-tick",tooltipText:this.l10n.getConstant("OK"),align:"Right"}),o.push({id:this.parent.element.id+"_cancel",prefixIcon:"e-icons e-close",cssClass:"top-icon e-save",tooltipText:this.l10n.getConstant("Cancel"),align:"Right"})),o},a.prototype.initPenToolbarItem=function(t){var i=this,r=this.getLeftToolbarItem(),n=this.getRightToolbarItem(),a=this.getPenToolbarItem(t),s=this.getZoomToolbarItem();e.Browser.isDevice?this.defToolbarItems=a:this.defToolbarItems=r.concat(s,a,n);var l=new o.Toolbar({width:"100%",items:this.defToolbarItems,clicked:this.defToolbarClicked.bind(this),created:function(){i.renderAnnotationBtn(!0),i.createPenColor(t),i.createPenBtn(t),i.wireZoomBtnEvents(),e.Browser.isDevice||i.renderSaveBtn(),i.parent.trigger("toolbarCreated",{toolbarType:"pen"}),e.Browser.isDevice?i.defToolbarItems.length>0&&!e.isNullOrUndefined(document.getElementById(i.parent.element.id+"_toolbar"))&&(l.refreshOverflow(),l.refreshOverflow()):(i.createLeftToolbarControls(),i.defToolbarItems.length>0&&!e.isNullOrUndefined(document.getElementById(i.parent.element.id+"_toolbar"))&&l.refreshOverflow())}});e.Browser.isDevice?l.appendTo("#"+this.parent.element.id+"_bottomToolbar"):l.appendTo("#"+this.parent.element.id+"_toolbar"),this.enableDisableTbrBtn()},a.prototype.createPenColor=function(t){var i=this,o=this.parent;if(t.indexOf("strokeColor")>-1){o.element.querySelector(".e-template.e-pen-stroke-color").appendChild(o.createElement("input",{id:o.element.id+"_pen_stroke"}));var a=new n.ColorPicker({modeSwitcher:!1,value:"#fff",showButtons:!1,mode:"Palette",cssClass:"e-pen-color",change:function(t){i.parent.updatePenStrokeColor(t.currentValue.hex),i.selFhdColor=t.currentValue.hex,s.element.children[0].style.backgroundColor=t.currentValue.rgba,s.toggle()}},"#"+o.element.id+"_pen_stroke"),s=new r.DropDownButton({open:function(t){e.Browser.isDevice&&(t.element.parentElement.style.top=s.element.getBoundingClientRect().top-t.element.parentElement.offsetHeight+"px",t.element.parentElement.style.left=o.element.offsetLeft+"px")},target:".e-pen-color",iconCss:"e-dropdownbtn-preview"},"#"+o.element.id+"_penColorBtn");a.inline=!0;var l={tempFreeHandDrawEditingStyles:null};o.notify("freehand-draw",{prop:"getTempFreeHandDrawEditingStyles",value:{obj:l}});var p={freehandSelectedIndex:null};o.notify("freehand-draw",{prop:"getFreehandSelectedIndex",onPropertyChange:!1,value:{obj:p}}),!e.isNullOrUndefined(p.freehandSelectedIndex)&&p.freehandSelectedIndex>-1?this.parent.element.querySelector(".e-pen-stroke-color.e-template .e-dropdownbtn-preview").style.background="#42a5f5"===this.selFhdColor?l.tempFreeHandDrawEditingStyles.strokeColor:o.pointColl[p.freehandSelectedIndex].strokeColor:o.element.querySelector(".e-pen-stroke-color.e-template .e-dropdownbtn-preview").style.background="#fff"}},a.prototype.createPenBtn=function(t){var i=this,o=this.parent,n=[{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(o.element.id+"_penStrokeWidth"),s=document.createElement("span"),l={freehandSelectedIndex:null};o.notify("freehand-draw",{prop:"getFreehandSelectedIndex",onPropertyChange:!1,value:{obj:l}}),!e.isNullOrUndefined(l.freehandSelectedIndex)&&l.freehandSelectedIndex>-1?s.innerHTML=this.getPenStroke(o.pointColl[l.freehandSelectedIndex].strokeWidth):s.innerHTML=this.l10n.getConstant("Small"),s.className="e-pen-stroke-width",a.appendChild(s);var p=new r.DropDownButton({items:n,open:function(t){e.Browser.isDevice&&(t.element.parentElement.style.top=p.element.getBoundingClientRect().top-t.element.parentElement.offsetHeight+"px");var i=s.innerHTML;t.element.querySelector('[aria-label = "'+i+'"]').classList.add("e-selected-btn")},select:function(t){if(s.textContent=t.item.text,i.parent.updatePenStrokeWidth(t.item.id),e.Browser.isDevice){if(!e.isNullOrUndefined(document.getElementById(o.element.id+"_bottomToolbar"))){e.getComponent(o.element.id+"_bottomToolbar","toolbar").refreshOverflow()}}else if(!e.isNullOrUndefined(document.getElementById(o.element.id+"_toolbar"))){e.getComponent(o.element.id+"_toolbar","toolbar").refreshOverflow()}}});p.appendTo("#"+o.element.id+"_penStrokeWidth")}},a.prototype.getPenStroke=function(t){var e="",i={1:this.l10n.getConstant("XSmall"),2:this.l10n.getConstant("Small"),3:this.l10n.getConstant("Medium"),4:this.l10n.getConstant("Large"),5:this.l10n.getConstant("XLarge")};return t>=1&&t<=5&&(e=i[t]),e},a.prototype.initAdjustmentToolbarItem=function(){var t=this,i=this.parent,r=this.getLeftToolbarItem(null),n=this.getRightToolbarItem(),a=this.getAdjustmentToolbarItem(),s=this.getZoomToolbarItem();e.Browser.isDevice?this.defToolbarItems=a:this.defToolbarItems=r.concat(s,a,n);var l=new o.Toolbar({width:"100%",items:this.defToolbarItems,clicked:this.defToolbarClicked.bind(this),created:function(){t.wireZoomBtnEvents(),e.Browser.isDevice||t.renderSaveBtn(),e.Browser.isDevice?t.defToolbarItems.length>0&&!e.isNullOrUndefined(document.getElementById(i.element.id+"_toolbar"))&&l.refreshOverflow():(t.createLeftToolbarControls(),t.defToolbarItems.length>0&&!e.isNullOrUndefined(document.getElementById(i.element.id+"_toolbar"))&&l.refreshOverflow())}});e.Browser.isDevice?l.appendTo("#"+i.element.id+"_bottomToolbar"):l.appendTo("#"+i.element.id+"_toolbar"),this.enableDisableTbrBtn()},a.prototype.initFilterToolbarItem=function(){var t=this,i=this.parent,r=this.getFilterToolbarItem();document.querySelector("#"+this.parent.element.id+"_contextualToolbar").classList.contains("e-control")&&e.getComponent(document.getElementById(this.parent.element.id+"_contextualToolbar"),"toolbar").destroy();var n=new o.Toolbar({width:"100%",items:r,clicked:this.contextualToolbarClicked.bind(this),created:function(){t.updatePrivateVariables(),t.createCanvasFilter(),""===i.currentFilter&&(i.currentFilter=t.parent.element.id+"_default");var e=document.querySelector("#"+i.element.id+"_headWrapper");e&&(e.style.display="none"),document.getElementById(i.currentFilter+"Canvas").parentElement.parentElement.classList.add("e-selected"),t.enableDisableTbrBtn(),n.refreshOverflow()}});n.appendTo("#"+this.parent.element.id+"_contextualToolbar")},a.prototype.createCanvasFilter=function(){var t=this.parent,e=t.getCurrentCanvasData();this.inMemoryCanvas.width=e.width,this.inMemoryCanvas.height=e.height,this.inMemoryContext.putImageData(e,0,0),this.updateFilterCanvas("_defaultCanvas","default"),this.updateFilterCanvas("_chromeCanvas","chrome"),this.updateFilterCanvas("_coldCanvas","cold"),this.updateFilterCanvas("_warmCanvas","warm"),this.updateFilterCanvas("_grayscaleCanvas","grayscale"),this.updateFilterCanvas("_sepiaCanvas","sepia"),this.updateFilterCanvas("_invertCanvas","invert"),t.initialAdjustmentValue=this.lowerContext.filter},a.prototype.updateFilterCanvas=function(t,i){var o=this.parent.element.querySelector("#"+this.parent.element.id+t);if(!e.isNullOrUndefined(o)){var r=o.getContext("2d");r=o.getContext("2d"),o.style.width="100px",o.style.height="100px",this.parent.notify("filter",{prop:"updateAdj",value:{type:i,value:null,isPreview:!0,ctx:r}}),r.drawImage(this.inMemoryCanvas,0,0,300,150)}},a.prototype.getQuickAccessToolbarItem=function(t){var i=this.parent,o={cancel:!1,toolbarItems:[]},r=[];e.isNullOrUndefined(t)?(r.push("Clone"),r.push("Delete"),"text"===i.activeObj.shape&&r.push("EditText"),o.shape=i.toPascalCase(i.activeObj.shape)):t&&(r.push("Delete"),o.shape="Freehand draw"),o.toolbarItems=e.extend([],r,null,!0),i.trigger("quickAccessToolbarOpen",o);var n=[];if(o.cancel)n=[];else for(var a=0;a<o.toolbarItems.length;a++)switch(o.toolbarItems[a]){case"Clone":n.push({id:i.element.id+"_duplicate",prefixIcon:"e-icons e-order",cssClass:"top-icon e-order",tooltipText:this.l10n.getConstant("Duplicate"),align:"Left"});break;case"Delete":n.push({id:i.element.id+"_remove",prefixIcon:"e-icons e-trash",cssClass:"top-icon e-trash",tooltipText:this.l10n.getConstant("Remove"),align:"Left"});break;case"EditText":n.push({id:i.element.id+"_editText",prefixIcon:"e-icons e-annotation-edit",cssClass:"top-icon e-annotation-edit",tooltipText:this.l10n.getConstant("EditText"),align:"Left"});break;default:n.push(o.toolbarItems[a])}return n},a.prototype.renderQAT=function(t){if(!e.isNullOrUndefined(this.parent.activeObj)&&this.parent.showQuickAccessToolbar){var i=document.getElementById(this.parent.element.id+"_quickAccessToolbarArea");e.isNullOrUndefined(document.getElementById(this.parent.element.id+"_quickAccessToolbarArea"))||(this.destroyQuickAccessToolbar(),document.getElementById(this.parent.element.id+"_quickAccessToolbarArea").style.display="block");var r=this.getQuickAccessToolbarItem(t);if(0===r.length)return;if(e.isNullOrUndefined(this.parent.quickAccessToolbarTemplate)){new o.Toolbar({items:r,clicked:this.quickAccessToolbarClicked.bind(this)}).appendTo("#"+this.parent.element.id+"_quickAccessToolbar")}if(e.isNullOrUndefined(t)){i.style.width="auto",this.parent.activeObj.activePoint.width=Math.abs(this.parent.activeObj.activePoint.width),this.parent.activeObj.activePoint.height=Math.abs(this.parent.activeObj.activePoint.height);var n=this.parent.activeObj.activePoint.startX<this.parent.activeObj.activePoint.endX?this.parent.activeObj.activePoint.startX:this.parent.activeObj.activePoint.endX,a=this.parent.activeObj.activePoint.startY<this.parent.activeObj.activePoint.endY?this.parent.activeObj.activePoint.startY:this.parent.activeObj.activePoint.endY,s=this.parent.activeObj.activePoint.width;if(0!==this.parent.activeObj.rotatedAngle&&"arrow"!==this.parent.activeObj.shape){n=(c=this.parent.getSquarePointForRotatedShape(this.parent.activeObj)).startX,a=c.startY,s=c.width}else if("path"===this.parent.activeObj.shape){var l=this.parent.getSquarePointForPath(this.parent.activeObj);n=l.startX,a=l.startY,s=l.width}i.style.left=n+s/2-25*r.length+"px",a-60<this.parent.img.destTop?i.style.top=this.parent.img.destTop+"px":i.style.top=a-60+"px"}else if(t){var p={activePoint:null},h={freehandSelectedIndex:null};this.parent.notify("freehand-draw",{prop:"getFreehandSelectedIndex",onPropertyChange:!1,value:{obj:h}}),this.parent.notify("freehand-draw",{prop:"getSqPtFD",value:{idx:h.freehandSelectedIndex,obj:p}});var c=p.activePoint;i.style.width="auto",i.style.left=c.startX+c.width/2-27*r.length+"px",c.startY-60<this.parent.img.destTop?i.style.top=this.parent.img.destTop+"px":i.style.top=c.startY-60+"px"}}},a.prototype.refreshDropDownBtn=function(t){if(!e.isNullOrUndefined(t)){var i=document.querySelector("#"+this.parent.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 o=document.querySelector("#"+this.parent.element.id+"_transformBtn");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,"dropdown-btn").disabled=t);var r=document.querySelector("#"+this.parent.element.id+"_adjustment");e.isNullOrUndefined(r)||(t?(r.classList.add("e-disabled"),r.parentElement.classList.add("e-overlay")):(r.classList.remove("e-disabled"),r.parentElement.classList.remove("e-overlay")),e.getComponent(r,"btn").disabled=t);var n=document.querySelector("#"+this.parent.element.id+"_filter");e.isNullOrUndefined(n)||(t?(n.classList.add("e-disabled"),n.parentElement.classList.add("e-overlay")):(n.classList.remove("e-disabled"),n.parentElement.classList.remove("e-overlay")),e.getComponent(n,"btn").disabled=t)}},a.prototype.cropSelect=function(t){var i=this.parent;i.isCropTab=!0,e.isNullOrUndefined(i.transform.cropZoomFactor)&&(i.transform.cropZoomFactor=i.transform.zoomFactor,i.notify("draw",{prop:"setTempZoomFactor",onPropertyChange:!1,value:{tempZoomFactor:i.transform.zoomFactor}})),i.transform.zoomFactor=i.transform.cropZoomFactor;var o=t.item.id;this.currentToolbar="crop",i.currSelectionPoint=null,i.select(o),this.enableDisableTbrBtn(),i.notify("transform",{prop:"disableZoomOutBtn",value:{isZoomOut:!0}})},a.prototype.quickAccessToolbarClicked=function(t,i){var o=this.parent,r={x:o.activeObj.activePoint.startX,y:o.activeObj.activePoint.startY};if(!e.isNullOrUndefined(t.item)){var n=void 0,a=void 0,s=null,l={prevActObj:null},p={tempObj:null};o.notify("draw",{prop:"getPrevActObj",onPropertyChange:!1,value:{obj:l}}),o.notify("selection",{prop:"getTempActObj",onPropertyChange:!1,value:{obj:p}}),p.tempObj.activePoint.height=Math.abs(p.tempObj.activePoint.height);var h={isNewPath:null};switch(o.notify("draw",{prop:"getNewPath",value:{obj:h}}),t.item.id.replace(o.element.id+"_","").toLowerCase()){case"duplicate":if(!this.parent.element.querySelector("#"+this.parent.element.id+"_duplicate").classList.contains("e-disabled")){if(h.isNewPath||JSON.stringify(p.tempObj)!==JSON.stringify(o.activeObj)||(s=!0),n=e.extend({},o.activeObj,{},!0),e.isNullOrUndefined(o.activeObj.currIndex)?o.notify("shape",{prop:"applyActObj",onPropertyChange:!1,value:{isMouseDown:s}}):e.isNullOrUndefined(l.prevActObj)?o.notify("shape",{prop:"applyActObj",onPropertyChange:!1,value:{isMouseDown:!0}}):(o.activeObj.currIndex=null,n.currIndex=null,o.notify("shape",{prop:"applyActObj",onPropertyChange:!1,value:{isMouseDown:s}})),h.isNewPath&&o.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"ok"}}),a=e.extend([],o.objColl,[],!0),n.activePoint.startX+=10,n.activePoint.startY-=10,n.activePoint.endX+=10,n.activePoint.endY-=10,"path"===n.shape)for(var c=0;c<n.pointColl.length;c++)n.pointColl[c].x+=10,n.pointColl[c].y-=10;o.activeObj=n,"line"!==o.activeObj.shape&&"arrow"!==o.activeObj.shape||o.notify("shape",{prop:"setPointCollForLineArrow",onPropertyChange:!1,value:{obj:o.activeObj}}),o.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate",obj:o.activeObj}}),o.notify("undo-redo",{prop:"updateUrObj",onPropertyChange:!1,value:{objColl:a}}),this.renderQAT()}break;case"remove":this.parent.element.querySelector("#"+this.parent.element.id+"_remove").classList.contains("e-disabled")||o.notify("selection",{prop:"deleteItem",onPropertyChange:!1});break;case"edittext":this.parent.element.querySelector("#"+this.parent.element.id+"_editText").classList.contains("e-disabled")||(this.upperContext.clearRect(0,0,o.upperCanvas.width,o.upperCanvas.height),o.notify("selection",{prop:"setTempActObj",onPropertyChange:!1,value:{obj:e.extend({},o.activeObj,{},!0)}}),o.notify("selection",{prop:"setInitialTextEdit",onPropertyChange:!1,value:{bool:!0}}),o.notify("draw",{prop:"setPrevActObj",onPropertyChange:!1,value:{prevActObj:e.extend({},o.activeObj,{},!0)}}),0!==o.activeObj.rotatedAngle&&(r.x=o.activeObj.horTopLinePointColl[0].x,r.y=o.activeObj.horTopLinePointColl[0].y),o.notify("shape",{prop:"renderTextArea",onPropertyChange:!1,value:{x:r.x,y:r.y,actObj:o.activeObj}}),e.isNullOrUndefined(o.activeObj.currIndex)?o.notify("draw",{prop:"setShapeTextInsert",onPropertyChange:!1,value:{bool:!0}}):e.isNullOrUndefined(l.prevActObj)||o.notify("draw",{prop:"setShapeTextInsert",onPropertyChange:!1,value:{bool:!0}}),e.isNullOrUndefined(document.getElementById(this.parent.element.id+"_quickAccessToolbarArea"))||(document.getElementById(o.element.id+"_quickAccessToolbarArea").style.display="none"))}}e.isNullOrUndefined(i)&&o.trigger("quickAccessToolbarItemClick",t)},a.prototype.defToolbarClicked=function(t){var i=this.parent,o=!1,r=!1;if(i.element.querySelector(".e-contextual-toolbar-wrapper")&&(i.element.querySelector(".e-contextual-toolbar-wrapper").classList.contains("e-hide")||(o=r=!0),i.element.querySelector(".e-contextual-toolbar-wrapper").classList.add("e-hide")),!e.isNullOrUndefined(t.item)){var n=t.item.id.replace(i.element.id+"_","").toLowerCase();if("duplicate"===n||"remove"===n||"edittext"===n)this.quickAccessToolbarClicked(t,!0),i.trigger("toolbarItemClicked",t);else{var a=!1,s=!1,l=document.querySelector("#"+i.element.id+"_adjustment");!e.isNullOrUndefined(l)&&l.classList.contains("e-disabled")&&(s=!0);var p=document.querySelector("#"+i.element.id+"_filter");!e.isNullOrUndefined(p)&&p.classList.contains("e-disabled")&&(a=!0),this.enableDisableTbrBtn(),this.performDefTbrClick(n,o,s,a,r),i.trigger("toolbarItemClicked",t)}}},a.prototype.performDefTbrClick=function(t,o,r,n,a){var s,l,p=this.parent,h=p.element.querySelector("#"+p.element.id+"_zoomIn"),c=!1;if(void 0!==p.activeObj.shape&&(l=p.activeObj.shape.split("-")),void 0===l&&p.currObjType.isCustomCrop?c=!0:void 0!==l&&"crop"===l[0]&&(c=!0),!p.disabled)switch(t){case"pan":p.currObjType.isCustomCrop=p.currObjType.isFiltered=!1,p.currObjType.isUndoAction&&p.notify("undo-redo",{prop:"refreshUrc",value:{bool:null}}),c&&(p.currObjType.isCustomCrop=!1,p.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),this.upperContext.clearRect(0,0,p.upperCanvas.width,p.upperCanvas.height),this.refreshToolbar("main")),p.togglePan?(this.cancelPan(),p.notify("transform",{prop:"setDisablePan",onPropertyChange:!1,value:{bool:!0}}),"pen"===this.currentToolbar&&p.freehandDraw(!0)):(s=this.parent.element.querySelector(".e-img-pan .e-btn"),e.isNullOrUndefined(s)||s.classList.add("e-selected-btn"),p.pan(!0),p.notify("transform",{prop:"setDisablePan",onPropertyChange:!1,value:{bool:!1}})),!e.isNullOrUndefined(h)&&p.zoomSettings.zoomFactor>=p.zoomSettings.maxZoomFactor?(h.classList.add("e-disabled"),h.parentElement.classList.add("e-overlay")):e.isNullOrUndefined(h)||(h.classList.remove("e-disabled"),h.parentElement.classList.remove("e-overlay")),this.refreshToolbar("main");break;case"cancel":p.notify("draw",{prop:"performCancel",value:{isContextualToolbar:o}});break;case"ok":p.okBtn(),this.refreshDropDownBtn(!1),this.currentToolbar="main";break;case"crop":e.isNullOrUndefined(p.currSelectionPoint)||(p.currObjType.isUndoAction&&p.notify("undo-redo",{prop:"refreshUrc",value:{bool:null}}),e.isNullOrUndefined(p.cropObj.activeObj.shape)||p.select(p.activeObj.shape),this.refreshToolbar("main",!0,!0),e.getComponent(p.element.querySelector("#"+this.parent.element.id+"_cropBtn"),"dropdown-btn").toggle(),e.isNullOrUndefined(p.activeObj.shape)||document.getElementById(p.activeObj.shape.split("-")[1]).classList.add("e-selected")),p.notify("transform",{prop:"disableZoomOutBtn",value:{isZoomOut:!0}});break;case"reset":p.reset(),this.currentToolbar="main";break;case"undo":p.notify("undo-redo",{prop:"call-undo"});break;case"redo":p.notify("undo-redo",{prop:"call-redo"});break;case"adjustment":r||(p.currObjType.isFiltered&&p.okBtn(),this.refreshToolbar("adjustment"),p.setTempFilterProperties(),this.openSlider("brightness"));break;case"brightness":case"contrast":case"hue":case"saturation":case"opacity":case"blur":case"exposure":this.openSlider(t);break;case"filter":n||(i.showSpinner(p.element),this.refreshToolbar("filter"),p.setTempFilterProperties(),i.hideSpinner(p.element));break;case"default":case"chrome":case"cold":case"warm":case"grayscale":case"blackandwhite":case"sepia":case"invert":case"sharpen":p.currObjType.isFiltered=!0,p.notify("filter",{prop:"applyImageFilter",value:{option:t}});break;case"upload":a&&p.element.querySelector(".e-contextual-toolbar-wrapper").classList.remove("e-hide");break;case"bold":p.notify("selection",{prop:"setInitialTextEdit",value:{bool:!1}}),p.activeObj.textSettings.bold&&p.activeObj.textSettings.italic?p.notify("shape",{prop:"applyFontStyle",onPropertyChange:!1,value:{item:"italic"}}):p.activeObj.textSettings.bold&&!p.activeObj.textSettings.italic?p.notify("shape",{prop:"applyFontStyle",onPropertyChange:!1,value:{item:"default"}}):!p.activeObj.textSettings.bold&&p.activeObj.textSettings.italic?p.notify("shape",{prop:"applyFontStyle",onPropertyChange:!1,value:{item:"bolditalic"}}):p.activeObj.textSettings.bold||p.activeObj.textSettings.italic||p.notify("shape",{prop:"applyFontStyle",onPropertyChange:!1,value:{item:"bold"}}),p.element.querySelector("#"+p.element.id+"_bold").classList.contains("e-selected-btn")?p.element.querySelector("#"+p.element.id+"_bold").classList.remove("e-selected-btn"):p.element.querySelector("#"+p.element.id+"_bold").classList.add("e-selected-btn");break;case"italic":p.notify("selection",{prop:"setInitialTextEdit",value:{bool:!1}}),p.activeObj.textSettings.bold&&p.activeObj.textSettings.italic?p.notify("shape",{prop:"applyFontStyle",onPropertyChange:!1,value:{item:"bold"}}):p.activeObj.textSettings.bold&&!p.activeObj.textSettings.italic?p.notify("shape",{prop:"applyFontStyle",onPropertyChange:!1,value:{item:"bolditalic"}}):!p.activeObj.textSettings.bold&&p.activeObj.textSettings.italic?p.notify("shape",{prop:"applyFontStyle",onPropertyChange:!1,value:{item:"default"}}):p.activeObj.textSettings.bold||p.activeObj.textSettings.italic||p.notify("shape",{prop:"applyFontStyle",onPropertyChange:!1,value:{item:"italic"}}),p.element.querySelector("#"+p.element.id+"_italic").classList.contains("e-selected-btn")?p.element.querySelector("#"+p.element.id+"_italic").classList.remove("e-selected-btn"):p.element.querySelector("#"+p.element.id+"_italic").classList.add("e-selected-btn");break;case"croptransform":this.refreshToolbar("croptransform");break;case"rotateleft":case"rotateright":case"horizontalflip":case"verticalflip":this.parent.transformSelect(t),p.notify("transform",{prop:"disableZoomOutBtn",value:{isZoomOut:!0}});break;case"save":if(p.element.querySelector("#"+p.element.id+"_saveBtn").classList.contains("e-hide")){p.element.querySelector("#"+p.element.id+"_saveBtn").classList.remove("e-hide");break}p.okBtn(),p.element.querySelector("#"+p.element.id+"_saveBtn").classList.add("e-hide"),p.element.querySelector("#"+p.element.id+"_saveBtn").click()}},a.prototype.contextualToolbarClicked=function(t){var e=this.parent,i=e.element.querySelector(".e-contextual-toolbar-wrapper .e-toolbar-item.e-selected");i&&i.classList.remove("e-selected");var o=t.item.id.replace(e.element.id,"").split("_")[1],r={filter:e.toPascalCase(o),cancel:!1};this.parent.trigger("imageFiltering",r),r.cancel||(document.getElementById(t.item.id+"Canvas").parentElement.parentElement.classList.add("e-selected"),e.currObjType.isFiltered=!0,e.notify("filter",{prop:"applyImageFilter",value:{option:o.toLowerCase()}}),e.currentFilter=t.item.id,this.enableDisableTbrBtn())},a.prototype.refreshShapeDrawing=function(){var t={shape:""};this.parent.notify("selection",{prop:"getCurrentDrawingShape",onPropertyChange:!1,value:{obj:t}}),""!==t.shape&&(this.parent.notify("selection",{prop:"setCurrentDrawingShape",onPropertyChange:!1,value:{value:""}}),this.parent.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),this.refreshToolbar("main",!1))},a.prototype.zoomInBtnClickHandler=function(i){var o=this.parent;if((o.zoomSettings.zoomTrigger&t.ZoomTrigger.Toolbar)===t.ZoomTrigger.Toolbar){if(this.refreshShapeDrawing(),e.Browser.isDevice&&"touchstart"===i.type){if(!i.returnValue)return;i.preventDefault()}var r=document.querySelector("#"+o.element.id+"_zoomIn");e.EventHandler.trigger(r,"click");var n={bool:!1};o.notify("selection",{prop:"getFreehandDrawEditing",onPropertyChange:!1,value:{obj:n}}),n.bool&&(o.notify("freehand-draw",{prop:"applyFhd",onPropertyChange:!1}),this.destroyQuickAccessToolbar()),this.applyPreviewFilter(),o.currObjType.isFiltered=!1,o.togglePen&&(o.currObjType.isZoomed=!0,o.freeHandDraw(!1),o.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"ok"}})),o.notify("draw",{prop:"resetCurrentSelectionPoint"}),o.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:.1,zoomPoint:null}})}},a.prototype.zoomOutBtnClickHandler=function(i){var o=this.parent;if((o.zoomSettings.zoomTrigger&t.ZoomTrigger.Toolbar)===t.ZoomTrigger.Toolbar){if(this.refreshShapeDrawing(),e.Browser.isDevice&&"touchstart"===i.type){if(!i.returnValue)return;i.preventDefault()}var r=document.querySelector("#"+o.element.id+"_zoomOut");e.EventHandler.trigger(r,"click");var n={bool:!1};o.notify("selection",{prop:"getFreehandDrawEditing",onPropertyChange:!1,value:{obj:n}}),n.bool&&(o.notify("freehand-draw",{prop:"applyFhd",onPropertyChange:!1}),this.destroyQuickAccessToolbar()),this.applyPreviewFilter(),o.currObjType.isFiltered=!1,o.togglePen&&(o.currObjType.isZoomed=!0,o.freeHandDraw(!1),o.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"ok"}})),o.notify("draw",{prop:"resetCurrentSelectionPoint"}),o.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:-.1,zoomPoint:null}})}},a.prototype.zoomInBtnMouseDownHandler=function(t){t.preventDefault(),this.zoomBtnHold=setInterval(this.zoomInBtnClickHandler.bind(this),250)},a.prototype.zoomOutBtnMouseDownHandler=function(t){t.preventDefault(),this.zoomBtnHold=setInterval(this.zoomOutBtnClickHandler.bind(this),250)},a.prototype.zoomBtnMouseUpHandler=function(){clearInterval(this.zoomBtnHold),this.zoomBtnHold=0},a.prototype.closeContextualToolbar=function(){var t=this.parent,i=!1;return(e.isNullOrUndefined(t.element.querySelector("#"+t.element.id+"_contextualToolbar"))||t.element.querySelector("#"+t.element.id+"_contextualToolbar").parentElement.classList.contains("e-hide"))&&(e.isNullOrUndefined(t.element.querySelector("#"+t.element.id+"_headWrapper"))||t.element.querySelector("#"+t.element.id+"_headWrapper").parentElement.classList.contains("e-hide"))||(t.element.querySelector(".e-contextual-toolbar-wrapper").classList.add("e-hide"),t.okBtn(),this.refreshMainToolbar(),i=!0),i},a.prototype.destroyQuickAccessToolbar=function(){var t=this.parent;e.isNullOrUndefined(document.getElementById(t.element.id+"_quickAccessToolbar"))||e.isNullOrUndefined(e.getComponent(document.getElementById(t.element.id+"_quickAccessToolbar"),"toolbar"))||e.getComponent(document.getElementById(t.element.id+"_quickAccessToolbar"),"toolbar").destroy(),e.isNullOrUndefined(document.getElementById(t.element.id+"_quickAccessToolbarArea"))||(document.getElementById(t.element.id+"_quickAccessToolbarArea").style.display="none")},a.prototype.renderSlider=function(t){var i=this.parent,o=document.querySelector("#"+i.element.id+"_contextualToolbarArea"),r=document.querySelector("#"+i.element.id+"_headWrapper"),n=document.querySelector("#"+i.element.id+"_labelWrapper");r?r.style.display="block":n=(r=o.appendChild(i.createElement("div",{id:i.element.id+"_headWrapper",styles:"position: relative"}))).appendChild(this.parent.createElement("label",{id:i.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;"})),n.textContent=this.l10n.getConstant(i.toPascalCase(t));var a,s,l,p=r.appendChild(i.createElement("div",{id:i.element.id+"_sliderWrapper",styles:"position: absolute"})),h=this.parent.getCurrAdjustmentValue(t);"brightness"===t||"contrast"===t||"saturation"===t||"exposure"===t?(this.parent.finetuneSettings?"brightness"===t&&i.finetuneSettings.brightness?(a=i.finetuneSettings.brightness.min,s=i.finetuneSettings.brightness.max):"contrast"===t&&i.finetuneSettings.contrast?(a=i.finetuneSettings.contrast.min,s=i.finetuneSettings.contrast.max):"saturation"===t&&i.finetuneSettings.saturation?(a=i.finetuneSettings.saturation.min,s=i.finetuneSettings.saturation.max):"exposure"===t&&this.parent.finetuneSettings.exposure?(a=i.finetuneSettings.exposure.min,s=i.finetuneSettings.exposure.max):(a=-100,s=100):(a=-100,s=100),l=this.createSlider(a,s,h,t)):"hue"!==t&&"blur"!==t&&"opacity"!==t||(i.finetuneSettings?"hue"===t&&i.finetuneSettings.hue?(a=i.finetuneSettings.hue.min,s=i.finetuneSettings.hue.max):"blur"===t&&i.finetuneSettings.blur?(a=i.finetuneSettings.blur.min,s=i.finetuneSettings.blur.max):"opacity"===t&&i.finetuneSettings.opacity?(a=i.finetuneSettings.opacity.min,s=i.finetuneSettings.opacity.max):(a=0,s=100):(a=0,s=100),l=this.createSlider(a,s,h,t)),l.appendTo("#"+i.element.id+"_sliderWrapper"),p.style.left=(parseFloat(o.style.width)-parseFloat(l.width))/2+"px"},a.prototype.createSlider=function(t,i,o,r){var a=this;this.parent;return new n.Slider({value:o,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){a.parent.setCurrAdjustmentValue(r,t.value),a.enableDisableTbrBtn()}})},a.prototype.applyPreviewFilter=function(){e.isNullOrUndefined(document.querySelector("#"+this.parent.element.id+"_sliderWrapper"))&&!this.parent.currObjType.isFiltered||(this.parent.initialAdjustmentValue=this.parent.canvasFilter=this.lowerContext.filter,this.parent.currObjType.isFiltered=!1)},a.prototype.unselectBtn=function(){for(var t=0,e=["#"+this.parent.element.id+"_brightness","#"+this.parent.element.id+"_contrast","#"+this.parent.element.id+"_hue","#"+this.parent.element.id+"_saturation","#"+this.parent.element.id+"_opacity","#"+this.parent.element.id+"_blur","#"+this.parent.element.id+"_exposure"];t<e.length;t++){var i=e[t],o=document.querySelector(i);if(o.classList.contains("e-selected-btn")){o.classList.remove("e-selected-btn");break}}},a.prototype.openSlider=function(t){this.unselectBtn(),this.parent.currObjType.isFiltered=!0,this.refreshToolbar("color",null,null,null,t),document.getElementById(this.parent.element.id+"_"+t).classList.add("e-selected-btn")},a.prototype.refreshSlider=function(){var t=document.querySelector("#"+this.parent.element.id+"_sliderWrapper"),i=document.querySelector(".e-slider"),o=document.querySelector("#"+this.parent.element.id+"_headWrapper");o&&(o.style.display="none"),e.isNullOrUndefined(t)||e.isNullOrUndefined(i)||(i.ej2_instances[0].destroy(),t.remove())},a.prototype.updateToolbarItems=function(){var t=this.parent.element.querySelector(".e-fill.e-template .e-dropdownbtn-preview"),i=this.parent.element.querySelector(".e-stroke.e-template .e-dropdownbtn-preview"),o=this.parent.element.querySelector(".e-text-font-color.e-template .e-dropdownbtn-preview"),r=this.parent.element.querySelector(".e-pen-stroke-color.e-template .e-dropdownbtn-preview"),n=this.parent.element.querySelector(".e-shape-stroke-width"),a=this.parent.element.querySelector(".e-text-font-family"),s=this.parent.element.querySelector(".e-text-font-size"),l=this.parent.element.querySelector("#"+this.parent.element.id+"_bold"),p=this.parent.element.querySelector("#"+this.parent.element.id+"_italic");if(e.isNullOrUndefined(this.parent.activeObj.strokeSettings.strokeWidth)&&(this.parent.activeObj.strokeSettings.strokeWidth=2),t&&(""===this.parent.activeObj.strokeSettings.fillColor?t.classList.add("e-nocolor-item"):(t.classList.remove("e-nocolor-item"),t.style.background=this.parent.activeObj.strokeSettings.fillColor),e.getComponent(this.parent.element.id+"_shape_fill","colorpicker").value=this.parent.activeObj.strokeSettings.fillColor+"ff"),i&&(i.style.background=this.parent.activeObj.strokeSettings.strokeColor,e.getComponent(this.parent.element.id+"_shape_stroke","colorpicker").value=this.parent.activeObj.strokeSettings.strokeColor+"ff"),o&&(o.style.background=this.parent.activeObj.strokeSettings.strokeColor,e.getComponent(this.parent.element.id+"_text_font","colorpicker").value=this.parent.activeObj.strokeSettings.strokeColor+"ff"),r&&(r.style.background=this.parent.activeObj.strokeSettings.strokeColor,e.getComponent(this.parent.element.id+"_pen_stroke","colorpicker").value=this.parent.activeObj.strokeSettings.strokeColor+"ff"),a&&(e.Browser.isDevice?a.setAttribute("style","font-family:"+this.parent.activeObj.textSettings.fontFamily.toLowerCase()):a.textContent=this.parent.activeObj.textSettings.fontFamily),s)for(var h=0;h<this.parent.fontSizeColl.length;h++)if(parseInt(this.parent.fontSizeColl[h].text,10)>=Math.round(this.parent.activeObj.textSettings.fontSize)){s.textContent=(h+1).toString();break}if(l&&(this.parent.activeObj.textSettings.bold?l.classList.add("e-selected-btn"):l.classList.remove("e-selected-btn")),p&&(this.parent.activeObj.textSettings.italic?p.classList.add("e-selected-btn"):p.classList.remove("e-selected-btn")),n){var c=Math.round(this.parent.activeObj.strokeSettings.strokeWidth).toString();n.textContent=this.getStrokeWidth(c)}},a.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},a.prototype.cancelPan=function(){var t=this.parent;t.notify("shape",{prop:"applyActObj",onPropertyChange:!1,value:{isMouseDown:!0}});var i=t.element.querySelector(".e-img-pan .e-btn");e.isNullOrUndefined(i)||i.classList.remove("e-selected-btn"),t.pan(!1)},a.prototype.refreshMainToolbar=function(){"main"!==this.currToolbar&&this.refreshToolbar("main")},a.prototype.destroySubComponents=function(){for(var t=this.parent.element.querySelectorAll("input.e-control"),i=this.parent.element.querySelectorAll("button.e-control"),o=0,r=t.length;o<r;o++)t[o].classList.contains("e-color-picker")&&(e.getComponent(t[o],"color-picker").destroy(),e.detach(e.select("input#"+t[o].id,this.parent.element)));for(o=0,r=i.length;o<r;o++)i[o].classList.contains("e-dropdown-btn")?(e.getComponent(i[o],"dropdown-btn").destroy(),e.detach(e.select("button#"+i[o].id,this.parent.element))):i[o].classList.contains("e-btn")&&(e.getComponent(i[o],"btn").destroy(),e.detach(e.select("button#"+i[o].id,this.parent.element)))},a.prototype.setInitialShapeSettings=function(t){var e=this.parent;e.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),e.currObjType.shape=t.item.id,e.activeObj.shape=e.currObjType.shape.toLowerCase(),e.currObjType.isDragging=e.currObjType.isCustomCrop=!1,e.activeObj.shapeDegree=e.transform.degree,e.activeObj.shapeFlip=e.transform.currFlipState,e.activeObj.textFlip=e.transform.currFlipState,e.activeObj.flipObjColl=[]},a.prototype.getModuleName=function(){return"toolbar-module"},a}();t.Crop=a,t.Draw=s,t.Export=l,t.Filter=p,t.FreehandDrawing=h,t.Selection=c,t.Shape=d,t.Transform=v,t.UndoRedo=u,t.FinetuneSettings=C,t.ZoomSettings=f,t.SelectionSettings=m,t.ImageEditor=y,t.ToolbarModule=P,Object.defineProperty(t,"__esModule",{value:!0})});
11
11
  //# sourceMappingURL=ej2-image-editor.umd.min.js.map