@syncfusion/ej2-image-editor 26.2.10 → 27.1.48

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 (187) hide show
  1. package/README.md +1 -1
  2. package/dist/ej2-image-editor.umd.min.js +2 -2
  3. package/dist/ej2-image-editor.umd.min.js.map +1 -1
  4. package/dist/es6/ej2-image-editor.es2015.js +3207 -732
  5. package/dist/es6/ej2-image-editor.es2015.js.map +1 -1
  6. package/dist/es6/ej2-image-editor.es5.js +3286 -797
  7. package/dist/es6/ej2-image-editor.es5.js.map +1 -1
  8. package/dist/global/ej2-image-editor.min.js +2 -2
  9. package/dist/global/ej2-image-editor.min.js.map +1 -1
  10. package/dist/global/index.d.ts +1 -1
  11. package/package.json +14 -13
  12. package/src/image-editor/action/crop.d.ts +0 -1
  13. package/src/image-editor/action/crop.js +8 -19
  14. package/src/image-editor/action/draw.d.ts +4 -0
  15. package/src/image-editor/action/draw.js +377 -45
  16. package/src/image-editor/action/export.js +21 -13
  17. package/src/image-editor/action/filter.d.ts +13 -0
  18. package/src/image-editor/action/filter.js +272 -1
  19. package/src/image-editor/action/freehand-draw.d.ts +1 -0
  20. package/src/image-editor/action/freehand-draw.js +44 -23
  21. package/src/image-editor/action/selection.d.ts +6 -0
  22. package/src/image-editor/action/selection.js +382 -97
  23. package/src/image-editor/action/shape.d.ts +5 -0
  24. package/src/image-editor/action/shape.js +287 -141
  25. package/src/image-editor/action/transform.js +56 -82
  26. package/src/image-editor/action/undo-redo.d.ts +2 -0
  27. package/src/image-editor/action/undo-redo.js +100 -1
  28. package/src/image-editor/base/enum.d.ts +11 -0
  29. package/src/image-editor/base/enum.js +12 -0
  30. package/src/image-editor/base/image-editor-model.d.ts +13 -1
  31. package/src/image-editor/base/image-editor.d.ts +142 -20
  32. package/src/image-editor/base/image-editor.js +816 -149
  33. package/src/image-editor/base/interface.d.ts +140 -1
  34. package/src/image-editor/renderer/toolbar.d.ts +8 -0
  35. package/src/image-editor/renderer/toolbar.js +873 -191
  36. package/styles/bootstrap-dark-lite.css +746 -0
  37. package/styles/bootstrap-dark-lite.scss +13 -0
  38. package/styles/bootstrap-dark.css +150 -105
  39. package/styles/bootstrap-dark.scss +1 -0
  40. package/styles/bootstrap-lite.css +747 -0
  41. package/styles/bootstrap-lite.scss +13 -0
  42. package/styles/bootstrap.css +151 -106
  43. package/styles/bootstrap.scss +1 -0
  44. package/styles/bootstrap4-lite.css +747 -0
  45. package/styles/bootstrap4-lite.scss +13 -0
  46. package/styles/bootstrap4.css +150 -105
  47. package/styles/bootstrap4.scss +1 -0
  48. package/styles/bootstrap5-dark-lite.css +757 -0
  49. package/styles/bootstrap5-dark-lite.scss +13 -0
  50. package/styles/bootstrap5-dark.css +152 -113
  51. package/styles/bootstrap5-dark.scss +1 -0
  52. package/styles/bootstrap5-lite.css +757 -0
  53. package/styles/bootstrap5-lite.scss +13 -0
  54. package/styles/bootstrap5.3-lite.css +760 -0
  55. package/styles/bootstrap5.3-lite.scss +13 -0
  56. package/styles/bootstrap5.3.css +867 -0
  57. package/styles/bootstrap5.3.scss +14 -0
  58. package/styles/bootstrap5.css +152 -113
  59. package/styles/bootstrap5.scss +1 -0
  60. package/styles/fabric-dark-lite.css +749 -0
  61. package/styles/fabric-dark-lite.scss +13 -0
  62. package/styles/fabric-dark.css +150 -105
  63. package/styles/fabric-dark.scss +1 -0
  64. package/styles/fabric-lite.css +751 -0
  65. package/styles/fabric-lite.scss +13 -0
  66. package/styles/fabric.css +151 -106
  67. package/styles/fabric.scss +1 -0
  68. package/styles/fluent-dark-lite.css +758 -0
  69. package/styles/fluent-dark-lite.scss +13 -0
  70. package/styles/fluent-dark.css +150 -111
  71. package/styles/fluent-dark.scss +1 -0
  72. package/styles/fluent-lite.css +758 -0
  73. package/styles/fluent-lite.scss +13 -0
  74. package/styles/fluent.css +150 -111
  75. package/styles/fluent.scss +1 -0
  76. package/styles/fluent2-lite.css +791 -0
  77. package/styles/fluent2-lite.scss +13 -0
  78. package/styles/fluent2.css +173 -117
  79. package/styles/fluent2.scss +1 -0
  80. package/styles/highcontrast-light-lite.css +748 -0
  81. package/styles/highcontrast-light-lite.scss +13 -0
  82. package/styles/highcontrast-light.css +149 -104
  83. package/styles/highcontrast-light.scss +1 -0
  84. package/styles/highcontrast-lite.css +753 -0
  85. package/styles/highcontrast-lite.scss +13 -0
  86. package/styles/highcontrast.css +150 -104
  87. package/styles/highcontrast.scss +1 -0
  88. package/styles/image-editor/_bds-definition.scss +3 -1
  89. package/styles/image-editor/_bigger.scss +216 -0
  90. package/styles/image-editor/_bootstrap-dark-definition.scss +3 -1
  91. package/styles/image-editor/_bootstrap-definition.scss +3 -1
  92. package/styles/image-editor/_bootstrap4-definition.scss +3 -1
  93. package/styles/image-editor/_bootstrap5-definition.scss +3 -1
  94. package/styles/image-editor/_bootstrap5.3-definition.scss +3 -1
  95. package/styles/image-editor/_fabric-dark-definition.scss +3 -1
  96. package/styles/image-editor/_fabric-definition.scss +3 -1
  97. package/styles/image-editor/_fluent-definition.scss +3 -1
  98. package/styles/image-editor/_fluent2-definition.scss +4 -2
  99. package/styles/image-editor/_fusionnew-definition.scss +3 -1
  100. package/styles/image-editor/_highcontrast-definition.scss +3 -1
  101. package/styles/image-editor/_highcontrast-light-definition.scss +3 -1
  102. package/styles/image-editor/_layout.scss +75 -212
  103. package/styles/image-editor/_material-dark-definition.scss +3 -1
  104. package/styles/image-editor/_material-definition.scss +3 -1
  105. package/styles/image-editor/_material3-definition.scss +5 -3
  106. package/styles/image-editor/_tailwind-definition.scss +5 -3
  107. package/styles/image-editor/_theme.scss +48 -11
  108. package/styles/image-editor/bootstrap-dark.css +150 -105
  109. package/styles/image-editor/bootstrap-dark.scss +1 -0
  110. package/styles/image-editor/bootstrap.css +151 -106
  111. package/styles/image-editor/bootstrap.scss +1 -0
  112. package/styles/image-editor/bootstrap4.css +150 -105
  113. package/styles/image-editor/bootstrap4.scss +1 -0
  114. package/styles/image-editor/bootstrap5-dark.css +152 -113
  115. package/styles/image-editor/bootstrap5-dark.scss +1 -0
  116. package/styles/image-editor/bootstrap5.3.css +867 -0
  117. package/styles/image-editor/bootstrap5.3.scss +14 -0
  118. package/styles/image-editor/bootstrap5.css +152 -113
  119. package/styles/image-editor/bootstrap5.scss +1 -0
  120. package/styles/image-editor/fabric-dark.css +150 -105
  121. package/styles/image-editor/fabric-dark.scss +1 -0
  122. package/styles/image-editor/fabric.css +151 -106
  123. package/styles/image-editor/fabric.scss +1 -0
  124. package/styles/image-editor/fluent-dark.css +150 -111
  125. package/styles/image-editor/fluent-dark.scss +1 -0
  126. package/styles/image-editor/fluent.css +150 -111
  127. package/styles/image-editor/fluent.scss +1 -0
  128. package/styles/image-editor/fluent2.css +173 -117
  129. package/styles/image-editor/fluent2.scss +1 -0
  130. package/styles/image-editor/highcontrast-light.css +149 -104
  131. package/styles/image-editor/highcontrast-light.scss +1 -0
  132. package/styles/image-editor/highcontrast.css +150 -104
  133. package/styles/image-editor/highcontrast.scss +1 -0
  134. package/styles/image-editor/icons/_bds.scss +10 -1
  135. package/styles/image-editor/icons/_bootstrap-dark.scss +10 -1
  136. package/styles/image-editor/icons/_bootstrap.scss +10 -1
  137. package/styles/image-editor/icons/_bootstrap4.scss +10 -1
  138. package/styles/image-editor/icons/_bootstrap5.3.scss +10 -1
  139. package/styles/image-editor/icons/_bootstrap5.scss +10 -1
  140. package/styles/image-editor/icons/_fabric-dark.scss +10 -1
  141. package/styles/image-editor/icons/_fabric.scss +10 -1
  142. package/styles/image-editor/icons/_fluent.scss +10 -1
  143. package/styles/image-editor/icons/_fluent2.scss +10 -1
  144. package/styles/image-editor/icons/_fusionnew.scss +10 -1
  145. package/styles/image-editor/icons/_highcontrast-light.scss +10 -1
  146. package/styles/image-editor/icons/_highcontrast.scss +10 -1
  147. package/styles/image-editor/icons/_material-dark.scss +10 -1
  148. package/styles/image-editor/icons/_material.scss +10 -1
  149. package/styles/image-editor/icons/_material3.scss +10 -1
  150. package/styles/image-editor/icons/_tailwind.scss +10 -1
  151. package/styles/image-editor/material-dark.css +153 -108
  152. package/styles/image-editor/material-dark.scss +1 -0
  153. package/styles/image-editor/material.css +159 -114
  154. package/styles/image-editor/material.scss +1 -0
  155. package/styles/image-editor/material3-dark.css +171 -123
  156. package/styles/image-editor/material3-dark.scss +1 -0
  157. package/styles/image-editor/material3.css +171 -123
  158. package/styles/image-editor/material3.scss +1 -0
  159. package/styles/image-editor/tailwind-dark.css +154 -116
  160. package/styles/image-editor/tailwind-dark.scss +1 -0
  161. package/styles/image-editor/tailwind.css +154 -116
  162. package/styles/image-editor/tailwind.scss +1 -0
  163. package/styles/material-dark-lite.css +767 -0
  164. package/styles/material-dark-lite.scss +13 -0
  165. package/styles/material-dark.css +153 -108
  166. package/styles/material-dark.scss +1 -0
  167. package/styles/material-lite.css +769 -0
  168. package/styles/material-lite.scss +13 -0
  169. package/styles/material.css +159 -114
  170. package/styles/material.scss +1 -0
  171. package/styles/material3-dark-lite.css +799 -0
  172. package/styles/material3-dark-lite.scss +13 -0
  173. package/styles/material3-dark.css +171 -123
  174. package/styles/material3-dark.scss +1 -0
  175. package/styles/material3-lite.css +801 -0
  176. package/styles/material3-lite.scss +13 -0
  177. package/styles/material3.css +171 -123
  178. package/styles/material3.scss +1 -0
  179. package/styles/tailwind-dark-lite.css +751 -0
  180. package/styles/tailwind-dark-lite.scss +13 -0
  181. package/styles/tailwind-dark.css +154 -116
  182. package/styles/tailwind-dark.scss +1 -0
  183. package/styles/tailwind-lite.css +751 -0
  184. package/styles/tailwind-lite.scss +13 -0
  185. package/styles/tailwind.css +154 -116
  186. package/styles/tailwind.scss +1 -0
  187. package/hotfix/26.1.35_Vol2.txt +0 -1
@@ -1,11 +1,11 @@
1
1
  /*!
2
2
  * filename: ej2-image-editor.min.js
3
- * version : 26.2.10
3
+ * version : 27.1.48
4
4
  * Copyright Syncfusion Inc. 2001 - 2023. All rights reserved.
5
5
  * Use of this code is subject to the terms of our license.
6
6
  * A copy of the current license can be obtained at any time by e-mailing
7
7
  * licensing@syncfusion.com. Any infringement will be prosecuted under
8
8
  * applicable laws.
9
9
  */
10
- this.ej=this.ej||{},this.ej.imageeditor=function(e,t,o,i,r,a,n){"use strict";var s=function(){function e(e){this.croppedDegree=0,this.cropDestPoints={startX:0,startY:0,width:0,height:0},this.tempFlipPanPoint={x:0,y:0},this.isPreventScaling=!1,this.isInitCrop=!1,this.isTransformCrop=!1,this.parent=e,this.addEventListener()}return e.prototype.destroy=function(){this.parent.isDestroyed||this.removeEventListener()},e.prototype.addEventListener=function(){this.parent.on("crop",this.cropping,this),this.parent.on("destroyed",this.destroy,this)},e.prototype.removeEventListener=function(){this.parent.off("crop",this.cropping),this.parent.off("destroyed",this.destroy)},e.prototype.cropping=function(e){switch(this.updateCropPvtVar(),e.prop){case"cropCircle":this.cropCircle(e.value.context,e.value.isSave,e.value.isFlip);break;case"setCurrSelPoints":this.setCurrSelPoints(e.value.isSetDimension);break;case"updateRotatePan":this.updateRotatePan();break;case"crop":this.crop(e.value.obj);break;case"calcRatio":this.calcRatio(e.value.obj,e.value.dimension);break;case"isObjInImage":this.isObjInImage(e.value.obj,e.value.object);break;case"getCurrFlipState":this.getCurrFlipState(e.value.panObj);break;case"getPreviousCropCurrentObj":e.value.obj.prevObj=this.prevCropCurrObj;break;case"setPreviousCropCurrentObj":this.prevCropCurrObj=e.value.obj;break;case"setCropDestPoints":this.cropDestPoints=e.value.point;break;case"getTempFlipPanPoint":e.value.obj.point=this.tempFlipPanPoint;break;case"setTempFlipPanPoint":t.isNullOrUndefined(e.value.isAdd)?this.tempFlipPanPoint=e.value.point:(this.tempFlipPanPoint.x+=e.value.point.x,this.tempFlipPanPoint.y+=e.value.point.y);break;case"getPreventScaling":e.value.obj.bool=this.isPreventScaling;break;case"adjustStraightenForShapes":this.adjustStraightenForShapes(e.value.type,e.value.isInitialRotated);break;case"resizeWrapper":this.resizeWrapper();break;case"setTransformCrop":this.isTransformCrop=e.value.bool;break;case"setInitCrop":this.isInitCrop=e.value.bool;break;case"reset":this.reset()}},e.prototype.getModuleName=function(){return"crop"},e.prototype.updateCropPvtVar=function(){var e=this.parent;e.lowerCanvas&&(this.lowerContext=e.lowerCanvas.getContext("2d")),e.upperCanvas&&(this.upperContext=e.upperCanvas.getContext("2d"))},e.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},this.isPreventScaling=!1,this.isInitCrop=!1,this.isTransformCrop=!1},e.prototype.cropImg=function(e){for(var o=this.parent,i=t.isNullOrUndefined(e),r=o.element.querySelector("#"+o.element.id+"_nonaspectratio"),a=o.activeObj.activePoint,n=o.img,s=!1,l=0,p=o.rotateFlipColl.length;l<p;l++){var h=o.rotateFlipColl[l];90!==h&&-90!==h||(s=!0)}if(o.notify("draw",{prop:"setImageEdited",onPropertyChange:!1}),(i||r)&&(this.croppedDegree=o.transform.degree),i&&0!==o.transform.degree||s){this.updateCropObj();c={startX:n.destLeft,startY:n.destTop,width:n.destWidth,height:n.destHeight};o.notify("transform",{prop:"setCurrDestinationPoint",onPropertyChange:!1,value:{point:c}}),this.rotateCrop()}else if(i&&""!==o.transform.currFlipState){this.updateCropObj();c={startX:n.destLeft,startY:n.destTop,width:n.destWidth,height:n.destHeight};o.notify("transform",{prop:"setCurrDestinationPoint",onPropertyChange:!1,value:{point:c}}),this.flipCrop()}else{this.adjustStraightenForShapes("initial",!1),o.notify("draw",{prop:"setTempZoomFactor",onPropertyChange:!1,value:{tempZoomFactor:o.transform.zoomFactor}});var d=this.calcRatio();if(i||!e){this.updateCropObj(),o.notify("draw",{prop:"resetPanPoints",onPropertyChange:!1}),o.notify("shape",{prop:"updImgRatioForActObj",onPropertyChange:!1});var c={startX:n.destLeft,startY:n.destTop,width:n.destWidth,height:n.destHeight};o.notify("transform",{prop:"setCurrDestinationPoint",onPropertyChange:!1,value:{point:c}}),o.currSelectionPoint=t.extend({},o.activeObj,{},!0),this.cropDestPoints={startX:n.destLeft,startY:n.destTop,width:n.destWidth,height:n.destHeight}}var u={width:0,height:0};o.notify("transform",{prop:"calcMaxDimension",onPropertyChange:!1,value:{width:a.width*d.width,height:a.height*d.height,obj:u,isImgShape:null}});var v=u;this.upperContext.clearRect(0,0,o.upperCanvas.width,o.upperCanvas.height),this.lowerContext.clearRect(0,0,o.lowerCanvas.width,o.lowerCanvas.height),o.img={srcLeft:a.startX*d.width-n.destLeft*d.width,srcTop:a.startY*d.height-n.destTop*d.height,srcWidth:a.width*d.width,srcHeight:a.height*d.height,destLeft:(o.lowerCanvas.clientWidth-v.width)/2,destTop:(o.lowerCanvas.clientHeight-v.height+1)/2,destWidth:v.width,destHeight:v.height};var g=this.lowerContext.filter;o.notify("draw",{prop:"drawImage",onPropertyChange:!1}),this.lowerContext.filter="none";var f=t.extend({},o.activeObj,{},!0);this.cropObjColl(),o.transform.straighten=0,o.activeObj=f,this.cropFreehandDrawColl(),o.shapeColl=[],o.notify("shape",{prop:"updateShapeColl",onPropertyChange:!1}),o.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"zoom",pen:"zoom",isPreventApply:null}}),o.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.lowerContext}}),o.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.upperContext}}),o.currSelectionPoint&&"crop-circle"===o.currSelectionPoint.shape?this.cropCircle(this.lowerContext):o.isCircleCrop=!1,this.lowerContext.filter=g,o.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),o.currObjType.isCustomCrop=!1,o.pan(!1),o.transform.defaultZoomFactor=0}},e.prototype.adjustStraightenForShapes=function(e,t){for(var o=this.parent,i={x:o.img.destLeft+o.img.destWidth/2,y:o.img.destTop+o.img.destHeight/2},r=0,a=o.objColl;r<a.length;r++){var n=a[r];if(-1!==["rectangle","ellipse","text","image"].indexOf(n.shape)&&(t||0!==n.rotatedAngle)){var s=n.activePoint,l=s.startX,p=s.startY,h=s.width,d=s.height,c="initial"===e?n.rotatedAngle:-n.rotatedAngle,u=l+h/2-i.x,v=p+d/2-i.y,g=Math.cos(c),f=Math.sin(c),C=g*u-f*v+i.x-l-h/2,b=f*u+g*v+i.y-p-d/2;n.activePoint.startX+=C,n.activePoint.startY+=b,n.activePoint.endX+=C,n.activePoint.endY+=b}}},e.prototype.updateCropObj=function(){this.parent.afterCropActions=[];var e={currObj:{}};this.parent.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:e}});var o=e.currObj;o.straighten=this.parent.transform.straighten,this.parent.cropObj=t.extend({},o,{},!0)},e.prototype.rotateCrop=function(){var e=this.parent,o=this.getCurrFlipState(),i=e.activeObj.shape||"";e.notify("shape",{prop:"updImgRatioForActObj",onPropertyChange:!1}),e.currSelectionPoint=t.extend({},e.activeObj,{},!0),e.objColl.push(e.activeObj),e.activeObj=t.extend({},e.objColl[e.objColl.length-1],{},!0);var r=t.extend({},e.objColl[e.objColl.length-1],{},!0),a=t.extend({},e.currSelectionPoint,{},!0),n={bool:null};e.notify("transform",{prop:"getPreventSelect",onPropertyChange:!1,value:{obj:n}}),e.notify("transform",{prop:"setPreventSelect",onPropertyChange:!1,value:{bool:!0}});var s=t.extend([],e.rotateFlipColl,[],!0);this.panToSelRangle(!0),r=t.extend({},e.objColl[e.objColl.length-1],{},!0),this.upperContext.clearRect(0,0,e.upperCanvas.width,e.upperCanvas.height),e.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate",obj:r}}),e.objColl.pop(),e.notify("shape",{prop:"updImgRatioForActObj",onPropertyChange:!1}),e.objColl.push(e.activeObj);var l=e.transform.straighten;0!==l&&(e.transform.straighten=0,e.straightenBaseImageCanvas(),e.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"zoom",pen:"zoom",isPreventApply:null}}),e.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),e.notify("draw",{prop:"render-image",value:{isMouseWheel:!1}})),this.resetZoom();var p=t.extend([],e.afterCropActions,[],!0);this.revertTransform("initial",s),0!==l&&(e.transform.straighten="horizontal"===o||"vertical"===o?-l:l,e.straightenBaseImageCanvas(),e.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"zoom",pen:"zoom",isPreventApply:null}}),e.notify("draw",{prop:"render-image",value:{isMouseWheel:!1}}),e.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"zoom",pen:"zoom",isPreventApply:null}})),r=t.extend({},e.objColl[e.objColl.length-1],{},!0),this.upperContext.clearRect(0,0,e.upperCanvas.width,e.upperCanvas.height),e.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate",obj:r}}),e.objColl.pop(),e.transform.degree=0;var h={isIntersect:null};e.notify("draw",{prop:"updateImgCanvasPoints",onPropertyChange:!1}),e.notify("draw",{prop:"isLinesIntersect",onPropertyChange:!1,value:{obj:h}});for(var d=0;0!==l&&h.isIntersect&&50!=++d;)e.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:.025,zoomPoint:null},isResize:null}),e.notify("draw",{prop:"updateImgCanvasPoints",onPropertyChange:!1}),e.notify("draw",{prop:"isLinesIntersect",onPropertyChange:!1,value:{obj:h}});this.cropImg(!0),this.revertTransform("reverse",s),e.afterCropActions=p,e.currSelectionPoint=a,e.notify("transform",{prop:"setPreventSelect",onPropertyChange:!1,value:{bool:n.bool}}),e.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.lowerContext}}),e.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.upperContext}}),"crop-circle"===i&&this.cropCircle(this.lowerContext),this.upperContext.clearRect(0,0,e.upperCanvas.width,e.upperCanvas.height),e.notify("draw",{prop:"resetPanPoints",onPropertyChange:!1})},e.prototype.revertTransform=function(e,t){var o=this.parent,i={isRotate:!1};if("initial"===e)for(r=t.length-1;r>=0;r--)switch(n=t[r]){case 90:o.notify("transform",{prop:"rotate",value:{degree:-90,obj:i}});break;case-90:o.notify("transform",{prop:"rotate",value:{degree:90,obj:i}});break;default:o.notify("transform",{prop:"flipImage",value:{direction:o.toPascalCase(n.toString())}})}else{this.updateFlipState();for(var r=0,a=t.length;r<a;r++){var n=t[r];switch(n){case 90:o.notify("transform",{prop:"rotate",value:{degree:90,obj:i}});break;case-90:o.notify("transform",{prop:"rotate",value:{degree:-90,obj:i}});break;default:o.notify("transform",{prop:"flipImage",value:{direction:o.toPascalCase(n.toString())}})}}}},e.prototype.updateFlipState=function(){for(var e=this.parent,t=e.objColl,o=0,i=t.length;o<i;o++)t[o].shapeFlip="";for(var r=e.pointColl,o=0;o<e.freehandCounter;o++)r[o].shapeFlip=""},e.prototype.resetZoom=function(){var e=this.parent;if(e.transform.zoomFactor>0){var t=e.transform.zoomFactor,o=e.isUndoRedo;e.setProperties({zoomSettings:{zoomFactor:10*t}},!0),e.notify("transform",{prop:"setPreviousZoomValue",onPropertyChange:!1,value:{previousZoomValue:e.zoomSettings.zoomFactor}});for(var i=0;i<10*t;i++)e.isUndoRedo=!0,e.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:-.1,zoomPoint:null},isResize:null});e.isUndoRedo=o,e.notify("draw",{prop:"resetPanPoints",onPropertyChange:!1})}},e.prototype.flipCrop=function(){var e=this.parent;e.notify("transform",{prop:"setReverseFlip",onPropertyChange:!1,value:{isReverseFlip:!0}}),e.panPoint.totalPannedPoint.x+=this.tempFlipPanPoint.x,e.panPoint.totalPannedPoint.y+=this.tempFlipPanPoint.y;var o=e.transform.currFlipState,i={flipColl:null};e.notify("transform",{prop:"getFlipColl",onPropertyChange:!1,value:{obj:i}});var r=i.flipColl;if(e.notify("transform",{prop:"setFlipColl",onPropertyChange:!1,value:{flipColl:[]}}),e.notify("shape",{prop:"updImgRatioForActObj",onPropertyChange:!1}),e.objColl.push(e.activeObj),0===e.transform.degree){var a=-e.cropObj.totalPannedPoint.x,n=-e.cropObj.totalPannedPoint.y;e.img.destLeft+=a,e.img.destTop+=n,e.notify("transform",{prop:"drawPannImage",value:{point:{x:a,y:n}}}),e.activeObj=t.extend({},e.objColl[e.objColl.length-1],{},!0),this.upperContext.clearRect(0,0,e.upperCanvas.width,e.upperCanvas.height),e.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate",obj:e.activeObj}}),e.objColl.pop(),e.notify("shape",{prop:"updImgRatioForActObj",onPropertyChange:!1}),e.objColl.push(e.activeObj)}this.resetZoom(),e.currSelectionPoint=t.extend({},e.objColl[e.objColl.length-1],{},!0),this.lowerContext.clearRect(0,0,e.lowerCanvas.width,e.lowerCanvas.height),this.upperContext.clearRect(0,0,e.upperCanvas.width,e.upperCanvas.height);var s=this.lowerContext.filter;e.notify("draw",{prop:"drawImage",onPropertyChange:!1}),this.updateFlipState(),e.notify("shape",{prop:"redrawObj",onPropertyChange:!1,value:{degree:this.getCurrFlipState()}}),e.notify("freehand-draw",{prop:"flipFHDColl",onPropertyChange:!1,value:{value:this.getCurrFlipState()}}),e.activeObj=t.extend({},e.objColl[e.objColl.length-1],{},!0),e.objColl.pop(),this.upperContext.clearRect(0,0,e.upperCanvas.width,e.upperCanvas.height),e.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate"}}),this.cropImg(!0),e.notify("transform",{prop:"setReverseRotate",onPropertyChange:!1,value:{bool:!0}}),this.lowerContext.setTransform(1,0,0,1,0,0),e.notify("draw",{prop:"setDestPoints",onPropertyChange:!1}),e.notify("draw",{prop:"currTransState",onPropertyChange:!1,value:{type:"initial",isPreventDestination:null,context:null,isPreventCircleCrop:null}}),e.notify("draw",{prop:"drawImage",onPropertyChange:!1}),this.lowerContext.filter=s,e.notify("draw",{prop:"setRotateZoom",onPropertyChange:!1,value:{isRotateZoom:!1}}),e.notify("draw",{prop:"currTransState",onPropertyChange:!1,value:{type:"reverse",isPreventDestination:null,context:null,isPreventCircleCrop:null}}),e.transform.currFlipState=o,e.notify("transform",{prop:"setFlipColl",onPropertyChange:!1,value:{flipColl:r}}),this.lowerContext.filter="none",this.updateFlipState(),e.notify("shape",{prop:"redrawObj",onPropertyChange:!1,value:{degree:this.getCurrFlipState()}}),e.notify("freehand-draw",{prop:"flipFHDColl",onPropertyChange:!1,value:{value:this.getCurrFlipState()}}),e.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"zoom",pen:"zoom",isPreventApply:null}}),this.lowerContext.filter=s,(e.currSelectionPoint&&"crop-circle"===e.currSelectionPoint.shape||e.isCircleCrop)&&this.cropCircle(this.lowerContext),e.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),e.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.lowerContext}}),e.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.upperContext}}),this.upperContext.clearRect(0,0,e.upperCanvas.width,e.upperCanvas.height),e.notify("transform",{prop:"setReverseFlip",onPropertyChange:!1,value:{isReverseFlip:!1}}),e.notify("draw",{prop:"resetPanPoints",onPropertyChange:!1}),this.tempFlipPanPoint={x:0,y:0}},e.prototype.cropObjColl=function(){var e,t,o,i=this.parent;if(i.objColl.length>0)for(var r=0,a=i.objColl.length;r<a;r++){e=(o=i.objColl[r]).activePoint;var n=i.activeObj.activePoint,s=n.startX,l=n.startY,p=n.width,h=n.height;t=o.shape,o.imageRatio={startX:(e.startX-s)/p,startY:(e.startY-l)/h,endX:(e.endX-s)/p,endY:(e.endY-l)/h,width:p/e.width,height:h/e.height};var d=void 0,c=void 0;switch(t){case"text":c=0===(d=0===o.shapeDegree?i.transform.degree:i.transform.degree-o.shapeDegree)||180===Math.abs(d)?e.width:e.height,o.textSettings.fontRatio=c/o.textSettings.fontSize;break;case"line":case"arrow":this.cropPointCollection(r),"arrow"===t&&i.notify("shape",{prop:"updateArrowRatio",onPropertyChange:!1,value:{obj:o}});break;case"path":this.cropPointCollection(r)}}},e.prototype.cropPointCollection=function(e){var t,o,i,r,a=this.parent,n=a.objColl[e].shape,s=a.activeObj.activePoint,l=a.img,p=l.destLeft,h=l.destTop,d=l.destWidth,c=l.destHeight;"path"===n?(t=s.startX,o=s.startY,i=s.width,r=s.height):(t=p,o=h,i=d,r=c);for(var u=a.objColl[e].pointColl,v=0,g=u.length;v<g;v++)u[v].ratioX=(u[v].x-t)/i,u[v].ratioY=(u[v].y-o)/r},e.prototype.cropFreehandDrawColl=function(){for(var e=this.parent,o=e.activeObj.activePoint,i=o.startX,r=o.startY,a=o.width,n=o.height,s=0;s<e.freehandCounter;s++){e.points=t.extend([],e.pointColl[s].points,[]),e.notify("freehand-draw",{prop:"setPointCounter",onPropertyChange:!1,value:{value:0}});for(var l=e.points.length,p=0;p<l;p++)e.points[p].ratioX=(e.points[p].x-i)/a,e.points[p].ratioY=(e.points[p].y-r)/n}e.notify("freehand-draw",{prop:"updateCropPtsForSel",onPropertyChange:!1})},e.prototype.resetAnnotations=function(){var e=this.parent;e.objColl=[],e.pointColl=[],e.freehandCounter=0,e.notify("freehand-draw",{prop:"resetStraightenPoint"})},e.prototype.setCurrSelPoints=function(e){var o=this.parent;o.allowDownScale=!1;var i=this.cropDestPoints,r=this.lowerContext.filter,a=o.isCropTab;o.img={srcLeft:0,srcTop:0,srcWidth:o.baseImgCanvas.width,srcHeight:o.baseImgCanvas.height,destLeft:i.startX,destTop:i.startY,destWidth:i.width,destHeight:i.height};var n=o.img,s=o.currSelectionPoint;this.lowerContext.clearRect(0,0,o.lowerCanvas.width,o.lowerCanvas.height),e&&o.notify("draw",{prop:"setDestPoints",onPropertyChange:!1}),o.notify("draw",{prop:"currTransState",onPropertyChange:!1,value:{type:"initial",isPreventDestination:null,context:null,isPreventCircleCrop:null}}),0===this.croppedDegree&&0===o.transform.degree&&s&&"crop-circle"!==s.shape&&"crop-square"!==s.shape&&(n.destLeft=i.startX,n.destTop=i.startY,n.destWidth=i.width,n.destHeight=i.height),0===o.transform.degree&&(n.destLeft+=o.panPoint.totalPannedInternalPoint.x,n.destTop+=o.panPoint.totalPannedInternalPoint.y),o.notify("draw",{prop:"drawImage",onPropertyChange:!1}),this.lowerContext.filter=r,o.notify("draw",{prop:"currTransState",onPropertyChange:!1,value:{type:"reverse",isPreventDestination:null,context:null,isPreventCircleCrop:!0}});var l=t.extend([],o.objColl,null,!0),p=t.extend([],o.pointColl,null,!0),h={straightenPoint:null};if(o.notify("freehand-draw",{prop:"getStraightenPoint",onPropertyChange:!1,value:{obj:h}}),this.resetAnnotations(),t.isNullOrUndefined(o.activeObj.shape)&&o.cropObj.activeObj.shape&&(o.activeObj=t.extend({},o.cropObj.activeObj,null,!0)),this.panToSelRangle(),o.isCropTab=a,o.objColl=l,o.pointColl=p,o.freehandCounter=o.pointColl.length,h.straightenPoint.x&&h.straightenPoint.y&&o.notify("freehand-draw",{prop:"setStraightenPoint",onPropertyChange:!1,value:{x:h.straightenPoint.x,y:h.straightenPoint.y,ratioX:h.straightenPoint.ratioX,ratioY:h.straightenPoint.ratioY}}),o.cropObj.activeObj.shape){var d={startX:n.destLeft,startY:n.destTop,width:n.destWidth,height:n.destHeight};if(s&&s.activePoint){var c=s.activePoint,u=c.startX,v=c.startY,g=c.width,f=c.height;n.destLeft=u,n.destTop=v,n.destWidth=g,n.destHeight=f}o.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"zoom",pen:"zoom",isPreventApply:null}}),n.destLeft=d.startX,n.destTop=d.startY,n.destWidth=d.width,n.destHeight=d.height,o.notify("freehand-draw",{prop:"updateFHDColl",onPropertyChange:!1}),l=t.extend([],o.objColl,null,!0),p=t.extend([],o.pointColl,null,!0),o.notify("freehand-draw",{prop:"getStraightenPoint",onPropertyChange:!1,value:{obj:h}}),this.resetAnnotations();var C={selPointColl:null};o.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:C}});var b=C.selPointColl;o.notify("freehand-draw",{prop:"setSelPointColl",onPropertyChange:!1,value:{obj:{selPointColl:[]}}}),o.cropObj.filter=this.lowerContext.filter;var m=t.extend({},o.currSelectionPoint,null,!0);o.notify("draw",{prop:"setCurrentObj",onPropertyChange:!1,value:{obj:null}}),o.activeObj=t.extend({},m,null,!0);var y=t.extend({},o.activeObj,null,!0);if(o.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),o.currSelectionPoint=null,o.isCircleCrop=!1,0!==o.transform.degree&&(t.isNullOrUndefined(o.activeObj.shape)&&o.cropObj.activeObj.shape&&(o.activeObj=t.extend({},o.cropObj.activeObj,null,!0)),o.notify("transform",{prop:"drawPannedImage",value:{xDiff:0,yDiff:0}}),o.panPoint.currentPannedPoint={x:0,y:0}),o.objColl=l,o.pointColl=p,o.freehandCounter=o.pointColl.length,h.straightenPoint.x&&h.straightenPoint.y&&o.notify("freehand-draw",{prop:"setStraightenPoint",onPropertyChange:!1,value:{x:h.straightenPoint.x,y:h.straightenPoint.y,ratioX:h.straightenPoint.ratioX,ratioY:h.straightenPoint.ratioY}}),o.notify("freehand-draw",{prop:"setSelPointColl",onPropertyChange:!1,value:{obj:{selPointColl:b}}}),o.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"iterate",pen:"iterate",isPreventApply:null}}),this.adjustStraightenForShapes("reverse",!1),o.notify("freehand-draw",{prop:"updateFHDColl",onPropertyChange:!1,value:{isPreventApply:!0}}),o.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"zoom",pen:"zoom",isPreventApply:null}}),0===o.transform.degree?o.notify("transform",{prop:"drawPannImage",onPropertyChange:!1,value:{point:{x:0,y:0}}}):(t.isNullOrUndefined(o.activeObj.shape)&&o.cropObj.activeObj.shape&&(o.activeObj=t.extend({},o.cropObj.activeObj,null,!0)),o.notify("transform",{prop:"drawPannedImage",value:{xDiff:0,yDiff:0}}),o.panPoint.currentPannedPoint={x:0,y:0}),o.activeObj=y,o.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate"}}),o.notify("transform",{prop:"setTempPanMove",onPropertyChange:!1,value:{point:null}}),this.isInitCrop||0!==o.transform.degree||""===o.cropObj.currFlipState||0===o.cropObj.cropZoom)this.isInitCrop=!1;else{this.isInitCrop=!0;var P={activeObj:null};o.notify("draw",{prop:"getStraightenActObj",onPropertyChange:!1,value:{obj:P}}),o.notify("draw",{prop:"performCancel",value:{isContextualToolbar:null}}),o.notify("draw",{prop:"setStraightenActObj",onPropertyChange:!1,value:{activeObj:P.activeObj}}),o.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"croptransform",isApplyBtn:!1,isCropping:null,isZooming:null,cType:null}})}}else{this.adjustStraightenForShapes("reverse",!0),o.notify("freehand-draw",{prop:"updateFHDColl",onPropertyChange:!1,value:{isPreventApply:!0}});var j=this.lowerContext.filter;this.lowerContext.filter="none",o.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"iterate",pen:"iterate",isPreventApply:null}}),this.lowerContext.filter=j,o.currSelectionPoint=null}document.querySelector(".e-ie-straighten-value-span")&&(document.querySelector(".e-ie-straighten-value-span").innerHTML=o.transform.straighten.toString()+"&#176")},e.prototype.panToSelRangle=function(e){var t=this.parent,o=t.cropObj.totalPannedClientPoint,i=0!==t.transform.degree?e?-o.x:o.x:0,r=0!==t.transform.degree?e?-o.y:o.y:0;0!==t.transform.degree&&(t.panPoint.currentPannedPoint={x:i,y:r},t.notify("transform",{prop:"drawPannedImage",value:{xDiff:i,yDiff:r}}),t.panPoint.currentPannedPoint={x:0,y:0})},e.prototype.cropCircle=function(e,o,i){var r=this.parent,a=r.img,n=a.destLeft,s=a.destTop,l=a.destWidth,p=a.destHeight;i&&""!==r.transform.currFlipState&&r.notify("draw",{prop:"setTransform",onPropertyChange:!1,value:{context:e,value:r.transform.currFlipState,isReverse:null}});var h=e.filter;e.filter="none",e.globalCompositeOperation="destination-in",e.beginPath();var d=t.isNullOrUndefined(o)?n+l/2:e.canvas.width/2,c=t.isNullOrUndefined(o)?s+p/2:e.canvas.height/2,u=o?e.canvas.width/2:l/2;e.arc(d,c,u,0,2*Math.PI),e.closePath(),e.fill(),e.restore(),e.globalCompositeOperation="source-over",r.currObjType.isActiveObj=r.isCircleCrop=!0,e.filter=h,i&&""!==r.transform.currFlipState&&r.notify("draw",{prop:"setTransform",onPropertyChange:!1,value:{context:e,value:r.transform.currFlipState,isReverse:null}})},e.prototype.getCurrCropState=function(){var e=this.parent,t="",o={flipColl:null};return e.notify("transform",{prop:"getFlipColl",onPropertyChange:!1,value:{obj:o}}),t=this.getCurrFlipState(),-90!==e.transform.degree&&-270!==e.transform.degree||("horizontal"===t?t="vertical":"vertical"===t&&(t="horizontal")),""===t&&(t=o.flipColl.length>1?this.getCurrFlipState():e.transform.currFlipState),t},e.prototype.updateRotatePan=function(){var e=this.parent;if(!t.isNullOrUndefined(e.panPoint.currentPannedPoint)){var o="",i=e.transform.degree,r=e.panPoint.currentPannedPoint,a=r.x,n=r.y;o=e.rotateFlipColl.length>0&&"number"==typeof e.rotateFlipColl[0]&&i<0?this.getCurrCropState():this.getCurrFlipState(),i%90==0&&i%180!=0?90===i||-90===i&&("horizontal"===o||"vertical"===o)||-270===i&&(""===o||"verticalHorizontal"===o||"horizontalVertical"===o)?("horizontal"===o||""===o?e.img.destLeft+=n:e.img.destLeft-=n,""===o||"vertical"===o?e.img.destTop-=a:e.img.destTop+=a):270!==i&&(-270!==i||"horizontal"!==o&&"vertical"!==o)&&(-90!==i||""!==o&&"verticalHorizontal"!==o&&"horizontalVertical"!==o)||(""===o||"horizontal"===o?e.img.destLeft-=n:e.img.destLeft+=n,""===o||"vertical"===o?e.img.destTop+=a:e.img.destTop-=a):180!==i&&-180!==i||(""===o||"vertical"===o?e.img.destLeft-=a:e.img.destLeft+=a,""===o||"horizontal"===o?e.img.destTop-=n:e.img.destTop+=n)}},e.prototype.crop=function(e){var t=this.parent,o=t.activeObj.activePoint,i=o.startX,r=o.startY,a=o.endX,n=o.endY;if(!t.disabled&&t.isImageLoaded){var s={isCropToolbar:t.isCropToolbar};t.currObjType.isUndoAction&&!s.isCropToolbar&&t.notify("undo-redo",{prop:"refreshUrc",value:{bool:null}});var l={cancel:!1,startPoint:{x:i,y:r},endPoint:{x:a,y:n},preventScaling:!1};s.isCropToolbar||t.trigger("cropping",l),this.cropEvent(l,e,s)}},e.prototype.cropEvent=function(e,o,i){var r,a=this.parent;if(!e.cancel&&(r=a.activeObj.shape?a.activeObj.shape.split("-"):[],!a.disabled&&a.activeObj.horTopLine&&(a.currObjType.isCustomCrop||r.length>0&&"crop"===r[0]))){o.isCrop=!0;var n=t.extend({},a.cropObj,{},!0),s=t.extend({},this.prevCropCurrObj,{},!0);e.preventScaling?this.isPreventScaling=!0:this.isPreventScaling=!1,this.cropImg(),this.isPreventScaling&&(a.aspectWidth=a.img.destWidth,a.aspectHeight=a.img.destHeight),a.notify("freehand-draw",{prop:"resetStraightenPoint"}),a.isCropTab=!1,a.transform.zoomFactor=0,a.setProperties({zoomSettings:{zoomFactor:1}},!0),a.notify("transform",{prop:"setPreviousZoomValue",onPropertyChange:!1,value:{previousZoomValue:a.zoomSettings.zoomFactor}}),t.Browser.isDevice||this.updateUndoRedoColl(s,n,i),a.notify("transform",{prop:"setCropDimension",onPropertyChange:!1,value:{width:a.cropObj.destPoints.width,height:a.cropObj.destPoints.height}});var l=a.element.querySelector("#"+a.element.id+"_aspectratio"),p=a.element.querySelector("#"+a.element.id+"_nonaspectratio");a.notify("draw",{prop:"render-image",value:{isMouseWheel:!1}}),!i.isCropToolbar&&t.isNullOrUndefined(l)&&t.isNullOrUndefined(p)&&a.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"main",isApplyBtn:!1,isCropping:!1,isZooming:null,cType:null}}),this.resizeWrapper(),t.Browser.isDevice&&this.updateUndoRedoColl(s,n,i)}},e.prototype.updateUndoRedoColl=function(e,o,i){var r=this.parent,a={prevCurrSelectionPoint:r.prevCurrSelectionPoint};e.currSelectionPoint=t.extend({},a.prevCurrSelectionPoint,{},!0),r.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"crop",previousObj:e,previousObjColl:e.objColl,previousPointColl:e.pointColl,previousSelPointColl:e.selPointColl,previousCropObj:o,previousText:null,currentText:null,previousFilter:null,isCircleCrop:r.isCircleCrop}}),i.isCropToolbar||r.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"ok"}})},e.prototype.resizeWrapper=function(){var e=this.parent;if(t.Browser.isDevice){var o=e.element,i=o.querySelector("#"+o.id+"_contextualToolbarArea");i&&""===i.style.position&&!this.isTransformCrop&&(i.style.position="absolute",e.isStraightening=!1,e.update(),e.notify("filter",{prop:"setAdjustmentValue",value:{adjustmentValue:e.canvasFilter}}))}},e.prototype.calcRatio=function(e,t){var o=this.parent,i=o.transform.degree,r=o.img,a=r.destWidth,n=r.destHeight,s=t||o.baseImgCanvas,l=s.width,p=s.height,h=0===i||i%180==0?l/a:p/a,d=0===i||i%180==0?p/n:l/n;return e&&(e.width=h,e.height=d),{width:h,height:d}},e.prototype.isObjInImage=function(e,t){var o=this.parent.img,i=o.destLeft,r=o.destTop,a=o.destWidth,n=o.destHeight,s=e.activePoint,l=s.startX,p=s.endX,h=s.startY,d=s.endY,c=l>=i&&p<=i+a||l<=i&&p>=i||l<=i+a&&p>=i+a||h>=r&&d<=r+n||h<=r&&d>=r||h<=r+n&&d>=r+n;return t&&(t.isInside=c),c},e.prototype.getCurrFlipState=function(e){var t=this.parent,o={panRegion:""},i={collection:t.rotateFlipColl};t.notify("shape",{prop:"alignRotateFlipColl",onPropertyChange:!1,value:{collection:t.rotateFlipColl,isRotateFlipCollection:!0,obj:i}}),t.rotateFlipColl=i.collection;for(var r=0,a=t.rotateFlipColl.length;r<a;r++)t.notify("transform",{prop:"setCurrPanRegion",onPropertyChange:!1,value:{region:o.panRegion,type:t.rotateFlipColl[r],obj:o}});return e&&(e.panRegion=o.panRegion),o.panRegion},e}(),l=function(e,t,o,i){return new(o||(o=Promise))(function(r,a){function n(e){try{l(i.next(e))}catch(e){a(e)}}function s(e){try{l(i.throw(e))}catch(e){a(e)}}function l(e){e.done?r(e.value):new o(function(t){t(e.value)}).then(n,s)}l((i=i.apply(e,t||[])).next())})},p=function(e,t){function o(e){return function(t){return i([e,t])}}function i(o){if(r)throw new TypeError("Generator is already executing.");for(;l;)try{if(r=1,a&&(n=2&o[0]?a.return:o[0]?a.throw||((n=a.return)&&n.call(a),0):a.next)&&!(n=n.call(a,o[1])).done)return n;switch(a=0,n&&(o=[2&o[0],n.value]),o[0]){case 0:case 1:n=o;break;case 4:return l.label++,{value:o[1],done:!1};case 5:l.label++,a=o[1],o=[0];continue;case 7:o=l.ops.pop(),l.trys.pop();continue;default:if(n=l.trys,!(n=n.length>0&&n[n.length-1])&&(6===o[0]||2===o[0])){l=0;continue}if(3===o[0]&&(!n||o[1]>n[0]&&o[1]<n[3])){l.label=o[1];break}if(6===o[0]&&l.label<n[1]){l.label=n[1],n=o;break}if(n&&l.label<n[2]){l.label=n[2],l.ops.push(o);break}n[2]&&l.ops.pop(),l.trys.pop();continue}o=t.call(e,l)}catch(e){o=[6,e],a=0}finally{r=n=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}var r,a,n,s,l={label:0,sent:function(){if(1&n[0])throw n[1];return n[1]},trys:[],ops:[]};return s={next:o(0),throw:o(1),return:o(2)},"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s},h=function(){function e(e){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:"",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.isResizeSelect=!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.origDim={width:0,height:0},this.isImageApply=!1,this.imgCanvasPoints=[],this.isCropSelect=!1,this.isDownScale=!1,this.preventStraightening=!1,this.tempObjColl=[],this.tempPointColl={},this.parent=e,this.addEventListener()}return e.prototype.destroy=function(){this.parent.isDestroyed||this.removeEventListener()},e.prototype.addEventListener=function(){this.parent.on("draw",this.draw,this),this.parent.on("destroyed",this.destroy,this)},e.prototype.removeEventListener=function(){this.parent.off("draw",this.draw),this.parent.off("destroyed",this.destroy)},e.prototype.draw=function(e){switch(this.updatePrivateVariables(),e.prop){case"drawObject":this.drawObject(e.value.canvas,e.value.obj,e.value.isCropRatio,e.value.points,e.value.isPreventDrag,e.value.saveContext,e.value.isPreventSelection);break;case"updateActiveObject":this.updateActiveObject(e.value.actPoint,e.value.obj,e.value.isMouseMove,e.value.x,e.value.y);break;case"clearOuterCanvas":this.clearOuterCanvas(e.value.context);break;case"setDestPoints":this.setDestPoints();break;case"updateCurrTransState":this.updateCurrTransState(e.value.type,e.value.isPreventDestination,e.value.isRotatePan);break;case"currTransState":this.currTransState(e.value.type,e.value.isPreventDestination,e.value.context,e.value.isPreventCircleCrop);break;case"setTransform":this.setTransform(e.value.context,e.value.value,e.value.isReverse);break;case"render-image":this.renderImage(e.value.isMouseWheel,e.value.isPreventClearRect,e.value.isFrame,e.value.isStraighten);break;case"draw-image-to-canvas":this.drawImgToCanvas(e.value.dimension);break;case"update-canvas":this.updateCanvas();break;case"performCancel":this.performCancel(e.value.isContextualToolbar,e.value.isUndoRedo,e.value.isFinalCancel);break;case"updateFlipPan":this.updateFlipPan(e.value.tempSelectionObj);break;case"select":this.select(e.value.type,e.value.startX,e.value.startY,e.value.width,e.value.height);break;case"callUpdateCurrTransState":this.callUpdateCurrTransState();break;case"resetPanPoints":this.resetPanPoints();break;case"setClientTransDim":this.setClientTransDim(e.value.isPreventDimension);break;case"redrawImgWithObj":this.redrawImgWithObj();break;case"setCurrentObj":this.setCurrentObj(e.value.obj,e.value.isUndoRedo);break;case"performPointZoom":this.performPointZoom(e.value.x,e.value.y,e.value.type,e.value.isResize);break;case"open":this.open(e.value.data);break;case"isInitialLoading":this.isInitialLoading=e.value.isInitialLoading;break;case"isInitialLoaded":this.getInitialLoaded(e.value.object);break;case"fileSelect":this.fileSelect(e.value.inputElement,e.value.args);break;case"getFileName":e.value.obj.fileName=this.fileName,e.value.obj.fileType=this.fileType;break;case"getErrorImage":e.value.obj.isErrorImage=this.isErrorImage;break;case"getInitialZoomValue":e.value.obj.initialZoomValue=this.initZoomValue;break;case"setShapeTextInsert":this.isShapeTextInserted=e.value.bool;break;case"resetCurrentSelectionPoint":this.currSelPoint=null;break;case"setRotateZoom":this.isRotateZoom=e.value.isRotateZoom;break;case"setTempStrokeSettings":this.tempStrokeSettings=e.value.tempStrokeSettings;break;case"setTempTextSettings":this.tempTextSettings=e.value.tempTextSettings;break;case"setTempAdjustmentValue":this.tempAdjValue=e.value.tempAdjustmentValue;break;case"getTempAdjustmentValue":e.value.obj.value=this.tempAdjValue;break;case"setTempFilter":this.tempFilter=e.value.tempFilter;break;case"setTempUndoRedoStep":this.tempUndoRedoStep=e.value.tempUndoRedoStep;break;case"setTempFreehandCounter":this.tempFreehandCounter=e.value.tempFreehandCounter;break;case"setTempCurrentFreehandDrawIndex":this.tempCurrFhdIndex=e.value.tempCurrentFreehandDrawIndex;break;case"setTempZoomFactor":this.tempZoomFactor=e.value.tempZoomFactor;break;case"setCancelAction":this.isCancelAction=e.value.bool;break;case"getRotatedFlipCropSelection":e.value.bool.isSelected=this.rotatedFlipCropSel;break;case"getPrevActObj":e.value.obj.prevActObj=this.prevActObj;break;case"setPrevActObj":this.prevActObj=e.value.prevActObj;break;case"setZoomCropWidth":this.zoomCrop.width=e.value.width,this.zoomCrop.height=e.value.height;break;case"setImageEdited":this.isImageEdited=!0;break;case"reset":this.reset();break;case"setNewPath":this.isNewPath=e.value.bool;break;case"getNewPath":e.value.obj.isNewPath=this.isNewPath;break;case"getArrowDimension":e.value.obj.arrowDimension=t.extend({},this.arrowDimension,{},!0);break;case"setArrowDimension":this.arrowDimension=e.value.arrowDimension;break;case"moveToSelectionRange":this.moveToSelectionRange(e.value.type,e.value.activeObj);break;case"setResizeSelect":this.isResizeSelect=e.value.bool;break;case"applyFrame":this.applyFrame(e.value.ctx,e.value.frame,e.value.preventImg);break;case"drawImage":this.drawImage();break;case"downScaleImgCanvas":this.downScaleImgCanvas(e.value.ctx,e.value.isImgAnnotation,e.value.isHFlip,e.value.isVFlip);break;case"downScale":this.downScale(e.value.canvas,e.value.width,e.value.height);break;case"resetFrameZoom":this.resetFrameZoom(e.value.isOk);break;case"triggerFrameChange":e.value.obj.frameChangeEventArgs=this.triggerFrameChange(e.value.prevFrameSettings);break;case"setImageApply":this.isImageApply=e.value.bool;break;case"zoomToSel":this.zoomToSel(e.value.activeObj,e.value.isToolbar);break;case"getStraightenActObj":e.value.obj.activeObj=this.straightenActObj;break;case"setStraightenActObj":this.straightenActObj=e.value.activeObj;break;case"updateImgCanvasPoints":this.updateImgCanvasPoints();break;case"isLinesIntersect":e.value.obj.isIntersect=this.isLinesIntersect(e.value.obj);break;case"getImageCanvasPoints":e.value.obj.points=this.imgCanvasPoints;break;case"setDestForStraighten":this.setDestForStraighten();break;case"setTempDestForStraighten":this.tempStraightenDestPoints=t.extend({},this.straightenDestPoints,{},!0);break;case"getStraightenInitZoom":e.value.obj.zoomFactor=this.straightenInitZoom;break;case"setStraightenInitZoom":this.straightenInitZoom=e.value.zoomFactor;break;case"isPointsInsideImg":e.value.obj.bool="inside"!==this.checkPointPosition(e.value.x,e.value.y,this.imgCanvasPoints[0].x,this.imgCanvasPoints[0].y,this.imgCanvasPoints[1].x,this.imgCanvasPoints[1].y,this.imgCanvasPoints[2].x,this.imgCanvasPoints[2].y,this.imgCanvasPoints[3].x,this.imgCanvasPoints[3].y);break;case"setIsCropSelect":this.isCropSelect=e.value.bool;break;case"updateCropSelection":this.updateCropSelection();break;case"updateCropSelObj":this.updateCropSelObj();break;case"redrawDownScale":this.redrawDownScale();break;case"updateFinetune":this.updateFinetune();break;case"isSelOutsideImg":e.value.obj.bool=this.isSelOutsideImg();break;case"resetStraightenDestPoints":this.straightenDestPoints=null;break;case"checkPointPosition":e.value.obj.position=this.checkPointPosition(e.value.obj.x,e.value.obj.y,e.value.obj.x1,e.value.obj.y1,e.value.obj.x2,e.value.obj.y2,e.value.obj.x3,e.value.obj.y3,e.value.obj.x4,e.value.obj.y4);break;case"updateTempObjColl":this.tempObjColl=t.extend([],this.parent.objColl,[],!0);break;case"resetTempObjColl":this.tempObjColl=null;break;case"updateTempPointColl":this.tempPointColl=t.extend({},this.parent.pointColl,{},!0);break;case"resetTempPointColl":this.tempPointColl={}}},e.prototype.getModuleName=function(){return"draw"},e.prototype.updatePrivateVariables=function(){var e=this.parent;e.lowerCanvas&&(this.lowerContext=e.lowerCanvas.getContext("2d")),e.upperCanvas&&(this.upperContext=e.upperCanvas.getContext("2d")),t.isNullOrUndefined(this.tempZoomFactor)&&(this.tempZoomFactor=e.transform.zoomFactor),""===this.tempTextSettings.fontFamily&&(this.tempTextSettings.fontFamily=e.fontFamily.default)},e.prototype.reset=function(){this.isInitialLoading=this.isErrorImage=this.isNewPath=this.isResizeSelect=!1,this.isShapeTextInserted=!1,this.isImageApply=!1,this.initZoomValue=null,this.tempFilter="",this.origDim={width:0,height:0},this.currSelPoint=null,this.isRotateZoom=!1,this.tempAdjValue="",this.tempStrokeSettings={strokeColor:"#fff",fillColor:"",strokeWidth:null},this.tempTextSettings={text:"Enter Text",fontFamily:this.parent.fontFamily.default,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.tempStraightenDestPoints=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}},this.straightenActObj=null,this.imgCanvasPoints=[],this.straightenInitZoom=null,this.tempObjColl=[],this.tempPointColl={},this.straightenDestPoints=null,this.isCropSelect=this.isDownScale=this.preventStraightening=!1},e.prototype.redrawDownScale=function(){var e=this.parent;if(e.transform.zoomFactor&&e.transform.zoomFactor<0){var o=t.extend({},e.activeObj,{},!0);e.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),this.isDownScale=!0,this.renderImage(),this.isDownScale=!1,o.shape&&this.drawObject("duplicate",o)}},e.prototype.updateFinetune=function(){var e=this.parent;if(e.transform.zoomFactor&&e.transform.zoomFactor<0){var t=this.lowerContext.filter;this.lowerContext.filter="none",e.notify("draw",{prop:"redrawDownScale"});var o=e.inMemoryCanvas.getContext("2d"),i=this.lowerContext,r=i.getImageData(0,0,i.canvas.width,i.canvas.height);e.inMemoryCanvas.width=r.width,e.inMemoryCanvas.height=r.height,o.putImageData(r,0,0),this.lowerContext.filter=t,e.notify("draw",{prop:"redrawDownScale"})}},e.prototype.drawImage=function(){this.applyFrame(this.lowerContext,this.parent.frameObj.type)},e.prototype.drawObject=function(e,o,i,r,a,n,s){var l=this.parent,p=l.activeObj,h=l.activeObj.activePoint;this.upperContext.clearRect(0,0,l.upperCanvas.width,l.upperCanvas.height);var d;if(e=e.toLowerCase(),"original"===e?d=this.lowerContext:"duplicate"===e?d=this.upperContext:n&&(d=n),!a&&p.shape&&this.setDragLimit(),l.currObjType.shape&&"crop"===l.currObjType.shape.split("-")[0].toLowerCase()&&i&&this.drawCropRatio(),p=l.activeObj,h=l.activeObj.activePoint,t.isNullOrUndefined(p.strokeSettings)){var c={strokeSettings:{}};l.notify("shape",{prop:"getStrokeSettings",onPropertyChange:!1,value:{obj:c}}),p.strokeSettings=c.strokeSettings}if(t.isNullOrUndefined(p.strokeSettings.strokeWidth)&&(p.strokeSettings.strokeWidth=2),o&&(l.activeObj=t.extend({},o,{},!0)),r&&r.startX&&r.startY&&r.endX&&r.endY&&r.width&&r.height&&(h.startX=r.startX,h.startY=r.startY,h.endX=r.endX,h.endY=r.endY,h.width=r.width,h.height=r.height),this.updateActiveObject(),p=l.activeObj,h=l.activeObj.activePoint,!t.isNullOrUndefined(h.startX)||!t.isNullOrUndefined(h.startY)){if(l.currObjType.isText){var u={keyHistory:""};l.notify("shape",{prop:"getKeyHistory",onPropertyChange:!1,value:{obj:u}}),p.keyHistory=u.keyHistory}var v=!1;if("original"!==e){p.shape&&"crop"===p.shape.split("-")[0]&&(v=!0),v&&(r&&r.startX&&r.startY&&r.endX&&r.endY&&r.width&&r.height?(h.startX=r.startX,h.startY=r.startY,h.endX=r.endX,h.endY=r.endY,h.width=r.width,h.height=r.height):h=p.activePoint,this.upperContext.fillStyle="rgb(0, 0, 0, 0.25)",this.upperContext.fillRect(0,0,l.lowerCanvas.width,l.lowerCanvas.height),this.upperContext.clearRect(h.startX,h.startY,h.width,h.height)),!t.isNullOrUndefined(s)||d!==this.lowerContext&&d!==this.upperContext||(this.rotateContext("initial",d),this.drawOuterSelection(d),this.rotateContext("reverse",d))}l.currObjType.isActiveObj=!0;var g={keyHistory:""};l.notify("shape",{prop:"getKeyHistory",onPropertyChange:!1,value:{obj:g}}),o?this.drawShapeObj(e,o.shape,n,s):""!==g.keyHistory&&l.currObjType.isText?this.drawShapeObj(e,"text",n,s):p.shape?this.drawShapeObj(e,p.shape,n,s):this.drawShapeObj(e,void 0,n,s),"duplicate"===e&&v&&"crop-circle"!==p.shape&&"none"!==l.frameObj.type&&(this.applyFrame(this.upperContext,l.frameObj.type),this.drawCornerCircles(this.upperContext))}},e.prototype.rotateContext=function(e,t){var o=this.parent,i=o.activeObj,r=i.shape,a=i.rotatedAngle,n=o.img,s=n.destLeft,l=n.destTop,p=n.destWidth,h=n.destHeight,d=o.activeObj.activePoint,c=d.startX,u=d.startY,v=d.width,g=d.height;if("line"!==r&&"arrow"!==r){var f,C,b="initial"===e?a:-a;0!==o.transform.straighten||o.isCropTab?(f=s+p/2,C=l+h/2):(f=c+v/2,C=u+g/2),t.translate(f,C),t.rotate(b),t.translate(-f,-C)}},e.prototype.setDragLimit=function(){var e=this.parent,t=e.activeObj.activePoint,o=e.activeObj,i=o.shape,r=o.rotatedAngle;if(t&&"image"!==i&&"line"!==i&&0===r){var a=e.img,n=a.destLeft,s=a.destTop,l=a.destWidth,p=a.destHeight;t.startX<n?(t.startX=n,t.endX=Math.min(t.startX+t.width,n+l)):t.endX>n+l&&(t.endX=n+l,t.startX=Math.max(t.endX-t.width,n)),t.startY<s?t.startY=s:t.endY>s+p&&(t.endY=s+p,t.startY=Math.max(t.endY-t.height,s)),e.activeObj=this.updateWidthHeight(e.activeObj)}},e.prototype.drawCropRatio=function(){var e,o,i,r,a=this.parent,n=a.activeObj.activePoint,s=a.lowerCanvas.clientWidth,l=a.lowerCanvas.clientHeight+1,p=a.img,h=p.destLeft,d=p.destTop,c=p.destWidth,u=p.destHeight;if(a.transform.zoomFactor>0&&this.currSelPoint){var v=t.extend({},a.activeObj,{},!0);this.drawCustomSelection("crop-custom",null,null,null,null),0!==a.transform.straighten&&(n=a.activeObj.activePoint),a.transform.degree%90==0&&a.transform.degree%180!=0?r=i=n.width<n.height?n.width:n.height:(i=h+h+c<=s?n.width:0===a.transform.straighten?s-h:n.width,r=d+d+u<=l?n.height:0===a.transform.straighten?l-d:n.height),a.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),a.activeObj=v,a.currObjType.shape=v.shape,this.upperContext.clearRect(0,0,a.upperCanvas.width,a.upperCanvas.height),a.currObjType.isCustomCrop=!1}else i=c,r=u,h<0&&(i+=h),d<0&&(r+=d),h+c>a.lowerCanvas.width&&(i-=h+c-a.lowerCanvas.width),d+u>a.lowerCanvas.height&&(r-=d+u-a.lowerCanvas.height);switch(a.currObjType.shape.toLowerCase()){case"crop-square":case"crop-circle":a.notify("selection",{prop:"setDragDirection",onPropertyChange:!1,value:{width:i,height:r}}),n=a.activeObj.activePoint,a.lowerCanvas.width<n.endX-n.startX&&(n.startX=7.5,n.endX=a.lowerCanvas.width-7.5),a.lowerCanvas.height<n.endY-n.startY&&(n.startY=7.5,n.endY=a.lowerCanvas.height-7.5),i===c&&r===u&&(n.startX+=h,n.startY+=d,n.endX+=h,n.endY+=d),a.lowerCanvas.width>a.lowerCanvas.height?(n.height=n.endY-n.startY,n.width=n.height,n.endX=n.startX+n.width):(n.width=n.endX-n.startX,n.height=n.width,n.endY=n.startY+n.height);break;case"crop-3:2":e=3,o=2;break;case"crop-4:3":e=4,o=3;break;case"crop-5:4":e=5,o=4;break;case"crop-7:5":e=7,o=5;break;case"crop-16:9":e=16,o=9;break;case"crop-2:3":e=2,o=3;break;case"crop-3:4":e=3,o=4;break;case"crop-4:5":e=4,o=5;break;case"crop-5:7":e=5,o=7;break;case"crop-9:16":e=9,o=16;break;default:e=parseInt(a.currObjType.shape.toLowerCase().split("crop-")[1].split(":")[0]),o=parseInt(a.currObjType.shape.toLowerCase().split("crop-")[1].split(":")[1])}if(void 0!==e&&void 0!==o&&(a.notify("selection",{prop:"calcShapeRatio",onPropertyChange:!1,value:{x:e,y:o,imgWidth:i,imgHeight:r}}),i===c&&r===u&&this.updatePoints(),n=a.activeObj.activePoint),n.startX<h){C=h-n.startX+7.5;n.startX+=C,n.endX+=C}if(n.startY<d){C=d-n.startY+7.5;n.startY+=C,n.endY+=C}a.activeObj=this.updateWidthHeight(a.activeObj),this.adjToCenter(),this.enlargeToImg(),0!==a.transform.straighten&&(this.adjToStraighten(),this.updateActiveObject(a.activeObj.activePoint,a.activeObj));var g={isIntersect:null,arr:null},f=0;if(n=a.activeObj.activePoint,0!==a.transform.straighten)for(;this.isLinesIntersect(g)&&f<100;){f++;var C=1*n.width/100;n.startX+=C,n.endX-=C,C=1*n.height/100,n.startY+=C,n.endY-=C,n.width=n.endX-n.startX,n.height=n.endY-n.startY,this.updateActiveObject(n,a.activeObj)}this.straightenInitZoom=a.transform.zoomFactor,this.straightenActObj=t.extend({},a.activeObj,{},!0),a.notify("draw",{prop:"resetStraightenDestPoints"}),a.notify("draw",{prop:"setDestForStraighten"})},e.prototype.adjToCenter=function(){var e=this.parent,t=e.activeObj.activePoint,o=e.img,i=o.destLeft,r=o.destTop,a=o.destWidth,n=o.destHeight,s=e.lowerCanvas.width/2-(t.endX-t.width/2),l=e.lowerCanvas.height/2-(t.endY-t.height/2);if(t.startX+=s,t.endX+=s,t.startY+=l,t.endY+=l,t.startX<(i>=7.5?i:7.5)){p=(i>=7.5?i:0)-t.startX;t.startX+=p,t.endX+=p}else if(t.endX>i+a){p=t.endX-(i+a);t.startX-=p,t.endX-=p}if(t.startY<(r>=7.5?r:7.5)){p=(r>=7.5?r:0)-t.startY;t.startY+=p,t.endY+=p}else if(t.endY>r+n){var p=t.endY-(r+n);t.startY-=p,t.endY-=p}},e.prototype.enlargeToImg=function(){var e=this.parent;if(0!==e.transform.straighten&&e.transform.degree%90==0&&e.transform.degree%180!=0)for(var o=e.activeObj.activePoint,i=t.extend({},o,{},!0),r=0;;){r++;var a=5*o.width/100;o.startX-=a,o.endX+=a,a=5*o.height/100,o.startY-=a,o.endY+=a,o.width=o.endX-o.startX,o.height=o.endY-o.startY,this.updateActiveObject(o,e.activeObj);var n={isIntersect:null,arr:null};if(this.updateImgCanvasPoints(),this.isLinesIntersect(n),n.arr[0]||n.arr[1]||n.arr[2]||n.arr[3]||o.startX<7.5||o.startY<7.5||100===r){a=1*(o=t.extend({},i,{},!0)).width/100,o.startX+=a,o.endX-=a,a=1*o.height/100,o.startY+=a,o.endY-=a,o.width=o.endX-o.startX,o.height=o.endY-o.startY,this.updateActiveObject(o,e.activeObj);break}i=t.extend({},o,{},!0)}},e.prototype.updateActiveObject=function(e,o,i,r,a){var n=this.parent;e=e||t.extend({},n.activeObj.activePoint,{},!0),o=o||t.extend({},n.activeObj,{},!0),e.width=e.endX-e.startX,e.height=e.endY-e.startY;var s=e.startX,l=e.startY,p=e.endX,h=e.endY,d=e.width,c=e.height;r=r||0,a=a||0;var u=d/2,v=c/2;o.horTopLine={startX:s+r,startY:l-a,endX:p+r,endY:h+a},o.horBottomLine={startX:s-r,startY:h-a,endX:p-r,endY:h+a},o.verLeftLine={startX:s+r,startY:l-a,endX:s-a,endY:h-a},o.verRightLine={startX:p+r,startY:l+a,endX:p-r,endY:h+a},o.topLeftCircle={startX:s,startY:l,radius:o.horTopLine.endX?7.5:0},o.topCenterCircle={startX:s+u,startY:l,radius:o.horTopLine.endX?7.5:0},o.topRightCircle={startX:p,startY:l,radius:o.horTopLine.endX?7.5:0},o.centerLeftCircle={startX:s,startY:l+v,radius:o.horTopLine.endX?7.5:0},o.centerRightCircle={startX:p,startY:l+v,radius:o.horTopLine.endX?7.5:0},o.bottomLeftCircle={startX:s,startY:h,radius:o.horTopLine.endX?7.5:0},o.bottomCenterCircle={startX:s+u,startY:h,radius:o.horTopLine.endX?7.5:0},o.bottomRightCircle={startX:p,startY:h,radius:o.horTopLine.endX?7.5:0},0===o.rotatedAngle&&(o.rotationCirclePoint={x:o.bottomCenterCircle.startX,y:o.bottomCenterCircle.startY+25},o.rotationCirclePoint.ratioX=(o.rotationCirclePoint.x-n.img.destLeft)/n.img.destWidth,o.rotationCirclePoint.ratioY=(o.rotationCirclePoint.y-n.img.destTop)/n.img.destHeight),o.activePoint=e,t.isNullOrUndefined(i)&&(n.activeObj=t.extend({},o,{},!0))},e.prototype.drawOuterSelection=function(e,o){var i,r=this.parent,a=r.activeObj.activePoint,n=r.activeObj;e.lineWidth=.5;var s=t.extend({},n,{},!0);n.shape&&(i=n.shape.split("-")),(i&&"crop"===i[0]||void 0===n.shape)&&!o&&(this.upperContext.fillStyle="rgb(0, 0, 0, 0.25)",this.upperContext.fillRect(0,0,r.lowerCanvas.width,r.lowerCanvas.height),this.upperContext.clearRect(a.startX,a.startY,a.width,a.height)),e.strokeStyle=r.themeColl[r.theme].primaryColor,e.fillStyle=r.themeColl[r.theme].secondaryColor;var l;if((l=0===s.shapeDegree?r.transform.degree:r.transform.degree-s.shapeDegree)<0&&(l=360+l),"arrow"===n.shape||"line"===n.shape)e.beginPath(),e.moveTo(a.startX,a.startY),e.lineTo(a.endX,a.endY),e.stroke();else if("path"===n.shape){e.beginPath();var p=t.extend({},r.activeObj,{},!0);if(p.pointColl[0]&&(e.moveTo(p.pointColl[0].x,p.pointColl[0].y),p.pointColl.length>1))for(var h=1,d=p.pointColl.length;h<d;h++)a.endX=p.pointColl[h].x,a.endY=p.pointColl[h].y,e.lineTo(a.endX,a.endY);var c={shape:null};r.notify("selection",{prop:"getCurrentDrawingShape",value:{obj:c}}),"path"===c.shape&&(r.activeObj=n=p),e.lineTo(a.endX,a.endY),e.stroke()}else this.drawCornerCircles(e);if(r.selectionSettings.showCircle&&(void 0===i||"crop"!==i[0])){var u=e.strokeStyle,v=e.fillStyle;e.strokeStyle=r.selectionSettings.strokeColor,e.fillStyle=r.selectionSettings.fillColor,"text"===n.shape?(e.lineWidth*=2,e.beginPath(),this.drawRotationArcLine(e),e.lineTo(n.rotationCirclePoint.x,n.rotationCirclePoint.y),e.stroke(),e.fill(),e.closePath(),e.beginPath(),e.moveTo(n.rotationCirclePoint.x,n.rotationCirclePoint.y),e.arc(n.rotationCirclePoint.x,n.rotationCirclePoint.y,n.bottomCenterCircle.radius,0,2*Math.PI),e.stroke(),e.fill(),e.closePath(),e.lineWidth/=2):this.drawCenterCircles(e),e.strokeStyle=u,e.fillStyle=v}s.rotationCircleLine=n.rotationCircleLine,r.activeObj=t.extend({},s,{},!0)},e.prototype.drawArrowHead=function(e,t){switch(t?this.parent.activeObj.start:this.parent.activeObj.end){case"arrowSolid":t?this.arrowSolid(e,!0):this.arrowSolid(e,!1);break;case"arrow":t?this.arrow(e,!0):this.arrow(e,!1);break;case"circleSolid":t?this.arrowCircleSolid(e,!0):this.arrowCircleSolid(e,!1);break;case"circle":t?this.arrowCircle(e,!0):this.arrowCircle(e,!1);break;case"bar":t?this.arrowBar(e,!0):this.arrowBar(e,!1);break;case"square":case"squareSolid":t?this.arrowSquareStart(e):this.arrowSquareEnd(e)}},e.prototype.drawShapeObj=function(e,o,i,r){var a=this.parent,n=a.activeObj.activePoint,s=a.activeObj,l=s.strokeSettings,p=l.strokeColor,h=l.fillColor,d=l.strokeWidth,c=void 0!==o?o:a.currObjType.shape;a.currObjType.shape=c;var u;"original"===e.toLowerCase()?u=this.lowerContext:"duplicate"===e.toLowerCase()?u=this.upperContext:i&&(u=i);var v=a.currObjType.shape.toLowerCase();-1!==["rectangle","ellipse","line","arrow","path","image"].indexOf(v)&&(s.shape=a.currObjType.shape),u.strokeStyle=p,u.fillStyle="text"===o||"freehanddraw"===o?p:h;var g=n.width/3,f=n.height/3,C=n.endX-n.startX,b=n.endY-n.startY;this.rotateContext("initial",u);var m,y,P=u.fillStyle;switch(a.currObjType.shape.toLowerCase()){case"rectangle":this.drawSquareLines(u),t.isNullOrUndefined(r)&&u===this.upperContext&&this.drawOuterSelection(u);break;case"ellipse":C=Math.abs(C),b=Math.abs(b),u.beginPath(),u.ellipse(n.startX+C/2,n.startY+b/2,C/2,b/2,0,0,2*Math.PI,!1),""!==h&&(u.fillStyle=h,u.fill()),u.ellipse(n.startX+C/2,n.startY+b/2,Math.abs(C/2-d),Math.abs(b/2-d),0,0,2*Math.PI,!1),u.fillStyle=p,u.fill("evenodd"),u.closePath(),t.isNullOrUndefined(r)&&u===this.upperContext&&this.drawOuterSelection(u);break;case"crop-circle":u===this.lowerContext&&(u=this.upperContext),this.shapeCircle(u,C,b);break;case"line":this.shapeLine(u,n.startX,n.startY,n.endX,n.endY),t.isNullOrUndefined(r)&&u===this.upperContext&&this.drawOuterSelection(u);break;case"arrow":(m=0===s.shapeDegree?a.transform.degree:a.transform.degree-s.shapeDegree)<0&&(m=360+m),u.fillStyle=u.strokeStyle,t.isNullOrUndefined(s.triangleDirection)&&(s.triangleDirection="right"),t.isNullOrUndefined(s.start)&&(s.start="none"),t.isNullOrUndefined(s.end)&&(s.end="arrowSolid"),this.drawArrowHead(u,!0),this.drawArrowHead(u,!1),"none"===s.end&&this.shapeLine(u,n.startX,n.startY,n.endX,n.endY),u.fillStyle=P,t.isNullOrUndefined(r)&&u===this.upperContext&&this.drawOuterSelection(u);break;case"path":if((y=t.extend({},a.activeObj,{},!0)).pointColl.length>1){var j={shape:null};if(a.notify("selection",{prop:"getCurrentDrawingShape",value:{obj:j}}),"path"===j.shape)for(var x={x:0,y:0},w=0,O=y.pointColl.length;w<O;w++)t.isNullOrUndefined(y.pointColl[w+1])?(x.x=y.activePoint.endX,x.y=y.activePoint.endY):(x.x=y.pointColl[w+1].x,x.y=y.pointColl[w+1].y),n.startX=y.pointColl[w].x,n.startY=y.pointColl[w].y,n.endX=x.x,n.endY=x.y,a.activeObj=this.updateWidthHeight(a.activeObj),this.shapeLine(u,n.startX,n.startY,n.endX,n.endY);else for(var w=1,O=y.pointColl.length;w<O;w++)n.startX=y.pointColl[w-1].x,n.startY=y.pointColl[w-1].y,n.endX=y.pointColl[w].x,n.endY=y.pointColl[w].y,a.activeObj=this.updateWidthHeight(a.activeObj),this.shapeLine(u,n.startX,n.startY,n.endX,n.endY);a.activeObj=s=y}else this.shapeLine(u,n.startX,n.startY,n.endX,n.endY);u===this.upperContext&&this.drawOuterSelection(u);break;case"text":this.shapeText(u);break;case"image":this.shapeImage(u),t.isNullOrUndefined(r)&&u===this.upperContext&&this.drawOuterSelection(u);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":u===this.lowerContext&&(u=this.upperContext),this.drawSelection(g,f),a.currObjType.shape="";break;default:this.drawSelection(g,f)}this.rotateContext("reverse",u)},e.prototype.updatePoints=function(){var e=this.parent,t=e.activeObj.activePoint,o=e.img,i=o.destLeft,r=o.destTop;t.startX+=i,t.startY+=r,t.endX+=i,t.endY+=r,e.activeObj=this.updateWidthHeight(e.activeObj)},e.prototype.updateWidthHeight=function(e){var t=e.activePoint,o=t.startX,i=t.startY,r=t.endX,a=t.endY;return e.activePoint.width=r-o,e.activePoint.height=a-i,e},e.prototype.drawCornerCircles=function(e){var t=this.parent,o=t.activeObj;if(e.beginPath(),e.rect(o.activePoint.startX,o.activePoint.startY,o.activePoint.width,o.activePoint.height),e.stroke(),e.closePath(),t.selectionSettings.showCircle){var i=e.strokeStyle,r=e.fillStyle;e.strokeStyle=t.selectionSettings.strokeColor,e.fillStyle=t.selectionSettings.fillColor,e.lineWidth*=2,e.beginPath(),e.moveTo(o.topLeftCircle.startX,o.topLeftCircle.startY),e.arc(o.topLeftCircle.startX,o.topLeftCircle.startY,o.topLeftCircle.radius,0,2*Math.PI),e.moveTo(o.topRightCircle.startX,o.topRightCircle.startY),e.arc(o.topRightCircle.startX,o.topRightCircle.startY,o.topRightCircle.radius,0,2*Math.PI),e.moveTo(o.bottomLeftCircle.startX,o.bottomLeftCircle.startY),e.arc(o.bottomLeftCircle.startX,o.bottomLeftCircle.startY,o.bottomLeftCircle.radius,0,2*Math.PI),e.moveTo(o.bottomRightCircle.startX,o.bottomRightCircle.startY),e.arc(o.bottomRightCircle.startX,o.bottomRightCircle.startY,o.bottomRightCircle.radius,0,2*Math.PI),e.stroke(),e.fill(),e.closePath(),e.lineWidth/=2,e.strokeStyle=i,e.fillStyle=r}},e.prototype.drawCenterCircles=function(e){var o=this.parent,i=o.activeObj.activePoint,r=o.activeObj;if(e.lineWidth*=2,e.beginPath(),"arrow"===r.shape||"line"===r.shape)e.moveTo(i.startX,i.startY),e.arc(i.startX,i.startY,r.topCenterCircle.radius,0,2*Math.PI),e.moveTo(i.endX,i.endY),e.arc(i.endX,i.endY,r.bottomCenterCircle.radius,0,2*Math.PI);else if("path"===r.shape){var a=t.extend({},o.activeObj,{},!0);if(a.pointColl.length>1)for(var n=1,s=a.pointColl.length;n<s;n++)i.startX=a.pointColl[n-1].x,i.startY=a.pointColl[n-1].y,i.endX=a.pointColl[n].x,i.endY=a.pointColl[n].y,e.moveTo(i.startX,i.startY),e.arc(i.startX,i.startY,r.topCenterCircle.radius,0,2*Math.PI),e.moveTo(i.endX,i.endY),e.arc(i.endX,i.endY,r.bottomCenterCircle.radius,0,2*Math.PI);var l={shape:null};o.notify("selection",{prop:"getCurrentDrawingShape",value:{obj:l}}),"path"===l.shape&&(o.activeObj=r=a),e.moveTo(i.startX,i.startY),e.arc(i.startX,i.startY,r.topCenterCircle.radius,0,2*Math.PI),e.moveTo(i.endX,i.endY),e.arc(i.endX,i.endY,r.bottomCenterCircle.radius,0,2*Math.PI)}else this.drawRotationArcLine(e),e.lineTo(r.rotationCirclePoint.x,r.rotationCirclePoint.y);e.stroke(),e.fill(),e.closePath(),"arrow"!==r.shape&&"line"!==r.shape&&"path"!==r.shape&&(e.beginPath(),e.moveTo(r.rotationCirclePoint.x,r.rotationCirclePoint.y),e.arc(r.rotationCirclePoint.x,r.rotationCirclePoint.y,r.bottomCenterCircle.radius,0,2*Math.PI),e.stroke(),e.fill(),e.closePath()),e.lineWidth/=2},e.prototype.drawRotationArcLine=function(e){var o=this.parent,i=o.activeObj;t.isNullOrUndefined(i.rotationCircleLine)&&(i.rotationCircleLine=22.5);var r,a=!1,n=!1;if((r=0===i.shapeDegree?o.transform.degree:o.transform.degree-i.shapeDegree)<0&&(r=360+r),i.flipObjColl)for(var s=0,l=i.flipObjColl.length;s<l;s++){var p=i.flipObjColl[s].toLowerCase();"horizontal"===p?a=!0:"vertical"===p&&(n=!0)}switch(r){case 0:case 360:n?(i.rotationCirclePoint={x:i.topCenterCircle.startX,y:i.topCenterCircle.startY-i.rotationCircleLine},e.moveTo(i.rotationCirclePoint.x,i.rotationCirclePoint.y+i.rotationCircleLine)):(i.rotationCirclePoint={x:i.bottomCenterCircle.startX,y:i.bottomCenterCircle.startY+i.rotationCircleLine},e.moveTo(i.rotationCirclePoint.x,i.rotationCirclePoint.y-i.rotationCircleLine));break;case 90:case-270:a?(i.rotationCirclePoint={x:i.centerRightCircle.startX+i.rotationCircleLine,y:i.centerLeftCircle.startY},e.moveTo(i.rotationCirclePoint.x-i.rotationCircleLine,i.rotationCirclePoint.y)):(i.rotationCirclePoint={x:i.centerLeftCircle.startX-i.rotationCircleLine,y:i.centerLeftCircle.startY},e.moveTo(i.rotationCirclePoint.x+i.rotationCircleLine,i.rotationCirclePoint.y));break;case 180:case-180:n?(i.rotationCirclePoint={x:i.bottomCenterCircle.startX,y:i.bottomCenterCircle.startY+i.rotationCircleLine},e.moveTo(i.rotationCirclePoint.x,i.rotationCirclePoint.y-i.rotationCircleLine)):(i.rotationCirclePoint={x:i.topCenterCircle.startX,y:i.topCenterCircle.startY-i.rotationCircleLine},e.moveTo(i.rotationCirclePoint.x,i.rotationCirclePoint.y+i.rotationCircleLine));break;case 270:case-90:a?(i.rotationCirclePoint={x:i.centerLeftCircle.startX-i.rotationCircleLine,y:i.centerLeftCircle.startY},e.moveTo(i.rotationCirclePoint.x+i.rotationCircleLine,i.rotationCirclePoint.y)):(i.rotationCirclePoint={x:i.centerRightCircle.startX+i.rotationCircleLine,y:i.centerLeftCircle.startY},e.moveTo(i.rotationCirclePoint.x-i.rotationCircleLine,i.rotationCirclePoint.y))}},e.prototype.drawSquareLines=function(e){var t,o=this.parent.activeObj,i=o.activePoint,r=i.startX,a=i.startY,n=i.width,s=i.height,l=o.strokeSettings,p=l.fillColor,h=l.strokeColor,d=l.strokeWidth;o.shape&&(t=o.shape.split("-")),"crop"===t[0]?e.strokeStyle="#fff":e.strokeStyle=h,e.beginPath(),e.rect(r,a,n,s),""!==p&&(e.fillStyle=p,e.fill()),e.rect(r+d,a+d,n-2*d,s-2*d),e.fillStyle=h,e.fill("evenodd"),e.closePath()},e.prototype.drawSelection=function(e,t){var o=this.parent,i=o.activeObj,r=i.activePoint,a=r.startX,n=r.startY,s=r.endX,l=r.endY;this.upperContext.strokeStyle=o.themeColl[o.theme].primaryColor,this.upperContext.beginPath(),i.horTopInnerLine={startX:a,startY:n+t,endX:s,endY:l+t},i.horBottomInnerLine={startX:a,startY:n+2*t,endX:s,endY:l+2*t},i.verLeftInnerLine={startX:a+e,startY:n,endX:a+e,endY:l},i.verRightInnerLine={startX:a+2*e,startY:n,endX:a+2*e,endY:l},this.upperContext.moveTo(i.horTopInnerLine.startX,i.horTopInnerLine.startY),this.upperContext.lineTo(i.horTopInnerLine.endX,i.horTopInnerLine.startY),this.upperContext.moveTo(i.horBottomInnerLine.startX,i.horBottomInnerLine.startY),this.upperContext.lineTo(i.horBottomInnerLine.endX,i.horBottomInnerLine.startY),this.upperContext.moveTo(i.verLeftInnerLine.startX,i.verLeftInnerLine.startY),this.upperContext.lineTo(i.verLeftInnerLine.endX,i.verLeftInnerLine.endY),this.upperContext.moveTo(i.verRightInnerLine.startX,i.verRightInnerLine.startY),this.upperContext.lineTo(i.verRightInnerLine.endX,i.verRightInnerLine.endY),this.upperContext.stroke(),this.upperContext.closePath()},e.prototype.shapeCircle=function(e,t,o){var i=this.parent,r=i.activeObj.activePoint,a=r.startX,n=r.startY,s=r.endX,l=r.endY,p=r.width;e.strokeStyle=i.themeColl[i.theme].primaryColor,e.clearRect(0,0,i.lowerCanvas.width,i.lowerCanvas.height),e.fillStyle="rgb(0, 0, 0, 0.25)",e.fillRect(0,0,i.lowerCanvas.width,i.lowerCanvas.height);var h=e.lineWidth;e.lineWidth=2,e.beginPath(),e.ellipse(i.activeObj.horTopLine.startX+t/2,i.activeObj.horTopLine.startY+o/2,t/2,o/2,0,0,2*Math.PI,!1),e.stroke(),e.closePath(),e.save(),e.beginPath(),e.arc((s-a)/2+a,(l-n)/2+n,p/2,0,2*Math.PI),e.closePath(),e.clip(),e.clearRect(0,0,i.lowerCanvas.width,i.lowerCanvas.height),e.restore(),e.lineWidth=h,this.drawOuterSelection(e,!0),i.currObjType.shape=""},e.prototype.shapeLine=function(e,t,o,i,r){var a=e.lineWidth;e.lineWidth=this.parent.activeObj.strokeSettings.strokeWidth,e.beginPath(),e.moveTo(t,o),e.lineTo(i,r),e.stroke(),e.lineWidth=a},e.prototype.manipulateSaveCtx=function(e,t,o){if(e!==this.lowerContext&&e!==this.upperContext){var i={width:0,height:0};this.parent.notify("crop",{prop:"calcRatio",onPropertyChange:!1,value:{obj:i,dimension:{width:e.canvas.width,height:e.canvas.height}}});var r=i;t&&(t*=r.width),o&&(o*=r.height)}return{x:t,y:o}},e.prototype.arrow=function(e,t){var o=this.parent.activeObj,i=o.activePoint,r=i.startX,a=i.startY,n=i.endX,s=i.endY,l=o.strokeSettings.strokeWidth;e.lineWidth=l;var p=this.arrowDimension.arrow.width,h=this.arrowDimension.arrow.height,d=this.manipulateSaveCtx(e,p,h);p=d.x+l,h=d.y+l,this.dx=n-r,this.dy=s-a,e.fillStyle=o.strokeSettings.strokeColor;var c=Math.atan2(this.dy,this.dx),u="arrow"===o.start,v="arrow"===o.end,g="circle"===o.end||"square"===o.end;((t&&"left"===o.triangleDirection||"right"===o.triangleDirection)&&(u&&"none"===o.end||u&&!g)||!t&&(v&&"none"===o.start||!u&&!g))&&this.shapeLine(e,r,a,n,s),t&&"left"===o.triangleDirection||!t&&"right"===o.triangleDirection?(e.translate(n,s),e.rotate(c),this.shapeLine(e,0,0,-p,h/2),this.shapeLine(e,0,0,-p,-h/2),e.rotate(-c),e.translate(-n,-s)):(t&&"right"===o.triangleDirection||!t&&"left"===o.triangleDirection)&&(e.translate(r,a),e.rotate(c),this.shapeLine(e,0,0,p,h/2),this.shapeLine(e,0,0,p,-h/2),e.rotate(-c),e.translate(-r,-a))},e.prototype.arrowSolid=function(e,t){var o=this.parent.activeObj,i=o.strokeSettings.strokeWidth,r=o.activePoint,a=r.startX,n=r.startY,s=r.endX,l=r.endY,p=this.arrowDimension.arrowSolid.width,h=this.arrowDimension.arrowSolid.height,d=this.manipulateSaveCtx(e,p,h);p=d.x+i,h=d.y+i,this.dx=s-a,this.dy=l-n;var c=Math.atan2(this.dy,this.dx),u="arrowSolid"===o.start,v="arrowSolid"===o.end,g="circle"===o.end||"square"===o.end;(t&&u&&"none"===o.end||u&&!g||!t&&(v&&"none"===o.start||!u&&!g))&&this.shapeLine(e,a,n,s,l),t&&"left"===o.triangleDirection||!t&&"right"===o.triangleDirection?(e.translate(s,l),e.rotate(c),e.beginPath(),e.moveTo(i,0),e.lineTo(h/2-p,h/2),e.lineTo(h/2-p,-h/2),e.closePath(),e.fill(),e.rotate(-c),e.translate(-s,-l),o.rotatedAngle=c):(t&&"right"===o.triangleDirection||!t&&"left"===o.triangleDirection)&&(e.translate(a,n),e.rotate(c),e.beginPath(),e.moveTo(0-i,0),e.lineTo(p-h/2,h/2),e.lineTo(p-h/2,-h/2),e.closePath(),e.fill(),e.rotate(-c),e.translate(-a,-n),o.rotatedAngle=c)},e.prototype.arrowSquareStart=function(e){var t=this.parent.activeObj,o=t.strokeSettings.strokeWidth,i=t.activePoint,r=i.startX,a=i.startY,n=i.endX,s=i.endY,l="square"===t.start,p="circle"===t.end,h="squareSolid"===t.start,d="circleSolid"===t.end;(l&&"none"===t.end||l&&!p&&"square"!==t.start||h&&d)&&this.shapeLine(e,r,a,n,s),e.lineWidth=o,e.beginPath(),e.fillStyle=t.strokeSettings.strokeColor;var c=this.arrowDimension.square.width,u=this.arrowDimension.square.height,v=this.manipulateSaveCtx(e,c,u);c=v.x+o,u=v.y+o,this.dx=n-r,this.dy=s-a;var g=Math.atan2(this.dy,this.dx);"left"===t.triangleDirection?(e.translate(n,s),e.rotate(g),"squareSolid"===t.start&&e.fillRect(u/2-c,-u/2,c,u),e.strokeRect(u/2-c,-u/2,c,u),e.rotate(-g),e.translate(-n,-s),this.squareStartIntersectX1=n-u/2*Math.cos(g),this.squareStartIntersectY1=s-u/2*Math.sin(g),"square"===t.start&&"square"!==t.end&&"circle"!==t.end?this.shapeLine(e,r,a,this.squareStartIntersectX1,this.squareStartIntersectY1):"square"===t.start&&"circle"===t.end?this.shapeLine(e,this.endCircleIntersectX1,this.endCircleIntersectY1,this.squareStartIntersectX1,this.squareStartIntersectY1):"squareSolid"===t.start&&"squareSolid"===t.end&&this.shapeLine(e,r,a,n,s)):"right"===t.triangleDirection&&(e.lineWidth=o,e.fillStyle=t.strokeSettings.strokeColor,"squareSolid"===t.start&&"squareSolid"===t.end&&this.shapeLine(e,r,a,n,s),e.translate(r,a),e.rotate(g),"squareSolid"===t.start&&e.fillRect(u/2-c,-u/2,c,u),e.strokeRect(u/2-c,-u/2,c,u),e.rotate(-g),e.translate(-r,-a),t.rotatedAngle=g,this.squareStartIntersectX1=r+u/2*Math.cos(g),this.squareStartIntersectY1=a+u/2*Math.sin(g),"square"===t.start&&"square"!==t.end&&"circle"!==t.end&&this.shapeLine(e,n,s,this.squareStartIntersectX1,this.squareStartIntersectY1),"square"===t.start&&"circle"===t.end&&this.shapeLine(e,this.endCircleIntersectX1,this.endCircleIntersectY1,this.squareStartIntersectX1,this.squareStartIntersectY1))},e.prototype.arrowSquareEnd=function(e){var t=this.parent.activeObj,o=t.activePoint,i=o.startX,r=o.startY,a=o.endX,n=o.endY,s=t.strokeSettings.strokeWidth,l=this.arrowDimension.square.width,p=this.arrowDimension.square.height,h=this.manipulateSaveCtx(e,l,p);l=h.x+s,p=h.y+s,this.dx=a-i,this.dy=n-r;var d=Math.atan2(this.dy,this.dx);e.lineWidth=s,"right"===t.triangleDirection?(e.fillStyle=t.strokeSettings.strokeColor,"squareSolid"===t.end&&"none"===t.start&&this.shapeLine(e,i,r,a,n),e.translate(a,n),e.rotate(d),"squareSolid"===t.end&&e.fillRect(p/2-l,-p/2,l,p),e.strokeRect(p/2-l,-p/2,l,p),e.rotate(-d),e.translate(-a,-n),t.rotatedAngle=d,this.squareEndIntersectX1=a-p/2*Math.cos(d),this.squareEndIntersectY1=n-p/2*Math.sin(d),"square"===t.end&&"square"!==t.start&&"circle"!==t.start?this.shapeLine(e,i,r,this.squareEndIntersectX1,this.squareEndIntersectY1):"circle"===t.start&&"square"===t.end?this.shapeLine(e,this.squareEndIntersectX1,this.squareEndIntersectY1,this.startCircleIntersectX1,this.startCircleIntersectY1):"square"===t.start&&"square"===t.end&&this.shapeLine(e,this.squareEndIntersectX1,this.squareEndIntersectY1,this.squareStartIntersectX1,this.squareStartIntersectY1)):"left"===t.triangleDirection&&(e.translate(i,r),e.rotate(d),"squareSolid"===t.end&&e.fillRect(p/2-l,-p/2,l,p),e.strokeRect(p/2-l,-p/2,l,p),e.rotate(-d),e.translate(-i,-r),t.rotatedAngle=d,this.squareEndIntersectX1=i+p/2*Math.cos(d),this.squareEndIntersectY1=r+p/2*Math.sin(d),"square"===t.end&&"square"!==t.start&&"circle"!==t.start?this.shapeLine(e,a,n,this.squareEndIntersectX1,this.squareEndIntersectY1):"circle"===t.start&&"square"===t.end?this.shapeLine(e,this.squareEndIntersectX1,this.squareEndIntersectY1,this.startCircleIntersectX1,this.startCircleIntersectY1):"square"===t.start&&"square"===t.end&&this.shapeLine(e,this.squareEndIntersectX1,this.squareEndIntersectY1,this.squareStartIntersectX1,this.squareStartIntersectY1))},e.prototype.arrowCircle=function(e,t){var o=this.parent,i=o.activeObj,r=i.activePoint,a=r.startX,n=r.startY,s=r.endX,l=r.endY,p=i.strokeSettings.strokeWidth;if(t&&"left"===i.triangleDirection||!t&&"right"===i.triangleDirection){e.lineWidth=p;u=this.arrowDimension.circle.width;u=(v=this.manipulateSaveCtx(e,u,null)).x+p,e.beginPath(),e.arc(s,l,u,0,2*Math.PI),e.stroke(),e.closePath(),this.dx=s-a,this.dy=l-n;g=this.dx*this.dx+this.dy*this.dy;if((b=(f=2*(this.dx*(a-s)+this.dy*(n-l)))*f-4*g*(C=(a-s)*(a-s)+(n-l)*(n-l)-u*u))>=0){e.fillStyle=i.strokeSettings.strokeColor;var h=(-f-Math.sqrt(b))/(2*g),d=a+this.dx*h,c=n+this.dy*h;t?(this.startCircleIntersectX1=d,this.startCircleIntersectY1=c,this.endCircleIntersectX1=s-this.dx*h,this.endCircleIntersectY1=l-this.dy*h,e.beginPath(),e.fill(),e.beginPath(),"circle"===i.start&&"circle"===i.end?this.shapeLine(e,this.startCircleIntersectX1,this.startCircleIntersectY1,this.endCircleIntersectX1,this.endCircleIntersectY1):"circle"===i.start&&"circle"!==i.end&&"square"!==i.end&&this.shapeLine(e,a,n,this.startCircleIntersectX1,this.startCircleIntersectY1),e.stroke(),e.closePath()):(this.endCircleIntersectX1=d,this.endCircleIntersectY1=c,"circle"===i.end&&"circle"!==i.start&&"square"!==i.start&&this.shapeLine(e,a,n,this.endCircleIntersectX1,this.endCircleIntersectY1))}m=Math.atan2(this.dy,this.dx);o.activeObj.rotatedAngle=m}else if(t&&"right"===i.triangleDirection||!t&&"left"===i.triangleDirection){e.lineWidth=p;var u=this.arrowDimension.circle.width,v=this.manipulateSaveCtx(e,u,null);u=v.x+p,e.beginPath(),e.arc(a,n,u,0,2*Math.PI),e.stroke(),e.closePath(),this.dx=a-s,this.dy=n-l;var g=this.dx*this.dx+this.dy*this.dy,f=2*(this.dx*(s-a)+this.dy*(l-n)),C=(s-a)*(s-a)+(l-n)*(l-n)-u*u,b=f*f-4*g*C;if(b>=0){e.fillStyle=i.strokeSettings.strokeColor;var h=(-f-Math.sqrt(b))/(2*g),d=s+this.dx*h,c=l+this.dy*h;t?(this.startCircleIntersectX1=d,this.startCircleIntersectY1=c,this.endCircleIntersectX1=a-this.dx*h,this.endCircleIntersectY1=n-this.dy*h,"circle"===i.start&&"circle"===i.end?this.shapeLine(e,this.endCircleIntersectX1,this.endCircleIntersectY1,this.startCircleIntersectX1,this.startCircleIntersectY1):"circle"===i.start&&"circle"!==i.end&&"square"!==i.end&&this.shapeLine(e,s,l,this.startCircleIntersectX1,this.startCircleIntersectY1)):(this.endCircleIntersectX1=d,this.endCircleIntersectY1=c,e.beginPath(),e.fill(),e.beginPath(),"circle"===i.end&&"circle"!==i.start&&"square"!==i.start&&this.shapeLine(e,s,l,this.endCircleIntersectX1,this.endCircleIntersectY1))}var m=Math.atan2(this.dy,this.dx);o.activeObj.rotatedAngle=m}},e.prototype.arrowCircleSolid=function(e,t){var o=this.parent.activeObj,i=o.activePoint,r=i.startX,a=i.startY,n=i.endX,s=i.endY,l="circleSolid"===o.start,p=o.strokeSettings.strokeWidth;if(t&&"left"===o.triangleDirection||!t&&"right"===o.triangleDirection){e.lineWidth=p,e.beginPath(),e.fillStyle=o.strokeSettings.strokeColor,(t&&l&&"none"===o.end||l&&"circle"!==o.end&&"square"!==o.end||!t&&"circleSolid"===o.end&&"none"===o.start)&&this.shapeLine(e,r,a,n,s);h=this.arrowDimension.circle.width;h=(d=this.manipulateSaveCtx(e,h,null)).x+p,this.dx=n-r,this.dy=s-a,e.save(),e.beginPath(),e.arc(n,s,h,0,2*Math.PI),e.stroke(),e.fill(),e.closePath(),o.rotatedAngle=Math.atan2(this.dy,this.dx)}else if(t&&"right"===o.triangleDirection||!t&&"left"===o.triangleDirection){e.lineWidth=p,e.beginPath(),e.fillStyle=o.strokeSettings.strokeColor,(t&&l&&"none"===o.end||l&&"circle"!==o.end&&"square"!==o.end||!t&&"circleSolid"===o.end&&"none"===o.start)&&this.shapeLine(e,r,a,n,s);var h=this.arrowDimension.circle.width,d=this.manipulateSaveCtx(e,h,null);h=d.x+p,this.dx=n-r,this.dy=s-a,e.save(),e.beginPath(),e.arc(r,a,h,0,2*Math.PI),e.stroke(),e.fill(),e.closePath(),o.rotatedAngle=Math.atan2(this.dy,this.dx)}},e.prototype.arrowBar=function(e,t){var o=this.parent,i=o.activeObj,r=i.activePoint,a=r.startX,n=r.startY,s=r.endX,l=r.endY,p=i.strokeSettings.strokeWidth;if(t&&"left"===i.triangleDirection||!t&&"right"===i.triangleDirection){e.lineWidth=p,e.beginPath(),e.fillStyle=i.strokeSettings.strokeColor,(t&&"bar"===i.start&&"none"===i.end||"bar"===i.start&&"circle"!==i.end&&"square"!==i.end||!t&&("bar"===i.end&&"none"===i.start||"bar"===i.end&&"circle"!==i.start&&"square"!==i.start))&&this.shapeLine(e,a,n,s,l);var h=this.arrowDimension.bar.width,d=this.arrowDimension.bar.height;h=(c=this.manipulateSaveCtx(e,h,d)).x+p,d=c.y+p,this.dx=s-a,this.dy=l-n;u=Math.atan2(this.dy,this.dx);e.translate(s,l),e.rotate(u),e.fillRect(d/4-h,-d/2,h,d),e.rotate(-u),e.translate(-s,-l),i.rotatedAngle=u}else if(t&&"right"===i.triangleDirection||!t&&"left"===i.triangleDirection){e.lineWidth=p,e.beginPath(),e.fillStyle=i.strokeSettings.strokeColor,(t&&"bar"===i.start&&"none"===i.end||"bar"===i.start&&"circle"!==i.end&&"square"!==i.end||!t&&"bar"===i.end&&"none"===i.start)&&this.shapeLine(e,a,n,s,l);var h=this.arrowDimension.bar.width,d=this.arrowDimension.bar.height,c=this.manipulateSaveCtx(e,h,d);h=c.x+p,d=c.y+p,this.dx=s-a,this.dy=l-n;var u=Math.atan2(this.dy,this.dx);e.translate(a,n),e.rotate(u),e.fillRect(d/4-h,-d/2,h,d),e.rotate(-u),e.translate(-a,-n),o.activeObj.rotatedAngle=u}},e.prototype.shapeImage=function(e){var t=this.parent,o=t.activeObj,i=o.activePoint,r=i.startX,a=i.startY,n=i.width,s=i.height,l=o.imageCanvas.getContext("2d");if(e===this.lowerContext&&this.isImageApply){var p={width:0,height:0};t.notify("transform",{prop:"calcMaxDimension",onPropertyChange:!1,value:{width:o.imageElement.width,height:o.imageElement.height,obj:p,isImgShape:null}}),(n<p.width/5||s<p.height/5)&&(l.clearRect(0,0,o.imageCanvas.width,o.imageCanvas.height),t.notify("selection",{prop:"applyTransformToImg",onPropertyChange:!1,value:{ctx:l}}),t.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate"}}),this.upperContext.clearRect(0,0,t.upperCanvas.width,t.upperCanvas.height),t.notify("selection",{prop:"setImageClarity",onPropertyChange:!1,value:{bool:!1}}),this.isImageApply=!1)}var h={startX:0,startY:0,width:0,height:0};h.width=n,h.height=s,4===o.flipObjColl.length&&(o.flipObjColl=[],o.shapeFlip=""),h.startX=(n-h.width)/2+r,h.startY=(s-h.height)/2+a;var d=e.globalAlpha;e.globalAlpha=o.opacity,o.rotateFlipColl&&o.rotateFlipColl.length>0?this.rotateImage(e):e.drawImage(o.imageCanvas,h.startX,h.startY,h.width,h.height),e.globalAlpha=d,t.currObjType.isText=!1},e.prototype.shapeText=function(e){var t=this.parent,o=e.filter,i=t.activeObj,r=i.activePoint,a=r.startX,n=r.startY,s=r.width,l=r.height,p=i.keyHistory.split("\n"),h=i.textSettings,d=h.fontFamily,c=h.bold,u=h.italic,v=i.textSettings.fontSize,g=((v+.25*v)*p.length-v*p.length)/p.length;e.filter="none";for(var f=0;f<p.length;f++){var C=p[f],b=(f+1)*v*.85+f*g;-360===t.transform.degree&&(t.transform.degree=0),0===t.transform.degree||180===t.transform.degree?v>l&&(v=i.textSettings.fontSize=l-.1*l):v>s&&(v=i.textSettings.fontSize=s-.1*s),e.strokeStyle=i.strokeSettings.strokeColor,e.fillStyle=i.strokeSettings.strokeColor;var m="";c&&(m="bold "),u&&(m="italic "),c&&u&&(m="italic bold "),e.font=m+v+"px "+d,4===i.flipObjColl.length&&(i.flipObjColl=[],i.shapeFlip=""),i.rotateFlipColl&&i.rotateFlipColl.length>0?this.rotateText(e):e.fillText(C,a+.1*v,n+b)}e.filter=o,t.currObjType.isText=!1},e.prototype.updateActPoint=function(e,t){var o=this.parent,i=o.activeObj,r=i.activePoint;return"horizontal"===e.toLowerCase()?r.startX<=t.canvas.width/2?(r.startX=t.canvas.width/2+(t.canvas.width/2-r.endX),r.endX=r.startX+r.width,this.updateActiveObject(r,i),o.activeObj=i):r.startX>=t.canvas.width/2&&(r.startX=t.canvas.width-r.endX,r.endX=r.startX+r.width,this.updateActiveObject(r,i),o.activeObj=i):"vertical"===e.toLowerCase()&&(r.startY<=t.canvas.height/2?(r.startY=t.canvas.height/2+(t.canvas.height/2-r.endY),r.endY=r.startY+r.height,this.updateActiveObject(r,i),o.activeObj=i):r.startY>=t.canvas.height/2&&(r.startY=t.canvas.height-r.endY,r.endY=r.startY+r.height,this.updateActiveObject(r,i),o.activeObj=i)),r},e.prototype.rotateImage=function(e){var o,i=this.parent,r=i.activeObj,a=t.extend({},i.activeObj,null,!0);-450===(o=0===r.shapeDegree?i.transform.degree:i.transform.degree-r.shapeDegree)&&(o=-90),o<0&&(o=360+o);var n={startX:0,startY:0,width:0,height:0};n.width=o%90==0&&o%180!=0?r.activePoint.height:r.activePoint.width,n.height=o%90==0&&o%180!=0?r.activePoint.width:r.activePoint.height,n.startX=r.activePoint.startX,n.startY=r.activePoint.startY;var s,l=n.startX,p=n.startY;e.save();for(var h=0,d=r.rotateFlipColl.length;h<d;h++){var c=r.rotateFlipColl[h];"number"==typeof c?(-450===(s=0===r.shapeDegree?c:c-r.shapeDegree)&&(s=-90),s<0&&(s=360+s),n.width=s%90==0&&s%180!=0?r.activePoint.height:r.activePoint.width,n.height=s%90==0&&s%180!=0?r.activePoint.width:r.activePoint.height,e.translate(e.canvas.width/2,e.canvas.height/2),e.rotate(Math.PI/180*c),e.translate(-e.canvas.height/2,-e.canvas.width/2),s%90==0&&s%270!=0||0===s?(p=e.canvas.width-(r.activePoint.startX+r.activePoint.width),p+=(r.activePoint.width-n.height)/2,l=n.startY):s%270==0&&(l=e.canvas.height-(r.activePoint.startY+r.activePoint.height),l+=(r.activePoint.height-n.width)/2,p=n.startX),n.startX=l,n.startY=p,r.activePoint.startX=l,r.activePoint.startY=p,r.activePoint.endX=r.activePoint.startX+n.width,r.activePoint.endY=r.activePoint.startY+n.height,r=this.updateWidthHeight(r)):("horizontal"===c&&o%90==0&&o%180!=0?c="vertical":"vertical"===c&&o%90==0&&o%180!=0&&(c="horizontal"),"horizontal"===c?(e.translate(e.canvas.width,0),e.scale(-1,1),r.activePoint=this.updateActPoint("horizontal",e)):"vertical"===c&&(e.translate(0,e.canvas.height),e.scale(1,-1),r.activePoint=this.updateActPoint("vertical",e)),n.startX=r.activePoint.startX,n.startY=r.activePoint.startY),n.startX=r.activePoint.startX,n.startY=r.activePoint.startY,l=n.startX,p=n.startY}0!==r.rotatedAngle&&i.notify("shape",{prop:"setPointCollForShapeRotation",onPropertyChange:!1,value:{obj:r}}),e.drawImage(r.imageCanvas,n.startX,n.startY,n.width,n.height),e.restore(),i.activeObj=a,360!==i.transform.degree&&-360!==i.transform.degree||(i.transform.degree=0)},e.prototype.rotateText=function(e){var o,i=this.parent,r=i.activeObj,a=t.extend({},i.activeObj,null,!0),n=i.activeObj.activePoint;-450===(o=0===r.shapeDegree?i.transform.degree:i.transform.degree-r.shapeDegree)&&(o=-90),o<0&&(o=360+o);var s={startX:0,startY:0,width:0,height:0};s.width=o%90==0&&o%180!=0?n.height:n.width,s.height=o%90==0&&o%180!=0?n.width:n.height,s.startX=n.startX,s.startY=n.startY;var l,p=s.startX,h=s.startY;e.save();for(var d=0,c=r.rotateFlipColl.length;d<c;d++){var u=r.rotateFlipColl[d];"number"==typeof u?(-450===(l=0===r.shapeDegree?u:u-r.shapeDegree)&&(l=-90),l<0&&(l=360+l),s.width=l%90==0&&l%180!=0?n.height:n.width,s.height=l%90==0&&l%180!=0?n.width:n.height,e.translate(e.canvas.width/2,e.canvas.height/2),e.rotate(Math.PI/180*u),e.translate(-e.canvas.height/2,-e.canvas.width/2),l%90==0&&l%270!=0||0===l?(h=e.canvas.width-n.endX,p=n.startY):l%270==0&&(p=e.canvas.height-n.endY,h=n.startX),s.startX=p,s.startY=h,n.startX=p,n.startY=h,n.endX=n.startX+s.width,n.endY=n.startY+s.height,r=this.updateWidthHeight(r)):("horizontal"===u&&o%90==0&&o%180!=0?u="vertical":"vertical"===u&&o%90==0&&o%180!=0&&(u="horizontal"),"horizontal"===u?(e.translate(e.canvas.width,0),e.scale(-1,1)):"vertical"===u&&(e.translate(0,e.canvas.height),e.scale(1,-1)),r.activePoint=n=this.updateActPoint(u,e),s.startX=n.startX,s.startY=n.startY),s.startX=n.startX,s.startY=n.startY,p=s.startX,h=s.startY}0!==r.rotatedAngle&&i.notify("shape",{prop:"setPointCollForShapeRotation",onPropertyChange:!1,value:{obj:r}}),h+=.4*r.textSettings.fontSize,this.textFlipDegree(e,p,h),e.restore(),i.activeObj=a,360!==i.transform.degree&&-360!==i.transform.degree||(i.transform.degree=0)},e.prototype.textFlipDegree=function(e,t,o){for(var i=this.parent.activeObj,r=i.keyHistory.split("\n"),a=i.textSettings.fontSize,n=.85*a+(a*r.length-a*r.length)/r.length,s=0,l=r.length;s<l;s++){var p=r[s];s>0&&(1===s&&(n-=.85*a),n+=a+.15*a),e.fillText(p,t+.15*a,o+n+(s>0?.25*a:.35*-a))}},e.prototype.clearOuterCanvas=function(e){var t=this.parent,o=t.img,i=o.destLeft,r=o.destTop,a=o.destWidth,n=o.destHeight,s=i>0?i:0,l=r>0?r:0;e.clearRect(0,0,s,t.lowerCanvas.height),e.clearRect(i+a,0,t.lowerCanvas.width-(i+a),t.lowerCanvas.height),e.clearRect(0,0,t.lowerCanvas.width,l),e.clearRect(0,r+n,t.lowerCanvas.width,t.lowerCanvas.height-(r+n)),""!==t.transform.currFlipState&&(t.img.destLeft=i,t.img.destTop=r)},e.prototype.setDestPoints=function(){var e,t=this.parent,o=t.transform,i=o.degree,r=o.zoomFactor;if(i%90==0&&i%180!=0){a={width:0,height:0};t.notify("transform",{prop:"calcMaxDimension",onPropertyChange:!1,value:{width:t.img.srcHeight,height:t.img.srcWidth,obj:a,isImgShape:null}}),e=a,this.isRotateZoom&&(e.width+=e.width*r,e.height+=e.height*r,t.img.destWidth=e.height,t.img.destHeight=e.width),t.img.destLeft=(t.lowerCanvas.clientWidth-e.height)/2,t.img.destTop=(t.lowerCanvas.clientHeight-e.width)/2,t.img.destWidth=e.height,t.img.destHeight=e.width}else{var a={width:0,height:0};t.notify("transform",{prop:"calcMaxDimension",onPropertyChange:!1,value:{width:t.img.srcWidth,height:t.img.srcHeight,obj:a,isImgShape:null}}),e=a,this.isRotateZoom&&(e.width+=e.width*r,e.height+=e.height*r,t.img.destWidth=e.width,t.img.destHeight=e.height),t.img.destLeft=(t.lowerCanvas.clientWidth-e.width)/2,t.img.destTop=0===i?(t.lowerCanvas.clientHeight-e.height+1)/2:(t.lowerCanvas.clientHeight-e.height)/2,t.img.destWidth=e.width,t.img.destHeight=e.height}},e.prototype.updateCurrTransState=function(e,o,i,r){var a=this.parent,n=a.img.destLeft,s=a.img.destTop;"initial"===e&&(this.lowerContext.setTransform(1,0,0,1,0,0),t.isNullOrUndefined(o)&&this.setDestPoints()),a.isCircleCrop||a.currSelectionPoint&&"crop-circle"===a.currSelectionPoint.shape?(this.currTransState(e,!0,null,i),0===a.transform.degree&&""===a.transform.currFlipState&&0===a.transform.straighten&&t.isNullOrUndefined(r)&&(a.img.destLeft=n,a.img.destTop=s),i&&(a.img.destLeft+=a.panPoint.totalPannedClientPoint.x,a.img.destTop+=a.panPoint.totalPannedClientPoint.y),a.notify("crop",{prop:"cropCircle",onPropertyChange:!1,value:{context:this.lowerContext,isSave:null,isFlip:null}}),i&&(a.img.destLeft-=a.panPoint.totalPannedClientPoint.x,a.img.destTop-=a.panPoint.totalPannedClientPoint.y)):(this.currTransState(e,null,null,i),0===a.transform.degree&&""===a.transform.currFlipState&&0===a.transform.straighten&&t.isNullOrUndefined(r)&&(a.img.destLeft=n,a.img.destTop=s))},e.prototype.currTransState=function(e,o,i,r){var a=this.parent;i=i||this.lowerContext,"initial"===e?this.setTransformColl(i,e):"reverse"===e&&(this.setTransformColl(i,e),this.setClientTransDim(o),(a.isCircleCrop||a.currSelectionPoint&&"crop-circle"===a.currSelectionPoint.shape&&t.isNullOrUndefined(r))&&(r&&(a.img.destLeft+=a.panPoint.totalPannedClientPoint.x,a.img.destTop+=a.panPoint.totalPannedClientPoint.y),a.notify("crop",{prop:"cropCircle",onPropertyChange:!1,value:{context:this.lowerContext,isSave:null,isFlip:null}}),r&&(a.img.destLeft-=a.panPoint.totalPannedClientPoint.x,a.img.destTop-=a.panPoint.totalPannedClientPoint.y)))},e.prototype.setTransformColl=function(e,t){var o=this.parent;if("initial"===t)for(var i=0,r=o.rotateFlipColl.length;i<r;i++)this.setTransform(e,o.rotateFlipColl[i]);else if("reverse"===t)for(i=o.rotateFlipColl.length-1;i>=0;i--)this.setTransform(e,o.rotateFlipColl[i],!0)},e.prototype.setTransform=function(e,o,i){var r=this.parent;switch(i&&90===o?o=-90:i&&-90===o&&(o=90),"horizontal"===o&&r.transform.degree%90==0&&r.transform.degree%180!=0?o="vertical":"vertical"===o&&r.transform.degree%90==0&&r.transform.degree%180!=0&&(o="horizontal"),r.notify("transform",{prop:"setReverseRotate",onPropertyChange:!1,value:{bool:!0}}),r.notify("transform",{prop:"setReverseFlip",onPropertyChange:!1,value:{isReverseFlip:!0}}),t.isNullOrUndefined(i)&&e.clearRect(0,0,e.canvas.width,e.canvas.height),o){case 90:case-90:e.translate(e.canvas.width/2,e.canvas.height/2),e.rotate(Math.PI/180*o),e.translate(-e.canvas.width/2,-e.canvas.height/2);break;case"horizontal":e.translate(e.canvas.width,0),e.scale(-1,1);break;case"vertical":e.translate(0,e.canvas.height),e.scale(1,-1)}r.notify("transform",{prop:"setReverseRotate",onPropertyChange:!1,value:{bool:!1}}),r.notify("transform",{prop:"setReverseFlip",onPropertyChange:!1,value:{isReverseFlip:!1}})},e.prototype.drawImgToCanvas=function(e){var t=this.parent;this.lowerContext.clearRect(0,0,t.lowerCanvas.width,t.lowerCanvas.height),t.img.destWidth=e.width,t.img.destHeight=e.height,this.isInitialLoading&&(t.notify("filter",{prop:"initFilter",onPropertyChange:!1}),this.isInitialLoading=!1);var o=this.lowerContext.filter;this.lowerContext.clearRect(0,0,t.lowerCanvas.width,t.lowerCanvas.height),this.drawImage(),(t.currSelectionPoint&&"crop-circle"===t.currSelectionPoint.shape||t.isCircleCrop)&&t.notify("crop",{prop:"cropCircle",onPropertyChange:!1,value:{context:this.lowerContext,isSave:null,isFlip:null}}),this.lowerContext.filter=o},e.prototype.renderImage=function(e,o,i,r){var a=this.parent;a.notify("shape",{prop:"applyActObj",onPropertyChange:!1,value:{isMouseDown:null}}),t.isNullOrUndefined(o)&&(this.upperContext.clearRect(0,0,a.lowerCanvas.width,a.lowerCanvas.height),this.lowerContext.clearRect(0,0,a.lowerCanvas.width,a.lowerCanvas.height)),e?this.setTransformColl(this.lowerContext,"initial"):(0!==a.transform.zoomFactor&&(this.isRotateZoom=!0),this.updateCurrTransState("initial",null,null,r)),a.notify("transform",{prop:"setDestPointsForFlipState",onPropertyChange:!1}),this.drawImage(),a.notify("transform",{prop:"setDestPointsForFlipState",onPropertyChange:!1}),e?this.setTransformColl(this.lowerContext,"reverse"):(this.updateCurrTransState("reverse",null,null,r),this.isRotateZoom=!1),i?a.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"zoom",pen:"zoom",isPreventApply:null}}):a.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"iterate",pen:"iterate",isPreventApply:null}}),this.clearOuterCanvas(this.lowerContext),(a.isCircleCrop||a.currSelectionPoint&&"crop-circle"===a.currSelectionPoint.shape)&&a.notify("crop",{prop:"cropCircle",onPropertyChange:!1,value:{context:this.lowerContext,isSave:null,isFlip:null}})},e.prototype.imageOnLoad=function(e){var i=this,r=this.parent,a=this;r.baseImg.src=e,r.baseImg.onload=function(){r.imgSrc=e,r.notify("filter",{prop:"update-finetunes",onPropertyChange:!1}),a.lowerContext.drawImage(r.baseImg,0,0,a.parent.lowerCanvas.width,a.parent.lowerCanvas.height),o.hideSpinner(r.element),r.element.style.opacity="1",a.updateBaseImgCanvas();var n={fileName:i.fileName,fileType:i.fileType,isValidImage:!0};if(a.updateCanvas(),r.currObjType.isUndoZoom&&(r.currObjType.isUndoZoom=!1,a.parent.lowerCanvas.style.display="block"),r.isUndoRedo=i.isErrorImage=!1,t.Browser.isDevice){r.notify("toolbar",{prop:"destroy-top-toolbar",onPropertyChange:!1}),r.notify("toolbar",{prop:"destroy-bottom-toolbar",onPropertyChange:!1});s={isApplyBtn:!1,isDevice:t.Browser.isDevice,isOkBtn:null,isResize:null,isFrame:null,isMainToolbar:!0};r.notify("toolbar",{prop:"init-main-toolbar",onPropertyChange:!1,value:s}),r.notify("toolbar",{prop:"create-bottom-toolbar",onPropertyChange:!1})}else{r.notify("toolbar",{prop:"destroy-top-toolbar",onPropertyChange:!1});var s={isApplyBtn:!1,isDevice:!1,isOkBtn:null};r.notify("toolbar",{prop:"init-main-toolbar",onPropertyChange:!1,value:s})}r.isImageLoaded&&"0.5"!==r.element.style.opacity&&r.trigger("fileOpened",n)},r.baseImg.onerror=function(){o.hideSpinner(r.element),a.isErrorImage=!0,a.errorLoading()}},e.prototype.errorLoading=function(){var e={fileName:null,fileType:null,isValidImage:!1};this.parent.trigger("fileOpened",e)},e.prototype.updateBaseImgCanvas=function(){var e=this.parent;e.baseImgCanvas.width=e.baseImg.width,e.baseImgCanvas.height=e.baseImg.height,e.baseImgCanvas.getContext("2d").drawImage(e.baseImg,0,0)},e.prototype.updateCanvas=function(){var e=this.parent;e.img.srcWidth=e.baseImgCanvas.width,e.img.srcHeight=e.baseImgCanvas.height;var o={width:0,height:0};e.notify("transform",{prop:"calcMaxDimension",onPropertyChange:!1,value:{width:e.img.srcWidth,height:e.img.srcHeight,obj:o,isImgShape:null}});var i=o;e.img.destLeft=(e.lowerCanvas.clientWidth-i.width)/2,e.img.destTop=(e.lowerCanvas.clientHeight-i.height+1)/2,this.drawImgToCanvas(i),this.origDim.width=e.img.destWidth,this.origDim.height=e.img.destHeight,this.zoomCrop.width=e.img.destWidth,this.zoomCrop.height=e.img.destHeight,e.notify("transform",{prop:"setCropDimension",onPropertyChange:!1,value:{width:e.img.destWidth,height:e.img.destHeight}});var r={startX:e.img.destLeft,startY:e.img.destTop,width:e.img.destWidth,height:e.img.destHeight};e.notify("crop",{prop:"setCropDestPoints",onPropertyChange:!1,value:{point:r}});var a=this.lowerContext.filter;this.lowerContext.filter="none",e.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"iterate",pen:"zoom",isPreventApply:null}}),this.lowerContext.filter=a,e.img.destWidth>0&&e.img.destHeight>0&&(e.isImageLoaded=!0),e.isUndoRedo&&""!==e.transform.currFlipState&&e.notify("transform",{prop:"flipImage",onPropertyChange:!1,value:{direction:e.toPascalCase(e.transform.currFlipState)}}),e.disabled&&e.element.setAttribute("class","e-disabled"),(1!==e.zoomSettings.zoomFactor||e.zoomSettings.zoomPoint)&&e.zoom(e.zoomSettings.zoomFactor,e.zoomSettings.zoomPoint),t.isNullOrUndefined(this.initZoomValue)&&(this.initZoomValue=e.zoomSettings.zoomFactor),this.isImageEdited=!1},e.prototype.resetFrameZoom=function(e){var o=this.parent;if(!t.isNullOrUndefined(o.tempFrameZoomLevel)){var i=o.tempFrameZoomLevel;o.tempFrameZoomLevel=null,o.notify("transform",{prop:"resetZoom",onPropertyChange:!1}),o.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:i,zoomPoint:null,isResize:!0}});var r=o.cancelCropSelection;e&&r&&(r.previousObj.frameObj=t.extend({},o.frameObj,null,!0),r.currentObj.frameObj=t.extend({},o.frameObj,null,!0),r.previousObj.frame=r.currentObj.frame=o.frameObj.type),this.updateCropSelObj(),o.cancelCropSelection=null}},e.prototype.performCancel=function(e,o,i){var r=this.parent;i&&(r.noPushUndo=!1);var a={bool:r.isStraightening};e=e||!1;var n={bool:!1};if(r.allowDownScale=!0,r.notify("selection",{prop:"getFreehandDrawEditing",onPropertyChange:!1,value:{obj:n}}),t.isNullOrUndefined(o)&&JSON.stringify(r.frameObj)!==JSON.stringify(r.tempFrameObj)&&(t.extend(r.frameObj,r.tempFrameObj),this.renderImage(null,null,!0)),this.resetFrameZoom(!1),n.bool)r.notify("freehand-draw",{prop:"cancelFhd",onPropertyChange:!1}),r.notify("toolbar",{prop:"destroy-qa-toolbar",onPropertyChange:!1}),r.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"ok"}});else if("block"===r.textArea.style.display||"inline-block"===r.textArea.style.display)r.textArea.style.display="none",r.textArea.value="",r.textArea.style.transform="",this.prevActObj?(r.activeObj=this.prevActObj,this.prevActObj=null):(r.activeObj.strokeSettings=this.tempStrokeSettings,r.activeObj.textSettings=this.tempTextSettings),r.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"cancel"}}),this.isShapeTextInserted&&r.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),r.notify("shape",{prop:"applyActObj",onPropertyChange:!1,value:{isMouseDown:!0}}),r.notify("toolbar",{prop:"refresh-main-toolbar",onPropertyChange:!1}),r.notify("selection",{prop:"setTempActObj",onPropertyChange:!1,value:{obj:r.activeObj}}),r.drawingShape&&r.enableShapeDrawing(r.toPascalCase(r.drawingShape),!0);else if((!t.Browser.isDevice||t.Browser.isDevice&&!a.bool)&&document.querySelector("#"+r.element.id+"_sliderWrapper")||r.currObjType.isFiltered){this.lowerContext.filter=this.tempAdjValue,r.canvasFilter=this.tempAdjValue,r.notify("filter",{prop:"setAdjustmentValue",onPropertyChange:!1,value:{adjustmentValue:this.tempAdjValue}}),r.initialAdjustmentValue=this.tempAdjValue,this.lowerContext.filter.split(" ").length>1&&"1"===this.lowerContext.filter.split(" ")[0].split("(")[1].split(")")[0]&&r.notify("filter",{prop:"setBrightnessAdjusted",onPropertyChange:!1,value:{isBrightnessAdjusted:!1}}),r.currentFilter=this.tempFilter,r.notify("filter",{prop:"setBevelFilter",onPropertyChange:!1,value:{bevelFilter:this.lowerContext.filter}}),this.lowerContext.clearRect(0,0,r.lowerCanvas.width,r.lowerCanvas.height),this.redrawImgWithObj(),r.currObjType.isFiltered=!1;var s={tempAdjustmentLevel:null};r.notify("filter",{prop:"getTempAdjustmentLevel",onPropertyChange:!1,value:{obj:s}}),r.notify("filter",{prop:"setAdjustmentLevel",onPropertyChange:!1,value:{adjustmentLevel:t.extend({},s.tempAdjustmentLevel,{},!0)}}),r.notify("undo-redo",{prop:"setUndoRedoStep",onPropertyChange:!1,value:{step:this.tempUndoRedoStep}}),r.upperCanvas.style.cursor=r.cursor="default",r.currObjType.isCustomCrop=!1,this.tempStrokeSettings={strokeColor:"#fff",fillColor:"",strokeWidth:null},this.clearOuterCanvas(this.lowerContext),(r.currSelectionPoint&&"crop-circle"===r.currSelectionPoint.shape||r.isCircleCrop)&&r.notify("crop",{prop:"cropCircle",onPropertyChange:!1,value:{context:this.lowerContext,isSave:null,isFlip:null}});l={type:"main",isApplyBtn:null,isCropping:null,isZooming:null};r.element.querySelector(".e-contextual-toolbar-wrapper").classList.add("e-hide"),r.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:l}),r.activeObj.shape&&"image"===r.activeObj.shape&&r.notify("toolbar",{prop:"destroy-qa-toolbar",onPropertyChange:!1}),r.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"cancel"}}),r.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),this.upperContext.clearRect(0,0,r.upperCanvas.width,r.upperCanvas.height)}else if(e&&(!t.Browser.isDevice||t.Browser.isDevice&&!a.bool)){var l={type:"main",isApplyBtn:null,isCropping:null,isZooming:null};r.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:l})}else this.cancelItems(),r.transform.zoomFactor>0?(r.togglePan=!0,r.notify("selection",{prop:"setDragCanvas",value:{bool:!0}})):(r.togglePan=!1,r.notify("selection",{prop:"setDragCanvas",value:{bool:!1}}));this.isShapeTextInserted=!1,this.isNewPath=!1,r.notify("toolbar",{prop:"refresh-dropdown-btn",value:{isDisabled:!1}}),r.notify("toolbar",{prop:"setCurrentToolbar",value:{type:"main"}}),i&&(r.noPushUndo=!1),r.drawingShape=null,r.notify("draw",{prop:"resetTempObjColl"}),r.notify("draw",{prop:"resetTempPointColl"})},e.prototype.cancelItems=function(){var e,o=this.parent,i=!1,r=o.element.id,a=o.element.querySelector("#"+r+"_aspectratio"),n=o.element.querySelector("#"+r+"_nonaspectratio"),s=["rectangle","ellipse","line","arrow","path","image"];if(void 0!==o.activeObj.shape&&(e=o.activeObj.shape.split("-")),void 0===e&&o.currObjType.isCustomCrop?i=!0:void 0!==e&&"crop"===e[0]&&(i=!0),i&&o.isCropTab&&(o.isCropTab=!1,o.transform.zoomFactor=o.transform.defaultZoomFactor),o.isResize&&(a||n||"resize-toolbar"===o.currentToolbar)){var l={width:null,height:null};o.notify("selection",{prop:"getNumTextValue",onPropertyChange:!1,value:{obj:l}});var p={x:l.width,y:l.height},h=o.element.querySelector("#"+o.element.id+"_aspectratio"),d=o.element.querySelector(".e-ie-toolbar-aspect-ratio-btn");if(p&&p.x&&p.y&&!t.isNullOrUndefined(o.aspectWidth))if(h||d&&!d.classList.contains("e-hidden"))o.notify("transform",{prop:"resizeImage",value:{width:o.aspectWidth,height:o.aspectHeight}});else{var c=o.currObjType.isUndoAction;o.currObjType.isUndoAction=!1,o.notify("transform",{prop:"resizeCrop",value:{width:o.aspectWidth,height:o.aspectHeight}}),o.currObjType.isUndoAction=c}var u={prevCropObj:o.prevCropObj},v={prevObj:o.prevObj};if(o.notify("toolbar",{prop:"getPrevCropObj",onPropertyChange:!1,value:{obj:u}}),o.notify("toolbar",{prop:"getPrevObj",onPropertyChange:!1,value:{obj:v}}),u.prevCropObj&&v.prevObj){o.objColl=[],o.pointColl=[],o.freehandCounter=0,o.cropObj=t.extend({},u.prevCropObj,{},!0),this.setCurrentObj(v.prevObj),o.objColl=v.prevObj.objColl,o.pointColl=v.prevObj.pointColl,o.freehandCounter=o.pointColl.length,o.transform.straighten=0,o.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"zoom",pen:"zoom",isPreventApply:null}});var g=o.currSelectionPoint?t.extend({},o.currSelectionPoint,{},!0):null;o.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:-o.transform.zoomFactor,zoomPoint:null,isResize:!0}}),o.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:v.prevObj.defaultZoom,zoomPoint:null,isResize:!0}}),o.currSelectionPoint=g,v.prevObj.zoomFactor&&o.setProperties({zoomSettings:{zoomFactor:v.prevObj.zoomFactor}},!0),o.notify("transform",{prop:"setPreviousZoomValue",onPropertyChange:!1,value:{previousZoomValue:o.zoomSettings.zoomFactor}})}o.isResize=!1,o.notify("transform",{prop:"setResizedImgAngle",onPropertyChange:!1,value:{angle:null}});var f=o.isCropTab;o.isCropTab=!1,this.updateCropSelObj(),o.cancelCropSelection=null,o.isCropTab=f}switch(!0){case o.togglePen:this.cancelPen();break;case"text"===o.activeObj.shape:this.cancelText();break;case-1!==s.indexOf(o.activeObj.shape):this.cancelShape();break;case i:this.cancelSelection();break;default:o.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),this.upperContext.clearRect(0,0,o.upperCanvas.width,o.upperCanvas.height),o.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"cancel"}})}o.notify("selection",{prop:"setCurrentDrawingShape",onPropertyChange:!1,value:{value:""}}),o.upperCanvas.style.cursor=o.cursor="default",o.currObjType.isCustomCrop=!1,this.tempStrokeSettings={strokeColor:"#fff",fillColor:"",strokeWidth:null};var C={type:"main",isApplyBtn:null,isCropping:!1,isZooming:null};o.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:C})},e.prototype.cancelPen=function(){var e=this.parent;this.upperContext.clearRect(0,0,e.upperCanvas.width,e.upperCanvas.height),e.togglePen=!1,e.upperCanvas.style.cursor=e.cursor="default";var o=t.extend([],e.pointColl,[],!0);e.pointColl={};for(var i=0;i<this.tempFreehandCounter;i++)e.pointColl[i]=o[i];e.freehandCounter=this.tempFreehandCounter,e.notify("freehand-draw",{prop:"setCurrentFreehandDrawIndex",value:{value:this.tempCurrFhdIndex}}),e.activeObj.strokeSettings=this.tempStrokeSettings,e.notify("shape",{prop:"setStrokeSettings",value:{strokeSettings:e.activeObj.strokeSettings,strokeColor:null,fillColor:null,strokeWidth:null}}),e.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"cancel"}}),e.notify("selection",{prop:"setFreehandDrawCustomized",value:{isFreehandDrawCustomized:!1}}),e.objColl=t.extend([],this.tempObjColl,[],!0),e.pointColl=t.extend([],this.tempPointColl,[],!0),e.freehandCounter=e.pointColl.length,this.tempPointColl={},this.renderImage(),e.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"ok",isCancel:!0}})},e.prototype.cancelText=function(){var e=this.parent;if(e.notify("shape",{prop:"setTextSettings",onPropertyChange:!1,value:{textSettings:this.tempTextSettings,fontFamily:null,fontSize:null}}),e.notify("shape",{prop:"setStrokeSettings",value:{strokeSettings:this.tempStrokeSettings,strokeColor:null,fillColor:null,strokeWidth:null}}),t.isNullOrUndefined(e.activeObj.currIndex))e.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),this.upperContext.clearRect(0,0,e.upperCanvas.width,e.upperCanvas.height);else{var o={appliedUndoRedoColl:[]};e.notify("undo-redo",{prop:"getAppliedUndoRedoColl",value:{obj:o}});var i=o.appliedUndoRedoColl.length,r=o.appliedUndoRedoColl[i-1];this.prevActObj&&r&&r.currentObjColl.length&&r.currentObjColl[r.currentObjColl.length-1].currIndex===this.prevActObj.currIndex?(e.activeObj=this.prevActObj,this.prevActObj=null):(e.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),this.upperContext.clearRect(0,0,e.upperCanvas.width,e.upperCanvas.height))}e.notify("toolbar",{prop:"destroy-qa-toolbar",onPropertyChange:!1}),this.tempTextSettings={text:"Enter Text",fontFamily:e.fontFamily.default,fontSize:null,fontRatio:null,bold:!1,italic:!1,underline:!1},e.objColl=t.extend([],this.tempObjColl,[],!0),e.pointColl=t.extend([],this.tempPointColl,[],!0),this.renderImage(),this.tempObjColl=[],e.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"ok",isCancel:!0}})},e.prototype.cancelShape=function(){var e=this.parent;if(e.notify("shape",{prop:"setStrokeSettings",value:{strokeSettings:this.tempStrokeSettings,strokeColor:null,fillColor:null,strokeWidth:null}}),t.isNullOrUndefined(e.activeObj.currIndex))e.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),this.upperContext.clearRect(0,0,e.upperCanvas.width,e.upperCanvas.height);else if(this.isNewPath)e.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),this.upperContext.clearRect(0,0,e.upperCanvas.width,e.upperCanvas.height),this.renderImage();else{var o={appliedUndoRedoColl:[]};e.notify("undo-redo",{prop:"getAppliedUndoRedoColl",value:{obj:o}});for(var i=void 0,r=0,a=o.appliedUndoRedoColl.length;r<a;r++)for(var n=o.appliedUndoRedoColl[r].currentObjColl,s=0,l=n.length;s<l;s++)if(this.prevActObj&&this.prevActObj.currIndex&&n[s].currIndex===this.prevActObj.currIndex){i=n[0];break}this.prevActObj&&i?(e.activeObj=this.prevActObj,this.prevActObj=null,e.notify("selection",{prop:"redrawShape",onPropertyChange:!1,value:{obj:e.activeObj}}),e.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"cancel"}}),e.notify("shape",{prop:"applyActObj",onPropertyChange:!1,value:{isMouseDown:!0}})):(e.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),this.upperContext.clearRect(0,0,e.upperCanvas.width,e.upperCanvas.height));var p={undoRedoStep:null};e.notify("undo-redo",{prop:"getUndoRedoStep",value:{obj:p}}),o.appliedUndoRedoColl[p.undoRedoStep-1]?e.objColl=t.extend([],o.appliedUndoRedoColl[p.undoRedoStep-1].currentObjColl,[],!0):e.objColl=[],this.renderImage()}e.currObjType.isDragging=!1,e.notify("toolbar",{prop:"destroy-qa-toolbar",onPropertyChange:!1}),e.objColl=t.extend([],this.tempObjColl,[],!0),e.pointColl=t.extend([],this.tempPointColl,[],!0),this.renderImage(),this.tempObjColl=[],e.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"ok",isCancel:!0}})},e.prototype.cancelSelection=function(){var e=this.parent;if(e.cancelCropSelection){var o={value:e.tempStraighten};e.transform.straighten=o.value,e.straightenBaseImageCanvas(),e.notify("freehand-draw",{prop:"resetStraightenPoint"}),e.notify("draw",{prop:"render-image",value:{isMouseWheel:!1}}),e.notify("draw",{prop:"setStraightenActObj",value:{activeObj:e.activeObj}}),e.notify("crop",{prop:"resizeWrapper"}),this.updateCropSelObj(),this.tempStraightenDestPoints&&JSON.stringify(this.tempStraightenDestPoints)!==JSON.stringify(this.straightenDestPoints)&&(this.straightenDestPoints=t.extend({},this.tempStraightenDestPoints,{},!0))}},e.prototype.updateCropSelObj=function(){var e=this.parent;e.cancelCropSelection&&(e.cropObj=t.extend({},e.cancelCropSelection.previousCropObj,{},!0),e.afterCropActions=e.cancelCropSelection.previousObj.afterCropActions,e.notify("undo-redo",{prop:"undoDefault",onPropertyChange:!1,value:{obj:e.cancelCropSelection}}),e.currSelectionPoint=t.extend({},e.cancelCropSelection.previousCropObj.activeObj,!0),e.currSelectionPoint&&t.isNullOrUndefined(e.currSelectionPoint.shape)&&(e.currSelectionPoint=null),this.clearOuterCanvas(this.lowerContext),(e.isCircleCrop||e.currSelectionPoint&&"crop-circle"===e.currSelectionPoint.shape)&&e.notify("crop",{prop:"cropCircle",onPropertyChange:!1,value:{context:this.lowerContext,isSave:null,isFlip:null}}))},e.prototype.updateCropSelection=function(){var e=this.parent,o={currObj:{}};e.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:o}});var i=o.currObj;i.objColl=t.extend([],e.objColl,[],!0),i.pointColl=t.extend([],e.pointColl,[],!0),i.afterCropActions=t.extend([],e.afterCropActions,[],!0);var r={selPointColl:null};e.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:r}}),i.selPointColl=t.extend([],r.selPointColl,[],!0),e.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:t.extend({},e.cropObj,{},!0),currentCropObj:t.extend({},e.cropObj,{},!0),previousText:null,currentText:null,filter:null,isCircleCrop:e.isCircleCrop}},e.prototype.updateFlipPan=function(e){var t=this.parent;if(""!==t.transform.currFlipState){var o=this.lowerContext.filter;t.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),t.notify("transform",{prop:"rotatedFlip",onPropertyChange:!1}),this.lowerContext.filter="none",t.notify("freehand-draw",{prop:"freehandRedraw",onPropertyChange:!1,value:{context:this.lowerContext,points:null}}),this.lowerContext.filter=o,this.upperContext.clearRect(0,0,t.upperCanvas.width,t.upperCanvas.height),e&&this.drawObject("duplicate",e)}},e.prototype.select=function(e,o,i,r,a){var n=this.parent;if(e=e.toLowerCase(),!n.disabled&&n.isImageLoaded){n.allowDownScale=!1;var s={currObj:{}};n.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:s}});var l=s.currObj;l.objColl=t.extend([],n.objColl,[],!0),l.pointColl=t.extend([],n.pointColl,[],!0),l.afterCropActions=n.afterCropActions;var p={selPointColl:null};n.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:p}}),l.selPointColl=t.extend([],p.selPointColl,[],!0),n.notify("crop",{prop:"setPreviousCropCurrentObj",onPropertyChange:!1,value:{obj:l}}),n.transform.zoomFactor>0&&n.activeObj.shape&&"crop"===n.activeObj.shape.split("-")[0]&&t.isNullOrUndefined(this.currSelPoint)&&(this.currSelPoint=t.extend({},n.activeObj,{},!0));var h=!1,d=void 0;void 0!==n.activeObj.shape&&(d=n.activeObj.shape.split("-")),void 0===d&&n.currObjType.isCustomCrop?h=!0:void 0!==d&&"crop"===d[0]&&(h=!0);var c={currObj:{}};n.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:c}});var u=c.currObj;if(u.objColl=t.extend([],n.objColl,[],!0),u.pointColl=t.extend([],n.pointColl,[],!0),u.afterCropActions=t.extend([],n.afterCropActions,[],!0),n.notify("shape",{prop:"redrawActObj",onPropertyChange:!1,value:{x:null,y:null,isMouseDown:null}}),n.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),n.notify("shape",{prop:"setKeyHistory",onPropertyChange:!1,value:{keyHistory:""}}),this.upperContext.clearRect(0,0,n.upperCanvas.width,n.upperCanvas.height),n.upperCanvas.style.display="block",n.currSelectionPoint||0!==n.transform.defaultZoomFactor||0!==n.transform.degree&&0!==n.panPoint.totalPannedInternalPoint.x&&0!==n.panPoint.totalPannedInternalPoint.y&&!h){if(n.isCircleCrop=!1,0!==n.transform.defaultZoomFactor&&!this.isResizeSelect){var v=n.isCropTab;n.isCropTab=!1,n.notify("transform",{prop:"resetZoom",onPropertyChange:!1}),n.isCropTab=v,this.resetPanPoints()}n.notify("freehand-draw",{prop:"updateFHDColl",onPropertyChange:!1}),n.isCropTab=!0,n.isCircleCrop=!1,this.isResizeSelect||n.notify("crop",{prop:"setCurrSelPoints",onPropertyChange:!1,value:{isSetDimension:!0}}),n.transform.zoomFactor=n.transform.cropZoomFactor,t.isNullOrUndefined(n.cropObj.activeObj.shape)&&(n.currObjType.shape="crop-"+e,this.drawNewSelection(e,o,i,r,a))}else this.isCropSelect?this.isCropSelect=!1:(n.notify("crop",{prop:"adjustStraightenForShapes",onPropertyChange:!1,value:{type:"reverse",isInitialRotated:!0}}),n.notify("freehand-draw",{prop:"updateFHDColl",onPropertyChange:!1}),this.renderImage()),"custom"===e&&(n.currObjType.shape=""),this.drawNewSelection(e,o,i,r,a)}},e.prototype.drawNewSelection=function(e,o,i,r,a){var n,s=this.parent,l="crop-"+e.toLowerCase();"crop-custom"===l?""!==s.currObjType.shape&&"crop-custom"!==s.currObjType.shape||(this.drawCustomSelection("crop-custom",o,i,r,a),this.adjToStraighten(),this.updateSelectionInsert(),s.isStraightening&&(this.straightenActObj=t.extend({},s.activeObj,{},!0),this.straightenInitZoom=s.transform.zoomFactor)):"crop-canvas"===l?(s.upperCanvas.style.display="block",s.notify("selection",{prop:"setDragCanvas",value:{bool:!0}})):(s.currObjType.isCustomCrop=!1,s.currObjType.shape=l,r&&a?n={startX:o,startY:i,endX:o+r,endY:i+a,width:r,height:a}:r&&"crop-circle"===l&&(n={startX:o,startY:i,endX:o+r,endY:i+r,width:r,height:r}),s.activeObj.shape=l,this.updateSelectionInsert(n))},e.prototype.updateSelectionInsert=function(e){var t=this.parent,o=t.activeObj.activePoint,i={shapeSettingsObj:{}};t.notify("selection",{prop:"updatePrevShapeSettings",onPropertyChange:!1,value:{obj:i}});var r={type:t.getSelectionType(i.shapeSettingsObj.type),startX:i.shapeSettingsObj.startX,startY:i.shapeSettingsObj.startY,width:i.shapeSettingsObj.width,height:i.shapeSettingsObj.height},a={action:"insert",previousSelectionSettings:r,currentSelectionSettings:r};t.trigger("selectionChanging",a),t.notify("shape",{prop:"updSelChangeEventArgs",onPropertyChange:!1,value:{selectionSettings:a.currentSelectionSettings}}),"Custom"===a.currentSelectionSettings.type?this.drawObject("duplicate",t.activeObj,null,null,!0):(0===o.startX&&0===o.startY&&0===o.width&&0===o.height||(e={startX:o.startX,startY:o.startY,endX:o.endX,endY:o.endY,width:o.width,height:o.height}),this.drawObject("duplicate",null,!0,e))},e.prototype.drawCustomSelection=function(e,o,i,r,a){var n=this.parent,s=n.activeObj.activePoint;if(n.currObjType.isCustomCrop=!0,this.upperContext.clearRect(0,0,n.upperCanvas.width,n.upperCanvas.height),n.currObjType.shape=n.activeObj.shape=e.toLowerCase(),t.isNullOrUndefined(o)||t.isNullOrUndefined(i)||t.isNullOrUndefined(r)||t.isNullOrUndefined(a))if(r&&a){var l=n.img,p=l.destLeft,h=l.destTop,d=l.destWidth,c=l.destHeight;s.width=r,s.height=a,s.startX=p+(d/2-r/2),s.startY=h+(c/2-a/2)}else{if(t.isNullOrUndefined(n.transform.zoomFactor)||0===n.transform.zoomFactor){var u=n.img,v=u.destLeft,g=u.destTop,f=u.destWidth,C=u.destHeight,b=n.lowerCanvas.width,m=n.lowerCanvas.height,y=s;v>=0&&g>=0?(y.startX=v,y.startY=g,y.endX=v+f,y.endY=g+C):v>=0?(y.startX=v,y.startY=7.5,y.endX=v+f,y.endY=m-15):g>=0?(y.startX=7.5,y.startY=g,y.endX=b-15,y.endY=g+C):(y.startX=7.5,y.startY=7.5,y.endX=b-15,y.endY=m-15)}else{var P=n.img,j=P.destLeft,x=P.destTop,w=P.destWidth,O=P.destHeight,S=n.lowerCanvas.width,T=n.lowerCanvas.height,F=s;F.startX=Math.max(j>0?j:7.5,j),F.startY=Math.max(x>0?x:7.5,x),F.endX=Math.min(j+w+15<S?j+w-15:S-15,j+w),F.endY=Math.min(x+O+15<T?x+O-15:T-15,x+O)}var k=n.img,p=k.destLeft,h=k.destTop,d=k.destWidth,c=k.destHeight,I=n.lowerCanvas.clientWidth,A=n.lowerCanvas.clientHeight,z=s;if(z.startX=Math.max(z.startX,p),z.startY=Math.max(z.startY,h),z.endX=Math.min(z.endX,p+d),z.endY=Math.min(z.endY,h+c),n.transform.straighten>0?(this.imgCanvasPoints[0].x>z.startX&&(z.startX=this.imgCanvasPoints[0].x),this.imgCanvasPoints[0].y>z.startY&&(z.startY=this.imgCanvasPoints[0].y),this.imgCanvasPoints[2].x<z.endX&&(z.endX=this.imgCanvasPoints[2].x),this.imgCanvasPoints[2].y<z.endY&&(z.endY=this.imgCanvasPoints[2].x)):n.transform.straighten<0&&(this.imgCanvasPoints[3].x>z.startX&&(z.startX=this.imgCanvasPoints[3].x),this.imgCanvasPoints[3].y<z.startY&&(z.startY=this.imgCanvasPoints[3].y),this.imgCanvasPoints[1].x<z.endX&&(z.endX=this.imgCanvasPoints[1].x),this.imgCanvasPoints[1].y>z.endY&&(z.endY=this.imgCanvasPoints[1].x)),z.startX===p&&p+d>I&&(z.endX=I-15),z.startY===h&&h+c>A&&(z.endY=A-15),n.activeObj.activePoint.startX>n.activeObj.activePoint.endX){D=n.activeObj.activePoint.startX;n.activeObj.activePoint.startX=n.activeObj.activePoint.endX,n.activeObj.activePoint.endX=D}if(n.activeObj.activePoint.startY>n.activeObj.activePoint.endY){var D=n.activeObj.activePoint.startY;n.activeObj.activePoint.startY=n.activeObj.activePoint.endY,n.activeObj.activePoint.endY=D}n.activeObj=this.updateWidthHeight(n.activeObj),this.updateActiveObject(s,n.activeObj),this.adjActObj()}else s.startX=o,s.startY=i,s.endX=o+r,s.endY=i+a,s.width=r,s.height=a;this.updateSelectionInsert()},e.prototype.adjToStraighten=function(){var e=this.parent;if(0!==e.transform.straighten&&e.isStraightening){var t=e.activeObj.activePoint;t.startX+=7.5,t.startY+=7.5,t.endX-=7.5,t.endY-=7.5,e.activeObj=this.updateWidthHeight(e.activeObj)}},e.prototype.adjActObj=function(){var e=this.parent;if(0!==e.transform.straighten)for(var o=e.activeObj.activePoint,i=t.extend({},o,{},!0),r=0;;){r++;var a={isIntersect:null,arr:null};if(e.notify("draw",{prop:"updateImgCanvasPoints",onPropertyChange:!1}),e.notify("draw",{prop:"isLinesIntersect",onPropertyChange:!1,value:{obj:a}}),a.arr[0]||a.arr[1]||a.arr[2]||a.arr[3]||100===r){o=t.extend({},i,{},!0);break}i=t.extend({},o,{},!0),o.startX-=5,o.endX+=5,o.width=o.endX-o.startX,this.updateActiveObject(o,e.activeObj)}},e.prototype.callUpdateCurrTransState=function(){var e=this.parent,o=t.extend([],e.objColl,[],!0),i=t.extend({},e.activeObj,{},!0);e.objColl=[],e.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),this.isRotateZoom=!0,this.updateCurrTransState("initial"),this.lowerContext.clearRect(0,0,e.lowerCanvas.width,e.lowerCanvas.height),0===e.transform.degree&&e.rotateFlipColl.length>0&&(e.img.destLeft+=e.panPoint.totalPannedPoint.x,e.img.destTop+=e.panPoint.totalPannedPoint.y),e.img.destLeft+=e.panPoint.totalPannedInternalPoint.x,e.img.destTop+=e.panPoint.totalPannedInternalPoint.y;var r=this.lowerContext.filter;0===e.transform.degree&&e.notify("transform",{prop:"setDestPointsForFlipState",onPropertyChange:!1}),this.drawImage(),this.updateCurrTransState("reverse"),0===e.transform.degree&&e.rotateFlipColl.length>0&&(e.img.destLeft+=e.panPoint.totalPannedPoint.x,e.img.destTop+=e.panPoint.totalPannedPoint.y),this.isRotateZoom=!1,e.objColl=o;var a=e.togglePen;e.togglePen=!1,this.lowerContext.filter="none",e.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"iterate",pen:"iterate",isPreventApply:null}}),e.img.destLeft+=e.panPoint.totalPannedInternalPoint.x,e.img.destTop+=e.panPoint.totalPannedInternalPoint.y,e.img.destLeft-=e.panPoint.totalPannedInternalPoint.x,e.img.destTop-=e.panPoint.totalPannedInternalPoint.y,e.togglePen=a,this.lowerContext.filter=r,e.activeObj=i},e.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}},e.prototype.setClientTransDim=function(e){var o=this.parent;if(o.transform.degree%90==0&&o.transform.degree%180!=0){o.img.destLeft=(o.lowerCanvas.clientWidth-o.img.destHeight)/2,o.img.destTop=(o.lowerCanvas.clientHeight-o.img.destWidth+1)/2;var i=o.img.destWidth;o.img.destWidth=o.img.destHeight,o.img.destHeight=i}else t.isNullOrUndefined(e)&&(o.img.destLeft=(o.lowerCanvas.clientWidth-o.img.destWidth)/2,o.img.destTop=(o.lowerCanvas.clientHeight-o.img.destHeight+1)/2)},e.prototype.redrawImgWithObj=function(){var e=this.parent,o={canvasFilter:e.canvasFilter};if(this.lowerContext.filter=o.canvasFilter,0!==e.rotateFlipColl.length){var i=t.extend({},e.panPoint.totalPannedInternalPoint,{},!0),r={startX:e.img.destLeft,startY:e.img.destTop,width:e.img.destWidth,height:e.img.destHeight};this.callUpdateCurrTransState(),e.panPoint.totalPannedInternalPoint=i,e.img.destLeft=r.startX,e.img.destTop=r.startY,e.img.destWidth=r.width,e.img.destHeight=r.height}else this.callUpdateCurrTransState();e.isCircleCrop&&e.notify("crop",{prop:"cropCircle",onPropertyChange:!1,value:{context:this.lowerContext,isSave:null,isFlip:null}})},e.prototype.setCurrentObj=function(e,o){var i=this.parent,r=!!e;r||(i.cropObj.aspectWidth=i.aspectWidth,i.cropObj.aspectHeight=i.aspectHeight,i.cropObj.frame=i.frameObj.type),e=e||i.cropObj,i.transform.cropZoomFactor=e.cropZoom,i.transform.defaultZoomFactor=e.defaultZoom,this.straightenInitZoom=e.straightenZoom,r?e.activeObj.shape&&"crop"===e.activeObj.shape.split("-")[0]?i.transform.zoomFactor=e.cropZoom:i.transform.zoomFactor=e.defaultZoom:i.transform.zoomFactor=e.cropZoom,i.setProperties({zoomSettings:{zoomFactor:e.zoomFactor}},!0),i.notify("transform",{prop:"setPreviousZoomValue",onPropertyChange:!1,value:{previousZoomValue:e.previousZoomValue}}),i.panPoint.totalPannedPoint=t.extend({},e.totalPannedPoint,{},!0),i.panPoint.totalPannedClientPoint=t.extend({},e.totalPannedClientPoint,{},!0),i.panPoint.totalPannedInternalPoint=t.extend({},e.totalPannedInternalPoint,{},!0);var a=t.extend({},e.tempFlipPanPoint,{},!0);i.notify("crop",{prop:"setTempFlipPanPoint",onPropertyChange:!1,value:{point:a}}),i.rotateFlipColl=t.extend([],e.rotateFlipColl,[],!0),i.transform.degree=e.degree,i.frameObj.type=e.frame,i.transform.currFlipState=e.currFlipState,i.notify("filter",{prop:"setAdjustmentLevel",onPropertyChange:!1,value:{adjustmentLevel:e.adjustmentLevel}}),i.notify("filter",{prop:"setTempAdjVal"}),i.currentFilter=e.currentFilter,i.notify("filter",{prop:"setTempFilVal"}),(i.transform.straighten!==e.straighten||o)&&(i.transform.straighten=e.straighten,i.straightenBaseImageCanvas()),i.img={destLeft:e.destPoints.startX,destTop:e.destPoints.startY,destWidth:e.destPoints.width,destHeight:e.destPoints.height,srcLeft:e.srcPoints.startX,srcTop:e.srcPoints.startY,srcWidth:e.srcPoints.width,srcHeight:e.srcPoints.height},i.aspectWidth=e.aspectWidth,i.aspectHeight=e.aspectHeight,e.afterCropActions&&(i.afterCropActions=e.afterCropActions),this.lowerContext.filter=e.filter,i.notify("filter",{prop:"setBrightnessAdjusted",onPropertyChange:!1,value:{isBrightnessAdjusted:e.isBrightAdjust}});var n,s=i.isCircleCrop;t.isNullOrUndefined(i.currSelectionPoint)?n=null:(n=t.extend({},i.currSelectionPoint,{},!0),i.currSelectionPoint=null),i.isCircleCrop=!1,this.drawCropSelectionImage(e,!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=e.destPoints.startX,i.img.destTop=e.destPoints.startY,i.panPoint.totalPannedClientPoint=t.extend({},e.totalPannedClientPoint,{},!0),i.panPoint.totalPannedInternalPoint=t.extend({},e.totalPannedInternalPoint,{},!0)),i.activeObj=t.extend({},e.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 l=t.extend({},e.activeObj,{},!0),p=!1;if(i.afterCropActions.length>0){var h={collection:i.afterCropActions};i.notify("shape",{prop:"alignRotateFlipColl",onPropertyChange:!1,value:{collection:i.afterCropActions,isRotateFlipCollection:null,obj:h}}),i.afterCropActions=h.collection}var d=t.extend([],i.afterCropActions,[],!0);if(!r&&d.length>0){p=!0;for(var c=0,u=d.length;c<u;c++)"horizontalflip"!==d[c]&&"verticalflip"!==d[c]||(i.activeObj=t.extend({},n,{},!0),this.rotatedFlipCropSel=!0),i.notify("transform",{prop:"updateTransform",onPropertyChange:!1,value:{text:d[c]}});l=t.extend({},i.activeObj,{},!0),this.resetPanPoints(),i.activeObj=l,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),e.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=d,this.isCancelAction||p||(i.notify("freehand-draw",{prop:"updateFHDColl",onPropertyChange:!1}),i.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"zoom",pen:"zoom",isPreventApply:null}}),i.img.destLeft=e.destPoints.startX,i.img.destTop=e.destPoints.startY),i.activeObj=l,i.isCircleCrop=s,t.isNullOrUndefined(n)?i.currSelectionPoint=null:(i.currSelectionPoint=t.extend({},n,{},!0),i.currSelectionPoint&&t.isNullOrUndefined(i.currSelectionPoint.shape)&&(i.currSelectionPoint=null))},e.prototype.drawCropSelectionImage=function(e,o){var i=this.parent,r=this.lowerContext.filter;i.clearContext(this.lowerContext),i.clearContext(this.upperContext),this.lowerContext.setTransform(1,0,0,1,0,0),o?this.updateCurrTransState("initial"):this.setTransformColl(this.lowerContext,"initial"),i.notify("transform",{prop:"setDestPointsForFlipState",onPropertyChange:!1}),this.drawImage(),o?this.updateCurrTransState("reverse"):this.setTransformColl(this.lowerContext,"reverse"),i.img.destLeft=i.cropObj.destPoints.startX,i.img.destTop=i.cropObj.destPoints.startY;var a=t.extend({},e.activeObj,{},!0);if(this.lowerContext.filter="none",i.img={destLeft:e.destPoints.startX,destTop:e.destPoints.startY,destWidth:e.destPoints.width,destHeight:e.destPoints.height,srcLeft:e.srcPoints.startX,srcTop:e.srcPoints.startY,srcWidth:e.srcPoints.width,srcHeight:e.srcPoints.height},0!==e.activeObj.activePoint.width&&0!==e.activeObj.activePoint.height){var n={startX:i.img.destLeft,startY:i.img.destTop,width:i.img.destWidth,height:i.img.destHeight};i.img.destLeft=e.activeObj.activePoint.startX,i.img.destTop=e.activeObj.activePoint.startY,i.img.destWidth=e.activeObj.activePoint.width,i.img.destHeight=e.activeObj.activePoint.height,i.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"zoom",pen:"zoom",isPreventApply:null}}),i.img.destLeft=n.startX,i.img.destTop=n.startY,i.img.destWidth=n.width,i.img.destHeight=n.height}i.activeObj=a,this.lowerContext.filter=r},e.prototype.performPointZoom=function(e,t,o,i,r){var a=this.parent,n=a.img,s=n.destLeft,l=n.destTop,p=(e-s)/n.destWidth,h=(t-l)/n.destHeight,d=a.isUndoRedo;a.isUndoRedo=!0,a.setProperties({zoomSettings:{zoomPoint:{x:e,y:t}}},!0);var c=r||("zoomIn"===o?.1:-.1);a.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:c,zoomPoint:null,isResize:i}}),a.isUndoRedo=d,this.panToPoint(e,t,p,h)},e.prototype.panToPoint=function(e,o,i,r){var a=this.parent;if(a.transform.zoomFactor>0){var n=a.img.destLeft,s=a.img.destTop,l=t.extend({},a.activeObj,{},!0);if(0===a.transform.degree)a.img.destLeft=e-i*a.img.destWidth,a.img.destTop=o-r*a.img.destHeight,this.drawZoomPanImage(a.img.destLeft-n,a.img.destTop-s);else{var p=a.isCropTab;a.isCropTab=!0;var h=t.extend([],a.objColl,[],!0),d=t.extend([],a.pointColl,[],!0),c={straightenPoint:null};a.notify("freehand-draw",{prop:"getStraightenPoint",onPropertyChange:!1,value:{obj:c}}),a.objColl=[],a.pointColl=[],a.freehandCounter=0,a.notify("freehand-draw",{prop:"setStraightenPoint",onPropertyChange:!1,value:{x:null,y:null,ratioX:null,ratioY:null}});var u={selPointColl:null};a.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:u}});var v=u.selPointColl;a.notify("freehand-draw",{prop:"setSelPointColl",onPropertyChange:!1,value:{obj:{selPointColl:[]}}}),a.panPoint.currentPannedPoint={x:e-i*a.img.destWidth-n,y:o-r*a.img.destHeight-s},a.notify("transform",{prop:"rotatePan",onPropertyChange:!1,value:{isCropSelection:null,isDefaultZoom:null}}),a.isCropTab=p,a.objColl=h,a.pointColl=d,a.freehandCounter=a.pointColl.length,c.straightenPoint.x&&c.straightenPoint.y&&a.notify("freehand-draw",{prop:"setStraightenPoint",onPropertyChange:!1,value:{x:c.straightenPoint.x,y:c.straightenPoint.y,ratioX:c.straightenPoint.ratioX,ratioY:c.straightenPoint.ratioY}}),a.notify("freehand-draw",{prop:"setSelPointColl",onPropertyChange:!1,value:{obj:{selPointColl:v}}}),a.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"pan",pen:"pan",x:a.panPoint.currentPannedPoint.x,y:a.panPoint.currentPannedPoint.y,panRegion:""}})}this.adjustPanning(l);for(var g=!1,f=0;f<a.objColl.length;f++)if(JSON.stringify(l.activePoint)===JSON.stringify(a.objColl[f].activePoint)){g=!0;break}g||(a.activeObj=l),0!==a.activeObj.activePoint.width&&0!==a.activeObj.activePoint.height&&this.drawObject("duplicate",null,null,null,!0)}},e.prototype.adjustPanning=function(e){var o=this.parent,i=e.activePoint,r=i.startX,a=i.startY,n=i.width,s=i.height;if(0!==n&&0!==s){var l=o.img,p=l.destLeft,h=l.destTop,d=l.destWidth,c=l.destHeight,u={x:0,y:0};if(p>r?u.x=p-r:p+d<r+n&&(u.x=p+d-(r+n)),h>a?u.y=h-a:h+c<a+s&&(u.y=h+c-(a+s)),0===o.transform.degree)o.img.destLeft-=u.x,o.img.destTop-=u.y,this.drawZoomPanImage(o.img.destLeft-p,o.img.destTop-h);else{var v=o.isCropTab;o.isCropTab=!0;var g=t.extend([],o.objColl,[],!0),f=t.extend([],o.pointColl,[],!0);o.objColl=[],o.pointColl=[],o.freehandCounter=0;var C={selPointColl:null};o.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:C}});var b=C.selPointColl;o.notify("freehand-draw",{prop:"setSelPointColl",onPropertyChange:!1,value:{obj:{selPointColl:[]}}}),o.img.destLeft-=u.x,o.img.destTop-=u.y,o.panPoint.currentPannedPoint={x:o.img.destLeft-p,y:o.img.destTop-h},o.notify("transform",{prop:"rotatePan",onPropertyChange:!1,value:{isCropSelection:null,isDefaultZoom:null}}),o.isCropTab=v,o.objColl=g,o.pointColl=f,o.freehandCounter=o.pointColl.length,o.notify("freehand-draw",{prop:"setSelPointColl",onPropertyChange:!1,value:{obj:{selPointColl:b}}}),o.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"pan",pen:"pan",x:o.panPoint.currentPannedPoint.x,y:o.panPoint.currentPannedPoint.y,panRegion:""}})}}},e.prototype.panToSel=function(){var e=this.parent,o=t.extend({},e.activeObj,{},!0),i=o.activePoint,r=i.startX,a=i.startY,n=i.width,s=i.height,l={straightenPoint:null};if(e.notify("freehand-draw",{prop:"getStraightenPoint",onPropertyChange:!1,value:{obj:l}}),l.straightenPoint.x&&l.straightenPoint.y){var p=r+n/2-l.straightenPoint.x,h=a+s/2-l.straightenPoint.y;0===e.transform.degree?(e.img.destLeft+=p,e.img.destTop+=h,e.notify("transform",{prop:"drawPannImage",value:{point:{x:p,y:h}}})):(e.panPoint.currentPannedPoint={x:p,y:h},e.notify("transform",{prop:"drawPannedImage",value:{xDiff:p,yDiff:h}}),e.panPoint.currentPannedPoint={x:0,y:0},e.notify("transform",{prop:"setTempPanMove",value:{point:null}})),e.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate",obj:o}});var d=e.img,c=d.destLeft,u=d.destTop,v=d.destWidth,g=d.destHeight,f=this.imgCanvasPoints;f.forEach(function(e){e.x=e.ratioX*v+c,e.y=e.ratioY*g+u}),this.imgCanvasPoints=f;var C=0;if(3===e.transform.straighten&&!this.preventStraightening){this.preventStraightening=!0;var b=e.prevStraightenedDegree;e.prevStraightenedDegree=e.transform.straighten,e.setStraighten(0),e.setStraighten(3),e.prevStraightenedDegree=b,this.preventStraightening=!1}for(;this.isLinesIntersect()&&0!==e.transform.straighten&&360!==e.transform.straighten&&C<100;)C++,this.performPointZoom(e.activeObj.activePoint.startX+e.activeObj.activePoint.width/2,e.activeObj.activePoint.startY+e.activeObj.activePoint.height/2,"zoomIn",!1,.025),this.updateImgCanvasPoints()}},e.prototype.drawZoomPanImage=function(e,t){var o=this.parent;o.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"pan",pen:"pan",x:e,y:t,panRegion:""}}),this.renderImage(!0);var i={width:0,height:0};o.notify("transform",{prop:"calcMaxDimension",onPropertyChange:!1,value:{width:o.img.srcWidth,height:o.img.srcHeight,obj:i,isImgShape:null}});var r=i;r.width+=r.width*o.transform.zoomFactor,r.height+=r.height*o.transform.zoomFactor,o.panPoint.totalPannedPoint.x+=e,o.panPoint.totalPannedPoint.y+=t,o.notify("crop",{prop:"setTempFlipPanPoint",onPropertyChange:!1,value:{point:{x:0,y:0}}})},e.prototype.openNewImage=function(){var e=this,i=this.parent,r=i.element.id,a=i.inMemoryCanvas.getContext("2d");o.showSpinner(i.element),i.element.style.opacity="0.5";var n=document.querySelector("#"+r+"_currPos");n&&(n.style.display="none");var s={defToolbarItems:null};if(i.notify("toolbar",{prop:"getDefToolbarItems",value:{obj:s}}),0===s.defToolbarItems.length&&t.isNullOrUndefined(document.getElementById(r+"_toolbar"))&&i.element.querySelector("#"+r+"_toolbarArea")){var l=i.element.querySelector("#"+r+"_toolbarArea").clientHeight;i.notify("toolbar",{prop:"setToolbarHeight",value:{height:l}})}if(i.reset(),i.update(),i.transform.degree=0,i.transform.zoomFactor=0,i.isImageLoaded=!1,i.currSelectionPoint=null,"string"===typeof this.openURL){var p=this.openURL.split(".");if(p.length>1?(p=p[p.length-2].split("/"),this.fileName=p[p.length-1]):this.fileName="ImageEditor",this.fileType=this.getFileExtensionFromURL(this.openURL),this.fileType){this.fileType=i.toPascalCase(this.fileType);var h=this.fileType.toLowerCase();"jpg"!==h&&"jpeg"!==h||(this.fileType="Jpeg",h="jpeg"),"jpeg"!==h&&"png"!==h&&"svg"!==h&&(this.fileType=null)}this.imageOnLoad(this.openURL),"string"==typeof this.openURL&&-1!==this.openURL.indexOf("localhost")||this.getImageSizeFromURL(this.openURL.toString(),function(t){null!==t&&e.parent.notify("toolbar",{prop:"setInitialSize",value:{value:+t}})})}else this.fileName="ImageEditor",this.fileType=null,i.lowerCanvas=document.querySelector("#"+r+"_lowerCanvas"),i.upperCanvas=document.querySelector("#"+r+"_upperCanvas"),this.lowerContext=i.lowerCanvas.getContext("2d"),this.upperContext=i.upperCanvas.getContext("2d"),i.clearContext(this.lowerContext),i.clearContext(this.upperContext),i.clearContext(a),i.inMemoryCanvas.width=this.openURL.width,i.inMemoryCanvas.height=this.openURL.height,a.putImageData(this.openURL,0,0),i.baseImg.src=i.inMemoryCanvas.toDataURL()},e.prototype.getImageSizeFromURL=function(e,t){return l(this,void 0,void 0,function(){var o,i,r,a;return p(this,function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),[4,fetch(e,{method:"HEAD"})];case 1:return o=n.sent(),i=parseInt(o.headers.get("content-length")||"0",10),r=i,t(r),[3,3];case 2:return a=n.sent(),[3,3];case 3:return[2]}})})},e.prototype.dlgBtnClick=function(){this.parent.export(),this.applyDialogOption()},e.prototype.dlgCloseBtnClick=function(){this.applyDialogOption()},e.prototype.applyDialogOption=function(){var e=this.parent;this.isFileChanged?(e.isImageLoaded=this.isFileChanged=!1,e.reset(),this.checkToolbarTemplate(this.inputElem,this.openURL)):(this.reset(),this.openNewImage()),t.getComponent(document.getElementById(e.element.id+"_dialog"),"dialog").destroy(),this.isImageEdited=!1},e.prototype.showDialogPopup=function(){var e=this.parent,t={key:"ConfirmDialogHeader"};e.notify("toolbar",{prop:"getLocaleText",onPropertyChange:!1,value:{obj:t}});var i={key:"ConfirmDialogContent"};e.notify("toolbar",{prop:"getLocaleText",onPropertyChange:!1,value:{obj:i}});var r={key:"Yes"};e.notify("toolbar",{prop:"getLocaleText",onPropertyChange:!1,value:{obj:r}});var a={key:"No"};e.notify("toolbar",{prop:"getLocaleText",onPropertyChange:!1,value:{obj:a}}),e.element.querySelector("#"+e.element.id+"_dialog").style.display="block",new o.Dialog({header:t.value,closeOnEscape:!0,content:"<span>"+i.value+"</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:a.value,iconCss:"e-icons e-close"}},{click:this.dlgBtnClick.bind(this),buttonModel:{content:r.value,isPrimary:!0,iconCss:"e-icons e-check"}}]}).appendTo("#"+e.element.id+"_dialog")},e.prototype.restoreOldImage=function(){this.parent.isImageLoaded?(this.reset(),this.openNewImage()):this.openNewImage()},e.prototype.open=function(e){var t=document.getElementById(this.parent.element.id+"_dropArea");t&&(t.style.display="none"),this.parent.disabled||(this.openURL=e,this.restoreOldImage())},e.prototype.getInitialLoaded=function(e){e.isInitialLoaded=this.isInitialLoading},e.prototype.getFileExtensionFromURL=function(e){var t=e.lastIndexOf(".");return-1!==t?e.slice(t+1).toLowerCase():-1!==e.indexOf("base64")?e.slice(e.indexOf("/")+1,e.indexOf(";")).toLowerCase():null},e.prototype.fileSelect=function(e,t){var i=this.parent,r=document.getElementById(i.element.id+"_dropArea");if(r&&(r.style.display="none"),!i.disabled){var a=void 0,n=void 0;t.target?n=a=t.target.files[0]:a=n=t.filesData[0].rawFile;var s=void 0;if(n.name){var l=n.name.split(".");s=l[l.length-1].toLowerCase()}if(s&&-1===["jpg","jpeg","png","svg"].indexOf(s))return void this.errorLoading();if(o.showSpinner(i.element),i.element.style.opacity="0.5",this.inputElem=e,s=n.name&&n.name.split(".")[1]){var p=i.toPascalCase(s);this.fileType="JPG"===p||"Jpg"===p?"Jpeg":p}else this.fileType=null;var h=window.URL.createObjectURL(a);this.openURL=h,i.isImageLoaded&&!i.isChangesSaved&&(this.isImageEdited||i.pointColl.length>0||i.objColl.length>0)?(this.isFileChanged=!0,this.showDialogPopup()):this.checkToolbarTemplate(e,h)}},e.prototype.checkToolbarTemplate=function(e,o){var i=this.parent;t.isNullOrUndefined(i.toolbarTemplate)&&(i.reset(),i.update()),this.fileName=e.value.split("\\")[e.value.split("\\").length-1],this.fileName=this.fileName.split(".")[0],this.imageOnLoad(o.toString()),e.value=""},e.prototype.moveToSelectionRange=function(e,o){var i=this.parent;if(i.activeObj.shape){for(var r=!1,a=0,n=i.rotateFlipColl.length;a<n;a++){var s=i.rotateFlipColl[a];if(90===s||-90===s){r=!0;break}}if(r){if(0===i.transform.degree)return;var l=i.transform.zoomFactor;i.objColl.push(i.activeObj),i.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1});var p=i.objColl[i.objColl.length-1];if("rotateleft"===e||"rotateright"===e)if(i.transform.degree%90==0&&i.transform.degree%180!=0)if(p.activePoint.width<o.activePoint.height)for(a=2;a<i.zoomSettings.maxZoomFactor;a++){if(p.activePoint.width>=o.activePoint.height||this.isSelectionBiggerThanCanvas(p)||this.isSelectionOutsideCanvas(p)){t.isNullOrUndefined(l)||i.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:-.1,zoomPoint:null},isResize:null});break}l+=.1,i.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:l,zoomPoint:null},isResize:null})}else for(a=2;a<i.zoomSettings.maxZoomFactor;a++){if(p.activePoint.width>=o.activePoint.height||this.isSelectionBiggerThanCanvas(p)||this.isSelectionOutsideCanvas(p)){t.isNullOrUndefined(l)||i.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:.1,zoomPoint:null,isResize:null}});break}l-=.1,i.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:l,zoomPoint:null},isResize:null})}else if(p.activePoint.height<o.activePoint.width)for(a=2;a<i.zoomSettings.maxZoomFactor;a++){if(p.activePoint.height>=o.activePoint.width||this.isSelectionBiggerThanCanvas(p)||this.isSelectionOutsideCanvas(p)){t.isNullOrUndefined(l)||i.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:-.1,zoomPoint:null},isResize:null});break}l+=.1,i.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:l,zoomPoint:null},isResize:null})}else for(a=2;a<i.zoomSettings.maxZoomFactor;a++){if(p.activePoint.height>=o.activePoint.width||this.isSelectionBiggerThanCanvas(p)||this.isSelectionOutsideCanvas(p)){t.isNullOrUndefined(l)||i.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:.1,zoomPoint:null},isResize:null});break}l-=.1,i.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:l,zoomPoint:null},isResize:null})}var h=i.lowerCanvas.clientWidth/2-(p.activePoint.startX+p.activePoint.width/2),d=(i.lowerCanvas.clientHeight+1)/2-(p.activePoint.startY+p.activePoint.height/2);t.isNullOrUndefined(i.activeObj.shape)&&(i.activeObj=t.extend({},o,{},!0)),0===i.transform.degree?(i.img.destLeft+=h,i.img.destTop+=d,i.notify("transform",{prop:"drawPannImage",value:{point:{x:h,y:d}}})):(i.panPoint.currentPannedPoint={x:h,y:d},i.notify("transform",{prop:"drawPannedImage",value:{xDiff:h,yDiff:d}}),i.panPoint.currentPannedPoint={x:0,y:0}),i.notify("transform",{prop:"setTempPanMove",onPropertyChange:!1,value:{point:null}}),i.activeObj=t.extend({},i.objColl[i.objColl.length-1]),i.objColl.pop(),i.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate",obj:i.activeObj}})}}},e.prototype.isSelectionBiggerThanCanvas=function(e){var t=!1,o=this.parent,i=e.activePoint,r=i.startX,a=i.startY,n=i.endX,s=i.endY,l=o.img,p=l.destLeft,h=l.destTop,d=l.destWidth,c=l.destHeight;return(r<=p||a<=h||n>=p+d||s>=h+c)&&(t=!0),t},e.prototype.isSelectionOutsideCanvas=function(e){var t=!1,o=this.parent;return(e.activePoint.height<o.lowerCanvas.height-o.toolbarHeight||e.activePoint.width<o.lowerCanvas.width)&&(t=!0),t},e.prototype.downScaleImgCanvas=function(e,o,i,r){var a=this.parent,n=o?a.activeObj.imageCanvas:a.baseImgCanvas,s=o?a.activeObj.imageElement:a.baseImg,l=o?a.activeObj.activePoint.width:a.img.destWidth,p=o?a.activeObj.activePoint.height:a.img.destHeight,h={width:0,height:0};if(a.transform.degree%90==0&&a.transform.degree%180!=0?a.notify("transform",{prop:"calcMaxDimension",onPropertyChange:!1,value:{width:s.height,height:s.width,obj:h,isImgShape:o}}):a.notify("transform",{prop:"calcMaxDimension",onPropertyChange:!1,value:{width:s.width,height:s.height,obj:h,isImgShape:o}}),o||a.allowDownScale&&!a.isCropTab&&!a.isCropToolbar&&0!==s.width&&0!==s.height&&.75*h.width>l&&.75*h.height>p){var d=a.createElement("canvas",{id:a.element.id+"_downScaleCanvas",attrs:{name:"canvasImage"}});d.width=o?s.width:a.img.srcWidth,d.height=o?s.height:a.img.srcHeight,o?d.getContext("2d").drawImage(s,0,0,d.width,d.height):d.getContext("2d").drawImage(n,a.img.srcLeft,a.img.srcTop,a.img.srcWidth,a.img.srcHeight,0,0,d.width,d.height),(o||this.isDownScale)&&this.downScale(d,l,p,o),o?(e.canvas.width=d.width,e.canvas.height=d.height,i&&r?(e.translate(a.activeObj.imageCanvas.width,0),e.scale(-1,1),e.translate(0,a.activeObj.imageCanvas.height),e.scale(1,-1)):i?(t.isNullOrUndefined(a.activeObj.isHorImageFlip)||!a.activeObj.isHorImageFlip?(a.activeObj.isHorImageFlip=!0,e.translate(a.activeObj.imageCanvas.width,0),e.scale(-1,1)):a.activeObj.isHorImageFlip&&(a.activeObj.isHorImageFlip=!1),a.activeObj.isVerImageFlip&&(e.translate(0,a.activeObj.imageCanvas.height),e.scale(1,-1))):r&&(t.isNullOrUndefined(a.activeObj.isVerImageFlip)||!a.activeObj.isVerImageFlip?(a.activeObj.isVerImageFlip=!0,e.translate(0,a.activeObj.imageCanvas.height),e.scale(1,-1)):a.activeObj.isVerImageFlip&&(a.activeObj.isVerImageFlip=!1),a.activeObj.isHorImageFlip&&(e.translate(a.activeObj.imageCanvas.width,0),e.scale(-1,1))),e.drawImage(d,0,0),e.setTransform(1,0,0,1,0,0)):a.isFinetuning?(e.save(),e.setTransform(1,0,0,1,0,0),e.drawImage(a.inMemoryCanvas,0,0),e.restore()):e.drawImage(d,0,0,d.width,d.height,a.img.destLeft,a.img.destTop,d.width,d.height)}else!t.isNullOrUndefined(o)&&o||0===a.baseImgCanvas.width||0===a.baseImgCanvas.height||e.drawImage(a.baseImgCanvas,a.img.srcLeft,a.img.srcTop,a.img.srcWidth,a.img.srcHeight,a.img.destLeft,a.img.destTop,a.img.destWidth,a.img.destHeight)},e.prototype.downScale=function(e,t,o,i){var r=this.parent;if(!i||!r.isStraightening){for(var a=e.width,n=e.height,s=a/(t=Math.round(t)),l=n/(o=Math.round(o)),p=Math.ceil(s/2),h=Math.ceil(l/2),d=e.getContext("2d"),c=d.getImageData(0,0,a,n),u=d.createImageData(t,o),v=c.data,g=u.data,f=0;f<o;f++)for(var C=0;C<t;C++){for(var b=4*(C+f*t),m=0,y=0,P=0,j=0,x=0,w=0,O=0,S=(f+.5)*l,T=Math.floor(f*l),F=Math.ceil((f+1)*l),k=T;k<F;k++)for(var I=Math.abs(S-(k+.5))/h,A=(C+.5)*s,z=I*I,D=Math.floor(C*s),X=Math.ceil((C+1)*s),Y=D;Y<X;Y++){var R=Math.abs(A-(Y+.5))/p,L=Math.sqrt(z+R*R);if(!(L>=1)){var E=4*(Y+k*a);O+=(m=2*L*L*L-3*L*L+1)*v[E+3],P+=m,j+=(m=m*v[E+3]/250)*v[E],x+=m*v[E+1],w+=m*v[E+2],y+=m}}g[b]=j/y,g[b+1]=x/y,g[b+2]=w/y,g[b+3]=O/P}e.width=i?r.activeObj.activePoint.width:r.lowerCanvas.width,e.height=i?r.activeObj.activePoint.height:r.lowerCanvas.height,d.putImageData(u,0,0)}},e.prototype.drawImgToCtx=function(e,o){var i=this.parent;e.canvas.id!==i.element.id+"_tempCanvas"&&e!==this.upperContext&&t.isNullOrUndefined(o)&&this.downScaleImgCanvas(e,null,null,null)},e.prototype.getFrameColor=function(e,t,o){var i=this.parent.frameObj.color;if(e.gradientColor){var r=t.createLinearGradient(o.startX,o.startY,o.startX+o.width,o.startY+o.height);r.addColorStop(0,e.color),r.addColorStop(1,e.gradientColor),i=r}else i=e.color;return i},e.prototype.applyFrame=function(e,o,i){var r=this.parent;r.frameObj.type=o;var a,n={width:1,height:1},s={startX:r.img.destLeft-e.lineWidth,startY:r.img.destTop-e.lineWidth,width:r.img.destWidth+2*e.lineWidth,height:r.img.destHeight+2*e.lineWidth},l={type:r.frameObj.type,color:r.frameObj.color,size:r.frameObj.size,inset:r.frameObj.inset,offset:r.frameObj.offset/2,radius:r.frameObj.radius,amount:r.frameObj.amount,border:r.frameObj.border,gradientColor:r.frameObj.gradientColor},p=r.transform.zoomFactor;if(e.canvas.id===r.element.id+"_tempCanvas"){var h=e.canvas.width,d=e.canvas.height,c={width:0,height:0};r.notify("crop",{prop:"calcRatio",onPropertyChange:!1,value:{obj:c,dimension:{width:h,height:d}}}),n=c,l.size*=(n.width+n.height)/2,l.inset*=(n.width+n.height)/2,l.offset*=(n.width+n.height)/2,l.radius*=(n.width+n.height)/2,s={startX:0,startY:0,width:e.canvas.width,height:e.canvas.height},r.notify("export",{prop:"updateSaveContext",onPropertyChange:!1,value:{context:e}})}else e===this.upperContext&&r.activeObj.shape?s={startX:r.activeObj.activePoint.startX-e.lineWidth,startY:r.activeObj.activePoint.startY-e.lineWidth,width:r.activeObj.activePoint.width+2*e.lineWidth,height:r.activeObj.activePoint.height+2*e.lineWidth}:t.isNullOrUndefined(i)&&e.clearRect(0,0,e.canvas.width,e.canvas.height);var u=(n.width+n.height)/2*40,v=(n.width+n.height)/2*50;if(e!==this.upperContext&&(l.size+=l.size*p,l.inset+=l.inset*p,l.offset+=l.offset*p,l.radius+=l.radius*p,u+=u*p,v+=v*p),e!==this.upperContext||!r.activeObj.shape||!("mat"===o&&(s.width-2*l.size<0||s.height-2*l.size<0)||"bevel"===o&&(s.width-2*l.size<40||s.height-2*l.size<40)||"inset"===o&&(s.startX+s.width-l.offset-(s.startX+l.offset)<0||s.startY+s.height-l.offset-(s.startY+l.offset)<0)||"hook"===o&&(s.width-2*l.size<50||s.height-2*l.size<50))){var g={bevelFilter:e.filter},f=e.filter;if(r.currSelectionPoint&&"crop-circle"===r.currSelectionPoint.shape||r.isCircleCrop||e===this.lowerContext&&r.isCropTab)this.drawImgToCtx(e,i);else{switch(o){case"none":this.drawImgToCtx(e,i);break;case"mat":for(this.drawImgToCtx(e,i);(s.width-2*l.size<0||s.height-2*l.size<0)&&l.size>0;)l.size-=20;e.filter="none",e.fillStyle=this.getFrameColor(l,e,s),e.beginPath(),e.rect(s.startX,s.startY,s.width,s.height),e.rect(s.startX+l.size,s.startY+l.size,s.width-2*l.size,s.height-2*l.size),e.fill("evenodd"),e.closePath();break;case"bevel":for(e.filter="none",e.fillStyle=this.getFrameColor(l,e,s),e.beginPath(),e.fillRect(s.startX,s.startY,s.width,s.height),e.closePath(),s.startX+=l.size,s.startY+=l.size,s.width-=2*l.size,s.height-=2*l.size;(s.width-2*l.size<40||s.height-2*l.size<40)&&l.size>0;)s.startX-=l.size,s.startY-=l.size,s.width+=2*l.size,s.height+=2*l.size,l.size-=20,s.startX+=l.size,s.startY+=l.size,s.width-=2*l.size,s.height-=2*l.size;e.fillStyle=this.getFrameColor(l,e,s),e.save(),e.beginPath(),e.moveTo(s.startX+u,s.startY),e.lineTo(s.startX+s.width-u,s.startY),e.quadraticCurveTo(s.startX+s.width,s.startY,s.startX+s.width,s.startY+u),e.lineTo(s.startX+s.width,s.startY+s.height-u),e.quadraticCurveTo(s.startX+s.width,s.startY+s.height,s.startX+s.width-u,s.startY+s.height),e.lineTo(s.startX+u,s.startY+s.height),e.quadraticCurveTo(s.startX,s.startY+s.height,s.startX,s.startY+s.height-u),e.lineTo(s.startX,s.startY+u),e.quadraticCurveTo(s.startX,s.startY,s.startX+u,s.startY),e.closePath(),e.clip(),e.filter="none"===f?r.canvasFilter:f,e.canvas.id===r.element.id+"_tempCanvas"?(i=null,e.filter="none",e.drawImage(r.inMemoryCanvas,0,0),e.filter="none"===f?r.canvasFilter:f):(e.clearRect(0,0,e.canvas.width,e.canvas.height),i?(i=null,0!==r.transform.zoomFactor&&(this.isRotateZoom=!0),r.notify("filter",{prop:"getBevelFilter",onPropertyChange:!1,value:{obj:g}}),e.filter=g.bevelFilter,this.updateCurrTransState("initial"),this.drawImgToCtx(e,i),this.updateCurrTransState("reverse"),this.isRotateZoom=!1,r.frameObj.type="none",e.filter="none",r.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:e,shape:"iterate",pen:"iterate",isPreventApply:null}}),r.frameObj.type="bevel",e.filter="none"===f?r.canvasFilter:f):(r.notify("filter",{prop:"getBevelFilter",onPropertyChange:!1,value:{obj:g}}),e.filter=g.bevelFilter,this.drawImgToCtx(e,i))),e.restore();break;case"line":this.drawImgToCtx(e,i),a=e.lineWidth,e.lineWidth=l.size/10;for(var C=0;C<r.frameObj.amount;C++){C>0&&(s.startX+=l.offset,s.startY+=l.offset,s.width-=2*l.offset,s.height-=2*l.offset);var b=s.startY+s.height-l.inset-l.radius,m=s.startY+l.inset+l.radius,y=s.startX+s.width-l.inset-l.radius,P=s.startX+l.inset+l.radius,j=s.startX+l.inset+l.radius,x=s.startX+s.width-l.inset-l.radius,w=s.startY+l.inset+l.radius,O=s.startY+s.height-l.inset-l.radius;b>=m&&y>=P&&j<=x&&w<=O&&(e.filter="none",e.strokeStyle=this.getFrameColor(l,e,s),"dashed"===l.border?e.setLineDash([2.5*e.lineWidth,1.5*e.lineWidth]):"dotted"===l.border&&e.setLineDash([e.lineWidth,e.lineWidth]),e.beginPath(),e.moveTo(s.startX+l.inset+l.radius,s.startY+l.inset),e.lineTo(s.startX+s.width-l.inset-l.radius,s.startY+l.inset),e.arcTo(s.startX+s.width-l.inset,s.startY+l.inset,s.startX+s.width-l.inset,s.startY+l.inset+l.radius,l.radius),e.lineTo(s.startX+s.width-l.inset,s.startY+s.height-l.inset-l.radius),e.arcTo(s.startX+s.width-l.inset,s.startY+s.height-l.inset,s.startX+s.width-l.inset-l.radius,s.startY+s.height-l.inset,l.radius),e.lineTo(s.startX+l.inset+l.radius,s.startY+s.height-l.inset),e.arcTo(s.startX+l.inset,s.startY+s.height-l.inset,s.startX+l.inset,s.startY+s.height-l.inset-l.radius,l.radius),e.lineTo(s.startX+l.inset,s.startY+l.inset+l.radius),e.arcTo(s.startX+l.inset,s.startY+l.inset,s.startX+l.inset+l.radius,s.startY+l.inset,l.radius),e.closePath(),e.stroke(),e.setLineDash([]))}e.lineWidth=a;break;case"inset":this.drawImgToCtx(e,i),e.filter="none",e.strokeStyle=this.getFrameColor(l,e,s),a=e.lineWidth,e.lineWidth=l.size/10,e.beginPath(),e.moveTo(s.startX+l.offset,s.startY+l.inset),e.lineTo(s.startX+s.width-l.offset,s.startY+l.inset),e.moveTo(s.startX+s.width-l.inset,s.startY+l.offset),e.lineTo(s.startX+s.width-l.inset,s.startY+s.height-l.offset),e.moveTo(s.startX+s.width-l.offset,s.startY+s.height-l.inset),e.lineTo(s.startX+l.offset,s.startY+s.height-l.inset),e.moveTo(s.startX+l.inset,s.startY+s.height-l.offset),e.lineTo(s.startX+l.inset,s.startY+l.offset),e.stroke(),e.closePath(),e.lineWidth=a;break;case"hook":this.drawImgToCtx(e,i),e.filter="none",e.strokeStyle=this.getFrameColor(l,e,s),a=e.lineWidth,e.lineWidth=l.size/10,e.beginPath(),e.moveTo(s.startX+l.inset+v,s.startY+l.inset),e.lineTo(s.startX+l.inset,s.startY+l.inset),e.lineTo(s.startX+l.inset,s.startY+l.inset+v),e.moveTo(s.startX+s.width-l.inset-v,s.startY+l.inset),e.lineTo(s.startX+s.width-l.inset,s.startY+l.inset),e.lineTo(s.startX+s.width-l.inset,s.startY+l.inset+v),e.moveTo(s.startX+s.width-l.inset-v,s.startY+s.height-l.inset),e.lineTo(s.startX+s.width-l.inset,s.startY+s.height-l.inset),e.lineTo(s.startX+s.width-l.inset,s.startY+s.height-l.inset-v),e.moveTo(s.startX+l.inset+v,s.startY+s.height-l.inset),e.lineTo(s.startX+l.inset,s.startY+s.height-l.inset),e.lineTo(s.startX+l.inset,s.startY+s.height-l.inset-v),e.stroke(),e.lineWidth=a}(r.isCircleCrop||r.currSelectionPoint&&"crop-circle"===r.currSelectionPoint.shape)&&r.notify("crop",{prop:"cropCircle",onPropertyChange:!1,value:{context:e,isSave:e.canvas.id===r.element.id+"_tempCanvas"||null,isFlip:null}}),e.filter=f}}},e.prototype.triggerFrameChange=function(e){var t=this.parent,o={cancel:!1,previousFrameSetting:e,currentFrameSetting:{type:t.toPascalCase(t.frameObj.type),color:t.frameObj.color,gradientColor:t.frameObj.gradientColor,size:t.frameObj.size,inset:t.frameObj.inset,offset:t.frameObj.offset,borderRadius:t.frameObj.radius,frameLineStyle:t.toPascalCase(t.frameObj.border),lineCount:t.frameObj.amount}};return t.trigger("frameChange",o),o.cancel||this.setFrameObj(o.currentFrameSetting),o},e.prototype.setFrameObj=function(e){var t=this.parent;t.frameObj.type=e.type.toLowerCase(),t.frameObj.color=e.color,t.frameObj.gradientColor=e.gradientColor,t.frameObj.size=e.size,t.frameObj.inset=e.inset,t.frameObj.offset=e.offset,t.frameObj.radius=e.borderRadius,t.frameObj.border=e.frameLineStyle.toLowerCase(),t.frameObj.amount=e.lineCount},e.prototype.zoomToSel=function(e,o){var i=this.parent;if(this.straightenActObj&&JSON.stringify(this.straightenActObj.activePoint)===JSON.stringify(e.activePoint))if(i.activeObj=t.extend({},this.straightenActObj,null,!0),0===i.transform.straighten){var r=i.img.destWidth,a=i.img.destHeight;for(i.transform.straighten=360;;){if(t.isNullOrUndefined(this.straightenInitZoom)||!(Math.round(i.transform.zoomFactor*Math.pow(10,3))/Math.pow(10,3)>Math.round(this.straightenInitZoom*Math.pow(10,3))/Math.pow(10,3))){this.performDummyZoom();break}if(this.setZoomPan("out"),r===i.img.destWidth&&a===i.img.destHeight){this.performDummyZoom();break}0===i.transform.degree&&(i.transform.zoomFactor-=.025,i.transform.cropZoomFactor-=.025)}i.transform.straighten=0,i.img={destLeft:i.img.destLeft,destTop:i.img.destTop,destWidth:i.img.destWidth,destHeight:i.img.destHeight,srcLeft:i.img.srcLeft,srcTop:i.img.srcTop,srcWidth:i.img.srcWidth,srcHeight:i.img.srcHeight}}else t.isNullOrUndefined(this.straightenInitZoom)&&(this.straightenInitZoom=i.transform.zoomFactor),this.straightenInitZoom-i.transform.zoomFactor>0?i.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:-(this.straightenInitZoom-i.transform.zoomFactor),zoomPoint:null,isResize:!0}}):this.straightenInitZoom-i.transform.zoomFactor<0&&i.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:this.straightenInitZoom-i.transform.zoomFactor,zoomPoint:null,isResize:!0}}),i.activeObj=t.extend({},e,null,!0),i.transform.zoomFactor+=.001,this.calcStraightenedPoints(o);else this.straightenActObj=t.extend({},e,null,!0),i.activeObj=t.extend({},this.straightenActObj,null,!0),this.straightenInitZoom=i.transform.zoomFactor,this.calcStraightenedPoints(o)},e.prototype.isDestPointSmall=function(){var e=this.parent,t=e.img,o={startX:t.destLeft,startY:t.destTop,width:t.destWidth,height:t.destHeight};e.notify("shape",{prop:"straightenShapes",onPropertyChange:!1});var i=!1;return this.straightenDestPoints.destWidth&&this.straightenDestPoints.destHeight&&(t.destWidth<this.straightenDestPoints.destWidth||t.destHeight<this.straightenDestPoints.destHeight)&&(i=!0),t.destLeft=o.startX,t.destTop=o.startY,t.destWidth=o.width,t.destHeight=o.height,e.img=t,i},e.prototype.calcStraightenedPoints=function(e){var o=this.parent,i=o.img.destWidth,r=o.img.destHeight;t.isNullOrUndefined(o.transform.zoomFactor)&&(o.transform.zoomFactor+=.025),this.updateImgCanvasPoints();for(var a=this;;)if("break"===function(){if(!(a.isLinesIntersect()||a.isSelOutsideImg()||e&&a.isDestPointSmall()))return a.performDummyZoom(),"break";if(o.activeObj=t.extend({},a.straightenActObj,null,!0),a.setZoomPan("in"),i===o.img.destWidth&&r===o.img.destHeight)return a.performDummyZoom(),"break";0===o.transform.degree&&(o.transform.zoomFactor+=.025,o.transform.cropZoomFactor+=.025);var n=a.imgCanvasPoints,s=o.img.destLeft,l=o.img.destTop,p=o.img.destWidth,h=o.img.destHeight;n.forEach(function(e){e.x=e.ratioX*p+s,e.y=e.ratioY*h+l}),a.imgCanvasPoints=n}())break},e.prototype.performDummyZoom=function(){var e=this.parent;e.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:.025,zoomPoint:null,isResize:!0}}),e.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:-.025,zoomPoint:null,isResize:!0}});var t=10*e.transform.zoomFactor;t<1&&(t=1+t/10),e.setProperties({zoomSettings:{zoomFactor:t}},!0),e.notify("transform",{prop:"setPreviousZoomValue",onPropertyChange:!1,value:{previousZoomValue:t}}),this.panToSel()},e.prototype.setZoomPan=function(e){var t=this.parent,o={maxDimension:null};0===t.transform.degree?(t.notify("transform",{prop:"cropZoom",onPropertyChange:!1,value:{value:"in"===e?.025:-.025,selectionObj:t.activeObj,obj:o}}),t.img.destWidth=o.maxDimension.width,t.img.destHeight=o.maxDimension.height):(t.transform.zoomFactor+="in"===e?.025:-.025,t.transform.cropZoomFactor+="in"===e?.025:-.025,this.updateCurrTransState("initial"),this.isRotateZoom=!0,this.setDestPoints(),this.isRotateZoom=!1,this.updateCurrTransState("reverse"))},e.prototype.updateImgCanvasPoints=function(){var e=this.parent,t=this.getImagePoints(),o={width:0,height:0},i=e.baseImgCanvas.width,r=e.baseImgCanvas.height;e.notify("crop",{prop:"calcRatio",onPropertyChange:!1,value:{obj:o,dimension:{width:i,height:r}}});var a=o;i=e.transform.degree%90==0&&e.transform.degree%180!=0?a.height:a.width,r=e.transform.degree%90==0&&e.transform.degree%180!=0?a.width:a.height;var n,s,l,p,h=e.img,d=h.destLeft,c=h.destTop,u=h.destWidth,v=h.destHeight;e.transform.straighten>0?(n={x:d+t[0].x/i,y:c},s={x:d+u,y:c+t[1].y/r},l={x:d+u-t[0].x/i,y:c+v},p={x:d,y:c+v-t[1].y/r}):(n={x:d,y:c+t[0].y/r},s={x:d+t[1].x/i,y:c},l={x:d+u,y:c+v-t[0].y/r},p={x:d+u-t[1].x/i,y:c+v}),n.ratioX=(n.x-d)/u,n.ratioY=(n.y-c)/v,s.ratioX=(s.x-d)/u,s.ratioY=(s.y-c)/v,l.ratioX=(l.x-d)/u,l.ratioY=(l.y-c)/v,p.ratioX=(p.x-d)/u,p.ratioY=(p.y-c)/v,this.imgCanvasPoints=[n,s,l,p]},e.prototype.isLinesIntersect=function(e){var t=this.parent.activeObj.activePoint,o=this.imgCanvasPoints,i=this.doIntersect({x:t.startX,y:t.startY},{x:t.endX,y:t.startY},o[0],o[1]),r=this.doIntersect({x:t.endX,y:t.startY},{x:t.endX,y:t.endY},o[1],o[2]),a=this.doIntersect({x:t.startX,y:t.endY},{x:t.endX,y:t.endY},o[2],o[3]),n=this.doIntersect({x:t.startX,y:t.startY},{x:t.startX,y:t.endY},o[3],o[0]),s=this.isInsideRect(o[0]),l=this.isInsideRect(o[1]),p=this.isInsideRect(o[2]),h=this.isInsideRect(o[3]);return e&&(e.arr=[i,r,a,n]),i||r||a||n||s||l||p||h||o[0].x>t.startX&&o[1].x<t.endX&&o[2].x<t.endX&&o[3].x>t.startX&&o[0].y<t.startY&&o[1].y<t.startY&&o[2].y>t.endY&&o[3].y>t.endY||o[0].x<t.startX&&o[1].x>t.endX&&o[2].x>t.endX&&o[3].x<t.startX&&o[0].y>t.startY&&o[1].y>t.startY&&o[2].y<t.endY&&o[3].y<t.endY},e.prototype.isSelOutsideImg=function(){var e=this.parent,t=this.imgCanvasPoints,o=e.activeObj.activePoint;return"inside"!==this.checkPointPosition(o.startX,o.startY,t[0].x,t[0].y,t[1].x,t[1].y,t[2].x,t[2].y,t[3].x,t[3].y)||"inside"!==this.checkPointPosition(o.endX,o.startY,t[0].x,t[0].y,t[1].x,t[1].y,t[2].x,t[2].y,t[3].x,t[3].y)||"inside"!==this.checkPointPosition(o.startX,o.endY,t[0].x,t[0].y,t[1].x,t[1].y,t[2].x,t[2].y,t[3].x,t[3].y)||"inside"!==this.checkPointPosition(o.endX,o.endY,t[0].x,t[0].y,t[1].x,t[1].y,t[2].x,t[2].y,t[3].x,t[3].y)},e.prototype.calcTriangleArea=function(e,t,o,i,r,a){return Math.abs((e*(i-a)+o*(a-t)+r*(t-i))/2)},e.prototype.checkPointPosition=function(e,t,o,i,r,a,n,s,l,p){var h=this.calcTriangleArea(e,t,o,i,l,p),d=this.calcTriangleArea(e,t,l,p,n,s),c=this.calcTriangleArea(e,t,n,s,r,a),u=this.calcTriangleArea(e,t,r,a,o,i),v=this.calcTriangleArea(o,i,r,a,n,s)+this.calcTriangleArea(n,s,l,p,o,i);return h+d+c+u>v?"outside":h+d+c+u!==v||0!==h&&0!==d&&0!==c&&0!==u?"inside":"on"},e.prototype.getImagePoints=function(){var e=[],t=this.parent,o=t.transform.degree,i=t.baseImg.width,r=t.baseImg.height,a={dim:null,width:r,height:i,angle:t.transform.straighten};a.dim=t.getRotatedCanvasDim(a.width,a.height,a.angle);var n=o%90==0&&o%180!=0?a.dim.width:t.baseImgCanvas.width,s=o%90==0&&o%180!=0?a.dim.height:t.baseImgCanvas.height,l=o%90==0&&o%180!=0?r:i,p=o%90==0&&o%180!=0?i:r,h=n/2,d=s/2,c=h-l/2,u=d-p/2,v=h+l/2,g=d+p/2,f={x:h,y:d},C=t.transform.straighten*(Math.PI/180),b={x:Math.cos(C)*(c-f.x)-Math.sin(C)*(u-f.y)+f.x,y:Math.sin(C)*(c-f.x)+Math.cos(C)*(u-f.y)+f.y},m={x:Math.cos(C)*(v-f.x)-Math.sin(C)*(u-f.y)+f.x,y:Math.sin(C)*(v-f.x)+Math.cos(C)*(u-f.y)+f.y},y={x:Math.cos(C)*(v-f.x)-Math.sin(C)*(g-f.y)+f.x,y:Math.sin(C)*(v-f.x)+Math.cos(C)*(g-f.y)+f.y},P={x:Math.cos(C)*(c-f.x)-Math.sin(C)*(g-f.y)+f.x,y:Math.sin(C)*(c-f.x)+Math.cos(C)*(g-f.y)+f.y};return e.push(b),e.push(m),e.push(y),e.push(P),e},e.prototype.doIntersect=function(e,t,o,i){var r=this.initiation(e,t,o),a=this.initiation(e,t,i),n=this.initiation(o,i,e),s=this.initiation(o,i,t);return r!==a&&n!==s||(!(0!==r||!this.onSegment(e,o,t))||(!(0!==a||!this.onSegment(e,i,t))||(!(0!==n||!this.onSegment(o,e,i))||!(0!==s||!this.onSegment(o,t,i)))))},e.prototype.initiation=function(e,t,o){var i=(t.y-e.y)*(o.x-t.x)-(t.x-e.x)*(o.y-t.y);return 0===i?0:i>0?1:2},e.prototype.onSegment=function(e,t,o){return t.x<=Math.max(e.x,o.x)&&t.x>=Math.min(e.x,o.x)&&t.y<=Math.max(e.y,o.y)&&t.y>=Math.min(e.y,o.y)},e.prototype.isInsideRect=function(e){var t=this.parent.activeObj.activePoint,o=!1;return e.x>=t.startX&&e.x<=t.endX&&e.y>=t.startY&&e.y<=t.endY&&(o=!0),o},e.prototype.setDestForStraighten=function(){var e=this.parent;if(t.isNullOrUndefined(this.straightenDestPoints)){var o=e.img,i=o.destLeft,r=o.destTop,a=o.destWidth,n=o.destHeight;e.notify("shape",{prop:"straightenShapes",onPropertyChange:!1}),this.straightenDestPoints=t.extend({},e.img,{},!0),e.img.destLeft=i,e.img.destTop=r,e.img.destWidth=a,e.img.destHeight=n}},e}(),d=function(){function e(e){this.parent=e,this.addEventListener()}return e.prototype.destroy=function(){this.parent.isDestroyed||this.removeEventListener()},e.prototype.addEventListener=function(){this.parent.on("export",this.export,this),this.parent.on("destroyed",this.destroy,this)},e.prototype.removeEventListener=function(){this.parent.off("export",this.export),this.parent.off("destroyed",this.destroy)},e.prototype.export=function(e){switch(this.parent.notify("toolbar",{prop:"refreshShapeDrawing",onPropertyChange:!1}),this.updatePvtVar(),e.prop){case"export":this.exportImg(e.value.type,e.value.fileName,e.value.imgQuality);break;case"exportToCanvas":this.exportToCanvas(e.value.object);break;case"updateSaveContext":this.updateSaveContext(e.value.context);break;case"setImageQuality":this.imageQuality=e.value.value}},e.prototype.getModuleName=function(){return"export"},e.prototype.updatePvtVar=function(){var e=this.parent;e.lowerCanvas&&(this.lowerContext=e.lowerCanvas.getContext("2d"))},e.prototype.exportImg=function(e,t,o){var i=this.parent,r={fileName:""};i.notify("draw",{prop:"getFileName",onPropertyChange:!1,value:{obj:r}});var a=r.fileName;if(!i.disabled&&i.isImageLoaded){var n={bool:!1};i.notify("selection",{prop:"getFreehandDrawEditing",onPropertyChange:!1,value:{obj:n}}),n.bool&&i.notify("freehand-draw",{prop:"applyFhd",onPropertyChange:!1}),i.togglePen&&(i.currObjType.isZoomed=!0,i.notify("shape",{prop:"apply",onPropertyChange:!1,value:{shape:null,obj:null,canvas:null}})),"block"!==i.textArea.style.display&&"inline-block"!==i.textArea.style.display||i.notify("shape",{prop:"redrawActObj",onPropertyChange:!1,value:{x:null,y:null,isMouseDown:null}}),i.notify("shape",{prop:"applyActObj",onPropertyChange:!1,value:{isMouseDown:null}});var s={canvasFilter:this.parent.canvasFilter};this.lowerContext.filter=s.canvasFilter,e=e||"Png",i.notify("shape",{prop:"redrawActObj",onPropertyChange:!1,value:{x:null,y:null,isMouseDown:null}});var l={cancel:!1,fileName:t||a,fileType:e,imageQuality:o};i.trigger("beforeSave",l),this.beforeSaveEvent(l,e,t,a,o)}},e.prototype.beforeSaveEvent=function(e,t,o,i,r){var a=this.parent;if(!e.cancel){a.currObjType.isSave=!0,o=e.fileName?e.fileName:o;var n=t.toLowerCase();o=o||i,"svg"===n?this.toSVGImg(o):this.toBlobFn(o,n,r);var s={fileName:o||i,fileType:t};a.trigger("saved",s),a.notify("toolbar",{prop:"refresh-main-toolbar",onPropertyChange:!1}),a.lowerCanvas.style.left=a.upperCanvas.style.left="",a.lowerCanvas.style.top=a.upperCanvas.style.top="",a.lowerCanvas.style.maxWidth=a.upperCanvas.style.maxWidth="",a.lowerCanvas.style.maxHeight=a.upperCanvas.style.maxHeight=""}},e.prototype.toSVGImg=function(e){var t=this.parent;o.showSpinner(t.element),t.element.style.opacity="0.5";var i=this.exportToCanvas(),r=i.toDataURL();o.hideSpinner(t.element),t.element.style.opacity="1";var a=document.createElementNS("http://www.w3.org/2000/svg","svg");a.setAttribute("width",i.style.maxWidth),a.setAttribute("height",i.style.maxHeight);var n=document.createElementNS("http://www.w3.org/2000/svg","image");n.setAttributeNS(null,"height",i.height.toString()),n.setAttributeNS(null,"width",i.width.toString()),n.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",r),a.appendChild(n);var s='<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="'+i.width+'" height="'+i.height+'">'+a.innerHTML+"</svg>",l="data:image/svg+xml;base64,"+btoa(s);return null===e?l:(this.downloadImg(l,e+".svg"),null)},e.prototype.toBlobFn=function(e,i,r){var a=this,n=this.parent;o.showSpinner(n.element),n.element.style.opacity="0.5",t.isNullOrUndefined(r)||(r=r>1?1:r<=0?.01:r,this.imageQuality=r||null);var s=this.exportToCanvas(),l="jpeg"!==i?"image/png":"image/jpeg";s.toBlob(function(t){var r=URL.createObjectURL(t);a.downloadImg(r,e+"."+i),o.hideSpinner(n.element),n.element.style.opacity="1"},l,this.imageQuality?this.imageQuality:null)},e.prototype.exportToCanvas=function(e){var o,i,r=this.parent,a=t.extend({},r.cropObj,{},!0),n={currObj:{}};r.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:n}});var s=n.currObj;s.objColl=t.extend([],r.objColl,[],!0),s.pointColl=t.extend([],r.pointColl,[],!0),s.afterCropActions=t.extend([],r.afterCropActions,[],!0);var l={selPointColl:null};r.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:l}}),this.parent.aspectWidth?(r.notify("undo-redo",{prop:"setPreventUR",value:{bool:!0}}),r.notify("toolbar",{prop:"resizeClick",value:{bool:!1}}),r.okBtn(),r.transform.degree%90==0&&r.transform.degree%180!=0?(o=this.parent.aspectHeight,i=this.parent.aspectWidth):(o=this.parent.aspectWidth,i=this.parent.aspectHeight),r.notify("undo-redo",{prop:"setPreventUR",value:{bool:!1}})):r.currSelectionPoint?(o=r.img.srcWidth,i=r.img.srcHeight):(o=r.baseImgCanvas.width,i=r.baseImgCanvas.height);var p={width:0,height:0};r.notify("crop",{prop:"calcRatio",onPropertyChange:!1,value:{obj:p,dimension:{width:o,height:i}}});var h=p,d=this.lowerContext.filter;if("none"!==this.lowerContext.filter){var c=this.lowerContext.filter.split(" "),u=parseFloat(c[5].split("(")[1]);u*=(h.width+h.height)/2,c[5]="blur("+u+"px)",this.lowerContext.filter=c.join(" ")}var v=r.createElement("canvas",{id:r.element.id+"_tempCanvas",attrs:{name:"canvasImage"}}),g=v.getContext("2d");v.width=o,v.height=i;var f={width:0,height:0};r.notify("transform",{prop:"calcMaxDimension",onPropertyChange:!1,value:{width:o,height:i,obj:f}});var C=f;v.style.maxWidth=C.width+"px",v.style.maxHeight=C.height+"px";var b=this.lowerContext.filter;return g.filter=this.lowerContext.filter,this.downScaleImgCanvas(g,o,i),this.lowerContext.filter=b,0===r.transform.degree&&""===r.transform.currFlipState&&0===r.transform.straighten||(this.updateSaveContext(g),this.exportTransformedImage(g)),this.drawAnnotation(g,h),r.isCircleCrop&&r.notify("crop",{prop:"cropCircle",onPropertyChange:!1,value:{context:g,isSave:!0,isFlip:null}}),this.updateFrame(g,!0),this.lowerContext.filter=d,r.canvasFilter=d,e&&(e.canvas=v),r.aspectWidth&&(r.objColl=[],r.pointColl=[],r.freehandCounter=0,r.notify("freehand-draw",{prop:"setSelPointColl",onPropertyChange:!1,value:{obj:{selPointColl:[]}}}),r.notify("draw",{prop:"setCurrentObj",onPropertyChange:!1,value:{obj:s}}),s.selPointColl=t.extend([],l.selPointColl,[],!0),r.notify("freehand-draw",{prop:"setSelPointColl",onPropertyChange:!1,value:{obj:{selPointColl:s.selPointColl}}}),r.cropObj=a,r.objColl=t.extend([],s.objColl,[],!0),r.pointColl=t.extend([],s.pointColl,[],!0),r.freehandCounter=r.pointColl.length,r.transform.straighten=0,this.lowerContext.filter="none",r.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"zoom",pen:"zoom",isPreventApply:null}}),this.lowerContext.filter=s.filter,r.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.lowerContext}}),(r.isCircleCrop||r.currSelectionPoint&&"crop-circle"===r.currSelectionPoint.shape)&&r.notify("crop",{prop:"cropCircle",onPropertyChange:!1,value:{context:this.lowerContext,isSave:null,isFlip:null}})),v},e.prototype.drawAnnotation=function(e,o){for(var i=this.parent,r=t.extend([],i.objColl,[],!0),a=t.extend([],i.pointColl,[],!0),n=0;n<i.shapeColl.length;n++)i.shapeColl[n].order&&(i.shapeColl[n].currIndex&&i.shapeColl[n].currIndex.indexOf("shape")>-1?(i.objColl=[],i.objColl.push(t.extend({},i.shapeColl[n],{},!0)),this.drawShape(e,o)):i.shapeColl[n].id&&i.shapeColl[n].id.indexOf("pen")>-1&&(i.pointColl=[],i.freehandCounter=0,i.pointColl.push(t.extend({},i.shapeColl[n],{},!0)),i.freehandCounter=i.pointColl.length,this.drawPen(e,o)));i.objColl=r,i.pointColl=a,i.freehandCounter=i.pointColl.length},e.prototype.drawShape=function(e,o){var i=this.parent;if(i.objColl.length>0){var r=e.filter;e.filter="none";var a={index:null};i.notify("shape",{prop:"getSmallestIndex",onPropertyChange:!1,value:{obj:a}});for(var n=a.index,s=t.extend([],i.objColl,[],!0),l=t.extend([],i.objColl,[],!0);s.length>0;){for(var p=!1,h=0;h<s.length;h++){var d=s[h];if(t.isNullOrUndefined(d.order))s.splice(h,1),h--;else if(d.order===n){var c=e.filter;e.filter="none";var u=s[h],v=u.activePoint;if(v.startX-=i.img.destLeft,v.startY-=i.img.destTop,v.endX-=i.img.destLeft,v.endY-=i.img.destTop,v.width=v.endX-v.startX,v.height=v.endY-v.startY,v.startX*=o.width,v.startY*=o.height,v.endX*=o.width,v.endY*=o.height,v.width=v.endX-v.startX,v.height=v.endY-v.startY,u.strokeSettings.strokeWidth*=(o.width+o.height)/2,"text"===u.shape)u.textSettings.fontSize*=(o.width+o.height)/2;else if("path"===u.shape)for(var g=0;g<u.pointColl.length;g++)u.pointColl[g].x=(u.pointColl[g].x-i.img.destLeft)*o.width,u.pointColl[g].y=(u.pointColl[g].y-i.img.destTop)*o.height;else"image"===u.shape&&(i.activeObj=t.extend({},s[h],{},!0),i.notify("selection",{prop:"upgradeImageQuality",onPropertyChange:!1}),s[h]=t.extend({},i.activeObj,{},!0));i.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"saveContext",obj:s[h],isCropRatio:null,points:null,isPreventDrag:!0,saveContext:e,isPreventSelection:null}}),e.filter=c,i.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),n++;var f={bool:!1};i.notify("shape",{prop:"isIndexInObjColl",onPropertyChange:!1,value:{obj:f,index:n}}),f.bool||n++,s.splice(h,1),p=!0;break}}if(!p)break}e.filter=r,i.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),i.objColl=l}},e.prototype.drawPen=function(e,o){var i=this.parent;if(i.freehandCounter>0){var r={penStrokeWidth:null};i.notify("freehand-draw",{prop:"getPenStrokeWidth",onPropertyChange:!1,value:{obj:r}});for(var a=t.extend({},i.pointColl,{},!0),n=0;n<i.freehandCounter;n++){i.points=t.extend([],i.pointColl[n].points,[]),i.notify("freehand-draw",{prop:"setPointCounter",onPropertyChange:!1,value:{value:0}});var s=i.points.length;i.pointColl[n].strokeWidth*=(o.width+o.height)/2;for(var l=0;l<s;l++)i.points[l].x=(i.points[l].x-i.img.destLeft)*o.width,i.points[l].y=(i.points[l].y-i.img.destTop)*o.height}i.notify("freehand-draw",{prop:"freehandRedraw",onPropertyChange:!1,value:{context:e,points:null}}),i.pointColl=a,i.notify("freehand-draw",{prop:"setPenStrokeWidth",onPropertyChange:!1,value:{value:r.penStrokeWidth}})}},e.prototype.downScaleImgCanvas=function(e,t,o){var i=this.parent,r=i.baseImgCanvas,a=i.baseImg,n={width:0,height:0};if(i.notify("transform",{prop:"calcMaxDimension",onPropertyChange:!1,value:{width:a.width,height:a.height,obj:n,isImgShape:null}}),n.width>t&&n.height>o){var s=i.createElement("canvas",{id:i.element.id+"_downScaleCanvas",attrs:{name:"canvasImage"}});s.width=this.parent.img.srcWidth,s.height=this.parent.img.srcHeight,s.getContext("2d").drawImage(r,i.img.srcLeft,i.img.srcTop,i.img.srcWidth,i.img.srcHeight,0,0,s.width,s.height),i.notify("draw",{prop:"downScale",value:{canvas:s,width:t,height:o}}),e.drawImage(s,0,0)}else e.drawImage(i.baseImgCanvas,i.img.srcLeft,i.img.srcTop,i.img.srcWidth,i.img.srcHeight,0,0,t,o)},e.prototype.updateFrame=function(e,t){if("none"!==this.parent.frameObj.type){var o=e.filter;e.filter="none",this.parent.notify("draw",{prop:"applyFrame",value:{ctx:e,frame:this.parent.frameObj.type,preventImg:t}}),e.filter=o}},e.prototype.downloadImg=function(e,t){var o=document.createElement("a");o.href=e,o.target="_parent",o.download=t,(document.body||document.documentElement).appendChild(o),o.click(),o.parentNode.removeChild(o)},e.prototype.exportTransformedImage=function(e){var t=this.parent,o=t.transform.degree;if(t.rotateFlipColl.length>0)for(var i=0,r=t.rotateFlipColl.length;i<r;i++){var a=t.rotateFlipColl[i];"number"==typeof a?this.exportRotate(e,a):"horizontal"===a?this.exportFlip(e,!0,!1):"vertical"===a&&this.exportFlip(e,!1,!0)}t.transform.degree=o},e.prototype.exportRotate=function(e,t){var o=this.parent;e.clearRect(0,0,e.canvas.width,e.canvas.height),this.setMaxDim(o.transform.degree,e.canvas),e.translate(e.canvas.width/2,e.canvas.height/2),e.rotate(Math.PI/180*t),e.drawImage(o.inMemoryCanvas,-e.canvas.height/2,-e.canvas.width/2,e.canvas.height,e.canvas.width),this.updateSaveContext(e)},e.prototype.exportFlip=function(e,t,o){e.clearRect(0,0,e.canvas.width,e.canvas.height),t&&(e.translate(e.canvas.width,0),e.scale(-1,1)),o&&(e.translate(0,e.canvas.height),e.scale(1,-1)),e.drawImage(this.parent.inMemoryCanvas,0,0),this.updateSaveContext(e)},e.prototype.updateSaveContext=function(e){var t=this.parent.inMemoryCanvas.getContext("2d");e.setTransform(1,0,0,1,0,0);var o=e.getImageData(0,0,e.canvas.width,e.canvas.height);this.parent.inMemoryCanvas.width=o.width,this.parent.inMemoryCanvas.height=o.height,t.putImageData(o,0,0)},e.prototype.setMaxDim=function(e,o){var i,r;e%90==0&&e%180!=0?t.isNullOrUndefined(this.parent.currSelectionPoint)?(i=this.parent.baseImgCanvas.height,r=this.parent.baseImgCanvas.width):(i=this.parent.img.srcHeight,r=this.parent.img.srcWidth):e%180!=0&&0!==e||(t.isNullOrUndefined(this.parent.currSelectionPoint)?(i=this.parent.baseImgCanvas.width,r=this.parent.baseImgCanvas.height):(i=this.parent.img.srcWidth,r=this.parent.img.srcHeight)),t.isNullOrUndefined(this.parent.aspectWidth)||(i=this.parent.aspectWidth,r=this.parent.aspectHeight),o.width=i,o.height=r;var a={width:0,height:0};this.parent.notify("transform",{prop:"calcMaxDimension",onPropertyChange:!1,value:{width:i,height:r,obj:a,isImgShape:null}});var n=a;o.style.maxWidth=n.width+"px",o.style.maxHeight=n.height+"px"},e}(),c=function(){function e(e){this.adjustmentLevel={brightness:0,contrast:0,hue:0,opacity:100,saturation:0,blur:0,exposure:0,transparency:100,sharpen:!1,bw:!1},this.tempAdjustmentLevel={brightness:0,contrast:0,hue:0,opacity:100,saturation:0,blur:0,exposure:0,transparency:100,sharpen:!1,bw:!1},this.adjustmentValue="",this.isBrightnessAdjusted=!1,this.bevelFilter="none",this.tempAdjVal={brightness:0,contrast:0,hue:0,opacity:100,saturation:0,blur:0,exposure:0,transparency:100,sharpen:!1,bw:!1},this.tempFilVal="",this.parent=e,this.addEventListener()}return e.prototype.destroy=function(){this.parent.isDestroyed||this.removeEventListener()},e.prototype.addEventListener=function(){this.parent.on("filter",this.filter,this),this.parent.on("destroyed",this.destroy,this)},e.prototype.removeEventListener=function(){this.parent.off("filter",this.filter),this.parent.off("destroyed",this.destroy)},e.prototype.filter=function(e){switch(this.updatePrivateVariables(),e.prop){case"finetuneImage":this.finetuneImage(e.value.option,e.value.value);break;case"applyImageFilter":this.setFilter(e.value.option);break;case"update-finetunes":this.updateFinetunes();break;case"set-adjustment":this.setAdjustment(e.value.operation);break;case"initFilter":this.initFilter();break;case"setCurrAdjValue":this.setCurrAdjValue(e.value.type,e.value.value);break;case"updateAdj":this.updateAdj(e.value.type,e.value.value,e.value.isPreview,e.value.ctx);break;case"getCurrentObj":this.getCurrentObj(e.value.object);break;case"getAdjustmentLevel":t.isNullOrUndefined(this.parent.activeObj.opacity)?this.adjustmentLevel.transparency=100:this.adjustmentLevel.transparency=100*this.parent.activeObj.opacity,e.value.obj.adjustmentLevel=this.adjustmentLevel;break;case"setAdjustmentLevel":this.adjustmentLevel=e.value.adjustmentLevel;break;case"getTempAdjustmentLevel":e.value.obj.tempAdjustmentLevel=this.tempAdjustmentLevel;break;case"setTempAdjustmentLevel":this.tempAdjustmentLevel=e.value.tempAdjustmentLevel;break;case"setAdjustmentValue":this.adjustmentValue=e.value.adjustmentValue;break;case"getBrightnessAdjusted":e.value.obj.isBrightnessAdjusted=this.isBrightnessAdjusted;break;case"setBrightnessAdjusted":this.isBrightnessAdjusted=e.value.isBrightnessAdjusted,this.parent.currentFilter.split("_")&&"cold"===this.parent.currentFilter.split("_")[1]&&(this.isBrightnessAdjusted=!1);break;case"getBevelFilter":e.value.obj.bevelFilter=this.bevelFilter;break;case"setBevelFilter":this.bevelFilter=e.value.bevelFilter;break;case"setTempAdjVal":this.tempAdjVal=t.extend({},this.adjustmentLevel,{},!0);break;case"setTempFilVal":this.tempFilVal=this.parent.currentFilter;break;case"reset":this.reset()}},e.prototype.updatePrivateVariables=function(){var e=this.parent;e.lowerCanvas&&(this.lowerContext=e.lowerCanvas.getContext("2d"))},e.prototype.getModuleName=function(){return"filter"},e.prototype.reset=function(){this.adjustmentLevel={brightness:0,contrast:0,hue:0,opacity:100,saturation:0,blur:0,exposure:0,transparency:100,sharpen:!1,bw:!1},this.tempAdjustmentLevel={brightness:0,contrast:0,hue:0,opacity:100,saturation:0,blur:0,exposure:0,transparency:100,sharpen:!1,bw:!1},this.adjustmentValue=this.parent.getDefaultFilter(),this.isBrightnessAdjusted=!1,this.bevelFilter="none",this.tempFilVal="",this.tempAdjVal={brightness:0,contrast:0,hue:0,opacity:100,saturation:0,blur:0,exposure:0,transparency:100,sharpen:!1,bw:!1}},e.prototype.updateFinetunes=function(){var e=this,t=this.parent,o=t.finetuneSettings;o&&(["brightness","contrast","hue","saturation","exposure","opacity","blur"].forEach(function(t){o[t]&&(e.adjustmentLevel[t]=o[t].defaultValue,e.tempAdjustmentLevel[t]=o[t].defaultValue)}),t.notify("draw",{prop:"isInitialLoading",onPropertyChange:!1,value:{isInitialLoading:!0}}))},e.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)},e.prototype.updateAdj=function(e,o,i,r){var a=this.parent;this.lowerContext.clearRect(0,0,a.lowerCanvas.width,a.lowerCanvas.height);var n=this.lowerContext.filter.split(" "),s=[],l=this.getFilterValue(this.adjustmentLevel.brightness);if(-1===["brightness","contrast","hue","saturation","exposure","opacity","blur"].indexOf(e)&&t.isNullOrUndefined(i)&&(this.adjustmentLevel.sharpen||this.adjustmentLevel.bw)){a.isUndoRedo=!0;var p=this.lowerContext.filter;this.lowerContext.filter="none",a.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"iterate",pen:"iterate",isPreventApply:null}}),this.lowerContext.filter=p,a.isUndoRedo=!1}var h,d,c,u,v;switch(e){case"brightness":o=this.getFilterValue(this.adjustmentLevel.exposure)+.005*o,n[0]="brightness("+o+")",0!==this.adjustmentLevel.brightness?(o=this.adjustmentLevel.opacity/100-.3*this.adjustmentLevel.opacity/100,n[4]="opacity("+o+")"):(o=this.adjustmentLevel.opacity/100,n[4]="opacity("+o+")"),this.adjustmentValue=n.join(" ");break;case"contrast":n[1]="contrast("+o+"%)",this.adjustmentValue=n.join(" ");break;case"hue":n[2]="hue-rotate("+o+"deg)",this.adjustmentValue=n.join(" ");break;case"saturation":n[3]="saturate("+o+"%)",this.adjustmentValue=n.join(" ");break;case"opacity":1!==parseFloat(n[0].split("(")[1])&&(o-=.2),o<0&&(o=0),n[4]="opacity("+o+")",this.adjustmentValue=n.join(" ");break;case"blur":n[5]="blur("+o+"px)",this.adjustmentValue=n.join(" ");break;case"exposure":o>1?(o-=1,o+=l):o<1&&(o=l-(o=1-o)),n[0]="brightness("+o+")",this.adjustmentValue=n.join(" ");break;case"chrome":h=this.getSaturationFilterValue(this.adjustmentLevel.saturation),o=(h*=100)+.4*h,n[3]="saturate("+o+"%)",s=this.adjustmentValue.split(" "),n[0]=s[0],n[1]=s[1],n[2]=s[2],n[4]=s[4],n[5]=s[5],n[6]="sepia(0%)",n[7]="grayscale(0%)",n[8]="invert(0%)";break;case"cold":d=this.getFilterValue(this.adjustmentLevel.brightness),o=.9*(d*=100),o*=.01,n[0]="brightness("+o+")",u=this.getFilterValue(this.adjustmentLevel.contrast),o=(u*=100)+.5*u,n[1]="contrast("+o+"%)",v=this.getSaturationFilterValue(this.adjustmentLevel.saturation),o=v*=100,n[3]="saturate("+o+"%)",s=this.adjustmentValue.split(" "),n[2]=s[2],n[4]=s[4],n[5]=s[5],n[6]="sepia(0%)",n[7]="grayscale(0%)",n[8]="invert(0%)";break;case"warm":c=this.getSaturationFilterValue(this.adjustmentLevel.saturation),o=(c*=100)+.4*c,n[3]="saturate("+o+"%)",n[6]="sepia(25%)",s=this.adjustmentValue.split(" "),n[0]=s[0],n[1]=s[1],n[2]=s[2],n[4]=s[4],n[5]=s[5],n[7]="grayscale(0%)",n[8]="invert(0%)";break;case"grayscale":n[7]="grayscale(100%)",s=this.adjustmentValue.split(" "),n[0]=s[0],n[1]=s[1],n[2]=s[2],n[3]=s[3],n[4]=s[4],n[5]=s[5],n[6]="sepia(0%)",n[8]="invert(0%)";break;case"sepia":n[6]="sepia(100%)",s=this.adjustmentValue.split(" "),n[0]=s[0],n[1]=s[1],n[2]=s[2],n[3]=s[3],n[4]=s[4],n[5]=s[5],n[7]="grayscale(0%)",n[8]="invert(0%)";break;case"invert":n[8]="invert(100%)",s=this.adjustmentValue.split(" "),n[0]=s[0],n[1]=s[1],n[2]=s[2],n[3]=s[3],n[4]=s[4],n[5]=s[5],n[6]="sepia(0%)",n[7]="grayscale(0%)"}if("sharpen"!==e&&"blackandwhite"!==e){t.isNullOrUndefined(i)&&("default"===e&&(n=this.getDefaultCurrentFilter(n)),this.lowerContext.filter=n.join(" ")),n=this.setTempFilterValue(l,i,n,e),a.notify("draw",{prop:"setRotateZoom",onPropertyChange:!1,value:{isRotateZoom:!0}}),a.notify("draw",{prop:"updateCurrTransState",onPropertyChange:!1,value:{type:"initial",isPreventDestination:null,isRotatePan:null}});var g=void 0;"bevel"===a.frameObj.type&&(g=this.lowerContext.filter,this.bevelFilter=g),0===a.transform.degree&&a.rotateFlipColl.length>0&&(a.img.destLeft+=a.panPoint.totalPannedPoint.x,a.img.destTop+=a.panPoint.totalPannedPoint.y),a.img.destLeft+=a.panPoint.totalPannedInternalPoint.x,a.img.destTop+=a.panPoint.totalPannedInternalPoint.y,0===a.transform.degree&&a.notify("transform",{prop:"setDestPointsForFlipState",onPropertyChange:!1}),a.notify("draw",{prop:"drawImage",onPropertyChange:!1}),a.notify("draw",{prop:"updateCurrTransState",onPropertyChange:!1,value:{type:"reverse",isPreventDestination:null,isRotatePan:null}}),a.notify("draw",{prop:"setRotateZoom",onPropertyChange:!1,value:{isRotateZoom:!1}}),0===a.transform.degree&&a.rotateFlipColl.length>0&&(a.img.destLeft+=a.panPoint.totalPannedPoint.x,a.img.destTop+=a.panPoint.totalPannedPoint.y),n=this.setTempFilterValue(l,i,n,e),t.isNullOrUndefined(i)&&(this.lowerContext.filter=n.join(" ")),a.initialAdjustmentValue=n.join(" "),g=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%)",this.bevelFilter=g,a.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"iterate",pen:"iterate",isPreventApply:null}}),this.lowerContext.filter=g,a.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.lowerContext}}),(a.currSelectionPoint&&"crop-circle"===a.currSelectionPoint.shape||a.isCircleCrop)&&a.notify("crop",{prop:"cropCircle",onPropertyChange:!1,value:{context:this.lowerContext,isSave:null,isFlip:null}}),this.isBrightnessAdjusted=1!==l}var f=n.join(" ");r&&(r.filter=f)},e.prototype.setTempFilterValue=function(e,t,o,i){if(t)if("default"===i)o=this.getDefaultCurrentFilter(o);else if(1!==e){var r=this.lowerContext.filter.split(" ");r[4]=o[4],this.lowerContext.filter=r.join(" ")}return o},e.prototype.getDefaultCurrentFilter=function(e){var t=this.adjustmentValue.split(" ");return[t[0],t[1],t[2],t[3],t[4],t[5],"sepia(0%)","grayscale(0%)","invert(0%)"]},e.prototype.getFilterValue=function(e){return 0===e?1:1+.5*e/100},e.prototype.getSaturationFilterValue=function(e){return 0===e?1:1+e/100},e.prototype.setFilterAdj=function(e,o){var i=this.parent;switch(i.notify("freehand-draw",{prop:"apply-pen-draw",onPropertyChange:!1}),this.adjustmentLevel[""+e]=o,e){case"contrast":case"exposure":o=this.getFilterValue(o),"contrast"===e&&(o*=100);break;case"hue":o*=3;break;case"saturation":o=100*this.getSaturationFilterValue(o);break;case"opacity":o<10&&(o+=1),o/=100;break;case"blur":0!==o&&(o/=20,o+=.5)}var r=t.extend({},i.cropObj,{},!0),a=this.getCurrentObj();a.objColl=t.extend([],i.objColl,[],!0),a.pointColl=t.extend([],i.pointColl,[],!0),a.afterCropActions=t.extend([],i.afterCropActions,[],!0);var n={selPointColl:null};i.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:n}}),a.selPointColl=t.extend([],n.selPointColl,[],!0),this.updateAdj(e,o),i.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:e,previousObj:a,previousObjColl:a.objColl,previousPointColl:a.pointColl,previousSelPointColl:a.selPointColl,previousCropObj:r,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}})},e.prototype.setFilter=function(e){var o=this.parent;e=e.toLowerCase(),o.notify("freehand-draw",{prop:"apply-pen-draw",onPropertyChange:!1});var i={currentFilter:this.parent.currentFilter}.currentFilter,r=t.extend({},o.cropObj,{},!0),a=this.getCurrentObj();a.objColl=t.extend([],o.objColl,[],!0),a.pointColl=t.extend([],o.pointColl,[],!0),a.afterCropActions=t.extend([],o.afterCropActions,[],!0);var n={selPointColl:null};o.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:n}}),a.selPointColl=t.extend([],n.selPointColl,[],!0),this.updateAdj(e,null),o.notify("draw",{prop:"setImageEdited",onPropertyChange:!1}),o.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:e,previousObj:a,previousObjColl:a.objColl,previousPointColl:a.pointColl,previousSelPointColl:a.selPointColl,previousCropObj:r,previousText:null,currentText:null,previousFilter:i,isCircleCrop:null}})},e.prototype.setAdjustment=function(e){var t,o,i=this.lowerContext.filter.split(" ");switch(e){case"brightness":o=i[0].split("("),t=parseFloat(o[1].split(")")[0]),this.adjustmentLevel.brightness=this.setFilterValue(t);break;case"contrast":o=i[1].split("("),t=parseFloat(o[1].split(")")[0]),t/=100,this.adjustmentLevel.contrast=this.setFilterValue(t);break;case"hue":o=i[2].split("("),t=parseFloat(o[1].split(")")[0]),t/=3,this.adjustmentLevel.hue=t;break;case"saturation":o=i[3].split("("),t=parseFloat(o[1].split(")")[0]),t/=100,this.adjustmentLevel.saturation=this.setSaturationFilterValue(t);break;case"opacity":o=i[4].split("("),.45===(t=parseFloat(o[1].split(")")[0]))?t=40:.4===t?t=30:.35===t?t=20:.3===t?t=10:.25===t?t=0:t*=100,this.adjustmentLevel.opacity=t;break;case"blur":o=i[5].split("("),t=parseFloat(o[1].split(")")[0]),t*=20,this.adjustmentLevel.blur=t;break;case"exposure":o=i[0].split("("),t=parseFloat(o[1].split(")")[0]),this.adjustmentLevel.exposure=this.setFilterValue(t)}},e.prototype.setFilterValue=function(e){return Math.round(1===e?0:100*(e-1)/.5)},e.prototype.setSaturationFilterValue=function(e){return Math.round(1===e?0:100*(e-1))},e.prototype.finetuneImage=function(e,t){var o=this.parent;if(!o.disabled&&o.isImageLoaded){switch(e.toLowerCase()){case"brightness":this.setFilterAdj("brightness",t);break;case"contrast":this.setFilterAdj("contrast",t);break;case"hue":this.setFilterAdj("hue",t);break;case"saturation":this.setFilterAdj("saturation",t);break;case"opacity":this.setFilterAdj("opacity",t);break;case"blur":this.setFilterAdj("blur",t);break;case"exposure":this.setFilterAdj("exposure",t)}this.parent.canvasFilter=this.lowerContext.filter,o.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"ok"}})}},e.prototype.setCurrAdjValue=function(e,t){var o=this.parent;switch(this.parent.notify("draw",{prop:"setImageEdited",onPropertyChange:!1}),e){case"brightness":this.setFilterAdj("brightness",t);break;case"contrast":this.setFilterAdj("contrast",t);break;case"hue":this.setFilterAdj("hue",t);break;case"saturation":this.setFilterAdj("saturation",t);break;case"opacity":this.setFilterAdj("opacity",t);break;case"blur":this.setFilterAdj("blur",t);break;case"exposure":this.setFilterAdj("exposure",t)}o.isFinetuneBtnClick=!0,o.curFinetuneObjEvent={finetune:o.toPascalCase(e),value:t}},e.prototype.getCurrentObj=function(e){var o=this.parent,i={point:null};o.notify("crop",{prop:"getTempFlipPanPoint",value:{obj:i}});var r={previousZoomValue:null};o.notify("transform",{prop:"getPreviousZoomValue",value:{obj:r}});var a={zoomFactor:null};o.notify("draw",{prop:"getStraightenInitZoom",value:{obj:a}});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,straighten:0,destPoints:{startX:0,startY:0,width:0,height:0},frame:"none",srcPoints:{startX:0,startY:0,width:0,height:0},filter:"",isBrightAdjust:this.isBrightnessAdjusted,aspectWidth:null,aspectHeight:null,straightenZoom:0,adjustmentLevel:t.extend({},this.tempAdjVal,{},!0),currentFilter:this.tempFilVal};return n.cropZoom=o.transform.cropZoomFactor,n.defaultZoom=o.transform.defaultZoomFactor,n.zoomFactor=o.zoomSettings.zoomFactor,n.previousZoomValue=r.previousZoomValue,n.straightenZoom=a.zoomFactor,n.totalPannedPoint=t.extend({},o.panPoint.totalPannedPoint,{},!0),n.totalPannedClientPoint=t.extend({},o.panPoint.totalPannedClientPoint,{},!0),n.totalPannedInternalPoint=t.extend({},o.panPoint.totalPannedInternalPoint,{},!0),n.tempFlipPanPoint=t.extend({},i.point,{},!0),n.activeObj=t.extend({},o.activeObj,{},!0),n.rotateFlipColl=t.extend([],o.rotateFlipColl,[],!0),n.degree=o.transform.degree,n.straighten=o.cropObj.straighten,n.currFlipState=o.transform.currFlipState,n.destPoints={startX:o.img.destLeft,startY:o.img.destTop,endX:0,endY:0,width:o.img.destWidth,height:o.img.destHeight},n.srcPoints={startX:o.img.srcLeft,startY:o.img.srcTop,endX:0,endY:0,width:o.img.srcWidth,height:o.img.srcHeight},n.filter=this.lowerContext.filter,n.aspectWidth=o.aspectWidth,n.aspectHeight=o.aspectHeight,n.frame=o.frameObj.type,n.frameObj=t.extend({},o.frameObj),e&&(e.currObj=n),n},e}(),u=function(){function o(e){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.dummyPoints=[],this.tempFHDStyles={strokeColor:null,fillColor:null,strokeWidth:null},this.straightenPoint={x:null,y:null,ratioX:null,ratioY:null},this.straightenPointAngle=0,this.parent=e,this.addEventListener()}return o.prototype.destroy=function(){this.parent.isDestroyed||this.removeEventListener()},o.prototype.addEventListener=function(){this.parent.on("freehand-draw",this.draw,this),this.parent.on("destroyed",this.destroy,this)},o.prototype.removeEventListener=function(){this.parent.off("freehand-draw",this.draw),this.parent.off("destroyed",this.destroy)},o.prototype.draw=function(e){switch(this.updateFhdPvtVar(),e.prop){case"hoverFhd":this.hoverFhd(e.value.strokeColor,e.value.strokeWidth);break;case"freehandDownHandler":this.freehandDownHandler(e.value.e,e.value.canvas);break;case"freehandUpHandler":this.freehandUpHandler(e.value.e,e.value.canvas,e.value.context);break;case"handle-freehand-draw":o=parseInt(e.value.id.split("_")[1],10)-1;this.isFHDIdx(o)&&this.deleteFhd(o,!0);break;case"freehandRedraw":this.freehandRedraw(e.value.context,e.value.points);break;case"deleteFhd":o=parseInt(e.value.id.split("_")[1],10)-1;this.deleteFhd(o,!0);break;case"selectFhd":var o=null;e.value.id&&(o=parseInt(e.value.id.split("_")[1],10)-1),this.selectFhd(o);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(e.value.value);break;case"panFHDColl":this.panFHDColl(e.value.xDiff,e.value.yDiff,e.value.panRegion);break;case"updateFHDColl":e.value&&e.value.isPreventApply?this.updateFHDColl(e.value.isPreventApply):this.updateFHDColl();break;case"zoomFHDColl":this.zoomFHDColl(e.value.isPreventApply);break;case"apply-pen-draw":this.applyPenDraw();break;case"freeHandDraw":this.freeHandDraw(e.value.value);break;case"isFHDIdx":this.isFHDIdx(e.value.index,e.value.obj);break;case"getSqPtFD":this.getSqPtFD(e.value.idx,e.value.obj);break;case"getSelPointColl":e.value.obj.selPointColl=t.extend([],this.selPointColl);break;case"setSelPointColl":this.selPointColl=t.extend([],e.value.obj.selPointColl);break;case"setFreehandDrawHoveredIndex":this.fhdHovIdx=e.value.index;break;case"getFreehandDrawHoveredIndex":e.value.obj.index=this.fhdHovIdx;break;case"setPointCounter":this.pointCounter=e.value.value;break;case"getPenStrokeWidth":e.value.obj.penStrokeWidth=this.penStrokeWidth;break;case"setPenStrokeWidth":this.penStrokeWidth=e.value.value;break;case"getCurrentFreehandDrawIndex":e.value.obj.currentFreehandDrawIndex=this.currFHDIdx;break;case"setCurrentFreehandDrawIndex":this.currFHDIdx=e.value.value;break;case"updateCropPtsForSel":this.updateCropPtsForSel();break;case"getFreehandDrawSelectedId":e.value.obj.freehandDrawSelectedId=this.fhdSelID;break;case"resetFreehandDrawSelectedId":this.fhdSelID=null;break;case"getTempFreeHandDrawEditingStyles":e.value.obj.tempFreeHandDrawEditingStyles=this.tempFHDStyles;break;case"setFreehandSelectedIndex":this.fhdSelIdx=e.value.index;break;case"getFreehandSelectedIndex":e.value.obj.freehandSelectedIndex=this.fhdSelIdx;break;case"setCenterSelPoints":this.setCenterSelPoints();break;case"getStraightenPoint":e.value.obj.straightenPoint=t.extend({},this.straightenPoint,{},!0);break;case"setStraightenPoint":this.straightenPoint.x=e.value.x,this.straightenPoint.y=e.value.y,e.value.ratioX&&e.value.ratioY&&(this.straightenPoint.ratioX=e.value.ratioX,this.straightenPoint.ratioY=e.value.ratioY);break;case"resetStraightenPoint":this.straightenPoint={x:null,y:null,ratioX:null,ratioY:null},this.prevStraightenObj=null,this.straightenPointAngle=0;break;case"getStraightenPointAngle":e.value.obj.angle=this.straightenPointAngle;break;case"reset":this.reset();break;case"triggerShapeChanging":this.triggerShapeChanging(e.value.shapeChangingArgs)}},o.prototype.updateFhdPvtVar=function(){var e=this.parent;e.lowerCanvas&&(this.lowerContext=e.lowerCanvas.getContext("2d")),e.upperCanvas&&(this.upperContext=e.upperCanvas.getContext("2d"))},o.prototype.reset=function(){this.fhdObj={lastWidth:0,lastVelocity:0,time:0,pointX:0,pointY:0},this.isFreehandDrawing=this.isFreehandPointMoved=!1,this.selPoints=[],this.dummyPoints=[],this.freehandDownPoint={x:0,y:0},this.selPointColl={},this.straightenPointAngle=0,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},this.straightenPoint={x:null,y:null,ratioX:null,ratioY:null},this.prevStraightenObj=null},o.prototype.getModuleName=function(){return"freehand-draw"},o.prototype.hoverFhd=function(e,o){var i=this.parent,r=this.upperContext,a=-1;a=this.fhdHovIdx>-1?this.fhdHovIdx:this.fhdSelIdx,i.points=t.extend([],i.pointColl[a].points),this.pointCounter=0;var n,s,l,p,h=i.points.length,d=0,c=0;r.fillStyle=e||i.pointColl[a].strokeColor,r.strokeStyle=r.fillStyle,d=c=this.penStrokeWidth=o||i.pointColl[a].strokeWidth,1===h&&(n=s=l=p=i.points[0],this.startDraw(r,n,s,l,p,d,c));for(var u=0;u<h-3;u++)i.points[u+1]&&i.points[u+2]&&i.points[u+2]&&(n=this.calcCurveCP(i.points[u+0],i.points[u+1],i.points[u+2]).controlPoint2,s=this.calcCurveCP(i.points[u+1],i.points[u+2],i.points[u+3]).controlPoint1,l=0===u?i.points[u]:i.points[u+1],p=i.points[u+2],this.startDraw(r,n,s,l,p,d,c));r.closePath();var v=this.getSqPtFD(a),g=r.lineWidth;r.lineWidth=2,r.strokeStyle=i.themeColl[i.theme].primaryColor,r.beginPath(),r.rect(v.startX,v.startY,v.width,v.height),r.stroke(),r.closePath(),r.lineWidth=g},o.prototype.freehandDownHandler=function(o,i){var r=this.parent;r.lowerCanvas=document.querySelector("#"+r.element.id+"_lowerCanvas"),this.lowerContext=r.lowerCanvas.getContext("2d"),r.upperCanvas=document.querySelector("#"+r.element.id+"_upperCanvas"),this.upperContext=r.upperCanvas.getContext("2d"),this.fhdObj.time=(new Date).getTime(),this.isFreehandDrawing=!0,"mousedown"===o.type?this.freehandDownPoint={x:o.clientX,y:o.clientY}:this.freehandDownPoint={x:o.touches[0].clientX,y:o.touches[0].clientY},this.isFreehandPointMoved=!1,t.EventHandler.add(i,"mousemove touchmove",this.freehandMoveHandler,this);var a={id:"pen_"+(this.currFHDIdx+1),type:e.ShapeType.FreehandDraw,startX:this.freehandDownPoint.x,startY:this.freehandDownPoint.y,strokeColor:r.activeObj.strokeSettings.strokeColor,strokeWidth:this.penStrokeWidth,points:null,index:r.objColl.length+r.freehandCounter+1},n={cancel:!1,action:"draw-start",previousShapeSettings:a,currentShapeSettings:a};this.triggerShapeChanging(n)},o.prototype.freehandUpHandler=function(o,i,r){var a=i.getBoundingClientRect(),n=this.parent;t.EventHandler.remove(i,"mousemove touchmove",this.freehandMoveHandler),0===n.points.length&&("mouseup"===o.type?this.processPoint(o.clientX-a.left,o.clientY-a.top,!0,r):"touchend"===o.type&&o.changedTouches?this.processPoint(o.changedTouches[0].clientX-a.left,o.changedTouches[0].clientY-a.top,!0,r):this.isFreehandPointMoved||this.processPoint(this.freehandDownPoint.x-a.left,this.freehandDownPoint.y-a.top,!0,r)),r.closePath();var s=t.extend({},n.cropObj,{},!0),l={currObj:{}};n.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:l}});var p=l.currObj;p.objColl=t.extend([],n.objColl,[],!0),p.pointColl=t.extend([],n.pointColl,[],!0),p.afterCropActions=t.extend([],n.afterCropActions,[],!0);var h={selPointColl:null};n.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:h}}),p.selPointColl=t.extend([],h.selPointColl,[],!0);var d=n.freehandCounter,c=n.objColl.length+n.freehandCounter+1;n.pointColl[d]={points:t.extend([],n.points),strokeColor:n.activeObj.strokeSettings.strokeColor,strokeWidth:this.penStrokeWidth,flipState:n.transform.currFlipState,id:"pen_"+(this.currFHDIdx+1),order:c},n.points=[],this.dummyPoints=[],this.selPointColl[d]={points:t.extend([],this.selPoints)},this.selPoints=[],this.pointCounter=0,n.freehandCounter++,this.isFreehandDrawing=!1,n.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"freehand-draw",previousObj:p,previousObjColl:p.objColl,previousPointColl:p.pointColl,previousSelPointColl:p.selPointColl,previousCropObj:s,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}});var u={id:"pen_"+(this.currFHDIdx+1),type:e.ShapeType.FreehandDraw,startX:this.freehandDownPoint.x,startY:this.freehandDownPoint.y,strokeColor:n.activeObj.strokeSettings.strokeColor,strokeWidth:this.penStrokeWidth,points:n.pointColl[this.currFHDIdx].points,index:c},v={cancel:!1,action:"draw-end",previousShapeSettings:u,currentShapeSettings:u};this.triggerShapeChanging(v),this.currFHDIdx++},o.prototype.freehandMoveHandler=function(e){this.isFreehandPointMoved=!0;var t,o,i=this.parent.upperCanvas.getBoundingClientRect();"mousemove"===e.type?(t=e.clientX-i.left,o=e.clientY-i.top):(t=e.touches[0].clientX-i.left,o=e.touches[0].clientY-i.top),this.isFreehandDrawing&&(this.upperContext.fillStyle=this.parent.activeObj.strokeSettings.strokeColor,this.processPoint(t,o,!1,this.upperContext))},o.prototype.processPoint=function(e,o,i,r){var a,n,s,l,p=this.parent,h=this.point(e,o,(new Date).getTime()),d=!!(h=p.points.length>0&&p.points[p.points.length-1])&&this.distanceTo(h)<=5;if(this.selPoints.push({x:e,y:o,ratioX:(e-p.img.destLeft)/p.img.destWidth,ratioY:(o-p.img.destTop)/p.img.destHeight,time:this.fhdObj.time}),!h||!h||!d||i){if(this.fhdObj.time=(new Date).getTime(),p.points.push({x:e,y:o,ratioX:(e-p.img.destLeft)/p.img.destWidth,ratioY:(o-p.img.destTop)/p.img.destHeight,time:this.fhdObj.time}),this.dummyPoints.push({x:e,y:o,ratioX:(e-p.img.destLeft)/p.img.destWidth,ratioY:(o-p.img.destTop)/p.img.destHeight,time:this.fhdObj.time}),this.dummyPoints.length>2){3===this.dummyPoints.length&&this.dummyPoints.unshift(this.dummyPoints[0]);var c=this.dummyPoints[0],u=this.dummyPoints[1],v=this.dummyPoints[2],g=this.dummyPoints[3];a=this.calcCurveCP(c,u,v).controlPoint2,n=this.calcCurveCP(u,v,g).controlPoint1,s=this.dummyPoints[1],l=this.dummyPoints[2];var f=.5,C=5;t.isNullOrUndefined(this.penStrokeWidth)||(f=C=this.penStrokeWidth),this.startDraw(r,a,n,s,l,f,C),this.pointCounter++,this.dummyPoints.shift()}if(i){a=n=s=l={x:e,y:o,time:(new Date).getTime()};var f=.5,C=5;t.isNullOrUndefined(this.penStrokeWidth)||(f=C=this.penStrokeWidth),this.startDraw(r,a,n,s,l,f,C)}}},o.prototype.calcCurveCP=function(e,t,o){t||(t=e),o||(o=t);var i=e.x-t.x,r=e.y-t.y,a=t.x-o.x,n=t.y-o.y,s={x:(e.x+t.x)/2,y:(e.y+t.y)/2},l={x:(t.x+o.x)/2,y:(t.y+o.y)/2},p=Math.sqrt(i*i+r*r),h=Math.sqrt(a*a+n*n),d=s.x-l.x,c=s.y-l.y,u=h/(p+h),v={x:l.x+d*u,y:l.y+c*u},g=t.x-v.x,f=t.y-v.y;return{controlPoint1:this.point(s.x+g,s.y+f,0),controlPoint2:this.point(l.x+g,l.y+f,0)}},o.prototype.point=function(e,t,o){return this.fhdObj.pointX=e,this.fhdObj.pointY=t,{x:this.fhdObj.pointX,y:this.fhdObj.pointY,time:o}},o.prototype.startDraw=function(e,t,o,i,r,a,n){var s;s=.7*(s=this.pointVelocity(i))+(1-.7)*this.fhdObj.lastVelocity;var l=Math.max(n/1.7,a);this.drawCurve(this.fhdObj.time,l,e,t,o,i,r,n),this.fhdObj.lastVelocity=s,this.fhdObj.time=l},o.prototype.pointVelocity=function(e){return this.fhdObj.time!==e.time?this.distanceTo(e)/(this.fhdObj.time-e.time):0},o.prototype.distanceTo=function(e){return Math.sqrt(Math.pow(this.fhdObj.pointX-e.x,2)+Math.pow(this.fhdObj.pointY-e.y,2))},o.prototype.drawCurve=function(e,t,o,i,r,a,n,s){var l,p,h,d,c,u,v,g,f,C,b=t-e,m=this.bezierLength(i,r,a,n),y=2*Math.ceil(m);for(o.beginPath(),p=0;p<y;p++)c=(d=(h=p/y)*h)*h,f=(g=(v=(u=1-h)*u)*u)*a.x,f+=3*v*h*i.x,f+=3*u*d*r.x,f+=c*n.x,C=g*a.y,C+=3*v*h*i.y,C+=3*u*d*r.y,C+=c*n.y,l=Math.min(e+c*b,s),this.drawArc(f,C,l,o);o.closePath(),o.fill()},o.prototype.bezierLength=function(e,t,o,i){var r,a,n,s,l,p,h,d,c=0;for(r=0;r<=10;r++)a=r/10,n=this.bezierPoint(a,o.x,e.x,t.x,i.x),s=this.bezierPoint(a,o.y,e.y,t.y,i.y),r>0&&(h=n-l,d=s-p,c+=Math.sqrt(h*h+d*d)),l=n,p=s;return c},o.prototype.bezierPoint=function(e,t,o,i,r){return t*(1-e)*(1-e)*(1-e)+3*o*(1-e)*(1-e)*e+3*i*(1-e)*e*e+r*e*e*e},o.prototype.drawArc=function(e,t,o,i){var r=this.parent.img;(e>r.destLeft&&t>r.destTop&&e<r.destLeft+r.destWidth&&t<r.destTop+r.destHeight||i!==this.lowerContext&&i!==this.upperContext)&&(i.moveTo(e,t),i.arc(e,t,o,0,2*Math.PI,!1))},o.prototype.freehandRedraw=function(e,o){var i=this.parent,r=e.filter;if(e.filter="none",o&&(i.pointColl[i.freehandCounter]={points:o,strokeColor:i.activeObj.strokeSettings.strokeColor,strokeWidth:this.penStrokeWidth,flipState:i.transform.currFlipState,id:"pen_"+(i.freehandCounter+1),order:i.objColl.length+i.freehandCounter+1},this.selPointColl[i.freehandCounter]=t.extend({},i.pointColl[i.freehandCounter],{},!0),i.freehandCounter++),i.freehandCounter>0){for(var a=0;a<i.freehandCounter;a++){i.points=t.extend([],i.pointColl[a].points),this.pointCounter=0;var n=i.points.length,s=void 0,l=void 0,p=void 0,h=void 0,d=void 0,c=void 0;n>0&&(e.fillStyle=i.pointColl[a].strokeColor,d=c=this.penStrokeWidth=i.pointColl[a].strokeWidth),1===n&&(s=l=p=h=i.points[0],this.startDraw(e,s,l,p,h,d,c));for(var u=0;u<n-3;u++)i.points[u+1]&&i.points[u+2]&&i.points[u+2]&&(s=this.calcCurveCP(i.points[u+0],i.points[u+1],i.points[u+2]).controlPoint2,l=this.calcCurveCP(i.points[u+1],i.points[u+2],i.points[u+3]).controlPoint1,p=0===u?i.points[u]:i.points[u+1],h=i.points[u+2],this.startDraw(e,s,l,p,h,d,c));e.closePath()}e===this.lowerContext&&(i.notify("draw",{prop:"applyFrame",value:{ctx:this.lowerContext,frame:i.frameObj.type,preventImg:!0}}),this.upperContext.clearRect(0,0,i.upperCanvas.width,i.upperCanvas.height))}e.filter=r},o.prototype.getSqPtFD=function(e,o){var i={startX:0,startY:0,endX:0,endY:0,width:0,height:0},r=t.extend([],this.selPointColl[e].points,[]);this.parent.points=t.extend([],this.parent.pointColl[e].points),this.pointCounter=0;for(var a=r.length,n=0;n<a;n++)0===i.startX&&0===i.startY&&0===i.endX&&0===i.endY?(i.startX=r[n].x,i.startY=r[n].y,i.endX=r[n].x,i.endY=r[n].y):(i.startX=Math.min(i.startX,r[n].x),i.startY=Math.min(i.startY,r[n].y),i.endX=Math.max(i.endX,r[n].x),i.endY=Math.max(i.endY,r[n].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,o&&(o.activePoint=i),i},o.prototype.applyPenDraw=function(){var e=this.parent;"freehanddraw"===e.currObjType.shape&&(e.notify("shape",{prop:"apply",onPropertyChange:!1,value:{shape:null,obj:null,canvas:null}}),e.upperCanvas.style.cursor=e.cursor="default",e.currObjType.shape=""),e.notify("shape",{prop:"clearActObj"})},o.prototype.applyFhd=function(){var e=this.parent,t=e.pointColl[this.fhdSelIdx];"#42a5f5"===t.strokeColor&&(t.strokeColor=this.tempFHDStyles.strokeColor),e.notify("toolbar",{prop:"setSelectedFreehandColor",value:{color:"#42a5f5"}}),this.upperContext.clearRect(0,0,e.upperCanvas.width,e.upperCanvas.height),this.lowerContext.clearRect(0,0,e.lowerCanvas.width,e.lowerCanvas.height),e.notify("draw",{prop:"render-image",value:{isMouseWheel:null}}),e.notify("toolbar",{prop:"refresh-main-toolbar",onPropertyChange:!1}),t&&(t.isSelected=!1),e.notify("selection",{prop:"resetFreehandDrawVariables"}),this.fhdHovIdx=this.fhdSelIdx=null},o.prototype.cancelFhd=function(){var e=this.parent,t=e.pointColl[this.fhdSelIdx];e.notify("toolbar",{prop:"setSelectedFreehandColor",value:{color:"#42a5f5"}}),this.upperContext.clearRect(0,0,e.upperCanvas.width,e.upperCanvas.height),this.lowerContext.clearRect(0,0,e.upperCanvas.width,e.upperCanvas.height),this.pointCounter=0,t&&(t.strokeColor=this.tempFHDStyles.strokeColor,t.strokeWidth=this.tempFHDStyles.strokeWidth,t.isSelected=!1),this.fhdHovIdx=this.fhdSelIdx=this.fhdSelID=null,e.notify("selection",{prop:"resetFreehandDrawVariables"}),e.activeObj.strokeSettings.strokeColor=this.tempFHDStyles.strokeColor,e.activeObj.strokeSettings.strokeWidth=this.penStrokeWidth=this.tempFHDStyles.strokeWidth,this.tempFHDStyles={strokeColor:null,strokeWidth:null,fillColor:null},e.notify("draw",{prop:"render-image",value:{isMouseWheel:null}}),e.notify("toolbar",{prop:"refresh-main-toolbar",onPropertyChange:!1})},o.prototype.selectFhd=function(o){var i=this.parent,r=t.extend({},this.tempFHDStyles,{},!0);if(i.notify("selection",{prop:"setFreehandDrawEditing",onPropertyChange:!1,value:{bool:!0}}),o||0===o){if(!this.isFHDIdx(o))return;this.fhdSelIdx=this.fhdHovIdx=o,this.hoverFhd(),i.upperCanvas.style.cursor=i.cursor="pointer"}this.fhdSelIdx=this.fhdHovIdx;var a=i.pointColl[this.fhdSelIdx];a.isSelected=!0,this.fhdSelID=a.id,"#42a5f5"!==a.strokeColor&&(i.activeObj.strokeSettings.strokeColor=this.tempFHDStyles.strokeColor=a.strokeColor),i.activeObj.strokeSettings.strokeWidth=this.tempFHDStyles.strokeWidth=i.pointColl[this.fhdHovIdx].strokeWidth;var n={bool:!1};if(i.notify("selection",{prop:"getFreehandDrawEditing",onPropertyChange:!1,value:{obj:n}}),n.bool){var s={id:"pen_"+(this.fhdSelIdx+1),type:e.ShapeType.FreehandDraw,startX:a.points[0].x,startY:a.points[0].y,strokeColor:a.strokeColor,strokeWidth:a.strokeWidth,points:a.points,opacity:a.opacity,index:a.order},l={cancel:!1,action:"select",previousShapeSettings:s,currentShapeSettings:s};this.triggerShapeChanging(l)}else i.okBtn(null,!0);i.isUndoRedoStack&&(this.tempFHDStyles=r)},o.prototype.deleteFhd=function(e,o){var i=this.parent;if(this.isFHDIdx(e)){this.upperContext.clearRect(0,0,i.upperCanvas.width,i.upperCanvas.height);var r=t.extend({},i.pointColl,{},!0),a=t.extend({},this.selPointColl,{},!0);i.pointColl={},this.selPointColl={};var n=0;if(t.isNullOrUndefined(o))for(s=0;s<i.freehandCounter;s++)s!==e&&(i.pointColl[n]=r[s],this.selPointColl[n]=a[s],n++);else for(var s=0;s<i.freehandCounter;s++)parseInt(r[s].id.split("_")[1],10)-1!==e&&(i.pointColl[n]=r[s],this.selPointColl[n]=a[s],n++);i.freehandCounter-=1,this.fhdHovIdx=this.fhdSelIdx=null,i.notify("selection",{prop:"resetFreehandDrawVariables"}),i.notify("draw",{prop:"render-image",value:{isMouseWheel:null}}),i.notify("toolbar",{prop:"refresh-main-toolbar",onPropertyChange:!1})}},o.prototype.zoomX=function(e){return e*this.parent.img.destWidth+this.parent.img.destLeft},o.prototype.zoomY=function(e){return e*this.parent.img.destHeight+this.parent.img.destTop},o.prototype.zoomFHDColl=function(e){var o=this.parent,i={startX:o.img.destLeft,startY:o.img.destTop,width:o.img.destWidth,height:o.img.destHeight};o.notify("shape",{prop:"straightenShapes",onPropertyChange:!1});for(var r=0;r<o.freehandCounter;r++){o.points=t.extend([],o.pointColl[r].points,[]),this.pointCounter=0;for(var a=o.points.length,n=0;n<a;n++){var s=o.points[n];s.x=this.zoomX(s.ratioX),s.y=this.zoomY(s.ratioY)}}this.updateFHDCurPts(),this.straightenPoint.x&&this.straightenPoint.y&&(this.straightenPoint.x=this.zoomX(this.straightenPoint.ratioX),this.straightenPoint.y=this.zoomY(this.straightenPoint.ratioY)),0!==o.transform.straighten&&o.notify("shape",{prop:"straightenFHD",onPropertyChange:!1}),o.img.destLeft=i.startX,o.img.destTop=i.startY,o.img.destWidth=i.width,o.img.destHeight=i.height,t.isNullOrUndefined(e)&&this.freehandRedraw(this.lowerContext,null)},o.prototype.updateFHDCurPts=function(){for(var e=this.parent,o=0;o<e.freehandCounter;o++)if(this.selPointColl[o]){this.selPoints=t.extend([],this.selPointColl[o].points,[]),this.pointCounter=0;for(var i=this.selPoints.length,r=0;r<i;r++){var a=this.selPoints[r];a.x=this.zoomX(a.ratioX),a.y=this.zoomY(a.ratioY)}}},o.prototype.rotateFhdColl=function(){for(var e=this.parent,o=e.img,i=o.destLeft,r=o.destTop,a=o.destWidth,n=o.destHeight,s=0;s<e.freehandCounter;s++){e.points=t.extend([],e.pointColl[s].points,[]),this.pointCounter=0;for(var l=e.points.length,p=0;p<l;p++)(h=e.points[p]).y=r+n*h.ratioX,h.x=i+a-a*h.ratioY,h.ratioX=(h.x-i)/a,h.ratioY=(h.y-r)/n}for(s=0;s<e.freehandCounter;s++)if(this.selPointColl[s]){this.selPoints=t.extend([],this.selPointColl[s].points,[]),this.pointCounter=0;for(var l=this.selPoints.length,p=0;p<l;p++){var h=this.selPoints[p];h.y=r+n*h.ratioX,h.x=i+a-a*h.ratioY,h.ratioX=(h.x-i)/a,h.ratioY=(h.y-r)/n}}this.updateFHDCurPts()},o.prototype.flipFHDColl=function(e){var t=e.toLowerCase();if("horizontal"===t)this.pointsHorizontalFlip();else if("vertical"===t)this.pointsVerticalFlip();else{this.pointsHorizontalFlip();for(var o=0;o<this.parent.freehandCounter;o++)this.parent.pointColl[o].shapeFlip="";this.pointsVerticalFlip()}},o.prototype.pointsHorizontalFlip=function(){for(var e=this.parent,o=e.img,i=o.destLeft,r=o.destTop,a=o.destWidth,n=o.destHeight,s=0;s<e.freehandCounter;s++)if(e.pointColl[s].shapeFlip!==e.transform.currFlipState){e.points=t.extend([],e.pointColl[s].points,[]),this.pointCounter=0;for(var l=e.points.length,p=0;p<l;p++)(h=e.points[p]).x<=i+a/2?h.x=i+a-(h.x-i):h.x>=i+a/2&&(h.x=i+(i+a-h.x)),h.ratioX=(h.x-i)/a,h.ratioY=(h.y-r)/n;e.pointColl[s].shapeFlip=e.transform.currFlipState}for(s=0;s<e.freehandCounter;s++)if(this.selPointColl[s]&&this.selPointColl[s].shapeFlip!==e.transform.currFlipState){this.selPoints=t.extend([],this.selPointColl[s].points,[]),this.pointCounter=0;for(var l=this.selPoints.length,p=0;p<l;p++){var h=this.selPoints[p];h.x<=i+a/2?h.x=i+a-(h.x-i):h.x>=i+a/2&&(h.x=i+(i+a-h.x)),h.ratioX=(h.x-i)/a,h.ratioY=(h.y-r)/n}}this.updateFHDCurPts()},o.prototype.pointsVerticalFlip=function(){for(var e=this.parent,o=e.img,i=o.destLeft,r=o.destTop,a=o.destWidth,n=o.destHeight,s=0;s<e.freehandCounter;s++)if(e.pointColl[s].shapeFlip!==e.transform.currFlipState){e.points=t.extend([],e.pointColl[s].points,[]),this.pointCounter=0;for(var l=e.points.length,p=0;p<l;p++)(h=e.points[p]).y<=r+n/2?h.y=r+n-(h.y-r):h.y>=r+n/2&&(h.y=r+(r+n-h.y)),h.ratioX=(h.x-i)/a,h.ratioY=(h.y-r)/n;e.pointColl[s].shapeFlip=e.transform.currFlipState}for(s=0;s<e.freehandCounter;s++)if(this.selPointColl[s]&&this.selPointColl[s].shapeFlip!==e.transform.currFlipState){this.selPoints=t.extend([],this.selPointColl[s].points,[]),this.pointCounter=0;for(var l=this.selPoints.length,p=0;p<l;p++){var h=this.selPoints[p];h.y<=r+n/2?h.y=r+n-(h.y-r):h.y>=r+n/2&&(h.y=r+(r+n-h.y)),h.ratioX=(h.x-i)/a,h.ratioY=(h.y-r)/n}}this.updateFHDCurPts()},o.prototype.updateFHDColl=function(e){var o=this.parent,i={startX:o.img.destLeft,startY:o.img.destTop,width:o.img.destWidth,height:o.img.destHeight};o.notify("shape",{prop:"straightenShapes",onPropertyChange:!1});for(var r=o.img,a=r.destLeft,n=r.destTop,s=r.destWidth,l=r.destHeight,p=0,h=o.objColl.length;p<h;p++){var d=o.objColl[p];if("line"===d.shape||"arrow"===d.shape)o.notify("shape",{prop:"straightenShapePoints",value:{obj:d,isReverse:!0}});else if("path"===d.shape){v=o.transform.straighten;o.transform.straighten=-o.transform.straighten,o.notify("shape",{prop:"straightenPath",onPropertyChange:!1,value:{obj:d}}),o.transform.straighten=v}if(d.imageRatio={startX:(d.activePoint.startX-a)/s,startY:(d.activePoint.startY-n)/l,endX:(d.activePoint.endX-a)/s,endY:(d.activePoint.endY-n)/l,width:s/d.activePoint.width,height:l/d.activePoint.height},"path"===d.shape)for(var c=0,u=d.pointColl.length;c<u;c++)d.pointColl[c].ratioX=(d.pointColl[c].x-a)/s,d.pointColl[c].ratioY=(d.pointColl[c].y-n)/l;o.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1})}if(o.freehandCounter>0&&0!==o.transform.straighten){var v=o.transform.straighten;o.transform.straighten=-o.transform.straighten,o.notify("shape",{prop:"straightenFHD",onPropertyChange:!1}),o.transform.straighten=v}for(C=0;C<o.freehandCounter;C++){o.points=t.extend([],o.pointColl[C].points,[]),this.pointCounter=0;for(var g=o.points.length,f=0;f<g;f++)(b=o.points[f]).ratioX=(b.x-a)/s,b.ratioY=(b.y-n)/l}for(var C=0;C<o.freehandCounter;C++)if(this.selPointColl[C]){this.selPoints=t.extend([],this.selPointColl[C].points,[]),this.pointCounter=0;for(var g=this.selPoints.length,f=0;f<g;f++){var b=this.selPoints[f];b.ratioX=(b.x-a)/s,b.ratioY=(b.y-n)/l}}this.straightenPoint.x&&this.straightenPoint.y&&(this.straightenPoint.ratioX=(this.straightenPoint.x-a)/s,this.straightenPoint.ratioY=(this.straightenPoint.y-n)/l),o.img.destLeft=i.startX,o.img.destTop=i.startY,o.img.destWidth=i.width,o.img.destHeight=i.height,o.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"zoom",pen:"zoom",isPreventApply:e}})},o.prototype.panFHDColl=function(e,o,i){for(var r=this.parent,a=0;a<r.freehandCounter;a++){r.points=t.extend([],r.pointColl[a].points,[]),this.pointCounter=0;for(var n=r.points.length,s=0;s<n;s++){l=r.points[s];""===i||"vertical"===i?l.x+=e:l.x-=e,""===i||"horizontal"===i?l.y+=o:l.y-=o}}for(a=0;a<r.freehandCounter;a++)if(this.selPointColl[a]){this.selPoints=t.extend([],this.selPointColl[a].points,[]),this.pointCounter=0;for(var n=this.selPoints.length,s=0;s<n;s++){var l=this.selPoints[s];""===i||"vertical"===i?l.x+=e:l.x-=e,""===i||"horizontal"===i?l.y+=o:l.y-=o}}this.straightenPoint.x&&this.straightenPoint.y&&(""===i||"vertical"===i?this.straightenPoint.x+=e:this.straightenPoint.x-=e,""===i||"horizontal"===i?this.straightenPoint.y+=o:this.straightenPoint.y-=o),this.freehandRedraw(this.lowerContext,null)},o.prototype.freeHandDraw=function(e){var o=this.parent;if(e){if(o.points=[],this.dummyPoints=[],o.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),o.togglePen=!0,o.upperCanvas.style.cursor=o.cursor="crosshair",o.upperCanvas.style.display="block",t.isNullOrUndefined(o.activeObj.strokeSettings)){var i={strokeSettings:{}};o.notify("shape",{prop:"getStrokeSettings",onPropertyChange:!1,value:{obj:i}}),o.activeObj.strokeSettings=i.strokeSettings}t.isNullOrUndefined(o.activeObj.strokeSettings.strokeWidth)&&(o.activeObj.strokeSettings.strokeWidth=2),o.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"pen",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}})}else{o.upperCanvas.style.cursor=o.cursor="default";var r=this.penStrokeWidth;o.notify("shape",{prop:"apply",onPropertyChange:!1,value:{shape:null,obj:null,canvas:null}}),o.notify("toolbar",{prop:"refresh-main-toolbar",onPropertyChange:!1}),o.notify("toolbar",{prop:"setCurrentToolbar",value:{type:"main"}}),o.notify("selection",{prop:"setFreehandDrawCustomized",value:{isFreehandDrawCustomized:!1}}),this.penStrokeWidth=r}},o.prototype.isFHDIdx=function(e,t){for(var o=!1,i=0;i<this.parent.freehandCounter;i++)if(this.parent.pointColl[i].id&&parseInt(this.parent.pointColl[i].id.split("_")[1],10)-1===e){o=!0;break}return t&&(t.isIndex=o),o},o.prototype.updateCropPtsForSel=function(){for(var e=this.parent,o=e.activeObj.activePoint,i=0;i<e.freehandCounter;i++){var r={selPointColl:t.extend([],this.selPointColl)};if(r.selPointColl[i]){this.selPoints=t.extend([],r.selPointColl[i].points,[]),this.pointCounter=0;for(var a=this.selPoints.length,n=0;n<a;n++){var s=this.selPoints[n];s.ratioX=(s.x-o.startX)/o.width,s.ratioY=(s.y-o.startY)/o.height}}}},o.prototype.triggerShapeChanging=function(e){var t=this.parent,o=t.pointColl[this.fhdSelIdx];if(t.trigger("shapeChanging",e),-1===e.currentShapeSettings.id.indexOf("pen_")&&("draw-end"===e.action||"select"===e.action)){var i="pen_"+e.currentShapeSettings.id;this.fhdSelIdx?t.pointColl[this.fhdSelIdx].id=i:t.pointColl[t.freehandCounter-1].id=i}this.penStrokeWidth=e.currentShapeSettings.strokeWidth,t.activeObj.strokeSettings.strokeColor!==e.currentShapeSettings.strokeColor&&(t.activeObj.strokeSettings.strokeColor=e.currentShapeSettings.strokeColor,t.notify("toolbar",{prop:"update-toolbar-items",onPropertyChange:!1})),this.fhdSelID&&o&&e.currentShapeSettings&&(o.strokeColor=e.currentShapeSettings.strokeColor,o.strokeWidth=e.currentShapeSettings.strokeWidth,o.points=e.currentShapeSettings.points,o.opacity=e.currentShapeSettings.opacity),"select"===e.action&&(this.freehandRedraw(this.upperContext),t.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"pen",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}}))},o.prototype.setCenterSelPoints=function(){var e=this.parent,o={startX:e.img.destLeft,startY:e.img.destTop,width:e.img.destWidth,height:e.img.destHeight};e.notify("shape",{prop:"straightenShapes",onPropertyChange:!1});var i=e.img,r=i.destLeft,a=i.destTop,n=i.destWidth,s=i.destHeight,l=e.activeObj.activePoint;(t.isNullOrUndefined(this.prevStraightenObj)||JSON.stringify(this.prevStraightenObj.activePoint)!==JSON.stringify(l))&&(this.straightenPoint={x:l.startX+l.width/2,y:l.startY+l.height/2,ratioX:(l.startX+l.width/2-r)/n,ratioY:(l.startY+l.height/2-a)/s},this.prevStraightenObj=t.extend({},e.activeObj,{},!0),this.straightenPointAngle=e.transform.straighten),e.img.destLeft=o.startX,e.img.destTop=o.startY,e.img.destWidth=o.width,e.img.destHeight=o.height},o}(),v=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:[],order:null},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.isImageClarity=!0,this.isPinching=!1,this.isSliding=!1,this.mouseDown="",this.isSliderActive=!1,this.arrowShape=[e.ArrowheadType.None,e.ArrowheadType.SolidArrow],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(e){var t=this.parent;switch(this.updatePrivateVariables(),e.prop){case"setCursor":this.setCursor(e.value.x,e.value.y);break;case"updateActivePoint":this.updateActivePoint(e.value.x,e.value.y,e.value.isCropSelection);break;case"updateCursorStyles":this.updateCursorStyles(e.value.x,e.value.y,e.value.type);break;case"setTextSelection":this.setTextSelection(e.value.width,e.value.height);break;case"setActivePoint":this.setActivePoint(e.value.startX,e.value.startY);break;case"clearSelection":this.clearSelection(e.value.resetCrop);break;case"calcShapeRatio":this.calcShapeRatio(e.value.x,e.value.y,e.value.imgWidth,e.value.imgHeight);break;case"tab":this.performTabAction();break;case"setDragDirection":this.setDragDirection(e.value.width,e.value.height);break;case"clearUpperCanvas":this.isTouch&&setTimeout(function(){t.upperCanvas.getContext("2d").clearRect(0,0,t.upperCanvas.width,t.upperCanvas.height)},550);break;case"resetFreehandDrawVariables":this.isFhdEditing=this.isFhdPoint=!1;break;case"isShapeInserted":this.isShapeInserted=e.value.bool;break;case"redrawShape":this.redrawShape(e.value.obj);break;case"setTextBoxStylesToActObj":this.setTextBoxStylesToActObj();break;case"mouseDownEventHandler":this.mouseDownEventHandler(e.value.e);break;case"mouseMoveEventHandler":this.mouseMoveEventHandler(e.value.e);break;case"mouseUpEventHandler":this.mouseUpEventHandler(e.value.e);break;case"canvasMouseDownHandler":this.canvasMouseDownHandler(e.value.e);break;case"canvasMouseMoveHandler":this.canvasMouseMoveHandler(e.value.e);break;case"canvasMouseUpHandler":this.canvasMouseUpHandler(e.value.e);break;case"touchStartHandler":this.touchStartHandler(e.value.e);break;case"keyDownEventHandler":this.keyDownEventHandler(e.value.e);break;case"handleScroll":this.handleScroll(e.value.e);break;case"textKeyDown":setTimeout(this.textKeyDown.bind(this),1,e.value.e);break;case"deleteItem":this.deleteItem();break;case"updatePrevShapeSettings":this.updatePrevShapeSettings(e.value.obj);break;case"getZoomType":e.value.obj.zoomType=this.zoomType;break;case"setZoomType":this.zoomType=e.value.zoomType;break;case"setInitialTextEdit":this.isInitialTextEdited=e.value.bool;break;case"setDragCanvas":this.dragCanvas=e.value.bool;break;case"setFreehandDrawCustomized":this.isFhdCustomized=e.value.isFreehandDrawCustomized;break;case"setTouchEndPoint":this.touchEndPoint.x=e.value.x,this.touchEndPoint.y=e.value.y;break;case"getPanDown":e.value.obj.panDown=this.panDown;break;case"setPanDown":this.panDown=e.value.panDown;break;case"getFreehandDrawEditing":e.value.obj.bool=this.isFhdEditing;break;case"setFreehandDrawEditing":this.isFhdEditing=e.value.bool;break;case"getTempActObj":e.value.obj.tempObj=this.tempActiveObj;break;case"setTempActObj":this.tempActiveObj=e.value.obj;break;case"isInside":this.isInside(e.value.x,e.value.y,e.value.z1,e.value.z2,e.value.z3,e.value.z4);break;case"setDragElement":this.dragElement=e.value.value;break;case"setObjSelected":this.isObjSelected=e.value.bool;break;case"adjustActObjForLineArrow":this.adjustActObjForLineArrow(e.value.obj);break;case"findTarget":this.findTarget(e.value.x,e.value.y,e.value.type);break;case"getCurrentFlipState":this.getCurrentFlipState();break;case"setDragWidth":this.setDragWidth(e.value.width);break;case"setDragHeight":this.setDragHeight(e.value.setDragHeight);break;case"annotate":this.currentDrawingShape=e.value.shape,"text"===e.value.shape?(t.activeObj.textSettings.fontSize=11,t.activeObj.keyHistory="Enter Text",t.notify("shape",{prop:"initializeTextShape",onPropertyChange:!1,value:{text:null,fontFamily:null,fontSize:null,bold:null,italic:null,strokeColor:null}})):"path"===e.value.shape&&(t.activeObj.pointColl=[]);break;case"getCurrentDrawingShape":e.value.obj.shape=this.currentDrawingShape;break;case"setCurrentDrawingShape":this.currentDrawingShape=e.value.value;break;case"getTransRotationPoint":this.getTransRotationPoint(e.value.obj,e.value.object);break;case"adjustNEPoints":this.adjustNEPoints(e.value.rectangle,e.value.x,e.value.y,e.value.angle);break;case"adjustRotationPoints":this.adjustRotationPoints(e.value.rectangle,e.value.x,e.value.y,e.value.angle,e.value.type,e.value.elem);break;case"getResizeDirection":this.getResizeDirection(e.value.rectangle,e.value.x,e.value.y,e.value.angle);break;case"setResizedElement":this.resizedElement=e.value.value;break;case"reset":this.reset();break;case"unWireEvent":this.unwireEvent();break;case"updPtCollForShpRot":this.updPtCollForShpRot(e.value.obj);break;case"findImageRatio":this.findImageRatio(e.value.width,e.value.height,e.value.obj);break;case"getNumTextValue":this.getNumTextValue(e.value.obj);break;case"setImageClarity":this.isImageClarity=e.value.bool;break;case"upgradeImageQuality":this.upgradeImageQuality();break;case"triggerShapeChange":this.triggerShapeChange(e.value.shapeResizingArgs,e.value.shapeMovingArgs,e.value.type);break;case"applyTransformToImg":this.applyTransformToImg(e.value.ctx);break;case"findTargetObj":e.value.obj.bool=this.findTargetObj(e.value.x,e.value.y,e.value.isCrop);break;case"setSliding":this.isSliding=e.value.bool;break;case"setSliderActive":this.isSliderActive=e.value.bool;break;case"getArrowType":e.value.obj.type=this.getArrowType(e.value.type);break;case"setArrowShape":"initial"===e.value.type?this.arrowShape[0]=e.value.shape:this.arrowShape[1]=e.value.shape;break;case"updateNWPoints":this.updateNWPoints(e.value.x,e.value.y);break;case"updateNPoints":this.updateNPoints(e.value.x,e.value.y);break;case"updateNEPoints":this.updateNEPoints(e.value.x,e.value.y);break;case"updateWPoints":this.updateWPoints(e.value.x,e.value.y);break;case"updateEPoints":this.updateEPoints(e.value.x,e.value.y);break;case"updateSWPoints":this.updateSWPoints(e.value.x,e.value.y);break;case"updateSPoints":this.updateSPoints(e.value.x,e.value.y);break;case"updateSEPoints":this.updateSEPoints(e.value.x,e.value.y)}},o.prototype.getModuleName=function(){return"selection"},o.prototype.updatePrivateVariables=function(){var e=this.parent;e.lowerCanvas&&(this.lowerContext=e.lowerCanvas.getContext("2d")),e.upperCanvas&&(this.upperContext=e.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:[],order:null},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=this.isPinching=!1,this.isFhdCustomized=!1,this.touchEndPoint={},this.panDown=null,this.isSliding=!1,this.isFhdEditing=!1,this.pathAdjustedIndex=null,this.touchTime=0,this.isImageClarity=!0,this.currentDrawingShape="",this.initialPrevObj={},this.resizedElement="",this.mouseDown="",this.isSliderActive=!1,this.arrowShape=[e.ArrowheadType.None,e.ArrowheadType.SolidArrow]},o.prototype.performTabAction=function(){var e=this.parent;if("block"===e.textArea.style.display||"inline-block"===e.textArea.style.display){var t=this.applyCurrShape(!1);e.notify("shape",{prop:"redrawActObj",onPropertyChange:!1,value:{x:null,y:null,isMouseDown:null}}),t&&e.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"ok"}})}e.isKBDNavigation=!0},o.prototype.selMouseUpEvent=function(){this.oldPoint.x=void 0,this.oldPoint.y=void 0},o.prototype.getMouseCursor=function(e,t,o,i,r){var a=this.getTransRotationPoint(e),n=e.bottomCenterCircle.radius,s=r?0:2*e.topLeftCircle.radius;return t>=e.topLeftCircle.startX-s&&t<=e.topLeftCircle.startX+s&&o>=e.topLeftCircle.startY-s&&o<=e.topLeftCircle.startY+s?"nw-resize":t>=e.topLeftCircle.startX-s&&t<=e.topRightCircle.startX-s&&o>=e.topCenterCircle.startY-s&&o<=e.topCenterCircle.startY+s?"n-resize":t>=e.topRightCircle.startX-s&&t<=e.topRightCircle.startX+s&&o>=e.topRightCircle.startY-s&&o<=e.topRightCircle.startY+s?"ne-resize":t>=e.centerLeftCircle.startX-s&&t<=e.centerLeftCircle.startX+s&&o>=e.topLeftCircle.startY-s&&o<=e.bottomLeftCircle.startY-s?"w-resize":t>=e.centerRightCircle.startX-s&&t<=e.centerRightCircle.startX+s&&o>=e.topRightCircle.startY-s&&o<=e.bottomRightCircle.startY-s?"e-resize":t>=e.bottomLeftCircle.startX-s&&t<=e.bottomLeftCircle.startX+s&&o>=e.bottomLeftCircle.startY-s&&o<=e.bottomLeftCircle.startY+s?"sw-resize":t>=e.bottomLeftCircle.startX-s&&t<=e.bottomRightCircle.startX-s&&o>=e.bottomCenterCircle.startY-s&&o<=e.bottomCenterCircle.startY+s?"s-resize":t>=e.bottomRightCircle.startX-s&&t<=e.bottomRightCircle.startX+s&&o>=e.bottomRightCircle.startY-s&&o<=e.bottomRightCircle.startY+s?"se-resize":t>=e.activePoint.startX&&t<=e.activePoint.endX&&o>=e.activePoint.startY&&o<=e.activePoint.endY?i?"grab":"move":a&&!r&&t>=a.x-(n+2)&&t<=a.x+(n+2)&&o>=a.y-(n+2)&&o<=a.y+(n+2)?"grabbing":"default"},o.prototype.setCursor=function(e,o){var i=this.parent;i.upperCanvas.style.cursor=i.cursor="default";var r={bool:null};if(i.notify("toolbar",{prop:"getFrameToolbar",onPropertyChange:!1,value:{obj:r}}),i.isResize||this.isSliding||r.bool)return void(i.upperCanvas.style.cursor="default");if(i.currObjType.isDragging)return void(""===this.dragElement?i.upperCanvas.style.cursor=i.cursor="move":i.upperCanvas.style.cursor=i.cursor=this.dragElement);if(i.togglePen)return void(i.upperCanvas.style.cursor=i.cursor="crosshair");if(i.activeObj.shape&&this.setCursorForActObj(void 0,!1,e,o),"default"===i.cursor||"grab"===i.cursor){for(var a=this.getHighestOrder(),n=t.extend([],i.shapeColl,[],!0),s=t.extend([],i.objColl,[],!0),l=!1;a>0;){l=!1;for(var p=n.length-1;p>=0;p--)if(n[p].order===a)if(l=!0,n[p].id&&n[p].id.indexOf("pen")>-1){if(i.pointColl[0]&&(i.cursor,!0)&&!i.currObjType.isDragging&&!i.currObjType.isResize){var h=t.extend([],i.points,[],!0);this.setCursorForFreehandDrawing(e,o,i.upperCanvas,n[p].id),i.points=h}}else{i.objColl=[],i.objColl.push(t.extend({},n[p],null,!0));var d=i.upperCanvas.style.cursor;i.objColl.length>0&&(i.cursor,!0)&&this.setCursorFromObj(e,o,i.objColl,i.upperCanvas,!1),"grab"===d&&"default"===i.cursor&&(i.upperCanvas.style.cursor=i.cursor="grab")}else t.isNullOrUndefined(n[p].order)&&(l=!0);if("default"!==i.cursor&&"grab"!==i.cursor)break;if(l)for(var c=!1;!c&&a>0;){for(var u=0;u<n.length;u++)if(n[u].order===a-1){c=!0;break}a--,c||a--}}i.objColl=s,"default"!==i.cursor&&"grab"!==i.cursor||i.togglePan&&(i.lowerCanvas.style.cursor=i.upperCanvas.style.cursor=i.cursor="grab")}""===this.currentDrawingShape||"default"!==i.cursor&&"grab"!==i.cursor||(i.upperCanvas.style.cursor=i.cursor="crosshair")},o.prototype.getHighestOrder=function(){for(var e=0,t=0;t<this.parent.shapeColl.length;t++)this.parent.shapeColl[t].order>e&&(e=this.parent.shapeColl[t].order);return e},o.prototype.setCursorForActObj=function(e,o,i,r){var a=this.parent;if(void 0!==a.activeObj.horTopLine){void 0!==a.activeObj.shape&&(e=a.activeObj.shape.split("-")),void 0===e&&a.currObjType.isCustomCrop?o=!0:void 0!==e&&"crop"===e[0]&&(o=!0),!o&&a.togglePan&&(a.lowerCanvas.style.cursor=a.upperCanvas.style.cursor=a.cursor="grab");var n=a.upperCanvas.style.cursor,s=t.extend({},a.activeObj,{},!0);this.cursorTargetId=s.currIndex;var l=void 0;if((l=0===s.shapeDegree?a.transform.degree:a.transform.degree-s.shapeDegree)<0&&(l=360+l),"line"===s.shape||"arrow"===s.shape)this.setCursorForLineArrow(s,i,r,a.upperCanvas);else if("path"===s.shape)this.setCursorForPath(s,i,r,a.upperCanvas);else if(t.isNullOrUndefined(s.rotatedAngle)||0===s.rotatedAngle){a.upperCanvas.style.cursor=a.cursor=this.getMouseCursor(s,i,r,o,!1);var p=["n-resize","s-resize","e-resize","w-resize"];"text"===s.shape&&p.indexOf(a.cursor)>-1&&(a.upperCanvas.style.cursor=a.cursor="move")}else this.setCursorForRotatedObject(s,i,r,a.upperCanvas);"default"===n&&"default"===a.cursor&&o&&(a.upperCanvas.style.cursor=a.cursor="grab"),"grab"===n&&"default"===a.cursor&&(a.upperCanvas.style.cursor=a.cursor="grab")}else a.togglePan&&!a.togglePen?a.lowerCanvas.style.cursor=a.upperCanvas.style.cursor=a.cursor="grab":a.currObjType.isCustomCrop||a.togglePen?a.upperCanvas.style.cursor=a.cursor="crosshair":a.upperCanvas.style.cursor=a.cursor="default"},o.prototype.setCursorForPath=function(e,o,i,r){this.setCursorForLineArrow(e,o,i,r);var a=this.parent;if("default"===a.cursor)for(var n=t.extend({},e,null,!0),s=!1,l=1,p=e.pointColl.length;l<p&&!s;l++){n.activePoint.startX=e.pointColl[l-1].x,n.activePoint.startY=e.pointColl[l-1].y,n.activePoint.endX=e.pointColl[l].x,n.activePoint.endY=e.pointColl[l].y,a.notify("shape",{prop:"setPointCollForLineArrow",onPropertyChange:!1,value:{obj:n}});for(var h=e.topLeftCircle.radius,d=0,c=n.pointColl.length;d<c;d++){var u=n.pointColl[d];if(!t.isNullOrUndefined(u.x-2*h)&&!t.isNullOrUndefined(u.x+2*h)&&!t.isNullOrUndefined(u.y-2*h)&&!t.isNullOrUndefined(u.y+2*h)&&o>=u.x-2*h&&o<=u.x+2*h&&i>=u.y-2*h&&i<=u.y+2*h){r.style.cursor=a.cursor="move",s=!0;break}r.style.cursor=a.cursor="default"}}return a.cursor},o.prototype.setCursorForLineArrow=function(e,o,i,r){var a,n=e.topLeftCircle.radius;if(t.isNullOrUndefined(e.pointColl))return a;for(var s=0,l=e.pointColl.length;s<l;s++){var p=e.pointColl[s];if(o>=p.x-2*n&&o<=p.x+2*n&&i>=p.y-2*n&&i<=p.y+2*n){r.style.cursor=this.parent.cursor="move",a=s;break}r.style.cursor=this.parent.cursor="default"}return a},o.prototype.setCursorForRotatedObject=function(e,t,o,i){this.resizedElement="";var r=this.parent,a=e.bottomCenterCircle.radius,n=e.horTopLinePointColl[Math.round(e.horTopLinePointColl.length/2)],s=e.horTopLinePointColl[Math.round(e.horTopLinePointColl.length-1)],l=e.verLeftLinePointColl[Math.round(e.verLeftLinePointColl.length/2)],p=e.verRightLinePointColl[Math.round(e.verRightLinePointColl.length/2)],h=e.horBottomLinePointColl[Math.round(e.horBottomLinePointColl.length/2)],d=e.horBottomLinePointColl[Math.round(e.horBottomLinePointColl.length-1)],c=e.rotationCirclePointColl,u=e.horTopLinePointColl[0],v=e.horBottomLinePointColl[0];if(t>=u.x-(a+2)&&t<=u.x+(a+2)&&o>=u.y-(a+2)&&o<=u.y+(a+2)?i.style.cursor=r.cursor="nw-resize":t>=n.x-5&&t<=n.x+5&&o>=n.y-5&&o<=n.y+5?i.style.cursor=r.cursor=this.resizedElement="n-resize":t>=s.x-(a+2)&&t<=s.x+(a+2)&&o>=s.y-(a+2)&&o<=s.y+(a+2)?i.style.cursor=r.cursor="ne-resize":t>=l.x-5&&t<=l.x+5&&o>=l.y-5&&o<=l.y+5?i.style.cursor=r.cursor=this.resizedElement="w-resize":t>=p.x-5&&t<=p.x+5&&o>=p.y-5&&o<=p.y+5?i.style.cursor=r.cursor=this.resizedElement="e-resize":t>=v.x-(a+2)&&t<=v.x+(a+2)&&o>=v.y-(a+2)&&o<=v.y+(a+2)?i.style.cursor=r.cursor="sw-resize":t>=h.x-5&&t<=h.x+5&&o>=h.y-5&&o<=h.y+5?i.style.cursor=r.cursor=this.resizedElement="s-resize":t>=d.x-(a+2)&&t<=d.x+(a+2)&&o>=d.y-(a+2)&&o<=d.y+(a+2)?i.style.cursor=r.cursor="se-resize":c&&t>=c.x-(a+2)&&t<=c.x+(a+2)&&o>=c.y-(a+2)&&o<=c.y+(a+2)?i.style.cursor=r.cursor="grabbing":(i.style.cursor=r.cursor="default",this.getRectanglePoints(e.activePoint.startX,e.activePoint.startY,e.activePoint.width,e.activePoint.height,e.rotatedAngle*(180/Math.PI),t,o)&&(i.style.cursor=r.cursor="move")),"default"===r.cursor)for(var g=0,f=e.horTopLinePointColl.length;g<f;g++){var C=e.horTopLinePointColl[g];if(t>=C.x-5&&t<=C.x+5&&o>=C.y-5&&o<=C.y+5){i.style.cursor=r.cursor=this.resizedElement="n-resize";break}}if("default"===r.cursor)for(var g=0,f=e.horBottomLinePointColl.length;g<f;g++){var b=e.horBottomLinePointColl[g];if(t>=b.x-5&&t<=b.x+5&&o>=b.y-5&&o<=b.y+5){i.style.cursor=r.cursor=this.resizedElement="s-resize";break}}if("default"===r.cursor)for(var g=0,f=e.verLeftLinePointColl.length;g<f;g++){var m=e.verLeftLinePointColl[g];if(t>=m.x-5&&t<=m.x+5&&o>=m.y-5&&o<=m.y+5){i.style.cursor=r.cursor=this.resizedElement="w-resize";break}}if("default"===r.cursor)for(var g=0,f=e.verRightLinePointColl.length;g<f;g++){var y=e.verRightLinePointColl[g];if(t>=y.x-5&&t<=y.x+5&&o>=y.y-5&&o<=y.y+5){i.style.cursor=r.cursor=this.resizedElement="e-resize";break}}return this.adjustCursorStylesForRotatedState(e),r.cursor},o.prototype.adjustCursorStylesForRotatedState=function(e){var t=this.parent,o=e.rotatedAngle*(180/Math.PI);if((o=o>0?Math.floor(o):Math.ceil(o))>=92&&o<=182||o>=-178&&o<=-88){var i={"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"};t.cursor in i&&(t.cursor=i[t.cursor])}return t.upperCanvas.style.cursor=this.getResizeElement(e.rotatedAngle*(180/Math.PI),t.cursor),t.cursor},o.prototype.getResizeElement=function(e,t){var o=[];switch(t){case"nw-resize":o=[[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"]];break;case"n-resize":o=[[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"]];break;case"ne-resize":o=[[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"]];break;case"e-resize":o=[[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"]];break;case"se-resize":o=[[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"]];break;case"s-resize":o=[[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"]];break;case"sw-resize":o=[[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"]];break;case"w-resize":o=[[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 i=e<0?360-Math.abs(e):e,r=0,a=o;r<a.length;r++){var n=a[r],s=n[0],l=n[1],p=n[2];if(i>s&&i<=l||i+360>s&&i+360<=l)return p}return t},o.prototype.setCursorForFreehandDrawing=function(e,o,i,r){var a=i.getContext("2d"),n=this.parent,s=document.querySelector("#"+n.element.id+"_textArea"),l=!1;n.notify("freehand-draw",{prop:"setFreehandDrawHoveredIndex",onPropertyChange:!1,value:{index:-1}});for(var p,h=0;h<n.freehandCounter;h++)if(!r||r===n.pointColl[h].id){var d={selPointColl:{}};n.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:d}}),p=t.extend([],d.selPointColl[h].points,[]),n.points=t.extend([],n.pointColl[h].points,[]);var c=n.pointColl[h];n.notify("freehand-draw",{prop:"setPointCounter",onPropertyChange:!1,value:{value:0}});for(var u=p.length,v=0;v<u;v++)if(0!==v){var g=!1;if(p[v-1]&&p[v]&&(g=this.isInside(e,o,p[v-1].x,p[v-1].y,p[v].x,p[v].y)),g){this.isFhdPoint=!0,n.notify("freehand-draw",{prop:"setFreehandDrawHoveredIndex",onPropertyChange:!1,value:{index:h}}),n.notify("freehand-draw",{prop:"hoverFhd",onPropertyChange:!1,value:{strokeColor:null,strokeWidth:null}}),i.style.cursor=n.cursor="pointer",l=!0;break}if(!this.isFhdEditing||c.isSelected){if((this.isFhdPoint||this.isFhdEditing)&&(a.clearRect(0,0,i.width,i.height),n.activeObj.shape&&"none"===s.style.display&&n.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate",obj:n.activeObj}})),this.isFhdEditing){m={freehandSelectedIndex:-1};n.notify("freehand-draw",{prop:"getFreehandSelectedIndex",onPropertyChange:!1,value:{obj:m}});var f=n.pointColl[m.freehandSelectedIndex].strokeColor,C=n.pointColl[m.freehandSelectedIndex].strokeWidth;n.notify("freehand-draw",{prop:"hoverFhd",onPropertyChange:!1,value:{strokeColor:f,strokeWidth:C}})}else n.notify("freehand-draw",{prop:"setFreehandDrawHoveredIndex",onPropertyChange:!1,value:{index:null}});this.isFhdPoint=!1}}else{var b=n.points[v];if(e>b.x-c.strokeWidth&&e<b.x+c.strokeWidth&&o>b.y-c.strokeWidth&&o<b.y+c.strokeWidth){this.isFhdPoint=!0,n.notify("freehand-draw",{prop:"setFreehandDrawHoveredIndex",onPropertyChange:!1,value:{index:h}}),n.notify("freehand-draw",{prop:"hoverFhd",onPropertyChange:!1,value:{strokeColor:null,strokeWidth:null}}),i.style.cursor=n.cursor="pointer",l=!0;break}if(!this.isFhdEditing||c.isSelected){if((this.isFhdPoint||this.isFhdEditing)&&(a.clearRect(0,0,i.width,i.height),n.activeObj.shape&&"none"===s.style.display&&n.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate",obj:n.activeObj}})),this.isFhdEditing){var m={freehandSelectedIndex:-1};n.notify("freehand-draw",{prop:"getFreehandSelectedIndex",onPropertyChange:!1,value:{obj:m}});var f=n.pointColl[m.freehandSelectedIndex].strokeColor,C=n.pointColl[m.freehandSelectedIndex].strokeWidth;n.notify("freehand-draw",{prop:"hoverFhd",onPropertyChange:!1,value:{strokeColor:f,strokeWidth:C}})}this.isFhdPoint=!1}}if(l)break}},o.prototype.setCursorFromObj=function(e,o,i,r,a){for(var n=this.parent,s=0,l=i.length;s<l;s++){if("move"===n.cursor)return;var p=t.extend({},i[s],{},!0);if(0===p.activePoint.width&&0===p.activePoint.height)return void i.splice(s,1);this.cursorTargetId=p.currIndex,"line"===p.shape||"arrow"===p.shape?this.setCursorForLineArrow(p,e,o,r):"path"===p.shape?this.setCursorForPath(p,e,o,r):t.isNullOrUndefined(p.rotatedAngle)||0===p.rotatedAngle?r.style.cursor=n.cursor=this.getMouseCursor(p,e,o,a,!0):this.setCursorForRotatedObject(p,e,o,r)}},o.prototype.isInside=function(e,t,o,i,r,a){var n=Math.min(o,r),s=Math.max(o,r),l=Math.min(i,a),p=Math.max(i,a);return n<=e&&e<=s&&l<=t&&t<=p},o.prototype.updateActivePoint=function(e,o,i){var r=this.parent,a={width:0,height:0},n=r.activeObj.activePoint,s=n.startX,l=n.startY,p=n.endX,h=n.endY,d=r.activeObj.activePoint,c=d.width,u=d.height;r.notify("transform",{prop:"calcMaxDimension",onPropertyChange:!1,value:{width:c,height:u,obj:a,isImgShape:null}});var v=this.updatePrevShapeSettings(),g={cancel:!1,action:"resize",previousShapeSettings:v},f={cancel:!1,action:"move",previousShapeSettings:v};this.shapeResizingArgs=g,this.shapeMovingArgs=f,"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||!r.isShapeDrawing||(["line","arrow","path"].indexOf(r.activeObj.shape)>-1?this.dragElement="e-resize":e>s&&o>l?this.dragElement="se-resize":e<s&&o>l?this.dragElement="sw-resize":e>s&&o<l?this.dragElement="ne-resize":e<s&&o<l&&(this.dragElement="nw-resize")),"arrow"===r.activeObj.shape&&(Math.atan2(e-r.lowerCanvas.width/2,o-r.lowerCanvas.height/2)>0?r.activeObj.rotatedAngle=-Math.atan2(e-r.lowerCanvas.width/2,o-r.lowerCanvas.height/2):r.activeObj.rotatedAngle=Math.abs(Math.atan2(e-r.lowerCanvas.width/2,o-r.lowerCanvas.height/2)));var C,b=!1,m=!1;if(!i||0===r.transform.straighten||!this.isMouseOutsideImg(e,o))switch(this.dragElement.toLowerCase()){case"nw-resize":this.updateNWPoints(e,o),r.notify("shape",{prop:"updateArrowDirection",onPropertyChange:!1,value:{obj:r.activeObj,flip:null,rotatedDegree:null}}),this.triggerShapeChange(g,f,"resize");break;case"n-resize":this.updateNPoints(e,o),r.notify("shape",{prop:"updateArrowDirection",onPropertyChange:!1,value:{obj:r.activeObj,flip:null,rotatedDegree:null}}),this.triggerShapeChange(g,f,"resize");break;case"ne-resize":this.updateNEPoints(e,o),r.notify("shape",{prop:"updateArrowDirection",onPropertyChange:!1,value:{obj:r.activeObj,flip:null,rotatedDegree:null}}),this.triggerShapeChange(g,f,"resize");break;case"w-resize":this.updateWPoints(e,o),r.notify("shape",{prop:"updateArrowDirection",onPropertyChange:!1,value:{obj:r.activeObj,flip:null,rotatedDegree:null}}),this.triggerShapeChange(g,f,"resize");break;case"e-resize":this.updateEPoints(e,o),r.notify("shape",{prop:"updateArrowDirection",onPropertyChange:!1,value:{obj:r.activeObj,flip:null,rotatedDegree:null}}),this.triggerShapeChange(g,f,"resize");break;case"sw-resize":this.updateSWPoints(e,o),r.notify("shape",{prop:"updateArrowDirection",onPropertyChange:!1,value:{obj:r.activeObj,flip:null,rotatedDegree:null}}),this.triggerShapeChange(g,f,"resize");break;case"s-resize":this.updateSPoints(e,o),r.notify("shape",{prop:"updateArrowDirection",onPropertyChange:!1,value:{obj:r.activeObj,flip:null,rotatedDegree:null}}),this.triggerShapeChange(g,f,"resize");break;case"se-resize":this.updateSEPoints(e,o),r.notify("shape",{prop:"updateArrowDirection",onPropertyChange:!1,value:{obj:r.activeObj,flip:null,rotatedDegree:null}}),this.triggerShapeChange(g,f,"resize");break;case"grabbing":Math.atan2(e-(s+c/2),o-(l+u/2))>0?r.activeObj.rotatedAngle=-Math.atan2(e-(s+c/2),o-(l+u/2)):r.activeObj.rotatedAngle=Math.abs(Math.atan2(e-(s+c/2),o-(l+u/2))),(C=0===r.activeObj.shapeDegree?r.transform.degree:r.transform.degree-r.activeObj.shapeDegree)<0&&(C=360+C);for(var y=0,P=r.activeObj.flipObjColl.length;y<P;y++)"horizontal"===r.activeObj.flipObjColl[y].toLowerCase()?b=!0:"vertical"===r.activeObj.flipObjColl[y].toLowerCase()&&(m=!0);r.activeObj.rotatedAngle-=C*(Math.PI/180),0===C||360===C?m&&(r.activeObj.rotatedAngle-=Math.PI/180*180):90===C||-270===C?b&&(r.activeObj.rotatedAngle-=Math.PI/180*180):180===C||-180===C?m&&(r.activeObj.rotatedAngle-=Math.PI/180*180):270!==C&&-90!==C||b&&(r.activeObj.rotatedAngle-=Math.PI/180*180);break;case"pathdrag":t.isNullOrUndefined(this.pathAdjustedIndex)||(r.activeObj.pointColl[this.pathAdjustedIndex].x=e,r.activeObj.pointColl[this.pathAdjustedIndex].y=o);break;default:if(!i&&!r.currObjType.isCustomCrop){var j=r.activeObj.activePoint;if(this.dragPoint.startX){var x=this.dragPoint.endX-this.previousPoint.x,w=this.dragPoint.endY-this.previousPoint.y;if(j.startX+=x,j.endX+=x,j.startY+=w,j.endY+=w,s=j.startX,l=j.startY,p=j.endX,h=j.endY,"line"!==r.activeObj.shape&&"arrow"!==r.activeObj.shape&&r.activeObj.rotationCirclePointColl&&(r.activeObj.rotationCirclePointColl.x+=x,r.activeObj.rotationCirclePointColl.y+=w,r.activeObj.rotationCirclePoint.x+=x,r.activeObj.rotationCirclePoint.y+=w),"path"===r.activeObj.shape)for(var y=0,P=r.activeObj.pointColl.length;y<P;y++)r.activeObj.pointColl[y].x+=x,r.activeObj.pointColl[y].y+=w;!this.isPreventDragging&&"line"!==r.activeObj.shape&&0===r.activeObj.rotatedAngle&&(s<r.img.destLeft||l<r.img.destTop||p>r.img.destLeft+r.img.destWidth||h>r.img.destTop+r.img.destHeight)&&(j.startX-=x,j.endX-=x,j.startY-=w,j.endY-=w,"line"!==r.activeObj.shape&&"arrow"!==r.activeObj.shape&&r.activeObj.rotationCirclePointColl&&(r.activeObj.rotationCirclePointColl.x-=x,r.activeObj.rotationCirclePointColl.y-=w,r.activeObj.rotationCirclePoint.x-=x,r.activeObj.rotationCirclePoint.y-=w),this.setDragWidth(x),this.setDragHeight(w))}else j.startX=e<this.mouseDownPoint.x?e:this.mouseDownPoint.x,j.startY=o<this.mouseDownPoint.y?o:this.mouseDownPoint.y,e=e<this.mouseDownPoint.x?this.mouseDownPoint.x:e,o=o<this.mouseDownPoint.y?this.mouseDownPoint.y:o,j.endX=e,j.endY=o;this.triggerShapeChange(g,f,"move")}}},o.prototype.triggerShapeChange=function(e,o,i){var r=this.parent,a=r.activeObj.activePoint;a.width=a.endX-a.startX,a.height=a.endY-a.startY;var n=this.updatePrevShapeSettings();if(t.isNullOrUndefined(this.shapeResizingArgs)||t.isNullOrUndefined(this.shapeMovingArgs)?(e.currentShapeSettings=n,o.currentShapeSettings=n):(e.currentShapeSettings=this.shapeResizingArgs.currentShapeSettings=n,o.currentShapeSettings=this.shapeMovingArgs.currentShapeSettings=n),"resize"===i){this.isCropSelection=!1;var s=void 0;if(void 0!==r.activeObj.shape&&(s=r.activeObj.shape.split("-")),void 0!==s&&"crop"===s[0]&&(this.isCropSelection=!0),this.isCropSelection){var l={action:e.action,previousSelectionSettings:{type:r.getSelectionType(r.activeObj.shape),startX:e.previousShapeSettings.startX,startY:e.previousShapeSettings.startY,width:e.previousShapeSettings.width,height:e.previousShapeSettings.height},currentSelectionSettings:{type:r.getSelectionType(r.activeObj.shape),startX:e.currentShapeSettings.startX,startY:e.currentShapeSettings.startY,width:e.currentShapeSettings.width,height:e.currentShapeSettings.height}};this.selectionResizingArgs=l,r.trigger("selectionChanging",l),r.notify("shape",{prop:"updSelChangeEventArgs",onPropertyChange:!1,value:{selectionSettings:l.currentSelectionSettings}})}else""!==this.currentDrawingShape&&"crosshair"===r.upperCanvas.style.cursor&&(e.action="drawing"),r.trigger("shapeChanging",e),this.isPreventShaping=e.cancel,r.notify("shape",{prop:"updateShapeChangeEventArgs",onPropertyChange:!1,value:{shapeSettings:e.currentShapeSettings}})}else"mouse-down"===i||"mouse-up"===i?(r.trigger("shapeChanging",e),this.isPreventShaping=e.cancel,r.notify("shape",{prop:"updateShapeChangeEventArgs",onPropertyChange:!1,value:{shapeSettings:e.currentShapeSettings}})):(r.trigger("shapeChanging",o),this.isPreventShaping=o.cancel,r.notify("shape",{prop:"updateShapeChangeEventArgs",onPropertyChange:!1,value:{shapeSettings:o.currentShapeSettings}}));r.eventType=i},o.prototype.setDragWidth=function(e){var t=this.parent,o=t.activeObj.activePoint,i=t.img,r=i.destLeft,a=i.destWidth,n=e;if(n>=0)for(s=0;s<n&&(e=n-s,o.startX+=e,o.endX+=e,!(o.startX>=r&&o.endX<=r+a));s++)o.startX-=e,o.endX-=e;else for(var s=1;s<Math.abs(n)&&(e=n+s,o.startX+=e,o.endX+=e,!(o.startX>=r&&o.endX<=r+a));s++)o.startX-=e,o.endX-=e},o.prototype.setDragHeight=function(e){var t=this.parent,o=t.activeObj.activePoint,i=t.img,r=i.destTop,a=i.destHeight,n=e;if(n>=0)for(s=1;s<n&&(e=n-s,o.startY+=e,o.endY+=e,!(o.startY>=r&&o.endY<=r+a));s++)o.startY-=e,o.endY-=e;else for(var s=0;s<Math.abs(n)&&(e=n+s,o.startY+=e,o.endY+=e,!(o.startY>=r&&o.endY<=r+a));s++)o.startY-=e,o.endY-=e},o.prototype.limitDrag=function(e){var t=!1,o=this.parent,i=o.img,r=i.destLeft,a=i.destTop,n=i.destWidth,s=i.destHeight,l=o.activeObj.activePoint,p=e?l.startX:l.endX,h=e?l.startY:l.endY,d=e?l.endX:l.startX,c=e?l.endY:l.startY;if(p<r&&(p=r),h<a&&(h=a),d>r+n&&(d=r+n),c>a+s&&(c=a+s),0!==o.transform.straighten){var u={isIntersect:null,arr:null};o.notify("draw",{prop:"updateImgCanvasPoints",onPropertyChange:!1}),o.notify("draw",{prop:"isLinesIntersect",onPropertyChange:!1,value:{obj:u}}),(u.arr[0]||u.arr[1]||u.arr[2]||u.arr[3])&&(t=!0)}return e?(l.startX=p,l.startY=h,l.endX=d,l.endY=c):(l.startX=d,l.startY=c,l.endX=p,l.endY=h),t},o.prototype.isMouseOutsideImg=function(e,t){var o={bool:!1};return this.parent.notify("draw",{prop:"updateImgCanvasPoints",onPropertyChange:!1}),this.parent.notify("draw",{prop:"isPointsInsideImg",value:{obj:o,x:e,y:t}}),o.bool},o.prototype.preventDraggingInvertly=function(){var e=!1,t=this.parent;return"image"===t.activeObj.shape?e:(this.isPreventDragging||0!==t.activeObj.rotatedAngle||(e=this.limitDrag(!0),["line","arrow","path"].indexOf(t.activeObj.shape)>-1&&(e=this.limitDrag(!1))),e)},o.prototype.preventTextDraggingInvertly=function(){var e=this.parent,t=!1,o=e.activeObj.activePoint,i=e.img,r=i.destLeft,a=i.destTop,n=i.destWidth,s=i.destHeight;return this.isPreventDragging||(o.startX<r||o.startY<a||o.endX>r+n||o.endY>a+s)&&(t=!0),t},o.prototype.preventInverseResize=function(e){var t=this.parent.activeObj.activePoint;t.width<0&&(t.width=0,t.startX=e.activePoint.startX,t.endX=e.activePoint.endX),t.height<0&&(t.height=0,t.startY=e.activePoint.startY,t.endY=e.activePoint.endY)},o.prototype.getScaleRatio=function(e){var t=this.parent,o={x:e,y:e};if(t.activeObj.shape&&"crop-custom"!==t.activeObj.shape&&"crop-circle"!==t.activeObj.shape&&"crop-square"!==t.activeObj.shape){var i="image"===t.activeObj.shape||"text"===t.activeObj.shape?this.findImageRatio(t.activeObj.activePoint.width,t.activeObj.activePoint.height).split("-"):t.activeObj.shape.split("-");if(i.length>1||"image"===t.activeObj.shape||"text"===t.activeObj.shape){i="image"===t.activeObj.shape||"text"===t.activeObj.shape?i[0].split(":"):i[1].split(":");var r=e/parseInt(i[1],10);o.x=r*parseInt(i[0],10),o.y=r*parseInt(i[1],10)}}return o},o.prototype.findImageRatio=function(e,t,o){var i=function(e,t){return 0===t?e:i(t,e%t)},r=i(e,t),a=e/r+":"+t/r;return o&&(o.ratio=a),a},o.prototype.revertResizing=function(e){var t=this.parent.activeObj.activePoint;this.preventDraggingInvertly()&&(t.startX=e.activePoint.startX,t.startY=e.activePoint.startY,t.endX=e.activePoint.endX,t.endY=e.activePoint.endY)},o.prototype.performSEResize=function(e,t,o,i){var r=this.parent;if(this.resizeImg(e,t,"se-resize",o),i.endX<i.startX){a=i.endX;i.endX=i.startX,i.startX=a,this.dragElement=r.upperCanvas.style.cursor=r.cursor="sw-resize"}if(i.endY<i.startY){var a=i.endY;i.endY=i.startY,i.startY=a,this.dragElement=r.upperCanvas.style.cursor=r.cursor="ne-resize"}this.revertCustomSelection(i,o,"se-resize"),this.revertResizing(o)},o.prototype.performNWResize=function(e,t,o,i){var r=this.parent;if(this.resizeImg(e,t,"nw-resize",o),i.startX>i.endX){a=i.startX;i.startX=i.endX,i.endX=a,this.dragElement=r.upperCanvas.style.cursor=r.cursor="ne-resize"}if(i.startY>i.endY){var a=i.startY;i.startY=i.endY,i.endY=a,this.dragElement=r.upperCanvas.style.cursor=r.cursor="sw-resize"}this.revertCustomSelection(i,o,"nw-resize"),this.revertResizing(o)},o.prototype.isCustomSelection=function(){if(this.parent.activeObj.shape){var e=["custom","circle","square","2:3","3:2","3:4","4:3","4:5","5:4","5:7","7:5","9:16","16:9"];return this.parent.activeObj.shape.indexOf("crop-")>-1&&-1===e.indexOf(this.parent.activeObj.shape.split("-")[1])}return!1},o.prototype.revertCustomSelection=function(e,t,o){var i=this.parent;if(this.isCustomSelection()){var r=i.img,a=r.destLeft,n=r.destTop,s=r.destWidth,l=r.destHeight,p=a+s<i.lowerCanvas.width?a+s:i.lowerCanvas.width,h=n+l<i.lowerCanvas.height?n+l:i.lowerCanvas.height,d=a>0?a:0,c=n>0?n:0,u=n>0?n:0,v=a>0?a:0;("se-resize"===o&&(e.endX>p||e.endY>h)||"nw-resize"===o&&(e.startX<d||e.startY<c)||"ne-resize"===o&&(e.endX>p||e.startY<u)||"sw-resize"===o&&(e.startX<v||e.endY>h))&&this.revertPoints(e,t)}},o.prototype.revertPoints=function(e,t){e.startX=t.activePoint.startX,e.startY=t.activePoint.startY,e.endX=t.activePoint.endX,e.endY=t.activePoint.endY,e.width=t.activePoint.width,e.height=t.activePoint.height},o.prototype.updateNWPoints=function(e,o){var i,r,a,n=this.parent,s=n.activeObj.activePoint,l=t.extend({},n.activeObj,null,!0);if("text"===n.activeObj.shape)this.resizeImg(e,o,"nw-resize",l),n.notify("shape",{prop:"updateFontSize",onPropertyChange:!1,value:{obj:n.activeObj}});else{var p=void 0;if(void 0!==n.activeObj.shape&&(p=n.activeObj.shape.split("-")),"crop-custom"===n.activeObj.shape||void 0!==n.activeObj.shape&&"crop"!==p[0]||this.isCustomSelection()){if("image"===n.activeObj.shape||this.isCustomSelection()?this.resizeImg(e,o,"nw-resize",l):this.adjustNWPoints(s,e,o,n.activeObj.rotatedAngle),s.startX>s.endX){h=s.startX;s.startX=s.endX,s.endX=h,this.dragElement=n.upperCanvas.style.cursor=n.cursor="ne-resize"}if(s.startY>s.endY){var h=s.startY;s.startY=s.endY,s.endY=h,this.dragElement=n.upperCanvas.style.cursor=n.cursor="sw-resize"}this.revertCustomSelection(s,l,"nw-resize"),this.revertResizing(l)}else{var d=n.img,c=d.destLeft,u=d.destTop;if(s.startX<e&&s.startY<o){i=e-s.startX,r=o-s.startY,a=Math.min(i,r);f=this.getScaleRatio(a);s.startX+=f.x,s.startY+=f.y;var v=c>0?c:0,g=u>0?u:0;(s.startX<v||s.startY<g)&&(s.startX-=f.x,s.startY-=f.y)}else{i=s.startX-e,r=o-s.endY,a=Math.max(i,r);var f=this.getScaleRatio(a);s.startX-=f.x,s.startY-=f.y;var v=c>0?c:0,C=u>0?u:0;(s.startX<v||s.startY<C)&&(s.startX+=f.x,s.startY+=f.y)}s.width=s.endX-s.startX,s.height=s.endY-s.startY,this.revertResizing(l)}s.width=s.endX-s.startX,s.height=s.endY-s.startY,this.preventInverseResize(l)}},o.prototype.updateNPoints=function(e,o){var i,r,a,n=this.parent,s=n.activeObj.activePoint,l=t.extend({},n.activeObj,null,!0);if("text"!==n.activeObj.shape){var p=void 0;if(n.activeObj.shape&&(p=n.activeObj.shape.split("-")),"crop-custom"===n.activeObj.shape||n.activeObj.shape&&"crop"!==p[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=e,this.dragPoint.endY=o),i=this.dragPoint.endX-this.previousPoint.x,r=this.dragPoint.endY-this.previousPoint.y,this.adjustRotationPoints(s,i,r,n.activeObj.rotatedAngle)):(s.startY=o,s.height=s.endY-s.startY),s.startY>s.endY){var h=s.startY;s.startY=s.endY,s.endY=h,this.dragElement=this.resizedElement="s-resize"}this.revertResizing(l)}else{var d=n.img,c=d.destLeft,u=d.destTop,v=d.destWidth;if(this.isCustomSelection())this.performNWResize(e,o,l,s);else if(s.endX>e&&s.startY<o){i=s.endX-e,r=o-s.startY,a=Math.min(i,r);g=this.getScaleRatio(a);s.endX-=g.x,s.startY+=g.y,(s.endX>c+v||s.startY<u)&&(s.endX+=g.x,s.startY-=g.y)}else{i=e-s.endX,r=s.startY-o,a=Math.max(i,r);var g=this.getScaleRatio(a);s.endX+=g.x,s.startY-=g.y,(s.endX>c+v||s.startY<u)&&(s.endX-=g.x,s.startY+=g.y)}s.width=s.endX-s.startX,s.height=s.endY-s.startY,this.revertResizing(l)}}},o.prototype.updateNEPoints=function(e,o){var i,r,a,n=this.parent,s=n.activeObj.activePoint,l=t.extend({},n.activeObj,null,!0);if("text"===n.activeObj.shape)this.resizeImg(e,o,"ne-resize",l),n.notify("shape",{prop:"updateFontSize",onPropertyChange:!1,value:{obj:n.activeObj}});else{var p=void 0;if(n.activeObj.shape&&(p=n.activeObj.shape.split("-")),"crop-custom"===n.activeObj.shape||void 0!==n.activeObj.shape&&"crop"!==p[0]||this.isCustomSelection()){if("image"===n.activeObj.shape||this.isCustomSelection()?this.resizeImg(e,o,"ne-resize",l):this.adjustNEPoints(s,e,o,n.activeObj.rotatedAngle),s.endX<s.startX){h=s.endX;s.endX=s.startX,s.startX=h,this.dragElement=n.upperCanvas.style.cursor=n.cursor="nw-resize"}if(s.startY>s.endY){var h=s.startY;s.startY=s.endY,s.endY=h,this.dragElement=n.upperCanvas.style.cursor=n.cursor="se-resize"}this.revertCustomSelection(s,l,"ne-resize"),this.revertResizing(l)}else{var d=n.img,c=d.destLeft,u=d.destTop,v=d.destWidth;if(s.endX>e&&s.startY<o){i=s.endX-e,r=o-s.startY,a=Math.min(i,r);C=this.getScaleRatio(a);s.endX-=C.x,s.startY+=C.y;var g=c+v<n.lowerCanvas.width?c+v:n.lowerCanvas.width,f=u>0?u:0;(s.endX>g||s.startY<f)&&(s.endX+=C.x,s.startY-=C.y)}else{i=e-s.endX,r=s.startY-o,a=Math.max(i,r);var C=this.getScaleRatio(a);s.endX+=C.x,s.startY-=C.y;var g=c+v<n.lowerCanvas.width?c+v:n.lowerCanvas.width,f=u>0?u:0;(s.endX>g||s.startY<f)&&(s.endX-=C.x,s.startY+=C.y)}s.width=s.endX-s.startX,s.height=s.endY-s.startY,this.revertResizing(l)}s.width=s.endX-s.startX,s.height=s.endY-s.startY,this.preventInverseResize(l)}},o.prototype.updateWPoints=function(e,o){var i,r,a,n=this.parent,s=n.activeObj.activePoint,l=t.extend({},n.activeObj,null,!0);if("text"!==n.activeObj.shape){var p=void 0;if(n.activeObj.shape&&(p=n.activeObj.shape.split("-")),"crop-custom"===n.activeObj.shape||n.activeObj.shape&&"crop"!==p[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=e,this.dragPoint.endY=o),i=this.dragPoint.endX-this.previousPoint.x,r=this.dragPoint.endY-this.previousPoint.y,this.adjustRotationPoints(s,i,r,n.activeObj.rotatedAngle)):(s.startX=e,s.width=s.endX-s.startX),"line"===n.activeObj.shape||"arrow"===n.activeObj.shape||"path"===n.activeObj.shape)s.startY=o,s.height=s.endY-s.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(s.startX>s.endX){var h=s.startX;s.startX=s.endX,s.endX=h,this.dragElement=this.resizedElement="e-resize"}this.revertResizing(l)}else{var d=n.img,c=d.destLeft,u=d.destTop,v=d.destHeight;if(this.isCustomSelection())this.performNWResize(e,o,l,s);else if(s.startX<e&&s.endY>o){i=e-s.startX,r=s.endY-o,a=Math.min(i,r);g=this.getScaleRatio(a);s.startX+=g.x,s.endY-=g.y,(s.startX<c||s.endY>u+v)&&(s.startX-=g.x,s.endY+=g.y)}else{i=s.startX-e,r=o-s.endY,a=Math.max(i,r);var g=this.getScaleRatio(a);s.startX-=g.x,s.endY+=g.y,(s.startX<c||s.endY>u+v)&&(s.startX+=g.x,s.endY-=g.y)}s.width=s.endX-s.startX,s.height=s.endY-s.startY,this.revertResizing(l)}}},o.prototype.updateEPoints=function(e,o){var i,r,a,n=this.parent,s=n.activeObj.activePoint,l=t.extend({},n.activeObj,null,!0);if("text"!==n.activeObj.shape){var p=void 0;if(n.activeObj.shape&&(p=n.activeObj.shape.split("-")),"crop-custom"===n.activeObj.shape||n.activeObj.shape&&"crop"!==p[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=e,this.dragPoint.endY=o),i=this.dragPoint.endX-this.previousPoint.x,r=this.dragPoint.endY-this.previousPoint.y,this.adjustRotationPoints(s,i,r,n.activeObj.rotatedAngle)):(s.endX=e,s.width=s.endX-s.startX),"line"===n.activeObj.shape||"arrow"===n.activeObj.shape||"path"===n.activeObj.shape)s.endY=o,s.height=s.endY-s.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(s.endX<s.startX){var h=s.endX;s.endX=s.startX,s.startX=h,this.dragElement=this.resizedElement="w-resize"}this.revertResizing(l)}else{var d=n.img,c=d.destLeft,u=d.destTop,v=d.destWidth,g=d.destHeight;if(this.isCustomSelection())this.performSEResize(e,o,l,s);else if(s.endX>e&&s.endY>o){i=s.endX-e,r=s.endY-o,a=Math.min(i,r);f=this.getScaleRatio(a);s.endX-=f.x,s.endY-=f.y,(s.endX>c+v||s.endY>u+g)&&(s.endX+=f.x,s.endY+=f.y)}else{i=e-s.endX,r=o-s.endY,a=Math.max(i,r);var f=this.getScaleRatio(a);s.endX+=f.x,s.endY+=f.y,(s.endX>c+v||s.endY>u+g)&&(s.endX-=f.x,s.endY-=f.y)}s.width=s.endX-s.startX,s.height=s.endY-s.startY,this.revertResizing(l)}}},o.prototype.updateSWPoints=function(e,o){var i,r,a,n=this.parent,s=n.activeObj.activePoint,l=t.extend({},n.activeObj,null,!0);if("text"===n.activeObj.shape)this.resizeImg(e,o,"sw-resize",l),n.notify("shape",{prop:"updateFontSize",onPropertyChange:!1,value:{obj:n.activeObj}});else{var p=void 0;if(void 0!==n.activeObj.shape&&(p=n.activeObj.shape.split("-")),"crop-custom"===n.activeObj.shape||void 0!==n.activeObj.shape&&"crop"!==p[0]||this.isCustomSelection()){if("image"===n.activeObj.shape||this.isCustomSelection()?this.resizeImg(e,o,"sw-resize",l):this.adjustSWPoints(s,e,o,n.activeObj.rotatedAngle),s.startX>s.endX){h=s.startX;s.startX=s.endX,s.endX=h,this.dragElement=n.upperCanvas.style.cursor=n.cursor="se-resize"}if(s.endY<s.startY){var h=s.endY;s.endY=s.startY,s.startY=h,this.dragElement=n.upperCanvas.style.cursor=n.cursor="nw-resize"}this.revertCustomSelection(s,l,"sw-resize"),this.revertResizing(l)}else{var d=n.img,c=d.destLeft,u=d.destTop,v=d.destHeight;if(s.startX<e&&s.endY>o){i=e-s.startX,r=s.endY-o,a=Math.min(i,r);C=this.getScaleRatio(a);s.startX+=C.x,s.endY-=C.y;var g=c>0?c:0,f=u+v<n.lowerCanvas.height?u+v:n.lowerCanvas.height;(s.startX<g||s.endY>f)&&(s.startX-=C.x,s.endY+=C.y)}else{i=s.startX-e,r=o-s.endY,a=Math.max(i,r);var C=this.getScaleRatio(a);s.startX-=C.x,s.endY+=C.y;var g=c>0?c:0,f=u+v<n.lowerCanvas.height?u+v:n.lowerCanvas.height;(s.startX<g||s.endY>f)&&(s.startX+=C.x,s.endY-=C.y)}s.width=s.endX-s.startX,s.height=s.endY-s.startY,this.revertResizing(l)}s.width=s.endX-s.startX,s.height=s.endY-s.startY,this.preventInverseResize(l)}},o.prototype.updateSPoints=function(e,o){var i,r,a,n=this.parent,s=n.activeObj.activePoint,l=t.extend({},n.activeObj,null,!0);if("text"!==n.activeObj.shape){var p=void 0;if(n.activeObj.shape&&(p=n.activeObj.shape.split("-")),"crop-custom"===n.activeObj.shape||n.activeObj.shape&&"crop"!==p[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=e,this.dragPoint.endY=o),i=this.dragPoint.endX-this.previousPoint.x,r=this.dragPoint.endY-this.previousPoint.y,this.adjustRotationPoints(s,i,r,n.activeObj.rotatedAngle)):(s.endY=o,s.height=s.endY-s.startY),s.endY<s.startY){var h=s.endY;s.endY=s.startY,s.startY=h,this.dragElement=this.resizedElement="n-resize"}this.revertResizing(l)}else{var d=n.img,c=d.destLeft,u=d.destTop,v=d.destWidth,g=d.destHeight;if(this.isCustomSelection())this.performSEResize(e,o,l,s);else if(s.endX>e&&s.endY>o){i=s.endX-e,r=s.endY-o,a=Math.min(i,r);f=this.getScaleRatio(a);s.endX-=f.x,s.endY-=f.y,(s.endX>c+v||s.endY>u+g)&&(s.endX+=f.x,s.endY+=f.y)}else{i=e-s.endX,r=o-s.endY,a=Math.max(i,r);var f=this.getScaleRatio(a);s.endX+=f.x,s.endY+=f.x,(s.endX>c+v||s.endY>u+g)&&(s.endX-=f.x,s.endY-=f.y)}s.width=s.endX-s.startX,s.height=s.endY-s.startY,this.revertResizing(l)}}},o.prototype.updateSEPoints=function(e,o){var i,r,a,n=this.parent,s=n.activeObj.activePoint,l=t.extend({},n.activeObj,null,!0);if("text"===n.activeObj.shape)this.resizeImg(e,o,"se-resize",l),n.notify("shape",{prop:"updateFontSize",onPropertyChange:!1,value:{obj:n.activeObj}});else{var p=void 0,h=void 0;if(void 0!==n.activeObj.shape&&(p=n.activeObj.shape.split("-")),"crop-custom"===n.activeObj.shape||void 0!==n.activeObj.shape&&"crop"!==p[0]||this.isCustomSelection()){if("image"===n.activeObj.shape||this.isCustomSelection()?this.resizeImg(e,o,"se-resize",l):this.adjustSEPoints(s,e,o,n.activeObj.rotatedAngle),s.endX<s.startX){d=s.endX;s.endX=s.startX,s.startX=d,this.dragElement=n.upperCanvas.style.cursor=n.cursor="sw-resize"}if(s.endY<s.startY){var d=s.endY;s.endY=s.startY,s.startY=d,this.dragElement=n.upperCanvas.style.cursor=n.cursor="ne-resize"}this.revertCustomSelection(s,l,"se-resize"),this.revertResizing(l)}else{var c=n.img,u=c.destLeft,v=c.destTop,g=c.destWidth,f=c.destHeight;if(s.endX>e&&s.endY>o){i=s.endX-e,r=s.endY-o,a=Math.min(i,r),h=this.getScaleRatio(a),s.endX-=h.x,s.endY-=h.y;var C=u+g<n.lowerCanvas.width?u+g:n.lowerCanvas.width,b=v+f<n.lowerCanvas.height?v+f:n.lowerCanvas.height;(s.endX>C||s.endY>b)&&(s.endX+=h.x,s.endY+=h.y)}else{i=e-s.endX,r=o-s.endY,a=Math.max(i,r),h=this.getScaleRatio(a),s.endX+=h.x,s.endY+=h.y;var C=u+g<n.lowerCanvas.width?u+g:n.lowerCanvas.width,b=v+f<n.lowerCanvas.height?v+f:n.lowerCanvas.height;(s.endX>C||s.endY>b)&&(s.endX-=h.x,s.endY-=h.y)}s.width=s.endX-s.startX,s.height=s.endY-s.startY,this.revertResizing(l)}this.preventInverseResize(l)}},o.prototype.resizeImg=function(e,o,i,r){var a,n,s=this.parent,l=s.activeObj.activePoint;if(0!==this.previousPoint.x&&0!==this.previousPoint.y){if("text"===this.currentDrawingShape&&(this.setCursor(e,o),0===s.activeObj.textSettings.fontSize)){s.activeObj.textSettings.fontSize=11,s.notify("shape",{prop:"updateFontRatio",onPropertyChange:!1,value:{obj:s.activeObj,isTextArea:null}}),s.activeObj.textSettings.text=s.activeObj.keyHistory="Enter Text",s.notify("shape",{prop:"updateFontStyles",onPropertyChange:!1,value:{isTextBox:null}});var p=this.upperContext.measureText(s.activeObj.textSettings.text).width+.5*s.activeObj.textSettings.fontSize;l.endX=l.startX+p,l.endY=l.startY+s.activeObj.textSettings.fontSize,l.width=l.endX-l.startX,l.height=l.endY-l.startY,r=t.extend({},s.activeObj,null,!0),s.notify("draw",{prop:"updateActiveObject",onPropertyChange:!1,value:{actPoint:s.activeObj.activePoint,obj:s.activeObj,isMouseMove:null,x:null,y:null}})}switch(s.upperCanvas.style.cursor){case"se-resize":case"s-resize":this.previousPoint.x>e||this.previousPoint.y>o?(a=(this.previousPoint.x-e+(this.previousPoint.y-o))/2,n=this.getScaleRatio(a),this.adjustRotationPoints(l,-Math.abs(n.x),-Math.abs(n.y),s.activeObj.rotatedAngle,"img-resize",i)):0!==this.previousPoint.x&&0!==this.previousPoint.y&&(a=(e-this.previousPoint.x+(o-this.previousPoint.y))/2,n=this.getScaleRatio(a),this.adjustRotationPoints(l,Math.abs(n.x),Math.abs(n.y),s.activeObj.rotatedAngle,"img-resize",i));break;case"sw-resize":this.previousPoint.x<e||this.previousPoint.y>o?(a=(e-this.previousPoint.x+(this.previousPoint.y-o))/2,n=this.getScaleRatio(a),this.adjustRotationPoints(l,-Math.abs(n.x),-Math.abs(n.y),s.activeObj.rotatedAngle,"img-resize",i)):0!==this.previousPoint.x&&0!==this.previousPoint.y&&(a=(this.previousPoint.x-e+(o-this.previousPoint.y))/2,n=this.getScaleRatio(a),this.adjustRotationPoints(l,Math.abs(n.x),Math.abs(n.y),s.activeObj.rotatedAngle,"img-resize",i));break;case"w-resize":case"nw-resize":this.previousPoint.x<e||this.previousPoint.y<o?(a=(e-this.previousPoint.x+(o-this.previousPoint.y))/2,n=this.getScaleRatio(a),this.adjustRotationPoints(l,-Math.abs(n.x),-Math.abs(n.y),s.activeObj.rotatedAngle,"img-resize",i)):0!==this.previousPoint.x&&0!==this.previousPoint.y&&(a=(this.previousPoint.x-e+(this.previousPoint.y-o))/2,n=this.getScaleRatio(a),this.adjustRotationPoints(l,Math.abs(n.x),Math.abs(n.y),s.activeObj.rotatedAngle,"img-resize",i));break;case"n-resize":case"ne-resize":this.previousPoint.x>e||this.previousPoint.y<o?(a=(this.previousPoint.x-e+(o-this.previousPoint.y))/2,n=this.getScaleRatio(a),this.adjustRotationPoints(l,-Math.abs(n.x),-Math.abs(n.y),s.activeObj.rotatedAngle,"img-resize",i)):0!==this.previousPoint.x&&0!==this.previousPoint.y&&(a=(e-this.previousPoint.x+(this.previousPoint.y-o))/2,n=this.getScaleRatio(a),this.adjustRotationPoints(l,Math.abs(n.x),Math.abs(n.y),s.activeObj.rotatedAngle,"img-resize",i));break;case"e-resize":this.previousPoint.x>e||this.previousPoint.y>o?(a=(this.previousPoint.x-e+(this.previousPoint.y-o))/2,n=this.getScaleRatio(a),this.adjustRotationPoints(l,-Math.abs(n.x),-Math.abs(n.y),s.activeObj.rotatedAngle,"img-resize",i)):0!==this.previousPoint.x&&0!==this.previousPoint.y&&(a=(e-this.previousPoint.x+(o-this.previousPoint.y))/2,n=this.getScaleRatio(a),this.adjustRotationPoints(l,Math.abs(n.x),Math.abs(n.y),s.activeObj.rotatedAngle,"img-resize",i))}l.width=l.endX-l.startX,l.height=l.endY-l.startY,(l.width<10||l.height<10||"text"===s.activeObj.shape&&0===s.activeObj.rotatedAngle&&this.preventTextDraggingInvertly())&&(s.activeObj=t.extend({},r,null,!0))}this.previousPoint={x:e,y:o}},o.prototype.adjustNWPoints=function(e,t,o,i){var r=e.startX+e.width/2,a=e.startY+e.height/2,n=this.rotatePoints(e.endX,e.endY,r,a,i),s=[(n[0]+t)/2,(n[1]+o)/2],l=this.rotatePoints(n[0],n[1],s[0],s[1],-i),p=this.rotatePoints(t,o,s[0],s[1],-i);return e.endX=l[0],e.endY=l[1],e.startY=p[1],e.startX=p[0],e.width=e.endX-e.startX,e.height=e.endY-e.startY,e},o.prototype.adjustNEPoints=function(e,t,o,i){var r=e.startX+e.width/2,a=e.startY+e.height/2,n=this.rotatePoints(e.startX,e.endY,r,a,i),s=[(n[0]+t)/2,(n[1]+o)/2],l=this.rotatePoints(n[0],n[1],s[0],s[1],-i),p=this.rotatePoints(t,o,s[0],s[1],-i);return e.startX=l[0],e.endY=l[1],e.width=p[0]-l[0],e.height=l[1]-p[1],e.endX=e.startX+e.width,e.startY=e.endY-e.height,e},o.prototype.adjustSWPoints=function(e,t,o,i){var r=e.startX+e.width/2,a=e.startY+e.height/2,n=this.rotatePoints(e.endX,e.startY,r,a,i),s=[(n[0]+t)/2,(n[1]+o)/2],l=this.rotatePoints(n[0],n[1],s[0],s[1],-i),p=this.rotatePoints(t,o,s[0],s[1],-i);return e.endX=l[0],e.startY=l[1],e.startX=p[0],e.endY=p[1],e.width=e.endX-e.startX,e.height=e.endY-e.startY,e},o.prototype.adjustSEPoints=function(e,t,o,i){var r=e.startX+e.width/2,a=e.startY+e.height/2,n=this.rotatePoints(e.startX,e.startY,r,a,i),s=[(n[0]+t)/2,(n[1]+o)/2],l=this.rotatePoints(n[0],n[1],s[0],s[1],-i),p=this.rotatePoints(t,o,s[0],s[1],-i);return e.startX=l[0],e.startY=l[1],e.width=p[0]-l[0],e.height=p[1]-l[1],e.endX=e.startX+e.width,e.endY=e.startY+e.height,e},o.prototype.adjustRotationPoints=function(e,t,o,i,r,a){var n=e.startX+e.width/2,s=e.startY+e.height/2;this.getResizeDirection(e,t,o,i,r,a);var l=this.rotatePoints(e.startX,e.startY,n,s,i),p=this.rotatePoints(e.endX,e.startY,n,s,i),h=this.rotatePoints(e.endX,e.endY,n,s,i),d=this.rotatePoints(e.startX,e.endY,n,s,i),c=[(l[0]+h[0])/2,(l[1]+h[1])/2],u=this.rotatePoints(l[0],l[1],c[0],c[1],-i),v=this.rotatePoints(d[0],d[1],c[0],c[1],-i),g=this.rotatePoints(p[0],p[1],c[0],c[1],-i);return e.startX=u[0],e.startY=u[1],e.endX=g[0],e.endY=v[1],e.width=e.endX-e.startX,e.height=e.endY-e.startY,e},o.prototype.rotatePoints=function(e,t,o,i,r){return[(e-o)*Math.cos(r)-(t-i)*Math.sin(r)+o,(e-o)*Math.sin(r)+(t-i)*Math.cos(r)+i]},o.prototype.setResizedValue=function(e,t,o,i){switch(e){case"x":t+=o;break;case"y":t+=i;break;case"abs-x":t+=o>0?-o:Math.abs(o);break;case"abs-y":t+=i>0?-i:Math.abs(i);break;case"y-abs-x":t+=i+(o>0?-o:Math.abs(o))/2;break;case"abs-x-abs-y":t+=(o>0?-o:Math.abs(o))+(i>0?-i:Math.abs(i))/2;break;case"abs-y-x":t+=(i>0?-i:Math.abs(i))+o/2;break;case"x-y":t+=o+i/2;break;case"y-x":t+=i+o/2;break;case"img-resize-x":t+=o;break;case"img-resize-y":t+=i}return t},o.prototype.getResizeDirection=function(e,t,o,i,r,a){var n=i*(180/Math.PI),s=this.getResizedElement(n,this.resizedElement);"e-resize"===this.resizedElement?(e.width=this.setResizedValue(s,e.width,t,o),e.endX=e.width+e.startX):"n-resize"===this.resizedElement?(e.startY=this.setResizedValue(s,e.startY,t,o),e.height=e.endY-e.startY):"w-resize"===this.resizedElement?(e.startX=this.setResizedValue(s,e.startX,t,o),e.width=e.startX+e.endX):"s-resize"===this.resizedElement?(e.height=this.setResizedValue(s,e.height,t,o),e.endY=e.height+e.startY):r&&"img-resize"===r?(e.width=this.setResizedValue("img-resize-x",e.width,t,o),e.height=this.setResizedValue("img-resize-y",e.height,t,o),"se-resize"===a?(e.endX=e.width+e.startX,e.endY=e.height+e.startY):"sw-resize"===a?(e.startX=e.endX-e.width,e.endY=e.height+e.startY):"ne-resize"===a?(e.endX=e.width+e.startX,e.startY=e.endY-e.height):"nw-resize"===a&&(e.startX=e.endX-e.width,e.startY=e.endY-e.height)):r&&"text"===r&&("widthHeight"===a?(e.width=this.setResizedValue("x-y",e.width,t,o),e.endX=e.width+e.startX,e.height=this.setResizedValue("y-x",e.height,t,o),e.endY=e.height+e.startY):"width"===a?(e.width=this.setResizedValue("x-y",e.width,t,o),e.endX=e.width+e.startX):"height"===a&&(e.height=this.setResizedValue("y-abs-x",e.height,t,o),e.endY=e.height+e.startY))},o.prototype.getResizedElement=function(e,t){var o=[];"n-resize"===t?o=[[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"===t?o=[[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"===t?o=[[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"===t&&(o=[[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 i=e<0?360-Math.abs(e):e,r=0,a=o;r<a.length;r++){var n=a[r],s=n[0],l=n[1],p=n[2];if(i>s&&i<=l||i+360>s&&i+360<=l)return p}return t},o.prototype.updateCursorStyles=function(e,o,i){var r=this.parent,a=!1;""===r.activeObj.keyHistory||void 0!==r.activeObj.shape||r.currObjType.isCustomCrop||r.currObjType.isLine||!r.currObjType.isText||(r.activeObj.shape="text");var n=t.extend({},r.activeObj,{},!0);if(!t.isNullOrUndefined(n.topLeftCircle)){var s;if((s=0===n.shapeDegree?r.transform.degree:r.transform.degree-n.shapeDegree)<0&&(s=360+s),this.isObjSelected)if("line"===n.shape||"arrow"===n.shape)a=this.updateCursorStylesForLineArrow(e,o,n);else if("path"===n.shape)a=this.updateCursorStylesForPath(e,o,n);else if(n.rotatedAngle)this.setCursorForRotatedObject(n,e,o,r.upperCanvas),"grabbing"===r.cursor?(r.upperCanvas.style.cursor=r.cursor="grabbing",this.dragElement=r.cursor):"move"===r.cursor?(this.dragPoint.startX=this.previousPoint.x=this.dragPoint.endX=e,this.dragPoint.startY=this.previousPoint.y=this.dragPoint.endY=o):"default"!==r.cursor&&(a=!0,this.dragElement=r.cursor,r.currObjType.isResize=!0);else{var l=this.getTransRotationPoint(n),p=n.topLeftCircle.radius;e>=n.topLeftCircle.startX-2*p&&e<=n.topLeftCircle.startX+2*p&&o>=n.topLeftCircle.startY-2*p&&o<=n.topLeftCircle.startY+2*p&&"nw-resize"!==this.dragElement?(n.topLeftCircle.startX=n.topLeftCircle.startY=0,r.upperCanvas.style.cursor=r.cursor="nw-resize",a=!0,this.dragElement=r.upperCanvas.style.cursor):e>=n.topLeftCircle.startX-2*p&&e<=n.topRightCircle.startX-2*p&&o>=n.topCenterCircle.startY-2*p&&o<=n.topCenterCircle.startY+2*p&&"n-resize"!==this.dragElement?(n.topCenterCircle.startX=n.topCenterCircle.startY=0,r.upperCanvas.style.cursor=r.cursor="n-resize",a=!0,this.dragElement=r.upperCanvas.style.cursor):e>=n.topRightCircle.startX-2*p&&e<=n.topRightCircle.startX+2*p&&o>=n.topRightCircle.startY-2*p&&o<=n.topRightCircle.startY+2*p&&"ne-resize"!==this.dragElement?(n.topRightCircle.startX=n.topRightCircle.startY=0,r.upperCanvas.style.cursor=r.cursor="ne-resize",a=!0,this.dragElement=r.upperCanvas.style.cursor):e>=n.centerLeftCircle.startX-2*p&&e<=n.centerLeftCircle.startX+2*p&&o>=n.topLeftCircle.startY-2*p&&o<=n.bottomLeftCircle.startY-2*p&&"w-resize"!==this.dragElement?(n.centerLeftCircle.startX=n.centerLeftCircle.startY=0,r.upperCanvas.style.cursor=r.cursor="w-resize",a=!0,this.dragElement=r.upperCanvas.style.cursor):e>=n.centerRightCircle.startX-2*p&&e<=n.centerRightCircle.startX+2*p&&o>=n.topRightCircle.startY-2*p&&o<=n.bottomRightCircle.startY-2*p&&"e-resize"!==this.dragElement?(n.centerRightCircle.startX=n.centerRightCircle.startY=0,r.upperCanvas.style.cursor=r.cursor="e-resize",a=!0,this.dragElement=r.upperCanvas.style.cursor):e>=n.bottomLeftCircle.startX-2*p&&e<=n.bottomLeftCircle.startX+2*p&&o>=n.bottomLeftCircle.startY-2*p&&o<=n.bottomLeftCircle.startY+2*p&&"sw-resize"!==this.dragElement?(n.bottomLeftCircle.startX=n.bottomLeftCircle.startY=0,r.upperCanvas.style.cursor=r.cursor="sw-resize",a=!0,this.dragElement=r.upperCanvas.style.cursor):e>=n.bottomLeftCircle.startX-2*p&&e<=n.bottomRightCircle.startX-2*p&&o>=n.bottomCenterCircle.startY-2*p&&o<=n.bottomCenterCircle.startY+2*p&&"s-resize"!==this.dragElement?(n.bottomCenterCircle.startX=n.bottomCenterCircle.startY=0,r.upperCanvas.style.cursor=r.cursor="s-resize",a=!0,this.dragElement=r.upperCanvas.style.cursor):e>=n.bottomRightCircle.startX-2*p&&e<=n.bottomRightCircle.startX+2*p&&o>=n.bottomRightCircle.startY-2*p&&o<=n.bottomRightCircle.startY+2*p&&"se-resize"!==this.dragElement?(n.bottomRightCircle.startX=n.bottomRightCircle.startY=0,r.upperCanvas.style.cursor=r.cursor="se-resize",a=!0,this.dragElement=r.upperCanvas.style.cursor):l&&e>=l.x-2*p&&e<=l.x+2*p&&o>=l.y-2*p&&o<=l.y+2*p&&"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=e,this.dragPoint.startY=this.previousPoint.y=this.dragPoint.endY=o),"text"!==n.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=e,this.dragPoint.startY=this.previousPoint.y=this.dragPoint.endY=o)}else this.dragPoint.startX=this.previousPoint.x=this.dragPoint.endX=e,this.dragPoint.startY=this.previousPoint.y=this.dragPoint.endY=o;this.previousPoint.x=this.previousPoint.y=this.diffPoint.x=this.diffPoint.y=0,"touchstart"===i?a||e>=n.activePoint.startX&&e<=n.activePoint.endX&&o>=n.activePoint.startY&&o<=n.activePoint.endY||"grabbing"===this.dragElement?r.currObjType.isDragging=!0:"line"===n.shape||"arrow"===n.shape?(this.setCursorForLineArrow(n,e,o,r.upperCanvas),"move"===r.cursor&&(r.currObjType.isDragging=!0)):"path"===n.shape&&(this.setCursorForPath(n,e,o,r.upperCanvas),"move"===r.cursor&&(r.currObjType.isDragging=!0)):r.currObjType.isDragging=!0,0===n.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=e,this.dragPoint.startY=this.previousPoint.y=this.dragPoint.endY=o)}},o.prototype.updateCursorStylesForLineArrow=function(e,t,o){for(var i,r=!1,a=this.parent,n=o.topLeftCircle.radius,s=0;s<5;s++)if(i=o.pointColl[s],e>=i.x-2*n&&e<=i.x+2*n&&t>=i.y-2*n&&t<=i.y+2*n){o.centerLeftCircle.startX=o.centerLeftCircle.startY=0,this.dragElement="w-resize",r=!0;break}if(!r)for(s=1;s<6;s++)if(i=o.pointColl[o.pointColl.length-s],e>=i.x-2*n&&e<=i.x+2*n&&t>=i.y-2*n&&t<=i.y+2*n){o.centerRightCircle.startX=o.centerRightCircle.startY=0,this.dragElement="e-resize",r=!0;break}if(!r)for(s=0;s<o.pointColl.length;s++){if(i=o.pointColl[s],e>=i.x-2*n&&e<=i.x+2*n&&t>=i.y-2*n&&t<=i.y+2*n){a.upperCanvas.style.cursor=a.cursor="move",this.dragPoint.startX=this.previousPoint.x=this.dragPoint.endX=e,this.dragPoint.startY=this.previousPoint.y=this.dragPoint.endY=t;break}a.upperCanvas.style.cursor=a.cursor="default"}return r},o.prototype.updateCursorStylesForPath=function(e,t,o){var i=!1,r=this.parent;return this.pathAdjustedIndex=this.setCursorForLineArrow(o,e,t,r.upperCanvas),"move"===r.cursor&&(i=!0,this.dragElement="pathDrag"),i||(r.upperCanvas.style.cursor=r.cursor="move",this.dragPoint.startX=this.previousPoint.x=this.dragPoint.endX=e,this.dragPoint.startY=this.previousPoint.y=this.dragPoint.endY=t),i},o.prototype.setTextSelection=function(e,t){var o=this.parent,i=o.activeObj.activePoint,r=o.transform.degree;(r=0===o.activeObj.shapeDegree?o.transform.degree:o.transform.degree-o.activeObj.shapeDegree)<0&&(r=360+r);for(var a=0,n=o.activeObj.flipObjColl.length;a<n;a++){var s=o.activeObj.flipObjColl[a].toLowerCase();switch(r){case 0:switch(s){case"horizontal":i={startX:i.endX-e,startY:i.startY,endX:i.endX,endY:i.startY+(t||0)};break;case"vertical":i.startY=i.endY-t,i={startX:i.startX,startY:i.startY,endX:i.startX+(e||0),endY:i.endY};break;default:i={startX:i.startX,startY:i.startY,endX:i.startX+(e||0),endY:i.startY+(t||0)}}break;case 90:switch(s){case"horizontal":i.endX=i.startX+t,i={startX:i.startX,startY:i.startY,endX:i.endX,endY:i.startY+(e||0)};break;case"vertical":i.startX=i.endX-t,i={startX:i.startX,startY:i.endY-e,endX:i.endX,endY:i.endY};break;default:i.startX=i.endX-t,i={startX:i.startX,startY:i.startY,endX:i.endX,endY:i.startY+(e||0)}}break;case 180:switch(s){case"horizontal":i.startY=i.endY-t,i={startX:i.startX,startY:i.startY,endX:i.startX+e,endY:i.endY};break;case"vertical":i.endY=i.startY+t,i={endX:i.endX,endY:i.endY,startX:i.endX-(e||0),startY:i.startY};break;default:i={endX:i.endX,endY:i.endY,startX:i.endX-(e||0),startY:i.endY-(t||0)}}break;case 270:switch(s){case"horizontal":i.startX=i.endX-t,i={startX:i.startX,startY:i.endY-(e||0),endX:i.endX,endY:i.endY};break;case"vertical":i={startX:i.startX,startY:i.startY,endX:i.startX+t,endY:i.startY+(e||0)};break;default:i.endX=i.startX+t,i={startX:i.startX,startY:i.endY-(e||0),endX:i.endX,endY:i.endY}}}}if(0===o.activeObj.flipObjColl.length)switch(r){case 0:i={startX:i.startX,startY:i.startY,endX:i.startX+(e||0),endY:i.startY+(t||0)};break;case 90:i.startX=i.endX-t,i={startX:i.startX,startY:i.startY,endX:i.endX,endY:i.startY+(e||0)};break;case 180:i={endX:i.endX,endY:i.endY,startX:i.endX-(e||0),startY:i.endY-(t||0)};break;case 270:i.endX=i.startX+t,i={startX:i.startX,startY:i.endY-(e||0),endX:i.endX,endY:i.endY}}i.width=i.endX-i.startX,i.height=i.endY-i.startY,o.activeObj.activePoint=i,360!==o.transform.degree&&-360!==o.transform.degree||(o.transform.degree=0)},o.prototype.setActivePoint=function(e,o){var i=this.parent,r=i.activeObj.activePoint;if(!t.isNullOrUndefined(r))if(i.currObjType.isText){var a=e||0,n=o||i.activeObj.textSettings.fontSize;void 0===i.activeObj.textSettings.fontSize&&(i.activeObj.textSettings.fontSize=.1*Math.abs(i.baseImgCanvas.width-i.baseImgCanvas.height)),this.setTextSelection(a,n),this.mouseDownPoint.x=r.endX,this.mouseDownPoint.y=r.endY,void 0!==i.activeObj.horTopLine&&(i.activeObj.activePoint=t.extend({},r,{},!0)),i.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate"}})}else if(e&&o)r.startX=this.mouseDownPoint.x=e,r.startY=this.mouseDownPoint.y=o,i.currObjType.isDragging=!0;else{var s=i.activeObj;(r={startX:s.horTopLine.startX,startY:s.horTopLine.startY,endX:s.horTopLine.endX,endY:s.horTopLine.endY}).width=r.endX-r.startX,r.height=r.endY-r.startY}},o.prototype.mouseDownEventHandler=function(e){var t=this.parent;if(t.isKBDNavigation=!1,this.mouseDown=e.currentTarget===t.lowerCanvas||e.currentTarget===t.upperCanvas?"canvas":"","touchstart"===e.type?this.isTouch=!0:this.isTouch=!1,"touchstart"!==e.type||e.currentTarget!==t.lowerCanvas||t.isImageLoaded){this.isCropSelection=!1,this.isPan=!0;var o;if(void 0!==t.activeObj.shape&&(o=t.activeObj.shape.split("-")),void 0!==o&&"crop"===o[0]&&(this.isCropSelection=!0),this.isCropSelection&&(this.dragCanvas=t.togglePan=!0),"grabbing"===t.cursor){var i={shapeSettingsObj:{}};this.isGrabbing=!0,t.notify("selection",{prop:"updatePrevShapeSettings",onPropertyChange:!1,value:{obj:i}});var r=i.shapeSettingsObj,a={cancel:!1,action:"rotate-start",previousShapeSettings:r},n={cancel:!1,action:"rotate-start",previousShapeSettings:r};this.triggerShapeChange(a,n,"mouse-down")}var s={point:this.setXYPoints(e)};t.trigger("click",s),this.clickEvent(s,e)}},o.prototype.getImagePoints=function(e,t){var o=this.parent.img,i=o.destLeft,r=o.destTop,a=o.destWidth,n=o.destHeight;return e<i?e=i:e>i+a&&(e=i+a),t<r?t=r:t>r+n&&(t=r+n),{x:e,y:t}},o.prototype.clickEvent=function(o,i){var r=this.parent,a=r.activeObj.activePoint,n=o.point.x,s=o.point.y,l=r.activeObj.shape&&"text"===r.activeObj.shape?r.cursor:"default";if(r.isResize)return this.performEnterAction(),void(r.upperCanvas.style.cursor="default");if(JSON.stringify(r.frameObj)!==JSON.stringify(r.tempFrameObj))r.okBtn();else if(""!==this.currentDrawingShape&&(this.isTouch&&!this.isShapeTouch(i,this.isCropSelection)||"crosshair"===r.upperCanvas.style.cursor||r.isShapeDrawing)){r.drawingShape&&!r.isShapeDrawing&&(r.okBtn(),r.enableShapeDrawing(r.toPascalCase(r.drawingShape),!0)),a=r.activeObj.activePoint;var p={currObj:{}};r.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:p}}),this.initialPrevObj=p.currObj,this.initialPrevObj.objColl=t.extend([],r.objColl,[],!0),this.initialPrevObj.pointColl=t.extend([],r.pointColl,[],!0),this.initialPrevObj.afterCropActions=t.extend([],r.afterCropActions,[],!0);var h={selPointColl:null};if(r.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:h}}),this.initialPrevObj.selPointColl=t.extend([],h.selPointColl,[],!0),this.setActivePoint(n,s),a=r.activeObj.activePoint,"path"===this.currentDrawingShape){Y=this.getImagePoints(n,s);r.activeObj.pointColl.push({x:Y.x,y:Y.y}),0!==a.width&&0!==a.height&&(a.width=0,a.height=0,a.startX=r.activeObj.pointColl[r.activeObj.pointColl.length-1].x,a.startY=r.activeObj.pointColl[r.activeObj.pointColl.length-1].y)}if(a.endX=a.startX,a.endY=a.startY,"text"===this.currentDrawingShape){r.activeObj.textSettings.fontSize=11,this.previousPoint.x=a.startX,this.previousPoint.y=a.startY,r.notify("shape",{prop:"updateFontStyles",onPropertyChange:!1,value:{isTextBox:null}});var d=this.upperContext.measureText(r.activeObj.textSettings.text).width+.5*r.activeObj.textSettings.fontSize;a.endX=a.startX+d,a.endY=a.startY+r.activeObj.textSettings.fontSize,a.width=a.endX-a.startX,a.height=a.endY-a.startY}else"arrow"===this.currentDrawingShape&&(r.activeObj.start=this.arrowShape[0],r.activeObj.end=this.arrowShape[1]);r.currObjType.isDragging=!0;var c=this.updatePrevShapeSettings(),u={cancel:!1,action:"draw-start",previousShapeSettings:c},v={cancel:!1,action:"move",previousShapeSettings:c};return this.shapeResizingArgs=u,this.shapeMovingArgs=v,this.triggerShapeChange(u,v,"mouse-down"),r.activeObj.activePoint=a,void(r.isShapeDrawing=!0)}r.notify("draw",{prop:"resetFrameZoom",onPropertyChange:!1,value:{isOk:!0}}),this.isCropSelection&&this.dragCanvas&&(this.setCursor(n,s),"move"!==r.cursor&&"crosshair"!==r.cursor&&"default"!==r.cursor&&"grab"!==r.cursor&&(this.isPan=!1)),r.activeObj.shape?this.isObjSelected=!0:this.isObjSelected=!1;var g={currObj:{}};r.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:g}});var f=g.currObj,C=t.extend({},r.activeObj,null,!0),b=this.isShapeTouch(i,this.isCropSelection),m=this.isFreehandDrawTouch(i,this.isCropSelection),y=b||this.isShapeClick(i,this.isCropSelection),P=this.applyCurrShape(y),j="none"!==r.textArea.style.display;if(this.isTouch&&!b&&C.shape&&!this.isCropSelection){this.applyObj(n,s)&&(r.okBtn(!0),r.notify("draw",{prop:"setPrevActObj",onPropertyChange:!1,value:{prevActObj:null}}));var x=t.extend({},r.cropObj,{},!0);r.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"shapeTransform",previousObj:f,previousObjColl:f.objColl,previousPointColl:f.pointColl,previousSelPointColl:f.selPointColl,previousCropObj:x,previousText:null,currentText:null,previousFilter:null,isCircleCrop:r.isCircleCrop}}),P&&r.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"ok"}})}if(b||r.togglePen||this.isCropSelection||(r.notify("toolbar",{prop:"refresh-main-toolbar",onPropertyChange:!1}),r.notify("toolbar",{prop:"close-contextual-toolbar",onPropertyChange:!1})),!this.dragCanvas||!this.isPan||"grab"!==r.cursor&&!this.isTouch||b||m||r.togglePen){var w=!1;!r.activeObj.shape||"line"!==r.activeObj.shape&&"arrow"!==r.activeObj.shape||(w=!0);var O=this.setXYPoints(i),S=O.x,T=O.y;if(this.applyObj(S,T)){if(r.okBtn(!0),P){var F=r.cursor;r.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"ok"}}),r.cursor=F}r.notify("draw",{prop:"setPrevActObj",onPropertyChange:!1,value:{prevActObj:null}})}r.notify("shape",{prop:"redrawActObj",onPropertyChange:!1,value:{x:S,y:T,isMouseDown:!0}});var k={index:null};r.notify("freehand-draw",{prop:"getFreehandDrawHoveredIndex",onPropertyChange:!1,value:{obj:k}});var I={freehandSelectedIndex:null};if(r.notify("freehand-draw",{prop:"getFreehandSelectedIndex",onPropertyChange:!1,value:{obj:I}}),this.isFhdPoint||this.isFhdCustomized&&!r.togglePen){if(!t.isNullOrUndefined(I.freehandSelectedIndex)&&I.freehandSelectedIndex!==k.index){var A=k.index;if(r.okBtn(),this.isFhdCustomized=!1,r.notify("freehand-draw",{prop:"setFreehandDrawHoveredIndex",onPropertyChange:!1,value:{index:A}}),k.index>-1){D=r.pointColl[k.index].strokeColor;r.notify("freehand-draw",{prop:"hoverFhd",onPropertyChange:!1,value:{strokeColor:D,strokeWidth:r.pointColl[k.index].strokeWidth}})}}I.freehandSelectedIndex=null,r.notify("freehand-draw",{prop:"getFreehandSelectedIndex",onPropertyChange:!1,value:{obj:I}});var z=t.extend([],r.objColl,[],!0);if(!t.isNullOrUndefined(k.index)&&k.index>-1)r.notify("freehand-draw",{prop:"selectFhd",value:{type:"ok"}}),r.notify("freehand-draw",{prop:"hoverFhd",onPropertyChange:!1,value:{strokeColor:null,strokeWidth:null}}),r.notify("toolbar",{prop:"renderQAT",onPropertyChange:!1,value:{isPenEdit:!0}});else if(I.freehandSelectedIndex){r.okBtn();var D=r.pointColl[I.freehandSelectedIndex].strokeColor;r.notify("freehand-draw",{prop:"hoverFhd",onPropertyChange:!1,value:{strokeColor:D,strokeWidth:r.pointColl[I.freehandSelectedIndex].strokeWidth}})}else this.findTargetObj(S,T,!1)&&(r.objColl=z,this.findTarget(S,T,i.type),r.notify("draw",{prop:"redrawDownScale"}))}else{if(this.isFhdEditing){r.apply();var X=document.getElementById(r.element.id+"_quickAccessToolbarArea");X&&(X.style.display="none");var Y=r.pointColl[I.freehandSelectedIndex],R={id:"pen_"+(I.freehandSelectedIndex+1),type:e.ShapeType.FreehandDraw,startX:Y.points[0].x,startY:Y.points[0].y,strokeColor:Y.strokeColor,strokeWidth:Y.strokeWidth,points:Y.points,opacity:Y.opacity,index:Y.order},L={action:"apply",currentShapeSettings:t.extend({},R,{},!0)};r.trigger("shapeChange",L)}var E=r.togglePen;if(r.notify("toolbar",{prop:"close-contextual-toolbar",onPropertyChange:!1}),E&&r.freeHandDraw(!0),this.isFhdEditing=!1,w?this.setCursor(S,T):"default"!==l&&(r.upperCanvas.style.cursor=r.cursor=l),"crosshair"===r.cursor||t.Browser.isDevice&&r.togglePen){if(r.togglePen){if(t.isNullOrUndefined(r.activeObj.strokeSettings)){var H={strokeSettings:{}};r.notify("shape",{prop:"getStrokeSettings",onPropertyChange:!1,value:{obj:H}}),r.activeObj.strokeSettings=H.strokeSettings}var B={penStrokeWidth:null};r.notify("freehand-draw",{prop:"getPenStrokeWidth",onPropertyChange:!1,value:{obj:B}}),t.isNullOrUndefined(B.penStrokeWidth)&&r.notify("freehand-draw",{prop:"setPenStrokeWidth",onPropertyChange:!1,value:{value:2}}),this.upperContext.strokeStyle=r.activeObj.strokeSettings.strokeColor,this.upperContext.fillStyle=r.activeObj.strokeSettings.strokeColor,r.notify("freehand-draw",{prop:"freehandDownHandler",onPropertyChange:!1,value:{e:i,canvas:r.upperCanvas}})}else r.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),this.upperContext.clearRect(0,0,r.upperCanvas.width,r.upperCanvas.height);r.currObjType.isActiveObj=!1,this.dragElement="",this.dragPoint.startX=this.dragPoint.startY=this.dragPoint.endX=this.dragPoint.endY=0}"crosshair"!==r.cursor&&"touchstart"===i.type.toLowerCase()||r.currObjType.isActiveObj&&"default"!==r.cursor&&!r.togglePen?(r.notify("draw",{prop:"updateTempObjColl"}),r.notify("draw",{prop:"updateTempPointColl"}),this.findTarget(S,T,i.type),r.notify("draw",{prop:"redrawDownScale"})):""!==r.currObjType.shape&&!r.currObjType.isCustomCrop||r.togglePen||"default"===r.cursor||this.setActivePoint(S,T),j&&r.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.lowerContext}})}}else{if(this.applyObj(n,s)){if(r.okBtn(!0),P){var M=r.cursor;r.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"ok"}}),r.cursor=M}r.notify("draw",{prop:"setPrevActObj",onPropertyChange:!1,value:{prevActObj:null}})}this.isFhdEditing&&(r.notify("freehand-draw",{prop:"applyFhd",onPropertyChange:!1}),this.isFhdCustomized=!1,r.notify("toolbar",{prop:"destroy-qa-toolbar",onPropertyChange:!1}));var U=r.activeObj.shape,W=["rectangle","ellipse","line","arrow","path","text","image"];U&&W.indexOf(U)>-1&&(r.notify("shape",{prop:"redrawActObj",onPropertyChange:!1,value:{x:null,y:null,isMouseDown:null}}),r.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),r.notify("toolbar",{prop:"setCurrentToolbar",value:{type:"main"}}),r.notify("toolbar",{prop:"refresh-main-toolbar",onPropertyChange:!1})),this.canvasMouseDownHandler(i)}this.isShapeInserted=!1,this.tempActiveObj=t.extend({},r.activeObj,{},!0)},o.prototype.mouseMoveEventHandler=function(o){var i=this.parent,r=i.cursor,a=i.upperCanvas.style.cursor;if(o.preventDefault(),!this.isPreventShaping){if("grabbing"===i.cursor&&this.isGrabbing){var n={shapeSettingsObj:{}};i.notify("selection",{prop:"updatePrevShapeSettings",onPropertyChange:!1,value:{obj:n}});var s=n.shapeSettingsObj,l={cancel:!1,action:"rotating",previousShapeSettings:s},p={cancel:!1,action:"rotating",previousShapeSettings:s};this.triggerShapeChange(l,p,"mouse-down")}this.timer&&this.timer>0&&(this.timer=0);var h=i.lowerCanvas.getBoundingClientRect();if("touchmove"===o.type&&2===o.touches.length){if(this.isFirstMove)this.startTouches=this.targetTouches(o.touches),this.tempTouches=[],this.tempTouches.push({x:o.touches[0].clientX||o.touches[0].pageX-i.lowerCanvas.offsetLeft-h.left,y:(o.touches[0].clientY||o.touches[0].pageY-i.lowerCanvas.offsetTop)-h.top}),this.tempTouches.push({x:(o.touches[1].clientX||o.touches[1].pageX-i.lowerCanvas.offsetLeft)-h.left,y:(o.touches[1].clientY||o.touches[1].pageY-i.lowerCanvas.offsetTop)-h.top});else{var d=(o.touches[0].clientX||o.touches[0].pageX-i.lowerCanvas.offsetLeft)-h.left,c=(o.touches[0].clientY||o.touches[0].pageY-i.lowerCanvas.offsetTop)-h.top,u=(o.touches[1].clientX||o.touches[1].pageX-i.lowerCanvas.offsetLeft)-h.left,v=(o.touches[1].clientY||o.touches[1].pageY-i.lowerCanvas.offsetTop)-h.top,g={x:d<u?u-(u-d)/2:d-(d-u)/2,y:c<v?v-(v-c)/2:c-(c-v)/2};if(this.currMousePoint.x!==g.x&&this.currMousePoint.y!==g.y){var f="";if("touchmove"===o.type&&(i.zoomSettings.zoomTrigger&e.ZoomTrigger.Pinch)===e.ZoomTrigger.Pinch){this.zoomType="Pinch";var C=this.calculateScale(this.startTouches,this.targetTouches(o.touches));this.startTouches=this.targetTouches(o.touches),C>1?f="zoomIn":C<1&&(f="zoomOut")}""!==f&&i.notify("draw",{prop:"performPointZoom",onPropertyChange:!1,value:{x:g.x,y:g.y,type:f,isResize:null}}),this.tempTouches=[],this.tempTouches.push({x:o.touches[0].clientX||o.touches[0].pageX-i.lowerCanvas.offsetLeft,y:o.touches[0].clientY||o.touches[0].pageY-i.lowerCanvas.offsetTop}),this.tempTouches.push({x:o.touches[1].clientX||o.touches[1].pageX-i.lowerCanvas.offsetLeft,y:o.touches[1].clientY||o.touches[1].pageY-i.lowerCanvas.offsetTop}),this.currMousePoint.x=g.x,this.currMousePoint.y=g.y,this.isPinching=!0}}return void(this.isFirstMove=!1)}var b,m;"mousemove"===o.type?(b=o.clientX,m=o.clientY):(this.touchEndPoint.x=b=o.touches[0].clientX,this.touchEndPoint.y=m=o.touches[0].clientY),b-=h.left,m-=h.top,this.canvasMouseMoveHandler(o);var y,P=!1;void 0!==i.activeObj.shape&&(y=i.activeObj.shape.split("-")),void 0!==y&&"crop"===y[0]&&(P=!0),P&&i.notify("transform",{prop:"disableZoomOutBtn",value:{isZoomOut:!0}}),i.upperCanvas.style.cursor=a,i.cursor=r,(i.currObjType.isActiveObj&&(void 0!==i.activeObj.activePoint||i.objColl.length>0)&&!this.dragCanvas||void 0!==i.activeObj.activePoint)&&""===this.dragElement&&(this.setCursor(b,m),i.activeObj.activePoint&&(0===i.activeObj.activePoint.width||!t.isNullOrUndefined(i.activeObj.currIndex)&&this.cursorTargetId!==i.activeObj.currIndex)&&"default"!==i.cursor&&"move"!==i.cursor&&"crosshair"!==i.cursor&&"grab"!==i.cursor&&"pointer"!==i.cursor&&(i.upperCanvas.style.cursor=i.cursor="move"),this.findTarget(b,m,o.type));var j=i.img,x=j.destLeft,w=j.destTop,O=j.destWidth,S=j.destHeight;i.currObjType.isDragging&&(this.upperContext.clearRect(0,0,i.lowerCanvas.width,i.lowerCanvas.height),this.updateActivePoint(b,m,P),i.notify("shape",{prop:"updateTrianglePoints",onPropertyChange:!1,value:{obj:i.activeObj}}),this.isPreventDragging?(i.activeObj.activePoint.startX>x&&i.activeObj.activePoint.endX<x+O&&i.activeObj.activePoint.startY>w&&i.activeObj.activePoint.endY<w+S&&(this.isPreventDragging=!1),i.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate",obj:null,isCropRatio:null,points:null,isPreventDrag:!0,saveContext:null,isPreventSelection:null}})):i.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate",obj:null,isCropRatio:null,points:null,isPreventDrag:null,saveContext:null,isPreventSelection:null}}),P&&(this.dragCanvas=i.togglePan=!0))}},o.prototype.mouseUpEventHandler=function(e){var o=this.parent,i=o.element.id;if(o.isKBDNavigation=!1,t.Browser.isDevice||!(o.element.querySelector("#"+i+"_contextualToolbar")&&!o.element.querySelector("#"+i+"_contextualToolbar").parentElement.classList.contains("e-hide")||o.element.querySelector("#"+i+"_headWrapper")&&!o.element.querySelector("#"+i+"_headWrapper").parentElement.classList.contains("e-hide"))){if("grabbing"===o.cursor&&this.isGrabbing){I={shapeSettingsObj:{}};o.notify("selection",{prop:"updatePrevShapeSettings",onPropertyChange:!1,value:{obj:I}});var r=I.shapeSettingsObj,a={cancel:!1,action:"rotate-end",previousShapeSettings:r},n={cancel:!1,action:"rotate-end",previousShapeSettings:r};this.triggerShapeChange(a,n,"mouse-up")}if(this.isGrabbing=!1,this.isPreventShaping&&(this.isPreventShaping=!1),"canvas"===this.mouseDown||this.isSliderActive||e.target.closest(".e-image-editor")||e.target.closest(".e-ie-ddb-popup")){"touchstart"===e.type?this.isTouch=!1:"touchend"===e.type&&e.stopImmediatePropagation(),e.preventDefault(),o.togglePan&&this.canvasMouseUpHandler(e);var s=void 0,l=void 0;"mouseup"===e.type?(s=e.clientX,l=e.clientY):(s=this.touchEndPoint.x,l=this.touchEndPoint.y);var p=o.lowerCanvas.getBoundingClientRect();s-=p.left,l-=p.top;var h=void 0,d=this.currentDrawingShape,c=!1;if("touchend"===e.type&&(this.startTouches=this.tempTouches=[],this.isFirstMove=!1,"none"===o.textArea.style.display&&(this.timer=0),this.isPinching))return this.isPinching=!1,o.notify("draw",{prop:"redrawDownScale"}),(o.isCropTab||o.activeObj.shape)&&(o.notify("draw",{prop:"setStraightenActObj",value:{activeObj:null}}),o.notify("freehand-draw",{prop:"resetStraightenPoint"})),void(o.isStraightening&&(o.notify("draw",{prop:"resetStraightenDestPoints"}),o.notify("draw",{prop:"setDestForStraighten"})));var u=!1,v=void 0;if(void 0!==o.activeObj.shape&&(v=o.activeObj.shape.split("-")),void 0!==v&&"crop"===v[0]&&(u=!0),"path"===this.currentDrawingShape&&o.isShapeDrawing){var g=e.srcElement,f=g.parentElement.id,C=o.element.id;return void(e.currentTarget!==o.upperCanvas&&e.currentTarget!==o.lowerCanvas&&o.activeObj.pointColl.length>0&&(g.classList.contains("e-upload-icon")||f===C+"_zoomIn"||f===C+"_zoomOut"||f===C+"_annotationBtn"||f===C+"_borderColorBtn"||f===C+"_borderWidthBtn")&&(o.notify("shape",{prop:"stopPathDrawing",onPropertyChange:!1,value:{e:e,isApply:!0}}),this.upperContext.clearRect(0,0,o.upperCanvas.width,o.upperCanvas.height),o.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate",obj:o.activeObj,isCropRatio:null,points:null,isPreventDrag:!0,saveContext:null,isPreventSelection:!0}})))}if(e.currentTarget===o.upperCanvas&&!o.isResize){if(this.pathAdjustedIndex=null,""!==this.currentDrawingShape){if("text"===this.currentDrawingShape){var b=t.extend({},o.cropObj,{},!0);o.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"shapeInsert",previousObj:this.initialPrevObj,previousObjColl:this.initialPrevObj.objColl,previousPointColl:this.initialPrevObj.pointColl,previousSelPointColl:this.initialPrevObj.selPointColl,previousCropObj:b,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}})}else o.notify("undo-redo",{prop:"updateUrObj",onPropertyChange:!1,value:{objColl:this.initialPrevObj.objColl,operation:"shapeInsert"}});this.isShapeInserted=!0,this.currentDrawingShape="",(o.activeObj.shape&&"path"===o.activeObj.shape&&0===o.activeObj.pointColl.length||(!o.activeObj.shape||"path"!==o.activeObj.shape)&&0===o.activeObj.activePoint.width&&0===o.activeObj.activePoint.height)&&(c=!0,o.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),this.upperContext.clearRect(0,0,o.upperCanvas.width,o.upperCanvas.height));var m=this.updatePrevShapeSettings(),a={cancel:!1,action:"draw-end",previousShapeSettings:m},n={cancel:!1,action:"move",previousShapeSettings:m};this.shapeResizingArgs=a,this.shapeMovingArgs=n,this.triggerShapeChange(a,n,"mouse-up")}this.adjustActObjForLineArrow(),this.updPtCollForShpRot(),o.currObjType.shape=o.currObjType.shape.toLowerCase();var y=t.extend({},o.cropObj,{},!0),P={currObj:{}};o.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:P}});var j=P.currObj;j.objColl=t.extend([],o.objColl,[],!0),j.pointColl=t.extend([],o.pointColl,[],!0),j.afterCropActions=t.extend([],o.afterCropActions,[],!0);var x={selPointColl:null};if(o.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:x}}),j.selPointColl=t.extend([],x.selPointColl,[],!0),!o.togglePen&&!u){if(this.tempObjColl&&0!==o.activeObj.activePoint.width){o.notify("shape",{prop:"updImgRatioForActObj",onPropertyChange:!1}),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:j,previousObjColl:this.tempObjColl,previousPointColl:j.pointColl,previousSelPointColl:j.selPointColl,previousCropObj:y,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}});var w=t.extend({},o.objColl[o.objColl.length-1],{},!0);o.objColl.pop(),this.redrawShape(w),this.tempObjColl=void 0}this.isFhdEditing||(this.applyCurrActObj(s,l),o.currObjType.isResize=!1,o.notify("toolbar",{prop:"destroy-qa-toolbar",onPropertyChange:!1}))}if(o.activeObj){var O,S=!1;void 0!==o.activeObj.shape&&(O=o.activeObj.shape.split("-")),void 0===O&&(o.currObjType.isCustomCrop||o.togglePen)?S=!0:void 0!==O&&"crop"===O[0]&&(S=!0);var T=o.activeObj.shape;if(h=T,["rectangle","ellipse","line","arrow","path"].indexOf(T)>-1)o.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"shapes",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}});else if("text"===T)"none"===o.textArea.style.display&&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(!S){var F={type:"main",isApplyBtn:null,isCropping:!1,isZooming:null};o.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:F})}if(o.notify("toolbar",{prop:"update-toolbar-items",onPropertyChange:!1}),!this.isFhdEditing&&(o.activeObj.shape&&"text"===o.activeObj.shape&&11===o.activeObj.textSettings.fontSize&&55===Math.floor(o.activeObj.activePoint.width)&&11===Math.floor(o.activeObj.activePoint.height)&&o.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),!S))if(this.adjustActObjForLineArrow(),o.isShapeDrawing){k=this.currentDrawingShape;o.notify("undo-redo",{prop:"updateUndoRedoStack",onPropertyChange:!1}),this.currentDrawingShape=k}else o.notify("undo-redo",{prop:"updateUndoRedoStack",onPropertyChange:!1})}}if(void 0!==o.activeObj.shape&&(v=o.activeObj.shape.split("-")),void 0!==v&&"crop"===v[0]&&(u=!0),o.activeObj.shape&&!u&&e.currentTarget===o.upperCanvas&&"none"===o.textArea.style.display){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{var k=this.currentDrawingShape;this.currentDrawingShape="",o.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"shapes",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}}),this.currentDrawingShape=k}o.notify("toolbar",{prop:"update-toolbar-items",onPropertyChange:!1}),o.notify("toolbar",{prop:"renderQAT",onPropertyChange:!1,value:{isPenEdit:null}})}var I={freehandDrawSelectedId:null};o.notify("freehand-draw",{prop:"getFreehandDrawSelectedId",onPropertyChange:!1,value:{obj:I}}),o.togglePen&&e.currentTarget===o.upperCanvas&&!I.freehandDrawSelectedId?(o.notify("freehand-draw",{prop:"freehandUpHandler",onPropertyChange:!1,value:{e:e,canvas:o.upperCanvas,context:this.upperContext}}),o.togglePen&&(t.isNullOrUndefined(o.toolbar)||o.toolbar&&o.toolbar.length>0||!t.isNullOrUndefined(o.toolbarTemplate))&&(o.okBtn(),o.freeHandDraw(!0))):o.currObjType.shape="",this.dragElement="",this.mouseDown="",this.isSliderActive=!1,o.currObjType.isInitialLine=o.currObjType.isDragging=!1,this.selMouseUpEvent(),t.isNullOrUndefined(o.drawingShape)&&h&&""!==d&&(o.drawingShape=h),o.drawingShape&&(this.currentDrawingShape=o.drawingShape.toLowerCase(),c&&(o.enableShapeDrawing(o.toPascalCase(o.drawingShape),!0),o.upperCanvas.style.cursor="crosshair")),o.isShapeDrawing=!1}}},o.prototype.adjustActObjForLineArrow=function(e){var t=!1,o=this.parent;if((e=e||o.activeObj).shape&&("line"===e.shape||"arrow"===o.activeObj.shape)){var i=void 0;if(("e-resize"===this.dragElement&&e.activePoint.endX<e.activePoint.startX||"w-resize"===this.dragElement&&e.activePoint.startX>e.activePoint.endX)&&(t=!0,i=e.activePoint.startX,e.activePoint.startX=e.activePoint.endX,e.activePoint.endX=i,i=e.activePoint.startY,e.activePoint.startY=e.activePoint.endY,e.activePoint.endY=i),e.activePoint.width=Math.abs(e.activePoint.endX-e.activePoint.startX),e.activePoint.height=Math.abs(e.activePoint.endY-e.activePoint.startY),"path"!==o.activeObj.shape){o.notify("shape",{prop:"setPointCollForLineArrow",onPropertyChange:!1,value:{obj:e}});for(var r=0;r<e.pointColl.length;r++)e.pointColl[r].ratioX=(e.pointColl[r].x-o.img.destLeft)/o.img.destWidth,e.pointColl[r].ratioY=(e.pointColl[r].y-o.img.destTop)/o.img.destHeight}}return t},o.prototype.updPtCollForShpRot=function(e){var t=this.parent;if((e=e||t.activeObj).shape&&0!==e.rotatedAngle){t.notify("shape",{prop:"setPointCollForShapeRotation",onPropertyChange:!1,value:{obj:e}});var o=t.img,i=o.destLeft,r=o.destTop,a=o.destWidth,n=o.destHeight,s=e.horTopLinePointColl,l=e.horBottomLinePointColl,p=e.verLeftLinePointColl,h=e.verRightLinePointColl,d=function(e){e.ratioX=(e.x-i)/a,e.ratioY=(e.y-r)/n};s.forEach(d),l.forEach(d),p.forEach(d),h.forEach(d)}},o.prototype.setXYPoints=function(e){e.preventDefault();var t,o;"mousedown"===e.type?(t=e.clientX,o=e.clientY):(this.touchEndPoint.x=t=e.touches[0].clientX,this.touchEndPoint.y=o=e.touches[0].clientY);var i=this.parent.lowerCanvas.getBoundingClientRect();return t-=i.left,o-=i.top,{x:t,y:o}},o.prototype.getCurrentIndex=function(){for(var e,t=this.parent,o=0,i=t.objColl.length;o<i;o++)if(t.activeObj.currIndex===t.objColl[o].currIndex){e=o;break}return e},o.prototype.isShapeClick=function(e,o){var i=this.parent,r=!1;if(i.togglePen)return r;if(i.activeObj.shape&&"text"===i.activeObj.shape&&this.isShapeInserted){var a="block"===i.textArea.style.display||"inline-block"===i.textArea.style.display,n=t.extend({},i.activeObj,null,!0);i.notify("shape",{prop:"redrawActObj",onPropertyChange:!1,value:{x:null,y:null,isMouseDown:!0}});var s=this.setXYPoints(e),l=s.x,p=s.y;if(r=this.findTargetObj(l,p,o),o||(this.upperContext.clearRect(0,0,i.upperCanvas.width,i.upperCanvas.height),r&&i.notify("shape",{prop:"redrawActObj",onPropertyChange:!1,value:{x:null,y:null,isMouseDown:!0}})),a){i.textArea.value=i.objColl[i.objColl.length-1].keyHistory,i.textArea.style.display="block",i.activeObj=n;h=this.getCurrentIndex();t.isNullOrUndefined(h)?i.objColl.pop():i.objColl.splice(h,1)}else if(!r&&n.shape){i.activeObj=n;var h=this.getCurrentIndex();t.isNullOrUndefined(h)||JSON.stringify(i.activeObj.activePoint)!==JSON.stringify(i.objColl[h].activePoint)?t.isNullOrUndefined(i.activeObj.currIndex)&&i.objColl.pop():i.objColl.splice(h,1)}}return r},o.prototype.isShapeTouch=function(e,o){var i=this.parent,r=!1;if("touchstart"===e.type&&!i.togglePen){i.activeObj&&"text"===i.activeObj.shape&&(this.timer=setTimeout(this.setTimer.bind(this),1e3,e));var a="block"===i.textArea.style.display||"inline-block"===i.textArea.style.display,n=t.extend({},i.activeObj,null,!0);i.notify("shape",{prop:"redrawActObj",onPropertyChange:!1,value:{x:null,y:null,isMouseDown:!0}});var s=this.setXYPoints(e),l=s.x,p=s.y;if(r=this.findTargetObj(l,p,o),o||this.upperContext.clearRect(0,0,i.upperCanvas.width,i.upperCanvas.height),a){i.textArea.value=i.objColl[i.objColl.length-1].keyHistory,i.textArea.style.display="block",i.activeObj=n;h=this.getCurrentIndex();t.isNullOrUndefined(h)?i.objColl.pop():i.objColl.splice(h,1)}else if(!r&&n.shape&&(0!==n.activePoint.width||0!=n.activePoint.height)){i.activeObj=n;var h=this.getCurrentIndex();o||(t.isNullOrUndefined(h)||JSON.stringify(i.activeObj.activePoint)!==JSON.stringify(i.objColl[h].activePoint)?t.isNullOrUndefined(i.activeObj.currIndex)&&i.objColl.pop():i.objColl.splice(h,1))}}return r},o.prototype.isFreehandDrawTouch=function(e,o){var i=this.parent,r=!1;if("touchstart"===e.type&&!o&&!i.togglePen){var a="block"===i.textArea.style.display||"inline-block"===i.textArea.style.display,n=t.extend({},i.activeObj,null,!0);i.notify("shape",{prop:"redrawActObj",onPropertyChange:!1,value:{x:null,y:null,isMouseDown:!0}});var s=this.setXYPoints(e),l=s.x,p=s.y;if(this.setCursor(l,p),this.isFhdPoint&&(r=!0),a){i.textArea.value=i.objColl[i.objColl.length-1].keyHistory,i.textArea.style.display="block",i.activeObj=n;h=this.getCurrentIndex();t.isNullOrUndefined(h)?i.objColl.pop():i.objColl.splice(h,1)}else if(n.shape){i.activeObj=n;var h=this.getCurrentIndex();o||(t.isNullOrUndefined(h)||JSON.stringify(i.activeObj.activePoint)!==JSON.stringify(i.objColl[h].activePoint)?t.isNullOrUndefined(i.activeObj.currIndex)&&i.objColl.pop():i.objColl.splice(h,1))}}return r},o.prototype.applyObj=function(e,t){var o=this.parent,i=!1;if(0===o.activeObj.activePoint.width&&0===o.activeObj.activePoint.height)return!1;var r=["rectangle","ellipse","line","arrow","path","image","text"],a=o.activeObj.activePoint,n=a.startX,s=a.startY,l=a.endX,p=a.endY;if(o.activeObj.shape&&r.indexOf(o.activeObj.shape)>-1){var h=o.activeObj.topLeftCircle.radius;i=!(e>=n-2*h&&e<=l+2*h&&t>=s-2*h&&t<=p+2*h)&&("default"===o.upperCanvas.style.cursor||"grab"===o.upperCanvas.style.cursor||"crosshair"===o.upperCanvas.style.cursor||"pointer"===o.upperCanvas.style.cursor||"move"===o.upperCanvas.style.cursor)}return i},o.prototype.applyCurrShape=function(e){var o=this.parent,i=!1;if(o.togglePen)return i;var r=t.extend({},o.activeObj,null,!0);if(this.isShapeInserted&&"text"===o.activeObj.shape&&e&&(this.isInitialTextEdited=!0,o.notify("draw",{prop:"setShapeTextInsert",onPropertyChange:!1,value:{bool:!0}})),"block"===o.textArea.style.display||"inline-block"===o.textArea.style.display){var a=t.extend({},o.activeObj,null,!0);o.notify("shape",{prop:"redrawActObj",onPropertyChange:!1,value:{x:null,y:null,isMouseDown:null}}),r=t.extend({},o.objColl[o.objColl.length-1],null,!0),o.objColl.pop(),o.activeObj=t.extend({},a,null,!0),o.textArea.value=r.keyHistory,o.textArea.style.display="block";var n=r.strokeSettings&&r.strokeSettings.strokeColor?"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]),parseFloat(r.strokeSettings.strokeColor.split("(")[1].split(",")[3])):r.strokeSettings.strokeColor:null;n&&"#ffffff"===n&&(n="#fff"),this.tempActiveObj.strokeSettings&&this.tempActiveObj.strokeSettings.strokeColor&&"#ffffff"===this.tempActiveObj.strokeSettings.strokeColor&&(this.tempActiveObj.strokeSettings.strokeColor="#fff"),(r.keyHistory!==this.tempActiveObj.keyHistory||n&&n!==this.tempActiveObj.strokeSettings.strokeColor||r.textSettings&&r.textSettings.fontFamily!==this.tempActiveObj.textSettings.fontFamily||r.textSettings&&Math.round(r.textSettings.fontSize)!==Math.round(this.tempActiveObj.textSettings.fontSize)||r.textSettings&&Math.round(r.textSettings.fontRatio)!==Math.round(this.tempActiveObj.textSettings.fontRatio)||r.textSettings&&r.textSettings.bold!==this.tempActiveObj.textSettings.bold||r.textSettings&&r.textSettings.italic!==this.tempActiveObj.textSettings.italic||r.textSettings&&r.textSettings.underline!==this.tempActiveObj.textSettings.underline)&&(i=!0),this.isInitialTextEdited&&!i&&(i=!0,this.isInitialTextEdited=!1)}else this.tempActiveObj.activePoint.height=Math.abs(this.tempActiveObj.activePoint.height),i=JSON.stringify(r)!==JSON.stringify(this.tempActiveObj);return i},o.prototype.canvasMouseDownHandler=function(e){var o=this.parent;e.preventDefault();var i,r;"mousedown"===e.type?(i=e.offsetX||e.pageX-o.lowerCanvas.offsetLeft,r=e.offsetY||e.pageY-o.lowerCanvas.offsetTop):(i=e.touches[0].clientX||e.touches[0].pageX-o.lowerCanvas.offsetLeft,r=e.touches[0].clientY||e.touches[0].pageY-o.lowerCanvas.offsetTop);var a=o.lowerCanvas.getBoundingClientRect();i-=a.left,r-=a.top,this.panDown={x:i,y:r};var n={tempPanMove:null};o.notify("transform",{prop:"getTempPanMove",onPropertyChange:!1,value:{obj:n}}),t.isNullOrUndefined(n.tempPanMove)&&o.notify("transform",{prop:"setTempPanMove",onPropertyChange:!1,value:{point:{x:i,y:r}}})},o.prototype.canvasMouseMoveHandler=function(e){var t=this.parent,o={bool:null};if(t.notify("toolbar",{prop:"getFrameToolbar",onPropertyChange:!1,value:{obj:o}}),t.isResize||o.bool)return void(t.upperCanvas.style.cursor="default");this.dragCanvas?t.lowerCanvas.style.cursor="grab":(this.dragCanvas=t.togglePan=!1,t.lowerCanvas.style.cursor=t.upperCanvas.style.cursor=t.cursor="default");var i,r;"mousemove"===e.type?(i=e.offsetX,r=e.offsetY):(i=e.touches[0].clientX||e.touches[0].pageX-t.lowerCanvas.offsetLeft,r=e.touches[0].clientY||e.touches[0].pageY-t.lowerCanvas.offsetTop);var a=t.lowerCanvas.getBoundingClientRect(),n={x:i-=a.left,y:r-=a.top};t.notify("transform",{prop:"setPanMove",onPropertyChange:!1,value:{point:{x:i,y:r}}}),this.panDown&&n&&t.togglePan&&this.dragCanvas&&((t.isCropTab||t.activeObj.shape)&&(t.notify("draw",{prop:"setStraightenActObj",value:{activeObj:null}}),t.notify("freehand-draw",{prop:"resetStraightenPoint"})),t.notify("transform",{prop:"drawPannedImage",onPropertyChange:!1,value:{xDiff:null,yDiff:null}}))},o.prototype.canvasMouseUpHandler=function(e){var t=this.parent;e.preventDefault();var o={panMove:null};t.notify("transform",{prop:"getPanMove",onPropertyChange:!1,value:{obj:o}}),t.togglePan&&this.panDown&&o.panMove&&t.togglePan&&this.dragCanvas&&(this.panDown=null,t.notify("transform",{prop:"setPanMove",onPropertyChange:!1,value:{point:null}})),t.notify("transform",{prop:"setTempPanMove",onPropertyChange:!1,value:{point:null}}),"path"!==this.currentDrawingShape&&(t.currObjType.isDragging=!1)},o.prototype.touchStartHandler=function(e){e.preventDefault();var o=this.parent;0===this.touchTime?this.touchTime=(new Date).getTime():(new Date).getTime()-this.touchTime<400?(o.notify("shape",{prop:"stopPathDrawing",onPropertyChange:!1,value:{e:e,isApply:null}}),this.touchTime=0):this.touchTime=(new Date).getTime(),2===e.touches.length?this.isFirstMove=!0:this.mouseDownEventHandler(e),t.EventHandler.add(o.lowerCanvas,"touchend",this.mouseUpEventHandler,this),t.EventHandler.add(o.lowerCanvas,"touchmove",this.mouseMoveEventHandler,this),t.EventHandler.add(o.upperCanvas,"touchend",this.mouseUpEventHandler,this),t.EventHandler.add(o.upperCanvas,"touchmove",this.mouseMoveEventHandler,this)},o.prototype.unwireEvent=function(){var e=this.parent;t.EventHandler.remove(e.lowerCanvas,"touchend",this.mouseUpEventHandler),t.EventHandler.remove(e.lowerCanvas,"touchmove",this.mouseMoveEventHandler),t.EventHandler.remove(e.upperCanvas,"touchend",this.mouseUpEventHandler),t.EventHandler.remove(e.upperCanvas,"touchmove",this.mouseMoveEventHandler)},o.prototype.keyDownEventHandler=function(o){var i=this.parent;!o.ctrlKey||"+"!==o.key&&"-"!==o.key||o.preventDefault();var r={fileName:"",fileType:null};i.notify("draw",{prop:"getFileName",onPropertyChange:!1,value:{obj:r}});var a={fileName:r.fileName,fileType:r.fileType,cancel:!1};switch(o.key){case o.ctrlKey&&"s":i.trigger("beforeSave",a),this.beforeSaveEvent(a,o);break;case o.ctrlKey&&"z":i.allowUndoRedo&&(i.noPushUndo=!1,(i.togglePen||i.drawingShape)&&(i.okBtn(),i.drawingShape=null),i.notify("undo-redo",{prop:"call-undo"}));break;case o.ctrlKey&&"y":i.allowUndoRedo&&(i.noPushUndo=!1,(i.togglePen||i.drawingShape)&&(i.okBtn(),i.drawingShape=null),i.notify("undo-redo",{prop:"call-redo"}));break;case o.ctrlKey&&"+":(i.zoomSettings.zoomTrigger&e.ZoomTrigger.Commands)===e.ZoomTrigger.Commands&&(this.zoomType="Commands",i.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:.1,zoomPoint:null},isResize:null}),i.notify("draw",{prop:"redrawDownScale"}),(i.isCropTab||i.activeObj.shape)&&(i.notify("draw",{prop:"setStraightenActObj",value:{activeObj:null}}),i.notify("freehand-draw",{prop:"resetStraightenPoint"})),i.isStraightening&&(i.notify("draw",{prop:"resetStraightenDestPoints"}),i.notify("draw",{prop:"setDestForStraighten"})));break;case o.ctrlKey&&"-":(i.zoomSettings.zoomTrigger&e.ZoomTrigger.Commands)===e.ZoomTrigger.Commands&&(this.zoomType="Commands",i.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:-.1,zoomPoint:null},isResize:null}),i.notify("draw",{prop:"redrawDownScale"}),(i.isCropTab||i.activeObj.shape)&&(i.notify("draw",{prop:"setStraightenActObj",value:{activeObj:null}}),i.notify("freehand-draw",{prop:"resetStraightenPoint"})),i.isStraightening&&(i.notify("draw",{prop:"resetStraightenDestPoints"}),i.notify("draw",{prop:"setDestForStraighten"})));break;case"Delete":this.deleteItem();break;case"Escape":i.notify("draw",{prop:"performCancel",value:{isContextualToolbar:null,isFinalCancel:!0}});break;case"Enter":this.performEnterAction(o);break;case"Tab":this.performTabAction();break;default:!t.Browser.isDevice||"block"!==i.textArea.style.display&&"inline-block"!==i.textArea.style.display||setTimeout(this.textKeyDown.bind(this),1,o)}},o.prototype.performEnterAction=function(e){var o=this.parent;if(o.isResize){var i=e.target,r=!!(i.id.indexOf("aspectratio")||i.id.indexOf("non-aspectratio")>-1);if(!this.isValueUpdated())return void(r&&this.focusRatioBtn());var a=this.getNumTextValue(),n=o.element.querySelector("#"+o.element.id+"_aspectratio"),s=o.element.querySelector(".e-ie-toolbar-aspect-ratio-btn");a&&a.x&&a.y&&(n||s&&!s.classList.contains("e-hidden")?o.notify("transform",{prop:"resize",value:{width:a.x,height:null,isAspectRatio:!0}}):o.notify("transform",{prop:"resize",value:{width:a.x,height:a.y,isAspectRatio:!1}}));var l=o.element.querySelector("#"+o.element.id+"_resizeHeight"),p=o.element.querySelector("#"+o.element.id+"_resizeWidth");if(t.isNullOrUndefined(n)){if(l){h=t.getComponent(l,"numerictextbox");l&&""===l.value&&(h.value=parseFloat(h.placeholder),l.value=h.placeholder+"px")}if(p){var h=t.getComponent(p,"numerictextbox");p&&""===p.value&&(h.value=parseFloat(h.placeholder),p.value=h.placeholder+"px")}}o.notify("draw",{prop:"redrawDownScale"}),r&&this.focusRatioBtn()}else if(e.target.classList.contains("e-upload")){var d=o.element.querySelector(".e-image-upload");d&&d.querySelector(".e-tbar-btn")&&d.querySelector(".e-tbar-btn").click()}else if(e.target.classList.contains("filter-wrapper"))e.target.parentElement.click();else{var c=void 0;o.activeObj.shape&&(c=o.activeObj.shape.split("-")),e&&this.isKeyBoardCrop(e)&&o.activeObj.horTopLine&&o.activeObj.shape&&"crop"===c[0]&&o.crop()}},o.prototype.focusRatioBtn=function(){var e=this.parent.element.id;this.parent.isKBDNavigation&&setTimeout(function(){document.getElementById(e+"_aspectratio")?document.getElementById(e+"_aspectratio").focus():document.getElementById(e+"_nonaspectratio")&&document.getElementById(e+"_nonaspectratio").focus()},50)},o.prototype.isKeyBoardCrop=function(e){var t=!1,o=e.target;return o.id!==this.parent.element.id+"_ok"&&""!==o.id||(t=!0),t},o.prototype.beforeSaveEvent=function(e,t){var o=this.parent;e.cancel||o.notify("export",{prop:"export",onPropertyChange:!1,value:{type:e.fileType,fileName:e.fileName}}),t.preventDefault(),t.stopImmediatePropagation()},o.prototype.handleScroll=function(t){var o,i,r=this.parent,a=!1;"mousewheel"===t.type&&(o=t.clientX,i=t.clientY);var n=r.lowerCanvas.getBoundingClientRect();if(o-=n.left,i-=n.top,o>r.img.destLeft&&o<r.img.destLeft+r.img.destWidth&&i>r.img.destTop&&i<r.img.destTop+r.img.destHeight&&(a=!0),t.stopPropagation(),!0===t.ctrlKey&&a){t.preventDefault(),!r.isCropTab&&r.activeObj.shape&&"crop"!==r.activeObj.shape.split("-")[0]&&(r.okBtn(null,!0),r.notify("toolbar",{prop:"close-contextual-toolbar",onPropertyChange:!1}));var s="";"mousewheel"===t.type&&(r.zoomSettings.zoomTrigger&e.ZoomTrigger.MouseWheel)===e.ZoomTrigger.MouseWheel&&(this.zoomType="MouseWheel",s=t.wheelDelta>0?"zoomIn":"zoomOut"),""!==s&&(r.notify("draw",{prop:"performPointZoom",onPropertyChange:!1,value:{x:o,y:i,type:s,isResize:null}}),r.notify("draw",{prop:"redrawDownScale"}),(r.isCropTab||r.activeObj.shape)&&(r.notify("draw",{prop:"setStraightenActObj",value:{activeObj:null}}),r.notify("freehand-draw",{prop:"resetStraightenPoint"})),r.isStraightening&&(r.notify("draw",{prop:"resetStraightenDestPoints"}),r.notify("draw",{prop:"setDestForStraighten"})))}},o.prototype.textKeyDown=function(e){var o=this.parent;if(0===o.activeObj.rotatedAngle){"\r"===String.fromCharCode(e.which)&&(this.textRow+=1),o.textArea.setAttribute("rows",this.textRow.toString()),o.textArea.style.height="auto",o.textArea.style.height=o.textArea.scrollHeight+"px",o.notify("shape",{prop:"setTextBoxWidth",onPropertyChange:!1,value:{e:e}}),t.Browser.isDevice&&(o.textArea.style.width=parseFloat(o.textArea.style.width)+o.textArea.style.fontSize+"px");var i=o.textArea.value.split("\n");this.textRow=i.length,o.textArea.setAttribute("rows",this.textRow.toString()),this.isInitialTextEdited=!1}},o.prototype.clearSelection=function(e){var t=this.parent;!t.disabled&&t.isImageLoaded&&(e?t.notify("draw",{prop:"performCancel",value:{isContextualToolbar:null}}):(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(e,t){var o=this.parent,i=o.activeObj.activePoint;o.img.destWidth>o.img.destHeight?(i.startX=this.dragPoint.startX=e/2-t/2+7.5,i.startY=this.dragPoint.startY=t/2-t/2+7.5,i.endX=e/2+t/2-7.5,i.endY=t/2+t/2-7.5):(i.startY=this.dragPoint.startX=t/2-e/2+7.5,i.endY=t/2+e/2-7.5,i.startX=this.dragPoint.startX=7.5,i.endX=e-7.5)},o.prototype.calcShapeRatio=function(e,t,o,i){for(var r=this.parent,a=r.activeObj.activePoint,n=e/t,s=o,l=i,p=s>=l?s:l,h=p*n,d=p,c=this.getScale(h,s),u=[],v=r.img,g=v.destLeft,f=v.destTop,C=v.destWidth,b=v.destHeight,m=0;m<2;m++)0===m?u.push(h*c):u.push(d*c);h=u[0],d=u[1];for(var y=this.getScale(d,l),P=[],m=0;m<2;m++)0===m?P.push(h*y):P.push(d*y);h=P[0],d=P[1],a.width=h,a.height=d,a.startX=7.5+(this.dragPoint.startX=(s-h)/2),a.startY=7.5+(this.dragPoint.startY=(l-d)/2),a.endX=a.startX+a.width,a.endY=a.startY+a.height,a.startX<g&&g+C>r.lowerCanvas.clientWidth&&(a.startX=g,a.endX=a.startX+h-7.5),a.startY<f&&f+b>r.lowerCanvas.clientHeight&&(a.startY=f,a.endY=a.startY+d-7.5),a.width=a.endX-a.startX,a.height=a.endY-a.startY},o.prototype.getScale=function(e,t){return e>t?t/e:1},o.prototype.findTarget=function(e,t,o){var i=this.parent;if("mousedown"===o.toLowerCase()||"touchstart"===o.toLowerCase()){var r=!1;i.activeObj.shape&&"crop"===i.activeObj.shape.split("-")[0]&&(r=!0),this.findTargetObj(e,t,r),this.updateCursorStyles(e,t,o)}else{var a=i.activeObj,n=a.topLeftCircle,s=a.topCenterCircle,l=a.topRightCircle,p=a.centerLeftCircle,h=a.centerRightCircle,d=a.bottomLeftCircle,c=a.bottomCenterCircle,u=a.bottomRightCircle;switch(this.dragElement.toLowerCase()){case"nw-resize":n.startX=e,n.startY=t;break;case"n-resize":s.startX=e,s.startY=t;break;case"ne-resize":l.startX=e,l.startY=t;break;case"w-resize":p.startX=e,p.startY=t;break;case"e-resize":h.startX=e,h.startY=t;break;case"sw-resize":d.startX=e,d.startY=t;break;case"s-resize":c.startX=e,c.startY=t;break;case"se-resize":u.startX=e,u.startY=t;break;default:this.dragPoint.startX&&this.dragPoint.startY&&(this.previousPoint.x=this.dragPoint.endX,this.previousPoint.y=this.dragPoint.endY,this.dragPoint.endX=e,this.dragPoint.endY=t)}}},o.prototype.findTargetObj=function(e,o,i){var r=this.parent,a=!1;if(0!==r.objColl.length&&!r.currObjType.isCustomCrop&&!i){for(var n=0,s=void 0,l=0;l<r.objColl.length;l++){var p=r.upperCanvas.style.cursor;this.setCursor(e,o);var h=t.extend({},r.objColl[l],{},!0),d=h.topLeftCircle.radius;if("line"===h.shape||"arrow"===h.shape){for(var c=0;c<h.pointColl.length;c++)if(e>=h.pointColl[c].x-2*d&&e<=h.pointColl[c].x+2*d&&o>=h.pointColl[c].y-2*d&&o<=h.pointColl[c].y+2*d){if(this.tempActiveObj&&this.tempActiveObj.activePoint&&JSON.stringify(this.tempActiveObj.activePoint)===JSON.stringify(h.activePoint)){s=l;break}this.isTouch||"move"===r.cursor||"grab"===r.cursor||this.isShapeInserted?(0===n||n<h.order)&&(n=h.order,s=l):r.objColl[l].currIndex===this.tempActiveObj.currIndex&&(s=l);break}}else if("path"===h.shape){var u=this.setCursorForPath(h,e,o,r.upperCanvas);if("default"!==u&&"grab"!==u){if(this.tempActiveObj&&this.tempActiveObj.activePoint&&JSON.stringify(this.tempActiveObj.activePoint)===JSON.stringify(h.activePoint)){s=l;break}this.isTouch||"move"===r.cursor||"grab"===r.cursor||this.isShapeInserted?(0===n||n<h.order)&&(n=h.order,s=l):r.objColl[l].currIndex===this.tempActiveObj.currIndex&&(s=l)}}else if(0!==h.rotatedAngle){var v=this.setCursorForRotatedObject(h,e,o,r.upperCanvas);if("default"!==v&&"grab"!==v){if(this.tempActiveObj&&this.tempActiveObj.activePoint&&JSON.stringify(this.tempActiveObj.activePoint)===JSON.stringify(h.activePoint)){s=l;break}this.isTouch||"move"===r.cursor||"grab"===r.cursor||this.isShapeInserted?(0===n||n<h.order)&&(n=h.order,s=l):r.objColl[l].currIndex===this.tempActiveObj.currIndex&&(s=l)}}else{var g=this.getTransRotationPoint(h);if(e>=h.activePoint.startX-2*d&&e<=h.activePoint.endX+2*d&&o>=h.activePoint.startY-2*d&&o<=h.activePoint.endY+2*d||g&&e>=g.x-2*d&&e<=g.x+2*d&&o>=g.y-2*d&&o<=g.y+2*d){if(this.tempActiveObj&&this.tempActiveObj.activePoint&&JSON.stringify(this.tempActiveObj.activePoint)===JSON.stringify(h.activePoint)){s=l;break}this.isTouch||"move"===p||"grabbing"===p||this.isShapeInserted||"move"===r.cursor||"grabbing"===r.cursor?(0===n||n<h.order)&&(n=h.order,s=l):r.objColl[l].currIndex===this.tempActiveObj.currIndex&&(s=l)}}}if(t.isNullOrUndefined(s))r.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),a=!1;else{this.tempObjColl=t.extend([],r.objColl,[],!0),r.currObjType.isCustomCrop=!1,r.activeObj=t.extend({},r.objColl[s],{},!0);var f=t.extend({},r.objColl[s],{},!0);if(r.objColl.splice(s,1),0===r.transform.degree){var C=this.lowerContext.filter;this.lowerContext.clearRect(0,0,r.lowerCanvas.width,r.lowerCanvas.height),r.notify("draw",{prop:"drawImage",onPropertyChange:!1}),this.lowerContext.filter="none",r.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"iterate",pen:"iterate",isPreventApply:null}}),r.activeObj=t.extend({},C,{},!0),this.lowerContext.filter=C,this.getCurrentFlipState()}else{var b=t.extend({},r.panPoint.totalPannedInternalPoint,{},!0),m={startX:r.img.destLeft,startY:r.img.destTop,width:r.img.destWidth,height:r.img.destHeight};r.notify("draw",{prop:"callUpdateCurrTransState",onPropertyChange:!1}),r.panPoint.totalPannedInternalPoint=b,r.img.destLeft=m.startX,r.img.destTop=m.startY,r.img.destWidth=m.width,r.img.destHeight=m.height,r.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"iterate",pen:"iterate",isPreventApply:null}})}r.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.lowerContext}}),(r.currSelectionPoint&&"crop-circle"===r.currSelectionPoint.shape||r.isCircleCrop)&&r.notify("crop",{prop:"cropCircle",onPropertyChange:!1,value:{context:this.lowerContext,isSave:null,isFlip:null}}),r.activeObj=t.extend({},f,{},!0),this.setActivePoint(),r.activeObj=t.extend({},f,{},!0);var y=t.extend({},r.activeObj.strokeSettings,{},!0);r.notify("draw",{prop:"setTempStrokeSettings",onPropertyChange:!1,value:{tempStrokeSettings:y}});var P=t.extend({},r.activeObj.textSettings,{},!0);r.notify("draw",{prop:"setTempTextSettings",onPropertyChange:!1,value:{tempTextSettings:P}});var j=this.updatePrevShapeSettings(),x={cancel:!1,action:"select",previousShapeSettings:j,currentShapeSettings:j};"line"!==r.activeObj.shape&&"arrow"!==r.activeObj.shape||(x.currentShapeSettings.width=r.activeObj.activePoint.endX-r.activeObj.activePoint.startX,x.currentShapeSettings.height=r.activeObj.activePoint.endY-r.activeObj.activePoint.startY),this.isCropSelection=!1;var w=void 0;if(void 0!==r.activeObj.shape&&(w=r.activeObj.shape.split("-")),void 0!==w&&"crop"===w[0]&&(this.isCropSelection=!0),this.isCropSelection){var O={action:x.action,previousSelectionSettings:{type:r.getSelectionType(r.activeObj.shape),startX:x.previousShapeSettings.startX,startY:x.previousShapeSettings.startY,width:x.previousShapeSettings.width,height:x.previousShapeSettings.height},currentSelectionSettings:{type:r.getSelectionType(r.activeObj.shape),startX:x.currentShapeSettings.startX,startY:x.currentShapeSettings.startY,width:x.currentShapeSettings.width,height:x.currentShapeSettings.height}};r.trigger("selectionChanging",O),x.currentShapeSettings.startX=O.currentSelectionSettings.startX,x.currentShapeSettings.startY=O.currentSelectionSettings.startY,x.currentShapeSettings.width=O.currentSelectionSettings.width,x.currentShapeSettings.height=O.currentSelectionSettings.height,this.shapeEvent(x)}else r.trigger("shapeChanging",x),this.shapeEvent(x);a=!0}}return a},o.prototype.shapeEvent=function(e){var o=this.parent;if(o.notify("shape",{prop:"updateShapeChangeEventArgs",onPropertyChange:!1,value:{shapeSettings:e.currentShapeSettings}}),o.activeObj.activePoint){var i={prevActObj:null};if(o.notify("draw",{prop:"getPrevActObj",onPropertyChange:!1,value:{obj:i}}),t.isNullOrUndefined(i.prevActObj)&&o.notify("draw",{prop:"setPrevActObj",onPropertyChange:!1,value:{prevActObj:t.extend({},o.activeObj,{},!0)}}),"image"!==o.activeObj.shape||this.isImageClarity||(this.upgradeImageQuality(),this.isImageClarity=!0),o.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate",obj:o.activeObj,isCropRatio:null,points:null,isPreventDrag:!0,saveContext:null,isPreventSelection:!0}}),!this.isShapeInserted){var r=o.activeObj.activePoint,a=o.img,n=a.destLeft,s=a.destWidth,l=a.destTop,p=a.destHeight;this.isPreventDragging=r.startX<n||r.endX>n+s||r.startY<l||r.endY>l+p}}},o.prototype.upgradeImageQuality=function(){var e=this.parent,o=t.extend({},e.activeObj,null,!0),i=e.activeObj.imageCanvas.getContext("2d"),r={width:0,height:0};e.notify("transform",{prop:"calcMaxDimension",onPropertyChange:!1,value:{width:e.activeObj.imageElement.width,height:e.activeObj.imageElement.height,obj:r,isImgShape:null}}),e.notify("shape",{prop:"updateObj",onPropertyChange:!1,value:{dimObj:r,x:null,y:null}}),i.clearRect(0,0,e.activeObj.imageCanvas.width,e.activeObj.imageCanvas.height),this.applyTransformToImg(i),e.activeObj=o},o.prototype.applyTransformToImg=function(e){var t=this.parent;t.activeObj.isHorImageFlip&&t.activeObj.isVerImageFlip?(t.activeObj.isHorImageFlip=t.activeObj.isVerImageFlip=!1,t.notify("draw",{prop:"downScaleImgCanvas",onPropertyChange:!1,value:{ctx:e,isImgAnnotation:!0,isHFlip:!0,isVFlip:!0}})):t.activeObj.isHorImageFlip?(t.activeObj.isHorImageFlip=!1,t.notify("draw",{prop:"downScaleImgCanvas",onPropertyChange:!1,value:{ctx:e,isImgAnnotation:!0,isHFlip:!0,isVFlip:!1}})):t.activeObj.isVerImageFlip?(t.activeObj.isVerImageFlip=!1,t.notify("draw",{prop:"downScaleImgCanvas",onPropertyChange:!1,value:{ctx:e,isImgAnnotation:!0,isHFlip:!1,isVFlip:!0}})):t.notify("draw",{prop:"downScaleImgCanvas",onPropertyChange:!1,value:{ctx:e,isImgAnnotation:!0,isHFlip:!1,isVFlip:!1}})},o.prototype.targetTouches=function(e){var t=this.parent.lowerCanvas.getBoundingClientRect();return[{x:e[0].pageX-t.left,y:e[0].pageY-t.top},{x:e[1].pageX-t.left,y:e[1].pageY-t.top}]},o.prototype.calculateScale=function(e,t){var o=this.getDistance(e[0],e[1]);return this.getDistance(t[0],t[1])/o},o.prototype.getDistance=function(e,t){var o=0,i=0;return e&&t&&(o=e.x-t.x,i=e.y-t.y),Math.sqrt(o*o+i*i)},o.prototype.redrawShape=function(e,t){for(var o=this.parent,i=0,r=o.objColl.length;i<r;i++)if(JSON.stringify(e)===JSON.stringify(o.objColl[i])){o.objColl.splice(i,1);break}"path"===e.shape&&0===e.pointColl.length||"path"!==e.shape&&0===e.activePoint.width&&0===e.activePoint.height||(this.upperContext.clearRect(0,0,o.upperCanvas.width,o.upperCanvas.height),this.isPreventDragging?(o.activeObj.activePoint.startX>o.img.destLeft&&(this.isPreventDragging=!1),t&&o.activeObj.rotatedAngle,o.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate",obj:null,isCropRatio:null,points:null,isPreventDrag:!0,saveContext:null,isPreventSelection:null}})):(t&&o.activeObj.rotatedAngle,o.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(e){var o=this.parent;this.timer>10&&(clearTimeout(this.timer),this.timer=0,o.notify("shape",{prop:"findTextTarget",onPropertyChange:!1,value:{e:e}}),t.Browser.isDevice&&this.upperContext.clearRect(0,0,o.upperCanvas.width,o.upperCanvas.height))},o.prototype.applyCurrActObj=function(e,o){var i=this.parent,r=!1,a=t.extend({},i.activeObj,{},!0);if(!t.isNullOrUndefined(a.activePoint)){var n=a.activePoint,s=n.startX,l=n.startY,p=n.endX,h=n.endY,d=a.topLeftCircle?a.topLeftCircle.radius:0;if(e>=Math.floor(s)&&e<=Math.ceil(p)&&o>=Math.floor(l)&&o<=Math.ceil(h))r=!0;else if(0!==d&&e>=Math.floor(s)-d&&e<=Math.ceil(p)+d&&o>=Math.floor(l)-d&&o<=Math.ceil(h)+d)r=!0,this.tempActiveObj={activePoint:{startX:0,startY:0,endX:0,endY:0,width:0,height:0},flipObjColl:[],triangle:[],triangleRatio:[]};else if("text"!==a.shape&&"image"!==a.shape||""===this.dragElement)if("line"===a.shape||"arrow"===a.shape){var c={x:s<p?s:p,y:l<h?l:h},u={x:s>p?s:p,y:l>h?l:h};e>=Math.floor(c.x)-5&&e<=Math.ceil(u.x)+5&&o>=Math.floor(c.y)-5&&o<=Math.ceil(u.y)+5&&(r=!0)}else if("path"===a.shape)"move"===(v=this.setCursorForPath(a,e,o,i.upperCanvas))&&(r=!0);else if("grabbing"===this.dragElement)r=!0;else if(0!==a.rotatedAngle){var v=this.setCursorForRotatedObject(a,e,o,i.upperCanvas);("default"!==v&&"grab"!==v||"n-resize"===this.dragElement||"e-resize"===this.dragElement||"s-resize"===this.dragElement||"w-resize"===this.dragElement)&&(r=!0)}else"block"!==i.textArea.style.display&&"inline-block"!==i.textArea.style.display||(r=!0);else r=!0;if(!r){if(t.isNullOrUndefined(i.activeObj.currIndex)){var g={id:"shape_"+(i.objColl.length+1)};i.notify("shape",{prop:"getNewShapeId",onPropertyChange:!1,value:{obj:g}}),i.activeObj.currIndex=g.id}if(i.notify("shape",{prop:"updImgRatioForActObj",onPropertyChange:!1}),void 0===i.activeObj.horTopLine||0===i.activeObj.horTopLine.startX||0===i.activeObj.horTopLine.endX||i.currObjType.isCustomCrop||""===i.currObjType.shape||i.objColl.push(t.extend({},i.activeObj,{},!0)),["rectangle","ellipse","line","arrow","path","text","image"].indexOf(i.activeObj.shape)>-1){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%)";for(var C=0;C<i.objColl.length;C++){var b={isInside:!1};i.notify("crop",{prop:"isObjInImage",onPropertyChange:!1,value:{obj:i.objColl[C],object:b}}),b.isInside&&(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.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"zoom",pen:"zoom",isPreventApply:null}}),this.lowerContext.filter=f,i.activeObj.shape&&i.notify("shape",{prop:"apply",onPropertyChange:!1,value:{shape:null,obj:null,canvas:null}}),i.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.lowerContext}}),i.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.upperContext}}),i.isCircleCrop&&i.notify("crop",{prop:"cropCircle",onPropertyChange:!1,value:{context:this.lowerContext,isSave:null,isFlip:null}})}i.notify("toolbar",{prop:"refresh-main-toolbar",onPropertyChange:!1})}}},o.prototype.getCurrentFlipState=function(){var e=this.parent;if(0!==e.rotateFlipColl.length){var o=t.extend({},e.panPoint.totalPannedInternalPoint,{},!0);e.notify("draw",{prop:"callUpdateCurrTransState",onPropertyChange:!1}),e.panPoint.totalPannedInternalPoint=o}else e.notify("draw",{prop:"callUpdateCurrTransState",onPropertyChange:!1})},o.prototype.setTextBoxStylesToActObj=function(){var e=this.parent;e.activeObj.textSettings.fontFamily=e.textArea.style.fontFamily,e.activeObj.strokeSettings.strokeColor=""!==e.textArea.style.color&&e.textArea.style.color.split("(")[1]&&e.textArea.style.color.split("(")[1].split(",")[0]&&e.textArea.style.color.split("(")[1].split(",")[1]&&e.textArea.style.color.split("(")[1].split(",")[2]&&e.textArea.style.color.split("(")[1].split(",")[3]?this.rgbToHex(parseFloat(e.textArea.style.color.split("(")[1].split(",")[0]),parseFloat(e.textArea.style.color.split("(")[1].split(",")[1]),parseFloat(e.textArea.style.color.split("(")[1].split(",")[2]),parseFloat(e.textArea.style.color.split("(")[1].split(",")[3])):e.textArea.style.color,"bold"===e.textArea.style.fontWeight?e.activeObj.textSettings.bold=!0:e.activeObj.textSettings.bold=!1,"italic"===e.textArea.style.fontStyle?e.activeObj.textSettings.italic=!0:e.activeObj.textSettings.italic=!1,e.activeObj.textSettings.fontSize=parseFloat(e.textArea.style.fontSize)},o.prototype.rgbToHex=function(e,t,o,i){return e=Math.max(0,Math.min(255,Math.round(e))),t=Math.max(0,Math.min(255,Math.round(t))),o=Math.max(0,Math.min(255,Math.round(o))),i=Math.max(0,Math.min(1,i)),"#"+this.padLeft(e.toString(16),2,"0")+this.padLeft(t.toString(16),2,"0")+this.padLeft(o.toString(16),2,"0")+this.padLeft(Math.round(255*i).toString(16),2,"0")},o.prototype.padLeft=function(e,t,o){for(;e.length<t;)e=o+e;return e},o.prototype.deleteItem=function(){var e=this.parent,o={cancel:!1};if(this.isFhdEditing){this.updateFreehandDrawColorChange();var i=t.extend({},e.cropObj,{},!0),r={currObj:{}};e.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:r}}),(h=r.currObj).objColl=t.extend([],e.objColl,[],!0),h.pointColl=t.extend([],e.pointColl,[],!0),h.afterCropActions=t.extend([],e.afterCropActions,[],!0);d={selPointColl:null};e.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:d}}),h.selPointColl=t.extend([],d.selPointColl,[],!0);a={freehandDrawSelectedId:null};e.notify("freehand-draw",{prop:"getFreehandDrawSelectedId",onPropertyChange:!1,value:{obj:a}}),e.notify("freehand-draw",{prop:"deleteFhd",value:{id:a.freehandDrawSelectedId}}),e.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"deleteFreehandDrawing",previousObj:h,previousObjColl:this.tempObjColl,previousPointColl:h.pointColl,previousSelPointColl:h.selPointColl,previousCropObj:i,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),e.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"ok"}}),e.notify("freehand-draw",{prop:"resetFreehandDrawSelectedId"})}else if("none"===e.textArea.style.display){var a={prevActObj:null};if(e.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(e.activeObj)){var n=e.activeObj.currIndex;e.notify("draw",{prop:"performCancel",value:{isContextualToolbar:null,isFinalCancel:!0}});for(var s=0,l=e.objColl.length;s<l;s++)if(e.objColl[s].currIndex===n){e.objColl.splice(s,1),e.notify("draw",{prop:"render-image",value:{isMouseWheel:null}});break}}r={isNewPath:null};if(e.notify("draw",{prop:"getNewPath",value:{obj:r}}),r.isNewPath)e.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),this.upperContext.clearRect(0,0,e.upperCanvas.width,e.upperCanvas.height),e.notify("draw",{prop:"render-image",value:{isMouseWheel:null}}),e.notify("toolbar",{prop:"refresh-main-toolbar",onPropertyChange:!1});else if(e.activeObj.shape){e.objColl.push(e.activeObj);var i=t.extend({},e.cropObj,{},!0),p={currObj:{}};e.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:p}});var h=p.currObj;h.objColl=t.extend([],e.objColl,[],!0),h.pointColl=t.extend([],e.pointColl,[],!0),h.afterCropActions=t.extend([],e.afterCropActions,[],!0);var d={selPointColl:null};e.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:d}}),h.selPointColl=t.extend([],d.selPointColl,[],!0),e.objColl.pop(),o={cancel:!1,action:"delete",previousShapeSettings:this.updatePrevShapeSettings(),currentShapeSettings:null},e.notify("shape",{prop:"setKeyHistory",onPropertyChange:!1,value:{keyHistory:""}}),e.clearSelection(),e.trigger("shapeChanging",o),e.notify("toolbar",{prop:"refresh-main-toolbar",onPropertyChange:!1}),e.notify("draw",{prop:"render-image",value:{isMouseWheel:null}}),t.isNullOrUndefined(h.objColl[h.objColl.length-1].currIndex)||(e.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"deleteObj",previousObj:h,previousObjColl:this.tempObjColl,previousPointColl:h.pointColl,previousSelPointColl:h.selPointColl,previousCropObj:i,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),e.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"ok"}}))}e.notify("draw",{prop:"setPrevActObj",onPropertyChange:!1,value:{prevActObj:null}}),e.drawingShape&&(this.currentDrawingShape=e.drawingShape.toLowerCase(),e.enableShapeDrawing(e.toPascalCase(e.drawingShape),!0),e.upperCanvas.style.cursor="crosshair")}document.getElementById(e.element.id+"_quickAccessToolbarArea")&&(document.getElementById(e.element.id+"_quickAccessToolbarArea").style.display="none")},o.prototype.updateFreehandDrawColorChange=function(){var e=this.parent,o={freehandSelectedIndex:null};if(e.notify("freehand-draw",{prop:"getFreehandSelectedIndex",onPropertyChange:!1,value:{obj:o}}),!t.isNullOrUndefined(o.freehandSelectedIndex)&&!t.isNullOrUndefined(e.pointColl[o.freehandSelectedIndex])&&"#42a5f5"===e.pointColl[o.freehandSelectedIndex].strokeColor){var i={tempFreeHandDrawEditingStyles:null};e.notify("freehand-draw",{prop:"getTempFreeHandDrawEditingStyles",value:{obj:i}}),e.pointColl[o.freehandSelectedIndex].strokeColor=i.tempFreeHandDrawEditingStyles.strokeColor}},o.prototype.updatePrevShapeSettings=function(e){var o=this.parent,i=[];if(t.isNullOrUndefined(o.activeObj.currIndex)){var r={id:"shape_"+(o.objColl.length+1)};o.notify("shape",{prop:"getNewShapeId",onPropertyChange:!1,value:{obj:r}}),o.activeObj.currIndex=r.id}"text"===o.activeObj.shape&&o.activeObj.textSettings&&(o.activeObj.textSettings.bold&&i.push("bold"),o.activeObj.textSettings.italic&&i.push("italic"),o.activeObj.textSettings.underline&&i.push("underline"));var a=o.activeObj.activePoint,n=a.startX,s=a.startY,l=a.endX,p=a.endY,h=a.width,d=a.height,c=o.activeObj,u=c.keyHistory,v=c.currIndex,g=c.shape,f=c.textSettings,C=c.strokeSettings,b=c.rotatedAngle,m=c.imageElement,y=c.opacity,P={id:t.isNullOrUndefined(v)?null:v,type:o.toPascalCase(g),startX:n,startY:s,width:h,height:d,strokeColor:C?C.strokeColor:null,strokeWidth:C?C.strokeWidth:null,fillColor:C?C.fillColor:null,radius:"ellipse"===g?h/2:null,length:"line"===g||"arrow"===g?h:null,text:"text"===g?u||(f.text?f.text:null):null,fontSize:"text"===g&&f?f.fontSize:null,fontFamily:"text"===g&&f?f.fontFamily:null,fontStyle:"text"===g?i:null,color:"text"===g&&C?C.strokeColor:null,degree:"ellipse"===g||"rectangle"===g||"image"===g||"text"===g?b*(180/Math.PI):null,imageData:"image"===g?m.src:null,opacity:"image"===g?y:null,radiusX:"ellipse"===g?h/2:null,radiusY:"ellipse"===g?d/2:null,endX:"line"===g||"arrow"===g?l:null,endY:"line"===g||"arrow"===g?p:null,arrowHead:"arrow"===g?this.getArrowType(o.activeObj.start):null,arrowTail:"arrow"===g?this.getArrowType(o.activeObj.end):null,points:"path"===g?o.activeObj.pointColl:null,index:o.activeObj.order};return e&&(e.shapeSettingsObj=P),P},o.prototype.getArrowType=function(e){return{none:"None",arrow:"Arrow",arrowSolid:"SolidArrow",circle:"Circle",circleSolid:"SolidCircle",square:"Square",squareSolid:"SolidSquare",bar:"Bar"}[""+e]},o.prototype.getRectanglePoints=function(e,t,o,i,r,a,n){var s=e+o/2,l=t+i/2,p=r*(Math.PI/180),h=Math.cos(p),d=Math.sin(p),c=a-s,u=n-l,v=c*h+u*d,g=-c*d+u*h,f=o/2,C=i/2;return v>=-f&&v<=f&&g>=-C&&g<=C},o.prototype.getTransRotationPoint=function(e,t){var o,i,r=!1,a=!1;if((i=0===e.shapeDegree?this.parent.transform.degree:this.parent.transform.degree-e.shapeDegree)<0&&(i=360+i),e.flipObjColl)for(var n=0,s=e.flipObjColl.length;n<s;n++)"horizontal"===e.flipObjColl[n].toLowerCase()?r=!0:"vertical"===e.flipObjColl[n].toLowerCase()&&(a=!0);return 0===i||360===i?o=a?{x:e.topCenterCircle.startX,y:e.topCenterCircle.startY-e.rotationCircleLine}:{x:e.bottomCenterCircle.startX,y:e.bottomCenterCircle.startY+e.rotationCircleLine}:90===i||-270===i?o=r?{x:e.centerRightCircle.startX+e.rotationCircleLine,y:e.centerLeftCircle.startY}:{x:e.centerLeftCircle.startX-e.rotationCircleLine,y:e.centerLeftCircle.startY}:180===i||-180===i?o=a?{x:e.bottomCenterCircle.startX,y:e.bottomCenterCircle.startY+e.rotationCircleLine}:{x:e.topCenterCircle.startX,y:e.topCenterCircle.startY-e.rotationCircleLine}:270!==i&&-90!==i||(o=r?{x:e.centerLeftCircle.startX-e.rotationCircleLine,y:e.centerLeftCircle.startY}:{x:e.centerRightCircle.startX+e.rotationCircleLine,y:e.centerLeftCircle.startY}),t&&(t.rotationCirclePoint=o),o},o.prototype.getNumTextValue=function(e){var t,o,i,r,a=this.parent.element;if(i=a.querySelector("#"+a.id+"_resizeWidth"),r=a.querySelector("#"+a.id+"_resizeHeight"),i&&r){var n=r.value.replace(/,/g,""),s=i.value.replace(/,/g,"");""===n&&(n=r.placeholder.replace(/,/g,"")),""===s&&(s=i.placeholder.replace(/,/g,"")),t=parseFloat(n),o=parseFloat(s)}return e&&(e.width=o,e.height=t),{x:o,y:t}},o.prototype.isValueUpdated=function(){var e,t,o=!0;return e=this.parent.element.querySelector("#"+this.parent.element.id+"_resizeWidth"),t=this.parent.element.querySelector("#"+this.parent.element.id+"_resizeHeight"),e&&t&&""===t.value.replace(/,/g,"")&&""===e.value.replace(/,/g,"")&&(o=!1),o},o}(),g=function(){function o(e){this.textSettings={text:"Enter Text",fontFamily:"",fontSize:null,fontRatio:null,bold:!1,italic:!1,underline:!1},this.strokeSettings={strokeColor:"#fff",fillColor:"",strokeWidth:null},this.keyHistory="",this.preventFrameAnnotation=!1,this.parent=e,this.addEventListener()}return o.prototype.destroy=function(){this.parent.isDestroyed||this.removeEventListener()},o.prototype.addEventListener=function(){this.parent.on("shape",this.shape,this),this.parent.on("destroyed",this.destroy,this)},o.prototype.removeEventListener=function(){this.parent.off("shape",this.shape),this.parent.off("destroyed",this.destroy)},o.prototype.shape=function(e){var o=this.parent;this.initShapePvtProps();var i;switch(e.prop){case"drawEllipse":this.drawEllipse(e.value.x,e.value.y,e.value.radiusX,e.value.radiusY,e.value.strokeWidth,e.value.strokeColor,e.value.fillColor,e.value.degree,e.value.isSelected);break;case"drawLine":this.drawLine(e.value.startX,e.value.startY,e.value.endX,e.value.endY,e.value.strokeWidth,e.value.strokeColor,e.value.isSelected);break;case"drawArrow":this.drawArrow(e.value.startX,e.value.startY,e.value.endX,e.value.endY,e.value.strokeWidth,e.value.strokeColor,e.value.arrowStart,e.value.arrowEnd,e.value.isSelected);break;case"drawPath":this.drawPath(e.value.pointColl,e.value.strokeWidth,e.value.strokeColor,e.value.isSelected);break;case"drawRectangle":this.drawRectangle(e.value.x,e.value.y,e.value.width,e.value.height,e.value.strokeWidth,e.value.strokeColor,e.value.fillColor,e.value.degree,e.value.isSelected);break;case"drawText":this.drawText(e.value.x,e.value.y,e.value.text,e.value.fontFamily,e.value.fontSize,e.value.bold,e.value.italic,e.value.color,e.value.isSelected,e.value.degree);break;case"redrawActObj":this.redrawActObj(e.value.x,e.value.y,e.value.isMouseDown);break;case"apply":this.apply(e.value.shape,e.value.obj,e.value.canvas);break;case"updateShapeChangeEventArgs":this.updateShapeChangeEventArgs(e.value.shapeSettings);break;case"updSelChangeEventArgs":this.updSelChangeEventArgs(e.value.selectionSettings);break;case"iterateObjColl":this.iterateObjColl();break;case"updImgRatioForActObj":this.updImgRatioForActObj();break;case"redrawObj":this.redrawObj(e.value.degree);break;case"redraw-text":this.redrawText();break;case"draw-shape":this.drawShape(e.value.obj,e.value.strokeWidth,e.value.strokeColor,e.value.fillColor,e.value.start,e.value.width,e.value.height);break;case"renderTextArea":this.renderTextArea(e.value.x,e.value.y,e.value.actObj);break;case"setTextBoxWidth":this.setTextBoxWidth(e.value.e);break;case"findTextTarget":this.findTextTarget(e.value.e);break;case"updateFontStyles":this.updateFontStyles(e.value.isTextBox);break;case"applyFontStyle":this.applyFontStyle(e.value.item);break;case"updateFontRatio":this.updateFontRatio(e.value.obj,e.value.isTextArea);break;case"updateFontSize":this.updateFontSize(e.value.obj);break;case"pushActItemIntoObj":this.pushActItemIntoObj();break;case"clearActObj":this.clearActObj();break;case"refreshActiveObj":this.refreshActiveObj();break;case"applyActObj":this.applyActObj(e.value.isMouseDown);break;case"wireEvent":t.EventHandler.add(o.upperCanvas,"dblclick",this.findTextTarget,this),t.EventHandler.add(o.textArea,"mousedown",this.findTextTarget,this),(i=document.getElementById(o.element.id+"_fileUpload"))&&t.EventHandler.add(i,"change",this.fileChanged,this);break;case"unWireEvent":t.EventHandler.remove(o.upperCanvas,"dblclick",this.findTextTarget),t.EventHandler.remove(o.textArea,"mousedown",this.findTextTarget),(i=document.getElementById(o.element.id+"_fileUpload"))&&t.EventHandler.remove(i,"change",this.fileChanged);break;case"getShapeSetting":this.getShapeSetting(e.value.id,e.value.obj);break;case"getShapeSettings":this.getShapeSettings(e.value.obj);break;case"isPointsInRange":this.isPointsInRange(e.value.x,e.value.y,e.value.obj);break;case"alignRotateFlipColl":this.alignRotateFlipColl(e.value.collection,e.value.isRotateFlipCollection,e.value.obj);break;case"selectShape":this.selectShape(e.value.id,e.value.obj);break;case"deleteShape":this.deleteShape(e.value.id);break;case"getMaxText":this.getMaxText(e.value.isTextBox,e.value.text,e.value.obj);break;case"setPointCollForLineArrow":e.value.obj.pointColl=this.getLinePoints(e.value.obj.activePoint.startX,e.value.obj.activePoint.startY,e.value.obj.activePoint.endX,e.value.obj.activePoint.endY);break;case"setPointCollForShapeRotation":this.setPointCollForShapeRotation(e.value.obj);break;case"setTextSettings":e.value.textSettings?this.textSettings=e.value.textSettings:e.value.fontFamily?this.textSettings.fontFamily=e.value.fontFamily:e.value.fontSize&&(this.textSettings.fontSize=e.value.fontSize);break;case"setStrokeSettings":e.value.strokeSettings?this.strokeSettings=e.value.strokeSettings:e.value.strokeColor?this.strokeSettings.strokeColor=e.value.strokeColor:e.value.fillColor?this.strokeSettings.fillColor=e.value.fillColor:e.value.strokeWidth&&(this.strokeSettings.strokeWidth=e.value.strokeWidth);break;case"getStrokeSettings":e.value.obj.strokeSettings=this.strokeSettings;break;case"setKeyHistory":this.keyHistory=e.value.keyHistory;break;case"getKeyHistory":e.value.obj.keyHistory=this.keyHistory;break;case"setTextBoxPos":this.setTextBoxPos(e.value.actObj,e.value.degree,e.value.flip,e.value.x,e.value.y);break;case"setTextBoxPoints":this.setTextBoxPoints(e.value.actObj,e.value.degree,e.value.flip,e.value.x,e.value.y);break;case"alignTextAreaIntoCanvas":this.alignTextAreaIntoCanvas();break;case"initializeTextShape":this.initializeTextShape(e.value.text,e.value.fontFamily,e.value.fontSize,e.value.bold,e.value.italic,e.value.strokeColor);break;case"stopPathDrawing":this.stopPathDrawing(e.value.e,e.value.isApply);break;case"updateArrowRatio":this.updateArrowRatio(e.value.obj);break;case"getSquarePointForRotatedShape":this.getSquarePointForRotatedShape(e.value.obj,e.value.object);break;case"drawImage":this.drawImage(e.value.x,e.value.y,e.value.width,e.value.height,e.value.src,e.value.degree,e.value.isAspectRatio,e.value.opacity,e.value.isSelected);break;case"reset":this.reset();break;case"updateObj":this.updateObj(e.value.dimObj,e.value.x,e.value.y);break;case"straightenShapes":this.straightenShapes();break;case"straightenShapePoints":this.straightenShapePoints(e.value.obj,e.value.isReverse);break;case"straightenPath":this.straightenPath(e.value.obj);break;case"straightenFHD":this.straightenFHD();break;case"getTextBoxPosition":this.getTextBoxPosition(e.value.obj,e.value.object);break;case"setFlipState":this.setFlipState(e.value.x,e.value.y,e.value.obj,e.value.object);break;case"getNewShapeId":e.value.obj.id=this.getNewShapeId();break;case"z-order":this.updateZOrder(e.value.obj,e.value.value);break;case"getSmallestIndex":e.value.obj.index=this.getSmallestIndex();break;case"isIndexInObjColl":e.value.obj.bool=this.isIndexInObjColl(e.value.index);break;case"drawAnnotations":this.drawAnnotations(e.value.ctx,e.value.shape,e.value.pen,e.value.isPreventApply,e.value.x,e.value.y,e.value.panRegion);break;case"updateShapeColl":this.updateShapeColl();break;case"getNewOrder":e.value.obj.order=this.getNewOrder();break;case"getHighestOrder":e.value.obj.order=this.getHighestOrder();break;case"getLowestOrder":e.value.obj.order=this.getLowestOrder()}},o.prototype.getModuleName=function(){return"shape"},o.prototype.initShapePvtProps=function(){var e=this.parent;e.lowerCanvas&&(this.lowerContext=e.lowerCanvas.getContext("2d")),e.upperCanvas&&(this.upperContext=e.upperCanvas.getContext("2d")),t.isNullOrUndefined(this.shapeImg)&&(this.shapeImg=e.createElement("img",{id:e.element.id+"_shapeImg",attrs:{name:"Image",crossorigin:"anonymous"}})),""===this.textSettings.fontFamily&&(this.textSettings.fontFamily=e.fontFamily.default)},o.prototype.reset=function(){this.textSettings={text:"Enter Text",fontFamily:this.parent.fontFamily.default,fontSize:null,fontRatio:null,bold:!1,italic:!1,underline:!1},this.strokeSettings={strokeColor:"#fff",fillColor:"",strokeWidth:null},this.preventFrameAnnotation=!1},o.prototype.drawEllipse=function(e,t,o,i,r,a,n,s,l){this.initializeShape("ellipse");var p=e&&t?{x:e,y:t}:null;this.drawShape("ellipse",r,a,n,p,o,i,null,null,null,s,null,l)},o.prototype.drawLine=function(e,t,o,i,r,a,n){this.initializeShape("line");var s=e&&t?{x:e,y:t}:null,l=o-e,p=i-t;this.drawShape("line",r,a,null,s,l,p,null,null,null,null,null,n)},o.prototype.drawPath=function(e,o,i,r){var a=this.parent;if(this.initializeShape("path"),e)this.drawShape("path",o,i,null,null,null,null,e,null,null,null,null,r);else{this.drawShape("line",o,i,null,null,null,null,null,null,null,null,null,r);var n=t.extend({},a.objColl[a.objColl.length-1],null,!0);n.shape="path",n.lineDraw=null,n.pointColl=[{x:n.activePoint.startX,y:n.activePoint.startY},{x:n.activePoint.endX,y:n.activePoint.endY}],a.objColl[a.objColl.length-1]=n}},o.prototype.drawArrow=function(e,t,o,i,r,a,n,s,l){this.initializeShape("arrow");var p=e&&t?{x:e,y:t}:null,h=o-e,d=i-t;this.drawShape("arrow",r,a,null,p,h,d,null,n,s,null,null,l)},o.prototype.drawRectangle=function(e,t,o,i,r,a,n,s,l){this.initializeShape("rectangle");var p=e&&t?{x:e,y:t}:null;this.drawShape("rectangle",r,a,n,p,o,i,null,null,null,s,null,l)},o.prototype.drawText=function(e,t,o,i,r,a,n,s,l,p){this.drawShapeText(o,i,r,a,n,s,e,t,l,p)},o.prototype.initializeShape=function(e){var t=this.parent;this.redrawActObj(),t.activeObj.shape=e,"freehanddraw"===t.currObjType.shape&&(this.apply(),t.upperCanvas.style.cursor=t.cursor="default",t.currObjType.shape=""),t.currObjType.isCustomCrop=!1},o.prototype.updateWidthHeight=function(e){return e.activePoint.width=e.activePoint.endX-e.activePoint.startX,e.activePoint.height=e.activePoint.endY-e.activePoint.startY,e},o.prototype.setDimension=function(e,t){var o=this.parent;e&&t&&(o.activeObj.activePoint.width=e,o.activeObj.activePoint.height=t,"ellipse"===o.currObjType.shape.toLowerCase()&&(o.activeObj.activePoint.width=2*e,o.activeObj.activePoint.height=2*t))},o.prototype.getArrowType=function(e){var t=e;return e&&(t={None:"none",Arrow:"arrow",SolidArrow:"arrowSolid",Circle:"circle",SolidCircle:"circleSolid",Square:"square",SolidSquare:"squareSolid",Bar:"bar"}[""+e]),t},o.prototype.drawShape=function(e,o,i,r,a,n,s,l,p,h,d,c,u){var v=this.parent;if(!v.disabled&&v.isImageLoaded){v.notify("draw",{prop:"setImageEdited",onPropertyChange:!1}),this.redrawActObj();var g=t.extend([],v.objColl,[],!0);if(v.togglePen=!1,this.keyHistory="",v.upperCanvas.style.display="block",this.refreshActiveObj(),v.currObjType.shape=e=e.toLowerCase(),"path"===e&&t.isNullOrUndefined(l))v.activeObj.shape=e,v.activeObj.pointColl=[],v.upperCanvas.style.cursor=v.cursor="crosshair",v.notify("selection",{prop:"setCurrentDrawingShape",onPropertyChange:!1,value:{value:"path"}}),v.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"shapes",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}}),v.notify("toolbar",{prop:"update-toolbar-items",onPropertyChange:!1});else if("freehanddraw"!==e&&""!==e){v.activeObj.shape=e;var f=v.activeObj.strokeSettings;this.upperContext.clearRect(0,0,v.upperCanvas.width,v.upperCanvas.height),t.isNullOrUndefined(f)&&(f=this.strokeSettings),"path"===e&&l&&(v.activeObj.pointColl=l),null!==c&&void 0!==c&&(v.activeObj.opacity=c),f.strokeWidth=o||f.strokeWidth,f.strokeColor=i||f.strokeColor,f.fillColor=r||f.fillColor;var C=v.img.destWidth>100?100:v.img.destWidth/2,b=v.img.destHeight>100?100:v.img.destHeight/2;v.activeObj.activePoint.width=C,v.activeObj.activePoint.height=b,"line"===e||"arrow"===e?(v.activeObj.lineDraw="horizontal",v.activeObj.activePoint.height=0,"arrow"===e&&(v.activeObj.activePoint.width+=50,v.activeObj.start=this.getArrowType(p),v.activeObj.end=this.getArrowType(h))):"rectangle"===e&&(v.activeObj.activePoint.width+=v.activeObj.activePoint.width/2),this.setDimension(n,s),a?(v.activeObj.activePoint.startX=a.x,v.activeObj.activePoint.startY=a.y,v.activeObj.activePoint.endX=v.activeObj.activePoint.startX+v.activeObj.activePoint.width,v.activeObj.activePoint.endY=v.activeObj.activePoint.startY+v.activeObj.activePoint.height):this.setCenterPoints(),this.setPointCollForLineAndArrow(),"arrow"===e&&(v.activeObj.triangleDirection="right"),v.currObjType.isDragging=v.currObjType.isCustomCrop=!1,this.initShapeProps();var m={shapeSettingsObj:{}};v.notify("selection",{prop:"updatePrevShapeSettings",onPropertyChange:!1,value:{obj:m}});var y=m.shapeSettingsObj,P={cancel:!1,action:"insert",previousShapeSettings:y,currentShapeSettings:y};v.trigger("shapeChanging",P),this.updateShapeChangeEventArgs(P.currentShapeSettings),this.setDimension(n,s),v.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate"}}),d&&(v.activeObj.rotatedAngle=d*(Math.PI/180),v.notify("selection",{prop:"updPtCollForShpRot",onPropertyChange:!1,value:{obj:v.activeObj}})),v.notify("toolbar",{prop:"renderQAT",onPropertyChange:!1,value:{isPenEdit:null}}),v.notify("selection",{prop:"isShapeInserted",onPropertyChange:!1,value:{bool:!0}}),v.notify("undo-redo",{prop:"updateUrObj",onPropertyChange:!1,value:{objColl:g}}),v.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"shapes",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}}),v.notify("toolbar",{prop:"update-toolbar-items",onPropertyChange:!1}),v.isPublicMethod&&!u&&v.notify("undo-redo",{prop:"updateUndoRedo",value:{operation:"shapeInsert"},onPropertyChange:!1}),v.isPublicMethod=!1}}},o.prototype.initShapeProps=function(){var e=this.parent;e.activeObj.shapeDegree=e.transform.degree,e.activeObj.shapeFlip=e.transform.currFlipState,e.activeObj.textFlip=e.transform.currFlipState,e.activeObj.flipObjColl=[],e.activeObj.order=this.getNewOrder()},o.prototype.setPointCollForLineAndArrow=function(){var e=this.parent,t=e.activeObj.shape,o=e.activeObj.activePoint,i=o.startX,r=o.startY,a=o.endX,n=o.endY;if(("line"===t||"arrow"===t)&&(e.activeObj.pointColl=this.getLinePoints(i,r,a,n),e.activeObj.pointColl))for(var s=0,l=e.activeObj.pointColl.length;s<l;s++)e.activeObj.pointColl[s].ratioX=(e.activeObj.pointColl[s].x-e.img.destLeft)/e.img.destWidth,e.activeObj.pointColl[s].ratioY=(e.activeObj.pointColl[s].y-e.img.destTop)/e.img.destHeight},o.prototype.prevObjColl=function(){var e=this.parent,o={currObj:{}};e.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:o}}),this.prevObj=o.currObj,this.prevObj.objColl=t.extend([],e.objColl,[],!0),this.prevObj.pointColl=t.extend([],e.pointColl,[],!0),this.prevObj.afterCropActions=t.extend([],e.afterCropActions,[],!0);var i={selPointColl:null};e.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:i}}),this.prevObj.selPointColl=t.extend([],i.selPointColl,[],!0)},o.prototype.drawShapeText=function(e,o,i,r,a,n,s,l,p,h){var d=this.parent;if(!d.disabled&&d.isImageLoaded){"freehanddraw"===d.currObjType.shape&&(this.apply(),d.upperCanvas.style.cursor=d.cursor="default",d.currObjType.shape=""),d.notify("draw",{prop:"setImageEdited",onPropertyChange:!1}),d.togglePen=!1,this.redrawActObj(),this.prevObjColl(),this.refreshActiveObj(),d.activeObj.shape=d.currObjType.shape="text",d.currObjType.isCustomCrop=!1,this.initializeTextShape(e,o,i,r,a,n),d.currObjType.isText=d.currObjType.isInitialText=!0,t.isNullOrUndefined(d.activeObj.textSettings.fontSize)&&(d.getFontSizes(),d.activeObj.textSettings.fontSize=parseInt(d.fontSizeColl[parseInt("3",10)-1].text,10)),d.img.destWidth<100?d.activeObj.textSettings.fontSize=Math.floor(d.img.destWidth/20):d.img.destHeight<100&&(d.activeObj.textSettings.fontSize=Math.floor(d.img.destHeight/20)),d.activeObj.shapeDegree=d.transform.degree,d.activeObj.shapeFlip=d.transform.currFlipState,d.activeObj.flipObjColl=[],this.updateFontStyles(),d.activeObj.order=this.getNewOrder();var c=this.upperContext.measureText(d.activeObj.textSettings.text).width+.5*d.activeObj.textSettings.fontSize,u=d.activeObj.textSettings.fontSize+.25*d.activeObj.textSettings.fontSize;t.isNullOrUndefined(s)||t.isNullOrUndefined(l)?this.setCenterPoints(!0,c,u):(d.activeObj.activePoint.startX=s,d.activeObj.activePoint.startY=l,d.activeObj.activePoint.endX=d.activeObj.activePoint.startX+c,d.activeObj.activePoint.endY=d.activeObj.activePoint.startY+u);var v={shapeSettingsObj:{}};d.notify("selection",{prop:"updatePrevShapeSettings",onPropertyChange:!1,value:{obj:v}});var g=v.shapeSettingsObj,f={cancel:!1,action:"insert",previousShapeSettings:g,currentShapeSettings:g};if(d.trigger("shapeChanging",f),this.drawShapeTextEvent(f),h&&(d.activeObj.rotatedAngle=h*(Math.PI/180),d.notify("selection",{prop:"updPtCollForShpRot",onPropertyChange:!1,value:{obj:d.activeObj}}),this.upperContext.clearRect(0,0,d.upperCanvas.width,d.upperCanvas.height),d.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate",obj:d.activeObj,isCropRatio:null,points:null,isPreventDrag:!0,saveContext:null,isPreventSelection:null}}),d.notify("toolbar",{prop:"destroy-qa-toolbar",onPropertyChange:!1}),d.notify("toolbar",{prop:"renderQAT",onPropertyChange:!1,value:{isPenEdit:null}})),e&&e.indexOf("\n")>-1&&d.isPublicMethod){var C=String(d.fontSizeColl.findIndex(function(e){return e.text===String(d.activeObj.textSettings.fontSize)})+1);d.noPushUndo=!0,d.updateFontSize("5"),parseInt(C,10)>0&&d.updateFontSize(C),d.noPushUndo=!1}d.isPublicMethod&&!p&&d.notify("undo-redo",{prop:"updateUndoRedo",value:{operation:"shapeInsert"},onPropertyChange:!1}),d.isPublicMethod=!1}},o.prototype.drawShapeImageEvent=function(e,o){var i=this.parent;this.updateShapeChangeEventArgs(e.currentShapeSettings),i.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate"}}),i.objColl.push(i.activeObj);var r=t.extend({},i.cropObj,{},!0);i.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"shapeInsert",previousObj:this.prevObj,previousObjColl:this.prevObj.objColl,previousPointColl:this.prevObj.pointColl,previousSelPointColl:this.prevObj.selPointColl,previousCropObj:r,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),i.notify("selection",{prop:"redrawShape",onPropertyChange:!1,value:{obj:i.objColl[i.objColl.length-1]}}),o?(i.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"shapes",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}}),i.notify("toolbar",{prop:"update-toolbar-items",onPropertyChange:!1}),i.notify("toolbar",{prop:"renderQAT",onPropertyChange:!1,value:{isPenEdit:null}})):i.okBtn(null,!0),i.notify("selection",{prop:"isShapeInserted",onPropertyChange:!1,value:{bool:!0}})},o.prototype.drawShapeTextEvent=function(e){var o=this.parent;this.updateShapeChangeEventArgs(e.currentShapeSettings),this.addLetter(o.activeObj.textSettings.text),o.activeObj.textFlip=o.transform.currFlipState,this.updateFontRatio(o.activeObj),o.objColl.push(o.activeObj);var i=t.extend({},o.cropObj,{},!0);o.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"shapeInsert",previousObj:this.prevObj,previousObjColl:this.prevObj.objColl,previousPointColl:this.prevObj.pointColl,previousSelPointColl:this.prevObj.selPointColl,previousCropObj:i,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),o.notify("selection",{prop:"redrawShape",onPropertyChange:!1,value:{obj:o.objColl[o.objColl.length-1]}}),o.notify("toolbar",{prop:"renderQAT",onPropertyChange:!1,value:{isPenEdit:null}}),o.notify("selection",{prop:"isShapeInserted",onPropertyChange:!1,value:{bool:!0}}),o.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"text",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}}),o.notify("toolbar",{prop:"update-toolbar-items",onPropertyChange:!1})},o.prototype.initializeTextShape=function(e,o,i,r,a,n){var s=this.parent;this.keyHistory="",s.upperCanvas.style.display="block",t.isNullOrUndefined(s.activeObj.textSettings)&&(s.activeObj.textSettings=this.textSettings),t.isNullOrUndefined(s.activeObj.strokeSettings)&&(s.activeObj.strokeSettings=this.strokeSettings),s.activeObj.strokeSettings.strokeColor=n||s.activeObj.strokeSettings.strokeColor,s.activeObj.textSettings.text=e||s.activeObj.textSettings.text,s.activeObj.textSettings.fontFamily=o||s.activeObj.textSettings.fontFamily,s.activeObj.textSettings.fontSize=i||s.activeObj.textSettings.fontSize,s.activeObj.textSettings.bold=r||s.activeObj.textSettings.bold,s.activeObj.textSettings.italic=a||s.activeObj.textSettings.italic},o.prototype.drawImage=function(e,t,o,i,r,a,n,s,l){this.initializeShape("image"),this.onLoadImgShape(e,t,o,i,r,null,a,n,s,l)},o.prototype.redrawActObj=function(e,t,o){var i,r=this.parent;r.activeObj.shape&&(i=r.activeObj.shape.split("-")),r.activeObj.horTopLine&&r.activeObj.shape&&"crop"!==i[0]&&("block"===r.textArea.style.display||"inline-block"===r.textArea.style.display?(r.notify("selection",{prop:"setTextBoxStylesToActObj",onPropertyChange:!1}),this.updateFontRatio(r.activeObj,!0),e&&t?e!==r.activeObj.activePoint.startX&&t!==r.activeObj.activePoint.startY&&this.updateTextFromTextArea():(this.updateTextFromTextArea(),r.textArea.style.transform="",r.notify("toolbar",{prop:"refresh-main-toolbar",onPropertyChange:!1})),this.refreshActiveObj()):this.applyActObj(o))},o.prototype.apply=function(e,o,i){var r=this.parent;if(!r.disabled)if(r.togglePen&&!r.currObjType.isCustomCrop){var a=r.img.destLeft,n=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,(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=a,r.img.destTop=n,r.img.destWidth=s,r.img.destHeight=l,this.lowerContext.filter=p}else i=i||"original",t.isNullOrUndefined(r.activeObj.shape)&&t.isNullOrUndefined(e)?r.currObjType.shape="":r.currObjType.shape=e||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:i,obj:o,isCropRatio:null,points:null,isPreventDrag:!0,saveContext:null,isPreventSelection:null}}):r.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:i,obj:o}}),r.activeObj.shape=r.currObjType.shape.toLowerCase(),e||""===r.currObjType.shape||r.currObjType.isCustomCrop||r.objColl.push(t.extend({},r.activeObj,{},!0)),this.keyHistory="")},o.prototype.setCenterPoints=function(e,t,o){var i,r,a=this.parent;e&&t&&o?(i=t,r=o):(i=a.activeObj.activePoint.width,r=a.activeObj.activePoint.height),a.activeObj.activePoint.startX=a.lowerCanvas.width/2-i/2,a.activeObj.activePoint.startY=a.lowerCanvas.height/2-r/2,a.activeObj.activePoint.endX=a.lowerCanvas.width/2+i/2,a.activeObj.activePoint.endY=a.lowerCanvas.height/2+r/2},o.prototype.updSelChangeEventArgs=function(e){var t=this.parent;t.activeObj.activePoint={startX:e.startX,startY:e.startY,endX:t.activeObj.activePoint.startX+t.activeObj.activePoint.width,endY:t.activeObj.activePoint.startY+t.activeObj.activePoint.height,width:e.width,height:e.height},t.activeObj.activePoint.endX=t.activeObj.activePoint.startX+t.activeObj.activePoint.width,t.activeObj.activePoint.endY=t.activeObj.activePoint.startY+t.activeObj.activePoint.height},o.prototype.updateShapeChangeEventArgs=function(e){var o,i=this.parent;if(e.id&&-1===e.id.indexOf("shape_")&&-1===e.id.indexOf("pen_")&&(i.activeObj.currIndex?i.activeObj.currIndex="shape_"+e.id:i.pointColl[o].id="pen_"+e.id),e.id&&e.id.split("_")[0]&&"pen"===e.id.split("_")[0])o=parseInt(e.id.split("_")[1],10)-1,i.pointColl[o].points=e.points,i.pointColl[o].strokeColor=e.strokeColor,i.pointColl[o].strokeWidth=e.strokeWidth,i.pointColl[o].opacity=e.opacity,i.pointColl[o].order=e.index;else{switch(i.activeObj.activePoint.startX=e.startX,i.activeObj.activePoint.startY=e.startY,e.width&&e.height&&(i.activeObj.activePoint.width=e.width,i.activeObj.activePoint.height=e.height,i.activeObj.activePoint.endX=i.activeObj.activePoint.startX+i.activeObj.activePoint.width,i.activeObj.activePoint.endY=i.activeObj.activePoint.startY+i.activeObj.activePoint.height),i.activeObj.strokeSettings.strokeColor=e.strokeColor,i.activeObj.strokeSettings.fillColor=e.fillColor,i.activeObj.strokeSettings.strokeWidth=e.strokeWidth,i.activeObj.opacity=e.opacity,i.activeObj.order=e.index,t.isNullOrUndefined(e.degree)&&(e.degree=0),i.activeObj.shape){case"ellipse":i.activeObj.activePoint.width=2*e.radiusX,i.activeObj.activePoint.height=2*e.radiusY,i.activeObj.activePoint.endX=i.activeObj.activePoint.startX+i.activeObj.activePoint.width,i.activeObj.activePoint.endY=i.activeObj.activePoint.startY+i.activeObj.activePoint.height,e.degree&&(i.activeObj.rotatedAngle=e.degree*(Math.PI/180));break;case"line":case"arrow":i.activeObj.activePoint.width=e.length,i.activeObj.activePoint.endX=e.endX,i.activeObj.activePoint.endY=e.endY,i.activeObj.activePoint.width=i.activeObj.activePoint.startX+i.activeObj.activePoint.width,i.activeObj.activePoint.height=i.activeObj.activePoint.startY+i.activeObj.activePoint.height,"arrow"===i.activeObj.shape&&(i.activeObj.start=this.getArrowType(e.arrowHead),i.activeObj.end=this.getArrowType(e.arrowTail));break;case"text":i.activeObj.keyHistory=i.activeObj.textSettings.text=e.text,i.activeObj.textSettings.fontSize=e.fontSize,i.activeObj.strokeSettings.strokeColor=e.color,i.activeObj.textSettings.fontFamily=e.fontFamily,e.degree&&(i.activeObj.rotatedAngle=e.degree*(Math.PI/180)),this.updateFontRatio(i.activeObj);break;case"rectangle":case"image":e.degree&&(i.activeObj.rotatedAngle=e.degree*(Math.PI/180));break;case"path":i.activeObj.pointColl=e.points}if("text"===i.activeObj.shape&&i.activeObj.textSettings){i.activeObj.textSettings.bold=!1,i.activeObj.textSettings.italic=!1,i.activeObj.textSettings.underline=!1;for(var r=0;r<e.fontStyle.length;r++)switch(e.fontStyle[r]){case"bold":i.activeObj.textSettings.bold=!0;break;case"italic":i.activeObj.textSettings.italic=!0;break;case"underline":i.activeObj.textSettings.underline=!0}}}},o.prototype.addLetter=function(e){var t=this.parent;if("none"===t.textArea.style.display&&(t.currObjType.isText||"text"===t.activeObj.shape)){var o=t.activeObj.textSettings.fontSize;"Backspace"===e?this.keyHistory=this.keyHistory.slice(0,-1):this.keyHistory+=e,this.upperContext.clearRect(0,0,t.upperCanvas.width,t.upperCanvas.height),this.updateFontStyles();var i=this.upperContext.measureText(this.keyHistory).width+.5*o,r=o+.25*o;this.upperContext.fillText(this.keyHistory,t.activeObj.activePoint.startX,t.activeObj.activePoint.startY+o),this.upperContext.clearRect(0,0,t.upperCanvas.width,t.upperCanvas.height),t.currObjType.isText=!0,t.notify("selection",{prop:"setActivePoint",onPropertyChange:!1,value:{startX:i,startY:r}})}},o.prototype.redrawText=function(){var e=this.parent,t=e.activeObj.textSettings,o=t.fontSize,i=t.fontFamily,r=t.bold,a=t.italic,n="";r&&(n+="bold "),a&&(n+="italic "),this.upperContext.font=n+o+"px "+i;var s=e.activeObj.keyHistory.split("\n"),l="block"===e.textArea.style.display||"inline-block"===e.textArea.style.display?this.getMaxText(!0):this.getMaxText(),p=this.upperContext.measureText(l).width+.5*o,h=s.length*(o+.25*o);e.notify("selection",{prop:"setTextSelection",onPropertyChange:!1,value:{width:p,height:h}}),e.notify("draw",{prop:"updateActiveObject",onPropertyChange:!1,value:{actPoint:e.activeObj.activePoint,obj:e.activeObj,isMouseMove:null,x:null,y:null}}),e.notify("selection",{prop:"redrawShape",onPropertyChange:!1,value:{obj:e.activeObj}})},o.prototype.updateTextFromTextArea=function(){var e=this.parent,o=!1,i=e.activeObj.textSettings.fontSize,r=t.extend({},e.activeObj,{},!0),a=t.extend({},e.cropObj,{},!0),n={currObj:{}};e.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:n}});var s=n.currObj;s.objColl=t.extend([],e.objColl,[],!0),s.pointColl=t.extend([],e.pointColl,[],!0),s.afterCropActions=t.extend([],e.afterCropActions,[],!0);var l={selPointColl:null};e.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:l}}),s.selPointColl=t.extend([],l.selPointColl,[],!0),e.activeObj.keyHistory!==e.textArea.value&&(o=!0),e.activeObj.keyHistory=e.textArea.value,e.textArea.style.display="none",e.textArea.value="",this.updateFontStyles();var p=this.upperContext.measureText(e.activeObj.keyHistory).width+.5*i,h=i+.25*i,d=e.activeObj.keyHistory.split("\n");if(d.length>1){h*=d.length;for(var c=[],u=0,v=d.length;u<v;u++)c.push(this.upperContext.measureText(d[u]).width+.5*i);p=Math.max.apply(Math,c)}if(e.notify("selection",{prop:"setTextSelection",onPropertyChange:!1,value:{width:p,height:h}}),0!==e.activeObj.rotatedAngle){var g=e.activeObj.activePoint.width-r.activePoint.width,f=e.activeObj.activePoint.height-r.activePoint.height,C="";g>0&&f>0?C="widthHeight":0!==g?C="width":0!==f&&(C="height"),e.activeObj.activePoint=t.extend({},r.activePoint,{},!0),e.notify("selection",{prop:"adjustRotationPoints",onPropertyChange:!1,value:{rectangle:e.activeObj.activePoint,x:g,y:f,angle:e.activeObj.rotatedAngle,type:"text",elem:C}}),e.notify("shape",{prop:"updateFontSize",onPropertyChange:!1,value:{obj:e.activeObj}})}e.notify("draw",{prop:"updateActiveObject",onPropertyChange:!1,value:{actPoint:e.activeObj.activePoint,obj:e.activeObj,isMouseMove:null,x:null,y:null}}),this.updImgRatioForActObj(),0!==e.activeObj.rotatedAngle&&e.notify("selection",{prop:"updPtCollForShpRot",onPropertyChange:!1,value:{obj:e.activeObj}}),o?(this.apply(e.activeObj.shape,e.activeObj),e.objColl.push(t.extend({},e.activeObj,{},!0)),e.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"text",previousObj:s,previousObjColl:s.objColl,previousPointColl:s.pointColl,previousSelPointColl:s.selPointColl,previousCropObj:a,previousText:e.activeObj.keyHistory,currentText:e.textArea.value,previousFilter:null,isCircleCrop:null}})):(this.apply(e.activeObj.shape,e.activeObj),e.objColl.push(t.extend({},e.activeObj,{},!0)))},o.prototype.iterateObjColl=function(){var e=this.parent;if(e.objColl.length>0)for(var o=this.getSmallestIndex(),i=t.extend([],e.objColl,[],!0);i.length>0;){for(var r=!1,a=0;a<i.length;a++){var n=i[a];if(t.isNullOrUndefined(n.order))i.splice(a,1),a--;else if(n.order===o){this.apply(n.shape,n),this.refreshActiveObj(),o++,this.isIndexInObjColl(o)||o++,i.splice(a,1),r=!0;break}}if(!r)break}},o.prototype.getSmallestIndex=function(){for(var e,o=this.parent,i=0,r=o.objColl.length;i<r;i++){var a=o.objColl[i];t.isNullOrUndefined(a.order)||(t.isNullOrUndefined(e)||a.order<e)&&(e=a.order)}return e},o.prototype.isIndexInObjColl=function(e){for(var o=this.parent,i=0,r=o.objColl.length;i<r;i++){var a=o.objColl[i];if(!t.isNullOrUndefined(a.order)&&a.order===e)return!0}return!1},o.prototype.updImgRatioForActObj=function(){var e=this.parent,t={startX:e.img.destLeft,startY:e.img.destTop,width:e.img.destWidth,height:e.img.destHeight};this.straightenShapes();var o=e.img,i=o.destLeft,r=o.destTop,a=o.destWidth,n=o.destHeight,s=e.activeObj.activePoint;e.activeObj.imageRatio={startX:(s.startX-i)/a,startY:(s.startY-r)/n,endX:(s.endX-i)/a,endY:(s.endY-r)/n,width:a/s.width,height:n/s.height},e.activeObj.rotationCirclePointColl&&(e.activeObj.rotationCirclePointColl.ratioX=(e.activeObj.rotationCirclePointColl.x-i)/a,e.activeObj.rotationCirclePointColl.ratioY=(e.activeObj.rotationCirclePointColl.y-r)/n),"path"===e.activeObj.shape?this.updatePathRatio(e.activeObj):"arrow"===e.activeObj.shape&&this.updateArrowRatio(e.activeObj),e.img.destLeft=t.startX,e.img.destTop=t.startY,e.img.destWidth=t.width,e.img.destHeight=t.height},o.prototype.zoomObjColl=function(e){var o=this.parent,i={startX:o.img.destLeft,startY:o.img.destTop,width:o.img.destWidth,height:o.img.destHeight};if(this.straightenShapes(),o.objColl.length>0){for(var r=0,a=o.objColl.length;r<a;r++){var n=o.objColl[r];if(n.imageRatio&&(n.activePoint.startX=n.imageRatio.startX*o.img.destWidth+o.img.destLeft,n.activePoint.startY=n.imageRatio.startY*o.img.destHeight+o.img.destTop,n.activePoint.endX=n.imageRatio.endX*o.img.destWidth+o.img.destLeft,n.activePoint.endY=n.imageRatio.endY*o.img.destHeight+o.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 s=0,l=n.pointColl.length;s<l;s++)n.pointColl[s].ratioX=(n.pointColl[s].x-o.img.destLeft)/o.img.destWidth,n.pointColl[s].ratioY=(n.pointColl[s].y-o.img.destTop)/o.img.destHeight;"arrow"===n.shape&&this.updateArrowSize(n),0===o.transform.straighten||"line"!==n.shape&&"arrow"!==n.shape||this.straightenShapePoints(n)}else if("path"===n.shape){for(var p=0,h=n.pointColl.length;p<h;p++)n.pointColl[p].x=n.pointColl[p].ratioX*o.img.destWidth+o.img.destLeft,n.pointColl[p].y=n.pointColl[p].ratioY*o.img.destHeight+o.img.destTop;this.updatePathRatio(n),0!==o.transform.straighten&&this.straightenPath(n)}o.notify("draw",{prop:"updateActiveObject",onPropertyChange:!1,value:{actPoint:n.activePoint,obj:n}}),"line"!==n.shape&&"arrow"!==n.shape&&"path"!==n.shape&&0!==n.rotatedAngle&&(this.setPointCollForShapeRotation(n),n.rotationCirclePoint.x=n.rotationCirclePoint.ratioX*o.img.destWidth+o.img.destLeft,n.rotationCirclePoint.y=n.rotationCirclePoint.ratioY*o.img.destHeight+o.img.destTop,n.rotationCirclePointColl&&(n.rotationCirclePointColl.x=n.rotationCirclePointColl.ratioX*o.img.destWidth+o.img.destLeft,n.rotationCirclePointColl.y=n.rotationCirclePointColl.ratioY*o.img.destHeight+o.img.destTop))}if(t.isNullOrUndefined(e)){var d=this.lowerContext.filter;this.lowerContext.filter="none",this.iterateObjColl(),this.lowerContext.filter=d}}o.img.destLeft=i.startX,o.img.destTop=i.startY,o.img.destWidth=i.width,o.img.destHeight=i.height},o.prototype.straightenPath=function(e){for(var t,o=0,i=e.pointColl.length;o<i;o++)t=this.straightenPoints(e.pointColl[o].x,e.pointColl[o].y),e.pointColl[o].x=t.x,e.pointColl[o].y=t.y},o.prototype.straightenFHD=function(){for(var e=this.parent,o=0,i=e.freehandCounter;o<i;o++){e.points=t.extend([],e.pointColl[o].points,[]);for(var r=e.points.length,a=void 0,n=0;n<r;n++)a=this.straightenPoints(e.points[n].x,e.points[n].y),e.points[n].x=a.x,e.points[n].y=a.y}var s={selPointColl:null};e.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:s}});for(var o=0,i=e.freehandCounter;o<i;o++)for(var r=s.selPointColl[o].points.length,a=void 0,n=0;n<r;n++)a=this.straightenPoints(s.selPointColl[o].points[n].x,s.selPointColl[o].points[n].y),s.selPointColl[o].points[n].x=a.x,s.selPointColl[o].points[n].y=a.y;var l={straightenPoint:null};if(e.notify("freehand-draw",{prop:"getStraightenPoint",onPropertyChange:!1,value:{obj:l}}),l.straightenPoint.x&&l.straightenPoint.y){var p={angle:0};e.notify("freehand-draw",{prop:"getStraightenPointAngle",onPropertyChange:!1,value:{obj:p}});var h=((360===e.transform.straighten?0:e.transform.straighten)-p.angle)*(Math.PI/180),a=this.straightenPoints(l.straightenPoint.x,l.straightenPoint.y,h);0===h&&(a.x=l.straightenPoint.x,a.y=l.straightenPoint.y),e.notify("freehand-draw",{prop:"setStraightenPoint",onPropertyChange:!1,value:{x:a.x,y:a.y}})}},o.prototype.straightenPoints=function(e,t,o){var i=this.parent,r={x:i.img.destLeft+i.img.destWidth/2,y:i.img.destTop+i.img.destHeight/2};return o=o||i.transform.straighten*(Math.PI/180),{x:Math.cos(o)*(e-r.x)-Math.sin(o)*(t-r.y)+r.x,y:Math.sin(o)*(e-r.x)+Math.cos(o)*(t-r.y)+r.y}},o.prototype.straightenShapes=function(){var e=this.parent,t=e.img,o=t.destLeft,i=t.destTop,r=t.destWidth,a=t.destHeight;if({bool:e.isStraightening}.bool&&0!==e.transform.straighten){e.notify("draw",{prop:"updateImgCanvasPoints"});var n={points:null};e.notify("draw",{prop:"getImageCanvasPoints",value:{obj:n}});var s={x:o+r/2,y:i+a/2},l=-e.transform.straighten*(Math.PI/180),p={x:Math.cos(l)*(n.points[0].x-s.x)-Math.sin(l)*(n.points[0].y-s.y)+s.x,y:Math.sin(l)*(n.points[0].x-s.x)+Math.cos(l)*(n.points[0].y-s.y)+s.y},h={x:Math.cos(l)*(n.points[1].x-s.x)-Math.sin(l)*(n.points[1].y-s.y)+s.x,y:Math.sin(l)*(n.points[1].x-s.x)+Math.cos(l)*(n.points[1].y-s.y)+s.y},d={x:Math.cos(l)*(n.points[2].x-s.x)-Math.sin(l)*(n.points[2].y-s.y)+s.x,y:Math.sin(l)*(n.points[2].x-s.x)+Math.cos(l)*(n.points[2].y-s.y)+s.y};e.img.destWidth=h.x-p.x,e.img.destHeight=d.y-h.y,e.img.destLeft=p.x,e.img.destTop=p.y}},o.prototype.straightenShapePoints=function(e,t){var o=this.parent,i=o.img,r=i.destLeft,a=i.destTop,n=i.destWidth,s=i.destHeight;if({bool:o.isStraightening}.bool&&("line"===e.shape||"arrow"===e.shape)){e.activePoint.width=e.activePoint.endX>e.activePoint.startX?e.activePoint.endX-e.activePoint.startX:e.activePoint.startX-e.activePoint.endX,e.activePoint.height=e.activePoint.endY>e.activePoint.startY?e.activePoint.endY-e.activePoint.startY:e.activePoint.startY-e.activePoint.endY;var l={x:r+n/2,y:a+s/2},p=(t?-o.transform.straighten:o.transform.straighten)*(Math.PI/180),h={x:Math.cos(p)*(e.activePoint.startX-l.x)-Math.sin(p)*(e.activePoint.startY-l.y)+l.x,y:Math.sin(p)*(e.activePoint.startX-l.x)+Math.cos(p)*(e.activePoint.startY-l.y)+l.y},d={x:Math.cos(p)*(e.activePoint.endX-l.x)-Math.sin(p)*(e.activePoint.endY-l.y)+l.x,y:Math.sin(p)*(e.activePoint.endX-l.x)+Math.cos(p)*(e.activePoint.endY-l.y)+l.y};e.activePoint.startX=h.x,e.activePoint.startY=h.y,e.activePoint.endX=d.x,e.activePoint.endY=d.y,e.activePoint.width=e.activePoint.endX>e.activePoint.startX?e.activePoint.endX-e.activePoint.startX:e.activePoint.startX-e.activePoint.endX,e.activePoint.height=e.activePoint.endY>e.activePoint.startY?e.activePoint.endY-e.activePoint.startY:e.activePoint.startY-e.activePoint.endY,o.notify("selection",{prop:"adjustActObjForLineArrow",onPropertyChange:!1,value:{obj:e}})}},o.prototype.redrawObj=function(e){var t=this.parent,o=!1;if(t.objColl.length>0)if("horizontal"===e||"vertical"===e||"Horizontal"===e||"Vertical"===e||"horizontalVertical"===e||"verticalHorizontal"===e)this.updateCurrentActiveObjPoint(e.toLowerCase());else if("number"==typeof e){this.updateCurrentActiveObjPoint(e);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 r=0,a=t.objColl.length;r<a;r++)"crop"!==t.objColl[r].shape.split("-")[0]&&(this.apply(t.objColl[r].shape,t.objColl[r]),o=!0);o&&t.notify("draw",{prop:"applyFrame",value:{ctx:this.lowerContext,frame:t.frameObj.type,preventImg:!0}}),this.lowerContext.filter=i}},o.prototype.updateCurrentActiveObjPoint=function(e){for(var o,i=this.parent,r=i.img,a=r.destLeft,n=r.destTop,s=r.destWidth,l=r.destHeight,p=0,h=i.objColl.length;p<h;p++){var d=i.objColl[p];if(i.activeObj.shape===d.shape&&i.activeObj.activePoint.startX===d.activePoint.startX&&i.activeObj.activePoint.startY===d.activePoint.startY&&i.activeObj.activePoint.endX===d.activePoint.endX&&i.activeObj.activePoint.endY===d.activePoint.endY&&i.activeObj.currIndex===d.currIndex){o=p;break}}if("horizontal"===e||"vertical"===e||"Horizontal"===e||"Vertical"===e||"horizontalvertical"===e||"verticalhorizontal"===e){if("horizontal"===e||"Horizontal"===e)for(var c=0,h=i.objColl.length;c<h;c++)(d=i.objColl[c]).shapeFlip!==i.transform.currFlipState&&(d.activePoint.startX<=a+s/2?(d.activePoint.endX=a+s-(d.activePoint.startX-a),d.activePoint.startX=d.activePoint.endX-d.activePoint.width,i.notify("draw",{prop:"updateActiveObject",onPropertyChange:!1,value:{actPoint:d.activePoint,obj:d}})):d.activePoint.startX>=a+s/2&&(d.activePoint.startX=a+(a+s-d.activePoint.endX),d.activePoint.endX=d.activePoint.startX+d.activePoint.width,i.notify("draw",{prop:"updateActiveObject",onPropertyChange:!1,value:{actPoint:d.activePoint,obj:d}})),"line"===d.shape||"arrow"===d.shape||"path"===d.shape?this.flipLineArrowObj(d,"horizontal"):0!==d.rotatedAngle&&(d.rotatedAngle=d.rotatedAngle+2*(Math.PI-d.rotatedAngle),d.rotationCirclePointColl.x<=a+s/2?d.rotationCirclePointColl.x=a+s-(d.rotationCirclePointColl.x-a):d.rotationCirclePointColl.x>=a+s/2&&(d.rotationCirclePointColl.x=a+(a+s-d.rotationCirclePointColl.x)),d.rotationCirclePointColl.ratioX=(d.rotationCirclePointColl.x-a)/s),d.shapeFlip=i.transform.currFlipState,d.imageRatio={startX:(d.activePoint.startX-a)/s,startY:(d.activePoint.startY-n)/l,endX:(d.activePoint.endX-a)/s,endY:(d.activePoint.endY-n)/l,width:s/d.activePoint.width,height:l/d.activePoint.height});else if("vertical"===e||"Vertical"===e)for(c=0;c<i.objColl.length;c++)(d=i.objColl[c]).shapeFlip!==i.transform.currFlipState&&(d.activePoint.startY<=n+l/2?(d.activePoint.endY=n+l-(d.activePoint.startY-n),d.activePoint.startY=d.activePoint.endY-d.activePoint.height,i.notify("draw",{prop:"updateActiveObject",onPropertyChange:!1,value:{actPoint:d.activePoint,obj:d}})):d.activePoint.startY>=i.lowerCanvas.height/2&&(d.activePoint.startY=n+(n+l-d.activePoint.endY),d.activePoint.endY=d.activePoint.startY+d.activePoint.height,i.notify("draw",{prop:"updateActiveObject",onPropertyChange:!1,value:{actPoint:d.activePoint,obj:d}})),"line"===d.shape||"arrow"===d.shape||"path"===d.shape?this.flipLineArrowObj(d,"vertical"):0!==d.rotatedAngle&&(d.rotatedAngle=-d.rotatedAngle,d.rotationCirclePointColl.y<=n+l/2?d.rotationCirclePointColl.y=n+l-(d.rotationCirclePointColl.y-n):d.rotationCirclePointColl.y>=n+l/2&&(d.rotationCirclePointColl.y=n+(n+l-d.rotationCirclePointColl.y)),d.rotationCirclePointColl.ratioY=(d.rotationCirclePointColl.y-n)/l),d.shapeFlip=i.transform.currFlipState,d.imageRatio={startX:(d.activePoint.startX-a)/s,startY:(d.activePoint.startY-n)/l,endX:(d.activePoint.endX-a)/s,endY:(d.activePoint.endY-n)/l,width:s/d.activePoint.width,height:l/d.activePoint.height});else if("verticalhorizontal"===e||"horizontalvertical"===e)for(var c=0,h=i.objColl.length;c<h;c++)(d=i.objColl[c]).shapeFlip!==i.transform.currFlipState&&(d.activePoint.startX<=a+s/2?(d.activePoint.endX=a+s-(d.activePoint.startX-a),d.activePoint.startX=d.activePoint.endX-d.activePoint.width,i.notify("draw",{prop:"updateActiveObject",onPropertyChange:!1,value:{actPoint:d.activePoint,obj:d}})):d.activePoint.startX>=a+s/2&&(d.activePoint.startX=a+(a+s-d.activePoint.endX),d.activePoint.endX=d.activePoint.startX+d.activePoint.width,i.notify("draw",{prop:"updateActiveObject",onPropertyChange:!1,value:{actPoint:d.activePoint,obj:d}})),d.activePoint.startY<=n+l/2?(d.activePoint.endY=n+l-(d.activePoint.startY-n),d.activePoint.startY=d.activePoint.endY-d.activePoint.height,i.notify("draw",{prop:"updateActiveObject",onPropertyChange:!1,value:{actPoint:d.activePoint,obj:d}})):d.activePoint.startY>=i.lowerCanvas.height/2&&(d.activePoint.startY=n+(n+l-d.activePoint.endY),d.activePoint.endY=d.activePoint.startY+d.activePoint.height,i.notify("draw",{prop:"updateActiveObject",onPropertyChange:!1,value:{actPoint:d.activePoint,obj:d}})),"line"!==d.shape&&"arrow"!==d.shape&&"path"!==d.shape||this.flipLineArrowObj(d,e),d.shapeFlip=i.transform.currFlipState,d.imageRatio={startX:(d.activePoint.startX-a)/s,startY:(d.activePoint.startY-n)/l,endX:(d.activePoint.endX-a)/s,endY:(d.activePoint.endY-n)/l,width:s/d.activePoint.width,height:l/d.activePoint.height});void 0!==o&&(i.activeObj=t.extend({},i.objColl[o],{},!0))}else if(90===e)this.rotateObjColl();else if(-90===e)for(c=0;c<3;c++)this.rotateObjColl();else if("number"==typeof e)if(e>0)this.rotateObjColl();else for(c=0;c<3;c++)this.rotateObjColl()},o.prototype.rotateObjColl=function(){for(var e=this.parent,t=e.img,o=t.destWidth,i=t.destHeight,r=t.destLeft,a=t.destTop,n=0,s=e.objColl.length;n<s;n++){var l=(p=e.objColl[n]).shape;p.activePoint.startY=a+i*p.imageRatio.startX,p.activePoint.endY=a+i*p.imageRatio.endX,p.activePoint.startX=r+o-o*p.imageRatio.endY,p.activePoint.endX=r+o-o*p.imageRatio.startY,p=this.updateWidthHeight(e.objColl[n]),this.updateFontSize(p),"line"===l||"arrow"===l||"path"===l?(this.rotateLineArrowObj(p),"arrow"===l&&this.updateArrowSize(p)):0!==p.rotatedAngle&&(p.rotationCirclePointColl.y=a+i*p.rotationCirclePointColl.ratioX,p.rotationCirclePointColl.x=r+o-o*p.rotationCirclePointColl.ratioY,p.rotationCirclePointColl.ratioX=(p.rotationCirclePointColl.x-r)/o,p.rotationCirclePointColl.ratioY=(p.rotationCirclePointColl.y-a)/i)}for(var n=0,s=e.objColl.length;n<s;n++)e.notify("draw",{prop:"updateActiveObject",onPropertyChange:!1,value:{actPoint:e.objColl[n].activePoint,obj:e.objColl[n]}});for(var n=0,s=e.objColl.length;n<s;n++){var p=e.objColl[n];p.imageRatio={startX:(p.activePoint.startX-r)/o,startY:(p.activePoint.startY-a)/i,endX:(p.activePoint.endX-r)/o,endY:(p.activePoint.endY-a)/i,width:o/p.activePoint.width,height:i/p.activePoint.height}}},o.prototype.rotateLineArrowObj=function(e){if(!t.isNullOrUndefined(e.pointColl)){var o=this.parent.img,i=o.destWidth,r=o.destHeight,a=o.destLeft,n=o.destTop;if(e.pointColl.length>0){for(s=0;s<e.pointColl.length;s++)e.pointColl[s].y=n+r*e.pointColl[s].ratioX,e.pointColl[s].x=a+i-i*e.pointColl[s].ratioY;for(var s=0;s<e.pointColl.length;s++)e.pointColl[s].ratioX=(e.pointColl[s].x-a)/i,e.pointColl[s].ratioY=(e.pointColl[s].y-n)/r;var l=void 0;l=t.isNullOrUndefined(e.pointColl[e.pointColl.length-2])?{x:0,y:0}:{x:e.pointColl[e.pointColl.length-2].x,y:e.pointColl[e.pointColl.length-2].y};var p=e.pointColl[e.pointColl.length-1].x-l.x,h=e.pointColl[e.pointColl.length-1].y-l.y;e.activePoint.startX=e.pointColl[0].x,e.activePoint.startY=e.pointColl[0].y,e.activePoint.endX=e.pointColl[e.pointColl.length-1].x+p/2,e.activePoint.endY=e.pointColl[e.pointColl.length-1].y+h/2,e=this.updateWidthHeight(e)}}},o.prototype.flipLineArrowObj=function(e,o){if(o=o.toLowerCase(),!t.isNullOrUndefined(e.pointColl)&&("horizontal"===o?this.lineArrowHorizontalFlip(e):"vertical"===o?this.lineArrowVerticalFlip(e):(this.lineArrowHorizontalFlip(e),e.shapeFlip="",this.lineArrowVerticalFlip(e)),e.activePoint.startX=e.pointColl[0].x,e.activePoint.startY=e.pointColl[0].y,e.activePoint.endX=e.pointColl[e.pointColl.length-1].x,e.activePoint.endY=e.pointColl[e.pointColl.length-1].y,e.activePoint.startX>e.activePoint.endX)){var i=e.activePoint.startX;e.activePoint.startX=e.activePoint.endX,e.activePoint.endX=i,i=e.activePoint.startY,e.activePoint.startY=e.activePoint.endY,e.activePoint.endY=i}},o.prototype.lineArrowHorizontalFlip=function(e){var t=this.parent,o=t.img,i=o.destWidth,r=o.destHeight,a=o.destLeft,n=o.destTop;if(e.shapeFlip!==t.transform.currFlipState){for(var s=0,l=e.pointColl.length;s<l;s++){var p=e.pointColl[s];p.x<=a+i/2?p.x=a+i-(p.x-a):p.x>=a+i/2&&(p.x=a+(a+i-p.x)),p.ratioX=(p.x-a)/i,p.ratioY=(p.y-n)/r}if("arrow"===e.shape){var h=e.start;e.start=e.end,e.end=h}e.shapeFlip=t.transform.currFlipState}},o.prototype.lineArrowVerticalFlip=function(e){var t=this.parent,o=t.img,i=o.destWidth,r=o.destHeight,a=o.destLeft,n=o.destTop;if(e.shapeFlip!==t.transform.currFlipState){for(var s=0,l=e.pointColl.length;s<l;s++){var p=e.pointColl[s];p.y<=n+r/2?p.y=n+r-(p.y-n):p.y>=n+r/2&&(p.y=n+(n+r-p.y)),p.ratioX=(p.x-a)/i,p.ratioY=(p.y-n)/r}e.shapeFlip=t.transform.currFlipState}},o.prototype.getRotDegOfShape=function(e){var t;return(t=0===e.shapeDegree?this.parent.transform.degree:this.parent.transform.degree-e.shapeDegree)<0&&(t=360+t),t},o.prototype.renderTextArea=function(e,t,o){var i=this.parent,r=this.getRotDegOfShape(i.activeObj);this.transformTextArea(),i.notify("toolbar",{prop:"destroy-qa-toolbar",onPropertyChange:!1});var a=i.element.querySelector("#"+i.element.id+"_zOrderBtn"),n=i.element.querySelector("#"+i.element.id+"_duplicate"),s=i.element.querySelector("#"+i.element.id+"_remove"),l=i.element.querySelector("#"+i.element.id+"_editText");a&&a.classList.add("e-disabled"),n&&n.classList.add("e-disabled"),s&&s.classList.add("e-disabled"),l&&l.classList.add("e-disabled"),i.textArea.style.display="block",i.textArea.style.left=e+"px",i.textArea.style.top=t+"px",i.textArea.style.fontFamily=o.textSettings.fontFamily,i.textArea.style.fontSize=o.textSettings.fontSize+"px",i.textArea.style.color=o.strokeSettings.strokeColor,i.textArea.style.fontWeight=o.textSettings.bold?"bold":"normal",i.textArea.style.fontStyle=o.textSettings.italic?"italic":"normal",i.textArea.style.border="2px solid "+i.themeColl[i.theme].primaryColor,i.textArea.value=o.keyHistory,i.textArea.style.overflow="hidden",i.textArea.style.width="auto",i.textArea.style.height="auto",i.textArea.focus();i.transform.zoomFactor;var p=o.activePoint,h=p.width,d=p.height;r%90==0&&r%180!=0&&0!==r?(i.textArea.style.width=d+"px",i.textArea.style.height=h+"px"):(i.textArea.style.width=h+"px",i.textArea.style.height=d+"px"),this.setTextBoxWidth();var c={flipColl:null};if(i.notify("transform",{prop:"getFlipColl",onPropertyChange:!1,value:{obj:c}}),c.flipColl.length<=1&&this.setTextBoxHeight(),parseFloat(i.textArea.style.maxHeight)<i.activeObj.textSettings.fontSize&&(i.textArea.style.maxHeight=i.activeObj.textSettings.fontSize+"px"),r%90==0&&r%180!=0?parseFloat(i.textArea.style.left)+parseFloat(i.textArea.style.width)>i.img.destTop+i.img.destHeight&&this.alignTextAreaIntoCanvas():parseFloat(i.textArea.style.left)+parseFloat(i.textArea.style.width)>i.img.destLeft+i.img.destWidth&&this.alignTextAreaIntoCanvas(),0!==o.rotatedAngle){var u=parseFloat(i.textArea.style.left),v=parseFloat(i.textArea.style.top);if(o.flipObjColl.length>0){var g={panRegion:""},f=i.lowerCanvas,C=f.clientWidth,b=f.clientHeight,m={x:0,y:0};i.notify("crop",{prop:"getCurrFlipState",onPropertyChange:!1,value:{panObj:g}}),""!==g.panRegion&&("horizontal"===g.panRegion?(m.x=C-C/2,u=m.x-u+m.x):"vertical"===g.panRegion?(m.y=b-b/2,v=m.y-v+m.y):(u=(m={x:C-C/2,y:b-b/2}).x-u+m.x,v=m.y-v+m.y))}var y=u+parseFloat(i.textArea.style.width),P=v+parseFloat(i.textArea.style.height),j=parseFloat(i.textArea.style.width),x=parseFloat(i.textArea.style.height),w={x:y-j/2,y:P-x/2},O=Math.cos(o.rotatedAngle),S=Math.sin(o.rotatedAngle),T={x:O*(y-w.x)-S*(P-w.y)+w.x,y:S*(y-w.x)+O*(P-w.y)+w.y};if(T.x>i.img.destLeft&&T.x<i.img.destLeft+i.img.destWidth&&T.y>i.img.destTop&&T.y+parseFloat(i.textArea.style.fontSize)<i.img.destTop+i.img.destHeight)i.textArea.style.width=i.textArea.style.width;else for(var F=0,k=parseFloat(i.textArea.style.width);;)if(F++,j-=1,y=u+j,w={x:y-j/2,y:P-x/2},(T={x:O*(y-w.x)-S*(P-w.y)+w.x,y:S*(y-w.x)+O*(P-w.y)+w.y}).x>i.img.destLeft&&T.x<i.img.destLeft+i.img.destWidth&&T.y>i.img.destTop&&T.y+parseFloat(i.textArea.style.fontSize)<i.img.destTop+i.img.destHeight||F===k){i.textArea.style.width=j+"px";break}}i.notify("selection",{prop:"clearUpperCanvas",onPropertyChange:!1})},o.prototype.setTextBoxWidth=function(e){var o=this.parent;if(0!==o.activeObj.rotatedAngle)return o.textArea.style.whiteSpace="nowrap",o.textArea.style.textOverflow="ellipsis",void(o.textArea.style.display="inline-block");o.textArea.style.whiteSpace="",o.textArea.style.textOverflow="","inline-block"===o.textArea.style.display&&(o.textArea.style.display="block");var i=this.getMaxText(!0);"block"===o.textArea.style.display||"inline-block"===o.textArea.style.display?this.updateFontStyles(!0):this.updateFontStyles();var r=this.upperContext.measureText(i).width+parseFloat(o.textArea.style.fontSize)/2,a=e?this.upperContext.measureText(String.fromCharCode(e.which)).width:0,n=t.extend({},o.activeObj,{},!0),s="",l=this.getRotDegOfShape(n);if(s=n.shapeFlip!==o.transform.currFlipState?"":o.transform.currFlipState,e&&parseFloat(o.textArea.style.width)<r+a||t.isNullOrUndefined(e))if(0===l)"horizontal"===s.toLowerCase()?parseFloat(o.textArea.style.left)-o.img.destLeft-r-a>0&&(o.textArea.style.width=r+a+"px"):o.img.destWidth-(parseFloat(o.textArea.style.left)-o.img.destLeft)>r+a&&(o.textArea.style.width=r+a+"px");else if(90===l)"vertical"===s.toLowerCase()?parseFloat(o.textArea.style.top)-o.img.destTop-r-a>0&&(o.textArea.style.width=r+a+"px"):o.img.destHeight-(parseFloat(o.textArea.style.top)-o.img.destTop)>r+a&&(o.textArea.style.width=r+a+"px");else if(180===l){var p=parseFloat(o.textArea.style.left),h=o.img.destLeft;"horizontal"===s.toLowerCase()?o.img.destWidth-(p-h)>r+a&&(o.textArea.style.width=r+a+"px"):p-h-r-a>0&&(o.textArea.style.width=r+a+"px")}else if(270===l){var d=parseFloat(o.textArea.style.top),c=o.img.destTop;"vertical"===s.toLowerCase()?o.img.destHeight-(d-c)>r+a&&(o.textArea.style.width=r+a+"px"):d-c-r-a>0&&(o.textArea.style.width=r+a+"px")}},o.prototype.setTextBoxHeight=function(){var e,o=this.parent,i=t.extend({},o.activeObj,{},!0),r="",a=this.getRotDegOfShape(i);switch(r=i.textFlip===o.transform.currFlipState?"":""===i.textFlip?o.transform.currFlipState:i.textFlip,a){case 0:"vertical"===r.toLowerCase()?o.textArea.style.maxHeight=o.img.destHeight-(o.img.destHeight-parseFloat(o.textArea.style.top))+"px":(e=parseFloat(o.textArea.style.top)-o.img.destTop,o.textArea.style.maxHeight=o.img.destHeight-e+"px");break;case 90:"horizontal"===r.toLowerCase()?o.textArea.style.maxHeight=o.img.destWidth-(parseFloat(o.textArea.style.left)-o.img.destLeft)+"px":o.textArea.style.maxHeight=parseFloat(o.textArea.style.left)-o.img.destLeft+"px";break;case 180:"vertical"===r.toLowerCase()?(e=parseFloat(o.textArea.style.top)-o.img.destTop,o.textArea.style.maxHeight=o.img.destHeight-e+"px"):o.textArea.style.maxHeight=parseFloat(o.textArea.style.top)-o.img.destTop+"px";break;case 270:"horizontal"===r.toLowerCase()?o.textArea.style.maxHeight=parseFloat(o.textArea.style.left)-o.img.destLeft+"px":o.textArea.style.maxHeight=o.img.destWidth-(parseFloat(o.textArea.style.left)-o.img.destLeft)+"px"}},o.prototype.updatePathRatio=function(e){for(var t=this.parent,o=0,i=e.pointColl.length;o<i;o++){var r=e.pointColl[o];r.ratioX=(r.x-t.img.destLeft)/t.img.destWidth,r.ratioY=(r.y-t.img.destTop)/t.img.destHeight}},o.prototype.stopPathDrawing=function(e,o){var i=this.parent;if("path"===i.activeObj.shape){var r={shape:null};if(i.notify("selection",{prop:"getCurrentDrawingShape",value:{obj:r}}),"path"===r.shape){var a=t.extend({},i.cropObj,{},!0),n={currObj:{}};i.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:n}});var s=n.currObj;s.objColl=t.extend([],i.objColl,[],!0),s.pointColl=t.extend([],i.pointColl,[],!0),s.afterCropActions=t.extend([],i.afterCropActions,[],!0);var l={selPointColl:null};if(i.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:l}}),s.selPointColl=t.extend([],l.selPointColl,[],!0),i.notify("selection",{prop:"setCurrentDrawingShape",value:{value:""}}),i.currObjType.isDragging=!1,e&&"touchstart"!==e.type&&t.isNullOrUndefined(o)&&i.activeObj.pointColl.pop(),this.updatePathRatio(i.activeObj),t.isNullOrUndefined(i.activeObj.imageRatio)&&i.notify("shape",{prop:"updImgRatioForActObj",onPropertyChange:!1}),i.objColl.push(i.activeObj),i.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"shapeTransform",previousObj:s,previousObjColl:s.objColl,previousPointColl:s.pointColl,previousSelPointColl:s.selPointColl,previousCropObj:a,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),i.objColl.pop(),e&&(i.notify("selection",{prop:"mouseUpEventHandler",value:{e:e}}),this.lowerContext.clearRect(0,0,i.lowerCanvas.width,i.lowerCanvas.height),i.notify("draw",{prop:"redrawImgWithObj",onPropertyChange:!1})),i.notify("draw",{prop:"setNewPath",value:{bool:!0}}),i.objColl[i.objColl.length-1]){var p=i.drawingShape;i.notify("selection",{prop:"setCurrentDrawingShape",value:{value:""}}),i.selectShape(i.objColl[i.objColl.length-1].currIndex),i.notify("selection",{prop:"setCurrentDrawingShape",value:{value:"path"}}),i.drawingShape=p}i.notify("toolbar",{prop:"renderQAT",onPropertyChange:!1,value:{isPenEdit:null}});var h={shapeSettingsObj:{}};i.notify("selection",{prop:"updatePrevShapeSettings",onPropertyChange:!1,value:{obj:h}});var d=h.shapeSettingsObj,c={cancel:!1,action:"draw-end",previousShapeSettings:d},u={cancel:!1,action:"move",previousShapeSettings:d};i.notify("selection",{prop:"triggerShapeChange",onPropertyChange:!1,value:{shapeResizingArgs:c,shapeMovingArgs:u,type:"mouse-up"}}),i.notify("undo-redo",{prop:"updateUndoRedoStack",onPropertyChange:!1})}}},o.prototype.findTextTarget=function(e){var o=this.parent;if("text"!==o.activeObj.shape){if("path"===o.activeObj.shape)return void this.stopPathDrawing(e,null);if("dblclick"!==e.type)return;var i=t.extend({},o.activeObj,{},!0),r=t.extend([],o.objColl,[],!0),a={bool:null};if(o.notify("selection",{prop:"findTargetObj",onPropertyChange:!1,value:{x:e.clientX,y:e.clientY,isCrop:!1,obj:a}}),o.objColl=r,!a.bool||"text"!==o.activeObj.shape)return void(o.activeObj=t.extend({},i,{},!0))}var n,s;if("dblclick"===e.type?(n=e.clientX,s=e.clientY):"touchstart"===e.type&&(n=e.touches[0].clientX,s=e.touches[0].clientY,o.notify("selection",{prop:"setTouchEndPoint",onPropertyChange:!1,value:{x:e.touches[0].clientX,y:e.touches[0].clientY}})),o.notify("toolbar",{prop:"setPreventZoomBtn",onPropertyChange:!1,value:{isPrevent:!0}}),o.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"text",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}}),o.notify("toolbar",{prop:"setPreventZoomBtn",onPropertyChange:!1,value:{isPrevent:!1}}),o.notify("toolbar",{prop:"update-toolbar-items",onPropertyChange:!1}),t.isNullOrUndefined(n)||t.isNullOrUndefined(s))if("block"!==o.textArea.style.display&&"inline-block"!==o.textArea.style.display||""===this.selectedText()||"mousedown"!==e.type)"none"===o.textArea.style.display&&(o.textArea.style.display="block");else{d=o.textArea.value;o.textArea.value+="a",o.textArea.value=d}else{var l=o.lowerCanvas.getBoundingClientRect();n-=l.left,s-=l.top;var p="",h=this.getRotDegOfShape(o.activeObj);p=""===o.activeObj.textFlip?o.activeObj.textFlip===o.transform.currFlipState?"":o.transform.currFlipState:o.activeObj.textFlip===o.transform.currFlipState?"":""===o.transform.currFlipState?o.activeObj.textFlip:o.transform.currFlipState;var d=void 0;if("none"===o.textArea.style.display){d=t.extend({},o.activeObj,{},!0);for(var c=0;c<o.objColl.length;c++)JSON.stringify(o.activeObj)===JSON.stringify(o.objColl[c])&&o.objColl.splice(c,1);this.refreshActiveObj(),this.upperContext.clearRect(0,0,o.upperCanvas.width,o.upperCanvas.height),this.lowerContext.clearRect(0,0,o.upperCanvas.width,o.upperCanvas.height),o.notify("draw",{prop:"redrawImgWithObj",onPropertyChange:!1}),o.notify("draw",{prop:"redrawDownScale"}),o.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.lowerContext}}),o.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.upperContext}}),(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.activeObj=d,this.updateFontStyles();var u=t.extend({},o.activeObj,{},!0),v=u.topLeftCircle.radius,g=u.activePoint,f=g.startX,C=g.startY,b=g.endX,m=g.endY,y={x:f+g.width/2,y:C+g.height/2},P=Math.cos(u.rotatedAngle),j=Math.sin(u.rotatedAngle),x={x:P*(f-y.x)-j*(C-y.y)+y.x,y:j*(f-y.x)+P*(C-y.y)+y.y},w={x:P*(b-y.x)-j*(C-y.y)+y.x,y:j*(b-y.x)+P*(C-y.y)+y.y},O={x:P*(f-y.x)-j*(m-y.y)+y.x,y:j*(f-y.x)+P*(m-y.y)+y.y},S={x:P*(b-y.x)-j*(m-y.y)+y.x,y:j*(b-y.x)+P*(m-y.y)+y.y},a={position:null,x:n,y:s,x1:x.x,y1:x.y,x2:w.x,y2:w.y,x3:O.x,y3:O.y,x4:S.x,y4:S.y};if(o.notify("draw",{prop:"checkPointPosition",onPropertyChange:!1,value:{obj:a}}),0!==u.rotatedAngle&&("inside"===a.position||"on"===a.position)||0===u.rotatedAngle&&n>=u.activePoint.startX-2*v&&n<=u.activePoint.endX+2*v&&s>=u.activePoint.startY-2*v&&s<=u.activePoint.endY+2*v){if(this.upperContext.clearRect(0,0,o.upperCanvas.width,o.upperCanvas.height),4===u.flipObjColl.length&&(u.flipObjColl=[],p="",u.shapeFlip=""),""===p&&u.flipObjColl.length>1&&(p=u.flipObjColl[u.flipObjColl.length-1]),u.flipObjColl.length<=1)n=(T=this.setTextBoxPos(u,h,p,n,s)).x,s=T.y;else{var T=this.setTextBoxPoints(u,h,p,n,s);n=T.x,s=T.y}if(0!==o.activeObj.rotatedAngle){var F=this.getTextBoxPosition(o.activeObj);n=F.x,s=F.y,n=(F=this.setFlipState(n,s,o.activeObj)).x,s=F.y}this.renderTextArea(n,s,u)}else this.applyActObj()}}},o.prototype.getTextBoxPosition=function(e,t){var o={x:0,y:0},i=e.activePoint,r=i.startX,a=i.startY,n=i.endX,s=i.endY,l={x:r+i.width/2,y:a+i.height/2},p=Math.cos(e.rotatedAngle),h=Math.sin(e.rotatedAngle),d={x:p*(r-l.x)-h*(a-l.y)+l.x,y:h*(r-l.x)+p*(a-l.y)+l.y},c={x:p*(n-l.x)-h*(a-l.y)+l.x,y:h*(n-l.x)+p*(a-l.y)+l.y},u={x:p*(r-l.x)-h*(s-l.y)+l.x,y:h*(r-l.x)+p*(s-l.y)+l.y},v={x:p*(n-l.x)-h*(s-l.y)+l.x,y:h*(n-l.x)+p*(s-l.y)+l.y},g=this.getRotDegOfShape(e);return 0===g||360===g?o={x:d.x,y:d.y}:90===g||-270===g?o={x:c.x,y:c.y}:180===g||-180===g?o={x:v.x,y:v.y}:270!==g&&-90!==g||(o={x:u.x,y:u.y}),t&&(t.x=o.x,t.y=o.y),o},o.prototype.setFlipState=function(e,t,o,i){var r=this.parent,a={panRegion:""},n=r.lowerCanvas,s=n.clientWidth,l=n.clientHeight,p={x:0,y:0};return r.notify("crop",{prop:"getCurrFlipState",onPropertyChange:!1,value:{panObj:a}}),""!==a.panRegion&&("horizontal"===a.panRegion?(p.x=s-s/2,e=p.x-e+p.x):"vertical"===a.panRegion?(p.y=l-l/2,t=p.y-t+p.y):(e=(p={x:s-s/2,y:l-l/2}).x-e+p.x,t=p.y-t+p.y)),i&&(i.x=e,i.y=t),{x:e,y:t}},o.prototype.fileChanged=function(e){var t=e.target.files[0],o=t.name&&t.name.split(".")[1].toLowerCase();if(o&&-1===["jpg","jpeg","png","svg"].indexOf(o))return void this.refreshActiveObj();var i=window.URL.createObjectURL(e.target.files[0]);this.onLoadImgShape(null,null,null,null,i.toString(),!0),document.getElementById(this.parent.element.id+"_fileUpload").value=""},o.prototype.onLoadImgShape=function(e,t,o,i,r,a,n,s,l,p){var h=this,d=this.parent;"string"==typeof r?this.shapeImg.src=r:(d.inMemoryCanvas.width=r.width,d.inMemoryCanvas.height=r.height,d.inMemoryCanvas.getContext("2d").putImageData(r,0,0),this.shapeImg.src=d.inMemoryCanvas.toDataURL()),this.prevObjColl(),d.activeObj.shape="image",this.initShapeProps(),this.shapeImg.onload=function(){h.upperContext.drawImage(h.shapeImg,0,0,h.shapeImg.width,h.shapeImg.height),h.updateImgCanvas(a,e,t,o,i,n,s,l,p)}},o.prototype.updateImgCanvas=function(e,t,o,i,r,a,n,s,l){var p=this.parent;p.activeObj.imageElement=this.shapeImg,p.activeObj.imageCanvas=p.createElement("canvas");var h={width:0,height:0};if(p.notify("transform",{prop:"calcMaxDimension",onPropertyChange:!1,value:{width:this.shapeImg.width,height:this.shapeImg.height,obj:h,isImgShape:null}}),i&&r)if(n){var d={ratio:null};p.notify("selection",{prop:"findImageRatio",onPropertyChange:!1,value:{width:this.shapeImg.width,height:this.shapeImg.height,obj:d}}),h=this.resizeImage(i,d.ratio)}else h={width:i,height:r};if(this.updateObj(h,t,o),p.notify("draw",{prop:"downScaleImgCanvas",onPropertyChange:!1,value:{ctx:p.activeObj.imageCanvas.getContext("2d"),isImgAnnotation:!0,isHFlip:null,isVFlip:null}}),p.notify("transform",{prop:"calcMaxDimension",onPropertyChange:!1,value:{width:this.shapeImg.width,height:this.shapeImg.height,obj:h,isImgShape:!0}}),i&&r)if(n){var c={ratio:null};p.notify("selection",{prop:"findImageRatio",onPropertyChange:!1,value:{width:this.shapeImg.width,height:this.shapeImg.height,obj:c}}),h=this.resizeImage(i,c.ratio)}else h={width:i,height:r};null!==s&&void 0!==s&&(p.activeObj.opacity=s),this.updateObj(h,t,o),p.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate"}}),this.shapeImg=null,a&&(p.activeObj.rotatedAngle=a*(Math.PI/180),p.notify("selection",{prop:"updPtCollForShpRot",onPropertyChange:!1,value:{obj:p.activeObj}}));var u={shapeSettingsObj:{}};p.notify("selection",{prop:"updatePrevShapeSettings",onPropertyChange:!1,value:{obj:u}});var v=u.shapeSettingsObj,g={cancel:!1,action:"insert",previousShapeSettings:v,currentShapeSettings:v};p.trigger("shapeChanging",g),e=e||l,this.drawShapeImageEvent(g,e),p.isPublicMethod&&!l?p.notify("undo-redo",{prop:"updateUndoRedo",onPropertyChange:!1}):p.isPublicMethod||p.notify("undo-redo",{prop:"updateUndoRedoStack",onPropertyChange:!1}),p.isPublicMethod=!1},o.prototype.updateObj=function(e,t,o){var i=this.parent;i.activeObj.activePoint.width=e.width,i.activeObj.activePoint.height=e.height,i.activeObj.activePoint.startX=t||i.lowerCanvas.width/2-e.width/2,i.activeObj.activePoint.startY=o||i.lowerCanvas.height/2-e.height/2,i.activeObj.activePoint.endX=i.activeObj.activePoint.startX+e.width,i.activeObj.activePoint.endY=i.activeObj.activePoint.startY+e.height},o.prototype.resizeImage=function(e,t){var o=t.split(":"),i=parseInt(o[0],10),r=parseInt(o[1],10);return{width:e,height:Math.round(e*r/i)}},o.prototype.setTextBoxPos=function(e,t,o,i,r){var a={x:i,y:r},n=e.activePoint,s=n.startX,l=n.startY,p=n.endX,h=n.endY;switch(o=o.toLowerCase(),t){case 0:"horizontal"===o?(a.x=p,a.y=l):"vertical"===o?(a.x=s,a.y=h):(a.x=s,a.y=l);break;case 90:"horizontal"===o?(a.x=s,a.y=l):"vertical"===o?(a.x=p,a.y=h):(a.x=p,a.y=l);break;case 180:"horizontal"===o?(a.x=s,a.y=h):"vertical"===o?(a.x=p,a.y=l):(a.x=p,a.y=h);break;case 270:"horizontal"===o?(a.x=p,a.y=h):"vertical"===o?(a.x=s,a.y=l):(a.x=s,a.y=h)}return a},o.prototype.setTextBoxPoints=function(e,t,o,i,r){var a={x:i,y:r},n=e.activePoint,s=n.startX,l=n.startY,p=n.endX,h=n.endY;switch(o=o.toLowerCase(),t){case 0:e.flipObjColl[0]&&"horizontal"===e.flipObjColl[0].toLowerCase()?"horizontal"===o?(a.x=s,a.y=l):"vertical"===o&&(a.x=p,a.y=h):"horizontal"===o?(a.x=p,a.y=h):"vertical"===o&&(a.x=p,a.y=l);break;case 90:e.flipObjColl[0]&&"horizontal"===e.flipObjColl[0].toLowerCase()?"horizontal"===o?(a.x=p,a.y=h):"vertical"===o&&(a.x=s,a.y=h):"horizontal"===o?(a.x=s,a.y=h):"vertical"===o&&(a.x=s,a.y=l);break;case 180:e.flipObjColl[0]&&"horizontal"===e.flipObjColl[0].toLowerCase()?"horizontal"===o?(a.x=s,a.y=l):"vertical"===o&&(a.x=s,a.y=l):"horizontal"===o?(a.x=s,a.y=l):"vertical"===o&&(a.x=s,a.y=h);break;case 270:e.flipObjColl[0]&&"horizontal"===e.flipObjColl[0].toLowerCase()?"horizontal"===o?(a.x=s,a.y=l):"vertical"===o&&(a.x=p,a.y=l):"horizontal"===o?(a.x=p,a.y=l):"vertical"===o&&(a.x=p,a.y=h)}return a},o.prototype.selectedText=function(){var e=this.parent,t=e.textArea.selectionStart,o=e.textArea.selectionEnd;return e.textArea.value.substring(t,o)},o.prototype.panObjColl=function(e,t,o){var i=this.parent;if(i.objColl.length>0){for(var r=0,a=i.objColl.length;r<a;r++){var n=i.objColl[r];if(""===o){if(n.activePoint.startX+=e,n.activePoint.endX+=e,n.rotationCirclePointColl&&(n.rotationCirclePointColl.x+=e),"path"===n.shape)for(var s=0,l=n.pointColl.length;s<l;s++)n.pointColl[s].x+=e;if(n.activePoint.startY+=t,n.activePoint.endY+=t,n.rotationCirclePointColl&&(n.rotationCirclePointColl.y+=t),"path"===n.shape)for(s=0;s<n.pointColl.length;s++)n.pointColl[s].y+=t}if(n=this.updateWidthHeight(n),i.notify("draw",{prop:"updateActiveObject",onPropertyChange:!1,value:{actPoint:n.activePoint,obj:n}}),"line"===n.shape||"arrow"===n.shape){n.pointColl=this.getLinePoints(n.activePoint.startX,n.activePoint.startY,n.activePoint.endX,n.activePoint.endY);for(var p=0,h=n.pointColl.length;p<h;p++)n.pointColl[p].ratioX=(n.pointColl[p].x-i.img.destLeft)/i.img.destWidth,n.pointColl[p].ratioY=(n.pointColl[p].y-i.img.destTop)/i.img.destHeight}this.refreshActiveObj()}var d=this.lowerContext.filter;this.lowerContext.filter="none",this.iterateObjColl(),this.lowerContext.filter=d,this.refreshActiveObj(),i.notify("draw",{prop:"applyFrame",value:{ctx:this.lowerContext,frame:i.frameObj.type,preventImg:!0}})}},o.prototype.updateFontStyles=function(e){var t=this.parent;this.upperContext.strokeStyle=t.activeObj.strokeSettings.strokeColor,this.upperContext.fillStyle=t.activeObj.strokeSettings.strokeColor;var o="";t.activeObj.textSettings.bold&&(o="bold "),t.activeObj.textSettings.italic&&(o="italic "),t.activeObj.textSettings.bold&&t.activeObj.textSettings.italic&&(o="italic bold ");var i=e?parseFloat(t.textArea.style.fontSize):t.activeObj.textSettings.fontSize,r="block"===t.textArea.style.display||"inline-block"===t.textArea.style.display?t.textArea.style.fontFamily:t.activeObj.textSettings.fontFamily;this.upperContext.font=o+i+"px "+r},o.prototype.applyFontStyle=function(e){var o=this.parent,i={shapeSettingsObj:{}};o.notify("selection",{prop:"updatePrevShapeSettings",onPropertyChange:!1,value:{obj:i}});var r=i.shapeSettingsObj;this.pushActItemIntoObj();var a=t.extend([],o.objColl,[],!0);switch(o.objColl.pop(),"none"===o.textArea.style.display?this.updateFontRatio(o.activeObj):this.updateFontRatio(o.activeObj,!0),e){case"default":this.updateFontStyle(e,a,"normal","normal");break;case"bold":this.updateFontStyle(e,a,"bold","normal");break;case"italic":this.updateFontStyle(e,a,"normal","italic");break;case"bolditalic":this.updateFontStyle(e,a,"bold","italic")}var n={action:"font-style",currentShapeSettings:t.extend({},r,{},!0)};n.currentShapeSettings.fontStyle=[e],o.trigger("shapeChange",n)},o.prototype.updateFontStyle=function(e,t,o,i){var r=this.parent,a=r.textArea.style;if("block"===a.display||"inline-block"===a.display){"normal"===a.fontWeight&&"bold"===o?a.fontWeight="bold":"bold"===a.fontWeight&&"bold"===o&&(a.fontWeight="normal"),"normal"===a.fontStyle&&"italic"===i?a.fontStyle="italic":"italic"===a.fontStyle&&"italic"===i&&(a.fontStyle="normal");var n="normal"===a.fontWeight&&"normal"===a.fontStyle?"default":"bold"===a.fontWeight&&"normal"===a.fontStyle?"bold":"normal"===a.fontWeight&&"italic"===a.fontStyle?"italic":"bolditalic",s=this.getTextAreaWidth(n);a.width=s+"px",this.updateObjColl(e,t)}else this.textSettings.bold=r.activeObj.textSettings.bold="normal"!==o,this.textSettings.italic=r.activeObj.textSettings.italic="normal"!==i,0===r.activeObj.activePoint.width&&0===r.activeObj.activePoint.height||this.redrawText(),r.notify("undo-redo",{prop:"updateUrObj",onPropertyChange:!1,value:{objColl:t}})},o.prototype.updateArrowRatio=function(e){var t={arrowDimension:null};this.parent.notify("draw",{prop:"getArrowDimension",onPropertyChange:!1,value:{obj:t}});var o;o=Math.abs(e.activePoint.width)>Math.abs(e.activePoint.height)?Math.abs(e.activePoint.width):Math.abs(e.activePoint.height);for(var i,r=0,a=["bar","arrow","arrowSolid","circle","square"];r<a.length;r++){i=a[r];var n=o/t.arrowDimension[i].width,s=o/t.arrowDimension[i].height;t.arrowDimension[i].ratioX=n,t.arrowDimension[i].ratioY=s}},o.prototype.updateArrowSize=function(e){var t={arrowDimension:null};this.parent.notify("draw",{prop:"getArrowDimension",onPropertyChange:!1,value:{obj:t}});var o;o=Math.abs(e.activePoint.width)>Math.abs(e.activePoint.height)?Math.abs(e.activePoint.width):Math.abs(e.activePoint.height);for(var i,r=0,a=["bar","arrow","arrowSolid","circle","square"];r<a.length;r++){i=a[r];var n=t.arrowDimension[i].ratioX,s=t.arrowDimension[i].ratioY;t.arrowDimension[i].width=o/n,t.arrowDimension[i].height=o/s}},o.prototype.updateFontRatio=function(e,o){var i=this.parent,r=this.getMaxText(o),a=this.upperContext.measureText(r).width+.5*i.activeObj.textSettings.fontSize,n=i.activeObj.textSettings.fontSize+.25*i.activeObj.textSettings.fontSize,s=this.getRotDegOfShape(e);t.isNullOrUndefined(o)?0===s||180===Math.abs(s)?e.textSettings.fontRatio=a/e.textSettings.fontSize:e.textSettings.fontRatio=n/e.textSettings.fontSize:o&&(e.textSettings.fontRatio=a/parseFloat(i.textArea.style.fontSize))},o.prototype.updateFontSize=function(e){var t=this.getRotDegOfShape(e);0===t||180===Math.abs(t)?e.textSettings.fontSize=e.activePoint.width/e.textSettings.fontRatio:e.textSettings.fontSize=e.activePoint.height/e.textSettings.fontRatio},o.prototype.updateObjColl=function(e,o){var i=this.parent,r=t.extend({},i.cropObj,{},!0),a={currObj:{}};i.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:a}});var n=a.currObj;n.objColl=o,n.pointColl=t.extend([],i.pointColl,[],!0),n.afterCropActions=t.extend([],i.afterCropActions,[],!0);var s={selPointColl:null};i.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:s}}),n.selPointColl=t.extend([],s.selPointColl,[],!0);var l=i.activeObj.textSettings.bold,p=i.activeObj.textSettings.italic;switch(e){case"default":i.activeObj.textSettings.bold=!1,i.activeObj.textSettings.italic=!1;break;case"bold":i.activeObj.textSettings.bold=!0,i.activeObj.textSettings.italic=!1;break;case"italic":i.activeObj.textSettings.bold=!1,i.activeObj.textSettings.italic=!0;break;case"bolditalic":i.activeObj.textSettings.bold=!0,i.activeObj.textSettings.italic=!0}i.objColl.push(i.activeObj),i.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"textAreaCustomization",previousObj:n,previousObjColl:n.objColl,previousPointColl:n.pointColl,previousSelPointColl:n.selPointColl,previousCropObj:r,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),i.objColl.pop(),i.activeObj.textSettings.bold=l,i.activeObj.textSettings.italic=p},o.prototype.pushActItemIntoObj=function(){var e=this.parent;if("none"===e.textArea.style.display)0===e.activeObj.activePoint.width&&0===e.activeObj.activePoint.height||e.objColl.push(e.activeObj);else{var o=t.extend({},e.activeObj,{},!0);e.notify("selection",{prop:"setTextBoxStylesToActObj",onPropertyChange:!1}),e.objColl.push(e.activeObj),e.activeObj=o}},o.prototype.clearActObj=function(){var e=this.parent;"none"===e.textArea.style.display&&(this.refreshActiveObj(),this.applyActObj(),this.refreshActiveObj(),e.currObjType.isCustomCrop=!1)},o.prototype.refreshActiveObj=function(){var e=this.parent;e.activeObj={},e.activeObj.activePoint={startX:0,startY:0,endX:0,endY:0,width:0,height:0},e.activeObj.triangle=[],e.activeObj.triangleRatio=[],e.activeObj.order=null,e.activeObj.flipObjColl=[],e.activeObj.strokeSettings=this.strokeSettings,e.activeObj.textSettings=this.textSettings,e.activeObj.rotatedAngle=0,e.activeObj.opacity=1},o.prototype.applyActObj=function(e){var o=this.parent,i=!1;if(void 0!==o.activeObj.shape&&"text"===o.activeObj.shape&&""===o.activeObj.keyHistory)this.refreshActiveObj(),this.upperContext.clearRect(0,0,o.upperCanvas.width,o.upperCanvas.height);else{var r=void 0,a=!1;if(void 0!==o.activeObj.shape&&(r=o.activeObj.shape.split("-")),void 0===r&&o.currObjType.isCustomCrop?a=!0:void 0!==r&&"crop"===r[0]&&(a=!0),o.activeObj.shape&&!a&&"shape"!==o.activeObj.shape){for(l=0;l<o.objColl.length;l++)if(JSON.stringify(o.activeObj)===JSON.stringify(o.objColl[l])){i=!0;break}if(!i){t.isNullOrUndefined(o.activeObj.currIndex)&&(o.activeObj.currIndex=this.getNewShapeId()),t.isNullOrUndefined(o.activeObj.order)&&(o.activeObj.order=this.getNewOrder()),this.updImgRatioForActObj();var n=o.activeObj.currIndex.split("_"),s=o.objColl.splice(0,parseInt(n[1],10)-1);s.push(t.extend({},o.activeObj,{},!0));for(var l=0;l<o.objColl.length;l++)s.push(o.objColl[l]);o.objColl=s,s=[],this.refreshActiveObj(),this.lowerContext.clearRect(0,0,o.lowerCanvas.width,o.lowerCanvas.height),o.notify("draw",{prop:"redrawImgWithObj",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.currObjType.shape="",this.refreshActiveObj(),o.isCircleCrop&&o.notify("crop",{prop:"cropCircle",onPropertyChange:!1,value:{context:this.lowerContext,isSave:null,isFlip:null}}),o.notify("toolbar",{prop:"destroy-qa-toolbar",onPropertyChange:!1}),t.isNullOrUndefined(e)&&(o.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"ok"}}),o.notify("draw",{prop:"setPrevActObj",onPropertyChange:!1,value:{prevActObj:null}}))}}}},o.prototype.getNewShapeId=function(){for(var e=this.parent,t=e.objColl.length+1,o=0;o<e.objColl.length;o++)e.objColl[o].currIndex==="shape_"+t&&(t++,o=-1);return"shape_"+t},o.prototype.getNewOrder=function(){var e=this.parent;this.updateShapeColl();for(var t=e.shapeColl.length+1,o=0;o<e.shapeColl.length;o++)e.shapeColl[o].order===t&&(t++,o=-1);return t},o.prototype.getHighestOrder=function(){var e=this.parent;this.updateShapeColl();for(var t=0,o=0;o<e.shapeColl.length;o++)e.shapeColl[o].order>t&&(t=e.shapeColl[o].order);return t},o.prototype.getLowestOrder=function(){var e=this.parent;this.updateShapeColl();for(var t=1,o=0;o<e.shapeColl.length;o++)e.shapeColl[o].order<t&&(t=e.shapeColl[o].order);return t},o.prototype.alignTextAreaIntoCanvas=function(){var e=this.parent,t=e.textArea.value;e.textArea.value="";for(var o=0,i=t.length;o<i;o++)e.textArea.value+=t[o],e.textArea.style.height="auto",e.textArea.style.height=e.textArea.scrollHeight+"px",this.setTextBoxWidth()},o.prototype.transformTextArea=function(){var e=this.parent;if("text"===e.activeObj.shape){e.textArea.style.transformOrigin="0 0";var t=e.activeObj.rotatedAngle*(180/Math.PI),o="",i=this.getRotDegOfShape(e.activeObj);if(e.activeObj.flipObjColl.length>0)for(var r=0;r<e.activeObj.flipObjColl.length;r++)o+=0!==i&&i%90==0&&180!==i?"horizontal"===e.activeObj.flipObjColl[r].toLowerCase()?"scale(1, -1)":"scale(-1, 1)":"horizontal"===e.activeObj.flipObjColl[r].toLowerCase()?"scale(-1, 1)":"scale(1, -1)",i+=t,"horizontal"===e.activeObj.flipObjColl[r].toLowerCase()?e.textArea.style.transform="rotate("+i+"deg)"+o:"vertical"===e.activeObj.flipObjColl[r].toLowerCase()&&(e.textArea.style.transform="rotate("+i+"deg)"+o);else i+=t,e.textArea.style.transform="rotate("+i+"deg)"}},o.prototype.getTextAreaWidth=function(e){var t=this.parent,o=t.activeObj.textSettings.bold,i=t.activeObj.textSettings.italic;switch(e){case"default":t.activeObj.textSettings.bold=!1,t.activeObj.textSettings.italic=!1;break;case"bold":t.activeObj.textSettings.bold=!0,t.activeObj.textSettings.italic=!1;break;case"italic":t.activeObj.textSettings.bold=!1,t.activeObj.textSettings.italic=!0;break;case"bolditalic":t.activeObj.textSettings.bold=!0,t.activeObj.textSettings.italic=!0}var r="none"!==t.textArea.style.display;this.updateFontStyles(r);var a;return a=r?this.upperContext.measureText(t.textArea.value).width+.5*t.activeObj.textSettings.fontSize:this.upperContext.measureText(t.activeObj.keyHistory).width+.5*t.activeObj.textSettings.fontSize,t.activeObj.textSettings.bold=o,t.activeObj.textSettings.italic=i,a},o.prototype.getObjDetails=function(e){var t=this.parent,o={};switch(o.id=e.currIndex,o.type=t.toPascalCase(e.shape),o.startX=e.activePoint.startX,o.startY=e.activePoint.startY,o.index=e.order,e.shape){case"rectangle":o.width=e.activePoint.width,o.height=e.activePoint.height,o.strokeColor=e.strokeSettings.strokeColor,o.fillColor=e.strokeSettings.fillColor,o.strokeWidth=e.strokeSettings.strokeWidth,o.degree=e.rotatedAngle*(180/Math.PI);break;case"ellipse":o.radius=e.activePoint.width/2,o.strokeColor=e.strokeSettings.strokeColor,o.fillColor=e.strokeSettings.fillColor,o.strokeWidth=e.strokeSettings.strokeWidth,o.radiusX=e.activePoint.width/2,o.radiusY=e.activePoint.height/2,o.degree=e.rotatedAngle*(180/Math.PI);break;case"line":case"arrow":if(o.length=e.activePoint.width,o.strokeColor=e.strokeSettings.strokeColor,o.strokeWidth=e.strokeSettings.strokeWidth,o.endX=e.activePoint.endX,o.endY=e.activePoint.endY,"arrow"===e.shape){var i={type:null};t.notify("selection",{prop:"getArrowType",onPropertyChange:!1,value:{type:e.start,obj:i}}),o.arrowHead=i.type,t.notify("selection",{prop:"getArrowType",onPropertyChange:!1,value:{type:e.end,obj:i}}),o.arrowTail=i.type}break;case"text":o.text=e.keyHistory,o.fontSize=e.textSettings.fontSize,o.fontFamily=e.textSettings.fontFamily,o.color=e.strokeSettings.strokeColor,o.fontStyle=[],e.textSettings.bold&&o.fontStyle.push("bold"),e.textSettings.italic&&o.fontStyle.push("italic"),o.degree=e.rotatedAngle*(180/Math.PI);break;case"path":o.strokeColor=e.strokeSettings.strokeColor,o.strokeWidth=e.strokeSettings.strokeWidth,o.points=e.pointColl;break;case"image":o.imageData=e.imageCanvas.toDataURL(),o.degree=e.rotatedAngle*(180/Math.PI),o.width=e.activePoint.width,o.height=e.activePoint.height,o.opacity=e.opacity}return o},o.prototype.getFreehandDrawDetails=function(o){var i=this.parent,r={};return r.id=i.pointColl[o].id,r.type=e.ShapeType.FreehandDraw,r.points=t.extend([],i.pointColl[o].points),r.strokeColor=i.pointColl[o].strokeColor,r.strokeWidth=i.pointColl[o].strokeWidth,r.index=i.pointColl[o].order,r},o.prototype.getShapeSetting=function(e,o){var i,r=this.parent;if(!r.disabled&&r.isImageLoaded)if("none"!==r.textArea.style.display?r.okBtn(null,!0):this.applyActObj(!0),"shape"===e.split("_")[0]){for(var a,n=0,s=r.objColl.length;n<s;n++)if(r.objColl[n].currIndex===e){a=t.extend({},r.objColl[n],{},!0);break}i=this.getObjDetails(a)}else"pen"===e.split("_")[0]&&(i=this.getFreehandDrawDetails(parseInt(e.split("_")[1],10)-1));o.shapeDetails=i},o.prototype.getShapeSettings=function(e){var t=this.parent,o=[];if(!t.disabled&&t.isImageLoaded){"none"!==t.textArea.style.display?t.okBtn(null,!0):this.applyActObj(!0);for(var i=0,r=t.objColl.length;i<r;i++){a=this.getObjDetails(t.objColl[i]);o.push(a)}for(i=0;i<t.freehandCounter;i++){var a=this.getFreehandDrawDetails(i);o.push(a)}}e.shapeDetailsColl=o},o.prototype.isPointsInRange=function(e,o,i){var r=!1,a=this.parent;!t.isNullOrUndefined(e)&&!t.isNullOrUndefined(o)&&e>=a.img.destLeft&&o>=a.img.destTop&&e<=a.img.destLeft+a.img.destWidth&&o<=a.img.destTop+a.img.destHeight&&(r=!0),i.inRange=r},o.prototype.alignRotateFlipColl=function(e,t,o){return e=this.popForDefaultTransformedState(e),e=this.popForDefaultFlipState(e),0===(e=this.popForDefaultRotateState(e)).length&&t&&(this.parent.transform.degree=0,this.parent.transform.currFlipState=""),o.collection=e,e},o.prototype.popForDefaultTransformedState=function(e){for(var t=0,o=0,i=0,r=0,a=0;a<e.length;a++)90===e[a]||"rotateRight"===e[a]?(o=0,i=0,r=0,4===++t&&(e.pop(),e.pop(),e.pop(),e.pop())):-90===e[a]||"rotateLeft"===e[a]?(t=0,i=0,r=0,4===++o&&(e.pop(),e.pop(),e.pop(),e.pop())):"horizontal"===e[a]||"Horizontal"===e[a]||"horizontalflip"===e[a]?(o=0,t=0,r=0,2===++i&&(e.pop(),e.pop())):"vertical"!==e[a]&&"Vertical"!==e[a]&&"verticalflip"!==e[a]||(i=0,o=0,t=0,2===++r&&(e.pop(),e.pop()));return e},o.prototype.popForDefaultFlipState=function(e){for(var t=0,o=e.length-3;t<o;t++){var i="horizontal"===e[t]||"Horizontal"===e[t]||"horizontalFlip"===e[t],r="vertical"===e[t]||"Vertical"===e[t]||"verticalFlip"===e[t],a="horizontal"===e[t+1]||"Horizontal"===e[t+1]||"horizontalFlip"===e[t+1],n="vertical"===e[t+1]||"Vertical"===e[t+1]||"verticalFlip"===e[t+1],s="horizontal"===e[t+2]||"Horizontal"===e[t+2]||"horizontalFlip"===e[t+2],l="vertical"===e[t+2]||"Vertical"===e[t+2]||"verticalFlip"===e[t+2],p="horizontal"===e[t+3]||"Horizontal"===e[t+3]||"horizontalFlip"===e[t+3];(i&&n&&s&&l||r&&a&&l&&p)&&(e.splice(t,4),t-=4)}return e},o.prototype.popForDefaultRotateState=function(e){for(var t=0;t<e.length-1;t++){var o=e[t],i=e[t+1];90!==o&&"rotateRight"!==o||-90!==i&&"rotateLeft"!==i?-90!==o&&"rotateLeft"!==o||90!==i&&"rotateRight"!==i||(e.splice(t,2),t-=2):(e.splice(t,2),t-=2)}return e},o.prototype.selectShape=function(e,o){var i=this.parent,r=!1;if(!i.disabled&&i.isImageLoaded)if(this.applyActObj(),"shape"===e.split("_")[0]){for(var a,n=0,s=i.objColl.length;n<s;n++)if(i.objColl[n].currIndex===e){a=t.extend({},i.objColl[n],{},!0);break}if(t.isNullOrUndefined(a))r=!1;else{r=!0,i.activeObj=a;l={canvasFilter:null};i.notify("toolbar",{prop:"getCanvasFilter",onPropertyChange:!1,value:{obj:l}}),this.lowerContext.filter=l.canvasFilter,i.notify("selection",{prop:"redrawShape",onPropertyChange:!1,value:{obj:i.activeObj}}),"text"===i.activeObj.shape?i.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"text",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}}):"pen"===i.activeObj.shape?i.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"pen",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}}):i.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"shapes",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}}),i.notify("toolbar",{prop:"update-toolbar-items",onPropertyChange:!1}),i.notify("toolbar",{prop:"renderQAT",onPropertyChange:!1,value:{isPenEdit:null}})}}else if("pen"===e.split("_")[0]){var l={bool:!1};i.notify("selection",{prop:"getFreehandDrawEditing",onPropertyChange:!1,value:{obj:l}}),l.bool&&i.okBtn(null,!0);var p={isIndex:!1};i.notify("freehand-draw",{prop:"isFHDIdx",value:{index:parseInt(e.split("_")[1],10)-1,obj:p}}),p.isIndex?(r=!0,i.notify("freehand-draw",{prop:"selectFhd",value:{id:e}}),i.notify("toolbar",{prop:"renderQAT",onPropertyChange:!1,value:{isPenEdit:!0}}),i.notify("toolbar",{prop:"update-toolbar-items",onPropertyChange:!1})):r=!1}o.isSelected=r},o.prototype.deleteShape=function(e){var t=this.parent;if(!t.disabled&&t.isImageLoaded){if(t.activeObj.currIndex&&t.activeObj.currIndex===e)t.notify("selection",{prop:"deleteItem",onPropertyChange:!1});else if(this.applyActObj(),"shape"===e.split("_")[0]){for(var o=0,i=t.objColl.length;o<i;o++)if(t.objColl[o].currIndex===e){t.objColl.splice(o,1);break}}else"pen"===e.split("_")[0]&&t.notify("freehand-draw",{prop:"handle-freehand-draw",value:{id:e}});var r={canvasFilter:null};t.notify("toolbar",{prop:"getCanvasFilter",onPropertyChange:!1,value:{obj:r}}),this.lowerContext.filter=r.canvasFilter,this.lowerContext.clearRect(0,0,t.lowerCanvas.width,t.lowerCanvas.height),t.notify("draw",{prop:"redrawImgWithObj",onPropertyChange:!1}),t.notify("toolbar",{prop:"refresh-main-toolbar",onPropertyChange:!1})}},o.prototype.getMaxText=function(e,o,i){t.isNullOrUndefined(o)&&(o=e?this.parent.textArea.value:this.parent.activeObj.keyHistory);for(var r,a=o.split("\n"),n=a[0].length,s=a[0],l=1;l<a.length;l++)(r=a[l].length)>n&&(s=a[l],n=r);return i&&(i.maxText=s),s},o.prototype.getLinePoints=function(e,o,i,r){var a,n,s=[];if(e===i){o<r?(a=[e,o],n=[i,r]):(n=[e,o],a=[i,r]);for(var l=this.getSlope(a,n,!0),p=this.getIntercept(a,l),h=a[1];h<=n[1];h++){d=l*h+p;s.push({x:d,y:h})}}else{e<i?(a=[e,o],n=[i,r]):(n=[e,o],a=[i,r]);for(var l=this.getSlope(a,n,!1),p=this.getIntercept(a,l),d=a[0];d<=n[0];d++){h=l*d+p;s.push({x:d,y:h})}}if(Math.floor(e)===Math.floor(i)||s.length<10&&(r-o>10||o-r>10)){s=[];for(var c=Math.min(o,r),u=0;u<Math.abs(Math.floor(r)-Math.floor(o));u++)s.push({x:e,y:c+u});if(s.length>1){b=void 0;b=t.isNullOrUndefined(s[s.length-2])?{x:0,y:0}:s[s.length-2];var v=s[s.length-1].x-b.x,g=s[s.length-1].y-b.y;s.push({x:s[s.length-1].x+v/2,y:s[s.length-1].y+g/2})}}else if(Math.floor(o)===Math.floor(r)||s.length<10&&(i-e>10||e-i>10)){s=[];for(var f=Math.min(e,i),C=0;C<Math.abs(Math.floor(i)-Math.floor(e));C++)s.push({x:f+C,y:o});if(s.length>1){var b=void 0;b=t.isNullOrUndefined(s[s.length-2])?{x:0,y:0}:s[s.length-2];var v=s[s.length-1].x-b.x,g=s[s.length-1].y-b.y;s.push({x:s[s.length-1].x+v/2,y:s[s.length-1].y+g/2})}}return s},o.prototype.getSlope=function(e,t,o){var i;if(o){if(e[1]===t[1])return null;i=(t[0]-e[0])/(t[1]-e[1])}else{if(e[0]===t[0])return null;i=(t[1]-e[1])/(t[0]-e[0])}return i},o.prototype.getIntercept=function(e,t){return null===t?e[0]:e[1]-t*e[0]},o.prototype.setPointCollForShapeRotation=function(e){var t=this.parent,o=e.activePoint,i=o.startX,r=o.startY,a=o.endX,n=o.endY,s={x:i+o.width/2,y:r+o.height/2},l=Math.cos(e.rotatedAngle),p=Math.sin(e.rotatedAngle),h={x:l*(i-s.x)-p*(r-s.y)+s.x,y:p*(i-s.x)+l*(r-s.y)+s.y},d={x:l*(a-s.x)-p*(r-s.y)+s.x,y:p*(a-s.x)+l*(r-s.y)+s.y},c={x:l*(i-s.x)-p*(n-s.y)+s.x,y:p*(i-s.x)+l*(n-s.y)+s.y},u={x:l*(a-s.x)-p*(n-s.y)+s.x,y:p*(a-s.x)+l*(n-s.y)+s.y};e.horTopLinePointColl=this.getLinePoints(h.x,h.y,d.x,d.y),e.horTopLinePointColl=this.getLinePoints(h.x,h.y,d.x,d.y),e.horBottomLinePointColl=this.getLinePoints(c.x,c.y,u.x,u.y),e.verLeftLinePointColl=this.getLinePoints(h.x,h.y,c.x,c.y),e.verRightLinePointColl=this.getLinePoints(d.x,d.y,u.x,u.y),e.verLeftLinePointColl.reverse(),e.verRightLinePointColl.reverse();for(v=0;v<e.horTopLinePointColl.length;v++)e.horTopLinePointColl[v].ratioX=(e.horTopLinePointColl[v].x-this.parent.img.destLeft)/this.parent.img.destWidth,e.horTopLinePointColl[v].ratioY=(e.horTopLinePointColl[v].y-this.parent.img.destTop)/this.parent.img.destHeight;for(v=0;v<e.horBottomLinePointColl.length;v++)e.horBottomLinePointColl[v].ratioX=(e.horBottomLinePointColl[v].x-this.parent.img.destLeft)/this.parent.img.destWidth,e.horBottomLinePointColl[v].ratioY=(e.horBottomLinePointColl[v].y-this.parent.img.destTop)/this.parent.img.destHeight;for(v=0;v<e.verLeftLinePointColl.length;v++)e.verLeftLinePointColl[v].ratioX=(e.verLeftLinePointColl[v].x-this.parent.img.destLeft)/this.parent.img.destWidth,e.verLeftLinePointColl[v].ratioY=(e.verLeftLinePointColl[v].y-this.parent.img.destTop)/this.parent.img.destHeight;for(var v=0;v<e.verRightLinePointColl.length;v++)e.verRightLinePointColl[v].ratioX=(e.verRightLinePointColl[v].x-this.parent.img.destLeft)/this.parent.img.destWidth,e.verRightLinePointColl[v].ratioY=(e.verRightLinePointColl[v].y-this.parent.img.destTop)/this.parent.img.destHeight;if("move"!==t.upperCanvas.style.cursor){var g={rotationCirclePoint:null};t.notify("selection",{prop:"getTransRotationPoint",value:{obj:e,object:g}});var f=g.rotationCirclePoint;f&&(e.rotationCirclePointColl={x:l*(f.x-s.x)-p*(f.y-s.y)+s.x,y:p*(f.x-s.x)+l*(f.y-s.y)+s.y},e.rotationCirclePointColl.ratioX=(e.rotationCirclePointColl.x-t.img.destLeft)/t.img.destWidth,e.rotationCirclePointColl.ratioY=(e.rotationCirclePointColl.y-t.img.destTop)/t.img.destHeight)}},o.prototype.getSquarePointForRotatedShape=function(e,t){var o={startX:0,startY:0,endX:0,endY:0,width:0,height:0},i=e.activePoint,r=i.startX,a=i.startY,n=i.endX,s=i.endY,l={x:r+i.width/2,y:a+i.height/2},p=Math.cos(e.rotatedAngle),h=Math.sin(e.rotatedAngle),d={x:p*(r-l.x)-h*(a-l.y)+l.x,y:h*(r-l.x)+p*(a-l.y)+l.y},c={x:p*(n-l.x)-h*(a-l.y)+l.x,y:h*(n-l.x)+p*(a-l.y)+l.y},u={x:p*(r-l.x)-h*(s-l.y)+l.x,y:h*(r-l.x)+p*(s-l.y)+l.y},v={x:p*(n-l.x)-h*(s-l.y)+l.x,y:h*(n-l.x)+p*(s-l.y)+l.y};return o.startX=d.x,o.startY=d.y,o.endX=d.x,o.endY=d.y,o.startX>c.x&&(o.startX=c.x),o.startX>u.x&&(o.startX=u.x),o.startX>v.x&&(o.startX=v.x),o.startY>c.y&&(o.startY=c.y),o.startY>u.y&&(o.startY=u.y),o.startY>v.y&&(o.startY=v.y),o.endX<c.x&&(o.endX=c.x),o.endX<u.x&&(o.endX=u.x),o.endX<v.x&&(o.endX=v.x),o.endY<c.y&&(o.endY=c.y),o.endY<u.y&&(o.endY=u.y),o.endY<v.y&&(o.endY=v.y),o.width=o.endX-o.startX,o.height=o.endY-o.startY,t&&(t.activePoint=o),o},o.prototype.updateZOrder=function(e,o){var i=this.parent;o=o.toLowerCase();var r=e;if(!t.isNullOrUndefined(r.order)){var a,n,s=this.getHighestOrder();if(this.updateShapeColl(),0!==i.shapeColl.length){for(var l,p=0;p<i.shapeColl.length;p++)l=i.shapeColl[p],r.id&&r.id.indexOf("pen")>-1?l.id&&l.id===r.id&&i.shapeColl.splice(p,1):l.shape&&l.shape.indexOf("crop-")>-1&&i.shapeColl.splice(p,1);switch(o){case"sendtoback":n=r.order,a=r.order,r.order=1;break;case"sendbackward":r.order-=1,a=r.order;break;case"bringtofront":n=r.order,a=s,r.order=a;break;case"bringforward":r.order+=1,a=r.order}this.reArrangeObjColl(a,o,n),r.id&&r.id.indexOf("pen")>-1&&this.reUpdateShapeColl(r)}}},o.prototype.reArrangeObjColl=function(e,t,o){var i,r=this.parent;switch(t){case"sendtoback":for(var a=0,n=r.shapeColl.length;a<n;a++)(i=r.shapeColl[a]).order<o&&i.order<=e&&(i.order+=1,this.reUpdateShapeColl(i));break;case"sendbackward":for(var a=0,n=r.shapeColl.length;a<n;a++)if((i=r.shapeColl[a]).order===e){i.order+=1,this.reUpdateShapeColl(i);break}break;case"bringtofront":for(var a=0,n=r.shapeColl.length;a<n;a++)(i=r.shapeColl[a]).order>o&&i.order<=e&&(i.order-=1,this.reUpdateShapeColl(i));break;case"bringforward":for(var a=0,n=r.shapeColl.length;a<n;a++)if((i=r.shapeColl[a]).order===e){i.order-=1,this.reUpdateShapeColl(i);break}}},o.prototype.updateShapeColl=function(){var e=this.parent,o=!1,i=1,r=t.extend([],e.objColl,[],!0),a=t.extend([],e.pointColl,[],!0);if(e.shapeColl.length>0&&e.shapeColl.length===e.objColl.length+e.pointColl.length){for(h=0;h<e.shapeColl.length;h++){if(e.shapeColl[h].order!==i){o=!1;break}o=!0,i++}if(o){for(h=0;h<e.shapeColl.length;h++)if(e.shapeColl[h].currIndex&&e.shapeColl[h].currIndex.indexOf("shape")>-1){for(n=0;n<r.length;n++)if(e.shapeColl[h].currIndex===r[n].currIndex){e.shapeColl[h]=t.extend({},r[n],{},!0),r.splice(n,1);break}}else if(e.shapeColl[h].id&&e.shapeColl[h].id.indexOf("pen")>-1)for(var n=0;n<a.length;n++)if(e.shapeColl[h].id===a[n].id){e.shapeColl[h]=t.extend([],a[n],[],!0),a.splice(n,1);break}return}}r=t.extend([],e.objColl,[],!0),a=t.extend([],e.pointColl,[],!0),e.shapeColl=[];for(var s,l=1,p=!1;0!==r.length||0!==a.length;){s=p=!1;for(h=0;h<r.length;h++)if(r[h].order===l||!r[h].order&&r[h].shape&&r[h].shape.indexOf("crop-")>-1){e.shapeColl.push(t.extend({},r[h],{},!0)),r[h].shape&&r[h].shape.indexOf("crop-")>-1&&(p=!0),r.splice(h,1),s=!0;break}if(!s)for(var h=0;h<a.length;h++)if(a[h].order===l){e.shapeColl.push(t.extend([],a[h],[],!0)),a.splice(h,1),s=!0;break}p||l++}},o.prototype.reUpdateShapeColl=function(e){var t=this.parent;if(e.id&&e.id.indexOf("pen")>-1){if(t.freehandCounter>0)for(o=0;o<t.freehandCounter;o++)t.pointColl[o].id===e.id&&(t.pointColl[o].order=e.order)}else if(e.currIndex&&e.currIndex.indexOf("shape")>-1)for(var o=0;o<t.objColl.length;o++)t.objColl[o].currIndex===e.currIndex&&(t.objColl[o].order=e.order)},o.prototype.drawAnnotations=function(e,o,i,r,a,n,s){var l=this.parent,p=t.extend({},l.activeObj,{},!0),h=t.extend([],l.objColl,[],!0),d=t.extend([],l.pointColl,[],!0);this.updateShapeColl();var c=t.extend([],l.shapeColl,[],!0),u=!1;this.preventFrameAnnotation||(this.preventFrameAnnotation=u=!0);for(var v=0;v<c.length;v++){var g=c[v].id;if(c[v].order||!c[v].order&&c[v].shape&&c[v].shape.indexOf("crop-")>-1||!c[v].order&&"path"===c[v].shape&&"path"===l.drawingShape){if(c[v].currIndex&&c[v].currIndex.indexOf("shape")>-1){if(l.objColl=[],l.objColl.push(t.extend({},c[v],{},!0)),"iterate"===o){var f=this.lowerContext.filter;this.lowerContext.filter="none",this.iterateObjColl(),this.lowerContext.filter=f}else if("zoom"===o||"pan"===o){for(var C=-1,b=0;b<h.length;b++)if(JSON.stringify(h[b])===JSON.stringify(l.objColl[0])){C=b;break}"zoom"===o?this.zoomObjColl(r):this.panObjColl(a,n,s),C>-1&&(h[C]=t.extend({},l.objColl[0],{},!0))}}else if(c[v].id&&c[v].id.indexOf("pen")>-1)if(l.pointColl=[],l.freehandCounter=0,l.pointColl.push(t.extend({},c[v],{},!0)),l.freehandCounter=l.pointColl.length,"iterate"===i)l.notify("freehand-draw",{prop:"freehandRedraw",onPropertyChange:!1,value:{context:e,points:null}});else if("zoom"===i||"pan"===i){"zoom"===i?l.notify("freehand-draw",{prop:"zoomFHDColl",onPropertyChange:!1,value:{isPreventApply:r}}):l.notify("freehand-draw",{prop:"panFHDColl",onPropertyChange:!1,value:{xDiff:a,yDiff:n,panRegion:s}});for(var m=0;m<d.length;m++)if(d[m].id===l.pointColl[0].id){d[m]=t.extend({},l.pointColl[0],{},!0);break}}}else(c[v].shape||g)&&(c[v].currIndex||g)||c.splice(v,1)}i&&"zoom"===i&&(l.pointColl=[],l.freehandCounter=0,l.notify("freehand-draw",{prop:"zoomFHDColl",onPropertyChange:!1,value:{isPreventApply:r}})),l.objColl=h,l.pointColl=d,l.freehandCounter=l.pointColl.length,u&&this.preventFrameAnnotation&&(l.notify("draw",{prop:"applyFrame",value:{ctx:this.lowerContext,frame:l.frameObj.type,preventImg:!0}}),this.preventFrameAnnotation=!1),l.activeObj=p},o}(),f=function(){function i(e){this.isReverseFlip=!1,this.disablePan=!1,this.isReverseRotate=!1,this.flipColl=[],this.prevZoomValue=1,this.cropDimension={width:0,height:0},this.isPreventSelect=!1,this.preventDownScale=!1,this.resizedImgAngle=null,this.parent=e,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(e){switch(this.initTransformPvtVar(),e.prop){case"flipImage":this.flipImage(e.value.direction);break;case"setDestPointsForFlipState":this.setDestPointsForFlipState();break;case"zoomAction":this.zoomAction(e.value.zoomFactor,e.value.zoomPoint,e.value.isResize);break;case"disableZoomOutBtn":this.disableZoomOutBtn(e.value.isZoomOut);break;case"rotatedFlip":this.rotatedFlip();break;case"drawPannedImage":this.drawPannedImage(e.value.xDiff,e.value.yDiff);break;case"drawPannImage":this.drawPannImage(e.value.point);break;case"performTransformation":this.performTransformation(e.value.text);break;case"updateTransform":this.updateTransform(e.value.text);break;case"rotatePan":this.rotatePan(e.value.isCropSelection,e.value.isDefaultZoom);break;case"resetZoom":this.resetZoom();break;case"pan":this.pan(e.value.value,e.value.x,e.value.y);break;case"zoom":this.zoom(e.value.zoomFactor,e.value.zoomPoint);break;case"setCurrPanRegion":this.setCurrPanRegion(e.value.region,e.value.type,e.value.obj);break;case"rotate":this.rotate(e.value.degree,e.value.obj);break;case"flip":this.flip(e.value.direction);break;case"update":this.update();break;case"calcMaxDimension":this.calcMaxDimension(e.value.width,e.value.height,e.value.obj,e.value.isImgShape);break;case"getPanMove":e.value.obj.panMove=this.panMove;break;case"setPanMove":this.panMove=e.value.point;break;case"getTempPanMove":e.value.obj.tempPanMove=this.tempPanMove;break;case"setTempPanMove":this.tempPanMove=e.value.point;break;case"setReverseFlip":this.isReverseFlip=e.value.isReverseFlip;break;case"setDisablePan":this.disablePan=e.value.bool;break;case"setCurrDestinationPoint":this.currDestPoint=e.value.point,this.currDestPoint.startX-=this.parent.cropObj.totalPannedPoint.x,this.currDestPoint.startY-=this.parent.cropObj.totalPannedPoint.y;break;case"setReverseRotate":this.isReverseRotate=e.value.bool;break;case"getFlipColl":e.value.obj.flipColl=this.flipColl;break;case"setFlipColl":this.flipColl=e.value.flipColl;break;case"getPreviousZoomValue":e.value.obj.previousZoomValue=this.prevZoomValue;break;case"setPreviousZoomValue":this.prevZoomValue=e.value.previousZoomValue;break;case"getCropDimension":e.value.obj.cropDimension=this.cropDimension;break;case"setCropDimension":this.cropDimension.width=e.value.width,this.cropDimension.height=e.value.height;break;case"getPreventSelect":e.value.obj.bool=this.isPreventSelect;break;case"setPreventSelect":this.isPreventSelect=e.value.bool;break;case"resizeImage":this.resizeImage(e.value.width,e.value.height);break;case"resizeCrop":this.resizeCrop(e.value.width,e.value.height);break;case"updateResize":this.updateResize();break;case"resize":this.resize(e.value.width,e.value.height,e.value.isAspectRatio);break;case"straightenImage":this.straightenImage(e.value.degree);break;case"reset":this.reset();break;case"cropZoom":e.value.obj.maxDimension=this.cropZoom(e.value.value,e.value.selectionObj);break;case"setResizedImgAngle":this.resizedImgAngle=e.value.angle}},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.resizedImgAngle=null,this.transCurrObj=null,this.prevZoomValue=1,this.isPreventSelect=this.preventDownScale=!1},i.prototype.rotateImage=function(e){var t=this.parent,o={cancel:!1,previousDegree:t.transform.degree,currentDegree:360===Math.abs(t.transform.degree+e)?0:t.transform.degree+e};this.isPreventSelect||t.trigger("rotating",o),this.rotateEvent(o,e)},i.prototype.rotateEvent=function(e,o){var i=this.parent;if(e.cancel)i.notify("draw",{prop:"setCurrentObj",onPropertyChange:!1,value:{obj:i.prevEventObjPoint}}),i.activeObj=i.prevEventSelectionPoint,i.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate",obj:i.activeObj}});else{var r=void 0;if(t.isNullOrUndefined(this.transCurrObj)){var a={currObj:{}};i.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:a}}),(r=a.currObj).objColl=t.extend([],i.objColl,null,!0),r.pointColl=t.extend({},i.pointColl,null,!0),r.afterCropActions=t.extend([],i.afterCropActions,[],!0);var n={selPointColl:null};i.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:n}}),r.selPointColl=t.extend([],n.selPointColl,[],!0)}i.afterCropActions.push(90===o?"rotateRight":"rotateLeft");var s=[],l=void 0;i.activeObj.activePoint&&i.activeObj.shape&&(void 0!==i.activeObj.shape&&(s=i.activeObj.shape.split("-")),(i.currObjType.isCustomCrop||"crop"===s[0])&&(l=i.currObjType.isCustomCrop?"custom":s[1],i.notify("shape",{prop:"updImgRatioForActObj",onPropertyChange:!1}),i.objColl.push(i.activeObj),i.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}))),i.notify("shape",{prop:"redrawActObj",onPropertyChange:!1,value:{x:null,y:null,isMouseDown:!0}}),this.upperContext.clearRect(0,0,i.upperCanvas.width,i.upperCanvas.height),this.drawRotatedImage(o),i.notify("draw",{prop:"setImageEdited",onPropertyChange:!1}),i.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.lowerContext}}),i.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.upperContext}}),i.isCircleCrop&&i.notify("crop",{prop:"cropCircle",onPropertyChange:!1,value:{context:this.lowerContext,isSave:null,isFlip:null}}),l&&(this.upperContext.clearRect(0,0,i.upperCanvas.width,i.upperCanvas.height),i.activeObj=t.extend({},i.objColl[i.objColl.length-1],{},!0),i.objColl.pop(),i.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate",obj:i.activeObj}})),i.isUndoRedo=!1;var p={collection:i.rotateFlipColl};i.notify("shape",{prop:"alignRotateFlipColl",onPropertyChange:!1,value:{collection:i.rotateFlipColl,isRotateFlipCollection:!0,obj:p}}),i.rotateFlipColl=p.collection,i.cropObj.activeObj.shape&&!this.isPreventSelect&&(i.notify("draw",{prop:"setIsCropSelect",value:{bool:!0}}),this.isPreventSelect=!0,i.notify("draw",{prop:"select",onPropertyChange:!1,value:{type:"custom",startX:null,startY:null,width:null,height:null}}),this.isPreventSelect=!1,i.setProperties({zoomSettings:{zoomFactor:1}},!0),this.prevZoomValue=i.zoomSettings.zoomFactor)}},i.prototype.drawRotatedImage=function(e){var o=this.parent;0===e?o.transform.degree=0:o.transform.degree+=e,360===Math.abs(o.transform.degree)&&(o.transform.degree=0),o.notify("draw",{prop:"setDestPoints",onPropertyChange:!1});var i=t.extend([],o.objColl,[],!0),r=t.extend({},o.activeObj,{},!0);if(o.objColl=[],o.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),this.isReverseRotate||o.notify("draw",{prop:"updateCurrTransState",onPropertyChange:!1,value:{type:"initial",isPreventDestination:null,isRotatePan:null}}),this.rotateDegree(e),this.isReverseRotate||(o.notify("draw",{prop:"updateCurrTransState",onPropertyChange:!1,value:{type:"reverse",isPreventDestination:null,isRotatePan:null}}),o.rotateFlipColl.push(e)),o.objColl=t.extend([],i,[],!0),o.activeObj=t.extend({},r,{},!0),o.isCircleCrop&&o.notify("crop",{prop:"cropCircle",onPropertyChange:!1,value:{context:this.lowerContext,isSave:null,isFlip:null}}),o.notify("shape",{prop:"redrawObj",onPropertyChange:!1,value:{degree:e}}),o.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),e>0)o.notify("freehand-draw",{prop:"rotateFhdColl",onPropertyChange:!1});else for(var a=0;a<3;a++)o.notify("freehand-draw",{prop:"rotateFhdColl",onPropertyChange:!1});o.notify("freehand-draw",{prop:"freehandRedraw",onPropertyChange:!1,value:{context:this.lowerContext,points:null}}),this.updateCurrSelectionPoint(e)},i.prototype.rotateDegree=function(e){var t=this.parent;this.lowerContext.save(),this.lowerContext.clearRect(0,0,t.lowerCanvas.width,t.lowerCanvas.height),this.lowerContext.translate(t.lowerCanvas.width/2,t.lowerCanvas.height/2),this.lowerContext.rotate(Math.PI/180*e),this.lowerContext.translate(-t.lowerCanvas.width/2,-t.lowerCanvas.height/2);var o=this.lowerContext.filter;t.notify("draw",{prop:"drawImage",onPropertyChange:!1}),this.lowerContext.filter=o,this.lowerContext.translate(t.lowerCanvas.width/2,t.lowerCanvas.height/2),this.lowerContext.rotate(Math.PI/180*-e),this.lowerContext.translate(-t.lowerCanvas.width/2,-t.lowerCanvas.height/2),this.lowerContext.restore()},i.prototype.updateCurrSelectionPoint=function(e){var o=this.parent;if(o.currSelectionPoint&&this.currDestPoint){var i=t.extend({},o.activeObj,{},!0),r=t.extend([],o.objColl,[],!0),a={startX:o.img.srcLeft,startY:o.img.srcTop,width:o.img.srcWidth,height:o.img.srcHeight},n={startX:o.img.destLeft,startY:o.img.destTop,width:o.img.destWidth,height:o.img.destHeight};o.objColl=[],o.objColl.push(t.extend({},o.currSelectionPoint,{},!0)),t.isNullOrUndefined(o.objColl[0].imageRatio)&&(o.activeObj=o.objColl[0],o.notify("shape",{prop:"updImgRatioForActObj",onPropertyChange:!1}),o.objColl[0]=o.activeObj),o.img={srcLeft:0,srcTop:0,srcWidth:o.baseImgCanvas.width,srcHeight:o.baseImgCanvas.height,destLeft:this.currDestPoint.startX,destTop:this.currDestPoint.startY,destWidth:this.currDestPoint.width,destHeight:this.currDestPoint.height},"number"==typeof e&&(o.notify("draw",{prop:"setDestPoints",onPropertyChange:!1}),o.notify("draw",{prop:"setClientTransDim",onPropertyChange:!1,value:{isPreventDimension:null}})),o.notify("shape",{prop:"redrawObj",onPropertyChange:!1,value:{degree:e}}),o.currSelectionPoint=t.extend({},o.objColl[0],{},!0),this.currDestPoint={startX:o.img.destLeft,startY:o.img.destTop,width:o.img.destWidth,height:o.img.destHeight},o.objColl=r,o.activeObj=i,o.img={srcLeft:a.startX,srcTop:a.startY,srcWidth:a.width,srcHeight:a.height,destLeft:n.startX,destTop:n.startY,destWidth:n.width,destHeight:n.height}}},i.prototype.flipImage=function(e){var t=this.parent,o={direction:e,cancel:!1,previousDirection:t.toPascalCase(t.transform.currFlipState||e)};this.isPreventSelect||t.trigger("flipping",o),this.flipEvent(o,e)},i.prototype.flipEvent=function(e,o){var i=this.parent;if(e.cancel)return i.notify("draw",{prop:"setCurrentObj",onPropertyChange:!1,value:{obj:i.prevEventObjPoint}}),i.activeObj=i.prevEventSelectionPoint,void i.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate",obj:i.activeObj}});var r;if(t.isNullOrUndefined(this.transCurrObj)){var a={currObj:{}};i.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:a}}),(r=a.currObj).objColl=t.extend([],i.objColl,null,!0),r.pointColl=t.extend({},i.pointColl,null,!0),r.afterCropActions=t.extend([],i.afterCropActions,[],!0);var n={selPointColl:null};i.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:n}}),r.selPointColl=t.extend([],n.selPointColl,[],!0)}i.afterCropActions.push("horizontal"===o.toLowerCase()?"horizontalflip":"verticalflip");var s,l=[];i.activeObj.activePoint&&(void 0!==i.activeObj.shape&&(l=i.activeObj.shape.split("-")),(i.currObjType.isCustomCrop||"crop"===l[0])&&(s=i.currObjType.isCustomCrop?"custom":l[1],i.notify("shape",{prop:"updImgRatioForActObj",onPropertyChange:!1}),i.objColl.push(i.activeObj),i.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}))),i.notify("shape",{prop:"redrawActObj",onPropertyChange:!1,value:{x:null,y:null,isMouseDown:!0}}),i.clearContext(this.lowerContext),i.clearContext(this.upperContext);var p=t.extend([],i.objColl,[],!0),h=t.extend({},i.activeObj,{},!0);i.objColl=[],i.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),this.isReverseFlip||i.notify("draw",{prop:"updateCurrTransState",onPropertyChange:!1,value:{type:"initial",isPreventDestination:null,isRotatePan:null}});var d=o.toLowerCase();this.updateFlipState(d);var c=i.transform.currFlipState.toLowerCase();i.transform.currFlipState="horizontal"===d&&"horizontal"===c||"vertical"===d&&"vertical"===c?"":d;var u={isSelected:null};i.notify("draw",{prop:"getRotatedFlipCropSelection",onPropertyChange:!1,value:{bool:u}}),u.isSelected&&(i.img.destLeft+=i.panPoint.totalPannedInternalPoint.x,i.img.destTop+=i.panPoint.totalPannedInternalPoint.y);var v=this.lowerContext.filter;if(i.notify("draw",{prop:"drawImage",onPropertyChange:!1}),this.lowerContext.filter=v,i.notify("draw",{prop:"setImageEdited",onPropertyChange:!1}),this.updateFlipState(o.toLowerCase()),this.isReverseFlip||(i.notify("draw",{prop:"updateCurrTransState",onPropertyChange:!1,value:{type:"reverse",isPreventDestination:null,isRotatePan:null}}),this.updateFlipColl(o.toLocaleLowerCase()),i.rotateFlipColl.push(o.toLowerCase())),1===i.rotateFlipColl.length){var g={panRegion:""};i.notify("crop",{prop:"getCurrFlipState",onPropertyChange:!1,value:{panObj:g}}),""===g.panRegion?i.notify("draw",{prop:"setClientTransDim",onPropertyChange:!1,value:{isPreventDimension:null}}):this.setDestPointsForFlipState()}i.isCircleCrop&&i.notify("crop",{prop:"cropCircle",onPropertyChange:!1,value:{context:this.lowerContext,isSave:null,isFlip:null}}),i.objColl=t.extend([],p,[],!0),i.activeObj=t.extend({},h,{},!0);for(var f=0,C=i.objColl.length;f<C;f++){var b=i.objColl[f].flipObjColl;0===b.length?b.push(o):b[b.length-1]===o?b.pop():b.push(o)}i.notify("shape",{prop:"redrawObj",onPropertyChange:!1,value:{degree:o.toLowerCase()}});var m=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%)",i.notify("shape",{prop:"iterateObjColl",onPropertyChange:!1});var y=o.toLowerCase();"horizontal"===y||"vertical"===y?(i.notify("freehand-draw",{prop:"flipFHDColl",onPropertyChange:!1,value:{value:y}}),i.notify("freehand-draw",{prop:"freehandRedraw",onPropertyChange:!1,value:{context:this.lowerContext,points:null}})):i.notify("freehand-draw",{prop:"freehandRedraw",onPropertyChange:!1,value:{context:this.lowerContext,points:null}}),this.lowerContext.filter=m,i.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),this.updateCurrSelectionPoint(y),i.isUndoRedo=!1,i.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.lowerContext}}),i.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.upperContext}}),i.isCircleCrop&&i.notify("crop",{prop:"cropCircle",onPropertyChange:!1,value:{context:this.lowerContext,isSave:null,isFlip:null}}),s&&(this.upperContext.clearRect(0,0,i.upperCanvas.width,i.upperCanvas.height),i.activeObj=t.extend({},i.objColl[i.objColl.length-1],{},!0),i.objColl.pop(),i.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate",obj:i.activeObj}}));var P={collection:i.rotateFlipColl};i.notify("shape",{prop:"alignRotateFlipColl",onPropertyChange:!1,value:{collection:i.rotateFlipColl,isRotateFlipCollection:!0,obj:P}}),i.rotateFlipColl=P.collection,i.cropObj.activeObj.shape&&!this.isPreventSelect&&(i.notify("draw",{prop:"setIsCropSelect",value:{bool:!0}}),this.isPreventSelect=!0,i.notify("draw",{prop:"select",onPropertyChange:!1,value:{type:"custom",startX:null,startY:null,width:null,height:null}}),this.isPreventSelect=!1,i.setProperties({zoomSettings:{zoomFactor:1}},!0),this.prevZoomValue=i.zoomSettings.zoomFactor)},i.prototype.updateFlipState=function(e){var t=this.parent.transform.degree;"horizontal"===e?t%90==0&&t%180!=0?this.verticalFlip():this.horizontalFlip():"vertical"===e&&(t%90==0&&t%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(e){if(!this.isPreventSelect&&(0===this.flipColl.length||this.flipColl[this.flipColl.length-1]!==e?this.flipColl.push(e):this.flipColl.pop(),this.flipColl.length>=4)){var t=this.flipColl.slice(-4);("horizontal"===t[0]&&"vertical"===t[1]&&"horizontal"===t[2]&&"vertical"===t[3]||"vertical"===t[0]&&"horizontal"===t[1]&&"vertical"===t[2]&&"horizontal"===t[3])&&this.flipColl.splice(-4)}},i.prototype.setDestPointsForFlipState=function(){var e=this.parent,t={panRegion:""},o=e.img,i=o.destLeft,r=o.destTop,a=o.destWidth,n=o.destHeight,s=e.lowerCanvas,l=s.clientWidth,p=s.clientHeight;e.notify("crop",{prop:"getCurrFlipState",onPropertyChange:!1,value:{panObj:t}}),""!==t.panRegion&&("horizontal"===t.panRegion?e.img.destLeft=l-(a+i):"vertical"===t.panRegion?e.img.destTop=p-(n+r):(e.img.destLeft=l-(a+i),e.img.destTop=p-(n+r)))},i.prototype.zoomAction=function(e,o,i,r){var a=this.parent;if(!a.disabled&&a.isImageLoaded){if(t.isNullOrUndefined(i)&&(a.zoomSettings.zoomFactor>=a.zoomSettings.maxZoomFactor&&e>0||a.zoomSettings.zoomFactor>a.zoomSettings.minZoomFactor&&e<0&&this.disableZoomOutBtn(!0)||a.zoomSettings.zoomFactor<=a.zoomSettings.minZoomFactor&&e<0))return void a.notify("toolbar",{prop:"zoom-up-handler",onPropertyChange:!1});a.notify("draw",{prop:"setImageEdited",onPropertyChange:!1});var n=e;e=n>0?.1:-.1;for(var s=0;s<Math.round(Math.abs(n/.1));s++)if(1===this.prevZoomValue)this.prevZoomValue+=e>0?10*e:10*e/10;else if(this.prevZoomValue>1)this.prevZoomValue+=10*e;else if(this.prevZoomValue<1){this.prevZoomValue+=10*e/10;var l=Math.pow(10,1);this.prevZoomValue=Math.round(this.prevZoomValue*l)/l}e=n,a.setProperties({zoomSettings:{zoomFactor:this.prevZoomValue}},!0);var p=void 0;this.tempActiveObj=null,this.isShape=!1,void 0!==a.activeObj.shape&&("shape"===a.activeObj.shape?a.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}):p=a.activeObj.shape.split("-")),void 0!==p&&"crop"===p[0]?(this.tempActiveObj=t.extend({},a.activeObj,{},!0),a.isCropTab=!0):a.activeObj.shape&&"crop"!==p[0]&&(this.isShape=!0);var h={zoomType:null};a.notify("selection",{prop:"getZoomType",onPropertyChange:!1,value:{obj:h}}),t.isNullOrUndefined(o)&&(o=a.isCropTab&&this.tempActiveObj?{x:a.activeObj.activePoint.startX+a.activeObj.activePoint.width/2,y:a.activeObj.activePoint.startY+a.activeObj.activePoint.height/2}:{x:a.lowerCanvas.clientWidth/2,y:a.lowerCanvas.clientHeight/2},"MouseWheel"!==h.zoomType&&"Pinch"!==h.zoomType||(o={x:a.zoomSettings.zoomPoint.x,y:a.zoomSettings.zoomPoint.y}));var d={zoomPoint:o,cancel:!1,previousZoomFactor:a.zoomSettings.zoomFactor-10*e,currentZoomFactor:a.zoomSettings.zoomFactor,zoomTrigger:h.zoomType};!a.isCropToolbar&&a.isZoomBtnClick&&a.trigger("zooming",d),this.zoomEvent(d,e,r)}},i.prototype.zoomEvent=function(e,o,i){var r=this.parent,a=r.zoomSettings,n=a.zoomFactor,s=a.minZoomFactor;if(e.cancel)return void(r.isZoomBtnClick=!1);r.notify("toolbar",{prop:"close-contextual-toolbar",onPropertyChange:!1}),r.notify("shape",{prop:"redrawActObj",onPropertyChange:!1,value:{x:null,y:null,isMouseDown:!0}}),r.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),this.upperContext.clearRect(0,0,r.lowerCanvas.width,r.lowerCanvas.height);var l={canvasFilter:r.canvasFilter};this.lowerContext.filter=l.canvasFilter,r.upperCanvas.style.cursor=r.cursor="default";var p=t.extend([],r.objColl,[],!0);if(!r.isCropTab){if(0!==r.transform.degree){r.notify("shape",{prop:"redrawActObj",onPropertyChange:!1,value:{x:null,y:null,isMouseDown:null}}),r.panPoint.currentPannedPoint={x:0,y:0};f=r.allowDownScale;r.allowDownScale=!1,this.rotatePan(!0,!0),r.allowDownScale=f}else""!==r.transform.currFlipState&&(r.panPoint.totalPannedPoint={x:0,y:0});0!==r.transform.straighten||this.isPreventSelect||r.notify("freehand-draw",{prop:"updateFHDColl",onPropertyChange:!1,value:{isPreventApply:i}})}if(0===r.transform.degree){this.drawZoomImgToCanvas(o,this.tempActiveObj);var h={panRegion:""};if(r.notify("crop",{prop:"getCurrFlipState",onPropertyChange:!1,value:{panObj:h}}),""!==h.panRegion){r.notify("crop",{prop:"setTempFlipPanPoint",onPropertyChange:!1,value:{point:r.panPoint.totalPannedPoint,isAdd:!0}}),p=t.extend([],r.objColl,[],!0),r.objColl=[];var d=r.img.destLeft,c=r.img.destTop;this.setDestPointsForFlipState(),this.rotatedFlip(),r.img.destLeft=d,r.img.destTop=c,r.objColl=p,r.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"zoom",pen:"zoom",isPreventApply:i}}),0!==r.transform.straighten||this.isPreventSelect||r.notify("freehand-draw",{prop:"updateFHDColl",onPropertyChange:!1,value:{isPreventApply:i}})}n<=s&&!r.isCropTab&&(r.panPoint.totalPannedPoint={x:0,y:0})}else{0!==r.transform.straighten||this.isPreventSelect||r.notify("freehand-draw",{prop:"updateFHDColl",onPropertyChange:!1,value:{isPreventApply:i}}),r.panPoint.totalPannedClientPoint={x:0,y:0},r.panPoint.totalPannedInternalPoint={x:0,y:0},this.rotateZoom(o);var u={panRegion:""};if(r.notify("crop",{prop:"getCurrFlipState",onPropertyChange:!1,value:{panObj:u}}),""!==u.panRegion){f=this.lowerContext.filter;this.lowerContext.filter="none",r.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"zoom",pen:"zoom",isPreventApply:i}}),this.lowerContext.filter=f}}var v=Math.pow(10,1);(n<=s||Math.round(r.transform.zoomFactor*v)/v==2)&&(clearInterval(this.zoomBtnHold),this.zoomBtnHold=0);var g={panRegion:""};if(r.notify("crop",{prop:"getCurrFlipState",onPropertyChange:!1,value:{panObj:g}}),""===g.panRegion){var f=this.lowerContext.filter;this.lowerContext.filter="none",r.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"zoom",pen:"zoom",isPreventApply:i}}),this.lowerContext.filter=f}(r.currSelectionPoint&&"crop-circle"===r.currSelectionPoint.shape||r.isCircleCrop)&&r.notify("crop",{prop:"cropCircle",onPropertyChange:!1,value:{context:this.lowerContext,isSave:null,isFlip:null}}),r.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.lowerContext}}),r.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),this.tempActiveObj&&(r.activeObj=t.extend({},this.tempActiveObj,{},!0),r.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate",obj:r.activeObj}}),n<=s&&(r.currSelectionPoint=null)),r.isUndoRedo=!1;var C;(C=document.querySelector("#"+r.element.id+"_zoomOut"))&&n<=s?(C.classList.add("e-disabled"),C.parentElement.classList.add("e-overlay")):C&&(C.classList.remove("e-disabled"),C.parentElement.classList.remove("e-overlay"));var b=r.drawingShape;this.autoEnablePan(),r.drawingShape=b,this.tempActiveObj&&(r.activeObj=t.extend({},this.tempActiveObj,{},!0)),"crop-custom"===r.activeObj.shape&&(r.currObjType.isCustomCrop=!0);var m=r.element.querySelector(".e-img-pan .e-btn");if(m&&r.togglePan?m.classList.add("e-selected-btn"):m&&m.classList.remove("e-selected-btn"),this.isShape&&(r.activeObj=t.extend({},r.objColl[r.objColl.length-1],{},!0),r.objColl.pop(),r.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate",obj:r.activeObj,isCropRatio:null,points:null,isPreventDrag:!0,saveContext:null,isPreventSelection:null}}),r.notify("toolbar",{prop:"update-toolbar-items",onPropertyChange:!1}),r.notify("toolbar",{prop:"renderQAT",onPropertyChange:!1,value:{isPenEdit:null}})),r.notify("toolbar",{prop:"enable-disable-btns",onPropertyChange:!1}),r.notify("selection",{prop:"setZoomType",onPropertyChange:!1,value:{zoomType:"Toolbar"}}),e={zoomPoint:e.zoomPoint,previousZoomFactor:e.previousZoomFactor,currentZoomFactor:e.currentZoomFactor,zoomTrigger:e.zoomTrigger},!r.isCropToolbar&&r.isZoomBtnClick&&(r.isZoomBtnClick=!1),r.drawingShape){var y=t.extend({},r.activeObj,{},!0);if(r.enableShapeDrawing(r.toPascalCase(r.drawingShape),!0),r.activeObj=y,y.activePoint.width>0||y.activePoint.height>0||y.pointColl&&y.pointColl.length>0){var P=r.element.querySelector("#"+r.element.id+"_zOrderBtn"),j=r.element.querySelector("#"+r.element.id+"_duplicate"),x=r.element.querySelector("#"+r.element.id+"_remove"),w=r.element.querySelector("#"+r.element.id+"_editText");P&&P.classList.remove("e-disabled"),j&&j.classList.remove("e-disabled"),x&&x.classList.remove("e-disabled"),w&&w.classList.remove("e-disabled")}}},i.prototype.disableZoomOutBtn=function(e){var o,i=this.parent,r=i.zoomSettings,a=r.zoomFactor,n=r.minZoomFactor,s=!1;t.isNullOrUndefined(e)||(i.transform.zoomFactor-=.1),o=i.element.querySelector("#"+i.element.id+"_zoomOut");var l={destLeft:i.img.destLeft,destTop:i.img.destTop,destWidth:i.img.destWidth,destHeight:i.img.destHeight};if(i.activeObj.shape){var p=this.setZoomDimension(-.1,i.activeObj);if(!t.isNullOrUndefined(o)){var h=i.activeObj.activePoint;if(0===i.transform.straighten)i.img.destLeft>h.startX||i.img.destTop>h.startY||i.img.destLeft+i.img.destWidth<h.endX||i.img.destTop+i.img.destHeight<h.endY||a===n?(o.classList.add("e-disabled"),o.parentElement.classList.add("e-overlay"),s=!0):(o.classList.remove("e-disabled"),o.parentElement.classList.remove("e-overlay"),s=!1);else{i.img.destWidth=p.width,i.img.destHeight=p.height;var d={isIntersect:null};i.notify("draw",{prop:"updateImgCanvasPoints",onPropertyChange:!1}),i.notify("draw",{prop:"isLinesIntersect",onPropertyChange:!1,value:{obj:d}}),d.isIntersect||a===n?(o.classList.add("e-disabled"),o.parentElement.classList.add("e-overlay"),s=!0):(o.classList.remove("e-disabled"),o.parentElement.classList.remove("e-overlay"),s=!1)}}}else this.setZoomDimension(-.1,null);return t.isNullOrUndefined(e)||(i.transform.zoomFactor+=.1),i.img.destLeft=l.destLeft,i.img.destTop=l.destTop,i.img.destWidth=l.destWidth,i.img.destHeight=l.destHeight,s},i.prototype.drawZoomImgToCanvas=function(e,t){var o=this.parent,i=Math.pow(10,1),r=Math.round(o.transform.zoomFactor*i)/i;.1===r&&-.1===e||0===r&&-.025===e?o.transform.zoomFactor=0:o.transform.zoomFactor+=e,o.transform[o.isCropTab?"cropZoomFactor":"defaultZoomFactor"]=o.transform.zoomFactor;var a={width:0,height:0};o.isCropTab?a=this.cropZoom(e,t):((a=this.calcMaxDimension(o.img.srcWidth,o.img.srcHeight)).width+=a.width*o.transform.zoomFactor,a.height+=a.height*o.transform.zoomFactor,o.img.destLeft=(o.lowerCanvas.clientWidth-a.width)/2,o.img.destTop=(o.lowerCanvas.clientHeight-a.height+1)/2),o.notify("draw",{prop:"draw-image-to-canvas",value:{dimension:a}}),a.width=this.cropDimension.width,a.height=this.cropDimension.height,a.width+=a.width*o.transform.zoomFactor,a.height+=a.height*o.transform.zoomFactor,o.notify("draw",{prop:"setZoomCropWidth",value:{width:a.width,height:a.height}})},i.prototype.rotatedFlip=function(){var e=this.parent;this.isReverseFlip=!0;var o=e.transform.currFlipState,i=this.flipColl,r=t.extend([],e.objColl,[],!0),a=t.extend({},e.activeObj,{},!0);this.flipColl=[],e.objColl=[],e.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),e.notify("draw",{prop:"currTransState",onPropertyChange:!1,value:{type:"initial",isPreventDestination:null,context:null,isPreventCircleCrop:null}});var n=this.lowerContext.filter;e.notify("draw",{prop:"drawImage",onPropertyChange:!1}),this.lowerContext.filter=n,e.notify("draw",{prop:"currTransState",onPropertyChange:!1,value:{type:"reverse",isPreventDestination:!0,context:null,isPreventCircleCrop:null}}),""===o&&""!==e.transform.currFlipState&&(o=e.transform.currFlipState),e.transform.currFlipState=o,this.flipColl=i,e.objColl=t.extend([],r,[],!0),this.lowerContext.filter="none",e.notify("shape",{prop:"iterateObjColl",onPropertyChange:!1}),this.lowerContext.filter=n,0!==a.activePoint.width&&(e.activeObj=t.extend({},a,{},!0)),this.isReverseFlip=!1},i.prototype.rotateZoom=function(e){var o=this.parent,i=Math.pow(10,1),r=Math.round(o.transform.zoomFactor*i)/i;.1===r&&-.1===e||0===r&&-.025===e?o.transform.zoomFactor=0:o.transform.zoomFactor+=e,o.isCropTab?o.transform.cropZoomFactor=o.transform.zoomFactor:o.transform.defaultZoomFactor=o.transform.zoomFactor;var a=t.extend([],o.objColl,[],!0),n=t.extend({},o.activeObj,{},!0);o.objColl=[],o.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),o.notify("draw",{prop:"updateCurrTransState",onPropertyChange:!1,value:{type:"initial",isPreventDestination:null,isRotatePan:null}}),o.notify("draw",{prop:"setRotateZoom",onPropertyChange:!1,value:{isRotateZoom:!0}}),o.notify("draw",{prop:"setDestPoints",onPropertyChange:!1});var s=this.lowerContext.filter;o.notify("draw",{prop:"drawImage",onPropertyChange:!1}),this.lowerContext.filter=s,o.notify("draw",{prop:"setRotateZoom",onPropertyChange:!1,value:{isRotateZoom:!1}}),o.notify("draw",{prop:"updateCurrTransState",onPropertyChange:!1,value:{type:"reverse",isPreventDestination:null,isRotatePan:null}}),o.objColl=a,o.activeObj=n;var l={width:this.cropDimension.width,height:this.cropDimension.height};l.width+=l.width*o.transform.zoomFactor,l.height+=l.height*o.transform.zoomFactor,o.notify("draw",{prop:"setZoomCropWidth",value:{width:l.width,height:l.height}})},i.prototype.autoEnablePan=function(){var e=this.parent;e.transform.zoomFactor<=0?(e.togglePan=!1,e.notify("selection",{prop:"setDragCanvas",value:{bool:!1}}),e.pan(!1),this.disablePan=!1):e.pan(!this.disablePan)},i.prototype.cropZoom=function(e,o){var i=this.parent,r=i.img.destLeft,a=i.img.destTop,n={width:0,height:0};return 0===i.img.srcLeft||0===i.img.srcTop?n=t.isNullOrUndefined(o)?this.setZoomDimension(e,null):this.setZoomDimension(e,o):((n=i.transform.degree%90==0&&i.transform.degree%180!=0?this.calcMaxDimension(i.img.srcHeight,i.img.srcWidth):this.calcMaxDimension(i.img.srcWidth,i.img.srcHeight)).width+=n.width*i.transform.zoomFactor,n.height+=n.height*i.transform.zoomFactor),i.img.destLeft=r-(n.width-i.img.destWidth)/2,i.img.destTop=a-(n.height-i.img.destHeight)/2,r=i.img.destLeft,a=i.img.destTop,o&&0===i.transform.straighten&&(i.img.destLeft>o.activePoint.startX&&(i.img.destLeft=o.activePoint.startX,0===i.transform.degree&&(i.panPoint.totalPannedPoint.x-=r-i.img.destLeft)),i.img.destTop>o.activePoint.startY&&(i.img.destTop=o.activePoint.startY,0===i.transform.degree&&(i.panPoint.totalPannedPoint.y-=a-i.img.destTop)),i.img.destLeft+n.width<o.activePoint.endX&&(i.img.destLeft=o.activePoint.endX-n.width,0===i.transform.degree&&(i.panPoint.totalPannedPoint.x-=r-i.img.destLeft)),i.img.destTop+n.height<o.activePoint.endY&&(i.img.destTop=o.activePoint.endY-n.height,0===i.transform.degree&&(i.panPoint.totalPannedPoint.y-=a-i.img.destTop))),n},i.prototype.setZoomDimension=function(e,o){var i=this.parent,r=i.transform.degree,a={width:0,height:0};if(a=r%90==0&&r%180!=0?this.calcMaxDimension(i.img.srcHeight,i.img.srcWidth):this.calcMaxDimension(i.img.srcWidth,i.img.srcHeight),a.width+=a.width*i.transform.zoomFactor,a.height+=a.height*i.transform.zoomFactor,i.img.destLeft+=(i.img.destWidth-a.width)/2,i.img.destTop+=(i.img.destHeight-a.height)/2,e<0&&o){var n=o.activePoint.startX,s=o.activePoint.startY,l=o.activePoint.width,p=o.activePoint.height,h=i.img.destLeft+a.width,d=i.img.destTop+a.height;i.img.destLeft>n&&(i.img.destLeft=n),i.img.destTop>s&&(i.img.destTop=s),h<n+l&&(i.img.destLeft=n+l-a.width),d<s+p&&(i.img.destTop=s+p-a.height)}else e<0&&t.isNullOrUndefined(o)&&(i.img.destLeft>0&&(i.img.destLeft=0),i.img.destTop>0&&(i.img.destTop=0),i.img.destLeft+a.width<i.lowerCanvas.clientWidth&&(i.img.destLeft=i.lowerCanvas.clientWidth-i.img.destWidth),i.img.destTop+a.height<i.lowerCanvas.clientHeight&&(i.img.destTop=i.lowerCanvas.clientHeight-i.img.destHeight));return a},i.prototype.drawPannedImage=function(e,t){var o=this.parent,i={panDown:null};o.notify("selection",{prop:"getPanDown",onPropertyChange:!1,value:{obj:i}});var r={startPoint:i.panDown,endPoint:this.panMove,cancel:!1};o.trigger("panning",r),r.cancel||this.panEvent(e,t)},i.prototype.panEvent=function(e,o,i){var r=this.parent,a=!1;if(r.activeObj.shape&&"shape"===r.activeObj.shape&&r.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),t.isNullOrUndefined(r.activeObj.shape)){a=!0;var n=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},s=n.startX,l=n.startY,p=n.endX,h=n.endY;s<0&&(n.startX=0),l<0&&(n.startY=0),p>r.lowerCanvas.width&&(n.endX=r.lowerCanvas.width),h>r.lowerCanvas.height&&(n.endY=r.lowerCanvas.height),n.width=n.endX-n.startX,n.height=n.endY-n.startY,r.activeObj.shape="crop-custom";var d={strokeSettings:{}};r.notify("shape",{prop:"getStrokeSettings",onPropertyChange:!1,value:{obj:d}}),r.activeObj.strokeSettings=d.strokeSettings,r.notify("draw",{prop:"updateActiveObject",onPropertyChange:!1,value:{actPoint:n,obj:r.activeObj,isMouseMove:null,x:null,y:null}}),r.isCropTab=!0}if(0===r.transform.degree){var c=void 0;c=t.isNullOrUndefined(e)&&t.isNullOrUndefined(o)||i?i?this.updatePanPoints(e,o):this.updatePanPoints():{x:e,y:o},r.panPoint.totalPannedPoint.x+=c.x,r.panPoint.totalPannedPoint.y+=c.y;var u=t.extend({},r.activeObj,{},!0),v=this.lowerContext.filter;this.drawPannImage(c,a),this.lowerContext.filter=v,this.tempPanMove=t.extend({},this.panMove,{},!0),r.activeObj=t.extend({},u,{},!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 g=r.transform.currFlipState;r.isCropTab=!0,t.isNullOrUndefined(e)&&t.isNullOrUndefined(o)||i?r.panPoint.currentPannedPoint=i?this.updatePanPoints(e,o):this.updatePanPoints():r.panPoint.currentPannedPoint={x:e,y:o},r.transform.currFlipState=g,this.rotatePan(null,null,a),r.isCropTab=!1,this.tempPanMove=t.extend({},this.panMove,{},!0)}a&&(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(e,t){var o=this.parent,i=this.lowerContext.filter,r={startX:o.img.destLeft,startY:o.img.destTop,width:o.img.destWidth,height:o.img.destHeight};this.lowerContext.clearRect(0,0,o.lowerCanvas.width,o.lowerCanvas.height),o.notify("draw",{prop:"updateCurrTransState",onPropertyChange:!1,value:{type:"initial",isPreventDestination:null,isRotatePan:null}}),o.img.destLeft=r.startX,o.img.destTop=r.startY,o.img.destWidth=r.width,o.img.destHeight=r.height,this.setDestPointsForFlipState(),t&&(o.isCropTab=!1),o.notify("draw",{prop:"drawImage",onPropertyChange:!1}),t&&(o.isCropTab=!0),(o.currSelectionPoint&&"crop-circle"===o.currSelectionPoint.shape||o.isCircleCrop)&&o.notify("crop",{prop:"cropCircle",onPropertyChange:!1,value:{context:this.lowerContext,isSave:null,isFlip:!0}}),this.lowerContext.filter=i,o.notify("draw",{prop:"updateCurrTransState",onPropertyChange:!1,value:{type:"reverse",isPreventDestination:null,isRotatePan:null}}),o.img.destLeft=r.startX,o.img.destTop=r.startY,o.img.destWidth=r.width,o.img.destHeight=r.height;var a=this.lowerContext.filter;this.lowerContext.filter="none",t&&(o.isCropTab=!1),o.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"pan",pen:"pan",x:e.x,y:e.y,panRegion:""}}),t&&(o.isCropTab=!0),this.lowerContext.filter=a,o.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.lowerContext}}),o.isCircleCrop&&o.notify("crop",{prop:"cropCircle",onPropertyChange:!1,value:{context:this.lowerContext,isSave:null,isFlip:!0}})},i.prototype.resetZoom=function(){var e=this.parent;if(0!==e.transform.defaultZoomFactor){var o=e.isUndoRedo,i={currObj:{}};e.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:i}}),this.transCurrObj=i.currObj,this.transCurrObj.objColl=t.extend([],e.objColl,null,!0),this.transCurrObj.pointColl=t.extend({},e.pointColl,null,!0),this.transCurrObj.afterCropActions=t.extend([],e.afterCropActions,[],!0);var r={selPointColl:null};e.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:r}}),this.transCurrObj.selPointColl=t.extend([],r.selPointColl,[],!0),e.isUndoRedo=e.isCropToolbar=!0;var a=e.transform.defaultZoomFactor;a>0?this.zoomAction(-a):this.zoomAction(Math.abs(a)),e.isCropToolbar=!1,e.isUndoRedo=o}},i.prototype.performTransformation=function(e){var o=this.parent,i=o.transform.defaultZoomFactor,r=o.isUndoRedo,a=t.extend({},o.cropObj,{},!0);this.resetZoom(),this.updateTransform(e);for(var n=0,s=o.objColl.length;n<s;n++)if(o.objColl[n].flipObjColl.length>0){var l={collection:o.objColl[n].flipObjColl};o.notify("shape",{prop:"alignRotateFlipColl",onPropertyChange:!1,value:{collection:l.collection,isRotateFlipCollection:null,obj:l}}),o.objColl[n].flipObjColl=l.collection,0===o.objColl[n].flipObjColl.length&&(o.objColl[n].shapeFlip="")}if(0!==i){o.isUndoRedo=!0,this.zoomAction(i),o.isUndoRedo=r;var p="";"rotateleft"===e||"rotateright"===e?p="rotate":"horizontalflip"!==e&&"verticalflip"!==e||(p="flip"),o.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:a,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),this.transCurrObj=null}},i.prototype.updateTransform=function(t){switch(t.toLowerCase()){case"rotateleft":this.rotateImage(-90);break;case"rotateright":this.rotateImage(90);break;case"horizontalflip":this.flipImage(e.Direction.Horizontal);break;case"verticalflip":this.flipImage(e.Direction.Vertical)}},i.prototype.rotatePan=function(e,o,i){var r=this.parent;this.isReverseRotate=!0;var a,n=r.transform.degree,s={selPointColl:null};r.activeObj.activePoint&&r.activeObj.shape&&(a=t.extend({},r.activeObj,{},!0));var l=t.extend([],r.objColl,[],!0),p=t.extend([],r.pointColl,[],!0);r.objColl=[],r.pointColl=[],r.freehandCounter=0,r.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:s}});var h=s.selPointColl;r.notify("freehand-draw",{prop:"setSelPointColl",onPropertyChange:!1,value:{obj:{selPointColl:[]}}}),r.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),r.notify("draw",{prop:"setRotateZoom",onPropertyChange:!1,value:{isRotateZoom:!0}}),r.notify("draw",{prop:"updateCurrTransState",onPropertyChange:!1,value:{type:"initial",isPreventDestination:null,isRotatePan:null}});var d=r.img.destLeft,c=r.img.destTop,u=r.panPoint.totalPannedInternalPoint;r.isCropTab&&(r.img.destLeft+=u.x,r.img.destTop+=u.y),r.notify("crop",{prop:"updateRotatePan",onPropertyChange:!1}),r.isCropTab&&(r.panPoint.totalPannedInternalPoint.x=r.img.destLeft-d,r.panPoint.totalPannedInternalPoint.y=r.img.destTop-c);var v=this.lowerContext.filter;i&&(r.isCropTab=!1),r.notify("draw",{prop:"drawImage",onPropertyChange:!1}),i&&(r.isCropTab=!0),r.notify("draw",{prop:"setRotateZoom",onPropertyChange:!1,value:{isRotateZoom:!1}}),r.notify("draw",{prop:"updateCurrTransState",onPropertyChange:!1,value:{type:"reverse",isPreventDestination:!0,isRotatePan:!0}});var g=r.img.destLeft,f=r.img.destTop;r.img.destLeft+=r.panPoint.totalPannedClientPoint.x,r.img.destTop+=r.panPoint.totalPannedClientPoint.y,r.img.destLeft+=r.panPoint.currentPannedPoint.x,r.img.destTop+=r.panPoint.currentPannedPoint.y,r.panPoint.totalPannedClientPoint.x=r.img.destLeft-g,r.panPoint.totalPannedClientPoint.y=r.img.destTop-f,r.objColl=l,r.pointColl=p,r.freehandCounter=r.pointColl.length,r.notify("freehand-draw",{prop:"setSelPointColl",onPropertyChange:!1,value:{obj:{selPointColl:h}}}),r.transform.degree=n,this.lowerContext.filter="none",e&&(o?(r.panPoint.totalPannedClientPoint.x=-r.panPoint.totalPannedClientPoint.x,r.panPoint.totalPannedClientPoint.y=-r.panPoint.totalPannedClientPoint.y,r.panPoint.currentPannedPoint=t.extend({},r.panPoint.totalPannedClientPoint,{},!0),r.panPoint.totalPannedClientPoint={x:0,y:0},r.img.destLeft+=r.panPoint.currentPannedPoint.x,r.img.destTop+=r.panPoint.currentPannedPoint.y):r.panPoint.currentPannedPoint=t.extend({},r.panPoint.totalPannedClientPoint,{},!0)),i&&(r.isCropTab=!1),r.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"pan",pen:"pan",x:r.panPoint.currentPannedPoint.x,y:r.panPoint.currentPannedPoint.y,panRegion:""}}),i&&(r.isCropTab=!0),this.lowerContext.filter=v,r.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.lowerContext}}),this.upperContext.clearRect(0,0,r.upperCanvas.width,r.upperCanvas.height),r.activeObj=t.extend({},a,{},!0),r.activeObj.activePoint&&r.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate",obj:r.activeObj,isCropRatio:null,points:null,isPreventDrag:!0,saveContext:null,isPreventSelection:null}}),this.isReverseRotate=!1},i.prototype.limitPan=function(){var e=this.parent,t=e.activeObj.activePoint,o=t.startX,i=t.startY,r=t.endX,a=t.endY,n=e.img;e.activeObj.activePoint&&(n.destLeft>o&&(e.img.destLeft=o),n.destTop>i&&(e.img.destTop=i),n.destLeft+n.destWidth<r&&(e.img.destLeft=r-n.destWidth),n.destTop+n.destHeight<a&&(e.img.destTop=a-n.destHeight))},i.prototype.pan=function(e,o,i){var r=this.parent;!r.disabled&&r.isImageLoaded&&(e?(r.togglePan=!0,r.notify("shape",{prop:"redrawActObj",onPropertyChange:!1,value:{x:null,y:null,isMouseDown:null}}),r.notify("selection",{prop:"setDragCanvas",value:{bool:!0}}),r.lowerCanvas.style.cursor=r.upperCanvas.style.cursor=r.cursor="grab",r.notify("selection",{prop:"setPanDown",onPropertyChange:!1,value:{panDown:null}}),(o||i)&&(o=o||0,i=i||0,t.isNullOrUndefined(this.panMove)&&(this.panMove={x:o,y:i}),t.isNullOrUndefined(this.tempPanMove)&&(this.tempPanMove={x:this.panMove.x,y:this.panMove.y}),this.panEvent(o,i,!0),this.tempPanMove=null)):(r.togglePan=r.currObjType.isCustomCrop=!1,r.notify("selection",{prop:"setDragCanvas",value:{bool:!1}}),r.lowerCanvas.style.cursor=r.upperCanvas.style.cursor=r.cursor="default"))},i.prototype.zoom=function(e,o){var i=this.parent;if(!i.disabled&&i.isImageLoaded){var r=this.getCurrentZoomFactor(e);if(t.isNullOrUndefined(o))this.zoomAction(r,o);else for(var a=r>0?"zoomIn":"zoomOut",n=10*Math.abs(r),s=0;s<n;s++)i.notify("draw",{prop:"performPointZoom",onPropertyChange:!1,value:{x:o.x,y:o.y,type:a,isResize:null}})}},i.prototype.getCurrentZoomFactor=function(e){return e>=1?this.prevZoomValue<1?e-this.prevZoomValue:.1*(e-this.prevZoomValue):e-this.prevZoomValue},i.prototype.setCurrPanRegion=function(e,t,o){var i=e;i=""===e?"horizontal"===t?"horizontal":"vertical"===t?"vertical":e:"horizontal"===e?"horizontal"===t?"horizontalVertical":"vertical"===t?"verticalHorizontal":90===t?"vertical":-90===t?"horizontal":e:"vertical"===e?"horizontal"===t?"horizontalVertical":"vertical"===t?"verticalHorizontal":90===t?"horizontal":-90===t?"vertical":e:"horizontal"===t?"vertical":"vertical"===t?"horizontal":e,o.panRegion=i},i.prototype.rotate=function(e,t){var o=this.parent;!o.disabled&&o.isImageLoaded&&e%90==0&&this.rotateImage(e),t.isRotate=!1},i.prototype.flip=function(e){var t=this.parent;!t.disabled&&t.isImageLoaded&&this.flipImage(e)},i.prototype.update=function(){var e=this.parent,i=0,r=!1,a={bool:!1},n={bool:e.isStraightening},s=0,l=e.element.querySelector("#"+e.element.id+"_contextualToolbar"),p=e.element.querySelector(".e-contextual-toolbar-wrapper"),h=e.element.querySelector("#"+e.element.id+"_headWrapper");if(e.isImageLoaded){var d=!1,c=void 0;t.Browser.isDevice&&(e.activeObj.shape&&(c=e.activeObj.shape.split("-")),e.currObjType.isCustomCrop?d=!0:c&&"crop"===c[0]&&(d=!0));var u={bool:null};e.notify("toolbar",{prop:"getFrameToolbar",onPropertyChange:!1,value:{obj:u}}),!n.bool&&(l&&!l.parentElement.classList.contains("e-hide")||h&&!h.parentElement.classList.contains("e-hide"))&&(p.classList.add("e-hide"),d||e.okBtn(null,!0),e.notify("toolbar",{prop:"refresh-main-toolbar",onPropertyChange:!1}),e.notify("toolbar",{prop:"destroy-qa-toolbar",onPropertyChange:!1})),e.notify("selection",{prop:"getFreehandDrawEditing",onPropertyChange:!1,value:{obj:a}}),a.bool&&e.notify("toolbar",{prop:"destroy-qa-toolbar",onPropertyChange:!1});var v=t.extend({},e.activeObj.activePoint,{},!0);!e.activeObj.shape||0===v.width&&0===v.height||(r=!0,"block"===e.textArea.style.display||"inline-block"===e.textArea.style.display?(e.notify("shape",{prop:"redrawActObj",onPropertyChange:!1,value:{x:null,y:null,isMouseDown:null}}),e.notify("toolbar",{prop:"destroy-qa-toolbar",onPropertyChange:!1})):(e.notify("shape",{prop:"updImgRatioForActObj",onPropertyChange:!1}),e.objColl.push(e.activeObj)),e.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}))}var g=this.lowerContext.filter,f=e.element.querySelector("#"+e.element.id+"_canvasWrapper");if(f&&(f.style.width=e.element.offsetWidth-2+"px"),e.lowerCanvas.width=e.upperCanvas.width=e.element.offsetWidth-2,e.toolbarTemplate)i=e.element.querySelector("#"+e.element.id+"_toolbarArea").clientHeight;else if(e.element.querySelector("#"+e.element.id+"_toolbar")&&0===(i=e.element.querySelector("#"+e.element.id+"_toolbar").clientHeight)&&e.toolbar&&e.toolbar.length>0&&-1===e.toolbar.indexOf("Open")){m={toolbarHeight:0};e.notify("toolbar",{prop:"getToolbarHeight",value:{obj:m}}),i=m.toolbarHeight}var C=e.element.querySelector("#"+e.element.id+"_contextualToolbarArea");if(t.Browser.isDevice&&n.bool&&C&&(s=C.clientHeight),e.notify("toolbar",{prop:"setToolbarHeight",value:{height:i}}),t.Browser.isDevice?f&&(f.style.height=e.element.offsetHeight-(2*i+s)-4+"px"):f&&(f.style.height=e.element.offsetHeight-i-2+"px"),e.lowerCanvas.height=e.upperCanvas.height=parseFloat(f.style.height),this.lowerContext.filter="brightness(1) contrast(100%) hue-rotate(0deg) saturate(100%) opacity(1) blur(0px) sepia(0%) grayscale(0%) invert(0%)",e.notify("filter",{prop:"setAdjustmentValue",onPropertyChange:!1,value:{adjustmentValue:this.lowerContext.filter}}),e.canvasFilter=this.lowerContext.filter,e.initialAdjustmentValue=this.lowerContext.filter,e.clearContext(this.lowerContext),e.clearContext(this.upperContext),e.isImageLoaded){if(e.notify("shape",{prop:"applyActObj",onPropertyChange:!1,value:{isMouseDown:null}}),e.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),this.lowerContext.filter=g,e.initialAdjustmentValue=g,e.canvasFilter=this.lowerContext.filter,e.isImageLoaded&&(o.showSpinner(e.element),e.element.style.opacity="0.5"),this.lowerContext.clearRect(0,0,e.lowerCanvas.width,e.lowerCanvas.height),this.upperContext.clearRect(0,0,e.upperCanvas.width,e.upperCanvas.height),f){f.style.width=e.element.offsetWidth-2+"px",f.style.height=e.element.offsetHeight+"px";var b={toolbarHeight:0};e.notify("toolbar",{prop:"getToolbarHeight",value:{obj:b}}),t.Browser.isDevice?f.style.height=parseFloat(f.style.height)-2*b.toolbarHeight-s-4+"px":f.style.height=parseFloat(f.style.height)-b.toolbarHeight-2+"px"}e.lowerCanvas.width=e.upperCanvas.width=parseFloat(f.style.width),e.lowerCanvas.height=e.upperCanvas.height=parseFloat(f.style.height),this.lowerContext.filter=g;var m={width:0,height:0};this.calcMaxDimension(e.img.srcWidth,e.img.srcHeight,m);var y=m;if(n.bool&&0!==e.transform.cropZoomFactor?(y.width+=y.width*e.transform.cropZoomFactor,y.height+=y.height*e.transform.cropZoomFactor):e.transform.defaultZoomFactor>0&&(y.width+=y.width*e.transform.defaultZoomFactor,y.height+=y.height*e.transform.defaultZoomFactor),e.img.destLeft=(e.lowerCanvas.clientWidth-y.width)/2,e.img.destTop=(e.lowerCanvas.clientHeight-y.height+1)/2,0===e.transform.degree&&""===e.transform.currFlipState)e.transform.defaultZoomFactor>0&&(e.img.destLeft+=e.panPoint.totalPannedPoint.x,e.img.destTop+=e.panPoint.totalPannedPoint.y),e.notify("draw",{prop:"draw-image-to-canvas",value:{dimension:y}});else{e.notify("draw",{prop:"draw-image-to-canvas",value:{dimension:y}}),e.notify("draw",{prop:"updateCurrTransState",onPropertyChange:!1,value:{type:"initial",isPreventDestination:null,isRotatePan:null}});var P=this.lowerContext.filter;e.notify("draw",{prop:"drawImage",onPropertyChange:!1}),this.lowerContext.filter=P,e.notify("draw",{prop:"updateCurrTransState",onPropertyChange:!1,value:{type:"reverse",isPreventDestination:null,isRotatePan:null}})}e.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"zoom",pen:"zoom",isPreventApply:null}}),e.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.lowerContext}}),e.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.upperContext}}),e.isCircleCrop&&e.notify("crop",{prop:"cropCircle",onPropertyChange:!1,value:{context:this.lowerContext,isSave:null,isFlip:null}}),o.hideSpinner(e.element),e.element.style.opacity="1";var j={defToolbarItems:null};if(e.notify("toolbar",{prop:"getDefToolbarItems",value:{obj:j}}),j.defToolbarItems&&j.defToolbarItems.length>0&&document.getElementById(e.element.id+"_toolbar")&&(t.getComponent(e.element.id+"_toolbar","toolbar").refreshOverflow(),p&&!n.bool&&p.classList.add("e-hide")),e.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),this.upperContext.clearRect(0,0,e.upperCanvas.width,e.upperCanvas.height),r){var x=t.extend({},e.objColl[e.objColl.length-1],null,!0);e.objColl.pop(),0!==x.activePoint.width&&0!==x.activePoint.height&&(this.lowerContext.clearRect(0,0,e.lowerCanvas.width,e.lowerCanvas.height),e.notify("draw",{prop:"render-image",value:{isMouseWheel:null}}),e.objColl.push(x),e.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"zoom",pen:"zoom",isPreventApply:null}}),x=t.extend({},e.objColl[e.objColl.length-1],null,!0),e.objColl.pop(),this.lowerContext.clearRect(0,0,e.lowerCanvas.width,e.lowerCanvas.height),e.notify("draw",{prop:"render-image",value:{isMouseWheel:null}}),e.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate",obj:x}}),n.bool&&e.notify("draw",{prop:"setStraightenActObj",value:{activeObj:x}}),"rectangle"!==e.activeObj.shape&&"ellipse"!==e.activeObj.shape&&"text"!==e.activeObj.shape&&"line"!==e.activeObj.shape&&"arrow"!==e.activeObj.shape&&"path"!==e.activeObj.shape&&"image"!==e.activeObj.shape||e.notify("toolbar",{prop:"renderQAT",onPropertyChange:!1,value:{isPenEdit:null}}))}if(a.bool&&e.notify("toolbar",{prop:"renderQAT",onPropertyChange:!1,value:{isPenEdit:!0}}),e.isResize&&(e.aspectWidth=Math.ceil(e.img.destWidth),e.aspectHeight=Math.ceil(e.img.destHeight),e.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"resize",isApplyBtn:!1,isCropping:!1}}),e.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"resize",isApplyBtn:!1,isCropping:!1}})),(0!==e.transform.degree||""!==e.transform.currFlipState)&&e.transform.defaultZoomFactor>0){var w=t.extend({},e.panPoint.totalPannedPoint,null,!0),O=t.extend({},e.panPoint.totalPannedInternalPoint,null,!0),S=t.extend({},e.panPoint.totalPannedClientPoint,null,!0);this.zoomAction(.1),this.zoomAction(-.1),0===e.transform.degree?(e.img.destLeft+=w.x,e.img.destTop+=w.y,e.panPoint.totalPannedPoint=w,e.notify("draw",{prop:"updateFlipPan",value:{tempSelectionObj:null}})):(e.panPoint.totalPannedInternalPoint=O,e.panPoint.totalPannedClientPoint=S,e.panPoint.currentPannedPoint={x:0,y:0},e.isCropTab=!0,this.rotatePan(),e.isCropTab=!1)}else 0!==e.transform.degree&&e.transform.cropZoomFactor>0&&(e.transform.zoomFactor=0,e.transform.cropZoomFactor=null,e.notify("toolbar",{prop:"enable-disable-btns",onPropertyChange:!1}))}},i.prototype.calcMaxDimension=function(e,o,i,r){var a={toolbarHeight:0},n=this.parent;n.notify("toolbar",{prop:"getToolbarHeight",value:{obj:a}});var s=r?n.element.clientWidth/3:n.element.clientWidth,l=r?(n.element.clientHeight-a.toolbarHeight)/3:n.element.clientHeight-a.toolbarHeight;if(l=t.Browser.isDevice?l-a.toolbarHeight:l,t.Browser.isDevice&&n.isStraightening){var p=n.element.querySelector("#"+n.element.id+"_contextualToolbarArea");l-=p?p.clientHeight:0}r||0!==n.element.clientHeight||(l=0),t.isNullOrUndefined(r)&&(s>30&&(s-=30),l>30&&(l-=30));var h=s/e,d=l/o,c=Math.min(e,s),u=Math.min(o,l);if(h<1&&h<d?(c=e*h,u=o*h):d<1&&d<h&&(c=e*d,u=o*d),t.isNullOrUndefined(r)){var v={bool:null};n.notify("crop",{prop:"getPreventScaling",onPropertyChange:!1,value:{obj:v}}),v.bool&&n.cropObj.activeObj.activePoint&&0!==n.cropObj.activeObj.activePoint.width&&0!==n.cropObj.activeObj.activePoint.height&&(c=n.cropObj.activeObj.activePoint.width,u=n.cropObj.activeObj.activePoint.height)}return i&&(i.width=c,i.height=u),{width:c,height:u}},i.prototype.updatePanPoints=function(e,o){var i=this.parent,r=t.extend({},i.activeObj,{},!0),a=i.img.destLeft,n=i.img.destTop;t.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;(e||o)&&(s=e,l=o),i.img.destLeft+=s,i.img.destTop+=l,this.limitPan();var p={bool:null},h={isIntersect:null};i.notify("draw",{prop:"updateImgCanvasPoints",onPropertyChange:!1}),i.notify("draw",{prop:"isLinesIntersect",onPropertyChange:!1,value:{obj:h}}),i.notify("draw",{prop:"isSelOutsideImg",onPropertyChange:!1,value:{obj:p}});for(var d=0;0!==i.transform.straighten&&(h.isIntersect||p.bool)&&(d++,i.img.destLeft=a,i.img.destTop=n,0!==s&&s>0?s-=1:0!==s&&s<0&&(s+=1),0!==l&&l>0?l-=1:0!==l&&l<0&&(l+=1),(0!==s||0!==l)&&200!==d);)i.img.destLeft+=s,i.img.destTop+=l,this.limitPan(),i.notify("draw",{prop:"updateImgCanvasPoints",onPropertyChange:!1}),i.notify("draw",{prop:"isLinesIntersect",onPropertyChange:!1,value:{obj:h}}),i.notify("draw",{prop:"isSelOutsideImg",onPropertyChange:!1,value:{obj:p}});return i.activeObj=r,{x:i.img.destLeft-a,y:i.img.destTop-n}},i.prototype.resizeImage=function(e,o){var i=this.parent,r=!0,a=!0;i.allowDownScale=!1,i.img.srcLeft=0,i.img.srcTop=0,i.isAspectRatio=!0;var n=[];for(i.img.srcWidth=i.baseImgCanvas.width,i.img.srcHeight=i.baseImgCanvas.height,i.resizeSrc&&0!==i.resizeSrc.width&&0!==i.resizeSrc.height&&(i.img.srcLeft=i.resizeSrc.startX,i.img.srcTop=i.resizeSrc.startY,i.img.srcWidth=i.resizeSrc.width,i.img.srcHeight=i.resizeSrc.height);(e<i.img.destWidth||o<i.img.destHeight)&&a;)if(this.zoomAction(-.1,null,!0,!0),e>i.img.destWidth||o>i.img.destHeight)for(;e>i.img.destWidth||o>i.img.destHeight;)this.zoomAction(.0125,null,!0,!0),a=!1,n.push(i.img.destWidth);for(;(e>i.img.destWidth||o>i.img.destHeight)&&a&&r;)if(this.zoomAction(.1,null,!0,!0),e<i.img.destWidth||o<i.img.destHeight)for(;e<i.img.destWidth;)this.zoomAction(-.0125,null,!0,!0),r=!1,n.push(i.img.destWidth);for(var s=n[0],l=Math.abs(i.img.destWidth-s),p=0,h=n;p<h.length;p++){var d=h[p],c=Math.abs(e-d);c<l&&(s=d,l=c)}s<e&&r&&(this.zoomAction(-.0125,null,!0,!0),r=!1),s>e&&!r&&(this.zoomAction(.0125,null,!0,!0),r=!1),this.zoomAction(.0125,null,!0),i.allowDownScale=!0,this.zoomAction(-.0125,null,!0);var u=t.extend({},i.cropObj,{},!0),v=t.extend({},this.prevResizeCurrObj,{},!0);i.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"resize",previousObj:v,previousObjColl:v.objColl,previousPointColl:v.pointColl,previousSelPointColl:v.selPointColl,previousCropObj:u,previousText:null,currentText:null,previousFilter:null,isCircleCrop:i.isCircleCrop}}),i.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"ok"}})},i.prototype.resizeCrop=function(e,o){var i=this.parent,r=!0,a={prevObj:i.prevObj};i.cropObj=t.extend({},i.prevCropObj,{},!0),i.allowDownScale=!1,i.notify("toolbar",{prop:"getPrevObj",onPropertyChange:!1,value:{obj:a}});var n=t.extend({},a.prevObj.activeObj,{},!0);a.prevObj.activeObj=t.extend({},i.activeObj,{},!0),i.notify("draw",{prop:"setCurrentObj",onPropertyChange:!1,value:{obj:a.prevObj}}),i.objColl=t.extend([],a.prevObj.objColl,[],!0),i.pointColl=t.extend([],a.prevObj.pointColl,[],!0),i.transform.straighten=0,i.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"zoom",pen:"zoom",isPreventApply:null}}),0!==i.transform.straighten||this.isPreventSelect||i.notify("freehand-draw",{prop:"updateFHDColl",onPropertyChange:!1});var s=e,l=o,p=!1;if(o>=e&&o<=Math.ceil(i.img.destHeight)){for(;o<=Math.ceil(i.img.destHeight)&&r;)if(this.zoomAction(-.1,null,!0,!0),e>i.img.destWidth||o>i.img.destHeight)for(;e>i.img.destWidth||o>i.img.destHeight;)this.zoomAction(.0125,null,!0,!0),r=!1}else if(o<=e&&e<i.img.destWidth){for(;e<i.img.destWidth&&r;)if(this.zoomAction(-.1,null,!0,!0),e>i.img.destWidth||o>i.img.destHeight)for(;e>i.img.destWidth||o>i.img.destHeight;)this.zoomAction(.0125,null,!0,!0),r=!1}else if(o>=e&&o>=i.img.destHeight)for(;o>=i.img.destHeight&&r;)this.zoomAction(.1,null,!0,!0);else if(e>=o&&e>=i.img.destWidth){for(;e>=i.img.destWidth&&r;)this.zoomAction(.1,null,!0,!0);if(e<i.img.destWidth&&o<i.img.destHeight){for(;e<i.img.destWidth&&o<i.img.destHeight;)this.zoomAction(-.0125,null,!0,!0),r=!1;this.zoomAction(.0125,null,!0,!0)}}else if(o>i.img.destHeight&&e>i.img.destWidth){for(;o>i.img.destHeight&&e>i.img.destWidth&&r;)this.zoomAction(.1,null,!0,!0);if(e<i.img.destWidth&&o<i.img.destHeight){for(;e<i.img.destWidth&&o<i.img.destHeight;)this.zoomAction(-.0125,null,!0,!0),r=!1;this.zoomAction(.0125,null,!0,!0)}}if(this.resizeImg(n,e,o),e=s,(o=l)!==i.img.destHeight||e!==i.img.destWidth){for(;o>i.img.destHeight||e>i.img.destWidth;)this.zoomAction(.0125,null,!0,!0),p=!0;p&&(this.zoomAction(-.0125,null,!0,!0),p=!1)}if(o!==i.img.destHeight||e!==i.img.destWidth){for(;o<i.img.destHeight||e<i.img.destWidth;)this.zoomAction(-.0125,null,!0,!0),p=!0;p&&(this.zoomAction(-.0125,null,!0,!0),p=!1)}a.prevObj.activeObj=t.extend({},n,{},!0),this.zoomAction(.0125,null,!0),i.allowDownScale=!this.preventDownScale,i.isCropTab=!1,this.zoomAction(-.0125,null,!0),i.aspectWidth=e,i.aspectHeight=o},i.prototype.resizeImg=function(e,o,i){var r=this.parent,a=o/r.img.destWidth,n=i/r.img.destHeight;e.shape?(r.currSelectionPoint=e,r.notify("crop",{prop:"setInitCrop",onPropertyChange:!1,value:{bool:!0}})):r.img.srcWidth===r.baseImgCanvas.width&&r.img.srcHeight===r.baseImgCanvas.height&&(r.currSelectionPoint=null,r.notify("draw",{prop:"select",onPropertyChange:!1,value:{type:"custom",startX:null,startY:null,width:null,height:null}})),t.isNullOrUndefined(r.currSelectionPoint)?r.notify("draw",{prop:"select",onPropertyChange:!1,value:{type:"custom",startX:r.img.destLeft,startY:r.img.destTop,width:r.img.destWidth,height:r.img.destHeight}}):r.notify("draw",{prop:"select",onPropertyChange:!1,value:{type:"custom",startX:null,startY:null,width:null,height:null}}),o=r.activeObj.activePoint.width*a,i=r.activeObj.activePoint.height*n;for(var s=r.activeObj.activePoint.startX+r.activeObj.activePoint.width/2-o/2,l=r.activeObj.activePoint.startY+r.activeObj.activePoint.height/2-i/2,p=0;t.Browser.isDevice&&p<500&&(s<0||l<0||s+o>r.img.destWidth||l+i>r.img.destHeight);)p++,o-=1,i-=1,s=r.activeObj.activePoint.startX+r.activeObj.activePoint.width/2-o/2,l=r.activeObj.activePoint.startY+r.activeObj.activePoint.height/2-i/2;if(r.transform.defaultZoomFactor=0,r.notify("draw",{prop:"setResizeSelect",value:{bool:!0}}),r.notify("draw",{prop:"setIsCropSelect",value:{bool:!0}}),r.notify("draw",{prop:"select",onPropertyChange:!1,value:{type:"custom",startX:s,startY:l,width:o,height:i}}),r.notify("draw",{prop:"setResizeSelect",value:{bool:!1}}),0!==r.transform.straighten){var h={isIntersect:null,arr:null};for(r.notify("draw",{prop:"updateImgCanvasPoints",onPropertyChange:!1}),r.notify("draw",{prop:"isLinesIntersect",onPropertyChange:!1,value:{obj:h}});h.arr[0]||h.arr[1]||h.arr[2]||h.arr[3];)this.zoomAction(.0125,null,!0),r.notify("draw",{prop:"updateImgCanvasPoints",onPropertyChange:!1}),r.notify("draw",{prop:"isLinesIntersect",onPropertyChange:!1,value:{obj:h}})}r.isCropToolbar=!0,r.crop(),r.isCropToolbar=!1},i.prototype.updateResize=function(){var e=this.parent;e.prevCropObj=t.extend({},e.cropObj,{},!0);var o={currObj:{}};e.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:o}}),e.prevObj=o.currObj,e.currSelectionPoint&&e.prevCropObj.activeObj.shape&&(e.prevObj.activeObj=t.extend({},e.prevCropObj.activeObj,{},!0)),e.prevObj.objColl=t.extend([],e.objColl,[],!0),e.prevObj.pointColl=t.extend([],e.pointColl,[],!0),e.prevObj.afterCropActions=t.extend([],e.afterCropActions,[],!0);var i={selPointColl:null};e.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:i}}),e.prevObj.selPointColl=t.extend([],i.selPointColl,[],!0),e.resizeSrc={startX:e.img.srcLeft,startY:e.img.srcTop,width:e.img.srcWidth,height:e.img.srcHeight}},i.prototype.resize=function(e,o,i){var r=this.parent;r.isResize=!0,t.isNullOrUndefined(r.prevCropObj)&&t.isNullOrUndefined(r.prevObj)&&r.notify("transform",{prop:"updateResize",value:{bool:!1}});var a=r.element.querySelector("#"+r.element.id+"_aspectratio"),n=r.element.querySelector("#"+r.element.id+"_nonaspectratio");a&&n&&(r.notify("toolbar",{prop:"initResizeToolbar"}),t.Browser.isDevice&&r.notify("toolbar",{prop:"init-main-toolbar",value:{isApplyBtn:!1,isDevice:!0,isOkBtn:!0,isResize:!0}}));var s=r.element.querySelector("#"+r.element.id+"_resizeHeight"),l=""===s.value?s.placeholder:s.value,p={cancel:!1,previousWidth:Math.ceil(r.img.destWidth),previousHeight:Math.ceil(r.img.destHeight),width:Math.ceil(e),height:o&&0!==o?Math.ceil(o):i?Math.ceil(parseFloat(l)):Math.ceil(r.img.destHeight),isAspectRatio:i||!1};r.trigger("resizing",p),p.cancel?r.aspectHeight&&r.aspectWidth&&(r.aspectHeight=p.previousHeight,r.aspectWidth=p.previousWidth):this.resizeEventHandler(p)},i.prototype.resizeEventHandler=function(e){var o,i=this.parent,r=i.element.querySelector("#"+i.element.id+"_resizeWidth"),a=i.element.querySelector("#"+i.element.id+"_resizeHeight"),n=i.element.querySelector(".e-ie-toolbar-e-resize-height-input .e-textbox"),s=i.element.querySelector(".e-ie-toolbar-e-resize-width-input .e-textbox");if(e.isAspectRatio)if(null!=this.resizedImgAngle&&this.resizedImgAngle===i.transform.degree||(this.resizedImgAngle=i.transform.degree,o=!0),o){i.notify("transform",{prop:"resizeImage",value:{width:e.width,height:0}});var l=i.img.destWidth,p=i.img.destHeight,h=void 0;if(h=parseFloat(""===r.value?r.placeholder:r.value),a){c=(d=h/(l/p))%1>=.5||d%1<=-.5?Math.round(d):d<0?Math.ceil(d):Math.floor(d);if(t.getComponent(a,"numerictextbox").value=c,a.value=c.toString()+" px",i.aspectHeight=c,r&&""===r.value){v=(d=(u=parseFloat(""===a.value?a.placeholder:a.value))/(p/l))%1>=.5||d%1<=-.5?Math.round(d):d<0?Math.ceil(d):Math.floor(d);t.getComponent(r,"numerictextbox").value=v,r.value=v.toString()+" px",i.aspectWidth=v}}else if(n){var d=h/(l/p),c=d%1>=.5||d%1<=-.5?Math.round(d):d<0?Math.ceil(d):Math.floor(d);if(n.value=c.toString(),i.aspectHeight=c,s&&""===s.value){var u=parseFloat(""===n.value?n.placeholder:n.value),v=(d=u/(p/l))%1>=.5||d%1<=-.5?Math.round(d):d<0?Math.ceil(d):Math.floor(d);s.value=v.toString(),i.aspectWidth=v}}}else i.notify("transform",{prop:"resizeImage",value:{width:e.width,height:null}});else null!==this.resizedImgAngle&&this.resizedImgAngle!==i.transform.degree&&(this.resizedImgAngle=i.transform.degree,o=!0),o?(i.notify("transform",{prop:"setPreventDownScale",value:{bool:!0}}),i.notify("transform",{prop:"resizeCrop",value:{width:e.width,height:e.height}}),i.notify("undo-redo",{prop:"setPreventUR",value:{bool:!0}}),i.okBtn(null,!0),i.notify("undo-redo",{prop:"setPreventUR",value:{bool:!1}}),i.resizeSrc={startX:i.img.srcLeft,startY:i.img.srcTop,width:i.img.srcWidth,height:i.img.srcHeight},i.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"resize",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}}),i.notify("transform",{prop:"setPreventDownScale",value:{bool:!1}}),i.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"resize",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}})):i.notify("transform",{prop:"resizeCrop",value:{width:e.width,height:e.height}});this.resizedImgAngle=i.transform.degree},i.prototype.straightenImage=function(e){var t=this.parent;t.toolbar&&0===t.toolbar.length&&t.notify("draw",{prop:"select",onPropertyChange:!1,value:{type:"custom",startX:null,startY:null,width:null,height:null}}),t.notify("toolbar",{prop:"performCropTransformClick",value:{shape:null}}),t.setStraighten(e),t.okBtn()},i}(),C=function(){function e(e){this.undoRedoStep=0,this.undoRedoColl=[],this.appliedUndoRedoColl=[],this.tempUndoRedoColl=[],this.tempUndoRedoStep=0,this.isPreventing=!1,this.parent=e,this.addEventListener()}return e.prototype.destroy=function(){this.parent.isDestroyed||this.removeEventListener()},e.prototype.addEventListener=function(){this.parent.on("undo-redo",this.undoRedo,this),this.parent.on("destroyed",this.destroy,this)},e.prototype.removeEventListener=function(){this.parent.off("undo-redo",this.undoRedo),this.parent.off("destroyed",this.destroy)},e.prototype.initializeUrPvtProp=function(){this.parent.lowerCanvas&&(this.lowerContext=this.parent.lowerCanvas.getContext("2d")),this.parent.upperCanvas&&(this.upperContext=this.parent.upperCanvas.getContext("2d"))},e.prototype.undoRedo=function(e){switch(this.initializeUrPvtProp(),e.prop){case"updateUndoRedoColl":this.updateUrc(e.value.operation,e.value.previousObj,e.value.previousObjColl,e.value.previousPointColl,e.value.previousSelPointColl,e.value.previousCropObj,e.value.previousText,e.value.currentText,e.value.previousFilter,e.value.isCircleCrop);break;case"refreshUrc":this.refreshUrc(e.value.bool);break;case"updateCurrUrc":this.updateCurrUrc(e.value.type,e.value.isCancel);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(e.value.objColl,e.value.operation);break;case"updateUndoRedo":this.updateUndoRedo(e.value?e.value.operation:null);break;case"getAppliedUndoRedoColl":e.value.obj.appliedUndoRedoColl=this.appliedUndoRedoColl;break;case"getUndoRedoStep":e.value.obj.undoRedoStep=this.undoRedoStep;break;case"setUndoRedoStep":this.undoRedoStep=e.value.step;break;case"undoDefault":this.undoDefault(e.value.obj);break;case"setPreventUR":this.isPreventing=e.value.bool;break;case"updateUndoRedoStack":e.value&&e.value.isPenDraw?this.updateUndoRedoStack(e.value.isPenDraw):this.updateUndoRedoStack();break;case"reset":this.reset()}},e.prototype.getModuleName=function(){return"undo-redo"},e.prototype.reset=function(){this.tempCurrSelPoint=null,this.undoRedoStep=0,this.undoRedoColl=[],this.appliedUndoRedoColl=[],this.tempActObj=null,this.tempUndoRedoColl=[],this.tempUndoRedoStep=0,this.isPreventing=!1},e.prototype.refreshUrc=function(e){var o=this.parent;(e=e||!1)&&(o.notify("toolbar",{prop:"setEnableDisableUndoRedo",value:{isPrevent:!0}}),this.tempUndoRedoColl=t.extend([],this.appliedUndoRedoColl,[],!0),this.tempUndoRedoStep=this.undoRedoStep),o.notify("toolbar",{prop:"setEnableDisableUndoRedo",value:{isPrevent:!1}}),this.undoRedoColl=this.undoRedoColl.slice(0,this.undoRedoStep),this.appliedUndoRedoColl=this.appliedUndoRedoColl.slice(0,this.undoRedoStep),o.isUndoRedo=o.currObjType.isUndoAction=!1,o.notify("toolbar",{prop:"enable-disable-btns"})},e.prototype.updateCurrUrc=function(e,o){var i=this.parent;if(!(i.isResize||this.isPreventing||i.noPushUndo)){if(i.notify("toolbar",{prop:"setEnableDisableUndoRedo",value:{isPrevent:!1}}),"ok"===e){i.notify("draw",{prop:"setShapeTextInsert",onPropertyChange:!1,value:{bool:!1}});var r=this.tempUndoRedoColl.length>0?t.extend([],this.tempUndoRedoColl,[],!0):t.extend([],this.undoRedoColl,[],!0),a=this.undoRedoColl[this.undoRedoColl.length-1],n=this.appliedUndoRedoColl[this.appliedUndoRedoColl.length-1],s=a?t.extend({},a.previousObj,{},!0):null;if(t.isNullOrUndefined(n)?this.undoRedoColl[0]&&(a.previousCropObj=r[0].previousCropObj,a.previousObj=r[0].previousObj,a.previousObjColl=r[0].previousObjColl,a.previousPointColl=r[0].previousPointColl,a.previousText=r[0].previousText):"imageHFlip"!==a.operation&&"imageVFlip"!==a.operation&&(a.previousCropObj=n.currentCropObj,a.previousObj=n.currentObj,a.previousObjColl=n.currentObjColl,a.previousPointColl=n.currentPointColl,a.previousText=n.currentText,"frame"===a.operation&&a.previousObj&&s&&(a.previousObj.defaultZoom=s.defaultZoom,a.previousObj.zoomFactor=s.zoomFactor,a.previousObj.cropZoom=s.cropZoom)),a){if("imageHFlip"!==a.operation&&"imageVFlip"!==a.operation){var l=this.getZeroZoomObjPointValue(a.currentObjColl,a.currentPointColl);a.currentObjColl=l.obj,a.currentPointColl=l.point;var p={adjustmentLevel:null};i.notify("filter",{prop:"getAdjustmentLevel",onPropertyChange:!1,value:{obj:p}}),a.currentObj.adjustmentLevel=t.extend({},p.adjustmentLevel,{},!0),i.notify("filter",{prop:"setTempAdjVal"}),a.currentObj.currentFilter=i.currentFilter}this.appliedUndoRedoColl.push(a)}this.tempUndoRedoColl=[],this.tempUndoRedoStep=0}else this.tempUndoRedoColl.length>0&&(this.appliedUndoRedoColl=t.extend([],this.tempUndoRedoColl,[],!0),this.undoRedoStep=this.tempUndoRedoStep,this.tempUndoRedoColl=[],this.tempUndoRedoStep=0);var h=this.appliedUndoRedoColl[this.appliedUndoRedoColl.length-1],d=this.appliedUndoRedoColl[this.appliedUndoRedoColl.length-2];this.appliedUndoRedoColl.length>16?this.appliedUndoRedoColl.splice(0,1):!o&&h&&d&&(("shapeTransform"===h.operation&&"shapeTransform"===d.operation||"shapeInsert"===h.operation&&"shapeInsert"===d.operation)&&JSON.stringify(h.currentObjColl)===JSON.stringify(d.currentObjColl)||"freehand-draw"===h.operation&&"freehand-draw"===d.operation&&JSON.stringify(h.currentPointColl)===JSON.stringify(d.currentPointColl)||"freehanddrawCustomized"===h.operation&&"freehanddrawCustomized"===d.operation&&JSON.stringify(h.currentPointColl)===JSON.stringify(d.currentPointColl))&&this.appliedUndoRedoColl.splice(this.appliedUndoRedoColl.length-1,1),this.undoRedoColl=[],this.undoRedoColl=t.extend([],this.appliedUndoRedoColl,[],!0),"ok"===e&&(this.undoRedoStep=this.undoRedoColl.length,i.notify("toolbar",{prop:"enable-disable-btns"})),i.transform.zoomFactor>0&&(i.togglePan=!0,i.notify("selection",{prop:"setDragCanvas",value:{bool:!0}}))}},e.prototype.cancelCropSelection=function(){var e,o=this.parent,i=!1;o.activeObj.shape&&(e=o.activeObj.shape.split("-")),(o.currObjType.isCustomCrop||e&&"crop"===e[0])&&(i=!0),i&&o.notify("draw",{prop:"performCancel",value:{isContextualToolbar:null}}),0===this.tempUndoRedoColl.length&&0===this.tempUndoRedoStep||(this.appliedUndoRedoColl=t.extend([],this.tempUndoRedoColl,[],!0),this.undoRedoColl=t.extend([],this.tempUndoRedoColl,[],!0),this.undoRedoStep=this.tempUndoRedoStep,this.tempUndoRedoColl=[],this.tempUndoRedoStep=0,o.notify("toolbar",{prop:"setEnableDisableUndoRedo",value:{isPrevent:!1}}))},e.prototype.refreshToolbarActions=function(){var e=this.parent;e.activeObj.shape?(e.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"shapes",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}}),e.notify("toolbar",{prop:"update-toolbar-items",onPropertyChange:!1})):e.notify("toolbar",{prop:"refresh-main-toolbar",onPropertyChange:!1})},e.prototype.applyCurrentChanges=function(){var e=this.parent;e.currObjType.isFiltered=!1,0===e.transform.zoomFactor&&(e.togglePan=!1,e.notify("selection",{prop:"setDragCanvas",value:{bool:!1}})),e.element.querySelector(".e-contextual-toolbar-wrapper")&&e.element.querySelector(".e-contextual-toolbar-wrapper").classList.add("e-hide"),e.togglePen&&(e.togglePen=!1,e.upperCanvas.style.cursor=e.cursor="default",this.upperContext.clearRect(0,0,e.upperCanvas.width,e.upperCanvas.height)),this.appliedUndoRedoColl.length>0&&(this.undoRedoColl=t.extend([],this.appliedUndoRedoColl,[],!0))},e.prototype.callUndo=function(){this.applyCurrentChanges(),this.undo()},e.prototype.callRedo=function(){this.applyCurrentChanges(),this.redo()},e.prototype.undo=function(){var e=this.parent;if(this.cancelCropSelection(),e.notify("draw",{prop:"resetFrameZoom",onPropertyChange:!1,value:{isOk:!1}}),!e.disabled&&e.isImageLoaded&&this.undoRedoStep>0){this.refreshToolbarActions(),e.activeObj.activePoint&&0!==e.activeObj.activePoint.width&&(this.tempActObj=e.activeObj),e.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),this.undoRedoStep--,e.notify("toolbar",{prop:"enable-disable-btns"}),e.element.querySelector(".e-contextual-toolbar-wrapper")&&e.element.querySelector(".e-contextual-toolbar-wrapper").classList.add("e-hide"),e.isUndoRedo=!0;var o=this.undoRedoColl[this.undoRedoStep];this.undoRedoColl.length===this.undoRedoStep?e.currObjType.isUndoAction=!1:e.currObjType.isUndoAction=!0,"textAreaCustomization"===o.operation||"block"!==e.textArea.style.display&&"inline-block"!==e.textArea.style.display||(e.textArea.style.display="none"),e.notify("draw",{prop:"setCancelAction",onPropertyChange:!1,value:{bool:!0}});switch(e.cropObj=t.extend({},o.previousCropObj,{},!0),e.afterCropActions=o.previousObj.afterCropActions,this.lowerContext.filter=o.previousObj.filter,e.notify("filter",{prop:"setAdjustmentLevel",onPropertyChange:!1,value:{adjustmentLevel:o.previousObj.adjustmentLevel}}),e.notify("filter",{prop:"setTempAdjVal"}),e.currentFilter=o.previousObj.currentFilter,e.notify("filter",{prop:"setTempFilVal"}),e.canvasFilter=this.lowerContext.filter,e.initialAdjustmentValue=this.lowerContext.filter,e.notify("filter",{prop:"setBevelFilter",onPropertyChange:!1,value:{bevelFilter:this.lowerContext.filter}}),o.operation){case"shapeTransform":case"brightness":case"contrast":case"hue":case"saturation":case"opacity":case"blur":case"exposure":case"default":case"chrome":case"cold":case"warm":case"grayscale":case"blackandwhite":case"sepia":case"invert":case"sharpen":case"imageRotate":case"shapeInsert":this.shapeTransform(o.previousObjColl,o.previousPointColl);break;case"freehanddraw":case"freehand-draw":this.updateFreehandDraw(o.previousPointColl,o.previousSelPointColl),e.notify("freehand-draw",{prop:"setCurrentFreehandDrawIndex",value:{value:e.pointColl.length}});break;case"freehanddrawCustomized":this.updateFreehandDrawCustomized(o.previousObjColl,o.previousPointColl);break;case"deleteFreehandDrawing":case"deleteObj":this.updateDelete(o.operation,o.previousObjColl,o.previousPointColl,o.previousSelPointColl);break;case"textAreaCustomization":this.shapeTransform(o.previousObjColl,o.previousPointColl),this.updateTextAreaCustomization(void 0,o.previousObjColl);break;case"text":this.updateText(o.previousObjColl,!0);break;case"frame":e.transform.zoomFactor=e.transform.defaultZoomFactor=o.previousObj.defaultZoom,e.setProperties({zoomSettings:{zoomFactor:o.previousObj.zoomFactor}},!0),e.notify("transform",{prop:"setPreviousZoomValue",onPropertyChange:!1,value:{previousZoomValue:e.zoomSettings.zoomFactor}}),t.extend(e.frameObj,o.previousObj.frameObj),e.notify("draw",{prop:"render-image",value:{isMouseWheel:!0,isPreventClearRect:null,isFrame:!0}});break;case"imageHFlip":this.imageFlip("horizontal",o.previousObjColl);break;case"imageVFlip":this.imageFlip("vertical",o.previousObjColl);break;default:this.undoDefault(o,!0),e.notify("filter",{prop:"set-adjustment",value:{operation:o.operation}}),e.notify("filter",{prop:"update-filter",value:{operation:o.operation,filter:o.filter}})}"crop"===o.operation?(o.previousObj.currSelectionPoint&&(e.currSelectionPoint=t.extend({},o.previousObj.currSelectionPoint,{},!0),e.currSelectionPoint&&t.isNullOrUndefined(e.currSelectionPoint.shape)&&(e.currSelectionPoint=null)),e.updateCropTransformItems(),e.notify("draw",{prop:"select",onPropertyChange:!1,value:{type:"custom",startX:null,startY:null,width:null,height:null}}),e.isCircleCrop&&(e.isCircleCrop=!1,this.tempCurrSelPoint=t.extend({},e.currSelectionPoint,{},!0),e.currSelectionPoint=null),e.notify("draw",{prop:"performCancel",value:{isContextualToolbar:null,isUndoRedo:!0}}),e.currObjType.isActiveObj=!1,0!==e.transform.straighten&&e.notify("draw",{prop:"setStraightenActObj",value:{activeObj:null}})):"resize"===o.operation&&e.cropObj&&e.cropObj.activeObj&&(e.currSelectionPoint=t.extend({},e.cropObj.activeObj,{},!0)),this.undoRedoColl[this.undoRedoStep-1]&&this.undoRedoColl[this.undoRedoStep-1].isCircleCrop&&(e.isCircleCrop=!0,e.notify("crop",{prop:"cropCircle",onPropertyChange:!1,value:{context:this.lowerContext,isSave:null,isFlip:null}})),this.endUndoRedo(o.operation,!0)}},e.prototype.redo=function(){var e=this.parent;if(this.cancelCropSelection(),e.notify("draw",{prop:"resetFrameZoom",onPropertyChange:!1,value:{isOk:!1}}),!e.disabled&&e.isImageLoaded&&this.undoRedoStep<this.appliedUndoRedoColl.length){this.refreshToolbarActions(),this.undoRedoStep++,e.notify("toolbar",{prop:"enable-disable-btns"}),e.isUndoRedo=!0;var o=this.undoRedoColl[this.undoRedoStep-1];this.undoRedoColl.length===this.undoRedoStep?e.currObjType.isUndoAction=!1:e.currObjType.isUndoAction=!0,"textAreaCustomization"===o.operation||"block"!==e.textArea.style.display&&"inline-block"!==e.textArea.style.display||(e.textArea.style.display="none"),e.notify("draw",{prop:"setCancelAction",onPropertyChange:!1,value:{bool:!0}}),e.cropObj=t.extend({},o.currentCropObj,{},!0),e.afterCropActions=o.currentObj.afterCropActions,this.lowerContext.filter=o.currentObj.filter,e.element.querySelector(".e-contextual-toolbar-wrapper")&&e.element.querySelector(".e-contextual-toolbar-wrapper").classList.add("e-hide"),e.notify("filter",{prop:"setAdjustmentLevel",onPropertyChange:!1,value:{adjustmentLevel:o.currentObj.adjustmentLevel}}),e.notify("filter",{prop:"setTempAdjVal"}),e.currentFilter=o.currentObj.currentFilter,e.notify("filter",{prop:"setTempFilVal"}),e.canvasFilter=this.lowerContext.filter,e.initialAdjustmentValue=this.lowerContext.filter,e.notify("filter",{prop:"setBevelFilter",onPropertyChange:!1,value:{bevelFilter:this.lowerContext.filter}});var i=void 0;switch(o.operation){case"shapeTransform":case"brightness":case"contrast":case"hue":case"saturation":case"opacity":case"blur":case"exposure":case"default":case"chrome":case"cold":case"warm":case"grayscale":case"blackandwhite":case"sepia":case"invert":case"sharpen":case"imageRotate":case"shapeInsert":this.shapeTransform(o.currentObjColl,o.currentPointColl);break;case"freehanddraw":case"freehand-draw":this.updateFreehandDraw(o.currentPointColl,o.currentSelPointColl),e.notify("freehand-draw",{prop:"setCurrentFreehandDrawIndex",value:{value:e.pointColl.length}});break;case"freehanddrawCustomized":this.updateFreehandDrawCustomized(o.currentObjColl,o.currentPointColl);break;case"deleteFreehandDrawing":case"deleteObj":this.updateDelete(o.operation,o.currentObjColl,o.currentPointColl,o.currentSelPointColl);break;case"textAreaCustomization":this.shapeTransform(o.currentObjColl,o.currentPointColl),this.updateTextAreaCustomization(i,o.currentObjColl);break;case"text":this.updateText(o.currentObjColl,!1);break;case"frame":t.extend(e.frameObj,o.currentObj.frameObj),e.notify("draw",{prop:"render-image",value:{isMouseWheel:!0,isPreventClearRect:null,isFrame:!0}});break;case"imageHFlip":this.imageFlip("horizontal",o.currentObjColl);break;case"imageVFlip":this.imageFlip("vertical",o.currentObjColl);break;default:e.objColl=[],e.pointColl=[],e.freehandCounter=0,e.notify("freehand-draw",{prop:"setSelPointColl",onPropertyChange:!1,value:{obj:{selPointColl:[]}}}),e.notify("draw",{prop:"setCurrentObj",onPropertyChange:!1,value:{obj:o.currentObj,isUndoRedo:!0}}),e.img.destLeft=o.currentObj.destPoints.startX,e.img.destTop=o.currentObj.destPoints.startY,i=t.extend({},e.activeObj,{},!0),e.objColl=t.extend([],o.currentObjColl,[],!0),e.pointColl=t.extend([],o.currentPointColl,[],!0),e.freehandCounter=e.pointColl.length,e.notify("freehand-draw",{prop:"setSelPointColl",onPropertyChange:!1,value:{obj:{selPointColl:t.extend([],o.currentSelPointColl,[],!0)}}}),e.transform.straighten=0,this.lowerContext.filter="none",e.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"zoom",pen:"zoom",isPreventApply:null}}),this.lowerContext.filter=o.currentObj.filter,e.prevStraightenedDegree=e.transform.straighten,e.activeObj=i,this.upperContext.clearRect(0,0,e.upperCanvas.width,e.upperCanvas.height),0!==e.activeObj.activePoint.width&&0!==e.activeObj.activePoint.height&&e.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate"}}),e.notify("filter",{prop:"set-adjustment",value:{operation:o.operation}}),e.notify("filter",{prop:"update-filter",value:{operation:o.operation}})}"crop"===o.operation&&o.isCircleCrop&&(e.isCircleCrop=!0,e.currSelectionPoint=t.extend({},this.tempCurrSelPoint,{},!0),this.tempCurrSelPoint=null),"crop"!==o.operation||o.isCircleCrop||(e.isCircleCrop=!1),"crop"===o.operation&&o.currentObj.currSelectionPoint&&(e.currSelectionPoint=t.extend({},o.currentObj.currSelectionPoint,{},!0),e.notify("draw",{prop:"setStraightenActObj",value:{activeObj:e.currSelectionPoint}})),e.currSelectionPoint&&t.isNullOrUndefined(e.currSelectionPoint.shape)&&(e.currSelectionPoint=null),"resize"===o.operation&&e.cropObj&&e.cropObj.activeObj&&(e.currSelectionPoint=t.extend({},e.cropObj.activeObj,{},!0)),this.endUndoRedo(o.operation,!1)}},e.prototype.imageFlip=function(e,o){var i=this.parent;this.shapeTransform(o,null),i.activeObj=t.extend({},i.objColl[i.objColl.length-1],{},!0);var r=i.activeObj,a=r.shape,n=r.isHorImageFlip,s=r.isVerImageFlip;i.objColl.pop(),a&&"image"===a?("horizontal"===e?t.isNullOrUndefined(n)&&s?(i.activeObj.isHorImageFlip=!0,i.activeObj.isVerImageFlip=null,i.horizontalFlip(this.upperContext,!0)):(t.isNullOrUndefined(n)||!n?i.activeObj.isHorImageFlip=!0:i.activeObj.isHorImageFlip=null,i.horizontalFlip(this.upperContext,!0)):"vertical"===e&&(t.isNullOrUndefined(s)&&n?(i.activeObj.isVerImageFlip=!0,i.activeObj.isHorImageFlip=null,i.verticalFlip(this.upperContext,!0)):(t.isNullOrUndefined(s)||!s?i.activeObj.isVerImageFlip=!0:i.activeObj.isVerImageFlip=null,i.verticalFlip(this.upperContext,!0))),i.notify("shape",{prop:"applyActObj",onPropertyChange:!1,value:{isMouseDown:!0}})):i.notify("draw",{prop:"render-image",value:{isMouseWheel:!0}})},e.prototype.shapeTransform=function(e,o){var i=this.parent;i.objColl=t.extend([],e,[],!0),o&&(i.pointColl=t.extend([],o,[],!0),i.freehandCounter=i.pointColl.length),i.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"zoom",pen:"zoom",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})},e.prototype.updateFreehandDraw=function(e,t){var o=this.parent;o.pointColl=e,o.notify("freehand-draw",{prop:"setSelPointColl",onPropertyChange:!1,value:{obj:{selPointColl:t}}}),o.freehandCounter=o.pointColl.length,o.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"zoom",pen:"zoom",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})},e.prototype.updateFreehandDrawCustomized=function(e,o){var i=this.parent;i.objColl=t.extend([],e,[],!0),i.pointColl=o,i.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"zoom",pen:"zoom",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})},e.prototype.updateDelete=function(e,t,o,i){var r=this.parent;"deleteFreehandDrawing"===e?(r.pointColl=o,r.freehandCounter=r.pointColl.length,r.notify("freehand-draw",{prop:"setSelPointColl",onPropertyChange:!1,value:{obj:{selPointColl:i}}}),r.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"zoom",pen:"zoom",isPreventApply:null}})):"deleteObj"===e&&(r.objColl=t,r.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"zoom",pen:"zoom",isPreventApply:null}})),this.lowerContext.clearRect(0,0,r.lowerCanvas.width,r.lowerCanvas.height),this.upperContext.clearRect(0,0,r.upperCanvas.width,r.upperCanvas.height),r.isUndoRedo=!0,r.notify("draw",{prop:"redrawImgWithObj",onPropertyChange:!1})},e.prototype.updateTextAreaCustomization=function(e,o){var i=this.parent;i.objColl=t.extend([],o,[],!0),i.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"zoom",pen:"zoom",isPreventApply:null}}),this.lowerContext.clearRect(0,0,i.lowerCanvas.width,i.lowerCanvas.height),i.isUndoRedo=!0,i.notify("draw",{prop:"redrawImgWithObj",onPropertyChange:!1});for(var r=0,a=o.length;r<a;r++){if(!this.tempActObj){e=t.extend({},o[o.length-1],{},!0),i.objColl.splice(r,1);break}if(this.tempActObj.currIndex===o[r].currIndex){e=t.extend({},o[r],{},!0),i.objColl.splice(r,1);break}}e&&this.updateTextBox(e),"block"!==i.textArea.style.display&&"inline-block"!==i.textArea.style.display||i.notify("shape",{prop:"redrawActObj",onPropertyChange:!1,value:{x:null,y:null,isMouseDown:null}})},e.prototype.updateText=function(e,o){var i=this.parent;if(this.tempActObj&&(i.activeObj=t.extend({},this.tempActObj,{},!0)),0===e.length&&1===i.objColl.length)this.tempActObj=t.extend({},i.objColl[0],{},!0);else for(var r=0,a=i.objColl.length;r<a;r++){if(i.objColl[r]&&t.isNullOrUndefined(e[r])){this.tempActObj=t.extend({},i.objColl[r],{},!0);break}if(e[r].currIndex!==i.objColl[r].currIndex){this.tempActObj=t.extend({},i.objColl[r],{},!0);break}}o&&(i.activeObj=t.extend({},this.tempActObj,{},!0)),i.objColl=t.extend([],e,[],!0),i.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"zoom",pen:"zoom",isPreventApply:!0}}),this.upperContext.clearRect(0,0,i.upperCanvas.width,i.upperCanvas.height),this.lowerContext.clearRect(0,0,i.lowerCanvas.width,i.lowerCanvas.height),i.isUndoRedo=!0,i.notify("draw",{prop:"redrawImgWithObj",onPropertyChange:!1}),i.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1})},e.prototype.updateTextBox=function(e){var o=this.parent;this.upperContext.clearRect(0,0,o.lowerCanvas.width,o.lowerCanvas.height),this.lowerContext.clearRect(0,0,o.lowerCanvas.width,o.lowerCanvas.height),o.notify("draw",{prop:"redrawImgWithObj",onPropertyChange:!1}),o.notify("toolbar",{prop:"destroy-qa-toolbar",onPropertyChange:!1});var i=o.textArea;i.style.display="block",i.style.fontFamily=e.textSettings.fontFamily,i.style.fontSize=e.textSettings.fontSize+"px",i.style.color=e.strokeSettings.strokeColor,i.style.fontWeight=e.textSettings.bold?"bold":"normal",i.style.fontStyle=e.textSettings.italic?"italic":"normal",i.style.border="2px solid "+o.themeColl[o.theme].primaryColor,i.value=e.keyHistory,o.activeObj=t.extend({},e,{},!0),o.notify("shape",{prop:"updateFontStyles",onPropertyChange:!1,value:{isTextBox:null}}),o.textArea.style.width=o.activeObj.activePoint.width+"px"},e.prototype.undoDefault=function(e,o){this.lowerContext.filter=e.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:e.previousObj,isUndoRedo:o}}),i.prevStraightenedDegree=i.transform.straighten,this.upperContext.clearRect(0,0,i.upperCanvas.width,i.upperCanvas.height),i.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),i.img.destLeft=e.previousObj.destPoints.startX,i.img.destTop=e.previousObj.destPoints.startY;var r=t.extend({},i.activeObj,{},!0);i.objColl=t.extend([],e.previousObjColl,[],!0),i.pointColl=t.extend([],e.previousPointColl,[],!0),i.freehandCounter=i.pointColl.length,i.notify("freehand-draw",{prop:"setSelPointColl",onPropertyChange:!1,value:{obj:{selPointColl:t.extend([],e.previousSelPointColl,[],!0)}}}),i.transform.straighten=0,this.lowerContext.filter="none",i.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"zoom",pen:"zoom",isPreventApply:null}}),this.lowerContext.filter=e.previousObj.filter,i.activeObj=r,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"}})},e.prototype.endUndoRedo=function(e,t){var o=this.parent,i={type:"none",color:"#fff",size:20,inset:20,offset:20,radius:0,amount:1,border:"solid",gradientColor:""};(o.currSelectionPoint&&"crop-circle"===o.currSelectionPoint.shape||o.isCircleCrop)&&JSON.stringify(o.frameObj)!==JSON.stringify(i)&&o.notify("draw",{prop:"render-image",value:{isMouseWheel:!0}}),o.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.lowerContext}}),o.isCircleCrop&&(t&&"crop"!==e||!t)&&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}}),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"),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},e.prototype.updateUrc=function(e,o,i,r,a,n,s,l,p,h){var d=this.parent;if(!d.isResize&&!this.isPreventing){var c={isInitialLoaded:!1};if(d.currObjType.isUndoAction&&this.refreshUrc(!0),d.notify("draw",{prop:"isInitialLoaded",onPropertyChange:!1,value:{object:c}}),!c.isInitialLoaded&&d.allowUndoRedo){var u={currObj:{}};d.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:u}});var v=u.currObj;v.objColl=t.extend([],d.objColl,[],!0),v.pointColl=t.extend([],d.pointColl,[],!0),v.afterCropActions=t.extend([],d.afterCropActions,[],!0);var g={selPointColl:null};if(d.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:g}}),v.selPointColl=t.extend([],g.selPointColl,[],!0),"crop"===e)v.currSelectionPoint=t.extend({},d.currSelectionPoint,{},!0);else if("frame"===e)o.destPoints={startX:d.frameDestPoints.destLeft,startY:d.frameDestPoints.destTop,width:d.frameDestPoints.destWidth,height:d.frameDestPoints.destHeight},v.destPoints={startX:d.frameDestPoints.destLeft,startY:d.frameDestPoints.destTop,width:d.frameDestPoints.destWidth,height:d.frameDestPoints.destHeight},t.isNullOrUndefined(d.tempFrameZoomLevel)||(o.defaultZoom=v.defaultZoom=d.tempFrameZoomLevel);else if(("imageHFlip"===e||"imageVFlip"===e)&&this.appliedUndoRedoColl.length>0){var f=i[i.length-1].currIndex;if(i=this.appliedUndoRedoColl[this.appliedUndoRedoColl.length-1].currentObjColl,f)for(var C=0,b=i.length;C<b;C++)if(i[C].currIndex===f){var m=t.extend({},i[C],{},!0);i.splice(C,1),i.push(m);break}}this.undoRedoColl.push({operation:e,previousObj:o,currentObj:v,previousObjColl:i,currentObjColl:v.objColl,previousPointColl:r,currentPointColl:v.pointColl,previousSelPointColl:a,currentSelPointColl:v.selPointColl,previousCropObj:n,currentCropObj:t.extend({},d.cropObj,{},!0),previousText:s,currentText:l,filter:p,isCircleCrop:h}),d.notify("toolbar",{prop:"enable-disable-btns",onPropertyChange:!1})}}},e.prototype.updateUrObj=function(e,o){var i=this.parent;if(i.allowUndoRedo){i.currObjType.isUndoAction&&!i.isShapeDrawing&&this.refreshUrc(!0),t.isNullOrUndefined(i.activeObj.imageRatio)&&i.notify("shape",{prop:"updImgRatioForActObj",onPropertyChange:!1}),i.objColl.push(i.activeObj);var r=t.extend({},i.cropObj,{},!0),a={currObj:{}};i.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:a}});var n=a.currObj;n.objColl=t.extend([],i.objColl,[],!0),n.pointColl=t.extend([],i.pointColl,[],!0),n.afterCropActions=t.extend([],i.afterCropActions,[],!0);var s={selPointColl:null};i.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:s}}),n.selPointColl=t.extend([],s.selPointColl,[],!0);var l=o||"shapeTransform";this.undoRedoColl.push({operation:l,previousObj:n,currentObj:n,previousObjColl:e,currentObjColl:n.objColl,previousPointColl:n.pointColl,currentPointColl:n.pointColl,previousSelPointColl:n.selPointColl,currentSelPointColl:n.selPointColl,previousCropObj:r,currentCropObj:r}),i.notify("selection",{prop:"redrawShape",onPropertyChange:!1,value:{obj:i.objColl[i.objColl.length-1]}})}},e.prototype.updateUndoRedo=function(e){var o=this.parent,i=t.extend({},o.cropObj,{},!0),r={currObj:{}};o.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:r}});var a=r.currObj;a.objColl=t.extend([],o.objColl,[],!0),a.pointColl=t.extend([],o.pointColl,[],!0),a.afterCropActions=t.extend([],o.afterCropActions,[],!0);var n={selPointColl:null};o.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:n}}),a.selPointColl=t.extend([],n.selPointColl,[],!0),t.isNullOrUndefined(o.activeObj.imageRatio)&&o.notify("shape",{prop:"updImgRatioForActObj",onPropertyChange:!1}),o.objColl.push(o.activeObj);var s=e||"shapeTransform";this.updateUrc(s,a,a.objColl,a.pointColl,a.selPointColl,i),o.objColl.pop(),o.notify("shape",{prop:"applyActObj",onPropertyChange:!1,value:{isMouseDown:null}}),o.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),o.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"shapes",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}}),o.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"main",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}})},e.prototype.getZeroZoomObjPointValue=function(e,o){var i=this.parent;this.updateObjColl();var r={currObj:{}};i.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:r}});var a=r.currObj;a.objColl=t.extend([],i.objColl,[],!0),a.pointColl=t.extend([],i.pointColl,[],!0),a.afterCropActions=t.extend([],i.afterCropActions,[],!0);var n={selPointColl:null};i.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:n}}),a.selPointColl=t.extend([],n.selPointColl,[],!0);var s={cropDimension:null};i.notify("transform",{prop:"getCropDimension",onPropertyChange:!1,value:{obj:s}});var l=t.extend([],i.objColl,[],!0),p=t.extend([],i.pointColl,[],!0),h={arrowDimension:null};this.parent.notify("draw",{prop:"getArrowDimension",onPropertyChange:!1,value:{obj:h}});var d=t.extend({},h.arrowDimension,{},!0);if(i.transform.zoomFactor>0&&(e.length>0||o.length>0)){if(e.length>0)for(var c=0;c<e.length;c++)e[c].currIndex||(e[c].currIndex="shape_"+(c+1));i.objColl=e,i.pointColl=o;var u=i.isUndoRedo,v=i.isCropTab;if(0!==i.transform.zoomFactor){i.isUndoRedo=!0,i.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"zoom",pen:"zoom",isPreventApply:!0}}),i.notify("freehand-draw",{prop:"updateFHDColl",onPropertyChange:!1}),i.isCropTab=!0;var g=t.extend({},i.zoomSettings,null,!0);i.transform.zoomFactor>0?i.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:-i.transform.zoomFactor,zoomPoint:null,isResize:null}}):i.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:Math.abs(i.transform.zoomFactor),zoomPoint:null,isResize:null}}),i.zoomSettings=g,i.isCropTab=v,i.isUndoRedo=u,l=t.extend([],i.objColl,[],!0),p=t.extend([],i.pointColl,[],!0),i.objColl=[],i.pointColl=[],i.freehandCounter=0,i.notify("freehand-draw",{prop:"setSelPointColl",onPropertyChange:!1,value:{obj:{selPointColl:[]}}}),i.notify("transform",{prop:"setCropDimension",onPropertyChange:!1,value:{width:s.cropDimension.width,height:s.cropDimension.height}});var f={width:s.cropDimension.width,height:s.cropDimension.height};f.width+=f.width*a.defaultZoom,f.height+=f.height*a.defaultZoom,i.notify("draw",{prop:"setZoomCropWidth",value:{width:f.width,height:f.height}}),i.notify("draw",{prop:"setCurrentObj",onPropertyChange:!1,value:{obj:a}}),i.img.destLeft=a.destPoints.startX,i.img.destTop=a.destPoints.startY,i.panPoint.totalPannedPoint=a.totalPannedPoint,i.panPoint.totalPannedClientPoint=a.totalPannedClientPoint,i.panPoint.totalPannedInternalPoint=a.totalPannedInternalPoint,i.objColl=t.extend([],a.objColl,[],!0),i.pointColl=t.extend([],a.pointColl,[],!0),i.freehandCounter=i.pointColl.length,i.notify("draw",{prop:"setArrowDimension",onPropertyChange:!1,value:{arrowDimension:d}}),i.notify("freehand-draw",{prop:"setSelPointColl",onPropertyChange:!1,value:{obj:{selPointColl:t.extend([],a.selPointColl,[],!0)}}}),this.lowerContext.filter="none",i.transform.straighten=0,this.applyImgTranform(),i.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"iterate",pen:"iterate",isPreventApply:null}}),i.notify("freehand-draw",{prop:"updateFHDCurPts",onPropertyChange:!1}),this.lowerContext.filter=a.filter,0!==i.transform.degree&&i.notify("transform",{prop:"drawPannedImage",onPropertyChange:!1,value:{xDiff:0,yDiff:0}}),i.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.lowerContext}}),(i.isCircleCrop||i.currSelectionPoint&&"crop-circle"===i.currSelectionPoint.shape)&&i.notify("crop",{prop:"cropCircle",onPropertyChange:!1,value:{context:this.lowerContext,isSave:null,isFlip:null}})}}return{obj:l,point:p}},e.prototype.updateObjColl=function(){for(var e=this.parent,t=0;t<e.objColl.length;t++){var o=e.objColl[t];"line"!==o.shape&&"arrow"!==o.shape||(o.activePoint.width<0&&(o.activePoint.width=Math.abs(o.activePoint.width)),o.activePoint.height<0&&(o.activePoint.height=Math.abs(o.activePoint.height)))}},e.prototype.applyImgTranform=function(){for(var e=this.parent,o=t.extend({},e.activeObj,{},!0),i=0,r=e.objColl.length;i<r;i++)if("image"===e.objColl[i].shape){e.activeObj=t.extend({},e.objColl[i],{},!0);var a=e.objColl[i].imageCanvas.getContext("2d");e.notify("selection",{prop:"applyTransformToImg",onPropertyChange:!1,value:{ctx:a}}),this.upperContext.clearRect(0,0,e.upperCanvas.width,e.upperCanvas.height),e.notify("selection",{prop:"setImageClarity",onPropertyChange:!1,value:{bool:!0}})}e.activeObj=o},e.prototype.updateUndoRedoStack=function(e){var t=this.parent;if(t.activeObj.currIndex&&0!==t.activeObj.activePoint.width||0!==t.activeObj.activePoint.height||t.activeObj.pointColl&&t.activeObj.pointColl.length>0||e){var o="none"!==t.textArea.style.display,i=t.noPushUndo;if(t.noPushUndo=!1,t.isUndoRedoStack=!0,e){var r=t.togglePen,a={freehandDrawSelectedId:null};t.notify("freehand-draw",{prop:"getFreehandDrawSelectedId",onPropertyChange:!1,value:{obj:a}}),t.okBtn(),t.noPushUndo=i,a.freehandDrawSelectedId?t.selectShape(a.freehandDrawSelectedId):t.freeHandDraw(!0),t.togglePen=r}else if(t.activeObj.currIndex){var n=t.activeObj.currIndex;t.okBtn(),t.noPushUndo=i,t.selectShape(n),t.drawingShape&&t.notify("selection",{prop:"setCurrentDrawingShape",onPropertyChange:!1,value:{value:t.drawingShape.toLowerCase()}}),o&&t.enableTextEditing()}t.isUndoRedoStack=!1}},e}(),b=function(){var e=function(t,o){return(e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var o in t)t.hasOwnProperty(o)&&(e[o]=t[o])})(t,o)};return function(t,o){function i(){this.constructor=t}e(t,o),t.prototype=null===o?Object.create(o):(i.prototype=o.prototype,new i)}}(),m=function(e,t,o,i){var r,a=arguments.length,n=a<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,o):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(e,t,o,i);else for(var s=e.length-1;s>=0;s--)(r=e[s])&&(n=(a<3?r(n):a>3?r(t,o,n):r(t,o))||n);return a>3&&n&&Object.defineProperty(t,o,n),n},y=function(e){function o(){return null!==e&&e.apply(this,arguments)||this}return b(o,e),m([t.Property(null)],o.prototype,"brightness",void 0),m([t.Property(null)],o.prototype,"contrast",void 0),m([t.Property(null)],o.prototype,"hue",void 0),m([t.Property(null)],o.prototype,"saturation",void 0),m([t.Property(null)],o.prototype,"exposure",void 0),m([t.Property(null)],o.prototype,"opacity",void 0),m([t.Property(null)],o.prototype,"blur",void 0),o}(t.ChildProperty),P=function(e){function o(){return null!==e&&e.apply(this,arguments)||this}return b(o,e),m([t.Property(null)],o.prototype,"zoomTrigger",void 0),m([t.Property(1)],o.prototype,"minZoomFactor",void 0),m([t.Property(10)],o.prototype,"maxZoomFactor",void 0),m([t.Property(1)],o.prototype,"zoomFactor",void 0),m([t.Property(null)],o.prototype,"zoomPoint",void 0),o}(t.ChildProperty),j=function(e){function o(){return null!==e&&e.apply(this,arguments)||this}return b(o,e),m([t.Property(!0)],o.prototype,"showCircle",void 0),m([t.Property(null)],o.prototype,"strokeColor",void 0),m([t.Property(null)],o.prototype,"fillColor",void 0),o}(t.ChildProperty),x=function(e){function o(){return null!==e&&e.apply(this,arguments)||this}return b(o,e),m([t.Property("Arial")],o.prototype,"default",void 0),m([t.Property(null)],o.prototype,"items",void 0),o}(t.ChildProperty),w=function(r){function a(e,t){var o=r.call(this,e)||this;return o.isImageLoaded=!1,o.activeObj={activePoint:{startX:0,startY:0,endX:0,endY:0,width:0,height:0},flipObjColl:[],triangle:[],triangleRatio:[],rotatedAngle:0,opacity:1,order:null},o.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},o.objColl=[],o.pointColl={},o.freehandCounter=0,o.points=[],o.togglePen=!1,o.togglePan=!1,o.img={destLeft:0,destTop:0,destWidth:0,destHeight:0,srcLeft:0,srcTop:0,srcWidth:0,srcHeight:0},o.rotateFlipColl=[],o.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:"",straighten:0,destPoints:{startX:0,startY:0,width:0,height:0},srcPoints:{startX:0,startY:0,width:0,height:0},filter:"",isBrightAdjust:!1,zoomFactor:0,previousZoomValue:0,aspectWidth:null,aspectHeight:null,frame:"none",straightenZoom:0,adjustmentLevel:{brightness:0,contrast:0,hue:0,opacity:100,saturation:0,blur:0,exposure:0,transparency:100,sharpen:!1,bw:!1},currentFilter:""},o.afterCropActions=[],o.transform={degree:0,currFlipState:"",zoomFactor:0,cropZoomFactor:null,defaultZoomFactor:0,straighten:0},o.panPoint={currentPannedPoint:{x:0,y:0},totalPannedPoint:{x:0,y:0},totalPannedInternalPoint:{x:0,y:0},totalPannedClientPoint:{x:0,y:0}},o.isUndoRedo=!1,o.isCropTab=!1,o.isCircleCrop=!1,o.fontSizeColl=[],o.initialAdjustmentValue="",o.currentFilter="",o.canvasFilter="brightness(1) contrast(100%) hue-rotate(0deg) saturate(100%) opacity(1) blur(0px) sepia(0%) grayscale(0%) invert(0%)",o.toolbarHeight=0,o.isPublicMethod=!1,o.isCropToolbar=!1,o.cursor="default",o.resizeSrc={startX:o.img.srcLeft,startY:o.img.srcTop,width:o.img.srcWidth,height:o.img.srcHeight},o.isResize=!1,o.isAspectRatio=!1,o.frameObj={type:"none",color:"#fff",size:20,inset:20,offset:20,radius:0,amount:1,border:"solid",gradientColor:""},o.tempFrameObj={type:"none",color:"#fff",size:20,inset:20,offset:20,radius:0,amount:1,border:"solid",gradientColor:""},o.allowDownScale=!0,o.gradientColor="",o.size=20,o.inset=0,o.offset=0,o.borderRadius=0,o.lineCount=0,o.prevStraightenedDegree=0,o.tempStraighten=0,o.isStraightening=!1,o.isFinetuning=!1,o.isZoomBtnClick=!1,o.isFinetuneBtnClick=!1,o.isFilterCanvasClick=!1,o.isFrameBtnClick=!1,o.isChangesSaved=!1,o.isShapeDrawing=!1,o.noPushUndo=!1,o.isUndoRedoStack=!1,o.shapeColl=[],o.isKBDNavigation=!1,n.Inject(s,h,v,f,d,O),n.Inject(C),n.Inject(c),n.Inject(g),n.Inject(u),t&&o.appendTo(t),o}b(a,r),n=a,a.prototype.requiredModules=function(){var e=[];return e.push({member:"crop",args:[this]}),e.push({member:"draw",args:[this]}),e.push({member:"selection",args:[this]}),e.push({member:"transform",args:[this]}),e.push({member:"export",args:[this]}),e.push({member:"toolbar-module",args:[this]}),e.push({member:"undo-redo",args:[this]}),e.push({member:"filter",args:[this]}),e.push({member:"shape",args:[this]}),e.push({member:"freehand-draw",args:[this]}),e},a.prototype.preRender=function(){this.element.id=this.element.id||t.getUniqueID("ej2-image-editor"),t.Browser.isDevice&&this.element.classList.add("e-device"),this.initializeThemeColl()},a.prototype.render=function(){if(this.isAngular){var e=this.element,o=e.cloneNode(!0);e.parentNode.replaceChild(o,e),this.element=o,t.setValue("ej2_instances",[this],this.element)}this.initialize()},a.prototype.getModuleName=function(){return"image-editor"},a.prototype.getPersistData=function(){return this.addOnPersist([])},a.prototype.onPropertyChanged=function(o,i){for(var r,a=0,n=Object.keys(o);a<n.length;a++)switch(n[a]){case"cssClass":i.cssClass&&t.removeClass([this.element],i.cssClass.replace(/\s+/g," ").trim().split(" ")),o.cssClass&&t.addClass([this.element],o.cssClass.replace(/\s+/g," ").trim().split(" "));break;case"disabled":o.disabled?(this.element.classList.add("e-disabled"),this.unwireEvent()):(this.element.classList.remove("e-disabled"),this.wireEvent());break;case"height":this.element.style.height=o.height,this.update();break;case"width":this.element.style.width=o.width,this.update();break;case"theme":o.theme&&(this.theme&&""!==this.theme?this.theme=this.toPascalCase(this.theme):this.theme="Bootstrap5",this.upperContext.strokeStyle=this.themeColl[this.theme].primaryColor,this.upperContext.fillStyle=this.themeColl[this.theme].secondaryColor,this.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"main",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}}));break;case"finetuneSettings":o.finetuneSettings&&(this.finetuneSettings=o.finetuneSettings,this.notify("filter",{prop:"update-finetunes"}));break;case"locale":o.locale&&(this.notify("toolbar",{prop:"setLocale",onPropertyChange:!1,value:{locale:o.locale}}),this.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"main",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}}));break;case"allowUndoRedo":o.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":o.showQuickAccessToolbar?(this.showQuickAccessToolbar=!0,this.notify("toolbar",{prop:"create-qa-toolbar",onPropertyChange:!1}),r={freehandSelectedIndex:null},this.notify("freehand-draw",{prop:"getFreehandSelectedIndex",onPropertyChange:!1,value:{obj:r}}),this.activeObj.shape?this.notify("toolbar",{prop:"renderQAT",onPropertyChange:!1,value:{isPenEdit:null}}):r.freehandSelectedIndex&&this.notify("toolbar",{prop:"renderQAT",onPropertyChange:!1,value:{isPenEdit:!0}})):(this.showQuickAccessToolbar=!1,this.notify("toolbar",{prop:"destroy-qa-toolbar",onPropertyChange:!1}));break;case"zoomSettings":o.zoomSettings&&(this.zoomSettings.zoomTrigger=o.zoomSettings.zoomTrigger),t.isNullOrUndefined(this.zoomSettings.zoomTrigger)?(this.zoomSettings.zoomTrigger=e.ZoomTrigger.MouseWheel|e.ZoomTrigger.Pinch|e.ZoomTrigger.Toolbar|e.ZoomTrigger.Commands,this.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"main",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}})):(o.zoomSettings.zoomTrigger&e.ZoomTrigger.Toolbar)===e.ZoomTrigger.Toolbar&&this.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"main",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}});break;case"selectionSettings":o.selectionSettings&&(this.selectionSettings=o.selectionSettings,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}})));break;case"toolbar":o.toolbar&&(this.toolbar=o.toolbar,this.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"main",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}}));break;case"toolbarTemplate":o.toolbarTemplate&&(this.notify("toolbar",{prop:"destroy-bottom-toolbar",onPropertyChange:!1}),this.notify("toolbar",{prop:"destroy-top-toolbar",onPropertyChange:!1}),this.element.appendChild(this.createElement("div",{id:this.element.id+"_toolbarArea",className:"e-toolbar-area"})),this.toolbarTemplateFn());break;case"quickAccessToolbarTemplate":o.quickAccessToolbarTemplate&&(this.notify("toolbar",{prop:"destroy-qa-toolbar",onPropertyChange:!1}),this.quickAccessToolbarTemplateFn())}},a.prototype.destroy=function(){var e=[];this.element.removeAttribute("tabindex");var o=this.element.querySelector("#"+this.element.id+"_saveDialog");o&&"block"===o.style.display&&t.getComponent(document.getElementById(this.element.id+"_saveDialog"),"dialog").destroy(),this.cssClass&&(e=e.concat(this.cssClass.replace(/\s+/g," ").trim().split(" "))),t.removeClass([this.element],e),this.element.getAttribute("class")||this.element.removeAttribute("class"),this.unwireEvent(),this.notify("toolbar",{prop:"destroySubComponents",onPropertyChange:!1}),this.notify("destroyed",null),r.prototype.destroy.call(this),this.element.innerHTML=""},a.prototype.initialize=function(){if(this.toolbarTemplate?(this.element.appendChild(this.createElement("div",{id:this.element.id+"_toolbarArea",className:"e-toolbar-area"})),this.toolbarTemplateFn()):(this.notify("toolbar",{prop:"create-toolbar",onPropertyChange:!1}),this.notify("toolbar",{prop:"create-contextual-toolbar",onPropertyChange:!1})),this.createCanvas(),this.element.offsetWidth>359&&this.element.querySelector(".e-ie-min-drop-content")&&this.element.querySelector(".e-ie-drop-content")&&(this.element.querySelector(".e-ie-min-drop-content").style.display="none",this.element.querySelector(".e-ie-drop-content").style.display="block"),this.createDropUploader(),this.showQuickAccessToolbar){document.querySelector("#"+this.element.id+"_canvasWrapper").appendChild(this.createElement("div",{id:this.element.id+"_quickAccessToolbarArea",className:"e-quick-access-toolbar-area"}));var e=document.getElementById(this.element.id+"_quickAccessToolbarArea");e.style.position="absolute",e.style.display="none",this.activeObj&&(e.style.left=this.activeObj.activePoint.startX+"px",e.style.top=this.activeObj.activePoint.startY+"px"),e.style.width="100%"}this.quickAccessToolbarTemplate?this.quickAccessToolbarTemplateFn():this.notify("toolbar",{prop:"create-qa-toolbar",onPropertyChange:!1}),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.canvasFilter=this.lowerContext.filter,this.notify("toolbar",{prop:"setInitialAdjustmentValue",onPropertyChange:!1,value:{value:this.lowerContext.filter}}),this.cssClass&&t.addClass([this.element],this.cssClass.replace(/\s+/g," ").trim().split(" ")),this.element&&o.createSpinner({target:this.element}),this.initializeZoomSettings(),this.imgSrc&&this.open(this.imgSrc)},a.prototype.createDropUploader=function(){var e=this;new i.Uploader({dropArea:this.element.getElementsByClassName("e-canvas-wrapper")[0],allowedExtensions:".jpg, .jpeg, .png,.svg",multiple:!1,selected:function(t){if("change"===t.event.type||"drop"===t.event.type){var o=t.filesData[0].type,i="unsupported";"change"!==t.event.type&&("drop"!==t.event.type||1!==t.event.dataTransfer.files.length)||"png"!==o&&"jpg"!==o&&"jpeg"!==o&&"svg"!==o?("drop"===t.event.type&&t.event.dataTransfer.files.length>1&&(i="multi-select-image"),e.showDialogPopup(i)):e.notify("draw",{prop:"fileSelect",value:{inputElement:e.element.querySelector("#"+e.element.id+"_dropfileUpload"),args:t}})}}}).appendTo("#"+this.element.id+"_dropfileUpload")},a.prototype.dlgCloseBtnClick=function(){t.getComponent(document.getElementById(this.element.id+"_dialog"),"dialog").destroy()},a.prototype.showDialogPopup=function(e){var t="";this.element.querySelector("#"+this.element.id+"_dialog").style.display="block";var i,r={key:"DlgOK"};if(this.notify("toolbar",{prop:"getLocaleText",onPropertyChange:!1,value:{obj:r}}),"multi-select-image"===e){i={key:"ImageErrorDialogHeader"},this.notify("toolbar",{prop:"getLocaleText",onPropertyChange:!1,value:{obj:i}});a={key:"ImageErrorDialogContent"};this.notify("toolbar",{prop:"getLocaleText",onPropertyChange:!1,value:{obj:a}}),t="<span>"+a.value+"</span>"}else{i={key:"AlertDialogHeader"},this.notify("toolbar",{prop:"getLocaleText",onPropertyChange:!1,value:{obj:i}});var a={key:"AlertDialogContent"};this.notify("toolbar",{prop:"getLocaleText",onPropertyChange:!1,value:{obj:a}});var n={key:"SupportText"};this.notify("toolbar",{prop:"getLocaleText",onPropertyChange:!1,value:{obj:n}}),t="<span>"+a.value+" "+n.value+"<b> JPG, PNG, and SVG</b></span>"}new o.Dialog({header:i.value,closeOnEscape:!0,content:t,target:document.getElementById("target"),width:"285px",isModal:!0,animationSettings:{effect:"Zoom"},close:this.dlgCloseBtnClick.bind(this),buttons:[{click:this.dlgCloseBtnClick.bind(this),buttonModel:{content:r.value}}]}).appendTo("#"+this.element.id+"_dialog")},a.prototype.wireEvent=function(){t.EventHandler.add(document,"keydown",this.keyDownEventHandler,this),t.EventHandler.add(document,"keypress",this.keyUpEventHandler,this),t.EventHandler.add(this.upperCanvas,"mousedown",this.mouseDownEventHandler,this),t.EventHandler.add(this.upperCanvas,"mousemove",this.mouseMoveEventHandler,this),t.EventHandler.add(this.upperCanvas,"mouseup",this.mouseUpEventHandler,this),t.EventHandler.add(document,"mouseup",this.mouseUpEventHandler,this),t.EventHandler.add(this.lowerCanvas,"mousedown",this.canvasMouseDownHandler,this),t.EventHandler.add(this.lowerCanvas,"mousemove",this.canvasMouseMoveHandler,this),t.EventHandler.add(this.lowerCanvas,"mouseup",this.canvasMouseUpHandler,this),t.EventHandler.add(this.upperCanvas,"touchstart",this.touchStartHandler,this),t.EventHandler.add(this.lowerCanvas,"touchstart",this.touchStartHandler,this),t.EventHandler.add(this.lowerCanvas,"mousewheel DOMMouseScroll",this.handleScroll,this),t.EventHandler.add(this.upperCanvas,"mousewheel DOMMouseScroll",this.handleScroll,this),window.addEventListener("resize",this.windowResizeHandler.bind(this)),t.Browser.isIos||"safari"===t.Browser.info.name||screen.orientation.addEventListener("change",this.screenOrientation.bind(this)),this.notify("shape",{prop:"wireEvent",onPropertyChange:!1})},a.prototype.unwireEvent=function(){t.EventHandler.remove(document,"keydown",this.keyDownEventHandler),t.EventHandler.remove(document,"keypress",this.keyUpEventHandler),t.EventHandler.remove(this.upperCanvas,"mousedown",this.mouseDownEventHandler),t.EventHandler.remove(this.upperCanvas,"mousemove",this.mouseMoveEventHandler),t.EventHandler.remove(this.upperCanvas,"mouseup",this.mouseUpEventHandler),t.EventHandler.remove(document,"mouseup",this.mouseUpEventHandler),t.EventHandler.remove(this.lowerCanvas,"mousedown",this.canvasMouseDownHandler),t.EventHandler.remove(this.lowerCanvas,"mousemove",this.canvasMouseMoveHandler),t.EventHandler.remove(this.lowerCanvas,"mouseup",this.canvasMouseUpHandler),t.EventHandler.remove(this.upperCanvas,"touchstart",this.touchStartHandler),t.EventHandler.remove(this.lowerCanvas,"touchstart",this.touchStartHandler),t.EventHandler.remove(this.lowerCanvas,"mousewheel DOMMouseScroll",this.handleScroll),t.EventHandler.remove(this.upperCanvas,"mousewheel DOMMouseScroll",this.handleScroll),window.removeEventListener("resize",this.windowResizeHandler.bind(this)),t.Browser.isIos||"safari"===t.Browser.info.name||screen.orientation.removeEventListener("change",this.screenOrientation.bind(this)),this.notify("shape",{prop:"unWireEvent",onPropertyChange:!1}),this.notify("selection",{prop:"unWireEvent",onPropertyChange:!1})},a.prototype.createCanvas=function(){this.element.style.boxSizing="border-box";var e={toolbarHeight:0};this.notify("toolbar",{prop:"getToolbarHeight",value:{obj:e}});var t=e.toolbarHeight;this.toolbar&&this.toolbar.length>0&&-1===this.toolbar.indexOf("Open")&&(t=0),this.element.style.width=this.width,this.element.style.height=this.height;var o=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;"}})),i={key:"DragText"};this.notify("toolbar",{prop:"getLocaleText",onPropertyChange:!1,value:{obj:i}});var r={key:"DropText"};this.notify("toolbar",{prop:"getLocaleText",onPropertyChange:!1,value:{obj:r}});var a={key:"BrowseText"};this.notify("toolbar",{prop:"getLocaleText",onPropertyChange:!1,value:{obj:a}});var n={key:"SupportText"};this.notify("toolbar",{prop:"getLocaleText",onPropertyChange:!1,value:{obj:n}});var s=this.createElement("div",{id:this.element.id+"_dropArea",className:"e-ie-drop-area",attrs:{style:"position: relative;"}}),l=this.createElement("span",{className:"e-ie-drop-icon e-icons e-image",attrs:{style:"position: absolute;"}}),p=this.createElement("span",{className:"e-ie-drop-content",attrs:{style:"position: absolute; display: none;"}});p.textContent=i.value+" ";var h=this.createElement("span",{className:"e-ie-min-drop-content",attrs:{style:"position: absolute;"}});h.textContent=r.value+" ";var d=this.createElement("a",{id:this.element.id+"_dropBrowse",className:"e-ie-drop-browse"});d.textContent=a.value;var c=this.createElement("a",{id:this.element.id+"_dropBrowse",className:"e-ie-drop-browse"});c.textContent=a.value,p.appendChild(d),h.appendChild(c),d.href="",c.href="";var u=this.createElement("span",{className:"e-ie-drop-info",attrs:{position:"absolute"}});u.textContent=n.value+" SVG, PNG, and JPG";var v=s.appendChild(this.createElement("input",{id:this.element.id+"_dropfileUpload",className:"e-fileUpload e-image-upload"}));v.setAttribute("type","file"),v.setAttribute("accept","image/*"),s.appendChild(l),s.appendChild(p),s.appendChild(h),s.appendChild(u),o.appendChild(s),this.lowerCanvas=o.appendChild(this.createElement("canvas",{id:this.element.id+"_lowerCanvas",attrs:{name:"canvasImage"}})),this.upperCanvas=o.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.baseImgCanvas=this.createElement("canvas",{id:this.element.id+"_baseImgCanvas",attrs:{name:"canvasImage"}}),this.textArea=o.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";var g=this.element.appendChild(this.createElement("input",{id:this.element.id+"_fileUpload",className:"e-fileUpload"}));g.setAttribute("type","file"),g.setAttribute("accept","image/*"),g.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"),d.addEventListener("click",function(e){return e.preventDefault(),v.click(),!1}),c.addEventListener("click",function(e){return e.preventDefault(),v.click(),!1})},a.prototype.touchStartHandler=function(e){this.notify("selection",{prop:"touchStartHandler",onPropertyChange:!1,value:{e:e}})},a.prototype.mouseDownEventHandler=function(e){"e-ie-drop-browse"!==e.target.className&&this.notify("selection",{prop:"mouseDownEventHandler",onPropertyChange:!1,value:{e:e}})},a.prototype.mouseMoveEventHandler=function(e){this.notify("selection",{prop:"mouseMoveEventHandler",onPropertyChange:!1,value:{e:e}})},a.prototype.mouseUpEventHandler=function(e){"e-ie-drop-browse"!==e.target.className&&this.notify("selection",{prop:"mouseUpEventHandler",onPropertyChange:!1,value:{e:e}})},a.prototype.keyDownEventHandler=function(e){this.notify("selection",{prop:"keyDownEventHandler",onPropertyChange:!1,value:{e:e}})},a.prototype.keyUpEventHandler=function(e){"block"!==this.textArea.style.display&&"inline-block"!==this.textArea.style.display||e.target.id!==this.element.id+"_textArea"||this.notify("selection",{prop:"textKeyDown",value:{e:e}})},a.prototype.canvasMouseDownHandler=function(e){"e-ie-drop-browse"!==e.target.className&&this.notify("selection",{prop:"canvasMouseDownHandler",onPropertyChange:!1,value:{e:e}})},a.prototype.canvasMouseMoveHandler=function(e){this.notify("selection",{prop:"canvasMouseMoveHandler",onPropertyChange:!1,value:{e:e}})},a.prototype.canvasMouseUpHandler=function(e){"e-ie-drop-browse"!==e.target.className&&this.notify("selection",{prop:"canvasMouseUpHandler",onPropertyChange:!1,value:{e:e}})},a.prototype.handleScroll=function(e){this.notify("selection",{prop:"handleScroll",onPropertyChange:!1,value:{e:e}})},a.prototype.adjustToScreen=function(){this.update()},a.prototype.screenOrientation=function(){t.Browser.isDevice&&setTimeout(this.adjustToScreen.bind(this),100)},a.prototype.windowResizeHandler=function(){!t.Browser.isDevice&&this.element.classList.contains("e-image-editor")&&this.adjustToScreen()},a.prototype.notifyResetForAllModules=function(){for(var e=this.requiredModules(),t=0;t<e.length;t++){var o=e[t].member;this.notify("toolbar-module"===o?"toolbar":o,{prop:"reset",onPropertyChange:!1})}},a.prototype.allowShape=function(e,t){this.isPublicMethod=!0,this.applyShapes();var o={inRange:!1};return this.notify("shape",{prop:"isPointsInRange",onPropertyChange:!1,value:{x:e,y:t,obj:o}}),o.inRange},a.prototype.clearSelection=function(e){this.notify("selection",{prop:"clearSelection",onPropertyChange:!1,value:{resetCrop:e}})},a.prototype.crop=function(){var e={isCrop:!1};return this.notify("crop",{prop:"crop",onPropertyChange:!1,value:{obj:e}}),e.isCrop},a.prototype.flip=function(e){this.notify("transform",{prop:"flip",value:{direction:e}}),this.notify("draw",{prop:"redrawDownScale"}),this.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"ok"}})},a.prototype.getImageData=function(){var e={canvas:null};return this.applyShapes(),this.notify("export",{prop:"exportToCanvas",value:{object:e}}),e.canvas.getContext("2d").getImageData(0,0,e.canvas.width,e.canvas.height)},a.prototype.open=function(e){if(!t.isNullOrUndefined(e)){var o=document.getElementById(this.element.id+"_dropArea");o&&(o.style.display="none"),this.notify("draw",{prop:"open",value:{data:e}})}},a.prototype.reset=function(){var e={isErrorImage:!1};if(this.notify("draw",{prop:"getErrorImage",value:{obj:e}}),!this.disabled&&!e.isErrorImage){this.clearContext(this.inMemoryContext),this.clearContext(this.lowerContext),this.clearContext(this.upperContext),this.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),this.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"main",isApplyBtn:!1,isCropping:!1,isZooming:null,cType:null}}),t.Browser.isDevice&&document.getElementById(this.element.id+"_bottomToolbar")&&(t.getComponent(document.getElementById(this.element.id+"_bottomToolbar"),"toolbar").destroy(),this.notify("toolbar",{prop:"create-bottom-toolbar",onPropertyChange:!1}));var o=this.isImageLoaded;this.currObjType.isUndoAction=this.isUndoRedo=this.togglePan=this.togglePen=this.isImageLoaded=this.isFinetuning=!1,this.isCircleCrop=this.isCropTab=!1,this.objColl=[],this.transform.degree=0,this.upperCanvas.style.display="block",this.transform.currFlipState="",this.allowDownScale=!0,this.upperCanvas.style.cursor=this.cursor=this.lowerCanvas.style.cursor="default",this.lowerContext.lineWidth=this.upperContext.lineWidth=void 0,this.frameDestPoints=null,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.frameObj={type:"none",color:"#fff",size:20,inset:20,offset:20,radius:0,amount:1,border:"solid",gradientColor:""},this.tempFrameObj={type:"none",color:"#fff",size:20,inset:20,offset:20,radius:0,amount:1,border:"solid",gradientColor:""},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:"",straighten:0,zoomFactor:0,previousZoomValue:0,destPoints:{startX:0,startY:0,width:0,height:0},frame:"none",srcPoints:{startX:0,startY:0,width:0,height:0},filter:"",isBrightAdjust:!1,aspectWidth:null,aspectHeight:null,straightenZoom:0,adjustmentLevel:{brightness:0,contrast:0,hue:0,opacity:100,saturation:0,blur:0,exposure:0,transparency:100,sharpen:!1,bw:!1},currentFilter:""},this.afterCropActions=[],this.currentFilter="",this.tempFrameZoomLevel=null,this.cxtTbarHeight=null,this.straightenPoint=null,this.transform.straighten=0,this.cancelCropSelection=null,this.aspectWidth=this.aspectHeight=null,this.isResize=!1,this.drawingShape=null,this.isShapeDrawing=this.noPushUndo=this.isUndoRedoStack=this.isKBDNavigation=!1,this.shapeColl=[];var i={initialZoomValue:!1};this.notify("draw",{prop:"getInitialZoomValue",onPropertyChange:!1,value:{obj:i}}),i.initialZoomValue&&this.setProperties({zoomSettings:{zoomFactor:i.initialZoomValue}},!0);var r=document.getElementById(this.element.id+"_quickAccessToolbarArea");r&&(r.style.display="none"),this.notifyResetForAllModules(),this.notify("filter",{prop:"update-finetunes"}),this.toolbarTemplate?this.toolbarHeight=this.element.querySelector("#"+this.element.id+"_toolbarArea").clientHeight:this.element.querySelector("#"+this.element.id+"_toolbar")&&(this.toolbarHeight=this.element.querySelector("#"+this.element.id+"_toolbar").clientHeight),this.notify("toolbar",{prop:"setToolbarHeight",value:{height:this.toolbarHeight}}),this.isImageLoaded=o,this.straightenBaseImageCanvas(),this.isImageLoaded=!1,this.notify("draw",{prop:"update-canvas",onPropertyChange:!1}),this.isImageLoaded=o,this.prevStraightenedDegree=0;var a=this.element.querySelector(".e-contextual-toolbar-wrapper");a&&a.classList.add("e-hide"),this.notify("toolbar",{prop:"refresh-dropdown-btn",value:{isDisabled:!1}}),this.notify("toolbar",{prop:"enable-disable-btns"});var n={bool:this.isStraightening};t.Browser.isDevice&&n.bool&&this.notify("crop",{prop:"resizeWrapper"})}},a.prototype.rotate=function(e){var t={isRotate:!1};return 90!==e&&-90!==e||this.updateImageTransformColl(90===e?"rotateright":"rotateleft"),this.notify("transform",{prop:"rotate",value:{degree:e,obj:t}}),this.notify("draw",{prop:"redrawDownScale"}),t.isRotate},a.prototype.export=function(e,t,o){this.applyShapes(),this.notify("export",{prop:"export",onPropertyChange:!1,value:{type:e,fileName:t,imgQuality:o}})},a.prototype.select=function(e,t,o,i,r){this.applyShapes(),this.notify("toolbar",{prop:"performCropTransformClick",value:{shape:"crop-"+e}}),this.notify("draw",{prop:"select",onPropertyChange:!1,value:{type:e,startX:t,startY:o,width:i,height:r}}),t&&o||i&&r?this.notify("draw",{prop:"select",onPropertyChange:!1,value:{type:e,startX:t,startY:o,width:i,height:r}}):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:"",straighten:0,zoomFactor:0,previousZoomValue:0,destPoints:{startX:0,startY:0,width:0,height:0},frame:"none",srcPoints:{startX:0,startY:0,width:0,height:0},filter:"",isBrightAdjust:!1,aspectWidth:null,aspectHeight:null,straightenZoom:0,adjustmentLevel:{brightness:0,contrast:0,hue:0,opacity:100,saturation:0,blur:0,exposure:0,transparency:100,sharpen:!1,bw:!1},currentFilter:""}},a.prototype.freeHandDraw=function(e){this.notify("freehand-draw",{prop:"freeHandDraw",onPropertyChange:!1,value:{value:e}})},a.prototype.freehandDraw=function(e){!this.disabled&&this.isImageLoaded&&(this.applyShapes(),this.freeHandDraw(e))},a.prototype.pan=function(e,t,o){this.applyShapes(),this.notify("transform",{prop:"pan",onPropertyChange:!1,value:{value:e,x:t,y:o}})},a.prototype.zoom=function(e,t){this.isZoomBtnClick=!0,this.notify("transform",{prop:"zoom",onPropertyChange:!1,value:{zoomFactor:e,zoomPoint:t}}),this.notify("draw",{prop:"redrawDownScale"})},a.prototype.drawEllipse=function(e,o,i,r,a,n,s,l,p){var h=!1,d=this.allowShape(e,o);return!this.disabled&&this.isImageLoaded&&(d||t.isNullOrUndefined(e)&&t.isNullOrUndefined(o))&&(h=!0,this.notify("shape",{prop:"drawEllipse",onPropertyChange:!1,value:{x:e,y:o,radiusX:i,radiusY:r,strokeWidth:a,strokeColor:n,fillColor:s,degree:l,isSelected:p}}),this.notify("draw",{prop:"redrawDownScale"})),h},a.prototype.drawLine=function(e,o,i,r,a,n,s){var l=!1,p=this.allowShape(e,o);return!this.disabled&&this.isImageLoaded&&(p||t.isNullOrUndefined(e)&&t.isNullOrUndefined(o))&&(l=!0,this.notify("shape",{prop:"drawLine",onPropertyChange:!1,value:{startX:e,startY:o,endX:i,endY:r,strokeWidth:a,strokeColor:n,isSelected:s}}),this.notify("draw",{prop:"redrawDownScale"})),l},a.prototype.drawArrow=function(e,o,i,r,a,n,s,l,p){var h=!1,d=this.allowShape(e,o);return!this.disabled&&this.isImageLoaded&&(d||t.isNullOrUndefined(e)&&t.isNullOrUndefined(o))&&(h=!0,this.notify("shape",{prop:"drawArrow",onPropertyChange:!1,value:{startX:e,startY:o,endX:i,endY:r,strokeWidth:a,strokeColor:n,arrowStart:s,arrowEnd:l,isSelected:p}}),this.notify("draw",{prop:"redrawDownScale"})),h},a.prototype.drawPath=function(e,o,i,r){this.isPublicMethod=!0;var a={inRange:!1},n=!1;if(e&&e.length>0)for(var s=0;s<e.length&&!a.inRange;s++)this.notify("shape",{prop:"isPointsInRange",onPropertyChange:!1,value:{x:e[s].x,y:e[s].y,obj:a}});return!this.disabled&&this.isImageLoaded&&(a.inRange||t.isNullOrUndefined(e))&&(n=!0,this.applyShapes(),this.notify("shape",{prop:"drawPath",onPropertyChange:!1,value:{pointColl:e,strokeWidth:o,strokeColor:i,isSelected:r}}),this.notify("draw",{prop:"redrawDownScale"})),n},a.prototype.drawRectangle=function(e,o,i,r,a,n,s,l,p){var h=!1,d=this.allowShape(e,o);return!this.disabled&&this.isImageLoaded&&(d||t.isNullOrUndefined(e)&&t.isNullOrUndefined(o))&&(h=!0,this.notify("shape",{prop:"drawRectangle",onPropertyChange:!1,value:{x:e,y:o,width:i,height:r,strokeWidth:a,strokeColor:n,fillColor:s,degree:l,isSelected:p}}),this.notify("draw",{prop:"redrawDownScale"})),h},a.prototype.drawText=function(e,o,i,r,a,n,s,l,p,h){var d=!1,c=this.allowShape(e,o);return!this.disabled&&this.isImageLoaded&&(c||t.isNullOrUndefined(e)&&t.isNullOrUndefined(o))&&(d=!0,this.notify("shape",{prop:"drawText",onPropertyChange:!1,value:{x:e,y:o,text:i,fontFamily:r,fontSize:a,bold:n,italic:s,color:l,isSelected:p,degree:h}}),this.notify("draw",{prop:"redrawDownScale"})),d},a.prototype.drawImage=function(e,o,i,r,a,n,s,l,p){var h=!1,d=this.allowShape(o,i);if(!this.disabled&&this.isImageLoaded&&(d||t.isNullOrUndefined(o)&&t.isNullOrUndefined(i))){var c=this.objColl.length;this.notify("shape",{prop:"drawImage",onPropertyChange:!1,value:{x:o,y:i,width:r,height:a,src:e,degree:s,isAspectRatio:n,opacity:l,isSelected:p}}),this.notify("draw",{prop:"redrawDownScale"}),this.objColl.length>c&&(h=!0)}return h},a.prototype.selectShape=function(e){this.applyShapes();var t={isSelected:!1};return this.notify("shape",{prop:"selectShape",onPropertyChange:!1,value:{id:e,obj:t}}),this.notify("draw",{prop:"redrawDownScale"}),t.isSelected},a.prototype.deleteShape=function(e){this.applyShapes(),this.notify("shape",{prop:"deleteShape",onPropertyChange:!1,value:{id:e}}),this.notify("draw",{prop:"redrawDownScale"})},a.prototype.getShapeSetting=function(e){this.applyShapes();var t={shapeDetails:null};return this.notify("shape",{prop:"getShapeSetting",onPropertyChange:!1,value:{id:e,obj:t}}),this.notify("draw",{prop:"redrawDownScale"}),t.shapeDetails?t.shapeDetails:{}},a.prototype.getShapeSettings=function(){this.applyShapes();var e={shapeDetailsColl:[]};return this.notify("shape",{prop:"getShapeSettings",onPropertyChange:!1,value:{obj:e}}),this.notify("draw",{prop:"redrawDownScale"}),e.shapeDetailsColl},a.prototype.update=function(){this.notify("transform",{prop:"update"})},a.prototype.finetuneImage=function(e,t){!this.disabled&&this.isImageLoaded&&(this.applyShapes(),this.notify("filter",{prop:"finetuneImage",value:{value:t,option:e}}),this.notify("draw",{prop:"redrawDownScale"}))},a.prototype.applyImageFilter=function(e){!this.disabled&&this.isImageLoaded&&(this.applyShapes(),this.notify("filter",{prop:"applyImageFilter",value:{option:e.toString()}}),this.notify("draw",{prop:"redrawDownScale"}),this.canvasFilter=this.lowerContext.filter,this.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"ok"}}))},a.prototype.undo=function(){this.applyShapes(),this.notify("undo-redo",{prop:"undo",onPropertyChange:!1}),this.notify("draw",{prop:"redrawDownScale"})},a.prototype.redo=function(){this.applyShapes(),this.notify("undo-redo",{prop:"redo",onPropertyChange:!1}),this.notify("draw",{prop:"redrawDownScale"})},a.prototype.getImageDimension=function(){return{x:this.img.destLeft,y:this.img.destTop,width:this.img.destWidth,height:this.img.destHeight}},a.prototype.resize=function(e,o,i){var r=!1;if(e.toString().length<=4&&o.toString().length<=4){this.applyShapes();var a={startX:this.img.destLeft,startY:this.img.destTop,width:this.img.destWidth,height:this.img.destHeight};i?(this.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"resize",isApplyBtn:!1,isCropping:!1}}),this.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"resize",isApplyBtn:!1,isCropping:!1}})):this.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"resize",isApplyBtn:!1,isCropping:!1}});var n=this.element.querySelector("#"+this.element.id+"_resizeWidth"),s=this.element.querySelector("#"+this.element.id+"_resizeHeight");n&&s&&(t.getComponent(n,"numerictextbox").value=Math.floor(e),n.value=Math.floor(e).toString()+" px",t.getComponent(s,"numerictextbox").value=Math.floor(o),s.value=Math.floor(o).toString()+" px"),this.notify("transform",{prop:"resize",value:{width:e,height:o,isAspectRatio:i}}),a.startX!==this.img.destLeft||a.startY!==this.img.destTop||a.width!==this.img.destWidth||a.height!==this.img.destHeight?(r=!0,this.okBtn()):this.notify("draw",{prop:"performCancel",value:{isContextualToolbar:null}}),this.notify("draw",{prop:"redrawDownScale"})}return r},a.prototype.drawFrame=function(o,i,r,a,n,s,l,p,h){this.applyShapes();var d=!1,c={frameChangeEventArgs:null};i=i||"#fff",r=r||"",a=a||20,n=n||0,s=s||0,l=l||0,p=p||e.FrameLineStyle.Solid,h=h||0;var u={type:this.toPascalCase(this.frameObj.type),color:this.frameObj.color,gradientColor:this.frameObj.gradientColor,size:this.frameObj.size,inset:this.frameObj.inset,offset:this.frameObj.offset,borderRadius:this.frameObj.radius,frameLineStyle:this.toPascalCase(this.frameObj.border),lineCount:this.frameObj.amount};return t.extend(this.tempFrameObj,this.frameObj),this.tempFrameZoomLevel=this.transform.zoomFactor,this.frameDestPoints=t.extend({},this.img,{},!0),this.notify("toolbar",{prop:"frameToolbarClick"}),this.frameObj.type=o.toLowerCase(),this.frameObj.color=i,this.frameObj.gradientColor=r,this.frameObj.size=a,this.frameObj.inset=n,this.frameObj.offset=s,this.frameObj.radius=l,this.frameObj.border=p.toLowerCase(),this.frameObj.amount=h,this.notify("draw",{prop:"triggerFrameChange",value:{prevFrameSettings:u,obj:c}}),c.frameChangeEventArgs&&!c.frameChangeEventArgs.cancel?(this.notify("draw",{prop:"render-image",value:{isMouseWheel:null}}),JSON.stringify(this.frameObj)!==JSON.stringify(this.tempFrameObj)?(d=!0,this.okBtn()):this.tempFrameZoomLevel=null):(this.notify("draw",{prop:"performCancel",value:{isContextualToolbar:null}}),t.extend(this.frameObj,this.tempFrameObj),this.tempFrameZoomLevel=null),this.notify("draw",{prop:"redrawDownScale"}),d},a.prototype.straightenImage=function(e){var t=!1;return e>=-45&&e<=45&&(this.applyShapes(),t=!0,this.notify("transform",{prop:"straightenImage",value:{degree:e}}),this.notify("draw",{prop:"redrawDownScale"})),t},a.prototype.updateShape=function(e,o){var i={isSelected:!1},r=!1,a={bool:!1};if(t.isNullOrUndefined(e.id))e.strokeColor&&(this.activeObj.strokeSettings.strokeColor=e.strokeColor),e.fillColor&&(this.activeObj.strokeSettings.fillColor=e.fillColor),e.strokeWidth&&(this.activeObj.strokeSettings.strokeWidth=e.strokeWidth),e.index&&(this.activeObj.order=e.index),"FreehandDraw"===e.type&&e.strokeWidth&&this.notify("freehand-draw",{prop:"setPenStrokeWidth",onPropertyChange:!1,value:{value:e.strokeWidth}});else if("text"!==e.type.toLowerCase()||"block"!==this.textArea.style.display&&"inline-block"!==this.textArea.style.display||(this.okBtn(null,!0),r=!0),this.notify("shape",{prop:"selectShape",onPropertyChange:!1,value:{id:e.id,obj:i}}),this.notify("selection",{prop:"getFreehandDrawEditing",onPropertyChange:!1,value:{obj:a}}),i.isSelected){var n=this.activeObj.textSettings.fontSize;if(this.notify("shape",{prop:"updateShapeChangeEventArgs",onPropertyChange:!1,value:{shapeSettings:e}}),"text"===this.activeObj.shape&&n){var s=this.activeObj.textSettings.fontSize-n;0!==s&&(this.activeObj.activePoint.height+=s,this.activeObj.activePoint.startY-=s/2,this.activeObj.activePoint.endY+=s/2,this.notify("draw",{prop:"updateActiveObject",onPropertyChange:!1,value:{actPoint:this.activeObj.activePoint,obj:this.activeObj,isMouseMove:null,x:null,y:null}}))}var l=t.extend({},this.activeObj,{},!0);this.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),this.notify("draw",{prop:"render-image",value:{isMouseWheel:null,isPreventClearRect:null,isFrame:null}}),this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),l.shape&&this.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate",obj:l}}),"text"===this.activeObj.shape&&this.notify("toolbar",{prop:"editText",onPropertyChange:!1}),a.bool&&this.notify("undo-redo",{prop:"setPreventUR",value:{bool:!0}}),this.okBtn(o,!0),a.bool&&this.notify("undo-redo",{prop:"setPreventUR",value:{bool:!1}}),this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),this.notify("draw",{prop:"redrawDownScale"}),r&&this.enableTextEditing(),o&&this.selectShape(e.id)}return i.isSelected},a.prototype.cloneShape=function(e){var t={isSelected:!1};return"shape"===e.split("_")[0]&&(this.notify("shape",{prop:"selectShape",onPropertyChange:!1,value:{id:e,obj:t}}),t.isSelected&&(this.notify("toolbar",{prop:"duplicateShape",onPropertyChange:!1,value:{isPreventUndoRedo:!1}}),this.okBtn(null,!0),this.notify("draw",{prop:"redrawDownScale"}))),t.isSelected},a.prototype.getImageFilter=function(e){var t=this.createElement("canvas").getContext("2d");return this.notify("filter",{prop:"updateAdj",value:{type:e.toLowerCase(),value:null,isPreview:!0,ctx:t}}),t.filter},a.prototype.enableTextEditing=function(){var e=t.extend({},this.activeObj,{},!0);e.order||(this.noPushUndo=!0,this.okBtn(),this.noPushUndo=!1,this.selectShape(e.currIndex),e.order=this.activeObj.order),this.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),this.notify("draw",{prop:"render-image",value:{isMouseWheel:null,isPreventClearRect:null,isFrame:!1}}),this.activeObj=e,this.notify("toolbar",{prop:"editText",onPropertyChange:!1})},a.prototype.canUndo=function(){var e=!1;return this.getUndoRedoColl().index>0&&(e=!0),e},a.prototype.canRedo=function(){var e=!1,t=this.getUndoRedoColl(),o=t.undoRedoColl,i=t.index;return o&&o.length>0&&i<o.length-1&&(e=!0),i===o.length?e=!1:0===i&&o.length>0?e=!0:i>0&&(e=!0),e},a.prototype.apply=function(){this.closeOverlayTbar(),this.okBtn(null,!0)},a.prototype.discard=function(){this.notify("draw",{prop:"performCancel",value:{isContextualToolbar:this.closeOverlayTbar(),isFinalCancel:!0}})},a.prototype.enableShapeDrawing=function(e,t){if(t&&(this.drawingShape=e.toLowerCase(),this.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1})),e&&t){this.currObjType.shape=e.toLowerCase(),this.activeObj.shape=this.currObjType.shape,this.currObjType.isDragging=this.currObjType.isCustomCrop=!1,this.activeObj.shapeDegree=this.transform.degree,this.activeObj.shapeFlip=this.transform.currFlipState,this.activeObj.textFlip=this.transform.currFlipState,this.activeObj.flipObjColl=[];var o={order:null};this.notify("shape",{prop:"getNewOrder",onPropertyChange:!1,value:{obj:o}}),this.activeObj.order=o.order,this.notify("selection",{prop:"annotate",value:{shape:this.currObjType.shape}}),"text"===this.currObjType.shape?this.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"text",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}}):this.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"shapes",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}}),this.notify("toolbar",{prop:"update-toolbar-items",onPropertyChange:!1})}else t||this.okBtn(null,!0)},a.prototype.bringToFront=function(e){this.selectShape(e)&&(this.updateShapeOrder(e,"bringToFront"),this.apply())},a.prototype.bringForward=function(e){this.selectShape(e)&&(this.updateShapeOrder(e,"bringForward"),this.apply())},a.prototype.sendToBack=function(e){this.selectShape(e)&&(this.updateShapeOrder(e,"sendToBack"),this.apply())},a.prototype.sendBackward=function(e){this.selectShape(e)&&(this.updateShapeOrder(e,"sendBackward"),this.apply())},a.prototype.clearImage=function(){this.reset(),this.isImageLoaded=!1,this.lowerContext.clearRect(0,0,this.lowerCanvas.width,this.lowerCanvas.height),this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height);var e=document.getElementById(this.element.id+"_bottomToolbar");t.Browser.isDevice&&e&&(document.getElementById(this.element.id+"_bottomToolbar").style.display="none"),this.notify("toolbar",{prop:"destroy-top-toolbar",onPropertyChange:!1}),this.notify("toolbar",{prop:"create-toolbar",onPropertyChange:!1}),this.notify("toolbar",{prop:"create-contextual-toolbar",onPropertyChange:!1});var o=document.getElementById(this.element.id+"_dropArea");o&&(o.style.display="block")},a.prototype.applyShapes=function(){if(!this.isUndoRedoStack){var e=["rectangle","ellipse","line","arrow","path","text","image"],t={bool:!1};this.notify("selection",{prop:"getFreehandDrawEditing",onPropertyChange:!1,value:{obj:t}}),(t.bool||this.togglePen||this.activeObj.shape&&-1!==e.indexOf(this.activeObj.shape)||this.drawingShape)&&this.okBtn(null,!0)}},a.prototype.closeOverlayTbar=function(){var e=!1,o={bool:null};if(this.notify("toolbar",{prop:"getFrameToolbar",onPropertyChange:!1,value:{obj:o}}),!o.bool&&this.element.querySelector(".e-contextual-toolbar-wrapper")){this.element.querySelector(".e-contextual-toolbar-wrapper").classList.contains("e-hide")||(e=!0);var i={bool:this.isStraightening};(!t.Browser.isDevice||t.Browser.isDevice&&!i.bool)&&this.element.querySelector(".e-contextual-toolbar-wrapper").classList.add("e-hide")}return e},a.prototype.toolbarTemplateFn=function(){var e,t=this.element.id+"_toolbar",o=this.element.querySelector("#"+this.element.id+"_toolbarArea");if(this.toolbarTemplate){if(this.toolbarFn=this.templateParser(this.toolbarTemplate),this.isReact)e=this.toolbarFn({type:"toolbar"},this,"Template",t)[0];else if(this.isAngular){var i=this.toolbarFn({type:"toolbar"},this,"Template",t);e=3===i[0].nodeType?i[1]:i[0]}else e=this.toolbarFn({type:"toolbar"},this,"Template",t)[0];o.appendChild(e),this.toolbarHeight=o.clientHeight,this.notify("toolbar",{prop:"setToolbarHeight",value:{height:this.toolbarHeight}}),this.renderReactTemplates()}},a.prototype.quickAccessToolbarTemplateFn=function(){var e,t=this.element.id+"_quickAccessToolbar",o=this.element.querySelector("#"+this.element.id+"_quickAccessToolbarArea");if(this.quickAccessToolbarTemplate){if(this.qatFn=this.templateParser(this.quickAccessToolbarTemplate),this.isReact)e=this.qatFn({type:"toolbar"},this,"Template",t)[0];else if(this.isAngular){var i=this.qatFn({type:"toolbar"},this,"Template",t);e=3===i[0].nodeType?i[1]:i[0]}else e=this.qatFn({type:"toolbar"},this,"Template",t)[0];o.appendChild(e),this.renderReactTemplates()}},a.prototype.templateParser=function(e){if(e)try{return"function"!=typeof e&&document.querySelectorAll(e).length?t.compile(document.querySelector(e).innerHTML.trim()):t.compile(e)}catch(o){return t.compile(e)}},a.prototype.getTextFromId=function(e){return{1:"none",2:"bar",3:"arrow",4:"arrowSolid",5:"circle",6:"circleSolid",7:"square",8:"squareSolid"}[""+e]},a.prototype.getFinetuneOption=function(t){return{brightness:e.ImageFinetuneOption.Brightness,contrast:e.ImageFinetuneOption.Contrast,hue:e.ImageFinetuneOption.Hue,saturation:e.ImageFinetuneOption.Saturation,opacity:e.ImageFinetuneOption.Opacity,blur:e.ImageFinetuneOption.Blur,exposure:e.ImageFinetuneOption.Exposure}[""+t]},a.prototype.setPenStroke=function(e){this.notify("freehand-draw",{prop:"setPenStrokeWidth",onPropertyChange:!1,value:{value:parseInt(e,10)}})},a.prototype.updateFreehandDrawColorChange=function(){var e={tempFreeHandDrawEditingStyles:null};this.notify("freehand-draw",{prop:"getTempFreeHandDrawEditingStyles",value:{obj:e}}),this.notify("freehand-draw",{prop:"color-change",value:{color:e.tempFreeHandDrawEditingStyles.strokeColor}})},a.prototype.getUndoRedoColl=function(){var e={undoRedoColl:null,index:null},t={undoRedoStep:null},o={appliedUndoRedoColl:[]};return this.notify("undo-redo",{prop:"getAppliedUndoRedoColl",value:{obj:o}}),this.notify("undo-redo",{prop:"getUndoRedoStep",value:{obj:t}}),e.undoRedoColl=o.appliedUndoRedoColl,e.index=t.undoRedoStep,e},a.prototype.updateImageTransformColl=function(e){var o;"rotateleft"===e?o=-90:"rotateright"===e?o=90:"horizontalflip"===e?o="horizontal":"verticalflip"===e&&(o="vertical");for(var i=0;i<this.objColl.length;i++){var r=this.objColl[i].shape;if("image"===r||"text"===r){t.isNullOrUndefined(this.objColl[i].rotateFlipColl)&&(this.objColl[i].rotateFlipColl=[]),this.objColl[i].rotateFlipColl.push(o);var a={collection:this.objColl[i].rotateFlipColl};this.notify("shape",{prop:"alignRotateFlipColl",onPropertyChange:!1,value:{collection:this.objColl[i].rotateFlipColl,isRotateFlipCollection:!1,obj:a}}),this.objColl[i].rotateFlipColl=a.collection}}},a.prototype.setInitialZoomState=function(){this.objColl.push(this.activeObj),this.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1});var e=this.isUndoRedo;this.isCropTab=!1,this.isUndoRedo=!0,this.transform.cropZoomFactor&&this.transform.cropZoomFactor>0?this.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:-this.transform.cropZoomFactor,zoomPoint:null,isResize:!0}}):this.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:Math.abs(this.transform.cropZoomFactor),zoomPoint:null,isResize:!0}}),this.isUndoRedo=e,this.panPoint.totalPannedPoint={x:0,y:0},this.transform.cropZoomFactor=0,this.notify("freehand-draw",{prop:"updateFHDColl",onPropertyChange:!1}),this.activeObj=t.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}})},a.prototype.updateCropTransformItems=function(){this.prevCurrSelectionPoint=t.extend({},this.currSelectionPoint,{},!0),this.notify("draw",{prop:"updateCropSelection",onPropertyChange:!1})},a.prototype.toPascalCase=function(e,o){var i=[];t.isNullOrUndefined(e)||(i=e.toLowerCase().split("-"));for(var r=0;r<i.length;r++)i[r]=i[r].charAt(0).toUpperCase()+i[r].slice(1);return o&&(o.maxText=i.join("")),i.join("")},a.prototype.getFontSizes=function(){var e=[];this.fontSizeColl=[];var t;t=0===this.transform.degree||this.transform.degree%180==0?this.img.destWidth/25:this.img.destHeight/25;for(var o=1;o<=10;o++)this.fontSizeColl.push({text:(o*Math.round(t/2)).toString()}),e.push({text:o.toString()});return e},a.prototype.okBtn=function(o,i){if(i){this.noPushUndo=!1;var r={activePoint:{startX:0,startY:0,endX:0,endY:0,width:0,height:0},flipObjColl:[],triangle:[],triangleRatio:[],order:null};this.notify("selection",{prop:"setTempActObj",onPropertyChange:!1,value:{obj:r}})}var a=this.element.querySelector(".e-contextual-toolbar-wrapper");a&&a.classList.remove("e-frame-wrapper");var n,s=!1;this.isResizeOkBtn=!0;var l=this.element.querySelector("#"+this.element.id+"_aspectratio"),p=this.element.querySelector("#"+this.element.id+"_nonaspectratio"),h=this.element.querySelector(".e-ie-toolbar-aspect-ratio-btn"),d=this.element.querySelector(".e-ie-toolbar-nonaspect-ratio-btn");if(void 0!==this.activeObj.shape&&(n=this.activeObj.shape.split("-")),void 0===n&&this.currObjType.isCustomCrop?s=!0:void 0!==n&&"crop"===n[0]&&(s=!0),this.allowDownScale=!0,(this.activeObj.shape&&"image"!==this.activeObj.shape||this.togglePen)&&!s){var c={shapeSettingsObj:{}};this.notify("selection",{prop:"updatePrevShapeSettings",onPropertyChange:!1,value:{obj:c}});var u=c.shapeSettingsObj;this.togglePen&&(u.type=e.ShapeType.FreehandDraw);var v={action:"apply",currentShapeSettings:t.extend({},u,{},!0)};this.trigger("shapeChange",v)}if(l||p){var g={width:null,height:null};this.notify("selection",{prop:"getNumTextValue",onPropertyChange:!1,value:{obj:g}});var f={x:g.width,y:g.height},C={prevCropObj:this.prevCropObj},b={prevObj:this.prevObj};if(f&&f.x&&f.y&&C.prevCropObj&&b.prevObj){p||d&&!d.classList.contains("e-hidden")?this.notify("transform",{prop:"resize",value:{width:f.x,height:f.y,isAspectRatio:!1}}):(l||h&&!h.classList.contains("e-hidden"))&&this.notify("transform",{prop:"resize",value:{width:f.x,height:null,isAspectRatio:!0}}),this.isResize=!1,this.aspectWidth=f.x,this.aspectHeight=f.y,this.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"main",isApplyBtn:!1,isCropping:!1,isZooming:null,cType:null}}),this.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:-this.transform.zoomFactor,zoomPoint:null,isResize:!0}}),this.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:b.prevObj.defaultZoom,zoomPoint:null,isResize:!0}}),b.prevObj.zoomFactor&&this.setProperties({zoomSettings:{zoomFactor:b.prevObj.zoomFactor}},!0),this.notify("transform",{prop:"setPreviousZoomValue",onPropertyChange:!1,value:{previousZoomValue:this.zoomSettings.zoomFactor}}),this.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"resize",previousObj:b.prevObj,previousObjColl:b.prevObj.objColl,previousPointColl:b.prevObj.pointColl,previousSelPointColl:b.prevObj.selPointColl,previousCropObj:C.prevCropObj,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),this.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"ok"}});var m=this.cancelCropSelection;!m||!t.isNullOrUndefined(p)&&p||(m.previousObj.aspectWidth=m.currentObj.aspectWidth=this.aspectWidth,m.previousObj.aspectHeight=m.currentObj.aspectHeight=this.aspectHeight,m.previousCropObj=t.extend({},this.cropObj,{},!0),m.currentCropObj=t.extend({},this.cropObj,{},!0),this.notify("draw",{prop:"updateCropSelObj"})),this.cancelCropSelection=null}else!f||0!==f.x&&0!==f.y?this.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"main",isApplyBtn:!1,isCropping:!1,isZooming:null,cType:null}}):this.notify("draw",{prop:"performCancel",value:{isContextualToolbar:null}});this.isAspectRatio=!1}var y=this.element.querySelector(".e-contextual-toolbar-wrapper .e-toolbar-item.e-selected"),P={bool:!1};this.notify("selection",{prop:"getFreehandDrawEditing",onPropertyChange:!1,value:{obj:P}});var j={bool:null};this.notify("toolbar",{prop:"getFrameToolbar",onPropertyChange:!1,value:{obj:j}});var x=document.querySelector("#"+this.element.id+"_sliderWrapper");if(y&&(this.currentFilter=y.children[0].children[0].id.replace("Canvas","")),s){if(0!==this.transform.straighten&&(0!==this.panPoint.totalPannedPoint.x||0!==this.panPoint.totalPannedPoint.y||0!==this.panPoint.totalPannedClientPoint.x||0!==this.panPoint.totalPannedClientPoint.y)){var w=this.prevStraightenedDegree;this.prevStraightenedDegree=this.transform.straighten,this.setStraighten(this.transform.straighten-3),this.setStraighten(this.transform.straighten+3),this.prevStraightenedDegree=w}this.isCroppedEvent=this.crop()}else if(this.togglePen)this.freeHandDraw(!1),this.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"ok"}}),this.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.lowerContext}}),this.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.upperContext}});else if("block"===this.textArea.style.display||"inline-block"===this.textArea.style.display)this.notify("shape",{prop:"redrawActObj",onPropertyChange:!1,value:{x:null,y:null,isMouseDown:null}}),this.lowerContext.clearRect(0,0,this.lowerCanvas.width,this.lowerCanvas.height),this.notify("draw",{prop:"redrawImgWithObj",onPropertyChange:!1}),t.isNullOrUndefined(o)&&this.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"ok"}}),this.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.lowerContext}}),this.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.upperContext}});else if(x||this.currObjType.isFiltered){this.initialAdjustmentValue=this.canvasFilter=this.lowerContext.filter,this.currObjType.isFiltered=!1;var O={value:null};this.notify("draw",{prop:"getTempAdjustmentValue",value:{obj:O}}),O.value===this.lowerContext.filter||x&&x.classList.contains("e-ie-finetune-slider-wrap")||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:null}})}else if(P.bool)this.notify("freehand-draw",{prop:"applyFhd",onPropertyChange:!1}),this.notify("selection",{prop:"setFreehandDrawCustomized",value:{isFreehandDrawCustomized:!1}}),this.notify("toolbar",{prop:"destroy-qa-toolbar"}),this.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"ok"}}),this.notify("freehand-draw",{prop:"resetFreehandDrawSelectedId",onPropertyChange:!1});else if(0!==this.activeObj.activePoint.width||0!==this.activeObj.activePoint.height||"path"===this.activeObj.shape&&this.activeObj.pointColl.length>0)"image"===this.activeObj.shape&&this.notify("draw",{prop:"setImageApply",onPropertyChange:!1,value:{bool:!0}}),this.notify("shape",{prop:"applyActObj",onPropertyChange:!1,value:{isMouseDown:null}});else{if(JSON.stringify(this.frameObj)!==JSON.stringify(this.tempFrameObj)){var S={currObj:{}};this.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:S}}),this.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"frame",previousObj:S.currObj,previousObjColl:S.currObj.objColl,previousPointColl:S.currObj.pointColl,previousSelPointColl:S.currObj.selPointColl,previousCropObj:t.extend({},this.cropObj,{},!0),previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),this.notify("draw",{prop:"render-image",value:{isMouseWheel:null,isPreventClearRect:null,isFrame:!0}}),this.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"ok"}}),this.tempFrameObj=t.extend({},this.frameObj,{},!0)}this.notify("draw",{prop:"resetFrameZoom",onPropertyChange:!1,value:{isOk:!0}})}P.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.transform.zoomFactor=this.transform.defaultZoomFactor,this.notify("selection",{prop:"setCurrentDrawingShape",onPropertyChange:!1,value:{value:""}}),this.isResizeOkBtn=!1,this.notify("draw",{prop:"redrawDownScale"}),this.isChangesSaved=!1,i&&(this.drawingShape=null,this.notify("draw",{prop:"resetTempObjColl"}),this.notify("draw",{prop:"resetTempPointColl"}))},a.prototype.getObjFromId=function(e){var o;if(this.activeObj.currIndex&&this.activeObj.currIndex===e)o=t.extend({},this.activeObj,{},!0);else for(var i=0;i<this.shapeColl.length;i++)if((this.shapeColl[i].id?this.shapeColl[i].id:this.shapeColl[i].currIndex)===e){o=t.extend({},this.shapeColl[i],{},!0);break}return o},a.prototype.setTempFilterProperties=function(){this.upperCanvas.style.display="block",this.cropSelectedState();var e={adjustmentLevel:null};this.notify("filter",{prop:"getAdjustmentLevel",onPropertyChange:!1,value:{obj:e}}),this.lowerContext.filter=this.initialAdjustmentValue,this.notify("draw",{prop:"setTempAdjustmentValue",value:{tempAdjustmentValue:this.lowerContext.filter}}),this.notify("filter",{prop:"setTempAdjustmentLevel",onPropertyChange:!1,value:{tempAdjustmentLevel:t.extend({},e.adjustmentLevel,{},!0)}}),this.notify("draw",{prop:"setTempFilter",value:{tempFilter:this.currentFilter}});var o={undoRedoStep:null};this.notify("undo-redo",{prop:"getUndoRedoStep",value:{obj:o}}),this.notify("draw",{prop:"setTempUndoRedoStep",value:{tempUndoRedoStep:o.undoRedoStep}})},a.prototype.cropSelectedState=function(){this.activeObj.shape&&"crop"===this.activeObj.shape.split("-")[0]&&this.okBtn()},a.prototype.getCurrentCanvasData=function(){var e=t.extend({},this.frameObj,{},!0);this.frameObj={type:"none",color:"#fff",size:20,inset:20,offset:20,radius:0,amount:1,border:"solid",gradientColor:""};var o=this.lowerContext.filter;this.lowerContext.filter=this.canvasFilter="none";var i=t.extend([],this.objColl,null,!0),r=t.extend([],this.pointColl,null,!0);this.objColl=[],this.pointColl=[],this.freehandCounter=0,this.notify("draw",{prop:"render-image",value:{isMouseWheel:!1}});var a=this.element.querySelector(".e-contextual-toolbar-wrapper");a&&a.classList.add("e-hide");var n=this.getImageData();return a&&a.classList.remove("e-hide"),t.Browser.isDevice||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.pointColl=r,this.freehandCounter=r.length,this.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"iterate",pen:"iterate",isPreventApply:null}}),this.lowerContext.filter=this.canvasFilter=o,this.frameObj=e,n},a.prototype.setCurrAdjustmentValue=function(e,t){var o={finetune:this.getFinetuneOption(e),value:t,cancel:!1};this.trigger("finetuneValueChanging",o),o.cancel||this.notify("filter",{prop:"setCurrAdjValue",value:{type:e.toLowerCase(),value:t}})},a.prototype.getSquarePointForPath=function(e){var t={startX:0,startY:0,endX:0,endY:0,width:0,height:0};if(e.pointColl.length>0){t={startX:e.pointColl[0].x,startY:e.pointColl[0].y,endX:e.pointColl[0].x,endY:e.pointColl[0].y};for(var o=1;o<e.pointColl.length;o++)e.pointColl[o].x<t.startX&&(t.startX=e.pointColl[o].x),e.pointColl[o].y<t.startY&&(t.startY=e.pointColl[o].y),e.pointColl[o].x>t.endX&&(t.endX=e.pointColl[o].x),e.pointColl[o].y>t.endY&&(t.endY=e.pointColl[o].y);t.width=t.endX-t.startX,t.height=t.endY-t.startY}return t},a.prototype.getSelectionType=function(e){var t={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","Crop2:3":"2:3","Crop3:4":"3:4","Crop4:5":"4:5","Crop5:7":"5:7","Crop9:16":"9:16"};return t[""+(e="crop-custom"===e?"CropCustom":e)]?t[""+e]:e.split("Crop")[1]},a.prototype.clearContext=function(e){e.clearRect(0,0,e.canvas.width,e.canvas.height),e.clearRect(0,0,e.canvas.height,e.canvas.width)},a.prototype.updateArrow=function(e,o){var i=!1,r=this.objColl.length;this.notify("shape",{prop:"pushActItemIntoObj"}),r!==this.objColl.length&&(i=!0);var a=t.extend({},this.cropObj,{},!0),n={currObj:{}},s={shapeSettingsObj:{}};this.notify("selection",{prop:"updatePrevShapeSettings",onPropertyChange:!1,value:{obj:s}});var l=s.shapeSettingsObj;this.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:n}});var p=n.currObj;p.objColl=t.extend([],this.objColl,[],!0),p.pointColl=t.extend([],this.pointColl,[],!0),p.afterCropActions=t.extend([],this.afterCropActions,[],!0),i&&this.objColl.pop(),"startArrow"===e?this.activeObj.start=this.getTextFromId(o):"endArrow"===e&&(this.activeObj.end=this.getTextFromId(o)),this.notify("shape",{prop:"setStrokeSettings",value:{strokeSettings:null,strokeColor:null,fillColor:null,strokeWidth:this.activeObj.strokeSettings.strokeWidth}}),this.objColl.push(this.activeObj),0===this.activeObj.activePoint.width&&0===this.activeObj.activePoint.height||this.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"shapeTransform",previousObj:p,previousObjColl:p.objColl,previousPointColl:p.pointColl,previousCropObj:a,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),this.notify("selection",{prop:"redrawShape",value:{obj:this.objColl[this.objColl.length-1]}}),t.Browser.isDevice?document.getElementById(this.element.id+"_bottomToolbar")&&t.getComponent(this.element.id+"_bottomToolbar","toolbar").refreshOverflow():document.getElementById(this.element.id+"_toolbar")&&t.getComponent(this.element.id+"_toolbar","toolbar").refreshOverflow();var h={action:e,currentShapeSettings:t.extend({},l,{},!0)};this.trigger("shapeChange",h)},a.prototype.updateFontFamily=function(e){this.notify("selection",{prop:"setInitialTextEdit",value:{bool:!1}});var o=!1,i=this.objColl.length;this.notify("shape",{prop:"pushActItemIntoObj"}),i!==this.objColl.length&&(o=!0);var r=t.extend([],this.objColl,[],!0),a=t.extend({},this.cropObj,{},!0),n={shapeSettingsObj:{}};this.notify("selection",{prop:"updatePrevShapeSettings",onPropertyChange:!1,value:{obj:n}});var s=n.shapeSettingsObj,l={currObj:{}};this.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:l}});var p=l.currObj;p.objColl=t.extend([],this.objColl,[],!0),p.pointColl=t.extend([],this.pointColl,[],!0),p.afterCropActions=t.extend([],this.afterCropActions,[],!0);var h={selPointColl:null};if(this.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:h}}),p.selPointColl=t.extend([],h.selPointColl,[],!0),o&&this.objColl.pop(),"block"===this.textArea.style.display||"inline-block"===this.textArea.style.display){this.notify("shape",{prop:"updateFontRatio",onPropertyChange:!1,value:{obj:this.activeObj,isTextArea:!0}});var d=this.activeObj.textSettings.fontFamily;this.activeObj.textSettings.fontFamily=this.toPascalCase(e),0===this.activeObj.activePoint.width&&0===this.activeObj.activePoint.height||this.notify("shape",{prop:"redraw-text"}),this.objColl.push(this.activeObj),0===this.activeObj.activePoint.width&&0===this.activeObj.activePoint.height||this.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"textAreaCustomization",previousObj:p,previousObjColl:p.objColl,previousPointColl:p.pointColl,previousSelPointColl:p.selPointColl,previousCropObj:a,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),this.objColl.pop(),this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height);var c=this.activeObj.activePoint.width+.25*this.activeObj.textSettings.fontSize;this.textArea.style.width=c+"px",this.textArea.style.fontFamily=this.toPascalCase(e),this.activeObj.textSettings.fontFamily=d,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 u=this.activeObj.textSettings.fontFamily=this.toPascalCase(e);this.notify("shape",{prop:"setTextSettings",onPropertyChange:!1,value:{textSettings:null,fontFamily:u,fontSize:null}}),0===this.activeObj.activePoint.width&&0===this.activeObj.activePoint.height||this.notify("shape",{prop:"redraw-text"}),this.objColl.push(this.activeObj),0===this.activeObj.activePoint.width&&0===this.activeObj.activePoint.height||this.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"shapeTransform",previousObj:p,previousObjColl:r,previousPointColl:t.extend([],this.pointColl,[],!0),previousSelPointColl:p.selPointColl,previousCropObj:a,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),this.notify("selection",{prop:"redrawShape",value:{obj:this.objColl[this.objColl.length-1]}})}var v={action:"font-family",currentShapeSettings:t.extend({},s,{},!0)};v.currentShapeSettings.fontFamily=this.textArea.style.fontFamily,this.trigger("shapeChange",v)},a.prototype.updateFontSize=function(e){var o=e;this.notify("selection",{prop:"setInitialTextEdit",value:{bool:!1}});var i=!1,r=this.objColl.length;this.notify("shape",{prop:"pushActItemIntoObj"}),r!==this.objColl.length&&(i=!0);var a=t.extend({},this.cropObj,{},!0),n={shapeSettingsObj:{}};this.notify("selection",{prop:"updatePrevShapeSettings",onPropertyChange:!1,value:{obj:n}});var s=n.shapeSettingsObj,l={currObj:{}};this.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:l}});var p=l.currObj;p.objColl=t.extend([],this.objColl,[],!0),p.pointColl=t.extend([],this.pointColl,[],!0),p.afterCropActions=t.extend([],this.afterCropActions,[],!0);var h={selPointColl:null};if(this.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:h}}),p.selPointColl=t.extend([],h.selPointColl,[],!0),i&&this.objColl.pop(),"block"===this.textArea.style.display||"inline-block"===this.textArea.style.display){this.notify("shape",{prop:"updateFontRatio",onPropertyChange:!1,value:{obj:this.activeObj,isTextArea:!0}});var d=this.activeObj.textSettings.fontSize;this.activeObj.textSettings.fontSize=parseInt(this.fontSizeColl[parseInt(o,10)-1].text,10),this.objColl.push(this.activeObj),0===this.activeObj.activePoint.width&&0===this.activeObj.activePoint.height||this.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"textAreaCustomization",previousObj:p,previousObjColl:p.objColl,previousPointColl:p.pointColl,previousSelPointColl:p.selPointColl,previousCropObj:a,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),this.objColl.pop();var c="";"bold"===this.textArea.style.fontWeight&&(c="bold "),"italic"===this.textArea.style.fontStyle&&(c="italic "),"bold"===this.textArea.style.fontWeight&&"italic"===this.textArea.style.fontStyle&&(c="italic bold "),this.upperContext.font=c+this.activeObj.textSettings.fontSize+"px "+this.textArea.style.fontFamily;var u=this.textArea.value.split("\n"),v={maxText:""};this.notify("shape",{prop:"getMaxText",onPropertyChange:!1,value:{isTextBox:!0,text:null,obj:v}});var g=v.maxText,f=this.upperContext.measureText(g).width+.5*this.activeObj.textSettings.fontSize;this.textArea.style.width=f+"px",this.textArea.style.height=u.length*(this.activeObj.textSettings.fontSize+.25*this.activeObj.textSettings.fontSize)+"px",this.activeObj.textSettings.fontSize=d,this.upperContext.font=this.activeObj.textSettings.fontSize+"px "+this.activeObj.textSettings.fontFamily,this.textArea.style.fontSize=parseInt(this.fontSizeColl[parseInt(o,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 C=this.activeObj.textSettings.fontSize=parseInt(this.fontSizeColl[parseInt(o,10)-1].text,10);this.notify("shape",{prop:"setTextSettings",onPropertyChange:!1,value:{textSettings:null,fontFamily:null,fontSize:C}}),this.upperContext.font=this.activeObj.textSettings.fontSize+"px "+this.activeObj.textSettings.fontFamily;var u=this.activeObj.keyHistory.split("\n"),v={maxText:""};this.notify("shape",{prop:"getMaxText",onPropertyChange:!1,value:{isTextBox:null,text:null,obj:v}});var b=v.maxText,f=this.upperContext.measureText(b).width+.5*this.activeObj.textSettings.fontSize,m=u.length*(this.activeObj.textSettings.fontSize+.25*this.activeObj.textSettings.fontSize);0===this.activeObj.activePoint.width&&0===this.activeObj.activePoint.height||(this.notify("selection",{prop:"setTextSelection",onPropertyChange:!1,value:{width:f,height:m}}),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),0===this.activeObj.activePoint.width&&0===this.activeObj.activePoint.height||this.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"shapeTransform",previousObj:p,previousObjColl:p.objColl,previousPointColl:p.pointColl,previousSelPointColl:p.selPointColl,previousCropObj:a,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),this.notify("selection",{prop:"redrawShape",value:{obj:this.objColl[this.objColl.length-1]}})}var y={action:"font-size",currentShapeSettings:t.extend({},s,{},!0)};y.currentShapeSettings.fontSize=this.activeObj.textSettings.fontSize,this.trigger("shapeChange",y)},a.prototype.updateFontColor=function(e){this.notify("selection",{prop:"setInitialTextEdit",value:{bool:!1}});var o=!1,i=this.objColl.length;this.notify("shape",{prop:"pushActItemIntoObj"}),i!==this.objColl.length&&(o=!0);var r=t.extend({},this.cropObj,{},!0),a={shapeSettingsObj:{}};this.notify("selection",{prop:"updatePrevShapeSettings",onPropertyChange:!1,value:{obj:a}});var n=a.shapeSettingsObj,s={currObj:{}};this.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:s}});var l=s.currObj;l.objColl=t.extend([],this.objColl,[],!0),l.pointColl=t.extend([],this.pointColl,[],!0),l.afterCropActions=t.extend([],this.afterCropActions,[],!0);var p={selPointColl:null};if(this.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:p}}),l.selPointColl=t.extend([],p.selPointColl,[],!0),o&&this.objColl.pop(),"none"===this.textArea.style.display)this.activeObj.strokeSettings.strokeColor=e,this.notify("shape",{prop:"setStrokeSettings",value:{strokeSettings:null,strokeColor:this.activeObj.strokeSettings.strokeColor,fillColor:null,strokeWidth:null}}),this.togglePen||(this.objColl.push(this.activeObj),0===this.activeObj.activePoint.width&&0===this.activeObj.activePoint.height||(this.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"shapeTransform",previousObj:l,previousObjColl:l.objColl,previousPointColl:l.pointColl,previousSelPointColl:l.selPointColl,previousCropObj:r,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||"inline-block"===this.textArea.style.display){this.textArea.style.color=e;var h=this.activeObj.strokeSettings.strokeColor;this.activeObj.strokeSettings.strokeColor=e,this.objColl.push(this.activeObj),0===this.activeObj.activePoint.width&&0===this.activeObj.activePoint.height||this.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"textAreaCustomization",previousObj:l,previousObjColl:l.objColl,previousPointColl:l.pointColl,previousSelPointColl:l.selPointColl,previousCropObj:r,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),this.objColl.pop(),this.activeObj.strokeSettings.strokeColor=h}else this.togglePen||(this.objColl.push(this.activeObj),0===this.activeObj.activePoint.width&&0===this.activeObj.activePoint.height||this.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"shapeTransform",previousObj:l,previousObjColl:l.objColl,previousPointColl:l.pointColl,previousSelPointColl:l.selPointColl,previousCropObj:r,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),0===this.activeObj.activePoint.width&&0===this.activeObj.activePoint.height||this.notify("selection",{prop:"redrawShape",value:{obj:this.objColl[this.objColl.length-1]}}));var d={action:"font-color",currentShapeSettings:t.extend({},n,{},!0)};d.currentShapeSettings.fillColor=e,this.trigger("shapeChange",d)},a.prototype.updatePenStrokeWidth=function(o){var i=t.extend([],this.pointColl,[],!0);this.updateFreehandDrawColorChange();var r=t.extend({},this.cropObj,{},!0),a={shapeSettingsObj:{}};this.notify("selection",{prop:"updatePrevShapeSettings",onPropertyChange:!1,value:{obj:a}});var n=a.shapeSettingsObj,s={currObj:{}};this.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:s}});var l=s.currObj;l.objColl=t.extend([],this.objColl,[],!0),l.pointColl=t.extend([],this.pointColl,[],!0),l.afterCropActions=t.extend([],this.afterCropActions,[],!0);var p={selPointColl:null};this.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:p}}),l.selPointColl=t.extend([],p.selPointColl,[],!0),this.pointColl=i,this.notify("selection",{prop:"setFreehandDrawCustomized",value:{isFreehandDrawCustomized:!0}}),this.setPenStroke(o);var h={bool:!1};if(this.notify("selection",{prop:"getFreehandDrawEditing",onPropertyChange:!1,value:{obj:h}}),h.bool){var d={penStrokeWidth:null};this.notify("freehand-draw",{prop:"getPenStrokeWidth",onPropertyChange:!1,value:{obj:d}}),this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),this.lowerContext.clearRect(0,0,this.lowerCanvas.width,this.lowerCanvas.height),this.notify("freehand-draw",{prop:"hoverFhd",onPropertyChange:!1,value:{strokeColor:null,strokeWidth:d.penStrokeWidth}});var c={freehandSelectedIndex:null};this.notify("freehand-draw",{prop:"getFreehandSelectedIndex",onPropertyChange:!1,value:{obj:c}}),this.pointColl[c.freehandSelectedIndex].strokeWidth=d.penStrokeWidth,this.notify("draw",{prop:"render-image",value:{isMouseWheel:null}}),this.notify("draw",{prop:"redrawDownScale"}),this.notify("freehand-draw",{prop:"hoverFhd",onPropertyChange:!1,value:{strokeColor:null,strokeWidth:d.penStrokeWidth}}),this.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"freehanddrawCustomized",previousObj:l,previousObjColl:l.objColl,previousPointColl:l.pointColl,previousSelPointColl:l.selPointColl,previousCropObj:r,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}})}n.type=e.ShapeType.FreehandDraw;var u={action:"stroke-width",currentShapeSettings:t.extend({},n,{},!0)};u.currentShapeSettings.strokeWidth=this.activeObj.strokeSettings.strokeWidth,this.trigger("shapeChange",u)},a.prototype.updatePenStrokeColor=function(o){var i=t.extend([],this.pointColl,[],!0);this.updateFreehandDrawColorChange();var r=t.extend({},this.cropObj,{},!0),a={shapeSettingsObj:{}};this.notify("selection",{prop:"updatePrevShapeSettings",onPropertyChange:!1,value:{obj:a}});var n=a.shapeSettingsObj,s={currObj:{}};this.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:s}});var l=s.currObj;l.objColl=t.extend([],this.objColl,[],!0),l.pointColl=t.extend([],this.pointColl,[],!0),l.afterCropActions=t.extend([],this.afterCropActions,[],!0);var p={selPointColl:null};this.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:p}}),l.selPointColl=t.extend([],p.selPointColl,[],!0),this.pointColl=i,this.notify("selection",{prop:"setFreehandDrawCustomized",value:{isFreehandDrawCustomized:!0}}),this.activeObj.strokeSettings.strokeColor=o;var h={freehandSelectedIndex:null};this.notify("freehand-draw",{prop:"getFreehandSelectedIndex",onPropertyChange:!1,value:{obj:h}}),null!==h.freehandSelectedIndex&&void 0!==h.freehandSelectedIndex&&(this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),this.notify("draw",{prop:"render-image",value:{isMouseWheel:null}}),this.notify("draw",{prop:"redrawDownScale"}),this.notify("freehand-draw",{prop:"hoverFhd",onPropertyChange:!1,value:{strokeColor:null,strokeWidth:null}}));var d={bool:!1};if(this.notify("selection",{prop:"getFreehandDrawEditing",onPropertyChange:!1,value:{obj:d}}),d.bool){var c={freehandSelectedIndex:null};this.notify("freehand-draw",{prop:"getFreehandSelectedIndex",onPropertyChange:!1,value:{obj:c}}),this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),this.pointColl[c.freehandSelectedIndex].strokeColor=o,this.notify("freehand-draw",{prop:"hoverFhd",onPropertyChange:!1,value:{strokeColor:o}}),this.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"freehanddrawCustomized",previousObj:l,previousObjColl:l.objColl,previousPointColl:l.pointColl,previousSelPointColl:l.selPointColl,previousCropObj:r,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}})}else this.togglePen||this.notify("selection",{prop:"redrawShape",value:{obj:this.activeObj}});n.type=e.ShapeType.FreehandDraw;var u={action:"stroke-color",currentShapeSettings:t.extend({},n,{},!0)};u.currentShapeSettings.strokeColor=o,this.trigger("shapeChange",u)},a.prototype.updateStrokeWidth=function(e){if(this.activeObj.shape&&("path"!==this.activeObj.shape||"path"===this.activeObj.shape&&this.activeObj.pointColl.length>0)){var o={shapeSettingsObj:{}};this.notify("selection",{prop:"updatePrevShapeSettings",onPropertyChange:!1,value:{obj:o}});var i=o.shapeSettingsObj,r=!1,a=this.objColl.length;this.notify("shape",{prop:"pushActItemIntoObj"}),a!==this.objColl.length&&(r=!0);var n=t.extend({},this.cropObj,{},!0),s={currObj:{}};this.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:s}});var l=s.currObj;l.objColl=t.extend([],this.objColl,[],!0),l.pointColl=t.extend([],this.pointColl,[],!0),l.afterCropActions=t.extend([],this.afterCropActions,[],!0);var p={selPointColl:null};this.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:p}}),l.selPointColl=t.extend([],p.selPointColl,[],!0),r&&this.objColl.pop(),this.activeObj.strokeSettings.strokeWidth=parseInt(e,10),"rectangle"!==this.activeObj.shape&&"ellipse"!==this.activeObj.shape||(this.activeObj.strokeSettings.strokeWidth=parseInt(e,10)-1),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),0===this.activeObj.activePoint.width&&0===this.activeObj.activePoint.height||this.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"shapeTransform",previousObj:l,previousObjColl:l.objColl,previousPointColl:l.pointColl,previousSelPointColl:l.selPointColl,previousCropObj:n,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),this.notify("selection",{prop:"redrawShape",value:{obj:this.objColl[this.objColl.length-1]}});var h={action:"stroke-width",currentShapeSettings:t.extend({},i,{},!0)};h.currentShapeSettings.strokeWidth=this.activeObj.strokeSettings.strokeWidth,this.trigger("shapeChange",h)}else this.activeObj.shape&&"path"===this.activeObj.shape&&0===this.activeObj.pointColl.length&&(this.activeObj.strokeSettings.strokeWidth=parseInt(e,10),this.activeObj.strokeSettings.strokeWidth*=2,this.notify("shape",{prop:"setStrokeSettings",value:{strokeSettings:null,strokeColor:null,fillColor:null,strokeWidth:this.activeObj.strokeSettings.strokeWidth}}))},a.prototype.updateStrokeColor=function(e){var o={shapeSettingsObj:{}};this.notify("selection",{prop:"updatePrevShapeSettings",onPropertyChange:!1,value:{obj:o}});var i=o.shapeSettingsObj;if(this.activeObj.shape&&("path"!==this.activeObj.shape||"path"===this.activeObj.shape&&this.activeObj.pointColl.length>0)){var r=!1,a=this.objColl.length;this.notify("shape",{prop:"pushActItemIntoObj"}),a!==this.objColl.length&&(r=!0);var n=t.extend({},this.cropObj,{},!0),s={currObj:{}};this.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:s}});var l=s.currObj;l.objColl=t.extend([],this.objColl,[],!0),l.pointColl=t.extend([],this.pointColl,[],!0),l.afterCropActions=t.extend([],this.afterCropActions,[],!0);var p={selPointColl:null};this.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:p}}),l.selPointColl=t.extend([],p.selPointColl,[],!0),r&&this.objColl.pop(),this.activeObj.strokeSettings.strokeColor=e,this.notify("shape",{prop:"setStrokeSettings",value:{strokeSettings:null,strokeColor:this.activeObj.strokeSettings.strokeColor,fillColor:null,strokeWidth:null}}),this.togglePen||(this.objColl.push(this.activeObj),0===this.activeObj.activePoint.width&&0===this.activeObj.activePoint.height||this.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"shapeTransform",previousObj:l,previousObjColl:l.objColl,previousPointColl:l.pointColl,previousSelPointColl:l.selPointColl,previousCropObj:n,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),this.notify("selection",{prop:"redrawShape",value:{obj:this.objColl[this.objColl.length-1]}}))}else this.activeObj.shape&&"path"===this.activeObj.shape&&0===this.activeObj.pointColl.length&&(this.activeObj.strokeSettings.strokeColor=e,this.notify("shape",{prop:"setStrokeSettings",value:{strokeSettings:null,strokeColor:this.activeObj.strokeSettings.strokeColor,fillColor:null,strokeWidth:null}}));var h={action:"stroke-color",currentShapeSettings:t.extend({},i,{},!0)};h.currentShapeSettings.strokeColor=e,this.trigger("shapeChange",h)},a.prototype.updateFillColor=function(e){var o={shapeSettingsObj:{}};this.notify("selection",{prop:"updatePrevShapeSettings",onPropertyChange:!1,value:{obj:o}});var i=o.shapeSettingsObj,r=!1,a=this.objColl.length;this.notify("shape",{prop:"pushActItemIntoObj"}),a!==this.objColl.length&&(r=!0);var n=t.extend({},this.cropObj,{},!0),s={currObj:{}};this.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:s}});var l=s.currObj;l.objColl=t.extend([],this.objColl,[],!0),l.pointColl=t.extend([],this.pointColl,[],!0),l.afterCropActions=t.extend([],this.afterCropActions,[],!0);var p={selPointColl:null};this.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:p}}),l.selPointColl=t.extend([],p.selPointColl,[],!0),r&&this.objColl.pop(),this.activeObj.strokeSettings.fillColor=e,this.notify("shape",{prop:"setStrokeSettings",value:{strokeSettings:null,strokeColor:null,fillColor:this.activeObj.strokeSettings.fillColor,strokeWidth:null}}),this.objColl.push(this.activeObj),0===this.activeObj.activePoint.width&&0===this.activeObj.activePoint.height||this.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"shapeTransform",previousObj:l,previousObjColl:l.objColl,previousPointColl:l.pointColl,previousSelPointColl:l.selPointColl,previousCropObj:n,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),this.notify("selection",{prop:"redrawShape",value:{obj:this.objColl[this.objColl.length-1]}});var h={action:"fill-color",currentShapeSettings:t.extend({},i,{},!0)};this.trigger("shapeChange",h)},a.prototype.horizontalFlip=function(e,o){var i,r;if(t.isNullOrUndefined(o)){t.isNullOrUndefined(this.activeObj.imageRatio)&&this.notify("shape",{prop:"updImgRatioForActObj",onPropertyChange:!1}),this.notify("shape",{prop:"pushActItemIntoObj"}),i=t.extend({},this.cropObj,{},!0);var a={currObj:{}};this.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:a}}),(r=a.currObj).objColl=t.extend([],this.objColl,[],!0),r.pointColl=t.extend([],this.pointColl,[],!0),r.afterCropActions=t.extend([],this.afterCropActions,[],!0);var n={selPointColl:null};this.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:n}}),r.selPointColl=t.extend([],n.selPointColl,[],!0),this.objColl.pop()}this.notify("toolbar",{prop:"refreshSlider"}),e.clearRect(0,0,this.activeObj.imageCanvas.width,this.activeObj.imageCanvas.height);var s=this.duplicateImage();this.notify("draw",{prop:"downScaleImgCanvas",onPropertyChange:!1,value:{ctx:this.activeObj.imageCanvas.getContext("2d"),isImgAnnotation:!0,isHFlip:!0,isVFlip:null}}),this.activeObj.activePoint=s,this.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate"}}),t.isNullOrUndefined(o)&&(this.objColl.push(this.activeObj),this.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"imageHFlip",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]}}))},a.prototype.verticalFlip=function(e,o){var i,r;if(t.isNullOrUndefined(o)){t.isNullOrUndefined(this.activeObj.imageRatio)&&this.notify("shape",{prop:"updImgRatioForActObj",onPropertyChange:!1}),this.notify("shape",{prop:"pushActItemIntoObj"}),i=t.extend({},this.cropObj,{},!0);var a={currObj:{}};this.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:a}}),(r=a.currObj).objColl=t.extend([],this.objColl,[],!0),r.pointColl=t.extend([],this.pointColl,[],!0),r.afterCropActions=t.extend([],this.afterCropActions,[],!0);var n={selPointColl:null};this.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:n}}),r.selPointColl=t.extend([],n.selPointColl,[],!0),this.objColl.pop()}this.notify("toolbar",{prop:"refreshSlider"}),e.clearRect(0,0,this.activeObj.imageCanvas.width,this.activeObj.imageCanvas.height);var s=this.duplicateImage();this.notify("draw",{prop:"downScaleImgCanvas",onPropertyChange:!1,value:{ctx:this.activeObj.imageCanvas.getContext("2d"),isImgAnnotation:!0,isHFlip:null,isVFlip:!0}}),this.activeObj.activePoint=s,this.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate"}}),t.isNullOrUndefined(o)&&(this.objColl.push(this.activeObj),this.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"imageVFlip",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]}}))},a.prototype.rotateImage=function(e){var o,i;t.isNullOrUndefined(this.activeObj.imageRatio)&&this.notify("shape",{prop:"updImgRatioForActObj",onPropertyChange:!1}),this.notify("shape",{prop:"pushActItemIntoObj"}),o=t.extend({},this.cropObj,{},!0);var r={currObj:{}};this.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:r}}),(i=r.currObj).objColl=t.extend([],this.objColl,[],!0),i.pointColl=t.extend([],this.pointColl,[],!0),i.afterCropActions=t.extend([],this.afterCropActions,[],!0);var a={selPointColl:null};this.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:a}}),i.selPointColl=t.extend([],a.selPointColl,[],!0),this.objColl.pop(),this.notify("toolbar",{prop:"refreshSlider"}),"rotleft"===e?this.activeObj.rotatedAngle-=Math.PI/180*90:this.activeObj.rotatedAngle+=Math.PI/180*90,this.notify("selection",{prop:"updPtCollForShpRot",onPropertyChange:!1,value:{obj:this.activeObj}}),this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),this.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate"}}),this.objColl.push(this.activeObj),this.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"imageRotate",previousObj:i,previousObjColl:i.objColl,previousPointColl:i.pointColl,previousSelPointColl:i.selPointColl,previousCropObj:o,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),this.notify("selection",{prop:"redrawShape",value:{obj:this.objColl[this.objColl.length-1]}}),this.notify("toolbar",{prop:"destroy-qa-toolbar"}),this.notify("toolbar",{prop:"renderQAT",onPropertyChange:!1,value:{isPenEdit:null}})},a.prototype.pascalToSplitWords=function(e){var o=(e=e.charAt(0).toUpperCase()+e.slice(1)).match(/[A-Z][a-z]+/g);return t.isNullOrUndefined(o)?e:o.map(function(e){return e.charAt(0).toUpperCase()+e.slice(1)}).join(" ")},a.prototype.getCurrAdjustmentValue=function(e){var t=100,o={freehandSelectedIndex:null};if(this.notify("freehand-draw",{prop:"getFreehandSelectedIndex",onPropertyChange:!1,value:{obj:o}}),"transparency"===e&&this.togglePen){i={penOpacity:1};this.notify("freehand-draw",{prop:"getPenOpacity",onPropertyChange:!1,value:{obj:i}}),t=100*i.penOpacity}else if("transparency"===e&&null!==o.freehandSelectedIndex&&void 0!==o.freehandSelectedIndex)t=100*this.pointColl[o.freehandSelectedIndex].opacity;else{var i={adjustmentLevel:null};this.notify("filter",{prop:"getAdjustmentLevel",onPropertyChange:!1,value:{obj:i}}),t={brightness:i.adjustmentLevel.brightness,contrast:i.adjustmentLevel.contrast,hue:i.adjustmentLevel.hue,saturation:i.adjustmentLevel.saturation,opacity:i.adjustmentLevel.opacity,blur:i.adjustmentLevel.blur,exposure:i.adjustmentLevel.exposure,transparency:i.adjustmentLevel.transparency,straighten:this.transform.straighten}[""+e]}return t},a.prototype.transformSelect=function(e){0!==this.transform.straighten||"rotateleft"!==e&&"rotateright"!==e||!this.activeObj.shape||-1===["crop-2:3","crop-3:2","crop-3:4","crop-4:3","crop-4:5","crop-5:4","crop-5:7","crop-7:5","crop-9:16","crop-16:9"].indexOf(this.activeObj.shape)&&(-1===this.activeObj.shape.indexOf("crop-")||"crop-custom"===this.activeObj.shape||"crop-square"===this.activeObj.shape||"crop-circle"===this.activeObj.shape)||(this.activeObj.shape="crop-"+this.activeObj.shape.split("-")[1].split(":")[1]+":"+this.activeObj.shape.split("-")[1].split(":")[0],this.notify("toolbar",{prop:"performCropTransformClick",value:{shape:this.activeObj.shape,isTransform:!0}})),this.isCropToolbar=!0,this.allowDownScale=!1;var o=this.transform.straighten,i=t.extend({},this.activeObj,{},!0),r=this.transform.zoomFactor;this.prevEventSelectionPoint=t.extend({},this.activeObj,{},!0);var a={currObj:{}};this.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:a}}),this.prevEventObjPoint=a.currObj,this.prevEventObjPoint.objColl=t.extend([],this.objColl,[],!0),this.prevEventObjPoint.pointColl=t.extend([],this.pointColl,[],!0),this.prevEventObjPoint.afterCropActions=t.extend([],this.afterCropActions,[],!0);var n={selPointColl:null};if(this.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:n}}),this.prevEventObjPoint.selPointColl=t.extend([],n.selPointColl,[],!0),0!==this.transform.straighten){this.transform.straighten=0,this.straightenBaseImageCanvas();for(var s=0,l=this.objColl.length;s<l;s++)"line"!==(h=this.objColl[s].shape)&&"arrow"!==h&&"path"!==h&&(this.objColl[s].rotatedAngle-=o*(Math.PI/180),this.notify("selection",{prop:"updPtCollForShpRot",onPropertyChange:!1,value:{obj:this.objColl[s]}}));this.notify("draw",{prop:"render-image",value:{isMouseWheel:!1}}),this.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"zoom",pen:"zoom",isPreventApply:null}})}this.setInitialZoomState();var p=t.extend({},this.activeObj,{},!0);if(this.notify("crop",{prop:"setTransformCrop",onPropertyChange:!1,value:{bool:!0}}),this.cropSelectedState(),this.notify("crop",{prop:"setTransformCrop",onPropertyChange:!1,value:{bool:!1}}),this.notify("draw",{prop:"resetCurrentSelectionPoint"}),this.updateImageTransformColl(e),this.notify("transform",{prop:"performTransformation",value:{text:e}}),this.isCropTab=!0,this.notify("draw",{prop:"moveToSelectionRange",value:{type:e,activeObj:p}}),!this.isStraightening||"horizontalflip"!==e&&"verticalflip"!==e||(this.notify("draw",{prop:"resetStraightenDestPoints"}),this.notify("draw",{prop:"setDestForStraighten"})),0!==o){this.transform.straighten=o,this.straightenBaseImageCanvas();for(var s=0,l=this.objColl.length;s<l;s++){var h=this.objColl[s].shape;"line"!==h&&"arrow"!==h&&"path"!==h&&(this.objColl[s].rotatedAngle+=o*(Math.PI/180),this.notify("selection",{prop:"updPtCollForShpRot",onPropertyChange:!1,value:{obj:this.objColl[s]}}))}this.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"zoom",pen:"zoom",isPreventApply:null}}),this.notify("draw",{prop:"render-image",value:{isMouseWheel:!1}}),this.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate",obj:i}}),this.notify("draw",{prop:"setStraightenActObj",value:{activeObj:null}}),this.notify("draw",{prop:"setStraightenInitZoom",value:{zoomFactor:r}}),(this.isStraightening&&("horizontalflip"===e||"verticalflip"===e)&&t.isNullOrUndefined(this.transform.zoomFactor)||0===this.transform.zoomFactor)&&(0===this.transform.degree?this.transform.zoomFactor+=.025:0===this.transform.zoomFactor&&(this.transform.zoomFactor=null)),this.notify("draw",{prop:"zoomToSel",value:{activeObj:i,isToolbar:!1}})}this.isCropToolbar=!1;var d=this.element.querySelector(".e-ie-straighten-value-span");d&&(d.innerHTML=this.transform.straighten.toString()+"&#176")},a.prototype.getDefaultFilter=function(){return"brightness(1) contrast(100%) hue-rotate(0deg) saturate(100%) opacity(1) blur(0px) sepia(0%) grayscale(0%) invert(0%)"},a.prototype.setStraighten=function(e){var t={cancel:!1,previousDegree:this.transform.straighten,currentDegree:e};this.trigger("rotating",t),t.cancel||this.performStraighten(t)},a.prototype.duplicateImage=function(){var e=t.extend({},this.activeObj.activePoint,{},!0),o={width:0,height:0};return this.notify("transform",{prop:"calcMaxDimension",onPropertyChange:!1,value:{width:this.activeObj.imageElement.width,height:this.activeObj.imageElement.height,obj:o,isImgShape:null}}),this.activeObj.activePoint.width=o.width,this.activeObj.activePoint.height=o.height,e},a.prototype.performStraighten=function(e){var o=e.currentDegree,i=this.element.querySelector(".e-ie-straighten-value-span");i&&(i.innerHTML=o.toString()+"&#176");var r=t.extend({},this.activeObj,null,!0);this.notify("freehand-draw",{prop:"setCenterSelPoints"}),this.transform.straighten=o,this.straightenPoint={x:this.activeObj.activePoint.startX+this.activeObj.activePoint.width/2,y:this.activeObj.activePoint.startY+this.activeObj.activePoint.height/2},this.straightenBaseImageCanvas();for(var a=0,n=this.objColl.length;a<n;a++){var s=this.objColl[a].shape;"line"!==s&&"arrow"!==s&&"path"!==s&&(this.objColl[a].rotatedAngle+=(this.transform.straighten-this.prevStraightenedDegree)*(Math.PI/180),this.notify("selection",{prop:"updPtCollForShpRot",onPropertyChange:!1,value:{obj:this.objColl[a]}}))}this.transform.degree%90==0&&this.transform.degree%180!=0?(0===this.transform.straighten&&(this.transform.straighten=360),this.notify("draw",{prop:"performPointZoom",onPropertyChange:!1,value:{x:this.activeObj.activePoint.startX+this.activeObj.activePoint.width/2,y:this.activeObj.activePoint.startY+this.activeObj.activePoint.height/2,type:"zoomIn",isResize:!0}}),this.notify("draw",{prop:"performPointZoom",onPropertyChange:!1,value:{x:this.activeObj.activePoint.startX+this.activeObj.activePoint.width/2,y:this.activeObj.activePoint.startY+this.activeObj.activePoint.height/2,type:"zoomOut",isResize:!0}}),360===this.transform.straighten&&(this.transform.straighten=0)):this.notify("draw",{prop:"render-image",value:{isMouseWheel:!0,isPreventClearRect:null,isFrame:null,isStraighten:!0}}),this.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate",obj:r}}),this.notify("draw",{prop:"zoomToSel",value:{activeObj:r,isToolbar:!0}}),this.notify("transform",{prop:"disableZoomOutBtn",value:{isZoomOut:!0}}),this.prevStraightenedDegree=this.transform.straighten},a.prototype.straightenBaseImageCanvas=function(){if(this.isImageLoaded){var e=this.getStraightenFlipState(),t="horizontal"===e||"vertical"===e?-this.transform.straighten:this.transform.straighten,o=this.baseImgCanvas.getContext("2d");if(o.canvas.width!==this.lowerContext.canvas.width&&o.canvas.height!==this.lowerContext.canvas.height){var i={width:0,height:0};this.notify("crop",{prop:"calcRatio",onPropertyChange:!1,value:{obj:i,dimension:{width:o.canvas.width,height:o.canvas.height}}})}var r=void 0;r=this.getRotatedCanvasDim(this.baseImg.width,this.baseImg.height,this.transform.straighten),this.img.srcWidth=o.canvas.width=r.width,this.img.srcHeight=o.canvas.height=r.height;var a=o.canvas.width/2,n=o.canvas.height/2;o.clearRect(0,0,o.canvas.width,o.canvas.height),o.translate(a,n),o.rotate(t*Math.PI/180),o.drawImage(this.baseImg,-this.baseImg.width/2,-this.baseImg.height/2,this.baseImg.width,this.baseImg.height),o.setTransform(1,0,0,1,0,0);var s={width:0,height:0};this.notify("crop",{prop:"calcRatio",onPropertyChange:!1,value:{obj:s,dimension:{width:o.canvas.width,height:o.canvas.height}}})}},a.prototype.getRotatedCanvasDim=function(e,t,o){var i=o*Math.PI/180,r=Math.cos(i),a=Math.sin(i),n=Math.min(0,e*r,t*Math.cos(Math.PI/2-i),e*r+t*Math.cos(Math.PI/2-i)),s=Math.max(0,e*r,t*Math.cos(Math.PI/2-i),e*r+t*Math.cos(Math.PI/2-i)),l=Math.min(0,e*a,t*Math.sin(Math.PI/2-i),e*a+t*Math.sin(Math.PI/2-i)),p=Math.max(0,e*a,t*Math.sin(Math.PI/2-i),e*a+t*Math.sin(Math.PI/2-i));return{width:Math.ceil(s-n),height:Math.ceil(p-l)}},a.prototype.updateShapeOrder=function(e,o){var i=this.getObjFromId(e);if(i.shape&&("path"!==i.shape||"path"===i.shape&&i.pointColl.length>0)||i&&i.id&&i.id.indexOf("pen")>-1){var r={shapeSettingsObj:{}};this.notify("selection",{prop:"updatePrevShapeSettings",onPropertyChange:!1,value:{obj:r}});var a=r.shapeSettingsObj;i.shape&&this.notify("shape",{prop:"pushActItemIntoObj"});var n=t.extend({},this.cropObj,{},!0),s={currObj:{}};this.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:s}});var l=s.currObj;l.objColl=t.extend([],this.objColl,[],!0),l.pointColl=t.extend([],this.pointColl,[],!0),l.afterCropActions=t.extend([],this.afterCropActions,[],!0);var p={selPointColl:null};this.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:p}}),l.selPointColl=t.extend([],p.selPointColl,[],!0),i.shape&&this.objColl.pop(),this.notify("shape",{prop:"z-order",onPropertyChange:!1,value:{obj:i,value:o}}),i.shape&&(this.notify("shape",{prop:"setStrokeSettings",value:{strokeSettings:null,strokeColor:null,fillColor:null,strokeWidth:i.strokeSettings.strokeWidth}}),this.objColl.push(i)),this.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"shapeTransform",previousObj:l,previousObjColl:l.objColl,previousPointColl:l.pointColl,previousSelPointColl:l.selPointColl,previousCropObj:n,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),i.shape&&(this.notify("selection",{prop:"redrawShape",value:{obj:this.objColl[this.objColl.length-1]}}),this.activeObj.order=i.order),{action:"stroke-width",previousShapeSettings:t.extend({},a,{},!0),currentShapeSettings:t.extend({},a,{},!0)}.currentShapeSettings.strokeWidth=this.activeObj.strokeSettings.strokeWidth}else this.activeObj.shape&&"path"===this.activeObj.shape&&0===this.activeObj.pointColl.length&&this.notify("shape",{prop:"setStrokeSettings",value:{strokeSettings:null,strokeColor:null,fillColor:null,strokeWidth:this.activeObj.strokeSettings.strokeWidth}})},a.prototype.getStraightenFlipState=function(){var e="";if(this.rotateFlipColl.length>0)for(var t=0,o=this.rotateFlipColl.length;t<o;t++){var i=this.rotateFlipColl[t];"horizontal"===i?e+="horizontal":"vertical"===i&&(e+="vertical"),"horizontalvertical"!==e&&"verticalhorizontal"!==e||(e="")}return e},a.prototype.initializeZoomSettings=function(){this.theme=t.isNullOrUndefined(this.theme)?"Bootstrap5":this.theme,(t.isNullOrUndefined(this.zoomSettings.zoomTrigger)||0===this.zoomSettings.zoomTrigger)&&(this.zoomSettings.zoomTrigger=e.ZoomTrigger.MouseWheel|e.ZoomTrigger.Pinch|e.ZoomTrigger.Toolbar|e.ZoomTrigger.Commands),t.isNullOrUndefined(this.selectionSettings.strokeColor)&&(this.selectionSettings.strokeColor=this.themeColl[this.theme].primaryColor),t.isNullOrUndefined(this.selectionSettings.fillColor)&&(this.selectionSettings.fillColor=this.themeColl[this.theme].secondaryColor)},a.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"},Fluent2:{primaryColor:"#0f6cbd",secondaryColor:"#fff"},Fluent2Dark:{primaryColor:"#115ea3",secondaryColor:"#fff"},Fluent2Highcontrast:{primaryColor:"#1aebff",secondaryColor:"#fff"}}};var n;return m([t.Property("")],a.prototype,"cssClass",void 0),m([t.Property(!1)],a.prototype,"disabled",void 0),m([t.Property("100%")],a.prototype,"height",void 0),m([t.Property("Bootstrap5")],a.prototype,"theme",void 0),m([t.Property()],a.prototype,"toolbar",void 0),m([t.Property()],a.prototype,"toolbarTemplate",void 0),m([t.Property("100%")],a.prototype,"width",void 0),m([t.Property(!0)],a.prototype,"allowUndoRedo",void 0),m([t.Property(!0)],a.prototype,"showQuickAccessToolbar",void 0),m([t.Property()],a.prototype,"quickAccessToolbarTemplate",void 0),m([t.Property(!1)],a.prototype,"isReadOnly",void 0),m([t.Property(!1)],a.prototype,"enableRtl",void 0),m([t.Property(!1)],a.prototype,"enablePersistence",void 0),m([t.Complex({},y)],a.prototype,"finetuneSettings",void 0),m([t.Complex({},P)],a.prototype,"zoomSettings",void 0),m([t.Complex({},j)],a.prototype,"selectionSettings",void 0),m([t.Complex({},x)],a.prototype,"fontFamily",void 0),m([t.Event()],a.prototype,"beforeSave",void 0),m([t.Event()],a.prototype,"created",void 0),m([t.Event()],a.prototype,"destroyed",void 0),m([t.Event()],a.prototype,"zooming",void 0),m([t.Event()],a.prototype,"panning",void 0),m([t.Event()],a.prototype,"cropping",void 0),m([t.Event()],a.prototype,"rotating",void 0),m([t.Event()],a.prototype,"flipping",void 0),m([t.Event()],a.prototype,"shapeChanging",void 0),m([t.Event()],a.prototype,"selectionChanging",void 0),m([t.Event()],a.prototype,"fileOpened",void 0),m([t.Event()],a.prototype,"saved",void 0),m([t.Event()],a.prototype,"toolbarCreated",void 0),m([t.Event()],a.prototype,"toolbarUpdating",void 0),m([t.Event()],a.prototype,"toolbarItemClicked",void 0),m([t.Event()],a.prototype,"imageFiltering",void 0),m([t.Event()],a.prototype,"finetuneValueChanging",void 0),m([t.Event()],a.prototype,"click",void 0),m([t.Event()],a.prototype,"shapeChange",void 0),m([t.Event()],a.prototype,"quickAccessToolbarOpen",void 0),m([t.Event()],a.prototype,"resizing",void 0),m([t.Event()],a.prototype,"quickAccessToolbarItemClick",void 0),m([t.Event()],a.prototype,"frameChange",void 0),a=n=m([t.NotifyPropertyChanges],a)}(t.Component);!function(e){e.Png="Png",e.Jpeg="Jpeg",e.Svg="Svg"}(e.FileType||(e.FileType={})),function(e){e.Horizontal="Horizontal",e.Vertical="Vertical"}(e.Direction||(e.Direction={})),function(e){e.Rectangle="Rectangle",e.Ellipse="Ellipse",e.Line="Line",e.Arrow="Arrow",e.Path="Path",e.Text="Text",e.FreehandDraw="FreehandDraw",e.Image="Image"}(e.ShapeType||(e.ShapeType={})),function(e){e[e.MouseWheel=1]="MouseWheel",e[e.Pinch=2]="Pinch",e[e.Commands=4]="Commands",e[e.Toolbar=8]="Toolbar"}(e.ZoomTrigger||(e.ZoomTrigger={})),function(e){e.Bootstrap5="Bootstrap5",e.Bootstrap5Dark="Bootstrap5Dark",e.Tailwind="Tailwind",e.TailwindDark="TailwindDark",e.Fluent="Fluent",e.FluentDark="FluentDark",e.Bootstrap4="Bootstrap4",e.Bootstrap="Bootstrap",e.BootstrapDark="BootstrapDark",e.Material="Material",e.MaterialDark="MaterialDark",e.Fabric="Fabric",e.FabricDark="FabricDark",e.Highcontrast="Highcontrast",e.Fluent2="Fluent2",e.Fluent2Dark="Fluent2Dark"}(e.Theme||(e.Theme={})),function(e){e.Crop="Crop",e.Transform="Transform",e.Annotate="Annotate",e.ZoomIn="ZoomIn",e.ZoomOut="ZoomOut",e.Open="Open",e.Reset="Reset",e.Save="Save",e.Pan="Pan",e.Move="Move",e.Pen="Pen",e.Line="Line",e.Arrow="Arrow",e.Path="Path",e.Rectangle="Rectangle",e.Image="Image",e.Ellipse="Ellipse",e.Text="Text",e.CustomSelection="CustomSelection",e.CircleSelection="CircleSelection",e.SquareSelection="SquareSelection",e.RatioSelection="RatioSelection",e.RotateLeft="RotateLeft",e.RotateRight="RotateRight",e.FlipHorizontal="FlipHorizontal",e.FlipVertical="FlipVertical",e.Undo="Undo",e.Redo="Redo",e.None="None",e.Mat="Mat",e.Bevel="Bevel",e.Inset="Inset",e.Hook="Hook",e.Finetune="Finetune",e.Filter="Filter",e.Frame="Frame",e.Resize="Resize",e.HorizontalFlip="HorizontalFlip",e.VerticalFlip="VerticalFlip",e.Brightness="Brightness",e.Contrast="Contrast",e.Hue="Hue",e.Saturation="Saturation",e.Opacity="Opacity",e.Blur="Blur",e.Exposure="Exposure",e.Default="Default",e.Chrome="Chrome",e.Cold="Cold",e.Warm="Warm",e.Grayscale="Grayscale",e.Sepia="Sepia",e.Invert="Invert",e.Straightening="Straightening"}(e.ImageEditorCommand||(e.ImageEditorCommand={})),function(e){e.Default="Default",e.Chrome="Chrome",e.Cold="Cold",e.Warm="Warm",e.Grayscale="Grayscale",e.Sepia="Sepia",e.Invert="Invert"}(e.ImageFilterOption||(e.ImageFilterOption={})),function(e){e.Brightness="Brightness",e.Contrast="Contrast",e.Hue="Hue",e.Saturation="Saturation",e.Exposure="Exposure",e.Opacity="Opacity",e.Blur="Blur"}(e.ImageFinetuneOption||(e.ImageFinetuneOption={})),function(e){e.None="None",e.Arrow="Arrow",e.SolidArrow="SolidArrow",e.Circle="Circle",e.SolidCircle="SolidCircle",e.Square="Square",e.SolidSquare="SolidSquare",e.Bar="Bar"}(e.ArrowheadType||(e.ArrowheadType={})),function(e){e.None="None",e.Mat="Mat",e.Bevel="Bevel",e.Line="Line",e.Inset="Inset",e.Hook="Hook"}(e.FrameType||(e.FrameType={})),function(e){e.Solid="Solid",e.Dashed="Dashed",e.Dotted="Dotted"}(e.FrameLineStyle||(e.FrameLineStyle={}));var O=function(){function s(e){this.defToolbarItems=[],this.toolbarHeight=46,this.currToolbar="",this.preventZoomBtn=!1,this.currentToolbar="main",this.selFhdColor="#42a5f5",this.preventEnableDisableUr=!1,this.isAspectRatio=!0,this.isFrameToolbar=!1,this.presetColors={custom:["#000000","#f44336","#e91e63","#9c27b0","#673ab7","#2196f3","#03a9f4","#00bcd4","#009688","#ffeb3b","#ffffff","#ffebee","#fce4ec","#f3e5f5","#ede7f6","#e3f2fd","#e1f5fe","#e0f7fa","#e0f2f1","#fffde7","#f2f2f2","#ffcdd2","#f8bbd0","#e1bee7","#d1c4e9","#bbdefb","#b3e5fc","#b2ebf2","#b2dfdb","#fff9c4","#e6e6e6","#ef9a9a","#f48fb1","#ce93d8","#b39ddb","#90caf9","#81d4fa","#80deea","#80cbc4","#fff59d","#cccccc","#e57373","#f06292","#ba68c8","#9575cd","#64b5f6","#4fc3f7","#4dd0e1","#4db6ac","#fff176","#b3b3b3","#ef5350","#ec407a","#ab47bc","#7e57c2","#42a5f5","#29b6f6","#26c6da","#26a69a","#ffee58","#999999","#e53935","#d81b60","#8e24aa","#5e35b1","#1e88e5","#039be5","#00acc1","#00897b","#fdd835","#808080","#d32f2f","#c2185b","#7b1fa2","#512da8","#1976d2","#0288d1","#0097a7","#00796b","#fbc02d","#666666","#c62828","#ad1457","#6a1b9a","#4527a0","#1565c0","#0277bd","#00838f","#00695c","#f9a825","#4d4d4d","#b71c1c","#880e4f","#4a148c","#311b92","#0d47a1","#01579b","#006064","#004d40","#f57f17"]},this.isSlider=!1,this.currentQuality=1,this.imageQuality="highest",this.parent=e,this.addEventListener(),this.initLocale()}return s.prototype.destroy=function(){this.parent.isDestroyed||this.removeEventListener()},s.prototype.addEventListener=function(){this.parent.on("toolbar",this.toolbar,this),this.parent.on("destroyed",this.destroy,this)},s.prototype.removeEventListener=function(){this.parent.off("toolbar",this.toolbar),this.parent.off("destroyed",this.destroy)},s.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:"Apply",Cancel:"Discard",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",Image:"Add Image",Transparency:"Transparency",Height:"Height",Width:"Width",AspectRatio:"Maintain aspect ratio",W:"W",H:"H",DragText:"Drag and drop your image here or",DropText:"Drop your image here or",BrowseText:"Browse here...",SupportText:"Supports:",Frame:"Frame",Mat:"Mat",Bevel:"Bevel",Inset:"Inset",Hook:"Hook",Color:"Color",Size:"Size",Offset:"Offset",Radius:"Radius",Amount:"Amount",Resize:"Resize",0:"0%",20:"20%",40:"40%",60:"60%",80:"80%",100:"100%",1:"1",2:"2",3:"3",4:"4",5:"5",Border:"Border",Solid:"Solid",Dashed:"Dashed",Dotted:"Dotted",GradientColor:"Gradient Color",ConfirmDialogHeader:"Confirm Save Changes",ConfirmDialogContent:"Do you want to save the changes you made to the image?",AlertDialogHeader:"Unsupported file",AlertDialogContent:"The selected file is unsupported.",Yes:"Yes",No:"No",ImageErrorDialogHeader:"Image Selection Error",ImageErrorDialogContent:"Please select only one image to open.",Straighten:"Straighten",NoOutline:"No outline",DlgOK:"OK",SaveAs:"Save As",ImageName:"Image name",Format:"Format",Quality:"Quality",Download:"Download",Close:"Close",ImageSize:"Image Size",QualityInfo:"The image quality option is only available for JPEG format",Good:"Good",Great:"Great",Highest:"Highest",BringForward:"Bring Forward",SendBackward:"Send Backward",SendToBack:"Send to Back",BringToFront:"Bring to Front",ZOrder:"Z-Order"},this.l10n=new t.L10n("image-editor",this.defaultLocale,this.parent.locale)},s.prototype.toolbar=function(e){var o=this.parent;switch(this.updatePrivateVariables(),e.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(e.value.type,e.value.isApplyBtn,e.value.isCropping,e.value.isZooming,e.value.cType);break;case"renderQAT":this.renderQAT(e.value.isPenEdit);break;case"enable-disable-btns":this.enableDisableTbrBtn();break;case"init-main-toolbar":this.initMainToolbar(e.value.isApplyBtn,e.value.isDevice,e.value.isOkBtn,e.value.isResize,e.value.isFrame,e.value.isMainToolbar);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(e.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(e.value.locale);break;case"setPreventZoomBtn":this.preventZoomBtn=e.value.isPrevent;break;case"getToolbarHeight":e.value.obj.toolbarHeight=this.toolbarHeight;break;case"setToolbarHeight":(t.isNullOrUndefined(o.toolbar)||o.toolbar&&o.toolbar.length>0&&o.toolbar.indexOf("Open")>-1)&&(this.toolbarHeight=e.value.height);break;case"setCurrentToolbar":this.currentToolbar=e.value.type;break;case"setSelectedFreehandColor":this.selFhdColor=e.value.color;break;case"setInitialAdjustmentValue":o.initialAdjustmentValue=e.value.value;break;case"getCanvasFilter":e.value.obj.canvasFilter=o.canvasFilter;break;case"getDefToolbarItems":e.value.obj.defToolbarItems=this.defToolbarItems;break;case"getPenStroke":this.getPenStroke(e.value.value);break;case"performDefToolbarClickAction":this.performDefTbrClick(e.value.type,e.value.isContextualToolbar,e.value.isDisabledAdjustment,e.value.isDisabledFilter,e.value.isFilterFinetune);break;case"setTempFilterProperties":o.setTempFilterProperties();break;case"refreshSlider":this.refreshSlider();break;case"getCurrAdjustmentValue":o.getCurrAdjustmentValue(e.value.type);break;case"setCurrAdjustmentValue":o.setCurrAdjustmentValue(e.value.type,e.value.value);break;case"refreshShapeDrawing":this.refreshShapeDrawing();break;case"setEnableDisableUndoRedo":this.preventEnableDisableUr=e.value.isPrevent;break;case"reset":this.reset();break;case"getLocaleText":e.value.obj.value=this.l10n.getConstant(e.value.obj.key);break;case"initResizeToolbar":this.initResizeToolbar();break;case"getFrameToolbar":e.value.obj.bool=this.isFrameToolbar;break;case"callFrameToolbar":this.callFrameToolbar();break;case"resizeClick":this.resizeClick();break;case"frameToolbarClick":this.frameToolbarClick();break;case"performCropTransformClick":this.performCropTransformClick(e.value.shape,e.value.isTransform);break;case"duplicateShape":this.duplicateShape(e.value.isPreventUndoRedo,!0);break;case"editText":this.editText();break;case"setInitialSize":this.initialSize=Number(e.value.value)}},s.prototype.updatePrivateVariables=function(){var e=this.parent;this.inMemoryCanvas=e.inMemoryCanvas,e.lowerCanvas&&(this.lowerContext=e.lowerCanvas.getContext("2d")),e.upperCanvas&&(this.upperContext=e.upperCanvas.getContext("2d")),this.inMemoryCanvas&&(this.inMemoryContext=this.inMemoryCanvas.getContext("2d"))},s.prototype.reset=function(){var e=this.parent;this.toolbarHeight=46,e.prevCurrSelectionPoint=null,this.zoomBtnHold=null,this.currToolbar="",e.cxtTbarHeight=null,this.currentToolbar="main",this.selFhdColor="#42a5f5",e.currentFilter="",this.preventZoomBtn=e.isCropToolbar=this.preventEnableDisableUr=this.isFrameToolbar=!1,e.initialAdjustmentValue=e.canvasFilter="brightness(1) contrast(100%) hue-rotate(0deg) saturate(100%) opacity(1) blur(0px) sepia(0%) grayscale(0%) invert(0%)",e.tempStraighten=0,e.isStraightening=!1},s.prototype.destroyTopToolbar=function(){var e=this.parent,o=document.getElementById(e.element.id+"_toolbar");this.isToolbar()&&o&&o.classList.contains("e-control")&&t.getComponent(o,"toolbar").destroy()},s.prototype.destroyBottomToolbar=function(){var e=this.parent,o=document.getElementById(e.element.id+"_bottomToolbar");o&&o.classList.contains("e-control")&&t.getComponent(o,"toolbar").destroy()},s.prototype.isToolbar=function(){var e=this.parent;return t.isNullOrUndefined(e.toolbar)||e.toolbar&&e.toolbar.length>0||!t.isNullOrUndefined(e.toolbarTemplate)},s.prototype.createToolbar=function(){var e=this,o=this.parent,a=o.element.id;if(t.isNullOrUndefined(o.toolbar)||o.toolbar&&o.toolbar.length>0){o.element.appendChild(o.createElement("div",{id:a+"_toolbarArea",className:"e-toolbar-area"}));var n={cssClass:"e-image-upload",align:"Left",type:"Input",tooltipText:this.l10n.getConstant("Browse"),template:new i.Uploader({allowedExtensions:".jpg, .jpeg, .png,.svg",multiple:!1})};t.isNullOrUndefined(this.defToolbarItems)&&(this.defToolbarItems=[]),this.defToolbarItems.push(n);var s=document.getElementById(a+"_toolbarArea"),l=o.createElement("div",{id:a+"_toolbar"});s.appendChild(l);var p=[{cssClass:"e-image-upload",align:"Left",type:"Input",tooltipText:this.l10n.getConstant("Browse"),template:new i.Uploader({allowedExtensions:".jpg, .jpeg, .png,.svg",multiple:!1,selected:function(){var i=document.getElementById(a+"_toolbar"),r=document.getElementById(a+"_bottomToolbar");o.disabled||(t.Browser.isDevice?(e.defToolbarItems.length>0&&i&&t.getComponent(i,"toolbar").destroy(),r&&t.getComponent(r,"toolbar").destroy(),e.initMainToolbar(!1,t.Browser.isDevice,null),e.createBottomToolbar()):(e.defToolbarItems.length>0&&i&&t.getComponent(i,"toolbar").destroy(),e.initMainToolbar(!1,!1,null)))}})}];new r.Toolbar({items:p,width:"100%",created:function(){o.trigger("toolbarCreated",{toolbarType:"main"})},clicked:this.defToolbarClicked.bind(this)}).appendTo("#"+a+"_toolbar"),this.createLeftToolbarControls();var h=document.getElementById(a+"_toolbar");if(l&&(this.toolbarHeight=h.clientHeight,o.toolbar&&o.toolbar.length>0&&-1===o.toolbar.indexOf("Open"))){var d=t.getComponent(document.getElementById(o.element.id+"_toolbar"),"toolbar");d&&(d.destroy(),document.getElementById(o.element.id+"_toolbar").innerHTML="")}}else this.toolbarHeight=0},s.prototype.createContextualToolbar=function(){var e=this.parent,o=e.element.id;if(t.isNullOrUndefined(e.toolbar)||e.toolbar&&e.toolbar.length>0){e.element.appendChild(e.createElement("div",{id:o+"_contextualToolbarArea",className:"e-contextual-toolbar-wrapper e-hide",attrs:{style:"position: absolute;"}}));var i=document.getElementById(o+"_contextualToolbarArea"),r=e.createElement("div",{id:o+"_contextualToolbar"});i.appendChild(r)}},s.prototype.createBottomToolbar=function(){var e=this.parent,o=e.element.id;if(e.element.querySelector("#"+o+"_bottomToolbarArea")&&e.element.querySelector("#"+o+"_bottomToolbarArea").remove(),t.isNullOrUndefined(e.toolbar)||e.toolbar&&e.toolbar.length>0){if(e.element.appendChild(e.createElement("div",{id:o+"_bottomToolbarArea",className:"e-bottom-toolbar"})),!e.toolbarTemplate){var i=document.getElementById(o+"_bottomToolbarArea"),r=e.createElement("div",{id:o+"_bottomToolbar"});i.appendChild(r)}this.initBottomToolbar()}},s.prototype.createQuickAccessToolbar=function(){var e=this.parent,o=e.element.id;if(e.showQuickAccessToolbar){var a={cssClass:"e-image-upload",align:"Left",type:"Input",tooltipText:this.l10n.getConstant("Browse"),template:new i.Uploader({allowedExtensions:".jpg, .jpeg, .png,.svg",multiple:!1})};t.isNullOrUndefined(this.defToolbarItems)&&(this.defToolbarItems=[]),this.defToolbarItems.push(a);var n=document.getElementById(o+"_quickAccessToolbarArea"),s=e.createElement("div",{id:o+"_quickAccessToolbar"});n.appendChild(s),new r.Toolbar({clicked:this.defToolbarClicked.bind(this)}).appendTo("#"+o+"_quickAccessToolbar")}},s.prototype.initMainToolbar=function(e,o,i,a,n,s){var l=this,p=this.parent,h=p.element.id;if(this.isToolbar()){var d=this.getLeftToolbarItem(i,a),c=this.getRightToolbarItem(i,s),u=this.getMainToolbarItem(e,n),v=this.getZoomToolbarItem();this.defToolbarItems=o?n?u:d.concat(c):d.concat(u,c,v);var g={toolbarType:"main",toolbarItems:this.defToolbarItems};if(p.trigger("toolbarUpdating",g),this.defToolbarItems=g.toolbarItems,this.defToolbarItems.length>0){var f=new r.Toolbar({width:"100%",items:this.defToolbarItems,clicked:this.defToolbarClicked.bind(this),created:function(){o||l.renderAnnotationBtn(),l.wireZoomBtnEvents(),p.trigger("toolbarCreated",{toolbarType:"main"})}});o&&n?f.appendTo("#"+h+"_bottomToolbar"):f.appendTo("#"+h+"_toolbar"),this.createLeftToolbarControls(),this.enableDisableTbrBtn(),this.isToolbar()&&document.getElementById(h+"_toolbar")&&t.getComponent(h+"_toolbar","toolbar").refreshOverflow()}}},s.prototype.initBottomToolbar=function(){var e=this,o=this.parent,i=o.element.id;if(t.isNullOrUndefined(o.toolbar)||o.toolbar&&o.toolbar.length>0){var a=this.getMainToolbarItem(),n={toolbarType:"bottom-toolbar",toolbarItems:a};o.trigger("toolbarUpdating",n),a=n.toolbarItems,new r.Toolbar({items:a,width:"100%",created:function(){e.renderAnnotationBtn(),e.renderCropBtn(),e.renderTransformBtn(),o.trigger("toolbarCreated",{toolbarType:"main"})},clicked:this.defToolbarClicked.bind(this)}).appendTo("#"+i+"_bottomToolbar"),this.defToolbarItems.length>0&&document.getElementById(i+"_bottomToolbar")&&t.getComponent(i+"_bottomToolbar","toolbar").refreshOverflow()}},s.prototype.getLeftToolbarItem=function(o,r){var a=this.parent,n=a.element.id,s=[];o&&!r||(t.isNullOrUndefined(a.toolbar)||a.toolbar&&a.toolbar.indexOf("Open")>-1?(s.push({id:n+"_upload",cssClass:"e-image-upload",align:"Left",type:"Input",template:new i.Uploader({allowedExtensions:".jpg, .jpeg, .png,.svg",multiple:!1})}),s.push({visible:!1,cssClass:"e-image-position e-btn e-flat",tooltipText:this.l10n.getConstant("Browse"),align:"Left"})):t.Browser.isDevice&&a.toolbar&&-1===a.toolbar.indexOf("Open")&&(s.push({visible:!1,id:n+"_upload",cssClass:"e-image-upload",align:"Left",type:"Input",template:new i.Uploader({allowedExtensions:".jpg, .jpeg, .png,.svg",multiple:!1})}),s.push({visible:!1,cssClass:"e-image-position e-btn e-flat",tooltipText:this.l10n.getConstant("Browse"),align:"Left"}))),a.allowUndoRedo&&!r&&((t.isNullOrUndefined(a.toolbar)||a.toolbar&&a.toolbar.indexOf("Undo")>-1)&&s.push({id:n+"_undo",prefixIcon:"e-icons e-undo",cssClass:"top-icon e-undo",tooltipText:this.l10n.getConstant("Undo"),align:"Left"}),(t.isNullOrUndefined(a.toolbar)||a.toolbar&&a.toolbar.indexOf("Redo")>-1)&&s.push({id:n+"_redo",prefixIcon:"e-icons e-redo",cssClass:"top-icon e-redo",tooltipText:this.l10n.getConstant("Redo"),align:"Left"})),this.preventZoomBtn||(a.zoomSettings.zoomTrigger&e.ZoomTrigger.Toolbar)!==e.ZoomTrigger.Toolbar||r||((t.isNullOrUndefined(a.toolbar)||a.toolbar&&a.toolbar.indexOf("ZoomOut")>-1)&&s.push({id:n+"_zoomOut",prefixIcon:"e-icons e-zoom-out",cssClass:"top-icon e-dec-zoom",tooltipText:this.l10n.getConstant("ZoomOut"),align:"Left"}),(t.isNullOrUndefined(a.toolbar)||a.toolbar&&a.toolbar.indexOf("ZoomIn")>-1)&&s.push({id:n+"_zoomIn",prefixIcon:"e-icons e-zoom-in",cssClass:"top-icon e-inc-zoom",tooltipText:this.l10n.getConstant("ZoomIn"),align:"Left"}));for(var l=this.processToolbar("left"),p=0,h=l.length;p<h;p++)s.push(l[p]);return s},s.prototype.getRightToolbarItem=function(e,o){var i=this.parent,r=i.element.id,a=[];e&&(a.push({id:r+"_ok",prefixIcon:"e-icons e-check",cssClass:"top-icon e-tick",tooltipText:this.l10n.getConstant("OK"),align:"Right",tabIndex:0}),a.push({id:r+"_cancel",prefixIcon:"e-icons e-close",cssClass:"top-icon e-save",tooltipText:this.l10n.getConstant("Cancel"),align:"Right"})),!o&&t.Browser.isDevice||!(t.isNullOrUndefined(i.toolbar)||i.toolbar&&i.toolbar.indexOf("Reset")>-1)||a.push({id:r+"_reset",prefixIcon:"e-icons e-btn-reset",cssClass:"top-icon e-img-reset",tooltipText:this.l10n.getConstant("Reset"),align:"Right"}),e||(t.isNullOrUndefined(i.toolbar)||i.toolbar&&i.toolbar.indexOf("Save")>-1)&&a.push({id:r+"_save",prefixIcon:"e-icons e-btn-save",cssClass:"e-caret-hide top-icon e-save",tooltipText:this.l10n.getConstant("Save"),align:"Right"});for(var n=this.processToolbar("right"),s=0,l=n.length;s<l;s++)a.push(n[s]);return a},s.prototype.getMainToolbarItem=function(e,o){var i=this.parent,r=i.element.id,a=[];o?((t.isNullOrUndefined(i.toolbar)||!t.isNullOrUndefined(i.toolbar)&&i.toolbar.indexOf("None")>-1||i.toolbar.indexOf("Frame")>-1)&&a.push({id:r+"_none",prefixIcon:"e-icons e-frame-none",cssClass:"top-icon e-frame-none",tooltipText:this.l10n.getConstant("None"),align:"Center"}),(t.isNullOrUndefined(i.toolbar)||!t.isNullOrUndefined(i.toolbar)&&i.toolbar.indexOf("Mat")>-1||i.toolbar.indexOf("Frame")>-1)&&a.push({id:r+"_mat",prefixIcon:"e-icons e-frame-mat",cssClass:"top-icon e-frame-mat",tooltipText:this.l10n.getConstant("Mat"),align:"Center"}),(t.isNullOrUndefined(i.toolbar)||!t.isNullOrUndefined(i.toolbar)&&i.toolbar.indexOf("Bevel")>-1||i.toolbar.indexOf("Frame")>-1)&&a.push({id:r+"_bevel",prefixIcon:"e-icons e-frame-bevel",cssClass:"top-icon e-frame-bevel",tooltipText:this.l10n.getConstant("Bevel"),align:"Center"}),(t.isNullOrUndefined(i.toolbar)||!t.isNullOrUndefined(i.toolbar)&&i.toolbar.indexOf("Line")>-1||i.toolbar.indexOf("Frame")>-1)&&a.push({id:r+"_line",prefixIcon:"e-icons e-frame-line",cssClass:"top-icon e-frame-line",tooltipText:this.l10n.getConstant("Line"),align:"Center"}),(t.isNullOrUndefined(i.toolbar)||!t.isNullOrUndefined(i.toolbar)&&i.toolbar.indexOf("Inset")>-1||i.toolbar.indexOf("Frame")>-1)&&a.push({id:r+"_inset",prefixIcon:"e-icons e-frame-inset",cssClass:"top-icon e-frame-inset",tooltipText:this.l10n.getConstant("Inset"),align:"Center"}),(t.isNullOrUndefined(i.toolbar)||!t.isNullOrUndefined(i.toolbar)&&i.toolbar.indexOf("Hook")>-1||i.toolbar.indexOf("Frame")>-1)&&a.push({id:r+"_hook",prefixIcon:"e-icons e-frame-hook",cssClass:"top-icon e-frame-hook",tooltipText:this.l10n.getConstant("Hook"),align:"Center"})):((t.isNullOrUndefined(i.toolbar)||i.toolbar&&i.toolbar.indexOf("Crop")>-1)&&a.push({id:r+"_cropTransform",prefixIcon:"e-icons e-crop",cssClass:"top-icon e-crop",tooltipText:this.l10n.getConstant("CropAndTransform"),align:"Center"}),(t.isNullOrUndefined(i.toolbar)||i.toolbar&&i.toolbar.indexOf("Annotate")>-1)&&a.push({id:r+"_annotation",tooltipText:this.l10n.getConstant("Annotation"),align:"Center",template:'<button id="'+r+'_annotationBtn"></button>'}),(t.isNullOrUndefined(i.toolbar)||i.toolbar&&i.toolbar.indexOf("Finetune")>-1)&&a.push({id:r+"_adjustment",prefixIcon:"e-icons e-adjustment",cssClass:"top-icon e-adjustment",tooltipText:this.l10n.getConstant("Finetune"),align:"Center"}),(t.isNullOrUndefined(i.toolbar)||i.toolbar&&i.toolbar.indexOf("Filter")>-1)&&a.push({id:r+"_filter",prefixIcon:"e-icons e-filters",cssClass:"top-icon e-filters",tooltipText:this.l10n.getConstant("Filter"),align:"Center"}),(t.isNullOrUndefined(i.toolbar)||!t.isNullOrUndefined(i.toolbar)&&i.toolbar.indexOf("Frame")>-1)&&a.push({id:r+"_frame",prefixIcon:"e-icons e-border-frame",cssClass:"top-icon e-border-frame",tooltipText:this.l10n.getConstant("Frame"),align:"Center"}),(t.isNullOrUndefined(i.toolbar)||!t.isNullOrUndefined(i.toolbar)&&i.toolbar.indexOf("Resize")>-1)&&a.push({id:r+"_resize",prefixIcon:"e-icons e-resize",cssClass:"top-icon e-resize",tooltipText:this.l10n.getConstant("Resize"),align:"Center"}));for(var n=this.processToolbar("center"),s=0,l=n.length;s<l;s++)a.push(n[s]);return e&&(a.push({id:r+"_ok",prefixIcon:"e-icons e-check",cssClass:"top-icon e-tick",tooltipText:this.l10n.getConstant("OK"),align:"Right",tabIndex:0}),a.push({id:r+"_cancel",prefixIcon:"e-icons e-close",cssClass:"top-icon e-save",tooltipText:this.l10n.getConstant("Cancel"),align:"Right"})),a},s.prototype.getZoomToolbarItem=function(){return[]},s.prototype.updateContextualToolbar=function(e,o,i){var r=this.parent,a=r.element.id,n=r.element.querySelector("#"+a+"_toolbarArea"),s=r.element.querySelector("#"+a+"_contextualToolbarArea");if(s){if(s.classList.remove("e-hide"),s.style.left=n.offsetLeft+"px","filter"===e){var l=document.getElementById(a+"_toolbar");l&&this.defToolbarItems.length>0&&t.getComponent(l,"toolbar").destroy(),t.Browser.isDevice?this.initMainToolbar(!1,!0,!0):this.initMainToolbar(!0,null,null),this.refreshSlider(),this.initFilterToolbarItem()}else(c=document.querySelector("#"+a+"_contextualToolbar")).classList.contains("e-control")&&t.getComponent(c,"toolbar").destroy(),this.refreshSlider(),"frame"===e?this.initFrameToolbarItem():this.renderSlider(o,i);if(r.toolbarTemplate?this.toolbarHeight=r.element.querySelector("#"+a+"_toolbarArea").clientHeight:r.element.querySelector("#"+a+"_toolbar")&&(this.toolbarHeight=r.element.querySelector("#"+a+"_toolbar").clientHeight),r.toolbarHeight=this.toolbarHeight,t.Browser.isDevice){var p=s.offsetHeight+1,h=r.element.querySelector("#"+a+"_customizeWrapper");this.isFrameToolbar&&h&&(p=h.offsetHeight+2);var d=r.element.querySelector("#"+a+"_canvasWrapper").offsetHeight;if(s.style.top=this.toolbarHeight+1+d-p+"px","straighten"===o){r.isStraightening=!0;var c=r.element.querySelector("#"+a+"_contextualToolbarArea");"absolute"===c.style.position&&(c.style.position="",r.element.insertBefore(c,r.element.querySelector("#"+a+"_bottomToolbarArea")),r.update(),i&&r.notify("draw",{prop:"select",onPropertyChange:!1,value:{type:this.getCropTextContent(document.getElementById(a+"_cropBtn")).toLowerCase(),startX:null,startY:null,width:null,height:null}}))}}else s.style.top=this.toolbarHeight+1+"px"}},s.prototype.processToolbar=function(e){var o=this.parent,i=[];if(o.toolbar)for(var r=0,a=o.toolbar.length;r<a;r++)"object"==typeof o.toolbar[r]&&(t.isNullOrUndefined(o.toolbar[r].align)?"left"===e&&i.push(o.toolbar[r]):o.toolbar[r].align.toLowerCase()===e&&i.push(o.toolbar[r]));return i},s.prototype.processSubToolbar=function(e){var t=[];if(e)for(var o=0,i=e.length;o<i;o++)"object"==typeof e[o]&&(e[o].align="Center",t.push(e[o]));return t},s.prototype.wireZoomBtnEvents=function(){var e=document.querySelector("#"+this.parent.element.id+"_zoomIn"),t=document.querySelector("#"+this.parent.element.id+"_zoomOut");e&&(e.addEventListener("mousedown",this.zoomInBtnMouseDownHandler.bind(this)),e.addEventListener("mouseup",this.zoomBtnMouseUpHandler.bind(this)),e.addEventListener("click",this.zoomInBtnClickHandler.bind(this)),e.addEventListener("touchstart",this.zoomInBtnClickHandler.bind(this))),t&&(t.addEventListener("mousedown",this.zoomOutBtnMouseDownHandler.bind(this)),t.addEventListener("mouseup",this.zoomBtnMouseUpHandler.bind(this)),t.addEventListener("click",this.zoomOutBtnClickHandler.bind(this)),e.addEventListener("touchstart",this.zoomInBtnClickHandler.bind(this)))},s.prototype.widthPress=function(e){if(109===e.keyCode)return void e.preventDefault()},s.prototype.heightPress=function(e){if(109===e.keyCode)return void e.preventDefault()},s.prototype.widthAspectRatio=function(e){if(109!==e.keyCode&&9!==e.keyCode){var o=this.parent,i=o.element.id,r=o.element.querySelector("#"+i+"_resizeHeight"),a=o.element.querySelector("#"+i+"_resizeWidth"),n=o.element.querySelector("#"+i+"_aspectratio"),s=o.img.destWidth,l=o.img.destHeight,p=parseFloat(r.value)/(l/s),h=p%1>=.5||p%1<=-.5?Math.round(p):p<0?Math.ceil(p):Math.floor(p),d=t.getComponent(a,"numerictextbox"),c=t.getComponent(a,"numerictextbox");n&&(null==h||isNaN(h)?t.isNullOrUndefined(d.value)?(d.placeholder="0 px",a.placeholder="0 px",t.isNullOrUndefined(c.value)&&!t.isNullOrUndefined(c.placeholder)&&(d.placeholder=""+o.img.srcWidth,a.placeholder=""+o.img.srcWidth)):(d.value=0,a.value="0 px"):t.isNullOrUndefined(d.value)?(d.placeholder=h+" px",a.placeholder=h.toString()+" px"):(d.value=h,a.value=h.toString()+" px"))}},s.prototype.heightAspectRatio=function(e){if(109!==e.keyCode&&9!==e.keyCode){var o=this.parent,i=o.element.id,r=o.element.querySelector("#"+i+"_resizeHeight"),a=o.element.querySelector("#"+i+"_resizeWidth"),n=o.element.querySelector("#"+i+"_aspectratio"),s=o.img.destWidth,l=o.img.destHeight,p=parseFloat(a.value)/(s/l),h=p%1>=.5||p%1<=-.5?Math.round(p):p<0?Math.ceil(p):Math.floor(p),d=t.getComponent(r,"numerictextbox"),c=t.getComponent(a,"numerictextbox");n&&(isNaN(h)?t.isNullOrUndefined(d.value)?(d.placeholder="0 px",r.placeholder="0 px",t.isNullOrUndefined(c.value)&&!t.isNullOrUndefined(c.placeholder)&&(d.placeholder=""+o.img.srcHeight,r.placeholder=""+o.img.srcHeight)):(d.value=0,r.value="0 px"):t.isNullOrUndefined(d.value)?(d.placeholder=h+" px",r.placeholder=h.toString()+" px"):(d.value=h,r.value=h.toString()+" px"))}},s.prototype.getResizeToolbarItem=function(){var e=this.parent,o=e.element.id,r=!(!e.aspectWidth||!e.aspectHeight),a=this.parent.transform.degree%90==0&&this.parent.transform.degree%180!=0?Math.ceil(this.parent.img.srcHeight).toString():Math.ceil(this.parent.img.srcWidth).toString(),n=this.parent.transform.degree%90==0&&this.parent.transform.degree%180!=0?Math.ceil(this.parent.img.srcWidth).toString():Math.ceil(this.parent.img.srcHeight).toString(),s=[],l=document.createElement("span");l.innerHTML=this.l10n.getConstant("W"),s.push({id:o+"_width",cssClass:"e-ie-resize-width",template:l,align:"Center"}),s.push({id:o+"_resizeWidth",prefixIcon:"e-icons e-anti-clock-wise",tooltipText:this.l10n.getConstant("Width"),align:"Center",type:"Input",template:new i.NumericTextBox({width:75,htmlAttributes:{maxLength:"4"},showSpinButton:!1,value:r?e.aspectWidth:null,placeholder:r?null:a,format:"###.## px"})});var p=document.createElement("span");return p.innerHTML=this.l10n.getConstant("H"),s.push({id:o+"_height",cssClass:"e-ie-resize-height",template:p,align:"Center"}),s.push({id:o+"_resizeHeight",prefixIcon:"e-icons e-clock-wise",tooltipText:this.l10n.getConstant("Height"),align:"Center",type:"Input",template:new i.NumericTextBox({width:75,htmlAttributes:{maxLength:"4"},showSpinButton:!1,value:r?e.aspectHeight:null,placeholder:r?null:n,format:"###.## px"})}),this.isAspectRatio?(s.push({id:o+"_nonaspectratio",prefixIcon:"e-icons e-unlock",align:"Center",tooltipText:this.l10n.getConstant("AspectRatio"),type:"Button"}),this.isAspectRatio=!1):(s.push({id:o+"_aspectratio",prefixIcon:"e-icons e-lock",align:"Center",tooltipText:this.l10n.getConstant("AspectRatio"),type:"Button",tabIndex:0}),this.isAspectRatio=!0),t.Browser.isDevice||(s.push({id:o+"_ok",prefixIcon:"e-icons e-check",cssClass:"top-icon e-tick",tooltipText:this.l10n.getConstant("OK"),align:"Right",tabIndex:0}),s.push({id:o+"_cancel",prefixIcon:"e-icons e-close",cssClass:"top-icon e-save",tooltipText:this.l10n.getConstant("Cancel"),align:"Right"})),s},s.prototype.initResizeToolbar=function(){var e=this,o=this.parent,i=o.element.id,a=this.getLeftToolbarItem(!1,!0),n=this.getRightToolbarItem(),s=this.getResizeToolbarItem(),l=this.getZoomToolbarItem();t.Browser.isDevice?this.defToolbarItems=s:this.defToolbarItems=a.concat(l,s,n);var p={toolbarType:"resize",toolbarItems:this.defToolbarItems};o.trigger("toolbarUpdating",p),this.defToolbarItems=p.toolbarItems;var h=new r.Toolbar({width:"100%",items:this.defToolbarItems,clicked:this.defToolbarClicked.bind(this),created:function(){e.wireResizeBtnEvents(),o.trigger("toolbarCreated",{toolbarType:"shapes"}),t.Browser.isDevice?e.defToolbarItems.length>0&&!t.isNullOrUndefined(document.getElementById(i+"_bottomToolbar"))&&h.refreshOverflow():(e.createLeftToolbarControls(),e.defToolbarItems.length>0&&!t.isNullOrUndefined(document.getElementById(i+"_toolbar"))&&h.refreshOverflow())}});t.Browser.isDevice?h.appendTo("#"+i+"_bottomToolbar"):h.appendTo("#"+i+"_toolbar"),o.isResize=!1,this.enableDisableTbrBtn(),o.isResize=!0,o.notify("transform",{prop:"disableZoomOutBtn",value:{isZoomOut:!0}})},s.prototype.wireResizeBtnEvents=function(){var e=this.parent,o=e.element.id,i=e.element.querySelector("#"+o+"_resizeHeight"),r=e.element.querySelector("#"+o+"_resizeWidth");t.isNullOrUndefined(i)||(i.addEventListener("keydown",this.widthPress.bind(this)),r.addEventListener("keyup",this.heightAspectRatio.bind(this))),t.isNullOrUndefined(r)||(r.addEventListener("keydown",this.heightPress.bind(this)),i.addEventListener("keyup",this.widthAspectRatio.bind(this)))},s.prototype.enableDisableTbrBtn=function(){var e=this.parent,t=e.element.id;if(!this.preventEnableDisableUr){var o={appliedUndoRedoColl:[]};e.notify("undo-redo",{prop:"getAppliedUndoRedoColl",value:{obj:o}});var i={undoRedoStep:null};e.notify("undo-redo",{prop:"getUndoRedoStep",value:{obj:i}});var r=e.element.querySelector("#"+t+"_undo");r&&0===i.undoRedoStep?(r.classList.add("e-disabled"),r.parentElement.classList.add("e-overlay")):r&&i.undoRedoStep>0&&(r.classList.remove("e-disabled"),r.parentElement.classList.remove("e-overlay"));var a=e.element.querySelector("#"+t+"_redo");a&&i.undoRedoStep===o.appliedUndoRedoColl.length?(a.classList.add("e-disabled"),a.parentElement.classList.add("e-overlay")):a&&0===i.undoRedoStep&&o.appliedUndoRedoColl.length>0?(a.classList.remove("e-disabled"),a.parentElement.classList.remove("e-overlay")):a&&i.undoRedoStep>0&&(a.classList.remove("e-disabled"),a.parentElement.classList.remove("e-overlay"))}var n=document.querySelector("#"+t+"_zoomIn");n&&e.zoomSettings.zoomFactor>=e.zoomSettings.maxZoomFactor?(n.classList.add("e-disabled"),n.parentElement.classList.add("e-overlay")):n&&(n.classList.remove("e-disabled"),n.parentElement.classList.remove("e-overlay"));var s=document.querySelector("#"+t+"_zoomOut");s&&e.zoomSettings.zoomFactor<=e.zoomSettings.minZoomFactor?(s.classList.add("e-disabled"),s.parentElement.classList.add("e-overlay")):s&&(s.classList.remove("e-disabled"),s.parentElement.classList.remove("e-overlay"));var l=document.querySelector("#"+t+"_frame");l&&(e.currSelectionPoint&&"crop-circle"===e.currSelectionPoint.shape||e.isCircleCrop)?l.classList.add("e-disabled"):l&&l.classList.remove("e-disabled")},s.prototype.createLeftToolbarControls=function(){var e=this.parent,t=e.element.id;if(void 0!==this.defToolbarItems&&this.defToolbarItems.length>0&&document.getElementById(t+"_toolbar")){var o=document.getElementById(t+"_toolbar").querySelector(".e-image-upload");if(o){var i=o.getElementsByTagName("input")[0],r=o.getElementsByTagName("button")[0];r.className="e-tbar-btn e-tbtn-txt top-icon",r.innerHTML="",r.appendChild(e.createElement("span",{className:"e-btn-icon e-icons e-upload-icon e-icon-left"})),i.onchange=this.fileSelect.bind(this,i)}}},s.prototype.fileSelect=function(e,t){var o=e.files[0].type.split("/")[1],i=["png","jpg","jpeg","svg","svg+xml"];this.fileName=e.files[0].name.split(".")[0],this.parent.notify("toolbar",{prop:"setInitialSize",value:{value:e.files[0].size}}),i.indexOf(o)>-1?this.parent.notify("draw",{prop:"fileSelect",value:{inputElement:e,args:t}}):this.parent.showDialogPopup()},s.prototype.triggerTbarClickEvent=function(e){var t={item:e.item,originalEvent:e.event};this.parent.trigger("toolbarItemClicked",t)},s.prototype.renderAnnotationBtn=function(o){var i=this,r=this.parent,a=!1,s=[],l=r.element.id,p=["Ellipse","Arrow","Line","Rectangle","Pen","Path","Text","Image"];if(r.toolbar)for(var h=0;h<p.length;h++)if(-1!==r.toolbar.indexOf(p[h])){a=!0;break}(t.isNullOrUndefined(r.toolbar)||!a||r.toolbar&&r.toolbar.indexOf("Pen")>-1)&&s.push({text:this.l10n.getConstant("Pen"),id:"pen",iconCss:"e-icons e-free-pen"}),(t.isNullOrUndefined(r.toolbar)||!a||r.toolbar&&r.toolbar.indexOf("Line")>-1)&&s.push({text:this.l10n.getConstant("Line"),id:"line",iconCss:"e-icons e-line"}),(t.isNullOrUndefined(r.toolbar)||!a||r.toolbar&&r.toolbar.indexOf("Rectangle")>-1)&&s.push({text:this.l10n.getConstant("Rectangle"),id:"rectangle",iconCss:"e-icons e-rectangle"}),(t.isNullOrUndefined(r.toolbar)||!a||r.toolbar&&r.toolbar.indexOf("Ellipse")>-1)&&s.push({text:this.l10n.getConstant("Ellipse"),id:"ellipse",iconCss:"e-icons e-circle"}),(t.isNullOrUndefined(r.toolbar)||!a||r.toolbar&&r.toolbar.indexOf("Arrow")>-1)&&s.push({text:this.l10n.getConstant("Arrow"),id:"arrow",iconCss:"e-icons e-arrow-right-up"}),(t.isNullOrUndefined(r.toolbar)||!a||r.toolbar&&r.toolbar.indexOf("Path")>-1)&&s.push({text:this.l10n.getConstant("Path"),id:"path",iconCss:"e-icons e-critical-path"}),(t.isNullOrUndefined(r.toolbar)||!a||r.toolbar&&r.toolbar.indexOf("Text")>-1)&&s.push({text:this.l10n.getConstant("Text"),id:"text",iconCss:"e-icons e-add-text"}),(t.isNullOrUndefined(r.toolbar)||!a||r.toolbar&&r.toolbar.indexOf("Image")>-1)&&s.push({text:this.l10n.getConstant("Image"),id:"image",iconCss:"e-icons e-image"});var d={freehandDrawSelectedId:null};r.notify("freehand-draw",{prop:"getFreehandDrawSelectedId",onPropertyChange:!1,value:{obj:d}});var c=document.querySelector("#"+l+"_duplicate"),u=document.querySelector("#"+l+"_remove"),v=document.querySelector("#"+l+"_editText"),g=document.querySelector("#"+l+"_zOrderBtn");0===r.activeObj.activePoint.width&&0===r.activeObj.activePoint.height&&(t.isNullOrUndefined(r.activeObj.pointColl)||r.activeObj.pointColl&&0===r.activeObj.pointColl.length)&&t.isNullOrUndefined(d.freehandDrawSelectedId)?(c&&c.classList.add("e-disabled"),u&&u.classList.add("e-disabled"),v&&v.classList.add("e-disabled"),g&&g.classList.add("e-disabled")):(c&&c.classList.remove("e-disabled"),u&&u.classList.remove("e-disabled"),v&&v.classList.remove("e-disabled"),g&&g.classList.remove("e-disabled"));var f=o?this.getCurrentShapeIcon(r.activeObj.shape):"e-annotation",C=new n.DropDownButton({items:s,iconCss:"e-icons "+f,cssClass:"e-image-popup",open:function(e){r.currObjType.isFiltered&&(r.okBtn(),r.element.querySelector("#"+l+"_annotationBtn").click()),t.Browser.isDevice&&(e.element.parentElement.style.top=C.element.getBoundingClientRect().top-e.element.parentElement.offsetHeight+"px"),r.activeObj.shape?document.getElementById(r.activeObj.shape).classList.add("e-selected"):r.togglePen&&document.getElementById("pen").classList.add("e-selected")},select:function(t){r.noPushUndo=!1,i.triggerTbarClickEvent(t),r.okBtn();var o,a=!1;void 0!==r.activeObj.shape&&(o=r.activeObj.shape.split("-")),void 0===o&&r.currObjType.isCustomCrop?a=!0:void 0!==o&&"crop"===o[0]&&(a=!0),r.currObjType.isCustomCrop=!1,(a||r.togglePan)&&(r.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),i.upperContext.clearRect(0,0,r.upperCanvas.width,r.upperCanvas.height),i.refreshToolbar("main"));var n={currentFreehandDrawIndex:null};r.notify("freehand-draw",{prop:"getCurrentFreehandDrawIndex",value:{obj:n}});var s,p,h={shapeSettingsObj:{}};switch(C.iconCss="e-icons "+i.getCurrentShapeIcon(t.item.id),r.notify("draw",{prop:"updateTempObjColl"}),r.notify("draw",{prop:"updateTempPointColl"}),t.item.id){case"pen":r.drawingShape=null,r.notify("draw",{prop:"setTempFreehandCounter",value:{tempFreehandCounter:r.freehandCounter}}),r.notify("draw",{prop:"setTempCurrentFreehandDrawIndex",value:{tempCurrentFreehandDrawIndex:n.currentFreehandDrawIndex}}),i.currentToolbar="pen",r.freeHandDraw(!0),r.notify("selection",{prop:"updatePrevShapeSettings",onPropertyChange:!1,value:{obj:h}}),(s=h.shapeSettingsObj).type=e.ShapeType.FreehandDraw,p={cancel:!1,action:"insert",previousShapeSettings:s,currentShapeSettings:s},r.notify("freehand-draw",{prop:"triggerShapeChanging",value:{shapeChangingArgs:p}});break;case"text":i.currentToolbar="text",r.drawingShape=t.item.id,i.currentToolbar="text",i.setInitialShapeSettings(t),r.notify("selection",{prop:"annotate",value:{shape:t.item.id}}),r.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"text",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}});break;case"image":r.drawingShape=null,i.currentToolbar="shapes",r.element.querySelector("#"+l+"_fileUpload").click();break;case"ellipse":case"arrow":case"line":case"rectangle":case"path":r.drawingShape=t.item.id,i.currentToolbar="shapes",i.setInitialShapeSettings(t),r.notify("selection",{prop:"annotate",value:{shape:t.item.id}}),r.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"shapes",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}}),r.notify("selection",{prop:"updatePrevShapeSettings",onPropertyChange:!1,value:{obj:h}}),p={cancel:!1,action:"insert",previousShapeSettings:s=h.shapeSettingsObj,currentShapeSettings:s},r.trigger("shapeChanging",p),r.notify("shape",{prop:"updateShapeChangeEventArgs",value:{shapeSettings:p.currentShapeSettings}})}i.updateToolbarItems();var d=r.togglePen;"pen"===t.item.id&&(r.togglePen=!1),r.notify("draw",{prop:"redrawDownScale"}),r.togglePen=d}});C.appendTo("#"+l+"_annotationBtn")},s.prototype.renderStraightenSlider=function(){var e=this.parent,o=e.element.id;if((t.isNullOrUndefined(e.toolbar)||e.toolbar&&e.toolbar.indexOf("Straightening")>-1)&&e.element.querySelector("#"+o+"_straightenSlider")){var i=this.createSlider(-45,45,e.cropObj.straighten,"straighten");i.appendTo("#"+o+"_straightenSlider");var r=i.element.querySelector(".e-handle");r&&!t.Browser.isDevice&&(r.addEventListener("mousedown",function(e){e.preventDefault(),e.stopPropagation()}),r.addEventListener("touchstart",function(e){e.preventDefault(),e.stopPropagation()}))}},s.prototype.renderCropBtn=function(e){var o=this,i=this.parent,r=[],a=!1,s=["CustomSelection","CircleSelection","SquareSelection","RatioSelection"];if(i.toolbar)for(var l=0;l<s.length;l++)if(-1!==i.toolbar.indexOf(s[l])){a=!0;break}(t.isNullOrUndefined(i.toolbar)||!a||i.toolbar&&i.toolbar.indexOf("CustomSelection")>-1)&&r.push({text:this.l10n.getConstant("Custom"),id:"custom",iconCss:"e-icons e-custom"}),(t.isNullOrUndefined(i.toolbar)||!a||i.toolbar&&i.toolbar.indexOf("CircleSelection")>-1)&&r.push({text:this.l10n.getConstant("Circle"),id:"circle",iconCss:"e-icons e-circle"}),(t.isNullOrUndefined(i.toolbar)||!a||i.toolbar&&i.toolbar.indexOf("SquareSelection")>-1)&&r.push({text:this.l10n.getConstant("Square"),id:"square",iconCss:"e-icons e-square"}),(t.isNullOrUndefined(i.toolbar)||!a||i.toolbar&&i.toolbar.indexOf("RatioSelection")>-1)&&(r.push({text:"2:3",id:"2:3",iconCss:"e-icons e-custom-f"}),r.push({text:"3:2",id:"3:2",iconCss:"e-icons e-custom-a"}),r.push({text:"3:4",id:"3:4",iconCss:"e-icons e-custom-g"}),r.push({text:"4:3",id:"4:3",iconCss:"e-icons e-custom-b"}),r.push({text:"4:5",id:"4:5",iconCss:"e-icons e-custom-h"}),r.push({text:"5:4",id:"5:4",iconCss:"e-icons e-custom-c"}),r.push({text:"5:7",id:"5:7",iconCss:"e-icons e-custom-i"}),r.push({text:"7:5",id:"7:5",iconCss:"e-icons e-custom-d"}),r.push({text:"9:16",id:"9:16",iconCss:"e-icons e-custom-j"}),r.push({text:"16:9",id:"16:9",iconCss:"e-icons e-custom-e"}));var p,h;e?(p=this.getCurrentShapeIcon(e),h=e):i.activeObj.shape&&(0!==i.activeObj.activePoint.width||0!==i.activeObj.activePoint.height)||"path"===i.activeObj.shape&&i.activeObj.pointColl.length>0?(p=this.getCurrentShapeIcon(i.activeObj.shape),h=i.activeObj.shape):i.currSelectionPoint?(p=this.getCurrentShapeIcon(i.currSelectionPoint.shape),h=i.currSelectionPoint.shape):(p=r[0].iconCss,h=r[0].id);var d=new n.DropDownButton({open:function(e){if(i.togglePan&&o.cancelPan(),t.Browser.isDevice&&(e.element.parentElement.style.top=d.element.getBoundingClientRect().top-e.element.parentElement.offsetHeight+"px"),i.activeObj.shape&&i.activeObj.shape.split("-").length>1){var r=document.getElementById(i.activeObj.shape.split("-")[1]);r&&(r.classList.add("e-selected"),r.focus())}i.notify("transform",{prop:"disableZoomOutBtn",value:{isZoomOut:!0}})},items:r,select:function(e){o.triggerTbarClickEvent(e),o.cropSelect(e),d.iconCss="e-icons "+o.getCurrentShapeIcon("crop-"+e.item.id),d.content=t.Browser.isDevice?null:i.toPascalCase(e.item.id)},iconCss:"e-icons "+p,cssClass:"e-image-popup e-ie-crop-ddb-popup",content:t.Browser.isDevice?null:i.toPascalCase(h.replace("crop-",""))});d.appendTo("#"+i.element.id+"_cropBtn")},s.prototype.renderTransformBtn=function(){var e=this,o=this.parent,i=[];(t.isNullOrUndefined(o.toolbar)||o.toolbar&&o.toolbar.indexOf("RotateLeft")>-1)&&i.push({text:this.l10n.getConstant("RotateLeft"),id:"rotateleft",iconCss:"e-icons e-anti-clock-wise"}),(t.isNullOrUndefined(o.toolbar)||o.toolbar&&o.toolbar.indexOf("RotateRight")>-1)&&i.push({text:this.l10n.getConstant("RotateRight"),id:"rotateright",iconCss:"e-icons e-clock-wise"}),(t.isNullOrUndefined(o.toolbar)||o.toolbar&&o.toolbar.indexOf("FlipHorizontal")>-1)&&i.push({text:this.l10n.getConstant("HorizontalFlip"),id:"horizontalflip",iconCss:"e-icons e-horizontal-flip"}),(t.isNullOrUndefined(o.toolbar)||o.toolbar&&o.toolbar.indexOf("FlipVertical")>-1)&&i.push({text:this.l10n.getConstant("VerticalFlip"),id:"verticalflip",iconCss:"e-icons e-vertical-flip"});var r=new n.DropDownButton({open:function(e){if(t.Browser.isDevice){var o=e.element.parentElement,i=o.offsetHeight;o.style.display="none",o.style.top=r.element.getBoundingClientRect().top-i+"px",o.style.display="block"}},items:i,select:function(t){e.triggerTbarClickEvent(t),o.transformSelect.bind(e)},iconCss:"e-icons e-transform",cssClass:"e-image-popup"});r.appendTo("#"+o.element.id+"_transformBtn")},s.prototype.saveDialogPopup=function(){var e=this,i=this.parent,r=i.element.id,a=["Good","Great","Highest"];i.element.appendChild(i.createElement("div",{id:r+"_saveDialog"}));var n=i.createElement("div",{id:r+"_dialogContent",attrs:{style:"display: flex;"}}),s=n.appendChild(i.createElement("div",{id:r+"_dialogImgContent",className:"e-ie-dlg-img-content"}));s.appendChild(i.createElement("canvas",{id:r+"_imgPic",className:"e-ie-img-dlg-canvas"})),s.appendChild(i.createElement("div",{id:r+"_imageNameContainer",className:"e-ie-img-size"})).appendChild(i.createElement("span",{id:r+"_imageNameLabel",className:"e-ie-quality-info"}));var l=n.appendChild(i.createElement("div",{id:r+"_dialogRightContent",className:"e-ie-dlg-right-content"})),p=l.appendChild(i.createElement("div",{id:r+"_namediv",className:"e-ie-img-save-name"}));p.appendChild(i.createElement("span",{id:r+"_labelImgname",className:"e-ie-img-label-name",innerHTML:this.l10n.getConstant("ImageName")})),p.appendChild(i.createElement("input",{id:r+"_imgNametext",className:"e-ie-img-input",attrs:{type:"text"}}));var h=l.appendChild(i.createElement("div",{id:r+"_imgNamediv",className:"e-ie-img-save-dlg"}));h.appendChild(i.createElement("span",{id:r+"_labelname",className:"e-ie-img-label-name",innerHTML:this.l10n.getConstant("Format")})),h.appendChild(i.createElement("button",{id:r+"_saveDropdownbtn",attrs:{tabindex:"1"}}));var d=l.appendChild(i.createElement("div",{id:r+"_imgQualitydiv",className:"e-ie-img-quality-name"})),c=i.createElement("div",{id:r+"_qualityContainer"});c.appendChild(i.createElement("span",{id:r+"_qualityLabel",className:"e-ie-img-quality-label",innerHTML:this.l10n.getConstant("Quality")})),c.appendChild(i.createElement("span",{id:r+"_qualityInfo",className:"e-circle-info e-icons e-ie-quality-span",attrs:{title:this.l10n.getConstant("QualityInfo")}})),c.appendChild(i.createElement("div",{id:r+"_imgsizeSpan",className:"e-ie-img-size-value-span"})).appendChild(i.createElement("span",{id:r+"_imgsizeValueSpan",className:""})),d.appendChild(c);var u=i.createElement("div",{id:r+"_qualityOptionContainer",className:"e-ie-quality-option-container"}),v=d.appendChild(i.createElement("div",{id:r+"_qualityButtonGroup",className:"e-btn-group"}));a.forEach(function(t){var o=document.createElement("input");o.type="radio",o.id=r+"_"+t.toLowerCase(),o.name="quality",o.value=t.toLowerCase();var i=document.createElement("label");i.className="e-btn",i.htmlFor=t.toLowerCase(),i.textContent=e.l10n.getConstant(t),v.appendChild(o),v.appendChild(i)}),u.appendChild(v),u.appendChild(i.createElement("div",{id:r+"_qualitySlider",className:"e-ie-img-quality-slider"})),u.appendChild(i.createElement("button",{id:r+"_qualitybuttonIcon",className:"e-ie-img-icon-button",attrs:{type:"button"}})),d.appendChild(u),t.Browser.isDevice&&d.appendChild(i.createElement("span",{id:r+"_qualitySize",className:"e-ie-img-quality-size"})),i.element.querySelector("#"+r+"_saveDialog").style.display="block",i.element.appendChild(n);var g=new o.Dialog({target:i.element,header:this.l10n.getConstant("SaveAs"),closeOnEscape:!0,content:document.getElementById(r+"_dialogContent"),width:t.Browser.isDevice?"345px":"570px",isModal:!0,animationSettings:{effect:"Zoom"},beforeOpen:this.onBeforeopen(),close:this.saveDialogClosed.bind(this,r),cssClass:"e-ie-save-dialog",buttons:[{click:function(){g.hide()},buttonModel:{content:this.l10n.getConstant("Close"),cssClass:"e-save-cancel-btn"}},{click:function(){e.download(),g.hide(),e.isSlider=!1},buttonModel:{isPrimary:!0,content:this.l10n.getConstant("Download"),cssClass:"e-flat e-save-download-btn"}}]});g.appendTo("#"+r+"_saveDialog")},s.prototype.saveDialogClosed=function(e){t.getComponent(document.getElementById(e+"_saveDropdownbtn"),"dropdownbutton")&&t.getComponent(document.getElementById(e+"_saveDropdownbtn"),"dropdownbutton").destroy(),this.isSlider=!1,document.querySelector("#"+e+"_qualityButtonGroup")&&document.querySelector("#"+e+"_qualitySlider")&&(document.querySelector("#"+e+"_qualityButtonGroup").remove(),document.querySelector("#"+e+"_qualitySlider").remove(),document.querySelector("#"+e+"_imgsizeValueSpan").remove(),document.querySelector("#"+e+"_imageNameLabel").remove(),document.querySelector("#"+e+"_imgsizeSpan").remove()),document.getElementById(e+"_dialogContent").remove(),t.getComponent(document.getElementById(e+"_saveDialog"),"dialog").destroy(),document.getElementById(e+"_saveDialog").remove()},s.prototype.onBeforeopen=function(){var e=this,o=this.parent,r=o.element.id,s={canvas:null},l=[{id:"jpeg",text:"JPEG"},{id:"png",text:"PNG"},{id:"svg",text:"SVG"}];new i.TextBox({placeholder:this.l10n.getConstant("ImageName")}).appendTo("#"+r+"_imgNametext");var p,h=document.getElementById(r+"_imgQualitydiv"),d=document.getElementById(r+"_qualitySlider"),c=document.querySelector("#"+r+"_qualityButtonGroup"),u=document.querySelector("#"+r+"_qualitybuttonIcon"),v=document.querySelector("#"+r+"_imgsizeSpan");p=t.Browser.isDevice?document.getElementById(r+"_qualitySize"):document.getElementById(r+"_imageNameLabel");var g={fileName:"",fileType:""};o.notify("draw",{prop:"getFileName",onPropertyChange:!1,value:{obj:g}}),this.fileType=g.fileType?g.fileType:"JPEG",o.notify("export",{prop:"exportToCanvas",value:{object:s}});var f=s.canvas,C=document.getElementById(r+"_imgPic");C.width=f.width,C.height=f.height,new a.Button({iconCss:"e-icons e-settings"}).appendTo("#"+r+"_qualitybuttonIcon");var b=document.getElementById(r+"_saveDropdownbtn");if(b){var m=document.createElement("span");m.innerHTML=this.fileType.toUpperCase(),b&&b.appendChild(m);var y=new n.DropDownButton({items:l,open:function(e){t.Browser.isDevice&&(e.element.parentElement.style.top=y.element.getBoundingClientRect().top-e.element.parentElement.offsetHeight+"px");var o=m.innerHTML;""!==o&&e.element.querySelector('[aria-label = "'+o+'"]').classList.add("e-selected-btn")},select:function(o){if(v.style.display="none",e.fileType=m.innerHTML=o.item.text,"jpeg"!==o.item.id){if(h.style.display="none",p.style.display="block",e.initialSize>1e3){var i=e.initialSize/1048576;p.innerHTML=e.l10n.getConstant("ImageSize")+": "+i.toFixed(2)+" MB"}else p.innerHTML=e.l10n.getConstant("ImageSize")+": "+e.initialSize.toFixed(2)+" KB";d&&(e.isSlider&&t.getComponent(d,"slider").destroy(),d.style.display="none"),e.isSlider=!1}else h.style.display="block",t.removeClass([c],"e-hide"),d.style.display="none",p.style.display="block",e.updateImageSize(t.isNullOrUndefined(e.currentQuality)?1:e.currentQuality,s.canvas),document.getElementById(r+"_"+e.imageQuality).checked=!0}});y.appendTo("#"+r+"_saveDropdownbtn"),document.getElementById(r+"_imgNametext").value=this.fileName?this.fileName:g.fileName,g.fileType&&"JPEG"!==g.fileType.toUpperCase()&&(h.style.display="none",v.style.display="none"),t.Browser.isDevice?(document.getElementById(r+"_dialogImgContent").style.display="none",document.getElementById(r+"_dialogRightContent").style.width="100%",this.updateImageSize(1,s.canvas)):this.updateImageSize(1,s.canvas)}document.getElementById(r+"_"+this.imageQuality).checked=!0,c.addEventListener("click",this.qualityBtnClickHandler.bind(this)),u.addEventListener("click",this.qualityBtnClickHandler.bind(this))},s.prototype.qualityBtnClickHandler=function(e){var o=this,r=this.parent,a=r.element.id,n=e.target,s={fileName:""},l={canvas:null},p={Good:.8,Great:.9,Highest:1},h=document.querySelector("#"+a+"_qualityButtonGroup"),d=document.querySelector("#"+a+"_qualitySlider"),c=document.querySelector("#"+a+"_qualityOptionContainer"),u=document.querySelector("#"+a+"_imgsizeSpan"),v=document.querySelector("#"+a+"_imgsizeValueSpan");if(r.notify("draw",{prop:"getFileName",onPropertyChange:!1,value:{obj:s}}),r.notify("export",{prop:"exportToCanvas",value:{object:l}}),e.currentTarget.id!==a+"_qualitybuttonIcon"||this.isSlider)e.currentTarget.id===a+"_qualitybuttonIcon"&&this.isSlider?(t.getComponent(d,"slider").destroy(),d.style.display="none",u.style.display="none",t.removeClass([h],"e-hide"),c.style.display="block",this.isSlider=!1):p.hasOwnProperty(n.textContent)&&!this.isSlider&&(e.target.previousElementSibling.checked=!0,this.currentQuality=p[n.textContent],this.imageQuality=n.textContent.toLowerCase(),this.updateImageSize(p[n.textContent],l.canvas));else{t.addClass([h],"e-hide"),d.style.display="block",u.style.display="inline-block",c.style.display="flex";var g=new i.Slider({tooltip:{placement:"Before",isVisible:!0,format:"P0",showOn:"Focus"},min:.01,max:1,step:.01,value:this.currentQuality,type:"MinRange",width:t.Browser.isDevice?"80%":"190px",created:function(){o.updateImageSize(o.currentQuality,l.canvas),v.innerHTML=Math.round(100*o.currentQuality).toString()},changed:function(e){o.currentQuality=e.value,v.innerHTML=Math.round(100*o.currentQuality).toString(),r.notify("export",{prop:"setImageQuality",value:{value:e.value}}),o.updateImageSize(e.value,l.canvas)}});g.appendTo("#"+a+"_qualitySlider"),g.element.parentElement.classList.add("e-ie-quality-slider"),this.isSlider=!0}},s.prototype.updateImageSize=function(e,o){var i,r,a=this.parent.element.id,n=document.getElementById(a+"_imgPic"),s=n.getContext("2d");r=t.Browser.isDevice?document.getElementById(a+"_qualitySize"):document.getElementById(a+"_imageNameLabel"),o.toBlob(function(e){if((i=Math.floor(e.size/1024))>1e3){var o=i/1024;r.innerHTML="Image size: "+o.toFixed(2)+" MB",i=+o.toFixed(2)}else r.innerHTML="Image size: "+i.toFixed(2)+" KB",i=+i.toFixed(2);if(t.Browser.isDevice)n.style.display="none";else{var a=new Image;a.src=URL.createObjectURL(e),a.onload=function(){s.drawImage(a,0,0),URL.revokeObjectURL(a.src)}}this.fileSize=i}.bind(this),"image/jpeg",e)},s.prototype.download=function(){var e=this.parent,o=e.element.id;if("JPEG"===this.fileType&&this.isSlider){var i=t.getComponent(document.getElementById(o+"_qualitySlider"),"slider").value;e.notify("export",{prop:"setImageQuality",value:{value:i}})}else e.notify("export",{prop:"setImageQuality",value:{value:this.currentQuality}});var r=document.getElementById(o+"_imgNametext").value;e.export(this.fileType,r)},s.prototype.getCropTransformToolbarItem=function(){var e=this.parent,o=e.element.id,i=[];if(i.push({id:o+"_crop",tooltipText:this.l10n.getConstant("CropSelection"),align:"Center",template:'<button id="'+o+'_cropBtn"></button>'}),i.push({align:"Center",type:"Separator"}),(t.isNullOrUndefined(e.toolbar)||e.toolbar&&(e.toolbar.indexOf("Transform")>-1||e.toolbar.indexOf("RotateLeft")>-1))&&i.push({id:o+"_rotateLeft",prefixIcon:"e-icons e-anti-clock-wise",tooltipText:this.l10n.getConstant("RotateLeft"),align:"Center"}),(t.isNullOrUndefined(e.toolbar)||e.toolbar&&(e.toolbar.indexOf("Transform")>-1||e.toolbar.indexOf("RotateRight")>-1))&&i.push({id:o+"_rotateRight",prefixIcon:"e-icons e-clock-wise",tooltipText:this.l10n.getConstant("RotateRight"),align:"Center"}),i.length>2&&i.push({align:"Center",type:"Separator"}),(t.isNullOrUndefined(e.toolbar)||e.toolbar&&(e.toolbar.indexOf("Transform")>-1||e.toolbar.indexOf("HorizontalFlip")>-1))&&i.push({id:o+"_horizontalFlip",prefixIcon:"e-icons e-horizontal-flip",tooltipText:this.l10n.getConstant("HorizontalFlip"),align:"Center"}),(t.isNullOrUndefined(e.toolbar)||e.toolbar&&(e.toolbar.indexOf("Transform")>-1||e.toolbar.indexOf("VerticalFlip")>-1))&&i.push({id:o+"_verticalFlip",prefixIcon:"e-icons e-vertical-flip",tooltipText:this.l10n.getConstant("VerticalFlip"),align:"Center"}),(t.isNullOrUndefined(e.toolbar)||e.toolbar&&e.toolbar.indexOf("Straightening")>-1)&&!t.Browser.isDevice&&(i.push({align:"Center",type:"Separator"}),t.isNullOrUndefined(e.toolbar)||e.toolbar&&(e.toolbar.indexOf("Straighten")>-1||e.toolbar.indexOf("Straighten")>-1))){var r=document.createElement("span");r.innerHTML=this.l10n.getConstant("Straighten"),i.push({id:o+"_straightenSpan",cssClass:"e-ie-straighten-span",template:r,align:"Center"}),i.push({id:o+"_straighten",cssClass:"top-icon e-straighten",tooltipText:this.l10n.getConstant("Straighten"),align:"Center",type:"Input",template:'<div id="'+o+'_straightenSlider"></div>'});var a=document.createElement("span");a.innerHTML=e.transform.straighten.toString()+"&#176",i.push({id:o+"_straightenSpan",cssClass:"e-ie-straighten-value-span",template:a,align:"Center"})}return t.Browser.isDevice||(i.push({id:o+"_ok",prefixIcon:"e-icons e-check",cssClass:"top-icon e-tick",tooltipText:this.l10n.getConstant("OK"),align:"Right",tabIndex:0}),i.push({id:o+"_cancel",prefixIcon:"e-icons e-close",cssClass:"top-icon e-save",tooltipText:this.l10n.getConstant("Cancel"),align:"Right"})),i},s.prototype.getShapesToolbarItem=function(e){var o=this.parent,i=o.element.id,r=[];(t.isNullOrUndefined(o.toolbar)||o.toolbar)&&r.push({id:i+"_annotation",tooltipText:this.l10n.getConstant("Annotation"),align:"Center",template:'<button id="'+i+'_annotationBtn"></button>'}),e.indexOf("fillColor")>-1&&r.push({prefixIcon:"e-icons e-copy",id:i+"_fillcolor",cssClass:"top-icon e-fill",tooltipText:this.l10n.getConstant("FillColor"),align:"Center",type:"Input",template:'<button id="'+i+'_fillColorBtn"></button>'}),e.indexOf("strokeColor")>-1&&r.push({prefixIcon:"e-icons e-copy",id:i+"_strokecolor",cssClass:"top-icon e-stroke",tooltipText:this.l10n.getConstant("StrokeColor"),align:"Center",type:"Input",template:'<button id="'+i+'_borderColorBtn"></button>'}),e.indexOf("strokeWidth")>-1&&r.push({id:i+"_strokeWidth",cssClass:"top-icon e-size",tooltipText:"Stroke Width",align:"Center",type:"Input",template:'<button id="'+i+'_borderWidthBtn"></button>'}),e.indexOf("start")>-1&&r.push({id:i+"_start",cssClass:"top-icon e-size",tooltipText:"Start",align:"Center",type:"Input",template:'<button id="'+i+'_startBtn"></button>'}),e.indexOf("end")>-1&&r.push({id:i+"_end",cssClass:"top-icon e-size",tooltipText:"End",align:"Center",type:"Input",template:'<button id="'+i+'_endBtn"></button>'}),e.indexOf("flip")>-1&&(r.push({id:i+"_rotLeft",prefixIcon:"e-anti-clock-wise",tooltipText:this.l10n.getConstant("RotateLeft"),align:"Center"}),r.push({id:i+"_rotRight",prefixIcon:"e-clock-wise",tooltipText:this.l10n.getConstant("RotateRight"),align:"Center"}),r.push({id:i+"_hFlip",prefixIcon:"e-horizontal-flip",tooltipText:this.l10n.getConstant("HorizontalFlip"),align:"Center"}),r.push({id:i+"_vFlip",prefixIcon:"e-vertical-flip",tooltipText:this.l10n.getConstant("VerticalFlip"),align:"Center"})),e.indexOf("transparency")>-1&&(r.push({align:"Center",type:"Separator"}),r.push({id:i+"_transparency",prefixIcon:"e-opacity",tooltipText:this.l10n.getConstant("Opacity"),align:"Center"})),r.push({align:"Center",type:"Separator"}),e.indexOf("z-order")>-1&&r.push({id:i+"_zOrder",cssClass:"top-icon e-list-unordered-3",tooltipText:this.l10n.getConstant("ZOrder"),align:"Center",type:"Input",template:'<button id="'+i+'_zOrderBtn"></button>'}),e.indexOf("duplicate")>-1&&r.push({id:i+"_duplicate",prefixIcon:"e-icons e-order",cssClass:"top-icon e-order",tooltipText:this.l10n.getConstant("Duplicate"),align:"Center"}),e.indexOf("remove")>-1&&r.push({id:i+"_remove",prefixIcon:"e-icons e-trash",cssClass:"top-icon e-trash",tooltipText:this.l10n.getConstant("Remove"),align:"Center"}),e.indexOf("text")>-1&&r.push({id:i+"_editText",prefixIcon:"e-icons e-annotation-edit",cssClass:"top-icon e-annotation-edit",tooltipText:this.l10n.getConstant("EditText"),align:"Center"});for(var a=this.processSubToolbar(e),n=0,s=a.length;n<s;n++)r.push(a[n]);if(!t.Browser.isDevice){var l={shape:null};o.notify("selection",{prop:"getCurrentDrawingShape",value:{obj:l}}),"path"!==l.shape&&(r.push({id:i+"_ok",prefixIcon:"e-icons e-check",cssClass:"top-icon e-tick",tooltipText:this.l10n.getConstant("OK"),align:"Right",tabIndex:0}),r.push({id:i+"_cancel",prefixIcon:"e-icons e-close",cssClass:"top-icon e-save",tooltipText:this.l10n.getConstant("Cancel"),align:"Right"}))}return r},s.prototype.initCropTransformToolbar=function(e,o){var i=this,a=this.parent,n=a.element.id,s=this.getLeftToolbarItem(),l=this.getRightToolbarItem(),p=this.getCropTransformToolbarItem(),h=this.getZoomToolbarItem();t.Browser.isDevice?this.defToolbarItems=p:this.defToolbarItems=s.concat(h,p,l);var d={toolbarType:"crop-transform",toolbarItems:this.defToolbarItems};a.trigger("toolbarUpdating",d),this.defToolbarItems=d.toolbarItems;var c=new r.Toolbar({width:"100%",items:this.defToolbarItems,clicked:this.defToolbarClicked.bind(this),created:function(){i.renderCropBtn(e),i.renderStraightenSlider(),i.wireZoomBtnEvents(),a.trigger("toolbarCreated",{toolbarType:"shapes"}),t.Browser.isDevice?i.defToolbarItems.length>0&&document.getElementById(n+"_bottomToolbar")&&(c.refreshOverflow(),c.refreshOverflow(),c.refreshOverflow()):(i.createLeftToolbarControls(),i.defToolbarItems.length>0&&document.getElementById(n+"_toolbar")&&c.refreshOverflow()),document.getElementById(n+"_cropBtn")&&t.isNullOrUndefined(o)&&(t.Browser.isDevice||a.notify("draw",{prop:"select",onPropertyChange:!1,value:{type:i.getCropTextContent(document.getElementById(n+"_cropBtn")).toLowerCase(),startX:null,startY:null,width:null,height:null}}))}});t.Browser.isDevice?c.appendTo("#"+n+"_bottomToolbar"):c.appendTo("#"+n+"_toolbar");var u=a.element.querySelector("#"+n+"_straightenSlider");(t.isNullOrUndefined(a.toolbar)||a.toolbar&&a.toolbar.indexOf("Straightening")>-1)&&u&&u.parentElement.clientHeight>this.toolbarHeight&&(this.toolbarHeight=a.toolbarHeight=u.parentElement.clientHeight),this.enableDisableTbrBtn(),a.notify("transform",{prop:"disableZoomOutBtn",value:{isZoomOut:!0}})},s.prototype.getCropTextContent=function(e){if(e){var t={"e-custom":"Custom","e-circle":"Circle","e-square":"Square","e-custom-a":"3:2","e-custom-b":"4:3","e-custom-c":"5:4","e-custom-d":"7:5","e-custom-e":"16:9","e-custom-f":"2:3","e-custom-g":"3:4","e-custom-h":"4:5","e-custom-i":"5:7","e-custom-j":"9:16"},o=e.children[0].classList;for(var i in t)if(o.contains(i))return t[i]}return""},s.prototype.getCurrentShapeIcon=function(e){var t={rectangle:"e-rectangle",ellipse:"e-circle",line:"e-line",arrow:"e-arrow-right-up",path:"e-critical-path",text:"e-add-text",image:"e-image",pen:"e-free-pen","crop-custom":"e-custom","crop-circle":"e-circle","crop-square":"e-square","crop-3:2":"e-custom-a","crop-4:3":"e-custom-b","crop-5:4":"e-custom-c","crop-7:5":"e-custom-d","crop-16:9":"e-custom-e","crop-2:3":"e-custom-f","crop-3:4":"e-custom-g","crop-4:5":"e-custom-h","crop-5:7":"e-custom-i","crop-9:16":"e-custom-j"};return t[e]?t[e]:e&&-1!==e.indexOf("crop-")?"e-custom":"e-free-pen"},s.prototype.initShapesToolbarItem=function(e){var o=this,i=this.parent,a=i.element.id,n=this.getLeftToolbarItem(),s=this.getRightToolbarItem(),l=this.getShapesToolbarItem(e),p=this.getZoomToolbarItem();t.Browser.isDevice?this.defToolbarItems=l:this.defToolbarItems=n.concat(p,l,s);var h={toolbarType:i.activeObj.shape?i.activeObj.shape:"shapes",toolbarItems:this.defToolbarItems};i.trigger("toolbarUpdating",h),this.isToolbarString(h.toolbarItems)?(e=h.toolbarItems,this.excludeItems(h.toolbarItems)):this.defToolbarItems=h.toolbarItems;var d=new r.Toolbar({width:"100%",items:this.defToolbarItems,clicked:this.defToolbarClicked.bind(this),created:function(){o.renderAnnotationBtn(!0),o.createShapeColor(e),o.createShapeBtn(e),o.createZOrderBtn(e),"arrow"===i.activeObj.shape&&(e.some(function(e){return e.toLowerCase().indexOf("start")>-1})&&o.createStartBtn(),e.some(function(e){return e.toLowerCase().indexOf("end")>-1})&&o.createEndBtn()),o.wireZoomBtnEvents(),i.trigger("toolbarCreated",{toolbarType:"shapes"}),t.Browser.isDevice?o.defToolbarItems.length>0&&document.getElementById(a+"_bottomToolbar")&&(d.refreshOverflow(),d.refreshOverflow(),d.refreshOverflow()):(o.createLeftToolbarControls(),o.defToolbarItems.length>0&&document.getElementById(a+"_toolbar")&&d.refreshOverflow())}});t.Browser.isDevice?d.appendTo("#"+a+"_bottomToolbar"):d.appendTo("#"+a+"_toolbar"),this.enableDisableTbrBtn()},s.prototype.beforeModeSwitch=function(e,t){this.popupLeft=e.element.offsetParent.style.left,"Picker"===e.mode?(t.showButtons=!0,t.dataBind(),e.element.querySelector(".e-apply").title=this.l10n.getConstant("Apply"),e.element.querySelector(".e-cancel").title=this.l10n.getConstant("Cancel"),e.element.querySelector(".e-mode-switch-btn").title=this.l10n.getConstant("StandardColors")):(t.showButtons=!1,t.dataBind(),e.element.querySelector(".e-mode-switch-btn").title=this.l10n.getConstant("MoreColors"))},s.prototype.createShapeColor=function(e){var o=this,r=this.parent,a=r.element.id;if(e.indexOf("fillColor")>-1){r.element.querySelector(".e-template.e-fill").appendChild(r.createElement("input",{id:a+"_shape_fill"}));var s=new i.ColorPicker({modeSwitcher:!0,noColor:!0,value:"",inline:!0,showButtons:!1,mode:"Palette",cssClass:"e-shape-fill-color",beforeModeSwitch:function(e){return o.beforeModeSwitch(e,s)},presetColors:{custom:["","#f44336","#e91e63","#9c27b0","#673ab7","#2196f3","#03a9f4","#00bcd4","#009688","#ffeb3b","#ffffff","#ffebee","#fce4ec","#f3e5f5","#ede7f6","#e3f2fd","#e1f5fe","#e0f7fa","#e0f2f1","#fffde7","#f2f2f2","#ffcdd2","#f8bbd0","#e1bee7","#d1c4e9","#bbdefb","#b3e5fc","#b2ebf2","#b2dfdb","#fff9c4","#e6e6e6","#ef9a9a","#f48fb1","#ce93d8","#b39ddb","#90caf9","#81d4fa","#80deea","#80cbc4","#fff59d","#cccccc","#e57373","#f06292","#ba68c8","#9575cd","#64b5f6","#4fc3f7","#4dd0e1","#4db6ac","#fff176","#b3b3b3","#ef5350","#ec407a","#ab47bc","#7e57c2","#42a5f5","#29b6f6","#26c6da","#26a69a","#ffee58","#999999","#e53935","#d81b60","#8e24aa","#5e35b1","#1e88e5","#039be5","#00acc1","#00897b","#fdd835","#808080","#d32f2f","#c2185b","#7b1fa2","#512da8","#1976d2","#0288d1","#0097a7","#00796b","#fbc02d","#666666","#c62828","#ad1457","#6a1b9a","#4527a0","#1565c0","#0277bd","#00838f","#00695c","#f9a825","#4d4d4d","#b71c1c","#880e4f","#4a148c","#311b92","#0d47a1","#01579b","#006064","#004d40","#f57f17"]},beforeTileRender:function(e){""===e.value&&e.element.classList.add("e-nocolor-item")},change:function(e){r.updateFillColor(e.value),""===e.currentValue.rgba?l.element.children[0].classList.add("e-nocolor-item"):(l.element.children[0].classList.remove("e-nocolor-item"),l.element.children[0].style.backgroundColor=e.currentValue.rgba),l.toggle(),r.notify("undo-redo",{prop:"updateUndoRedoStack",onPropertyChange:!1})},onModeSwitch:function(e){t.Browser.isDevice&&(e.element.parentElement.parentElement.style.left=o.popupLeft,e.element.parentElement.parentElement.style.top=l.element.getBoundingClientRect().top-e.element.parentElement.parentElement.offsetHeight+"px")},beforeClose:function(){l.toggle()}},"#"+a+"_shape_fill"),l=new n.DropDownButton({open:function(e){var o=e.element.parentElement;t.Browser.isDevice&&(o.style.top=l.element.getBoundingClientRect().top-o.offsetHeight+"px",o.style.left=r.element.offsetLeft+"px")},target:".e-shape-fill-color",iconCss:"e-dropdownbtn-preview",cssClass:"e-ie-ddb-popup"},"#"+a+"_fillColorBtn");s.inline=!0,s.value=s.getValue(s.value,"rgba"),r.element.querySelector(".e-fill.e-template .e-dropdownbtn-preview").classList.add("e-nocolor-item")}if(e.indexOf("strokeColor")>-1){r.element.querySelector(".e-template.e-stroke").appendChild(r.createElement("input",{id:a+"_shape_stroke"}));var p=new i.ColorPicker({modeSwitcher:!0,noColor:!1,value:"#fff",inline:!0,showButtons:!1,mode:"Palette",cssClass:"e-shape-stroke-color",beforeModeSwitch:function(e){o.popupLeft=e.element.offsetParent.style.left,p.value="#fff"!==r.activeObj.strokeSettings.strokeColor?r.activeObj.strokeSettings.strokeColor:"#008000ff",o.beforeModeSwitch(e,p)},presetColors:this.presetColors,change:function(e){r.updateStrokeColor(e.value),h.element.children[0].style.backgroundColor=e.currentValue.rgba,h.toggle(),r.notify("undo-redo",{prop:"updateUndoRedoStack",onPropertyChange:!1})},onModeSwitch:function(e){t.Browser.isDevice&&(e.element.parentElement.parentElement.style.left=o.popupLeft,e.element.parentElement.parentElement.style.top=h.element.getBoundingClientRect().top-e.element.parentElement.parentElement.offsetHeight+"px")},beforeClose:function(){h.toggle()}},"#"+a+"_shape_stroke"),h=new n.DropDownButton({open:function(e){var o=e.element.parentElement;t.Browser.isDevice&&(o.style.top=h.element.getBoundingClientRect().top-o.offsetHeight+"px",o.style.left=r.element.offsetLeft+"px")},target:".e-shape-stroke-color",iconCss:"e-dropdownbtn-preview",cssClass:"e-ie-ddb-popup"},"#"+a+"_borderColorBtn");p.inline=!0,p.value=p.getValue(p.value,"rgba"),r.element.querySelector(".e-stroke.e-template .e-dropdownbtn-preview").style.background="#fff"}},s.prototype.createShapeBtn=function(e){var o=this,i=this.parent,r=i.element.id;if(e.indexOf("strokeWidth")>-1){var a=[{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")}];!i.activeObj.shape||"rectangle"!==i.activeObj.shape&&"ellipse"!==i.activeObj.shape||(a=[{id:"1",text:this.l10n.getConstant("NoOutline")},{id:"2",text:this.l10n.getConstant("XSmall")},{id:"3",text:this.l10n.getConstant("Small")},{id:"4",text:this.l10n.getConstant("Medium")},{id:"5",text:this.l10n.getConstant("Large")},{id:"6",text:this.l10n.getConstant("XLarge")}]);var s=document.getElementById(r+"_borderWidthBtn"),l=document.createElement("span");l.innerHTML=this.l10n.getConstant("XSmall"),l.className="e-shape-stroke-width",s.appendChild(l);var p=new n.DropDownButton({items:a,open:function(e){t.Browser.isDevice&&(e.element.parentElement.style.top=p.element.getBoundingClientRect().top-e.element.parentElement.offsetHeight+"px");var o=l.innerHTML;""!==o&&e.element.querySelector('[aria-label = "'+o+'"]').classList.add("e-selected-btn")},select:function(e){o.triggerTbarClickEvent(e),l.textContent=e.item.text,i.updateStrokeWidth(e.item.id),t.Browser.isDevice?document.getElementById(r+"_bottomToolbar")&&t.getComponent(r+"_bottomToolbar","toolbar").refreshOverflow():document.getElementById(r+"_toolbar")&&t.getComponent(r+"_toolbar","toolbar").refreshOverflow(),i.notify("undo-redo",{prop:"updateUndoRedoStack",onPropertyChange:!1})}});p.appendTo("#"+r+"_borderWidthBtn")}},s.prototype.createZOrderBtn=function(e){var o=this,i=this.parent,r=i.element.id;if(e.indexOf("z-order")>-1){var a=[{text:this.l10n.getConstant("BringForward"),id:"bringForward",iconCss:"e-icons e-bring-forward"},{text:this.l10n.getConstant("SendBackward"),id:"sendBackward",iconCss:"e-icons e-send-backward"},{text:this.l10n.getConstant("BringToFront"),id:"bringToFront",iconCss:"e-icons e-bring-to-front"},{text:this.l10n.getConstant("SendToBack"),id:"sendToBack",iconCss:"e-icons e-send-to-back"}],s=new n.DropDownButton({items:a,iconCss:"e-icons e-layers",beforeOpen:function(e){document.getElementById(i.element.id+"_zOrderBtn").classList.contains("e-disabled")&&(e.cancel=!0);var t={freehandSelectedIndex:-1};i.notify("freehand-draw",{prop:"getFreehandSelectedIndex",onPropertyChange:!1,value:{obj:t}});var o={order:null};i.notify("shape",{prop:"getHighestOrder",onPropertyChange:!1,value:{obj:o}});var r=i.activeObj.order?i.activeObj.order:i.getObjFromId(i.pointColl[t.freehandSelectedIndex].id).order;r&&r>=o.order?(e.items[0].disabled=!0,e.items[2].disabled=!0):(e.items[0].disabled=!1,e.items[2].disabled=!1),i.notify("shape",{prop:"getLowestOrder",onPropertyChange:!1,value:{obj:o}}),r&&r<=o.order?(e.items[1].disabled=!0,e.items[3].disabled=!0):(e.items[1].disabled=!1,e.items[3].disabled=!1)},open:function(e){t.Browser.isDevice&&(e.element.parentElement.style.top=s.element.getBoundingClientRect().top-e.element.parentElement.offsetHeight+"px")},select:function(e){o.triggerTbarClickEvent(e);var a={freehandDrawSelectedId:null};i.notify("freehand-draw",{prop:"getFreehandDrawSelectedId",onPropertyChange:!1,value:{obj:a}});var n=a.freehandDrawSelectedId?a.freehandDrawSelectedId:i.activeObj.currIndex;i.updateShapeOrder(n,e.item.id),t.Browser.isDevice?document.getElementById(r+"_bottomToolbar")&&t.getComponent(r+"_bottomToolbar","toolbar").refreshOverflow():document.getElementById(r+"_toolbar")&&t.getComponent(r+"_toolbar","toolbar").refreshOverflow(),n.indexOf("shape")>-1?i.notify("undo-redo",{prop:"updateUndoRedoStack",onPropertyChange:!1}):n.indexOf("pen")>-1&&i.notify("undo-redo",{prop:"updateUndoRedoStack",value:{isPenDraw:!0}})}});s.appendTo("#"+r+"_zOrderBtn")}},s.prototype.createStartBtn=function(){var e=this,o=this.parent,i=o.element.id,r=[{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")}],a=document.getElementById(i+"_startBtn"),s=document.createElement("span");t.isNullOrUndefined(o.activeObj.start)&&(o.activeObj.start="none"),s.innerHTML=o.pascalToSplitWords(o.activeObj.start),s.className="e-shape-start",a.appendChild(s);var l=new n.DropDownButton({items:r,open:function(e){t.Browser.isDevice&&(e.element.parentElement.style.top=l.element.getBoundingClientRect().top-e.element.parentElement.offsetHeight+"px");var o=s.innerHTML;""!==o&&e.element.querySelector('[aria-label = "'+o+'"]').classList.add("e-selected-btn")},select:function(t){var i={1:"none",2:"bar",3:"arrow",4:"arrowSolid",5:"circle",6:"circleSolid",7:"square",8:"squareSolid"};o.notify("selection",{prop:"setArrowShape",value:{type:"initial",shape:i[""+t.item.id]}}),e.triggerTbarClickEvent(t),s.textContent=t.item.text,o.updateArrow("startArrow",t.item.id),o.notify("undo-redo",{prop:"updateUndoRedoStack",onPropertyChange:!1})}});l.appendTo("#"+i+"_startBtn")},s.prototype.createEndBtn=function(){var e=this,o=this.parent,i=o.element.id,r=[{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")}],a=document.getElementById(i+"_endBtn"),s=document.createElement("span");t.isNullOrUndefined(o.activeObj.end)&&(o.activeObj.end="arrowSolid"),s.innerHTML=o.pascalToSplitWords(o.activeObj.end),s.className="e-shape-end",a.appendChild(s);var l=new n.DropDownButton({items:r,open:function(e){t.Browser.isDevice&&(e.element.parentElement.style.top=l.element.getBoundingClientRect().top-e.element.parentElement.offsetHeight+"px");var o=s.innerHTML;""!==o&&e.element.querySelector('[aria-label = "'+o+'"]').classList.add("e-selected-btn")},select:function(t){var i={1:"none",2:"bar",3:"arrow",4:"arrowSolid",5:"circle",6:"circleSolid",7:"square",8:"squareSolid"};o.notify("selection",{prop:"setArrowShape",value:{type:"final",shape:i[""+t.item.id]}}),e.triggerTbarClickEvent(t),s.textContent=t.item.text,o.updateArrow("endArrow",t.item.id),o.notify("undo-redo",{prop:"updateUndoRedoStack",onPropertyChange:!1})}});l.appendTo("#"+i+"_endBtn")},s.prototype.getTextToolbarItem=function(e){var o=this.parent,i=o.element.id,r=[];(t.isNullOrUndefined(o.toolbar)||o.toolbar)&&r.push({id:i+"_annotation",tooltipText:this.l10n.getConstant("Annotation"),align:"Center",template:'<button id="'+i+'_annotationBtn"></button>'}),e.indexOf("fontFamily")>-1&&r.push({id:i+"_fontFamily",cssClass:"top-icon e-img-font-family",tooltipText:this.l10n.getConstant("FontFamily"),align:"Center",template:'<button id="'+i+'_fontFamilyBtn"></button>'}),e.indexOf("fontSize")>-1&&r.push({id:i+"_fontSize",cssClass:"top-icon e-img-font-size",tooltipText:this.l10n.getConstant("FontSize"),align:"Center",template:'<button id="'+i+'_fontSizeBtn"></button>'}),e.indexOf("fontColor")>-1&&r.push({cssClass:"top-icon e-text-font-color",id:i+"_text_strokecolor",tooltipText:this.l10n.getConstant("FontColor"),align:"Center",type:"Input",template:'<button id="'+i+'_fontColorBtn"></button>'}),e.indexOf("bold")>-1&&r.push({id:i+"_bold",prefixIcon:"e-icons e-bold",cssClass:"top-icon e-bold",tooltipText:this.l10n.getConstant("Bold"),align:"Center"}),e.indexOf("italic")>-1&&r.push({id:i+"_italic",prefixIcon:"e-icons e-italic",cssClass:"top-icon e-italic",tooltipText:this.l10n.getConstant("Italic"),align:"Center"}),e.indexOf("transparency")>-1&&r.push({id:i+"_transparency",prefixIcon:"e-opacity",tooltipText:this.l10n.getConstant("Opacity"),align:"Center"}),r.push({align:"Center",type:"Separator"}),e.indexOf("z-order")>-1&&r.push({id:i+"_zOrder",cssClass:"top-icon e-list-unordered-3",tooltipText:this.l10n.getConstant("ZOrder"),align:"Center",type:"Input",template:'<button id="'+i+'_zOrderBtn"></button>'}),e.indexOf("duplicate")>-1&&r.push({id:i+"_duplicate",prefixIcon:"e-icons e-order",cssClass:"top-icon e-order",tooltipText:this.l10n.getConstant("Duplicate"),align:"Center",disabled:"block"===o.textArea.style.display||"inline-block"===o.textArea.style.display}),e.indexOf("remove")>-1&&r.push({id:i+"_remove",prefixIcon:"e-icons e-trash",cssClass:"top-icon e-trash",tooltipText:this.l10n.getConstant("Remove"),align:"Center",disabled:"block"===o.textArea.style.display||"inline-block"===o.textArea.style.display}),e.indexOf("text")>-1&&r.push({id:i+"_editText",prefixIcon:"e-icons e-annotation-edit",cssClass:"top-icon e-annotation-edit",tooltipText:this.l10n.getConstant("EditText"),align:"Center",disabled:"block"===o.textArea.style.display||"inline-block"===o.textArea.style.display});for(var a=this.processSubToolbar(e),n=0,s=a.length;n<s;n++)r.push(a[n]);return t.Browser.isDevice||(r.push({id:i+"_ok",prefixIcon:"e-icons e-check",cssClass:"top-icon e-tick",tooltipText:this.l10n.getConstant("OK"),align:"Right",tabIndex:0}),r.push({id:i+"_cancel",prefixIcon:"e-icons e-close",cssClass:"top-icon e-save",tooltipText:this.l10n.getConstant("Cancel"),align:"Right"})),r},s.prototype.getFontFamilyItems=function(){var e=this.parent;return e.fontFamily&&e.fontFamily.items&&e.fontFamily.items.length>0?e.fontFamily.items:t.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"}]},s.prototype.initTextToolbarItem=function(e){var o=this,i=this.parent,a=i.element.id,n=this.getLeftToolbarItem(),s=this.getRightToolbarItem(),l=this.getTextToolbarItem(e),p=this.getZoomToolbarItem();t.Browser.isDevice?this.defToolbarItems=l:this.defToolbarItems=n.concat(p,l,s);var h={toolbarType:"text",toolbarItems:this.defToolbarItems};i.trigger("toolbarUpdating",h),this.isToolbarString(h.toolbarItems)?(e=h.toolbarItems,this.excludeItems(h.toolbarItems)):this.defToolbarItems=h.toolbarItems;var d=new r.Toolbar({width:"100%",items:this.defToolbarItems,clicked:this.defToolbarClicked.bind(this),created:function(){o.renderAnnotationBtn(!0),o.createTextColor(e),o.createTextBtn(e),o.createZOrderBtn(e),o.wireZoomBtnEvents(),i.trigger("toolbarCreated",{toolbarType:"text"}),t.Browser.isDevice?o.defToolbarItems.length>0&&document.getElementById(a+"_bottomToolbar")&&(d.refreshOverflow(),d.refreshOverflow(),d.refreshOverflow()):(o.createLeftToolbarControls(),o.defToolbarItems.length>0&&document.getElementById(a+"_toolbar")&&d.refreshOverflow())}});t.Browser.isDevice?d.appendTo("#"+a+"_bottomToolbar"):d.appendTo("#"+a+"_toolbar"),this.enableDisableTbrBtn()},s.prototype.createTextColor=function(e){var o=this,r=this.parent,a=r.element.id;if(e.indexOf("fontColor")>-1&&r.element.querySelector(".e-template.e-text-font-color")){r.element.querySelector(".e-template.e-text-font-color").appendChild(r.createElement("input",{id:a+"_text_font"}));var s=new i.ColorPicker({modeSwitcher:!0,noColor:!1,value:"#fff",inline:!0,showButtons:!1,mode:"Palette",cssClass:"e-text-fontt-color",beforeModeSwitch:function(e){o.popupLeft=e.element.offsetParent.style.left,s.value="#fff"!==r.activeObj.strokeSettings.strokeColor?r.activeObj.strokeSettings.strokeColor:"#008000ff",o.beforeModeSwitch(e,s)},presetColors:this.presetColors,change:function(e){r.updateFontColor(e.value),l.element.children[0].style.backgroundColor=e.currentValue.rgba,l.toggle(),0===r.activeObj.activePoint.width&&0===r.activeObj.activePoint.height||r.notify("undo-redo",{prop:"updateUndoRedoStack",onPropertyChange:!1})},onModeSwitch:function(e){t.Browser.isDevice&&(e.element.parentElement.parentElement.style.left=o.popupLeft,e.element.parentElement.parentElement.style.top=l.element.getBoundingClientRect().top-e.element.parentElement.parentElement.offsetHeight+"px")},beforeClose:function(){l.toggle()}},"#"+a+"_text_font"),l=new n.DropDownButton({open:function(e){var o=e.element.parentElement;t.Browser.isDevice&&(o.style.top=l.element.getBoundingClientRect().top-o.offsetHeight+"px",o.style.left=r.element.offsetLeft+"px")},target:".e-text-fontt-color",iconCss:"e-dropdownbtn-preview",cssClass:"e-ie-ddb-popup"},"#"+a+"_fontColorBtn");s.inline=!0,s.value=s.getValue(s.value,"rgba"),r.element.querySelector(".e-text-font-color.e-template .e-dropdownbtn-preview").style.background="#fff"}},s.prototype.createTextBtn=function(e){var o=this,i=this.parent,r=i.element.id;if(e.indexOf("fontFamily")>-1){var a=document.getElementById(r+"_fontFamilyBtn"),s=document.createElement("span");t.Browser.isDevice?(s.innerHTML="ABC",s.setAttribute("style","font-family: "+i.fontFamily.default.toLowerCase()+"'")):s.innerHTML=i.fontFamily.default,s.className="e-text-font-family",a&&a.appendChild(s);var l=new n.DropDownButton({items:this.getFontFamilyItems(),cssClass:"e-font-family",createPopupOnClick:!0,beforeItemRender:function(e){e.element.setAttribute("style","font-family:"+e.element.id)},open:function(e){t.Browser.isDevice&&(e.element.parentElement.style.top=l.element.getBoundingClientRect().top-e.element.parentElement.offsetHeight+"px");var o;o="block"===i.textArea.style.display||"inline-block"===i.textArea.style.display?i.textArea.style.fontFamily:i.activeObj.textSettings.fontFamily;var r=e.element.querySelector('[id *= "'+o.toLowerCase()+'"]');r&&r.classList.add("e-selected-btn")},select:function(e){o.triggerTbarClickEvent(e),s.textContent=e.item.text,t.Browser.isDevice&&s.setAttribute("style","font-family:"+e.item.id),i.updateFontFamily(e.item.id),i.notify("undo-redo",{prop:"updateUndoRedoStack",onPropertyChange:!1})}});l.appendTo("#"+r+"_fontFamilyBtn")}if(e.indexOf("fontSize")>-1){var p=document.getElementById(r+"_fontSizeBtn"),h=document.createElement("span"),d=i.getFontSizes();h.innerHTML=d[0].text,h.className="e-text-font-size",p.appendChild(h);var c=new n.DropDownButton({cssClass:"e-font-size",items:d,open:function(e){t.Browser.isDevice&&(e.element.parentElement.style.top=c.element.getBoundingClientRect().top-e.element.parentElement.offsetHeight+"px");var o=h.innerHTML;e.element.querySelector('[aria-label *= "'+o+'"]').classList.add("e-selected-btn")},select:function(e){o.triggerTbarClickEvent(e),h.textContent=e.item.text,i.updateFontSize(e.item.text),i.notify("undo-redo",{prop:"updateUndoRedoStack",onPropertyChange:!1})}});c.appendTo("#"+r+"_fontSizeBtn")}},s.prototype.refreshToolbar=function(e,o,i,r,a,n,s){var l=this.parent,p=l.element.id;if(l.isImageLoaded&&!l.isCropToolbar){var h,d,c={};if("filter"!==e&&"color"!==e){var u=document.getElementById(p+"_toolbar"),v=document.getElementById(p+"_customizeWrapper"),g=document.getElementById(p+"_bottomToolbar");if(v&&t.getComponent(v,"toolbar")&&this.defToolbarItems.length>0&&(t.getComponent(v,"toolbar").destroy(),v.innerHTML=""),u&&u.classList.contains("e-control")&&this.defToolbarItems.length>0&&(t.getComponent(u,"toolbar").destroy(),u.innerHTML=""),u&&(this.defToolbarItems.length>0||l.toolbar&&l.toolbar.length>0&&-1===l.toolbar.indexOf("Open"))){var f=t.getComponent(u,"toolbar");t.isNullOrUndefined(f)||(f.destroy(),document.getElementById(l.element.id+"_toolbar").innerHTML="")}g&&this.defToolbarItems.length>0&&g.className.indexOf("e-control")>-1&&(t.getComponent(g,"toolbar").destroy(),g.innerHTML="")}switch(this.refreshSlider(),document.querySelector(".e-slider-tooltip")&&document.querySelector(".e-slider-tooltip").remove(),this.isFrameToolbar=l.isCropTab=!1,e){case"main":t.Browser.isDevice?i?this.initMainToolbar(!1,!0,!0,!1,!1,!0):this.initMainToolbar(!1,!0,null,!1,!1,!0):t.Browser.isDevice&&!r||this.initMainToolbar(o,t.Browser.isDevice,null),t.Browser.isDevice&&this.initBottomToolbar();break;case"shapes":if(l.noPushUndo=!0,t.Browser.isDevice&&this.initMainToolbar(!1,!0,!0),"line"===l.activeObj.shape||"path"===l.activeObj.shape?c.toolbarItems=["strokeColor","strokeWidth","z-order","duplicate","remove"]:"arrow"===l.activeObj.shape?c.toolbarItems=["strokeColor","strokeWidth","start","end","z-order","duplicate","remove"]:"image"===l.activeObj.shape?c.toolbarItems=["flip","z-order","duplicate","remove","transparency"]:c.toolbarItems=["fillColor","strokeColor","strokeWidth","z-order","duplicate","remove"],this.initShapesToolbarItem(c.toolbarItems),"image"===l.activeObj.shape){var C=t.extend({},l.activeObj,{},!0);l.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),l.notify("draw",{prop:"render-image",value:{isMouseWheel:null,isPreventClearRect:null,isFrame:!0}}),l.activeObj=C,l.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate",obj:l.activeObj,isCropRatio:null,points:null,isPreventDrag:!0}}),this.renderQAT(!1)}break;case"text":t.Browser.isDevice&&this.initMainToolbar(!1,!0,!0),c.toolbarItems=["fontFamily","fontSize","fontColor","bold","italic","z-order","duplicate","remove","text"],this.initTextToolbarItem(c.toolbarItems);break;case"pen":t.Browser.isDevice&&this.initMainToolbar(!1,!0,!0),c.toolbarItems=["strokeColor","strokeWidth","z-order","remove","transparency"],this.initPenToolbarItem(c.toolbarItems);break;case"adjustment":t.Browser.isDevice&&this.initMainToolbar(!1,!0,!0),this.initAdjustmentToolbarItem();break;case"filter":this.updateContextualToolbar(e);break;case"resize":(l.isCircleCrop||l.currSelectionPoint&&"crop-circle"===l.currSelectionPoint.shape)&&(l.aspectHeight=l.aspectWidth,this.isAspectRatio=!1),this.initResizeToolbar(),t.Browser.isDevice&&this.initMainToolbar(!1,!0,!0,!0),h=l.element.querySelector("#"+p+"_aspectratio"),d=l.element.querySelector("#"+p+"_nonaspectratio"),l.aspectWidth&&l.aspectHeight&&(d?l.notify("transform",{prop:"resize",value:{width:l.aspectWidth,height:l.aspectHeight,isAspectRatio:!1}}):h&&l.notify("transform",{prop:"resize",value:{width:l.aspectWidth,height:null,isAspectRatio:!0}}));break;case"color":this.updateContextualToolbar(e,a);break;case"croptransform":t.isNullOrUndefined(s)&&(l.allowDownScale=!1,l.isCropTab=!0),t.Browser.isDevice&&this.initMainToolbar(!1,!0,!0),t.isNullOrUndefined(s)&&l.updateCropTransformItems(),this.initCropTransformToolbar(n,s),t.Browser.isDevice&&this.isToolbar()&&this.updateContextualToolbar("color","straighten",!0);break;case"frame":this.isFrameToolbar=!0,t.Browser.isDevice?(this.initMainToolbar(!1,!0,!0),this.initMainToolbar(!1,!0,!0,!1,!0)):this.initMainToolbar(!0,null,null,!1,!0);var b=l.element.querySelector("#"+p+"_"+l.frameObj.type);b&&b.classList.add("e-selected-btn"),"none"!==l.frameObj.type&&this.updateContextualToolbar(e,a),l.notify("draw",{prop:"render-image",value:{isMouseWheel:null,isPreventClearRect:null,isFrame:!0}})}this.refreshDropDownBtn(i),this.updateKBDNavigation(e),this.currToolbar=e}},s.prototype.updateKBDNavigation=function(e){var t=this.parent,o=t.element.id;if(t.isKBDNavigation&&this.currToolbar!==e&&this.isToolbar()){var i,r=t.element.querySelectorAll("#"+o+"_toolbar")[0],a=void 0;if(r){if(!(a=r.querySelector(".e-toolbar-center"))||!a.children[0])return;i=a.children[0].querySelector(".e-btn");var n=a.children[1];n&&(n=n.children[0]),n&&(n=n.children[0]),"resize"===e&&n&&(i=n),i&&("main"===e?setTimeout(function(){return i.focus()},50):i.focus())}}},s.prototype.performCropTransformClick=function(e,o){var i=this.parent;t.isNullOrUndefined(o)&&(i.notify("draw",{prop:"setTempStraightenZoomDeg"}),i.tempStraighten=i.transform.straighten,i.currObjType.isFiltered&&i.okBtn(),i.isStraightening=!0),this.refreshToolbar("croptransform",null,null,null,null,e,o),t.isNullOrUndefined(o)&&(i.notify("draw",{prop:"setDestForStraighten"}),i.notify("draw",{prop:"setTempDestForStraighten"}))},s.prototype.getAdjustmentToolbarItem=function(){var e=[],o=this.parent,i=!1,r=o.element.id,a=["Brightness","Contrast","Hue","Saturation","Exposure","Opacity","Blur"];if(o.toolbar)for(s=0;s<a.length;s++)if(-1!==o.toolbar.indexOf(a[s])){i=!0;break}(t.isNullOrUndefined(o.toolbar)||!i||o.toolbar&&o.toolbar.indexOf("Brightness")>-1)&&e.push({id:r+"_brightness",prefixIcon:"e-icons e-brightness",cssClass:"top-icon e-brightness",tooltipText:this.l10n.getConstant("Brightness"),align:"Center"}),(t.isNullOrUndefined(o.toolbar)||!i||o.toolbar&&o.toolbar.indexOf("Contrast")>-1)&&e.push({id:r+"_contrast",prefixIcon:"e-icons e-contrast",cssClass:"top-icon e-contrast",tooltipText:this.l10n.getConstant("Contrast"),align:"Center"}),(t.isNullOrUndefined(o.toolbar)||!i||o.toolbar&&o.toolbar.indexOf("Hue")>-1)&&e.push({id:r+"_hue",prefixIcon:"e-icons e-fade",cssClass:"top-icon e-fade",tooltipText:this.l10n.getConstant("Hue"),align:"Center"}),(t.isNullOrUndefined(o.toolbar)||!i||o.toolbar&&o.toolbar.indexOf("Saturation")>-1)&&e.push({id:r+"_saturation",prefixIcon:"e-icons e-saturation",cssClass:"top-icon e-saturation",tooltipText:this.l10n.getConstant("Saturation"),align:"Center"}),(t.isNullOrUndefined(o.toolbar)||!i||o.toolbar&&o.toolbar.indexOf("Exposure")>-1)&&e.push({id:r+"_exposure",prefixIcon:"e-icons e-grain",cssClass:"top-icon e-grain",tooltipText:this.l10n.getConstant("Exposure"),align:"Center"}),(t.isNullOrUndefined(o.toolbar)||!i||o.toolbar&&o.toolbar.indexOf("Opacity")>-1)&&e.push({id:r+"_opacity",prefixIcon:"e-icons e-opacity",cssClass:"top-icon e-opacity",tooltipText:this.l10n.getConstant("Opacity"),align:"Center"}),(t.isNullOrUndefined(o.toolbar)||!i||o.toolbar&&o.toolbar.indexOf("Blur")>-1)&&e.push({id:r+"_blur",prefixIcon:"e-icons e-tint",cssClass:"top-icon e-tint",tooltipText:this.l10n.getConstant("Blur"),align:"Center"});for(var n=this.processToolbar("center"),s=0,l=n.length;s<l;s++)e.push(n[s]);return t.Browser.isDevice||(e.push({id:r+"_ok",prefixIcon:"e-icons e-check",cssClass:"top-icon e-tick",tooltipText:this.l10n.getConstant("OK"),align:"Right",tabIndex:0}),e.push({id:r+"_cancel",prefixIcon:"e-icons e-close",cssClass:"top-icon e-save",tooltipText:this.l10n.getConstant("Cancel"),align:"Right"})),e},s.prototype.getFrameToolbarItem=function(){var e=this.parent,t=e.element.id,o=[];return o.push({prefixIcon:"e-icons e-copy",id:t+"_frameColor",cssClass:"top-icon e-stroke",tooltipText:this.l10n.getConstant("Color"),align:"Center",type:"Input",template:"<span>"+this.l10n.getConstant("Color")+'</span><button id="'+t+'_frameColorBtn"></button>'}),o.push({prefixIcon:"e-icons e-copy",id:t+"_frameGradient",cssClass:"top-icon e-frame-stroke",tooltipText:this.l10n.getConstant("GradientColor"),align:"Center",type:"Input",template:"<span>"+this.l10n.getConstant("GradientColor")+'</span><button id="'+t+'_frameGradientColorBtn"></button>'}),o.push({id:t+"_frameSize",cssClass:"top-icon e-size",tooltipText:this.l10n.getConstant("Size"),align:"Center",type:"Input",template:"<span>"+this.l10n.getConstant("Size")+'</span><button id="'+t+'_frameSizeBtn"></button>'}),"line"!==e.frameObj.type&&"inset"!==e.frameObj.type&&"hook"!==e.frameObj.type||o.push({id:t+"_frameInset",cssClass:"top-icon e-size",tooltipText:this.l10n.getConstant("Inset"),align:"Center",type:"Input",template:"<span>"+this.l10n.getConstant("Inset")+'</span><button id="'+t+'_frameInsetBtn"></button>'}),"line"!==e.frameObj.type&&"inset"!==e.frameObj.type||o.push({id:t+"_frameOffset",cssClass:"top-icon e-size",tooltipText:this.l10n.getConstant("Offset"),align:"Center",type:"Input",template:"<span>"+this.l10n.getConstant("Offset")+'</span><button id="'+t+'_frameOffsetBtn"></button>'}),"line"===e.frameObj.type&&(o.push({id:t+"_frameRadius",cssClass:"top-icon e-size",tooltipText:this.l10n.getConstant("Radius"),align:"Center",type:"Input",template:"<span>"+this.l10n.getConstant("Radius")+'</span><button id="'+t+'_frameRadiusBtn"></button>'}),o.push({id:t+"_frameAmount",cssClass:"top-icon e-size",tooltipText:this.l10n.getConstant("Amount"),align:"Center",type:"Input",template:"<span>"+this.l10n.getConstant("Amount")+'</span><button id="'+t+'_frameAmountBtn"></button>'}),o.push({id:t+"_frameBorder",cssClass:"top-icon e-size",tooltipText:this.l10n.getConstant("Border"),align:"Center",type:"Input",template:"<span>"+this.l10n.getConstant("Border")+'</span><button id="'+t+'_frameBorderBtn"></button>'})),o},s.prototype.getFilterToolbarItem=function(){var e=[],o=this.parent,i=!1,r=o.element.id,a=["Default","Chrome","Cold","Warm","Grayscale","Sepia","Invert"];if(o.toolbar)for(s=0;s<a.length;s++)if(-1!==o.toolbar.indexOf(a[s])){i=!0;break}(t.isNullOrUndefined(o.toolbar)||!i||o.toolbar&&o.toolbar.indexOf("Default")>-1)&&e.push({id:r+"_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='+r+'_defaultCanvas tabindex=0></canvas><div style="text-align:center;"><span>'+this.l10n.getConstant("Default")+"</span></div></div>"}),(t.isNullOrUndefined(o.toolbar)||!i||o.toolbar&&o.toolbar.indexOf("Chrome")>-1)&&e.push({id:r+"_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='+r+'_chromeCanvas></canvas><div style="text-align:center;"><span>'+this.l10n.getConstant("Chrome")+"</span></div></div>"}),(t.isNullOrUndefined(o.toolbar)||!i||o.toolbar&&o.toolbar.indexOf("Cold")>-1)&&e.push({id:r+"_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='+r+'_coldCanvas></canvas><div style="text-align:center;"><span>'+this.l10n.getConstant("Cold")+"</span></div></div>"}),(t.isNullOrUndefined(o.toolbar)||!i||o.toolbar&&o.toolbar.indexOf("Warm")>-1)&&e.push({id:r+"_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='+r+'_warmCanvas></canvas><div style="text-align:center;"><span>'+this.l10n.getConstant("Warm")+"</span></div></div>"}),(t.isNullOrUndefined(o.toolbar)||!i||o.toolbar&&o.toolbar.indexOf("Grayscale")>-1)&&e.push({id:r+"_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='+r+'_grayscaleCanvas></canvas><div style="text-align:center;"><span>'+this.l10n.getConstant("Grayscale")+"</span></div></div>"}),(t.isNullOrUndefined(o.toolbar)||!i||o.toolbar&&o.toolbar.indexOf("Sepia")>-1)&&e.push({id:r+"_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='+r+'_sepiaCanvas></canvas><div style="text-align:center;"><span>'+this.l10n.getConstant("Sepia")+"</span></div></div>"}),(t.isNullOrUndefined(o.toolbar)||!i||o.toolbar&&o.toolbar.indexOf("Invert")>-1)&&e.push({id:r+"_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='+r+'_invertCanvas></canvas><div style="text-align:center;"><span>'+this.l10n.getConstant("Invert")+"</span></div></div>"});for(var n=this.processToolbar("center"),s=0,l=n.length;s<l;s++)e.push(n[s]);return e},s.prototype.getPenToolbarItem=function(e){var o=this.parent,i=o.element.id,r=[];(t.isNullOrUndefined(o.toolbar)||o.toolbar)&&r.push({id:i+"_annotation",tooltipText:this.l10n.getConstant("Annotation"),align:"Center",template:'<button id="'+i+'_annotationBtn"></button>'}),e.indexOf("strokeColor")>-1&&r.push({prefixIcon:"e-icons e-copy",id:i+"_pen_strokecolor",cssClass:"top-icon e-pen-stroke-color",tooltipText:this.l10n.getConstant("StrokeColor"),align:"Center",type:"Input",template:'<button id="'+i+'_penColorBtn"></button>'}),e.indexOf("strokeWidth")>-1&&r.push({prefixIcon:"e-icons e-copy",id:i+"_pen_strokewidth",cssClass:"top-icon e-size",tooltipText:this.l10n.getConstant("StrokeWidth"),align:"Center",type:"Input",template:'<button id="'+i+'_penStrokeWidth"></button>'}),r.push({align:"Center",type:"Separator"}),e.indexOf("z-order")>-1&&r.push({id:i+"_zOrder",cssClass:"top-icon e-list-unordered-3",tooltipText:this.l10n.getConstant("ZOrder"),align:"Center",type:"Input",template:'<button id="'+i+'_zOrderBtn"></button>'}),e.indexOf("remove")>-1&&r.push({id:i+"_remove",prefixIcon:"e-icons e-trash",cssClass:"top-icon e-trash",tooltipText:this.l10n.getConstant("Remove"),align:"Center"});for(var a=this.processSubToolbar(e),n=0,s=a.length;n<s;n++)r.push(a[n]);return t.Browser.isDevice||(r.push({id:i+"_ok",prefixIcon:"e-icons e-check",cssClass:"top-icon e-tick",tooltipText:this.l10n.getConstant("OK"),align:"Right",tabIndex:0}),r.push({id:i+"_cancel",prefixIcon:"e-icons e-close",cssClass:"top-icon e-save",tooltipText:this.l10n.getConstant("Cancel"),align:"Right"})),r},s.prototype.initPenToolbarItem=function(e){var o=this,i=this.parent,a=i.element.id,n=this.getLeftToolbarItem(),s=this.getRightToolbarItem(),l=this.getPenToolbarItem(e),p=this.getZoomToolbarItem();t.Browser.isDevice?this.defToolbarItems=l:this.defToolbarItems=n.concat(p,l,s);var h={toolbarType:"pen",toolbarItems:this.defToolbarItems};i.trigger("toolbarUpdating",h),this.isToolbarString(h.toolbarItems)?(e=h.toolbarItems,this.excludeItems(h.toolbarItems)):this.defToolbarItems=h.toolbarItems;var d=new r.Toolbar({width:"100%",items:this.defToolbarItems,clicked:this.defToolbarClicked.bind(this),created:function(){o.renderAnnotationBtn(!0),o.createPenColor(e),o.createPenBtn(e),o.createZOrderBtn(e),o.wireZoomBtnEvents(),i.trigger("toolbarCreated",{toolbarType:"pen"}),t.Browser.isDevice?o.defToolbarItems.length>0&&document.getElementById(a+"_toolbar")&&(d.refreshOverflow(),d.refreshOverflow()):(o.createLeftToolbarControls(),o.defToolbarItems.length>0&&document.getElementById(a+"_toolbar")&&d.refreshOverflow())}});t.Browser.isDevice?d.appendTo("#"+a+"_bottomToolbar"):d.appendTo("#"+a+"_toolbar"),this.enableDisableTbrBtn()},s.prototype.createPenColor=function(e){var o=this,r=this.parent,a=r.element.id;if(e.indexOf("strokeColor")>-1){r.element.querySelector(".e-template.e-pen-stroke-color").appendChild(r.createElement("input",{id:a+"_pen_stroke"}));var s=r.activeObj.strokeSettings.strokeColor,l=new i.ColorPicker({modeSwitcher:!1,value:"#fff",showButtons:!1,mode:"Palette",cssClass:"e-pen-color",change:function(e){r.updatePenStrokeColor(e.currentValue.hex),o.selFhdColor=e.currentValue.hex,p.element.children[0].style.backgroundColor=e.currentValue.rgba,p.toggle(),r.notify("undo-redo",{prop:"updateUndoRedoStack",value:{isPenDraw:!0}})}},"#"+a+"_pen_stroke"),p=new n.DropDownButton({open:function(e){var o=e.element.parentElement;t.Browser.isDevice&&(o.style.top=p.element.getBoundingClientRect().top-o.offsetHeight+"px",o.style.left=r.element.offsetLeft+"px")},target:".e-pen-color",iconCss:"e-dropdownbtn-preview",cssClass:"e-ie-ddb-popup"},"#"+a+"_penColorBtn");l.inline=!0,l.value=l.getValue(r.activeObj.strokeSettings.strokeColor,"rgba"),"null"===l.value&&(l.value=s);var h={tempFreeHandDrawEditingStyles:null};r.notify("freehand-draw",{prop:"getTempFreeHandDrawEditingStyles",value:{obj:h}});var d={freehandSelectedIndex:null};r.notify("freehand-draw",{prop:"getFreehandSelectedIndex",onPropertyChange:!1,value:{obj:d}}),!t.isNullOrUndefined(d.freehandSelectedIndex)&&d.freehandSelectedIndex>-1?r.element.querySelector(".e-pen-stroke-color.e-template .e-dropdownbtn-preview").style.background="#42a5f5"===this.selFhdColor?h.tempFreeHandDrawEditingStyles.strokeColor:r.pointColl[d.freehandSelectedIndex].strokeColor:r.element.querySelector(".e-pen-stroke-color.e-template .e-dropdownbtn-preview").style.background=l.value}},s.prototype.createPenBtn=function(e){var o=this,i=this.parent,r=i.element.id,a=[{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(e.indexOf("strokeWidth")>-1){var s=document.getElementById(r+"_penStrokeWidth"),l=document.createElement("span"),p={freehandSelectedIndex:null};if(i.notify("freehand-draw",{prop:"getFreehandSelectedIndex",onPropertyChange:!1,value:{obj:p}}),!t.isNullOrUndefined(p.freehandSelectedIndex)&&p.freehandSelectedIndex>-1)l.innerHTML=this.getPenStroke(i.pointColl[p.freehandSelectedIndex].strokeWidth);else{var h={penStrokeWidth:2};i.notify("freehand-draw",{prop:"getPenStrokeWidth",onPropertyChange:!1,value:{obj:h}}),l.innerHTML=h.penStrokeWidth?this.getPenStroke(h.penStrokeWidth):this.l10n.getConstant("Small")}l.className="e-pen-stroke-width",s.appendChild(l);var d=new n.DropDownButton({items:a,open:function(e){t.Browser.isDevice&&(e.element.parentElement.style.top=d.element.getBoundingClientRect().top-e.element.parentElement.offsetHeight+"px");var o=l.innerHTML;e.element.querySelector('[aria-label = "'+o+'"]').classList.add("e-selected-btn")},select:function(e){o.triggerTbarClickEvent(e),l.textContent=e.item.text,i.updatePenStrokeWidth(e.item.id),t.Browser.isDevice?document.getElementById(r+"_bottomToolbar")&&t.getComponent(r+"_bottomToolbar","toolbar").refreshOverflow():document.getElementById(r+"_toolbar")&&t.getComponent(r+"_toolbar","toolbar").refreshOverflow(),i.notify("undo-redo",{prop:"updateUndoRedoStack",value:{isPenDraw:!0}})}});d.appendTo("#"+r+"_penStrokeWidth")}},s.prototype.getPenStroke=function(e){var t="",o={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 e>=1&&e<=5&&(t=o[e]),t},s.prototype.initAdjustmentToolbarItem=function(){var e=this,o=this.parent,i=o.element.id,a=this.getLeftToolbarItem(null),n=this.getRightToolbarItem(),s=this.getAdjustmentToolbarItem(),l=this.getZoomToolbarItem();t.Browser.isDevice?this.defToolbarItems=s:this.defToolbarItems=a.concat(l,s,n);var p={toolbarType:"finetune",toolbarItems:this.defToolbarItems};o.trigger("toolbarUpdating",p),this.defToolbarItems=p.toolbarItems;var h=new r.Toolbar({width:"100%",items:this.defToolbarItems,clicked:this.defToolbarClicked.bind(this),created:function(){e.wireZoomBtnEvents(),t.Browser.isDevice?e.defToolbarItems.length>0&&document.getElementById(i+"_toolbar")&&h.refreshOverflow():(e.createLeftToolbarControls(),e.defToolbarItems.length>0&&document.getElementById(i+"_toolbar")&&h.refreshOverflow())}});t.Browser.isDevice?h.appendTo("#"+i+"_bottomToolbar"):h.appendTo("#"+i+"_toolbar"),this.enableDisableTbrBtn()},s.prototype.initFrameToolbarItem=function(){var e=this,o=this.parent,i=o.element.id,a=document.querySelector("#"+i+"_contextualToolbarArea"),n=document.querySelector("#"+i+"_frameWrapper");n?n.style.display="block":n=a.appendChild(o.createElement("div",{id:i+"_frameWrapper",className:"e-frame-wrapper",styles:"position: relative"})),n.appendChild(o.createElement("div",{id:i+"_customizeWrapper",styles:"position: absolute"}));var s=this.getFrameToolbarItem(),l={toolbarType:"frame",toolbarItems:s};o.trigger("toolbarUpdating",l),s=l.toolbarItems;var p=new r.Toolbar({width:"100%",items:s,clicked:this.defToolbarClicked.bind(this),created:function(){e.createFrameColor(),e.createFrameSize();var r=o.frameObj.type;"line"===r&&e.createFrameRadius(),"line"!==r&&"inset"!==r&&"hook"!==r||e.createFrameInset(),"line"!==r&&"inset"!==r||e.createFrameOffset(),"line"===r&&(e.createFrameAmount(),e.createFrameBorder()),e.createFrameGradientColor(),t.Browser.isDevice?e.defToolbarItems.length>0&&document.getElementById(i+"_bottomToolbar")&&(p.refreshOverflow(),p.refreshOverflow(),p.refreshOverflow()):(e.createLeftToolbarControls(),e.defToolbarItems.length>0&&document.getElementById(i+"_toolbar")&&p.refreshOverflow()),o.element.querySelector("#"+i+"_"+r).focus()}});p.appendTo("#"+i+"_customizeWrapper")},s.prototype.createFrameGradientColor=function(){var e,o=this.parent,r={frameChangeEventArgs:null},a=o.element.id;o.element.querySelector(".e-template.e-frame-stroke").appendChild(o.createElement("input",{id:a+"_frame_gradient_fill"}));var s=new i.ColorPicker({modeSwitcher:!1,noColor:!0,value:o.frameObj.gradientColor,showButtons:!1,mode:"Palette",cssClass:"e-frame-gradient-fill-color",change:function(i){e={type:o.toPascalCase(o.frameObj.type),color:o.frameObj.color,gradientColor:o.frameObj.gradientColor,size:o.frameObj.size,inset:o.frameObj.inset,offset:o.frameObj.offset,borderRadius:o.frameObj.radius,frameLineStyle:o.toPascalCase(o.frameObj.border),lineCount:o.frameObj.amount};var a=o.frameObj.gradientColor,n={currObj:{}};o.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:n}}),o.frameObj.gradientColor=i.currentValue.hex,o.notify("draw",{prop:"triggerFrameChange",value:{prevFrameSettings:e,obj:r}}),r.frameChangeEventArgs&&!r.frameChangeEventArgs.cancel?(o.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"frame",previousObj:n.currObj,previousObjColl:n.currObj.objColl,previousPointColl:n.currObj.pointColl,previousSelPointColl:n.currObj.selPointColl,previousCropObj:t.extend({},o.cropObj,{},!0),previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),o.notify("draw",{prop:"render-image",value:{isMouseWheel:null,isPreventClearRect:null,isFrame:!0}}),o.notify("draw",{prop:"redrawDownScale"}),""===i.currentValue.rgba?l.element.children[0].classList.add("e-nocolor-item"):(l.element.children[0].classList.remove("e-nocolor-item"),l.element.children[0].style.backgroundColor=i.currentValue.rgba),o.curFrameObjEvent={previousFrameSetting:r.frameChangeEventArgs.previousFrameSetting,currentFrameSetting:r.frameChangeEventArgs.currentFrameSetting},o.isFrameBtnClick=!0):o.frameObj.gradientColor=a,l.toggle()}},"#"+a+"_frame_gradient_fill"),l=new n.DropDownButton({open:function(e){if(t.Browser.isDevice){var i=e.element.parentElement;i.style.top=l.element.getBoundingClientRect().top-i.offsetHeight+"px",i.style.left=o.element.offsetLeft+"px"}},target:".e-frame-gradient-fill-color",iconCss:"e-dropdownbtn-preview",cssClass:"e-ie-ddb-popup"},"#"+a+"_frameGradientColorBtn");s.inline=!0,""===o.frameObj.gradientColor?o.element.querySelector(".e-frame-stroke.e-template .e-dropdownbtn-preview").classList.add("e-nocolor-item"):o.element.querySelector(".e-frame-stroke.e-template .e-dropdownbtn-preview").style.background=o.frameObj.gradientColor},s.prototype.createFrameColor=function(){var e,o=this.parent,r={frameChangeEventArgs:null},a=o.element.id;o.element.querySelector(".e-template.e-stroke").appendChild(o.createElement("input",{id:a+"_frame_fill"}));var s=new i.ColorPicker({modeSwitcher:!1,value:o.frameObj.color,showButtons:!1,mode:"Palette",cssClass:"e-frame-fill-color",change:function(i){e={type:o.toPascalCase(o.frameObj.type),color:o.frameObj.color,gradientColor:o.frameObj.gradientColor,size:o.frameObj.size,inset:o.frameObj.inset,offset:o.frameObj.offset,borderRadius:o.frameObj.radius,frameLineStyle:o.toPascalCase(o.frameObj.border),lineCount:o.frameObj.amount};var a=o.frameObj.color,n={currObj:{}};o.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:n}}),o.frameObj.color=i.currentValue.hex,o.notify("draw",{prop:"triggerFrameChange",value:{prevFrameSettings:e,obj:r}}),r.frameChangeEventArgs&&!r.frameChangeEventArgs.cancel?(o.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"frame",previousObj:n.currObj,previousObjColl:n.currObj.objColl,previousPointColl:n.currObj.pointColl,previousSelPointColl:n.currObj.selPointColl,previousCropObj:t.extend({},o.cropObj,{},!0),previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),o.notify("draw",{prop:"render-image",value:{isMouseWheel:null,isPreventClearRect:null,isFrame:!0}}),o.notify("draw",{prop:"redrawDownScale"}),""===i.currentValue.rgba?l.element.children[0].classList.add("e-nocolor-item"):(l.element.children[0].classList.remove("e-nocolor-item"),l.element.children[0].style.backgroundColor=i.currentValue.rgba),o.curFrameObjEvent={previousFrameSetting:r.frameChangeEventArgs.previousFrameSetting,currentFrameSetting:r.frameChangeEventArgs.currentFrameSetting},o.isFrameBtnClick=!0):o.frameObj.color=a,l.toggle()}},"#"+a+"_frame_fill"),l=new n.DropDownButton({open:function(e){if(t.Browser.isDevice){var i=e.element.parentElement;i.style.top=l.element.getBoundingClientRect().top-i.offsetHeight+"px",i.style.left=o.element.offsetLeft+"px"}},target:".e-frame-fill-color",iconCss:"e-dropdownbtn-preview",cssClass:"e-ie-ddb-popup"},"#"+a+"_frameColorBtn");s.inline=!0,o.element.querySelector(".e-stroke.e-template .e-dropdownbtn-preview").style.background=o.frameObj.color},s.prototype.createFrameSize=function(){var e,o=this,i=this.parent,r={frameChangeEventArgs:null},a=i.element.id,s=[{id:"1",text:this.l10n.getConstant("20")},{id:"2",text:this.l10n.getConstant("40")},{id:"3",text:this.l10n.getConstant("60")},{id:"4",text:this.l10n.getConstant("80")},{id:"5",text:this.l10n.getConstant("100")}],l=document.getElementById(a+"_frameSizeBtn"),p=document.createElement("span");p.innerHTML=this.l10n.getConstant(i.frameObj.size.toString()),p.className="e-frame-stroke-width",l.appendChild(p);var h=new n.DropDownButton({items:s,open:function(e){if(t.Browser.isDevice){var o=e.element.parentElement;o.style.top=h.element.getBoundingClientRect().top-o.offsetHeight+"px"}var i=h.element.childNodes[0].textContent;""!==i&&e.element.querySelector('[aria-label = "'+i+'"]').classList.add("e-selected-btn")},select:function(n){o.triggerTbarClickEvent(n),e={type:i.toPascalCase(i.frameObj.type),color:i.frameObj.color,gradientColor:i.frameObj.gradientColor,size:i.frameObj.size,inset:i.frameObj.inset,offset:i.frameObj.offset,borderRadius:i.frameObj.radius,frameLineStyle:i.toPascalCase(i.frameObj.border),lineCount:i.frameObj.amount};var s=i.frameObj.size,l={currObj:{}};i.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:l}}),i.frameObj.size=parseInt(n.item.text,10),i.notify("draw",{prop:"triggerFrameChange",value:{prevFrameSettings:e,obj:r}}),r.frameChangeEventArgs&&!r.frameChangeEventArgs.cancel?(i.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"frame",previousObj:l.currObj,previousObjColl:l.currObj.objColl,previousPointColl:l.currObj.pointColl,previousSelPointColl:l.currObj.selPointColl,previousCropObj:t.extend({},i.cropObj,{},!0),previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),i.notify("draw",{prop:"render-image",value:{isMouseWheel:null,isPreventClearRect:null,isFrame:!0}}),i.notify("draw",{prop:"redrawDownScale"}),h.content=n.item.text,i.curFrameObjEvent={previousFrameSetting:r.frameChangeEventArgs.previousFrameSetting,currentFrameSetting:r.frameChangeEventArgs.currentFrameSetting},i.isFrameBtnClick=!0):i.frameObj.size=s,t.Browser.isDevice?document.getElementById(a+"_bottomToolbar")&&t.getComponent(a+"_bottomToolbar","toolbar").refreshOverflow():document.getElementById(a+"_toolbar")&&t.getComponent(a+"_toolbar","toolbar").refreshOverflow()}});h.appendTo("#"+a+"_frameSizeBtn")},s.prototype.createFrameInset=function(){var e,o=this,i=this.parent,r={frameChangeEventArgs:null},a=i.element.id,s=[{id:"1",text:this.l10n.getConstant("20")},{id:"2",text:this.l10n.getConstant("40")},{id:"3",text:this.l10n.getConstant("60")},{id:"4",text:this.l10n.getConstant("80")},{id:"5",text:this.l10n.getConstant("100")}],l=document.getElementById(a+"_frameInsetBtn"),p=document.createElement("span");p.innerHTML=this.l10n.getConstant(i.frameObj.inset.toString()),p.className="e-frame-inset",l.appendChild(p);var h=new n.DropDownButton({items:s,open:function(e){if(t.Browser.isDevice){var o=e.element.parentElement;o.style.top=h.element.getBoundingClientRect().top-o.offsetHeight+"px"}var i=h.element.childNodes[0].textContent;""!==i&&e.element.querySelector('[aria-label = "'+i+'"]').classList.add("e-selected-btn")},select:function(n){o.triggerTbarClickEvent(n),e={type:i.toPascalCase(i.frameObj.type),color:i.frameObj.color,gradientColor:i.frameObj.gradientColor,size:i.frameObj.size,inset:i.frameObj.inset,offset:i.frameObj.offset,borderRadius:i.frameObj.radius,frameLineStyle:i.toPascalCase(i.frameObj.border),lineCount:i.frameObj.amount};var s=i.frameObj.inset,l={currObj:{}};i.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:l}}),i.frameObj.inset=parseInt(n.item.text,10),i.notify("draw",{prop:"triggerFrameChange",value:{prevFrameSettings:e,obj:r}}),r.frameChangeEventArgs&&!r.frameChangeEventArgs.cancel?(i.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"frame",previousObj:l.currObj,previousObjColl:l.currObj.objColl,previousPointColl:l.currObj.pointColl,previousSelPointColl:l.currObj.selPointColl,previousCropObj:t.extend({},i.cropObj,{},!0),previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),i.notify("draw",{prop:"render-image",value:{isMouseWheel:null,isPreventClearRect:null,isFrame:!0}}),i.notify("draw",{prop:"redrawDownScale"}),h.content=n.item.text,i.curFrameObjEvent={previousFrameSetting:r.frameChangeEventArgs.previousFrameSetting,currentFrameSetting:r.frameChangeEventArgs.currentFrameSetting},i.isFrameBtnClick=!0):i.frameObj.inset=s,t.Browser.isDevice?document.getElementById(a+"_bottomToolbar")&&t.getComponent(a+"_bottomToolbar","toolbar").refreshOverflow():document.getElementById(a+"_toolbar")&&t.getComponent(a+"_toolbar","toolbar").refreshOverflow()}});h.appendTo("#"+a+"_frameInsetBtn")},s.prototype.createFrameOffset=function(){var e,o=this,i=this.parent,r={frameChangeEventArgs:null},a=i.element.id,s=[{id:"1",text:this.l10n.getConstant("20")},{id:"2",text:this.l10n.getConstant("40")},{id:"3",text:this.l10n.getConstant("60")},{id:"4",text:this.l10n.getConstant("80")},{id:"5",text:this.l10n.getConstant("100")}],l=document.getElementById(a+"_frameOffsetBtn"),p=document.createElement("span");p.innerHTML=this.l10n.getConstant(i.frameObj.offset.toString()),p.className="e-frame-offset",l.appendChild(p);var h=new n.DropDownButton({items:s,open:function(e){if(t.Browser.isDevice){var o=e.element.parentElement;o.style.top=h.element.getBoundingClientRect().top-o.offsetHeight+"px"}var i=h.element.childNodes[0].textContent;""!==i&&e.element.querySelector('[aria-label = "'+i+'"]').classList.add("e-selected-btn")},select:function(n){o.triggerTbarClickEvent(n),e={type:i.toPascalCase(i.frameObj.type),color:i.frameObj.color,gradientColor:i.frameObj.gradientColor,size:i.frameObj.size,inset:i.frameObj.inset,offset:i.frameObj.offset,borderRadius:i.frameObj.radius,lineCount:i.frameObj.amount,frameLineStyle:i.toPascalCase(i.frameObj.border)};var s=i.frameObj.offset,l={currObj:{}};i.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:l}}),i.frameObj.offset=parseInt(n.item.text,10),i.notify("draw",{prop:"triggerFrameChange",value:{prevFrameSettings:e,obj:r}}),r.frameChangeEventArgs&&!r.frameChangeEventArgs.cancel?(i.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"frame",previousObj:l.currObj,previousObjColl:l.currObj.objColl,previousPointColl:l.currObj.pointColl,previousSelPointColl:l.currObj.selPointColl,previousCropObj:t.extend({},i.cropObj,{},!0),previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),i.notify("draw",{prop:"render-image",value:{isMouseWheel:null,isPreventClearRect:null,isFrame:!0}}),i.notify("draw",{prop:"redrawDownScale"}),h.content=n.item.text,i.curFrameObjEvent={previousFrameSetting:r.frameChangeEventArgs.previousFrameSetting,currentFrameSetting:r.frameChangeEventArgs.currentFrameSetting},i.isFrameBtnClick=!0):i.frameObj.offset=s,t.Browser.isDevice?document.getElementById(a+"_bottomToolbar")&&t.getComponent(a+"_bottomToolbar","toolbar").refreshOverflow():document.getElementById(a+"_toolbar")&&t.getComponent(a+"_toolbar","toolbar").refreshOverflow()}});h.appendTo("#"+a+"_frameOffsetBtn")},s.prototype.createFrameRadius=function(){var e,o=this,i=this.parent,r={frameChangeEventArgs:null},a=i.element.id,s=[{id:"1",text:this.l10n.getConstant("0")},{id:"2",text:this.l10n.getConstant("20")},{id:"3",text:this.l10n.getConstant("40")},{id:"4",text:this.l10n.getConstant("60")},{id:"5",text:this.l10n.getConstant("80")},{id:"6",text:this.l10n.getConstant("100")}],l=document.getElementById(a+"_frameRadiusBtn"),p=document.createElement("span");p.innerHTML=this.l10n.getConstant(i.frameObj.radius.toString()),p.className="e-frame-radius",l.appendChild(p);var h=new n.DropDownButton({items:s,open:function(e){if(t.Browser.isDevice){var o=e.element.parentElement;o.style.top=h.element.getBoundingClientRect().top-o.offsetHeight+"px"}var i=h.element.childNodes[0].textContent;""!==i&&e.element.querySelector('[aria-label = "'+i+'"]').classList.add("e-selected-btn")},select:function(n){o.triggerTbarClickEvent(n),e={type:i.toPascalCase(i.frameObj.type),color:i.frameObj.color,gradientColor:i.frameObj.gradientColor,size:i.frameObj.size,inset:i.frameObj.inset,offset:i.frameObj.offset,borderRadius:i.frameObj.radius,frameLineStyle:i.toPascalCase(i.frameObj.border),lineCount:i.frameObj.amount};var s=i.frameObj.radius,l={currObj:{}};i.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:l}}),i.frameObj.radius=parseInt(n.item.text,10),i.notify("draw",{prop:"triggerFrameChange",value:{prevFrameSettings:e,obj:r}}),r.frameChangeEventArgs&&!r.frameChangeEventArgs.cancel?(i.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"frame",previousObj:l.currObj,previousObjColl:l.currObj.objColl,previousPointColl:l.currObj.pointColl,previousSelPointColl:l.currObj.selPointColl,previousCropObj:t.extend({},i.cropObj,{},!0),previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),i.notify("draw",{prop:"render-image",value:{isMouseWheel:null,isPreventClearRect:null,isFrame:!0}}),i.notify("draw",{prop:"redrawDownScale"}),h.content=n.item.text,i.curFrameObjEvent={previousFrameSetting:r.frameChangeEventArgs.previousFrameSetting,currentFrameSetting:r.frameChangeEventArgs.currentFrameSetting},i.isFrameBtnClick=!0):i.frameObj.radius=s,t.Browser.isDevice?document.getElementById(a+"_bottomToolbar")&&t.getComponent(a+"_bottomToolbar","toolbar").refreshOverflow():document.getElementById(a+"_toolbar")&&t.getComponent(a+"_toolbar","toolbar").refreshOverflow()}});h.appendTo("#"+a+"_frameRadiusBtn")},s.prototype.createFrameAmount=function(){var e,o=this,i=this.parent,r={frameChangeEventArgs:null},a=i.element.id,s=[{id:"1",text:this.l10n.getConstant("1")},{id:"2",text:this.l10n.getConstant("2")},{id:"3",text:this.l10n.getConstant("3")},{id:"4",text:this.l10n.getConstant("4")},{id:"5",text:this.l10n.getConstant("5")}],l=document.getElementById(a+"_frameAmountBtn"),p=document.createElement("span");p.innerHTML=this.l10n.getConstant(i.frameObj.amount.toString()),p.className="e-frame-amount",l.appendChild(p);var h=new n.DropDownButton({items:s,open:function(e){if(t.Browser.isDevice){var o=e.element.parentElement;o.style.top=h.element.getBoundingClientRect().top-o.offsetHeight+"px"}var i=h.element.childNodes[0].textContent;""!==i&&e.element.querySelector('[aria-label = "'+i+'"]').classList.add("e-selected-btn")},select:function(n){o.triggerTbarClickEvent(n),e={type:i.toPascalCase(i.frameObj.type),color:i.frameObj.color,gradientColor:i.frameObj.gradientColor,size:i.frameObj.size,inset:i.frameObj.inset,offset:i.frameObj.offset,borderRadius:i.frameObj.radius,lineCount:i.frameObj.amount,frameLineStyle:i.toPascalCase(i.frameObj.border)};var s=i.frameObj.amount,l={currObj:{}};i.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:l}}),i.frameObj.amount=parseInt(n.item.text,10),i.notify("draw",{prop:"triggerFrameChange",value:{prevFrameSettings:e,obj:r}}),r.frameChangeEventArgs&&!r.frameChangeEventArgs.cancel?(i.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"frame",previousObj:l.currObj,previousObjColl:l.currObj.objColl,previousPointColl:l.currObj.pointColl,previousSelPointColl:l.currObj.selPointColl,previousCropObj:t.extend({},i.cropObj,{},!0),previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),i.notify("draw",{prop:"render-image",value:{isMouseWheel:null,isPreventClearRect:null,isFrame:!0}}),i.notify("draw",{prop:"redrawDownScale"}),h.content=n.item.text,i.curFrameObjEvent={previousFrameSetting:r.frameChangeEventArgs.previousFrameSetting,currentFrameSetting:r.frameChangeEventArgs.currentFrameSetting},i.isFrameBtnClick=!0):i.frameObj.amount=s,t.Browser.isDevice?document.getElementById(a+"_bottomToolbar")&&t.getComponent(a+"_bottomToolbar","toolbar").refreshOverflow():document.getElementById(a+"_toolbar")&&t.getComponent(a+"_toolbar","toolbar").refreshOverflow()}});h.appendTo("#"+a+"_frameAmountBtn")},s.prototype.createFrameBorder=function(){var e,o=this,i=this.parent,r={frameChangeEventArgs:null},a=i.element.id,s=[{id:"1",text:this.l10n.getConstant("Solid")},{id:"2",text:this.l10n.getConstant("Dashed")},{id:"3",text:this.l10n.getConstant("Dotted")}],l=document.getElementById(a+"_frameBorderBtn"),p=document.createElement("span");p.innerHTML=this.l10n.getConstant(i.toPascalCase(i.frameObj.border)),p.className="e-frame-border",l.appendChild(p);var h=new n.DropDownButton({items:s,open:function(e){if(t.Browser.isDevice){var o=e.element.parentElement;o.style.top=h.element.getBoundingClientRect().top-o.offsetHeight+"px"}var i=h.element.childNodes[0].textContent;""!==i&&e.element.querySelector('[aria-label = "'+i+'"]').classList.add("e-selected-btn")},select:function(n){o.triggerTbarClickEvent(n),e={lineCount:i.frameObj.amount,color:i.frameObj.color,borderRadius:i.frameObj.radius,gradientColor:i.frameObj.gradientColor,size:i.frameObj.size,inset:i.frameObj.inset,offset:i.frameObj.offset,frameLineStyle:i.toPascalCase(i.frameObj.border),type:i.toPascalCase(i.frameObj.type)};var s=i.frameObj.border,l={currObj:{}};i.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:l}}),i.frameObj.border=n.item.text.toLowerCase(),i.notify("draw",{prop:"triggerFrameChange",value:{prevFrameSettings:e,obj:r}}),r.frameChangeEventArgs&&!r.frameChangeEventArgs.cancel?(i.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"frame",previousObj:l.currObj,previousObjColl:l.currObj.objColl,previousPointColl:l.currObj.pointColl,previousSelPointColl:l.currObj.selPointColl,previousCropObj:t.extend({},i.cropObj,{},!0),previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),i.notify("draw",{prop:"render-image",value:{isMouseWheel:null,isPreventClearRect:null,isFrame:!0}}),i.notify("draw",{prop:"redrawDownScale"}),h.content=n.item.text,i.curFrameObjEvent={previousFrameSetting:r.frameChangeEventArgs.previousFrameSetting,currentFrameSetting:r.frameChangeEventArgs.currentFrameSetting},i.isFrameBtnClick=!0):i.frameObj.border=s,t.Browser.isDevice?document.getElementById(a+"_bottomToolbar")&&t.getComponent(a+"_bottomToolbar","toolbar").refreshOverflow():document.getElementById(a+"_toolbar")&&t.getComponent(a+"_toolbar","toolbar").refreshOverflow()}});h.appendTo("#"+a+"_frameBorderBtn")},s.prototype.initFilterToolbarItem=function(){var e=this,o=this.parent,i=o.element.id,a=this.getFilterToolbarItem(),n={toolbarType:"filter",toolbarItems:a};o.trigger("toolbarUpdating",n),a=n.toolbarItems,document.querySelector("#"+i+"_contextualToolbar").classList.contains("e-control")&&t.getComponent(document.getElementById(i+"_contextualToolbar"),"toolbar").destroy();var s=new r.Toolbar({width:"100%",items:a,clicked:this.contextualToolbarClicked.bind(this),created:function(){e.updatePrivateVariables(),e.createCanvasFilter(),""===o.currentFilter&&(o.currentFilter=i+"_default");var t=document.querySelector("#"+i+"_headWrapper");t&&(t.style.display="none");var r=document.getElementById(o.currentFilter+"Canvas");r&&r.parentElement.parentElement.classList.add("e-selected"),e.enableDisableTbrBtn(),s.refreshOverflow()}});s.appendTo("#"+i+"_contextualToolbar")},s.prototype.drawDashedLine=function(e){e.beginPath(),e.setLineDash([5]),e.rect(10,10,280,130),e.stroke(),e.closePath()},s.prototype.createCanvasFilter=function(){var e=this.parent;o.showSpinner(e.element),e.element.style.opacity="0.5";var t=e.getCurrentCanvasData();this.inMemoryCanvas.width=t.width,this.inMemoryCanvas.height=t.height,this.inMemoryContext.putImageData(t,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"),o.hideSpinner(e.element),e.element.style.opacity="1",e.initialAdjustmentValue=this.lowerContext.filter},s.prototype.updateFilterCanvas=function(e,t){var o=this.parent,i=o.element.querySelector("#"+o.element.id+e);if(i){var r=i.getContext("2d");r=i.getContext("2d"),i.style.width="100px",i.style.height="100px",o.notify("filter",{prop:"updateAdj",value:{type:t,value:null,isPreview:!0,ctx:r}}),r.drawImage(this.inMemoryCanvas,0,0,300,150)}},s.prototype.getQuickAccessToolbarItem=function(e){var o=this.parent,i=o.element.id,r={cancel:!1,toolbarItems:[]},a=[];t.isNullOrUndefined(e)?("image"===o.activeObj.shape&&a.push("Flip"),a.push("BringToFront"),a.push("Clone"),a.push("Delete"),"text"===o.activeObj.shape&&a.push("EditText"),r.shape=o.toPascalCase(o.activeObj.shape)):e&&(a.push("BringToFront"),a.push("Delete"),r.shape="Freehand draw"),r.toolbarItems=t.extend([],a,null,!0),o.trigger("quickAccessToolbarOpen",r);var n=[];if(r.cancel)n=[];else for(var s=0;s<r.toolbarItems.length;s++)switch(r.toolbarItems[s]){case"BringToFront":n.push({id:i+"_bringToFront",prefixIcon:"e-icons e-bring-to-front",tooltipText:this.l10n.getConstant("BringToFront"),align:"Left"});break;case"Clone":n.push({id:i+"_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+"_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+"_editText",prefixIcon:"e-icons e-annotation-edit",cssClass:"top-icon e-annotation-edit",tooltipText:this.l10n.getConstant("EditText"),align:"Left"});break;case"Flip":n.push({id:i+"_hFlip",prefixIcon:"e-icons e-horizontal-flip",tooltipText:this.l10n.getConstant("HorizontalFlip"),align:"Left"}),n.push({id:i+"_vFlip",prefixIcon:"e-icons e-vertical-flip",tooltipText:this.l10n.getConstant("VerticalFlip"),align:"Left"});break;default:n.push(r.toolbarItems[s])}return n},s.prototype.renderQAT=function(e){var o=this.parent,i=o.element.id;if(o.activeObj&&o.showQuickAccessToolbar){var a=document.getElementById(i+"_quickAccessToolbarArea");a&&(this.destroyQuickAccessToolbar(),a.style.display="block");var n=this.getQuickAccessToolbarItem(e);if(0===n.length)return;t.isNullOrUndefined(o.quickAccessToolbarTemplate)&&new r.Toolbar({items:n,clicked:this.quickAccessToolbarClicked.bind(this)}).appendTo("#"+i+"_quickAccessToolbar");var s=this.toolbarHeight&&0!==this.toolbarHeight?this.toolbarHeight:a.clientHeight;if(t.isNullOrUndefined(e)&&(0!==o.activeObj.activePoint.width||0!==o.activeObj.activePoint.height||o.activeObj.shape&&"path"===o.activeObj.shape&&o.activeObj.pointColl.length>0)){g={order:null};o.notify("shape",{prop:"getHighestOrder",onPropertyChange:!1,value:{obj:g}}),o.activeObj.order>g.order?document.getElementById(o.element.id+"_bringToFront").classList.add("e-disabled"):document.getElementById(o.element.id+"_bringToFront").classList.remove("e-disabled"),a.style.width="auto",o.activeObj.activePoint.width=Math.abs(o.activeObj.activePoint.width),o.activeObj.activePoint.height=Math.abs(o.activeObj.activePoint.height);var l=o.activeObj.activePoint.startX<o.activeObj.activePoint.endX?o.activeObj.activePoint.startX:o.activeObj.activePoint.endX,p=o.activeObj.activePoint.startY<o.activeObj.activePoint.endY?o.activeObj.activePoint.startY:o.activeObj.activePoint.endY,h=o.activeObj.activePoint.width;if(0!==o.activeObj.rotatedAngle&&"arrow"!==o.activeObj.shape){var d={activePoint:null};o.notify("shape",{prop:"getSquarePointForRotatedShape",onPropertyChange:!1,value:{obj:o.activeObj,object:d}}),l=(C=d.activePoint).startX,p=C.startY,h=C.width}else if("path"===o.activeObj.shape){var c=o.getSquarePointForPath(o.activeObj);l=c.startX,p=c.startY,h=c.width}if(a.style.left=l+h/2-25*n.length+"px",parseFloat(a.style.left)+a.clientWidth/2!==l+h/2){var u=l+h/2-(parseFloat(a.style.left)+a.clientWidth/2);a.style.left=parseFloat(a.style.left)+u+"px"}p-(s+s/1.5)<o.img.destTop?a.style.top=o.img.destTop+"px":a.style.top=p-(s+s/1.5)+"px"}else if(e){var v={freehandSelectedIndex:-1};o.notify("freehand-draw",{prop:"getFreehandSelectedIndex",onPropertyChange:!1,value:{obj:v}});var g={order:null};o.notify("shape",{prop:"getHighestOrder",onPropertyChange:!1,value:{obj:g}}),o.getObjFromId(o.pointColl[v.freehandSelectedIndex].id).order>=g.order?document.getElementById(o.element.id+"_bringToFront").classList.add("e-disabled"):document.getElementById(o.element.id+"_bringToFront").classList.remove("e-disabled");var f={activePoint:null};o.notify("freehand-draw",{prop:"getSqPtFD",value:{idx:v.freehandSelectedIndex,obj:f}});var C=f.activePoint;a.style.width="auto",a.style.left=C.startX+C.width/2-24*n.length+"px",C.startY-(s+s/1.5)<o.img.destTop?a.style.top=o.img.destTop+"px":a.style.top=C.startY-(s+s/1.5)+"px"}else a.style.display="none";parseFloat(a.style.top)<0&&(a.style.top="0px")}},s.prototype.refreshDropDownBtn=function(e){if(!t.isNullOrUndefined(e)){var o=this.parent.element.id,i=document.querySelector("#"+o+"_annotationBtn");i&&(e?(i.classList.add("e-disabled"),i.parentElement.classList.add("e-overlay")):(i.classList.remove("e-disabled"),i.parentElement.classList.remove("e-overlay")),t.getComponent(i,"dropdown-btn").disabled=e);var r=document.querySelector("#"+o+"_transformBtn");r&&(e?(r.classList.add("e-disabled"),r.parentElement.classList.add("e-overlay")):(r.classList.remove("e-disabled"),r.parentElement.classList.remove("e-overlay")),t.getComponent(r,"dropdown-btn").disabled=e);var a=document.querySelector("#"+o+"_adjustment");a&&(e?(a.classList.add("e-disabled"),a.parentElement.classList.add("e-overlay")):(a.classList.remove("e-disabled"),a.parentElement.classList.remove("e-overlay")),t.getComponent(a,"btn").disabled=e);var n=document.querySelector("#"+o+"_filter");n&&(e?(n.classList.add("e-disabled"),n.parentElement.classList.add("e-overlay")):(n.classList.remove("e-disabled"),n.parentElement.classList.remove("e-overlay")),t.getComponent(n,"btn").disabled=e)}},s.prototype.cropSelect=function(e){var o=this.parent;o.isCropTab=!0,t.isNullOrUndefined(o.transform.cropZoomFactor)&&(o.transform.cropZoomFactor=o.transform.zoomFactor,o.notify("draw",{prop:"setTempZoomFactor",onPropertyChange:!1,value:{tempZoomFactor:o.transform.zoomFactor}})),o.transform.zoomFactor=o.transform.cropZoomFactor;var i=e.item.id;this.currentToolbar="crop",o.currSelectionPoint=null,o.notify("draw",{prop:"setIsCropSelect",value:{bool:!0}});var r={prevObj:null};o.notify("crop",{prop:"getPreviousCropCurrentObj",value:{obj:r}}),o.notify("draw",{prop:"select",onPropertyChange:!1,value:{type:i,startX:null,startY:null,width:null,height:null}}),o.notify("crop",{prop:"setPreviousCropCurrentObj",value:{obj:r.prevObj}}),this.enableDisableTbrBtn(),o.notify("transform",{prop:"disableZoomOutBtn",value:{isZoomOut:!0}})},s.prototype.quickAccessToolbarClicked=function(e,o){var i=this.parent,r=i.element.id;if(e.item){var a=null,n={prevActObj:null},s={tempObj:null};i.notify("draw",{prop:"getPrevActObj",onPropertyChange:!1,value:{obj:n}}),i.notify("selection",{prop:"getTempActObj",onPropertyChange:!1,value:{obj:s}}),s.tempObj.activePoint.height=Math.abs(s.tempObj.activePoint.height);var l={isNewPath:null},p=void 0;i.notify("draw",{prop:"getNewPath",value:{obj:l}});var h=e.item.id.replace(r+"_","").toLowerCase(),d=void 0,c=void 0,u={freehandSelectedIndex:null},v=void 0,g=void 0,f={order:null};switch(h){case"duplicate":i.element.querySelector("#"+r+"_duplicate").classList.contains("e-disabled")||(this.refreshSlider(),l.isNewPath||JSON.stringify(s.tempObj)!==JSON.stringify(i.activeObj)||(a=!0),this.duplicateShape(a));break;case"remove":i.element.querySelector("#"+r+"_remove").classList.contains("e-disabled")||(i.noPushUndo=!1,this.refreshSlider(),i.notify("selection",{prop:"deleteItem",onPropertyChange:!1}));break;case"edittext":i.element.querySelector("#"+r+"_editText").classList.contains("e-disabled")||this.editText();break;case"rotleft":case"rotright":d=i.element.querySelector("#"+r+"_rotLeft"),c=i.element.querySelector("#"+r+"_rotRight"),(d&&!d.classList.contains("e-disabled")||c&&!c.classList.contains("e-disabled"))&&i.rotateImage(e.item.id.replace(r+"_","").toLowerCase()),i.notify("undo-redo",{prop:"updateUndoRedoStack",onPropertyChange:!1});break;case"hflip":i.element.querySelector("#"+r+"_hFlip").classList.contains("e-disabled")||(p=i.activeObj.imageCanvas.getContext("2d"),i.horizontalFlip(p)),i.notify("undo-redo",{prop:"updateUndoRedoStack",onPropertyChange:!1});break;case"vflip":i.element.querySelector("#"+r+"_vFlip").classList.contains("e-disabled")||(p=i.activeObj.imageCanvas.getContext("2d"),i.verticalFlip(p)),i.notify("undo-redo",{prop:"updateUndoRedoStack",onPropertyChange:!1});break;case"bringtofront":if(!i.element.querySelector("#"+r+"_bringToFront").classList.contains("e-disabled")){if(i.notify("freehand-draw",{prop:"getFreehandSelectedIndex",onPropertyChange:!1,value:{obj:u}}),v=null!==u.freehandSelectedIndex?i.pointColl[u.freehandSelectedIndex].id:i.activeObj.currIndex,i.updateShapeOrder(v,h),g=!1,i.notify("shape",{prop:"getHighestOrder",onPropertyChange:!1,value:{obj:f}}),v.indexOf("pen")>-1)i.notify("shape",{prop:"updateShapeColl",onPropertyChange:!1}),g=(C=i.getObjFromId(v).order)>=f.order;else{var C=i.getObjFromId(v).order;g=C>f.order}g?document.getElementById(i.element.id+"_bringToFront").classList.add("e-disabled"):document.getElementById(i.element.id+"_bringToFront").classList.remove("e-disabled"),i.notify("undo-redo",{prop:"updateUndoRedoStack",onPropertyChange:!1})}}"duplicate"!==h&&"remove"!==h||i.notify("draw",{prop:"redrawDownScale"})}t.isNullOrUndefined(o)&&i.trigger("quickAccessToolbarItemClick",e)},s.prototype.editText=function(){var e=this.parent,o={x:e.activeObj.activePoint.startX,y:e.activeObj.activePoint.startY};if(this.upperContext.clearRect(0,0,e.upperCanvas.width,e.upperCanvas.height),e.notify("selection",{prop:"setTempActObj",onPropertyChange:!1,value:{obj:t.extend({},e.activeObj,{},!0)}}),e.notify("selection",{prop:"setInitialTextEdit",onPropertyChange:!1,value:{bool:!0}}),e.notify("draw",{prop:"setPrevActObj",onPropertyChange:!1,value:{prevActObj:t.extend({},e.activeObj,{},!0)}}),0!==e.activeObj.rotatedAngle){var i={x:o.x,y:o.y};e.notify("shape",{prop:"getTextBoxPosition",onPropertyChange:!1,value:{obj:e.activeObj,object:i}}),o.x=i.x,o.y=i.y;var r={x:o.x,y:o.y};e.notify("shape",{prop:"setFlipState",onPropertyChange:!1,value:{x:o.x,y:o.y,obj:e.activeObj,object:r}}),o.x=r.x,o.y=r.y}var a=t.extend({},e.activeObj,{},!0);e.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),this.upperContext.clearRect(0,0,e.upperCanvas.width,e.upperCanvas.height),this.lowerContext.clearRect(0,0,e.upperCanvas.width,e.upperCanvas.height),e.notify("draw",{prop:"redrawImgWithObj",onPropertyChange:!1}),e.notify("draw",{prop:"redrawDownScale"}),e.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.lowerContext}}),e.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.upperContext}}),e.activeObj=a,e.notify("shape",{prop:"renderTextArea",onPropertyChange:!1,value:{x:o.x,y:o.y,actObj:e.activeObj}}),t.isNullOrUndefined(e.activeObj.currIndex)&&e.notify("draw",{prop:"setShapeTextInsert",onPropertyChange:!1,value:{bool:!0}}),document.getElementById(e.element.id+"_quickAccessToolbarArea")&&(document.getElementById(e.element.id+"_quickAccessToolbarArea").style.display="none")},s.prototype.duplicateShape=function(e,o){var i=this.parent,r={activePoint:{startX:0,startY:0,endX:0,endY:0,width:0,height:0},flipObjColl:[],triangle:[],triangleRatio:[]};i.notify("selection",{prop:"setTempActObj",onPropertyChange:!1,value:{obj:r}});var a={prevActObj:null};i.notify("draw",{prop:"getPrevActObj",onPropertyChange:!1,value:{obj:a}});var n={isNewPath:null};i.notify("draw",{prop:"getNewPath",value:{obj:n}});var s,l=t.extend({},i.activeObj,{},!0),p={order:null};i.notify("shape",{prop:"getHighestOrder",onPropertyChange:!1,value:{obj:p}}),l.order?(i.notify("shape",{prop:"updateShapeColl",onPropertyChange:!1}),l.order=p.order>l.order?p.order+1:l.order+1):(i.noPushUndo=!0,i.okBtn(),i.noPushUndo=!1,i.selectShape(l.currIndex),l.order=p.order>l.order?p.order+1:l.order+1),"image"===l.shape&&(s=t.extend([],i.objColl,[],!0),i.notify("undo-redo",{prop:"updateUrObj",onPropertyChange:!1,value:{objColl:s}})),t.isNullOrUndefined(i.activeObj.currIndex)?i.notify("shape",{prop:"applyActObj",onPropertyChange:!1,value:{isMouseDown:e}}):a.prevActObj||o?(i.activeObj.currIndex=null,l.currIndex=null,i.notify("shape",{prop:"applyActObj",onPropertyChange:!1,value:{isMouseDown:e}})):i.notify("shape",{prop:"applyActObj",onPropertyChange:!1,value:{isMouseDown:!0}});var h=i.noPushUndo;if(i.noPushUndo=!1,i.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"ok"}}),i.noPushUndo=h,s=t.extend([],i.objColl,[],!0),l.activePoint.startX+=10,l.activePoint.startY-=10,l.activePoint.endX+=10,l.activePoint.endY-=10,"path"===l.shape)for(var d=0;d<l.pointColl.length;d++)l.pointColl[d].x+=10,l.pointColl[d].y-=10;else"image"===l.shape&&(l.imageCanvas=i.createElement("canvas"));var c={id:"shape_"+(i.objColl.length+1)};if(i.notify("shape",{prop:"getNewShapeId",onPropertyChange:!1,value:{obj:c}}),l.currIndex=c.id,i.activeObj=t.extend({},l,{},!0),"image"===i.activeObj.shape){var u=t.extend({},l.activePoint,{},!0),v={width:0,height:0};i.notify("transform",{prop:"calcMaxDimension",onPropertyChange:!1,value:{width:i.activeObj.imageElement.width,height:i.activeObj.imageElement.height,obj:v,isImgShape:null}}),i.activeObj.activePoint.width=v.width,i.activeObj.activePoint.height=v.height,i.activeObj.isHorImageFlip&&i.activeObj.isVerImageFlip?(i.activeObj.isHorImageFlip=i.activeObj.isVerImageFlip=!1,i.notify("draw",{prop:"downScaleImgCanvas",onPropertyChange:!1,value:{ctx:l.imageCanvas.getContext("2d"),isImgAnnotation:!0,isHFlip:!0,isVFlip:!0}}),i.activeObj.isHorImageFlip=i.activeObj.isVerImageFlip=!0):i.activeObj.isHorImageFlip?(i.activeObj.isHorImageFlip=!1,i.notify("draw",{prop:"downScaleImgCanvas",onPropertyChange:!1,value:{ctx:l.imageCanvas.getContext("2d"),isImgAnnotation:!0,isHFlip:!0,isVFlip:null}}),i.activeObj.isHorImageFlip=!0):i.activeObj.isVerImageFlip?(i.activeObj.isVerImageFlip=!1,i.notify("draw",{prop:"downScaleImgCanvas",onPropertyChange:!1,value:{ctx:l.imageCanvas.getContext("2d"),isImgAnnotation:!0,isHFlip:null,isVFlip:!0}}),i.activeObj.isVerImageFlip=!0):i.notify("draw",{prop:"downScaleImgCanvas",onPropertyChange:!1,value:{ctx:l.imageCanvas.getContext("2d"),isImgAnnotation:!0,isHFlip:null,isVFlip:null}}),i.activeObj.activePoint=u}"line"!==i.activeObj.shape&&"arrow"!==i.activeObj.shape||i.notify("shape",{prop:"setPointCollForLineArrow",onPropertyChange:!1,value:{obj:i.activeObj}}),i.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate",obj:i.activeObj,isCropRatio:null,points:null,isPreventDrag:!0}}),i.notify("undo-redo",{prop:"updateUrObj",onPropertyChange:!1,value:{objColl:s}}),this.renderQAT()},s.prototype.defToolbarClicked=function(e){var o=this.parent,i=o.element.id,r=!1,a=!1;if(!this.isFrameToolbar&&o.element.querySelector(".e-contextual-toolbar-wrapper")){o.element.querySelector(".e-contextual-toolbar-wrapper").classList.contains("e-hide")||(r=a=!0);var n={bool:o.isStraightening};(!t.Browser.isDevice||t.Browser.isDevice&&!n.bool)&&o.element.querySelector(".e-contextual-toolbar-wrapper").classList.add("e-hide")}if(e.item){var s=e.item.id.replace(i+"_","").toLowerCase();if("duplicate"===s||"remove"===s||"edittext"===s||"hflip"===s||"vflip"===s||"rotleft"===s||"rotright"===s)this.quickAccessToolbarClicked(e,!0),o.trigger("toolbarItemClicked",e);else{var l=!1,p=!1,h=document.querySelector("#"+i+"_adjustment");h&&h.classList.contains("e-disabled")&&(p=!0);var d=document.querySelector("#"+i+"_filter");d&&d.classList.contains("e-disabled")&&(l=!0),this.enableDisableTbrBtn(),this.performDefTbrClick(s,r,p,l,a),o.trigger("toolbarItemClicked",e),o.isStraightening&&o.notify("transform",{prop:"disableZoomOutBtn",value:{isZoomOut:!0}}),-1!==["undo","redo","cancel","aspectratio","nonaspectratio","save","duplicate","filter","frame","none","mat","bevel","line","inset","hook","resize","remove"].indexOf(s)&&o.notify("draw",{prop:"redrawDownScale"})}}},s.prototype.performDefTbrClick=function(e,i,r,a,n){var s,l,p=this.parent,h=p.element.id,d=p.element.querySelector("#"+h+"_zoomIn"),c=p.element.querySelector("#"+h+"_resizeHeight"),u=p.element.querySelector("#"+h+"_resizeWidth"),v=!1;if(void 0!==p.activeObj.shape&&(l=p.activeObj.shape.split("-")),void 0===l&&p.currObjType.isCustomCrop?v=!0:void 0!==l&&"crop"===l[0]&&(v=!0),!p.disabled)switch(e){case"pan":p.currObjType.isCustomCrop=p.currObjType.isFiltered=!1,p.currObjType.isUndoAction&&p.notify("undo-redo",{prop:"refreshUrc",value:{bool:null}}),v&&(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=p.element.querySelector(".e-img-pan .e-btn"))&&s.classList.add("e-selected-btn"),p.pan(!0),p.notify("transform",{prop:"setDisablePan",onPropertyChange:!1,value:{bool:!1}})),d&&p.zoomSettings.zoomFactor>=p.zoomSettings.maxZoomFactor?(d.classList.add("e-disabled"),d.parentElement.classList.add("e-overlay")):d&&(d.classList.remove("e-disabled"),d.parentElement.classList.remove("e-overlay")),this.refreshToolbar("main");break;case"cancel":p.notify("draw",{prop:"performCancel",value:{isContextualToolbar:i,isFinalCancel:!0}});break;case"ok":p.okBtn(null,!0),p.drawingShape=null,this.refreshDropDownBtn(!1),this.currentToolbar="main",p.isStraightening=!1,p.notify("draw",{prop:"resetTempObjColl"}),p.notify("draw",{prop:"resetTempPointColl"});break;case"crop":p.notify("transform",{prop:"disableZoomOutBtn",value:{isZoomOut:!0}}),t.Browser.isDevice&&this.updateContextualToolbar("color","straighten");break;case"reset":p.reset(),this.imageHeight=null,this.imageWidth=null,p.aspectHeight=null,p.aspectWidth=null,this.isAspectRatio=!0,this.currentToolbar="main";break;case"undo":p.noPushUndo=!1,(p.togglePen||p.drawingShape)&&(p.okBtn(),p.drawingShape=null),p.notify("undo-redo",{prop:"call-undo"});break;case"redo":p.noPushUndo=!1,(p.togglePen||p.drawingShape)&&(p.okBtn(),p.drawingShape=null),p.notify("undo-redo",{prop:"call-redo"});break;case"aspectratio":(!p.isCircleCrop&&t.isNullOrUndefined(p.currSelectionPoint)||p.currSelectionPoint&&"crop-circle"!==p.currSelectionPoint.shape)&&(t.getComponent(u,"numerictextbox").value?(p.aspectWidth=t.getComponent(u,"numerictextbox").value,p.aspectHeight=t.getComponent(c,"numerictextbox").value,p.notify("transform",{prop:"resize",value:{width:p.aspectWidth,height:null,isAspectRatio:!0}})):t.getComponent(c,"numerictextbox").value&&(p.aspectWidth=parseFloat(t.getComponent(u,"numerictextbox").placeholder),p.aspectHeight=t.getComponent(c,"numerictextbox").value,p.notify("transform",{prop:"resize",value:{width:p.aspectWidth,height:p.aspectHeight,isAspectRatio:!0}})),p.resizeSrc={startX:p.img.srcLeft,startY:p.img.srcTop,width:p.img.srcWidth,height:p.img.srcHeight},this.refreshToolbar("resize"));break;case"nonaspectratio":(t.getComponent(u,"numerictextbox").value||t.getComponent(c,"numerictextbox").value)&&(p.aspectWidth=t.getComponent(u,"numerictextbox").value?t.getComponent(u,"numerictextbox").value:parseFloat(t.getComponent(u,"numerictextbox").placeholder),p.aspectHeight=t.getComponent(c,"numerictextbox").value?t.getComponent(c,"numerictextbox").value:parseFloat(t.getComponent(c,"numerictextbox").placeholder),p.notify("transform",{prop:"resize",value:{width:p.aspectWidth,height:p.aspectHeight,isAspectRatio:!1}})),p.resizeSrc={startX:p.img.srcLeft,startY:p.img.srcTop,width:p.img.srcWidth,height:p.img.srcHeight},this.refreshToolbar("resize");break;case"resize":p.currObjType.isFiltered&&p.okBtn(),this.resizeClick();break;case"adjustment":r||(p.currObjType.isFiltered&&p.okBtn(),this.refreshToolbar("adjustment"),p.setTempFilterProperties(),p.notify("draw",{prop:"updateFinetune"}),p.notify("filter",{prop:"setTempAdjVal"}),this.openSlider("brightness"));break;case"brightness":case"contrast":case"hue":case"saturation":case"opacity":case"blur":case"exposure":this.openSlider(e);break;case"filter":a||(o.showSpinner(p.element),this.refreshToolbar("filter"),p.setTempFilterProperties(),o.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:e}});break;case"upload":n&&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("#"+h+"_bold").classList.contains("e-selected-btn")?p.element.querySelector("#"+h+"_bold").classList.remove("e-selected-btn"):p.element.querySelector("#"+h+"_bold").classList.add("e-selected-btn"),0===p.activeObj.activePoint.width&&0===p.activeObj.activePoint.height||p.notify("undo-redo",{prop:"updateUndoRedoStack",onPropertyChange:!1});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("#"+h+"_italic").classList.contains("e-selected-btn")?p.element.querySelector("#"+h+"_italic").classList.remove("e-selected-btn"):p.element.querySelector("#"+h+"_italic").classList.add("e-selected-btn"),0===p.activeObj.activePoint.width&&0===p.activeObj.activePoint.height||p.notify("undo-redo",{prop:"updateUndoRedoStack",onPropertyChange:!1});break;case"croptransform":this.performCropTransformClick();break;case"rotateleft":case"rotateright":case"horizontalflip":case"verticalflip":p.transformSelect(e),"rotateleft"!==e&&"rotateright"!==e||(p.notify("draw",{prop:"resetStraightenDestPoints"}),p.notify("draw",{prop:"setDestForStraighten"})),p.notify("transform",{prop:"disableZoomOutBtn",value:{isZoomOut:!0}}),t.Browser.isDevice&&this.updateContextualToolbar("color","straighten");break;case"save":p.noPushUndo=!1,p.okBtn(),p.drawingShape=null,this.saveDialogPopup();break;case"transparency":this.updateContextualToolbar("transparency","transparency");break;case"frame":this.frameToolbarClick();break;case"none":case"mat":case"bevel":case"line":case"inset":case"hook":this.unselectFrameBtn(),p.element.querySelector("#"+h+"_"+e)&&p.element.querySelector("#"+h+"_"+e).classList.add("e-selected-btn"),p.frameObj.type=e,p.frameObj.size=20,p.frameObj.inset=20,p.frameObj.radius=0,p.frameObj.amount=1,p.frameObj.offset="inset"===e?60:20,this.refreshToolbar("frame"),p.notify("draw",{prop:"render-image",value:{isMouseWheel:null,isPreventClearRect:null,isFrame:!0}}),p.isFrameBtnClick=!0,p.curFrameObjEvent={previousFrameSetting:p.tempFrameObj,currentFrameSetting:p.frameObj}}},s.prototype.frameToolbarClick=function(){var e,o,i,r=this.parent,a=r.element.id,n=document.querySelector("#"+a+"_frame");r.notify("draw",{prop:"updateCropSelection",onPropertyChange:!1}),r.currObjType.isFiltered&&r.okBtn(),n&&!n.classList.contains("e-disabled")&&(e=r.transform.zoomFactor,r.frameDestPoints=t.extend({},r.img,{},!0),t.isNullOrUndefined(r.cxtTbarHeight)&&(o=t.extend({},r.frameObj,{},!0),i=t.extend({},r.tempFrameObj,{},!0),this.callFrameToolbar(),r.frameObj.type="mat",this.callFrameToolbar(),r.cxtTbarHeight=r.element.querySelector("#"+a+"_customizeWrapper").scrollHeight,r.frameObj=o,r.tempFrameObj=i),this.zoomToFrameRange(),r.tempFrameZoomLevel=e,t.Browser.isDevice?r.img.destTop-=r.cxtTbarHeight/2:r.img.destTop+=r.cxtTbarHeight/2,this.callFrameToolbar())},s.prototype.zoomToFrameRange=function(){var e=this.parent;this.isFrameToolbar=!1,e.notify("transform",{prop:"resetZoom",onPropertyChange:!1});for(var t=!0;t;){if(this.toolbarHeight+e.img.destTop>=this.toolbarHeight+e.cxtTbarHeight){t=!1;break}e.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:-.1,zoomPoint:null,isResize:!0}})}this.isFrameToolbar=!0},s.prototype.resizeClick=function(){var e=this.parent;e.notify("draw",{prop:"updateCropSelection",onPropertyChange:!1}),e.upperCanvas.style.cursor="default",e.notify("transform",{prop:"updateResize",value:{bool:!1}}),this.isAspectRatio?this.isAspectRatio=!1:this.isAspectRatio=!0,e.isResize=!0,this.refreshToolbar("resize")},s.prototype.callFrameToolbar=function(){var e=this.parent;t.extend(e.tempFrameObj,e.frameObj);var o={appliedUndoRedoColl:[]};if(e.notify("undo-redo",{prop:"getAppliedUndoRedoColl",value:{obj:o}}),0===o.appliedUndoRedoColl.length){var i={currObj:{}};e.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:i}}),e.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"frame",previousObj:i.currObj,previousObjColl:i.currObj.objColl,previousPointColl:i.currObj.pointColl,previousSelPointColl:i.currObj.selPointColl,previousCropObj:t.extend({},e.cropObj,{},!0),previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}})}this.refreshToolbar("frame")},s.prototype.contextualToolbarClicked=function(e){var t=this.parent,o=t.element.querySelector(".e-contextual-toolbar-wrapper .e-toolbar-item.e-selected");o&&o.classList.remove("e-selected");var i=e.item.id.replace(t.element.id,"").split("_")[1],r={filter:t.toPascalCase(i),cancel:!1};t.trigger("imageFiltering",r),r.cancel||(document.getElementById(e.item.id+"Canvas").parentElement.parentElement.classList.add("e-selected"),t.currObjType.isFiltered=!0,t.notify("filter",{prop:"applyImageFilter",value:{option:i.toLowerCase()}}),t.notify("draw",{prop:"redrawDownScale"}),t.currentFilter=e.item.id,this.enableDisableTbrBtn(),t.isFilterCanvasClick=!0,t.curFilterObjEvent=r)},s.prototype.refreshShapeDrawing=function(){var e=this.parent,t={shape:""};e.notify("selection",{prop:"getCurrentDrawingShape",onPropertyChange:!1,value:{obj:t}}),""!==t.shape&&(e.notify("selection",{prop:"setCurrentDrawingShape",onPropertyChange:!1,value:{value:""}}),e.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),this.refreshToolbar("main",!1))},s.prototype.zoomInBtnClickHandler=function(o){if(o){var i=this.parent;if((i.zoomSettings.zoomTrigger&e.ZoomTrigger.Toolbar)===e.ZoomTrigger.Toolbar){i.noPushUndo=!1,i.currObjType.isFiltered&&i.okBtn();var r=i.drawingShape;if(i.drawingShape){var a=i.activeObj.currIndex;i.noPushUndo=!0,i.okBtn(),i.noPushUndo=!1,i.drawingShape=null,a&&i.selectShape(a)}if(this.refreshShapeDrawing(),t.Browser.isDevice&&"touchstart"===o.type){if(!o.returnValue)return;o.preventDefault()}var n=document.querySelector("#"+i.element.id+"_zoomIn");t.EventHandler.trigger(n,"click");var s={bool:!1};i.notify("selection",{prop:"getFreehandDrawEditing",onPropertyChange:!1,value:{obj:s}}),s.bool&&(i.notify("freehand-draw",{prop:"applyFhd",onPropertyChange:!1}),this.destroyQuickAccessToolbar()),i.isZoomBtnClick=!0,this.applyPreviewFilter(),i.currObjType.isFiltered=!1,i.togglePen&&(i.currObjType.isZoomed=!0,i.freeHandDraw(!1),i.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"ok"}})),i.notify("draw",{prop:"resetCurrentSelectionPoint"}),i.drawingShape=r,i.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:.1,zoomPoint:null,isResize:null}}),i.notify("draw",{prop:"redrawDownScale"}),(i.isCropTab||i.activeObj.shape)&&(i.notify("draw",{prop:"setStraightenActObj",value:{activeObj:null}}),i.notify("freehand-draw",{prop:"resetStraightenPoint"})),i.isStraightening&&(i.notify("draw",{prop:"resetStraightenDestPoints"}),i.notify("draw",{prop:"setDestForStraighten"}))}}},s.prototype.zoomOutBtnClickHandler=function(o){if(o){var i=this.parent;if((i.zoomSettings.zoomTrigger&e.ZoomTrigger.Toolbar)===e.ZoomTrigger.Toolbar){i.noPushUndo=!1,i.currObjType.isFiltered&&i.okBtn();var r=i.drawingShape;if(i.drawingShape){var a=i.activeObj.currIndex;i.noPushUndo=!0,i.okBtn(),i.noPushUndo=!1,i.drawingShape=null,a&&i.selectShape(a)}if(this.refreshShapeDrawing(),t.Browser.isDevice&&"touchstart"===o.type){if(!o.returnValue)return;o.preventDefault()}var n=document.querySelector("#"+i.element.id+"_zoomOut");t.EventHandler.trigger(n,"click");var s={bool:!1};i.notify("selection",{prop:"getFreehandDrawEditing",onPropertyChange:!1,value:{obj:s}}),s.bool&&(i.notify("freehand-draw",{prop:"applyFhd",onPropertyChange:!1}),this.destroyQuickAccessToolbar()),i.isZoomBtnClick=!0,this.applyPreviewFilter(),i.currObjType.isFiltered=!1,i.togglePen&&(i.currObjType.isZoomed=!0,i.freeHandDraw(!1),i.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"ok"}})),i.notify("draw",{prop:"resetCurrentSelectionPoint"}),i.drawingShape=r,i.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:-.1,zoomPoint:null,isResize:null}}),i.notify("draw",{prop:"redrawDownScale"}),(i.isCropTab||i.activeObj.shape)&&(i.notify("draw",{prop:"setStraightenActObj",value:{activeObj:null}}),i.notify("freehand-draw",{prop:"resetStraightenPoint"})),i.isStraightening&&(i.notify("draw",{prop:"resetStraightenDestPoints"}),i.notify("draw",{prop:"setDestForStraighten"}))}}},s.prototype.zoomInBtnMouseDownHandler=function(e){e.preventDefault(),this.zoomBtnHold=setInterval(this.zoomInBtnClickHandler.bind(this),250)},s.prototype.zoomOutBtnMouseDownHandler=function(e){e.preventDefault(),this.zoomBtnHold=setInterval(this.zoomOutBtnClickHandler.bind(this),250)},s.prototype.zoomBtnMouseUpHandler=function(){clearInterval(this.zoomBtnHold),this.zoomBtnHold=0},s.prototype.closeContextualToolbar=function(){var e=this.parent,o=e.element.id,i=!1,r={bool:e.isStraightening};return(!t.Browser.isDevice||t.Browser.isDevice&&!r.bool)&&(e.element.querySelector("#"+o+"_contextualToolbar")&&!e.element.querySelector("#"+o+"_contextualToolbar").parentElement.classList.contains("e-hide")||e.element.querySelector("#"+o+"_headWrapper")&&!e.element.querySelector("#"+o+"_headWrapper").parentElement.classList.contains("e-hide"))&&(e.element.querySelector(".e-contextual-toolbar-wrapper").classList.add("e-hide"),e.okBtn(),this.refreshMainToolbar(),i=!0),i},s.prototype.destroyQuickAccessToolbar=function(){var e=this.parent.element.id,o=document.getElementById(e+"_quickAccessToolbar");o&&o.classList.contains("e-control")&&t.getComponent(o,"toolbar").destroy();var i=document.getElementById(e+"_quickAccessToolbarArea");i&&(i.style.display="none")},s.prototype.renderSlider=function(e,o){var i=this.parent,r=i.element.id,a=document.querySelector("#"+r+"_contextualToolbarArea"),n=document.querySelector("#"+r+"_headWrapper"),s=document.querySelector("#"+r+"_labelWrapper");n&&(n.remove(),s.remove()),n=a.appendChild(i.createElement("div",{id:r+"_headWrapper",styles:"position: relative"})),(s="transparency"===e?n.appendChild(i.createElement("label",{id:r+"_labelWrapper",className:"e-ie-finetune-slider-label",styles:t.Browser.isDevice?"position: absolute; top: 31%; left: calc(50% - 150px); font-size: 15px; text-transform: capitalize; font-weight: 400;":"position: absolute; top: 31%; left: calc(50% - 220px); font-size: 15px; text-transform: capitalize; font-weight: 400;"})):n.appendChild(i.createElement("label",{id:r+"_labelWrapper",className:"e-ie-finetune-slider-label",styles:t.Browser.isDevice?"position: absolute; top: 31%; left: calc(50% - 160px); 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;"}))).textContent=this.l10n.getConstant(i.toPascalCase("transparency"===e?"opacity":e));var l=n.appendChild(i.createElement("div",{id:r+"_sliderWrapper",className:"e-ie-finetune-slider-wrap",styles:"position: absolute"})),p=i.getCurrAdjustmentValue(e);o&&"straighten"===e&&t.Browser.isDevice&&(p=i.cropObj.straighten);var h,d,c;"brightness"===e||"contrast"===e||"saturation"===e||"exposure"===e?(i.finetuneSettings?"brightness"===e&&i.finetuneSettings.brightness?(h=i.finetuneSettings.brightness.min,d=i.finetuneSettings.brightness.max):"contrast"===e&&i.finetuneSettings.contrast?(h=i.finetuneSettings.contrast.min,d=i.finetuneSettings.contrast.max):"saturation"===e&&i.finetuneSettings.saturation?(h=i.finetuneSettings.saturation.min,d=i.finetuneSettings.saturation.max):"exposure"===e&&i.finetuneSettings.exposure?(h=i.finetuneSettings.exposure.min,d=i.finetuneSettings.exposure.max):(h=-100,d=100):(h=-100,d=100),c=this.createSlider(h,d,p,e)):"hue"===e||"blur"===e||"opacity"===e?(i.finetuneSettings?"hue"===e&&i.finetuneSettings.hue?(h=i.finetuneSettings.hue.min,d=i.finetuneSettings.hue.max):"blur"===e&&i.finetuneSettings.blur?(h=i.finetuneSettings.blur.min,d=i.finetuneSettings.blur.max):"opacity"===e&&i.finetuneSettings.opacity?(h=i.finetuneSettings.opacity.min,d=i.finetuneSettings.opacity.max):(h=0,d=100):(h=0,d=100),c=this.createSlider(h,d,p,e)):"transparency"===e?(h=0,d=100,c=this.createSlider(h,d,p,e)):"straighten"===e&&(h=-45,d=45,c=this.createSlider(h,d,p,e)),c.appendTo("#"+r+"_sliderWrapper"),l.style.left=(parseFloat(a.style.width)-parseFloat(c.width))/2+"px","straighten"===e&&t.Browser.isDevice&&(n.appendChild(i.createElement("label",{id:r+"_sLabelWrapper",className:"e-ie-straighten-value-span e-ie-finetune-value-span",styles:"position: absolute; top: 31%; margin-left: 20px; font-size: 15px; text-transform: capitalize; font-weight: 400;"})).innerHTML=i.transform.straighten.toString()+"&#176",l.parentElement.classList.add("e-straighten-slider")),"straighten"!==e&&(n.appendChild(i.createElement("label",{id:r+"_finetuneSpan",className:"e-ie-finetune-value-span",styles:t.Browser.isDevice?"position: absolute; top: 25%; margin-left: 20px; font-size: 15px; text-transform: capitalize; font-weight: 400;":"position: absolute; top: 25%; left: calc(50% + 190px); font-size: 15px; text-transform: capitalize; font-weight: 400;"})),l.parentElement.classList.add("e-finetune-slider"),"transparency"===e&&t.Browser.isDevice&&l.parentElement.classList.add("e-ie-device-transparency-slider"),this.updateFinetuneSpan(e))},s.prototype.createSlider=function(e,o,r,a){var n=this,s=this.parent,l="straighten"===a?3:1;return new i.Slider({value:r,type:"MinRange",min:e,max:o,step:l,width:t.Browser.isDevice?"180px":"straighten"===a?"200px":"300px",cssClass:"e-slider",change:function(e){if(s.notify("selection",{prop:"setSliderActive",onPropertyChange:!1,value:{bool:!0}}),"transparency"===a){if(s.activeObj.shape){t.isNullOrUndefined(s.activeObj.imageRatio)&&s.notify("shape",{prop:"updImgRatioForActObj",onPropertyChange:!1}),s.notify("shape",{prop:"pushActItemIntoObj"});var o=t.extend({},s.cropObj,{},!0),i={currObj:{}};s.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:i}});var r=i.currObj;r.objColl=t.extend([],s.objColl,[],!0),r.pointColl=t.extend([],s.pointColl,[],!0),r.afterCropActions=t.extend([],s.afterCropActions,[],!0);var l={selPointColl:null};s.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:l}}),r.selPointColl=t.extend([],l.selPointColl,[],!0),s.objColl.pop(),s.activeObj.opacity=e.value/100,n.upperContext.clearRect(0,0,s.upperCanvas.width,s.upperCanvas.height),s.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate"}}),s.objColl.push(s.activeObj),s.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"shapeTransform",previousObj:r,previousObjColl:r.objColl,previousPointColl:r.pointColl,previousSelPointColl:r.selPointColl,previousCropObj:o,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),s.notify("selection",{prop:"redrawShape",value:{obj:s.objColl[s.objColl.length-1]}}),n.updateFinetuneSpan(a)}}else"straighten"===a?s.setStraighten(e.value):(s.transform.zoomFactor&&s.transform.zoomFactor<0&&(s.isFinetuning=!0),s.notify("selection",{prop:"setSliding",value:{bool:!0}}),s.setCurrAdjustmentValue(a,e.value),n.updateFinetuneSpan(a),n.enableDisableTbrBtn(),s.isFinetuning=!1)},changed:function(){"transparency"!==a&&"straighten"!==a&&(s.notify("selection",{prop:"setSliding",value:{bool:!1}}),s.notify("draw",{prop:"redrawDownScale"})),s.notify("selection",{prop:"setSliderActive",onPropertyChange:!1,value:{bool:!1}}),"transparency"===a&&setTimeout(function(){s.notify("undo-redo",{prop:"updateUndoRedoStack",onPropertyChange:!1}),s.element.querySelector("#"+s.element.id+"_transparency").click()},50)}})},s.prototype.updateFinetuneSpan=function(e){var t=this.parent,o=t.element.querySelector(".e-ie-finetune-value-span");if(o){var i={adjustmentLevel:null};t.notify("filter",{prop:"getAdjustmentLevel",onPropertyChange:!1,value:{obj:i}}),o.innerHTML=Math.round(i.adjustmentLevel[e]).toString()}},s.prototype.applyPreviewFilter=function(){var e=this.parent;(document.querySelector("#"+e.element.id+"_sliderWrapper")||e.currObjType.isFiltered)&&(e.initialAdjustmentValue=this.lowerContext.filter,e.canvasFilter=this.lowerContext.filter,e.currObjType.isFiltered=!1)},s.prototype.unselectBtn=function(){for(var e=this.parent.element.id,t=0,o=["#"+e+"_brightness","#"+e+"_contrast","#"+e+"_hue","#"+e+"_saturation","#"+e+"_opacity","#"+e+"_blur","#"+e+"_exposure"];t<o.length;t++){var i=o[t],r=document.querySelector(i);if(r&&r.classList.contains("e-selected-btn")){r.classList.remove("e-selected-btn");break}}},s.prototype.openSlider=function(e){this.unselectBtn(),this.parent.currObjType.isFiltered=!0,this.refreshToolbar("color",null,null,null,e),document.getElementById(this.parent.element.id+"_"+e).classList.add("e-selected-btn")},s.prototype.refreshSlider=function(){var e=this.parent.element.id,t=document.querySelector("#"+e+"_sliderWrapper"),o=document.querySelector(".e-slider"),i=document.querySelector("#"+e+"_headWrapper");i&&(i.style.display="none"),t&&o&&(o.ej2_instances[0].destroy(),t.remove())},s.prototype.unselectFrameBtn=function(){for(var e=this.parent.element.id,t=0,o=["#"+e+"_none","#"+e+"_mat","#"+e+"_line","#"+e+"_inset","#"+e+"_bevel","#"+e+"_hook"];t<o.length;t++){var i=o[t],r=document.querySelector(i);if(r.classList.contains("e-selected-btn")){r.classList.remove("e-selected-btn");break}}},s.prototype.updateToolbarItems=function(){var e=this.parent,o=e.element.id;if(e.isImageLoaded&&this.isToolbar()){var i=e.element.querySelector(".e-fill.e-template .e-dropdownbtn-preview"),r=e.element.querySelector(".e-stroke.e-template .e-dropdownbtn-preview"),a=e.element.querySelector(".e-text-font-color.e-template .e-dropdownbtn-preview"),n=e.element.querySelector(".e-pen-stroke-color.e-template .e-dropdownbtn-preview"),s=e.element.querySelector(".e-shape-stroke-width"),l=e.element.querySelector(".e-text-font-family"),p=e.element.querySelector(".e-text-font-size"),h=e.element.querySelector("#"+o+"_bold"),d=e.element.querySelector("#"+o+"_italic");if(e.activeObj.strokeSettings&&e.activeObj.textSettings){if(t.isNullOrUndefined(e.activeObj.strokeSettings.strokeWidth)&&(e.activeObj.strokeSettings.strokeWidth=2),i){c=e.activeObj.strokeSettings.fillColor;""===e.activeObj.strokeSettings.fillColor?i.classList.add("e-nocolor-item"):(i.classList.remove("e-nocolor-item"),i.style.background=c),document.querySelector("#"+o+"_shape_fill")&&(t.getComponent(o+"_shape_fill","colorpicker").value=c)}if(r){c=e.activeObj.strokeSettings.strokeColor;r.style.background=c,document.querySelector("#"+o+"_shape_stroke")&&(t.getComponent(o+"_shape_stroke","colorpicker").value=c)}if(a){c=e.activeObj.strokeSettings.strokeColor;a.style.background=c,document.querySelector("#"+o+"_text_font")&&(t.getComponent(o+"_text_font","colorpicker").value=c)}if(n){var c=e.activeObj.strokeSettings.strokeColor;n.style.background=c,document.querySelector("#"+o+"_pen_stroke")&&(t.getComponent(o+"_pen_stroke","colorpicker").value=c);var u={penOpacity:1};e.notify("freehand-draw",{prop:"getPenOpacity",onPropertyChange:!1,value:{obj:u}})}if(l&&(t.Browser.isDevice?l.setAttribute("style","font-family:"+e.activeObj.textSettings.fontFamily.toLowerCase()):l.textContent=e.activeObj.textSettings.fontFamily),p)for(var v=0;v<e.fontSizeColl.length;v++)if(parseInt(e.fontSizeColl[v].text,10)>=Math.round(e.activeObj.textSettings.fontSize)){p.textContent=(v+1).toString();break}if(h&&(e.activeObj.textSettings.bold?h.classList.add("e-selected-btn"):h.classList.remove("e-selected-btn")),d&&(e.activeObj.textSettings.italic?d.classList.add("e-selected-btn"):d.classList.remove("e-selected-btn")),s){var g=Math.round(e.activeObj.strokeSettings.strokeWidth).toString();s.textContent=this.getStrokeWidth(g)}}}},s.prototype.getStrokeWidth=function(e){var t;switch(parseInt(e,10)/2){case 0:t=this.l10n.getConstant("NoOutline");break;case 1:t=this.l10n.getConstant("XSmall");break;case 2:t=this.l10n.getConstant("Small");break;case 3:t=this.l10n.getConstant("Medium");break;case 4:t=this.l10n.getConstant("Large");break;case 5:t=this.l10n.getConstant("XLarge")}return t},s.prototype.cancelPan=function(){var e=this.parent;e.notify("shape",{prop:"applyActObj",onPropertyChange:!1,value:{isMouseDown:!0}});var t=e.element.querySelector(".e-img-pan .e-btn");t&&t.classList.remove("e-selected-btn"),e.pan(!1)},s.prototype.refreshMainToolbar=function(){"main"!==this.currToolbar&&this.refreshToolbar("main")},s.prototype.destroySubComponents=function(){for(var e=this.parent,o=e.element.querySelectorAll("input.e-control"),i=e.element.querySelectorAll("button.e-control"),r=0,a=o.length;r<a;r++)o[r].classList.contains("e-color-picker")&&(t.getComponent(o[r],"color-picker").destroy(),t.detach(t.select("input#"+o[r].id,e.element)));for(var r=0,a=i.length;r<a;r++)i[r].classList.contains("e-dropdown-btn")?(t.getComponent(i[r],"dropdown-btn").destroy(),t.detach(t.select("button#"+i[r].id,e.element))):i[r].classList.contains("e-btn")&&(t.getComponent(i[r],"btn").destroy(),t.detach(t.select("button#"+i[r].id,e.element)))},s.prototype.setInitialShapeSettings=function(e){var t=this.parent;t.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),t.currObjType.shape=e.item.id,t.activeObj.shape=t.currObjType.shape.toLowerCase(),t.currObjType.isDragging=t.currObjType.isCustomCrop=!1,t.activeObj.shapeDegree=t.transform.degree,t.activeObj.shapeFlip=t.transform.currFlipState,t.activeObj.textFlip=t.transform.currFlipState,t.activeObj.flipObjColl=[];var o={order:null};t.notify("shape",{prop:"getNewOrder",onPropertyChange:!1,value:{obj:o}}),t.activeObj.order=o.order},s.prototype.isToolbarString=function(e){for(var t=!1,o=0;o<e.length;o++)if("string"==typeof e[o]){t=!0;break}return t},s.prototype.excludeItems=function(e){for(var t=[],o=0;o<e.length;o++){var i=this.getIndex(e[o]);-1!==i&&t.push(i)}for(var r=[],o=0;o<this.defToolbarItems.length;o++)"Center"!==this.defToolbarItems[o].align||this.isSameIndex(t,o)||this.defToolbarItems[o].id===this.parent.element.id+"_annotation"||r.push(o);for(o=r.length-1;o>=0;o--)this.defToolbarItems.splice(r[o],1)},s.prototype.isSameIndex=function(e,t){for(var o=0;o<e.length;o++)if(e[o]===t)return!0;return!1},s.prototype.getIndex=function(e){var t=-1,o=!1;"rotateLeft"===e&&(e="rotLeft"),"rotateRight"===e&&(e="rotRight"),"horizontalFlip"===e&&(e="hflip"),"verticalFlip"===e&&(e="vflip"),"arrowStart"===e&&(e="start"),"arrowEnd"===e&&(e="end"),"fontColor"===e&&(e="strokeColor",o=!0);for(var i=0;i<this.defToolbarItems.length;i++){var r=this.defToolbarItems[i].id;if(r&&-1!==r.toLowerCase().indexOf(e.toLowerCase())){t=i;break}}return o&&(e="fontColor"),t},s.prototype.getModuleName=function(){return"toolbar-module"},s}();return e.Crop=s,e.Draw=h,e.Export=d,e.Filter=c,e.FinetuneSettings=y,e.FontFamily=x,e.FreehandDrawing=u,e.ImageEditor=w,e.Selection=v,e.SelectionSettings=j,e.Shape=g,e.ToolbarModule=O,e.Transform=f,e.UndoRedo=C,e.ZoomSettings=P,e}({},ej.base,ej.popups,ej.inputs,ej.navigations,ej.buttons,ej.splitbuttons),this.ejs=ej;
10
+ this.ej=this.ej||{},this.ej.imageeditor=function(e,t,o,i,r,a,n){"use strict";var s=function(){function e(e){this.croppedDegree=0,this.cropDestPoints={startX:0,startY:0,width:0,height:0},this.tempFlipPanPoint={x:0,y:0},this.isPreventScaling=!1,this.isInitCrop=!1,this.isTransformCrop=!1,this.parent=e,this.addEventListener()}return e.prototype.destroy=function(){this.parent.isDestroyed||this.removeEventListener()},e.prototype.addEventListener=function(){this.parent.on("crop",this.cropping,this),this.parent.on("destroyed",this.destroy,this)},e.prototype.removeEventListener=function(){this.parent.off("crop",this.cropping),this.parent.off("destroyed",this.destroy)},e.prototype.cropping=function(e){switch(this.updateCropPvtVar(),e.prop){case"cropCircle":this.cropCircle(e.value.context,e.value.isSave,e.value.isFlip);break;case"setCurrSelPoints":this.setCurrSelPoints(e.value.isSetDimension);break;case"updateRotatePan":this.updateRotatePan();break;case"crop":this.crop(e.value.obj);break;case"calcRatio":this.calcRatio(e.value.obj,e.value.dimension);break;case"getCurrFlipState":this.getCurrFlipState(e.value.panObj);break;case"getPreviousCropCurrentObj":e.value.obj.prevObj=this.prevCropCurrObj;break;case"setPreviousCropCurrentObj":this.prevCropCurrObj=e.value.obj;break;case"setCropDestPoints":this.cropDestPoints=e.value.point;break;case"getTempFlipPanPoint":e.value.obj.point=this.tempFlipPanPoint;break;case"setTempFlipPanPoint":t.isNullOrUndefined(e.value.isAdd)?this.tempFlipPanPoint=e.value.point:(this.tempFlipPanPoint.x+=e.value.point.x,this.tempFlipPanPoint.y+=e.value.point.y);break;case"getPreventScaling":e.value.obj.bool=this.isPreventScaling;break;case"adjustStraightenForShapes":this.adjustStraightenForShapes(e.value.type,e.value.isInitialRotated);break;case"resizeWrapper":this.resizeWrapper();break;case"setTransformCrop":this.isTransformCrop=e.value.bool;break;case"setInitCrop":this.isInitCrop=e.value.bool;break;case"resetZoom":this.resetZoom();break;case"revertTransform":this.revertTransform(e.value.type,e.value.coll);break;case"reset":this.reset()}},e.prototype.getModuleName=function(){return"crop"},e.prototype.updateCropPvtVar=function(){var e=this.parent;e.lowerCanvas&&(this.lowerContext=e.lowerCanvas.getContext("2d")),e.upperCanvas&&(this.upperContext=e.upperCanvas.getContext("2d"))},e.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},this.isPreventScaling=!1,this.isInitCrop=!1,this.isTransformCrop=!1},e.prototype.cropImg=function(e){for(var o=this.parent,i=t.isNullOrUndefined(e),r=o.element.querySelector("#"+o.element.id+"_nonaspectratio"),a=o.activeObj.activePoint,n=o.img,s=!1,l=0,p=o.rotateFlipColl.length;l<p;l++){var h=o.rotateFlipColl[l];90!==h&&-90!==h||(s=!0)}if(o.notify("draw",{prop:"setImageEdited",onPropertyChange:!1}),(i||r)&&(this.croppedDegree=o.transform.degree),i&&0!==o.transform.degree||s){this.updateCropObj();c={startX:n.destLeft,startY:n.destTop,width:n.destWidth,height:n.destHeight};o.notify("transform",{prop:"setCurrDestinationPoint",onPropertyChange:!1,value:{point:c}}),this.rotateCrop()}else if(i&&""!==o.transform.currFlipState){this.updateCropObj();c={startX:n.destLeft,startY:n.destTop,width:n.destWidth,height:n.destHeight};o.notify("transform",{prop:"setCurrDestinationPoint",onPropertyChange:!1,value:{point:c}}),this.flipCrop()}else{this.adjustStraightenForShapes("initial",!1),o.notify("draw",{prop:"setTempZoomFactor",onPropertyChange:!1,value:{tempZoomFactor:o.transform.zoomFactor}});var d=this.calcRatio();if(i||!e){this.updateCropObj(),o.notify("draw",{prop:"resetPanPoints",onPropertyChange:!1}),o.notify("shape",{prop:"updImgRatioForActObj",onPropertyChange:!1});var c={startX:n.destLeft,startY:n.destTop,width:n.destWidth,height:n.destHeight};o.notify("transform",{prop:"setCurrDestinationPoint",onPropertyChange:!1,value:{point:c}}),o.currSelectionPoint=t.extend({},o.activeObj,{},!0),this.cropDestPoints={startX:n.destLeft,startY:n.destTop,width:n.destWidth,height:n.destHeight}}var u={width:0,height:0};o.notify("transform",{prop:"calcMaxDimension",onPropertyChange:!1,value:{width:a.width*d.width,height:a.height*d.height,obj:u,isImgShape:null}});var v=u;this.upperContext.clearRect(0,0,o.upperCanvas.width,o.upperCanvas.height),this.lowerContext.clearRect(0,0,o.lowerCanvas.width,o.lowerCanvas.height),o.img={srcLeft:a.startX*d.width-n.destLeft*d.width,srcTop:a.startY*d.height-n.destTop*d.height,srcWidth:a.width*d.width,srcHeight:a.height*d.height,destLeft:(o.lowerCanvas.clientWidth-v.width)/2,destTop:(o.lowerCanvas.clientHeight-v.height+1)/2,destWidth:v.width,destHeight:v.height};var g=this.lowerContext.filter;o.notify("draw",{prop:"drawImage",onPropertyChange:!1}),this.lowerContext.filter="none";var f=t.extend({},o.activeObj,{},!0);this.cropObjColl(),o.transform.straighten=0,o.activeObj=f,this.cropFreehandDrawColl(),o.shapeColl=[],o.notify("shape",{prop:"updateShapeColl",onPropertyChange:!1}),o.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"zoom",pen:"zoom",isPreventApply:null}}),o.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.lowerContext}}),o.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.upperContext}}),o.currSelectionPoint&&"crop-circle"===o.currSelectionPoint.shape?this.cropCircle(this.lowerContext):o.isCircleCrop=!1,this.lowerContext.filter=g,o.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),o.currObjType.isCustomCrop=!1,o.pan(!1),o.transform.defaultZoomFactor=0}},e.prototype.adjustStraightenForShapes=function(e,t){for(var o=this.parent,i={x:o.img.destLeft+o.img.destWidth/2,y:o.img.destTop+o.img.destHeight/2},r=0,a=o.objColl;r<a.length;r++){var n=a[r];if(-1!==["rectangle","ellipse","text","image","redact"].indexOf(n.shape)&&(t||0!==n.rotatedAngle)){var s=n.activePoint,l=s.startX,p=s.startY,h=s.width,d=s.height,c="initial"===e?n.rotatedAngle:-n.rotatedAngle,u=l+h/2-i.x,v=p+d/2-i.y,g=Math.cos(c),f=Math.sin(c),C=g*u-f*v+i.x-l-h/2,b=f*u+g*v+i.y-p-d/2;n.activePoint.startX+=C,n.activePoint.startY+=b,n.activePoint.endX+=C,n.activePoint.endY+=b}}},e.prototype.updateCropObj=function(){this.parent.afterCropActions=[];var e={currObj:{}};this.parent.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:e}});var o=e.currObj;o.straighten=this.parent.transform.straighten,this.parent.cropObj=t.extend({},o,{},!0)},e.prototype.rotateCrop=function(){var e=this.parent,o=this.getCurrFlipState(),i=e.activeObj.shape||"";e.notify("shape",{prop:"updImgRatioForActObj",onPropertyChange:!1}),e.currSelectionPoint=t.extend({},e.activeObj,{},!0),e.objColl.push(e.activeObj),e.activeObj=t.extend({},e.objColl[e.objColl.length-1],{},!0);var r=t.extend({},e.objColl[e.objColl.length-1],{},!0),a=t.extend({},e.currSelectionPoint,{},!0),n={bool:null};e.notify("transform",{prop:"getPreventSelect",onPropertyChange:!1,value:{obj:n}}),e.notify("transform",{prop:"setPreventSelect",onPropertyChange:!1,value:{bool:!0}});var s=t.extend([],e.rotateFlipColl,[],!0);this.panToSelRangle(!0),r=t.extend({},e.objColl[e.objColl.length-1],{},!0),this.upperContext.clearRect(0,0,e.upperCanvas.width,e.upperCanvas.height),e.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate",obj:r}}),e.objColl.pop(),e.notify("shape",{prop:"updImgRatioForActObj",onPropertyChange:!1}),e.objColl.push(e.activeObj);var l=e.transform.straighten;0!==l&&(e.transform.straighten=0,e.straightenBaseImageCanvas(),e.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"zoom",pen:"zoom",isPreventApply:null}}),e.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),e.notify("draw",{prop:"render-image",value:{isMouseWheel:!1}})),this.resetZoom();var p=t.extend([],e.afterCropActions,[],!0);this.revertTransform("initial",s),0!==l&&(e.transform.straighten="horizontal"===o||"vertical"===o?-l:l,e.straightenBaseImageCanvas(),e.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"zoom",pen:"zoom",isPreventApply:null}}),e.notify("draw",{prop:"render-image",value:{isMouseWheel:!1}}),e.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"zoom",pen:"zoom",isPreventApply:null}})),r=t.extend({},e.objColl[e.objColl.length-1],{},!0),this.upperContext.clearRect(0,0,e.upperCanvas.width,e.upperCanvas.height),e.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate",obj:r}}),e.objColl.pop(),e.transform.degree=0;var h={isIntersect:null};e.notify("draw",{prop:"updateImgCanvasPoints",onPropertyChange:!1}),e.notify("draw",{prop:"isLinesIntersect",onPropertyChange:!1,value:{obj:h}});for(var d=0;0!==l&&h.isIntersect&&50!=++d;)e.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:.025,zoomPoint:null},isResize:null}),e.notify("draw",{prop:"updateImgCanvasPoints",onPropertyChange:!1}),e.notify("draw",{prop:"isLinesIntersect",onPropertyChange:!1,value:{obj:h}});this.cropImg(!0),this.revertTransform("reverse",s),e.afterCropActions=p,e.currSelectionPoint=a,e.notify("transform",{prop:"setPreventSelect",onPropertyChange:!1,value:{bool:n.bool}}),e.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.lowerContext}}),e.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.upperContext}}),"crop-circle"===i&&this.cropCircle(this.lowerContext),this.upperContext.clearRect(0,0,e.upperCanvas.width,e.upperCanvas.height),e.notify("draw",{prop:"resetPanPoints",onPropertyChange:!1})},e.prototype.revertTransform=function(e,t){var o=this.parent,i={isRotate:!1};if("initial"===e)for(r=t.length-1;r>=0;r--)switch(n=t[r]){case 90:o.notify("transform",{prop:"rotate",value:{degree:-90,obj:i}});break;case-90:o.notify("transform",{prop:"rotate",value:{degree:90,obj:i}});break;default:o.notify("transform",{prop:"flipImage",value:{direction:o.toPascalCase(n.toString())}})}else{this.updateFlipState();for(var r=0,a=t.length;r<a;r++){var n=t[r];switch(n){case 90:o.notify("transform",{prop:"rotate",value:{degree:90,obj:i}});break;case-90:o.notify("transform",{prop:"rotate",value:{degree:-90,obj:i}});break;default:o.notify("transform",{prop:"flipImage",value:{direction:o.toPascalCase(n.toString())}})}}}},e.prototype.updateFlipState=function(){for(var e=this.parent,t=e.objColl,o=0,i=t.length;o<i;o++)t[o].shapeFlip="";for(var r=e.pointColl,o=0;o<e.freehandCounter;o++)r[o].shapeFlip=""},e.prototype.resetZoom=function(){var e=this.parent;if(e.transform.zoomFactor>0){var t=e.transform.zoomFactor,o=e.isUndoRedo;e.setProperties({zoomSettings:{zoomFactor:10*t}},!0),e.notify("transform",{prop:"setPreviousZoomValue",onPropertyChange:!1,value:{previousZoomValue:e.zoomSettings.zoomFactor}});for(var i=0;i<10*t;i++)e.isUndoRedo=!0,e.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:-.1,zoomPoint:null},isResize:null});e.isUndoRedo=o,e.notify("draw",{prop:"resetPanPoints",onPropertyChange:!1})}},e.prototype.flipCrop=function(){var e=this.parent;e.notify("transform",{prop:"setReverseFlip",onPropertyChange:!1,value:{isReverseFlip:!0}}),e.panPoint.totalPannedPoint.x+=this.tempFlipPanPoint.x,e.panPoint.totalPannedPoint.y+=this.tempFlipPanPoint.y;var o=e.transform.currFlipState,i={flipColl:null};e.notify("transform",{prop:"getFlipColl",onPropertyChange:!1,value:{obj:i}});var r=i.flipColl;if(e.notify("transform",{prop:"setFlipColl",onPropertyChange:!1,value:{flipColl:[]}}),e.notify("shape",{prop:"updImgRatioForActObj",onPropertyChange:!1}),e.objColl.push(e.activeObj),0===e.transform.degree){var a=-e.cropObj.totalPannedPoint.x,n=-e.cropObj.totalPannedPoint.y;e.img.destLeft+=a,e.img.destTop+=n,e.notify("transform",{prop:"drawPannImage",value:{point:{x:a,y:n}}}),e.activeObj=t.extend({},e.objColl[e.objColl.length-1],{},!0),this.upperContext.clearRect(0,0,e.upperCanvas.width,e.upperCanvas.height),e.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate",obj:e.activeObj}}),e.objColl.pop(),e.notify("shape",{prop:"updImgRatioForActObj",onPropertyChange:!1}),e.objColl.push(e.activeObj)}this.resetZoom(),e.currSelectionPoint=t.extend({},e.objColl[e.objColl.length-1],{},!0),this.lowerContext.clearRect(0,0,e.lowerCanvas.width,e.lowerCanvas.height),this.upperContext.clearRect(0,0,e.upperCanvas.width,e.upperCanvas.height);var s=this.lowerContext.filter;e.notify("draw",{prop:"drawImage",onPropertyChange:!1}),this.updateFlipState(),e.notify("shape",{prop:"redrawObj",onPropertyChange:!1,value:{degree:this.getCurrFlipState()}}),e.notify("freehand-draw",{prop:"flipFHDColl",onPropertyChange:!1,value:{value:this.getCurrFlipState()}}),e.activeObj=t.extend({},e.objColl[e.objColl.length-1],{},!0),e.objColl.pop(),this.upperContext.clearRect(0,0,e.upperCanvas.width,e.upperCanvas.height),e.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate"}}),this.cropImg(!0),e.notify("transform",{prop:"setReverseRotate",onPropertyChange:!1,value:{bool:!0}}),this.lowerContext.setTransform(1,0,0,1,0,0),e.notify("draw",{prop:"setDestPoints",onPropertyChange:!1}),e.notify("draw",{prop:"currTransState",onPropertyChange:!1,value:{type:"initial",isPreventDestination:null,context:null,isPreventCircleCrop:null}}),e.notify("draw",{prop:"drawImage",onPropertyChange:!1}),this.lowerContext.filter=s,e.notify("draw",{prop:"setRotateZoom",onPropertyChange:!1,value:{isRotateZoom:!1}}),e.notify("draw",{prop:"currTransState",onPropertyChange:!1,value:{type:"reverse",isPreventDestination:null,context:null,isPreventCircleCrop:null}}),e.transform.currFlipState=o,e.notify("transform",{prop:"setFlipColl",onPropertyChange:!1,value:{flipColl:r}}),this.lowerContext.filter="none",this.updateFlipState(),e.notify("shape",{prop:"redrawObj",onPropertyChange:!1,value:{degree:this.getCurrFlipState()}}),e.notify("freehand-draw",{prop:"flipFHDColl",onPropertyChange:!1,value:{value:this.getCurrFlipState()}}),e.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"zoom",pen:"zoom",isPreventApply:null}}),this.lowerContext.filter=s,(e.currSelectionPoint&&"crop-circle"===e.currSelectionPoint.shape||e.isCircleCrop)&&this.cropCircle(this.lowerContext),e.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),e.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.lowerContext}}),e.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.upperContext}}),this.upperContext.clearRect(0,0,e.upperCanvas.width,e.upperCanvas.height),e.notify("transform",{prop:"setReverseFlip",onPropertyChange:!1,value:{isReverseFlip:!1}}),e.notify("draw",{prop:"resetPanPoints",onPropertyChange:!1}),this.tempFlipPanPoint={x:0,y:0}},e.prototype.cropObjColl=function(){var e,t,o,i=this.parent;if(i.objColl.length>0)for(var r=0,a=i.objColl.length;r<a;r++){e=(o=i.objColl[r]).activePoint;var n=i.activeObj.activePoint,s=n.startX,l=n.startY,p=n.width,h=n.height;t=o.shape,o.imageRatio={startX:(e.startX-s)/p,startY:(e.startY-l)/h,endX:(e.endX-s)/p,endY:(e.endY-l)/h,width:p/e.width,height:h/e.height};var d=void 0,c=void 0;switch(t){case"text":c=0===(d=0===o.shapeDegree?i.transform.degree:i.transform.degree-o.shapeDegree)||180===Math.abs(d)?e.width:e.height,o.textSettings.fontRatio=c/o.textSettings.fontSize;break;case"line":case"arrow":this.cropPointCollection(r),"arrow"===t&&i.notify("shape",{prop:"updateArrowRatio",onPropertyChange:!1,value:{obj:o}});break;case"path":this.cropPointCollection(r)}}},e.prototype.cropPointCollection=function(e){var t,o,i,r,a=this.parent,n=a.objColl[e].shape,s=a.activeObj.activePoint,l=a.img,p=l.destLeft,h=l.destTop,d=l.destWidth,c=l.destHeight;"path"===n?(t=s.startX,o=s.startY,i=s.width,r=s.height):(t=p,o=h,i=d,r=c);for(var u=a.objColl[e].pointColl,v=0,g=u.length;v<g;v++)u[v].ratioX=(u[v].x-t)/i,u[v].ratioY=(u[v].y-o)/r},e.prototype.cropFreehandDrawColl=function(){for(var e=this.parent,o=e.activeObj.activePoint,i=o.startX,r=o.startY,a=o.width,n=o.height,s=0;s<e.freehandCounter;s++){e.points=t.extend([],e.pointColl[s].points,[]),e.notify("freehand-draw",{prop:"setPointCounter",onPropertyChange:!1,value:{value:0}});for(var l=e.points.length,p=0;p<l;p++)e.points[p].ratioX=(e.points[p].x-i)/a,e.points[p].ratioY=(e.points[p].y-r)/n}e.notify("freehand-draw",{prop:"updateCropPtsForSel",onPropertyChange:!1})},e.prototype.resetAnnotations=function(){var e=this.parent;e.objColl=[],e.pointColl=[],e.freehandCounter=0,e.notify("freehand-draw",{prop:"resetStraightenPoint"})},e.prototype.setCurrSelPoints=function(e){var o=this.parent;o.allowDownScale=!1;var i=this.cropDestPoints,r=this.lowerContext.filter,a=o.isCropTab;o.img={srcLeft:0,srcTop:0,srcWidth:o.baseImgCanvas.width,srcHeight:o.baseImgCanvas.height,destLeft:i.startX,destTop:i.startY,destWidth:i.width,destHeight:i.height};var n=o.img,s=o.currSelectionPoint;this.lowerContext.clearRect(0,0,o.lowerCanvas.width,o.lowerCanvas.height),e&&o.notify("draw",{prop:"setDestPoints",onPropertyChange:!1}),o.notify("draw",{prop:"currTransState",onPropertyChange:!1,value:{type:"initial",isPreventDestination:null,context:null,isPreventCircleCrop:null}}),0===this.croppedDegree&&0===o.transform.degree&&s&&"crop-circle"!==s.shape&&"crop-square"!==s.shape&&(n.destLeft=i.startX,n.destTop=i.startY,n.destWidth=i.width,n.destHeight=i.height),0===o.transform.degree&&(n.destLeft+=o.panPoint.totalPannedInternalPoint.x,n.destTop+=o.panPoint.totalPannedInternalPoint.y),o.notify("draw",{prop:"drawImage",onPropertyChange:!1}),this.lowerContext.filter=r,o.notify("draw",{prop:"currTransState",onPropertyChange:!1,value:{type:"reverse",isPreventDestination:null,context:null,isPreventCircleCrop:!0}});var l=t.extend([],o.objColl,null,!0),p=t.extend([],o.pointColl,null,!0),h={straightenPoint:null};if(o.notify("freehand-draw",{prop:"getStraightenPoint",onPropertyChange:!1,value:{obj:h}}),this.resetAnnotations(),t.isNullOrUndefined(o.activeObj.shape)&&o.cropObj.activeObj.shape&&(o.activeObj=t.extend({},o.cropObj.activeObj,null,!0)),this.panToSelRangle(),o.isCropTab=a,o.objColl=l,o.pointColl=p,o.freehandCounter=o.pointColl.length,h.straightenPoint.x&&h.straightenPoint.y&&o.notify("freehand-draw",{prop:"setStraightenPoint",onPropertyChange:!1,value:{x:h.straightenPoint.x,y:h.straightenPoint.y,ratioX:h.straightenPoint.ratioX,ratioY:h.straightenPoint.ratioY}}),o.cropObj.activeObj.shape){var d={startX:n.destLeft,startY:n.destTop,width:n.destWidth,height:n.destHeight};if(s&&s.activePoint){var c=s.activePoint,u=c.startX,v=c.startY,g=c.width,f=c.height;n.destLeft=u,n.destTop=v,n.destWidth=g,n.destHeight=f}o.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"zoom",pen:"zoom",isPreventApply:null}}),n.destLeft=d.startX,n.destTop=d.startY,n.destWidth=d.width,n.destHeight=d.height,o.notify("freehand-draw",{prop:"updateFHDColl",onPropertyChange:!1}),l=t.extend([],o.objColl,null,!0),p=t.extend([],o.pointColl,null,!0),o.notify("freehand-draw",{prop:"getStraightenPoint",onPropertyChange:!1,value:{obj:h}}),this.resetAnnotations();var C={selPointColl:null};o.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:C}});var b=C.selPointColl;o.notify("freehand-draw",{prop:"setSelPointColl",onPropertyChange:!1,value:{obj:{selPointColl:[]}}}),o.cropObj.filter=this.lowerContext.filter;var m=t.extend({},o.currSelectionPoint,null,!0);o.notify("draw",{prop:"setCurrentObj",onPropertyChange:!1,value:{obj:null}}),o.activeObj=t.extend({},m,null,!0);var y=t.extend({},o.activeObj,null,!0);if(o.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),o.currSelectionPoint=null,o.isCircleCrop=!1,0!==o.transform.degree&&(t.isNullOrUndefined(o.activeObj.shape)&&o.cropObj.activeObj.shape&&(o.activeObj=t.extend({},o.cropObj.activeObj,null,!0)),o.notify("transform",{prop:"drawPannedImage",value:{xDiff:0,yDiff:0}}),o.panPoint.currentPannedPoint={x:0,y:0}),o.objColl=l,o.pointColl=p,o.freehandCounter=o.pointColl.length,h.straightenPoint.x&&h.straightenPoint.y&&o.notify("freehand-draw",{prop:"setStraightenPoint",onPropertyChange:!1,value:{x:h.straightenPoint.x,y:h.straightenPoint.y,ratioX:h.straightenPoint.ratioX,ratioY:h.straightenPoint.ratioY}}),o.notify("freehand-draw",{prop:"setSelPointColl",onPropertyChange:!1,value:{obj:{selPointColl:b}}}),o.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"iterate",pen:"iterate",isPreventApply:null}}),this.adjustStraightenForShapes("reverse",!1),o.notify("freehand-draw",{prop:"updateFHDColl",onPropertyChange:!1,value:{isPreventApply:!0}}),o.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"zoom",pen:"zoom",isPreventApply:null}}),0===o.transform.degree?o.notify("transform",{prop:"drawPannImage",onPropertyChange:!1,value:{point:{x:0,y:0}}}):(t.isNullOrUndefined(o.activeObj.shape)&&o.cropObj.activeObj.shape&&(o.activeObj=t.extend({},o.cropObj.activeObj,null,!0)),o.notify("transform",{prop:"drawPannedImage",value:{xDiff:0,yDiff:0}}),o.panPoint.currentPannedPoint={x:0,y:0}),o.activeObj=y,o.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate"}}),o.notify("transform",{prop:"setTempPanMove",onPropertyChange:!1,value:{point:null}}),this.isInitCrop||0!==o.transform.degree||""===o.cropObj.currFlipState||0===o.cropObj.cropZoom)this.isInitCrop=!1;else{this.isInitCrop=!0;var P={activeObj:null};o.notify("draw",{prop:"getStraightenActObj",onPropertyChange:!1,value:{obj:P}}),o.notify("draw",{prop:"performCancel",value:{isContextualToolbar:null}}),o.notify("draw",{prop:"setStraightenActObj",onPropertyChange:!1,value:{activeObj:P.activeObj}}),o.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"croptransform",isApplyBtn:!1,isCropping:null,isZooming:null,cType:null}})}}else{this.adjustStraightenForShapes("reverse",!0),o.notify("freehand-draw",{prop:"updateFHDColl",onPropertyChange:!1,value:{isPreventApply:!0}});var j=this.lowerContext.filter;this.lowerContext.filter="none",o.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"iterate",pen:"iterate",isPreventApply:null}}),this.lowerContext.filter=j,o.currSelectionPoint=null}document.querySelector(".e-ie-straighten-value-span")&&(document.querySelector(".e-ie-straighten-value-span").innerHTML=o.transform.straighten.toString()+"&#176")},e.prototype.panToSelRangle=function(e){var t=this.parent,o=t.cropObj.totalPannedClientPoint,i=0!==t.transform.degree?e?-o.x:o.x:0,r=0!==t.transform.degree?e?-o.y:o.y:0;0!==t.transform.degree&&(t.panPoint.currentPannedPoint={x:i,y:r},t.notify("transform",{prop:"drawPannedImage",value:{xDiff:i,yDiff:r}}),t.panPoint.currentPannedPoint={x:0,y:0})},e.prototype.cropCircle=function(e,o,i){var r=this.parent,a=r.img,n=a.destLeft,s=a.destTop,l=a.destWidth,p=a.destHeight;i&&""!==r.transform.currFlipState&&r.notify("draw",{prop:"setTransform",onPropertyChange:!1,value:{context:e,value:r.transform.currFlipState,isReverse:null}});var h=e.filter;e.filter="none",e.globalCompositeOperation="destination-in",e.beginPath();var d=t.isNullOrUndefined(o)?n+l/2:e.canvas.width/2,c=t.isNullOrUndefined(o)?s+p/2:e.canvas.height/2,u=o?e.canvas.width/2:l/2;e.arc(d,c,u,0,2*Math.PI),e.closePath(),e.fill(),e.restore(),e.globalCompositeOperation="source-over",r.currObjType.isActiveObj=r.isCircleCrop=!0,e.filter=h,i&&""!==r.transform.currFlipState&&r.notify("draw",{prop:"setTransform",onPropertyChange:!1,value:{context:e,value:r.transform.currFlipState,isReverse:null}})},e.prototype.getCurrCropState=function(){var e=this.parent,t="",o={flipColl:null};return e.notify("transform",{prop:"getFlipColl",onPropertyChange:!1,value:{obj:o}}),t=this.getCurrFlipState(),-90!==e.transform.degree&&-270!==e.transform.degree||("horizontal"===t?t="vertical":"vertical"===t&&(t="horizontal")),""===t&&(t=o.flipColl.length>1?this.getCurrFlipState():e.transform.currFlipState),t},e.prototype.updateRotatePan=function(){var e=this.parent;if(!t.isNullOrUndefined(e.panPoint.currentPannedPoint)){var o="",i=e.transform.degree,r=e.panPoint.currentPannedPoint,a=r.x,n=r.y;o=e.rotateFlipColl.length>0&&"number"==typeof e.rotateFlipColl[0]&&i<0?this.getCurrCropState():this.getCurrFlipState(),i%90==0&&i%180!=0?90===i||-90===i&&("horizontal"===o||"vertical"===o)||-270===i&&(""===o||"verticalHorizontal"===o||"horizontalVertical"===o)?("horizontal"===o||""===o?e.img.destLeft+=n:e.img.destLeft-=n,""===o||"vertical"===o?e.img.destTop-=a:e.img.destTop+=a):270!==i&&(-270!==i||"horizontal"!==o&&"vertical"!==o)&&(-90!==i||""!==o&&"verticalHorizontal"!==o&&"horizontalVertical"!==o)||(""===o||"horizontal"===o?e.img.destLeft-=n:e.img.destLeft+=n,""===o||"vertical"===o?e.img.destTop+=a:e.img.destTop-=a):180!==i&&-180!==i||(""===o||"vertical"===o?e.img.destLeft-=a:e.img.destLeft+=a,""===o||"horizontal"===o?e.img.destTop-=n:e.img.destTop+=n)}},e.prototype.crop=function(e){var t=this.parent,o=t.activeObj.activePoint,i=o.startX,r=o.startY,a=o.endX,n=o.endY;if(!t.disabled&&t.isImageLoaded){var s={isCropToolbar:t.isCropToolbar};t.currObjType.isUndoAction&&!s.isCropToolbar&&t.notify("undo-redo",{prop:"refreshUrc",value:{bool:null}});var l={cancel:!1,startPoint:{x:i,y:r},endPoint:{x:a,y:n},preventScaling:!1};s.isCropToolbar||(t.trigger("cropping",l),t.editCompleteArgs=l),this.cropEvent(l,e,s)}},e.prototype.cropEvent=function(e,o,i){var r,a=this.parent;if(!e.cancel&&(r=a.activeObj.shape?a.activeObj.shape.split("-"):[],!a.disabled&&a.activeObj.horTopLine&&(a.currObjType.isCustomCrop||r.length>0&&"crop"===r[0]))){o.isCrop=!0;var n=t.extend({},a.cropObj,{},!0),s=t.extend({},this.prevCropCurrObj,{},!0);e.preventScaling?this.isPreventScaling=!0:this.isPreventScaling=!1,this.cropImg(),this.isPreventScaling&&(a.aspectWidth=a.img.destWidth,a.aspectHeight=a.img.destHeight),a.notify("freehand-draw",{prop:"resetStraightenPoint"}),a.isCropTab=!1,a.transform.zoomFactor=0,a.setProperties({zoomSettings:{zoomFactor:1}},!0),a.notify("transform",{prop:"setPreviousZoomValue",onPropertyChange:!1,value:{previousZoomValue:a.zoomSettings.zoomFactor}}),t.Browser.isDevice||this.updateUndoRedoColl(s,n,i),a.notify("transform",{prop:"setCropDimension",onPropertyChange:!1,value:{width:a.cropObj.destPoints.width,height:a.cropObj.destPoints.height}});var l=a.element.querySelector("#"+a.element.id+"_aspectratio"),p=a.element.querySelector("#"+a.element.id+"_nonaspectratio");a.notify("draw",{prop:"render-image",value:{isMouseWheel:!1}}),!i.isCropToolbar&&t.isNullOrUndefined(l)&&t.isNullOrUndefined(p)&&a.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"main",isApplyBtn:!1,isCropping:!1,isZooming:null,cType:null}}),this.resizeWrapper(),t.Browser.isDevice&&this.updateUndoRedoColl(s,n,i)}},e.prototype.updateUndoRedoColl=function(e,o,i){var r=this.parent,a={prevCurrSelectionPoint:r.prevCurrSelectionPoint};e.currSelectionPoint=t.extend({},a.prevCurrSelectionPoint,{},!0),r.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"crop",previousObj:e,previousObjColl:e.objColl,previousPointColl:e.pointColl,previousSelPointColl:e.selPointColl,previousCropObj:o,previousText:null,currentText:null,previousFilter:null,isCircleCrop:r.isCircleCrop}}),i.isCropToolbar||r.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"ok"}})},e.prototype.resizeWrapper=function(){var e=this.parent;if(t.Browser.isDevice){var o=e.element,i=o.querySelector("#"+o.id+"_contextualToolbarArea");i&&""===i.style.position&&!this.isTransformCrop&&(i.style.position="absolute",e.isStraightening=!1,e.update(),e.notify("filter",{prop:"setAdjustmentValue",value:{adjustmentValue:e.canvasFilter}}))}},e.prototype.calcRatio=function(e,t){var o=this.parent,i=o.transform.degree,r=o.img,a=r.destWidth,n=r.destHeight,s=t||o.baseImgCanvas,l=s.width,p=s.height,h=0===i||i%180==0?l/a:p/a,d=0===i||i%180==0?p/n:l/n;return e&&(e.width=h,e.height=d),{width:h,height:d}},e.prototype.getCurrFlipState=function(e){var t=this.parent,o={panRegion:""},i={collection:t.rotateFlipColl};t.notify("shape",{prop:"alignRotateFlipColl",onPropertyChange:!1,value:{collection:t.rotateFlipColl,isRotateFlipCollection:!0,obj:i}}),t.rotateFlipColl=i.collection;for(var r=0,a=t.rotateFlipColl.length;r<a;r++)t.notify("transform",{prop:"setCurrPanRegion",onPropertyChange:!1,value:{region:o.panRegion,type:t.rotateFlipColl[r],obj:o}});return e&&(e.panRegion=o.panRegion),o.panRegion},e}(),l=function(e,t,o,i){return new(o||(o=Promise))(function(r,a){function n(e){try{l(i.next(e))}catch(e){a(e)}}function s(e){try{l(i.throw(e))}catch(e){a(e)}}function l(e){e.done?r(e.value):new o(function(t){t(e.value)}).then(n,s)}l((i=i.apply(e,t||[])).next())})},p=function(e,t){function o(e){return function(t){return i([e,t])}}function i(o){if(r)throw new TypeError("Generator is already executing.");for(;l;)try{if(r=1,a&&(n=2&o[0]?a.return:o[0]?a.throw||((n=a.return)&&n.call(a),0):a.next)&&!(n=n.call(a,o[1])).done)return n;switch(a=0,n&&(o=[2&o[0],n.value]),o[0]){case 0:case 1:n=o;break;case 4:return l.label++,{value:o[1],done:!1};case 5:l.label++,a=o[1],o=[0];continue;case 7:o=l.ops.pop(),l.trys.pop();continue;default:if(n=l.trys,!(n=n.length>0&&n[n.length-1])&&(6===o[0]||2===o[0])){l=0;continue}if(3===o[0]&&(!n||o[1]>n[0]&&o[1]<n[3])){l.label=o[1];break}if(6===o[0]&&l.label<n[1]){l.label=n[1],n=o;break}if(n&&l.label<n[2]){l.label=n[2],l.ops.push(o);break}n[2]&&l.ops.pop(),l.trys.pop();continue}o=t.call(e,l)}catch(e){o=[6,e],a=0}finally{r=n=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}var r,a,n,s,l={label:0,sent:function(){if(1&n[0])throw n[1];return n[1]},trys:[],ops:[]};return s={next:o(0),throw:o(1),return:o(2)},"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s},h=function(){function e(e){this.isInitialLoading=!1,this.fileName="",this.isErrorImage=!1,this.isShapeTextInserted=!1,this.isRotateZoom=!1,this.tempStrokeSettings={strokeColor:"#fff",fillColor:"",strokeWidth:null,outlineColor:"",radius:null,outlineWidth:null},this.tempTextSettings={text:"Enter Text",fontFamily:"",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.isResizeSelect=!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.origDim={width:0,height:0},this.isImageApply=!1,this.imgCanvasPoints=[],this.isCropSelect=!1,this.isDownScale=!1,this.preventStraightening=!1,this.tempObjColl=[],this.tempPointColl={},this.imageBackgroundColor="",this.allowRedactStraighten=!0,this.parent=e,this.addEventListener()}return e.prototype.destroy=function(){this.parent.isDestroyed||this.removeEventListener()},e.prototype.addEventListener=function(){this.parent.on("draw",this.draw,this),this.parent.on("destroyed",this.destroy,this)},e.prototype.removeEventListener=function(){this.parent.off("draw",this.draw),this.parent.off("destroyed",this.destroy)},e.prototype.draw=function(e){switch(this.updatePrivateVariables(),e.prop){case"drawObject":this.drawObject(e.value.canvas,e.value.obj,e.value.isCropRatio,e.value.points,e.value.isPreventDrag,e.value.saveContext,e.value.isPreventSelection);break;case"updateActiveObject":this.updateActiveObject(e.value.actPoint,e.value.obj,e.value.isMouseMove,e.value.x,e.value.y);break;case"clearOuterCanvas":this.clearOuterCanvas(e.value.context);break;case"setDestPoints":this.setDestPoints();break;case"updateCurrTransState":this.updateCurrTransState(e.value.type,e.value.isPreventDestination,e.value.isRotatePan);break;case"currTransState":this.currTransState(e.value.type,e.value.isPreventDestination,e.value.context,e.value.isPreventCircleCrop);break;case"setTransform":this.setTransform(e.value.context,e.value.value,e.value.isReverse);break;case"render-image":this.renderImage(e.value.isMouseWheel,e.value.isPreventClearRect,e.value.isFrame,e.value.isStraighten);break;case"draw-image-to-canvas":this.drawImgToCanvas(e.value.dimension);break;case"update-canvas":this.updateCanvas();break;case"performCancel":this.performCancel(e.value.isContextualToolbar,e.value.isUndoRedo,e.value.isFinalCancel);break;case"updateFlipPan":this.updateFlipPan(e.value.tempSelectionObj);break;case"select":this.select(e.value.type,e.value.startX,e.value.startY,e.value.width,e.value.height);break;case"callUpdateCurrTransState":this.callUpdateCurrTransState();break;case"resetPanPoints":this.resetPanPoints();break;case"setClientTransDim":this.setClientTransDim(e.value.isPreventDimension);break;case"redrawImgWithObj":this.redrawImgWithObj();break;case"setCurrentObj":this.setCurrentObj(e.value.obj,e.value.isUndoRedo,e.value.isCircleCrop);break;case"performPointZoom":this.performPointZoom(e.value.x,e.value.y,e.value.type,e.value.isResize);break;case"open":this.open(e.value.data);break;case"isInitialLoading":this.isInitialLoading=e.value.isInitialLoading;break;case"isInitialLoaded":this.getInitialLoaded(e.value.object);break;case"fileSelect":this.fileSelect(e.value.inputElement,e.value.args);break;case"getFileName":e.value.obj.fileName=this.fileName,e.value.obj.fileType=this.fileType;break;case"getErrorImage":e.value.obj.isErrorImage=this.isErrorImage;break;case"getInitialZoomValue":e.value.obj.initialZoomValue=this.initZoomValue;break;case"setShapeTextInsert":this.isShapeTextInserted=e.value.bool;break;case"resetCurrentSelectionPoint":this.currSelPoint=null;break;case"setRotateZoom":this.isRotateZoom=e.value.isRotateZoom;break;case"setTempStrokeSettings":this.tempStrokeSettings=e.value.tempStrokeSettings;break;case"setTempTextSettings":this.tempTextSettings=e.value.tempTextSettings;break;case"setTempAdjustmentValue":this.tempAdjValue=e.value.tempAdjustmentValue;break;case"getTempAdjustmentValue":e.value.obj.value=this.tempAdjValue;break;case"setTempFilter":this.tempFilter=e.value.tempFilter;break;case"setTempUndoRedoStep":this.tempUndoRedoStep=e.value.tempUndoRedoStep;break;case"setTempFreehandCounter":this.tempFreehandCounter=e.value.tempFreehandCounter;break;case"setTempCurrentFreehandDrawIndex":this.tempCurrFhdIndex=e.value.tempCurrentFreehandDrawIndex;break;case"setTempZoomFactor":this.tempZoomFactor=e.value.tempZoomFactor;break;case"setCancelAction":this.isCancelAction=e.value.bool;break;case"getRotatedFlipCropSelection":e.value.bool.isSelected=this.rotatedFlipCropSel;break;case"getPrevActObj":e.value.obj.prevActObj=this.prevActObj;break;case"setPrevActObj":this.prevActObj=e.value.prevActObj;break;case"setZoomCropWidth":this.zoomCrop.width=e.value.width,this.zoomCrop.height=e.value.height;break;case"setImageEdited":this.isImageEdited=!0;break;case"reset":this.reset();break;case"setNewPath":this.isNewPath=e.value.bool;break;case"getNewPath":e.value.obj.isNewPath=this.isNewPath;break;case"getArrowDimension":e.value.obj.arrowDimension=t.extend({},this.arrowDimension,{},!0);break;case"setArrowDimension":this.arrowDimension=e.value.arrowDimension;break;case"moveToSelectionRange":this.moveToSelectionRange(e.value.type,e.value.activeObj);break;case"setResizeSelect":this.isResizeSelect=e.value.bool;break;case"applyFrame":this.applyFrame(e.value.ctx,e.value.frame,e.value.preventImg);break;case"drawImage":this.drawImage();break;case"downScaleImgCanvas":this.downScaleImgCanvas(e.value.ctx,e.value.isImgAnnotation,e.value.isHFlip,e.value.isVFlip);break;case"downScale":this.downScale(e.value.canvas,e.value.width,e.value.height);break;case"resetFrameZoom":this.resetFrameZoom(e.value.isOk);break;case"triggerFrameChange":e.value.obj.frameChangeEventArgs=this.triggerFrameChange(e.value.prevFrameSettings);break;case"setImageApply":this.isImageApply=e.value.bool;break;case"zoomToSel":this.zoomToSel(e.value.activeObj,e.value.isToolbar);break;case"getStraightenActObj":e.value.obj.activeObj=this.straightenActObj;break;case"setStraightenActObj":this.straightenActObj=e.value.activeObj;break;case"updateImgCanvasPoints":this.updateImgCanvasPoints();break;case"isLinesIntersect":e.value.obj.isIntersect=this.isLinesIntersect(e.value.obj);break;case"getImageCanvasPoints":e.value.obj.points=this.imgCanvasPoints;break;case"setDestForStraighten":this.setDestForStraighten();break;case"setTempDestForStraighten":this.tempStraightenDestPoints=t.extend({},this.straightenDestPoints,{},!0);break;case"getStraightenInitZoom":e.value.obj.zoomFactor=this.straightenInitZoom;break;case"setStraightenInitZoom":this.straightenInitZoom=e.value.zoomFactor;break;case"isPointsInsideImg":e.value.obj.bool="inside"!==this.checkPointPosition(e.value.x,e.value.y,this.imgCanvasPoints[0].x,this.imgCanvasPoints[0].y,this.imgCanvasPoints[1].x,this.imgCanvasPoints[1].y,this.imgCanvasPoints[2].x,this.imgCanvasPoints[2].y,this.imgCanvasPoints[3].x,this.imgCanvasPoints[3].y);break;case"setIsCropSelect":this.isCropSelect=e.value.bool;break;case"updateCropSelection":this.updateCropSelection();break;case"updateCropSelObj":this.updateCropSelObj();break;case"redrawDownScale":this.redrawDownScale();break;case"updateFinetune":this.updateFinetune();break;case"isSelOutsideImg":e.value.obj.bool=this.isSelOutsideImg();break;case"resetStraightenDestPoints":this.straightenDestPoints=null;break;case"checkPointPosition":e.value.obj.position=this.checkPointPosition(e.value.obj.x,e.value.obj.y,e.value.obj.x1,e.value.obj.y1,e.value.obj.x2,e.value.obj.y2,e.value.obj.x3,e.value.obj.y3,e.value.obj.x4,e.value.obj.y4);break;case"updateTempObjColl":this.tempObjColl=t.extend([],this.parent.objColl,[],!0);break;case"resetTempObjColl":this.tempObjColl=null;break;case"updateTempPointColl":this.tempPointColl=t.extend({},this.parent.pointColl,{},!0);break;case"resetTempPointColl":this.tempPointColl={};break;case"showDialogPopup":this.showDialogPopup();break;case"imageBackgroundColor":this.imageBackgroundColor=e.value.color;break;case"getImageBackgroundColor":e.value.obj.color=this.imageBackgroundColor;break;case"setTempStrokeWidth":this.tempStrokeWidth=e.value.strokeWidth}},e.prototype.getModuleName=function(){return"draw"},e.prototype.updatePrivateVariables=function(){var e=this.parent;e.lowerCanvas&&(this.lowerContext=e.lowerCanvas.getContext("2d")),e.upperCanvas&&(this.upperContext=e.upperCanvas.getContext("2d")),t.isNullOrUndefined(this.tempZoomFactor)&&(this.tempZoomFactor=e.transform.zoomFactor),""===this.tempTextSettings.fontFamily&&(this.tempTextSettings.fontFamily=e.fontFamily.default)},e.prototype.reset=function(){this.isInitialLoading=this.isErrorImage=this.isNewPath=this.isResizeSelect=!1,this.isShapeTextInserted=!1,this.isImageApply=!1,this.initZoomValue=null,this.tempFilter="",this.origDim={width:0,height:0},this.currSelPoint=null,this.isRotateZoom=!1,this.tempAdjValue="",this.tempStrokeSettings={strokeColor:"#fff",fillColor:"",strokeWidth:null,radius:null,outlineColor:"",outlineWidth:null},this.tempTextSettings={text:"Enter Text",fontFamily:this.parent.fontFamily.default,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.tempStraightenDestPoints=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}},this.straightenActObj=null,this.imgCanvasPoints=[],this.straightenInitZoom=null,this.allowRedactStraighten=!0,this.tempObjColl=[],this.tempPointColl={},this.imageBackgroundColor="",this.tempStrokeWidth=null,this.straightenDestPoints=null,this.isCropSelect=this.isDownScale=this.preventStraightening=!1},e.prototype.redrawDownScale=function(){var e=this.parent;if(e.transform.zoomFactor&&e.transform.zoomFactor<0){var o=t.extend({},e.activeObj,{},!0);e.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),this.isDownScale=!0,this.renderImage(),this.isDownScale=!1,o.shape&&this.drawObject("duplicate",o)}},e.prototype.updateFinetune=function(){var e=this.parent;if(e.transform.zoomFactor&&e.transform.zoomFactor<0){var t=this.lowerContext.filter;this.lowerContext.filter="none",e.notify("draw",{prop:"redrawDownScale"});var o=e.inMemoryCanvas.getContext("2d"),i=this.lowerContext,r=i.getImageData(0,0,i.canvas.width,i.canvas.height);e.inMemoryCanvas.width=r.width,e.inMemoryCanvas.height=r.height,o.putImageData(r,0,0),this.lowerContext.filter=t,e.notify("draw",{prop:"redrawDownScale"})}},e.prototype.drawImage=function(){this.applyFrame(this.lowerContext,this.parent.frameObj.type)},e.prototype.drawObject=function(e,o,i,r,a,n,s){var l=this.parent,p=l.activeObj,h=l.activeObj.activePoint;this.upperContext.clearRect(0,0,l.upperCanvas.width,l.upperCanvas.height);var d;if(e=e.toLowerCase(),"original"===e?d=this.lowerContext:"duplicate"===e?d=this.upperContext:n&&(d=n),!a&&p.shape&&this.setDragLimit(),l.currObjType.shape&&"crop"===l.currObjType.shape.split("-")[0].toLowerCase()&&i&&this.drawCropRatio(),p=l.activeObj,h=l.activeObj.activePoint,t.isNullOrUndefined(p.strokeSettings)){var c={strokeSettings:{}};l.notify("shape",{prop:"getStrokeSettings",onPropertyChange:!1,value:{obj:c}}),p.strokeSettings=c.strokeSettings}if(t.isNullOrUndefined(p.strokeSettings.strokeWidth)&&(p.strokeSettings.strokeWidth=2),o&&(l.activeObj=t.extend({},o,{},!0)),r&&r.startX&&r.startY&&r.endX&&r.endY&&r.width&&r.height&&(h.startX=r.startX,h.startY=r.startY,h.endX=r.endX,h.endY=r.endY,h.width=r.width,h.height=r.height),this.updateActiveObject(),p=l.activeObj,h=l.activeObj.activePoint,!t.isNullOrUndefined(h.startX)||!t.isNullOrUndefined(h.startY)){if(l.currObjType.isText){var u={keyHistory:""};l.notify("shape",{prop:"getKeyHistory",onPropertyChange:!1,value:{obj:u}}),p.keyHistory=u.keyHistory}var v=!1;if("original"!==e){p.shape&&"crop"===p.shape.split("-")[0]&&(v=!0),v&&(r&&r.startX&&r.startY&&r.endX&&r.endY&&r.width&&r.height?(h.startX=r.startX,h.startY=r.startY,h.endX=r.endX,h.endY=r.endY,h.width=r.width,h.height=r.height):h=p.activePoint,this.upperContext.fillStyle="rgb(0, 0, 0, 0.25)",this.upperContext.fillRect(0,0,l.lowerCanvas.width,l.lowerCanvas.height),this.upperContext.clearRect(h.startX,h.startY,h.width,h.height)),!t.isNullOrUndefined(s)||d!==this.lowerContext&&d!==this.upperContext||(this.rotateContext("initial",d),this.drawOuterSelection(d),this.rotateContext("reverse",d))}l.currObjType.isActiveObj=!0;var g={keyHistory:""};l.notify("shape",{prop:"getKeyHistory",onPropertyChange:!1,value:{obj:g}}),o?this.drawShapeObj(e,o.shape,n,s):""!==g.keyHistory&&l.currObjType.isText?this.drawShapeObj(e,"text",n,s):p.shape?this.drawShapeObj(e,p.shape,n,s):this.drawShapeObj(e,void 0,n,s),"duplicate"===e&&v&&"crop-circle"!==p.shape&&"none"!==l.frameObj.type&&(this.applyFrame(this.upperContext,l.frameObj.type),this.drawCornerCircles(this.upperContext))}},e.prototype.rotateContext=function(e,t){var o=this.parent,i=o.activeObj,r=i.shape,a=i.rotatedAngle,n=o.img,s=n.destLeft,l=n.destTop,p=n.destWidth,h=n.destHeight,d=o.activeObj.activePoint,c=d.startX,u=d.startY,v=d.width,g=d.height;if("line"!==r&&"arrow"!==r){var f,C,b="initial"===e?a:-a;0!==o.transform.straighten||o.isCropTab?(f=s+p/2,C=l+h/2):(f=c+v/2,C=u+g/2),t.translate(f,C),t.rotate(b),t.translate(-f,-C)}},e.prototype.setDragLimit=function(){var e=this.parent,t=e.activeObj.activePoint,o=e.activeObj,i=o.shape,r=o.rotatedAngle;if(t&&"image"!==i&&"line"!==i&&0===r&&e.activeObj.preventShapeDragOut){var a=e.img,n=a.destLeft,s=a.destTop,l=a.destWidth,p=a.destHeight;t.startX<n?(t.startX=n,t.endX=Math.min(t.startX+t.width,n+l)):t.endX>n+l&&(t.endX=n+l,t.startX=Math.max(t.endX-t.width,n)),t.startY<s?t.startY=s:t.endY>s+p&&(t.endY=s+p,t.startY=Math.max(t.endY-t.height,s)),e.activeObj=this.updateWidthHeight(e.activeObj)}},e.prototype.drawCropRatio=function(){var e,o,i,r,a=this.parent,n=a.activeObj.activePoint,s=a.img,l=s.destLeft,p=s.destTop,h=s.destWidth,d=s.destHeight;if(a.transform.zoomFactor>0&&this.currSelPoint){var c=t.extend({},a.activeObj,{},!0);this.drawCustomSelection("crop-custom",null,null,null,null),0!==a.transform.straighten&&(n=a.activeObj.activePoint),a.transform.degree%90==0&&a.transform.degree%180!=0?r=i=n.width<n.height?n.width:n.height:(i=n.width,r=n.height),a.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),a.activeObj=c,a.currObjType.shape=c.shape,this.upperContext.clearRect(0,0,a.upperCanvas.width,a.upperCanvas.height),a.currObjType.isCustomCrop=!1}else i=h,r=d,l<0&&(i+=l),p<0&&(r+=p),l+h>a.lowerCanvas.width&&(i-=l+h-a.lowerCanvas.width),p+d>a.lowerCanvas.height&&(r-=p+d-a.lowerCanvas.height);switch(a.currObjType.shape.toLowerCase()){case"crop-square":case"crop-circle":a.notify("selection",{prop:"setDragDirection",onPropertyChange:!1,value:{width:i,height:r}}),n=a.activeObj.activePoint,a.lowerCanvas.width<n.endX-n.startX&&(n.startX=7.5,n.endX=a.lowerCanvas.width-7.5),a.lowerCanvas.height<n.endY-n.startY&&(n.startY=7.5,n.endY=a.lowerCanvas.height-7.5),i===h&&r===d&&(n.startX+=l,n.startY+=p,n.endX+=l,n.endY+=p),a.lowerCanvas.width>a.lowerCanvas.height?(n.height=n.endY-n.startY,n.width=n.height,n.endX=n.startX+n.width):(n.width=n.endX-n.startX,n.height=n.width,n.endY=n.startY+n.height);break;case"crop-3:2":e=3,o=2;break;case"crop-4:3":e=4,o=3;break;case"crop-5:4":e=5,o=4;break;case"crop-7:5":e=7,o=5;break;case"crop-16:9":e=16,o=9;break;case"crop-2:3":e=2,o=3;break;case"crop-3:4":e=3,o=4;break;case"crop-4:5":e=4,o=5;break;case"crop-5:7":e=5,o=7;break;case"crop-9:16":e=9,o=16;break;default:e=parseInt(a.currObjType.shape.toLowerCase().split("crop-")[1].split(":")[0]),o=parseInt(a.currObjType.shape.toLowerCase().split("crop-")[1].split(":")[1])}if(void 0!==e&&void 0!==o&&(a.notify("selection",{prop:"calcShapeRatio",onPropertyChange:!1,value:{x:e,y:o,imgWidth:i,imgHeight:r}}),i===h&&r===d&&this.updatePoints(),n=a.activeObj.activePoint),n.startX<l){g=l-n.startX+7.5;n.startX+=g,n.endX+=g}if(n.startY<p){g=p-n.startY+7.5;n.startY+=g,n.endY+=g}a.activeObj=this.updateWidthHeight(a.activeObj),this.adjToCenter(),this.enlargeToImg(),0!==a.transform.straighten&&(this.adjToStraighten(),this.updateActiveObject(a.activeObj.activePoint,a.activeObj));var u={isIntersect:null,arr:null},v=0;if(n=a.activeObj.activePoint,0!==a.transform.straighten)for(;this.isLinesIntersect(u)&&v<100;){v++;var g=1*n.width/100;n.startX+=g,n.endX-=g,g=1*n.height/100,n.startY+=g,n.endY-=g,n.width=n.endX-n.startX,n.height=n.endY-n.startY,this.updateActiveObject(n,a.activeObj)}this.straightenInitZoom=a.transform.zoomFactor,this.straightenActObj=t.extend({},a.activeObj,{},!0),a.notify("draw",{prop:"resetStraightenDestPoints"}),a.notify("draw",{prop:"setDestForStraighten"})},e.prototype.adjToCenter=function(){var e=this.parent,t=e.activeObj.activePoint,o=e.img,i=o.destLeft,r=o.destTop,a=o.destWidth,n=o.destHeight,s=e.lowerCanvas.width/2-(t.endX-t.width/2),l=e.lowerCanvas.height/2-(t.endY-t.height/2);if(t.startX+=s,t.endX+=s,t.startY+=l,t.endY+=l,t.startX<(i>=7.5?i:7.5)){p=(i>=7.5?i:0)-t.startX;t.startX+=p,t.endX+=p}else if(t.endX>i+a){p=t.endX-(i+a);t.startX-=p,t.endX-=p}if(t.startY<(r>=7.5?r:7.5)){p=(r>=7.5?r:0)-t.startY;t.startY+=p,t.endY+=p}else if(t.endY>r+n){var p=t.endY-(r+n);t.startY-=p,t.endY-=p}},e.prototype.enlargeToImg=function(){var e=this.parent;if(0!==e.transform.straighten&&e.transform.degree%90==0&&e.transform.degree%180!=0)for(var o=e.activeObj.activePoint,i=t.extend({},o,{},!0),r=0;;){r++;var a=5*o.width/100;o.startX-=a,o.endX+=a,a=5*o.height/100,o.startY-=a,o.endY+=a,o.width=o.endX-o.startX,o.height=o.endY-o.startY,this.updateActiveObject(o,e.activeObj);var n={isIntersect:null,arr:null};if(this.updateImgCanvasPoints(),this.isLinesIntersect(n),n.arr[0]||n.arr[1]||n.arr[2]||n.arr[3]||o.startX<7.5||o.startY<7.5||100===r){a=1*(o=t.extend({},i,{},!0)).width/100,o.startX+=a,o.endX-=a,a=1*o.height/100,o.startY+=a,o.endY-=a,o.width=o.endX-o.startX,o.height=o.endY-o.startY,this.updateActiveObject(o,e.activeObj);break}i=t.extend({},o,{},!0)}},e.prototype.updateActiveObject=function(e,o,i,r,a){var n=this.parent;e=e||t.extend({},n.activeObj.activePoint,{},!0),o=o||t.extend({},n.activeObj,{},!0),e.width=e.endX-e.startX,e.height=e.endY-e.startY;var s=e.startX,l=e.startY,p=e.endX,h=e.endY,d=e.width,c=e.height;r=r||0,a=a||0;var u=d/2,v=c/2;o.horTopLine={startX:s+r,startY:l-a,endX:p+r,endY:h+a},o.horBottomLine={startX:s-r,startY:h-a,endX:p-r,endY:h+a},o.verLeftLine={startX:s+r,startY:l-a,endX:s-a,endY:h-a},o.verRightLine={startX:p+r,startY:l+a,endX:p-r,endY:h+a},o.topLeftCircle={startX:s,startY:l,radius:o.horTopLine.endX?7.5:0},o.topCenterCircle={startX:s+u,startY:l,radius:o.horTopLine.endX?7.5:0},o.topRightCircle={startX:p,startY:l,radius:o.horTopLine.endX?7.5:0},o.centerLeftCircle={startX:s,startY:l+v,radius:o.horTopLine.endX?7.5:0},o.centerRightCircle={startX:p,startY:l+v,radius:o.horTopLine.endX?7.5:0},o.bottomLeftCircle={startX:s,startY:h,radius:o.horTopLine.endX?7.5:0},o.bottomCenterCircle={startX:s+u,startY:h,radius:o.horTopLine.endX?7.5:0},o.bottomRightCircle={startX:p,startY:h,radius:o.horTopLine.endX?7.5:0},0===o.rotatedAngle&&(o.rotationCirclePoint={x:o.bottomCenterCircle.startX,y:o.bottomCenterCircle.startY+25},o.rotationCirclePoint.ratioX=(o.rotationCirclePoint.x-n.img.destLeft)/n.img.destWidth,o.rotationCirclePoint.ratioY=(o.rotationCirclePoint.y-n.img.destTop)/n.img.destHeight),o.activePoint=e,t.isNullOrUndefined(i)&&(n.activeObj=t.extend({},o,{},!0))},e.prototype.drawOuterSelection=function(e,o){var i,r=this.parent,a=r.activeObj.activePoint,n=r.activeObj;e.lineWidth=.5;var s=t.extend({},n,{},!0);n.shape&&(i=n.shape.split("-")),(i&&"crop"===i[0]||void 0===n.shape)&&!o&&(this.upperContext.fillStyle="rgb(0, 0, 0, 0.25)",this.upperContext.fillRect(0,0,r.lowerCanvas.width,r.lowerCanvas.height),this.upperContext.clearRect(a.startX,a.startY,a.width,a.height)),e.strokeStyle=r.themeColl[r.theme].primaryColor,e.fillStyle=r.themeColl[r.theme].secondaryColor;var l;if((l=0===s.shapeDegree?r.transform.degree:r.transform.degree-s.shapeDegree)<0&&(l=360+l),"arrow"===n.shape||"line"===n.shape)e.beginPath(),e.moveTo(a.startX,a.startY),e.lineTo(a.endX,a.endY),e.stroke();else if("path"===n.shape){e.beginPath();var p=t.extend({},r.activeObj,{},!0);if(p.pointColl[0]&&(e.moveTo(p.pointColl[0].x,p.pointColl[0].y),p.pointColl.length>1))for(var h=1,d=p.pointColl.length;h<d;h++)a.endX=p.pointColl[h].x,a.endY=p.pointColl[h].y,e.lineTo(a.endX,a.endY);var c={shape:null};r.notify("selection",{prop:"getCurrentDrawingShape",value:{obj:c}}),"path"===c.shape&&(r.activeObj=n=p),e.lineTo(a.endX,a.endY),e.stroke()}else this.drawCornerCircles(e);if(r.selectionSettings.showCircle&&(void 0===i||"crop"!==i[0])){var u=e.strokeStyle,v=e.fillStyle;e.strokeStyle=r.selectionSettings.strokeColor,e.fillStyle=r.selectionSettings.fillColor,"text"===n.shape?(e.lineWidth*=2,e.beginPath(),this.drawRotationArcLine(e),e.lineTo(n.rotationCirclePoint.x,n.rotationCirclePoint.y),e.stroke(),e.fill(),e.closePath(),e.beginPath(),e.moveTo(n.rotationCirclePoint.x,n.rotationCirclePoint.y),e.arc(n.rotationCirclePoint.x,n.rotationCirclePoint.y,n.bottomCenterCircle.radius,0,2*Math.PI),e.stroke(),e.fill(),e.closePath(),e.lineWidth/=2):"redact"!==r.activeObj.shape&&this.drawCenterCircles(e),e.strokeStyle=u,e.fillStyle=v}s.rotationCircleLine=n.rotationCircleLine,r.activeObj=t.extend({},s,{},!0)},e.prototype.drawArrowHead=function(e,t){switch(t?this.parent.activeObj.start:this.parent.activeObj.end){case"arrowSolid":t?this.arrowSolid(e,!0):this.arrowSolid(e,!1);break;case"arrow":t?this.arrow(e,!0):this.arrow(e,!1);break;case"circleSolid":t?this.arrowCircleSolid(e,!0):this.arrowCircleSolid(e,!1);break;case"circle":t?this.arrowCircle(e,!0):this.arrowCircle(e,!1);break;case"bar":t?this.arrowBar(e,!0):this.arrowBar(e,!1);break;case"square":case"squareSolid":t?this.arrowSquareStart(e):this.arrowSquareEnd(e)}},e.prototype.drawShapeObj=function(e,o,i,r){var a=this.parent,n=a.activeObj.activePoint,s=a.activeObj,l=s.strokeSettings,p=l.strokeColor,h=l.fillColor,d=l.strokeWidth,c=void 0!==o?o:a.currObjType.shape;a.currObjType.shape=c;var u;"original"===e.toLowerCase()?u=this.lowerContext:"duplicate"===e.toLowerCase()?u=this.upperContext:i&&(u=i);var v=a.currObjType.shape.toLowerCase();-1!==["rectangle","ellipse","line","arrow","path","image","redact"].indexOf(v)&&(s.shape=a.currObjType.shape),u.strokeStyle=p,u.fillStyle="text"===o||"freehanddraw"===o?p:h;var g=n.width/3,f=n.height/3,C=n.endX-n.startX,b=n.endY-n.startY;this.rotateContext("initial",u);var m,y,P=u.fillStyle;switch(a.currObjType.shape.toLowerCase()){case"rectangle":this.drawSquareLines(u),t.isNullOrUndefined(r)&&u===this.upperContext&&this.drawOuterSelection(u);break;case"redact":this.drawRedact(u,s),t.isNullOrUndefined(r)&&u===this.upperContext&&this.drawOuterSelection(u),a.currObjType.isRedact=!0;break;case"ellipse":C=Math.abs(C),b=Math.abs(b),u.beginPath(),u.ellipse(n.startX+C/2,n.startY+b/2,C/2,b/2,0,0,2*Math.PI,!1),""!==h&&(u.fillStyle=h,u.fill()),u.ellipse(n.startX+C/2,n.startY+b/2,Math.abs(C/2-d),Math.abs(b/2-d),0,0,2*Math.PI,!1),u.fillStyle=p,u.fill("evenodd"),u.closePath(),t.isNullOrUndefined(r)&&u===this.upperContext&&this.drawOuterSelection(u);break;case"crop-circle":this.shapeCircle(u,C,b);break;case"line":this.shapeLine(u,n.startX,n.startY,n.endX,n.endY),t.isNullOrUndefined(r)&&u===this.upperContext&&this.drawOuterSelection(u);break;case"arrow":(m=0===s.shapeDegree?a.transform.degree:a.transform.degree-s.shapeDegree)<0&&(m=360+m),u.fillStyle=u.strokeStyle,t.isNullOrUndefined(s.triangleDirection)&&(s.triangleDirection="right"),t.isNullOrUndefined(s.start)&&(s.start="none"),t.isNullOrUndefined(s.end)&&(s.end="arrowSolid"),this.drawArrowHead(u,!0),this.drawArrowHead(u,!1),"none"===s.end&&this.shapeLine(u,n.startX,n.startY,n.endX,n.endY),u.fillStyle=P,t.isNullOrUndefined(r)&&u===this.upperContext&&this.drawOuterSelection(u);break;case"path":if((y=t.extend({},a.activeObj,{},!0)).pointColl.length>1){var j={shape:null};if(a.notify("selection",{prop:"getCurrentDrawingShape",value:{obj:j}}),"path"===j.shape&&a.isShapeDrawing)for(var x={x:0,y:0},w=0,O=y.pointColl.length;w<O;w++)t.isNullOrUndefined(y.pointColl[w+1])?(x.x=y.activePoint.endX,x.y=y.activePoint.endY):(x.x=y.pointColl[w+1].x,x.y=y.pointColl[w+1].y),n.startX=y.pointColl[w].x,n.startY=y.pointColl[w].y,n.endX=x.x,n.endY=x.y,a.activeObj=this.updateWidthHeight(a.activeObj),this.shapeLine(u,n.startX,n.startY,n.endX,n.endY),t.Browser.isDevice&&(y.activePoint.endX=x.x,y.activePoint.endY=x.y);else for(var w=1,O=y.pointColl.length;w<O;w++)n.startX=y.pointColl[w-1].x,n.startY=y.pointColl[w-1].y,n.endX=y.pointColl[w].x,n.endY=y.pointColl[w].y,a.activeObj=this.updateWidthHeight(a.activeObj),this.shapeLine(u,n.startX,n.startY,n.endX,n.endY);a.activeObj=s=y}else this.shapeLine(u,n.startX,n.startY,n.endX,n.endY);u===this.upperContext&&this.drawOuterSelection(u);break;case"text":this.shapeText(u);break;case"image":this.shapeImage(u),t.isNullOrUndefined(r)&&u===this.upperContext&&this.drawOuterSelection(u);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":u===this.lowerContext&&(u=this.upperContext),this.drawSelection(g,f),a.currObjType.shape="";break;default:this.drawSelection(g,f)}this.rotateContext("reverse",u)},e.prototype.updatePoints=function(){var e=this.parent,t=e.activeObj.activePoint,o=e.img,i=o.destLeft,r=o.destTop;t.startX+=i,t.startY+=r,t.endX+=i,t.endY+=r,e.activeObj=this.updateWidthHeight(e.activeObj)},e.prototype.updateWidthHeight=function(e){var t=e.activePoint,o=t.startX,i=t.startY,r=t.endX,a=t.endY;return e.activePoint.width=r-o,e.activePoint.height=a-i,e},e.prototype.drawCornerCircles=function(e){var t=this.parent,o=t.activeObj;if(e.beginPath(),e.rect(o.activePoint.startX,o.activePoint.startY,o.activePoint.width,o.activePoint.height),e.stroke(),e.closePath(),t.selectionSettings.showCircle){var i=e.strokeStyle,r=e.fillStyle;e.strokeStyle=t.selectionSettings.strokeColor,e.fillStyle=t.selectionSettings.fillColor,e.lineWidth*=2,e.beginPath(),e.moveTo(o.topLeftCircle.startX,o.topLeftCircle.startY),e.arc(o.topLeftCircle.startX,o.topLeftCircle.startY,o.topLeftCircle.radius,0,2*Math.PI),e.moveTo(o.topRightCircle.startX,o.topRightCircle.startY),e.arc(o.topRightCircle.startX,o.topRightCircle.startY,o.topRightCircle.radius,0,2*Math.PI),e.moveTo(o.bottomLeftCircle.startX,o.bottomLeftCircle.startY),e.arc(o.bottomLeftCircle.startX,o.bottomLeftCircle.startY,o.bottomLeftCircle.radius,0,2*Math.PI),e.moveTo(o.bottomRightCircle.startX,o.bottomRightCircle.startY),e.arc(o.bottomRightCircle.startX,o.bottomRightCircle.startY,o.bottomRightCircle.radius,0,2*Math.PI),e.stroke(),e.fill(),e.closePath(),e.lineWidth/=2,e.strokeStyle=i,e.fillStyle=r}},e.prototype.drawCenterCircles=function(e){var o=this.parent,i=o.activeObj.activePoint,r=o.activeObj;if(e.lineWidth*=2,e.beginPath(),"arrow"===r.shape||"line"===r.shape)e.moveTo(i.startX,i.startY),e.arc(i.startX,i.startY,r.topCenterCircle.radius,0,2*Math.PI),e.moveTo(i.endX,i.endY),e.arc(i.endX,i.endY,r.bottomCenterCircle.radius,0,2*Math.PI);else if("path"===r.shape){var a=t.extend({},o.activeObj,{},!0);if(a.pointColl.length>1)for(var n=1,s=a.pointColl.length;n<s;n++)i.startX=a.pointColl[n-1].x,i.startY=a.pointColl[n-1].y,i.endX=a.pointColl[n].x,i.endY=a.pointColl[n].y,e.moveTo(i.startX,i.startY),e.arc(i.startX,i.startY,r.topCenterCircle.radius,0,2*Math.PI),e.moveTo(i.endX,i.endY),e.arc(i.endX,i.endY,r.bottomCenterCircle.radius,0,2*Math.PI);var l={shape:null};o.notify("selection",{prop:"getCurrentDrawingShape",value:{obj:l}}),"path"===l.shape&&(o.activeObj=r=a),e.moveTo(i.startX,i.startY),e.arc(i.startX,i.startY,r.topCenterCircle.radius,0,2*Math.PI),e.moveTo(i.endX,i.endY),e.arc(i.endX,i.endY,r.bottomCenterCircle.radius,0,2*Math.PI)}else this.drawRotationArcLine(e),e.lineTo(r.rotationCirclePoint.x,r.rotationCirclePoint.y);e.stroke(),e.fill(),e.closePath(),"arrow"!==r.shape&&"line"!==r.shape&&"path"!==r.shape&&(e.beginPath(),e.moveTo(r.rotationCirclePoint.x,r.rotationCirclePoint.y),e.arc(r.rotationCirclePoint.x,r.rotationCirclePoint.y,r.bottomCenterCircle.radius,0,2*Math.PI),e.stroke(),e.fill(),e.closePath()),e.lineWidth/=2},e.prototype.drawRotationArcLine=function(e){var o=this.parent,i=o.activeObj;t.isNullOrUndefined(i.rotationCircleLine)&&(i.rotationCircleLine=22.5);var r,a=!1,n=!1;if((r=0===i.shapeDegree?o.transform.degree:o.transform.degree-i.shapeDegree)<0&&(r=360+r),i.flipObjColl)for(var s=0,l=i.flipObjColl.length;s<l;s++){var p=i.flipObjColl[s].toLowerCase();"horizontal"===p?a=!0:"vertical"===p&&(n=!0)}switch(r){case 0:case 360:n?(i.rotationCirclePoint={x:i.topCenterCircle.startX,y:i.topCenterCircle.startY-i.rotationCircleLine},e.moveTo(i.rotationCirclePoint.x,i.rotationCirclePoint.y+i.rotationCircleLine)):(i.rotationCirclePoint={x:i.bottomCenterCircle.startX,y:i.bottomCenterCircle.startY+i.rotationCircleLine},e.moveTo(i.rotationCirclePoint.x,i.rotationCirclePoint.y-i.rotationCircleLine));break;case 90:case-270:a?(i.rotationCirclePoint={x:i.centerRightCircle.startX+i.rotationCircleLine,y:i.centerLeftCircle.startY},e.moveTo(i.rotationCirclePoint.x-i.rotationCircleLine,i.rotationCirclePoint.y)):(i.rotationCirclePoint={x:i.centerLeftCircle.startX-i.rotationCircleLine,y:i.centerLeftCircle.startY},e.moveTo(i.rotationCirclePoint.x+i.rotationCircleLine,i.rotationCirclePoint.y));break;case 180:case-180:n?(i.rotationCirclePoint={x:i.bottomCenterCircle.startX,y:i.bottomCenterCircle.startY+i.rotationCircleLine},e.moveTo(i.rotationCirclePoint.x,i.rotationCirclePoint.y-i.rotationCircleLine)):(i.rotationCirclePoint={x:i.topCenterCircle.startX,y:i.topCenterCircle.startY-i.rotationCircleLine},e.moveTo(i.rotationCirclePoint.x,i.rotationCirclePoint.y+i.rotationCircleLine));break;case 270:case-90:a?(i.rotationCirclePoint={x:i.centerLeftCircle.startX-i.rotationCircleLine,y:i.centerLeftCircle.startY},e.moveTo(i.rotationCirclePoint.x+i.rotationCircleLine,i.rotationCirclePoint.y)):(i.rotationCirclePoint={x:i.centerRightCircle.startX+i.rotationCircleLine,y:i.centerLeftCircle.startY},e.moveTo(i.rotationCirclePoint.x-i.rotationCircleLine,i.rotationCirclePoint.y))}},e.prototype.drawSquareLines=function(e){var t,o=this.parent,i=o.activeObj,r=i.activePoint,a=r.startX,n=r.startY,s=r.width,l=r.height,p=i.strokeSettings,h=p.fillColor,d=p.strokeColor,c=p.strokeWidth,u=p.radius;i.shape&&(t=i.shape.split("-")),"crop"===t[0]?e.strokeStyle="#fff":e.strokeStyle=d,e.beginPath();var v={width:0,height:0},g={width:1,height:1};o.notify("crop",{prop:"calcRatio",onPropertyChange:!1,value:{obj:v,dimension:{width:e.canvas.width,height:e.canvas.height}}}),g=v;var f=e.canvas.id===o.element.id+"_tempCanvas",C=o.transform.zoomFactor,b=f?10*u*((g.width+g.height)/2):10*u,m=b+b*C;null!==u?e.roundRect(a,n,s,l,m):e.rect(a,n,s,l),""!==h&&(e.fillStyle=h,e.fill()),null!==u?e.roundRect(a+c,n+c,s-2*c,l-2*c,m):e.rect(a+c,n+c,s-2*c,l-2*c),e.fillStyle=d,e.fill("evenodd"),e.closePath()},e.prototype.drawSelection=function(e,t){var o=this.parent,i=o.activeObj,r=i.activePoint,a=r.startX,n=r.startY,s=r.endX,l=r.endY;this.upperContext.strokeStyle=o.themeColl[o.theme].primaryColor,this.upperContext.beginPath(),i.horTopInnerLine={startX:a,startY:n+t,endX:s,endY:l+t},i.horBottomInnerLine={startX:a,startY:n+2*t,endX:s,endY:l+2*t},i.verLeftInnerLine={startX:a+e,startY:n,endX:a+e,endY:l},i.verRightInnerLine={startX:a+2*e,startY:n,endX:a+2*e,endY:l},this.upperContext.moveTo(i.horTopInnerLine.startX,i.horTopInnerLine.startY),this.upperContext.lineTo(i.horTopInnerLine.endX,i.horTopInnerLine.startY),this.upperContext.moveTo(i.horBottomInnerLine.startX,i.horBottomInnerLine.startY),this.upperContext.lineTo(i.horBottomInnerLine.endX,i.horBottomInnerLine.startY),this.upperContext.moveTo(i.verLeftInnerLine.startX,i.verLeftInnerLine.startY),this.upperContext.lineTo(i.verLeftInnerLine.endX,i.verLeftInnerLine.endY),this.upperContext.moveTo(i.verRightInnerLine.startX,i.verRightInnerLine.startY),this.upperContext.lineTo(i.verRightInnerLine.endX,i.verRightInnerLine.endY),this.upperContext.stroke(),this.upperContext.closePath()},e.prototype.shapeCircle=function(e,t,o){var i=this.parent,r=i.activeObj.activePoint,a=r.startX,n=r.startY,s=r.endX,l=r.endY,p=r.width;e.strokeStyle=i.themeColl[i.theme].primaryColor,e.clearRect(0,0,i.lowerCanvas.width,i.lowerCanvas.height),e.fillStyle="rgb(0, 0, 0, 0.25)",e.fillRect(0,0,i.lowerCanvas.width,i.lowerCanvas.height);var h=e.lineWidth;e.lineWidth=2,e.beginPath(),e.ellipse(i.activeObj.horTopLine.startX+t/2,i.activeObj.horTopLine.startY+o/2,t/2,o/2,0,0,2*Math.PI,!1),e.stroke(),e.closePath(),e.save(),e.beginPath(),e.arc((s-a)/2+a,(l-n)/2+n,p/2,0,2*Math.PI),e.closePath(),e.clip(),e.clearRect(0,0,i.lowerCanvas.width,i.lowerCanvas.height),e.restore(),e.lineWidth=h,this.drawOuterSelection(e,!0),i.currObjType.shape=""},e.prototype.shapeLine=function(e,t,o,i,r){var a=e.lineWidth;e.lineWidth=this.parent.activeObj.strokeSettings.strokeWidth,e.beginPath(),e.moveTo(t,o),e.lineTo(i,r),e.stroke(),e.lineWidth=a},e.prototype.manipulateSaveCtx=function(e,t,o){if(e!==this.lowerContext&&e!==this.upperContext){var i={width:0,height:0};this.parent.notify("crop",{prop:"calcRatio",onPropertyChange:!1,value:{obj:i,dimension:{width:e.canvas.width,height:e.canvas.height}}});var r=i;t&&(t*=r.width),o&&(o*=r.height)}return{x:t,y:o}},e.prototype.arrow=function(e,t){var o=this.parent.activeObj,i=o.activePoint,r=i.startX,a=i.startY,n=i.endX,s=i.endY,l=o.strokeSettings.strokeWidth;e.lineWidth=l;var p=this.arrowDimension.arrow.width,h=this.arrowDimension.arrow.height,d=this.manipulateSaveCtx(e,p,h);p=d.x+l,h=d.y+l,this.dx=n-r,this.dy=s-a,e.fillStyle=o.strokeSettings.strokeColor;var c=Math.atan2(this.dy,this.dx),u="arrow"===o.start,v="arrow"===o.end,g="circle"===o.end||"square"===o.end;((t&&"left"===o.triangleDirection||"right"===o.triangleDirection)&&(u&&"none"===o.end||u&&!g)||!t&&(v&&"none"===o.start||!u&&!g))&&this.shapeLine(e,r,a,n,s),t&&"left"===o.triangleDirection||!t&&"right"===o.triangleDirection?(e.translate(n,s),e.rotate(c),this.shapeLine(e,0,0,-p,h/2),this.shapeLine(e,0,0,-p,-h/2),e.rotate(-c),e.translate(-n,-s)):(t&&"right"===o.triangleDirection||!t&&"left"===o.triangleDirection)&&(e.translate(r,a),e.rotate(c),this.shapeLine(e,0,0,p,h/2),this.shapeLine(e,0,0,p,-h/2),e.rotate(-c),e.translate(-r,-a))},e.prototype.arrowSolid=function(e,t){var o=this.parent.activeObj,i=o.strokeSettings.strokeWidth,r=o.activePoint,a=r.startX,n=r.startY,s=r.endX,l=r.endY,p=this.arrowDimension.arrowSolid.width,h=this.arrowDimension.arrowSolid.height,d=this.manipulateSaveCtx(e,p,h);p=d.x+i,h=d.y+i,this.dx=s-a,this.dy=l-n;var c=Math.atan2(this.dy,this.dx),u="arrowSolid"===o.start,v="arrowSolid"===o.end,g="circle"===o.end||"square"===o.end;(t&&u&&"none"===o.end||u&&!g||!t&&(v&&"none"===o.start||!u&&!g))&&this.shapeLine(e,a,n,s,l),t&&"left"===o.triangleDirection||!t&&"right"===o.triangleDirection?(e.translate(s,l),e.rotate(c),e.beginPath(),e.moveTo(i,0),e.lineTo(h/2-p,h/2),e.lineTo(h/2-p,-h/2),e.closePath(),e.fill(),e.rotate(-c),e.translate(-s,-l),o.rotatedAngle=c):(t&&"right"===o.triangleDirection||!t&&"left"===o.triangleDirection)&&(e.translate(a,n),e.rotate(c),e.beginPath(),e.moveTo(0-i,0),e.lineTo(p-h/2,h/2),e.lineTo(p-h/2,-h/2),e.closePath(),e.fill(),e.rotate(-c),e.translate(-a,-n),o.rotatedAngle=c)},e.prototype.arrowSquareStart=function(e){var t=this.parent.activeObj,o=t.strokeSettings.strokeWidth,i=t.activePoint,r=i.startX,a=i.startY,n=i.endX,s=i.endY,l="square"===t.start,p="circle"===t.end,h="squareSolid"===t.start,d="circleSolid"===t.end;(l&&"none"===t.end||l&&!p&&"square"!==t.start||h&&d)&&this.shapeLine(e,r,a,n,s),e.lineWidth=o,e.beginPath(),e.fillStyle=t.strokeSettings.strokeColor;var c=this.arrowDimension.square.width,u=this.arrowDimension.square.height,v=this.manipulateSaveCtx(e,c,u);c=v.x+o,u=v.y+o,this.dx=n-r,this.dy=s-a;var g=Math.atan2(this.dy,this.dx);"left"===t.triangleDirection?(e.translate(n,s),e.rotate(g),"squareSolid"===t.start&&e.fillRect(u/2-c,-u/2,c,u),e.strokeRect(u/2-c,-u/2,c,u),e.rotate(-g),e.translate(-n,-s),this.squareStartIntersectX1=n-u/2*Math.cos(g),this.squareStartIntersectY1=s-u/2*Math.sin(g),"square"===t.start&&"square"!==t.end&&"circle"!==t.end?this.shapeLine(e,r,a,this.squareStartIntersectX1,this.squareStartIntersectY1):"square"===t.start&&"circle"===t.end?this.shapeLine(e,this.endCircleIntersectX1,this.endCircleIntersectY1,this.squareStartIntersectX1,this.squareStartIntersectY1):"squareSolid"===t.start&&"squareSolid"===t.end&&this.shapeLine(e,r,a,n,s)):"right"===t.triangleDirection&&(e.lineWidth=o,e.fillStyle=t.strokeSettings.strokeColor,"squareSolid"===t.start&&"squareSolid"===t.end&&this.shapeLine(e,r,a,n,s),e.translate(r,a),e.rotate(g),"squareSolid"===t.start&&e.fillRect(u/2-c,-u/2,c,u),e.strokeRect(u/2-c,-u/2,c,u),e.rotate(-g),e.translate(-r,-a),t.rotatedAngle=g,this.squareStartIntersectX1=r+u/2*Math.cos(g),this.squareStartIntersectY1=a+u/2*Math.sin(g),"square"===t.start&&"square"!==t.end&&"circle"!==t.end&&this.shapeLine(e,n,s,this.squareStartIntersectX1,this.squareStartIntersectY1),"square"===t.start&&"circle"===t.end&&this.shapeLine(e,this.endCircleIntersectX1,this.endCircleIntersectY1,this.squareStartIntersectX1,this.squareStartIntersectY1))},e.prototype.arrowSquareEnd=function(e){var t=this.parent.activeObj,o=t.activePoint,i=o.startX,r=o.startY,a=o.endX,n=o.endY,s=t.strokeSettings.strokeWidth,l=this.arrowDimension.square.width,p=this.arrowDimension.square.height,h=this.manipulateSaveCtx(e,l,p);l=h.x+s,p=h.y+s,this.dx=a-i,this.dy=n-r;var d=Math.atan2(this.dy,this.dx);e.lineWidth=s,"right"===t.triangleDirection?(e.fillStyle=t.strokeSettings.strokeColor,"squareSolid"===t.end&&"none"===t.start&&this.shapeLine(e,i,r,a,n),e.translate(a,n),e.rotate(d),"squareSolid"===t.end&&e.fillRect(p/2-l,-p/2,l,p),e.strokeRect(p/2-l,-p/2,l,p),e.rotate(-d),e.translate(-a,-n),t.rotatedAngle=d,this.squareEndIntersectX1=a-p/2*Math.cos(d),this.squareEndIntersectY1=n-p/2*Math.sin(d),"square"===t.end&&"square"!==t.start&&"circle"!==t.start?this.shapeLine(e,i,r,this.squareEndIntersectX1,this.squareEndIntersectY1):"circle"===t.start&&"square"===t.end?this.shapeLine(e,this.squareEndIntersectX1,this.squareEndIntersectY1,this.startCircleIntersectX1,this.startCircleIntersectY1):"square"===t.start&&"square"===t.end&&this.shapeLine(e,this.squareEndIntersectX1,this.squareEndIntersectY1,this.squareStartIntersectX1,this.squareStartIntersectY1)):"left"===t.triangleDirection&&(e.translate(i,r),e.rotate(d),"squareSolid"===t.end&&e.fillRect(p/2-l,-p/2,l,p),e.strokeRect(p/2-l,-p/2,l,p),e.rotate(-d),e.translate(-i,-r),t.rotatedAngle=d,this.squareEndIntersectX1=i+p/2*Math.cos(d),this.squareEndIntersectY1=r+p/2*Math.sin(d),"square"===t.end&&"square"!==t.start&&"circle"!==t.start?this.shapeLine(e,a,n,this.squareEndIntersectX1,this.squareEndIntersectY1):"circle"===t.start&&"square"===t.end?this.shapeLine(e,this.squareEndIntersectX1,this.squareEndIntersectY1,this.startCircleIntersectX1,this.startCircleIntersectY1):"square"===t.start&&"square"===t.end?this.shapeLine(e,this.squareEndIntersectX1,this.squareEndIntersectY1,this.squareStartIntersectX1,this.squareStartIntersectY1):"squareSolid"===t.end&&"none"===t.start&&this.shapeLine(e,i,r,a,n))},e.prototype.arrowCircle=function(e,t){var o=this.parent,i=o.activeObj,r=i.activePoint,a=r.startX,n=r.startY,s=r.endX,l=r.endY,p=i.strokeSettings.strokeWidth;if(t&&"left"===i.triangleDirection||!t&&"right"===i.triangleDirection){e.lineWidth=p;u=this.arrowDimension.circle.width;u=(v=this.manipulateSaveCtx(e,u,null)).x+p,e.beginPath(),e.arc(s,l,u,0,2*Math.PI),e.stroke(),e.closePath(),this.dx=s-a,this.dy=l-n;g=this.dx*this.dx+this.dy*this.dy;if((b=(f=2*(this.dx*(a-s)+this.dy*(n-l)))*f-4*g*(C=(a-s)*(a-s)+(n-l)*(n-l)-u*u))>=0){e.fillStyle=i.strokeSettings.strokeColor;var h=(-f-Math.sqrt(b))/(2*g),d=a+this.dx*h,c=n+this.dy*h;t?(this.startCircleIntersectX1=d,this.startCircleIntersectY1=c,this.endCircleIntersectX1=s-this.dx*h,this.endCircleIntersectY1=l-this.dy*h,e.beginPath(),e.fill(),e.beginPath(),"circle"===i.start&&"circle"===i.end?this.shapeLine(e,this.startCircleIntersectX1,this.startCircleIntersectY1,this.endCircleIntersectX1,this.endCircleIntersectY1):"circle"===i.start&&"circle"!==i.end&&"square"!==i.end&&this.shapeLine(e,a,n,this.startCircleIntersectX1,this.startCircleIntersectY1),e.stroke(),e.closePath()):(this.endCircleIntersectX1=d,this.endCircleIntersectY1=c,"circle"===i.end&&"circle"!==i.start&&"square"!==i.start&&this.shapeLine(e,a,n,this.endCircleIntersectX1,this.endCircleIntersectY1))}m=Math.atan2(this.dy,this.dx);o.activeObj.rotatedAngle=m}else if(t&&"right"===i.triangleDirection||!t&&"left"===i.triangleDirection){e.lineWidth=p;var u=this.arrowDimension.circle.width,v=this.manipulateSaveCtx(e,u,null);u=v.x+p,e.beginPath(),e.arc(a,n,u,0,2*Math.PI),e.stroke(),e.closePath(),this.dx=a-s,this.dy=n-l;var g=this.dx*this.dx+this.dy*this.dy,f=2*(this.dx*(s-a)+this.dy*(l-n)),C=(s-a)*(s-a)+(l-n)*(l-n)-u*u,b=f*f-4*g*C;if(b>=0){e.fillStyle=i.strokeSettings.strokeColor;var h=(-f-Math.sqrt(b))/(2*g),d=s+this.dx*h,c=l+this.dy*h;t?(this.startCircleIntersectX1=d,this.startCircleIntersectY1=c,this.endCircleIntersectX1=a-this.dx*h,this.endCircleIntersectY1=n-this.dy*h,"circle"===i.start&&"circle"===i.end?this.shapeLine(e,this.endCircleIntersectX1,this.endCircleIntersectY1,this.startCircleIntersectX1,this.startCircleIntersectY1):"circle"===i.start&&"circle"!==i.end&&"square"!==i.end&&this.shapeLine(e,s,l,this.startCircleIntersectX1,this.startCircleIntersectY1)):(this.endCircleIntersectX1=d,this.endCircleIntersectY1=c,e.beginPath(),e.fill(),e.beginPath(),"circle"===i.end&&"circle"!==i.start&&"square"!==i.start&&this.shapeLine(e,s,l,this.endCircleIntersectX1,this.endCircleIntersectY1))}var m=Math.atan2(this.dy,this.dx);o.activeObj.rotatedAngle=m}},e.prototype.arrowCircleSolid=function(e,t){var o=this.parent.activeObj,i=o.activePoint,r=i.startX,a=i.startY,n=i.endX,s=i.endY,l="circleSolid"===o.start,p=o.strokeSettings.strokeWidth;if(t&&"left"===o.triangleDirection||!t&&"right"===o.triangleDirection){e.lineWidth=p,e.beginPath(),e.fillStyle=o.strokeSettings.strokeColor,(t&&l&&"none"===o.end||l&&"circle"!==o.end&&"square"!==o.end||!t&&"circleSolid"===o.end&&"none"===o.start)&&this.shapeLine(e,r,a,n,s);h=this.arrowDimension.circle.width;h=(d=this.manipulateSaveCtx(e,h,null)).x+p,this.dx=n-r,this.dy=s-a,e.save(),e.beginPath(),e.arc(n,s,h,0,2*Math.PI),e.stroke(),e.fill(),e.closePath(),o.rotatedAngle=Math.atan2(this.dy,this.dx)}else if(t&&"right"===o.triangleDirection||!t&&"left"===o.triangleDirection){e.lineWidth=p,e.beginPath(),e.fillStyle=o.strokeSettings.strokeColor,(t&&l&&"none"===o.end||l&&"circle"!==o.end&&"square"!==o.end||!t&&"circleSolid"===o.end&&"none"===o.start)&&this.shapeLine(e,r,a,n,s);var h=this.arrowDimension.circle.width,d=this.manipulateSaveCtx(e,h,null);h=d.x+p,this.dx=n-r,this.dy=s-a,e.save(),e.beginPath(),e.arc(r,a,h,0,2*Math.PI),e.stroke(),e.fill(),e.closePath(),o.rotatedAngle=Math.atan2(this.dy,this.dx)}},e.prototype.arrowBar=function(e,t){var o=this.parent,i=o.activeObj,r=i.activePoint,a=r.startX,n=r.startY,s=r.endX,l=r.endY,p=i.strokeSettings.strokeWidth;if(t&&"left"===i.triangleDirection||!t&&"right"===i.triangleDirection){e.lineWidth=p,e.beginPath(),e.fillStyle=i.strokeSettings.strokeColor,(t&&"bar"===i.start&&"none"===i.end||"bar"===i.start&&"circle"!==i.end&&"square"!==i.end||!t&&("bar"===i.end&&"none"===i.start||"bar"===i.end&&"circle"!==i.start&&"square"!==i.start))&&this.shapeLine(e,a,n,s,l);var h=this.arrowDimension.bar.width,d=this.arrowDimension.bar.height;h=(c=this.manipulateSaveCtx(e,h,d)).x+p,d=c.y+p,this.dx=s-a,this.dy=l-n;u=Math.atan2(this.dy,this.dx);e.translate(s,l),e.rotate(u),e.fillRect(d/4-h,-d/2,h,d),e.rotate(-u),e.translate(-s,-l),i.rotatedAngle=u}else if(t&&"right"===i.triangleDirection||!t&&"left"===i.triangleDirection){e.lineWidth=p,e.beginPath(),e.fillStyle=i.strokeSettings.strokeColor,(t&&"bar"===i.start&&"none"===i.end||"bar"===i.start&&"circle"!==i.end&&"square"!==i.end||!t&&"bar"===i.end&&"none"===i.start)&&this.shapeLine(e,a,n,s,l);var h=this.arrowDimension.bar.width,d=this.arrowDimension.bar.height,c=this.manipulateSaveCtx(e,h,d);h=c.x+p,d=c.y+p,this.dx=s-a,this.dy=l-n;var u=Math.atan2(this.dy,this.dx);e.translate(a,n),e.rotate(u),e.fillRect(d/4-h,-d/2,h,d),e.rotate(-u),e.translate(-a,-n),o.activeObj.rotatedAngle=u}},e.prototype.shapeImage=function(e){var t=this.parent,o=t.activeObj,i=o.activePoint,r=i.startX,a=i.startY,n=i.width,s=i.height,l=o.imageCanvas.getContext("2d");if(e===this.lowerContext&&this.isImageApply){var p={width:0,height:0};t.notify("transform",{prop:"calcMaxDimension",onPropertyChange:!1,value:{width:o.imageElement.width,height:o.imageElement.height,obj:p,isImgShape:null}}),(n<p.width/5||s<p.height/5)&&(l.clearRect(0,0,o.imageCanvas.width,o.imageCanvas.height),t.notify("selection",{prop:"applyTransformToImg",onPropertyChange:!1,value:{ctx:l}}),t.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate"}}),this.upperContext.clearRect(0,0,t.upperCanvas.width,t.upperCanvas.height),t.notify("selection",{prop:"setImageClarity",onPropertyChange:!1,value:{bool:!1}}),this.isImageApply=!1)}var h={startX:0,startY:0,width:0,height:0};h.width=n,h.height=s,4===o.flipObjColl.length&&(o.flipObjColl=[],o.shapeFlip=""),h.startX=(n-h.width)/2+r,h.startY=(s-h.height)/2+a;var d=e.globalAlpha;e.globalAlpha=o.opacity,o.rotateFlipColl&&o.rotateFlipColl.length>0?this.rotateImage(e):e.drawImage(o.imageCanvas,h.startX,h.startY,h.width,h.height),e.globalAlpha=d,t.currObjType.isText=!1},e.prototype.shapeText=function(e){var t=this.parent,o=e.filter,i=t.activeObj,r=i.activePoint,a=r.startX,n=r.startY,s=r.width,l=r.height,p=i.keyHistory.split("\n"),h=i.textSettings,d=h.fontFamily,c=h.bold,u=h.italic,v=i.textSettings.fontSize,g=((v+.25*v)*p.length-v*p.length)/p.length;e.filter="none";var f=e.fillStyle;""!==i.strokeSettings.fillColor&&(e.fillStyle=i.strokeSettings.fillColor,e.fillRect(i.activePoint.startX,i.activePoint.startY,i.activePoint.width,i.activePoint.height)),e.fillStyle=f;for(var C=0;C<p.length;C++){var b=p[C],m=(C+1)*v*.85+C*g;-360===t.transform.degree&&(t.transform.degree=0),0===t.transform.degree||180===t.transform.degree?v>l&&(v=i.textSettings.fontSize=l-.1*l):v>s&&(v=i.textSettings.fontSize=s-.1*s),e.strokeStyle=i.strokeSettings.outlineColor,e.fillStyle=i.strokeSettings.strokeColor;var y=e.lineWidth,P={width:0,height:0},j={width:1,height:1};t.notify("crop",{prop:"calcRatio",onPropertyChange:!1,value:{obj:P,dimension:{width:e.canvas.width,height:e.canvas.height}}}),j=P;var x=e.canvas.id===t.element.id+"_tempCanvas",w=Math.max(1,i.strokeSettings.outlineWidth/2);/^#([0-9A-Fa-f]{3}|[0-9A-Fa-f]{6}|[0-9A-Fa-f]{8})$|^[a-zA-Z]+$/.test(i.strokeSettings.outlineColor)?(e.lineWidth=w*(.5*(x?Math.floor((v-1)/60):Math.floor((v-1)/16))+.5),x&&(e.lineWidth*=(j.width+j.height)/2,0!==t.transform.degree&&(e.lineWidth/=1.8))):e.lineWidth=0;var O="";c&&(O="bold "),u&&(O="italic "),c&&u&&(O="italic bold "),e.font=O+v+"px "+d,4===i.flipObjColl.length&&(i.flipObjColl=[],i.shapeFlip=""),i.rotateFlipColl&&i.rotateFlipColl.length>0?this.rotateText(e):(e.strokeText(b,a+.1*v,n+m),e.fillText(b,a+.1*v,n+m)),e.lineWidth=y}e.filter=o,t.currObjType.isText=!1,this.upperContext===e&&this.drawOuterSelection(e)},e.prototype.updateActPoint=function(e,t){var o=this.parent,i=o.activeObj,r=i.activePoint;return"horizontal"===e.toLowerCase()?r.startX<=t.canvas.width/2?(r.startX=t.canvas.width/2+(t.canvas.width/2-r.endX),r.endX=r.startX+r.width,this.updateActiveObject(r,i),o.activeObj=i):r.startX>=t.canvas.width/2&&(r.startX=t.canvas.width-r.endX,r.endX=r.startX+r.width,this.updateActiveObject(r,i),o.activeObj=i):"vertical"===e.toLowerCase()&&(r.startY<=t.canvas.height/2?(r.startY=t.canvas.height/2+(t.canvas.height/2-r.endY),r.endY=r.startY+r.height,this.updateActiveObject(r,i),o.activeObj=i):r.startY>=t.canvas.height/2&&(r.startY=t.canvas.height-r.endY,r.endY=r.startY+r.height,this.updateActiveObject(r,i),o.activeObj=i)),r},e.prototype.rotateImage=function(e){var o,i=this.parent,r=i.activeObj,a=t.extend({},i.activeObj,null,!0);-450===(o=0===r.shapeDegree?i.transform.degree:i.transform.degree-r.shapeDegree)&&(o=-90),o<0&&(o=360+o);var n={startX:0,startY:0,width:0,height:0};n.width=o%90==0&&o%180!=0?r.activePoint.height:r.activePoint.width,n.height=o%90==0&&o%180!=0?r.activePoint.width:r.activePoint.height,n.startX=r.activePoint.startX,n.startY=r.activePoint.startY;var s,l=n.startX,p=n.startY;e.save();for(var h=0,d=r.rotateFlipColl.length;h<d;h++){var c=r.rotateFlipColl[h];"number"==typeof c?(-450===(s=0===r.shapeDegree?c:c-r.shapeDegree)&&(s=-90),s<0&&(s=360+s),n.width=s%90==0&&s%180!=0?r.activePoint.height:r.activePoint.width,n.height=s%90==0&&s%180!=0?r.activePoint.width:r.activePoint.height,e.translate(e.canvas.width/2,e.canvas.height/2),e.rotate(Math.PI/180*c),e.translate(-e.canvas.height/2,-e.canvas.width/2),s%90==0&&s%270!=0||0===s?(p=e.canvas.width-(r.activePoint.startX+r.activePoint.width),p+=(r.activePoint.width-n.height)/2,l=n.startY):s%270==0&&(l=e.canvas.height-(r.activePoint.startY+r.activePoint.height),l+=(r.activePoint.height-n.width)/2,p=n.startX),n.startX=l,n.startY=p,r.activePoint.startX=l,r.activePoint.startY=p,r.activePoint.endX=r.activePoint.startX+n.width,r.activePoint.endY=r.activePoint.startY+n.height,r=this.updateWidthHeight(r)):("horizontal"===c&&o%90==0&&o%180!=0?c="vertical":"vertical"===c&&o%90==0&&o%180!=0&&(c="horizontal"),"horizontal"===c?(e.translate(e.canvas.width,0),e.scale(-1,1),r.activePoint=this.updateActPoint("horizontal",e)):"vertical"===c&&(e.translate(0,e.canvas.height),e.scale(1,-1),r.activePoint=this.updateActPoint("vertical",e)),n.startX=r.activePoint.startX,n.startY=r.activePoint.startY),n.startX=r.activePoint.startX,n.startY=r.activePoint.startY,l=n.startX,p=n.startY}0!==r.rotatedAngle&&i.notify("shape",{prop:"setPointCollForShapeRotation",onPropertyChange:!1,value:{obj:r}}),e.drawImage(r.imageCanvas,n.startX,n.startY,n.width,n.height),e.restore(),i.activeObj=a,360!==i.transform.degree&&-360!==i.transform.degree||(i.transform.degree=0)},e.prototype.rotateText=function(e){var o,i=this.parent,r=i.activeObj,a=t.extend({},i.activeObj,null,!0),n=i.activeObj.activePoint;-450===(o=0===r.shapeDegree?i.transform.degree:i.transform.degree-r.shapeDegree)&&(o=-90),o<0&&(o=360+o);var s={startX:0,startY:0,width:0,height:0};s.width=o%90==0&&o%180!=0?n.height:n.width,s.height=o%90==0&&o%180!=0?n.width:n.height,s.startX=n.startX,s.startY=n.startY;var l,p=s.startX,h=s.startY;e.save();for(var d=0,c=r.rotateFlipColl.length;d<c;d++){var u=r.rotateFlipColl[d];"number"==typeof u?(-450===(l=0===r.shapeDegree?u:u-r.shapeDegree)&&(l=-90),l<0&&(l=360+l),s.width=l%90==0&&l%180!=0?n.height:n.width,s.height=l%90==0&&l%180!=0?n.width:n.height,e.translate(e.canvas.width/2,e.canvas.height/2),e.rotate(Math.PI/180*u),e.translate(-e.canvas.height/2,-e.canvas.width/2),l%90==0&&l%270!=0||0===l?(h=e.canvas.width-n.endX,p=n.startY):l%270==0&&(p=e.canvas.height-n.endY,h=n.startX),s.startX=p,s.startY=h,n.startX=p,n.startY=h,n.endX=n.startX+s.width,n.endY=n.startY+s.height,r=this.updateWidthHeight(r)):("horizontal"===u&&o%90==0&&o%180!=0?u="vertical":"vertical"===u&&o%90==0&&o%180!=0&&(u="horizontal"),"horizontal"===u?(e.translate(e.canvas.width,0),e.scale(-1,1)):"vertical"===u&&(e.translate(0,e.canvas.height),e.scale(1,-1)),r.activePoint=n=this.updateActPoint(u,e),s.startX=n.startX,s.startY=n.startY),s.startX=n.startX,s.startY=n.startY,p=s.startX,h=s.startY}0!==r.rotatedAngle&&i.notify("shape",{prop:"setPointCollForShapeRotation",onPropertyChange:!1,value:{obj:r}}),h+=.4*r.textSettings.fontSize,this.textFlipDegree(e,p,h),e.restore(),i.activeObj=a,360!==i.transform.degree&&-360!==i.transform.degree||(i.transform.degree=0)},e.prototype.textFlipDegree=function(e,t,o){for(var i=this.parent.activeObj,r=i.keyHistory.split("\n"),a=i.textSettings.fontSize,n=.85*a+(a*r.length-a*r.length)/r.length,s=0,l=r.length;s<l;s++){var p=r[s];s>0&&(1===s&&(n-=.85*a),n+=a+.15*a),e.strokeText(p,t+.15*a,o+n+(s>0?.25*a:.35*-a)),e.fillText(p,t+.15*a,o+n+(s>0?.25*a:.35*-a))}},e.prototype.clearOuterCanvas=function(e){var t=this.parent,o=t.img,i=o.destLeft,r=o.destTop,a=o.destWidth,n=o.destHeight,s=i>0?i:0,l=r>0?r:0;e.clearRect(0,0,s,t.lowerCanvas.height),e.clearRect(i+a,0,t.lowerCanvas.width-(i+a),t.lowerCanvas.height),e.clearRect(0,0,t.lowerCanvas.width,l),e.clearRect(0,r+n,t.lowerCanvas.width,t.lowerCanvas.height-(r+n)),""!==t.transform.currFlipState&&(t.img.destLeft=i,t.img.destTop=r)},e.prototype.setDestPoints=function(){var e,t=this.parent,o=t.transform,i=o.degree,r=o.zoomFactor;if(i%90==0&&i%180!=0){a={width:0,height:0};t.notify("transform",{prop:"calcMaxDimension",onPropertyChange:!1,value:{width:t.img.srcHeight,height:t.img.srcWidth,obj:a,isImgShape:null}}),e=a,this.isRotateZoom&&(e.width+=e.width*r,e.height+=e.height*r,t.img.destWidth=e.height,t.img.destHeight=e.width),t.img.destLeft=(t.lowerCanvas.clientWidth-e.height)/2,t.img.destTop=(t.lowerCanvas.clientHeight-e.width)/2,t.img.destWidth=e.height,t.img.destHeight=e.width}else{var a={width:0,height:0};t.notify("transform",{prop:"calcMaxDimension",onPropertyChange:!1,value:{width:t.img.srcWidth,height:t.img.srcHeight,obj:a,isImgShape:null}}),e=a,this.isRotateZoom&&(e.width+=e.width*r,e.height+=e.height*r,t.img.destWidth=e.width,t.img.destHeight=e.height),t.img.destLeft=(t.lowerCanvas.clientWidth-e.width)/2,t.img.destTop=0===i?(t.lowerCanvas.clientHeight-e.height+1)/2:(t.lowerCanvas.clientHeight-e.height)/2,t.img.destWidth=e.width,t.img.destHeight=e.height}},e.prototype.updateCurrTransState=function(e,o,i,r){var a=this.parent,n=a.img.destLeft,s=a.img.destTop;"initial"===e&&(this.lowerContext.setTransform(1,0,0,1,0,0),t.isNullOrUndefined(o)&&this.setDestPoints()),a.isCircleCrop||a.currSelectionPoint&&"crop-circle"===a.currSelectionPoint.shape?(this.currTransState(e,!0,null,i),0===a.transform.degree&&""===a.transform.currFlipState&&0===a.transform.straighten&&t.isNullOrUndefined(r)&&(a.img.destLeft=n,a.img.destTop=s),i&&(a.img.destLeft+=a.panPoint.totalPannedClientPoint.x,a.img.destTop+=a.panPoint.totalPannedClientPoint.y),a.notify("crop",{prop:"cropCircle",onPropertyChange:!1,value:{context:this.lowerContext,isSave:null,isFlip:null}}),i&&(a.img.destLeft-=a.panPoint.totalPannedClientPoint.x,a.img.destTop-=a.panPoint.totalPannedClientPoint.y)):(this.currTransState(e,null,null,i),0===a.transform.degree&&""===a.transform.currFlipState&&0===a.transform.straighten&&t.isNullOrUndefined(r)&&(a.img.destLeft=n,a.img.destTop=s))},e.prototype.currTransState=function(e,o,i,r){var a=this.parent;i=i||this.lowerContext,"initial"===e?this.setTransformColl(i,e):"reverse"===e&&(this.setTransformColl(i,e),this.setClientTransDim(o),(a.isCircleCrop||a.currSelectionPoint&&"crop-circle"===a.currSelectionPoint.shape&&t.isNullOrUndefined(r))&&(r&&(a.img.destLeft+=a.panPoint.totalPannedClientPoint.x,a.img.destTop+=a.panPoint.totalPannedClientPoint.y),a.notify("crop",{prop:"cropCircle",onPropertyChange:!1,value:{context:this.lowerContext,isSave:null,isFlip:null}}),r&&(a.img.destLeft-=a.panPoint.totalPannedClientPoint.x,a.img.destTop-=a.panPoint.totalPannedClientPoint.y)))},e.prototype.setTransformColl=function(e,t){var o=this.parent;if("initial"===t)for(var i=0,r=o.rotateFlipColl.length;i<r;i++)this.setTransform(e,o.rotateFlipColl[i]);else if("reverse"===t)for(i=o.rotateFlipColl.length-1;i>=0;i--)this.setTransform(e,o.rotateFlipColl[i],!0)},e.prototype.setTransform=function(e,o,i){var r=this.parent;switch(i&&90===o?o=-90:i&&-90===o&&(o=90),"horizontal"===o&&r.transform.degree%90==0&&r.transform.degree%180!=0?o="vertical":"vertical"===o&&r.transform.degree%90==0&&r.transform.degree%180!=0&&(o="horizontal"),r.notify("transform",{prop:"setReverseRotate",onPropertyChange:!1,value:{bool:!0}}),r.notify("transform",{prop:"setReverseFlip",onPropertyChange:!1,value:{isReverseFlip:!0}}),t.isNullOrUndefined(i)&&e.clearRect(0,0,e.canvas.width,e.canvas.height),o){case 90:case-90:e.translate(e.canvas.width/2,e.canvas.height/2),e.rotate(Math.PI/180*o),e.translate(-e.canvas.width/2,-e.canvas.height/2);break;case"horizontal":e.translate(e.canvas.width,0),e.scale(-1,1);break;case"vertical":e.translate(0,e.canvas.height),e.scale(1,-1)}r.notify("transform",{prop:"setReverseRotate",onPropertyChange:!1,value:{bool:!1}}),r.notify("transform",{prop:"setReverseFlip",onPropertyChange:!1,value:{isReverseFlip:!1}})},e.prototype.drawImgToCanvas=function(e){var t=this.parent;this.lowerContext.clearRect(0,0,t.lowerCanvas.width,t.lowerCanvas.height),t.img.destWidth=e.width,t.img.destHeight=e.height,this.isInitialLoading&&(t.notify("filter",{prop:"initFilter",onPropertyChange:!1}),this.isInitialLoading=!1);var o=this.lowerContext.filter;this.lowerContext.clearRect(0,0,t.lowerCanvas.width,t.lowerCanvas.height),this.drawImage(),(t.currSelectionPoint&&"crop-circle"===t.currSelectionPoint.shape||t.isCircleCrop)&&t.notify("crop",{prop:"cropCircle",onPropertyChange:!1,value:{context:this.lowerContext,isSave:null,isFlip:null}}),this.lowerContext.filter=o},e.prototype.renderImage=function(e,o,i,r){var a=this.parent;a.notify("shape",{prop:"applyActObj",onPropertyChange:!1,value:{isMouseDown:null}}),t.isNullOrUndefined(o)&&(this.upperContext.clearRect(0,0,a.lowerCanvas.width,a.lowerCanvas.height),this.lowerContext.clearRect(0,0,a.lowerCanvas.width,a.lowerCanvas.height)),e?this.setTransformColl(this.lowerContext,"initial"):(0!==a.transform.zoomFactor&&(this.isRotateZoom=!0),this.updateCurrTransState("initial",null,null,r)),a.notify("transform",{prop:"setDestPointsForFlipState",onPropertyChange:!1}),this.drawImage(),a.notify("transform",{prop:"setDestPointsForFlipState",onPropertyChange:!1}),e?this.setTransformColl(this.lowerContext,"reverse"):(this.updateCurrTransState("reverse",null,null,r),this.isRotateZoom=!1),i?a.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"zoom",pen:"zoom",isPreventApply:null}}):a.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"iterate",pen:"iterate",isPreventApply:null}}),this.clearOuterCanvas(this.lowerContext),(a.isCircleCrop||a.currSelectionPoint&&"crop-circle"===a.currSelectionPoint.shape)&&a.notify("crop",{prop:"cropCircle",onPropertyChange:!1,value:{context:this.lowerContext,isSave:null,isFlip:null}})},e.prototype.imageOnLoad=function(e){var i=this,r=this.parent,a=this;r.baseImg.src=e,r.baseImg.onload=function(){r.imgSrc=e,r.isUndoRedo||r.notify("filter",{prop:"update-finetunes",onPropertyChange:!1}),a.lowerContext.drawImage(r.baseImg,0,0,a.parent.lowerCanvas.width,a.parent.lowerCanvas.height),o.hideSpinner(r.element),r.element.style.opacity="1",a.updateBaseImgCanvas();var n={fileName:i.fileName,fileType:i.fileType,isValidImage:!0};if(a.updateCanvas(),r.currObjType.isUndoZoom&&(r.currObjType.isUndoZoom=!1,a.parent.lowerCanvas.style.display="block"),r.isUndoRedo=i.isErrorImage=!1,t.Browser.isDevice){r.notify("toolbar",{prop:"destroy-top-toolbar",onPropertyChange:!1}),r.notify("toolbar",{prop:"destroy-bottom-toolbar",onPropertyChange:!1});s={isApplyBtn:!1,isDevice:t.Browser.isDevice,isOkBtn:null,isResize:null,isFrame:null,isMainToolbar:!0};r.notify("toolbar",{prop:"init-main-toolbar",onPropertyChange:!1,value:s}),r.notify("toolbar",{prop:"create-bottom-toolbar",onPropertyChange:!1})}else{r.notify("toolbar",{prop:"destroy-top-toolbar",onPropertyChange:!1});var s={isApplyBtn:!1,isDevice:!1,isOkBtn:null};r.notify("toolbar",{prop:"init-main-toolbar",onPropertyChange:!1,value:s})}if(r.isImageLoaded&&"0.5"!==r.element.style.opacity){r.trigger("fileOpened",n);var l={action:"file-open",actionEventArgs:n};r.triggerEditCompleteEvent(l)}},r.baseImg.onerror=function(){o.hideSpinner(r.element),a.isErrorImage=!0,a.errorLoading()}},e.prototype.errorLoading=function(){var e={fileName:null,fileType:null,isValidImage:!1};this.parent.trigger("fileOpened",e)},e.prototype.updateBaseImgCanvas=function(){var e=this.parent;e.baseImgCanvas.width=e.baseImg.width,e.baseImgCanvas.height=e.baseImg.height,e.baseImgCanvas.getContext("2d").drawImage(e.baseImg,0,0)},e.prototype.updateCanvas=function(){var e=this.parent;e.isImageUpdated||(e.img.srcWidth=e.baseImgCanvas.width,e.img.srcHeight=e.baseImgCanvas.height);var o={width:0,height:0};e.notify("transform",{prop:"calcMaxDimension",onPropertyChange:!1,value:{width:e.img.srcWidth,height:e.img.srcHeight,obj:o,isImgShape:null}});var i=o;e.img.destLeft=(e.lowerCanvas.clientWidth-i.width)/2,e.img.destTop=(e.lowerCanvas.clientHeight-i.height+1)/2,this.drawImgToCanvas(i),this.origDim.width=e.img.destWidth,this.origDim.height=e.img.destHeight,this.zoomCrop.width=e.img.destWidth,this.zoomCrop.height=e.img.destHeight,e.notify("transform",{prop:"setCropDimension",onPropertyChange:!1,value:{width:e.img.destWidth,height:e.img.destHeight}});var r={startX:e.img.destLeft,startY:e.img.destTop,width:e.img.destWidth,height:e.img.destHeight};e.notify("crop",{prop:"setCropDestPoints",onPropertyChange:!1,value:{point:r}});var a=this.lowerContext.filter;this.lowerContext.filter="none",e.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"iterate",pen:"zoom",isPreventApply:null}}),this.lowerContext.filter=a,e.img.destWidth>0&&e.img.destHeight>0&&(e.isImageLoaded=!0),e.isUndoRedo&&""!==e.transform.currFlipState&&e.notify("transform",{prop:"flipImage",onPropertyChange:!1,value:{direction:e.toPascalCase(e.transform.currFlipState)}}),e.disabled&&e.element.setAttribute("class","e-disabled"),(1!==e.zoomSettings.zoomFactor||e.zoomSettings.zoomPoint)&&e.zoom(e.zoomSettings.zoomFactor,e.zoomSettings.zoomPoint),t.isNullOrUndefined(this.initZoomValue)&&(this.initZoomValue=e.zoomSettings.zoomFactor),this.isImageEdited=!1},e.prototype.resetFrameZoom=function(e){var o=this.parent;if(!t.isNullOrUndefined(o.tempFrameZoomLevel)){var i=o.tempFrameZoomLevel;o.tempFrameZoomLevel=null,o.notify("transform",{prop:"resetZoom",onPropertyChange:!1}),o.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:i,zoomPoint:null,isResize:!0}});var r=o.cancelCropSelection;e&&r&&(r.previousObj.frameObj=t.extend({},o.frameObj,null,!0),r.currentObj.frameObj=t.extend({},o.frameObj,null,!0),r.previousObj.frame=r.currentObj.frame=o.frameObj.type),this.updateCropSelObj(),o.cancelCropSelection=null}},e.prototype.performCancel=function(e,o,i){var r=this.parent;i&&(r.noPushUndo=!1);var a={bool:r.isStraightening};e=e||!1;var n={bool:!1};r.allowDownScale=!0,r.notify("selection",{prop:"getFreehandDrawEditing",onPropertyChange:!1,value:{obj:n}}),t.isNullOrUndefined(o)&&JSON.stringify(r.frameObj)!==JSON.stringify(r.tempFrameObj)&&(t.extend(r.frameObj,r.tempFrameObj),this.renderImage(null,null,!0)),this.resetFrameZoom(!1);var s={action:""};if(n.bool)s.action="freehand-draw",r.notify("freehand-draw",{prop:"cancelFhd",onPropertyChange:!1}),r.notify("toolbar",{prop:"destroy-qa-toolbar",onPropertyChange:!1}),r.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"ok"}});else if("block"===r.textArea.style.display||"inline-block"===r.textArea.style.display)s.action="text-editing",r.textArea.style.display="none",r.textArea.value="",r.textArea.style.transform="",this.prevActObj?(r.activeObj=this.prevActObj,this.prevActObj=null):(r.activeObj.strokeSettings=this.tempStrokeSettings,r.activeObj.textSettings=this.tempTextSettings),r.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"cancel"}}),this.isShapeTextInserted&&r.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),r.notify("shape",{prop:"applyActObj",onPropertyChange:!1,value:{isMouseDown:!0}}),r.notify("toolbar",{prop:"refresh-main-toolbar",onPropertyChange:!1}),r.notify("selection",{prop:"setTempActObj",onPropertyChange:!1,value:{obj:r.activeObj}}),r.drawingShape&&r.enableShapeDrawing(r.toPascalCase(r.drawingShape),!0);else if(r.activeObj.shape&&"redact"===r.activeObj.shape||!((!t.Browser.isDevice||t.Browser.isDevice&&!a.bool)&&document.querySelector("#"+r.element.id+"_sliderWrapper")||r.currObjType.isFiltered))if(r.activeObj.shape&&"redact"===r.activeObj.shape||!e||t.Browser.isDevice&&(!t.Browser.isDevice||a.bool))this.cancelItems(s),r.transform.zoomFactor>0?(r.togglePan=!0,r.notify("selection",{prop:"setDragCanvas",value:{bool:!0}})):(r.togglePan=!1,r.notify("selection",{prop:"setDragCanvas",value:{bool:!1}}));else{p={type:"main",isApplyBtn:null,isCropping:null,isZooming:null};r.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:p})}else{s.action=r.isFinetuneBtnClick?"fine-tune":"filter",this.lowerContext.filter=this.tempAdjValue,r.canvasFilter=this.tempAdjValue,r.notify("filter",{prop:"setAdjustmentValue",onPropertyChange:!1,value:{adjustmentValue:this.tempAdjValue}}),r.initialAdjustmentValue=this.tempAdjValue,this.lowerContext.filter.split(" ").length>1&&"1"===this.lowerContext.filter.split(" ")[0].split("(")[1].split(")")[0]&&r.notify("filter",{prop:"setBrightnessAdjusted",onPropertyChange:!1,value:{isBrightnessAdjusted:!1}}),r.currentFilter=this.tempFilter,r.notify("filter",{prop:"setBevelFilter",onPropertyChange:!1,value:{bevelFilter:this.lowerContext.filter}}),this.lowerContext.clearRect(0,0,r.lowerCanvas.width,r.lowerCanvas.height),this.redrawImgWithObj(),r.currObjType.isFiltered=!1;var l={tempAdjustmentLevel:null};r.notify("filter",{prop:"getTempAdjustmentLevel",onPropertyChange:!1,value:{obj:l}}),r.notify("filter",{prop:"setAdjustmentLevel",onPropertyChange:!1,value:{adjustmentLevel:t.extend({},l.tempAdjustmentLevel,{},!0)}}),r.notify("undo-redo",{prop:"setUndoRedoStep",onPropertyChange:!1,value:{step:this.tempUndoRedoStep}}),r.upperCanvas.style.cursor=r.cursor="default",r.currObjType.isCustomCrop=!1,this.tempStrokeSettings={strokeColor:"#fff",fillColor:"",strokeWidth:null,radius:null,outlineColor:"",outlineWidth:null},this.clearOuterCanvas(this.lowerContext),(r.currSelectionPoint&&"crop-circle"===r.currSelectionPoint.shape||r.isCircleCrop)&&r.notify("crop",{prop:"cropCircle",onPropertyChange:!1,value:{context:this.lowerContext,isSave:null,isFlip:null}});var p={type:"main",isApplyBtn:null,isCropping:null,isZooming:null};r.element.querySelector(".e-contextual-toolbar-wrapper").classList.add("e-hide"),r.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:p}),r.activeObj.shape&&"image"===r.activeObj.shape&&r.notify("toolbar",{prop:"destroy-qa-toolbar",onPropertyChange:!1}),r.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"cancel"}}),r.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),this.upperContext.clearRect(0,0,r.upperCanvas.width,r.upperCanvas.height),r.drawingShape&&(r.drawingShape=null,r.notify("selection",{prop:"setCurrentDrawingShape",onPropertyChange:!1,value:{value:""}}))}this.isShapeTextInserted=!1,this.isNewPath=!1,r.notify("toolbar",{prop:"refresh-dropdown-btn",value:{isDisabled:!1}}),r.notify("toolbar",{prop:"setCurrentToolbar",value:{type:"main"}}),i&&(r.noPushUndo=!1),r.drawingShape=null,r.notify("draw",{prop:"resetTempObjColl"}),r.notify("draw",{prop:"resetTempPointColl"}),r.isMaskImage=r.isFinetuneBtnClick=!1;var h={action:"cancel",actionEventArgs:s};r.triggerEditCompleteEvent(h)},e.prototype.cancelItems=function(e){var o,i=this.parent,r=!1,a=i.element.id,n=i.element.querySelector("#"+a+"_aspectratio"),s=i.element.querySelector("#"+a+"_nonaspectratio"),l=["rectangle","ellipse","line","arrow","path","image","redact"];if(void 0!==i.activeObj.shape&&(o=i.activeObj.shape.split("-")),void 0===o&&i.currObjType.isCustomCrop?r=!0:void 0!==o&&"crop"===o[0]&&(r=!0),r&&i.isCropTab&&(i.isCropTab=!1,i.transform.zoomFactor=i.transform.defaultZoomFactor),i.isResize&&(n||s||"resize-toolbar"===i.currentToolbar)){e.action="resize";var p={width:null,height:null};i.notify("selection",{prop:"getNumTextValue",onPropertyChange:!1,value:{obj:p}});var h={x:p.width,y:p.height},d=i.element.querySelector("#"+i.element.id+"_aspectratio"),c=i.element.querySelector(".e-ie-toolbar-aspect-ratio-btn");if(h&&h.x&&h.y&&!t.isNullOrUndefined(i.aspectWidth))if(d||c&&!c.classList.contains("e-hidden"))i.notify("transform",{prop:"resizeImage",value:{width:i.aspectWidth,height:i.aspectHeight}});else{var u=i.currObjType.isUndoAction;i.currObjType.isUndoAction=!1,i.notify("transform",{prop:"resizeCrop",value:{width:i.aspectWidth,height:i.aspectHeight}}),i.currObjType.isUndoAction=u}var v={prevCropObj:i.prevCropObj},g={prevObj:i.prevObj};if(i.notify("toolbar",{prop:"getPrevCropObj",onPropertyChange:!1,value:{obj:v}}),i.notify("toolbar",{prop:"getPrevObj",onPropertyChange:!1,value:{obj:g}}),v.prevCropObj&&g.prevObj){i.objColl=[],i.pointColl=[],i.freehandCounter=0,i.cropObj=t.extend({},v.prevCropObj,{},!0),this.setCurrentObj(g.prevObj),i.objColl=g.prevObj.objColl,i.pointColl=g.prevObj.pointColl,i.freehandCounter=i.pointColl.length,i.transform.straighten=0,i.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"zoom",pen:"zoom",isPreventApply:null}});var f=i.currSelectionPoint?t.extend({},i.currSelectionPoint,{},!0):null;i.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:-i.transform.zoomFactor,zoomPoint:null,isResize:!0}}),i.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:g.prevObj.defaultZoom,zoomPoint:null,isResize:!0}}),i.currSelectionPoint=f,g.prevObj.zoomFactor&&i.setProperties({zoomSettings:{zoomFactor:g.prevObj.zoomFactor}},!0),i.notify("transform",{prop:"setPreviousZoomValue",onPropertyChange:!1,value:{previousZoomValue:i.zoomSettings.zoomFactor}})}i.isResize=!1,i.notify("transform",{prop:"setResizedImgAngle",onPropertyChange:!1,value:{angle:null}});var C=i.isCropTab;i.isCropTab=!1,this.updateCropSelObj(),i.cancelCropSelection=null,i.isCropTab=C}switch(!0){case i.togglePen:e.action="freehand-draw",this.cancelPen();break;case"text"===i.activeObj.shape:e.action="text",this.cancelText();break;case-1!==l.indexOf(i.activeObj.shape):e.action=i.activeObj.shape,this.cancelShape(),i.currObjType.isRedact=!1;break;case r:e.action="crop-selection",this.cancelSelection();break;default: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,radius:null,outlineColor:"",outlineWidth:null};var b={type:"main",isApplyBtn:null,isCropping:!1,isZooming:null};i.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:b})},e.prototype.cancelPen=function(){var e=this.parent;this.upperContext.clearRect(0,0,e.upperCanvas.width,e.upperCanvas.height),e.togglePen=!1,e.upperCanvas.style.cursor=e.cursor="default";var o=t.extend([],e.pointColl,[],!0);e.pointColl={};for(var i=0;i<this.tempFreehandCounter;i++)e.pointColl[i]=o[i];e.freehandCounter=this.tempFreehandCounter,e.notify("freehand-draw",{prop:"setCurrentFreehandDrawIndex",value:{value:this.tempCurrFhdIndex}}),e.activeObj.strokeSettings=this.tempStrokeSettings,e.notify("shape",{prop:"setStrokeSettings",value:{strokeSettings:e.activeObj.strokeSettings,strokeColor:null,fillColor:null,strokeWidth:null,radius:null}}),e.notify("freehand-draw",{prop:"setPenStrokeWidth",onPropertyChange:!1,value:{value:this.tempStrokeWidth}}),e.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"cancel"}}),e.notify("selection",{prop:"setFreehandDrawCustomized",value:{isFreehandDrawCustomized:!1}}),e.objColl=t.extend([],this.tempObjColl,[],!0),e.pointColl=t.extend([],this.tempPointColl,[],!0),e.freehandCounter=e.pointColl.length,this.tempPointColl={},this.renderImage(),e.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"ok",isCancel:!0}})},e.prototype.cancelText=function(){var e=this.parent;if(e.notify("shape",{prop:"setTextSettings",onPropertyChange:!1,value:{textSettings:this.tempTextSettings,fontFamily:null,fontSize:null}}),e.notify("shape",{prop:"setStrokeSettings",value:{strokeSettings:this.tempStrokeSettings,strokeColor:null,fillColor:null,strokeWidth:null,radius:null}}),t.isNullOrUndefined(e.activeObj.currIndex))e.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),this.upperContext.clearRect(0,0,e.upperCanvas.width,e.upperCanvas.height);else{var o={appliedUndoRedoColl:[]};e.notify("undo-redo",{prop:"getAppliedUndoRedoColl",value:{obj:o}});var i=o.appliedUndoRedoColl.length,r=o.appliedUndoRedoColl[i-1];this.prevActObj&&r&&r.currentObjColl.length&&r.currentObjColl[r.currentObjColl.length-1].currIndex===this.prevActObj.currIndex?(e.activeObj=this.prevActObj,this.prevActObj=null):(e.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),this.upperContext.clearRect(0,0,e.upperCanvas.width,e.upperCanvas.height))}e.notify("toolbar",{prop:"destroy-qa-toolbar",onPropertyChange:!1}),this.tempTextSettings={text:"Enter Text",fontFamily:e.fontFamily.default,fontSize:null,fontRatio:null,bold:!1,italic:!1,underline:!1},e.objColl=t.extend([],this.tempObjColl,[],!0),e.pointColl=t.extend([],this.tempPointColl,[],!0),this.renderImage(),this.tempObjColl=[],e.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"ok",isCancel:!0}})},e.prototype.cancelShape=function(){var e=this.parent;if(e.notify("shape",{prop:"setStrokeSettings",value:{strokeSettings:this.tempStrokeSettings,strokeColor:null,fillColor:null,strokeWidth:null,radius:null}}),t.isNullOrUndefined(e.activeObj.currIndex))e.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),this.upperContext.clearRect(0,0,e.upperCanvas.width,e.upperCanvas.height);else if(this.isNewPath)e.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),this.upperContext.clearRect(0,0,e.upperCanvas.width,e.upperCanvas.height),this.renderImage();else{var o={appliedUndoRedoColl:[]};e.notify("undo-redo",{prop:"getAppliedUndoRedoColl",value:{obj:o}});for(var i=void 0,r=0,a=o.appliedUndoRedoColl.length;r<a;r++)for(var n=o.appliedUndoRedoColl[r].currentObjColl,s=0,l=n.length;s<l;s++)if(this.prevActObj&&this.prevActObj.currIndex&&n[s].currIndex===this.prevActObj.currIndex){i=n[0];break}this.prevActObj&&i?(e.activeObj=this.prevActObj,this.prevActObj=null,e.notify("selection",{prop:"redrawShape",onPropertyChange:!1,value:{obj:e.activeObj}}),e.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"cancel"}}),e.notify("shape",{prop:"applyActObj",onPropertyChange:!1,value:{isMouseDown:!0}})):(e.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),this.upperContext.clearRect(0,0,e.upperCanvas.width,e.upperCanvas.height));var p={undoRedoStep:null};e.notify("undo-redo",{prop:"getUndoRedoStep",value:{obj:p}}),o.appliedUndoRedoColl[p.undoRedoStep-1]?e.objColl=t.extend([],o.appliedUndoRedoColl[p.undoRedoStep-1].currentObjColl,[],!0):e.objColl=[],this.renderImage()}e.currObjType.isDragging=!1,e.notify("toolbar",{prop:"destroy-qa-toolbar",onPropertyChange:!1}),e.objColl=t.extend([],this.tempObjColl,[],!0),e.pointColl=t.extend([],this.tempPointColl,[],!0),this.renderImage(),this.tempObjColl=[],e.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"ok",isCancel:!0}})},e.prototype.cancelSelection=function(){var e=this.parent;if(e.cancelCropSelection){var o={value:e.tempStraighten};e.transform.straighten=o.value,e.straightenBaseImageCanvas(),e.notify("freehand-draw",{prop:"resetStraightenPoint"}),e.notify("draw",{prop:"render-image",value:{isMouseWheel:!1}}),e.notify("draw",{prop:"setStraightenActObj",value:{activeObj:e.activeObj}}),e.notify("crop",{prop:"resizeWrapper"}),this.updateCropSelObj(),this.tempStraightenDestPoints&&JSON.stringify(this.tempStraightenDestPoints)!==JSON.stringify(this.straightenDestPoints)&&(this.straightenDestPoints=t.extend({},this.tempStraightenDestPoints,{},!0))}},e.prototype.updateCropSelObj=function(){var e=this.parent;e.cancelCropSelection&&(e.cropObj=t.extend({},e.cancelCropSelection.previousCropObj,{},!0),e.afterCropActions=e.cancelCropSelection.previousObj.afterCropActions,e.notify("undo-redo",{prop:"undoDefault",onPropertyChange:!1,value:{obj:e.cancelCropSelection}}),e.currSelectionPoint=t.extend({},e.cancelCropSelection.previousCropObj.activeObj,!0),e.currSelectionPoint&&t.isNullOrUndefined(e.currSelectionPoint.shape)&&(e.currSelectionPoint=null),this.clearOuterCanvas(this.lowerContext),(e.isCircleCrop||e.currSelectionPoint&&"crop-circle"===e.currSelectionPoint.shape)&&e.notify("crop",{prop:"cropCircle",onPropertyChange:!1,value:{context:this.lowerContext,isSave:null,isFlip:null}}))},e.prototype.updateCropSelection=function(){var e=this.parent,o={currObj:{}};e.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:o}});var i=o.currObj;i.objColl=t.extend([],e.objColl,[],!0),i.pointColl=t.extend([],e.pointColl,[],!0),i.afterCropActions=t.extend([],e.afterCropActions,[],!0);var r={selPointColl:null};e.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:r}}),i.selPointColl=t.extend([],r.selPointColl,[],!0),e.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:t.extend({},e.cropObj,{},!0),currentCropObj:t.extend({},e.cropObj,{},!0),previousText:null,currentText:null,filter:null,isCircleCrop:e.isCircleCrop}},e.prototype.updateFlipPan=function(e){var t=this.parent;if(""!==t.transform.currFlipState){var o=this.lowerContext.filter;t.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),t.notify("transform",{prop:"rotatedFlip",onPropertyChange:!1}),this.lowerContext.filter="none",t.notify("freehand-draw",{prop:"freehandRedraw",onPropertyChange:!1,value:{context:this.lowerContext,points:null}}),this.lowerContext.filter=o,this.upperContext.clearRect(0,0,t.upperCanvas.width,t.upperCanvas.height),e&&this.drawObject("duplicate",e)}},e.prototype.select=function(e,o,i,r,a){var n=this.parent;if(e=e.toLowerCase(),!n.disabled&&n.isImageLoaded){n.allowDownScale=!1;var s={currObj:{}};n.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:s}});var l=s.currObj;l.objColl=t.extend([],n.objColl,[],!0),l.pointColl=t.extend([],n.pointColl,[],!0),l.afterCropActions=n.afterCropActions;var p={selPointColl:null};n.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:p}}),l.selPointColl=t.extend([],p.selPointColl,[],!0),n.notify("crop",{prop:"setPreviousCropCurrentObj",onPropertyChange:!1,value:{obj:l}}),n.transform.zoomFactor>0&&n.activeObj.shape&&"crop"===n.activeObj.shape.split("-")[0]&&t.isNullOrUndefined(this.currSelPoint)&&(this.currSelPoint=t.extend({},n.activeObj,{},!0));var h=!1,d=void 0;void 0!==n.activeObj.shape&&(d=n.activeObj.shape.split("-")),void 0===d&&n.currObjType.isCustomCrop?h=!0:void 0!==d&&"crop"===d[0]&&(h=!0);var c={currObj:{}};n.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:c}});var u=c.currObj;if(u.objColl=t.extend([],n.objColl,[],!0),u.pointColl=t.extend([],n.pointColl,[],!0),u.afterCropActions=t.extend([],n.afterCropActions,[],!0),n.notify("shape",{prop:"redrawActObj",onPropertyChange:!1,value:{x:null,y:null,isMouseDown:null}}),n.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),n.notify("shape",{prop:"setKeyHistory",onPropertyChange:!1,value:{keyHistory:""}}),this.upperContext.clearRect(0,0,n.upperCanvas.width,n.upperCanvas.height),n.upperCanvas.style.display="block",n.currSelectionPoint||0!==n.transform.defaultZoomFactor||0!==n.transform.degree&&0!==n.panPoint.totalPannedInternalPoint.x&&0!==n.panPoint.totalPannedInternalPoint.y&&!h){if(n.isCircleCrop=!1,0!==n.transform.defaultZoomFactor&&!this.isResizeSelect){var v=n.isCropTab;n.isCropTab=!1,n.notify("transform",{prop:"resetZoom",onPropertyChange:!1}),n.isCropTab=v,this.resetPanPoints()}n.notify("freehand-draw",{prop:"updateFHDColl",onPropertyChange:!1}),n.isCropTab=!0,n.isCircleCrop=!1,this.isResizeSelect||n.notify("crop",{prop:"setCurrSelPoints",onPropertyChange:!1,value:{isSetDimension:!0}}),n.transform.zoomFactor=n.transform.cropZoomFactor,t.isNullOrUndefined(n.cropObj.activeObj.shape)&&(n.currObjType.shape="crop-"+e,this.drawNewSelection(e,o,i,r,a))}else this.isCropSelect?this.isCropSelect=!1:(n.notify("crop",{prop:"adjustStraightenForShapes",onPropertyChange:!1,value:{type:"reverse",isInitialRotated:!0}}),n.notify("freehand-draw",{prop:"updateFHDColl",onPropertyChange:!1}),this.renderImage()),"custom"===e&&(n.currObjType.shape=""),this.drawNewSelection(e,o,i,r,a)}},e.prototype.drawNewSelection=function(e,o,i,r,a){var n,s=this.parent,l="crop-"+e.toLowerCase();"crop-custom"===l?""!==s.currObjType.shape&&"crop-custom"!==s.currObjType.shape||(this.drawCustomSelection("crop-custom",o,i,r,a),this.adjToStraighten(),this.updateSelectionInsert(),s.isStraightening&&(this.straightenActObj=t.extend({},s.activeObj,{},!0),this.straightenInitZoom=s.transform.zoomFactor)):"crop-canvas"===l?(s.upperCanvas.style.display="block",s.notify("selection",{prop:"setDragCanvas",value:{bool:!0}})):(s.currObjType.isCustomCrop=!1,s.currObjType.shape=l,r&&a?n={startX:o,startY:i,endX:o+r,endY:i+a,width:r,height:a}:r&&"crop-circle"===l&&(n={startX:o,startY:i,endX:o+r,endY:i+r,width:r,height:r}),s.activeObj.shape=l,this.updateSelectionInsert(n))},e.prototype.updateSelectionInsert=function(e){var t=this.parent,o=t.activeObj.activePoint,i={shapeSettingsObj:{}};t.notify("selection",{prop:"updatePrevShapeSettings",onPropertyChange:!1,value:{obj:i}});var r={type:t.getSelectionType(i.shapeSettingsObj.type),startX:i.shapeSettingsObj.startX,startY:i.shapeSettingsObj.startY,width:i.shapeSettingsObj.width,height:i.shapeSettingsObj.height},a={action:"insert",previousSelectionSettings:r,currentSelectionSettings:r};t.trigger("selectionChanging",a),t.editCompleteArgs=a,t.notify("shape",{prop:"updSelChangeEventArgs",onPropertyChange:!1,value:{selectionSettings:a.currentSelectionSettings}}),"Custom"===a.currentSelectionSettings.type?this.drawObject("duplicate",t.activeObj,null,null,!0):(0===o.startX&&0===o.startY&&0===o.width&&0===o.height||(e={startX:o.startX,startY:o.startY,endX:o.endX,endY:o.endY,width:o.width,height:o.height}),this.drawObject("duplicate",null,!0,e))},e.prototype.drawCustomSelection=function(e,o,i,r,a){var n=this.parent,s=n.activeObj.activePoint;if(n.currObjType.isCustomCrop=!0,this.upperContext.clearRect(0,0,n.upperCanvas.width,n.upperCanvas.height),n.currObjType.shape=n.activeObj.shape=e.toLowerCase(),t.isNullOrUndefined(o)||t.isNullOrUndefined(i)||t.isNullOrUndefined(r)||t.isNullOrUndefined(a))if(r&&a){var l=n.img,p=l.destLeft,h=l.destTop,d=l.destWidth,c=l.destHeight;s.width=r,s.height=a,s.startX=p+(d/2-r/2),s.startY=h+(c/2-a/2)}else{if(t.isNullOrUndefined(n.transform.zoomFactor)||0===n.transform.zoomFactor){var u=n.img,v=u.destLeft,g=u.destTop,f=u.destWidth,C=u.destHeight,b=n.lowerCanvas.width,m=n.lowerCanvas.height,y=s;v>=0&&g>=0?(y.startX=v,y.startY=g,y.endX=v+f,y.endY=g+C):v>=0?(y.startX=v,y.startY=7.5,y.endX=v+f,y.endY=m-15):g>=0?(y.startX=7.5,y.startY=g,y.endX=b-15,y.endY=g+C):(y.startX=7.5,y.startY=7.5,y.endX=b-15,y.endY=m-15)}else{var P=n.img,j=P.destLeft,x=P.destTop,w=P.destWidth,O=P.destHeight,S=n.lowerCanvas.width,T=n.lowerCanvas.height,k=s;k.startX=Math.max(j>0?j:7.5,j),k.startY=Math.max(x>0?x:7.5,x),k.endX=Math.min(j+w+15<S?j+w-15:S-15,j+w),k.endY=Math.min(x+O+15<T?x+O-15:T-15,x+O)}var F=n.img,p=F.destLeft,h=F.destTop,d=F.destWidth,c=F.destHeight,I=n.lowerCanvas.clientWidth,A=n.lowerCanvas.clientHeight,z=s;if(z.startX=Math.max(z.startX,p),z.startY=Math.max(z.startY,h),z.endX=Math.min(z.endX,p+d),z.endY=Math.min(z.endY,h+c),n.transform.straighten>0?(this.imgCanvasPoints[0].x>z.startX&&(z.startX=this.imgCanvasPoints[0].x),this.imgCanvasPoints[0].y>z.startY&&(z.startY=this.imgCanvasPoints[0].y),this.imgCanvasPoints[2].x<z.endX&&(z.endX=this.imgCanvasPoints[2].x),this.imgCanvasPoints[2].y<z.endY&&(z.endY=this.imgCanvasPoints[2].x)):n.transform.straighten<0&&(this.imgCanvasPoints[3].x>z.startX&&(z.startX=this.imgCanvasPoints[3].x),this.imgCanvasPoints[3].y<z.startY&&(z.startY=this.imgCanvasPoints[3].y),this.imgCanvasPoints[1].x<z.endX&&(z.endX=this.imgCanvasPoints[1].x),this.imgCanvasPoints[1].y>z.endY&&(z.endY=this.imgCanvasPoints[1].x)),z.startX===p&&p+d>I&&(z.endX=I-15),z.startY===h&&h+c>A&&(z.endY=A-15),n.activeObj.activePoint.startX>n.activeObj.activePoint.endX){R=n.activeObj.activePoint.startX;n.activeObj.activePoint.startX=n.activeObj.activePoint.endX,n.activeObj.activePoint.endX=R}if(n.activeObj.activePoint.startY>n.activeObj.activePoint.endY){var R=n.activeObj.activePoint.startY;n.activeObj.activePoint.startY=n.activeObj.activePoint.endY,n.activeObj.activePoint.endY=R}n.activeObj=this.updateWidthHeight(n.activeObj),this.updateActiveObject(s,n.activeObj),this.adjActObj()}else s.startX=o,s.startY=i,s.endX=o+r,s.endY=i+a,s.width=r,s.height=a;this.updateSelectionInsert()},e.prototype.adjToStraighten=function(){var e=this.parent;if(0!==e.transform.straighten&&e.isStraightening){var t=e.activeObj.activePoint;t.startX+=7.5,t.startY+=7.5,t.endX-=7.5,t.endY-=7.5,e.activeObj=this.updateWidthHeight(e.activeObj)}},e.prototype.adjActObj=function(){var e=this.parent;if(0!==e.transform.straighten)for(var o=e.activeObj.activePoint,i=t.extend({},o,{},!0),r=0;;){r++;var a={isIntersect:null,arr:null};if(e.notify("draw",{prop:"updateImgCanvasPoints",onPropertyChange:!1}),e.notify("draw",{prop:"isLinesIntersect",onPropertyChange:!1,value:{obj:a}}),a.arr[0]||a.arr[1]||a.arr[2]||a.arr[3]||100===r){o=t.extend({},i,{},!0);break}i=t.extend({},o,{},!0),o.startX-=5,o.endX+=5,o.width=o.endX-o.startX,this.updateActiveObject(o,e.activeObj)}},e.prototype.callUpdateCurrTransState=function(){var e=this.parent,o=t.extend([],e.objColl,[],!0),i=t.extend({},e.activeObj,{},!0);e.objColl=[],e.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),this.isRotateZoom=!0,this.updateCurrTransState("initial"),this.lowerContext.clearRect(0,0,e.lowerCanvas.width,e.lowerCanvas.height),0===e.transform.degree&&e.rotateFlipColl.length>0&&(e.img.destLeft+=e.panPoint.totalPannedPoint.x,e.img.destTop+=e.panPoint.totalPannedPoint.y),e.img.destLeft+=e.panPoint.totalPannedInternalPoint.x,e.img.destTop+=e.panPoint.totalPannedInternalPoint.y;var r=this.lowerContext.filter;0===e.transform.degree&&e.notify("transform",{prop:"setDestPointsForFlipState",onPropertyChange:!1}),this.drawImage(),this.updateCurrTransState("reverse"),0===e.transform.degree&&e.rotateFlipColl.length>0&&(e.img.destLeft+=e.panPoint.totalPannedPoint.x,e.img.destTop+=e.panPoint.totalPannedPoint.y),this.isRotateZoom=!1,e.objColl=o;var a=e.togglePen;e.togglePen=!1,this.lowerContext.filter="none";var n={penStrokeWidth:null};e.notify("freehand-draw",{prop:"getPenStrokeWidth",onPropertyChange:!1,value:{obj:n}}),e.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"iterate",pen:"iterate",isPreventApply:null}}),e.notify("freehand-draw",{prop:"setPenStrokeWidth",onPropertyChange:!1,value:{value:n.penStrokeWidth}}),e.img.destLeft+=e.panPoint.totalPannedInternalPoint.x,e.img.destTop+=e.panPoint.totalPannedInternalPoint.y,e.img.destLeft-=e.panPoint.totalPannedInternalPoint.x,e.img.destTop-=e.panPoint.totalPannedInternalPoint.y,e.togglePen=a,this.lowerContext.filter=r,e.activeObj=i},e.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}},e.prototype.setClientTransDim=function(e){var o=this.parent;if(o.transform.degree%90==0&&o.transform.degree%180!=0){o.img.destLeft=(o.lowerCanvas.clientWidth-o.img.destHeight)/2,o.img.destTop=(o.lowerCanvas.clientHeight-o.img.destWidth+1)/2;var i=o.img.destWidth;o.img.destWidth=o.img.destHeight,o.img.destHeight=i}else t.isNullOrUndefined(e)&&(o.img.destLeft=(o.lowerCanvas.clientWidth-o.img.destWidth)/2,o.img.destTop=(o.lowerCanvas.clientHeight-o.img.destHeight+1)/2)},e.prototype.redrawImgWithObj=function(){var e=this.parent,o={canvasFilter:e.canvasFilter};if(this.lowerContext.filter=o.canvasFilter,0!==e.rotateFlipColl.length){var i=t.extend({},e.panPoint.totalPannedInternalPoint,{},!0),r={startX:e.img.destLeft,startY:e.img.destTop,width:e.img.destWidth,height:e.img.destHeight};this.callUpdateCurrTransState(),e.panPoint.totalPannedInternalPoint=i,e.img.destLeft=r.startX,e.img.destTop=r.startY,e.img.destWidth=r.width,e.img.destHeight=r.height}else this.callUpdateCurrTransState();e.isCircleCrop&&e.notify("crop",{prop:"cropCircle",onPropertyChange:!1,value:{context:this.lowerContext,isSave:null,isFlip:null}})},e.prototype.setCurrentObj=function(e,o,i){var r=this.parent,a=!!e;a||(r.cropObj.aspectWidth=r.aspectWidth,r.cropObj.aspectHeight=r.aspectHeight,r.cropObj.frame=r.frameObj.type),e=e||r.cropObj,r.transform.cropZoomFactor=e.cropZoom,r.transform.defaultZoomFactor=e.defaultZoom,this.straightenInitZoom=e.straightenZoom,a?e.activeObj.shape&&"crop"===e.activeObj.shape.split("-")[0]?r.transform.zoomFactor=e.cropZoom:r.transform.zoomFactor=e.defaultZoom:r.transform.zoomFactor=e.cropZoom,r.setProperties({zoomSettings:{zoomFactor:e.zoomFactor}},!0),r.notify("transform",{prop:"setPreviousZoomValue",onPropertyChange:!1,value:{previousZoomValue:e.previousZoomValue}}),r.panPoint.totalPannedPoint=t.extend({},e.totalPannedPoint,{},!0),r.panPoint.totalPannedClientPoint=t.extend({},e.totalPannedClientPoint,{},!0),r.panPoint.totalPannedInternalPoint=t.extend({},e.totalPannedInternalPoint,{},!0);var n=t.extend({},e.tempFlipPanPoint,{},!0);r.notify("crop",{prop:"setTempFlipPanPoint",onPropertyChange:!1,value:{point:n}}),r.rotateFlipColl=t.extend([],e.rotateFlipColl,[],!0),r.transform.degree=e.degree,r.frameObj.type=e.frame,r.transform.currFlipState=e.currFlipState,r.notify("filter",{prop:"setAdjustmentLevel",onPropertyChange:!1,value:{adjustmentLevel:e.adjustmentLevel}}),r.notify("filter",{prop:"setTempAdjVal"}),r.currentFilter=e.currentFilter,r.notify("filter",{prop:"setTempFilVal"}),(r.transform.straighten!==e.straighten||o)&&(r.transform.straighten=e.straighten,r.straightenBaseImageCanvas()),r.img={destLeft:e.destPoints.startX,destTop:e.destPoints.startY,destWidth:e.destPoints.width,destHeight:e.destPoints.height,srcLeft:e.srcPoints.startX,srcTop:e.srcPoints.startY,srcWidth:e.srcPoints.width,srcHeight:e.srcPoints.height},r.aspectWidth=e.aspectWidth,r.aspectHeight=e.aspectHeight,e.afterCropActions&&(r.afterCropActions=e.afterCropActions),this.lowerContext.filter=e.filter,r.notify("filter",{prop:"setBrightnessAdjusted",onPropertyChange:!1,value:{isBrightnessAdjusted:e.isBrightAdjust}}),r.notify("draw",{prop:"imageBackgroundColor",onPropertyChange:!1,value:{color:e.bgColor}});var s,l=r.isCircleCrop;t.isNullOrUndefined(r.currSelectionPoint)?s=null:(s=t.extend({},r.currSelectionPoint,{},!0),r.currSelectionPoint=null),r.isCircleCrop=!1,i&&(r.frameObj.type="none"),this.drawCropSelectionImage(e,!1),0!==r.transform.degree&&(""===r.transform.currFlipState?r.notify("transform",{prop:"rotatePan",onPropertyChange:!1,value:{isCropSelection:null,isDefaultZoom:null}}):r.notify("transform",{prop:"drawPannedImage",value:{xDiff:0,yDiff:0}}),r.img.destLeft=e.destPoints.startX,r.img.destTop=e.destPoints.startY,r.panPoint.totalPannedClientPoint=t.extend({},e.totalPannedClientPoint,{},!0),r.panPoint.totalPannedInternalPoint=t.extend({},e.totalPannedInternalPoint,{},!0)),r.activeObj=t.extend({},e.activeObj,{},!0),this.upperContext.clearRect(0,0,r.upperCanvas.width,r.upperCanvas.height),0!==r.activeObj.activePoint.width&&0!==r.activeObj.activePoint.height&&this.drawObject("duplicate",null,null,null,!0);var p=t.extend({},e.activeObj,{},!0),h=!1;if(r.afterCropActions.length>0){var d={collection:r.afterCropActions};r.notify("shape",{prop:"alignRotateFlipColl",onPropertyChange:!1,value:{collection:r.afterCropActions,isRotateFlipCollection:null,obj:d}}),r.afterCropActions=d.collection}var c=t.extend([],r.afterCropActions,[],!0);if(!a&&c.length>0){h=!0;for(var u=0,v=c.length;u<v;u++)"horizontalflip"!==c[u]&&"verticalflip"!==c[u]||(r.activeObj=t.extend({},s,{},!0),this.rotatedFlipCropSel=!0),r.notify("transform",{prop:"updateTransform",onPropertyChange:!1,value:{text:c[u]}});p=t.extend({},r.activeObj,{},!0),this.resetPanPoints(),r.activeObj=p,this.upperContext.clearRect(0,0,r.upperCanvas.width,r.upperCanvas.height),0!==r.activeObj.activePoint.width&&0!==r.activeObj.activePoint.height&&this.drawObject("duplicate",null,null,null,!0),e.degree!==r.transform.degree&&(r.transform.cropZoomFactor=null,r.transform.zoomFactor=0),r.notify("freehand-draw",{prop:"updateFHDColl",onPropertyChange:!1}),this.rotatedFlipCropSel&&(this.rotatedFlipCropSel=!1)}r.afterCropActions=c,this.isCancelAction||h||(r.notify("freehand-draw",{prop:"updateFHDColl",onPropertyChange:!1}),r.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"zoom",pen:"zoom",isPreventApply:null}}),r.img.destLeft=e.destPoints.startX,r.img.destTop=e.destPoints.startY),r.activeObj=p,r.isCircleCrop=l,t.isNullOrUndefined(s)?r.currSelectionPoint=null:(r.currSelectionPoint=t.extend({},s,{},!0),r.currSelectionPoint&&t.isNullOrUndefined(r.currSelectionPoint.shape)&&(r.currSelectionPoint=null))},e.prototype.drawCropSelectionImage=function(e,o){var i=this.parent,r=this.lowerContext.filter;i.clearContext(this.lowerContext),i.clearContext(this.upperContext),this.lowerContext.setTransform(1,0,0,1,0,0),o?this.updateCurrTransState("initial"):this.setTransformColl(this.lowerContext,"initial"),i.notify("transform",{prop:"setDestPointsForFlipState",onPropertyChange:!1}),this.drawImage(),o?this.updateCurrTransState("reverse"):this.setTransformColl(this.lowerContext,"reverse"),i.img.destLeft=i.cropObj.destPoints.startX,i.img.destTop=i.cropObj.destPoints.startY;var a=t.extend({},e.activeObj,{},!0);if(this.lowerContext.filter="none",i.img={destLeft:e.destPoints.startX,destTop:e.destPoints.startY,destWidth:e.destPoints.width,destHeight:e.destPoints.height,srcLeft:e.srcPoints.startX,srcTop:e.srcPoints.startY,srcWidth:e.srcPoints.width,srcHeight:e.srcPoints.height},0!==e.activeObj.activePoint.width&&0!==e.activeObj.activePoint.height){var n={startX:i.img.destLeft,startY:i.img.destTop,width:i.img.destWidth,height:i.img.destHeight};i.img.destLeft=e.activeObj.activePoint.startX,i.img.destTop=e.activeObj.activePoint.startY,i.img.destWidth=e.activeObj.activePoint.width,i.img.destHeight=e.activeObj.activePoint.height,i.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"zoom",pen:"zoom",isPreventApply:null}}),i.img.destLeft=n.startX,i.img.destTop=n.startY,i.img.destWidth=n.width,i.img.destHeight=n.height}i.activeObj=a,this.lowerContext.filter=r},e.prototype.performPointZoom=function(e,t,o,i,r){var a=this.parent,n=a.img,s=n.destLeft,l=n.destTop,p=n.destWidth,h=n.destHeight,d=!1;a.activeObj.shape&&a.activeObj.shape.indexOf("crop-")>-1&&(d=!0),a.element.querySelector(".e-contextual-toolbar-wrapper")&&!d&&(a.element.querySelector(".e-contextual-toolbar-wrapper").classList.contains("e-hide")||(a.okBtn(),a.element.querySelector(".e-contextual-toolbar-wrapper").classList.add("e-hide")));var c=(e-s)/p,u=(t-l)/h,v=a.isUndoRedo;a.isUndoRedo=!0,a.setProperties({zoomSettings:{zoomPoint:{x:e,y:t}}},!0);var g=r||("zoomIn"===o?.1:-.1);a.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:g,zoomPoint:null,isResize:i}}),a.isUndoRedo=v,this.panToPoint(e,t,c,u)},e.prototype.panToPoint=function(e,o,i,r){var a=this.parent;if(a.transform.zoomFactor>0){var n=a.img.destLeft,s=a.img.destTop,l=t.extend({},a.activeObj,{},!0);if(0===a.transform.degree)a.img.destLeft=e-i*a.img.destWidth,a.img.destTop=o-r*a.img.destHeight,this.drawZoomPanImage(a.img.destLeft-n,a.img.destTop-s);else{var p=a.isCropTab;a.isCropTab=!0;var h=t.extend([],a.objColl,[],!0),d=t.extend([],a.pointColl,[],!0),c={straightenPoint:null};a.notify("freehand-draw",{prop:"getStraightenPoint",onPropertyChange:!1,value:{obj:c}}),a.objColl=[],a.pointColl=[],a.freehandCounter=0,a.notify("freehand-draw",{prop:"setStraightenPoint",onPropertyChange:!1,value:{x:null,y:null,ratioX:null,ratioY:null}});var u={selPointColl:null};a.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:u}});var v=u.selPointColl;a.notify("freehand-draw",{prop:"setSelPointColl",onPropertyChange:!1,value:{obj:{selPointColl:[]}}}),a.panPoint.currentPannedPoint={x:e-i*a.img.destWidth-n,y:o-r*a.img.destHeight-s},a.notify("transform",{prop:"rotatePan",onPropertyChange:!1,value:{isCropSelection:null,isDefaultZoom:null}}),a.isCropTab=p,a.objColl=h,a.pointColl=d,a.freehandCounter=a.pointColl.length,c.straightenPoint.x&&c.straightenPoint.y&&a.notify("freehand-draw",{prop:"setStraightenPoint",onPropertyChange:!1,value:{x:c.straightenPoint.x,y:c.straightenPoint.y,ratioX:c.straightenPoint.ratioX,ratioY:c.straightenPoint.ratioY}}),a.notify("freehand-draw",{prop:"setSelPointColl",onPropertyChange:!1,value:{obj:{selPointColl:v}}}),a.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"pan",pen:"pan",x:a.panPoint.currentPannedPoint.x,y:a.panPoint.currentPannedPoint.y,panRegion:""}})}this.adjustPanning(l);for(var g=!1,f=0;f<a.objColl.length;f++)if(JSON.stringify(l.activePoint)===JSON.stringify(a.objColl[f].activePoint)){g=!0;break}g||(a.activeObj=l),0!==a.activeObj.activePoint.width&&0!==a.activeObj.activePoint.height&&this.drawObject("duplicate",null,null,null,!0)}},e.prototype.adjustPanning=function(e){var o=this.parent,i=e.activePoint,r=i.startX,a=i.startY,n=i.width,s=i.height;if(0!==n&&0!==s){var l=o.img,p=l.destLeft,h=l.destTop,d=l.destWidth,c=l.destHeight,u={x:0,y:0};if(p>r?u.x=p-r:p+d<r+n&&(u.x=p+d-(r+n)),h>a?u.y=h-a:h+c<a+s&&(u.y=h+c-(a+s)),0===o.transform.degree)o.img.destLeft-=u.x,o.img.destTop-=u.y,this.drawZoomPanImage(o.img.destLeft-p,o.img.destTop-h);else{var v=o.isCropTab;o.isCropTab=!0;var g=t.extend([],o.objColl,[],!0),f=t.extend([],o.pointColl,[],!0);o.objColl=[],o.pointColl=[],o.freehandCounter=0;var C={selPointColl:null};o.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:C}});var b=C.selPointColl;o.notify("freehand-draw",{prop:"setSelPointColl",onPropertyChange:!1,value:{obj:{selPointColl:[]}}}),o.img.destLeft-=u.x,o.img.destTop-=u.y,o.panPoint.currentPannedPoint={x:o.img.destLeft-p,y:o.img.destTop-h},o.notify("transform",{prop:"rotatePan",onPropertyChange:!1,value:{isCropSelection:null,isDefaultZoom:null}}),o.isCropTab=v,o.objColl=g,o.pointColl=f,o.freehandCounter=o.pointColl.length,o.notify("freehand-draw",{prop:"setSelPointColl",onPropertyChange:!1,value:{obj:{selPointColl:b}}}),o.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"pan",pen:"pan",x:o.panPoint.currentPannedPoint.x,y:o.panPoint.currentPannedPoint.y,panRegion:""}})}}},e.prototype.panToSel=function(){var e=this.parent,o=t.extend({},e.activeObj,{},!0),i=o.activePoint,r=i.startX,a=i.startY,n=i.width,s=i.height;this.allowRedactStraighten=!0;var l={straightenPoint:null};if(e.notify("freehand-draw",{prop:"getStraightenPoint",onPropertyChange:!1,value:{obj:l}}),l.straightenPoint.x&&l.straightenPoint.y){var p=r+n/2-l.straightenPoint.x,h=a+s/2-l.straightenPoint.y;0===e.transform.degree?(e.img.destLeft+=p,e.img.destTop+=h,e.notify("transform",{prop:"drawPannImage",value:{point:{x:p,y:h}}})):(e.panPoint.currentPannedPoint={x:p,y:h},e.notify("transform",{prop:"drawPannedImage",value:{xDiff:p,yDiff:h}}),e.panPoint.currentPannedPoint={x:0,y:0},e.notify("transform",{prop:"setTempPanMove",value:{point:null}})),e.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate",obj:o}});var d=e.img,c=d.destLeft,u=d.destTop,v=d.destWidth,g=d.destHeight,f=this.imgCanvasPoints;f.forEach(function(e){e.x=e.ratioX*v+c,e.y=e.ratioY*g+u}),this.imgCanvasPoints=f;var C=0;if(3===e.transform.straighten&&!this.preventStraightening){this.preventStraightening=!0;var b=e.prevStraightenedDegree;e.prevStraightenedDegree=e.transform.straighten,e.setStraighten(0),e.setStraighten(3),e.prevStraightenedDegree=b,this.preventStraightening=!1}for(;this.isLinesIntersect()&&0!==e.transform.straighten&&360!==e.transform.straighten&&C<100;)C++,this.performPointZoom(e.activeObj.activePoint.startX+e.activeObj.activePoint.width/2,e.activeObj.activePoint.startY+e.activeObj.activePoint.height/2,"zoomIn",!1,.025),this.updateImgCanvasPoints()}},e.prototype.drawZoomPanImage=function(e,t){var o=this.parent;o.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"pan",pen:"pan",x:e,y:t,panRegion:""}}),this.renderImage(!0);var i={width:0,height:0};o.notify("transform",{prop:"calcMaxDimension",onPropertyChange:!1,value:{width:o.img.srcWidth,height:o.img.srcHeight,obj:i,isImgShape:null}});var r=i;r.width+=r.width*o.transform.zoomFactor,r.height+=r.height*o.transform.zoomFactor,o.panPoint.totalPannedPoint.x+=e,o.panPoint.totalPannedPoint.y+=t,o.notify("crop",{prop:"setTempFlipPanPoint",onPropertyChange:!1,value:{point:{x:0,y:0}}})},e.prototype.openNewImage=function(){var e=this,i=this.parent,r=i.element.id,a=i.inMemoryCanvas.getContext("2d");o.showSpinner(i.element),i.element.style.opacity="0.5";var n=document.querySelector("#"+r+"_currPos");n&&(n.style.display="none");var s={defToolbarItems:null};if(i.notify("toolbar",{prop:"getDefToolbarItems",value:{obj:s}}),0===s.defToolbarItems.length&&t.isNullOrUndefined(document.getElementById(r+"_toolbar"))&&i.element.querySelector("#"+r+"_toolbarArea")){var l=i.element.querySelector("#"+r+"_toolbarArea").clientHeight;i.notify("toolbar",{prop:"setToolbarHeight",value:{height:l}})}if(i.reset(),i.update(),i.transform.degree=0,i.transform.zoomFactor=0,i.isImageLoaded=!1,i.currSelectionPoint=null,"string"===typeof this.openURL){var p=this.openURL.split(".");if(p.length>1?(p=p[p.length-2].split("/"),this.fileName=p[p.length-1]):this.fileName="ImageEditor",this.fileType=this.getFileExtensionFromURL(this.openURL),this.fileType){this.fileType=i.toPascalCase(this.fileType);var h=this.fileType.toLowerCase();"jpg"!==h&&"jpeg"!==h||(this.fileType="Jpeg",h="jpeg"),"jpeg"!==h&&"png"!==h&&"svg"!==h&&(this.fileType=null)}this.imageOnLoad(this.openURL),"string"==typeof this.openURL&&-1!==this.openURL.indexOf("localhost")||this.getImageSizeFromURL(this.openURL.toString(),function(t){null!==t&&e.parent.notify("toolbar",{prop:"setInitialSize",value:{value:+t}})})}else this.fileName="ImageEditor",this.fileType=null,i.lowerCanvas=document.querySelector("#"+r+"_lowerCanvas"),i.upperCanvas=document.querySelector("#"+r+"_upperCanvas"),this.lowerContext=i.lowerCanvas.getContext("2d"),this.upperContext=i.upperCanvas.getContext("2d"),i.clearContext(this.lowerContext),i.clearContext(this.upperContext),i.clearContext(a),i.inMemoryCanvas.width=this.openURL.width,i.inMemoryCanvas.height=this.openURL.height,a.putImageData(this.openURL,0,0),i.baseImg.src=i.inMemoryCanvas.toDataURL()},e.prototype.getImageSizeFromURL=function(e,t){return l(this,void 0,void 0,function(){var o,i,r,a;return p(this,function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),[4,fetch(e,{method:"HEAD"})];case 1:return o=n.sent(),i=parseInt(o.headers.get("content-length")||"0",10),r=i,t(r),[3,3];case 2:return a=n.sent(),console.log(a.message),[3,3];case 3:return[2]}})})},e.prototype.dlgBtnClick=function(){this.parent.export(),this.applyDialogOption()},e.prototype.dlgCloseBtnClick=function(){this.applyDialogOption()},e.prototype.applyDialogOption=function(){var e=this.parent;this.isFileChanged?(e.isImageLoaded=this.isFileChanged=!1,e.reset(),this.checkToolbarTemplate(this.inputElem,this.openURL)):(this.reset(),this.openNewImage()),t.getComponent(document.getElementById(e.element.id+"_dialog"),"dialog").destroy(),this.isImageEdited=!1},e.prototype.showDialogPopup=function(){var e=this.parent,t={key:"ConfirmDialogHeader"};e.notify("toolbar",{prop:"getLocaleText",onPropertyChange:!1,value:{obj:t}});var i={key:"ConfirmDialogContent"};e.notify("toolbar",{prop:"getLocaleText",onPropertyChange:!1,value:{obj:i}});var r={key:"Yes"};e.notify("toolbar",{prop:"getLocaleText",onPropertyChange:!1,value:{obj:r}});var a={key:"No"};e.notify("toolbar",{prop:"getLocaleText",onPropertyChange:!1,value:{obj:a}}),e.element.querySelector("#"+e.element.id+"_dialog").style.display="block",new o.Dialog({header:t.value,closeOnEscape:!0,content:"<span>"+i.value+"</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:a.value,iconCss:"e-icons e-close"}},{click:this.dlgBtnClick.bind(this),buttonModel:{content:r.value,isPrimary:!0,iconCss:"e-icons e-check"}}]}).appendTo("#"+e.element.id+"_dialog")},e.prototype.restoreOldImage=function(){this.parent.isImageLoaded?(this.reset(),this.openNewImage()):this.openNewImage()},e.prototype.open=function(e){var t=document.getElementById(this.parent.element.id+"_dropArea");t&&(t.style.display="none"),this.parent.disabled||(this.openURL=e,this.restoreOldImage())},e.prototype.getInitialLoaded=function(e){e.isInitialLoaded=this.isInitialLoading},e.prototype.getFileExtensionFromURL=function(e){var t=e.lastIndexOf(".");return-1!==t?e.slice(t+1).toLowerCase():-1!==e.indexOf("base64")?e.slice(e.indexOf("/")+1,e.indexOf(";")).toLowerCase():null},e.prototype.fileSelect=function(e,t){var i=this.parent,r=document.getElementById(i.element.id+"_dropArea");if(r&&(r.style.display="none"),!i.disabled){var a=void 0,n=void 0;t.target?n=a=t.target.files[0]:a=n=t.filesData[0].rawFile;var s=void 0;if(n.name){var l=n.name.split(".");s=l[l.length-1].toLowerCase()}if(s&&-1===["jpg","jpeg","png","svg"].indexOf(s))return void this.errorLoading();if(o.showSpinner(i.element),i.element.style.opacity="0.5",this.inputElem=e,s=n.name&&n.name.split(".")[1]){var p=i.toPascalCase(s);this.fileType="JPG"===p||"Jpg"===p?"Jpeg":p}else this.fileType=null;var h=window.URL.createObjectURL(a);this.openURL=h,i.isImageLoaded&&!i.isChangesSaved&&(this.isImageEdited||i.pointColl.length>0||i.objColl.length>0)?(this.isFileChanged=!0,this.showDialogPopup()):this.checkToolbarTemplate(e,h)}},e.prototype.checkToolbarTemplate=function(e,o){var i=this.parent;t.isNullOrUndefined(i.toolbarTemplate)&&(i.reset(),i.update()),this.fileName=e.value.split("\\")[e.value.split("\\").length-1],this.fileName=this.fileName.split(".")[0],this.imageOnLoad(o.toString()),e.value=""},e.prototype.moveToSelectionRange=function(e,o){var i=this.parent;if(i.activeObj.shape){for(var r=!1,a=0,n=i.rotateFlipColl.length;a<n;a++){var s=i.rotateFlipColl[a];if(90===s||-90===s){r=!0;break}}if(r){if(0===i.transform.degree)return;var l=i.transform.zoomFactor;i.objColl.push(i.activeObj),i.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1});var p=i.objColl[i.objColl.length-1];if("rotateleft"===e||"rotateright"===e)if(i.transform.degree%90==0&&i.transform.degree%180!=0)if(p.activePoint.width<o.activePoint.height)for(a=2;a<i.zoomSettings.maxZoomFactor;a++){if(p.activePoint.width>=o.activePoint.height||this.isSelectionBiggerThanCanvas(p)||this.isSelectionOutsideCanvas(p)){t.isNullOrUndefined(l)||i.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:-.1,zoomPoint:null},isResize:null});break}l+=.1,i.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:l,zoomPoint:null},isResize:null})}else for(a=2;a<i.zoomSettings.maxZoomFactor;a++){if(p.activePoint.width>=o.activePoint.height||this.isSelectionBiggerThanCanvas(p)||this.isSelectionOutsideCanvas(p)){t.isNullOrUndefined(l)||i.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:.1,zoomPoint:null,isResize:null}});break}l-=.1,i.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:l,zoomPoint:null},isResize:null})}else if(p.activePoint.height<o.activePoint.width)for(a=2;a<i.zoomSettings.maxZoomFactor;a++){if(p.activePoint.height>=o.activePoint.width||this.isSelectionBiggerThanCanvas(p)||this.isSelectionOutsideCanvas(p)){t.isNullOrUndefined(l)||i.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:-.1,zoomPoint:null},isResize:null});break}l+=.1,i.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:l,zoomPoint:null},isResize:null})}else for(a=2;a<i.zoomSettings.maxZoomFactor;a++){if(p.activePoint.height>=o.activePoint.width||this.isSelectionBiggerThanCanvas(p)||this.isSelectionOutsideCanvas(p)){t.isNullOrUndefined(l)||i.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:.1,zoomPoint:null},isResize:null});break}l-=.1,i.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:l,zoomPoint:null},isResize:null})}var h=i.lowerCanvas.clientWidth/2-(p.activePoint.startX+p.activePoint.width/2),d=(i.lowerCanvas.clientHeight+1)/2-(p.activePoint.startY+p.activePoint.height/2);t.isNullOrUndefined(i.activeObj.shape)&&(i.activeObj=t.extend({},o,{},!0)),0===i.transform.degree?(i.img.destLeft+=h,i.img.destTop+=d,i.notify("transform",{prop:"drawPannImage",value:{point:{x:h,y:d}}})):(i.panPoint.currentPannedPoint={x:h,y:d},i.notify("transform",{prop:"drawPannedImage",value:{xDiff:h,yDiff:d}}),i.panPoint.currentPannedPoint={x:0,y:0}),i.notify("transform",{prop:"setTempPanMove",onPropertyChange:!1,value:{point:null}}),i.activeObj=t.extend({},i.objColl[i.objColl.length-1]),i.objColl.pop(),i.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate",obj:i.activeObj}})}}},e.prototype.isSelectionBiggerThanCanvas=function(e){var t=!1,o=this.parent,i=e.activePoint,r=i.startX,a=i.startY,n=i.endX,s=i.endY,l=o.img,p=l.destLeft,h=l.destTop,d=l.destWidth,c=l.destHeight;return(r<=p||a<=h||n>=p+d||s>=h+c)&&(t=!0),t},e.prototype.isSelectionOutsideCanvas=function(e){var t=!1,o=this.parent;return(e.activePoint.height<o.lowerCanvas.height-o.toolbarHeight||e.activePoint.width<o.lowerCanvas.width)&&(t=!0),t},e.prototype.downScaleImgCanvas=function(e,o,i,r){var a=this.parent,n=o?a.activeObj.imageCanvas:a.baseImgCanvas,s=o?a.activeObj.imageElement:a.baseImg,l=o?a.activeObj.activePoint.width:a.img.destWidth,p=o?a.activeObj.activePoint.height:a.img.destHeight,h={width:0,height:0};if(a.transform.degree%90==0&&a.transform.degree%180!=0?a.notify("transform",{prop:"calcMaxDimension",onPropertyChange:!1,value:{width:s.height,height:s.width,obj:h,isImgShape:o}}):a.notify("transform",{prop:"calcMaxDimension",onPropertyChange:!1,value:{width:s.width,height:s.height,obj:h,isImgShape:o}}),o||a.allowDownScale&&!a.isCropTab&&!a.isCropToolbar&&0!==s.width&&0!==s.height&&.75*h.width>l&&.75*h.height>p){var d=a.createElement("canvas",{id:a.element.id+"_downScaleCanvas",attrs:{name:"canvasImage"}});d.width=o?s.width:a.img.srcWidth,d.height=o?s.height:a.img.srcHeight,o?d.getContext("2d").drawImage(s,0,0,d.width,d.height):(""!==this.imageBackgroundColor&&(e.fillStyle=this.imageBackgroundColor,e.fillRect(a.img.destLeft,a.img.destTop,a.img.destWidth,a.img.destHeight)),d.getContext("2d").drawImage(n,a.img.srcLeft,a.img.srcTop,a.img.srcWidth,a.img.srcHeight,0,0,d.width,d.height)),(o||this.isDownScale)&&this.downScale(d,l,p,o),o?(e.canvas.width=d.width,e.canvas.height=d.height,i&&r?(e.translate(a.activeObj.imageCanvas.width,0),e.scale(-1,1),e.translate(0,a.activeObj.imageCanvas.height),e.scale(1,-1)):i?(t.isNullOrUndefined(a.activeObj.isHorImageFlip)||!a.activeObj.isHorImageFlip?(a.activeObj.isHorImageFlip=!0,e.translate(a.activeObj.imageCanvas.width,0),e.scale(-1,1)):a.activeObj.isHorImageFlip&&(a.activeObj.isHorImageFlip=!1),a.activeObj.isVerImageFlip&&(e.translate(0,a.activeObj.imageCanvas.height),e.scale(1,-1))):r&&(t.isNullOrUndefined(a.activeObj.isVerImageFlip)||!a.activeObj.isVerImageFlip?(a.activeObj.isVerImageFlip=!0,e.translate(0,a.activeObj.imageCanvas.height),e.scale(1,-1)):a.activeObj.isVerImageFlip&&(a.activeObj.isVerImageFlip=!1),a.activeObj.isHorImageFlip&&(e.translate(a.activeObj.imageCanvas.width,0),e.scale(-1,1))),e.drawImage(d,0,0),e.setTransform(1,0,0,1,0,0)):a.isFinetuning?(e.save(),e.setTransform(1,0,0,1,0,0),e.drawImage(a.inMemoryCanvas,0,0),e.restore()):e.drawImage(d,0,0,d.width,d.height,a.img.destLeft,a.img.destTop,d.width,d.height)}else!t.isNullOrUndefined(o)&&o||0===a.baseImgCanvas.width||0===a.baseImgCanvas.height||(""!==this.imageBackgroundColor&&(e.fillStyle=this.imageBackgroundColor,e.fillRect(a.img.destLeft,a.img.destTop,a.img.destWidth,a.img.destHeight)),e.drawImage(a.baseImgCanvas,a.img.srcLeft,a.img.srcTop,a.img.srcWidth,a.img.srcHeight,a.img.destLeft,a.img.destTop,a.img.destWidth,a.img.destHeight));a.isSafari&&a.notify("filter",{prop:"apply-filter",onPropertyChange:!1,value:{context:e}})},e.prototype.downScale=function(e,t,o,i){var r=this.parent;if(!i||!r.isStraightening){for(var a=e.width,n=e.height,s=a/(t=Math.round(t)),l=n/(o=Math.round(o)),p=Math.ceil(s/2),h=Math.ceil(l/2),d=e.getContext("2d"),c=d.getImageData(0,0,a,n),u=d.createImageData(t,o),v=c.data,g=u.data,f=0;f<o;f++)for(var C=0;C<t;C++){for(var b=4*(C+f*t),m=0,y=0,P=0,j=0,x=0,w=0,O=0,S=(f+.5)*l,T=Math.floor(f*l),k=Math.ceil((f+1)*l),F=T;F<k;F++)for(var I=Math.abs(S-(F+.5))/h,A=(C+.5)*s,z=I*I,R=Math.floor(C*s),D=Math.ceil((C+1)*s),X=R;X<D;X++){var L=Math.abs(A-(X+.5))/p,Y=Math.sqrt(z+L*L);if(!(Y>=1)){var E=4*(X+F*a);O+=(m=2*Y*Y*Y-3*Y*Y+1)*v[E+3],P+=m,j+=(m=m*v[E+3]/250)*v[E],x+=m*v[E+1],w+=m*v[E+2],y+=m}}g[b]=j/y,g[b+1]=x/y,g[b+2]=w/y,g[b+3]=O/P}e.width=i?r.activeObj.activePoint.width:r.lowerCanvas.width,e.height=i?r.activeObj.activePoint.height:r.lowerCanvas.height,d.putImageData(u,0,0)}},e.prototype.drawImgToCtx=function(e,o){var i=this.parent;e.canvas.id!==i.element.id+"_tempCanvas"&&e!==this.upperContext&&t.isNullOrUndefined(o)&&this.downScaleImgCanvas(e,null,null,null)},e.prototype.getFrameColor=function(e,t,o){var i=this.parent.frameObj.color;if(e.gradientColor){var r=t.createLinearGradient(o.startX,o.startY,o.startX+o.width,o.startY+o.height);r.addColorStop(0,e.color),r.addColorStop(1,e.gradientColor),i=r}else i=e.color;return i},e.prototype.applyFrame=function(e,o,i){var r=this.parent;r.frameObj.type=o;var a,n={width:1,height:1},s={startX:r.img.destLeft-e.lineWidth,startY:r.img.destTop-e.lineWidth,width:r.img.destWidth+2*e.lineWidth,height:r.img.destHeight+2*e.lineWidth},l={type:r.frameObj.type,color:r.frameObj.color,size:r.frameObj.size,inset:r.frameObj.inset,offset:r.frameObj.offset/2,radius:r.frameObj.radius,amount:r.frameObj.amount,border:r.frameObj.border,gradientColor:r.frameObj.gradientColor},p=r.transform.zoomFactor;if(e.canvas.id===r.element.id+"_tempCanvas"){var h=e.canvas.width,d=e.canvas.height,c={width:0,height:0};r.notify("crop",{prop:"calcRatio",onPropertyChange:!1,value:{obj:c,dimension:{width:h,height:d}}}),n=c,l.size*=(n.width+n.height)/2,l.inset*=(n.width+n.height)/2,l.offset*=(n.width+n.height)/2,l.radius*=(n.width+n.height)/2,s={startX:0,startY:0,width:e.canvas.width,height:e.canvas.height},r.notify("export",{prop:"updateSaveContext",onPropertyChange:!1,value:{context:e}})}else e===this.upperContext&&r.activeObj.shape?s={startX:r.activeObj.activePoint.startX-e.lineWidth,startY:r.activeObj.activePoint.startY-e.lineWidth,width:r.activeObj.activePoint.width+2*e.lineWidth,height:r.activeObj.activePoint.height+2*e.lineWidth}:t.isNullOrUndefined(i)&&e.clearRect(0,0,e.canvas.width,e.canvas.height);var u=(n.width+n.height)/2*40,v=(n.width+n.height)/2*50;if(e!==this.upperContext&&(l.size+=l.size*p,l.inset+=l.inset*p,l.offset+=l.offset*p,l.radius+=l.radius*p,u+=u*p,v+=v*p),e!==this.upperContext||!r.activeObj.shape||!("mat"===o&&(s.width-2*l.size<0||s.height-2*l.size<0)||"bevel"===o&&(s.width-2*l.size<40||s.height-2*l.size<40)||"inset"===o&&(s.startX+s.width-l.offset-(s.startX+l.offset)<0||s.startY+s.height-l.offset-(s.startY+l.offset)<0)||"hook"===o&&(s.width-2*l.size<50||s.height-2*l.size<50))){var g={bevelFilter:e.filter},f=e.filter;if(r.currSelectionPoint&&"crop-circle"===r.currSelectionPoint.shape||r.isCircleCrop||e===this.lowerContext&&r.isCropTab)this.drawImgToCtx(e,i);else{switch(o){case"none":this.drawImgToCtx(e,i);break;case"mat":for(this.drawImgToCtx(e,i);(s.width-2*l.size<0||s.height-2*l.size<0)&&l.size>0;)l.size-=20;e.filter="none",e.fillStyle=this.getFrameColor(l,e,s),e.beginPath(),e.rect(s.startX,s.startY,s.width,s.height),e.rect(s.startX+l.size,s.startY+l.size,s.width-2*l.size,s.height-2*l.size),e.fill("evenodd"),e.closePath();break;case"bevel":for(e.filter="none",e.fillStyle=this.getFrameColor(l,e,s),e.beginPath(),e.fillRect(s.startX,s.startY,s.width,s.height),e.closePath(),s.startX+=l.size,s.startY+=l.size,s.width-=2*l.size,s.height-=2*l.size;(s.width-2*l.size<40||s.height-2*l.size<40)&&l.size>0;)s.startX-=l.size,s.startY-=l.size,s.width+=2*l.size,s.height+=2*l.size,l.size-=20,s.startX+=l.size,s.startY+=l.size,s.width-=2*l.size,s.height-=2*l.size;e.fillStyle=this.getFrameColor(l,e,s),e.save(),e.beginPath(),e.moveTo(s.startX+u,s.startY),e.lineTo(s.startX+s.width-u,s.startY),e.quadraticCurveTo(s.startX+s.width,s.startY,s.startX+s.width,s.startY+u),e.lineTo(s.startX+s.width,s.startY+s.height-u),e.quadraticCurveTo(s.startX+s.width,s.startY+s.height,s.startX+s.width-u,s.startY+s.height),e.lineTo(s.startX+u,s.startY+s.height),e.quadraticCurveTo(s.startX,s.startY+s.height,s.startX,s.startY+s.height-u),e.lineTo(s.startX,s.startY+u),e.quadraticCurveTo(s.startX,s.startY,s.startX+u,s.startY),e.closePath(),e.clip(),e.filter="none"===f?r.canvasFilter:f,e.canvas.id===r.element.id+"_tempCanvas"?(i=null,e.filter="none",e.drawImage(r.inMemoryCanvas,0,0),e.filter="none"===f?r.canvasFilter:f):(e.clearRect(0,0,e.canvas.width,e.canvas.height),i?(i=null,0!==r.transform.zoomFactor&&(this.isRotateZoom=!0),r.notify("filter",{prop:"getBevelFilter",onPropertyChange:!1,value:{obj:g}}),e.filter=g.bevelFilter,this.updateCurrTransState("initial"),this.drawImgToCtx(e,i),this.updateCurrTransState("reverse"),this.isRotateZoom=!1,r.frameObj.type="none",e.filter="none",r.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:e,shape:"iterate",pen:"iterate",isPreventApply:null}}),r.frameObj.type="bevel",e.filter="none"===f?r.canvasFilter:f):(r.notify("filter",{prop:"getBevelFilter",onPropertyChange:!1,value:{obj:g}}),e.filter=g.bevelFilter,this.drawImgToCtx(e,i))),e.restore();break;case"line":this.drawImgToCtx(e,i),a=e.lineWidth,e.lineWidth=l.size/10;for(var C=0;C<r.frameObj.amount;C++){C>0&&(s.startX+=l.offset,s.startY+=l.offset,s.width-=2*l.offset,s.height-=2*l.offset);var b=s.startY+s.height-l.inset-l.radius,m=s.startY+l.inset+l.radius,y=s.startX+s.width-l.inset-l.radius,P=s.startX+l.inset+l.radius,j=s.startX+l.inset+l.radius,x=s.startX+s.width-l.inset-l.radius,w=s.startY+l.inset+l.radius,O=s.startY+s.height-l.inset-l.radius;b>=m&&y>=P&&j<=x&&w<=O&&(e.filter="none",e.strokeStyle=this.getFrameColor(l,e,s),"dashed"===l.border?e.setLineDash([2.5*e.lineWidth,1.5*e.lineWidth]):"dotted"===l.border&&e.setLineDash([e.lineWidth,e.lineWidth]),e.beginPath(),e.moveTo(s.startX+l.inset+l.radius,s.startY+l.inset),e.lineTo(s.startX+s.width-l.inset-l.radius,s.startY+l.inset),e.arcTo(s.startX+s.width-l.inset,s.startY+l.inset,s.startX+s.width-l.inset,s.startY+l.inset+l.radius,l.radius),e.lineTo(s.startX+s.width-l.inset,s.startY+s.height-l.inset-l.radius),e.arcTo(s.startX+s.width-l.inset,s.startY+s.height-l.inset,s.startX+s.width-l.inset-l.radius,s.startY+s.height-l.inset,l.radius),e.lineTo(s.startX+l.inset+l.radius,s.startY+s.height-l.inset),e.arcTo(s.startX+l.inset,s.startY+s.height-l.inset,s.startX+l.inset,s.startY+s.height-l.inset-l.radius,l.radius),e.lineTo(s.startX+l.inset,s.startY+l.inset+l.radius),e.arcTo(s.startX+l.inset,s.startY+l.inset,s.startX+l.inset+l.radius,s.startY+l.inset,l.radius),e.closePath(),e.stroke(),e.setLineDash([]))}e.lineWidth=a;break;case"inset":this.drawImgToCtx(e,i),e.filter="none",e.strokeStyle=this.getFrameColor(l,e,s),a=e.lineWidth,e.lineWidth=l.size/10,e.beginPath(),e.moveTo(s.startX+l.offset,s.startY+l.inset),e.lineTo(s.startX+s.width-l.offset,s.startY+l.inset),e.moveTo(s.startX+s.width-l.inset,s.startY+l.offset),e.lineTo(s.startX+s.width-l.inset,s.startY+s.height-l.offset),e.moveTo(s.startX+s.width-l.offset,s.startY+s.height-l.inset),e.lineTo(s.startX+l.offset,s.startY+s.height-l.inset),e.moveTo(s.startX+l.inset,s.startY+s.height-l.offset),e.lineTo(s.startX+l.inset,s.startY+l.offset),e.stroke(),e.closePath(),e.lineWidth=a;break;case"hook":this.drawImgToCtx(e,i),e.filter="none",e.strokeStyle=this.getFrameColor(l,e,s),a=e.lineWidth,e.lineWidth=l.size/10,e.beginPath(),e.moveTo(s.startX+l.inset+v,s.startY+l.inset),e.lineTo(s.startX+l.inset,s.startY+l.inset),e.lineTo(s.startX+l.inset,s.startY+l.inset+v),e.moveTo(s.startX+s.width-l.inset-v,s.startY+l.inset),e.lineTo(s.startX+s.width-l.inset,s.startY+l.inset),e.lineTo(s.startX+s.width-l.inset,s.startY+l.inset+v),e.moveTo(s.startX+s.width-l.inset-v,s.startY+s.height-l.inset),e.lineTo(s.startX+s.width-l.inset,s.startY+s.height-l.inset),e.lineTo(s.startX+s.width-l.inset,s.startY+s.height-l.inset-v),e.moveTo(s.startX+l.inset+v,s.startY+s.height-l.inset),e.lineTo(s.startX+l.inset,s.startY+s.height-l.inset),e.lineTo(s.startX+l.inset,s.startY+s.height-l.inset-v),e.stroke(),e.lineWidth=a}(r.isCircleCrop||r.currSelectionPoint&&"crop-circle"===r.currSelectionPoint.shape)&&r.notify("crop",{prop:"cropCircle",onPropertyChange:!1,value:{context:e,isSave:e.canvas.id===r.element.id+"_tempCanvas"||null,isFlip:null}}),e.filter=f}}},e.prototype.triggerFrameChange=function(e){var t=this.parent,o={cancel:!1,previousFrameSetting:e,currentFrameSetting:{type:t.toPascalCase(t.frameObj.type),color:t.frameObj.color,gradientColor:t.frameObj.gradientColor,size:t.frameObj.size,inset:t.frameObj.inset,offset:t.frameObj.offset,borderRadius:t.frameObj.radius,frameLineStyle:t.toPascalCase(t.frameObj.border),lineCount:t.frameObj.amount}};return t.trigger("frameChange",o),t.editCompleteArgs=o,o.cancel||this.setFrameObj(o.currentFrameSetting),o},e.prototype.setFrameObj=function(e){var t=this.parent;t.frameObj.type=e.type.toLowerCase(),t.frameObj.color=e.color,t.frameObj.gradientColor=e.gradientColor,t.frameObj.size=e.size,t.frameObj.inset=e.inset,t.frameObj.offset=e.offset,t.frameObj.radius=e.borderRadius,t.frameObj.border=e.frameLineStyle.toLowerCase(),t.frameObj.amount=e.lineCount},e.prototype.zoomToSel=function(e,o){var i=this.parent;if(this.straightenActObj&&JSON.stringify(this.straightenActObj.activePoint)===JSON.stringify(e.activePoint))if(i.activeObj=t.extend({},this.straightenActObj,null,!0),this.allowRedactStraighten=!1,0===i.transform.straighten){var r=i.img.destWidth,a=i.img.destHeight;for(i.transform.straighten=360;;){if(t.isNullOrUndefined(this.straightenInitZoom)||!(Math.round(i.transform.zoomFactor*Math.pow(10,3))/Math.pow(10,3)>Math.round(this.straightenInitZoom*Math.pow(10,3))/Math.pow(10,3))){this.performDummyZoom();break}if(this.setZoomPan("out"),r===i.img.destWidth&&a===i.img.destHeight){this.performDummyZoom();break}0===i.transform.degree&&(i.transform.zoomFactor-=.025,i.transform.cropZoomFactor-=.025)}i.transform.straighten=0,i.img={destLeft:i.img.destLeft,destTop:i.img.destTop,destWidth:i.img.destWidth,destHeight:i.img.destHeight,srcLeft:i.img.srcLeft,srcTop:i.img.srcTop,srcWidth:i.img.srcWidth,srcHeight:i.img.srcHeight}}else t.isNullOrUndefined(this.straightenInitZoom)&&(this.straightenInitZoom=i.transform.zoomFactor),this.straightenInitZoom-i.transform.zoomFactor>0?i.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:-(this.straightenInitZoom-i.transform.zoomFactor),zoomPoint:null,isResize:!0}}):this.straightenInitZoom-i.transform.zoomFactor<0&&i.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:this.straightenInitZoom-i.transform.zoomFactor,zoomPoint:null,isResize:!0}}),i.activeObj=t.extend({},e,null,!0),i.transform.zoomFactor+=.001,this.calcStraightenedPoints(o);else this.straightenActObj=t.extend({},e,null,!0),i.activeObj=t.extend({},this.straightenActObj,null,!0),this.straightenInitZoom=i.transform.zoomFactor,this.calcStraightenedPoints(o)},e.prototype.isDestPointSmall=function(){var e=this.parent,t=e.img,o={startX:t.destLeft,startY:t.destTop,width:t.destWidth,height:t.destHeight};e.notify("shape",{prop:"straightenShapes",onPropertyChange:!1});var i=!1;return this.straightenDestPoints.destWidth&&this.straightenDestPoints.destHeight&&(t.destWidth<this.straightenDestPoints.destWidth||t.destHeight<this.straightenDestPoints.destHeight)&&(i=!0),t.destLeft=o.startX,t.destTop=o.startY,t.destWidth=o.width,t.destHeight=o.height,e.img=t,i},e.prototype.calcStraightenedPoints=function(e){var o=this.parent,i=o.img.destWidth,r=o.img.destHeight;t.isNullOrUndefined(o.transform.zoomFactor)&&(o.transform.zoomFactor+=.025),this.updateImgCanvasPoints();for(var a=this;;)if("break"===function(){if(!(a.isLinesIntersect()||a.isSelOutsideImg()||e&&a.isDestPointSmall()))return a.performDummyZoom(),"break";if(o.activeObj=t.extend({},a.straightenActObj,null,!0),a.setZoomPan("in"),i===o.img.destWidth&&r===o.img.destHeight)return a.performDummyZoom(),"break";0===o.transform.degree&&(o.transform.zoomFactor+=.025,o.transform.cropZoomFactor+=.025);var n=a.imgCanvasPoints,s=o.img.destLeft,l=o.img.destTop,p=o.img.destWidth,h=o.img.destHeight;n.forEach(function(e){e.x=e.ratioX*p+s,e.y=e.ratioY*h+l}),a.imgCanvasPoints=n}())break},e.prototype.performDummyZoom=function(){var e=this.parent;e.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:.025,zoomPoint:null,isResize:!0}}),e.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:-.025,zoomPoint:null,isResize:!0}});var t=10*e.transform.zoomFactor;t<1&&(t=1+t/10),e.setProperties({zoomSettings:{zoomFactor:t}},!0),e.notify("transform",{prop:"setPreviousZoomValue",onPropertyChange:!1,value:{previousZoomValue:t}}),this.panToSel()},e.prototype.setZoomPan=function(e){var t=this.parent,o={maxDimension:null};0===t.transform.degree?(t.notify("transform",{prop:"cropZoom",onPropertyChange:!1,value:{value:"in"===e?.025:-.025,selectionObj:t.activeObj,obj:o}}),t.img.destWidth=o.maxDimension.width,t.img.destHeight=o.maxDimension.height):(t.transform.zoomFactor+="in"===e?.025:-.025,t.transform.cropZoomFactor+="in"===e?.025:-.025,this.updateCurrTransState("initial"),this.isRotateZoom=!0,this.setDestPoints(),this.isRotateZoom=!1,this.updateCurrTransState("reverse"))},e.prototype.updateImgCanvasPoints=function(){var e=this.parent,t=this.getImagePoints(),o={width:0,height:0},i=e.baseImgCanvas.width,r=e.baseImgCanvas.height;e.notify("crop",{prop:"calcRatio",onPropertyChange:!1,value:{obj:o,dimension:{width:i,height:r}}});var a=o;i=e.transform.degree%90==0&&e.transform.degree%180!=0?a.height:a.width,r=e.transform.degree%90==0&&e.transform.degree%180!=0?a.width:a.height;var n,s,l,p,h=e.img,d=h.destLeft,c=h.destTop,u=h.destWidth,v=h.destHeight;e.transform.straighten>0?(n={x:d+t[0].x/i,y:c},s={x:d+u,y:c+t[1].y/r},l={x:d+u-t[0].x/i,y:c+v},p={x:d,y:c+v-t[1].y/r}):e.transform.straighten<0?(n={x:d,y:c+t[0].y/r},s={x:d+t[1].x/i,y:c},l={x:d+u,y:c+v-t[0].y/r},p={x:d+u-t[1].x/i,y:c+v}):0===e.transform.straighten&&(n={x:d,y:c},s={x:d+u,y:c},l={x:d+u,y:c+v},p={x:d,y:c+v}),n.ratioX=(n.x-d)/u,n.ratioY=(n.y-c)/v,s.ratioX=(s.x-d)/u,s.ratioY=(s.y-c)/v,l.ratioX=(l.x-d)/u,l.ratioY=(l.y-c)/v,p.ratioX=(p.x-d)/u,p.ratioY=(p.y-c)/v,this.imgCanvasPoints=[n,s,l,p]},e.prototype.isLinesIntersect=function(e){var t=this.parent,o=t.activeObj.activePoint;if(0!==t.activeObj.rotatedAngle){var i=t.activeObj.activePoint,r=i.startX,a=i.startY,n=i.endX,s=i.endY,l={x:r+i.width/2,y:a+i.height/2},p=Math.cos(t.activeObj.rotatedAngle),h=Math.sin(t.activeObj.rotatedAngle),d={x:p*(r-l.x)-h*(a-l.y)+l.x,y:h*(r-l.x)+p*(a-l.y)+l.y},c={x:p*(n-l.x)-h*(a-l.y)+l.x,y:h*(n-l.x)+p*(a-l.y)+l.y},u={x:p*(r-l.x)-h*(s-l.y)+l.x,y:h*(r-l.x)+p*(s-l.y)+l.y},v={x:p*(n-l.x)-h*(s-l.y)+l.x,y:h*(n-l.x)+p*(s-l.y)+l.y},g=this.imgCanvasPoints,f=this.doIntersect(d,c,g[0],g[1]),C=this.doIntersect(c,v,g[1],g[2]),b=this.doIntersect(u,v,g[2],g[3]),m=this.doIntersect(d,u,g[3],g[0]);return e&&(e.arr=[f,C,b,m]),f||C||b||m}var y=this.imgCanvasPoints,P=this.doIntersect({x:o.startX,y:o.startY},{x:o.endX,y:o.startY},y[0],y[1]),j=this.doIntersect({x:o.endX,y:o.startY},{x:o.endX,y:o.endY},y[1],y[2]),x=this.doIntersect({x:o.startX,y:o.endY},{x:o.endX,y:o.endY},y[2],y[3]),w=this.doIntersect({x:o.startX,y:o.startY},{x:o.startX,y:o.endY},y[3],y[0]),O=this.isInsideRect(y[0]),S=this.isInsideRect(y[1]),T=this.isInsideRect(y[2]),k=this.isInsideRect(y[3]);return e&&(e.arr=[P,j,x,w]),P||j||x||w||O||S||T||k||y[0].x>o.startX&&y[1].x<o.endX&&y[2].x<o.endX&&y[3].x>o.startX&&y[0].y<o.startY&&y[1].y<o.startY&&y[2].y>o.endY&&y[3].y>o.endY||y[0].x<o.startX&&y[1].x>o.endX&&y[2].x>o.endX&&y[3].x<o.startX&&y[0].y>o.startY&&y[1].y>o.startY&&y[2].y<o.endY&&y[3].y<o.endY},e.prototype.isSelOutsideImg=function(){var e=this.parent,t=this.imgCanvasPoints,o=e.activeObj.activePoint;return"inside"!==this.checkPointPosition(o.startX,o.startY,t[0].x,t[0].y,t[1].x,t[1].y,t[2].x,t[2].y,t[3].x,t[3].y)||"inside"!==this.checkPointPosition(o.endX,o.startY,t[0].x,t[0].y,t[1].x,t[1].y,t[2].x,t[2].y,t[3].x,t[3].y)||"inside"!==this.checkPointPosition(o.startX,o.endY,t[0].x,t[0].y,t[1].x,t[1].y,t[2].x,t[2].y,t[3].x,t[3].y)||"inside"!==this.checkPointPosition(o.endX,o.endY,t[0].x,t[0].y,t[1].x,t[1].y,t[2].x,t[2].y,t[3].x,t[3].y)},e.prototype.calcTriangleArea=function(e,t,o,i,r,a){return Math.abs((e*(i-a)+o*(a-t)+r*(t-i))/2)},e.prototype.checkPointPosition=function(e,t,o,i,r,a,n,s,l,p){var h=this.calcTriangleArea(e,t,o,i,l,p),d=this.calcTriangleArea(e,t,l,p,n,s),c=this.calcTriangleArea(e,t,n,s,r,a),u=this.calcTriangleArea(e,t,r,a,o,i),v=this.calcTriangleArea(o,i,r,a,n,s)+this.calcTriangleArea(n,s,l,p,o,i);return h+d+c+u>v?"outside":h+d+c+u!==v||0!==h&&0!==d&&0!==c&&0!==u?"inside":"on"},e.prototype.getImagePoints=function(){var e=[],t=this.parent,o=t.transform.degree,i=t.baseImg.width,r=t.baseImg.height,a={dim:null,width:r,height:i,angle:t.transform.straighten};a.dim=t.getRotatedCanvasDim(a.width,a.height,a.angle);var n=o%90==0&&o%180!=0?a.dim.width:t.baseImgCanvas.width,s=o%90==0&&o%180!=0?a.dim.height:t.baseImgCanvas.height,l=o%90==0&&o%180!=0?r:i,p=o%90==0&&o%180!=0?i:r,h=n/2,d=s/2,c=h-l/2,u=d-p/2,v=h+l/2,g=d+p/2,f={x:h,y:d},C=t.transform.straighten*(Math.PI/180),b={x:Math.cos(C)*(c-f.x)-Math.sin(C)*(u-f.y)+f.x,y:Math.sin(C)*(c-f.x)+Math.cos(C)*(u-f.y)+f.y},m={x:Math.cos(C)*(v-f.x)-Math.sin(C)*(u-f.y)+f.x,y:Math.sin(C)*(v-f.x)+Math.cos(C)*(u-f.y)+f.y},y={x:Math.cos(C)*(v-f.x)-Math.sin(C)*(g-f.y)+f.x,y:Math.sin(C)*(v-f.x)+Math.cos(C)*(g-f.y)+f.y},P={x:Math.cos(C)*(c-f.x)-Math.sin(C)*(g-f.y)+f.x,y:Math.sin(C)*(c-f.x)+Math.cos(C)*(g-f.y)+f.y};return e.push(b),e.push(m),e.push(y),e.push(P),e},e.prototype.doIntersect=function(e,t,o,i){var r=this.initiation(e,t,o),a=this.initiation(e,t,i),n=this.initiation(o,i,e),s=this.initiation(o,i,t);return r!==a&&n!==s||(!(0!==r||!this.onSegment(e,o,t))||(!(0!==a||!this.onSegment(e,i,t))||(!(0!==n||!this.onSegment(o,e,i))||!(0!==s||!this.onSegment(o,t,i)))))},e.prototype.initiation=function(e,t,o){var i=(t.y-e.y)*(o.x-t.x)-(t.x-e.x)*(o.y-t.y);return 0===i?0:i>0?1:2},e.prototype.onSegment=function(e,t,o){return t.x<=Math.max(e.x,o.x)&&t.x>=Math.min(e.x,o.x)&&t.y<=Math.max(e.y,o.y)&&t.y>=Math.min(e.y,o.y)},e.prototype.isInsideRect=function(e){var t=this.parent.activeObj.activePoint,o=!1;return e.x>=t.startX&&e.x<=t.endX&&e.y>=t.startY&&e.y<=t.endY&&(o=!0),o},e.prototype.setDestForStraighten=function(){var e=this.parent;if(t.isNullOrUndefined(this.straightenDestPoints)){var o=e.img,i=o.destLeft,r=o.destTop,a=o.destWidth,n=o.destHeight;e.notify("shape",{prop:"straightenShapes",onPropertyChange:!1}),this.straightenDestPoints=t.extend({},e.img,{},!0),e.img.destLeft=i,e.img.destTop=r,e.img.destWidth=a,e.img.destHeight=n}},e.prototype.drawRedact=function(e,t){var o=t.activePoint,i=o.startX,r=o.startY,a=o.endX,n=o.endY,s=t.activePoint,l=s.width,p=s.height,h=!1,d=e.canvas;-1!==d.id.indexOf("_tempCanvas")&&(h=!0);var c=this.parent.img;if(!(l<=0||p<=0))if(this.parent.isCropTab)e.drawImage(t.redactImage,0,0,t.redactImage.width,t.redactImage.height,i,r,l,p);else{var u=document.createElement("canvas"),v=u.getContext("2d"),g=d.width,f=d.height,C=Math.min(g,f)/1e3,b=0!==this.parent.transform.straighten?this.parent.transform.straighten:this.parent.cropObj.straighten;if(this.allowRedactStraighten&&0!==b){var m=document.createElement("canvas"),y=m.getContext("2d");h?(m.width=d.width,m.height=d.height,y.drawImage(d,0,0)):(m.width=c.destWidth,m.height=c.destHeight,y.drawImage(this.lowerContext.canvas,c.destLeft,c.destTop,c.destWidth,c.destHeight,0,0,c.destWidth,c.destHeight));var P=-b*Math.PI/180,j=document.createElement("canvas"),x=j.getContext("2d");j.width=m.width,j.height=m.height,c.destWidth>d.width&&!h&&(j.width=d.width),c.destHeight>d.height&&!h&&(j.height=d.height),x.save(),x.translate(m.width/2,m.height/2),x.rotate(P),x.drawImage(m,-m.width/2,-m.height/2),x.restore(),c.destLeft>0&&!h&&(i-=c.destLeft,a-=c.destLeft),c.destTop>0&&!h&&(r-=c.destTop,n-=c.destTop);var w={x:i+l/2,y:r+p/2},O=Math.cos(b*Math.PI/180),S=Math.sin(b*Math.PI/180),T={x:O*(i-w.x)-S*(r-w.y)+w.x,y:S*(i-w.x)+O*(r-w.y)+w.y},k={x:O*(a-w.x)-S*(r-w.y)+w.x,y:S*(a-w.x)+O*(r-w.y)+w.y},F={x:O*(i-w.x)-S*(n-w.y)+w.x,y:S*(i-w.x)+O*(n-w.y)+w.y};h?w={x:d.width/2,y:d.height/2}:(w={x:c.destWidth/2,y:c.destHeight/2},c.destWidth>d.width&&(w.x=d.width/2),c.destHeight>d.height&&(w.y=d.height/2)),O=Math.cos(P),S=Math.sin(P);var I={x:O*(T.x-w.x)-S*(T.y-w.y)+w.x,y:S*(T.x-w.x)+O*(T.y-w.y)+w.y},A={x:O*(k.x-w.x)-S*(k.y-w.y)+w.x,y:S*(k.x-w.x)+O*(k.y-w.y)+w.y},z={x:O*(F.x-w.x)-S*(F.y-w.y)+w.x,y:S*(F.x-w.x)+O*(F.y-w.y)+w.y};if("blur"===this.parent.activeObj.redactType)u.width=l,u.height=p,v.drawImage(j,I.x,I.y,A.x-I.x,z.y-A.y,0,0,l,p);else{D=t.redactPixelate/100*20;h&&(D=C*(t.redactPixelate/100)*35),u.width=Math.ceil(l/D),u.height=Math.ceil(p/D),v.drawImage(j,I.x,I.y,A.x-I.x,z.y-A.y,0,0,u.width,u.height)}}if("blur"===this.parent.activeObj.redactType){if(0===b&&(u.width=l,u.height=p,v.drawImage(h?d:this.lowerContext.canvas,i,r,l,p,0,0,l,p)),h){var R=C*(t.redactBlur/100*34);v.filter="blur("+R+"px)"}else v.filter="blur("+t.redactBlur/100*17+"px)";v.drawImage(u,0,0),0===b?v.drawImage(h?d:this.lowerContext.canvas,i,r,l,p,0,0,l,p):(c.destLeft>0&&!h&&(i+=c.destLeft,a+=c.destLeft),c.destTop>0&&!h&&(r+=c.destTop,n+=c.destTop)),this.parent.isSafari&&this.parent.notify("filter",{prop:"apply-filter",onPropertyChange:!1,value:{context:v}}),e.drawImage(u,0,0,l,p,i,r,l,p)}else{var D=t.redactPixelate/100*20;h&&(D=C*(t.redactPixelate/100)*35),0===b?(u.width=Math.ceil(l/D),u.height=Math.ceil(p/D),v.drawImage(h?d:this.lowerContext.canvas,i,r,l,p,0,0,u.width,u.height)):(c.destLeft>0&&!h&&(i+=c.destLeft,a+=c.destLeft),c.destTop>0&&!h&&(r+=c.destTop,n+=c.destTop)),e.imageSmoothingEnabled=!1,e.drawImage(u,0,0,u.width,u.height,i,r,l,p)}t.redactImage=this.parent.createElement("canvas"),t.redactImage.width=u.width,t.redactImage.height=u.height,t.redactImage.getContext("2d").drawImage(u,0,0),e.beginPath(),e.rect(i,r,l,p),e.rect(i,r,l,p),e.fill("evenodd"),e.closePath()}},e}(),d=function(){function e(e){this.parent=e,this.addEventListener()}return e.prototype.destroy=function(){this.parent.isDestroyed||this.removeEventListener()},e.prototype.addEventListener=function(){this.parent.on("export",this.export,this),this.parent.on("destroyed",this.destroy,this)},e.prototype.removeEventListener=function(){this.parent.off("export",this.export),this.parent.off("destroyed",this.destroy)},e.prototype.export=function(e){switch(this.parent.notify("toolbar",{prop:"refreshShapeDrawing",onPropertyChange:!1}),this.updatePvtVar(),e.prop){case"export":this.exportImg(e.value.type,e.value.fileName,e.value.imgQuality);break;case"exportToCanvas":this.exportToCanvas(e.value.object);break;case"updateSaveContext":this.updateSaveContext(e.value.context);break;case"setImageQuality":this.imageQuality=e.value.value;break;case"drawAnnotation":this.drawAnnotation(e.value.context,e.value.ratio)}},e.prototype.getModuleName=function(){return"export"},e.prototype.updatePvtVar=function(){var e=this.parent;e.lowerCanvas&&(this.lowerContext=e.lowerCanvas.getContext("2d"))},e.prototype.exportImg=function(e,t,o){var i=this.parent,r={fileName:""};i.notify("draw",{prop:"getFileName",onPropertyChange:!1,value:{obj:r}});var a=r.fileName;if(!i.disabled&&i.isImageLoaded){i.notify("shape",{prop:"applyActObj",onPropertyChange:!1,value:{isMouseDown:null}});var n={canvasFilter:this.parent.canvasFilter};this.lowerContext.filter=n.canvasFilter,e=e||"Png",i.notify("shape",{prop:"redrawActObj",onPropertyChange:!1,value:{x:null,y:null,isMouseDown:null}});var s={cancel:!1,fileName:t||a,fileType:e,imageQuality:o};i.trigger("beforeSave",s),this.beforeSaveEvent(s,e,t,a,o)}},e.prototype.beforeSaveEvent=function(e,t,o,i,r){var a=this.parent;if(!e.cancel){a.currObjType.isSave=!0,o=e.fileName?e.fileName:o;var n=t.toLowerCase();o=o||i,"svg"===n?this.toSVGImg(o):this.toBlobFn(o,n,r);var s={fileName:o||i,fileType:t};a.trigger("saved",s);var l={action:"save",actionEventArgs:s};a.triggerEditCompleteEvent(l),a.notify("toolbar",{prop:"refresh-main-toolbar",onPropertyChange:!1}),a.lowerCanvas.style.left=a.upperCanvas.style.left="",a.lowerCanvas.style.top=a.upperCanvas.style.top="",a.lowerCanvas.style.maxWidth=a.upperCanvas.style.maxWidth="",a.lowerCanvas.style.maxHeight=a.upperCanvas.style.maxHeight=""}},e.prototype.toSVGImg=function(e){var t=this.parent;o.showSpinner(t.element),t.element.style.opacity="0.5";var i=this.exportToCanvas(),r=i.toDataURL();o.hideSpinner(t.element),t.element.style.opacity="1";var a=document.createElementNS("http://www.w3.org/2000/svg","svg");a.setAttribute("width",i.style.maxWidth),a.setAttribute("height",i.style.maxHeight);var n=document.createElementNS("http://www.w3.org/2000/svg","image");n.setAttributeNS(null,"height",i.height.toString()),n.setAttributeNS(null,"width",i.width.toString()),n.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",r),a.appendChild(n);var s='<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="'+i.width+'" height="'+i.height+'">'+a.innerHTML+"</svg>",l="data:image/svg+xml;base64,"+btoa(s);return null===e?l:(this.downloadImg(l,e+".svg"),null)},e.prototype.toBlobFn=function(e,i,r){var a=this,n=this.parent;o.showSpinner(n.element),n.element.style.opacity="0.5",t.isNullOrUndefined(r)||(r=r>1?1:r<=0?.01:r,this.imageQuality=r||null);var s=this.exportToCanvas(),l="jpeg"!==i?"image/png":"image/jpeg";s.toBlob(function(t){var r=URL.createObjectURL(t);a.downloadImg(r,e+"."+i),o.hideSpinner(n.element),n.element.style.opacity="1"},l,this.imageQuality?this.imageQuality:null)},e.prototype.exportToCanvas=function(e){var o,i,r=this.parent,a=t.extend({},r.cropObj,{},!0),n={currObj:{}};r.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:n}});var s=n.currObj;s.objColl=t.extend([],r.objColl,[],!0),s.pointColl=t.extend([],r.pointColl,[],!0),s.afterCropActions=t.extend([],r.afterCropActions,[],!0);var l={selPointColl:null};r.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:l}}),this.parent.aspectWidth?(r.notify("undo-redo",{prop:"setPreventUR",value:{bool:!0}}),r.notify("toolbar",{prop:"resizeClick",value:{bool:!1}}),r.okBtn(),r.transform.degree%90==0&&r.transform.degree%180!=0?(o=this.parent.aspectHeight,i=this.parent.aspectWidth):(o=this.parent.aspectWidth,i=this.parent.aspectHeight),r.notify("undo-redo",{prop:"setPreventUR",value:{bool:!1}})):r.currSelectionPoint?(o=r.img.srcWidth,i=r.img.srcHeight):(o=r.baseImgCanvas.width,i=r.baseImgCanvas.height);var p={width:0,height:0};r.notify("crop",{prop:"calcRatio",onPropertyChange:!1,value:{obj:p,dimension:{width:o,height:i}}});var h=p,d=this.lowerContext.filter;if("none"!==this.lowerContext.filter){var c=this.lowerContext.filter.split(" "),u=parseFloat(c[5].split("(")[1]);u*=(h.width+h.height)/2,c[5]="blur("+u+"px)",this.lowerContext.filter=c.join(" ")}var v=r.createElement("canvas",{id:r.element.id+"_tempCanvas",attrs:{name:"canvasImage"}}),g=v.getContext("2d");v.width=o,v.height=i;var f={width:0,height:0};r.notify("transform",{prop:"calcMaxDimension",onPropertyChange:!1,value:{width:o,height:i,obj:f}});var C=f;v.style.maxWidth=C.width+"px",v.style.maxHeight=C.height+"px";var b=this.lowerContext.filter;return g.filter=this.lowerContext.filter,this.downScaleImgCanvas(g,o,i),this.lowerContext.filter=b,0===r.transform.degree&&""===r.transform.currFlipState&&0===r.transform.straighten||(this.updateSaveContext(g),this.exportTransformedImage(g)),r.isSafari&&r.notify("filter",{prop:"apply-filter",onPropertyChange:!1,value:{context:g}}),this.drawAnnotation(g,h),r.isCircleCrop&&r.notify("crop",{prop:"cropCircle",onPropertyChange:!1,value:{context:g,isSave:!0,isFlip:null}}),this.updateFrame(g,!0),this.lowerContext.filter=d,r.canvasFilter=d,e&&(e.canvas=v),r.aspectWidth&&(r.objColl=[],r.pointColl=[],r.freehandCounter=0,r.notify("freehand-draw",{prop:"setSelPointColl",onPropertyChange:!1,value:{obj:{selPointColl:[]}}}),r.notify("draw",{prop:"setCurrentObj",onPropertyChange:!1,value:{obj:s}}),s.selPointColl=t.extend([],l.selPointColl,[],!0),r.notify("freehand-draw",{prop:"setSelPointColl",onPropertyChange:!1,value:{obj:{selPointColl:s.selPointColl}}}),r.cropObj=a,r.objColl=t.extend([],s.objColl,[],!0),r.pointColl=t.extend([],s.pointColl,[],!0),r.freehandCounter=r.pointColl.length,r.transform.straighten=0,this.lowerContext.filter="none",r.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"zoom",pen:"zoom",isPreventApply:null}}),this.lowerContext.filter=s.filter,r.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.lowerContext}}),(r.isCircleCrop||r.currSelectionPoint&&"crop-circle"===r.currSelectionPoint.shape)&&r.notify("crop",{prop:"cropCircle",onPropertyChange:!1,value:{context:this.lowerContext,isSave:null,isFlip:null}})),v},e.prototype.drawAnnotation=function(e,o){var i=this.parent,r=t.extend([],i.objColl,[],!0),a=t.extend([],i.pointColl,[],!0),n=i.shapeColl.filter(function(e){return"redact"!==e.shape}),s=i.shapeColl.filter(function(e){return"redact"===e.shape});i.shapeColl=s.concat(n);for(var l=0;l<i.shapeColl.length;l++)i.shapeColl[l].order&&(i.shapeColl[l].currIndex&&i.shapeColl[l].currIndex.indexOf("shape")>-1?(i.objColl=[],i.objColl.push(t.extend({},i.shapeColl[l],{},!0)),this.drawShape(e,o)):i.shapeColl[l].id&&i.shapeColl[l].id.indexOf("pen")>-1&&(i.pointColl=[],i.freehandCounter=0,i.pointColl.push(t.extend({},i.shapeColl[l],{},!0)),i.freehandCounter=i.pointColl.length,this.drawPen(e,o)));i.objColl=r,i.pointColl=a,i.freehandCounter=i.pointColl.length},e.prototype.drawShape=function(e,o){var i=this.parent;if(i.objColl.length>0){var r=e.filter;e.filter="none";var a={index:null};i.notify("shape",{prop:"getSmallestIndex",onPropertyChange:!1,value:{obj:a}});for(var n=a.index,s=t.extend([],i.objColl,[],!0),l=t.extend([],i.objColl,[],!0);s.length>0;){for(var p=!1,h=0;h<s.length;h++){var d=s[h];if(t.isNullOrUndefined(d.order))s.splice(h,1),h--;else if(d.order===n){var c=e.filter;e.filter="none";var u=s[h],v=u.activePoint;if(v.startX-=i.img.destLeft,v.startY-=i.img.destTop,v.endX-=i.img.destLeft,v.endY-=i.img.destTop,v.width=v.endX-v.startX,v.height=v.endY-v.startY,v.startX*=o.width,v.startY*=o.height,v.endX*=o.width,v.endY*=o.height,v.width=v.endX-v.startX,v.height=v.endY-v.startY,u.strokeSettings.strokeWidth*=(o.width+o.height)/2,"text"===u.shape)u.textSettings.fontSize*=(o.width+o.height)/2;else if("path"===u.shape)for(var g=0;g<u.pointColl.length;g++)u.pointColl[g].x=(u.pointColl[g].x-i.img.destLeft)*o.width,u.pointColl[g].y=(u.pointColl[g].y-i.img.destTop)*o.height;else"image"===u.shape&&(i.activeObj=t.extend({},s[h],{},!0),i.notify("selection",{prop:"upgradeImageQuality",onPropertyChange:!1}),s[h]=t.extend({},i.activeObj,{},!0));i.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"saveContext",obj:s[h],isCropRatio:null,points:null,isPreventDrag:!0,saveContext:e,isPreventSelection:null}}),e.filter=c,i.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),n++;var f={bool:!1};i.notify("shape",{prop:"isIndexInObjColl",onPropertyChange:!1,value:{obj:f,index:n}}),f.bool||n++,s.splice(h,1),p=!0;break}}if(!p)break}e.filter=r,i.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),i.objColl=l}},e.prototype.drawPen=function(e,o){var i=this.parent;if(i.freehandCounter>0){var r={penStrokeWidth:null};i.notify("freehand-draw",{prop:"getPenStrokeWidth",onPropertyChange:!1,value:{obj:r}});for(var a=t.extend({},i.pointColl,{},!0),n=0;n<i.freehandCounter;n++){i.points=t.extend([],i.pointColl[n].points,[]),i.notify("freehand-draw",{prop:"setPointCounter",onPropertyChange:!1,value:{value:0}});var s=i.points.length;i.pointColl[n].strokeWidth*=(o.width+o.height)/2;for(var l=0;l<s;l++)i.points[l].x=(i.points[l].x-i.img.destLeft)*o.width,i.points[l].y=(i.points[l].y-i.img.destTop)*o.height}i.notify("freehand-draw",{prop:"freehandRedraw",onPropertyChange:!1,value:{context:e,points:null}}),i.pointColl=a,i.notify("freehand-draw",{prop:"setPenStrokeWidth",onPropertyChange:!1,value:{value:r.penStrokeWidth}})}},e.prototype.downScaleImgCanvas=function(e,t,o){var i=this.parent,r=i.baseImgCanvas,a=i.baseImg,n={width:0,height:0};i.notify("transform",{prop:"calcMaxDimension",onPropertyChange:!1,value:{width:a.width,height:a.height,obj:n,isImgShape:null}});var s={color:null};if(i.notify("draw",{prop:"getImageBackgroundColor",value:{obj:s}}),""!==s.color&&(e.fillStyle=s.color,e.fillRect(0,0,e.canvas.width,e.canvas.height)),n.width>t&&n.height>o){var l=i.createElement("canvas",{id:i.element.id+"_downScaleCanvas",attrs:{name:"canvasImage"}});l.width=this.parent.img.srcWidth,l.height=this.parent.img.srcHeight,l.getContext("2d").drawImage(r,i.img.srcLeft,i.img.srcTop,i.img.srcWidth,i.img.srcHeight,0,0,l.width,l.height),i.notify("draw",{prop:"downScale",value:{canvas:l,width:t,height:o}}),e.drawImage(l,0,0)}else e.drawImage(i.baseImgCanvas,i.img.srcLeft,i.img.srcTop,i.img.srcWidth,i.img.srcHeight,0,0,t,o)},e.prototype.updateFrame=function(e,t){if("none"!==this.parent.frameObj.type){var o=e.filter;e.filter="none",this.parent.notify("draw",{prop:"applyFrame",value:{ctx:e,frame:this.parent.frameObj.type,preventImg:t}}),e.filter=o}},e.prototype.downloadImg=function(e,t){var o=document.createElement("a");o.href=e,o.target="_parent",o.download=t,(document.body||document.documentElement).appendChild(o),o.click(),o.parentNode.removeChild(o)},e.prototype.exportTransformedImage=function(e){var t=this.parent,o=t.transform.degree;if(t.rotateFlipColl.length>0)for(var i=0,r=t.rotateFlipColl.length;i<r;i++){var a=t.rotateFlipColl[i];"number"==typeof a?this.exportRotate(e,a):"horizontal"===a?this.exportFlip(e,!0,!1):"vertical"===a&&this.exportFlip(e,!1,!0)}t.transform.degree=o},e.prototype.exportRotate=function(e,t){var o=this.parent;e.clearRect(0,0,e.canvas.width,e.canvas.height),this.setMaxDim(o.transform.degree,e.canvas),e.translate(e.canvas.width/2,e.canvas.height/2),e.rotate(Math.PI/180*t),e.drawImage(o.inMemoryCanvas,-e.canvas.height/2,-e.canvas.width/2,e.canvas.height,e.canvas.width),this.updateSaveContext(e)},e.prototype.exportFlip=function(e,t,o){e.clearRect(0,0,e.canvas.width,e.canvas.height),t&&(e.translate(e.canvas.width,0),e.scale(-1,1)),o&&(e.translate(0,e.canvas.height),e.scale(1,-1)),e.drawImage(this.parent.inMemoryCanvas,0,0),this.updateSaveContext(e)},e.prototype.updateSaveContext=function(e){var t=this.parent.inMemoryCanvas.getContext("2d");e.setTransform(1,0,0,1,0,0);var o=e.getImageData(0,0,e.canvas.width,e.canvas.height);this.parent.inMemoryCanvas.width=o.width,this.parent.inMemoryCanvas.height=o.height,t.putImageData(o,0,0)},e.prototype.setMaxDim=function(e,o){var i,r;e%90==0&&e%180!=0?t.isNullOrUndefined(this.parent.currSelectionPoint)?(i=this.parent.baseImgCanvas.height,r=this.parent.baseImgCanvas.width):(i=this.parent.img.srcHeight,r=this.parent.img.srcWidth):e%180!=0&&0!==e||(t.isNullOrUndefined(this.parent.currSelectionPoint)?(i=this.parent.baseImgCanvas.width,r=this.parent.baseImgCanvas.height):(i=this.parent.img.srcWidth,r=this.parent.img.srcHeight)),t.isNullOrUndefined(this.parent.aspectWidth)||(i=this.parent.aspectWidth,r=this.parent.aspectHeight),o.width=i,o.height=r;var a={width:0,height:0};this.parent.notify("transform",{prop:"calcMaxDimension",onPropertyChange:!1,value:{width:i,height:r,obj:a,isImgShape:null}});var n=a;o.style.maxWidth=n.width+"px",o.style.maxHeight=n.height+"px"},e}(),c=function(){function e(e){this.adjustmentLevel={brightness:0,contrast:0,hue:0,opacity:100,saturation:0,blur:0,exposure:0,transparency:100,sharpen:!1,bw:!1},this.tempAdjustmentLevel={brightness:0,contrast:0,hue:0,opacity:100,saturation:0,blur:0,exposure:0,transparency:100,sharpen:!1,bw:!1},this.adjustmentValue="",this.isBrightnessAdjusted=!1,this.bevelFilter="none",this.tempAdjVal={brightness:0,contrast:0,hue:0,opacity:100,saturation:0,blur:0,exposure:0,transparency:100,sharpen:!1,bw:!1},this.tempFilVal="",this.parent=e,this.addEventListener()}return e.prototype.destroy=function(){this.parent.isDestroyed||this.removeEventListener()},e.prototype.addEventListener=function(){this.parent.on("filter",this.filter,this),this.parent.on("destroyed",this.destroy,this)},e.prototype.removeEventListener=function(){this.parent.off("filter",this.filter),this.parent.off("destroyed",this.destroy)},e.prototype.filter=function(e){switch(this.updatePrivateVariables(),e.prop){case"finetuneImage":this.finetuneImage(e.value.option,e.value.value);break;case"applyImageFilter":this.setFilter(e.value.option);break;case"update-finetunes":this.updateFinetunes();break;case"set-adjustment":this.setAdjustment(e.value.operation);break;case"initFilter":this.initFilter();break;case"setCurrAdjValue":this.setCurrAdjValue(e.value.type,e.value.value);break;case"updateAdj":this.updateAdj(e.value.type,e.value.value,e.value.isPreview,e.value.ctx);break;case"getCurrentObj":this.getCurrentObj(e.value.object);break;case"getAdjustmentLevel":t.isNullOrUndefined(this.parent.activeObj.opacity)?this.adjustmentLevel.transparency=100:this.adjustmentLevel.transparency=100*this.parent.activeObj.opacity,e.value.obj.adjustmentLevel=this.adjustmentLevel;break;case"setAdjustmentLevel":this.adjustmentLevel=e.value.adjustmentLevel;break;case"getTempAdjustmentLevel":e.value.obj.tempAdjustmentLevel=this.tempAdjustmentLevel;break;case"setTempAdjustmentLevel":this.tempAdjustmentLevel=e.value.tempAdjustmentLevel;break;case"setAdjustmentValue":this.adjustmentValue=e.value.adjustmentValue;break;case"getBrightnessAdjusted":e.value.obj.isBrightnessAdjusted=this.isBrightnessAdjusted;break;case"setBrightnessAdjusted":this.isBrightnessAdjusted=e.value.isBrightnessAdjusted,this.parent.currentFilter.split("_")&&"cold"===this.parent.currentFilter.split("_")[1]&&(this.isBrightnessAdjusted=!1);break;case"getBevelFilter":e.value.obj.bevelFilter=this.bevelFilter;break;case"setBevelFilter":this.bevelFilter=e.value.bevelFilter;break;case"setTempAdjVal":this.tempAdjVal=t.extend({},this.adjustmentLevel,{},!0);break;case"setTempFilVal":this.tempFilVal=this.parent.currentFilter;break;case"reset":this.reset();break;case"apply-filter":this.applyFilter(e.value.context)}},e.prototype.updatePrivateVariables=function(){var e=this.parent;e.lowerCanvas&&(this.lowerContext=e.lowerCanvas.getContext("2d"))},e.prototype.getModuleName=function(){return"filter"},e.prototype.reset=function(){this.adjustmentLevel={brightness:0,contrast:0,hue:0,opacity:100,saturation:0,blur:0,exposure:0,transparency:100,sharpen:!1,bw:!1},this.tempAdjustmentLevel={brightness:0,contrast:0,hue:0,opacity:100,saturation:0,blur:0,exposure:0,transparency:100,sharpen:!1,bw:!1},this.adjustmentValue=this.parent.getDefaultFilter(),this.isBrightnessAdjusted=!1,this.bevelFilter="none",this.tempFilVal="",this.tempAdjVal={brightness:0,contrast:0,hue:0,opacity:100,saturation:0,blur:0,exposure:0,transparency:100,sharpen:!1,bw:!1}},e.prototype.updateFinetunes=function(){var e=this,t=this.parent,o=t.finetuneSettings;o&&(["brightness","contrast","hue","saturation","exposure","opacity","blur"].forEach(function(t){o[t]&&(e.adjustmentLevel[t]=o[t].defaultValue,e.tempAdjustmentLevel[t]=o[t].defaultValue)}),t.notify("draw",{prop:"isInitialLoading",onPropertyChange:!1,value:{isInitialLoading:!0}}))},e.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)},e.prototype.updateAdj=function(e,o,i,r){var a=this.parent;this.lowerContext.clearRect(0,0,a.lowerCanvas.width,a.lowerCanvas.height);var n=this.lowerContext.filter.split(" "),s=[],l=this.getFilterValue(this.adjustmentLevel.brightness);if(-1===["brightness","contrast","hue","saturation","exposure","opacity","blur"].indexOf(e)&&t.isNullOrUndefined(i)&&(this.adjustmentLevel.sharpen||this.adjustmentLevel.bw)){a.isUndoRedo=!0;var p=this.lowerContext.filter;this.lowerContext.filter="none",a.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"iterate",pen:"iterate",isPreventApply:null}}),this.lowerContext.filter=p,a.isUndoRedo=!1}var h,d,c,u,v;switch(e){case"brightness":o=this.getFilterValue(this.adjustmentLevel.exposure)+.005*o,n[0]="brightness("+o+")",0!==this.adjustmentLevel.brightness?(o=this.adjustmentLevel.opacity/100-.3*this.adjustmentLevel.opacity/100,n[4]="opacity("+o+")"):(o=this.adjustmentLevel.opacity/100,n[4]="opacity("+o+")"),this.adjustmentValue=n.join(" ");break;case"contrast":n[1]="contrast("+o+"%)",this.adjustmentValue=n.join(" ");break;case"hue":n[2]="hue-rotate("+o+"deg)",this.adjustmentValue=n.join(" ");break;case"saturation":n[3]="saturate("+o+"%)",this.adjustmentValue=n.join(" ");break;case"opacity":1!==parseFloat(n[0].split("(")[1])&&(o-=.2),o<0&&(o=0),n[4]="opacity("+o+")",this.adjustmentValue=n.join(" ");break;case"blur":n[5]="blur("+o+"px)",this.adjustmentValue=n.join(" ");break;case"exposure":o>1?(o-=1,o+=l):o<1&&(o=l-(o=1-o)),n[0]="brightness("+o+")",this.adjustmentValue=n.join(" ");break;case"chrome":h=this.getSaturationFilterValue(this.adjustmentLevel.saturation),o=(h*=100)+.4*h,n[3]="saturate("+o+"%)",s=this.adjustmentValue.split(" "),n[0]=s[0],n[1]=s[1],n[2]=s[2],n[4]=s[4],n[5]=s[5],n[6]="sepia(0%)",n[7]="grayscale(0%)",n[8]="invert(0%)";break;case"cold":d=this.getFilterValue(this.adjustmentLevel.brightness),o=.9*(d*=100),o*=.01,n[0]="brightness("+o+")",u=this.getFilterValue(this.adjustmentLevel.contrast),o=(u*=100)+.5*u,n[1]="contrast("+o+"%)",v=this.getSaturationFilterValue(this.adjustmentLevel.saturation),o=v*=100,n[3]="saturate("+o+"%)",s=this.adjustmentValue.split(" "),n[2]=s[2],n[4]=s[4],n[5]=s[5],n[6]="sepia(0%)",n[7]="grayscale(0%)",n[8]="invert(0%)";break;case"warm":c=this.getSaturationFilterValue(this.adjustmentLevel.saturation),o=(c*=100)+.4*c,n[3]="saturate("+o+"%)",n[6]="sepia(25%)",s=this.adjustmentValue.split(" "),n[0]=s[0],n[1]=s[1],n[2]=s[2],n[4]=s[4],n[5]=s[5],n[7]="grayscale(0%)",n[8]="invert(0%)";break;case"grayscale":n[7]="grayscale(100%)",s=this.adjustmentValue.split(" "),n[0]=s[0],n[1]=s[1],n[2]=s[2],n[3]=s[3],n[4]=s[4],n[5]=s[5],n[6]="sepia(0%)",n[8]="invert(0%)";break;case"sepia":n[6]="sepia(100%)",s=this.adjustmentValue.split(" "),n[0]=s[0],n[1]=s[1],n[2]=s[2],n[3]=s[3],n[4]=s[4],n[5]=s[5],n[7]="grayscale(0%)",n[8]="invert(0%)";break;case"invert":n[8]="invert(100%)",s=this.adjustmentValue.split(" "),n[0]=s[0],n[1]=s[1],n[2]=s[2],n[3]=s[3],n[4]=s[4],n[5]=s[5],n[6]="sepia(0%)",n[7]="grayscale(0%)"}if("sharpen"!==e&&"blackandwhite"!==e){t.isNullOrUndefined(i)&&("default"===e&&(n=this.getDefaultCurrentFilter(n)),this.lowerContext.filter=n.join(" ")),n=this.setTempFilterValue(l,i,n,e),a.notify("draw",{prop:"setRotateZoom",onPropertyChange:!1,value:{isRotateZoom:!0}}),a.notify("draw",{prop:"updateCurrTransState",onPropertyChange:!1,value:{type:"initial",isPreventDestination:null,isRotatePan:null}});var g=void 0;"bevel"===a.frameObj.type&&(g=this.lowerContext.filter,this.bevelFilter=g),0===a.transform.degree&&a.rotateFlipColl.length>0&&(a.img.destLeft+=a.panPoint.totalPannedPoint.x,a.img.destTop+=a.panPoint.totalPannedPoint.y),a.img.destLeft+=a.panPoint.totalPannedInternalPoint.x,a.img.destTop+=a.panPoint.totalPannedInternalPoint.y,0===a.transform.degree&&a.notify("transform",{prop:"setDestPointsForFlipState",onPropertyChange:!1}),a.notify("draw",{prop:"drawImage",onPropertyChange:!1}),a.notify("draw",{prop:"updateCurrTransState",onPropertyChange:!1,value:{type:"reverse",isPreventDestination:null,isRotatePan:null}}),a.notify("draw",{prop:"setRotateZoom",onPropertyChange:!1,value:{isRotateZoom:!1}}),0===a.transform.degree&&a.rotateFlipColl.length>0&&(a.img.destLeft+=a.panPoint.totalPannedPoint.x,a.img.destTop+=a.panPoint.totalPannedPoint.y),n=this.setTempFilterValue(l,i,n,e),t.isNullOrUndefined(i)&&(this.lowerContext.filter=n.join(" ")),a.initialAdjustmentValue=n.join(" "),g=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%)",this.bevelFilter=g,a.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"iterate",pen:"iterate",isPreventApply:null}}),this.lowerContext.filter=g,a.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.lowerContext}}),(a.currSelectionPoint&&"crop-circle"===a.currSelectionPoint.shape||a.isCircleCrop)&&a.notify("crop",{prop:"cropCircle",onPropertyChange:!1,value:{context:this.lowerContext,isSave:null,isFlip:null}}),this.isBrightnessAdjusted=1!==l}var f=n.join(" ");r&&(r.filter=f)},e.prototype.setTempFilterValue=function(e,t,o,i){if(t)if("default"===i)o=this.getDefaultCurrentFilter(o);else if(1!==e){var r=this.lowerContext.filter.split(" ");r[4]=o[4],this.lowerContext.filter=r.join(" ")}return o},e.prototype.getDefaultCurrentFilter=function(e){var t=this.adjustmentValue.split(" ");return[t[0],t[1],t[2],t[3],t[4],t[5],"sepia(0%)","grayscale(0%)","invert(0%)"]},e.prototype.getFilterValue=function(e){return 0===e?1:1+.5*e/100},e.prototype.getSaturationFilterValue=function(e){return 0===e?1:1+e/100},e.prototype.setFilterAdj=function(e,o){var i=this.parent;switch(i.notify("freehand-draw",{prop:"apply-pen-draw",onPropertyChange:!1}),this.adjustmentLevel[""+e]=o,e){case"contrast":case"exposure":o=this.getFilterValue(o),"contrast"===e&&(o*=100);break;case"hue":o*=3;break;case"saturation":o=100*this.getSaturationFilterValue(o);break;case"opacity":o<10&&(o+=1),o/=100;break;case"blur":0!==o&&(o/=20,o+=.5)}var r=t.extend({},i.cropObj,{},!0),a=this.getCurrentObj();a.objColl=t.extend([],i.objColl,[],!0),a.pointColl=t.extend([],i.pointColl,[],!0),a.afterCropActions=t.extend([],i.afterCropActions,[],!0);var n={selPointColl:null};i.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:n}}),a.selPointColl=t.extend([],n.selPointColl,[],!0),this.updateAdj(e,o),i.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:e,previousObj:a,previousObjColl:a.objColl,previousPointColl:a.pointColl,previousSelPointColl:a.selPointColl,previousCropObj:r,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}})},e.prototype.setFilter=function(e){var o=this.parent;e=e.toLowerCase(),o.notify("freehand-draw",{prop:"apply-pen-draw",onPropertyChange:!1});var i={currentFilter:this.parent.currentFilter}.currentFilter,r=t.extend({},o.cropObj,{},!0),a=this.getCurrentObj();a.objColl=t.extend([],o.objColl,[],!0),a.pointColl=t.extend([],o.pointColl,[],!0),a.afterCropActions=t.extend([],o.afterCropActions,[],!0);var n={selPointColl:null};o.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:n}}),a.selPointColl=t.extend([],n.selPointColl,[],!0),this.updateAdj(e,null),o.notify("draw",{prop:"setImageEdited",onPropertyChange:!1}),o.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:e,previousObj:a,previousObjColl:a.objColl,previousPointColl:a.pointColl,previousSelPointColl:a.selPointColl,previousCropObj:r,previousText:null,currentText:null,previousFilter:i,isCircleCrop:null}})},e.prototype.setAdjustment=function(e){var t,o,i=this.lowerContext.filter.split(" ");switch(e){case"brightness":o=i[0].split("("),t=parseFloat(o[1].split(")")[0]),this.adjustmentLevel.brightness=this.setFilterValue(t);break;case"contrast":o=i[1].split("("),t=parseFloat(o[1].split(")")[0]),t/=100,this.adjustmentLevel.contrast=this.setFilterValue(t);break;case"hue":o=i[2].split("("),t=parseFloat(o[1].split(")")[0]),t/=3,this.adjustmentLevel.hue=t;break;case"saturation":o=i[3].split("("),t=parseFloat(o[1].split(")")[0]),t/=100,this.adjustmentLevel.saturation=this.setSaturationFilterValue(t);break;case"opacity":o=i[4].split("("),.45===(t=parseFloat(o[1].split(")")[0]))?t=40:.4===t?t=30:.35===t?t=20:.3===t?t=10:.25===t?t=0:t*=100,this.adjustmentLevel.opacity=t;break;case"blur":o=i[5].split("("),t=parseFloat(o[1].split(")")[0]),t*=20,this.adjustmentLevel.blur=t;break;case"exposure":o=i[0].split("("),t=parseFloat(o[1].split(")")[0]),this.adjustmentLevel.exposure=this.setFilterValue(t)}},e.prototype.setFilterValue=function(e){return Math.round(1===e?0:100*(e-1)/.5)},e.prototype.setSaturationFilterValue=function(e){return Math.round(1===e?0:100*(e-1))},e.prototype.finetuneImage=function(e,t){var o=this.parent;if(!o.disabled&&o.isImageLoaded){switch(e.toLowerCase()){case"brightness":this.setFilterAdj("brightness",t);break;case"contrast":this.setFilterAdj("contrast",t);break;case"hue":this.setFilterAdj("hue",t);break;case"saturation":this.setFilterAdj("saturation",t);break;case"opacity":this.setFilterAdj("opacity",t);break;case"blur":this.setFilterAdj("blur",t);break;case"exposure":this.setFilterAdj("exposure",t)}this.parent.canvasFilter=this.lowerContext.filter,o.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"ok"}})}},e.prototype.setCurrAdjValue=function(e,t){var o=this.parent;switch(this.parent.notify("draw",{prop:"setImageEdited",onPropertyChange:!1}),e){case"brightness":this.setFilterAdj("brightness",t);break;case"contrast":this.setFilterAdj("contrast",t);break;case"hue":this.setFilterAdj("hue",t);break;case"saturation":this.setFilterAdj("saturation",t);break;case"opacity":this.setFilterAdj("opacity",t);break;case"blur":this.setFilterAdj("blur",t);break;case"exposure":this.setFilterAdj("exposure",t)}o.isFinetuneBtnClick=!0,o.curFinetuneObjEvent={finetune:o.toPascalCase(e),value:t}},e.prototype.getCurrentObj=function(e){var o=this.parent,i={point:null};o.notify("crop",{prop:"getTempFlipPanPoint",value:{obj:i}});var r={previousZoomValue:null};o.notify("transform",{prop:"getPreviousZoomValue",value:{obj:r}});var a={zoomFactor:null};o.notify("draw",{prop:"getStraightenInitZoom",value:{obj:a}});var n={color:null};o.notify("draw",{prop:"getImageBackgroundColor",value:{obj:n}});var s={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,straighten:0,destPoints:{startX:0,startY:0,width:0,height:0},frame:"none",srcPoints:{startX:0,startY:0,width:0,height:0},filter:"",isBrightAdjust:this.isBrightnessAdjusted,aspectWidth:null,aspectHeight:null,straightenZoom:0,adjustmentLevel:t.extend({},this.tempAdjVal,{},!0),currentFilter:this.tempFilVal,imageSource:"",bgColor:""};return s.cropZoom=o.transform.cropZoomFactor,s.defaultZoom=o.transform.defaultZoomFactor,s.zoomFactor=o.zoomSettings.zoomFactor,s.previousZoomValue=r.previousZoomValue,s.straightenZoom=a.zoomFactor,s.totalPannedPoint=t.extend({},o.panPoint.totalPannedPoint,{},!0),s.totalPannedClientPoint=t.extend({},o.panPoint.totalPannedClientPoint,{},!0),s.totalPannedInternalPoint=t.extend({},o.panPoint.totalPannedInternalPoint,{},!0),s.tempFlipPanPoint=t.extend({},i.point,{},!0),s.activeObj=t.extend({},o.activeObj,{},!0),s.rotateFlipColl=t.extend([],o.rotateFlipColl,[],!0),s.degree=o.transform.degree,s.straighten=o.cropObj.straighten,s.currFlipState=o.transform.currFlipState,s.destPoints={startX:o.img.destLeft,startY:o.img.destTop,endX:0,endY:0,width:o.img.destWidth,height:o.img.destHeight},s.srcPoints={startX:o.img.srcLeft,startY:o.img.srcTop,endX:0,endY:0,width:o.img.srcWidth,height:o.img.srcHeight},s.filter=this.lowerContext.filter,s.aspectWidth=o.aspectWidth,s.aspectHeight=o.aspectHeight,s.frame=o.frameObj.type,s.frameObj=t.extend({},o.frameObj),s.imageSource=o.baseImg.src,s.bgColor=n.color,e&&(e.currObj=s),s},e.prototype.getValFromPercentage=function(e){var t=parseFloat(e);return/%\s*?$/i.test(e)&&(t/=100),t},e.prototype.getValFromLength=function(e){return parseFloat(e)},e.prototype.parseFilterString=function(e){var t=[];return"none"!==e&&(t=e.split(" ").map(function(e){var t=e.match(/([a-z-]+)\(([^)]+)\)/).slice(1,3);return{filter:t[0],value:t[1]}})),t},e.prototype.applyFilter=function(e){for(var t=e.canvas,o=t.height,i=t.width,r=e.getImageData(0,0,i,o),a=this.parseFilterString(e.filter),n=0,s=a.length;n<s;n++)switch(a[n].filter){case"blur":r=this.blur(e,r,a[n].value);break;case"brightness":r=this.brightness(r,a[n].value);break;case"contrast":r=this.contrast(r,a[n].value);break;case"grayscale":r=this.grayscale(r,a[n].value);break;case"hue-rotate":r=this.hueRotate(r,a[n].value);break;case"invert":r=this.invert(r,a[n].value);break;case"opacity":r=this.opacity(r,a[n].value);break;case"saturate":r=this.saturate(e,r,a[n].value);break;case"sepia":r=this.sepia(r,a[n].value)}e.putImageData(r,0,0)},e.prototype.blur=function(e,t,o){void 0===o&&(o="0");var i=this.getValFromLength(o);if((i=Math.floor(i))<=0)return t;for(var r=e.canvas,a=r.height,n=r.width,s=t.data,l=new Uint8ClampedArray(s.length),p=0;p<a;p++)for(var h=0;h<n;h++){for(var d=0,c=0,u=0,v=0,g=0,f=-i;f<=i;f++)for(var C=-i;C<=i;C++){var b=h+C,m=p+f;if(b>=0&&b<n&&m>=0&&m<a){var y=4*(m*n+b);d+=s[y],c+=s[y+1],u+=s[y+2],v+=s[y+3],g++}}l[P=4*(p*n+h)]=d/g,l[P+1]=c/g,l[P+2]=u/g,l[P+3]=v/g}for(var P=0;P<s.length;P++)s[P]=l[P];return t},e.prototype.brightness=function(e,t){void 0===t&&(t="1");var o=this.getValFromPercentage(t);if(1!==o)for(var i=e.data,r=i.length,a=0;a<r;a+=4)i[a+0]*=o,i[a+1]*=o,i[a+2]*=o;return e},e.prototype.contrast=function(e,t){void 0===t&&(t="1");var o=this.getValFromPercentage(t);if(1!==o)for(var i=e.data,r=i.length,a=0;a<r;a+=4)i[a+0]=255*((i[a+0]/255-.5)*o+.5),i[a+1]=255*((i[a+1]/255-.5)*o+.5),i[a+2]=255*((i[a+2]/255-.5)*o+.5);return e},e.prototype.grayscale=function(e,t){void 0===t&&(t="0");var o=this.getValFromPercentage(t);if(o>0)for(var i=e.data,r=i.length,a=0;a<r;a+=4){var n=i[a],s=i[a+1],l=i[a+2],p=.299*n+.587*s+.114*l;i[a]=n*(1-o)+p*o,i[a+1]=s*(1-o)+p*o,i[a+2]=l*(1-o)+p*o}return e},e.prototype.hueRotate=function(e,t){void 0===t&&(t="0deg");var o=e.data,i=parseFloat(t)*(Math.PI/180);if(i>0)for(var r=Math.cos(i),a=Math.sin(i),n=[.213+.787*r-.213*a,.715-.715*r-.715*a,.072-.072*r+.928*a,.213-.213*r+.143*a,.715+.285*r+.14*a,.072-.072*r-.283*a,.213-.213*r-.787*a,.715-.715*r+.715*a,.072+.928*r+.072*a],s=0;s<o.length;s+=4){var l=o[s],p=o[s+1],h=o[s+2];o[s]=n[0]*l+n[1]*p+n[2]*h,o[s+1]=n[3]*l+n[4]*p+n[5]*h,o[s+2]=n[6]*l+n[7]*p+n[8]*h}return e},e.prototype.invert=function(e,t){void 0===t&&(t="0");var o=this.getValFromPercentage(t);if(o>0)for(var i=e.data,r=i.length,a=0;a<r;a+=4)i[a+0]=Math.abs(i[a+0]-255*o),i[a+1]=Math.abs(i[a+1]-255*o),i[a+2]=Math.abs(i[a+2]-255*o);return e},e.prototype.opacity=function(e,t){void 0===t&&(t="0");var o=this.getValFromPercentage(t);if(o>=0)for(var i=e.data,r=i.length,a=3;a<r;a+=4)i[a]*=o;return e},e.prototype.saturate=function(e,t,o){void 0===o&&(o="0");var i=this.getValFromPercentage(o);if(1!==i)for(var r=e.canvas,a=r.width,n=r.height,s=t.data,l=.3086*(1-i),p=.6094*(1-i),h=.082*(1-i),d=a<<2,c=0;c<n;c++)for(var u=c*d,v=0;v<a;v++){var g=u+(v<<2),f=s[g+0],C=s[g+1],b=s[g+2];s[g+0]=(l+i)*f+p*C+h*b,s[g+1]=l*f+(p+i)*C+h*b,s[g+2]=l*f+p*C+(h+i)*b}return t},e.prototype.sepia=function(e,t){void 0===t&&(t="0");var o=this.getValFromPercentage(t);if(o>1&&(o=1),o>0)for(var i=e.data,r=i.length,a=0;a<r;a+=4){var n=i[a+0],s=i[a+1],l=i[a+2];i[a+0]=(.393*n+.769*s+.189*l)*o+n*(1-o),i[a+1]=(.349*n+.686*s+.168*l)*o+s*(1-o),i[a+2]=(.272*n+.534*s+.131*l)*o+l*(1-o)}return e},e}(),u=function(){function o(e){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.dummyPoints=[],this.tempFHDStyles={strokeColor:null,fillColor:null,strokeWidth:null},this.straightenPoint={x:null,y:null,ratioX:null,ratioY:null},this.straightenPointAngle=0,this.isMasking=!1,this.parent=e,this.addEventListener()}return o.prototype.destroy=function(){this.parent.isDestroyed||this.removeEventListener()},o.prototype.addEventListener=function(){this.parent.on("freehand-draw",this.draw,this),this.parent.on("destroyed",this.destroy,this)},o.prototype.removeEventListener=function(){this.parent.off("freehand-draw",this.draw),this.parent.off("destroyed",this.destroy)},o.prototype.draw=function(e){switch(this.updateFhdPvtVar(),e.prop){case"hoverFhd":this.hoverFhd(e.value.strokeColor,e.value.strokeWidth);break;case"freehandDownHandler":this.freehandDownHandler(e.value.e,e.value.canvas);break;case"freehandUpHandler":this.freehandUpHandler(e.value.e,e.value.canvas,e.value.context);break;case"handle-freehand-draw":o=parseInt(e.value.id.split("_")[1],10)-1;this.isFHDIdx(o)&&this.deleteFhd(o,!0);break;case"freehandRedraw":this.freehandRedraw(e.value.context,e.value.points);break;case"deleteFhd":o=parseInt(e.value.id.split("_")[1],10)-1;this.deleteFhd(o,!0);break;case"selectFhd":var o=null;e.value.id&&(o=parseInt(e.value.id.split("_")[1],10)-1),this.selectFhd(o);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(e.value.value);break;case"panFHDColl":this.panFHDColl(e.value.xDiff,e.value.yDiff,e.value.panRegion);break;case"updateFHDColl":e.value&&e.value.isPreventApply?this.updateFHDColl(e.value.isPreventApply):this.updateFHDColl();break;case"zoomFHDColl":this.zoomFHDColl(e.value.isPreventApply);break;case"apply-pen-draw":this.applyPenDraw();break;case"freeHandDraw":this.freeHandDraw(e.value.value);break;case"isFHDIdx":this.isFHDIdx(e.value.index,e.value.obj);break;case"getSqPtFD":this.getSqPtFD(e.value.idx,e.value.obj);break;case"getSelPointColl":e.value.obj.selPointColl=t.extend([],this.selPointColl);break;case"setSelPointColl":this.selPointColl=t.extend([],e.value.obj.selPointColl);break;case"pushSelPointColl":this.selPointColl.push(t.extend([],e.value.obj.selPointColl));break;case"setFreehandDrawHoveredIndex":this.fhdHovIdx=e.value.index;break;case"getFreehandDrawHoveredIndex":e.value.obj.index=this.fhdHovIdx;break;case"setPointCounter":this.pointCounter=e.value.value;break;case"getPenStrokeWidth":e.value.obj.penStrokeWidth=this.penStrokeWidth;break;case"setPenStrokeWidth":this.penStrokeWidth=e.value.value;break;case"getCurrentFreehandDrawIndex":e.value.obj.currentFreehandDrawIndex=this.currFHDIdx;break;case"setCurrentFreehandDrawIndex":this.currFHDIdx=e.value.value;break;case"updateCropPtsForSel":this.updateCropPtsForSel();break;case"getFreehandDrawSelectedId":e.value.obj.freehandDrawSelectedId=this.fhdSelID;break;case"resetFreehandDrawSelectedId":this.fhdSelID=null;break;case"getTempFreeHandDrawEditingStyles":e.value.obj.tempFreeHandDrawEditingStyles=this.tempFHDStyles;break;case"setFreehandSelectedIndex":this.fhdSelIdx=e.value.index;break;case"getFreehandSelectedIndex":e.value.obj.freehandSelectedIndex=this.fhdSelIdx;break;case"setCenterSelPoints":this.setCenterSelPoints();break;case"getStraightenPoint":e.value.obj.straightenPoint=t.extend({},this.straightenPoint,{},!0);break;case"setStraightenPoint":this.straightenPoint.x=e.value.x,this.straightenPoint.y=e.value.y,e.value.ratioX&&e.value.ratioY&&(this.straightenPoint.ratioX=e.value.ratioX,this.straightenPoint.ratioY=e.value.ratioY);break;case"resetStraightenPoint":this.straightenPoint={x:null,y:null,ratioX:null,ratioY:null},this.prevStraightenObj=null,this.straightenPointAngle=0;break;case"getStraightenPointAngle":e.value.obj.angle=this.straightenPointAngle;break;case"reset":this.reset();break;case"triggerShapeChanging":this.triggerShapeChanging(e.value.shapeChangingArgs);break;case"setMasking":this.isMasking=e.value.value;break;case"resetSelPoints":this.selPoints=[]}},o.prototype.updateFhdPvtVar=function(){var e=this.parent;e.lowerCanvas&&(this.lowerContext=e.lowerCanvas.getContext("2d")),e.upperCanvas&&(this.upperContext=e.upperCanvas.getContext("2d"))},o.prototype.reset=function(){this.fhdObj={lastWidth:0,lastVelocity:0,time:0,pointX:0,pointY:0},this.isFreehandDrawing=this.isFreehandPointMoved=!1,this.selPoints=[],this.dummyPoints=[],this.freehandDownPoint={x:0,y:0},this.selPointColl={},this.straightenPointAngle=0,this.fhdHovIdx=null,this.pointCounter=0,this.fhdSelID=null,this.isMasking=!1,this.penStrokeWidth=void 0,this.currFHDIdx=0,this.fhdSelIdx=null,this.tempFHDStyles={strokeColor:null,fillColor:null,strokeWidth:null},this.straightenPoint={x:null,y:null,ratioX:null,ratioY:null},this.prevStraightenObj=null},o.prototype.getModuleName=function(){return"freehand-draw"},o.prototype.hoverFhd=function(e,o){var i=this.parent,r=this.upperContext,a=-1;a=this.fhdHovIdx>-1?this.fhdHovIdx:this.fhdSelIdx,i.points=t.extend([],i.pointColl[a].points),this.pointCounter=0;var n,s,l,p,h=i.points.length,d=0,c=0;r.fillStyle=e||i.pointColl[a].strokeColor,r.strokeStyle=r.fillStyle,d=c=this.penStrokeWidth=o||i.pointColl[a].strokeWidth,1===h&&(n=s=l=p=i.points[0],this.startDraw(r,n,s,l,p,d,c));for(var u=0;u<h-3;u++)i.points[u+1]&&i.points[u+2]&&i.points[u+2]&&(n=this.calcCurveCP(i.points[u+0],i.points[u+1],i.points[u+2]).controlPoint2,s=this.calcCurveCP(i.points[u+1],i.points[u+2],i.points[u+3]).controlPoint1,l=0===u?i.points[u]:i.points[u+1],p=i.points[u+2],this.startDraw(r,n,s,l,p,d,c));r.closePath();var v=this.getSqPtFD(a),g=r.lineWidth;r.lineWidth=2,r.strokeStyle=i.themeColl[i.theme].primaryColor,r.beginPath(),r.rect(v.startX,v.startY,v.width,v.height),r.stroke(),r.closePath(),r.lineWidth=g},o.prototype.freehandDownHandler=function(o,i){var r=this.parent;r.lowerCanvas=document.querySelector("#"+r.element.id+"_lowerCanvas"),this.lowerContext=r.lowerCanvas.getContext("2d"),r.upperCanvas=document.querySelector("#"+r.element.id+"_upperCanvas"),this.upperContext=r.upperCanvas.getContext("2d"),this.fhdObj.time=(new Date).getTime(),this.isFreehandDrawing=!0,"mousedown"===o.type?this.freehandDownPoint={x:o.clientX,y:o.clientY}:this.freehandDownPoint={x:o.touches[0].clientX,y:o.touches[0].clientY},this.isFreehandPointMoved=!1,t.EventHandler.add(i,"mousemove touchmove",this.freehandMoveHandler,this);var a={id:"pen_"+(this.currFHDIdx+1),type:e.ShapeType.FreehandDraw,startX:this.freehandDownPoint.x,startY:this.freehandDownPoint.y,strokeColor:r.activeObj.strokeSettings.strokeColor,strokeWidth:this.penStrokeWidth,points:null,index:r.objColl.length+r.freehandCounter+1},n={cancel:!1,action:"draw-start",previousShapeSettings:a,currentShapeSettings:a};this.triggerShapeChanging(n)},o.prototype.freehandUpHandler=function(o,i,r){var a=i.getBoundingClientRect(),n=this.parent;t.EventHandler.remove(i,"mousemove touchmove",this.freehandMoveHandler),0===n.points.length&&("mouseup"===o.type?this.processPoint(o.clientX-a.left,o.clientY-a.top,!0,r):"touchend"===o.type&&o.changedTouches?this.processPoint(o.changedTouches[0].clientX-a.left,o.changedTouches[0].clientY-a.top,!0,r):this.isFreehandPointMoved||this.processPoint(this.freehandDownPoint.x-a.left,this.freehandDownPoint.y-a.top,!0,r)),r.closePath();var s=t.extend({},n.cropObj,{},!0),l={currObj:{}};n.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:l}});var p=l.currObj;p.objColl=t.extend([],n.objColl,[],!0),p.pointColl=t.extend([],n.pointColl,[],!0),p.afterCropActions=t.extend([],n.afterCropActions,[],!0);var h={selPointColl:null};n.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:h}}),p.selPointColl=t.extend([],h.selPointColl,[],!0);var d=n.freehandCounter,c=n.objColl.length+n.freehandCounter+1;n.pointColl[d]={points:t.extend([],n.points),strokeColor:n.activeObj.strokeSettings.strokeColor,strokeWidth:this.penStrokeWidth,flipState:n.transform.currFlipState,id:"pen_"+(this.currFHDIdx+1),order:c},n.points=[],this.dummyPoints=[],this.selPointColl[d]={points:t.extend([],this.selPoints)},this.selPoints=[],this.pointCounter=0,n.freehandCounter++,this.isFreehandDrawing=!1,n.isMaskImage||n.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"freehand-draw",previousObj:p,previousObjColl:p.objColl,previousPointColl:p.pointColl,previousSelPointColl:p.selPointColl,previousCropObj:s,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}});var u={id:"pen_"+(this.currFHDIdx+1),type:e.ShapeType.FreehandDraw,startX:this.freehandDownPoint.x,startY:this.freehandDownPoint.y,strokeColor:n.activeObj.strokeSettings.strokeColor,strokeWidth:this.penStrokeWidth,points:n.pointColl[this.currFHDIdx].points,index:c},v={cancel:!1,action:"draw-end",previousShapeSettings:u,currentShapeSettings:u};this.triggerShapeChanging(v),this.currFHDIdx++},o.prototype.freehandMoveHandler=function(e){this.isFreehandPointMoved=!0;var t,o,i=this.parent.upperCanvas.getBoundingClientRect();"mousemove"===e.type?(t=e.clientX-i.left,o=e.clientY-i.top):(t=e.touches[0].clientX-i.left,o=e.touches[0].clientY-i.top),this.isFreehandDrawing&&(this.upperContext.fillStyle=this.parent.activeObj.strokeSettings.strokeColor,this.parent.isMaskImage&&(this.upperContext.globalCompositeOperation="xor"),this.processPoint(t,o,!1,this.upperContext))},o.prototype.processPoint=function(e,o,i,r){var a,n,s,l,p=this.parent,h=this.point(e,o,(new Date).getTime()),d=!!(h=p.points.length>0&&p.points[p.points.length-1])&&this.distanceTo(h)<=5;if(this.selPoints.push({x:e,y:o,ratioX:(e-p.img.destLeft)/p.img.destWidth,ratioY:(o-p.img.destTop)/p.img.destHeight,time:this.fhdObj.time}),!h||!h||!d||i){if(this.fhdObj.time=(new Date).getTime(),p.points.push({x:e,y:o,ratioX:(e-p.img.destLeft)/p.img.destWidth,ratioY:(o-p.img.destTop)/p.img.destHeight,time:this.fhdObj.time}),this.dummyPoints.push({x:e,y:o,ratioX:(e-p.img.destLeft)/p.img.destWidth,ratioY:(o-p.img.destTop)/p.img.destHeight,time:this.fhdObj.time}),this.dummyPoints.length>2){3===this.dummyPoints.length&&this.dummyPoints.unshift(this.dummyPoints[0]);var c=this.dummyPoints[0],u=this.dummyPoints[1],v=this.dummyPoints[2],g=this.dummyPoints[3];a=this.calcCurveCP(c,u,v).controlPoint2,n=this.calcCurveCP(u,v,g).controlPoint1,s=this.dummyPoints[1],l=this.dummyPoints[2];var f=.5,C=5;t.isNullOrUndefined(this.penStrokeWidth)||(f=C=this.penStrokeWidth),this.startDraw(r,a,n,s,l,f,C),this.pointCounter++,this.dummyPoints.shift()}if(i){a=n=s=l={x:e,y:o,time:(new Date).getTime()};var f=.5,C=5;t.isNullOrUndefined(this.penStrokeWidth)||(f=C=this.penStrokeWidth),this.startDraw(r,a,n,s,l,f,C)}}},o.prototype.calcCurveCP=function(e,t,o){t||(t=e),o||(o=t);var i=e.x-t.x,r=e.y-t.y,a=t.x-o.x,n=t.y-o.y,s={x:(e.x+t.x)/2,y:(e.y+t.y)/2},l={x:(t.x+o.x)/2,y:(t.y+o.y)/2},p=Math.sqrt(i*i+r*r),h=Math.sqrt(a*a+n*n),d=s.x-l.x,c=s.y-l.y,u=h/(p+h),v={x:l.x+d*u,y:l.y+c*u},g=t.x-v.x,f=t.y-v.y;return{controlPoint1:this.point(s.x+g,s.y+f,0),controlPoint2:this.point(l.x+g,l.y+f,0)}},o.prototype.point=function(e,t,o){return this.fhdObj.pointX=e,this.fhdObj.pointY=t,{x:this.fhdObj.pointX,y:this.fhdObj.pointY,time:o}},o.prototype.startDraw=function(e,t,o,i,r,a,n){var s;s=.7*(s=this.pointVelocity(i))+(1-.7)*this.fhdObj.lastVelocity;var l=Math.max(n/1.7,a);this.drawCurve(this.fhdObj.time,l,e,t,o,i,r,n),this.fhdObj.lastVelocity=s,this.fhdObj.time=l},o.prototype.pointVelocity=function(e){return this.fhdObj.time!==e.time?this.distanceTo(e)/(this.fhdObj.time-e.time):0},o.prototype.distanceTo=function(e){return Math.sqrt(Math.pow(this.fhdObj.pointX-e.x,2)+Math.pow(this.fhdObj.pointY-e.y,2))},o.prototype.drawCurve=function(e,t,o,i,r,a,n,s){var l,p,h,d,c,u,v,g,f,C,b=t-e,m=this.bezierLength(i,r,a,n),y=2*Math.ceil(m);for(o.beginPath(),p=0;p<y;p++)c=(d=(h=p/y)*h)*h,f=(g=(v=(u=1-h)*u)*u)*a.x,f+=3*v*h*i.x,f+=3*u*d*r.x,f+=c*n.x,C=g*a.y,C+=3*v*h*i.y,C+=3*u*d*r.y,C+=c*n.y,l=Math.min(e+c*b,s),this.drawArc(f,C,l,o);o.closePath(),o.fill()},o.prototype.bezierLength=function(e,t,o,i){var r,a,n,s,l,p,h,d,c=0;for(r=0;r<=10;r++)a=r/10,n=this.bezierPoint(a,o.x,e.x,t.x,i.x),s=this.bezierPoint(a,o.y,e.y,t.y,i.y),r>0&&(h=n-l,d=s-p,c+=Math.sqrt(h*h+d*d)),l=n,p=s;return c},o.prototype.bezierPoint=function(e,t,o,i,r){return t*(1-e)*(1-e)*(1-e)+3*o*(1-e)*(1-e)*e+3*i*(1-e)*e*e+r*e*e*e},o.prototype.drawArc=function(e,t,o,i){var r=this.parent.img;(e>r.destLeft&&t>r.destTop&&e<r.destLeft+r.destWidth&&t<r.destTop+r.destHeight||i!==this.lowerContext&&i!==this.upperContext)&&(i.moveTo(e,t),i.arc(e,t,o,0,2*Math.PI,!1))},o.prototype.freehandRedraw=function(e,o){var i=this.parent,r=e.filter;if(e.filter="none",o&&(i.pointColl[i.freehandCounter]={points:o,strokeColor:i.activeObj.strokeSettings.strokeColor,strokeWidth:this.penStrokeWidth,flipState:i.transform.currFlipState,id:"pen_"+(i.freehandCounter+1),order:i.objColl.length+i.freehandCounter+1},this.selPointColl[i.freehandCounter]=t.extend({},i.pointColl[i.freehandCounter],{},!0),i.freehandCounter++),i.freehandCounter>0){for(var a=0;a<i.freehandCounter;a++){i.points=t.extend([],i.pointColl[a].points),this.pointCounter=0;var n=i.points.length,s=void 0,l=void 0,p=void 0,h=void 0,d=void 0,c=void 0;n>0&&(e.fillStyle=i.pointColl[a].strokeColor,d=c=this.penStrokeWidth=i.pointColl[a].strokeWidth),1===n&&(s=l=p=h=i.points[0],this.startDraw(e,s,l,p,h,d,c));for(var u=0;u<n-3;u++)i.points[u+1]&&i.points[u+2]&&i.points[u+2]&&(s=this.calcCurveCP(i.points[u+0],i.points[u+1],i.points[u+2]).controlPoint2,l=this.calcCurveCP(i.points[u+1],i.points[u+2],i.points[u+3]).controlPoint1,p=0===u?i.points[u]:i.points[u+1],h=i.points[u+2],this.startDraw(e,s,l,p,h,d,c));e.closePath()}e===this.lowerContext&&(i.notify("draw",{prop:"applyFrame",value:{ctx:this.lowerContext,frame:i.frameObj.type,preventImg:!0}}),this.upperContext.clearRect(0,0,i.upperCanvas.width,i.upperCanvas.height))}e.filter=r},o.prototype.getSqPtFD=function(e,o){var i={startX:0,startY:0,endX:0,endY:0,width:0,height:0},r=t.extend([],this.selPointColl[e].points,[]);this.parent.points=t.extend([],this.parent.pointColl[e].points),this.pointCounter=0;for(var a=r.length,n=0;n<a;n++)0===i.startX&&0===i.startY&&0===i.endX&&0===i.endY?(i.startX=r[n].x,i.startY=r[n].y,i.endX=r[n].x,i.endY=r[n].y):(i.startX=Math.min(i.startX,r[n].x),i.startY=Math.min(i.startY,r[n].y),i.endX=Math.max(i.endX,r[n].x),i.endY=Math.max(i.endY,r[n].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,o&&(o.activePoint=i),i},o.prototype.applyPenDraw=function(){var e=this.parent;"freehanddraw"===e.currObjType.shape&&(e.notify("shape",{prop:"apply",onPropertyChange:!1,value:{shape:null,obj:null,canvas:null}}),e.upperCanvas.style.cursor=e.cursor="default",e.currObjType.shape=""),e.notify("shape",{prop:"clearActObj"})},o.prototype.applyFhd=function(){var e=this.parent,t=e.pointColl[this.fhdSelIdx];"#42a5f5"===t.strokeColor&&(t.strokeColor=this.tempFHDStyles.strokeColor),e.notify("toolbar",{prop:"setSelectedFreehandColor",value:{color:"#42a5f5"}}),this.upperContext.clearRect(0,0,e.upperCanvas.width,e.upperCanvas.height),this.lowerContext.clearRect(0,0,e.lowerCanvas.width,e.lowerCanvas.height),e.notify("draw",{prop:"render-image",value:{isMouseWheel:null}}),e.notify("toolbar",{prop:"refresh-main-toolbar",onPropertyChange:!1}),t&&(t.isSelected=!1),e.notify("selection",{prop:"resetFreehandDrawVariables"}),this.fhdHovIdx=this.fhdSelIdx=null},o.prototype.cancelFhd=function(){var e=this.parent,t=e.pointColl[this.fhdSelIdx];e.notify("toolbar",{prop:"setSelectedFreehandColor",value:{color:"#42a5f5"}}),this.upperContext.clearRect(0,0,e.upperCanvas.width,e.upperCanvas.height),this.lowerContext.clearRect(0,0,e.upperCanvas.width,e.upperCanvas.height),this.pointCounter=0,t&&(t.strokeColor=this.tempFHDStyles.strokeColor,t.strokeWidth=this.tempFHDStyles.strokeWidth,t.isSelected=!1),this.fhdHovIdx=this.fhdSelIdx=this.fhdSelID=null,e.notify("selection",{prop:"resetFreehandDrawVariables"}),e.activeObj.strokeSettings.strokeColor=this.tempFHDStyles.strokeColor,e.activeObj.strokeSettings.strokeWidth=this.penStrokeWidth=this.tempFHDStyles.strokeWidth,this.tempFHDStyles={strokeColor:null,strokeWidth:null,fillColor:null},e.notify("draw",{prop:"render-image",value:{isMouseWheel:null}}),e.notify("toolbar",{prop:"refresh-main-toolbar",onPropertyChange:!1})},o.prototype.selectFhd=function(o){var i=this.parent,r=t.extend({},this.tempFHDStyles,{},!0);if(i.notify("selection",{prop:"setFreehandDrawEditing",onPropertyChange:!1,value:{bool:!0}}),o||0===o){if(!this.isFHDIdx(o))return;this.fhdSelIdx=this.fhdHovIdx=o,this.hoverFhd(),i.upperCanvas.style.cursor=i.cursor="pointer"}this.fhdSelIdx=this.fhdHovIdx;var a=i.pointColl[this.fhdSelIdx];a.isSelected=!0,this.fhdSelID=a.id,"#42a5f5"!==a.strokeColor&&(i.activeObj.strokeSettings.strokeColor=this.tempFHDStyles.strokeColor=a.strokeColor),i.activeObj.strokeSettings.strokeWidth=this.tempFHDStyles.strokeWidth=i.pointColl[this.fhdHovIdx].strokeWidth;var n={bool:!1};if(i.notify("selection",{prop:"getFreehandDrawEditing",onPropertyChange:!1,value:{obj:n}}),n.bool){var s={id:"pen_"+(this.fhdSelIdx+1),type:e.ShapeType.FreehandDraw,startX:a.points[0].x,startY:a.points[0].y,strokeColor:a.strokeColor,strokeWidth:a.strokeWidth,points:a.points,opacity:a.opacity,index:a.order},l={cancel:!1,action:"select",previousShapeSettings:s,currentShapeSettings:s};this.triggerShapeChanging(l)}else i.okBtn(null,!0);i.isUndoRedoStack&&(this.tempFHDStyles=r)},o.prototype.deleteFhd=function(e,o){var i=this.parent;if(this.isFHDIdx(e)){this.upperContext.clearRect(0,0,i.upperCanvas.width,i.upperCanvas.height);var r=t.extend({},i.pointColl,{},!0),a=t.extend({},this.selPointColl,{},!0);i.pointColl={},this.selPointColl={};for(var n=0,s=0;s<i.freehandCounter;s++)parseInt(r[s].id.split("_")[1],10)-1!==e&&(i.pointColl[n]=r[s],this.selPointColl[n]=a[s],n++);i.freehandCounter-=1,this.fhdHovIdx=this.fhdSelIdx=null,i.notify("selection",{prop:"resetFreehandDrawVariables"}),i.notify("draw",{prop:"render-image",value:{isMouseWheel:null}}),i.notify("toolbar",{prop:"refresh-main-toolbar",onPropertyChange:!1})}},o.prototype.zoomX=function(e){return e*this.parent.img.destWidth+this.parent.img.destLeft},o.prototype.zoomY=function(e){return e*this.parent.img.destHeight+this.parent.img.destTop},o.prototype.zoomFHDColl=function(e){var o=this.parent,i={startX:o.img.destLeft,startY:o.img.destTop,width:o.img.destWidth,height:o.img.destHeight};o.notify("shape",{prop:"straightenShapes",onPropertyChange:!1});for(var r=0;r<o.freehandCounter;r++){o.points=t.extend([],o.pointColl[r].points,[]),this.pointCounter=0;for(var a=o.points.length,n=0;n<a;n++){var s=o.points[n];s.x=this.zoomX(s.ratioX),s.y=this.zoomY(s.ratioY)}}this.updateFHDCurPts(),this.straightenPoint.x&&this.straightenPoint.y&&(this.straightenPoint.x=this.zoomX(this.straightenPoint.ratioX),this.straightenPoint.y=this.zoomY(this.straightenPoint.ratioY)),0!==o.transform.straighten&&o.notify("shape",{prop:"straightenFHD",onPropertyChange:!1}),o.img.destLeft=i.startX,o.img.destTop=i.startY,o.img.destWidth=i.width,o.img.destHeight=i.height,t.isNullOrUndefined(e)&&this.freehandRedraw(this.lowerContext,null)},o.prototype.updateFHDCurPts=function(){for(var e=this.parent,o=0;o<e.freehandCounter;o++)if(this.selPointColl[o]){this.selPoints=t.extend([],this.selPointColl[o].points,[]),this.pointCounter=0;for(var i=this.selPoints.length,r=0;r<i;r++){var a=this.selPoints[r];a.x=this.zoomX(a.ratioX),a.y=this.zoomY(a.ratioY)}}},o.prototype.rotateFhdColl=function(){for(var e=this.parent,o=e.img,i=o.destLeft,r=o.destTop,a=o.destWidth,n=o.destHeight,s=0;s<e.freehandCounter;s++){e.points=t.extend([],e.pointColl[s].points,[]),this.pointCounter=0;for(var l=e.points.length,p=0;p<l;p++)(h=e.points[p]).y=r+n*h.ratioX,h.x=i+a-a*h.ratioY,h.ratioX=(h.x-i)/a,h.ratioY=(h.y-r)/n}for(s=0;s<e.freehandCounter;s++)if(this.selPointColl[s]){this.selPoints=t.extend([],this.selPointColl[s].points,[]),this.pointCounter=0;for(var l=this.selPoints.length,p=0;p<l;p++){var h=this.selPoints[p];h.y=r+n*h.ratioX,h.x=i+a-a*h.ratioY,h.ratioX=(h.x-i)/a,h.ratioY=(h.y-r)/n}}this.updateFHDCurPts()},o.prototype.flipFHDColl=function(e){var t=e.toLowerCase();if("horizontal"===t)this.pointsHorizontalFlip();else if("vertical"===t)this.pointsVerticalFlip();else{this.pointsHorizontalFlip();for(var o=0;o<this.parent.freehandCounter;o++)this.parent.pointColl[o].shapeFlip="";this.pointsVerticalFlip()}},o.prototype.pointsHorizontalFlip=function(){for(var e=this.parent,o=e.img,i=o.destLeft,r=o.destTop,a=o.destWidth,n=o.destHeight,s=0;s<e.freehandCounter;s++)if(e.pointColl[s].shapeFlip!==e.transform.currFlipState){e.points=t.extend([],e.pointColl[s].points,[]),this.pointCounter=0;for(var l=e.points.length,p=0;p<l;p++)(h=e.points[p]).x<=i+a/2?h.x=i+a-(h.x-i):h.x>=i+a/2&&(h.x=i+(i+a-h.x)),h.ratioX=(h.x-i)/a,h.ratioY=(h.y-r)/n;e.pointColl[s].shapeFlip=e.transform.currFlipState}for(s=0;s<e.freehandCounter;s++)if(this.selPointColl[s]&&this.selPointColl[s].shapeFlip!==e.transform.currFlipState){this.selPoints=t.extend([],this.selPointColl[s].points,[]),this.pointCounter=0;for(var l=this.selPoints.length,p=0;p<l;p++){var h=this.selPoints[p];h.x<=i+a/2?h.x=i+a-(h.x-i):h.x>=i+a/2&&(h.x=i+(i+a-h.x)),h.ratioX=(h.x-i)/a,h.ratioY=(h.y-r)/n}}this.updateFHDCurPts()},o.prototype.pointsVerticalFlip=function(){for(var e=this.parent,o=e.img,i=o.destLeft,r=o.destTop,a=o.destWidth,n=o.destHeight,s=0;s<e.freehandCounter;s++)if(e.pointColl[s].shapeFlip!==e.transform.currFlipState){e.points=t.extend([],e.pointColl[s].points,[]),this.pointCounter=0;for(var l=e.points.length,p=0;p<l;p++)(h=e.points[p]).y<=r+n/2?h.y=r+n-(h.y-r):h.y>=r+n/2&&(h.y=r+(r+n-h.y)),h.ratioX=(h.x-i)/a,h.ratioY=(h.y-r)/n;e.pointColl[s].shapeFlip=e.transform.currFlipState}for(s=0;s<e.freehandCounter;s++)if(this.selPointColl[s]&&this.selPointColl[s].shapeFlip!==e.transform.currFlipState){this.selPoints=t.extend([],this.selPointColl[s].points,[]),this.pointCounter=0;for(var l=this.selPoints.length,p=0;p<l;p++){var h=this.selPoints[p];h.y<=r+n/2?h.y=r+n-(h.y-r):h.y>=r+n/2&&(h.y=r+(r+n-h.y)),h.ratioX=(h.x-i)/a,h.ratioY=(h.y-r)/n}}this.updateFHDCurPts()},o.prototype.updateFHDColl=function(e){var o=this.parent,i={startX:o.img.destLeft,startY:o.img.destTop,width:o.img.destWidth,height:o.img.destHeight};o.notify("shape",{prop:"straightenShapes",onPropertyChange:!1});for(var r=o.img,a=r.destLeft,n=r.destTop,s=r.destWidth,l=r.destHeight,p=0,h=o.objColl.length;p<h;p++){var d=o.objColl[p];if("line"===d.shape||"arrow"===d.shape)o.notify("shape",{prop:"straightenShapePoints",value:{obj:d,isReverse:!0}});else if("path"===d.shape){v=o.transform.straighten;o.transform.straighten=-o.transform.straighten,o.notify("shape",{prop:"straightenPath",onPropertyChange:!1,value:{obj:d}}),o.transform.straighten=v}if(d.imageRatio={startX:(d.activePoint.startX-a)/s,startY:(d.activePoint.startY-n)/l,endX:(d.activePoint.endX-a)/s,endY:(d.activePoint.endY-n)/l,width:s/d.activePoint.width,height:l/d.activePoint.height},"path"===d.shape)for(var c=0,u=d.pointColl.length;c<u;c++)d.pointColl[c].ratioX=(d.pointColl[c].x-a)/s,d.pointColl[c].ratioY=(d.pointColl[c].y-n)/l;o.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1})}if(o.freehandCounter>0&&0!==o.transform.straighten){var v=o.transform.straighten;o.transform.straighten=-o.transform.straighten,o.notify("shape",{prop:"straightenFHD",onPropertyChange:!1}),o.transform.straighten=v}for(C=0;C<o.freehandCounter;C++){o.points=t.extend([],o.pointColl[C].points,[]),this.pointCounter=0;for(var g=o.points.length,f=0;f<g;f++)(b=o.points[f]).ratioX=(b.x-a)/s,b.ratioY=(b.y-n)/l}for(var C=0;C<o.freehandCounter;C++)if(this.selPointColl[C]){this.selPoints=t.extend([],this.selPointColl[C].points,[]),this.pointCounter=0;for(var g=this.selPoints.length,f=0;f<g;f++){var b=this.selPoints[f];b.ratioX=(b.x-a)/s,b.ratioY=(b.y-n)/l}}this.straightenPoint.x&&this.straightenPoint.y&&(this.straightenPoint.ratioX=(this.straightenPoint.x-a)/s,this.straightenPoint.ratioY=(this.straightenPoint.y-n)/l),o.img.destLeft=i.startX,o.img.destTop=i.startY,o.img.destWidth=i.width,o.img.destHeight=i.height,o.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"zoom",pen:"zoom",isPreventApply:e}})},o.prototype.panFHDColl=function(e,o,i){for(var r=this.parent,a=0;a<r.freehandCounter;a++){r.points=t.extend([],r.pointColl[a].points,[]),this.pointCounter=0;for(var n=r.points.length,s=0;s<n;s++){l=r.points[s];""===i||"vertical"===i?l.x+=e:l.x-=e,""===i||"horizontal"===i?l.y+=o:l.y-=o}}for(a=0;a<r.freehandCounter;a++)if(this.selPointColl[a]){this.selPoints=t.extend([],this.selPointColl[a].points,[]),this.pointCounter=0;for(var n=this.selPoints.length,s=0;s<n;s++){var l=this.selPoints[s];""===i||"vertical"===i?l.x+=e:l.x-=e,""===i||"horizontal"===i?l.y+=o:l.y-=o}}this.straightenPoint.x&&this.straightenPoint.y&&(""===i||"vertical"===i?this.straightenPoint.x+=e:this.straightenPoint.x-=e,""===i||"horizontal"===i?this.straightenPoint.y+=o:this.straightenPoint.y-=o),this.freehandRedraw(this.lowerContext,null)},o.prototype.freeHandDraw=function(e){var o=this.parent;if(e){if(o.points=[],this.dummyPoints=[],o.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),o.togglePen=!0,o.upperCanvas.style.cursor=o.cursor="crosshair",o.upperCanvas.style.display="block",t.isNullOrUndefined(o.activeObj.strokeSettings)){var i={strokeSettings:{}};o.notify("shape",{prop:"getStrokeSettings",onPropertyChange:!1,value:{obj:i}}),o.activeObj.strokeSettings=i.strokeSettings}t.isNullOrUndefined(o.activeObj.strokeSettings.strokeWidth)&&(o.activeObj.strokeSettings.strokeWidth=2),o.isMaskImage?o.notify("toolbar",{prop:"refresh-main-toolbar",onPropertyChange:!1}):o.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"pen",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}})}else{o.upperCanvas.style.cursor=o.cursor="default";var r=this.penStrokeWidth;o.notify("shape",{prop:"apply",onPropertyChange:!1,value:{shape:null,obj:null,canvas:null}}),o.notify("toolbar",{prop:"refresh-main-toolbar",onPropertyChange:!1}),o.notify("toolbar",{prop:"setCurrentToolbar",value:{type:"main"}}),o.notify("selection",{prop:"setFreehandDrawCustomized",value:{isFreehandDrawCustomized:!1}}),this.penStrokeWidth=r}},o.prototype.isFHDIdx=function(e,t){for(var o=!1,i=0;i<this.parent.freehandCounter;i++)if(this.parent.pointColl[i].id&&parseInt(this.parent.pointColl[i].id.split("_")[1],10)-1===e){o=!0;break}return t&&(t.isIndex=o),o},o.prototype.updateCropPtsForSel=function(){for(var e=this.parent,o=e.activeObj.activePoint,i=0;i<e.freehandCounter;i++){var r={selPointColl:t.extend([],this.selPointColl)};if(r.selPointColl[i]){this.selPoints=t.extend([],r.selPointColl[i].points,[]),this.pointCounter=0;for(var a=this.selPoints.length,n=0;n<a;n++){var s=this.selPoints[n];s.ratioX=(s.x-o.startX)/o.width,s.ratioY=(s.y-o.startY)/o.height}}}},o.prototype.triggerShapeChanging=function(e){var t=this.parent,o=t.pointColl[this.fhdSelIdx];if(t.trigger("shapeChanging",e),"mask-drawing"===t.element.getAttribute("data-value")&&!this.isMasking)return this.isMasking=!0,t.upperCanvas.style.cursor="crosshair",t.notify("draw",{prop:"updateTempObjColl"}),t.notify("draw",{prop:"updateTempPointColl"}),t.discard(),void t.selectMaskImage();if(t.editCompleteArgs=e,-1===e.currentShapeSettings.id.indexOf("pen_")&&("draw-end"===e.action||"select"===e.action)){var i="pen_"+e.currentShapeSettings.id;this.fhdSelIdx?t.pointColl[this.fhdSelIdx].id=i:t.pointColl[t.freehandCounter-1].id=i}this.penStrokeWidth=e.currentShapeSettings.strokeWidth,t.activeObj.strokeSettings.strokeColor!==e.currentShapeSettings.strokeColor&&(t.activeObj.strokeSettings.strokeColor=e.currentShapeSettings.strokeColor,t.notify("toolbar",{prop:"update-toolbar-items",onPropertyChange:!1})),this.fhdSelID&&o&&e.currentShapeSettings&&(o.strokeColor=e.currentShapeSettings.strokeColor,o.strokeWidth=e.currentShapeSettings.strokeWidth,o.points=e.currentShapeSettings.points,o.opacity=e.currentShapeSettings.opacity),"select"===e.action&&(this.freehandRedraw(this.upperContext),t.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"pen",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}}))},o.prototype.setCenterSelPoints=function(){var e=this.parent,o={startX:e.img.destLeft,startY:e.img.destTop,width:e.img.destWidth,height:e.img.destHeight};e.notify("shape",{prop:"straightenShapes",onPropertyChange:!1});var i=e.img,r=i.destLeft,a=i.destTop,n=i.destWidth,s=i.destHeight,l=e.activeObj.activePoint;(t.isNullOrUndefined(this.prevStraightenObj)||JSON.stringify(this.prevStraightenObj.activePoint)!==JSON.stringify(l))&&(this.straightenPoint={x:l.startX+l.width/2,y:l.startY+l.height/2,ratioX:(l.startX+l.width/2-r)/n,ratioY:(l.startY+l.height/2-a)/s},this.prevStraightenObj=t.extend({},e.activeObj,{},!0),this.straightenPointAngle=e.transform.straighten),e.img.destLeft=o.startX,e.img.destTop=o.startY,e.img.destWidth=o.width,e.img.destHeight=o.height},o}(),v=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:[],order:null},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.isImageClarity=!0,this.isPinching=!1,this.isSliding=!1,this.mouseDown="",this.isSliderActive=!1,this.arrowShape=[e.ArrowheadType.None,e.ArrowheadType.SolidArrow],this.isTouchDblClick=!1,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(e){var t=this.parent;switch(this.updatePrivateVariables(),e.prop){case"setCursor":this.setCursor(e.value.x,e.value.y);break;case"updateActivePoint":this.updateActivePoint(e.value.x,e.value.y,e.value.isCropSelection);break;case"updateCursorStyles":this.updateCursorStyles(e.value.x,e.value.y,e.value.type);break;case"setTextSelection":this.setTextSelection(e.value.width,e.value.height);break;case"setActivePoint":this.setActivePoint(e.value.startX,e.value.startY);break;case"clearSelection":this.clearSelection(e.value.resetCrop);break;case"calcShapeRatio":this.calcShapeRatio(e.value.x,e.value.y,e.value.imgWidth,e.value.imgHeight);break;case"tab":this.performTabAction();break;case"setDragDirection":this.setDragDirection(e.value.width,e.value.height);break;case"clearUpperCanvas":this.isTouch&&setTimeout(function(){t.upperCanvas.getContext("2d").clearRect(0,0,t.upperCanvas.width,t.upperCanvas.height)},550);break;case"resetFreehandDrawVariables":this.isFhdEditing=this.isFhdPoint=!1;break;case"isShapeInserted":this.isShapeInserted=e.value.bool;break;case"redrawShape":this.redrawShape(e.value.obj);break;case"setTextBoxStylesToActObj":this.setTextBoxStylesToActObj();break;case"mouseDownEventHandler":this.mouseDownEventHandler(e.value.e);break;case"mouseMoveEventHandler":this.mouseMoveEventHandler(e.value.e);break;case"mouseUpEventHandler":this.mouseUpEventHandler(e.value.e);break;case"canvasMouseDownHandler":this.canvasMouseDownHandler(e.value.e);break;case"canvasMouseMoveHandler":this.canvasMouseMoveHandler(e.value.e);break;case"canvasMouseUpHandler":this.canvasMouseUpHandler(e.value.e);break;case"touchStartHandler":this.touchStartHandler(e.value.e);break;case"keyDownEventHandler":this.keyDownEventHandler(e.value.e);break;case"handleScroll":this.handleScroll(e.value.e);break;case"textKeyDown":setTimeout(this.textKeyDown.bind(this),1,e.value.e);break;case"deleteItem":this.deleteItem();break;case"updatePrevShapeSettings":this.updatePrevShapeSettings(e.value.obj);break;case"getZoomType":e.value.obj.zoomType=this.zoomType;break;case"setZoomType":this.zoomType=e.value.zoomType;break;case"setInitialTextEdit":this.isInitialTextEdited=e.value.bool;break;case"setDragCanvas":this.dragCanvas=e.value.bool;break;case"setFreehandDrawCustomized":this.isFhdCustomized=e.value.isFreehandDrawCustomized;break;case"setTouchEndPoint":this.touchEndPoint.x=e.value.x,this.touchEndPoint.y=e.value.y;break;case"getPanDown":e.value.obj.panDown=this.panDown;break;case"setPanDown":this.panDown=e.value.panDown;break;case"getFreehandDrawEditing":e.value.obj.bool=this.isFhdEditing;break;case"setFreehandDrawEditing":this.isFhdEditing=e.value.bool;break;case"getTempActObj":e.value.obj.tempObj=this.tempActiveObj;break;case"setTempActObj":this.tempActiveObj=e.value.obj;break;case"isInside":this.isInside(e.value.x,e.value.y,e.value.z1,e.value.z2,e.value.z3,e.value.z4);break;case"setDragElement":this.dragElement=e.value.value;break;case"setObjSelected":this.isObjSelected=e.value.bool;break;case"adjustActObjForLineArrow":this.adjustActObjForLineArrow(e.value.obj);break;case"findTarget":this.findTarget(e.value.x,e.value.y,e.value.type);break;case"getCurrentFlipState":this.getCurrentFlipState();break;case"setDragWidth":this.setDragWidth(e.value.width);break;case"setDragHeight":this.setDragHeight(e.value.setDragHeight);break;case"annotate":this.currentDrawingShape=e.value.shape,"text"===e.value.shape?(t.activeObj.textSettings.fontSize=11,t.activeObj.keyHistory="Enter Text",t.notify("shape",{prop:"initializeTextShape",onPropertyChange:!1,value:{text:null,fontFamily:null,fontSize:null,bold:null,italic:null,strokeColor:null}})):"path"===e.value.shape&&(t.activeObj.pointColl=[]);break;case"getCurrentDrawingShape":e.value.obj.shape=this.currentDrawingShape;break;case"setCurrentDrawingShape":this.currentDrawingShape=e.value.value;break;case"getTransRotationPoint":this.getTransRotationPoint(e.value.obj,e.value.object);break;case"adjustNEPoints":this.adjustNEPoints(e.value.rectangle,e.value.x,e.value.y,e.value.angle);break;case"adjustRotationPoints":this.adjustRotationPoints(e.value.rectangle,e.value.x,e.value.y,e.value.angle,e.value.type,e.value.elem);break;case"getResizeDirection":this.getResizeDirection(e.value.rectangle,e.value.x,e.value.y,e.value.angle);break;case"setResizedElement":this.resizedElement=e.value.value;break;case"reset":this.reset();break;case"unWireEvent":this.unwireEvent();break;case"updPtCollForShpRot":this.updPtCollForShpRot(e.value.obj);break;case"findImageRatio":this.findImageRatio(e.value.width,e.value.height,e.value.obj);break;case"getNumTextValue":this.getNumTextValue(e.value.obj);break;case"setImageClarity":this.isImageClarity=e.value.bool;break;case"upgradeImageQuality":this.upgradeImageQuality();break;case"triggerShapeChange":this.triggerShapeChange(e.value.shapeResizingArgs,e.value.shapeMovingArgs,e.value.type);break;case"applyTransformToImg":this.applyTransformToImg(e.value.ctx);break;case"findTargetObj":e.value.obj.bool=this.findTargetObj(e.value.x,e.value.y,e.value.isCrop);break;case"setSliding":this.isSliding=e.value.bool;break;case"setSliderActive":this.isSliderActive=e.value.bool;break;case"getArrowType":e.value.obj.type=this.getArrowType(e.value.type);break;case"setArrowShape":"initial"===e.value.type?this.arrowShape[0]=e.value.shape:this.arrowShape[1]=e.value.shape;break;case"updateNWPoints":this.updateNWPoints(e.value.x,e.value.y);break;case"updateNPoints":this.updateNPoints(e.value.x,e.value.y);break;case"updateNEPoints":this.updateNEPoints(e.value.x,e.value.y);break;case"updateWPoints":this.updateWPoints(e.value.x,e.value.y);break;case"updateEPoints":this.updateEPoints(e.value.x,e.value.y);break;case"updateSWPoints":this.updateSWPoints(e.value.x,e.value.y);break;case"updateSPoints":this.updateSPoints(e.value.x,e.value.y);break;case"updateSEPoints":this.updateSEPoints(e.value.x,e.value.y);break;case"drawMaskCircle":this.drawMaskCircle(e.value.x,e.value.y);break;case"isValueUpdated":this.isValueUpdated();break;case"getDistance":this.getDistance(e.value.x,e.value.y);break;case"redact":this.currentDrawingShape=e.value.shape}},o.prototype.getModuleName=function(){return"selection"},o.prototype.updatePrivateVariables=function(){var e=this.parent;e.lowerCanvas&&(this.lowerContext=e.lowerCanvas.getContext("2d")),e.upperCanvas&&(this.upperContext=e.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:[],order:null},this.isFirstMove=!1,this.cursorTargetId=this.dragElement="",this.isTouchDblClick=!1,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=this.isPinching=!1,this.isFhdCustomized=!1,this.touchEndPoint={},this.panDown=null,this.isSliding=!1,this.isFhdEditing=!1,this.pathAdjustedIndex=null,this.touchTime=0,this.isImageClarity=!0,this.currentDrawingShape="",this.initialPrevObj={},this.resizedElement="",this.mouseDown="",this.isSliderActive=!1,this.arrowShape=[e.ArrowheadType.None,e.ArrowheadType.SolidArrow]},o.prototype.performTabAction=function(){var e=this.parent;if("block"===e.textArea.style.display||"inline-block"===e.textArea.style.display){var t=this.applyCurrShape(!1);e.notify("shape",{prop:"redrawActObj",onPropertyChange:!1,value:{x:null,y:null,isMouseDown:null}}),t&&e.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"ok"}})}e.isKBDNavigation=!0},o.prototype.selMouseUpEvent=function(){this.oldPoint.x=void 0,this.oldPoint.y=void 0},o.prototype.getMouseCursor=function(e,t,o,i,r){var a=this.getTransRotationPoint(e),n=e.bottomCenterCircle.radius,s=r?0:2*e.topLeftCircle.radius;return t>=e.topLeftCircle.startX-s&&t<=e.topLeftCircle.startX+s&&o>=e.topLeftCircle.startY-s&&o<=e.topLeftCircle.startY+s?"nw-resize":t>=e.topLeftCircle.startX-s&&t<=e.topRightCircle.startX-s&&o>=e.topCenterCircle.startY-s&&o<=e.topCenterCircle.startY+s?"n-resize":t>=e.topRightCircle.startX-s&&t<=e.topRightCircle.startX+s&&o>=e.topRightCircle.startY-s&&o<=e.topRightCircle.startY+s?"ne-resize":t>=e.centerLeftCircle.startX-s&&t<=e.centerLeftCircle.startX+s&&o>=e.topLeftCircle.startY-s&&o<=e.bottomLeftCircle.startY-s?"w-resize":t>=e.centerRightCircle.startX-s&&t<=e.centerRightCircle.startX+s&&o>=e.topRightCircle.startY-s&&o<=e.bottomRightCircle.startY-s?"e-resize":t>=e.bottomLeftCircle.startX-s&&t<=e.bottomLeftCircle.startX+s&&o>=e.bottomLeftCircle.startY-s&&o<=e.bottomLeftCircle.startY+s?"sw-resize":t>=e.bottomLeftCircle.startX-s&&t<=e.bottomRightCircle.startX-s&&o>=e.bottomCenterCircle.startY-s&&o<=e.bottomCenterCircle.startY+s?"s-resize":t>=e.bottomRightCircle.startX-s&&t<=e.bottomRightCircle.startX+s&&o>=e.bottomRightCircle.startY-s&&o<=e.bottomRightCircle.startY+s?"se-resize":t>=e.activePoint.startX&&t<=e.activePoint.endX&&o>=e.activePoint.startY&&o<=e.activePoint.endY?i?"grab":"move":a&&!r&&t>=a.x-(n+2)&&t<=a.x+(n+2)&&o>=a.y-(n+2)&&o<=a.y+(n+2)?"grabbing":"default"},o.prototype.setCursor=function(e,o){var i=this.parent;i.upperCanvas.style.cursor=i.cursor="default";var r={bool:null};if(i.notify("toolbar",{prop:"getFrameToolbar",onPropertyChange:!1,value:{obj:r}}),i.isResize||this.isSliding||r.bool)return void(i.upperCanvas.style.cursor="default");var a,n=!1;if(i.activeObj.shape&&(a=i.activeObj.shape.split("-")),(!a&&i.currObjType.isCustomCrop||a&&"crop"===a[0])&&(n=!0),i.currObjType.isDragging)return void(""===this.dragElement?i.upperCanvas.style.cursor=i.cursor="move":i.upperCanvas.style.cursor=i.cursor=this.dragElement);if(i.togglePen)return i.upperCanvas.style.cursor=i.cursor="crosshair",void(i.isMaskImage&&(this.drawMaskCircle(e,o),i.upperCanvas.style.cursor="none"));if(i.activeObj.shape&&this.setCursorForActObj(a,n,e,o),"default"===i.cursor||"grab"===i.cursor){for(var s=this.getHighestOrder(),l=t.extend([],i.shapeColl,[],!0),p=t.extend([],i.objColl,[],!0),h=!1;s>0;){h=!1;for(var d=l.length-1;d>=0;d--)if(l[d].order===s)if(h=!0,l[d].id&&l[d].id.indexOf("pen")>-1){if(i.pointColl[0]&&("grab"!==i.cursor||!n)&&!i.currObjType.isDragging&&!i.currObjType.isResize){var c=t.extend([],i.points,[],!0);n||this.setCursorForFreehandDrawing(e,o,i.upperCanvas,l[d].id),i.points=c}}else{i.objColl=[],i.objColl.push(t.extend({},l[d],null,!0));var u=i.upperCanvas.style.cursor;i.objColl.length>0&&("grab"!==i.cursor||!n)&&this.setCursorFromObj(e,o,i.objColl,i.upperCanvas,n),"grab"===u&&"default"===i.cursor&&(i.upperCanvas.style.cursor=i.cursor="grab")}else t.isNullOrUndefined(l[d].order)&&(h=!0);if("default"!==i.cursor&&"grab"!==i.cursor)break;if(h)for(var v=!1;!v&&s>0;){for(var g=0;g<l.length;g++)if(l[g].order===s-1){v=!0;break}s--,v||s--}}i.objColl=p,"default"!==i.cursor&&"grab"!==i.cursor||i.togglePan&&(i.lowerCanvas.style.cursor=i.upperCanvas.style.cursor=i.cursor="grab")}""===this.currentDrawingShape||"default"!==i.cursor&&"grab"!==i.cursor||(i.upperCanvas.style.cursor=i.cursor="crosshair")},o.prototype.getHighestOrder=function(){for(var e=0,t=0;t<this.parent.shapeColl.length;t++)this.parent.shapeColl[t].order>e&&(e=this.parent.shapeColl[t].order);return e},o.prototype.drawMaskCircle=function(e,t){var o=this.parent;if(o.isMaskImage){var i=2*o.activeObj.strokeSettings.strokeWidth,r=o.maskCanvas.getContext("2d");r.clearRect(0,0,o.maskCanvas.width,o.maskCanvas.height),r.fillStyle=o.activeObj.strokeSettings.strokeColor,r.strokeStyle="#fff",r.beginPath(),r.ellipse(e,t,i/2,i/2,0,0,2*Math.PI,!1),r.fill(),r.stroke(),r.closePath(),o.maskCanvas.style.cursor="none"}},o.prototype.setCursorForActObj=function(e,o,i,r){var a=this.parent;if(void 0!==a.activeObj.horTopLine){void 0!==a.activeObj.shape&&(e=a.activeObj.shape.split("-")),void 0===e&&a.currObjType.isCustomCrop?o=!0:void 0!==e&&"crop"===e[0]&&(o=!0),!o&&a.togglePan&&(a.lowerCanvas.style.cursor=a.upperCanvas.style.cursor=a.cursor="grab");var n=a.upperCanvas.style.cursor,s=t.extend({},a.activeObj,{},!0);this.cursorTargetId=s.currIndex;var l=void 0;if((l=0===s.shapeDegree?a.transform.degree:a.transform.degree-s.shapeDegree)<0&&(l=360+l),"line"===s.shape||"arrow"===s.shape)this.setCursorForLineArrow(s,i,r,a.upperCanvas);else if("path"===s.shape)this.setCursorForPath(s,i,r,a.upperCanvas);else if(t.isNullOrUndefined(s.rotatedAngle)||0===s.rotatedAngle){a.upperCanvas.style.cursor=a.cursor=this.getMouseCursor(s,i,r,o,!1);var p=["n-resize","s-resize","e-resize","w-resize"];"text"===s.shape&&p.indexOf(a.cursor)>-1&&(a.upperCanvas.style.cursor=a.cursor="move")}else this.setCursorForRotatedObject(s,i,r,a.upperCanvas);"default"===n&&"default"===a.cursor&&o&&(a.upperCanvas.style.cursor=a.cursor="grab"),"grab"===n&&"default"===a.cursor&&(a.upperCanvas.style.cursor=a.cursor="grab")}else a.togglePan&&!a.togglePen?a.lowerCanvas.style.cursor=a.upperCanvas.style.cursor=a.cursor="grab":a.currObjType.isCustomCrop||a.togglePen?a.upperCanvas.style.cursor=a.cursor="crosshair":a.upperCanvas.style.cursor=a.cursor="default"},o.prototype.setCursorForPath=function(e,o,i,r){this.setCursorForLineArrow(e,o,i,r);var a=this.parent;if("default"===a.cursor)for(var n=t.extend({},e,null,!0),s=!1,l=1,p=e.pointColl.length;l<p&&!s;l++){n.activePoint.startX=e.pointColl[l-1].x,n.activePoint.startY=e.pointColl[l-1].y,n.activePoint.endX=e.pointColl[l].x,n.activePoint.endY=e.pointColl[l].y,a.notify("shape",{prop:"setPointCollForLineArrow",onPropertyChange:!1,value:{obj:n}});for(var h=e.topLeftCircle.radius,d=0,c=n.pointColl.length;d<c;d++){var u=n.pointColl[d];if(!t.isNullOrUndefined(u.x-2*h)&&!t.isNullOrUndefined(u.x+2*h)&&!t.isNullOrUndefined(u.y-2*h)&&!t.isNullOrUndefined(u.y+2*h)&&o>=u.x-2*h&&o<=u.x+2*h&&i>=u.y-2*h&&i<=u.y+2*h){r.style.cursor=a.cursor="move",s=!0;break}r.style.cursor=a.cursor="default"}}return a.cursor},o.prototype.setCursorForLineArrow=function(e,o,i,r){var a,n=e.topLeftCircle.radius;if(t.isNullOrUndefined(e.pointColl))return a;for(var s=0,l=e.pointColl.length;s<l;s++){var p=e.pointColl[s];if(o>=p.x-2*n&&o<=p.x+2*n&&i>=p.y-2*n&&i<=p.y+2*n){r.style.cursor=this.parent.cursor="move",a=s;break}r.style.cursor=this.parent.cursor="default"}return a},o.prototype.setCursorForRotatedObject=function(e,t,o,i){this.resizedElement="";var r=this.parent,a=e.bottomCenterCircle.radius,n=e.horTopLinePointColl[Math.round(e.horTopLinePointColl.length/2)],s=e.horTopLinePointColl[Math.round(e.horTopLinePointColl.length-1)],l=e.verLeftLinePointColl[Math.round(e.verLeftLinePointColl.length/2)],p=e.verRightLinePointColl[Math.round(e.verRightLinePointColl.length/2)],h=e.horBottomLinePointColl[Math.round(e.horBottomLinePointColl.length/2)],d=e.horBottomLinePointColl[Math.round(e.horBottomLinePointColl.length-1)],c=e.rotationCirclePointColl,u=e.horTopLinePointColl[0],v=e.horBottomLinePointColl[0];if(t>=u.x-(a+2)&&t<=u.x+(a+2)&&o>=u.y-(a+2)&&o<=u.y+(a+2)?i.style.cursor=r.cursor="nw-resize":t>=n.x-5&&t<=n.x+5&&o>=n.y-5&&o<=n.y+5?i.style.cursor=r.cursor=this.resizedElement="n-resize":t>=s.x-(a+2)&&t<=s.x+(a+2)&&o>=s.y-(a+2)&&o<=s.y+(a+2)?i.style.cursor=r.cursor="ne-resize":t>=l.x-5&&t<=l.x+5&&o>=l.y-5&&o<=l.y+5?i.style.cursor=r.cursor=this.resizedElement="w-resize":t>=p.x-5&&t<=p.x+5&&o>=p.y-5&&o<=p.y+5?i.style.cursor=r.cursor=this.resizedElement="e-resize":t>=v.x-(a+2)&&t<=v.x+(a+2)&&o>=v.y-(a+2)&&o<=v.y+(a+2)?i.style.cursor=r.cursor="sw-resize":t>=h.x-5&&t<=h.x+5&&o>=h.y-5&&o<=h.y+5?i.style.cursor=r.cursor=this.resizedElement="s-resize":t>=d.x-(a+2)&&t<=d.x+(a+2)&&o>=d.y-(a+2)&&o<=d.y+(a+2)?i.style.cursor=r.cursor="se-resize":c&&t>=c.x-(a+2)&&t<=c.x+(a+2)&&o>=c.y-(a+2)&&o<=c.y+(a+2)?i.style.cursor=r.cursor="grabbing":(i.style.cursor=r.cursor="default",this.getRectanglePoints(e.activePoint.startX,e.activePoint.startY,e.activePoint.width,e.activePoint.height,e.rotatedAngle*(180/Math.PI),t,o)&&(i.style.cursor=r.cursor="move")),"default"===r.cursor)for(var g=0,f=e.horTopLinePointColl.length;g<f;g++){var C=e.horTopLinePointColl[g];if(t>=C.x-5&&t<=C.x+5&&o>=C.y-5&&o<=C.y+5){i.style.cursor=r.cursor=this.resizedElement="n-resize";break}}if("default"===r.cursor)for(var g=0,f=e.horBottomLinePointColl.length;g<f;g++){var b=e.horBottomLinePointColl[g];if(t>=b.x-5&&t<=b.x+5&&o>=b.y-5&&o<=b.y+5){i.style.cursor=r.cursor=this.resizedElement="s-resize";break}}if("default"===r.cursor)for(var g=0,f=e.verLeftLinePointColl.length;g<f;g++){var m=e.verLeftLinePointColl[g];if(t>=m.x-5&&t<=m.x+5&&o>=m.y-5&&o<=m.y+5){i.style.cursor=r.cursor=this.resizedElement="w-resize";break}}if("default"===r.cursor)for(var g=0,f=e.verRightLinePointColl.length;g<f;g++){var y=e.verRightLinePointColl[g];if(t>=y.x-5&&t<=y.x+5&&o>=y.y-5&&o<=y.y+5){i.style.cursor=r.cursor=this.resizedElement="e-resize";break}}return this.adjustCursorStylesForRotatedState(e),r.cursor},o.prototype.adjustCursorStylesForRotatedState=function(e){var t=this.parent,o=e.rotatedAngle*(180/Math.PI);if((o=o>0?Math.floor(o):Math.ceil(o))>=92&&o<=182||o>=-178&&o<=-88){var i={"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"};t.cursor in i&&(t.cursor=i[t.cursor])}return t.upperCanvas.style.cursor=this.getResizeElement(e.rotatedAngle*(180/Math.PI),t.cursor),t.cursor},o.prototype.getResizeElement=function(e,t){var o=[];switch(t){case"nw-resize":o=[[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"]];break;case"n-resize":o=[[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"]];break;case"ne-resize":o=[[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"]];break;case"e-resize":o=[[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"]];break;case"se-resize":o=[[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"]];break;case"s-resize":o=[[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"]];break;case"sw-resize":o=[[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"]];break;case"w-resize":o=[[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 i=e<0?360-Math.abs(e):e,r=0,a=o;r<a.length;r++){var n=a[r],s=n[0],l=n[1],p=n[2];if(i>s&&i<=l||i+360>s&&i+360<=l)return p}return t},o.prototype.setCursorForFreehandDrawing=function(e,o,i,r){var a=i.getContext("2d"),n=this.parent,s=document.querySelector("#"+n.element.id+"_textArea"),l=!1;n.notify("freehand-draw",{prop:"setFreehandDrawHoveredIndex",onPropertyChange:!1,value:{index:-1}});for(var p,h=0;h<n.freehandCounter;h++)if(!r||r===n.pointColl[h].id){var d={selPointColl:{}};n.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:d}}),p=t.extend([],d.selPointColl[h].points,[]),n.points=t.extend([],n.pointColl[h].points,[]);var c=n.pointColl[h];n.notify("freehand-draw",{prop:"setPointCounter",onPropertyChange:!1,value:{value:0}});for(var u=p.length,v=0;v<u;v++)if(0!==v){var g=!1;if(p[v-1]&&p[v]&&(g=this.isInside(e,o,p[v-1].x,p[v-1].y,p[v].x,p[v].y)),g){this.isFhdPoint=!0,n.notify("freehand-draw",{prop:"setFreehandDrawHoveredIndex",onPropertyChange:!1,value:{index:h}}),n.notify("freehand-draw",{prop:"hoverFhd",onPropertyChange:!1,value:{strokeColor:null,strokeWidth:null}}),i.style.cursor=n.cursor="pointer",l=!0;break}if(!this.isFhdEditing||c.isSelected){if((this.isFhdPoint||this.isFhdEditing)&&(a.clearRect(0,0,i.width,i.height),n.activeObj.shape&&"none"===s.style.display&&n.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate",obj:n.activeObj}})),this.isFhdEditing){m={freehandSelectedIndex:-1};n.notify("freehand-draw",{prop:"getFreehandSelectedIndex",onPropertyChange:!1,value:{obj:m}});var f=n.pointColl[m.freehandSelectedIndex].strokeColor,C=n.pointColl[m.freehandSelectedIndex].strokeWidth;n.notify("freehand-draw",{prop:"hoverFhd",onPropertyChange:!1,value:{strokeColor:f,strokeWidth:C}})}else n.notify("freehand-draw",{prop:"setFreehandDrawHoveredIndex",onPropertyChange:!1,value:{index:null}});this.isFhdPoint=!1}}else{var b=n.points[v];if(e>b.x-c.strokeWidth&&e<b.x+c.strokeWidth&&o>b.y-c.strokeWidth&&o<b.y+c.strokeWidth){this.isFhdPoint=!0,n.notify("freehand-draw",{prop:"setFreehandDrawHoveredIndex",onPropertyChange:!1,value:{index:h}}),n.notify("freehand-draw",{prop:"hoverFhd",onPropertyChange:!1,value:{strokeColor:null,strokeWidth:null}}),i.style.cursor=n.cursor="pointer",l=!0;break}if(!this.isFhdEditing||c.isSelected){if((this.isFhdPoint||this.isFhdEditing)&&(a.clearRect(0,0,i.width,i.height),n.activeObj.shape&&"none"===s.style.display&&n.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate",obj:n.activeObj}})),this.isFhdEditing){var m={freehandSelectedIndex:-1};n.notify("freehand-draw",{prop:"getFreehandSelectedIndex",onPropertyChange:!1,value:{obj:m}});var f=n.pointColl[m.freehandSelectedIndex].strokeColor,C=n.pointColl[m.freehandSelectedIndex].strokeWidth;n.notify("freehand-draw",{prop:"hoverFhd",onPropertyChange:!1,value:{strokeColor:f,strokeWidth:C}})}this.isFhdPoint=!1}}if(l)break}},o.prototype.setCursorFromObj=function(e,o,i,r,a){for(var n=this.parent,s=0,l=i.length;s<l;s++){if("move"===n.cursor)return;var p=t.extend({},i[s],{},!0);if(0===p.activePoint.width&&0===p.activePoint.height)return void i.splice(s,1);this.cursorTargetId=p.currIndex,"line"===p.shape||"arrow"===p.shape?this.setCursorForLineArrow(p,e,o,r):"path"===p.shape?this.setCursorForPath(p,e,o,r):t.isNullOrUndefined(p.rotatedAngle)||0===p.rotatedAngle?r.style.cursor=n.cursor=this.getMouseCursor(p,e,o,a,!0):this.setCursorForRotatedObject(p,e,o,r)}},o.prototype.isInside=function(e,t,o,i,r,a){var n=Math.min(o,r),s=Math.max(o,r),l=Math.min(i,a),p=Math.max(i,a);return n<=e&&e<=s&&l<=t&&t<=p},o.prototype.preventResizing=function(e){var t=this.parent;if(t.activeObj.preventShapeDragOut&&this.isShapeDragOut()){var o=t.activeObj.activePoint;o.startX=e.activePoint.startX,o.startY=e.activePoint.startY,o.endX=e.activePoint.endX,o.endY=e.activePoint.endY,o.width=e.activePoint.width,o.height=e.activePoint.height,t.activeObj.rotatedAngle=e.rotatedAngle,t.notify("draw",{prop:"updateActiveObject",onPropertyChange:!1,value:{actPoint:o,obj:t.activeObj,isMouseMove:null,x:null,y:null}})}},o.prototype.updateActivePoint=function(e,o,i){var r=this.parent,a={width:0,height:0},n=r.activeObj.activePoint,s=n.startX,l=n.startY,p=r.activeObj.activePoint,h=p.width,d=p.height;r.notify("transform",{prop:"calcMaxDimension",onPropertyChange:!1,value:{width:h,height:d,obj:a,isImgShape:null}});var c=this.updatePrevShapeSettings(),u={cancel:!1,action:"resize",previousShapeSettings:c,allowShapeOverflow:this.allowOutofBound()},v={cancel:!1,action:"move",previousShapeSettings:c,allowShapeOverflow:this.allowOutofBound()};this.shapeResizingArgs=u,this.shapeMovingArgs=v,"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||!r.isShapeDrawing||(["line","arrow","path"].indexOf(r.activeObj.shape)>-1?this.dragElement="e-resize":e>s&&o>l?this.dragElement="se-resize":e<s&&o>l?this.dragElement="sw-resize":e>s&&o<l?this.dragElement="ne-resize":e<s&&o<l&&(this.dragElement="nw-resize")),"arrow"===r.activeObj.shape&&(Math.atan2(e-r.lowerCanvas.width/2,o-r.lowerCanvas.height/2)>0?r.activeObj.rotatedAngle=-Math.atan2(e-r.lowerCanvas.width/2,o-r.lowerCanvas.height/2):r.activeObj.rotatedAngle=Math.abs(Math.atan2(e-r.lowerCanvas.width/2,o-r.lowerCanvas.height/2)));var g,f=!1,C=!1;if(!i||0===r.transform.straighten||!this.isMouseOutsideImg(e,o)){var b,m,y=t.extend({},r.activeObj,{},!0);switch(void 0!==r.activeObj.shape&&(b=r.activeObj.shape.split("-")),void 0!==b&&"crop"===b[0]&&(m=!0),this.dragElement.toLowerCase()){case"nw-resize":this.updateNWPoints(e,o),this.preventResizing(y),r.notify("shape",{prop:"updateArrowDirection",onPropertyChange:!1,value:{obj:r.activeObj,flip:null,rotatedDegree:null}}),this.triggerShapeChange(u,v,"resize");break;case"n-resize":this.updateNPoints(e,o),this.preventResizing(y),r.notify("shape",{prop:"updateArrowDirection",onPropertyChange:!1,value:{obj:r.activeObj,flip:null,rotatedDegree:null}}),this.triggerShapeChange(u,v,"resize");break;case"ne-resize":this.updateNEPoints(e,o),this.preventResizing(y),r.notify("shape",{prop:"updateArrowDirection",onPropertyChange:!1,value:{obj:r.activeObj,flip:null,rotatedDegree:null}}),this.triggerShapeChange(u,v,"resize");break;case"w-resize":this.updateWPoints(e,o),this.preventResizing(y),r.notify("shape",{prop:"updateArrowDirection",onPropertyChange:!1,value:{obj:r.activeObj,flip:null,rotatedDegree:null}}),this.triggerShapeChange(u,v,"resize");break;case"e-resize":this.updateEPoints(e,o),this.preventResizing(y),r.notify("shape",{prop:"updateArrowDirection",onPropertyChange:!1,value:{obj:r.activeObj,flip:null,rotatedDegree:null}}),this.triggerShapeChange(u,v,"resize");break;case"sw-resize":this.updateSWPoints(e,o),this.preventResizing(y),r.notify("shape",{prop:"updateArrowDirection",onPropertyChange:!1,value:{obj:r.activeObj,flip:null,rotatedDegree:null}}),this.triggerShapeChange(u,v,"resize");break;case"s-resize":this.updateSPoints(e,o),this.preventResizing(y),r.notify("shape",{prop:"updateArrowDirection",onPropertyChange:!1,value:{obj:r.activeObj,flip:null,rotatedDegree:null}}),this.triggerShapeChange(u,v,"resize");break;case"se-resize":this.updateSEPoints(e,o),this.preventResizing(y),r.notify("shape",{prop:"updateArrowDirection",onPropertyChange:!1,value:{obj:r.activeObj,flip:null,rotatedDegree:null}}),this.triggerShapeChange(u,v,"resize");break;case"grabbing":Math.atan2(e-(s+h/2),o-(l+d/2))>0?r.activeObj.rotatedAngle=-Math.atan2(e-(s+h/2),o-(l+d/2)):r.activeObj.rotatedAngle=Math.abs(Math.atan2(e-(s+h/2),o-(l+d/2))),(g=0===r.activeObj.shapeDegree?r.transform.degree:r.transform.degree-r.activeObj.shapeDegree)<0&&(g=360+g);for(var P=0,j=r.activeObj.flipObjColl.length;P<j;P++)"horizontal"===r.activeObj.flipObjColl[P].toLowerCase()?f=!0:"vertical"===r.activeObj.flipObjColl[P].toLowerCase()&&(C=!0);r.activeObj.rotatedAngle-=g*(Math.PI/180),0===g||360===g?C&&(r.activeObj.rotatedAngle-=Math.PI/180*180):90===g||-270===g?f&&(r.activeObj.rotatedAngle-=Math.PI/180*180):180===g||-180===g?C&&(r.activeObj.rotatedAngle-=Math.PI/180*180):270!==g&&-90!==g||f&&(r.activeObj.rotatedAngle-=Math.PI/180*180),this.preventResizing(y);break;case"pathdrag":t.isNullOrUndefined(this.pathAdjustedIndex)||(r.activeObj.pointColl[this.pathAdjustedIndex].x=e,r.activeObj.pointColl[this.pathAdjustedIndex].y=o);break;default:if(!i&&!r.currObjType.isCustomCrop){var x=r.activeObj.activePoint;if(this.dragPoint.startX){var w=this.dragPoint.endX-this.previousPoint.x,O=this.dragPoint.endY-this.previousPoint.y;if(x.startX+=w,x.endX+=w,x.startY+=O,x.endY+=O,s=x.startX,l=x.startY,"line"!==r.activeObj.shape&&"arrow"!==r.activeObj.shape&&r.activeObj.rotationCirclePointColl&&(r.activeObj.rotationCirclePointColl.x+=w,r.activeObj.rotationCirclePointColl.y+=O,r.activeObj.rotationCirclePoint.x+=w,r.activeObj.rotationCirclePoint.y+=O),"path"===r.activeObj.shape)for(var P=0,j=r.activeObj.pointColl.length;P<j;P++)r.activeObj.pointColl[P].x+=w,r.activeObj.pointColl[P].y+=O;if(!this.isPreventDragging&&this.isShapeDragOut()&&(r.activeObj.preventShapeDragOut||"redact"===r.activeObj.shape||m)){if(x.startX-=w,x.endX-=w,x.startY-=O,x.endY-=O,"line"!==r.activeObj.shape&&"arrow"!==r.activeObj.shape&&r.activeObj.rotationCirclePointColl)r.activeObj.rotationCirclePointColl.x-=w,r.activeObj.rotationCirclePointColl.y-=O,r.activeObj.rotationCirclePoint.x-=w,r.activeObj.rotationCirclePoint.y-=O;else if("path"===r.activeObj.shape)for(var S=0,j=r.activeObj.pointColl.length;S<j;S++)r.activeObj.pointColl[S].x-=w,r.activeObj.pointColl[S].y-=O;if(0===r.activeObj.rotatedAngle){var T=r.activeObj.activePoint.endX,k=r.activeObj.activePoint.endY;"path"===r.activeObj.shape&&(r.activeObj.activePoint=r.getSquarePointForPath(r.activeObj)),this.setDragWidth(w),this.setDragHeight(O);var F=r.activeObj,I=F.activePoint.endX-T,A=F.activePoint.endY-k;if("path"===F.shape)for(var S=0,j=F.pointColl.length;S<j;S++)F.pointColl[S].x+=I,F.pointColl[S].y+=A}else r.notify("selection",{prop:"updPtCollForShpRot",onPropertyChange:!1,value:{obj:r.activeObj}})}}else x.startX=e<this.mouseDownPoint.x?e:this.mouseDownPoint.x,x.startY=o<this.mouseDownPoint.y?o:this.mouseDownPoint.y,e=e<this.mouseDownPoint.x?this.mouseDownPoint.x:e,o=o<this.mouseDownPoint.y?this.mouseDownPoint.y:o,x.endX=e,x.endY=o;this.triggerShapeChange(u,v,"move")}}}},o.prototype.isShapeDragOut=function(){var e=this.parent,t=!1,o=!1,i=e.activeObj.shape;if(e.activeObj.preventShapeDragOut?o=!0:0===e.activeObj.rotatedAngle&&"line"!==i&&"arrow"!==i&&"path"!==i&&(o=!0),o){var r=e.activeObj.activePoint,a=r.startX,n=r.startY,s=r.endX,l=r.endY;if("path"===i){var p=e.getSquarePointForPath(e.activeObj);a=p.startX,n=p.startY,s=p.endX,l=p.endY}if(0===e.activeObj.rotatedAngle||"arrow"===i)t=this.isObjOutsideImg(a,n,s,l,i);else{var h={isIntersect:null,arr:null};e.notify("draw",{prop:"updateImgCanvasPoints",onPropertyChange:!1}),e.notify("draw",{prop:"isLinesIntersect",onPropertyChange:!1,value:{obj:h}}),t=!!(h.arr[0]||h.arr[1]||h.arr[2]||h.arr[3])||this.isObjOutsideImg(a,n,s,l,i)}}return t},o.prototype.isObjOutsideImg=function(e,t,o,i,r){var a=this.parent.img,n=a.destLeft,s=a.destTop,l=a.destWidth,p=a.destHeight;return e<n||t<s||o>n+l||i>s+p||("line"===r||"arrow"===r)&&(e>n+l||t>s+p||o<n||i<s)},o.prototype.triggerShapeChange=function(e,o,i){var r=this.parent,a=r.activeObj.activePoint;a.width=a.endX-a.startX,a.height=a.endY-a.startY;var n=this.updatePrevShapeSettings();if(t.isNullOrUndefined(this.shapeResizingArgs)||t.isNullOrUndefined(this.shapeMovingArgs)?(e.currentShapeSettings=n,o.currentShapeSettings=n):(e.currentShapeSettings=this.shapeResizingArgs.currentShapeSettings=n,o.currentShapeSettings=this.shapeMovingArgs.currentShapeSettings=n),"resize"===i){this.isCropSelection=!1;var s=void 0;if(void 0!==r.activeObj.shape&&(s=r.activeObj.shape.split("-")),void 0!==s&&"crop"===s[0]&&(this.isCropSelection=!0),this.isCropSelection){var l={action:e.action,previousSelectionSettings:{type:r.getSelectionType(r.activeObj.shape),startX:e.previousShapeSettings.startX,startY:e.previousShapeSettings.startY,width:e.previousShapeSettings.width,height:e.previousShapeSettings.height},currentSelectionSettings:{type:r.getSelectionType(r.activeObj.shape),startX:e.currentShapeSettings.startX,startY:e.currentShapeSettings.startY,width:e.currentShapeSettings.width,height:e.currentShapeSettings.height}};this.selectionResizingArgs=l,r.trigger("selectionChanging",l),r.editCompleteArgs=l,r.notify("shape",{prop:"updSelChangeEventArgs",onPropertyChange:!1,value:{selectionSettings:l.currentSelectionSettings}})}else""!==this.currentDrawingShape&&"crosshair"===r.upperCanvas.style.cursor&&(e.action="drawing"),r.currObjType.isRedact&&"redact"===r.activeObj.shape||r.trigger("shapeChanging",e),r.editCompleteArgs=e,this.isPreventShaping=e.cancel,r.notify("shape",{prop:"updateShapeChangeEventArgs",onPropertyChange:!1,value:{shapeSettings:e.currentShapeSettings,allowShapeOverflow:e.allowShapeOverflow}})}else"mouse-down"===i||"mouse-up"===i?("redact"!==r.activeObj.shape&&r.trigger("shapeChanging",e),r.editCompleteArgs=e,this.isPreventShaping=e.cancel,r.notify("shape",{prop:"updateShapeChangeEventArgs",onPropertyChange:!1,value:{shapeSettings:e.currentShapeSettings,allowShapeOverflow:e.allowShapeOverflow}})):("redact"!==r.activeObj.shape&&r.trigger("shapeChanging",o),r.editCompleteArgs=o,this.isPreventShaping=o.cancel,r.notify("shape",{prop:"updateShapeChangeEventArgs",onPropertyChange:!1,value:{shapeSettings:o.currentShapeSettings,allowShapeOverflow:o.allowShapeOverflow}}));r.eventType=i},o.prototype.setDragWidth=function(e){var t=this.parent,o=t.activeObj.activePoint,i=t.img,r=i.destLeft,a=i.destWidth,n=e,s=t.activeObj.shape,l=!1;if(!t.activeObj.preventShapeDragOut||"line"!==s&&"arrow"!==s||(l=!0),n>=0)for(p=0;p<n&&(e=n-p,o.startX+=e,o.endX+=e,!(o.startX>=r&&o.endX<=r+a&&!l||o.startX>=r&&o.endX<=r+a&&o.endX>=r&&o.startX<=r+a&&l));p++)o.startX-=e,o.endX-=e;else for(var p=1;p<Math.abs(n)&&(e=n+p,o.startX+=e,o.endX+=e,!(o.startX>=r&&o.endX<=r+a&&!l||o.startX>=r&&o.endX<=r+a&&o.endX>=r&&o.startX<=r+a&&l));p++)o.startX-=e,o.endX-=e},o.prototype.setDragHeight=function(e){var t=this.parent,o=t.activeObj.activePoint,i=t.img,r=i.destTop,a=i.destHeight,n=e,s=t.activeObj.shape,l=!1;if(!t.activeObj.preventShapeDragOut||"line"!==s&&"arrow"!==s||(l=!0),n>=0)for(p=1;p<n&&(e=n-p,o.startY+=e,o.endY+=e,!(o.startY>=r&&o.endY<=r+a&&!l||o.startY>=r&&o.endY<=r+a&&o.endY>=r&&o.startY<=r+a&&l));p++)o.startY-=e,o.endY-=e;else for(var p=0;p<Math.abs(n)&&(e=n+p,o.startY+=e,o.endY+=e,!(o.startY>=r&&o.endY<=r+a&&!l||o.startY>=r&&o.endY<=r+a&&o.endY>=r&&o.startY<=r+a&&l));p++)o.startY-=e,o.endY-=e},o.prototype.limitDrag=function(e){var o=!1,i=this.parent,r=i.img,a=r.destLeft,n=r.destTop,s=r.destWidth,l=r.destHeight,p=i.activeObj.activePoint,h=e?p.startX:p.endX,d=e?p.startY:p.endY,c=e?p.endX:p.startX,u=e?p.endY:p.startY,v=i.upperCanvas.width,g=i.upperCanvas.height;if(t.Browser.isDevice?(h<0&&a<0&&(h=0),d<0&&n<0&&(d=0),c>v&&a+s>v&&(c=v),u>g&&n+l>g&&(u=g)):(h<a&&(h=a),d<n&&(d=n),c>a+s&&(c=a+s),u>n+l&&(u=n+l)),0!==i.transform.straighten){var f={isIntersect:null,arr:null};i.notify("draw",{prop:"updateImgCanvasPoints",onPropertyChange:!1}),i.notify("draw",{prop:"isLinesIntersect",onPropertyChange:!1,value:{obj:f}}),(f.arr[0]||f.arr[1]||f.arr[2]||f.arr[3])&&(o=!0)}return e?(p.startX=h,p.startY=d,p.endX=c,p.endY=u):(p.startX=c,p.startY=u,p.endX=h,p.endY=d),o},o.prototype.isMouseOutsideImg=function(e,t){var o={bool:!1};return this.parent.notify("draw",{prop:"updateImgCanvasPoints",onPropertyChange:!1}),this.parent.notify("draw",{prop:"isPointsInsideImg",value:{obj:o,x:e,y:t}}),o.bool},o.prototype.preventDraggingInvertly=function(){var e=!1,t=this.parent;if("image"===t.activeObj.shape)return e;var o,i;return void 0!==t.activeObj.shape&&(o=t.activeObj.shape.split("-")),void 0!==o&&"crop"===o[0]&&(i=!0),this.isPreventDragging||0!==t.activeObj.rotatedAngle||!t.activeObj.preventShapeDragOut&&"redact"!==t.activeObj.shape&&!i||(e=this.limitDrag(!0),["line","arrow","path"].indexOf(t.activeObj.shape)>-1&&(e=this.limitDrag(!1))),e},o.prototype.preventTextDraggingInvertly=function(){var e=this.parent,t=!1,o=e.activeObj.activePoint,i=e.img,r=i.destLeft,a=i.destTop,n=i.destWidth,s=i.destHeight;return this.isPreventDragging||(o.startX<r||o.startY<a||o.endX>r+n||o.endY>a+s)&&(t=!0),t},o.prototype.preventInverseResize=function(e){var t=this.parent.activeObj.activePoint;t.width<0&&(t.width=0,t.startX=e.activePoint.startX,t.endX=e.activePoint.endX),t.height<0&&(t.height=0,t.startY=e.activePoint.startY,t.endY=e.activePoint.endY)},o.prototype.getScaleRatio=function(e){var t=this.parent,o={x:e,y:e};if(t.activeObj.shape&&"crop-custom"!==t.activeObj.shape&&"crop-circle"!==t.activeObj.shape&&"crop-square"!==t.activeObj.shape){var i="image"===t.activeObj.shape||"text"===t.activeObj.shape?this.findImageRatio(t.activeObj.activePoint.width,t.activeObj.activePoint.height).split("-"):t.activeObj.shape.split("-");if(i.length>1||"image"===t.activeObj.shape||"text"===t.activeObj.shape){i="image"===t.activeObj.shape||"text"===t.activeObj.shape?i[0].split(":"):i[1].split(":");var r=e/parseInt(i[1],10);o.x=r*parseInt(i[0],10),o.y=r*parseInt(i[1],10)}}return o},o.prototype.findImageRatio=function(e,t,o){var i=function(e,t){return 0===t?e:i(t,e%t)},r=i(e,t),a=e/r+":"+t/r;return o&&(o.ratio=a),a},o.prototype.revertResizing=function(e){var t=this.parent.activeObj.activePoint;this.preventDraggingInvertly()&&(t.startX=e.activePoint.startX,t.startY=e.activePoint.startY,t.endX=e.activePoint.endX,t.endY=e.activePoint.endY)},o.prototype.performSEResize=function(e,t,o,i){var r=this.parent;if(this.resizeImg(e,t,"se-resize",o),i.endX<i.startX){a=i.endX;i.endX=i.startX,i.startX=a,this.dragElement=r.upperCanvas.style.cursor=r.cursor="sw-resize"}if(i.endY<i.startY){var a=i.endY;i.endY=i.startY,i.startY=a,this.dragElement=r.upperCanvas.style.cursor=r.cursor="ne-resize"}this.revertCustomSelection(i,o,"se-resize"),this.revertResizing(o)},o.prototype.performNWResize=function(e,t,o,i){var r=this.parent;if(this.resizeImg(e,t,"nw-resize",o),i.startX>i.endX){a=i.startX;i.startX=i.endX,i.endX=a,this.dragElement=r.upperCanvas.style.cursor=r.cursor="ne-resize"}if(i.startY>i.endY){var a=i.startY;i.startY=i.endY,i.endY=a,this.dragElement=r.upperCanvas.style.cursor=r.cursor="sw-resize"}this.revertCustomSelection(i,o,"nw-resize"),this.revertResizing(o)},o.prototype.isCustomSelection=function(){if(this.parent.activeObj.shape){var e=["custom","circle","square","2:3","3:2","3:4","4:3","4:5","5:4","5:7","7:5","9:16","16:9"];return this.parent.activeObj.shape.indexOf("crop-")>-1&&-1===e.indexOf(this.parent.activeObj.shape.split("-")[1])}return!1},o.prototype.revertCustomSelection=function(e,t,o){var i=this.parent;if(this.isCustomSelection()){var r=i.img,a=r.destLeft,n=r.destTop,s=r.destWidth,l=r.destHeight,p=a+s<i.lowerCanvas.width?a+s:i.lowerCanvas.width,h=n+l<i.lowerCanvas.height?n+l:i.lowerCanvas.height,d=a>0?a:0,c=n>0?n:0,u=n>0?n:0,v=a>0?a:0;("se-resize"===o&&(e.endX>p||e.endY>h)||"nw-resize"===o&&(e.startX<d||e.startY<c)||"ne-resize"===o&&(e.endX>p||e.startY<u)||"sw-resize"===o&&(e.startX<v||e.endY>h))&&this.revertPoints(e,t)}},o.prototype.revertPoints=function(e,t){e.startX=t.activePoint.startX,e.startY=t.activePoint.startY,e.endX=t.activePoint.endX,e.endY=t.activePoint.endY,e.width=t.activePoint.width,e.height=t.activePoint.height},o.prototype.updateNWPoints=function(e,o){var i,r,a,n=this.parent,s=n.activeObj.activePoint,l=t.extend({},n.activeObj,null,!0);if("text"===n.activeObj.shape)this.resizeImg(e,o,"nw-resize",l),n.notify("shape",{prop:"updateFontSize",onPropertyChange:!1,value:{obj:n.activeObj}});else{var p=void 0;if(void 0!==n.activeObj.shape&&(p=n.activeObj.shape.split("-")),"crop-custom"===n.activeObj.shape||void 0!==n.activeObj.shape&&"crop"!==p[0]||this.isCustomSelection()){if("image"===n.activeObj.shape||this.isCustomSelection()?this.resizeImg(e,o,"nw-resize",l):this.adjustNWPoints(s,e,o,n.activeObj.rotatedAngle),s.startX>s.endX){h=s.startX;s.startX=s.endX,s.endX=h,this.dragElement=n.upperCanvas.style.cursor=n.cursor="ne-resize"}if(s.startY>s.endY){var h=s.startY;s.startY=s.endY,s.endY=h,this.dragElement=n.upperCanvas.style.cursor=n.cursor="sw-resize"}this.revertCustomSelection(s,l,"nw-resize"),this.revertResizing(l)}else{var d=n.img,c=d.destLeft,u=d.destTop;if(s.startX<e&&s.startY<o){i=e-s.startX,r=o-s.startY,a=Math.min(i,r);f=this.getScaleRatio(a);s.startX+=f.x,s.startY+=f.y;var v=c>0?c:0,g=u>0?u:0;(s.startX<v||s.startY<g)&&(s.startX-=f.x,s.startY-=f.y)}else{i=s.startX-e,r=o-s.endY,a=Math.max(i,r);var f=this.getScaleRatio(a);s.startX-=f.x,s.startY-=f.y;var v=c>0?c:0,C=u>0?u:0;(s.startX<v||s.startY<C)&&(s.startX+=f.x,s.startY+=f.y)}s.width=s.endX-s.startX,s.height=s.endY-s.startY,this.revertResizing(l)}s.width=s.endX-s.startX,s.height=s.endY-s.startY,this.preventInverseResize(l)}},o.prototype.updateNPoints=function(e,o){var i,r,a,n=this.parent,s=n.activeObj.activePoint,l=t.extend({},n.activeObj,null,!0);if("text"!==n.activeObj.shape){var p=void 0;if(n.activeObj.shape&&(p=n.activeObj.shape.split("-")),"crop-custom"===n.activeObj.shape||n.activeObj.shape&&"crop"!==p[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=e,this.dragPoint.endY=o),i=this.dragPoint.endX-this.previousPoint.x,r=this.dragPoint.endY-this.previousPoint.y,this.adjustRotationPoints(s,i,r,n.activeObj.rotatedAngle)):(s.startY=o,s.height=s.endY-s.startY),s.startY>s.endY){var h=s.startY;s.startY=s.endY,s.endY=h,this.dragElement=this.resizedElement="s-resize"}this.revertResizing(l)}else{var d=n.img,c=d.destLeft,u=d.destTop,v=d.destWidth;if(this.isCustomSelection())this.performNWResize(e,o,l,s);else if(s.endX>e&&s.startY<o){i=s.endX-e,r=o-s.startY,a=Math.min(i,r);g=this.getScaleRatio(a);s.endX-=g.x,s.startY+=g.y,(s.endX>c+v||s.startY<u)&&(s.endX+=g.x,s.startY-=g.y)}else{i=e-s.endX,r=s.startY-o,a=Math.max(i,r);var g=this.getScaleRatio(a);s.endX+=g.x,s.startY-=g.y,(s.endX>c+v||s.startY<u)&&(s.endX-=g.x,s.startY+=g.y)}s.width=s.endX-s.startX,s.height=s.endY-s.startY,this.revertResizing(l)}}},o.prototype.updateNEPoints=function(e,o){var i,r,a,n=this.parent,s=n.activeObj.activePoint,l=t.extend({},n.activeObj,null,!0);if("text"===n.activeObj.shape)this.resizeImg(e,o,"ne-resize",l),n.notify("shape",{prop:"updateFontSize",onPropertyChange:!1,value:{obj:n.activeObj}});else{var p=void 0;if(n.activeObj.shape&&(p=n.activeObj.shape.split("-")),"crop-custom"===n.activeObj.shape||void 0!==n.activeObj.shape&&"crop"!==p[0]||this.isCustomSelection()){if("image"===n.activeObj.shape||this.isCustomSelection()?this.resizeImg(e,o,"ne-resize",l):this.adjustNEPoints(s,e,o,n.activeObj.rotatedAngle),s.endX<s.startX){h=s.endX;s.endX=s.startX,s.startX=h,this.dragElement=n.upperCanvas.style.cursor=n.cursor="nw-resize"}if(s.startY>s.endY){var h=s.startY;s.startY=s.endY,s.endY=h,this.dragElement=n.upperCanvas.style.cursor=n.cursor="se-resize"}this.revertCustomSelection(s,l,"ne-resize"),this.revertResizing(l)}else{var d=n.img,c=d.destLeft,u=d.destTop,v=d.destWidth;if(s.endX>e&&s.startY<o){i=s.endX-e,r=o-s.startY,a=Math.min(i,r);C=this.getScaleRatio(a);s.endX-=C.x,s.startY+=C.y;var g=c+v<n.lowerCanvas.width?c+v:n.lowerCanvas.width,f=u>0?u:0;(s.endX>g||s.startY<f)&&(s.endX+=C.x,s.startY-=C.y)}else{i=e-s.endX,r=s.startY-o,a=Math.max(i,r);var C=this.getScaleRatio(a);s.endX+=C.x,s.startY-=C.y;var g=c+v<n.lowerCanvas.width?c+v:n.lowerCanvas.width,f=u>0?u:0;(s.endX>g||s.startY<f)&&(s.endX-=C.x,s.startY+=C.y)}s.width=s.endX-s.startX,s.height=s.endY-s.startY,this.revertResizing(l)}s.width=s.endX-s.startX,s.height=s.endY-s.startY,this.preventInverseResize(l)}},o.prototype.updateWPoints=function(e,o){var i,r,a,n=this.parent,s=n.activeObj.activePoint,l=t.extend({},n.activeObj,null,!0);if("text"!==n.activeObj.shape){var p=void 0;if(n.activeObj.shape&&(p=n.activeObj.shape.split("-")),"crop-custom"===n.activeObj.shape||n.activeObj.shape&&"crop"!==p[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=e,this.dragPoint.endY=o),i=this.dragPoint.endX-this.previousPoint.x,r=this.dragPoint.endY-this.previousPoint.y,this.adjustRotationPoints(s,i,r,n.activeObj.rotatedAngle)):(s.startX=e,s.width=s.endX-s.startX),"line"===n.activeObj.shape||"arrow"===n.activeObj.shape||"path"===n.activeObj.shape)s.startY=o,s.height=s.endY-s.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(s.startX>s.endX){var h=s.startX;s.startX=s.endX,s.endX=h,this.dragElement=this.resizedElement="e-resize"}this.revertResizing(l)}else{var d=n.img,c=d.destLeft,u=d.destTop,v=d.destHeight;if(this.isCustomSelection())this.performNWResize(e,o,l,s);else if(s.startX<e&&s.endY>o){i=e-s.startX,r=s.endY-o,a=Math.min(i,r);g=this.getScaleRatio(a);s.startX+=g.x,s.endY-=g.y,(s.startX<c||s.endY>u+v)&&(s.startX-=g.x,s.endY+=g.y)}else{i=s.startX-e,r=o-s.endY,a=Math.max(i,r);var g=this.getScaleRatio(a);s.startX-=g.x,s.endY+=g.y,(s.startX<c||s.endY>u+v)&&(s.startX+=g.x,s.endY-=g.y)}s.width=s.endX-s.startX,s.height=s.endY-s.startY,this.revertResizing(l)}}},o.prototype.updateEPoints=function(e,o){var i,r,a,n=this.parent,s=n.activeObj.activePoint,l=t.extend({},n.activeObj,null,!0);if("text"!==n.activeObj.shape){var p=void 0;if(n.activeObj.shape&&(p=n.activeObj.shape.split("-")),"crop-custom"===n.activeObj.shape||n.activeObj.shape&&"crop"!==p[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=e,this.dragPoint.endY=o),i=this.dragPoint.endX-this.previousPoint.x,r=this.dragPoint.endY-this.previousPoint.y,this.adjustRotationPoints(s,i,r,n.activeObj.rotatedAngle)):(s.endX=e,s.width=s.endX-s.startX),"line"===n.activeObj.shape||"arrow"===n.activeObj.shape||"path"===n.activeObj.shape)s.endY=o,s.height=s.endY-s.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(s.endX<s.startX){var h=s.endX;s.endX=s.startX,s.startX=h,this.dragElement=this.resizedElement="w-resize"}this.revertResizing(l)}else{var d=n.img,c=d.destLeft,u=d.destTop,v=d.destWidth,g=d.destHeight;if(this.isCustomSelection())this.performSEResize(e,o,l,s);else if(s.endX>e&&s.endY>o){i=s.endX-e,r=s.endY-o,a=Math.min(i,r);f=this.getScaleRatio(a);s.endX-=f.x,s.endY-=f.y,(s.endX>c+v||s.endY>u+g)&&(s.endX+=f.x,s.endY+=f.y)}else{i=e-s.endX,r=o-s.endY,a=Math.max(i,r);var f=this.getScaleRatio(a);s.endX+=f.x,s.endY+=f.y,(s.endX>c+v||s.endY>u+g)&&(s.endX-=f.x,s.endY-=f.y)}s.width=s.endX-s.startX,s.height=s.endY-s.startY,this.revertResizing(l)}}},o.prototype.updateSWPoints=function(e,o){var i,r,a,n=this.parent,s=n.activeObj.activePoint,l=t.extend({},n.activeObj,null,!0);if("text"===n.activeObj.shape)this.resizeImg(e,o,"sw-resize",l),n.notify("shape",{prop:"updateFontSize",onPropertyChange:!1,value:{obj:n.activeObj}});else{var p=void 0;if(void 0!==n.activeObj.shape&&(p=n.activeObj.shape.split("-")),"crop-custom"===n.activeObj.shape||void 0!==n.activeObj.shape&&"crop"!==p[0]||this.isCustomSelection()){if("image"===n.activeObj.shape||this.isCustomSelection()?this.resizeImg(e,o,"sw-resize",l):this.adjustSWPoints(s,e,o,n.activeObj.rotatedAngle),s.startX>s.endX){h=s.startX;s.startX=s.endX,s.endX=h,this.dragElement=n.upperCanvas.style.cursor=n.cursor="se-resize"}if(s.endY<s.startY){var h=s.endY;s.endY=s.startY,s.startY=h,this.dragElement=n.upperCanvas.style.cursor=n.cursor="nw-resize"}this.revertCustomSelection(s,l,"sw-resize"),this.revertResizing(l)}else{var d=n.img,c=d.destLeft,u=d.destTop,v=d.destHeight;if(s.startX<e&&s.endY>o){i=e-s.startX,r=s.endY-o,a=Math.min(i,r);C=this.getScaleRatio(a);s.startX+=C.x,s.endY-=C.y;var g=c>0?c:0,f=u+v<n.lowerCanvas.height?u+v:n.lowerCanvas.height;(s.startX<g||s.endY>f)&&(s.startX-=C.x,s.endY+=C.y)}else{i=s.startX-e,r=o-s.endY,a=Math.max(i,r);var C=this.getScaleRatio(a);s.startX-=C.x,s.endY+=C.y;var g=c>0?c:0,f=u+v<n.lowerCanvas.height?u+v:n.lowerCanvas.height;(s.startX<g||s.endY>f)&&(s.startX+=C.x,s.endY-=C.y)}s.width=s.endX-s.startX,s.height=s.endY-s.startY,this.revertResizing(l)}s.width=s.endX-s.startX,s.height=s.endY-s.startY,this.preventInverseResize(l)}},o.prototype.updateSPoints=function(e,o){var i,r,a,n=this.parent,s=n.activeObj.activePoint,l=t.extend({},n.activeObj,null,!0);if("text"!==n.activeObj.shape){var p=void 0;if(n.activeObj.shape&&(p=n.activeObj.shape.split("-")),"crop-custom"===n.activeObj.shape||n.activeObj.shape&&"crop"!==p[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=e,this.dragPoint.endY=o),i=this.dragPoint.endX-this.previousPoint.x,r=this.dragPoint.endY-this.previousPoint.y,this.adjustRotationPoints(s,i,r,n.activeObj.rotatedAngle)):(s.endY=o,s.height=s.endY-s.startY),s.endY<s.startY){var h=s.endY;s.endY=s.startY,s.startY=h,this.dragElement=this.resizedElement="n-resize"}this.revertResizing(l)}else{var d=n.img,c=d.destLeft,u=d.destTop,v=d.destWidth,g=d.destHeight;if(this.isCustomSelection())this.performSEResize(e,o,l,s);else if(s.endX>e&&s.endY>o){i=s.endX-e,r=s.endY-o,a=Math.min(i,r);f=this.getScaleRatio(a);s.endX-=f.x,s.endY-=f.y,(s.endX>c+v||s.endY>u+g)&&(s.endX+=f.x,s.endY+=f.y)}else{i=e-s.endX,r=o-s.endY,a=Math.max(i,r);var f=this.getScaleRatio(a);s.endX+=f.x,s.endY+=f.x,(s.endX>c+v||s.endY>u+g)&&(s.endX-=f.x,s.endY-=f.y)}s.width=s.endX-s.startX,s.height=s.endY-s.startY,this.revertResizing(l)}}},o.prototype.updateSEPoints=function(e,o){var i,r,a,n=this.parent,s=n.activeObj.activePoint,l=t.extend({},n.activeObj,null,!0);if("text"===n.activeObj.shape)this.resizeImg(e,o,"se-resize",l),n.notify("shape",{prop:"updateFontSize",onPropertyChange:!1,value:{obj:n.activeObj}});else{var p=void 0,h=void 0;if(void 0!==n.activeObj.shape&&(p=n.activeObj.shape.split("-")),"crop-custom"===n.activeObj.shape||void 0!==n.activeObj.shape&&"crop"!==p[0]||this.isCustomSelection()){if("image"===n.activeObj.shape||this.isCustomSelection()?this.resizeImg(e,o,"se-resize",l):this.adjustSEPoints(s,e,o,n.activeObj.rotatedAngle),s.endX<s.startX){d=s.endX;s.endX=s.startX,s.startX=d,this.dragElement=n.upperCanvas.style.cursor=n.cursor="sw-resize"}if(s.endY<s.startY){var d=s.endY;s.endY=s.startY,s.startY=d,this.dragElement=n.upperCanvas.style.cursor=n.cursor="ne-resize"}this.revertCustomSelection(s,l,"se-resize"),this.revertResizing(l)}else{var c=n.img,u=c.destLeft,v=c.destTop,g=c.destWidth,f=c.destHeight;if(s.endX>e&&s.endY>o){i=s.endX-e,r=s.endY-o,a=Math.min(i,r),h=this.getScaleRatio(a),s.endX-=h.x,s.endY-=h.y;var C=u+g<n.lowerCanvas.width?u+g:n.lowerCanvas.width,b=v+f<n.lowerCanvas.height?v+f:n.lowerCanvas.height;(s.endX>C||s.endY>b)&&(s.endX+=h.x,s.endY+=h.y)}else{i=e-s.endX,r=o-s.endY,a=Math.max(i,r),h=this.getScaleRatio(a),s.endX+=h.x,s.endY+=h.y;var C=u+g<n.lowerCanvas.width?u+g:n.lowerCanvas.width,b=v+f<n.lowerCanvas.height?v+f:n.lowerCanvas.height;(s.endX>C||s.endY>b)&&(s.endX-=h.x,s.endY-=h.y)}s.width=s.endX-s.startX,s.height=s.endY-s.startY,this.revertResizing(l)}this.preventInverseResize(l)}},o.prototype.resizeImg=function(e,o,i,r){var a,n,s=this.parent,l=s.activeObj.activePoint;if(0!==this.previousPoint.x&&0!==this.previousPoint.y){if("text"===this.currentDrawingShape&&(this.setCursor(e,o),0===s.activeObj.textSettings.fontSize)){s.activeObj.textSettings.fontSize=11,s.notify("shape",{prop:"updateFontRatio",onPropertyChange:!1,value:{obj:s.activeObj,isTextArea:null}}),s.activeObj.textSettings.text=s.activeObj.keyHistory="Enter Text",s.notify("shape",{prop:"updateFontStyles",onPropertyChange:!1,value:{isTextBox:null}});var p=this.upperContext.measureText(s.activeObj.textSettings.text).width+.5*s.activeObj.textSettings.fontSize;l.endX=l.startX+p,l.endY=l.startY+s.activeObj.textSettings.fontSize,l.width=l.endX-l.startX,l.height=l.endY-l.startY,r=t.extend({},s.activeObj,null,!0),s.notify("draw",{prop:"updateActiveObject",onPropertyChange:!1,value:{actPoint:s.activeObj.activePoint,obj:s.activeObj,isMouseMove:null,x:null,y:null}})}switch(s.upperCanvas.style.cursor){case"se-resize":case"s-resize":this.previousPoint.x>e||this.previousPoint.y>o?(a=(this.previousPoint.x-e+(this.previousPoint.y-o))/2,n=this.getScaleRatio(a),this.adjustRotationPoints(l,-Math.abs(n.x),-Math.abs(n.y),s.activeObj.rotatedAngle,"img-resize",i)):0!==this.previousPoint.x&&0!==this.previousPoint.y&&(a=(e-this.previousPoint.x+(o-this.previousPoint.y))/2,n=this.getScaleRatio(a),this.adjustRotationPoints(l,Math.abs(n.x),Math.abs(n.y),s.activeObj.rotatedAngle,"img-resize",i));break;case"sw-resize":this.previousPoint.x<e||this.previousPoint.y>o?(a=(e-this.previousPoint.x+(this.previousPoint.y-o))/2,n=this.getScaleRatio(a),this.adjustRotationPoints(l,-Math.abs(n.x),-Math.abs(n.y),s.activeObj.rotatedAngle,"img-resize",i)):0!==this.previousPoint.x&&0!==this.previousPoint.y&&(a=(this.previousPoint.x-e+(o-this.previousPoint.y))/2,n=this.getScaleRatio(a),this.adjustRotationPoints(l,Math.abs(n.x),Math.abs(n.y),s.activeObj.rotatedAngle,"img-resize",i));break;case"w-resize":case"nw-resize":this.previousPoint.x<e||this.previousPoint.y<o?(a=(e-this.previousPoint.x+(o-this.previousPoint.y))/2,n=this.getScaleRatio(a),this.adjustRotationPoints(l,-Math.abs(n.x),-Math.abs(n.y),s.activeObj.rotatedAngle,"img-resize",i)):0!==this.previousPoint.x&&0!==this.previousPoint.y&&(a=(this.previousPoint.x-e+(this.previousPoint.y-o))/2,n=this.getScaleRatio(a),this.adjustRotationPoints(l,Math.abs(n.x),Math.abs(n.y),s.activeObj.rotatedAngle,"img-resize",i));break;case"n-resize":case"ne-resize":this.previousPoint.x>e||this.previousPoint.y<o?(a=(this.previousPoint.x-e+(o-this.previousPoint.y))/2,n=this.getScaleRatio(a),this.adjustRotationPoints(l,-Math.abs(n.x),-Math.abs(n.y),s.activeObj.rotatedAngle,"img-resize",i)):0!==this.previousPoint.x&&0!==this.previousPoint.y&&(a=(e-this.previousPoint.x+(this.previousPoint.y-o))/2,n=this.getScaleRatio(a),this.adjustRotationPoints(l,Math.abs(n.x),Math.abs(n.y),s.activeObj.rotatedAngle,"img-resize",i));break;case"e-resize":this.previousPoint.x>e||this.previousPoint.y>o?(a=(this.previousPoint.x-e+(this.previousPoint.y-o))/2,n=this.getScaleRatio(a),this.adjustRotationPoints(l,-Math.abs(n.x),-Math.abs(n.y),s.activeObj.rotatedAngle,"img-resize",i)):0!==this.previousPoint.x&&0!==this.previousPoint.y&&(a=(e-this.previousPoint.x+(o-this.previousPoint.y))/2,n=this.getScaleRatio(a),this.adjustRotationPoints(l,Math.abs(n.x),Math.abs(n.y),s.activeObj.rotatedAngle,"img-resize",i))}l.width=l.endX-l.startX,l.height=l.endY-l.startY,(l.width<10||l.height<10||"text"===s.activeObj.shape&&0===s.activeObj.rotatedAngle&&this.preventTextDraggingInvertly())&&(s.activeObj=t.extend({},r,null,!0))}this.previousPoint={x:e,y:o}},o.prototype.adjustNWPoints=function(e,t,o,i){var r=e.startX+e.width/2,a=e.startY+e.height/2,n=this.rotatePoints(e.endX,e.endY,r,a,i),s=[(n[0]+t)/2,(n[1]+o)/2],l=this.rotatePoints(n[0],n[1],s[0],s[1],-i),p=this.rotatePoints(t,o,s[0],s[1],-i);return e.endX=l[0],e.endY=l[1],e.startY=p[1],e.startX=p[0],e.width=e.endX-e.startX,e.height=e.endY-e.startY,e},o.prototype.adjustNEPoints=function(e,t,o,i){var r=e.startX+e.width/2,a=e.startY+e.height/2,n=this.rotatePoints(e.startX,e.endY,r,a,i),s=[(n[0]+t)/2,(n[1]+o)/2],l=this.rotatePoints(n[0],n[1],s[0],s[1],-i),p=this.rotatePoints(t,o,s[0],s[1],-i);return e.startX=l[0],e.endY=l[1],e.width=p[0]-l[0],e.height=l[1]-p[1],e.endX=e.startX+e.width,e.startY=e.endY-e.height,e},o.prototype.adjustSWPoints=function(e,t,o,i){var r=e.startX+e.width/2,a=e.startY+e.height/2,n=this.rotatePoints(e.endX,e.startY,r,a,i),s=[(n[0]+t)/2,(n[1]+o)/2],l=this.rotatePoints(n[0],n[1],s[0],s[1],-i),p=this.rotatePoints(t,o,s[0],s[1],-i);return e.endX=l[0],e.startY=l[1],e.startX=p[0],e.endY=p[1],e.width=e.endX-e.startX,e.height=e.endY-e.startY,e},o.prototype.adjustSEPoints=function(e,t,o,i){var r=e.startX+e.width/2,a=e.startY+e.height/2,n=this.rotatePoints(e.startX,e.startY,r,a,i),s=[(n[0]+t)/2,(n[1]+o)/2],l=this.rotatePoints(n[0],n[1],s[0],s[1],-i),p=this.rotatePoints(t,o,s[0],s[1],-i);return e.startX=l[0],e.startY=l[1],e.width=p[0]-l[0],e.height=p[1]-l[1],e.endX=e.startX+e.width,e.endY=e.startY+e.height,e},o.prototype.adjustRotationPoints=function(e,t,o,i,r,a){var n=e.startX+e.width/2,s=e.startY+e.height/2;this.getResizeDirection(e,t,o,i,r,a);var l=this.rotatePoints(e.startX,e.startY,n,s,i),p=this.rotatePoints(e.endX,e.startY,n,s,i),h=this.rotatePoints(e.endX,e.endY,n,s,i),d=this.rotatePoints(e.startX,e.endY,n,s,i),c=[(l[0]+h[0])/2,(l[1]+h[1])/2],u=this.rotatePoints(l[0],l[1],c[0],c[1],-i),v=this.rotatePoints(d[0],d[1],c[0],c[1],-i),g=this.rotatePoints(p[0],p[1],c[0],c[1],-i);return e.startX=u[0],e.startY=u[1],e.endX=g[0],e.endY=v[1],e.width=e.endX-e.startX,e.height=e.endY-e.startY,e},o.prototype.rotatePoints=function(e,t,o,i,r){return[(e-o)*Math.cos(r)-(t-i)*Math.sin(r)+o,(e-o)*Math.sin(r)+(t-i)*Math.cos(r)+i]},o.prototype.setResizedValue=function(e,t,o,i){switch(e){case"x":t+=o;break;case"y":t+=i;break;case"abs-x":t+=o>0?-o:Math.abs(o);break;case"abs-y":t+=i>0?-i:Math.abs(i);break;case"y-abs-x":t+=i+(o>0?-o:Math.abs(o))/2;break;case"abs-x-abs-y":t+=(o>0?-o:Math.abs(o))+(i>0?-i:Math.abs(i))/2;break;case"abs-y-x":t+=(i>0?-i:Math.abs(i))+o/2;break;case"x-y":t+=o+i/2;break;case"y-x":t+=i+o/2;break;case"img-resize-x":t+=o;break;case"img-resize-y":t+=i}return t},o.prototype.getResizeDirection=function(e,t,o,i,r,a){var n=i*(180/Math.PI),s=this.getResizedElement(n,this.resizedElement);"e-resize"===this.resizedElement?(e.width=this.setResizedValue(s,e.width,t,o),e.endX=e.width+e.startX):"n-resize"===this.resizedElement?(e.startY=this.setResizedValue(s,e.startY,t,o),e.height=e.endY-e.startY):"w-resize"===this.resizedElement?(e.startX=this.setResizedValue(s,e.startX,t,o),e.width=e.startX+e.endX):"s-resize"===this.resizedElement?(e.height=this.setResizedValue(s,e.height,t,o),e.endY=e.height+e.startY):r&&"img-resize"===r?(e.width=this.setResizedValue("img-resize-x",e.width,t,o),e.height=this.setResizedValue("img-resize-y",e.height,t,o),"se-resize"===a?(e.endX=e.width+e.startX,e.endY=e.height+e.startY):"sw-resize"===a?(e.startX=e.endX-e.width,e.endY=e.height+e.startY):"ne-resize"===a?(e.endX=e.width+e.startX,e.startY=e.endY-e.height):"nw-resize"===a&&(e.startX=e.endX-e.width,e.startY=e.endY-e.height)):r&&"text"===r&&("widthHeight"===a?(e.width=this.setResizedValue("x-y",e.width,t,o),e.endX=e.width+e.startX,e.height=this.setResizedValue("y-x",e.height,t,o),e.endY=e.height+e.startY):"width"===a?(e.width=this.setResizedValue("x-y",e.width,t,o),e.endX=e.width+e.startX):"height"===a&&(e.height=this.setResizedValue("y-abs-x",e.height,t,o),e.endY=e.height+e.startY))},o.prototype.getResizedElement=function(e,t){var o=[];"n-resize"===t?o=[[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"===t?o=[[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"===t?o=[[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"===t&&(o=[[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 i=e<0?360-Math.abs(e):e,r=0,a=o;r<a.length;r++){var n=a[r],s=n[0],l=n[1],p=n[2];if(i>s&&i<=l||i+360>s&&i+360<=l)return p}return t},o.prototype.updateCursorStyles=function(e,o,i){var r=this.parent,a=!1;""===r.activeObj.keyHistory||void 0!==r.activeObj.shape||r.currObjType.isCustomCrop||r.currObjType.isLine||!r.currObjType.isText||(r.activeObj.shape="text");var n=t.extend({},r.activeObj,{},!0);if(!t.isNullOrUndefined(n.topLeftCircle)){var s;if((s=0===n.shapeDegree?r.transform.degree:r.transform.degree-n.shapeDegree)<0&&(s=360+s),this.isObjSelected)if("line"===n.shape||"arrow"===n.shape)a=this.updateCursorStylesForLineArrow(e,o,n);else if("path"===n.shape)a=this.updateCursorStylesForPath(e,o,n);else if(n.rotatedAngle)this.setCursorForRotatedObject(n,e,o,r.upperCanvas),"grabbing"===r.cursor?(r.upperCanvas.style.cursor=r.cursor="grabbing",this.dragElement=r.cursor):"move"===r.cursor?(this.dragPoint.startX=this.previousPoint.x=this.dragPoint.endX=e,this.dragPoint.startY=this.previousPoint.y=this.dragPoint.endY=o):"default"!==r.cursor&&(a=!0,this.dragElement=r.cursor,r.currObjType.isResize=!0);else{var l=this.getTransRotationPoint(n),p=n.topLeftCircle.radius;l&&e>=l.x-2*p&&e<=l.x+2*p&&o>=l.y-2*p&&o<=l.y+2*p&&"grabbing"!==this.dragElement?(r.upperCanvas.style.cursor=r.cursor="grabbing",this.dragElement=r.upperCanvas.style.cursor):e>=n.topLeftCircle.startX-2*p&&e<=n.topLeftCircle.startX+2*p&&o>=n.topLeftCircle.startY-2*p&&o<=n.topLeftCircle.startY+2*p&&"nw-resize"!==this.dragElement?(n.topLeftCircle.startX=n.topLeftCircle.startY=0,r.upperCanvas.style.cursor=r.cursor="nw-resize",a=!0,this.dragElement=r.upperCanvas.style.cursor):e>=n.topLeftCircle.startX-2*p&&e<=n.topRightCircle.startX-2*p&&o>=n.topCenterCircle.startY-2*p&&o<=n.topCenterCircle.startY+2*p&&"n-resize"!==this.dragElement?(n.topCenterCircle.startX=n.topCenterCircle.startY=0,r.upperCanvas.style.cursor=r.cursor="n-resize",a=!0,this.dragElement=r.upperCanvas.style.cursor):e>=n.topRightCircle.startX-2*p&&e<=n.topRightCircle.startX+2*p&&o>=n.topRightCircle.startY-2*p&&o<=n.topRightCircle.startY+2*p&&"ne-resize"!==this.dragElement?(n.topRightCircle.startX=n.topRightCircle.startY=0,r.upperCanvas.style.cursor=r.cursor="ne-resize",a=!0,this.dragElement=r.upperCanvas.style.cursor):e>=n.centerLeftCircle.startX-2*p&&e<=n.centerLeftCircle.startX+2*p&&o>=n.topLeftCircle.startY-2*p&&o<=n.bottomLeftCircle.startY-2*p&&"w-resize"!==this.dragElement?(n.centerLeftCircle.startX=n.centerLeftCircle.startY=0,r.upperCanvas.style.cursor=r.cursor="w-resize",a=!0,this.dragElement=r.upperCanvas.style.cursor):e>=n.centerRightCircle.startX-2*p&&e<=n.centerRightCircle.startX+2*p&&o>=n.topRightCircle.startY-2*p&&o<=n.bottomRightCircle.startY-2*p&&"e-resize"!==this.dragElement?(n.centerRightCircle.startX=n.centerRightCircle.startY=0,r.upperCanvas.style.cursor=r.cursor="e-resize",a=!0,this.dragElement=r.upperCanvas.style.cursor):e>=n.bottomLeftCircle.startX-2*p&&e<=n.bottomLeftCircle.startX+2*p&&o>=n.bottomLeftCircle.startY-2*p&&o<=n.bottomLeftCircle.startY+2*p&&"sw-resize"!==this.dragElement?(n.bottomLeftCircle.startX=n.bottomLeftCircle.startY=0,r.upperCanvas.style.cursor=r.cursor="sw-resize",a=!0,this.dragElement=r.upperCanvas.style.cursor):e>=n.bottomLeftCircle.startX-2*p&&e<=n.bottomRightCircle.startX-2*p&&o>=n.bottomCenterCircle.startY-2*p&&o<=n.bottomCenterCircle.startY+2*p&&"s-resize"!==this.dragElement?(n.bottomCenterCircle.startX=n.bottomCenterCircle.startY=0,r.upperCanvas.style.cursor=r.cursor="s-resize",a=!0,this.dragElement=r.upperCanvas.style.cursor):e>=n.bottomRightCircle.startX-2*p&&e<=n.bottomRightCircle.startX+2*p&&o>=n.bottomRightCircle.startY-2*p&&o<=n.bottomRightCircle.startY+2*p&&"se-resize"!==this.dragElement?(n.bottomRightCircle.startX=n.bottomRightCircle.startY=0,r.upperCanvas.style.cursor=r.cursor="se-resize",a=!0,this.dragElement=r.upperCanvas.style.cursor):(this.dragPoint.startX=this.previousPoint.x=this.dragPoint.endX=e,this.dragPoint.startY=this.previousPoint.y=this.dragPoint.endY=o),"text"!==n.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=e,this.dragPoint.startY=this.previousPoint.y=this.dragPoint.endY=o)}else this.dragPoint.startX=this.previousPoint.x=this.dragPoint.endX=e,this.dragPoint.startY=this.previousPoint.y=this.dragPoint.endY=o;this.previousPoint.x=this.previousPoint.y=this.diffPoint.x=this.diffPoint.y=0,"touchstart"===i?a||e>=n.activePoint.startX&&e<=n.activePoint.endX&&o>=n.activePoint.startY&&o<=n.activePoint.endY||"grabbing"===this.dragElement?r.currObjType.isDragging=!0:"line"===n.shape||"arrow"===n.shape?(this.setCursorForLineArrow(n,e,o,r.upperCanvas),"move"===r.cursor&&(r.currObjType.isDragging=!0)):"path"===n.shape&&(this.setCursorForPath(n,e,o,r.upperCanvas),"move"===r.cursor&&(r.currObjType.isDragging=!0)):r.currObjType.isDragging=!0,0===n.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=e,this.dragPoint.startY=this.previousPoint.y=this.dragPoint.endY=o)}},o.prototype.updateCursorStylesForLineArrow=function(e,t,o){for(var i,r=!1,a=this.parent,n=o.topLeftCircle.radius,s=0;s<5;s++)if(i=o.pointColl[s],e>=i.x-2*n&&e<=i.x+2*n&&t>=i.y-2*n&&t<=i.y+2*n){o.centerLeftCircle.startX=o.centerLeftCircle.startY=0,this.dragElement="w-resize",r=!0;break}if(!r)for(s=1;s<6;s++)if(i=o.pointColl[o.pointColl.length-s],e>=i.x-2*n&&e<=i.x+2*n&&t>=i.y-2*n&&t<=i.y+2*n){o.centerRightCircle.startX=o.centerRightCircle.startY=0,this.dragElement="e-resize",r=!0;break}if(!r)for(s=0;s<o.pointColl.length;s++){if(i=o.pointColl[s],e>=i.x-2*n&&e<=i.x+2*n&&t>=i.y-2*n&&t<=i.y+2*n){a.upperCanvas.style.cursor=a.cursor="move",this.dragPoint.startX=this.previousPoint.x=this.dragPoint.endX=e,this.dragPoint.startY=this.previousPoint.y=this.dragPoint.endY=t;break}a.upperCanvas.style.cursor=a.cursor="default"}return r},o.prototype.updateCursorStylesForPath=function(e,t,o){var i=!1,r=this.parent;return this.pathAdjustedIndex=this.setCursorForLineArrow(o,e,t,r.upperCanvas),"move"===r.cursor&&(i=!0,this.dragElement="pathDrag"),i||(r.upperCanvas.style.cursor=r.cursor="move",this.dragPoint.startX=this.previousPoint.x=this.dragPoint.endX=e,this.dragPoint.startY=this.previousPoint.y=this.dragPoint.endY=t),i},o.prototype.setTextSelection=function(e,t){var o=this.parent,i=o.activeObj.activePoint,r=o.transform.degree;(r=0===o.activeObj.shapeDegree?o.transform.degree:o.transform.degree-o.activeObj.shapeDegree)<0&&(r=360+r);for(var a=0,n=o.activeObj.flipObjColl.length;a<n;a++){var s=o.activeObj.flipObjColl[a].toLowerCase();switch(r){case 0:switch(s){case"horizontal":i={startX:i.endX-e,startY:i.startY,endX:i.endX,endY:i.startY+(t||0)};break;case"vertical":i.startY=i.endY-t,i={startX:i.startX,startY:i.startY,endX:i.startX+(e||0),endY:i.endY};break;default:i={startX:i.startX,startY:i.startY,endX:i.startX+(e||0),endY:i.startY+(t||0)}}break;case 90:switch(s){case"horizontal":i.endX=i.startX+t,i={startX:i.startX,startY:i.startY,endX:i.endX,endY:i.startY+(e||0)};break;case"vertical":i.startX=i.endX-t,i={startX:i.startX,startY:i.endY-e,endX:i.endX,endY:i.endY};break;default:i.startX=i.endX-t,i={startX:i.startX,startY:i.startY,endX:i.endX,endY:i.startY+(e||0)}}break;case 180:switch(s){case"horizontal":i.startY=i.endY-t,i={startX:i.startX,startY:i.startY,endX:i.startX+e,endY:i.endY};break;case"vertical":i.endY=i.startY+t,i={endX:i.endX,endY:i.endY,startX:i.endX-(e||0),startY:i.startY};break;default:i={endX:i.endX,endY:i.endY,startX:i.endX-(e||0),startY:i.endY-(t||0)}}break;case 270:switch(s){case"horizontal":i.startX=i.endX-t,i={startX:i.startX,startY:i.endY-(e||0),endX:i.endX,endY:i.endY};break;case"vertical":i={startX:i.startX,startY:i.startY,endX:i.startX+t,endY:i.startY+(e||0)};break;default:i.endX=i.startX+t,i={startX:i.startX,startY:i.endY-(e||0),endX:i.endX,endY:i.endY}}}}if(0===o.activeObj.flipObjColl.length)switch(r){case 0:i={startX:i.startX,startY:i.startY,endX:i.startX+(e||0),endY:i.startY+(t||0)};break;case 90:i.startX=i.endX-t,i={startX:i.startX,startY:i.startY,endX:i.endX,endY:i.startY+(e||0)};break;case 180:i={endX:i.endX,endY:i.endY,startX:i.endX-(e||0),startY:i.endY-(t||0)};break;case 270:i.endX=i.startX+t,i={startX:i.startX,startY:i.endY-(e||0),endX:i.endX,endY:i.endY}}i.width=i.endX-i.startX,i.height=i.endY-i.startY,o.activeObj.activePoint=i,360!==o.transform.degree&&-360!==o.transform.degree||(o.transform.degree=0)},o.prototype.setActivePoint=function(e,o){var i=this.parent,r=i.activeObj.activePoint;if(!t.isNullOrUndefined(r))if(i.currObjType.isText){var a=e||0,n=o||i.activeObj.textSettings.fontSize;void 0===i.activeObj.textSettings.fontSize&&(i.activeObj.textSettings.fontSize=.1*Math.abs(i.baseImgCanvas.width-i.baseImgCanvas.height)),this.setTextSelection(a,n),this.mouseDownPoint.x=r.endX,this.mouseDownPoint.y=r.endY,void 0!==i.activeObj.horTopLine&&(i.activeObj.activePoint=t.extend({},r,{},!0)),i.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate"}})}else if(e&&o)r.startX=this.mouseDownPoint.x=e,r.startY=this.mouseDownPoint.y=o,i.currObjType.isDragging=!0;else{var s=i.activeObj;(r={startX:s.horTopLine.startX,startY:s.horTopLine.startY,endX:s.horTopLine.endX,endY:s.horTopLine.endY}).width=r.endX-r.startX,r.height=r.endY-r.startY}},o.prototype.mouseDownEventHandler=function(e){var t=this.parent;if(t.isKBDNavigation=!1,this.mouseDown=e.currentTarget===t.lowerCanvas||e.currentTarget===t.upperCanvas?"canvas":"","touchstart"===e.type?this.isTouch=!0:this.isTouch=!1,"touchstart"!==e.type||e.currentTarget!==t.lowerCanvas||t.isImageLoaded){this.isCropSelection=!1,this.isPan=!0;var o;if(void 0!==t.activeObj.shape&&(o=t.activeObj.shape.split("-")),void 0!==o&&"crop"===o[0]&&(this.isCropSelection=!0),this.isCropSelection&&(this.dragCanvas=t.togglePan=!0),"grabbing"===t.cursor){var i={shapeSettingsObj:{}};this.isGrabbing=!0,t.notify("selection",{prop:"updatePrevShapeSettings",onPropertyChange:!1,value:{obj:i}});var r=i.shapeSettingsObj,a={cancel:!1,action:"rotate-start",previousShapeSettings:r,allowShapeOverflow:this.allowOutofBound()},n={cancel:!1,action:"rotate-start",previousShapeSettings:r,allowShapeOverflow:this.allowOutofBound()};this.triggerShapeChange(a,n,"mouse-down")}var s={point:this.setXYPoints(e)};t.trigger("click",s),this.clickEvent(s,e)}},o.prototype.getImagePoints=function(e,t){var o=this.parent.img,i=o.destLeft,r=o.destTop,a=o.destWidth,n=o.destHeight;return e<i?e=i:e>i+a&&(e=i+a),t<r?t=r:t>r+n&&(t=r+n),{x:e,y:t}},o.prototype.clickEvent=function(o,i){var r=this.parent,a=r.activeObj.activePoint,n=o.point.x,s=o.point.y,l=r.activeObj.shape&&"text"===r.activeObj.shape?r.cursor:"default",p=r.upperCanvas.style.cursor;if(r.isResize)return this.performEnterAction(),void(r.upperCanvas.style.cursor="default");if(JSON.stringify(r.frameObj)!==JSON.stringify(r.tempFrameObj))r.okBtn();else if(""!==this.currentDrawingShape&&!this.isShapeTouch(i,this.isCropSelection)&&(this.isTouch||"crosshair"===p||r.isShapeDrawing)){r.drawingShape&&!r.isShapeDrawing&&(r.okBtn(),r.enableShapeDrawing(r.toPascalCase(r.drawingShape),!0)),a=r.activeObj.activePoint;var h={currObj:{}};r.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:h}}),this.initialPrevObj=h.currObj,this.initialPrevObj.objColl=t.extend([],r.objColl,[],!0),this.initialPrevObj.pointColl=t.extend([],r.pointColl,[],!0),this.initialPrevObj.afterCropActions=t.extend([],r.afterCropActions,[],!0);var d={selPointColl:null};if(r.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:d}}),this.initialPrevObj.selPointColl=t.extend([],d.selPointColl,[],!0),this.setActivePoint(n,s),a=r.activeObj.activePoint,"path"===this.currentDrawingShape){L=this.getImagePoints(n,s);r.activeObj.pointColl.push({x:L.x,y:L.y}),0!==a.width&&0!==a.height&&(a.width=0,a.height=0,a.startX=r.activeObj.pointColl[r.activeObj.pointColl.length-1].x,a.startY=r.activeObj.pointColl[r.activeObj.pointColl.length-1].y)}if(a.endX=a.startX,a.endY=a.startY,"text"===this.currentDrawingShape){r.activeObj.textSettings.fontSize=11,this.previousPoint.x=a.startX,this.previousPoint.y=a.startY,r.notify("shape",{prop:"updateFontStyles",onPropertyChange:!1,value:{isTextBox:null}});var c=this.upperContext.measureText(r.activeObj.textSettings.text).width+.5*r.activeObj.textSettings.fontSize;a.endX=a.startX+c,a.endY=a.startY+r.activeObj.textSettings.fontSize,a.width=a.endX-a.startX,a.height=a.endY-a.startY}else"arrow"===this.currentDrawingShape&&(r.activeObj.start=this.arrowShape[0],r.activeObj.end=this.arrowShape[1]);r.currObjType.isDragging=!0;var u=this.updatePrevShapeSettings(),v={cancel:!1,action:"draw-start",previousShapeSettings:u,allowShapeOverflow:this.allowOutofBound()},g={cancel:!1,action:"move",previousShapeSettings:u,allowShapeOverflow:this.allowOutofBound()};return this.shapeResizingArgs=v,this.shapeMovingArgs=g,this.triggerShapeChange(v,g,"mouse-down"),r.activeObj.activePoint=a,void(r.isShapeDrawing=!0)}r.notify("draw",{prop:"resetFrameZoom",onPropertyChange:!1,value:{isOk:!0}}),this.isCropSelection&&this.dragCanvas&&(this.setCursor(n,s),"move"!==r.cursor&&"crosshair"!==r.cursor&&"default"!==r.cursor&&"grab"!==r.cursor&&(this.isPan=!1)),r.activeObj.shape?this.isObjSelected=!0:this.isObjSelected=!1;var f={currObj:{}};r.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:f}});var C=f.currObj,b=t.extend({},r.activeObj,null,!0),m=this.isShapeTouch(i,this.isCropSelection),y=this.isFreehandDrawTouch(i,this.isCropSelection),P=m||this.isShapeClick(i,this.isCropSelection),j=this.applyCurrShape(P),x="none"!==r.textArea.style.display;if(this.isTouch&&!m&&b.shape&&!this.isCropSelection){this.applyObj(n,s)&&(r.okBtn(!0),r.notify("draw",{prop:"setPrevActObj",onPropertyChange:!1,value:{prevActObj:null}}));var w=t.extend({},r.cropObj,{},!0);r.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"shapeTransform",previousObj:C,previousObjColl:C.objColl,previousPointColl:C.pointColl,previousSelPointColl:C.selPointColl,previousCropObj:w,previousText:null,currentText:null,previousFilter:null,isCircleCrop:r.isCircleCrop}}),j&&r.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"ok"}})}if(m||r.togglePen||this.isCropSelection||"blur"===r.activeObj.redactType||"pixelate"===r.activeObj.redactType||(r.notify("toolbar",{prop:"refresh-main-toolbar",onPropertyChange:!1}),r.notify("toolbar",{prop:"close-contextual-toolbar",onPropertyChange:!1})),!this.dragCanvas||!this.isPan||"grab"!==r.cursor&&!this.isTouch||m||y||r.togglePen){var O=!1;!r.activeObj.shape||"line"!==r.activeObj.shape&&"arrow"!==r.activeObj.shape||(O=!0);var S=this.setXYPoints(i),T=S.x,k=S.y;if(this.applyObj(T,k)){if(r.okBtn(!0),j){var F=r.cursor;r.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"ok"}}),r.cursor=F}r.notify("draw",{prop:"setPrevActObj",onPropertyChange:!1,value:{prevActObj:null}})}r.notify("shape",{prop:"redrawActObj",onPropertyChange:!1,value:{x:T,y:k,isMouseDown:!0}});var I={index:null};r.notify("freehand-draw",{prop:"getFreehandDrawHoveredIndex",onPropertyChange:!1,value:{obj:I}});var A={freehandSelectedIndex:null};if(r.notify("freehand-draw",{prop:"getFreehandSelectedIndex",onPropertyChange:!1,value:{obj:A}}),this.isFhdPoint||this.isFhdCustomized&&!r.togglePen){if(!t.isNullOrUndefined(A.freehandSelectedIndex)&&A.freehandSelectedIndex!==I.index){var z=I.index;if(r.okBtn(),this.isFhdCustomized=!1,r.notify("freehand-draw",{prop:"setFreehandDrawHoveredIndex",onPropertyChange:!1,value:{index:z}}),I.index>-1){D=r.pointColl[I.index].strokeColor;r.notify("freehand-draw",{prop:"hoverFhd",onPropertyChange:!1,value:{strokeColor:D,strokeWidth:r.pointColl[I.index].strokeWidth}})}}A.freehandSelectedIndex=null,r.notify("freehand-draw",{prop:"getFreehandSelectedIndex",onPropertyChange:!1,value:{obj:A}});var R=t.extend([],r.objColl,[],!0);if(!t.isNullOrUndefined(I.index)&&I.index>-1)r.notify("freehand-draw",{prop:"selectFhd",value:{type:"ok"}}),r.notify("freehand-draw",{prop:"hoverFhd",onPropertyChange:!1,value:{strokeColor:null,strokeWidth:null}}),r.notify("toolbar",{prop:"renderQAT",onPropertyChange:!1,value:{isPenEdit:!0}});else if(A.freehandSelectedIndex){r.okBtn();var D=r.pointColl[A.freehandSelectedIndex].strokeColor;r.notify("freehand-draw",{prop:"hoverFhd",onPropertyChange:!1,value:{strokeColor:D,strokeWidth:r.pointColl[A.freehandSelectedIndex].strokeWidth}})}else this.findTargetObj(T,k,!1)&&(r.objColl=R,this.findTarget(T,k,i.type),r.notify("draw",{prop:"redrawDownScale"}))}else{if(this.isFhdEditing){r.apply();var X=document.getElementById(r.element.id+"_quickAccessToolbarArea");X&&(X.style.display="none");var L=r.pointColl[A.freehandSelectedIndex],Y={id:"pen_"+(A.freehandSelectedIndex+1),type:e.ShapeType.FreehandDraw,startX:L.points[0].x,startY:L.points[0].y,strokeColor:L.strokeColor,strokeWidth:L.strokeWidth,points:L.points,opacity:L.opacity,index:L.order},E={action:"apply",currentShapeSettings:t.extend({},Y,{},!0)};r.trigger("shapeChange",E),r.editCompleteArgs=E}var B=r.togglePen;if(r.notify("toolbar",{prop:"close-contextual-toolbar",onPropertyChange:!1}),B&&r.freeHandDraw(!0),this.isFhdEditing=!1,O?this.setCursor(T,k):"default"!==l&&(r.upperCanvas.style.cursor=r.cursor=l),"crosshair"===r.cursor||t.Browser.isDevice&&r.togglePen){if(r.togglePen){if(t.isNullOrUndefined(r.activeObj.strokeSettings)){var H={strokeSettings:{}};r.notify("shape",{prop:"getStrokeSettings",onPropertyChange:!1,value:{obj:H}}),r.activeObj.strokeSettings=H.strokeSettings}var M={penStrokeWidth:null};r.notify("freehand-draw",{prop:"getPenStrokeWidth",onPropertyChange:!1,value:{obj:M}}),t.isNullOrUndefined(M.penStrokeWidth)&&r.notify("freehand-draw",{prop:"setPenStrokeWidth",onPropertyChange:!1,value:{value:2}}),this.upperContext.strokeStyle=r.activeObj.strokeSettings.strokeColor,this.upperContext.fillStyle=r.activeObj.strokeSettings.strokeColor,r.notify("freehand-draw",{prop:"resetSelPoints",onPropertyChange:!1}),r.notify("freehand-draw",{prop:"freehandDownHandler",onPropertyChange:!1,value:{e:i,canvas:r.upperCanvas}})}else r.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),this.upperContext.clearRect(0,0,r.upperCanvas.width,r.upperCanvas.height);r.currObjType.isActiveObj=!1,this.dragElement="",this.dragPoint.startX=this.dragPoint.startY=this.dragPoint.endX=this.dragPoint.endY=0}(this.isTouch&&"crosshair"!==p||"crosshair"!==r.cursor)&&"touchstart"===i.type.toLowerCase()||r.currObjType.isActiveObj&&"default"!==r.cursor&&!r.togglePen?(r.notify("draw",{prop:"updateTempObjColl"}),r.notify("draw",{prop:"updateTempPointColl"}),this.findTarget(T,k,i.type),r.notify("draw",{prop:"redrawDownScale"})):""!==r.currObjType.shape&&!r.currObjType.isCustomCrop||r.togglePen||"default"===r.cursor||this.setActivePoint(T,k),x&&r.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.lowerContext}})}}else{if(this.applyObj(n,s)){if(r.okBtn(!0),j){var W=r.cursor;r.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"ok"}}),r.cursor=W}r.notify("draw",{prop:"setPrevActObj",onPropertyChange:!1,value:{prevActObj:null}})}this.isFhdEditing&&(r.notify("freehand-draw",{prop:"applyFhd",onPropertyChange:!1}),this.isFhdCustomized=!1,r.notify("toolbar",{prop:"destroy-qa-toolbar",onPropertyChange:!1}));var U=r.activeObj.shape,_=["rectangle","ellipse","line","arrow","path","text","image","redact"];U&&_.indexOf(U)>-1&&(r.notify("shape",{prop:"redrawActObj",onPropertyChange:!1,value:{x:null,y:null,isMouseDown:null}}),r.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),r.notify("toolbar",{prop:"setCurrentToolbar",value:{type:"main"}}),r.notify("toolbar",{prop:"refresh-main-toolbar",onPropertyChange:!1}));var N=!1;r.activeObj.shape&&r.activeObj.shape.indexOf("crop-")>-1&&(N=!0),r.element.querySelector(".e-contextual-toolbar-wrapper")&&!N&&(r.element.querySelector(".e-contextual-toolbar-wrapper").classList.contains("e-hide")||(r.okBtn(),r.element.querySelector(".e-contextual-toolbar-wrapper").classList.add("e-hide"))),this.canvasMouseDownHandler(i)}this.isShapeInserted=!1,this.tempActiveObj=t.extend({},r.activeObj,{},!0)},o.prototype.mouseMoveEventHandler=function(o){var i=this.parent,r=i.cursor,a=i.upperCanvas.style.cursor;if(o.preventDefault(),!(this.isPreventShaping||i.isShapeDrawing&&i.currObjType.isDragging&&this.isTouch&&i.activeObj.shape&&"path"===i.activeObj.shape)){if("grabbing"===i.cursor&&this.isGrabbing){var n={shapeSettingsObj:{}};i.notify("selection",{prop:"updatePrevShapeSettings",onPropertyChange:!1,value:{obj:n}});var s=n.shapeSettingsObj,l={cancel:!1,action:"rotating",previousShapeSettings:s,allowShapeOverflow:this.allowOutofBound()},p={cancel:!1,action:"rotating",previousShapeSettings:s,allowShapeOverflow:this.allowOutofBound()};this.triggerShapeChange(l,p,"mouse-down")}if(this.timer&&this.timer>0&&this.dragPoint.startX&&this.dragPoint.startY){var h=Math.abs(this.dragPoint.startX-o.touches[0].clientX),d=Math.abs(this.dragPoint.startY-o.touches[0].clientY);(h>10||d>10)&&(this.timer=0)}var c=i.lowerCanvas.getBoundingClientRect();if("touchmove"===o.type&&2===o.touches.length){if(this.isFirstMove)this.startTouches=this.targetTouches(o.touches),this.tempTouches=[],this.tempTouches.push({x:o.touches[0].clientX||o.touches[0].pageX-i.lowerCanvas.offsetLeft-c.left,y:(o.touches[0].clientY||o.touches[0].pageY-i.lowerCanvas.offsetTop)-c.top}),this.tempTouches.push({x:(o.touches[1].clientX||o.touches[1].pageX-i.lowerCanvas.offsetLeft)-c.left,y:(o.touches[1].clientY||o.touches[1].pageY-i.lowerCanvas.offsetTop)-c.top});else{var u=(o.touches[0].clientX||o.touches[0].pageX-i.lowerCanvas.offsetLeft)-c.left,v=(o.touches[0].clientY||o.touches[0].pageY-i.lowerCanvas.offsetTop)-c.top,g=(o.touches[1].clientX||o.touches[1].pageX-i.lowerCanvas.offsetLeft)-c.left,f=(o.touches[1].clientY||o.touches[1].pageY-i.lowerCanvas.offsetTop)-c.top,C={x:u<g?g-(g-u)/2:u-(u-g)/2,y:v<f?f-(f-v)/2:v-(v-f)/2};if(this.currMousePoint.x!==C.x&&this.currMousePoint.y!==C.y){var b="";if("touchmove"===o.type&&(i.zoomSettings.zoomTrigger&e.ZoomTrigger.Pinch)===e.ZoomTrigger.Pinch){this.zoomType="Pinch";var m=this.calculateScale(this.startTouches,this.targetTouches(o.touches));this.startTouches=this.targetTouches(o.touches),m>1?b="zoomIn":m<1&&(b="zoomOut")}""!==b&&i.notify("draw",{prop:"performPointZoom",onPropertyChange:!1,value:{x:C.x,y:C.y,type:b,isResize:null}}),this.tempTouches=[],this.tempTouches.push({x:o.touches[0].clientX||o.touches[0].pageX-i.lowerCanvas.offsetLeft,y:o.touches[0].clientY||o.touches[0].pageY-i.lowerCanvas.offsetTop}),this.tempTouches.push({x:o.touches[1].clientX||o.touches[1].pageX-i.lowerCanvas.offsetLeft,y:o.touches[1].clientY||o.touches[1].pageY-i.lowerCanvas.offsetTop}),this.currMousePoint.x=C.x,this.currMousePoint.y=C.y,this.isPinching=!0}}return void(this.isFirstMove=!1)}var y,P;"mousemove"===o.type?(y=o.clientX,P=o.clientY):(this.touchEndPoint.x=y=o.touches[0].clientX,this.touchEndPoint.y=P=o.touches[0].clientY),y-=c.left,P-=c.top,this.canvasMouseMoveHandler(o);var j,x=!1;void 0!==i.activeObj.shape&&(j=i.activeObj.shape.split("-")),void 0!==j&&"crop"===j[0]&&(x=!0),x&&i.notify("transform",{prop:"disableZoomOutBtn",value:{isZoomOut:!0}}),i.upperCanvas.style.cursor=a,i.cursor=r,(i.currObjType.isActiveObj&&(void 0!==i.activeObj.activePoint||i.objColl.length>0)&&!this.dragCanvas||void 0!==i.activeObj.activePoint)&&""===this.dragElement&&(this.setCursor(y,P),i.activeObj.activePoint&&(0===i.activeObj.activePoint.width||!t.isNullOrUndefined(i.activeObj.currIndex)&&this.cursorTargetId!==i.activeObj.currIndex)&&"default"!==i.cursor&&"move"!==i.cursor&&"crosshair"!==i.cursor&&"grab"!==i.cursor&&"pointer"!==i.cursor&&(i.upperCanvas.style.cursor=i.cursor="move"),this.findTarget(y,P,o.type));var w=i.img,O=w.destLeft,S=w.destTop,T=w.destWidth,k=w.destHeight;if(i.currObjType.isDragging){if(i.activeObj.shape&&i.activeObj.preventShapeDragOut&&(y<O||y>O+T||P<S||P>S+k))return;this.upperContext.clearRect(0,0,i.lowerCanvas.width,i.lowerCanvas.height),this.updateActivePoint(y,P,x),i.notify("shape",{prop:"updateTrianglePoints",onPropertyChange:!1,value:{obj:i.activeObj}}),this.isPreventDragging?(this.isShapeDragOut()||(this.isPreventDragging=!1),i.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate",obj:null,isCropRatio:null,points:null,isPreventDrag:!0,saveContext:null,isPreventSelection:null}})):i.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate",obj:null,isCropRatio:null,points:null,isPreventDrag:null,saveContext:null,isPreventSelection:null}}),x&&(this.dragCanvas=i.togglePan=!0)}}},o.prototype.mouseUpEventHandler=function(e){var o=this.parent,i=o.element.id;if(o.isKBDNavigation=!1,t.Browser.isDevice||!(o.element.querySelector("#"+i+"_contextualToolbar")&&!o.element.querySelector("#"+i+"_contextualToolbar").parentElement.classList.contains("e-hide")||o.element.querySelector("#"+i+"_headWrapper")&&!o.element.querySelector("#"+i+"_headWrapper").parentElement.classList.contains("e-hide"))||o.activeObj.shape&&"redact"===o.activeObj.shape&&o.isShapeDrawing){if("grabbing"===o.cursor&&this.isGrabbing){I={shapeSettingsObj:{}};o.notify("selection",{prop:"updatePrevShapeSettings",onPropertyChange:!1,value:{obj:I}});var r=I.shapeSettingsObj,a={cancel:!1,action:"rotate-end",previousShapeSettings:r,allowShapeOverflow:this.allowOutofBound()},n={cancel:!1,action:"rotate-end",previousShapeSettings:r,allowShapeOverflow:this.allowOutofBound()};this.triggerShapeChange(a,n,"mouse-up")}if(this.isGrabbing=!1,this.isPreventShaping&&(this.isPreventShaping=!1),"canvas"===this.mouseDown||this.isSliderActive||e.target.closest(".e-image-editor")||e.target.closest(".e-ie-ddb-popup")){"touchstart"===e.type?this.isTouch=!1:"touchend"===e.type&&e.stopImmediatePropagation(),e.preventDefault(),o.togglePan&&this.canvasMouseUpHandler(e);var s=void 0,l=void 0;"mouseup"===e.type?(s=e.clientX,l=e.clientY):this.isTouchDblClick||(s=this.touchEndPoint.x,l=this.touchEndPoint.y);var p=o.lowerCanvas.getBoundingClientRect();s-=p.left,l-=p.top;var h=void 0,d=this.currentDrawingShape,c=!1;if("touchend"===e.type&&(this.startTouches=this.tempTouches=[],this.isFirstMove=!1,"none"===o.textArea.style.display&&(this.timer=0),this.isPinching))return this.isPinching=!1,o.notify("draw",{prop:"redrawDownScale"}),(o.isCropTab||o.activeObj.shape)&&(o.notify("draw",{prop:"setStraightenActObj",value:{activeObj:null}}),o.notify("freehand-draw",{prop:"resetStraightenPoint"})),void(o.isStraightening&&(o.notify("draw",{prop:"resetStraightenDestPoints"}),o.notify("draw",{prop:"setDestForStraighten"})));var u=!1,v=void 0;if(void 0!==o.activeObj.shape&&(v=o.activeObj.shape.split("-")),void 0!==v&&"crop"===v[0]&&(u=!0),"path"===this.currentDrawingShape&&o.isShapeDrawing){var g=e.srcElement,f=g.parentElement.id,C=o.element.id;return e.currentTarget!==o.upperCanvas&&e.currentTarget!==o.lowerCanvas&&o.activeObj.pointColl.length>0&&(g.classList.contains("e-upload-icon")||f===C+"_zoomIn"||f===C+"_zoomOut"||f===C+"_annotationBtn"||f===C+"_borderColorBtn"||f===C+"_borderWidthBtn")&&(o.notify("shape",{prop:"stopPathDrawing",onPropertyChange:!1,value:{e:e,isApply:!0}}),this.upperContext.clearRect(0,0,o.upperCanvas.width,o.upperCanvas.height),o.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate",obj:o.activeObj,isCropRatio:null,points:null,isPreventDrag:!0,saveContext:null,isPreventSelection:!0}})),void(o.currObjType.isDragging&&this.isTouch&&o.activeObj.shape&&"path"===o.activeObj.shape&&(this.upperContext.clearRect(0,0,o.upperCanvas.width,o.upperCanvas.height),o.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate",obj:o.activeObj,isCropRatio:null,points:null,isPreventDrag:!0,saveContext:null,isPreventSelection:!0}})))}if(e.currentTarget===o.upperCanvas&&!o.isResize){if(this.pathAdjustedIndex=null,""!==this.currentDrawingShape){if("text"===this.currentDrawingShape){var b=t.extend({},o.cropObj,{},!0);o.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"shapeInsert",previousObj:this.initialPrevObj,previousObjColl:this.initialPrevObj.objColl,previousPointColl:this.initialPrevObj.pointColl,previousSelPointColl:this.initialPrevObj.selPointColl,previousCropObj:b,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}})}else o.notify("undo-redo",{prop:"updateUrObj",onPropertyChange:!1,value:{objColl:this.initialPrevObj.objColl,operation:"shapeInsert"}});this.isShapeInserted=!0,this.currentDrawingShape="",(o.activeObj.shape&&"path"===o.activeObj.shape&&0===o.activeObj.pointColl.length||(!o.activeObj.shape||"path"!==o.activeObj.shape)&&0===o.activeObj.activePoint.width&&0===o.activeObj.activePoint.height)&&(c=!0,o.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),this.upperContext.clearRect(0,0,o.upperCanvas.width,o.upperCanvas.height));var m=this.updatePrevShapeSettings(),a={cancel:!1,action:"draw-end",previousShapeSettings:m},n={cancel:!1,action:"move",previousShapeSettings:m};this.shapeResizingArgs=a,this.shapeMovingArgs=n,this.triggerShapeChange(a,n,"mouse-up")}o.activeObj.shape&&"path"===o.activeObj.shape&&o.activeObj.pointColl.length>0&&(o.activeObj.activePoint=o.getSquarePointForPath(o.activeObj)),this.adjustActObjForLineArrow(),this.updPtCollForShpRot(),o.currObjType.shape=o.currObjType.shape.toLowerCase();var y=t.extend({},o.cropObj,{},!0),P={currObj:{}};o.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:P}});var j=P.currObj;j.objColl=t.extend([],o.objColl,[],!0),j.pointColl=t.extend([],o.pointColl,[],!0),j.afterCropActions=t.extend([],o.afterCropActions,[],!0);var x={selPointColl:null};if(o.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:x}}),j.selPointColl=t.extend([],x.selPointColl,[],!0),!o.togglePen&&!u){if(this.tempObjColl&&0!==o.activeObj.activePoint.width){o.notify("shape",{prop:"updImgRatioForActObj",onPropertyChange:!1}),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:j,previousObjColl:this.tempObjColl,previousPointColl:j.pointColl,previousSelPointColl:j.selPointColl,previousCropObj:y,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}});var w=t.extend({},o.objColl[o.objColl.length-1],{},!0);o.objColl.pop(),this.redrawShape(w),this.tempObjColl=void 0}this.isFhdEditing||(this.applyCurrActObj(s,l),o.currObjType.isResize=!1,o.notify("toolbar",{prop:"destroy-qa-toolbar",onPropertyChange:!1}))}if(o.activeObj){var O,S=!1;void 0!==o.activeObj.shape&&(O=o.activeObj.shape.split("-")),void 0===O&&(o.currObjType.isCustomCrop||o.togglePen)?S=!0:void 0!==O&&"crop"===O[0]&&(S=!0);var T=o.activeObj.shape;if(h=T,["rectangle","ellipse","line","arrow","path"].indexOf(T)>-1)o.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"shapes",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}});else if("text"===T)"none"===o.textArea.style.display&&o.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"text",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}});else if("redact"===T)o.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"redact",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(!S){var k={type:"main",isApplyBtn:null,isCropping:!1,isZooming:null};o.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:k})}if(o.notify("toolbar",{prop:"update-toolbar-items",onPropertyChange:!1}),!this.isFhdEditing&&(o.activeObj.shape&&"text"===o.activeObj.shape&&11===o.activeObj.textSettings.fontSize&&55===Math.floor(o.activeObj.activePoint.width)&&11===Math.floor(o.activeObj.activePoint.height)&&(o.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),"text"!==o.drawingShape||o.activeObj.keyHistory||(o.activeObj.keyHistory="Enter Text")),!S))if(this.adjustActObjForLineArrow(),o.isShapeDrawing){F=this.currentDrawingShape;o.notify("undo-redo",{prop:"updateUndoRedoStack",onPropertyChange:!1}),this.currentDrawingShape=F}else o.notify("undo-redo",{prop:"updateUndoRedoStack",onPropertyChange:!1})}}if(void 0!==o.activeObj.shape&&(v=o.activeObj.shape.split("-")),void 0!==v&&"crop"===v[0]&&(u=!0),o.activeObj.shape&&!u&&e.currentTarget===o.upperCanvas&&"none"===o.textArea.style.display){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("redact"===o.activeObj.shape)o.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"redact",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}});else{var F=this.currentDrawingShape;this.currentDrawingShape="",o.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"shapes",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}}),this.currentDrawingShape=F}o.notify("toolbar",{prop:"update-toolbar-items",onPropertyChange:!1}),o.notify("toolbar",{prop:"renderQAT",onPropertyChange:!1,value:{isPenEdit:null}})}var I={freehandDrawSelectedId:null};o.notify("freehand-draw",{prop:"getFreehandDrawSelectedId",onPropertyChange:!1,value:{obj:I}}),o.togglePen&&e.currentTarget===o.upperCanvas&&!I.freehandDrawSelectedId?(o.notify("freehand-draw",{prop:"freehandUpHandler",onPropertyChange:!1,value:{e:e,canvas:o.upperCanvas,context:this.upperContext}}),o.togglePen&&!o.isMaskImage&&(t.isNullOrUndefined(o.toolbar)||o.toolbar&&o.toolbar.length>0||!t.isNullOrUndefined(o.toolbarTemplate))&&(o.okBtn(),o.freeHandDraw(!0))):o.currObjType.shape="",this.dragElement="",this.mouseDown="",this.isSliderActive=!1,o.currObjType.isInitialLine=o.currObjType.isDragging=!1,this.selMouseUpEvent(),t.isNullOrUndefined(o.drawingShape)&&h&&""!==d&&(o.drawingShape=h),o.drawingShape&&(this.currentDrawingShape=o.drawingShape.toLowerCase(),c&&(o.enableShapeDrawing(o.toPascalCase(o.drawingShape),!0),o.upperCanvas.style.cursor="crosshair")),o.isShapeDrawing=!1,o.notify("freehand-draw",{prop:"resetSelPoints",onPropertyChange:!1})}}},o.prototype.adjustActObjForLineArrow=function(e){var t=!1,o=this.parent;if((e=e||o.activeObj).shape&&("line"===e.shape||"arrow"===o.activeObj.shape)){var i=void 0;if(("e-resize"===this.dragElement&&e.activePoint.endX<e.activePoint.startX||"w-resize"===this.dragElement&&e.activePoint.startX>e.activePoint.endX)&&(t=!0,i=e.activePoint.startX,e.activePoint.startX=e.activePoint.endX,e.activePoint.endX=i,i=e.activePoint.startY,e.activePoint.startY=e.activePoint.endY,e.activePoint.endY=i),e.activePoint.width=Math.abs(e.activePoint.endX-e.activePoint.startX),e.activePoint.height=Math.abs(e.activePoint.endY-e.activePoint.startY),"path"!==o.activeObj.shape){o.notify("shape",{prop:"setPointCollForLineArrow",onPropertyChange:!1,value:{obj:e}});for(var r=0;r<e.pointColl.length;r++)e.pointColl[r].ratioX=(e.pointColl[r].x-o.img.destLeft)/o.img.destWidth,e.pointColl[r].ratioY=(e.pointColl[r].y-o.img.destTop)/o.img.destHeight}}return t},o.prototype.updPtCollForShpRot=function(e){var t=this.parent;if((e=e||t.activeObj).shape&&0!==e.rotatedAngle){t.notify("shape",{prop:"setPointCollForShapeRotation",onPropertyChange:!1,value:{obj:e}});var o=t.img,i=o.destLeft,r=o.destTop,a=o.destWidth,n=o.destHeight,s=e.horTopLinePointColl,l=e.horBottomLinePointColl,p=e.verLeftLinePointColl,h=e.verRightLinePointColl,d=function(e){e.ratioX=(e.x-i)/a,e.ratioY=(e.y-r)/n};s.forEach(d),l.forEach(d),p.forEach(d),h.forEach(d)}},o.prototype.setXYPoints=function(e){e.preventDefault();var t,o;"mousedown"===e.type?(t=e.clientX,o=e.clientY):(this.touchEndPoint.x=t=e.touches[0].clientX,this.touchEndPoint.y=o=e.touches[0].clientY);var i=this.parent.lowerCanvas.getBoundingClientRect();return t-=i.left,o-=i.top,{x:t,y:o}},o.prototype.getCurrentIndex=function(){for(var e,t=this.parent,o=0,i=t.objColl.length;o<i;o++)if(t.activeObj.currIndex===t.objColl[o].currIndex){e=o;break}return e},o.prototype.isShapeClick=function(e,o){var i=this.parent,r=!1;if(i.togglePen)return r;if(i.activeObj.shape&&"text"===i.activeObj.shape&&this.isShapeInserted){var a="block"===i.textArea.style.display||"inline-block"===i.textArea.style.display,n=t.extend({},i.activeObj,null,!0);i.notify("shape",{prop:"redrawActObj",onPropertyChange:!1,value:{x:null,y:null,isMouseDown:!0}});var s=this.setXYPoints(e),l=s.x,p=s.y;if(r=this.findTargetObj(l,p,o),o||(this.upperContext.clearRect(0,0,i.upperCanvas.width,i.upperCanvas.height),r&&i.notify("shape",{prop:"redrawActObj",onPropertyChange:!1,value:{x:null,y:null,isMouseDown:!0}})),a){i.textArea.value=i.objColl[i.objColl.length-1].keyHistory,i.textArea.style.display="block",i.activeObj=n;h=this.getCurrentIndex();t.isNullOrUndefined(h)?i.objColl.pop():i.objColl.splice(h,1)}else if(!r&&n.shape){i.activeObj=n;var h=this.getCurrentIndex();t.isNullOrUndefined(h)||JSON.stringify(i.activeObj.activePoint)!==JSON.stringify(i.objColl[h].activePoint)?t.isNullOrUndefined(i.activeObj.currIndex)&&i.objColl.pop():i.objColl.splice(h,1)}}return r},o.prototype.isShapeTouch=function(e,o){var i=this.parent,r=!1;if("touchstart"===e.type&&!i.togglePen){i.activeObj&&"text"===i.activeObj.shape&&(this.timer=setTimeout(this.setTimer.bind(this),1e3,e));var a="block"===i.textArea.style.display||"inline-block"===i.textArea.style.display,n=t.extend({},i.activeObj,null,!0);i.notify("shape",{prop:"redrawActObj",onPropertyChange:!1,value:{x:null,y:null,isMouseDown:!0}});var s=this.setXYPoints(e),l=s.x,p=s.y;if(r=this.findTargetObj(l,p,o),o||this.upperContext.clearRect(0,0,i.upperCanvas.width,i.upperCanvas.height),a){i.textArea.value=i.objColl[i.objColl.length-1].keyHistory,i.textArea.style.display="block",i.activeObj=n;h=this.getCurrentIndex();t.isNullOrUndefined(h)?i.objColl.pop():i.objColl.splice(h,1)}else if(!r&&n.shape&&(0!==n.activePoint.width||0!==n.activePoint.height||"path"===n.shape&&n.pointColl.length>0)){i.activeObj=n;var h=this.getCurrentIndex();o||(t.isNullOrUndefined(h)||JSON.stringify(i.activeObj.activePoint)!==JSON.stringify(i.objColl[h].activePoint)?t.isNullOrUndefined(i.activeObj.currIndex)&&i.objColl.pop():i.objColl.splice(h,1))}}return r},o.prototype.isFreehandDrawTouch=function(e,o){var i=this.parent,r=!1;if("touchstart"===e.type&&!o&&!i.togglePen){var a="block"===i.textArea.style.display||"inline-block"===i.textArea.style.display,n=t.extend({},i.activeObj,null,!0);i.notify("shape",{prop:"redrawActObj",onPropertyChange:!1,value:{x:null,y:null,isMouseDown:!0}});var s=this.setXYPoints(e),l=s.x,p=s.y;if(this.setCursor(l,p),this.isFhdPoint&&(r=!0),a){i.textArea.value=i.objColl[i.objColl.length-1].keyHistory,i.textArea.style.display="block",i.activeObj=n;h=this.getCurrentIndex();t.isNullOrUndefined(h)?i.objColl.pop():i.objColl.splice(h,1)}else if(n.shape){i.activeObj=n;var h=this.getCurrentIndex();o||(t.isNullOrUndefined(h)||JSON.stringify(i.activeObj.activePoint)!==JSON.stringify(i.objColl[h].activePoint)?t.isNullOrUndefined(i.activeObj.currIndex)&&i.objColl.pop():i.objColl.splice(h,1))}}return r},o.prototype.applyObj=function(e,t){var o=this.parent,i=!1;if(0===o.activeObj.activePoint.width&&0===o.activeObj.activePoint.height)return!1;var r=["rectangle","ellipse","line","arrow","path","image","text"],a=o.activeObj.activePoint,n=a.startX,s=a.startY,l=a.endX,p=a.endY;if(o.activeObj.shape&&r.indexOf(o.activeObj.shape)>-1){var h=o.activeObj.topLeftCircle.radius;i=!(e>=n-2*h&&e<=l+2*h&&t>=s-2*h&&t<=p+2*h)&&("default"===o.upperCanvas.style.cursor||"grab"===o.upperCanvas.style.cursor||"crosshair"===o.upperCanvas.style.cursor||"pointer"===o.upperCanvas.style.cursor||"move"===o.upperCanvas.style.cursor)}return i},o.prototype.applyCurrShape=function(e){var o=this.parent,i=!1;if(o.togglePen)return i;var r=t.extend({},o.activeObj,null,!0);if(this.isShapeInserted&&"text"===o.activeObj.shape&&e&&(this.isInitialTextEdited=!0,o.notify("draw",{prop:"setShapeTextInsert",onPropertyChange:!1,value:{bool:!0}})),"block"===o.textArea.style.display||"inline-block"===o.textArea.style.display){var a=t.extend({},o.activeObj,null,!0);o.notify("shape",{prop:"redrawActObj",onPropertyChange:!1,value:{x:null,y:null,isMouseDown:null}}),r=t.extend({},o.objColl[o.objColl.length-1],null,!0),o.objColl.pop(),o.activeObj=t.extend({},a,null,!0),o.textArea.value=r.keyHistory,o.textArea.style.display="block";var n=r.strokeSettings&&r.strokeSettings.strokeColor?"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]),parseFloat(r.strokeSettings.strokeColor.split("(")[1].split(",")[3])):r.strokeSettings.strokeColor:null;n&&"#ffffff"===n&&(n="#fff"),this.tempActiveObj.strokeSettings&&this.tempActiveObj.strokeSettings.strokeColor&&"#ffffff"===this.tempActiveObj.strokeSettings.strokeColor&&(this.tempActiveObj.strokeSettings.strokeColor="#fff"),(r.keyHistory!==this.tempActiveObj.keyHistory||n&&n!==this.tempActiveObj.strokeSettings.strokeColor||r.textSettings&&r.textSettings.fontFamily!==this.tempActiveObj.textSettings.fontFamily||r.textSettings&&Math.round(r.textSettings.fontSize)!==Math.round(this.tempActiveObj.textSettings.fontSize)||r.textSettings&&Math.round(r.textSettings.fontRatio)!==Math.round(this.tempActiveObj.textSettings.fontRatio)||r.textSettings&&r.textSettings.bold!==this.tempActiveObj.textSettings.bold||r.textSettings&&r.textSettings.italic!==this.tempActiveObj.textSettings.italic||r.textSettings&&r.textSettings.underline!==this.tempActiveObj.textSettings.underline)&&(i=!0),this.isInitialTextEdited&&!i&&(i=!0,this.isInitialTextEdited=!1)}else this.tempActiveObj.activePoint.height=Math.abs(this.tempActiveObj.activePoint.height),i=JSON.stringify(r)!==JSON.stringify(this.tempActiveObj);return i},o.prototype.canvasMouseDownHandler=function(e){var o=this.parent;e.preventDefault();var i,r;"mousedown"===e.type?(i=e.offsetX||e.pageX-o.lowerCanvas.offsetLeft,r=e.offsetY||e.pageY-o.lowerCanvas.offsetTop):(i=e.touches[0].clientX||e.touches[0].pageX-o.lowerCanvas.offsetLeft,r=e.touches[0].clientY||e.touches[0].pageY-o.lowerCanvas.offsetTop);var a=o.lowerCanvas.getBoundingClientRect();i-=a.left,r-=a.top,this.panDown={x:i,y:r};var n={tempPanMove:null};o.notify("transform",{prop:"getTempPanMove",onPropertyChange:!1,value:{obj:n}}),t.isNullOrUndefined(n.tempPanMove)&&o.notify("transform",{prop:"setTempPanMove",onPropertyChange:!1,value:{point:{x:i,y:r}}})},o.prototype.canvasMouseMoveHandler=function(e){var t=this.parent,o={bool:null};if(t.notify("toolbar",{prop:"getFrameToolbar",onPropertyChange:!1,value:{obj:o}}),t.isResize||o.bool)return void(t.upperCanvas.style.cursor="default");this.dragCanvas?t.lowerCanvas.style.cursor="grab":(this.dragCanvas=t.togglePan=!1,t.lowerCanvas.style.cursor=t.upperCanvas.style.cursor=t.cursor="default");var i,r;"mousemove"===e.type?(i=e.offsetX,r=e.offsetY):(i=e.touches[0].clientX||e.touches[0].pageX-t.lowerCanvas.offsetLeft,r=e.touches[0].clientY||e.touches[0].pageY-t.lowerCanvas.offsetTop);var a=t.lowerCanvas.getBoundingClientRect(),n={x:i-=a.left,y:r-=a.top};t.notify("transform",{prop:"setPanMove",onPropertyChange:!1,value:{point:{x:i,y:r}}}),this.panDown&&n&&t.togglePan&&this.dragCanvas&&((t.isCropTab||t.activeObj.shape)&&(t.notify("draw",{prop:"setStraightenActObj",value:{activeObj:null}}),t.notify("freehand-draw",{prop:"resetStraightenPoint"})),t.notify("transform",{prop:"drawPannedImage",onPropertyChange:!1,value:{xDiff:null,yDiff:null}}))},o.prototype.canvasMouseUpHandler=function(e){var t=this.parent;e.preventDefault();var o={panMove:null};t.notify("transform",{prop:"getPanMove",onPropertyChange:!1,value:{obj:o}}),t.togglePan&&this.panDown&&o.panMove&&t.togglePan&&this.dragCanvas&&(this.panDown=null,t.notify("transform",{prop:"setPanMove",onPropertyChange:!1,value:{point:null}})),t.notify("transform",{prop:"setTempPanMove",onPropertyChange:!1,value:{point:null}}),"path"!==this.currentDrawingShape&&(t.currObjType.isDragging=!1)},o.prototype.touchStartHandler=function(e){e.preventDefault();var o=this.parent;if(0===this.touchTime)this.touchTime=(new Date).getTime();else if((new Date).getTime()-this.touchTime<400){this.isTouchDblClick=!0;var i=o.isShapeDrawing;if(o.notify("shape",{prop:"stopPathDrawing",onPropertyChange:!1,value:{e:e,isApply:null}}),this.isTouchDblClick=!1,this.touchTime=0,i!==o.isShapeDrawing&&o.activeObj.shape&&"path"===o.activeObj.shape)return}else this.touchTime=(new Date).getTime();2===e.touches.length?this.isFirstMove=!0:this.mouseDownEventHandler(e),t.EventHandler.add(o.lowerCanvas,"touchend",this.mouseUpEventHandler,this),t.EventHandler.add(o.lowerCanvas,"touchmove",this.mouseMoveEventHandler,this),t.EventHandler.add(o.upperCanvas,"touchend",this.mouseUpEventHandler,this),t.EventHandler.add(o.upperCanvas,"touchmove",this.mouseMoveEventHandler,this)},o.prototype.unwireEvent=function(){var e=this.parent;t.EventHandler.remove(e.lowerCanvas,"touchend",this.mouseUpEventHandler),t.EventHandler.remove(e.lowerCanvas,"touchmove",this.mouseMoveEventHandler),t.EventHandler.remove(e.upperCanvas,"touchend",this.mouseUpEventHandler),t.EventHandler.remove(e.upperCanvas,"touchmove",this.mouseMoveEventHandler)},o.prototype.keyDownEventHandler=function(o){var i=this.parent;!o.ctrlKey||"+"!==o.key&&"-"!==o.key||o.preventDefault();var r={fileName:"",fileType:null};i.notify("draw",{prop:"getFileName",onPropertyChange:!1,value:{obj:r}});var a={fileName:r.fileName,fileType:r.fileType,cancel:!1};switch(o.key){case o.ctrlKey&&"s":i.trigger("beforeSave",a),this.beforeSaveEvent(a,o);break;case o.ctrlKey&&"z":i.allowUndoRedo&&(i.noPushUndo=!1,(i.togglePen||i.drawingShape)&&(i.okBtn(),i.drawingShape=null),i.notify("undo-redo",{prop:"call-undo"}));break;case o.ctrlKey&&"y":i.allowUndoRedo&&(i.noPushUndo=!1,(i.togglePen||i.drawingShape)&&(i.okBtn(),i.drawingShape=null),i.notify("undo-redo",{prop:"call-redo"}));break;case o.ctrlKey&&"+":(i.zoomSettings.zoomTrigger&e.ZoomTrigger.Commands)===e.ZoomTrigger.Commands&&(this.zoomType="Commands",i.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:.1,zoomPoint:null},isResize:null}),i.notify("draw",{prop:"redrawDownScale"}),(i.isCropTab||i.activeObj.shape)&&(i.notify("draw",{prop:"setStraightenActObj",value:{activeObj:null}}),i.notify("freehand-draw",{prop:"resetStraightenPoint"})),i.isStraightening&&(i.notify("draw",{prop:"resetStraightenDestPoints"}),i.notify("draw",{prop:"setDestForStraighten"})));break;case o.ctrlKey&&"-":(i.zoomSettings.zoomTrigger&e.ZoomTrigger.Commands)===e.ZoomTrigger.Commands&&(this.zoomType="Commands",i.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:-.1,zoomPoint:null},isResize:null}),i.notify("draw",{prop:"redrawDownScale"}),(i.isCropTab||i.activeObj.shape)&&(i.notify("draw",{prop:"setStraightenActObj",value:{activeObj:null}}),i.notify("freehand-draw",{prop:"resetStraightenPoint"})),i.isStraightening&&(i.notify("draw",{prop:"resetStraightenDestPoints"}),i.notify("draw",{prop:"setDestForStraighten"})));break;case"Delete":this.deleteItem();break;case"Escape":i.notify("draw",{prop:"performCancel",value:{isContextualToolbar:null,isFinalCancel:!0}});break;case"Enter":this.performEnterAction(o);break;case"Tab":this.performTabAction();break;default:!t.Browser.isDevice||"block"!==i.textArea.style.display&&"inline-block"!==i.textArea.style.display||setTimeout(this.textKeyDown.bind(this),1,o)}},o.prototype.performEnterAction=function(e){var o=this.parent;if(o.isResize){var i=e.target,r=!!(i.id.indexOf("aspectratio")||i.id.indexOf("non-aspectratio")>-1);if(!this.isValueUpdated())return void(r&&this.focusRatioBtn());var a=this.getNumTextValue(),n=o.element.querySelector("#"+o.element.id+"_aspectratio"),s=o.element.querySelector(".e-ie-toolbar-aspect-ratio-btn");a&&a.x&&a.y&&(n||s&&!s.classList.contains("e-hidden")?o.notify("transform",{prop:"resize",value:{width:a.x,height:null,isAspectRatio:!0}}):o.notify("transform",{prop:"resize",value:{width:a.x,height:a.y,isAspectRatio:!1}}));var l=o.element.querySelector("#"+o.element.id+"_resizeHeight"),p=o.element.querySelector("#"+o.element.id+"_resizeWidth");if(t.isNullOrUndefined(n)){if(l){h=t.getComponent(l,"numerictextbox");l&&""===l.value&&(h.value=parseFloat(h.placeholder),l.value=h.placeholder+"px")}if(p){var h=t.getComponent(p,"numerictextbox");p&&""===p.value&&(h.value=parseFloat(h.placeholder),p.value=h.placeholder+"px")}}o.notify("draw",{prop:"redrawDownScale"}),r&&this.focusRatioBtn()}else if(e.target.classList.contains("e-upload")){var d=o.element.querySelector(".e-image-upload");d&&d.querySelector(".e-tbar-btn")&&d.querySelector(".e-tbar-btn").click()}else if(e.target.classList.contains("filter-wrapper"))e.target.parentElement.click();else{var c=void 0;o.activeObj.shape&&(c=o.activeObj.shape.split("-")),e&&this.isKeyBoardCrop(e)&&o.activeObj.horTopLine&&o.activeObj.shape&&"crop"===c[0]&&o.crop()}},o.prototype.focusRatioBtn=function(){var e=this.parent.element.id;this.parent.isKBDNavigation&&setTimeout(function(){document.getElementById(e+"_aspectratio")?document.getElementById(e+"_aspectratio").focus():document.getElementById(e+"_nonaspectratio")&&document.getElementById(e+"_nonaspectratio").focus()},50)},o.prototype.isKeyBoardCrop=function(e){var t=!1,o=e.target;return o.id!==this.parent.element.id+"_ok"&&""!==o.id||(t=!0),t},o.prototype.beforeSaveEvent=function(e,t){var o=this.parent;e.cancel||o.notify("export",{prop:"export",onPropertyChange:!1,value:{type:e.fileType,fileName:e.fileName}}),t.preventDefault(),t.stopImmediatePropagation()},o.prototype.handleScroll=function(t){var o,i,r=this.parent,a=!1;"mousewheel"===t.type&&(o=t.clientX,i=t.clientY);var n=r.lowerCanvas.getBoundingClientRect();if(o-=n.left,i-=n.top,o>r.img.destLeft&&o<r.img.destLeft+r.img.destWidth&&i>r.img.destTop&&i<r.img.destTop+r.img.destHeight&&(a=!0),t.stopPropagation(),!0===t.ctrlKey&&a){t.preventDefault(),!r.isCropTab&&r.activeObj.shape&&"crop"!==r.activeObj.shape.split("-")[0]&&(r.okBtn(null,!0),r.notify("toolbar",{prop:"close-contextual-toolbar",onPropertyChange:!1}));var s="";"mousewheel"===t.type&&(r.zoomSettings.zoomTrigger&e.ZoomTrigger.MouseWheel)===e.ZoomTrigger.MouseWheel&&(this.zoomType="MouseWheel",s=t.wheelDelta>0?"zoomIn":"zoomOut"),""!==s&&(r.notify("draw",{prop:"performPointZoom",onPropertyChange:!1,value:{x:o,y:i,type:s,isResize:null}}),r.notify("draw",{prop:"redrawDownScale"}),(r.isCropTab||r.activeObj.shape)&&(r.notify("draw",{prop:"setStraightenActObj",value:{activeObj:null}}),r.notify("freehand-draw",{prop:"resetStraightenPoint"})),r.isStraightening&&(r.notify("draw",{prop:"resetStraightenDestPoints"}),r.notify("draw",{prop:"setDestForStraighten"})))}},o.prototype.textKeyDown=function(e){var o=this.parent;if(0===o.activeObj.rotatedAngle){"\r"===String.fromCharCode(e.which)&&(this.textRow+=1),o.textArea.setAttribute("rows",this.textRow.toString()),o.textArea.style.height="auto",o.textArea.style.height=o.textArea.scrollHeight+"px",o.notify("shape",{prop:"setTextBoxWidth",onPropertyChange:!1,value:{e:e}}),t.Browser.isDevice&&(o.textArea.style.width=parseFloat(o.textArea.style.width)+o.textArea.style.fontSize+"px");var i=o.textArea.value.split("\n");this.textRow=i.length,o.textArea.setAttribute("rows",this.textRow.toString()),this.isInitialTextEdited=!1}},o.prototype.clearSelection=function(e){var t=this.parent;!t.disabled&&t.isImageLoaded&&(e?t.notify("draw",{prop:"performCancel",value:{isContextualToolbar:null}}):(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(e,t){var o=this.parent,i=o.activeObj.activePoint;o.img.destWidth>o.img.destHeight?(i.startX=this.dragPoint.startX=e/2-t/2+7.5,i.startY=this.dragPoint.startY=t/2-t/2+7.5,i.endX=e/2+t/2-7.5,i.endY=t/2+t/2-7.5):(i.startY=this.dragPoint.startX=t/2-e/2+7.5,i.endY=t/2+e/2-7.5,i.startX=this.dragPoint.startX=7.5,i.endX=e-7.5)},o.prototype.calcShapeRatio=function(e,t,o,i){for(var r=this.parent,a=r.activeObj.activePoint,n=e/t,s=o,l=i,p=s>=l?s:l,h=p*n,d=p,c=this.getScale(h,s),u=[],v=r.img,g=v.destLeft,f=v.destTop,C=v.destWidth,b=v.destHeight,m=0;m<2;m++)0===m?u.push(h*c):u.push(d*c);h=u[0],d=u[1];for(var y=this.getScale(d,l),P=[],m=0;m<2;m++)0===m?P.push(h*y):P.push(d*y);h=P[0],d=P[1],a.width=h,a.height=d,a.startX=7.5+(this.dragPoint.startX=(s-h)/2),a.startY=7.5+(this.dragPoint.startY=(l-d)/2),a.endX=a.startX+a.width,a.endY=a.startY+a.height,a.startX<g&&g+C>r.lowerCanvas.clientWidth&&(a.startX=g,a.endX=a.startX+h-7.5),a.startY<f&&f+b>r.lowerCanvas.clientHeight&&(a.startY=f,a.endY=a.startY+d-7.5),a.width=a.endX-a.startX,a.height=a.endY-a.startY},o.prototype.getScale=function(e,t){return e>t?t/e:1},o.prototype.findTarget=function(e,t,o){var i=this.parent;if("mousedown"===o.toLowerCase()||"touchstart"===o.toLowerCase()){var r=!1;i.activeObj.shape&&"crop"===i.activeObj.shape.split("-")[0]&&(r=!0),this.findTargetObj(e,t,r),this.updateCursorStyles(e,t,o)}else{var a=i.activeObj,n=a.topLeftCircle,s=a.topCenterCircle,l=a.topRightCircle,p=a.centerLeftCircle,h=a.centerRightCircle,d=a.bottomLeftCircle,c=a.bottomCenterCircle,u=a.bottomRightCircle;switch(this.dragElement.toLowerCase()){case"nw-resize":n.startX=e,n.startY=t;break;case"n-resize":s.startX=e,s.startY=t;break;case"ne-resize":l.startX=e,l.startY=t;break;case"w-resize":p.startX=e,p.startY=t;break;case"e-resize":h.startX=e,h.startY=t;break;case"sw-resize":d.startX=e,d.startY=t;break;case"s-resize":c.startX=e,c.startY=t;break;case"se-resize":u.startX=e,u.startY=t;break;default:this.dragPoint.startX&&this.dragPoint.startY&&(this.previousPoint.x=this.dragPoint.endX,this.previousPoint.y=this.dragPoint.endY,this.dragPoint.endX=e,this.dragPoint.endY=t)}}},o.prototype.findTargetObj=function(e,o,i){var r=this.parent,a=!1;if(0!==r.objColl.length&&!r.currObjType.isCustomCrop&&!i){for(var n=0,s=void 0,l=0;l<r.objColl.length;l++){var p=r.upperCanvas.style.cursor;this.setCursor(e,o);var h=t.extend({},r.objColl[l],{},!0),d=h.topLeftCircle.radius;if("line"===h.shape||"arrow"===h.shape){for(var c=0;c<h.pointColl.length;c++)if(e>=h.pointColl[c].x-2*d&&e<=h.pointColl[c].x+2*d&&o>=h.pointColl[c].y-2*d&&o<=h.pointColl[c].y+2*d){if(this.tempActiveObj&&this.tempActiveObj.activePoint&&JSON.stringify(this.tempActiveObj.activePoint)===JSON.stringify(h.activePoint)){s=l;break}this.isTouch||"move"===r.cursor||"grab"===r.cursor||this.isShapeInserted?(0===n||n<h.order)&&(n=h.order,s=l):r.objColl[l].currIndex===this.tempActiveObj.currIndex&&(s=l);break}}else if("path"===h.shape){var u=this.setCursorForPath(h,e,o,r.upperCanvas);if("default"!==u&&"grab"!==u){if(this.tempActiveObj&&this.tempActiveObj.activePoint&&JSON.stringify(this.tempActiveObj.activePoint)===JSON.stringify(h.activePoint)){s=l;break}this.isTouch||"move"===r.cursor||"grab"===r.cursor||this.isShapeInserted?(0===n||n<h.order)&&(n=h.order,s=l):r.objColl[l].currIndex===this.tempActiveObj.currIndex&&(s=l)}}else if(0!==h.rotatedAngle){var v=this.setCursorForRotatedObject(h,e,o,r.upperCanvas);if("default"!==v&&"grab"!==v){if(this.tempActiveObj&&this.tempActiveObj.activePoint&&JSON.stringify(this.tempActiveObj.activePoint)===JSON.stringify(h.activePoint)){s=l;break}this.isTouch||"move"===r.cursor||"grab"===r.cursor||this.isShapeInserted?(0===n||n<h.order&&("redact"!==h.shape||"redact"===r.drawingShape))&&(n=h.order,s=l):r.objColl[l].currIndex===this.tempActiveObj.currIndex&&(s=l)}}else{var g=this.getTransRotationPoint(h);if(e>=h.activePoint.startX-2*d&&e<=h.activePoint.endX+2*d&&o>=h.activePoint.startY-2*d&&o<=h.activePoint.endY+2*d||g&&e>=g.x-2*d&&e<=g.x+2*d&&o>=g.y-2*d&&o<=g.y+2*d){if(this.tempActiveObj&&this.tempActiveObj.activePoint&&JSON.stringify(this.tempActiveObj.activePoint)===JSON.stringify(h.activePoint)){s=l;break}this.isTouch||"move"===p||"grabbing"===p||this.isShapeInserted||"move"===r.cursor||"grabbing"===r.cursor?(0===n||n<h.order&&("redact"!==h.shape||"redact"===r.drawingShape))&&(n=h.order,s=l):r.objColl[l].currIndex===this.tempActiveObj.currIndex&&(s=l)}}}if(t.isNullOrUndefined(s))r.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),a=!1;else{this.tempObjColl=t.extend([],r.objColl,[],!0),r.currObjType.isCustomCrop=!1,r.activeObj=t.extend({},r.objColl[s],{},!0);var f=t.extend({},r.objColl[s],{},!0);if(r.objColl.splice(s,1),0===r.transform.degree){var C=this.lowerContext.filter;this.lowerContext.clearRect(0,0,r.lowerCanvas.width,r.lowerCanvas.height),r.notify("draw",{prop:"drawImage",onPropertyChange:!1}),this.lowerContext.filter="none",r.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"iterate",pen:"iterate",isPreventApply:null}}),r.activeObj=t.extend({},C,{},!0),this.lowerContext.filter=C,this.getCurrentFlipState()}else{var b=t.extend({},r.panPoint.totalPannedInternalPoint,{},!0),m={startX:r.img.destLeft,startY:r.img.destTop,width:r.img.destWidth,height:r.img.destHeight};r.notify("draw",{prop:"callUpdateCurrTransState",onPropertyChange:!1}),r.panPoint.totalPannedInternalPoint=b,r.img.destLeft=m.startX,r.img.destTop=m.startY,r.img.destWidth=m.width,r.img.destHeight=m.height,r.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"iterate",pen:"iterate",isPreventApply:null}})}r.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.lowerContext}}),(r.currSelectionPoint&&"crop-circle"===r.currSelectionPoint.shape||r.isCircleCrop)&&r.notify("crop",{prop:"cropCircle",onPropertyChange:!1,value:{context:this.lowerContext,isSave:null,isFlip:null}}),r.activeObj=t.extend({},f,{},!0),this.setActivePoint(),r.activeObj=t.extend({},f,{},!0);var y=t.extend({},r.activeObj.strokeSettings,{},!0);r.notify("draw",{prop:"setTempStrokeSettings",onPropertyChange:!1,value:{tempStrokeSettings:y}});var P=t.extend({},r.activeObj.textSettings,{},!0);r.notify("draw",{prop:"setTempTextSettings",onPropertyChange:!1,value:{tempTextSettings:P}});var j=this.updatePrevShapeSettings(),x={cancel:!1,action:"select",previousShapeSettings:j,currentShapeSettings:j,allowShapeOverflow:this.allowOutofBound()};"line"!==r.activeObj.shape&&"arrow"!==r.activeObj.shape||(x.currentShapeSettings.width=r.activeObj.activePoint.endX-r.activeObj.activePoint.startX,x.currentShapeSettings.height=r.activeObj.activePoint.endY-r.activeObj.activePoint.startY),this.isCropSelection=!1;var w=void 0;if(void 0!==r.activeObj.shape&&(w=r.activeObj.shape.split("-")),void 0!==w&&"crop"===w[0]&&(this.isCropSelection=!0),this.isCropSelection||"redact"===r.activeObj.shape){var O={action:x.action,previousSelectionSettings:{type:r.getSelectionType(r.activeObj.shape),startX:x.previousShapeSettings.startX,startY:x.previousShapeSettings.startY,width:x.previousShapeSettings.width,height:x.previousShapeSettings.height},currentSelectionSettings:{type:r.getSelectionType(r.activeObj.shape),startX:x.currentShapeSettings.startX,startY:x.currentShapeSettings.startY,width:x.currentShapeSettings.width,height:x.currentShapeSettings.height}};r.trigger("selectionChanging",O),r.editCompleteArgs=O,x.currentShapeSettings.startX=O.currentSelectionSettings.startX,x.currentShapeSettings.startY=O.currentSelectionSettings.startY,x.currentShapeSettings.width=O.currentSelectionSettings.width,x.currentShapeSettings.height=O.currentSelectionSettings.height,this.shapeEvent(x)}else r.trigger("shapeChanging",x),this.shapeEvent(x),r.editCompleteArgs=x;a=!0}}return a},o.prototype.shapeEvent=function(e){var o=this.parent;if(o.notify("shape",{prop:"updateShapeChangeEventArgs",onPropertyChange:!1,value:{shapeSettings:e.currentShapeSettings,allowShapeOverflow:e.allowShapeOverflow}}),o.activeObj.activePoint){var i={prevActObj:null};o.notify("draw",{prop:"getPrevActObj",onPropertyChange:!1,value:{obj:i}}),t.isNullOrUndefined(i.prevActObj)&&o.notify("draw",{prop:"setPrevActObj",onPropertyChange:!1,value:{prevActObj:t.extend({},o.activeObj,{},!0)}}),"image"!==o.activeObj.shape||this.isImageClarity||(this.upgradeImageQuality(),this.isImageClarity=!0),o.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate",obj:o.activeObj,isCropRatio:null,points:null,isPreventDrag:!0,saveContext:null,isPreventSelection:!0}}),this.isShapeInserted||(this.isPreventDragging=this.isShapeDragOut())}},o.prototype.upgradeImageQuality=function(){var e=this.parent;if(e.activeObj.imageCanvas){var o=t.extend({},e.activeObj,null,!0),i=e.activeObj.imageCanvas.getContext("2d"),r={width:0,height:0};e.notify("transform",{prop:"calcMaxDimension",onPropertyChange:!1,value:{width:e.activeObj.imageElement.width,height:e.activeObj.imageElement.height,obj:r,isImgShape:null}}),e.notify("shape",{prop:"updateObj",onPropertyChange:!1,value:{dimObj:r,x:null,y:null}}),i.clearRect(0,0,e.activeObj.imageCanvas.width,e.activeObj.imageCanvas.height),this.applyTransformToImg(i),e.activeObj=o}},o.prototype.applyTransformToImg=function(e){var t=this.parent;t.activeObj.isHorImageFlip&&t.activeObj.isVerImageFlip?(t.activeObj.isHorImageFlip=t.activeObj.isVerImageFlip=!1,t.notify("draw",{prop:"downScaleImgCanvas",onPropertyChange:!1,value:{ctx:e,isImgAnnotation:!0,isHFlip:!0,isVFlip:!0}})):t.activeObj.isHorImageFlip?(t.activeObj.isHorImageFlip=!1,t.notify("draw",{prop:"downScaleImgCanvas",onPropertyChange:!1,value:{ctx:e,isImgAnnotation:!0,isHFlip:!0,isVFlip:!1}})):t.activeObj.isVerImageFlip?(t.activeObj.isVerImageFlip=!1,t.notify("draw",{prop:"downScaleImgCanvas",onPropertyChange:!1,value:{ctx:e,isImgAnnotation:!0,isHFlip:!1,isVFlip:!0}})):t.notify("draw",{prop:"downScaleImgCanvas",onPropertyChange:!1,value:{ctx:e,isImgAnnotation:!0,isHFlip:!1,isVFlip:!1}})},o.prototype.targetTouches=function(e){var t=this.parent.lowerCanvas.getBoundingClientRect();return[{x:e[0].pageX-t.left,y:e[0].pageY-t.top},{x:e[1].pageX-t.left,y:e[1].pageY-t.top}]},o.prototype.calculateScale=function(e,t){var o=this.getDistance(e[0],e[1]);return this.getDistance(t[0],t[1])/o},o.prototype.getDistance=function(e,t){var o=0,i=0;return e&&t&&(o=e.x-t.x,i=e.y-t.y),Math.sqrt(o*o+i*i)},o.prototype.redrawShape=function(e,o){for(var i=this.parent,r=0,a=i.objColl.length;r<a;r++)if(JSON.stringify(e)===JSON.stringify(i.objColl[r])){if(i.objColl.splice(r,1),e.shape&&"none"===i.textArea.style.display){var n=t.extend({},e,{},!0);i.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),this.lowerContext.clearRect(0,0,i.lowerCanvas.width,i.lowerCanvas.height),i.notify("draw",{prop:"render-image",value:{isMouseWheel:null}}),i.rotateFlipColl.length>0&&(0!==i.panPoint.totalPannedClientPoint.x||0!==i.panPoint.totalPannedClientPoint.y)&&i.notify("draw",{prop:"redrawImgWithObj",onPropertyChange:!1}),e=i.activeObj=n}break}"path"===e.shape&&0===e.pointColl.length||"path"!==e.shape&&0===e.activePoint.width&&0===e.activePoint.height||(this.upperContext.clearRect(0,0,i.upperCanvas.width,i.upperCanvas.height),this.isPreventDragging?(i.activeObj.activePoint.startX>i.img.destLeft&&(this.isPreventDragging=!1),o&&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&&0!==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}}):("redact"===i.activeObj.shape&&(this.lowerContext.clearRect(0,0,i.lowerCanvas.width,i.lowerCanvas.height),i.notify("draw",{prop:"redrawImgWithObj",onPropertyChange:!1}),i.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.lowerContext}})),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(e){var o=this.parent;this.timer>10&&(clearTimeout(this.timer),this.timer=0,o.notify("shape",{prop:"findTextTarget",onPropertyChange:!1,value:{e:e}}),t.Browser.isDevice&&this.upperContext.clearRect(0,0,o.upperCanvas.width,o.upperCanvas.height))},o.prototype.applyCurrActObj=function(e,o){var i=this.parent,r=!1,a=t.extend({},i.activeObj,{},!0);if(!t.isNullOrUndefined(a.activePoint)){var n=a.activePoint,s=n.startX,l=n.startY,p=n.endX,h=n.endY,d=a.topLeftCircle?a.topLeftCircle.radius:0;if(e>=Math.floor(s)&&e<=Math.ceil(p)&&o>=Math.floor(l)&&o<=Math.ceil(h))r=!0;else if(0!==d&&e>=Math.floor(s)-d&&e<=Math.ceil(p)+d&&o>=Math.floor(l)-d&&o<=Math.ceil(h)+d)r=!0,this.tempActiveObj={activePoint:{startX:0,startY:0,endX:0,endY:0,width:0,height:0},flipObjColl:[],triangle:[],triangleRatio:[]};else if("text"!==a.shape&&"image"!==a.shape||""===this.dragElement)if("line"===a.shape||"arrow"===a.shape){var c={x:s<p?s:p,y:l<h?l:h},u={x:s>p?s:p,y:l>h?l:h};(e>=Math.floor(c.x)-5&&e<=Math.ceil(u.x)+5&&o>=Math.floor(c.y)-5&&o<=Math.ceil(u.y)+5||i.activeObj.preventShapeDragOut)&&(r=!0)}else if("path"===a.shape)"move"===(v=this.setCursorForPath(a,e,o,i.upperCanvas))&&(r=!0);else if("grabbing"===this.dragElement)r=!0;else if(0!==a.rotatedAngle){var v=this.setCursorForRotatedObject(a,e,o,i.upperCanvas);("default"!==v&&"grab"!==v||"n-resize"===this.dragElement||"e-resize"===this.dragElement||"s-resize"===this.dragElement||"w-resize"===this.dragElement)&&(r=!0)}else"block"!==i.textArea.style.display&&"inline-block"!==i.textArea.style.display||(r=!0);else r=!0;if(!r){if(t.isNullOrUndefined(i.activeObj.currIndex)){var g={id:"shape_"+(i.objColl.length+1)};i.notify("shape",{prop:"getNewShapeId",onPropertyChange:!1,value:{obj:g}}),i.activeObj.currIndex=g.id}if(i.notify("shape",{prop:"updImgRatioForActObj",onPropertyChange:!1}),void 0===i.activeObj.horTopLine||0===i.activeObj.horTopLine.startX||0===i.activeObj.horTopLine.endX||i.currObjType.isCustomCrop||""===i.currObjType.shape||i.objColl.length>0&&JSON.stringify(i.objColl[i.objColl.length-1].activePoint)!==JSON.stringify(i.activeObj.activePoint)&&i.objColl.push(t.extend({},i.activeObj,{},!0)),["rectangle","ellipse","line","arrow","path","text","image"].indexOf(i.activeObj.shape)>-1){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%)",i.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"zoom",pen:"zoom",isPreventApply:null}}),this.lowerContext.filter=f,i.activeObj.shape&&i.notify("shape",{prop:"apply",onPropertyChange:!1,value:{shape:null,obj:null,canvas:null}}),i.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.lowerContext}}),i.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.upperContext}}),i.isCircleCrop&&i.notify("crop",{prop:"cropCircle",onPropertyChange:!1,value:{context:this.lowerContext,isSave:null,isFlip:null}})}i.notify("toolbar",{prop:"refresh-main-toolbar",onPropertyChange:!1})}}},o.prototype.getCurrentFlipState=function(){var e=this.parent;if(0!==e.rotateFlipColl.length){var o=t.extend({},e.panPoint.totalPannedInternalPoint,{},!0);e.notify("draw",{prop:"callUpdateCurrTransState",onPropertyChange:!1}),e.panPoint.totalPannedInternalPoint=o}else e.notify("draw",{prop:"callUpdateCurrTransState",onPropertyChange:!1})},o.prototype.setTextBoxStylesToActObj=function(){var e=this.parent;e.activeObj.textSettings.fontFamily=e.textArea.style.fontFamily,e.activeObj.strokeSettings.strokeColor=""!==e.textArea.style.color&&e.textArea.style.color.split("(")[1]&&e.textArea.style.color.split("(")[1].split(",")[0]&&e.textArea.style.color.split("(")[1].split(",")[1]&&e.textArea.style.color.split("(")[1].split(",")[2]&&e.textArea.style.color.split("(")[1].split(",")[3]?this.rgbToHex(parseFloat(e.textArea.style.color.split("(")[1].split(",")[0]),parseFloat(e.textArea.style.color.split("(")[1].split(",")[1]),parseFloat(e.textArea.style.color.split("(")[1].split(",")[2]),parseFloat(e.textArea.style.color.split("(")[1].split(",")[3])):e.textArea.style.color,e.activeObj.strokeSettings.fillColor=""!==e.textArea.style.backgroundColor&&e.textArea.style.backgroundColor.split("(")[1]&&e.textArea.style.backgroundColor.split("(")[1].split(",")[0]&&e.textArea.style.backgroundColor.split("(")[1].split(",")[1]&&e.textArea.style.backgroundColor.split("(")[1].split(",")[2]&&e.textArea.style.backgroundColor.split("(")[1].split(",")[3]?this.rgbToHex(parseFloat(e.textArea.style.backgroundColor.split("(")[1].split(",")[0]),parseFloat(e.textArea.style.backgroundColor.split("(")[1].split(",")[1]),parseFloat(e.textArea.style.backgroundColor.split("(")[1].split(",")[2]),parseFloat(e.textArea.style.backgroundColor.split("(")[1].split(",")[3])):e.textArea.style.backgroundColor,e.activeObj.strokeSettings.outlineColor=""!==e.textArea.style.textShadow&&e.textArea.style.textShadow.split("(")[1]&&e.textArea.style.textShadow.split("(")[1].split(",")[0]&&e.textArea.style.textShadow.split("(")[1].split(",")[1]&&e.textArea.style.textShadow.split("(")[1].split(",")[2]&&e.textArea.style.textShadow.split("(")[1].split(",")[3]?this.rgbToHex(parseFloat(e.textArea.style.textShadow.split("(")[1].split(",")[0]),parseFloat(e.textArea.style.textShadow.split("(")[1].split(",")[1]),parseFloat(e.textArea.style.textShadow.split("(")[1].split(",")[2]),parseFloat(e.textArea.style.textShadow.split("(")[1].split(",")[3])):e.textArea.style.textShadow.match(/^(\s*[\w#]+)\s/)?e.textArea.style.textShadow.match(/^(\s*[\w#]+)\s/)[1].trim():e.textArea.style.textShadow,"bold"===e.textArea.style.fontWeight?e.activeObj.textSettings.bold=!0:e.activeObj.textSettings.bold=!1,"italic"===e.textArea.style.fontStyle?e.activeObj.textSettings.italic=!0:e.activeObj.textSettings.italic=!1,e.activeObj.textSettings.fontSize=parseFloat(e.textArea.style.fontSize)},o.prototype.rgbToHex=function(e,t,o,i){e=Math.max(0,Math.min(255,Math.round(e))),t=Math.max(0,Math.min(255,Math.round(t))),o=Math.max(0,Math.min(255,Math.round(o))),i=Math.max(0,Math.min(1,i));var r=this.padLeft(e.toString(16),2,"0"),a=this.padLeft(t.toString(16),2,"0"),n=this.padLeft(o.toString(16),2,"0"),s=this.padLeft(Math.round(255*i).toString(16),2,"0");return isNaN(Number(s))?"#"+r+a+n:"#"+r+a+n+s},o.prototype.padLeft=function(e,t,o){for(;e.length<t;)e=o+e;return e},o.prototype.deleteItem=function(){var e=this.parent,o={cancel:!1};if(this.isFhdEditing){this.updateFreehandDrawColorChange();var i=t.extend({},e.cropObj,{},!0),r={currObj:{}};e.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:r}}),(h=r.currObj).objColl=t.extend([],e.objColl,[],!0),h.pointColl=t.extend([],e.pointColl,[],!0),h.afterCropActions=t.extend([],e.afterCropActions,[],!0);d={selPointColl:null};e.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:d}}),h.selPointColl=t.extend([],d.selPointColl,[],!0);a={freehandDrawSelectedId:null};e.notify("freehand-draw",{prop:"getFreehandDrawSelectedId",onPropertyChange:!1,value:{obj:a}}),e.notify("freehand-draw",{prop:"deleteFhd",value:{id:a.freehandDrawSelectedId}}),e.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"deleteFreehandDrawing",previousObj:h,previousObjColl:this.tempObjColl,previousPointColl:h.pointColl,previousSelPointColl:h.selPointColl,previousCropObj:i,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),e.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"ok"}}),e.notify("freehand-draw",{prop:"resetFreehandDrawSelectedId"})}else if("none"===e.textArea.style.display){var a={prevActObj:null};if(e.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(e.activeObj)){var n=e.activeObj.currIndex;e.notify("draw",{prop:"performCancel",value:{isContextualToolbar:null,isFinalCancel:!0}});for(var s=0,l=e.objColl.length;s<l;s++)if(e.objColl[s].currIndex===n){e.objColl.splice(s,1),e.notify("draw",{prop:"render-image",value:{isMouseWheel:null}});break}}r={isNewPath:null};if(e.notify("draw",{prop:"getNewPath",value:{obj:r}}),r.isNewPath)e.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),this.upperContext.clearRect(0,0,e.upperCanvas.width,e.upperCanvas.height),e.notify("draw",{prop:"render-image",value:{isMouseWheel:null}}),e.notify("toolbar",{prop:"refresh-main-toolbar",onPropertyChange:!1});else if(e.activeObj.shape){e.objColl.push(e.activeObj);var i=t.extend({},e.cropObj,{},!0),p={currObj:{}};e.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:p}});var h=p.currObj;h.objColl=t.extend([],e.objColl,[],!0),h.pointColl=t.extend([],e.pointColl,[],!0),h.afterCropActions=t.extend([],e.afterCropActions,[],!0);var d={selPointColl:null};e.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:d}}),h.selPointColl=t.extend([],d.selPointColl,[],!0),e.objColl.pop(),o={cancel:!1,action:"delete",previousShapeSettings:this.updatePrevShapeSettings(),currentShapeSettings:null},e.notify("shape",{prop:"setKeyHistory",onPropertyChange:!1,value:{keyHistory:""}}),e.clearSelection(),e.trigger("shapeChanging",o),e.editCompleteArgs=o,e.notify("toolbar",{prop:"refresh-main-toolbar",onPropertyChange:!1}),e.notify("draw",{prop:"render-image",value:{isMouseWheel:null}}),t.isNullOrUndefined(h.objColl[h.objColl.length-1].currIndex)||(e.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"deleteObj",previousObj:h,previousObjColl:this.tempObjColl,previousPointColl:h.pointColl,previousSelPointColl:h.selPointColl,previousCropObj:i,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),e.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"ok"}}))}e.notify("draw",{prop:"setPrevActObj",onPropertyChange:!1,value:{prevActObj:null}}),e.drawingShape&&(this.currentDrawingShape=e.drawingShape.toLowerCase(),e.enableShapeDrawing(e.toPascalCase(e.drawingShape),!0),e.upperCanvas.style.cursor="crosshair")}document.getElementById(e.element.id+"_quickAccessToolbarArea")&&(document.getElementById(e.element.id+"_quickAccessToolbarArea").style.display="none")},o.prototype.updateFreehandDrawColorChange=function(){var e=this.parent,o={freehandSelectedIndex:null};if(e.notify("freehand-draw",{prop:"getFreehandSelectedIndex",onPropertyChange:!1,value:{obj:o}}),!t.isNullOrUndefined(o.freehandSelectedIndex)&&!t.isNullOrUndefined(e.pointColl[o.freehandSelectedIndex])&&"#42a5f5"===e.pointColl[o.freehandSelectedIndex].strokeColor){var i={tempFreeHandDrawEditingStyles:null};e.notify("freehand-draw",{prop:"getTempFreeHandDrawEditingStyles",value:{obj:i}}),e.pointColl[o.freehandSelectedIndex].strokeColor=i.tempFreeHandDrawEditingStyles.strokeColor}},o.prototype.updatePrevShapeSettings=function(e){var o=this.parent,i=[];if(t.isNullOrUndefined(o.activeObj.currIndex)){var r={id:"shape_"+(o.objColl.length+1)};o.notify("shape",{prop:"getNewShapeId",onPropertyChange:!1,value:{obj:r}}),o.activeObj.currIndex=r.id}"text"===o.activeObj.shape&&o.activeObj.textSettings&&(o.activeObj.textSettings.bold&&i.push("bold"),o.activeObj.textSettings.italic&&i.push("italic"),o.activeObj.textSettings.underline&&i.push("underline"));var a=o.activeObj.activePoint,n=a.startX,s=a.startY,l=a.endX,p=a.endY,h=a.width,d=a.height,c=o.activeObj,u=c.keyHistory,v=c.currIndex,g=c.shape,f=c.textSettings,C=c.strokeSettings,b=c.rotatedAngle,m=c.imageElement,y=c.opacity,P={id:t.isNullOrUndefined(v)?null:v,type:o.toPascalCase(g),startX:n,startY:s,width:h,height:d,strokeColor:C?C.strokeColor:null,strokeWidth:C?C.strokeWidth:null,fillColor:C?C.fillColor:null,radius:"ellipse"===g?h/2:null,length:"line"===g||"arrow"===g?h:null,text:"text"===g?u||(f.text?f.text:null):null,fontSize:"text"===g&&f?f.fontSize:null,fontFamily:"text"===g&&f?f.fontFamily:null,fontStyle:"text"===g?i:null,color:"text"===g&&C?C.strokeColor:null,degree:"ellipse"===g||"rectangle"===g||"image"===g||"text"===g?b*(180/Math.PI):null,imageData:"image"===g?m.src:null,opacity:"image"===g?y:null,radiusX:"ellipse"===g?h/2:null,radiusY:"ellipse"===g?d/2:null,endX:"line"===g||"arrow"===g?l:null,endY:"line"===g||"arrow"===g?p:null,arrowHead:"arrow"===g?this.getArrowType(o.activeObj.start):null,arrowTail:"arrow"===g?this.getArrowType(o.activeObj.end):null,points:"path"===g?o.activeObj.pointColl:null,index:o.activeObj.order};return e&&(e.shapeSettingsObj=P),P},o.prototype.getArrowType=function(e){return{none:"None",arrow:"Arrow",arrowSolid:"SolidArrow",circle:"Circle",circleSolid:"SolidCircle",square:"Square",squareSolid:"SolidSquare",bar:"Bar"}[""+e]},o.prototype.getRectanglePoints=function(e,t,o,i,r,a,n){var s=e+o/2,l=t+i/2,p=r*(Math.PI/180),h=Math.cos(p),d=Math.sin(p),c=a-s,u=n-l,v=c*h+u*d,g=-c*d+u*h,f=o/2,C=i/2;return v>=-f&&v<=f&&g>=-C&&g<=C},o.prototype.getTransRotationPoint=function(e,t){var o,i,r=!1,a=!1;if((i=0===e.shapeDegree?this.parent.transform.degree:this.parent.transform.degree-e.shapeDegree)<0&&(i=360+i),e.flipObjColl)for(var n=0,s=e.flipObjColl.length;n<s;n++)"horizontal"===e.flipObjColl[n].toLowerCase()?r=!0:"vertical"===e.flipObjColl[n].toLowerCase()&&(a=!0);return 0===i||360===i?o=a?{x:e.topCenterCircle.startX,y:e.topCenterCircle.startY-e.rotationCircleLine}:{x:e.bottomCenterCircle.startX,y:e.bottomCenterCircle.startY+e.rotationCircleLine}:90===i||-270===i?o=r?{x:e.centerRightCircle.startX+e.rotationCircleLine,y:e.centerLeftCircle.startY}:{x:e.centerLeftCircle.startX-e.rotationCircleLine,y:e.centerLeftCircle.startY}:180===i||-180===i?o=a?{x:e.bottomCenterCircle.startX,y:e.bottomCenterCircle.startY+e.rotationCircleLine}:{x:e.topCenterCircle.startX,y:e.topCenterCircle.startY-e.rotationCircleLine}:270!==i&&-90!==i||(o=r?{x:e.centerLeftCircle.startX-e.rotationCircleLine,y:e.centerLeftCircle.startY}:{x:e.centerRightCircle.startX+e.rotationCircleLine,y:e.centerLeftCircle.startY}),t&&(t.rotationCirclePoint=o),o},o.prototype.getNumTextValue=function(e){var t,o,i,r,a=this.parent.element;if(i=a.querySelector("#"+a.id+"_resizeWidth"),r=a.querySelector("#"+a.id+"_resizeHeight"),i&&r){var n=r.value.replace(/,/g,""),s=i.value.replace(/,/g,"");""===n&&(n=r.placeholder.replace(/,/g,"")),""===s&&(s=i.placeholder.replace(/,/g,"")),t=parseFloat(n),o=parseFloat(s)}return e&&(e.width=o,e.height=t),{x:o,y:t}},o.prototype.isValueUpdated=function(){var e,t,o=!0;return e=this.parent.element.querySelector("#"+this.parent.element.id+"_resizeWidth"),t=this.parent.element.querySelector("#"+this.parent.element.id+"_resizeHeight"),e&&t&&""===t.value.replace(/,/g,"")&&""===e.value.replace(/,/g,"")&&(o=!1),o},o.prototype.allowOutofBound=function(){return-1===["ellipse","rectangle","text","image","redact"].indexOf(this.parent.activeObj.shape)||0!==this.parent.activeObj.rotatedAngle},o}(),g=function(){function o(e){this.textSettings={text:"Enter Text",fontFamily:"",fontSize:null,fontRatio:null,bold:!1,italic:!1,underline:!1},this.strokeSettings={strokeColor:"#fff",fillColor:"",strokeWidth:null,radius:null,outlineColor:"",outlineWidth:null},this.keyHistory="",this.preventFrameAnnotation=!1,this.redactType="blur",this.parent=e,this.addEventListener()}return o.prototype.destroy=function(){this.parent.isDestroyed||this.removeEventListener()},o.prototype.addEventListener=function(){this.parent.on("shape",this.shape,this),this.parent.on("destroyed",this.destroy,this)},o.prototype.removeEventListener=function(){this.parent.off("shape",this.shape),this.parent.off("destroyed",this.destroy)},o.prototype.shape=function(e){var o=this.parent;this.initShapePvtProps();var i;switch(e.prop){case"drawEllipse":this.drawEllipse(e.value.x,e.value.y,e.value.radiusX,e.value.radiusY,e.value.strokeWidth,e.value.strokeColor,e.value.fillColor,e.value.degree,e.value.isSelected);break;case"drawLine":this.drawLine(e.value.startX,e.value.startY,e.value.endX,e.value.endY,e.value.strokeWidth,e.value.strokeColor,e.value.isSelected);break;case"drawArrow":this.drawArrow(e.value.startX,e.value.startY,e.value.endX,e.value.endY,e.value.strokeWidth,e.value.strokeColor,e.value.arrowStart,e.value.arrowEnd,e.value.isSelected);break;case"drawPath":this.drawPath(e.value.pointColl,e.value.strokeWidth,e.value.strokeColor,e.value.isSelected);break;case"drawRectangle":this.drawRectangle(e.value.x,e.value.y,e.value.width,e.value.height,e.value.strokeWidth,e.value.strokeColor,e.value.fillColor,e.value.degree,e.value.isSelected,e.value.radius);break;case"drawText":this.drawText(e.value.x,e.value.y,e.value.text,e.value.fontFamily,e.value.fontSize,e.value.bold,e.value.italic,e.value.color,e.value.isSelected,e.value.degree,e.value.fillColor,e.value.outlineColor,e.value.outlineWidth);break;case"redrawActObj":this.redrawActObj(e.value.x,e.value.y,e.value.isMouseDown);break;case"apply":this.apply(e.value.shape,e.value.obj,e.value.canvas);break;case"updateShapeChangeEventArgs":this.updateShapeChangeEventArgs(e.value.shapeSettings,e.value.allowShapeOverflow);break;case"updSelChangeEventArgs":this.updSelChangeEventArgs(e.value.selectionSettings);break;case"iterateObjColl":this.iterateObjColl();break;case"updImgRatioForActObj":this.updImgRatioForActObj();break;case"redrawObj":this.redrawObj(e.value.degree);break;case"redraw-text":this.redrawText();break;case"draw-shape":this.drawShape(e.value.obj,e.value.strokeWidth,e.value.strokeColor,e.value.fillColor,e.value.start,e.value.width,e.value.height);break;case"renderTextArea":this.renderTextArea(e.value.x,e.value.y,e.value.actObj);break;case"setTextBoxWidth":this.setTextBoxWidth(e.value.e);break;case"findTextTarget":this.findTextTarget(e.value.e);break;case"updateFontStyles":this.updateFontStyles(e.value.isTextBox);break;case"applyFontStyle":this.applyFontStyle(e.value.item);break;case"updateFontRatio":this.updateFontRatio(e.value.obj,e.value.isTextArea);break;case"updateFontSize":this.updateFontSize(e.value.obj);break;case"pushActItemIntoObj":this.pushActItemIntoObj();break;case"clearActObj":this.clearActObj();break;case"refreshActiveObj":this.refreshActiveObj();break;case"applyActObj":this.applyActObj(e.value.isMouseDown);break;case"wireEvent":t.EventHandler.add(o.upperCanvas,"dblclick",this.findTextTarget,this),t.EventHandler.add(o.textArea,"mousedown",this.findTextTarget,this),(i=document.getElementById(o.element.id+"_fileUpload"))&&t.EventHandler.add(i,"change",this.fileChanged,this);break;case"unWireEvent":t.EventHandler.remove(o.upperCanvas,"dblclick",this.findTextTarget),t.EventHandler.remove(o.textArea,"mousedown",this.findTextTarget),(i=document.getElementById(o.element.id+"_fileUpload"))&&t.EventHandler.remove(i,"change",this.fileChanged);break;case"getShapeSetting":this.getShapeSetting(e.value.id,e.value.obj);break;case"getShapeSettings":this.getShapeSettings(e.value.obj);break;case"getRedactSettings":this.getRedactSettings(e.value.obj);break;case"isPointsInRange":this.isPointsInRange(e.value.x,e.value.y,e.value.obj);break;case"alignRotateFlipColl":this.alignRotateFlipColl(e.value.collection,e.value.isRotateFlipCollection,e.value.obj);break;case"selectShape":this.selectShape(e.value.id,e.value.obj);break;case"deleteShape":this.deleteShape(e.value.id);break;case"getMaxText":this.getMaxText(e.value.isTextBox,e.value.text,e.value.obj);break;case"setPointCollForLineArrow":e.value.obj.pointColl=this.getLinePoints(e.value.obj.activePoint.startX,e.value.obj.activePoint.startY,e.value.obj.activePoint.endX,e.value.obj.activePoint.endY);break;case"setPointCollForShapeRotation":this.setPointCollForShapeRotation(e.value.obj);break;case"setTextSettings":e.value.textSettings?this.textSettings=e.value.textSettings:e.value.fontFamily?this.textSettings.fontFamily=e.value.fontFamily:e.value.fontSize?this.textSettings.fontSize=e.value.fontSize:e.value.radius&&(this.strokeSettings.radius=e.value.radius);break;case"setStrokeSettings":e.value.strokeSettings?this.strokeSettings=e.value.strokeSettings:e.value.strokeColor?this.strokeSettings.strokeColor=e.value.strokeColor:e.value.fillColor?this.strokeSettings.fillColor=e.value.fillColor:e.value.strokeWidth?this.strokeSettings.strokeWidth=e.value.strokeWidth:e.value.outlineColor?this.strokeSettings.outlineColor=e.value.outlineColor:e.value.radius?this.strokeSettings.radius=e.value.radius:e.value.outlineWidth&&(this.strokeSettings.outlineWidth=e.value.outlineWidth);break;case"getStrokeSettings":e.value.obj.strokeSettings=this.strokeSettings;break;case"setKeyHistory":this.keyHistory=e.value.keyHistory;break;case"getKeyHistory":e.value.obj.keyHistory=this.keyHistory;break;case"setTextBoxPos":this.setTextBoxPos(e.value.actObj,e.value.degree,e.value.flip,e.value.x,e.value.y);break;case"setTextBoxPoints":this.setTextBoxPoints(e.value.actObj,e.value.degree,e.value.flip,e.value.x,e.value.y);break;case"alignTextAreaIntoCanvas":this.alignTextAreaIntoCanvas();break;case"initializeTextShape":this.initializeTextShape(e.value.text,e.value.fontFamily,e.value.fontSize,e.value.bold,e.value.italic,e.value.strokeColor,e.value.fillColor,e.value.outlineColor,e.value.outlineWidth);break;case"stopPathDrawing":this.stopPathDrawing(e.value.e,e.value.isApply);break;case"updateArrowRatio":this.updateArrowRatio(e.value.obj);break;case"getSquarePointForRotatedShape":this.getSquarePointForRotatedShape(e.value.obj,e.value.object);break;case"drawImage":this.drawImage(e.value.x,e.value.y,e.value.width,e.value.height,e.value.src,e.value.degree,e.value.isAspectRatio,e.value.opacity,e.value.isSelected);break;case"reset":this.reset();break;case"updateObj":this.updateObj(e.value.dimObj,e.value.x,e.value.y);break;case"straightenShapes":this.straightenShapes();break;case"straightenShapePoints":this.straightenShapePoints(e.value.obj,e.value.isReverse);break;case"straightenPath":this.straightenPath(e.value.obj);break;case"straightenFHD":this.straightenFHD();break;case"getTextBoxPosition":this.getTextBoxPosition(e.value.obj,e.value.object);break;case"setFlipState":this.setFlipState(e.value.x,e.value.y,e.value.obj,e.value.object);break;case"getNewShapeId":e.value.obj.id=this.getNewShapeId();break;case"z-order":this.updateZOrder(e.value.obj,e.value.value);break;case"getSmallestIndex":e.value.obj.index=this.getSmallestIndex();break;case"isIndexInObjColl":e.value.obj.bool=this.isIndexInObjColl(e.value.index);break;case"drawAnnotations":this.drawAnnotations(e.value.ctx,e.value.shape,e.value.pen,e.value.isPreventApply,e.value.x,e.value.y,e.value.panRegion);break;case"updateShapeColl":this.updateShapeColl();break;case"getNewOrder":e.value.obj.order=this.getNewOrder();break;case"getHighestOrder":e.value.obj.order=this.getHighestOrder();break;case"getLowestOrder":e.value.obj.order=this.getLowestOrder();break;case"drawRedact":this.drawRedact(e.value.x,e.value.y,e.value.width,e.value.height,e.value.type,e.value.value);break;case"setRedactType":this.redactType=e.value.redactType}},o.prototype.getModuleName=function(){return"shape"},o.prototype.initShapePvtProps=function(){var e=this.parent;e.lowerCanvas&&(this.lowerContext=e.lowerCanvas.getContext("2d")),e.upperCanvas&&(this.upperContext=e.upperCanvas.getContext("2d")),t.isNullOrUndefined(this.shapeImg)&&(this.shapeImg=e.createElement("img",{id:e.element.id+"_shapeImg",attrs:{name:"Image",crossorigin:"anonymous"}})),""===this.textSettings.fontFamily&&(this.textSettings.fontFamily=e.fontFamily.default)},o.prototype.reset=function(){this.textSettings={text:"Enter Text",fontFamily:this.parent.fontFamily.default,fontSize:null,fontRatio:null,bold:!1,italic:!1,underline:!1},this.strokeSettings={strokeColor:"#fff",fillColor:"",strokeWidth:null,radius:null,outlineColor:"",outlineWidth:null},this.preventFrameAnnotation=!1},o.prototype.drawEllipse=function(e,t,o,i,r,a,n,s,l){this.initializeShape("ellipse");var p=e&&t?{x:e,y:t}:null;this.drawShape("ellipse",r,a,n,p,o,i,null,null,null,s,null,l)},o.prototype.drawLine=function(e,t,o,i,r,a,n){this.initializeShape("line");var s=e&&t?{x:e,y:t}:null,l=o-e,p=i-t;this.drawShape("line",r,a,null,s,l,p,null,null,null,null,null,n)},o.prototype.drawPath=function(e,t,o,i){this.initializeShape("path"),e&&this.drawShape("path",t,o,null,null,null,null,e,null,null,null,null,i)},o.prototype.drawArrow=function(e,t,o,i,r,a,n,s,l){this.initializeShape("arrow");var p=e&&t?{x:e,y:t}:null,h=o-e,d=i-t;this.drawShape("arrow",r,a,null,p,h,d,null,n,s,null,null,l)},o.prototype.drawRectangle=function(e,t,o,i,r,a,n,s,l,p){this.initializeShape("rectangle");var h=e&&t?{x:e,y:t}:null;this.drawShape("rectangle",r,a,n,h,o,i,null,null,null,s,null,l,p)},o.prototype.drawRedact=function(e,t,o,i,r,a){this.initializeShape("redact");var n=e&&t?{x:e,y:t}:null;this.drawShape("redact",null,null,null,n,o,i,null,null,null,null,null,null,null,r,a)},o.prototype.drawText=function(e,t,o,i,r,a,n,s,l,p,h,d,c){this.drawShapeText(o,i,r,a,n,s,e,t,l,p,h,d,c)},o.prototype.initializeShape=function(e){var t=this.parent;this.redrawActObj(),t.activeObj.shape=e,t.currObjType.isCustomCrop=!1},o.prototype.updateWidthHeight=function(e){return e.activePoint.width=e.activePoint.endX-e.activePoint.startX,e.activePoint.height=e.activePoint.endY-e.activePoint.startY,e},o.prototype.setDimension=function(e,t){var o=this.parent;e&&t&&(o.activeObj.activePoint.width=e,o.activeObj.activePoint.height=t,"ellipse"===o.currObjType.shape.toLowerCase()&&(o.activeObj.activePoint.width=2*e,o.activeObj.activePoint.height=2*t))},o.prototype.getArrowType=function(e){var t=e;return e&&(t={None:"none",Arrow:"arrow",SolidArrow:"arrowSolid",Circle:"circle",SolidCircle:"circleSolid",Square:"square",SolidSquare:"squareSolid",Bar:"bar"}[""+e]),t},o.prototype.drawShape=function(o,i,r,a,n,s,l,p,h,d,c,u,v,g,f,C){var b=this.parent;if(!b.disabled&&b.isImageLoaded){b.notify("draw",{prop:"setImageEdited",onPropertyChange:!1}),this.redrawActObj();var m=t.extend([],b.objColl,[],!0);if(b.togglePen=!1,this.keyHistory="",b.upperCanvas.style.display="block",this.refreshActiveObj(),b.currObjType.shape=o=o.toLowerCase(),"freehanddraw"!==o&&""!==o){b.activeObj.shape=o;var y=b.activeObj.strokeSettings;this.upperContext.clearRect(0,0,b.upperCanvas.width,b.upperCanvas.height),t.isNullOrUndefined(y)&&(y=this.strokeSettings),"path"===o&&p&&(b.activeObj.pointColl=p),null!==u&&void 0!==u&&(b.activeObj.opacity=u),y.strokeWidth=i||y.strokeWidth,y.strokeColor=r||y.strokeColor,y.fillColor=a||y.fillColor,y.radius=g||y.radius;var P=b.img.destWidth>100?100:b.img.destWidth/2,j=b.img.destHeight>100?100:b.img.destHeight/2;b.activeObj.activePoint.width=P,b.activeObj.activePoint.height=j,"line"===o||"arrow"===o?(b.activeObj.lineDraw="horizontal",b.activeObj.activePoint.height=0,"arrow"===o&&(b.activeObj.activePoint.width+=50,b.activeObj.start=this.getArrowType(h),b.activeObj.end=this.getArrowType(d))):"rectangle"===o?b.activeObj.activePoint.width+=b.activeObj.activePoint.width/2:"redact"===o&&f&&(b.activeObj.redactType=f.toLowerCase(),f===e.RedactType.Blur?C&&(b.activeObj.redactBlur=C):C&&(b.activeObj.redactPixelate=C),b.activeObj.redactImage=b.createElement("canvas")),this.setDimension(s,l),n?(b.activeObj.activePoint.startX=n.x,b.activeObj.activePoint.startY=n.y,b.activeObj.activePoint.endX=b.activeObj.activePoint.startX+b.activeObj.activePoint.width,b.activeObj.activePoint.endY=b.activeObj.activePoint.startY+b.activeObj.activePoint.height):this.setCenterPoints(),this.setPointCollForLineAndArrow(),"arrow"===o&&(b.activeObj.triangleDirection="right"),b.currObjType.isDragging=b.currObjType.isCustomCrop=!1,this.initShapeProps();var x={shapeSettingsObj:{}};b.notify("selection",{prop:"updatePrevShapeSettings",onPropertyChange:!1,value:{obj:x}});var w=x.shapeSettingsObj,O={cancel:!1,action:"insert",previousShapeSettings:w,currentShapeSettings:w};b.trigger("shapeChanging",O),b.editCompleteArgs=O,this.updateShapeChangeEventArgs(O.currentShapeSettings,O.allowShapeOverflow),this.setDimension(s,l),b.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate"}}),c&&(b.activeObj.rotatedAngle=c*(Math.PI/180),b.notify("selection",{prop:"updPtCollForShpRot",onPropertyChange:!1,value:{obj:b.activeObj}})),b.notify("toolbar",{prop:"renderQAT",onPropertyChange:!1,value:{isPenEdit:null}}),b.notify("selection",{prop:"isShapeInserted",onPropertyChange:!1,value:{bool:!0}}),b.notify("undo-redo",{prop:"updateUrObj",onPropertyChange:!1,value:{objColl:m}}),"redact"===o?b.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"redact",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}}):b.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"shapes",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}}),b.notify("toolbar",{prop:"update-toolbar-items",onPropertyChange:!1}),b.isPublicMethod&&!v&&b.notify("undo-redo",{prop:"updateUndoRedo",value:{operation:"shapeInsert"},onPropertyChange:!1}),b.isPublicMethod=!1}}},o.prototype.initShapeProps=function(){var e=this.parent;e.activeObj.shapeDegree=e.transform.degree,e.activeObj.shapeFlip=e.transform.currFlipState,e.activeObj.textFlip=e.transform.currFlipState,e.activeObj.flipObjColl=[],e.activeObj.order=this.getNewOrder()},o.prototype.setPointCollForLineAndArrow=function(){var e=this.parent,t=e.activeObj.shape,o=e.activeObj.activePoint,i=o.startX,r=o.startY,a=o.endX,n=o.endY;if(("line"===t||"arrow"===t)&&(e.activeObj.pointColl=this.getLinePoints(i,r,a,n),e.activeObj.pointColl))for(var s=0,l=e.activeObj.pointColl.length;s<l;s++)e.activeObj.pointColl[s].ratioX=(e.activeObj.pointColl[s].x-e.img.destLeft)/e.img.destWidth,e.activeObj.pointColl[s].ratioY=(e.activeObj.pointColl[s].y-e.img.destTop)/e.img.destHeight},o.prototype.prevObjColl=function(){var e=this.parent,o={currObj:{}};e.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:o}}),this.prevObj=o.currObj,this.prevObj.objColl=t.extend([],e.objColl,[],!0),this.prevObj.pointColl=t.extend([],e.pointColl,[],!0),this.prevObj.afterCropActions=t.extend([],e.afterCropActions,[],!0);var i={selPointColl:null};e.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:i}}),this.prevObj.selPointColl=t.extend([],i.selPointColl,[],!0)},o.prototype.drawShapeText=function(e,o,i,r,a,n,s,l,p,h,d,c,u){var v=this.parent;if(!v.disabled&&v.isImageLoaded){"freehanddraw"===v.currObjType.shape&&(this.apply(),v.upperCanvas.style.cursor=v.cursor="default",v.currObjType.shape=""),v.notify("draw",{prop:"setImageEdited",onPropertyChange:!1}),v.togglePen=!1,this.redrawActObj(),this.prevObjColl(),this.refreshActiveObj(),v.activeObj.shape=v.currObjType.shape="text",v.currObjType.isCustomCrop=!1,this.initializeTextShape(e,o,i,r,a,n,d,c,u),v.currObjType.isText=v.currObjType.isInitialText=!0,t.isNullOrUndefined(v.activeObj.textSettings.fontSize)&&(v.getFontSizes(),v.activeObj.textSettings.fontSize=parseInt(v.fontSizeColl[parseInt("3",10)-1].text,10)),v.img.destWidth<100?v.activeObj.textSettings.fontSize=Math.floor(v.img.destWidth/20):v.img.destHeight<100&&(v.activeObj.textSettings.fontSize=Math.floor(v.img.destHeight/20)),v.activeObj.shapeDegree=v.transform.degree,v.activeObj.shapeFlip=v.transform.currFlipState,v.activeObj.flipObjColl=[],this.updateFontStyles(),v.activeObj.order=this.getNewOrder();var g=this.upperContext.measureText(v.activeObj.textSettings.text).width+.5*v.activeObj.textSettings.fontSize,f=v.activeObj.textSettings.fontSize;t.isNullOrUndefined(s)||t.isNullOrUndefined(l)?this.setCenterPoints(!0,g,f):(v.activeObj.activePoint.startX=s,v.activeObj.activePoint.startY=l,v.activeObj.activePoint.endX=v.activeObj.activePoint.startX+g,v.activeObj.activePoint.endY=v.activeObj.activePoint.startY+f);var C={shapeSettingsObj:{}};v.notify("selection",{prop:"updatePrevShapeSettings",onPropertyChange:!1,value:{obj:C}});var b=C.shapeSettingsObj,m={cancel:!1,action:"insert",previousShapeSettings:b,currentShapeSettings:b};if(v.trigger("shapeChanging",m),v.editCompleteArgs=m,this.drawShapeTextEvent(m),h&&(v.activeObj.rotatedAngle=h*(Math.PI/180),v.notify("selection",{prop:"updPtCollForShpRot",onPropertyChange:!1,value:{obj:v.activeObj}}),this.upperContext.clearRect(0,0,v.upperCanvas.width,v.upperCanvas.height),v.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate",obj:v.activeObj,isCropRatio:null,points:null,isPreventDrag:!0,saveContext:null,isPreventSelection:null}}),v.notify("toolbar",{prop:"destroy-qa-toolbar",onPropertyChange:!1}),v.notify("toolbar",{prop:"renderQAT",onPropertyChange:!1,value:{isPenEdit:null}})),e&&e.indexOf("\n")>-1&&v.isPublicMethod){var y=String(v.fontSizeColl.findIndex(function(e){return e.text===String(v.activeObj.textSettings.fontSize)})+1);v.noPushUndo=!0,v.updateFontSize("5"),parseInt(y,10)>0&&v.updateFontSize(y),v.noPushUndo=!1}v.isPublicMethod&&!p&&v.notify("undo-redo",{prop:"updateUndoRedo",value:{operation:"shapeInsert"},onPropertyChange:!1}),v.isPublicMethod=!1}},o.prototype.drawShapeImageEvent=function(e,o){var i=this.parent;this.updateShapeChangeEventArgs(e.currentShapeSettings,e.allowShapeOverflow),i.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate"}}),i.objColl.push(i.activeObj);var r=t.extend({},i.cropObj,{},!0);i.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"shapeInsert",previousObj:this.prevObj,previousObjColl:this.prevObj.objColl,previousPointColl:this.prevObj.pointColl,previousSelPointColl:this.prevObj.selPointColl,previousCropObj:r,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),i.notify("selection",{prop:"redrawShape",onPropertyChange:!1,value:{obj:i.objColl[i.objColl.length-1]}}),o?(i.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"shapes",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}}),i.notify("toolbar",{prop:"update-toolbar-items",onPropertyChange:!1}),i.notify("toolbar",{prop:"renderQAT",onPropertyChange:!1,value:{isPenEdit:null}})):i.okBtn(null,!0),i.notify("selection",{prop:"isShapeInserted",onPropertyChange:!1,value:{bool:!0}})},o.prototype.drawShapeTextEvent=function(e){var o=this.parent;this.updateShapeChangeEventArgs(e.currentShapeSettings,e.allowShapeOverflow),this.addLetter(o.activeObj.textSettings.text),o.activeObj.textFlip=o.transform.currFlipState,this.updateFontRatio(o.activeObj),o.objColl.push(o.activeObj);var i=t.extend({},o.cropObj,{},!0);o.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"shapeInsert",previousObj:this.prevObj,previousObjColl:this.prevObj.objColl,previousPointColl:this.prevObj.pointColl,previousSelPointColl:this.prevObj.selPointColl,previousCropObj:i,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),o.notify("selection",{prop:"redrawShape",onPropertyChange:!1,value:{obj:o.objColl[o.objColl.length-1]}}),o.notify("toolbar",{prop:"renderQAT",onPropertyChange:!1,value:{isPenEdit:null}}),o.notify("selection",{prop:"isShapeInserted",onPropertyChange:!1,value:{bool:!0}}),o.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"text",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}}),o.notify("toolbar",{prop:"update-toolbar-items",onPropertyChange:!1})},o.prototype.initializeTextShape=function(e,t,o,i,r,a,n,s,l){var p=this.parent;this.keyHistory="",p.upperCanvas.style.display="block",p.activeObj.strokeSettings.strokeColor=a||p.activeObj.strokeSettings.strokeColor,p.activeObj.strokeSettings.fillColor=n||p.activeObj.strokeSettings.fillColor,p.activeObj.textSettings.text=e||p.activeObj.textSettings.text,p.activeObj.textSettings.fontFamily=t||p.activeObj.textSettings.fontFamily,p.activeObj.textSettings.fontSize=o||p.activeObj.textSettings.fontSize,p.activeObj.textSettings.bold=i||p.activeObj.textSettings.bold,p.activeObj.textSettings.italic=r||p.activeObj.textSettings.italic,p.activeObj.strokeSettings.outlineColor=s||p.activeObj.strokeSettings.outlineColor,p.activeObj.strokeSettings.outlineWidth=l||p.activeObj.strokeSettings.outlineWidth},o.prototype.drawImage=function(e,t,o,i,r,a,n,s,l){this.initializeShape("image"),this.onLoadImgShape(e,t,o,i,r,null,a,n,s,l)},o.prototype.redrawActObj=function(e,t,o){var i,r=this.parent;r.activeObj.shape&&(i=r.activeObj.shape.split("-")),r.activeObj.horTopLine&&r.activeObj.shape&&"crop"!==i[0]&&("block"===r.textArea.style.display||"inline-block"===r.textArea.style.display?(r.notify("selection",{prop:"setTextBoxStylesToActObj",onPropertyChange:!1}),this.updateFontRatio(r.activeObj,!0),e&&t?e!==r.activeObj.activePoint.startX&&t!==r.activeObj.activePoint.startY&&this.updateTextFromTextArea():(this.updateTextFromTextArea(),r.textArea.style.transform="",r.notify("toolbar",{prop:"refresh-main-toolbar",onPropertyChange:!1})),this.refreshActiveObj()):this.applyActObj(o))},o.prototype.apply=function(e,o,i){var r=this.parent;if(!r.disabled)if(r.togglePen&&!r.currObjType.isCustomCrop){var a=r.img.destLeft,n=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,(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=a,r.img.destTop=n,r.img.destWidth=s,r.img.destHeight=l,this.lowerContext.filter=p}else i=i||"original",t.isNullOrUndefined(r.activeObj.shape)&&t.isNullOrUndefined(e)?r.currObjType.shape="":r.currObjType.shape=e||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:i,obj:o,isCropRatio:null,points:null,isPreventDrag:!0,saveContext:null,isPreventSelection:null}}):r.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:i,obj:o}}),r.activeObj.shape=r.currObjType.shape.toLowerCase(),e||""===r.currObjType.shape||r.currObjType.isCustomCrop||r.objColl.push(t.extend({},r.activeObj,{},!0)),this.keyHistory="")},o.prototype.setCenterPoints=function(e,t,o){var i,r,a=this.parent;e&&t&&o?(i=t,r=o):(i=a.activeObj.activePoint.width,r=a.activeObj.activePoint.height),a.activeObj.activePoint.startX=a.lowerCanvas.width/2-i/2,a.activeObj.activePoint.startY=a.lowerCanvas.height/2-r/2,a.activeObj.activePoint.endX=a.lowerCanvas.width/2+i/2,a.activeObj.activePoint.endY=a.lowerCanvas.height/2+r/2},o.prototype.updSelChangeEventArgs=function(e){var t=this.parent;t.activeObj.activePoint={startX:e.startX,startY:e.startY,endX:t.activeObj.activePoint.startX+t.activeObj.activePoint.width,endY:t.activeObj.activePoint.startY+t.activeObj.activePoint.height,width:e.width,height:e.height},t.activeObj.activePoint.endX=t.activeObj.activePoint.startX+t.activeObj.activePoint.width,t.activeObj.activePoint.endY=t.activeObj.activePoint.startY+t.activeObj.activePoint.height},o.prototype.updateShapeChangeEventArgs=function(e,o){var i,r=this.parent;if(e.id&&-1===e.id.indexOf("shape_")&&-1===e.id.indexOf("pen_")&&(r.activeObj.currIndex?r.activeObj.currIndex="shape_"+e.id:r.pointColl[i].id="pen_"+e.id),e.id&&e.id.split("_")[0]&&"pen"===e.id.split("_")[0])i=parseInt(e.id.split("_")[1],10)-1,r.pointColl[i].points=e.points,r.pointColl[i].strokeColor=e.strokeColor,r.pointColl[i].strokeWidth=e.strokeWidth,r.pointColl[i].opacity=e.opacity,r.pointColl[i].order=e.index;else{switch(r.activeObj.activePoint.startX=e.startX,r.activeObj.activePoint.startY=e.startY,e.width&&e.height&&(r.activeObj.activePoint.width=e.width,r.activeObj.activePoint.height=e.height,r.activeObj.activePoint.endX=r.activeObj.activePoint.startX+r.activeObj.activePoint.width,r.activeObj.activePoint.endY=r.activeObj.activePoint.startY+r.activeObj.activePoint.height),r.activeObj.strokeSettings.strokeColor=e.strokeColor,r.activeObj.strokeSettings.fillColor=e.fillColor,r.activeObj.strokeSettings.strokeWidth=e.strokeWidth,r.activeObj.opacity=e.opacity,r.activeObj.order=e.index,r.activeObj.preventShapeDragOut=!o,t.isNullOrUndefined(e.degree)&&(e.degree=0),r.activeObj.shape){case"ellipse":r.activeObj.activePoint.width=2*e.radiusX,r.activeObj.activePoint.height=2*e.radiusY,r.activeObj.activePoint.endX=r.activeObj.activePoint.startX+r.activeObj.activePoint.width,r.activeObj.activePoint.endY=r.activeObj.activePoint.startY+r.activeObj.activePoint.height,e.degree&&(r.activeObj.rotatedAngle=e.degree*(Math.PI/180));break;case"line":case"arrow":r.activeObj.activePoint.width=e.length,r.activeObj.activePoint.endX=e.endX,r.activeObj.activePoint.endY=e.endY,r.activeObj.activePoint.width=r.activeObj.activePoint.startX+r.activeObj.activePoint.width,r.activeObj.activePoint.height=r.activeObj.activePoint.startY+r.activeObj.activePoint.height,"arrow"===r.activeObj.shape&&(r.activeObj.start=this.getArrowType(e.arrowHead),r.activeObj.end=this.getArrowType(e.arrowTail));break;case"text":r.activeObj.keyHistory=r.activeObj.textSettings.text=e.text,r.activeObj.textSettings.fontSize=e.fontSize,r.activeObj.strokeSettings.strokeColor=e.color,r.activeObj.textSettings.fontFamily=e.fontFamily,e.degree&&(r.activeObj.rotatedAngle=e.degree*(Math.PI/180)),this.updateFontRatio(r.activeObj);break;case"rectangle":case"image":e.degree&&(r.activeObj.rotatedAngle=e.degree*(Math.PI/180));break;case"path":r.activeObj.pointColl=e.points}if("text"===r.activeObj.shape&&r.activeObj.textSettings){r.activeObj.textSettings.bold=!1,r.activeObj.textSettings.italic=!1,r.activeObj.textSettings.underline=!1;for(var a=0;a<e.fontStyle.length;a++)switch(e.fontStyle[a]){case"bold":r.activeObj.textSettings.bold=!0;break;case"italic":r.activeObj.textSettings.italic=!0}}}},o.prototype.addLetter=function(e){var t=this.parent;if("none"===t.textArea.style.display&&(t.currObjType.isText||"text"===t.activeObj.shape)){var o=t.activeObj.textSettings.fontSize;"Backspace"===e?this.keyHistory=this.keyHistory.slice(0,-1):this.keyHistory+=e,this.upperContext.clearRect(0,0,t.upperCanvas.width,t.upperCanvas.height),this.updateFontStyles();var i=this.upperContext.measureText(this.keyHistory).width+.5*o,r=o;this.upperContext.fillText(this.keyHistory,t.activeObj.activePoint.startX,t.activeObj.activePoint.startY+o),this.upperContext.clearRect(0,0,t.upperCanvas.width,t.upperCanvas.height),t.currObjType.isText=!0,t.notify("selection",{prop:"setActivePoint",onPropertyChange:!1,value:{startX:i,startY:r}})}},o.prototype.redrawText=function(){var e=this.parent,t=e.activeObj.textSettings,o=t.fontSize,i=t.fontFamily,r=t.bold,a=t.italic,n="";r&&(n+="bold "),a&&(n+="italic "),this.upperContext.font=n+o+"px "+i;var s=e.activeObj.keyHistory.split("\n"),l="block"===e.textArea.style.display||"inline-block"===e.textArea.style.display?this.getMaxText(!0):this.getMaxText(),p=this.upperContext.measureText(l).width+.5*o,h=s.length*o;s.length>1&&(h+=.5*o),e.notify("selection",{prop:"setTextSelection",onPropertyChange:!1,value:{width:p,height:h}}),e.notify("draw",{prop:"updateActiveObject",onPropertyChange:!1,value:{actPoint:e.activeObj.activePoint,obj:e.activeObj,isMouseMove:null,x:null,y:null}}),e.notify("selection",{prop:"redrawShape",onPropertyChange:!1,value:{obj:e.activeObj}})},o.prototype.updateTextFromTextArea=function(){var e=this.parent,o=!1,i=e.activeObj.textSettings.fontSize,r=t.extend({},e.activeObj,{},!0),a=t.extend({},e.cropObj,{},!0),n={currObj:{}};e.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:n}});var s=n.currObj;s.objColl=t.extend([],e.objColl,[],!0),s.pointColl=t.extend([],e.pointColl,[],!0),s.afterCropActions=t.extend([],e.afterCropActions,[],!0);var l={selPointColl:null};e.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:l}}),s.selPointColl=t.extend([],l.selPointColl,[],!0),e.activeObj.keyHistory!==e.textArea.value&&(o=!0),e.activeObj.keyHistory=e.textArea.value,e.textArea.style.display="none",e.textArea.value="",this.updateFontStyles();var p=this.upperContext.measureText(e.activeObj.keyHistory).width+.5*i,h=i,d=e.activeObj.keyHistory.split("\n");if(d.length>1){h*=d.length,h+=.1*i*d.length;for(var c=[],u=0,v=d.length;u<v;u++)c.push(this.upperContext.measureText(d[u]).width+.5*i);p=Math.max.apply(Math,c)}if(e.notify("selection",{prop:"setTextSelection",onPropertyChange:!1,value:{width:p,height:h}}),0!==e.activeObj.rotatedAngle){var g=e.activeObj.activePoint.width-r.activePoint.width,f=e.activeObj.activePoint.height-r.activePoint.height,C="";g>0&&f>0?C="widthHeight":0!==g?C="width":0!==f&&(C="height"),e.activeObj.activePoint=t.extend({},r.activePoint,{},!0),e.notify("selection",{prop:"adjustRotationPoints",onPropertyChange:!1,value:{rectangle:e.activeObj.activePoint,x:g,y:f,angle:e.activeObj.rotatedAngle,type:"text",elem:C}}),e.notify("shape",{prop:"updateFontSize",onPropertyChange:!1,value:{obj:e.activeObj}})}e.notify("draw",{prop:"updateActiveObject",onPropertyChange:!1,value:{actPoint:e.activeObj.activePoint,obj:e.activeObj,isMouseMove:null,x:null,y:null}}),this.updImgRatioForActObj(),0!==e.activeObj.rotatedAngle&&e.notify("selection",{prop:"updPtCollForShpRot",onPropertyChange:!1,value:{obj:e.activeObj}}),o?(this.apply(e.activeObj.shape,e.activeObj),e.objColl.push(t.extend({},e.activeObj,{},!0)),e.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"text",previousObj:s,previousObjColl:s.objColl,previousPointColl:s.pointColl,previousSelPointColl:s.selPointColl,previousCropObj:a,previousText:e.activeObj.keyHistory,currentText:e.textArea.value,previousFilter:null,isCircleCrop:null}})):(this.apply(e.activeObj.shape,e.activeObj),e.objColl.push(t.extend({},e.activeObj,{},!0)))},o.prototype.iterateObjColl=function(){var e=this.parent;if(e.objColl.length>0)for(var o=this.getSmallestIndex(),i=t.extend([],e.objColl,[],!0);i.length>0;){for(var r=!1,a=0;a<i.length;a++){var n=i[a];if(t.isNullOrUndefined(n.order))i.splice(a,1),a--;else if(n.order===o){this.apply(n.shape,n),"redact"===n.shape&&JSON.stringify(n.activePoint)===JSON.stringify(e.activeObj.activePoint)&&n.redactImage!==e.activeObj.redactImage&&(n.redactImage=e.activeObj.redactImage,e.objColl[a]&&JSON.stringify(e.objColl[a].activePoint)===JSON.stringify(n.activePoint)&&(e.objColl[a].redactImage=e.activeObj.redactImage)),this.refreshActiveObj(),o++,this.isIndexInObjColl(o)||o++,i.splice(a,1),r=!0;break}}if(!r)break}},o.prototype.getSmallestIndex=function(){for(var e,o=this.parent,i=0,r=o.objColl.length;i<r;i++){var a=o.objColl[i];t.isNullOrUndefined(a.order)||(t.isNullOrUndefined(e)||a.order<e)&&(e=a.order)}return e},o.prototype.isIndexInObjColl=function(e){for(var o=this.parent,i=0,r=o.objColl.length;i<r;i++){var a=o.objColl[i];if(!t.isNullOrUndefined(a.order)&&a.order===e)return!0}return!1},o.prototype.updImgRatioForActObj=function(){var e=this.parent,t={startX:e.img.destLeft,startY:e.img.destTop,width:e.img.destWidth,height:e.img.destHeight};this.straightenShapes();var o=e.img,i=o.destLeft,r=o.destTop,a=o.destWidth,n=o.destHeight,s=e.activeObj.activePoint;e.activeObj.imageRatio={startX:(s.startX-i)/a,startY:(s.startY-r)/n,endX:(s.endX-i)/a,endY:(s.endY-r)/n,width:a/s.width,height:n/s.height},e.activeObj.rotationCirclePointColl&&(e.activeObj.rotationCirclePointColl.ratioX=(e.activeObj.rotationCirclePointColl.x-i)/a,e.activeObj.rotationCirclePointColl.ratioY=(e.activeObj.rotationCirclePointColl.y-r)/n),"path"===e.activeObj.shape?this.updatePathRatio(e.activeObj):"arrow"===e.activeObj.shape&&this.updateArrowRatio(e.activeObj),e.img.destLeft=t.startX,e.img.destTop=t.startY,e.img.destWidth=t.width,e.img.destHeight=t.height},o.prototype.zoomObjColl=function(e){var o=this.parent,i={startX:o.img.destLeft,startY:o.img.destTop,width:o.img.destWidth,height:o.img.destHeight};if(this.straightenShapes(),o.objColl.length>0){for(var r=0,a=o.objColl.length;r<a;r++){var n=o.objColl[r];if(n.imageRatio&&(n.activePoint.startX=n.imageRatio.startX*o.img.destWidth+o.img.destLeft,n.activePoint.startY=n.imageRatio.startY*o.img.destHeight+o.img.destTop,n.activePoint.endX=n.imageRatio.endX*o.img.destWidth+o.img.destLeft,n.activePoint.endY=n.imageRatio.endY*o.img.destHeight+o.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 s=0,l=n.pointColl.length;s<l;s++)n.pointColl[s].ratioX=(n.pointColl[s].x-o.img.destLeft)/o.img.destWidth,n.pointColl[s].ratioY=(n.pointColl[s].y-o.img.destTop)/o.img.destHeight;"arrow"===n.shape&&this.updateArrowSize(n),0===o.transform.straighten||"line"!==n.shape&&"arrow"!==n.shape||this.straightenShapePoints(n)}else if("path"===n.shape){for(var p=0,h=n.pointColl.length;p<h;p++)n.pointColl[p].x=n.pointColl[p].ratioX*o.img.destWidth+o.img.destLeft,n.pointColl[p].y=n.pointColl[p].ratioY*o.img.destHeight+o.img.destTop;this.updatePathRatio(n),0!==o.transform.straighten&&this.straightenPath(n)}o.notify("draw",{prop:"updateActiveObject",onPropertyChange:!1,value:{actPoint:n.activePoint,obj:n}}),"line"!==n.shape&&"arrow"!==n.shape&&"path"!==n.shape&&0!==n.rotatedAngle&&(this.setPointCollForShapeRotation(n),n.rotationCirclePoint.x=n.rotationCirclePoint.ratioX*o.img.destWidth+o.img.destLeft,n.rotationCirclePoint.y=n.rotationCirclePoint.ratioY*o.img.destHeight+o.img.destTop,n.rotationCirclePointColl&&(n.rotationCirclePointColl.x=n.rotationCirclePointColl.ratioX*o.img.destWidth+o.img.destLeft,n.rotationCirclePointColl.y=n.rotationCirclePointColl.ratioY*o.img.destHeight+o.img.destTop))}if(t.isNullOrUndefined(e)){var d=this.lowerContext.filter;this.lowerContext.filter="none",this.iterateObjColl(),this.lowerContext.filter=d}}o.img.destLeft=i.startX,o.img.destTop=i.startY,o.img.destWidth=i.width,o.img.destHeight=i.height},o.prototype.straightenPath=function(e){for(var t,o=0,i=e.pointColl.length;o<i;o++)t=this.straightenPoints(e.pointColl[o].x,e.pointColl[o].y),e.pointColl[o].x=t.x,e.pointColl[o].y=t.y},o.prototype.straightenFHD=function(){for(var e=this.parent,o=0,i=e.freehandCounter;o<i;o++){e.points=t.extend([],e.pointColl[o].points,[]);for(var r=e.points.length,a=void 0,n=0;n<r;n++)a=this.straightenPoints(e.points[n].x,e.points[n].y),e.points[n].x=a.x,e.points[n].y=a.y}var s={selPointColl:null};e.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:s}});for(var o=0,i=e.freehandCounter;o<i;o++)if(s.selPointColl[o]&&s.selPointColl[o].points)for(var r=s.selPointColl[o].points.length,a=void 0,n=0;n<r;n++)a=this.straightenPoints(s.selPointColl[o].points[n].x,s.selPointColl[o].points[n].y),s.selPointColl[o].points[n].x=a.x,s.selPointColl[o].points[n].y=a.y;var l={straightenPoint:null};if(e.notify("freehand-draw",{prop:"getStraightenPoint",onPropertyChange:!1,value:{obj:l}}),l.straightenPoint.x&&l.straightenPoint.y){var p={angle:0};e.notify("freehand-draw",{prop:"getStraightenPointAngle",onPropertyChange:!1,value:{obj:p}});var h=((360===e.transform.straighten?0:e.transform.straighten)-p.angle)*(Math.PI/180),a=this.straightenPoints(l.straightenPoint.x,l.straightenPoint.y,h);0===h&&(a.x=l.straightenPoint.x,a.y=l.straightenPoint.y),e.notify("freehand-draw",{prop:"setStraightenPoint",onPropertyChange:!1,value:{x:a.x,y:a.y}})}},o.prototype.straightenPoints=function(e,t,o){var i=this.parent,r={x:i.img.destLeft+i.img.destWidth/2,y:i.img.destTop+i.img.destHeight/2};return o=o||i.transform.straighten*(Math.PI/180),{x:Math.cos(o)*(e-r.x)-Math.sin(o)*(t-r.y)+r.x,y:Math.sin(o)*(e-r.x)+Math.cos(o)*(t-r.y)+r.y}},o.prototype.straightenShapes=function(){var e=this.parent,t=e.img,o=t.destLeft,i=t.destTop,r=t.destWidth,a=t.destHeight;if({bool:e.isStraightening}.bool&&0!==e.transform.straighten){e.notify("draw",{prop:"updateImgCanvasPoints"});var n={points:null};e.notify("draw",{prop:"getImageCanvasPoints",value:{obj:n}});var s={x:o+r/2,y:i+a/2},l=-e.transform.straighten*(Math.PI/180),p={x:Math.cos(l)*(n.points[0].x-s.x)-Math.sin(l)*(n.points[0].y-s.y)+s.x,y:Math.sin(l)*(n.points[0].x-s.x)+Math.cos(l)*(n.points[0].y-s.y)+s.y},h={x:Math.cos(l)*(n.points[1].x-s.x)-Math.sin(l)*(n.points[1].y-s.y)+s.x,y:Math.sin(l)*(n.points[1].x-s.x)+Math.cos(l)*(n.points[1].y-s.y)+s.y},d={x:Math.cos(l)*(n.points[2].x-s.x)-Math.sin(l)*(n.points[2].y-s.y)+s.x,y:Math.sin(l)*(n.points[2].x-s.x)+Math.cos(l)*(n.points[2].y-s.y)+s.y};e.img.destWidth=h.x-p.x,e.img.destHeight=d.y-h.y,e.img.destLeft=p.x,e.img.destTop=p.y}},o.prototype.straightenShapePoints=function(e,t){var o=this.parent,i=o.img,r=i.destLeft,a=i.destTop,n=i.destWidth,s=i.destHeight;if({bool:o.isStraightening}.bool&&("line"===e.shape||"arrow"===e.shape)){e.activePoint.width=e.activePoint.endX>e.activePoint.startX?e.activePoint.endX-e.activePoint.startX:e.activePoint.startX-e.activePoint.endX,e.activePoint.height=e.activePoint.endY>e.activePoint.startY?e.activePoint.endY-e.activePoint.startY:e.activePoint.startY-e.activePoint.endY;var l={x:r+n/2,y:a+s/2},p=(t?-o.transform.straighten:o.transform.straighten)*(Math.PI/180),h={x:Math.cos(p)*(e.activePoint.startX-l.x)-Math.sin(p)*(e.activePoint.startY-l.y)+l.x,y:Math.sin(p)*(e.activePoint.startX-l.x)+Math.cos(p)*(e.activePoint.startY-l.y)+l.y},d={x:Math.cos(p)*(e.activePoint.endX-l.x)-Math.sin(p)*(e.activePoint.endY-l.y)+l.x,y:Math.sin(p)*(e.activePoint.endX-l.x)+Math.cos(p)*(e.activePoint.endY-l.y)+l.y};e.activePoint.startX=h.x,e.activePoint.startY=h.y,e.activePoint.endX=d.x,e.activePoint.endY=d.y,e.activePoint.width=e.activePoint.endX>e.activePoint.startX?e.activePoint.endX-e.activePoint.startX:e.activePoint.startX-e.activePoint.endX,e.activePoint.height=e.activePoint.endY>e.activePoint.startY?e.activePoint.endY-e.activePoint.startY:e.activePoint.startY-e.activePoint.endY,o.notify("selection",{prop:"adjustActObjForLineArrow",onPropertyChange:!1,value:{obj:e}})}},o.prototype.redrawObj=function(e){var t=this.parent,o=!1;if(t.objColl.length>0)if("horizontal"===e||"vertical"===e||"Horizontal"===e||"Vertical"===e||"horizontalVertical"===e||"verticalHorizontal"===e)this.updateCurrentActiveObjPoint(e.toLowerCase());else if("number"==typeof e){this.updateCurrentActiveObjPoint(e);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 r=0,a=t.objColl.length;r<a;r++)"crop"!==t.objColl[r].shape.split("-")[0]&&(this.apply(t.objColl[r].shape,t.objColl[r]),o=!0);o&&t.notify("draw",{prop:"applyFrame",value:{ctx:this.lowerContext,frame:t.frameObj.type,preventImg:!0}}),this.lowerContext.filter=i}},o.prototype.updateCurrentActiveObjPoint=function(e){for(var o,i=this.parent,r=i.img,a=r.destLeft,n=r.destTop,s=r.destWidth,l=r.destHeight,p=0,h=i.objColl.length;p<h;p++){var d=i.objColl[p];if(i.activeObj.shape===d.shape&&i.activeObj.activePoint.startX===d.activePoint.startX&&i.activeObj.activePoint.startY===d.activePoint.startY&&i.activeObj.activePoint.endX===d.activePoint.endX&&i.activeObj.activePoint.endY===d.activePoint.endY&&i.activeObj.currIndex===d.currIndex){o=p;break}}if("horizontal"===e||"vertical"===e||"Horizontal"===e||"Vertical"===e||"horizontalvertical"===e||"verticalhorizontal"===e){if("horizontal"===e||"Horizontal"===e)for(var c=0,h=i.objColl.length;c<h;c++)(d=i.objColl[c]).shapeFlip!==i.transform.currFlipState&&(d.activePoint.startX<=a+s/2?(d.activePoint.endX=a+s-(d.activePoint.startX-a),d.activePoint.startX=d.activePoint.endX-d.activePoint.width,i.notify("draw",{prop:"updateActiveObject",onPropertyChange:!1,value:{actPoint:d.activePoint,obj:d}})):d.activePoint.startX>=a+s/2&&(d.activePoint.startX=a+(a+s-d.activePoint.endX),d.activePoint.endX=d.activePoint.startX+d.activePoint.width,i.notify("draw",{prop:"updateActiveObject",onPropertyChange:!1,value:{actPoint:d.activePoint,obj:d}})),"line"===d.shape||"arrow"===d.shape||"path"===d.shape?this.flipLineArrowObj(d,"horizontal"):0!==d.rotatedAngle&&(d.rotatedAngle=d.rotatedAngle+2*(Math.PI-d.rotatedAngle),d.rotationCirclePointColl.x<=a+s/2?d.rotationCirclePointColl.x=a+s-(d.rotationCirclePointColl.x-a):d.rotationCirclePointColl.x>=a+s/2&&(d.rotationCirclePointColl.x=a+(a+s-d.rotationCirclePointColl.x)),d.rotationCirclePointColl.ratioX=(d.rotationCirclePointColl.x-a)/s),d.shapeFlip=i.transform.currFlipState,d.imageRatio={startX:(d.activePoint.startX-a)/s,startY:(d.activePoint.startY-n)/l,endX:(d.activePoint.endX-a)/s,endY:(d.activePoint.endY-n)/l,width:s/d.activePoint.width,height:l/d.activePoint.height});else if("vertical"===e||"Vertical"===e)for(c=0;c<i.objColl.length;c++)(d=i.objColl[c]).shapeFlip!==i.transform.currFlipState&&(d.activePoint.startY<=n+l/2?(d.activePoint.endY=n+l-(d.activePoint.startY-n),d.activePoint.startY=d.activePoint.endY-d.activePoint.height,i.notify("draw",{prop:"updateActiveObject",onPropertyChange:!1,value:{actPoint:d.activePoint,obj:d}})):d.activePoint.startY>=i.lowerCanvas.height/2&&(d.activePoint.startY=n+(n+l-d.activePoint.endY),d.activePoint.endY=d.activePoint.startY+d.activePoint.height,i.notify("draw",{prop:"updateActiveObject",onPropertyChange:!1,value:{actPoint:d.activePoint,obj:d}})),"line"===d.shape||"arrow"===d.shape||"path"===d.shape?this.flipLineArrowObj(d,"vertical"):0!==d.rotatedAngle&&(d.rotatedAngle=-d.rotatedAngle,d.rotationCirclePointColl.y<=n+l/2?d.rotationCirclePointColl.y=n+l-(d.rotationCirclePointColl.y-n):d.rotationCirclePointColl.y>=n+l/2&&(d.rotationCirclePointColl.y=n+(n+l-d.rotationCirclePointColl.y)),d.rotationCirclePointColl.ratioY=(d.rotationCirclePointColl.y-n)/l),d.shapeFlip=i.transform.currFlipState,d.imageRatio={startX:(d.activePoint.startX-a)/s,startY:(d.activePoint.startY-n)/l,endX:(d.activePoint.endX-a)/s,endY:(d.activePoint.endY-n)/l,width:s/d.activePoint.width,height:l/d.activePoint.height});else if("verticalhorizontal"===e||"horizontalvertical"===e)for(var c=0,h=i.objColl.length;c<h;c++)(d=i.objColl[c]).shapeFlip!==i.transform.currFlipState&&(d.activePoint.startX<=a+s/2?(d.activePoint.endX=a+s-(d.activePoint.startX-a),d.activePoint.startX=d.activePoint.endX-d.activePoint.width,i.notify("draw",{prop:"updateActiveObject",onPropertyChange:!1,value:{actPoint:d.activePoint,obj:d}})):d.activePoint.startX>=a+s/2&&(d.activePoint.startX=a+(a+s-d.activePoint.endX),d.activePoint.endX=d.activePoint.startX+d.activePoint.width,i.notify("draw",{prop:"updateActiveObject",onPropertyChange:!1,value:{actPoint:d.activePoint,obj:d}})),d.activePoint.startY<=n+l/2?(d.activePoint.endY=n+l-(d.activePoint.startY-n),d.activePoint.startY=d.activePoint.endY-d.activePoint.height,i.notify("draw",{prop:"updateActiveObject",onPropertyChange:!1,value:{actPoint:d.activePoint,obj:d}})):d.activePoint.startY>=i.lowerCanvas.height/2&&(d.activePoint.startY=n+(n+l-d.activePoint.endY),d.activePoint.endY=d.activePoint.startY+d.activePoint.height,i.notify("draw",{prop:"updateActiveObject",onPropertyChange:!1,value:{actPoint:d.activePoint,obj:d}})),"line"!==d.shape&&"arrow"!==d.shape&&"path"!==d.shape||this.flipLineArrowObj(d,e),d.shapeFlip=i.transform.currFlipState,d.imageRatio={startX:(d.activePoint.startX-a)/s,startY:(d.activePoint.startY-n)/l,endX:(d.activePoint.endX-a)/s,endY:(d.activePoint.endY-n)/l,width:s/d.activePoint.width,height:l/d.activePoint.height});void 0!==o&&(i.activeObj=t.extend({},i.objColl[o],{},!0))}else if(90===e)this.rotateObjColl();else if(-90===e)for(c=0;c<3;c++)this.rotateObjColl();else if("number"==typeof e)if(e>0)this.rotateObjColl();else for(c=0;c<3;c++)this.rotateObjColl()},o.prototype.rotateObjColl=function(){for(var e=this.parent,t=e.img,o=t.destWidth,i=t.destHeight,r=t.destLeft,a=t.destTop,n=0,s=e.objColl.length;n<s;n++){var l=(p=e.objColl[n]).shape;p.activePoint.startY=a+i*p.imageRatio.startX,p.activePoint.endY=a+i*p.imageRatio.endX,p.activePoint.startX=r+o-o*p.imageRatio.endY,p.activePoint.endX=r+o-o*p.imageRatio.startY,p=this.updateWidthHeight(e.objColl[n]),this.updateFontSize(p),"line"===l||"arrow"===l||"path"===l?(this.rotateLineArrowObj(p),"arrow"===l&&this.updateArrowSize(p)):0!==p.rotatedAngle&&(p.rotationCirclePointColl.y=a+i*p.rotationCirclePointColl.ratioX,p.rotationCirclePointColl.x=r+o-o*p.rotationCirclePointColl.ratioY,p.rotationCirclePointColl.ratioX=(p.rotationCirclePointColl.x-r)/o,p.rotationCirclePointColl.ratioY=(p.rotationCirclePointColl.y-a)/i)}for(var n=0,s=e.objColl.length;n<s;n++)e.notify("draw",{prop:"updateActiveObject",onPropertyChange:!1,value:{actPoint:e.objColl[n].activePoint,obj:e.objColl[n]}});for(var n=0,s=e.objColl.length;n<s;n++){var p=e.objColl[n];p.imageRatio={startX:(p.activePoint.startX-r)/o,startY:(p.activePoint.startY-a)/i,endX:(p.activePoint.endX-r)/o,endY:(p.activePoint.endY-a)/i,width:o/p.activePoint.width,height:i/p.activePoint.height}}},o.prototype.rotateLineArrowObj=function(e){if(!t.isNullOrUndefined(e.pointColl)){var o=this.parent.img,i=o.destWidth,r=o.destHeight,a=o.destLeft,n=o.destTop;if(e.pointColl.length>0){for(s=0;s<e.pointColl.length;s++)e.pointColl[s].y=n+r*e.pointColl[s].ratioX,e.pointColl[s].x=a+i-i*e.pointColl[s].ratioY;for(var s=0;s<e.pointColl.length;s++)e.pointColl[s].ratioX=(e.pointColl[s].x-a)/i,e.pointColl[s].ratioY=(e.pointColl[s].y-n)/r;var l=void 0;l=t.isNullOrUndefined(e.pointColl[e.pointColl.length-2])?{x:0,y:0}:{x:e.pointColl[e.pointColl.length-2].x,y:e.pointColl[e.pointColl.length-2].y};var p=e.pointColl[e.pointColl.length-1].x-l.x,h=e.pointColl[e.pointColl.length-1].y-l.y;e.activePoint.startX=e.pointColl[0].x,e.activePoint.startY=e.pointColl[0].y,e.activePoint.endX=e.pointColl[e.pointColl.length-1].x+p/2,e.activePoint.endY=e.pointColl[e.pointColl.length-1].y+h/2,e=this.updateWidthHeight(e)}}},o.prototype.flipLineArrowObj=function(e,o){if(o=o.toLowerCase(),!t.isNullOrUndefined(e.pointColl)&&("horizontal"===o?this.lineArrowHorizontalFlip(e):"vertical"===o?this.lineArrowVerticalFlip(e):(this.lineArrowHorizontalFlip(e),e.shapeFlip="",this.lineArrowVerticalFlip(e)),e.activePoint.startX=e.pointColl[0].x,e.activePoint.startY=e.pointColl[0].y,e.activePoint.endX=e.pointColl[e.pointColl.length-1].x,e.activePoint.endY=e.pointColl[e.pointColl.length-1].y,e.activePoint.startX>e.activePoint.endX)){var i=e.activePoint.startX;e.activePoint.startX=e.activePoint.endX,e.activePoint.endX=i,i=e.activePoint.startY,e.activePoint.startY=e.activePoint.endY,e.activePoint.endY=i}},o.prototype.lineArrowHorizontalFlip=function(e){var t=this.parent,o=t.img,i=o.destWidth,r=o.destHeight,a=o.destLeft,n=o.destTop;if(e.shapeFlip!==t.transform.currFlipState){for(var s=0,l=e.pointColl.length;s<l;s++){var p=e.pointColl[s];p.x<=a+i/2?p.x=a+i-(p.x-a):p.x>=a+i/2&&(p.x=a+(a+i-p.x)),p.ratioX=(p.x-a)/i,p.ratioY=(p.y-n)/r}if("arrow"===e.shape){var h=e.start;e.start=e.end,e.end=h}e.shapeFlip=t.transform.currFlipState}},o.prototype.lineArrowVerticalFlip=function(e){var t=this.parent,o=t.img,i=o.destWidth,r=o.destHeight,a=o.destLeft,n=o.destTop;if(e.shapeFlip!==t.transform.currFlipState){for(var s=0,l=e.pointColl.length;s<l;s++){var p=e.pointColl[s];p.y<=n+r/2?p.y=n+r-(p.y-n):p.y>=n+r/2&&(p.y=n+(n+r-p.y)),p.ratioX=(p.x-a)/i,p.ratioY=(p.y-n)/r}e.shapeFlip=t.transform.currFlipState}},o.prototype.getRotDegOfShape=function(e){var t;return(t=0===e.shapeDegree?this.parent.transform.degree:this.parent.transform.degree-e.shapeDegree)<0&&(t=360+t),t},o.prototype.renderTextArea=function(e,t,o){var i=this.parent,r=this.getRotDegOfShape(i.activeObj);this.transformTextArea(),i.notify("toolbar",{prop:"destroy-qa-toolbar",onPropertyChange:!1});var a=i.element.querySelector("#"+i.element.id+"_zOrderBtn"),n=i.element.querySelector("#"+i.element.id+"_duplicate"),s=i.element.querySelector("#"+i.element.id+"_remove"),l=i.element.querySelector("#"+i.element.id+"_editText"),p=o.strokeSettings.outlineColor,h=o.strokeSettings.outlineWidth,d=[];a&&a.classList.add("e-overlay"),n&&n.classList.add("e-overlay"),s&&s.classList.add("e-overlay"),l&&l.classList.add("e-overlay"),""!==o.strokeSettings.fillColor?i.textArea.style.backgroundColor=o.strokeSettings.fillColor:i.textArea.style.backgroundColor="transparent",i.textArea.style.display="block",i.textArea.style.left=e+"px",i.textArea.style.top=t+"px",i.textArea.style.fontFamily=o.textSettings.fontFamily,i.textArea.style.fontSize=o.textSettings.fontSize+"px",i.textArea.style.color=o.strokeSettings.strokeColor;var c=o.textSettings.fontSize,u=Math.max(1,h/2)*(.5*Math.floor((c-1)/16)+.5);if(/^#([0-9A-Fa-f]{3}|[0-9A-Fa-f]{6}|[0-9A-Fa-f]{8})$|^[a-zA-Z]+$/.test(o.strokeSettings.outlineColor)){for(var v=-u;v<=u;v++)for(var g=-u;g<=u;g++)0===v&&0===g||d.push(v/2+"px "+g/2+"px 0 "+p);i.textArea.style.textShadow=d.join(", ")}else i.textArea.style.textShadow=null;i.textArea.style.fontWeight=o.textSettings.bold?"bold":"normal",i.textArea.style.fontStyle=o.textSettings.italic?"italic":"normal",i.textArea.style.border="2px solid "+i.themeColl[i.theme].primaryColor,i.textArea.value=o.keyHistory,i.textArea.style.overflow="hidden",i.textArea.style.width="auto",i.textArea.style.height="auto",i.textArea.focus();var f=o.activePoint,C=f.width,b=f.height;r%90==0&&r%180!=0&&0!==r?(i.textArea.style.width=b+.25*b+"px",i.textArea.style.height=C+.25*C+"px"):(i.textArea.style.width=C+.25*C+"px",i.textArea.style.height=b+.25*b+"px"),this.setTextBoxWidth();var m={flipColl:null};if(i.notify("transform",{prop:"getFlipColl",onPropertyChange:!1,value:{obj:m}}),m.flipColl.length<=1&&this.setTextBoxHeight(),parseFloat(i.textArea.style.maxHeight)<i.activeObj.textSettings.fontSize&&(i.textArea.style.maxHeight=i.activeObj.textSettings.fontSize+"px"),r%90==0&&r%180!=0?parseFloat(i.textArea.style.left)+parseFloat(i.textArea.style.width)>i.img.destTop+i.img.destHeight&&this.alignTextAreaIntoCanvas():parseFloat(i.textArea.style.left)+parseFloat(i.textArea.style.width)>i.img.destLeft+i.img.destWidth&&this.alignTextAreaIntoCanvas(),0!==o.rotatedAngle){var y=parseFloat(i.textArea.style.left),P=parseFloat(i.textArea.style.top);if(o.flipObjColl.length>0){var j={panRegion:""},x=i.lowerCanvas,w=x.clientWidth,O=x.clientHeight,S={x:0,y:0};i.notify("crop",{prop:"getCurrFlipState",onPropertyChange:!1,value:{panObj:j}}),""!==j.panRegion&&("horizontal"===j.panRegion?(S.x=w-w/2,y=S.x-y+S.x):"vertical"===j.panRegion?(S.y=O-O/2,P=S.y-P+S.y):(y=(S={x:w-w/2,y:O-O/2}).x-y+S.x,P=S.y-P+S.y))}var T=y+parseFloat(i.textArea.style.width),k=P+parseFloat(i.textArea.style.height),F=parseFloat(i.textArea.style.width),I=parseFloat(i.textArea.style.height),A={x:T-F/2,y:k-I/2},z=Math.cos(o.rotatedAngle),R=Math.sin(o.rotatedAngle),D={x:z*(T-A.x)-R*(k-A.y)+A.x,y:R*(T-A.x)+z*(k-A.y)+A.y};if(D.x>i.img.destLeft&&D.x<i.img.destLeft+i.img.destWidth&&D.y>i.img.destTop&&D.y+parseFloat(i.textArea.style.fontSize)<i.img.destTop+i.img.destHeight)i.textArea.style.width=i.textArea.style.width;else for(var X=0,L=parseFloat(i.textArea.style.width);;)if(X++,F-=1,T=y+F,A={x:T-F/2,y:k-I/2},(D={x:z*(T-A.x)-R*(k-A.y)+A.x,y:R*(T-A.x)+z*(k-A.y)+A.y}).x>i.img.destLeft&&D.x<i.img.destLeft+i.img.destWidth&&D.y>i.img.destTop&&D.y+parseFloat(i.textArea.style.fontSize)<i.img.destTop+i.img.destHeight||X===L){i.textArea.style.width=F+"px";break}}i.notify("selection",{prop:"clearUpperCanvas",onPropertyChange:!1})},o.prototype.setTextBoxWidth=function(e){var o=this.parent;if(0!==o.activeObj.rotatedAngle)return o.textArea.style.whiteSpace="nowrap",o.textArea.style.textOverflow="ellipsis",void(o.textArea.style.display="inline-block");o.textArea.style.whiteSpace="",o.textArea.style.textOverflow="","inline-block"===o.textArea.style.display&&(o.textArea.style.display="block");var i=this.getMaxText(!0);"block"===o.textArea.style.display||"inline-block"===o.textArea.style.display?this.updateFontStyles(!0):this.updateFontStyles();var r=this.upperContext.measureText(i).width+parseFloat(o.textArea.style.fontSize)/2,a=e?this.upperContext.measureText(String.fromCharCode(e.which)).width:0,n=t.extend({},o.activeObj,{},!0),s="",l=this.getRotDegOfShape(n);if(s=n.shapeFlip!==o.transform.currFlipState?"":o.transform.currFlipState,e&&parseFloat(o.textArea.style.width)<r+a||t.isNullOrUndefined(e))if(0===l)"horizontal"===s.toLowerCase()?parseFloat(o.textArea.style.left)-o.img.destLeft-r-a>0&&(o.textArea.style.width=r+a+"px"):o.img.destWidth-(parseFloat(o.textArea.style.left)-o.img.destLeft)>r+a&&(o.textArea.style.width=r+a+"px");else if(90===l)"vertical"===s.toLowerCase()?parseFloat(o.textArea.style.top)-o.img.destTop-r-a>0&&(o.textArea.style.width=r+a+"px"):o.img.destHeight-(parseFloat(o.textArea.style.top)-o.img.destTop)>r+a&&(o.textArea.style.width=r+a+"px");else if(180===l){var p=parseFloat(o.textArea.style.left),h=o.img.destLeft;"horizontal"===s.toLowerCase()?o.img.destWidth-(p-h)>r+a&&(o.textArea.style.width=r+a+"px"):p-h-r-a>0&&(o.textArea.style.width=r+a+"px")}else if(270===l){var d=parseFloat(o.textArea.style.top),c=o.img.destTop;"vertical"===s.toLowerCase()?o.img.destHeight-(d-c)>r+a&&(o.textArea.style.width=r+a+"px"):d-c-r-a>0&&(o.textArea.style.width=r+a+"px")}},o.prototype.setTextBoxHeight=function(){var e,o=this.parent,i=t.extend({},o.activeObj,{},!0),r="",a=this.getRotDegOfShape(i);switch(r=i.textFlip===o.transform.currFlipState?"":""===i.textFlip?o.transform.currFlipState:i.textFlip,a){case 0:"vertical"===r.toLowerCase()?o.textArea.style.maxHeight=o.img.destHeight-(o.img.destHeight-parseFloat(o.textArea.style.top))+"px":(e=parseFloat(o.textArea.style.top)-o.img.destTop,o.textArea.style.maxHeight=o.img.destHeight-e+"px");break;case 90:"horizontal"===r.toLowerCase()?o.textArea.style.maxHeight=o.img.destWidth-(parseFloat(o.textArea.style.left)-o.img.destLeft)+"px":o.textArea.style.maxHeight=parseFloat(o.textArea.style.left)-o.img.destLeft+"px";break;case 180:"vertical"===r.toLowerCase()?(e=parseFloat(o.textArea.style.top)-o.img.destTop,o.textArea.style.maxHeight=o.img.destHeight-e+"px"):o.textArea.style.maxHeight=parseFloat(o.textArea.style.top)-o.img.destTop+"px";break;case 270:"horizontal"===r.toLowerCase()?o.textArea.style.maxHeight=parseFloat(o.textArea.style.left)-o.img.destLeft+"px":o.textArea.style.maxHeight=o.img.destWidth-(parseFloat(o.textArea.style.left)-o.img.destLeft)+"px"}},o.prototype.updatePathRatio=function(e){for(var t=this.parent,o=0,i=e.pointColl.length;o<i;o++){var r=e.pointColl[o];r.ratioX=(r.x-t.img.destLeft)/t.img.destWidth,r.ratioY=(r.y-t.img.destTop)/t.img.destHeight}},o.prototype.stopPathDrawing=function(e,o){var i=this.parent;if("path"===i.activeObj.shape){var r={shape:null};if(i.notify("selection",{prop:"getCurrentDrawingShape",value:{obj:r}}),"path"===r.shape){var a=t.extend({},i.cropObj,{},!0),n={currObj:{}};i.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:n}});var s=n.currObj;s.objColl=t.extend([],i.objColl,[],!0),s.pointColl=t.extend([],i.pointColl,[],!0),s.afterCropActions=t.extend([],i.afterCropActions,[],!0);var l={selPointColl:null};if(i.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:l}}),s.selPointColl=t.extend([],l.selPointColl,[],!0),i.notify("selection",{prop:"setCurrentDrawingShape",value:{value:""}}),i.currObjType.isDragging=!1,e&&"touchstart"!==e.type&&t.isNullOrUndefined(o)&&i.activeObj.pointColl.pop(),this.updatePathRatio(i.activeObj),t.isNullOrUndefined(i.activeObj.imageRatio)&&i.notify("shape",{prop:"updImgRatioForActObj",onPropertyChange:!1}),i.objColl.push(i.activeObj),i.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"shapeTransform",previousObj:s,previousObjColl:s.objColl,previousPointColl:s.pointColl,previousSelPointColl:s.selPointColl,previousCropObj:a,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),i.objColl.pop(),e&&(i.notify("selection",{prop:"mouseUpEventHandler",value:{e:e}}),this.lowerContext.clearRect(0,0,i.lowerCanvas.width,i.lowerCanvas.height),i.notify("draw",{prop:"redrawImgWithObj",onPropertyChange:!1}),i.objColl.length>0)){var p=i.activeObj.activePoint,h=i.objColl[i.objColl.length-1].activePoint;Math.floor(p.startX)===Math.floor(h.startX)&&Math.floor(p.startY)===Math.floor(h.startY)&&Math.floor(p.endX)===Math.floor(h.endX)&&Math.floor(p.endY)===Math.floor(h.endY)&&this.refreshActiveObj()}if(i.notify("draw",{prop:"setNewPath",value:{bool:!0}}),i.objColl[i.objColl.length-1]){var d=i.drawingShape;i.notify("selection",{prop:"setCurrentDrawingShape",value:{value:""}}),i.noRedact=!0,i.selectShape(i.objColl[i.objColl.length-1].currIndex),i.notify("selection",{prop:"setCurrentDrawingShape",value:{value:"path"}}),i.drawingShape=d}i.notify("toolbar",{prop:"renderQAT",onPropertyChange:!1,value:{isPenEdit:null}});var c={shapeSettingsObj:{}};i.notify("selection",{prop:"updatePrevShapeSettings",onPropertyChange:!1,value:{obj:c}});var u=c.shapeSettingsObj,v={cancel:!1,action:"draw-end",previousShapeSettings:u},g={cancel:!1,action:"move",previousShapeSettings:u};i.notify("selection",{prop:"triggerShapeChange",onPropertyChange:!1,value:{shapeResizingArgs:v,shapeMovingArgs:g,type:"mouse-up"}}),i.notify("undo-redo",{prop:"updateUndoRedoStack",onPropertyChange:!1})}}},o.prototype.findTextTarget=function(e){var o=this.parent;if(e){if("text"!==o.activeObj.shape){if("path"===o.activeObj.shape)return void this.stopPathDrawing(e,null);if("dblclick"!==e.type)return;o.notify("selection",{prop:"setPanDown",onPropertyChange:!1,value:{panDown:null}});var i=t.extend({},o.activeObj,{},!0),r=t.extend([],o.objColl,[],!0),a={bool:null};if(o.notify("selection",{prop:"findTargetObj",onPropertyChange:!1,value:{x:e.clientX,y:e.clientY,isCrop:!1,obj:a}}),o.objColl=r,!a.bool||"text"!==o.activeObj.shape)return void(o.activeObj=t.extend({},i,{},!0))}var n,s;if("dblclick"===e.type?(n=e.clientX,s=e.clientY):"touchstart"===e.type&&(n=e.touches[0].clientX,s=e.touches[0].clientY,o.notify("selection",{prop:"setTouchEndPoint",onPropertyChange:!1,value:{x:e.touches[0].clientX,y:e.touches[0].clientY}})),o.notify("toolbar",{prop:"setPreventZoomBtn",onPropertyChange:!1,value:{isPrevent:!0}}),o.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"text",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}}),o.notify("toolbar",{prop:"setPreventZoomBtn",onPropertyChange:!1,value:{isPrevent:!1}}),o.notify("toolbar",{prop:"update-toolbar-items",onPropertyChange:!1}),t.isNullOrUndefined(n)||t.isNullOrUndefined(s))if("block"!==o.textArea.style.display&&"inline-block"!==o.textArea.style.display||""===this.selectedText()||"mousedown"!==e.type)"none"===o.textArea.style.display&&(o.textArea.style.display="block");else{d=o.textArea.value;o.textArea.value+="a",o.textArea.value=d}else{var l=o.lowerCanvas.getBoundingClientRect();n-=l.left,s-=l.top;var p="",h=this.getRotDegOfShape(o.activeObj);p=""===o.activeObj.textFlip?o.activeObj.textFlip===o.transform.currFlipState?"":o.transform.currFlipState:o.activeObj.textFlip===o.transform.currFlipState?"":""===o.transform.currFlipState?o.activeObj.textFlip:o.transform.currFlipState;var d=void 0;if("none"===o.textArea.style.display){d=t.extend({},o.activeObj,{},!0);for(var c=0;c<o.objColl.length;c++)JSON.stringify(o.activeObj)===JSON.stringify(o.objColl[c])&&o.objColl.splice(c,1);this.refreshActiveObj(),this.upperContext.clearRect(0,0,o.upperCanvas.width,o.upperCanvas.height),this.lowerContext.clearRect(0,0,o.upperCanvas.width,o.upperCanvas.height),o.notify("draw",{prop:"redrawImgWithObj",onPropertyChange:!1}),o.notify("draw",{prop:"redrawDownScale"}),o.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.lowerContext}}),o.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.upperContext}}),(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.activeObj=d,this.updateFontStyles();var u=t.extend({},o.activeObj,{},!0),v=u.topLeftCircle.radius,g=u.activePoint,f=g.startX,C=g.startY,b=g.endX,m=g.endY,y={x:f+g.width/2,y:C+g.height/2},P=Math.cos(u.rotatedAngle),j=Math.sin(u.rotatedAngle),x={x:P*(f-y.x)-j*(C-y.y)+y.x,y:j*(f-y.x)+P*(C-y.y)+y.y},w={x:P*(b-y.x)-j*(C-y.y)+y.x,y:j*(b-y.x)+P*(C-y.y)+y.y},O={x:P*(f-y.x)-j*(m-y.y)+y.x,y:j*(f-y.x)+P*(m-y.y)+y.y},S={x:P*(b-y.x)-j*(m-y.y)+y.x,y:j*(b-y.x)+P*(m-y.y)+y.y},a={position:null,x:n,y:s,x1:x.x,y1:x.y,x2:w.x,y2:w.y,x3:O.x,y3:O.y,x4:S.x,y4:S.y};if(o.notify("draw",{prop:"checkPointPosition",onPropertyChange:!1,value:{obj:a}}),0!==u.rotatedAngle&&("inside"===a.position||"on"===a.position)||0===u.rotatedAngle&&n>=u.activePoint.startX-2*v&&n<=u.activePoint.endX+2*v&&s>=u.activePoint.startY-2*v&&s<=u.activePoint.endY+2*v){if(this.upperContext.clearRect(0,0,o.upperCanvas.width,o.upperCanvas.height),4===u.flipObjColl.length&&(u.flipObjColl=[],p="",u.shapeFlip=""),""===p&&u.flipObjColl.length>1&&(p=u.flipObjColl[u.flipObjColl.length-1]),u.flipObjColl.length<=1)n=(T=this.setTextBoxPos(u,h,p,n,s)).x,s=T.y;else{var T=this.setTextBoxPoints(u,h,p,n,s);n=T.x,s=T.y}if(0!==o.activeObj.rotatedAngle){var k=this.getTextBoxPosition(o.activeObj);n=k.x,s=k.y,n=(k=this.setFlipState(n,s,o.activeObj)).x,s=k.y}this.renderTextArea(n,s,u)}else this.applyActObj()}}}},o.prototype.getTextBoxPosition=function(e,t){var o={x:0,y:0},i=e.activePoint,r=i.startX,a=i.startY,n=i.endX,s=i.endY,l={x:r+i.width/2,y:a+i.height/2},p=Math.cos(e.rotatedAngle),h=Math.sin(e.rotatedAngle),d={x:p*(r-l.x)-h*(a-l.y)+l.x,y:h*(r-l.x)+p*(a-l.y)+l.y},c={x:p*(n-l.x)-h*(a-l.y)+l.x,y:h*(n-l.x)+p*(a-l.y)+l.y},u={x:p*(r-l.x)-h*(s-l.y)+l.x,y:h*(r-l.x)+p*(s-l.y)+l.y},v={x:p*(n-l.x)-h*(s-l.y)+l.x,y:h*(n-l.x)+p*(s-l.y)+l.y},g=this.getRotDegOfShape(e);return 0===g||360===g?o={x:d.x,y:d.y}:90===g||-270===g?o={x:c.x,y:c.y}:180===g||-180===g?o={x:v.x,y:v.y}:270!==g&&-90!==g||(o={x:u.x,y:u.y}),t&&(t.x=o.x,t.y=o.y),o},o.prototype.setFlipState=function(e,t,o,i){var r=this.parent,a={panRegion:""},n=r.lowerCanvas,s=n.clientWidth,l=n.clientHeight,p={x:0,y:0};return r.notify("crop",{prop:"getCurrFlipState",onPropertyChange:!1,value:{panObj:a}}),""!==a.panRegion&&("horizontal"===a.panRegion?(p.x=s-s/2,e=p.x-e+p.x):"vertical"===a.panRegion?(p.y=l-l/2,t=p.y-t+p.y):(e=(p={x:s-s/2,y:l-l/2}).x-e+p.x,t=p.y-t+p.y)),i&&(i.x=e,i.y=t),{x:e,y:t}},o.prototype.fileChanged=function(e){var t=e.target.files[0],o=t.name&&t.name.split(".").pop().toLowerCase();if(o&&-1===["jpg","jpeg","png","svg"].indexOf(o))return void this.refreshActiveObj();var i=window.URL.createObjectURL(e.target.files[0]);this.onLoadImgShape(null,null,null,null,i.toString(),!0),document.getElementById(this.parent.element.id+"_fileUpload").value=""},o.prototype.onLoadImgShape=function(e,t,o,i,r,a,n,s,l,p){var h=this,d=this.parent;"string"==typeof r?this.shapeImg.src=r:(d.inMemoryCanvas.width=r.width,d.inMemoryCanvas.height=r.height,d.inMemoryCanvas.getContext("2d").putImageData(r,0,0),this.shapeImg.src=d.inMemoryCanvas.toDataURL()),this.prevObjColl(),d.activeObj.shape="image",this.initShapeProps(),this.shapeImg.onload=function(){h.upperContext.drawImage(h.shapeImg,0,0,h.shapeImg.width,h.shapeImg.height),h.updateImgCanvas(a,e,t,o,i,n,s,l,p)}},o.prototype.updateImgCanvas=function(e,t,o,i,r,a,n,s,l){var p=this.parent;p.activeObj.imageElement=this.shapeImg,p.activeObj.imageCanvas=p.createElement("canvas");var h={width:0,height:0};if(p.notify("transform",{prop:"calcMaxDimension",onPropertyChange:!1,value:{width:this.shapeImg.width,height:this.shapeImg.height,obj:h,isImgShape:null}}),i&&r)if(n){var d={ratio:null};p.notify("selection",{prop:"findImageRatio",onPropertyChange:!1,value:{width:this.shapeImg.width,height:this.shapeImg.height,obj:d}}),h=this.resizeImage(i,d.ratio)}else h={width:i,height:r};if(this.updateObj(h,t,o),p.notify("draw",{prop:"downScaleImgCanvas",onPropertyChange:!1,value:{ctx:p.activeObj.imageCanvas.getContext("2d"),isImgAnnotation:!0,isHFlip:null,isVFlip:null}}),p.notify("transform",{prop:"calcMaxDimension",onPropertyChange:!1,value:{width:this.shapeImg.width,height:this.shapeImg.height,obj:h,isImgShape:!0}}),i&&r)if(n){var c={ratio:null};p.notify("selection",{prop:"findImageRatio",onPropertyChange:!1,value:{width:this.shapeImg.width,height:this.shapeImg.height,obj:c}}),h=this.resizeImage(i,c.ratio)}else h={width:i,height:r};null!==s&&void 0!==s&&(p.activeObj.opacity=s),this.updateObj(h,t,o),p.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate"}}),this.shapeImg=null,a&&(p.activeObj.rotatedAngle=a*(Math.PI/180),p.notify("selection",{prop:"updPtCollForShpRot",onPropertyChange:!1,value:{obj:p.activeObj}}));var u={shapeSettingsObj:{}};p.notify("selection",{prop:"updatePrevShapeSettings",onPropertyChange:!1,value:{obj:u}});var v=u.shapeSettingsObj,g={cancel:!1,action:"insert",previousShapeSettings:v,currentShapeSettings:v};p.trigger("shapeChanging",g),p.editCompleteArgs=g,e=e||l,this.drawShapeImageEvent(g,e),p.isPublicMethod&&!l?p.notify("undo-redo",{prop:"updateUndoRedo",onPropertyChange:!1}):p.isPublicMethod||p.notify("undo-redo",{prop:"updateUndoRedoStack",onPropertyChange:!1}),p.isPublicMethod=!1},o.prototype.updateObj=function(e,t,o){var i=this.parent;i.activeObj.activePoint.width=e.width,i.activeObj.activePoint.height=e.height,i.activeObj.activePoint.startX=t||i.lowerCanvas.width/2-e.width/2,i.activeObj.activePoint.startY=o||i.lowerCanvas.height/2-e.height/2,i.activeObj.activePoint.endX=i.activeObj.activePoint.startX+e.width,i.activeObj.activePoint.endY=i.activeObj.activePoint.startY+e.height},o.prototype.resizeImage=function(e,t){var o=t.split(":"),i=parseInt(o[0],10),r=parseInt(o[1],10);return{width:e,height:Math.round(e*r/i)}},o.prototype.setTextBoxPos=function(e,t,o,i,r){var a={x:i,y:r},n=e.activePoint,s=n.startX,l=n.startY,p=n.endX,h=n.endY;switch(o=o.toLowerCase(),t){case 0:"horizontal"===o?(a.x=p,a.y=l):"vertical"===o?(a.x=s,a.y=h):(a.x=s,a.y=l);break;case 90:"horizontal"===o?(a.x=s,a.y=l):"vertical"===o?(a.x=p,a.y=h):(a.x=p,a.y=l);break;case 180:"horizontal"===o?(a.x=s,a.y=h):"vertical"===o?(a.x=p,a.y=l):(a.x=p,a.y=h);break;case 270:"horizontal"===o?(a.x=p,a.y=h):"vertical"===o?(a.x=s,a.y=l):(a.x=s,a.y=h)}return a},o.prototype.setTextBoxPoints=function(e,t,o,i,r){var a={x:i,y:r},n=e.activePoint,s=n.startX,l=n.startY,p=n.endX,h=n.endY;switch(o=o.toLowerCase(),t){case 0:e.flipObjColl[0]&&"horizontal"===e.flipObjColl[0].toLowerCase()?"horizontal"===o?(a.x=s,a.y=l):"vertical"===o&&(a.x=p,a.y=h):"horizontal"===o?(a.x=p,a.y=h):"vertical"===o&&(a.x=p,a.y=l);break;case 90:e.flipObjColl[0]&&"horizontal"===e.flipObjColl[0].toLowerCase()?"horizontal"===o?(a.x=p,a.y=h):"vertical"===o&&(a.x=s,a.y=h):"horizontal"===o?(a.x=s,a.y=h):"vertical"===o&&(a.x=s,a.y=l);break;case 180:e.flipObjColl[0]&&"horizontal"===e.flipObjColl[0].toLowerCase()?"horizontal"===o?(a.x=s,a.y=l):"vertical"===o&&(a.x=s,a.y=l):"horizontal"===o?(a.x=s,a.y=l):"vertical"===o&&(a.x=s,a.y=h);break;case 270:e.flipObjColl[0]&&"horizontal"===e.flipObjColl[0].toLowerCase()?"horizontal"===o?(a.x=s,a.y=l):"vertical"===o&&(a.x=p,a.y=l):"horizontal"===o?(a.x=p,a.y=l):"vertical"===o&&(a.x=p,a.y=h)}return a},o.prototype.selectedText=function(){var e=this.parent,t=e.textArea.selectionStart,o=e.textArea.selectionEnd;return e.textArea.value.substring(t,o)},o.prototype.panObjColl=function(e,t,o){var i=this.parent;if(i.objColl.length>0){for(var r=0,a=i.objColl.length;r<a;r++){var n=i.objColl[r];if(""===o){if(n.activePoint.startX+=e,n.activePoint.endX+=e,n.rotationCirclePointColl&&(n.rotationCirclePointColl.x+=e),"path"===n.shape)for(var s=0,l=n.pointColl.length;s<l;s++)n.pointColl[s].x+=e;if(n.activePoint.startY+=t,n.activePoint.endY+=t,n.rotationCirclePointColl&&(n.rotationCirclePointColl.y+=t),"path"===n.shape)for(s=0;s<n.pointColl.length;s++)n.pointColl[s].y+=t}if(n=this.updateWidthHeight(n),i.notify("draw",{prop:"updateActiveObject",onPropertyChange:!1,value:{actPoint:n.activePoint,obj:n}}),"line"===n.shape||"arrow"===n.shape){n.pointColl=this.getLinePoints(n.activePoint.startX,n.activePoint.startY,n.activePoint.endX,n.activePoint.endY);for(var p=0,h=n.pointColl.length;p<h;p++)n.pointColl[p].ratioX=(n.pointColl[p].x-i.img.destLeft)/i.img.destWidth,n.pointColl[p].ratioY=(n.pointColl[p].y-i.img.destTop)/i.img.destHeight}this.refreshActiveObj()}var d=this.lowerContext.filter;this.lowerContext.filter="none",this.iterateObjColl(),this.lowerContext.filter=d,this.refreshActiveObj(),i.notify("draw",{prop:"applyFrame",value:{ctx:this.lowerContext,frame:i.frameObj.type,preventImg:!0}})}},o.prototype.updateFontStyles=function(e){var t=this.parent;this.upperContext.strokeStyle=t.activeObj.strokeSettings.strokeColor,this.upperContext.fillStyle=t.activeObj.strokeSettings.strokeColor;var o="";t.activeObj.textSettings.bold&&(o="bold "),t.activeObj.textSettings.italic&&(o="italic "),t.activeObj.textSettings.bold&&t.activeObj.textSettings.italic&&(o="italic bold ");var i=e?parseFloat(t.textArea.style.fontSize):t.activeObj.textSettings.fontSize,r="block"===t.textArea.style.display||"inline-block"===t.textArea.style.display?t.textArea.style.fontFamily:t.activeObj.textSettings.fontFamily;this.upperContext.font=o+i+"px "+r},o.prototype.applyFontStyle=function(e){var o=this.parent,i={shapeSettingsObj:{}};o.notify("selection",{prop:"updatePrevShapeSettings",onPropertyChange:!1,value:{obj:i}});var r=i.shapeSettingsObj;this.pushActItemIntoObj();var a=t.extend([],o.objColl,[],!0);switch(o.objColl.pop(),"none"===o.textArea.style.display?this.updateFontRatio(o.activeObj):this.updateFontRatio(o.activeObj,!0),e){case"default":this.updateFontStyle(e,a,"normal","normal");break;case"bold":this.updateFontStyle(e,a,"bold","normal");break;case"italic":this.updateFontStyle(e,a,"normal","italic");break;case"bolditalic":this.updateFontStyle(e,a,"bold","italic")}var n={action:"font-style",currentShapeSettings:t.extend({},r,{},!0)};n.currentShapeSettings.fontStyle=[e],o.trigger("shapeChange",n),o.editCompleteArgs=n},o.prototype.updateFontStyle=function(e,t,o,i){var r=this.parent,a=r.textArea.style;if("block"===a.display||"inline-block"===a.display){"normal"===a.fontWeight&&"bold"===o?a.fontWeight="bold":"bold"===a.fontWeight&&"bold"===o&&(a.fontWeight="normal"),"normal"===a.fontStyle&&"italic"===i?a.fontStyle="italic":"italic"===a.fontStyle&&"italic"===i&&(a.fontStyle="normal");var n="normal"===a.fontWeight&&"normal"===a.fontStyle?"default":"bold"===a.fontWeight&&"normal"===a.fontStyle?"bold":"normal"===a.fontWeight&&"italic"===a.fontStyle?"italic":"bolditalic",s=this.getTextAreaWidth(n);a.width=s+"px",this.updateObjColl(e,t)}else this.textSettings.bold=r.activeObj.textSettings.bold="normal"!==o,this.textSettings.italic=r.activeObj.textSettings.italic="normal"!==i,0===r.activeObj.activePoint.width&&0===r.activeObj.activePoint.height||this.redrawText(),r.notify("undo-redo",{prop:"updateUrObj",onPropertyChange:!1,value:{objColl:t}})},o.prototype.updateArrowRatio=function(e){var t={arrowDimension:null};this.parent.notify("draw",{prop:"getArrowDimension",onPropertyChange:!1,value:{obj:t}});var o;o=Math.abs(e.activePoint.width)>Math.abs(e.activePoint.height)?Math.abs(e.activePoint.width):Math.abs(e.activePoint.height);for(var i,r=0,a=["bar","arrow","arrowSolid","circle","square"];r<a.length;r++){i=a[r];var n=o/t.arrowDimension[i].width,s=o/t.arrowDimension[i].height;t.arrowDimension[i].ratioX=n,t.arrowDimension[i].ratioY=s}},o.prototype.updateArrowSize=function(e){var t={arrowDimension:null};this.parent.notify("draw",{prop:"getArrowDimension",onPropertyChange:!1,value:{obj:t}});var o;o=Math.abs(e.activePoint.width)>Math.abs(e.activePoint.height)?Math.abs(e.activePoint.width):Math.abs(e.activePoint.height);for(var i,r=0,a=["bar","arrow","arrowSolid","circle","square"];r<a.length;r++){i=a[r];var n=t.arrowDimension[i].ratioX,s=t.arrowDimension[i].ratioY;t.arrowDimension[i].width=o/n,t.arrowDimension[i].height=o/s}},o.prototype.updateFontRatio=function(e,o){var i=this.parent,r=this.getMaxText(o),a=this.upperContext.measureText(r).width+.5*i.activeObj.textSettings.fontSize,n=i.activeObj.textSettings.fontSize,s=this.getRotDegOfShape(e);t.isNullOrUndefined(o)?0===s||180===Math.abs(s)?e.textSettings.fontRatio=a/e.textSettings.fontSize:e.textSettings.fontRatio=n/e.textSettings.fontSize:o&&(e.textSettings.fontRatio=a/parseFloat(i.textArea.style.fontSize))},o.prototype.updateFontSize=function(e){var t=this.getRotDegOfShape(e);0===t||180===Math.abs(t)?e.textSettings.fontSize=e.activePoint.width/e.textSettings.fontRatio:e.textSettings.fontSize=e.activePoint.height/e.textSettings.fontRatio},o.prototype.updateObjColl=function(e,o){var i=this.parent,r=t.extend({},i.cropObj,{},!0),a={currObj:{}};i.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:a}});var n=a.currObj;n.objColl=o,n.pointColl=t.extend([],i.pointColl,[],!0),n.afterCropActions=t.extend([],i.afterCropActions,[],!0);var s={selPointColl:null};i.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:s}}),n.selPointColl=t.extend([],s.selPointColl,[],!0);var l=i.activeObj.textSettings.bold,p=i.activeObj.textSettings.italic;switch(e){case"default":i.activeObj.textSettings.bold=!1,i.activeObj.textSettings.italic=!1;break;case"bold":i.activeObj.textSettings.bold=!0,i.activeObj.textSettings.italic=!1;break;case"italic":i.activeObj.textSettings.bold=!1,i.activeObj.textSettings.italic=!0;break;case"bolditalic":i.activeObj.textSettings.bold=!0,i.activeObj.textSettings.italic=!0}i.objColl.push(i.activeObj),i.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"textAreaCustomization",previousObj:n,previousObjColl:n.objColl,previousPointColl:n.pointColl,previousSelPointColl:n.selPointColl,previousCropObj:r,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),i.objColl.pop(),i.activeObj.textSettings.bold=l,i.activeObj.textSettings.italic=p},o.prototype.pushActItemIntoObj=function(){var e=this.parent;if("none"===e.textArea.style.display)0===e.activeObj.activePoint.width&&0===e.activeObj.activePoint.height||e.objColl.push(e.activeObj);else{var o=t.extend({},e.activeObj,{},!0);e.notify("selection",{prop:"setTextBoxStylesToActObj",onPropertyChange:!1}),e.objColl.push(e.activeObj),e.activeObj=o}},o.prototype.clearActObj=function(){var e=this.parent;"none"===e.textArea.style.display&&(this.refreshActiveObj(),this.applyActObj(),this.refreshActiveObj(),e.currObjType.isCustomCrop=!1)},o.prototype.refreshActiveObj=function(){var e=this.parent;e.activeObj={},e.activeObj.activePoint={startX:0,startY:0,endX:0,endY:0,width:0,height:0},e.activeObj.triangle=[],e.activeObj.triangleRatio=[],e.activeObj.order=null,e.activeObj.flipObjColl=[],e.activeObj.strokeSettings=this.strokeSettings,e.activeObj.textSettings=this.textSettings,e.activeObj.rotatedAngle=0,e.activeObj.opacity=1,e.activeObj.redactType=this.redactType,e.activeObj.redactBlur=e.tempRedactBlur,e.activeObj.redactPixelate=e.tempRedactPixel},o.prototype.applyActObj=function(e){var o=this.parent,i=!1;if(void 0!==o.activeObj.shape&&"text"===o.activeObj.shape&&""===o.activeObj.keyHistory)this.refreshActiveObj(),this.upperContext.clearRect(0,0,o.upperCanvas.width,o.upperCanvas.height);else{var r=void 0,a=!1;if(void 0!==o.activeObj.shape&&(r=o.activeObj.shape.split("-")),void 0===r&&o.currObjType.isCustomCrop?a=!0:void 0!==r&&"crop"===r[0]&&(a=!0),o.activeObj.shape&&!a&&"shape"!==o.activeObj.shape){for(l=0;l<o.objColl.length;l++)if(JSON.stringify(o.activeObj)===JSON.stringify(o.objColl[l])){i=!0;break}if(!i){t.isNullOrUndefined(o.activeObj.currIndex)&&(o.activeObj.currIndex=this.getNewShapeId()),t.isNullOrUndefined(o.activeObj.order)&&(o.activeObj.order=this.getNewOrder()),this.updImgRatioForActObj();var n=o.activeObj.currIndex.split("_"),s=o.objColl.splice(0,parseInt(n[1],10)-1);s.push(t.extend({},o.activeObj,{},!0));for(var l=0;l<o.objColl.length;l++)s.push(o.objColl[l]);o.objColl=s,s=[],this.refreshActiveObj(),this.lowerContext.clearRect(0,0,o.lowerCanvas.width,o.lowerCanvas.height),o.notify("draw",{prop:"redrawImgWithObj",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.currObjType.shape="",this.refreshActiveObj(),o.isCircleCrop&&o.notify("crop",{prop:"cropCircle",onPropertyChange:!1,value:{context:this.lowerContext,isSave:null,isFlip:null}}),o.notify("toolbar",{prop:"destroy-qa-toolbar",onPropertyChange:!1}),t.isNullOrUndefined(e)&&(o.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"ok"}}),o.notify("draw",{prop:"setPrevActObj",onPropertyChange:!1,value:{prevActObj:null}}))}}}},o.prototype.getNewShapeId=function(){for(var e=this.parent,t=e.objColl.length+1,o=0;o<e.objColl.length;o++)e.objColl[o].currIndex==="shape_"+t&&(t++,o=-1);return"shape_"+t},o.prototype.getNewOrder=function(){var e=this.parent;this.updateShapeColl();for(var t=e.shapeColl.length+1,o=0;o<e.shapeColl.length;o++)e.shapeColl[o].order===t&&(t++,o=-1);return t},o.prototype.getHighestOrder=function(){var e=this.parent;this.updateShapeColl();for(var t=0,o=0;o<e.shapeColl.length;o++)e.shapeColl[o].order>t&&(t=e.shapeColl[o].order);return t},o.prototype.getLowestOrder=function(){var e=this.parent;this.updateShapeColl();for(var t=1,o=0;o<e.shapeColl.length;o++)e.shapeColl[o].order<t&&(t=e.shapeColl[o].order);return t},o.prototype.alignTextAreaIntoCanvas=function(){var e=this.parent,t=e.textArea.value;e.textArea.value="";for(var o=0,i=t.length;o<i;o++)e.textArea.value+=t[o],e.textArea.style.height="auto",e.textArea.style.height=e.textArea.scrollHeight+"px",this.setTextBoxWidth()},o.prototype.transformTextArea=function(){var e=this.parent;if("text"===e.activeObj.shape){e.textArea.style.transformOrigin="0 0";var t=e.activeObj.rotatedAngle*(180/Math.PI),o="",i=this.getRotDegOfShape(e.activeObj);if(e.activeObj.flipObjColl.length>0)for(var r=0;r<e.activeObj.flipObjColl.length;r++)o+=0!==i&&i%90==0&&180!==i?"horizontal"===e.activeObj.flipObjColl[r].toLowerCase()?"scale(1, -1)":"scale(-1, 1)":"horizontal"===e.activeObj.flipObjColl[r].toLowerCase()?"scale(-1, 1)":"scale(1, -1)",i+=t,"horizontal"===e.activeObj.flipObjColl[r].toLowerCase()?e.textArea.style.transform="rotate("+i+"deg)"+o:"vertical"===e.activeObj.flipObjColl[r].toLowerCase()&&(e.textArea.style.transform="rotate("+i+"deg)"+o);else i+=t,e.textArea.style.transform="rotate("+i+"deg)"}},o.prototype.getTextAreaWidth=function(e){var t=this.parent,o=t.activeObj.textSettings.bold,i=t.activeObj.textSettings.italic;switch(e){case"default":t.activeObj.textSettings.bold=!1,t.activeObj.textSettings.italic=!1;break;case"bold":t.activeObj.textSettings.bold=!0,t.activeObj.textSettings.italic=!1;break;case"italic":t.activeObj.textSettings.bold=!1,t.activeObj.textSettings.italic=!0;break;case"bolditalic":t.activeObj.textSettings.bold=!0,t.activeObj.textSettings.italic=!0}var r="none"!==t.textArea.style.display;this.updateFontStyles(r);var a;return a=r?this.upperContext.measureText(t.textArea.value).width+.5*t.activeObj.textSettings.fontSize:this.upperContext.measureText(t.activeObj.keyHistory).width+.5*t.activeObj.textSettings.fontSize,t.activeObj.textSettings.bold=o,t.activeObj.textSettings.italic=i,a},o.prototype.getRedactObjDetails=function(e){var t=this.parent,o={};switch(o.id=e.currIndex,o.type=t.toPascalCase(e.redactType),o.startX=e.activePoint.startX,o.startY=e.activePoint.startY,o.width=e.activePoint.width,o.height=e.activePoint.height,e.redactType){case"blur":o.blurIntensity=e.redactBlur;break;case"pixelate":o.pixelSize=e.redactPixelate}return o},o.prototype.getObjDetails=function(e){var t=this.parent,o={};switch(o.id=e.currIndex,o.type=t.toPascalCase(e.shape),o.startX=e.activePoint.startX,o.startY=e.activePoint.startY,o.index=e.order,e.shape){case"rectangle":o.width=e.activePoint.width,o.height=e.activePoint.height,o.strokeColor=e.strokeSettings.strokeColor,o.fillColor=e.strokeSettings.fillColor,o.strokeWidth=e.strokeSettings.strokeWidth,o.degree=e.rotatedAngle*(180/Math.PI);break;case"ellipse":o.radius=e.activePoint.width/2,o.strokeColor=e.strokeSettings.strokeColor,o.fillColor=e.strokeSettings.fillColor,o.strokeWidth=e.strokeSettings.strokeWidth,o.radiusX=e.activePoint.width/2,o.radiusY=e.activePoint.height/2,o.degree=e.rotatedAngle*(180/Math.PI);break;case"line":case"arrow":if(o.length=e.activePoint.width,o.strokeColor=e.strokeSettings.strokeColor,o.strokeWidth=e.strokeSettings.strokeWidth,o.endX=e.activePoint.endX,o.endY=e.activePoint.endY,"arrow"===e.shape){var i={type:null};t.notify("selection",{prop:"getArrowType",onPropertyChange:!1,value:{type:e.start,obj:i}}),o.arrowHead=i.type,t.notify("selection",{prop:"getArrowType",onPropertyChange:!1,value:{type:e.end,obj:i}}),o.arrowTail=i.type}break;case"text":o.text=e.keyHistory,o.fontSize=e.textSettings.fontSize,o.fontFamily=e.textSettings.fontFamily,o.color=e.strokeSettings.strokeColor,o.fontStyle=[],e.textSettings.bold&&o.fontStyle.push("bold"),e.textSettings.italic&&o.fontStyle.push("italic"),o.degree=e.rotatedAngle*(180/Math.PI);break;case"path":o.strokeColor=e.strokeSettings.strokeColor,o.strokeWidth=e.strokeSettings.strokeWidth,o.points=e.pointColl;break;case"image":o.imageData=e.imageCanvas.toDataURL(),o.degree=e.rotatedAngle*(180/Math.PI),o.width=e.activePoint.width,o.height=e.activePoint.height,o.opacity=e.opacity}return o},o.prototype.getFreehandDrawDetails=function(o){var i=this.parent,r={};return r.id=i.pointColl[o].id,r.type=e.ShapeType.FreehandDraw,r.points=t.extend([],i.pointColl[o].points),r.strokeColor=i.pointColl[o].strokeColor,r.strokeWidth=i.pointColl[o].strokeWidth,r.index=i.pointColl[o].order,r},o.prototype.getShapeSetting=function(e,o){var i,r=this.parent;if(!r.disabled&&r.isImageLoaded)if("none"!==r.textArea.style.display?r.okBtn(null,!0):this.applyActObj(!0),"shape"===e.split("_")[0]){for(var a,n=0,s=r.objColl.length;n<s;n++)if(r.objColl[n].currIndex===e){a=t.extend({},r.objColl[n],{},!0);break}i=this.getObjDetails(a)}else"pen"===e.split("_")[0]&&(i=this.getFreehandDrawDetails(parseInt(e.split("_")[1],10)-1));o.shapeDetails=i},o.prototype.getShapeSettings=function(e){var t=this.parent,o=[];if(!t.disabled&&t.isImageLoaded){"none"!==t.textArea.style.display?t.okBtn(null,!0):this.applyActObj(!0);for(var i=0,r=t.objColl.length;i<r;i++){a=this.getObjDetails(t.objColl[i]);o.push(a)}for(i=0;i<t.freehandCounter;i++){var a=this.getFreehandDrawDetails(i);o.push(a)}}e.shapeDetailsColl=o},o.prototype.getRedactSettings=function(e){var t=this.parent,o=[];if(!t.disabled&&t.isImageLoaded){"none"!==t.textArea.style.display?t.okBtn(null,!0):this.applyActObj(!0);for(var i=0,r=t.objColl.length;i<r;i++){var a=this.getRedactObjDetails(t.objColl[i]);o.push(a)}}e.shapeDetailsColl=o},o.prototype.isPointsInRange=function(e,o,i){var r=!1,a=this.parent;!t.isNullOrUndefined(e)&&!t.isNullOrUndefined(o)&&e>=a.img.destLeft&&o>=a.img.destTop&&e<=a.img.destLeft+a.img.destWidth&&o<=a.img.destTop+a.img.destHeight&&(r=!0),i.inRange=r},o.prototype.alignRotateFlipColl=function(e,t,o){return e=this.popForDefaultTransformedState(e),e=this.popForDefaultFlipState(e),0===(e=this.popForDefaultRotateState(e)).length&&t&&(this.parent.transform.degree=0,this.parent.transform.currFlipState=""),o.collection=e,e},o.prototype.popForDefaultTransformedState=function(e){for(var t=0,o=0,i=0,r=0,a=0;a<e.length;a++)90===e[a]||"rotateRight"===e[a]?(o=0,i=0,r=0,4===++t&&(e.pop(),e.pop(),e.pop(),e.pop())):-90===e[a]||"rotateLeft"===e[a]?(t=0,i=0,r=0,4===++o&&(e.pop(),e.pop(),e.pop(),e.pop())):"horizontal"===e[a]||"Horizontal"===e[a]||"horizontalflip"===e[a]?(o=0,t=0,r=0,2===++i&&(e.pop(),e.pop())):"vertical"!==e[a]&&"Vertical"!==e[a]&&"verticalflip"!==e[a]||(i=0,o=0,t=0,2===++r&&(e.pop(),e.pop()));return e},o.prototype.popForDefaultFlipState=function(e){for(var t=0,o=e.length-3;t<o;t++){var i="horizontal"===e[t]||"Horizontal"===e[t]||"horizontalFlip"===e[t],r="vertical"===e[t]||"Vertical"===e[t]||"verticalFlip"===e[t],a="horizontal"===e[t+1]||"Horizontal"===e[t+1]||"horizontalFlip"===e[t+1],n="vertical"===e[t+1]||"Vertical"===e[t+1]||"verticalFlip"===e[t+1],s="horizontal"===e[t+2]||"Horizontal"===e[t+2]||"horizontalFlip"===e[t+2],l="vertical"===e[t+2]||"Vertical"===e[t+2]||"verticalFlip"===e[t+2],p="horizontal"===e[t+3]||"Horizontal"===e[t+3]||"horizontalFlip"===e[t+3];(i&&n&&s&&l||r&&a&&l&&p)&&(e.splice(t,4),t-=4)}return e},o.prototype.popForDefaultRotateState=function(e){for(var t=0;t<e.length-1;t++){var o=e[t],i=e[t+1];90!==o&&"rotateRight"!==o||-90!==i&&"rotateLeft"!==i?-90!==o&&"rotateLeft"!==o||90!==i&&"rotateRight"!==i||(e.splice(t,2),t-=2):(e.splice(t,2),t-=2)}return e},o.prototype.selectShape=function(e,o){var i=this.parent,r=!1;if(!i.disabled&&i.isImageLoaded)if(this.applyActObj(),"shape"===e.split("_")[0]){for(var a,n=0,s=i.objColl.length;n<s;n++)if(i.objColl[n].currIndex===e){a=t.extend({},i.objColl[n],{},!0);break}if(t.isNullOrUndefined(a))r=!1;else{r=!0,i.activeObj=a;l={canvasFilter:null};i.notify("toolbar",{prop:"getCanvasFilter",onPropertyChange:!1,value:{obj:l}}),this.lowerContext.filter=l.canvasFilter,i.notify("selection",{prop:"redrawShape",onPropertyChange:!1,value:{obj:i.activeObj}}),"text"===i.activeObj.shape?i.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"text",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}}):"pen"===i.activeObj.shape?i.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"pen",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}}):"redact"===i.activeObj.shape?i.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"redact",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}}):i.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"shapes",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}}),i.notify("toolbar",{prop:"update-toolbar-items",onPropertyChange:!1}),i.notify("toolbar",{prop:"renderQAT",onPropertyChange:!1,value:{isPenEdit:null}})}}else if("pen"===e.split("_")[0]){var l={bool:!1};i.notify("selection",{prop:"getFreehandDrawEditing",onPropertyChange:!1,value:{obj:l}}),l.bool&&i.okBtn(null,!0);var p={isIndex:!1};i.notify("freehand-draw",{prop:"isFHDIdx",value:{index:parseInt(e.split("_")[1],10)-1,obj:p}}),p.isIndex?(r=!0,i.notify("freehand-draw",{prop:"selectFhd",value:{id:e}}),i.notify("toolbar",{prop:"renderQAT",onPropertyChange:!1,value:{isPenEdit:!0}}),i.notify("toolbar",{prop:"update-toolbar-items",onPropertyChange:!1})):r=!1}o.isSelected=r},o.prototype.deleteShape=function(e){var t=this.parent;if(!t.disabled&&t.isImageLoaded){if(t.activeObj.currIndex&&t.activeObj.currIndex===e)t.notify("selection",{prop:"deleteItem",onPropertyChange:!1});else if(this.applyActObj(),"shape"===e.split("_")[0]){for(var o=0,i=t.objColl.length;o<i;o++)if(t.objColl[o].currIndex===e){t.objColl.splice(o,1);break}}else"pen"===e.split("_")[0]&&t.notify("freehand-draw",{prop:"handle-freehand-draw",value:{id:e}});var r={canvasFilter:null};t.notify("toolbar",{prop:"getCanvasFilter",onPropertyChange:!1,value:{obj:r}}),this.lowerContext.filter=r.canvasFilter,this.lowerContext.clearRect(0,0,t.lowerCanvas.width,t.lowerCanvas.height),t.notify("draw",{prop:"redrawImgWithObj",onPropertyChange:!1}),t.notify("toolbar",{prop:"refresh-main-toolbar",onPropertyChange:!1})}},o.prototype.getMaxText=function(e,o,i){t.isNullOrUndefined(o)&&(o=e?this.parent.textArea.value:this.parent.activeObj.keyHistory);for(var r,a=o.split("\n"),n=a[0].length,s=a[0],l=1;l<a.length;l++)(r=a[l].length)>n&&(s=a[l],n=r);return i&&(i.maxText=s),s},o.prototype.getLinePoints=function(e,o,i,r){var a,n,s=[];if(e===i){o<r?(a=[e,o],n=[i,r]):(n=[e,o],a=[i,r]);for(var l=this.getSlope(a,n,!0),p=this.getIntercept(a,l),h=a[1];h<=n[1];h++){d=l*h+p;s.push({x:d,y:h})}}else{e<i?(a=[e,o],n=[i,r]):(n=[e,o],a=[i,r]);for(var l=this.getSlope(a,n,!1),p=this.getIntercept(a,l),d=a[0];d<=n[0];d++){h=l*d+p;s.push({x:d,y:h})}}if(Math.floor(e)===Math.floor(i)||s.length<10&&(r-o>10||o-r>10)){s=[];for(var c=Math.min(o,r),u=0;u<Math.abs(Math.floor(r)-Math.floor(o));u++)s.push({x:e,y:c+u});if(s.length>1){b=void 0;b=t.isNullOrUndefined(s[s.length-2])?{x:0,y:0}:s[s.length-2];var v=s[s.length-1].x-b.x,g=s[s.length-1].y-b.y;s.push({x:s[s.length-1].x+v/2,y:s[s.length-1].y+g/2})}}else if(Math.floor(o)===Math.floor(r)||s.length<10&&(i-e>10||e-i>10)){s=[];for(var f=Math.min(e,i),C=0;C<Math.abs(Math.floor(i)-Math.floor(e));C++)s.push({x:f+C,y:o});if(s.length>1){var b=void 0;b=t.isNullOrUndefined(s[s.length-2])?{x:0,y:0}:s[s.length-2];var v=s[s.length-1].x-b.x,g=s[s.length-1].y-b.y;s.push({x:s[s.length-1].x+v/2,y:s[s.length-1].y+g/2})}}return s},o.prototype.getSlope=function(e,t,o){var i;if(o){if(e[1]===t[1])return null;i=(t[0]-e[0])/(t[1]-e[1])}else{if(e[0]===t[0])return null;i=(t[1]-e[1])/(t[0]-e[0])}return i},o.prototype.getIntercept=function(e,t){return null===t?e[0]:e[1]-t*e[0]},o.prototype.setPointCollForShapeRotation=function(e){var t=this.parent,o=e.activePoint,i=o.startX,r=o.startY,a=o.endX,n=o.endY,s={x:i+o.width/2,y:r+o.height/2},l=Math.cos(e.rotatedAngle),p=Math.sin(e.rotatedAngle),h={x:l*(i-s.x)-p*(r-s.y)+s.x,y:p*(i-s.x)+l*(r-s.y)+s.y},d={x:l*(a-s.x)-p*(r-s.y)+s.x,y:p*(a-s.x)+l*(r-s.y)+s.y},c={x:l*(i-s.x)-p*(n-s.y)+s.x,y:p*(i-s.x)+l*(n-s.y)+s.y},u={x:l*(a-s.x)-p*(n-s.y)+s.x,y:p*(a-s.x)+l*(n-s.y)+s.y};e.horTopLinePointColl=this.getLinePoints(h.x,h.y,d.x,d.y),e.horTopLinePointColl=this.getLinePoints(h.x,h.y,d.x,d.y),e.horBottomLinePointColl=this.getLinePoints(c.x,c.y,u.x,u.y),e.verLeftLinePointColl=this.getLinePoints(h.x,h.y,c.x,c.y),e.verRightLinePointColl=this.getLinePoints(d.x,d.y,u.x,u.y),e.verLeftLinePointColl.reverse(),e.verRightLinePointColl.reverse();for(v=0;v<e.horTopLinePointColl.length;v++)e.horTopLinePointColl[v].ratioX=(e.horTopLinePointColl[v].x-this.parent.img.destLeft)/this.parent.img.destWidth,e.horTopLinePointColl[v].ratioY=(e.horTopLinePointColl[v].y-this.parent.img.destTop)/this.parent.img.destHeight;for(v=0;v<e.horBottomLinePointColl.length;v++)e.horBottomLinePointColl[v].ratioX=(e.horBottomLinePointColl[v].x-this.parent.img.destLeft)/this.parent.img.destWidth,e.horBottomLinePointColl[v].ratioY=(e.horBottomLinePointColl[v].y-this.parent.img.destTop)/this.parent.img.destHeight;for(v=0;v<e.verLeftLinePointColl.length;v++)e.verLeftLinePointColl[v].ratioX=(e.verLeftLinePointColl[v].x-this.parent.img.destLeft)/this.parent.img.destWidth,e.verLeftLinePointColl[v].ratioY=(e.verLeftLinePointColl[v].y-this.parent.img.destTop)/this.parent.img.destHeight;for(var v=0;v<e.verRightLinePointColl.length;v++)e.verRightLinePointColl[v].ratioX=(e.verRightLinePointColl[v].x-this.parent.img.destLeft)/this.parent.img.destWidth,e.verRightLinePointColl[v].ratioY=(e.verRightLinePointColl[v].y-this.parent.img.destTop)/this.parent.img.destHeight;if("move"!==t.upperCanvas.style.cursor){var g={rotationCirclePoint:null};t.notify("selection",{prop:"getTransRotationPoint",value:{obj:e,object:g}});var f=g.rotationCirclePoint;f&&(e.rotationCirclePointColl={x:l*(f.x-s.x)-p*(f.y-s.y)+s.x,y:p*(f.x-s.x)+l*(f.y-s.y)+s.y},e.rotationCirclePointColl.ratioX=(e.rotationCirclePointColl.x-t.img.destLeft)/t.img.destWidth,e.rotationCirclePointColl.ratioY=(e.rotationCirclePointColl.y-t.img.destTop)/t.img.destHeight)}},o.prototype.getSquarePointForRotatedShape=function(e,t){var o={startX:0,startY:0,endX:0,endY:0,width:0,height:0},i=e.activePoint,r=i.startX,a=i.startY,n=i.endX,s=i.endY,l={x:r+i.width/2,y:a+i.height/2},p=Math.cos(e.rotatedAngle),h=Math.sin(e.rotatedAngle),d={x:p*(r-l.x)-h*(a-l.y)+l.x,y:h*(r-l.x)+p*(a-l.y)+l.y},c={x:p*(n-l.x)-h*(a-l.y)+l.x,y:h*(n-l.x)+p*(a-l.y)+l.y},u={x:p*(r-l.x)-h*(s-l.y)+l.x,y:h*(r-l.x)+p*(s-l.y)+l.y},v={x:p*(n-l.x)-h*(s-l.y)+l.x,y:h*(n-l.x)+p*(s-l.y)+l.y};return o.startX=d.x,o.startY=d.y,o.endX=d.x,o.endY=d.y,o.startX>c.x&&(o.startX=c.x),o.startX>u.x&&(o.startX=u.x),o.startX>v.x&&(o.startX=v.x),o.startY>c.y&&(o.startY=c.y),o.startY>u.y&&(o.startY=u.y),o.startY>v.y&&(o.startY=v.y),o.endX<c.x&&(o.endX=c.x),o.endX<u.x&&(o.endX=u.x),o.endX<v.x&&(o.endX=v.x),o.endY<c.y&&(o.endY=c.y),o.endY<u.y&&(o.endY=u.y),o.endY<v.y&&(o.endY=v.y),o.width=o.endX-o.startX,o.height=o.endY-o.startY,t&&(t.activePoint=o),o},o.prototype.updateZOrder=function(e,o){var i=this.parent;o=o.toLowerCase();var r=e;if(!t.isNullOrUndefined(r.order)){var a,n,s=this.getHighestOrder();if(this.updateShapeColl(),0!==i.shapeColl.length){for(var l,p=0;p<i.shapeColl.length;p++)l=i.shapeColl[p],r.id&&r.id.indexOf("pen")>-1?l.id&&l.id===r.id&&i.shapeColl.splice(p,1):l.shape&&l.shape.indexOf("crop-")>-1&&i.shapeColl.splice(p,1);switch(o){case"sendtoback":n=r.order,a=r.order,r.order=1;break;case"sendbackward":r.order-=1,a=r.order;break;case"bringtofront":n=r.order,a=s,r.order=a;break;case"bringforward":r.order+=1,a=r.order}this.reArrangeObjColl(a,o,n),r.id&&r.id.indexOf("pen")>-1&&this.reUpdateShapeColl(r)}}},o.prototype.reArrangeObjColl=function(e,t,o){var i,r=this.parent;switch(t){case"sendtoback":for(var a=0,n=r.shapeColl.length;a<n;a++)(i=r.shapeColl[a]).order<o&&i.order<=e&&(i.order+=1,this.reUpdateShapeColl(i));break;case"sendbackward":for(var a=0,n=r.shapeColl.length;a<n;a++)if((i=r.shapeColl[a]).order===e){i.order+=1,this.reUpdateShapeColl(i);break}break;case"bringtofront":for(var a=0,n=r.shapeColl.length;a<n;a++)(i=r.shapeColl[a]).order>o&&i.order<=e&&(i.order-=1,this.reUpdateShapeColl(i));break;case"bringforward":for(var a=0,n=r.shapeColl.length;a<n;a++)if((i=r.shapeColl[a]).order===e){i.order-=1,this.reUpdateShapeColl(i);break}}},o.prototype.reorderRedact=function(e){var t=e.filter(function(e){return"redact"!==e.shape});return e.filter(function(e){return"redact"===e.shape}).concat(t)},o.prototype.updateShapeColl=function(){var e=this.parent,o=!1,i=1,r=t.extend([],e.objColl,[],!0);r=this.reorderRedact(r);var a=t.extend([],e.pointColl,[],!0);if(e.shapeColl.length>0&&e.shapeColl.length===e.objColl.length+e.pointColl.length){for(h=0;h<e.shapeColl.length;h++){if(e.shapeColl[h].order!==i){o=!1;break}o=!0,i++}if(o){for(h=0;h<e.shapeColl.length;h++)if(e.shapeColl[h].currIndex&&e.shapeColl[h].currIndex.indexOf("shape")>-1){for(n=0;n<r.length;n++)if(e.shapeColl[h].currIndex===r[n].currIndex){e.shapeColl[h]=t.extend({},r[n],{},!0),r.splice(n,1);break}}else if(e.shapeColl[h].id&&e.shapeColl[h].id.indexOf("pen")>-1)for(var n=0;n<a.length;n++)if(e.shapeColl[h].id===a[n].id){e.shapeColl[h]=t.extend([],a[n],[],!0),a.splice(n,1);break}return}}r=t.extend([],e.objColl,[],!0),a=t.extend([],e.pointColl,[],!0),e.shapeColl=[];for(var s,l=1,p=!1;0!==r.length||0!==a.length;){s=p=!1;for(h=0;h<r.length;h++)if(r[h].order===l||!r[h].order&&r[h].shape&&r[h].shape.indexOf("crop-")>-1){e.shapeColl.push(t.extend({},r[h],{},!0)),r[h].shape&&r[h].shape.indexOf("crop-")>-1&&(p=!0),r.splice(h,1),s=!0;break}if(!s)for(var h=0;h<a.length;h++)if(a[h].order===l){e.shapeColl.push(t.extend([],a[h],[],!0)),a.splice(h,1),s=!0;break}p||l++}},o.prototype.reUpdateShapeColl=function(e){var t=this.parent;if(e.id&&e.id.indexOf("pen")>-1){if(t.freehandCounter>0)for(o=0;o<t.freehandCounter;o++)t.pointColl[o].id===e.id&&(t.pointColl[o].order=e.order)}else if(e.currIndex&&e.currIndex.indexOf("shape")>-1)for(var o=0;o<t.objColl.length;o++)t.objColl[o].currIndex===e.currIndex&&(t.objColl[o].order=e.order)},o.prototype.drawAnnotations=function(e,o,i,r,a,n,s){var l=this.parent,p=t.extend({},l.activeObj,{},!0),h=t.extend([],l.objColl,[],!0),d=t.extend([],l.pointColl,[],!0),c={selPointColl:null};l.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:c}});var u={selPointColl:null};l.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:u}}),this.updateShapeColl();var v=t.extend([],l.shapeColl,[],!0);v=this.reorderRedact(v);var g=!1;this.preventFrameAnnotation||(this.preventFrameAnnotation=g=!0);for(var f=0;f<v.length;f++){var C=v[f].id;if(v[f].order||!v[f].order&&v[f].shape&&v[f].shape.indexOf("crop-")>-1||!v[f].order&&"path"===v[f].shape&&"path"===l.drawingShape){if(v[f].currIndex&&v[f].currIndex.indexOf("shape")>-1){if(l.objColl=[],l.objColl.push(t.extend({},v[f],{},!0)),"iterate"===o){var b=this.lowerContext.filter;this.lowerContext.filter="none",this.iterateObjColl(),this.lowerContext.filter=b}else if("zoom"===o||"pan"===o){for(var m=-1,y=0;y<h.length;y++)if(JSON.stringify(h[y])===JSON.stringify(l.objColl[0])){m=y;break}"zoom"===o?this.zoomObjColl(r):this.panObjColl(a,n,s),m>-1&&(h[m]=t.extend({},l.objColl[0],{},!0))}}else if(v[f].id&&v[f].id.indexOf("pen")>-1)if(l.pointColl=[],l.freehandCounter=0,l.notify("freehand-draw",{prop:"setSelPointColl",onPropertyChange:!1,value:{obj:{selPointColl:[]}}}),l.pointColl.push(t.extend({},v[f],{},!0)),l.notify("freehand-draw",{prop:"pushSelPointColl",onPropertyChange:!1,value:{obj:{selPointColl:u.selPointColl[f]}}}),l.freehandCounter=l.pointColl.length,"iterate"===i)l.notify("freehand-draw",{prop:"freehandRedraw",onPropertyChange:!1,value:{context:e,points:null}});else if("zoom"===i||"pan"===i){"zoom"===i?l.notify("freehand-draw",{prop:"zoomFHDColl",onPropertyChange:!1,value:{isPreventApply:r}}):l.notify("freehand-draw",{prop:"panFHDColl",onPropertyChange:!1,value:{xDiff:a,yDiff:n,panRegion:s}});for(var P=0;P<d.length;P++)if(d[P].id===l.pointColl[0].id){d[P]=t.extend({},l.pointColl[0],{},!0);break}for(var j=0,x=c.selPointColl.length;j<x;j++)if(c.selPointColl[j].id===u.selPointColl[j].id){c.selPointColl[j]=t.extend({},u.selPointColl[j],{},!0);break}}}else(v[f].shape||C)&&(v[f].currIndex||C)||v.splice(f,1)}i&&"zoom"===i&&(l.pointColl=[],l.freehandCounter=0,l.notify("freehand-draw",{prop:"zoomFHDColl",onPropertyChange:!1,value:{isPreventApply:r}})),l.objColl=h,l.pointColl=d,l.freehandCounter=l.pointColl.length,l.notify("freehand-draw",{prop:"setSelPointColl",onPropertyChange:!1,value:{obj:{selPointColl:c.selPointColl}}}),g&&this.preventFrameAnnotation&&(l.notify("draw",{prop:"applyFrame",value:{ctx:this.lowerContext,frame:l.frameObj.type,preventImg:!0}}),this.preventFrameAnnotation=!1),l.activeObj=p},o}(),f=function(){function i(e){this.isReverseFlip=!1,this.disablePan=!1,this.isReverseRotate=!1,this.flipColl=[],this.prevZoomValue=1,this.cropDimension={width:0,height:0},this.isPreventSelect=!1,this.preventDownScale=!1,this.resizedImgAngle=null,this.parent=e,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(e){switch(this.initTransformPvtVar(),e.prop){case"flipImage":this.flipImage(e.value.direction);break;case"setDestPointsForFlipState":this.setDestPointsForFlipState();break;case"zoomAction":this.zoomAction(e.value.zoomFactor,e.value.zoomPoint,e.value.isResize);break;case"disableZoomOutBtn":this.disableZoomOutBtn(e.value.isZoomOut);break;case"rotatedFlip":this.rotatedFlip();break;case"drawPannedImage":this.drawPannedImage(e.value.xDiff,e.value.yDiff);break;case"drawPannImage":this.drawPannImage(e.value.point);break;case"performTransformation":this.performTransformation(e.value.text);break;case"updateTransform":this.updateTransform(e.value.text);break;case"rotatePan":this.rotatePan(e.value.isCropSelection,e.value.isDefaultZoom);break;case"resetZoom":this.resetZoom();break;case"pan":this.pan(e.value.value,e.value.x,e.value.y);break;case"zoom":this.zoom(e.value.zoomFactor,e.value.zoomPoint);break;case"setCurrPanRegion":this.setCurrPanRegion(e.value.region,e.value.type,e.value.obj);break;case"rotate":this.rotate(e.value.degree,e.value.obj);break;case"flip":this.flip(e.value.direction);break;case"update":this.update();break;case"calcMaxDimension":this.calcMaxDimension(e.value.width,e.value.height,e.value.obj,e.value.isImgShape);break;case"getPanMove":e.value.obj.panMove=this.panMove;break;case"setPanMove":this.panMove=e.value.point;break;case"getTempPanMove":e.value.obj.tempPanMove=this.tempPanMove;break;case"setTempPanMove":this.tempPanMove=e.value.point;break;case"setReverseFlip":this.isReverseFlip=e.value.isReverseFlip;break;case"setDisablePan":this.disablePan=e.value.bool;break;case"setCurrDestinationPoint":this.currDestPoint=e.value.point,this.currDestPoint.startX-=this.parent.cropObj.totalPannedPoint.x,this.currDestPoint.startY-=this.parent.cropObj.totalPannedPoint.y;break;case"setReverseRotate":this.isReverseRotate=e.value.bool;break;case"getFlipColl":e.value.obj.flipColl=this.flipColl;break;case"setFlipColl":this.flipColl=e.value.flipColl;break;case"getPreviousZoomValue":e.value.obj.previousZoomValue=this.prevZoomValue;break;case"setPreviousZoomValue":this.prevZoomValue=e.value.previousZoomValue;break;case"getCropDimension":e.value.obj.cropDimension=this.cropDimension;break;case"setCropDimension":this.cropDimension.width=e.value.width,this.cropDimension.height=e.value.height;break;case"getPreventSelect":e.value.obj.bool=this.isPreventSelect;break;case"setPreventSelect":this.isPreventSelect=e.value.bool;break;case"resizeImage":this.resizeImage(e.value.width,e.value.height);break;case"resizeCrop":this.resizeCrop(e.value.width,e.value.height);break;case"updateResize":this.updateResize();break;case"resize":this.resize(e.value.width,e.value.height,e.value.isAspectRatio);break;case"straightenImage":this.straightenImage(e.value.degree);break;case"reset":this.reset();break;case"cropZoom":e.value.obj.maxDimension=this.cropZoom(e.value.value,e.value.selectionObj);break;case"setResizedImgAngle":this.resizedImgAngle=e.value.angle}},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.resizedImgAngle=null,this.transCurrObj=null,this.prevZoomValue=1,this.isPreventSelect=this.preventDownScale=!1},i.prototype.rotateImage=function(e){var t=this.parent,o={cancel:!1,previousDegree:t.transform.degree,currentDegree:360===Math.abs(t.transform.degree+e)?0:t.transform.degree+e};this.isPreventSelect||(t.trigger("rotating",o),t.editCompleteArgs=o),this.rotateEvent(o,e)},i.prototype.rotateEvent=function(e,o){var i=this.parent;if(e.cancel)i.notify("draw",{prop:"setCurrentObj",onPropertyChange:!1,value:{obj:i.prevEventObjPoint}}),i.activeObj=i.prevEventSelectionPoint,i.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate",obj:i.activeObj}});else{var r=void 0;if(t.isNullOrUndefined(this.transCurrObj)){var a={currObj:{}};i.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:a}}),(r=a.currObj).objColl=t.extend([],i.objColl,null,!0),r.pointColl=t.extend({},i.pointColl,null,!0),r.afterCropActions=t.extend([],i.afterCropActions,[],!0);var n={selPointColl:null};i.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:n}}),r.selPointColl=t.extend([],n.selPointColl,[],!0)}i.afterCropActions.push(90===o?"rotateRight":"rotateLeft");var s=[],l=void 0;i.activeObj.activePoint&&i.activeObj.shape&&(void 0!==i.activeObj.shape&&(s=i.activeObj.shape.split("-")),(i.currObjType.isCustomCrop||"crop"===s[0])&&(l=i.currObjType.isCustomCrop?"custom":s[1],i.notify("shape",{prop:"updImgRatioForActObj",onPropertyChange:!1}),i.objColl.push(i.activeObj),i.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}))),i.notify("shape",{prop:"redrawActObj",onPropertyChange:!1,value:{x:null,y:null,isMouseDown:!0}}),this.upperContext.clearRect(0,0,i.upperCanvas.width,i.upperCanvas.height),this.drawRotatedImage(o),i.notify("draw",{prop:"setImageEdited",onPropertyChange:!1}),i.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.lowerContext}}),i.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.upperContext}}),i.isCircleCrop&&i.notify("crop",{prop:"cropCircle",onPropertyChange:!1,value:{context:this.lowerContext,isSave:null,isFlip:null}}),l&&(this.upperContext.clearRect(0,0,i.upperCanvas.width,i.upperCanvas.height),i.activeObj=t.extend({},i.objColl[i.objColl.length-1],{},!0),i.objColl.pop(),i.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate",obj:i.activeObj}})),i.isUndoRedo=!1;var p={collection:i.rotateFlipColl};i.notify("shape",{prop:"alignRotateFlipColl",onPropertyChange:!1,value:{collection:i.rotateFlipColl,isRotateFlipCollection:!0,obj:p}}),i.rotateFlipColl=p.collection,i.cropObj.activeObj.shape&&!this.isPreventSelect&&(i.notify("draw",{prop:"setIsCropSelect",value:{bool:!0}}),this.isPreventSelect=!0,i.notify("draw",{prop:"select",onPropertyChange:!1,value:{type:"custom",startX:null,startY:null,width:null,height:null}}),this.isPreventSelect=!1,i.setProperties({zoomSettings:{zoomFactor:1}},!0),this.prevZoomValue=i.zoomSettings.zoomFactor)}},i.prototype.drawRotatedImage=function(e){var o=this.parent;0===e?o.transform.degree=0:o.transform.degree+=e,360===Math.abs(o.transform.degree)&&(o.transform.degree=0),o.notify("draw",{prop:"setDestPoints",onPropertyChange:!1});var i=t.extend([],o.objColl,[],!0),r=t.extend({},o.activeObj,{},!0);if(o.objColl=[],o.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),this.isReverseRotate||o.notify("draw",{prop:"updateCurrTransState",onPropertyChange:!1,value:{type:"initial",isPreventDestination:null,isRotatePan:null}}),this.rotateDegree(e),this.isReverseRotate||(o.notify("draw",{prop:"updateCurrTransState",onPropertyChange:!1,value:{type:"reverse",isPreventDestination:null,isRotatePan:null}}),o.rotateFlipColl.push(e)),o.objColl=t.extend([],i,[],!0),o.activeObj=t.extend({},r,{},!0),o.isCircleCrop&&o.notify("crop",{prop:"cropCircle",onPropertyChange:!1,value:{context:this.lowerContext,isSave:null,isFlip:null}}),o.notify("shape",{prop:"redrawObj",onPropertyChange:!1,value:{degree:e}}),o.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),e>0)o.notify("freehand-draw",{prop:"rotateFhdColl",onPropertyChange:!1});else for(var a=0;a<3;a++)o.notify("freehand-draw",{prop:"rotateFhdColl",onPropertyChange:!1});o.notify("freehand-draw",{prop:"freehandRedraw",onPropertyChange:!1,value:{context:this.lowerContext,points:null}}),this.updateCurrSelectionPoint(e)},i.prototype.rotateDegree=function(e){var t=this.parent;this.lowerContext.save(),this.lowerContext.clearRect(0,0,t.lowerCanvas.width,t.lowerCanvas.height),this.lowerContext.translate(t.lowerCanvas.width/2,t.lowerCanvas.height/2),this.lowerContext.rotate(Math.PI/180*e),this.lowerContext.translate(-t.lowerCanvas.width/2,-t.lowerCanvas.height/2);var o=this.lowerContext.filter;t.notify("draw",{prop:"drawImage",onPropertyChange:!1}),this.lowerContext.filter=o,this.lowerContext.translate(t.lowerCanvas.width/2,t.lowerCanvas.height/2),this.lowerContext.rotate(Math.PI/180*-e),this.lowerContext.translate(-t.lowerCanvas.width/2,-t.lowerCanvas.height/2),this.lowerContext.restore()},i.prototype.updateCurrSelectionPoint=function(e){var o=this.parent;if(o.currSelectionPoint&&this.currDestPoint){var i=t.extend({},o.activeObj,{},!0),r=t.extend([],o.objColl,[],!0),a={startX:o.img.srcLeft,startY:o.img.srcTop,width:o.img.srcWidth,height:o.img.srcHeight},n={startX:o.img.destLeft,startY:o.img.destTop,width:o.img.destWidth,height:o.img.destHeight};o.objColl=[],o.objColl.push(t.extend({},o.currSelectionPoint,{},!0)),o.img={srcLeft:0,srcTop:0,srcWidth:o.baseImgCanvas.width,srcHeight:o.baseImgCanvas.height,destLeft:this.currDestPoint.startX,destTop:this.currDestPoint.startY,destWidth:this.currDestPoint.width,destHeight:this.currDestPoint.height},"number"==typeof e&&(o.notify("draw",{prop:"setDestPoints",onPropertyChange:!1}),o.notify("draw",{prop:"setClientTransDim",onPropertyChange:!1,value:{isPreventDimension:null}})),o.notify("shape",{prop:"redrawObj",onPropertyChange:!1,value:{degree:e}}),o.currSelectionPoint=t.extend({},o.objColl[0],{},!0),this.currDestPoint={startX:o.img.destLeft,startY:o.img.destTop,width:o.img.destWidth,height:o.img.destHeight},o.objColl=r,o.activeObj=i,o.img={srcLeft:a.startX,srcTop:a.startY,srcWidth:a.width,srcHeight:a.height,destLeft:n.startX,destTop:n.startY,destWidth:n.width,destHeight:n.height}}},i.prototype.flipImage=function(e){var t=this.parent,o={direction:e,cancel:!1,previousDirection:t.toPascalCase(t.transform.currFlipState||e)};this.isPreventSelect||(t.trigger("flipping",o),t.editCompleteArgs=o),this.flipEvent(o,e)},i.prototype.flipEvent=function(e,o){var i=this.parent;if(e.cancel)return i.notify("draw",{prop:"setCurrentObj",onPropertyChange:!1,value:{obj:i.prevEventObjPoint}}),i.activeObj=i.prevEventSelectionPoint,void i.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate",obj:i.activeObj}});var r;if(t.isNullOrUndefined(this.transCurrObj)){var a={currObj:{}};i.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:a}}),(r=a.currObj).objColl=t.extend([],i.objColl,null,!0),r.pointColl=t.extend({},i.pointColl,null,!0),r.afterCropActions=t.extend([],i.afterCropActions,[],!0);var n={selPointColl:null};i.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:n}}),r.selPointColl=t.extend([],n.selPointColl,[],!0)}i.afterCropActions.push("horizontal"===o.toLowerCase()?"horizontalflip":"verticalflip");var s,l=[];i.activeObj.activePoint&&(void 0!==i.activeObj.shape&&(l=i.activeObj.shape.split("-")),(i.currObjType.isCustomCrop||"crop"===l[0])&&(s=i.currObjType.isCustomCrop?"custom":l[1],i.notify("shape",{prop:"updImgRatioForActObj",onPropertyChange:!1}),i.objColl.push(i.activeObj),i.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}))),i.notify("shape",{prop:"redrawActObj",onPropertyChange:!1,value:{x:null,y:null,isMouseDown:!0}}),i.clearContext(this.lowerContext),i.clearContext(this.upperContext);var p=t.extend([],i.objColl,[],!0),h=t.extend({},i.activeObj,{},!0);i.objColl=[],i.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),this.isReverseFlip||i.notify("draw",{prop:"updateCurrTransState",onPropertyChange:!1,value:{type:"initial",isPreventDestination:null,isRotatePan:null}});var d=o.toLowerCase();this.updateFlipState(d);var c=i.transform.currFlipState.toLowerCase();i.transform.currFlipState="horizontal"===d&&"horizontal"===c||"vertical"===d&&"vertical"===c?"":d;var u={isSelected:null};i.notify("draw",{prop:"getRotatedFlipCropSelection",onPropertyChange:!1,value:{bool:u}}),u.isSelected&&(i.img.destLeft+=i.panPoint.totalPannedInternalPoint.x,i.img.destTop+=i.panPoint.totalPannedInternalPoint.y);var v=this.lowerContext.filter;if(i.notify("draw",{prop:"drawImage",onPropertyChange:!1}),this.lowerContext.filter=v,i.notify("draw",{prop:"setImageEdited",onPropertyChange:!1}),this.updateFlipState(o.toLowerCase()),this.isReverseFlip||(i.notify("draw",{prop:"updateCurrTransState",onPropertyChange:!1,value:{type:"reverse",isPreventDestination:null,isRotatePan:null}}),this.updateFlipColl(o.toLocaleLowerCase()),i.rotateFlipColl.push(o.toLowerCase())),1===i.rotateFlipColl.length){var g={panRegion:""};i.notify("crop",{prop:"getCurrFlipState",onPropertyChange:!1,value:{panObj:g}}),""===g.panRegion?i.notify("draw",{prop:"setClientTransDim",onPropertyChange:!1,value:{isPreventDimension:null}}):this.setDestPointsForFlipState()}i.isCircleCrop&&i.notify("crop",{prop:"cropCircle",onPropertyChange:!1,value:{context:this.lowerContext,isSave:null,isFlip:null}}),i.objColl=t.extend([],p,[],!0),i.activeObj=t.extend({},h,{},!0);for(var f=0,C=i.objColl.length;f<C;f++){var b=i.objColl[f].flipObjColl;0===b.length?b.push(o):b[b.length-1]===o?b.pop():b.push(o)}i.notify("shape",{prop:"redrawObj",onPropertyChange:!1,value:{degree:o.toLowerCase()}});var m=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%)",i.notify("shape",{prop:"iterateObjColl",onPropertyChange:!1});var y=o.toLowerCase();"horizontal"===y||"vertical"===y?(i.notify("freehand-draw",{prop:"flipFHDColl",onPropertyChange:!1,value:{value:y}}),i.notify("freehand-draw",{prop:"freehandRedraw",onPropertyChange:!1,value:{context:this.lowerContext,points:null}})):i.notify("freehand-draw",{prop:"freehandRedraw",onPropertyChange:!1,value:{context:this.lowerContext,points:null}}),this.lowerContext.filter=m,i.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),this.updateCurrSelectionPoint(y),i.isUndoRedo=!1,i.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.lowerContext}}),i.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.upperContext}}),i.isCircleCrop&&i.notify("crop",{prop:"cropCircle",onPropertyChange:!1,value:{context:this.lowerContext,isSave:null,isFlip:null}}),s&&(this.upperContext.clearRect(0,0,i.upperCanvas.width,i.upperCanvas.height),i.activeObj=t.extend({},i.objColl[i.objColl.length-1],{},!0),i.objColl.pop(),i.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate",obj:i.activeObj}}));var P={collection:i.rotateFlipColl};i.notify("shape",{prop:"alignRotateFlipColl",onPropertyChange:!1,value:{collection:i.rotateFlipColl,isRotateFlipCollection:!0,obj:P}}),i.rotateFlipColl=P.collection,i.cropObj.activeObj.shape&&!this.isPreventSelect&&(i.notify("draw",{prop:"setIsCropSelect",value:{bool:!0}}),this.isPreventSelect=!0,i.notify("draw",{prop:"select",onPropertyChange:!1,value:{type:"custom",startX:null,startY:null,width:null,height:null}}),this.isPreventSelect=!1,i.setProperties({zoomSettings:{zoomFactor:1}},!0),this.prevZoomValue=i.zoomSettings.zoomFactor)},i.prototype.updateFlipState=function(e){var t=this.parent.transform.degree;"horizontal"===e?t%90==0&&t%180!=0?this.verticalFlip():this.horizontalFlip():"vertical"===e&&(t%90==0&&t%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(e){if(!this.isPreventSelect&&(0===this.flipColl.length||this.flipColl[this.flipColl.length-1]!==e?this.flipColl.push(e):this.flipColl.pop(),this.flipColl.length>=4)){var t=this.flipColl.slice(-4);("horizontal"===t[0]&&"vertical"===t[1]&&"horizontal"===t[2]&&"vertical"===t[3]||"vertical"===t[0]&&"horizontal"===t[1]&&"vertical"===t[2]&&"horizontal"===t[3])&&this.flipColl.splice(-4)}},i.prototype.setDestPointsForFlipState=function(){var e=this.parent,t={panRegion:""},o=e.img,i=o.destLeft,r=o.destTop,a=o.destWidth,n=o.destHeight,s=e.lowerCanvas,l=s.clientWidth,p=s.clientHeight;e.notify("crop",{prop:"getCurrFlipState",onPropertyChange:!1,value:{panObj:t}}),""!==t.panRegion&&("horizontal"===t.panRegion?e.img.destLeft=l-(a+i):"vertical"===t.panRegion?e.img.destTop=p-(n+r):(e.img.destLeft=l-(a+i),e.img.destTop=p-(n+r)))},i.prototype.zoomAction=function(e,o,i,r){var a=this.parent;if(!a.disabled&&a.isImageLoaded){if(t.isNullOrUndefined(i)&&(a.zoomSettings.zoomFactor>=a.zoomSettings.maxZoomFactor&&e>0||a.zoomSettings.zoomFactor>a.zoomSettings.minZoomFactor&&e<0&&this.disableZoomOutBtn(!0)||a.zoomSettings.zoomFactor<=a.zoomSettings.minZoomFactor&&e<0))return void a.notify("toolbar",{prop:"zoom-up-handler",onPropertyChange:!1});a.notify("draw",{prop:"setImageEdited",onPropertyChange:!1});var n=e;e=n>0?.1:-.1;for(var s=0;s<Math.round(Math.abs(n/.1));s++)if(1===this.prevZoomValue)this.prevZoomValue+=e>0?10*e:10*e/10;else if(this.prevZoomValue>1)this.prevZoomValue+=10*e;else if(this.prevZoomValue<1){this.prevZoomValue+=10*e/10;var l=Math.pow(10,1);this.prevZoomValue=Math.round(this.prevZoomValue*l)/l}e=n,a.setProperties({zoomSettings:{zoomFactor:this.prevZoomValue}},!0);var p=void 0;this.tempActiveObj=null,this.isShape=!1,void 0!==a.activeObj.shape&&("shape"===a.activeObj.shape?a.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}):p=a.activeObj.shape.split("-")),void 0!==p&&"crop"===p[0]?(this.tempActiveObj=t.extend({},a.activeObj,{},!0),a.isCropTab=!0):(a.activeObj.shape&&"crop"!==p[0]&&(0!==a.activeObj.activePoint.width||0!==a.activeObj.activePoint.height)||"path"===a.activeObj.shape&&a.activeObj.pointColl.length>0)&&(this.isShape=!0);var h={zoomType:null};a.notify("selection",{prop:"getZoomType",onPropertyChange:!1,value:{obj:h}}),t.isNullOrUndefined(o)&&(o=a.isCropTab&&this.tempActiveObj?{x:a.activeObj.activePoint.startX+a.activeObj.activePoint.width/2,y:a.activeObj.activePoint.startY+a.activeObj.activePoint.height/2}:{x:a.lowerCanvas.clientWidth/2,y:a.lowerCanvas.clientHeight/2},"MouseWheel"!==h.zoomType&&"Pinch"!==h.zoomType||(o={x:a.zoomSettings.zoomPoint.x,y:a.zoomSettings.zoomPoint.y}));var d={zoomPoint:o,cancel:!1,previousZoomFactor:a.zoomSettings.zoomFactor-10*e,currentZoomFactor:a.zoomSettings.zoomFactor,zoomTrigger:h.zoomType};!a.isCropToolbar&&a.isZoomBtnClick&&(a.trigger("zooming",d),a.editCompleteArgs=d),this.zoomEvent(d,e,r)}},i.prototype.zoomEvent=function(e,o,i){var r,a=this.parent,n=a.zoomSettings,s=n.zoomFactor,l=n.minZoomFactor;if(e.cancel)return void(a.isZoomBtnClick=!1);"blur"!==this.parent.activeObj.redactType&&"pixelate"!==this.parent.activeObj.redactType&&a.notify("toolbar",{prop:"close-contextual-toolbar",onPropertyChange:!1}),!a.isCropTab&&a.activeObj.shape&&(r=a.activeObj.currIndex),a.notify("shape",{prop:"redrawActObj",onPropertyChange:!1,value:{x:null,y:null,isMouseDown:!0}}),a.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),this.upperContext.clearRect(0,0,a.lowerCanvas.width,a.lowerCanvas.height);var p={canvasFilter:a.canvasFilter};this.lowerContext.filter=p.canvasFilter,a.upperCanvas.style.cursor=a.cursor="default";var h=t.extend([],a.objColl,[],!0);if(!a.isCropTab){if(0!==a.transform.degree){a.notify("shape",{prop:"redrawActObj",onPropertyChange:!1,value:{x:null,y:null,isMouseDown:null}}),a.panPoint.currentPannedPoint={x:0,y:0};C=a.allowDownScale;a.allowDownScale=!1,this.rotatePan(!0,!0),a.allowDownScale=C}else""!==a.transform.currFlipState&&(a.panPoint.totalPannedPoint={x:0,y:0});0!==a.transform.straighten||this.isPreventSelect||a.notify("freehand-draw",{prop:"updateFHDColl",onPropertyChange:!1,value:{isPreventApply:i}})}if(0===a.transform.degree){this.drawZoomImgToCanvas(o,this.tempActiveObj);var d={panRegion:""};if(a.notify("crop",{prop:"getCurrFlipState",onPropertyChange:!1,value:{panObj:d}}),""!==d.panRegion){a.notify("crop",{prop:"setTempFlipPanPoint",onPropertyChange:!1,value:{point:a.panPoint.totalPannedPoint,isAdd:!0}}),h=t.extend([],a.objColl,[],!0),a.objColl=[];var c=a.img.destLeft,u=a.img.destTop;this.setDestPointsForFlipState(),this.rotatedFlip(),a.img.destLeft=c,a.img.destTop=u,a.objColl=h,a.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"zoom",pen:"zoom",isPreventApply:i}}),0!==a.transform.straighten||this.isPreventSelect||a.notify("freehand-draw",{prop:"updateFHDColl",onPropertyChange:!1,value:{isPreventApply:i}})}s<=l&&!a.isCropTab&&(a.panPoint.totalPannedPoint={x:0,y:0})}else{0!==a.transform.straighten||this.isPreventSelect||a.notify("freehand-draw",{prop:"updateFHDColl",onPropertyChange:!1,value:{isPreventApply:i}}),a.panPoint.totalPannedClientPoint={x:0,y:0},a.panPoint.totalPannedInternalPoint={x:0,y:0},this.rotateZoom(o);var v={panRegion:""};if(a.notify("crop",{prop:"getCurrFlipState",onPropertyChange:!1,value:{panObj:v}}),""!==v.panRegion){C=this.lowerContext.filter;this.lowerContext.filter="none",a.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"zoom",pen:"zoom",isPreventApply:i}}),this.lowerContext.filter=C}}var g=Math.pow(10,1);(s<=l||Math.round(a.transform.zoomFactor*g)/g==2)&&(clearInterval(this.zoomBtnHold),this.zoomBtnHold=0);var f={panRegion:""};if(a.notify("crop",{prop:"getCurrFlipState",onPropertyChange:!1,value:{panObj:f}}),""===f.panRegion){var C=this.lowerContext.filter;this.lowerContext.filter="none",a.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"zoom",pen:"zoom",isPreventApply:i}}),this.lowerContext.filter=C}(a.currSelectionPoint&&"crop-circle"===a.currSelectionPoint.shape||a.isCircleCrop)&&a.notify("crop",{prop:"cropCircle",onPropertyChange:!1,value:{context:this.lowerContext,isSave:null,isFlip:null}}),a.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.lowerContext}}),a.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),this.tempActiveObj&&(a.activeObj=t.extend({},this.tempActiveObj,{},!0),a.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate",obj:a.activeObj}}),s<=l&&(a.currSelectionPoint=null)),a.isUndoRedo=!1;var b;(b=document.querySelector("#"+a.element.id+"_zoomOut"))&&s<=l?(b.classList.add("e-disabled"),b.parentElement.classList.add("e-overlay")):b&&(b.classList.remove("e-disabled"),b.parentElement.classList.remove("e-overlay"));var m=a.drawingShape;if(this.autoEnablePan(),a.drawingShape=m,this.tempActiveObj&&(a.activeObj=t.extend({},this.tempActiveObj,{},!0)),"crop-custom"===a.activeObj.shape&&(a.currObjType.isCustomCrop=!0),this.isShape){if(r){for(var y=0,P=a.objColl.length;y<P;y++)if(a.objColl[y].currIndex===r){a.activeObj=t.extend({},a.objColl[y],{},!0),a.objColl.splice(y,1);break}}else a.activeObj=t.extend({},a.objColl[a.objColl.length-1],{},!0),a.objColl.pop();a.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate",obj:a.activeObj,isCropRatio:null,points:null,isPreventDrag:!0,saveContext:null,isPreventSelection:null}}),a.notify("toolbar",{prop:"update-toolbar-items",onPropertyChange:!1}),a.notify("toolbar",{prop:"renderQAT",onPropertyChange:!1,value:{isPenEdit:null}})}if(a.notify("toolbar",{prop:"enable-disable-btns",onPropertyChange:!1}),a.notify("selection",{prop:"setZoomType",onPropertyChange:!1,value:{zoomType:"Toolbar"}}),e={zoomPoint:e.zoomPoint,previousZoomFactor:e.previousZoomFactor,currentZoomFactor:e.currentZoomFactor,zoomTrigger:e.zoomTrigger},!a.isCropToolbar&&a.isZoomBtnClick&&(a.isZoomBtnClick=!1),a.drawingShape){var j=t.extend({},a.activeObj,{},!0);if(a.enableShapeDrawing(a.toPascalCase(a.drawingShape),!0),a.activeObj=j,j.activePoint.width>0||j.activePoint.height>0||j.pointColl&&j.pointColl.length>0){"redact"===j.shape&&a.notify("toolbar",{prop:"renderQAT",onPropertyChange:!1,value:{isPenEdit:null}});var x=a.element.querySelector("#"+a.element.id+"_zOrderBtn"),w=a.element.querySelector("#"+a.element.id+"_duplicate"),O=a.element.querySelector("#"+a.element.id+"_remove"),S=a.element.querySelector("#"+a.element.id+"_editText");x&&x.classList.remove("e-overlay"),w&&w.classList.remove("e-overlay"),O&&O.classList.remove("e-overlay"),S&&S.classList.remove("e-overlay")}}else a.activeObj.shape&&"redact"===a.activeObj.shape&&(a.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"redact",isApplyBtn:!1,isCropping:!1}}),a.notify("toolbar",{prop:"renderQAT",onPropertyChange:!1,value:{isPenEdit:null}}))},i.prototype.disableZoomOutBtn=function(e){var o,i=this.parent,r=i.zoomSettings,a=r.zoomFactor,n=r.minZoomFactor,s=!1;t.isNullOrUndefined(e)||(i.transform.zoomFactor-=.1),o=i.element.querySelector("#"+i.element.id+"_zoomOut");var l={destLeft:i.img.destLeft,destTop:i.img.destTop,destWidth:i.img.destWidth,destHeight:i.img.destHeight};if(i.activeObj.shape){var p=this.setZoomDimension(-.1,i.activeObj);if(!t.isNullOrUndefined(o)){var h=i.activeObj.activePoint;if(0===i.transform.straighten)i.img.destLeft>h.startX||i.img.destTop>h.startY||i.img.destLeft+i.img.destWidth<h.endX||i.img.destTop+i.img.destHeight<h.endY||a===n?(o.classList.add("e-disabled"),o.parentElement.classList.add("e-overlay"),s=!0):(o.classList.remove("e-disabled"),o.parentElement.classList.remove("e-overlay"),s=!1);else{i.img.destWidth=p.width,i.img.destHeight=p.height;var d={isIntersect:null};i.notify("draw",{prop:"updateImgCanvasPoints",onPropertyChange:!1}),i.notify("draw",{prop:"isLinesIntersect",onPropertyChange:!1,value:{obj:d}}),d.isIntersect||a===n?(o.classList.add("e-disabled"),o.parentElement.classList.add("e-overlay"),s=!0):(o.classList.remove("e-disabled"),o.parentElement.classList.remove("e-overlay"),s=!1)}}}else this.setZoomDimension(-.1,null);return t.isNullOrUndefined(e)||(i.transform.zoomFactor+=.1),i.img.destLeft=l.destLeft,i.img.destTop=l.destTop,i.img.destWidth=l.destWidth,i.img.destHeight=l.destHeight,s},i.prototype.drawZoomImgToCanvas=function(e,t){var o=this.parent,i=Math.pow(10,1),r=Math.round(o.transform.zoomFactor*i)/i;.1===r&&-.1===e||0===r&&-.025===e?o.transform.zoomFactor=0:o.transform.zoomFactor+=e,o.transform[o.isCropTab?"cropZoomFactor":"defaultZoomFactor"]=o.transform.zoomFactor;var a={width:0,height:0};o.isCropTab?a=this.cropZoom(e,t):((a=this.calcMaxDimension(o.img.srcWidth,o.img.srcHeight)).width+=a.width*o.transform.zoomFactor,a.height+=a.height*o.transform.zoomFactor,o.img.destLeft=(o.lowerCanvas.clientWidth-a.width)/2,o.img.destTop=(o.lowerCanvas.clientHeight-a.height+1)/2),o.notify("draw",{prop:"draw-image-to-canvas",value:{dimension:a}}),a.width=this.cropDimension.width,a.height=this.cropDimension.height,a.width+=a.width*o.transform.zoomFactor,a.height+=a.height*o.transform.zoomFactor,o.notify("draw",{prop:"setZoomCropWidth",value:{width:a.width,height:a.height}})},i.prototype.rotatedFlip=function(){var e=this.parent;this.isReverseFlip=!0;var o=e.transform.currFlipState,i=this.flipColl,r=t.extend([],e.objColl,[],!0),a=t.extend({},e.activeObj,{},!0);this.flipColl=[],e.objColl=[],e.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),e.notify("draw",{prop:"currTransState",onPropertyChange:!1,value:{type:"initial",isPreventDestination:null,context:null,isPreventCircleCrop:null}});var n=this.lowerContext.filter;e.notify("draw",{prop:"drawImage",onPropertyChange:!1}),this.lowerContext.filter=n,e.notify("draw",{prop:"currTransState",onPropertyChange:!1,value:{type:"reverse",isPreventDestination:!0,context:null,isPreventCircleCrop:null}}),""===o&&""!==e.transform.currFlipState&&(o=e.transform.currFlipState),e.transform.currFlipState=o,this.flipColl=i,e.objColl=t.extend([],r,[],!0),this.lowerContext.filter="none",e.notify("shape",{prop:"iterateObjColl",onPropertyChange:!1}),this.lowerContext.filter=n,0!==a.activePoint.width&&(e.activeObj=t.extend({},a,{},!0)),this.isReverseFlip=!1},i.prototype.rotateZoom=function(e){var o=this.parent,i=Math.pow(10,1),r=Math.round(o.transform.zoomFactor*i)/i;.1===r&&-.1===e||0===r&&-.025===e?o.transform.zoomFactor=0:o.transform.zoomFactor+=e,o.isCropTab?o.transform.cropZoomFactor=o.transform.zoomFactor:o.transform.defaultZoomFactor=o.transform.zoomFactor;var a=t.extend([],o.objColl,[],!0),n=t.extend({},o.activeObj,{},!0);o.objColl=[],o.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),o.notify("draw",{prop:"updateCurrTransState",onPropertyChange:!1,value:{type:"initial",isPreventDestination:null,isRotatePan:null}}),o.notify("draw",{prop:"setRotateZoom",onPropertyChange:!1,value:{isRotateZoom:!0}}),o.notify("draw",{prop:"setDestPoints",onPropertyChange:!1});var s=this.lowerContext.filter;o.notify("draw",{prop:"drawImage",onPropertyChange:!1}),this.lowerContext.filter=s,o.notify("draw",{prop:"setRotateZoom",onPropertyChange:!1,value:{isRotateZoom:!1}}),o.notify("draw",{prop:"updateCurrTransState",onPropertyChange:!1,value:{type:"reverse",isPreventDestination:null,isRotatePan:null}}),o.objColl=a,o.activeObj=n;var l={width:this.cropDimension.width,height:this.cropDimension.height};l.width+=l.width*o.transform.zoomFactor,l.height+=l.height*o.transform.zoomFactor,o.notify("draw",{prop:"setZoomCropWidth",value:{width:l.width,height:l.height}})},i.prototype.autoEnablePan=function(){var e=this.parent;e.transform.zoomFactor<=0?(e.togglePan=!1,e.notify("selection",{prop:"setDragCanvas",value:{bool:!1}}),e.pan(!1),this.disablePan=!1):e.pan(!this.disablePan)},i.prototype.cropZoom=function(e,t){var o=this.parent,i=o.img.destLeft,r=o.img.destTop,a={width:0,height:0};return 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),a.width+=a.width*o.transform.zoomFactor,a.height+=a.height*o.transform.zoomFactor,o.img.destLeft=i-(a.width-o.img.destWidth)/2,o.img.destTop=r-(a.height-o.img.destHeight)/2,i=o.img.destLeft,r=o.img.destTop,t&&0===o.transform.straighten&&(o.img.destLeft>t.activePoint.startX&&(o.img.destLeft=t.activePoint.startX,0===o.transform.degree&&(o.panPoint.totalPannedPoint.x-=i-o.img.destLeft)),o.img.destTop>t.activePoint.startY&&(o.img.destTop=t.activePoint.startY,0===o.transform.degree&&(o.panPoint.totalPannedPoint.y-=r-o.img.destTop)),o.img.destLeft+a.width<t.activePoint.endX&&(o.img.destLeft=t.activePoint.endX-a.width,0===o.transform.degree&&(o.panPoint.totalPannedPoint.x-=i-o.img.destLeft)),o.img.destTop+a.height<t.activePoint.endY&&(o.img.destTop=t.activePoint.endY-a.height,0===o.transform.degree&&(o.panPoint.totalPannedPoint.y-=r-o.img.destTop))),a},i.prototype.setZoomDimension=function(e,o){var i=this.parent,r=i.transform.degree,a={width:0,height:0};if(a=r%90==0&&r%180!=0?this.calcMaxDimension(i.img.srcHeight,i.img.srcWidth):this.calcMaxDimension(i.img.srcWidth,i.img.srcHeight),a.width+=a.width*i.transform.zoomFactor,a.height+=a.height*i.transform.zoomFactor,i.img.destLeft+=(i.img.destWidth-a.width)/2,i.img.destTop+=(i.img.destHeight-a.height)/2,e<0&&o){var n=o.activePoint.startX,s=o.activePoint.startY,l=o.activePoint.width,p=o.activePoint.height,h=i.img.destLeft+a.width,d=i.img.destTop+a.height;i.img.destLeft>n&&(i.img.destLeft=n),i.img.destTop>s&&(i.img.destTop=s),h<n+l&&(i.img.destLeft=n+l-a.width),d<s+p&&(i.img.destTop=s+p-a.height)}else e<0&&t.isNullOrUndefined(o)&&(i.img.destLeft>0&&(i.img.destLeft=0),i.img.destTop>0&&(i.img.destTop=0),i.img.destLeft+a.width<i.lowerCanvas.clientWidth&&(i.img.destLeft=i.lowerCanvas.clientWidth-i.img.destWidth),i.img.destTop+a.height<i.lowerCanvas.clientHeight&&(i.img.destTop=i.lowerCanvas.clientHeight-i.img.destHeight));return a},i.prototype.drawPannedImage=function(e,t){var o=this.parent,i={panDown:null};o.notify("selection",{prop:"getPanDown",onPropertyChange:!1,value:{obj:i}});var r={startPoint:i.panDown,endPoint:this.panMove,cancel:!1};o.trigger("panning",r),r.cancel||this.panEvent(e,t)},i.prototype.panEvent=function(e,o,i){var r=this.parent,a=!1;if(r.activeObj.shape&&"shape"===r.activeObj.shape&&r.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),t.isNullOrUndefined(r.activeObj.shape)){a=!0;var n=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},s=n.startX,l=n.startY,p=n.endX,h=n.endY;s<0&&(n.startX=0),l<0&&(n.startY=0),p>r.lowerCanvas.width&&(n.endX=r.lowerCanvas.width),h>r.lowerCanvas.height&&(n.endY=r.lowerCanvas.height),n.width=n.endX-n.startX,n.height=n.endY-n.startY,r.activeObj.shape="crop-custom";var d={strokeSettings:{}};r.notify("shape",{prop:"getStrokeSettings",onPropertyChange:!1,value:{obj:d}}),r.activeObj.strokeSettings=d.strokeSettings,r.notify("draw",{prop:"updateActiveObject",onPropertyChange:!1,value:{actPoint:n,obj:r.activeObj,isMouseMove:null,x:null,y:null}}),r.isCropTab=!0}if(0===r.transform.degree){var c=void 0;c=t.isNullOrUndefined(e)&&t.isNullOrUndefined(o)||i?i?this.updatePanPoints(e,o):this.updatePanPoints():{x:e,y:o},r.panPoint.totalPannedPoint.x+=c.x,r.panPoint.totalPannedPoint.y+=c.y;var u=t.extend({},r.activeObj,{},!0),v=this.lowerContext.filter;this.drawPannImage(c,a),this.lowerContext.filter=v,this.tempPanMove=t.extend({},this.panMove,{},!0),r.activeObj=t.extend({},u,{},!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 g=r.transform.currFlipState;r.isCropTab=!0,t.isNullOrUndefined(e)&&t.isNullOrUndefined(o)||i?r.panPoint.currentPannedPoint=i?this.updatePanPoints(e,o):this.updatePanPoints():r.panPoint.currentPannedPoint={x:e,y:o},r.transform.currFlipState=g,this.rotatePan(null,null,a),r.isCropTab=!1,this.tempPanMove=t.extend({},this.panMove,{},!0)}a&&(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(e,t){var o=this.parent,i=this.lowerContext.filter,r={startX:o.img.destLeft,startY:o.img.destTop,width:o.img.destWidth,height:o.img.destHeight};this.lowerContext.clearRect(0,0,o.lowerCanvas.width,o.lowerCanvas.height),o.notify("draw",{prop:"updateCurrTransState",onPropertyChange:!1,value:{type:"initial",isPreventDestination:null,isRotatePan:null}}),o.img.destLeft=r.startX,o.img.destTop=r.startY,o.img.destWidth=r.width,o.img.destHeight=r.height,this.setDestPointsForFlipState(),t&&(o.isCropTab=!1),o.notify("draw",{prop:"drawImage",onPropertyChange:!1}),t&&(o.isCropTab=!0),(o.currSelectionPoint&&"crop-circle"===o.currSelectionPoint.shape||o.isCircleCrop)&&o.notify("crop",{prop:"cropCircle",onPropertyChange:!1,value:{context:this.lowerContext,isSave:null,isFlip:!0}}),this.lowerContext.filter=i,o.notify("draw",{prop:"updateCurrTransState",onPropertyChange:!1,value:{type:"reverse",isPreventDestination:null,isRotatePan:null}}),o.img.destLeft=r.startX,o.img.destTop=r.startY,o.img.destWidth=r.width,o.img.destHeight=r.height;var a=this.lowerContext.filter;this.lowerContext.filter="none",t&&(o.isCropTab=!1),o.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"pan",pen:"pan",x:e.x,y:e.y,panRegion:""}}),t&&(o.isCropTab=!0),this.lowerContext.filter=a,o.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.lowerContext}}),o.isCircleCrop&&o.notify("crop",{prop:"cropCircle",onPropertyChange:!1,value:{context:this.lowerContext,isSave:null,isFlip:!0}})},i.prototype.resetZoom=function(){var e=this.parent;if(0!==e.transform.defaultZoomFactor){var o=e.isUndoRedo,i={currObj:{}};e.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:i}}),this.transCurrObj=i.currObj,this.transCurrObj.objColl=t.extend([],e.objColl,null,!0),this.transCurrObj.pointColl=t.extend({},e.pointColl,null,!0),this.transCurrObj.afterCropActions=t.extend([],e.afterCropActions,[],!0);var r={selPointColl:null};e.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:r}}),this.transCurrObj.selPointColl=t.extend([],r.selPointColl,[],!0),e.isUndoRedo=e.isCropToolbar=!0;var a=e.transform.defaultZoomFactor;a>0?this.zoomAction(-a):this.zoomAction(Math.abs(a)),e.isCropToolbar=!1,e.isUndoRedo=o}},i.prototype.performTransformation=function(e){var t=this.parent;this.resetZoom(),this.updateTransform(e);for(var o=0,i=t.objColl.length;o<i;o++)if(t.objColl[o].flipObjColl.length>0){var r={collection:t.objColl[o].flipObjColl};t.notify("shape",{prop:"alignRotateFlipColl",onPropertyChange:!1,value:{collection:r.collection,isRotateFlipCollection:null,obj:r}}),t.objColl[o].flipObjColl=r.collection,0===t.objColl[o].flipObjColl.length&&(t.objColl[o].shapeFlip="")}},i.prototype.updateTransform=function(t){switch(t.toLowerCase()){case"rotateleft":this.rotateImage(-90);break;case"rotateright":this.rotateImage(90);break;case"horizontalflip":this.flipImage(e.Direction.Horizontal);break;case"verticalflip":this.flipImage(e.Direction.Vertical)}},i.prototype.rotatePan=function(e,o,i){var r=this.parent;this.isReverseRotate=!0;var a,n=r.transform.degree,s={selPointColl:null};r.activeObj.activePoint&&r.activeObj.shape&&(a=t.extend({},r.activeObj,{},!0));var l=t.extend([],r.objColl,[],!0),p=t.extend([],r.pointColl,[],!0);r.objColl=[],r.pointColl=[],r.freehandCounter=0,r.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:s}});var h=s.selPointColl;r.notify("freehand-draw",{prop:"setSelPointColl",onPropertyChange:!1,value:{obj:{selPointColl:[]}}}),r.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),r.notify("draw",{prop:"setRotateZoom",onPropertyChange:!1,value:{isRotateZoom:!0}}),r.notify("draw",{prop:"updateCurrTransState",onPropertyChange:!1,value:{type:"initial",isPreventDestination:null,isRotatePan:null}});var d=r.img.destLeft,c=r.img.destTop,u=r.panPoint.totalPannedInternalPoint;r.isCropTab&&(r.img.destLeft+=u.x,r.img.destTop+=u.y),r.notify("crop",{prop:"updateRotatePan",onPropertyChange:!1}),r.isCropTab&&(r.panPoint.totalPannedInternalPoint.x=r.img.destLeft-d,r.panPoint.totalPannedInternalPoint.y=r.img.destTop-c);var v=this.lowerContext.filter;i&&(r.isCropTab=!1),r.notify("draw",{prop:"drawImage",onPropertyChange:!1}),i&&(r.isCropTab=!0),r.notify("draw",{prop:"setRotateZoom",onPropertyChange:!1,value:{isRotateZoom:!1}}),r.notify("draw",{prop:"updateCurrTransState",onPropertyChange:!1,value:{type:"reverse",isPreventDestination:!0,isRotatePan:!0}});var g=r.img.destLeft,f=r.img.destTop;r.img.destLeft+=r.panPoint.totalPannedClientPoint.x,r.img.destTop+=r.panPoint.totalPannedClientPoint.y,r.img.destLeft+=r.panPoint.currentPannedPoint.x,r.img.destTop+=r.panPoint.currentPannedPoint.y,r.panPoint.totalPannedClientPoint.x=r.img.destLeft-g,r.panPoint.totalPannedClientPoint.y=r.img.destTop-f,r.objColl=l,r.pointColl=p,r.freehandCounter=r.pointColl.length,r.notify("freehand-draw",{prop:"setSelPointColl",onPropertyChange:!1,value:{obj:{selPointColl:h}}}),r.transform.degree=n,this.lowerContext.filter="none",e&&(o?(r.panPoint.totalPannedClientPoint.x=-r.panPoint.totalPannedClientPoint.x,r.panPoint.totalPannedClientPoint.y=-r.panPoint.totalPannedClientPoint.y,r.panPoint.currentPannedPoint=t.extend({},r.panPoint.totalPannedClientPoint,{},!0),r.panPoint.totalPannedClientPoint={x:0,y:0},r.img.destLeft+=r.panPoint.currentPannedPoint.x,r.img.destTop+=r.panPoint.currentPannedPoint.y):r.panPoint.currentPannedPoint=t.extend({},r.panPoint.totalPannedClientPoint,{},!0)),i&&(r.isCropTab=!1),r.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"pan",pen:"pan",x:r.panPoint.currentPannedPoint.x,y:r.panPoint.currentPannedPoint.y,panRegion:""}}),i&&(r.isCropTab=!0),this.lowerContext.filter=v,r.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.lowerContext}}),this.upperContext.clearRect(0,0,r.upperCanvas.width,r.upperCanvas.height),r.activeObj=t.extend({},a,{},!0),r.activeObj.activePoint&&r.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate",obj:r.activeObj,isCropRatio:null,points:null,isPreventDrag:!0,saveContext:null,isPreventSelection:null}}),this.isReverseRotate=!1},i.prototype.limitPan=function(){var e=this.parent,t=e.activeObj.activePoint,o=t.startX,i=t.startY,r=t.endX,a=t.endY,n=e.img;e.activeObj.activePoint&&(n.destLeft>o&&(e.img.destLeft=o),n.destTop>i&&(e.img.destTop=i),n.destLeft+n.destWidth<r&&(e.img.destLeft=r-n.destWidth),n.destTop+n.destHeight<a&&(e.img.destTop=a-n.destHeight))},i.prototype.pan=function(e,o,i){var r=this.parent;!r.disabled&&r.isImageLoaded&&(e?(r.togglePan=!0,r.notify("shape",{prop:"redrawActObj",onPropertyChange:!1,value:{x:null,y:null,isMouseDown:null}}),r.notify("selection",{prop:"setDragCanvas",value:{bool:!0}}),r.lowerCanvas.style.cursor=r.upperCanvas.style.cursor=r.cursor="grab",r.notify("selection",{prop:"setPanDown",onPropertyChange:!1,value:{panDown:null}}),(o||i)&&(o=o||0,i=i||0,t.isNullOrUndefined(this.panMove)&&(this.panMove={x:o,y:i}),t.isNullOrUndefined(this.tempPanMove)&&(this.tempPanMove={x:this.panMove.x,y:this.panMove.y}),this.panEvent(o,i,!0),this.tempPanMove=null)):(r.togglePan=r.currObjType.isCustomCrop=!1,r.notify("selection",{prop:"setDragCanvas",value:{bool:!1}}),r.lowerCanvas.style.cursor=r.upperCanvas.style.cursor=r.cursor="default"))},i.prototype.zoom=function(e,o){var i=this.parent;if(!i.disabled&&i.isImageLoaded){var r=this.getCurrentZoomFactor(e);if(t.isNullOrUndefined(o))this.zoomAction(r,o);else for(var a=r>0?"zoomIn":"zoomOut",n=10*Math.abs(r),s=0;s<n;s++)i.notify("draw",{prop:"performPointZoom",onPropertyChange:!1,value:{x:o.x,y:o.y,type:a,isResize:null}});var l={action:r>0?"zoom-in":"zoom-out",actionEventArgs:i.editCompleteArgs};i.triggerEditCompleteEvent(l)}},i.prototype.getCurrentZoomFactor=function(e){return e>=1?this.prevZoomValue<1?e-this.prevZoomValue:.1*(e-this.prevZoomValue):e-this.prevZoomValue},i.prototype.setCurrPanRegion=function(e,t,o){var i=e;i=""===e?"horizontal"===t?"horizontal":"vertical"===t?"vertical":e:"horizontal"===e?"horizontal"===t?"horizontalVertical":"vertical"===t?"verticalHorizontal":90===t?"vertical":-90===t?"horizontal":e:"vertical"===e?"horizontal"===t?"horizontalVertical":"vertical"===t?"verticalHorizontal":90===t?"horizontal":-90===t?"vertical":e:"horizontal"===t?"vertical":"vertical"===t?"horizontal":e,o.panRegion=i},i.prototype.rotate=function(e,t){var o=this.parent;!o.disabled&&o.isImageLoaded&&e%90==0&&this.rotateImage(e),t.isRotate=!1},i.prototype.flip=function(e){var t=this.parent;!t.disabled&&t.isImageLoaded&&this.flipImage(e)},i.prototype.update=function(){var e=this.parent,i=0,r=!1,a={bool:!1},n={bool:e.isStraightening},s=0,l=e.element.querySelector("#"+e.element.id+"_contextualToolbar"),p=e.element.querySelector(".e-contextual-toolbar-wrapper"),h=e.element.querySelector("#"+e.element.id+"_headWrapper");if(e.isImageLoaded){var d=!1,c=void 0;t.Browser.isDevice&&(e.activeObj.shape&&(c=e.activeObj.shape.split("-")),e.currObjType.isCustomCrop?d=!0:c&&"crop"===c[0]&&(d=!0));var u={bool:null};e.notify("toolbar",{prop:"getFrameToolbar",onPropertyChange:!1,value:{obj:u}}),!n.bool&&(l&&!l.parentElement.classList.contains("e-hide")||h&&!h.parentElement.classList.contains("e-hide"))&&(p.classList.add("e-hide"),d||e.okBtn(null,!0),e.notify("toolbar",{prop:"refresh-main-toolbar",onPropertyChange:!1}),e.notify("toolbar",{prop:"destroy-qa-toolbar",onPropertyChange:!1})),e.notify("selection",{prop:"getFreehandDrawEditing",onPropertyChange:!1,value:{obj:a}}),a.bool&&e.notify("toolbar",{prop:"destroy-qa-toolbar",onPropertyChange:!1});var v=t.extend({},e.activeObj.activePoint,{},!0);!e.activeObj.shape||0===v.width&&0===v.height||(r=!0,"block"===e.textArea.style.display||"inline-block"===e.textArea.style.display?(e.notify("shape",{prop:"redrawActObj",onPropertyChange:!1,value:{x:null,y:null,isMouseDown:null}}),e.notify("toolbar",{prop:"destroy-qa-toolbar",onPropertyChange:!1})):(e.notify("shape",{prop:"updImgRatioForActObj",onPropertyChange:!1}),e.objColl.push(e.activeObj)),e.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}))}var g=this.lowerContext.filter,f=e.element.querySelector("#"+e.element.id+"_canvasWrapper");if(f&&(f.style.width=e.element.offsetWidth-2+"px"),e.lowerCanvas.width=e.upperCanvas.width=e.maskCanvas.width=e.element.offsetWidth-2,e.toolbarTemplate)i=e.element.querySelector("#"+e.element.id+"_toolbarArea").clientHeight;else if(e.element.querySelector("#"+e.element.id+"_toolbar")&&0===(i=e.element.querySelector("#"+e.element.id+"_toolbar").clientHeight)&&e.toolbar&&e.toolbar.length>0&&-1===e.toolbar.indexOf("Open")){m={toolbarHeight:0};e.notify("toolbar",{prop:"getToolbarHeight",value:{obj:m}}),i=m.toolbarHeight}var C=e.element.querySelector("#"+e.element.id+"_contextualToolbarArea");if(t.Browser.isDevice&&n.bool&&C&&(s=C.clientHeight),e.notify("toolbar",{prop:"setToolbarHeight",value:{height:i}}),t.Browser.isDevice?f&&(f.style.height=e.element.offsetHeight-(2*i+s)-4+"px"):f&&(f.style.height=e.element.offsetHeight-i-2+"px"),e.lowerCanvas.height=e.upperCanvas.height=parseFloat(f.style.height),this.lowerContext.filter="brightness(1) contrast(100%) hue-rotate(0deg) saturate(100%) opacity(1) blur(0px) sepia(0%) grayscale(0%) invert(0%)",e.notify("filter",{prop:"setAdjustmentValue",onPropertyChange:!1,value:{adjustmentValue:this.lowerContext.filter}}),e.canvasFilter=this.lowerContext.filter,e.initialAdjustmentValue=this.lowerContext.filter,e.clearContext(this.lowerContext),e.clearContext(this.upperContext),e.isImageLoaded){if(e.notify("shape",{prop:"applyActObj",onPropertyChange:!1,value:{isMouseDown:null}}),e.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),this.lowerContext.filter=g,e.initialAdjustmentValue=g,e.canvasFilter=this.lowerContext.filter,e.isImageLoaded&&(o.showSpinner(e.element),e.element.style.opacity="0.5"),this.lowerContext.clearRect(0,0,e.lowerCanvas.width,e.lowerCanvas.height),this.upperContext.clearRect(0,0,e.upperCanvas.width,e.upperCanvas.height),f){f.style.width=e.element.offsetWidth-2+"px",f.style.height=e.element.offsetHeight+"px";var b={toolbarHeight:0};e.notify("toolbar",{prop:"getToolbarHeight",value:{obj:b}}),t.Browser.isDevice?f.style.height=parseFloat(f.style.height)-2*b.toolbarHeight-s-4+"px":f.style.height=parseFloat(f.style.height)-b.toolbarHeight-2+"px"}e.lowerCanvas.width=e.upperCanvas.width=e.maskCanvas.width=parseFloat(f.style.width),e.lowerCanvas.height=e.upperCanvas.height=e.maskCanvas.height=parseFloat(f.style.height),this.lowerContext.filter=g;var m={width:0,height:0};this.calcMaxDimension(e.img.srcWidth,e.img.srcHeight,m);var y=m;if(n.bool&&0!==e.transform.cropZoomFactor?(y.width+=y.width*e.transform.cropZoomFactor,y.height+=y.height*e.transform.cropZoomFactor):e.transform.defaultZoomFactor>0&&(y.width+=y.width*e.transform.defaultZoomFactor,y.height+=y.height*e.transform.defaultZoomFactor),e.img.destLeft=(e.lowerCanvas.clientWidth-y.width)/2,e.img.destTop=(e.lowerCanvas.clientHeight-y.height+1)/2,0===e.transform.degree&&""===e.transform.currFlipState)e.transform.defaultZoomFactor>0&&(e.img.destLeft+=e.panPoint.totalPannedPoint.x,e.img.destTop+=e.panPoint.totalPannedPoint.y),e.notify("draw",{prop:"draw-image-to-canvas",value:{dimension:y}});else{e.notify("draw",{prop:"draw-image-to-canvas",value:{dimension:y}}),e.notify("draw",{prop:"updateCurrTransState",onPropertyChange:!1,value:{type:"initial",isPreventDestination:null,isRotatePan:null}});var P=this.lowerContext.filter;e.notify("draw",{prop:"drawImage",onPropertyChange:!1}),this.lowerContext.filter=P,e.notify("draw",{prop:"updateCurrTransState",onPropertyChange:!1,value:{type:"reverse",isPreventDestination:null,isRotatePan:null}})}e.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"zoom",pen:"zoom",isPreventApply:null}}),e.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.lowerContext}}),e.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.upperContext}}),e.isCircleCrop&&e.notify("crop",{prop:"cropCircle",onPropertyChange:!1,value:{context:this.lowerContext,isSave:null,isFlip:null}}),o.hideSpinner(e.element),e.element.style.opacity="1";var j={defToolbarItems:null};if(e.notify("toolbar",{prop:"getDefToolbarItems",value:{obj:j}}),j.defToolbarItems&&j.defToolbarItems.length>0&&document.getElementById(e.element.id+"_toolbar")){var x=t.getComponent(e.element.id+"_toolbar","toolbar");x&&x.refreshOverflow(),p&&!n.bool&&p.classList.add("e-hide")}if(e.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),this.upperContext.clearRect(0,0,e.upperCanvas.width,e.upperCanvas.height),r){var w=t.extend({},e.objColl[e.objColl.length-1],null,!0);e.objColl.pop(),0!==w.activePoint.width&&0!==w.activePoint.height&&(this.lowerContext.clearRect(0,0,e.lowerCanvas.width,e.lowerCanvas.height),e.notify("draw",{prop:"render-image",value:{isMouseWheel:null}}),e.objColl.push(w),e.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"zoom",pen:"zoom",isPreventApply:null}}),w=t.extend({},e.objColl[e.objColl.length-1],null,!0),e.objColl.pop(),this.lowerContext.clearRect(0,0,e.lowerCanvas.width,e.lowerCanvas.height),e.notify("draw",{prop:"render-image",value:{isMouseWheel:null}}),e.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate",obj:w}}),n.bool&&e.notify("draw",{prop:"setStraightenActObj",value:{activeObj:w}}),"rectangle"!==e.activeObj.shape&&"ellipse"!==e.activeObj.shape&&"text"!==e.activeObj.shape&&"line"!==e.activeObj.shape&&"arrow"!==e.activeObj.shape&&"path"!==e.activeObj.shape&&"image"!==e.activeObj.shape||e.notify("toolbar",{prop:"renderQAT",onPropertyChange:!1,value:{isPenEdit:null}}))}if(a.bool&&e.notify("toolbar",{prop:"renderQAT",onPropertyChange:!1,value:{isPenEdit:!0}}),e.isResize&&(e.aspectWidth=Math.ceil(e.img.destWidth),e.aspectHeight=Math.ceil(e.img.destHeight),e.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"resize",isApplyBtn:!1,isCropping:!1}}),e.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"resize",isApplyBtn:!1,isCropping:!1}})),(0!==e.transform.degree||""!==e.transform.currFlipState)&&e.transform.defaultZoomFactor>0){var O=t.extend({},e.panPoint.totalPannedPoint,null,!0),S=t.extend({},e.panPoint.totalPannedInternalPoint,null,!0),T=t.extend({},e.panPoint.totalPannedClientPoint,null,!0);this.zoomAction(.1),this.zoomAction(-.1),0===e.transform.degree?(e.img.destLeft+=O.x,e.img.destTop+=O.y,e.panPoint.totalPannedPoint=O,e.notify("draw",{prop:"updateFlipPan",value:{tempSelectionObj:null}})):(e.panPoint.totalPannedInternalPoint=S,e.panPoint.totalPannedClientPoint=T,e.panPoint.currentPannedPoint={x:0,y:0},e.isCropTab=!0,this.rotatePan(),e.isCropTab=!1)}else 0!==e.transform.degree&&e.transform.cropZoomFactor>0&&(e.transform.zoomFactor=0,e.transform.cropZoomFactor=null,e.notify("toolbar",{prop:"enable-disable-btns",onPropertyChange:!1}))}},i.prototype.calcMaxDimension=function(e,o,i,r){var a={toolbarHeight:0},n=this.parent;n.notify("toolbar",{prop:"getToolbarHeight",value:{obj:a}});var s=r?n.element.clientWidth/3:n.element.clientWidth,l=r?(n.element.clientHeight-a.toolbarHeight)/3:n.element.clientHeight-a.toolbarHeight;if(l=t.Browser.isDevice?l-a.toolbarHeight:l,t.Browser.isDevice&&n.isStraightening){var p=n.element.querySelector("#"+n.element.id+"_contextualToolbarArea");l-=p?p.clientHeight:0}r||0!==n.element.clientHeight||(l=0),t.isNullOrUndefined(r)&&(s>30&&(s-=30),l>30&&(l-=30));var h=s/e,d=l/o,c=Math.min(e,s),u=Math.min(o,l);if(h<1&&h<d?(c=e*h,u=o*h):d<1&&d<h&&(c=e*d,u=o*d),t.isNullOrUndefined(r)){var v={bool:null};n.notify("crop",{prop:"getPreventScaling",onPropertyChange:!1,value:{obj:v}}),v.bool&&n.cropObj.activeObj.activePoint&&0!==n.cropObj.activeObj.activePoint.width&&0!==n.cropObj.activeObj.activePoint.height&&(c=n.cropObj.activeObj.activePoint.width,u=n.cropObj.activeObj.activePoint.height)}return i&&(i.width=c,i.height=u),{width:c,height:u}},i.prototype.updatePanPoints=function(e,o){var i=this.parent,r=t.extend({},i.activeObj,{},!0),a=i.img.destLeft,n=i.img.destTop;t.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;(e||o)&&(s=e,l=o),i.img.destLeft+=s,i.img.destTop+=l,this.limitPan();var p={bool:null},h={isIntersect:null};i.notify("draw",{prop:"updateImgCanvasPoints",onPropertyChange:!1}),i.notify("draw",{prop:"isLinesIntersect",onPropertyChange:!1,value:{obj:h}}),i.notify("draw",{prop:"isSelOutsideImg",onPropertyChange:!1,value:{obj:p}});for(var d=0;0!==i.transform.straighten&&(h.isIntersect||p.bool)&&(d++,i.img.destLeft=a,i.img.destTop=n,0!==s&&s>0?s-=1:0!==s&&s<0&&(s+=1),0!==l&&l>0?l-=1:0!==l&&l<0&&(l+=1),(0!==s||0!==l)&&200!==d);)i.img.destLeft+=s,i.img.destTop+=l,this.limitPan(),i.notify("draw",{prop:"updateImgCanvasPoints",onPropertyChange:!1}),i.notify("draw",{prop:"isLinesIntersect",onPropertyChange:!1,value:{obj:h}}),i.notify("draw",{prop:"isSelOutsideImg",onPropertyChange:!1,value:{obj:p}});return i.activeObj=r,{x:i.img.destLeft-a,y:i.img.destTop-n}},i.prototype.resizeImage=function(e,o){var i=this.parent,r=!0,a=!0;i.allowDownScale=!1,i.img.srcLeft=0,i.img.srcTop=0,i.isAspectRatio=!0;var n=[];for(i.img.srcWidth=i.baseImgCanvas.width,i.img.srcHeight=i.baseImgCanvas.height,i.resizeSrc&&0!==i.resizeSrc.width&&0!==i.resizeSrc.height&&(i.img.srcLeft=i.resizeSrc.startX,i.img.srcTop=i.resizeSrc.startY,i.img.srcWidth=i.resizeSrc.width,i.img.srcHeight=i.resizeSrc.height);(e<i.img.destWidth||o<i.img.destHeight)&&a;)if(this.zoomAction(-.1,null,!0,!0),e>i.img.destWidth||o>i.img.destHeight)for(;e>i.img.destWidth||o>i.img.destHeight;)this.zoomAction(.0125,null,!0,!0),a=!1,n.push(i.img.destWidth);for(;(e>i.img.destWidth||o>i.img.destHeight)&&a&&r;)if(this.zoomAction(.1,null,!0,!0),e<i.img.destWidth||o<i.img.destHeight)for(;e<i.img.destWidth;)this.zoomAction(-.0125,null,!0,!0),r=!1,n.push(i.img.destWidth);for(var s=n[0],l=Math.abs(i.img.destWidth-s),p=0,h=n;p<h.length;p++){var d=h[p],c=Math.abs(e-d);c<l&&(s=d,l=c)}s<e&&r&&(this.zoomAction(-.0125,null,!0,!0),r=!1),s>e&&!r&&(this.zoomAction(.0125,null,!0,!0),r=!1),this.zoomAction(.0125,null,!0),i.allowDownScale=!0,this.zoomAction(-.0125,null,!0);var u=t.extend({},i.cropObj,{},!0),v=t.extend({},this.prevResizeCurrObj,{},!0);i.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"resize",previousObj:v,previousObjColl:v.objColl,previousPointColl:v.pointColl,previousSelPointColl:v.selPointColl,previousCropObj:u,previousText:null,currentText:null,previousFilter:null,isCircleCrop:i.isCircleCrop}}),i.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"ok"}})},i.prototype.resizeCrop=function(e,o){var i=this.parent,r=!0,a={prevObj:i.prevObj};i.cropObj=t.extend({},i.prevCropObj,{},!0),i.allowDownScale=!1,i.notify("toolbar",{prop:"getPrevObj",onPropertyChange:!1,value:{obj:a}});var n=t.extend({},a.prevObj.activeObj,{},!0);a.prevObj.activeObj=t.extend({},i.activeObj,{},!0),i.notify("draw",{prop:"setCurrentObj",onPropertyChange:!1,value:{obj:a.prevObj}}),i.objColl=t.extend([],a.prevObj.objColl,[],!0),i.pointColl=t.extend([],a.prevObj.pointColl,[],!0),i.transform.straighten=0,i.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"zoom",pen:"zoom",isPreventApply:null}}),0!==i.transform.straighten||this.isPreventSelect||i.notify("freehand-draw",{prop:"updateFHDColl",onPropertyChange:!1});var s=e,l=o,p=!1;if(o>=e&&o<=Math.ceil(i.img.destHeight)){for(;o<=Math.ceil(i.img.destHeight)&&r;)if(this.zoomAction(-.1,null,!0,!0),e>i.img.destWidth||o>i.img.destHeight)for(;e>i.img.destWidth||o>i.img.destHeight;)this.zoomAction(.0125,null,!0,!0),r=!1}else if(o<=e&&e<i.img.destWidth){for(;e<i.img.destWidth&&r;)if(this.zoomAction(-.1,null,!0,!0),e>i.img.destWidth||o>i.img.destHeight)for(;e>i.img.destWidth||o>i.img.destHeight;)this.zoomAction(.0125,null,!0,!0),r=!1}else if(o>=e&&o>=i.img.destHeight)for(;o>=i.img.destHeight&&r;)this.zoomAction(.1,null,!0,!0);else if(e>=o&&e>=i.img.destWidth){for(;e>=i.img.destWidth&&r;)this.zoomAction(.1,null,!0,!0);if(e<i.img.destWidth&&o<i.img.destHeight){for(;e<i.img.destWidth&&o<i.img.destHeight;)this.zoomAction(-.0125,null,!0,!0),r=!1;this.zoomAction(.0125,null,!0,!0)}}else if(o>i.img.destHeight&&e>i.img.destWidth){for(;o>i.img.destHeight&&e>i.img.destWidth&&r;)this.zoomAction(.1,null,!0,!0);if(e<i.img.destWidth&&o<i.img.destHeight){for(;e<i.img.destWidth&&o<i.img.destHeight;)this.zoomAction(-.0125,null,!0,!0),r=!1;this.zoomAction(.0125,null,!0,!0)}}if(this.resizeImg(n,e,o),e=s,(o=l)!==i.img.destHeight||e!==i.img.destWidth){for(;o>i.img.destHeight||e>i.img.destWidth;)this.zoomAction(.0125,null,!0,!0),p=!0;p&&(this.zoomAction(-.0125,null,!0,!0),p=!1)}if(o!==i.img.destHeight||e!==i.img.destWidth){for(;o<i.img.destHeight||e<i.img.destWidth;)this.zoomAction(-.0125,null,!0,!0),p=!0;p&&(this.zoomAction(-.0125,null,!0,!0),p=!1)}a.prevObj.activeObj=t.extend({},n,{},!0),this.zoomAction(.0125,null,!0),i.allowDownScale=!this.preventDownScale,i.isCropTab=!1,this.zoomAction(-.0125,null,!0),i.aspectWidth=e,i.aspectHeight=o},i.prototype.resizeImg=function(e,o,i){var r=this.parent,a=o/r.img.destWidth,n=i/r.img.destHeight;e.shape?(r.currSelectionPoint=e,r.notify("crop",{prop:"setInitCrop",onPropertyChange:!1,value:{bool:!0}})):r.img.srcWidth===r.baseImgCanvas.width&&r.img.srcHeight===r.baseImgCanvas.height&&(r.currSelectionPoint=null,r.notify("draw",{prop:"select",onPropertyChange:!1,value:{type:"custom",startX:null,startY:null,width:null,height:null}})),t.isNullOrUndefined(r.currSelectionPoint)?r.notify("draw",{prop:"select",onPropertyChange:!1,value:{type:"custom",startX:r.img.destLeft,startY:r.img.destTop,width:r.img.destWidth,height:r.img.destHeight}}):r.notify("draw",{prop:"select",onPropertyChange:!1,value:{type:"custom",startX:null,startY:null,width:null,height:null}}),o=r.activeObj.activePoint.width*a,i=r.activeObj.activePoint.height*n;for(var s=r.activeObj.activePoint.startX+r.activeObj.activePoint.width/2-o/2,l=r.activeObj.activePoint.startY+r.activeObj.activePoint.height/2-i/2,p=0;t.Browser.isDevice&&p<500&&(s<0||l<0||s+o>r.img.destWidth||l+i>r.img.destHeight);)p++,o-=1,i-=1,s=r.activeObj.activePoint.startX+r.activeObj.activePoint.width/2-o/2,l=r.activeObj.activePoint.startY+r.activeObj.activePoint.height/2-i/2;if(r.transform.defaultZoomFactor=0,r.notify("draw",{prop:"setResizeSelect",value:{bool:!0}}),r.notify("draw",{prop:"setIsCropSelect",value:{bool:!0}}),r.notify("draw",{prop:"select",onPropertyChange:!1,value:{type:"custom",startX:s,startY:l,width:o,height:i}}),r.notify("draw",{prop:"setResizeSelect",value:{bool:!1}}),0!==r.transform.straighten){var h={isIntersect:null,arr:null};for(r.notify("draw",{prop:"updateImgCanvasPoints",onPropertyChange:!1}),r.notify("draw",{prop:"isLinesIntersect",onPropertyChange:!1,value:{obj:h}});h.arr[0]||h.arr[1]||h.arr[2]||h.arr[3];)this.zoomAction(.0125,null,!0),r.notify("draw",{prop:"updateImgCanvasPoints",onPropertyChange:!1}),r.notify("draw",{prop:"isLinesIntersect",onPropertyChange:!1,value:{obj:h}})}r.isCropToolbar=!0,r.crop(),r.isCropToolbar=!1},i.prototype.updateResize=function(){var e=this.parent;e.prevCropObj=t.extend({},e.cropObj,{},!0);var o={currObj:{}};e.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:o}}),e.prevObj=o.currObj,e.currSelectionPoint&&e.prevCropObj.activeObj.shape&&(e.prevObj.activeObj=t.extend({},e.prevCropObj.activeObj,{},!0)),e.prevObj.objColl=t.extend([],e.objColl,[],!0),e.prevObj.pointColl=t.extend([],e.pointColl,[],!0),e.prevObj.afterCropActions=t.extend([],e.afterCropActions,[],!0);var i={selPointColl:null};e.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:i}}),e.prevObj.selPointColl=t.extend([],i.selPointColl,[],!0),e.resizeSrc={startX:e.img.srcLeft,startY:e.img.srcTop,width:e.img.srcWidth,height:e.img.srcHeight}},i.prototype.resize=function(e,o,i){var r=this.parent;r.isResize=!0,t.isNullOrUndefined(r.prevCropObj)&&t.isNullOrUndefined(r.prevObj)&&r.notify("transform",{prop:"updateResize",value:{bool:!1}});var a=r.element.querySelector("#"+r.element.id+"_aspectratio"),n=r.element.querySelector("#"+r.element.id+"_nonaspectratio");a&&n&&(r.notify("toolbar",{prop:"initResizeToolbar"}),t.Browser.isDevice&&r.notify("toolbar",{prop:"init-main-toolbar",value:{isApplyBtn:!1,isDevice:!0,isOkBtn:!0,isResize:!0}}));var s=r.element.querySelector("#"+r.element.id+"_resizeHeight"),l=""===s.value?s.placeholder:s.value,p={cancel:!1,previousWidth:Math.ceil(r.img.destWidth),previousHeight:Math.ceil(r.img.destHeight),width:Math.ceil(e),height:o&&0!==o?Math.ceil(o):i?Math.ceil(parseFloat(l)):Math.ceil(r.img.destHeight),isAspectRatio:i||!1};r.trigger("resizing",p),r.editCompleteArgs=p,p.cancel?r.aspectHeight&&r.aspectWidth&&(r.aspectHeight=p.previousHeight,r.aspectWidth=p.previousWidth):this.resizeEventHandler(p)},i.prototype.resizeEventHandler=function(e){var o,i=this.parent,r=i.element.querySelector("#"+i.element.id+"_resizeWidth"),a=i.element.querySelector("#"+i.element.id+"_resizeHeight");if(e.isAspectRatio)if(null!=this.resizedImgAngle&&this.resizedImgAngle===i.transform.degree||(this.resizedImgAngle=i.transform.degree,o=!0),o){i.notify("transform",{prop:"resizeImage",value:{width:e.width,height:0}});var n=i.img.destWidth,s=i.img.destHeight,l=void 0;if(l=parseFloat(""===r.value?r.placeholder:r.value),a){var p=l/(n/s),h=p%1>=.5||p%1<=-.5?Math.round(p):p<0?Math.ceil(p):Math.floor(p);if(t.getComponent(a,"numerictextbox").value=h,a.value=h.toString()+" px",i.aspectHeight=h,r&&""===r.value){var d=(p=parseFloat(""===a.value?a.placeholder:a.value)/(s/n))%1>=.5||p%1<=-.5?Math.round(p):p<0?Math.ceil(p):Math.floor(p);t.getComponent(r,"numerictextbox").value=d,r.value=d.toString()+" px",i.aspectWidth=d}}}else i.notify("transform",{prop:"resizeImage",value:{width:e.width,height:null}});else null!==this.resizedImgAngle&&this.resizedImgAngle!==i.transform.degree&&(this.resizedImgAngle=i.transform.degree,o=!0),o?(i.notify("transform",{prop:"setPreventDownScale",value:{bool:!0}}),i.notify("transform",{prop:"resizeCrop",value:{width:e.width,height:e.height}}),i.notify("undo-redo",{prop:"setPreventUR",value:{bool:!0}}),i.okBtn(null,!0),i.notify("undo-redo",{prop:"setPreventUR",value:{bool:!1}}),i.resizeSrc={startX:i.img.srcLeft,startY:i.img.srcTop,width:i.img.srcWidth,height:i.img.srcHeight},i.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"resize",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}}),i.notify("transform",{prop:"setPreventDownScale",value:{bool:!1}}),i.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"resize",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}})):i.notify("transform",{prop:"resizeCrop",value:{width:e.width,height:e.height}});this.resizedImgAngle=i.transform.degree},i.prototype.straightenImage=function(e){var t=this.parent;t.toolbar&&0===t.toolbar.length&&t.notify("draw",{prop:"select",onPropertyChange:!1,value:{type:"custom",startX:null,startY:null,width:null,height:null}}),t.notify("toolbar",{prop:"performCropTransformClick",value:{shape:null}}),t.setStraighten(e),t.okBtn()},i}(),C=function(){function e(e){this.undoRedoStep=0,this.undoRedoColl=[],this.appliedUndoRedoColl=[],this.tempUndoRedoColl=[],this.tempUndoRedoStep=0,this.isPreventing=!1,this.parent=e,this.addEventListener()}return e.prototype.destroy=function(){this.parent.isDestroyed||this.removeEventListener()},e.prototype.addEventListener=function(){this.parent.on("undo-redo",this.undoRedo,this),this.parent.on("destroyed",this.destroy,this)},e.prototype.removeEventListener=function(){this.parent.off("undo-redo",this.undoRedo),this.parent.off("destroyed",this.destroy)},e.prototype.initializeUrPvtProp=function(){this.parent.lowerCanvas&&(this.lowerContext=this.parent.lowerCanvas.getContext("2d")),this.parent.upperCanvas&&(this.upperContext=this.parent.upperCanvas.getContext("2d"))},e.prototype.undoRedo=function(e){switch(this.initializeUrPvtProp(),e.prop){case"updateUndoRedoColl":this.updateUrc(e.value.operation,e.value.previousObj,e.value.previousObjColl,e.value.previousPointColl,e.value.previousSelPointColl,e.value.previousCropObj,e.value.previousText,e.value.currentText,e.value.previousFilter,e.value.isCircleCrop);break;case"refreshUrc":this.refreshUrc(e.value.bool);break;case"updateCurrUrc":this.updateCurrUrc(e.value.type,e.value.isCancel);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(e.value.objColl,e.value.operation);break;case"updateUndoRedo":this.updateUndoRedo(e.value?e.value.operation:null);break;case"getAppliedUndoRedoColl":e.value.obj.appliedUndoRedoColl=this.appliedUndoRedoColl;break;case"getUndoRedoStep":e.value.obj.undoRedoStep=this.undoRedoStep;break;case"setUndoRedoStep":this.undoRedoStep=e.value.step;break;case"undoDefault":this.undoDefault(e.value.obj);break;case"setPreventUR":this.isPreventing=e.value.bool;break;case"updateUndoRedoStack":e.value&&e.value.isPenDraw?this.updateUndoRedoStack(e.value.isPenDraw):this.updateUndoRedoStack();break;case"reset":this.reset()}},e.prototype.getModuleName=function(){return"undo-redo"},e.prototype.reset=function(){this.tempCurrSelPoint=null,this.undoRedoStep=0,this.undoRedoColl=[],this.appliedUndoRedoColl=[],this.tempActObj=null,this.tempUndoRedoColl=[],this.tempUndoRedoStep=0,this.isPreventing=!1},e.prototype.refreshUrc=function(e){var o=this.parent;o.isImageUpdated||((e=e||!1)&&(o.notify("toolbar",{prop:"setEnableDisableUndoRedo",value:{isPrevent:!0}}),this.tempUndoRedoColl=t.extend([],this.appliedUndoRedoColl,[],!0),this.tempUndoRedoStep=this.undoRedoStep),o.notify("toolbar",{prop:"setEnableDisableUndoRedo",value:{isPrevent:!1}}),this.undoRedoColl=this.undoRedoColl.slice(0,this.undoRedoStep),this.appliedUndoRedoColl=this.appliedUndoRedoColl.slice(0,this.undoRedoStep),o.isUndoRedo=o.currObjType.isUndoAction=!1,o.notify("toolbar",{prop:"enable-disable-btns"}))},e.prototype.updateCurrUrc=function(e,o){var i=this.parent;if(!(i.isResize||this.isPreventing||i.noPushUndo)){if(i.notify("toolbar",{prop:"setEnableDisableUndoRedo",value:{isPrevent:!1}}),"ok"===e){i.notify("draw",{prop:"setShapeTextInsert",onPropertyChange:!1,value:{bool:!1}});var r=this.tempUndoRedoColl.length>0?t.extend([],this.tempUndoRedoColl,[],!0):t.extend([],this.undoRedoColl,[],!0),a=this.undoRedoColl[this.undoRedoColl.length-1],n=this.appliedUndoRedoColl[this.appliedUndoRedoColl.length-1],s=a?t.extend({},a.previousObj,{},!0):null;if(t.isNullOrUndefined(n)?this.undoRedoColl[0]&&(a.previousCropObj=r[0].previousCropObj,a.previousObj=r[0].previousObj,a.previousObjColl=r[0].previousObjColl,a.previousPointColl=r[0].previousPointColl,a.previousText=r[0].previousText):"imageHFlip"!==a.operation&&"imageVFlip"!==a.operation&&(a.previousCropObj=n.currentCropObj,a.previousObj=n.currentObj,a.previousObjColl=n.currentObjColl,a.previousPointColl=n.currentPointColl,a.previousText=n.currentText,"frame"===a.operation&&a.previousObj&&s&&(a.previousObj.defaultZoom=s.defaultZoom,a.previousObj.zoomFactor=s.zoomFactor,a.previousObj.cropZoom=s.cropZoom)),a){if("imageHFlip"!==a.operation&&"imageVFlip"!==a.operation){var l=this.getZeroZoomObjPointValue(a.currentObjColl,a.currentPointColl);a.currentObjColl=l.obj,a.currentPointColl=l.point;var p={adjustmentLevel:null};i.notify("filter",{prop:"getAdjustmentLevel",onPropertyChange:!1,value:{obj:p}}),a.currentObj.adjustmentLevel=t.extend({},p.adjustmentLevel,{},!0),i.notify("filter",{prop:"setTempAdjVal"}),a.currentObj.currentFilter=i.currentFilter}this.appliedUndoRedoColl.push(a),o||this.triggerActionCompletedEvent(a.operation)}this.tempUndoRedoColl=[],this.tempUndoRedoStep=0}else this.tempUndoRedoColl.length>0&&(this.appliedUndoRedoColl=t.extend([],this.tempUndoRedoColl,[],!0),this.undoRedoStep=this.tempUndoRedoStep,this.tempUndoRedoColl=[],this.tempUndoRedoStep=0);var h=this.appliedUndoRedoColl[this.appliedUndoRedoColl.length-1],d=this.appliedUndoRedoColl[this.appliedUndoRedoColl.length-2];if(this.appliedUndoRedoColl.length>16)this.appliedUndoRedoColl.splice(0,1);else if(!o&&h&&d)if(("shapeTransform"===h.operation&&"shapeTransform"===d.operation||"shapeInsert"===h.operation&&"shapeInsert"===d.operation)&&JSON.stringify(h.currentObjColl)===JSON.stringify(d.currentObjColl)||"freehand-draw"===h.operation&&"freehand-draw"===d.operation&&JSON.stringify(h.currentPointColl)===JSON.stringify(d.currentPointColl)||"freehanddrawCustomized"===h.operation&&"freehanddrawCustomized"===d.operation&&JSON.stringify(h.currentPointColl)===JSON.stringify(d.currentPointColl))this.appliedUndoRedoColl.splice(this.appliedUndoRedoColl.length-1,1);else if(this.undoRedoStep!==this.appliedUndoRedoColl.length-1&&(h=this.appliedUndoRedoColl[this.appliedUndoRedoColl.length-1],d=this.appliedUndoRedoColl[this.undoRedoStep],h&&d&&"shapeTransform"===h.operation&&"shapeTransform"===d.operation&&JSON.stringify(h.currentObjColl)===JSON.stringify(d.previousObjColl)))return this.appliedUndoRedoColl.splice(this.appliedUndoRedoColl.length-1,1),this.undoRedoColl=[],void(this.undoRedoColl=t.extend([],this.appliedUndoRedoColl,[],!0));this.undoRedoColl=[],this.undoRedoColl=t.extend([],this.appliedUndoRedoColl,[],!0),"ok"===e&&(this.undoRedoStep=this.undoRedoColl.length,i.notify("toolbar",{prop:"enable-disable-btns"})),i.transform.zoomFactor>0&&(i.togglePan=!0,i.notify("selection",{prop:"setDragCanvas",value:{bool:!0}}))}},e.prototype.triggerActionCompletedEvent=function(e){var t=this.parent,o={action:{brightness:"fine-tune",contrast:"fine-tune",hue:"fine-tune",saturation:"fine-tune",opacity:"fine-tune",blur:"fine-tune",exposure:"fine-tune",default:"filter",chrome:"filter",cold:"filter",warm:"filter",grayscale:"filter",sepia:"filter",invert:"filter",deleteObj:"shape-delete",deleteFreehandDrawing:"freehand-draw-delete",shapeInsert:"shape-insert",shapeTransform:"shape-customize",freehanddrawCustomized:"freehand-draw-customize"}[e]||e,actionEventArgs:t.editCompleteArgs};t.triggerEditCompleteEvent(o)},e.prototype.getUndoRedoAction=function(e){return{brightness:"fine-tune",contrast:"fine-tune",hue:"fine-tune",saturation:"fine-tune",opacity:"fine-tune",blur:"fine-tune",exposure:"fine-tune",default:"filter",chrome:"filter",cold:"filter",warm:"filter",grayscale:"filter",sepia:"filter",invert:"filter",deleteObj:"shape-delete",deleteFreehandDrawing:"freehand-drawing-delete",shapeInsert:"shape-insert",shapeTransform:"shape-customize",imageRotate:"shape-customize",freehanddraw:"freehand-draw",freehanddrawCustomized:"freehand-draw-customize",textAreaCustomization:"text-area-customization",imageHFlip:"shape-customize",imageVFlip:"shape-customize",bgColor:"background-color",updateImage:"image-update"}[e]||e},e.prototype.cancelCropSelection=function(){var e,o=this.parent,i=!1;o.activeObj.shape&&(e=o.activeObj.shape.split("-")),(o.currObjType.isCustomCrop||e&&"crop"===e[0])&&(i=!0),i&&o.notify("draw",{prop:"performCancel",value:{isContextualToolbar:null}}),0===this.tempUndoRedoColl.length&&0===this.tempUndoRedoStep||(this.appliedUndoRedoColl=t.extend([],this.tempUndoRedoColl,[],!0),this.undoRedoColl=t.extend([],this.tempUndoRedoColl,[],!0),this.undoRedoStep=this.tempUndoRedoStep,this.tempUndoRedoColl=[],this.tempUndoRedoStep=0,o.notify("toolbar",{prop:"setEnableDisableUndoRedo",value:{isPrevent:!1}}))},e.prototype.refreshToolbarActions=function(){var e=this.parent;e.activeObj.shape?(e.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"shapes",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}}),e.notify("toolbar",{prop:"update-toolbar-items",onPropertyChange:!1})):e.notify("toolbar",{prop:"refresh-main-toolbar",onPropertyChange:!1})},e.prototype.applyCurrentChanges=function(){var e=this.parent;e.currObjType.isFiltered=!1,0===e.transform.zoomFactor&&(e.togglePan=!1,e.notify("selection",{prop:"setDragCanvas",value:{bool:!1}})),e.element.querySelector(".e-contextual-toolbar-wrapper")&&e.element.querySelector(".e-contextual-toolbar-wrapper").classList.add("e-hide"),e.togglePen&&(e.togglePen=!1,e.upperCanvas.style.cursor=e.cursor="default",this.upperContext.clearRect(0,0,e.upperCanvas.width,e.upperCanvas.height)),this.appliedUndoRedoColl.length>0&&(this.undoRedoColl=t.extend([],this.appliedUndoRedoColl,[],!0))},e.prototype.callUndo=function(){this.applyCurrentChanges(),this.undo()},e.prototype.callRedo=function(){this.applyCurrentChanges(),this.redo()},e.prototype.undo=function(){var e=this.parent;if(this.cancelCropSelection(),e.notify("draw",{prop:"resetFrameZoom",onPropertyChange:!1,value:{isOk:!1}}),!e.disabled&&e.isImageLoaded&&this.undoRedoStep>0){this.refreshToolbarActions(),e.activeObj.activePoint&&0!==e.activeObj.activePoint.width&&(this.tempActObj=e.activeObj),e.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),this.undoRedoStep--,e.notify("toolbar",{prop:"enable-disable-btns"}),e.element.querySelector(".e-contextual-toolbar-wrapper")&&e.element.querySelector(".e-contextual-toolbar-wrapper").classList.add("e-hide"),e.isUndoRedo=!0;var o=this.undoRedoColl[this.undoRedoStep];this.undoRedoColl.length===this.undoRedoStep?e.currObjType.isUndoAction=!1:e.currObjType.isUndoAction=!0,"textAreaCustomization"===o.operation||"block"!==e.textArea.style.display&&"inline-block"!==e.textArea.style.display||(e.textArea.style.display="none"),e.notify("draw",{prop:"setCancelAction",onPropertyChange:!1,value:{bool:!0}});e.cropObj=t.extend({},o.previousCropObj,{},!0),e.afterCropActions=o.previousObj.afterCropActions,this.lowerContext.filter=o.previousObj.filter,e.notify("filter",{prop:"setAdjustmentLevel",onPropertyChange:!1,value:{adjustmentLevel:o.previousObj.adjustmentLevel}}),e.notify("filter",{prop:"setTempAdjVal"}),e.currentFilter=o.previousObj.currentFilter,e.notify("filter",{prop:"setTempFilVal"}),e.canvasFilter=this.lowerContext.filter,e.initialAdjustmentValue=this.lowerContext.filter,e.notify("filter",{prop:"setBevelFilter",onPropertyChange:!1,value:{bevelFilter:this.lowerContext.filter}});var i={action:this.getUndoRedoAction(o.operation)};switch(o.operation){case"shapeTransform":case"brightness":case"contrast":case"hue":case"saturation":case"opacity":case"blur":case"exposure":case"default":case"chrome":case"cold":case"warm":case"grayscale":case"blackandwhite":case"sepia":case"invert":case"sharpen":case"imageRotate":case"shapeInsert":this.shapeTransform(o.previousObjColl,o.previousPointColl);break;case"freehanddraw":case"freehand-draw":this.updateFreehandDraw(o.previousPointColl,o.previousSelPointColl),e.notify("freehand-draw",{prop:"setCurrentFreehandDrawIndex",value:{value:e.pointColl.length}});break;case"freehanddrawCustomized":this.updateFreehandDrawCustomized(o.previousObjColl,o.previousPointColl);break;case"deleteFreehandDrawing":case"deleteObj":this.updateDelete(o.operation,o.previousObjColl,o.previousPointColl,o.previousSelPointColl);break;case"textAreaCustomization":this.shapeTransform(o.previousObjColl,o.previousPointColl),this.updateTextAreaCustomization(void 0,o.previousObjColl);break;case"text":this.updateText(o.previousObjColl,!0);break;case"frame":e.transform.zoomFactor=e.transform.defaultZoomFactor=o.previousObj.defaultZoom,e.setProperties({zoomSettings:{zoomFactor:o.previousObj.zoomFactor}},!0),e.notify("transform",{prop:"setPreviousZoomValue",onPropertyChange:!1,value:{previousZoomValue:e.zoomSettings.zoomFactor}}),t.extend(e.frameObj,o.previousObj.frameObj),e.notify("draw",{prop:"render-image",value:{isMouseWheel:!0,isPreventClearRect:null,isFrame:!0}});break;case"imageHFlip":this.imageFlip("horizontal",o.previousObjColl);break;case"imageVFlip":this.imageFlip("vertical",o.previousObjColl);break;case"bgColor":e.notify("draw",{prop:"imageBackgroundColor",onPropertyChange:!1,value:{color:o.previousObj.bgColor}}),e.notify("draw",{prop:"render-image",value:{isMouseWheel:!1}});break;case"updateImage":e.isImageUpdated=!0,e.baseImg.src=o.previousObj.imageSource,setTimeout(function(){0!==e.cropObj.straighten?(e.notify("toolbar",{prop:"performCropTransformClick",value:{shape:"crop-custom"}}),e.noPushUndo=!0,e.crop(),e.noPushUndo=!1):e.notify("draw",{prop:"render-image",value:{isMouseWheel:!1}}),e.isImageUpdated=!1});break;default:this.undoDefault(o,!0),e.notify("filter",{prop:"set-adjustment",value:{operation:o.operation}}),e.notify("filter",{prop:"update-filter",value:{operation:o.operation,filter:o.filter}})}if("crop"===o.operation){o.previousObj.currSelectionPoint&&(e.currSelectionPoint=t.extend({},o.previousObj.currSelectionPoint,{},!0),e.currSelectionPoint&&t.isNullOrUndefined(e.currSelectionPoint.shape)&&(e.currSelectionPoint=null)),e.updateCropTransformItems(),e.notify("draw",{prop:"select",onPropertyChange:!1,value:{type:"custom",startX:null,startY:null,width:null,height:null}}),e.isCircleCrop&&(e.isCircleCrop=!1,this.tempCurrSelPoint=t.extend({},e.currSelectionPoint,{},!0),e.currSelectionPoint=null);var r=e.cancelCropSelection.isCircleCrop;e.cancelCropSelection.isCircleCrop=!1,e.notify("draw",{prop:"performCancel",value:{isContextualToolbar:null,isUndoRedo:!0}}),e.cancelCropSelection.isCircleCrop=r,e.currObjType.isActiveObj=!1,0!==e.transform.straighten&&e.notify("draw",{prop:"setStraightenActObj",value:{activeObj:null}})}else"resize"===o.operation&&e.cropObj&&e.cropObj.activeObj&&(e.currSelectionPoint=t.extend({},e.cropObj.activeObj,{},!0));this.undoRedoColl[this.undoRedoStep-1]&&this.undoRedoColl[this.undoRedoStep-1].isCircleCrop&&(e.isCircleCrop=!0,e.notify("crop",{prop:"cropCircle",onPropertyChange:!1,value:{context:this.lowerContext,isSave:null,isFlip:null}})),this.endUndoRedo(o.operation,!0);var a={action:"undo",actionEventArgs:i};e.triggerEditCompleteEvent(a)}},e.prototype.redo=function(){var e=this.parent;if(this.cancelCropSelection(),e.notify("draw",{prop:"resetFrameZoom",onPropertyChange:!1,value:{isOk:!1}}),!e.disabled&&e.isImageLoaded&&this.undoRedoStep<this.appliedUndoRedoColl.length){this.refreshToolbarActions(),this.undoRedoStep++,e.notify("toolbar",{prop:"enable-disable-btns"}),e.isUndoRedo=!0;var o=this.undoRedoColl[this.undoRedoStep-1];this.undoRedoColl.length===this.undoRedoStep?e.currObjType.isUndoAction=!1:e.currObjType.isUndoAction=!0,"textAreaCustomization"===o.operation||"block"!==e.textArea.style.display&&"inline-block"!==e.textArea.style.display||(e.textArea.style.display="none"),e.notify("draw",{prop:"setCancelAction",onPropertyChange:!1,value:{bool:!0}}),e.cropObj=t.extend({},o.currentCropObj,{},!0),e.afterCropActions=o.currentObj.afterCropActions,this.lowerContext.filter=o.currentObj.filter,e.element.querySelector(".e-contextual-toolbar-wrapper")&&e.element.querySelector(".e-contextual-toolbar-wrapper").classList.add("e-hide"),e.notify("filter",{prop:"setAdjustmentLevel",onPropertyChange:!1,value:{adjustmentLevel:o.currentObj.adjustmentLevel}}),e.notify("filter",{prop:"setTempAdjVal"}),e.currentFilter=o.currentObj.currentFilter,e.notify("filter",{prop:"setTempFilVal"}),e.canvasFilter=this.lowerContext.filter,e.initialAdjustmentValue=this.lowerContext.filter,e.notify("filter",{prop:"setBevelFilter",onPropertyChange:!1,value:{bevelFilter:this.lowerContext.filter}});var i=void 0,r={action:this.getUndoRedoAction(o.operation)};switch(o.operation){case"shapeTransform":case"brightness":case"contrast":case"hue":case"saturation":case"opacity":case"blur":case"exposure":case"default":case"chrome":case"cold":case"warm":case"grayscale":case"blackandwhite":case"sepia":case"invert":case"sharpen":case"imageRotate":case"shapeInsert":this.shapeTransform(o.currentObjColl,o.currentPointColl);break;case"freehanddraw":case"freehand-draw":this.updateFreehandDraw(o.currentPointColl,o.currentSelPointColl),e.notify("freehand-draw",{prop:"setCurrentFreehandDrawIndex",value:{value:e.pointColl.length}});break;case"freehanddrawCustomized":this.updateFreehandDrawCustomized(o.currentObjColl,o.currentPointColl);break;case"deleteFreehandDrawing":case"deleteObj":this.updateDelete(o.operation,o.currentObjColl,o.currentPointColl,o.currentSelPointColl);break;case"textAreaCustomization":this.shapeTransform(o.currentObjColl,o.currentPointColl),this.updateTextAreaCustomization(i,o.currentObjColl);break;case"text":this.updateText(o.currentObjColl,!1);break;case"frame":t.extend(e.frameObj,o.currentObj.frameObj),e.notify("draw",{prop:"render-image",value:{isMouseWheel:!0,isPreventClearRect:null,isFrame:!0}});break;case"imageHFlip":this.imageFlip("horizontal",o.currentObjColl);break;case"imageVFlip":this.imageFlip("vertical",o.currentObjColl);break;case"bgColor":e.notify("draw",{prop:"imageBackgroundColor",onPropertyChange:!1,value:{color:o.currentObj.bgColor}}),e.notify("draw",{prop:"render-image",value:{isMouseWheel:!1}});break;case"updateImage":e.isImageUpdated=!0,e.baseImg.src=o.currentObj.imageSource,setTimeout(function(){0!==e.cropObj.straighten?(e.notify("toolbar",{prop:"performCropTransformClick",value:{shape:"crop-custom"}}),e.noPushUndo=!0,e.crop(),e.noPushUndo=!1):e.notify("draw",{prop:"render-image",value:{isMouseWheel:!1}}),e.isImageUpdated=!1});break;default:e.objColl=[],e.pointColl=[],e.freehandCounter=0,e.notify("freehand-draw",{prop:"setSelPointColl",onPropertyChange:!1,value:{obj:{selPointColl:[]}}}),e.notify("draw",{prop:"setCurrentObj",onPropertyChange:!1,value:{obj:o.currentObj,isUndoRedo:!0}}),e.img.destLeft=o.currentObj.destPoints.startX,e.img.destTop=o.currentObj.destPoints.startY,i=t.extend({},e.activeObj,{},!0),e.objColl=t.extend([],o.currentObjColl,[],!0),e.pointColl=t.extend([],o.currentPointColl,[],!0),e.freehandCounter=e.pointColl.length,e.notify("freehand-draw",{prop:"setSelPointColl",onPropertyChange:!1,value:{obj:{selPointColl:t.extend([],o.currentSelPointColl,[],!0)}}}),e.transform.straighten=0,this.lowerContext.filter="none",e.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"zoom",pen:"zoom",isPreventApply:null}}),this.lowerContext.filter=o.currentObj.filter,e.prevStraightenedDegree=e.transform.straighten,e.activeObj=i,this.upperContext.clearRect(0,0,e.upperCanvas.width,e.upperCanvas.height),0!==e.activeObj.activePoint.width&&0!==e.activeObj.activePoint.height&&e.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate"}}),e.notify("filter",{prop:"set-adjustment",value:{operation:o.operation}}),e.notify("filter",{prop:"update-filter",value:{operation:o.operation}})}"crop"===o.operation&&o.isCircleCrop&&(e.isCircleCrop=!0,e.currSelectionPoint=t.extend({},this.tempCurrSelPoint,{},!0),this.tempCurrSelPoint=null),"crop"!==o.operation||o.isCircleCrop||(e.isCircleCrop=!1),"crop"===o.operation&&o.currentObj.currSelectionPoint&&(e.currSelectionPoint=t.extend({},o.currentObj.currSelectionPoint,{},!0),e.notify("draw",{prop:"setStraightenActObj",value:{activeObj:e.currSelectionPoint}})),e.currSelectionPoint&&t.isNullOrUndefined(e.currSelectionPoint.shape)&&(e.currSelectionPoint=null),"resize"===o.operation&&e.cropObj&&e.cropObj.activeObj&&(e.currSelectionPoint=t.extend({},e.cropObj.activeObj,{},!0)),this.endUndoRedo(o.operation,!1);var a={action:"redo",actionEventArgs:r};e.triggerEditCompleteEvent(a)}},e.prototype.imageFlip=function(e,o){var i=this.parent;this.shapeTransform(o,null),i.activeObj=t.extend({},i.objColl[i.objColl.length-1],{},!0);var r=i.activeObj,a=r.shape,n=r.isHorImageFlip,s=r.isVerImageFlip;i.objColl.pop(),a&&"image"===a?("horizontal"===e?t.isNullOrUndefined(n)&&s?(i.activeObj.isHorImageFlip=!0,i.activeObj.isVerImageFlip=null,i.horizontalFlip(this.upperContext,!0)):(t.isNullOrUndefined(n)||!n?i.activeObj.isHorImageFlip=!0:i.activeObj.isHorImageFlip=null,i.horizontalFlip(this.upperContext,!0)):"vertical"===e&&(t.isNullOrUndefined(s)&&n?(i.activeObj.isVerImageFlip=!0,i.activeObj.isHorImageFlip=null,i.verticalFlip(this.upperContext,!0)):(t.isNullOrUndefined(s)||!s?i.activeObj.isVerImageFlip=!0:i.activeObj.isVerImageFlip=null,i.verticalFlip(this.upperContext,!0))),i.notify("shape",{prop:"applyActObj",onPropertyChange:!1,value:{isMouseDown:!0}})):i.notify("draw",{prop:"render-image",value:{isMouseWheel:!0}})},e.prototype.shapeTransform=function(e,o){var i=this.parent;i.objColl=t.extend([],e,[],!0),o&&(i.pointColl=t.extend([],o,[],!0),i.freehandCounter=i.pointColl.length),i.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"zoom",pen:"zoom",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})},e.prototype.updateFreehandDraw=function(e,t){var o=this.parent;o.pointColl=e,o.notify("freehand-draw",{prop:"setSelPointColl",onPropertyChange:!1,value:{obj:{selPointColl:t}}}),o.freehandCounter=o.pointColl.length,o.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"zoom",pen:"zoom",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})},e.prototype.updateFreehandDrawCustomized=function(e,o){var i=this.parent;i.objColl=t.extend([],e,[],!0),i.pointColl=o,i.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"zoom",pen:"zoom",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})},e.prototype.updateDelete=function(e,t,o,i){var r=this.parent;"deleteFreehandDrawing"===e?(r.pointColl=o,r.freehandCounter=r.pointColl.length,r.notify("freehand-draw",{prop:"setSelPointColl",onPropertyChange:!1,value:{obj:{selPointColl:i}}}),r.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"zoom",pen:"zoom",isPreventApply:null}})):"deleteObj"===e&&(r.objColl=t,r.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"zoom",pen:"zoom",isPreventApply:null}})),this.lowerContext.clearRect(0,0,r.lowerCanvas.width,r.lowerCanvas.height),this.upperContext.clearRect(0,0,r.upperCanvas.width,r.upperCanvas.height),r.isUndoRedo=!0,r.notify("draw",{prop:"redrawImgWithObj",onPropertyChange:!1})},e.prototype.updateTextAreaCustomization=function(e,o){var i=this.parent;i.objColl=t.extend([],o,[],!0),i.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"zoom",pen:"zoom",isPreventApply:null}}),this.lowerContext.clearRect(0,0,i.lowerCanvas.width,i.lowerCanvas.height),i.isUndoRedo=!0,i.notify("draw",{prop:"redrawImgWithObj",onPropertyChange:!1});for(var r=0,a=o.length;r<a;r++){if(!this.tempActObj){e=t.extend({},o[o.length-1],{},!0),i.objColl.splice(r,1);break}if(this.tempActObj.currIndex===o[r].currIndex){e=t.extend({},o[r],{},!0),i.objColl.splice(r,1);break}}e&&this.updateTextBox(e),"block"!==i.textArea.style.display&&"inline-block"!==i.textArea.style.display||i.notify("shape",{prop:"redrawActObj",onPropertyChange:!1,value:{x:null,y:null,isMouseDown:null}})},e.prototype.updateText=function(e,o){var i=this.parent;if(this.tempActObj&&(i.activeObj=t.extend({},this.tempActObj,{},!0)),0===e.length&&1===i.objColl.length)this.tempActObj=t.extend({},i.objColl[0],{},!0);else for(var r=0,a=i.objColl.length;r<a;r++){if(i.objColl[r]&&t.isNullOrUndefined(e[r])){this.tempActObj=t.extend({},i.objColl[r],{},!0);break}if(e[r].currIndex!==i.objColl[r].currIndex){this.tempActObj=t.extend({},i.objColl[r],{},!0);break}}o&&(i.activeObj=t.extend({},this.tempActObj,{},!0)),i.objColl=t.extend([],e,[],!0),i.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"zoom",pen:"zoom",isPreventApply:!0}}),this.upperContext.clearRect(0,0,i.upperCanvas.width,i.upperCanvas.height),this.lowerContext.clearRect(0,0,i.lowerCanvas.width,i.lowerCanvas.height),i.isUndoRedo=!0,i.notify("draw",{prop:"redrawImgWithObj",onPropertyChange:!1}),i.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1})},e.prototype.updateTextBox=function(e){var o=this.parent;this.upperContext.clearRect(0,0,o.lowerCanvas.width,o.lowerCanvas.height),this.lowerContext.clearRect(0,0,o.lowerCanvas.width,o.lowerCanvas.height),o.notify("draw",{prop:"redrawImgWithObj",onPropertyChange:!1}),o.notify("toolbar",{prop:"destroy-qa-toolbar",onPropertyChange:!1});var i=o.textArea;i.style.display="block",i.style.fontFamily=e.textSettings.fontFamily,i.style.fontSize=e.textSettings.fontSize+"px",i.style.color=e.strokeSettings.strokeColor,i.style.fontWeight=e.textSettings.bold?"bold":"normal",i.style.fontStyle=e.textSettings.italic?"italic":"normal",i.style.border="2px solid "+o.themeColl[o.theme].primaryColor,i.value=e.keyHistory,o.activeObj=t.extend({},e,{},!0),o.notify("shape",{prop:"updateFontStyles",onPropertyChange:!1,value:{isTextBox:null}}),o.textArea.style.width=o.activeObj.activePoint.width+"px"},e.prototype.undoDefault=function(e,o){this.lowerContext.filter=e.previousObj.filter;var i=this.parent;i.objColl=[],i.pointColl=[],i.freehandCounter=0,i.notify("freehand-draw",{prop:"setSelPointColl",onPropertyChange:!1,value:{obj:{selPointColl:[]}}});var r=!o&&e.isCircleCrop;i.notify("draw",{prop:"setCurrentObj",onPropertyChange:!1,value:{obj:e.previousObj,isUndoRedo:o,isCircleCrop:r}}),i.prevStraightenedDegree=i.transform.straighten,this.upperContext.clearRect(0,0,i.upperCanvas.width,i.upperCanvas.height),i.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),i.img.destLeft=e.previousObj.destPoints.startX,i.img.destTop=e.previousObj.destPoints.startY;var a=t.extend({},i.activeObj,{},!0);i.objColl=t.extend([],e.previousObjColl,[],!0),i.pointColl=t.extend([],e.previousPointColl,[],!0),i.freehandCounter=i.pointColl.length,i.notify("freehand-draw",{prop:"setSelPointColl",onPropertyChange:!1,value:{obj:{selPointColl:t.extend([],e.previousSelPointColl,[],!0)}}}),i.transform.straighten=0,this.lowerContext.filter="none",i.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"zoom",pen:"zoom",isPreventApply:null}}),this.lowerContext.filter=e.previousObj.filter,i.activeObj=a,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"}})},e.prototype.endUndoRedo=function(e,t){var o=this.parent,i={type:"none",color:"#fff",size:20,inset:20,offset:20,radius:0,amount:1,border:"solid",gradientColor:""};(o.currSelectionPoint&&"crop-circle"===o.currSelectionPoint.shape||o.isCircleCrop)&&JSON.stringify(o.frameObj)!==JSON.stringify(i)&&o.notify("draw",{prop:"render-image",value:{isMouseWheel:!0}}),o.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.lowerContext}}),o.isCircleCrop&&(t&&"crop"!==e||!t)&&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}}),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"),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},e.prototype.updateUrc=function(e,o,i,r,a,n,s,l,p,h){var d=this.parent;if(!d.isResize&&!this.isPreventing){var c={isInitialLoaded:!1};if(d.currObjType.isUndoAction&&this.refreshUrc(!0),d.notify("draw",{prop:"isInitialLoaded",onPropertyChange:!1,value:{object:c}}),!c.isInitialLoaded&&d.allowUndoRedo){var u={currObj:{}};d.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:u}});var v=u.currObj;v.objColl=t.extend([],d.objColl,[],!0),v.pointColl=t.extend([],d.pointColl,[],!0),v.afterCropActions=t.extend([],d.afterCropActions,[],!0);var g={selPointColl:null};if(d.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:g}}),v.selPointColl=t.extend([],g.selPointColl,[],!0),"crop"===e)v.currSelectionPoint=t.extend({},d.currSelectionPoint,{},!0);else if("frame"===e)o.destPoints={startX:d.frameDestPoints.destLeft,startY:d.frameDestPoints.destTop,width:d.frameDestPoints.destWidth,height:d.frameDestPoints.destHeight},v.destPoints={startX:d.frameDestPoints.destLeft,startY:d.frameDestPoints.destTop,width:d.frameDestPoints.destWidth,height:d.frameDestPoints.destHeight},t.isNullOrUndefined(d.tempFrameZoomLevel)||(o.defaultZoom=v.defaultZoom=d.tempFrameZoomLevel);else if(("imageHFlip"===e||"imageVFlip"===e)&&this.appliedUndoRedoColl.length>0){var f=i[i.length-1].currIndex;if(i=this.appliedUndoRedoColl[this.appliedUndoRedoColl.length-1].currentObjColl,f)for(var C=0,b=i.length;C<b;C++)if(i[C].currIndex===f){var m=t.extend({},i[C],{},!0);i.splice(C,1),i.push(m);break}}this.undoRedoColl.push({operation:e,previousObj:o,currentObj:v,previousObjColl:i,currentObjColl:v.objColl,previousPointColl:r,currentPointColl:v.pointColl,previousSelPointColl:a,currentSelPointColl:v.selPointColl,previousCropObj:n,currentCropObj:t.extend({},d.cropObj,{},!0),previousText:s,currentText:l,filter:p,isCircleCrop:h}),d.notify("toolbar",{prop:"enable-disable-btns",onPropertyChange:!1})}}},e.prototype.updateUrObj=function(e,o){var i=this.parent;if(i.allowUndoRedo){i.currObjType.isUndoAction&&!i.isShapeDrawing&&this.refreshUrc(!0),t.isNullOrUndefined(i.activeObj.imageRatio)&&i.notify("shape",{prop:"updImgRatioForActObj",onPropertyChange:!1}),i.objColl.push(i.activeObj);var r=t.extend({},i.cropObj,{},!0),a={currObj:{}};i.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:a}});var n=a.currObj;n.objColl=t.extend([],i.objColl,[],!0),n.pointColl=t.extend([],i.pointColl,[],!0),n.afterCropActions=t.extend([],i.afterCropActions,[],!0);var s={selPointColl:null};i.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:s}}),n.selPointColl=t.extend([],s.selPointColl,[],!0);var l=o||"shapeTransform";this.undoRedoColl.push({operation:l,previousObj:n,currentObj:n,previousObjColl:e,currentObjColl:n.objColl,previousPointColl:n.pointColl,currentPointColl:n.pointColl,previousSelPointColl:n.selPointColl,currentSelPointColl:n.selPointColl,previousCropObj:r,currentCropObj:r}),i.notify("selection",{prop:"redrawShape",onPropertyChange:!1,value:{obj:i.objColl[i.objColl.length-1]}})}},e.prototype.updateUndoRedo=function(e){var o=this.parent,i=t.extend({},o.cropObj,{},!0),r={currObj:{}};o.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:r}});var a=r.currObj;a.objColl=t.extend([],o.objColl,[],!0),a.pointColl=t.extend([],o.pointColl,[],!0),a.afterCropActions=t.extend([],o.afterCropActions,[],!0);var n={selPointColl:null};o.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:n}}),a.selPointColl=t.extend([],n.selPointColl,[],!0),t.isNullOrUndefined(o.activeObj.imageRatio)&&o.notify("shape",{prop:"updImgRatioForActObj",onPropertyChange:!1}),o.objColl.push(o.activeObj);var s=e||"shapeTransform";this.updateUrc(s,a,a.objColl,a.pointColl,a.selPointColl,i),o.objColl.pop(),o.notify("shape",{prop:"applyActObj",onPropertyChange:!1,value:{isMouseDown:null}}),o.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),o.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"shapes",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}}),o.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"main",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}})},e.prototype.getZeroZoomObjPointValue=function(e,o){var i=this.parent;this.updateObjColl();var r={currObj:{}};i.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:r}});var a=r.currObj;a.objColl=t.extend([],i.objColl,[],!0),a.pointColl=t.extend([],i.pointColl,[],!0),a.afterCropActions=t.extend([],i.afterCropActions,[],!0);var n={selPointColl:null};i.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:n}}),a.selPointColl=t.extend([],n.selPointColl,[],!0);var s={cropDimension:null};i.notify("transform",{prop:"getCropDimension",onPropertyChange:!1,value:{obj:s}});var l=t.extend([],i.objColl,[],!0),p=t.extend([],i.pointColl,[],!0),h={arrowDimension:null};this.parent.notify("draw",{prop:"getArrowDimension",onPropertyChange:!1,value:{obj:h}});var d=t.extend({},h.arrowDimension,{},!0);if(i.transform.zoomFactor>0&&(e.length>0||o.length>0)){if(e.length>0)for(var c=0;c<e.length;c++)e[c].currIndex||(e[c].currIndex="shape_"+(c+1));i.objColl=e,i.pointColl=o;var u=i.isUndoRedo,v=i.isCropTab;if(0!==i.transform.zoomFactor){i.isUndoRedo=!0,i.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"zoom",pen:"zoom",isPreventApply:!0}}),i.notify("freehand-draw",{prop:"updateFHDColl",onPropertyChange:!1}),i.isCropTab=!0;var g=t.extend({},i.zoomSettings,null,!0);i.transform.zoomFactor>0?i.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:-i.transform.zoomFactor,zoomPoint:null,isResize:null}}):i.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:Math.abs(i.transform.zoomFactor),zoomPoint:null,isResize:null}}),i.zoomSettings=g,i.isCropTab=v,i.isUndoRedo=u,l=t.extend([],i.objColl,[],!0),p=t.extend([],i.pointColl,[],!0),i.objColl=[],i.pointColl=[],i.freehandCounter=0,i.notify("freehand-draw",{prop:"setSelPointColl",onPropertyChange:!1,value:{obj:{selPointColl:[]}}}),i.notify("transform",{prop:"setCropDimension",onPropertyChange:!1,value:{width:s.cropDimension.width,height:s.cropDimension.height}});var f={width:s.cropDimension.width,height:s.cropDimension.height};f.width+=f.width*a.defaultZoom,f.height+=f.height*a.defaultZoom,i.notify("draw",{prop:"setZoomCropWidth",value:{width:f.width,height:f.height}}),i.notify("draw",{prop:"setCurrentObj",onPropertyChange:!1,value:{obj:a}}),i.img.destLeft=a.destPoints.startX,i.img.destTop=a.destPoints.startY,i.panPoint.totalPannedPoint=a.totalPannedPoint,i.panPoint.totalPannedClientPoint=a.totalPannedClientPoint,i.panPoint.totalPannedInternalPoint=a.totalPannedInternalPoint,i.objColl=t.extend([],a.objColl,[],!0),i.pointColl=t.extend([],a.pointColl,[],!0),i.freehandCounter=i.pointColl.length,i.notify("draw",{prop:"setArrowDimension",onPropertyChange:!1,value:{arrowDimension:d}}),i.notify("freehand-draw",{prop:"setSelPointColl",onPropertyChange:!1,value:{obj:{selPointColl:t.extend([],a.selPointColl,[],!0)}}}),this.lowerContext.filter="none",i.transform.straighten=0,this.applyImgTranform(),i.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"iterate",pen:"iterate",isPreventApply:null}}),i.notify("freehand-draw",{prop:"updateFHDCurPts",onPropertyChange:!1}),this.lowerContext.filter=a.filter,0!==i.transform.degree&&i.notify("transform",{prop:"drawPannedImage",onPropertyChange:!1,value:{xDiff:0,yDiff:0}}),i.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.lowerContext}}),(i.isCircleCrop||i.currSelectionPoint&&"crop-circle"===i.currSelectionPoint.shape)&&i.notify("crop",{prop:"cropCircle",onPropertyChange:!1,value:{context:this.lowerContext,isSave:null,isFlip:null}})}}return{obj:l,point:p}},e.prototype.updateObjColl=function(){for(var e=this.parent,t=0;t<e.objColl.length;t++){var o=e.objColl[t];"line"!==o.shape&&"arrow"!==o.shape||(o.activePoint.width<0&&(o.activePoint.width=Math.abs(o.activePoint.width)),o.activePoint.height<0&&(o.activePoint.height=Math.abs(o.activePoint.height)))}},e.prototype.applyImgTranform=function(){for(var e=this.parent,o=t.extend({},e.activeObj,{},!0),i=0,r=e.objColl.length;i<r;i++)if("image"===e.objColl[i].shape){e.activeObj=t.extend({},e.objColl[i],{},!0);var a=e.objColl[i].imageCanvas.getContext("2d");e.notify("selection",{prop:"applyTransformToImg",onPropertyChange:!1,value:{ctx:a}}),this.upperContext.clearRect(0,0,e.upperCanvas.width,e.upperCanvas.height),e.notify("selection",{prop:"setImageClarity",onPropertyChange:!1,value:{bool:!0}})}e.activeObj=o},e.prototype.updateUndoRedoStack=function(e){var t=this.parent;if(t.activeObj.currIndex&&0!==t.activeObj.activePoint.width||0!==t.activeObj.activePoint.height||t.activeObj.pointColl&&t.activeObj.pointColl.length>0||e){var o="none"!==t.textArea.style.display,i=t.noPushUndo;if(t.noPushUndo=!1,t.isUndoRedoStack=!0,e){var r=t.togglePen,a={freehandDrawSelectedId:null};t.notify("freehand-draw",{prop:"getFreehandDrawSelectedId",onPropertyChange:!1,value:{obj:a}}),t.okBtn(),t.noPushUndo=i,a.freehandDrawSelectedId?(t.noRedact=!0,t.selectShape(a.freehandDrawSelectedId)):t.freeHandDraw(!0),t.togglePen=r}else if(t.activeObj.currIndex){var n=t.activeObj.currIndex;t.okBtn(),t.noPushUndo=i,t.noRedact=!0,t.selectShape(n),t.drawingShape&&t.notify("selection",{prop:"setCurrentDrawingShape",onPropertyChange:!1,value:{value:t.drawingShape.toLowerCase()}}),o&&t.enableTextEditing()}t.isUndoRedoStack=!1}},e}(),b=function(){var e=function(t,o){return(e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var o in t)t.hasOwnProperty(o)&&(e[o]=t[o])})(t,o)};return function(t,o){function i(){this.constructor=t}e(t,o),t.prototype=null===o?Object.create(o):(i.prototype=o.prototype,new i)}}(),m=function(e,t,o,i){var r,a=arguments.length,n=a<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,o):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(e,t,o,i);else for(var s=e.length-1;s>=0;s--)(r=e[s])&&(n=(a<3?r(n):a>3?r(t,o,n):r(t,o))||n);return a>3&&n&&Object.defineProperty(t,o,n),n},y=function(e){function o(){return null!==e&&e.apply(this,arguments)||this}return b(o,e),m([t.Property(null)],o.prototype,"brightness",void 0),m([t.Property(null)],o.prototype,"contrast",void 0),m([t.Property(null)],o.prototype,"hue",void 0),m([t.Property(null)],o.prototype,"saturation",void 0),m([t.Property(null)],o.prototype,"exposure",void 0),m([t.Property(null)],o.prototype,"opacity",void 0),m([t.Property(null)],o.prototype,"blur",void 0),o}(t.ChildProperty),P=function(e){function o(){return null!==e&&e.apply(this,arguments)||this}return b(o,e),m([t.Property(null)],o.prototype,"zoomTrigger",void 0),m([t.Property(1)],o.prototype,"minZoomFactor",void 0),m([t.Property(10)],o.prototype,"maxZoomFactor",void 0),m([t.Property(1)],o.prototype,"zoomFactor",void 0),m([t.Property(null)],o.prototype,"zoomPoint",void 0),o}(t.ChildProperty),j=function(e){function o(){return null!==e&&e.apply(this,arguments)||this}return b(o,e),m([t.Property(!0)],o.prototype,"showCircle",void 0),m([t.Property(null)],o.prototype,"strokeColor",void 0),m([t.Property(null)],o.prototype,"fillColor",void 0),o}(t.ChildProperty),x=function(e){function o(){return null!==e&&e.apply(this,arguments)||this}return b(o,e),m([t.Property("Arial")],o.prototype,"default",void 0),m([t.Property(null)],o.prototype,"items",void 0),o}(t.ChildProperty),w=function(r){function a(e,t){var o=r.call(this,e)||this;return o.isImageLoaded=!1,o.activeObj={activePoint:{startX:0,startY:0,endX:0,endY:0,width:0,height:0},flipObjColl:[],triangle:[],triangleRatio:[],rotatedAngle:0,opacity:1,order:null},o.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,isRedact:!1},o.objColl=[],o.pointColl={},o.freehandCounter=0,o.points=[],o.togglePen=!1,o.togglePan=!1,o.img={destLeft:0,destTop:0,destWidth:0,destHeight:0,srcLeft:0,srcTop:0,srcWidth:0,srcHeight:0},o.rotateFlipColl=[],o.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:"",straighten:0,destPoints:{startX:0,startY:0,width:0,height:0},srcPoints:{startX:0,startY:0,width:0,height:0},filter:"",isBrightAdjust:!1,zoomFactor:0,previousZoomValue:0,aspectWidth:null,aspectHeight:null,frame:"none",straightenZoom:0,adjustmentLevel:{brightness:0,contrast:0,hue:0,opacity:100,saturation:0,blur:0,exposure:0,transparency:100,sharpen:!1,bw:!1},currentFilter:""},o.afterCropActions=[],o.transform={degree:0,currFlipState:"",zoomFactor:0,cropZoomFactor:null,defaultZoomFactor:0,straighten:0},o.panPoint={currentPannedPoint:{x:0,y:0},totalPannedPoint:{x:0,y:0},totalPannedInternalPoint:{x:0,y:0},totalPannedClientPoint:{x:0,y:0}},o.isUndoRedo=!1,o.isCropTab=!1,o.isCircleCrop=!1,o.fontSizeColl=[],o.initialAdjustmentValue="",o.currentFilter="",o.canvasFilter="brightness(1) contrast(100%) hue-rotate(0deg) saturate(100%) opacity(1) blur(0px) sepia(0%) grayscale(0%) invert(0%)",o.toolbarHeight=0,o.isPublicMethod=!1,o.isCropToolbar=!1,o.cursor="default",o.resizeSrc={startX:o.img.srcLeft,startY:o.img.srcTop,width:o.img.srcWidth,height:o.img.srcHeight},o.isResize=!1,o.isAspectRatio=!1,o.frameObj={type:"none",color:"#fff",size:20,inset:20,offset:20,radius:0,amount:1,border:"solid",gradientColor:""},o.tempFrameObj={type:"none",color:"#fff",size:20,inset:20,offset:20,radius:0,amount:1,border:"solid",gradientColor:""},o.allowDownScale=!0,o.gradientColor="",o.size=20,o.inset=0,o.offset=0,o.borderRadius=0,o.lineCount=0,o.prevStraightenedDegree=0,o.tempStraighten=0,o.isStraightening=!1,o.isFinetuning=!1,o.isZoomBtnClick=!1,o.isFinetuneBtnClick=!1,o.isFilterCanvasClick=!1,o.isFrameBtnClick=!1,o.isChangesSaved=!1,o.isShapeDrawing=!1,o.noPushUndo=!1,o.isUndoRedoStack=!1,o.shapeColl=[],o.isKBDNavigation=!1,o.isMaskImage=!1,o.tempObjColl=[],o.tempPointColl=[],o.tempShapeColl=[],o.isImageUpdated=!1,o.noRedact=!1,o.tempRedactBlur=50,o.tempRedactPixel=40,o.tempToolbarHeight=0,o.tempToolbar=[],n.Inject(s,h,v,f,d,O),n.Inject(C),n.Inject(c),n.Inject(g),n.Inject(u),t&&o.appendTo(t),o}b(a,r),n=a,a.prototype.requiredModules=function(){var e=[];return e.push({member:"crop",args:[this]}),e.push({member:"draw",args:[this]}),e.push({member:"selection",args:[this]}),e.push({member:"transform",args:[this]}),e.push({member:"export",args:[this]}),e.push({member:"toolbar-module",args:[this]}),e.push({member:"undo-redo",args:[this]}),e.push({member:"filter",args:[this]}),e.push({member:"shape",args:[this]}),e.push({member:"freehand-draw",args:[this]}),e},a.prototype.preRender=function(){this.element.id=this.element.id||t.getUniqueID("ej2-image-editor"),this.isSafari=/^((?!chrome|android).)*safari/i.test(navigator.userAgent),t.Browser.isDevice&&this.element.classList.add("e-device"),this.initializeThemeColl()},a.prototype.render=function(){if(this.isAngular){var e=this.element,o=e.cloneNode(!0);e.parentNode.replaceChild(o,e),this.element=o,t.setValue("ej2_instances",[this],this.element)}this.initialize()},a.prototype.getModuleName=function(){return"image-editor"},a.prototype.getPersistData=function(){return this.addOnPersist([])},a.prototype.onPropertyChanged=function(o,i){for(var r,a=0,n=Object.keys(o);a<n.length;a++)switch(n[a]){case"cssClass":i.cssClass&&t.removeClass([this.element],i.cssClass.replace(/\s+/g," ").trim().split(" ")),o.cssClass&&t.addClass([this.element],o.cssClass.replace(/\s+/g," ").trim().split(" "));break;case"disabled":o.disabled?(this.element.classList.add("e-disabled"),this.unwireEvent()):(this.element.classList.remove("e-disabled"),this.wireEvent());break;case"height":this.element.style.height=o.height,this.update();break;case"width":this.element.style.width=o.width,this.update();break;case"theme":o.theme&&(this.theme&&""!==this.theme?this.theme=this.toPascalCase(this.theme):this.theme="Bootstrap5",this.upperContext.strokeStyle=this.themeColl[this.theme].primaryColor,this.upperContext.fillStyle=this.themeColl[this.theme].secondaryColor,this.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"main",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}}));break;case"finetuneSettings":o.finetuneSettings&&(this.finetuneSettings=o.finetuneSettings,this.notify("filter",{prop:"update-finetunes"}));break;case"locale":o.locale&&(this.notify("toolbar",{prop:"setLocale",onPropertyChange:!1,value:{locale:o.locale}}),this.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"main",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}}));break;case"allowUndoRedo":o.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":o.showQuickAccessToolbar?(this.showQuickAccessToolbar=!0,this.notify("toolbar",{prop:"create-qa-toolbar",onPropertyChange:!1}),r={freehandSelectedIndex:null},this.notify("freehand-draw",{prop:"getFreehandSelectedIndex",onPropertyChange:!1,value:{obj:r}}),this.activeObj.shape?this.notify("toolbar",{prop:"renderQAT",onPropertyChange:!1,value:{isPenEdit:null}}):r.freehandSelectedIndex&&this.notify("toolbar",{prop:"renderQAT",onPropertyChange:!1,value:{isPenEdit:!0}})):(this.showQuickAccessToolbar=!1,this.notify("toolbar",{prop:"destroy-qa-toolbar",onPropertyChange:!1}));break;case"zoomSettings":o.zoomSettings&&(this.zoomSettings.zoomTrigger=o.zoomSettings.zoomTrigger),t.isNullOrUndefined(this.zoomSettings.zoomTrigger)?(this.zoomSettings.zoomTrigger=e.ZoomTrigger.MouseWheel|e.ZoomTrigger.Pinch|e.ZoomTrigger.Toolbar|e.ZoomTrigger.Commands,this.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"main",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}})):(o.zoomSettings.zoomTrigger&e.ZoomTrigger.Toolbar)===e.ZoomTrigger.Toolbar&&this.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"main",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}});break;case"selectionSettings":o.selectionSettings&&(this.selectionSettings=o.selectionSettings,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}})));break;case"toolbar":o.toolbar&&(this.toolbar=o.toolbar,this.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"main",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}}));break;case"toolbarTemplate":o.toolbarTemplate&&(this.notify("toolbar",{prop:"destroy-bottom-toolbar",onPropertyChange:!1}),this.notify("toolbar",{prop:"destroy-top-toolbar",onPropertyChange:!1}),this.element.appendChild(this.createElement("div",{id:this.element.id+"_toolbarArea",className:"e-toolbar-area"})),this.toolbarTemplateFn());break;case"quickAccessToolbarTemplate":o.quickAccessToolbarTemplate&&(this.notify("toolbar",{prop:"destroy-qa-toolbar",onPropertyChange:!1}),this.quickAccessToolbarTemplateFn())}},a.prototype.destroy=function(){var e=[];this.element.removeAttribute("tabindex");var o=this.element.querySelector("#"+this.element.id+"_saveDialog");o&&"block"===o.style.display&&t.getComponent(document.getElementById(this.element.id+"_saveDialog"),"dialog").destroy(),this.cssClass&&(e=e.concat(this.cssClass.replace(/\s+/g," ").trim().split(" "))),t.removeClass([this.element],e),this.element.getAttribute("class")||this.element.removeAttribute("class"),this.unwireEvent(),this.notify("toolbar",{prop:"destroySubComponents",onPropertyChange:!1}),this.notify("destroyed",null),r.prototype.destroy.call(this),this.element.innerHTML=""},a.prototype.initialize=function(){if(this.toolbarTemplate?(this.element.appendChild(this.createElement("div",{id:this.element.id+"_toolbarArea",className:"e-toolbar-area"})),this.toolbarTemplateFn()):(this.notify("toolbar",{prop:"create-toolbar",onPropertyChange:!1}),this.notify("toolbar",{prop:"create-contextual-toolbar",onPropertyChange:!1})),this.createCanvas(),this.element.offsetWidth>359&&this.element.querySelector(".e-ie-min-drop-content")&&this.element.querySelector(".e-ie-drop-content")&&(this.element.querySelector(".e-ie-min-drop-content").style.display="none",this.element.querySelector(".e-ie-drop-content").style.display="block"),this.createDropUploader(),this.showQuickAccessToolbar){document.querySelector("#"+this.element.id+"_canvasWrapper").appendChild(this.createElement("div",{id:this.element.id+"_quickAccessToolbarArea",className:"e-quick-access-toolbar-area"}));var e=document.getElementById(this.element.id+"_quickAccessToolbarArea");e.style.position="absolute",e.style.display="none",this.activeObj&&(e.style.left=this.activeObj.activePoint.startX+"px",e.style.top=this.activeObj.activePoint.startY+"px"),e.style.width="100%"}this.quickAccessToolbarTemplate?this.quickAccessToolbarTemplateFn():this.notify("toolbar",{prop:"create-qa-toolbar",onPropertyChange:!1}),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.canvasFilter=this.lowerContext.filter,this.notify("toolbar",{prop:"setInitialAdjustmentValue",onPropertyChange:!1,value:{value:this.lowerContext.filter}}),this.cssClass&&t.addClass([this.element],this.cssClass.replace(/\s+/g," ").trim().split(" ")),this.element&&o.createSpinner({target:this.element}),this.initializeZoomSettings(),this.imgSrc&&this.open(this.imgSrc)},a.prototype.createDropUploader=function(){var e=this;new i.Uploader({dropArea:this.element.getElementsByClassName("e-canvas-wrapper")[0],allowedExtensions:".jpg, .jpeg, .png,.svg",multiple:!1,selected:function(t){if("change"===t.event.type||"drop"===t.event.type){var o=t.filesData[0].type,i="unsupported";"change"!==t.event.type&&("drop"!==t.event.type||1!==t.event.dataTransfer.files.length)||"png"!==o&&"jpg"!==o&&"jpeg"!==o&&"svg"!==o?("drop"===t.event.type&&t.event.dataTransfer.files.length>1&&(i="multi-select-image"),e.showDialogPopup(i)):e.notify("draw",{prop:"fileSelect",value:{inputElement:e.element.querySelector("#"+e.element.id+"_dropfileUpload"),args:t}})}}}).appendTo("#"+this.element.id+"_dropfileUpload")},a.prototype.dlgCloseBtnClick=function(){t.getComponent(document.getElementById(this.element.id+"_dialog"),"dialog").destroy()},a.prototype.showDialogPopup=function(e){var t="";this.element.querySelector("#"+this.element.id+"_dialog").style.display="block";var i,r={key:"DlgOK"};if(this.notify("toolbar",{prop:"getLocaleText",onPropertyChange:!1,value:{obj:r}}),"multi-select-image"===e){i={key:"ImageErrorDialogHeader"},this.notify("toolbar",{prop:"getLocaleText",onPropertyChange:!1,value:{obj:i}});a={key:"ImageErrorDialogContent"};this.notify("toolbar",{prop:"getLocaleText",onPropertyChange:!1,value:{obj:a}}),t="<span>"+a.value+"</span>"}else{i={key:"AlertDialogHeader"},this.notify("toolbar",{prop:"getLocaleText",onPropertyChange:!1,value:{obj:i}});var a={key:"AlertDialogContent"};this.notify("toolbar",{prop:"getLocaleText",onPropertyChange:!1,value:{obj:a}});var n={key:"SupportText"};this.notify("toolbar",{prop:"getLocaleText",onPropertyChange:!1,value:{obj:n}}),t="<span>"+a.value+" "+n.value+"<b> JPG, PNG, and SVG</b></span>"}new o.Dialog({header:i.value,closeOnEscape:!0,content:t,target:document.getElementById("target"),width:"285px",isModal:!0,animationSettings:{effect:"Zoom"},close:this.dlgCloseBtnClick.bind(this),buttons:[{click:this.dlgCloseBtnClick.bind(this),buttonModel:{content:r.value}}]}).appendTo("#"+this.element.id+"_dialog")},a.prototype.wireEvent=function(){t.EventHandler.add(document,"keydown",this.keyDownEventHandler,this),t.EventHandler.add(document,"keypress",this.keyUpEventHandler,this),t.EventHandler.add(this.upperCanvas,"mousedown",this.mouseDownEventHandler,this),t.EventHandler.add(this.upperCanvas,"mousemove",this.mouseMoveEventHandler,this),t.EventHandler.add(this.upperCanvas,"mouseup",this.mouseUpEventHandler,this),t.EventHandler.add(document,"mouseup",this.mouseUpEventHandler,this),t.EventHandler.add(this.lowerCanvas,"mousedown",this.canvasMouseDownHandler,this),t.EventHandler.add(this.lowerCanvas,"mousemove",this.canvasMouseMoveHandler,this),t.EventHandler.add(this.lowerCanvas,"mouseup",this.canvasMouseUpHandler,this),t.EventHandler.add(this.upperCanvas,"touchstart",this.touchStartHandler,this),t.EventHandler.add(this.lowerCanvas,"touchstart",this.touchStartHandler,this),t.EventHandler.add(this.lowerCanvas,"mousewheel DOMMouseScroll",this.handleScroll,this),t.EventHandler.add(this.upperCanvas,"mousewheel DOMMouseScroll",this.handleScroll,this),window.addEventListener("resize",this.windowResizeHandler.bind(this)),t.Browser.isIos||"safari"===t.Browser.info.name||screen.orientation.addEventListener("change",this.screenOrientation.bind(this)),this.notify("shape",{prop:"wireEvent",onPropertyChange:!1})},a.prototype.unwireEvent=function(){t.EventHandler.remove(document,"keydown",this.keyDownEventHandler),t.EventHandler.remove(document,"keypress",this.keyUpEventHandler),t.EventHandler.remove(this.upperCanvas,"mousedown",this.mouseDownEventHandler),t.EventHandler.remove(this.upperCanvas,"mousemove",this.mouseMoveEventHandler),t.EventHandler.remove(this.upperCanvas,"mouseup",this.mouseUpEventHandler),t.EventHandler.remove(document,"mouseup",this.mouseUpEventHandler),t.EventHandler.remove(this.lowerCanvas,"mousedown",this.canvasMouseDownHandler),t.EventHandler.remove(this.lowerCanvas,"mousemove",this.canvasMouseMoveHandler),t.EventHandler.remove(this.lowerCanvas,"mouseup",this.canvasMouseUpHandler),t.EventHandler.remove(this.upperCanvas,"touchstart",this.touchStartHandler),t.EventHandler.remove(this.lowerCanvas,"touchstart",this.touchStartHandler),t.EventHandler.remove(this.lowerCanvas,"mousewheel DOMMouseScroll",this.handleScroll),t.EventHandler.remove(this.upperCanvas,"mousewheel DOMMouseScroll",this.handleScroll),window.removeEventListener("resize",this.windowResizeHandler.bind(this)),t.Browser.isIos||"safari"===t.Browser.info.name||screen.orientation.removeEventListener("change",this.screenOrientation.bind(this)),this.notify("shape",{prop:"unWireEvent",onPropertyChange:!1}),this.notify("selection",{prop:"unWireEvent",onPropertyChange:!1})},a.prototype.createCanvas=function(){this.element.style.boxSizing="border-box";var e={toolbarHeight:0};this.notify("toolbar",{prop:"getToolbarHeight",value:{obj:e}});var t=e.toolbarHeight;this.toolbar&&this.toolbar.length>0&&-1===this.toolbar.indexOf("Open")&&(t=0),this.element.style.width=this.width,this.element.style.height=this.height;var o=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;"}})),i={key:"DragText"};this.notify("toolbar",{prop:"getLocaleText",onPropertyChange:!1,value:{obj:i}});var r={key:"DropText"};this.notify("toolbar",{prop:"getLocaleText",onPropertyChange:!1,value:{obj:r}});var a={key:"BrowseText"};this.notify("toolbar",{prop:"getLocaleText",onPropertyChange:!1,value:{obj:a}});var n={key:"SupportText"};this.notify("toolbar",{prop:"getLocaleText",onPropertyChange:!1,value:{obj:n}});var s=this.createElement("div",{id:this.element.id+"_dropArea",className:"e-ie-drop-area",attrs:{style:"position: relative;"}}),l=this.createElement("span",{className:"e-ie-drop-icon e-icons e-image",attrs:{style:"position: absolute;"}}),p=this.createElement("span",{className:"e-ie-drop-content",attrs:{style:"position: absolute; display: none;"}});p.textContent=i.value+" ";var h=this.createElement("span",{className:"e-ie-min-drop-content",attrs:{style:"position: absolute;"}});h.textContent=r.value+" ";var d=this.createElement("a",{id:this.element.id+"_dropBrowse",className:"e-ie-drop-browse"});d.textContent=a.value;var c=this.createElement("a",{id:this.element.id+"_dropBrowse",className:"e-ie-drop-browse"});c.textContent=a.value,p.appendChild(d),h.appendChild(c),d.href="",c.href="";var u=this.createElement("span",{className:"e-ie-drop-info",attrs:{position:"absolute"}});u.textContent=n.value+" SVG, PNG, and JPG";var v=s.appendChild(this.createElement("input",{id:this.element.id+"_dropfileUpload",className:"e-fileUpload e-image-upload"}));v.setAttribute("type","file"),v.setAttribute("accept","image/*"),s.appendChild(l),s.appendChild(p),s.appendChild(h),s.appendChild(u),o.appendChild(s),this.lowerCanvas=o.appendChild(this.createElement("canvas",{id:this.element.id+"_lowerCanvas",attrs:{name:"canvasImage"}})),this.maskCanvas=o.appendChild(this.createElement("canvas",{id:this.element.id+"_maskCanvas",attrs:{name:"canvasImage"}})),this.upperCanvas=o.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.baseImgCanvas=this.createElement("canvas",{id:this.element.id+"_baseImgCanvas",attrs:{name:"canvasImage"}}),this.textArea=o.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";var g=this.element.appendChild(this.createElement("input",{id:this.element.id+"_fileUpload",className:"e-fileUpload"}));g.setAttribute("type","file"),g.setAttribute("accept","image/*"),g.style.display="none",this.textArea.setAttribute("spellcheck","false"),this.textArea.style.lineHeight="normal",this.lowerCanvas.style.width=this.upperCanvas.style.width=this.maskCanvas.style.width=this.inMemoryCanvas.style.width="100%",this.lowerCanvas.style.height=this.upperCanvas.style.height=this.maskCanvas.style.height=this.inMemoryCanvas.style.height="100%",this.upperCanvas.style.position=this.lowerCanvas.style.position=this.maskCanvas.style.position=this.textArea.style.position="absolute",this.textArea.style.backgroundColor="transparent",this.textArea.style.display="none",this.maskCanvas.style.display=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"),d.addEventListener("click",function(e){return e.preventDefault(),v.click(),!1}),c.addEventListener("click",function(e){return e.preventDefault(),v.click(),!1})},a.prototype.touchStartHandler=function(e){this.notify("selection",{prop:"touchStartHandler",onPropertyChange:!1,value:{e:e}})},a.prototype.mouseDownEventHandler=function(e){"e-ie-drop-browse"!==e.target.className&&this.notify("selection",{prop:"mouseDownEventHandler",onPropertyChange:!1,value:{e:e}})},a.prototype.mouseMoveEventHandler=function(e){this.notify("selection",{prop:"mouseMoveEventHandler",onPropertyChange:!1,value:{e:e}})},a.prototype.mouseUpEventHandler=function(e){"e-ie-drop-browse"!==e.target.className&&this.notify("selection",{prop:"mouseUpEventHandler",onPropertyChange:!1,value:{e:e}})},a.prototype.keyDownEventHandler=function(e){this.notify("selection",{prop:"keyDownEventHandler",onPropertyChange:!1,value:{e:e}})},a.prototype.keyUpEventHandler=function(e){"block"!==this.textArea.style.display&&"inline-block"!==this.textArea.style.display||e.target.id!==this.element.id+"_textArea"||this.notify("selection",{prop:"textKeyDown",value:{e:e}})},a.prototype.canvasMouseDownHandler=function(e){"e-ie-drop-browse"!==e.target.className&&this.notify("selection",{prop:"canvasMouseDownHandler",onPropertyChange:!1,value:{e:e}})},a.prototype.canvasMouseMoveHandler=function(e){this.notify("selection",{prop:"canvasMouseMoveHandler",onPropertyChange:!1,value:{e:e}})},a.prototype.canvasMouseUpHandler=function(e){"e-ie-drop-browse"!==e.target.className&&this.notify("selection",{prop:"canvasMouseUpHandler",onPropertyChange:!1,value:{e:e}})},a.prototype.handleScroll=function(e){this.notify("selection",{prop:"handleScroll",onPropertyChange:!1,value:{e:e}})},a.prototype.adjustToScreen=function(){this.update()},a.prototype.screenOrientation=function(){t.Browser.isDevice&&setTimeout(this.adjustToScreen.bind(this),100)},a.prototype.windowResizeHandler=function(){!t.Browser.isDevice&&this.element.classList.contains("e-image-editor")&&this.adjustToScreen()},a.prototype.notifyResetForAllModules=function(){for(var e=this.requiredModules(),t=0;t<e.length;t++){var o=e[t].member;this.notify("toolbar-module"===o?"toolbar":o,{prop:"reset",onPropertyChange:!1})}},a.prototype.allowShape=function(e,t){this.isPublicMethod=!0,this.applyShapes();var o={inRange:!1};return this.notify("shape",{prop:"isPointsInRange",onPropertyChange:!1,value:{x:e,y:t,obj:o}}),o.inRange},a.prototype.clearSelection=function(e){this.notify("selection",{prop:"clearSelection",onPropertyChange:!1,value:{resetCrop:e}})},a.prototype.crop=function(){var e={isCrop:!1};return this.notify("crop",{prop:"crop",onPropertyChange:!1,value:{obj:e}}),e.isCrop},a.prototype.flip=function(e){this.notify("transform",{prop:"flip",value:{direction:e}}),this.notify("draw",{prop:"redrawDownScale"}),this.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"ok"}});var t={action:"flip",actionEventArgs:this.editCompleteArgs};this.triggerEditCompleteEvent(t)},a.prototype.getImageData=function(e){var o;if(e=!!t.isNullOrUndefined(e)||e){var i={canvas:null};this.applyShapes(),this.notify("export",{prop:"exportToCanvas",value:{object:i}}),o=i.canvas.getContext("2d").getImageData(0,0,i.canvas.width,i.canvas.height)}else this.isMaskImage&&"mask-drawing"===this.element.getAttribute("data-value")?(o=this.getData(!0),this.updateColl("reset")):(o=this.getData(),this.notify("draw",{prop:"render-image",value:{isMouseWheel:!1}}));return o},a.prototype.open=function(e,o,i){if(o=!!t.isNullOrUndefined(o)||o){if(t.isNullOrUndefined(e))return;var r=document.getElementById(this.element.id+"_dropArea");r&&(r.style.display="none"),this.notify("draw",{prop:"open",value:{data:e}})}else this.updateImage(e,i.backgroundColor)},a.prototype.reset=function(){this.updateColl("reset");var e={isErrorImage:!1};if(this.notify("draw",{prop:"getErrorImage",value:{obj:e}}),!this.disabled&&!e.isErrorImage){this.clearContext(this.inMemoryContext),this.clearContext(this.lowerContext),this.clearContext(this.upperContext),this.notify("shape",{prop:"setRedactType",onPropertyChange:!1,value:{redactType:"blur"}}),this.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),this.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"main",isApplyBtn:!1,isCropping:!1,isZooming:null,cType:null}}),t.Browser.isDevice&&document.getElementById(this.element.id+"_bottomToolbar")&&(t.getComponent(document.getElementById(this.element.id+"_bottomToolbar"),"toolbar").destroy(),this.notify("toolbar",{prop:"create-bottom-toolbar",onPropertyChange:!1}));var o=this.isImageLoaded;this.currObjType.isUndoAction=this.isUndoRedo=this.togglePan=this.togglePen=this.isImageLoaded=this.isFinetuning=!1,this.isCircleCrop=this.isCropTab=!1,this.objColl=[],this.transform.degree=0,this.upperCanvas.style.display="block",this.transform.currFlipState="",this.allowDownScale=!0,this.upperCanvas.style.cursor=this.cursor=this.lowerCanvas.style.cursor="default",this.lowerContext.lineWidth=this.upperContext.lineWidth=void 0,this.frameDestPoints=null,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.frameObj={type:"none",color:"#fff",size:20,inset:20,offset:20,radius:0,amount:1,border:"solid",gradientColor:""},this.tempFrameObj={type:"none",color:"#fff",size:20,inset:20,offset:20,radius:0,amount:1,border:"solid",gradientColor:""},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,isRedact:!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:"",straighten:0,zoomFactor:0,previousZoomValue:0,destPoints:{startX:0,startY:0,width:0,height:0},frame:"none",srcPoints:{startX:0,startY:0,width:0,height:0},filter:"",isBrightAdjust:!1,aspectWidth:null,aspectHeight:null,straightenZoom:0,adjustmentLevel:{brightness:0,contrast:0,hue:0,opacity:100,saturation:0,blur:0,exposure:0,transparency:100,sharpen:!1,bw:!1},currentFilter:""},this.afterCropActions=[],this.currentFilter="",this.tempFrameZoomLevel=null,this.cxtTbarHeight=null,this.straightenPoint=null,this.transform.straighten=0,this.cancelCropSelection=null,this.aspectWidth=this.aspectHeight=null,this.isResize=this.isMaskImage=!1,this.drawingShape=null,this.isShapeDrawing=this.noPushUndo=this.isUndoRedoStack=this.isKBDNavigation=!1,this.shapeColl=[],this.tempObjColl=[],this.tempPointColl=[],this.tempShapeColl=[],this.isImageUpdated=!1,this.tempToolbarHeight=0,this.tempToolbar=[],this.tempRedactBlur=50,this.tempRedactPixel=40;var i={initialZoomValue:!1};this.editCompleteArgs=null,this.isFinetuneBtnClick=!1,this.notify("draw",{prop:"getInitialZoomValue",onPropertyChange:!1,value:{obj:i}}),i.initialZoomValue&&this.setProperties({zoomSettings:{zoomFactor:i.initialZoomValue}},!0);var r=document.getElementById(this.element.id+"_quickAccessToolbarArea");r&&(r.style.display="none"),this.notifyResetForAllModules(),this.notify("filter",{prop:"update-finetunes"}),this.toolbarTemplate?this.toolbarHeight=this.element.querySelector("#"+this.element.id+"_toolbarArea").clientHeight:this.element.querySelector("#"+this.element.id+"_toolbar")&&(this.toolbarHeight=this.element.querySelector("#"+this.element.id+"_toolbar").clientHeight),this.notify("toolbar",{prop:"setToolbarHeight",value:{height:this.toolbarHeight}}),this.isImageLoaded=o,this.straightenBaseImageCanvas(),this.isImageLoaded=!1,this.notify("draw",{prop:"update-canvas",onPropertyChange:!1}),this.isImageLoaded=o,this.prevStraightenedDegree=0;var a=this.element.querySelector(".e-contextual-toolbar-wrapper");a&&a.classList.add("e-hide"),this.notify("toolbar",{prop:"refresh-dropdown-btn",value:{isDisabled:!1}}),this.notify("toolbar",{prop:"enable-disable-btns"});var n={bool:this.isStraightening};t.Browser.isDevice&&n.bool&&this.notify("crop",{prop:"resizeWrapper"});var s={action:"reset",actionEventArgs:null};this.triggerEditCompleteEvent(s)}},a.prototype.rotate=function(e){var t={isRotate:!1};90!==e&&-90!==e||this.updateImageTransformColl(90===e?"rotateright":"rotateleft"),this.notify("transform",{prop:"rotate",value:{degree:e,obj:t}}),this.notify("draw",{prop:"redrawDownScale"});var o={action:"rotate",actionEventArgs:this.editCompleteArgs};return this.triggerEditCompleteEvent(o),t.isRotate},a.prototype.export=function(e,t,o){this.applyShapes(),this.notify("export",{prop:"export",onPropertyChange:!1,value:{type:e,fileName:t,imgQuality:o}})},a.prototype.select=function(e,t,o,i,r){this.applyShapes(),this.notify("toolbar",{prop:"performCropTransformClick",value:{shape:"crop-"+e}}),this.notify("draw",{prop:"select",onPropertyChange:!1,value:{type:e,startX:t,startY:o,width:i,height:r}}),t&&o||i&&r?this.notify("draw",{prop:"select",onPropertyChange:!1,value:{type:e,startX:t,startY:o,width:i,height:r}}):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:"",straighten:0,zoomFactor:0,previousZoomValue:0,destPoints:{startX:0,startY:0,width:0,height:0},frame:"none",srcPoints:{startX:0,startY:0,width:0,height:0},filter:"",isBrightAdjust:!1,aspectWidth:null,aspectHeight:null,straightenZoom:0,adjustmentLevel:{brightness:0,contrast:0,hue:0,opacity:100,saturation:0,blur:0,exposure:0,transparency:100,sharpen:!1,bw:!1},currentFilter:""}},a.prototype.freeHandDraw=function(e){this.notify("freehand-draw",{prop:"freeHandDraw",onPropertyChange:!1,value:{value:e}})},a.prototype.freehandDraw=function(t){if(!this.disabled&&this.isImageLoaded){if(!t&&this.isMaskImage)return void this.discard();this.applyShapes(),this.freeHandDraw(t);var o={shapeSettingsObj:{}};this.notify("selection",{prop:"updatePrevShapeSettings",onPropertyChange:!1,value:{obj:o}});var i=o.shapeSettingsObj;i.type=e.ShapeType.FreehandDraw;var r={cancel:!1,action:"insert",previousShapeSettings:i,currentShapeSettings:i};this.notify("freehand-draw",{prop:"triggerShapeChanging",value:{shapeChangingArgs:r}})}},a.prototype.pan=function(e,t,o){this.applyShapes(),this.notify("transform",{prop:"pan",onPropertyChange:!1,value:{value:e,x:t,y:o}})},a.prototype.zoom=function(e,t){this.isZoomBtnClick=!0,this.notify("transform",{prop:"zoom",onPropertyChange:!1,value:{zoomFactor:e,zoomPoint:t}}),this.notify("draw",{prop:"redrawDownScale"})},a.prototype.drawEllipse=function(e,o,i,r,a,n,s,l,p){var h=!1,d=this.allowShape(e,o);return!this.disabled&&this.isImageLoaded&&(d||t.isNullOrUndefined(e)&&t.isNullOrUndefined(o))&&(h=!0,this.notify("shape",{prop:"drawEllipse",onPropertyChange:!1,value:{x:e,y:o,radiusX:i,radiusY:r,strokeWidth:a,strokeColor:n,fillColor:s,degree:l,isSelected:p}}),this.editCompleted()),h},a.prototype.drawLine=function(e,o,i,r,a,n,s){var l=!1,p=this.allowShape(e,o);return!this.disabled&&this.isImageLoaded&&(p||t.isNullOrUndefined(e)&&t.isNullOrUndefined(o))&&(l=!0,this.notify("shape",{prop:"drawLine",onPropertyChange:!1,value:{startX:e,startY:o,endX:i,endY:r,strokeWidth:a,strokeColor:n,isSelected:s}}),this.editCompleted()),l},a.prototype.drawArrow=function(e,o,i,r,a,n,s,l,p){var h=!1,d=this.allowShape(e,o);return!this.disabled&&this.isImageLoaded&&(d||t.isNullOrUndefined(e)&&t.isNullOrUndefined(o))&&(h=!0,this.notify("shape",{prop:"drawArrow",onPropertyChange:!1,value:{startX:e,startY:o,endX:i,endY:r,strokeWidth:a,strokeColor:n,arrowStart:s,arrowEnd:l,isSelected:p}}),this.editCompleted()),h},a.prototype.drawPath=function(e,o,i,r){this.isPublicMethod=!0;var a={inRange:!1},n=!1;if(e&&e.length>0)for(var s=0;s<e.length&&!a.inRange;s++)this.notify("shape",{prop:"isPointsInRange",onPropertyChange:!1,value:{x:e[s].x,y:e[s].y,obj:a}});return!this.disabled&&this.isImageLoaded&&(a.inRange||t.isNullOrUndefined(e))&&(n=!0,this.applyShapes(),this.notify("shape",{prop:"drawPath",onPropertyChange:!1,value:{pointColl:e,strokeWidth:o,strokeColor:i,isSelected:r}}),this.editCompleted()),n},a.prototype.drawRectangle=function(e,o,i,r,a,n,s,l,p,h){var d=!1,c=this.allowShape(e,o);return!this.disabled&&this.isImageLoaded&&(c||t.isNullOrUndefined(e)&&t.isNullOrUndefined(o))&&(d=!0,this.notify("shape",{prop:"drawRectangle",onPropertyChange:!1,value:{x:e,y:o,width:i,height:r,strokeWidth:a,strokeColor:n,fillColor:s,degree:l,isSelected:p,radius:h}}),this.editCompleted()),d},a.prototype.drawText=function(e,o,i,r,a,n,s,l,p,h,d,c,u){var v=!1,g=this.allowShape(e,o);return!this.disabled&&this.isImageLoaded&&(g||t.isNullOrUndefined(e)&&t.isNullOrUndefined(o))&&(v=!0,this.notify("shape",{prop:"drawText",onPropertyChange:!1,value:{x:e,y:o,text:i,fontFamily:r,fontSize:a,bold:n,italic:s,color:l,isSelected:p,degree:h,fillColor:d,outlineColor:c,outlineWidth:u}}),this.editCompleted()),v},a.prototype.drawImage=function(e,o,i,r,a,n,s,l,p){var h=!1,d=this.allowShape(o,i);if(!this.disabled&&this.isImageLoaded&&(d||t.isNullOrUndefined(o)&&t.isNullOrUndefined(i))){var c=this.objColl.length;this.notify("shape",{prop:"drawImage",onPropertyChange:!1,value:{x:o,y:i,width:r,height:a,src:e,degree:s,isAspectRatio:n,opacity:l,isSelected:p}}),this.editCompleted(),this.objColl.length>c&&(h=!0)}return h},a.prototype.updateShape=function(e,o){var i={isSelected:!1},r=!1,a={bool:!1};if(t.isNullOrUndefined(e.id))e.strokeColor&&(this.activeObj.strokeSettings.strokeColor=e.strokeColor),e.fillColor&&(this.activeObj.strokeSettings.fillColor=e.fillColor),e.strokeWidth&&(this.activeObj.strokeSettings.strokeWidth=e.strokeWidth),e.index&&(this.activeObj.order=e.index),"FreehandDraw"===e.type&&e.strokeWidth&&this.notify("freehand-draw",{prop:"setPenStrokeWidth",onPropertyChange:!1,value:{value:e.strokeWidth}});else if("text"!==e.type.toLowerCase()||"block"!==this.textArea.style.display&&"inline-block"!==this.textArea.style.display||(this.okBtn(null,!0),r=!0),this.notify("shape",{prop:"selectShape",onPropertyChange:!1,value:{id:e.id,obj:i}}),this.notify("selection",{prop:"getFreehandDrawEditing",onPropertyChange:!1,value:{obj:a}}),i.isSelected){var n=this.activeObj.textSettings.fontSize;if(this.notify("shape",{prop:"updateShapeChangeEventArgs",onPropertyChange:!1,value:{shapeSettings:e}}),"text"===this.activeObj.shape&&n){var s=this.activeObj.textSettings.fontSize-n;0!==s&&(this.activeObj.activePoint.height+=s,this.activeObj.activePoint.startY-=s/2,this.activeObj.activePoint.endY+=s/2,this.notify("draw",{prop:"updateActiveObject",onPropertyChange:!1,value:{actPoint:this.activeObj.activePoint,obj:this.activeObj,isMouseMove:null,x:null,y:null}}))}var l=t.extend({},this.activeObj,{},!0);this.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),this.notify("draw",{prop:"render-image",value:{isMouseWheel:null,isPreventClearRect:null,isFrame:null}}),this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),l.shape&&this.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate",obj:l}}),"text"===this.activeObj.shape&&this.notify("toolbar",{prop:"editText",onPropertyChange:!1}),a.bool&&this.notify("undo-redo",{prop:"setPreventUR",value:{bool:!0}}),this.okBtn(o,!0),a.bool&&this.notify("undo-redo",{prop:"setPreventUR",value:{bool:!1}}),this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),this.editCompleteArgs={action:"shape-update",currentShapeSettings:e},this.editCompleted("shape-customize"),r&&this.enableTextEditing(),o&&(this.noRedact=!0,this.selectShape(e.id))}return i.isSelected},a.prototype.selectShape=function(e){this.applyShapes();var t={isSelected:!1};return this.notify("shape",{prop:"selectShape",onPropertyChange:!1,value:{id:e,obj:t}}),this.editCompleted("shape-select"),this.noRedact=!1,t.isSelected},a.prototype.deleteShape=function(e){"Redact"!==this.getShapeSetting(e).type&&(this.applyShapes(),this.notify("shape",{prop:"deleteShape",onPropertyChange:!1,value:{id:e}}),this.editCompleted("shape-delete"))},a.prototype.getShapeSetting=function(e){this.applyShapes();var t={shapeDetails:null};return this.notify("shape",{prop:"getShapeSetting",onPropertyChange:!1,value:{id:e,obj:t}}),this.notify("draw",{prop:"redrawDownScale"}),t.shapeDetails?t.shapeDetails:{}},a.prototype.getShapeSettings=function(){this.applyShapes();var e={shapeDetailsColl:[]};return this.notify("shape",{prop:"getShapeSettings",onPropertyChange:!1,value:{obj:e}}),this.notify("draw",{prop:"redrawDownScale"}),e.shapeDetailsColl.filter(function(e){return"redact"!==e.type})},a.prototype.getRedacts=function(){this.applyShapes();var e={shapeDetailsColl:[]};return this.notify("shape",{prop:"getRedactSettings",onPropertyChange:!1,value:{obj:e}}),this.notify("draw",{prop:"redrawDownScale"}),e.shapeDetailsColl.filter(function(e){return"redact"!==e.type})},a.prototype.selectRedact=function(e){this.applyShapes();var t={isSelected:!1};return this.notify("shape",{prop:"selectShape",onPropertyChange:!1,value:{id:e,obj:t}}),this.editCompleted("redact-select"),this.noRedact=!1,t.isSelected},a.prototype.deleteRedact=function(e){this.applyShapes(),this.notify("shape",{prop:"deleteShape",onPropertyChange:!1,value:{id:e}}),this.editCompleted("redact-delete")},a.prototype.updateRedact=function(e,o){this.applyShapes();var i={isSelected:!1};if(this.notify("shape",{prop:"selectShape",onPropertyChange:!1,value:{id:e.id,obj:i}}),i.isSelected){this.notify("shape",{prop:"updateShapeChangeEventArgs",onPropertyChange:!1,value:{shapeSettings:e}}),e.blurIntensity&&(this.activeObj.redactBlur=e.blurIntensity),e.pixelSize&&(this.activeObj.redactPixelate=e.pixelSize),this.activeObj.redactType="blur"===e.type.toLowerCase()?"blur":"pixelate";var r=t.extend({},this.activeObj,{},!0);this.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),this.notify("draw",{prop:"render-image",value:{isMouseWheel:null,isPreventClearRect:null,isFrame:null}}),this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),r.shape&&this.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate",obj:r}}),this.okBtn(o,!0),this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),this.editCompleteArgs={action:"redact-update",currentShapeSettings:e},this.editCompleted("redact-customize"),o&&this.selectRedact(e.id)}return i.isSelected},a.prototype.update=function(){this.notify("transform",{prop:"update"})},a.prototype.finetuneImage=function(e,t){!this.disabled&&this.isImageLoaded&&(this.applyShapes(),this.notify("filter",{prop:"finetuneImage",value:{value:t,option:e}}),this.editCompleteArgs={finetune:e,value:t},this.editCompleted("fine-tune"))},a.prototype.applyImageFilter=function(e){!this.disabled&&this.isImageLoaded&&(this.applyShapes(),this.notify("filter",{prop:"applyImageFilter",value:{option:e.toString()}}),this.editCompleteArgs={filter:e},this.editCompleted("filter"),this.canvasFilter=this.lowerContext.filter,this.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"ok"}}))},a.prototype.undo=function(){this.applyShapes(),this.notify("undo-redo",{prop:"undo",onPropertyChange:!1}),this.notify("draw",{prop:"redrawDownScale"})},a.prototype.redo=function(){this.applyShapes(),this.notify("undo-redo",{prop:"redo",onPropertyChange:!1}),this.notify("draw",{prop:"redrawDownScale"})},a.prototype.getImageDimension=function(){return{x:this.img.destLeft,y:this.img.destTop,width:this.img.destWidth,height:this.img.destHeight}},a.prototype.resize=function(e,o,i){var r=!1;if(e.toString().length<=4&&o.toString().length<=4){this.applyShapes();var a={startX:this.img.destLeft,startY:this.img.destTop,width:this.img.destWidth,height:this.img.destHeight};i?(this.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"resize",isApplyBtn:!1,isCropping:!1}}),this.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"resize",isApplyBtn:!1,isCropping:!1}})):this.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"resize",isApplyBtn:!1,isCropping:!1}});var n=this.element.querySelector("#"+this.element.id+"_resizeWidth"),s=this.element.querySelector("#"+this.element.id+"_resizeHeight");n&&s&&(t.getComponent(n,"numerictextbox").value=Math.floor(e),n.value=Math.floor(e).toString()+" px",t.getComponent(s,"numerictextbox").value=Math.floor(o),s.value=Math.floor(o).toString()+" px"),this.notify("transform",{prop:"resize",value:{width:e,height:o,isAspectRatio:i}}),a.startX!==this.img.destLeft||a.startY!==this.img.destTop||a.width!==this.img.destWidth||a.height!==this.img.destHeight?(r=!0,this.okBtn()):this.notify("draw",{prop:"performCancel",value:{isContextualToolbar:null}}),this.notify("draw",{prop:"redrawDownScale"})}return r},a.prototype.drawFrame=function(o,i,r,a,n,s,l,p,h){this.applyShapes();var d=!1,c={frameChangeEventArgs:null};i=i||"#fff",r=r||"",a=a||20,n=n||0,s=s||0,l=l||0,p=p||e.FrameLineStyle.Solid,h=h||0;var u={type:this.toPascalCase(this.frameObj.type),color:this.frameObj.color,gradientColor:this.frameObj.gradientColor,size:this.frameObj.size,inset:this.frameObj.inset,offset:this.frameObj.offset,borderRadius:this.frameObj.radius,frameLineStyle:this.toPascalCase(this.frameObj.border),lineCount:this.frameObj.amount};return t.extend(this.tempFrameObj,this.frameObj),this.tempFrameZoomLevel=this.transform.zoomFactor,this.frameDestPoints=t.extend({},this.img,{},!0),this.notify("toolbar",{prop:"frameToolbarClick"}),this.frameObj.type=o.toLowerCase(),this.frameObj.color=i,this.frameObj.gradientColor=r,this.frameObj.size=a,this.frameObj.inset=n,this.frameObj.offset=s,this.frameObj.radius=l,this.frameObj.border=p.toLowerCase(),this.frameObj.amount=h,this.notify("draw",{prop:"triggerFrameChange",value:{prevFrameSettings:u,obj:c}}),c.frameChangeEventArgs&&!c.frameChangeEventArgs.cancel?(this.notify("draw",{prop:"render-image",value:{isMouseWheel:null}}),JSON.stringify(this.frameObj)!==JSON.stringify(this.tempFrameObj)?(d=!0,this.okBtn()):this.tempFrameZoomLevel=null):(this.notify("draw",{prop:"performCancel",value:{isContextualToolbar:null}}),t.extend(this.frameObj,this.tempFrameObj),this.tempFrameZoomLevel=null),this.notify("draw",{prop:"redrawDownScale"}),d},a.prototype.straightenImage=function(e){var t=!1;return e>=-45&&e<=45&&(this.applyShapes(),t=!0,this.notify("transform",{prop:"straightenImage",value:{degree:e}}),this.notify("draw",{prop:"redrawDownScale"})),t},a.prototype.cloneShape=function(e){var t={isSelected:!1};return"shape"===e.split("_")[0]&&(this.notify("shape",{prop:"selectShape",onPropertyChange:!1,value:{id:e,obj:t}}),t.isSelected&&(this.notify("toolbar",{prop:"duplicateShape",onPropertyChange:!1,value:{isPreventUndoRedo:!1}}),this.okBtn(null,!0),this.notify("draw",{prop:"redrawDownScale"}))),t.isSelected},a.prototype.getImageFilter=function(e){var t=this.createElement("canvas").getContext("2d");return this.notify("filter",{prop:"updateAdj",value:{type:e.toLowerCase(),value:null,isPreview:!0,ctx:t}}),t.filter},a.prototype.enableTextEditing=function(){var e=t.extend({},this.activeObj,{},!0);e.order||(this.noPushUndo=!0,this.okBtn(),this.noPushUndo=!1,this.noRedact=!0,this.selectShape(e.currIndex),e.order=this.activeObj.order),this.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),this.notify("draw",{prop:"render-image",value:{isMouseWheel:null,isPreventClearRect:null,isFrame:!1}}),this.activeObj=e,this.notify("toolbar",{prop:"editText",onPropertyChange:!1})},a.prototype.canUndo=function(){var e=!1;return this.getUndoRedoColl().index>0&&(e=!0),e},a.prototype.canRedo=function(){var e=!1,t=this.getUndoRedoColl(),o=t.undoRedoColl,i=t.index;return o&&o.length>0&&i<o.length-1&&(e=!0),i===o.length?e=!1:0===i&&o.length>0?e=!0:i>0&&(e=!0),e},a.prototype.apply=function(){this.isMaskImage?this.discard():(this.updateColl("reset"),this.closeOverlayTbar(),this.okBtn(null,!0))},a.prototype.discard=function(){this.updateColl("reset"),this.notify("draw",{prop:"performCancel",value:{isContextualToolbar:this.closeOverlayTbar(),isFinalCancel:!0}})},a.prototype.enableShapeDrawing=function(e,t){if(t&&(this.drawingShape=e.toLowerCase(),this.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1})),e&&t){this.currObjType.shape=e.toLowerCase(),this.activeObj.shape=this.currObjType.shape,this.currObjType.isDragging=this.currObjType.isCustomCrop=!1,this.activeObj.shapeDegree=this.transform.degree,this.activeObj.shapeFlip=this.transform.currFlipState,this.activeObj.textFlip=this.transform.currFlipState,this.activeObj.flipObjColl=[];var o={order:null};this.notify("shape",{prop:"getNewOrder",onPropertyChange:!1,value:{obj:o}}),this.activeObj.order=o.order,this.notify("selection",{prop:"annotate",value:{shape:this.currObjType.shape}}),"text"===this.currObjType.shape?this.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"text",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}}):"redact"===this.currObjType.shape?this.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"redact",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}}):this.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"shapes",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}}),this.notify("toolbar",{prop:"update-toolbar-items",onPropertyChange:!1})}else t||this.okBtn(null,!0)},a.prototype.bringToFront=function(e){this.noRedact=!0,this.selectShape(e)&&(this.updateShapeOrder(e,"bringToFront"),this.apply())},a.prototype.bringForward=function(e){this.noRedact=!0,this.selectShape(e)&&(this.updateShapeOrder(e,"bringForward"),this.apply())},a.prototype.sendToBack=function(e){this.noRedact=!0,this.selectShape(e)&&(this.updateShapeOrder(e,"sendToBack"),this.apply())},a.prototype.sendBackward=function(e){this.noRedact=!0,this.selectShape(e)&&(this.updateShapeOrder(e,"sendBackward"),this.apply())},a.prototype.clearImage=function(){this.reset(),this.isImageLoaded=!1,this.lowerContext.clearRect(0,0,this.lowerCanvas.width,this.lowerCanvas.height),this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height);var e=document.getElementById(this.element.id+"_bottomToolbar");t.Browser.isDevice&&e&&(document.getElementById(this.element.id+"_bottomToolbar").style.display="none"),this.notify("toolbar",{prop:"destroy-top-toolbar",onPropertyChange:!1}),this.notify("toolbar",{prop:"create-toolbar",onPropertyChange:!1}),this.notify("toolbar",{prop:"create-contextual-toolbar",onPropertyChange:!1});var o=document.getElementById(this.element.id+"_dropArea");o&&(o.style.display="block")},a.prototype.selectMaskImage=function(e,t){e=e||10,t=t||"#512da880",this.applyShapes(),this.isMaskImage=!0,this.updateColl("empty"),this.enableDisableToolbar(!0),this.update(),this.activeObj.strokeSettings.strokeWidth=e,this.notify("freehand-draw",{prop:"setPenStrokeWidth",onPropertyChange:!1,value:{value:e}}),this.activeObj.strokeSettings.strokeColor=t,this.notify("freehand-draw",{prop:"freeHandDraw",onPropertyChange:!1,value:{value:!0}}),this.maskCanvas.style.display="block"},a.prototype.enableDisableToolbar=function(e){var o,i=document.getElementById(this.element.id+"_toolbar");i&&(o=t.getComponent(i,"toolbar"))&&o.disable(e),(i=document.getElementById(this.element.id+"_bottomToolbar"))&&(o=t.getComponent(i,"toolbar"))&&o.disable(e)},a.prototype.updateImage=function(e,o){var i=this;if(e||o){var r=t.extend({},this.cropObj,{},!0),a={currObj:{}};this.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:a}});var n=a.currObj;n.objColl=t.extend([],this.objColl,[],!0),n.pointColl=t.extend([],this.pointColl,[],!0),n.afterCropActions=t.extend([],this.afterCropActions,[],!0);var s={selPointColl:null};if(this.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:s}}),n.selPointColl=t.extend([],s.selPointColl,[],!0),e){if(this.isImageUpdated=!0,"string"!=typeof e){var l=this.createElement("canvas");l.width=e.width,l.height=e.height,l.getContext("2d").putImageData(e,0,0),e=l.toDataURL()}this.baseImg.src=e,setTimeout(function(){0!==i.cropObj.straighten?(i.notify("toolbar",{prop:"performCropTransformClick",value:{shape:"crop-custom"}}),i.noPushUndo=!0,i.crop(),i.noPushUndo=!1):i.notify("draw",{prop:"render-image",value:{isMouseWheel:!1}}),i.isImageUpdated=!1,o||(i.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"updateImage",previousObj:n,previousObjColl:n.objColl,previousPointColl:n.pointColl,previousSelPointColl:n.selPointColl,previousCropObj:r,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),i.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"ok"}}))},100)}o&&(this.notify("draw",{prop:"imageBackgroundColor",onPropertyChange:!1,value:{color:o}}),this.notify("draw",{prop:"render-image",value:{isMouseWheel:!1}}),e||(this.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"bgColor",previousObj:n,previousObjColl:n.objColl,previousPointColl:n.pointColl,previousSelPointColl:n.selPointColl,previousCropObj:r,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),this.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"ok"}}))),e&&o&&(this.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"updateImage",previousObj:n,previousObjColl:n.objColl,previousPointColl:n.pointColl,previousSelPointColl:n.selPointColl,previousCropObj:r,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),this.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"ok"}}))}},a.prototype.editCompleted=function(e){this.notify("draw",{prop:"redrawDownScale"});var t={action:e||"shape-insert",actionEventArgs:this.editCompleteArgs};this.triggerEditCompleteEvent(t)},a.prototype.updateColl=function(e){this.isMaskImage&&("empty"===e?(this.tempToolbarHeight=this.toolbarHeight,this.tempToolbar=this.toolbar?t.extend([],this.toolbar,[],!0):null,this.tempObjColl=t.extend([],this.objColl,[],!0),this.tempPointColl=t.extend([],this.pointColl,[],!0),this.tempShapeColl=t.extend([],this.shapeColl,[],!0),this.objColl=[],this.pointColl=[],this.shapeColl=[],this.freehandCounter=0,this.notify("freehand-draw",{prop:"setCurrentFreehandDrawIndex",value:{value:0}}),this.notify("draw",{prop:"render-image",value:{isMouseWheel:!1}})):"reset"===e&&(this.objColl=this.tempObjColl,this.pointColl=this.tempPointColl,this.shapeColl=this.tempShapeColl,this.freehandCounter=this.pointColl.length,this.notify("freehand-draw",{prop:"setCurrentFreehandDrawIndex",value:{value:this.freehandCounter}}),this.enableDisableToolbar(!1),0!==this.cropObj.straighten&&(this.notify("toolbar",{prop:"performCropTransformClick",value:{shape:"crop-custom"}}),this.noPushUndo=!0,this.crop(),this.noPushUndo=!1),this.notify("draw",{prop:"render-image",value:{isMouseWheel:!1}}),this.isMaskImage=!1,this.upperContext.globalCompositeOperation="source-over",this.maskCanvas.style.display="none",this.activeObj.strokeSettings={strokeColor:"#fff",fillColor:"",strokeWidth:null,radius:null,outlineColor:"",outlineWidth:null},this.notify("shape",{prop:"setStrokeSettings",value:{strokeSettings:this.activeObj.strokeSettings,strokeColor:"#fff",fillColor:"",strokeWidth:null,outlineWidth:null}}),this.notify("freehand-draw",{prop:"setPenStrokeWidth",onPropertyChange:!1,value:{value:2}}),this.notify("freehand-draw",{prop:"setMasking",onPropertyChange:!1,value:{value:!1}})))},a.prototype.resetToolbar=function(){this.toolbarHeight!==this.tempToolbarHeight&&!(t.isNullOrUndefined(this.toolbar)||this.toolbar&&this.toolbar.length>0)&&t.isNullOrUndefined(this.toolbarTemplate)&&(this.toolbarHeight=this.tempToolbarHeight,this.notify("toolbar",{prop:"setToolbarHeight",value:{height:this.toolbarHeight}}),this.toolbar=this.tempToolbar,this.toolbarTemplate||(this.notify("toolbar",{prop:"create-toolbar",onPropertyChange:!1}),this.notify("toolbar",{prop:"create-contextual-toolbar",onPropertyChange:!1})),this.update())},a.prototype.getData=function(e){e&&this.resetToolbar();var o=t.extend([],this.objColl,null,!0),i=t.extend([],this.pointColl,null,!0),r=t.extend([],this.shapeColl,null,!0);if(e){this.notify("shape",{prop:"updateShapeColl",onPropertyChange:!1});for(var a=0;a<this.freehandCounter;a++)this.pointColl[a].strokeColor="#fff"}else this.objColl=[],this.pointColl=[],this.shapeColl=[],this.freehandCounter=0;var n=this.frameObj.type;this.frameObj.type="none";var s=this.aspectWidth,l=this.aspectHeight;this.aspectWidth=this.aspectHeight=null;var p=this.cropObj.straighten;this.togglePen=!1,this.notify("toolbar",{prop:"performCropTransformClick",value:{shape:"crop-custom"}});var h=t.extend({},this.img,{},!0),d=t.extend({},this.cropObj,{},!0),c=t.extend({},this.activeObj,{},!0),u=t.extend({},this.transform,{},!0),v=t.extend({},this.panPoint,{},!0);0!==p&&this.setStraighten(0);var g=this.activeObj.activePoint;g.startX=this.img.destLeft,g.startY=this.img.destTop,g.width=this.img.destWidth,g.height=this.img.destHeight,g.endX=g.startX+g.width,g.endY=g.startY+g.height,this.notify("draw",{prop:"updateActiveObject",onPropertyChange:!1,value:{actPoint:g,obj:this.activeObj,isMouseMove:null,x:null,y:null}}),this.noPushUndo=!0,this.crop(),this.noPushUndo=!1,this.isCropTab=!1,this.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),this.notify("crop",{prop:"resetZoom",onPropertyChange:!1}),this.isCropTab=!0;var f=t.extend([],this.afterCropActions,[],!0),C=t.extend([],this.rotateFlipColl,[],!0);this.notify("crop",{prop:"revertTransform",value:{type:"initial",coll:C}});var b=this.getImageData();if(e){var m=this.createElement("canvas"),y=m.getContext("2d");if(m.width=b.width,m.height=b.height,y.fillRect(0,0,m.width,m.height),this.pointColl.length>0){var P={width:0,height:0};this.notify("crop",{prop:"calcRatio",onPropertyChange:!1,value:{obj:P,dimension:{width:m.width,height:m.height}}});var j=P;this.notify("export",{prop:"drawAnnotation",value:{context:y,ratio:j}})}this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),b=y.getImageData(0,0,m.width,m.height)}return this.notify("crop",{prop:"revertTransform",value:{type:"reverse",coll:C}}),this.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),this.afterCropActions=f,e||(this.objColl=o,this.pointColl=i,this.shapeColl=r,this.freehandCounter=this.pointColl.length),this.frameObj.type=n,this.aspectWidth=s,this.aspectHeight=l,this.notify("toolbar",{prop:"performCropTransformClick",value:{shape:"crop-custom"}}),0!==p&&this.setStraighten(p),this.img=h,this.cropObj=d,this.activeObj=c,this.transform=u,this.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:.1,zoomPoint:null,isResize:null}}),this.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:-.1,zoomPoint:null,isResize:null}}),0!==this.transform.degree&&(this.panPoint.currentPannedPoint={x:v.totalPannedClientPoint.x,y:v.totalPannedClientPoint.y},this.notify("transform",{prop:"drawPannedImage",value:{xDiff:v.totalPannedClientPoint.x,yDiff:v.totalPannedClientPoint.y}}),this.panPoint.currentPannedPoint={x:0,y:0},this.notify("transform",{prop:"setTempPanMove",value:{point:null}})),this.noPushUndo=!0,this.crop(),this.noPushUndo=!1,this.transform.straighten=0,this.notify("draw",{prop:"render-image",value:{isMouseWheel:!1}}),b},a.prototype.applyShapes=function(){if(!this.isUndoRedoStack){var e=["rectangle","ellipse","line","arrow","path","text","image"],t={bool:!1};this.notify("selection",{prop:"getFreehandDrawEditing",onPropertyChange:!1,value:{obj:t}}),(t.bool||this.togglePen||this.activeObj.shape&&-1!==e.indexOf(this.activeObj.shape)||this.drawingShape)&&this.okBtn(null,!0)}},a.prototype.closeOverlayTbar=function(){var e=!1,o={bool:null};if(this.notify("toolbar",{prop:"getFrameToolbar",onPropertyChange:!1,value:{obj:o}}),!o.bool&&this.element.querySelector(".e-contextual-toolbar-wrapper")){this.element.querySelector(".e-contextual-toolbar-wrapper").classList.contains("e-hide")||(e=!0);var i={bool:this.isStraightening};(!t.Browser.isDevice||t.Browser.isDevice&&!i.bool)&&this.element.querySelector(".e-contextual-toolbar-wrapper").classList.add("e-hide")}return e},a.prototype.toolbarTemplateFn=function(){var e,t=this.element.id+"_toolbar",o=this.element.querySelector("#"+this.element.id+"_toolbarArea");if(this.toolbarTemplate){if(this.toolbarFn=this.templateParser(this.toolbarTemplate),this.isReact)e=this.toolbarFn({type:"toolbar"},this,"Template",t)[0];else if(this.isAngular){var i=this.toolbarFn({type:"toolbar"},this,"Template",t);e=3===i[0].nodeType?i[1]:i[0]}else e=this.toolbarFn({type:"toolbar"},this,"Template",t)[0];o.appendChild(e),this.toolbarHeight=o.clientHeight,this.notify("toolbar",{prop:"setToolbarHeight",value:{height:this.toolbarHeight}}),this.renderReactTemplates()}},a.prototype.quickAccessToolbarTemplateFn=function(){var e,t=this.element.id+"_quickAccessToolbar",o=this.element.querySelector("#"+this.element.id+"_quickAccessToolbarArea");if(this.quickAccessToolbarTemplate){if(this.qatFn=this.templateParser(this.quickAccessToolbarTemplate),this.isReact)e=this.qatFn({type:"toolbar"},this,"Template",t)[0];else if(this.isAngular){var i=this.qatFn({type:"toolbar"},this,"Template",t);e=3===i[0].nodeType?i[1]:i[0]}else e=this.qatFn({type:"toolbar"},this,"Template",t)[0];o.appendChild(e),this.renderReactTemplates()}},a.prototype.templateParser=function(e){if(e)try{return"function"!=typeof e&&document.querySelectorAll(e).length?t.compile(document.querySelector(e).innerHTML.trim()):t.compile(e)}catch(o){return t.compile(e)}},a.prototype.getTextFromId=function(e){return{1:"none",2:"bar",3:"arrow",4:"arrowSolid",5:"circle",6:"circleSolid",7:"square",8:"squareSolid"}[""+e]},a.prototype.getFinetuneOption=function(t){return{brightness:e.ImageFinetuneOption.Brightness,contrast:e.ImageFinetuneOption.Contrast,hue:e.ImageFinetuneOption.Hue,saturation:e.ImageFinetuneOption.Saturation,opacity:e.ImageFinetuneOption.Opacity,blur:e.ImageFinetuneOption.Blur,exposure:e.ImageFinetuneOption.Exposure}[""+t]},a.prototype.setPenStroke=function(e){this.notify("freehand-draw",{prop:"setPenStrokeWidth",onPropertyChange:!1,value:{value:parseInt(e,10)}})},a.prototype.updateFreehandDrawColorChange=function(){var e={tempFreeHandDrawEditingStyles:null};this.notify("freehand-draw",{prop:"getTempFreeHandDrawEditingStyles",value:{obj:e}}),this.notify("freehand-draw",{prop:"color-change",value:{color:e.tempFreeHandDrawEditingStyles.strokeColor}})},a.prototype.getUndoRedoColl=function(){var e={undoRedoColl:null,index:null},t={undoRedoStep:null},o={appliedUndoRedoColl:[]};return this.notify("undo-redo",{prop:"getAppliedUndoRedoColl",value:{obj:o}}),this.notify("undo-redo",{prop:"getUndoRedoStep",value:{obj:t}}),e.undoRedoColl=o.appliedUndoRedoColl,e.index=t.undoRedoStep,e},a.prototype.updateImageTransformColl=function(e){var o;"rotateleft"===e?o=-90:"rotateright"===e?o=90:"horizontalflip"===e?o="horizontal":"verticalflip"===e&&(o="vertical");for(var i=0;i<this.objColl.length;i++){var r=this.objColl[i].shape;if("image"===r||"text"===r){t.isNullOrUndefined(this.objColl[i].rotateFlipColl)&&(this.objColl[i].rotateFlipColl=[]),this.objColl[i].rotateFlipColl.push(o);var a={collection:this.objColl[i].rotateFlipColl};this.notify("shape",{prop:"alignRotateFlipColl",onPropertyChange:!1,value:{collection:this.objColl[i].rotateFlipColl,isRotateFlipCollection:!1,obj:a}}),this.objColl[i].rotateFlipColl=a.collection}}},a.prototype.setInitialZoomState=function(){this.objColl.push(this.activeObj),this.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1});var e=this.isUndoRedo;this.isCropTab=!1,this.isUndoRedo=!0,this.transform.cropZoomFactor&&this.transform.cropZoomFactor>0?this.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:-this.transform.cropZoomFactor,zoomPoint:null,isResize:!0}}):this.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:Math.abs(this.transform.cropZoomFactor),zoomPoint:null,isResize:!0}}),this.isUndoRedo=e,this.panPoint.totalPannedPoint={x:0,y:0},this.transform.cropZoomFactor=0,this.notify("freehand-draw",{prop:"updateFHDColl",onPropertyChange:!1}),this.activeObj=t.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}})},a.prototype.updateCropTransformItems=function(){this.prevCurrSelectionPoint=t.extend({},this.currSelectionPoint,{},!0),this.notify("draw",{prop:"updateCropSelection",onPropertyChange:!1})},a.prototype.toPascalCase=function(e,o){var i=[];t.isNullOrUndefined(e)||(i=e.toLowerCase().split("-"));for(var r=0;r<i.length;r++)i[r]=i[r].charAt(0).toUpperCase()+i[r].slice(1);return o&&(o.maxText=i.join("")),i.join("")},a.prototype.getFontSizes=function(){var e=[];this.fontSizeColl=[];var t;t=0===this.transform.degree||this.transform.degree%180==0?this.img.destWidth/25:this.img.destHeight/25;for(var o=1;o<=10;o++)this.fontSizeColl.push({text:(o*Math.round(t/2)).toString()}),e.push({text:o.toString()});return e},a.prototype.okBtn=function(o,i){if(i){this.noPushUndo=!1;var r={activePoint:{startX:0,startY:0,endX:0,endY:0,width:0,height:0},flipObjColl:[],triangle:[],triangleRatio:[],order:null};this.notify("selection",{prop:"setTempActObj",onPropertyChange:!1,value:{obj:r}})}var a=this.element.querySelector(".e-contextual-toolbar-wrapper");a&&a.classList.remove("e-frame-wrapper");var n,s=!1;this.isResizeOkBtn=!0;var l=this.element.querySelector("#"+this.element.id+"_aspectratio"),p=this.element.querySelector("#"+this.element.id+"_nonaspectratio"),h=this.element.querySelector(".e-ie-toolbar-aspect-ratio-btn"),d=this.element.querySelector(".e-ie-toolbar-nonaspect-ratio-btn");if(void 0!==this.activeObj.shape&&(n=this.activeObj.shape.split("-")),void 0===n&&this.currObjType.isCustomCrop?s=!0:void 0!==n&&"crop"===n[0]&&(s=!0),this.allowDownScale=!0,(this.activeObj.shape&&"image"!==this.activeObj.shape||this.togglePen)&&!s){var c={shapeSettingsObj:{}};this.notify("selection",{prop:"updatePrevShapeSettings",onPropertyChange:!1,value:{obj:c}});var u=c.shapeSettingsObj;this.togglePen&&(u.type=e.ShapeType.FreehandDraw);var v={action:"apply",currentShapeSettings:t.extend({},u,{},!0)};this.currObjType.isRedact||!i&&!this.isShapeDrawing||(this.isShapeDrawing&&(v.action="draw-end"),this.trigger("shapeChange",v)),this.editCompleteArgs=v,this.currObjType.isRedact&&(this.currObjType.isRedact=!1)}if(l||p){var g={width:null,height:null};this.notify("selection",{prop:"getNumTextValue",onPropertyChange:!1,value:{obj:g}});var f={x:g.width,y:g.height},C={prevCropObj:this.prevCropObj},b={prevObj:this.prevObj};if(f&&f.x&&f.y&&C.prevCropObj&&b.prevObj){p||d&&!d.classList.contains("e-hidden")?this.notify("transform",{prop:"resize",value:{width:f.x,height:f.y,isAspectRatio:!1}}):(l||h&&!h.classList.contains("e-hidden"))&&this.notify("transform",{prop:"resize",value:{width:f.x,height:null,isAspectRatio:!0}}),this.isResize=!1,this.aspectWidth=f.x,this.aspectHeight=f.y,this.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"main",isApplyBtn:!1,isCropping:!1,isZooming:null,cType:null}}),this.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:-this.transform.zoomFactor,zoomPoint:null,isResize:!0}}),this.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:b.prevObj.defaultZoom,zoomPoint:null,isResize:!0}}),b.prevObj.zoomFactor&&this.setProperties({zoomSettings:{zoomFactor:b.prevObj.zoomFactor}},!0),this.notify("transform",{prop:"setPreviousZoomValue",onPropertyChange:!1,value:{previousZoomValue:this.zoomSettings.zoomFactor}}),this.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"resize",previousObj:b.prevObj,previousObjColl:b.prevObj.objColl,previousPointColl:b.prevObj.pointColl,previousSelPointColl:b.prevObj.selPointColl,previousCropObj:C.prevCropObj,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),this.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"ok"}});var m=this.cancelCropSelection;!m||!t.isNullOrUndefined(p)&&p||(m.previousObj.aspectWidth=m.currentObj.aspectWidth=this.aspectWidth,m.previousObj.aspectHeight=m.currentObj.aspectHeight=this.aspectHeight,m.previousCropObj=t.extend({},this.cropObj,{},!0),m.currentCropObj=t.extend({},this.cropObj,{},!0),this.notify("draw",{prop:"updateCropSelObj"})),this.cancelCropSelection=null}else!f||0!==f.x&&0!==f.y?this.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"main",isApplyBtn:!1,isCropping:!1,isZooming:null,cType:null}}):this.notify("draw",{prop:"performCancel",value:{isContextualToolbar:null}});this.isAspectRatio=!1}var y=this.element.querySelector(".e-contextual-toolbar-wrapper .e-toolbar-item.e-selected"),P={bool:!1};this.notify("selection",{prop:"getFreehandDrawEditing",onPropertyChange:!1,value:{obj:P}});var j={bool:null};this.notify("toolbar",{prop:"getFrameToolbar",onPropertyChange:!1,value:{obj:j}});var x=document.querySelector("#"+this.element.id+"_sliderWrapper");if(y&&(this.currentFilter=y.children[0].children[0].id.replace("Canvas","")),s){if(0!==this.transform.straighten&&(0!==this.panPoint.totalPannedPoint.x||0!==this.panPoint.totalPannedPoint.y||0!==this.panPoint.totalPannedClientPoint.x||0!==this.panPoint.totalPannedClientPoint.y)){var w=this.prevStraightenedDegree;this.prevStraightenedDegree=this.transform.straighten,this.setStraighten(this.transform.straighten-3),this.setStraighten(this.transform.straighten+3),this.prevStraightenedDegree=w}this.isCroppedEvent=this.crop()}else if(this.togglePen){if(this.freeHandDraw(!1),!this.isMaskImage){var O={penStrokeWidth:null};this.notify("freehand-draw",{prop:"getPenStrokeWidth",onPropertyChange:!1,value:{obj:O}}),this.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"ok"}}),this.notify("freehand-draw",{prop:"setPenStrokeWidth",onPropertyChange:!1,value:{value:O.penStrokeWidth}})}this.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.lowerContext}}),this.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.upperContext}})}else if("block"===this.textArea.style.display||"inline-block"===this.textArea.style.display)this.notify("shape",{prop:"redrawActObj",onPropertyChange:!1,value:{x:null,y:null,isMouseDown:null}}),this.lowerContext.clearRect(0,0,this.lowerCanvas.width,this.lowerCanvas.height),this.notify("draw",{prop:"redrawImgWithObj",onPropertyChange:!1}),t.isNullOrUndefined(o)&&this.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"ok"}}),this.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.lowerContext}}),this.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.upperContext}});else if(!x&&!this.currObjType.isFiltered||this.drawingShape||"redact"===this.activeObj.shape)if(P.bool)this.notify("freehand-draw",{prop:"applyFhd",onPropertyChange:!1}),this.notify("selection",{prop:"setFreehandDrawCustomized",value:{isFreehandDrawCustomized:!1}}),this.notify("toolbar",{prop:"destroy-qa-toolbar"}),this.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"ok"}}),this.notify("freehand-draw",{prop:"resetFreehandDrawSelectedId",onPropertyChange:!1});else if(0!==this.activeObj.activePoint.width||0!==this.activeObj.activePoint.height||"path"===this.activeObj.shape&&this.activeObj.pointColl.length>0)"image"===this.activeObj.shape&&this.notify("draw",{prop:"setImageApply",onPropertyChange:!1,value:{bool:!0}}),this.notify("shape",{prop:"applyActObj",onPropertyChange:!1,value:{isMouseDown:null}});else{if(JSON.stringify(this.frameObj)!==JSON.stringify(this.tempFrameObj)){var S={currObj:{}};this.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:S}}),this.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"frame",previousObj:S.currObj,previousObjColl:S.currObj.objColl,previousPointColl:S.currObj.pointColl,previousSelPointColl:S.currObj.selPointColl,previousCropObj:t.extend({},this.cropObj,{},!0),previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),this.notify("draw",{prop:"render-image",value:{isMouseWheel:null,isPreventClearRect:null,isFrame:!0}});var T={type:this.toPascalCase(this.frameObj.type),color:this.frameObj.color,gradientColor:this.frameObj.gradientColor,size:this.frameObj.size,inset:this.frameObj.inset,offset:this.frameObj.offset,borderRadius:this.frameObj.radius,frameLineStyle:this.toPascalCase(this.frameObj.border),lineCount:this.frameObj.amount},k={cancel:!1,previousFrameSetting:{type:this.toPascalCase(this.tempFrameObj.type),color:this.tempFrameObj.color,gradientColor:this.tempFrameObj.gradientColor,size:this.tempFrameObj.size,inset:this.tempFrameObj.inset,offset:this.tempFrameObj.offset,borderRadius:this.tempFrameObj.radius,frameLineStyle:this.toPascalCase(this.tempFrameObj.border),lineCount:this.tempFrameObj.amount},currentFrameSetting:T};this.editCompleteArgs=k,this.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"ok"}}),this.tempFrameObj=t.extend({},this.frameObj,{},!0)}this.notify("draw",{prop:"resetFrameZoom",onPropertyChange:!1,value:{isOk:!0}})}else{this.initialAdjustmentValue=this.canvasFilter=this.lowerContext.filter,this.currObjType.isFiltered=!1;var F={value:null};this.notify("draw",{prop:"getTempAdjustmentValue",value:{obj:F}}),x&&"Opacity"===x.parentElement.previousElementSibling.textContent||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:null}})}P.isCropToolbar||(this.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"main",isApplyBtn:!1,isCropping:null,isZooming:null,cType:null}}),this.currObjType.isRedact=!1),this.notify("draw",{prop:"setNewPath",value:{bool:!1}}),this.transform.zoomFactor=this.transform.defaultZoomFactor,this.notify("selection",{prop:"setCurrentDrawingShape",onPropertyChange:!1,value:{value:""}}),this.isResizeOkBtn=!1,this.notify("draw",{prop:"redrawDownScale"}),this.isChangesSaved=this.isFinetuneBtnClick=!1,i&&(this.drawingShape=null,this.notify("draw",{prop:"resetTempObjColl"}),this.notify("draw",{prop:"resetTempPointColl"}))},a.prototype.triggerEditCompleteEvent=function(e){"shape-insert"===e.action&&e.actionEventArgs&&e.actionEventArgs.currentShapeSettings&&"Redact"===e.actionEventArgs.currentShapeSettings.type.toString()&&(e.action="redact"),this.trigger("editComplete",e),this.editCompleteArgs=null},a.prototype.getObjFromId=function(e){var o;if(this.activeObj.currIndex&&this.activeObj.currIndex===e)o=t.extend({},this.activeObj,{},!0);else for(var i=0;i<this.shapeColl.length;i++)if((this.shapeColl[i].id?this.shapeColl[i].id:this.shapeColl[i].currIndex)===e){o=t.extend({},this.shapeColl[i],{},!0);break}return o},a.prototype.setTempFilterProperties=function(){this.upperCanvas.style.display="block",this.cropSelectedState();var e={adjustmentLevel:null};this.notify("filter",{prop:"getAdjustmentLevel",onPropertyChange:!1,value:{obj:e}}),this.lowerContext.filter=this.initialAdjustmentValue,this.notify("draw",{prop:"setTempAdjustmentValue",value:{tempAdjustmentValue:this.lowerContext.filter}}),this.notify("filter",{prop:"setTempAdjustmentLevel",onPropertyChange:!1,value:{tempAdjustmentLevel:t.extend({},e.adjustmentLevel,{},!0)}}),this.notify("draw",{prop:"setTempFilter",value:{tempFilter:this.currentFilter}});var o={undoRedoStep:null};this.notify("undo-redo",{prop:"getUndoRedoStep",value:{obj:o}}),this.notify("draw",{prop:"setTempUndoRedoStep",value:{tempUndoRedoStep:o.undoRedoStep}})},a.prototype.cropSelectedState=function(){this.activeObj.shape&&"crop"===this.activeObj.shape.split("-")[0]&&this.okBtn()},a.prototype.getCurrentCanvasData=function(){var e=t.extend({},this.frameObj,{},!0);this.frameObj={type:"none",color:"#fff",size:20,inset:20,offset:20,radius:0,amount:1,border:"solid",gradientColor:""};var o=this.lowerContext.filter;this.lowerContext.filter=this.canvasFilter="none";var i=t.extend([],this.objColl,null,!0),r=t.extend([],this.pointColl,null,!0);this.objColl=[],this.pointColl=[],this.freehandCounter=0,this.notify("draw",{prop:"render-image",value:{isMouseWheel:!1}});var a=this.element.querySelector(".e-contextual-toolbar-wrapper");a&&a.classList.add("e-hide");var n=this.getImageData();return a&&a.classList.remove("e-hide"),t.Browser.isDevice||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.pointColl=r,this.freehandCounter=r.length,this.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"iterate",pen:"iterate",isPreventApply:null}}),this.lowerContext.filter=this.canvasFilter=o,this.frameObj=e,n},a.prototype.setCurrAdjustmentValue=function(e,t){var o={finetune:this.getFinetuneOption(e),value:t,cancel:!1};this.trigger("finetuneValueChanging",o),this.editCompleteArgs=o,o.cancel||this.notify("filter",{prop:"setCurrAdjValue",value:{type:e.toLowerCase(),value:t}})},a.prototype.getSquarePointForPath=function(e){var t={startX:0,startY:0,endX:0,endY:0,width:0,height:0};if(e.pointColl.length>0){t={startX:e.pointColl[0].x,startY:e.pointColl[0].y,endX:e.pointColl[0].x,endY:e.pointColl[0].y};for(var o=1;o<e.pointColl.length;o++)e.pointColl[o].x<t.startX&&(t.startX=e.pointColl[o].x),e.pointColl[o].y<t.startY&&(t.startY=e.pointColl[o].y),e.pointColl[o].x>t.endX&&(t.endX=e.pointColl[o].x),e.pointColl[o].y>t.endY&&(t.endY=e.pointColl[o].y);t.width=t.endX-t.startX,t.height=t.endY-t.startY}return t},a.prototype.getSelectionType=function(e){var t={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","Crop2:3":"2:3","Crop3:4":"3:4","Crop4:5":"4:5","Crop5:7":"5:7","Crop9:16":"9:16"};return t[""+(e="crop-custom"===e?"CropCustom":e)]?t[""+e]:e.split("Crop")[1]},a.prototype.clearContext=function(e){e.clearRect(0,0,e.canvas.width,e.canvas.height),e.clearRect(0,0,e.canvas.height,e.canvas.width)},a.prototype.updateArrow=function(e,o){var i=!1,r=this.objColl.length;this.notify("shape",{prop:"pushActItemIntoObj"}),r!==this.objColl.length&&(i=!0);var a=t.extend({},this.cropObj,{},!0),n={currObj:{}},s={shapeSettingsObj:{}};this.notify("selection",{prop:"updatePrevShapeSettings",onPropertyChange:!1,value:{obj:s}});var l=s.shapeSettingsObj;this.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:n}});var p=n.currObj;p.objColl=t.extend([],this.objColl,[],!0),p.pointColl=t.extend([],this.pointColl,[],!0),p.afterCropActions=t.extend([],this.afterCropActions,[],!0),i&&this.objColl.pop(),"startArrow"===e?this.activeObj.start=this.getTextFromId(o):"endArrow"===e&&(this.activeObj.end=this.getTextFromId(o)),this.notify("shape",{prop:"setStrokeSettings",value:{strokeSettings:null,strokeColor:null,fillColor:null,strokeWidth:this.activeObj.strokeSettings.strokeWidth}}),this.objColl.push(this.activeObj),0===this.activeObj.activePoint.width&&0===this.activeObj.activePoint.height||this.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"shapeTransform",previousObj:p,previousObjColl:p.objColl,previousPointColl:p.pointColl,previousCropObj:a,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),this.notify("selection",{prop:"redrawShape",value:{obj:this.objColl[this.objColl.length-1]}}),t.Browser.isDevice?document.getElementById(this.element.id+"_bottomToolbar")&&t.getComponent(this.element.id+"_bottomToolbar","toolbar").refreshOverflow():document.getElementById(this.element.id+"_toolbar")&&t.getComponent(this.element.id+"_toolbar","toolbar").refreshOverflow();var h={action:e,currentShapeSettings:t.extend({},l,{},!0)};this.trigger("shapeChange",h),this.editCompleteArgs=h},a.prototype.updateFontFamily=function(e){this.notify("selection",{prop:"setInitialTextEdit",value:{bool:!1}});var o=!1,i=this.objColl.length;this.notify("shape",{prop:"pushActItemIntoObj"}),i!==this.objColl.length&&(o=!0);var r=t.extend([],this.objColl,[],!0),a=t.extend({},this.cropObj,{},!0),n={shapeSettingsObj:{}};this.notify("selection",{prop:"updatePrevShapeSettings",onPropertyChange:!1,value:{obj:n}});var s=n.shapeSettingsObj,l={currObj:{}};this.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:l}});var p=l.currObj;p.objColl=t.extend([],this.objColl,[],!0),p.pointColl=t.extend([],this.pointColl,[],!0),p.afterCropActions=t.extend([],this.afterCropActions,[],!0);var h={selPointColl:null};if(this.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:h}}),p.selPointColl=t.extend([],h.selPointColl,[],!0),o&&this.objColl.pop(),"block"===this.textArea.style.display||"inline-block"===this.textArea.style.display){this.notify("shape",{prop:"updateFontRatio",onPropertyChange:!1,value:{obj:this.activeObj,isTextArea:!0}});var d=this.activeObj.textSettings.fontFamily;this.activeObj.textSettings.fontFamily=this.toPascalCase(e),0===this.activeObj.activePoint.width&&0===this.activeObj.activePoint.height||this.notify("shape",{prop:"redraw-text"}),this.objColl.push(this.activeObj),0===this.activeObj.activePoint.width&&0===this.activeObj.activePoint.height||this.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"textAreaCustomization",previousObj:p,previousObjColl:p.objColl,previousPointColl:p.pointColl,previousSelPointColl:p.selPointColl,previousCropObj:a,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),this.objColl.pop(),this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height);var c=this.activeObj.activePoint.width+.25*this.activeObj.textSettings.fontSize;this.textArea.style.width=c+"px",this.textArea.style.fontFamily=this.toPascalCase(e),this.activeObj.textSettings.fontFamily=d,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 u=this.activeObj.textSettings.fontFamily=this.toPascalCase(e);this.notify("shape",{prop:"setTextSettings",onPropertyChange:!1,value:{textSettings:null,fontFamily:u,fontSize:null}}),0===this.activeObj.activePoint.width&&0===this.activeObj.activePoint.height||this.notify("shape",{prop:"redraw-text"}),this.objColl.push(this.activeObj),0===this.activeObj.activePoint.width&&0===this.activeObj.activePoint.height||this.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"shapeTransform",previousObj:p,previousObjColl:r,previousPointColl:t.extend([],this.pointColl,[],!0),previousSelPointColl:p.selPointColl,previousCropObj:a,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),this.notify("selection",{prop:"redrawShape",value:{obj:this.objColl[this.objColl.length-1]}})}var v={action:"font-family",currentShapeSettings:t.extend({},s,{},!0)};v.currentShapeSettings.fontFamily=this.textArea.style.fontFamily,this.trigger("shapeChange",v),this.editCompleteArgs=v},a.prototype.updateFontSize=function(e){var o=e;this.notify("selection",{prop:"setInitialTextEdit",value:{bool:!1}});var i=!1,r=this.objColl.length;this.notify("shape",{prop:"pushActItemIntoObj"}),r!==this.objColl.length&&(i=!0);var a=t.extend({},this.cropObj,{},!0),n={shapeSettingsObj:{}};this.notify("selection",{prop:"updatePrevShapeSettings",onPropertyChange:!1,value:{obj:n}});var s=n.shapeSettingsObj,l={currObj:{}};this.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:l}});var p=l.currObj;p.objColl=t.extend([],this.objColl,[],!0),p.pointColl=t.extend([],this.pointColl,[],!0),p.afterCropActions=t.extend([],this.afterCropActions,[],!0);var h={selPointColl:null};if(this.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:h}}),p.selPointColl=t.extend([],h.selPointColl,[],!0),i&&this.objColl.pop(),"block"===this.textArea.style.display||"inline-block"===this.textArea.style.display){this.notify("shape",{prop:"updateFontRatio",onPropertyChange:!1,value:{obj:this.activeObj,isTextArea:!0}});var d=this.activeObj.textSettings.fontSize;this.activeObj.textSettings.fontSize=parseInt(this.fontSizeColl[parseInt(o,10)-1].text,10),this.objColl.push(this.activeObj),0===this.activeObj.activePoint.width&&0===this.activeObj.activePoint.height||this.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"textAreaCustomization",previousObj:p,previousObjColl:p.objColl,previousPointColl:p.pointColl,previousSelPointColl:p.selPointColl,previousCropObj:a,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),this.objColl.pop();var c="";"bold"===this.textArea.style.fontWeight&&(c="bold "),"italic"===this.textArea.style.fontStyle&&(c="italic "),"bold"===this.textArea.style.fontWeight&&"italic"===this.textArea.style.fontStyle&&(c="italic bold "),this.upperContext.font=c+this.activeObj.textSettings.fontSize+"px "+this.textArea.style.fontFamily;var u=this.textArea.value.split("\n"),v={maxText:""};this.notify("shape",{prop:"getMaxText",onPropertyChange:!1,value:{isTextBox:!0,text:null,obj:v}});var g=v.maxText,f=this.upperContext.measureText(g).width+.5*this.activeObj.textSettings.fontSize;this.textArea.style.width=f+"px",this.textArea.style.height=u.length*(this.activeObj.textSettings.fontSize+.25*this.activeObj.textSettings.fontSize)+"px",this.activeObj.textSettings.fontSize=d,this.upperContext.font=this.activeObj.textSettings.fontSize+"px "+this.activeObj.textSettings.fontFamily,this.textArea.style.fontSize=parseInt(this.fontSizeColl[parseInt(o,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 C=this.activeObj.textSettings.fontSize=parseInt(this.fontSizeColl[parseInt(o,10)-1].text,10);this.notify("shape",{prop:"setTextSettings",onPropertyChange:!1,value:{textSettings:null,fontFamily:null,fontSize:C}}),this.upperContext.font=this.activeObj.textSettings.fontSize+"px "+this.activeObj.textSettings.fontFamily;var u=this.activeObj.keyHistory.split("\n"),v={maxText:""};this.notify("shape",{prop:"getMaxText",onPropertyChange:!1,value:{isTextBox:null,text:null,obj:v}});var b=v.maxText,f=this.upperContext.measureText(b).width+.5*this.activeObj.textSettings.fontSize,m=u.length*(this.activeObj.textSettings.fontSize+.25*this.activeObj.textSettings.fontSize);0===this.activeObj.activePoint.width&&0===this.activeObj.activePoint.height||(this.notify("selection",{prop:"setTextSelection",onPropertyChange:!1,value:{width:f,height:m}}),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),0===this.activeObj.activePoint.width&&0===this.activeObj.activePoint.height||this.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"shapeTransform",previousObj:p,previousObjColl:p.objColl,previousPointColl:p.pointColl,previousSelPointColl:p.selPointColl,previousCropObj:a,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),this.notify("selection",{prop:"redrawShape",value:{obj:this.objColl[this.objColl.length-1]}})}var y={action:"font-size",currentShapeSettings:t.extend({},s,{},!0)};y.currentShapeSettings.fontSize=this.activeObj.textSettings.fontSize,this.trigger("shapeChange",y),this.editCompleteArgs=y},a.prototype.updateFontColor=function(e,o){this.notify("selection",{prop:"setInitialTextEdit",value:{bool:!1}});var i=!1,r=this.objColl.length;this.notify("shape",{prop:"pushActItemIntoObj"}),r!==this.objColl.length&&(i=!0);var a=t.extend({},this.cropObj,{},!0),n={shapeSettingsObj:{}};this.notify("selection",{prop:"updatePrevShapeSettings",onPropertyChange:!1,value:{obj:n}});var s=n.shapeSettingsObj,l={currObj:{}};this.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:l}});var p=l.currObj;p.objColl=t.extend([],this.objColl,[],!0),p.pointColl=t.extend([],this.pointColl,[],!0),p.afterCropActions=t.extend([],this.afterCropActions,[],!0);var h={selPointColl:null};if(this.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:h}}),p.selPointColl=t.extend([],h.selPointColl,[],!0),i&&this.objColl.pop(),"none"===this.textArea.style.display)"Text"===o?(this.activeObj.strokeSettings.strokeColor=e,this.notify("shape",{prop:"setStrokeSettings",value:{strokeSettings:null,strokeColor:this.activeObj.strokeSettings.strokeColor,fillColor:null,strokeWidth:null}})):(this.activeObj.strokeSettings.fillColor=e,this.notify("shape",{prop:"setStrokeSettings",value:{strokeSettings:null,strokeColor:null,fillColor:this.activeObj.strokeSettings.fillColor,strokeWidth:null}})),this.togglePen||0===this.activeObj.activePoint.width&&0===this.activeObj.activePoint.height||(this.objColl.push(this.activeObj),this.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"shapeTransform",previousObj:p,previousObjColl:p.objColl,previousPointColl:p.pointColl,previousSelPointColl:p.selPointColl,previousCropObj:a,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||"inline-block"===this.textArea.style.display){this.textArea.style["Text"===o?"color":"backgroundColor"]=e;var d="Text"===o?this.activeObj.strokeSettings.strokeColor:this.activeObj.strokeSettings.fillColor;this.activeObj.strokeSettings["Text"===o?"strokeColor":"fillColor"]=e,0===this.activeObj.activePoint.width&&0===this.activeObj.activePoint.height||(this.objColl.push(this.activeObj),this.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"textAreaCustomization",previousObj:p,previousObjColl:p.objColl,previousPointColl:p.pointColl,previousSelPointColl:p.selPointColl,previousCropObj:a,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),this.objColl.pop()),this.activeObj.strokeSettings["Text"===o?"strokeColor":"fillColor"]=d}else this.togglePen||0===this.activeObj.activePoint.width&&0===this.activeObj.activePoint.height||(this.objColl.push(this.activeObj),this.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"shapeTransform",previousObj:p,previousObjColl:p.objColl,previousPointColl:p.pointColl,previousSelPointColl:p.selPointColl,previousCropObj:a,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),this.notify("selection",{prop:"redrawShape",value:{obj:this.objColl[this.objColl.length-1]}}));var c={action:"font-color",currentShapeSettings:t.extend({},s,{},!0)};c.currentShapeSettings.fillColor=e,this.trigger("shapeChange",c),this.editCompleteArgs=c},a.prototype.updateStrokeTextColor=function(e){this.notify("selection",{prop:"setInitialTextEdit",value:{bool:!1}});var o=!1,i=this.objColl.length;this.notify("shape",{prop:"pushActItemIntoObj"}),i!==this.objColl.length&&(o=!0);var r=t.extend({},this.cropObj,{},!0),a={shapeSettingsObj:{}};this.notify("selection",{prop:"updatePrevShapeSettings",onPropertyChange:!1,value:{obj:a}});var n=a.shapeSettingsObj,s={currObj:{}};this.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:s}});var l=s.currObj;l.objColl=t.extend([],this.objColl,[],!0),l.pointColl=t.extend([],this.pointColl,[],!0),l.afterCropActions=t.extend([],this.afterCropActions,[],!0);var p={selPointColl:null};if(this.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:p}}),l.selPointColl=t.extend([],p.selPointColl,[],!0),o&&this.objColl.pop(),"none"===this.textArea.style.display)this.activeObj.strokeSettings.outlineColor=e,this.notify("shape",{prop:"setStrokeSettings",value:{strokeSettings:null,strokeColor:null,fillColor:null,strokeWidth:null,outlineColor:this.activeObj.strokeSettings.outlineColor}}),this.togglePen||0===this.activeObj.activePoint.width&&0===this.activeObj.activePoint.height||(this.objColl.push(this.activeObj),this.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"shapeTransform",previousObj:l,previousObjColl:l.objColl,previousPointColl:l.pointColl,previousSelPointColl:l.selPointColl,previousCropObj:r,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||"inline-block"===this.textArea.style.display){this.textArea.style.textShadow="-1px -1px 0 "+e+", 1px -1px 0 "+e+", -1px 1px 0 "+e+", 1px 1px 0 "+e;var h=this.activeObj.strokeSettings.outlineColor;this.activeObj.strokeSettings.outlineColor=e,0===this.activeObj.activePoint.width&&0===this.activeObj.activePoint.height||(this.objColl.push(this.activeObj),this.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"textAreaCustomization",previousObj:l,previousObjColl:l.objColl,previousPointColl:l.pointColl,previousSelPointColl:l.selPointColl,previousCropObj:r,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),this.objColl.pop()),this.activeObj.strokeSettings.outlineColor=h}else this.togglePen||0===this.activeObj.activePoint.width&&0===this.activeObj.activePoint.height||(this.objColl.push(this.activeObj),this.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"shapeTransform",previousObj:l,previousObjColl:l.objColl,previousPointColl:l.pointColl,previousSelPointColl:l.selPointColl,previousCropObj:r,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),this.notify("selection",{prop:"redrawShape",value:{obj:this.objColl[this.objColl.length-1]}}));var d={action:"font-color",currentShapeSettings:t.extend({},n,{},!0)};d.currentShapeSettings.fillColor=e,this.trigger("shapeChange",d),this.editCompleteArgs=d},a.prototype.updatePenStrokeWidth=function(o){var i=t.extend([],this.pointColl,[],!0);this.updateFreehandDrawColorChange();var r=t.extend({},this.cropObj,{},!0),a={shapeSettingsObj:{}};this.notify("selection",{prop:"updatePrevShapeSettings",onPropertyChange:!1,value:{obj:a}});var n=a.shapeSettingsObj,s={currObj:{}};this.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:s}});var l=s.currObj;l.objColl=t.extend([],this.objColl,[],!0),l.pointColl=t.extend([],this.pointColl,[],!0),l.afterCropActions=t.extend([],this.afterCropActions,[],!0);var p={selPointColl:null};this.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:p}}),l.selPointColl=t.extend([],p.selPointColl,[],!0),this.pointColl=i,this.notify("selection",{prop:"setFreehandDrawCustomized",value:{isFreehandDrawCustomized:!0}}),this.setPenStroke(o);var h={bool:!1};if(this.notify("selection",{prop:"getFreehandDrawEditing",onPropertyChange:!1,value:{obj:h}}),h.bool){var d={penStrokeWidth:null};this.notify("freehand-draw",{prop:"getPenStrokeWidth",onPropertyChange:!1,value:{obj:d}}),this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),this.lowerContext.clearRect(0,0,this.lowerCanvas.width,this.lowerCanvas.height),this.notify("freehand-draw",{prop:"hoverFhd",onPropertyChange:!1,value:{strokeColor:null,strokeWidth:d.penStrokeWidth}});var c={freehandSelectedIndex:null};this.notify("freehand-draw",{prop:"getFreehandSelectedIndex",onPropertyChange:!1,value:{obj:c}}),this.pointColl[c.freehandSelectedIndex].strokeWidth=d.penStrokeWidth,this.notify("draw",{prop:"render-image",value:{isMouseWheel:null}}),this.notify("draw",{prop:"redrawDownScale"}),this.notify("freehand-draw",{prop:"hoverFhd",onPropertyChange:!1,value:{strokeColor:null,strokeWidth:d.penStrokeWidth}}),this.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"freehanddrawCustomized",previousObj:l,previousObjColl:l.objColl,previousPointColl:l.pointColl,previousSelPointColl:l.selPointColl,previousCropObj:r,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}})}n.type=e.ShapeType.FreehandDraw;var u={action:"stroke-width",currentShapeSettings:t.extend({},n,{},!0)};u.currentShapeSettings.strokeWidth=this.activeObj.strokeSettings.strokeWidth,this.trigger("shapeChange",u),this.editCompleteArgs=u},a.prototype.updatePenStrokeColor=function(o){var i=t.extend([],this.pointColl,[],!0);this.updateFreehandDrawColorChange();var r=t.extend({},this.cropObj,{},!0),a={shapeSettingsObj:{}};this.notify("selection",{prop:"updatePrevShapeSettings",onPropertyChange:!1,value:{obj:a}});var n=a.shapeSettingsObj,s={currObj:{}};this.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:s}});var l=s.currObj;l.objColl=t.extend([],this.objColl,[],!0),l.pointColl=t.extend([],this.pointColl,[],!0),l.afterCropActions=t.extend([],this.afterCropActions,[],!0);var p={selPointColl:null};this.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:p}}),l.selPointColl=t.extend([],p.selPointColl,[],!0),this.pointColl=i,this.notify("selection",{prop:"setFreehandDrawCustomized",value:{isFreehandDrawCustomized:!0}}),this.activeObj.strokeSettings.strokeColor=o;var h={freehandSelectedIndex:null};this.notify("freehand-draw",{prop:"getFreehandSelectedIndex",onPropertyChange:!1,value:{obj:h}}),null!==h.freehandSelectedIndex&&void 0!==h.freehandSelectedIndex&&(this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),this.notify("draw",{prop:"render-image",value:{isMouseWheel:null}}),this.notify("draw",{prop:"redrawDownScale"}),this.notify("freehand-draw",{prop:"hoverFhd",onPropertyChange:!1,value:{strokeColor:null,strokeWidth:null}}));var d={bool:!1};if(this.notify("selection",{prop:"getFreehandDrawEditing",onPropertyChange:!1,value:{obj:d}}),d.bool){var c={freehandSelectedIndex:null};this.notify("freehand-draw",{prop:"getFreehandSelectedIndex",onPropertyChange:!1,value:{obj:c}}),this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),this.pointColl[c.freehandSelectedIndex].strokeColor=o,this.notify("freehand-draw",{prop:"hoverFhd",onPropertyChange:!1,value:{strokeColor:o}}),this.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"freehanddrawCustomized",previousObj:l,previousObjColl:l.objColl,previousPointColl:l.pointColl,previousSelPointColl:l.selPointColl,previousCropObj:r,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}})}else this.togglePen||this.notify("selection",{prop:"redrawShape",value:{obj:this.activeObj}});n.type=e.ShapeType.FreehandDraw;var u={action:"stroke-color",currentShapeSettings:t.extend({},n,{},!0)};u.currentShapeSettings.strokeColor=o,this.trigger("shapeChange",u),this.editCompleteArgs=u},a.prototype.updateStrokeWidth=function(e,o,i){if(this.activeObj.shape&&("path"!==this.activeObj.shape||"path"===this.activeObj.shape&&this.activeObj.pointColl.length>0)){var r={shapeSettingsObj:{}};this.notify("selection",{prop:"updatePrevShapeSettings",onPropertyChange:!1,value:{obj:r}});var a=r.shapeSettingsObj,n=!1,s=this.objColl.length;this.notify("shape",{prop:"pushActItemIntoObj"}),s!==this.objColl.length&&(n=!0);var l=t.extend({},this.cropObj,{},!0),p={currObj:{}};this.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:p}});var h=p.currObj;h.objColl=t.extend([],this.objColl,[],!0),h.pointColl=t.extend([],this.pointColl,[],!0),h.afterCropActions=t.extend([],this.afterCropActions,[],!0);var d={selPointColl:null};this.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:d}}),h.selPointColl=t.extend([],d.selPointColl,[],!0),n&&this.objColl.pop(),this.activeObj.strokeSettings["width"===o?"text"===i?"outlineWidth":"strokeWidth":"radius"]=parseInt(e,10),"rectangle"!==this.activeObj.shape&&"ellipse"!==this.activeObj.shape||(this.activeObj.strokeSettings["width"===o?"text"===i?"outlineWidth":"strokeWidth":"radius"]=parseInt(e,10)-1),this.activeObj.strokeSettings["width"===o?"text"===i?"outlineWidth":"strokeWidth":"radius"]*=2,"width"===o?"text"===i?this.notify("shape",{prop:"setStrokeSettings",value:{strokeSettings:null,strokeColor:null,fillColor:null,strokeWidth:null,radius:null,outlineWidth:this.activeObj.strokeSettings.outlineWidth}}):this.notify("shape",{prop:"setStrokeSettings",value:{strokeSettings:null,strokeColor:null,fillColor:null,strokeWidth:this.activeObj.strokeSettings.strokeWidth,radius:null,outlineWidth:null}}):this.notify("shape",{prop:"setStrokeSettings",value:{strokeSettings:null,strokeColor:null,fillColor:null,strokeWidth:null,radius:this.activeObj.strokeSettings.radius}}),this.objColl.push(this.activeObj),0===this.activeObj.activePoint.width&&0===this.activeObj.activePoint.height||this.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"shapeTransform",previousObj:h,previousObjColl:h.objColl,previousPointColl:h.pointColl,previousSelPointColl:h.selPointColl,previousCropObj:l,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),this.notify("selection",{prop:"redrawShape",value:{obj:this.objColl[this.objColl.length-1]}});var c={action:"stroke-width",currentShapeSettings:t.extend({},a,{},!0)};c.currentShapeSettings["width"===o?"text"===i?"outlineWidth":"strokeWidth":"radius"]=this.activeObj.strokeSettings["width"===o?"text"===i?"outlineWidth":"strokeWidth":"radius"],this.trigger("shapeChange",c),this.editCompleteArgs=c}else this.activeObj.shape&&"path"===this.activeObj.shape&&0===this.activeObj.pointColl.length&&(this.activeObj.strokeSettings.strokeWidth=parseInt(e,10),this.activeObj.strokeSettings.strokeWidth*=2,"width"===o?"text"===i?this.notify("shape",{prop:"setStrokeSettings",value:{strokeSettings:null,strokeColor:null,fillColor:null,strokeWidth:null,radius:null,outlineWidth:this.activeObj.strokeSettings.outlineWidth}}):this.notify("shape",{prop:"setStrokeSettings",value:{strokeSettings:null,strokeColor:null,fillColor:null,strokeWidth:this.activeObj.strokeSettings.strokeWidth,radius:null,outlineWidth:null}}):this.notify("shape",{prop:"setStrokeSettings",value:{strokeSettings:null,strokeColor:null,fillColor:null,strokeWidth:null,radius:this.activeObj.strokeSettings.radius}}))},a.prototype.updateStrokeColor=function(e){var o={shapeSettingsObj:{}};this.notify("selection",{prop:"updatePrevShapeSettings",onPropertyChange:!1,value:{obj:o}});var i=o.shapeSettingsObj;if(this.activeObj.shape&&("path"!==this.activeObj.shape||"path"===this.activeObj.shape&&this.activeObj.pointColl.length>0)){var r=!1,a=this.objColl.length;this.notify("shape",{prop:"pushActItemIntoObj"}),a!==this.objColl.length&&(r=!0);var n=t.extend({},this.cropObj,{},!0),s={currObj:{}};this.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:s}});var l=s.currObj;l.objColl=t.extend([],this.objColl,[],!0),l.pointColl=t.extend([],this.pointColl,[],!0),l.afterCropActions=t.extend([],this.afterCropActions,[],!0);var p={selPointColl:null};this.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:p}}),l.selPointColl=t.extend([],p.selPointColl,[],!0),r&&this.objColl.pop(),this.activeObj.strokeSettings.strokeColor=e,this.notify("shape",{prop:"setStrokeSettings",value:{strokeSettings:null,strokeColor:this.activeObj.strokeSettings.strokeColor,fillColor:null,strokeWidth:null}}),this.togglePen||(this.objColl.push(this.activeObj),0===this.activeObj.activePoint.width&&0===this.activeObj.activePoint.height||this.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"shapeTransform",previousObj:l,previousObjColl:l.objColl,previousPointColl:l.pointColl,previousSelPointColl:l.selPointColl,previousCropObj:n,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),this.notify("selection",{prop:"redrawShape",value:{obj:this.objColl[this.objColl.length-1]}}))}else this.activeObj.shape&&"path"===this.activeObj.shape&&0===this.activeObj.pointColl.length&&(this.activeObj.strokeSettings.strokeColor=e,this.notify("shape",{prop:"setStrokeSettings",value:{strokeSettings:null,strokeColor:this.activeObj.strokeSettings.strokeColor,fillColor:null,strokeWidth:null}}));var h={action:"stroke-color",currentShapeSettings:t.extend({},i,{},!0)};h.currentShapeSettings.strokeColor=e,this.trigger("shapeChange",h),this.editCompleteArgs=h},a.prototype.updateFillColor=function(e){var o={shapeSettingsObj:{}};this.notify("selection",{prop:"updatePrevShapeSettings",onPropertyChange:!1,value:{obj:o}});var i=o.shapeSettingsObj,r=!1,a=this.objColl.length;this.notify("shape",{prop:"pushActItemIntoObj"}),a!==this.objColl.length&&(r=!0);var n=t.extend({},this.cropObj,{},!0),s={currObj:{}};this.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:s}});var l=s.currObj;l.objColl=t.extend([],this.objColl,[],!0),l.pointColl=t.extend([],this.pointColl,[],!0),l.afterCropActions=t.extend([],this.afterCropActions,[],!0);var p={selPointColl:null};this.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:p}}),l.selPointColl=t.extend([],p.selPointColl,[],!0),r&&this.objColl.pop(),this.activeObj.strokeSettings.fillColor=e,this.notify("shape",{prop:"setStrokeSettings",value:{strokeSettings:null,strokeColor:null,fillColor:this.activeObj.strokeSettings.fillColor,strokeWidth:null}}),this.objColl.push(this.activeObj),0===this.activeObj.activePoint.width&&0===this.activeObj.activePoint.height||this.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"shapeTransform",previousObj:l,previousObjColl:l.objColl,previousPointColl:l.pointColl,previousSelPointColl:l.selPointColl,previousCropObj:n,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),this.notify("selection",{prop:"redrawShape",value:{obj:this.objColl[this.objColl.length-1]}});var h={action:"fill-color",currentShapeSettings:t.extend({},i,{},!0)};this.trigger("shapeChange",h),this.editCompleteArgs=h},a.prototype.horizontalFlip=function(e,o){var i,r;if(t.isNullOrUndefined(o)){t.isNullOrUndefined(this.activeObj.imageRatio)&&this.notify("shape",{prop:"updImgRatioForActObj",onPropertyChange:!1}),this.notify("shape",{prop:"pushActItemIntoObj"}),i=t.extend({},this.cropObj,{},!0);var a={currObj:{}};this.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:a}}),(r=a.currObj).objColl=t.extend([],this.objColl,[],!0),r.pointColl=t.extend([],this.pointColl,[],!0),r.afterCropActions=t.extend([],this.afterCropActions,[],!0);var n={selPointColl:null};this.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:n}}),r.selPointColl=t.extend([],n.selPointColl,[],!0),this.objColl.pop()}this.notify("toolbar",{prop:"refreshSlider"}),e.clearRect(0,0,this.activeObj.imageCanvas.width,this.activeObj.imageCanvas.height);var s=this.duplicateImage();this.notify("draw",{prop:"downScaleImgCanvas",onPropertyChange:!1,value:{ctx:this.activeObj.imageCanvas.getContext("2d"),isImgAnnotation:!0,isHFlip:!0,isVFlip:null}}),this.activeObj.activePoint=s,this.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate"}}),t.isNullOrUndefined(o)&&(this.objColl.push(this.activeObj),this.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"imageHFlip",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]}}))},a.prototype.verticalFlip=function(e,o){var i,r;if(t.isNullOrUndefined(o)){t.isNullOrUndefined(this.activeObj.imageRatio)&&this.notify("shape",{prop:"updImgRatioForActObj",onPropertyChange:!1}),this.notify("shape",{prop:"pushActItemIntoObj"}),i=t.extend({},this.cropObj,{},!0);var a={currObj:{}};this.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:a}}),(r=a.currObj).objColl=t.extend([],this.objColl,[],!0),r.pointColl=t.extend([],this.pointColl,[],!0),r.afterCropActions=t.extend([],this.afterCropActions,[],!0);var n={selPointColl:null};this.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:n}}),r.selPointColl=t.extend([],n.selPointColl,[],!0),this.objColl.pop()}this.notify("toolbar",{prop:"refreshSlider"}),e.clearRect(0,0,this.activeObj.imageCanvas.width,this.activeObj.imageCanvas.height);var s=this.duplicateImage();this.notify("draw",{prop:"downScaleImgCanvas",onPropertyChange:!1,value:{ctx:this.activeObj.imageCanvas.getContext("2d"),isImgAnnotation:!0,isHFlip:null,isVFlip:!0}}),this.activeObj.activePoint=s,this.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate"}}),t.isNullOrUndefined(o)&&(this.objColl.push(this.activeObj),this.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"imageVFlip",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]}}))},a.prototype.rotateImage=function(e){var o,i;t.isNullOrUndefined(this.activeObj.imageRatio)&&this.notify("shape",{prop:"updImgRatioForActObj",onPropertyChange:!1}),this.notify("shape",{prop:"pushActItemIntoObj"}),o=t.extend({},this.cropObj,{},!0);var r={currObj:{}};this.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:r}}),(i=r.currObj).objColl=t.extend([],this.objColl,[],!0),i.pointColl=t.extend([],this.pointColl,[],!0),i.afterCropActions=t.extend([],this.afterCropActions,[],!0);var a={selPointColl:null};this.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:a}}),i.selPointColl=t.extend([],a.selPointColl,[],!0),this.objColl.pop(),this.notify("toolbar",{prop:"refreshSlider"}),"rotleft"===e?this.activeObj.rotatedAngle-=Math.PI/180*90:this.activeObj.rotatedAngle+=Math.PI/180*90,this.notify("selection",{prop:"updPtCollForShpRot",onPropertyChange:!1,value:{obj:this.activeObj}}),this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),this.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate"}}),this.objColl.push(this.activeObj),this.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"imageRotate",previousObj:i,previousObjColl:i.objColl,previousPointColl:i.pointColl,previousSelPointColl:i.selPointColl,previousCropObj:o,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),this.notify("selection",{prop:"redrawShape",value:{obj:this.objColl[this.objColl.length-1]}}),this.notify("toolbar",{prop:"destroy-qa-toolbar"}),this.notify("toolbar",{prop:"renderQAT",onPropertyChange:!1,value:{isPenEdit:null}})},a.prototype.pascalToSplitWords=function(e){var o=(e=e.charAt(0).toUpperCase()+e.slice(1)).match(/[A-Z][a-z]+/g);return t.isNullOrUndefined(o)?e:o.map(function(e){return e.charAt(0).toUpperCase()+e.slice(1)}).join(" ")},a.prototype.getCurrAdjustmentValue=function(e){var t=100,o={freehandSelectedIndex:null};if(this.notify("freehand-draw",{prop:"getFreehandSelectedIndex",onPropertyChange:!1,value:{obj:o}}),"transparency"===e&&this.togglePen){i={penOpacity:1};this.notify("freehand-draw",{prop:"getPenOpacity",onPropertyChange:!1,value:{obj:i}}),t=100*i.penOpacity}else if("transparency"===e&&null!==o.freehandSelectedIndex&&void 0!==o.freehandSelectedIndex)t=100*this.pointColl[o.freehandSelectedIndex].opacity;else{var i={adjustmentLevel:null};this.notify("filter",{prop:"getAdjustmentLevel",onPropertyChange:!1,value:{obj:i}}),t={brightness:i.adjustmentLevel.brightness,contrast:i.adjustmentLevel.contrast,hue:i.adjustmentLevel.hue,saturation:i.adjustmentLevel.saturation,opacity:i.adjustmentLevel.opacity,blur:i.adjustmentLevel.blur,exposure:i.adjustmentLevel.exposure,transparency:i.adjustmentLevel.transparency,straighten:this.transform.straighten}[""+e]}return t},a.prototype.transformSelect=function(e){0!==this.transform.straighten||"rotateleft"!==e&&"rotateright"!==e||!this.activeObj.shape||-1===["crop-2:3","crop-3:2","crop-3:4","crop-4:3","crop-4:5","crop-5:4","crop-5:7","crop-7:5","crop-9:16","crop-16:9"].indexOf(this.activeObj.shape)&&(-1===this.activeObj.shape.indexOf("crop-")||"crop-custom"===this.activeObj.shape||"crop-square"===this.activeObj.shape||"crop-circle"===this.activeObj.shape)||(this.activeObj.shape="crop-"+this.activeObj.shape.split("-")[1].split(":")[1]+":"+this.activeObj.shape.split("-")[1].split(":")[0],this.notify("toolbar",{prop:"performCropTransformClick",value:{shape:this.activeObj.shape,isTransform:!0}})),this.isCropToolbar=!0,this.allowDownScale=!1;var o=this.transform.straighten,i=t.extend({},this.activeObj,{},!0),r=this.transform.zoomFactor;this.prevEventSelectionPoint=t.extend({},this.activeObj,{},!0);var a={currObj:{}};this.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:a}}),this.prevEventObjPoint=a.currObj,this.prevEventObjPoint.objColl=t.extend([],this.objColl,[],!0),this.prevEventObjPoint.pointColl=t.extend([],this.pointColl,[],!0),this.prevEventObjPoint.afterCropActions=t.extend([],this.afterCropActions,[],!0);var n={selPointColl:null};if(this.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:n}}),this.prevEventObjPoint.selPointColl=t.extend([],n.selPointColl,[],!0),0!==this.transform.straighten){this.transform.straighten=0,this.straightenBaseImageCanvas();for(var s=0,l=this.objColl.length;s<l;s++)"line"!==(h=this.objColl[s].shape)&&"arrow"!==h&&"path"!==h&&(this.objColl[s].rotatedAngle-=o*(Math.PI/180),this.notify("selection",{prop:"updPtCollForShpRot",onPropertyChange:!1,value:{obj:this.objColl[s]}}));this.notify("draw",{prop:"render-image",value:{isMouseWheel:!1}}),this.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"zoom",pen:"zoom",isPreventApply:null}})}this.setInitialZoomState();var p=t.extend({},this.activeObj,{},!0);if(this.notify("crop",{prop:"setTransformCrop",onPropertyChange:!1,value:{bool:!0}}),this.cropSelectedState(),this.notify("crop",{prop:"setTransformCrop",onPropertyChange:!1,value:{bool:!1}}),this.notify("draw",{prop:"resetCurrentSelectionPoint"}),this.updateImageTransformColl(e),this.notify("transform",{prop:"performTransformation",value:{text:e}}),this.isCropTab=!0,this.notify("draw",{prop:"moveToSelectionRange",value:{type:e,activeObj:p}}),!this.isStraightening||"horizontalflip"!==e&&"verticalflip"!==e||(this.notify("draw",{prop:"resetStraightenDestPoints"}),this.notify("draw",{prop:"setDestForStraighten"})),0!==o){this.transform.straighten=o,this.straightenBaseImageCanvas();for(var s=0,l=this.objColl.length;s<l;s++){var h=this.objColl[s].shape;"line"!==h&&"arrow"!==h&&"path"!==h&&(this.objColl[s].rotatedAngle+=o*(Math.PI/180),this.notify("selection",{prop:"updPtCollForShpRot",onPropertyChange:!1,value:{obj:this.objColl[s]}}))}this.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"zoom",pen:"zoom",isPreventApply:null}}),this.notify("draw",{prop:"render-image",value:{isMouseWheel:!1}}),this.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate",obj:i}}),this.notify("draw",{prop:"setStraightenActObj",value:{activeObj:null}}),this.notify("draw",{prop:"setStraightenInitZoom",value:{zoomFactor:r}}),(this.isStraightening&&("horizontalflip"===e||"verticalflip"===e)&&t.isNullOrUndefined(this.transform.zoomFactor)||0===this.transform.zoomFactor)&&(0===this.transform.degree?this.transform.zoomFactor+=.025:0===this.transform.zoomFactor&&(this.transform.zoomFactor=null)),this.notify("draw",{prop:"zoomToSel",value:{activeObj:i,isToolbar:!1}})}this.isCropToolbar=!1;var d=this.element.querySelector(".e-ie-straighten-value-span");d&&(d.innerHTML=this.transform.straighten.toString()+"&#176")},a.prototype.getDefaultFilter=function(){return"brightness(1) contrast(100%) hue-rotate(0deg) saturate(100%) opacity(1) blur(0px) sepia(0%) grayscale(0%) invert(0%)"},a.prototype.setStraighten=function(e){var t={cancel:!1,previousDegree:this.transform.straighten,currentDegree:e};if(this.trigger("rotating",t),this.editCompleteArgs=t,!t.cancel){this.performStraighten(t);var o={action:"straighten",actionEventArgs:this.editCompleteArgs};this.triggerEditCompleteEvent(o)}},a.prototype.duplicateImage=function(){var e=t.extend({},this.activeObj.activePoint,{},!0),o={width:0,height:0};return this.notify("transform",{prop:"calcMaxDimension",onPropertyChange:!1,value:{width:this.activeObj.imageElement.width,height:this.activeObj.imageElement.height,obj:o,isImgShape:null}}),this.activeObj.activePoint.width=o.width,this.activeObj.activePoint.height=o.height,e},a.prototype.performStraighten=function(e){var o=e.currentDegree,i=this.element.querySelector(".e-ie-straighten-value-span");i&&(i.innerHTML=o.toString()+"&#176");var r=t.extend({},this.activeObj,null,!0);this.notify("freehand-draw",{prop:"setCenterSelPoints"}),this.transform.straighten=o,this.straightenPoint={x:this.activeObj.activePoint.startX+this.activeObj.activePoint.width/2,y:this.activeObj.activePoint.startY+this.activeObj.activePoint.height/2},this.straightenBaseImageCanvas();for(var a=0,n=this.objColl.length;a<n;a++){var s=this.objColl[a].shape;"line"!==s&&"arrow"!==s&&"path"!==s&&(this.objColl[a].rotatedAngle+=(this.transform.straighten-this.prevStraightenedDegree)*(Math.PI/180),this.notify("selection",{prop:"updPtCollForShpRot",onPropertyChange:!1,value:{obj:this.objColl[a]}}))}this.transform.degree%90==0&&this.transform.degree%180!=0?(0===this.transform.straighten&&(this.transform.straighten=360),this.notify("draw",{prop:"performPointZoom",onPropertyChange:!1,value:{x:this.activeObj.activePoint.startX+this.activeObj.activePoint.width/2,y:this.activeObj.activePoint.startY+this.activeObj.activePoint.height/2,type:"zoomIn",isResize:!0}}),this.notify("draw",{prop:"performPointZoom",onPropertyChange:!1,value:{x:this.activeObj.activePoint.startX+this.activeObj.activePoint.width/2,y:this.activeObj.activePoint.startY+this.activeObj.activePoint.height/2,type:"zoomOut",isResize:!0}}),360===this.transform.straighten&&(this.transform.straighten=0)):this.notify("draw",{prop:"render-image",value:{isMouseWheel:!0,isPreventClearRect:null,isFrame:null,isStraighten:!0}}),this.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate",obj:r}}),this.notify("draw",{prop:"zoomToSel",value:{activeObj:r,isToolbar:!0}}),this.notify("transform",{prop:"disableZoomOutBtn",value:{isZoomOut:!0}}),this.prevStraightenedDegree=this.transform.straighten},a.prototype.straightenBaseImageCanvas=function(){if(this.isImageLoaded){var e=this.getStraightenFlipState(),t="horizontal"===e||"vertical"===e?-this.transform.straighten:this.transform.straighten,o=this.baseImgCanvas.getContext("2d");if(o.canvas.width!==this.lowerContext.canvas.width&&o.canvas.height!==this.lowerContext.canvas.height){var i={width:0,height:0};this.notify("crop",{prop:"calcRatio",onPropertyChange:!1,value:{obj:i,dimension:{width:o.canvas.width,height:o.canvas.height}}})}var r=void 0;r=this.getRotatedCanvasDim(this.baseImg.width,this.baseImg.height,this.transform.straighten),this.img.srcWidth=o.canvas.width=r.width,this.img.srcHeight=o.canvas.height=r.height;var a=o.canvas.width/2,n=o.canvas.height/2;o.clearRect(0,0,o.canvas.width,o.canvas.height),o.translate(a,n),o.rotate(t*Math.PI/180),o.drawImage(this.baseImg,-this.baseImg.width/2,-this.baseImg.height/2,this.baseImg.width,this.baseImg.height),o.setTransform(1,0,0,1,0,0);var s={width:0,height:0};this.notify("crop",{prop:"calcRatio",onPropertyChange:!1,value:{obj:s,dimension:{width:o.canvas.width,height:o.canvas.height}}})}},a.prototype.getRotatedCanvasDim=function(e,t,o){var i=o*Math.PI/180,r=Math.cos(i),a=Math.sin(i),n=Math.min(0,e*r,t*Math.cos(Math.PI/2-i),e*r+t*Math.cos(Math.PI/2-i)),s=Math.max(0,e*r,t*Math.cos(Math.PI/2-i),e*r+t*Math.cos(Math.PI/2-i)),l=Math.min(0,e*a,t*Math.sin(Math.PI/2-i),e*a+t*Math.sin(Math.PI/2-i)),p=Math.max(0,e*a,t*Math.sin(Math.PI/2-i),e*a+t*Math.sin(Math.PI/2-i));return{width:Math.ceil(s-n),height:Math.ceil(p-l)}},a.prototype.updateShapeOrder=function(e,o){var i=this.getObjFromId(e);if(i.shape&&("path"!==i.shape||"path"===i.shape&&i.pointColl.length>0)||i&&i.id&&i.id.indexOf("pen")>-1){var r={shapeSettingsObj:{}};this.notify("selection",{prop:"updatePrevShapeSettings",onPropertyChange:!1,value:{obj:r}});var a=r.shapeSettingsObj;i.shape&&this.notify("shape",{prop:"pushActItemIntoObj"});var n=t.extend({},this.cropObj,{},!0),s={currObj:{}};this.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:s}});var l=s.currObj;l.objColl=t.extend([],this.objColl,[],!0),l.pointColl=t.extend([],this.pointColl,[],!0),l.afterCropActions=t.extend([],this.afterCropActions,[],!0);var p={selPointColl:null};this.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:p}}),l.selPointColl=t.extend([],p.selPointColl,[],!0),i.shape&&this.objColl.pop(),this.notify("shape",{prop:"z-order",onPropertyChange:!1,value:{obj:i,value:o}}),i.shape&&(this.notify("shape",{prop:"setStrokeSettings",value:{strokeSettings:null,strokeColor:null,fillColor:null,strokeWidth:i.strokeSettings.strokeWidth}}),this.objColl.push(i)),this.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"shapeTransform",previousObj:l,previousObjColl:l.objColl,previousPointColl:l.pointColl,previousSelPointColl:l.selPointColl,previousCropObj:n,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),i.shape&&(this.notify("selection",{prop:"redrawShape",value:{obj:this.objColl[this.objColl.length-1]}}),this.activeObj.order=i.order),{action:"stroke-width",previousShapeSettings:t.extend({},a,{},!0),currentShapeSettings:t.extend({},a,{},!0)}.currentShapeSettings.strokeWidth=this.activeObj.strokeSettings.strokeWidth}else this.activeObj.shape&&"path"===this.activeObj.shape&&0===this.activeObj.pointColl.length&&this.notify("shape",{prop:"setStrokeSettings",value:{strokeSettings:null,strokeColor:null,fillColor:null,strokeWidth:this.activeObj.strokeSettings.strokeWidth}})},a.prototype.getStraightenFlipState=function(){var e="";if(this.rotateFlipColl.length>0)for(var t=0,o=this.rotateFlipColl.length;t<o;t++){var i=this.rotateFlipColl[t];"horizontal"===i?e+="horizontal":"vertical"===i&&(e+="vertical"),"horizontalvertical"!==e&&"verticalhorizontal"!==e||(e="")}return e},a.prototype.initializeZoomSettings=function(){this.theme=t.isNullOrUndefined(this.theme)?"Bootstrap5":this.theme,(t.isNullOrUndefined(this.zoomSettings.zoomTrigger)||0===this.zoomSettings.zoomTrigger)&&(this.zoomSettings.zoomTrigger=e.ZoomTrigger.MouseWheel|e.ZoomTrigger.Pinch|e.ZoomTrigger.Toolbar|e.ZoomTrigger.Commands),t.isNullOrUndefined(this.selectionSettings.strokeColor)&&(this.selectionSettings.strokeColor=this.themeColl[this.theme].primaryColor),t.isNullOrUndefined(this.selectionSettings.fillColor)&&(this.selectionSettings.fillColor=this.themeColl[this.theme].secondaryColor)},a.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"},Fluent2:{primaryColor:"#0f6cbd",secondaryColor:"#fff"},Fluent2Dark:{primaryColor:"#115ea3",secondaryColor:"#fff"},Fluent2Highcontrast:{primaryColor:"#1aebff",secondaryColor:"#fff"},"Bootstrap5.3":{primaryColor:"#0d6efd",secondaryColor:"#fff"},"Bootstrap5.3Dark":{primaryColor:"#0d6efd",secondaryColor:"#fff"}}},a.prototype.drawRedact=function(e,o,i,r,a,n){var s=!1,l=this.allowShape(o,i);return!this.disabled&&this.isImageLoaded&&(l||t.isNullOrUndefined(o)&&t.isNullOrUndefined(i))&&(s=!0,this.notify("shape",{prop:"drawRedact",onPropertyChange:!1,value:{x:o,y:i,width:r,height:a,type:e,value:n}}),this.notify("draw",{prop:"redrawDownScale"})),s};var n;return m([t.Property("")],a.prototype,"cssClass",void 0),m([t.Property(!1)],a.prototype,"disabled",void 0),m([t.Property("100%")],a.prototype,"height",void 0),m([t.Property("Bootstrap5")],a.prototype,"theme",void 0),m([t.Property()],a.prototype,"toolbar",void 0),m([t.Property()],a.prototype,"toolbarTemplate",void 0),m([t.Property("100%")],a.prototype,"width",void 0),m([t.Property(!0)],a.prototype,"allowUndoRedo",void 0),m([t.Property(!0)],a.prototype,"showQuickAccessToolbar",void 0),m([t.Property()],a.prototype,"quickAccessToolbarTemplate",void 0),m([t.Property(!1)],a.prototype,"isReadOnly",void 0),m([t.Property(!1)],a.prototype,"enableRtl",void 0),m([t.Property(!1)],a.prototype,"enablePersistence",void 0),m([t.Complex({},y)],a.prototype,"finetuneSettings",void 0),m([t.Complex({},P)],a.prototype,"zoomSettings",void 0),m([t.Complex({},j)],a.prototype,"selectionSettings",void 0),m([t.Complex({},x)],a.prototype,"fontFamily",void 0),m([t.Event()],a.prototype,"beforeSave",void 0),m([t.Event()],a.prototype,"created",void 0),m([t.Event()],a.prototype,"destroyed",void 0),m([t.Event()],a.prototype,"zooming",void 0),m([t.Event()],a.prototype,"panning",void 0),m([t.Event()],a.prototype,"cropping",void 0),m([t.Event()],a.prototype,"rotating",void 0),m([t.Event()],a.prototype,"flipping",void 0),m([t.Event()],a.prototype,"shapeChanging",void 0),m([t.Event()],a.prototype,"selectionChanging",void 0),m([t.Event()],a.prototype,"fileOpened",void 0),m([t.Event()],a.prototype,"saved",void 0),m([t.Event()],a.prototype,"toolbarCreated",void 0),m([t.Event()],a.prototype,"toolbarUpdating",void 0),m([t.Event()],a.prototype,"toolbarItemClicked",void 0),m([t.Event()],a.prototype,"imageFiltering",void 0),m([t.Event()],a.prototype,"finetuneValueChanging",void 0),m([t.Event()],a.prototype,"click",void 0),m([t.Event()],a.prototype,"shapeChange",void 0),m([t.Event()],a.prototype,"quickAccessToolbarOpen",void 0),m([t.Event()],a.prototype,"resizing",void 0),m([t.Event()],a.prototype,"quickAccessToolbarItemClick",void 0),m([t.Event()],a.prototype,"frameChange",void 0),m([t.Event()],a.prototype,"editComplete",void 0),a=n=m([t.NotifyPropertyChanges],a)}(t.Component);!function(e){e.Png="Png",e.Jpeg="Jpeg",e.Svg="Svg"}(e.FileType||(e.FileType={})),function(e){e.Horizontal="Horizontal",e.Vertical="Vertical"}(e.Direction||(e.Direction={})),function(e){e.Rectangle="Rectangle",e.Ellipse="Ellipse",e.Line="Line",e.Arrow="Arrow",e.Path="Path",e.Text="Text",e.FreehandDraw="FreehandDraw",e.Image="Image"}(e.ShapeType||(e.ShapeType={})),function(e){e[e.MouseWheel=1]="MouseWheel",e[e.Pinch=2]="Pinch",e[e.Commands=4]="Commands",e[e.Toolbar=8]="Toolbar"}(e.ZoomTrigger||(e.ZoomTrigger={})),function(e){e.Bootstrap5="Bootstrap5",e.Bootstrap5Dark="Bootstrap5Dark",e.Tailwind="Tailwind",e.TailwindDark="TailwindDark",e.Fluent="Fluent",e.FluentDark="FluentDark",e.Bootstrap4="Bootstrap4",e.Bootstrap="Bootstrap",e.BootstrapDark="BootstrapDark",e.Material="Material",e.MaterialDark="MaterialDark",e.Fabric="Fabric",e.FabricDark="FabricDark",e.Highcontrast="Highcontrast",e.Fluent2="Fluent2",e.Fluent2Dark="Fluent2Dark"}(e.Theme||(e.Theme={})),function(e){e.Crop="Crop",e.Transform="Transform",e.Annotate="Annotate",e.ZoomIn="ZoomIn",e.ZoomOut="ZoomOut",e.Open="Open",e.Reset="Reset",e.Save="Save",e.Pan="Pan",e.Move="Move",e.Pen="Pen",e.Line="Line",e.Arrow="Arrow",e.Path="Path",e.Rectangle="Rectangle",e.Image="Image",e.Ellipse="Ellipse",e.Text="Text",e.CustomSelection="CustomSelection",e.CircleSelection="CircleSelection",e.SquareSelection="SquareSelection",e.RatioSelection="RatioSelection",e.RotateLeft="RotateLeft",e.RotateRight="RotateRight",e.FlipHorizontal="FlipHorizontal",e.FlipVertical="FlipVertical",e.Undo="Undo",e.Redo="Redo",e.None="None",e.Mat="Mat",e.Bevel="Bevel",e.Inset="Inset",e.Hook="Hook",e.Finetune="Finetune",e.Filter="Filter",e.Frame="Frame",e.Resize="Resize",e.HorizontalFlip="HorizontalFlip",e.VerticalFlip="VerticalFlip",e.Brightness="Brightness",e.Contrast="Contrast",e.Hue="Hue",e.Saturation="Saturation",e.Opacity="Opacity",e.Blur="Blur",e.Exposure="Exposure",e.Default="Default",e.Chrome="Chrome",e.Cold="Cold",e.Warm="Warm",e.Grayscale="Grayscale",e.Sepia="Sepia",e.Invert="Invert",e.Straightening="Straightening"}(e.ImageEditorCommand||(e.ImageEditorCommand={})),function(e){e.Default="Default",e.Chrome="Chrome",e.Cold="Cold",e.Warm="Warm",e.Grayscale="Grayscale",e.Sepia="Sepia",e.Invert="Invert"}(e.ImageFilterOption||(e.ImageFilterOption={})),function(e){e.Brightness="Brightness",e.Contrast="Contrast",e.Hue="Hue",e.Saturation="Saturation",e.Exposure="Exposure",e.Opacity="Opacity",e.Blur="Blur"}(e.ImageFinetuneOption||(e.ImageFinetuneOption={})),function(e){e.None="None",e.Arrow="Arrow",e.SolidArrow="SolidArrow",e.Circle="Circle",e.SolidCircle="SolidCircle",e.Square="Square",e.SolidSquare="SolidSquare",e.Bar="Bar"}(e.ArrowheadType||(e.ArrowheadType={})),function(e){e.None="None",e.Mat="Mat",e.Bevel="Bevel",e.Line="Line",e.Inset="Inset",e.Hook="Hook"}(e.FrameType||(e.FrameType={})),function(e){e.Solid="Solid",e.Dashed="Dashed",e.Dotted="Dotted"}(e.FrameLineStyle||(e.FrameLineStyle={})),function(e){e.Blur="Blur",e.Pixelate="Pixelate"}(e.RedactType||(e.RedactType={}));var O=function(){function s(e){this.defToolbarItems=[],this.toolbarHeight=46,this.currToolbar="",this.preventZoomBtn=!1,this.currentToolbar="main",this.selFhdColor="#42a5f5",this.preventEnableDisableUr=!1,this.isAspectRatio=!0,this.isFrameToolbar=!1,this.presetColors={custom:["#000000","#f44336","#e91e63","#9c27b0","#673ab7","#2196f3","#03a9f4","#00bcd4","#009688","#ffeb3b","#ffffff","#ffebee","#fce4ec","#f3e5f5","#ede7f6","#e3f2fd","#e1f5fe","#e0f7fa","#e0f2f1","#fffde7","#f2f2f2","#ffcdd2","#f8bbd0","#e1bee7","#d1c4e9","#bbdefb","#b3e5fc","#b2ebf2","#b2dfdb","#fff9c4","#e6e6e6","#ef9a9a","#f48fb1","#ce93d8","#b39ddb","#90caf9","#81d4fa","#80deea","#80cbc4","#fff59d","#cccccc","#e57373","#f06292","#ba68c8","#9575cd","#64b5f6","#4fc3f7","#4dd0e1","#4db6ac","#fff176","#b3b3b3","#ef5350","#ec407a","#ab47bc","#7e57c2","#42a5f5","#29b6f6","#26c6da","#26a69a","#ffee58","#999999","#e53935","#d81b60","#8e24aa","#5e35b1","#1e88e5","#039be5","#00acc1","#00897b","#fdd835","#808080","#d32f2f","#c2185b","#7b1fa2","#512da8","#1976d2","#0288d1","#0097a7","#00796b","#fbc02d","#666666","#c62828","#ad1457","#6a1b9a","#4527a0","#1565c0","#0277bd","#00838f","#00695c","#f9a825","#4d4d4d","#b71c1c","#880e4f","#4a148c","#311b92","#0d47a1","#01579b","#006064","#004d40","#f57f17"]},this.isSlider=!1,this.currentQuality=1,this.imageQuality="highest",this.parent=e,this.addEventListener(),this.initLocale()}return s.prototype.destroy=function(){this.parent.isDestroyed||this.removeEventListener()},s.prototype.addEventListener=function(){this.parent.on("toolbar",this.toolbar,this),this.parent.on("destroyed",this.destroy,this)},s.prototype.removeEventListener=function(){this.parent.off("toolbar",this.toolbar),this.parent.off("destroyed",this.destroy)},s.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:"Apply",Cancel:"Discard",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",Image:"Add Image",Transparency:"Transparency",Height:"Height",Width:"Width",AspectRatio:"Maintain aspect ratio",W:"W",H:"H",DragText:"Drag and drop your image here or",DropText:"Drop your image here or",BrowseText:"Browse here...",SupportText:"Supports:",Frame:"Frame",Mat:"Mat",Bevel:"Bevel",Inset:"Inset",Hook:"Hook",Color:"Color",Size:"Size",Offset:"Offset",Radius:"Radius",Amount:"Amount",Resize:"Resize",0:"0%",20:"20%",40:"40%",60:"60%",80:"80%",100:"100%",1:"1",2:"2",3:"3",4:"4",5:"5",Border:"Border",Solid:"Solid",Dashed:"Dashed",Dotted:"Dotted",GradientColor:"Gradient Color",ConfirmDialogHeader:"Confirm Save Changes",ConfirmDialogContent:"Do you want to save the changes you made to the image?",AlertDialogHeader:"Unsupported file",AlertDialogContent:"The selected file is unsupported.",Yes:"Yes",No:"No",ImageErrorDialogHeader:"Image Selection Error",ImageErrorDialogContent:"Please select only one image to open.",Straighten:"Straighten",NoOutline:"No outline",DlgOK:"OK",SaveAs:"Save As",ImageName:"Image name",Format:"Format",Quality:"Quality",Download:"Download",Close:"Close",ImageSize:"Image Size",QualityInfo:"The image quality option is only available for JPEG format",Good:"Good",Great:"Great",Highest:"Highest",BringForward:"Bring Forward",SendBackward:"Send Backward",SendToBack:"Send to Back",BringToFront:"Bring to Front",ZOrder:"Z-Order",Redact:"Redact",Pixelate:"Pixelate",BorderRadius:"Border Radius",TextOutlineColor:"Outline Color",TextOutlineWidth:"Outline Width",PixelSize:"Pixel Size"},this.l10n=new t.L10n("image-editor",this.defaultLocale,this.parent.locale)},s.prototype.toolbar=function(e){var o=this.parent;switch(this.updatePrivateVariables(),e.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(e.value.type,e.value.isApplyBtn,e.value.isCropping,e.value.isZooming,e.value.cType);break;case"renderQAT":this.renderQAT(e.value.isPenEdit);break;case"enable-disable-btns":this.enableDisableTbrBtn();break;case"init-main-toolbar":this.initMainToolbar(e.value.isApplyBtn,e.value.isDevice,e.value.isOkBtn,e.value.isResize,e.value.isFrame,e.value.isMainToolbar);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(e.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(e.value.locale);break;case"setPreventZoomBtn":this.preventZoomBtn=e.value.isPrevent;break;case"getToolbarHeight":e.value.obj.toolbarHeight=this.toolbarHeight;break;case"setToolbarHeight":(t.isNullOrUndefined(o.toolbar)||o.toolbar&&o.toolbar.length>0&&o.toolbar.indexOf("Open")>-1)&&(this.toolbarHeight=e.value.height);break;case"setCurrentToolbar":this.currentToolbar=e.value.type;break;case"setSelectedFreehandColor":this.selFhdColor=e.value.color;break;case"setInitialAdjustmentValue":o.initialAdjustmentValue=e.value.value;break;case"getCanvasFilter":e.value.obj.canvasFilter=o.canvasFilter;break;case"getDefToolbarItems":e.value.obj.defToolbarItems=this.defToolbarItems;break;case"getPenStroke":this.getPenStroke(e.value.value);break;case"performDefToolbarClickAction":this.performDefTbrClick(e.value.type,e.value.isContextualToolbar,e.value.isDisabledAdjustment,e.value.isDisabledFilter,e.value.isFilterFinetune);break;case"setTempFilterProperties":o.setTempFilterProperties();break;case"refreshSlider":this.refreshSlider();break;case"getCurrAdjustmentValue":o.getCurrAdjustmentValue(e.value.type);break;case"setCurrAdjustmentValue":o.setCurrAdjustmentValue(e.value.type,e.value.value);break;case"refreshShapeDrawing":this.refreshShapeDrawing();break;case"setEnableDisableUndoRedo":this.preventEnableDisableUr=e.value.isPrevent;break;case"reset":this.reset();break;case"getLocaleText":e.value.obj.value=this.l10n.getConstant(e.value.obj.key);break;case"initResizeToolbar":this.initResizeToolbar();break;case"getFrameToolbar":e.value.obj.bool=this.isFrameToolbar;break;case"resizeClick":this.resizeClick();break;case"frameToolbarClick":this.frameToolbarClick();break;case"performCropTransformClick":this.performCropTransformClick(e.value.shape,e.value.isTransform);break;case"duplicateShape":this.duplicateShape(e.value.isPreventUndoRedo,!0);break;case"editText":this.editText();break;case"setInitialSize":this.initialSize=Number(e.value.value);break;case"widthPress":this.widthPress(e.value.e);break;case"heightPress":this.heightPress(e.value.e);break;case"widthAspectRatio":this.widthAspectRatio(e.value.e);break;case"heightAspectRatio":this.heightAspectRatio(e.value.e)}},s.prototype.updatePrivateVariables=function(){var e=this.parent;this.inMemoryCanvas=e.inMemoryCanvas,e.lowerCanvas&&(this.lowerContext=e.lowerCanvas.getContext("2d")),e.upperCanvas&&(this.upperContext=e.upperCanvas.getContext("2d")),this.inMemoryCanvas&&(this.inMemoryContext=this.inMemoryCanvas.getContext("2d"))},s.prototype.reset=function(){var e=this.parent;this.toolbarHeight=46,e.prevCurrSelectionPoint=null,this.zoomBtnHold=null,this.currToolbar="",e.cxtTbarHeight=null,this.currentToolbar="main",this.selFhdColor="#42a5f5",e.currentFilter="",this.preventZoomBtn=e.isCropToolbar=this.preventEnableDisableUr=this.isFrameToolbar=!1,e.initialAdjustmentValue=e.canvasFilter="brightness(1) contrast(100%) hue-rotate(0deg) saturate(100%) opacity(1) blur(0px) sepia(0%) grayscale(0%) invert(0%)",e.tempStraighten=0,e.isStraightening=!1},s.prototype.destroyTopToolbar=function(){var e=this.parent,o=document.getElementById(e.element.id+"_toolbar");this.isToolbar()&&o&&o.classList.contains("e-control")&&t.getComponent(o,"toolbar").destroy()},s.prototype.destroyBottomToolbar=function(){var e=this.parent,o=document.getElementById(e.element.id+"_bottomToolbar");o&&o.classList.contains("e-control")&&t.getComponent(o,"toolbar").destroy()},s.prototype.isToolbar=function(){var e=this.parent;return t.isNullOrUndefined(e.toolbar)||e.toolbar&&e.toolbar.length>0||!t.isNullOrUndefined(e.toolbarTemplate)},s.prototype.createToolbar=function(){var e=this,o=this.parent,a=o.element.id;if(t.isNullOrUndefined(o.toolbar)||o.toolbar&&o.toolbar.length>0){o.element.appendChild(o.createElement("div",{id:a+"_toolbarArea",className:"e-toolbar-area"}));var n={cssClass:"e-image-upload",align:"Left",type:"Input",tooltipText:this.l10n.getConstant("Browse"),template:new i.Uploader({allowedExtensions:".jpg, .jpeg, .png,.svg",multiple:!1})};t.isNullOrUndefined(this.defToolbarItems)&&(this.defToolbarItems=[]),this.defToolbarItems.push(n);var s=document.getElementById(a+"_toolbarArea"),l=o.createElement("div",{id:a+"_toolbar"});s.appendChild(l);var p=[{cssClass:"e-image-upload",align:"Left",type:"Input",tooltipText:this.l10n.getConstant("Browse"),template:new i.Uploader({allowedExtensions:".jpg, .jpeg, .png,.svg",multiple:!1,selected:function(){var i=document.getElementById(a+"_toolbar"),r=document.getElementById(a+"_bottomToolbar");o.disabled||(t.Browser.isDevice?(e.defToolbarItems.length>0&&i&&t.getComponent(i,"toolbar").destroy(),r&&t.getComponent(r,"toolbar").destroy(),e.initMainToolbar(!1,t.Browser.isDevice,null),e.createBottomToolbar()):(e.defToolbarItems.length>0&&i&&t.getComponent(i,"toolbar").destroy(),e.initMainToolbar(!1,!1,null)))}})}];new r.Toolbar({items:p,width:"100%",created:function(){o.trigger("toolbarCreated",{toolbarType:"main"})},clicked:this.defToolbarClicked.bind(this)}).appendTo("#"+a+"_toolbar"),this.createLeftToolbarControls();var h=document.getElementById(a+"_toolbar");if(l&&(this.toolbarHeight=h.clientHeight,o.toolbar&&o.toolbar.length>0&&-1===o.toolbar.indexOf("Open"))){var d=t.getComponent(document.getElementById(o.element.id+"_toolbar"),"toolbar");d&&(d.destroy(),document.getElementById(o.element.id+"_toolbar").innerHTML="")}}else this.toolbarHeight=0},s.prototype.createContextualToolbar=function(){var e=this.parent,o=e.element.id;if(t.isNullOrUndefined(e.toolbar)||e.toolbar&&e.toolbar.length>0){e.element.appendChild(e.createElement("div",{id:o+"_contextualToolbarArea",className:"e-contextual-toolbar-wrapper e-hide",attrs:{style:"position: absolute;"}}));var i=document.getElementById(o+"_contextualToolbarArea"),r=e.createElement("div",{id:o+"_contextualToolbar"});i.appendChild(r)}},s.prototype.createBottomToolbar=function(){var e=this.parent,o=e.element.id;if(e.element.querySelector("#"+o+"_bottomToolbarArea")&&e.element.querySelector("#"+o+"_bottomToolbarArea").remove(),t.isNullOrUndefined(e.toolbar)||e.toolbar&&e.toolbar.length>0){if(e.element.appendChild(e.createElement("div",{id:o+"_bottomToolbarArea",className:"e-bottom-toolbar"})),!e.toolbarTemplate){var i=document.getElementById(o+"_bottomToolbarArea"),r=e.createElement("div",{id:o+"_bottomToolbar"});i.appendChild(r)}this.initBottomToolbar()}},s.prototype.createQuickAccessToolbar=function(){var e=this.parent,o=e.element.id;if(e.showQuickAccessToolbar){var a={cssClass:"e-image-upload",align:"Left",type:"Input",tooltipText:this.l10n.getConstant("Browse"),template:new i.Uploader({allowedExtensions:".jpg, .jpeg, .png,.svg",multiple:!1})};t.isNullOrUndefined(this.defToolbarItems)&&(this.defToolbarItems=[]),this.defToolbarItems.push(a);var n=document.getElementById(o+"_quickAccessToolbarArea"),s=e.createElement("div",{id:o+"_quickAccessToolbar"});n.appendChild(s),new r.Toolbar({clicked:this.defToolbarClicked.bind(this)}).appendTo("#"+o+"_quickAccessToolbar")}},s.prototype.initMainToolbar=function(e,o,i,a,n,s,l){var p=this,h=this.parent,d=h.element.id;if(this.isToolbar()){var c=this.getLeftToolbarItem(i,a),u=this.getRightToolbarItem(i,s,l),v=this.getMainToolbarItem(e,n,l),g=this.getZoomToolbarItem();this.defToolbarItems=o?n||l?v:c.concat(u):c.concat(v,u,g);var f={toolbarType:"main",toolbarItems:this.defToolbarItems};if(h.trigger("toolbarUpdating",f),this.defToolbarItems=f.toolbarItems,this.defToolbarItems.length>0){var C=new r.Toolbar({width:"100%",items:this.defToolbarItems,clicked:this.defToolbarClicked.bind(this),created:function(){o||p.renderAnnotationBtn(),p.wireZoomBtnEvents(),h.trigger("toolbarCreated",{toolbarType:"main"})}});o&&n||o&&l?C.appendTo("#"+d+"_bottomToolbar"):C.appendTo("#"+d+"_toolbar"),this.createLeftToolbarControls(),this.enableDisableTbrBtn(),this.isToolbar()&&document.getElementById(d+"_toolbar")&&t.getComponent(d+"_toolbar","toolbar").refreshOverflow()}}},s.prototype.initBottomToolbar=function(){var e=this,o=this.parent,i=o.element.id;if(t.isNullOrUndefined(o.toolbar)||o.toolbar&&o.toolbar.length>0){var a=this.getMainToolbarItem(),n={toolbarType:"bottom-toolbar",toolbarItems:a};o.trigger("toolbarUpdating",n),a=n.toolbarItems,new r.Toolbar({items:a,width:"100%",created:function(){e.renderAnnotationBtn(),e.renderCropBtn(),e.renderTransformBtn(),o.trigger("toolbarCreated",{toolbarType:"main"})},clicked:this.defToolbarClicked.bind(this)}).appendTo("#"+i+"_bottomToolbar"),this.defToolbarItems.length>0&&document.getElementById(i+"_bottomToolbar")&&t.getComponent(i+"_bottomToolbar","toolbar").refreshOverflow()}},s.prototype.getLeftToolbarItem=function(o,r){var a=this.parent,n=a.element.id,s=[];o&&!r||(t.isNullOrUndefined(a.toolbar)||a.toolbar&&a.toolbar.indexOf("Open")>-1?(s.push({id:n+"_upload",cssClass:"e-image-upload",align:"Left",type:"Input",template:new i.Uploader({allowedExtensions:".jpg, .jpeg, .png,.svg",multiple:!1})}),s.push({visible:!1,cssClass:"e-image-position e-btn e-flat",tooltipText:this.l10n.getConstant("Browse"),align:"Left"})):t.Browser.isDevice&&a.toolbar&&-1===a.toolbar.indexOf("Open")&&(s.push({visible:!1,id:n+"_upload",cssClass:"e-image-upload",align:"Left",type:"Input",template:new i.Uploader({allowedExtensions:".jpg, .jpeg, .png,.svg",multiple:!1})}),s.push({visible:!1,cssClass:"e-image-position e-btn e-flat",tooltipText:this.l10n.getConstant("Browse"),align:"Left"}))),a.allowUndoRedo&&!r&&((t.isNullOrUndefined(a.toolbar)||a.toolbar&&a.toolbar.indexOf("Undo")>-1)&&s.push({id:n+"_undo",prefixIcon:"e-icons e-undo",cssClass:"top-icon e-undo",tooltipText:this.l10n.getConstant("Undo"),align:"Left"}),(t.isNullOrUndefined(a.toolbar)||a.toolbar&&a.toolbar.indexOf("Redo")>-1)&&s.push({id:n+"_redo",prefixIcon:"e-icons e-redo",cssClass:"top-icon e-redo",tooltipText:this.l10n.getConstant("Redo"),align:"Left"})),this.preventZoomBtn||(a.zoomSettings.zoomTrigger&e.ZoomTrigger.Toolbar)!==e.ZoomTrigger.Toolbar||r||((t.isNullOrUndefined(a.toolbar)||a.toolbar&&a.toolbar.indexOf("ZoomOut")>-1)&&s.push({id:n+"_zoomOut",prefixIcon:"e-icons e-zoom-out",cssClass:"top-icon e-dec-zoom",tooltipText:this.l10n.getConstant("ZoomOut"),align:"Left"}),(t.isNullOrUndefined(a.toolbar)||a.toolbar&&a.toolbar.indexOf("ZoomIn")>-1)&&s.push({id:n+"_zoomIn",prefixIcon:"e-icons e-zoom-in",cssClass:"top-icon e-inc-zoom",tooltipText:this.l10n.getConstant("ZoomIn"),align:"Left"}));for(var l=this.processToolbar("left"),p=0,h=l.length;p<h;p++)s.push(l[p]);return s},s.prototype.getRightToolbarItem=function(e,o,i){var r=this.parent,a=r.element.id,n=[];(e||i)&&(n.push({id:a+"_ok",prefixIcon:"e-icons e-check",cssClass:"top-icon e-tick",tooltipText:this.l10n.getConstant("OK"),align:"Right",tabIndex:0}),n.push({id:a+"_cancel",prefixIcon:"e-icons e-close",cssClass:"top-icon e-save",tooltipText:this.l10n.getConstant("Cancel"),align:"Right"})),!o&&t.Browser.isDevice||!(t.isNullOrUndefined(r.toolbar)||r.toolbar&&r.toolbar.indexOf("Reset")>-1)||n.push({id:a+"_reset",prefixIcon:"e-icons e-btn-reset",cssClass:"top-icon e-img-reset",tooltipText:this.l10n.getConstant("Reset"),align:"Right"}),e||(t.isNullOrUndefined(r.toolbar)||r.toolbar&&r.toolbar.indexOf("Save")>-1)&&n.push({id:a+"_save",prefixIcon:"e-icons e-btn-save",cssClass:"e-caret-hide top-icon e-save",tooltipText:this.l10n.getConstant("Save"),align:"Right"});for(var s=this.processToolbar("right"),l=0,p=s.length;l<p;l++)n.push(s[l]);return n},s.prototype.getMainToolbarItem=function(e,o,i){var r=this.parent,a=r.element.id,n=[];o?((t.isNullOrUndefined(r.toolbar)||!t.isNullOrUndefined(r.toolbar)&&r.toolbar.indexOf("None")>-1||r.toolbar.indexOf("Frame")>-1)&&n.push({id:a+"_none",prefixIcon:"e-icons e-frame-none",cssClass:"top-icon e-frame-none",tooltipText:this.l10n.getConstant("None"),align:"Center"}),(t.isNullOrUndefined(r.toolbar)||!t.isNullOrUndefined(r.toolbar)&&r.toolbar.indexOf("Mat")>-1||r.toolbar.indexOf("Frame")>-1)&&n.push({id:a+"_mat",prefixIcon:"e-icons e-frame-mat",cssClass:"top-icon e-frame-mat",tooltipText:this.l10n.getConstant("Mat"),align:"Center"}),(t.isNullOrUndefined(r.toolbar)||!t.isNullOrUndefined(r.toolbar)&&r.toolbar.indexOf("Bevel")>-1||r.toolbar.indexOf("Frame")>-1)&&n.push({id:a+"_bevel",prefixIcon:"e-icons e-frame-bevel",cssClass:"top-icon e-frame-bevel",tooltipText:this.l10n.getConstant("Bevel"),align:"Center"}),(t.isNullOrUndefined(r.toolbar)||!t.isNullOrUndefined(r.toolbar)&&r.toolbar.indexOf("Line")>-1||r.toolbar.indexOf("Frame")>-1)&&n.push({id:a+"_line",prefixIcon:"e-icons e-frame-line",cssClass:"top-icon e-frame-line",tooltipText:this.l10n.getConstant("Line"),align:"Center"}),(t.isNullOrUndefined(r.toolbar)||!t.isNullOrUndefined(r.toolbar)&&r.toolbar.indexOf("Inset")>-1||r.toolbar.indexOf("Frame")>-1)&&n.push({id:a+"_inset",prefixIcon:"e-icons e-frame-inset",cssClass:"top-icon e-frame-inset",tooltipText:this.l10n.getConstant("Inset"),align:"Center"}),(t.isNullOrUndefined(r.toolbar)||!t.isNullOrUndefined(r.toolbar)&&r.toolbar.indexOf("Hook")>-1||r.toolbar.indexOf("Frame")>-1)&&n.push({id:a+"_hook",prefixIcon:"e-icons e-frame-hook",cssClass:"top-icon e-frame-hook",tooltipText:this.l10n.getConstant("Hook"),align:"Center"})):i?(n.push({id:a+"_redactBlur",prefixIcon:"e-icons e-tint",cssClass:"top-icon e-opacity",tooltipText:this.l10n.getConstant("Blur"),align:"Center"}),n.push({id:a+"_pixelate",prefixIcon:"e-icons e-opacity",cssClass:"top-icon e-opacity",tooltipText:this.l10n.getConstant("Pixelate"),align:"Center"}),n.push({id:a+"_duplicate",prefixIcon:"e-icons e-order",cssClass:"top-icon e-order",tooltipText:this.l10n.getConstant("Duplicate"),align:"Center"}),n.push({id:a+"_remove",prefixIcon:"e-icons e-trash",cssClass:"top-icon e-trash",tooltipText:this.l10n.getConstant("Remove"),align:"Center"})):((t.isNullOrUndefined(r.toolbar)||r.toolbar&&r.toolbar.indexOf("Crop")>-1)&&n.push({id:a+"_cropTransform",prefixIcon:"e-icons e-crop",cssClass:"top-icon e-crop",tooltipText:this.l10n.getConstant("CropAndTransform"),align:"Center"}),(t.isNullOrUndefined(r.toolbar)||r.toolbar&&r.toolbar.indexOf("Annotate")>-1)&&n.push({id:a+"_annotation",tooltipText:this.l10n.getConstant("Annotation"),align:"Center",template:'<button id="'+a+'_annotationBtn"></button>'}),(t.isNullOrUndefined(r.toolbar)||r.toolbar&&r.toolbar.indexOf("Finetune")>-1)&&n.push({id:a+"_adjustment",prefixIcon:"e-icons e-adjustment",cssClass:"top-icon e-adjustment",tooltipText:this.l10n.getConstant("Finetune"),align:"Center"}),(t.isNullOrUndefined(r.toolbar)||r.toolbar&&r.toolbar.indexOf("Filter")>-1)&&n.push({id:a+"_filter",prefixIcon:"e-icons e-filters",cssClass:"top-icon e-filters",tooltipText:this.l10n.getConstant("Filter"),align:"Center"}),(t.isNullOrUndefined(r.toolbar)||!t.isNullOrUndefined(r.toolbar)&&r.toolbar.indexOf("Frame")>-1)&&n.push({id:a+"_frame",prefixIcon:"e-icons e-border-frame",cssClass:"top-icon e-border-frame",tooltipText:this.l10n.getConstant("Frame"),align:"Center"}),(t.isNullOrUndefined(r.toolbar)||!t.isNullOrUndefined(r.toolbar)&&r.toolbar.indexOf("Resize")>-1)&&n.push({id:a+"_resize",prefixIcon:"e-icons e-resize",cssClass:"top-icon e-resize",tooltipText:this.l10n.getConstant("Resize"),align:"Center"}),(t.isNullOrUndefined(r.toolbar)||!t.isNullOrUndefined(r.toolbar)&&r.toolbar.indexOf("Redact")>-1)&&n.push({id:a+"_redact",prefixIcon:"e-icons e-redact",cssClass:"top-icon e-opacity",tooltipText:this.l10n.getConstant("Redact"),align:"Center"}));for(var s=this.processToolbar("center"),l=0,p=s.length;l<p;l++)n.push(s[l]);return e&&(n.push({id:a+"_ok",prefixIcon:"e-icons e-check",cssClass:"top-icon e-tick",tooltipText:this.l10n.getConstant("OK"),align:"Right",tabIndex:0}),n.push({id:a+"_cancel",prefixIcon:"e-icons e-close",cssClass:"top-icon e-save",tooltipText:this.l10n.getConstant("Cancel"),align:"Right"})),n},s.prototype.getZoomToolbarItem=function(){return[]},s.prototype.updateContextualToolbar=function(e,o,i){var r=this.parent,a=r.element.id,n=r.element.querySelector("#"+a+"_toolbarArea"),s=r.element.querySelector("#"+a+"_contextualToolbarArea");if(s){if(s.classList.remove("e-hide"),s.style.left=n.offsetLeft+"px","filter"===e){var l=document.getElementById(a+"_toolbar");l&&this.defToolbarItems.length>0&&t.getComponent(l,"toolbar").destroy(),t.Browser.isDevice?this.initMainToolbar(!1,!0,!0):this.initMainToolbar(!0,null,null),this.refreshSlider(),this.initFilterToolbarItem()}else(c=document.querySelector("#"+a+"_contextualToolbar")).classList.contains("e-control")&&t.getComponent(c,"toolbar").destroy(),this.refreshSlider(),"frame"===e?this.initFrameToolbarItem():this.renderSlider(o,i);if(r.toolbarTemplate?this.toolbarHeight=r.element.querySelector("#"+a+"_toolbarArea").clientHeight:r.element.querySelector("#"+a+"_toolbar")&&(this.toolbarHeight=r.element.querySelector("#"+a+"_toolbar").clientHeight),r.toolbarHeight=this.toolbarHeight,t.Browser.isDevice){var p=s.offsetHeight+1,h=r.element.querySelector("#"+a+"_customizeWrapper");this.isFrameToolbar&&h&&(p=h.offsetHeight+2);var d=r.element.querySelector("#"+a+"_canvasWrapper").offsetHeight;if(s.style.top=this.toolbarHeight+1+d-p+"px","straighten"===o){r.isStraightening=!0;var c=r.element.querySelector("#"+a+"_contextualToolbarArea");"absolute"===c.style.position&&(c.style.position="",r.element.insertBefore(c,r.element.querySelector("#"+a+"_bottomToolbarArea")),r.update(),i&&r.notify("draw",{prop:"select",onPropertyChange:!1,value:{type:this.getCropTextContent(document.getElementById(a+"_cropBtn")).toLowerCase(),startX:null,startY:null,width:null,height:null}}))}}else s.style.top=this.toolbarHeight+1+"px"}},s.prototype.processToolbar=function(e){var o=this.parent,i=[];if(o.toolbar)for(var r=0,a=o.toolbar.length;r<a;r++)"object"==typeof o.toolbar[r]&&(t.isNullOrUndefined(o.toolbar[r].align)?"left"===e&&i.push(o.toolbar[r]):o.toolbar[r].align.toLowerCase()===e&&i.push(o.toolbar[r]));return i},s.prototype.processSubToolbar=function(e){var t=[];if(e)for(var o=0,i=e.length;o<i;o++)"object"==typeof e[o]&&(e[o].align="Center",t.push(e[o]));return t},s.prototype.wireZoomBtnEvents=function(){var e=document.querySelector("#"+this.parent.element.id+"_zoomIn"),t=document.querySelector("#"+this.parent.element.id+"_zoomOut");e&&(e.addEventListener("mousedown",this.zoomInBtnMouseDownHandler.bind(this)),e.addEventListener("mouseup",this.zoomBtnMouseUpHandler.bind(this)),e.addEventListener("click",this.zoomInBtnClickHandler.bind(this)),e.addEventListener("touchstart",this.zoomInBtnClickHandler.bind(this))),t&&(t.addEventListener("mousedown",this.zoomOutBtnMouseDownHandler.bind(this)),t.addEventListener("mouseup",this.zoomBtnMouseUpHandler.bind(this)),t.addEventListener("click",this.zoomOutBtnClickHandler.bind(this)),e.addEventListener("touchstart",this.zoomInBtnClickHandler.bind(this)))},s.prototype.widthPress=function(e){if(109===e.keyCode)return void e.preventDefault()},s.prototype.heightPress=function(e){if(109===e.keyCode)return void e.preventDefault()},s.prototype.widthAspectRatio=function(e){if(109!==e.keyCode&&9!==e.keyCode){var o=this.parent,i=o.element.id,r=o.element.querySelector("#"+i+"_resizeHeight"),a=o.element.querySelector("#"+i+"_resizeWidth"),n=o.element.querySelector("#"+i+"_aspectratio"),s=o.img.destWidth,l=o.img.destHeight,p=parseFloat(r.value)/(l/s),h=p%1>=.5||p%1<=-.5?Math.round(p):p<0?Math.ceil(p):Math.floor(p),d=t.getComponent(a,"numerictextbox"),c=t.getComponent(a,"numerictextbox");n&&(null==h||isNaN(h)?t.isNullOrUndefined(d.value)?(d.placeholder="0 px",a.placeholder="0 px",t.isNullOrUndefined(c.value)&&!t.isNullOrUndefined(c.placeholder)&&(d.placeholder=""+o.img.srcWidth,a.placeholder=""+o.img.srcWidth)):(d.value=0,a.value="0 px"):t.isNullOrUndefined(d.value)?(d.placeholder=h+" px",a.placeholder=h.toString()+" px"):(d.value=h,a.value=h.toString()+" px"))}},s.prototype.heightAspectRatio=function(e){if(109!==e.keyCode&&9!==e.keyCode){var o=this.parent,i=o.element.id,r=o.element.querySelector("#"+i+"_resizeHeight"),a=o.element.querySelector("#"+i+"_resizeWidth"),n=o.element.querySelector("#"+i+"_aspectratio"),s=o.img.destWidth,l=o.img.destHeight,p=parseFloat(a.value)/(s/l),h=p%1>=.5||p%1<=-.5?Math.round(p):p<0?Math.ceil(p):Math.floor(p),d=t.getComponent(r,"numerictextbox"),c=t.getComponent(a,"numerictextbox");n&&(isNaN(h)?t.isNullOrUndefined(d.value)?(d.placeholder="0 px",r.placeholder="0 px",t.isNullOrUndefined(c.value)&&!t.isNullOrUndefined(c.placeholder)&&(d.placeholder=""+o.img.srcHeight,r.placeholder=""+o.img.srcHeight)):(d.value=0,r.value="0 px"):t.isNullOrUndefined(d.value)?(d.placeholder=h+" px",r.placeholder=h.toString()+" px"):(d.value=h,r.value=h.toString()+" px"))}},s.prototype.getResizeToolbarItem=function(){var e=this.parent,o=e.element.id,r=!(!e.aspectWidth||!e.aspectHeight),a=this.parent.transform.degree%90==0&&this.parent.transform.degree%180!=0?Math.ceil(this.parent.img.srcHeight).toString():Math.ceil(this.parent.img.srcWidth).toString(),n=this.parent.transform.degree%90==0&&this.parent.transform.degree%180!=0?Math.ceil(this.parent.img.srcWidth).toString():Math.ceil(this.parent.img.srcHeight).toString(),s=[],l=document.createElement("span");l.innerHTML=this.l10n.getConstant("W"),s.push({id:o+"_width",cssClass:"e-ie-resize-width",template:l,align:"Center"}),s.push({id:o+"_resizeWidth",prefixIcon:"e-icons e-anti-clock-wise",tooltipText:this.l10n.getConstant("Width"),align:"Center",type:"Input",template:new i.NumericTextBox({width:75,htmlAttributes:{maxLength:"4"},showSpinButton:!1,value:r?e.aspectWidth:null,placeholder:r?null:a,format:"###.## px"})});var p=document.createElement("span");return p.innerHTML=this.l10n.getConstant("H"),s.push({id:o+"_height",cssClass:"e-ie-resize-height",template:p,align:"Center"}),s.push({id:o+"_resizeHeight",prefixIcon:"e-icons e-clock-wise",tooltipText:this.l10n.getConstant("Height"),align:"Center",type:"Input",template:new i.NumericTextBox({width:75,htmlAttributes:{maxLength:"4"},showSpinButton:!1,value:r?e.aspectHeight:null,placeholder:r?null:n,format:"###.## px"})}),this.isAspectRatio?(s.push({id:o+"_nonaspectratio",prefixIcon:"e-icons e-unlock",align:"Center",tooltipText:this.l10n.getConstant("AspectRatio"),type:"Button"}),this.isAspectRatio=!1):(s.push({id:o+"_aspectratio",prefixIcon:"e-icons e-lock",align:"Center",tooltipText:this.l10n.getConstant("AspectRatio"),type:"Button",tabIndex:0}),this.isAspectRatio=!0),t.Browser.isDevice||(s.push({id:o+"_ok",prefixIcon:"e-icons e-check",cssClass:"top-icon e-tick",tooltipText:this.l10n.getConstant("OK"),align:"Right",tabIndex:0}),s.push({id:o+"_cancel",prefixIcon:"e-icons e-close",cssClass:"top-icon e-save",tooltipText:this.l10n.getConstant("Cancel"),align:"Right"})),s},s.prototype.initResizeToolbar=function(){var e=this,o=this.parent,i=o.element.id,a=this.getLeftToolbarItem(!1,!0),n=this.getRightToolbarItem(),s=this.getResizeToolbarItem(),l=this.getZoomToolbarItem();t.Browser.isDevice?this.defToolbarItems=s:this.defToolbarItems=a.concat(l,s,n);var p={toolbarType:"resize",toolbarItems:this.defToolbarItems};o.trigger("toolbarUpdating",p),this.defToolbarItems=p.toolbarItems;var h=new r.Toolbar({width:"100%",items:this.defToolbarItems,clicked:this.defToolbarClicked.bind(this),created:function(){e.wireResizeBtnEvents(),o.trigger("toolbarCreated",{toolbarType:"shapes"}),t.Browser.isDevice?e.defToolbarItems.length>0&&!t.isNullOrUndefined(document.getElementById(i+"_bottomToolbar"))&&h.refreshOverflow():(e.createLeftToolbarControls(),e.defToolbarItems.length>0&&!t.isNullOrUndefined(document.getElementById(i+"_toolbar"))&&h.refreshOverflow())}});t.Browser.isDevice?h.appendTo("#"+i+"_bottomToolbar"):h.appendTo("#"+i+"_toolbar"),o.isResize=!1,this.enableDisableTbrBtn(),o.isResize=!0,o.notify("transform",{prop:"disableZoomOutBtn",value:{isZoomOut:!0}})},s.prototype.wireResizeBtnEvents=function(){var e=this.parent,o=e.element.id,i=e.element.querySelector("#"+o+"_resizeHeight"),r=e.element.querySelector("#"+o+"_resizeWidth");t.isNullOrUndefined(i)||(i.addEventListener("keydown",this.widthPress.bind(this)),r.addEventListener("keyup",this.heightAspectRatio.bind(this))),t.isNullOrUndefined(r)||(r.addEventListener("keydown",this.heightPress.bind(this)),i.addEventListener("keyup",this.widthAspectRatio.bind(this)))},s.prototype.enableDisableTbrBtn=function(){var e=this.parent,t=e.element.id;if(!this.preventEnableDisableUr){var o={appliedUndoRedoColl:[]};e.notify("undo-redo",{prop:"getAppliedUndoRedoColl",value:{obj:o}});var i={undoRedoStep:null};e.notify("undo-redo",{prop:"getUndoRedoStep",value:{obj:i}});var r=e.element.querySelector("#"+t+"_undo");r&&0===i.undoRedoStep?(r.classList.add("e-disabled"),r.parentElement.classList.add("e-overlay")):r&&i.undoRedoStep>0&&(r.classList.remove("e-disabled"),r.parentElement.classList.remove("e-overlay"));var a=e.element.querySelector("#"+t+"_redo");a&&i.undoRedoStep===o.appliedUndoRedoColl.length?(a.classList.add("e-disabled"),a.parentElement.classList.add("e-overlay")):a&&0===i.undoRedoStep&&o.appliedUndoRedoColl.length>0?(a.classList.remove("e-disabled"),a.parentElement.classList.remove("e-overlay")):a&&i.undoRedoStep>0&&(a.classList.remove("e-disabled"),a.parentElement.classList.remove("e-overlay"))}var n=document.querySelector("#"+t+"_zoomIn");n&&e.zoomSettings.zoomFactor>=e.zoomSettings.maxZoomFactor?(n.classList.add("e-disabled"),n.parentElement.classList.add("e-overlay")):n&&(n.classList.remove("e-disabled"),n.parentElement.classList.remove("e-overlay"));var s=document.querySelector("#"+t+"_zoomOut");s&&e.zoomSettings.zoomFactor<=e.zoomSettings.minZoomFactor?(s.classList.add("e-disabled"),s.parentElement.classList.add("e-overlay")):s&&(s.classList.remove("e-disabled"),s.parentElement.classList.remove("e-overlay"));var l=document.querySelector("#"+t+"_frame");l&&(e.currSelectionPoint&&"crop-circle"===e.currSelectionPoint.shape||e.isCircleCrop)?l.classList.add("e-overlay"):l&&l.classList.remove("e-overlay");var p=document.querySelector("#"+t+"_aspectratio");p&&(e.currSelectionPoint&&"crop-circle"===e.currSelectionPoint.shape||e.isCircleCrop)?p.classList.add("e-overlay"):p&&p.classList.remove("e-overlay")},s.prototype.createLeftToolbarControls=function(){var e=this.parent,t=e.element.id;if(void 0!==this.defToolbarItems&&this.defToolbarItems.length>0&&document.getElementById(t+"_toolbar")){var o=document.getElementById(t+"_toolbar").querySelector(".e-image-upload");if(o){var i=o.getElementsByTagName("input")[0],r=o.getElementsByTagName("button")[0];r.className="e-tbar-btn e-tbtn-txt top-icon",r.innerHTML="",r.title=this.l10n.getConstant("Browse"),r.appendChild(e.createElement("span",{className:"e-btn-icon e-icons e-upload-icon e-icon-left"})),i.onchange=this.fileSelect.bind(this,i)}}},s.prototype.fileSelect=function(e,t){var o=e.files[0].type.split("/")[1],i=["png","jpg","jpeg","svg","svg+xml"];this.fileName=e.files[0].name.split(".")[0],this.parent.notify("toolbar",{prop:"setInitialSize",value:{value:e.files[0].size}}),i.indexOf(o)>-1?this.parent.notify("draw",{prop:"fileSelect",value:{inputElement:e,args:t}}):this.parent.showDialogPopup()},s.prototype.triggerTbarClickEvent=function(e){var t={item:e.item,originalEvent:e.event};this.parent.trigger("toolbarItemClicked",t)},s.prototype.renderAnnotationBtn=function(o){var i=this,r=this.parent,a=!1,s=[],l=r.element.id,p=["Ellipse","Arrow","Line","Rectangle","Pen","Path","Text","Image"];if(r.toolbar)for(var h=0;h<p.length;h++)if(-1!==r.toolbar.indexOf(p[h])){a=!0;break}(t.isNullOrUndefined(r.toolbar)||!a||r.toolbar&&r.toolbar.indexOf("Pen")>-1)&&s.push({text:this.l10n.getConstant("Pen"),id:"pen",iconCss:"e-icons e-free-pen"}),(t.isNullOrUndefined(r.toolbar)||!a||r.toolbar&&r.toolbar.indexOf("Line")>-1)&&s.push({text:this.l10n.getConstant("Line"),id:"line",iconCss:"e-icons e-line"}),(t.isNullOrUndefined(r.toolbar)||!a||r.toolbar&&r.toolbar.indexOf("Rectangle")>-1)&&s.push({text:this.l10n.getConstant("Rectangle"),id:"rectangle",iconCss:"e-icons e-rectangle"}),(t.isNullOrUndefined(r.toolbar)||!a||r.toolbar&&r.toolbar.indexOf("Ellipse")>-1)&&s.push({text:this.l10n.getConstant("Ellipse"),id:"ellipse",iconCss:"e-icons e-circle"}),(t.isNullOrUndefined(r.toolbar)||!a||r.toolbar&&r.toolbar.indexOf("Arrow")>-1)&&s.push({text:this.l10n.getConstant("Arrow"),id:"arrow",iconCss:"e-icons e-arrow-right-up"}),(t.isNullOrUndefined(r.toolbar)||!a||r.toolbar&&r.toolbar.indexOf("Path")>-1)&&s.push({text:this.l10n.getConstant("Path"),id:"path",iconCss:"e-icons e-critical-path"}),(t.isNullOrUndefined(r.toolbar)||!a||r.toolbar&&r.toolbar.indexOf("Text")>-1)&&s.push({text:this.l10n.getConstant("Text"),id:"text",iconCss:"e-icons e-add-text"}),(t.isNullOrUndefined(r.toolbar)||!a||r.toolbar&&r.toolbar.indexOf("Image")>-1)&&s.push({text:this.l10n.getConstant("Image"),id:"image",iconCss:"e-icons e-image"});var d={freehandDrawSelectedId:null};r.notify("freehand-draw",{prop:"getFreehandDrawSelectedId",onPropertyChange:!1,value:{obj:d}});var c=t.Browser.isDevice?"#"+l+"_bottomToolbar #"+l:"#"+l;this.enableDisableCloneBtn(c,d);var u=o?this.getCurrentShapeIcon(r.activeObj.shape):"e-annotation",v=new n.DropDownButton({items:s,iconCss:"e-icons "+u,cssClass:"e-image-popup",open:function(e){(r.currObjType.isFiltered||r.currObjType.isRedact)&&(r.okBtn(),r.element.querySelector("#"+l+"_annotationBtn").click()),t.Browser.isDevice&&(e.element.parentElement.style.top=v.element.getBoundingClientRect().top-e.element.parentElement.offsetHeight+"px"),r.activeObj.shape?document.getElementById(r.activeObj.shape).classList.add("e-selected"):r.togglePen&&document.getElementById("pen").classList.add("e-selected")},select:function(t){r.noPushUndo=!1,i.triggerTbarClickEvent(t),r.okBtn();var o,a=!1;void 0!==r.activeObj.shape&&(o=r.activeObj.shape.split("-")),void 0===o&&r.currObjType.isCustomCrop?a=!0:void 0!==o&&"crop"===o[0]&&(a=!0),r.currObjType.isCustomCrop=!1,(a||r.togglePan)&&(r.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),i.upperContext.clearRect(0,0,r.upperCanvas.width,r.upperCanvas.height),i.refreshToolbar("main"));var n={currentFreehandDrawIndex:null};r.notify("freehand-draw",{prop:"getCurrentFreehandDrawIndex",value:{obj:n}});var s,p,h={shapeSettingsObj:{}},d=["ellipse","rectangle","text","image"];v.iconCss="e-icons "+i.getCurrentShapeIcon(t.item.id),r.notify("draw",{prop:"updateTempObjColl"}),r.notify("draw",{prop:"updateTempPointColl"});var c={penStrokeWidth:2};switch(t.item.id){case"pen":r.notify("freehand-draw",{prop:"getPenStrokeWidth",onPropertyChange:!1,value:{obj:c}}),r.notify("draw",{prop:"setTempStrokeWidth",value:{strokeWidth:c.penStrokeWidth}}),r.drawingShape=null,r.notify("draw",{prop:"setTempFreehandCounter",value:{tempFreehandCounter:r.freehandCounter}}),r.notify("draw",{prop:"setTempCurrentFreehandDrawIndex",value:{tempCurrentFreehandDrawIndex:n.currentFreehandDrawIndex}}),i.currentToolbar="pen",r.freeHandDraw(!0),r.notify("selection",{prop:"updatePrevShapeSettings",onPropertyChange:!1,value:{obj:h}}),s=h.shapeSettingsObj,r.notify("freehand-draw",{prop:"getPenStrokeWidth",onPropertyChange:!1,value:{obj:c}}),s.strokeWidth=c.penStrokeWidth,s.type=e.ShapeType.FreehandDraw,p={cancel:!1,action:"insert",previousShapeSettings:s,currentShapeSettings:s},r.notify("freehand-draw",{prop:"triggerShapeChanging",value:{shapeChangingArgs:p}});break;case"text":i.currentToolbar="text",r.drawingShape=t.item.id,i.currentToolbar="text",i.setInitialShapeSettings(t),r.notify("selection",{prop:"annotate",value:{shape:t.item.id}}),r.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"text",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}});break;case"image":r.drawingShape=null,i.currentToolbar="shapes",r.element.querySelector("#"+l+"_fileUpload").click();break;case"ellipse":case"arrow":case"line":case"rectangle":case"path":r.drawingShape=t.item.id,i.currentToolbar="shapes",i.setInitialShapeSettings(t),r.notify("selection",{prop:"annotate",value:{shape:t.item.id}}),r.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"shapes",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}}),r.notify("selection",{prop:"updatePrevShapeSettings",onPropertyChange:!1,value:{obj:h}}),p={cancel:!1,action:"insert",previousShapeSettings:s=h.shapeSettingsObj,currentShapeSettings:s,allowShapeOverflow:-1===d.indexOf(i.parent.activeObj.shape)},r.trigger("shapeChanging",p),r.editCompleteArgs=p,r.notify("shape",{prop:"updateShapeChangeEventArgs",value:{shapeSettings:p.currentShapeSettings}})}i.updateToolbarItems();var u=r.togglePen;"pen"===t.item.id&&(r.togglePen=!1),r.notify("draw",{prop:"redrawDownScale"}),r.togglePen=u}});v.appendTo("#"+l+"_annotationBtn")},s.prototype.enableDisableCloneBtn=function(e,o){var i=this.parent,r=!1;i.activeObj.shape&&"text"===i.activeObj.shape&&11===i.activeObj.textSettings.fontSize&&55===Math.floor(i.activeObj.activePoint.width)&&11===Math.floor(i.activeObj.activePoint.height)&&(r=!0);var a=document.querySelector(e+"_duplicate"),n=document.querySelector(e+"_remove"),s=document.querySelector(e+"_editText"),l=document.querySelector(e+"_zOrderBtn");r||0===i.activeObj.activePoint.width&&0===i.activeObj.activePoint.height&&(t.isNullOrUndefined(i.activeObj.pointColl)||i.activeObj.pointColl&&0===i.activeObj.pointColl.length)&&t.isNullOrUndefined(o.freehandDrawSelectedId)?(a&&a.classList.add("e-overlay"),n&&n.classList.add("e-overlay"),s&&s.classList.add("e-overlay"),l&&l.classList.add("e-overlay")):(a&&a.classList.remove("e-overlay"),n&&n.classList.remove("e-overlay"),s&&s.classList.remove("e-overlay"),l&&l.classList.remove("e-overlay"))},s.prototype.renderStraightenSlider=function(){var e=this.parent,o=e.element.id;if((t.isNullOrUndefined(e.toolbar)||e.toolbar&&e.toolbar.indexOf("Straightening")>-1)&&e.element.querySelector("#"+o+"_straightenSlider")){var i=this.createSlider(-45,45,e.cropObj.straighten,"straighten");i.appendTo("#"+o+"_straightenSlider");var r=i.element.querySelector(".e-handle");r&&!t.Browser.isDevice&&(r.addEventListener("mousedown",function(e){e.preventDefault(),e.stopPropagation()}),r.addEventListener("touchstart",function(e){e.preventDefault(),e.stopPropagation()}))}},s.prototype.renderCropBtn=function(e){var o=this,i=this.parent,r=[],a=!1,s=["CustomSelection","CircleSelection","SquareSelection","RatioSelection"];if(i.toolbar)for(var l=0;l<s.length;l++)if(-1!==i.toolbar.indexOf(s[l])){a=!0;break}(t.isNullOrUndefined(i.toolbar)||!a||i.toolbar&&i.toolbar.indexOf("CustomSelection")>-1)&&r.push({text:this.l10n.getConstant("Custom"),id:"custom",iconCss:"e-icons e-custom"}),(t.isNullOrUndefined(i.toolbar)||!a||i.toolbar&&i.toolbar.indexOf("CircleSelection")>-1)&&r.push({text:this.l10n.getConstant("Circle"),id:"circle",iconCss:"e-icons e-circle"}),(t.isNullOrUndefined(i.toolbar)||!a||i.toolbar&&i.toolbar.indexOf("SquareSelection")>-1)&&r.push({text:this.l10n.getConstant("Square"),id:"square",iconCss:"e-icons e-square"}),(t.isNullOrUndefined(i.toolbar)||!a||i.toolbar&&i.toolbar.indexOf("RatioSelection")>-1)&&(r.push({text:"2:3",id:"2:3",iconCss:"e-icons e-custom-f"}),r.push({text:"3:2",id:"3:2",iconCss:"e-icons e-custom-a"}),r.push({text:"3:4",id:"3:4",iconCss:"e-icons e-custom-g"}),r.push({text:"4:3",id:"4:3",iconCss:"e-icons e-custom-b"}),r.push({text:"4:5",id:"4:5",iconCss:"e-icons e-custom-h"}),r.push({text:"5:4",id:"5:4",iconCss:"e-icons e-custom-c"}),r.push({text:"5:7",id:"5:7",iconCss:"e-icons e-custom-i"}),r.push({text:"7:5",id:"7:5",iconCss:"e-icons e-custom-d"}),r.push({text:"9:16",id:"9:16",iconCss:"e-icons e-custom-j"}),r.push({text:"16:9",id:"16:9",iconCss:"e-icons e-custom-e"}));var p,h;e?(p=this.getCurrentShapeIcon(e),h=e):i.activeObj.shape&&(0!==i.activeObj.activePoint.width||0!==i.activeObj.activePoint.height)||"path"===i.activeObj.shape&&i.activeObj.pointColl.length>0?(p=this.getCurrentShapeIcon(i.activeObj.shape),h=i.activeObj.shape):i.currSelectionPoint?(p=this.getCurrentShapeIcon(i.currSelectionPoint.shape),h=i.currSelectionPoint.shape):(p=r[0].iconCss,h=r[0].id);var d=new n.DropDownButton({open:function(e){if(i.togglePan&&o.cancelPan(),t.Browser.isDevice&&(e.element.parentElement.style.top=d.element.getBoundingClientRect().top-e.element.parentElement.offsetHeight+"px"),i.activeObj.shape&&i.activeObj.shape.split("-").length>1){var r=document.getElementById(i.activeObj.shape.split("-")[1]);r&&(r.classList.add("e-selected"),r.focus())}i.notify("transform",{prop:"disableZoomOutBtn",value:{isZoomOut:!0}})},items:r,select:function(e){o.triggerTbarClickEvent(e),o.cropSelect(e),d.iconCss="e-icons "+o.getCurrentShapeIcon("crop-"+e.item.id),d.content=t.Browser.isDevice?null:i.toPascalCase(e.item.id)},iconCss:"e-icons "+p,cssClass:"e-image-popup e-ie-crop-ddb-popup",content:t.Browser.isDevice?null:i.toPascalCase(h.replace("crop-",""))});d.appendTo("#"+i.element.id+"_cropBtn")},s.prototype.renderTransformBtn=function(){var e=this,o=this.parent,i=[];(t.isNullOrUndefined(o.toolbar)||o.toolbar&&o.toolbar.indexOf("RotateLeft")>-1)&&i.push({text:this.l10n.getConstant("RotateLeft"),id:"rotateleft",iconCss:"e-icons e-anti-clock-wise"}),(t.isNullOrUndefined(o.toolbar)||o.toolbar&&o.toolbar.indexOf("RotateRight")>-1)&&i.push({text:this.l10n.getConstant("RotateRight"),id:"rotateright",iconCss:"e-icons e-clock-wise"}),(t.isNullOrUndefined(o.toolbar)||o.toolbar&&o.toolbar.indexOf("FlipHorizontal")>-1)&&i.push({text:this.l10n.getConstant("HorizontalFlip"),id:"horizontalflip",iconCss:"e-icons e-horizontal-flip"}),(t.isNullOrUndefined(o.toolbar)||o.toolbar&&o.toolbar.indexOf("FlipVertical")>-1)&&i.push({text:this.l10n.getConstant("VerticalFlip"),id:"verticalflip",iconCss:"e-icons e-vertical-flip"});var r=new n.DropDownButton({open:function(e){if(t.Browser.isDevice){var o=e.element.parentElement,i=o.offsetHeight;o.style.display="none",o.style.top=r.element.getBoundingClientRect().top-i+"px",o.style.display="block"}},items:i,select:function(t){e.triggerTbarClickEvent(t),o.transformSelect.bind(e)},iconCss:"e-icons e-transform",cssClass:"e-image-popup"});r.appendTo("#"+o.element.id+"_transformBtn")},s.prototype.saveDialogPopup=function(){var e=this,i=this.parent,r=i.element.id,a=["Good","Great","Highest"];i.element.appendChild(i.createElement("div",{id:r+"_saveDialog"}));var n=i.createElement("div",{id:r+"_dialogContent",attrs:{style:"display: flex;"}}),s=n.appendChild(i.createElement("div",{id:r+"_dialogImgContent",className:"e-ie-dlg-img-content"}));s.appendChild(i.createElement("canvas",{id:r+"_imgPic",className:"e-ie-img-dlg-canvas"})),s.appendChild(i.createElement("div",{id:r+"_imageNameContainer",className:"e-ie-img-size"})).appendChild(i.createElement("span",{id:r+"_imageNameLabel",className:"e-ie-quality-info"}));var l=n.appendChild(i.createElement("div",{id:r+"_dialogRightContent",className:"e-ie-dlg-right-content"})),p=l.appendChild(i.createElement("div",{id:r+"_namediv",className:"e-ie-img-save-name"}));p.appendChild(i.createElement("span",{id:r+"_labelImgname",className:"e-ie-img-label-name",innerHTML:this.l10n.getConstant("ImageName")})),p.appendChild(i.createElement("input",{id:r+"_imgNametext",className:"e-ie-img-input",attrs:{type:"text"}}));var h=l.appendChild(i.createElement("div",{id:r+"_imgNamediv",className:"e-ie-img-save-dlg"}));h.appendChild(i.createElement("span",{id:r+"_labelname",className:"e-ie-img-label-name",innerHTML:this.l10n.getConstant("Format")})),h.appendChild(i.createElement("button",{id:r+"_saveDropdownbtn",attrs:{tabindex:"1"}}));var d=l.appendChild(i.createElement("div",{id:r+"_imgQualitydiv",className:"e-ie-img-quality-name"})),c=i.createElement("div",{id:r+"_qualityContainer"});c.appendChild(i.createElement("span",{id:r+"_qualityLabel",className:"e-ie-img-quality-label",innerHTML:this.l10n.getConstant("Quality")})),c.appendChild(i.createElement("span",{id:r+"_qualityInfo",className:"e-circle-info e-icons e-ie-quality-span",attrs:{title:this.l10n.getConstant("QualityInfo")}})),c.appendChild(i.createElement("div",{id:r+"_imgsizeSpan",className:"e-ie-img-size-value-span"})).appendChild(i.createElement("span",{id:r+"_imgsizeValueSpan",className:""})),d.appendChild(c);var u=i.createElement("div",{id:r+"_qualityOptionContainer",className:"e-ie-quality-option-container"}),v=d.appendChild(i.createElement("div",{id:r+"_qualityButtonGroup",className:"e-btn-group"}));a.forEach(function(t){var o=document.createElement("input");o.type="radio",o.id=r+"_"+t.toLowerCase(),o.name="quality",o.value=t.toLowerCase();var i=document.createElement("label");i.className="e-btn",i.htmlFor=t.toLowerCase(),i.textContent=e.l10n.getConstant(t),v.appendChild(o),v.appendChild(i)}),u.appendChild(v),u.appendChild(i.createElement("div",{id:r+"_qualitySlider",className:"e-ie-img-quality-slider"})),u.appendChild(i.createElement("button",{id:r+"_qualitybuttonIcon",className:"e-ie-img-icon-button",attrs:{type:"button"}})),d.appendChild(u),t.Browser.isDevice&&d.appendChild(i.createElement("span",{id:r+"_qualitySize",className:"e-ie-img-quality-size"})),i.element.querySelector("#"+r+"_saveDialog").style.display="block",i.element.appendChild(n);var g=new o.Dialog({target:i.element,header:this.l10n.getConstant("SaveAs"),closeOnEscape:!0,content:document.getElementById(r+"_dialogContent"),width:t.Browser.isDevice?"345px":"570px",isModal:!0,animationSettings:{effect:"Zoom"},beforeOpen:this.onBeforeopen(),close:this.saveDialogClosed.bind(this,r),cssClass:"e-ie-save-dialog",buttons:[{click:function(){g.hide()},buttonModel:{content:this.l10n.getConstant("Close"),cssClass:"e-save-cancel-btn"}},{click:function(){e.download(),g.hide(),e.isSlider=!1},buttonModel:{isPrimary:!0,content:this.l10n.getConstant("Download"),cssClass:"e-flat e-save-download-btn"}}]});g.appendTo("#"+r+"_saveDialog")},s.prototype.saveDialogClosed=function(e){t.getComponent(document.getElementById(e+"_saveDropdownbtn"),"dropdownbutton")&&t.getComponent(document.getElementById(e+"_saveDropdownbtn"),"dropdownbutton").destroy(),this.isSlider=!1,document.querySelector("#"+e+"_qualityButtonGroup")&&document.querySelector("#"+e+"_qualitySlider")&&(document.querySelector("#"+e+"_qualityButtonGroup").remove(),document.querySelector("#"+e+"_qualitySlider").remove(),document.querySelector("#"+e+"_imgsizeValueSpan").remove(),document.querySelector("#"+e+"_imageNameLabel").remove(),document.querySelector("#"+e+"_imgsizeSpan").remove()),document.getElementById(e+"_dialogContent").remove(),t.getComponent(document.getElementById(e+"_saveDialog"),"dialog").destroy(),document.getElementById(e+"_saveDialog").remove()},s.prototype.onBeforeopen=function(){var e=this,o=this.parent,r=o.element.id,s={canvas:null},l=[{id:"jpeg",text:"JPEG"},{id:"png",text:"PNG"},{id:"svg",text:"SVG"}];new i.TextBox({placeholder:this.l10n.getConstant("ImageName")}).appendTo("#"+r+"_imgNametext");var p,h=document.getElementById(r+"_imgQualitydiv"),d=document.getElementById(r+"_qualitySlider"),c=document.querySelector("#"+r+"_qualityButtonGroup"),u=document.querySelector("#"+r+"_qualitybuttonIcon"),v=document.querySelector("#"+r+"_imgsizeSpan");p=t.Browser.isDevice?document.getElementById(r+"_qualitySize"):document.getElementById(r+"_imageNameLabel");var g={fileName:"",fileType:""};o.notify("draw",{prop:"getFileName",onPropertyChange:!1,value:{obj:g}}),this.fileType=g.fileType?g.fileType:"JPEG",o.notify("export",{prop:"exportToCanvas",value:{object:s}});var f=s.canvas,C=document.getElementById(r+"_imgPic");C.width=f.width,C.height=f.height,new a.Button({iconCss:"e-icons e-settings"}).appendTo("#"+r+"_qualitybuttonIcon");var b=document.getElementById(r+"_saveDropdownbtn");if(b){var m=document.createElement("span");m.innerHTML=this.fileType.toUpperCase(),b&&b.appendChild(m);var y=new n.DropDownButton({items:l,open:function(e){t.Browser.isDevice&&(e.element.parentElement.style.top=y.element.getBoundingClientRect().top-e.element.parentElement.offsetHeight+"px");var o=m.innerHTML;""!==o&&e.element.querySelector('[aria-label = "'+o+'"]').classList.add("e-selected-btn")},select:function(o){v.style.display="none",e.fileType=m.innerHTML=o.item.text,"jpeg"!==o.item.id?(h.style.display="none",p.style.display="block",e.updateImageSize(1,s.canvas,e.fileType),d&&(e.isSlider&&t.getComponent(d,"slider").destroy(),d.style.display="none"),e.isSlider=!1):(h.style.display="block",t.removeClass([c],"e-hide"),d.style.display="none",p.style.display="block",e.updateImageSize(t.isNullOrUndefined(e.currentQuality)?1:e.currentQuality,s.canvas,e.fileType),document.getElementById(r+"_"+e.imageQuality).checked=!0)}});y.appendTo("#"+r+"_saveDropdownbtn"),document.getElementById(r+"_imgNametext").value=this.fileName?this.fileName:g.fileName,g.fileType&&"JPEG"!==g.fileType.toUpperCase()&&(h.style.display="none",v.style.display="none"),t.Browser.isDevice?(document.getElementById(r+"_dialogImgContent").style.display="none",document.getElementById(r+"_dialogRightContent").style.width="100%",this.updateImageSize(1,s.canvas,this.fileType)):this.updateImageSize(1,s.canvas,this.fileType)}document.getElementById(r+"_"+this.imageQuality).checked=!0,c.addEventListener("click",this.qualityBtnClickHandler.bind(this)),u.addEventListener("click",this.qualityBtnClickHandler.bind(this))},s.prototype.qualityBtnClickHandler=function(e){var o=this,r=this.parent,a=r.element.id,n=e.target,s={fileName:""},l={canvas:null},p={Good:.8,Great:.9,Highest:1},h=document.querySelector("#"+a+"_qualityButtonGroup"),d=document.querySelector("#"+a+"_qualitySlider"),c=document.querySelector("#"+a+"_qualityOptionContainer"),u=document.querySelector("#"+a+"_imgsizeSpan"),v=document.querySelector("#"+a+"_imgsizeValueSpan");if(r.notify("draw",{prop:"getFileName",onPropertyChange:!1,value:{obj:s}}),r.notify("export",{prop:"exportToCanvas",value:{object:l}}),e.currentTarget.id!==a+"_qualitybuttonIcon"||this.isSlider)e.currentTarget.id===a+"_qualitybuttonIcon"&&this.isSlider?(t.getComponent(d,"slider").destroy(),d.style.display="none",u.style.display="none",t.removeClass([h],"e-hide"),c.style.display="block",this.isSlider=!1):p.hasOwnProperty(n.textContent)&&!this.isSlider&&(e.target.previousElementSibling.checked=!0,this.currentQuality=p[n.textContent],this.imageQuality=n.textContent.toLowerCase(),this.updateImageSize(p[n.textContent],l.canvas,"jpeg"));else{t.addClass([h],"e-hide"),d.style.display="block",u.style.display="inline-block",c.style.display="flex";var g=new i.Slider({tooltip:{placement:"Before",isVisible:!0,format:"P0",showOn:"Focus"},min:.01,max:1,step:.01,value:this.currentQuality,type:"MinRange",width:t.Browser.isDevice?"80%":"190px",created:function(){o.updateImageSize(o.currentQuality,l.canvas,"jpeg"),v.innerHTML=Math.round(100*o.currentQuality).toString()},changed:function(e){o.currentQuality=e.value,v.innerHTML=Math.round(100*o.currentQuality).toString(),r.notify("export",{prop:"setImageQuality",value:{value:e.value}}),o.updateImageSize(e.value,l.canvas,"jpeg")}});g.appendTo("#"+a+"_qualitySlider"),g.element.parentElement.classList.add("e-ie-quality-slider"),this.isSlider=!0}},s.prototype.updateImageSize=function(e,o,i){var r,a,n=this.parent.element.id,s=document.getElementById(n+"_imgPic"),l=s.getContext("2d");if(a=t.Browser.isDevice?document.getElementById(n+"_qualitySize"):document.getElementById(n+"_imageNameLabel"),"jpeg"===i.toLowerCase())o.toBlob(function(e){if((r=Math.floor(e.size/1024))>1e3){var o=r/1024;a.innerHTML="Image size: "+o.toFixed(2)+" MB",r=+o.toFixed(2)}else a.innerHTML="Image size: "+r.toFixed(2)+" KB",r=+r.toFixed(2);if(t.Browser.isDevice)s.style.display="none";else{var i=new Image;i.src=URL.createObjectURL(e),i.onload=function(){l.drawImage(i,0,0),URL.revokeObjectURL(i.src)}}this.fileSize=r}.bind(this),"image/jpeg",e);else if(t.Browser.isDevice)s.style.display="none";else if(l.drawImage(o,0,0),this.initialSize>1e3){var p=this.initialSize/1048576;a.innerHTML=this.l10n.getConstant("ImageSize")+": "+p.toFixed(2)+" MB"}else a.innerHTML=this.l10n.getConstant("ImageSize")+": "+this.initialSize.toFixed(2)+" KB"},s.prototype.download=function(){var e=this.parent,o=e.element.id;if("JPEG"===this.fileType&&this.isSlider){var i=t.getComponent(document.getElementById(o+"_qualitySlider"),"slider").value;e.notify("export",{prop:"setImageQuality",value:{value:i}})}else e.notify("export",{prop:"setImageQuality",value:{value:this.currentQuality}});var r=document.getElementById(o+"_imgNametext").value;e.export(this.fileType,r)},s.prototype.getCropTransformToolbarItem=function(){var e=this.parent,o=e.element.id,i=[];if(i.push({id:o+"_crop",tooltipText:this.l10n.getConstant("CropSelection"),align:"Center",template:'<button id="'+o+'_cropBtn"></button>'}),i.push({align:"Center",type:"Separator"}),(t.isNullOrUndefined(e.toolbar)||e.toolbar&&(e.toolbar.indexOf("Transform")>-1||e.toolbar.indexOf("RotateLeft")>-1))&&i.push({id:o+"_rotateLeft",prefixIcon:"e-icons e-anti-clock-wise",tooltipText:this.l10n.getConstant("RotateLeft"),align:"Center"}),(t.isNullOrUndefined(e.toolbar)||e.toolbar&&(e.toolbar.indexOf("Transform")>-1||e.toolbar.indexOf("RotateRight")>-1))&&i.push({id:o+"_rotateRight",prefixIcon:"e-icons e-clock-wise",tooltipText:this.l10n.getConstant("RotateRight"),align:"Center"}),i.length>2&&i.push({align:"Center",type:"Separator"}),(t.isNullOrUndefined(e.toolbar)||e.toolbar&&(e.toolbar.indexOf("Transform")>-1||e.toolbar.indexOf("HorizontalFlip")>-1))&&i.push({id:o+"_horizontalFlip",prefixIcon:"e-icons e-horizontal-flip",tooltipText:this.l10n.getConstant("HorizontalFlip"),align:"Center"}),(t.isNullOrUndefined(e.toolbar)||e.toolbar&&(e.toolbar.indexOf("Transform")>-1||e.toolbar.indexOf("VerticalFlip")>-1))&&i.push({id:o+"_verticalFlip",prefixIcon:"e-icons e-vertical-flip",tooltipText:this.l10n.getConstant("VerticalFlip"),align:"Center"}),(t.isNullOrUndefined(e.toolbar)||e.toolbar&&e.toolbar.indexOf("Straightening")>-1)&&!t.Browser.isDevice&&(i.push({align:"Center",type:"Separator"}),t.isNullOrUndefined(e.toolbar)||e.toolbar&&(e.toolbar.indexOf("Straighten")>-1||e.toolbar.indexOf("Straighten")>-1))){var r=document.createElement("span");r.innerHTML=this.l10n.getConstant("Straighten"),i.push({id:o+"_straightenSpan",cssClass:"e-ie-straighten-span",template:r,align:"Center"}),i.push({id:o+"_straighten",cssClass:"top-icon e-straighten",tooltipText:this.l10n.getConstant("Straighten"),align:"Center",type:"Input",template:'<div id="'+o+'_straightenSlider"></div>'});var a=document.createElement("span");a.innerHTML=e.transform.straighten.toString()+"&#176",i.push({id:o+"_straightenSpan",cssClass:"e-ie-straighten-value-span",template:a,align:"Center"})}return t.Browser.isDevice||(i.push({id:o+"_ok",prefixIcon:"e-icons e-check",cssClass:"top-icon e-tick",tooltipText:this.l10n.getConstant("OK"),align:"Right",tabIndex:0}),i.push({id:o+"_cancel",prefixIcon:"e-icons e-close",cssClass:"top-icon e-save",tooltipText:this.l10n.getConstant("Cancel"),align:"Right"})),i},s.prototype.getShapesToolbarItem=function(e){var o=this.parent,i=o.element.id,r=[];(t.isNullOrUndefined(o.toolbar)||o.toolbar)&&r.push({id:i+"_annotation",tooltipText:this.l10n.getConstant("Annotation"),align:"Center",template:'<button id="'+i+'_annotationBtn"></button>'}),e.indexOf("fillColor")>-1&&r.push({prefixIcon:"e-icons e-copy",id:i+"_fillcolor",cssClass:"top-icon e-fill",tooltipText:this.l10n.getConstant("FillColor"),align:"Center",type:"Input",template:'<button id="'+i+'_fillColorBtn"></button>'}),e.indexOf("strokeColor")>-1&&r.push({prefixIcon:"e-icons e-copy",id:i+"_strokecolor",cssClass:"top-icon e-stroke",tooltipText:this.l10n.getConstant("StrokeColor"),align:"Center",type:"Input",template:'<button id="'+i+'_borderColorBtn"></button>'}),e.indexOf("strokeWidth")>-1&&r.push({id:i+"_strokeWidth",cssClass:"top-icon e-size",tooltipText:this.l10n.getConstant("StrokeWidth"),align:"Center",type:"Input",template:'<button id="'+i+'_borderWidthBtn"></button>'}),e.indexOf("start")>-1&&r.push({id:i+"_start",cssClass:"top-icon e-size",tooltipText:this.l10n.getConstant("Start"),align:"Center",type:"Input",template:'<button id="'+i+'_startBtn"></button>'}),e.indexOf("borderRadius")>-1&&r.push({id:i+"_rectangleRadius",cssClass:"top-icon e-size",tooltipText:this.l10n.getConstant("BorderRadius"),align:"Center",type:"Input",template:'<button id="'+i+'_rectangleRadiusBtn"></button>'}),e.indexOf("end")>-1&&r.push({id:i+"_end",cssClass:"top-icon e-size",tooltipText:this.l10n.getConstant("End"),align:"Center",type:"Input",template:'<button id="'+i+'_endBtn"></button>'}),e.indexOf("flip")>-1&&(r.push({id:i+"_rotLeft",prefixIcon:"e-anti-clock-wise",tooltipText:this.l10n.getConstant("RotateLeft"),align:"Center"}),r.push({id:i+"_rotRight",prefixIcon:"e-clock-wise",tooltipText:this.l10n.getConstant("RotateRight"),align:"Center"}),r.push({id:i+"_hFlip",prefixIcon:"e-horizontal-flip",tooltipText:this.l10n.getConstant("HorizontalFlip"),align:"Center"}),r.push({id:i+"_vFlip",prefixIcon:"e-vertical-flip",tooltipText:this.l10n.getConstant("VerticalFlip"),align:"Center"})),e.indexOf("transparency")>-1&&(r.push({align:"Center",type:"Separator"}),r.push({id:i+"_transparency",prefixIcon:"e-opacity",tooltipText:this.l10n.getConstant("Opacity"),align:"Center"})),r.push({align:"Center",type:"Separator"}),e.indexOf("z-order")>-1&&r.push({id:i+"_zOrder",cssClass:"top-icon e-list-unordered-3",tooltipText:this.l10n.getConstant("ZOrder"),align:"Center",type:"Input",template:'<button id="'+i+'_zOrderBtn"></button>'}),e.indexOf("duplicate")>-1&&r.push({id:i+"_duplicate",prefixIcon:"e-icons e-order",cssClass:"top-icon e-order",tooltipText:this.l10n.getConstant("Duplicate"),align:"Center"}),e.indexOf("remove")>-1&&r.push({id:i+"_remove",prefixIcon:"e-icons e-trash",cssClass:"top-icon e-trash",tooltipText:this.l10n.getConstant("Remove"),align:"Center"}),e.indexOf("text")>-1&&r.push({id:i+"_editText",prefixIcon:"e-icons e-annotation-edit",cssClass:"top-icon e-annotation-edit",tooltipText:this.l10n.getConstant("EditText"),align:"Center"});for(var a=this.processSubToolbar(e),n=0,s=a.length;n<s;n++)r.push(a[n]);if(!t.Browser.isDevice){var l={shape:null};o.notify("selection",{prop:"getCurrentDrawingShape",value:{obj:l}}),"path"!==l.shape&&(r.push({id:i+"_ok",prefixIcon:"e-icons e-check",cssClass:"top-icon e-tick",tooltipText:this.l10n.getConstant("OK"),align:"Right",tabIndex:0}),r.push({id:i+"_cancel",prefixIcon:"e-icons e-close",cssClass:"top-icon e-save",tooltipText:this.l10n.getConstant("Cancel"),align:"Right"}))}return r},s.prototype.initCropTransformToolbar=function(e,o){var i=this,a=this.parent,n=a.element.id,s=this.getLeftToolbarItem(),l=this.getRightToolbarItem(),p=this.getCropTransformToolbarItem(),h=this.getZoomToolbarItem();t.Browser.isDevice?this.defToolbarItems=p:this.defToolbarItems=s.concat(h,p,l);var d={toolbarType:"crop-transform",toolbarItems:this.defToolbarItems};a.trigger("toolbarUpdating",d),this.defToolbarItems=d.toolbarItems;var c=new r.Toolbar({width:"100%",items:this.defToolbarItems,clicked:this.defToolbarClicked.bind(this),created:function(){i.renderCropBtn(e),i.renderStraightenSlider(),i.wireZoomBtnEvents(),a.trigger("toolbarCreated",{toolbarType:"shapes"}),t.Browser.isDevice?i.defToolbarItems.length>0&&document.getElementById(n+"_bottomToolbar")&&(c.refreshOverflow(),c.refreshOverflow(),c.refreshOverflow()):(i.createLeftToolbarControls(),i.defToolbarItems.length>0&&document.getElementById(n+"_toolbar")&&c.refreshOverflow()),document.getElementById(n+"_cropBtn")&&t.isNullOrUndefined(o)&&(t.Browser.isDevice||a.notify("draw",{prop:"select",onPropertyChange:!1,value:{type:i.getCropTextContent(document.getElementById(n+"_cropBtn")).toLowerCase(),startX:null,startY:null,width:null,height:null}}))}});t.Browser.isDevice?c.appendTo("#"+n+"_bottomToolbar"):c.appendTo("#"+n+"_toolbar");var u=a.element.querySelector("#"+n+"_straightenSlider");(t.isNullOrUndefined(a.toolbar)||a.toolbar&&a.toolbar.indexOf("Straightening")>-1)&&u&&u.parentElement.clientHeight>this.toolbarHeight&&(this.toolbarHeight=a.toolbarHeight=u.parentElement.clientHeight),this.enableDisableTbrBtn(),a.notify("transform",{prop:"disableZoomOutBtn",value:{isZoomOut:!0}})},s.prototype.getCropTextContent=function(e){if(e){var t={"e-custom":"Custom","e-circle":"Circle","e-square":"Square","e-custom-a":"3:2","e-custom-b":"4:3","e-custom-c":"5:4","e-custom-d":"7:5","e-custom-e":"16:9","e-custom-f":"2:3","e-custom-g":"3:4","e-custom-h":"4:5","e-custom-i":"5:7","e-custom-j":"9:16"},o=e.children[0].classList;for(var i in t)if(o.contains(i))return t[i]}return""},s.prototype.getCurrentShapeIcon=function(e){var t={rectangle:"e-rectangle",ellipse:"e-circle",line:"e-line",arrow:"e-arrow-right-up",path:"e-critical-path",text:"e-add-text",image:"e-image",pen:"e-free-pen","crop-custom":"e-custom","crop-circle":"e-circle","crop-square":"e-square","crop-3:2":"e-custom-a","crop-4:3":"e-custom-b","crop-5:4":"e-custom-c","crop-7:5":"e-custom-d","crop-16:9":"e-custom-e","crop-2:3":"e-custom-f","crop-3:4":"e-custom-g","crop-4:5":"e-custom-h","crop-5:7":"e-custom-i","crop-9:16":"e-custom-j"};return t[e]?t[e]:e&&-1!==e.indexOf("crop-")?"e-custom":"e-free-pen"},s.prototype.initShapesToolbarItem=function(e){var o=this,i=this.parent,a=i.element.id,n=this.getLeftToolbarItem(),s=this.getRightToolbarItem(),l=this.getShapesToolbarItem(e),p=this.getZoomToolbarItem();t.Browser.isDevice?this.defToolbarItems=l:this.defToolbarItems=n.concat(p,l,s);var h={toolbarType:i.activeObj.shape?i.activeObj.shape:"shapes",toolbarItems:this.defToolbarItems};i.trigger("toolbarUpdating",h),this.isToolbarString(h.toolbarItems)?(e=h.toolbarItems,this.excludeItems(h.toolbarItems)):this.defToolbarItems=h.toolbarItems;var d=new r.Toolbar({width:"100%",items:this.defToolbarItems,clicked:this.defToolbarClicked.bind(this),created:function(){o.renderAnnotationBtn(!0),o.createRectangleRadius(e),o.createShapeColor(e),o.createShapeBtn(e),o.createZOrderBtn(e),"arrow"===i.activeObj.shape&&(e.some(function(e){return e.toLowerCase().indexOf("start")>-1})&&o.createStartBtn(),e.some(function(e){return e.toLowerCase().indexOf("end")>-1})&&o.createEndBtn()),o.wireZoomBtnEvents(),i.trigger("toolbarCreated",{toolbarType:"shapes"}),t.Browser.isDevice?o.defToolbarItems.length>0&&document.getElementById(a+"_bottomToolbar")&&(d.refreshOverflow(),d.refreshOverflow(),d.refreshOverflow()):(o.createLeftToolbarControls(),o.defToolbarItems.length>0&&document.getElementById(a+"_toolbar")&&d.refreshOverflow())}});t.Browser.isDevice?d.appendTo("#"+a+"_bottomToolbar"):d.appendTo("#"+a+"_toolbar"),this.enableDisableTbrBtn()},s.prototype.createRectangleRadius=function(e){var o=this,i=this.parent,r=i.element.id;if(e.indexOf("borderRadius")>-1){var a=[{id:"1",text:this.l10n.getConstant("0")},{id:"2",text:this.l10n.getConstant("20")},{id:"3",text:this.l10n.getConstant("40")},{id:"4",text:this.l10n.getConstant("60")},{id:"5",text:this.l10n.getConstant("80")},{id:"6",text:this.l10n.getConstant("100")}],s=document.getElementById(r+"_rectangleRadiusBtn"),l=document.createElement("span");l.innerHTML=this.l10n.getConstant(i.frameObj.radius.toString()),l.className="e-shape-rectangle-radius",s.appendChild(l);var p=new n.DropDownButton({items:a,open:function(e){if(t.Browser.isDevice){var o=e.element.parentElement;o.style.top=p.element.getBoundingClientRect().top-o.offsetHeight+"px"}var i=p.element.childNodes[0].textContent;""!==i&&e.element.querySelector('[aria-label = "'+i+'"]').classList.add("e-selected-btn")},select:function(e){o.triggerTbarClickEvent(e),l.textContent=e.item.text,i.updateStrokeWidth(e.item.id,"radius"),t.Browser.isDevice?document.getElementById(r+"_bottomToolbar")&&t.getComponent(r+"_bottomToolbar","toolbar").refreshOverflow():document.getElementById(r+"_toolbar")&&t.getComponent(r+"_toolbar","toolbar").refreshOverflow(),i.notify("undo-redo",{prop:"updateUndoRedoStack",onPropertyChange:!1})}});p.appendTo("#"+r+"_rectangleRadiusBtn")}},s.prototype.beforeModeSwitch=function(e,t){this.popupLeft=e.element.offsetParent.style.left,"Picker"===e.mode?(t.showButtons=!0,t.dataBind(),e.element.querySelector(".e-apply").title=this.l10n.getConstant("Apply"),e.element.querySelector(".e-cancel").title=this.l10n.getConstant("Cancel"),e.element.querySelector(".e-mode-switch-btn").title=this.l10n.getConstant("StandardColors")):(t.showButtons=!1,t.dataBind(),e.element.querySelector(".e-mode-switch-btn").title=this.l10n.getConstant("MoreColors"))},s.prototype.createShapeColor=function(e){var o=this,r=this.parent,a=r.element.id;if(e.indexOf("fillColor")>-1){r.element.querySelector(".e-template.e-fill").appendChild(r.createElement("input",{id:a+"_shape_fill"}));var s=new i.ColorPicker({modeSwitcher:!0,noColor:!0,value:"",inline:!0,showButtons:!1,mode:"Palette",cssClass:"e-shape-fill-color",beforeModeSwitch:function(e){return o.beforeModeSwitch(e,s)},presetColors:{custom:["","#f44336","#e91e63","#9c27b0","#673ab7","#2196f3","#03a9f4","#00bcd4","#009688","#ffeb3b","#ffffff","#ffebee","#fce4ec","#f3e5f5","#ede7f6","#e3f2fd","#e1f5fe","#e0f7fa","#e0f2f1","#fffde7","#f2f2f2","#ffcdd2","#f8bbd0","#e1bee7","#d1c4e9","#bbdefb","#b3e5fc","#b2ebf2","#b2dfdb","#fff9c4","#e6e6e6","#ef9a9a","#f48fb1","#ce93d8","#b39ddb","#90caf9","#81d4fa","#80deea","#80cbc4","#fff59d","#cccccc","#e57373","#f06292","#ba68c8","#9575cd","#64b5f6","#4fc3f7","#4dd0e1","#4db6ac","#fff176","#b3b3b3","#ef5350","#ec407a","#ab47bc","#7e57c2","#42a5f5","#29b6f6","#26c6da","#26a69a","#ffee58","#999999","#e53935","#d81b60","#8e24aa","#5e35b1","#1e88e5","#039be5","#00acc1","#00897b","#fdd835","#808080","#d32f2f","#c2185b","#7b1fa2","#512da8","#1976d2","#0288d1","#0097a7","#00796b","#fbc02d","#666666","#c62828","#ad1457","#6a1b9a","#4527a0","#1565c0","#0277bd","#00838f","#00695c","#f9a825","#4d4d4d","#b71c1c","#880e4f","#4a148c","#311b92","#0d47a1","#01579b","#006064","#004d40","#f57f17"]},beforeTileRender:function(e){""===e.value&&e.element.classList.add("e-nocolor-item")},change:function(e){r.updateFillColor(e.value),""===e.currentValue.rgba?l.element.children[0].classList.add("e-nocolor-item"):(l.element.children[0].classList.remove("e-nocolor-item"),l.element.children[0].style.backgroundColor=e.currentValue.rgba),l.toggle(),r.notify("undo-redo",{prop:"updateUndoRedoStack",onPropertyChange:!1})},onModeSwitch:function(e){t.Browser.isDevice&&(e.element.parentElement.parentElement.style.left=o.popupLeft,e.element.parentElement.parentElement.style.top=l.element.getBoundingClientRect().top-e.element.parentElement.parentElement.offsetHeight+"px")},beforeClose:function(){l.toggle()}},"#"+a+"_shape_fill"),l=new n.DropDownButton({open:function(e){var o=e.element.parentElement;t.Browser.isDevice&&(o.style.top=l.element.getBoundingClientRect().top-o.offsetHeight+"px",window.innerWidth<=520&&(o.style.left=r.element.offsetLeft+"px"))},target:".e-shape-fill-color",iconCss:"e-dropdownbtn-preview",cssClass:"e-ie-ddb-popup"},"#"+a+"_fillColorBtn");s.inline=!0,s.value=s.getValue(s.value,"rgba"),r.element.querySelector(".e-fill.e-template .e-dropdownbtn-preview").classList.add("e-nocolor-item")}if(e.indexOf("strokeColor")>-1){r.element.querySelector(".e-template.e-stroke").appendChild(r.createElement("input",{id:a+"_shape_stroke"}));var p=new i.ColorPicker({modeSwitcher:!0,noColor:!1,value:"#fff",inline:!0,showButtons:!1,mode:"Palette",cssClass:"e-shape-stroke-color",beforeModeSwitch:function(e){o.popupLeft=e.element.offsetParent.style.left,p.value="#fff"!==r.activeObj.strokeSettings.strokeColor?r.activeObj.strokeSettings.strokeColor:"#008000ff",o.beforeModeSwitch(e,p)},presetColors:this.presetColors,change:function(e){r.updateStrokeColor(e.value),h.element.children[0].style.backgroundColor=e.currentValue.rgba,h.toggle(),r.notify("undo-redo",{prop:"updateUndoRedoStack",onPropertyChange:!1})},onModeSwitch:function(e){t.Browser.isDevice&&(e.element.parentElement.parentElement.style.left=o.popupLeft,e.element.parentElement.parentElement.style.top=h.element.getBoundingClientRect().top-e.element.parentElement.parentElement.offsetHeight+"px")},beforeClose:function(){h.toggle()}},"#"+a+"_shape_stroke"),h=new n.DropDownButton({open:function(e){var o=e.element.parentElement;t.Browser.isDevice&&(o.style.top=h.element.getBoundingClientRect().top-o.offsetHeight+"px",window.innerWidth<=520&&(o.style.left=r.element.offsetLeft+"px"))},target:".e-shape-stroke-color",iconCss:"e-dropdownbtn-preview",cssClass:"e-ie-ddb-popup"},"#"+a+"_borderColorBtn");p.inline=!0,p.value=p.getValue(p.value,"rgba"),r.element.querySelector(".e-stroke.e-template .e-dropdownbtn-preview").style.background="#fff"}},s.prototype.createShapeBtn=function(e){var o=this,i=this.parent,r=i.element.id;if(e.indexOf("strokeWidth")>-1){var a=[{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")}];!i.activeObj.shape||"rectangle"!==i.activeObj.shape&&"ellipse"!==i.activeObj.shape||(a=[{id:"1",text:this.l10n.getConstant("NoOutline")},{id:"2",text:this.l10n.getConstant("XSmall")},{id:"3",text:this.l10n.getConstant("Small")},{id:"4",text:this.l10n.getConstant("Medium")},{id:"5",text:this.l10n.getConstant("Large")},{id:"6",text:this.l10n.getConstant("XLarge")}]);var s=document.getElementById(r+"_borderWidthBtn"),l=document.createElement("span");l.innerHTML=this.l10n.getConstant("XSmall"),l.className="e-shape-stroke-width",s.appendChild(l);var p=new n.DropDownButton({items:a,open:function(e){t.Browser.isDevice&&(e.element.parentElement.style.top=p.element.getBoundingClientRect().top-e.element.parentElement.offsetHeight+"px");var o=l.innerHTML;""!==o&&e.element.querySelector('[aria-label = "'+o+'"]').classList.add("e-selected-btn")},select:function(e){o.triggerTbarClickEvent(e),l.textContent=e.item.text,i.updateStrokeWidth(e.item.id,"width",i.activeObj.shape),t.Browser.isDevice?document.getElementById(r+"_bottomToolbar")&&t.getComponent(r+"_bottomToolbar","toolbar").refreshOverflow():document.getElementById(r+"_toolbar")&&t.getComponent(r+"_toolbar","toolbar").refreshOverflow(),i.notify("undo-redo",{prop:"updateUndoRedoStack",onPropertyChange:!1})}});p.appendTo("#"+r+"_borderWidthBtn")}},s.prototype.createZOrderBtn=function(e){var o=this,i=this.parent,r=i.element.id;if(e.indexOf("z-order")>-1){var a=[{text:this.l10n.getConstant("BringForward"),id:"bringForward",iconCss:"e-icons e-bring-forward"},{text:this.l10n.getConstant("SendBackward"),id:"sendBackward",iconCss:"e-icons e-send-backward"},{text:this.l10n.getConstant("BringToFront"),id:"bringToFront",iconCss:"e-icons e-bring-to-front"},{text:this.l10n.getConstant("SendToBack"),id:"sendToBack",iconCss:"e-icons e-send-to-back"}],s=new n.DropDownButton({items:a,iconCss:"e-icons e-layers",beforeOpen:function(e){document.getElementById(i.element.id+"_zOrderBtn").classList.contains("e-disabled")&&(e.cancel=!0);var t={freehandSelectedIndex:-1};i.notify("freehand-draw",{prop:"getFreehandSelectedIndex",onPropertyChange:!1,value:{obj:t}});var o={order:null};i.notify("shape",{prop:"getHighestOrder",onPropertyChange:!1,value:{obj:o}});var r=i.activeObj.order?i.activeObj.order:i.getObjFromId(i.pointColl[t.freehandSelectedIndex].id).order;r&&r>=o.order?(e.items[0].disabled=!0,e.items[2].disabled=!0):(e.items[0].disabled=!1,e.items[2].disabled=!1),i.notify("shape",{prop:"getLowestOrder",onPropertyChange:!1,value:{obj:o}}),r&&r<=o.order?(e.items[1].disabled=!0,e.items[3].disabled=!0):(e.items[1].disabled=!1,e.items[3].disabled=!1)},open:function(e){t.Browser.isDevice&&(e.element.parentElement.style.top=s.element.getBoundingClientRect().top-e.element.parentElement.offsetHeight+"px")},select:function(e){o.triggerTbarClickEvent(e);var a={freehandDrawSelectedId:null};i.notify("freehand-draw",{prop:"getFreehandDrawSelectedId",onPropertyChange:!1,value:{obj:a}});var n=a.freehandDrawSelectedId?a.freehandDrawSelectedId:i.activeObj.currIndex;i.updateShapeOrder(n,e.item.id),t.Browser.isDevice?document.getElementById(r+"_bottomToolbar")&&t.getComponent(r+"_bottomToolbar","toolbar").refreshOverflow():document.getElementById(r+"_toolbar")&&t.getComponent(r+"_toolbar","toolbar").refreshOverflow(),n.indexOf("shape")>-1?i.notify("undo-redo",{prop:"updateUndoRedoStack",onPropertyChange:!1}):n.indexOf("pen")>-1&&i.notify("undo-redo",{prop:"updateUndoRedoStack",value:{isPenDraw:!0}})}});s.appendTo("#"+r+"_zOrderBtn")}},s.prototype.createStartBtn=function(){var e=this,o=this.parent,i=o.element.id,r=[{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")}],a=document.getElementById(i+"_startBtn"),s=document.createElement("span");t.isNullOrUndefined(o.activeObj.start)&&(o.activeObj.start="none"),s.innerHTML=o.pascalToSplitWords(o.activeObj.start),s.className="e-shape-start",a.appendChild(s);var l=new n.DropDownButton({items:r,open:function(e){t.Browser.isDevice&&(e.element.parentElement.style.top=l.element.getBoundingClientRect().top-e.element.parentElement.offsetHeight+"px");var o=s.innerHTML;""!==o&&e.element.querySelector('[aria-label = "'+o+'"]').classList.add("e-selected-btn")},select:function(t){var i={1:"none",2:"bar",3:"arrow",4:"arrowSolid",5:"circle",6:"circleSolid",7:"square",8:"squareSolid"};o.notify("selection",{prop:"setArrowShape",value:{type:"initial",shape:i[""+t.item.id]}}),e.triggerTbarClickEvent(t),s.textContent=t.item.text,o.updateArrow("startArrow",t.item.id),o.notify("undo-redo",{prop:"updateUndoRedoStack",onPropertyChange:!1})}});l.appendTo("#"+i+"_startBtn")},s.prototype.createEndBtn=function(){var e=this,o=this.parent,i=o.element.id,r=[{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")}],a=document.getElementById(i+"_endBtn"),s=document.createElement("span");t.isNullOrUndefined(o.activeObj.end)&&(o.activeObj.end="arrowSolid"),s.innerHTML=o.pascalToSplitWords(o.activeObj.end),s.className="e-shape-end",a.appendChild(s);var l=new n.DropDownButton({items:r,open:function(e){t.Browser.isDevice&&(e.element.parentElement.style.top=l.element.getBoundingClientRect().top-e.element.parentElement.offsetHeight+"px");var o=s.innerHTML;""!==o&&e.element.querySelector('[aria-label = "'+o+'"]').classList.add("e-selected-btn")},select:function(t){var i={1:"none",2:"bar",3:"arrow",4:"arrowSolid",5:"circle",6:"circleSolid",7:"square",8:"squareSolid"};o.notify("selection",{prop:"setArrowShape",value:{type:"final",shape:i[""+t.item.id]}}),e.triggerTbarClickEvent(t),s.textContent=t.item.text,o.updateArrow("endArrow",t.item.id),o.notify("undo-redo",{prop:"updateUndoRedoStack",onPropertyChange:!1})}});l.appendTo("#"+i+"_endBtn")},s.prototype.getTextToolbarItem=function(e){var o=this.parent,i=o.element.id,r=[];(t.isNullOrUndefined(o.toolbar)||o.toolbar)&&r.push({id:i+"_annotation",tooltipText:this.l10n.getConstant("Annotation"),align:"Center",template:'<button id="'+i+'_annotationBtn"></button>'}),e.indexOf("fontFamily")>-1&&r.push({id:i+"_fontFamily",cssClass:"top-icon e-img-font-family",tooltipText:this.l10n.getConstant("FontFamily"),align:"Center",template:'<button id="'+i+'_fontFamilyBtn"></button>'}),e.indexOf("fontSize")>-1&&r.push({id:i+"_fontSize",cssClass:"top-icon e-img-font-size",tooltipText:this.l10n.getConstant("FontSize"),align:"Center",template:'<button id="'+i+'_fontSizeBtn"></button>'}),e.indexOf("fontColor")>-1&&r.push({cssClass:"top-icon e-text-font-color",id:i+"_text_strokecolor",tooltipText:this.l10n.getConstant("FontColor"),align:"Center",type:"Input",template:'<button id="'+i+'_fontColorBtn"></button>'}),e.indexOf("strokeColor")>-1&&r.push({cssClass:"top-icon e-stroke-text-font-color",id:i+"_stroke_text_color",tooltipText:this.l10n.getConstant("TextOutlineColor"),align:"Center",type:"Input",template:'<button id="'+i+'_strokeTextColorBtn"></button>'}),e.indexOf("fillColor")>-1&&r.push({cssClass:"top-icon e-text-background-color",id:i+"_text_backgroundcolor",tooltipText:this.l10n.getConstant("FillColor"),align:"Center",type:"Input",template:'<button id="'+i+'_bgColorBtn"></button>'}),e.indexOf("bold")>-1&&r.push({id:i+"_bold",prefixIcon:"e-icons e-bold",cssClass:"top-icon e-bold",tooltipText:this.l10n.getConstant("Bold"),align:"Center"}),e.indexOf("italic")>-1&&r.push({id:i+"_italic",prefixIcon:"e-icons e-italic",cssClass:"top-icon e-italic",tooltipText:this.l10n.getConstant("Italic"),align:"Center"}),e.indexOf("strokeWidth")>-1&&r.push({id:i+"_strokeWidth",cssClass:"top-icon e-size",tooltipText:this.l10n.getConstant("TextOutlineWidth"),align:"Center",type:"Input",template:'<button id="'+i+'_borderWidthBtn"></button>'}),e.indexOf("transparency")>-1&&r.push({id:i+"_transparency",prefixIcon:"e-opacity",tooltipText:this.l10n.getConstant("Opacity"),align:"Center"}),r.push({align:"Center",type:"Separator"}),e.indexOf("z-order")>-1&&r.push({id:i+"_zOrder",cssClass:"top-icon e-list-unordered-3",tooltipText:this.l10n.getConstant("ZOrder"),align:"Center",type:"Input",template:'<button id="'+i+'_zOrderBtn"></button>'}),e.indexOf("duplicate")>-1&&r.push({id:i+"_duplicate",prefixIcon:"e-icons e-order",cssClass:"top-icon e-order",tooltipText:this.l10n.getConstant("Duplicate"),align:"Center",disabled:"block"===o.textArea.style.display||"inline-block"===o.textArea.style.display}),e.indexOf("remove")>-1&&r.push({id:i+"_remove",prefixIcon:"e-icons e-trash",cssClass:"top-icon e-trash",tooltipText:this.l10n.getConstant("Remove"),align:"Center",disabled:"block"===o.textArea.style.display||"inline-block"===o.textArea.style.display}),e.indexOf("text")>-1&&r.push({id:i+"_editText",prefixIcon:"e-icons e-annotation-edit",cssClass:"top-icon e-annotation-edit",tooltipText:this.l10n.getConstant("EditText"),align:"Center",disabled:"block"===o.textArea.style.display||"inline-block"===o.textArea.style.display});for(var a=this.processSubToolbar(e),n=0,s=a.length;n<s;n++)r.push(a[n]);return t.Browser.isDevice||(r.push({id:i+"_ok",prefixIcon:"e-icons e-check",cssClass:"top-icon e-tick",tooltipText:this.l10n.getConstant("OK"),align:"Right",tabIndex:0}),r.push({id:i+"_cancel",prefixIcon:"e-icons e-close",cssClass:"top-icon e-save",tooltipText:this.l10n.getConstant("Cancel"),align:"Right"})),r},s.prototype.getFontFamilyItems=function(){var e=this.parent;return e.fontFamily&&e.fontFamily.items&&e.fontFamily.items.length>0?e.fontFamily.items:t.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"}]},s.prototype.initTextToolbarItem=function(e){var o=this,i=this.parent,a=i.element.id,n=this.getLeftToolbarItem(),s=this.getRightToolbarItem(),l=this.getTextToolbarItem(e),p=this.getZoomToolbarItem();t.Browser.isDevice?this.defToolbarItems=l:this.defToolbarItems=n.concat(p,l,s);var h={toolbarType:"text",toolbarItems:this.defToolbarItems};i.trigger("toolbarUpdating",h),this.isToolbarString(h.toolbarItems)?(e=h.toolbarItems,this.excludeItems(h.toolbarItems)):this.defToolbarItems=h.toolbarItems;var d=new r.Toolbar({width:"100%",items:this.defToolbarItems,clicked:this.defToolbarClicked.bind(this),created:function(){o.renderAnnotationBtn(!0),o.createTextColor(e),o.createStrokeTextColor(e),o.createShapeBtn(e),o.createBackgroundColor(e),o.createTextBtn(e),o.createZOrderBtn(e),o.wireZoomBtnEvents(),i.trigger("toolbarCreated",{toolbarType:"text"}),t.Browser.isDevice?o.defToolbarItems.length>0&&document.getElementById(a+"_bottomToolbar")&&(d.refreshOverflow(),d.refreshOverflow(),d.refreshOverflow()):(o.createLeftToolbarControls(),o.defToolbarItems.length>0&&document.getElementById(a+"_toolbar")&&d.refreshOverflow())}});t.Browser.isDevice?d.appendTo("#"+a+"_bottomToolbar"):d.appendTo("#"+a+"_toolbar"),this.enableDisableTbrBtn()},s.prototype.createTextColor=function(e){var o=this,r=this.parent,a=r.element.id;if(e.indexOf("fontColor")>-1&&r.element.querySelector(".e-template.e-text-font-color")){r.element.querySelector(".e-template.e-text-font-color").appendChild(r.createElement("input",{id:a+"_text_font"}));var s=new i.ColorPicker({modeSwitcher:!0,noColor:!1,value:"#fff",inline:!0,showButtons:!1,mode:"Palette",cssClass:"e-text-fontt-color",beforeModeSwitch:function(e){o.popupLeft=e.element.offsetParent.style.left,s.value="#fff"!==r.activeObj.strokeSettings.strokeColor?r.activeObj.strokeSettings.strokeColor:"#008000ff",o.beforeModeSwitch(e,s)},presetColors:this.presetColors,change:function(e){r.updateFontColor(e.value,"Text"),l.element.children[0].style.backgroundColor=e.currentValue.rgba,l.toggle(),0===r.activeObj.activePoint.width&&0===r.activeObj.activePoint.height||r.notify("undo-redo",{prop:"updateUndoRedoStack",onPropertyChange:!1})},onModeSwitch:function(e){t.Browser.isDevice&&(e.element.parentElement.parentElement.style.left=o.popupLeft,e.element.parentElement.parentElement.style.top=l.element.getBoundingClientRect().top-e.element.parentElement.parentElement.offsetHeight+"px")},beforeClose:function(){l.toggle()}},"#"+a+"_text_font"),l=new n.DropDownButton({open:function(e){var o=e.element.parentElement;t.Browser.isDevice&&(o.style.top=l.element.getBoundingClientRect().top-o.offsetHeight+"px",window.innerWidth<=520&&(o.style.left=r.element.offsetLeft+"px"))},target:".e-text-fontt-color",iconCss:"e-dropdownbtn-preview",cssClass:"e-ie-ddb-popup"},"#"+a+"_fontColorBtn");s.inline=!0,s.value=s.getValue(s.value,"rgba"),r.element.querySelector(".e-text-font-color.e-template .e-dropdownbtn-preview").style.background="#fff"}},s.prototype.createBackgroundColor=function(e){var o=this,r=this.parent,a=r.element.id;if(e.indexOf("fillColor")>-1&&r.element.querySelector(".e-template.e-text-background-color")){r.element.querySelector(".e-template.e-text-background-color").appendChild(r.createElement("input",{id:a+"_text_bgColor"}));var s=new i.ColorPicker({modeSwitcher:!0,noColor:!0,value:"",inline:!0,showButtons:!1,mode:"Palette",cssClass:"e-text-fontt-color",beforeModeSwitch:function(e){o.popupLeft=e.element.offsetParent.style.left,o.beforeModeSwitch(e,s)},presetColors:{custom:["","#f44336","#e91e63","#9c27b0","#673ab7","#2196f3","#03a9f4","#00bcd4","#009688","#ffeb3b","#ffffff","#ffebee","#fce4ec","#f3e5f5","#ede7f6","#e3f2fd","#e1f5fe","#e0f7fa","#e0f2f1","#fffde7","#f2f2f2","#ffcdd2","#f8bbd0","#e1bee7","#d1c4e9","#bbdefb","#b3e5fc","#b2ebf2","#b2dfdb","#fff9c4","#e6e6e6","#ef9a9a","#f48fb1","#ce93d8","#b39ddb","#90caf9","#81d4fa","#80deea","#80cbc4","#fff59d","#cccccc","#e57373","#f06292","#ba68c8","#9575cd","#64b5f6","#4fc3f7","#4dd0e1","#4db6ac","#fff176","#b3b3b3","#ef5350","#ec407a","#ab47bc","#7e57c2","#42a5f5","#29b6f6","#26c6da","#26a69a","#ffee58","#999999","#e53935","#d81b60","#8e24aa","#5e35b1","#1e88e5","#039be5","#00acc1","#00897b","#fdd835","#808080","#d32f2f","#c2185b","#7b1fa2","#512da8","#1976d2","#0288d1","#0097a7","#00796b","#fbc02d","#666666","#c62828","#ad1457","#6a1b9a","#4527a0","#1565c0","#0277bd","#00838f","#00695c","#f9a825","#4d4d4d","#b71c1c","#880e4f","#4a148c","#311b92","#0d47a1","#01579b","#006064","#004d40","#f57f17"]},beforeTileRender:function(e){""===e.value&&e.element.classList.add("e-nocolor-item")},change:function(e){r.updateFontColor(e.value,"Background"),""===e.currentValue.rgba?l.element.children[0].classList.add("e-nocolor-item"):(l.element.children[0].classList.remove("e-nocolor-item"),l.element.children[0].style.backgroundColor=e.currentValue.rgba),l.toggle(),0===r.activeObj.activePoint.width&&0===r.activeObj.activePoint.height||r.notify("undo-redo",{prop:"updateUndoRedoStack",onPropertyChange:!1})},onModeSwitch:function(e){t.Browser.isDevice&&(e.element.parentElement.parentElement.style.left=o.popupLeft,e.element.parentElement.parentElement.style.top=l.element.getBoundingClientRect().top-e.element.parentElement.parentElement.offsetHeight+"px")},beforeClose:function(){l.toggle()}},"#"+a+"_text_bgColor"),l=new n.DropDownButton({open:function(e){var o=e.element.parentElement;t.Browser.isDevice&&(o.style.top=l.element.getBoundingClientRect().top-o.offsetHeight+"px",window.innerWidth<=520&&(o.style.left=r.element.offsetLeft+"px"))},target:".e-text-fontt-color",iconCss:"e-dropdownbtn-preview",cssClass:"e-ie-ddb-popup"},"#"+a+"_bgColorBtn");s.inline=!0,s.value=s.getValue(s.value,"rgba"),r.element.querySelector(".e-text-background-color.e-template .e-dropdownbtn-preview").style.background="#fff"}},s.prototype.createStrokeTextColor=function(e){var o=this,r=this.parent,a=r.element.id;if(e.indexOf("strokeColor")>-1&&r.element.querySelector(".e-template.e-stroke-text-font-color")){r.element.querySelector(".e-template.e-stroke-text-font-color").appendChild(r.createElement("input",{id:a+"_stroke_text"}));var s=new i.ColorPicker({modeSwitcher:!0,noColor:!0,value:"",inline:!0,showButtons:!1,mode:"Palette",cssClass:"e-text-fontt-color",beforeModeSwitch:function(e){o.popupLeft=e.element.offsetParent.style.left,o.beforeModeSwitch(e,s)},presetColors:{custom:["","#f44336","#e91e63","#9c27b0","#673ab7","#2196f3","#03a9f4","#00bcd4","#009688","#ffeb3b","#ffffff","#ffebee","#fce4ec","#f3e5f5","#ede7f6","#e3f2fd","#e1f5fe","#e0f7fa","#e0f2f1","#fffde7","#f2f2f2","#ffcdd2","#f8bbd0","#e1bee7","#d1c4e9","#bbdefb","#b3e5fc","#b2ebf2","#b2dfdb","#fff9c4","#e6e6e6","#ef9a9a","#f48fb1","#ce93d8","#b39ddb","#90caf9","#81d4fa","#80deea","#80cbc4","#fff59d","#cccccc","#e57373","#f06292","#ba68c8","#9575cd","#64b5f6","#4fc3f7","#4dd0e1","#4db6ac","#fff176","#b3b3b3","#ef5350","#ec407a","#ab47bc","#7e57c2","#42a5f5","#29b6f6","#26c6da","#26a69a","#ffee58","#999999","#e53935","#d81b60","#8e24aa","#5e35b1","#1e88e5","#039be5","#00acc1","#00897b","#fdd835","#808080","#d32f2f","#c2185b","#7b1fa2","#512da8","#1976d2","#0288d1","#0097a7","#00796b","#fbc02d","#666666","#c62828","#ad1457","#6a1b9a","#4527a0","#1565c0","#0277bd","#00838f","#00695c","#f9a825","#4d4d4d","#b71c1c","#880e4f","#4a148c","#311b92","#0d47a1","#01579b","#006064","#004d40","#f57f17"]},beforeTileRender:function(e){""===e.value&&e.element.classList.add("e-nocolor-item")},change:function(e){r.updateStrokeTextColor(e.value),""===e.currentValue.rgba?l.element.children[0].classList.add("e-nocolor-item"):(l.element.children[0].classList.remove("e-nocolor-item"),l.element.children[0].style.backgroundColor=e.currentValue.rgba),l.toggle(),0===r.activeObj.activePoint.width&&0===r.activeObj.activePoint.height||r.notify("undo-redo",{prop:"updateUndoRedoStack",onPropertyChange:!1})},onModeSwitch:function(e){t.Browser.isDevice&&(e.element.parentElement.parentElement.style.left=o.popupLeft,e.element.parentElement.parentElement.style.top=l.element.getBoundingClientRect().top-e.element.parentElement.parentElement.offsetHeight+"px")},beforeClose:function(){l.toggle()}},"#"+a+"_stroke_text"),l=new n.DropDownButton({open:function(e){var o=e.element.parentElement;t.Browser.isDevice&&(o.style.top=l.element.getBoundingClientRect().top-o.offsetHeight+"px",window.innerWidth<=520&&(o.style.left=r.element.offsetLeft+"px"))},target:".e-text-fontt-color",iconCss:"e-dropdownbtn-preview",cssClass:"e-ie-ddb-popup"},"#"+a+"_strokeTextColorBtn");s.inline=!0,s.value=s.getValue(s.value,"rgba"),r.element.querySelector(".e-stroke-text-font-color.e-template .e-dropdownbtn-preview").style.background="#fff"}},s.prototype.createTextBtn=function(e){var o=this,i=this.parent,r=i.element.id;if(e.indexOf("fontFamily")>-1){var a=document.getElementById(r+"_fontFamilyBtn"),s=document.createElement("span");t.Browser.isDevice?(s.innerHTML="ABC",s.setAttribute("style","font-family: "+i.fontFamily.default.toLowerCase()+"'")):s.innerHTML=i.fontFamily.default,s.className="e-text-font-family",a&&a.appendChild(s);var l=new n.DropDownButton({items:this.getFontFamilyItems(),cssClass:"e-font-family",createPopupOnClick:!0,beforeItemRender:function(e){e.element.setAttribute("style","font-family:"+e.element.id)},open:function(e){t.Browser.isDevice&&(e.element.parentElement.style.top=l.element.getBoundingClientRect().top-e.element.parentElement.offsetHeight+"px");var o;o="block"===i.textArea.style.display||"inline-block"===i.textArea.style.display?i.textArea.style.fontFamily:i.activeObj.textSettings.fontFamily;var r=e.element.querySelector('[id *= "'+o.toLowerCase()+'"]');r&&r.classList.add("e-selected-btn")},select:function(e){o.triggerTbarClickEvent(e),s.textContent=e.item.text,t.Browser.isDevice&&s.setAttribute("style","font-family:"+e.item.id),i.updateFontFamily(e.item.id),i.notify("undo-redo",{prop:"updateUndoRedoStack",onPropertyChange:!1});var r=document.getElementById(i.element.id+"_toolbar");r&&r.classList.contains("e-control")&&t.getComponent(r,"toolbar").refreshOverflow()}});l.appendTo("#"+r+"_fontFamilyBtn")}if(e.indexOf("fontSize")>-1){var p=document.getElementById(r+"_fontSizeBtn"),h=document.createElement("span"),d=i.getFontSizes();h.innerHTML=d[0].text,h.className="e-text-font-size",p.appendChild(h);var c=new n.DropDownButton({cssClass:"e-font-size",items:d,open:function(e){t.Browser.isDevice&&(e.element.parentElement.style.top=c.element.getBoundingClientRect().top-e.element.parentElement.offsetHeight+"px");var o=h.innerHTML;e.element.querySelector('[aria-label *= "'+o+'"]').classList.add("e-selected-btn")},select:function(e){o.triggerTbarClickEvent(e),h.textContent=e.item.text,i.updateFontSize(e.item.text),i.notify("undo-redo",{prop:"updateUndoRedoStack",onPropertyChange:!1})}});c.appendTo("#"+r+"_fontSizeBtn")}},s.prototype.refreshToolbar=function(e,o,i,r,a,n,s){var l=this.parent,p=l.element.id;if(l.isImageLoaded&&!l.isCropToolbar){var h,d,c={};if("filter"!==e&&"color"!==e){var u=document.getElementById(p+"_toolbar"),v=document.getElementById(p+"_customizeWrapper"),g=document.getElementById(p+"_bottomToolbar");if(v&&t.getComponent(v,"toolbar")&&this.defToolbarItems.length>0&&(t.getComponent(v,"toolbar").destroy(),v.innerHTML=""),u&&u.classList.contains("e-control")&&this.defToolbarItems.length>0&&(t.getComponent(u,"toolbar").destroy(),u.innerHTML=""),u&&(this.defToolbarItems.length>0||l.toolbar&&l.toolbar.length>0&&-1===l.toolbar.indexOf("Open"))){var f=t.getComponent(u,"toolbar");t.isNullOrUndefined(f)||(f.destroy(),document.getElementById(l.element.id+"_toolbar").innerHTML="")}g&&this.defToolbarItems.length>0&&g.className.indexOf("e-control")>-1&&(t.getComponent(g,"toolbar").destroy(),g.innerHTML="")}switch(this.refreshSlider(),document.querySelector(".e-slider-tooltip")&&document.querySelector(".e-slider-tooltip").remove(),this.isFrameToolbar=l.isCropTab=!1,e){case"main":t.Browser.isDevice?i?this.initMainToolbar(!1,!0,!0,!1,!1,!0):this.initMainToolbar(!1,!0,null,!1,!1,!0):t.Browser.isDevice&&!r||this.initMainToolbar(o,t.Browser.isDevice,null),t.Browser.isDevice&&this.initBottomToolbar();break;case"shapes":if(l.noPushUndo=!0,t.Browser.isDevice&&this.initMainToolbar(!1,!0,!0),"line"===l.activeObj.shape||"path"===l.activeObj.shape?c.toolbarItems=["strokeColor","strokeWidth","z-order","duplicate","remove"]:"arrow"===l.activeObj.shape?c.toolbarItems=["strokeColor","strokeWidth","start","end","z-order","duplicate","remove"]:"image"===l.activeObj.shape?c.toolbarItems=["flip","z-order","duplicate","remove","transparency"]:"rectangle"===l.activeObj.shape?c.toolbarItems=["fillColor","strokeColor","strokeWidth","borderRadius","z-order","duplicate","remove"]:c.toolbarItems=["fillColor","strokeColor","strokeWidth","z-order","duplicate","remove"],this.initShapesToolbarItem(c.toolbarItems),"image"===l.activeObj.shape){var C=t.extend({},l.activeObj,{},!0);l.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),l.notify("draw",{prop:"render-image",value:{isMouseWheel:null,isPreventClearRect:null,isFrame:!0}}),l.activeObj=C,l.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate",obj:l.activeObj,isCropRatio:null,points:null,isPreventDrag:!0}}),this.renderQAT(!1)}break;case"text":t.Browser.isDevice&&this.initMainToolbar(!1,!0,!0),c.toolbarItems=["fontFamily","fontSize","fontColor","fillColor","strokeColor","strokeWidth","bold","italic","z-order","duplicate","remove","text"],this.initTextToolbarItem(c.toolbarItems);break;case"pen":t.Browser.isDevice&&this.initMainToolbar(!1,!0,!0),c.toolbarItems=["strokeColor","strokeWidth","z-order","remove","transparency"],this.initPenToolbarItem(c.toolbarItems);break;case"adjustment":t.Browser.isDevice&&this.initMainToolbar(!1,!0,!0),this.initAdjustmentToolbarItem();break;case"filter":this.updateContextualToolbar(e);break;case"resize":(l.isCircleCrop||l.currSelectionPoint&&"crop-circle"===l.currSelectionPoint.shape)&&(l.aspectHeight=l.aspectWidth,this.isAspectRatio=!1),this.initResizeToolbar(),t.Browser.isDevice&&this.initMainToolbar(!1,!0,!0,!0),h=l.element.querySelector("#"+p+"_aspectratio"),d=l.element.querySelector("#"+p+"_nonaspectratio"),l.aspectWidth&&l.aspectHeight&&(d?l.notify("transform",{prop:"resize",value:{width:l.aspectWidth,height:l.aspectHeight,isAspectRatio:!1}}):h&&l.notify("transform",{prop:"resize",value:{width:l.aspectWidth,height:null,isAspectRatio:!0}}));break;case"color":this.updateContextualToolbar(e,a);break;case"croptransform":t.isNullOrUndefined(s)&&(l.allowDownScale=!1,l.isCropTab=!0),t.Browser.isDevice&&this.initMainToolbar(!1,!0,!0),t.isNullOrUndefined(s)&&l.updateCropTransformItems(),this.initCropTransformToolbar(n,s),t.Browser.isDevice&&this.isToolbar()&&this.updateContextualToolbar("color","straighten",!0),l.isMaskImage&&this.refreshToolbar("main");break;case"frame":this.isFrameToolbar=!0,t.Browser.isDevice?(this.initMainToolbar(!1,!0,!0),this.initMainToolbar(!1,!0,!0,!1,!0)):this.initMainToolbar(!0,null,null,!1,!0);var b=l.element.querySelector("#"+p+"_"+l.frameObj.type);b&&b.classList.add("e-selected-btn"),"none"!==l.frameObj.type&&this.updateContextualToolbar(e,a),l.notify("draw",{prop:"render-image",value:{isMouseWheel:null,isPreventClearRect:null,isFrame:!0}});break;case"redact":if(t.Browser.isDevice?(this.initMainToolbar(!1,!0,!0),this.initMainToolbar(!1,!0,!0,null,null,null,!0)):this.initMainToolbar(o,t.Browser.isDevice,null,null,null,null,!0),this.enableDisableTbrBtn(),"blur"===l.activeObj.redactType){var m=l.element.querySelector("#"+p+"_redactBlur");m&&m.classList.add("e-selected-btn")}else{var y=l.element.querySelector("#"+p+"_pixelate");y&&y.classList.add("e-selected-btn")}this.redactSlider(l.activeObj.redactType)}this.refreshDropDownBtn(i),this.updateKBDNavigation(e),this.currToolbar=e}},s.prototype.updateRedactObj=function(){var e=this.parent,o=t.extend([],e.objColl,[],!0);e.objColl=[];var i=t.extend({},e.activeObj,{},!0);e.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),e.notify("draw",{prop:"render-image",value:{isMouseWheel:null,isPreventClearRect:null,isFrame:!0}}),e.objColl=o;for(var r=0;r<e.objColl.length;r++){var a=e.objColl[r];"redact"===a.shape&&(a.redactImage=e.createElement("canvas"),a.redactImage.width=a.activePoint.width,a.redactImage.height=a.activePoint.height,a.redactImage.getContext("2d").drawImage(e.lowerCanvas,a.activePoint.startX,a.activePoint.startY,a.activePoint.width,a.activePoint.height,0,0,a.redactImage.width,a.redactImage.height))}e.isCropTab=!1,e.notify("draw",{prop:"render-image",value:{isMouseWheel:null,isPreventClearRect:null,isFrame:!0}}),e.isCropTab=!0,i&&e.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate",obj:i,isCropRatio:null,points:null,isPreventDrag:!0}})},s.prototype.updateKBDNavigation=function(e){var t=this.parent,o=t.element.id;if(t.isKBDNavigation&&this.currToolbar!==e&&this.isToolbar()){var i,r=t.element.querySelectorAll("#"+o+"_toolbar")[0],a=void 0;if(r){if(!(a=r.querySelector(".e-toolbar-center"))||!a.children[0])return;i=a.children[0].querySelector(".e-btn");var n=a.children[1];if(n&&(n=n.children[0]),n&&(n=n.children[0]),"resize"===e&&n&&(i=n),"filter"===e){var s=document.querySelector("#"+o+"_defaultCanvas");s&&setTimeout(function(){return s.focus()},50)}i&&("main"===e?setTimeout(function(){return i.focus()},50):i.focus())}}},s.prototype.performCropTransformClick=function(e,o){var i=this.parent;t.isNullOrUndefined(o)&&(i.notify("draw",{prop:"setTempStraightenZoomDeg"}),i.tempStraighten=i.transform.straighten,(i.currObjType.isFiltered||i.currObjType.isRedact)&&i.okBtn(),i.isStraightening=!0),this.refreshToolbar("croptransform",null,null,null,null,e,o),t.isNullOrUndefined(o)&&(i.notify("draw",{prop:"setDestForStraighten"}),i.notify("draw",{prop:"setTempDestForStraighten"}))},s.prototype.getAdjustmentToolbarItem=function(){var e=[],o=this.parent,i=!1,r=o.element.id,a=["Brightness","Contrast","Hue","Saturation","Exposure","Opacity","Blur"];if(o.toolbar)for(s=0;s<a.length;s++)if(-1!==o.toolbar.indexOf(a[s])){i=!0;break}(t.isNullOrUndefined(o.toolbar)||!i||o.toolbar&&o.toolbar.indexOf("Brightness")>-1)&&e.push({id:r+"_brightness",prefixIcon:"e-icons e-brightness",cssClass:"top-icon e-brightness",tooltipText:this.l10n.getConstant("Brightness"),align:"Center"}),(t.isNullOrUndefined(o.toolbar)||!i||o.toolbar&&o.toolbar.indexOf("Contrast")>-1)&&e.push({id:r+"_contrast",prefixIcon:"e-icons e-contrast",cssClass:"top-icon e-contrast",tooltipText:this.l10n.getConstant("Contrast"),align:"Center"}),(t.isNullOrUndefined(o.toolbar)||!i||o.toolbar&&o.toolbar.indexOf("Hue")>-1)&&e.push({id:r+"_hue",prefixIcon:"e-icons e-fade",cssClass:"top-icon e-fade",tooltipText:this.l10n.getConstant("Hue"),align:"Center"}),(t.isNullOrUndefined(o.toolbar)||!i||o.toolbar&&o.toolbar.indexOf("Saturation")>-1)&&e.push({id:r+"_saturation",prefixIcon:"e-icons e-saturation",cssClass:"top-icon e-saturation",tooltipText:this.l10n.getConstant("Saturation"),align:"Center"}),(t.isNullOrUndefined(o.toolbar)||!i||o.toolbar&&o.toolbar.indexOf("Exposure")>-1)&&e.push({id:r+"_exposure",prefixIcon:"e-icons e-grain",cssClass:"top-icon e-grain",tooltipText:this.l10n.getConstant("Exposure"),align:"Center"}),(t.isNullOrUndefined(o.toolbar)||!i||o.toolbar&&o.toolbar.indexOf("Opacity")>-1)&&e.push({id:r+"_opacity",prefixIcon:"e-icons e-opacity",cssClass:"top-icon e-opacity",tooltipText:this.l10n.getConstant("Opacity"),align:"Center"}),(t.isNullOrUndefined(o.toolbar)||!i||o.toolbar&&o.toolbar.indexOf("Blur")>-1)&&e.push({id:r+"_blur",prefixIcon:"e-icons e-tint",cssClass:"top-icon e-tint",tooltipText:this.l10n.getConstant("Blur"),align:"Center"});for(var n=this.processToolbar("center"),s=0,l=n.length;s<l;s++)e.push(n[s]);return t.Browser.isDevice||(e.push({id:r+"_ok",prefixIcon:"e-icons e-check",cssClass:"top-icon e-tick",tooltipText:this.l10n.getConstant("OK"),align:"Right",tabIndex:0}),e.push({id:r+"_cancel",prefixIcon:"e-icons e-close",cssClass:"top-icon e-save",tooltipText:this.l10n.getConstant("Cancel"),align:"Right"})),e},s.prototype.getFrameToolbarItem=function(){var e=this.parent,t=e.element.id,o=[];return o.push({prefixIcon:"e-icons e-copy",id:t+"_frameColor",cssClass:"top-icon e-stroke",tooltipText:this.l10n.getConstant("Color"),align:"Center",type:"Input",template:"<span>"+this.l10n.getConstant("Color")+'</span><button id="'+t+'_frameColorBtn"></button>'}),o.push({prefixIcon:"e-icons e-copy",id:t+"_frameGradient",cssClass:"top-icon e-frame-stroke",tooltipText:this.l10n.getConstant("GradientColor"),align:"Center",type:"Input",template:"<span>"+this.l10n.getConstant("GradientColor")+'</span><button id="'+t+'_frameGradientColorBtn"></button>'}),o.push({id:t+"_frameSize",cssClass:"top-icon e-size",tooltipText:this.l10n.getConstant("Size"),align:"Center",type:"Input",template:"<span>"+this.l10n.getConstant("Size")+'</span><button id="'+t+'_frameSizeBtn"></button>'}),"line"!==e.frameObj.type&&"inset"!==e.frameObj.type&&"hook"!==e.frameObj.type||o.push({id:t+"_frameInset",cssClass:"top-icon e-size",tooltipText:this.l10n.getConstant("Inset"),align:"Center",type:"Input",template:"<span>"+this.l10n.getConstant("Inset")+'</span><button id="'+t+'_frameInsetBtn"></button>'}),"line"!==e.frameObj.type&&"inset"!==e.frameObj.type||o.push({id:t+"_frameOffset",cssClass:"top-icon e-size",tooltipText:this.l10n.getConstant("Offset"),align:"Center",type:"Input",template:"<span>"+this.l10n.getConstant("Offset")+'</span><button id="'+t+'_frameOffsetBtn"></button>'}),"line"===e.frameObj.type&&(o.push({id:t+"_frameRadius",cssClass:"top-icon e-size",tooltipText:this.l10n.getConstant("Radius"),align:"Center",type:"Input",template:"<span>"+this.l10n.getConstant("Radius")+'</span><button id="'+t+'_frameRadiusBtn"></button>'}),o.push({id:t+"_frameAmount",cssClass:"top-icon e-size",tooltipText:this.l10n.getConstant("Amount"),align:"Center",type:"Input",template:"<span>"+this.l10n.getConstant("Amount")+'</span><button id="'+t+'_frameAmountBtn"></button>'}),o.push({id:t+"_frameBorder",cssClass:"top-icon e-size",tooltipText:this.l10n.getConstant("Border"),align:"Center",type:"Input",template:"<span>"+this.l10n.getConstant("Border")+'</span><button id="'+t+'_frameBorderBtn"></button>'})),o},s.prototype.getFilterToolbarItem=function(){var e=[],o=this.parent,i=!1,r=o.element.id,a=["Default","Chrome","Cold","Warm","Grayscale","Sepia","Invert"];if(o.toolbar)for(s=0;s<a.length;s++)if(-1!==o.toolbar.indexOf(a[s])){i=!0;break}(t.isNullOrUndefined(o.toolbar)||!i||o.toolbar&&o.toolbar.indexOf("Default")>-1)&&e.push({id:r+"_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='+r+'_defaultCanvas tabindex=0></canvas><div style="text-align:center;"><span>'+this.l10n.getConstant("Default")+"</span></div></div>"}),(t.isNullOrUndefined(o.toolbar)||!i||o.toolbar&&o.toolbar.indexOf("Chrome")>-1)&&e.push({id:r+"_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='+r+'_chromeCanvas></canvas><div style="text-align:center;"><span>'+this.l10n.getConstant("Chrome")+"</span></div></div>"}),(t.isNullOrUndefined(o.toolbar)||!i||o.toolbar&&o.toolbar.indexOf("Cold")>-1)&&e.push({id:r+"_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='+r+'_coldCanvas></canvas><div style="text-align:center;"><span>'+this.l10n.getConstant("Cold")+"</span></div></div>"}),(t.isNullOrUndefined(o.toolbar)||!i||o.toolbar&&o.toolbar.indexOf("Warm")>-1)&&e.push({id:r+"_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='+r+'_warmCanvas></canvas><div style="text-align:center;"><span>'+this.l10n.getConstant("Warm")+"</span></div></div>"}),(t.isNullOrUndefined(o.toolbar)||!i||o.toolbar&&o.toolbar.indexOf("Grayscale")>-1)&&e.push({id:r+"_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='+r+'_grayscaleCanvas></canvas><div style="text-align:center;"><span>'+this.l10n.getConstant("Grayscale")+"</span></div></div>"}),(t.isNullOrUndefined(o.toolbar)||!i||o.toolbar&&o.toolbar.indexOf("Sepia")>-1)&&e.push({id:r+"_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='+r+'_sepiaCanvas></canvas><div style="text-align:center;"><span>'+this.l10n.getConstant("Sepia")+"</span></div></div>"}),(t.isNullOrUndefined(o.toolbar)||!i||o.toolbar&&o.toolbar.indexOf("Invert")>-1)&&e.push({id:r+"_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='+r+'_invertCanvas></canvas><div style="text-align:center;"><span>'+this.l10n.getConstant("Invert")+"</span></div></div>"});for(var n=this.processToolbar("center"),s=0,l=n.length;s<l;s++)e.push(n[s]);return e},s.prototype.getPenToolbarItem=function(e){var o=this.parent,i=o.element.id,r=[];(t.isNullOrUndefined(o.toolbar)||o.toolbar)&&r.push({id:i+"_annotation",tooltipText:this.l10n.getConstant("Annotation"),align:"Center",template:'<button id="'+i+'_annotationBtn"></button>'}),e.indexOf("strokeColor")>-1&&r.push({prefixIcon:"e-icons e-copy",id:i+"_pen_strokecolor",cssClass:"top-icon e-pen-stroke-color",tooltipText:this.l10n.getConstant("StrokeColor"),align:"Center",type:"Input",template:'<button id="'+i+'_penColorBtn"></button>'}),e.indexOf("strokeWidth")>-1&&r.push({prefixIcon:"e-icons e-copy",id:i+"_pen_strokewidth",cssClass:"top-icon e-size",tooltipText:this.l10n.getConstant("StrokeWidth"),align:"Center",type:"Input",template:'<button id="'+i+'_penStrokeWidth"></button>'}),r.push({align:"Center",type:"Separator"}),e.indexOf("z-order")>-1&&r.push({id:i+"_zOrder",cssClass:"top-icon e-list-unordered-3",tooltipText:this.l10n.getConstant("ZOrder"),align:"Center",type:"Input",template:'<button id="'+i+'_zOrderBtn"></button>'}),e.indexOf("remove")>-1&&r.push({id:i+"_remove",prefixIcon:"e-icons e-trash",cssClass:"top-icon e-trash",tooltipText:this.l10n.getConstant("Remove"),align:"Center"});for(var a=this.processSubToolbar(e),n=0,s=a.length;n<s;n++)r.push(a[n]);return t.Browser.isDevice||(r.push({id:i+"_ok",prefixIcon:"e-icons e-check",cssClass:"top-icon e-tick",tooltipText:this.l10n.getConstant("OK"),align:"Right",tabIndex:0}),r.push({id:i+"_cancel",prefixIcon:"e-icons e-close",cssClass:"top-icon e-save",tooltipText:this.l10n.getConstant("Cancel"),align:"Right"})),r},s.prototype.initPenToolbarItem=function(e){var o=this,i=this.parent,a=i.element.id,n=this.getLeftToolbarItem(),s=this.getRightToolbarItem(),l=this.getPenToolbarItem(e),p=this.getZoomToolbarItem();t.Browser.isDevice?this.defToolbarItems=l:this.defToolbarItems=n.concat(p,l,s);var h={toolbarType:"pen",toolbarItems:this.defToolbarItems};i.trigger("toolbarUpdating",h),this.isToolbarString(h.toolbarItems)?(e=h.toolbarItems,this.excludeItems(h.toolbarItems)):this.defToolbarItems=h.toolbarItems;var d=new r.Toolbar({width:"100%",items:this.defToolbarItems,clicked:this.defToolbarClicked.bind(this),created:function(){o.renderAnnotationBtn(!0),o.createPenColor(e),o.createPenBtn(e),o.createZOrderBtn(e),o.wireZoomBtnEvents(),i.trigger("toolbarCreated",{toolbarType:"pen"}),t.Browser.isDevice?o.defToolbarItems.length>0&&document.getElementById(a+"_toolbar")&&(d.refreshOverflow(),d.refreshOverflow()):(o.createLeftToolbarControls(),o.defToolbarItems.length>0&&document.getElementById(a+"_toolbar")&&d.refreshOverflow())}});t.Browser.isDevice?d.appendTo("#"+a+"_bottomToolbar"):d.appendTo("#"+a+"_toolbar"),this.enableDisableTbrBtn()},s.prototype.createPenColor=function(e){var o=this,r=this.parent,a=r.element.id;if(e.indexOf("strokeColor")>-1){r.element.querySelector(".e-template.e-pen-stroke-color").appendChild(r.createElement("input",{id:a+"_pen_stroke"}));var s=r.activeObj.strokeSettings.strokeColor,l=new i.ColorPicker({modeSwitcher:!1,value:"#fff",showButtons:!1,mode:"Palette",cssClass:"e-pen-color",change:function(e){r.updatePenStrokeColor(e.currentValue.hex),o.selFhdColor=e.currentValue.hex,p.element.children[0].style.backgroundColor=e.currentValue.rgba,p.toggle(),r.notify("undo-redo",{prop:"updateUndoRedoStack",value:{isPenDraw:!0}})}},"#"+a+"_pen_stroke"),p=new n.DropDownButton({open:function(e){var o=e.element.parentElement;t.Browser.isDevice&&(o.style.top=p.element.getBoundingClientRect().top-o.offsetHeight+"px",window.innerWidth<=520&&(o.style.left=r.element.offsetLeft+"px"))},target:".e-pen-color",iconCss:"e-dropdownbtn-preview",cssClass:"e-ie-ddb-popup"},"#"+a+"_penColorBtn");l.inline=!0,l.value=l.getValue(r.activeObj.strokeSettings.strokeColor,"rgba"),"null"===l.value&&(l.value=s);var h={tempFreeHandDrawEditingStyles:null};r.notify("freehand-draw",{prop:"getTempFreeHandDrawEditingStyles",value:{obj:h}});var d={freehandSelectedIndex:null};r.notify("freehand-draw",{prop:"getFreehandSelectedIndex",onPropertyChange:!1,value:{obj:d}}),!t.isNullOrUndefined(d.freehandSelectedIndex)&&d.freehandSelectedIndex>-1?r.element.querySelector(".e-pen-stroke-color.e-template .e-dropdownbtn-preview").style.background="#42a5f5"===this.selFhdColor?h.tempFreeHandDrawEditingStyles.strokeColor:r.pointColl[d.freehandSelectedIndex].strokeColor:r.element.querySelector(".e-pen-stroke-color.e-template .e-dropdownbtn-preview").style.background=l.value}},s.prototype.createPenBtn=function(e){var o=this,i=this.parent,r=i.element.id,a=[{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(e.indexOf("strokeWidth")>-1){var s=document.getElementById(r+"_penStrokeWidth"),l=document.createElement("span"),p={freehandSelectedIndex:null};if(i.notify("freehand-draw",{prop:"getFreehandSelectedIndex",onPropertyChange:!1,value:{obj:p}}),!t.isNullOrUndefined(p.freehandSelectedIndex)&&p.freehandSelectedIndex>-1)l.innerHTML=this.getPenStroke(i.pointColl[p.freehandSelectedIndex].strokeWidth);else{var h={penStrokeWidth:2};i.notify("freehand-draw",{prop:"getPenStrokeWidth",onPropertyChange:!1,value:{obj:h}}),l.innerHTML=h.penStrokeWidth?this.getPenStroke(h.penStrokeWidth):this.l10n.getConstant("Small")}l.className="e-pen-stroke-width",s.appendChild(l);var d=new n.DropDownButton({items:a,open:function(e){t.Browser.isDevice&&(e.element.parentElement.style.top=d.element.getBoundingClientRect().top-e.element.parentElement.offsetHeight+"px");var o=l.innerHTML;e.element.querySelector('[aria-label = "'+o+'"]').classList.add("e-selected-btn")},select:function(e){o.triggerTbarClickEvent(e),l.textContent=e.item.text,i.updatePenStrokeWidth(e.item.id),t.Browser.isDevice?document.getElementById(r+"_bottomToolbar")&&t.getComponent(r+"_bottomToolbar","toolbar").refreshOverflow():document.getElementById(r+"_toolbar")&&t.getComponent(r+"_toolbar","toolbar").refreshOverflow();var a={penStrokeWidth:null};i.notify("freehand-draw",{prop:"getPenStrokeWidth",onPropertyChange:!1,value:{obj:a}}),i.notify("undo-redo",{prop:"updateUndoRedoStack",value:{isPenDraw:!0}}),i.notify("freehand-draw",{prop:"setPenStrokeWidth",onPropertyChange:!1,value:{value:a.penStrokeWidth}})}});d.appendTo("#"+r+"_penStrokeWidth")}},s.prototype.getPenStroke=function(e){var t="",o={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 e>=1&&e<=5&&(t=o[e]),t},s.prototype.initAdjustmentToolbarItem=function(){var e=this,o=this.parent,i=o.element.id,a=this.getLeftToolbarItem(null),n=this.getRightToolbarItem(),s=this.getAdjustmentToolbarItem(),l=this.getZoomToolbarItem();t.Browser.isDevice?this.defToolbarItems=s:this.defToolbarItems=a.concat(l,s,n);var p={toolbarType:"finetune",toolbarItems:this.defToolbarItems};o.trigger("toolbarUpdating",p),this.defToolbarItems=p.toolbarItems;var h=new r.Toolbar({width:"100%",items:this.defToolbarItems,clicked:this.defToolbarClicked.bind(this),created:function(){e.wireZoomBtnEvents(),t.Browser.isDevice?e.defToolbarItems.length>0&&document.getElementById(i+"_toolbar")&&h.refreshOverflow():(e.createLeftToolbarControls(),e.defToolbarItems.length>0&&document.getElementById(i+"_toolbar")&&h.refreshOverflow())}});t.Browser.isDevice?h.appendTo("#"+i+"_bottomToolbar"):h.appendTo("#"+i+"_toolbar"),this.enableDisableTbrBtn()},s.prototype.initFrameToolbarItem=function(){var e=this,o=this.parent,i=o.element.id,a=document.querySelector("#"+i+"_contextualToolbarArea"),n=document.querySelector("#"+i+"_frameWrapper");n?n.style.display="block":n=a.appendChild(o.createElement("div",{id:i+"_frameWrapper",className:"e-frame-wrapper",styles:"position: relative"})),n.appendChild(o.createElement("div",{id:i+"_customizeWrapper",styles:"position: absolute"}));var s=this.getFrameToolbarItem(),l={toolbarType:"frame",toolbarItems:s};o.trigger("toolbarUpdating",l),s=l.toolbarItems;var p=new r.Toolbar({width:"100%",items:s,clicked:this.defToolbarClicked.bind(this),created:function(){e.createFrameColor(),e.createFrameSize();var r=o.frameObj.type;"line"===r&&e.createFrameRadius(),"line"!==r&&"inset"!==r&&"hook"!==r||e.createFrameInset(),"line"!==r&&"inset"!==r||e.createFrameOffset(),"line"===r&&(e.createFrameAmount(),e.createFrameBorder()),e.createFrameGradientColor(),t.Browser.isDevice?e.defToolbarItems.length>0&&document.getElementById(i+"_bottomToolbar")&&(p.refreshOverflow(),p.refreshOverflow(),p.refreshOverflow()):(e.createLeftToolbarControls(),e.defToolbarItems.length>0&&document.getElementById(i+"_toolbar")&&p.refreshOverflow()),o.element.querySelector("#"+i+"_"+r).focus()}});p.appendTo("#"+i+"_customizeWrapper")},s.prototype.createFrameGradientColor=function(){var e,o=this.parent,r={frameChangeEventArgs:null},a=o.element.id;o.element.querySelector(".e-template.e-frame-stroke").appendChild(o.createElement("input",{id:a+"_frame_gradient_fill"}));var s=new i.ColorPicker({modeSwitcher:!1,noColor:!0,value:o.frameObj.gradientColor,showButtons:!1,mode:"Palette",cssClass:"e-frame-gradient-fill-color",change:function(i){e={type:o.toPascalCase(o.frameObj.type),color:o.frameObj.color,gradientColor:o.frameObj.gradientColor,size:o.frameObj.size,inset:o.frameObj.inset,offset:o.frameObj.offset,borderRadius:o.frameObj.radius,frameLineStyle:o.toPascalCase(o.frameObj.border),lineCount:o.frameObj.amount};var a=o.frameObj.gradientColor,n={currObj:{}};o.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:n}}),o.frameObj.gradientColor=i.currentValue.hex,o.notify("draw",{prop:"triggerFrameChange",value:{prevFrameSettings:e,obj:r}}),r.frameChangeEventArgs&&!r.frameChangeEventArgs.cancel?(o.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"frame",previousObj:n.currObj,previousObjColl:n.currObj.objColl,previousPointColl:n.currObj.pointColl,previousSelPointColl:n.currObj.selPointColl,previousCropObj:t.extend({},o.cropObj,{},!0),previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),o.notify("draw",{prop:"render-image",value:{isMouseWheel:null,isPreventClearRect:null,isFrame:!0}}),o.notify("draw",{prop:"redrawDownScale"}),""===i.currentValue.rgba?l.element.children[0].classList.add("e-nocolor-item"):(l.element.children[0].classList.remove("e-nocolor-item"),l.element.children[0].style.backgroundColor=i.currentValue.rgba),o.curFrameObjEvent={previousFrameSetting:r.frameChangeEventArgs.previousFrameSetting,currentFrameSetting:r.frameChangeEventArgs.currentFrameSetting},o.isFrameBtnClick=!0):o.frameObj.gradientColor=a,l.toggle()}},"#"+a+"_frame_gradient_fill"),l=new n.DropDownButton({open:function(e){if(t.Browser.isDevice){var i=e.element.parentElement;i.style.top=l.element.getBoundingClientRect().top-i.offsetHeight+"px",window.innerWidth<=520&&(i.style.left=o.element.offsetLeft+"px")}},target:".e-frame-gradient-fill-color",iconCss:"e-dropdownbtn-preview",cssClass:"e-ie-ddb-popup"},"#"+a+"_frameGradientColorBtn");s.inline=!0,""===o.frameObj.gradientColor?o.element.querySelector(".e-frame-stroke.e-template .e-dropdownbtn-preview").classList.add("e-nocolor-item"):o.element.querySelector(".e-frame-stroke.e-template .e-dropdownbtn-preview").style.background=o.frameObj.gradientColor},s.prototype.createFrameColor=function(){var e,o=this.parent,r={frameChangeEventArgs:null},a=o.element.id;o.element.querySelector(".e-template.e-stroke").appendChild(o.createElement("input",{id:a+"_frame_fill"}));var s=new i.ColorPicker({modeSwitcher:!1,value:o.frameObj.color,showButtons:!1,mode:"Palette",cssClass:"e-frame-fill-color",change:function(i){e={type:o.toPascalCase(o.frameObj.type),color:o.frameObj.color,gradientColor:o.frameObj.gradientColor,size:o.frameObj.size,inset:o.frameObj.inset,offset:o.frameObj.offset,borderRadius:o.frameObj.radius,frameLineStyle:o.toPascalCase(o.frameObj.border),lineCount:o.frameObj.amount};var a=o.frameObj.color,n={currObj:{}};o.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:n}}),o.frameObj.color=i.currentValue.hex,o.notify("draw",{prop:"triggerFrameChange",value:{prevFrameSettings:e,obj:r}}),r.frameChangeEventArgs&&!r.frameChangeEventArgs.cancel?(o.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"frame",previousObj:n.currObj,previousObjColl:n.currObj.objColl,previousPointColl:n.currObj.pointColl,previousSelPointColl:n.currObj.selPointColl,previousCropObj:t.extend({},o.cropObj,{},!0),previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),o.notify("draw",{prop:"render-image",value:{isMouseWheel:null,isPreventClearRect:null,isFrame:!0}}),o.notify("draw",{prop:"redrawDownScale"}),""===i.currentValue.rgba?l.element.children[0].classList.add("e-nocolor-item"):(l.element.children[0].classList.remove("e-nocolor-item"),l.element.children[0].style.backgroundColor=i.currentValue.rgba),o.curFrameObjEvent={previousFrameSetting:r.frameChangeEventArgs.previousFrameSetting,currentFrameSetting:r.frameChangeEventArgs.currentFrameSetting},o.isFrameBtnClick=!0):o.frameObj.color=a,l.toggle()}},"#"+a+"_frame_fill"),l=new n.DropDownButton({open:function(e){if(t.Browser.isDevice){var i=e.element.parentElement;i.style.top=l.element.getBoundingClientRect().top-i.offsetHeight+"px",window.innerWidth<=520&&(i.style.left=o.element.offsetLeft+"px")}},target:".e-frame-fill-color",iconCss:"e-dropdownbtn-preview",cssClass:"e-ie-ddb-popup"},"#"+a+"_frameColorBtn");s.inline=!0,o.element.querySelector(".e-stroke.e-template .e-dropdownbtn-preview").style.background=o.frameObj.color},s.prototype.createFrameSize=function(){var e,o=this,i=this.parent,r={frameChangeEventArgs:null},a=i.element.id,s=[{id:"1",text:this.l10n.getConstant("20")},{id:"2",text:this.l10n.getConstant("40")},{id:"3",text:this.l10n.getConstant("60")},{id:"4",text:this.l10n.getConstant("80")},{id:"5",text:this.l10n.getConstant("100")}],l=document.getElementById(a+"_frameSizeBtn"),p=document.createElement("span");p.innerHTML=this.l10n.getConstant(i.frameObj.size.toString()),p.className="e-frame-stroke-width",l.appendChild(p);var h=new n.DropDownButton({items:s,open:function(e){if(t.Browser.isDevice){var o=e.element.parentElement;o.style.top=h.element.getBoundingClientRect().top-o.offsetHeight+"px"}var i=h.element.childNodes[0].textContent;""!==i&&e.element.querySelector('[aria-label = "'+i+'"]').classList.add("e-selected-btn")},select:function(n){o.triggerTbarClickEvent(n),e={type:i.toPascalCase(i.frameObj.type),color:i.frameObj.color,gradientColor:i.frameObj.gradientColor,size:i.frameObj.size,inset:i.frameObj.inset,offset:i.frameObj.offset,borderRadius:i.frameObj.radius,frameLineStyle:i.toPascalCase(i.frameObj.border),lineCount:i.frameObj.amount};var s=i.frameObj.size,l={currObj:{}};i.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:l}}),i.frameObj.size=parseInt(n.item.text,10),i.notify("draw",{prop:"triggerFrameChange",value:{prevFrameSettings:e,obj:r}}),r.frameChangeEventArgs&&!r.frameChangeEventArgs.cancel?(i.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"frame",previousObj:l.currObj,previousObjColl:l.currObj.objColl,previousPointColl:l.currObj.pointColl,previousSelPointColl:l.currObj.selPointColl,previousCropObj:t.extend({},i.cropObj,{},!0),previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),i.notify("draw",{prop:"render-image",value:{isMouseWheel:null,isPreventClearRect:null,isFrame:!0}}),i.notify("draw",{prop:"redrawDownScale"}),h.content=n.item.text,i.curFrameObjEvent={previousFrameSetting:r.frameChangeEventArgs.previousFrameSetting,currentFrameSetting:r.frameChangeEventArgs.currentFrameSetting},i.isFrameBtnClick=!0):i.frameObj.size=s,t.Browser.isDevice?document.getElementById(a+"_bottomToolbar")&&t.getComponent(a+"_bottomToolbar","toolbar").refreshOverflow():document.getElementById(a+"_toolbar")&&t.getComponent(a+"_toolbar","toolbar").refreshOverflow()}});h.appendTo("#"+a+"_frameSizeBtn")},s.prototype.createFrameInset=function(){var e,o=this,i=this.parent,r={frameChangeEventArgs:null},a=i.element.id,s=[{id:"1",text:this.l10n.getConstant("20")},{id:"2",text:this.l10n.getConstant("40")},{id:"3",text:this.l10n.getConstant("60")},{id:"4",text:this.l10n.getConstant("80")},{id:"5",text:this.l10n.getConstant("100")}],l=document.getElementById(a+"_frameInsetBtn"),p=document.createElement("span");p.innerHTML=this.l10n.getConstant(i.frameObj.inset.toString()),p.className="e-frame-inset",l.appendChild(p);var h=new n.DropDownButton({items:s,open:function(e){if(t.Browser.isDevice){var o=e.element.parentElement;o.style.top=h.element.getBoundingClientRect().top-o.offsetHeight+"px"}var i=h.element.childNodes[0].textContent;""!==i&&e.element.querySelector('[aria-label = "'+i+'"]').classList.add("e-selected-btn")},select:function(n){o.triggerTbarClickEvent(n),e={type:i.toPascalCase(i.frameObj.type),color:i.frameObj.color,gradientColor:i.frameObj.gradientColor,size:i.frameObj.size,inset:i.frameObj.inset,offset:i.frameObj.offset,borderRadius:i.frameObj.radius,frameLineStyle:i.toPascalCase(i.frameObj.border),lineCount:i.frameObj.amount};var s=i.frameObj.inset,l={currObj:{}};i.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:l}}),i.frameObj.inset=parseInt(n.item.text,10),i.notify("draw",{prop:"triggerFrameChange",value:{prevFrameSettings:e,obj:r}}),r.frameChangeEventArgs&&!r.frameChangeEventArgs.cancel?(i.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"frame",previousObj:l.currObj,previousObjColl:l.currObj.objColl,previousPointColl:l.currObj.pointColl,previousSelPointColl:l.currObj.selPointColl,previousCropObj:t.extend({},i.cropObj,{},!0),previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),i.notify("draw",{prop:"render-image",value:{isMouseWheel:null,isPreventClearRect:null,isFrame:!0}}),i.notify("draw",{prop:"redrawDownScale"}),h.content=n.item.text,i.curFrameObjEvent={previousFrameSetting:r.frameChangeEventArgs.previousFrameSetting,currentFrameSetting:r.frameChangeEventArgs.currentFrameSetting},i.isFrameBtnClick=!0):i.frameObj.inset=s,t.Browser.isDevice?document.getElementById(a+"_bottomToolbar")&&t.getComponent(a+"_bottomToolbar","toolbar").refreshOverflow():document.getElementById(a+"_toolbar")&&t.getComponent(a+"_toolbar","toolbar").refreshOverflow()}});h.appendTo("#"+a+"_frameInsetBtn")},s.prototype.createFrameOffset=function(){var e,o=this,i=this.parent,r={frameChangeEventArgs:null},a=i.element.id,s=[{id:"1",text:this.l10n.getConstant("20")},{id:"2",text:this.l10n.getConstant("40")},{id:"3",text:this.l10n.getConstant("60")},{id:"4",text:this.l10n.getConstant("80")},{id:"5",text:this.l10n.getConstant("100")}],l=document.getElementById(a+"_frameOffsetBtn"),p=document.createElement("span");p.innerHTML=this.l10n.getConstant(i.frameObj.offset.toString()),p.className="e-frame-offset",l.appendChild(p);var h=new n.DropDownButton({items:s,open:function(e){if(t.Browser.isDevice){var o=e.element.parentElement;o.style.top=h.element.getBoundingClientRect().top-o.offsetHeight+"px"}var i=h.element.childNodes[0].textContent;""!==i&&e.element.querySelector('[aria-label = "'+i+'"]').classList.add("e-selected-btn")},select:function(n){o.triggerTbarClickEvent(n),e={type:i.toPascalCase(i.frameObj.type),color:i.frameObj.color,gradientColor:i.frameObj.gradientColor,size:i.frameObj.size,inset:i.frameObj.inset,offset:i.frameObj.offset,borderRadius:i.frameObj.radius,lineCount:i.frameObj.amount,frameLineStyle:i.toPascalCase(i.frameObj.border)};var s=i.frameObj.offset,l={currObj:{}};i.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:l}}),i.frameObj.offset=parseInt(n.item.text,10),i.notify("draw",{prop:"triggerFrameChange",value:{prevFrameSettings:e,obj:r}}),r.frameChangeEventArgs&&!r.frameChangeEventArgs.cancel?(i.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"frame",previousObj:l.currObj,previousObjColl:l.currObj.objColl,previousPointColl:l.currObj.pointColl,previousSelPointColl:l.currObj.selPointColl,previousCropObj:t.extend({},i.cropObj,{},!0),previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),i.notify("draw",{prop:"render-image",value:{isMouseWheel:null,isPreventClearRect:null,isFrame:!0}}),i.notify("draw",{prop:"redrawDownScale"}),h.content=n.item.text,i.curFrameObjEvent={previousFrameSetting:r.frameChangeEventArgs.previousFrameSetting,currentFrameSetting:r.frameChangeEventArgs.currentFrameSetting},i.isFrameBtnClick=!0):i.frameObj.offset=s,t.Browser.isDevice?document.getElementById(a+"_bottomToolbar")&&t.getComponent(a+"_bottomToolbar","toolbar").refreshOverflow():document.getElementById(a+"_toolbar")&&t.getComponent(a+"_toolbar","toolbar").refreshOverflow()}});h.appendTo("#"+a+"_frameOffsetBtn")},s.prototype.createFrameRadius=function(){var e,o=this,i=this.parent,r={frameChangeEventArgs:null},a=i.element.id,s=[{id:"1",text:this.l10n.getConstant("0")},{id:"2",text:this.l10n.getConstant("20")},{id:"3",text:this.l10n.getConstant("40")},{id:"4",text:this.l10n.getConstant("60")},{id:"5",text:this.l10n.getConstant("80")},{id:"6",text:this.l10n.getConstant("100")}],l=document.getElementById(a+"_frameRadiusBtn"),p=document.createElement("span");p.innerHTML=this.l10n.getConstant(i.frameObj.radius.toString()),p.className="e-frame-radius",l.appendChild(p);var h=new n.DropDownButton({items:s,open:function(e){if(t.Browser.isDevice){var o=e.element.parentElement;o.style.top=h.element.getBoundingClientRect().top-o.offsetHeight+"px"}var i=h.element.childNodes[0].textContent;""!==i&&e.element.querySelector('[aria-label = "'+i+'"]').classList.add("e-selected-btn")},select:function(n){o.triggerTbarClickEvent(n),e={type:i.toPascalCase(i.frameObj.type),color:i.frameObj.color,gradientColor:i.frameObj.gradientColor,size:i.frameObj.size,inset:i.frameObj.inset,offset:i.frameObj.offset,borderRadius:i.frameObj.radius,frameLineStyle:i.toPascalCase(i.frameObj.border),lineCount:i.frameObj.amount};var s=i.frameObj.radius,l={currObj:{}};i.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:l}}),i.frameObj.radius=parseInt(n.item.text,10),i.notify("draw",{prop:"triggerFrameChange",value:{prevFrameSettings:e,obj:r}}),r.frameChangeEventArgs&&!r.frameChangeEventArgs.cancel?(i.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"frame",previousObj:l.currObj,previousObjColl:l.currObj.objColl,previousPointColl:l.currObj.pointColl,previousSelPointColl:l.currObj.selPointColl,previousCropObj:t.extend({},i.cropObj,{},!0),previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),i.notify("draw",{prop:"render-image",value:{isMouseWheel:null,isPreventClearRect:null,isFrame:!0}}),i.notify("draw",{prop:"redrawDownScale"}),h.content=n.item.text,i.curFrameObjEvent={previousFrameSetting:r.frameChangeEventArgs.previousFrameSetting,currentFrameSetting:r.frameChangeEventArgs.currentFrameSetting},i.isFrameBtnClick=!0):i.frameObj.radius=s,t.Browser.isDevice?document.getElementById(a+"_bottomToolbar")&&t.getComponent(a+"_bottomToolbar","toolbar").refreshOverflow():document.getElementById(a+"_toolbar")&&t.getComponent(a+"_toolbar","toolbar").refreshOverflow()}});h.appendTo("#"+a+"_frameRadiusBtn")},s.prototype.createFrameAmount=function(){var e,o=this,i=this.parent,r={frameChangeEventArgs:null},a=i.element.id,s=[{id:"1",text:this.l10n.getConstant("1")},{id:"2",text:this.l10n.getConstant("2")},{id:"3",text:this.l10n.getConstant("3")},{id:"4",text:this.l10n.getConstant("4")},{id:"5",text:this.l10n.getConstant("5")}],l=document.getElementById(a+"_frameAmountBtn"),p=document.createElement("span");p.innerHTML=this.l10n.getConstant(i.frameObj.amount.toString()),p.className="e-frame-amount",l.appendChild(p);var h=new n.DropDownButton({items:s,open:function(e){if(t.Browser.isDevice){var o=e.element.parentElement;o.style.top=h.element.getBoundingClientRect().top-o.offsetHeight+"px"}var i=h.element.childNodes[0].textContent;""!==i&&e.element.querySelector('[aria-label = "'+i+'"]').classList.add("e-selected-btn")},select:function(n){o.triggerTbarClickEvent(n),e={type:i.toPascalCase(i.frameObj.type),color:i.frameObj.color,gradientColor:i.frameObj.gradientColor,size:i.frameObj.size,inset:i.frameObj.inset,offset:i.frameObj.offset,borderRadius:i.frameObj.radius,lineCount:i.frameObj.amount,frameLineStyle:i.toPascalCase(i.frameObj.border)};var s=i.frameObj.amount,l={currObj:{}};i.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:l}}),i.frameObj.amount=parseInt(n.item.text,10),i.notify("draw",{prop:"triggerFrameChange",value:{prevFrameSettings:e,obj:r}}),r.frameChangeEventArgs&&!r.frameChangeEventArgs.cancel?(i.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"frame",previousObj:l.currObj,previousObjColl:l.currObj.objColl,previousPointColl:l.currObj.pointColl,previousSelPointColl:l.currObj.selPointColl,previousCropObj:t.extend({},i.cropObj,{},!0),previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),i.notify("draw",{prop:"render-image",value:{isMouseWheel:null,isPreventClearRect:null,isFrame:!0}}),i.notify("draw",{prop:"redrawDownScale"}),h.content=n.item.text,i.curFrameObjEvent={previousFrameSetting:r.frameChangeEventArgs.previousFrameSetting,currentFrameSetting:r.frameChangeEventArgs.currentFrameSetting},i.isFrameBtnClick=!0):i.frameObj.amount=s,t.Browser.isDevice?document.getElementById(a+"_bottomToolbar")&&t.getComponent(a+"_bottomToolbar","toolbar").refreshOverflow():document.getElementById(a+"_toolbar")&&t.getComponent(a+"_toolbar","toolbar").refreshOverflow()}});h.appendTo("#"+a+"_frameAmountBtn")},s.prototype.createFrameBorder=function(){var e,o=this,i=this.parent,r={frameChangeEventArgs:null},a=i.element.id,s=[{id:"1",text:this.l10n.getConstant("Solid")},{id:"2",text:this.l10n.getConstant("Dashed")},{id:"3",text:this.l10n.getConstant("Dotted")}],l=document.getElementById(a+"_frameBorderBtn"),p=document.createElement("span");p.innerHTML=this.l10n.getConstant(i.toPascalCase(i.frameObj.border)),p.className="e-frame-border",l.appendChild(p);var h=new n.DropDownButton({items:s,open:function(e){if(t.Browser.isDevice){var o=e.element.parentElement;o.style.top=h.element.getBoundingClientRect().top-o.offsetHeight+"px"}var i=h.element.childNodes[0].textContent;""!==i&&e.element.querySelector('[aria-label = "'+i+'"]').classList.add("e-selected-btn")},select:function(n){o.triggerTbarClickEvent(n),e={lineCount:i.frameObj.amount,color:i.frameObj.color,borderRadius:i.frameObj.radius,gradientColor:i.frameObj.gradientColor,size:i.frameObj.size,inset:i.frameObj.inset,offset:i.frameObj.offset,frameLineStyle:i.toPascalCase(i.frameObj.border),type:i.toPascalCase(i.frameObj.type)};var s=i.frameObj.border,l={currObj:{}};i.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:l}}),i.frameObj.border=n.item.text.toLowerCase(),i.notify("draw",{prop:"triggerFrameChange",value:{prevFrameSettings:e,obj:r}}),r.frameChangeEventArgs&&!r.frameChangeEventArgs.cancel?(i.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"frame",previousObj:l.currObj,previousObjColl:l.currObj.objColl,previousPointColl:l.currObj.pointColl,previousSelPointColl:l.currObj.selPointColl,previousCropObj:t.extend({},i.cropObj,{},!0),previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),i.notify("draw",{prop:"render-image",value:{isMouseWheel:null,isPreventClearRect:null,isFrame:!0}}),i.notify("draw",{prop:"redrawDownScale"}),h.content=n.item.text,i.curFrameObjEvent={previousFrameSetting:r.frameChangeEventArgs.previousFrameSetting,currentFrameSetting:r.frameChangeEventArgs.currentFrameSetting},i.isFrameBtnClick=!0):i.frameObj.border=s,t.Browser.isDevice?document.getElementById(a+"_bottomToolbar")&&t.getComponent(a+"_bottomToolbar","toolbar").refreshOverflow():document.getElementById(a+"_toolbar")&&t.getComponent(a+"_toolbar","toolbar").refreshOverflow()}});h.appendTo("#"+a+"_frameBorderBtn")},s.prototype.initFilterToolbarItem=function(){var e=this,o=this.parent,i=o.element.id,a=this.getFilterToolbarItem(),n={toolbarType:"filter",toolbarItems:a};o.trigger("toolbarUpdating",n),a=n.toolbarItems,document.querySelector("#"+i+"_contextualToolbar").classList.contains("e-control")&&t.getComponent(document.getElementById(i+"_contextualToolbar"),"toolbar").destroy();var s=new r.Toolbar({width:"100%",items:a,clicked:this.contextualToolbarClicked.bind(this),created:function(){e.updatePrivateVariables(),e.createCanvasFilter(),""===o.currentFilter&&(o.currentFilter=i+"_default");var t=document.querySelector("#"+i+"_headWrapper");t&&(t.style.display="none");var r=document.getElementById(o.currentFilter+"Canvas");r&&r.parentElement.parentElement.classList.add("e-selected"),e.enableDisableTbrBtn(),s.refreshOverflow()}});s.appendTo("#"+i+"_contextualToolbar")},s.prototype.drawDashedLine=function(e){e.beginPath(),e.setLineDash([5]),e.rect(10,10,280,130),e.stroke(),e.closePath()},s.prototype.createCanvasFilter=function(){var e=this.parent;o.showSpinner(e.element),e.element.style.opacity="0.5";var t=e.getCurrentCanvasData();this.inMemoryCanvas.width=t.width,this.inMemoryCanvas.height=t.height,this.inMemoryContext.putImageData(t,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"),o.hideSpinner(e.element),e.element.style.opacity="1",e.initialAdjustmentValue=this.lowerContext.filter},s.prototype.updateFilterCanvas=function(e,t){var o=this.parent,i=o.element.querySelector("#"+o.element.id+e);if(i){var r=i.getContext("2d");r=i.getContext("2d"),i.style.width="100px",i.style.height="100px",o.notify("filter",{prop:"updateAdj",value:{type:t,value:null,isPreview:!0,ctx:r}}),r.drawImage(this.inMemoryCanvas,0,0,300,150),o.isSafari&&o.notify("filter",{prop:"apply-filter",onPropertyChange:!1,value:{context:r}})}},s.prototype.getQuickAccessToolbarItem=function(e){var o=this.parent,i=o.element.id,r={cancel:!1,toolbarItems:[]},a=[];t.isNullOrUndefined(e)?("image"===o.activeObj.shape&&a.push("Flip"),"redact"!==o.activeObj.shape&&a.push("BringToFront"),a.push("Clone"),a.push("Delete"),"text"===o.activeObj.shape&&a.push("EditText"),r.shape=o.toPascalCase(o.activeObj.shape)):e&&(a.push("BringToFront"),a.push("Delete"),r.shape="Freehand draw"),r.toolbarItems=t.extend([],a,null,!0),o.trigger("quickAccessToolbarOpen",r);var n=[];if(r.cancel)n=[];else for(var s=0;s<r.toolbarItems.length;s++)switch(r.toolbarItems[s]){case"BringToFront":n.push({id:i+"_bringToFront",prefixIcon:"e-icons e-bring-to-front",tooltipText:this.l10n.getConstant("BringToFront"),align:"Left"});break;case"Clone":n.push({id:i+"_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+"_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+"_editText",prefixIcon:"e-icons e-annotation-edit",cssClass:"top-icon e-annotation-edit",tooltipText:this.l10n.getConstant("EditText"),align:"Left"});break;case"Flip":n.push({id:i+"_hFlip",prefixIcon:"e-icons e-horizontal-flip",tooltipText:this.l10n.getConstant("HorizontalFlip"),align:"Left"}),n.push({id:i+"_vFlip",prefixIcon:"e-icons e-vertical-flip",tooltipText:this.l10n.getConstant("VerticalFlip"),align:"Left"});break;default:n.push(r.toolbarItems[s])}return n},s.prototype.renderQAT=function(e){var o=this.parent,i=o.element.id;if(o.activeObj&&o.showQuickAccessToolbar){var a=document.getElementById(i+"_quickAccessToolbarArea");a&&(this.destroyQuickAccessToolbar(),a.style.display="block");var n=this.getQuickAccessToolbarItem(e);if(0===n.length)return;t.isNullOrUndefined(o.quickAccessToolbarTemplate)&&new r.Toolbar({items:n,clicked:this.quickAccessToolbarClicked.bind(this)}).appendTo("#"+i+"_quickAccessToolbar");var s=this.toolbarHeight&&0!==this.toolbarHeight?this.toolbarHeight:a.clientHeight,l=o.element.querySelector("#"+i+"_headWrapper");if(t.isNullOrUndefined(e)&&(0!==o.activeObj.activePoint.width||0!==o.activeObj.activePoint.height||o.activeObj.shape&&"path"===o.activeObj.shape&&o.activeObj.pointColl.length>0)){f={order:null};o.notify("shape",{prop:"getHighestOrder",onPropertyChange:!1,value:{obj:f}}),o.activeObj.order>f.order&&document.getElementById(o.element.id+"_bringToFront")?document.getElementById(o.element.id+"_bringToFront").classList.add("e-overlay"):document.getElementById(o.element.id+"_bringToFront")&&document.getElementById(o.element.id+"_bringToFront").classList.remove("e-overlay"),a.style.width="auto",o.activeObj.activePoint.width=Math.abs(o.activeObj.activePoint.width),o.activeObj.activePoint.height=Math.abs(o.activeObj.activePoint.height);var p=o.activeObj.activePoint.startX<o.activeObj.activePoint.endX?o.activeObj.activePoint.startX:o.activeObj.activePoint.endX,h=o.activeObj.activePoint.startY<o.activeObj.activePoint.endY?o.activeObj.activePoint.startY:o.activeObj.activePoint.endY,d=o.activeObj.activePoint.width;if(0!==o.activeObj.rotatedAngle&&"arrow"!==o.activeObj.shape){var c={activePoint:null};o.notify("shape",{prop:"getSquarePointForRotatedShape",onPropertyChange:!1,value:{obj:o.activeObj,object:c}}),p=(b=c.activePoint).startX,h=b.startY,d=b.width}else if("path"===o.activeObj.shape){var u=o.getSquarePointForPath(o.activeObj);p=u.startX,h=u.startY,d=u.width}if(a.style.left=p+d/2-25*n.length+"px",parseFloat(a.style.left)+a.clientWidth/2!==p+d/2){var v=p+d/2-(parseFloat(a.style.left)+a.clientWidth/2);a.style.left=parseFloat(a.style.left)+v+"px"}l&&(s=l.offsetHeight+s),h-(s+s/1.5)<o.img.destTop?(a.style.top=o.img.destTop+"px",l&&(a.style.top=(o.img.destTop<0?0:o.img.destTop)+l.offsetHeight+"px")):(s=this.toolbarHeight,a.style.top=h-(s+s/1.5)+"px")}else if(e){var g={freehandSelectedIndex:-1};o.notify("freehand-draw",{prop:"getFreehandSelectedIndex",onPropertyChange:!1,value:{obj:g}});var f={order:null};o.notify("shape",{prop:"getHighestOrder",onPropertyChange:!1,value:{obj:f}}),o.getObjFromId(o.pointColl[g.freehandSelectedIndex].id).order>=f.order&&document.getElementById(o.element.id+"_bringToFront")?document.getElementById(o.element.id+"_bringToFront").classList.add("e-overlay"):document.getElementById(o.element.id+"_bringToFront")&&document.getElementById(o.element.id+"_bringToFront").classList.remove("e-overlay");var C={activePoint:null};o.notify("freehand-draw",{prop:"getSqPtFD",value:{idx:g.freehandSelectedIndex,obj:C}});var b=C.activePoint;a.style.width="auto",a.style.left=b.startX+b.width/2-24*n.length+"px",b.startY-(s+s/1.5)<o.img.destTop?a.style.top=o.img.destTop+"px":a.style.top=b.startY-(s+s/1.5)+"px"}else a.style.display="none";parseFloat(a.style.top)<0&&(a.style.top="0px")}},s.prototype.refreshDropDownBtn=function(e){if(!t.isNullOrUndefined(e)){var o=this.parent.element.id,i=document.querySelector("#"+o+"_annotationBtn");i&&(e?(i.classList.add("e-disabled"),i.parentElement.classList.add("e-overlay")):(i.classList.remove("e-disabled"),i.parentElement.classList.remove("e-overlay")),t.getComponent(i,"dropdown-btn").disabled=e);var r=document.querySelector("#"+o+"_transformBtn");r&&(e?(r.classList.add("e-disabled"),r.parentElement.classList.add("e-overlay")):(r.classList.remove("e-disabled"),r.parentElement.classList.remove("e-overlay")),t.getComponent(r,"dropdown-btn").disabled=e);var a=document.querySelector("#"+o+"_adjustment");a&&(e?(a.classList.add("e-disabled"),a.parentElement.classList.add("e-overlay")):(a.classList.remove("e-disabled"),a.parentElement.classList.remove("e-overlay")),t.getComponent(a,"btn").disabled=e);var n=document.querySelector("#"+o+"_filter");n&&(e?(n.classList.add("e-disabled"),n.parentElement.classList.add("e-overlay")):(n.classList.remove("e-disabled"),n.parentElement.classList.remove("e-overlay")),t.getComponent(n,"btn").disabled=e)}},s.prototype.cropSelect=function(e){var o=this.parent;o.isCropTab=!0,t.isNullOrUndefined(o.transform.cropZoomFactor)&&(o.transform.cropZoomFactor=o.transform.zoomFactor,o.notify("draw",{prop:"setTempZoomFactor",onPropertyChange:!1,value:{tempZoomFactor:o.transform.zoomFactor}})),o.transform.zoomFactor=o.transform.cropZoomFactor;var i=e.item.id;this.currentToolbar="crop",o.currSelectionPoint=null,o.notify("draw",{prop:"setIsCropSelect",value:{bool:!0}});var r={prevObj:null};o.notify("crop",{prop:"getPreviousCropCurrentObj",value:{obj:r}}),o.notify("draw",{prop:"select",onPropertyChange:!1,value:{type:i,startX:null,startY:null,width:null,height:null}}),o.notify("crop",{prop:"setPreviousCropCurrentObj",value:{obj:r.prevObj}}),this.enableDisableTbrBtn(),o.notify("transform",{prop:"disableZoomOutBtn",value:{isZoomOut:!0}})},s.prototype.quickAccessToolbarClicked=function(e,o){var i=this.parent,r=i.element.id;if(e.item){var a=null,n={prevActObj:null},s={tempObj:null};i.notify("draw",{prop:"getPrevActObj",onPropertyChange:!1,value:{obj:n}}),i.notify("selection",{prop:"getTempActObj",onPropertyChange:!1,value:{obj:s}}),s.tempObj.activePoint.height=Math.abs(s.tempObj.activePoint.height);var l={isNewPath:null},p=void 0;i.notify("draw",{prop:"getNewPath",value:{obj:l}});var h=e.item.id.replace(r+"_","").toLowerCase(),d=void 0,c=void 0,u={freehandSelectedIndex:null},v=void 0,g=void 0,f={order:null};switch(h){case"duplicate":i.element.querySelector("#"+r+"_duplicate").classList.contains("e-overlay")||(this.refreshSlider(),l.isNewPath||JSON.stringify(s.tempObj)!==JSON.stringify(i.activeObj)||(a=!0),this.duplicateShape(a));break;case"remove":i.element.querySelector("#"+r+"_remove").classList.contains("e-overlay")||(i.noPushUndo=!1,this.refreshSlider(),i.notify("selection",{prop:"deleteItem",onPropertyChange:!1}));break;case"edittext":i.element.querySelector("#"+r+"_editText").classList.contains("e-overlay")||this.editText();break;case"rotleft":case"rotright":d=i.element.querySelector("#"+r+"_rotLeft"),c=i.element.querySelector("#"+r+"_rotRight"),(d&&!d.classList.contains("e-disabled")||c&&!c.classList.contains("e-disabled"))&&i.rotateImage(e.item.id.replace(r+"_","").toLowerCase()),i.notify("undo-redo",{prop:"updateUndoRedoStack",onPropertyChange:!1});break;case"hflip":i.element.querySelector("#"+r+"_hFlip").classList.contains("e-disabled")||(p=i.activeObj.imageCanvas.getContext("2d"),i.horizontalFlip(p)),i.notify("undo-redo",{prop:"updateUndoRedoStack",onPropertyChange:!1});break;case"vflip":i.element.querySelector("#"+r+"_vFlip").classList.contains("e-disabled")||(p=i.activeObj.imageCanvas.getContext("2d"),i.verticalFlip(p)),i.notify("undo-redo",{prop:"updateUndoRedoStack",onPropertyChange:!1});break;case"bringtofront":if(!i.element.querySelector("#"+r+"_bringToFront").classList.contains("e-overlay")){if(i.notify("freehand-draw",{prop:"getFreehandSelectedIndex",onPropertyChange:!1,value:{obj:u}}),v=null!==u.freehandSelectedIndex?i.pointColl[u.freehandSelectedIndex].id:i.activeObj.currIndex,i.updateShapeOrder(v,h),g=!1,i.notify("shape",{prop:"getHighestOrder",onPropertyChange:!1,value:{obj:f}}),v.indexOf("pen")>-1)i.notify("shape",{prop:"updateShapeColl",onPropertyChange:!1}),g=(C=i.getObjFromId(v).order)>=f.order;else{var C=i.getObjFromId(v).order;g=C>f.order}g?document.getElementById(i.element.id+"_bringToFront").classList.add("e-overlay"):document.getElementById(i.element.id+"_bringToFront").classList.remove("e-overlay"),i.notify("undo-redo",{prop:"updateUndoRedoStack",onPropertyChange:!1})}}"duplicate"!==h&&"remove"!==h||i.notify("draw",{prop:"redrawDownScale"})}t.isNullOrUndefined(o)&&i.trigger("quickAccessToolbarItemClick",e)},s.prototype.editText=function(){var e=this.parent,o={x:e.activeObj.activePoint.startX,y:e.activeObj.activePoint.startY};if(this.upperContext.clearRect(0,0,e.upperCanvas.width,e.upperCanvas.height),e.notify("selection",{prop:"setTempActObj",onPropertyChange:!1,value:{obj:t.extend({},e.activeObj,{},!0)}}),e.notify("selection",{prop:"setInitialTextEdit",onPropertyChange:!1,value:{bool:!0}}),e.notify("draw",{prop:"setPrevActObj",onPropertyChange:!1,value:{prevActObj:t.extend({},e.activeObj,{},!0)}}),0!==e.activeObj.rotatedAngle){var i={x:o.x,y:o.y};e.notify("shape",{prop:"getTextBoxPosition",onPropertyChange:!1,value:{obj:e.activeObj,object:i}}),o.x=i.x,o.y=i.y;var r={x:o.x,y:o.y};e.notify("shape",{prop:"setFlipState",onPropertyChange:!1,value:{x:o.x,y:o.y,obj:e.activeObj,object:r}}),o.x=r.x,o.y=r.y}var a=t.extend({},e.activeObj,{},!0);e.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),this.upperContext.clearRect(0,0,e.upperCanvas.width,e.upperCanvas.height),this.lowerContext.clearRect(0,0,e.upperCanvas.width,e.upperCanvas.height),e.notify("draw",{prop:"redrawImgWithObj",onPropertyChange:!1}),e.notify("draw",{prop:"redrawDownScale"}),e.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.lowerContext}}),e.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.upperContext}}),e.activeObj=a,e.notify("shape",{prop:"renderTextArea",onPropertyChange:!1,value:{x:o.x,y:o.y,actObj:e.activeObj}}),t.isNullOrUndefined(e.activeObj.currIndex)&&e.notify("draw",{prop:"setShapeTextInsert",onPropertyChange:!1,value:{bool:!0}}),document.getElementById(e.element.id+"_quickAccessToolbarArea")&&(document.getElementById(e.element.id+"_quickAccessToolbarArea").style.display="none")},s.prototype.duplicateShape=function(e,o){var i=this.parent,r={activePoint:{startX:0,startY:0,endX:0,endY:0,width:0,height:0},flipObjColl:[],triangle:[],triangleRatio:[]};i.notify("selection",{prop:"setTempActObj",onPropertyChange:!1,value:{obj:r}});var a={prevActObj:null};i.notify("draw",{prop:"getPrevActObj",onPropertyChange:!1,value:{obj:a}});var n={isNewPath:null};i.notify("draw",{prop:"getNewPath",value:{obj:n}});var s,l=t.extend({},i.activeObj,{},!0),p={order:null};i.notify("shape",{prop:"getHighestOrder",onPropertyChange:!1,value:{obj:p}}),l.order?(i.notify("shape",{prop:"updateShapeColl",onPropertyChange:!1}),l.order=p.order>l.order?p.order+1:l.order+1):(i.noPushUndo=!0,i.okBtn(),i.noPushUndo=!1,i.selectShape(l.currIndex),l.order=p.order>l.order?p.order+1:l.order+1),"image"===l.shape&&(s=t.extend([],i.objColl,[],!0),i.notify("undo-redo",{prop:"updateUrObj",onPropertyChange:!1,value:{objColl:s}})),t.isNullOrUndefined(i.activeObj.currIndex)?i.notify("shape",{prop:"applyActObj",onPropertyChange:!1,value:{isMouseDown:e}}):a.prevActObj||o?(i.activeObj.currIndex=null,l.currIndex=null,i.notify("shape",{prop:"applyActObj",onPropertyChange:!1,value:{isMouseDown:e}})):i.notify("shape",{prop:"applyActObj",onPropertyChange:!1,value:{isMouseDown:!0}});var h=i.noPushUndo;if(i.noPushUndo=!1,i.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"ok"}}),i.noPushUndo=h,s=t.extend([],i.objColl,[],!0),l.activePoint.startX+=10,l.activePoint.startY-=10,l.activePoint.endX+=10,l.activePoint.endY-=10,"path"===l.shape)for(var d=0;d<l.pointColl.length;d++)l.pointColl[d].x+=10,l.pointColl[d].y-=10;else"image"===l.shape&&(l.imageCanvas=i.createElement("canvas"));var c={id:"shape_"+(i.objColl.length+1)};if(i.notify("shape",{prop:"getNewShapeId",onPropertyChange:!1,value:{obj:c}}),l.currIndex=c.id,i.activeObj=t.extend({},l,{},!0),"image"===i.activeObj.shape){var u=t.extend({},l.activePoint,{},!0),v={width:0,height:0};i.notify("transform",{prop:"calcMaxDimension",onPropertyChange:!1,value:{width:i.activeObj.imageElement.width,height:i.activeObj.imageElement.height,obj:v,isImgShape:null}}),i.activeObj.activePoint.width=v.width,i.activeObj.activePoint.height=v.height,i.activeObj.isHorImageFlip&&i.activeObj.isVerImageFlip?(i.activeObj.isHorImageFlip=i.activeObj.isVerImageFlip=!1,i.notify("draw",{prop:"downScaleImgCanvas",onPropertyChange:!1,value:{ctx:l.imageCanvas.getContext("2d"),isImgAnnotation:!0,isHFlip:!0,isVFlip:!0}}),i.activeObj.isHorImageFlip=i.activeObj.isVerImageFlip=!0):i.activeObj.isHorImageFlip?(i.activeObj.isHorImageFlip=!1,i.notify("draw",{prop:"downScaleImgCanvas",onPropertyChange:!1,value:{ctx:l.imageCanvas.getContext("2d"),isImgAnnotation:!0,isHFlip:!0,isVFlip:null}}),i.activeObj.isHorImageFlip=!0):i.activeObj.isVerImageFlip?(i.activeObj.isVerImageFlip=!1,i.notify("draw",{prop:"downScaleImgCanvas",onPropertyChange:!1,value:{ctx:l.imageCanvas.getContext("2d"),isImgAnnotation:!0,isHFlip:null,isVFlip:!0}}),i.activeObj.isVerImageFlip=!0):i.notify("draw",{prop:"downScaleImgCanvas",onPropertyChange:!1,value:{ctx:l.imageCanvas.getContext("2d"),isImgAnnotation:!0,isHFlip:null,isVFlip:null}}),i.activeObj.activePoint=u}"line"!==i.activeObj.shape&&"arrow"!==i.activeObj.shape||i.notify("shape",{prop:"setPointCollForLineArrow",onPropertyChange:!1,value:{obj:i.activeObj}}),i.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate",obj:i.activeObj,isCropRatio:null,points:null,isPreventDrag:!0}}),i.notify("undo-redo",{prop:"updateUrObj",onPropertyChange:!1,value:{objColl:s}}),i.notify("shape",{prop:"applyActObj",onPropertyChange:!1,value:{isMouseDown:!0}}),i.noPushUndo=!1,i.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"ok"}}),i.noPushUndo=!0,i.notify("selection",{prop:"redrawShape",onPropertyChange:!1,value:{obj:i.objColl[i.objColl.length-1]}});var g=i.element.id,f=t.Browser.isDevice?"#"+g+"_bottomToolbar #"+g:"#"+g,C={freehandDrawSelectedId:null};i.notify("freehand-draw",{prop:"getFreehandDrawSelectedId",onPropertyChange:!1,value:{obj:C}}),this.enableDisableCloneBtn(f,C),this.renderQAT(),i.activeObj.shape&&"redact"===i.activeObj.shape&&this.redactSlider(i.activeObj.redactType)},s.prototype.defToolbarClicked=function(e){var o=this.parent,i=o.element.id,r=!1,a=!1;if(!this.isFrameToolbar&&o.element.querySelector(".e-contextual-toolbar-wrapper")){o.element.querySelector(".e-contextual-toolbar-wrapper").classList.contains("e-hide")||(r=a=!0);var n={bool:o.isStraightening};(!t.Browser.isDevice||t.Browser.isDevice&&!n.bool)&&o.element.querySelector(".e-contextual-toolbar-wrapper").classList.add("e-hide")}if(e.item){var s=e.item.id.replace(i+"_","").toLowerCase();if("duplicate"===s||"remove"===s||"edittext"===s||"hflip"===s||"vflip"===s||"rotleft"===s||"rotright"===s)this.quickAccessToolbarClicked(e,!0),o.trigger("toolbarItemClicked",e);else{var l=!1,p=!1,h=document.querySelector("#"+i+"_adjustment");h&&h.classList.contains("e-disabled")&&(p=!0);var d=document.querySelector("#"+i+"_filter");d&&d.classList.contains("e-disabled")&&(l=!0),this.enableDisableTbrBtn(),this.performDefTbrClick(s,r,p,l,a),o.trigger("toolbarItemClicked",e),o.isStraightening&&o.notify("transform",{prop:"disableZoomOutBtn",value:{isZoomOut:!0}}),-1!==["undo","redo","cancel","aspectratio","nonaspectratio","save","duplicate","filter","frame","none","mat","bevel","line","inset","hook","resize","remove"].indexOf(s)&&o.notify("draw",{prop:"redrawDownScale"})}}},s.prototype.performDefTbrClick=function(e,i,r,a,n){var s,l,p,h=this.parent,d=h.element.id,c=h.element.querySelector("#"+d+"_zoomIn"),u=h.element.querySelector("#"+d+"_resizeHeight"),v=h.element.querySelector("#"+d+"_resizeWidth"),g=!1;if(void 0!==h.activeObj.shape&&(l=h.activeObj.shape.split("-")),void 0===l&&h.currObjType.isCustomCrop?g=!0:void 0!==l&&"crop"===l[0]&&(g=!0),!h.disabled)switch(e){case"pan":h.currObjType.isCustomCrop=h.currObjType.isFiltered=!1,h.currObjType.isRedact=!1,h.currObjType.isUndoAction&&h.notify("undo-redo",{prop:"refreshUrc",value:{bool:null}}),g&&(h.currObjType.isCustomCrop=!1,h.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),this.upperContext.clearRect(0,0,h.upperCanvas.width,h.upperCanvas.height),this.refreshToolbar("main")),h.togglePan?(this.cancelPan(),h.notify("transform",{prop:"setDisablePan",onPropertyChange:!1,value:{bool:!0}}),"pen"===this.currentToolbar&&h.freeHandDraw(!0)):((s=h.element.querySelector(".e-img-pan .e-btn"))&&s.classList.add("e-selected-btn"),h.pan(!0),h.notify("transform",{prop:"setDisablePan",onPropertyChange:!1,value:{bool:!1}})),c&&h.zoomSettings.zoomFactor>=h.zoomSettings.maxZoomFactor?(c.classList.add("e-disabled"),c.parentElement.classList.add("e-overlay")):c&&(c.classList.remove("e-disabled"),c.parentElement.classList.remove("e-overlay")),this.refreshToolbar("main");break;case"cancel":h.currObjType.isRedact&&(h.currObjType.isRedact=!1),this.isFrameToolbar&&h.element.querySelector(".e-contextual-toolbar-wrapper")&&!h.element.querySelector(".e-contextual-toolbar-wrapper").classList.contains("e-hide")&&h.element.querySelector(".e-contextual-toolbar-wrapper").classList.add("e-hide"),h.notify("draw",{prop:"performCancel",value:{isContextualToolbar:i,isFinalCancel:!0}});break;case"ok":t.Browser.isDevice&&this.isFrameToolbar&&h.element.querySelector(".e-contextual-toolbar-wrapper")&&!h.element.querySelector(".e-contextual-toolbar-wrapper").classList.contains("e-hide")&&h.element.querySelector(".e-contextual-toolbar-wrapper").classList.add("e-hide"),h.okBtn(null,!0),h.drawingShape=null,this.refreshDropDownBtn(!1),this.currentToolbar="main",h.isStraightening=!1,h.notify("draw",{prop:"resetTempObjColl"}),h.notify("draw",{prop:"resetTempPointColl"});break;case"crop":h.notify("transform",{prop:"disableZoomOutBtn",value:{isZoomOut:!0}}),t.Browser.isDevice&&this.updateContextualToolbar("color","straighten");break;case"reset":h.reset(),this.imageHeight=null,this.imageWidth=null,h.aspectHeight=null,h.aspectWidth=null,this.isAspectRatio=!0,this.currentToolbar="main";break;case"undo":h.noPushUndo=!1,(h.togglePen||h.drawingShape)&&(h.okBtn(),h.drawingShape=null),h.notify("undo-redo",{prop:"call-undo"});break;case"redo":h.noPushUndo=!1,(h.togglePen||h.drawingShape)&&(h.okBtn(),h.drawingShape=null),h.notify("undo-redo",{prop:"call-redo"});break;case"aspectratio":(!h.isCircleCrop&&t.isNullOrUndefined(h.currSelectionPoint)||h.currSelectionPoint&&"crop-circle"!==h.currSelectionPoint.shape)&&(t.getComponent(v,"numerictextbox").value?(h.aspectWidth=t.getComponent(v,"numerictextbox").value,h.aspectHeight=t.getComponent(u,"numerictextbox").value,h.notify("transform",{prop:"resize",value:{width:h.aspectWidth,height:null,isAspectRatio:!0}})):t.getComponent(u,"numerictextbox").value&&(h.aspectWidth=parseFloat(t.getComponent(v,"numerictextbox").placeholder),h.aspectHeight=t.getComponent(u,"numerictextbox").value,h.notify("transform",{prop:"resize",value:{width:h.aspectWidth,height:h.aspectHeight,isAspectRatio:!0}})),h.resizeSrc={startX:h.img.srcLeft,startY:h.img.srcTop,width:h.img.srcWidth,height:h.img.srcHeight},this.refreshToolbar("resize"));break;case"nonaspectratio":(t.getComponent(v,"numerictextbox").value||t.getComponent(u,"numerictextbox").value)&&(h.aspectWidth=t.getComponent(v,"numerictextbox").value?t.getComponent(v,"numerictextbox").value:parseFloat(t.getComponent(v,"numerictextbox").placeholder),h.aspectHeight=t.getComponent(u,"numerictextbox").value?t.getComponent(u,"numerictextbox").value:parseFloat(t.getComponent(u,"numerictextbox").placeholder),h.notify("transform",{prop:"resize",value:{width:h.aspectWidth,height:h.aspectHeight,isAspectRatio:!1}})),h.resizeSrc={startX:h.img.srcLeft,startY:h.img.srcTop,width:h.img.srcWidth,height:h.img.srcHeight},this.refreshToolbar("resize");break;case"resize":(h.currObjType.isFiltered||h.currObjType.isRedact)&&h.okBtn(),this.resizeClick();break;case"adjustment":r||((h.currObjType.isFiltered||h.currObjType.isRedact)&&h.okBtn(),this.refreshToolbar("adjustment"),h.setTempFilterProperties(),h.notify("draw",{prop:"updateFinetune"}),h.notify("filter",{prop:"setTempAdjVal"}),this.openSlider("brightness"));break;case"brightness":case"contrast":case"hue":case"saturation":case"opacity":case"blur":case"exposure":this.openSlider(e);break;case"filter":a||(o.showSpinner(h.element),this.refreshToolbar("filter"),h.setTempFilterProperties(),o.hideSpinner(h.element));break;case"default":case"chrome":case"cold":case"warm":case"grayscale":case"blackandwhite":case"sepia":case"invert":case"sharpen":h.currObjType.isFiltered=!0,h.notify("filter",{prop:"applyImageFilter",value:{option:e}});break;case"upload":n&&h.element.querySelector(".e-contextual-toolbar-wrapper").classList.remove("e-hide");break;case"bold":h.notify("selection",{prop:"setInitialTextEdit",value:{bool:!1}}),h.activeObj.textSettings.bold&&h.activeObj.textSettings.italic?h.notify("shape",{prop:"applyFontStyle",onPropertyChange:!1,value:{item:"italic"}}):h.activeObj.textSettings.bold&&!h.activeObj.textSettings.italic?h.notify("shape",{prop:"applyFontStyle",onPropertyChange:!1,value:{item:"default"}}):!h.activeObj.textSettings.bold&&h.activeObj.textSettings.italic?h.notify("shape",{prop:"applyFontStyle",onPropertyChange:!1,value:{item:"bolditalic"}}):h.activeObj.textSettings.bold||h.activeObj.textSettings.italic||h.notify("shape",{prop:"applyFontStyle",onPropertyChange:!1,value:{item:"bold"}}),h.element.querySelector("#"+d+"_bold").classList.contains("e-selected-btn")?h.element.querySelector("#"+d+"_bold").classList.remove("e-selected-btn"):h.element.querySelector("#"+d+"_bold").classList.add("e-selected-btn"),0===h.activeObj.activePoint.width&&0===h.activeObj.activePoint.height||h.notify("undo-redo",{prop:"updateUndoRedoStack",onPropertyChange:!1});break;case"italic":h.notify("selection",{prop:"setInitialTextEdit",value:{bool:!1}}),h.activeObj.textSettings.bold&&h.activeObj.textSettings.italic?h.notify("shape",{prop:"applyFontStyle",onPropertyChange:!1,value:{item:"bold"}}):h.activeObj.textSettings.bold&&!h.activeObj.textSettings.italic?h.notify("shape",{prop:"applyFontStyle",onPropertyChange:!1,value:{item:"bolditalic"}}):!h.activeObj.textSettings.bold&&h.activeObj.textSettings.italic?h.notify("shape",{prop:"applyFontStyle",onPropertyChange:!1,value:{item:"default"}}):h.activeObj.textSettings.bold||h.activeObj.textSettings.italic||h.notify("shape",{prop:"applyFontStyle",onPropertyChange:!1,value:{item:"italic"}}),h.element.querySelector("#"+d+"_italic").classList.contains("e-selected-btn")?h.element.querySelector("#"+d+"_italic").classList.remove("e-selected-btn"):h.element.querySelector("#"+d+"_italic").classList.add("e-selected-btn"),0===h.activeObj.activePoint.width&&0===h.activeObj.activePoint.height||h.notify("undo-redo",{prop:"updateUndoRedoStack",onPropertyChange:!1});break;case"croptransform":this.performCropTransformClick();break;case"rotateleft":case"rotateright":case"horizontalflip":case"verticalflip":h.transformSelect(e),this.updateRedactObj(),"rotateleft"!==e&&"rotateright"!==e||(h.notify("draw",{prop:"resetStraightenDestPoints"}),h.notify("draw",{prop:"setDestForStraighten"})),h.notify("transform",{prop:"disableZoomOutBtn",value:{isZoomOut:!0}}),t.Browser.isDevice&&this.updateContextualToolbar("color","straighten"),p={action:"rotateleft"===e||"rotateright"===e?"rotate":"flip",actionEventArgs:h.editCompleteArgs},h.triggerEditCompleteEvent(p);break;case"save":h.noPushUndo=!1,h.okBtn(),h.drawingShape=null,this.saveDialogPopup();break;case"transparency":this.updateContextualToolbar("transparency","transparency");break;case"frame":this.frameToolbarClick();break;case"none":case"mat":case"bevel":case"line":case"inset":case"hook":this.unselectFrameBtn(),h.element.querySelector("#"+d+"_"+e)&&h.element.querySelector("#"+d+"_"+e).classList.add("e-selected-btn"),h.frameObj.type=e,h.frameObj.size=20,h.frameObj.inset=20,h.frameObj.radius=0,h.frameObj.amount=1,h.frameObj.offset="inset"===e?60:20,this.refreshToolbar("frame"),h.notify("draw",{prop:"render-image",value:{isMouseWheel:null,isPreventClearRect:null,isFrame:!0}}),h.isFrameBtnClick=!0,h.curFrameObjEvent={previousFrameSetting:h.tempFrameObj,currentFrameSetting:h.frameObj};break;case"redact":h.currObjType.isRedact=!0,h.drawingShape="redact",t.isNullOrUndefined(h.activeObj.redactBlur)&&(h.activeObj.redactBlur=20),t.isNullOrUndefined(h.activeObj.redactPixelate)&&(h.activeObj.redactPixelate=20),h.notify("selection",{prop:"annotate",value:{shape:"redact"}}),this.refreshToolbar("redact"),this.redactSlider(h.activeObj.redactType);break;case"pixelate":if(h.currObjType.isRedact=!0,h.drawingShape="redact",h.notify("selection",{prop:"annotate",value:{shape:"redact"}}),"blur"===h.activeObj.redactType&&this.updateRedactType("pixelate"),h.notify("shape",{prop:"setRedactType",onPropertyChange:!1,value:{redactType:"pixelate"}}),"pixelate"===h.activeObj.redactType){var f=h.element.querySelector("#"+d+"_pixelate"),C=h.element.querySelector("#"+d+"_redactBlur");f&&f.classList.add("e-selected-btn"),C&&C.classList.contains("e-selected-btn")&&C.classList.remove("e-selected-btn")}else(C=h.element.querySelector("#"+d+"_redactBlur"))&&C.classList.add("e-selected-btn");this.redactSlider(h.activeObj.redactType),0===h.activeObj.activePoint.width&&0===h.activeObj.activePoint.height||h.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"shapeTransform",previousObj:null,previousObjColl:null,previousPointColl:null,previousSelPointColl:null,previousCropObj:null,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}});break;case"redactblur":if(h.currObjType.isRedact=!0,h.drawingShape="redact",h.notify("selection",{prop:"annotate",value:{shape:"redact"}}),h.notify("shape",{prop:"setRedactType",onPropertyChange:!1,value:{redactType:"blur"}}),"pixelate"===h.activeObj.redactType&&this.updateRedactType("blur"),h.notify("shape",{prop:"setRedactType",onPropertyChange:!1,value:{redactType:"blur"}}),"blur"===h.activeObj.redactType){var C=h.element.querySelector("#"+d+"_redactBlur"),f=h.element.querySelector("#"+d+"_pixelate");C&&C.classList.add("e-selected-btn"),f&&f.classList.contains("e-selected-btn")&&f.classList.remove("e-selected-btn")}else(f=h.element.querySelector("#"+d+"_pixelate"))&&f.classList.add("e-selected-btn");this.redactSlider(h.activeObj.redactType),0===h.activeObj.activePoint.width&&0===h.activeObj.activePoint.height||h.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"shapeTransform",previousObj:null,previousObjColl:null,previousPointColl:null,previousSelPointColl:null,previousCropObj:null,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}})}},s.prototype.updateRedactType=function(e){var t=this.parent;t.activeObj.redactType=e,t.notify("shape",{prop:"setRedactType",value:{type:e}}),this.parent.objColl.push(t.activeObj),t.notify("selection",{prop:"redrawShape",value:{obj:t.objColl[t.objColl.length-1]}})},s.prototype.frameToolbarClick=function(){var e,o,i,r=this.parent,a=r.element.id,n=document.querySelector("#"+a+"_frame");r.notify("draw",{prop:"updateCropSelection",onPropertyChange:!1}),(r.currObjType.isFiltered||r.currObjType.isRedact)&&r.okBtn(),n&&!n.classList.contains("e-overlay")&&(e=r.transform.zoomFactor,r.frameDestPoints=t.extend({},r.img,{},!0),t.isNullOrUndefined(r.cxtTbarHeight)&&(o=t.extend({},r.frameObj,{},!0),i=t.extend({},r.tempFrameObj,{},!0),this.callFrameToolbar(),r.frameObj.type="mat",this.callFrameToolbar(),r.cxtTbarHeight=r.element.querySelector("#"+a+"_customizeWrapper").scrollHeight,r.frameObj=o,r.tempFrameObj=i),this.zoomToFrameRange(),r.tempFrameZoomLevel=e,t.Browser.isDevice?r.img.destTop-=r.cxtTbarHeight/2:r.img.destTop+=r.cxtTbarHeight/2,this.callFrameToolbar())},s.prototype.zoomToFrameRange=function(){var e=this.parent;this.isFrameToolbar=!1,e.notify("transform",{prop:"resetZoom",onPropertyChange:!1});for(var t=!0;t;){if(this.toolbarHeight+e.img.destTop>=this.toolbarHeight+e.cxtTbarHeight){t=!1;break}e.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:-.1,zoomPoint:null,isResize:!0}})}this.isFrameToolbar=!0},s.prototype.resizeClick=function(){var e=this.parent;e.notify("draw",{prop:"updateCropSelection",onPropertyChange:!1}),e.upperCanvas.style.cursor="default",e.notify("transform",{prop:"updateResize",value:{bool:!1}}),this.isAspectRatio?this.isAspectRatio=!1:this.isAspectRatio=!0,e.isResize=!0,this.refreshToolbar("resize")},s.prototype.callFrameToolbar=function(){var e=this.parent;t.extend(e.tempFrameObj,e.frameObj);var o={appliedUndoRedoColl:[]};if(e.notify("undo-redo",{prop:"getAppliedUndoRedoColl",value:{obj:o}}),0===o.appliedUndoRedoColl.length){var i={currObj:{}};e.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:i}}),e.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"frame",previousObj:i.currObj,previousObjColl:i.currObj.objColl,previousPointColl:i.currObj.pointColl,previousSelPointColl:i.currObj.selPointColl,previousCropObj:t.extend({},e.cropObj,{},!0),previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}})}this.refreshToolbar("frame")},s.prototype.contextualToolbarClicked=function(e){var t=this.parent,o=t.element.querySelector(".e-contextual-toolbar-wrapper .e-toolbar-item.e-selected");o&&o.classList.remove("e-selected");var i=e.item.id.replace(t.element.id,"").split("_")[1],r={filter:t.toPascalCase(i),cancel:!1};t.trigger("imageFiltering",r),t.editCompleteArgs=r,r.cancel||(document.getElementById(e.item.id+"Canvas").parentElement.parentElement.classList.add("e-selected"),t.currObjType.isFiltered=!0,t.notify("filter",{prop:"applyImageFilter",value:{option:i.toLowerCase()}}),t.notify("draw",{prop:"redrawDownScale"}),t.currentFilter=e.item.id,this.enableDisableTbrBtn(),t.isFilterCanvasClick=!0,t.curFilterObjEvent=r)},s.prototype.refreshShapeDrawing=function(){var e=this.parent,t={shape:""};e.notify("selection",{prop:"getCurrentDrawingShape",onPropertyChange:!1,value:{obj:t}}),""!==t.shape&&(e.notify("selection",{prop:"setCurrentDrawingShape",onPropertyChange:!1,value:{value:""}}),e.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),this.refreshToolbar("main",!1))},s.prototype.zoomInBtnClickHandler=function(o){if(o){var i=this.parent;if((i.zoomSettings.zoomTrigger&e.ZoomTrigger.Toolbar)===e.ZoomTrigger.Toolbar){i.noPushUndo=!1,i.currObjType.isFiltered&&i.okBtn();var r=i.drawingShape;if(i.drawingShape){var a=i.activeObj.currIndex;i.noPushUndo=!0,i.okBtn(),i.noPushUndo=!1,i.drawingShape=null,a&&i.selectShape(a)}if(this.refreshShapeDrawing(),t.Browser.isDevice&&"touchstart"===o.type){if(!o.returnValue)return;o.preventDefault()}var n=document.querySelector("#"+i.element.id+"_zoomIn");t.EventHandler.trigger(n,"click");var s={bool:!1};i.notify("selection",{prop:"getFreehandDrawEditing",onPropertyChange:!1,value:{obj:s}}),s.bool&&(i.notify("freehand-draw",{prop:"applyFhd",onPropertyChange:!1}),this.destroyQuickAccessToolbar()),i.isZoomBtnClick=!0,this.applyPreviewFilter(),i.currObjType.isFiltered=!1,i.currObjType.isRedact=!1,i.togglePen&&(i.currObjType.isZoomed=!0,i.freeHandDraw(!1),i.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"ok"}})),i.notify("draw",{prop:"resetCurrentSelectionPoint"}),i.drawingShape=r,i.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:.1,zoomPoint:null,isResize:null}}),i.notify("draw",{prop:"redrawDownScale"}),(i.isCropTab||i.activeObj.shape)&&(i.notify("draw",{prop:"setStraightenActObj",value:{activeObj:null}}),i.notify("freehand-draw",{prop:"resetStraightenPoint"})),i.isStraightening&&(i.notify("draw",{prop:"resetStraightenDestPoints"}),i.notify("draw",{prop:"setDestForStraighten"}));var l={action:"zoom-in",actionEventArgs:i.editCompleteArgs};i.triggerEditCompleteEvent(l),t.Browser.isDevice&&n.focus()}}},s.prototype.zoomOutBtnClickHandler=function(o){if(o){var i=this.parent;if((i.zoomSettings.zoomTrigger&e.ZoomTrigger.Toolbar)===e.ZoomTrigger.Toolbar){i.noPushUndo=!1,i.currObjType.isFiltered&&i.okBtn();var r=i.drawingShape;if(i.drawingShape){var a=i.activeObj.currIndex;i.noPushUndo=!0,i.okBtn(),i.noPushUndo=!1,i.drawingShape=null,a&&i.selectShape(a)}if(this.refreshShapeDrawing(),t.Browser.isDevice&&"touchstart"===o.type){if(!o.returnValue)return;o.preventDefault()}var n=document.querySelector("#"+i.element.id+"_zoomOut");t.EventHandler.trigger(n,"click");var s={bool:!1};i.notify("selection",{prop:"getFreehandDrawEditing",onPropertyChange:!1,value:{obj:s}}),s.bool&&(i.notify("freehand-draw",{prop:"applyFhd",onPropertyChange:!1}),this.destroyQuickAccessToolbar()),i.isZoomBtnClick=!0,this.applyPreviewFilter(),i.currObjType.isFiltered=!1,i.currObjType.isRedact=!1,i.togglePen&&(i.currObjType.isZoomed=!0,i.freeHandDraw(!1),i.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"ok"}})),i.notify("draw",{prop:"resetCurrentSelectionPoint"}),i.drawingShape=r,i.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:-.1,zoomPoint:null,isResize:null}}),i.notify("draw",{prop:"redrawDownScale"}),(i.isCropTab||i.activeObj.shape)&&(i.notify("draw",{prop:"setStraightenActObj",value:{activeObj:null}}),i.notify("freehand-draw",{prop:"resetStraightenPoint"})),i.isStraightening&&(i.notify("draw",{prop:"resetStraightenDestPoints"}),i.notify("draw",{prop:"setDestForStraighten"}));var l={action:"zoom-out",actionEventArgs:i.editCompleteArgs};i.triggerEditCompleteEvent(l),t.Browser.isDevice&&n.focus()}}},s.prototype.zoomInBtnMouseDownHandler=function(e){e.preventDefault(),this.zoomBtnHold=setInterval(this.zoomInBtnClickHandler.bind(this),250)},s.prototype.zoomOutBtnMouseDownHandler=function(e){e.preventDefault(),this.zoomBtnHold=setInterval(this.zoomOutBtnClickHandler.bind(this),250)},s.prototype.zoomBtnMouseUpHandler=function(){clearInterval(this.zoomBtnHold),this.zoomBtnHold=0},s.prototype.closeContextualToolbar=function(){var e=this.parent,o=e.element.id,i=!1,r={bool:e.isStraightening};return(!t.Browser.isDevice||t.Browser.isDevice&&!r.bool)&&(e.element.querySelector("#"+o+"_contextualToolbar")&&!e.element.querySelector("#"+o+"_contextualToolbar").parentElement.classList.contains("e-hide")||e.element.querySelector("#"+o+"_headWrapper")&&!e.element.querySelector("#"+o+"_headWrapper").parentElement.classList.contains("e-hide"))&&(e.element.querySelector(".e-contextual-toolbar-wrapper").classList.add("e-hide"),e.okBtn(),this.refreshMainToolbar(),i=!0),i},s.prototype.destroyQuickAccessToolbar=function(){var e=this.parent.element.id,o=document.getElementById(e+"_quickAccessToolbar");o&&o.classList.contains("e-control")&&t.getComponent(o,"toolbar").destroy();var i=document.getElementById(e+"_quickAccessToolbarArea");i&&(i.style.display="none")},s.prototype.renderSlider=function(e,o){var i=this.parent,r=i.element.id,a=document.querySelector("#"+r+"_contextualToolbarArea"),n=document.querySelector("#"+r+"_headWrapper"),s=document.querySelector("#"+r+"_labelWrapper");n&&(n.remove(),s.remove()),n=a.appendChild(i.createElement("div",{id:r+"_headWrapper",styles:"position: relative"})),(s="transparency"===e?n.appendChild(i.createElement("label",{id:r+"_labelWrapper",className:"e-ie-finetune-slider-label",styles:t.Browser.isDevice?"position: absolute; top: 31%; left: calc(50% - 150px); font-size: 15px; text-transform: capitalize; font-weight: 400;":"position: absolute; top: 31%; left: calc(50% - 220px); font-size: 15px; text-transform: capitalize; font-weight: 400;"})):n.appendChild(i.createElement("label",{id:r+"_labelWrapper",className:"e-ie-finetune-slider-label",styles:t.Browser.isDevice?"position: absolute; top: 31%; left: calc(50% - 160px); 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;"}))).textContent=this.l10n.getConstant(i.toPascalCase("transparency"===e?"opacity":e));var l=n.appendChild(i.createElement("div",{id:r+"_sliderWrapper",className:"e-ie-finetune-slider-wrap",styles:"position: absolute"})),p=i.getCurrAdjustmentValue(e);o&&"straighten"===e&&t.Browser.isDevice&&(p=i.cropObj.straighten);var h,d,c;"brightness"===e||"contrast"===e||"saturation"===e||"exposure"===e?(i.finetuneSettings?"brightness"===e&&i.finetuneSettings.brightness?(h=i.finetuneSettings.brightness.min,d=i.finetuneSettings.brightness.max):"contrast"===e&&i.finetuneSettings.contrast?(h=i.finetuneSettings.contrast.min,d=i.finetuneSettings.contrast.max):"saturation"===e&&i.finetuneSettings.saturation?(h=i.finetuneSettings.saturation.min,d=i.finetuneSettings.saturation.max):"exposure"===e&&i.finetuneSettings.exposure?(h=i.finetuneSettings.exposure.min,d=i.finetuneSettings.exposure.max):(h=-100,d=100):(h=-100,d=100),c=this.createSlider(h,d,p,e)):"hue"===e||"blur"===e||"opacity"===e?(i.finetuneSettings?"hue"===e&&i.finetuneSettings.hue?(h=i.finetuneSettings.hue.min,d=i.finetuneSettings.hue.max):"blur"===e&&i.finetuneSettings.blur?(h=i.finetuneSettings.blur.min,d=i.finetuneSettings.blur.max):"opacity"===e&&i.finetuneSettings.opacity?(h=i.finetuneSettings.opacity.min,d=i.finetuneSettings.opacity.max):(h=0,d=100):(h=0,d=100),c=this.createSlider(h,d,p,e)):"transparency"===e?(h=0,d=100,c=this.createSlider(h,d,p,e)):"straighten"===e&&(h=-45,d=45,c=this.createSlider(h,d,p,e)),c.appendTo("#"+r+"_sliderWrapper"),l.style.left=(parseFloat(a.style.width)-parseFloat(c.width))/2+"px","straighten"===e&&t.Browser.isDevice&&(n.appendChild(i.createElement("label",{id:r+"_sLabelWrapper",className:"e-ie-straighten-value-span e-ie-finetune-value-span",styles:"position: absolute; top: 31%; margin-left: 20px; font-size: 15px; text-transform: capitalize; font-weight: 400;"})).innerHTML=i.transform.straighten.toString()+"&#176",l.parentElement.classList.add("e-straighten-slider")),"straighten"!==e&&(n.appendChild(i.createElement("label",{id:r+"_finetuneSpan",className:"e-ie-finetune-value-span",styles:t.Browser.isDevice?"position: absolute; top: 25%; margin-left: 20px; font-size: 15px; text-transform: capitalize; font-weight: 400;":"position: absolute; top: 25%; left: calc(50% + 190px); font-size: 15px; text-transform: capitalize; font-weight: 400;"})),l.parentElement.classList.add("e-finetune-slider"),"transparency"===e&&t.Browser.isDevice&&l.parentElement.classList.add("e-ie-device-transparency-slider"),this.updateFinetuneSpan(e))},s.prototype.createSlider=function(e,o,r,a){var n=this,s=this.parent,l="straighten"===a?3:1;return new i.Slider({value:r,type:"MinRange",min:e,max:o,step:l,width:t.Browser.isDevice?"180px":"straighten"===a?"200px":"300px",cssClass:"e-slider",change:function(e){if(s.notify("selection",{prop:"setSliderActive",onPropertyChange:!1,value:{bool:!0}}),"transparency"===a){if(s.activeObj.shape){t.isNullOrUndefined(s.activeObj.imageRatio)&&s.notify("shape",{prop:"updImgRatioForActObj",onPropertyChange:!1}),s.notify("shape",{prop:"pushActItemIntoObj"});var o=t.extend({},s.cropObj,{},!0),i={currObj:{}};s.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:i}});var r=i.currObj;r.objColl=t.extend([],s.objColl,[],!0),r.pointColl=t.extend([],s.pointColl,[],!0),r.afterCropActions=t.extend([],s.afterCropActions,[],!0);var l={selPointColl:null};s.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:l}}),r.selPointColl=t.extend([],l.selPointColl,[],!0),s.objColl.pop(),s.activeObj.opacity=e.value/100,n.upperContext.clearRect(0,0,s.upperCanvas.width,s.upperCanvas.height),s.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate"}}),s.objColl.push(s.activeObj),s.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"shapeTransform",previousObj:r,previousObjColl:r.objColl,previousPointColl:r.pointColl,previousSelPointColl:r.selPointColl,previousCropObj:o,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),s.notify("selection",{prop:"redrawShape",value:{obj:s.objColl[s.objColl.length-1]}}),n.updateFinetuneSpan(a)}}else"straighten"===a?s.setStraighten(e.value):(s.transform.zoomFactor&&s.transform.zoomFactor<0&&(s.isFinetuning=!0),s.notify("selection",{prop:"setSliding",value:{bool:!0}}),s.setCurrAdjustmentValue(a,e.value),n.updateFinetuneSpan(a),n.enableDisableTbrBtn(),s.isFinetuning=!1)},changed:function(){"transparency"!==a&&"straighten"!==a&&(s.notify("selection",{prop:"setSliding",value:{bool:!1}}),s.notify("draw",{prop:"redrawDownScale"})),s.notify("selection",{prop:"setSliderActive",onPropertyChange:!1,value:{bool:!1}}),"transparency"===a&&setTimeout(function(){s.notify("undo-redo",{prop:"updateUndoRedoStack",onPropertyChange:!1}),s.element.querySelector("#"+s.element.id+"_transparency").click()},50)}})},s.prototype.updateFinetuneSpan=function(e){var t=this.parent,o=t.element.querySelector(".e-ie-finetune-value-span");if(o){var i={adjustmentLevel:null};t.notify("filter",{prop:"getAdjustmentLevel",onPropertyChange:!1,value:{obj:i}}),o.innerHTML=Math.round(i.adjustmentLevel[e]).toString()}},s.prototype.applyPreviewFilter=function(){var e=this.parent;(document.querySelector("#"+e.element.id+"_sliderWrapper")||e.currObjType.isFiltered)&&(e.initialAdjustmentValue=this.lowerContext.filter,e.canvasFilter=this.lowerContext.filter,e.currObjType.isFiltered=!1)},s.prototype.unselectBtn=function(){for(var e=this.parent.element.id,t=0,o=["#"+e+"_brightness","#"+e+"_contrast","#"+e+"_hue","#"+e+"_saturation","#"+e+"_opacity","#"+e+"_blur","#"+e+"_exposure"];t<o.length;t++){var i=o[t],r=document.querySelector(i);if(r&&r.classList.contains("e-selected-btn")){r.classList.remove("e-selected-btn");break}}},s.prototype.openSlider=function(e){this.unselectBtn(),this.parent.currObjType.isFiltered=!0,this.refreshToolbar("color",null,null,null,e),document.getElementById(this.parent.element.id+"_"+e).classList.add("e-selected-btn")},s.prototype.refreshSlider=function(){var e=this.parent.element.id,t=document.querySelector("#"+e+"_sliderWrapper"),o=document.querySelector(".e-slider"),i=document.querySelector("#"+e+"_headWrapper");i&&(i.style.display="none"),t&&o&&(o.ej2_instances[0].destroy(),t.remove())},s.prototype.unselectFrameBtn=function(){for(var e=this.parent.element.id,t=0,o=["#"+e+"_none","#"+e+"_mat","#"+e+"_line","#"+e+"_inset","#"+e+"_bevel","#"+e+"_hook"];t<o.length;t++){var i=o[t],r=document.querySelector(i);if(r.classList.contains("e-selected-btn")){r.classList.remove("e-selected-btn");break}}},s.prototype.updateToolbarItems=function(){var e=this.parent,o=e.element.id;if(e.isImageLoaded&&this.isToolbar()){var i=e.element.querySelector(".e-fill.e-template .e-dropdownbtn-preview"),r=e.element.querySelector(".e-stroke.e-template .e-dropdownbtn-preview"),a=e.element.querySelector(".e-text-font-color.e-template .e-dropdownbtn-preview"),n=e.element.querySelector(".e-stroke-text-font-color.e-template .e-dropdownbtn-preview"),s=e.element.querySelector(".e-text-background-color.e-template .e-dropdownbtn-preview"),l=e.element.querySelector(".e-pen-stroke-color.e-template .e-dropdownbtn-preview"),p=e.element.querySelector(".e-shape-stroke-width"),h=e.element.querySelector(".e-shape-rectangle-radius"),d=e.element.querySelector(".e-text-font-family"),c=e.element.querySelector(".e-text-font-size"),u=e.element.querySelector("#"+o+"_bold"),v=e.element.querySelector("#"+o+"_italic");if(e.activeObj.strokeSettings&&e.activeObj.textSettings){if(t.isNullOrUndefined(e.activeObj.strokeSettings.strokeWidth)&&(e.activeObj.strokeSettings.strokeWidth=2),t.isNullOrUndefined(e.activeObj.strokeSettings.outlineWidth)&&(e.activeObj.strokeSettings.outlineWidth=2),i){g=e.activeObj.strokeSettings.fillColor;""===e.activeObj.strokeSettings.fillColor?i.classList.add("e-nocolor-item"):(i.classList.remove("e-nocolor-item"),i.style.background=g),document.querySelector("#"+o+"_shape_fill")&&(t.getComponent(o+"_shape_fill","colorpicker").value=g)}if(r){g=e.activeObj.strokeSettings.strokeColor;r.style.background=g,document.querySelector("#"+o+"_shape_stroke")&&(t.getComponent(o+"_shape_stroke","colorpicker").value=g)}if(a){g=e.activeObj.strokeSettings.strokeColor;a.style.background=g,document.querySelector("#"+o+"_text_font")&&(t.getComponent(o+"_text_font","colorpicker").value=g)}if(n){g=e.activeObj.strokeSettings.outlineColor;/^#([0-9A-Fa-f]{3}|[0-9A-Fa-f]{6}|[0-9A-Fa-f]{8})$|^[a-zA-Z]+$/.test(e.activeObj.strokeSettings.outlineColor)?(n.classList.remove("e-nocolor-item"),n.style.background=g):n.classList.add("e-nocolor-item"),document.querySelector("#"+o+"_stroke_text")&&(t.getComponent(o+"_stroke_text","colorpicker").value=g)}if(s){g=e.activeObj.strokeSettings.fillColor;""===e.activeObj.strokeSettings.fillColor||"transparent"===e.activeObj.strokeSettings.fillColor?s.classList.add("e-nocolor-item"):(s.classList.remove("e-nocolor-item"),s.style.background=g),document.querySelector("#"+o+"_text_bgColor")&&(t.getComponent(o+"_text_bgColor","colorpicker").value=g)}if(l){var g=e.activeObj.strokeSettings.strokeColor;l.style.background=g,document.querySelector("#"+o+"_pen_stroke")&&(t.getComponent(o+"_pen_stroke","colorpicker").value=g);var f={penOpacity:1};e.notify("freehand-draw",{prop:"getPenOpacity",onPropertyChange:!1,value:{obj:f}})}if(d&&(t.Browser.isDevice?d.setAttribute("style","font-family:"+e.activeObj.textSettings.fontFamily.toLowerCase()):d.textContent=e.activeObj.textSettings.fontFamily),c)for(var C=0;C<e.fontSizeColl.length;C++)if(parseInt(e.fontSizeColl[C].text,10)>=Math.round(e.activeObj.textSettings.fontSize)){c.textContent=(C+1).toString();break}if(u&&(e.activeObj.textSettings.bold?u.classList.add("e-selected-btn"):u.classList.remove("e-selected-btn")),v&&(e.activeObj.textSettings.italic?v.classList.add("e-selected-btn"):v.classList.remove("e-selected-btn")),p){var b="text"===e.activeObj.shape?e.activeObj.strokeSettings.outlineWidth:e.activeObj.strokeSettings.strokeWidth,m=Math.round(b).toString();p.textContent=this.getStrokeWidth(m)}if(h){var y=Math.round(e.activeObj.strokeSettings.radius).toString();h.textContent=this.getRectRadius(y)}}}},s.prototype.getStrokeWidth=function(e){var t;switch(parseInt(e,10)/2){case 0:t=this.l10n.getConstant("NoOutline");break;case 1:t=this.l10n.getConstant("XSmall");break;case 2:t=this.l10n.getConstant("Small");break;case 3:t=this.l10n.getConstant("Medium");break;case 4:t=this.l10n.getConstant("Large");break;case 5:t=this.l10n.getConstant("XLarge")}return t},s.prototype.getRectRadius=function(e){var t;switch(parseInt(e,10)/2){case 0:t=this.l10n.getConstant("0");break;case 1:t=this.l10n.getConstant("20");break;case 2:t=this.l10n.getConstant("40");break;case 3:t=this.l10n.getConstant("60");break;case 4:t=this.l10n.getConstant("80");break;case 5:t=this.l10n.getConstant("100")}return t},s.prototype.cancelPan=function(){var e=this.parent;e.notify("shape",{prop:"applyActObj",onPropertyChange:!1,value:{isMouseDown:!0}});var t=e.element.querySelector(".e-img-pan .e-btn");t&&t.classList.remove("e-selected-btn"),e.pan(!1)},s.prototype.refreshMainToolbar=function(){"main"!==this.currToolbar&&this.refreshToolbar("main")},s.prototype.destroySubComponents=function(){for(var e=this.parent,o=e.element.querySelectorAll("input.e-control"),i=e.element.querySelectorAll("button.e-control"),r=0,a=o.length;r<a;r++)o[r].classList.contains("e-color-picker")&&(t.getComponent(o[r],"color-picker").destroy(),t.detach(t.select("input#"+o[r].id,e.element)));for(var r=0,a=i.length;r<a;r++)i[r].classList.contains("e-dropdown-btn")?(t.getComponent(i[r],"dropdown-btn").destroy(),t.detach(t.select("button#"+i[r].id,e.element))):i[r].classList.contains("e-btn")&&(t.getComponent(i[r],"btn").destroy(),t.detach(t.select("button#"+i[r].id,e.element)))},s.prototype.setInitialShapeSettings=function(e){var t=this.parent;t.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),t.currObjType.shape=e.item.id,t.activeObj.shape=t.currObjType.shape.toLowerCase(),t.currObjType.isDragging=t.currObjType.isCustomCrop=!1,t.activeObj.shapeDegree=t.transform.degree,t.activeObj.shapeFlip=t.transform.currFlipState,t.activeObj.textFlip=t.transform.currFlipState,t.activeObj.flipObjColl=[];var o={order:null};t.notify("shape",{prop:"getNewOrder",onPropertyChange:!1,value:{obj:o}}),t.activeObj.order=o.order},s.prototype.isToolbarString=function(e){for(var t=!1,o=0;o<e.length;o++)if("string"==typeof e[o]){t=!0;break}return t},s.prototype.excludeItems=function(e){for(var t=[],o=0;o<e.length;o++){var i=this.getIndex(e[o]);-1!==i&&t.push(i)}for(var r=[],o=0;o<this.defToolbarItems.length;o++)"Center"!==this.defToolbarItems[o].align||this.isSameIndex(t,o)||this.defToolbarItems[o].id===this.parent.element.id+"_annotation"||r.push(o);for(o=r.length-1;o>=0;o--)this.defToolbarItems.splice(r[o],1)},s.prototype.isSameIndex=function(e,t){for(var o=0;o<e.length;o++)if(e[o]===t)return!0;return!1},s.prototype.getIndex=function(e){var t=-1,o=!1;"rotateLeft"===e&&(e="rotLeft"),"rotateRight"===e&&(e="rotRight"),"horizontalFlip"===e&&(e="hflip"),"verticalFlip"===e&&(e="vflip"),"arrowStart"===e&&(e="start"),"arrowEnd"===e&&(e="end"),"fontColor"===e&&(e="strokeColor",o=!0);for(var i=0;i<this.defToolbarItems.length;i++){var r=this.defToolbarItems[i].id;if(r&&-1!==r.toLowerCase().indexOf(e.toLowerCase())){t=i;break}}return o&&(e="fontColor"),t},s.prototype.getModuleName=function(){return"toolbar-module"},s.prototype.redactSlider=function(e){var o=this.parent,r=o.element.id,a=o.element.querySelector("#"+r+"_toolbarArea"),n=o.element.querySelector("#"+r+"_contextualToolbarArea");if(n){n.classList.remove("e-hide"),n.style.left=a.offsetLeft+"px";var s=document.querySelector("#"+r+"_contextualToolbarArea"),l=document.querySelector("#"+r+"_headWrapper"),p=document.querySelector("#"+r+"_labelWrapper"),h=document.querySelector("#"+r+"_contextualToolbar");l&&(l.remove(),p.remove()),h&&(h.remove(),this.createContextualToolbar()),p=(l=s.appendChild(o.createElement("div",{id:r+"_headWrapper",styles:"position: relative"}))).appendChild(o.createElement("label",{id:r+"_labelWrapper",className:"e-ie-finetune-slider-label",styles:t.Browser.isDevice?"position: absolute; top: 31%; left: calc(50% - 160px); 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;"}));var d="blur"===e?this.l10n.getConstant("Blur"):this.l10n.getConstant("PixelSize");p.textContent=d;var c=l.appendChild(o.createElement("div",{id:r+"_sliderWrapper",className:"e-ie-finetune-slider-wrap",styles:"position: absolute"}));l.appendChild(o.createElement("label",{id:r+"_redactSpan",className:"e-ie-redact-value-span",styles:t.Browser.isDevice?"position: absolute; top: 30%; margin-left: 20px; font-size: 15px; text-transform: capitalize; font-weight: 400;":"position: absolute; top: 30%; left: calc(50% + 190px); font-size: 15px; text-transform: capitalize; font-weight: 400;"})),c.parentElement.classList.add("e-finetune-slider");var u="blur"===o.activeObj.redactType?o.activeObj.redactBlur:o.activeObj.redactPixelate;if(new i.Slider({tooltip:{placement:"Before",isVisible:!0,showOn:"Focus"},min:10,max:100,step:1,value:u,type:"MinRange",width:t.Browser.isDevice?"130px":"300px",created:function(){o.element.querySelector(".e-ie-redact-value-span").innerText=u.toString()},change:function(e){o.element.querySelector(".e-ie-redact-value-span").innerText=e.value.toString(),"blur"===o.activeObj.redactType?o.activeObj.redactBlur=o.tempRedactBlur=e.value:"pixelate"===o.activeObj.redactType&&(o.activeObj.redactPixelate=o.tempRedactPixel=e.value),o.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate",obj:o.activeObj,isCropRatio:null,points:null,isPreventDrag:!0,saveContext:null,isPreventSelection:!0}})},changed:function(){setTimeout(function(){o.notify("undo-redo",{prop:"updateUndoRedoStack",onPropertyChange:!1})},50)}}).appendTo("#"+r+"_sliderWrapper"),t.Browser.isDevice){var v=n.offsetHeight+1,g=o.element.querySelector("#"+r+"_customizeWrapper");this.isFrameToolbar&&g&&(v=g.offsetHeight+2);var f=o.element.querySelector("#"+r+"_canvasWrapper").offsetHeight;n.style.top=this.toolbarHeight+1+f-v+"px"}}},s}();return e.Crop=s,e.Draw=h,e.Export=d,e.Filter=c,e.FinetuneSettings=y,e.FontFamily=x,e.FreehandDrawing=u,e.ImageEditor=w,e.Selection=v,e.SelectionSettings=j,e.Shape=g,e.ToolbarModule=O,e.Transform=f,e.UndoRedo=C,e.ZoomSettings=P,e}({},ej.base,ej.popups,ej.inputs,ej.navigations,ej.buttons,ej.splitbuttons),this.ejs=ej;
11
11
  //# sourceMappingURL=ej2-image-editor.min.js.map