@syncfusion/ej2-image-editor 26.1.35 → 26.1.40
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.
- package/dist/ej2-image-editor.umd.min.js +2 -2
- package/dist/ej2-image-editor.umd.min.js.map +1 -1
- package/dist/es6/ej2-image-editor.es2015.js +30 -6
- package/dist/es6/ej2-image-editor.es2015.js.map +1 -1
- package/dist/es6/ej2-image-editor.es5.js +30 -6
- package/dist/es6/ej2-image-editor.es5.js.map +1 -1
- package/dist/global/ej2-image-editor.min.js +2 -2
- package/dist/global/ej2-image-editor.min.js.map +1 -1
- package/dist/global/index.d.ts +1 -1
- package/package.json +11 -11
- package/src/image-editor/action/draw.js +8 -2
- package/src/image-editor/action/selection.js +1 -1
- package/src/image-editor/action/shape.js +11 -1
- package/src/image-editor/action/undo-redo.js +2 -0
- package/src/image-editor/base/image-editor.js +8 -2
- package/styles/bootstrap-dark.css +7 -0
- package/styles/bootstrap.css +7 -0
- package/styles/bootstrap4.css +7 -0
- package/styles/bootstrap5-dark.css +7 -0
- package/styles/bootstrap5.css +7 -0
- package/styles/fabric-dark.css +7 -0
- package/styles/fabric.css +7 -0
- package/styles/fluent-dark.css +7 -0
- package/styles/fluent.css +7 -0
- package/styles/fluent2.css +13 -5
- package/styles/highcontrast-light.css +7 -0
- package/styles/highcontrast.css +7 -0
- package/styles/image-editor/_bds-definition.scss +1 -0
- package/styles/image-editor/_bootstrap-dark-definition.scss +1 -0
- package/styles/image-editor/_bootstrap-definition.scss +1 -0
- package/styles/image-editor/_bootstrap4-definition.scss +1 -0
- package/styles/image-editor/_bootstrap5-definition.scss +1 -0
- package/styles/image-editor/_bootstrap5.3-definition.scss +1 -0
- package/styles/image-editor/_fabric-dark-definition.scss +1 -0
- package/styles/image-editor/_fabric-definition.scss +1 -0
- package/styles/image-editor/_fluent-definition.scss +1 -0
- package/styles/image-editor/_fluent2-definition.scss +1 -0
- package/styles/image-editor/_fusionnew-definition.scss +1 -0
- package/styles/image-editor/_highcontrast-definition.scss +1 -0
- package/styles/image-editor/_highcontrast-light-definition.scss +1 -0
- package/styles/image-editor/_layout.scss +32 -4
- package/styles/image-editor/_material-dark-definition.scss +1 -0
- package/styles/image-editor/_material-definition.scss +1 -0
- package/styles/image-editor/_material3-definition.scss +1 -0
- package/styles/image-editor/_tailwind-definition.scss +1 -0
- package/styles/image-editor/_theme.scss +7 -0
- package/styles/image-editor/bootstrap-dark.css +7 -0
- package/styles/image-editor/bootstrap.css +7 -0
- package/styles/image-editor/bootstrap4.css +7 -0
- package/styles/image-editor/bootstrap5-dark.css +7 -0
- package/styles/image-editor/bootstrap5.css +7 -0
- package/styles/image-editor/fabric-dark.css +7 -0
- package/styles/image-editor/fabric.css +7 -0
- package/styles/image-editor/fluent-dark.css +7 -0
- package/styles/image-editor/fluent.css +7 -0
- package/styles/image-editor/fluent2.css +13 -5
- package/styles/image-editor/highcontrast-light.css +7 -0
- package/styles/image-editor/highcontrast.css +7 -0
- package/styles/image-editor/material-dark.css +7 -0
- package/styles/image-editor/material.css +7 -0
- package/styles/image-editor/material3-dark.css +20 -3
- package/styles/image-editor/material3.css +20 -3
- package/styles/image-editor/tailwind-dark.css +7 -0
- package/styles/image-editor/tailwind.css +7 -0
- package/styles/material-dark.css +7 -0
- package/styles/material.css +7 -0
- package/styles/material3-dark.css +20 -3
- package/styles/material3.css +20 -3
- package/styles/tailwind-dark.css +7 -0
- package/styles/tailwind.css +7 -0
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/*!
|
|
2
2
|
* filename: ej2-image-editor.umd.min.js
|
|
3
|
-
* version : 26.1.
|
|
3
|
+
* version : 26.1.40
|
|
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
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@syncfusion/ej2-base"),require("@syncfusion/ej2-popups"),require("@syncfusion/ej2-inputs"),require("@syncfusion/ej2-navigations"),require("@syncfusion/ej2-buttons"),require("@syncfusion/ej2-splitbuttons")):"function"==typeof define&&define.amd?define(["exports","@syncfusion/ej2-base","@syncfusion/ej2-popups","@syncfusion/ej2-inputs","@syncfusion/ej2-navigations","@syncfusion/ej2-buttons","@syncfusion/ej2-splitbuttons"],t):t((e=e||self).ej={},e.ej2Base,e.ej2Popups,e.ej2Inputs,e.ej2Navigations,e.ej2Buttons,e.ej2Splitbuttons)}(this,function(v,O,u,g,d,L,f){"use strict";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":O.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 t,o=this.parent,i=O.isNullOrUndefined(e),r=o.element.querySelector("#"+o.element.id+"_nonaspectratio"),n=o.activeObj.activePoint,a=o.img,s=!1,l=0,p=o.rotateFlipColl.length;l<p;l++){var h=o.rotateFlipColl[l];90!==h&&-90!==h||(s=!0)}o.notify("draw",{prop:"setImageEdited",onPropertyChange:!1}),(i||r)&&(this.croppedDegree=o.transform.degree),i&&0!==o.transform.degree||s?(this.updateCropObj(),t={startX:a.destLeft,startY:a.destTop,width:a.destWidth,height:a.destHeight},o.notify("transform",{prop:"setCurrDestinationPoint",onPropertyChange:!1,value:{point:t}}),this.rotateCrop()):i&&""!==o.transform.currFlipState?(this.updateCropObj(),t={startX:a.destLeft,startY:a.destTop,width:a.destWidth,height:a.destHeight},o.notify("transform",{prop:"setCurrDestinationPoint",onPropertyChange:!1,value:{point:t}}),this.flipCrop()):(this.adjustStraightenForShapes("initial",!1),o.notify("draw",{prop:"setTempZoomFactor",onPropertyChange:!1,value:{tempZoomFactor:o.transform.zoomFactor}}),r=this.calcRatio(),!i&&e||(this.updateCropObj(),o.notify("draw",{prop:"resetPanPoints",onPropertyChange:!1}),o.notify("shape",{prop:"updImgRatioForActObj",onPropertyChange:!1}),t={startX:a.destLeft,startY:a.destTop,width:a.destWidth,height:a.destHeight},o.notify("transform",{prop:"setCurrDestinationPoint",onPropertyChange:!1,value:{point:t}}),o.currSelectionPoint=O.extend({},o.activeObj,{},!0),this.cropDestPoints={startX:a.destLeft,startY:a.destTop,width:a.destWidth,height:a.destHeight}),o.notify("transform",{prop:"calcMaxDimension",onPropertyChange:!(i={width:0,height:0}),value:{width:n.width*r.width,height:n.height*r.height,obj:i,isImgShape:null}}),e=i,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:n.startX*r.width-a.destLeft*r.width,srcTop:n.startY*r.height-a.destTop*r.height,srcWidth:n.width*r.width,srcHeight:n.height*r.height,destLeft:(o.lowerCanvas.clientWidth-e.width)/2,destTop:(o.lowerCanvas.clientHeight-e.height+1)/2,destWidth:e.width,destHeight:e.height},t=this.lowerContext.filter,o.notify("draw",{prop:"drawImage",onPropertyChange:!1}),this.lowerContext.filter="none",i=O.extend({},o.activeObj,{},!0),this.cropObjColl(),o.transform.straighten=0,o.activeObj=i,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=t,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=o.img.destLeft+o.img.destWidth/2,r=o.img.destTop+o.img.destHeight/2,n=0,a=o.objColl;n<a.length;n++){var s,l,p,h,d,c,u,g,v=a[n];-1===["rectangle","ellipse","text","image"].indexOf(v.shape)||!t&&0===v.rotatedAngle||(s=(u=v.activePoint).startX,g=u.startY,l=u.width,u=u.height,c="initial"===e?v.rotatedAngle:-v.rotatedAngle,p=s+l/2-i,h=g+u/2-r,d=Math.cos(c),g=(c=Math.sin(c))*p+d*h+r-g-u/2,v.activePoint.startX+=u=d*p-c*h+i-s-l/2,v.activePoint.startY+=g,v.activePoint.endX+=u,v.activePoint.endY+=g)}},e.prototype.updateCropObj=function(){this.parent.afterCropActions=[];var e={currObj:{}},e=(this.parent.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:e}}),e.currObj);e.straighten=this.parent.transform.straighten,this.parent.cropObj=O.extend({},e,{},!0)},e.prototype.rotateCrop=function(){for(var e,t=this.parent,o=this.getCurrFlipState(),i=t.activeObj.shape||"",r=(t.notify("shape",{prop:"updImgRatioForActObj",onPropertyChange:!1}),t.currSelectionPoint=O.extend({},t.activeObj,{},!0),t.objColl.push(t.activeObj),t.activeObj=O.extend({},t.objColl[t.objColl.length-1],{},!0),O.extend({},t.objColl[t.objColl.length-1],{},!0),O.extend({},t.currSelectionPoint,{},!0)),n={bool:null},a=(t.notify("transform",{prop:"getPreventSelect",onPropertyChange:!1,value:{obj:n}}),t.notify("transform",{prop:"setPreventSelect",onPropertyChange:!1,value:{bool:!0}}),O.extend([],t.rotateFlipColl,[],!0)),s=(this.panToSelRangle(!0),e=O.extend({},t.objColl[t.objColl.length-1],{},!0),this.upperContext.clearRect(0,0,t.upperCanvas.width,t.upperCanvas.height),t.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate",obj:e}}),t.objColl.pop(),t.notify("shape",{prop:"updImgRatioForActObj",onPropertyChange:!1}),t.objColl.push(t.activeObj),t.transform.straighten),l=(0!==s&&(t.transform.straighten=0,t.straightenBaseImageCanvas(),t.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"zoom",pen:"zoom",isPreventApply:null}}),t.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),t.notify("draw",{prop:"render-image",value:{isMouseWheel:!1}})),this.resetZoom(),O.extend([],t.afterCropActions,[],!0)),p=(this.revertTransform("initial",a),0!==s&&(t.transform.straighten="horizontal"===o||"vertical"===o?-s:s,t.straightenBaseImageCanvas(),t.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"zoom",pen:"zoom",isPreventApply:null}}),t.notify("draw",{prop:"render-image",value:{isMouseWheel:!1}}),t.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"zoom",pen:"zoom",isPreventApply:null}})),e=O.extend({},t.objColl[t.objColl.length-1],{},!0),this.upperContext.clearRect(0,0,t.upperCanvas.width,t.upperCanvas.height),t.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate",obj:e}}),t.objColl.pop(),t.transform.degree=0,{isIntersect:null}),h=(t.notify("draw",{prop:"updateImgCanvasPoints",onPropertyChange:!1}),t.notify("draw",{prop:"isLinesIntersect",onPropertyChange:!1,value:{obj:p}}),0);0!==s&&p.isIntersect&&50!=++h;)t.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:.025,zoomPoint:null},isResize:null}),t.notify("draw",{prop:"updateImgCanvasPoints",onPropertyChange:!1}),t.notify("draw",{prop:"isLinesIntersect",onPropertyChange:!1,value:{obj:p}});this.cropImg(!0),this.revertTransform("reverse",a),t.afterCropActions=l,t.currSelectionPoint=r,t.notify("transform",{prop:"setPreventSelect",onPropertyChange:!1,value:{bool:n.bool}}),t.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.lowerContext}}),t.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.upperContext}}),"crop-circle"===i&&this.cropCircle(this.lowerContext),this.upperContext.clearRect(0,0,t.upperCanvas.width,t.upperCanvas.height),t.notify("draw",{prop:"resetPanPoints",onPropertyChange:!1})},e.prototype.revertTransform=function(e,t){var o=this.parent,i={isRotate:!1};if("initial"===e)for(var r=t.length-1;0<=r;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 n,r=0,a=t.length;r<a;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())}})}}},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(0<e.transform.zoomFactor){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,t=this.parent,o=(t.notify("transform",{prop:"setReverseFlip",onPropertyChange:!1,value:{isReverseFlip:!0}}),t.panPoint.totalPannedPoint.x+=this.tempFlipPanPoint.x,t.panPoint.totalPannedPoint.y+=this.tempFlipPanPoint.y,t.transform.currFlipState),i={flipColl:null},i=(t.notify("transform",{prop:"getFlipColl",onPropertyChange:!1,value:{obj:i}}),i.flipColl),r=(t.notify("transform",{prop:"setFlipColl",onPropertyChange:!1,value:{flipColl:[]}}),t.notify("shape",{prop:"updImgRatioForActObj",onPropertyChange:!1}),t.objColl.push(t.activeObj),0===t.transform.degree&&(r=-t.cropObj.totalPannedPoint.x,e=-t.cropObj.totalPannedPoint.y,t.img.destLeft+=r,t.img.destTop+=e,t.notify("transform",{prop:"drawPannImage",value:{point:{x:r,y:e}}}),t.activeObj=O.extend({},t.objColl[t.objColl.length-1],{},!0),this.upperContext.clearRect(0,0,t.upperCanvas.width,t.upperCanvas.height),t.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate",obj:t.activeObj}}),t.objColl.pop(),t.notify("shape",{prop:"updImgRatioForActObj",onPropertyChange:!1}),t.objColl.push(t.activeObj)),this.resetZoom(),t.currSelectionPoint=O.extend({},t.objColl[t.objColl.length-1],{},!0),this.lowerContext.clearRect(0,0,t.lowerCanvas.width,t.lowerCanvas.height),this.upperContext.clearRect(0,0,t.upperCanvas.width,t.upperCanvas.height),this.lowerContext.filter);t.notify("draw",{prop:"drawImage",onPropertyChange:!1}),this.updateFlipState(),t.notify("shape",{prop:"redrawObj",onPropertyChange:!1,value:{degree:this.getCurrFlipState()}}),t.notify("freehand-draw",{prop:"flipFHDColl",onPropertyChange:!1,value:{value:this.getCurrFlipState()}}),t.activeObj=O.extend({},t.objColl[t.objColl.length-1],{},!0),t.objColl.pop(),this.upperContext.clearRect(0,0,t.upperCanvas.width,t.upperCanvas.height),t.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate"}}),this.cropImg(!0),t.notify("transform",{prop:"setReverseRotate",onPropertyChange:!1,value:{bool:!0}}),this.lowerContext.setTransform(1,0,0,1,0,0),t.notify("draw",{prop:"setDestPoints",onPropertyChange:!1}),t.notify("draw",{prop:"currTransState",onPropertyChange:!1,value:{type:"initial",isPreventDestination:null,context:null,isPreventCircleCrop:null}}),t.notify("draw",{prop:"drawImage",onPropertyChange:!1}),this.lowerContext.filter=r,t.notify("draw",{prop:"setRotateZoom",onPropertyChange:!1,value:{isRotateZoom:!1}}),t.notify("draw",{prop:"currTransState",onPropertyChange:!1,value:{type:"reverse",isPreventDestination:null,context:null,isPreventCircleCrop:null}}),t.transform.currFlipState=o,t.notify("transform",{prop:"setFlipColl",onPropertyChange:!1,value:{flipColl:i}}),this.lowerContext.filter="none",this.updateFlipState(),t.notify("shape",{prop:"redrawObj",onPropertyChange:!1,value:{degree:this.getCurrFlipState()}}),t.notify("freehand-draw",{prop:"flipFHDColl",onPropertyChange:!1,value:{value:this.getCurrFlipState()}}),t.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"zoom",pen:"zoom",isPreventApply:null}}),this.lowerContext.filter=r,(t.currSelectionPoint&&"crop-circle"===t.currSelectionPoint.shape||t.isCircleCrop)&&this.cropCircle(this.lowerContext),t.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),t.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.lowerContext}}),t.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.upperContext}}),this.upperContext.clearRect(0,0,t.upperCanvas.width,t.upperCanvas.height),t.notify("transform",{prop:"setReverseFlip",onPropertyChange:!1,value:{isReverseFlip:!1}}),t.notify("draw",{prop:"resetPanPoints",onPropertyChange:!1}),this.tempFlipPanPoint={x:0,y:0}},e.prototype.cropObjColl=function(){var e=this.parent;if(0<e.objColl.length)for(var t=0,o=e.objColl.length;t<o;t++){var i,r,n=(i=e.objColl[t]).activePoint,a=e.activeObj.activePoint,s=a.startX,l=a.startY,p=a.width,a=a.height,h=i.shape;i.imageRatio={startX:(n.startX-s)/p,startY:(n.startY-l)/a,endX:(n.endX-s)/p,endY:(n.endY-l)/a,width:p/n.width,height:a/n.height};switch(h){case"text":r=0===(r=0===i.shapeDegree?e.transform.degree:e.transform.degree-i.shapeDegree)||180===Math.abs(r)?n.width:n.height,i.textSettings.fontRatio=r/i.textSettings.fontSize;break;case"line":case"arrow":this.cropPointCollection(t),"arrow"===h&&e.notify("shape",{prop:"updateArrowRatio",onPropertyChange:!1,value:{obj:i}});break;case"path":this.cropPointCollection(t)}}},e.prototype.cropPointCollection=function(e){for(var t,o,i,r=this.parent,n=r.objColl[e].shape,a=r.activeObj.activePoint,s=r.img,l=s.destLeft,p=s.destTop,h=s.destWidth,s=s.destHeight,d="path"===n?(t=a.startX,o=a.startY,i=a.width,a.height):(t=l,o=p,i=h,s),c=r.objColl[e].pointColl,u=0,g=c.length;u<g;u++)c[u].ratioX=(c[u].x-t)/i,c[u].ratioY=(c[u].y-o)/d},e.prototype.cropFreehandDrawColl=function(){for(var e=this.parent,t=e.activeObj.activePoint,o=t.startX,i=t.startY,r=t.width,n=t.height,a=0;a<e.freehandCounter;a++){e.points=O.extend([],e.pointColl[a].points,[]),e.notify("freehand-draw",{prop:"setPointCounter",onPropertyChange:!1,value:{value:0}});for(var s=e.points.length,l=0;l<s;l++)e.points[l].ratioX=(e.points[l].x-o)/r,e.points[l].ratioY=(e.points[l].y-i)/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 t,o,i,r=this.parent,n=(r.allowDownScale=!1,this.cropDestPoints),a=this.lowerContext.filter,s=r.isCropTab,l=(r.img={srcLeft:0,srcTop:0,srcWidth:r.baseImgCanvas.width,srcHeight:r.baseImgCanvas.height,destLeft:n.startX,destTop:n.startY,destWidth:n.width,destHeight:n.height},r.img),p=r.currSelectionPoint,e=(this.lowerContext.clearRect(0,0,r.lowerCanvas.width,r.lowerCanvas.height),e&&r.notify("draw",{prop:"setDestPoints",onPropertyChange:!1}),r.notify("draw",{prop:"currTransState",onPropertyChange:!1,value:{type:"initial",isPreventDestination:null,context:null,isPreventCircleCrop:null}}),0===this.croppedDegree&&0===r.transform.degree&&p&&"crop-circle"!==p.shape&&"crop-square"!==p.shape&&(l.destLeft=n.startX,l.destTop=n.startY,l.destWidth=n.width,l.destHeight=n.height),0===r.transform.degree&&(l.destLeft+=r.panPoint.totalPannedInternalPoint.x,l.destTop+=r.panPoint.totalPannedInternalPoint.y),r.notify("draw",{prop:"drawImage",onPropertyChange:!1}),this.lowerContext.filter=a,r.notify("draw",{prop:"currTransState",onPropertyChange:!1,value:{type:"reverse",isPreventDestination:null,context:null,isPreventCircleCrop:!0}}),O.extend([],r.objColl,null,!0)),n=O.extend([],r.pointColl,null,!0),a={straightenPoint:null};r.notify("freehand-draw",{prop:"getStraightenPoint",onPropertyChange:!1,value:{obj:a}}),this.resetAnnotations(),O.isNullOrUndefined(r.activeObj.shape)&&r.cropObj.activeObj.shape&&(r.activeObj=O.extend({},r.cropObj.activeObj,null,!0)),this.panToSelRangle(),r.isCropTab=s,r.objColl=e,r.pointColl=n,r.freehandCounter=r.pointColl.length,a.straightenPoint.x&&a.straightenPoint.y&&r.notify("freehand-draw",{prop:"setStraightenPoint",onPropertyChange:!1,value:{x:a.straightenPoint.x,y:a.straightenPoint.y,ratioX:a.straightenPoint.ratioX,ratioY:a.straightenPoint.ratioY}}),r.cropObj.activeObj.shape?(s={startX:l.destLeft,startY:l.destTop,width:l.destWidth,height:l.destHeight},p&&p.activePoint&&(t=(p=p.activePoint).startX,o=p.startY,i=p.width,p=p.height,l.destLeft=t,l.destTop=o,l.destWidth=i,l.destHeight=p),r.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"zoom",pen:"zoom",isPreventApply:null}}),l.destLeft=s.startX,l.destTop=s.startY,l.destWidth=s.width,l.destHeight=s.height,r.notify("freehand-draw",{prop:"updateFHDColl",onPropertyChange:!1}),e=O.extend([],r.objColl,null,!0),n=O.extend([],r.pointColl,null,!0),r.notify("freehand-draw",{prop:"getStraightenPoint",onPropertyChange:!1,value:{obj:a}}),this.resetAnnotations(),r.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!(t={selPointColl:null}),value:{obj:t}}),o=t.selPointColl,r.notify("freehand-draw",{prop:"setSelPointColl",onPropertyChange:!1,value:{obj:{selPointColl:[]}}}),r.cropObj.filter=this.lowerContext.filter,i=O.extend({},r.currSelectionPoint,null,!0),r.notify("draw",{prop:"setCurrentObj",onPropertyChange:!1,value:{obj:null}}),r.activeObj=O.extend({},i,null,!0),p=O.extend({},r.activeObj,null,!0),r.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),r.currSelectionPoint=null,r.isCircleCrop=!1,0!==r.transform.degree&&(O.isNullOrUndefined(r.activeObj.shape)&&r.cropObj.activeObj.shape&&(r.activeObj=O.extend({},r.cropObj.activeObj,null,!0)),r.notify("transform",{prop:"drawPannedImage",value:{xDiff:0,yDiff:0}}),r.panPoint.currentPannedPoint={x:0,y:0}),r.objColl=e,r.pointColl=n,r.freehandCounter=r.pointColl.length,a.straightenPoint.x&&a.straightenPoint.y&&r.notify("freehand-draw",{prop:"setStraightenPoint",onPropertyChange:!1,value:{x:a.straightenPoint.x,y:a.straightenPoint.y,ratioX:a.straightenPoint.ratioX,ratioY:a.straightenPoint.ratioY}}),r.notify("freehand-draw",{prop:"setSelPointColl",onPropertyChange:!1,value:{obj:{selPointColl:o}}}),r.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"iterate",pen:"iterate",isPreventApply:null}}),this.adjustStraightenForShapes("reverse",!1),r.notify("freehand-draw",{prop:"updateFHDColl",onPropertyChange:!1,value:{isPreventApply:!0}}),r.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"zoom",pen:"zoom",isPreventApply:null}}),0===r.transform.degree?r.notify("transform",{prop:"drawPannImage",onPropertyChange:!1,value:{point:{x:0,y:0}}}):(O.isNullOrUndefined(r.activeObj.shape)&&r.cropObj.activeObj.shape&&(r.activeObj=O.extend({},r.cropObj.activeObj,null,!0)),r.notify("transform",{prop:"drawPannedImage",value:{xDiff:0,yDiff:0}}),r.panPoint.currentPannedPoint={x:0,y:0}),r.activeObj=p,r.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate"}}),r.notify("transform",{prop:"setTempPanMove",onPropertyChange:!1,value:{point:null}}),this.isInitCrop||0!==r.transform.degree||""===r.cropObj.currFlipState||0===r.cropObj.cropZoom?this.isInitCrop=!1:(this.isInitCrop=!0,r.notify("draw",{prop:"getStraightenActObj",onPropertyChange:!(l={activeObj:null}),value:{obj:l}}),r.notify("draw",{prop:"performCancel",value:{isContextualToolbar:null}}),r.notify("draw",{prop:"setStraightenActObj",onPropertyChange:!1,value:{activeObj:l.activeObj}}),r.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"croptransform",isApplyBtn:!1,isCropping:null,isZooming:null,cType:null}}))):(this.adjustStraightenForShapes("reverse",!0),r.notify("freehand-draw",{prop:"updateFHDColl",onPropertyChange:!1,value:{isPreventApply:!0}}),s=this.lowerContext.filter,this.lowerContext.filter="none",r.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"iterate",pen:"iterate",isPreventApply:null}}),this.lowerContext.filter=s,r.currSelectionPoint=null),document.querySelector(".e-ie-straighten-value-span")&&(document.querySelector(".e-ie-straighten-value-span").innerHTML=r.transform.straighten.toString()+"°")},e.prototype.panToSelRangle=function(e){var t=this.parent,o=t.cropObj.totalPannedClientPoint,i=0!==t.transform.degree?e?-o.x:o.x:0,e=0!==t.transform.degree?e?-o.y:o.y:0;0!==t.transform.degree&&(t.panPoint.currentPannedPoint={x:i,y:e},t.notify("transform",{prop:"drawPannedImage",value:{xDiff:i,yDiff:e}}),t.panPoint.currentPannedPoint={x:0,y:0})},e.prototype.cropCircle=function(e,t,o){var i=this.parent,r=i.img,n=r.destLeft,a=r.destTop,s=r.destWidth,r=r.destHeight,l=(o&&""!==i.transform.currFlipState&&i.notify("draw",{prop:"setTransform",onPropertyChange:!1,value:{context:e,value:i.transform.currFlipState,isReverse:null}}),e.filter),n=(e.filter="none",e.globalCompositeOperation="destination-in",e.beginPath(),O.isNullOrUndefined(t)?n+s/2:e.canvas.width/2),a=O.isNullOrUndefined(t)?a+r/2:e.canvas.height/2,r=t?e.canvas.width/2:s/2;e.arc(n,a,r,0,2*Math.PI),e.closePath(),e.fill(),e.restore(),e.globalCompositeOperation="source-over",i.currObjType.isActiveObj=i.isCircleCrop=!0,e.filter=l,o&&""!==i.transform.currFlipState&&i.notify("draw",{prop:"setTransform",onPropertyChange:!1,value:{context:e,value:i.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?1<o.flipColl.length?this.getCurrFlipState():e.transform.currFlipState:t},e.prototype.updateRotatePan=function(){var e,t,o,i,r=this.parent;O.isNullOrUndefined(r.panPoint.currentPannedPoint)||(i="",e=r.transform.degree,t=(o=r.panPoint.currentPannedPoint).x,o=o.y,i=0<r.rotateFlipColl.length&&"number"==typeof r.rotateFlipColl[0]&&e<0?this.getCurrCropState():this.getCurrFlipState(),e%90==0&&e%180!=0?90===e||-90===e&&("horizontal"===i||"vertical"===i)||-270===e&&(""===i||"verticalHorizontal"===i||"horizontalVertical"===i)?("horizontal"===i||""===i?r.img.destLeft+=o:r.img.destLeft-=o,""===i||"vertical"===i?r.img.destTop-=t:r.img.destTop+=t):270!==e&&(-270!==e||"horizontal"!==i&&"vertical"!==i)&&(-90!==e||""!==i&&"verticalHorizontal"!==i&&"horizontalVertical"!==i)||(""===i||"horizontal"===i?r.img.destLeft-=o:r.img.destLeft+=o,""===i||"vertical"===i?r.img.destTop+=t:r.img.destTop-=t):180!==e&&-180!==e||(""===i||"vertical"===i?r.img.destLeft-=t:r.img.destLeft+=t,""===i||"horizontal"===i?r.img.destTop-=o:r.img.destTop+=o))},e.prototype.crop=function(e){var t,o=this.parent,i=o.activeObj.activePoint,r=i.startX,n=i.startY,a=i.endX,i=i.endY;!o.disabled&&o.isImageLoaded&&(t={isCropToolbar:o.isCropToolbar},o.currObjType.isUndoAction&&!t.isCropToolbar&&o.notify("undo-redo",{prop:"refreshUrc",value:{bool:null}}),r={cancel:!1,startPoint:{x:r,y:n},endPoint:{x:a,y:i},preventScaling:!1},t.isCropToolbar||o.trigger("cropping",r),this.cropEvent(r,e,t))},e.prototype.cropEvent=function(e,t,o){var i,r,n=this.parent;e.cancel||(r=n.activeObj.shape?n.activeObj.shape.split("-"):[],!n.disabled&&n.activeObj.horTopLine&&(n.currObjType.isCustomCrop||0<r.length&&"crop"===r[0])&&(t.isCrop=!0,r=O.extend({},n.cropObj,{},!0),t=O.extend({},this.prevCropCurrObj,{},!0),e.preventScaling?this.isPreventScaling=!0:this.isPreventScaling=!1,this.cropImg(),this.isPreventScaling&&(n.aspectWidth=n.img.destWidth,n.aspectHeight=n.img.destHeight),n.notify("freehand-draw",{prop:"resetStraightenPoint"}),n.isCropTab=!1,n.transform.zoomFactor=0,n.setProperties({zoomSettings:{zoomFactor:1}},!0),n.notify("transform",{prop:"setPreviousZoomValue",onPropertyChange:!1,value:{previousZoomValue:n.zoomSettings.zoomFactor}}),O.Browser.isDevice||this.updateUndoRedoColl(t,r,o),n.notify("transform",{prop:"setCropDimension",onPropertyChange:!1,value:{width:n.cropObj.destPoints.width,height:n.cropObj.destPoints.height}}),e=n.element.querySelector("#"+n.element.id+"_aspectratio"),i=n.element.querySelector("#"+n.element.id+"_nonaspectratio"),n.notify("draw",{prop:"render-image",value:{isMouseWheel:!1}}),!o.isCropToolbar&&O.isNullOrUndefined(e)&&O.isNullOrUndefined(i)&&n.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"main",isApplyBtn:!1,isCropping:!1,isZooming:null,cType:null}}),this.resizeWrapper(),O.Browser.isDevice)&&this.updateUndoRedoColl(t,r,o))},e.prototype.updateUndoRedoColl=function(e,t,o){var i=this.parent,r={prevCurrSelectionPoint:i.prevCurrSelectionPoint};e.currSelectionPoint=O.extend({},r.prevCurrSelectionPoint,{},!0),i.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"crop",previousObj:e,previousObjColl:e.objColl,previousPointColl:e.pointColl,previousSelPointColl:e.selPointColl,previousCropObj:t,previousText:null,currentText:null,previousFilter:null,isCircleCrop:i.isCircleCrop}}),o.isCropToolbar||i.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"ok"}})},e.prototype.resizeWrapper=function(){var e,t=this.parent;O.Browser.isDevice&&(e=(e=t.element).querySelector("#"+e.id+"_contextualToolbarArea"))&&""===e.style.position&&!this.isTransformCrop&&(e.style.position="absolute",t.isStraightening=!1,t.update(),t.notify("filter",{prop:"setAdjustmentValue",value:{adjustmentValue:t.canvasFilter}}))},e.prototype.calcRatio=function(e,t){var o=this.parent,i=o.transform.degree,r=o.img,n=r.destWidth,r=r.destHeight,t=t||o.baseImgCanvas,o=t.width,t=t.height,n=0===i||i%180==0?o/n:t/n,i=0===i||i%180==0?t/r:o/r;return e&&(e.width=n,e.height=i),{width:n,height:i}},e.prototype.isObjInImage=function(e,t){var o=this.parent.img,i=o.destLeft,r=o.destTop,n=o.destWidth,o=o.destHeight,e=e.activePoint,a=e.startX,s=e.endX,l=e.startY,e=e.endY,a=i<=a&&s<=i+n||a<=i&&i<=s||a<=i+n&&i+n<=s||r<=l&&e<=r+o||l<=r&&r<=e||l<=r+o&&r+o<=e;return t&&(t.isInside=a),a},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,n=t.rotateFlipColl.length;r<n;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};var o=e;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()}var R=function(n,a,s,l){return new(s=s||Promise)(function(e,t){function o(e){try{r(l.next(e))}catch(e){t(e)}}function i(e){try{r(l.throw(e))}catch(e){t(e)}}function r(t){t.done?e(t.value):new s(function(e){e(t.value)}).then(o,i)}r((l=l.apply(n,a||[])).next())})},E=function(i,r){var n,a,s,l={label:0,sent:function(){if(1&s[0])throw s[1];return s[1]},trys:[],ops:[]},e={next:t(0),throw:t(1),return:t(2)};return"function"==typeof Symbol&&(e[Symbol.iterator]=function(){return this}),e;function t(o){return function(e){var t=[o,e];if(n)throw new TypeError("Generator is already executing.");for(;l;)try{if(n=1,a&&(s=2&t[0]?a.return:t[0]?a.throw||((s=a.return)&&s.call(a),0):a.next)&&!(s=s.call(a,t[1])).done)return s;switch(a=0,(t=s?[2&t[0],s.value]:t)[0]){case 0:case 1:s=t;break;case 4:return l.label++,{value:t[1],done:!1};case 5:l.label++,a=t[1],t=[0];continue;case 7:t=l.ops.pop(),l.trys.pop();continue;default:if(!(s=0<(s=l.trys).length&&s[s.length-1])&&(6===t[0]||2===t[0])){l=0;continue}if(3===t[0]&&(!s||t[1]>s[0]&&t[1]<s[3]))l.label=t[1];else if(6===t[0]&&l.label<s[1])l.label=s[1],s=t;else{if(!(s&&l.label<s[2])){s[2]&&l.ops.pop(),l.trys.pop();continue}l.label=s[2],l.ops.push(t)}}t=r.call(i,l)}catch(e){t=[6,e],a=0}finally{n=s=0}if(5&t[0])throw t[1];return{value:t[0]?t[1]:void 0,done:!0}}}},i=(t.prototype.destroy=function(){this.parent.isDestroyed||this.removeEventListener()},t.prototype.addEventListener=function(){this.parent.on("draw",this.draw,this),this.parent.on("destroyed",this.destroy,this)},t.prototype.removeEventListener=function(){this.parent.off("draw",this.draw),this.parent.off("destroyed",this.destroy)},t.prototype.draw=function(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=this.arrowDimension;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=O.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=O.extend([],this.parent.objColl,[],!0);break;case"resetTempObjColl":this.tempObjColl=null;break;case"updateTempPointColl":this.tempPointColl=O.extend({},this.parent.pointColl,{},!0);break;case"resetTempPointColl":this.tempPointColl={}}},t.prototype.getModuleName=function(){return"draw"},t.prototype.updatePrivateVariables=function(){var e=this.parent;e.lowerCanvas&&(this.lowerContext=e.lowerCanvas.getContext("2d")),e.upperCanvas&&(this.upperContext=e.upperCanvas.getContext("2d")),O.isNullOrUndefined(this.tempZoomFactor)&&(this.tempZoomFactor=e.transform.zoomFactor),""===this.tempTextSettings.fontFamily&&(this.tempTextSettings.fontFamily=e.fontFamily.default)},t.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},t.prototype.redrawDownScale=function(){var e,t=this.parent;t.transform.zoomFactor&&t.transform.zoomFactor<0&&(e=O.extend({},t.activeObj,{},!0),t.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),this.isDownScale=!0,this.renderImage(),this.isDownScale=!1,e.shape)&&this.drawObject("duplicate",e)},t.prototype.updateFinetune=function(){var e,t,o,i=this.parent;i.transform.zoomFactor&&i.transform.zoomFactor<0&&(e=this.lowerContext.filter,this.lowerContext.filter="none",i.notify("draw",{prop:"redrawDownScale"}),t=i.inMemoryCanvas.getContext("2d"),o=(o=this.lowerContext).getImageData(0,0,o.canvas.width,o.canvas.height),i.inMemoryCanvas.width=o.width,i.inMemoryCanvas.height=o.height,t.putImageData(o,0,0),this.lowerContext.filter=e,i.notify("draw",{prop:"redrawDownScale"}))},t.prototype.drawImage=function(){this.applyFrame(this.lowerContext,this.parent.frameObj.type)},t.prototype.drawObject=function(e,t,o,i,r,n,a){var s,l=this.parent,p=l.activeObj,h=l.activeObj.activePoint;this.upperContext.clearRect(0,0,l.upperCanvas.width,l.upperCanvas.height),"original"===(e=e.toLowerCase())?s=this.lowerContext:"duplicate"===e?s=this.upperContext:n&&(s=n),!r&&p.shape&&this.setDragLimit(),l.currObjType.shape&&"crop"===l.currObjType.shape.split("-")[0].toLowerCase()&&o&&this.drawCropRatio(),p=l.activeObj,h=l.activeObj.activePoint,O.isNullOrUndefined(p.strokeSettings)&&(l.notify("shape",{prop:"getStrokeSettings",onPropertyChange:!(r={strokeSettings:{}}),value:{obj:r}}),p.strokeSettings=r.strokeSettings),O.isNullOrUndefined(p.strokeSettings.strokeWidth)&&(p.strokeSettings.strokeWidth=2),t&&(l.activeObj=O.extend({},t,{},!0)),i&&i.startX&&i.startY&&i.endX&&i.endY&&i.width&&i.height&&(h.startX=i.startX,h.startY=i.startY,h.endX=i.endX,h.endY=i.endY,h.width=i.width,h.height=i.height),this.updateActiveObject(),p=l.activeObj,h=l.activeObj.activePoint,O.isNullOrUndefined(h.startX)&&O.isNullOrUndefined(h.startY)||(l.currObjType.isText&&(l.notify("shape",{prop:"getKeyHistory",onPropertyChange:!(o={keyHistory:""}),value:{obj:o}}),p.keyHistory=o.keyHistory),r=!1,"original"!==e&&((r=p.shape&&"crop"===p.shape.split("-")[0]?!0:r)&&(i&&i.startX&&i.startY&&i.endX&&i.endY&&i.width&&i.height?(h.startX=i.startX,h.startY=i.startY,h.endX=i.endX,h.endY=i.endY,h.width=i.width,h.height=i.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)),!O.isNullOrUndefined(a)||s!==this.lowerContext&&s!==this.upperContext||(this.rotateContext("initial",s),this.drawOuterSelection(s),this.rotateContext("reverse",s))),l.currObjType.isActiveObj=!0,l.notify("shape",{prop:"getKeyHistory",onPropertyChange:!(o={keyHistory:""}),value:{obj:o}}),t?this.drawShapeObj(e,t.shape,n,a):""!==o.keyHistory&&l.currObjType.isText?this.drawShapeObj(e,"text",n,a):p.shape?this.drawShapeObj(e,p.shape,n,a):this.drawShapeObj(e,void 0,n,a),"duplicate"===e&&r&&"crop-circle"!==p.shape&&"none"!==l.frameObj.type&&(this.applyFrame(this.upperContext,l.frameObj.type),this.drawCornerCircles(this.upperContext)))},t.prototype.rotateContext=function(e,t){var o,i=this.parent,r=i.activeObj,n=r.shape,r=r.rotatedAngle,a=i.img,s=a.destLeft,l=a.destTop,p=a.destWidth,a=a.destHeight,h=i.activeObj.activePoint,d=h.startX,c=h.startY,u=h.width,h=h.height;"line"!==n&&"arrow"!==n&&(n="initial"===e?r:-r,e=0!==i.transform.straighten||i.isCropTab?(o=s+p/2,l+a/2):(o=d+u/2,c+h/2),t.translate(o,e),t.rotate(n),t.translate(-o,-e))},t.prototype.setDragLimit=function(){var e,t,o=this.parent,i=o.activeObj.activePoint,r=o.activeObj,n=r.shape,r=r.rotatedAngle;i&&"image"!==n&&"line"!==n&&0===r&&(r=(n=o.img).destLeft,e=n.destTop,t=n.destWidth,n=n.destHeight,i.startX<r?(i.startX=r,i.endX=Math.min(i.startX+i.width,r+t)):i.endX>r+t&&(i.endX=r+t,i.startX=Math.max(i.endX-i.width,r)),i.startY<e?i.startY=e:i.endY>e+n&&(i.endY=e+n,i.startY=Math.max(i.endY-i.height,e)),o.activeObj=this.updateWidthHeight(o.activeObj))},t.prototype.drawCropRatio=function(){var e,t,o,i,r=this.parent,n=r.activeObj.activePoint,a=r.lowerCanvas.clientWidth,s=r.lowerCanvas.clientHeight+1,l=r.img,p=l.destLeft,h=l.destTop,d=l.destWidth,c=l.destHeight;switch(0<r.transform.zoomFactor&&this.currSelPoint?(l=O.extend({},r.activeObj,{},!0),this.drawCustomSelection("crop-custom",null,null,null,null),0!==r.transform.straighten&&(n=r.activeObj.activePoint),i=r.transform.degree%90==0&&r.transform.degree%180!=0?o=n.width<n.height?n.width:n.height:(o=!(p+p+d<=a)&&0===r.transform.straighten?a-p:n.width,!(h+h+c<=s)&&0===r.transform.straighten?s-h:n.height),r.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),r.activeObj=l,r.currObjType.shape=l.shape,this.upperContext.clearRect(0,0,r.upperCanvas.width,r.upperCanvas.height),r.currObjType.isCustomCrop=!1):(o=d,i=c,p<0&&(o+=p),h<0&&(i+=h),p+d>r.lowerCanvas.width&&(o-=p+d-r.lowerCanvas.width),h+c>r.lowerCanvas.height&&(i-=h+c-r.lowerCanvas.height)),r.currObjType.shape.toLowerCase()){case"crop-square":case"crop-circle":r.notify("selection",{prop:"setDragDirection",onPropertyChange:!1,value:{width:o,height:i}}),n=r.activeObj.activePoint,r.lowerCanvas.width<n.endX-n.startX&&(n.startX=7.5,n.endX=r.lowerCanvas.width-7.5),r.lowerCanvas.height<n.endY-n.startY&&(n.startY=7.5,n.endY=r.lowerCanvas.height-7.5),o===d&&i===c&&(n.startX+=p,n.startY+=h,n.endX+=p,n.endY+=h),r.lowerCanvas.width>r.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,t=2;break;case"crop-4:3":e=4,t=3;break;case"crop-5:4":e=5,t=4;break;case"crop-7:5":e=7,t=5;break;case"crop-16:9":e=16,t=9;break;case"crop-2:3":e=2,t=3;break;case"crop-3:4":e=3,t=4;break;case"crop-4:5":e=4,t=5;break;case"crop-5:7":e=5,t=7;break;case"crop-9:16":e=9,t=16;break;default:e=parseInt(r.currObjType.shape.toLowerCase().split("crop-")[1].split(":")[0]),t=parseInt(r.currObjType.shape.toLowerCase().split("crop-")[1].split(":")[1])}void 0!==e&&void 0!==t&&(r.notify("selection",{prop:"calcShapeRatio",onPropertyChange:!1,value:{x:e,y:t,imgWidth:o,imgHeight:i}}),o===d&&i===c&&this.updatePoints(),n=r.activeObj.activePoint),n.startX<p&&(v=p-n.startX+7.5,n.startX+=v,n.endX+=v),n.startY<h&&(v=h-n.startY+7.5,n.startY+=v,n.endY+=v),r.activeObj=this.updateWidthHeight(r.activeObj),this.adjToCenter(),this.enlargeToImg(),0!==r.transform.straighten&&(this.adjToStraighten(),this.updateActiveObject(r.activeObj.activePoint,r.activeObj));var u={isIntersect:null,arr:null},g=0,n=r.activeObj.activePoint;if(0!==r.transform.straighten)for(;this.isLinesIntersect(u)&&g<100;){g++;var v=+n.width/100;n.startX+=v,n.endX-=v,v=+n.height/100,n.startY+=v,n.endY-=v,n.width=n.endX-n.startX,n.height=n.endY-n.startY,this.updateActiveObject(n,r.activeObj)}this.straightenInitZoom=r.transform.zoomFactor,this.straightenActObj=O.extend({},r.activeObj,{},!0),r.notify("draw",{prop:"resetStraightenDestPoints"}),r.notify("draw",{prop:"setDestForStraighten"})},t.prototype.adjToCenter=function(){var e,t=this.parent,o=t.activeObj.activePoint,i=t.img,r=i.destLeft,n=i.destTop,a=i.destWidth,i=i.destHeight,s=t.lowerCanvas.width/2-(o.endX-o.width/2),t=t.lowerCanvas.height/2-(o.endY-o.height/2);o.startX+=s,o.endX+=s,o.startY+=t,o.endY+=t,o.startX<(7.5<=r?r:7.5)?(e=(7.5<=r?r:0)-o.startX,o.startX+=e,o.endX+=e):o.endX>r+a&&(e=o.endX-(r+a),o.startX-=e,o.endX-=e),o.startY<(7.5<=n?n:7.5)?(e=(7.5<=n?n:0)-o.startY,o.startY+=e,o.endY+=e):o.endY>n+i&&(e=o.endY-(n+i),o.startY-=e,o.endY-=e)},t.prototype.enlargeToImg=function(){var e=this.parent;if(0!==e.transform.straighten&&e.transform.degree%90==0&&e.transform.degree%180!=0)for(var t=e.activeObj.activePoint,o=O.extend({},t,{},!0),i=0;;){i++;var r=5*t.width/100,n=(t.startX-=r,t.endX+=r,r=5*t.height/100,t.startY-=r,t.endY+=r,t.width=t.endX-t.startX,t.height=t.endY-t.startY,this.updateActiveObject(t,e.activeObj),{isIntersect:null,arr:null});if(this.updateImgCanvasPoints(),this.isLinesIntersect(n),n.arr[0]||n.arr[1]||n.arr[2]||n.arr[3]||t.startX<7.5||t.startY<7.5||100===i){r=+(t=O.extend({},o,{},!0)).width/100,t.startX+=r,t.endX-=r,r=+t.height/100,t.startY+=r,t.endY-=r,t.width=t.endX-t.startX,t.height=t.endY-t.startY,this.updateActiveObject(t,e.activeObj);break}o=O.extend({},t,{},!0)}},t.prototype.updateActiveObject=function(e,t,o,i,r){var n=this.parent,a=(e=e||O.extend({},n.activeObj.activePoint,{},!0),t=t||O.extend({},n.activeObj,{},!0),e.width=e.endX-e.startX,e.height=e.endY-e.startY,e.startX),s=e.startY,l=e.endX,p=e.endY,h=e.width/2,d=e.height/2,c=7.5;t.horTopLine={startX:a+(i=i||0),startY:s-(r=r||0),endX:l+i,endY:p+r},t.horBottomLine={startX:a-i,startY:p-r,endX:l-i,endY:p+r},t.verLeftLine={startX:a+i,startY:s-r,endX:a-r,endY:p-r},t.verRightLine={startX:l+i,startY:s+r,endX:l-i,endY:p+r},t.topLeftCircle={startX:a,startY:s,radius:t.horTopLine.endX?c:0},t.topCenterCircle={startX:a+h,startY:s,radius:t.horTopLine.endX?c:0},t.topRightCircle={startX:l,startY:s,radius:t.horTopLine.endX?c:0},t.centerLeftCircle={startX:a,startY:s+d,radius:t.horTopLine.endX?c:0},t.centerRightCircle={startX:l,startY:s+d,radius:t.horTopLine.endX?c:0},t.bottomLeftCircle={startX:a,startY:p,radius:t.horTopLine.endX?c:0},t.bottomCenterCircle={startX:a+h,startY:p,radius:t.horTopLine.endX?c:0},t.bottomRightCircle={startX:l,startY:p,radius:t.horTopLine.endX?c:0},0===t.rotatedAngle&&(t.rotationCirclePoint={x:t.bottomCenterCircle.startX,y:t.bottomCenterCircle.startY+25},t.rotationCirclePoint.ratioX=(t.rotationCirclePoint.x-n.img.destLeft)/n.img.destWidth,t.rotationCirclePoint.ratioY=(t.rotationCirclePoint.y-n.img.destTop)/n.img.destHeight),t.activePoint=e,O.isNullOrUndefined(o)&&(n.activeObj=O.extend({},t,{},!0))},t.prototype.drawOuterSelection=function(e,t){var o,i=this.parent,r=i.activeObj.activePoint,n=i.activeObj,a=(e.lineWidth=.5,O.extend({},n,{},!0));if(((o=n.shape?n.shape.split("-"):o)&&"crop"===o[0]||void 0===n.shape)&&!t&&(this.upperContext.fillStyle="rgb(0, 0, 0, 0.25)",this.upperContext.fillRect(0,0,i.lowerCanvas.width,i.lowerCanvas.height),this.upperContext.clearRect(r.startX,r.startY,r.width,r.height)),e.strokeStyle=i.themeColl[i.theme].primaryColor,e.fillStyle=i.themeColl[i.theme].secondaryColor,(0===a.shapeDegree?i.transform.degree:i.transform.degree-a.shapeDegree)<0&&0,"arrow"===n.shape||"line"===n.shape)e.beginPath(),e.moveTo(r.startX,r.startY),e.lineTo(r.endX,r.endY),e.stroke();else if("path"===n.shape){e.beginPath();var s=O.extend({},i.activeObj,{},!0);if(s.pointColl[0]&&(e.moveTo(s.pointColl[0].x,s.pointColl[0].y),1<s.pointColl.length))for(var l=1,p=s.pointColl.length;l<p;l++)r.endX=s.pointColl[l].x,r.endY=s.pointColl[l].y,e.lineTo(r.endX,r.endY);var t={shape:null};i.notify("selection",{prop:"getCurrentDrawingShape",value:{obj:t}}),"path"===t.shape&&(i.activeObj=n=s),e.lineTo(r.endX,r.endY),e.stroke()}else this.drawCornerCircles(e);!i.selectionSettings.showCircle||void 0!==o&&"crop"===o[0]||(t=e.strokeStyle,o=e.fillStyle,e.strokeStyle=i.selectionSettings.strokeColor,e.fillStyle=i.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=t,e.fillStyle=o),a.rotationCircleLine=n.rotationCircleLine,i.activeObj=O.extend({},a,{},!0)},t.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)}},t.prototype.drawShapeObj=function(e,t,o,i){var r,n,a=this.parent,s=a.activeObj.activePoint,l=a.activeObj,p=l.strokeSettings,h=p.strokeColor,d=p.fillColor,c=p.strokeWidth,p=void 0!==t?t:a.currObjType.shape,p=(a.currObjType.shape=p,"original"===e.toLowerCase()?r=this.lowerContext:"duplicate"===e.toLowerCase()?r=this.upperContext:o&&(r=o),a.currObjType.shape.toLowerCase()),u=(-1!==["rectangle","ellipse","line","arrow","path","image"].indexOf(p)&&(l.shape=a.currObjType.shape),r.strokeStyle=h,r.fillStyle="text"===t||"freehanddraw"===t?h:d,s.width/3),g=s.height/3,v=s.endX-s.startX,f=s.endY-s.startY,C=(this.rotateContext("initial",r),r.fillStyle);switch(a.currObjType.shape.toLowerCase()){case"rectangle":this.drawSquareLines(r),O.isNullOrUndefined(i)&&r===this.upperContext&&this.drawOuterSelection(r);break;case"ellipse":v=Math.abs(v),f=Math.abs(f),r.beginPath(),r.ellipse(s.startX+v/2,s.startY+f/2,v/2,f/2,0,0,2*Math.PI,!1),""!==d&&(r.fillStyle=d,r.fill()),r.ellipse(s.startX+v/2,s.startY+f/2,Math.abs(v/2-c),Math.abs(f/2-c),0,0,2*Math.PI,!1),r.fillStyle=h,r.fill("evenodd"),r.closePath(),O.isNullOrUndefined(i)&&r===this.upperContext&&this.drawOuterSelection(r);break;case"crop-circle":r===this.lowerContext&&(r=this.upperContext),this.shapeCircle(r,v,f);break;case"line":this.shapeLine(r,s.startX,s.startY,s.endX,s.endY),O.isNullOrUndefined(i)&&r===this.upperContext&&this.drawOuterSelection(r);break;case"arrow":(0===l.shapeDegree?a.transform.degree:a.transform.degree-l.shapeDegree)<0&&0,r.fillStyle=r.strokeStyle,O.isNullOrUndefined(l.triangleDirection)&&(l.triangleDirection="right"),O.isNullOrUndefined(l.start)&&(l.start="none"),O.isNullOrUndefined(l.end)&&(l.end="arrowSolid"),this.drawArrowHead(r,!0),this.drawArrowHead(r,!1),"none"===l.end&&this.shapeLine(r,s.startX,s.startY,s.endX,s.endY),r.fillStyle=C,O.isNullOrUndefined(i)&&r===this.upperContext&&this.drawOuterSelection(r);break;case"path":if(1<(n=O.extend({},a.activeObj,{},!0)).pointColl.length){var b={shape:null};if(a.notify("selection",{prop:"getCurrentDrawingShape",value:{obj:b}}),"path"===b.shape)for(var m={x:0,y:0},y=0,P=n.pointColl.length;y<P;y++)O.isNullOrUndefined(n.pointColl[y+1])?(m.x=n.activePoint.endX,m.y=n.activePoint.endY):(m.x=n.pointColl[y+1].x,m.y=n.pointColl[y+1].y),s.startX=n.pointColl[y].x,s.startY=n.pointColl[y].y,s.endX=m.x,s.endY=m.y,a.activeObj=this.updateWidthHeight(a.activeObj),this.shapeLine(r,s.startX,s.startY,s.endX,s.endY);else for(y=1,P=n.pointColl.length;y<P;y++)s.startX=n.pointColl[y-1].x,s.startY=n.pointColl[y-1].y,s.endX=n.pointColl[y].x,s.endY=n.pointColl[y].y,a.activeObj=this.updateWidthHeight(a.activeObj),this.shapeLine(r,s.startX,s.startY,s.endX,s.endY);a.activeObj=l=n}else this.shapeLine(r,s.startX,s.startY,s.endX,s.endY);r===this.upperContext&&this.drawOuterSelection(r);break;case"text":this.shapeText(r);break;case"image":this.shapeImage(r),O.isNullOrUndefined(i)&&r===this.upperContext&&this.drawOuterSelection(r);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":r===this.lowerContext&&(r=this.upperContext),this.drawSelection(u,g),a.currObjType.shape="";break;default:this.drawSelection(u,g)}this.rotateContext("reverse",r)},t.prototype.updatePoints=function(){var e=this.parent,t=e.activeObj.activePoint,o=e.img,i=o.destLeft,o=o.destTop;t.startX+=i,t.startY+=o,t.endX+=i,t.endY+=o,e.activeObj=this.updateWidthHeight(e.activeObj)},t.prototype.updateWidthHeight=function(e){var t=e.activePoint,o=t.startX,i=t.startY,r=t.endX,t=t.endY;return e.activePoint.width=r-o,e.activePoint.height=t-i,e},t.prototype.drawCornerCircles=function(e){var t,o,i=this.parent,r=i.activeObj;e.beginPath(),e.rect(r.activePoint.startX,r.activePoint.startY,r.activePoint.width,r.activePoint.height),e.stroke(),e.closePath(),i.selectionSettings.showCircle&&(t=e.strokeStyle,o=e.fillStyle,e.strokeStyle=i.selectionSettings.strokeColor,e.fillStyle=i.selectionSettings.fillColor,e.lineWidth*=2,e.beginPath(),e.moveTo(r.topLeftCircle.startX,r.topLeftCircle.startY),e.arc(r.topLeftCircle.startX,r.topLeftCircle.startY,r.topLeftCircle.radius,0,2*Math.PI),e.moveTo(r.topRightCircle.startX,r.topRightCircle.startY),e.arc(r.topRightCircle.startX,r.topRightCircle.startY,r.topRightCircle.radius,0,2*Math.PI),e.moveTo(r.bottomLeftCircle.startX,r.bottomLeftCircle.startY),e.arc(r.bottomLeftCircle.startX,r.bottomLeftCircle.startY,r.bottomLeftCircle.radius,0,2*Math.PI),e.moveTo(r.bottomRightCircle.startX,r.bottomRightCircle.startY),e.arc(r.bottomRightCircle.startX,r.bottomRightCircle.startY,r.bottomRightCircle.radius,0,2*Math.PI),e.stroke(),e.fill(),e.closePath(),e.lineWidth/=2,e.strokeStyle=t,e.fillStyle=o)},t.prototype.drawCenterCircles=function(e){var t=this.parent,o=t.activeObj.activePoint,i=t.activeObj;if(e.lineWidth*=2,e.beginPath(),"arrow"===i.shape||"line"===i.shape)e.moveTo(o.startX,o.startY),e.arc(o.startX,o.startY,i.topCenterCircle.radius,0,2*Math.PI),e.moveTo(o.endX,o.endY),e.arc(o.endX,o.endY,i.bottomCenterCircle.radius,0,2*Math.PI);else if("path"===i.shape){var r=O.extend({},t.activeObj,{},!0);if(1<r.pointColl.length)for(var n=1,a=r.pointColl.length;n<a;n++)o.startX=r.pointColl[n-1].x,o.startY=r.pointColl[n-1].y,o.endX=r.pointColl[n].x,o.endY=r.pointColl[n].y,e.moveTo(o.startX,o.startY),e.arc(o.startX,o.startY,i.topCenterCircle.radius,0,2*Math.PI),e.moveTo(o.endX,o.endY),e.arc(o.endX,o.endY,i.bottomCenterCircle.radius,0,2*Math.PI);var s={shape:null};t.notify("selection",{prop:"getCurrentDrawingShape",value:{obj:s}}),"path"===s.shape&&(t.activeObj=i=r),e.moveTo(o.startX,o.startY),e.arc(o.startX,o.startY,i.topCenterCircle.radius,0,2*Math.PI),e.moveTo(o.endX,o.endY),e.arc(o.endX,o.endY,i.bottomCenterCircle.radius,0,2*Math.PI)}else this.drawRotationArcLine(e),e.lineTo(i.rotationCirclePoint.x,i.rotationCirclePoint.y);e.stroke(),e.fill(),e.closePath(),"arrow"!==i.shape&&"line"!==i.shape&&"path"!==i.shape&&(e.beginPath(),e.moveTo(i.rotationCirclePoint.x,i.rotationCirclePoint.y),e.arc(i.rotationCirclePoint.x,i.rotationCirclePoint.y,i.bottomCenterCircle.radius,0,2*Math.PI),e.stroke(),e.fill(),e.closePath()),e.lineWidth/=2},t.prototype.drawRotationArcLine=function(e){var t=this.parent,o=t.activeObj,i=(O.isNullOrUndefined(o.rotationCircleLine)&&(o.rotationCircleLine=22.5),!1),r=!1,t=0===o.shapeDegree?t.transform.degree:t.transform.degree-o.shapeDegree;if(t<0&&(t=360+t),o.flipObjColl)for(var n=0,a=o.flipObjColl.length;n<a;n++){var s=o.flipObjColl[n].toLowerCase();"horizontal"===s?i=!0:"vertical"===s&&(r=!0)}switch(t){case 0:case 360:r?(o.rotationCirclePoint={x:o.topCenterCircle.startX,y:o.topCenterCircle.startY-o.rotationCircleLine},e.moveTo(o.rotationCirclePoint.x,o.rotationCirclePoint.y+o.rotationCircleLine)):(o.rotationCirclePoint={x:o.bottomCenterCircle.startX,y:o.bottomCenterCircle.startY+o.rotationCircleLine},e.moveTo(o.rotationCirclePoint.x,o.rotationCirclePoint.y-o.rotationCircleLine));break;case 90:case-270:i?(o.rotationCirclePoint={x:o.centerRightCircle.startX+o.rotationCircleLine,y:o.centerLeftCircle.startY},e.moveTo(o.rotationCirclePoint.x-o.rotationCircleLine,o.rotationCirclePoint.y)):(o.rotationCirclePoint={x:o.centerLeftCircle.startX-o.rotationCircleLine,y:o.centerLeftCircle.startY},e.moveTo(o.rotationCirclePoint.x+o.rotationCircleLine,o.rotationCirclePoint.y));break;case 180:case-180:r?(o.rotationCirclePoint={x:o.bottomCenterCircle.startX,y:o.bottomCenterCircle.startY+o.rotationCircleLine},e.moveTo(o.rotationCirclePoint.x,o.rotationCirclePoint.y-o.rotationCircleLine)):(o.rotationCirclePoint={x:o.topCenterCircle.startX,y:o.topCenterCircle.startY-o.rotationCircleLine},e.moveTo(o.rotationCirclePoint.x,o.rotationCirclePoint.y+o.rotationCircleLine));break;case 270:case-90:i?(o.rotationCirclePoint={x:o.centerLeftCircle.startX-o.rotationCircleLine,y:o.centerLeftCircle.startY},e.moveTo(o.rotationCirclePoint.x+o.rotationCircleLine,o.rotationCirclePoint.y)):(o.rotationCirclePoint={x:o.centerRightCircle.startX+o.rotationCircleLine,y:o.centerLeftCircle.startY},e.moveTo(o.rotationCirclePoint.x-o.rotationCircleLine,o.rotationCirclePoint.y))}},t.prototype.drawSquareLines=function(e){var t,o=this.parent.activeObj,i=o.activePoint,r=i.startX,n=i.startY,a=i.width,i=i.height,s=o.strokeSettings,l=s.fillColor,p=s.strokeColor,s=s.strokeWidth;"crop"===(t=o.shape?o.shape.split("-"):t)[0]?e.strokeStyle="#fff":e.strokeStyle=p,e.beginPath(),e.rect(r,n,a,i),""!==l&&(e.fillStyle=l,e.fill()),e.rect(r+s,n+s,a-2*s,i-2*s),e.fillStyle=p,e.fill("evenodd"),e.closePath()},t.prototype.drawSelection=function(e,t){var o=this.parent,i=o.activeObj,r=i.activePoint,n=r.startX,a=r.startY,s=r.endX,r=r.endY;this.upperContext.strokeStyle=o.themeColl[o.theme].primaryColor,this.upperContext.beginPath(),i.horTopInnerLine={startX:n,startY:a+t,endX:s,endY:r+t},i.horBottomInnerLine={startX:n,startY:a+2*t,endX:s,endY:r+2*t},i.verLeftInnerLine={startX:n+e,startY:a,endX:n+e,endY:r},i.verRightInnerLine={startX:n+2*e,startY:a,endX:n+2*e,endY:r},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()},t.prototype.shapeCircle=function(e,t,o){var i=this.parent,r=i.activeObj.activePoint,n=r.startX,a=r.startY,s=r.endX,l=r.endY,r=r.width,p=(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),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-n)/2+n,(l-a)/2+a,r/2,0,2*Math.PI),e.closePath(),e.clip(),e.clearRect(0,0,i.lowerCanvas.width,i.lowerCanvas.height),e.restore(),e.lineWidth=p,this.drawOuterSelection(e,!0),i.currObjType.shape=""},t.prototype.shapeLine=function(e,t,o,i,r){var n=e.lineWidth;e.lineWidth=this.parent.activeObj.strokeSettings.strokeWidth,e.beginPath(),e.moveTo(t,o),e.lineTo(i,r),e.stroke(),e.lineWidth=n},t.prototype.manipulateSaveCtx=function(e,t,o){var i;return e!==this.lowerContext&&e!==this.upperContext&&(this.parent.notify("crop",{prop:"calcRatio",onPropertyChange:!(i={width:0,height:0}),value:{obj:i,dimension:{width:e.canvas.width,height:e.canvas.height}}}),t&&(t*=i.width),o)&&(o*=i.height),{x:t,y:o}},t.prototype.arrow=function(e,t){var o=this.parent.activeObj,i=o.activePoint,r=i.startX,n=i.startY,a=i.endX,i=i.endY,s=o.strokeSettings.strokeWidth,l=(e.lineWidth=s,this.arrowDimension.arrow.width),p=this.arrowDimension.arrow.height,h=this.manipulateSaveCtx(e,l,p),l=h.x+s,p=h.y+s,h=(this.dx=a-r,this.dy=i-n,e.fillStyle=o.strokeSettings.strokeColor,Math.atan2(this.dy,this.dx)),s="arrow"===o.start,d="arrow"===o.end,c="circle"===o.end||"square"===o.end;((t&&"left"===o.triangleDirection||"right"===o.triangleDirection)&&(s&&"none"===o.end||s&&!c)||!t&&(d&&"none"===o.start||!s&&!c))&&this.shapeLine(e,r,n,a,i),t&&"left"===o.triangleDirection||!t&&"right"===o.triangleDirection?(e.translate(a,i),e.rotate(h),this.shapeLine(e,0,0,-l,p/2),this.shapeLine(e,0,0,-l,-p/2),e.rotate(-h),e.translate(-a,-i)):(t&&"right"===o.triangleDirection||!t&&"left"===o.triangleDirection)&&(e.translate(r,n),e.rotate(h),this.shapeLine(e,0,0,l,p/2),this.shapeLine(e,0,0,l,-p/2),e.rotate(-h),e.translate(-r,-n))},t.prototype.arrowSolid=function(e,t){var o=this.parent.activeObj,i=o.strokeSettings.strokeWidth,r=o.activePoint,n=r.startX,a=r.startY,s=r.endX,r=r.endY,l=this.arrowDimension.arrowSolid.width,p=this.arrowDimension.arrowSolid.height,h=this.manipulateSaveCtx(e,l,p),l=h.x+i,p=h.y+i,h=(this.dx=s-n,this.dy=r-a,Math.atan2(this.dy,this.dx)),d="arrowSolid"===o.start,c="arrowSolid"===o.end,u="circle"===o.end||"square"===o.end;(t&&d&&"none"===o.end||d&&!u||!t&&(c&&"none"===o.start||!d&&!u))&&this.shapeLine(e,n,a,s,r),t&&"left"===o.triangleDirection||!t&&"right"===o.triangleDirection?(e.translate(s,r),e.rotate(h),e.beginPath(),e.moveTo(i,0),e.lineTo(p/2-l,p/2),e.lineTo(p/2-l,-p/2),e.closePath(),e.fill(),e.rotate(-h),e.translate(-s,-r),o.rotatedAngle=h):(t&&"right"===o.triangleDirection||!t&&"left"===o.triangleDirection)&&(e.translate(n,a),e.rotate(h),e.beginPath(),e.moveTo(0-i,0),e.lineTo(l-p/2,p/2),e.lineTo(l-p/2,-p/2),e.closePath(),e.fill(),e.rotate(-h),e.translate(-n,-a),o.rotatedAngle=h)},t.prototype.arrowSquareStart=function(e){var t=this.parent.activeObj,o=t.strokeSettings.strokeWidth,i=t.activePoint,r=i.startX,n=i.startY,a=i.endX,i=i.endY,s="square"===t.start,l="circle"===t.end,p="squareSolid"===t.start,h="circleSolid"===t.end,s=((s&&"none"===t.end||s&&!l&&"square"!==t.start||p&&h)&&this.shapeLine(e,r,n,a,i),e.lineWidth=o,e.beginPath(),e.fillStyle=t.strokeSettings.strokeColor,this.arrowDimension.square.width),l=this.arrowDimension.square.height,p=this.manipulateSaveCtx(e,s,l),s=p.x+o,l=p.y+o,h=(this.dx=a-r,this.dy=i-n,Math.atan2(this.dy,this.dx));"left"===t.triangleDirection?(e.translate(a,i),e.rotate(h),"squareSolid"===t.start&&e.fillRect(l/2-s,-l/2,s,l),e.strokeRect(l/2-s,-l/2,s,l),e.rotate(-h),e.translate(-a,-i),this.squareStartIntersectX1=a-l/2*Math.cos(h),this.squareStartIntersectY1=i-l/2*Math.sin(h),"square"===t.start&&"square"!==t.end&&"circle"!==t.end?this.shapeLine(e,r,n,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,n,a,i)):"right"===t.triangleDirection&&(e.lineWidth=o,e.fillStyle=t.strokeSettings.strokeColor,"squareSolid"===t.start&&"squareSolid"===t.end&&this.shapeLine(e,r,n,a,i),e.translate(r,n),e.rotate(h),"squareSolid"===t.start&&e.fillRect(l/2-s,-l/2,s,l),e.strokeRect(l/2-s,-l/2,s,l),e.rotate(-h),e.translate(-r,-n),t.rotatedAngle=h,this.squareStartIntersectX1=r+l/2*Math.cos(h),this.squareStartIntersectY1=n+l/2*Math.sin(h),"square"===t.start&&"square"!==t.end&&"circle"!==t.end&&this.shapeLine(e,a,i,this.squareStartIntersectX1,this.squareStartIntersectY1),"square"===t.start)&&"circle"===t.end&&this.shapeLine(e,this.endCircleIntersectX1,this.endCircleIntersectY1,this.squareStartIntersectX1,this.squareStartIntersectY1)},t.prototype.arrowSquareEnd=function(e){var t=this.parent.activeObj,o=t.activePoint,i=o.startX,r=o.startY,n=o.endX,o=o.endY,a=t.strokeSettings.strokeWidth,s=this.arrowDimension.square.width,l=this.arrowDimension.square.height,p=this.manipulateSaveCtx(e,s,l),s=p.x+a,l=p.y+a,p=(this.dx=n-i,this.dy=o-r,Math.atan2(this.dy,this.dx));e.lineWidth=a,"right"===t.triangleDirection?(e.fillStyle=t.strokeSettings.strokeColor,"squareSolid"===t.end&&"none"===t.start&&this.shapeLine(e,i,r,n,o),e.translate(n,o),e.rotate(p),"squareSolid"===t.end&&e.fillRect(l/2-s,-l/2,s,l),e.strokeRect(l/2-s,-l/2,s,l),e.rotate(-p),e.translate(-n,-o),t.rotatedAngle=p,this.squareEndIntersectX1=n-l/2*Math.cos(p),this.squareEndIntersectY1=o-l/2*Math.sin(p),"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(p),"squareSolid"===t.end&&e.fillRect(l/2-s,-l/2,s,l),e.strokeRect(l/2-s,-l/2,s,l),e.rotate(-p),e.translate(-i,-r),t.rotatedAngle=p,this.squareEndIntersectX1=i+l/2*Math.cos(p),this.squareEndIntersectY1=r+l/2*Math.sin(p),"square"===t.end&&"square"!==t.start&&"circle"!==t.start?this.shapeLine(e,n,o,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))},t.prototype.arrowCircle=function(e,t){var o,i,r,n,a,s,l,p,h=this.parent,d=h.activeObj,c=d.activePoint,u=c.startX,g=c.startY,v=c.endX,c=c.endY,f=d.strokeSettings.strokeWidth;t&&"left"===d.triangleDirection||!t&&"right"===d.triangleDirection?(e.lineWidth=f,o=this.arrowDimension.circle.width,o=this.manipulateSaveCtx(e,o,null).x+f,e.beginPath(),e.arc(v,c,o,0,2*Math.PI),e.stroke(),e.closePath(),this.dx=v-u,this.dy=c-g,i=this.dx*this.dx+this.dy*this.dy,0<=(n=(r=2*(this.dx*(u-v)+this.dy*(g-c)))*r-4*i*((u-v)*(u-v)+(g-c)*(g-c)-o*o))&&(e.fillStyle=d.strokeSettings.strokeColor,a=(-r-Math.sqrt(n))/(2*i),s=u+this.dx*a,l=g+this.dy*a,t?(this.startCircleIntersectX1=s,this.startCircleIntersectY1=l,this.endCircleIntersectX1=v-this.dx*a,this.endCircleIntersectY1=c-this.dy*a,e.beginPath(),e.fill(),e.beginPath(),"circle"===d.start&&"circle"===d.end?this.shapeLine(e,this.startCircleIntersectX1,this.startCircleIntersectY1,this.endCircleIntersectX1,this.endCircleIntersectY1):"circle"===d.start&&"circle"!==d.end&&"square"!==d.end&&this.shapeLine(e,u,g,this.startCircleIntersectX1,this.startCircleIntersectY1),e.stroke(),e.closePath()):(this.endCircleIntersectX1=s,this.endCircleIntersectY1=l,"circle"===d.end&&"circle"!==d.start&&"square"!==d.start&&this.shapeLine(e,u,g,this.endCircleIntersectX1,this.endCircleIntersectY1))),p=Math.atan2(this.dy,this.dx),h.activeObj.rotatedAngle=p):(t&&"right"===d.triangleDirection||!t&&"left"===d.triangleDirection)&&(e.lineWidth=f,o=this.arrowDimension.circle.width,o=this.manipulateSaveCtx(e,o,null).x+f,e.beginPath(),e.arc(u,g,o,0,2*Math.PI),e.stroke(),e.closePath(),this.dx=u-v,this.dy=g-c,i=this.dx*this.dx+this.dy*this.dy,0<=(n=(r=2*(this.dx*(v-u)+this.dy*(c-g)))*r-4*i*((v-u)*(v-u)+(c-g)*(c-g)-o*o))&&(e.fillStyle=d.strokeSettings.strokeColor,a=(-r-Math.sqrt(n))/(2*i),s=v+this.dx*a,l=c+this.dy*a,t?(this.startCircleIntersectX1=s,this.startCircleIntersectY1=l,this.endCircleIntersectX1=u-this.dx*a,this.endCircleIntersectY1=g-this.dy*a,"circle"===d.start&&"circle"===d.end?this.shapeLine(e,this.endCircleIntersectX1,this.endCircleIntersectY1,this.startCircleIntersectX1,this.startCircleIntersectY1):"circle"===d.start&&"circle"!==d.end&&"square"!==d.end&&this.shapeLine(e,v,c,this.startCircleIntersectX1,this.startCircleIntersectY1)):(this.endCircleIntersectX1=s,this.endCircleIntersectY1=l,e.beginPath(),e.fill(),e.beginPath(),"circle"===d.end&&"circle"!==d.start&&"square"!==d.start&&this.shapeLine(e,v,c,this.endCircleIntersectX1,this.endCircleIntersectY1))),p=Math.atan2(this.dy,this.dx),h.activeObj.rotatedAngle=p)},t.prototype.arrowCircleSolid=function(e,t){var o,i=this.parent.activeObj,r=i.activePoint,n=r.startX,a=r.startY,s=r.endX,r=r.endY,l="circleSolid"===i.start,p=i.strokeSettings.strokeWidth;t&&"left"===i.triangleDirection||!t&&"right"===i.triangleDirection?(e.lineWidth=p,e.beginPath(),e.fillStyle=i.strokeSettings.strokeColor,(t&&l&&"none"===i.end||l&&"circle"!==i.end&&"square"!==i.end||!t&&"circleSolid"===i.end&&"none"===i.start)&&this.shapeLine(e,n,a,s,r),o=this.arrowDimension.circle.width,o=this.manipulateSaveCtx(e,o,null).x+p,this.dx=s-n,this.dy=r-a,e.save(),e.beginPath(),e.arc(s,r,o,0,2*Math.PI),e.stroke(),e.fill(),e.closePath(),i.rotatedAngle=Math.atan2(this.dy,this.dx)):(t&&"right"===i.triangleDirection||!t&&"left"===i.triangleDirection)&&(e.lineWidth=p,e.beginPath(),e.fillStyle=i.strokeSettings.strokeColor,(t&&l&&"none"===i.end||l&&"circle"!==i.end&&"square"!==i.end||!t&&"circleSolid"===i.end&&"none"===i.start)&&this.shapeLine(e,n,a,s,r),o=this.arrowDimension.circle.width,o=this.manipulateSaveCtx(e,o,null).x+p,this.dx=s-n,this.dy=r-a,e.save(),e.beginPath(),e.arc(n,a,o,0,2*Math.PI),e.stroke(),e.fill(),e.closePath(),i.rotatedAngle=Math.atan2(this.dy,this.dx))},t.prototype.arrowBar=function(e,t){var o,i,r,n,a=this.parent,s=a.activeObj,l=s.activePoint,p=l.startX,h=l.startY,d=l.endX,l=l.endY,c=s.strokeSettings.strokeWidth;t&&"left"===s.triangleDirection||!t&&"right"===s.triangleDirection?(e.lineWidth=c,e.beginPath(),e.fillStyle=s.strokeSettings.strokeColor,(t&&"bar"===s.start&&"none"===s.end||"bar"===s.start&&"circle"!==s.end&&"square"!==s.end||!t&&("bar"===s.end&&"none"===s.start||"bar"===s.end&&"circle"!==s.start&&"square"!==s.start))&&this.shapeLine(e,p,h,d,l),o=this.arrowDimension.bar.width,i=this.arrowDimension.bar.height,o=(r=this.manipulateSaveCtx(e,o,i)).x+c,i=r.y+c,this.dx=d-p,this.dy=l-h,n=Math.atan2(this.dy,this.dx),e.translate(d,l),e.rotate(n),e.fillRect(i/4-o,-i/2,o,i),e.rotate(-n),e.translate(-d,-l),s.rotatedAngle=n):(t&&"right"===s.triangleDirection||!t&&"left"===s.triangleDirection)&&(e.lineWidth=c,e.beginPath(),e.fillStyle=s.strokeSettings.strokeColor,(t&&"bar"===s.start&&"none"===s.end||"bar"===s.start&&"circle"!==s.end&&"square"!==s.end||!t&&"bar"===s.end&&"none"===s.start)&&this.shapeLine(e,p,h,d,l),o=this.arrowDimension.bar.width,i=this.arrowDimension.bar.height,o=(r=this.manipulateSaveCtx(e,o,i)).x+c,i=r.y+c,this.dx=d-p,this.dy=l-h,n=Math.atan2(this.dy,this.dx),e.translate(p,h),e.rotate(n),e.fillRect(i/4-o,-i/2,o,i),e.rotate(-n),e.translate(-p,-h),a.activeObj.rotatedAngle=n)},t.prototype.shapeImage=function(e){var t=this.parent,o=t.activeObj,i=o.activePoint,r=i.startX,n=i.startY,a=i.width,i=i.height,s=o.imageCanvas.getContext("2d"),l=(e===this.lowerContext&&this.isImageApply&&(t.notify("transform",{prop:"calcMaxDimension",onPropertyChange:!(l={width:0,height:0}),value:{width:o.imageElement.width,height:o.imageElement.height,obj:l,isImgShape:null}}),a<l.width/5||i<l.height/5)&&(s.clearRect(0,0,o.imageCanvas.width,o.imageCanvas.height),t.notify("selection",{prop:"applyTransformToImg",onPropertyChange:!1,value:{ctx:s}}),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),{startX:0,startY:0,width:0,height:0}),s=(l.width=a,l.height=i,4===o.flipObjColl.length&&(o.flipObjColl=[],o.shapeFlip=""),l.startX=(a-l.width)/2+r,l.startY=(i-l.height)/2+n,e.globalAlpha);e.globalAlpha=o.opacity,o.rotateFlipColl&&0<o.rotateFlipColl.length?this.rotateImage(e):e.drawImage(o.imageCanvas,l.startX,l.startY,l.width,l.height),e.globalAlpha=s,t.currObjType.isText=!1},t.prototype.shapeText=function(e){var t=this.parent,o=e.filter,i=t.activeObj,r=i.activePoint,n=r.startX,a=r.startY,s=r.width,l=r.height,p=i.keyHistory.split("\n"),r=i.textSettings,h=r.fontFamily,d=r.bold,c=r.italic,u=i.textSettings.fontSize,g=((u+.25*u)*p.length-u*p.length)/p.length;e.filter="none";for(var v=0;v<p.length;v++){var f=p[v],C=(v+1)*u*.85+v*g,b=(-360===t.transform.degree&&(t.transform.degree=0),0===t.transform.degree||180===t.transform.degree?l<u&&(u=i.textSettings.fontSize=l-.1*l):s<u&&(u=i.textSettings.fontSize=s-.1*s),e.strokeStyle=i.strokeSettings.strokeColor,e.fillStyle=i.strokeSettings.strokeColor,"");d&&(b="bold "),c&&(b="italic "),e.font=(b=d&&c?"italic bold ":b)+u+"px "+h,4===i.flipObjColl.length&&(i.flipObjColl=[],i.shapeFlip=""),i.rotateFlipColl&&0<i.rotateFlipColl.length?this.rotateText(e):e.fillText(f,n+.1*u,a+C)}e.filter=o,t.currObjType.isText=!1},t.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},t.prototype.rotateImage=function(e){var t,o=this.parent,i=o.activeObj,r=O.extend({},o.activeObj,null,!0),n=0===i.shapeDegree?o.transform.degree:o.transform.degree-i.shapeDegree,a={startX:0,startY:0,width:0,height:0},s=(a.width=(n=(n=-450===n?-90:n)<0?360+n:n)%90==0&&n%180!=0?i.activePoint.height:i.activePoint.width,a.height=n%90==0&&n%180!=0?i.activePoint.width:i.activePoint.height,a.startX=i.activePoint.startX,a.startY=i.activePoint.startY,a.startX),l=a.startY;e.save();for(var p=0,h=i.rotateFlipColl.length;p<h;p++){var d=i.rotateFlipColl[p];"number"==typeof d?(t=0===i.shapeDegree?d:d-i.shapeDegree,a.width=(t=(t=-450===t?-90:t)<0?360+t:t)%90==0&&t%180!=0?i.activePoint.height:i.activePoint.width,a.height=t%90==0&&t%180!=0?i.activePoint.width:i.activePoint.height,e.translate(e.canvas.width/2,e.canvas.height/2),e.rotate(Math.PI/180*d),e.translate(-e.canvas.height/2,-e.canvas.width/2),t%90==0&&t%270!=0||0===t?(l=e.canvas.width-(i.activePoint.startX+i.activePoint.width),l+=(i.activePoint.width-a.height)/2,s=a.startY):t%270==0&&(s=e.canvas.height-(i.activePoint.startY+i.activePoint.height),s+=(i.activePoint.height-a.width)/2,l=a.startX),a.startX=s,a.startY=l,i.activePoint.startX=s,i.activePoint.startY=l,i.activePoint.endX=i.activePoint.startX+a.width,i.activePoint.endY=i.activePoint.startY+a.height,i=this.updateWidthHeight(i)):("horizontal"===d&&n%90==0&&n%180!=0?d="vertical":"vertical"===d&&n%90==0&&n%180!=0&&(d="horizontal"),"horizontal"===d?(e.translate(e.canvas.width,0),e.scale(-1,1),i.activePoint=this.updateActPoint("horizontal",e)):"vertical"===d&&(e.translate(0,e.canvas.height),e.scale(1,-1),i.activePoint=this.updateActPoint("vertical",e)),a.startX=i.activePoint.startX,a.startY=i.activePoint.startY),a.startX=i.activePoint.startX,a.startY=i.activePoint.startY,s=a.startX,l=a.startY}0!==i.rotatedAngle&&o.notify("shape",{prop:"setPointCollForShapeRotation",onPropertyChange:!1,value:{obj:i}}),e.drawImage(i.imageCanvas,a.startX,a.startY,a.width,a.height),e.restore(),o.activeObj=r,360!==o.transform.degree&&-360!==o.transform.degree||(o.transform.degree=0)},t.prototype.rotateText=function(e){var t,o=this.parent,i=o.activeObj,r=O.extend({},o.activeObj,null,!0),n=o.activeObj.activePoint,a=0===i.shapeDegree?o.transform.degree:o.transform.degree-i.shapeDegree,s={startX:0,startY:0,width:0,height:0},l=(s.width=(a=(a=-450===a?-90:a)<0?360+a:a)%90==0&&a%180!=0?n.height:n.width,s.height=a%90==0&&a%180!=0?n.width:n.height,s.startX=n.startX,s.startY=n.startY,s.startX),p=s.startY;e.save();for(var h=0,d=i.rotateFlipColl.length;h<d;h++){var c=i.rotateFlipColl[h];"number"==typeof c?(t=0===i.shapeDegree?c:c-i.shapeDegree,s.width=(t=(t=-450===t?-90:t)<0?360+t:t)%90==0&&t%180!=0?n.height:n.width,s.height=t%90==0&&t%180!=0?n.width:n.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),t%90==0&&t%270!=0||0===t?(p=e.canvas.width-n.endX,l=n.startY):t%270==0&&(l=e.canvas.height-n.endY,p=n.startX),s.startX=l,s.startY=p,n.startX=l,n.startY=p,n.endX=n.startX+s.width,n.endY=n.startY+s.height,i=this.updateWidthHeight(i)):("horizontal"===c&&a%90==0&&a%180!=0?c="vertical":"vertical"===c&&a%90==0&&a%180!=0&&(c="horizontal"),"horizontal"===c?(e.translate(e.canvas.width,0),e.scale(-1,1)):"vertical"===c&&(e.translate(0,e.canvas.height),e.scale(1,-1)),i.activePoint=n=this.updateActPoint(c,e),s.startX=n.startX,s.startY=n.startY),s.startX=n.startX,s.startY=n.startY,l=s.startX,p=s.startY}0!==i.rotatedAngle&&o.notify("shape",{prop:"setPointCollForShapeRotation",onPropertyChange:!1,value:{obj:i}}),p+=.4*i.textSettings.fontSize,this.textFlipDegree(e,l,p),e.restore(),o.activeObj=r,360!==o.transform.degree&&-360!==o.transform.degree||(o.transform.degree=0)},t.prototype.textFlipDegree=function(e,t,o){for(var i=this.parent.activeObj,r=i.keyHistory.split("\n"),n=i.textSettings.fontSize,a=.85*n+(n*r.length-n*r.length)/r.length,s=0,l=r.length;s<l;s++){var p=r[s];0<s&&(1===s&&(a-=.85*n),a+=n+.15*n),e.fillText(p,t+.15*n,o+a+(0<s?.25*n:.35*-n))}},t.prototype.clearOuterCanvas=function(e){var t=this.parent,o=t.img,i=o.destLeft,r=o.destTop,n=o.destWidth,o=o.destHeight,a=0<r?r:0;e.clearRect(0,0,0<i?i:0,t.lowerCanvas.height),e.clearRect(i+n,0,t.lowerCanvas.width-(i+n),t.lowerCanvas.height),e.clearRect(0,0,t.lowerCanvas.width,a),e.clearRect(0,r+o,t.lowerCanvas.width,t.lowerCanvas.height-(r+o)),""!==t.transform.currFlipState&&(t.img.destLeft=i,t.img.destTop=r)},t.prototype.setDestPoints=function(){var e,t,o=this.parent,i=o.transform,r=i.degree,i=i.zoomFactor;r%90==0&&r%180!=0?(o.notify("transform",{prop:"calcMaxDimension",onPropertyChange:!(t={width:0,height:0}),value:{width:o.img.srcHeight,height:o.img.srcWidth,obj:t,isImgShape:null}}),e=t,this.isRotateZoom&&(e.width+=e.width*i,e.height+=e.height*i,o.img.destWidth=e.height,o.img.destHeight=e.width),o.img.destLeft=(o.lowerCanvas.clientWidth-e.height)/2,o.img.destTop=(o.lowerCanvas.clientHeight-e.width)/2,o.img.destWidth=e.height,o.img.destHeight=e.width):(o.notify("transform",{prop:"calcMaxDimension",onPropertyChange:!(t={width:0,height:0}),value:{width:o.img.srcWidth,height:o.img.srcHeight,obj:t,isImgShape:null}}),e=t,this.isRotateZoom&&(e.width+=e.width*i,e.height+=e.height*i,o.img.destWidth=e.width,o.img.destHeight=e.height),o.img.destLeft=(o.lowerCanvas.clientWidth-e.width)/2,o.img.destTop=0===r?(o.lowerCanvas.clientHeight-e.height+1)/2:(o.lowerCanvas.clientHeight-e.height)/2,o.img.destWidth=e.width,o.img.destHeight=e.height)},t.prototype.updateCurrTransState=function(e,t,o,i){var r=this.parent,n=r.img.destLeft,a=r.img.destTop;"initial"===e&&(this.lowerContext.setTransform(1,0,0,1,0,0),O.isNullOrUndefined(t))&&this.setDestPoints(),r.isCircleCrop||r.currSelectionPoint&&"crop-circle"===r.currSelectionPoint.shape?(this.currTransState(e,!0,null,o),0===r.transform.degree&&""===r.transform.currFlipState&&0===r.transform.straighten&&O.isNullOrUndefined(i)&&(r.img.destLeft=n,r.img.destTop=a),o&&(r.img.destLeft+=r.panPoint.totalPannedClientPoint.x,r.img.destTop+=r.panPoint.totalPannedClientPoint.y),r.notify("crop",{prop:"cropCircle",onPropertyChange:!1,value:{context:this.lowerContext,isSave:null,isFlip:null}}),o&&(r.img.destLeft-=r.panPoint.totalPannedClientPoint.x,r.img.destTop-=r.panPoint.totalPannedClientPoint.y)):(this.currTransState(e,null,null,o),0===r.transform.degree&&""===r.transform.currFlipState&&0===r.transform.straighten&&O.isNullOrUndefined(i)&&(r.img.destLeft=n,r.img.destTop=a))},t.prototype.currTransState=function(e,t,o,i){var r=this.parent;o=o||this.lowerContext,"initial"===e?this.setTransformColl(o,e):"reverse"===e&&(this.setTransformColl(o,e),this.setClientTransDim(t),r.isCircleCrop||r.currSelectionPoint&&"crop-circle"===r.currSelectionPoint.shape&&O.isNullOrUndefined(i))&&(i&&(r.img.destLeft+=r.panPoint.totalPannedClientPoint.x,r.img.destTop+=r.panPoint.totalPannedClientPoint.y),r.notify("crop",{prop:"cropCircle",onPropertyChange:!1,value:{context:this.lowerContext,isSave:null,isFlip:null}}),i)&&(r.img.destLeft-=r.panPoint.totalPannedClientPoint.x,r.img.destTop-=r.panPoint.totalPannedClientPoint.y)},t.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;0<=i;i--)this.setTransform(e,o.rotateFlipColl[i],!0)},t.prototype.setTransform=function(e,t,o){var i=this.parent;switch(o&&90===t?t=-90:o&&-90===t&&(t=90),"horizontal"===t&&i.transform.degree%90==0&&i.transform.degree%180!=0?t="vertical":"vertical"===t&&i.transform.degree%90==0&&i.transform.degree%180!=0&&(t="horizontal"),i.notify("transform",{prop:"setReverseRotate",onPropertyChange:!1,value:{bool:!0}}),i.notify("transform",{prop:"setReverseFlip",onPropertyChange:!1,value:{isReverseFlip:!0}}),O.isNullOrUndefined(o)&&e.clearRect(0,0,e.canvas.width,e.canvas.height),t){case 90:case-90:e.translate(e.canvas.width/2,e.canvas.height/2),e.rotate(Math.PI/180*t),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)}i.notify("transform",{prop:"setReverseRotate",onPropertyChange:!1,value:{bool:!1}}),i.notify("transform",{prop:"setReverseFlip",onPropertyChange:!1,value:{isReverseFlip:!1}})},t.prototype.drawImgToCanvas=function(e){var t=this.parent,e=(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),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=e},t.prototype.renderImage=function(e,t,o,i){var r=this.parent;r.notify("shape",{prop:"applyActObj",onPropertyChange:!1,value:{isMouseDown:null}}),O.isNullOrUndefined(t)&&(this.upperContext.clearRect(0,0,r.lowerCanvas.width,r.lowerCanvas.height),this.lowerContext.clearRect(0,0,r.lowerCanvas.width,r.lowerCanvas.height)),e?this.setTransformColl(this.lowerContext,"initial"):(0!==r.transform.zoomFactor&&(this.isRotateZoom=!0),this.updateCurrTransState("initial",null,null,i)),r.notify("transform",{prop:"setDestPointsForFlipState",onPropertyChange:!1}),this.drawImage(),r.notify("transform",{prop:"setDestPointsForFlipState",onPropertyChange:!1}),e?this.setTransformColl(this.lowerContext,"reverse"):(this.updateCurrTransState("reverse",null,null,i),this.isRotateZoom=!1),o?r.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"zoom",pen:"zoom",isPreventApply:null}}):r.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"iterate",pen:"iterate",isPreventApply:null}}),this.clearOuterCanvas(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}})},t.prototype.imageOnLoad=function(o){var i=this,r=this.parent,n=this;r.baseImg.src=o,r.baseImg.onload=function(){r.imgSrc=o,r.notify("filter",{prop:"update-finetunes",onPropertyChange:!1}),n.lowerContext.drawImage(r.baseImg,0,0,n.parent.lowerCanvas.width,n.parent.lowerCanvas.height),u.hideSpinner(r.element),r.element.style.opacity="1",n.updateBaseImgCanvas();var e,t={fileName:i.fileName,fileType:i.fileType,isValidImage:!0};n.updateCanvas(),r.currObjType.isUndoZoom&&(r.currObjType.isUndoZoom=!1,n.parent.lowerCanvas.style.display="block"),r.isUndoRedo=i.isErrorImage=!1,O.Browser.isDevice?(r.notify("toolbar",{prop:"destroy-top-toolbar",onPropertyChange:!1}),r.notify("toolbar",{prop:"destroy-bottom-toolbar",onPropertyChange:!1}),e={isApplyBtn:!1,isDevice:O.Browser.isDevice,isOkBtn:null,isResize:null,isFrame:null,isMainToolbar:!0},r.notify("toolbar",{prop:"init-main-toolbar",onPropertyChange:!1,value:e}),r.notify("toolbar",{prop:"create-bottom-toolbar",onPropertyChange:!1})):(r.notify("toolbar",{prop:"destroy-top-toolbar",onPropertyChange:!1}),r.notify("toolbar",{prop:"init-main-toolbar",onPropertyChange:!(e={isApplyBtn:!1,isDevice:!1,isOkBtn:null}),value:e})),r.isImageLoaded&&"0.5"!==r.element.style.opacity&&r.trigger("fileOpened",t)},r.baseImg.onerror=function(){u.hideSpinner(r.element),n.isErrorImage=!0,n.errorLoading()}},t.prototype.errorLoading=function(){this.parent.trigger("fileOpened",{fileName:null,fileType:null,isValidImage:!1})},t.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)},t.prototype.updateCanvas=function(){var e=this.parent,t=(e.img.srcWidth=e.baseImgCanvas.width,e.img.srcHeight=e.baseImgCanvas.height,{width:0,height:0}),t=(e.notify("transform",{prop:"calcMaxDimension",onPropertyChange:!1,value:{width:e.img.srcWidth,height:e.img.srcHeight,obj:t,isImgShape:null}}),e.img.destLeft=(e.lowerCanvas.clientWidth-t.width)/2,e.img.destTop=(e.lowerCanvas.clientHeight-t.height+1)/2,this.drawImgToCanvas(t),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}}),{startX:e.img.destLeft,startY:e.img.destTop,width:e.img.destWidth,height:e.img.destHeight}),t=(e.notify("crop",{prop:"setCropDestPoints",onPropertyChange:!1,value:{point:t}}),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=t,0<e.img.destWidth&&0<e.img.destHeight&&(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),O.isNullOrUndefined(this.initZoomValue)&&(this.initZoomValue=e.zoomSettings.zoomFactor),this.isImageEdited=!1},t.prototype.resetFrameZoom=function(e){var t,o=this.parent;O.isNullOrUndefined(o.tempFrameZoomLevel)||(t=o.tempFrameZoomLevel,o.tempFrameZoomLevel=null,o.notify("transform",{prop:"resetZoom",onPropertyChange:!1}),o.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:t,zoomPoint:null,isResize:!0}}),t=o.cancelCropSelection,e&&t&&(t.previousObj.frameObj=O.extend({},o.frameObj,null,!0),t.currentObj.frameObj=O.extend({},o.frameObj,null,!0),t.previousObj.frame=t.currentObj.frame=o.frameObj.type),this.updateCropSelObj(),o.cancelCropSelection=null)},t.prototype.performCancel=function(e,t,o){var i=this.parent;o&&(i.noPushUndo=!1);var r,n=i.isStraightening,a=(e=e||!1,{bool:!1});i.allowDownScale=!0,i.notify("selection",{prop:"getFreehandDrawEditing",onPropertyChange:!1,value:{obj:a}}),O.isNullOrUndefined(t)&&JSON.stringify(i.frameObj)!==JSON.stringify(i.tempFrameObj)&&(O.extend(i.frameObj,i.tempFrameObj),this.renderImage(null,null,!0)),this.resetFrameZoom(!1),a.bool?(i.notify("freehand-draw",{prop:"cancelFhd",onPropertyChange:!1}),i.notify("toolbar",{prop:"destroy-qa-toolbar",onPropertyChange:!1}),i.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"ok"}})):"block"===i.textArea.style.display||"inline-block"===i.textArea.style.display?(i.textArea.style.display="none",i.textArea.value="",i.textArea.style.transform="",this.prevActObj?(i.activeObj=this.prevActObj,this.prevActObj=null):(i.activeObj.strokeSettings=this.tempStrokeSettings,i.activeObj.textSettings=this.tempTextSettings),i.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"cancel"}}),this.isShapeTextInserted&&i.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),i.notify("shape",{prop:"applyActObj",onPropertyChange:!1,value:{isMouseDown:!0}}),i.notify("toolbar",{prop:"refresh-main-toolbar",onPropertyChange:!1}),i.notify("selection",{prop:"setTempActObj",onPropertyChange:!1,value:{obj:i.activeObj}}),i.drawingShape&&i.enableShapeDrawing(i.toPascalCase(i.drawingShape),!0)):(!O.Browser.isDevice||O.Browser.isDevice&&!n)&&document.querySelector("#"+i.element.id+"_sliderWrapper")||i.currObjType.isFiltered?(this.lowerContext.filter=this.tempAdjValue,i.canvasFilter=this.tempAdjValue,i.notify("filter",{prop:"setAdjustmentValue",onPropertyChange:!1,value:{adjustmentValue:this.tempAdjValue}}),i.initialAdjustmentValue=this.tempAdjValue,1<this.lowerContext.filter.split(" ").length&&"1"===this.lowerContext.filter.split(" ")[0].split("(")[1].split(")")[0]&&i.notify("filter",{prop:"setBrightnessAdjusted",onPropertyChange:!1,value:{isBrightnessAdjusted:!1}}),i.currentFilter=this.tempFilter,i.notify("filter",{prop:"setBevelFilter",onPropertyChange:!1,value:{bevelFilter:this.lowerContext.filter}}),this.lowerContext.clearRect(0,0,i.lowerCanvas.width,i.lowerCanvas.height),this.redrawImgWithObj(),i.currObjType.isFiltered=!1,i.notify("filter",{prop:"getTempAdjustmentLevel",onPropertyChange:!(t={tempAdjustmentLevel:null}),value:{obj:t}}),i.notify("filter",{prop:"setAdjustmentLevel",onPropertyChange:!1,value:{adjustmentLevel:O.extend({},t.tempAdjustmentLevel,{},!0)}}),i.notify("undo-redo",{prop:"setUndoRedoStep",onPropertyChange:!1,value:{step:this.tempUndoRedoStep}}),i.upperCanvas.style.cursor=i.cursor="default",i.currObjType.isCustomCrop=!1,this.tempStrokeSettings={strokeColor:"#fff",fillColor:"",strokeWidth:null},this.clearOuterCanvas(this.lowerContext),(i.currSelectionPoint&&"crop-circle"===i.currSelectionPoint.shape||i.isCircleCrop)&&i.notify("crop",{prop:"cropCircle",onPropertyChange:!1,value:{context:this.lowerContext,isSave:null,isFlip:null}}),r={type:"main",isApplyBtn:null,isCropping:null,isZooming:null},i.element.querySelector(".e-contextual-toolbar-wrapper").classList.add("e-hide"),i.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:r}),i.activeObj.shape&&"image"===i.activeObj.shape&&i.notify("toolbar",{prop:"destroy-qa-toolbar",onPropertyChange:!1}),i.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"cancel"}}),i.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),this.upperContext.clearRect(0,0,i.upperCanvas.width,i.upperCanvas.height)):e&&(!O.Browser.isDevice||O.Browser.isDevice&&!n)?i.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!(r={type:"main",isApplyBtn:null,isCropping:null,isZooming:null}),value:r}):(this.cancelItems(),0<i.transform.zoomFactor?(i.togglePan=!0,i.notify("selection",{prop:"setDragCanvas",value:{bool:!0}})):(i.togglePan=!1,i.notify("selection",{prop:"setDragCanvas",value:{bool:!1}}))),this.isShapeTextInserted=!1,this.isNewPath=!1,i.notify("toolbar",{prop:"refresh-dropdown-btn",value:{isDisabled:!1}}),i.notify("toolbar",{prop:"setCurrentToolbar",value:{type:"main"}}),o&&(i.noPushUndo=!1),i.drawingShape=null,i.notify("draw",{prop:"resetTempObjColl"}),i.notify("draw",{prop:"resetTempPointColl"})},t.prototype.cancelItems=function(){var e,t=this.parent,o=!1,i=t.element.id,r=t.element.querySelector("#"+i+"_aspectratio"),i=t.element.querySelector("#"+i+"_nonaspectratio");switch((o=void 0===(e=void 0!==t.activeObj.shape?t.activeObj.shape.split("-"):e)&&t.currObjType.isCustomCrop||void 0!==e&&"crop"===e[0]?!0:o)&&t.isCropTab&&(t.isCropTab=!1,t.transform.zoomFactor=t.transform.defaultZoomFactor),t.isResize&&(r||i||"resize-toolbar"===t.currentToolbar)&&(t.notify("selection",{prop:"getNumTextValue",onPropertyChange:!(e={width:null,height:null}),value:{obj:e}}),r={x:e.width,y:e.height},i=t.element.querySelector("#"+t.element.id+"_aspectratio"),e=t.element.querySelector(".e-ie-toolbar-aspect-ratio-btn"),r.x&&r.y&&!O.isNullOrUndefined(t.aspectWidth)&&(i||e&&!e.classList.contains("e-hidden")?t.notify("transform",{prop:"resizeImage",value:{width:t.aspectWidth,height:t.aspectHeight}}):(r=t.currObjType.isUndoAction,t.currObjType.isUndoAction=!1,t.notify("transform",{prop:"resizeCrop",value:{width:t.aspectWidth,height:t.aspectHeight}}),t.currObjType.isUndoAction=r)),i={prevCropObj:t.prevCropObj},e={prevObj:t.prevObj},t.notify("toolbar",{prop:"getPrevCropObj",onPropertyChange:!1,value:{obj:i}}),t.notify("toolbar",{prop:"getPrevObj",onPropertyChange:!1,value:{obj:e}}),i.prevCropObj&&e.prevObj&&(t.objColl=[],t.pointColl=[],t.freehandCounter=0,t.cropObj=O.extend({},i.prevCropObj,{},!0),this.setCurrentObj(e.prevObj),t.objColl=e.prevObj.objColl,t.pointColl=e.prevObj.pointColl,t.freehandCounter=t.pointColl.length,t.transform.straighten=0,t.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"zoom",pen:"zoom",isPreventApply:null}}),r=t.currSelectionPoint?O.extend({},t.currSelectionPoint,{},!0):null,t.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:-t.transform.zoomFactor,zoomPoint:null,isResize:!0}}),t.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:e.prevObj.defaultZoom,zoomPoint:null,isResize:!0}}),t.currSelectionPoint=r,e.prevObj.zoomFactor&&t.setProperties({zoomSettings:{zoomFactor:e.prevObj.zoomFactor}},!0),t.notify("transform",{prop:"setPreviousZoomValue",onPropertyChange:!1,value:{previousZoomValue:t.zoomSettings.zoomFactor}})),t.isResize=!1,t.notify("transform",{prop:"setResizedImgAngle",onPropertyChange:!1,value:{angle:null}}),i=t.isCropTab,t.isCropTab=!1,this.updateCropSelObj(),t.cancelCropSelection=null,t.isCropTab=i),!0){case t.togglePen:this.cancelPen();break;case"text"===t.activeObj.shape:this.cancelText();break;case-1!==["rectangle","ellipse","line","arrow","path","image"].indexOf(t.activeObj.shape):this.cancelShape();break;case o:this.cancelSelection();break;default:t.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),this.upperContext.clearRect(0,0,t.upperCanvas.width,t.upperCanvas.height),t.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"cancel"}})}t.notify("selection",{prop:"setCurrentDrawingShape",onPropertyChange:!1,value:{value:""}}),t.upperCanvas.style.cursor=t.cursor="default",t.currObjType.isCustomCrop=!1,this.tempStrokeSettings={strokeColor:"#fff",fillColor:"",strokeWidth:null};t.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"main",isApplyBtn:null,isCropping:!1,isZooming:null}})},t.prototype.cancelPen=function(){var e=this.parent,t=(this.upperContext.clearRect(0,0,e.upperCanvas.width,e.upperCanvas.height),e.togglePen=!1,e.upperCanvas.style.cursor=e.cursor="default",O.extend([],e.pointColl,[],!0));e.pointColl={};for(var o=0;o<this.tempFreehandCounter;o++)e.pointColl[o]=t[o];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=O.extend([],this.tempObjColl,[],!0),e.pointColl=O.extend([],this.tempPointColl,[],!0),e.freehandCounter=e.pointColl.length,this.tempPointColl={},this.renderImage(),e.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"ok",isCancel:!0}})},t.prototype.cancelText=function(){var e,t,o=this.parent;o.notify("shape",{prop:"setTextSettings",onPropertyChange:!1,value:{textSettings:this.tempTextSettings,fontFamily:null,fontSize:null}}),o.notify("shape",{prop:"setStrokeSettings",value:{strokeSettings:this.tempStrokeSettings,strokeColor:null,fillColor:null,strokeWidth:null}}),!O.isNullOrUndefined(o.activeObj.currIndex)&&(o.notify("undo-redo",{prop:"getAppliedUndoRedoColl",value:{obj:t={appliedUndoRedoColl:[]}}}),e=t.appliedUndoRedoColl.length,t=t.appliedUndoRedoColl[e-1],this.prevActObj)&&t&&t.currentObjColl.length&&t.currentObjColl[t.currentObjColl.length-1].currIndex===this.prevActObj.currIndex?(o.activeObj=this.prevActObj,this.prevActObj=null):(o.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),this.upperContext.clearRect(0,0,o.upperCanvas.width,o.upperCanvas.height)),o.notify("toolbar",{prop:"destroy-qa-toolbar",onPropertyChange:!1}),this.tempTextSettings={text:"Enter Text",fontFamily:o.fontFamily.default,fontSize:null,fontRatio:null,bold:!1,italic:!1,underline:!1},o.objColl=O.extend([],this.tempObjColl,[],!0),o.pointColl=O.extend([],this.tempPointColl,[],!0),this.renderImage(),this.tempObjColl=[],o.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"ok",isCancel:!0}})},t.prototype.cancelShape=function(){var e=this.parent;if(e.notify("shape",{prop:"setStrokeSettings",value:{strokeSettings:this.tempStrokeSettings,strokeColor:null,fillColor:null,strokeWidth:null}}),O.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);else{for(var t={appliedUndoRedoColl:[]},o=(e.notify("undo-redo",{prop:"getAppliedUndoRedoColl",value:{obj:t}}),void 0),i=0,r=t.appliedUndoRedoColl.length;i<r;i++)for(var n=t.appliedUndoRedoColl[i].currentObjColl,a=0,s=n.length;a<s;a++)if(this.prevActObj&&this.prevActObj.currIndex&&n[a].currIndex===this.prevActObj.currIndex){o=n[0];break}this.prevActObj&&o?(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 l={undoRedoStep:null};e.notify("undo-redo",{prop:"getUndoRedoStep",value:{obj:l}}),t.appliedUndoRedoColl[l.undoRedoStep-1]?e.objColl=O.extend([],t.appliedUndoRedoColl[l.undoRedoStep-1].currentObjColl,[],!0):e.objColl=[]}this.renderImage()}e.currObjType.isDragging=!1,e.notify("toolbar",{prop:"destroy-qa-toolbar",onPropertyChange:!1}),e.objColl=O.extend([],this.tempObjColl,[],!0),e.pointColl=O.extend([],this.tempPointColl,[],!0),this.renderImage(),this.tempObjColl=[],e.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"ok",isCancel:!0}})},t.prototype.cancelSelection=function(){var e,t=this.parent;t.cancelCropSelection&&(e={value:t.tempStraighten},t.transform.straighten=e.value,t.straightenBaseImageCanvas(),t.notify("freehand-draw",{prop:"resetStraightenPoint"}),t.notify("draw",{prop:"render-image",value:{isMouseWheel:!1}}),t.notify("draw",{prop:"setStraightenActObj",value:{activeObj:t.activeObj}}),t.notify("crop",{prop:"resizeWrapper"}),this.updateCropSelObj(),this.tempStraightenDestPoints)&&JSON.stringify(this.tempStraightenDestPoints)!==JSON.stringify(this.straightenDestPoints)&&(this.straightenDestPoints=O.extend({},this.tempStraightenDestPoints,{},!0))},t.prototype.updateCropSelObj=function(){var e=this.parent;e.cancelCropSelection&&(e.cropObj=O.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=O.extend({},e.cancelCropSelection.previousCropObj.activeObj,!0),e.currSelectionPoint&&O.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}})},t.prototype.updateCropSelection=function(){var e=this.parent,t={currObj:{}},t=(e.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:t}}),t.currObj),o=(t.objColl=O.extend([],e.objColl,[],!0),t.pointColl=O.extend([],e.pointColl,[],!0),t.afterCropActions=O.extend([],e.afterCropActions,[],!0),{selPointColl:null});e.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:o}}),t.selPointColl=O.extend([],o.selPointColl,[],!0),e.cancelCropSelection={operation:"cropTransform",previousObj:t,currentObj:t,previousObjColl:t.objColl,currentObjColl:t.objColl,previousPointColl:t.pointColl,currentPointColl:t.pointColl,previousSelPointColl:t.selPointColl,currentSelPointColl:t.selPointColl,previousCropObj:O.extend({},e.cropObj,{},!0),currentCropObj:O.extend({},e.cropObj,{},!0),previousText:null,currentText:null,filter:null,isCircleCrop:e.isCircleCrop}},t.prototype.updateFlipPan=function(e){var t,o=this.parent;""!==o.transform.currFlipState&&(t=this.lowerContext.filter,o.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),o.notify("transform",{prop:"rotatedFlip",onPropertyChange:!1}),this.lowerContext.filter="none",o.notify("freehand-draw",{prop:"freehandRedraw",onPropertyChange:!1,value:{context:this.lowerContext,points:null}}),this.lowerContext.filter=t,this.upperContext.clearRect(0,0,o.upperCanvas.width,o.upperCanvas.height),e)&&this.drawObject("duplicate",e)},t.prototype.select=function(e,t,o,i,r){var n,a,s=this.parent;e=e.toLowerCase(),!s.disabled&&s.isImageLoaded&&(s.allowDownScale=!1,s.notify("filter",{prop:"getCurrentObj",onPropertyChange:!(a={currObj:{}}),value:{object:a}}),(a=a.currObj).objColl=O.extend([],s.objColl,[],!0),a.pointColl=O.extend([],s.pointColl,[],!0),a.afterCropActions=s.afterCropActions,s.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!(n={selPointColl:null}),value:{obj:n}}),a.selPointColl=O.extend([],n.selPointColl,[],!0),s.notify("crop",{prop:"setPreviousCropCurrentObj",onPropertyChange:!1,value:{obj:a}}),0<s.transform.zoomFactor&&s.activeObj.shape&&"crop"===s.activeObj.shape.split("-")[0]&&O.isNullOrUndefined(this.currSelPoint)&&(this.currSelPoint=O.extend({},s.activeObj,{},!0)),n=!1,((a=void 0)===(a=void 0!==s.activeObj.shape?s.activeObj.shape.split("-"):a)&&s.currObjType.isCustomCrop||void 0!==a&&"crop"===a[0])&&(n=!0),s.notify("filter",{prop:"getCurrentObj",onPropertyChange:!(a={currObj:{}}),value:{object:a}}),(a=a.currObj).objColl=O.extend([],s.objColl,[],!0),a.pointColl=O.extend([],s.pointColl,[],!0),a.afterCropActions=O.extend([],s.afterCropActions,[],!0),s.notify("shape",{prop:"redrawActObj",onPropertyChange:!1,value:{x:null,y:null,isMouseDown:null}}),s.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),s.notify("shape",{prop:"setKeyHistory",onPropertyChange:!1,value:{keyHistory:""}}),this.upperContext.clearRect(0,0,s.upperCanvas.width,s.upperCanvas.height),s.upperCanvas.style.display="block",s.currSelectionPoint||0!==s.transform.defaultZoomFactor||0!==s.transform.degree&&0!==s.panPoint.totalPannedInternalPoint.x&&0!==s.panPoint.totalPannedInternalPoint.y&&!n?(s.isCircleCrop=!1,0===s.transform.defaultZoomFactor||this.isResizeSelect||(a=s.isCropTab,s.isCropTab=!1,s.notify("transform",{prop:"resetZoom",onPropertyChange:!1}),s.isCropTab=a,this.resetPanPoints()),s.notify("freehand-draw",{prop:"updateFHDColl",onPropertyChange:!1}),s.isCropTab=!0,s.isCircleCrop=!1,this.isResizeSelect||s.notify("crop",{prop:"setCurrSelPoints",onPropertyChange:!1,value:{isSetDimension:!0}}),s.transform.zoomFactor=s.transform.cropZoomFactor,O.isNullOrUndefined(s.cropObj.activeObj.shape)&&(s.currObjType.shape="crop-"+e,this.drawNewSelection(e,t,o,i,r))):(this.isCropSelect?this.isCropSelect=!1:(s.notify("crop",{prop:"adjustStraightenForShapes",onPropertyChange:!1,value:{type:"reverse",isInitialRotated:!0}}),s.notify("freehand-draw",{prop:"updateFHDColl",onPropertyChange:!1}),this.renderImage()),"custom"===e&&(s.currObjType.shape=""),this.drawNewSelection(e,t,o,i,r)))},t.prototype.drawNewSelection=function(e,t,o,i,r){var n,a=this.parent,e="crop-"+e.toLowerCase();"crop-custom"==e?""!==a.currObjType.shape&&"crop-custom"!==a.currObjType.shape||(this.drawCustomSelection("crop-custom",t,o,i,r),this.adjToStraighten(),this.updateSelectionInsert(),a.isStraightening&&(this.straightenActObj=O.extend({},a.activeObj,{},!0),this.straightenInitZoom=a.transform.zoomFactor)):"crop-canvas"==e?(a.upperCanvas.style.display="block",a.notify("selection",{prop:"setDragCanvas",value:{bool:!0}})):(a.currObjType.isCustomCrop=!1,a.currObjType.shape=e,i&&r?n={startX:t,startY:o,endX:t+i,endY:o+r,width:i,height:r}:i&&"crop-circle"==e&&(n={startX:t,startY:o,endX:t+i,endY:o+i,width:i,height:i}),a.activeObj.shape=e,this.updateSelectionInsert(n))},t.prototype.updateSelectionInsert=function(e){var t=this.parent,o=t.activeObj.activePoint,i={shapeSettingsObj:{}},i=(t.notify("selection",{prop:"updatePrevShapeSettings",onPropertyChange:!1,value:{obj:i}}),{type:t.getSelectionType(i.shapeSettingsObj.type),startX:i.shapeSettingsObj.startX,startY:i.shapeSettingsObj.startY,width:i.shapeSettingsObj.width,height:i.shapeSettingsObj.height}),i={action:"insert",previousSelectionSettings:i,currentSelectionSettings:i};t.trigger("selectionChanging",i),t.notify("shape",{prop:"updSelChangeEventArgs",onPropertyChange:!1,value:{selectionSettings:i.currentSelectionSettings}}),"Custom"===i.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))},t.prototype.drawCustomSelection=function(e,t,o,i,r){var n,a,s,l,p,h,d,c,u,g,v,f=this.parent,C=f.activeObj.activePoint;f.currObjType.isCustomCrop=!0,this.upperContext.clearRect(0,0,f.upperCanvas.width,f.upperCanvas.height),f.currObjType.shape=f.activeObj.shape=e.toLowerCase(),O.isNullOrUndefined(t)||O.isNullOrUndefined(o)||O.isNullOrUndefined(i)||O.isNullOrUndefined(r)?i&&r?(p=(e=f.img).destLeft,h=e.destTop,d=e.destWidth,c=e.destHeight,C.width=i,C.height=r,C.startX=p+(d/2-i/2),C.startY=h+(c/2-r/2)):(O.isNullOrUndefined(f.transform.zoomFactor)||0===f.transform.zoomFactor?(g=(e=f.img).destLeft,n=e.destTop,u=e.destWidth,e=e.destHeight,a=f.lowerCanvas.width,s=f.lowerCanvas.height,l=C,0<=g&&0<=n?(l.startX=g,l.startY=n,l.endX=g+u,l.endY=n+e):0<=g?(l.startX=g,l.startY=7.5,l.endX=g+u,l.endY=s-15):0<=n?(l.startX=7.5,l.startY=n,l.endX=a-15,l.endY=n+e):(l.startX=7.5,l.startY=7.5,l.endX=a-15,l.endY=s-15)):(u=(g=f.img).destLeft,n=g.destTop,e=g.destWidth,a=g.destHeight,l=f.lowerCanvas.width,s=f.lowerCanvas.height,(g=C).startX=Math.max(0<u?u:7.5,u),g.startY=Math.max(0<n?n:7.5,n),g.endX=Math.min(u+e+15<l?u+e-15:l-15,u+e),g.endY=Math.min(n+a+15<s?n+a-15:s-15,n+a)),p=(l=f.img).destLeft,h=l.destTop,d=l.destWidth,c=l.destHeight,u=f.lowerCanvas.clientWidth,e=f.lowerCanvas.clientHeight,(g=C).startX=Math.max(g.startX,p),g.startY=Math.max(g.startY,h),g.endX=Math.min(g.endX,p+d),g.endY=Math.min(g.endY,h+c),0<f.transform.straighten?(this.imgCanvasPoints[0].x>g.startX&&(g.startX=this.imgCanvasPoints[0].x),this.imgCanvasPoints[0].y>g.startY&&(g.startY=this.imgCanvasPoints[0].y),this.imgCanvasPoints[2].x<g.endX&&(g.endX=this.imgCanvasPoints[2].x),this.imgCanvasPoints[2].y<g.endY&&(g.endY=this.imgCanvasPoints[2].x)):f.transform.straighten<0&&(this.imgCanvasPoints[3].x>g.startX&&(g.startX=this.imgCanvasPoints[3].x),this.imgCanvasPoints[3].y<g.startY&&(g.startY=this.imgCanvasPoints[3].y),this.imgCanvasPoints[1].x<g.endX&&(g.endX=this.imgCanvasPoints[1].x),this.imgCanvasPoints[1].y>g.endY)&&(g.endY=this.imgCanvasPoints[1].x),g.startX===p&&u<p+d&&(g.endX=u-15),g.startY===h&&e<h+c&&(g.endY=e-15),f.activeObj.activePoint.startX>f.activeObj.activePoint.endX&&(v=f.activeObj.activePoint.startX,f.activeObj.activePoint.startX=f.activeObj.activePoint.endX,f.activeObj.activePoint.endX=v),f.activeObj.activePoint.startY>f.activeObj.activePoint.endY&&(v=f.activeObj.activePoint.startY,f.activeObj.activePoint.startY=f.activeObj.activePoint.endY,f.activeObj.activePoint.endY=v),f.activeObj=this.updateWidthHeight(f.activeObj),this.updateActiveObject(C,f.activeObj),this.adjActObj()):(C.startX=t,C.startY=o,C.endX=t+i,C.endY=o+r,C.width=i,C.height=r),this.updateSelectionInsert()},t.prototype.adjToStraighten=function(){var e,t=this.parent;0!==t.transform.straighten&&t.isStraightening&&((e=t.activeObj.activePoint).startX+=7.5,e.startY+=7.5,e.endX-=7.5,e.endY-=7.5,t.activeObj=this.updateWidthHeight(t.activeObj))},t.prototype.adjActObj=function(){var e=this.parent;if(0!==e.transform.straighten)for(var t=e.activeObj.activePoint,o=O.extend({},t,{},!0),i=0;;){i++;var r={isIntersect:null,arr:null};if(e.notify("draw",{prop:"updateImgCanvasPoints",onPropertyChange:!1}),e.notify("draw",{prop:"isLinesIntersect",onPropertyChange:!1,value:{obj:r}}),r.arr[0]||r.arr[1]||r.arr[2]||r.arr[3]||100===i){t=O.extend({},o,{},!0);break}o=O.extend({},t,{},!0),t.startX-=5,t.endX+=5,t.width=t.endX-t.startX,this.updateActiveObject(t,e.activeObj)}},t.prototype.callUpdateCurrTransState=function(){var e=this.parent,t=O.extend([],e.objColl,[],!0),o=O.extend({},e.activeObj,{},!0),i=(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&&0<e.rotateFlipColl.length&&(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,this.lowerContext.filter),t=(0===e.transform.degree&&e.notify("transform",{prop:"setDestPointsForFlipState",onPropertyChange:!1}),this.drawImage(),this.updateCurrTransState("reverse"),0===e.transform.degree&&0<e.rotateFlipColl.length&&(e.img.destLeft+=e.panPoint.totalPannedPoint.x,e.img.destTop+=e.panPoint.totalPannedPoint.y),this.isRotateZoom=!1,e.objColl=t,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=t,this.lowerContext.filter=i,e.activeObj=o},t.prototype.resetPanPoints=function(){this.parent.panPoint.totalPannedPoint={x:0,y:0},this.parent.panPoint.totalPannedClientPoint={x:0,y:0},this.parent.panPoint.totalPannedInternalPoint={x:0,y:0}},t.prototype.setClientTransDim=function(e){var t,o=this.parent;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,t=o.img.destWidth,o.img.destWidth=o.img.destHeight,o.img.destHeight=t):O.isNullOrUndefined(e)&&(o.img.destLeft=(o.lowerCanvas.clientWidth-o.img.destWidth)/2,o.img.destTop=(o.lowerCanvas.clientHeight-o.img.destHeight+1)/2)},t.prototype.redrawImgWithObj=function(){var e,t=this.parent,o={canvasFilter:t.canvasFilter};this.lowerContext.filter=o.canvasFilter,0!==t.rotateFlipColl.length?(o=O.extend({},t.panPoint.totalPannedInternalPoint,{},!0),e={startX:t.img.destLeft,startY:t.img.destTop,width:t.img.destWidth,height:t.img.destHeight},this.callUpdateCurrTransState(),t.panPoint.totalPannedInternalPoint=o,t.img.destLeft=e.startX,t.img.destTop=e.startY,t.img.destWidth=e.width,t.img.destHeight=e.height):this.callUpdateCurrTransState(),t.isCircleCrop&&t.notify("crop",{prop:"cropCircle",onPropertyChange:!1,value:{context:this.lowerContext,isSave:null,isFlip:null}})},t.prototype.setCurrentObj=function(e,t){var o,i,r=this.parent,n=!!e,a=(n||(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,!n||e.activeObj.shape&&"crop"===e.activeObj.shape.split("-")[0]?r.transform.zoomFactor=e.cropZoom:r.transform.zoomFactor=e.defaultZoom,r.setProperties({zoomSettings:{zoomFactor:e.zoomFactor}},!0),r.notify("transform",{prop:"setPreviousZoomValue",onPropertyChange:!1,value:{previousZoomValue:e.previousZoomValue}}),r.panPoint.totalPannedPoint=O.extend({},e.totalPannedPoint,{},!0),r.panPoint.totalPannedClientPoint=O.extend({},e.totalPannedClientPoint,{},!0),r.panPoint.totalPannedInternalPoint=O.extend({},e.totalPannedInternalPoint,{},!0),O.extend({},e.tempFlipPanPoint,{},!0)),a=(r.notify("crop",{prop:"setTempFlipPanPoint",onPropertyChange:!1,value:{point:a}}),r.rotateFlipColl=O.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&&!t||(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.isCircleCrop),t=(O.isNullOrUndefined(r.currSelectionPoint)?o=null:(o=O.extend({},r.currSelectionPoint,{},!0),r.currSelectionPoint=null),r.isCircleCrop=!1,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=O.extend({},e.totalPannedClientPoint,{},!0),r.panPoint.totalPannedInternalPoint=O.extend({},e.totalPannedInternalPoint,{},!0)),r.activeObj=O.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),O.extend({},e.activeObj,{},!0)),s=!1,l=(0<r.afterCropActions.length&&(i={collection:r.afterCropActions},r.notify("shape",{prop:"alignRotateFlipColl",onPropertyChange:!1,value:{collection:r.afterCropActions,isRotateFlipCollection:null,obj:i}}),r.afterCropActions=i.collection),O.extend([],r.afterCropActions,[],!0));if(!n&&0<l.length){for(var s=!0,p=0,h=l.length;p<h;p++)"horizontalflip"!==l[p]&&"verticalflip"!==l[p]||(r.activeObj=O.extend({},o,{},!0),this.rotatedFlipCropSel=!0),r.notify("transform",{prop:"updateTransform",onPropertyChange:!1,value:{text:l[p]}});t=O.extend({},r.activeObj,{},!0),this.resetPanPoints(),r.activeObj=t,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=l,this.isCancelAction||s||(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=t,r.isCircleCrop=a,(O.isNullOrUndefined(o)||(r.currSelectionPoint=O.extend({},o,{},!0),r.currSelectionPoint&&O.isNullOrUndefined(r.currSelectionPoint.shape)))&&(r.currSelectionPoint=null)},t.prototype.drawCropSelectionImage=function(e,t){var o,i=this.parent,r=this.lowerContext.filter,t=(i.clearContext(this.lowerContext),i.clearContext(this.upperContext),this.lowerContext.setTransform(1,0,0,1,0,0),t?this.updateCurrTransState("initial"):this.setTransformColl(this.lowerContext,"initial"),i.notify("transform",{prop:"setDestPointsForFlipState",onPropertyChange:!1}),this.drawImage(),t?this.updateCurrTransState("reverse"):this.setTransformColl(this.lowerContext,"reverse"),i.img.destLeft=i.cropObj.destPoints.startX,i.img.destTop=i.cropObj.destPoints.startY,O.extend({},e.activeObj,{},!0));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&&(o={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=o.startX,i.img.destTop=o.startY,i.img.destWidth=o.width,i.img.destHeight=o.height),i.activeObj=t,this.lowerContext.filter=r},t.prototype.performPointZoom=function(e,t,o,i,r){var n=this.parent,a=n.img,s=a.destLeft,l=a.destTop,s=(e-s)/a.destWidth,l=(t-l)/a.destHeight,a=n.isUndoRedo,r=(n.isUndoRedo=!0,n.setProperties({zoomSettings:{zoomPoint:{x:e,y:t}}},!0),r||("zoomIn"===o?.1:-.1));n.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:r,zoomPoint:null,isResize:i}}),n.isUndoRedo=a,this.panToPoint(e,t,s,l)},t.prototype.panToPoint=function(e,t,o,i){var r,n,a,s,l,p,h,d,c=this.parent;0<c.transform.zoomFactor&&(r=c.img.destLeft,n=c.img.destTop,a=O.extend({},c.activeObj,{},!0),0===c.transform.degree?(c.img.destLeft=e-o*c.img.destWidth,c.img.destTop=t-i*c.img.destHeight,this.drawZoomPanImage(c.img.destLeft-r,c.img.destTop-n)):(s=c.isCropTab,c.isCropTab=!0,l=O.extend([],c.objColl,[],!0),p=O.extend([],c.pointColl,[],!0),c.notify("freehand-draw",{prop:"getStraightenPoint",onPropertyChange:!(h={straightenPoint:null}),value:{obj:h}}),c.objColl=[],c.pointColl=[],c.freehandCounter=0,c.notify("freehand-draw",{prop:"setStraightenPoint",onPropertyChange:!1,value:{x:null,y:null,ratioX:null,ratioY:null}}),c.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!(d={selPointColl:null}),value:{obj:d}}),d=d.selPointColl,c.notify("freehand-draw",{prop:"setSelPointColl",onPropertyChange:!1,value:{obj:{selPointColl:[]}}}),c.panPoint.currentPannedPoint={x:e-o*c.img.destWidth-r,y:t-i*c.img.destHeight-n},c.notify("transform",{prop:"rotatePan",onPropertyChange:!1,value:{isCropSelection:null,isDefaultZoom:null}}),c.isCropTab=s,c.objColl=l,c.pointColl=p,c.freehandCounter=c.pointColl.length,h.straightenPoint.x&&h.straightenPoint.y&&c.notify("freehand-draw",{prop:"setStraightenPoint",onPropertyChange:!1,value:{x:h.straightenPoint.x,y:h.straightenPoint.y,ratioX:h.straightenPoint.ratioX,ratioY:h.straightenPoint.ratioY}}),c.notify("freehand-draw",{prop:"setSelPointColl",onPropertyChange:!1,value:{obj:{selPointColl:d}}}),c.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"pan",pen:"pan",x:c.panPoint.currentPannedPoint.x,y:c.panPoint.currentPannedPoint.y,panRegion:""}})),this.adjustPanning(a),c.activeObj=a,0!==c.activeObj.activePoint.width)&&0!==c.activeObj.activePoint.height&&this.drawObject("duplicate",null,null,null,!0)},t.prototype.adjustPanning=function(e){var t,o,i,r,n,a=this.parent,e=e.activePoint,s=e.startX,l=e.startY,p=e.width,e=e.height;0!==p&&0!==e&&(t=(n=a.img).destLeft,o=n.destTop,r=n.destWidth,n=n.destHeight,i={x:0,y:0},s<t?i.x=t-s:t+r<s+p&&(i.x=t+r-(s+p)),l<o?i.y=o-l:o+n<l+e&&(i.y=o+n-(l+e)),0===a.transform.degree?(a.img.destLeft-=i.x,a.img.destTop-=i.y,this.drawZoomPanImage(a.img.destLeft-t,a.img.destTop-o)):(r=a.isCropTab,a.isCropTab=!0,s=O.extend([],a.objColl,[],!0),p=O.extend([],a.pointColl,[],!0),a.objColl=[],a.pointColl=[],a.freehandCounter=0,a.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!(n={selPointColl:null}),value:{obj:n}}),l=n.selPointColl,a.notify("freehand-draw",{prop:"setSelPointColl",onPropertyChange:!1,value:{obj:{selPointColl:[]}}}),a.img.destLeft-=i.x,a.img.destTop-=i.y,a.panPoint.currentPannedPoint={x:a.img.destLeft-t,y:a.img.destTop-o},a.notify("transform",{prop:"rotatePan",onPropertyChange:!1,value:{isCropSelection:null,isDefaultZoom:null}}),a.isCropTab=r,a.objColl=s,a.pointColl=p,a.freehandCounter=a.pointColl.length,a.notify("freehand-draw",{prop:"setSelPointColl",onPropertyChange:!1,value:{obj:{selPointColl:l}}}),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:""}})))},t.prototype.panToSel=function(){var e=this.parent,t=O.extend({},e.activeObj,{},!0),o=t.activePoint,i=o.startX,r=o.startY,n=o.width,o=o.height,a={straightenPoint:null};if(e.notify("freehand-draw",{prop:"getStraightenPoint",onPropertyChange:!1,value:{obj:a}}),a.straightenPoint.x&&a.straightenPoint.y){var i=i+n/2-a.straightenPoint.x,n=r+o/2-a.straightenPoint.y,r=(0===e.transform.degree?(e.img.destLeft+=i,e.img.destTop+=n,e.notify("transform",{prop:"drawPannImage",value:{point:{x:i,y:n}}})):(e.panPoint.currentPannedPoint={x:i,y:n},e.notify("transform",{prop:"drawPannedImage",value:{xDiff:i,yDiff:n}}),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:t}}),e.img),s=r.destLeft,l=r.destTop,p=r.destWidth,h=r.destHeight,o=this.imgCanvasPoints,d=(o.forEach(function(e){e.x=e.ratioX*p+s,e.y=e.ratioY*h+l}),this.imgCanvasPoints=o,0);for(3!==e.transform.straighten||this.preventStraightening||(this.preventStraightening=!0,a=e.prevStraightenedDegree,e.prevStraightenedDegree=e.transform.straighten,e.setStraighten(0),e.setStraighten(3),e.prevStraightenedDegree=a,this.preventStraightening=!1);this.isLinesIntersect()&&0!==e.transform.straighten&&360!==e.transform.straighten&&d<100;)d++,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()}},t.prototype.drawZoomPanImage=function(e,t){var o=this.parent,i=(o.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"pan",pen:"pan",x:e,y:t,panRegion:""}}),this.renderImage(!0),{width:0,height:0});o.notify("transform",{prop:"calcMaxDimension",onPropertyChange:!1,value:{width:o.img.srcWidth,height:o.img.srcHeight,obj:i,isImgShape:null}});i.width+=i.width*o.transform.zoomFactor,i.height+=i.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}}})},t.prototype.openNewImage=function(){var t=this,e=this.parent,o=e.element.id,i=e.inMemoryCanvas.getContext("2d"),r=(u.showSpinner(e.element),e.element.style.opacity="0.5",document.querySelector("#"+o+"_currPos")),r=(r&&(r.style.display="none"),{defToolbarItems:null});e.notify("toolbar",{prop:"getDefToolbarItems",value:{obj:r}}),0===r.defToolbarItems.length&&O.isNullOrUndefined(document.getElementById(o+"_toolbar"))&&e.element.querySelector("#"+o+"_toolbarArea")&&(r=e.element.querySelector("#"+o+"_toolbarArea").clientHeight,e.notify("toolbar",{prop:"setToolbarHeight",value:{height:r}})),e.reset(),e.update(),e.transform.degree=0,e.transform.zoomFactor=0,e.isImageLoaded=!1,e.currSelectionPoint=null,"string"==typeof this.openURL?(1<(r=this.openURL.split(".")).length?(r=r[r.length-2].split("/"),this.fileName=r[r.length-1]):this.fileName="ImageEditor",this.fileType=this.getFileExtensionFromURL(this.openURL),this.fileType&&(this.fileType=e.toPascalCase(this.fileType),"jpg"!==(r=this.fileType.toLowerCase())&&"jpeg"!==r||(this.fileType="Jpeg",r="jpeg"),"jpeg"!==r)&&"png"!==r&&"svg"!==r&&(this.fileType=null),this.imageOnLoad(this.openURL),"string"==typeof this.openURL&&-1!==this.openURL.indexOf("localhost")||this.getImageSizeFromURL(this.openURL.toString(),function(e){null!==e&&t.parent.notify("toolbar",{prop:"setInitialSize",value:{value:+e}})})):(this.fileName="ImageEditor",this.fileType=null,e.lowerCanvas=document.querySelector("#"+o+"_lowerCanvas"),e.upperCanvas=document.querySelector("#"+o+"_upperCanvas"),this.lowerContext=e.lowerCanvas.getContext("2d"),this.upperContext=e.upperCanvas.getContext("2d"),e.clearContext(this.lowerContext),e.clearContext(this.upperContext),e.clearContext(i),e.inMemoryCanvas.width=this.openURL.width,e.inMemoryCanvas.height=this.openURL.height,i.putImageData(this.openURL,0,0),e.baseImg.src=e.inMemoryCanvas.toDataURL())},t.prototype.getImageSizeFromURL=function(o,i){return R(this,void 0,void 0,function(){var t;return E(this,function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),[4,fetch(o,{method:"HEAD"})];case 1:return t=e.sent(),t=parseInt(t.headers.get("content-length")||"0",10),i(t),[3,3];case 2:return t=e.sent(),console.log(t.message),[3,3];case 3:return[2]}})})},t.prototype.dlgBtnClick=function(){this.parent.export(),this.applyDialogOption()},t.prototype.dlgCloseBtnClick=function(){this.applyDialogOption()},t.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()),O.getComponent(document.getElementById(e.element.id+"_dialog"),"dialog").destroy(),this.isImageEdited=!1},t.prototype.showDialogPopup=function(){var e=this.parent,t={key:"ConfirmDialogHeader"},o=(e.notify("toolbar",{prop:"getLocaleText",onPropertyChange:!1,value:{obj:t}}),{key:"ConfirmDialogContent"}),i=(e.notify("toolbar",{prop:"getLocaleText",onPropertyChange:!1,value:{obj:o}}),{key:"Yes"}),r=(e.notify("toolbar",{prop:"getLocaleText",onPropertyChange:!1,value:{obj:i}}),{key:"No"});e.notify("toolbar",{prop:"getLocaleText",onPropertyChange:!1,value:{obj:r}}),e.element.querySelector("#"+e.element.id+"_dialog").style.display="block",new u.Dialog({header:t.value,closeOnEscape:!0,content:"<span>"+o.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:r.value,iconCss:"e-icons e-close"}},{click:this.dlgBtnClick.bind(this),buttonModel:{content:i.value,isPrimary:!0,iconCss:"e-icons e-check"}}]}).appendTo("#"+e.element.id+"_dialog")},t.prototype.restoreOldImage=function(){this.parent.isImageLoaded&&this.reset(),this.openNewImage()},t.prototype.open=function(e){document.getElementById(this.parent.element.id+"_dropArea").style.display="none",this.parent.disabled||(this.openURL=e,this.restoreOldImage())},t.prototype.getInitialLoaded=function(e){e.isInitialLoaded=this.isInitialLoading},t.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},t.prototype.fileSelect=function(e,t){var o,i,r,n=this.parent;document.getElementById(n.element.id+"_dropArea").style.display="none",n.disabled||(r=o=void 0,t=void(t.target?r=o=t.target.files[0]:o=r=t.filesData[0].rawFile),(t=r.name?(i=r.name.split("."))[i.length-1].toLowerCase():t)&&-1===["jpg","jpeg","png","svg"].indexOf(t)?this.errorLoading():(u.showSpinner(n.element),n.element.style.opacity="0.5",this.inputElem=e,(t=r.name&&r.name.split(".")[1])?(i=n.toPascalCase(t),this.fileType="JPG"===i||"Jpg"===i?"Jpeg":i):this.fileType=null,r=window.URL.createObjectURL(o),this.openURL=r,n.isImageLoaded&&!n.isChangesSaved&&(this.isImageEdited||0<n.pointColl.length||0<n.objColl.length)?(this.isFileChanged=!0,this.showDialogPopup()):this.checkToolbarTemplate(e,r)))},t.prototype.checkToolbarTemplate=function(e,t){var o=this.parent;O.isNullOrUndefined(o.toolbarTemplate)&&(o.reset(),o.update()),this.fileName=e.value.split("\\")[e.value.split("\\").length-1],this.fileName=this.fileName.split(".")[0],this.imageOnLoad(t.toString()),e.value=""},t.prototype.moveToSelectionRange=function(e,t){var o=this.parent;if(o.activeObj.shape){for(var i=!1,r=0,n=o.rotateFlipColl.length;r<n;r++){var a=o.rotateFlipColl[r];if(90===a||-90===a){i=!0;break}}if(i&&0!==o.transform.degree){var s=o.transform.zoomFactor,l=(o.objColl.push(o.activeObj),o.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),o.objColl[o.objColl.length-1]);if("rotateleft"===e||"rotateright"===e)if(o.transform.degree%90==0&&o.transform.degree%180!=0)if(l.activePoint.width<t.activePoint.height)for(r=2;r<o.zoomSettings.maxZoomFactor;r++){if(l.activePoint.width>=t.activePoint.height||this.isSelectionBiggerThanCanvas(l)||this.isSelectionOutsideCanvas(l)){O.isNullOrUndefined(s)||o.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:-.1,zoomPoint:null},isResize:null});break}s+=.1,o.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:s,zoomPoint:null},isResize:null})}else for(r=2;r<o.zoomSettings.maxZoomFactor;r++){if(l.activePoint.width>=t.activePoint.height||this.isSelectionBiggerThanCanvas(l)||this.isSelectionOutsideCanvas(l)){O.isNullOrUndefined(s)||o.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:.1,zoomPoint:null,isResize:null}});break}s-=.1,o.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:s,zoomPoint:null},isResize:null})}else if(l.activePoint.height<t.activePoint.width)for(r=2;r<o.zoomSettings.maxZoomFactor;r++){if(l.activePoint.height>=t.activePoint.width||this.isSelectionBiggerThanCanvas(l)||this.isSelectionOutsideCanvas(l)){O.isNullOrUndefined(s)||o.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:-.1,zoomPoint:null},isResize:null});break}s+=.1,o.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:s,zoomPoint:null},isResize:null})}else for(r=2;r<o.zoomSettings.maxZoomFactor;r++){if(l.activePoint.height>=t.activePoint.width||this.isSelectionBiggerThanCanvas(l)||this.isSelectionOutsideCanvas(l)){O.isNullOrUndefined(s)||o.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:.1,zoomPoint:null},isResize:null});break}s-=.1,o.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:s,zoomPoint:null},isResize:null})}var e=o.lowerCanvas.clientWidth/2-(l.activePoint.startX+l.activePoint.width/2),p=(o.lowerCanvas.clientHeight+1)/2-(l.activePoint.startY+l.activePoint.height/2);O.isNullOrUndefined(o.activeObj.shape)&&(o.activeObj=O.extend({},t,{},!0)),0===o.transform.degree?(o.img.destLeft+=e,o.img.destTop+=p,o.notify("transform",{prop:"drawPannImage",value:{point:{x:e,y:p}}})):(o.panPoint.currentPannedPoint={x:e,y:p},o.notify("transform",{prop:"drawPannedImage",value:{xDiff:e,yDiff:p}}),o.panPoint.currentPannedPoint={x:0,y:0}),o.notify("transform",{prop:"setTempPanMove",onPropertyChange:!1,value:{point:null}}),o.activeObj=O.extend({},o.objColl[o.objColl.length-1]),o.objColl.pop(),o.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate",obj:o.activeObj}})}}},t.prototype.isSelectionBiggerThanCanvas=function(e){var t=!1,o=this.parent,e=e.activePoint,i=e.startX,r=e.startY,n=e.endX,e=e.endY,o=o.img,a=o.destLeft,s=o.destTop,l=o.destWidth,o=o.destHeight;return t=i<=a||r<=s||a+l<=n||s+o<=e?!0:t},t.prototype.isSelectionOutsideCanvas=function(e){var t=!1,o=this.parent;return t=e.activePoint.height<o.lowerCanvas.height-o.toolbarHeight||e.activePoint.width<o.lowerCanvas.width?!0:t},t.prototype.downScaleImgCanvas=function(e,t,o,i){var r=this.parent,n=t?r.activeObj.imageCanvas:r.baseImgCanvas,a=t?r.activeObj.imageElement:r.baseImg,s=t?r.activeObj.activePoint.width:r.img.destWidth,l=t?r.activeObj.activePoint.height:r.img.destHeight,p={width:0,height:0};r.transform.degree%90==0&&r.transform.degree%180!=0?r.notify("transform",{prop:"calcMaxDimension",onPropertyChange:!1,value:{width:a.height,height:a.width,obj:p,isImgShape:t}}):r.notify("transform",{prop:"calcMaxDimension",onPropertyChange:!1,value:{width:a.width,height:a.height,obj:p,isImgShape:t}}),t||r.allowDownScale&&!r.isCropTab&&!r.isCropToolbar&&0!==a.width&&0!==a.height&&s<.75*p.width&&l<.75*p.height?((p=r.createElement("canvas",{id:r.element.id+"_downScaleCanvas",attrs:{name:"canvasImage"}})).width=t?a.width:r.img.srcWidth,p.height=t?a.height:r.img.srcHeight,t?p.getContext("2d").drawImage(a,0,0,p.width,p.height):p.getContext("2d").drawImage(n,r.img.srcLeft,r.img.srcTop,r.img.srcWidth,r.img.srcHeight,0,0,p.width,p.height),(t||this.isDownScale)&&this.downScale(p,s,l,t),t?(e.canvas.width=p.width,e.canvas.height=p.height,o&&i?(e.translate(r.activeObj.imageCanvas.width,0),e.scale(-1,1),e.translate(0,r.activeObj.imageCanvas.height),e.scale(1,-1)):o?(O.isNullOrUndefined(r.activeObj.isHorImageFlip)||!r.activeObj.isHorImageFlip?(r.activeObj.isHorImageFlip=!0,e.translate(r.activeObj.imageCanvas.width,0),e.scale(-1,1)):r.activeObj.isHorImageFlip&&(r.activeObj.isHorImageFlip=!1),r.activeObj.isVerImageFlip&&(e.translate(0,r.activeObj.imageCanvas.height),e.scale(1,-1))):i&&(O.isNullOrUndefined(r.activeObj.isVerImageFlip)||!r.activeObj.isVerImageFlip?(r.activeObj.isVerImageFlip=!0,e.translate(0,r.activeObj.imageCanvas.height),e.scale(1,-1)):r.activeObj.isVerImageFlip&&(r.activeObj.isVerImageFlip=!1),r.activeObj.isHorImageFlip)&&(e.translate(r.activeObj.imageCanvas.width,0),e.scale(-1,1)),e.drawImage(p,0,0),e.setTransform(1,0,0,1,0,0)):r.isFinetuning?(e.save(),e.setTransform(1,0,0,1,0,0),e.drawImage(r.inMemoryCanvas,0,0),e.restore()):e.drawImage(p,0,0,p.width,p.height,r.img.destLeft,r.img.destTop,p.width,p.height)):!O.isNullOrUndefined(t)&&t||0===r.baseImgCanvas.width||0===r.baseImgCanvas.height||e.drawImage(r.baseImgCanvas,r.img.srcLeft,r.img.srcTop,r.img.srcWidth,r.img.srcHeight,r.img.destLeft,r.img.destTop,r.img.destWidth,r.img.destHeight)},t.prototype.downScale=function(e,t,o,i){var r=this.parent;if(!i||!r.isStraightening){for(var n=e.width,a=e.height,s=n/(t=Math.round(t)),l=a/(o=Math.round(o)),p=Math.ceil(s/2),h=Math.ceil(l/2),d=e.getContext("2d"),a=d.getImageData(0,0,n,a),c=d.createImageData(t,o),u=a.data,g=c.data,v=0;v<o;v++)for(var f=0;f<t;f++){for(var C=4*(f+v*t),b=0,m=0,y=0,P=0,j=0,x=0,w=(v+.5)*l,O=Math.floor(v*l),S=Math.ceil((v+1)*l),T=O;T<S;T++)for(var k=Math.abs(w-(T+.5))/h,F=(f+.5)*s,I=k*k,k=Math.floor(f*s),A=Math.ceil((f+1)*s),z=k;z<A;z++){var X,D=Math.abs(F-(z+.5))/p,D=Math.sqrt(I+D*D);1<=D||(x+=(D=2*D*D*D-3*D*D+1)*u[3+(X=4*(z+T*n))],m+=D,y+=(D=D*u[3+X]/250)*u[X],P+=D*u[1+X],j+=D*u[2+X],b+=D)}g[C]=y/b,g[1+C]=P/b,g[2+C]=j/b,g[3+C]=x/m}e.width=(i?r.activeObj.activePoint:r.lowerCanvas).width,e.height=(i?r.activeObj.activePoint:r.lowerCanvas).height,d.putImageData(c,0,0)}},t.prototype.drawImgToCtx=function(e,t){var o=this.parent;e.canvas.id!==o.element.id+"_tempCanvas"&&e!==this.upperContext&&O.isNullOrUndefined(t)&&this.downScaleImgCanvas(e,null,null,null)},t.prototype.getFrameColor=function(e,t,o){this.parent.frameObj.color;return e.gradientColor?((t=t.createLinearGradient(o.startX,o.startY,o.startX+o.width,o.startY+o.height)).addColorStop(0,e.color),t.addColorStop(1,e.gradientColor),t):e.color},t.prototype.applyFrame=function(e,t,o){var i,r,n,a,s=this.parent,l=(s.frameObj.type=t,{width:1,height:1}),p={startX:s.img.destLeft-e.lineWidth,startY:s.img.destTop-e.lineWidth,width:s.img.destWidth+2*e.lineWidth,height:s.img.destHeight+2*e.lineWidth},h={type:s.frameObj.type,color:s.frameObj.color,size:s.frameObj.size,inset:s.frameObj.inset,offset:s.frameObj.offset/2,radius:s.frameObj.radius,amount:s.frameObj.amount,border:s.frameObj.border,gradientColor:s.frameObj.gradientColor},d=s.transform.zoomFactor,c=(e.canvas.id===s.element.id+"_tempCanvas"?(r=e.canvas.width,n=e.canvas.height,s.notify("crop",{prop:"calcRatio",onPropertyChange:!(a={width:0,height:0}),value:{obj:a,dimension:{width:r,height:n}}}),h.size*=((l=a).width+l.height)/2,h.inset*=(l.width+l.height)/2,h.offset*=(l.width+l.height)/2,h.radius*=(l.width+l.height)/2,p={startX:0,startY:0,width:e.canvas.width,height:e.canvas.height},s.notify("export",{prop:"updateSaveContext",onPropertyChange:!1,value:{context:e}})):e===this.upperContext&&s.activeObj.shape?p={startX:s.activeObj.activePoint.startX-e.lineWidth,startY:s.activeObj.activePoint.startY-e.lineWidth,width:s.activeObj.activePoint.width+2*e.lineWidth,height:s.activeObj.activePoint.height+2*e.lineWidth}:O.isNullOrUndefined(o)&&e.clearRect(0,0,e.canvas.width,e.canvas.height),(l.width+l.height)/2*40),u=(l.width+l.height)/2*50;if(e!==this.upperContext&&(h.size+=h.size*d,h.inset+=h.inset*d,h.offset+=h.offset*d,h.radius+=h.radius*d,c+=c*d,u+=u*d),e!==this.upperContext||!s.activeObj.shape||!("mat"===t&&(p.width-2*h.size<0||p.height-2*h.size<0)||"bevel"===t&&(p.width-2*h.size<40||p.height-2*h.size<40)||"inset"===t&&(p.startX+p.width-h.offset-(p.startX+h.offset)<0||p.startY+p.height-h.offset-(p.startY+h.offset)<0)||"hook"===t&&(p.width-2*h.size<50||p.height-2*h.size<50))){var g={bevelFilter:e.filter},v=e.filter;if(s.currSelectionPoint&&"crop-circle"===s.currSelectionPoint.shape||s.isCircleCrop||e===this.lowerContext&&s.isCropTab)this.drawImgToCtx(e,o);else{switch(t){case"none":this.drawImgToCtx(e,o);break;case"mat":for(this.drawImgToCtx(e,o);(p.width-2*h.size<0||p.height-2*h.size<0)&&0<h.size;)h.size-=20;e.filter="none",e.fillStyle=this.getFrameColor(h,e,p),e.beginPath(),e.rect(p.startX,p.startY,p.width,p.height),e.rect(p.startX+h.size,p.startY+h.size,p.width-2*h.size,p.height-2*h.size),e.fill("evenodd"),e.closePath();break;case"bevel":for(e.filter="none",e.fillStyle=this.getFrameColor(h,e,p),e.beginPath(),e.fillRect(p.startX,p.startY,p.width,p.height),e.closePath(),p.startX+=h.size,p.startY+=h.size,p.width-=2*h.size,p.height-=2*h.size;(p.width-2*h.size<40||p.height-2*h.size<40)&&0<h.size;)p.startX-=h.size,p.startY-=h.size,p.width+=2*h.size,p.height+=2*h.size,h.size-=20,p.startX+=h.size,p.startY+=h.size,p.width-=2*h.size,p.height-=2*h.size;e.fillStyle=this.getFrameColor(h,e,p),e.save(),e.beginPath(),e.moveTo(p.startX+c,p.startY),e.lineTo(p.startX+p.width-c,p.startY),e.quadraticCurveTo(p.startX+p.width,p.startY,p.startX+p.width,p.startY+c),e.lineTo(p.startX+p.width,p.startY+p.height-c),e.quadraticCurveTo(p.startX+p.width,p.startY+p.height,p.startX+p.width-c,p.startY+p.height),e.lineTo(p.startX+c,p.startY+p.height),e.quadraticCurveTo(p.startX,p.startY+p.height,p.startX,p.startY+p.height-c),e.lineTo(p.startX,p.startY+c),e.quadraticCurveTo(p.startX,p.startY,p.startX+c,p.startY),e.closePath(),e.clip(),e.filter="none"===v?s.canvasFilter:v,e.canvas.id===s.element.id+"_tempCanvas"?(o=null,e.filter="none",e.drawImage(s.inMemoryCanvas,0,0),e.filter="none"===v?s.canvasFilter:v):(e.clearRect(0,0,e.canvas.width,e.canvas.height),o?(o=null,0!==s.transform.zoomFactor&&(this.isRotateZoom=!0),s.notify("filter",{prop:"getBevelFilter",onPropertyChange:!1,value:{obj:g}}),e.filter=g.bevelFilter,this.updateCurrTransState("initial"),this.drawImgToCtx(e,o),this.updateCurrTransState("reverse"),this.isRotateZoom=!1,s.frameObj.type="none",e.filter="none",s.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:e,shape:"iterate",pen:"iterate",isPreventApply:null}}),s.frameObj.type="bevel",e.filter="none"===v?s.canvasFilter:v):(s.notify("filter",{prop:"getBevelFilter",onPropertyChange:!1,value:{obj:g}}),e.filter=g.bevelFilter,this.drawImgToCtx(e,o))),e.restore();break;case"line":this.drawImgToCtx(e,o),i=e.lineWidth,e.lineWidth=h.size/10;for(var f=0;f<s.frameObj.amount;f++){0<f&&(p.startX+=h.offset,p.startY+=h.offset,p.width-=2*h.offset,p.height-=2*h.offset);var C=p.startY+p.height-h.inset-h.radius,b=p.startY+h.inset+h.radius,m=p.startX+p.width-h.inset-h.radius,y=p.startX+h.inset+h.radius,P=p.startX+h.inset+h.radius,j=p.startX+p.width-h.inset-h.radius,x=p.startY+h.inset+h.radius,w=p.startY+p.height-h.inset-h.radius;b<=C&&y<=m&&P<=j&&x<=w&&(e.filter="none",e.strokeStyle=this.getFrameColor(h,e,p),"dashed"===h.border?e.setLineDash([2.5*e.lineWidth,1.5*e.lineWidth]):"dotted"===h.border&&e.setLineDash([e.lineWidth,e.lineWidth]),e.beginPath(),e.moveTo(p.startX+h.inset+h.radius,p.startY+h.inset),e.lineTo(p.startX+p.width-h.inset-h.radius,p.startY+h.inset),e.arcTo(p.startX+p.width-h.inset,p.startY+h.inset,p.startX+p.width-h.inset,p.startY+h.inset+h.radius,h.radius),e.lineTo(p.startX+p.width-h.inset,p.startY+p.height-h.inset-h.radius),e.arcTo(p.startX+p.width-h.inset,p.startY+p.height-h.inset,p.startX+p.width-h.inset-h.radius,p.startY+p.height-h.inset,h.radius),e.lineTo(p.startX+h.inset+h.radius,p.startY+p.height-h.inset),e.arcTo(p.startX+h.inset,p.startY+p.height-h.inset,p.startX+h.inset,p.startY+p.height-h.inset-h.radius,h.radius),e.lineTo(p.startX+h.inset,p.startY+h.inset+h.radius),e.arcTo(p.startX+h.inset,p.startY+h.inset,p.startX+h.inset+h.radius,p.startY+h.inset,h.radius),e.closePath(),e.stroke(),e.setLineDash([]))}e.lineWidth=i;break;case"inset":this.drawImgToCtx(e,o),e.filter="none",e.strokeStyle=this.getFrameColor(h,e,p),i=e.lineWidth,e.lineWidth=h.size/10,e.beginPath(),e.moveTo(p.startX+h.offset,p.startY+h.inset),e.lineTo(p.startX+p.width-h.offset,p.startY+h.inset),e.moveTo(p.startX+p.width-h.inset,p.startY+h.offset),e.lineTo(p.startX+p.width-h.inset,p.startY+p.height-h.offset),e.moveTo(p.startX+p.width-h.offset,p.startY+p.height-h.inset),e.lineTo(p.startX+h.offset,p.startY+p.height-h.inset),e.moveTo(p.startX+h.inset,p.startY+p.height-h.offset),e.lineTo(p.startX+h.inset,p.startY+h.offset),e.stroke(),e.closePath(),e.lineWidth=i;break;case"hook":this.drawImgToCtx(e,o),e.filter="none",e.strokeStyle=this.getFrameColor(h,e,p),i=e.lineWidth,e.lineWidth=h.size/10,e.beginPath(),e.moveTo(p.startX+h.inset+u,p.startY+h.inset),e.lineTo(p.startX+h.inset,p.startY+h.inset),e.lineTo(p.startX+h.inset,p.startY+h.inset+u),e.moveTo(p.startX+p.width-h.inset-u,p.startY+h.inset),e.lineTo(p.startX+p.width-h.inset,p.startY+h.inset),e.lineTo(p.startX+p.width-h.inset,p.startY+h.inset+u),e.moveTo(p.startX+p.width-h.inset-u,p.startY+p.height-h.inset),e.lineTo(p.startX+p.width-h.inset,p.startY+p.height-h.inset),e.lineTo(p.startX+p.width-h.inset,p.startY+p.height-h.inset-u),e.moveTo(p.startX+h.inset+u,p.startY+p.height-h.inset),e.lineTo(p.startX+h.inset,p.startY+p.height-h.inset),e.lineTo(p.startX+h.inset,p.startY+p.height-h.inset-u),e.stroke(),e.lineWidth=i}(s.isCircleCrop||s.currSelectionPoint&&"crop-circle"===s.currSelectionPoint.shape)&&s.notify("crop",{prop:"cropCircle",onPropertyChange:!1,value:{context:e,isSave:e.canvas.id===s.element.id+"_tempCanvas"||null,isFlip:null}}),e.filter=v}}},t.prototype.triggerFrameChange=function(e){var t=this.parent,e={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",e),e.cancel||this.setFrameObj(e.currentFrameSetting),e},t.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},t.prototype.zoomToSel=function(e,t){var o=this.parent;if(this.straightenActObj&&JSON.stringify(this.straightenActObj.activePoint)===JSON.stringify(e.activePoint))if(o.activeObj=O.extend({},this.straightenActObj,null,!0),0===o.transform.straighten){var i=o.img.destWidth,r=o.img.destHeight;for(o.transform.straighten=360;;){if(O.isNullOrUndefined(this.straightenInitZoom)||!(Math.round(o.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"),i===o.img.destWidth&&r===o.img.destHeight){this.performDummyZoom();break}0===o.transform.degree&&(o.transform.zoomFactor-=.025,o.transform.cropZoomFactor-=.025)}o.transform.straighten=0,o.img={destLeft:o.img.destLeft,destTop:o.img.destTop,destWidth:o.img.destWidth,destHeight:o.img.destHeight,srcLeft:o.img.srcLeft,srcTop:o.img.srcTop,srcWidth:o.img.srcWidth,srcHeight:o.img.srcHeight}}else O.isNullOrUndefined(this.straightenInitZoom)&&(this.straightenInitZoom=o.transform.zoomFactor),0<this.straightenInitZoom-o.transform.zoomFactor?o.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:-(this.straightenInitZoom-o.transform.zoomFactor),zoomPoint:null,isResize:!0}}):this.straightenInitZoom-o.transform.zoomFactor<0&&o.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:this.straightenInitZoom-o.transform.zoomFactor,zoomPoint:null,isResize:!0}}),o.activeObj=O.extend({},e,null,!0),o.transform.zoomFactor+=.001,this.calcStraightenedPoints(t);else this.straightenActObj=O.extend({},e,null,!0),o.activeObj=O.extend({},this.straightenActObj,null,!0),this.straightenInitZoom=o.transform.zoomFactor,this.calcStraightenedPoints(t)},t.prototype.isDestPointSmall=function(){var e=this.parent,t=e.img,o={startX:t.destLeft,startY:t.destTop,width:t.destWidth,height:t.destHeight},i=(e.notify("shape",{prop:"straightenShapes",onPropertyChange:!1}),!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},t.prototype.calcStraightenedPoints=function(n){for(var a=this.parent,s=a.img.destWidth,l=a.img.destHeight,p=(O.isNullOrUndefined(a.transform.zoomFactor)&&(a.transform.zoomFactor+=.025),this.updateImgCanvasPoints(),this);"break"!==function(){if(!(p.isLinesIntersect()||p.isSelOutsideImg()||n&&p.isDestPointSmall()))return p.performDummyZoom(),"break";if(a.activeObj=O.extend({},p.straightenActObj,null,!0),p.setZoomPan("in"),s===a.img.destWidth&&l===a.img.destHeight)return p.performDummyZoom(),"break";0===a.transform.degree&&(a.transform.zoomFactor+=.025,a.transform.cropZoomFactor+=.025);var e=p.imgCanvasPoints,t=a.img.destLeft,o=a.img.destTop,i=a.img.destWidth,r=a.img.destHeight;e.forEach(function(e){e.x=e.ratioX*i+t,e.y=e.ratioY*r+o}),p.imgCanvasPoints=e}(););},t.prototype.performDummyZoom=function(){var e=this.parent,t=(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}}),10*e.transform.zoomFactor);e.setProperties({zoomSettings:{zoomFactor:t=t<1?1+t/10:t}},!0),e.notify("transform",{prop:"setPreviousZoomValue",onPropertyChange:!1,value:{previousZoomValue:t}}),this.panToSel()},t.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"))},t.prototype.updateImgCanvasPoints=function(){var e,t,o,i=this.parent,r=this.getImagePoints(),n={width:0,height:0},a=i.baseImgCanvas.width,s=i.baseImgCanvas.height,a=(i.notify("crop",{prop:"calcRatio",onPropertyChange:!1,value:{obj:n,dimension:{width:a,height:s}}}),i.transform.degree%90==0&&i.transform.degree%180!=0?n.height:n.width),s=i.transform.degree%90==0&&i.transform.degree%180!=0?n.width:n.height,n=i.img,l=n.destLeft,p=n.destTop,h=n.destWidth,n=n.destHeight,i=0<i.transform.straighten?(e={x:l+r[0].x/a,y:p},t={x:l+h,y:p+r[1].y/s},o={x:l+h-r[0].x/a,y:p+n},{x:l,y:p+n-r[1].y/s}):(e={x:l,y:p+r[0].y/s},t={x:l+r[1].x/a,y:p},o={x:l+h,y:p+n-r[0].y/s},{x:l+h-r[1].x/a,y:p+n});e.ratioX=(e.x-l)/h,e.ratioY=(e.y-p)/n,t.ratioX=(t.x-l)/h,t.ratioY=(t.y-p)/n,o.ratioX=(o.x-l)/h,o.ratioY=(o.y-p)/n,i.ratioX=(i.x-l)/h,i.ratioY=(i.y-p)/n,this.imgCanvasPoints=[e,t,o,i]},t.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]),n=this.doIntersect({x:t.startX,y:t.endY},{x:t.endX,y:t.endY},o[2],o[3]),a=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,n,a]),i||r||n||a||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},t.prototype.isSelOutsideImg=function(){var e=this.parent,t=this.imgCanvasPoints,e=e.activeObj.activePoint;return"inside"!==this.checkPointPosition(e.startX,e.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(e.endX,e.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(e.startX,e.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(e.endX,e.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)},t.prototype.calcTriangleArea=function(e,t,o,i,r,n){return Math.abs((e*(i-n)+o*(n-t)+r*(t-i))/2)},t.prototype.checkPointPosition=function(e,t,o,i,r,n,a,s,l,p){var h=this.calcTriangleArea(e,t,o,i,l,p),d=this.calcTriangleArea(e,t,l,p,a,s),c=this.calcTriangleArea(e,t,a,s,r,n),e=this.calcTriangleArea(e,t,r,n,o,i),t=this.calcTriangleArea(o,i,r,n,a,s)+this.calcTriangleArea(a,s,l,p,o,i);return t<h+d+c+e?"outside":h+d+c+e!==t||0!==h&&0!==d&&0!==c&&0!==e?"inside":"on"},t.prototype.getImagePoints=function(){var e=[],t=this.parent,o=t.transform.degree,i=t.baseImg.width,r=t.baseImg.height,n={dim:null,width:r,height:i,angle:t.transform.straighten};n.dim=t.getRotatedCanvasDim(n.width,n.height,n.angle);var a=o%90==0&&o%180!=0?r:i,i=o%90==0&&o%180!=0?i:r,r=(o%90==0&&o%180!=0?n.dim:t.baseImgCanvas).width/2,o=(o%90==0&&o%180!=0?n.dim:t.baseImgCanvas).height/2,n=r-a/2,s=o-i/2,a=r+a/2,i=o+i/2,t=t.transform.straighten*(Math.PI/180),l={x:Math.cos(t)*(n-r)-Math.sin(t)*(s-o)+r,y:Math.sin(t)*(n-r)+Math.cos(t)*(s-o)+o},s={x:Math.cos(t)*(a-r)-Math.sin(t)*(s-o)+r,y:Math.sin(t)*(a-r)+Math.cos(t)*(s-o)+o},a={x:Math.cos(t)*(a-r)-Math.sin(t)*(i-o)+r,y:Math.sin(t)*(a-r)+Math.cos(t)*(i-o)+o},n={x:Math.cos(t)*(n-r)-Math.sin(t)*(i-o)+r,y:Math.sin(t)*(n-r)+Math.cos(t)*(i-o)+o};return e.push(l),e.push(s),e.push(a),e.push(n),e},t.prototype.doIntersect=function(e,t,o,i){var r=this.initiation(e,t,o),n=this.initiation(e,t,i),a=this.initiation(o,i,e),s=this.initiation(o,i,t);return r!==n&&a!==s||!!(0===r&&this.onSegment(e,o,t)||0===n&&this.onSegment(e,i,t)||0===a&&this.onSegment(o,e,i)||0===s&&this.onSegment(o,t,i))},t.prototype.initiation=function(e,t,o){e=(t.y-e.y)*(o.x-t.x)-(t.x-e.x)*(o.y-t.y);return 0==e?0:0<e?1:2},t.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)},t.prototype.isInsideRect=function(e){var t=this.parent.activeObj.activePoint,o=!1;return o=e.x>=t.startX&&e.x<=t.endX&&e.y>=t.startY&&e.y<=t.endY?!0:o},t.prototype.setDestForStraighten=function(){var e,t,o,i,r=this.parent;O.isNullOrUndefined(this.straightenDestPoints)&&(e=(i=r.img).destLeft,t=i.destTop,o=i.destWidth,i=i.destHeight,r.notify("shape",{prop:"straightenShapes",onPropertyChange:!1}),this.straightenDestPoints=O.extend({},r.img,{},!0),r.img.destLeft=e,r.img.destTop=t,r.img.destWidth=o,r.img.destHeight=i)},t);function t(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()}n.prototype.destroy=function(){this.parent.isDestroyed||this.removeEventListener()},n.prototype.addEventListener=function(){this.parent.on("export",this.export,this),this.parent.on("destroyed",this.destroy,this)},n.prototype.removeEventListener=function(){this.parent.off("export",this.export),this.parent.off("destroyed",this.destroy)},n.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);break;case"exportToCanvas":this.exportToCanvas(e.value.object);break;case"updateSaveContext":this.updateSaveContext(e.value.context);break;case"setImageQuality":this.imageQuality=e.value.value}},n.prototype.getModuleName=function(){return"export"},n.prototype.updatePvtVar=function(){var e=this.parent;e.lowerCanvas&&(this.lowerContext=e.lowerCanvas.getContext("2d"))},n.prototype.exportImg=function(e,t){var o,i=this.parent,r={fileName:""},r=(i.notify("draw",{prop:"getFileName",onPropertyChange:!1,value:{obj:r}}),r.fileName);!i.disabled&&i.isImageLoaded&&(i.notify("selection",{prop:"getFreehandDrawEditing",onPropertyChange:!(o={bool:!1}),value:{obj:o}}),o.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}}),o={canvasFilter:this.parent.canvasFilter},this.lowerContext.filter=o.canvasFilter,e=e||"Png",i.notify("shape",{prop:"redrawActObj",onPropertyChange:!1,value:{x:null,y:null,isMouseDown:null}}),i.trigger("beforeSave",o={cancel:!1,fileName:t||r,fileType:e}),this.beforeSaveEvent(o,e,t,r))},n.prototype.beforeSaveEvent=function(e,t,o,i){var r=this.parent;e.cancel||(r.currObjType.isSave=!0,o=(o=e.fileName||o)||i,"svg"===(e=t.toLowerCase())?this.toSVGImg(o):this.toBlobFn(o,e),r.trigger("saved",{fileName:o||i,fileType:t}),r.notify("toolbar",{prop:"refresh-main-toolbar",onPropertyChange:!1}),r.lowerCanvas.style.left=r.upperCanvas.style.left="",r.lowerCanvas.style.top=r.upperCanvas.style.top="",r.lowerCanvas.style.maxWidth=r.upperCanvas.style.maxWidth="",r.lowerCanvas.style.maxHeight=r.upperCanvas.style.maxHeight="")},n.prototype.toSVGImg=function(e){var t=this.parent,o=(u.showSpinner(t.element),t.element.style.opacity="0.5",this.exportToCanvas()),i=o.toDataURL(),t=(u.hideSpinner(t.element),t.element.style.opacity="1",document.createElementNS("http://www.w3.org/2000/svg","svg")),r=(t.setAttribute("width",o.style.maxWidth),t.setAttribute("height",o.style.maxHeight),document.createElementNS("http://www.w3.org/2000/svg","image")),i=(r.setAttributeNS(null,"height",o.height.toString()),r.setAttributeNS(null,"width",o.width.toString()),r.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",i),t.appendChild(r),'<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="'+o.width+'" height="'+o.height+'">'),r=t.innerHTML,o="data:image/svg+xml;base64,"+btoa(i+r+"</svg>");return null===e?o:(this.downloadImg(o,e+".svg"),null)},n.prototype.toBlobFn=function(t,o){var i=this,r=this.parent;u.showSpinner(r.element),r.element.style.opacity="0.5",this.exportToCanvas().toBlob(function(e){e=URL.createObjectURL(e);i.downloadImg(e,t+"."+o),u.hideSpinner(r.element),r.element.style.opacity="1"},"jpeg"!==o?"image/png":"image/jpeg",this.imageQuality||null)},n.prototype.exportToCanvas=function(e){var t,o,i=this.parent,r=O.extend({},i.cropObj,{},!0),n={currObj:{}},n=(i.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:n}}),n.currObj),a=(n.objColl=O.extend([],i.objColl,[],!0),n.pointColl=O.extend([],i.pointColl,[],!0),n.afterCropActions=O.extend([],i.afterCropActions,[],!0),{selPointColl:null}),s=(i.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:a}}),this.parent.aspectWidth?(i.notify("undo-redo",{prop:"setPreventUR",value:{bool:!0}}),i.notify("toolbar",{prop:"resizeClick",value:{bool:!1}}),i.okBtn(),o=i.transform.degree%90==0&&i.transform.degree%180!=0?(t=this.parent.aspectHeight,this.parent.aspectWidth):(t=this.parent.aspectWidth,this.parent.aspectHeight),i.notify("undo-redo",{prop:"setPreventUR",value:{bool:!1}})):o=i.currSelectionPoint?(t=i.img.srcWidth,i.img.srcHeight):(t=i.baseImgCanvas.width,i.baseImgCanvas.height),{width:0,height:0}),l=(i.notify("crop",{prop:"calcRatio",onPropertyChange:!1,value:{obj:s,dimension:{width:t,height:o}}}),this.lowerContext.filter),p=("none"!==this.lowerContext.filter&&(h=this.lowerContext.filter.split(" "),p=parseFloat(h[5].split("(")[1]),h[5]="blur("+(p*=(s.width+s.height)/2)+"px)",this.lowerContext.filter=h.join(" ")),i.createElement("canvas",{id:i.element.id+"_tempCanvas",attrs:{name:"canvasImage"}})),h=p.getContext("2d"),d=(p.width=t,p.height=o,{width:0,height:0}),d=(i.notify("transform",{prop:"calcMaxDimension",onPropertyChange:!1,value:{width:t,height:o,obj:d}}),p.style.maxWidth=d.width+"px",p.style.maxHeight=d.height+"px",this.lowerContext.filter);return h.filter=this.lowerContext.filter,this.downScaleImgCanvas(h,t,o),this.lowerContext.filter=d,0===i.transform.degree&&""===i.transform.currFlipState&&0===i.transform.straighten||(this.updateSaveContext(h),this.exportTransformedImage(h)),this.drawAnnotation(h,s),i.isCircleCrop&&i.notify("crop",{prop:"cropCircle",onPropertyChange:!1,value:{context:h,isSave:!0,isFlip:null}}),this.updateFrame(h,!0),this.lowerContext.filter=l,i.canvasFilter=l,e&&(e.canvas=p),i.aspectWidth&&(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:n}}),n.selPointColl=O.extend([],a.selPointColl,[],!0),i.notify("freehand-draw",{prop:"setSelPointColl",onPropertyChange:!1,value:{obj:{selPointColl:n.selPointColl}}}),i.cropObj=r,i.objColl=O.extend([],n.objColl,[],!0),i.pointColl=O.extend([],n.pointColl,[],!0),i.freehandCounter=i.pointColl.length,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=n.filter,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}}),p},n.prototype.drawAnnotation=function(e,t){for(var o=this.parent,i=O.extend([],o.objColl,[],!0),r=O.extend([],o.pointColl,[],!0),n=0;n<o.shapeColl.length;n++)o.shapeColl[n].order&&(o.shapeColl[n].currIndex&&-1<o.shapeColl[n].currIndex.indexOf("shape")?(o.objColl=[],o.objColl.push(O.extend({},o.shapeColl[n],{},!0)),this.drawShape(e,t)):o.shapeColl[n].id&&-1<o.shapeColl[n].id.indexOf("pen")&&(o.pointColl=[],o.freehandCounter=0,o.pointColl.push(O.extend({},o.shapeColl[n],{},!0)),o.freehandCounter=o.pointColl.length,this.drawPen(e,t)));o.objColl=i,o.pointColl=r,o.freehandCounter=o.pointColl.length},n.prototype.drawShape=function(e,t){var o=this.parent;if(0<o.objColl.length){for(var i=e.filter,r=(e.filter="none",{index:null}),n=(o.notify("shape",{prop:"getSmallestIndex",onPropertyChange:!1,value:{obj:r}}),r.index),a=O.extend([],o.objColl,[],!0),r=O.extend([],o.objColl,[],!0);0<a.length;){for(var s=!1,l=0;l<a.length;l++){var p=a[l];if(O.isNullOrUndefined(p.order))a.splice(l,1),l--;else if(p.order===n){var p=e.filter,h=(e.filter="none",a[l]),d=h.activePoint;if(d.startX-=o.img.destLeft,d.startY-=o.img.destTop,d.endX-=o.img.destLeft,d.endY-=o.img.destTop,d.width=d.endX-d.startX,d.height=d.endY-d.startY,d.startX*=t.width,d.startY*=t.height,d.endX*=t.width,d.endY*=t.height,d.width=d.endX-d.startX,d.height=d.endY-d.startY,h.strokeSettings.strokeWidth*=(t.width+t.height)/2,"text"===h.shape)h.textSettings.fontSize*=(t.width+t.height)/2;else if("path"===h.shape)for(var c=0;c<h.pointColl.length;c++)h.pointColl[c].x=(h.pointColl[c].x-o.img.destLeft)*t.width,h.pointColl[c].y=(h.pointColl[c].y-o.img.destTop)*t.height;else"image"===h.shape&&(o.activeObj=O.extend({},a[l],{},!0),o.notify("selection",{prop:"upgradeImageQuality",onPropertyChange:!1}),a[l]=O.extend({},o.activeObj,{},!0));o.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"saveContext",obj:a[l],isCropRatio:null,points:null,isPreventDrag:!0,saveContext:e,isPreventSelection:null}}),e.filter=p,o.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),n++;d={bool:!1};o.notify("shape",{prop:"isIndexInObjColl",onPropertyChange:!1,value:{obj:d,index:n}}),d.bool||n++,a.splice(l,1),s=!0;break}}if(!s)break}e.filter=i,o.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),o.objColl=r}},n.prototype.drawPen=function(e,t){var o=this.parent;if(0<o.freehandCounter){for(var i={penStrokeWidth:null},r=(o.notify("freehand-draw",{prop:"getPenStrokeWidth",onPropertyChange:!1,value:{obj:i}}),O.extend({},o.pointColl,{},!0)),n=0;n<o.freehandCounter;n++){o.points=O.extend([],o.pointColl[n].points,[]),o.notify("freehand-draw",{prop:"setPointCounter",onPropertyChange:!1,value:{value:0}});var a=o.points.length;o.pointColl[n].strokeWidth*=(t.width+t.height)/2;for(var s=0;s<a;s++)o.points[s].x=(o.points[s].x-o.img.destLeft)*t.width,o.points[s].y=(o.points[s].y-o.img.destTop)*t.height}o.notify("freehand-draw",{prop:"freehandRedraw",onPropertyChange:!1,value:{context:e,points:null}}),o.pointColl=r,o.notify("freehand-draw",{prop:"setPenStrokeWidth",onPropertyChange:!1,value:{value:i.penStrokeWidth}})}},n.prototype.downScaleImgCanvas=function(e,t,o){var i=this.parent,r=i.baseImgCanvas,n=i.baseImg,a={width:0,height:0};i.notify("transform",{prop:"calcMaxDimension",onPropertyChange:!1,value:{width:n.width,height:n.height,obj:a,isImgShape:null}}),t<a.width&&o<a.height?((n=i.createElement("canvas",{id:i.element.id+"_downScaleCanvas",attrs:{name:"canvasImage"}})).width=this.parent.img.srcWidth,n.height=this.parent.img.srcHeight,n.getContext("2d").drawImage(r,i.img.srcLeft,i.img.srcTop,i.img.srcWidth,i.img.srcHeight,0,0,n.width,n.height),i.notify("draw",{prop:"downScale",value:{canvas:n,width:t,height:o}}),e.drawImage(n,0,0)):e.drawImage(i.baseImgCanvas,i.img.srcLeft,i.img.srcTop,i.img.srcWidth,i.img.srcHeight,0,0,t,o)},n.prototype.updateFrame=function(e,t){var o;"none"!==this.parent.frameObj.type&&(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)},n.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)},n.prototype.exportTransformedImage=function(e){var t=this.parent,o=t.transform.degree;if(0<t.rotateFlipColl.length)for(var i=0,r=t.rotateFlipColl.length;i<r;i++){var n=t.rotateFlipColl[i];"number"==typeof n?this.exportRotate(e,n):"horizontal"===n?this.exportFlip(e,!0,!1):"vertical"===n&&this.exportFlip(e,!1,!0)}t.transform.degree=o},n.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)},n.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)},n.prototype.updateSaveContext=function(e){var t=this.parent.inMemoryCanvas.getContext("2d"),e=(e.setTransform(1,0,0,1,0,0),e.getImageData(0,0,e.canvas.width,e.canvas.height));this.parent.inMemoryCanvas.width=e.width,this.parent.inMemoryCanvas.height=e.height,t.putImageData(e,0,0)},n.prototype.setMaxDim=function(e,t){e%90==0&&e%180!=0?o=O.isNullOrUndefined(this.parent.currSelectionPoint)?(i=this.parent.baseImgCanvas.height,this.parent.baseImgCanvas.width):(i=this.parent.img.srcHeight,this.parent.img.srcWidth):e%180!=0&&0!==e||(o=O.isNullOrUndefined(this.parent.currSelectionPoint)?(i=this.parent.baseImgCanvas.width,this.parent.baseImgCanvas.height):(i=this.parent.img.srcWidth,this.parent.img.srcHeight)),O.isNullOrUndefined(this.parent.aspectWidth)||(i=this.parent.aspectWidth,o=this.parent.aspectHeight),t.width=i,t.height=o;var o,e={width:0,height:0},i=(this.parent.notify("transform",{prop:"calcMaxDimension",onPropertyChange:!1,value:{width:i,height:o,obj:e,isImgShape:null}}),e);t.style.maxWidth=i.width+"px",t.style.maxHeight=i.height+"px"};var r=n;function n(e){this.parent=e,this.addEventListener()}s.prototype.destroy=function(){this.parent.isDestroyed||this.removeEventListener()},s.prototype.addEventListener=function(){this.parent.on("filter",this.filter,this),this.parent.on("destroyed",this.destroy,this)},s.prototype.removeEventListener=function(){this.parent.off("filter",this.filter),this.parent.off("destroyed",this.destroy)},s.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":O.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=O.extend({},this.adjustmentLevel,{},!0);break;case"setTempFilVal":this.tempFilVal=this.parent.currentFilter;break;case"reset":this.reset()}},s.prototype.updatePrivateVariables=function(){var e=this.parent;e.lowerCanvas&&(this.lowerContext=e.lowerCanvas.getContext("2d"))},s.prototype.getModuleName=function(){return"filter"},s.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}},s.prototype.updateFinetunes=function(){var t=this,e=this.parent,o=e.finetuneSettings;o&&(["brightness","contrast","hue","saturation","exposure","opacity","blur"].forEach(function(e){o[e]&&(t.adjustmentLevel[e]=o[e].defaultValue,t.tempAdjustmentLevel[e]=o[e].defaultValue)}),e.notify("draw",{prop:"isInitialLoading",onPropertyChange:!1,value:{isInitialLoading:!0}}))},s.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)},s.prototype.updateAdj=function(e,t,o,i){var r,n,a=this.parent,s=(this.lowerContext.clearRect(0,0,a.lowerCanvas.width,a.lowerCanvas.height),this.lowerContext.filter.split(" ")),l=[],p=this.getFilterValue(this.adjustmentLevel.brightness);switch(-1===["brightness","contrast","hue","saturation","exposure","opacity","blur"].indexOf(e)&&O.isNullOrUndefined(o)&&(this.adjustmentLevel.sharpen||this.adjustmentLevel.bw)&&(a.isUndoRedo=!0,n=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=n,a.isUndoRedo=!1),e){case"brightness":t=this.getFilterValue(this.adjustmentLevel.exposure)+.005*t,s[0]="brightness("+t+")",t=0!==this.adjustmentLevel.brightness?this.adjustmentLevel.opacity/100-.3*this.adjustmentLevel.opacity/100:this.adjustmentLevel.opacity/100,s[4]="opacity("+t+")",this.adjustmentValue=s.join(" ");break;case"contrast":s[1]="contrast("+t+"%)",this.adjustmentValue=s.join(" ");break;case"hue":s[2]="hue-rotate("+t+"deg)",this.adjustmentValue=s.join(" ");break;case"saturation":s[3]="saturate("+t+"%)",this.adjustmentValue=s.join(" ");break;case"opacity":1!==parseFloat(s[0].split("(")[1])&&(t-=.2),s[4]="opacity("+(t=t<0?0:t)+")",this.adjustmentValue=s.join(" ");break;case"blur":s[5]="blur("+t+"px)",this.adjustmentValue=s.join(" ");break;case"exposure":1<t?(--t,t+=p):t<1&&(t=p-(t=1-t)),s[0]="brightness("+t+")",this.adjustmentValue=s.join(" ");break;case"chrome":r=this.getSaturationFilterValue(this.adjustmentLevel.saturation),s[3]="saturate("+(t=(r*=100)+.4*r)+"%)",l=this.adjustmentValue.split(" "),s[0]=l[0],s[1]=l[1],s[2]=l[2],s[4]=l[4],s[5]=l[5],s[6]="sepia(0%)",s[7]="grayscale(0%)",s[8]="invert(0%)";break;case"cold":r=this.getFilterValue(this.adjustmentLevel.brightness),t=.9*(r*=100),s[0]="brightness("+(t*=.01)+")",r=this.getFilterValue(this.adjustmentLevel.contrast),s[1]="contrast("+(t=(r*=100)+.5*r)+"%)",r=this.getSaturationFilterValue(this.adjustmentLevel.saturation),s[3]="saturate("+(t=r*=100)+"%)",l=this.adjustmentValue.split(" "),s[2]=l[2],s[4]=l[4],s[5]=l[5],s[6]="sepia(0%)",s[7]="grayscale(0%)",s[8]="invert(0%)";break;case"warm":r=this.getSaturationFilterValue(this.adjustmentLevel.saturation),s[3]="saturate("+(t=(r*=100)+.4*r)+"%)",s[6]="sepia(25%)",l=this.adjustmentValue.split(" "),s[0]=l[0],s[1]=l[1],s[2]=l[2],s[4]=l[4],s[5]=l[5],s[7]="grayscale(0%)",s[8]="invert(0%)";break;case"grayscale":s[7]="grayscale(100%)",l=this.adjustmentValue.split(" "),s[0]=l[0],s[1]=l[1],s[2]=l[2],s[3]=l[3],s[4]=l[4],s[5]=l[5],s[6]="sepia(0%)",s[8]="invert(0%)";break;case"sepia":s[6]="sepia(100%)",l=this.adjustmentValue.split(" "),s[0]=l[0],s[1]=l[1],s[2]=l[2],s[3]=l[3],s[4]=l[4],s[5]=l[5],s[7]="grayscale(0%)",s[8]="invert(0%)";break;case"invert":s[8]="invert(100%)",l=this.adjustmentValue.split(" "),s[0]=l[0],s[1]=l[1],s[2]=l[2],s[3]=l[3],s[4]=l[4],s[5]=l[5],s[6]="sepia(0%)",s[7]="grayscale(0%)"}"sharpen"!==e&&"blackandwhite"!==e&&(O.isNullOrUndefined(o)&&("default"===e&&(s=this.getDefaultCurrentFilter(s)),this.lowerContext.filter=s.join(" ")),s=this.setTempFilterValue(p,o,s,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}}),n=void 0,"bevel"===a.frameObj.type&&(n=this.lowerContext.filter,this.bevelFilter=n),0===a.transform.degree&&0<a.rotateFlipColl.length&&(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&&0<a.rotateFlipColl.length&&(a.img.destLeft+=a.panPoint.totalPannedPoint.x,a.img.destTop+=a.panPoint.totalPannedPoint.y),s=this.setTempFilterValue(p,o,s,e),O.isNullOrUndefined(o)&&(this.lowerContext.filter=s.join(" ")),a.initialAdjustmentValue=s.join(" "),n=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=n,a.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"iterate",pen:"iterate",isPreventApply:null}}),this.lowerContext.filter=n,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!==p);e=s.join(" ");i&&(i.filter=e)},s.prototype.setTempFilterValue=function(e,t,o,i){return t&&("default"===i?o=this.getDefaultCurrentFilter(o):1!==e&&((t=this.lowerContext.filter.split(" "))[4]=o[4],this.lowerContext.filter=t.join(" "))),o},s.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%)"]},s.prototype.getFilterValue=function(e){return 0===e?1:1+.5*e/100},s.prototype.getSaturationFilterValue=function(e){return 0===e?1:1+e/100},s.prototype.setFilterAdj=function(e,t){var o=this.parent;switch(o.notify("freehand-draw",{prop:"apply-pen-draw",onPropertyChange:!1}),this.adjustmentLevel[""+e]=t,e){case"contrast":case"exposure":t=this.getFilterValue(t),"contrast"===e&&(t*=100);break;case"hue":t*=3;break;case"saturation":t=100*this.getSaturationFilterValue(t);break;case"opacity":t<10&&(t+=1),t/=100;break;case"blur":0!==t&&(t=t/20+.5)}var i=O.extend({},o.cropObj,{},!0),r=this.getCurrentObj(),n=(r.objColl=O.extend([],o.objColl,[],!0),r.pointColl=O.extend([],o.pointColl,[],!0),r.afterCropActions=O.extend([],o.afterCropActions,[],!0),{selPointColl:null});o.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:n}}),r.selPointColl=O.extend([],n.selPointColl,[],!0),this.updateAdj(e,t),o.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:e,previousObj:r,previousObjColl:r.objColl,previousPointColl:r.pointColl,previousSelPointColl:r.selPointColl,previousCropObj:i,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}})},s.prototype.setFilter=function(e){var t=this.parent;e=e.toLowerCase(),t.notify("freehand-draw",{prop:"apply-pen-draw",onPropertyChange:!1});var o={currentFilter:this.parent.currentFilter}.currentFilter,i=O.extend({},t.cropObj,{},!0),r=this.getCurrentObj(),n=(r.objColl=O.extend([],t.objColl,[],!0),r.pointColl=O.extend([],t.pointColl,[],!0),r.afterCropActions=O.extend([],t.afterCropActions,[],!0),{selPointColl:null});t.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:n}}),r.selPointColl=O.extend([],n.selPointColl,[],!0),this.updateAdj(e,null),t.notify("draw",{prop:"setImageEdited",onPropertyChange:!1}),t.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:e,previousObj:r,previousObjColl:r.objColl,previousPointColl:r.pointColl,previousSelPointColl:r.selPointColl,previousCropObj:i,previousText:null,currentText:null,previousFilter:o,isCircleCrop:null}})},s.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]),this.adjustmentLevel.contrast=this.setFilterValue(t/=100);break;case"hue":o=i[2].split("("),t=parseFloat(o[1].split(")")[0]),this.adjustmentLevel.hue=t/=3;break;case"saturation":o=i[3].split("("),t=parseFloat(o[1].split(")")[0]),this.adjustmentLevel.saturation=this.setSaturationFilterValue(t/=100);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]),this.adjustmentLevel.blur=t*=20;break;case"exposure":o=i[0].split("("),t=parseFloat(o[1].split(")")[0]),this.adjustmentLevel.exposure=this.setFilterValue(t)}},s.prototype.setFilterValue=function(e){return Math.round(1===e?0:100*(e-1)/.5)},s.prototype.setSaturationFilterValue=function(e){return Math.round(1===e?0:100*(e-1))},s.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"}})}},s.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}},s.prototype.getCurrentObj=function(e){var t=this.parent,o={point:null},i=(t.notify("crop",{prop:"getTempFlipPanPoint",value:{obj:o}}),{previousZoomValue:null}),r=(t.notify("transform",{prop:"getPreviousZoomValue",value:{obj:i}}),{zoomFactor:null}),n=(t.notify("draw",{prop:"getStraightenInitZoom",value:{obj:r}}),{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:O.extend({},this.tempAdjVal,{},!0),currentFilter:this.tempFilVal});return n.cropZoom=t.transform.cropZoomFactor,n.defaultZoom=t.transform.defaultZoomFactor,n.zoomFactor=t.zoomSettings.zoomFactor,n.previousZoomValue=i.previousZoomValue,n.straightenZoom=r.zoomFactor,n.totalPannedPoint=O.extend({},t.panPoint.totalPannedPoint,{},!0),n.totalPannedClientPoint=O.extend({},t.panPoint.totalPannedClientPoint,{},!0),n.totalPannedInternalPoint=O.extend({},t.panPoint.totalPannedInternalPoint,{},!0),n.tempFlipPanPoint=O.extend({},o.point,{},!0),n.activeObj=O.extend({},t.activeObj,{},!0),n.rotateFlipColl=O.extend([],t.rotateFlipColl,[],!0),n.degree=t.transform.degree,n.straighten=t.cropObj.straighten,n.currFlipState=t.transform.currFlipState,n.destPoints={startX:t.img.destLeft,startY:t.img.destTop,endX:0,endY:0,width:t.img.destWidth,height:t.img.destHeight},n.srcPoints={startX:t.img.srcLeft,startY:t.img.srcTop,endX:0,endY:0,width:t.img.srcWidth,height:t.img.srcHeight},n.filter=this.lowerContext.filter,n.aspectWidth=t.aspectWidth,n.aspectHeight=t.aspectHeight,n.frame=t.frameObj.type,n.frameObj=O.extend({},t.frameObj),e&&(e.currObj=n),n};var a=s;function s(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()}p.prototype.destroy=function(){this.parent.isDestroyed||this.removeEventListener()},p.prototype.addEventListener=function(){this.parent.on("freehand-draw",this.draw,this),this.parent.on("destroyed",this.destroy,this)},p.prototype.removeEventListener=function(){this.parent.off("freehand-draw",this.draw),this.parent.off("destroyed",this.destroy)},p.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":var t=parseInt(e.value.id.split("_")[1],10)-1;this.isFHDIdx(t)&&this.deleteFhd(t,!0);break;case"freehandRedraw":this.freehandRedraw(e.value.context,e.value.points);break;case"deleteFhd":t=parseInt(e.value.id.split("_")[1],10)-1;this.deleteFhd(t,!0);break;case"selectFhd":t=null;e.value.id&&(t=parseInt(e.value.id.split("_")[1],10)-1),this.selectFhd(t);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=O.extend([],this.selPointColl);break;case"setSelPointColl":this.selPointColl=O.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=O.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)}},p.prototype.updateFhdPvtVar=function(){var e=this.parent;e.lowerCanvas&&(this.lowerContext=e.lowerCanvas.getContext("2d")),e.upperCanvas&&(this.upperContext=e.upperCanvas.getContext("2d"))},p.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},p.prototype.getModuleName=function(){return"freehand-draw"},p.prototype.hoverFhd=function(e,t){var o,i,r,n,a,s,l=this.parent,p=this.upperContext,h=-1,h=-1<this.fhdHovIdx?this.fhdHovIdx:this.fhdSelIdx,d=(l.points=O.extend([],l.pointColl[h].points),this.pointCounter=0,l.points.length);p.fillStyle=e||l.pointColl[h].strokeColor,p.strokeStyle=p.fillStyle,a=s=this.penStrokeWidth=t||l.pointColl[h].strokeWidth,1===d&&(o=i=r=n=l.points[0],this.startDraw(p,o,i,r,n,a,s));for(var c=0;c<d-3;c++)l.points[c+1]&&l.points[c+2]&&l.points[c+2]&&(o=this.calcCurveCP(l.points[c+0],l.points[c+1],l.points[c+2]).controlPoint2,i=this.calcCurveCP(l.points[c+1],l.points[c+2],l.points[c+3]).controlPoint1,r=0===c?l.points[c]:l.points[c+1],n=l.points[c+2],this.startDraw(p,o,i,r,n,a,s));p.closePath();e=this.getSqPtFD(h),t=p.lineWidth;p.lineWidth=2,p.strokeStyle=l.themeColl[l.theme].primaryColor,p.beginPath(),p.rect(e.startX,e.startY,e.width,e.height),p.stroke(),p.closePath(),p.lineWidth=t},p.prototype.freehandDownHandler=function(e,t){var o=this.parent,e=(o.lowerCanvas=document.querySelector("#"+o.element.id+"_lowerCanvas"),this.lowerContext=o.lowerCanvas.getContext("2d"),o.upperCanvas=document.querySelector("#"+o.element.id+"_upperCanvas"),this.upperContext=o.upperCanvas.getContext("2d"),this.fhdObj.time=(new Date).getTime(),this.isFreehandDrawing=!0,"mousedown"===e.type?this.freehandDownPoint={x:e.clientX,y:e.clientY}:this.freehandDownPoint={x:e.touches[0].clientX,y:e.touches[0].clientY},this.isFreehandPointMoved=!1,O.EventHandler.add(t,"mousemove touchmove",this.freehandMoveHandler,this),{id:"pen_"+(this.currFHDIdx+1),type:v.ShapeType.FreehandDraw,startX:this.freehandDownPoint.x,startY:this.freehandDownPoint.y,strokeColor:o.activeObj.strokeSettings.strokeColor,strokeWidth:this.penStrokeWidth,points:null,index:o.objColl.length+o.freehandCounter+1});this.triggerShapeChanging({cancel:!1,action:"draw-start",previousShapeSettings:e,currentShapeSettings:e})},p.prototype.freehandUpHandler=function(e,t,o){var i=t.getBoundingClientRect(),r=this.parent,t=(O.EventHandler.remove(t,"mousemove touchmove",this.freehandMoveHandler),0===r.points.length&&("mouseup"===e.type?this.processPoint(e.clientX-i.left,e.clientY-i.top,!0,o):"touchend"===e.type&&e.changedTouches?this.processPoint(e.changedTouches[0].clientX-i.left,e.changedTouches[0].clientY-i.top,!0,o):this.isFreehandPointMoved||this.processPoint(this.freehandDownPoint.x-i.left,this.freehandDownPoint.y-i.top,!0,o)),o.closePath(),O.extend({},r.cropObj,{},!0)),e={currObj:{}},i=(r.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:e}}),e.currObj),o=(i.objColl=O.extend([],r.objColl,[],!0),i.pointColl=O.extend([],r.pointColl,[],!0),i.afterCropActions=O.extend([],r.afterCropActions,[],!0),{selPointColl:null}),e=(r.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:o}}),i.selPointColl=O.extend([],o.selPointColl,[],!0),r.freehandCounter),o=r.objColl.length+r.freehandCounter+1,e=(r.pointColl[e]={points:O.extend([],r.points),strokeColor:r.activeObj.strokeSettings.strokeColor,strokeWidth:this.penStrokeWidth,flipState:r.transform.currFlipState,id:"pen_"+(this.currFHDIdx+1),order:o},r.points=[],this.dummyPoints=[],this.selPointColl[e]={points:O.extend([],this.selPoints)},this.selPoints=[],this.pointCounter=0,r.freehandCounter++,this.isFreehandDrawing=!1,r.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"freehand-draw",previousObj:i,previousObjColl:i.objColl,previousPointColl:i.pointColl,previousSelPointColl:i.selPointColl,previousCropObj:t,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),{id:"pen_"+(this.currFHDIdx+1),type:v.ShapeType.FreehandDraw,startX:this.freehandDownPoint.x,startY:this.freehandDownPoint.y,strokeColor:r.activeObj.strokeSettings.strokeColor,strokeWidth:this.penStrokeWidth,points:r.pointColl[this.currFHDIdx].points,index:o});this.triggerShapeChanging({cancel:!1,action:"draw-end",previousShapeSettings:e,currentShapeSettings:e}),this.currFHDIdx++},p.prototype.freehandMoveHandler=function(e){this.isFreehandPointMoved=!0;var t,o=this.parent.upperCanvas.getBoundingClientRect(),e="mousemove"===e.type?(t=e.clientX-o.left,e.clientY-o.top):(t=e.touches[0].clientX-o.left,e.touches[0].clientY-o.top);this.isFreehandDrawing&&(this.upperContext.fillStyle=this.parent.activeObj.strokeSettings.strokeColor,this.processPoint(t,e,!1,this.upperContext))},p.prototype.processPoint=function(e,t,o,i){var r,n,a,s,l,p,h,d=this.parent,c=(this.point(e,t,(new Date).getTime()),!!(r=0<d.points.length&&d.points[d.points.length-1])&&this.distanceTo(r)<=5);this.selPoints.push({x:e,y:t,ratioX:(e-d.img.destLeft)/d.img.destWidth,ratioY:(t-d.img.destTop)/d.img.destHeight,time:this.fhdObj.time}),r&&c&&!o||(this.fhdObj.time=(new Date).getTime(),d.points.push({x:e,y:t,ratioX:(e-d.img.destLeft)/d.img.destWidth,ratioY:(t-d.img.destTop)/d.img.destHeight,time:this.fhdObj.time}),this.dummyPoints.push({x:e,y:t,ratioX:(e-d.img.destLeft)/d.img.destWidth,ratioY:(t-d.img.destTop)/d.img.destHeight,time:this.fhdObj.time}),2<this.dummyPoints.length&&(3===this.dummyPoints.length&&this.dummyPoints.unshift(this.dummyPoints[0]),r=this.dummyPoints[0],c=this.dummyPoints[1],d=this.dummyPoints[2],a=this.dummyPoints[3],n=this.calcCurveCP(r,c,d).controlPoint2,a=this.calcCurveCP(c,d,a).controlPoint1,s=this.dummyPoints[1],l=this.dummyPoints[2],p=.5,h=5,O.isNullOrUndefined(this.penStrokeWidth)||(p=h=this.penStrokeWidth),this.startDraw(i,n,a,s,l,p,h),this.pointCounter++,this.dummyPoints.shift()),o&&(n=a=s=l={x:e,y:t,time:(new Date).getTime()},p=.5,h=5,O.isNullOrUndefined(this.penStrokeWidth)||(p=h=this.penStrokeWidth),this.startDraw(i,n,a,s,l,p,h)))},p.prototype.calcCurveCP=function(e,t,o){var i=e.x-(t=t||e).x,r=e.y-t.y,n=t.x-(o=o||t).x,a=t.y-o.y,s=(e.x+t.x)/2,e=(e.y+t.y)/2,l=(t.x+o.x)/2,o=(t.y+o.y)/2,i=Math.sqrt(i*i+r*r),r=Math.sqrt(n*n+a*a),n=r/(i+r),a=l+(s-l)*n,i=o+(e-o)*n,r=t.x-a,n=t.y-i;return{controlPoint1:this.point(s+r,e+n,0),controlPoint2:this.point(l+r,o+n,0)}},p.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}},p.prototype.startDraw=function(e,t,o,i,r,n,a){var s=this.pointVelocity(i),n=(s=.7*s+(1-.7)*this.fhdObj.lastVelocity,Math.max(a/1.7,n));this.drawCurve(this.fhdObj.time,n,e,t,o,i,r,a),this.fhdObj.lastVelocity=s,this.fhdObj.time=n},p.prototype.pointVelocity=function(e){return this.fhdObj.time!==e.time?this.distanceTo(e)/(this.fhdObj.time-e.time):0},p.prototype.distanceTo=function(e){return Math.sqrt(Math.pow(this.fhdObj.pointX-e.x,2)+Math.pow(this.fhdObj.pointY-e.y,2))},p.prototype.drawCurve=function(e,t,o,i,r,n,a,s){var l,p,h,d,c,u,g,v,f=t-e,t=this.bezierLength(i,r,n,a),C=2*Math.ceil(t);for(o.beginPath(),l=0;l<C;l++)g=(v=(u=(c=1-(p=l/C))*c)*c)*n.x,g=(g=(g+=3*u*p*i.x)+3*c*(h=p*p)*r.x)+(d=h*p)*a.x,v=v*n.y,v=(v=(v+=3*u*p*i.y)+3*c*h*r.y)+d*a.y,u=Math.min(e+d*f,s),this.drawArc(g,v,u,o);o.closePath(),o.fill()},p.prototype.bezierLength=function(e,t,o,i){for(var r,n,a,s,l,p,h=0,d=0;d<=10;d++)r=this.bezierPoint(n=d/10,o.x,e.x,t.x,i.x),n=this.bezierPoint(n,o.y,e.y,t.y,i.y),0<d&&(l=r-a,p=n-s,h+=Math.sqrt(l*l+p*p)),a=r,s=n;return h},p.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},p.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))},p.prototype.freehandRedraw=function(e,t){var o=this.parent,i=e.filter;if(e.filter="none",t&&(o.pointColl[o.freehandCounter]={points:t,strokeColor:o.activeObj.strokeSettings.strokeColor,strokeWidth:this.penStrokeWidth,flipState:o.transform.currFlipState,id:"pen_"+(o.freehandCounter+1),order:o.objColl.length+o.freehandCounter+1},this.selPointColl[o.freehandCounter]=O.extend({},o.pointColl[o.freehandCounter],{},!0),o.freehandCounter++),0<o.freehandCounter){for(var r=0;r<o.freehandCounter;r++){o.points=O.extend([],o.pointColl[r].points),this.pointCounter=0;var n=o.points.length,a=void 0,s=void 0,l=void 0,p=void 0,h=void 0,d=void 0;0<n&&(e.fillStyle=o.pointColl[r].strokeColor,h=d=this.penStrokeWidth=o.pointColl[r].strokeWidth),1===n&&(a=s=l=p=o.points[0],this.startDraw(e,a,s,l,p,h,d));for(var c=0;c<n-3;c++)o.points[c+1]&&o.points[c+2]&&o.points[c+2]&&(a=this.calcCurveCP(o.points[c+0],o.points[c+1],o.points[c+2]).controlPoint2,s=this.calcCurveCP(o.points[c+1],o.points[c+2],o.points[c+3]).controlPoint1,l=0===c?o.points[c]:o.points[c+1],p=o.points[c+2],this.startDraw(e,a,s,l,p,h,d));e.closePath()}e===this.lowerContext&&(o.notify("draw",{prop:"applyFrame",value:{ctx:this.lowerContext,frame:o.frameObj.type,preventImg:!0}}),this.upperContext.clearRect(0,0,o.upperCanvas.width,o.upperCanvas.height))}e.filter=i},p.prototype.getSqPtFD=function(e,t){for(var o={startX:0,startY:0,endX:0,endY:0,width:0,height:0},i=O.extend([],this.selPointColl[e].points,[]),r=(this.parent.points=O.extend([],this.parent.pointColl[e].points),this.pointCounter=0,i.length),n=0;n<r;n++)0===o.startX&&0===o.startY&&0===o.endX&&0===o.endY?(o.startX=i[n].x,o.startY=i[n].y,o.endX=i[n].x,o.endY=i[n].y):(o.startX=Math.min(o.startX,i[n].x),o.startY=Math.min(o.startY,i[n].y),o.endX=Math.max(o.endX,i[n].x),o.endY=Math.max(o.endY,i[n].y));return o.startX-=this.penStrokeWidth,o.startY-=this.penStrokeWidth,o.endX+=this.penStrokeWidth,o.endY+=this.penStrokeWidth,o.width=o.endX-o.startX,o.height=o.endY-o.startY,t&&(t.activePoint=o),o},p.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"})},p.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},p.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})},p.prototype.selectFhd=function(e){var t=this.parent,o=O.extend({},this.tempFHDStyles,{},!0);if(t.notify("selection",{prop:"setFreehandDrawEditing",onPropertyChange:!1,value:{bool:!0}}),e||0===e){if(!this.isFHDIdx(e))return;this.fhdSelIdx=this.fhdHovIdx=e,this.hoverFhd(),t.upperCanvas.style.cursor=t.cursor="pointer"}this.fhdSelIdx=this.fhdHovIdx;var e=t.pointColl[this.fhdSelIdx],i=(e.isSelected=!0,this.fhdSelID=e.id,"#42a5f5"!==e.strokeColor&&(t.activeObj.strokeSettings.strokeColor=this.tempFHDStyles.strokeColor=e.strokeColor),t.activeObj.strokeSettings.strokeWidth=this.tempFHDStyles.strokeWidth=t.pointColl[this.fhdHovIdx].strokeWidth,{bool:!1});t.notify("selection",{prop:"getFreehandDrawEditing",onPropertyChange:!1,value:{obj:i}}),i.bool?(i={id:"pen_"+(this.fhdSelIdx+1),type:v.ShapeType.FreehandDraw,startX:e.points[0].x,startY:e.points[0].y,strokeColor:e.strokeColor,strokeWidth:e.strokeWidth,points:e.points,opacity:e.opacity,index:e.order},this.triggerShapeChanging({cancel:!1,action:"select",previousShapeSettings:i,currentShapeSettings:i})):t.okBtn(null,!0),t.isUndoRedoStack&&(this.tempFHDStyles=o)},p.prototype.deleteFhd=function(e,t){var o=this.parent;if(this.isFHDIdx(e)){this.upperContext.clearRect(0,0,o.upperCanvas.width,o.upperCanvas.height);var i=O.extend({},o.pointColl,{},!0),r=O.extend({},this.selPointColl,{},!0),n=(o.pointColl={},this.selPointColl={},0);if(O.isNullOrUndefined(t))for(var a=0;a<o.freehandCounter;a++)a!==e&&(o.pointColl[n]=i[a],this.selPointColl[n]=r[a],n++);else for(a=0;a<o.freehandCounter;a++)parseInt(i[a].id.split("_")[1],10)-1!==e&&(o.pointColl[n]=i[a],this.selPointColl[n]=r[a],n++);--o.freehandCounter,this.fhdHovIdx=this.fhdSelIdx=null,o.notify("selection",{prop:"resetFreehandDrawVariables"}),o.notify("draw",{prop:"render-image",value:{isMouseWheel:null}}),o.notify("toolbar",{prop:"refresh-main-toolbar",onPropertyChange:!1})}},p.prototype.zoomX=function(e){return e*this.parent.img.destWidth+this.parent.img.destLeft},p.prototype.zoomY=function(e){return e*this.parent.img.destHeight+this.parent.img.destTop},p.prototype.zoomFHDColl=function(e){var t=this.parent,o={startX:t.img.destLeft,startY:t.img.destTop,width:t.img.destWidth,height:t.img.destHeight};t.notify("shape",{prop:"straightenShapes",onPropertyChange:!1});for(var i=0;i<t.freehandCounter;i++){t.points=O.extend([],t.pointColl[i].points,[]),this.pointCounter=0;for(var r=t.points.length,n=0;n<r;n++){var a=t.points[n];a.x=this.zoomX(a.ratioX),a.y=this.zoomY(a.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!==t.transform.straighten&&t.notify("shape",{prop:"straightenFHD",onPropertyChange:!1}),t.img.destLeft=o.startX,t.img.destTop=o.startY,t.img.destWidth=o.width,t.img.destHeight=o.height,O.isNullOrUndefined(e)&&this.freehandRedraw(this.lowerContext,null)},p.prototype.updateFHDCurPts=function(){for(var e=this.parent,t=0;t<e.freehandCounter;t++)if(this.selPointColl[t]){this.selPoints=O.extend([],this.selPointColl[t].points,[]),this.pointCounter=0;for(var o=this.selPoints.length,i=0;i<o;i++){var r=this.selPoints[i];r.x=this.zoomX(r.ratioX),r.y=this.zoomY(r.ratioY)}}},p.prototype.rotateFhdColl=function(){for(var e=this.parent,t=e.img,o=t.destLeft,i=t.destTop,r=t.destWidth,n=t.destHeight,a=0;a<e.freehandCounter;a++){e.points=O.extend([],e.pointColl[a].points,[]),this.pointCounter=0;for(var s=e.points.length,l=0;l<s;l++)(p=e.points[l]).y=i+n*p.ratioX,p.x=o+r-r*p.ratioY,p.ratioX=(p.x-o)/r,p.ratioY=(p.y-i)/n}for(a=0;a<e.freehandCounter;a++)if(this.selPointColl[a]){this.selPoints=O.extend([],this.selPointColl[a].points,[]),this.pointCounter=0;for(var p,s=this.selPoints.length,l=0;l<s;l++)(p=this.selPoints[l]).y=i+n*p.ratioX,p.x=o+r-r*p.ratioY,p.ratioX=(p.x-o)/r,p.ratioY=(p.y-i)/n}this.updateFHDCurPts()},p.prototype.flipFHDColl=function(e){e=e.toLowerCase();if("horizontal"===e)this.pointsHorizontalFlip();else{if("vertical"!==e){this.pointsHorizontalFlip();for(var t=0;t<this.parent.freehandCounter;t++)this.parent.pointColl[t].shapeFlip=""}this.pointsVerticalFlip()}},p.prototype.pointsHorizontalFlip=function(){for(var e=this.parent,t=e.img,o=t.destLeft,i=t.destTop,r=t.destWidth,n=t.destHeight,a=0;a<e.freehandCounter;a++)if(e.pointColl[a].shapeFlip!==e.transform.currFlipState){e.points=O.extend([],e.pointColl[a].points,[]),this.pointCounter=0;for(var s=e.points.length,l=0;l<s;l++)(p=e.points[l]).x<=o+r/2?p.x=o+r-(p.x-o):p.x>=o+r/2&&(p.x=o+(o+r-p.x)),p.ratioX=(p.x-o)/r,p.ratioY=(p.y-i)/n;e.pointColl[a].shapeFlip=e.transform.currFlipState}for(a=0;a<e.freehandCounter;a++)if(this.selPointColl[a]&&this.selPointColl[a].shapeFlip!==e.transform.currFlipState){this.selPoints=O.extend([],this.selPointColl[a].points,[]),this.pointCounter=0;for(var p,s=this.selPoints.length,l=0;l<s;l++)(p=this.selPoints[l]).x<=o+r/2?p.x=o+r-(p.x-o):p.x>=o+r/2&&(p.x=o+(o+r-p.x)),p.ratioX=(p.x-o)/r,p.ratioY=(p.y-i)/n}this.updateFHDCurPts()},p.prototype.pointsVerticalFlip=function(){for(var e=this.parent,t=e.img,o=t.destLeft,i=t.destTop,r=t.destWidth,n=t.destHeight,a=0;a<e.freehandCounter;a++)if(e.pointColl[a].shapeFlip!==e.transform.currFlipState){e.points=O.extend([],e.pointColl[a].points,[]),this.pointCounter=0;for(var s=e.points.length,l=0;l<s;l++)(p=e.points[l]).y<=i+n/2?p.y=i+n-(p.y-i):p.y>=i+n/2&&(p.y=i+(i+n-p.y)),p.ratioX=(p.x-o)/r,p.ratioY=(p.y-i)/n;e.pointColl[a].shapeFlip=e.transform.currFlipState}for(a=0;a<e.freehandCounter;a++)if(this.selPointColl[a]&&this.selPointColl[a].shapeFlip!==e.transform.currFlipState){this.selPoints=O.extend([],this.selPointColl[a].points,[]),this.pointCounter=0;for(var p,s=this.selPoints.length,l=0;l<s;l++)(p=this.selPoints[l]).y<=i+n/2?p.y=i+n-(p.y-i):p.y>=i+n/2&&(p.y=i+(i+n-p.y)),p.ratioX=(p.x-o)/r,p.ratioY=(p.y-i)/n}this.updateFHDCurPts()},p.prototype.updateFHDColl=function(e){for(var t=this.parent,o={startX:t.img.destLeft,startY:t.img.destTop,width:t.img.destWidth,height:t.img.destHeight},i=(t.notify("shape",{prop:"straightenShapes",onPropertyChange:!1}),t.img),r=i.destLeft,n=i.destTop,a=i.destWidth,s=i.destHeight,l=0,p=t.objColl.length;l<p;l++){var h,d=t.objColl[l];if("line"===d.shape||"arrow"===d.shape?t.notify("shape",{prop:"straightenShapePoints",value:{obj:d,isReverse:!0}}):"path"===d.shape&&(h=t.transform.straighten,t.transform.straighten=-t.transform.straighten,t.notify("shape",{prop:"straightenPath",onPropertyChange:!1,value:{obj:d}}),t.transform.straighten=h),d.imageRatio={startX:(d.activePoint.startX-r)/a,startY:(d.activePoint.startY-n)/s,endX:(d.activePoint.endX-r)/a,endY:(d.activePoint.endY-n)/s,width:a/d.activePoint.width,height:s/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-r)/a,d.pointColl[c].ratioY=(d.pointColl[c].y-n)/s;t.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1})}0<t.freehandCounter&&0!==t.transform.straighten&&(h=t.transform.straighten,t.transform.straighten=-t.transform.straighten,t.notify("shape",{prop:"straightenFHD",onPropertyChange:!1}),t.transform.straighten=h);for(var g=0;g<t.freehandCounter;g++){t.points=O.extend([],t.pointColl[g].points,[]),this.pointCounter=0;for(var v=t.points.length,f=0;f<v;f++)(C=t.points[f]).ratioX=(C.x-r)/a,C.ratioY=(C.y-n)/s}for(g=0;g<t.freehandCounter;g++)if(this.selPointColl[g]){this.selPoints=O.extend([],this.selPointColl[g].points,[]),this.pointCounter=0;for(var C,v=this.selPoints.length,f=0;f<v;f++)(C=this.selPoints[f]).ratioX=(C.x-r)/a,C.ratioY=(C.y-n)/s}this.straightenPoint.x&&this.straightenPoint.y&&(this.straightenPoint.ratioX=(this.straightenPoint.x-r)/a,this.straightenPoint.ratioY=(this.straightenPoint.y-n)/s),t.img.destLeft=o.startX,t.img.destTop=o.startY,t.img.destWidth=o.width,t.img.destHeight=o.height,t.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"zoom",pen:"zoom",isPreventApply:e}})},p.prototype.panFHDColl=function(e,t,o){for(var i=this.parent,r=0;r<i.freehandCounter;r++){i.points=O.extend([],i.pointColl[r].points,[]),this.pointCounter=0;for(var n=i.points.length,a=0;a<n;a++){var s=i.points[a];""===o||"vertical"===o?s.x+=e:s.x-=e,""===o||"horizontal"===o?s.y+=t:s.y-=t}}for(r=0;r<i.freehandCounter;r++)if(this.selPointColl[r]){this.selPoints=O.extend([],this.selPointColl[r].points,[]),this.pointCounter=0;for(n=this.selPoints.length,a=0;a<n;a++){s=this.selPoints[a];""===o||"vertical"===o?s.x+=e:s.x-=e,""===o||"horizontal"===o?s.y+=t:s.y-=t}}this.straightenPoint.x&&this.straightenPoint.y&&(""===o||"vertical"===o?this.straightenPoint.x+=e:this.straightenPoint.x-=e,""===o||"horizontal"===o?this.straightenPoint.y+=t:this.straightenPoint.y-=t),this.freehandRedraw(this.lowerContext,null)},p.prototype.freeHandDraw=function(e){var t=this.parent;e?(t.points=[],this.dummyPoints=[],t.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),t.togglePen=!0,t.upperCanvas.style.cursor=t.cursor="crosshair",t.upperCanvas.style.display="block",O.isNullOrUndefined(t.activeObj.strokeSettings)&&(t.notify("shape",{prop:"getStrokeSettings",onPropertyChange:!(e={strokeSettings:{}}),value:{obj:e}}),t.activeObj.strokeSettings=e.strokeSettings),O.isNullOrUndefined(t.activeObj.strokeSettings.strokeWidth)&&(t.activeObj.strokeSettings.strokeWidth=2),t.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"pen",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}})):(t.upperCanvas.style.cursor=t.cursor="default",e=this.penStrokeWidth,t.notify("shape",{prop:"apply",onPropertyChange:!1,value:{shape:null,obj:null,canvas:null}}),t.notify("toolbar",{prop:"refresh-main-toolbar",onPropertyChange:!1}),t.notify("toolbar",{prop:"setCurrentToolbar",value:{type:"main"}}),t.notify("selection",{prop:"setFreehandDrawCustomized",value:{isFreehandDrawCustomized:!1}}),this.penStrokeWidth=e)},p.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},p.prototype.updateCropPtsForSel=function(){for(var e=this.parent,t=e.activeObj.activePoint,o=0;o<e.freehandCounter;o++){var i={selPointColl:O.extend([],this.selPointColl)};if(i.selPointColl[o]){this.selPoints=O.extend([],i.selPointColl[o].points,[]),this.pointCounter=0;for(var r=this.selPoints.length,n=0;n<r;n++){var a=this.selPoints[n];a.ratioX=(a.x-t.startX)/t.width,a.ratioY=(a.y-t.startY)/t.height}}}},p.prototype.triggerShapeChanging=function(e){var t,o=this.parent,i=o.pointColl[this.fhdSelIdx];o.trigger("shapeChanging",e),-1!==e.currentShapeSettings.id.indexOf("pen_")||"draw-end"!==e.action&&"select"!==e.action||(t="pen_"+e.currentShapeSettings.id,this.fhdSelIdx?o.pointColl[this.fhdSelIdx].id=t:o.pointColl[o.freehandCounter-1].id=t),this.penStrokeWidth=e.currentShapeSettings.strokeWidth,o.activeObj.strokeSettings.strokeColor!==e.currentShapeSettings.strokeColor&&(o.activeObj.strokeSettings.strokeColor=e.currentShapeSettings.strokeColor,o.notify("toolbar",{prop:"update-toolbar-items",onPropertyChange:!1})),this.fhdSelID&&i&&e.currentShapeSettings&&(i.strokeColor=e.currentShapeSettings.strokeColor,i.strokeWidth=e.currentShapeSettings.strokeWidth,i.points=e.currentShapeSettings.points,i.opacity=e.currentShapeSettings.opacity),"select"===e.action&&(this.freehandRedraw(this.upperContext),o.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"pen",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}}))},p.prototype.setCenterSelPoints=function(){var e=this.parent,t={startX:e.img.destLeft,startY:e.img.destTop,width:e.img.destWidth,height:e.img.destHeight},o=(e.notify("shape",{prop:"straightenShapes",onPropertyChange:!1}),e.img),i=o.destLeft,r=o.destTop,n=o.destWidth,o=o.destHeight,a=e.activeObj.activePoint;!O.isNullOrUndefined(this.prevStraightenObj)&&JSON.stringify(this.prevStraightenObj.activePoint)===JSON.stringify(a)||(this.straightenPoint={x:a.startX+a.width/2,y:a.startY+a.height/2,ratioX:(a.startX+a.width/2-i)/n,ratioY:(a.startY+a.height/2-r)/o},this.prevStraightenObj=O.extend({},e.activeObj,{},!0),this.straightenPointAngle=e.transform.straighten),e.img.destLeft=t.startX,e.img.destTop=t.startY,e.img.destWidth=t.width,e.img.destHeight=t.height};var l=p;function p(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()}c.prototype.destroy=function(){this.parent.isDestroyed||this.removeEventListener()},c.prototype.addEventListener=function(){this.parent.on("selection",this.selection,this),this.parent.on("destroyed",this.destroy,this)},c.prototype.removeEventListener=function(){this.parent.off("selection",this.selection),this.parent.off("destroyed",this.destroy)},c.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)}},c.prototype.getModuleName=function(){return"selection"},c.prototype.updatePrivateVariables=function(){var e=this.parent;e.lowerCanvas&&(this.lowerContext=e.lowerCanvas.getContext("2d")),e.upperCanvas&&(this.upperContext=e.upperCanvas.getContext("2d"))},c.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=[v.ArrowheadType.None,v.ArrowheadType.SolidArrow]},c.prototype.performTabAction=function(){var e,t=this.parent;"block"!==t.textArea.style.display&&"inline-block"!==t.textArea.style.display||(e=this.applyCurrShape(!1),t.notify("shape",{prop:"redrawActObj",onPropertyChange:!1,value:{x:null,y:null,isMouseDown:null}}),e&&t.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"ok"}}))},c.prototype.selMouseUpEvent=function(){this.oldPoint.x=void 0,this.oldPoint.y=void 0},c.prototype.getMouseCursor=function(e,t,o,i,r){var n=this.getTransRotationPoint(e),a=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":n&&!r&&t>=n.x-(a+2)&&t<=n.x+(a+2)&&o>=n.y-(a+2)&&o<=n.y+(a+2)?"grabbing":"default"},c.prototype.setCursor=function(e,t){var o=this.parent,i=(o.upperCanvas.style.cursor=o.cursor="default",{bool:null});if(o.notify("toolbar",{prop:"getFrameToolbar",onPropertyChange:!1,value:{obj:i}}),o.isResize||this.isSliding||i.bool)o.upperCanvas.style.cursor="default";else if(o.currObjType.isDragging)""===this.dragElement?o.upperCanvas.style.cursor=o.cursor="move":o.upperCanvas.style.cursor=o.cursor=this.dragElement;else if(o.togglePen)o.upperCanvas.style.cursor=o.cursor="crosshair";else{if(o.activeObj.shape&&this.setCursorForActObj(void 0,!1,e,t),"default"===o.cursor||"grab"===o.cursor){for(var r=this.getHighestOrder(),n=O.extend([],o.shapeColl,[],!0),i=O.extend([],o.objColl,[],!0),a=!1;0<r;){a=!1;for(var s,l=n.length-1;0<=l;l--)n[l].order===r?(a=!0,n[l].id&&-1<n[l].id.indexOf("pen")?o.pointColl[0]&&(o.cursor,1)&&!o.currObjType.isDragging&&!o.currObjType.isResize&&(s=O.extend([],o.points,[],!0),this.setCursorForFreehandDrawing(e,t,o.upperCanvas,n[l].id),o.points=s):(o.objColl=[],o.objColl.push(O.extend({},n[l],null,!0)),s=o.upperCanvas.style.cursor,0<o.objColl.length&&(o.cursor,1)&&this.setCursorFromObj(e,t,o.objColl,o.upperCanvas,!1),"grab"===s&&"default"===o.cursor&&(o.upperCanvas.style.cursor=o.cursor="grab"))):O.isNullOrUndefined(n[l].order)&&(a=!0);if("default"!==o.cursor&&"grab"!==o.cursor)break;if(a)for(var p=!1;!p&&0<r;){for(var h=0;h<n.length;h++)if(n[h].order===r-1){p=!0;break}r--,p||r--}}o.objColl=i,"default"!==o.cursor&&"grab"!==o.cursor||o.togglePan&&(o.lowerCanvas.style.cursor=o.upperCanvas.style.cursor=o.cursor="grab")}""===this.currentDrawingShape||"default"!==o.cursor&&"grab"!==o.cursor||(o.upperCanvas.style.cursor=o.cursor="crosshair")}},c.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},c.prototype.setCursorForActObj=function(e,t,o,i){var r,n=this.parent;void 0!==n.activeObj.horTopLine?(!(t=void 0===(e=void 0!==n.activeObj.shape?n.activeObj.shape.split("-"):e)&&n.currObjType.isCustomCrop||void 0!==e&&"crop"===e[0]?!0:t)&&n.togglePan&&(n.lowerCanvas.style.cursor=n.upperCanvas.style.cursor=n.cursor="grab"),e=n.upperCanvas.style.cursor,r=O.extend({},n.activeObj,{},!0),this.cursorTargetId=r.currIndex,0===r.shapeDegree?n.transform.degree:(n.transform.degree,r.shapeDegree),"line"===r.shape||"arrow"===r.shape?this.setCursorForLineArrow(r,o,i,n.upperCanvas):"path"===r.shape?this.setCursorForPath(r,o,i,n.upperCanvas):O.isNullOrUndefined(r.rotatedAngle)||0===r.rotatedAngle?(n.upperCanvas.style.cursor=n.cursor=this.getMouseCursor(r,o,i,t,!1),"text"===r.shape&&-1<["n-resize","s-resize","e-resize","w-resize"].indexOf(n.cursor)&&(n.upperCanvas.style.cursor=n.cursor="move")):this.setCursorForRotatedObject(r,o,i,n.upperCanvas),"default"===e&&"default"===n.cursor&&t&&(n.upperCanvas.style.cursor=n.cursor="grab"),"grab"===e&&"default"===n.cursor&&(n.upperCanvas.style.cursor=n.cursor="grab")):n.togglePan&&!n.togglePen?n.lowerCanvas.style.cursor=n.upperCanvas.style.cursor=n.cursor="grab":n.currObjType.isCustomCrop||n.togglePen?n.upperCanvas.style.cursor=n.cursor="crosshair":n.upperCanvas.style.cursor=n.cursor="default"},c.prototype.setCursorForPath=function(e,t,o,i){this.setCursorForLineArrow(e,t,o,i);var r=this.parent;if("default"===r.cursor)for(var n=O.extend({},e,null,!0),a=!1,s=1,l=e.pointColl.length;s<l&&!a;s++){n.activePoint.startX=e.pointColl[s-1].x,n.activePoint.startY=e.pointColl[s-1].y,n.activePoint.endX=e.pointColl[s].x,n.activePoint.endY=e.pointColl[s].y,r.notify("shape",{prop:"setPointCollForLineArrow",onPropertyChange:!1,value:{obj:n}});for(var p=e.topLeftCircle.radius,h=0,d=n.pointColl.length;h<d;h++){var c=n.pointColl[h];if(!O.isNullOrUndefined(c.x-2*p)&&!O.isNullOrUndefined(c.x+2*p)&&!O.isNullOrUndefined(c.y-2*p)&&!O.isNullOrUndefined(c.y+2*p)&&t>=c.x-2*p&&t<=c.x+2*p&&o>=c.y-2*p&&o<=c.y+2*p){i.style.cursor=r.cursor="move",a=!0;break}i.style.cursor=r.cursor="default"}}return r.cursor},c.prototype.setCursorForLineArrow=function(e,t,o,i){var r,n=e.topLeftCircle.radius;if(!O.isNullOrUndefined(e.pointColl))for(var a=0,s=e.pointColl.length;a<s;a++){var l=e.pointColl[a];if(t>=l.x-2*n&&t<=l.x+2*n&&o>=l.y-2*n&&o<=l.y+2*n){i.style.cursor=this.parent.cursor="move",r=a;break}i.style.cursor=this.parent.cursor="default"}return r},c.prototype.setCursorForRotatedObject=function(e,t,o,i){this.resizedElement="";var r=this.parent,n=e.bottomCenterCircle.radius,a=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],g=e.horBottomLinePointColl[0];if(t>=u.x-(n+2)&&t<=u.x+(n+2)&&o>=u.y-(n+2)&&o<=u.y+(n+2)?i.style.cursor=r.cursor="nw-resize":t>=a.x-5&&t<=a.x+5&&o>=a.y-5&&o<=a.y+5?i.style.cursor=r.cursor=this.resizedElement="n-resize":t>=s.x-(n+2)&&t<=s.x+(n+2)&&o>=s.y-(n+2)&&o<=s.y+(n+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>=g.x-(n+2)&&t<=g.x+(n+2)&&o>=g.y-(n+2)&&o<=g.y+(n+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-(n+2)&&t<=d.x+(n+2)&&o>=d.y-(n+2)&&o<=d.y+(n+2)?i.style.cursor=r.cursor="se-resize":c&&t>=c.x-(n+2)&&t<=c.x+(n+2)&&o>=c.y-(n+2)&&o<=c.y+(n+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 v=0,f=e.horTopLinePointColl.length;v<f;v++){var C=e.horTopLinePointColl[v];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(v=0,f=e.horBottomLinePointColl.length;v<f;v++){var b=e.horBottomLinePointColl[v];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(v=0,f=e.verLeftLinePointColl.length;v<f;v++){var m=e.verLeftLinePointColl[v];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(v=0,f=e.verRightLinePointColl.length;v<f;v++){var y=e.verRightLinePointColl[v];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},c.prototype.adjustCursorStylesForRotatedState=function(e){var t=this.parent,o=e.rotatedAngle*(180/Math.PI);return(92<=(o=0<o?Math.floor(o):Math.ceil(o))&&o<=182||-178<=o&&o<=-88)&&t.cursor in(o={"nw-resize":"ne-resize","n-resize":"s-resize","ne-resize":"nw-resize","w-resize":"e-resize","e-resize":"w-resize","sw-resize":"se-resize","s-resize":"n-resize","se-resize":"sw-resize"})&&(t.cursor=o[t.cursor]),t.upperCanvas.style.cursor=this.getResizeElement(e.rotatedAngle*(180/Math.PI),t.cursor),t.cursor},c.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,n=o;r<n.length;r++){var a=n[r],s=a[0],l=a[1],a=a[2];if(s<i&&i<=l||s<i+360&&i+360<=l)return a}return t},c.prototype.setCursorForFreehandDrawing=function(e,t,o,i){var r,n=o.getContext("2d"),a=this.parent,s=document.querySelector("#"+a.element.id+"_textArea"),l=!1;a.notify("freehand-draw",{prop:"setFreehandDrawHoveredIndex",onPropertyChange:!1,value:{index:-1}});for(var p=0;p<a.freehandCounter;p++)if(!i||i===a.pointColl[p].id){for(var h={selPointColl:{}},d=(a.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:h}}),r=O.extend([],h.selPointColl[p].points,[]),a.points=O.extend([],a.pointColl[p].points,[]),a.pointColl[p]),c=(a.notify("freehand-draw",{prop:"setPointCounter",onPropertyChange:!1,value:{value:0}}),r.length),u=0;u<c;u++)if(0!==u){var g=!1;if(g=r[u-1]&&r[u]?this.isInside(e,t,r[u-1].x,r[u-1].y,r[u].x,r[u].y):g){this.isFhdPoint=!0,a.notify("freehand-draw",{prop:"setFreehandDrawHoveredIndex",onPropertyChange:!1,value:{index:p}}),a.notify("freehand-draw",{prop:"hoverFhd",onPropertyChange:!1,value:{strokeColor:null,strokeWidth:null}}),o.style.cursor=a.cursor="pointer",l=!0;break}this.isFhdEditing&&!d.isSelected||((this.isFhdPoint||this.isFhdEditing)&&(n.clearRect(0,0,o.width,o.height),a.activeObj.shape)&&"none"===s.style.display&&a.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate",obj:a.activeObj}}),this.isFhdEditing?(a.notify("freehand-draw",{prop:"getFreehandSelectedIndex",onPropertyChange:!(v={freehandSelectedIndex:-1}),value:{obj:v}}),f=a.pointColl[v.freehandSelectedIndex].strokeColor,C=a.pointColl[v.freehandSelectedIndex].strokeWidth,a.notify("freehand-draw",{prop:"hoverFhd",onPropertyChange:!1,value:{strokeColor:f,strokeWidth:C}})):a.notify("freehand-draw",{prop:"setFreehandDrawHoveredIndex",onPropertyChange:!1,value:{index:null}}),this.isFhdPoint=!1)}else{var v,f,C,g=a.points[u];if(e>g.x-d.strokeWidth&&e<g.x+d.strokeWidth&&t>g.y-d.strokeWidth&&t<g.y+d.strokeWidth){this.isFhdPoint=!0,a.notify("freehand-draw",{prop:"setFreehandDrawHoveredIndex",onPropertyChange:!1,value:{index:p}}),a.notify("freehand-draw",{prop:"hoverFhd",onPropertyChange:!1,value:{strokeColor:null,strokeWidth:null}}),o.style.cursor=a.cursor="pointer",l=!0;break}this.isFhdEditing&&!d.isSelected||((this.isFhdPoint||this.isFhdEditing)&&(n.clearRect(0,0,o.width,o.height),a.activeObj.shape)&&"none"===s.style.display&&a.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate",obj:a.activeObj}}),this.isFhdEditing&&(a.notify("freehand-draw",{prop:"getFreehandSelectedIndex",onPropertyChange:!(v={freehandSelectedIndex:-1}),value:{obj:v}}),f=a.pointColl[v.freehandSelectedIndex].strokeColor,C=a.pointColl[v.freehandSelectedIndex].strokeWidth,a.notify("freehand-draw",{prop:"hoverFhd",onPropertyChange:!1,value:{strokeColor:f,strokeWidth:C}})),this.isFhdPoint=!1)}if(l)break}},c.prototype.setCursorFromObj=function(e,t,o,i,r){for(var n=this.parent,a=0,s=o.length;a<s;a++){if("move"===n.cursor)return;var l=O.extend({},o[a],{},!0);this.cursorTargetId=l.currIndex,"line"===l.shape||"arrow"===l.shape?this.setCursorForLineArrow(l,e,t,i):"path"===l.shape?this.setCursorForPath(l,e,t,i):O.isNullOrUndefined(l.rotatedAngle)||0===l.rotatedAngle?i.style.cursor=n.cursor=this.getMouseCursor(l,e,t,r,!0):this.setCursorForRotatedObject(l,e,t,i)}},c.prototype.isInside=function(e,t,o,i,r,n){var a=Math.min(o,r),o=Math.max(o,r),r=Math.min(i,n),i=Math.max(i,n);return a<=e&&e<=o&&r<=t&&t<=i},c.prototype.updateActivePoint=function(e,t,o){var i,r,n=this.parent,a=n.activeObj.activePoint,s=a.startX,l=a.startY,a=(a.endX,a.endY,n.activeObj.activePoint),p=a.width,h=a.height,a=(n.notify("transform",{prop:"calcMaxDimension",onPropertyChange:!1,value:{width:p,height:h,obj:{width:0,height:0},isImgShape:null}}),this.updatePrevShapeSettings()),d={cancel:!1,action:"resize",previousShapeSettings:a},c={cancel:!1,action:"move",previousShapeSettings:a},u=(this.shapeResizingArgs=d,this.shapeMovingArgs=c,"text"===n.activeObj.shape&&""!==this.dragElement&&n.notify("shape",{prop:"updateFontRatio",onPropertyChange:!1,value:{obj:n.activeObj,isTextArea:null}}),""===this.currentDrawingShape||""!==this.dragElement&&"move"!==this.dragElement||!n.isShapeDrawing||(-1<["line","arrow","path"].indexOf(n.activeObj.shape)?this.dragElement="e-resize":s<e&&l<t?this.dragElement="se-resize":e<s&&l<t?this.dragElement="sw-resize":s<e&&t<l?this.dragElement="ne-resize":e<s&&t<l&&(this.dragElement="nw-resize")),"arrow"===n.activeObj.shape&&(0<Math.atan2(e-n.lowerCanvas.width/2,t-n.lowerCanvas.height/2)?n.activeObj.rotatedAngle=-Math.atan2(e-n.lowerCanvas.width/2,t-n.lowerCanvas.height/2):n.activeObj.rotatedAngle=Math.abs(Math.atan2(e-n.lowerCanvas.width/2,t-n.lowerCanvas.height/2))),!1),g=!1;if(!o||0===n.transform.straighten||!this.isMouseOutsideImg(e,t))switch(this.dragElement.toLowerCase()){case"nw-resize":this.updateNWPoints(e,t),n.notify("shape",{prop:"updateArrowDirection",onPropertyChange:!1,value:{obj:n.activeObj,flip:null,rotatedDegree:null}}),this.triggerShapeChange(d,c,"resize");break;case"n-resize":this.updateNPoints(e,t),n.notify("shape",{prop:"updateArrowDirection",onPropertyChange:!1,value:{obj:n.activeObj,flip:null,rotatedDegree:null}}),this.triggerShapeChange(d,c,"resize");break;case"ne-resize":this.updateNEPoints(e,t),n.notify("shape",{prop:"updateArrowDirection",onPropertyChange:!1,value:{obj:n.activeObj,flip:null,rotatedDegree:null}}),this.triggerShapeChange(d,c,"resize");break;case"w-resize":this.updateWPoints(e,t),n.notify("shape",{prop:"updateArrowDirection",onPropertyChange:!1,value:{obj:n.activeObj,flip:null,rotatedDegree:null}}),this.triggerShapeChange(d,c,"resize");break;case"e-resize":this.updateEPoints(e,t),n.notify("shape",{prop:"updateArrowDirection",onPropertyChange:!1,value:{obj:n.activeObj,flip:null,rotatedDegree:null}}),this.triggerShapeChange(d,c,"resize");break;case"sw-resize":this.updateSWPoints(e,t),n.notify("shape",{prop:"updateArrowDirection",onPropertyChange:!1,value:{obj:n.activeObj,flip:null,rotatedDegree:null}}),this.triggerShapeChange(d,c,"resize");break;case"s-resize":this.updateSPoints(e,t),n.notify("shape",{prop:"updateArrowDirection",onPropertyChange:!1,value:{obj:n.activeObj,flip:null,rotatedDegree:null}}),this.triggerShapeChange(d,c,"resize");break;case"se-resize":this.updateSEPoints(e,t),n.notify("shape",{prop:"updateArrowDirection",onPropertyChange:!1,value:{obj:n.activeObj,flip:null,rotatedDegree:null}}),this.triggerShapeChange(d,c,"resize");break;case"grabbing":0<Math.atan2(e-(s+p/2),t-(l+h/2))?n.activeObj.rotatedAngle=-Math.atan2(e-(s+p/2),t-(l+h/2)):n.activeObj.rotatedAngle=Math.abs(Math.atan2(e-(s+p/2),t-(l+h/2))),(C=0===n.activeObj.shapeDegree?n.transform.degree:n.transform.degree-n.activeObj.shapeDegree)<0&&(C=360+C);for(var v=0,f=n.activeObj.flipObjColl.length;v<f;v++)"horizontal"===n.activeObj.flipObjColl[v].toLowerCase()?u=!0:"vertical"===n.activeObj.flipObjColl[v].toLowerCase()&&(g=!0);n.activeObj.rotatedAngle-=C*(Math.PI/180),0===C||360===C?g&&(n.activeObj.rotatedAngle-=Math.PI/180*180):90===C||-270===C?u&&(n.activeObj.rotatedAngle-=Math.PI/180*180):180===C||-180===C?g&&(n.activeObj.rotatedAngle-=Math.PI/180*180):270!==C&&-90!==C||u&&(n.activeObj.rotatedAngle-=Math.PI/180*180);break;case"pathdrag":O.isNullOrUndefined(this.pathAdjustedIndex)||(n.activeObj.pointColl[this.pathAdjustedIndex].x=e,n.activeObj.pointColl[this.pathAdjustedIndex].y=t);break;default:if(!o&&!n.currObjType.isCustomCrop){var C=n.activeObj.activePoint;if(this.dragPoint.startX){var b=this.dragPoint.endX-this.previousPoint.x,m=this.dragPoint.endY-this.previousPoint.y;if(C.startX+=b,C.endX+=b,C.startY+=m,C.endY+=m,s=C.startX,l=C.startY,i=C.endX,r=C.endY,"line"!==n.activeObj.shape&&"arrow"!==n.activeObj.shape&&n.activeObj.rotationCirclePointColl&&(n.activeObj.rotationCirclePointColl.x+=b,n.activeObj.rotationCirclePointColl.y+=m,n.activeObj.rotationCirclePoint.x+=b,n.activeObj.rotationCirclePoint.y+=m),"path"===n.activeObj.shape)for(v=0,f=n.activeObj.pointColl.length;v<f;v++)n.activeObj.pointColl[v].x+=b,n.activeObj.pointColl[v].y+=m;!this.isPreventDragging&&"line"!==n.activeObj.shape&&0===n.activeObj.rotatedAngle&&(s<n.img.destLeft||l<n.img.destTop||i>n.img.destLeft+n.img.destWidth||r>n.img.destTop+n.img.destHeight)&&(C.startX-=b,C.endX-=b,C.startY-=m,C.endY-=m,"line"!==n.activeObj.shape&&"arrow"!==n.activeObj.shape&&n.activeObj.rotationCirclePointColl&&(n.activeObj.rotationCirclePointColl.x-=b,n.activeObj.rotationCirclePointColl.y-=m,n.activeObj.rotationCirclePoint.x-=b,n.activeObj.rotationCirclePoint.y-=m),this.setDragWidth(b),this.setDragHeight(m))}else C.startX=e<this.mouseDownPoint.x?e:this.mouseDownPoint.x,C.startY=t<this.mouseDownPoint.y?t:this.mouseDownPoint.y,e=e<this.mouseDownPoint.x?this.mouseDownPoint.x:e,t=t<this.mouseDownPoint.y?this.mouseDownPoint.y:t,C.endX=e,C.endY=t;this.triggerShapeChange(d,c,"move")}}},c.prototype.triggerShapeChange=function(e,t,o){var i=this.parent,r=i.activeObj.activePoint,r=(r.width=r.endX-r.startX,r.height=r.endY-r.startY,this.updatePrevShapeSettings());O.isNullOrUndefined(this.shapeResizingArgs)||O.isNullOrUndefined(this.shapeMovingArgs)?(e.currentShapeSettings=r,t.currentShapeSettings=r):(e.currentShapeSettings=this.shapeResizingArgs.currentShapeSettings=r,t.currentShapeSettings=this.shapeMovingArgs.currentShapeSettings=r),"resize"===o?(this.isCropSelection=!1,(r=void 0)!==(r=void 0!==i.activeObj.shape?i.activeObj.shape.split("-"):r)&&"crop"===r[0]&&(this.isCropSelection=!0),this.isCropSelection?(r={action:e.action,previousSelectionSettings:{type:i.getSelectionType(i.activeObj.shape),startX:e.previousShapeSettings.startX,startY:e.previousShapeSettings.startY,width:e.previousShapeSettings.width,height:e.previousShapeSettings.height},currentSelectionSettings:{type:i.getSelectionType(i.activeObj.shape),startX:e.currentShapeSettings.startX,startY:e.currentShapeSettings.startY,width:e.currentShapeSettings.width,height:e.currentShapeSettings.height}},this.selectionResizingArgs=r,i.trigger("selectionChanging",r),i.notify("shape",{prop:"updSelChangeEventArgs",onPropertyChange:!1,value:{selectionSettings:r.currentSelectionSettings}})):(""!==this.currentDrawingShape&&"crosshair"===i.upperCanvas.style.cursor&&(e.action="drawing"),i.trigger("shapeChanging",e),this.isPreventShaping=e.cancel,i.notify("shape",{prop:"updateShapeChangeEventArgs",onPropertyChange:!1,value:{shapeSettings:e.currentShapeSettings}}))):"mouse-down"===o||"mouse-up"===o?(i.trigger("shapeChanging",e),this.isPreventShaping=e.cancel,i.notify("shape",{prop:"updateShapeChangeEventArgs",onPropertyChange:!1,value:{shapeSettings:e.currentShapeSettings}})):(i.trigger("shapeChanging",t),this.isPreventShaping=e.cancel,i.notify("shape",{prop:"updateShapeChangeEventArgs",onPropertyChange:!1,value:{shapeSettings:t.currentShapeSettings}})),i.eventType=o},c.prototype.setDragWidth=function(e){var t=this.parent,o=t.activeObj.activePoint,t=t.img,i=t.destLeft,r=t.destWidth,n=e;if(0<=n)for(var a=0;a<n&&(o.startX+=e=n-a,o.endX+=e,!(o.startX>=i&&o.endX<=i+r));a++)o.startX-=e,o.endX-=e;else for(a=1;a<Math.abs(n)&&(o.startX+=e=n+a,o.endX+=e,!(o.startX>=i&&o.endX<=i+r));a++)o.startX-=e,o.endX-=e},c.prototype.setDragHeight=function(e){var t=this.parent,o=t.activeObj.activePoint,t=t.img,i=t.destTop,r=t.destHeight,n=e;if(0<=n)for(var a=1;a<n&&(o.startY+=e=n-a,o.endY+=e,!(o.startY>=i&&o.endY<=i+r));a++)o.startY-=e,o.endY-=e;else for(a=0;a<Math.abs(n)&&(o.startY+=e=n+a,o.endY+=e,!(o.startY>=i&&o.endY<=i+r));a++)o.startY-=e,o.endY-=e},c.prototype.limitDrag=function(e){var t=!1,o=this.parent,i=o.img,r=i.destLeft,n=i.destTop,a=i.destWidth,i=i.destHeight,s=o.activeObj.activePoint,l=e?s.startX:s.endX,p=e?s.startY:s.endY,h=e?s.endX:s.startX,d=e?s.endY:s.startY;return l<r&&(l=r),p<n&&(p=n),r+a<h&&(h=r+a),n+i<d&&(d=n+i),0!==o.transform.straighten&&(o.notify("draw",{prop:"updateImgCanvasPoints",onPropertyChange:!(r={isIntersect:null,arr:null})}),o.notify("draw",{prop:"isLinesIntersect",onPropertyChange:!1,value:{obj:r}}),r.arr[0]||r.arr[1]||r.arr[2]||r.arr[3])&&(t=!0),e?(s.startX=l,s.startY=p,s.endX=h,s.endY=d):(s.startX=h,s.startY=d,s.endX=l,s.endY=p),t},c.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},c.prototype.preventDraggingInvertly=function(){var e=!1,t=this.parent;return"image"===t.activeObj.shape||this.isPreventDragging||0!==t.activeObj.rotatedAngle||(e=this.limitDrag(!0),-1<["line","arrow","path"].indexOf(t.activeObj.shape)&&(e=this.limitDrag(!1))),e},c.prototype.preventTextDraggingInvertly=function(){var e=this.parent,t=!1,o=e.activeObj.activePoint,e=e.img,i=e.destLeft,r=e.destTop,n=e.destWidth,e=e.destHeight;return this.isPreventDragging||(o.startX<i||o.startY<r||o.endX>i+n||o.endY>r+e)&&(t=!0),t},c.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)},c.prototype.getScaleRatio=function(e){var t,o=this.parent,i={x:e,y:e};return o.activeObj.shape&&"crop-custom"!==o.activeObj.shape&&"crop-circle"!==o.activeObj.shape&&"crop-square"!==o.activeObj.shape&&(1<(t=("image"===o.activeObj.shape||"text"===o.activeObj.shape?this.findImageRatio(o.activeObj.activePoint.width,o.activeObj.activePoint.height):o.activeObj.shape).split("-")).length||"image"===o.activeObj.shape||"text"===o.activeObj.shape)&&(t=("image"===o.activeObj.shape||"text"===o.activeObj.shape?t[0]:t[1]).split(":"),o=e/parseInt(t[1],10),i.x=o*parseInt(t[0],10),i.y=o*parseInt(t[1],10)),i},c.prototype.findImageRatio=function(e,t,o){function i(e,t){return 0===t?e:i(t,e%t)}var r=i(e,t),e=e/r+":"+t/r;return o&&(o.ratio=e),e},c.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)},c.prototype.performSEResize=function(e,t,o,i){var r,n=this.parent;this.resizeImg(e,t,"se-resize",o),i.endX<i.startX&&(r=i.endX,i.endX=i.startX,i.startX=r,this.dragElement=n.upperCanvas.style.cursor=n.cursor="sw-resize"),i.endY<i.startY&&(r=i.endY,i.endY=i.startY,i.startY=r,this.dragElement=n.upperCanvas.style.cursor=n.cursor="ne-resize"),this.revertCustomSelection(i,o,"se-resize"),this.revertResizing(o)},c.prototype.performNWResize=function(e,t,o,i){var r,n=this.parent;this.resizeImg(e,t,"nw-resize",o),i.startX>i.endX&&(r=i.startX,i.startX=i.endX,i.endX=r,this.dragElement=n.upperCanvas.style.cursor=n.cursor="ne-resize"),i.startY>i.endY&&(r=i.startY,i.startY=i.endY,i.endY=r,this.dragElement=n.upperCanvas.style.cursor=n.cursor="sw-resize"),this.revertCustomSelection(i,o,"nw-resize"),this.revertResizing(o)},c.prototype.isCustomSelection=function(){return!!this.parent.activeObj.shape&&-1<this.parent.activeObj.shape.indexOf("crop-")&&-1===["custom","circle","square","2:3","3:2","3:4","4:3","4:5","5:4","5:7","7:5","9:16","16:9"].indexOf(this.parent.activeObj.shape.split("-")[1])},c.prototype.revertCustomSelection=function(e,t,o){var i,r,n,a,s=this.parent;this.isCustomSelection()&&(i=(a=s.img).destLeft,r=a.destTop,n=a.destWidth,a=a.destHeight,n=i+n<s.lowerCanvas.width?i+n:s.lowerCanvas.width,a=r+a<s.lowerCanvas.height?r+a:s.lowerCanvas.height,"se-resize"===o&&(e.endX>n||e.endY>a)||"nw-resize"===o&&(e.startX<(0<i?i:0)||e.startY<(0<r?r:0))||"ne-resize"===o&&(e.endX>n||e.startY<(0<r?r:0))||"sw-resize"===o&&(e.startX<(0<i?i:0)||e.endY>a))&&this.revertPoints(e,t)},c.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},c.prototype.updateNWPoints=function(e,t){var o,i,r,n,a,s,l=this.parent,p=l.activeObj.activePoint,h=O.extend({},l.activeObj,null,!0);"text"===l.activeObj.shape?(this.resizeImg(e,t,"nw-resize",h),l.notify("shape",{prop:"updateFontSize",onPropertyChange:!1,value:{obj:l.activeObj}})):((o=void 0)!==l.activeObj.shape&&(o=l.activeObj.shape.split("-")),"crop-custom"===l.activeObj.shape||void 0!==l.activeObj.shape&&"crop"!==o[0]||this.isCustomSelection()?("image"===l.activeObj.shape||this.isCustomSelection()?this.resizeImg(e,t,"nw-resize",h):this.adjustNWPoints(p,e,t,l.activeObj.rotatedAngle),p.startX>p.endX&&(i=p.startX,p.startX=p.endX,p.endX=i,this.dragElement=l.upperCanvas.style.cursor=l.cursor="ne-resize"),p.startY>p.endY&&(i=p.startY,p.startY=p.endY,p.endY=i,this.dragElement=l.upperCanvas.style.cursor=l.cursor="sw-resize"),this.revertCustomSelection(p,h,"nw-resize")):(i=(o=l.img).destLeft,l=o.destTop,p.startX<e&&p.startY<t?(r=e-p.startX,n=t-p.startY,a=Math.min(r,n),s=this.getScaleRatio(a),p.startX+=s.x,p.startY+=s.y,(p.startX<(0<i?i:0)||p.startY<(0<l?l:0))&&(p.startX-=s.x,p.startY-=s.y)):(r=p.startX-e,n=t-p.endY,a=Math.max(r,n),s=this.getScaleRatio(a),p.startX-=s.x,p.startY-=s.y,(p.startX<(0<i?i:0)||p.startY<(0<l?l:0))&&(p.startX+=s.x,p.startY+=s.y)),p.width=p.endX-p.startX,p.height=p.endY-p.startY),this.revertResizing(h),p.width=p.endX-p.startX,p.height=p.endY-p.startY,this.preventInverseResize(h))},c.prototype.updateNPoints=function(e,t){var o,i,r,n,a,s,l=this.parent,p=l.activeObj.activePoint,h=O.extend({},l.activeObj,null,!0);"text"!==l.activeObj.shape&&(i=void 0,l.activeObj.shape&&(i=l.activeObj.shape.split("-")),"crop-custom"===l.activeObj.shape||l.activeObj.shape&&"crop"!==i[0]?("line"!==l.activeObj.shape&&"arrow"!==l.activeObj.shape&&"path"!==l.activeObj.shape&&0!==l.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=t),r=this.dragPoint.endX-this.previousPoint.x,n=this.dragPoint.endY-this.previousPoint.y,this.adjustRotationPoints(p,r,n,l.activeObj.rotatedAngle)):(p.startY=t,p.height=p.endY-p.startY),p.startY>p.endY&&(i=p.startY,p.startY=p.endY,p.endY=i,this.dragElement=this.resizedElement="s-resize")):(l=(i=l.img).destLeft,o=i.destTop,i=i.destWidth,this.isCustomSelection()?this.performNWResize(e,t,h,p):p.endX>e&&p.startY<t?(r=p.endX-e,n=t-p.startY,a=Math.min(r,n),s=this.getScaleRatio(a),p.endX-=s.x,p.startY+=s.y,(p.endX>l+i||p.startY<o)&&(p.endX+=s.x,p.startY-=s.y)):(r=e-p.endX,n=p.startY-t,a=Math.max(r,n),s=this.getScaleRatio(a),p.endX+=s.x,p.startY-=s.y,(p.endX>l+i||p.startY<o)&&(p.endX-=s.x,p.startY+=s.y)),p.width=p.endX-p.startX,p.height=p.endY-p.startY),this.revertResizing(h))},c.prototype.updateNEPoints=function(e,t){var o,i,r,n,a,s,l,p,h,d=this.parent,c=d.activeObj.activePoint,u=O.extend({},d.activeObj,null,!0);"text"===d.activeObj.shape?(this.resizeImg(e,t,"ne-resize",u),d.notify("shape",{prop:"updateFontSize",onPropertyChange:!1,value:{obj:d.activeObj}})):(r=void 0,d.activeObj.shape&&(r=d.activeObj.shape.split("-")),"crop-custom"===d.activeObj.shape||void 0!==d.activeObj.shape&&"crop"!==r[0]||this.isCustomSelection()?("image"===d.activeObj.shape||this.isCustomSelection()?this.resizeImg(e,t,"ne-resize",u):this.adjustNEPoints(c,e,t,d.activeObj.rotatedAngle),c.endX<c.startX&&(o=c.endX,c.endX=c.startX,c.startX=o,this.dragElement=d.upperCanvas.style.cursor=d.cursor="nw-resize"),c.startY>c.endY&&(o=c.startY,c.startY=c.endY,c.endY=o,this.dragElement=d.upperCanvas.style.cursor=d.cursor="se-resize"),this.revertCustomSelection(c,u,"ne-resize")):(o=(r=d.img).destLeft,i=r.destTop,r=r.destWidth,c.endX>e&&c.startY<t?(n=c.endX-e,a=t-c.startY,s=Math.min(n,a),l=this.getScaleRatio(s),c.endX-=l.x,c.startY+=l.y,p=o+r<d.lowerCanvas.width?o+r:d.lowerCanvas.width,h=0<i?i:0,(c.endX>p||c.startY<h)&&(c.endX+=l.x,c.startY-=l.y)):(n=e-c.endX,a=c.startY-t,s=Math.max(n,a),l=this.getScaleRatio(s),c.endX+=l.x,c.startY-=l.y,p=o+r<d.lowerCanvas.width?o+r:d.lowerCanvas.width,h=0<i?i:0,(c.endX>p||c.startY<h)&&(c.endX-=l.x,c.startY+=l.y)),c.width=c.endX-c.startX,c.height=c.endY-c.startY),this.revertResizing(u),c.width=c.endX-c.startX,c.height=c.endY-c.startY,this.preventInverseResize(u))},c.prototype.updateWPoints=function(e,t){var o,i,r,n,a,s,l=this.parent,p=l.activeObj.activePoint,h=O.extend({},l.activeObj,null,!0);"text"!==l.activeObj.shape&&(i=void 0,l.activeObj.shape&&(i=l.activeObj.shape.split("-")),"crop-custom"===l.activeObj.shape||l.activeObj.shape&&"crop"!==i[0]?("line"!==l.activeObj.shape&&"arrow"!==l.activeObj.shape&&"path"!==l.activeObj.shape&&0!==l.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=t),r=this.dragPoint.endX-this.previousPoint.x,n=this.dragPoint.endY-this.previousPoint.y,this.adjustRotationPoints(p,r,n,l.activeObj.rotatedAngle)):(p.startX=e,p.width=p.endX-p.startX),"line"===l.activeObj.shape||"arrow"===l.activeObj.shape||"path"===l.activeObj.shape?(p.startY=t,p.height=p.endY-p.startY,this.adjustActObjForLineArrow()&&(this.dragElement="e-resize","right"===l.activeObj.triangleDirection?l.activeObj.triangleDirection="left":"left"===l.activeObj.triangleDirection&&(l.activeObj.triangleDirection="right"))):p.startX>p.endX&&(i=p.startX,p.startX=p.endX,p.endX=i,this.dragElement=this.resizedElement="e-resize")):(l=(i=l.img).destLeft,o=i.destTop,i=i.destHeight,this.isCustomSelection()?this.performNWResize(e,t,h,p):p.startX<e&&p.endY>t?(r=e-p.startX,n=p.endY-t,a=Math.min(r,n),s=this.getScaleRatio(a),p.startX+=s.x,p.endY-=s.y,(p.startX<l||p.endY>o+i)&&(p.startX-=s.x,p.endY+=s.y)):(r=p.startX-e,n=t-p.endY,a=Math.max(r,n),s=this.getScaleRatio(a),p.startX-=s.x,p.endY+=s.y,(p.startX<l||p.endY>o+i)&&(p.startX+=s.x,p.endY-=s.y)),p.width=p.endX-p.startX,p.height=p.endY-p.startY),this.revertResizing(h))},c.prototype.updateEPoints=function(e,t){var o,i,r,n,a,s,l,p=this.parent,h=p.activeObj.activePoint,d=O.extend({},p.activeObj,null,!0);"text"!==p.activeObj.shape&&(r=void 0,p.activeObj.shape&&(r=p.activeObj.shape.split("-")),"crop-custom"===p.activeObj.shape||p.activeObj.shape&&"crop"!==r[0]?("line"!==p.activeObj.shape&&"arrow"!==p.activeObj.shape&&"path"!==p.activeObj.shape&&0!==p.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=t),n=this.dragPoint.endX-this.previousPoint.x,a=this.dragPoint.endY-this.previousPoint.y,this.adjustRotationPoints(h,n,a,p.activeObj.rotatedAngle)):(h.endX=e,h.width=h.endX-h.startX),"line"===p.activeObj.shape||"arrow"===p.activeObj.shape||"path"===p.activeObj.shape?(h.endY=t,h.height=h.endY-h.startY,this.adjustActObjForLineArrow()&&(this.dragElement="w-resize","right"===p.activeObj.triangleDirection?p.activeObj.triangleDirection="left":"left"===p.activeObj.triangleDirection&&(p.activeObj.triangleDirection="right"))):h.endX<h.startX&&(r=h.endX,h.endX=h.startX,h.startX=r,this.dragElement=this.resizedElement="w-resize")):(p=(r=p.img).destLeft,o=r.destTop,i=r.destWidth,r=r.destHeight,this.isCustomSelection()?this.performSEResize(e,t,d,h):h.endX>e&&h.endY>t?(n=h.endX-e,a=h.endY-t,s=Math.min(n,a),l=this.getScaleRatio(s),h.endX-=l.x,h.endY-=l.y,(h.endX>p+i||h.endY>o+r)&&(h.endX+=l.x,h.endY+=l.y)):(n=e-h.endX,a=t-h.endY,s=Math.max(n,a),l=this.getScaleRatio(s),h.endX+=l.x,h.endY+=l.y,(h.endX>p+i||h.endY>o+r)&&(h.endX-=l.x,h.endY-=l.y)),h.width=h.endX-h.startX,h.height=h.endY-h.startY),this.revertResizing(d))},c.prototype.updateSWPoints=function(e,t){var o,i,r,n,a,s,l,p,h=this.parent,d=h.activeObj.activePoint,c=O.extend({},h.activeObj,null,!0);"text"===h.activeObj.shape?(this.resizeImg(e,t,"sw-resize",c),h.notify("shape",{prop:"updateFontSize",onPropertyChange:!1,value:{obj:h.activeObj}})):((r=void 0)!==h.activeObj.shape&&(r=h.activeObj.shape.split("-")),"crop-custom"===h.activeObj.shape||void 0!==h.activeObj.shape&&"crop"!==r[0]||this.isCustomSelection()?("image"===h.activeObj.shape||this.isCustomSelection()?this.resizeImg(e,t,"sw-resize",c):this.adjustSWPoints(d,e,t,h.activeObj.rotatedAngle),d.startX>d.endX&&(o=d.startX,d.startX=d.endX,d.endX=o,this.dragElement=h.upperCanvas.style.cursor=h.cursor="se-resize"),d.endY<d.startY&&(o=d.endY,d.endY=d.startY,d.startY=o,this.dragElement=h.upperCanvas.style.cursor=h.cursor="nw-resize"),this.revertCustomSelection(d,c,"sw-resize")):(o=(r=h.img).destLeft,i=r.destTop,r=r.destHeight,d.startX<e&&d.endY>t?(n=e-d.startX,a=d.endY-t,s=Math.min(n,a),l=this.getScaleRatio(s),d.startX+=l.x,d.endY-=l.y,p=i+r<h.lowerCanvas.height?i+r:h.lowerCanvas.height,(d.startX<(0<o?o:0)||d.endY>p)&&(d.startX-=l.x,d.endY+=l.y)):(n=d.startX-e,a=t-d.endY,s=Math.max(n,a),l=this.getScaleRatio(s),d.startX-=l.x,d.endY+=l.y,p=i+r<h.lowerCanvas.height?i+r:h.lowerCanvas.height,(d.startX<(0<o?o:0)||d.endY>p)&&(d.startX+=l.x,d.endY-=l.y)),d.width=d.endX-d.startX,d.height=d.endY-d.startY),this.revertResizing(c),d.width=d.endX-d.startX,d.height=d.endY-d.startY,this.preventInverseResize(c))},c.prototype.updateSPoints=function(e,t){var o,i,r,n,a,s,l,p=this.parent,h=p.activeObj.activePoint,d=O.extend({},p.activeObj,null,!0);"text"!==p.activeObj.shape&&(r=void 0,p.activeObj.shape&&(r=p.activeObj.shape.split("-")),"crop-custom"===p.activeObj.shape||p.activeObj.shape&&"crop"!==r[0]?("line"!==p.activeObj.shape&&"arrow"!==p.activeObj.shape&&"path"!==p.activeObj.shape&&0!==p.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=t),n=this.dragPoint.endX-this.previousPoint.x,a=this.dragPoint.endY-this.previousPoint.y,this.adjustRotationPoints(h,n,a,p.activeObj.rotatedAngle)):(h.endY=t,h.height=h.endY-h.startY),h.endY<h.startY&&(r=h.endY,h.endY=h.startY,h.startY=r,this.dragElement=this.resizedElement="n-resize")):(p=(r=p.img).destLeft,o=r.destTop,i=r.destWidth,r=r.destHeight,this.isCustomSelection()?this.performSEResize(e,t,d,h):h.endX>e&&h.endY>t?(n=h.endX-e,a=h.endY-t,s=Math.min(n,a),l=this.getScaleRatio(s),h.endX-=l.x,h.endY-=l.y,(h.endX>p+i||h.endY>o+r)&&(h.endX+=l.x,h.endY+=l.y)):(n=e-h.endX,a=t-h.endY,s=Math.max(n,a),l=this.getScaleRatio(s),h.endX+=l.x,h.endY+=l.x,(h.endX>p+i||h.endY>o+r)&&(h.endX-=l.x,h.endY-=l.y)),h.width=h.endX-h.startX,h.height=h.endY-h.startY),this.revertResizing(d))},c.prototype.updateSEPoints=function(e,t){var o,i,r,n,a,s,l,p,h,d,c=this.parent,u=c.activeObj.activePoint,g=O.extend({},c.activeObj,null,!0);"text"===c.activeObj.shape?(this.resizeImg(e,t,"se-resize",g),c.notify("shape",{prop:"updateFontSize",onPropertyChange:!1,value:{obj:c.activeObj}})):((n=p=void 0)!==c.activeObj.shape&&(p=c.activeObj.shape.split("-")),"crop-custom"===c.activeObj.shape||void 0!==c.activeObj.shape&&"crop"!==p[0]||this.isCustomSelection()?("image"===c.activeObj.shape||this.isCustomSelection()?this.resizeImg(e,t,"se-resize",g):this.adjustSEPoints(u,e,t,c.activeObj.rotatedAngle),u.endX<u.startX&&(a=u.endX,u.endX=u.startX,u.startX=a,this.dragElement=c.upperCanvas.style.cursor=c.cursor="sw-resize"),u.endY<u.startY&&(a=u.endY,u.endY=u.startY,u.startY=a,this.dragElement=c.upperCanvas.style.cursor=c.cursor="ne-resize"),this.revertCustomSelection(u,g,"se-resize")):(a=(p=c.img).destLeft,s=p.destTop,l=p.destWidth,p=p.destHeight,u.endX>e&&u.endY>t?(o=u.endX-e,i=u.endY-t,r=Math.min(o,i),n=this.getScaleRatio(r),u.endX-=n.x,u.endY-=n.y,h=a+l<c.lowerCanvas.width?a+l:c.lowerCanvas.width,d=s+p<c.lowerCanvas.height?s+p:c.lowerCanvas.height,(u.endX>h||u.endY>d)&&(u.endX+=n.x,u.endY+=n.y)):(o=e-u.endX,i=t-u.endY,r=Math.max(o,i),n=this.getScaleRatio(r),u.endX+=n.x,u.endY+=n.y,h=a+l<c.lowerCanvas.width?a+l:c.lowerCanvas.width,d=s+p<c.lowerCanvas.height?s+p:c.lowerCanvas.height,(u.endX>h||u.endY>d)&&(u.endX-=n.x,u.endY-=n.y)),u.width=u.endX-u.startX,u.height=u.endY-u.startY),this.revertResizing(g),this.preventInverseResize(g))},c.prototype.resizeImg=function(e,t,o,i){var r,n,a,s,l=this.parent,p=l.activeObj.activePoint;if(0!==this.previousPoint.x&&0!==this.previousPoint.y){switch("text"===this.currentDrawingShape&&(this.setCursor(e,t),0===l.activeObj.textSettings.fontSize)&&(l.activeObj.textSettings.fontSize=11,l.notify("shape",{prop:"updateFontRatio",onPropertyChange:!1,value:{obj:l.activeObj,isTextArea:null}}),l.activeObj.textSettings.text=l.activeObj.keyHistory="Enter Text",l.notify("shape",{prop:"updateFontStyles",onPropertyChange:!1,value:{isTextBox:null}}),s=this.upperContext.measureText(l.activeObj.textSettings.text).width+.5*l.activeObj.textSettings.fontSize,p.endX=p.startX+s,p.endY=p.startY+l.activeObj.textSettings.fontSize,p.width=p.endX-p.startX,p.height=p.endY-p.startY,i=O.extend({},l.activeObj,null,!0),l.notify("draw",{prop:"updateActiveObject",onPropertyChange:!1,value:{actPoint:l.activeObj.activePoint,obj:l.activeObj,isMouseMove:null,x:null,y:null}})),l.upperCanvas.style.cursor){case"se-resize":case"s-resize":this.previousPoint.x>e||this.previousPoint.y>t?(r=this.previousPoint.x-e,n=this.previousPoint.y-t,a=this.getScaleRatio((r+n)/2),this.adjustRotationPoints(p,-Math.abs(a.x),-Math.abs(a.y),l.activeObj.rotatedAngle,"img-resize",o)):0!==this.previousPoint.x&&0!==this.previousPoint.y&&(r=e-this.previousPoint.x,n=t-this.previousPoint.y,a=this.getScaleRatio((r+n)/2),this.adjustRotationPoints(p,Math.abs(a.x),Math.abs(a.y),l.activeObj.rotatedAngle,"img-resize",o));break;case"sw-resize":this.previousPoint.x<e||this.previousPoint.y>t?(r=e-this.previousPoint.x,n=this.previousPoint.y-t,a=this.getScaleRatio((r+n)/2),this.adjustRotationPoints(p,-Math.abs(a.x),-Math.abs(a.y),l.activeObj.rotatedAngle,"img-resize",o)):0!==this.previousPoint.x&&0!==this.previousPoint.y&&(r=this.previousPoint.x-e,n=t-this.previousPoint.y,a=this.getScaleRatio((r+n)/2),this.adjustRotationPoints(p,Math.abs(a.x),Math.abs(a.y),l.activeObj.rotatedAngle,"img-resize",o));break;case"w-resize":case"nw-resize":this.previousPoint.x<e||this.previousPoint.y<t?(r=e-this.previousPoint.x,n=t-this.previousPoint.y,a=this.getScaleRatio((r+n)/2),this.adjustRotationPoints(p,-Math.abs(a.x),-Math.abs(a.y),l.activeObj.rotatedAngle,"img-resize",o)):0!==this.previousPoint.x&&0!==this.previousPoint.y&&(r=this.previousPoint.x-e,n=this.previousPoint.y-t,a=this.getScaleRatio((r+n)/2),this.adjustRotationPoints(p,Math.abs(a.x),Math.abs(a.y),l.activeObj.rotatedAngle,"img-resize",o));break;case"n-resize":case"ne-resize":this.previousPoint.x>e||this.previousPoint.y<t?(r=this.previousPoint.x-e,n=t-this.previousPoint.y,a=this.getScaleRatio((r+n)/2),this.adjustRotationPoints(p,-Math.abs(a.x),-Math.abs(a.y),l.activeObj.rotatedAngle,"img-resize",o)):0!==this.previousPoint.x&&0!==this.previousPoint.y&&(r=e-this.previousPoint.x,n=this.previousPoint.y-t,a=this.getScaleRatio((r+n)/2),this.adjustRotationPoints(p,Math.abs(a.x),Math.abs(a.y),l.activeObj.rotatedAngle,"img-resize",o));break;case"e-resize":this.previousPoint.x>e||this.previousPoint.y>t?(r=this.previousPoint.x-e,n=this.previousPoint.y-t,a=this.getScaleRatio((r+n)/2),this.adjustRotationPoints(p,-Math.abs(a.x),-Math.abs(a.y),l.activeObj.rotatedAngle,"img-resize",o)):0!==this.previousPoint.x&&0!==this.previousPoint.y&&(r=e-this.previousPoint.x,n=t-this.previousPoint.y,a=this.getScaleRatio((r+n)/2),this.adjustRotationPoints(p,Math.abs(a.x),Math.abs(a.y),l.activeObj.rotatedAngle,"img-resize",o))}p.width=p.endX-p.startX,p.height=p.endY-p.startY,(p.width<10||p.height<10||"text"===l.activeObj.shape&&0===l.activeObj.rotatedAngle&&this.preventTextDraggingInvertly())&&(l.activeObj=O.extend({},i,null,!0))}this.previousPoint={x:e,y:t}},c.prototype.adjustNWPoints=function(e,t,o,i){var r=e.startX+e.width/2,n=e.startY+e.height/2,r=this.rotatePoints(e.endX,e.endY,r,n,i),n=[(r[0]+t)/2,(r[1]+o)/2],r=this.rotatePoints(r[0],r[1],n[0],n[1],-i),t=this.rotatePoints(t,o,n[0],n[1],-i);return e.endX=r[0],e.endY=r[1],e.startY=t[1],e.startX=t[0],e.width=e.endX-e.startX,e.height=e.endY-e.startY,e},c.prototype.adjustNEPoints=function(e,t,o,i){var r=e.startX+e.width/2,n=e.startY+e.height/2,r=this.rotatePoints(e.startX,e.endY,r,n,i),n=[(r[0]+t)/2,(r[1]+o)/2],r=this.rotatePoints(r[0],r[1],n[0],n[1],-i),t=this.rotatePoints(t,o,n[0],n[1],-i);return e.startX=r[0],e.endY=r[1],e.width=t[0]-r[0],e.height=r[1]-t[1],e.endX=e.startX+e.width,e.startY=e.endY-e.height,e},c.prototype.adjustSWPoints=function(e,t,o,i){var r=e.startX+e.width/2,n=e.startY+e.height/2,r=this.rotatePoints(e.endX,e.startY,r,n,i),n=[(r[0]+t)/2,(r[1]+o)/2],r=this.rotatePoints(r[0],r[1],n[0],n[1],-i),t=this.rotatePoints(t,o,n[0],n[1],-i);return e.endX=r[0],e.startY=r[1],e.startX=t[0],e.endY=t[1],e.width=e.endX-e.startX,e.height=e.endY-e.startY,e},c.prototype.adjustSEPoints=function(e,t,o,i){var r=e.startX+e.width/2,n=e.startY+e.height/2,r=this.rotatePoints(e.startX,e.startY,r,n,i),n=[(r[0]+t)/2,(r[1]+o)/2],r=this.rotatePoints(r[0],r[1],n[0],n[1],-i),t=this.rotatePoints(t,o,n[0],n[1],-i);return e.startX=r[0],e.startY=r[1],e.width=t[0]-r[0],e.height=t[1]-r[1],e.endX=e.startX+e.width,e.endY=e.startY+e.height,e},c.prototype.adjustRotationPoints=function(e,t,o,i,r,n){var a=e.startX+e.width/2,s=e.startY+e.height/2,t=(this.getResizeDirection(e,t,o,i,r,n),this.rotatePoints(e.startX,e.startY,a,s,i)),o=this.rotatePoints(e.endX,e.startY,a,s,i),r=this.rotatePoints(e.endX,e.endY,a,s,i),n=this.rotatePoints(e.startX,e.endY,a,s,i),a=[(t[0]+r[0])/2,(t[1]+r[1])/2],s=this.rotatePoints(t[0],t[1],a[0],a[1],-i),r=this.rotatePoints(n[0],n[1],a[0],a[1],-i),t=this.rotatePoints(o[0],o[1],a[0],a[1],-i);return e.startX=s[0],e.startY=s[1],e.endX=t[0],e.endY=r[1],e.width=e.endX-e.startX,e.height=e.endY-e.startY,e},c.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]},c.prototype.setResizedValue=function(e,t,o,i){switch(e){case"x":t+=o;break;case"y":t+=i;break;case"abs-x":t+=0<o?-o:Math.abs(o);break;case"abs-y":t+=0<i?-i:Math.abs(i);break;case"y-abs-x":t+=i+(0<o?-o:Math.abs(o))/2;break;case"abs-x-abs-y":t+=(0<o?-o:Math.abs(o))+(0<i?-i:Math.abs(i))/2;break;case"abs-y-x":t+=(0<i?-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},c.prototype.getResizeDirection=function(e,t,o,i,r,n){i*=180/Math.PI,i=this.getResizedElement(i,this.resizedElement);"e-resize"===this.resizedElement?(e.width=this.setResizedValue(i,e.width,t,o),e.endX=e.width+e.startX):"n-resize"===this.resizedElement?(e.startY=this.setResizedValue(i,e.startY,t,o),e.height=e.endY-e.startY):"w-resize"===this.resizedElement?(e.startX=this.setResizedValue(i,e.startX,t,o),e.width=e.startX+e.endX):"s-resize"===this.resizedElement?(e.height=this.setResizedValue(i,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"===n?(e.endX=e.width+e.startX,e.endY=e.height+e.startY):"sw-resize"===n?(e.startX=e.endX-e.width,e.endY=e.height+e.startY):"ne-resize"===n?(e.endX=e.width+e.startX,e.startY=e.endY-e.height):"nw-resize"===n&&(e.startX=e.endX-e.width,e.startY=e.endY-e.height)):r&&"text"===r&&("widthHeight"===n?(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"===n?(e.width=this.setResizedValue("x-y",e.width,t,o),e.endX=e.width+e.startX):"height"===n&&(e.height=this.setResizedValue("y-abs-x",e.height,t,o),e.endY=e.height+e.startY))},c.prototype.getResizedElement=function(e,t){for(var o=[],i=("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"]]),e<0?360-Math.abs(e):e),r=0,n=o;r<n.length;r++){var a=n[r],s=a[0],l=a[1],a=a[2];if(s<i&&i<=l||s<i+360&&i+360<=l)return a}return t},c.prototype.updateCursorStyles=function(e,t,o){var i,r,n=this.parent,a=!1,s=(""===n.activeObj.keyHistory||void 0!==n.activeObj.shape||n.currObjType.isCustomCrop||n.currObjType.isLine||!n.currObjType.isText||(n.activeObj.shape="text"),O.extend({},n.activeObj,{},!0));O.isNullOrUndefined(s.topLeftCircle)||((0===s.shapeDegree?n.transform.degree:n.transform.degree-s.shapeDegree)<0&&0,this.isObjSelected?"line"===s.shape||"arrow"===s.shape?a=this.updateCursorStylesForLineArrow(e,t,s):"path"===s.shape?a=this.updateCursorStylesForPath(e,t,s):s.rotatedAngle?(this.setCursorForRotatedObject(s,e,t,n.upperCanvas),"grabbing"===n.cursor?(n.upperCanvas.style.cursor=n.cursor="grabbing",this.dragElement=n.cursor):"move"===n.cursor?(this.dragPoint.startX=this.previousPoint.x=this.dragPoint.endX=e,this.dragPoint.startY=this.previousPoint.y=this.dragPoint.endY=t):"default"!==n.cursor&&(a=!0,this.dragElement=n.cursor,n.currObjType.isResize=!0)):(i=this.getTransRotationPoint(s),r=s.topLeftCircle.radius,e>=s.topLeftCircle.startX-2*r&&e<=s.topLeftCircle.startX+2*r&&t>=s.topLeftCircle.startY-2*r&&t<=s.topLeftCircle.startY+2*r&&"nw-resize"!==this.dragElement?(s.topLeftCircle.startX=s.topLeftCircle.startY=0,n.upperCanvas.style.cursor=n.cursor="nw-resize",a=!0,this.dragElement=n.upperCanvas.style.cursor):e>=s.topLeftCircle.startX-2*r&&e<=s.topRightCircle.startX-2*r&&t>=s.topCenterCircle.startY-2*r&&t<=s.topCenterCircle.startY+2*r&&"n-resize"!==this.dragElement?(s.topCenterCircle.startX=s.topCenterCircle.startY=0,n.upperCanvas.style.cursor=n.cursor="n-resize",a=!0,this.dragElement=n.upperCanvas.style.cursor):e>=s.topRightCircle.startX-2*r&&e<=s.topRightCircle.startX+2*r&&t>=s.topRightCircle.startY-2*r&&t<=s.topRightCircle.startY+2*r&&"ne-resize"!==this.dragElement?(s.topRightCircle.startX=s.topRightCircle.startY=0,n.upperCanvas.style.cursor=n.cursor="ne-resize",a=!0,this.dragElement=n.upperCanvas.style.cursor):e>=s.centerLeftCircle.startX-2*r&&e<=s.centerLeftCircle.startX+2*r&&t>=s.topLeftCircle.startY-2*r&&t<=s.bottomLeftCircle.startY-2*r&&"w-resize"!==this.dragElement?(s.centerLeftCircle.startX=s.centerLeftCircle.startY=0,n.upperCanvas.style.cursor=n.cursor="w-resize",a=!0,this.dragElement=n.upperCanvas.style.cursor):e>=s.centerRightCircle.startX-2*r&&e<=s.centerRightCircle.startX+2*r&&t>=s.topRightCircle.startY-2*r&&t<=s.bottomRightCircle.startY-2*r&&"e-resize"!==this.dragElement?(s.centerRightCircle.startX=s.centerRightCircle.startY=0,n.upperCanvas.style.cursor=n.cursor="e-resize",a=!0,this.dragElement=n.upperCanvas.style.cursor):e>=s.bottomLeftCircle.startX-2*r&&e<=s.bottomLeftCircle.startX+2*r&&t>=s.bottomLeftCircle.startY-2*r&&t<=s.bottomLeftCircle.startY+2*r&&"sw-resize"!==this.dragElement?(s.bottomLeftCircle.startX=s.bottomLeftCircle.startY=0,n.upperCanvas.style.cursor=n.cursor="sw-resize",a=!0,this.dragElement=n.upperCanvas.style.cursor):e>=s.bottomLeftCircle.startX-2*r&&e<=s.bottomRightCircle.startX-2*r&&t>=s.bottomCenterCircle.startY-2*r&&t<=s.bottomCenterCircle.startY+2*r&&"s-resize"!==this.dragElement?(s.bottomCenterCircle.startX=s.bottomCenterCircle.startY=0,n.upperCanvas.style.cursor=n.cursor="s-resize",a=!0,this.dragElement=n.upperCanvas.style.cursor):e>=s.bottomRightCircle.startX-2*r&&e<=s.bottomRightCircle.startX+2*r&&t>=s.bottomRightCircle.startY-2*r&&t<=s.bottomRightCircle.startY+2*r&&"se-resize"!==this.dragElement?(s.bottomRightCircle.startX=s.bottomRightCircle.startY=0,n.upperCanvas.style.cursor=n.cursor="se-resize",a=!0,this.dragElement=n.upperCanvas.style.cursor):i&&e>=i.x-2*r&&e<=i.x+2*r&&t>=i.y-2*r&&t<=i.y+2*r&&"grabbing"!==this.dragElement?(n.upperCanvas.style.cursor=n.cursor="grabbing",this.dragElement=n.upperCanvas.style.cursor):(this.dragPoint.startX=this.previousPoint.x=this.dragPoint.endX=e,this.dragPoint.startY=this.previousPoint.y=this.dragPoint.endY=t),"text"!==s.shape||"n-resize"!==n.cursor&&"s-resize"!==n.cursor&&"e-resize"!==n.cursor&&"w-resize"!==n.cursor||(n.upperCanvas.style.cursor=n.cursor="move",this.dragElement="",this.dragPoint.startX=this.previousPoint.x=this.dragPoint.endX=e,this.dragPoint.startY=this.previousPoint.y=this.dragPoint.endY=t)):(this.dragPoint.startX=this.previousPoint.x=this.dragPoint.endX=e,this.dragPoint.startY=this.previousPoint.y=this.dragPoint.endY=t),this.previousPoint.x=this.previousPoint.y=this.diffPoint.x=this.diffPoint.y=0,"touchstart"!==o||a||e>=s.activePoint.startX&&e<=s.activePoint.endX&&t>=s.activePoint.startY&&t<=s.activePoint.endY||"grabbing"===this.dragElement?n.currObjType.isDragging=!0:"line"===s.shape||"arrow"===s.shape?(this.setCursorForLineArrow(s,e,t,n.upperCanvas),"move"===n.cursor&&(n.currObjType.isDragging=!0)):"path"===s.shape&&(this.setCursorForPath(s,e,t,n.upperCanvas),"move"===n.cursor)&&(n.currObjType.isDragging=!0),0===s.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=t)},c.prototype.updateCursorStylesForLineArrow=function(e,t,o){for(var i,r=!1,n=this.parent,a=o.topLeftCircle.radius,s=0;s<5;s++)if(e>=(i=o.pointColl[s]).x-2*a&&e<=i.x+2*a&&t>=i.y-2*a&&t<=i.y+2*a){o.centerLeftCircle.startX=o.centerLeftCircle.startY=0,this.dragElement="w-resize",r=!0;break}if(!r)for(s=1;s<6;s++)if(e>=(i=o.pointColl[o.pointColl.length-s]).x-2*a&&e<=i.x+2*a&&t>=i.y-2*a&&t<=i.y+2*a){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(e>=(i=o.pointColl[s]).x-2*a&&e<=i.x+2*a&&t>=i.y-2*a&&t<=i.y+2*a){n.upperCanvas.style.cursor=n.cursor="move",this.dragPoint.startX=this.previousPoint.x=this.dragPoint.endX=e,this.dragPoint.startY=this.previousPoint.y=this.dragPoint.endY=t;break}n.upperCanvas.style.cursor=n.cursor="default"}return r},c.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},c.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 n=0,a=o.activeObj.flipObjColl.length;n<a;n++){var s=o.activeObj.flipObjColl[n].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)},c.prototype.setActivePoint=function(e,t){var o,i,r=this.parent,n=r.activeObj.activePoint;O.isNullOrUndefined(n)||(r.currObjType.isText?(i=e||0,o=t||r.activeObj.textSettings.fontSize,void 0===r.activeObj.textSettings.fontSize&&(r.activeObj.textSettings.fontSize=.1*Math.abs(r.baseImgCanvas.width-r.baseImgCanvas.height)),this.setTextSelection(i,o),this.mouseDownPoint.x=n.endX,this.mouseDownPoint.y=n.endY,void 0!==r.activeObj.horTopLine&&(r.activeObj.activePoint=O.extend({},n,{},!0)),r.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate"}})):e&&t?(n.startX=this.mouseDownPoint.x=e,n.startY=this.mouseDownPoint.y=t,r.currObjType.isDragging=!0):((n={startX:(i=r.activeObj).horTopLine.startX,startY:i.horTopLine.startY,endX:i.horTopLine.endX,endY:i.horTopLine.endY}).width=n.endX-n.startX,n.height=n.endY-n.startY))},c.prototype.mouseDownEventHandler=function(e){var t,o=this.parent;this.mouseDown=e.currentTarget===o.lowerCanvas||e.currentTarget===o.upperCanvas?"canvas":"","touchstart"===e.type?this.isTouch=!0:this.isTouch=!1,"touchstart"===e.type&&e.currentTarget===o.lowerCanvas&&!o.isImageLoaded||(this.isCropSelection=!1,this.isPan=!0,void 0!==(t=void 0!==o.activeObj.shape?o.activeObj.shape.split("-"):t)&&"crop"===t[0]&&(this.isCropSelection=!0),this.isCropSelection&&(this.dragCanvas=o.togglePan=!0),"grabbing"===o.cursor&&(t={shapeSettingsObj:{}},this.isGrabbing=!0,o.notify("selection",{prop:"updatePrevShapeSettings",onPropertyChange:!1,value:{obj:t}}),this.triggerShapeChange({cancel:!1,action:"rotate-start",previousShapeSettings:t=t.shapeSettingsObj},{cancel:!1,action:"rotate-start",previousShapeSettings:t},"mouse-down")),t={point:this.setXYPoints(e)},o.trigger("click",t),this.clickEvent(t,e))},c.prototype.getImagePoints=function(e,t){var o=this.parent.img,i=o.destLeft,r=o.destTop,n=o.destWidth,o=o.destHeight;return e<i?e=i:i+n<e&&(e=i+n),t<r?t=r:r+o<t&&(t=r+o),{x:e,y:t}},c.prototype.clickEvent=function(e,t){var o=this.parent,i=o.activeObj.activePoint,r=e.point.x,e=e.point.y,n=o.activeObj.shape&&"text"===o.activeObj.shape?o.cursor:"default";if(o.isResize)this.performEnterAction(),o.upperCanvas.style.cursor="default";else{if(JSON.stringify(o.frameObj)!==JSON.stringify(o.tempFrameObj))o.okBtn();else if(""!==this.currentDrawingShape&&(this.isTouch&&!this.isShapeTouch(t,this.isCropSelection)||"crosshair"===o.upperCanvas.style.cursor||o.isShapeDrawing))return o.drawingShape&&!o.isShapeDrawing&&(o.okBtn(),o.enableShapeDrawing(o.toPascalCase(o.drawingShape),!0)),i=o.activeObj.activePoint,o.notify("filter",{prop:"getCurrentObj",onPropertyChange:!(d={currObj:{}}),value:{object:d}}),this.initialPrevObj=d.currObj,this.initialPrevObj.objColl=O.extend([],o.objColl,[],!0),this.initialPrevObj.pointColl=O.extend([],o.pointColl,[],!0),this.initialPrevObj.afterCropActions=O.extend([],o.afterCropActions,[],!0),o.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!(d={selPointColl:null}),value:{obj:d}}),this.initialPrevObj.selPointColl=O.extend([],d.selPointColl,[],!0),this.setActivePoint(r,e),i=o.activeObj.activePoint,"path"===this.currentDrawingShape&&(s=this.getImagePoints(r,e),o.activeObj.pointColl.push({x:s.x,y:s.y}),0!==i.width)&&0!==i.height&&(i.width=0,i.height=0,i.startX=o.activeObj.pointColl[o.activeObj.pointColl.length-1].x,i.startY=o.activeObj.pointColl[o.activeObj.pointColl.length-1].y),i.endX=i.startX,i.endY=i.startY,"text"===this.currentDrawingShape?(o.activeObj.textSettings.fontSize=11,this.previousPoint.x=i.startX,this.previousPoint.y=i.startY,o.notify("shape",{prop:"updateFontStyles",onPropertyChange:!1,value:{isTextBox:null}}),d=this.upperContext.measureText(o.activeObj.textSettings.text).width+.5*o.activeObj.textSettings.fontSize,i.endX=i.startX+d,i.endY=i.startY+o.activeObj.textSettings.fontSize,i.width=i.endX-i.startX,i.height=i.endY-i.startY):"arrow"===this.currentDrawingShape&&(o.activeObj.start=this.arrowShape[0],o.activeObj.end=this.arrowShape[1]),d={cancel:!(h={cancel:!(o.currObjType.isDragging=!0),action:"draw-start",previousShapeSettings:d=this.updatePrevShapeSettings()}),action:"move",previousShapeSettings:d},this.shapeResizingArgs=h,this.shapeMovingArgs=d,this.triggerShapeChange(h,d,"mouse-down"),o.activeObj.activePoint=i,void(o.isShapeDrawing=!0);o.notify("draw",{prop:"resetFrameZoom",onPropertyChange:!1,value:{isOk:!0}}),this.isCropSelection&&this.dragCanvas&&(this.setCursor(r,e),"move"!==o.cursor)&&"crosshair"!==o.cursor&&"default"!==o.cursor&&"grab"!==o.cursor&&(this.isPan=!1),o.activeObj.shape?this.isObjSelected=!0:this.isObjSelected=!1;var a,s,l,p,h={currObj:{}},d=(o.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:h}}),h.currObj),i=O.extend({},o.activeObj,null,!0),h=this.isShapeTouch(t,this.isCropSelection),c=this.isFreehandDrawTouch(t,this.isCropSelection),u=h||this.isShapeClick(t,this.isCropSelection),u=this.applyCurrShape(u),g="none"!==o.textArea.style.display;this.isTouch&&!h&&i.shape&&!this.isCropSelection&&(this.applyObj(r,e)&&(o.okBtn(!0),o.notify("draw",{prop:"setPrevActObj",onPropertyChange:!1,value:{prevActObj:null}})),i=O.extend({},o.cropObj,{},!0),o.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"shapeTransform",previousObj:d,previousObjColl:d.objColl,previousPointColl:d.pointColl,previousSelPointColl:d.selPointColl,previousCropObj:i,previousText:null,currentText:null,previousFilter:null,isCircleCrop:o.isCircleCrop}}),u)&&o.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"ok"}}),h||o.togglePen||this.isCropSelection||(o.notify("toolbar",{prop:"refresh-main-toolbar",onPropertyChange:!1}),o.notify("toolbar",{prop:"close-contextual-toolbar",onPropertyChange:!1})),!this.dragCanvas||!this.isPan||"grab"!==o.cursor&&!this.isTouch||h||c||o.togglePen?(d=!1,!o.activeObj.shape||"line"!==o.activeObj.shape&&"arrow"!==o.activeObj.shape||(d=!0),h=(i=this.setXYPoints(t)).x,c=i.y,this.applyObj(h,c)&&(o.okBtn(!0),u&&(i=o.cursor,o.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"ok"}}),o.cursor=i),o.notify("draw",{prop:"setPrevActObj",onPropertyChange:!1,value:{prevActObj:null}})),o.notify("shape",{prop:"redrawActObj",onPropertyChange:!1,value:{x:h,y:c,isMouseDown:!0}}),o.notify("freehand-draw",{prop:"getFreehandDrawHoveredIndex",onPropertyChange:!(i={index:null}),value:{obj:i}}),o.notify("freehand-draw",{prop:"getFreehandSelectedIndex",onPropertyChange:!(a={freehandSelectedIndex:null}),value:{obj:a}}),this.isFhdPoint||this.isFhdCustomized&&!o.togglePen?(O.isNullOrUndefined(a.freehandSelectedIndex)||a.freehandSelectedIndex===i.index||(p=i.index,o.okBtn(),this.isFhdCustomized=!1,o.notify("freehand-draw",{prop:"setFreehandDrawHoveredIndex",onPropertyChange:!1,value:{index:p}}),-1<i.index&&(l=o.pointColl[i.index].strokeColor,o.notify("freehand-draw",{prop:"hoverFhd",onPropertyChange:!1,value:{strokeColor:l,strokeWidth:o.pointColl[i.index].strokeWidth}}))),a.freehandSelectedIndex=null,o.notify("freehand-draw",{prop:"getFreehandSelectedIndex",onPropertyChange:!1,value:{obj:a}}),p=O.extend([],o.objColl,[],!0),!O.isNullOrUndefined(i.index)&&-1<i.index?(o.notify("freehand-draw",{prop:"selectFhd",value:{type:"ok"}}),o.notify("freehand-draw",{prop:"hoverFhd",onPropertyChange:!1,value:{strokeColor:null,strokeWidth:null}}),o.notify("toolbar",{prop:"renderQAT",onPropertyChange:!1,value:{isPenEdit:!0}})):a.freehandSelectedIndex?(o.okBtn(),l=o.pointColl[a.freehandSelectedIndex].strokeColor,o.notify("freehand-draw",{prop:"hoverFhd",onPropertyChange:!1,value:{strokeColor:l,strokeWidth:o.pointColl[a.freehandSelectedIndex].strokeWidth}})):this.findTargetObj(h,c,!1)&&(o.objColl=p,this.findTarget(h,c,t.type),o.notify("draw",{prop:"redrawDownScale"}))):(this.isFhdEditing&&(o.apply(),(i=document.getElementById(o.element.id+"_quickAccessToolbarArea"))&&(i.style.display="none"),s=o.pointColl[a.freehandSelectedIndex],l={id:"pen_"+(a.freehandSelectedIndex+1),type:v.ShapeType.FreehandDraw,startX:s.points[0].x,startY:s.points[0].y,strokeColor:s.strokeColor,strokeWidth:s.strokeWidth,points:s.points,opacity:s.opacity,index:s.order},p={action:"apply",currentShapeSettings:O.extend({},l,{},!0)},o.trigger("shapeChange",p)),i=o.togglePen,o.notify("toolbar",{prop:"close-contextual-toolbar",onPropertyChange:!1}),i&&o.freeHandDraw(!0),this.isFhdEditing=!1,d?this.setCursor(h,c):"default"!==n&&(o.upperCanvas.style.cursor=o.cursor=n),("crosshair"===o.cursor||O.Browser.isDevice&&o.togglePen)&&(o.togglePen?(O.isNullOrUndefined(o.activeObj.strokeSettings)&&(o.notify("shape",{prop:"getStrokeSettings",onPropertyChange:!(a={strokeSettings:{}}),value:{obj:a}}),o.activeObj.strokeSettings=a.strokeSettings),o.notify("freehand-draw",{prop:"getPenStrokeWidth",onPropertyChange:!(s={penStrokeWidth:null}),value:{obj:s}}),O.isNullOrUndefined(s.penStrokeWidth)&&o.notify("freehand-draw",{prop:"setPenStrokeWidth",onPropertyChange:!1,value:{value:2}}),this.upperContext.strokeStyle=o.activeObj.strokeSettings.strokeColor,this.upperContext.fillStyle=o.activeObj.strokeSettings.strokeColor,o.notify("freehand-draw",{prop:"freehandDownHandler",onPropertyChange:!1,value:{e:t,canvas:o.upperCanvas}})):(o.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),this.upperContext.clearRect(0,0,o.upperCanvas.width,o.upperCanvas.height)),o.currObjType.isActiveObj=!1,this.dragElement="",this.dragPoint.startX=this.dragPoint.startY=this.dragPoint.endX=this.dragPoint.endY=0),"crosshair"!==o.cursor&&"touchstart"===t.type.toLowerCase()||o.currObjType.isActiveObj&&"default"!==o.cursor&&!o.togglePen?(o.notify("draw",{prop:"updateTempObjColl"}),o.notify("draw",{prop:"updateTempPointColl"}),this.findTarget(h,c,t.type),o.notify("draw",{prop:"redrawDownScale"})):""!==o.currObjType.shape&&!o.currObjType.isCustomCrop||o.togglePen||"default"===o.cursor||this.setActivePoint(h,c),g&&o.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.lowerContext}}))):(this.applyObj(r,e)&&(o.okBtn(!0),u&&(l=o.cursor,o.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"ok"}}),o.cursor=l),o.notify("draw",{prop:"setPrevActObj",onPropertyChange:!1,value:{prevActObj:null}})),this.isFhdEditing&&(o.notify("freehand-draw",{prop:"applyFhd",onPropertyChange:!1}),this.isFhdCustomized=!1,o.notify("toolbar",{prop:"destroy-qa-toolbar",onPropertyChange:!1})),(p=o.activeObj.shape)&&-1<["rectangle","ellipse","line","arrow","path","text","image"].indexOf(p)&&(o.notify("shape",{prop:"redrawActObj",onPropertyChange:!1,value:{x:null,y:null,isMouseDown:null}}),o.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),o.notify("toolbar",{prop:"setCurrentToolbar",value:{type:"main"}}),o.notify("toolbar",{prop:"refresh-main-toolbar",onPropertyChange:!1})),this.canvasMouseDownHandler(t)),this.isShapeInserted=!1,this.tempActiveObj=O.extend({},o.activeObj,{},!0)}},c.prototype.mouseMoveEventHandler=function(e){var t,o,i,r,n,a,s,l,p=this.parent,h=p.cursor,d=p.upperCanvas.style.cursor;e.preventDefault(),this.isPreventShaping||("grabbing"===p.cursor&&this.isGrabbing&&(p.notify("selection",{prop:"updatePrevShapeSettings",onPropertyChange:!(s={shapeSettingsObj:{}}),value:{obj:s}}),this.triggerShapeChange({cancel:!1,action:"rotating",previousShapeSettings:s=s.shapeSettingsObj},{cancel:!1,action:"rotating",previousShapeSettings:s},"mouse-down")),this.timer&&0<this.timer&&(this.timer=0),s=p.lowerCanvas.getBoundingClientRect(),"touchmove"===e.type&&2===e.touches.length?(this.isFirstMove?(this.startTouches=this.targetTouches(e.touches),this.tempTouches=[],this.tempTouches.push({x:e.touches[0].clientX||e.touches[0].pageX-p.lowerCanvas.offsetLeft-s.left,y:(e.touches[0].clientY||e.touches[0].pageY-p.lowerCanvas.offsetTop)-s.top}),this.tempTouches.push({x:(e.touches[1].clientX||e.touches[1].pageX-p.lowerCanvas.offsetLeft)-s.left,y:(e.touches[1].clientY||e.touches[1].pageY-p.lowerCanvas.offsetTop)-s.top})):(a=(e.touches[0].clientX||e.touches[0].pageX-p.lowerCanvas.offsetLeft)-s.left,r=(e.touches[0].clientY||e.touches[0].pageY-p.lowerCanvas.offsetTop)-s.top,n=(e.touches[1].clientX||e.touches[1].pageX-p.lowerCanvas.offsetLeft)-s.left,i=(e.touches[1].clientY||e.touches[1].pageY-p.lowerCanvas.offsetTop)-s.top,this.currMousePoint.x!==(a={x:a<n?n-(n-a)/2:a-(a-n)/2,y:r<i?i-(i-r)/2:r-(r-i)/2}).x&&this.currMousePoint.y!==a.y&&(n="","touchmove"===e.type&&(p.zoomSettings.zoomTrigger&v.ZoomTrigger.Pinch)===v.ZoomTrigger.Pinch&&(this.zoomType="Pinch",r=this.calculateScale(this.startTouches,this.targetTouches(e.touches)),this.startTouches=this.targetTouches(e.touches),1<r?n="zoomIn":r<1&&(n="zoomOut")),""!==n&&p.notify("draw",{prop:"performPointZoom",onPropertyChange:!1,value:{x:a.x,y:a.y,type:n,isResize:null}}),this.tempTouches=[],this.tempTouches.push({x:e.touches[0].clientX||e.touches[0].pageX-p.lowerCanvas.offsetLeft,y:e.touches[0].clientY||e.touches[0].pageY-p.lowerCanvas.offsetTop}),this.tempTouches.push({x:e.touches[1].clientX||e.touches[1].pageX-p.lowerCanvas.offsetLeft,y:e.touches[1].clientY||e.touches[1].pageY-p.lowerCanvas.offsetTop}),this.currMousePoint.x=a.x,this.currMousePoint.y=a.y,this.isPinching=!0)),this.isFirstMove=!1):("mousemove"===e.type?(t=e.clientX,o=e.clientY):(this.touchEndPoint.x=t=e.touches[0].clientX,this.touchEndPoint.y=o=e.touches[0].clientY),t-=s.left,o-=s.top,this.canvasMouseMoveHandler(e),i=!1,(i=void 0!==(l=void 0!==p.activeObj.shape?p.activeObj.shape.split("-"):l)&&"crop"===l[0]?!0:i)&&p.notify("transform",{prop:"disableZoomOutBtn",value:{isZoomOut:!0}}),p.upperCanvas.style.cursor=d,p.cursor=h,(p.currObjType.isActiveObj&&(void 0!==p.activeObj.activePoint||0<p.objColl.length)&&!this.dragCanvas||void 0!==p.activeObj.activePoint)&&""===this.dragElement&&(this.setCursor(t,o),p.activeObj.activePoint&&(0===p.activeObj.activePoint.width||!O.isNullOrUndefined(p.activeObj.currIndex)&&this.cursorTargetId!==p.activeObj.currIndex)&&"default"!==p.cursor&&"move"!==p.cursor&&"crosshair"!==p.cursor&&"grab"!==p.cursor&&"pointer"!==p.cursor&&(p.upperCanvas.style.cursor=p.cursor="move"),this.findTarget(t,o,e.type)),n=(r=p.img).destLeft,a=r.destTop,s=r.destWidth,l=r.destHeight,p.currObjType.isDragging&&(this.upperContext.clearRect(0,0,p.lowerCanvas.width,p.lowerCanvas.height),this.updateActivePoint(t,o,i),p.notify("shape",{prop:"updateTrianglePoints",onPropertyChange:!1,value:{obj:p.activeObj}}),this.isPreventDragging?(p.activeObj.activePoint.startX>n&&p.activeObj.activePoint.endX<n+s&&p.activeObj.activePoint.startY>a&&p.activeObj.activePoint.endY<a+l&&(this.isPreventDragging=!1),p.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate",obj:null,isCropRatio:null,points:null,isPreventDrag:!0,saveContext:null,isPreventSelection:null}})):p.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate",obj:null,isCropRatio:null,points:null,isPreventDrag:null,saveContext:null,isPreventSelection:null}}),i)&&(this.dragCanvas=p.togglePan=!0)))},c.prototype.mouseUpEventHandler=function(e){var t,o,i,r,n,a,s,l,p,h,d,c,u,g=this.parent,v=g.element.id;(O.Browser.isDevice||!(g.element.querySelector("#"+v+"_contextualToolbar")&&!g.element.querySelector("#"+v+"_contextualToolbar").parentElement.classList.contains("e-hide")||g.element.querySelector("#"+v+"_headWrapper")&&!g.element.querySelector("#"+v+"_headWrapper").parentElement.classList.contains("e-hide")))&&("grabbing"===g.cursor&&this.isGrabbing&&(g.notify("selection",{prop:"updatePrevShapeSettings",onPropertyChange:!(u={shapeSettingsObj:{}}),value:{obj:u}}),v=u.shapeSettingsObj,this.triggerShapeChange(c={cancel:!1,action:"rotate-end",previousShapeSettings:v},l={cancel:!1,action:"rotate-end",previousShapeSettings:v},"mouse-up")),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(),g.togglePan&&this.canvasMouseUpHandler(e),t=v=void 0,t="mouseup"===e.type?(v=e.clientX,e.clientY):(v=this.touchEndPoint.x,this.touchEndPoint.y),v-=(d=g.lowerCanvas.getBoundingClientRect()).left,d=void(t-=d.top),o=this.currentDrawingShape,i=!1,"touchend"===e.type&&(this.startTouches=this.tempTouches=[],this.isFirstMove=!1,"none"===g.textArea.style.display&&(this.timer=0),this.isPinching)?(this.isPinching=!1,g.notify("draw",{prop:"redrawDownScale"}),(g.isCropTab||g.activeObj.shape)&&(g.notify("draw",{prop:"setStraightenActObj",value:{activeObj:null}}),g.notify("freehand-draw",{prop:"resetStraightenPoint"})),g.isStraightening&&(g.notify("draw",{prop:"resetStraightenDestPoints"}),g.notify("draw",{prop:"setDestForStraighten"}))):(r=!1,(n=void 0)!==(n=void 0!==g.activeObj.shape?g.activeObj.shape.split("-"):n)&&"crop"===n[0]&&(r=!0),"path"===this.currentDrawingShape&&g.isShapeDrawing?(s=(h=e.srcElement).parentElement.id,a=g.element.id,e.currentTarget!==g.upperCanvas&&e.currentTarget!==g.lowerCanvas&&0<g.activeObj.pointColl.length&&(h.classList.contains("e-upload-icon")||s===a+"_zoomIn"||s===a+"_zoomOut"||s===a+"_annotationBtn"||s===a+"_borderColorBtn"||s===a+"_borderWidthBtn")&&(g.notify("shape",{prop:"stopPathDrawing",onPropertyChange:!1,value:{e:e,isApply:!0}}),this.upperContext.clearRect(0,0,g.upperCanvas.width,g.upperCanvas.height),g.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate",obj:g.activeObj,isCropRatio:null,points:null,isPreventDrag:!0,saveContext:null,isPreventSelection:!0}}))):(e.currentTarget!==g.upperCanvas||g.isResize||(this.pathAdjustedIndex=null,""!==this.currentDrawingShape&&("text"===this.currentDrawingShape?(h=O.extend({},g.cropObj,{},!0),g.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:h,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}})):g.notify("undo-redo",{prop:"updateUrObj",onPropertyChange:!1,value:{objColl:this.initialPrevObj.objColl,operation:"shapeInsert"}}),this.isShapeInserted=!0,this.currentDrawingShape="",(g.activeObj.shape&&"path"===g.activeObj.shape&&0===g.activeObj.pointColl.length||(!g.activeObj.shape||"path"!==g.activeObj.shape)&&0===g.activeObj.activePoint.width&&0===g.activeObj.activePoint.height)&&(g.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!(i=!0)}),this.upperContext.clearRect(0,0,g.upperCanvas.width,g.upperCanvas.height)),l={cancel:!(c={cancel:!1,action:"draw-end",previousShapeSettings:s=this.updatePrevShapeSettings()}),action:"move",previousShapeSettings:s},this.shapeResizingArgs=c,this.shapeMovingArgs=l,this.triggerShapeChange(c,l,"mouse-up")),this.adjustActObjForLineArrow(),this.updPtCollForShpRot(),g.currObjType.shape=g.currObjType.shape.toLowerCase(),a=O.extend({},g.cropObj,{},!0),g.notify("filter",{prop:"getCurrentObj",onPropertyChange:!(h={currObj:{}}),value:{object:h}}),(s=h.currObj).objColl=O.extend([],g.objColl,[],!0),s.pointColl=O.extend([],g.pointColl,[],!0),s.afterCropActions=O.extend([],g.afterCropActions,[],!0),g.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!(c={selPointColl:null}),value:{obj:c}}),s.selPointColl=O.extend([],c.selPointColl,[],!0),g.togglePen||r||(this.tempObjColl&&0!==g.activeObj.activePoint.width&&(g.notify("shape",{prop:"updImgRatioForActObj",onPropertyChange:!1}),g.objColl.push(g.activeObj),JSON.stringify(g.activeObj.activePoint)!==JSON.stringify(this.tempActiveObj.activePoint)&&g.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"shapeTransform",previousObj:s,previousObjColl:this.tempObjColl,previousPointColl:s.pointColl,previousSelPointColl:s.selPointColl,previousCropObj:a,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),this.redrawShape(g.objColl[g.objColl.length-1],!0),this.tempObjColl=void 0),this.isFhdEditing)||(this.applyCurrActObj(v,t),g.currObjType.isResize=!1,g.notify("toolbar",{prop:"destroy-qa-toolbar",onPropertyChange:!1})),g.activeObj&&(l=!1,(void 0===(p=void 0!==g.activeObj.shape?g.activeObj.shape.split("-"):p)&&(g.currObjType.isCustomCrop||g.togglePen)||void 0!==p&&"crop"===p[0])&&(l=!0),h=g.activeObj.shape,-1<["rectangle","ellipse","line","arrow","path"].indexOf(d=h)?g.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"shapes",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}}):"text"===h?"none"===g.textArea.style.display&&g.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"text",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}}):this.isFhdEditing?g.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"pen",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}}):l||g.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"main",isApplyBtn:null,isCropping:!1,isZooming:null}}),g.notify("toolbar",{prop:"update-toolbar-items",onPropertyChange:!1}),this.isFhdEditing||(g.activeObj.shape&&"text"===g.activeObj.shape&&11===g.activeObj.textSettings.fontSize&&55===Math.floor(g.activeObj.activePoint.width)&&11===Math.floor(g.activeObj.activePoint.height)&&g.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),l)||(g.isShapeDrawing?(c=this.currentDrawingShape,g.notify("undo-redo",{prop:"updateUndoRedoStack",onPropertyChange:!1}),this.currentDrawingShape=c):g.notify("undo-redo",{prop:"updateUndoRedoStack",onPropertyChange:!1})))),void 0!==(n=void 0!==g.activeObj.shape?g.activeObj.shape.split("-"):n)&&"crop"===n[0]&&(r=!0),g.activeObj.shape&&!r&&e.currentTarget===g.upperCanvas&&"none"===g.textArea.style.display&&("text"===g.activeObj.shape?g.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"text",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}}):g.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"shapes",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}}),g.notify("toolbar",{prop:"update-toolbar-items",onPropertyChange:!1}),g.notify("toolbar",{prop:"renderQAT",onPropertyChange:!1,value:{isPenEdit:null}})),g.notify("freehand-draw",{prop:"getFreehandDrawSelectedId",onPropertyChange:!(u={freehandDrawSelectedId:null}),value:{obj:u}}),g.togglePen&&e.currentTarget===g.upperCanvas&&!u.freehandDrawSelectedId?(g.notify("freehand-draw",{prop:"freehandUpHandler",onPropertyChange:!1,value:{e:e,canvas:g.upperCanvas,context:this.upperContext}}),g.togglePen&&(O.isNullOrUndefined(g.toolbar)||g.toolbar&&0<g.toolbar.length||!O.isNullOrUndefined(g.toolbarTemplate))&&(g.okBtn(),g.freeHandDraw(!0))):g.currObjType.shape="",this.dragElement="",this.mouseDown="",this.isSliderActive=!1,g.currObjType.isInitialLine=g.currObjType.isDragging=!1,this.selMouseUpEvent(),O.isNullOrUndefined(g.drawingShape)&&d&&""!==o&&(g.drawingShape=d),g.drawingShape&&(this.currentDrawingShape=g.drawingShape.toLowerCase(),i)&&(g.enableShapeDrawing(g.toPascalCase(g.drawingShape),!0),g.upperCanvas.style.cursor="crosshair"),g.isShapeDrawing=!1)))},c.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;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},c.prototype.updPtCollForShpRot=function(e){var t,o,i,r,n,a,s=this.parent;(e=e||s.activeObj).shape&&0!==e.rotatedAngle&&(s.notify("shape",{prop:"setPointCollForShapeRotation",onPropertyChange:!1,value:{obj:e}}),s=s.img,t=s.destLeft,o=s.destTop,i=s.destWidth,r=s.destHeight,s=e.horTopLinePointColl,n=e.horBottomLinePointColl,a=e.verLeftLinePointColl,e=e.verRightLinePointColl,s.forEach(s=function(e){e.ratioX=(e.x-t)/i,e.ratioY=(e.y-o)/r}),n.forEach(s),a.forEach(s),e.forEach(s))},c.prototype.setXYPoints=function(e){e.preventDefault(),"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 t,o,e=this.parent.lowerCanvas.getBoundingClientRect();return{x:t-=e.left,y:o-=e.top}},c.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},c.prototype.isShapeClick=function(e,t){var o,i,r,n,a=this.parent,s=!1;return a.togglePen||a.activeObj.shape&&"text"===a.activeObj.shape&&this.isShapeInserted&&(o="block"===a.textArea.style.display||"inline-block"===a.textArea.style.display,i=O.extend({},a.activeObj,null,!0),a.notify("shape",{prop:"redrawActObj",onPropertyChange:!1,value:{x:null,y:null,isMouseDown:!0}}),r=(e=this.setXYPoints(e)).x,e=e.y,s=this.findTargetObj(r,e,t),t||(this.upperContext.clearRect(0,0,a.upperCanvas.width,a.upperCanvas.height),s&&a.notify("shape",{prop:"redrawActObj",onPropertyChange:!1,value:{x:null,y:null,isMouseDown:!0}})),o?(a.textArea.value=a.objColl[a.objColl.length-1].keyHistory,a.textArea.style.display="block",a.activeObj=i,n=this.getCurrentIndex(),O.isNullOrUndefined(n)?a.objColl.pop():a.objColl.splice(n,1)):!s&&i.shape&&(a.activeObj=i,n=this.getCurrentIndex(),O.isNullOrUndefined(n)||JSON.stringify(a.activeObj.activePoint)!==JSON.stringify(a.objColl[n].activePoint)?O.isNullOrUndefined(a.activeObj.currIndex)&&a.objColl.pop():a.objColl.splice(n,1))),s},c.prototype.isShapeTouch=function(e,t){var o,i,r,n,a=this.parent,s=!1;return"touchstart"!==e.type||a.togglePen||(a.activeObj&&"text"===a.activeObj.shape&&(this.timer=setTimeout(this.setTimer.bind(this),1e3,e)),o="block"===a.textArea.style.display||"inline-block"===a.textArea.style.display,i=O.extend({},a.activeObj,null,!0),a.notify("shape",{prop:"redrawActObj",onPropertyChange:!1,value:{x:null,y:null,isMouseDown:!0}}),r=(e=this.setXYPoints(e)).x,e=e.y,s=this.findTargetObj(r,e,t),t||this.upperContext.clearRect(0,0,a.upperCanvas.width,a.upperCanvas.height),o?(a.textArea.value=a.objColl[a.objColl.length-1].keyHistory,a.textArea.style.display="block",a.activeObj=i,n=this.getCurrentIndex(),O.isNullOrUndefined(n)?a.objColl.pop():a.objColl.splice(n,1)):!s&&i.shape&&(a.activeObj=i,n=this.getCurrentIndex(),t||(O.isNullOrUndefined(n)||JSON.stringify(a.activeObj.activePoint)!==JSON.stringify(a.objColl[n].activePoint)?O.isNullOrUndefined(a.activeObj.currIndex)&&a.objColl.pop():a.objColl.splice(n,1)))),s},c.prototype.isFreehandDrawTouch=function(e,t){var o,i,r,n,a=this.parent,s=!1;return"touchstart"!==e.type||t||a.togglePen||(o="block"===a.textArea.style.display||"inline-block"===a.textArea.style.display,i=O.extend({},a.activeObj,null,!0),a.notify("shape",{prop:"redrawActObj",onPropertyChange:!1,value:{x:null,y:null,isMouseDown:!0}}),r=(e=this.setXYPoints(e)).x,e=e.y,this.setCursor(r,e),this.isFhdPoint&&(s=!0),o?(a.textArea.value=a.objColl[a.objColl.length-1].keyHistory,a.textArea.style.display="block",a.activeObj=i,n=this.getCurrentIndex(),O.isNullOrUndefined(n)?a.objColl.pop():a.objColl.splice(n,1)):i.shape&&(a.activeObj=i,n=this.getCurrentIndex(),t||(O.isNullOrUndefined(n)||JSON.stringify(a.activeObj.activePoint)!==JSON.stringify(a.objColl[n].activePoint)?O.isNullOrUndefined(a.activeObj.currIndex)&&a.objColl.pop():a.objColl.splice(n,1)))),s},c.prototype.applyObj=function(e,t){var o,i,r,n,a=this.parent,s=!1;return(0!==a.activeObj.activePoint.width||0!==a.activeObj.activePoint.height)&&(n=(r=a.activeObj.activePoint).startX,o=r.startY,i=r.endX,r=r.endY,a.activeObj.shape&&-1<["rectangle","ellipse","line","arrow","path","image","text"].indexOf(a.activeObj.shape)?!(n-2*(n=a.activeObj.topLeftCircle.radius)<=e&&e<=i+2*n&&o-2*n<=t&&t<=r+2*n||"default"!==a.upperCanvas.style.cursor&&"grab"!==a.upperCanvas.style.cursor&&"crosshair"!==a.upperCanvas.style.cursor&&"pointer"!==a.upperCanvas.style.cursor&&"move"!==a.upperCanvas.style.cursor):s)},c.prototype.applyCurrShape=function(e){var t,o=this.parent,i=!1;return o.togglePen||(t=O.extend({},o.activeObj,null,!0),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?(e=O.extend({},o.activeObj,null,!0),o.notify("shape",{prop:"redrawActObj",onPropertyChange:!1,value:{x:null,y:null,isMouseDown:null}}),t=O.extend({},o.objColl[o.objColl.length-1],null,!0),o.objColl.pop(),o.activeObj=O.extend({},e,null,!0),o.textArea.value=t.keyHistory,o.textArea.style.display="block",(e=t.strokeSettings&&t.strokeSettings.strokeColor?"rgb"===t.strokeSettings.strokeColor.split("(")[0]?this.rgbToHex(parseFloat(t.strokeSettings.strokeColor.split("(")[1].split(",")[0]),parseFloat(t.strokeSettings.strokeColor.split("(")[1].split(",")[1]),parseFloat(t.strokeSettings.strokeColor.split("(")[1].split(",")[2]),parseFloat(t.strokeSettings.strokeColor.split("(")[1].split(",")[3])):t.strokeSettings.strokeColor:null)&&"#ffffff"===e&&(e="#fff"),this.tempActiveObj.strokeSettings&&this.tempActiveObj.strokeSettings.strokeColor&&"#ffffff"===this.tempActiveObj.strokeSettings.strokeColor&&(this.tempActiveObj.strokeSettings.strokeColor="#fff"),(t.keyHistory!==this.tempActiveObj.keyHistory||e&&e!==this.tempActiveObj.strokeSettings.strokeColor||t.textSettings&&t.textSettings.fontFamily!==this.tempActiveObj.textSettings.fontFamily||t.textSettings&&Math.round(t.textSettings.fontSize)!==Math.round(this.tempActiveObj.textSettings.fontSize)||t.textSettings&&Math.round(t.textSettings.fontRatio)!==Math.round(this.tempActiveObj.textSettings.fontRatio)||t.textSettings&&t.textSettings.bold!==this.tempActiveObj.textSettings.bold||t.textSettings&&t.textSettings.italic!==this.tempActiveObj.textSettings.italic||t.textSettings&&t.textSettings.underline!==this.tempActiveObj.textSettings.underline)&&(i=!0),this.isInitialTextEdited&&!i&&(this.isInitialTextEdited=!(i=!0))):(this.tempActiveObj.activePoint.height=Math.abs(this.tempActiveObj.activePoint.height),i=JSON.stringify(t)!==JSON.stringify(this.tempActiveObj))),i},c.prototype.canvasMouseDownHandler=function(e){var t,o=this.parent,i=(e.preventDefault(),e="mousedown"===e.type?(t=e.offsetX||e.pageX-o.lowerCanvas.offsetLeft,e.offsetY||e.pageY-o.lowerCanvas.offsetTop):(t=e.touches[0].clientX||e.touches[0].pageX-o.lowerCanvas.offsetLeft,e.touches[0].clientY||e.touches[0].pageY-o.lowerCanvas.offsetTop),o.lowerCanvas.getBoundingClientRect()),i=(t-=i.left,e-=i.top,this.panDown={x:t,y:e},{tempPanMove:null});o.notify("transform",{prop:"getTempPanMove",onPropertyChange:!1,value:{obj:i}}),O.isNullOrUndefined(i.tempPanMove)&&o.notify("transform",{prop:"setTempPanMove",onPropertyChange:!1,value:{point:{x:t,y:e}}})},c.prototype.canvasMouseMoveHandler=function(e){var t,o=this.parent,i={bool:null};o.notify("toolbar",{prop:"getFrameToolbar",onPropertyChange:!1,value:{obj:i}}),o.isResize||i.bool?o.upperCanvas.style.cursor="default":(this.dragCanvas?o.lowerCanvas.style.cursor="grab":(this.dragCanvas=o.togglePan=!1,o.lowerCanvas.style.cursor=o.upperCanvas.style.cursor=o.cursor="default"),i="mousemove"===e.type?(t=e.offsetX,e.offsetY):(t=e.touches[0].clientX||e.touches[0].pageX-o.lowerCanvas.offsetLeft,e.touches[0].clientY||e.touches[0].pageY-o.lowerCanvas.offsetTop),e=o.lowerCanvas.getBoundingClientRect(),t-=e.left,i-=e.top,o.notify("transform",{prop:"setPanMove",onPropertyChange:!1,value:{point:{x:t,y:i}}}),this.panDown&&o.togglePan&&this.dragCanvas&&((o.isCropTab||o.activeObj.shape)&&(o.notify("draw",{prop:"setStraightenActObj",value:{activeObj:null}}),o.notify("freehand-draw",{prop:"resetStraightenPoint"})),o.notify("transform",{prop:"drawPannedImage",onPropertyChange:!1,value:{xDiff:null,yDiff:null}})))},c.prototype.canvasMouseUpHandler=function(e){var t=this.parent,e=(e.preventDefault(),{panMove:null});t.notify("transform",{prop:"getPanMove",onPropertyChange:!1,value:{obj:e}}),t.togglePan&&this.panDown&&e.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)},c.prototype.touchStartHandler=function(e){e.preventDefault();var t=this.parent;0!==this.touchTime&&(new Date).getTime()-this.touchTime<400?(t.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),O.EventHandler.add(t.lowerCanvas,"touchend",this.mouseUpEventHandler,this),O.EventHandler.add(t.lowerCanvas,"touchmove",this.mouseMoveEventHandler,this),O.EventHandler.add(t.upperCanvas,"touchend",this.mouseUpEventHandler,this),O.EventHandler.add(t.upperCanvas,"touchmove",this.mouseMoveEventHandler,this)},c.prototype.unwireEvent=function(){var e=this.parent;O.EventHandler.remove(e.lowerCanvas,"touchend",this.mouseUpEventHandler),O.EventHandler.remove(e.lowerCanvas,"touchmove",this.mouseMoveEventHandler),O.EventHandler.remove(e.upperCanvas,"touchend",this.mouseUpEventHandler),O.EventHandler.remove(e.upperCanvas,"touchmove",this.mouseMoveEventHandler)},c.prototype.keyDownEventHandler=function(e){var t=this.parent,o=(!e.ctrlKey||"+"!==e.key&&"-"!==e.key||e.preventDefault(),{fileName:"",fileType:null}),i=(t.notify("draw",{prop:"getFileName",onPropertyChange:!1,value:{obj:o}}),{fileName:o.fileName,fileType:o.fileType,cancel:!1});switch(e.key){case e.ctrlKey&&"s":t.trigger("beforeSave",i),this.beforeSaveEvent(i,e);break;case e.ctrlKey&&"z":t.allowUndoRedo&&(t.noPushUndo=!1,(t.togglePen||t.drawingShape)&&(t.okBtn(),t.drawingShape=null),t.notify("undo-redo",{prop:"call-undo"}));break;case e.ctrlKey&&"y":t.allowUndoRedo&&(t.noPushUndo=!1,(t.togglePen||t.drawingShape)&&(t.okBtn(),t.drawingShape=null),t.notify("undo-redo",{prop:"call-redo"}));break;case e.ctrlKey&&"+":(t.zoomSettings.zoomTrigger&v.ZoomTrigger.Commands)===v.ZoomTrigger.Commands&&(this.zoomType="Commands",t.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:.1,zoomPoint:null},isResize:null}),t.notify("draw",{prop:"redrawDownScale"}),(t.isCropTab||t.activeObj.shape)&&(t.notify("draw",{prop:"setStraightenActObj",value:{activeObj:null}}),t.notify("freehand-draw",{prop:"resetStraightenPoint"})),t.isStraightening)&&(t.notify("draw",{prop:"resetStraightenDestPoints"}),t.notify("draw",{prop:"setDestForStraighten"}));break;case e.ctrlKey&&"-":(t.zoomSettings.zoomTrigger&v.ZoomTrigger.Commands)===v.ZoomTrigger.Commands&&(this.zoomType="Commands",t.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:-.1,zoomPoint:null},isResize:null}),t.notify("draw",{prop:"redrawDownScale"}),(t.isCropTab||t.activeObj.shape)&&(t.notify("draw",{prop:"setStraightenActObj",value:{activeObj:null}}),t.notify("freehand-draw",{prop:"resetStraightenPoint"})),t.isStraightening)&&(t.notify("draw",{prop:"resetStraightenDestPoints"}),t.notify("draw",{prop:"setDestForStraighten"}));break;case"Delete":this.deleteItem();break;case"Escape":t.notify("draw",{prop:"performCancel",value:{isContextualToolbar:null,isFinalCancel:!0}});break;case"Enter":this.performEnterAction(e);break;case"Tab":this.performTabAction();break;default:!O.Browser.isDevice||"block"!==t.textArea.style.display&&"inline-block"!==t.textArea.style.display||setTimeout(this.textKeyDown.bind(this),1,e)}},c.prototype.performEnterAction=function(e){var t,o,i,r,n=this.parent;n.isResize?this.isValueUpdated()&&(o=this.getNumTextValue(),r=n.element.querySelector("#"+n.element.id+"_aspectratio"),t=n.element.querySelector(".e-ie-toolbar-aspect-ratio-btn"),o&&o.x&&o.y&&(r||t&&!t.classList.contains("e-hidden")?n.notify("transform",{prop:"resize",value:{width:o.x,height:null,isAspectRatio:!0}}):n.notify("transform",{prop:"resize",value:{width:o.x,height:o.y,isAspectRatio:!1}})),t=n.element.querySelector("#"+n.element.id+"_resizeHeight"),o=n.element.querySelector("#"+n.element.id+"_resizeWidth"),O.isNullOrUndefined(r)&&(t&&(i=O.getComponent(t,"numerictextbox"),t)&&""===t.value&&(i.value=parseFloat(i.placeholder),t.value=i.placeholder+"px"),o)&&(i=O.getComponent(o,"numerictextbox"),o)&&""===o.value&&(i.value=parseFloat(i.placeholder),o.value=i.placeholder+"px"),n.notify("draw",{prop:"redrawDownScale"})):(r=void 0,n.activeObj.shape&&(r=n.activeObj.shape.split("-")),e&&this.isKeyBoardCrop(e)&&n.activeObj.horTopLine&&n.activeObj.shape&&"crop"===r[0]&&n.crop())},c.prototype.isKeyBoardCrop=function(e){var t=!1,e=e.target;return t=e.id!==this.parent.element.id+"_ok"&&""!==e.id?t:!0},c.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()},c.prototype.handleScroll=function(e){var t,o,i=this.parent,r=!1,n=("mousewheel"===e.type&&(t=e.clientX,o=e.clientY),i.lowerCanvas.getBoundingClientRect());t-=n.left,o-=n.top,t>i.img.destLeft&&t<i.img.destLeft+i.img.destWidth&&o>i.img.destTop&&o<i.img.destTop+i.img.destHeight&&(r=!0),e.stopPropagation(),!0===e.ctrlKey&&r&&(e.preventDefault(),!i.isCropTab&&i.activeObj.shape&&"crop"!==i.activeObj.shape.split("-")[0]&&(i.okBtn(null,!0),i.notify("toolbar",{prop:"close-contextual-toolbar",onPropertyChange:!1})),n="","mousewheel"===e.type&&(i.zoomSettings.zoomTrigger&v.ZoomTrigger.MouseWheel)===v.ZoomTrigger.MouseWheel&&(this.zoomType="MouseWheel",n=0<e.wheelDelta?"zoomIn":"zoomOut"),""!==n)&&(i.notify("draw",{prop:"performPointZoom",onPropertyChange:!1,value:{x:t,y:o,type:n,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"}))},c.prototype.textKeyDown=function(e){var t=this.parent;0===t.activeObj.rotatedAngle&&("\r"===String.fromCharCode(e.which)&&(this.textRow+=1),t.textArea.setAttribute("rows",this.textRow.toString()),t.textArea.style.height="auto",t.textArea.style.height=t.textArea.scrollHeight+"px",t.notify("shape",{prop:"setTextBoxWidth",onPropertyChange:!1,value:{e:e}}),O.Browser.isDevice&&(t.textArea.style.width=parseFloat(t.textArea.style.width)+t.textArea.style.fontSize+"px"),e=t.textArea.value.split("\n"),this.textRow=e.length,t.textArea.setAttribute("rows",this.textRow.toString()),this.isInitialTextEdited=!1)},c.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"))},c.prototype.setDragDirection=function(e,t){var o=7.5,i=this.parent,r=i.activeObj.activePoint;i.img.destWidth>i.img.destHeight?(r.startX=this.dragPoint.startX=e/2-t/2+o,r.startY=this.dragPoint.startY=t/2-t/2+o,r.endX=e/2+t/2-o,r.endY=t/2+t/2-o):(r.startY=this.dragPoint.startX=t/2-e/2+o,r.endY=t/2+e/2-o,r.startX=this.dragPoint.startX=o,r.endX=e-o)},c.prototype.calcShapeRatio=function(e,t,o,i){for(var r=this.parent,n=r.activeObj.activePoint,a=i<=o?o:i,s=a*(e/t),l=a,p=this.getScale(s,o),h=[],e=r.img,t=e.destLeft,a=e.destTop,d=e.destWidth,e=e.destHeight,c=0;c<2;c++)h.push(0===c?s*p:l*p);for(var s=h[0],l=h[1],u=this.getScale(l,i),g=[],c=0;c<2;c++)g.push(0===c?s*u:l*u);l=g[1],n.width=s=g[0],n.height=l,n.startX=7.5+(this.dragPoint.startX=(o-s)/2),n.startY=7.5+(this.dragPoint.startY=(i-l)/2),n.endX=n.startX+n.width,n.endY=n.startY+n.height,n.startX<t&&t+d>r.lowerCanvas.clientWidth&&(n.startX=t,n.endX=n.startX+s-7.5),n.startY<a&&a+e>r.lowerCanvas.clientHeight&&(n.startY=a,n.endY=n.startY+l-7.5),n.width=n.endX-n.startX,n.height=n.endY-n.startY},c.prototype.getScale=function(e,t){return t<e?t/e:1},c.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 r=i.activeObj,n=r.topLeftCircle,a=r.topCenterCircle,s=r.topRightCircle,l=r.centerLeftCircle,p=r.centerRightCircle,h=r.bottomLeftCircle,d=r.bottomCenterCircle,c=r.bottomRightCircle;switch(this.dragElement.toLowerCase()){case"nw-resize":n.startX=e,n.startY=t;break;case"n-resize":a.startX=e,a.startY=t;break;case"ne-resize":s.startX=e,s.startY=t;break;case"w-resize":l.startX=e,l.startY=t;break;case"e-resize":p.startX=e,p.startY=t;break;case"sw-resize":h.startX=e,h.startY=t;break;case"s-resize":d.startX=e,d.startY=t;break;case"se-resize":c.startX=e,c.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)}}},c.prototype.findTargetObj=function(e,t,o){var i=this.parent,r=!1;if(0!==i.objColl.length&&!i.currObjType.isCustomCrop&&!o){for(var n,a,s=0,l=void 0,p=0;p<i.objColl.length;p++){var h=i.upperCanvas.style.cursor,d=(this.setCursor(e,t),O.extend({},i.objColl[p],{},!0)),c=d.topLeftCircle.radius;if("line"===d.shape||"arrow"===d.shape){for(var u=0;u<d.pointColl.length;u++)if(e>=d.pointColl[u].x-2*c&&e<=d.pointColl[u].x+2*c&&t>=d.pointColl[u].y-2*c&&t<=d.pointColl[u].y+2*c){if(this.tempActiveObj&&this.tempActiveObj.activePoint&&JSON.stringify(this.tempActiveObj.activePoint)===JSON.stringify(d.activePoint)){l=p;break}this.isTouch||"move"===i.cursor||"grab"===i.cursor||this.isShapeInserted?(0===s||s<d.order)&&(s=d.order,l=p):i.objColl[p].currIndex===this.tempActiveObj.currIndex&&(l=p);break}}else if("path"===d.shape){var g=this.setCursorForPath(d,e,t,i.upperCanvas);if("default"!==g&&"grab"!==g){if(this.tempActiveObj&&this.tempActiveObj.activePoint&&JSON.stringify(this.tempActiveObj.activePoint)===JSON.stringify(d.activePoint)){l=p;break}this.isTouch||"move"===i.cursor||"grab"===i.cursor||this.isShapeInserted?(0===s||s<d.order)&&(s=d.order,l=p):i.objColl[p].currIndex===this.tempActiveObj.currIndex&&(l=p)}}else if(0!==d.rotatedAngle){g=this.setCursorForRotatedObject(d,e,t,i.upperCanvas);if("default"!==g&&"grab"!==g){if(this.tempActiveObj&&this.tempActiveObj.activePoint&&JSON.stringify(this.tempActiveObj.activePoint)===JSON.stringify(d.activePoint)){l=p;break}this.isTouch||"move"===i.cursor||"grab"===i.cursor||this.isShapeInserted?(0===s||s<d.order)&&(s=d.order,l=p):i.objColl[p].currIndex===this.tempActiveObj.currIndex&&(l=p)}}else{var v=this.getTransRotationPoint(d);if(e>=d.activePoint.startX-2*c&&e<=d.activePoint.endX+2*c&&t>=d.activePoint.startY-2*c&&t<=d.activePoint.endY+2*c||v&&e>=v.x-2*c&&e<=v.x+2*c&&t>=v.y-2*c&&t<=v.y+2*c){if(this.tempActiveObj&&this.tempActiveObj.activePoint&&JSON.stringify(this.tempActiveObj.activePoint)===JSON.stringify(d.activePoint)){l=p;break}this.isTouch||"move"===h||"grabbing"===h||this.isShapeInserted||"move"===i.cursor||"grabbing"===i.cursor?(0===s||s<d.order)&&(s=d.order,l=p):i.objColl[p].currIndex===this.tempActiveObj.currIndex&&(l=p)}}}r=O.isNullOrUndefined(l)?(i.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),!1):(this.tempObjColl=O.extend([],i.objColl,[],!0),i.currObjType.isCustomCrop=!1,i.activeObj=O.extend({},i.objColl[l],{},!0),o=O.extend({},i.objColl[l],{},!0),i.objColl.splice(l,1),0===i.transform.degree?(n=this.lowerContext.filter,this.lowerContext.clearRect(0,0,i.lowerCanvas.width,i.lowerCanvas.height),i.notify("draw",{prop:"drawImage",onPropertyChange:!1}),this.lowerContext.filter="none",i.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"iterate",pen:"iterate",isPreventApply:null}}),i.activeObj=O.extend({},n,{},!0),this.lowerContext.filter=n,this.getCurrentFlipState()):(n=O.extend({},i.panPoint.totalPannedInternalPoint,{},!0),a={startX:i.img.destLeft,startY:i.img.destTop,width:i.img.destWidth,height:i.img.destHeight},i.notify("draw",{prop:"callUpdateCurrTransState",onPropertyChange:!1}),i.panPoint.totalPannedInternalPoint=n,i.img.destLeft=a.startX,i.img.destTop=a.startY,i.img.destWidth=a.width,i.img.destHeight=a.height,i.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"iterate",pen:"iterate",isPreventApply:null}})),i.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.lowerContext}}),(i.currSelectionPoint&&"crop-circle"===i.currSelectionPoint.shape||i.isCircleCrop)&&i.notify("crop",{prop:"cropCircle",onPropertyChange:!1,value:{context:this.lowerContext,isSave:null,isFlip:null}}),i.activeObj=O.extend({},o,{},!0),this.setActivePoint(),i.activeObj=O.extend({},o,{},!0),n=O.extend({},i.activeObj.strokeSettings,{},!0),i.notify("draw",{prop:"setTempStrokeSettings",onPropertyChange:!1,value:{tempStrokeSettings:n}}),a=O.extend({},i.activeObj.textSettings,{},!0),i.notify("draw",{prop:"setTempTextSettings",onPropertyChange:!1,value:{tempTextSettings:a}}),n={cancel:!1,action:"select",previousShapeSettings:o=this.updatePrevShapeSettings(),currentShapeSettings:o},"line"!==i.activeObj.shape&&"arrow"!==i.activeObj.shape||(n.currentShapeSettings.width=i.activeObj.activePoint.endX-i.activeObj.activePoint.startX,n.currentShapeSettings.height=i.activeObj.activePoint.endY-i.activeObj.activePoint.startY),a=void(this.isCropSelection=!1),void 0!==(a=void 0!==i.activeObj.shape?i.activeObj.shape.split("-"):a)&&"crop"===a[0]&&(this.isCropSelection=!0),this.isCropSelection?(o={action:n.action,previousSelectionSettings:{type:i.getSelectionType(i.activeObj.shape),startX:n.previousShapeSettings.startX,startY:n.previousShapeSettings.startY,width:n.previousShapeSettings.width,height:n.previousShapeSettings.height},currentSelectionSettings:{type:i.getSelectionType(i.activeObj.shape),startX:n.currentShapeSettings.startX,startY:n.currentShapeSettings.startY,width:n.currentShapeSettings.width,height:n.currentShapeSettings.height}},i.trigger("selectionChanging",o),n.currentShapeSettings.startX=o.currentSelectionSettings.startX,n.currentShapeSettings.startY=o.currentSelectionSettings.startY,n.currentShapeSettings.width=o.currentSelectionSettings.width,n.currentShapeSettings.height=o.currentSelectionSettings.height):i.trigger("shapeChanging",n),this.shapeEvent(n),!0)}return r},c.prototype.shapeEvent=function(e){var t,o,i,r=this.parent;r.notify("shape",{prop:"updateShapeChangeEventArgs",onPropertyChange:!1,value:{shapeSettings:e.currentShapeSettings}}),r.activeObj.activePoint&&(r.notify("draw",{prop:"getPrevActObj",onPropertyChange:!(e={prevActObj:null}),value:{obj:e}}),O.isNullOrUndefined(e.prevActObj)&&r.notify("draw",{prop:"setPrevActObj",onPropertyChange:!1,value:{prevActObj:O.extend({},r.activeObj,{},!0)}}),"image"!==r.activeObj.shape||this.isImageClarity||(this.upgradeImageQuality(),this.isImageClarity=!0),r.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate",obj:r.activeObj,isCropRatio:null,points:null,isPreventDrag:!0,saveContext:null,isPreventSelection:!0}}),this.isShapeInserted||(e=r.activeObj.activePoint,t=(r=r.img).destLeft,o=r.destWidth,i=r.destTop,r=r.destHeight,this.isPreventDragging=e.startX<t||e.endX>t+o||e.startY<i||e.endY>i+r))},c.prototype.upgradeImageQuality=function(){var e=this.parent,t=O.extend({},e.activeObj,null,!0),o=e.activeObj.imageCanvas.getContext("2d"),i={width:0,height:0};e.notify("transform",{prop:"calcMaxDimension",onPropertyChange:!1,value:{width:e.activeObj.imageElement.width,height:e.activeObj.imageElement.height,obj:i,isImgShape:null}}),e.notify("shape",{prop:"updateObj",onPropertyChange:!1,value:{dimObj:i,x:null,y:null}}),o.clearRect(0,0,e.activeObj.imageCanvas.width,e.activeObj.imageCanvas.height),this.applyTransformToImg(o),e.activeObj=t},c.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}})},c.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}]},c.prototype.calculateScale=function(e,t){e=this.getDistance(e[0],e[1]);return this.getDistance(t[0],t[1])/e},c.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)},c.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}}))},c.prototype.setTimer=function(e){var t=this.parent;10<this.timer&&(clearTimeout(this.timer),this.timer=0,t.notify("shape",{prop:"findTextTarget",onPropertyChange:!1,value:{e:e}}),O.Browser.isDevice)&&this.upperContext.clearRect(0,0,t.upperCanvas.width,t.upperCanvas.height)},c.prototype.applyCurrActObj=function(e,t){var o=this.parent,i=!1,r=O.extend({},o.activeObj,{},!0);if(!O.isNullOrUndefined(r.activePoint)){var n,a=r.activePoint,s=a.startX,l=a.startY,p=a.endX,a=a.endY,h=r.topLeftCircle?r.topLeftCircle.radius:0;if(e>=Math.floor(s)&&e<=Math.ceil(p)&&t>=Math.floor(l)&&t<=Math.ceil(a)?i=!0:0!==h&&e>=Math.floor(s)-h&&e<=Math.ceil(p)+h&&t>=Math.floor(l)-h&&t<=Math.ceil(a)+h?(i=!0,this.tempActiveObj={activePoint:{startX:0,startY:0,endX:0,endY:0,width:0,height:0},flipObjColl:[],triangle:[],triangleRatio:[]}):"text"!==r.shape&&"image"!==r.shape||""===this.dragElement?"line"===r.shape||"arrow"===r.shape?(h={x:s<p?s:p,y:l<a?l:a},s={x:p<s?s:p,y:a<l?l:a},e>=Math.floor(h.x)-5&&e<=Math.ceil(s.x)+5&&t>=Math.floor(h.y)-5&&t<=Math.ceil(s.y)+5&&(i=!0)):"path"===r.shape?"move"===(n=this.setCursorForPath(r,e,t,o.upperCanvas))&&(i=!0):"grabbing"===this.dragElement?i=!0:0!==r.rotatedAngle?("default"!==(n=this.setCursorForRotatedObject(r,e,t,o.upperCanvas))&&"grab"!==n||"n-resize"===this.dragElement||"e-resize"===this.dragElement||"s-resize"===this.dragElement||"w-resize"===this.dragElement)&&(i=!0):"block"!==o.textArea.style.display&&"inline-block"!==o.textArea.style.display||(i=!0):i=!0,!i){O.isNullOrUndefined(o.activeObj.currIndex)&&(p={id:"shape_"+(o.objColl.length+1)},o.notify("shape",{prop:"getNewShapeId",onPropertyChange:!1,value:{obj:p}}),o.activeObj.currIndex=p.id),o.notify("shape",{prop:"updImgRatioForActObj",onPropertyChange:!1}),void 0===o.activeObj.horTopLine||0===o.activeObj.horTopLine.startX||0===o.activeObj.horTopLine.endX||o.currObjType.isCustomCrop||""===o.currObjType.shape||o.objColl.push(O.extend({},o.activeObj,{},!0));if(-1<["rectangle","ellipse","line","arrow","path","text","image"].indexOf(o.activeObj.shape)){l=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 d=0;d<o.objColl.length;d++){var c={isInside:!1};o.notify("crop",{prop:"isObjInImage",onPropertyChange:!1,value:{obj:o.objColl[d],object:c}}),c.isInside&&(o.notify("shape",{prop:"apply",onPropertyChange:!1,value:{shape:o.objColl[d].shape,obj:o.objColl[d],canvas:null}}),o.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}))}o.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"zoom",pen:"zoom",isPreventApply:null}}),this.lowerContext.filter=l,o.activeObj.shape&&o.notify("shape",{prop:"apply",onPropertyChange:!1,value:{shape:null,obj:null,canvas:null}}),o.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.lowerContext}}),o.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.upperContext}}),o.isCircleCrop&&o.notify("crop",{prop:"cropCircle",onPropertyChange:!1,value:{context:this.lowerContext,isSave:null,isFlip:null}})}o.notify("toolbar",{prop:"refresh-main-toolbar",onPropertyChange:!1})}}},c.prototype.getCurrentFlipState=function(){var e,t=this.parent;0!==t.rotateFlipColl.length?(e=O.extend({},t.panPoint.totalPannedInternalPoint,{},!0),t.notify("draw",{prop:"callUpdateCurrTransState",onPropertyChange:!1}),t.panPoint.totalPannedInternalPoint=e):t.notify("draw",{prop:"callUpdateCurrTransState",onPropertyChange:!1})},c.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)},c.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")},c.prototype.padLeft=function(e,t,o){for(;e.length<t;)e=o+e;return e},c.prototype.deleteItem=function(){var e=this.parent;if(this.isFhdEditing){this.updateFreehandDrawColorChange();var t=O.extend({},e.cropObj,{},!0),o={currObj:{}};e.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:o}});(l=o.currObj).objColl=O.extend([],e.objColl,[],!0),l.pointColl=O.extend([],e.pointColl,[],!0),l.afterCropActions=O.extend([],e.afterCropActions,[],!0);var i={selPointColl:null},r=(e.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:i}}),l.selPointColl=O.extend([],i.selPointColl,[],!0),{freehandDrawSelectedId:null});e.notify("freehand-draw",{prop:"getFreehandDrawSelectedId",onPropertyChange:!1,value:{obj:r}}),e.notify("freehand-draw",{prop:"deleteFhd",value:{id:r.freehandDrawSelectedId}}),e.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"deleteFreehandDrawing",previousObj:l,previousObjColl:this.tempObjColl,previousPointColl:l.pointColl,previousSelPointColl:l.selPointColl,previousCropObj:t,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){r={prevActObj:null};if(e.notify("draw",{prop:"getPrevActObj",onPropertyChange:!1,value:{obj:r}}),r.prevActObj&&(r.prevActObj.activePoint.width=Math.abs(r.prevActObj.activePoint.width),r.prevActObj.activePoint.height=Math.abs(r.prevActObj.activePoint.height)),r.prevActObj&&JSON.stringify(r.prevActObj)!==JSON.stringify(e.activeObj)){var n=e.activeObj.currIndex;e.notify("draw",{prop:"performCancel",value:{isContextualToolbar:null,isFinalCancel:!0}});for(var a=0,s=e.objColl.length;a<s;a++)if(e.objColl[a].currIndex===n){e.objColl.splice(a,1),e.notify("draw",{prop:"render-image",value:{isMouseWheel:null}});break}}var l,o={isNewPath:null};e.notify("draw",{prop:"getNewPath",value:{obj:o}}),o.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})):e.activeObj.shape&&(e.objColl.push(e.activeObj),t=O.extend({},e.cropObj,{},!0),e.notify("filter",{prop:"getCurrentObj",onPropertyChange:!(r={currObj:{}}),value:{object:r}}),(l=r.currObj).objColl=O.extend([],e.objColl,[],!0),l.pointColl=O.extend([],e.pointColl,[],!0),l.afterCropActions=O.extend([],e.afterCropActions,[],!0),e.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!(i={selPointColl:null}),value:{obj:i}}),l.selPointColl=O.extend([],i.selPointColl,[],!0),e.objColl.pop(),o=this.updatePrevShapeSettings(),e.notify("shape",{prop:"setKeyHistory",onPropertyChange:!(r={cancel:!1,action:"delete",previousShapeSettings:o,currentShapeSettings:null}),value:{keyHistory:""}}),e.clearSelection(),e.trigger("shapeChanging",r),e.notify("toolbar",{prop:"refresh-main-toolbar",onPropertyChange:!1}),e.notify("draw",{prop:"render-image",value:{isMouseWheel:null}}),O.isNullOrUndefined(l.objColl[l.objColl.length-1].currIndex)||(e.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"deleteObj",previousObj:l,previousObjColl:this.tempObjColl,previousPointColl:l.pointColl,previousSelPointColl:l.selPointColl,previousCropObj:t,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")},c.prototype.updateFreehandDrawColorChange=function(){var e,t=this.parent,o={freehandSelectedIndex:null};t.notify("freehand-draw",{prop:"getFreehandSelectedIndex",onPropertyChange:!1,value:{obj:o}}),O.isNullOrUndefined(o.freehandSelectedIndex)||O.isNullOrUndefined(t.pointColl[o.freehandSelectedIndex])||"#42a5f5"!==t.pointColl[o.freehandSelectedIndex].strokeColor||(t.notify("freehand-draw",{prop:"getTempFreeHandDrawEditingStyles",value:{obj:e={tempFreeHandDrawEditingStyles:null}}}),t.pointColl[o.freehandSelectedIndex].strokeColor=e.tempFreeHandDrawEditingStyles.strokeColor)},c.prototype.updatePrevShapeSettings=function(e){var t=this.parent,o=[],i=(O.isNullOrUndefined(t.activeObj.currIndex)&&(i={id:"shape_"+(t.objColl.length+1)},t.notify("shape",{prop:"getNewShapeId",onPropertyChange:!1,value:{obj:i}}),t.activeObj.currIndex=i.id),"text"===t.activeObj.shape&&t.activeObj.textSettings&&(t.activeObj.textSettings.bold&&o.push("bold"),t.activeObj.textSettings.italic&&o.push("italic"),t.activeObj.textSettings.underline)&&o.push("underline"),t.activeObj.activePoint),r=i.startX,n=i.startY,a=i.endX,s=i.endY,l=i.width,i=i.height,p=t.activeObj,h=p.keyHistory,d=p.currIndex,c=p.shape,u=p.textSettings,g=p.strokeSettings,v=p.rotatedAngle,f=p.imageElement,p=p.opacity,d={id:O.isNullOrUndefined(d)?null:d,type:t.toPascalCase(c),startX:r,startY:n,width:l,height:i,strokeColor:g?g.strokeColor:null,strokeWidth:g?g.strokeWidth:null,fillColor:g?g.fillColor:null,radius:"ellipse"===c?l/2:null,length:"line"===c||"arrow"===c?l:null,text:"text"===c&&(h||u.text)||null,fontSize:"text"===c&&u?u.fontSize:null,fontFamily:"text"===c&&u?u.fontFamily:null,fontStyle:"text"===c?o:null,color:"text"===c&&g?g.strokeColor:null,degree:"ellipse"===c||"rectangle"===c||"image"===c||"text"===c?v*(180/Math.PI):null,imageData:"image"===c?f.src:null,opacity:"image"===c?p:null,radiusX:"ellipse"===c?l/2:null,radiusY:"ellipse"===c?i/2:null,endX:"line"===c||"arrow"===c?a:null,endY:"line"===c||"arrow"===c?s:null,arrowHead:"arrow"===c?this.getArrowType(t.activeObj.start):null,arrowTail:"arrow"===c?this.getArrowType(t.activeObj.end):null,points:"path"===c?t.activeObj.pointColl:null,index:t.activeObj.order};return e&&(e.shapeSettingsObj=d),d},c.prototype.getArrowType=function(e){return{none:"None",arrow:"Arrow",arrowSolid:"SolidArrow",circle:"Circle",circleSolid:"SolidCircle",square:"Square",squareSolid:"SolidSquare",bar:"Bar"}[""+e]},c.prototype.getRectanglePoints=function(e,t,o,i,r,n,a){var e=e+o/2,t=t+i/2,r=r*(Math.PI/180),s=Math.cos(r),r=Math.sin(r),n=n-e,e=a-t,a=n*s+e*r,t=-n*r+e*s,n=o/2,r=i/2;return-n<=a&&a<=n&&-r<=t&&t<=r},c.prototype.getTransRotationPoint=function(e,t){var o,i=!1,r=!1,n=0===e.shapeDegree?this.parent.transform.degree:this.parent.transform.degree-e.shapeDegree;if(n<0&&(n=360+n),e.flipObjColl)for(var a=0,s=e.flipObjColl.length;a<s;a++)"horizontal"===e.flipObjColl[a].toLowerCase()?i=!0:"vertical"===e.flipObjColl[a].toLowerCase()&&(r=!0);return 0===n||360===n?o=r?{x:e.topCenterCircle.startX,y:e.topCenterCircle.startY-e.rotationCircleLine}:{x:e.bottomCenterCircle.startX,y:e.bottomCenterCircle.startY+e.rotationCircleLine}:90===n||-270===n?o=i?{x:e.centerRightCircle.startX+e.rotationCircleLine,y:e.centerLeftCircle.startY}:{x:e.centerLeftCircle.startX-e.rotationCircleLine,y:e.centerLeftCircle.startY}:180===n||-180===n?o=r?{x:e.bottomCenterCircle.startX,y:e.bottomCenterCircle.startY+e.rotationCircleLine}:{x:e.topCenterCircle.startX,y:e.topCenterCircle.startY-e.rotationCircleLine}:270!==n&&-90!==n||(o=i?{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},c.prototype.getNumTextValue=function(e){var t,o,i=this.parent.element,r=i.querySelector("#"+i.id+"_resizeWidth"),i=i.querySelector("#"+i.id+"_resizeHeight");return r&&i&&(t=i.value.replace(/,/g,""),o=r.value.replace(/,/g,""),""===t&&(t=i.placeholder.replace(/,/g,"")),""===o&&(o=r.placeholder.replace(/,/g,"")),t=parseFloat(t),o=parseFloat(o)),e&&(e.width=o,e.height=t),{x:o,y:t}},c.prototype.isValueUpdated=function(){var e=!0,t=this.parent.element.querySelector("#"+this.parent.element.id+"_resizeWidth"),o=this.parent.element.querySelector("#"+this.parent.element.id+"_resizeHeight");return e=t&&o&&""===o.value.replace(/,/g,"")&&""===t.value.replace(/,/g,"")?!1:e};var h=c;function c(e){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=[v.ArrowheadType.None,v.ArrowheadType.SolidArrow],this.parent=e,this.addEventListener()}C.prototype.destroy=function(){this.parent.isDestroyed||this.removeEventListener()},C.prototype.addEventListener=function(){this.parent.on("shape",this.shape,this),this.parent.on("destroyed",this.destroy,this)},C.prototype.removeEventListener=function(){this.parent.off("shape",this.shape),this.parent.off("destroyed",this.destroy)},C.prototype.shape=function(e){var t,o=this.parent;switch(this.initShapePvtProps(),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":O.EventHandler.add(o.upperCanvas,"dblclick",this.findTextTarget,this),O.EventHandler.add(o.textArea,"mousedown",this.findTextTarget,this),(t=document.getElementById(o.element.id+"_fileUpload"))&&O.EventHandler.add(t,"change",this.fileChanged,this);break;case"unWireEvent":O.EventHandler.remove(o.upperCanvas,"dblclick",this.findTextTarget),O.EventHandler.remove(o.textArea,"mousedown",this.findTextTarget),(t=document.getElementById(o.element.id+"_fileUpload"))&&O.EventHandler.remove(t,"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()}},C.prototype.getModuleName=function(){return"shape"},C.prototype.initShapePvtProps=function(){var e=this.parent;e.lowerCanvas&&(this.lowerContext=e.lowerCanvas.getContext("2d")),e.upperCanvas&&(this.upperContext=e.upperCanvas.getContext("2d")),O.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)},C.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},C.prototype.drawEllipse=function(e,t,o,i,r,n,a,s,l){this.initializeShape("ellipse"),this.drawShape("ellipse",r,n,a,e&&t?{x:e,y:t}:null,o,i,null,null,null,s,null,l)},C.prototype.drawLine=function(e,t,o,i,r,n,a){this.initializeShape("line"),this.drawShape("line",r,n,null,e&&t?{x:e,y:t}:null,o-e,i-t,null,null,null,null,null,a)},C.prototype.drawPath=function(e,t,o,i){var r=this.parent;this.initializeShape("path"),e?this.drawShape("path",t,o,null,null,null,null,e,null,null,null,null,i):(this.drawShape("line",t,o,null,null,null,null,null,null,null,null,null,i),(e=O.extend({},r.objColl[r.objColl.length-1],null,!0)).shape="path",e.lineDraw=null,e.pointColl=[{x:e.activePoint.startX,y:e.activePoint.startY},{x:e.activePoint.endX,y:e.activePoint.endY}],r.objColl[r.objColl.length-1]=e)},C.prototype.drawArrow=function(e,t,o,i,r,n,a,s,l){this.initializeShape("arrow"),this.drawShape("arrow",r,n,null,e&&t?{x:e,y:t}:null,o-e,i-t,null,a,s,null,null,l)},C.prototype.drawRectangle=function(e,t,o,i,r,n,a,s,l){this.initializeShape("rectangle"),this.drawShape("rectangle",r,n,a,e&&t?{x:e,y:t}:null,o,i,null,null,null,s,null,l)},C.prototype.drawText=function(e,t,o,i,r,n,a,s,l,p){this.drawShapeText(o,i,r,n,a,s,e,t,l,p)},C.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},C.prototype.updateWidthHeight=function(e){return e.activePoint.width=e.activePoint.endX-e.activePoint.startX,e.activePoint.height=e.activePoint.endY-e.activePoint.startY,e},C.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)},C.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},C.prototype.drawShape=function(e,t,o,i,r,n,a,s,l,p,h,d,c){var u,g,v=this.parent;!v.disabled&&v.isImageLoaded&&(v.notify("draw",{prop:"setImageEdited",onPropertyChange:!1}),this.redrawActObj(),u=O.extend([],v.objColl,[],!0),v.togglePen=!1,this.keyHistory="",v.upperCanvas.style.display="block",this.refreshActiveObj(),v.currObjType.shape=e=e.toLowerCase(),"path"===e&&O.isNullOrUndefined(s)?(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})):"freehanddraw"!==e&&""!==e&&(v.activeObj.shape=e,g=v.activeObj.strokeSettings,this.upperContext.clearRect(0,0,v.upperCanvas.width,v.upperCanvas.height),O.isNullOrUndefined(g)&&(g=this.strokeSettings),"path"===e&&s&&(v.activeObj.pointColl=s),null!=d&&(v.activeObj.opacity=d),g.strokeWidth=t||g.strokeWidth,g.strokeColor=o||g.strokeColor,g.fillColor=i||g.fillColor,s=100<v.img.destWidth?100:v.img.destWidth/2,d=100<v.img.destHeight?100:v.img.destHeight/2,v.activeObj.activePoint.width=s,v.activeObj.activePoint.height=d,"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(l),v.activeObj.end=this.getArrowType(p))):"rectangle"===e&&(v.activeObj.activePoint.width+=v.activeObj.activePoint.width/2),this.setDimension(n,a),r?(v.activeObj.activePoint.startX=r.x,v.activeObj.activePoint.startY=r.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(),v.notify("selection",{prop:"updatePrevShapeSettings",onPropertyChange:!(t={shapeSettingsObj:{}}),value:{obj:t}}),v.trigger("shapeChanging",i={cancel:!1,action:"insert",previousShapeSettings:o=t.shapeSettingsObj,currentShapeSettings:o}),this.updateShapeChangeEventArgs(i.currentShapeSettings),this.setDimension(n,a),v.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate"}}),h&&(v.activeObj.rotatedAngle=h*(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:u}}),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&&!c&&v.notify("undo-redo",{prop:"updateUndoRedo",value:{operation:"shapeInsert"},onPropertyChange:!1}),v.isPublicMethod=!1))},C.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()},C.prototype.setPointCollForLineAndArrow=function(){var e=this.parent,t=e.activeObj.shape,o=e.activeObj.activePoint,i=o.startX,r=o.startY,n=o.endX,o=o.endY;if(("line"===t||"arrow"===t)&&(e.activeObj.pointColl=this.getLinePoints(i,r,n,o),e.activeObj.pointColl))for(var a=0,s=e.activeObj.pointColl.length;a<s;a++)e.activeObj.pointColl[a].ratioX=(e.activeObj.pointColl[a].x-e.img.destLeft)/e.img.destWidth,e.activeObj.pointColl[a].ratioY=(e.activeObj.pointColl[a].y-e.img.destTop)/e.img.destHeight},C.prototype.prevObjColl=function(){var e=this.parent,t={currObj:{}},t=(e.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:t}}),this.prevObj=t.currObj,this.prevObj.objColl=O.extend([],e.objColl,[],!0),this.prevObj.pointColl=O.extend([],e.pointColl,[],!0),this.prevObj.afterCropActions=O.extend([],e.afterCropActions,[],!0),{selPointColl:null});e.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:t}}),this.prevObj.selPointColl=O.extend([],t.selPointColl,[],!0)},C.prototype.drawShapeText=function(e,t,o,i,r,n,a,s,l,p){var h=this.parent;!h.disabled&&h.isImageLoaded&&("freehanddraw"===h.currObjType.shape&&(this.apply(),h.upperCanvas.style.cursor=h.cursor="default",h.currObjType.shape=""),h.notify("draw",{prop:"setImageEdited",onPropertyChange:!1}),h.togglePen=!1,this.redrawActObj(),this.prevObjColl(),this.refreshActiveObj(),h.activeObj.shape=h.currObjType.shape="text",h.currObjType.isCustomCrop=!1,this.initializeTextShape(e,t,o,i,r,n),h.currObjType.isText=h.currObjType.isInitialText=!0,O.isNullOrUndefined(h.activeObj.textSettings.fontSize)&&(h.getFontSizes(),h.activeObj.textSettings.fontSize=parseInt(h.fontSizeColl[parseInt("3",10)-1].text,10)),h.img.destWidth<100?h.activeObj.textSettings.fontSize=Math.floor(h.img.destWidth/20):h.img.destHeight<100&&(h.activeObj.textSettings.fontSize=Math.floor(h.img.destHeight/20)),h.activeObj.shapeDegree=h.transform.degree,h.activeObj.shapeFlip=h.transform.currFlipState,h.activeObj.flipObjColl=[],this.updateFontStyles(),h.activeObj.order=this.getNewOrder(),e=this.upperContext.measureText(h.activeObj.textSettings.text).width+.5*h.activeObj.textSettings.fontSize,t=h.activeObj.textSettings.fontSize+.25*h.activeObj.textSettings.fontSize,O.isNullOrUndefined(a)||O.isNullOrUndefined(s)?this.setCenterPoints(!0,e,t):(h.activeObj.activePoint.startX=a,h.activeObj.activePoint.startY=s,h.activeObj.activePoint.endX=h.activeObj.activePoint.startX+e,h.activeObj.activePoint.endY=h.activeObj.activePoint.startY+t),h.notify("selection",{prop:"updatePrevShapeSettings",onPropertyChange:!(o={shapeSettingsObj:{}}),value:{obj:o}}),h.trigger("shapeChanging",r={cancel:!1,action:"insert",previousShapeSettings:i=o.shapeSettingsObj,currentShapeSettings:i}),this.drawShapeTextEvent(r),p&&(h.activeObj.rotatedAngle=p*(Math.PI/180),h.notify("selection",{prop:"updPtCollForShpRot",onPropertyChange:!1,value:{obj:h.activeObj}}),this.upperContext.clearRect(0,0,h.upperCanvas.width,h.upperCanvas.height),h.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate",obj:h.activeObj,isCropRatio:null,points:null,isPreventDrag:!0,saveContext:null,isPreventSelection:null}}),h.notify("toolbar",{prop:"destroy-qa-toolbar",onPropertyChange:!1}),h.notify("toolbar",{prop:"renderQAT",onPropertyChange:!1,value:{isPenEdit:null}})),h.isPublicMethod&&!l&&h.notify("undo-redo",{prop:"updateUndoRedo",value:{operation:"shapeInsert"},onPropertyChange:!1}),h.isPublicMethod=!1)},C.prototype.drawShapeImageEvent=function(e,t){var o=this.parent,e=(this.updateShapeChangeEventArgs(e.currentShapeSettings),o.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate"}}),o.objColl.push(o.activeObj),O.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:e,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),o.notify("selection",{prop:"redrawShape",onPropertyChange:!1,value:{obj:o.objColl[o.objColl.length-1]}}),t?(o.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"shapes",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}}),o.notify("toolbar",{prop:"update-toolbar-items",onPropertyChange:!1}),o.notify("toolbar",{prop:"renderQAT",onPropertyChange:!1,value:{isPenEdit:null}})):o.okBtn(null,!0),o.notify("selection",{prop:"isShapeInserted",onPropertyChange:!1,value:{bool:!0}})},C.prototype.drawShapeTextEvent=function(e){var t=this.parent,e=(this.updateShapeChangeEventArgs(e.currentShapeSettings),this.addLetter(t.activeObj.textSettings.text),t.activeObj.textFlip=t.transform.currFlipState,this.updateFontRatio(t.activeObj),t.objColl.push(t.activeObj),O.extend({},t.cropObj,{},!0));t.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:e,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),t.notify("selection",{prop:"redrawShape",onPropertyChange:!1,value:{obj:t.objColl[t.objColl.length-1]}}),t.notify("toolbar",{prop:"renderQAT",onPropertyChange:!1,value:{isPenEdit:null}}),t.notify("selection",{prop:"isShapeInserted",onPropertyChange:!1,value:{bool:!0}}),t.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"text",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}}),t.notify("toolbar",{prop:"update-toolbar-items",onPropertyChange:!1})},C.prototype.initializeTextShape=function(e,t,o,i,r,n){var a=this.parent;this.keyHistory="",a.upperCanvas.style.display="block",O.isNullOrUndefined(a.activeObj.textSettings)&&(a.activeObj.textSettings=this.textSettings),O.isNullOrUndefined(a.activeObj.strokeSettings)&&(a.activeObj.strokeSettings=this.strokeSettings),a.activeObj.strokeSettings.strokeColor=n||a.activeObj.strokeSettings.strokeColor,a.activeObj.textSettings.text=e||a.activeObj.textSettings.text,a.activeObj.textSettings.fontFamily=t||a.activeObj.textSettings.fontFamily,a.activeObj.textSettings.fontSize=o||a.activeObj.textSettings.fontSize,a.activeObj.textSettings.bold=i||a.activeObj.textSettings.bold,a.activeObj.textSettings.italic=r||a.activeObj.textSettings.italic},C.prototype.drawImage=function(e,t,o,i,r,n,a,s,l){this.initializeShape("image"),this.onLoadImgShape(e,t,o,i,r,null,n,a,s,l)},C.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))},C.prototype.apply=function(e,t,o){var i,r,n,a,s,l=this.parent;l.disabled||(l.togglePen&&!l.currObjType.isCustomCrop?(i=l.img.destLeft,r=l.img.destTop,n=l.img.destWidth,a=l.img.destHeight,l.notify("draw",{prop:"callUpdateCurrTransState",onPropertyChange:!1}),s=this.lowerContext.filter,this.lowerContext.filter="none",l.togglePen=!1,(l.isCircleCrop||l.currSelectionPoint&&"crop-circle"===l.currSelectionPoint.shape)&&l.notify("crop",{prop:"cropCircle",onPropertyChange:!1,value:{context:this.lowerContext,isSave:null,isFlip:null}}),l.img.destLeft=i,l.img.destTop=r,l.img.destWidth=n,l.img.destHeight=a,this.lowerContext.filter=s):(o=o||"original",O.isNullOrUndefined(l.activeObj.shape)&&O.isNullOrUndefined(e)?l.currObjType.shape="":l.currObjType.shape=e||l.currObjType.shape,""!==l.currObjType.shape&&(this.upperContext.clearRect(0,0,l.upperCanvas.width,l.upperCanvas.height),"text"===l.activeObj.shape?l.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:o,obj:t,isCropRatio:null,points:null,isPreventDrag:!0,saveContext:null,isPreventSelection:null}}):l.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:o,obj:t}}),l.activeObj.shape=l.currObjType.shape.toLowerCase(),e||""===l.currObjType.shape||l.currObjType.isCustomCrop||l.objColl.push(O.extend({},l.activeObj,{},!0)),this.keyHistory="")))},C.prototype.setCenterPoints=function(e,t,o){var i,r=this.parent,e=e&&t&&o?(i=t,o):(i=r.activeObj.activePoint.width,r.activeObj.activePoint.height);r.activeObj.activePoint.startX=r.lowerCanvas.width/2-i/2,r.activeObj.activePoint.startY=r.lowerCanvas.height/2-e/2,r.activeObj.activePoint.endX=r.lowerCanvas.width/2+i/2,r.activeObj.activePoint.endY=r.lowerCanvas.height/2+e/2},C.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},C.prototype.updateShapeChangeEventArgs=function(e){var t,o=this.parent;if(e.id&&-1===e.id.indexOf("shape_")&&-1===e.id.indexOf("pen_")&&(o.activeObj.currIndex?o.activeObj.currIndex="shape_"+e.id:o.pointColl[t].id="pen_"+e.id),e.id&&e.id.split("_")[0]&&"pen"===e.id.split("_")[0])t=parseInt(e.id.split("_")[1],10)-1,o.pointColl[t].points=e.points,o.pointColl[t].strokeColor=e.strokeColor,o.pointColl[t].strokeWidth=e.strokeWidth,o.pointColl[t].opacity=e.opacity,o.pointColl[t].order=e.index;else{switch(o.activeObj.activePoint.startX=e.startX,o.activeObj.activePoint.startY=e.startY,e.width&&e.height&&(o.activeObj.activePoint.width=e.width,o.activeObj.activePoint.height=e.height,o.activeObj.activePoint.endX=o.activeObj.activePoint.startX+o.activeObj.activePoint.width,o.activeObj.activePoint.endY=o.activeObj.activePoint.startY+o.activeObj.activePoint.height),o.activeObj.strokeSettings.strokeColor=e.strokeColor,o.activeObj.strokeSettings.fillColor=e.fillColor,o.activeObj.strokeSettings.strokeWidth=e.strokeWidth,o.activeObj.opacity=e.opacity,o.activeObj.order=e.index,O.isNullOrUndefined(e.degree)&&(e.degree=0),o.activeObj.shape){case"ellipse":o.activeObj.activePoint.width=2*e.radiusX,o.activeObj.activePoint.height=2*e.radiusY,o.activeObj.activePoint.endX=o.activeObj.activePoint.startX+o.activeObj.activePoint.width,o.activeObj.activePoint.endY=o.activeObj.activePoint.startY+o.activeObj.activePoint.height,e.degree&&(o.activeObj.rotatedAngle=e.degree*(Math.PI/180));break;case"line":case"arrow":o.activeObj.activePoint.width=e.length,o.activeObj.activePoint.endX=e.endX,o.activeObj.activePoint.endY=e.endY,o.activeObj.activePoint.width=o.activeObj.activePoint.startX+o.activeObj.activePoint.width,o.activeObj.activePoint.height=o.activeObj.activePoint.startY+o.activeObj.activePoint.height,"arrow"===o.activeObj.shape&&(o.activeObj.start=this.getArrowType(e.arrowHead),o.activeObj.end=this.getArrowType(e.arrowTail));break;case"text":o.activeObj.keyHistory=o.activeObj.textSettings.text=e.text,o.activeObj.textSettings.fontSize=e.fontSize,o.activeObj.strokeSettings.strokeColor=e.color,o.activeObj.textSettings.fontFamily=e.fontFamily,e.degree&&(o.activeObj.rotatedAngle=e.degree*(Math.PI/180)),this.updateFontRatio(o.activeObj);break;case"rectangle":case"image":e.degree&&(o.activeObj.rotatedAngle=e.degree*(Math.PI/180));break;case"path":o.activeObj.pointColl=e.points}if("text"===o.activeObj.shape&&o.activeObj.textSettings){o.activeObj.textSettings.bold=!1,o.activeObj.textSettings.italic=!1,o.activeObj.textSettings.underline=!1;for(var i=0;i<e.fontStyle.length;i++)switch(e.fontStyle[i]){case"bold":o.activeObj.textSettings.bold=!0;break;case"italic":o.activeObj.textSettings.italic=!0;break;case"underline":o.activeObj.textSettings.underline=!0}}}},C.prototype.addLetter=function(e){var t,o,i=this.parent;"none"!==i.textArea.style.display||!i.currObjType.isText&&"text"!==i.activeObj.shape||(t=i.activeObj.textSettings.fontSize,"Backspace"===e?this.keyHistory=this.keyHistory.slice(0,-1):this.keyHistory+=e,this.upperContext.clearRect(0,0,i.upperCanvas.width,i.upperCanvas.height),this.updateFontStyles(),e=this.upperContext.measureText(this.keyHistory).width+.5*t,o=t+.25*t,this.upperContext.fillText(this.keyHistory,i.activeObj.activePoint.startX,i.activeObj.activePoint.startY+t),this.upperContext.clearRect(0,0,i.upperCanvas.width,i.upperCanvas.height),i.currObjType.isText=!0,i.notify("selection",{prop:"setActivePoint",onPropertyChange:!1,value:{startX:e,startY:o}}))},C.prototype.redrawText=function(){var e=this.parent,t=e.activeObj.textSettings,o=t.fontSize,i=t.fontFamily,r="",t=(t.bold&&(r+="bold "),t.italic&&(r+="italic "),this.upperContext.font=r+o+"px "+i,e.activeObj.keyHistory.split("\n")),r="block"===e.textArea.style.display||"inline-block"===e.textArea.style.display?this.getMaxText(!0):this.getMaxText(),i=this.upperContext.measureText(r).width+.5*o,r=t.length*(o+.25*o);e.notify("selection",{prop:"setTextSelection",onPropertyChange:!1,value:{width:i,height:r}}),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}})},C.prototype.updateTextFromTextArea=function(){var e,t=this.parent,o=!1,i=t.activeObj.textSettings.fontSize,r=O.extend({},t.activeObj,{},!0),n=O.extend({},t.cropObj,{},!0),a={currObj:{}},a=(t.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:a}}),a.currObj),s=(a.objColl=O.extend([],t.objColl,[],!0),a.pointColl=O.extend([],t.pointColl,[],!0),a.afterCropActions=O.extend([],t.afterCropActions,[],!0),{selPointColl:null}),s=(t.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:s}}),a.selPointColl=O.extend([],s.selPointColl,[],!0),t.activeObj.keyHistory!==t.textArea.value&&(o=!0),t.activeObj.keyHistory=t.textArea.value,t.textArea.style.display="none",t.textArea.value="",this.updateFontStyles(),this.upperContext.measureText(t.activeObj.keyHistory).width+.5*i),l=i+.25*i,p=t.activeObj.keyHistory.split("\n");if(1<p.length){l*=p.length;for(var h=[],d=0,c=p.length;d<c;d++)h.push(this.upperContext.measureText(p[d]).width+.5*i);s=Math.max.apply(Math,h)}t.notify("selection",{prop:"setTextSelection",onPropertyChange:!1,value:{width:s,height:l}}),0!==t.activeObj.rotatedAngle&&(s=t.activeObj.activePoint.width-r.activePoint.width,l=t.activeObj.activePoint.height-r.activePoint.height,e="",0<s&&0<l?e="widthHeight":0!=s?e="width":0!=l&&(e="height"),t.activeObj.activePoint=O.extend({},r.activePoint,{},!0),t.notify("selection",{prop:"adjustRotationPoints",onPropertyChange:!1,value:{rectangle:t.activeObj.activePoint,x:s,y:l,angle:t.activeObj.rotatedAngle,type:"text",elem:e}}),t.notify("shape",{prop:"updateFontSize",onPropertyChange:!1,value:{obj:t.activeObj}})),t.notify("draw",{prop:"updateActiveObject",onPropertyChange:!1,value:{actPoint:t.activeObj.activePoint,obj:t.activeObj,isMouseMove:null,x:null,y:null}}),this.updImgRatioForActObj(),0!==t.activeObj.rotatedAngle&&t.notify("selection",{prop:"updPtCollForShpRot",onPropertyChange:!1,value:{obj:t.activeObj}}),o?(this.apply(t.activeObj.shape,t.activeObj),t.objColl.push(O.extend({},t.activeObj,{},!0)),t.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"text",previousObj:a,previousObjColl:a.objColl,previousPointColl:a.pointColl,previousSelPointColl:a.selPointColl,previousCropObj:n,previousText:t.activeObj.keyHistory,currentText:t.textArea.value,previousFilter:null,isCircleCrop:null}})):(this.apply(t.activeObj.shape,t.activeObj),t.objColl.push(O.extend({},t.activeObj,{},!0)))},C.prototype.iterateObjColl=function(){var e=this.parent;if(0<e.objColl.length)for(var t=this.getSmallestIndex(),o=O.extend([],e.objColl,[],!0);0<o.length;){for(var i=!1,r=0;r<o.length;r++){var n=o[r];if(O.isNullOrUndefined(n.order))o.splice(r,1),r--;else if(n.order===t){this.apply(n.shape,n),this.refreshActiveObj(),t++,this.isIndexInObjColl(t)||t++,o.splice(r,1),i=!0;break}}if(!i)break}},C.prototype.getSmallestIndex=function(){for(var e,t=this.parent,o=0,i=t.objColl.length;o<i;o++){var r=t.objColl[o];O.isNullOrUndefined(r.order)||(O.isNullOrUndefined(e)||r.order<e)&&(e=r.order)}return e},C.prototype.isIndexInObjColl=function(e){for(var t=this.parent,o=0,i=t.objColl.length;o<i;o++){var r=t.objColl[o];if(!O.isNullOrUndefined(r.order)&&r.order===e)return!0}return!1},C.prototype.updImgRatioForActObj=function(){var e=this.parent,t={startX:e.img.destLeft,startY:e.img.destTop,width:e.img.destWidth,height:e.img.destHeight},o=(this.straightenShapes(),e.img),i=o.destLeft,r=o.destTop,n=o.destWidth,o=o.destHeight,a=e.activeObj.activePoint;e.activeObj.imageRatio={startX:(a.startX-i)/n,startY:(a.startY-r)/o,endX:(a.endX-i)/n,endY:(a.endY-r)/o,width:n/a.width,height:o/a.height},e.activeObj.rotationCirclePointColl&&(e.activeObj.rotationCirclePointColl.ratioX=(e.activeObj.rotationCirclePointColl.x-i)/n,e.activeObj.rotationCirclePointColl.ratioY=(e.activeObj.rotationCirclePointColl.y-r)/o),"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},C.prototype.zoomObjColl=function(e){var t=this.parent,o={startX:t.img.destLeft,startY:t.img.destTop,width:t.img.destWidth,height:t.img.destHeight};if(this.straightenShapes(),0<t.objColl.length){for(var i=0,r=t.objColl.length;i<r;i++){var n=t.objColl[i];if(n.imageRatio&&(n.activePoint.startX=n.imageRatio.startX*t.img.destWidth+t.img.destLeft,n.activePoint.startY=n.imageRatio.startY*t.img.destHeight+t.img.destTop,n.activePoint.endX=n.imageRatio.endX*t.img.destWidth+t.img.destLeft,n.activePoint.endY=n.imageRatio.endY*t.img.destHeight+t.img.destTop),"text"===(n=this.updateWidthHeight(n)).shape)this.updateFontSize(n);else if("line"===n.shape||"arrow"===n.shape){n.pointColl=this.getLinePoints(n.activePoint.startX,n.activePoint.startY,n.activePoint.endX,n.activePoint.endY);for(var a=0,s=n.pointColl.length;a<s;a++)n.pointColl[a].ratioX=(n.pointColl[a].x-t.img.destLeft)/t.img.destWidth,n.pointColl[a].ratioY=(n.pointColl[a].y-t.img.destTop)/t.img.destHeight;"arrow"===n.shape&&this.updateArrowSize(n),0===t.transform.straighten||"line"!==n.shape&&"arrow"!==n.shape||this.straightenShapePoints(n)}else if("path"===n.shape){for(var l=0,p=n.pointColl.length;l<p;l++)n.pointColl[l].x=n.pointColl[l].ratioX*t.img.destWidth+t.img.destLeft,n.pointColl[l].y=n.pointColl[l].ratioY*t.img.destHeight+t.img.destTop;this.updatePathRatio(n),0!==t.transform.straighten&&this.straightenPath(n)}t.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*t.img.destWidth+t.img.destLeft,n.rotationCirclePoint.y=n.rotationCirclePoint.ratioY*t.img.destHeight+t.img.destTop,n.rotationCirclePointColl)&&(n.rotationCirclePointColl.x=n.rotationCirclePointColl.ratioX*t.img.destWidth+t.img.destLeft,n.rotationCirclePointColl.y=n.rotationCirclePointColl.ratioY*t.img.destHeight+t.img.destTop)}O.isNullOrUndefined(e)&&(e=this.lowerContext.filter,this.lowerContext.filter="none",this.iterateObjColl(),this.lowerContext.filter=e)}t.img.destLeft=o.startX,t.img.destTop=o.startY,t.img.destWidth=o.width,t.img.destHeight=o.height},C.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},C.prototype.straightenFHD=function(){for(var e=this.parent,t=0,o=e.freehandCounter;t<o;t++){e.points=O.extend([],e.pointColl[t].points,[]);for(var i=e.points.length,r=void 0,n=0;n<i;n++)r=this.straightenPoints(e.points[n].x,e.points[n].y),e.points[n].x=r.x,e.points[n].y=r.y}var a={selPointColl:null};e.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:a}});for(t=0,o=e.freehandCounter;t<o;t++)for(i=a.selPointColl[t].points.length,r=void 0,n=0;n<i;n++)r=this.straightenPoints(a.selPointColl[t].points[n].x,a.selPointColl[t].points[n].y),a.selPointColl[t].points[n].x=r.x,a.selPointColl[t].points[n].y=r.y;var s,l={straightenPoint:null};e.notify("freehand-draw",{prop:"getStraightenPoint",onPropertyChange:!1,value:{obj:l}}),l.straightenPoint.x&&l.straightenPoint.y&&(e.notify("freehand-draw",{prop:"getStraightenPointAngle",onPropertyChange:!(s={angle:0}),value:{obj:s}}),s=((360===e.transform.straighten?0:e.transform.straighten)-s.angle)*(Math.PI/180),r=this.straightenPoints(l.straightenPoint.x,l.straightenPoint.y,s),0==s&&(r.x=l.straightenPoint.x,r.y=l.straightenPoint.y),e.notify("freehand-draw",{prop:"setStraightenPoint",onPropertyChange:!1,value:{x:r.x,y:r.y}}))},C.prototype.straightenPoints=function(e,t,o){var i=this.parent,r=i.img.destLeft+i.img.destWidth/2,n=i.img.destTop+i.img.destHeight/2;return o=o||i.transform.straighten*(Math.PI/180),{x:Math.cos(o)*(e-r)-Math.sin(o)*(t-n)+r,y:Math.sin(o)*(e-r)+Math.cos(o)*(t-n)+n}},C.prototype.straightenShapes=function(){var e,t,o,i=this.parent,r=i.img,n=r.destLeft,a=r.destTop,s=r.destWidth,r=r.destHeight;i.isStraightening&&0!==i.transform.straighten&&(i.notify("draw",{prop:"updateImgCanvasPoints"}),i.notify("draw",{prop:"getImageCanvasPoints",value:{obj:e={points:null}}}),n=n+s/2,s=a+r/2,a=-(i.transform.straighten*(Math.PI/180)),r={x:Math.cos(a)*(e.points[0].x-n)-Math.sin(a)*(e.points[0].y-s)+n,y:Math.sin(a)*(e.points[0].x-n)+Math.cos(a)*(e.points[0].y-s)+s},t=Math.cos(a)*(e.points[1].x-n)-Math.sin(a)*(e.points[1].y-s)+n,o=Math.sin(a)*(e.points[1].x-n)+Math.cos(a)*(e.points[1].y-s)+s,Math.cos(a),e.points[2].x,Math.sin(a),e.points[2].y,n=Math.sin(a)*(e.points[2].x-n)+Math.cos(a)*(e.points[2].y-s)+s,i.img.destWidth=t-r.x,i.img.destHeight=n-o,i.img.destLeft=r.x,i.img.destTop=r.y)},C.prototype.straightenShapePoints=function(e,t){var o=this.parent,i=o.img,r=i.destLeft,n=i.destTop,a=i.destWidth,i=i.destHeight;!o.isStraightening||"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,r=r+a/2,a=n+i/2,n=(t?-o.transform.straighten:o.transform.straighten)*(Math.PI/180),i={x:Math.cos(n)*(e.activePoint.startX-r)-Math.sin(n)*(e.activePoint.startY-a)+r,y:Math.sin(n)*(e.activePoint.startX-r)+Math.cos(n)*(e.activePoint.startY-a)+a},t={x:Math.cos(n)*(e.activePoint.endX-r)-Math.sin(n)*(e.activePoint.endY-a)+r,y:Math.sin(n)*(e.activePoint.endX-r)+Math.cos(n)*(e.activePoint.endY-a)+a},e.activePoint.startX=i.x,e.activePoint.startY=i.y,e.activePoint.endX=t.x,e.activePoint.endY=t.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}}))},C.prototype.redrawObj=function(e){var t=this.parent,o=!1;if(0<t.objColl.length)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);e=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 i=0,r=t.objColl.length;i<r;i++)"crop"!==t.objColl[i].shape.split("-")[0]&&(this.apply(t.objColl[i].shape,t.objColl[i]),o=!0);o&&t.notify("draw",{prop:"applyFrame",value:{ctx:this.lowerContext,frame:t.frameObj.type,preventImg:!0}}),this.lowerContext.filter=e}},C.prototype.updateCurrentActiveObjPoint=function(e){for(var t,o=this.parent,i=o.img,r=i.destLeft,n=i.destTop,a=i.destWidth,s=i.destHeight,l=0,p=o.objColl.length;l<p;l++){var h=o.objColl[l];if(o.activeObj.shape===h.shape&&o.activeObj.activePoint.startX===h.activePoint.startX&&o.activeObj.activePoint.startY===h.activePoint.startY&&o.activeObj.activePoint.endX===h.activePoint.endX&&o.activeObj.activePoint.endY===h.activePoint.endY&&o.activeObj.currIndex===h.currIndex){t=l;break}}if("horizontal"===e||"vertical"===e||"Horizontal"===e||"Vertical"===e||"horizontalvertical"===e||"verticalhorizontal"===e){if("horizontal"===e||"Horizontal"===e)for(var d=0,p=o.objColl.length;d<p;d++)(h=o.objColl[d]).shapeFlip!==o.transform.currFlipState&&(h.activePoint.startX<=r+a/2?(h.activePoint.endX=r+a-(h.activePoint.startX-r),h.activePoint.startX=h.activePoint.endX-h.activePoint.width,o.notify("draw",{prop:"updateActiveObject",onPropertyChange:!1,value:{actPoint:h.activePoint,obj:h}})):h.activePoint.startX>=r+a/2&&(h.activePoint.startX=r+(r+a-h.activePoint.endX),h.activePoint.endX=h.activePoint.startX+h.activePoint.width,o.notify("draw",{prop:"updateActiveObject",onPropertyChange:!1,value:{actPoint:h.activePoint,obj:h}})),"line"===h.shape||"arrow"===h.shape||"path"===h.shape?this.flipLineArrowObj(h,"horizontal"):0!==h.rotatedAngle&&(h.rotatedAngle=h.rotatedAngle+2*(Math.PI-h.rotatedAngle),h.rotationCirclePointColl.x<=r+a/2?h.rotationCirclePointColl.x=r+a-(h.rotationCirclePointColl.x-r):h.rotationCirclePointColl.x>=r+a/2&&(h.rotationCirclePointColl.x=r+(r+a-h.rotationCirclePointColl.x)),h.rotationCirclePointColl.ratioX=(h.rotationCirclePointColl.x-r)/a),h.shapeFlip=o.transform.currFlipState,h.imageRatio={startX:(h.activePoint.startX-r)/a,startY:(h.activePoint.startY-n)/s,endX:(h.activePoint.endX-r)/a,endY:(h.activePoint.endY-n)/s,width:a/h.activePoint.width,height:s/h.activePoint.height});else if("vertical"===e||"Vertical"===e)for(d=0;d<o.objColl.length;d++)(h=o.objColl[d]).shapeFlip!==o.transform.currFlipState&&(h.activePoint.startY<=n+s/2?(h.activePoint.endY=n+s-(h.activePoint.startY-n),h.activePoint.startY=h.activePoint.endY-h.activePoint.height,o.notify("draw",{prop:"updateActiveObject",onPropertyChange:!1,value:{actPoint:h.activePoint,obj:h}})):h.activePoint.startY>=o.lowerCanvas.height/2&&(h.activePoint.startY=n+(n+s-h.activePoint.endY),h.activePoint.endY=h.activePoint.startY+h.activePoint.height,o.notify("draw",{prop:"updateActiveObject",onPropertyChange:!1,value:{actPoint:h.activePoint,obj:h}})),"line"===h.shape||"arrow"===h.shape||"path"===h.shape?this.flipLineArrowObj(h,"vertical"):0!==h.rotatedAngle&&(h.rotatedAngle=-h.rotatedAngle,h.rotationCirclePointColl.y<=n+s/2?h.rotationCirclePointColl.y=n+s-(h.rotationCirclePointColl.y-n):h.rotationCirclePointColl.y>=n+s/2&&(h.rotationCirclePointColl.y=n+(n+s-h.rotationCirclePointColl.y)),h.rotationCirclePointColl.ratioY=(h.rotationCirclePointColl.y-n)/s),h.shapeFlip=o.transform.currFlipState,h.imageRatio={startX:(h.activePoint.startX-r)/a,startY:(h.activePoint.startY-n)/s,endX:(h.activePoint.endX-r)/a,endY:(h.activePoint.endY-n)/s,width:a/h.activePoint.width,height:s/h.activePoint.height});else if("verticalhorizontal"===e||"horizontalvertical"===e)for(d=0,p=o.objColl.length;d<p;d++)(h=o.objColl[d]).shapeFlip!==o.transform.currFlipState&&(h.activePoint.startX<=r+a/2?(h.activePoint.endX=r+a-(h.activePoint.startX-r),h.activePoint.startX=h.activePoint.endX-h.activePoint.width,o.notify("draw",{prop:"updateActiveObject",onPropertyChange:!1,value:{actPoint:h.activePoint,obj:h}})):h.activePoint.startX>=r+a/2&&(h.activePoint.startX=r+(r+a-h.activePoint.endX),h.activePoint.endX=h.activePoint.startX+h.activePoint.width,o.notify("draw",{prop:"updateActiveObject",onPropertyChange:!1,value:{actPoint:h.activePoint,obj:h}})),h.activePoint.startY<=n+s/2?(h.activePoint.endY=n+s-(h.activePoint.startY-n),h.activePoint.startY=h.activePoint.endY-h.activePoint.height,o.notify("draw",{prop:"updateActiveObject",onPropertyChange:!1,value:{actPoint:h.activePoint,obj:h}})):h.activePoint.startY>=o.lowerCanvas.height/2&&(h.activePoint.startY=n+(n+s-h.activePoint.endY),h.activePoint.endY=h.activePoint.startY+h.activePoint.height,o.notify("draw",{prop:"updateActiveObject",onPropertyChange:!1,value:{actPoint:h.activePoint,obj:h}})),"line"!==h.shape&&"arrow"!==h.shape&&"path"!==h.shape||this.flipLineArrowObj(h,e),h.shapeFlip=o.transform.currFlipState,h.imageRatio={startX:(h.activePoint.startX-r)/a,startY:(h.activePoint.startY-n)/s,endX:(h.activePoint.endX-r)/a,endY:(h.activePoint.endY-n)/s,width:a/h.activePoint.width,height:s/h.activePoint.height});void 0!==t&&(o.activeObj=O.extend({},o.objColl[t],{},!0))}else if(90===e)this.rotateObjColl();else if(-90===e)for(d=0;d<3;d++)this.rotateObjColl();else if("number"==typeof e)if(0<e)this.rotateObjColl();else for(d=0;d<3;d++)this.rotateObjColl()},C.prototype.rotateObjColl=function(){for(var e=this.parent,t=e.img,o=t.destWidth,i=t.destHeight,r=t.destLeft,n=t.destTop,a=0,s=e.objColl.length;a<s;a++){var l=(p=e.objColl[a]).shape;p.activePoint.startY=n+i*p.imageRatio.startX,p.activePoint.endY=n+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[a]),this.updateFontSize(p),"line"===l||"arrow"===l||"path"===l?(this.rotateLineArrowObj(p),"arrow"===l&&this.updateArrowSize(p)):0!==p.rotatedAngle&&(p.rotationCirclePointColl.y=n+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-n)/i)}for(a=0,s=e.objColl.length;a<s;a++)e.notify("draw",{prop:"updateActiveObject",onPropertyChange:!1,value:{actPoint:e.objColl[a].activePoint,obj:e.objColl[a]}});for(var p,a=0,s=e.objColl.length;a<s;a++)(p=e.objColl[a]).imageRatio={startX:(p.activePoint.startX-r)/o,startY:(p.activePoint.startY-n)/i,endX:(p.activePoint.endX-r)/o,endY:(p.activePoint.endY-n)/i,width:o/p.activePoint.width,height:i/p.activePoint.height}},C.prototype.rotateLineArrowObj=function(e){if(!O.isNullOrUndefined(e.pointColl)){var t=this.parent.img,o=t.destWidth,i=t.destHeight,r=t.destLeft,n=t.destTop;if(0<e.pointColl.length){for(var a=0;a<e.pointColl.length;a++)e.pointColl[a].y=n+i*e.pointColl[a].ratioX,e.pointColl[a].x=r+o-o*e.pointColl[a].ratioY;for(a=0;a<e.pointColl.length;a++)e.pointColl[a].ratioX=(e.pointColl[a].x-r)/o,e.pointColl[a].ratioY=(e.pointColl[a].y-n)/i;var t=void 0,t=O.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},s=e.pointColl[e.pointColl.length-1].x-t.x,t=e.pointColl[e.pointColl.length-1].y-t.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+s/2,e.activePoint.endY=e.pointColl[e.pointColl.length-1].y+t/2,this.updateWidthHeight(e)}}},C.prototype.flipLineArrowObj=function(e,t){t=t.toLowerCase(),O.isNullOrUndefined(e.pointColl)||("horizontal"===t?this.lineArrowHorizontalFlip(e):("vertical"!==t&&(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&&(t=e.activePoint.startX,e.activePoint.startX=e.activePoint.endX,e.activePoint.endX=t,t=e.activePoint.startY,e.activePoint.startY=e.activePoint.endY,e.activePoint.endY=t))},C.prototype.lineArrowHorizontalFlip=function(e){var t=this.parent,o=t.img,i=o.destWidth,r=o.destHeight,n=o.destLeft,a=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<=n+i/2?p.x=n+i-(p.x-n):p.x>=n+i/2&&(p.x=n+(n+i-p.x)),p.ratioX=(p.x-n)/i,p.ratioY=(p.y-a)/r}"arrow"===e.shape&&(o=e.start,e.start=e.end,e.end=o),e.shapeFlip=t.transform.currFlipState}},C.prototype.lineArrowVerticalFlip=function(e){var t=this.parent,o=t.img,i=o.destWidth,r=o.destHeight,n=o.destLeft,a=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<=a+r/2?p.y=a+r-(p.y-a):p.y>=a+r/2&&(p.y=a+(a+r-p.y)),p.ratioX=(p.x-n)/i,p.ratioY=(p.y-a)/r}e.shapeFlip=t.transform.currFlipState}},C.prototype.getRotDegOfShape=function(e){e=0===e.shapeDegree?this.parent.transform.degree:this.parent.transform.degree-e.shapeDegree;return e=e<0?360+e:e},C.prototype.renderTextArea=function(e,t,o){var i=this.parent,r=this.getRotDegOfShape(i.activeObj),n=(this.transformTextArea(),i.notify("toolbar",{prop:"destroy-qa-toolbar",onPropertyChange:!1}),i.element.querySelector("#"+i.element.id+"_zOrderBtn")),a=i.element.querySelector("#"+i.element.id+"_duplicate"),s=i.element.querySelector("#"+i.element.id+"_remove"),l=i.element.querySelector("#"+i.element.id+"_editText"),n=(n&&n.classList.add("e-disabled"),a&&a.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,o.activePoint),a=n.width,s=n.height,l=(r%90==0&&r%180!=0&&0!==r?(i.textArea.style.width=s+"px",i.textArea.style.height=a+"px"):(i.textArea.style.width=a+"px",i.textArea.style.height=s+"px"),this.setTextBoxWidth(),{flipColl:null});if(i.notify("transform",{prop:"getFlipColl",onPropertyChange:!1,value:{obj:l}}),l.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 p=parseFloat(i.textArea.style.left),e=parseFloat(i.textArea.style.top),h=(0<o.flipObjColl.length&&(n=(t=i.lowerCanvas).clientWidth,a=t.clientHeight,i.notify("crop",{prop:"getCurrFlipState",onPropertyChange:!(s={x:0,y:0}),value:{panObj:l={panRegion:""}}}),""!==l.panRegion)&&("horizontal"===l.panRegion?(s.x=n-n/2,p=s.x-p+s.x):e=("vertical"===l.panRegion?s.y=a-a/2:p=(s={x:n-n/2,y:a-a/2}).x-p+s.x,s.y-e+s.y)),p+parseFloat(i.textArea.style.width)),d=e+parseFloat(i.textArea.style.height),c=parseFloat(i.textArea.style.width),u=parseFloat(i.textArea.style.height),g={x:h-c/2,y:d-u/2},v=Math.cos(o.rotatedAngle),f=Math.sin(o.rotatedAngle),C={x:v*(h-g.x)-f*(d-g.y)+g.x,y:f*(h-g.x)+v*(d-g.y)+g.y};if(C.x>i.img.destLeft&&C.x<i.img.destLeft+i.img.destWidth&&C.y>i.img.destTop&&C.y+parseFloat(i.textArea.style.fontSize)<i.img.destTop+i.img.destHeight)i.textArea.style.width=i.textArea.style.width;else for(var b=0,m=parseFloat(i.textArea.style.width);;)if(b++,(C={x:v*((h=p+--c)-(g={x:h-c/2,y:d-u/2}).x)-f*(d-g.y)+g.x,y:f*(h-g.x)+v*(d-g.y)+g.y}).x>i.img.destLeft&&C.x<i.img.destLeft+i.img.destWidth&&C.y>i.img.destTop&&C.y+parseFloat(i.textArea.style.fontSize)<i.img.destTop+i.img.destHeight||b===m){i.textArea.style.width=c+"px";break}}i.notify("selection",{prop:"clearUpperCanvas",onPropertyChange:!1})},C.prototype.setTextBoxWidth=function(e){var t,o,i,r,n,a=this.parent;0!==a.activeObj.rotatedAngle?(a.textArea.style.whiteSpace="nowrap",a.textArea.style.textOverflow="ellipsis",a.textArea.style.display="inline-block"):(a.textArea.style.whiteSpace="",a.textArea.style.textOverflow="","inline-block"===a.textArea.style.display&&(a.textArea.style.display="block"),t=this.getMaxText(!0),"block"===a.textArea.style.display||"inline-block"===a.textArea.style.display?this.updateFontStyles(!0):this.updateFontStyles(),t=this.upperContext.measureText(t).width+parseFloat(a.textArea.style.fontSize)/2,o=e?this.upperContext.measureText(String.fromCharCode(e.which)).width:0,r=O.extend({},a.activeObj,{},!0),n="",i=this.getRotDegOfShape(r),n=r.shapeFlip!==a.transform.currFlipState?"":a.transform.currFlipState,(e&&parseFloat(a.textArea.style.width)<t+o||O.isNullOrUndefined(e))&&(0===i?"horizontal"===n.toLowerCase()?0<parseFloat(a.textArea.style.left)-a.img.destLeft-t-o&&(a.textArea.style.width=t+o+"px"):a.img.destWidth-(parseFloat(a.textArea.style.left)-a.img.destLeft)>t+o&&(a.textArea.style.width=t+o+"px"):90===i?"vertical"===n.toLowerCase()?0<parseFloat(a.textArea.style.top)-a.img.destTop-t-o&&(a.textArea.style.width=t+o+"px"):a.img.destHeight-(parseFloat(a.textArea.style.top)-a.img.destTop)>t+o&&(a.textArea.style.width=t+o+"px"):180===i?(r=parseFloat(a.textArea.style.left),e=a.img.destLeft,"horizontal"===n.toLowerCase()?t+o<a.img.destWidth-(r-e)&&(a.textArea.style.width=t+o+"px"):0<r-e-t-o&&(a.textArea.style.width=t+o+"px")):270===i&&(r=parseFloat(a.textArea.style.top),e=a.img.destTop,"vertical"===n.toLowerCase()?t+o<a.img.destHeight-(r-e)&&(a.textArea.style.width=t+o+"px"):0<r-e-t-o&&(a.textArea.style.width=t+o+"px"))))},C.prototype.setTextBoxHeight=function(){var e,t=this.parent,o=O.extend({},t.activeObj,{},!0),i="",r=this.getRotDegOfShape(o),i=o.textFlip===t.transform.currFlipState?"":""===o.textFlip?t.transform.currFlipState:o.textFlip;switch(r){case 0:"vertical"===i.toLowerCase()?t.textArea.style.maxHeight=t.img.destHeight-(t.img.destHeight-parseFloat(t.textArea.style.top))+"px":(e=parseFloat(t.textArea.style.top)-t.img.destTop,t.textArea.style.maxHeight=t.img.destHeight-e+"px");break;case 90:"horizontal"===i.toLowerCase()?t.textArea.style.maxHeight=t.img.destWidth-(parseFloat(t.textArea.style.left)-t.img.destLeft)+"px":t.textArea.style.maxHeight=parseFloat(t.textArea.style.left)-t.img.destLeft+"px";break;case 180:"vertical"===i.toLowerCase()?(e=parseFloat(t.textArea.style.top)-t.img.destTop,t.textArea.style.maxHeight=t.img.destHeight-e+"px"):t.textArea.style.maxHeight=parseFloat(t.textArea.style.top)-t.img.destTop+"px";break;case 270:"horizontal"===i.toLowerCase()?t.textArea.style.maxHeight=parseFloat(t.textArea.style.left)-t.img.destLeft+"px":t.textArea.style.maxHeight=t.img.destWidth-(parseFloat(t.textArea.style.left)-t.img.destLeft)+"px"}},C.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}},C.prototype.stopPathDrawing=function(e,t){var o,i,r,n=this.parent;"path"===n.activeObj.shape&&(n.notify("selection",{prop:"getCurrentDrawingShape",value:{obj:o={shape:null}}}),"path"===o.shape)&&(o=O.extend({},n.cropObj,{},!0),n.notify("filter",{prop:"getCurrentObj",onPropertyChange:!(r={currObj:{}}),value:{object:r}}),(r=r.currObj).objColl=O.extend([],n.objColl,[],!0),r.pointColl=O.extend([],n.pointColl,[],!0),r.afterCropActions=O.extend([],n.afterCropActions,[],!0),n.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!(i={selPointColl:null}),value:{obj:i}}),r.selPointColl=O.extend([],i.selPointColl,[],!0),n.notify("selection",{prop:"setCurrentDrawingShape",value:{value:""}}),n.currObjType.isDragging=!1,e&&"touchstart"!==e.type&&O.isNullOrUndefined(t)&&n.activeObj.pointColl.pop(),this.updatePathRatio(n.activeObj),O.isNullOrUndefined(n.activeObj.imageRatio)&&n.notify("shape",{prop:"updImgRatioForActObj",onPropertyChange:!1}),n.objColl.push(n.activeObj),n.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}}),n.objColl.pop(),e&&(n.notify("selection",{prop:"mouseUpEventHandler",value:{e:e}}),this.lowerContext.clearRect(0,0,n.lowerCanvas.width,n.lowerCanvas.height),n.notify("draw",{prop:"redrawImgWithObj",onPropertyChange:!1})),n.notify("draw",{prop:"setNewPath",value:{bool:!0}}),n.objColl[n.objColl.length-1]&&(i=n.drawingShape,n.notify("selection",{prop:"setCurrentDrawingShape",value:{value:""}}),n.selectShape(n.objColl[n.objColl.length-1].currIndex),n.notify("selection",{prop:"setCurrentDrawingShape",value:{value:"path"}}),n.drawingShape=i),n.notify("toolbar",{prop:"renderQAT",onPropertyChange:!1,value:{isPenEdit:null}}),n.notify("selection",{prop:"updatePrevShapeSettings",onPropertyChange:!(t={shapeSettingsObj:{}}),value:{obj:t}}),n.notify("selection",{prop:"triggerShapeChange",onPropertyChange:!1,value:{shapeResizingArgs:{cancel:!1,action:"draw-end",previousShapeSettings:r=t.shapeSettingsObj},shapeMovingArgs:{cancel:!1,action:"move",previousShapeSettings:r},type:"mouse-up"}}),n.notify("undo-redo",{prop:"updateUndoRedoStack",onPropertyChange:!1}))},C.prototype.findTextTarget=function(e){var t=this.parent;if("text"!==t.activeObj.shape){if("path"===t.activeObj.shape)return void this.stopPathDrawing(e,null);if("dblclick"!==e.type)return;var o=O.extend({},t.activeObj,{},!0),i=O.extend([],t.objColl,[],!0),r={bool:null};if(t.notify("selection",{prop:"findTargetObj",onPropertyChange:!1,value:{x:e.clientX,y:e.clientY,isCrop:!1,obj:r}}),t.objColl=i,!r.bool||"text"!==t.activeObj.shape)return void(t.activeObj=O.extend({},o,{},!0))}if("dblclick"===e.type?(s=e.clientX,l=e.clientY):"touchstart"===e.type&&(s=e.touches[0].clientX,l=e.touches[0].clientY,t.notify("selection",{prop:"setTouchEndPoint",onPropertyChange:!1,value:{x:e.touches[0].clientX,y:e.touches[0].clientY}})),t.notify("toolbar",{prop:"setPreventZoomBtn",onPropertyChange:!1,value:{isPrevent:!0}}),t.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"text",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}}),t.notify("toolbar",{prop:"setPreventZoomBtn",onPropertyChange:!1,value:{isPrevent:!1}}),t.notify("toolbar",{prop:"update-toolbar-items",onPropertyChange:!1}),O.isNullOrUndefined(s)||O.isNullOrUndefined(l))"block"!==t.textArea.style.display&&"inline-block"!==t.textArea.style.display||""===this.selectedText()||"mousedown"!==e.type?"none"===t.textArea.style.display&&(t.textArea.style.display="block"):(n=t.textArea.value,t.textArea.value+="a",t.textArea.value=n);else{var i=t.lowerCanvas.getBoundingClientRect(),o=(s-=i.left,l-=i.top,""),e=this.getRotDegOfShape(t.activeObj),o=""===t.activeObj.textFlip?t.activeObj.textFlip===t.transform.currFlipState?"":t.transform.currFlipState:t.activeObj.textFlip===t.transform.currFlipState?"":""===t.transform.currFlipState?t.activeObj.textFlip:t.transform.currFlipState,n=void 0;if("none"===t.textArea.style.display){n=O.extend({},t.activeObj,{},!0);for(var a=0;a<t.objColl.length;a++)JSON.stringify(t.activeObj)===JSON.stringify(t.objColl[a])&&t.objColl.splice(a,1);this.refreshActiveObj(),this.upperContext.clearRect(0,0,t.upperCanvas.width,t.upperCanvas.height),this.lowerContext.clearRect(0,0,t.upperCanvas.width,t.upperCanvas.height),t.notify("draw",{prop:"redrawImgWithObj",onPropertyChange:!1}),t.notify("draw",{prop:"redrawDownScale"}),t.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.lowerContext}}),t.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.upperContext}}),(t.currSelectionPoint&&"crop-circle"===t.currSelectionPoint.shape||t.isCircleCrop)&&t.notify("crop",{prop:"cropCircle",onPropertyChange:!1,value:{context:this.lowerContext,isSave:null,isFlip:null}}),t.activeObj=n,this.updateFontStyles();var s,l,i=O.extend({},t.activeObj,{},!0),n=i.topLeftCircle.radius,p=i.activePoint,h=p.startX,d=p.startY,c=p.endX,u=p.endY,g=h+p.width/2,p=d+p.height/2,v=Math.cos(i.rotatedAngle),f=Math.sin(i.rotatedAngle),C={x:v*(h-g)-f*(d-p)+g,y:f*(h-g)+v*(d-p)+p},d={x:v*(c-g)-f*(d-p)+g,y:f*(c-g)+v*(d-p)+p},h={x:v*(h-g)-f*(u-p)+g,y:f*(h-g)+v*(u-p)+p},f={x:v*(c-g)-f*(u-p)+g,y:f*(c-g)+v*(u-p)+p},r={position:null,x:s,y:l,x1:C.x,y1:C.y,x2:d.x,y2:d.y,x3:h.x,y3:h.y,x4:f.x,y4:f.y};t.notify("draw",{prop:"checkPointPosition",onPropertyChange:!1,value:{obj:r}}),0!==i.rotatedAngle&&("inside"===r.position||"on"===r.position)||0===i.rotatedAngle&&s>=i.activePoint.startX-2*n&&s<=i.activePoint.endX+2*n&&l>=i.activePoint.startY-2*n&&l<=i.activePoint.endY+2*n?(this.upperContext.clearRect(0,0,t.upperCanvas.width,t.upperCanvas.height),4===i.flipObjColl.length&&(i.flipObjColl=[],i.shapeFlip=o=""),""===o&&1<i.flipObjColl.length&&(o=i.flipObjColl[i.flipObjColl.length-1]),l=(s=(c=i.flipObjColl.length<=1?this.setTextBoxPos(i,e,o,s,l):this.setTextBoxPoints(i,e,o,s,l)).x,c.y),0!==t.activeObj.rotatedAngle&&(s=(g=this.getTextBoxPosition(t.activeObj)).x,l=g.y,s=(g=this.setFlipState(s,l,t.activeObj)).x,l=g.y),this.renderTextArea(s,l,i)):this.applyActObj()}}},C.prototype.getTextBoxPosition=function(e,t){var o={x:0,y:0},i=e.activePoint,r=i.startX,n=i.startY,a=i.endX,s=i.endY,l=r+i.width/2,i=n+i.height/2,p=Math.cos(e.rotatedAngle),h=Math.sin(e.rotatedAngle),d={x:p*(r-l)-h*(n-i)+l,y:h*(r-l)+p*(n-i)+i},n={x:p*(a-l)-h*(n-i)+l,y:h*(a-l)+p*(n-i)+i},r={x:p*(r-l)-h*(s-i)+l,y:h*(r-l)+p*(s-i)+i},h={x:p*(a-l)-h*(s-i)+l,y:h*(a-l)+p*(s-i)+i},a=this.getRotDegOfShape(e);return 0===a||360===a?o={x:d.x,y:d.y}:90===a||-270===a?o={x:n.x,y:n.y}:180===a||-180===a?o={x:h.x,y:h.y}:270!==a&&-90!==a||(o={x:r.x,y:r.y}),t&&(t.x=o.x,t.y=o.y),o},C.prototype.setFlipState=function(e,t,o,i){var r=this.parent,n={panRegion:""},a=r.lowerCanvas,s=a.clientWidth,a=a.clientHeight,l={x:0,y:0};return r.notify("crop",{prop:"getCurrFlipState",onPropertyChange:!1,value:{panObj:n}}),""!==n.panRegion&&("horizontal"===n.panRegion?(l.x=s-s/2,e=l.x-e+l.x):t=("vertical"===n.panRegion?l.y=a-a/2:e=(l={x:s-s/2,y:a-a/2}).x-e+l.x,l.y-t+l.y)),i&&(i.x=e,i.y=t),{x:e,y:t}},C.prototype.fileChanged=function(e){var t=e.target.files[0],t=t.name&&t.name.split(".")[1].toLowerCase();t&&-1===["jpg","jpeg","png","svg"].indexOf(t)?this.refreshActiveObj():(t=window.URL.createObjectURL(e.target.files[0]),this.onLoadImgShape(null,null,null,null,t.toString(),!0),document.getElementById(this.parent.element.id+"_fileUpload").value="")},C.prototype.onLoadImgShape=function(e,t,o,i,r,n,a,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(n,e,t,o,i,a,s,l,p)}},C.prototype.updateImgCanvas=function(e,t,o,i,r,n,a,s,l){var p=this.parent,h=(p.activeObj.imageElement=this.shapeImg,p.activeObj.imageCanvas=p.createElement("canvas"),{width:0,height:0}),a=(p.notify("transform",{prop:"calcMaxDimension",onPropertyChange:!1,value:{width:this.shapeImg.width,height:this.shapeImg.height,obj:h,isImgShape:null}}),i&&r&&(h=a?(p.notify("selection",{prop:"findImageRatio",onPropertyChange:!(d={ratio:null}),value:{width:this.shapeImg.width,height:this.shapeImg.height,obj:d}}),this.resizeImage(i,d.ratio)):{width:i,height:r}),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&&(h=a?(p.notify("selection",{prop:"findImageRatio",onPropertyChange:!(d={ratio:null}),value:{width:this.shapeImg.width,height:this.shapeImg.height,obj:d}}),this.resizeImage(i,d.ratio)):{width:i,height:r}),null!=s&&(p.activeObj.opacity=s),this.updateObj(h,t,o),p.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate"}}),this.shapeImg=null,n&&(p.activeObj.rotatedAngle=n*(Math.PI/180),p.notify("selection",{prop:"updPtCollForShpRot",onPropertyChange:!1,value:{obj:p.activeObj}})),{shapeSettingsObj:{}}),d=(p.notify("selection",{prop:"updatePrevShapeSettings",onPropertyChange:!1,value:{obj:a}}),a.shapeSettingsObj),i={cancel:!1,action:"insert",previousShapeSettings:d,currentShapeSettings:d};p.trigger("shapeChanging",i),this.drawShapeImageEvent(i,e=e||l),p.isPublicMethod&&!l?p.notify("undo-redo",{prop:"updateUndoRedo",onPropertyChange:!1}):p.isPublicMethod||p.notify("undo-redo",{prop:"updateUndoRedoStack",onPropertyChange:!1}),p.isPublicMethod=!1},C.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},C.prototype.resizeImage=function(e,t){var t=t.split(":"),o=parseInt(t[0],10),t=parseInt(t[1],10);return{width:e,height:Math.round(e*t/o)}},C.prototype.setTextBoxPos=function(e,t,o,i,r){var n={x:i,y:r},i=e.activePoint,a=i.startX,s=i.startY,l=i.endX,p=i.endY;switch(o=o.toLowerCase(),t){case 0:"horizontal"===o?(n.x=l,n.y=s):"vertical"===o?(n.x=a,n.y=p):(n.x=a,n.y=s);break;case 90:"horizontal"===o?(n.x=a,n.y=s):"vertical"===o?(n.x=l,n.y=p):(n.x=l,n.y=s);break;case 180:"horizontal"===o?(n.x=a,n.y=p):"vertical"===o?(n.x=l,n.y=s):(n.x=l,n.y=p);break;case 270:"horizontal"===o?(n.x=l,n.y=p):"vertical"===o?(n.x=a,n.y=s):(n.x=a,n.y=p)}return n},C.prototype.setTextBoxPoints=function(e,t,o,i,r){var n={x:i,y:r},i=e.activePoint,a=i.startX,s=i.startY,l=i.endX,p=i.endY;switch(o=o.toLowerCase(),t){case 0:e.flipObjColl[0]&&"horizontal"===e.flipObjColl[0].toLowerCase()?"horizontal"===o?(n.x=a,n.y=s):"vertical"===o&&(n.x=l,n.y=p):"horizontal"===o?(n.x=l,n.y=p):"vertical"===o&&(n.x=l,n.y=s);break;case 90:e.flipObjColl[0]&&"horizontal"===e.flipObjColl[0].toLowerCase()?"horizontal"===o?(n.x=l,n.y=p):"vertical"===o&&(n.x=a,n.y=p):"horizontal"===o?(n.x=a,n.y=p):"vertical"===o&&(n.x=a,n.y=s);break;case 180:e.flipObjColl[0]&&"horizontal"===e.flipObjColl[0].toLowerCase()?"horizontal"!==o&&"vertical"!==o||(n.x=a,n.y=s):"horizontal"===o?(n.x=a,n.y=s):"vertical"===o&&(n.x=a,n.y=p);break;case 270:e.flipObjColl[0]&&"horizontal"===e.flipObjColl[0].toLowerCase()?"horizontal"===o?(n.x=a,n.y=s):"vertical"===o&&(n.x=l,n.y=s):"horizontal"===o?(n.x=l,n.y=s):"vertical"===o&&(n.x=l,n.y=p)}return n},C.prototype.selectedText=function(){var e=this.parent,t=e.textArea.selectionStart,o=e.textArea.selectionEnd;return e.textArea.value.substring(t,o)},C.prototype.panObjColl=function(e,t,o){var i=this.parent;if(0<i.objColl.length){for(var r=0,n=i.objColl.length;r<n;r++){var a=i.objColl[r];if(""===o){if(a.activePoint.startX+=e,a.activePoint.endX+=e,a.rotationCirclePointColl&&(a.rotationCirclePointColl.x+=e),"path"===a.shape)for(var s=0,l=a.pointColl.length;s<l;s++)a.pointColl[s].x+=e;if(a.activePoint.startY+=t,a.activePoint.endY+=t,a.rotationCirclePointColl&&(a.rotationCirclePointColl.y+=t),"path"===a.shape)for(s=0;s<a.pointColl.length;s++)a.pointColl[s].y+=t}if(a=this.updateWidthHeight(a),i.notify("draw",{prop:"updateActiveObject",onPropertyChange:!1,value:{actPoint:a.activePoint,obj:a}}),"line"===a.shape||"arrow"===a.shape){a.pointColl=this.getLinePoints(a.activePoint.startX,a.activePoint.startY,a.activePoint.endX,a.activePoint.endY);for(var p=0,h=a.pointColl.length;p<h;p++)a.pointColl[p].ratioX=(a.pointColl[p].x-i.img.destLeft)/i.img.destWidth,a.pointColl[p].ratioY=(a.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}})}},C.prototype.updateFontStyles=function(e){var t=this.parent,o=(this.upperContext.strokeStyle=t.activeObj.strokeSettings.strokeColor,this.upperContext.fillStyle=t.activeObj.strokeSettings.strokeColor,""),e=(t.activeObj.textSettings.bold&&(o="bold "),t.activeObj.textSettings.italic&&(o="italic "),t.activeObj.textSettings.bold&&t.activeObj.textSettings.italic&&(o="italic bold "),e?parseFloat(t.textArea.style.fontSize):t.activeObj.textSettings.fontSize),t=("block"===t.textArea.style.display||"inline-block"===t.textArea.style.display?t.textArea.style:t.activeObj.textSettings).fontFamily;this.upperContext.font=o+e+"px "+t},C.prototype.applyFontStyle=function(e){var t=this.parent,o={shapeSettingsObj:{}},o=(t.notify("selection",{prop:"updatePrevShapeSettings",onPropertyChange:!1,value:{obj:o}}),o.shapeSettingsObj),i=(this.pushActItemIntoObj(),O.extend([],t.objColl,[],!0));switch(t.objColl.pop(),"none"===t.textArea.style.display?this.updateFontRatio(t.activeObj):this.updateFontRatio(t.activeObj,!0),e){case"default":this.updateFontStyle(e,i,"normal","normal");break;case"bold":this.updateFontStyle(e,i,"bold","normal");break;case"italic":this.updateFontStyle(e,i,"normal","italic");break;case"bolditalic":this.updateFontStyle(e,i,"bold","italic")}o={action:"font-style",currentShapeSettings:O.extend({},o,{},!0)};o.currentShapeSettings.fontStyle=[e],t.trigger("shapeChange",o)},C.prototype.updateFontStyle=function(e,t,o,i){var r,n=this.parent,a=n.textArea.style;"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"),r="normal"===a.fontWeight&&"normal"===a.fontStyle?"default":"bold"===a.fontWeight&&"normal"===a.fontStyle?"bold":"normal"===a.fontWeight&&"italic"===a.fontStyle?"italic":"bolditalic",r=this.getTextAreaWidth(r),a.width=r+"px",this.updateObjColl(e,t)):(this.textSettings.bold=n.activeObj.textSettings.bold="normal"!==o,this.textSettings.italic=n.activeObj.textSettings.italic="normal"!==i,0===n.activeObj.activePoint.width&&0===n.activeObj.activePoint.height||this.redrawText(),n.notify("undo-redo",{prop:"updateUrObj",onPropertyChange:!1,value:{objColl:t}}))},C.prototype.updateArrowRatio=function(e){for(var t,o={arrowDimension:null},i=(this.parent.notify("draw",{prop:"getArrowDimension",onPropertyChange:!1,value:{obj:o}}),t=Math.abs(e.activePoint.width)>Math.abs(e.activePoint.height)?Math.abs(e.activePoint.width):Math.abs(e.activePoint.height),0),r=["bar","arrow","arrowSolid","circle","square"];i<r.length;i++){var n,a=t/o.arrowDimension[n=r[i]].width,s=t/o.arrowDimension[n].height;o.arrowDimension[n].ratioX=a,o.arrowDimension[n].ratioY=s}},C.prototype.updateArrowSize=function(e){for(var t,o={arrowDimension:null},i=(this.parent.notify("draw",{prop:"getArrowDimension",onPropertyChange:!1,value:{obj:o}}),t=Math.abs(e.activePoint.width)>Math.abs(e.activePoint.height)?Math.abs(e.activePoint.width):Math.abs(e.activePoint.height),0),r=["bar","arrow","arrowSolid","circle","square"];i<r.length;i++){var n,a=o.arrowDimension[n=r[i]].ratioX,s=o.arrowDimension[n].ratioY;o.arrowDimension[n].width=t/a,o.arrowDimension[n].height=t/s}},C.prototype.updateFontRatio=function(e,t){var o=this.parent,i=this.getMaxText(t),i=this.upperContext.measureText(i).width+.5*o.activeObj.textSettings.fontSize,r=o.activeObj.textSettings.fontSize+.25*o.activeObj.textSettings.fontSize,n=this.getRotDegOfShape(e);O.isNullOrUndefined(t)?0===n||180===Math.abs(n)?e.textSettings.fontRatio=i/e.textSettings.fontSize:e.textSettings.fontRatio=r/e.textSettings.fontSize:t&&(e.textSettings.fontRatio=i/parseFloat(o.textArea.style.fontSize))},C.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},C.prototype.updateObjColl=function(e,t){var o=this.parent,i=O.extend({},o.cropObj,{},!0),r={currObj:{}},r=(o.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:r}}),r.currObj),t=(r.objColl=t,r.pointColl=O.extend([],o.pointColl,[],!0),r.afterCropActions=O.extend([],o.afterCropActions,[],!0),{selPointColl:null}),t=(o.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:t}}),r.selPointColl=O.extend([],t.selPointColl,[],!0),o.activeObj.textSettings.bold),n=o.activeObj.textSettings.italic;switch(e){case"default":o.activeObj.textSettings.bold=!1,o.activeObj.textSettings.italic=!1;break;case"bold":o.activeObj.textSettings.bold=!0,o.activeObj.textSettings.italic=!1;break;case"italic":o.activeObj.textSettings.bold=!1,o.activeObj.textSettings.italic=!0;break;case"bolditalic":o.activeObj.textSettings.bold=!0,o.activeObj.textSettings.italic=!0}o.objColl.push(o.activeObj),o.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"textAreaCustomization",previousObj:r,previousObjColl:r.objColl,previousPointColl:r.pointColl,previousSelPointColl:r.selPointColl,previousCropObj:i,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),o.objColl.pop(),o.activeObj.textSettings.bold=t,o.activeObj.textSettings.italic=n},C.prototype.pushActItemIntoObj=function(){var e,t=this.parent;"none"===t.textArea.style.display?t.objColl.push(t.activeObj):(e=O.extend({},t.activeObj,{},!0),t.notify("selection",{prop:"setTextBoxStylesToActObj",onPropertyChange:!1}),t.objColl.push(t.activeObj),t.activeObj=e)},C.prototype.clearActObj=function(){var e=this.parent;"none"===e.textArea.style.display&&(this.refreshActiveObj(),this.applyActObj(),this.refreshActiveObj(),e.currObjType.isCustomCrop=!1)},C.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},C.prototype.applyActObj=function(e){var t=this.parent,o=!1;if(void 0!==t.activeObj.shape&&"text"===t.activeObj.shape&&""===t.activeObj.keyHistory)this.refreshActiveObj(),this.upperContext.clearRect(0,0,t.upperCanvas.width,t.upperCanvas.height);else{var i=void 0,r=!1;if((void 0===(i=void 0!==t.activeObj.shape?t.activeObj.shape.split("-"):i)&&t.currObjType.isCustomCrop||void 0!==i&&"crop"===i[0])&&(r=!0),t.activeObj.shape&&!r&&"shape"!==t.activeObj.shape){for(var n=0;n<t.objColl.length;n++)if(JSON.stringify(t.activeObj)===JSON.stringify(t.objColl[n])){o=!0;break}if(!o){O.isNullOrUndefined(t.activeObj.currIndex)&&(t.activeObj.currIndex=this.getNewShapeId()),O.isNullOrUndefined(t.activeObj.order)&&(t.activeObj.order=this.getNewOrder()),this.updImgRatioForActObj();var i=t.activeObj.currIndex.split("_"),a=t.objColl.splice(0,parseInt(i[1],10)-1);a.push(O.extend({},t.activeObj,{},!0));for(n=0;n<t.objColl.length;n++)a.push(t.objColl[n]);t.objColl=a,a=[],this.refreshActiveObj(),this.lowerContext.clearRect(0,0,t.lowerCanvas.width,t.lowerCanvas.height),t.notify("draw",{prop:"redrawImgWithObj",onPropertyChange:!1}),t.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.lowerContext}}),t.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.upperContext}}),t.currObjType.shape="",this.refreshActiveObj(),t.isCircleCrop&&t.notify("crop",{prop:"cropCircle",onPropertyChange:!1,value:{context:this.lowerContext,isSave:null,isFlip:null}}),t.notify("toolbar",{prop:"destroy-qa-toolbar",onPropertyChange:!1}),O.isNullOrUndefined(e)&&(t.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"ok"}}),t.notify("draw",{prop:"setPrevActObj",onPropertyChange:!1,value:{prevActObj:null}}))}}}},C.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},C.prototype.getNewOrder=function(){for(var e=this.parent,t=(this.updateShapeColl(),e.shapeColl.length+1),o=0;o<e.shapeColl.length;o++)e.shapeColl[o].order===t&&(t++,o=-1);return t},C.prototype.getHighestOrder=function(){for(var e=this.parent,t=(this.updateShapeColl(),0),o=0;o<e.shapeColl.length;o++)e.shapeColl[o].order>t&&(t=e.shapeColl[o].order);return t},C.prototype.getLowestOrder=function(){for(var e=this.parent,t=(this.updateShapeColl(),1),o=0;o<e.shapeColl.length;o++)e.shapeColl[o].order<t&&(t=e.shapeColl[o].order);return t},C.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()},C.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(0<e.activeObj.flipObjColl.length)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()||"vertical"===e.activeObj.flipObjColl[r].toLowerCase())&&(e.textArea.style.transform="rotate("+i+"deg)"+o);else e.textArea.style.transform="rotate("+(i+=t)+"deg)"}},C.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 e="none"!==t.textArea.style.display;return this.updateFontStyles(e),e=e?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,e},C.prototype.getObjDetails=function(e){var t,o=this.parent,i={};switch(i.id=e.currIndex,i.type=o.toPascalCase(e.shape),i.startX=e.activePoint.startX,i.startY=e.activePoint.startY,i.index=e.order,e.shape){case"rectangle":i.width=e.activePoint.width,i.height=e.activePoint.height,i.strokeColor=e.strokeSettings.strokeColor,i.fillColor=e.strokeSettings.fillColor,i.strokeWidth=e.strokeSettings.strokeWidth,i.degree=e.rotatedAngle*(180/Math.PI);break;case"ellipse":i.radius=e.activePoint.width/2,i.strokeColor=e.strokeSettings.strokeColor,i.fillColor=e.strokeSettings.fillColor,i.strokeWidth=e.strokeSettings.strokeWidth,i.radiusX=e.activePoint.width/2,i.radiusY=e.activePoint.height/2,i.degree=e.rotatedAngle*(180/Math.PI);break;case"line":case"arrow":i.length=e.activePoint.width,i.strokeColor=e.strokeSettings.strokeColor,i.strokeWidth=e.strokeSettings.strokeWidth,i.endX=e.activePoint.endX,i.endY=e.activePoint.endY,"arrow"===e.shape&&(o.notify("selection",{prop:"getArrowType",onPropertyChange:!(t={type:null}),value:{type:e.start,obj:t}}),i.arrowHead=t.type,o.notify("selection",{prop:"getArrowType",onPropertyChange:!1,value:{type:e.end,obj:t}}),i.arrowTail=t.type);break;case"text":i.text=e.keyHistory,i.fontSize=e.textSettings.fontSize,i.fontFamily=e.textSettings.fontFamily,i.color=e.strokeSettings.strokeColor,i.fontStyle=[],e.textSettings.bold&&i.fontStyle.push("bold"),e.textSettings.italic&&i.fontStyle.push("italic"),i.degree=e.rotatedAngle*(180/Math.PI);break;case"path":i.strokeColor=e.strokeSettings.strokeColor,i.strokeWidth=e.strokeSettings.strokeWidth,i.points=e.pointColl;break;case"image":i.imageData=e.imageCanvas.toDataURL(),i.degree=e.rotatedAngle*(180/Math.PI),i.width=e.activePoint.width,i.height=e.activePoint.height,i.opacity=e.opacity}return i},C.prototype.getFreehandDrawDetails=function(e){var t=this.parent,o={};return o.id=t.pointColl[e].id,o.type=v.ShapeType.FreehandDraw,o.points=O.extend([],t.pointColl[e].points),o.strokeColor=t.pointColl[e].strokeColor,o.strokeWidth=t.pointColl[e].strokeWidth,o.index=t.pointColl[e].order,o},C.prototype.getShapeSetting=function(e,t){var o,i=this.parent;if(!i.disabled&&i.isImageLoaded)if("none"!==i.textArea.style.display?i.okBtn(null,!0):this.applyActObj(!0),"shape"===e.split("_")[0]){for(var r,n=0,a=i.objColl.length;n<a;n++)if(i.objColl[n].currIndex===e){r=O.extend({},i.objColl[n],{},!0);break}o=this.getObjDetails(r)}else"pen"===e.split("_")[0]&&(o=this.getFreehandDrawDetails(parseInt(e.split("_")[1],10)-1));t.shapeDetails=o},C.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++){var n=this.getObjDetails(t.objColl[i]);o.push(n)}for(i=0;i<t.freehandCounter;i++){n=this.getFreehandDrawDetails(i);o.push(n)}}e.shapeDetailsColl=o},C.prototype.isPointsInRange=function(e,t,o){var i=!1,r=this.parent;!O.isNullOrUndefined(e)&&!O.isNullOrUndefined(t)&&e>=r.img.destLeft&&t>=r.img.destTop&&e<=r.img.destLeft+r.img.destWidth&&t<=r.img.destTop+r.img.destHeight&&(i=!0),o.inRange=i},C.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},C.prototype.popForDefaultTransformedState=function(e){for(var t=0,o=0,i=0,r=0,n=0;n<e.length;n++)90===e[n]||"rotateRight"===e[n]?(r=i=o=0,4===++t&&(e.pop(),e.pop(),e.pop(),e.pop())):-90===e[n]||"rotateLeft"===e[n]?(r=i=t=0,4===++o&&(e.pop(),e.pop(),e.pop(),e.pop())):"horizontal"===e[n]||"Horizontal"===e[n]||"horizontalflip"===e[n]?(r=t=o=0,2===++i&&(e.pop(),e.pop())):"vertical"!==e[n]&&"Vertical"!==e[n]&&"verticalflip"!==e[n]||(t=o=i=0,2===++r&&(e.pop(),e.pop()));return e},C.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],n="horizontal"===e[t+1]||"Horizontal"===e[t+1]||"horizontalFlip"===e[t+1],a="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&&a&&s&&l||r&&n&&l&&p)&&(e.splice(t,4),t-=4)}return e},C.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)}return e},C.prototype.selectShape=function(e,t){var o=this.parent,i=!1;if(!o.disabled&&o.isImageLoaded)if(this.applyActObj(),"shape"===e.split("_")[0]){for(var r,n,a=0,s=o.objColl.length;a<s;a++)if(o.objColl[a].currIndex===e){r=O.extend({},o.objColl[a],{},!0);break}O.isNullOrUndefined(r)?i=!1:(i=!0,o.activeObj=r,o.notify("toolbar",{prop:"getCanvasFilter",onPropertyChange:!(n={canvasFilter:null}),value:{obj:n}}),this.lowerContext.filter=n.canvasFilter,o.notify("selection",{prop:"redrawShape",onPropertyChange:!1,value:{obj:o.activeObj}}),"text"===o.activeObj.shape?o.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"text",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}}):"pen"===o.activeObj.shape?o.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"pen",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}}):o.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"shapes",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}}),o.notify("toolbar",{prop:"update-toolbar-items",onPropertyChange:!1}),o.notify("toolbar",{prop:"renderQAT",onPropertyChange:!1,value:{isPenEdit:null}}))}else"pen"===e.split("_")[0]&&(o.notify("selection",{prop:"getFreehandDrawEditing",onPropertyChange:!(n={bool:!1}),value:{obj:n}}),n.bool&&o.okBtn(null,!0),n={isIndex:!1},o.notify("freehand-draw",{prop:"isFHDIdx",value:{index:parseInt(e.split("_")[1],10)-1,obj:n}}),n.isIndex?(i=!0,o.notify("freehand-draw",{prop:"selectFhd",value:{id:e}}),o.notify("toolbar",{prop:"renderQAT",onPropertyChange:!1,value:{isPenEdit:!0}}),o.notify("toolbar",{prop:"update-toolbar-items",onPropertyChange:!1})):i=!1);t.isSelected=i},C.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})}},C.prototype.getMaxText=function(e,t,o){for(var i,r=(t=O.isNullOrUndefined(t)?e?this.parent.textArea.value:this.parent.activeObj.keyHistory:t).split("\n"),n=r[0].length,a=r[0],s=1;s<r.length;s++)n<(i=r[s].length)&&(a=r[s],n=i);return o&&(o.maxText=a),a},C.prototype.getLinePoints=function(e,t,o,i){var r,n,a=[];if(e===o){t<i?(r=[e,t],n=[o,i]):(n=[e,t],r=[o,i]);for(var s=this.getSlope(r,n,!0),l=this.getIntercept(r,s),p=r[1];p<=n[1];p++){var h=s*p+l;a.push({x:h,y:p})}}else{e<o?(r=[e,t],n=[o,i]):(n=[e,t],r=[o,i]);for(s=this.getSlope(r,n,!1),l=this.getIntercept(r,s),h=r[0];h<=n[0];h++){p=s*h+l;a.push({x:h,y:p})}}if(Math.floor(e)===Math.floor(o)||a.length<10&&(10<i-t||10<t-i)){for(var a=[],d=Math.min(t,i),c=0;c<Math.abs(Math.floor(i)-Math.floor(t));c++)a.push({x:e,y:d+c});1<a.length&&(u=void 0,u=O.isNullOrUndefined(a[a.length-2])?{x:0,y:0}:a[a.length-2],g=a[a.length-1].x-u.x,v=a[a.length-1].y-u.y,a.push({x:a[a.length-1].x+g/2,y:a[a.length-1].y+v/2}))}else if(Math.floor(t)===Math.floor(i)||a.length<10&&(10<o-e||10<e-o)){a=[];for(var u,g,v,f=Math.min(e,o),C=0;C<Math.abs(Math.floor(o)-Math.floor(e));C++)a.push({x:f+C,y:t});1<a.length&&(u=void 0,u=O.isNullOrUndefined(a[a.length-2])?{x:0,y:0}:a[a.length-2],g=a[a.length-1].x-u.x,v=a[a.length-1].y-u.y,a.push({x:a[a.length-1].x+g/2,y:a[a.length-1].y+v/2}))}return a},C.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},C.prototype.getIntercept=function(e,t){return null===t?e[0]:e[1]-t*e[0]},C.prototype.setPointCollForShapeRotation=function(e){var t=this.parent,o=e.activePoint,i=o.startX,r=o.startY,n=o.endX,a=o.endY,s=i+o.width/2,o=r+o.height/2,l=Math.cos(e.rotatedAngle),p=Math.sin(e.rotatedAngle),h={x:l*(i-s)-p*(r-o)+s,y:p*(i-s)+l*(r-o)+o},r={x:l*(n-s)-p*(r-o)+s,y:p*(n-s)+l*(r-o)+o},i={x:l*(i-s)-p*(a-o)+s,y:p*(i-s)+l*(a-o)+o},n={x:l*(n-s)-p*(a-o)+s,y:p*(n-s)+l*(a-o)+o};e.horTopLinePointColl=this.getLinePoints(h.x,h.y,r.x,r.y),e.horTopLinePointColl=this.getLinePoints(h.x,h.y,r.x,r.y),e.horBottomLinePointColl=this.getLinePoints(i.x,i.y,n.x,n.y),e.verLeftLinePointColl=this.getLinePoints(h.x,h.y,i.x,i.y),e.verRightLinePointColl=this.getLinePoints(r.x,r.y,n.x,n.y),e.verLeftLinePointColl.reverse(),e.verRightLinePointColl.reverse();for(var d=0;d<e.horTopLinePointColl.length;d++)e.horTopLinePointColl[d].ratioX=(e.horTopLinePointColl[d].x-this.parent.img.destLeft)/this.parent.img.destWidth,e.horTopLinePointColl[d].ratioY=(e.horTopLinePointColl[d].y-this.parent.img.destTop)/this.parent.img.destHeight;for(d=0;d<e.horBottomLinePointColl.length;d++)e.horBottomLinePointColl[d].ratioX=(e.horBottomLinePointColl[d].x-this.parent.img.destLeft)/this.parent.img.destWidth,e.horBottomLinePointColl[d].ratioY=(e.horBottomLinePointColl[d].y-this.parent.img.destTop)/this.parent.img.destHeight;for(d=0;d<e.verLeftLinePointColl.length;d++)e.verLeftLinePointColl[d].ratioX=(e.verLeftLinePointColl[d].x-this.parent.img.destLeft)/this.parent.img.destWidth,e.verLeftLinePointColl[d].ratioY=(e.verLeftLinePointColl[d].y-this.parent.img.destTop)/this.parent.img.destHeight;for(d=0;d<e.verRightLinePointColl.length;d++)e.verRightLinePointColl[d].ratioX=(e.verRightLinePointColl[d].x-this.parent.img.destLeft)/this.parent.img.destWidth,e.verRightLinePointColl[d].ratioY=(e.verRightLinePointColl[d].y-this.parent.img.destTop)/this.parent.img.destHeight;"move"!==t.upperCanvas.style.cursor&&(t.notify("selection",{prop:"getTransRotationPoint",value:{obj:e,object:a={rotationCirclePoint:null}}}),h=a.rotationCirclePoint)&&(e.rotationCirclePointColl={x:l*(h.x-s)-p*(h.y-o)+s,y:p*(h.x-s)+l*(h.y-o)+o},e.rotationCirclePointColl.ratioX=(e.rotationCirclePointColl.x-t.img.destLeft)/t.img.destWidth,e.rotationCirclePointColl.ratioY=(e.rotationCirclePointColl.y-t.img.destTop)/t.img.destHeight)},C.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,n=i.startY,a=i.endX,s=i.endY,l=r+i.width/2,i=n+i.height/2,p=Math.cos(e.rotatedAngle),e=Math.sin(e.rotatedAngle),h={x:p*(r-l)-e*(n-i)+l,y:e*(r-l)+p*(n-i)+i},n={x:p*(a-l)-e*(n-i)+l,y:e*(a-l)+p*(n-i)+i},r={x:p*(r-l)-e*(s-i)+l,y:e*(r-l)+p*(s-i)+i},e={x:p*(a-l)-e*(s-i)+l,y:e*(a-l)+p*(s-i)+i};return o.startX=h.x,o.startY=h.y,o.endX=h.x,o.endY=h.y,n.x<o.startX&&(o.startX=n.x),r.x<o.startX&&(o.startX=r.x),e.x<o.startX&&(o.startX=e.x),n.y<o.startY&&(o.startY=n.y),r.y<o.startY&&(o.startY=r.y),e.y<o.startY&&(o.startY=e.y),o.endX<n.x&&(o.endX=n.x),o.endX<r.x&&(o.endX=r.x),o.endX<e.x&&(o.endX=e.x),o.endY<n.y&&(o.endY=n.y),o.endY<r.y&&(o.endY=r.y),o.endY<e.y&&(o.endY=e.y),o.width=o.endX-o.startX,o.height=o.endY-o.startY,t&&(t.activePoint=o),o},C.prototype.updateZOrder=function(e,t){var o=this.parent,i=(t=t.toLowerCase(),e);if(!O.isNullOrUndefined(i.order)){var r,n,a=this.getHighestOrder();if(this.updateShapeColl(),0!==o.shapeColl.length){for(var s,l=0;l<o.shapeColl.length;l++)s=o.shapeColl[l],i.id&&-1<i.id.indexOf("pen")?s.id&&s.id===i.id&&o.shapeColl.splice(l,1):s.shape&&-1<s.shape.indexOf("crop-")&&o.shapeColl.splice(l,1);switch(t){case"sendtoback":n=i.order,r=i.order,i.order=1;break;case"sendbackward":--i.order,r=i.order;break;case"bringtofront":n=i.order,i.order=r=a;break;case"bringforward":i.order+=1,r=i.order}this.reArrangeObjColl(r,t,n),i.id&&-1<i.id.indexOf("pen")&&this.reUpdateShapeColl(i)}}},C.prototype.reArrangeObjColl=function(e,t,o){var i,r=this.parent;switch(t){case"sendtoback":for(var n=0,a=r.shapeColl.length;n<a;n++)(i=r.shapeColl[n]).order<o&&i.order<=e&&(i.order+=1,this.reUpdateShapeColl(i));break;case"sendbackward":for(n=0,a=r.shapeColl.length;n<a;n++)if((i=r.shapeColl[n]).order===e){i.order+=1,this.reUpdateShapeColl(i);break}break;case"bringtofront":for(n=0,a=r.shapeColl.length;n<a;n++)(i=r.shapeColl[n]).order>o&&i.order<=e&&(--i.order,this.reUpdateShapeColl(i));break;case"bringforward":for(n=0,a=r.shapeColl.length;n<a;n++)if((i=r.shapeColl[n]).order===e){--i.order,this.reUpdateShapeColl(i);break}}},C.prototype.updateShapeColl=function(){var e=this.parent,t=!1,o=1,i=O.extend([],e.objColl,[],!0),r=O.extend([],e.pointColl,[],!0);if(0<e.shapeColl.length&&e.shapeColl.length===e.objColl.length+e.pointColl.length){for(var n=0;n<e.shapeColl.length;n++){if(e.shapeColl[n].order!==o){t=!1;break}t=!0,o++}if(t){for(n=0;n<e.shapeColl.length;n++)if(e.shapeColl[n].currIndex&&-1<e.shapeColl[n].currIndex.indexOf("shape")){for(var a=0;a<i.length;a++)if(e.shapeColl[n].currIndex===i[a].currIndex){e.shapeColl[n]=O.extend({},i[a],{},!0),i.splice(a,1);break}}else if(e.shapeColl[n].id&&-1<e.shapeColl[n].id.indexOf("pen"))for(a=0;a<r.length;a++)if(e.shapeColl[n].id===r[a].id){e.shapeColl[n]=O.extend([],r[a],[],!0),r.splice(a,1);break}return}}for(var i=O.extend([],e.objColl,[],!0),r=O.extend([],e.pointColl,[],!0),s=1,l=!(e.shapeColl=[]);0!==i.length||0!==r.length;){for(var p=l=!1,n=0;n<i.length;n++)if(i[n].order===s||!i[n].order&&i[n].shape&&-1<i[n].shape.indexOf("crop-")){e.shapeColl.push(O.extend({},i[n],{},!0)),i[n].shape&&-1<i[n].shape.indexOf("crop-")&&(l=!0),i.splice(n,1),p=!0;break}if(!p)for(n=0;n<r.length;n++)if(r[n].order===s){e.shapeColl.push(O.extend([],r[n],[],!0)),r.splice(n,1),p=!0;break}l||s++}},C.prototype.reUpdateShapeColl=function(e){var t=this.parent;if(e.id&&-1<e.id.indexOf("pen")){if(0<t.freehandCounter)for(var o=0;o<t.freehandCounter;o++)t.pointColl[o].id===e.id&&(t.pointColl[o].order=e.order)}else if(e.currIndex&&-1<e.currIndex.indexOf("shape"))for(o=0;o<t.objColl.length;o++)t.objColl[o].currIndex===e.currIndex&&(t.objColl[o].order=e.order)},C.prototype.drawAnnotations=function(e,t,o,i,r,n,a){var s=this.parent,l=O.extend({},s.activeObj,{},!0),p=O.extend([],s.objColl,[],!0),h=O.extend([],s.pointColl,[],!0),d=(this.updateShapeColl(),O.extend([],s.shapeColl,[],!0)),c=!1;this.preventFrameAnnotation||(this.preventFrameAnnotation=c=!0);for(var u=0;u<d.length;u++){var g=d[u].id;if(d[u].order||!d[u].order&&d[u].shape&&-1<d[u].shape.indexOf("crop-")||!d[u].order&&"path"===d[u].shape&&"path"===s.drawingShape){if(d[u].currIndex&&-1<d[u].currIndex.indexOf("shape")){if(s.objColl=[],s.objColl.push(O.extend({},d[u],{},!0)),"iterate"===t){var v=this.lowerContext.filter;this.lowerContext.filter="none",this.iterateObjColl(),this.lowerContext.filter=v}else if("zoom"===t||"pan"===t){for(var f=-1,C=0;C<p.length;C++)if(JSON.stringify(p[C])===JSON.stringify(s.objColl[0])){f=C;break}"zoom"===t?this.zoomObjColl(i):this.panObjColl(r,n,a),-1<f&&(p[f]=O.extend({},s.objColl[0],{},!0))}}else if(d[u].id&&-1<d[u].id.indexOf("pen"))if(s.pointColl=[],s.freehandCounter=0,s.pointColl.push(O.extend({},d[u],{},!0)),s.freehandCounter=s.pointColl.length,"iterate"===o)s.notify("freehand-draw",{prop:"freehandRedraw",onPropertyChange:!1,value:{context:e,points:null}});else if("zoom"===o||"pan"===o){"zoom"===o?s.notify("freehand-draw",{prop:"zoomFHDColl",onPropertyChange:!1,value:{isPreventApply:i}}):s.notify("freehand-draw",{prop:"panFHDColl",onPropertyChange:!1,value:{xDiff:r,yDiff:n,panRegion:a}});for(var b=0;b<h.length;b++)if(h[b].id===s.pointColl[0].id){h[b]=O.extend({},s.pointColl[0],{},!0);break}}}else(d[u].shape||g)&&(d[u].currIndex||g)||d.splice(u,1)}o&&"zoom"===o&&(s.pointColl=[],s.freehandCounter=0,s.notify("freehand-draw",{prop:"zoomFHDColl",onPropertyChange:!1,value:{isPreventApply:i}})),s.objColl=p,s.pointColl=h,s.freehandCounter=s.pointColl.length,c&&this.preventFrameAnnotation&&(s.notify("draw",{prop:"applyFrame",value:{ctx:this.lowerContext,frame:s.frameObj.type,preventImg:!0}}),this.preventFrameAnnotation=!1),s.activeObj=l};var H=C;function C(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()}b.prototype.destroy=function(){this.parent.isDestroyed||this.removeEventListener()},b.prototype.addEventListener=function(){this.parent.on("transform",this.transform,this),this.parent.on("destroyed",this.destroy,this)},b.prototype.removeEventListener=function(){this.parent.off("transform",this.transform),this.parent.off("destroyed",this.destroy)},b.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}},b.prototype.getModuleName=function(){return"transform"},b.prototype.initTransformPvtVar=function(){this.parent.lowerCanvas&&(this.lowerContext=this.parent.lowerCanvas.getContext("2d")),this.parent.upperCanvas&&(this.upperContext=this.parent.upperCanvas.getContext("2d"))},b.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},b.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)},b.prototype.rotateEvent=function(e,t){var o,i=this.parent;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}})):(e=void 0,O.isNullOrUndefined(this.transCurrObj)&&(i.notify("filter",{prop:"getCurrentObj",onPropertyChange:!(o={currObj:{}}),value:{object:o}}),(e=o.currObj).objColl=O.extend([],i.objColl,null,!0),e.pointColl=O.extend({},i.pointColl,null,!0),e.afterCropActions=O.extend([],i.afterCropActions,[],!0),i.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!(o={selPointColl:null}),value:{obj:o}}),e.selPointColl=O.extend([],o.selPointColl,[],!0)),i.afterCropActions.push(90===t?"rotateRight":"rotateLeft"),e=[],o=void 0,i.activeObj.activePoint&&i.activeObj.shape&&(void 0!==i.activeObj.shape&&(e=i.activeObj.shape.split("-")),!i.currObjType.isCustomCrop&&"crop"!==e[0]||(o=i.currObjType.isCustomCrop?"custom":e[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(t),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}}),o&&(this.upperContext.clearRect(0,0,i.upperCanvas.width,i.upperCanvas.height),i.activeObj=O.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,e={collection:i.rotateFlipColl},i.notify("shape",{prop:"alignRotateFlipColl",onPropertyChange:!1,value:{collection:i.rotateFlipColl,isRotateFlipCollection:!0,obj:e}}),i.rotateFlipColl=e.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))},b.prototype.drawRotatedImage=function(e){var t=this.parent,o=(0===e?t.transform.degree=0:t.transform.degree+=e,360===Math.abs(t.transform.degree)&&(t.transform.degree=0),t.notify("draw",{prop:"setDestPoints",onPropertyChange:!1}),O.extend([],t.objColl,[],!0)),i=O.extend({},t.activeObj,{},!0);if(t.objColl=[],t.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),this.isReverseRotate||t.notify("draw",{prop:"updateCurrTransState",onPropertyChange:!1,value:{type:"initial",isPreventDestination:null,isRotatePan:null}}),this.rotateDegree(e),this.isReverseRotate||(t.notify("draw",{prop:"updateCurrTransState",onPropertyChange:!1,value:{type:"reverse",isPreventDestination:null,isRotatePan:null}}),t.rotateFlipColl.push(e)),t.objColl=O.extend([],o,[],!0),t.activeObj=O.extend({},i,{},!0),t.isCircleCrop&&t.notify("crop",{prop:"cropCircle",onPropertyChange:!1,value:{context:this.lowerContext,isSave:null,isFlip:null}}),t.notify("shape",{prop:"redrawObj",onPropertyChange:!1,value:{degree:e}}),t.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),0<e)t.notify("freehand-draw",{prop:"rotateFhdColl",onPropertyChange:!1});else for(var r=0;r<3;r++)t.notify("freehand-draw",{prop:"rotateFhdColl",onPropertyChange:!1});t.notify("freehand-draw",{prop:"freehandRedraw",onPropertyChange:!1,value:{context:this.lowerContext,points:null}}),this.updateCurrSelectionPoint(e)},b.prototype.rotateDegree=function(e){var t=this.parent,o=(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),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()},b.prototype.updateCurrSelectionPoint=function(e){var t,o,i,r,n=this.parent;n.currSelectionPoint&&this.currDestPoint&&(t=O.extend({},n.activeObj,{},!0),o=O.extend([],n.objColl,[],!0),i={startX:n.img.srcLeft,startY:n.img.srcTop,width:n.img.srcWidth,height:n.img.srcHeight},r={startX:n.img.destLeft,startY:n.img.destTop,width:n.img.destWidth,height:n.img.destHeight},n.objColl=[],n.objColl.push(O.extend({},n.currSelectionPoint,{},!0)),O.isNullOrUndefined(n.objColl[0].imageRatio)&&(n.activeObj=n.objColl[0],n.notify("shape",{prop:"updImgRatioForActObj",onPropertyChange:!1}),n.objColl[0]=n.activeObj),n.img={srcLeft:0,srcTop:0,srcWidth:n.baseImgCanvas.width,srcHeight:n.baseImgCanvas.height,destLeft:this.currDestPoint.startX,destTop:this.currDestPoint.startY,destWidth:this.currDestPoint.width,destHeight:this.currDestPoint.height},"number"==typeof e&&(n.notify("draw",{prop:"setDestPoints",onPropertyChange:!1}),n.notify("draw",{prop:"setClientTransDim",onPropertyChange:!1,value:{isPreventDimension:null}})),n.notify("shape",{prop:"redrawObj",onPropertyChange:!1,value:{degree:e}}),n.currSelectionPoint=O.extend({},n.objColl[0],{},!0),this.currDestPoint={startX:n.img.destLeft,startY:n.img.destTop,width:n.img.destWidth,height:n.img.destHeight},n.objColl=o,n.activeObj=t,n.img={srcLeft:i.startX,srcTop:i.startY,srcWidth:i.width,srcHeight:i.height,destLeft:r.startX,destTop:r.startY,destWidth:r.width,destHeight:r.height})},b.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)},b.prototype.flipEvent=function(e,t){var o=this.parent;if(e.cancel)o.notify("draw",{prop:"setCurrentObj",onPropertyChange:!1,value:{obj:o.prevEventObjPoint}}),o.activeObj=o.prevEventSelectionPoint,o.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate",obj:o.activeObj}});else{O.isNullOrUndefined(this.transCurrObj)&&(o.notify("filter",{prop:"getCurrentObj",onPropertyChange:!(e={currObj:{}}),value:{object:e}}),(e=e.currObj).objColl=O.extend([],o.objColl,null,!0),e.pointColl=O.extend({},o.pointColl,null,!0),e.afterCropActions=O.extend([],o.afterCropActions,[],!0),o.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!(r={selPointColl:null}),value:{obj:r}}),e.selPointColl=O.extend([],r.selPointColl,[],!0)),o.afterCropActions.push("horizontal"===t.toLowerCase()?"horizontalflip":"verticalflip");var i,e=[],r=(o.activeObj.activePoint&&(void 0!==o.activeObj.shape&&(e=o.activeObj.shape.split("-")),!o.currObjType.isCustomCrop&&"crop"!==e[0]||(i=o.currObjType.isCustomCrop?"custom":e[1],o.notify("shape",{prop:"updImgRatioForActObj",onPropertyChange:!1}),o.objColl.push(o.activeObj),o.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}))),o.notify("shape",{prop:"redrawActObj",onPropertyChange:!1,value:{x:null,y:null,isMouseDown:!0}}),o.clearContext(this.lowerContext),o.clearContext(this.upperContext),O.extend([],o.objColl,[],!0)),e=O.extend({},o.activeObj,{},!0),n=(o.objColl=[],o.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),this.isReverseFlip||o.notify("draw",{prop:"updateCurrTransState",onPropertyChange:!1,value:{type:"initial",isPreventDestination:null,isRotatePan:null}}),t.toLowerCase()),a=(this.updateFlipState(n),o.transform.currFlipState.toLowerCase()),a=(o.transform.currFlipState="horizontal"===n&&"horizontal"===a||"vertical"===n&&"vertical"===a?"":n,{isSelected:null}),n=(o.notify("draw",{prop:"getRotatedFlipCropSelection",onPropertyChange:!1,value:{bool:a}}),a.isSelected&&(o.img.destLeft+=o.panPoint.totalPannedInternalPoint.x,o.img.destTop+=o.panPoint.totalPannedInternalPoint.y),this.lowerContext.filter);o.notify("draw",{prop:"drawImage",onPropertyChange:!1}),this.lowerContext.filter=n,o.notify("draw",{prop:"setImageEdited",onPropertyChange:!1}),this.updateFlipState(t.toLowerCase()),this.isReverseFlip||(o.notify("draw",{prop:"updateCurrTransState",onPropertyChange:!1,value:{type:"reverse",isPreventDestination:null,isRotatePan:null}}),this.updateFlipColl(t.toLocaleLowerCase()),o.rotateFlipColl.push(t.toLowerCase())),1===o.rotateFlipColl.length&&(o.notify("crop",{prop:"getCurrFlipState",onPropertyChange:!(a={panRegion:""}),value:{panObj:a}}),""===a.panRegion?o.notify("draw",{prop:"setClientTransDim",onPropertyChange:!1,value:{isPreventDimension:null}}):this.setDestPointsForFlipState()),o.isCircleCrop&&o.notify("crop",{prop:"cropCircle",onPropertyChange:!1,value:{context:this.lowerContext,isSave:null,isFlip:null}}),o.objColl=O.extend([],r,[],!0),o.activeObj=O.extend({},e,{},!0);for(var s=0,l=o.objColl.length;s<l;s++){var p=o.objColl[s].flipObjColl;0!==p.length&&p[p.length-1]===t?p.pop():p.push(t)}o.notify("shape",{prop:"redrawObj",onPropertyChange:!1,value:{degree:t.toLowerCase()}});n=this.lowerContext.filter,a=(this.lowerContext.filter="brightness(1) contrast(100%) hue-rotate(0deg) saturate(100%) opacity(1) blur(0px) sepia(0%) grayscale(0%) invert(0%)",o.notify("shape",{prop:"iterateObjColl",onPropertyChange:!1}),t.toLowerCase()),r=(("horizontal"===a||"vertical"===a)&&o.notify("freehand-draw",{prop:"flipFHDColl",onPropertyChange:!1,value:{value:a}}),o.notify("freehand-draw",{prop:"freehandRedraw",onPropertyChange:!1,value:{context:this.lowerContext,points:null}}),this.lowerContext.filter=n,o.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),this.updateCurrSelectionPoint(a),o.isUndoRedo=!1,o.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.lowerContext}}),o.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.upperContext}}),o.isCircleCrop&&o.notify("crop",{prop:"cropCircle",onPropertyChange:!1,value:{context:this.lowerContext,isSave:null,isFlip:null}}),i&&(this.upperContext.clearRect(0,0,o.upperCanvas.width,o.upperCanvas.height),o.activeObj=O.extend({},o.objColl[o.objColl.length-1],{},!0),o.objColl.pop(),o.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate",obj:o.activeObj}})),{collection:o.rotateFlipColl});o.notify("shape",{prop:"alignRotateFlipColl",onPropertyChange:!1,value:{collection:o.rotateFlipColl,isRotateFlipCollection:!0,obj:r}}),o.rotateFlipColl=r.collection,o.cropObj.activeObj.shape&&!this.isPreventSelect&&(o.notify("draw",{prop:"setIsCropSelect",value:{bool:!0}}),this.isPreventSelect=!0,o.notify("draw",{prop:"select",onPropertyChange:!1,value:{type:"custom",startX:null,startY:null,width:null,height:null}}),this.isPreventSelect=!1,o.setProperties({zoomSettings:{zoomFactor:1}},!0),this.prevZoomValue=o.zoomSettings.zoomFactor)}},b.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())},b.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)},b.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)},b.prototype.updateFlipColl=function(e){this.isPreventSelect||(0===this.flipColl.length||this.flipColl[this.flipColl.length-1]!==e?this.flipColl.push(e):this.flipColl.pop(),4<=this.flipColl.length&&("horizontal"===(e=this.flipColl.slice(-4))[0]&&"vertical"===e[1]&&"horizontal"===e[2]&&"vertical"===e[3]||"vertical"===e[0]&&"horizontal"===e[1]&&"vertical"===e[2]&&"horizontal"===e[3])&&this.flipColl.splice(-4))},b.prototype.setDestPointsForFlipState=function(){var e=this.parent,t={panRegion:""},o=e.img,i=o.destLeft,r=o.destTop,n=o.destWidth,o=o.destHeight,a=e.lowerCanvas,s=a.clientWidth,a=a.clientHeight;e.notify("crop",{prop:"getCurrFlipState",onPropertyChange:!1,value:{panObj:t}}),""!==t.panRegion&&("horizontal"===t.panRegion?e.img.destLeft=s-(n+i):("vertical"!==t.panRegion&&(e.img.destLeft=s-(n+i)),e.img.destTop=a-(o+r)))},b.prototype.zoomAction=function(e,t,o,i){var r=this.parent;if(!r.disabled&&r.isImageLoaded)if(O.isNullOrUndefined(o)&&(r.zoomSettings.zoomFactor>=r.zoomSettings.maxZoomFactor&&0<e||r.zoomSettings.zoomFactor>r.zoomSettings.minZoomFactor&&e<0&&this.disableZoomOutBtn(!0)||r.zoomSettings.zoomFactor<=r.zoomSettings.minZoomFactor&&e<0))r.notify("toolbar",{prop:"zoom-up-handler",onPropertyChange:!1});else{r.notify("draw",{prop:"setImageEdited",onPropertyChange:!1});var n=e;e=0<n?.1:-.1;for(var a,s=0;s<Math.round(Math.abs(n/.1));s++)1===this.prevZoomValue?this.prevZoomValue+=0<e?10*e:10*e/10:1<this.prevZoomValue?this.prevZoomValue+=10*e:this.prevZoomValue<1&&(this.prevZoomValue+=10*e/10,a=Math.pow(10,1),this.prevZoomValue=Math.round(this.prevZoomValue*a)/a);e=n,r.setProperties({zoomSettings:{zoomFactor:this.prevZoomValue}},!0);var o=void 0,o=(this.tempActiveObj=null,this.isShape=!1,void 0!==r.activeObj.shape&&("shape"===r.activeObj.shape?r.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}):o=r.activeObj.shape.split("-")),void 0!==o&&"crop"===o[0]?(this.tempActiveObj=O.extend({},r.activeObj,{},!0),r.isCropTab=!0):r.activeObj.shape&&"crop"!==o[0]&&(this.isShape=!0),{zoomType:null}),l=(r.notify("selection",{prop:"getZoomType",onPropertyChange:!1,value:{obj:o}}),O.isNullOrUndefined(t)&&(t=r.isCropTab&&this.tempActiveObj?{x:r.activeObj.activePoint.startX+r.activeObj.activePoint.width/2,y:r.activeObj.activePoint.startY+r.activeObj.activePoint.height/2}:{x:r.lowerCanvas.clientWidth/2,y:r.lowerCanvas.clientHeight/2},"MouseWheel"!==o.zoomType&&"Pinch"!==o.zoomType||(t={x:r.zoomSettings.zoomPoint.x,y:r.zoomSettings.zoomPoint.y})),r.zoomSettings.zoomFactor-10*e),t={zoomPoint:t,cancel:!1,previousZoomFactor:l,currentZoomFactor:r.zoomSettings.zoomFactor,zoomTrigger:o.zoomType};!r.isCropToolbar&&r.isZoomBtnClick&&r.trigger("zooming",t),this.zoomEvent(t,e,i)}},b.prototype.zoomEvent=function(e,t,o){var i,r,n,a,s=this.parent,l=s.zoomSettings,p=l.zoomFactor,l=l.minZoomFactor;e.cancel?s.isZoomBtnClick=!1:(s.notify("toolbar",{prop:"close-contextual-toolbar",onPropertyChange:!1}),s.notify("shape",{prop:"redrawActObj",onPropertyChange:!1,value:{x:null,y:null,isMouseDown:!0}}),s.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),this.upperContext.clearRect(0,0,s.lowerCanvas.width,s.lowerCanvas.height),n={canvasFilter:s.canvasFilter},this.lowerContext.filter=n.canvasFilter,s.upperCanvas.style.cursor=s.cursor="default",n=O.extend([],s.objColl,[],!0),s.isCropTab||(0!==s.transform.degree?(s.notify("shape",{prop:"redrawActObj",onPropertyChange:!1,value:{x:null,y:null,isMouseDown:null}}),s.panPoint.currentPannedPoint={x:0,y:0},a=s.allowDownScale,s.allowDownScale=!1,this.rotatePan(!0,!0),s.allowDownScale=a):""!==s.transform.currFlipState&&(s.panPoint.totalPannedPoint={x:0,y:0}),0!==s.transform.straighten)||this.isPreventSelect||s.notify("freehand-draw",{prop:"updateFHDColl",onPropertyChange:!1,value:{isPreventApply:o}}),0===s.transform.degree?(this.drawZoomImgToCanvas(t,this.tempActiveObj),s.notify("crop",{prop:"getCurrFlipState",onPropertyChange:!(i={panRegion:""}),value:{panObj:i}}),""!==i.panRegion&&(s.notify("crop",{prop:"setTempFlipPanPoint",onPropertyChange:!1,value:{point:s.panPoint.totalPannedPoint,isAdd:!0}}),n=O.extend([],s.objColl,[],!0),s.objColl=[],i=s.img.destLeft,r=s.img.destTop,this.setDestPointsForFlipState(),this.rotatedFlip(),s.img.destLeft=i,s.img.destTop=r,s.objColl=n,s.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"zoom",pen:"zoom",isPreventApply:o}}),0!==s.transform.straighten||this.isPreventSelect||s.notify("freehand-draw",{prop:"updateFHDColl",onPropertyChange:!1,value:{isPreventApply:o}})),p<=l&&!s.isCropTab&&(s.panPoint.totalPannedPoint={x:0,y:0})):(0!==s.transform.straighten||this.isPreventSelect||s.notify("freehand-draw",{prop:"updateFHDColl",onPropertyChange:!1,value:{isPreventApply:o}}),s.panPoint.totalPannedClientPoint={x:0,y:0},s.panPoint.totalPannedInternalPoint={x:0,y:0},this.rotateZoom(t),s.notify("crop",{prop:"getCurrFlipState",onPropertyChange:!(i={panRegion:""}),value:{panObj:i}}),""!==i.panRegion&&(a=this.lowerContext.filter,this.lowerContext.filter="none",s.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"zoom",pen:"zoom",isPreventApply:o}}),this.lowerContext.filter=a)),r=Math.pow(10,1),(p<=l||Math.round(s.transform.zoomFactor*r)/r==2)&&(clearInterval(this.zoomBtnHold),this.zoomBtnHold=0),s.notify("crop",{prop:"getCurrFlipState",onPropertyChange:!(n={panRegion:""}),value:{panObj:n}}),""===n.panRegion&&(a=this.lowerContext.filter,this.lowerContext.filter="none",s.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"zoom",pen:"zoom",isPreventApply:o}}),this.lowerContext.filter=a),(s.currSelectionPoint&&"crop-circle"===s.currSelectionPoint.shape||s.isCircleCrop)&&s.notify("crop",{prop:"cropCircle",onPropertyChange:!1,value:{context:this.lowerContext,isSave:null,isFlip:null}}),s.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.lowerContext}}),s.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),this.tempActiveObj&&(s.activeObj=O.extend({},this.tempActiveObj,{},!0),s.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate",obj:s.activeObj}}),p<=l)&&(s.currSelectionPoint=null),s.isUndoRedo=!1,(t=document.querySelector("#"+s.element.id+"_zoomOut"))&&p<=l?(t.classList.add("e-disabled"),t.parentElement.classList.add("e-overlay")):t&&(t.classList.remove("e-disabled"),t.parentElement.classList.remove("e-overlay")),i=s.drawingShape,this.autoEnablePan(),s.drawingShape=i,this.tempActiveObj&&(s.activeObj=O.extend({},this.tempActiveObj,{},!0)),"crop-custom"===s.activeObj.shape&&(s.currObjType.isCustomCrop=!0),(r=s.element.querySelector(".e-img-pan .e-btn"))&&s.togglePan?r.classList.add("e-selected-btn"):r&&r.classList.remove("e-selected-btn"),this.isShape&&(s.activeObj=O.extend({},s.objColl[s.objColl.length-1],{},!0),s.objColl.pop(),s.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate",obj:s.activeObj,isCropRatio:null,points:null,isPreventDrag:!0,saveContext:null,isPreventSelection:null}}),s.notify("toolbar",{prop:"update-toolbar-items",onPropertyChange:!1}),s.notify("toolbar",{prop:"renderQAT",onPropertyChange:!1,value:{isPenEdit:null}})),s.notify("toolbar",{prop:"enable-disable-btns",onPropertyChange:!1}),s.notify("selection",{prop:"setZoomType",onPropertyChange:!1,value:{zoomType:"Toolbar"}}),e={zoomPoint:e.zoomPoint,previousZoomFactor:e.previousZoomFactor,currentZoomFactor:e.currentZoomFactor,zoomTrigger:e.zoomTrigger},!s.isCropToolbar&&s.isZoomBtnClick&&(s.isZoomBtnClick=!1),s.drawingShape&&(n=O.extend({},s.activeObj,{},!0),s.enableShapeDrawing(s.toPascalCase(s.drawingShape),!0),0<(s.activeObj=n).activePoint.width||0<n.activePoint.height||n.pointColl&&0<n.pointColl.length)&&(o=s.element.querySelector("#"+s.element.id+"_zOrderBtn"),a=s.element.querySelector("#"+s.element.id+"_duplicate"),p=s.element.querySelector("#"+s.element.id+"_remove"),l=s.element.querySelector("#"+s.element.id+"_editText"),o&&o.classList.remove("e-disabled"),a&&a.classList.remove("e-disabled"),p&&p.classList.remove("e-disabled"),l)&&l.classList.remove("e-disabled"))},b.prototype.disableZoomOutBtn=function(e){var t,o,i,r=this.parent,n=r.zoomSettings,a=n.zoomFactor,n=n.minZoomFactor,s=!1,l=(O.isNullOrUndefined(e)||(r.transform.zoomFactor-=.1),t=r.element.querySelector("#"+r.element.id+"_zoomOut"),{destLeft:r.img.destLeft,destTop:r.img.destTop,destWidth:r.img.destWidth,destHeight:r.img.destHeight});return r.activeObj.shape?(o=this.setZoomDimension(-.1,r.activeObj),O.isNullOrUndefined(t)||(i=r.activeObj.activePoint,s=0===r.transform.straighten?r.img.destLeft>i.startX||r.img.destTop>i.startY||r.img.destLeft+r.img.destWidth<i.endX||r.img.destTop+r.img.destHeight<i.endY||a===n?(t.classList.add("e-disabled"),t.parentElement.classList.add("e-overlay"),!0):(t.classList.remove("e-disabled"),t.parentElement.classList.remove("e-overlay"),!1):(r.img.destWidth=o.width,r.img.destHeight=o.height,r.notify("draw",{prop:"updateImgCanvasPoints",onPropertyChange:!(i={isIntersect:null})}),r.notify("draw",{prop:"isLinesIntersect",onPropertyChange:!1,value:{obj:i}}),i.isIntersect||a===n?(t.classList.add("e-disabled"),t.parentElement.classList.add("e-overlay"),!0):(t.classList.remove("e-disabled"),t.parentElement.classList.remove("e-overlay"),!1)))):this.setZoomDimension(-.1,null),O.isNullOrUndefined(e)||(r.transform.zoomFactor+=.1),r.img.destLeft=l.destLeft,r.img.destTop=l.destTop,r.img.destWidth=l.destWidth,r.img.destHeight=l.destHeight,s},b.prototype.drawZoomImgToCanvas=function(e,t){var o=this.parent,i=Math.pow(10,1),i=Math.round(o.transform.zoomFactor*i)/i,i=(.1==i&&-.1===e||0==i&&-.025===e?o.transform.zoomFactor=0:o.transform.zoomFactor+=e,o.transform[o.isCropTab?"cropZoomFactor":"defaultZoomFactor"]=o.transform.zoomFactor,{width:0,height:0});o.isCropTab?i=this.cropZoom(e,t):((i=this.calcMaxDimension(o.img.srcWidth,o.img.srcHeight)).width+=i.width*o.transform.zoomFactor,i.height+=i.height*o.transform.zoomFactor,o.img.destLeft=(o.lowerCanvas.clientWidth-i.width)/2,o.img.destTop=(o.lowerCanvas.clientHeight-i.height+1)/2),o.notify("draw",{prop:"draw-image-to-canvas",value:{dimension:i}}),i.width=this.cropDimension.width,i.height=this.cropDimension.height,i.width+=i.width*o.transform.zoomFactor,i.height+=i.height*o.transform.zoomFactor,o.notify("draw",{prop:"setZoomCropWidth",value:{width:i.width,height:i.height}})},b.prototype.rotatedFlip=function(){var e=this.parent,t=(this.isReverseFlip=!0,e.transform.currFlipState),o=this.flipColl,i=O.extend([],e.objColl,[],!0),r=O.extend({},e.activeObj,{},!0),n=(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}}),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}}),""===t&&""!==e.transform.currFlipState&&(t=e.transform.currFlipState),e.transform.currFlipState=t,this.flipColl=o,e.objColl=O.extend([],i,[],!0),this.lowerContext.filter="none",e.notify("shape",{prop:"iterateObjColl",onPropertyChange:!1}),this.lowerContext.filter=n,0!==r.activePoint.width&&(e.activeObj=O.extend({},r,{},!0)),this.isReverseFlip=!1},b.prototype.rotateZoom=function(e){var t=this.parent,o=Math.pow(10,1),o=Math.round(t.transform.zoomFactor*o)/o,o=(.1==o&&-.1===e||0==o&&-.025===e?t.transform.zoomFactor=0:t.transform.zoomFactor+=e,t.isCropTab?t.transform.cropZoomFactor=t.transform.zoomFactor:t.transform.defaultZoomFactor=t.transform.zoomFactor,O.extend([],t.objColl,[],!0)),e=O.extend({},t.activeObj,{},!0),i=(t.objColl=[],t.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),t.notify("draw",{prop:"updateCurrTransState",onPropertyChange:!1,value:{type:"initial",isPreventDestination:null,isRotatePan:null}}),t.notify("draw",{prop:"setRotateZoom",onPropertyChange:!1,value:{isRotateZoom:!0}}),t.notify("draw",{prop:"setDestPoints",onPropertyChange:!1}),this.lowerContext.filter),i=(t.notify("draw",{prop:"drawImage",onPropertyChange:!1}),this.lowerContext.filter=i,t.notify("draw",{prop:"setRotateZoom",onPropertyChange:!1,value:{isRotateZoom:!1}}),t.notify("draw",{prop:"updateCurrTransState",onPropertyChange:!1,value:{type:"reverse",isPreventDestination:null,isRotatePan:null}}),t.objColl=o,t.activeObj=e,{width:this.cropDimension.width,height:this.cropDimension.height});i.width+=i.width*t.transform.zoomFactor,i.height+=i.height*t.transform.zoomFactor,t.notify("draw",{prop:"setZoomCropWidth",value:{width:i.width,height:i.height}})},b.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)},b.prototype.cropZoom=function(e,t){var o=this.parent,i=o.img.destLeft,r=o.img.destTop,n={width:0,height:0};return 0===o.img.srcLeft||0===o.img.srcTop?n=O.isNullOrUndefined(t)?this.setZoomDimension(e,null):this.setZoomDimension(e,t):((n=o.transform.degree%90==0&&o.transform.degree%180!=0?this.calcMaxDimension(o.img.srcHeight,o.img.srcWidth):this.calcMaxDimension(o.img.srcWidth,o.img.srcHeight)).width+=n.width*o.transform.zoomFactor,n.height+=n.height*o.transform.zoomFactor),o.img.destLeft=i-(n.width-o.img.destWidth)/2,o.img.destTop=r-(n.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+n.width<t.activePoint.endX&&(o.img.destLeft=t.activePoint.endX-n.width,0===o.transform.degree)&&(o.panPoint.totalPannedPoint.x-=i-o.img.destLeft),o.img.destTop+n.height<t.activePoint.endY)&&(o.img.destTop=t.activePoint.endY-n.height,0===o.transform.degree)&&(o.panPoint.totalPannedPoint.y-=r-o.img.destTop),n},b.prototype.setZoomDimension=function(e,t){var o,i,r,n,a,s=this.parent,l=s.transform.degree,p={width:0,height:0};return(p=l%90==0&&l%180!=0?this.calcMaxDimension(s.img.srcHeight,s.img.srcWidth):this.calcMaxDimension(s.img.srcWidth,s.img.srcHeight)).width+=p.width*s.transform.zoomFactor,p.height+=p.height*s.transform.zoomFactor,s.img.destLeft+=(s.img.destWidth-p.width)/2,s.img.destTop+=(s.img.destHeight-p.height)/2,e<0&&t?(l=t.activePoint.startX,o=t.activePoint.startY,i=t.activePoint.width,r=t.activePoint.height,n=s.img.destLeft+p.width,a=s.img.destTop+p.height,s.img.destLeft>l&&(s.img.destLeft=l),s.img.destTop>o&&(s.img.destTop=o),n<l+i&&(s.img.destLeft=l+i-p.width),a<o+r&&(s.img.destTop=o+r-p.height)):e<0&&O.isNullOrUndefined(t)&&(0<s.img.destLeft&&(s.img.destLeft=0),0<s.img.destTop&&(s.img.destTop=0),s.img.destLeft+p.width<s.lowerCanvas.clientWidth&&(s.img.destLeft=s.lowerCanvas.clientWidth-s.img.destWidth),s.img.destTop+p.height<s.lowerCanvas.clientHeight)&&(s.img.destTop=s.lowerCanvas.clientHeight-s.img.destHeight),p},b.prototype.drawPannedImage=function(e,t){var o=this.parent,i={panDown:null},i=(o.notify("selection",{prop:"getPanDown",onPropertyChange:!1,value:{obj:i}}),{startPoint:i.panDown,endPoint:this.panMove,cancel:!1});o.trigger("panning",i),i.cancel||this.panEvent(e,t)},b.prototype.panEvent=function(e,t,o){var i,r,n,a,s,l=this.parent,p=!1;l.activeObj.shape&&"shape"===l.activeObj.shape&&l.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),O.isNullOrUndefined(l.activeObj.shape)&&(p=!0,s=(i=l.activeObj.activePoint={startX:l.img.destLeft,startY:l.img.destTop,endX:l.img.destLeft+l.img.destWidth,endY:l.img.destTop+l.img.destHeight}).startX,r=i.startY,n=i.endX,a=i.endY,s<0&&(i.startX=0),r<0&&(i.startY=0),n>l.lowerCanvas.width&&(i.endX=l.lowerCanvas.width),a>l.lowerCanvas.height&&(i.endY=l.lowerCanvas.height),i.width=i.endX-i.startX,i.height=i.endY-i.startY,l.activeObj.shape="crop-custom",l.notify("shape",{prop:"getStrokeSettings",onPropertyChange:!(s={strokeSettings:{}}),value:{obj:s}}),l.activeObj.strokeSettings=s.strokeSettings,l.notify("draw",{prop:"updateActiveObject",onPropertyChange:!1,value:{actPoint:i,obj:l.activeObj,isMouseMove:null,x:null,y:null}}),l.isCropTab=!0),0===l.transform.degree?(r=void 0,r=O.isNullOrUndefined(e)&&O.isNullOrUndefined(t)||o?o?this.updatePanPoints(e,t):this.updatePanPoints():{x:e,y:t},l.panPoint.totalPannedPoint.x+=r.x,l.panPoint.totalPannedPoint.y+=r.y,n=O.extend({},l.activeObj,{},!0),a=this.lowerContext.filter,this.drawPannImage(r,p),this.lowerContext.filter=a,this.tempPanMove=O.extend({},this.panMove,{},!0),l.activeObj=O.extend({},n,{},!0),this.upperContext.clearRect(0,0,l.upperCanvas.width,l.upperCanvas.height),l.activeObj.shape&&l.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate",obj:l.activeObj}})):(s=l.transform.currFlipState,l.isCropTab=!0,O.isNullOrUndefined(e)&&O.isNullOrUndefined(t)||o?l.panPoint.currentPannedPoint=o?this.updatePanPoints(e,t):this.updatePanPoints():l.panPoint.currentPannedPoint={x:e,y:t},l.transform.currFlipState=s,this.rotatePan(null,null,p),l.isCropTab=!1,this.tempPanMove=O.extend({},this.panMove,{},!0)),p&&(l.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),l.isCropTab=!1,this.upperContext.clearRect(0,0,l.upperCanvas.width,l.upperCanvas.height))},b.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},i=(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,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=i,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}})},b.prototype.resetZoom=function(){var e,t,o=this.parent;0!==o.transform.defaultZoomFactor&&(e=o.isUndoRedo,o.notify("filter",{prop:"getCurrentObj",onPropertyChange:!(t={currObj:{}}),value:{object:t}}),this.transCurrObj=t.currObj,this.transCurrObj.objColl=O.extend([],o.objColl,null,!0),this.transCurrObj.pointColl=O.extend({},o.pointColl,null,!0),this.transCurrObj.afterCropActions=O.extend([],o.afterCropActions,[],!0),o.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!(t={selPointColl:null}),value:{obj:t}}),this.transCurrObj.selPointColl=O.extend([],t.selPointColl,[],!0),o.isUndoRedo=o.isCropToolbar=!0,0<(t=o.transform.defaultZoomFactor)?this.zoomAction(-t):this.zoomAction(Math.abs(t)),o.isCropToolbar=!1,o.isUndoRedo=e)},b.prototype.performTransformation=function(e){var t=this.parent,o=t.transform.defaultZoomFactor,i=t.isUndoRedo,r=O.extend({},t.cropObj,{},!0);this.resetZoom(),this.updateTransform(e);for(var n,a=0,s=t.objColl.length;a<s;a++)0<t.objColl[a].flipObjColl.length&&(n={collection:t.objColl[a].flipObjColl},t.notify("shape",{prop:"alignRotateFlipColl",onPropertyChange:!1,value:{collection:n.collection,isRotateFlipCollection:null,obj:n}}),t.objColl[a].flipObjColl=n.collection,0===t.objColl[a].flipObjColl.length)&&(t.objColl[a].shapeFlip="");0!==o&&(t.isUndoRedo=!0,this.zoomAction(o),t.isUndoRedo=i,o="","rotateleft"===e||"rotateright"===e?o="rotate":"horizontalflip"!==e&&"verticalflip"!==e||(o="flip"),t.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:o,previousObj:this.transCurrObj,previousObjColl:this.transCurrObj.objColl,previousPointColl:this.transCurrObj.pointColl,previousSelPointColl:this.transCurrObj.selPointColl,previousCropObj:r,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),this.transCurrObj=null)},b.prototype.updateTransform=function(e){switch(e.toLowerCase()){case"rotateleft":this.rotateImage(-90);break;case"rotateright":this.rotateImage(90);break;case"horizontalflip":this.flipImage(v.Direction.Horizontal);break;case"verticalflip":this.flipImage(v.Direction.Vertical)}},b.prototype.rotatePan=function(e,t,o){var i,r=this.parent,n=(this.isReverseRotate=!0,r.transform.degree),a={selPointColl:null},s=(r.activeObj.activePoint&&r.activeObj.shape&&(i=O.extend({},r.activeObj,{},!0)),O.extend([],r.objColl,[],!0)),l=O.extend([],r.pointColl,[],!0),a=(r.objColl=[],r.pointColl=[],r.freehandCounter=0,r.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:a}}),a.selPointColl),p=(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}}),r.img.destLeft),h=r.img.destTop,d=r.panPoint.totalPannedInternalPoint,d=(r.isCropTab&&(r.img.destLeft+=d.x,r.img.destTop+=d.y),r.notify("crop",{prop:"updateRotatePan",onPropertyChange:!1}),r.isCropTab&&(r.panPoint.totalPannedInternalPoint.x=r.img.destLeft-p,r.panPoint.totalPannedInternalPoint.y=r.img.destTop-h),this.lowerContext.filter),p=(o&&(r.isCropTab=!1),r.notify("draw",{prop:"drawImage",onPropertyChange:!1}),o&&(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}}),r.img.destLeft),h=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-p,r.panPoint.totalPannedClientPoint.y=r.img.destTop-h,r.objColl=s,r.pointColl=l,r.freehandCounter=r.pointColl.length,r.notify("freehand-draw",{prop:"setSelPointColl",onPropertyChange:!1,value:{obj:{selPointColl:a}}}),r.transform.degree=n,this.lowerContext.filter="none",e&&(t?(r.panPoint.totalPannedClientPoint.x=-r.panPoint.totalPannedClientPoint.x,r.panPoint.totalPannedClientPoint.y=-r.panPoint.totalPannedClientPoint.y,r.panPoint.currentPannedPoint=O.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=O.extend({},r.panPoint.totalPannedClientPoint,{},!0)),o&&(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:""}}),o&&(r.isCropTab=!0),this.lowerContext.filter=d,r.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.lowerContext}}),this.upperContext.clearRect(0,0,r.upperCanvas.width,r.upperCanvas.height),r.activeObj=O.extend({},i,{},!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},b.prototype.limitPan=function(){var e=this.parent,t=e.activeObj.activePoint,o=t.startX,i=t.startY,r=t.endX,t=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<t)&&(e.img.destTop=t-n.destHeight)},b.prototype.pan=function(e,t,o){var i=this.parent;!i.disabled&&i.isImageLoaded&&(e?(i.togglePan=!0,i.notify("shape",{prop:"redrawActObj",onPropertyChange:!1,value:{x:null,y:null,isMouseDown:null}}),i.notify("selection",{prop:"setDragCanvas",value:{bool:!0}}),i.lowerCanvas.style.cursor=i.upperCanvas.style.cursor=i.cursor="grab",i.notify("selection",{prop:"setPanDown",onPropertyChange:!1,value:{panDown:null}}),(t||o)&&(t=t||0,o=o||0,O.isNullOrUndefined(this.panMove)&&(this.panMove={x:t,y:o}),O.isNullOrUndefined(this.tempPanMove)&&(this.tempPanMove={x:this.panMove.x,y:this.panMove.y}),this.panEvent(t,o,!0),this.tempPanMove=null)):(i.togglePan=i.currObjType.isCustomCrop=!1,i.notify("selection",{prop:"setDragCanvas",value:{bool:!1}}),i.lowerCanvas.style.cursor=i.upperCanvas.style.cursor=i.cursor="default"))},b.prototype.zoom=function(e,t){var o=this.parent;if(!o.disabled&&o.isImageLoaded){e=this.getCurrentZoomFactor(e);if(O.isNullOrUndefined(t))this.zoomAction(e,t);else for(var i=0<e?"zoomIn":"zoomOut",r=10*Math.abs(e),n=0;n<r;n++)o.notify("draw",{prop:"performPointZoom",onPropertyChange:!1,value:{x:t.x,y:t.y,type:i,isResize:null}})}},b.prototype.getCurrentZoomFactor=function(e){return!(1<=e)||this.prevZoomValue<1?e-this.prevZoomValue:.1*(e-this.prevZoomValue)},b.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},b.prototype.rotate=function(e,t){var o=this.parent;!o.disabled&&o.isImageLoaded&&e%90==0&&this.rotateImage(e),t.isRotate=!1},b.prototype.flip=function(e){var t=this.parent;!t.disabled&&t.isImageLoaded&&this.flipImage(e)},b.prototype.update=function(){var e,t,o=this.parent,i=0,r=!1,n={bool:!1},a=o.isStraightening,s=0,l=o.element.querySelector("#"+o.element.id+"_contextualToolbar"),p=o.element.querySelector(".e-contextual-toolbar-wrapper"),h=o.element.querySelector("#"+o.element.id+"_headWrapper"),d=(o.isImageLoaded&&(e=!1,d=void 0,O.Browser.isDevice&&(o.activeObj.shape&&(d=o.activeObj.shape.split("-")),o.currObjType.isCustomCrop||d&&"crop"===d[0])&&(e=!0),o.notify("toolbar",{prop:"getFrameToolbar",onPropertyChange:!1,value:{obj:{bool:null}}}),!a&&(l&&!l.parentElement.classList.contains("e-hide")||h&&!h.parentElement.classList.contains("e-hide"))&&(p.classList.add("e-hide"),e||o.okBtn(null,!0),o.notify("toolbar",{prop:"refresh-main-toolbar",onPropertyChange:!1}),o.notify("toolbar",{prop:"destroy-qa-toolbar",onPropertyChange:!1})),o.notify("selection",{prop:"getFreehandDrawEditing",onPropertyChange:!1,value:{obj:n}}),n.bool&&o.notify("toolbar",{prop:"destroy-qa-toolbar",onPropertyChange:!1}),void 0!==o.activeObj.shape)&&(r=!0,"block"===o.textArea.style.display||"inline-block"===o.textArea.style.display?(o.notify("shape",{prop:"redrawActObj",onPropertyChange:!1,value:{x:null,y:null,isMouseDown:null}}),o.notify("toolbar",{prop:"destroy-qa-toolbar",onPropertyChange:!1})):(o.notify("shape",{prop:"updImgRatioForActObj",onPropertyChange:!1}),o.objColl.push(o.activeObj)),o.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1})),this.lowerContext.filter),l=o.element.querySelector("#"+o.element.id+"_canvasWrapper"),h=(l&&(l.style.width=o.element.offsetWidth-2+"px"),o.lowerCanvas.width=o.upperCanvas.width=o.element.offsetWidth-2,o.toolbarTemplate?i=o.element.querySelector("#"+o.element.id+"_toolbarArea").clientHeight:o.element.querySelector("#"+o.element.id+"_toolbar")&&0===(i=o.element.querySelector("#"+o.element.id+"_toolbar").clientHeight)&&o.toolbar&&0<o.toolbar.length&&-1===o.toolbar.indexOf("Open")&&(o.notify("toolbar",{prop:"getToolbarHeight",value:{obj:t={toolbarHeight:0}}}),i=t.toolbarHeight),o.element.querySelector("#"+o.element.id+"_contextualToolbarArea"));O.Browser.isDevice&&a&&h&&(s=h.clientHeight),o.notify("toolbar",{prop:"setToolbarHeight",value:{height:i}}),O.Browser.isDevice?l&&(l.style.height=o.element.offsetHeight-(2*i+s)-4+"px"):l&&(l.style.height=o.element.offsetHeight-i-2+"px"),o.lowerCanvas.height=o.upperCanvas.height=parseFloat(l.style.height),this.lowerContext.filter="brightness(1) contrast(100%) hue-rotate(0deg) saturate(100%) opacity(1) blur(0px) sepia(0%) grayscale(0%) invert(0%)",o.notify("filter",{prop:"setAdjustmentValue",onPropertyChange:!1,value:{adjustmentValue:this.lowerContext.filter}}),o.canvasFilter=this.lowerContext.filter,o.initialAdjustmentValue=this.lowerContext.filter,o.clearContext(this.lowerContext),o.clearContext(this.upperContext),o.isImageLoaded&&(o.notify("shape",{prop:"applyActObj",onPropertyChange:!1,value:{isMouseDown:null}}),o.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),this.lowerContext.filter=d,o.initialAdjustmentValue=d,o.canvasFilter=this.lowerContext.filter,o.isImageLoaded&&(u.showSpinner(o.element),o.element.style.opacity="0.5"),this.lowerContext.clearRect(0,0,o.lowerCanvas.width,o.lowerCanvas.height),this.upperContext.clearRect(0,0,o.upperCanvas.width,o.upperCanvas.height),l&&(l.style.width=o.element.offsetWidth-2+"px",l.style.height=o.element.offsetHeight+"px",o.notify("toolbar",{prop:"getToolbarHeight",value:{obj:e={toolbarHeight:0}}}),O.Browser.isDevice?l.style.height=parseFloat(l.style.height)-2*e.toolbarHeight-s-4+"px":l.style.height=parseFloat(l.style.height)-e.toolbarHeight-2+"px"),o.lowerCanvas.width=o.upperCanvas.width=parseFloat(l.style.width),o.lowerCanvas.height=o.upperCanvas.height=parseFloat(l.style.height),this.lowerContext.filter=d,this.calcMaxDimension(o.img.srcWidth,o.img.srcHeight,t={width:0,height:0}),h=t,a&&0!==o.transform.cropZoomFactor?(h.width+=h.width*o.transform.cropZoomFactor,h.height+=h.height*o.transform.cropZoomFactor):0<o.transform.defaultZoomFactor&&(h.width+=h.width*o.transform.defaultZoomFactor,h.height+=h.height*o.transform.defaultZoomFactor),o.img.destLeft=(o.lowerCanvas.clientWidth-h.width)/2,o.img.destTop=(o.lowerCanvas.clientHeight-h.height+1)/2,0===o.transform.degree&&""===o.transform.currFlipState?(0<o.transform.defaultZoomFactor&&(o.img.destLeft+=o.panPoint.totalPannedPoint.x,o.img.destTop+=o.panPoint.totalPannedPoint.y),o.notify("draw",{prop:"draw-image-to-canvas",value:{dimension:h}})):(o.notify("draw",{prop:"draw-image-to-canvas",value:{dimension:h}}),o.notify("draw",{prop:"updateCurrTransState",onPropertyChange:!1,value:{type:"initial",isPreventDestination:null,isRotatePan:null}}),i=this.lowerContext.filter,o.notify("draw",{prop:"drawImage",onPropertyChange:!1}),this.lowerContext.filter=i,o.notify("draw",{prop:"updateCurrTransState",onPropertyChange:!1,value:{type:"reverse",isPreventDestination:null,isRotatePan:null}})),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.isCircleCrop&&o.notify("crop",{prop:"cropCircle",onPropertyChange:!1,value:{context:this.lowerContext,isSave:null,isFlip:null}}),u.hideSpinner(o.element),o.element.style.opacity="1",o.notify("toolbar",{prop:"getDefToolbarItems",value:{obj:s={defToolbarItems:null}}}),s.defToolbarItems&&0<s.defToolbarItems.length&&document.getElementById(o.element.id+"_toolbar")&&(O.getComponent(o.element.id+"_toolbar","toolbar").refreshOverflow(),p)&&!a&&p.classList.add("e-hide"),o.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),this.upperContext.clearRect(0,0,o.upperCanvas.width,o.upperCanvas.height),r&&(e=O.extend({},o.objColl[o.objColl.length-1],null,!0),o.objColl.pop(),0!==e.activePoint.width)&&0!==e.activePoint.height&&(this.lowerContext.clearRect(0,0,o.lowerCanvas.width,o.lowerCanvas.height),o.notify("draw",{prop:"render-image",value:{isMouseWheel:null}}),o.objColl.push(e),o.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"zoom",pen:"zoom",isPreventApply:null}}),e=O.extend({},o.objColl[o.objColl.length-1],null,!0),o.objColl.pop(),this.lowerContext.clearRect(0,0,o.lowerCanvas.width,o.lowerCanvas.height),o.notify("draw",{prop:"render-image",value:{isMouseWheel:null}}),o.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate",obj:e}}),a&&o.notify("draw",{prop:"setStraightenActObj",value:{activeObj:e}}),"rectangle"!==o.activeObj.shape&&"ellipse"!==o.activeObj.shape&&"text"!==o.activeObj.shape&&"line"!==o.activeObj.shape&&"arrow"!==o.activeObj.shape&&"path"!==o.activeObj.shape&&"image"!==o.activeObj.shape||o.notify("toolbar",{prop:"renderQAT",onPropertyChange:!1,value:{isPenEdit:null}})),n.bool&&o.notify("toolbar",{prop:"renderQAT",onPropertyChange:!1,value:{isPenEdit:!0}}),o.isResize&&(o.aspectWidth=Math.ceil(o.img.destWidth),o.aspectHeight=Math.ceil(o.img.destHeight),o.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"resize",isApplyBtn:!1,isCropping:!1}}),o.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"resize",isApplyBtn:!1,isCropping:!1}})),(0!==o.transform.degree||""!==o.transform.currFlipState)&&0<o.transform.defaultZoomFactor?(l=O.extend({},o.panPoint.totalPannedPoint,null,!0),d=O.extend({},o.panPoint.totalPannedInternalPoint,null,!0),t=O.extend({},o.panPoint.totalPannedClientPoint,null,!0),this.zoomAction(.1),this.zoomAction(-.1),0===o.transform.degree?(o.img.destLeft+=l.x,o.img.destTop+=l.y,o.panPoint.totalPannedPoint=l,o.notify("draw",{prop:"updateFlipPan",value:{tempSelectionObj:null}})):(o.panPoint.totalPannedInternalPoint=d,o.panPoint.totalPannedClientPoint=t,o.panPoint.currentPannedPoint={x:0,y:0},o.isCropTab=!0,this.rotatePan(),o.isCropTab=!1)):0!==o.transform.degree&&0<o.transform.cropZoomFactor&&(o.transform.zoomFactor=0,o.transform.cropZoomFactor=null,o.notify("toolbar",{prop:"enable-disable-btns",onPropertyChange:!1})))},b.prototype.calcMaxDimension=function(e,t,o,i){var r={toolbarHeight:0},n=this.parent,a=(n.notify("toolbar",{prop:"getToolbarHeight",value:{obj:r}}),i?n.element.clientWidth/3:n.element.clientWidth),s=i?(n.element.clientHeight-r.toolbarHeight)/3:n.element.clientHeight-r.toolbarHeight,s=O.Browser.isDevice?s-r.toolbarHeight:s,r=(O.Browser.isDevice&&n.isStraightening&&(s-=(r=n.element.querySelector("#"+n.element.id+"_contextualToolbarArea"))?r.clientHeight:0),i||0!==n.element.clientHeight||(s=0),O.isNullOrUndefined(i)&&(30<a&&(a-=30),30<s)&&(s-=30),a/e),l=s/t,a=Math.min(e,a),s=Math.min(t,s);return r<1&&r<l?(a=e*r,s=t*r):l<1&&l<r&&(a=e*l,s=t*l),O.isNullOrUndefined(i)&&(n.notify("crop",{prop:"getPreventScaling",onPropertyChange:!(r={bool:null}),value:{obj:r}}),r.bool)&&n.cropObj.activeObj.activePoint&&0!==n.cropObj.activeObj.activePoint.width&&0!==n.cropObj.activeObj.activePoint.height&&(a=n.cropObj.activeObj.activePoint.width,s=n.cropObj.activeObj.activePoint.height),o&&(o.width=a,o.height=s),{width:a,height:s}},b.prototype.updatePanPoints=function(e,t){for(var o=this.parent,i=O.extend({},o.activeObj,{},!0),r=o.img.destLeft,n=o.img.destTop,a=(O.isNullOrUndefined(this.tempPanMove)&&(this.tempPanMove={x:this.panMove.x,y:this.panMove.y}),this.panMove.x-this.tempPanMove.x),s=this.panMove.y-this.tempPanMove.y,l=((e||t)&&(a=e,s=t),o.img.destLeft+=a,o.img.destTop+=s,this.limitPan(),{bool:null}),p={isIntersect:null},h=(o.notify("draw",{prop:"updateImgCanvasPoints",onPropertyChange:!1}),o.notify("draw",{prop:"isLinesIntersect",onPropertyChange:!1,value:{obj:p}}),o.notify("draw",{prop:"isSelOutsideImg",onPropertyChange:!1,value:{obj:l}}),0);0!==o.transform.straighten&&(p.isIntersect||l.bool)&&(h++,o.img.destLeft=r,o.img.destTop=n,0!==a&&0<a?--a:0!==a&&a<0&&(a+=1),0!==s&&0<s?--s:0!==s&&s<0&&(s+=1),0!==a||0!==s)&&200!==h;)o.img.destLeft+=a,o.img.destTop+=s,this.limitPan(),o.notify("draw",{prop:"updateImgCanvasPoints",onPropertyChange:!1}),o.notify("draw",{prop:"isLinesIntersect",onPropertyChange:!1,value:{obj:p}}),o.notify("draw",{prop:"isSelOutsideImg",onPropertyChange:!1,value:{obj:l}});return o.activeObj=i,{x:o.img.destLeft-r,y:o.img.destTop-n}},b.prototype.resizeImage=function(e,t){var o=this.parent,i=!0,r=!0,n=(o.allowDownScale=!1,o.img.srcLeft=0,o.img.srcTop=0,o.isAspectRatio=!0,[]);for(o.img.srcWidth=o.baseImgCanvas.width,o.img.srcHeight=o.baseImgCanvas.height,o.resizeSrc&&0!==o.resizeSrc.width&&0!==o.resizeSrc.height&&(o.img.srcLeft=o.resizeSrc.startX,o.img.srcTop=o.resizeSrc.startY,o.img.srcWidth=o.resizeSrc.width,o.img.srcHeight=o.resizeSrc.height);(e<o.img.destWidth||t<o.img.destHeight)&&r;)if(this.zoomAction(-.1,null,!0,!0),e>o.img.destWidth||t>o.img.destHeight)for(;e>o.img.destWidth||t>o.img.destHeight;)this.zoomAction(.0125,null,!0,!0),r=!1,n.push(o.img.destWidth);for(;(e>o.img.destWidth||t>o.img.destHeight)&&r&&i;)if(this.zoomAction(.1,null,!0,!0),e<o.img.destWidth||t<o.img.destHeight)for(;e<o.img.destWidth;)this.zoomAction(-.0125,null,!0,!0),i=!1,n.push(o.img.destWidth);for(var a=n[0],s=Math.abs(o.img.destWidth-a),l=0,p=n;l<p.length;l++){var h=p[l],d=Math.abs(e-h);d<s&&(a=h,s=d)}a<e&&i&&(this.zoomAction(-.0125,null,!0,!0),i=!1),e<a&&!i&&(this.zoomAction(.0125,null,!0,!0),i=!1),this.zoomAction(.0125,null,!0),o.allowDownScale=!0,this.zoomAction(-.0125,null,!0);var c=O.extend({},o.cropObj,{},!0),u=O.extend({},this.prevResizeCurrObj,{},!0);o.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"resize",previousObj:u,previousObjColl:u.objColl,previousPointColl:u.pointColl,previousSelPointColl:u.selPointColl,previousCropObj:c,previousText:null,currentText:null,previousFilter:null,isCircleCrop:o.isCircleCrop}}),o.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"ok"}})},b.prototype.resizeCrop=function(e,t){var o=this.parent,i=!0,r={prevObj:o.prevObj},n=(o.cropObj=O.extend({},o.prevCropObj,{},!0),o.allowDownScale=!1,o.notify("toolbar",{prop:"getPrevObj",onPropertyChange:!1,value:{obj:r}}),O.extend({},r.prevObj.activeObj,{},!0)),a=(r.prevObj.activeObj=O.extend({},o.activeObj,{},!0),o.notify("draw",{prop:"setCurrentObj",onPropertyChange:!1,value:{obj:r.prevObj}}),o.objColl=O.extend([],r.prevObj.objColl,[],!0),o.pointColl=O.extend([],r.prevObj.pointColl,[],!0),o.transform.straighten=0,o.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"zoom",pen:"zoom",isPreventApply:null}}),0!==o.transform.straighten||this.isPreventSelect||o.notify("freehand-draw",{prop:"updateFHDColl",onPropertyChange:!1}),e),s=t,l=!1;if(e<=t&&t<=Math.ceil(o.img.destHeight)){for(;t<=Math.ceil(o.img.destHeight)&&i;)if(this.zoomAction(-.1,null,!0,!0),e>o.img.destWidth||t>o.img.destHeight)for(;e>o.img.destWidth||t>o.img.destHeight;)this.zoomAction(.0125,null,!0,!0),i=!1}else if(t<=e&&e<o.img.destWidth){for(;e<o.img.destWidth&&i;)if(this.zoomAction(-.1,null,!0,!0),e>o.img.destWidth||t>o.img.destHeight)for(;e>o.img.destWidth||t>o.img.destHeight;)this.zoomAction(.0125,null,!0,!0),i=!1}else if(e<=t&&t>=o.img.destHeight)for(;t>=o.img.destHeight&&i;)this.zoomAction(.1,null,!0,!0);else if(t<=e&&e>=o.img.destWidth){for(;e>=o.img.destWidth&&i;)this.zoomAction(.1,null,!0,!0);if(e<o.img.destWidth&&t<o.img.destHeight){for(;e<o.img.destWidth&&t<o.img.destHeight;)this.zoomAction(-.0125,null,!0,!0),i=!1;this.zoomAction(.0125,null,!0,!0)}}else if(t>o.img.destHeight&&e>o.img.destWidth){for(;t>o.img.destHeight&&e>o.img.destWidth&&i;)this.zoomAction(.1,null,!0,!0);if(e<o.img.destWidth&&t<o.img.destHeight){for(;e<o.img.destWidth&&t<o.img.destHeight;)this.zoomAction(-.0125,null,!0,!0),i=!1;this.zoomAction(.0125,null,!0,!0)}}if(this.resizeImg(n,e,t),e=a,(t=s)!==o.img.destHeight||e!==o.img.destWidth){for(;t>o.img.destHeight||e>o.img.destWidth;)this.zoomAction(.0125,null,!0,!0),l=!0;l&&(this.zoomAction(-.0125,null,!0,!0),l=!1)}if(t!==o.img.destHeight||e!==o.img.destWidth){for(;t<o.img.destHeight||e<o.img.destWidth;)this.zoomAction(-.0125,null,!0,!0),l=!0;l&&(this.zoomAction(-.0125,null,!0,!0),l=!1)}r.prevObj.activeObj=O.extend({},n,{},!0),this.zoomAction(.0125,null,!0),o.allowDownScale=!this.preventDownScale,o.isCropTab=!1,this.zoomAction(-.0125,null,!0),o.aspectWidth=e,o.aspectHeight=t},b.prototype.resizeImg=function(e,t,o){for(var i=this.parent,r=t/i.img.destWidth,n=o/i.img.destHeight,a=(e.shape?(i.currSelectionPoint=e,i.notify("crop",{prop:"setInitCrop",onPropertyChange:!1,value:{bool:!0}})):i.img.srcWidth===i.baseImgCanvas.width&&i.img.srcHeight===i.baseImgCanvas.height&&(i.currSelectionPoint=null,i.notify("draw",{prop:"select",onPropertyChange:!1,value:{type:"custom",startX:null,startY:null,width:null,height:null}})),O.isNullOrUndefined(i.currSelectionPoint)?i.notify("draw",{prop:"select",onPropertyChange:!1,value:{type:"custom",startX:i.img.destLeft,startY:i.img.destTop,width:i.img.destWidth,height:i.img.destHeight}}):i.notify("draw",{prop:"select",onPropertyChange:!1,value:{type:"custom",startX:null,startY:null,width:null,height:null}}),t=i.activeObj.activePoint.width*r,o=i.activeObj.activePoint.height*n,i.activeObj.activePoint.startX+i.activeObj.activePoint.width/2-t/2),s=i.activeObj.activePoint.startY+i.activeObj.activePoint.height/2-o/2,l=0;O.Browser.isDevice&&l<500&&(a<0||s<0||a+t>i.img.destWidth||s+o>i.img.destHeight);)l++,a=i.activeObj.activePoint.startX+i.activeObj.activePoint.width/2- --t/2,s=i.activeObj.activePoint.startY+i.activeObj.activePoint.height/2- --o/2;if(i.transform.defaultZoomFactor=0,i.notify("draw",{prop:"setResizeSelect",value:{bool:!0}}),i.notify("draw",{prop:"setIsCropSelect",value:{bool:!0}}),i.notify("draw",{prop:"select",onPropertyChange:!1,value:{type:"custom",startX:a,startY:s,width:t,height:o}}),i.notify("draw",{prop:"setResizeSelect",value:{bool:!1}}),0!==i.transform.straighten){var p={isIntersect:null,arr:null};for(i.notify("draw",{prop:"updateImgCanvasPoints",onPropertyChange:!1}),i.notify("draw",{prop:"isLinesIntersect",onPropertyChange:!1,value:{obj:p}});p.arr[0]||p.arr[1]||p.arr[2]||p.arr[3];)this.zoomAction(.0125,null,!0),i.notify("draw",{prop:"updateImgCanvasPoints",onPropertyChange:!1}),i.notify("draw",{prop:"isLinesIntersect",onPropertyChange:!1,value:{obj:p}})}i.isCropToolbar=!0,i.crop(),i.isCropToolbar=!1},b.prototype.updateResize=function(){var e=this.parent,t=(e.prevCropObj=O.extend({},e.cropObj,{},!0),{currObj:{}}),t=(e.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:t}}),e.prevObj=t.currObj,e.currSelectionPoint&&e.prevCropObj.activeObj.shape&&(e.prevObj.activeObj=O.extend({},e.prevCropObj.activeObj,{},!0)),e.prevObj.objColl=O.extend([],e.objColl,[],!0),e.prevObj.pointColl=O.extend([],e.pointColl,[],!0),e.prevObj.afterCropActions=O.extend([],e.afterCropActions,[],!0),{selPointColl:null});e.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:t}}),e.prevObj.selPointColl=O.extend([],t.selPointColl,[],!0),e.resizeSrc={startX:e.img.srcLeft,startY:e.img.srcTop,width:e.img.srcWidth,height:e.img.srcHeight}},b.prototype.resize=function(e,t,o){var i=this.parent,r=(i.isResize=!0,O.isNullOrUndefined(i.prevCropObj)&&O.isNullOrUndefined(i.prevObj)&&i.notify("transform",{prop:"updateResize",value:{bool:!1}}),i.element.querySelector("#"+i.element.id+"_aspectratio")),n=i.element.querySelector("#"+i.element.id+"_nonaspectratio"),r=(r&&n&&(i.notify("toolbar",{prop:"initResizeToolbar"}),O.Browser.isDevice)&&i.notify("toolbar",{prop:"init-main-toolbar",value:{isApplyBtn:!1,isDevice:!0,isOkBtn:!0,isResize:!0}}),i.element.querySelector("#"+i.element.id+"_resizeHeight")),n=""===r.value?r.placeholder:r.value,r={cancel:!1,previousWidth:Math.ceil(i.img.destWidth),previousHeight:Math.ceil(i.img.destHeight),width:Math.ceil(e),height:t&&0!==t?Math.ceil(t):o?Math.ceil(parseFloat(n)):Math.ceil(i.img.destHeight),isAspectRatio:o||!1};i.trigger("resizing",r),r.cancel?i.aspectHeight&&i.aspectWidth&&(i.aspectHeight=r.previousHeight,i.aspectWidth=r.previousWidth):this.resizeEventHandler(r)},b.prototype.resizeEventHandler=function(e){var t,o,i,r,n,a,s,l=this.parent,p=l.element.querySelector("#"+l.element.id+"_resizeWidth"),h=l.element.querySelector("#"+l.element.id+"_resizeHeight"),d=l.element.querySelector(".e-ie-toolbar-e-resize-height-input .e-textbox"),c=l.element.querySelector(".e-ie-toolbar-e-resize-width-input .e-textbox");e.isAspectRatio?(null!=this.resizedImgAngle&&this.resizedImgAngle===l.transform.degree||(this.resizedImgAngle=l.transform.degree,t=!0),t?(l.notify("transform",{prop:"resizeImage",value:{width:e.width,height:0}}),o=l.img.destWidth,i=l.img.destHeight,s=void 0,s=parseFloat(""===p.value?p.placeholder:p.value),h?(n=.5<=(r=s/(o/i))%1||r%1<=-.5?Math.round(r):r<0?Math.ceil(r):Math.floor(r),O.getComponent(h,"numerictextbox").value=n,h.value=n.toString()+" px",l.aspectHeight=n,p&&""===p.value&&(a=.5<=(r=parseFloat(""===h.value?h.placeholder:h.value)/(i/o))%1||r%1<=-.5?Math.round(r):r<0?Math.ceil(r):Math.floor(r),O.getComponent(p,"numerictextbox").value=a,p.value=a.toString()+" px",l.aspectWidth=a)):d&&(n=.5<=(r=s/(o/i))%1||r%1<=-.5?Math.round(r):r<0?Math.ceil(r):Math.floor(r),d.value=n.toString(),l.aspectHeight=n,c)&&""===c.value&&(a=.5<=(r=parseFloat(""===d.value?d.placeholder:d.value)/(i/o))%1||r%1<=-.5?Math.round(r):r<0?Math.ceil(r):Math.floor(r),c.value=a.toString(),l.aspectWidth=a)):l.notify("transform",{prop:"resizeImage",value:{width:e.width,height:null}})):(null!==this.resizedImgAngle&&this.resizedImgAngle!==l.transform.degree&&(this.resizedImgAngle=l.transform.degree,t=!0),t?(l.notify("transform",{prop:"setPreventDownScale",value:{bool:!0}}),l.notify("transform",{prop:"resizeCrop",value:{width:e.width,height:e.height}}),l.notify("undo-redo",{prop:"setPreventUR",value:{bool:!0}}),l.okBtn(null,!0),l.notify("undo-redo",{prop:"setPreventUR",value:{bool:!1}}),l.resizeSrc={startX:l.img.srcLeft,startY:l.img.srcTop,width:l.img.srcWidth,height:l.img.srcHeight},l.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"resize",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}}),l.notify("transform",{prop:"setPreventDownScale",value:{bool:!1}}),l.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"resize",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}})):l.notify("transform",{prop:"resizeCrop",value:{width:e.width,height:e.height}})),this.resizedImgAngle=l.transform.degree},b.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()};var B=b;function b(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()}m.prototype.destroy=function(){this.parent.isDestroyed||this.removeEventListener()},m.prototype.addEventListener=function(){this.parent.on("undo-redo",this.undoRedo,this),this.parent.on("destroyed",this.destroy,this)},m.prototype.removeEventListener=function(){this.parent.off("undo-redo",this.undoRedo),this.parent.off("destroyed",this.destroy)},m.prototype.initializeUrPvtProp=function(){this.parent.lowerCanvas&&(this.lowerContext=this.parent.lowerCanvas.getContext("2d")),this.parent.upperCanvas&&(this.upperContext=this.parent.upperCanvas.getContext("2d"))},m.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()}},m.prototype.getModuleName=function(){return"undo-redo"},m.prototype.reset=function(){this.tempCurrSelPoint=null,this.undoRedoStep=0,this.undoRedoColl=[],this.appliedUndoRedoColl=[],this.tempActObj=null,this.tempUndoRedoColl=[],this.tempUndoRedoStep=0,this.isPreventing=!1},m.prototype.refreshUrc=function(e){var t=this.parent;(e=e||!1)&&(t.notify("toolbar",{prop:"setEnableDisableUndoRedo",value:{isPrevent:!0}}),this.tempUndoRedoColl=O.extend([],this.appliedUndoRedoColl,[],!0),this.tempUndoRedoStep=this.undoRedoStep),t.notify("toolbar",{prop:"setEnableDisableUndoRedo",value:{isPrevent:!1}}),this.undoRedoColl=this.undoRedoColl.slice(0,this.undoRedoStep),this.appliedUndoRedoColl=this.appliedUndoRedoColl.slice(0,this.undoRedoStep),t.isUndoRedo=t.currObjType.isUndoAction=!1,t.notify("toolbar",{prop:"enable-disable-btns"})},m.prototype.updateCurrUrc=function(e,t){var o,i,r,n,a=this.parent;a.isResize||this.isPreventing||a.noPushUndo||(a.notify("toolbar",{prop:"setEnableDisableUndoRedo",value:{isPrevent:!1}}),"ok"===e?(a.notify("draw",{prop:"setShapeTextInsert",onPropertyChange:!1,value:{bool:!1}}),n=0<this.tempUndoRedoColl.length?O.extend([],this.tempUndoRedoColl,[],!0):O.extend([],this.undoRedoColl,[],!0),o=this.undoRedoColl[this.undoRedoColl.length-1],i=this.appliedUndoRedoColl[this.appliedUndoRedoColl.length-1],r=o?O.extend({},o.previousObj,{},!0):null,O.isNullOrUndefined(i)?this.undoRedoColl[0]&&(o.previousCropObj=n[0].previousCropObj,o.previousObj=n[0].previousObj,o.previousObjColl=n[0].previousObjColl,o.previousPointColl=n[0].previousPointColl,o.previousText=n[0].previousText):"imageHFlip"!==o.operation&&"imageVFlip"!==o.operation&&(o.previousCropObj=i.currentCropObj,o.previousObj=i.currentObj,o.previousObjColl=i.currentObjColl,o.previousPointColl=i.currentPointColl,o.previousText=i.currentText,"frame"===o.operation)&&o.previousObj&&r&&(o.previousObj.defaultZoom=r.defaultZoom,o.previousObj.zoomFactor=r.zoomFactor,o.previousObj.cropZoom=r.cropZoom),o&&("imageHFlip"!==o.operation&&"imageVFlip"!==o.operation&&(n=this.getZeroZoomObjPointValue(o.currentObjColl,o.currentPointColl),o.currentObjColl=n.obj,o.currentPointColl=n.point,a.notify("filter",{prop:"getAdjustmentLevel",onPropertyChange:!(i={adjustmentLevel:null}),value:{obj:i}}),o.currentObj.adjustmentLevel=O.extend({},i.adjustmentLevel,{},!0),a.notify("filter",{prop:"setTempAdjVal"}),o.currentObj.currentFilter=a.currentFilter),this.appliedUndoRedoColl.push(o)),this.tempUndoRedoColl=[],this.tempUndoRedoStep=0):0<this.tempUndoRedoColl.length&&(this.appliedUndoRedoColl=O.extend([],this.tempUndoRedoColl,[],!0),this.undoRedoStep=this.tempUndoRedoStep,this.tempUndoRedoColl=[],this.tempUndoRedoStep=0),r=this.appliedUndoRedoColl[this.appliedUndoRedoColl.length-1],n=this.appliedUndoRedoColl[this.appliedUndoRedoColl.length-2],16<this.appliedUndoRedoColl.length?this.appliedUndoRedoColl.splice(0,1):!t&&r&&n&&(("shapeTransform"===r.operation&&"shapeTransform"===n.operation||"shapeInsert"===r.operation&&"shapeInsert"===n.operation)&&JSON.stringify(r.currentObjColl)===JSON.stringify(n.currentObjColl)||"freehand-draw"===r.operation&&"freehand-draw"===n.operation&&JSON.stringify(r.currentPointColl)===JSON.stringify(n.currentPointColl)||"freehanddrawCustomized"===r.operation&&"freehanddrawCustomized"===n.operation&&JSON.stringify(r.currentPointColl)===JSON.stringify(n.currentPointColl))&&this.appliedUndoRedoColl.splice(this.appliedUndoRedoColl.length-1,1),this.undoRedoColl=[],this.undoRedoColl=O.extend([],this.appliedUndoRedoColl,[],!0),"ok"===e&&(this.undoRedoStep=this.undoRedoColl.length,a.notify("toolbar",{prop:"enable-disable-btns"})),0<a.transform.zoomFactor&&(a.togglePan=!0,a.notify("selection",{prop:"setDragCanvas",value:{bool:!0}})))},m.prototype.cancelCropSelection=function(){var e,t=this.parent,o=!1;t.activeObj.shape&&(e=t.activeObj.shape.split("-")),(o=t.currObjType.isCustomCrop||e&&"crop"===e[0]?!0:o)&&t.notify("draw",{prop:"performCancel",value:{isContextualToolbar:null}}),0===this.tempUndoRedoColl.length&&0===this.tempUndoRedoStep||(this.appliedUndoRedoColl=O.extend([],this.tempUndoRedoColl,[],!0),this.undoRedoColl=O.extend([],this.tempUndoRedoColl,[],!0),this.undoRedoStep=this.tempUndoRedoStep,this.tempUndoRedoColl=[],this.tempUndoRedoStep=0,t.notify("toolbar",{prop:"setEnableDisableUndoRedo",value:{isPrevent:!1}}))},m.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})},m.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)),0<this.appliedUndoRedoColl.length&&(this.undoRedoColl=O.extend([],this.appliedUndoRedoColl,[],!0))},m.prototype.callUndo=function(){this.applyCurrentChanges(),this.undo()},m.prototype.callRedo=function(){this.applyCurrentChanges(),this.redo()},m.prototype.undo=function(){var e=this.parent;if(this.cancelCropSelection(),e.notify("draw",{prop:"resetFrameZoom",onPropertyChange:!1,value:{isOk:!1}}),!e.disabled&&e.isImageLoaded&&0<this.undoRedoStep){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 t=this.undoRedoColl[this.undoRedoStep];this.undoRedoColl.length===this.undoRedoStep?e.currObjType.isUndoAction=!1:e.currObjType.isUndoAction=!0,"textAreaCustomization"===t.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=O.extend({},t.previousCropObj,{},!0),e.afterCropActions=t.previousObj.afterCropActions,this.lowerContext.filter=t.previousObj.filter,e.notify("filter",{prop:"setAdjustmentLevel",onPropertyChange:!1,value:{adjustmentLevel:t.previousObj.adjustmentLevel}}),e.notify("filter",{prop:"setTempAdjVal"}),e.currentFilter=t.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}}),t.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(t.previousObjColl,t.previousPointColl);break;case"freehanddraw":case"freehand-draw":this.updateFreehandDraw(t.previousPointColl,t.previousSelPointColl);break;case"freehanddrawCustomized":this.updateFreehandDrawCustomized(t.previousObjColl,t.previousPointColl);break;case"deleteFreehandDrawing":case"deleteObj":this.updateDelete(t.operation,t.previousObjColl,t.previousPointColl,t.previousSelPointColl);break;case"textAreaCustomization":this.shapeTransform(t.previousObjColl,t.previousPointColl),this.updateTextAreaCustomization(void 0,t.previousObjColl);break;case"text":this.updateText(t.previousObjColl,!0);break;case"frame":e.transform.zoomFactor=e.transform.defaultZoomFactor=t.previousObj.defaultZoom,e.setProperties({zoomSettings:{zoomFactor:t.previousObj.zoomFactor}},!0),e.notify("transform",{prop:"setPreviousZoomValue",onPropertyChange:!1,value:{previousZoomValue:e.zoomSettings.zoomFactor}}),O.extend(e.frameObj,t.previousObj.frameObj),e.notify("draw",{prop:"render-image",value:{isMouseWheel:!0,isPreventClearRect:null,isFrame:!0}});break;case"imageHFlip":this.imageFlip("horizontal",t.previousObjColl);break;case"imageVFlip":this.imageFlip("vertical",t.previousObjColl);break;default:this.undoDefault(t,!0),e.notify("filter",{prop:"set-adjustment",value:{operation:t.operation}}),e.notify("filter",{prop:"update-filter",value:{operation:t.operation,filter:t.filter}})}"crop"===t.operation?(t.previousObj.currSelectionPoint&&(e.currSelectionPoint=O.extend({},t.previousObj.currSelectionPoint,{},!0),e.currSelectionPoint)&&O.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=O.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"===t.operation&&e.cropObj&&e.cropObj.activeObj&&(e.currSelectionPoint=O.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(t.operation,!0)}},m.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 t,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=O.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}});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);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(void 0,o.currentObjColl);break;case"text":this.updateText(o.currentObjColl,!1);break;case"frame":O.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,t=O.extend({},e.activeObj,{},!0),e.objColl=O.extend([],o.currentObjColl,[],!0),e.pointColl=O.extend([],o.currentPointColl,[],!0),e.freehandCounter=e.pointColl.length,e.notify("freehand-draw",{prop:"setSelPointColl",onPropertyChange:!1,value:{obj:{selPointColl:O.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=t,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=O.extend({},this.tempCurrSelPoint,{},!0),this.tempCurrSelPoint=null),"crop"!==o.operation||o.isCircleCrop||(e.isCircleCrop=!1),"crop"===o.operation&&o.currentObj.currSelectionPoint&&(e.currSelectionPoint=O.extend({},o.currentObj.currSelectionPoint,{},!0),e.notify("draw",{prop:"setStraightenActObj",value:{activeObj:e.currSelectionPoint}})),e.currSelectionPoint&&O.isNullOrUndefined(e.currSelectionPoint.shape)&&(e.currSelectionPoint=null),"resize"===o.operation&&e.cropObj&&e.cropObj.activeObj&&(e.currSelectionPoint=O.extend({},e.cropObj.activeObj,{},!0)),this.endUndoRedo(o.operation,!1)}},m.prototype.imageFlip=function(e,t){var o=this.parent,t=(this.shapeTransform(t,null),o.activeObj=O.extend({},o.objColl[o.objColl.length-1],{},!0),o.activeObj),i=t.shape,r=t.isHorImageFlip,t=t.isVerImageFlip;o.objColl.pop(),i&&"image"===i?("horizontal"===e?(O.isNullOrUndefined(r)&&t?(o.activeObj.isHorImageFlip=!0,o.activeObj.isVerImageFlip=null):O.isNullOrUndefined(r)||!r?o.activeObj.isHorImageFlip=!0:o.activeObj.isHorImageFlip=null,o.horizontalFlip(this.upperContext,!0)):"vertical"===e&&(O.isNullOrUndefined(t)&&r?(o.activeObj.isVerImageFlip=!0,o.activeObj.isHorImageFlip=null):O.isNullOrUndefined(t)||!t?o.activeObj.isVerImageFlip=!0:o.activeObj.isVerImageFlip=null,o.verticalFlip(this.upperContext,!0)),o.notify("shape",{prop:"applyActObj",onPropertyChange:!1,value:{isMouseDown:!0}})):o.notify("draw",{prop:"render-image",value:{isMouseWheel:!0}})},m.prototype.shapeTransform=function(e,t){var o=this.parent;o.objColl=O.extend([],e,[],!0),t&&(o.pointColl=O.extend([],t,[],!0),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}),o.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1})},m.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})},m.prototype.updateFreehandDrawCustomized=function(e,t){var o=this.parent;o.objColl=O.extend([],e,[],!0),o.pointColl=t,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})},m.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})},m.prototype.updateTextAreaCustomization=function(e,t){var o=this.parent;o.objColl=O.extend([],t,[],!0),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),o.isUndoRedo=!0,o.notify("draw",{prop:"redrawImgWithObj",onPropertyChange:!1});for(var i=0,r=t.length;i<r;i++){if(!this.tempActObj){e=O.extend({},t[t.length-1],{},!0),o.objColl.splice(i,1);break}if(this.tempActObj.currIndex===t[i].currIndex){e=O.extend({},t[i],{},!0),o.objColl.splice(i,1);break}}e&&this.updateTextBox(e),"block"!==o.textArea.style.display&&"inline-block"!==o.textArea.style.display||o.notify("shape",{prop:"redrawActObj",onPropertyChange:!1,value:{x:null,y:null,isMouseDown:null}})},m.prototype.updateText=function(e,t){var o=this.parent;if(this.tempActObj&&(o.activeObj=O.extend({},this.tempActObj,{},!0)),0===e.length&&1===o.objColl.length)this.tempActObj=O.extend({},o.objColl[0],{},!0);else for(var i=0,r=o.objColl.length;i<r;i++){if(o.objColl[i]&&O.isNullOrUndefined(e[i])){this.tempActObj=O.extend({},o.objColl[i],{},!0);break}if(e[i].currIndex!==o.objColl[i].currIndex){this.tempActObj=O.extend({},o.objColl[i],{},!0);break}}t&&(o.activeObj=O.extend({},this.tempActObj,{},!0)),o.objColl=O.extend([],e,[],!0),o.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"zoom",pen:"zoom",isPreventApply:!0}}),this.upperContext.clearRect(0,0,o.upperCanvas.width,o.upperCanvas.height),this.lowerContext.clearRect(0,0,o.lowerCanvas.width,o.lowerCanvas.height),o.isUndoRedo=!0,o.notify("draw",{prop:"redrawImgWithObj",onPropertyChange:!1}),o.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1})},m.prototype.updateTextBox=function(e){var t=this.parent,o=(this.upperContext.clearRect(0,0,t.lowerCanvas.width,t.lowerCanvas.height),this.lowerContext.clearRect(0,0,t.lowerCanvas.width,t.lowerCanvas.height),t.notify("draw",{prop:"redrawImgWithObj",onPropertyChange:!1}),t.notify("toolbar",{prop:"destroy-qa-toolbar",onPropertyChange:!1}),t.textArea);o.style.display="block",o.style.fontFamily=e.textSettings.fontFamily,o.style.fontSize=e.textSettings.fontSize+"px",o.style.color=e.strokeSettings.strokeColor,o.style.fontWeight=e.textSettings.bold?"bold":"normal",o.style.fontStyle=e.textSettings.italic?"italic":"normal",o.style.border="2px solid "+t.themeColl[t.theme].primaryColor,o.value=e.keyHistory,t.activeObj=O.extend({},e,{},!0),t.notify("shape",{prop:"updateFontStyles",onPropertyChange:!1,value:{isTextBox:null}}),t.textArea.style.width=t.activeObj.activePoint.width+"px"},m.prototype.undoDefault=function(e,t){this.lowerContext.filter=e.previousObj.filter;var o=this.parent,t=(o.objColl=[],o.pointColl=[],o.freehandCounter=0,o.notify("freehand-draw",{prop:"setSelPointColl",onPropertyChange:!1,value:{obj:{selPointColl:[]}}}),o.notify("draw",{prop:"setCurrentObj",onPropertyChange:!1,value:{obj:e.previousObj,isUndoRedo:t}}),o.prevStraightenedDegree=o.transform.straighten,this.upperContext.clearRect(0,0,o.upperCanvas.width,o.upperCanvas.height),o.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),o.img.destLeft=e.previousObj.destPoints.startX,o.img.destTop=e.previousObj.destPoints.startY,O.extend({},o.activeObj,{},!0));o.objColl=O.extend([],e.previousObjColl,[],!0),o.pointColl=O.extend([],e.previousPointColl,[],!0),o.freehandCounter=o.pointColl.length,o.notify("freehand-draw",{prop:"setSelPointColl",onPropertyChange:!1,value:{obj:{selPointColl:O.extend([],e.previousSelPointColl,[],!0)}}}),o.transform.straighten=0,this.lowerContext.filter="none",o.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"zoom",pen:"zoom",isPreventApply:null}}),this.lowerContext.filter=e.previousObj.filter,o.activeObj=t,this.upperContext.clearRect(0,0,o.upperCanvas.width,o.upperCanvas.height),0!==o.activeObj.activePoint.width&&0!==o.activeObj.activePoint.height&&o.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate"}})},m.prototype.endUndoRedo=function(e,t){var o=this.parent;(o.currSelectionPoint&&"crop-circle"===o.currSelectionPoint.shape||o.isCircleCrop)&&JSON.stringify(o.frameObj)!==JSON.stringify({type:"none",color:"#fff",size:20,inset:20,offset:20,radius:0,amount:1,border:"solid",gradientColor:""})&&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}}),0<o.transform.zoomFactor&&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},m.prototype.updateUrc=function(e,t,o,i,r,n,a,s,l,p){var h=this.parent;if(!h.isResize&&!this.isPreventing){var d={isInitialLoaded:!1};if(h.currObjType.isUndoAction&&this.refreshUrc(!0),h.notify("draw",{prop:"isInitialLoaded",onPropertyChange:!1,value:{object:d}}),!d.isInitialLoaded&&h.allowUndoRedo){var d={currObj:{}},d=(h.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:d}}),d.currObj),c=(d.objColl=O.extend([],h.objColl,[],!0),d.pointColl=O.extend([],h.pointColl,[],!0),d.afterCropActions=O.extend([],h.afterCropActions,[],!0),{selPointColl:null});if(h.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:c}}),d.selPointColl=O.extend([],c.selPointColl,[],!0),"crop"===e)d.currSelectionPoint=O.extend({},h.currSelectionPoint,{},!0);else if("frame"===e)t.destPoints={startX:h.frameDestPoints.destLeft,startY:h.frameDestPoints.destTop,width:h.frameDestPoints.destWidth,height:h.frameDestPoints.destHeight},d.destPoints={startX:h.frameDestPoints.destLeft,startY:h.frameDestPoints.destTop,width:h.frameDestPoints.destWidth,height:h.frameDestPoints.destHeight},O.isNullOrUndefined(h.tempFrameZoomLevel)||(t.defaultZoom=d.defaultZoom=h.tempFrameZoomLevel);else if(("imageHFlip"===e||"imageVFlip"===e)&&0<this.appliedUndoRedoColl.length){var u=o[o.length-1].currIndex;if(o=this.appliedUndoRedoColl[this.appliedUndoRedoColl.length-1].currentObjColl,u)for(var g=0,v=o.length;g<v;g++)if(o[g].currIndex===u){var f=O.extend({},o[g],{},!0);o.splice(g,1),o.push(f);break}}this.undoRedoColl.push({operation:e,previousObj:t,currentObj:d,previousObjColl:o,currentObjColl:d.objColl,previousPointColl:i,currentPointColl:d.pointColl,previousSelPointColl:r,currentSelPointColl:d.selPointColl,previousCropObj:n,currentCropObj:O.extend({},h.cropObj,{},!0),previousText:a,currentText:s,filter:l,isCircleCrop:p}),h.notify("toolbar",{prop:"enable-disable-btns",onPropertyChange:!1})}}},m.prototype.updateUrObj=function(e,t){var o,i,r,n=this.parent;n.allowUndoRedo&&(n.currObjType.isUndoAction&&!n.isShapeDrawing&&this.refreshUrc(!0),O.isNullOrUndefined(n.activeObj.imageRatio)&&n.notify("shape",{prop:"updImgRatioForActObj",onPropertyChange:!1}),n.objColl.push(n.activeObj),o=O.extend({},n.cropObj,{},!0),n.notify("filter",{prop:"getCurrentObj",onPropertyChange:!(i={currObj:{}}),value:{object:i}}),(i=i.currObj).objColl=O.extend([],n.objColl,[],!0),i.pointColl=O.extend([],n.pointColl,[],!0),i.afterCropActions=O.extend([],n.afterCropActions,[],!0),n.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!(r={selPointColl:null}),value:{obj:r}}),i.selPointColl=O.extend([],r.selPointColl,[],!0),this.undoRedoColl.push({operation:t||"shapeTransform",previousObj:i,currentObj:i,previousObjColl:e,currentObjColl:i.objColl,previousPointColl:i.pointColl,currentPointColl:i.pointColl,previousSelPointColl:i.selPointColl,currentSelPointColl:i.selPointColl,previousCropObj:o,currentCropObj:o}),n.notify("selection",{prop:"redrawShape",onPropertyChange:!1,value:{obj:n.objColl[n.objColl.length-1]}}))},m.prototype.updateUndoRedo=function(e){var t=this.parent,o=O.extend({},t.cropObj,{},!0),i={currObj:{}},i=(t.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:i}}),i.currObj),r=(i.objColl=O.extend([],t.objColl,[],!0),i.pointColl=O.extend([],t.pointColl,[],!0),i.afterCropActions=O.extend([],t.afterCropActions,[],!0),{selPointColl:null});t.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:r}}),i.selPointColl=O.extend([],r.selPointColl,[],!0),O.isNullOrUndefined(t.activeObj.imageRatio)&&t.notify("shape",{prop:"updImgRatioForActObj",onPropertyChange:!1}),t.objColl.push(t.activeObj),this.updateUrc(e||"shapeTransform",i,i.objColl,i.pointColl,i.selPointColl,o),t.objColl.pop(),t.notify("shape",{prop:"applyActObj",onPropertyChange:!1,value:{isMouseDown:null}}),t.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),t.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"shapes",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}}),t.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"main",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}})},m.prototype.getZeroZoomObjPointValue=function(e,t){var o=this.parent,i=(this.updateObjColl(),{currObj:{}}),i=(o.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:i}}),i.currObj),r=(i.objColl=O.extend([],o.objColl,[],!0),i.pointColl=O.extend([],o.pointColl,[],!0),i.afterCropActions=O.extend([],o.afterCropActions,[],!0),{selPointColl:null}),r=(o.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:r}}),i.selPointColl=O.extend([],r.selPointColl,[],!0),{cropDimension:null}),n=(o.notify("transform",{prop:"getCropDimension",onPropertyChange:!1,value:{obj:r}}),O.extend([],o.objColl,[],!0)),a=O.extend([],o.pointColl,[],!0),s={arrowDimension:null},s=(this.parent.notify("draw",{prop:"getArrowDimension",onPropertyChange:!1,value:{obj:s}}),O.extend({},s.arrowDimension,{},!0));if(0<o.transform.zoomFactor&&(0<e.length||0<t.length)){if(0<e.length)for(var l=0;l<e.length;l++)e[l].currIndex||(e[l].currIndex="shape_"+(l+1));o.objColl=e,o.pointColl=t;var p,t=o.isUndoRedo,h=o.isCropTab;0!==o.transform.zoomFactor&&(o.isUndoRedo=!0,o.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"zoom",pen:"zoom",isPreventApply:!0}}),o.notify("freehand-draw",{prop:"updateFHDColl",onPropertyChange:!1}),o.isCropTab=!0,p=O.extend({},o.zoomSettings,null,!0),0<o.transform.zoomFactor?o.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:-o.transform.zoomFactor,zoomPoint:null,isResize:null}}):o.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:Math.abs(o.transform.zoomFactor),zoomPoint:null,isResize:null}}),o.zoomSettings=p,o.isCropTab=h,o.isUndoRedo=t,n=O.extend([],o.objColl,[],!0),a=O.extend([],o.pointColl,[],!0),o.objColl=[],o.pointColl=[],o.freehandCounter=0,o.notify("freehand-draw",{prop:"setSelPointColl",onPropertyChange:!1,value:{obj:{selPointColl:[]}}}),o.notify("transform",{prop:"setCropDimension",onPropertyChange:!1,value:{width:r.cropDimension.width,height:r.cropDimension.height}}),(p={width:r.cropDimension.width,height:r.cropDimension.height}).width+=p.width*i.defaultZoom,p.height+=p.height*i.defaultZoom,o.notify("draw",{prop:"setZoomCropWidth",value:{width:p.width,height:p.height}}),o.notify("draw",{prop:"setCurrentObj",onPropertyChange:!1,value:{obj:i}}),o.img.destLeft=i.destPoints.startX,o.img.destTop=i.destPoints.startY,o.panPoint.totalPannedPoint=i.totalPannedPoint,o.panPoint.totalPannedClientPoint=i.totalPannedClientPoint,o.panPoint.totalPannedInternalPoint=i.totalPannedInternalPoint,o.objColl=O.extend([],i.objColl,[],!0),o.pointColl=O.extend([],i.pointColl,[],!0),o.freehandCounter=o.pointColl.length,o.notify("draw",{prop:"setArrowDimension",onPropertyChange:!1,value:{arrowDimension:s}}),o.notify("freehand-draw",{prop:"setSelPointColl",onPropertyChange:!1,value:{obj:{selPointColl:O.extend([],i.selPointColl,[],!0)}}}),this.lowerContext.filter="none",o.transform.straighten=0,this.applyImgTranform(),o.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"iterate",pen:"iterate",isPreventApply:null}}),o.notify("freehand-draw",{prop:"updateFHDCurPts",onPropertyChange:!1}),this.lowerContext.filter=i.filter,0!==o.transform.degree&&o.notify("transform",{prop:"drawPannedImage",onPropertyChange:!1,value:{xDiff:0,yDiff:0}}),o.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.lowerContext}}),o.isCircleCrop||o.currSelectionPoint&&"crop-circle"===o.currSelectionPoint.shape)&&o.notify("crop",{prop:"cropCircle",onPropertyChange:!1,value:{context:this.lowerContext,isSave:null,isFlip:null}})}return{obj:n,point:a}},m.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)))}},m.prototype.applyImgTranform=function(){for(var e,t=this.parent,o=O.extend({},t.activeObj,{},!0),i=0,r=t.objColl.length;i<r;i++)"image"===t.objColl[i].shape&&(t.activeObj=O.extend({},t.objColl[i],{},!0),e=t.objColl[i].imageCanvas.getContext("2d"),t.notify("selection",{prop:"applyTransformToImg",onPropertyChange:!1,value:{ctx:e}}),this.upperContext.clearRect(0,0,t.upperCanvas.width,t.upperCanvas.height),t.notify("selection",{prop:"setImageClarity",onPropertyChange:!1,value:{bool:!0}}));t.activeObj=o},m.prototype.updateUndoRedoStack=function(e){var t,o,i,r=this.parent;(r.activeObj.currIndex&&0!==r.activeObj.activePoint.width||0!==r.activeObj.activePoint.height||r.activeObj.pointColl&&0<r.activeObj.pointColl.length||e)&&(t="none"!==r.textArea.style.display,o=r.noPushUndo,r.noPushUndo=!1,r.isUndoRedoStack=!0,e?(e=r.togglePen,r.notify("freehand-draw",{prop:"getFreehandDrawSelectedId",onPropertyChange:!(i={freehandDrawSelectedId:null}),value:{obj:i}}),r.okBtn(),r.noPushUndo=o,i.freehandDrawSelectedId?r.selectShape(i.freehandDrawSelectedId):r.freeHandDraw(!0),r.togglePen=e):r.activeObj.currIndex&&(i=r.activeObj.currIndex,r.okBtn(),r.noPushUndo=o,r.selectShape(i),r.drawingShape&&r.notify("selection",{prop:"setCurrentDrawingShape",onPropertyChange:!1,value:{value:r.drawingShape.toLowerCase()}}),t)&&r.enableTextEditing(),r.isUndoRedoStack=!1)};var M=m;function m(e){this.undoRedoStep=0,this.undoRedoColl=[],this.appliedUndoRedoColl=[],this.tempUndoRedoColl=[],this.tempUndoRedoStep=0,this.isPreventing=!1,this.parent=e,this.addEventListener()}y=function(e,t){return(y=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])}))(e,t)};var y,P,j=function(e,t){function o(){this.constructor=e}y(e,t),e.prototype=null===t?Object.create(t):(o.prototype=t.prototype,new o)},x=function(e,t,o,i){var r,n=arguments.length,a=n<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,o):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,o,i);else for(var s=e.length-1;0<=s;s--)(r=e[s])&&(a=(n<3?r(a):3<n?r(t,o,a):r(t,o))||a);return 3<n&&a&&Object.defineProperty(t,o,a),a},U=(P=O.ChildProperty,j(w,P),x([O.Property(null)],w.prototype,"brightness",void 0),x([O.Property(null)],w.prototype,"contrast",void 0),x([O.Property(null)],w.prototype,"hue",void 0),x([O.Property(null)],w.prototype,"saturation",void 0),x([O.Property(null)],w.prototype,"exposure",void 0),x([O.Property(null)],w.prototype,"opacity",void 0),x([O.Property(null)],w.prototype,"blur",void 0),w);function w(){return null!==P&&P.apply(this,arguments)||this}S=O.ChildProperty,j(T,S),x([O.Property(null)],T.prototype,"zoomTrigger",void 0),x([O.Property(1)],T.prototype,"minZoomFactor",void 0),x([O.Property(10)],T.prototype,"maxZoomFactor",void 0),x([O.Property(1)],T.prototype,"zoomFactor",void 0),x([O.Property(null)],T.prototype,"zoomPoint",void 0);var S,W=T;function T(){return null!==S&&S.apply(this,arguments)||this}k=O.ChildProperty,j(F,k),x([O.Property(!0)],F.prototype,"showCircle",void 0),x([O.Property(null)],F.prototype,"strokeColor",void 0),x([O.Property(null)],F.prototype,"fillColor",void 0);var k,_=F;function F(){return null!==k&&k.apply(this,arguments)||this}I=O.ChildProperty,j(A,I),x([O.Property("Arial")],A.prototype,"default",void 0),x([O.Property(null)],A.prototype,"items",void 0);var I,N=A;function A(){return null!==I&&I.apply(this,arguments)||this}z=O.Component,j(D,z),(X=D).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},D.prototype.preRender=function(){this.element.id=this.element.id||O.getUniqueID("ej2-image-editor"),O.Browser.isDevice&&this.element.classList.add("e-device"),this.initializeThemeColl()},D.prototype.render=function(){var e,t;this.isAngular&&(t=(e=this.element).cloneNode(!0),e.parentNode.replaceChild(t,e),this.element=t,O.setValue("ej2_instances",[this],this.element)),this.initialize()},D.prototype.getModuleName=function(){return"image-editor"},D.prototype.getPersistData=function(){return this.addOnPersist([])},D.prototype.onPropertyChanged=function(e,t){for(var o,i=0,r=Object.keys(e);i<r.length;i++)switch(r[i]){case"cssClass":t.cssClass&&O.removeClass([this.element],t.cssClass.replace(/\s+/g," ").trim().split(" ")),e.cssClass&&O.addClass([this.element],e.cssClass.replace(/\s+/g," ").trim().split(" "));break;case"disabled":e.disabled?(this.element.classList.add("e-disabled"),this.unwireEvent()):(this.element.classList.remove("e-disabled"),this.wireEvent());break;case"height":this.element.style.height=e.height,this.update();break;case"width":this.element.style.width=e.width,this.update();break;case"theme":e.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":e.finetuneSettings&&(this.finetuneSettings=e.finetuneSettings,this.notify("filter",{prop:"update-finetunes"}));break;case"locale":e.locale&&(this.notify("toolbar",{prop:"setLocale",onPropertyChange:!1,value:{locale:e.locale}}),this.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"main",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}}));break;case"allowUndoRedo":e.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":e.showQuickAccessToolbar?(this.showQuickAccessToolbar=!0,this.notify("toolbar",{prop:"create-qa-toolbar",onPropertyChange:!1}),this.notify("freehand-draw",{prop:"getFreehandSelectedIndex",onPropertyChange:!(o={freehandSelectedIndex:null}),value:{obj:o}}),this.activeObj.shape?this.notify("toolbar",{prop:"renderQAT",onPropertyChange:!1,value:{isPenEdit:null}}):o.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":e.zoomSettings&&(this.zoomSettings.zoomTrigger=e.zoomSettings.zoomTrigger),O.isNullOrUndefined(this.zoomSettings.zoomTrigger)?(this.zoomSettings.zoomTrigger=v.ZoomTrigger.MouseWheel|v.ZoomTrigger.Pinch|v.ZoomTrigger.Toolbar|v.ZoomTrigger.Commands,this.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"main",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}})):(e.zoomSettings.zoomTrigger&v.ZoomTrigger.Toolbar)===v.ZoomTrigger.Toolbar&&this.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"main",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}});break;case"selectionSettings":e.selectionSettings&&(this.selectionSettings=e.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":e.toolbar&&(this.toolbar=e.toolbar,this.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"main",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}}));break;case"toolbarTemplate":e.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":e.quickAccessToolbarTemplate&&(this.notify("toolbar",{prop:"destroy-qa-toolbar",onPropertyChange:!1}),this.quickAccessToolbarTemplateFn())}},D.prototype.destroy=function(){var e=[],t=(this.element.removeAttribute("tabindex"),this.element.querySelector("#"+this.element.id+"_saveDialog"));t&&"block"===t.style.display&&O.getComponent(document.getElementById(this.element.id+"_saveDialog"),"dialog").destroy(),this.cssClass&&(e=e.concat(this.cssClass.replace(/\s+/g," ").trim().split(" "))),O.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),z.prototype.destroy.call(this),this.element.innerHTML=""},D.prototype.initialize=function(){var e;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(),359<this.element.offsetWidth&&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"})),(e=document.getElementById(this.element.id+"_quickAccessToolbarArea")).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&&O.addClass([this.element],this.cssClass.replace(/\s+/g," ").trim().split(" ")),this.element&&u.createSpinner({target:this.element}),this.initializeZoomSettings(),this.imgSrc&&this.open(this.imgSrc)},D.prototype.createDropUploader=function(){var i=this;new g.Uploader({dropArea:this.element.getElementsByClassName("e-canvas-wrapper")[0],allowedExtensions:".jpg, .jpeg, .png,.svg",multiple:!1,selected:function(e){var t,o;"change"!==e.event.type&&"drop"!==e.event.type||(t=e.filesData[0].type,o="unsupported","change"!==e.event.type&&("drop"!==e.event.type||1!==e.event.dataTransfer.files.length)||"png"!==t&&"jpg"!==t&&"jpeg"!==t&&"svg"!==t?("drop"===e.event.type&&1<e.event.dataTransfer.files.length&&(o="multi-select-image"),i.showDialogPopup(o)):i.notify("draw",{prop:"fileSelect",value:{inputElement:i.element.querySelector("#"+i.element.id+"_dropfileUpload"),args:e}}))}}).appendTo("#"+this.element.id+"_dropfileUpload")},D.prototype.dlgCloseBtnClick=function(){O.getComponent(document.getElementById(this.element.id+"_dialog"),"dialog").destroy()},D.prototype.showDialogPopup=function(e){var t,o,i="",r=(this.element.querySelector("#"+this.element.id+"_dialog").style.display="block",{key:"DlgOK"});this.notify("toolbar",{prop:"getLocaleText",onPropertyChange:!1,value:{obj:r}}),i="multi-select-image"===e?(this.notify("toolbar",{prop:"getLocaleText",onPropertyChange:!(t={key:"ImageErrorDialogHeader"}),value:{obj:t}}),this.notify("toolbar",{prop:"getLocaleText",onPropertyChange:!(o={key:"ImageErrorDialogContent"}),value:{obj:o}}),"<span>"+o.value+"</span>"):(this.notify("toolbar",{prop:"getLocaleText",onPropertyChange:!(t={key:"AlertDialogHeader"}),value:{obj:t}}),this.notify("toolbar",{prop:"getLocaleText",onPropertyChange:!(o={key:"AlertDialogContent"}),value:{obj:o}}),this.notify("toolbar",{prop:"getLocaleText",onPropertyChange:!(e={key:"SupportText"}),value:{obj:e}}),"<span>"+o.value+" "+e.value+"<b> JPG, PNG, and SVG</b></span>"),new u.Dialog({header:t.value,closeOnEscape:!0,content:i,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")},D.prototype.wireEvent=function(){O.EventHandler.add(document,"keydown",this.keyDownEventHandler,this),O.EventHandler.add(document,"keypress",this.keyUpEventHandler,this),O.EventHandler.add(this.upperCanvas,"mousedown",this.mouseDownEventHandler,this),O.EventHandler.add(this.upperCanvas,"mousemove",this.mouseMoveEventHandler,this),O.EventHandler.add(this.upperCanvas,"mouseup",this.mouseUpEventHandler,this),O.EventHandler.add(document,"mouseup",this.mouseUpEventHandler,this),O.EventHandler.add(this.lowerCanvas,"mousedown",this.canvasMouseDownHandler,this),O.EventHandler.add(this.lowerCanvas,"mousemove",this.canvasMouseMoveHandler,this),O.EventHandler.add(this.lowerCanvas,"mouseup",this.canvasMouseUpHandler,this),O.EventHandler.add(this.upperCanvas,"touchstart",this.touchStartHandler,this),O.EventHandler.add(this.lowerCanvas,"touchstart",this.touchStartHandler,this),O.EventHandler.add(this.lowerCanvas,"mousewheel DOMMouseScroll",this.handleScroll,this),O.EventHandler.add(this.upperCanvas,"mousewheel DOMMouseScroll",this.handleScroll,this),window.addEventListener("resize",this.windowResizeHandler.bind(this)),O.Browser.isIos||"safari"===O.Browser.info.name||screen.orientation.addEventListener("change",this.screenOrientation.bind(this)),this.notify("shape",{prop:"wireEvent",onPropertyChange:!1})},D.prototype.unwireEvent=function(){O.EventHandler.remove(document,"keydown",this.keyDownEventHandler),O.EventHandler.remove(document,"keypress",this.keyUpEventHandler),O.EventHandler.remove(this.upperCanvas,"mousedown",this.mouseDownEventHandler),O.EventHandler.remove(this.upperCanvas,"mousemove",this.mouseMoveEventHandler),O.EventHandler.remove(this.upperCanvas,"mouseup",this.mouseUpEventHandler),O.EventHandler.remove(document,"mouseup",this.mouseUpEventHandler),O.EventHandler.remove(this.lowerCanvas,"mousedown",this.canvasMouseDownHandler),O.EventHandler.remove(this.lowerCanvas,"mousemove",this.canvasMouseMoveHandler),O.EventHandler.remove(this.lowerCanvas,"mouseup",this.canvasMouseUpHandler),O.EventHandler.remove(this.upperCanvas,"touchstart",this.touchStartHandler),O.EventHandler.remove(this.lowerCanvas,"touchstart",this.touchStartHandler),O.EventHandler.remove(this.lowerCanvas,"mousewheel DOMMouseScroll",this.handleScroll),O.EventHandler.remove(this.upperCanvas,"mousewheel DOMMouseScroll",this.handleScroll),window.removeEventListener("resize",this.windowResizeHandler.bind(this)),O.Browser.isIos||"safari"===O.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})},D.prototype.createCanvas=function(){this.element.style.boxSizing="border-box";var e={toolbarHeight:0},e=(this.notify("toolbar",{prop:"getToolbarHeight",value:{obj:e}}),e.toolbarHeight),e=(this.toolbar&&0<this.toolbar.length&&-1===this.toolbar.indexOf("Open")&&(e=0),this.element.style.width=this.width,this.element.style.height=this.height,this.element.appendChild(this.createElement("div",{id:this.element.id+"_canvasWrapper",className:"e-canvas-wrapper",attrs:{style:"height:"+(this.element.offsetHeight-e-2)+"px; width:"+(this.element.offsetWidth-2)+"px; position: relative; overflow: hidden; margin: 0 auto;"}}))),t={key:"DragText"},o=(this.notify("toolbar",{prop:"getLocaleText",onPropertyChange:!1,value:{obj:t}}),{key:"DropText"}),i=(this.notify("toolbar",{prop:"getLocaleText",onPropertyChange:!1,value:{obj:o}}),{key:"BrowseText"}),r=(this.notify("toolbar",{prop:"getLocaleText",onPropertyChange:!1,value:{obj:i}}),{key:"SupportText"}),n=(this.notify("toolbar",{prop:"getLocaleText",onPropertyChange:!1,value:{obj:r}}),this.createElement("div",{id:this.element.id+"_dropArea",className:"e-ie-drop-area",attrs:{style:"position: relative;"}})),a=this.createElement("span",{className:"e-ie-drop-icon e-icons e-image",attrs:{style:"position: absolute;"}}),s=this.createElement("span",{className:"e-ie-drop-content",attrs:{style:"position: absolute; display: none;"}}),t=(s.textContent=t.value+" ",this.createElement("span",{className:"e-ie-min-drop-content",attrs:{style:"position: absolute;"}})),o=(t.textContent=o.value+" ",this.createElement("a",{id:this.element.id+"_dropBrowse",className:"e-ie-drop-browse"})),l=(o.textContent=i.value,this.createElement("a",{id:this.element.id+"_dropBrowse",className:"e-ie-drop-browse"})),i=(l.textContent=i.value,s.appendChild(o),t.appendChild(l),o.href="",l.href="",this.createElement("span",{className:"e-ie-drop-info",attrs:{position:"absolute"}})),p=(i.textContent=r.value+" SVG, PNG, and JPG",n.appendChild(this.createElement("input",{id:this.element.id+"_dropfileUpload",className:"e-fileUpload e-image-upload"})));p.setAttribute("type","file"),p.setAttribute("accept","image/*"),n.appendChild(a),n.appendChild(s),n.appendChild(t),n.appendChild(i),e.appendChild(n),this.lowerCanvas=e.appendChild(this.createElement("canvas",{id:this.element.id+"_lowerCanvas",attrs:{name:"canvasImage"}})),this.upperCanvas=e.appendChild(this.createElement("canvas",{id:this.element.id+"_upperCanvas",attrs:{name:"canvasImage"}})),this.inMemoryCanvas=this.createElement("canvas",{id:this.element.id+"_inMemoryCanvas",attrs:{name:"canvasImage"}}),this.baseImgCanvas=this.createElement("canvas",{id:this.element.id+"_baseImgCanvas",attrs:{name:"canvasImage"}}),this.textArea=e.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";r=this.element.appendChild(this.createElement("input",{id:this.element.id+"_fileUpload",className:"e-fileUpload"}));r.setAttribute("type","file"),r.setAttribute("accept","image/*"),r.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"),o.addEventListener("click",function(e){return e.preventDefault(),p.click(),!1}),l.addEventListener("click",function(e){return e.preventDefault(),p.click(),!1})},D.prototype.touchStartHandler=function(e){this.notify("selection",{prop:"touchStartHandler",onPropertyChange:!1,value:{e:e}})},D.prototype.mouseDownEventHandler=function(e){"e-ie-drop-browse"!==e.target.className&&this.notify("selection",{prop:"mouseDownEventHandler",onPropertyChange:!1,value:{e:e}})},D.prototype.mouseMoveEventHandler=function(e){this.notify("selection",{prop:"mouseMoveEventHandler",onPropertyChange:!1,value:{e:e}})},D.prototype.mouseUpEventHandler=function(e){"e-ie-drop-browse"!==e.target.className&&this.notify("selection",{prop:"mouseUpEventHandler",onPropertyChange:!1,value:{e:e}})},D.prototype.keyDownEventHandler=function(e){this.notify("selection",{prop:"keyDownEventHandler",onPropertyChange:!1,value:{e:e}})},D.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}})},D.prototype.canvasMouseDownHandler=function(e){"e-ie-drop-browse"!==e.target.className&&this.notify("selection",{prop:"canvasMouseDownHandler",onPropertyChange:!1,value:{e:e}})},D.prototype.canvasMouseMoveHandler=function(e){this.notify("selection",{prop:"canvasMouseMoveHandler",onPropertyChange:!1,value:{e:e}})},D.prototype.canvasMouseUpHandler=function(e){"e-ie-drop-browse"!==e.target.className&&this.notify("selection",{prop:"canvasMouseUpHandler",onPropertyChange:!1,value:{e:e}})},D.prototype.handleScroll=function(e){this.notify("selection",{prop:"handleScroll",onPropertyChange:!1,value:{e:e}})},D.prototype.adjustToScreen=function(){this.update()},D.prototype.screenOrientation=function(){O.Browser.isDevice&&setTimeout(this.adjustToScreen.bind(this),100)},D.prototype.windowResizeHandler=function(){!O.Browser.isDevice&&this.element.classList.contains("e-image-editor")&&this.adjustToScreen()},D.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})}},D.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},D.prototype.clearSelection=function(e){this.notify("selection",{prop:"clearSelection",onPropertyChange:!1,value:{resetCrop:e}})},D.prototype.crop=function(){var e={isCrop:!1};return this.notify("crop",{prop:"crop",onPropertyChange:!1,value:{obj:e}}),e.isCrop},D.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"}})},D.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)},D.prototype.open=function(e){O.isNullOrUndefined(e)||(document.getElementById(this.element.id+"_dropArea").style.display="none",this.notify("draw",{prop:"open",value:{data:e}}))},D.prototype.reset=function(){var e,t={isErrorImage:!1};this.notify("draw",{prop:"getErrorImage",value:{obj:t}}),this.disabled||t.isErrorImage||(this.clearContext(this.inMemoryContext),this.clearContext(this.lowerContext),this.clearContext(this.upperContext),this.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),this.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"main",isApplyBtn:!1,isCropping:!1,isZooming:null,cType:null}}),O.Browser.isDevice&&document.getElementById(this.element.id+"_bottomToolbar")&&(O.getComponent(document.getElementById(this.element.id+"_bottomToolbar"),"toolbar").destroy(),this.notify("toolbar",{prop:"create-bottom-toolbar",onPropertyChange:!1})),t=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=!1,e={initialZoomValue:!(this.shapeColl=[])},this.notify("draw",{prop:"getInitialZoomValue",onPropertyChange:!1,value:{obj:e}}),e.initialZoomValue&&this.setProperties({zoomSettings:{zoomFactor:e.initialZoomValue}},!0),(e=document.getElementById(this.element.id+"_quickAccessToolbarArea"))&&(e.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=t,this.straightenBaseImageCanvas(),this.isImageLoaded=!1,this.notify("draw",{prop:"update-canvas",onPropertyChange:!1}),this.isImageLoaded=t,this.prevStraightenedDegree=0,(e=this.element.querySelector(".e-contextual-toolbar-wrapper"))&&e.classList.add("e-hide"),this.notify("toolbar",{prop:"refresh-dropdown-btn",value:{isDisabled:!1}}),this.notify("toolbar",{prop:"enable-disable-btns"}),t=this.isStraightening,O.Browser.isDevice&&t&&this.notify("crop",{prop:"resizeWrapper"}))},D.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},D.prototype.export=function(e,t){this.applyShapes(),this.notify("export",{prop:"export",onPropertyChange:!1,value:{type:e,fileName:t}})},D.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:""}},D.prototype.freeHandDraw=function(e){this.notify("freehand-draw",{prop:"freeHandDraw",onPropertyChange:!1,value:{value:e}})},D.prototype.freehandDraw=function(e){!this.disabled&&this.isImageLoaded&&(this.applyShapes(),this.freeHandDraw(e))},D.prototype.pan=function(e,t,o){this.applyShapes(),this.notify("transform",{prop:"pan",onPropertyChange:!1,value:{value:e,x:t,y:o}})},D.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"})},D.prototype.drawEllipse=function(e,t,o,i,r,n,a,s,l){var p=!1,h=this.allowShape(e,t);return!this.disabled&&this.isImageLoaded&&(h||O.isNullOrUndefined(e)&&O.isNullOrUndefined(t))&&(this.notify("shape",{prop:"drawEllipse",onPropertyChange:!(p=!0),value:{x:e,y:t,radiusX:o,radiusY:i,strokeWidth:r,strokeColor:n,fillColor:a,degree:s,isSelected:l}}),this.notify("draw",{prop:"redrawDownScale"})),p},D.prototype.drawLine=function(e,t,o,i,r,n,a){var s=!1,l=this.allowShape(e,t);return!this.disabled&&this.isImageLoaded&&(l||O.isNullOrUndefined(e)&&O.isNullOrUndefined(t))&&(this.notify("shape",{prop:"drawLine",onPropertyChange:!(s=!0),value:{startX:e,startY:t,endX:o,endY:i,strokeWidth:r,strokeColor:n,isSelected:a}}),this.notify("draw",{prop:"redrawDownScale"})),s},D.prototype.drawArrow=function(e,t,o,i,r,n,a,s,l){var p=!1,h=this.allowShape(e,t);return!this.disabled&&this.isImageLoaded&&(h||O.isNullOrUndefined(e)&&O.isNullOrUndefined(t))&&(this.notify("shape",{prop:"drawArrow",onPropertyChange:!(p=!0),value:{startX:e,startY:t,endX:o,endY:i,strokeWidth:r,strokeColor:n,arrowStart:a,arrowEnd:s,isSelected:l}}),this.notify("draw",{prop:"redrawDownScale"})),p},D.prototype.drawPath=function(e,t,o,i){var r={inRange:!(this.isPublicMethod=!0)},n=!1;if(e&&0<e.length)for(var a=0;a<e.length&&!r.inRange;a++)this.notify("shape",{prop:"isPointsInRange",onPropertyChange:!1,value:{x:e[a].x,y:e[a].y,obj:r}});return!this.disabled&&this.isImageLoaded&&(r.inRange||O.isNullOrUndefined(e))&&(n=!0,this.applyShapes(),this.notify("shape",{prop:"drawPath",onPropertyChange:!1,value:{pointColl:e,strokeWidth:t,strokeColor:o,isSelected:i}}),this.notify("draw",{prop:"redrawDownScale"})),n},D.prototype.drawRectangle=function(e,t,o,i,r,n,a,s,l){var p=!1,h=this.allowShape(e,t);return!this.disabled&&this.isImageLoaded&&(h||O.isNullOrUndefined(e)&&O.isNullOrUndefined(t))&&(this.notify("shape",{prop:"drawRectangle",onPropertyChange:!(p=!0),value:{x:e,y:t,width:o,height:i,strokeWidth:r,strokeColor:n,fillColor:a,degree:s,isSelected:l}}),this.notify("draw",{prop:"redrawDownScale"})),p},D.prototype.drawText=function(e,t,o,i,r,n,a,s,l,p){var h=!1,d=this.allowShape(e,t);return!this.disabled&&this.isImageLoaded&&(d||O.isNullOrUndefined(e)&&O.isNullOrUndefined(t))&&(this.notify("shape",{prop:"drawText",onPropertyChange:!(h=!0),value:{x:e,y:t,text:o,fontFamily:i,fontSize:r,bold:n,italic:a,color:s,isSelected:l,degree:p}}),this.notify("draw",{prop:"redrawDownScale"})),h},D.prototype.drawImage=function(e,t,o,i,r,n,a,s,l){var p=!1,h=this.allowShape(t,o);return p=!this.disabled&&this.isImageLoaded&&(h||O.isNullOrUndefined(t)&&O.isNullOrUndefined(o))&&(h=this.objColl.length,this.notify("shape",{prop:"drawImage",onPropertyChange:!1,value:{x:t,y:o,width:i,height:r,src:e,degree:a,isAspectRatio:n,opacity:s,isSelected:l}}),this.notify("draw",{prop:"redrawDownScale"}),this.objColl.length>h)?!0:p},D.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},D.prototype.deleteShape=function(e){this.applyShapes(),this.notify("shape",{prop:"deleteShape",onPropertyChange:!1,value:{id:e}}),this.notify("draw",{prop:"redrawDownScale"})},D.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||{}},D.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},D.prototype.update=function(){this.notify("transform",{prop:"update"})},D.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"}))},D.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"}}))},D.prototype.undo=function(){this.applyShapes(),this.notify("undo-redo",{prop:"undo",onPropertyChange:!1}),this.notify("draw",{prop:"redrawDownScale"})},D.prototype.redo=function(){this.applyShapes(),this.notify("undo-redo",{prop:"redo",onPropertyChange:!1}),this.notify("draw",{prop:"redrawDownScale"})},D.prototype.getImageDimension=function(){return{x:this.img.destLeft,y:this.img.destTop,width:this.img.destWidth,height:this.img.destHeight}},D.prototype.resize=function(e,t,o){var i,r,n,a,s,l,p=!1;return e.toString().length<=4&&t.toString().length<=4&&(this.applyShapes(),i=this.img.destLeft,r=this.img.destTop,n=this.img.destWidth,a=this.img.destHeight,o&&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}}),s=this.element.querySelector("#"+this.element.id+"_resizeWidth"),l=this.element.querySelector("#"+this.element.id+"_resizeHeight"),s&&l&&(O.getComponent(s,"numerictextbox").value=Math.floor(e),s.value=Math.floor(e).toString()+" px",O.getComponent(l,"numerictextbox").value=Math.floor(t),l.value=Math.floor(t).toString()+" px"),this.notify("transform",{prop:"resize",value:{width:e,height:t,isAspectRatio:o}}),i!==this.img.destLeft||r!==this.img.destTop||n!==this.img.destWidth||a!==this.img.destHeight?(p=!0,this.okBtn()):this.notify("draw",{prop:"performCancel",value:{isContextualToolbar:null}}),this.notify("draw",{prop:"redrawDownScale"})),p},D.prototype.drawFrame=function(e,t,o,i,r,n,a,s,l){this.applyShapes();var p=!1,h={frameChangeEventArgs:null},d=(t=t||"#fff",o=o||"",i=i||20,r=r||0,n=n||0,a=a||0,s=s||v.FrameLineStyle.Solid,l=l||0,{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 O.extend(this.tempFrameObj,this.frameObj),this.tempFrameZoomLevel=this.transform.zoomFactor,this.frameDestPoints=O.extend({},this.img,{},!0),this.notify("toolbar",{prop:"frameToolbarClick"}),this.frameObj.type=e.toLowerCase(),this.frameObj.color=t,this.frameObj.gradientColor=o,this.frameObj.size=i,this.frameObj.inset=r,this.frameObj.offset=n,this.frameObj.radius=a,this.frameObj.border=s.toLowerCase(),this.frameObj.amount=l,this.notify("draw",{prop:"triggerFrameChange",value:{prevFrameSettings:d,obj:h}}),h.frameChangeEventArgs&&!h.frameChangeEventArgs.cancel?(this.notify("draw",{prop:"render-image",value:{isMouseWheel:null}}),JSON.stringify(this.frameObj)!==JSON.stringify(this.tempFrameObj)?(p=!0,this.okBtn()):this.tempFrameZoomLevel=null):(this.notify("draw",{prop:"performCancel",value:{isContextualToolbar:null}}),O.extend(this.frameObj,this.tempFrameObj),this.tempFrameZoomLevel=null),this.notify("draw",{prop:"redrawDownScale"}),p},D.prototype.straightenImage=function(e){var t=!1;return-45<=e&&e<=45&&(this.applyShapes(),t=!0,this.notify("transform",{prop:"straightenImage",value:{degree:e}}),this.notify("draw",{prop:"redrawDownScale"})),t},D.prototype.updateShape=function(e,t){var o,i={isSelected:!1},r=!1,n={bool:!1};return O.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}})):("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:n}}),i.isSelected&&(o=this.activeObj.textSettings.fontSize,this.notify("shape",{prop:"updateShapeChangeEventArgs",onPropertyChange:!1,value:{shapeSettings:e}}),"text"===this.activeObj.shape&&o&&0!=(o=this.activeObj.textSettings.fontSize-o)&&(this.activeObj.activePoint.height+=o,this.activeObj.activePoint.startY-=o/2,this.activeObj.activePoint.endY+=o/2,this.notify("draw",{prop:"updateActiveObject",onPropertyChange:!1,value:{actPoint:this.activeObj.activePoint,obj:this.activeObj,isMouseMove:null,x:null,y:null}})),o=O.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),o.shape&&this.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate",obj:o}}),"text"===this.activeObj.shape&&this.notify("toolbar",{prop:"editText",onPropertyChange:!1}),n.bool&&this.notify("undo-redo",{prop:"setPreventUR",value:{bool:!0}}),this.okBtn(t,!0),n.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(),t)&&this.selectShape(e.id)),i.isSelected},D.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},D.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},D.prototype.enableTextEditing=function(){var e=O.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})},D.prototype.canUndo=function(){var e=!1;return e=0<this.getUndoRedoColl().index?!0:e},D.prototype.canRedo=function(){var e=!1,t=this.getUndoRedoColl(),o=t.undoRedoColl,t=t.index;return o&&0<o.length&&t<o.length-1&&(e=!0),t===o.length?e=!1:(0===t&&0<o.length||0<t)&&(e=!0),e},D.prototype.apply=function(){this.closeOverlayTbar(),this.okBtn(null,!0)},D.prototype.discard=function(){this.notify("draw",{prop:"performCancel",value:{isContextualToolbar:this.closeOverlayTbar(),isFinalCancel:!0}})},D.prototype.enableShapeDrawing=function(e,t){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=[],this.notify("shape",{prop:"getNewOrder",onPropertyChange:!(e={order:null}),value:{obj:e}}),this.activeObj.order=e.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})):t||this.okBtn(null,!0)},D.prototype.bringToFront=function(e){this.selectShape(e)&&(this.updateShapeOrder(e,"bringToFront"),this.apply())},D.prototype.bringForward=function(e){this.selectShape(e)&&(this.updateShapeOrder(e,"bringForward"),this.apply())},D.prototype.sendToBack=function(e){this.selectShape(e)&&(this.updateShapeOrder(e,"sendToBack"),this.apply())},D.prototype.sendBackward=function(e){this.selectShape(e)&&(this.updateShapeOrder(e,"sendBackward"),this.apply())},D.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");O.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}),document.getElementById(this.element.id+"_dropArea").style.display="block"},D.prototype.applyShapes=function(){var e;!this.isUndoRedoStack&&(this.notify("selection",{prop:"getFreehandDrawEditing",onPropertyChange:!(e={bool:!1}),value:{obj:e}}),e.bool||this.togglePen||this.activeObj.shape&&-1!==["rectangle","ellipse","line","arrow","path","text","image"].indexOf(this.activeObj.shape)||this.drawingShape)&&this.okBtn(null,!0)},D.prototype.closeOverlayTbar=function(){var e=!1,t={bool:null};return this.notify("toolbar",{prop:"getFrameToolbar",onPropertyChange:!1,value:{obj:t}}),!t.bool&&this.element.querySelector(".e-contextual-toolbar-wrapper")&&(this.element.querySelector(".e-contextual-toolbar-wrapper").classList.contains("e-hide")||(e=!0),t=this.isStraightening,O.Browser.isDevice&&(!O.Browser.isDevice||t)||this.element.querySelector(".e-contextual-toolbar-wrapper").classList.add("e-hide")),e},D.prototype.toolbarTemplateFn=function(){var e,t=this.element.id+"_toolbar",o=this.element.querySelector("#"+this.element.id+"_toolbarArea");this.toolbarTemplate&&(this.toolbarFn=this.templateParser(this.toolbarTemplate),e=!this.isReact&&this.isAngular?3===(e=this.toolbarFn({type:"toolbar"},this,"Template",t))[0].nodeType?e[1]:e[0]: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())},D.prototype.quickAccessToolbarTemplateFn=function(){var e,t=this.element.id+"_quickAccessToolbar",o=this.element.querySelector("#"+this.element.id+"_quickAccessToolbarArea");this.quickAccessToolbarTemplate&&(this.qatFn=this.templateParser(this.quickAccessToolbarTemplate),e=!this.isReact&&this.isAngular?3===(e=this.qatFn({type:"toolbar"},this,"Template",t))[0].nodeType?e[1]:e[0]:this.qatFn({type:"toolbar"},this,"Template",t)[0],o.appendChild(e),this.renderReactTemplates())},D.prototype.templateParser=function(t){if(t)try{return"function"!=typeof t&&document.querySelectorAll(t).length?O.compile(document.querySelector(t).innerHTML.trim()):O.compile(t)}catch(e){return O.compile(t)}},D.prototype.getTextFromId=function(e){return{1:"none",2:"bar",3:"arrow",4:"arrowSolid",5:"circle",6:"circleSolid",7:"square",8:"squareSolid"}[""+e]},D.prototype.getFinetuneOption=function(e){return{brightness:v.ImageFinetuneOption.Brightness,contrast:v.ImageFinetuneOption.Contrast,hue:v.ImageFinetuneOption.Hue,saturation:v.ImageFinetuneOption.Saturation,opacity:v.ImageFinetuneOption.Opacity,blur:v.ImageFinetuneOption.Blur,exposure:v.ImageFinetuneOption.Exposure}[""+e]},D.prototype.setPenStroke=function(e){this.notify("freehand-draw",{prop:"setPenStrokeWidth",onPropertyChange:!1,value:{value:parseInt(e,10)}})},D.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}})},D.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},D.prototype.updateImageTransformColl=function(e){var t;"rotateleft"===e?t=-90:"rotateright"===e?t=90:"horizontalflip"===e?t="horizontal":"verticalflip"===e&&(t="vertical");for(var o=0;o<this.objColl.length;o++){var i=this.objColl[o].shape;"image"!==i&&"text"!==i||(O.isNullOrUndefined(this.objColl[o].rotateFlipColl)&&(this.objColl[o].rotateFlipColl=[]),this.objColl[o].rotateFlipColl.push(t),i={collection:this.objColl[o].rotateFlipColl},this.notify("shape",{prop:"alignRotateFlipColl",onPropertyChange:!1,value:{collection:this.objColl[o].rotateFlipColl,isRotateFlipCollection:!1,obj:i}}),this.objColl[o].rotateFlipColl=i.collection)}},D.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&&0<this.transform.cropZoomFactor?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=O.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}})},D.prototype.updateCropTransformItems=function(){this.prevCurrSelectionPoint=O.extend({},this.currSelectionPoint,{},!0),this.notify("draw",{prop:"updateCropSelection",onPropertyChange:!1})},D.prototype.toPascalCase=function(e,t){var o=[];O.isNullOrUndefined(e)||(o=e.toLowerCase().split("-"));for(var i=0;i<o.length;i++)o[i]=o[i].charAt(0).toUpperCase()+o[i].slice(1);return t&&(t.maxText=o.join("")),o.join("")},D.prototype.getFontSizes=function(){var e=[];this.fontSizeColl=[];for(var t=0===this.transform.degree||this.transform.degree%180==0?this.img.destWidth/25:this.img.destHeight/25,o=1;o<=10;o++)this.fontSizeColl.push({text:(o*Math.round(t/2)).toString()}),e.push({text:o.toString()});return e},D.prototype.okBtn=function(e,t){t&&(this.noPushUndo=!1,this.notify("selection",{prop:"setTempActObj",onPropertyChange:!1,value:{obj:{activePoint:{startX:0,startY:0,endX:0,endY:0,width:0,height:0},flipObjColl:[],triangle:[],triangleRatio:[],order:null}}}));var o,i,r=this.element.querySelector(".e-contextual-toolbar-wrapper"),r=(r&&r.classList.remove("e-frame-wrapper"),!1),n=(this.isResizeOkBtn=!0,this.element.querySelector("#"+this.element.id+"_aspectratio")),a=this.element.querySelector("#"+this.element.id+"_nonaspectratio"),s=this.element.querySelector(".e-ie-toolbar-aspect-ratio-btn"),l=this.element.querySelector(".e-ie-toolbar-nonaspect-ratio-btn"),n=((void 0===(o=void 0!==this.activeObj.shape?this.activeObj.shape.split("-"):o)&&this.currObjType.isCustomCrop||void 0!==o&&"crop"===o[0])&&(r=!0),this.allowDownScale=!0,(this.activeObj.shape&&"image"!==this.activeObj.shape||this.togglePen)&&!r&&(this.notify("selection",{prop:"updatePrevShapeSettings",onPropertyChange:!(o={shapeSettingsObj:{}}),value:{obj:o}}),o=o.shapeSettingsObj,this.togglePen&&(o.type=v.ShapeType.FreehandDraw),o={action:"apply",currentShapeSettings:O.extend({},o,{},!0)},this.trigger("shapeChange",o)),(n||a)&&(this.notify("selection",{prop:"getNumTextValue",onPropertyChange:!(o={width:null,height:null}),value:{obj:o}}),i={prevCropObj:this.prevCropObj},p={prevObj:this.prevObj},(o={x:o.width,y:o.height}).x&&o.y&&i.prevCropObj&&p.prevObj?(a||l&&!l.classList.contains("e-hidden")?this.notify("transform",{prop:"resize",value:{width:o.x,height:o.y,isAspectRatio:!1}}):(n||s&&!s.classList.contains("e-hidden"))&&this.notify("transform",{prop:"resize",value:{width:o.x,height:null,isAspectRatio:!0}}),this.isResize=!1,this.aspectWidth=o.x,this.aspectHeight=o.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:p.prevObj.defaultZoom,zoomPoint:null,isResize:!0}}),p.prevObj.zoomFactor&&this.setProperties({zoomSettings:{zoomFactor:p.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:p.prevObj,previousObjColl:p.prevObj.objColl,previousPointColl:p.prevObj.pointColl,previousSelPointColl:p.prevObj.selPointColl,previousCropObj:i.prevCropObj,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),this.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"ok"}}),!(l=this.cancelCropSelection)||!O.isNullOrUndefined(a)&&a||(l.previousObj.aspectWidth=l.currentObj.aspectWidth=this.aspectWidth,l.previousObj.aspectHeight=l.currentObj.aspectHeight=this.aspectHeight,l.previousCropObj=O.extend({},this.cropObj,{},!0),l.currentCropObj=O.extend({},this.cropObj,{},!0),this.notify("draw",{prop:"updateCropSelObj"})),this.cancelCropSelection=null):0===o.x||0===o.y?this.notify("draw",{prop:"performCancel",value:{isContextualToolbar:null}}):this.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"main",isApplyBtn:!1,isCropping:!1,isZooming:null,cType:null}}),this.isAspectRatio=!1),this.element.querySelector(".e-contextual-toolbar-wrapper .e-toolbar-item.e-selected")),s={bool:!1},p=(this.notify("selection",{prop:"getFreehandDrawEditing",onPropertyChange:!1,value:{obj:s}}),this.notify("toolbar",{prop:"getFrameToolbar",onPropertyChange:!1,value:{obj:{bool:null}}}),document.querySelector("#"+this.element.id+"_sliderWrapper"));n&&(this.currentFilter=n.children[0].children[0].id.replace("Canvas","")),r?(0===this.transform.straighten||0===this.panPoint.totalPannedPoint.x&&0===this.panPoint.totalPannedPoint.y&&0===this.panPoint.totalPannedClientPoint.x&&0===this.panPoint.totalPannedClientPoint.y||(i=this.prevStraightenedDegree,this.prevStraightenedDegree=this.transform.straighten,this.setStraighten(this.transform.straighten-3),this.setStraighten(this.transform.straighten+3),this.prevStraightenedDegree=i),this.isCroppedEvent=this.crop()):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}})):"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}),O.isNullOrUndefined(e)&&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}})):p||this.currObjType.isFiltered?(this.initialAdjustmentValue=this.canvasFilter=this.lowerContext.filter,this.currObjType.isFiltered=!1,this.notify("draw",{prop:"getTempAdjustmentValue",value:{obj:a={value:null}}}),a.value===this.lowerContext.filter||p&&p.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&&0<this.activeObj.pointColl.length)&&this.notify("shape",{prop:"applyActObj",onPropertyChange:!1,value:{isMouseDown:null}})):s.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})):0!==this.activeObj.activePoint.width||0!==this.activeObj.activePoint.height||"path"===this.activeObj.shape&&0<this.activeObj.pointColl.length?("image"===this.activeObj.shape&&this.notify("draw",{prop:"setImageApply",onPropertyChange:!1,value:{bool:!0}}),this.notify("shape",{prop:"applyActObj",onPropertyChange:!1,value:{isMouseDown:null}})):(JSON.stringify(this.frameObj)!==JSON.stringify(this.tempFrameObj)&&(this.notify("filter",{prop:"getCurrentObj",onPropertyChange:!(l={currObj:{}}),value:{object:l}}),this.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:O.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=O.extend({},this.frameObj,{},!0)),this.notify("draw",{prop:"resetFrameZoom",onPropertyChange:!1,value:{isOk:!0}})),s.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,t&&(this.drawingShape=null,this.notify("draw",{prop:"resetTempObjColl"}),this.notify("draw",{prop:"resetTempPointColl"}))},D.prototype.getObjFromId=function(e){var t;if(this.activeObj.currIndex&&this.activeObj.currIndex===e)t=O.extend({},this.activeObj,{},!0);else for(var o=0;o<this.shapeColl.length;o++)if((this.shapeColl[o].id||this.shapeColl[o].currIndex)===e){t=O.extend({},this.shapeColl[o],{},!0);break}return t},D.prototype.setTempFilterProperties=function(){this.upperCanvas.style.display="block",this.cropSelectedState();var e={adjustmentLevel:null},e=(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:O.extend({},e.adjustmentLevel,{},!0)}}),this.notify("draw",{prop:"setTempFilter",value:{tempFilter:this.currentFilter}}),{undoRedoStep:null});this.notify("undo-redo",{prop:"getUndoRedoStep",value:{obj:e}}),this.notify("draw",{prop:"setTempUndoRedoStep",value:{tempUndoRedoStep:e.undoRedoStep}})},D.prototype.cropSelectedState=function(){this.activeObj.shape&&"crop"===this.activeObj.shape.split("-")[0]&&this.okBtn()},D.prototype.getCurrentCanvasData=function(){var e=O.extend({},this.frameObj,{},!0),t=(this.frameObj={type:"none",color:"#fff",size:20,inset:20,offset:20,radius:0,amount:1,border:"solid",gradientColor:""},this.lowerContext.filter),o=(this.lowerContext.filter=this.canvasFilter="none",O.extend([],this.objColl,null,!0)),i=O.extend([],this.pointColl,null,!0),r=(this.objColl=[],this.pointColl=[],this.freehandCounter=0,this.notify("draw",{prop:"render-image",value:{isMouseWheel:!1}}),this.element.querySelector(".e-contextual-toolbar-wrapper")),n=(r&&r.classList.add("e-hide"),this.getImageData());return r&&r.classList.remove("e-hide"),O.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=o,this.pointColl=i,this.freehandCounter=i.length,this.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"iterate",pen:"iterate",isPreventApply:null}}),this.lowerContext.filter=this.canvasFilter=t,this.frameObj=e,n},D.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}})},D.prototype.getSquarePointForPath=function(e){var t={startX:0,startY:0,endX:0,endY:0,width:0,height:0};if(0<e.pointColl.length){for(var t={startX:e.pointColl[0].x,startY:e.pointColl[0].y,endX:e.pointColl[0].x,endY:e.pointColl[0].y},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},D.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)]||e.split("Crop")[1]},D.prototype.clearContext=function(e){e.clearRect(0,0,e.canvas.width,e.canvas.height),e.clearRect(0,0,e.canvas.height,e.canvas.width)},D.prototype.updateArrow=function(e,t){this.notify("shape",{prop:"pushActItemIntoObj"});var o=O.extend({},this.cropObj,{},!0),i={currObj:{}},r={shapeSettingsObj:{}},r=(this.notify("selection",{prop:"updatePrevShapeSettings",onPropertyChange:!1,value:{obj:r}}),r.shapeSettingsObj),i=(this.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:i}}),i.currObj),t=(i.objColl=O.extend([],this.objColl,[],!0),i.pointColl=O.extend([],this.pointColl,[],!0),i.afterCropActions=O.extend([],this.afterCropActions,[],!0),this.objColl.pop(),"startArrow"===e?this.activeObj.start=this.getTextFromId(t):"endArrow"===e&&(this.activeObj.end=this.getTextFromId(t)),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:i,previousObjColl:i.objColl,previousPointColl:i.pointColl,previousCropObj:o,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),this.notify("selection",{prop:"redrawShape",value:{obj:this.objColl[this.objColl.length-1]}}),O.Browser.isDevice?document.getElementById(this.element.id+"_bottomToolbar")&&O.getComponent(this.element.id+"_bottomToolbar","toolbar").refreshOverflow():document.getElementById(this.element.id+"_toolbar")&&O.getComponent(this.element.id+"_toolbar","toolbar").refreshOverflow(),{action:e,currentShapeSettings:O.extend({},r,{},!0)});this.trigger("shapeChange",t)},D.prototype.updateFontFamily=function(e){this.notify("selection",{prop:"setInitialTextEdit",value:{bool:!1}}),this.notify("shape",{prop:"pushActItemIntoObj"});var t,o=O.extend([],this.objColl,[],!0),i=O.extend({},this.cropObj,{},!0),r={shapeSettingsObj:{}},r=(this.notify("selection",{prop:"updatePrevShapeSettings",onPropertyChange:!1,value:{obj:r}}),r.shapeSettingsObj),n={currObj:{}},n=(this.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:n}}),n.currObj),a=(n.objColl=O.extend([],this.objColl,[],!0),n.pointColl=O.extend([],this.pointColl,[],!0),n.afterCropActions=O.extend([],this.afterCropActions,[],!0),{selPointColl:null}),a=(this.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:a}}),n.selPointColl=O.extend([],a.selPointColl,[],!0),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}}),a=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:n,previousObjColl:n.objColl,previousPointColl:n.pointColl,previousSelPointColl:n.selPointColl,previousCropObj:i,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),this.objColl.pop(),this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),t=this.activeObj.activePoint.width+.25*this.activeObj.textSettings.fontSize,this.textArea.style.width=t+"px",this.textArea.style.fontFamily=this.toPascalCase(e),this.activeObj.textSettings.fontFamily=a,this.notify("shape",{prop:"updateFontStyles",onPropertyChange:!1,value:{isTextBox:null}})):(this.notify("shape",{prop:"updateFontRatio",onPropertyChange:!1,value:{obj:this.activeObj,isTextArea:null}}),t=this.activeObj.textSettings.fontFamily=this.toPascalCase(e),this.notify("shape",{prop:"setTextSettings",onPropertyChange:!1,value:{textSettings:null,fontFamily:t,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:n,previousObjColl:o,previousPointColl:O.extend([],this.pointColl,[],!0),previousSelPointColl:n.selPointColl,previousCropObj:i,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),this.notify("selection",{prop:"redrawShape",value:{obj:this.objColl[this.objColl.length-1]}})),{action:"font-family",currentShapeSettings:O.extend({},r,{},!0)});a.currentShapeSettings.fontFamily=this.textArea.style.fontFamily,this.trigger("shapeChange",a)},D.prototype.updateFontSize=function(e){this.notify("selection",{prop:"setInitialTextEdit",value:{bool:!1}}),this.notify("shape",{prop:"pushActItemIntoObj"});var t,o,i=O.extend({},this.cropObj,{},!0),r={shapeSettingsObj:{}},r=(this.notify("selection",{prop:"updatePrevShapeSettings",onPropertyChange:!1,value:{obj:r}}),r.shapeSettingsObj),n={currObj:{}},n=(this.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:n}}),n.currObj),a=(n.objColl=O.extend([],this.objColl,[],!0),n.pointColl=O.extend([],this.pointColl,[],!0),n.afterCropActions=O.extend([],this.afterCropActions,[],!0),{selPointColl:null}),s=(this.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:a}}),n.selPointColl=O.extend([],a.selPointColl,[],!0),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}}),a=this.activeObj.textSettings.fontSize,this.activeObj.textSettings.fontSize=parseInt(this.fontSizeColl[parseInt(e,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:n,previousObjColl:n.objColl,previousPointColl:n.pointColl,previousSelPointColl:n.selPointColl,previousCropObj:i,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),this.objColl.pop(),t="","bold"===this.textArea.style.fontWeight&&(t="bold "),"italic"===this.textArea.style.fontStyle&&(t="italic "),"bold"===this.textArea.style.fontWeight&&"italic"===this.textArea.style.fontStyle&&(t="italic bold "),this.upperContext.font=t+this.activeObj.textSettings.fontSize+"px "+this.textArea.style.fontFamily,t=this.textArea.value.split("\n"),this.notify("shape",{prop:"getMaxText",onPropertyChange:!(s={maxText:""}),value:{isTextBox:!0,text:null,obj:s}}),o=s.maxText,o=this.upperContext.measureText(o).width+.5*this.activeObj.textSettings.fontSize,this.textArea.style.width=o+"px",this.textArea.style.height=t.length*(this.activeObj.textSettings.fontSize+.25*this.activeObj.textSettings.fontSize)+"px",this.activeObj.textSettings.fontSize=a,this.upperContext.font=this.activeObj.textSettings.fontSize+"px "+this.activeObj.textSettings.fontFamily,this.textArea.style.fontSize=parseInt(this.fontSizeColl[parseInt(e,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")):(this.notify("shape",{prop:"updateFontRatio",onPropertyChange:!1,value:{obj:this.activeObj,isTextArea:null}}),a=this.activeObj.textSettings.fontSize=parseInt(this.fontSizeColl[parseInt(e,10)-1].text,10),this.notify("shape",{prop:"setTextSettings",onPropertyChange:!1,value:{textSettings:null,fontFamily:null,fontSize:a}}),this.upperContext.font=this.activeObj.textSettings.fontSize+"px "+this.activeObj.textSettings.fontFamily,t=this.activeObj.keyHistory.split("\n"),this.notify("shape",{prop:"getMaxText",onPropertyChange:!(s={maxText:""}),value:{isTextBox:null,text:null,obj:s}}),e=s.maxText,o=this.upperContext.measureText(e).width+.5*this.activeObj.textSettings.fontSize,a=t.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:o,height:a}}),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:n,previousObjColl:n.objColl,previousPointColl:n.pointColl,previousSelPointColl:n.selPointColl,previousCropObj:i,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),this.notify("selection",{prop:"redrawShape",value:{obj:this.objColl[this.objColl.length-1]}})),{action:"font-size",currentShapeSettings:O.extend({},r,{},!0)});s.currentShapeSettings.fontSize=this.activeObj.textSettings.fontSize,this.trigger("shapeChange",s)},D.prototype.updateFontColor=function(e){this.notify("selection",{prop:"setInitialTextEdit",value:{bool:!1}}),this.notify("shape",{prop:"pushActItemIntoObj"});var t=O.extend({},this.cropObj,{},!0),o={shapeSettingsObj:{}},o=(this.notify("selection",{prop:"updatePrevShapeSettings",onPropertyChange:!1,value:{obj:o}}),o.shapeSettingsObj),i={currObj:{}},i=(this.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:i}}),i.currObj),r=(i.objColl=O.extend([],this.objColl,[],!0),i.pointColl=O.extend([],this.pointColl,[],!0),i.afterCropActions=O.extend([],this.afterCropActions,[],!0),{selPointColl:null}),r=(this.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:r}}),i.selPointColl=O.extend([],r.selPointColl,[],!0),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:i,previousObjColl:i.objColl,previousPointColl:i.pointColl,previousSelPointColl:i.selPointColl,previousCropObj:t,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),this.notify("selection",{prop:"redrawShape",value:{obj:this.objColl[this.objColl.length-1]}}))):"block"===this.textArea.style.display||"inline-block"===this.textArea.style.display?(this.textArea.style.color=e,r=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:i,previousObjColl:i.objColl,previousPointColl:i.pointColl,previousSelPointColl:i.selPointColl,previousCropObj:t,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),this.objColl.pop(),this.activeObj.strokeSettings.strokeColor=r):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:i,previousObjColl:i.objColl,previousPointColl:i.pointColl,previousSelPointColl:i.selPointColl,previousCropObj:t,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]}}),{action:"font-color",currentShapeSettings:O.extend({},o,{},!0)});r.currentShapeSettings.fillColor=e,this.trigger("shapeChange",r)},D.prototype.updatePenStrokeWidth=function(e){var t=O.extend([],this.pointColl,[],!0),o=(this.updateFreehandDrawColorChange(),O.extend({},this.cropObj,{},!0)),i={shapeSettingsObj:{}},i=(this.notify("selection",{prop:"updatePrevShapeSettings",onPropertyChange:!1,value:{obj:i}}),i.shapeSettingsObj),r={currObj:{}},r=(this.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:r}}),r.currObj),n=(r.objColl=O.extend([],this.objColl,[],!0),r.pointColl=O.extend([],this.pointColl,[],!0),r.afterCropActions=O.extend([],this.afterCropActions,[],!0),{selPointColl:null}),n=(this.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:n}}),r.selPointColl=O.extend([],n.selPointColl,[],!0),this.pointColl=t,this.notify("selection",{prop:"setFreehandDrawCustomized",value:{isFreehandDrawCustomized:!0}}),this.setPenStroke(e),{bool:!1}),n=(this.notify("selection",{prop:"getFreehandDrawEditing",onPropertyChange:!1,value:{obj:n}}),n.bool&&(this.notify("freehand-draw",{prop:"getPenStrokeWidth",onPropertyChange:!(t={penStrokeWidth:null}),value:{obj:t}}),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:t.penStrokeWidth}}),this.notify("freehand-draw",{prop:"getFreehandSelectedIndex",onPropertyChange:!(e={freehandSelectedIndex:null}),value:{obj:e}}),this.pointColl[e.freehandSelectedIndex].strokeWidth=t.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:t.penStrokeWidth}}),this.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"freehanddrawCustomized",previousObj:r,previousObjColl:r.objColl,previousPointColl:r.pointColl,previousSelPointColl:r.selPointColl,previousCropObj:o,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}})),i.type=v.ShapeType.FreehandDraw,{action:"stroke-width",currentShapeSettings:O.extend({},i,{},!0)});n.currentShapeSettings.strokeWidth=this.activeObj.strokeSettings.strokeWidth,this.trigger("shapeChange",n)},D.prototype.updatePenStrokeColor=function(e){var t=O.extend([],this.pointColl,[],!0),o=(this.updateFreehandDrawColorChange(),O.extend({},this.cropObj,{},!0)),i={shapeSettingsObj:{}},i=(this.notify("selection",{prop:"updatePrevShapeSettings",onPropertyChange:!1,value:{obj:i}}),i.shapeSettingsObj),r={currObj:{}},r=(this.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:r}}),r.currObj),n=(r.objColl=O.extend([],this.objColl,[],!0),r.pointColl=O.extend([],this.pointColl,[],!0),r.afterCropActions=O.extend([],this.afterCropActions,[],!0),{selPointColl:null}),n=(this.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:n}}),r.selPointColl=O.extend([],n.selPointColl,[],!0),this.pointColl=t,this.notify("selection",{prop:"setFreehandDrawCustomized",value:{isFreehandDrawCustomized:!0}}),this.activeObj.strokeSettings.strokeColor=e,{freehandSelectedIndex:null}),t=(this.notify("freehand-draw",{prop:"getFreehandSelectedIndex",onPropertyChange:!1,value:{obj:n}}),null!=n.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}})),{bool:!1}),t=(this.notify("selection",{prop:"getFreehandDrawEditing",onPropertyChange:!1,value:{obj:t}}),t.bool?(this.notify("freehand-draw",{prop:"getFreehandSelectedIndex",onPropertyChange:!(n={freehandSelectedIndex:null}),value:{obj:n}}),this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),this.pointColl[n.freehandSelectedIndex].strokeColor=e,this.notify("freehand-draw",{prop:"hoverFhd",onPropertyChange:!1,value:{strokeColor:e}}),this.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"freehanddrawCustomized",previousObj:r,previousObjColl:r.objColl,previousPointColl:r.pointColl,previousSelPointColl:r.selPointColl,previousCropObj:o,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}})):this.togglePen||this.notify("selection",{prop:"redrawShape",value:{obj:this.activeObj}}),i.type=v.ShapeType.FreehandDraw,{action:"stroke-color",currentShapeSettings:O.extend({},i,{},!0)});t.currentShapeSettings.strokeColor=e,this.trigger("shapeChange",t)},D.prototype.updateStrokeWidth=function(e){var t,o,i,r;this.activeObj.shape&&("path"!==this.activeObj.shape||"path"===this.activeObj.shape&&0<this.activeObj.pointColl.length)?(this.notify("selection",{prop:"updatePrevShapeSettings",onPropertyChange:!(t={shapeSettingsObj:{}}),value:{obj:t}}),t=t.shapeSettingsObj,this.notify("shape",{prop:"pushActItemIntoObj"}),o=O.extend({},this.cropObj,{},!0),this.notify("filter",{prop:"getCurrentObj",onPropertyChange:!(i={currObj:{}}),value:{object:i}}),(i=i.currObj).objColl=O.extend([],this.objColl,[],!0),i.pointColl=O.extend([],this.pointColl,[],!0),i.afterCropActions=O.extend([],this.afterCropActions,[],!0),this.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!(r={selPointColl:null}),value:{obj:r}}),i.selPointColl=O.extend([],r.selPointColl,[],!0),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: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]}}),(r={action:"stroke-width",currentShapeSettings:O.extend({},t,{},!0)}).currentShapeSettings.strokeWidth=this.activeObj.strokeSettings.strokeWidth,this.trigger("shapeChange",r)):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}}))},D.prototype.updateStrokeColor=function(e){var t,o,i={shapeSettingsObj:{}},i=(this.notify("selection",{prop:"updatePrevShapeSettings",onPropertyChange:!1,value:{obj:i}}),i.shapeSettingsObj),r=(this.activeObj.shape&&("path"!==this.activeObj.shape||"path"===this.activeObj.shape&&0<this.activeObj.pointColl.length)?(this.notify("shape",{prop:"pushActItemIntoObj"}),t=O.extend({},this.cropObj,{},!0),this.notify("filter",{prop:"getCurrentObj",onPropertyChange:!(o={currObj:{}}),value:{object:o}}),(o=o.currObj).objColl=O.extend([],this.objColl,[],!0),o.pointColl=O.extend([],this.pointColl,[],!0),o.afterCropActions=O.extend([],this.afterCropActions,[],!0),this.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!(r={selPointColl:null}),value:{obj:r}}),o.selPointColl=O.extend([],r.selPointColl,[],!0),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:o,previousObjColl:o.objColl,previousPointColl:o.pointColl,previousSelPointColl:o.selPointColl,previousCropObj:t,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),this.notify("selection",{prop:"redrawShape",value:{obj:this.objColl[this.objColl.length-1]}}))):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}})),{action:"stroke-color",currentShapeSettings:O.extend({},i,{},!0)});r.currentShapeSettings.strokeColor=e,this.trigger("shapeChange",r)},D.prototype.updateFillColor=function(e){var t={shapeSettingsObj:{}},t=(this.notify("selection",{prop:"updatePrevShapeSettings",onPropertyChange:!1,value:{obj:t}}),t.shapeSettingsObj),o=(this.notify("shape",{prop:"pushActItemIntoObj"}),O.extend({},this.cropObj,{},!0)),i={currObj:{}},i=(this.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:i}}),i.currObj),r=(i.objColl=O.extend([],this.objColl,[],!0),i.pointColl=O.extend([],this.pointColl,[],!0),i.afterCropActions=O.extend([],this.afterCropActions,[],!0),{selPointColl:null}),r=(this.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:r}}),i.selPointColl=O.extend([],r.selPointColl,[],!0),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: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]}}),{action:"fill-color",currentShapeSettings:O.extend({},t,{},!0)});this.trigger("shapeChange",r)},D.prototype.horizontalFlip=function(e,t){O.isNullOrUndefined(t)&&(O.isNullOrUndefined(this.activeObj.imageRatio)&&this.notify("shape",{prop:"updImgRatioForActObj",onPropertyChange:!1}),this.notify("shape",{prop:"pushActItemIntoObj"}),o=O.extend({},this.cropObj,{},!0),this.notify("filter",{prop:"getCurrentObj",onPropertyChange:!(i={currObj:{}}),value:{object:i}}),(i=i.currObj).objColl=O.extend([],this.objColl,[],!0),i.pointColl=O.extend([],this.pointColl,[],!0),i.afterCropActions=O.extend([],this.afterCropActions,[],!0),this.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!(r={selPointColl:null}),value:{obj:r}}),i.selPointColl=O.extend([],r.selPointColl,[],!0),this.objColl.pop()),this.notify("toolbar",{prop:"refreshSlider"}),e.clearRect(0,0,this.activeObj.imageCanvas.width,this.activeObj.imageCanvas.height);var o,i,r=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=r,this.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate"}}),O.isNullOrUndefined(t)&&(this.objColl.push(this.activeObj),this.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"imageHFlip",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]}}))},D.prototype.verticalFlip=function(e,t){O.isNullOrUndefined(t)&&(O.isNullOrUndefined(this.activeObj.imageRatio)&&this.notify("shape",{prop:"updImgRatioForActObj",onPropertyChange:!1}),this.notify("shape",{prop:"pushActItemIntoObj"}),o=O.extend({},this.cropObj,{},!0),this.notify("filter",{prop:"getCurrentObj",onPropertyChange:!(i={currObj:{}}),value:{object:i}}),(i=i.currObj).objColl=O.extend([],this.objColl,[],!0),i.pointColl=O.extend([],this.pointColl,[],!0),i.afterCropActions=O.extend([],this.afterCropActions,[],!0),this.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!(r={selPointColl:null}),value:{obj:r}}),i.selPointColl=O.extend([],r.selPointColl,[],!0),this.objColl.pop()),this.notify("toolbar",{prop:"refreshSlider"}),e.clearRect(0,0,this.activeObj.imageCanvas.width,this.activeObj.imageCanvas.height);var o,i,r=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=r,this.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate"}}),O.isNullOrUndefined(t)&&(this.objColl.push(this.activeObj),this.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"imageVFlip",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]}}))},D.prototype.rotateImage=function(e){O.isNullOrUndefined(this.activeObj.imageRatio)&&this.notify("shape",{prop:"updImgRatioForActObj",onPropertyChange:!1}),this.notify("shape",{prop:"pushActItemIntoObj"}),t=O.extend({},this.cropObj,{},!0);var t,o={currObj:{}},i=(this.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:o}}),(o=o.currObj).objColl=O.extend([],this.objColl,[],!0),o.pointColl=O.extend([],this.pointColl,[],!0),o.afterCropActions=O.extend([],this.afterCropActions,[],!0),{selPointColl:null});this.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:i}}),o.selPointColl=O.extend([],i.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:o,previousObjColl:o.objColl,previousPointColl:o.pointColl,previousSelPointColl:o.selPointColl,previousCropObj:t,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}})},D.prototype.pascalToSplitWords=function(e){var t=(e=e.charAt(0).toUpperCase()+e.slice(1)).match(/[A-Z][a-z]+/g);return O.isNullOrUndefined(t)?e:t.map(function(e){return e.charAt(0).toUpperCase()+e.slice(1)}).join(" ")},D.prototype.getCurrAdjustmentValue=function(e){var t,o={freehandSelectedIndex:null};return this.notify("freehand-draw",{prop:"getFreehandSelectedIndex",onPropertyChange:!1,value:{obj:o}}),"transparency"===e&&this.togglePen?(this.notify("freehand-draw",{prop:"getPenOpacity",onPropertyChange:!(t={penOpacity:1}),value:{obj:t}}),100*t.penOpacity):"transparency"===e&&null!=o.freehandSelectedIndex?100*this.pointColl[o.freehandSelectedIndex].opacity:(this.notify("filter",{prop:"getAdjustmentLevel",onPropertyChange:!(t={adjustmentLevel:null}),value:{obj:t}}),{brightness:t.adjustmentLevel.brightness,contrast:t.adjustmentLevel.contrast,hue:t.adjustmentLevel.hue,saturation:t.adjustmentLevel.saturation,opacity:t.adjustmentLevel.opacity,blur:t.adjustmentLevel.blur,exposure:t.adjustmentLevel.exposure,transparency:t.adjustmentLevel.transparency,straighten:this.transform.straighten}[""+e])},D.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 t=this.transform.straighten,o=O.extend({},this.activeObj,{},!0),i=this.transform.zoomFactor,r=(this.prevEventSelectionPoint=O.extend({},this.activeObj,{},!0),{currObj:{}}),r=(this.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:r}}),this.prevEventObjPoint=r.currObj,this.prevEventObjPoint.objColl=O.extend([],this.objColl,[],!0),this.prevEventObjPoint.pointColl=O.extend([],this.pointColl,[],!0),this.prevEventObjPoint.afterCropActions=O.extend([],this.afterCropActions,[],!0),{selPointColl:null});if(this.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:r}}),this.prevEventObjPoint.selPointColl=O.extend([],r.selPointColl,[],!0),0!==this.transform.straighten){this.transform.straighten=0,this.straightenBaseImageCanvas();for(var n=0,a=this.objColl.length;n<a;n++)"line"!==(s=this.objColl[n].shape)&&"arrow"!==s&&"path"!==s&&(this.objColl[n].rotatedAngle-=t*(Math.PI/180),this.notify("selection",{prop:"updPtCollForShpRot",onPropertyChange:!1,value:{obj:this.objColl[n]}}));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();r=O.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:r}}),!this.isStraightening||"horizontalflip"!==e&&"verticalflip"!==e||(this.notify("draw",{prop:"resetStraightenDestPoints"}),this.notify("draw",{prop:"setDestForStraighten"})),0!==t){this.transform.straighten=t,this.straightenBaseImageCanvas();for(var s,n=0,a=this.objColl.length;n<a;n++)"line"!==(s=this.objColl[n].shape)&&"arrow"!==s&&"path"!==s&&(this.objColl[n].rotatedAngle+=t*(Math.PI/180),this.notify("selection",{prop:"updPtCollForShpRot",onPropertyChange:!1,value:{obj:this.objColl[n]}}));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:o}}),this.notify("draw",{prop:"setStraightenActObj",value:{activeObj:null}}),this.notify("draw",{prop:"setStraightenInitZoom",value:{zoomFactor:i}}),(this.isStraightening&&("horizontalflip"===e||"verticalflip"===e)&&O.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:o,isToolbar:!1}})}this.isCropToolbar=!1;r=this.element.querySelector(".e-ie-straighten-value-span");r&&(r.innerHTML=this.transform.straighten.toString()+"°")},D.prototype.getDefaultFilter=function(){return"brightness(1) contrast(100%) hue-rotate(0deg) saturate(100%) opacity(1) blur(0px) sepia(0%) grayscale(0%) invert(0%)"},D.prototype.setStraighten=function(e){e={cancel:!1,previousDegree:this.transform.straighten,currentDegree:e};this.trigger("rotating",e),e.cancel||this.performStraighten(e)},D.prototype.duplicateImage=function(){var e=O.extend({},this.activeObj.activePoint,{},!0),t={width:0,height:0};return this.notify("transform",{prop:"calcMaxDimension",onPropertyChange:!1,value:{width:this.activeObj.imageElement.width,height:this.activeObj.imageElement.height,obj:t,isImgShape:null}}),this.activeObj.activePoint.width=t.width,this.activeObj.activePoint.height=t.height,e},D.prototype.performStraighten=function(e){var e=e.currentDegree,t=this.element.querySelector(".e-ie-straighten-value-span"),t=(t&&(t.innerHTML=e.toString()+"°"),O.extend({},this.activeObj,null,!0));this.notify("freehand-draw",{prop:"setCenterSelPoints"}),this.transform.straighten=e,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 o=0,i=this.objColl.length;o<i;o++){var r=this.objColl[o].shape;"line"!==r&&"arrow"!==r&&"path"!==r&&(this.objColl[o].rotatedAngle+=(this.transform.straighten-this.prevStraightenedDegree)*(Math.PI/180),this.notify("selection",{prop:"updPtCollForShpRot",onPropertyChange:!1,value:{obj:this.objColl[o]}}))}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:t}}),this.notify("draw",{prop:"zoomToSel",value:{activeObj:t,isToolbar:!0}}),this.notify("transform",{prop:"disableZoomOutBtn",value:{isZoomOut:!0}}),this.prevStraightenedDegree=this.transform.straighten},D.prototype.straightenBaseImageCanvas=function(){var e,t,o,i;this.isImageLoaded&&(e="horizontal"===(e=this.getStraightenFlipState())||"vertical"===e?-this.transform.straighten:this.transform.straighten,o=void((t=this.baseImgCanvas.getContext("2d")).canvas.width!==this.lowerContext.canvas.width&&t.canvas.height!==this.lowerContext.canvas.height&&this.notify("crop",{prop:"calcRatio",onPropertyChange:!1,value:{obj:{width:0,height:0},dimension:{width:t.canvas.width,height:t.canvas.height}}})),o=this.getRotatedCanvasDim(this.baseImg.width,this.baseImg.height,this.transform.straighten),this.img.srcWidth=t.canvas.width=o.width,this.img.srcHeight=t.canvas.height=o.height,o=t.canvas.width/2,i=t.canvas.height/2,t.clearRect(0,0,t.canvas.width,t.canvas.height),t.translate(o,i),t.rotate(e*Math.PI/180),t.drawImage(this.baseImg,-this.baseImg.width/2,-this.baseImg.height/2,this.baseImg.width,this.baseImg.height),t.setTransform(1,0,0,1,0,0),this.notify("crop",{prop:"calcRatio",onPropertyChange:!1,value:{obj:{width:0,height:0},dimension:{width:t.canvas.width,height:t.canvas.height}}}))},D.prototype.getRotatedCanvasDim=function(e,t,o){var o=o*Math.PI/180,i=Math.cos(o),r=Math.sin(o),n=Math.min(0,e*i,t*Math.cos(Math.PI/2-o),e*i+t*Math.cos(Math.PI/2-o)),i=Math.max(0,e*i,t*Math.cos(Math.PI/2-o),e*i+t*Math.cos(Math.PI/2-o)),a=Math.min(0,e*r,t*Math.sin(Math.PI/2-o),e*r+t*Math.sin(Math.PI/2-o)),e=Math.max(0,e*r,t*Math.sin(Math.PI/2-o),e*r+t*Math.sin(Math.PI/2-o));return{width:Math.ceil(i-n),height:Math.ceil(e-a)}},D.prototype.updateShapeOrder=function(e,t){var o,i,r,n,e=this.getObjFromId(e);e.shape&&("path"!==e.shape||"path"===e.shape&&0<e.pointColl.length)||e&&e.id&&-1<e.id.indexOf("pen")?(this.notify("selection",{prop:"updatePrevShapeSettings",onPropertyChange:!(o={shapeSettingsObj:{}}),value:{obj:o}}),o=o.shapeSettingsObj,e.shape&&this.notify("shape",{prop:"pushActItemIntoObj"}),i=O.extend({},this.cropObj,{},!0),this.notify("filter",{prop:"getCurrentObj",onPropertyChange:!(r={currObj:{}}),value:{object:r}}),(r=r.currObj).objColl=O.extend([],this.objColl,[],!0),r.pointColl=O.extend([],this.pointColl,[],!0),r.afterCropActions=O.extend([],this.afterCropActions,[],!0),this.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!(n={selPointColl:null}),value:{obj:n}}),r.selPointColl=O.extend([],n.selPointColl,[],!0),e.shape&&this.objColl.pop(),this.notify("shape",{prop:"z-order",onPropertyChange:!1,value:{obj:e,value:t}}),e.shape&&(this.notify("shape",{prop:"setStrokeSettings",value:{strokeSettings:null,strokeColor:null,fillColor:null,strokeWidth:e.strokeSettings.strokeWidth}}),this.objColl.push(e)),this.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"shapeTransform",previousObj:r,previousObjColl:r.objColl,previousPointColl:r.pointColl,previousSelPointColl:r.selPointColl,previousCropObj:i,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),e.shape&&(this.notify("selection",{prop:"redrawShape",value:{obj:this.objColl[this.objColl.length-1]}}),this.activeObj.order=e.order),{action:"stroke-width",previousShapeSettings:O.extend({},o,{},!0),currentShapeSettings:O.extend({},o,{},!0)}.currentShapeSettings.strokeWidth=this.activeObj.strokeSettings.strokeWidth):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}})},D.prototype.getStraightenFlipState=function(){var e="";if(0<this.rotateFlipColl.length)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},D.prototype.initializeZoomSettings=function(){this.theme=O.isNullOrUndefined(this.theme)?"Bootstrap5":this.theme,!O.isNullOrUndefined(this.zoomSettings.zoomTrigger)&&0!==this.zoomSettings.zoomTrigger||(this.zoomSettings.zoomTrigger=v.ZoomTrigger.MouseWheel|v.ZoomTrigger.Pinch|v.ZoomTrigger.Toolbar|v.ZoomTrigger.Commands),O.isNullOrUndefined(this.selectionSettings.strokeColor)&&(this.selectionSettings.strokeColor=this.themeColl[this.theme].primaryColor),O.isNullOrUndefined(this.selectionSettings.fillColor)&&(this.selectionSettings.fillColor=this.themeColl[this.theme].secondaryColor)},D.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"}}},x([O.Property("")],D.prototype,"cssClass",void 0),x([O.Property(!1)],D.prototype,"disabled",void 0),x([O.Property("100%")],D.prototype,"height",void 0),x([O.Property("Bootstrap5")],D.prototype,"theme",void 0),x([O.Property()],D.prototype,"toolbar",void 0),x([O.Property()],D.prototype,"toolbarTemplate",void 0),x([O.Property("100%")],D.prototype,"width",void 0),x([O.Property(!0)],D.prototype,"allowUndoRedo",void 0),x([O.Property(!0)],D.prototype,"showQuickAccessToolbar",void 0),x([O.Property()],D.prototype,"quickAccessToolbarTemplate",void 0),x([O.Property(!1)],D.prototype,"isReadOnly",void 0),x([O.Property(!1)],D.prototype,"enableRtl",void 0),x([O.Property(!1)],D.prototype,"enablePersistence",void 0),x([O.Complex({},U)],D.prototype,"finetuneSettings",void 0),x([O.Complex({},W)],D.prototype,"zoomSettings",void 0),x([O.Complex({},_)],D.prototype,"selectionSettings",void 0),x([O.Complex({},N)],D.prototype,"fontFamily",void 0),x([O.Event()],D.prototype,"beforeSave",void 0),x([O.Event()],D.prototype,"created",void 0),x([O.Event()],D.prototype,"destroyed",void 0),x([O.Event()],D.prototype,"zooming",void 0),x([O.Event()],D.prototype,"panning",void 0),x([O.Event()],D.prototype,"cropping",void 0),x([O.Event()],D.prototype,"rotating",void 0),x([O.Event()],D.prototype,"flipping",void 0),x([O.Event()],D.prototype,"shapeChanging",void 0),x([O.Event()],D.prototype,"selectionChanging",void 0),x([O.Event()],D.prototype,"fileOpened",void 0),x([O.Event()],D.prototype,"saved",void 0),x([O.Event()],D.prototype,"toolbarCreated",void 0),x([O.Event()],D.prototype,"toolbarUpdating",void 0),x([O.Event()],D.prototype,"toolbarItemClicked",void 0),x([O.Event()],D.prototype,"imageFiltering",void 0),x([O.Event()],D.prototype,"finetuneValueChanging",void 0),x([O.Event()],D.prototype,"click",void 0),x([O.Event()],D.prototype,"shapeChange",void 0),x([O.Event()],D.prototype,"quickAccessToolbarOpen",void 0),x([O.Event()],D.prototype,"resizing",void 0),x([O.Event()],D.prototype,"quickAccessToolbarItemClick",void 0),x([O.Event()],D.prototype,"frameChange",void 0);var z,X,j=X=x([O.NotifyPropertyChanges],D);function D(e,t){e=z.call(this,e)||this;return e.isImageLoaded=!1,e.activeObj={activePoint:{startX:0,startY:0,endX:0,endY:0,width:0,height:0},flipObjColl:[],triangle:[],triangleRatio:[],rotatedAngle:0,opacity:1,order:null},e.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},e.objColl=[],e.pointColl={},e.freehandCounter=0,e.points=[],e.togglePen=!1,e.togglePan=!1,e.img={destLeft:0,destTop:0,destWidth:0,destHeight:0,srcLeft:0,srcTop:0,srcWidth:0,srcHeight:0},e.rotateFlipColl=[],e.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:""},e.afterCropActions=[],e.transform={degree:0,currFlipState:"",zoomFactor:0,cropZoomFactor:null,defaultZoomFactor:0,straighten:0},e.panPoint={currentPannedPoint:{x:0,y:0},totalPannedPoint:{x:0,y:0},totalPannedInternalPoint:{x:0,y:0},totalPannedClientPoint:{x:0,y:0}},e.isUndoRedo=!1,e.isCropTab=!1,e.isCircleCrop=!1,e.fontSizeColl=[],e.initialAdjustmentValue="",e.currentFilter="",e.canvasFilter="brightness(1) contrast(100%) hue-rotate(0deg) saturate(100%) opacity(1) blur(0px) sepia(0%) grayscale(0%) invert(0%)",e.toolbarHeight=0,e.isPublicMethod=!1,e.isCropToolbar=!1,e.cursor="default",e.resizeSrc={startX:e.img.srcLeft,startY:e.img.srcTop,width:e.img.srcWidth,height:e.img.srcHeight},e.isResize=!1,e.isAspectRatio=!1,e.frameObj={type:"none",color:"#fff",size:20,inset:20,offset:20,radius:0,amount:1,border:"solid",gradientColor:""},e.tempFrameObj={type:"none",color:"#fff",size:20,inset:20,offset:20,radius:0,amount:1,border:"solid",gradientColor:""},e.allowDownScale=!0,e.gradientColor="",e.size=20,e.inset=0,e.offset=0,e.borderRadius=0,e.lineCount=0,e.prevStraightenedDegree=0,e.tempStraighten=0,e.isStraightening=!1,e.isFinetuning=!1,e.isZoomBtnClick=!1,e.isFinetuneBtnClick=!1,e.isFilterCanvasClick=!1,e.isFrameBtnClick=!1,e.isChangesSaved=!1,e.isShapeDrawing=!1,e.noPushUndo=!1,e.isUndoRedoStack=!1,e.shapeColl=[],X.Inject(o,i,h,B,r,q),X.Inject(M),X.Inject(a),X.Inject(H),X.Inject(l),t&&e.appendTo(t),e}(x=v.FileType||(v.FileType={})).Png="Png",x.Jpeg="Jpeg",x.Svg="Svg",(x=v.Direction||(v.Direction={})).Horizontal="Horizontal",x.Vertical="Vertical",(x=v.ShapeType||(v.ShapeType={})).Rectangle="Rectangle",x.Ellipse="Ellipse",x.Line="Line",x.Arrow="Arrow",x.Path="Path",x.Text="Text",x.FreehandDraw="FreehandDraw",x.Image="Image",(x=v.ZoomTrigger||(v.ZoomTrigger={}))[x.MouseWheel=1]="MouseWheel",x[x.Pinch=2]="Pinch",x[x.Commands=4]="Commands",x[x.Toolbar=8]="Toolbar",(x=v.Theme||(v.Theme={})).Bootstrap5="Bootstrap5",x.Bootstrap5Dark="Bootstrap5Dark",x.Tailwind="Tailwind",x.TailwindDark="TailwindDark",x.Fluent="Fluent",x.FluentDark="FluentDark",x.Bootstrap4="Bootstrap4",x.Bootstrap="Bootstrap",x.BootstrapDark="BootstrapDark",x.Material="Material",x.MaterialDark="MaterialDark",x.Fabric="Fabric",x.FabricDark="FabricDark",x.Highcontrast="Highcontrast",x.Fluent2="Fluent2",x.Fluent2Dark="Fluent2Dark",(x=v.ImageEditorCommand||(v.ImageEditorCommand={})).Crop="Crop",x.Transform="Transform",x.Annotate="Annotate",x.ZoomIn="ZoomIn",x.ZoomOut="ZoomOut",x.Open="Open",x.Reset="Reset",x.Save="Save",x.Pan="Pan",x.Move="Move",x.Pen="Pen",x.Line="Line",x.Arrow="Arrow",x.Path="Path",x.Rectangle="Rectangle",x.Image="Image",x.Ellipse="Ellipse",x.Text="Text",x.CustomSelection="CustomSelection",x.CircleSelection="CircleSelection",x.SquareSelection="SquareSelection",x.RatioSelection="RatioSelection",x.RotateLeft="RotateLeft",x.RotateRight="RotateRight",x.FlipHorizontal="FlipHorizontal",x.FlipVertical="FlipVertical",x.Undo="Undo",x.Redo="Redo",x.None="None",x.Mat="Mat",x.Bevel="Bevel",x.Inset="Inset",x.Hook="Hook",x.Finetune="Finetune",x.Filter="Filter",x.Frame="Frame",x.Resize="Resize",x.HorizontalFlip="HorizontalFlip",x.VerticalFlip="VerticalFlip",x.Brightness="Brightness",x.Contrast="Contrast",x.Hue="Hue",x.Saturation="Saturation",x.Opacity="Opacity",x.Blur="Blur",x.Exposure="Exposure",x.Default="Default",x.Chrome="Chrome",x.Cold="Cold",x.Warm="Warm",x.Grayscale="Grayscale",x.Sepia="Sepia",x.Invert="Invert",x.Straightening="Straightening",(x=v.ImageFilterOption||(v.ImageFilterOption={})).Default="Default",x.Chrome="Chrome",x.Cold="Cold",x.Warm="Warm",x.Grayscale="Grayscale",x.Sepia="Sepia",x.Invert="Invert",(x=v.ImageFinetuneOption||(v.ImageFinetuneOption={})).Brightness="Brightness",x.Contrast="Contrast",x.Hue="Hue",x.Saturation="Saturation",x.Exposure="Exposure",x.Opacity="Opacity",x.Blur="Blur",(x=v.ArrowheadType||(v.ArrowheadType={})).None="None",x.Arrow="Arrow",x.SolidArrow="SolidArrow",x.Circle="Circle",x.SolidCircle="SolidCircle",x.Square="Square",x.SolidSquare="SolidSquare",x.Bar="Bar",(x=v.FrameType||(v.FrameType={})).None="None",x.Mat="Mat",x.Bevel="Bevel",x.Line="Line",x.Inset="Inset",x.Hook="Hook",(x=v.FrameLineStyle||(v.FrameLineStyle={})).Solid="Solid",x.Dashed="Dashed",x.Dotted="Dotted";Y.prototype.destroy=function(){this.parent.isDestroyed||this.removeEventListener()},Y.prototype.addEventListener=function(){this.parent.on("toolbar",this.toolbar,this),this.parent.on("destroyed",this.destroy,this)},Y.prototype.removeEventListener=function(){this.parent.off("toolbar",this.toolbar),this.parent.off("destroyed",this.destroy)},Y.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 O.L10n("image-editor",this.defaultLocale,this.parent.locale)},Y.prototype.toolbar=function(e){var t=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":(O.isNullOrUndefined(t.toolbar)||t.toolbar&&0<t.toolbar.length&&-1<t.toolbar.indexOf("Open"))&&(this.toolbarHeight=e.value.height);break;case"setCurrentToolbar":this.currentToolbar=e.value.type;break;case"setSelectedFreehandColor":this.selFhdColor=e.value.color;break;case"setInitialAdjustmentValue":t.initialAdjustmentValue=e.value.value;break;case"getCanvasFilter":e.value.obj.canvasFilter=t.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":t.setTempFilterProperties();break;case"refreshSlider":this.refreshSlider();break;case"getCurrAdjustmentValue":t.getCurrAdjustmentValue(e.value.type);break;case"setCurrAdjustmentValue":t.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)}},Y.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"))},Y.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},Y.prototype.destroyTopToolbar=function(){var e=this.parent,e=document.getElementById(e.element.id+"_toolbar");this.isToolbar()&&e&&e.classList.contains("e-control")&&O.getComponent(e,"toolbar").destroy()},Y.prototype.destroyBottomToolbar=function(){var e=this.parent,e=document.getElementById(e.element.id+"_bottomToolbar");e&&e.classList.contains("e-control")&&O.getComponent(e,"toolbar").destroy()},Y.prototype.isToolbar=function(){var e=this.parent;return O.isNullOrUndefined(e.toolbar)||e.toolbar&&0<e.toolbar.length||!O.isNullOrUndefined(e.toolbarTemplate)},Y.prototype.createToolbar=function(){var e,t,o=this,i=this.parent,r=i.element.id;O.isNullOrUndefined(i.toolbar)||i.toolbar&&0<i.toolbar.length?(i.element.appendChild(i.createElement("div",{id:r+"_toolbarArea",className:"e-toolbar-area"})),e={cssClass:"e-image-upload",align:"Left",type:"Input",tooltipText:this.l10n.getConstant("Browse"),template:new g.Uploader({allowedExtensions:".jpg, .jpeg, .png,.svg",multiple:!1})},O.isNullOrUndefined(this.defToolbarItems)&&(this.defToolbarItems=[]),this.defToolbarItems.push(e),e=document.getElementById(r+"_toolbarArea"),t=i.createElement("div",{id:r+"_toolbar"}),e.appendChild(t),e=[{cssClass:"e-image-upload",align:"Left",type:"Input",tooltipText:this.l10n.getConstant("Browse"),template:new g.Uploader({allowedExtensions:".jpg, .jpeg, .png,.svg",multiple:!1,selected:function(){var e=document.getElementById(r+"_toolbar"),t=document.getElementById(r+"_bottomToolbar");i.disabled||(O.Browser.isDevice?(0<o.defToolbarItems.length&&e&&O.getComponent(e,"toolbar").destroy(),t&&O.getComponent(t,"toolbar").destroy(),o.initMainToolbar(!1,O.Browser.isDevice,null),o.createBottomToolbar()):(0<o.defToolbarItems.length&&e&&O.getComponent(e,"toolbar").destroy(),o.initMainToolbar(!1,!1,null)))}})}],new d.Toolbar({items:e,width:"100%",created:function(){i.trigger("toolbarCreated",{toolbarType:"main"})},clicked:this.defToolbarClicked.bind(this)}).appendTo("#"+r+"_toolbar"),this.createLeftToolbarControls(),e=document.getElementById(r+"_toolbar"),t&&(this.toolbarHeight=e.clientHeight,i.toolbar)&&0<i.toolbar.length&&-1===i.toolbar.indexOf("Open")&&(t=O.getComponent(document.getElementById(i.element.id+"_toolbar"),"toolbar"))&&(t.destroy(),document.getElementById(i.element.id+"_toolbar").innerHTML="")):this.toolbarHeight=0},Y.prototype.createContextualToolbar=function(){var e,t=this.parent,o=t.element.id;(O.isNullOrUndefined(t.toolbar)||t.toolbar&&0<t.toolbar.length)&&(t.element.appendChild(t.createElement("div",{id:o+"_contextualToolbarArea",className:"e-contextual-toolbar-wrapper e-hide",attrs:{style:"position: absolute;"}})),e=document.getElementById(o+"_contextualToolbarArea"),t=t.createElement("div",{id:o+"_contextualToolbar"}),e.appendChild(t))},Y.prototype.createBottomToolbar=function(){var e,t=this.parent,o=t.element.id;t.element.querySelector("#"+o+"_bottomToolbarArea")&&t.element.querySelector("#"+o+"_bottomToolbarArea").remove(),(O.isNullOrUndefined(t.toolbar)||t.toolbar&&0<t.toolbar.length)&&(t.element.appendChild(t.createElement("div",{id:o+"_bottomToolbarArea",className:"e-bottom-toolbar"})),t.toolbarTemplate||(e=document.getElementById(o+"_bottomToolbarArea"),t=t.createElement("div",{id:o+"_bottomToolbar"}),e.appendChild(t)),this.initBottomToolbar())},Y.prototype.createQuickAccessToolbar=function(){var e,t=this.parent,o=t.element.id;t.showQuickAccessToolbar&&(e={cssClass:"e-image-upload",align:"Left",type:"Input",tooltipText:this.l10n.getConstant("Browse"),template:new g.Uploader({allowedExtensions:".jpg, .jpeg, .png,.svg",multiple:!1})},O.isNullOrUndefined(this.defToolbarItems)&&(this.defToolbarItems=[]),this.defToolbarItems.push(e),e=document.getElementById(o+"_quickAccessToolbarArea"),t=t.createElement("div",{id:o+"_quickAccessToolbar"}),e.appendChild(t),new d.Toolbar({clicked:this.defToolbarClicked.bind(this)}).appendTo("#"+o+"_quickAccessToolbar"))},Y.prototype.initMainToolbar=function(e,t,o,i,r,n){var a=this,s=this.parent,l=s.element.id;this.isToolbar()&&(i=this.getLeftToolbarItem(o,i),o=this.getRightToolbarItem(o,n),n=this.getMainToolbarItem(e,r),e=this.getZoomToolbarItem(),this.defToolbarItems=t?r?n:i.concat(o):i.concat(n,o,e),i={toolbarType:"main",toolbarItems:this.defToolbarItems},s.trigger("toolbarUpdating",i),this.defToolbarItems=i.toolbarItems,0<this.defToolbarItems.length)&&(n=new d.Toolbar({width:"100%",items:this.defToolbarItems,clicked:this.defToolbarClicked.bind(this),created:function(){t||a.renderAnnotationBtn(),a.wireZoomBtnEvents(),s.trigger("toolbarCreated",{toolbarType:"main"})}}),t&&r?n.appendTo("#"+l+"_bottomToolbar"):n.appendTo("#"+l+"_toolbar"),this.createLeftToolbarControls(),this.enableDisableTbrBtn(),this.isToolbar())&&document.getElementById(l+"_toolbar")&&O.getComponent(l+"_toolbar","toolbar").refreshOverflow()},Y.prototype.initBottomToolbar=function(){var e,t=this,o=this.parent,i=o.element.id;(O.isNullOrUndefined(o.toolbar)||o.toolbar&&0<o.toolbar.length)&&(e={toolbarType:"bottom-toolbar",toolbarItems:this.getMainToolbarItem()},o.trigger("toolbarUpdating",e),new d.Toolbar({items:e.toolbarItems,width:"100%",created:function(){t.renderAnnotationBtn(),t.renderCropBtn(),t.renderTransformBtn(),o.trigger("toolbarCreated",{toolbarType:"main"})},clicked:this.defToolbarClicked.bind(this)}).appendTo("#"+i+"_bottomToolbar"),0<this.defToolbarItems.length)&&document.getElementById(i+"_bottomToolbar")&&O.getComponent(i+"_bottomToolbar","toolbar").refreshOverflow()},Y.prototype.getLeftToolbarItem=function(e,t){for(var o=this.parent,i=o.element.id,r=[],n=(e&&!t||(O.isNullOrUndefined(o.toolbar)||o.toolbar&&-1<o.toolbar.indexOf("Open")?(r.push({id:i+"_upload",cssClass:"e-image-upload",align:"Left",type:"Input",template:new g.Uploader({allowedExtensions:".jpg, .jpeg, .png,.svg",multiple:!1})}),r.push({visible:!1,cssClass:"e-image-position e-btn e-flat",tooltipText:this.l10n.getConstant("Browse"),align:"Left"})):O.Browser.isDevice&&o.toolbar&&-1===o.toolbar.indexOf("Open")&&(r.push({visible:!1,id:i+"_upload",cssClass:"e-image-upload",align:"Left",type:"Input",template:new g.Uploader({allowedExtensions:".jpg, .jpeg, .png,.svg",multiple:!1})}),r.push({visible:!1,cssClass:"e-image-position e-btn e-flat",tooltipText:this.l10n.getConstant("Browse"),align:"Left"}))),o.allowUndoRedo&&!t&&((O.isNullOrUndefined(o.toolbar)||o.toolbar&&-1<o.toolbar.indexOf("Undo"))&&r.push({id:i+"_undo",prefixIcon:"e-icons e-undo",cssClass:"top-icon e-undo",tooltipText:this.l10n.getConstant("Undo"),align:"Left"}),O.isNullOrUndefined(o.toolbar)||o.toolbar&&-1<o.toolbar.indexOf("Redo"))&&r.push({id:i+"_redo",prefixIcon:"e-icons e-redo",cssClass:"top-icon e-redo",tooltipText:this.l10n.getConstant("Redo"),align:"Left"}),!this.preventZoomBtn&&(o.zoomSettings.zoomTrigger&v.ZoomTrigger.Toolbar)===v.ZoomTrigger.Toolbar&&!t&&((O.isNullOrUndefined(o.toolbar)||o.toolbar&&-1<o.toolbar.indexOf("ZoomOut"))&&r.push({id:i+"_zoomOut",prefixIcon:"e-icons e-zoom-out",cssClass:"top-icon e-dec-zoom",tooltipText:this.l10n.getConstant("ZoomOut"),align:"Left"}),O.isNullOrUndefined(o.toolbar)||o.toolbar&&-1<o.toolbar.indexOf("ZoomIn"))&&r.push({id:i+"_zoomIn",prefixIcon:"e-icons e-zoom-in",cssClass:"top-icon e-inc-zoom",tooltipText:this.l10n.getConstant("ZoomIn"),align:"Left"}),this.processToolbar("left")),a=0,s=n.length;a<s;a++)r.push(n[a]);return r},Y.prototype.getRightToolbarItem=function(e,t){for(var o=this.parent,i=o.element.id,r=[],n=(e&&(r.push({id:i+"_ok",prefixIcon:"e-icons e-check",cssClass:"top-icon e-tick",tooltipText:this.l10n.getConstant("OK"),align:"Right"}),r.push({id:i+"_cancel",prefixIcon:"e-icons e-close",cssClass:"top-icon e-save",tooltipText:this.l10n.getConstant("Cancel"),align:"Right"})),!t&&O.Browser.isDevice||!(O.isNullOrUndefined(o.toolbar)||o.toolbar&&-1<o.toolbar.indexOf("Reset"))||r.push({id:i+"_reset",prefixIcon:"e-icons e-btn-reset",cssClass:"top-icon e-img-reset",tooltipText:this.l10n.getConstant("Reset"),align:"Right"}),e||(O.isNullOrUndefined(o.toolbar)||o.toolbar&&-1<o.toolbar.indexOf("Save"))&&r.push({id:i+"_save",prefixIcon:"e-icons e-btn-save",cssClass:"e-caret-hide top-icon e-save",tooltipText:this.l10n.getConstant("Save"),align:"Right"}),this.processToolbar("right")),a=0,s=n.length;a<s;a++)r.push(n[a]);return r},Y.prototype.getMainToolbarItem=function(e,t){for(var o=this.parent,i=o.element.id,r=[],n=(t?((O.isNullOrUndefined(o.toolbar)||!O.isNullOrUndefined(o.toolbar)&&-1<o.toolbar.indexOf("None")||-1<o.toolbar.indexOf("Frame"))&&r.push({id:i+"_none",prefixIcon:"e-icons e-frame-none",cssClass:"top-icon e-frame-none",tooltipText:this.l10n.getConstant("None"),align:"Center"}),(O.isNullOrUndefined(o.toolbar)||!O.isNullOrUndefined(o.toolbar)&&-1<o.toolbar.indexOf("Mat")||-1<o.toolbar.indexOf("Frame"))&&r.push({id:i+"_mat",prefixIcon:"e-icons e-frame-mat",cssClass:"top-icon e-frame-mat",tooltipText:this.l10n.getConstant("Mat"),align:"Center"}),(O.isNullOrUndefined(o.toolbar)||!O.isNullOrUndefined(o.toolbar)&&-1<o.toolbar.indexOf("Bevel")||-1<o.toolbar.indexOf("Frame"))&&r.push({id:i+"_bevel",prefixIcon:"e-icons e-frame-bevel",cssClass:"top-icon e-frame-bevel",tooltipText:this.l10n.getConstant("Bevel"),align:"Center"}),(O.isNullOrUndefined(o.toolbar)||!O.isNullOrUndefined(o.toolbar)&&-1<o.toolbar.indexOf("Line")||-1<o.toolbar.indexOf("Frame"))&&r.push({id:i+"_line",prefixIcon:"e-icons e-frame-line",cssClass:"top-icon e-frame-line",tooltipText:this.l10n.getConstant("Line"),align:"Center"}),(O.isNullOrUndefined(o.toolbar)||!O.isNullOrUndefined(o.toolbar)&&-1<o.toolbar.indexOf("Inset")||-1<o.toolbar.indexOf("Frame"))&&r.push({id:i+"_inset",prefixIcon:"e-icons e-frame-inset",cssClass:"top-icon e-frame-inset",tooltipText:this.l10n.getConstant("Inset"),align:"Center"}),(O.isNullOrUndefined(o.toolbar)||!O.isNullOrUndefined(o.toolbar)&&-1<o.toolbar.indexOf("Hook")||-1<o.toolbar.indexOf("Frame"))&&r.push({id:i+"_hook",prefixIcon:"e-icons e-frame-hook",cssClass:"top-icon e-frame-hook",tooltipText:this.l10n.getConstant("Hook"),align:"Center"})):((O.isNullOrUndefined(o.toolbar)||o.toolbar&&-1<o.toolbar.indexOf("Crop"))&&r.push({id:i+"_cropTransform",prefixIcon:"e-icons e-crop",cssClass:"top-icon e-crop",tooltipText:this.l10n.getConstant("CropAndTransform"),align:"Center"}),(O.isNullOrUndefined(o.toolbar)||o.toolbar&&-1<o.toolbar.indexOf("Annotate"))&&r.push({id:i+"_annotation",tooltipText:this.l10n.getConstant("Annotation"),align:"Center",template:'<button id="'+i+'_annotationBtn"></button>'}),(O.isNullOrUndefined(o.toolbar)||o.toolbar&&-1<o.toolbar.indexOf("Finetune"))&&r.push({id:i+"_adjustment",prefixIcon:"e-icons e-adjustment",cssClass:"top-icon e-adjustment",tooltipText:this.l10n.getConstant("Finetune"),align:"Center"}),(O.isNullOrUndefined(o.toolbar)||o.toolbar&&-1<o.toolbar.indexOf("Filter"))&&r.push({id:i+"_filter",prefixIcon:"e-icons e-filters",cssClass:"top-icon e-filters",tooltipText:this.l10n.getConstant("Filter"),align:"Center"}),(O.isNullOrUndefined(o.toolbar)||!O.isNullOrUndefined(o.toolbar)&&-1<o.toolbar.indexOf("Frame"))&&r.push({id:i+"_frame",prefixIcon:"e-icons e-border-frame",cssClass:"top-icon e-border-frame",tooltipText:this.l10n.getConstant("Frame"),align:"Center"}),(O.isNullOrUndefined(o.toolbar)||!O.isNullOrUndefined(o.toolbar)&&-1<o.toolbar.indexOf("Resize"))&&r.push({id:i+"_resize",prefixIcon:"e-icons e-resize",cssClass:"top-icon e-resize",tooltipText:this.l10n.getConstant("Resize"),align:"Center"})),this.processToolbar("center")),a=0,s=n.length;a<s;a++)r.push(n[a]);return e&&(r.push({id:i+"_ok",prefixIcon:"e-icons e-check",cssClass:"top-icon e-tick",tooltipText:this.l10n.getConstant("OK"),align:"Right"}),r.push({id:i+"_cancel",prefixIcon:"e-icons e-close",cssClass:"top-icon e-save",tooltipText:this.l10n.getConstant("Cancel"),align:"Right"})),r},Y.prototype.getZoomToolbarItem=function(){return[]},Y.prototype.updateContextualToolbar=function(e,t,o){var i,r=this.parent,n=r.element.id,a=r.element.querySelector("#"+n+"_toolbarArea"),s=r.element.querySelector("#"+n+"_contextualToolbarArea");s&&(s.classList.remove("e-hide"),s.style.left=a.offsetLeft+"px","filter"===e?((a=document.getElementById(n+"_toolbar"))&&0<this.defToolbarItems.length&&O.getComponent(a,"toolbar").destroy(),O.Browser.isDevice?this.initMainToolbar(!1,!0,!0):this.initMainToolbar(!0,null,null),this.refreshSlider(),this.initFilterToolbarItem()):((i=document.querySelector("#"+n+"_contextualToolbar")).classList.contains("e-control")&&O.getComponent(i,"toolbar").destroy(),this.refreshSlider(),"frame"===e?this.initFrameToolbarItem():this.renderSlider(t,o)),r.toolbarTemplate?this.toolbarHeight=r.element.querySelector("#"+n+"_toolbarArea").clientHeight:r.element.querySelector("#"+n+"_toolbar")&&(this.toolbarHeight=r.element.querySelector("#"+n+"_toolbar").clientHeight),r.toolbarHeight=this.toolbarHeight,O.Browser.isDevice?(a=s.offsetHeight+1,e=r.element.querySelector("#"+n+"_customizeWrapper"),this.isFrameToolbar&&e&&(a=e.offsetHeight+2),e=r.element.querySelector("#"+n+"_canvasWrapper").offsetHeight,s.style.top=this.toolbarHeight+1+e-a+"px","straighten"===t&&(r.isStraightening=!0,"absolute"===(i=r.element.querySelector("#"+n+"_contextualToolbarArea")).style.position)&&(i.style.position="",r.element.insertBefore(i,r.element.querySelector("#"+n+"_bottomToolbarArea")),r.update(),o)&&r.notify("draw",{prop:"select",onPropertyChange:!1,value:{type:this.getCropTextContent(document.getElementById(n+"_cropBtn")).toLowerCase(),startX:null,startY:null,width:null,height:null}})):s.style.top=this.toolbarHeight+1+"px")},Y.prototype.processToolbar=function(e){var t=this.parent,o=[];if(t.toolbar)for(var i=0,r=t.toolbar.length;i<r;i++)"object"==typeof t.toolbar[i]&&(O.isNullOrUndefined(t.toolbar[i].align)?"left"===e&&o.push(t.toolbar[i]):t.toolbar[i].align.toLowerCase()===e&&o.push(t.toolbar[i]));return o},Y.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},Y.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)))},Y.prototype.widthPress=function(e){109===e.keyCode&&e.preventDefault()},Y.prototype.heightPress=function(e){109===e.keyCode&&e.preventDefault()},Y.prototype.widthAspectRatio=function(e){var t,o,i,r,n;109!==e.keyCode&&(o=(e=this.parent).element.id,n=e.element.querySelector("#"+o+"_resizeHeight"),t=e.element.querySelector("#"+o+"_resizeWidth"),o=e.element.querySelector("#"+o+"_aspectratio"),r=e.img.destWidth,i=e.img.destHeight,i=.5<=(n=parseFloat(n.value)/(i/r))%1||n%1<=-.5?Math.round(n):n<0?Math.ceil(n):Math.floor(n),r=O.getComponent(t,"numerictextbox"),n=O.getComponent(t,"numerictextbox"),o)&&(null==i||isNaN(i)?O.isNullOrUndefined(r.value)?(r.placeholder="0 px",t.placeholder="0 px",O.isNullOrUndefined(n.value)&&!O.isNullOrUndefined(n.placeholder)&&(r.placeholder=""+e.img.srcWidth,t.placeholder=""+e.img.srcWidth)):(r.value=0,t.value="0 px"):O.isNullOrUndefined(r.value)?(r.placeholder=i+" px",t.placeholder=i.toString()+" px"):(r.value=i,t.value=i.toString()+" px"))},Y.prototype.heightAspectRatio=function(e){var t,o,i,r,n;109!==e.keyCode&&(o=(e=this.parent).element.id,t=e.element.querySelector("#"+o+"_resizeHeight"),n=e.element.querySelector("#"+o+"_resizeWidth"),o=e.element.querySelector("#"+o+"_aspectratio"),r=e.img.destWidth,i=e.img.destHeight,i=.5<=(r=parseFloat(n.value)/(r/i))%1||r%1<=-.5?Math.round(r):r<0?Math.ceil(r):Math.floor(r),r=O.getComponent(t,"numerictextbox"),n=O.getComponent(n,"numerictextbox"),o)&&(isNaN(i)?O.isNullOrUndefined(r.value)?(r.placeholder="0 px",t.placeholder="0 px",O.isNullOrUndefined(n.value)&&!O.isNullOrUndefined(n.placeholder)&&(r.placeholder=""+e.img.srcHeight,t.placeholder=""+e.img.srcHeight)):(r.value=0,t.value="0 px"):O.isNullOrUndefined(r.value)?(r.placeholder=i+" px",t.placeholder=i.toString()+" px"):(r.value=i,t.value=i.toString()+" px"))},Y.prototype.getResizeToolbarItem=function(){var e=this.parent,t=e.element.id,o=!(!e.aspectWidth||!e.aspectHeight),i=(this.parent.transform.degree%90==0&&this.parent.transform.degree%180!=0?Math.ceil(this.parent.img.srcHeight):Math.ceil(this.parent.img.srcWidth)).toString(),r=(this.parent.transform.degree%90==0&&this.parent.transform.degree%180!=0?Math.ceil(this.parent.img.srcWidth):Math.ceil(this.parent.img.srcHeight)).toString(),n=[],a=document.createElement("span"),a=(a.innerHTML=this.l10n.getConstant("W"),n.push({id:t+"_width",cssClass:"e-ie-resize-width",template:a,align:"Center"}),n.push({id:t+"_resizeWidth",prefixIcon:"e-icons e-anti-clock-wise",tooltipText:this.l10n.getConstant("Width"),align:"Center",type:"Input",template:new g.NumericTextBox({width:75,htmlAttributes:{maxLength:"4"},showSpinButton:!1,value:o?e.aspectWidth:null,placeholder:o?null:i,format:"###.## px"})}),document.createElement("span"));return a.innerHTML=this.l10n.getConstant("H"),n.push({id:t+"_height",cssClass:"e-ie-resize-height",template:a,align:"Center"}),n.push({id:t+"_resizeHeight",prefixIcon:"e-icons e-clock-wise",tooltipText:this.l10n.getConstant("Height"),align:"Center",type:"Input",template:new g.NumericTextBox({width:75,htmlAttributes:{maxLength:"4"},showSpinButton:!1,value:o?e.aspectHeight:null,placeholder:o?null:r,format:"###.## px"})}),this.isAspectRatio?(n.push({id:t+"_nonaspectratio",prefixIcon:"e-icons e-unlock",align:"Center",tooltipText:this.l10n.getConstant("AspectRatio"),type:"Button"}),this.isAspectRatio=!1):(n.push({id:t+"_aspectratio",prefixIcon:"e-icons e-lock",align:"Center",tooltipText:this.l10n.getConstant("AspectRatio"),type:"Button"}),this.isAspectRatio=!0),O.Browser.isDevice||(n.push({id:t+"_ok",prefixIcon:"e-icons e-check",cssClass:"top-icon e-tick",tooltipText:this.l10n.getConstant("OK"),align:"Right"}),n.push({id:t+"_cancel",prefixIcon:"e-icons e-close",cssClass:"top-icon e-save",tooltipText:this.l10n.getConstant("Cancel"),align:"Right"})),n},Y.prototype.initResizeToolbar=function(){var e=this,t=this.parent,o=t.element.id,i=this.getLeftToolbarItem(!1,!0),r=this.getRightToolbarItem(),n=this.getResizeToolbarItem(),a=this.getZoomToolbarItem(),i=(O.Browser.isDevice?this.defToolbarItems=n:this.defToolbarItems=i.concat(a,n,r),{toolbarType:"resize",toolbarItems:this.defToolbarItems}),s=(t.trigger("toolbarUpdating",i),this.defToolbarItems=i.toolbarItems,new d.Toolbar({width:"100%",items:this.defToolbarItems,clicked:this.defToolbarClicked.bind(this),created:function(){e.wireResizeBtnEvents(),t.trigger("toolbarCreated",{toolbarType:"shapes"}),O.Browser.isDevice?0<e.defToolbarItems.length&&!O.isNullOrUndefined(document.getElementById(o+"_bottomToolbar"))&&s.refreshOverflow():(e.createLeftToolbarControls(),0<e.defToolbarItems.length&&!O.isNullOrUndefined(document.getElementById(o+"_toolbar"))&&s.refreshOverflow())}}));O.Browser.isDevice?s.appendTo("#"+o+"_bottomToolbar"):s.appendTo("#"+o+"_toolbar"),t.isResize=!1,this.enableDisableTbrBtn(),t.isResize=!0,t.notify("transform",{prop:"disableZoomOutBtn",value:{isZoomOut:!0}})},Y.prototype.wireResizeBtnEvents=function(){var e=this.parent,t=e.element.id,o=e.element.querySelector("#"+t+"_resizeHeight"),e=e.element.querySelector("#"+t+"_resizeWidth");O.isNullOrUndefined(o)||(o.addEventListener("keydown",this.widthPress.bind(this)),e.addEventListener("keyup",this.heightAspectRatio.bind(this))),O.isNullOrUndefined(e)||(e.addEventListener("keydown",this.heightPress.bind(this)),o.addEventListener("keyup",this.widthAspectRatio.bind(this)))},Y.prototype.enableDisableTbrBtn=function(){var e=this.parent,t=e.element.id,o=(this.preventEnableDisableUr||(e.notify("undo-redo",{prop:"getAppliedUndoRedoColl",value:{obj:o={appliedUndoRedoColl:[]}}}),e.notify("undo-redo",{prop:"getUndoRedoStep",value:{obj:i={undoRedoStep:null}}}),(r=e.element.querySelector("#"+t+"_undo"))&&0===i.undoRedoStep?(r.classList.add("e-disabled"),r.parentElement.classList.add("e-overlay")):r&&0<i.undoRedoStep&&(r.classList.remove("e-disabled"),r.parentElement.classList.remove("e-overlay")),(r=e.element.querySelector("#"+t+"_redo"))&&i.undoRedoStep===o.appliedUndoRedoColl.length?(r.classList.add("e-disabled"),r.parentElement.classList.add("e-overlay")):(r&&0===i.undoRedoStep&&0<o.appliedUndoRedoColl.length||r&&0<i.undoRedoStep)&&(r.classList.remove("e-disabled"),r.parentElement.classList.remove("e-overlay"))),document.querySelector("#"+t+"_zoomIn")),i=(o&&e.zoomSettings.zoomFactor>=e.zoomSettings.maxZoomFactor?(o.classList.add("e-disabled"),o.parentElement.classList.add("e-overlay")):o&&(o.classList.remove("e-disabled"),o.parentElement.classList.remove("e-overlay")),document.querySelector("#"+t+"_zoomOut")),r=(i&&e.zoomSettings.zoomFactor<=e.zoomSettings.minZoomFactor?(i.classList.add("e-disabled"),i.parentElement.classList.add("e-overlay")):i&&(i.classList.remove("e-disabled"),i.parentElement.classList.remove("e-overlay")),document.querySelector("#"+t+"_frame"));r&&(e.currSelectionPoint&&"crop-circle"===e.currSelectionPoint.shape||e.isCircleCrop)?r.classList.add("e-disabled"):r&&r.classList.remove("e-disabled")},Y.prototype.createLeftToolbarControls=function(){var e,t=this.parent,o=t.element.id;void 0!==this.defToolbarItems&&0<this.defToolbarItems.length&&document.getElementById(o+"_toolbar")&&(o=document.getElementById(o+"_toolbar").querySelector(".e-image-upload"))&&(e=o.getElementsByTagName("input")[0],(o=o.getElementsByTagName("button")[0]).className="e-tbar-btn e-tbtn-txt top-icon",o.innerHTML="",o.appendChild(t.createElement("span",{className:"e-btn-icon e-icons e-upload-icon e-icon-left"})),e.onchange=this.fileSelect.bind(this,e))},Y.prototype.fileSelect=function(e,t){var o=e.files[0].type.split("/")[1];this.fileName=e.files[0].name.split(".")[0],this.parent.notify("toolbar",{prop:"setInitialSize",value:{value:e.files[0].size}}),-1<["png","jpg","jpeg","svg","svg+xml"].indexOf(o)?this.parent.notify("draw",{prop:"fileSelect",value:{inputElement:e,args:t}}):this.parent.showDialogPopup()},Y.prototype.triggerTbarClickEvent=function(e){e={item:e.item,originalEvent:e.event};this.parent.trigger("toolbarItemClicked",e)},Y.prototype.renderAnnotationBtn=function(e){var s=this,l=this.parent,t=!1,o=[],p=l.element.id,i=["Ellipse","Arrow","Line","Rectangle","Pen","Path","Text","Image"];if(l.toolbar)for(var r=0;r<i.length;r++)if(-1!==l.toolbar.indexOf(i[r])){t=!0;break}(O.isNullOrUndefined(l.toolbar)||!t||l.toolbar&&-1<l.toolbar.indexOf("Pen"))&&o.push({text:this.l10n.getConstant("Pen"),id:"pen",iconCss:"e-icons e-free-pen"}),(O.isNullOrUndefined(l.toolbar)||!t||l.toolbar&&-1<l.toolbar.indexOf("Line"))&&o.push({text:this.l10n.getConstant("Line"),id:"line",iconCss:"e-icons e-line"}),(O.isNullOrUndefined(l.toolbar)||!t||l.toolbar&&-1<l.toolbar.indexOf("Rectangle"))&&o.push({text:this.l10n.getConstant("Rectangle"),id:"rectangle",iconCss:"e-icons e-rectangle"}),(O.isNullOrUndefined(l.toolbar)||!t||l.toolbar&&-1<l.toolbar.indexOf("Ellipse"))&&o.push({text:this.l10n.getConstant("Ellipse"),id:"ellipse",iconCss:"e-icons e-circle"}),(O.isNullOrUndefined(l.toolbar)||!t||l.toolbar&&-1<l.toolbar.indexOf("Arrow"))&&o.push({text:this.l10n.getConstant("Arrow"),id:"arrow",iconCss:"e-icons e-arrow-right-up"}),(O.isNullOrUndefined(l.toolbar)||!t||l.toolbar&&-1<l.toolbar.indexOf("Path"))&&o.push({text:this.l10n.getConstant("Path"),id:"path",iconCss:"e-icons e-critical-path"}),(O.isNullOrUndefined(l.toolbar)||!t||l.toolbar&&-1<l.toolbar.indexOf("Text"))&&o.push({text:this.l10n.getConstant("Text"),id:"text",iconCss:"e-icons e-add-text"}),(O.isNullOrUndefined(l.toolbar)||!t||l.toolbar&&-1<l.toolbar.indexOf("Image"))&&o.push({text:this.l10n.getConstant("Image"),id:"image",iconCss:"e-icons e-image"});var n={freehandDrawSelectedId:null},a=(l.notify("freehand-draw",{prop:"getFreehandDrawSelectedId",onPropertyChange:!1,value:{obj:n}}),document.querySelector("#"+p+"_duplicate")),h=document.querySelector("#"+p+"_remove"),d=document.querySelector("#"+p+"_editText"),c=document.querySelector("#"+p+"_zOrderBtn"),n=(0===l.activeObj.activePoint.width&&0===l.activeObj.activePoint.height&&(O.isNullOrUndefined(l.activeObj.pointColl)||l.activeObj.pointColl&&0===l.activeObj.pointColl.length)&&O.isNullOrUndefined(n.freehandDrawSelectedId)?(a&&a.classList.add("e-disabled"),h&&h.classList.add("e-disabled"),d&&d.classList.add("e-disabled"),c&&c.classList.add("e-disabled")):(a&&a.classList.remove("e-disabled"),h&&h.classList.remove("e-disabled"),d&&d.classList.remove("e-disabled"),c&&c.classList.remove("e-disabled")),e?this.getCurrentShapeIcon(l.activeObj.shape):"e-annotation"),u=new f.DropDownButton({items:o,iconCss:"e-icons "+n,cssClass:"e-image-popup",open:function(e){l.currObjType.isFiltered&&(l.okBtn(),l.element.querySelector("#"+p+"_annotationBtn").click()),O.Browser.isDevice&&(e.element.parentElement.style.top=u.element.getBoundingClientRect().top-e.element.parentElement.offsetHeight+"px"),l.activeObj.shape?document.getElementById(l.activeObj.shape).classList.add("e-selected"):l.togglePen&&document.getElementById("pen").classList.add("e-selected")},select:function(e){l.noPushUndo=!1,s.triggerTbarClickEvent(e),l.okBtn();var t,o,i=!1,r=((void 0===(a=void 0!==l.activeObj.shape?l.activeObj.shape.split("-"):a)&&l.currObjType.isCustomCrop||void 0!==a&&"crop"===a[0])&&(i=!0),l.currObjType.isCustomCrop=!1,(i||l.togglePan)&&(l.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),s.upperContext.clearRect(0,0,l.upperCanvas.width,l.upperCanvas.height),s.refreshToolbar("main")),{currentFreehandDrawIndex:null}),n=(l.notify("freehand-draw",{prop:"getCurrentFreehandDrawIndex",value:{obj:r}}),{shapeSettingsObj:{}});switch(u.iconCss="e-icons "+s.getCurrentShapeIcon(e.item.id),l.notify("draw",{prop:"updateTempObjColl"}),l.notify("draw",{prop:"updateTempPointColl"}),e.item.id){case"pen":l.drawingShape=null,l.notify("draw",{prop:"setTempFreehandCounter",value:{tempFreehandCounter:l.freehandCounter}}),l.notify("draw",{prop:"setTempCurrentFreehandDrawIndex",value:{tempCurrentFreehandDrawIndex:r.currentFreehandDrawIndex}}),s.currentToolbar="pen",l.freeHandDraw(!0),l.notify("selection",{prop:"updatePrevShapeSettings",onPropertyChange:!1,value:{obj:n}}),(t=n.shapeSettingsObj).type=v.ShapeType.FreehandDraw,l.notify("freehand-draw",{prop:"triggerShapeChanging",value:{shapeChangingArgs:o={cancel:!1,action:"insert",previousShapeSettings:t,currentShapeSettings:t}}});break;case"text":s.currentToolbar="text",l.drawingShape=e.item.id,s.currentToolbar="text",s.setInitialShapeSettings(e),l.notify("selection",{prop:"annotate",value:{shape:e.item.id}}),l.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"text",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}});break;case"image":l.drawingShape=null,s.currentToolbar="shapes",l.element.querySelector("#"+p+"_fileUpload").click();break;case"ellipse":case"arrow":case"line":case"rectangle":case"path":l.drawingShape=e.item.id,s.currentToolbar="shapes",s.setInitialShapeSettings(e),l.notify("selection",{prop:"annotate",value:{shape:e.item.id}}),l.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"shapes",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}}),l.notify("selection",{prop:"updatePrevShapeSettings",onPropertyChange:!1,value:{obj:n}}),l.trigger("shapeChanging",o={cancel:!1,action:"insert",previousShapeSettings:t=n.shapeSettingsObj,currentShapeSettings:t}),l.notify("shape",{prop:"updateShapeChangeEventArgs",value:{shapeSettings:o.currentShapeSettings}})}s.updateToolbarItems();var a=l.togglePen;"pen"===e.item.id&&(l.togglePen=!1),l.notify("draw",{prop:"redrawDownScale"}),l.togglePen=a}});u.appendTo("#"+p+"_annotationBtn")},Y.prototype.renderStraightenSlider=function(){var e=this.parent,t=e.element.id;(O.isNullOrUndefined(e.toolbar)||e.toolbar&&-1<e.toolbar.indexOf("Straightening"))&&e.element.querySelector("#"+t+"_straightenSlider")&&((e=this.createSlider(-45,45,e.cropObj.straighten,"straighten")).appendTo("#"+t+"_straightenSlider"),t=e.element.querySelector(".e-handle"))&&!O.Browser.isDevice&&(t.addEventListener("mousedown",function(e){e.preventDefault(),e.stopPropagation()}),t.addEventListener("touchstart",function(e){e.preventDefault(),e.stopPropagation()}))},Y.prototype.renderCropBtn=function(e){var t,o=this,i=this.parent,r=[],n=!1,a=["CustomSelection","CircleSelection","SquareSelection","RatioSelection"];if(i.toolbar)for(var s=0;s<a.length;s++)if(-1!==i.toolbar.indexOf(a[s])){n=!0;break}(O.isNullOrUndefined(i.toolbar)||!n||i.toolbar&&-1<i.toolbar.indexOf("CustomSelection"))&&r.push({text:this.l10n.getConstant("Custom"),id:"custom",iconCss:"e-icons e-custom"}),(O.isNullOrUndefined(i.toolbar)||!n||i.toolbar&&-1<i.toolbar.indexOf("CircleSelection"))&&r.push({text:this.l10n.getConstant("Circle"),id:"circle",iconCss:"e-icons e-circle"}),(O.isNullOrUndefined(i.toolbar)||!n||i.toolbar&&-1<i.toolbar.indexOf("SquareSelection"))&&r.push({text:this.l10n.getConstant("Square"),id:"square",iconCss:"e-icons e-square"}),(O.isNullOrUndefined(i.toolbar)||!n||i.toolbar&&-1<i.toolbar.indexOf("RatioSelection"))&&(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 e=e?(t=this.getCurrentShapeIcon(e),e):i.activeObj.shape&&(0!==i.activeObj.activePoint.width||0!==i.activeObj.activePoint.height)||"path"===i.activeObj.shape&&0<i.activeObj.pointColl.length?(t=this.getCurrentShapeIcon(i.activeObj.shape),i.activeObj.shape):i.currSelectionPoint?(t=this.getCurrentShapeIcon(i.currSelectionPoint.shape),i.currSelectionPoint.shape):(t=r[0].iconCss,r[0].id),l=new f.DropDownButton({open:function(e){i.togglePan&&o.cancelPan(),O.Browser.isDevice&&(e.element.parentElement.style.top=l.element.getBoundingClientRect().top-e.element.parentElement.offsetHeight+"px"),i.activeObj.shape&&1<i.activeObj.shape.split("-").length&&(e=document.getElementById(i.activeObj.shape.split("-")[1]))&&(e.classList.add("e-selected"),e.focus()),i.notify("transform",{prop:"disableZoomOutBtn",value:{isZoomOut:!0}})},items:r,select:function(e){o.triggerTbarClickEvent(e),o.cropSelect(e),l.iconCss="e-icons "+o.getCurrentShapeIcon("crop-"+e.item.id),l.content=O.Browser.isDevice?null:i.toPascalCase(e.item.id)},iconCss:"e-icons "+t,cssClass:"e-image-popup e-ie-crop-ddb-popup",content:O.Browser.isDevice?null:i.toPascalCase(e.replace("crop-",""))});l.appendTo("#"+i.element.id+"_cropBtn")},Y.prototype.renderTransformBtn=function(){var t=this,o=this.parent,e=[],i=((O.isNullOrUndefined(o.toolbar)||o.toolbar&&-1<o.toolbar.indexOf("RotateLeft"))&&e.push({text:this.l10n.getConstant("RotateLeft"),id:"rotateleft",iconCss:"e-icons e-anti-clock-wise"}),(O.isNullOrUndefined(o.toolbar)||o.toolbar&&-1<o.toolbar.indexOf("RotateRight"))&&e.push({text:this.l10n.getConstant("RotateRight"),id:"rotateright",iconCss:"e-icons e-clock-wise"}),(O.isNullOrUndefined(o.toolbar)||o.toolbar&&-1<o.toolbar.indexOf("FlipHorizontal"))&&e.push({text:this.l10n.getConstant("HorizontalFlip"),id:"horizontalflip",iconCss:"e-icons e-horizontal-flip"}),(O.isNullOrUndefined(o.toolbar)||o.toolbar&&-1<o.toolbar.indexOf("FlipVertical"))&&e.push({text:this.l10n.getConstant("VerticalFlip"),id:"verticalflip",iconCss:"e-icons e-vertical-flip"}),new f.DropDownButton({open:function(e){var t;O.Browser.isDevice&&(t=(e=e.element.parentElement).offsetHeight,e.style.display="none",e.style.top=i.element.getBoundingClientRect().top-t+"px",e.style.display="block")},items:e,select:function(e){t.triggerTbarClickEvent(e),o.transformSelect.bind(t)},iconCss:"e-icons e-transform",cssClass:"e-image-popup"}));i.appendTo("#"+o.element.id+"_transformBtn")},Y.prototype.saveDialogPopup=function(){var i=this,e=this.parent,r=e.element.id,t=(e.element.appendChild(e.createElement("div",{id:r+"_saveDialog"})),e.createElement("div",{id:r+"_dialogContent",attrs:{style:"display: flex;"}})),o=t.appendChild(e.createElement("div",{id:r+"_dialogImgContent",className:"e-ie-dlg-img-content"}));o.appendChild(e.createElement("canvas",{id:r+"_imgPic",className:"e-ie-img-dlg-canvas"}));o.appendChild(e.createElement("div",{id:r+"_imageNameContainer",className:"e-ie-img-size"})).appendChild(e.createElement("span",{id:r+"_imageNameLabel",className:"e-ie-quality-info"}));var o=t.appendChild(e.createElement("div",{id:r+"_dialogRightContent",className:"e-ie-dlg-right-content"})),n=o.appendChild(e.createElement("div",{id:r+"_namediv",className:"e-ie-img-save-name"})),n=(n.appendChild(e.createElement("span",{id:r+"_labelImgname",className:"e-ie-img-label-name",innerHTML:this.l10n.getConstant("ImageName")})),n.appendChild(e.createElement("input",{id:r+"_imgNametext",className:"e-ie-img-input",attrs:{type:"text"}})),o.appendChild(e.createElement("div",{id:r+"_imgNamediv",className:"e-ie-img-save-dlg"}))),n=(n.appendChild(e.createElement("span",{id:r+"_labelname",className:"e-ie-img-label-name",innerHTML:this.l10n.getConstant("Format")})),n.appendChild(e.createElement("button",{id:r+"_saveDropdownbtn",attrs:{tabindex:"1"}})),o.appendChild(e.createElement("div",{id:r+"_imgQualitydiv",className:"e-ie-img-quality-name"}))),o=e.createElement("div",{id:r+"_qualityContainer"});o.appendChild(e.createElement("span",{id:r+"_qualityLabel",className:"e-ie-img-quality-label",innerHTML:this.l10n.getConstant("Quality")})),o.appendChild(e.createElement("span",{id:r+"_qualityInfo",className:"e-circle-info e-icons e-ie-quality-span",attrs:{title:this.l10n.getConstant("QualityInfo")}}));o.appendChild(e.createElement("div",{id:r+"_imgsizeSpan",className:"e-ie-img-size-value-span"})).appendChild(e.createElement("span",{id:r+"_imgsizeValueSpan",className:""})),n.appendChild(o);var o=e.createElement("div",{id:r+"_qualityOptionContainer",className:"e-ie-quality-option-container"}),a=n.appendChild(e.createElement("div",{id:r+"_qualityButtonGroup",className:"e-btn-group"})),s=(["Good","Great","Highest"].forEach(function(e){var t=document.createElement("input"),o=(t.type="radio",t.id=r+"_"+e.toLowerCase(),t.name="quality",t.value=e.toLowerCase(),document.createElement("label"));o.className="e-btn",o.htmlFor=e.toLowerCase(),o.textContent=i.l10n.getConstant(e),a.appendChild(t),a.appendChild(o)}),o.appendChild(a),o.appendChild(e.createElement("div",{id:r+"_qualitySlider",className:"e-ie-img-quality-slider"})),o.appendChild(e.createElement("button",{id:r+"_qualitybuttonIcon",className:"e-ie-img-icon-button",attrs:{type:"button"}})),n.appendChild(o),O.Browser.isDevice&&n.appendChild(e.createElement("span",{id:r+"_qualitySize",className:"e-ie-img-quality-size"})),e.element.querySelector("#"+r+"_saveDialog").style.display="block",e.element.appendChild(t),new u.Dialog({target:e.element,header:this.l10n.getConstant("SaveAs"),closeOnEscape:!0,content:document.getElementById(r+"_dialogContent"),width:O.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(){s.hide()},buttonModel:{content:this.l10n.getConstant("Close"),cssClass:"e-save-cancel-btn"}},{click:function(){i.download(),s.hide(),i.isSlider=!1},buttonModel:{isPrimary:!0,content:this.l10n.getConstant("Download"),cssClass:"e-flat e-save-download-btn"}}]}));s.appendTo("#"+r+"_saveDialog")},Y.prototype.saveDialogClosed=function(e){O.getComponent(document.getElementById(e+"_saveDropdownbtn"),"dropdownbutton")&&O.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(),O.getComponent(document.getElementById(e+"_saveDialog"),"dialog").destroy(),document.getElementById(e+"_saveDialog").remove()},Y.prototype.onBeforeopen=function(){var t=this,e=this.parent,o=e.element.id,i={canvas:null},r=(new g.TextBox({placeholder:this.l10n.getConstant("ImageName")}).appendTo("#"+o+"_imgNametext"),document.getElementById(o+"_imgQualitydiv")),n=document.getElementById(o+"_qualitySlider"),a=document.querySelector("#"+o+"_qualityButtonGroup"),s=document.querySelector("#"+o+"_qualitybuttonIcon"),l=document.querySelector("#"+o+"_imgsizeSpan"),p=O.Browser.isDevice?document.getElementById(o+"_qualitySize"):document.getElementById(o+"_imageNameLabel"),h={fileName:"",fileType:""},e=(e.notify("draw",{prop:"getFileName",onPropertyChange:!1,value:{obj:h}}),this.fileType=h.fileType,e.notify("export",{prop:"exportToCanvas",value:{object:i}}),i.canvas),d=document.getElementById(o+"_imgPic");d.width=e.width,d.height=e.height;new L.Button({iconCss:"e-icons e-settings"}).appendTo("#"+o+"_qualitybuttonIcon");var c,u,d=document.getElementById(o+"_saveDropdownbtn");d&&((c=document.createElement("span")).innerHTML=h.fileType.toUpperCase(),d&&d.appendChild(c),(u=new f.DropDownButton({items:[{id:"jpeg",text:"JPEG"},{id:"png",text:"PNG"},{id:"svg",text:"SVG"}],open:function(e){O.Browser.isDevice&&(e.element.parentElement.style.top=u.element.getBoundingClientRect().top-e.element.parentElement.offsetHeight+"px");var t=c.innerHTML;""!==t&&e.element.querySelector('[aria-label = "'+t+'"]').classList.add("e-selected-btn")},select:function(e){l.style.display="none",t.fileType=c.innerHTML=e.item.text,"jpeg"!==e.item.id?(r.style.display="none",p.style.display="block",1e3<t.initialSize?(e=t.initialSize/1048576,p.innerHTML=t.l10n.getConstant("ImageSize")+": "+e.toFixed(2)+" MB"):p.innerHTML=t.l10n.getConstant("ImageSize")+": "+t.initialSize.toFixed(2)+" KB",n&&(t.isSlider&&O.getComponent(n,"slider").destroy(),n.style.display="none"),t.isSlider=!1):(r.style.display="block",O.removeClass([a],"e-hide"),n.style.display="none",p.style.display="block",t.updateImageSize(O.isNullOrUndefined(t.currentQuality)?1:t.currentQuality,i.canvas),document.getElementById(o+"_"+t.imageQuality).checked=!0)}})).appendTo("#"+o+"_saveDropdownbtn"),document.getElementById(o+"_imgNametext").value=this.fileName||h.fileName,"JPEG"!==h.fileType.toUpperCase()&&(r.style.display="none",l.style.display="none"),O.Browser.isDevice&&(document.getElementById(o+"_dialogImgContent").style.display="none",document.getElementById(o+"_dialogRightContent").style.width="100%"),this.updateImageSize(1,i.canvas)),document.getElementById(o+"_"+this.imageQuality).checked=!0,a.addEventListener("click",this.qualityBtnClickHandler.bind(this)),s.addEventListener("click",this.qualityBtnClickHandler.bind(this))},Y.prototype.qualityBtnClickHandler=function(e){var t=this,o=this.parent,i=o.element.id,r=e.target,n={canvas:null},a={Good:.8,Great:.9,Highest:1},s=document.querySelector("#"+i+"_qualityButtonGroup"),l=document.querySelector("#"+i+"_qualitySlider"),p=document.querySelector("#"+i+"_qualityOptionContainer"),h=document.querySelector("#"+i+"_imgsizeSpan"),d=document.querySelector("#"+i+"_imgsizeValueSpan");o.notify("draw",{prop:"getFileName",onPropertyChange:!1,value:{obj:{fileName:""}}}),o.notify("export",{prop:"exportToCanvas",value:{object:n}}),e.currentTarget.id!==i+"_qualitybuttonIcon"||this.isSlider?e.currentTarget.id===i+"_qualitybuttonIcon"&&this.isSlider?(O.getComponent(l,"slider").destroy(),l.style.display="none",h.style.display="none",O.removeClass([s],"e-hide"),p.style.display="block",this.isSlider=!1):a.hasOwnProperty(r.textContent)&&!this.isSlider&&(e.target.previousElementSibling.checked=!0,this.currentQuality=a[r.textContent],this.imageQuality=r.textContent.toLowerCase(),this.updateImageSize(a[r.textContent],n.canvas)):(O.addClass([s],"e-hide"),l.style.display="block",h.style.display="inline-block",p.style.display="flex",(e=new g.Slider({tooltip:{placement:"Before",isVisible:!0,format:"P0",showOn:"Focus"},min:.01,max:1,step:.01,value:this.currentQuality,type:"MinRange",width:O.Browser.isDevice?"80%":"190px",created:function(){t.updateImageSize(t.currentQuality,n.canvas),d.innerHTML=Math.round(100*t.currentQuality).toString()},changed:function(e){t.currentQuality=e.value,d.innerHTML=Math.round(100*t.currentQuality).toString(),o.notify("export",{prop:"setImageQuality",value:{value:e.value}}),t.updateImageSize(e.value,n.canvas)}})).appendTo("#"+i+"_qualitySlider"),e.element.parentElement.classList.add("e-ie-quality-slider"),this.isSlider=!0)},Y.prototype.updateImageSize=function(e,t){var i,o=this.parent.element.id,r=document.getElementById(o+"_imgPic"),n=r.getContext("2d"),a=O.Browser.isDevice?document.getElementById(o+"_qualitySize"):document.getElementById(o+"_imageNameLabel");t.toBlob(function(e){var t,o;i=1e3<(i=Math.floor(e.size/1024))?(t=i/1024,a.innerHTML="Image size: "+t.toFixed(2)+" MB",+t.toFixed(2)):(a.innerHTML="Image size: "+i.toFixed(2)+" KB",+i.toFixed(2)),O.Browser.isDevice?r.style.display="none":((o=new Image).src=URL.createObjectURL(e),o.onload=function(){n.drawImage(o,0,0),URL.revokeObjectURL(o.src)}),this.fileSize=i}.bind(this),"image/jpeg",e)},Y.prototype.download=function(){var e=this.parent,t=e.element.id,o=("JPEG"===this.fileType&&this.isSlider?(o=O.getComponent(document.getElementById(t+"_qualitySlider"),"slider").value,e.notify("export",{prop:"setImageQuality",value:{value:o}})):e.notify("export",{prop:"setImageQuality",value:{value:this.currentQuality}}),document.getElementById(t+"_imgNametext").value);e.export(this.fileType,o)},Y.prototype.getCropTransformToolbarItem=function(){var e,t=this.parent,o=t.element.id,i=[];return i.push({id:o+"_crop",tooltipText:this.l10n.getConstant("CropSelection"),align:"Center",template:'<button id="'+o+'_cropBtn"></button>'}),i.push({align:"Center",type:"Separator"}),(O.isNullOrUndefined(t.toolbar)||t.toolbar&&(-1<t.toolbar.indexOf("Transform")||-1<t.toolbar.indexOf("RotateLeft")))&&i.push({id:o+"_rotateLeft",prefixIcon:"e-icons e-anti-clock-wise",tooltipText:this.l10n.getConstant("RotateLeft"),align:"Center"}),(O.isNullOrUndefined(t.toolbar)||t.toolbar&&(-1<t.toolbar.indexOf("Transform")||-1<t.toolbar.indexOf("RotateRight")))&&i.push({id:o+"_rotateRight",prefixIcon:"e-icons e-clock-wise",tooltipText:this.l10n.getConstant("RotateRight"),align:"Center"}),2<i.length&&i.push({align:"Center",type:"Separator"}),(O.isNullOrUndefined(t.toolbar)||t.toolbar&&(-1<t.toolbar.indexOf("Transform")||-1<t.toolbar.indexOf("HorizontalFlip")))&&i.push({id:o+"_horizontalFlip",prefixIcon:"e-icons e-horizontal-flip",tooltipText:this.l10n.getConstant("HorizontalFlip"),align:"Center"}),(O.isNullOrUndefined(t.toolbar)||t.toolbar&&(-1<t.toolbar.indexOf("Transform")||-1<t.toolbar.indexOf("VerticalFlip")))&&i.push({id:o+"_verticalFlip",prefixIcon:"e-icons e-vertical-flip",tooltipText:this.l10n.getConstant("VerticalFlip"),align:"Center"}),(O.isNullOrUndefined(t.toolbar)||t.toolbar&&-1<t.toolbar.indexOf("Straightening"))&&!O.Browser.isDevice&&(i.push({align:"Center",type:"Separator"}),O.isNullOrUndefined(t.toolbar)||t.toolbar&&(-1<t.toolbar.indexOf("Straighten")||-1<t.toolbar.indexOf("Straighten")))&&((e=document.createElement("span")).innerHTML=this.l10n.getConstant("Straighten"),i.push({id:o+"_straightenSpan",cssClass:"e-ie-straighten-span",template:e,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>'}),(e=document.createElement("span")).innerHTML=t.transform.straighten.toString()+"°",i.push({id:o+"_straightenSpan",cssClass:"e-ie-straighten-value-span",template:e,align:"Center"})),O.Browser.isDevice||(i.push({id:o+"_ok",prefixIcon:"e-icons e-check",cssClass:"top-icon e-tick",tooltipText:this.l10n.getConstant("OK"),align:"Right"}),i.push({id:o+"_cancel",prefixIcon:"e-icons e-close",cssClass:"top-icon e-save",tooltipText:this.l10n.getConstant("Cancel"),align:"Right"})),i},Y.prototype.getShapesToolbarItem=function(e){for(var t=this.parent,o=t.element.id,i=[],r=((O.isNullOrUndefined(t.toolbar)||t.toolbar)&&i.push({id:o+"_annotation",tooltipText:this.l10n.getConstant("Annotation"),align:"Center",template:'<button id="'+o+'_annotationBtn"></button>'}),-1<e.indexOf("fillColor")&&i.push({prefixIcon:"e-icons e-copy",id:o+"_fillcolor",cssClass:"top-icon e-fill",tooltipText:this.l10n.getConstant("FillColor"),align:"Center",type:"Input",template:'<button id="'+o+'_fillColorBtn"></button>'}),-1<e.indexOf("strokeColor")&&i.push({prefixIcon:"e-icons e-copy",id:o+"_strokecolor",cssClass:"top-icon e-stroke",tooltipText:this.l10n.getConstant("StrokeColor"),align:"Center",type:"Input",template:'<button id="'+o+'_borderColorBtn"></button>'}),-1<e.indexOf("strokeWidth")&&i.push({id:o+"_strokeWidth",cssClass:"top-icon e-size",tooltipText:"Stroke Width",align:"Center",type:"Input",template:'<button id="'+o+'_borderWidthBtn"></button>'}),-1<e.indexOf("start")&&i.push({id:o+"_start",cssClass:"top-icon e-size",tooltipText:"Start",align:"Center",type:"Input",template:'<button id="'+o+'_startBtn"></button>'}),-1<e.indexOf("end")&&i.push({id:o+"_end",cssClass:"top-icon e-size",tooltipText:"End",align:"Center",type:"Input",template:'<button id="'+o+'_endBtn"></button>'}),-1<e.indexOf("flip")&&(i.push({id:o+"_rotLeft",prefixIcon:"e-anti-clock-wise",tooltipText:this.l10n.getConstant("RotateLeft"),align:"Center"}),i.push({id:o+"_rotRight",prefixIcon:"e-clock-wise",tooltipText:this.l10n.getConstant("RotateRight"),align:"Center"}),i.push({id:o+"_hFlip",prefixIcon:"e-horizontal-flip",tooltipText:this.l10n.getConstant("HorizontalFlip"),align:"Center"}),i.push({id:o+"_vFlip",prefixIcon:"e-vertical-flip",tooltipText:this.l10n.getConstant("VerticalFlip"),align:"Center"})),-1<e.indexOf("transparency")&&(i.push({align:"Center",type:"Separator"}),i.push({id:o+"_transparency",prefixIcon:"e-opacity",tooltipText:this.l10n.getConstant("Opacity"),align:"Center"})),i.push({align:"Center",type:"Separator"}),-1<e.indexOf("z-order")&&i.push({id:o+"_zOrder",cssClass:"top-icon e-list-unordered-3",tooltipText:this.l10n.getConstant("ZOrder"),align:"Center",type:"Input",template:'<button id="'+o+'_zOrderBtn"></button>'}),-1<e.indexOf("duplicate")&&i.push({id:o+"_duplicate",prefixIcon:"e-icons e-order",cssClass:"top-icon e-order",tooltipText:this.l10n.getConstant("Duplicate"),align:"Center"}),-1<e.indexOf("remove")&&i.push({id:o+"_remove",prefixIcon:"e-icons e-trash",cssClass:"top-icon e-trash",tooltipText:this.l10n.getConstant("Remove"),align:"Center"}),-1<e.indexOf("text")&&i.push({id:o+"_editText",prefixIcon:"e-icons e-annotation-edit",cssClass:"top-icon e-annotation-edit",tooltipText:this.l10n.getConstant("EditText"),align:"Center"}),this.processSubToolbar(e)),n=0,a=r.length;n<a;n++)i.push(r[n]);return O.Browser.isDevice||(t.notify("selection",{prop:"getCurrentDrawingShape",value:{obj:e={shape:null}}}),"path"!==e.shape&&(i.push({id:o+"_ok",prefixIcon:"e-icons e-check",cssClass:"top-icon e-tick",tooltipText:this.l10n.getConstant("OK"),align:"Right"}),i.push({id:o+"_cancel",prefixIcon:"e-icons e-close",cssClass:"top-icon e-save",tooltipText:this.l10n.getConstant("Cancel"),align:"Right"}))),i},Y.prototype.initCropTransformToolbar=function(e,t){var o=this,i=this.parent,r=i.element.id,n=this.getLeftToolbarItem(),a=this.getRightToolbarItem(),s=this.getCropTransformToolbarItem(),l=this.getZoomToolbarItem(),n=(O.Browser.isDevice?this.defToolbarItems=s:this.defToolbarItems=n.concat(l,s,a),{toolbarType:"crop-transform",toolbarItems:this.defToolbarItems}),p=(i.trigger("toolbarUpdating",n),this.defToolbarItems=n.toolbarItems,new d.Toolbar({width:"100%",items:this.defToolbarItems,clicked:this.defToolbarClicked.bind(this),created:function(){o.renderCropBtn(e),o.renderStraightenSlider(),o.wireZoomBtnEvents(),i.trigger("toolbarCreated",{toolbarType:"shapes"}),O.Browser.isDevice?0<o.defToolbarItems.length&&document.getElementById(r+"_bottomToolbar")&&(p.refreshOverflow(),p.refreshOverflow(),p.refreshOverflow()):(o.createLeftToolbarControls(),0<o.defToolbarItems.length&&document.getElementById(r+"_toolbar")&&p.refreshOverflow()),document.getElementById(r+"_cropBtn")&&O.isNullOrUndefined(t)&&(O.Browser.isDevice||i.notify("draw",{prop:"select",onPropertyChange:!1,value:{type:o.getCropTextContent(document.getElementById(r+"_cropBtn")).toLowerCase(),startX:null,startY:null,width:null,height:null}}))}})),l=(O.Browser.isDevice?p.appendTo("#"+r+"_bottomToolbar"):p.appendTo("#"+r+"_toolbar"),i.element.querySelector("#"+r+"_straightenSlider"));(O.isNullOrUndefined(i.toolbar)||i.toolbar&&-1<i.toolbar.indexOf("Straightening"))&&l&&l.parentElement.clientHeight>this.toolbarHeight&&(this.toolbarHeight=i.toolbarHeight=l.parentElement.clientHeight),this.enableDisableTbrBtn(),i.notify("transform",{prop:"disableZoomOutBtn",value:{isZoomOut:!0}})},Y.prototype.getCropTextContent=function(e){if(e){var t,o={"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"},i=e.children[0].classList;for(t in o)if(i.contains(t))return o[t]}return""},Y.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]||(e&&-1!==e.indexOf("crop-")?"e-custom":"e-free-pen")},Y.prototype.initShapesToolbarItem=function(e){var t=this,o=this.parent,i=o.element.id,r=this.getLeftToolbarItem(),n=this.getRightToolbarItem(),a=this.getShapesToolbarItem(e),s=this.getZoomToolbarItem(),r=(O.Browser.isDevice?this.defToolbarItems=a:this.defToolbarItems=r.concat(s,a,n),{toolbarType:o.activeObj.shape||"shapes",toolbarItems:this.defToolbarItems}),l=(o.trigger("toolbarUpdating",r),this.isToolbarString(r.toolbarItems)?(e=r.toolbarItems,this.excludeItems(r.toolbarItems)):this.defToolbarItems=r.toolbarItems,new d.Toolbar({width:"100%",items:this.defToolbarItems,clicked:this.defToolbarClicked.bind(this),created:function(){t.renderAnnotationBtn(!0),t.createShapeColor(e),t.createShapeBtn(e),t.createZOrderBtn(e),"arrow"===o.activeObj.shape&&(e.some(function(e){return-1<e.toLowerCase().indexOf("start")})&&t.createStartBtn(),e.some(function(e){return-1<e.toLowerCase().indexOf("end")}))&&t.createEndBtn(),t.wireZoomBtnEvents(),o.trigger("toolbarCreated",{toolbarType:"shapes"}),O.Browser.isDevice?0<t.defToolbarItems.length&&document.getElementById(i+"_bottomToolbar")&&(l.refreshOverflow(),l.refreshOverflow(),l.refreshOverflow()):(t.createLeftToolbarControls(),0<t.defToolbarItems.length&&document.getElementById(i+"_toolbar")&&l.refreshOverflow())}}));O.Browser.isDevice?l.appendTo("#"+i+"_bottomToolbar"):l.appendTo("#"+i+"_toolbar"),this.enableDisableTbrBtn()},Y.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"))},Y.prototype.createShapeColor=function(e){var t,o,i,r,n=this,a=this.parent,s=a.element.id;-1<e.indexOf("fillColor")&&(a.element.querySelector(".e-template.e-fill").appendChild(a.createElement("input",{id:s+"_shape_fill"})),t=new g.ColorPicker({modeSwitcher:!0,noColor:!0,value:"",inline:!0,showButtons:!1,mode:"Palette",cssClass:"e-shape-fill-color",beforeModeSwitch:function(e){return n.beforeModeSwitch(e,t)},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){a.updateFillColor(e.value),""===e.currentValue.rgba?o.element.children[0].classList.add("e-nocolor-item"):(o.element.children[0].classList.remove("e-nocolor-item"),o.element.children[0].style.backgroundColor=e.currentValue.rgba),o.toggle(),a.notify("undo-redo",{prop:"updateUndoRedoStack",onPropertyChange:!1})},onModeSwitch:function(e){O.Browser.isDevice&&(e.element.parentElement.parentElement.style.left=n.popupLeft,e.element.parentElement.parentElement.style.top=o.element.getBoundingClientRect().top-e.element.parentElement.parentElement.offsetHeight+"px")},beforeClose:function(){o.toggle()}},"#"+s+"_shape_fill"),o=new f.DropDownButton({open:function(e){e=e.element.parentElement;O.Browser.isDevice&&(e.style.top=o.element.getBoundingClientRect().top-e.offsetHeight+"px",e.style.left=a.element.offsetLeft+"px")},target:".e-shape-fill-color",iconCss:"e-dropdownbtn-preview",cssClass:"e-ie-ddb-popup"},"#"+s+"_fillColorBtn"),t.inline=!0,t.value=t.getValue(t.value,"rgba"),a.element.querySelector(".e-fill.e-template .e-dropdownbtn-preview").classList.add("e-nocolor-item")),-1<e.indexOf("strokeColor")&&(a.element.querySelector(".e-template.e-stroke").appendChild(a.createElement("input",{id:s+"_shape_stroke"})),i=new g.ColorPicker({modeSwitcher:!0,noColor:!1,value:"#fff",inline:!0,showButtons:!1,mode:"Palette",cssClass:"e-shape-stroke-color",beforeModeSwitch:function(e){n.popupLeft=e.element.offsetParent.style.left,i.value="#fff"!==a.activeObj.strokeSettings.strokeColor?a.activeObj.strokeSettings.strokeColor:"#008000ff",n.beforeModeSwitch(e,i)},presetColors:this.presetColors,change:function(e){a.updateStrokeColor(e.value),r.element.children[0].style.backgroundColor=e.currentValue.rgba,r.toggle(),a.notify("undo-redo",{prop:"updateUndoRedoStack",onPropertyChange:!1})},onModeSwitch:function(e){O.Browser.isDevice&&(e.element.parentElement.parentElement.style.left=n.popupLeft,e.element.parentElement.parentElement.style.top=r.element.getBoundingClientRect().top-e.element.parentElement.parentElement.offsetHeight+"px")},beforeClose:function(){r.toggle()}},"#"+s+"_shape_stroke"),r=new f.DropDownButton({open:function(e){e=e.element.parentElement;O.Browser.isDevice&&(e.style.top=r.element.getBoundingClientRect().top-e.offsetHeight+"px",e.style.left=a.element.offsetLeft+"px")},target:".e-shape-stroke-color",iconCss:"e-dropdownbtn-preview",cssClass:"e-ie-ddb-popup"},"#"+s+"_borderColorBtn"),i.inline=!0,i.value=i.getValue(i.value,"rgba"),a.element.querySelector(".e-stroke.e-template .e-dropdownbtn-preview").style.background="#fff")},Y.prototype.createShapeBtn=function(e){var t,o,i,r=this,n=this.parent,a=n.element.id;-1<e.indexOf("strokeWidth")&&(e=[{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")}],!n.activeObj.shape||"rectangle"!==n.activeObj.shape&&"ellipse"!==n.activeObj.shape||(e=[{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")}]),t=document.getElementById(a+"_borderWidthBtn"),(o=document.createElement("span")).innerHTML=this.l10n.getConstant("XSmall"),o.className="e-shape-stroke-width",t.appendChild(o),(i=new f.DropDownButton({items:e,open:function(e){O.Browser.isDevice&&(e.element.parentElement.style.top=i.element.getBoundingClientRect().top-e.element.parentElement.offsetHeight+"px");var t=o.innerHTML;""!==t&&e.element.querySelector('[aria-label = "'+t+'"]').classList.add("e-selected-btn")},select:function(e){r.triggerTbarClickEvent(e),o.textContent=e.item.text,n.updateStrokeWidth(e.item.id),O.Browser.isDevice?document.getElementById(a+"_bottomToolbar")&&O.getComponent(a+"_bottomToolbar","toolbar").refreshOverflow():document.getElementById(a+"_toolbar")&&O.getComponent(a+"_toolbar","toolbar").refreshOverflow(),n.notify("undo-redo",{prop:"updateUndoRedoStack",onPropertyChange:!1})}})).appendTo("#"+a+"_borderWidthBtn"))},Y.prototype.createZOrderBtn=function(e){var t,o=this,i=this.parent,r=i.element.id;-1<e.indexOf("z-order")&&(e=[{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"}],(t=new f.DropDownButton({items:e,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},o=(i.notify("freehand-draw",{prop:"getFreehandSelectedIndex",onPropertyChange:!1,value:{obj:t}}),{order:null}),t=(i.notify("shape",{prop:"getHighestOrder",onPropertyChange:!1,value:{obj:o}}),i.activeObj.order||i.getObjFromId(i.pointColl[t.freehandSelectedIndex].id).order);t&&o.order<=t?(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}}),t&&t<=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){O.Browser.isDevice&&(e.element.parentElement.style.top=t.element.getBoundingClientRect().top-e.element.parentElement.offsetHeight+"px")},select:function(e){o.triggerTbarClickEvent(e);var t={freehandDrawSelectedId:null},t=(i.notify("freehand-draw",{prop:"getFreehandDrawSelectedId",onPropertyChange:!1,value:{obj:t}}),t.freehandDrawSelectedId||i.activeObj.currIndex);i.updateShapeOrder(t,e.item.id),O.Browser.isDevice?document.getElementById(r+"_bottomToolbar")&&O.getComponent(r+"_bottomToolbar","toolbar").refreshOverflow():document.getElementById(r+"_toolbar")&&O.getComponent(r+"_toolbar","toolbar").refreshOverflow(),-1<t.indexOf("shape")?i.notify("undo-redo",{prop:"updateUndoRedoStack",onPropertyChange:!1}):-1<t.indexOf("pen")&&i.notify("undo-redo",{prop:"updateUndoRedoStack",value:{isPenDraw:!0}})}})).appendTo("#"+r+"_zOrderBtn"))},Y.prototype.createStartBtn=function(){var t=this,o=this.parent,e=o.element.id,i=[{id:"1",text:this.l10n.getConstant("None")},{id:"2",text:this.l10n.getConstant("Bar")},{id:"3",text:this.l10n.getConstant("Arrow")},{id:"4",text:this.l10n.getConstant("ArrowSolid")},{id:"5",text:this.l10n.getConstant("Circle")},{id:"6",text:this.l10n.getConstant("CircleSolid")},{id:"7",text:this.l10n.getConstant("Square")},{id:"8",text:this.l10n.getConstant("SquareSolid")}],r=document.getElementById(e+"_startBtn"),n=document.createElement("span"),a=(O.isNullOrUndefined(o.activeObj.start)&&(o.activeObj.start="none"),n.innerHTML=o.pascalToSplitWords(o.activeObj.start),n.className="e-shape-start",r.appendChild(n),new f.DropDownButton({items:i,open:function(e){O.Browser.isDevice&&(e.element.parentElement.style.top=a.element.getBoundingClientRect().top-e.element.parentElement.offsetHeight+"px");var t=n.innerHTML;""!==t&&e.element.querySelector('[aria-label = "'+t+'"]').classList.add("e-selected-btn")},select:function(e){o.notify("selection",{prop:"setArrowShape",value:{type:"initial",shape:{1:"none",2:"bar",3:"arrow",4:"arrowSolid",5:"circle",6:"circleSolid",7:"square",8:"squareSolid"}[""+e.item.id]}}),t.triggerTbarClickEvent(e),n.textContent=e.item.text,o.updateArrow("startArrow",e.item.id),o.notify("undo-redo",{prop:"updateUndoRedoStack",onPropertyChange:!1})}}));a.appendTo("#"+e+"_startBtn")},Y.prototype.createEndBtn=function(){var t=this,o=this.parent,e=o.element.id,i=[{id:"1",text:this.l10n.getConstant("None")},{id:"2",text:this.l10n.getConstant("Bar")},{id:"3",text:this.l10n.getConstant("Arrow")},{id:"4",text:this.l10n.getConstant("ArrowSolid")},{id:"5",text:this.l10n.getConstant("Circle")},{id:"6",text:this.l10n.getConstant("CircleSolid")},{id:"7",text:this.l10n.getConstant("Square")},{id:"8",text:this.l10n.getConstant("SquareSolid")}],r=document.getElementById(e+"_endBtn"),n=document.createElement("span"),a=(O.isNullOrUndefined(o.activeObj.end)&&(o.activeObj.end="arrowSolid"),n.innerHTML=o.pascalToSplitWords(o.activeObj.end),n.className="e-shape-end",r.appendChild(n),new f.DropDownButton({items:i,open:function(e){O.Browser.isDevice&&(e.element.parentElement.style.top=a.element.getBoundingClientRect().top-e.element.parentElement.offsetHeight+"px");var t=n.innerHTML;""!==t&&e.element.querySelector('[aria-label = "'+t+'"]').classList.add("e-selected-btn")},select:function(e){o.notify("selection",{prop:"setArrowShape",value:{type:"final",shape:{1:"none",2:"bar",3:"arrow",4:"arrowSolid",5:"circle",6:"circleSolid",7:"square",8:"squareSolid"}[""+e.item.id]}}),t.triggerTbarClickEvent(e),n.textContent=e.item.text,o.updateArrow("endArrow",e.item.id),o.notify("undo-redo",{prop:"updateUndoRedoStack",onPropertyChange:!1})}}));a.appendTo("#"+e+"_endBtn")},Y.prototype.getTextToolbarItem=function(e){for(var t=this.parent,o=t.element.id,i=[],r=((O.isNullOrUndefined(t.toolbar)||t.toolbar)&&i.push({id:o+"_annotation",tooltipText:this.l10n.getConstant("Annotation"),align:"Center",template:'<button id="'+o+'_annotationBtn"></button>'}),-1<e.indexOf("fontFamily")&&i.push({id:o+"_fontFamily",cssClass:"top-icon e-img-font-family",tooltipText:this.l10n.getConstant("FontFamily"),align:"Center",template:'<button id="'+o+'_fontFamilyBtn"></button>'}),-1<e.indexOf("fontSize")&&i.push({id:o+"_fontSize",cssClass:"top-icon e-img-font-size",tooltipText:this.l10n.getConstant("FontSize"),align:"Center",template:'<button id="'+o+'_fontSizeBtn"></button>'}),-1<e.indexOf("fontColor")&&i.push({cssClass:"top-icon e-text-font-color",id:o+"_text_strokecolor",tooltipText:this.l10n.getConstant("FontColor"),align:"Center",type:"Input",template:'<button id="'+o+'_fontColorBtn"></button>'}),-1<e.indexOf("bold")&&i.push({id:o+"_bold",prefixIcon:"e-icons e-bold",cssClass:"top-icon e-bold",tooltipText:this.l10n.getConstant("Bold"),align:"Center"}),-1<e.indexOf("italic")&&i.push({id:o+"_italic",prefixIcon:"e-icons e-italic",cssClass:"top-icon e-italic",tooltipText:this.l10n.getConstant("Italic"),align:"Center"}),-1<e.indexOf("transparency")&&i.push({id:o+"_transparency",prefixIcon:"e-opacity",tooltipText:this.l10n.getConstant("Opacity"),align:"Center"}),i.push({align:"Center",type:"Separator"}),-1<e.indexOf("z-order")&&i.push({id:o+"_zOrder",cssClass:"top-icon e-list-unordered-3",tooltipText:this.l10n.getConstant("ZOrder"),align:"Center",type:"Input",template:'<button id="'+o+'_zOrderBtn"></button>'}),-1<e.indexOf("duplicate")&&i.push({id:o+"_duplicate",prefixIcon:"e-icons e-order",cssClass:"top-icon e-order",tooltipText:this.l10n.getConstant("Duplicate"),align:"Center",disabled:"block"===t.textArea.style.display||"inline-block"===t.textArea.style.display}),-1<e.indexOf("remove")&&i.push({id:o+"_remove",prefixIcon:"e-icons e-trash",cssClass:"top-icon e-trash",tooltipText:this.l10n.getConstant("Remove"),align:"Center",disabled:"block"===t.textArea.style.display||"inline-block"===t.textArea.style.display}),-1<e.indexOf("text")&&i.push({id:o+"_editText",prefixIcon:"e-icons e-annotation-edit",cssClass:"top-icon e-annotation-edit",tooltipText:this.l10n.getConstant("EditText"),align:"Center",disabled:"block"===t.textArea.style.display||"inline-block"===t.textArea.style.display}),this.processSubToolbar(e)),n=0,a=r.length;n<a;n++)i.push(r[n]);return O.Browser.isDevice||(i.push({id:o+"_ok",prefixIcon:"e-icons e-check",cssClass:"top-icon e-tick",tooltipText:this.l10n.getConstant("OK"),align:"Right"}),i.push({id:o+"_cancel",prefixIcon:"e-icons e-close",cssClass:"top-icon e-save",tooltipText:this.l10n.getConstant("Cancel"),align:"Right"})),i},Y.prototype.getFontFamilyItems=function(){var e=this.parent;return e.fontFamily&&e.fontFamily.items&&0<e.fontFamily.items.length?e.fontFamily.items:O.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"}]},Y.prototype.initTextToolbarItem=function(e){var t=this,o=this.parent,i=o.element.id,r=this.getLeftToolbarItem(),n=this.getRightToolbarItem(),a=this.getTextToolbarItem(e),s=this.getZoomToolbarItem(),r=(O.Browser.isDevice?this.defToolbarItems=a:this.defToolbarItems=r.concat(s,a,n),{toolbarType:"text",toolbarItems:this.defToolbarItems}),l=(o.trigger("toolbarUpdating",r),this.isToolbarString(r.toolbarItems)?(e=r.toolbarItems,this.excludeItems(r.toolbarItems)):this.defToolbarItems=r.toolbarItems,new d.Toolbar({width:"100%",items:this.defToolbarItems,clicked:this.defToolbarClicked.bind(this),created:function(){t.renderAnnotationBtn(!0),t.createTextColor(e),t.createTextBtn(e),t.createZOrderBtn(e),t.wireZoomBtnEvents(),o.trigger("toolbarCreated",{toolbarType:"text"}),O.Browser.isDevice?0<t.defToolbarItems.length&&document.getElementById(i+"_bottomToolbar")&&(l.refreshOverflow(),l.refreshOverflow(),l.refreshOverflow()):(t.createLeftToolbarControls(),0<t.defToolbarItems.length&&document.getElementById(i+"_toolbar")&&l.refreshOverflow())}}));O.Browser.isDevice?l.appendTo("#"+i+"_bottomToolbar"):l.appendTo("#"+i+"_toolbar"),this.enableDisableTbrBtn()},Y.prototype.createTextColor=function(e){var t,o,i=this,r=this.parent,n=r.element.id;-1<e.indexOf("fontColor")&&r.element.querySelector(".e-template.e-text-font-color")&&(r.element.querySelector(".e-template.e-text-font-color").appendChild(r.createElement("input",{id:n+"_text_font"})),t=new g.ColorPicker({modeSwitcher:!0,noColor:!1,value:"#fff",inline:!0,showButtons:!1,mode:"Palette",cssClass:"e-text-fontt-color",beforeModeSwitch:function(e){i.popupLeft=e.element.offsetParent.style.left,t.value="#fff"!==r.activeObj.strokeSettings.strokeColor?r.activeObj.strokeSettings.strokeColor:"#008000ff",i.beforeModeSwitch(e,t)},presetColors:this.presetColors,change:function(e){r.updateFontColor(e.value),o.element.children[0].style.backgroundColor=e.currentValue.rgba,o.toggle(),0===r.activeObj.activePoint.width&&0===r.activeObj.activePoint.height||r.notify("undo-redo",{prop:"updateUndoRedoStack",onPropertyChange:!1})},onModeSwitch:function(e){O.Browser.isDevice&&(e.element.parentElement.parentElement.style.left=i.popupLeft,e.element.parentElement.parentElement.style.top=o.element.getBoundingClientRect().top-e.element.parentElement.parentElement.offsetHeight+"px")},beforeClose:function(){o.toggle()}},"#"+n+"_text_font"),o=new f.DropDownButton({open:function(e){e=e.element.parentElement;O.Browser.isDevice&&(e.style.top=o.element.getBoundingClientRect().top-e.offsetHeight+"px",e.style.left=r.element.offsetLeft+"px")},target:".e-text-fontt-color",iconCss:"e-dropdownbtn-preview",cssClass:"e-ie-ddb-popup"},"#"+n+"_fontColorBtn"),t.inline=!0,t.value=t.getValue(t.value,"rgba"),r.element.querySelector(".e-text-font-color.e-template .e-dropdownbtn-preview").style.background="#fff")},Y.prototype.createTextBtn=function(e){var t,o,i,r,n,a=this,s=this.parent,l=s.element.id;-1<e.indexOf("fontFamily")&&(i=document.getElementById(l+"_fontFamilyBtn"),t=document.createElement("span"),O.Browser.isDevice?(t.innerHTML="ABC",t.setAttribute("style","font-family: "+s.fontFamily.default.toLowerCase()+"'")):t.innerHTML=s.fontFamily.default,t.className="e-text-font-family",i&&i.appendChild(t),(o=new f.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){O.Browser.isDevice&&(e.element.parentElement.style.top=o.element.getBoundingClientRect().top-e.element.parentElement.offsetHeight+"px"),t=("block"===s.textArea.style.display||"inline-block"===s.textArea.style.display?s.textArea.style:s.activeObj.textSettings).fontFamily;var t,e=e.element.querySelector('[id *= "'+t.toLowerCase()+'"]');e&&e.classList.add("e-selected-btn")},select:function(e){a.triggerTbarClickEvent(e),t.textContent=e.item.text,O.Browser.isDevice&&t.setAttribute("style","font-family:"+e.item.id),s.updateFontFamily(e.item.id),s.notify("undo-redo",{prop:"updateUndoRedoStack",onPropertyChange:!1})}})).appendTo("#"+l+"_fontFamilyBtn")),-1<e.indexOf("fontSize")&&(i=document.getElementById(l+"_fontSizeBtn"),r=document.createElement("span"),e=s.getFontSizes(),r.innerHTML=e[0].text,r.className="e-text-font-size",i.appendChild(r),(n=new f.DropDownButton({cssClass:"e-font-size",items:e,open:function(e){O.Browser.isDevice&&(e.element.parentElement.style.top=n.element.getBoundingClientRect().top-e.element.parentElement.offsetHeight+"px");var t=r.innerHTML;e.element.querySelector('[aria-label *= "'+t+'"]').classList.add("e-selected-btn")},select:function(e){a.triggerTbarClickEvent(e),r.textContent=e.item.text,s.updateFontSize(e.item.text),s.notify("undo-redo",{prop:"updateUndoRedoStack",onPropertyChange:!1})}})).appendTo("#"+l+"_fontSizeBtn"))},Y.prototype.refreshToolbar=function(e,t,o,i,r,n,a){var s=this.parent,l=s.element.id;if(s.isImageLoaded&&!s.isCropToolbar){var p,h,d,c,u={};switch("filter"!==e&&"color"!==e&&(h=document.getElementById(l+"_toolbar"),c=document.getElementById(l+"_customizeWrapper"),d=document.getElementById(l+"_bottomToolbar"),c&&O.getComponent(c,"toolbar")&&0<this.defToolbarItems.length&&(O.getComponent(c,"toolbar").destroy(),c.innerHTML=""),h&&h.classList.contains("e-control")&&0<this.defToolbarItems.length&&(O.getComponent(h,"toolbar").destroy(),h.innerHTML=""),h&&(0<this.defToolbarItems.length||s.toolbar&&0<s.toolbar.length&&-1===s.toolbar.indexOf("Open"))&&(c=O.getComponent(h,"toolbar"),O.isNullOrUndefined(c)||(c.destroy(),document.getElementById(s.element.id+"_toolbar").innerHTML="")),d)&&0<this.defToolbarItems.length&&-1<d.className.indexOf("e-control")&&(O.getComponent(d,"toolbar").destroy(),d.innerHTML=""),this.refreshSlider(),document.querySelector(".e-slider-tooltip")&&document.querySelector(".e-slider-tooltip").remove(),this.isFrameToolbar=s.isCropTab=!1,e){case"main":O.Browser.isDevice?o?this.initMainToolbar(!1,!0,!0,!1,!1,!0):this.initMainToolbar(!1,!0,null,!1,!1,!0):O.Browser.isDevice&&!i||this.initMainToolbar(t,O.Browser.isDevice,null),O.Browser.isDevice&&this.initBottomToolbar();break;case"shapes":s.noPushUndo=!0,O.Browser.isDevice&&this.initMainToolbar(!1,!0,!0),"line"===s.activeObj.shape||"path"===s.activeObj.shape?u.toolbarItems=["strokeColor","strokeWidth","z-order","duplicate","remove"]:"arrow"===s.activeObj.shape?u.toolbarItems=["strokeColor","strokeWidth","start","end","z-order","duplicate","remove"]:"image"===s.activeObj.shape?u.toolbarItems=["flip","z-order","duplicate","remove","transparency"]:u.toolbarItems=["fillColor","strokeColor","strokeWidth","z-order","duplicate","remove"],this.initShapesToolbarItem(u.toolbarItems);break;case"text":O.Browser.isDevice&&this.initMainToolbar(!1,!0,!0),u.toolbarItems=["fontFamily","fontSize","fontColor","bold","italic","z-order","duplicate","remove","text"],this.initTextToolbarItem(u.toolbarItems);break;case"pen":O.Browser.isDevice&&this.initMainToolbar(!1,!0,!0),u.toolbarItems=["strokeColor","strokeWidth","z-order","remove","transparency"],this.initPenToolbarItem(u.toolbarItems);break;case"adjustment":O.Browser.isDevice&&this.initMainToolbar(!1,!0,!0),this.initAdjustmentToolbarItem();break;case"filter":this.updateContextualToolbar(e);break;case"resize":(s.isCircleCrop||s.currSelectionPoint&&"crop-circle"===s.currSelectionPoint.shape)&&(s.aspectHeight=s.aspectWidth,this.isAspectRatio=!1),this.initResizeToolbar(),O.Browser.isDevice&&this.initMainToolbar(!1,!0,!0,!0),p=s.element.querySelector("#"+l+"_aspectratio"),g=s.element.querySelector("#"+l+"_nonaspectratio"),s.aspectWidth&&s.aspectHeight&&(g?s.notify("transform",{prop:"resize",value:{width:s.aspectWidth,height:s.aspectHeight,isAspectRatio:!1}}):p&&s.notify("transform",{prop:"resize",value:{width:s.aspectWidth,height:null,isAspectRatio:!0}}));break;case"color":this.updateContextualToolbar(e,r);break;case"croptransform":O.isNullOrUndefined(a)&&(s.allowDownScale=!1,s.isCropTab=!0),O.Browser.isDevice&&this.initMainToolbar(!1,!0,!0),O.isNullOrUndefined(a)&&s.updateCropTransformItems(),this.initCropTransformToolbar(n,a),O.Browser.isDevice&&this.isToolbar()&&this.updateContextualToolbar("color","straighten",!0);break;case"frame":this.isFrameToolbar=!0,O.Browser.isDevice?(this.initMainToolbar(!1,!0,!0),this.initMainToolbar(!1,!0,!0,!1,!0)):this.initMainToolbar(!0,null,null,!1,!0);var g=s.element.querySelector("#"+l+"_"+s.frameObj.type);g&&g.classList.add("e-selected-btn"),"none"!==s.frameObj.type&&this.updateContextualToolbar(e,r),s.notify("draw",{prop:"render-image",value:{isMouseWheel:null,isPreventClearRect:null,isFrame:!0}})}this.currToolbar=e,this.refreshDropDownBtn(o)}},Y.prototype.performCropTransformClick=function(e,t){var o=this.parent;O.isNullOrUndefined(t)&&(o.notify("draw",{prop:"setTempStraightenZoomDeg"}),o.tempStraighten=o.transform.straighten,o.currObjType.isFiltered&&o.okBtn(),o.isStraightening=!0),this.refreshToolbar("croptransform",null,null,null,null,e,t),O.isNullOrUndefined(t)&&(o.notify("draw",{prop:"setDestForStraighten"}),o.notify("draw",{prop:"setTempDestForStraighten"}))},Y.prototype.getAdjustmentToolbarItem=function(){var e=[],t=this.parent,o=!1,i=t.element.id,r=["Brightness","Contrast","Hue","Saturation","Exposure","Opacity","Blur"];if(t.toolbar)for(var n=0;n<r.length;n++)if(-1!==t.toolbar.indexOf(r[n])){o=!0;break}(O.isNullOrUndefined(t.toolbar)||!o||t.toolbar&&-1<t.toolbar.indexOf("Brightness"))&&e.push({id:i+"_brightness",prefixIcon:"e-icons e-brightness",cssClass:"top-icon e-brightness",tooltipText:this.l10n.getConstant("Brightness"),align:"Center"}),(O.isNullOrUndefined(t.toolbar)||!o||t.toolbar&&-1<t.toolbar.indexOf("Contrast"))&&e.push({id:i+"_contrast",prefixIcon:"e-icons e-contrast",cssClass:"top-icon e-contrast",tooltipText:this.l10n.getConstant("Contrast"),align:"Center"}),(O.isNullOrUndefined(t.toolbar)||!o||t.toolbar&&-1<t.toolbar.indexOf("Hue"))&&e.push({id:i+"_hue",prefixIcon:"e-icons e-fade",cssClass:"top-icon e-fade",tooltipText:this.l10n.getConstant("Hue"),align:"Center"}),(O.isNullOrUndefined(t.toolbar)||!o||t.toolbar&&-1<t.toolbar.indexOf("Saturation"))&&e.push({id:i+"_saturation",prefixIcon:"e-icons e-saturation",cssClass:"top-icon e-saturation",tooltipText:this.l10n.getConstant("Saturation"),align:"Center"}),(O.isNullOrUndefined(t.toolbar)||!o||t.toolbar&&-1<t.toolbar.indexOf("Exposure"))&&e.push({id:i+"_exposure",prefixIcon:"e-icons e-grain",cssClass:"top-icon e-grain",tooltipText:this.l10n.getConstant("Exposure"),align:"Center"}),(O.isNullOrUndefined(t.toolbar)||!o||t.toolbar&&-1<t.toolbar.indexOf("Opacity"))&&e.push({id:i+"_opacity",prefixIcon:"e-icons e-opacity",cssClass:"top-icon e-opacity",tooltipText:this.l10n.getConstant("Opacity"),align:"Center"}),(O.isNullOrUndefined(t.toolbar)||!o||t.toolbar&&-1<t.toolbar.indexOf("Blur"))&&e.push({id:i+"_blur",prefixIcon:"e-icons e-tint",cssClass:"top-icon e-tint",tooltipText:this.l10n.getConstant("Blur"),align:"Center"});for(var a=this.processToolbar("center"),n=0,s=a.length;n<s;n++)e.push(a[n]);return O.Browser.isDevice||(e.push({id:i+"_ok",prefixIcon:"e-icons e-check",cssClass:"top-icon e-tick",tooltipText:this.l10n.getConstant("OK"),align:"Right"}),e.push({id:i+"_cancel",prefixIcon:"e-icons e-close",cssClass:"top-icon e-save",tooltipText:this.l10n.getConstant("Cancel"),align:"Right"})),e},Y.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},Y.prototype.getFilterToolbarItem=function(){var e=[],t=this.parent,o=!1,i=t.element.id,r=["Default","Chrome","Cold","Warm","Grayscale","Sepia","Invert"];if(t.toolbar)for(var n=0;n<r.length;n++)if(-1!==t.toolbar.indexOf(r[n])){o=!0;break}(O.isNullOrUndefined(t.toolbar)||!o||t.toolbar&&-1<t.toolbar.indexOf("Default"))&&e.push({id:i+"_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='+i+'_defaultCanvas></canvas><div style="text-align:center;"><span>'+this.l10n.getConstant("Default")+"</span></div></div>"}),(O.isNullOrUndefined(t.toolbar)||!o||t.toolbar&&-1<t.toolbar.indexOf("Chrome"))&&e.push({id:i+"_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='+i+'_chromeCanvas></canvas><div style="text-align:center;"><span>'+this.l10n.getConstant("Chrome")+"</span></div></div>"}),(O.isNullOrUndefined(t.toolbar)||!o||t.toolbar&&-1<t.toolbar.indexOf("Cold"))&&e.push({id:i+"_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='+i+'_coldCanvas></canvas><div style="text-align:center;"><span>'+this.l10n.getConstant("Cold")+"</span></div></div>"}),(O.isNullOrUndefined(t.toolbar)||!o||t.toolbar&&-1<t.toolbar.indexOf("Warm"))&&e.push({id:i+"_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='+i+'_warmCanvas></canvas><div style="text-align:center;"><span>'+this.l10n.getConstant("Warm")+"</span></div></div>"}),(O.isNullOrUndefined(t.toolbar)||!o||t.toolbar&&-1<t.toolbar.indexOf("Grayscale"))&&e.push({id:i+"_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='+i+'_grayscaleCanvas></canvas><div style="text-align:center;"><span>'+this.l10n.getConstant("Grayscale")+"</span></div></div>"}),(O.isNullOrUndefined(t.toolbar)||!o||t.toolbar&&-1<t.toolbar.indexOf("Sepia"))&&e.push({id:i+"_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='+i+'_sepiaCanvas></canvas><div style="text-align:center;"><span>'+this.l10n.getConstant("Sepia")+"</span></div></div>"}),(O.isNullOrUndefined(t.toolbar)||!o||t.toolbar&&-1<t.toolbar.indexOf("Invert"))&&e.push({id:i+"_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='+i+'_invertCanvas></canvas><div style="text-align:center;"><span>'+this.l10n.getConstant("Invert")+"</span></div></div>"});for(var a=this.processToolbar("center"),n=0,s=a.length;n<s;n++)e.push(a[n]);return e},Y.prototype.getPenToolbarItem=function(e){for(var t=this.parent,o=t.element.id,i=[],r=((O.isNullOrUndefined(t.toolbar)||t.toolbar)&&i.push({id:o+"_annotation",tooltipText:this.l10n.getConstant("Annotation"),align:"Center",template:'<button id="'+o+'_annotationBtn"></button>'}),-1<e.indexOf("strokeColor")&&i.push({prefixIcon:"e-icons e-copy",id:o+"_pen_strokecolor",cssClass:"top-icon e-pen-stroke-color",tooltipText:this.l10n.getConstant("StrokeColor"),align:"Center",type:"Input",template:'<button id="'+o+'_penColorBtn"></button>'}),-1<e.indexOf("strokeWidth")&&i.push({prefixIcon:"e-icons e-copy",id:o+"_pen_strokewidth",cssClass:"top-icon e-size",tooltipText:this.l10n.getConstant("StrokeWidth"),align:"Center",type:"Input",template:'<button id="'+o+'_penStrokeWidth"></button>'}),i.push({align:"Center",type:"Separator"}),-1<e.indexOf("z-order")&&i.push({id:o+"_zOrder",cssClass:"top-icon e-list-unordered-3",tooltipText:this.l10n.getConstant("ZOrder"),align:"Center",type:"Input",template:'<button id="'+o+'_zOrderBtn"></button>'}),-1<e.indexOf("remove")&&i.push({id:o+"_remove",prefixIcon:"e-icons e-trash",cssClass:"top-icon e-trash",tooltipText:this.l10n.getConstant("Remove"),align:"Center"}),this.processSubToolbar(e)),n=0,a=r.length;n<a;n++)i.push(r[n]);return O.Browser.isDevice||(i.push({id:o+"_ok",prefixIcon:"e-icons e-check",cssClass:"top-icon e-tick",tooltipText:this.l10n.getConstant("OK"),align:"Right"}),i.push({id:o+"_cancel",prefixIcon:"e-icons e-close",cssClass:"top-icon e-save",tooltipText:this.l10n.getConstant("Cancel"),align:"Right"})),i},Y.prototype.initPenToolbarItem=function(e){var t=this,o=this.parent,i=o.element.id,r=this.getLeftToolbarItem(),n=this.getRightToolbarItem(),a=this.getPenToolbarItem(e),s=this.getZoomToolbarItem(),r=(O.Browser.isDevice?this.defToolbarItems=a:this.defToolbarItems=r.concat(s,a,n),{toolbarType:"pen",toolbarItems:this.defToolbarItems}),l=(o.trigger("toolbarUpdating",r),this.isToolbarString(r.toolbarItems)?(e=r.toolbarItems,this.excludeItems(r.toolbarItems)):this.defToolbarItems=r.toolbarItems,new d.Toolbar({width:"100%",items:this.defToolbarItems,clicked:this.defToolbarClicked.bind(this),created:function(){t.renderAnnotationBtn(!0),t.createPenColor(e),t.createPenBtn(e),t.createZOrderBtn(e),t.wireZoomBtnEvents(),o.trigger("toolbarCreated",{toolbarType:"pen"}),O.Browser.isDevice?0<t.defToolbarItems.length&&document.getElementById(i+"_toolbar")&&(l.refreshOverflow(),l.refreshOverflow()):(t.createLeftToolbarControls(),0<t.defToolbarItems.length&&document.getElementById(i+"_toolbar")&&l.refreshOverflow())}}));O.Browser.isDevice?l.appendTo("#"+i+"_bottomToolbar"):l.appendTo("#"+i+"_toolbar"),this.enableDisableTbrBtn()},Y.prototype.createPenColor=function(e){var t,o,i=this,r=this.parent,n=r.element.id;-1<e.indexOf("strokeColor")&&(r.element.querySelector(".e-template.e-pen-stroke-color").appendChild(r.createElement("input",{id:n+"_pen_stroke"})),e=r.activeObj.strokeSettings.strokeColor,t=new g.ColorPicker({modeSwitcher:!1,value:"#fff",showButtons:!1,mode:"Palette",cssClass:"e-pen-color",change:function(e){r.updatePenStrokeColor(e.currentValue.hex),i.selFhdColor=e.currentValue.hex,o.element.children[0].style.backgroundColor=e.currentValue.rgba,o.toggle(),r.notify("undo-redo",{prop:"updateUndoRedoStack",value:{isPenDraw:!0}})}},"#"+n+"_pen_stroke"),o=new f.DropDownButton({open:function(e){e=e.element.parentElement;O.Browser.isDevice&&(e.style.top=o.element.getBoundingClientRect().top-e.offsetHeight+"px",e.style.left=r.element.offsetLeft+"px")},target:".e-pen-color",iconCss:"e-dropdownbtn-preview",cssClass:"e-ie-ddb-popup"},"#"+n+"_penColorBtn"),t.inline=!0,t.value=t.getValue(r.activeObj.strokeSettings.strokeColor,"rgba"),"null"===t.value&&(t.value=e),r.notify("freehand-draw",{prop:"getTempFreeHandDrawEditingStyles",value:{obj:n={tempFreeHandDrawEditingStyles:null}}}),r.notify("freehand-draw",{prop:"getFreehandSelectedIndex",onPropertyChange:!(e={freehandSelectedIndex:null}),value:{obj:e}}),!O.isNullOrUndefined(e.freehandSelectedIndex)&&-1<e.freehandSelectedIndex?r.element.querySelector(".e-pen-stroke-color.e-template .e-dropdownbtn-preview").style.background=("#42a5f5"===this.selFhdColor?n.tempFreeHandDrawEditingStyles:r.pointColl[e.freehandSelectedIndex]).strokeColor:r.element.querySelector(".e-pen-stroke-color.e-template .e-dropdownbtn-preview").style.background=t.value)},Y.prototype.createPenBtn=function(e){var o,t,i,r=this,n=this.parent,a=n.element.id,s=[{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")}];-1<e.indexOf("strokeWidth")&&(e=document.getElementById(a+"_penStrokeWidth"),o=document.createElement("span"),n.notify("freehand-draw",{prop:"getFreehandSelectedIndex",onPropertyChange:!(t={freehandSelectedIndex:null}),value:{obj:t}}),!O.isNullOrUndefined(t.freehandSelectedIndex)&&-1<t.freehandSelectedIndex?o.innerHTML=this.getPenStroke(n.pointColl[t.freehandSelectedIndex].strokeWidth):(n.notify("freehand-draw",{prop:"getPenStrokeWidth",onPropertyChange:!(t={penStrokeWidth:2}),value:{obj:t}}),o.innerHTML=t.penStrokeWidth?this.getPenStroke(t.penStrokeWidth):this.l10n.getConstant("Small")),o.className="e-pen-stroke-width",e.appendChild(o),(i=new f.DropDownButton({items:s,open:function(e){O.Browser.isDevice&&(e.element.parentElement.style.top=i.element.getBoundingClientRect().top-e.element.parentElement.offsetHeight+"px");var t=o.innerHTML;e.element.querySelector('[aria-label = "'+t+'"]').classList.add("e-selected-btn")},select:function(e){r.triggerTbarClickEvent(e),o.textContent=e.item.text,n.updatePenStrokeWidth(e.item.id),O.Browser.isDevice?document.getElementById(a+"_bottomToolbar")&&O.getComponent(a+"_bottomToolbar","toolbar").refreshOverflow():document.getElementById(a+"_toolbar")&&O.getComponent(a+"_toolbar","toolbar").refreshOverflow(),n.notify("undo-redo",{prop:"updateUndoRedoStack",value:{isPenDraw:!0}})}})).appendTo("#"+a+"_penStrokeWidth"))},Y.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 t=1<=e&&e<=5?o[e]:t},Y.prototype.initAdjustmentToolbarItem=function(){var e=this,t=this.parent,o=t.element.id,i=this.getLeftToolbarItem(null),r=this.getRightToolbarItem(),n=this.getAdjustmentToolbarItem(),a=this.getZoomToolbarItem(),i=(O.Browser.isDevice?this.defToolbarItems=n:this.defToolbarItems=i.concat(a,n,r),{toolbarType:"finetune",toolbarItems:this.defToolbarItems}),s=(t.trigger("toolbarUpdating",i),this.defToolbarItems=i.toolbarItems,new d.Toolbar({width:"100%",items:this.defToolbarItems,clicked:this.defToolbarClicked.bind(this),created:function(){e.wireZoomBtnEvents(),O.Browser.isDevice||e.createLeftToolbarControls(),0<e.defToolbarItems.length&&document.getElementById(o+"_toolbar")&&s.refreshOverflow()}}));O.Browser.isDevice?s.appendTo("#"+o+"_bottomToolbar"):s.appendTo("#"+o+"_toolbar"),this.enableDisableTbrBtn()},Y.prototype.initFrameToolbarItem=function(){var t=this,o=this.parent,i=o.element.id,e=document.querySelector("#"+i+"_contextualToolbarArea"),r=document.querySelector("#"+i+"_frameWrapper");r?r.style.display="block":r=e.appendChild(o.createElement("div",{id:i+"_frameWrapper",className:"e-frame-wrapper",styles:"position: relative"})),r.appendChild(o.createElement("div",{id:i+"_customizeWrapper",styles:"position: absolute"}));var e={toolbarType:"frame",toolbarItems:this.getFrameToolbarItem()},n=(o.trigger("toolbarUpdating",e),new d.Toolbar({width:"100%",items:e.toolbarItems,clicked:this.defToolbarClicked.bind(this),created:function(){t.createFrameColor(),t.createFrameSize();var e=o.frameObj.type;"line"===e&&t.createFrameRadius(),"line"!==e&&"inset"!==e&&"hook"!==e||t.createFrameInset(),"line"!==e&&"inset"!==e||t.createFrameOffset(),"line"===e&&(t.createFrameAmount(),t.createFrameBorder()),t.createFrameGradientColor(),O.Browser.isDevice?0<t.defToolbarItems.length&&document.getElementById(i+"_bottomToolbar")&&(n.refreshOverflow(),n.refreshOverflow(),n.refreshOverflow()):(t.createLeftToolbarControls(),0<t.defToolbarItems.length&&document.getElementById(i+"_toolbar")&&n.refreshOverflow()),o.element.querySelector("#"+i+"_"+e).focus()}}));n.appendTo("#"+i+"_customizeWrapper")},Y.prototype.createFrameGradientColor=function(){var i,r=this.parent,n={frameChangeEventArgs:null},e=r.element.id,t=(r.element.querySelector(".e-template.e-frame-stroke").appendChild(r.createElement("input",{id:e+"_frame_gradient_fill"})),new g.ColorPicker({modeSwitcher:!1,noColor:!0,value:r.frameObj.gradientColor,showButtons:!1,mode:"Palette",cssClass:"e-frame-gradient-fill-color",change:function(e){i={type:r.toPascalCase(r.frameObj.type),color:r.frameObj.color,gradientColor:r.frameObj.gradientColor,size:r.frameObj.size,inset:r.frameObj.inset,offset:r.frameObj.offset,borderRadius:r.frameObj.radius,frameLineStyle:r.toPascalCase(r.frameObj.border),lineCount:r.frameObj.amount};var t=r.frameObj.gradientColor,o={currObj:{}};r.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:o}}),r.frameObj.gradientColor=e.currentValue.hex,r.notify("draw",{prop:"triggerFrameChange",value:{prevFrameSettings:i,obj:n}}),n.frameChangeEventArgs&&!n.frameChangeEventArgs.cancel?(r.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"frame",previousObj:o.currObj,previousObjColl:o.currObj.objColl,previousPointColl:o.currObj.pointColl,previousSelPointColl:o.currObj.selPointColl,previousCropObj:O.extend({},r.cropObj,{},!0),previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),r.notify("draw",{prop:"render-image",value:{isMouseWheel:null,isPreventClearRect:null,isFrame:!0}}),r.notify("draw",{prop:"redrawDownScale"}),""===e.currentValue.rgba?a.element.children[0].classList.add("e-nocolor-item"):(a.element.children[0].classList.remove("e-nocolor-item"),a.element.children[0].style.backgroundColor=e.currentValue.rgba),r.curFrameObjEvent={previousFrameSetting:n.frameChangeEventArgs.previousFrameSetting,currentFrameSetting:n.frameChangeEventArgs.currentFrameSetting},r.isFrameBtnClick=!0):r.frameObj.gradientColor=t,a.toggle()}},"#"+e+"_frame_gradient_fill")),a=new f.DropDownButton({open:function(e){O.Browser.isDevice&&((e=e.element.parentElement).style.top=a.element.getBoundingClientRect().top-e.offsetHeight+"px",e.style.left=r.element.offsetLeft+"px")},target:".e-frame-gradient-fill-color",iconCss:"e-dropdownbtn-preview",cssClass:"e-ie-ddb-popup"},"#"+e+"_frameGradientColorBtn");t.inline=!0,""===r.frameObj.gradientColor?r.element.querySelector(".e-frame-stroke.e-template .e-dropdownbtn-preview").classList.add("e-nocolor-item"):r.element.querySelector(".e-frame-stroke.e-template .e-dropdownbtn-preview").style.background=r.frameObj.gradientColor},Y.prototype.createFrameColor=function(){var i,r=this.parent,n={frameChangeEventArgs:null},e=r.element.id,t=(r.element.querySelector(".e-template.e-stroke").appendChild(r.createElement("input",{id:e+"_frame_fill"})),new g.ColorPicker({modeSwitcher:!1,value:r.frameObj.color,showButtons:!1,mode:"Palette",cssClass:"e-frame-fill-color",change:function(e){i={type:r.toPascalCase(r.frameObj.type),color:r.frameObj.color,gradientColor:r.frameObj.gradientColor,size:r.frameObj.size,inset:r.frameObj.inset,offset:r.frameObj.offset,borderRadius:r.frameObj.radius,frameLineStyle:r.toPascalCase(r.frameObj.border),lineCount:r.frameObj.amount};var t=r.frameObj.color,o={currObj:{}};r.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:o}}),r.frameObj.color=e.currentValue.hex,r.notify("draw",{prop:"triggerFrameChange",value:{prevFrameSettings:i,obj:n}}),n.frameChangeEventArgs&&!n.frameChangeEventArgs.cancel?(r.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"frame",previousObj:o.currObj,previousObjColl:o.currObj.objColl,previousPointColl:o.currObj.pointColl,previousSelPointColl:o.currObj.selPointColl,previousCropObj:O.extend({},r.cropObj,{},!0),previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),r.notify("draw",{prop:"render-image",value:{isMouseWheel:null,isPreventClearRect:null,isFrame:!0}}),r.notify("draw",{prop:"redrawDownScale"}),""===e.currentValue.rgba?a.element.children[0].classList.add("e-nocolor-item"):(a.element.children[0].classList.remove("e-nocolor-item"),a.element.children[0].style.backgroundColor=e.currentValue.rgba),r.curFrameObjEvent={previousFrameSetting:n.frameChangeEventArgs.previousFrameSetting,currentFrameSetting:n.frameChangeEventArgs.currentFrameSetting},r.isFrameBtnClick=!0):r.frameObj.color=t,a.toggle()}},"#"+e+"_frame_fill")),a=new f.DropDownButton({open:function(e){O.Browser.isDevice&&((e=e.element.parentElement).style.top=a.element.getBoundingClientRect().top-e.offsetHeight+"px",e.style.left=r.element.offsetLeft+"px")},target:".e-frame-fill-color",iconCss:"e-dropdownbtn-preview",cssClass:"e-ie-ddb-popup"},"#"+e+"_frameColorBtn");t.inline=!0,r.element.querySelector(".e-stroke.e-template .e-dropdownbtn-preview").style.background=r.frameObj.color},Y.prototype.createFrameSize=function(){var i,r=this,n=this.parent,a={frameChangeEventArgs:null},s=n.element.id,e=[{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")}],t=document.getElementById(s+"_frameSizeBtn"),o=document.createElement("span"),l=(o.innerHTML=this.l10n.getConstant(n.frameObj.size.toString()),o.className="e-frame-stroke-width",t.appendChild(o),new f.DropDownButton({items:e,open:function(e){O.Browser.isDevice&&((t=e.element.parentElement).style.top=l.element.getBoundingClientRect().top-t.offsetHeight+"px");var t=l.element.childNodes[0].textContent;""!==t&&e.element.querySelector('[aria-label = "'+t+'"]').classList.add("e-selected-btn")},select:function(e){r.triggerTbarClickEvent(e),i={type:n.toPascalCase(n.frameObj.type),color:n.frameObj.color,gradientColor:n.frameObj.gradientColor,size:n.frameObj.size,inset:n.frameObj.inset,offset:n.frameObj.offset,borderRadius:n.frameObj.radius,frameLineStyle:n.toPascalCase(n.frameObj.border),lineCount:n.frameObj.amount};var t=n.frameObj.size,o={currObj:{}};n.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:o}}),n.frameObj.size=parseInt(e.item.text,10),n.notify("draw",{prop:"triggerFrameChange",value:{prevFrameSettings:i,obj:a}}),a.frameChangeEventArgs&&!a.frameChangeEventArgs.cancel?(n.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"frame",previousObj:o.currObj,previousObjColl:o.currObj.objColl,previousPointColl:o.currObj.pointColl,previousSelPointColl:o.currObj.selPointColl,previousCropObj:O.extend({},n.cropObj,{},!0),previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),n.notify("draw",{prop:"render-image",value:{isMouseWheel:null,isPreventClearRect:null,isFrame:!0}}),n.notify("draw",{prop:"redrawDownScale"}),l.content=e.item.text,n.curFrameObjEvent={previousFrameSetting:a.frameChangeEventArgs.previousFrameSetting,currentFrameSetting:a.frameChangeEventArgs.currentFrameSetting},n.isFrameBtnClick=!0):n.frameObj.size=t,O.Browser.isDevice?document.getElementById(s+"_bottomToolbar")&&O.getComponent(s+"_bottomToolbar","toolbar").refreshOverflow():document.getElementById(s+"_toolbar")&&O.getComponent(s+"_toolbar","toolbar").refreshOverflow()}}));l.appendTo("#"+s+"_frameSizeBtn")},Y.prototype.createFrameInset=function(){var i,r=this,n=this.parent,a={frameChangeEventArgs:null},s=n.element.id,e=[{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")}],t=document.getElementById(s+"_frameInsetBtn"),o=document.createElement("span"),l=(o.innerHTML=this.l10n.getConstant(n.frameObj.inset.toString()),o.className="e-frame-inset",t.appendChild(o),new f.DropDownButton({items:e,open:function(e){O.Browser.isDevice&&((t=e.element.parentElement).style.top=l.element.getBoundingClientRect().top-t.offsetHeight+"px");var t=l.element.childNodes[0].textContent;""!==t&&e.element.querySelector('[aria-label = "'+t+'"]').classList.add("e-selected-btn")},select:function(e){r.triggerTbarClickEvent(e),i={type:n.toPascalCase(n.frameObj.type),color:n.frameObj.color,gradientColor:n.frameObj.gradientColor,size:n.frameObj.size,inset:n.frameObj.inset,offset:n.frameObj.offset,borderRadius:n.frameObj.radius,frameLineStyle:n.toPascalCase(n.frameObj.border),lineCount:n.frameObj.amount};var t=n.frameObj.inset,o={currObj:{}};n.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:o}}),n.frameObj.inset=parseInt(e.item.text,10),n.notify("draw",{prop:"triggerFrameChange",value:{prevFrameSettings:i,obj:a}}),a.frameChangeEventArgs&&!a.frameChangeEventArgs.cancel?(n.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"frame",previousObj:o.currObj,previousObjColl:o.currObj.objColl,previousPointColl:o.currObj.pointColl,previousSelPointColl:o.currObj.selPointColl,previousCropObj:O.extend({},n.cropObj,{},!0),previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),n.notify("draw",{prop:"render-image",value:{isMouseWheel:null,isPreventClearRect:null,isFrame:!0}}),n.notify("draw",{prop:"redrawDownScale"}),l.content=e.item.text,n.curFrameObjEvent={previousFrameSetting:a.frameChangeEventArgs.previousFrameSetting,currentFrameSetting:a.frameChangeEventArgs.currentFrameSetting},n.isFrameBtnClick=!0):n.frameObj.inset=t,O.Browser.isDevice?document.getElementById(s+"_bottomToolbar")&&O.getComponent(s+"_bottomToolbar","toolbar").refreshOverflow():document.getElementById(s+"_toolbar")&&O.getComponent(s+"_toolbar","toolbar").refreshOverflow()}}));l.appendTo("#"+s+"_frameInsetBtn")},Y.prototype.createFrameOffset=function(){var i,r=this,n=this.parent,a={frameChangeEventArgs:null},s=n.element.id,e=[{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")}],t=document.getElementById(s+"_frameOffsetBtn"),o=document.createElement("span"),l=(o.innerHTML=this.l10n.getConstant(n.frameObj.offset.toString()),o.className="e-frame-offset",t.appendChild(o),new f.DropDownButton({items:e,open:function(e){O.Browser.isDevice&&((t=e.element.parentElement).style.top=l.element.getBoundingClientRect().top-t.offsetHeight+"px");var t=l.element.childNodes[0].textContent;""!==t&&e.element.querySelector('[aria-label = "'+t+'"]').classList.add("e-selected-btn")},select:function(e){r.triggerTbarClickEvent(e),i={type:n.toPascalCase(n.frameObj.type),color:n.frameObj.color,gradientColor:n.frameObj.gradientColor,size:n.frameObj.size,inset:n.frameObj.inset,offset:n.frameObj.offset,borderRadius:n.frameObj.radius,lineCount:n.frameObj.amount,frameLineStyle:n.toPascalCase(n.frameObj.border)};var t=n.frameObj.offset,o={currObj:{}};n.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:o}}),n.frameObj.offset=parseInt(e.item.text,10),n.notify("draw",{prop:"triggerFrameChange",value:{prevFrameSettings:i,obj:a}}),a.frameChangeEventArgs&&!a.frameChangeEventArgs.cancel?(n.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"frame",previousObj:o.currObj,previousObjColl:o.currObj.objColl,previousPointColl:o.currObj.pointColl,previousSelPointColl:o.currObj.selPointColl,previousCropObj:O.extend({},n.cropObj,{},!0),previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),n.notify("draw",{prop:"render-image",value:{isMouseWheel:null,isPreventClearRect:null,isFrame:!0}}),n.notify("draw",{prop:"redrawDownScale"}),l.content=e.item.text,n.curFrameObjEvent={previousFrameSetting:a.frameChangeEventArgs.previousFrameSetting,currentFrameSetting:a.frameChangeEventArgs.currentFrameSetting},n.isFrameBtnClick=!0):n.frameObj.offset=t,O.Browser.isDevice?document.getElementById(s+"_bottomToolbar")&&O.getComponent(s+"_bottomToolbar","toolbar").refreshOverflow():document.getElementById(s+"_toolbar")&&O.getComponent(s+"_toolbar","toolbar").refreshOverflow()}}));l.appendTo("#"+s+"_frameOffsetBtn")},Y.prototype.createFrameRadius=function(){var i,r=this,n=this.parent,a={frameChangeEventArgs:null},s=n.element.id,e=[{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")}],t=document.getElementById(s+"_frameRadiusBtn"),o=document.createElement("span"),l=(o.innerHTML=this.l10n.getConstant(n.frameObj.radius.toString()),o.className="e-frame-radius",t.appendChild(o),new f.DropDownButton({items:e,open:function(e){O.Browser.isDevice&&((t=e.element.parentElement).style.top=l.element.getBoundingClientRect().top-t.offsetHeight+"px");var t=l.element.childNodes[0].textContent;""!==t&&e.element.querySelector('[aria-label = "'+t+'"]').classList.add("e-selected-btn")},select:function(e){r.triggerTbarClickEvent(e),i={type:n.toPascalCase(n.frameObj.type),color:n.frameObj.color,gradientColor:n.frameObj.gradientColor,size:n.frameObj.size,inset:n.frameObj.inset,offset:n.frameObj.offset,borderRadius:n.frameObj.radius,frameLineStyle:n.toPascalCase(n.frameObj.border),lineCount:n.frameObj.amount};var t=n.frameObj.radius,o={currObj:{}};n.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:o}}),n.frameObj.radius=parseInt(e.item.text,10),n.notify("draw",{prop:"triggerFrameChange",value:{prevFrameSettings:i,obj:a}}),a.frameChangeEventArgs&&!a.frameChangeEventArgs.cancel?(n.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"frame",previousObj:o.currObj,previousObjColl:o.currObj.objColl,previousPointColl:o.currObj.pointColl,previousSelPointColl:o.currObj.selPointColl,previousCropObj:O.extend({},n.cropObj,{},!0),previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),n.notify("draw",{prop:"render-image",value:{isMouseWheel:null,isPreventClearRect:null,isFrame:!0}}),n.notify("draw",{prop:"redrawDownScale"}),l.content=e.item.text,n.curFrameObjEvent={previousFrameSetting:a.frameChangeEventArgs.previousFrameSetting,currentFrameSetting:a.frameChangeEventArgs.currentFrameSetting},n.isFrameBtnClick=!0):n.frameObj.radius=t,O.Browser.isDevice?document.getElementById(s+"_bottomToolbar")&&O.getComponent(s+"_bottomToolbar","toolbar").refreshOverflow():document.getElementById(s+"_toolbar")&&O.getComponent(s+"_toolbar","toolbar").refreshOverflow()}}));l.appendTo("#"+s+"_frameRadiusBtn")},Y.prototype.createFrameAmount=function(){var i,r=this,n=this.parent,a={frameChangeEventArgs:null},s=n.element.id,e=[{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")}],t=document.getElementById(s+"_frameAmountBtn"),o=document.createElement("span"),l=(o.innerHTML=this.l10n.getConstant(n.frameObj.amount.toString()),o.className="e-frame-amount",t.appendChild(o),new f.DropDownButton({items:e,open:function(e){O.Browser.isDevice&&((t=e.element.parentElement).style.top=l.element.getBoundingClientRect().top-t.offsetHeight+"px");var t=l.element.childNodes[0].textContent;""!==t&&e.element.querySelector('[aria-label = "'+t+'"]').classList.add("e-selected-btn")},select:function(e){r.triggerTbarClickEvent(e),i={type:n.toPascalCase(n.frameObj.type),color:n.frameObj.color,gradientColor:n.frameObj.gradientColor,size:n.frameObj.size,inset:n.frameObj.inset,offset:n.frameObj.offset,borderRadius:n.frameObj.radius,lineCount:n.frameObj.amount,frameLineStyle:n.toPascalCase(n.frameObj.border)};var t=n.frameObj.amount,o={currObj:{}};n.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:o}}),n.frameObj.amount=parseInt(e.item.text,10),n.notify("draw",{prop:"triggerFrameChange",value:{prevFrameSettings:i,obj:a}}),a.frameChangeEventArgs&&!a.frameChangeEventArgs.cancel?(n.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"frame",previousObj:o.currObj,previousObjColl:o.currObj.objColl,previousPointColl:o.currObj.pointColl,previousSelPointColl:o.currObj.selPointColl,previousCropObj:O.extend({},n.cropObj,{},!0),previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),n.notify("draw",{prop:"render-image",value:{isMouseWheel:null,isPreventClearRect:null,isFrame:!0}}),n.notify("draw",{prop:"redrawDownScale"}),l.content=e.item.text,n.curFrameObjEvent={previousFrameSetting:a.frameChangeEventArgs.previousFrameSetting,currentFrameSetting:a.frameChangeEventArgs.currentFrameSetting},n.isFrameBtnClick=!0):n.frameObj.amount=t,O.Browser.isDevice?document.getElementById(s+"_bottomToolbar")&&O.getComponent(s+"_bottomToolbar","toolbar").refreshOverflow():document.getElementById(s+"_toolbar")&&O.getComponent(s+"_toolbar","toolbar").refreshOverflow()}}));l.appendTo("#"+s+"_frameAmountBtn")},Y.prototype.createFrameBorder=function(){var i,r=this,n=this.parent,a={frameChangeEventArgs:null},s=n.element.id,e=[{id:"1",text:this.l10n.getConstant("Solid")},{id:"2",text:this.l10n.getConstant("Dashed")},{id:"3",text:this.l10n.getConstant("Dotted")}],t=document.getElementById(s+"_frameBorderBtn"),o=document.createElement("span"),l=(o.innerHTML=this.l10n.getConstant(n.toPascalCase(n.frameObj.border)),o.className="e-frame-border",t.appendChild(o),new f.DropDownButton({items:e,open:function(e){O.Browser.isDevice&&((t=e.element.parentElement).style.top=l.element.getBoundingClientRect().top-t.offsetHeight+"px");var t=l.element.childNodes[0].textContent;""!==t&&e.element.querySelector('[aria-label = "'+t+'"]').classList.add("e-selected-btn")},select:function(e){r.triggerTbarClickEvent(e),i={lineCount:n.frameObj.amount,color:n.frameObj.color,borderRadius:n.frameObj.radius,gradientColor:n.frameObj.gradientColor,size:n.frameObj.size,inset:n.frameObj.inset,offset:n.frameObj.offset,frameLineStyle:n.toPascalCase(n.frameObj.border),type:n.toPascalCase(n.frameObj.type)};var t=n.frameObj.border,o={currObj:{}};n.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:o}}),n.frameObj.border=e.item.text.toLowerCase(),n.notify("draw",{prop:"triggerFrameChange",value:{prevFrameSettings:i,obj:a}}),a.frameChangeEventArgs&&!a.frameChangeEventArgs.cancel?(n.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"frame",previousObj:o.currObj,previousObjColl:o.currObj.objColl,previousPointColl:o.currObj.pointColl,previousSelPointColl:o.currObj.selPointColl,previousCropObj:O.extend({},n.cropObj,{},!0),previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),n.notify("draw",{prop:"render-image",value:{isMouseWheel:null,isPreventClearRect:null,isFrame:!0}}),n.notify("draw",{prop:"redrawDownScale"}),l.content=e.item.text,n.curFrameObjEvent={previousFrameSetting:a.frameChangeEventArgs.previousFrameSetting,currentFrameSetting:a.frameChangeEventArgs.currentFrameSetting},n.isFrameBtnClick=!0):n.frameObj.border=t,O.Browser.isDevice?document.getElementById(s+"_bottomToolbar")&&O.getComponent(s+"_bottomToolbar","toolbar").refreshOverflow():document.getElementById(s+"_toolbar")&&O.getComponent(s+"_toolbar","toolbar").refreshOverflow()}}));l.appendTo("#"+s+"_frameBorderBtn")},Y.prototype.initFilterToolbarItem=function(){var t=this,o=this.parent,i=o.element.id,e={toolbarType:"filter",toolbarItems:this.getFilterToolbarItem()},r=(o.trigger("toolbarUpdating",e),e=e.toolbarItems,document.querySelector("#"+i+"_contextualToolbar").classList.contains("e-control")&&O.getComponent(document.getElementById(i+"_contextualToolbar"),"toolbar").destroy(),new d.Toolbar({width:"100%",items:e,clicked:this.contextualToolbarClicked.bind(this),created:function(){t.updatePrivateVariables(),t.createCanvasFilter(),""===o.currentFilter&&(o.currentFilter=i+"_default");var e=document.querySelector("#"+i+"_headWrapper"),e=(e&&(e.style.display="none"),document.getElementById(o.currentFilter+"Canvas"));e&&e.parentElement.parentElement.classList.add("e-selected"),t.enableDisableTbrBtn(),r.refreshOverflow()}}));r.appendTo("#"+i+"_contextualToolbar")},Y.prototype.drawDashedLine=function(e){e.beginPath(),e.setLineDash([5]),e.rect(10,10,280,130),e.stroke(),e.closePath()},Y.prototype.createCanvasFilter=function(){var e=this.parent,t=(u.showSpinner(e.element),e.element.style.opacity="0.5",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"),u.hideSpinner(e.element),e.element.style.opacity="1",e.initialAdjustmentValue=this.lowerContext.filter},Y.prototype.updateFilterCanvas=function(e,t){var o,i=this.parent,e=i.element.querySelector("#"+i.element.id+e);e&&(o=e.getContext("2d"),o=e.getContext("2d"),e.style.width="100px",e.style.height="100px",i.notify("filter",{prop:"updateAdj",value:{type:t,value:null,isPreview:!0,ctx:o}}),o.drawImage(this.inMemoryCanvas,0,0,300,150))},Y.prototype.getQuickAccessToolbarItem=function(e){var t=this.parent,o=t.element.id,i={cancel:!1,toolbarItems:[]},r=[],n=(O.isNullOrUndefined(e)?("image"===t.activeObj.shape&&r.push("Flip"),r.push("BringToFront"),r.push("Clone"),r.push("Delete"),"text"===t.activeObj.shape&&r.push("EditText"),i.shape=t.toPascalCase(t.activeObj.shape)):e&&(r.push("BringToFront"),r.push("Delete"),i.shape="Freehand draw"),i.toolbarItems=O.extend([],r,null,!0),t.trigger("quickAccessToolbarOpen",i),[]);if(i.cancel)n=[];else for(var a=0;a<i.toolbarItems.length;a++)switch(i.toolbarItems[a]){case"BringToFront":n.push({id:o+"_bringToFront",prefixIcon:"e-icons e-bring-to-front",tooltipText:this.l10n.getConstant("BringToFront"),align:"Left"});break;case"Clone":n.push({id:o+"_duplicate",prefixIcon:"e-icons e-order",cssClass:"top-icon e-order",tooltipText:this.l10n.getConstant("Duplicate"),align:"Left"});break;case"Delete":n.push({id:o+"_remove",prefixIcon:"e-icons e-trash",cssClass:"top-icon e-trash",tooltipText:this.l10n.getConstant("Remove"),align:"Left"});break;case"EditText":n.push({id:o+"_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:o+"_hFlip",prefixIcon:"e-icons e-horizontal-flip",tooltipText:this.l10n.getConstant("HorizontalFlip"),align:"Left"}),n.push({id:o+"_vFlip",prefixIcon:"e-icons e-vertical-flip",tooltipText:this.l10n.getConstant("VerticalFlip"),align:"Left"});break;default:n.push(i.toolbarItems[a])}return n},Y.prototype.renderQAT=function(e){var t,o,i,r,n,a,s,l,p=this.parent,h=p.element.id;p.activeObj&&p.showQuickAccessToolbar&&((t=document.getElementById(h+"_quickAccessToolbarArea"))&&(this.destroyQuickAccessToolbar(),t.style.display="block"),0!==(o=this.getQuickAccessToolbarItem(e)).length)&&(O.isNullOrUndefined(p.quickAccessToolbarTemplate)&&new d.Toolbar({items:o,clicked:this.quickAccessToolbarClicked.bind(this)}).appendTo("#"+h+"_quickAccessToolbar"),h=this.toolbarHeight&&0!==this.toolbarHeight?this.toolbarHeight:t.clientHeight,O.isNullOrUndefined(e)&&(0!==p.activeObj.activePoint.width||0!==p.activeObj.activePoint.height||p.activeObj.shape&&"path"===p.activeObj.shape&&0<p.activeObj.pointColl.length)?(p.notify("shape",{prop:"getHighestOrder",onPropertyChange:!(a={order:null}),value:{obj:a}}),p.activeObj.order>a.order?document.getElementById(p.element.id+"_bringToFront").classList.add("e-disabled"):document.getElementById(p.element.id+"_bringToFront").classList.remove("e-disabled"),t.style.width="auto",p.activeObj.activePoint.width=Math.abs(p.activeObj.activePoint.width),p.activeObj.activePoint.height=Math.abs(p.activeObj.activePoint.height),n=p.activeObj.activePoint.startX<p.activeObj.activePoint.endX?p.activeObj.activePoint.startX:p.activeObj.activePoint.endX,i=p.activeObj.activePoint.startY<p.activeObj.activePoint.endY?p.activeObj.activePoint.startY:p.activeObj.activePoint.endY,s=p.activeObj.activePoint.width,0!==p.activeObj.rotatedAngle&&"arrow"!==p.activeObj.shape?(p.notify("shape",{prop:"getSquarePointForRotatedShape",onPropertyChange:!(l={activePoint:null}),value:{obj:p.activeObj,object:l}}),n=(l=l.activePoint).startX,i=l.startY,s=l.width):"path"===p.activeObj.shape&&(n=(r=p.getSquarePointForPath(p.activeObj)).startX,i=r.startY,s=r.width),t.style.left=n+s/2-25*o.length+"px",parseFloat(t.style.left)+t.clientWidth/2!==n+s/2&&(r=n+s/2-(parseFloat(t.style.left)+t.clientWidth/2),t.style.left=parseFloat(t.style.left)+r+"px"),i-(h+h/1.5)<p.img.destTop?t.style.top=p.img.destTop+"px":t.style.top=i-(h+h/1.5)+"px"):e?(p.notify("freehand-draw",{prop:"getFreehandSelectedIndex",onPropertyChange:!(n={freehandSelectedIndex:-1}),value:{obj:n}}),p.notify("shape",{prop:"getHighestOrder",onPropertyChange:!(a={order:null}),value:{obj:a}}),p.getObjFromId(p.pointColl[n.freehandSelectedIndex].id).order>=a.order?document.getElementById(p.element.id+"_bringToFront").classList.add("e-disabled"):document.getElementById(p.element.id+"_bringToFront").classList.remove("e-disabled"),p.notify("freehand-draw",{prop:"getSqPtFD",value:{idx:n.freehandSelectedIndex,obj:s={activePoint:null}}}),l=s.activePoint,t.style.width="auto",t.style.left=l.startX+l.width/2-24*o.length+"px",l.startY-(h+h/1.5)<p.img.destTop?t.style.top=p.img.destTop+"px":t.style.top=l.startY-(h+h/1.5)+"px"):t.style.display="none",parseFloat(t.style.top)<0)&&(t.style.top="0px")},Y.prototype.refreshDropDownBtn=function(e){var t,o;!O.isNullOrUndefined(e)&&(t=this.parent.element.id,(o=document.querySelector("#"+t+"_annotationBtn"))&&(e?(o.classList.add("e-disabled"),o.parentElement.classList.add("e-overlay")):(o.classList.remove("e-disabled"),o.parentElement.classList.remove("e-overlay")),O.getComponent(o,"dropdown-btn").disabled=e),(o=document.querySelector("#"+t+"_transformBtn"))&&(e?(o.classList.add("e-disabled"),o.parentElement.classList.add("e-overlay")):(o.classList.remove("e-disabled"),o.parentElement.classList.remove("e-overlay")),O.getComponent(o,"dropdown-btn").disabled=e),(o=document.querySelector("#"+t+"_adjustment"))&&(e?(o.classList.add("e-disabled"),o.parentElement.classList.add("e-overlay")):(o.classList.remove("e-disabled"),o.parentElement.classList.remove("e-overlay")),O.getComponent(o,"btn").disabled=e),o=document.querySelector("#"+t+"_filter"))&&(e?(o.classList.add("e-disabled"),o.parentElement.classList.add("e-overlay")):(o.classList.remove("e-disabled"),o.parentElement.classList.remove("e-overlay")),O.getComponent(o,"btn").disabled=e)},Y.prototype.cropSelect=function(e){var t=this.parent,e=(t.isCropTab=!0,O.isNullOrUndefined(t.transform.cropZoomFactor)&&(t.transform.cropZoomFactor=t.transform.zoomFactor,t.notify("draw",{prop:"setTempZoomFactor",onPropertyChange:!1,value:{tempZoomFactor:t.transform.zoomFactor}})),t.transform.zoomFactor=t.transform.cropZoomFactor,e.item.id),o=(this.currentToolbar="crop",t.currSelectionPoint=null,t.notify("draw",{prop:"setIsCropSelect",value:{bool:!0}}),{prevObj:null});t.notify("crop",{prop:"getPreviousCropCurrentObj",value:{obj:o}}),t.notify("draw",{prop:"select",onPropertyChange:!1,value:{type:e,startX:null,startY:null,width:null,height:null}}),t.notify("crop",{prop:"setPreviousCropCurrentObj",value:{obj:o.prevObj}}),this.enableDisableTbrBtn(),t.notify("transform",{prop:"disableZoomOutBtn",value:{isZoomOut:!0}})},Y.prototype.quickAccessToolbarClicked=function(e,t){var o=this.parent,i=o.element.id;if(e.item){var r,n=null,a={tempObj:null},s=(o.notify("draw",{prop:"getPrevActObj",onPropertyChange:!1,value:{obj:{prevActObj:null}}}),o.notify("selection",{prop:"getTempActObj",onPropertyChange:!1,value:{obj:a}}),a.tempObj.activePoint.height=Math.abs(a.tempObj.activePoint.height),{isNewPath:null}),l=void 0,p=(o.notify("draw",{prop:"getNewPath",value:{obj:s}}),e.item.id.replace(i+"_","").toLowerCase()),h=void 0,d=void 0,c={freehandSelectedIndex:null},u=void 0,g={order:null};switch(p){case"duplicate":o.element.querySelector("#"+i+"_duplicate").classList.contains("e-disabled")||(this.refreshSlider(),s.isNewPath||JSON.stringify(a.tempObj)!==JSON.stringify(o.activeObj)||(n=!0),this.duplicateShape(n));break;case"remove":o.element.querySelector("#"+i+"_remove").classList.contains("e-disabled")||(o.noPushUndo=!1,this.refreshSlider(),o.notify("selection",{prop:"deleteItem",onPropertyChange:!1}));break;case"edittext":o.element.querySelector("#"+i+"_editText").classList.contains("e-disabled")||this.editText();break;case"rotleft":case"rotright":h=o.element.querySelector("#"+i+"_rotLeft"),d=o.element.querySelector("#"+i+"_rotRight"),(h&&!h.classList.contains("e-disabled")||d&&!d.classList.contains("e-disabled"))&&o.rotateImage(e.item.id.replace(i+"_","").toLowerCase()),o.notify("undo-redo",{prop:"updateUndoRedoStack",onPropertyChange:!1});break;case"hflip":o.element.querySelector("#"+i+"_hFlip").classList.contains("e-disabled")||(l=o.activeObj.imageCanvas.getContext("2d"),o.horizontalFlip(l)),o.notify("undo-redo",{prop:"updateUndoRedoStack",onPropertyChange:!1});break;case"vflip":o.element.querySelector("#"+i+"_vFlip").classList.contains("e-disabled")||(l=o.activeObj.imageCanvas.getContext("2d"),o.verticalFlip(l)),o.notify("undo-redo",{prop:"updateUndoRedoStack",onPropertyChange:!1});break;case"bringtofront":o.element.querySelector("#"+i+"_bringToFront").classList.contains("e-disabled")||(o.notify("freehand-draw",{prop:"getFreehandSelectedIndex",onPropertyChange:!1,value:{obj:c}}),u=null!==c.freehandSelectedIndex?o.pointColl[c.freehandSelectedIndex].id:o.activeObj.currIndex,o.updateShapeOrder(u,p),o.notify("shape",{prop:"getHighestOrder",onPropertyChange:!1,value:{obj:g}}),(-1<u.indexOf("pen")?(o.notify("shape",{prop:"updateShapeColl",onPropertyChange:!1}),r=o.getObjFromId(u).order,g.order<=r):(r=o.getObjFromId(u).order,g.order<r))?document.getElementById(o.element.id+"_bringToFront").classList.add("e-disabled"):document.getElementById(o.element.id+"_bringToFront").classList.remove("e-disabled"),o.notify("undo-redo",{prop:"updateUndoRedoStack",onPropertyChange:!1}))}"duplicate"!==p&&"remove"!==p||o.notify("draw",{prop:"redrawDownScale"})}O.isNullOrUndefined(t)&&o.trigger("quickAccessToolbarItemClick",e)},Y.prototype.editText=function(){var e=this.parent,t={x:e.activeObj.activePoint.startX,y:e.activeObj.activePoint.startY},o=(this.upperContext.clearRect(0,0,e.upperCanvas.width,e.upperCanvas.height),e.notify("selection",{prop:"setTempActObj",onPropertyChange:!1,value:{obj:O.extend({},e.activeObj,{},!0)}}),e.notify("selection",{prop:"setInitialTextEdit",onPropertyChange:!1,value:{bool:!0}}),e.notify("draw",{prop:"setPrevActObj",onPropertyChange:!1,value:{prevActObj:O.extend({},e.activeObj,{},!0)}}),0!==e.activeObj.rotatedAngle&&(o={x:t.x,y:t.y},e.notify("shape",{prop:"getTextBoxPosition",onPropertyChange:!1,value:{obj:e.activeObj,object:o}}),t.x=o.x,t.y=o.y,o={x:t.x,y:t.y},e.notify("shape",{prop:"setFlipState",onPropertyChange:!1,value:{x:t.x,y:t.y,obj:e.activeObj,object:o}}),t.x=o.x,t.y=o.y),O.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=o,e.notify("shape",{prop:"renderTextArea",onPropertyChange:!1,value:{x:t.x,y:t.y,actObj:e.activeObj}}),O.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")},Y.prototype.duplicateShape=function(e,t){var o,i=this.parent,r=(i.notify("selection",{prop:"setTempActObj",onPropertyChange:!1,value:{obj:{activePoint:{startX:0,startY:0,endX:0,endY:0,width:0,height:0},flipObjColl:[],triangle:[],triangleRatio:[]}}}),{prevActObj:null}),n=(i.notify("draw",{prop:"getPrevActObj",onPropertyChange:!1,value:{obj:r}}),i.notify("draw",{prop:"getNewPath",value:{obj:{isNewPath:null}}}),O.extend({},i.activeObj,{},!0)),a={order:null},a=(i.notify("shape",{prop:"getHighestOrder",onPropertyChange:!1,value:{obj:a}}),n.order?i.notify("shape",{prop:"updateShapeColl",onPropertyChange:!1}):(i.noPushUndo=!0,i.okBtn(),i.noPushUndo=!1,i.selectShape(n.currIndex)),n.order=a.order>n.order?a.order+1:n.order+1,"image"===n.shape&&(o=O.extend([],i.objColl,[],!0),i.notify("undo-redo",{prop:"updateUrObj",onPropertyChange:!1,value:{objColl:o}})),O.isNullOrUndefined(i.activeObj.currIndex)?i.notify("shape",{prop:"applyActObj",onPropertyChange:!1,value:{isMouseDown:e}}):r.prevActObj||t?(i.activeObj.currIndex=null,n.currIndex=null,i.notify("shape",{prop:"applyActObj",onPropertyChange:!1,value:{isMouseDown:e}})):i.notify("shape",{prop:"applyActObj",onPropertyChange:!1,value:{isMouseDown:!0}}),i.noPushUndo);if(i.noPushUndo=!1,i.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"ok"}}),i.noPushUndo=a,o=O.extend([],i.objColl,[],!0),n.activePoint.startX+=10,n.activePoint.startY-=10,n.activePoint.endX+=10,n.activePoint.endY-=10,"path"===n.shape)for(var s=0;s<n.pointColl.length;s++)n.pointColl[s].x+=10,n.pointColl[s].y-=10;else"image"===n.shape&&(n.imageCanvas=i.createElement("canvas"));r={id:"shape_"+(i.objColl.length+1)};i.notify("shape",{prop:"getNewShapeId",onPropertyChange:!1,value:{obj:r}}),n.currIndex=r.id,i.activeObj=O.extend({},n,{},!0),"image"===i.activeObj.shape&&(t=O.extend({},n.activePoint,{},!0),i.notify("transform",{prop:"calcMaxDimension",onPropertyChange:!(e={width:0,height:0}),value:{width:i.activeObj.imageElement.width,height:i.activeObj.imageElement.height,obj:e,isImgShape:null}}),i.activeObj.activePoint.width=e.width,i.activeObj.activePoint.height=e.height,i.activeObj.isHorImageFlip&&i.activeObj.isVerImageFlip?(i.activeObj.isHorImageFlip=i.activeObj.isVerImageFlip=!1,i.notify("draw",{prop:"downScaleImgCanvas",onPropertyChange:!1,value:{ctx:n.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:n.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:n.imageCanvas.getContext("2d"),isImgAnnotation:!0,isHFlip:null,isVFlip:!0}}),i.activeObj.isVerImageFlip=!0):i.notify("draw",{prop:"downScaleImgCanvas",onPropertyChange:!1,value:{ctx:n.imageCanvas.getContext("2d"),isImgAnnotation:!0,isHFlip:null,isVFlip:null}}),i.activeObj.activePoint=t),"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:o}}),this.renderQAT()},Y.prototype.defToolbarClicked=function(e){var t,o,i,r,n=this.parent,a=n.element.id,s=!1,l=!1;!this.isFrameToolbar&&n.element.querySelector(".e-contextual-toolbar-wrapper")&&(n.element.querySelector(".e-contextual-toolbar-wrapper").classList.contains("e-hide")||(s=l=!0),t=n.isStraightening,O.Browser.isDevice&&(!O.Browser.isDevice||t)||n.element.querySelector(".e-contextual-toolbar-wrapper").classList.add("e-hide")),e.item&&("duplicate"===(t=e.item.id.replace(a+"_","").toLowerCase())||"remove"===t||"edittext"===t||"hflip"===t||"vflip"===t||"rotleft"===t||"rotright"===t?(this.quickAccessToolbarClicked(e,!0),n.trigger("toolbarItemClicked",e)):(i=o=!1,(r=document.querySelector("#"+a+"_adjustment"))&&r.classList.contains("e-disabled")&&(i=!0),(r=document.querySelector("#"+a+"_filter"))&&r.classList.contains("e-disabled")&&(o=!0),this.enableDisableTbrBtn(),this.performDefTbrClick(t,s,i,o,l),n.trigger("toolbarItemClicked",e),n.isStraightening&&n.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(t)&&n.notify("draw",{prop:"redrawDownScale"})))},Y.prototype.performDefTbrClick=function(e,t,o,i,r){var n,a,s=this.parent,l=s.element.id,p=s.element.querySelector("#"+l+"_zoomIn"),h=s.element.querySelector("#"+l+"_resizeHeight"),d=s.element.querySelector("#"+l+"_resizeWidth"),c=!1;if((void 0===(a=void 0!==s.activeObj.shape?s.activeObj.shape.split("-"):a)&&s.currObjType.isCustomCrop||void 0!==a&&"crop"===a[0])&&(c=!0),!s.disabled)switch(e){case"pan":s.currObjType.isCustomCrop=s.currObjType.isFiltered=!1,s.currObjType.isUndoAction&&s.notify("undo-redo",{prop:"refreshUrc",value:{bool:null}}),c&&(s.currObjType.isCustomCrop=!1,s.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),this.upperContext.clearRect(0,0,s.upperCanvas.width,s.upperCanvas.height),this.refreshToolbar("main")),s.togglePan?(this.cancelPan(),s.notify("transform",{prop:"setDisablePan",onPropertyChange:!1,value:{bool:!0}}),"pen"===this.currentToolbar&&s.freeHandDraw(!0)):((n=s.element.querySelector(".e-img-pan .e-btn"))&&n.classList.add("e-selected-btn"),s.pan(!0),s.notify("transform",{prop:"setDisablePan",onPropertyChange:!1,value:{bool:!1}})),p&&s.zoomSettings.zoomFactor>=s.zoomSettings.maxZoomFactor?(p.classList.add("e-disabled"),p.parentElement.classList.add("e-overlay")):p&&(p.classList.remove("e-disabled"),p.parentElement.classList.remove("e-overlay")),this.refreshToolbar("main");break;case"cancel":s.notify("draw",{prop:"performCancel",value:{isContextualToolbar:t,isFinalCancel:!0}});break;case"ok":s.okBtn(null,!0),s.drawingShape=null,this.refreshDropDownBtn(!1),this.currentToolbar="main",s.isStraightening=!1,s.notify("draw",{prop:"resetTempObjColl"}),s.notify("draw",{prop:"resetTempPointColl"});break;case"crop":s.notify("transform",{prop:"disableZoomOutBtn",value:{isZoomOut:!0}}),O.Browser.isDevice&&this.updateContextualToolbar("color","straighten");break;case"reset":s.reset(),this.imageHeight=null,this.imageWidth=null,s.aspectHeight=null,s.aspectWidth=null,this.isAspectRatio=!0,this.currentToolbar="main";break;case"undo":s.noPushUndo=!1,(s.togglePen||s.drawingShape)&&(s.okBtn(),s.drawingShape=null),s.notify("undo-redo",{prop:"call-undo"});break;case"redo":s.noPushUndo=!1,(s.togglePen||s.drawingShape)&&(s.okBtn(),s.drawingShape=null),s.notify("undo-redo",{prop:"call-redo"});break;case"aspectratio":(!s.isCircleCrop&&O.isNullOrUndefined(s.currSelectionPoint)||s.currSelectionPoint&&"crop-circle"!==s.currSelectionPoint.shape)&&(O.getComponent(d,"numerictextbox").value?(s.aspectWidth=O.getComponent(d,"numerictextbox").value,s.aspectHeight=O.getComponent(h,"numerictextbox").value,s.notify("transform",{prop:"resize",value:{width:s.aspectWidth,height:null,isAspectRatio:!0}})):O.getComponent(h,"numerictextbox").value&&(s.aspectWidth=parseFloat(O.getComponent(d,"numerictextbox").placeholder),s.aspectHeight=O.getComponent(h,"numerictextbox").value,s.notify("transform",{prop:"resize",value:{width:s.aspectWidth,height:s.aspectHeight,isAspectRatio:!0}})),s.resizeSrc={startX:s.img.srcLeft,startY:s.img.srcTop,width:s.img.srcWidth,height:s.img.srcHeight},this.refreshToolbar("resize"));break;case"nonaspectratio":(O.getComponent(d,"numerictextbox").value||O.getComponent(h,"numerictextbox").value)&&(s.aspectWidth=O.getComponent(d,"numerictextbox").value?O.getComponent(d,"numerictextbox").value:parseFloat(O.getComponent(d,"numerictextbox").placeholder),s.aspectHeight=O.getComponent(h,"numerictextbox").value?O.getComponent(h,"numerictextbox").value:parseFloat(O.getComponent(h,"numerictextbox").placeholder),s.notify("transform",{prop:"resize",value:{width:s.aspectWidth,height:s.aspectHeight,isAspectRatio:!1}})),s.resizeSrc={startX:s.img.srcLeft,startY:s.img.srcTop,width:s.img.srcWidth,height:s.img.srcHeight},this.refreshToolbar("resize");break;case"resize":s.currObjType.isFiltered&&s.okBtn(),this.resizeClick();break;case"adjustment":o||(s.currObjType.isFiltered&&s.okBtn(),this.refreshToolbar("adjustment"),s.setTempFilterProperties(),s.notify("draw",{prop:"updateFinetune"}),s.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":i||(u.showSpinner(s.element),this.refreshToolbar("filter"),s.setTempFilterProperties(),u.hideSpinner(s.element));break;case"default":case"chrome":case"cold":case"warm":case"grayscale":case"blackandwhite":case"sepia":case"invert":case"sharpen":s.currObjType.isFiltered=!0,s.notify("filter",{prop:"applyImageFilter",value:{option:e}});break;case"upload":r&&s.element.querySelector(".e-contextual-toolbar-wrapper").classList.remove("e-hide");break;case"bold":s.notify("selection",{prop:"setInitialTextEdit",value:{bool:!1}}),s.activeObj.textSettings.bold&&s.activeObj.textSettings.italic?s.notify("shape",{prop:"applyFontStyle",onPropertyChange:!1,value:{item:"italic"}}):s.activeObj.textSettings.bold&&!s.activeObj.textSettings.italic?s.notify("shape",{prop:"applyFontStyle",onPropertyChange:!1,value:{item:"default"}}):!s.activeObj.textSettings.bold&&s.activeObj.textSettings.italic?s.notify("shape",{prop:"applyFontStyle",onPropertyChange:!1,value:{item:"bolditalic"}}):s.activeObj.textSettings.bold||s.activeObj.textSettings.italic||s.notify("shape",{prop:"applyFontStyle",onPropertyChange:!1,value:{item:"bold"}}),s.element.querySelector("#"+l+"_bold").classList.contains("e-selected-btn")?s.element.querySelector("#"+l+"_bold").classList.remove("e-selected-btn"):s.element.querySelector("#"+l+"_bold").classList.add("e-selected-btn"),0===s.activeObj.activePoint.width&&0===s.activeObj.activePoint.height||s.notify("undo-redo",{prop:"updateUndoRedoStack",onPropertyChange:!1});break;case"italic":s.notify("selection",{prop:"setInitialTextEdit",value:{bool:!1}}),s.activeObj.textSettings.bold&&s.activeObj.textSettings.italic?s.notify("shape",{prop:"applyFontStyle",onPropertyChange:!1,value:{item:"bold"}}):s.activeObj.textSettings.bold&&!s.activeObj.textSettings.italic?s.notify("shape",{prop:"applyFontStyle",onPropertyChange:!1,value:{item:"bolditalic"}}):!s.activeObj.textSettings.bold&&s.activeObj.textSettings.italic?s.notify("shape",{prop:"applyFontStyle",onPropertyChange:!1,value:{item:"default"}}):s.activeObj.textSettings.bold||s.activeObj.textSettings.italic||s.notify("shape",{prop:"applyFontStyle",onPropertyChange:!1,value:{item:"italic"}}),s.element.querySelector("#"+l+"_italic").classList.contains("e-selected-btn")?s.element.querySelector("#"+l+"_italic").classList.remove("e-selected-btn"):s.element.querySelector("#"+l+"_italic").classList.add("e-selected-btn"),0===s.activeObj.activePoint.width&&0===s.activeObj.activePoint.height||s.notify("undo-redo",{prop:"updateUndoRedoStack",onPropertyChange:!1});break;case"croptransform":this.performCropTransformClick();break;case"rotateleft":case"rotateright":case"horizontalflip":case"verticalflip":s.transformSelect(e),"rotateleft"!==e&&"rotateright"!==e||(s.notify("draw",{prop:"resetStraightenDestPoints"}),s.notify("draw",{prop:"setDestForStraighten"})),s.notify("transform",{prop:"disableZoomOutBtn",value:{isZoomOut:!0}}),O.Browser.isDevice&&this.updateContextualToolbar("color","straighten");break;case"save":s.noPushUndo=!1,s.okBtn(),s.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(),s.element.querySelector("#"+l+"_"+e)&&s.element.querySelector("#"+l+"_"+e).classList.add("e-selected-btn"),s.frameObj.type=e,s.frameObj.size=20,s.frameObj.inset=20,s.frameObj.radius=0,s.frameObj.amount=1,s.frameObj.offset="inset"===e?60:20,this.refreshToolbar("frame"),s.notify("draw",{prop:"render-image",value:{isMouseWheel:null,isPreventClearRect:null,isFrame:!0}}),s.isFrameBtnClick=!0,s.curFrameObjEvent={previousFrameSetting:s.tempFrameObj,currentFrameSetting:s.frameObj}}},Y.prototype.frameToolbarClick=function(){var e,t,o=this.parent,i=o.element.id,r=document.querySelector("#"+i+"_frame");o.notify("draw",{prop:"updateCropSelection",onPropertyChange:!1}),o.currObjType.isFiltered&&o.okBtn(),r&&!r.classList.contains("e-disabled")&&(r=o.transform.zoomFactor,o.frameDestPoints=O.extend({},o.img,{},!0),O.isNullOrUndefined(o.cxtTbarHeight)&&(e=O.extend({},o.frameObj,{},!0),t=O.extend({},o.tempFrameObj,{},!0),this.callFrameToolbar(),o.frameObj.type="mat",this.callFrameToolbar(),o.cxtTbarHeight=o.element.querySelector("#"+i+"_customizeWrapper").scrollHeight,o.frameObj=e,o.tempFrameObj=t),this.zoomToFrameRange(),o.tempFrameZoomLevel=r,O.Browser.isDevice?o.img.destTop-=o.cxtTbarHeight/2:o.img.destTop+=o.cxtTbarHeight/2,this.callFrameToolbar())},Y.prototype.zoomToFrameRange=function(){for(var e=this.parent,t=(this.isFrameToolbar=!1,e.notify("transform",{prop:"resetZoom",onPropertyChange:!1}),!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},Y.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")},Y.prototype.callFrameToolbar=function(){var e=this.parent,t=(O.extend(e.tempFrameObj,e.frameObj),{appliedUndoRedoColl:[]});e.notify("undo-redo",{prop:"getAppliedUndoRedoColl",value:{obj:t}}),0===t.appliedUndoRedoColl.length&&(e.notify("filter",{prop:"getCurrentObj",onPropertyChange:!(t={currObj:{}}),value:{object:t}}),e.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"frame",previousObj:t.currObj,previousObjColl:t.currObj.objColl,previousPointColl:t.currObj.pointColl,previousSelPointColl:t.currObj.selPointColl,previousCropObj:O.extend({},e.cropObj,{},!0),previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}})),this.refreshToolbar("frame")},Y.prototype.contextualToolbarClicked=function(e){var t=this.parent,o=t.element.querySelector(".e-contextual-toolbar-wrapper .e-toolbar-item.e-selected"),o=(o&&o.classList.remove("e-selected"),e.item.id.replace(t.element.id,"").split("_")[1]),i={filter:t.toPascalCase(o),cancel:!1};t.trigger("imageFiltering",i),i.cancel||(document.getElementById(e.item.id+"Canvas").parentElement.parentElement.classList.add("e-selected"),t.currObjType.isFiltered=!0,t.notify("filter",{prop:"applyImageFilter",value:{option:o.toLowerCase()}}),t.notify("draw",{prop:"redrawDownScale"}),t.currentFilter=e.item.id,this.enableDisableTbrBtn(),t.isFilterCanvasClick=!0,t.curFilterObjEvent=i)},Y.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))},Y.prototype.zoomInBtnClickHandler=function(e){if(e){var t=this.parent;if((t.zoomSettings.zoomTrigger&v.ZoomTrigger.Toolbar)===v.ZoomTrigger.Toolbar){t.noPushUndo=!1,t.currObjType.isFiltered&&t.okBtn();var o=t.drawingShape;if(t.drawingShape&&(i=t.activeObj.currIndex,t.noPushUndo=!0,t.okBtn(),t.noPushUndo=!1,t.drawingShape=null,i)&&t.selectShape(i),this.refreshShapeDrawing(),O.Browser.isDevice&&"touchstart"===e.type){if(!e.returnValue)return;e.preventDefault()}var i=document.querySelector("#"+t.element.id+"_zoomIn"),e=(O.EventHandler.trigger(i,"click"),{bool:!1});t.notify("selection",{prop:"getFreehandDrawEditing",onPropertyChange:!1,value:{obj:e}}),e.bool&&(t.notify("freehand-draw",{prop:"applyFhd",onPropertyChange:!1}),this.destroyQuickAccessToolbar()),t.isZoomBtnClick=!0,this.applyPreviewFilter(),t.currObjType.isFiltered=!1,t.togglePen&&(t.currObjType.isZoomed=!0,t.freeHandDraw(!1),t.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"ok"}})),t.notify("draw",{prop:"resetCurrentSelectionPoint"}),t.drawingShape=o,t.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:.1,zoomPoint:null,isResize:null}}),t.notify("draw",{prop:"redrawDownScale"}),(t.isCropTab||t.activeObj.shape)&&(t.notify("draw",{prop:"setStraightenActObj",value:{activeObj:null}}),t.notify("freehand-draw",{prop:"resetStraightenPoint"})),t.isStraightening&&(t.notify("draw",{prop:"resetStraightenDestPoints"}),t.notify("draw",{prop:"setDestForStraighten"}))}}},Y.prototype.zoomOutBtnClickHandler=function(e){if(e){var t=this.parent;if((t.zoomSettings.zoomTrigger&v.ZoomTrigger.Toolbar)===v.ZoomTrigger.Toolbar){t.noPushUndo=!1,t.currObjType.isFiltered&&t.okBtn();var o=t.drawingShape;if(t.drawingShape&&(i=t.activeObj.currIndex,t.noPushUndo=!0,t.okBtn(),t.noPushUndo=!1,t.drawingShape=null,i)&&t.selectShape(i),this.refreshShapeDrawing(),O.Browser.isDevice&&"touchstart"===e.type){if(!e.returnValue)return;e.preventDefault()}var i=document.querySelector("#"+t.element.id+"_zoomOut"),e=(O.EventHandler.trigger(i,"click"),{bool:!1});t.notify("selection",{prop:"getFreehandDrawEditing",onPropertyChange:!1,value:{obj:e}}),e.bool&&(t.notify("freehand-draw",{prop:"applyFhd",onPropertyChange:!1}),this.destroyQuickAccessToolbar()),t.isZoomBtnClick=!0,this.applyPreviewFilter(),t.currObjType.isFiltered=!1,t.togglePen&&(t.currObjType.isZoomed=!0,t.freeHandDraw(!1),t.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"ok"}})),t.notify("draw",{prop:"resetCurrentSelectionPoint"}),t.drawingShape=o,t.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:-.1,zoomPoint:null,isResize:null}}),t.notify("draw",{prop:"redrawDownScale"}),(t.isCropTab||t.activeObj.shape)&&(t.notify("draw",{prop:"setStraightenActObj",value:{activeObj:null}}),t.notify("freehand-draw",{prop:"resetStraightenPoint"})),t.isStraightening&&(t.notify("draw",{prop:"resetStraightenDestPoints"}),t.notify("draw",{prop:"setDestForStraighten"}))}}},Y.prototype.zoomInBtnMouseDownHandler=function(e){e.preventDefault(),this.zoomBtnHold=setInterval(this.zoomInBtnClickHandler.bind(this),250)},Y.prototype.zoomOutBtnMouseDownHandler=function(e){e.preventDefault(),this.zoomBtnHold=setInterval(this.zoomOutBtnClickHandler.bind(this),250)},Y.prototype.zoomBtnMouseUpHandler=function(){clearInterval(this.zoomBtnHold),this.zoomBtnHold=0},Y.prototype.closeContextualToolbar=function(){var e=this.parent,t=e.element.id,o=!1,i=e.isStraightening;return(!O.Browser.isDevice||O.Browser.isDevice&&!i)&&(e.element.querySelector("#"+t+"_contextualToolbar")&&!e.element.querySelector("#"+t+"_contextualToolbar").parentElement.classList.contains("e-hide")||e.element.querySelector("#"+t+"_headWrapper")&&!e.element.querySelector("#"+t+"_headWrapper").parentElement.classList.contains("e-hide"))&&(e.element.querySelector(".e-contextual-toolbar-wrapper").classList.add("e-hide"),e.okBtn(),this.refreshMainToolbar(),o=!0),o},Y.prototype.destroyQuickAccessToolbar=function(){var e=this.parent.element.id,t=document.getElementById(e+"_quickAccessToolbar"),t=(t&&t.classList.contains("e-control")&&O.getComponent(t,"toolbar").destroy(),document.getElementById(e+"_quickAccessToolbarArea"));t&&(t.style.display="none")},Y.prototype.renderSlider=function(e,t){var o,i,r,n=this.parent,a=n.element.id,s=document.querySelector("#"+a+"_contextualToolbarArea"),l=document.querySelector("#"+a+"_headWrapper"),p=document.querySelector("#"+a+"_labelWrapper"),p=(l&&(l.remove(),p.remove()),l=s.appendChild(n.createElement("div",{id:a+"_headWrapper",styles:"position: relative"})),(p="transparency"===e?l.appendChild(n.createElement("label",{id:a+"_labelWrapper",className:"e-ie-finetune-slider-label",styles:O.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;"})):l.appendChild(n.createElement("label",{id:a+"_labelWrapper",className:"e-ie-finetune-slider-label",styles:O.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(n.toPascalCase("transparency"===e?"opacity":e)),l.appendChild(n.createElement("div",{id:a+"_sliderWrapper",className:"e-ie-finetune-slider-wrap",styles:"position: absolute"}))),h=n.getCurrAdjustmentValue(e);t&&"straighten"===e&&O.Browser.isDevice&&(h=n.cropObj.straighten),"brightness"===e||"contrast"===e||"saturation"===e||"exposure"===e?(i=n.finetuneSettings?"brightness"===e&&n.finetuneSettings.brightness?(o=n.finetuneSettings.brightness.min,n.finetuneSettings.brightness.max):"contrast"===e&&n.finetuneSettings.contrast?(o=n.finetuneSettings.contrast.min,n.finetuneSettings.contrast.max):"saturation"===e&&n.finetuneSettings.saturation?(o=n.finetuneSettings.saturation.min,n.finetuneSettings.saturation.max):"exposure"===e&&n.finetuneSettings.exposure?(o=n.finetuneSettings.exposure.min,n.finetuneSettings.exposure.max):(o=-100,100):(o=-100,100),r=this.createSlider(o,i,h,e)):"hue"===e||"blur"===e||"opacity"===e?(i=n.finetuneSettings?"hue"===e&&n.finetuneSettings.hue?(o=n.finetuneSettings.hue.min,n.finetuneSettings.hue.max):"blur"===e&&n.finetuneSettings.blur?(o=n.finetuneSettings.blur.min,n.finetuneSettings.blur.max):"opacity"===e&&n.finetuneSettings.opacity?(o=n.finetuneSettings.opacity.min,n.finetuneSettings.opacity.max):(o=0,100):(o=0,100),r=this.createSlider(o,i,h,e)):"transparency"===e?r=this.createSlider(o=0,i=100,h,e):"straighten"===e&&(r=this.createSlider(o=-45,i=45,h,e)),r.appendTo("#"+a+"_sliderWrapper"),p.style.left=(parseFloat(s.style.width)-parseFloat(r.width))/2+"px","straighten"===e&&O.Browser.isDevice&&(l.appendChild(n.createElement("label",{id:a+"_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=n.transform.straighten.toString()+"°",p.parentElement.classList.add("e-straighten-slider")),"straighten"!==e&&(l.appendChild(n.createElement("label",{id:a+"_finetuneSpan",className:"e-ie-finetune-value-span",styles:O.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;"})),p.parentElement.classList.add("e-finetune-slider"),"transparency"===e&&O.Browser.isDevice&&p.parentElement.classList.add("e-ie-device-transparency-slider"),this.updateFinetuneSpan(e))},Y.prototype.createSlider=function(e,t,o,r){var n=this,a=this.parent;return new g.Slider({value:o,type:"MinRange",min:e,max:t,step:"straighten"===r?3:1,width:O.Browser.isDevice?"180px":"straighten"===r?"200px":"300px",cssClass:"e-slider",change:function(e){var t,o,i;a.notify("selection",{prop:"setSliderActive",onPropertyChange:!1,value:{bool:!0}}),"transparency"===r?a.activeObj.shape&&(O.isNullOrUndefined(a.activeObj.imageRatio)&&a.notify("shape",{prop:"updImgRatioForActObj",onPropertyChange:!1}),a.notify("shape",{prop:"pushActItemIntoObj"}),t=O.extend({},a.cropObj,{},!0),a.notify("filter",{prop:"getCurrentObj",onPropertyChange:!(o={currObj:{}}),value:{object:o}}),(o=o.currObj).objColl=O.extend([],a.objColl,[],!0),o.pointColl=O.extend([],a.pointColl,[],!0),o.afterCropActions=O.extend([],a.afterCropActions,[],!0),a.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!(i={selPointColl:null}),value:{obj:i}}),o.selPointColl=O.extend([],i.selPointColl,[],!0),a.objColl.pop(),a.activeObj.opacity=e.value/100,n.upperContext.clearRect(0,0,a.upperCanvas.width,a.upperCanvas.height),a.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate"}}),a.objColl.push(a.activeObj),a.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"shapeTransform",previousObj:o,previousObjColl:o.objColl,previousPointColl:o.pointColl,previousSelPointColl:o.selPointColl,previousCropObj:t,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),a.notify("selection",{prop:"redrawShape",value:{obj:a.objColl[a.objColl.length-1]}}),n.updateFinetuneSpan(r)):"straighten"===r?a.setStraighten(e.value):(a.transform.zoomFactor&&a.transform.zoomFactor<0&&(a.isFinetuning=!0),a.notify("selection",{prop:"setSliding",value:{bool:!0}}),a.setCurrAdjustmentValue(r,e.value),n.updateFinetuneSpan(r),n.enableDisableTbrBtn(),a.isFinetuning=!1)},changed:function(){"transparency"!==r&&"straighten"!==r&&(a.notify("selection",{prop:"setSliding",value:{bool:!1}}),a.notify("draw",{prop:"redrawDownScale"})),a.notify("selection",{prop:"setSliderActive",onPropertyChange:!1,value:{bool:!1}}),"transparency"===r&&(a.notify("undo-redo",{prop:"updateUndoRedoStack",onPropertyChange:!1}),a.element.querySelector("#"+a.element.id+"_transparency").click())}})},Y.prototype.updateFinetuneSpan=function(e){var t=this.parent,o=t.element.querySelector(".e-ie-finetune-value-span");o&&(t.notify("filter",{prop:"getAdjustmentLevel",onPropertyChange:!(t={adjustmentLevel:null}),value:{obj:t}}),o.innerHTML=Math.round(t.adjustmentLevel[e]).toString())},Y.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)},Y.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=document.querySelector(o[t]);if(i&&i.classList.contains("e-selected-btn")){i.classList.remove("e-selected-btn");break}}},Y.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")},Y.prototype.refreshSlider=function(){var e=this.parent.element.id,t=document.querySelector("#"+e+"_sliderWrapper"),o=document.querySelector(".e-slider"),e=document.querySelector("#"+e+"_headWrapper");e&&(e.style.display="none"),t&&o&&(o.ej2_instances[0].destroy(),t.remove())},Y.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=document.querySelector(o[t]);if(i.classList.contains("e-selected-btn")){i.classList.remove("e-selected-btn");break}}},Y.prototype.updateToolbarItems=function(){var e=this.parent,t=e.element.id;if(e.isImageLoaded&&this.isToolbar()){var o,i=e.element.querySelector(".e-fill.e-template .e-dropdownbtn-preview"),r=e.element.querySelector(".e-stroke.e-template .e-dropdownbtn-preview"),n=e.element.querySelector(".e-text-font-color.e-template .e-dropdownbtn-preview"),a=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("#"+t+"_bold"),d=e.element.querySelector("#"+t+"_italic");if(e.activeObj.strokeSettings&&e.activeObj.textSettings){if(O.isNullOrUndefined(e.activeObj.strokeSettings.strokeWidth)&&(e.activeObj.strokeSettings.strokeWidth=2),i&&(o=e.activeObj.strokeSettings.fillColor,""===e.activeObj.strokeSettings.fillColor?i.classList.add("e-nocolor-item"):(i.classList.remove("e-nocolor-item"),i.style.background=o),document.querySelector("#"+t+"_shape_fill"))&&(O.getComponent(t+"_shape_fill","colorpicker").value=o),r&&(o=e.activeObj.strokeSettings.strokeColor,r.style.background=o,document.querySelector("#"+t+"_shape_stroke"))&&(O.getComponent(t+"_shape_stroke","colorpicker").value=o),n&&(o=e.activeObj.strokeSettings.strokeColor,n.style.background=o,document.querySelector("#"+t+"_text_font"))&&(O.getComponent(t+"_text_font","colorpicker").value=o),a&&(o=e.activeObj.strokeSettings.strokeColor,a.style.background=o,document.querySelector("#"+t+"_pen_stroke")&&(O.getComponent(t+"_pen_stroke","colorpicker").value=o),e.notify("freehand-draw",{prop:"getPenOpacity",onPropertyChange:!1,value:{obj:{penOpacity:1}}})),l&&(O.Browser.isDevice?l.setAttribute("style","font-family:"+e.activeObj.textSettings.fontFamily.toLowerCase()):l.textContent=e.activeObj.textSettings.fontFamily),p)for(var c=0;c<e.fontSizeColl.length;c++)if(parseInt(e.fontSizeColl[c].text,10)>=Math.round(e.activeObj.textSettings.fontSize)){p.textContent=(c+1).toString();break}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&&(i=Math.round(e.activeObj.strokeSettings.strokeWidth).toString(),s.textContent=this.getStrokeWidth(i))}}},Y.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},Y.prototype.cancelPan=function(){var e=this.parent,t=(e.notify("shape",{prop:"applyActObj",onPropertyChange:!1,value:{isMouseDown:!0}}),e.element.querySelector(".e-img-pan .e-btn"));t&&t.classList.remove("e-selected-btn"),e.pan(!1)},Y.prototype.refreshMainToolbar=function(){"main"!==this.currToolbar&&this.refreshToolbar("main")},Y.prototype.destroySubComponents=function(){for(var e=this.parent,t=e.element.querySelectorAll("input.e-control"),o=e.element.querySelectorAll("button.e-control"),i=0,r=t.length;i<r;i++)t[i].classList.contains("e-color-picker")&&(O.getComponent(t[i],"color-picker").destroy(),O.detach(O.select("input#"+t[i].id,e.element)));for(i=0,r=o.length;i<r;i++)o[i].classList.contains("e-dropdown-btn")?(O.getComponent(o[i],"dropdown-btn").destroy(),O.detach(O.select("button#"+o[i].id,e.element))):o[i].classList.contains("e-btn")&&(O.getComponent(o[i],"btn").destroy(),O.detach(O.select("button#"+o[i].id,e.element)))},Y.prototype.setInitialShapeSettings=function(e){var t=this.parent,e=(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=[],{order:null});t.notify("shape",{prop:"getNewOrder",onPropertyChange:!1,value:{obj:e}}),t.activeObj.order=e.order},Y.prototype.isToolbarString=function(e){for(var t=!1,o=0;o<e.length;o++)if("string"==typeof e[o]){t=!0;break}return t},Y.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;0<=o;o--)this.defToolbarItems.splice(r[o],1)},Y.prototype.isSameIndex=function(e,t){for(var o=0;o<e.length;o++)if(e[o]===t)return!0;return!1},Y.prototype.getIndex=function(e){var t=-1,o=!1;"fontColor"===(e="arrowEnd"===(e="arrowStart"===(e="verticalFlip"===(e="horizontalFlip"===(e="rotateRight"===(e="rotateLeft"===e?"rotLeft":e)?"rotRight":e)?"hflip":e)?"vflip":e)?"start":e)?"end":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},Y.prototype.getModuleName=function(){return"toolbar-module"};var q=Y;function Y(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()}v.Crop=o,v.Draw=i,v.Export=r,v.Filter=a,v.FinetuneSettings=U,v.FontFamily=N,v.FreehandDrawing=l,v.ImageEditor=j,v.Selection=h,v.SelectionSettings=_,v.Shape=H,v.ToolbarModule=q,v.Transform=B,v.UndoRedo=M,v.ZoomSettings=W,Object.defineProperty(v,"__esModule",{value:!0})});
|
|
10
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@syncfusion/ej2-base"),require("@syncfusion/ej2-popups"),require("@syncfusion/ej2-inputs"),require("@syncfusion/ej2-navigations"),require("@syncfusion/ej2-buttons"),require("@syncfusion/ej2-splitbuttons")):"function"==typeof define&&define.amd?define(["exports","@syncfusion/ej2-base","@syncfusion/ej2-popups","@syncfusion/ej2-inputs","@syncfusion/ej2-navigations","@syncfusion/ej2-buttons","@syncfusion/ej2-splitbuttons"],t):t((e=e||self).ej={},e.ej2Base,e.ej2Popups,e.ej2Inputs,e.ej2Navigations,e.ej2Buttons,e.ej2Splitbuttons)}(this,function(v,O,u,g,d,L,f){"use strict";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":O.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 t,o=this.parent,i=O.isNullOrUndefined(e),r=o.element.querySelector("#"+o.element.id+"_nonaspectratio"),n=o.activeObj.activePoint,a=o.img,s=!1,l=0,p=o.rotateFlipColl.length;l<p;l++){var h=o.rotateFlipColl[l];90!==h&&-90!==h||(s=!0)}o.notify("draw",{prop:"setImageEdited",onPropertyChange:!1}),(i||r)&&(this.croppedDegree=o.transform.degree),i&&0!==o.transform.degree||s?(this.updateCropObj(),t={startX:a.destLeft,startY:a.destTop,width:a.destWidth,height:a.destHeight},o.notify("transform",{prop:"setCurrDestinationPoint",onPropertyChange:!1,value:{point:t}}),this.rotateCrop()):i&&""!==o.transform.currFlipState?(this.updateCropObj(),t={startX:a.destLeft,startY:a.destTop,width:a.destWidth,height:a.destHeight},o.notify("transform",{prop:"setCurrDestinationPoint",onPropertyChange:!1,value:{point:t}}),this.flipCrop()):(this.adjustStraightenForShapes("initial",!1),o.notify("draw",{prop:"setTempZoomFactor",onPropertyChange:!1,value:{tempZoomFactor:o.transform.zoomFactor}}),r=this.calcRatio(),!i&&e||(this.updateCropObj(),o.notify("draw",{prop:"resetPanPoints",onPropertyChange:!1}),o.notify("shape",{prop:"updImgRatioForActObj",onPropertyChange:!1}),t={startX:a.destLeft,startY:a.destTop,width:a.destWidth,height:a.destHeight},o.notify("transform",{prop:"setCurrDestinationPoint",onPropertyChange:!1,value:{point:t}}),o.currSelectionPoint=O.extend({},o.activeObj,{},!0),this.cropDestPoints={startX:a.destLeft,startY:a.destTop,width:a.destWidth,height:a.destHeight}),o.notify("transform",{prop:"calcMaxDimension",onPropertyChange:!(i={width:0,height:0}),value:{width:n.width*r.width,height:n.height*r.height,obj:i,isImgShape:null}}),e=i,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:n.startX*r.width-a.destLeft*r.width,srcTop:n.startY*r.height-a.destTop*r.height,srcWidth:n.width*r.width,srcHeight:n.height*r.height,destLeft:(o.lowerCanvas.clientWidth-e.width)/2,destTop:(o.lowerCanvas.clientHeight-e.height+1)/2,destWidth:e.width,destHeight:e.height},t=this.lowerContext.filter,o.notify("draw",{prop:"drawImage",onPropertyChange:!1}),this.lowerContext.filter="none",i=O.extend({},o.activeObj,{},!0),this.cropObjColl(),o.transform.straighten=0,o.activeObj=i,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=t,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=o.img.destLeft+o.img.destWidth/2,r=o.img.destTop+o.img.destHeight/2,n=0,a=o.objColl;n<a.length;n++){var s,l,p,h,d,c,u,g,v=a[n];-1===["rectangle","ellipse","text","image"].indexOf(v.shape)||!t&&0===v.rotatedAngle||(s=(u=v.activePoint).startX,g=u.startY,l=u.width,u=u.height,c="initial"===e?v.rotatedAngle:-v.rotatedAngle,p=s+l/2-i,h=g+u/2-r,d=Math.cos(c),g=(c=Math.sin(c))*p+d*h+r-g-u/2,v.activePoint.startX+=u=d*p-c*h+i-s-l/2,v.activePoint.startY+=g,v.activePoint.endX+=u,v.activePoint.endY+=g)}},e.prototype.updateCropObj=function(){this.parent.afterCropActions=[];var e={currObj:{}},e=(this.parent.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:e}}),e.currObj);e.straighten=this.parent.transform.straighten,this.parent.cropObj=O.extend({},e,{},!0)},e.prototype.rotateCrop=function(){for(var e,t=this.parent,o=this.getCurrFlipState(),i=t.activeObj.shape||"",r=(t.notify("shape",{prop:"updImgRatioForActObj",onPropertyChange:!1}),t.currSelectionPoint=O.extend({},t.activeObj,{},!0),t.objColl.push(t.activeObj),t.activeObj=O.extend({},t.objColl[t.objColl.length-1],{},!0),O.extend({},t.objColl[t.objColl.length-1],{},!0),O.extend({},t.currSelectionPoint,{},!0)),n={bool:null},a=(t.notify("transform",{prop:"getPreventSelect",onPropertyChange:!1,value:{obj:n}}),t.notify("transform",{prop:"setPreventSelect",onPropertyChange:!1,value:{bool:!0}}),O.extend([],t.rotateFlipColl,[],!0)),s=(this.panToSelRangle(!0),e=O.extend({},t.objColl[t.objColl.length-1],{},!0),this.upperContext.clearRect(0,0,t.upperCanvas.width,t.upperCanvas.height),t.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate",obj:e}}),t.objColl.pop(),t.notify("shape",{prop:"updImgRatioForActObj",onPropertyChange:!1}),t.objColl.push(t.activeObj),t.transform.straighten),l=(0!==s&&(t.transform.straighten=0,t.straightenBaseImageCanvas(),t.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"zoom",pen:"zoom",isPreventApply:null}}),t.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),t.notify("draw",{prop:"render-image",value:{isMouseWheel:!1}})),this.resetZoom(),O.extend([],t.afterCropActions,[],!0)),p=(this.revertTransform("initial",a),0!==s&&(t.transform.straighten="horizontal"===o||"vertical"===o?-s:s,t.straightenBaseImageCanvas(),t.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"zoom",pen:"zoom",isPreventApply:null}}),t.notify("draw",{prop:"render-image",value:{isMouseWheel:!1}}),t.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"zoom",pen:"zoom",isPreventApply:null}})),e=O.extend({},t.objColl[t.objColl.length-1],{},!0),this.upperContext.clearRect(0,0,t.upperCanvas.width,t.upperCanvas.height),t.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate",obj:e}}),t.objColl.pop(),t.transform.degree=0,{isIntersect:null}),h=(t.notify("draw",{prop:"updateImgCanvasPoints",onPropertyChange:!1}),t.notify("draw",{prop:"isLinesIntersect",onPropertyChange:!1,value:{obj:p}}),0);0!==s&&p.isIntersect&&50!=++h;)t.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:.025,zoomPoint:null},isResize:null}),t.notify("draw",{prop:"updateImgCanvasPoints",onPropertyChange:!1}),t.notify("draw",{prop:"isLinesIntersect",onPropertyChange:!1,value:{obj:p}});this.cropImg(!0),this.revertTransform("reverse",a),t.afterCropActions=l,t.currSelectionPoint=r,t.notify("transform",{prop:"setPreventSelect",onPropertyChange:!1,value:{bool:n.bool}}),t.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.lowerContext}}),t.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.upperContext}}),"crop-circle"===i&&this.cropCircle(this.lowerContext),this.upperContext.clearRect(0,0,t.upperCanvas.width,t.upperCanvas.height),t.notify("draw",{prop:"resetPanPoints",onPropertyChange:!1})},e.prototype.revertTransform=function(e,t){var o=this.parent,i={isRotate:!1};if("initial"===e)for(var r=t.length-1;0<=r;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 n,r=0,a=t.length;r<a;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())}})}}},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(0<e.transform.zoomFactor){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,t=this.parent,o=(t.notify("transform",{prop:"setReverseFlip",onPropertyChange:!1,value:{isReverseFlip:!0}}),t.panPoint.totalPannedPoint.x+=this.tempFlipPanPoint.x,t.panPoint.totalPannedPoint.y+=this.tempFlipPanPoint.y,t.transform.currFlipState),i={flipColl:null},i=(t.notify("transform",{prop:"getFlipColl",onPropertyChange:!1,value:{obj:i}}),i.flipColl),r=(t.notify("transform",{prop:"setFlipColl",onPropertyChange:!1,value:{flipColl:[]}}),t.notify("shape",{prop:"updImgRatioForActObj",onPropertyChange:!1}),t.objColl.push(t.activeObj),0===t.transform.degree&&(r=-t.cropObj.totalPannedPoint.x,e=-t.cropObj.totalPannedPoint.y,t.img.destLeft+=r,t.img.destTop+=e,t.notify("transform",{prop:"drawPannImage",value:{point:{x:r,y:e}}}),t.activeObj=O.extend({},t.objColl[t.objColl.length-1],{},!0),this.upperContext.clearRect(0,0,t.upperCanvas.width,t.upperCanvas.height),t.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate",obj:t.activeObj}}),t.objColl.pop(),t.notify("shape",{prop:"updImgRatioForActObj",onPropertyChange:!1}),t.objColl.push(t.activeObj)),this.resetZoom(),t.currSelectionPoint=O.extend({},t.objColl[t.objColl.length-1],{},!0),this.lowerContext.clearRect(0,0,t.lowerCanvas.width,t.lowerCanvas.height),this.upperContext.clearRect(0,0,t.upperCanvas.width,t.upperCanvas.height),this.lowerContext.filter);t.notify("draw",{prop:"drawImage",onPropertyChange:!1}),this.updateFlipState(),t.notify("shape",{prop:"redrawObj",onPropertyChange:!1,value:{degree:this.getCurrFlipState()}}),t.notify("freehand-draw",{prop:"flipFHDColl",onPropertyChange:!1,value:{value:this.getCurrFlipState()}}),t.activeObj=O.extend({},t.objColl[t.objColl.length-1],{},!0),t.objColl.pop(),this.upperContext.clearRect(0,0,t.upperCanvas.width,t.upperCanvas.height),t.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate"}}),this.cropImg(!0),t.notify("transform",{prop:"setReverseRotate",onPropertyChange:!1,value:{bool:!0}}),this.lowerContext.setTransform(1,0,0,1,0,0),t.notify("draw",{prop:"setDestPoints",onPropertyChange:!1}),t.notify("draw",{prop:"currTransState",onPropertyChange:!1,value:{type:"initial",isPreventDestination:null,context:null,isPreventCircleCrop:null}}),t.notify("draw",{prop:"drawImage",onPropertyChange:!1}),this.lowerContext.filter=r,t.notify("draw",{prop:"setRotateZoom",onPropertyChange:!1,value:{isRotateZoom:!1}}),t.notify("draw",{prop:"currTransState",onPropertyChange:!1,value:{type:"reverse",isPreventDestination:null,context:null,isPreventCircleCrop:null}}),t.transform.currFlipState=o,t.notify("transform",{prop:"setFlipColl",onPropertyChange:!1,value:{flipColl:i}}),this.lowerContext.filter="none",this.updateFlipState(),t.notify("shape",{prop:"redrawObj",onPropertyChange:!1,value:{degree:this.getCurrFlipState()}}),t.notify("freehand-draw",{prop:"flipFHDColl",onPropertyChange:!1,value:{value:this.getCurrFlipState()}}),t.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"zoom",pen:"zoom",isPreventApply:null}}),this.lowerContext.filter=r,(t.currSelectionPoint&&"crop-circle"===t.currSelectionPoint.shape||t.isCircleCrop)&&this.cropCircle(this.lowerContext),t.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),t.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.lowerContext}}),t.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.upperContext}}),this.upperContext.clearRect(0,0,t.upperCanvas.width,t.upperCanvas.height),t.notify("transform",{prop:"setReverseFlip",onPropertyChange:!1,value:{isReverseFlip:!1}}),t.notify("draw",{prop:"resetPanPoints",onPropertyChange:!1}),this.tempFlipPanPoint={x:0,y:0}},e.prototype.cropObjColl=function(){var e=this.parent;if(0<e.objColl.length)for(var t=0,o=e.objColl.length;t<o;t++){var i,r,n=(i=e.objColl[t]).activePoint,a=e.activeObj.activePoint,s=a.startX,l=a.startY,p=a.width,a=a.height,h=i.shape;i.imageRatio={startX:(n.startX-s)/p,startY:(n.startY-l)/a,endX:(n.endX-s)/p,endY:(n.endY-l)/a,width:p/n.width,height:a/n.height};switch(h){case"text":r=0===(r=0===i.shapeDegree?e.transform.degree:e.transform.degree-i.shapeDegree)||180===Math.abs(r)?n.width:n.height,i.textSettings.fontRatio=r/i.textSettings.fontSize;break;case"line":case"arrow":this.cropPointCollection(t),"arrow"===h&&e.notify("shape",{prop:"updateArrowRatio",onPropertyChange:!1,value:{obj:i}});break;case"path":this.cropPointCollection(t)}}},e.prototype.cropPointCollection=function(e){for(var t,o,i,r=this.parent,n=r.objColl[e].shape,a=r.activeObj.activePoint,s=r.img,l=s.destLeft,p=s.destTop,h=s.destWidth,s=s.destHeight,d="path"===n?(t=a.startX,o=a.startY,i=a.width,a.height):(t=l,o=p,i=h,s),c=r.objColl[e].pointColl,u=0,g=c.length;u<g;u++)c[u].ratioX=(c[u].x-t)/i,c[u].ratioY=(c[u].y-o)/d},e.prototype.cropFreehandDrawColl=function(){for(var e=this.parent,t=e.activeObj.activePoint,o=t.startX,i=t.startY,r=t.width,n=t.height,a=0;a<e.freehandCounter;a++){e.points=O.extend([],e.pointColl[a].points,[]),e.notify("freehand-draw",{prop:"setPointCounter",onPropertyChange:!1,value:{value:0}});for(var s=e.points.length,l=0;l<s;l++)e.points[l].ratioX=(e.points[l].x-o)/r,e.points[l].ratioY=(e.points[l].y-i)/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 t,o,i,r=this.parent,n=(r.allowDownScale=!1,this.cropDestPoints),a=this.lowerContext.filter,s=r.isCropTab,l=(r.img={srcLeft:0,srcTop:0,srcWidth:r.baseImgCanvas.width,srcHeight:r.baseImgCanvas.height,destLeft:n.startX,destTop:n.startY,destWidth:n.width,destHeight:n.height},r.img),p=r.currSelectionPoint,e=(this.lowerContext.clearRect(0,0,r.lowerCanvas.width,r.lowerCanvas.height),e&&r.notify("draw",{prop:"setDestPoints",onPropertyChange:!1}),r.notify("draw",{prop:"currTransState",onPropertyChange:!1,value:{type:"initial",isPreventDestination:null,context:null,isPreventCircleCrop:null}}),0===this.croppedDegree&&0===r.transform.degree&&p&&"crop-circle"!==p.shape&&"crop-square"!==p.shape&&(l.destLeft=n.startX,l.destTop=n.startY,l.destWidth=n.width,l.destHeight=n.height),0===r.transform.degree&&(l.destLeft+=r.panPoint.totalPannedInternalPoint.x,l.destTop+=r.panPoint.totalPannedInternalPoint.y),r.notify("draw",{prop:"drawImage",onPropertyChange:!1}),this.lowerContext.filter=a,r.notify("draw",{prop:"currTransState",onPropertyChange:!1,value:{type:"reverse",isPreventDestination:null,context:null,isPreventCircleCrop:!0}}),O.extend([],r.objColl,null,!0)),n=O.extend([],r.pointColl,null,!0),a={straightenPoint:null};r.notify("freehand-draw",{prop:"getStraightenPoint",onPropertyChange:!1,value:{obj:a}}),this.resetAnnotations(),O.isNullOrUndefined(r.activeObj.shape)&&r.cropObj.activeObj.shape&&(r.activeObj=O.extend({},r.cropObj.activeObj,null,!0)),this.panToSelRangle(),r.isCropTab=s,r.objColl=e,r.pointColl=n,r.freehandCounter=r.pointColl.length,a.straightenPoint.x&&a.straightenPoint.y&&r.notify("freehand-draw",{prop:"setStraightenPoint",onPropertyChange:!1,value:{x:a.straightenPoint.x,y:a.straightenPoint.y,ratioX:a.straightenPoint.ratioX,ratioY:a.straightenPoint.ratioY}}),r.cropObj.activeObj.shape?(s={startX:l.destLeft,startY:l.destTop,width:l.destWidth,height:l.destHeight},p&&p.activePoint&&(t=(p=p.activePoint).startX,o=p.startY,i=p.width,p=p.height,l.destLeft=t,l.destTop=o,l.destWidth=i,l.destHeight=p),r.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"zoom",pen:"zoom",isPreventApply:null}}),l.destLeft=s.startX,l.destTop=s.startY,l.destWidth=s.width,l.destHeight=s.height,r.notify("freehand-draw",{prop:"updateFHDColl",onPropertyChange:!1}),e=O.extend([],r.objColl,null,!0),n=O.extend([],r.pointColl,null,!0),r.notify("freehand-draw",{prop:"getStraightenPoint",onPropertyChange:!1,value:{obj:a}}),this.resetAnnotations(),r.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!(t={selPointColl:null}),value:{obj:t}}),o=t.selPointColl,r.notify("freehand-draw",{prop:"setSelPointColl",onPropertyChange:!1,value:{obj:{selPointColl:[]}}}),r.cropObj.filter=this.lowerContext.filter,i=O.extend({},r.currSelectionPoint,null,!0),r.notify("draw",{prop:"setCurrentObj",onPropertyChange:!1,value:{obj:null}}),r.activeObj=O.extend({},i,null,!0),p=O.extend({},r.activeObj,null,!0),r.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),r.currSelectionPoint=null,r.isCircleCrop=!1,0!==r.transform.degree&&(O.isNullOrUndefined(r.activeObj.shape)&&r.cropObj.activeObj.shape&&(r.activeObj=O.extend({},r.cropObj.activeObj,null,!0)),r.notify("transform",{prop:"drawPannedImage",value:{xDiff:0,yDiff:0}}),r.panPoint.currentPannedPoint={x:0,y:0}),r.objColl=e,r.pointColl=n,r.freehandCounter=r.pointColl.length,a.straightenPoint.x&&a.straightenPoint.y&&r.notify("freehand-draw",{prop:"setStraightenPoint",onPropertyChange:!1,value:{x:a.straightenPoint.x,y:a.straightenPoint.y,ratioX:a.straightenPoint.ratioX,ratioY:a.straightenPoint.ratioY}}),r.notify("freehand-draw",{prop:"setSelPointColl",onPropertyChange:!1,value:{obj:{selPointColl:o}}}),r.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"iterate",pen:"iterate",isPreventApply:null}}),this.adjustStraightenForShapes("reverse",!1),r.notify("freehand-draw",{prop:"updateFHDColl",onPropertyChange:!1,value:{isPreventApply:!0}}),r.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"zoom",pen:"zoom",isPreventApply:null}}),0===r.transform.degree?r.notify("transform",{prop:"drawPannImage",onPropertyChange:!1,value:{point:{x:0,y:0}}}):(O.isNullOrUndefined(r.activeObj.shape)&&r.cropObj.activeObj.shape&&(r.activeObj=O.extend({},r.cropObj.activeObj,null,!0)),r.notify("transform",{prop:"drawPannedImage",value:{xDiff:0,yDiff:0}}),r.panPoint.currentPannedPoint={x:0,y:0}),r.activeObj=p,r.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate"}}),r.notify("transform",{prop:"setTempPanMove",onPropertyChange:!1,value:{point:null}}),this.isInitCrop||0!==r.transform.degree||""===r.cropObj.currFlipState||0===r.cropObj.cropZoom?this.isInitCrop=!1:(this.isInitCrop=!0,r.notify("draw",{prop:"getStraightenActObj",onPropertyChange:!(l={activeObj:null}),value:{obj:l}}),r.notify("draw",{prop:"performCancel",value:{isContextualToolbar:null}}),r.notify("draw",{prop:"setStraightenActObj",onPropertyChange:!1,value:{activeObj:l.activeObj}}),r.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"croptransform",isApplyBtn:!1,isCropping:null,isZooming:null,cType:null}}))):(this.adjustStraightenForShapes("reverse",!0),r.notify("freehand-draw",{prop:"updateFHDColl",onPropertyChange:!1,value:{isPreventApply:!0}}),s=this.lowerContext.filter,this.lowerContext.filter="none",r.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"iterate",pen:"iterate",isPreventApply:null}}),this.lowerContext.filter=s,r.currSelectionPoint=null),document.querySelector(".e-ie-straighten-value-span")&&(document.querySelector(".e-ie-straighten-value-span").innerHTML=r.transform.straighten.toString()+"°")},e.prototype.panToSelRangle=function(e){var t=this.parent,o=t.cropObj.totalPannedClientPoint,i=0!==t.transform.degree?e?-o.x:o.x:0,e=0!==t.transform.degree?e?-o.y:o.y:0;0!==t.transform.degree&&(t.panPoint.currentPannedPoint={x:i,y:e},t.notify("transform",{prop:"drawPannedImage",value:{xDiff:i,yDiff:e}}),t.panPoint.currentPannedPoint={x:0,y:0})},e.prototype.cropCircle=function(e,t,o){var i=this.parent,r=i.img,n=r.destLeft,a=r.destTop,s=r.destWidth,r=r.destHeight,l=(o&&""!==i.transform.currFlipState&&i.notify("draw",{prop:"setTransform",onPropertyChange:!1,value:{context:e,value:i.transform.currFlipState,isReverse:null}}),e.filter),n=(e.filter="none",e.globalCompositeOperation="destination-in",e.beginPath(),O.isNullOrUndefined(t)?n+s/2:e.canvas.width/2),a=O.isNullOrUndefined(t)?a+r/2:e.canvas.height/2,r=t?e.canvas.width/2:s/2;e.arc(n,a,r,0,2*Math.PI),e.closePath(),e.fill(),e.restore(),e.globalCompositeOperation="source-over",i.currObjType.isActiveObj=i.isCircleCrop=!0,e.filter=l,o&&""!==i.transform.currFlipState&&i.notify("draw",{prop:"setTransform",onPropertyChange:!1,value:{context:e,value:i.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?1<o.flipColl.length?this.getCurrFlipState():e.transform.currFlipState:t},e.prototype.updateRotatePan=function(){var e,t,o,i,r=this.parent;O.isNullOrUndefined(r.panPoint.currentPannedPoint)||(i="",e=r.transform.degree,t=(o=r.panPoint.currentPannedPoint).x,o=o.y,i=0<r.rotateFlipColl.length&&"number"==typeof r.rotateFlipColl[0]&&e<0?this.getCurrCropState():this.getCurrFlipState(),e%90==0&&e%180!=0?90===e||-90===e&&("horizontal"===i||"vertical"===i)||-270===e&&(""===i||"verticalHorizontal"===i||"horizontalVertical"===i)?("horizontal"===i||""===i?r.img.destLeft+=o:r.img.destLeft-=o,""===i||"vertical"===i?r.img.destTop-=t:r.img.destTop+=t):270!==e&&(-270!==e||"horizontal"!==i&&"vertical"!==i)&&(-90!==e||""!==i&&"verticalHorizontal"!==i&&"horizontalVertical"!==i)||(""===i||"horizontal"===i?r.img.destLeft-=o:r.img.destLeft+=o,""===i||"vertical"===i?r.img.destTop+=t:r.img.destTop-=t):180!==e&&-180!==e||(""===i||"vertical"===i?r.img.destLeft-=t:r.img.destLeft+=t,""===i||"horizontal"===i?r.img.destTop-=o:r.img.destTop+=o))},e.prototype.crop=function(e){var t,o=this.parent,i=o.activeObj.activePoint,r=i.startX,n=i.startY,a=i.endX,i=i.endY;!o.disabled&&o.isImageLoaded&&(t={isCropToolbar:o.isCropToolbar},o.currObjType.isUndoAction&&!t.isCropToolbar&&o.notify("undo-redo",{prop:"refreshUrc",value:{bool:null}}),r={cancel:!1,startPoint:{x:r,y:n},endPoint:{x:a,y:i},preventScaling:!1},t.isCropToolbar||o.trigger("cropping",r),this.cropEvent(r,e,t))},e.prototype.cropEvent=function(e,t,o){var i,r,n=this.parent;e.cancel||(r=n.activeObj.shape?n.activeObj.shape.split("-"):[],!n.disabled&&n.activeObj.horTopLine&&(n.currObjType.isCustomCrop||0<r.length&&"crop"===r[0])&&(t.isCrop=!0,r=O.extend({},n.cropObj,{},!0),t=O.extend({},this.prevCropCurrObj,{},!0),e.preventScaling?this.isPreventScaling=!0:this.isPreventScaling=!1,this.cropImg(),this.isPreventScaling&&(n.aspectWidth=n.img.destWidth,n.aspectHeight=n.img.destHeight),n.notify("freehand-draw",{prop:"resetStraightenPoint"}),n.isCropTab=!1,n.transform.zoomFactor=0,n.setProperties({zoomSettings:{zoomFactor:1}},!0),n.notify("transform",{prop:"setPreviousZoomValue",onPropertyChange:!1,value:{previousZoomValue:n.zoomSettings.zoomFactor}}),O.Browser.isDevice||this.updateUndoRedoColl(t,r,o),n.notify("transform",{prop:"setCropDimension",onPropertyChange:!1,value:{width:n.cropObj.destPoints.width,height:n.cropObj.destPoints.height}}),e=n.element.querySelector("#"+n.element.id+"_aspectratio"),i=n.element.querySelector("#"+n.element.id+"_nonaspectratio"),n.notify("draw",{prop:"render-image",value:{isMouseWheel:!1}}),!o.isCropToolbar&&O.isNullOrUndefined(e)&&O.isNullOrUndefined(i)&&n.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"main",isApplyBtn:!1,isCropping:!1,isZooming:null,cType:null}}),this.resizeWrapper(),O.Browser.isDevice)&&this.updateUndoRedoColl(t,r,o))},e.prototype.updateUndoRedoColl=function(e,t,o){var i=this.parent,r={prevCurrSelectionPoint:i.prevCurrSelectionPoint};e.currSelectionPoint=O.extend({},r.prevCurrSelectionPoint,{},!0),i.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"crop",previousObj:e,previousObjColl:e.objColl,previousPointColl:e.pointColl,previousSelPointColl:e.selPointColl,previousCropObj:t,previousText:null,currentText:null,previousFilter:null,isCircleCrop:i.isCircleCrop}}),o.isCropToolbar||i.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"ok"}})},e.prototype.resizeWrapper=function(){var e,t=this.parent;O.Browser.isDevice&&(e=(e=t.element).querySelector("#"+e.id+"_contextualToolbarArea"))&&""===e.style.position&&!this.isTransformCrop&&(e.style.position="absolute",t.isStraightening=!1,t.update(),t.notify("filter",{prop:"setAdjustmentValue",value:{adjustmentValue:t.canvasFilter}}))},e.prototype.calcRatio=function(e,t){var o=this.parent,i=o.transform.degree,r=o.img,n=r.destWidth,r=r.destHeight,t=t||o.baseImgCanvas,o=t.width,t=t.height,n=0===i||i%180==0?o/n:t/n,i=0===i||i%180==0?t/r:o/r;return e&&(e.width=n,e.height=i),{width:n,height:i}},e.prototype.isObjInImage=function(e,t){var o=this.parent.img,i=o.destLeft,r=o.destTop,n=o.destWidth,o=o.destHeight,e=e.activePoint,a=e.startX,s=e.endX,l=e.startY,e=e.endY,a=i<=a&&s<=i+n||a<=i&&i<=s||a<=i+n&&i+n<=s||r<=l&&e<=r+o||l<=r&&r<=e||l<=r+o&&r+o<=e;return t&&(t.isInside=a),a},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,n=t.rotateFlipColl.length;r<n;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};var o=e;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()}var R=function(n,a,s,l){return new(s=s||Promise)(function(e,t){function o(e){try{r(l.next(e))}catch(e){t(e)}}function i(e){try{r(l.throw(e))}catch(e){t(e)}}function r(t){t.done?e(t.value):new s(function(e){e(t.value)}).then(o,i)}r((l=l.apply(n,a||[])).next())})},E=function(i,r){var n,a,s,l={label:0,sent:function(){if(1&s[0])throw s[1];return s[1]},trys:[],ops:[]},e={next:t(0),throw:t(1),return:t(2)};return"function"==typeof Symbol&&(e[Symbol.iterator]=function(){return this}),e;function t(o){return function(e){var t=[o,e];if(n)throw new TypeError("Generator is already executing.");for(;l;)try{if(n=1,a&&(s=2&t[0]?a.return:t[0]?a.throw||((s=a.return)&&s.call(a),0):a.next)&&!(s=s.call(a,t[1])).done)return s;switch(a=0,(t=s?[2&t[0],s.value]:t)[0]){case 0:case 1:s=t;break;case 4:return l.label++,{value:t[1],done:!1};case 5:l.label++,a=t[1],t=[0];continue;case 7:t=l.ops.pop(),l.trys.pop();continue;default:if(!(s=0<(s=l.trys).length&&s[s.length-1])&&(6===t[0]||2===t[0])){l=0;continue}if(3===t[0]&&(!s||t[1]>s[0]&&t[1]<s[3]))l.label=t[1];else if(6===t[0]&&l.label<s[1])l.label=s[1],s=t;else{if(!(s&&l.label<s[2])){s[2]&&l.ops.pop(),l.trys.pop();continue}l.label=s[2],l.ops.push(t)}}t=r.call(i,l)}catch(e){t=[6,e],a=0}finally{n=s=0}if(5&t[0])throw t[1];return{value:t[0]?t[1]:void 0,done:!0}}}},i=(t.prototype.destroy=function(){this.parent.isDestroyed||this.removeEventListener()},t.prototype.addEventListener=function(){this.parent.on("draw",this.draw,this),this.parent.on("destroyed",this.destroy,this)},t.prototype.removeEventListener=function(){this.parent.off("draw",this.draw),this.parent.off("destroyed",this.destroy)},t.prototype.draw=function(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=this.arrowDimension;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=O.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=O.extend([],this.parent.objColl,[],!0);break;case"resetTempObjColl":this.tempObjColl=null;break;case"updateTempPointColl":this.tempPointColl=O.extend({},this.parent.pointColl,{},!0);break;case"resetTempPointColl":this.tempPointColl={}}},t.prototype.getModuleName=function(){return"draw"},t.prototype.updatePrivateVariables=function(){var e=this.parent;e.lowerCanvas&&(this.lowerContext=e.lowerCanvas.getContext("2d")),e.upperCanvas&&(this.upperContext=e.upperCanvas.getContext("2d")),O.isNullOrUndefined(this.tempZoomFactor)&&(this.tempZoomFactor=e.transform.zoomFactor),""===this.tempTextSettings.fontFamily&&(this.tempTextSettings.fontFamily=e.fontFamily.default)},t.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},t.prototype.redrawDownScale=function(){var e,t=this.parent;t.transform.zoomFactor&&t.transform.zoomFactor<0&&(e=O.extend({},t.activeObj,{},!0),t.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),this.isDownScale=!0,this.renderImage(),this.isDownScale=!1,e.shape)&&this.drawObject("duplicate",e)},t.prototype.updateFinetune=function(){var e,t,o,i=this.parent;i.transform.zoomFactor&&i.transform.zoomFactor<0&&(e=this.lowerContext.filter,this.lowerContext.filter="none",i.notify("draw",{prop:"redrawDownScale"}),t=i.inMemoryCanvas.getContext("2d"),o=(o=this.lowerContext).getImageData(0,0,o.canvas.width,o.canvas.height),i.inMemoryCanvas.width=o.width,i.inMemoryCanvas.height=o.height,t.putImageData(o,0,0),this.lowerContext.filter=e,i.notify("draw",{prop:"redrawDownScale"}))},t.prototype.drawImage=function(){this.applyFrame(this.lowerContext,this.parent.frameObj.type)},t.prototype.drawObject=function(e,t,o,i,r,n,a){var s,l=this.parent,p=l.activeObj,h=l.activeObj.activePoint;this.upperContext.clearRect(0,0,l.upperCanvas.width,l.upperCanvas.height),"original"===(e=e.toLowerCase())?s=this.lowerContext:"duplicate"===e?s=this.upperContext:n&&(s=n),!r&&p.shape&&this.setDragLimit(),l.currObjType.shape&&"crop"===l.currObjType.shape.split("-")[0].toLowerCase()&&o&&this.drawCropRatio(),p=l.activeObj,h=l.activeObj.activePoint,O.isNullOrUndefined(p.strokeSettings)&&(l.notify("shape",{prop:"getStrokeSettings",onPropertyChange:!(r={strokeSettings:{}}),value:{obj:r}}),p.strokeSettings=r.strokeSettings),O.isNullOrUndefined(p.strokeSettings.strokeWidth)&&(p.strokeSettings.strokeWidth=2),t&&(l.activeObj=O.extend({},t,{},!0)),i&&i.startX&&i.startY&&i.endX&&i.endY&&i.width&&i.height&&(h.startX=i.startX,h.startY=i.startY,h.endX=i.endX,h.endY=i.endY,h.width=i.width,h.height=i.height),this.updateActiveObject(),p=l.activeObj,h=l.activeObj.activePoint,O.isNullOrUndefined(h.startX)&&O.isNullOrUndefined(h.startY)||(l.currObjType.isText&&(l.notify("shape",{prop:"getKeyHistory",onPropertyChange:!(o={keyHistory:""}),value:{obj:o}}),p.keyHistory=o.keyHistory),r=!1,"original"!==e&&((r=p.shape&&"crop"===p.shape.split("-")[0]?!0:r)&&(i&&i.startX&&i.startY&&i.endX&&i.endY&&i.width&&i.height?(h.startX=i.startX,h.startY=i.startY,h.endX=i.endX,h.endY=i.endY,h.width=i.width,h.height=i.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)),!O.isNullOrUndefined(a)||s!==this.lowerContext&&s!==this.upperContext||(this.rotateContext("initial",s),this.drawOuterSelection(s),this.rotateContext("reverse",s))),l.currObjType.isActiveObj=!0,l.notify("shape",{prop:"getKeyHistory",onPropertyChange:!(o={keyHistory:""}),value:{obj:o}}),t?this.drawShapeObj(e,t.shape,n,a):""!==o.keyHistory&&l.currObjType.isText?this.drawShapeObj(e,"text",n,a):p.shape?this.drawShapeObj(e,p.shape,n,a):this.drawShapeObj(e,void 0,n,a),"duplicate"===e&&r&&"crop-circle"!==p.shape&&"none"!==l.frameObj.type&&(this.applyFrame(this.upperContext,l.frameObj.type),this.drawCornerCircles(this.upperContext)))},t.prototype.rotateContext=function(e,t){var o,i=this.parent,r=i.activeObj,n=r.shape,r=r.rotatedAngle,a=i.img,s=a.destLeft,l=a.destTop,p=a.destWidth,a=a.destHeight,h=i.activeObj.activePoint,d=h.startX,c=h.startY,u=h.width,h=h.height;"line"!==n&&"arrow"!==n&&(n="initial"===e?r:-r,e=0!==i.transform.straighten||i.isCropTab?(o=s+p/2,l+a/2):(o=d+u/2,c+h/2),t.translate(o,e),t.rotate(n),t.translate(-o,-e))},t.prototype.setDragLimit=function(){var e,t,o=this.parent,i=o.activeObj.activePoint,r=o.activeObj,n=r.shape,r=r.rotatedAngle;i&&"image"!==n&&"line"!==n&&0===r&&(r=(n=o.img).destLeft,e=n.destTop,t=n.destWidth,n=n.destHeight,i.startX<r?(i.startX=r,i.endX=Math.min(i.startX+i.width,r+t)):i.endX>r+t&&(i.endX=r+t,i.startX=Math.max(i.endX-i.width,r)),i.startY<e?i.startY=e:i.endY>e+n&&(i.endY=e+n,i.startY=Math.max(i.endY-i.height,e)),o.activeObj=this.updateWidthHeight(o.activeObj))},t.prototype.drawCropRatio=function(){var e,t,o,i,r=this.parent,n=r.activeObj.activePoint,a=r.lowerCanvas.clientWidth,s=r.lowerCanvas.clientHeight+1,l=r.img,p=l.destLeft,h=l.destTop,d=l.destWidth,c=l.destHeight;switch(0<r.transform.zoomFactor&&this.currSelPoint?(l=O.extend({},r.activeObj,{},!0),this.drawCustomSelection("crop-custom",null,null,null,null),0!==r.transform.straighten&&(n=r.activeObj.activePoint),i=r.transform.degree%90==0&&r.transform.degree%180!=0?o=n.width<n.height?n.width:n.height:(o=!(p+p+d<=a)&&0===r.transform.straighten?a-p:n.width,!(h+h+c<=s)&&0===r.transform.straighten?s-h:n.height),r.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),r.activeObj=l,r.currObjType.shape=l.shape,this.upperContext.clearRect(0,0,r.upperCanvas.width,r.upperCanvas.height),r.currObjType.isCustomCrop=!1):(o=d,i=c,p<0&&(o+=p),h<0&&(i+=h),p+d>r.lowerCanvas.width&&(o-=p+d-r.lowerCanvas.width),h+c>r.lowerCanvas.height&&(i-=h+c-r.lowerCanvas.height)),r.currObjType.shape.toLowerCase()){case"crop-square":case"crop-circle":r.notify("selection",{prop:"setDragDirection",onPropertyChange:!1,value:{width:o,height:i}}),n=r.activeObj.activePoint,r.lowerCanvas.width<n.endX-n.startX&&(n.startX=7.5,n.endX=r.lowerCanvas.width-7.5),r.lowerCanvas.height<n.endY-n.startY&&(n.startY=7.5,n.endY=r.lowerCanvas.height-7.5),o===d&&i===c&&(n.startX+=p,n.startY+=h,n.endX+=p,n.endY+=h),r.lowerCanvas.width>r.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,t=2;break;case"crop-4:3":e=4,t=3;break;case"crop-5:4":e=5,t=4;break;case"crop-7:5":e=7,t=5;break;case"crop-16:9":e=16,t=9;break;case"crop-2:3":e=2,t=3;break;case"crop-3:4":e=3,t=4;break;case"crop-4:5":e=4,t=5;break;case"crop-5:7":e=5,t=7;break;case"crop-9:16":e=9,t=16;break;default:e=parseInt(r.currObjType.shape.toLowerCase().split("crop-")[1].split(":")[0]),t=parseInt(r.currObjType.shape.toLowerCase().split("crop-")[1].split(":")[1])}void 0!==e&&void 0!==t&&(r.notify("selection",{prop:"calcShapeRatio",onPropertyChange:!1,value:{x:e,y:t,imgWidth:o,imgHeight:i}}),o===d&&i===c&&this.updatePoints(),n=r.activeObj.activePoint),n.startX<p&&(v=p-n.startX+7.5,n.startX+=v,n.endX+=v),n.startY<h&&(v=h-n.startY+7.5,n.startY+=v,n.endY+=v),r.activeObj=this.updateWidthHeight(r.activeObj),this.adjToCenter(),this.enlargeToImg(),0!==r.transform.straighten&&(this.adjToStraighten(),this.updateActiveObject(r.activeObj.activePoint,r.activeObj));var u={isIntersect:null,arr:null},g=0,n=r.activeObj.activePoint;if(0!==r.transform.straighten)for(;this.isLinesIntersect(u)&&g<100;){g++;var v=+n.width/100;n.startX+=v,n.endX-=v,v=+n.height/100,n.startY+=v,n.endY-=v,n.width=n.endX-n.startX,n.height=n.endY-n.startY,this.updateActiveObject(n,r.activeObj)}this.straightenInitZoom=r.transform.zoomFactor,this.straightenActObj=O.extend({},r.activeObj,{},!0),r.notify("draw",{prop:"resetStraightenDestPoints"}),r.notify("draw",{prop:"setDestForStraighten"})},t.prototype.adjToCenter=function(){var e,t=this.parent,o=t.activeObj.activePoint,i=t.img,r=i.destLeft,n=i.destTop,a=i.destWidth,i=i.destHeight,s=t.lowerCanvas.width/2-(o.endX-o.width/2),t=t.lowerCanvas.height/2-(o.endY-o.height/2);o.startX+=s,o.endX+=s,o.startY+=t,o.endY+=t,o.startX<(7.5<=r?r:7.5)?(e=(7.5<=r?r:0)-o.startX,o.startX+=e,o.endX+=e):o.endX>r+a&&(e=o.endX-(r+a),o.startX-=e,o.endX-=e),o.startY<(7.5<=n?n:7.5)?(e=(7.5<=n?n:0)-o.startY,o.startY+=e,o.endY+=e):o.endY>n+i&&(e=o.endY-(n+i),o.startY-=e,o.endY-=e)},t.prototype.enlargeToImg=function(){var e=this.parent;if(0!==e.transform.straighten&&e.transform.degree%90==0&&e.transform.degree%180!=0)for(var t=e.activeObj.activePoint,o=O.extend({},t,{},!0),i=0;;){i++;var r=5*t.width/100,n=(t.startX-=r,t.endX+=r,r=5*t.height/100,t.startY-=r,t.endY+=r,t.width=t.endX-t.startX,t.height=t.endY-t.startY,this.updateActiveObject(t,e.activeObj),{isIntersect:null,arr:null});if(this.updateImgCanvasPoints(),this.isLinesIntersect(n),n.arr[0]||n.arr[1]||n.arr[2]||n.arr[3]||t.startX<7.5||t.startY<7.5||100===i){r=+(t=O.extend({},o,{},!0)).width/100,t.startX+=r,t.endX-=r,r=+t.height/100,t.startY+=r,t.endY-=r,t.width=t.endX-t.startX,t.height=t.endY-t.startY,this.updateActiveObject(t,e.activeObj);break}o=O.extend({},t,{},!0)}},t.prototype.updateActiveObject=function(e,t,o,i,r){var n=this.parent,a=(e=e||O.extend({},n.activeObj.activePoint,{},!0),t=t||O.extend({},n.activeObj,{},!0),e.width=e.endX-e.startX,e.height=e.endY-e.startY,e.startX),s=e.startY,l=e.endX,p=e.endY,h=e.width/2,d=e.height/2,c=7.5;t.horTopLine={startX:a+(i=i||0),startY:s-(r=r||0),endX:l+i,endY:p+r},t.horBottomLine={startX:a-i,startY:p-r,endX:l-i,endY:p+r},t.verLeftLine={startX:a+i,startY:s-r,endX:a-r,endY:p-r},t.verRightLine={startX:l+i,startY:s+r,endX:l-i,endY:p+r},t.topLeftCircle={startX:a,startY:s,radius:t.horTopLine.endX?c:0},t.topCenterCircle={startX:a+h,startY:s,radius:t.horTopLine.endX?c:0},t.topRightCircle={startX:l,startY:s,radius:t.horTopLine.endX?c:0},t.centerLeftCircle={startX:a,startY:s+d,radius:t.horTopLine.endX?c:0},t.centerRightCircle={startX:l,startY:s+d,radius:t.horTopLine.endX?c:0},t.bottomLeftCircle={startX:a,startY:p,radius:t.horTopLine.endX?c:0},t.bottomCenterCircle={startX:a+h,startY:p,radius:t.horTopLine.endX?c:0},t.bottomRightCircle={startX:l,startY:p,radius:t.horTopLine.endX?c:0},0===t.rotatedAngle&&(t.rotationCirclePoint={x:t.bottomCenterCircle.startX,y:t.bottomCenterCircle.startY+25},t.rotationCirclePoint.ratioX=(t.rotationCirclePoint.x-n.img.destLeft)/n.img.destWidth,t.rotationCirclePoint.ratioY=(t.rotationCirclePoint.y-n.img.destTop)/n.img.destHeight),t.activePoint=e,O.isNullOrUndefined(o)&&(n.activeObj=O.extend({},t,{},!0))},t.prototype.drawOuterSelection=function(e,t){var o,i=this.parent,r=i.activeObj.activePoint,n=i.activeObj,a=(e.lineWidth=.5,O.extend({},n,{},!0));if(((o=n.shape?n.shape.split("-"):o)&&"crop"===o[0]||void 0===n.shape)&&!t&&(this.upperContext.fillStyle="rgb(0, 0, 0, 0.25)",this.upperContext.fillRect(0,0,i.lowerCanvas.width,i.lowerCanvas.height),this.upperContext.clearRect(r.startX,r.startY,r.width,r.height)),e.strokeStyle=i.themeColl[i.theme].primaryColor,e.fillStyle=i.themeColl[i.theme].secondaryColor,(0===a.shapeDegree?i.transform.degree:i.transform.degree-a.shapeDegree)<0&&0,"arrow"===n.shape||"line"===n.shape)e.beginPath(),e.moveTo(r.startX,r.startY),e.lineTo(r.endX,r.endY),e.stroke();else if("path"===n.shape){e.beginPath();var s=O.extend({},i.activeObj,{},!0);if(s.pointColl[0]&&(e.moveTo(s.pointColl[0].x,s.pointColl[0].y),1<s.pointColl.length))for(var l=1,p=s.pointColl.length;l<p;l++)r.endX=s.pointColl[l].x,r.endY=s.pointColl[l].y,e.lineTo(r.endX,r.endY);var t={shape:null};i.notify("selection",{prop:"getCurrentDrawingShape",value:{obj:t}}),"path"===t.shape&&(i.activeObj=n=s),e.lineTo(r.endX,r.endY),e.stroke()}else this.drawCornerCircles(e);!i.selectionSettings.showCircle||void 0!==o&&"crop"===o[0]||(t=e.strokeStyle,o=e.fillStyle,e.strokeStyle=i.selectionSettings.strokeColor,e.fillStyle=i.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=t,e.fillStyle=o),a.rotationCircleLine=n.rotationCircleLine,i.activeObj=O.extend({},a,{},!0)},t.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)}},t.prototype.drawShapeObj=function(e,t,o,i){var r,n,a=this.parent,s=a.activeObj.activePoint,l=a.activeObj,p=l.strokeSettings,h=p.strokeColor,d=p.fillColor,c=p.strokeWidth,p=void 0!==t?t:a.currObjType.shape,p=(a.currObjType.shape=p,"original"===e.toLowerCase()?r=this.lowerContext:"duplicate"===e.toLowerCase()?r=this.upperContext:o&&(r=o),a.currObjType.shape.toLowerCase()),u=(-1!==["rectangle","ellipse","line","arrow","path","image"].indexOf(p)&&(l.shape=a.currObjType.shape),r.strokeStyle=h,r.fillStyle="text"===t||"freehanddraw"===t?h:d,s.width/3),g=s.height/3,v=s.endX-s.startX,f=s.endY-s.startY,C=(this.rotateContext("initial",r),r.fillStyle);switch(a.currObjType.shape.toLowerCase()){case"rectangle":this.drawSquareLines(r),O.isNullOrUndefined(i)&&r===this.upperContext&&this.drawOuterSelection(r);break;case"ellipse":v=Math.abs(v),f=Math.abs(f),r.beginPath(),r.ellipse(s.startX+v/2,s.startY+f/2,v/2,f/2,0,0,2*Math.PI,!1),""!==d&&(r.fillStyle=d,r.fill()),r.ellipse(s.startX+v/2,s.startY+f/2,Math.abs(v/2-c),Math.abs(f/2-c),0,0,2*Math.PI,!1),r.fillStyle=h,r.fill("evenodd"),r.closePath(),O.isNullOrUndefined(i)&&r===this.upperContext&&this.drawOuterSelection(r);break;case"crop-circle":r===this.lowerContext&&(r=this.upperContext),this.shapeCircle(r,v,f);break;case"line":this.shapeLine(r,s.startX,s.startY,s.endX,s.endY),O.isNullOrUndefined(i)&&r===this.upperContext&&this.drawOuterSelection(r);break;case"arrow":(0===l.shapeDegree?a.transform.degree:a.transform.degree-l.shapeDegree)<0&&0,r.fillStyle=r.strokeStyle,O.isNullOrUndefined(l.triangleDirection)&&(l.triangleDirection="right"),O.isNullOrUndefined(l.start)&&(l.start="none"),O.isNullOrUndefined(l.end)&&(l.end="arrowSolid"),this.drawArrowHead(r,!0),this.drawArrowHead(r,!1),"none"===l.end&&this.shapeLine(r,s.startX,s.startY,s.endX,s.endY),r.fillStyle=C,O.isNullOrUndefined(i)&&r===this.upperContext&&this.drawOuterSelection(r);break;case"path":if(1<(n=O.extend({},a.activeObj,{},!0)).pointColl.length){var b={shape:null};if(a.notify("selection",{prop:"getCurrentDrawingShape",value:{obj:b}}),"path"===b.shape)for(var m={x:0,y:0},y=0,P=n.pointColl.length;y<P;y++)O.isNullOrUndefined(n.pointColl[y+1])?(m.x=n.activePoint.endX,m.y=n.activePoint.endY):(m.x=n.pointColl[y+1].x,m.y=n.pointColl[y+1].y),s.startX=n.pointColl[y].x,s.startY=n.pointColl[y].y,s.endX=m.x,s.endY=m.y,a.activeObj=this.updateWidthHeight(a.activeObj),this.shapeLine(r,s.startX,s.startY,s.endX,s.endY);else for(y=1,P=n.pointColl.length;y<P;y++)s.startX=n.pointColl[y-1].x,s.startY=n.pointColl[y-1].y,s.endX=n.pointColl[y].x,s.endY=n.pointColl[y].y,a.activeObj=this.updateWidthHeight(a.activeObj),this.shapeLine(r,s.startX,s.startY,s.endX,s.endY);a.activeObj=l=n}else this.shapeLine(r,s.startX,s.startY,s.endX,s.endY);r===this.upperContext&&this.drawOuterSelection(r);break;case"text":this.shapeText(r);break;case"image":this.shapeImage(r),O.isNullOrUndefined(i)&&r===this.upperContext&&this.drawOuterSelection(r);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":r===this.lowerContext&&(r=this.upperContext),this.drawSelection(u,g),a.currObjType.shape="";break;default:this.drawSelection(u,g)}this.rotateContext("reverse",r)},t.prototype.updatePoints=function(){var e=this.parent,t=e.activeObj.activePoint,o=e.img,i=o.destLeft,o=o.destTop;t.startX+=i,t.startY+=o,t.endX+=i,t.endY+=o,e.activeObj=this.updateWidthHeight(e.activeObj)},t.prototype.updateWidthHeight=function(e){var t=e.activePoint,o=t.startX,i=t.startY,r=t.endX,t=t.endY;return e.activePoint.width=r-o,e.activePoint.height=t-i,e},t.prototype.drawCornerCircles=function(e){var t,o,i=this.parent,r=i.activeObj;e.beginPath(),e.rect(r.activePoint.startX,r.activePoint.startY,r.activePoint.width,r.activePoint.height),e.stroke(),e.closePath(),i.selectionSettings.showCircle&&(t=e.strokeStyle,o=e.fillStyle,e.strokeStyle=i.selectionSettings.strokeColor,e.fillStyle=i.selectionSettings.fillColor,e.lineWidth*=2,e.beginPath(),e.moveTo(r.topLeftCircle.startX,r.topLeftCircle.startY),e.arc(r.topLeftCircle.startX,r.topLeftCircle.startY,r.topLeftCircle.radius,0,2*Math.PI),e.moveTo(r.topRightCircle.startX,r.topRightCircle.startY),e.arc(r.topRightCircle.startX,r.topRightCircle.startY,r.topRightCircle.radius,0,2*Math.PI),e.moveTo(r.bottomLeftCircle.startX,r.bottomLeftCircle.startY),e.arc(r.bottomLeftCircle.startX,r.bottomLeftCircle.startY,r.bottomLeftCircle.radius,0,2*Math.PI),e.moveTo(r.bottomRightCircle.startX,r.bottomRightCircle.startY),e.arc(r.bottomRightCircle.startX,r.bottomRightCircle.startY,r.bottomRightCircle.radius,0,2*Math.PI),e.stroke(),e.fill(),e.closePath(),e.lineWidth/=2,e.strokeStyle=t,e.fillStyle=o)},t.prototype.drawCenterCircles=function(e){var t=this.parent,o=t.activeObj.activePoint,i=t.activeObj;if(e.lineWidth*=2,e.beginPath(),"arrow"===i.shape||"line"===i.shape)e.moveTo(o.startX,o.startY),e.arc(o.startX,o.startY,i.topCenterCircle.radius,0,2*Math.PI),e.moveTo(o.endX,o.endY),e.arc(o.endX,o.endY,i.bottomCenterCircle.radius,0,2*Math.PI);else if("path"===i.shape){var r=O.extend({},t.activeObj,{},!0);if(1<r.pointColl.length)for(var n=1,a=r.pointColl.length;n<a;n++)o.startX=r.pointColl[n-1].x,o.startY=r.pointColl[n-1].y,o.endX=r.pointColl[n].x,o.endY=r.pointColl[n].y,e.moveTo(o.startX,o.startY),e.arc(o.startX,o.startY,i.topCenterCircle.radius,0,2*Math.PI),e.moveTo(o.endX,o.endY),e.arc(o.endX,o.endY,i.bottomCenterCircle.radius,0,2*Math.PI);var s={shape:null};t.notify("selection",{prop:"getCurrentDrawingShape",value:{obj:s}}),"path"===s.shape&&(t.activeObj=i=r),e.moveTo(o.startX,o.startY),e.arc(o.startX,o.startY,i.topCenterCircle.radius,0,2*Math.PI),e.moveTo(o.endX,o.endY),e.arc(o.endX,o.endY,i.bottomCenterCircle.radius,0,2*Math.PI)}else this.drawRotationArcLine(e),e.lineTo(i.rotationCirclePoint.x,i.rotationCirclePoint.y);e.stroke(),e.fill(),e.closePath(),"arrow"!==i.shape&&"line"!==i.shape&&"path"!==i.shape&&(e.beginPath(),e.moveTo(i.rotationCirclePoint.x,i.rotationCirclePoint.y),e.arc(i.rotationCirclePoint.x,i.rotationCirclePoint.y,i.bottomCenterCircle.radius,0,2*Math.PI),e.stroke(),e.fill(),e.closePath()),e.lineWidth/=2},t.prototype.drawRotationArcLine=function(e){var t=this.parent,o=t.activeObj,i=(O.isNullOrUndefined(o.rotationCircleLine)&&(o.rotationCircleLine=22.5),!1),r=!1,t=0===o.shapeDegree?t.transform.degree:t.transform.degree-o.shapeDegree;if(t<0&&(t=360+t),o.flipObjColl)for(var n=0,a=o.flipObjColl.length;n<a;n++){var s=o.flipObjColl[n].toLowerCase();"horizontal"===s?i=!0:"vertical"===s&&(r=!0)}switch(t){case 0:case 360:r?(o.rotationCirclePoint={x:o.topCenterCircle.startX,y:o.topCenterCircle.startY-o.rotationCircleLine},e.moveTo(o.rotationCirclePoint.x,o.rotationCirclePoint.y+o.rotationCircleLine)):(o.rotationCirclePoint={x:o.bottomCenterCircle.startX,y:o.bottomCenterCircle.startY+o.rotationCircleLine},e.moveTo(o.rotationCirclePoint.x,o.rotationCirclePoint.y-o.rotationCircleLine));break;case 90:case-270:i?(o.rotationCirclePoint={x:o.centerRightCircle.startX+o.rotationCircleLine,y:o.centerLeftCircle.startY},e.moveTo(o.rotationCirclePoint.x-o.rotationCircleLine,o.rotationCirclePoint.y)):(o.rotationCirclePoint={x:o.centerLeftCircle.startX-o.rotationCircleLine,y:o.centerLeftCircle.startY},e.moveTo(o.rotationCirclePoint.x+o.rotationCircleLine,o.rotationCirclePoint.y));break;case 180:case-180:r?(o.rotationCirclePoint={x:o.bottomCenterCircle.startX,y:o.bottomCenterCircle.startY+o.rotationCircleLine},e.moveTo(o.rotationCirclePoint.x,o.rotationCirclePoint.y-o.rotationCircleLine)):(o.rotationCirclePoint={x:o.topCenterCircle.startX,y:o.topCenterCircle.startY-o.rotationCircleLine},e.moveTo(o.rotationCirclePoint.x,o.rotationCirclePoint.y+o.rotationCircleLine));break;case 270:case-90:i?(o.rotationCirclePoint={x:o.centerLeftCircle.startX-o.rotationCircleLine,y:o.centerLeftCircle.startY},e.moveTo(o.rotationCirclePoint.x+o.rotationCircleLine,o.rotationCirclePoint.y)):(o.rotationCirclePoint={x:o.centerRightCircle.startX+o.rotationCircleLine,y:o.centerLeftCircle.startY},e.moveTo(o.rotationCirclePoint.x-o.rotationCircleLine,o.rotationCirclePoint.y))}},t.prototype.drawSquareLines=function(e){var t,o=this.parent.activeObj,i=o.activePoint,r=i.startX,n=i.startY,a=i.width,i=i.height,s=o.strokeSettings,l=s.fillColor,p=s.strokeColor,s=s.strokeWidth;"crop"===(t=o.shape?o.shape.split("-"):t)[0]?e.strokeStyle="#fff":e.strokeStyle=p,e.beginPath(),e.rect(r,n,a,i),""!==l&&(e.fillStyle=l,e.fill()),e.rect(r+s,n+s,a-2*s,i-2*s),e.fillStyle=p,e.fill("evenodd"),e.closePath()},t.prototype.drawSelection=function(e,t){var o=this.parent,i=o.activeObj,r=i.activePoint,n=r.startX,a=r.startY,s=r.endX,r=r.endY;this.upperContext.strokeStyle=o.themeColl[o.theme].primaryColor,this.upperContext.beginPath(),i.horTopInnerLine={startX:n,startY:a+t,endX:s,endY:r+t},i.horBottomInnerLine={startX:n,startY:a+2*t,endX:s,endY:r+2*t},i.verLeftInnerLine={startX:n+e,startY:a,endX:n+e,endY:r},i.verRightInnerLine={startX:n+2*e,startY:a,endX:n+2*e,endY:r},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()},t.prototype.shapeCircle=function(e,t,o){var i=this.parent,r=i.activeObj.activePoint,n=r.startX,a=r.startY,s=r.endX,l=r.endY,r=r.width,p=(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),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-n)/2+n,(l-a)/2+a,r/2,0,2*Math.PI),e.closePath(),e.clip(),e.clearRect(0,0,i.lowerCanvas.width,i.lowerCanvas.height),e.restore(),e.lineWidth=p,this.drawOuterSelection(e,!0),i.currObjType.shape=""},t.prototype.shapeLine=function(e,t,o,i,r){var n=e.lineWidth;e.lineWidth=this.parent.activeObj.strokeSettings.strokeWidth,e.beginPath(),e.moveTo(t,o),e.lineTo(i,r),e.stroke(),e.lineWidth=n},t.prototype.manipulateSaveCtx=function(e,t,o){var i;return e!==this.lowerContext&&e!==this.upperContext&&(this.parent.notify("crop",{prop:"calcRatio",onPropertyChange:!(i={width:0,height:0}),value:{obj:i,dimension:{width:e.canvas.width,height:e.canvas.height}}}),t&&(t*=i.width),o)&&(o*=i.height),{x:t,y:o}},t.prototype.arrow=function(e,t){var o=this.parent.activeObj,i=o.activePoint,r=i.startX,n=i.startY,a=i.endX,i=i.endY,s=o.strokeSettings.strokeWidth,l=(e.lineWidth=s,this.arrowDimension.arrow.width),p=this.arrowDimension.arrow.height,h=this.manipulateSaveCtx(e,l,p),l=h.x+s,p=h.y+s,h=(this.dx=a-r,this.dy=i-n,e.fillStyle=o.strokeSettings.strokeColor,Math.atan2(this.dy,this.dx)),s="arrow"===o.start,d="arrow"===o.end,c="circle"===o.end||"square"===o.end;((t&&"left"===o.triangleDirection||"right"===o.triangleDirection)&&(s&&"none"===o.end||s&&!c)||!t&&(d&&"none"===o.start||!s&&!c))&&this.shapeLine(e,r,n,a,i),t&&"left"===o.triangleDirection||!t&&"right"===o.triangleDirection?(e.translate(a,i),e.rotate(h),this.shapeLine(e,0,0,-l,p/2),this.shapeLine(e,0,0,-l,-p/2),e.rotate(-h),e.translate(-a,-i)):(t&&"right"===o.triangleDirection||!t&&"left"===o.triangleDirection)&&(e.translate(r,n),e.rotate(h),this.shapeLine(e,0,0,l,p/2),this.shapeLine(e,0,0,l,-p/2),e.rotate(-h),e.translate(-r,-n))},t.prototype.arrowSolid=function(e,t){var o=this.parent.activeObj,i=o.strokeSettings.strokeWidth,r=o.activePoint,n=r.startX,a=r.startY,s=r.endX,r=r.endY,l=this.arrowDimension.arrowSolid.width,p=this.arrowDimension.arrowSolid.height,h=this.manipulateSaveCtx(e,l,p),l=h.x+i,p=h.y+i,h=(this.dx=s-n,this.dy=r-a,Math.atan2(this.dy,this.dx)),d="arrowSolid"===o.start,c="arrowSolid"===o.end,u="circle"===o.end||"square"===o.end;(t&&d&&"none"===o.end||d&&!u||!t&&(c&&"none"===o.start||!d&&!u))&&this.shapeLine(e,n,a,s,r),t&&"left"===o.triangleDirection||!t&&"right"===o.triangleDirection?(e.translate(s,r),e.rotate(h),e.beginPath(),e.moveTo(i,0),e.lineTo(p/2-l,p/2),e.lineTo(p/2-l,-p/2),e.closePath(),e.fill(),e.rotate(-h),e.translate(-s,-r),o.rotatedAngle=h):(t&&"right"===o.triangleDirection||!t&&"left"===o.triangleDirection)&&(e.translate(n,a),e.rotate(h),e.beginPath(),e.moveTo(0-i,0),e.lineTo(l-p/2,p/2),e.lineTo(l-p/2,-p/2),e.closePath(),e.fill(),e.rotate(-h),e.translate(-n,-a),o.rotatedAngle=h)},t.prototype.arrowSquareStart=function(e){var t=this.parent.activeObj,o=t.strokeSettings.strokeWidth,i=t.activePoint,r=i.startX,n=i.startY,a=i.endX,i=i.endY,s="square"===t.start,l="circle"===t.end,p="squareSolid"===t.start,h="circleSolid"===t.end,s=((s&&"none"===t.end||s&&!l&&"square"!==t.start||p&&h)&&this.shapeLine(e,r,n,a,i),e.lineWidth=o,e.beginPath(),e.fillStyle=t.strokeSettings.strokeColor,this.arrowDimension.square.width),l=this.arrowDimension.square.height,p=this.manipulateSaveCtx(e,s,l),s=p.x+o,l=p.y+o,h=(this.dx=a-r,this.dy=i-n,Math.atan2(this.dy,this.dx));"left"===t.triangleDirection?(e.translate(a,i),e.rotate(h),"squareSolid"===t.start&&e.fillRect(l/2-s,-l/2,s,l),e.strokeRect(l/2-s,-l/2,s,l),e.rotate(-h),e.translate(-a,-i),this.squareStartIntersectX1=a-l/2*Math.cos(h),this.squareStartIntersectY1=i-l/2*Math.sin(h),"square"===t.start&&"square"!==t.end&&"circle"!==t.end?this.shapeLine(e,r,n,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,n,a,i)):"right"===t.triangleDirection&&(e.lineWidth=o,e.fillStyle=t.strokeSettings.strokeColor,"squareSolid"===t.start&&"squareSolid"===t.end&&this.shapeLine(e,r,n,a,i),e.translate(r,n),e.rotate(h),"squareSolid"===t.start&&e.fillRect(l/2-s,-l/2,s,l),e.strokeRect(l/2-s,-l/2,s,l),e.rotate(-h),e.translate(-r,-n),t.rotatedAngle=h,this.squareStartIntersectX1=r+l/2*Math.cos(h),this.squareStartIntersectY1=n+l/2*Math.sin(h),"square"===t.start&&"square"!==t.end&&"circle"!==t.end&&this.shapeLine(e,a,i,this.squareStartIntersectX1,this.squareStartIntersectY1),"square"===t.start)&&"circle"===t.end&&this.shapeLine(e,this.endCircleIntersectX1,this.endCircleIntersectY1,this.squareStartIntersectX1,this.squareStartIntersectY1)},t.prototype.arrowSquareEnd=function(e){var t=this.parent.activeObj,o=t.activePoint,i=o.startX,r=o.startY,n=o.endX,o=o.endY,a=t.strokeSettings.strokeWidth,s=this.arrowDimension.square.width,l=this.arrowDimension.square.height,p=this.manipulateSaveCtx(e,s,l),s=p.x+a,l=p.y+a,p=(this.dx=n-i,this.dy=o-r,Math.atan2(this.dy,this.dx));e.lineWidth=a,"right"===t.triangleDirection?(e.fillStyle=t.strokeSettings.strokeColor,"squareSolid"===t.end&&"none"===t.start&&this.shapeLine(e,i,r,n,o),e.translate(n,o),e.rotate(p),"squareSolid"===t.end&&e.fillRect(l/2-s,-l/2,s,l),e.strokeRect(l/2-s,-l/2,s,l),e.rotate(-p),e.translate(-n,-o),t.rotatedAngle=p,this.squareEndIntersectX1=n-l/2*Math.cos(p),this.squareEndIntersectY1=o-l/2*Math.sin(p),"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(p),"squareSolid"===t.end&&e.fillRect(l/2-s,-l/2,s,l),e.strokeRect(l/2-s,-l/2,s,l),e.rotate(-p),e.translate(-i,-r),t.rotatedAngle=p,this.squareEndIntersectX1=i+l/2*Math.cos(p),this.squareEndIntersectY1=r+l/2*Math.sin(p),"square"===t.end&&"square"!==t.start&&"circle"!==t.start?this.shapeLine(e,n,o,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))},t.prototype.arrowCircle=function(e,t){var o,i,r,n,a,s,l,p,h=this.parent,d=h.activeObj,c=d.activePoint,u=c.startX,g=c.startY,v=c.endX,c=c.endY,f=d.strokeSettings.strokeWidth;t&&"left"===d.triangleDirection||!t&&"right"===d.triangleDirection?(e.lineWidth=f,o=this.arrowDimension.circle.width,o=this.manipulateSaveCtx(e,o,null).x+f,e.beginPath(),e.arc(v,c,o,0,2*Math.PI),e.stroke(),e.closePath(),this.dx=v-u,this.dy=c-g,i=this.dx*this.dx+this.dy*this.dy,0<=(n=(r=2*(this.dx*(u-v)+this.dy*(g-c)))*r-4*i*((u-v)*(u-v)+(g-c)*(g-c)-o*o))&&(e.fillStyle=d.strokeSettings.strokeColor,a=(-r-Math.sqrt(n))/(2*i),s=u+this.dx*a,l=g+this.dy*a,t?(this.startCircleIntersectX1=s,this.startCircleIntersectY1=l,this.endCircleIntersectX1=v-this.dx*a,this.endCircleIntersectY1=c-this.dy*a,e.beginPath(),e.fill(),e.beginPath(),"circle"===d.start&&"circle"===d.end?this.shapeLine(e,this.startCircleIntersectX1,this.startCircleIntersectY1,this.endCircleIntersectX1,this.endCircleIntersectY1):"circle"===d.start&&"circle"!==d.end&&"square"!==d.end&&this.shapeLine(e,u,g,this.startCircleIntersectX1,this.startCircleIntersectY1),e.stroke(),e.closePath()):(this.endCircleIntersectX1=s,this.endCircleIntersectY1=l,"circle"===d.end&&"circle"!==d.start&&"square"!==d.start&&this.shapeLine(e,u,g,this.endCircleIntersectX1,this.endCircleIntersectY1))),p=Math.atan2(this.dy,this.dx),h.activeObj.rotatedAngle=p):(t&&"right"===d.triangleDirection||!t&&"left"===d.triangleDirection)&&(e.lineWidth=f,o=this.arrowDimension.circle.width,o=this.manipulateSaveCtx(e,o,null).x+f,e.beginPath(),e.arc(u,g,o,0,2*Math.PI),e.stroke(),e.closePath(),this.dx=u-v,this.dy=g-c,i=this.dx*this.dx+this.dy*this.dy,0<=(n=(r=2*(this.dx*(v-u)+this.dy*(c-g)))*r-4*i*((v-u)*(v-u)+(c-g)*(c-g)-o*o))&&(e.fillStyle=d.strokeSettings.strokeColor,a=(-r-Math.sqrt(n))/(2*i),s=v+this.dx*a,l=c+this.dy*a,t?(this.startCircleIntersectX1=s,this.startCircleIntersectY1=l,this.endCircleIntersectX1=u-this.dx*a,this.endCircleIntersectY1=g-this.dy*a,"circle"===d.start&&"circle"===d.end?this.shapeLine(e,this.endCircleIntersectX1,this.endCircleIntersectY1,this.startCircleIntersectX1,this.startCircleIntersectY1):"circle"===d.start&&"circle"!==d.end&&"square"!==d.end&&this.shapeLine(e,v,c,this.startCircleIntersectX1,this.startCircleIntersectY1)):(this.endCircleIntersectX1=s,this.endCircleIntersectY1=l,e.beginPath(),e.fill(),e.beginPath(),"circle"===d.end&&"circle"!==d.start&&"square"!==d.start&&this.shapeLine(e,v,c,this.endCircleIntersectX1,this.endCircleIntersectY1))),p=Math.atan2(this.dy,this.dx),h.activeObj.rotatedAngle=p)},t.prototype.arrowCircleSolid=function(e,t){var o,i=this.parent.activeObj,r=i.activePoint,n=r.startX,a=r.startY,s=r.endX,r=r.endY,l="circleSolid"===i.start,p=i.strokeSettings.strokeWidth;t&&"left"===i.triangleDirection||!t&&"right"===i.triangleDirection?(e.lineWidth=p,e.beginPath(),e.fillStyle=i.strokeSettings.strokeColor,(t&&l&&"none"===i.end||l&&"circle"!==i.end&&"square"!==i.end||!t&&"circleSolid"===i.end&&"none"===i.start)&&this.shapeLine(e,n,a,s,r),o=this.arrowDimension.circle.width,o=this.manipulateSaveCtx(e,o,null).x+p,this.dx=s-n,this.dy=r-a,e.save(),e.beginPath(),e.arc(s,r,o,0,2*Math.PI),e.stroke(),e.fill(),e.closePath(),i.rotatedAngle=Math.atan2(this.dy,this.dx)):(t&&"right"===i.triangleDirection||!t&&"left"===i.triangleDirection)&&(e.lineWidth=p,e.beginPath(),e.fillStyle=i.strokeSettings.strokeColor,(t&&l&&"none"===i.end||l&&"circle"!==i.end&&"square"!==i.end||!t&&"circleSolid"===i.end&&"none"===i.start)&&this.shapeLine(e,n,a,s,r),o=this.arrowDimension.circle.width,o=this.manipulateSaveCtx(e,o,null).x+p,this.dx=s-n,this.dy=r-a,e.save(),e.beginPath(),e.arc(n,a,o,0,2*Math.PI),e.stroke(),e.fill(),e.closePath(),i.rotatedAngle=Math.atan2(this.dy,this.dx))},t.prototype.arrowBar=function(e,t){var o,i,r,n,a=this.parent,s=a.activeObj,l=s.activePoint,p=l.startX,h=l.startY,d=l.endX,l=l.endY,c=s.strokeSettings.strokeWidth;t&&"left"===s.triangleDirection||!t&&"right"===s.triangleDirection?(e.lineWidth=c,e.beginPath(),e.fillStyle=s.strokeSettings.strokeColor,(t&&"bar"===s.start&&"none"===s.end||"bar"===s.start&&"circle"!==s.end&&"square"!==s.end||!t&&("bar"===s.end&&"none"===s.start||"bar"===s.end&&"circle"!==s.start&&"square"!==s.start))&&this.shapeLine(e,p,h,d,l),o=this.arrowDimension.bar.width,i=this.arrowDimension.bar.height,o=(r=this.manipulateSaveCtx(e,o,i)).x+c,i=r.y+c,this.dx=d-p,this.dy=l-h,n=Math.atan2(this.dy,this.dx),e.translate(d,l),e.rotate(n),e.fillRect(i/4-o,-i/2,o,i),e.rotate(-n),e.translate(-d,-l),s.rotatedAngle=n):(t&&"right"===s.triangleDirection||!t&&"left"===s.triangleDirection)&&(e.lineWidth=c,e.beginPath(),e.fillStyle=s.strokeSettings.strokeColor,(t&&"bar"===s.start&&"none"===s.end||"bar"===s.start&&"circle"!==s.end&&"square"!==s.end||!t&&"bar"===s.end&&"none"===s.start)&&this.shapeLine(e,p,h,d,l),o=this.arrowDimension.bar.width,i=this.arrowDimension.bar.height,o=(r=this.manipulateSaveCtx(e,o,i)).x+c,i=r.y+c,this.dx=d-p,this.dy=l-h,n=Math.atan2(this.dy,this.dx),e.translate(p,h),e.rotate(n),e.fillRect(i/4-o,-i/2,o,i),e.rotate(-n),e.translate(-p,-h),a.activeObj.rotatedAngle=n)},t.prototype.shapeImage=function(e){var t=this.parent,o=t.activeObj,i=o.activePoint,r=i.startX,n=i.startY,a=i.width,i=i.height,s=o.imageCanvas.getContext("2d"),l=(e===this.lowerContext&&this.isImageApply&&(t.notify("transform",{prop:"calcMaxDimension",onPropertyChange:!(l={width:0,height:0}),value:{width:o.imageElement.width,height:o.imageElement.height,obj:l,isImgShape:null}}),a<l.width/5||i<l.height/5)&&(s.clearRect(0,0,o.imageCanvas.width,o.imageCanvas.height),t.notify("selection",{prop:"applyTransformToImg",onPropertyChange:!1,value:{ctx:s}}),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),{startX:0,startY:0,width:0,height:0}),s=(l.width=a,l.height=i,4===o.flipObjColl.length&&(o.flipObjColl=[],o.shapeFlip=""),l.startX=(a-l.width)/2+r,l.startY=(i-l.height)/2+n,e.globalAlpha);e.globalAlpha=o.opacity,o.rotateFlipColl&&0<o.rotateFlipColl.length?this.rotateImage(e):e.drawImage(o.imageCanvas,l.startX,l.startY,l.width,l.height),e.globalAlpha=s,t.currObjType.isText=!1},t.prototype.shapeText=function(e){var t=this.parent,o=e.filter,i=t.activeObj,r=i.activePoint,n=r.startX,a=r.startY,s=r.width,l=r.height,p=i.keyHistory.split("\n"),r=i.textSettings,h=r.fontFamily,d=r.bold,c=r.italic,u=i.textSettings.fontSize,g=((u+.25*u)*p.length-u*p.length)/p.length;e.filter="none";for(var v=0;v<p.length;v++){var f=p[v],C=(v+1)*u*.85+v*g,b=(-360===t.transform.degree&&(t.transform.degree=0),0===t.transform.degree||180===t.transform.degree?l<u&&(u=i.textSettings.fontSize=l-.1*l):s<u&&(u=i.textSettings.fontSize=s-.1*s),e.strokeStyle=i.strokeSettings.strokeColor,e.fillStyle=i.strokeSettings.strokeColor,"");d&&(b="bold "),c&&(b="italic "),e.font=(b=d&&c?"italic bold ":b)+u+"px "+h,4===i.flipObjColl.length&&(i.flipObjColl=[],i.shapeFlip=""),i.rotateFlipColl&&0<i.rotateFlipColl.length?this.rotateText(e):e.fillText(f,n+.1*u,a+C)}e.filter=o,t.currObjType.isText=!1},t.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},t.prototype.rotateImage=function(e){var t,o=this.parent,i=o.activeObj,r=O.extend({},o.activeObj,null,!0),n=0===i.shapeDegree?o.transform.degree:o.transform.degree-i.shapeDegree,a={startX:0,startY:0,width:0,height:0},s=(a.width=(n=(n=-450===n?-90:n)<0?360+n:n)%90==0&&n%180!=0?i.activePoint.height:i.activePoint.width,a.height=n%90==0&&n%180!=0?i.activePoint.width:i.activePoint.height,a.startX=i.activePoint.startX,a.startY=i.activePoint.startY,a.startX),l=a.startY;e.save();for(var p=0,h=i.rotateFlipColl.length;p<h;p++){var d=i.rotateFlipColl[p];"number"==typeof d?(t=0===i.shapeDegree?d:d-i.shapeDegree,a.width=(t=(t=-450===t?-90:t)<0?360+t:t)%90==0&&t%180!=0?i.activePoint.height:i.activePoint.width,a.height=t%90==0&&t%180!=0?i.activePoint.width:i.activePoint.height,e.translate(e.canvas.width/2,e.canvas.height/2),e.rotate(Math.PI/180*d),e.translate(-e.canvas.height/2,-e.canvas.width/2),t%90==0&&t%270!=0||0===t?(l=e.canvas.width-(i.activePoint.startX+i.activePoint.width),l+=(i.activePoint.width-a.height)/2,s=a.startY):t%270==0&&(s=e.canvas.height-(i.activePoint.startY+i.activePoint.height),s+=(i.activePoint.height-a.width)/2,l=a.startX),a.startX=s,a.startY=l,i.activePoint.startX=s,i.activePoint.startY=l,i.activePoint.endX=i.activePoint.startX+a.width,i.activePoint.endY=i.activePoint.startY+a.height,i=this.updateWidthHeight(i)):("horizontal"===d&&n%90==0&&n%180!=0?d="vertical":"vertical"===d&&n%90==0&&n%180!=0&&(d="horizontal"),"horizontal"===d?(e.translate(e.canvas.width,0),e.scale(-1,1),i.activePoint=this.updateActPoint("horizontal",e)):"vertical"===d&&(e.translate(0,e.canvas.height),e.scale(1,-1),i.activePoint=this.updateActPoint("vertical",e)),a.startX=i.activePoint.startX,a.startY=i.activePoint.startY),a.startX=i.activePoint.startX,a.startY=i.activePoint.startY,s=a.startX,l=a.startY}0!==i.rotatedAngle&&o.notify("shape",{prop:"setPointCollForShapeRotation",onPropertyChange:!1,value:{obj:i}}),e.drawImage(i.imageCanvas,a.startX,a.startY,a.width,a.height),e.restore(),o.activeObj=r,360!==o.transform.degree&&-360!==o.transform.degree||(o.transform.degree=0)},t.prototype.rotateText=function(e){var t,o=this.parent,i=o.activeObj,r=O.extend({},o.activeObj,null,!0),n=o.activeObj.activePoint,a=0===i.shapeDegree?o.transform.degree:o.transform.degree-i.shapeDegree,s={startX:0,startY:0,width:0,height:0},l=(s.width=(a=(a=-450===a?-90:a)<0?360+a:a)%90==0&&a%180!=0?n.height:n.width,s.height=a%90==0&&a%180!=0?n.width:n.height,s.startX=n.startX,s.startY=n.startY,s.startX),p=s.startY;e.save();for(var h=0,d=i.rotateFlipColl.length;h<d;h++){var c=i.rotateFlipColl[h];"number"==typeof c?(t=0===i.shapeDegree?c:c-i.shapeDegree,s.width=(t=(t=-450===t?-90:t)<0?360+t:t)%90==0&&t%180!=0?n.height:n.width,s.height=t%90==0&&t%180!=0?n.width:n.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),t%90==0&&t%270!=0||0===t?(p=e.canvas.width-n.endX,l=n.startY):t%270==0&&(l=e.canvas.height-n.endY,p=n.startX),s.startX=l,s.startY=p,n.startX=l,n.startY=p,n.endX=n.startX+s.width,n.endY=n.startY+s.height,i=this.updateWidthHeight(i)):("horizontal"===c&&a%90==0&&a%180!=0?c="vertical":"vertical"===c&&a%90==0&&a%180!=0&&(c="horizontal"),"horizontal"===c?(e.translate(e.canvas.width,0),e.scale(-1,1)):"vertical"===c&&(e.translate(0,e.canvas.height),e.scale(1,-1)),i.activePoint=n=this.updateActPoint(c,e),s.startX=n.startX,s.startY=n.startY),s.startX=n.startX,s.startY=n.startY,l=s.startX,p=s.startY}0!==i.rotatedAngle&&o.notify("shape",{prop:"setPointCollForShapeRotation",onPropertyChange:!1,value:{obj:i}}),p+=.4*i.textSettings.fontSize,this.textFlipDegree(e,l,p),e.restore(),o.activeObj=r,360!==o.transform.degree&&-360!==o.transform.degree||(o.transform.degree=0)},t.prototype.textFlipDegree=function(e,t,o){for(var i=this.parent.activeObj,r=i.keyHistory.split("\n"),n=i.textSettings.fontSize,a=.85*n+(n*r.length-n*r.length)/r.length,s=0,l=r.length;s<l;s++){var p=r[s];0<s&&(1===s&&(a-=.85*n),a+=n+.15*n),e.fillText(p,t+.15*n,o+a+(0<s?.25*n:.35*-n))}},t.prototype.clearOuterCanvas=function(e){var t=this.parent,o=t.img,i=o.destLeft,r=o.destTop,n=o.destWidth,o=o.destHeight,a=0<r?r:0;e.clearRect(0,0,0<i?i:0,t.lowerCanvas.height),e.clearRect(i+n,0,t.lowerCanvas.width-(i+n),t.lowerCanvas.height),e.clearRect(0,0,t.lowerCanvas.width,a),e.clearRect(0,r+o,t.lowerCanvas.width,t.lowerCanvas.height-(r+o)),""!==t.transform.currFlipState&&(t.img.destLeft=i,t.img.destTop=r)},t.prototype.setDestPoints=function(){var e,t,o=this.parent,i=o.transform,r=i.degree,i=i.zoomFactor;r%90==0&&r%180!=0?(o.notify("transform",{prop:"calcMaxDimension",onPropertyChange:!(t={width:0,height:0}),value:{width:o.img.srcHeight,height:o.img.srcWidth,obj:t,isImgShape:null}}),e=t,this.isRotateZoom&&(e.width+=e.width*i,e.height+=e.height*i,o.img.destWidth=e.height,o.img.destHeight=e.width),o.img.destLeft=(o.lowerCanvas.clientWidth-e.height)/2,o.img.destTop=(o.lowerCanvas.clientHeight-e.width)/2,o.img.destWidth=e.height,o.img.destHeight=e.width):(o.notify("transform",{prop:"calcMaxDimension",onPropertyChange:!(t={width:0,height:0}),value:{width:o.img.srcWidth,height:o.img.srcHeight,obj:t,isImgShape:null}}),e=t,this.isRotateZoom&&(e.width+=e.width*i,e.height+=e.height*i,o.img.destWidth=e.width,o.img.destHeight=e.height),o.img.destLeft=(o.lowerCanvas.clientWidth-e.width)/2,o.img.destTop=0===r?(o.lowerCanvas.clientHeight-e.height+1)/2:(o.lowerCanvas.clientHeight-e.height)/2,o.img.destWidth=e.width,o.img.destHeight=e.height)},t.prototype.updateCurrTransState=function(e,t,o,i){var r=this.parent,n=r.img.destLeft,a=r.img.destTop;"initial"===e&&(this.lowerContext.setTransform(1,0,0,1,0,0),O.isNullOrUndefined(t))&&this.setDestPoints(),r.isCircleCrop||r.currSelectionPoint&&"crop-circle"===r.currSelectionPoint.shape?(this.currTransState(e,!0,null,o),0===r.transform.degree&&""===r.transform.currFlipState&&0===r.transform.straighten&&O.isNullOrUndefined(i)&&(r.img.destLeft=n,r.img.destTop=a),o&&(r.img.destLeft+=r.panPoint.totalPannedClientPoint.x,r.img.destTop+=r.panPoint.totalPannedClientPoint.y),r.notify("crop",{prop:"cropCircle",onPropertyChange:!1,value:{context:this.lowerContext,isSave:null,isFlip:null}}),o&&(r.img.destLeft-=r.panPoint.totalPannedClientPoint.x,r.img.destTop-=r.panPoint.totalPannedClientPoint.y)):(this.currTransState(e,null,null,o),0===r.transform.degree&&""===r.transform.currFlipState&&0===r.transform.straighten&&O.isNullOrUndefined(i)&&(r.img.destLeft=n,r.img.destTop=a))},t.prototype.currTransState=function(e,t,o,i){var r=this.parent;o=o||this.lowerContext,"initial"===e?this.setTransformColl(o,e):"reverse"===e&&(this.setTransformColl(o,e),this.setClientTransDim(t),r.isCircleCrop||r.currSelectionPoint&&"crop-circle"===r.currSelectionPoint.shape&&O.isNullOrUndefined(i))&&(i&&(r.img.destLeft+=r.panPoint.totalPannedClientPoint.x,r.img.destTop+=r.panPoint.totalPannedClientPoint.y),r.notify("crop",{prop:"cropCircle",onPropertyChange:!1,value:{context:this.lowerContext,isSave:null,isFlip:null}}),i)&&(r.img.destLeft-=r.panPoint.totalPannedClientPoint.x,r.img.destTop-=r.panPoint.totalPannedClientPoint.y)},t.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;0<=i;i--)this.setTransform(e,o.rotateFlipColl[i],!0)},t.prototype.setTransform=function(e,t,o){var i=this.parent;switch(o&&90===t?t=-90:o&&-90===t&&(t=90),"horizontal"===t&&i.transform.degree%90==0&&i.transform.degree%180!=0?t="vertical":"vertical"===t&&i.transform.degree%90==0&&i.transform.degree%180!=0&&(t="horizontal"),i.notify("transform",{prop:"setReverseRotate",onPropertyChange:!1,value:{bool:!0}}),i.notify("transform",{prop:"setReverseFlip",onPropertyChange:!1,value:{isReverseFlip:!0}}),O.isNullOrUndefined(o)&&e.clearRect(0,0,e.canvas.width,e.canvas.height),t){case 90:case-90:e.translate(e.canvas.width/2,e.canvas.height/2),e.rotate(Math.PI/180*t),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)}i.notify("transform",{prop:"setReverseRotate",onPropertyChange:!1,value:{bool:!1}}),i.notify("transform",{prop:"setReverseFlip",onPropertyChange:!1,value:{isReverseFlip:!1}})},t.prototype.drawImgToCanvas=function(e){var t=this.parent,e=(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),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=e},t.prototype.renderImage=function(e,t,o,i){var r=this.parent;r.notify("shape",{prop:"applyActObj",onPropertyChange:!1,value:{isMouseDown:null}}),O.isNullOrUndefined(t)&&(this.upperContext.clearRect(0,0,r.lowerCanvas.width,r.lowerCanvas.height),this.lowerContext.clearRect(0,0,r.lowerCanvas.width,r.lowerCanvas.height)),e?this.setTransformColl(this.lowerContext,"initial"):(0!==r.transform.zoomFactor&&(this.isRotateZoom=!0),this.updateCurrTransState("initial",null,null,i)),r.notify("transform",{prop:"setDestPointsForFlipState",onPropertyChange:!1}),this.drawImage(),r.notify("transform",{prop:"setDestPointsForFlipState",onPropertyChange:!1}),e?this.setTransformColl(this.lowerContext,"reverse"):(this.updateCurrTransState("reverse",null,null,i),this.isRotateZoom=!1),o?r.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"zoom",pen:"zoom",isPreventApply:null}}):r.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"iterate",pen:"iterate",isPreventApply:null}}),this.clearOuterCanvas(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}})},t.prototype.imageOnLoad=function(o){var i=this,r=this.parent,n=this;r.baseImg.src=o,r.baseImg.onload=function(){r.imgSrc=o,r.notify("filter",{prop:"update-finetunes",onPropertyChange:!1}),n.lowerContext.drawImage(r.baseImg,0,0,n.parent.lowerCanvas.width,n.parent.lowerCanvas.height),u.hideSpinner(r.element),r.element.style.opacity="1",n.updateBaseImgCanvas();var e,t={fileName:i.fileName,fileType:i.fileType,isValidImage:!0};n.updateCanvas(),r.currObjType.isUndoZoom&&(r.currObjType.isUndoZoom=!1,n.parent.lowerCanvas.style.display="block"),r.isUndoRedo=i.isErrorImage=!1,O.Browser.isDevice?(r.notify("toolbar",{prop:"destroy-top-toolbar",onPropertyChange:!1}),r.notify("toolbar",{prop:"destroy-bottom-toolbar",onPropertyChange:!1}),e={isApplyBtn:!1,isDevice:O.Browser.isDevice,isOkBtn:null,isResize:null,isFrame:null,isMainToolbar:!0},r.notify("toolbar",{prop:"init-main-toolbar",onPropertyChange:!1,value:e}),r.notify("toolbar",{prop:"create-bottom-toolbar",onPropertyChange:!1})):(r.notify("toolbar",{prop:"destroy-top-toolbar",onPropertyChange:!1}),r.notify("toolbar",{prop:"init-main-toolbar",onPropertyChange:!(e={isApplyBtn:!1,isDevice:!1,isOkBtn:null}),value:e})),r.isImageLoaded&&"0.5"!==r.element.style.opacity&&r.trigger("fileOpened",t)},r.baseImg.onerror=function(){u.hideSpinner(r.element),n.isErrorImage=!0,n.errorLoading()}},t.prototype.errorLoading=function(){this.parent.trigger("fileOpened",{fileName:null,fileType:null,isValidImage:!1})},t.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)},t.prototype.updateCanvas=function(){var e=this.parent,t=(e.img.srcWidth=e.baseImgCanvas.width,e.img.srcHeight=e.baseImgCanvas.height,{width:0,height:0}),t=(e.notify("transform",{prop:"calcMaxDimension",onPropertyChange:!1,value:{width:e.img.srcWidth,height:e.img.srcHeight,obj:t,isImgShape:null}}),e.img.destLeft=(e.lowerCanvas.clientWidth-t.width)/2,e.img.destTop=(e.lowerCanvas.clientHeight-t.height+1)/2,this.drawImgToCanvas(t),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}}),{startX:e.img.destLeft,startY:e.img.destTop,width:e.img.destWidth,height:e.img.destHeight}),t=(e.notify("crop",{prop:"setCropDestPoints",onPropertyChange:!1,value:{point:t}}),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=t,0<e.img.destWidth&&0<e.img.destHeight&&(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),O.isNullOrUndefined(this.initZoomValue)&&(this.initZoomValue=e.zoomSettings.zoomFactor),this.isImageEdited=!1},t.prototype.resetFrameZoom=function(e){var t,o=this.parent;O.isNullOrUndefined(o.tempFrameZoomLevel)||(t=o.tempFrameZoomLevel,o.tempFrameZoomLevel=null,o.notify("transform",{prop:"resetZoom",onPropertyChange:!1}),o.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:t,zoomPoint:null,isResize:!0}}),t=o.cancelCropSelection,e&&t&&(t.previousObj.frameObj=O.extend({},o.frameObj,null,!0),t.currentObj.frameObj=O.extend({},o.frameObj,null,!0),t.previousObj.frame=t.currentObj.frame=o.frameObj.type),this.updateCropSelObj(),o.cancelCropSelection=null)},t.prototype.performCancel=function(e,t,o){var i=this.parent;o&&(i.noPushUndo=!1);var r,n=i.isStraightening,a=(e=e||!1,{bool:!1});i.allowDownScale=!0,i.notify("selection",{prop:"getFreehandDrawEditing",onPropertyChange:!1,value:{obj:a}}),O.isNullOrUndefined(t)&&JSON.stringify(i.frameObj)!==JSON.stringify(i.tempFrameObj)&&(O.extend(i.frameObj,i.tempFrameObj),this.renderImage(null,null,!0)),this.resetFrameZoom(!1),a.bool?(i.notify("freehand-draw",{prop:"cancelFhd",onPropertyChange:!1}),i.notify("toolbar",{prop:"destroy-qa-toolbar",onPropertyChange:!1}),i.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"ok"}})):"block"===i.textArea.style.display||"inline-block"===i.textArea.style.display?(i.textArea.style.display="none",i.textArea.value="",i.textArea.style.transform="",this.prevActObj?(i.activeObj=this.prevActObj,this.prevActObj=null):(i.activeObj.strokeSettings=this.tempStrokeSettings,i.activeObj.textSettings=this.tempTextSettings),i.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"cancel"}}),this.isShapeTextInserted&&i.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),i.notify("shape",{prop:"applyActObj",onPropertyChange:!1,value:{isMouseDown:!0}}),i.notify("toolbar",{prop:"refresh-main-toolbar",onPropertyChange:!1}),i.notify("selection",{prop:"setTempActObj",onPropertyChange:!1,value:{obj:i.activeObj}}),i.drawingShape&&i.enableShapeDrawing(i.toPascalCase(i.drawingShape),!0)):(!O.Browser.isDevice||O.Browser.isDevice&&!n)&&document.querySelector("#"+i.element.id+"_sliderWrapper")||i.currObjType.isFiltered?(this.lowerContext.filter=this.tempAdjValue,i.canvasFilter=this.tempAdjValue,i.notify("filter",{prop:"setAdjustmentValue",onPropertyChange:!1,value:{adjustmentValue:this.tempAdjValue}}),i.initialAdjustmentValue=this.tempAdjValue,1<this.lowerContext.filter.split(" ").length&&"1"===this.lowerContext.filter.split(" ")[0].split("(")[1].split(")")[0]&&i.notify("filter",{prop:"setBrightnessAdjusted",onPropertyChange:!1,value:{isBrightnessAdjusted:!1}}),i.currentFilter=this.tempFilter,i.notify("filter",{prop:"setBevelFilter",onPropertyChange:!1,value:{bevelFilter:this.lowerContext.filter}}),this.lowerContext.clearRect(0,0,i.lowerCanvas.width,i.lowerCanvas.height),this.redrawImgWithObj(),i.currObjType.isFiltered=!1,i.notify("filter",{prop:"getTempAdjustmentLevel",onPropertyChange:!(t={tempAdjustmentLevel:null}),value:{obj:t}}),i.notify("filter",{prop:"setAdjustmentLevel",onPropertyChange:!1,value:{adjustmentLevel:O.extend({},t.tempAdjustmentLevel,{},!0)}}),i.notify("undo-redo",{prop:"setUndoRedoStep",onPropertyChange:!1,value:{step:this.tempUndoRedoStep}}),i.upperCanvas.style.cursor=i.cursor="default",i.currObjType.isCustomCrop=!1,this.tempStrokeSettings={strokeColor:"#fff",fillColor:"",strokeWidth:null},this.clearOuterCanvas(this.lowerContext),(i.currSelectionPoint&&"crop-circle"===i.currSelectionPoint.shape||i.isCircleCrop)&&i.notify("crop",{prop:"cropCircle",onPropertyChange:!1,value:{context:this.lowerContext,isSave:null,isFlip:null}}),r={type:"main",isApplyBtn:null,isCropping:null,isZooming:null},i.element.querySelector(".e-contextual-toolbar-wrapper").classList.add("e-hide"),i.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:r}),i.activeObj.shape&&"image"===i.activeObj.shape&&i.notify("toolbar",{prop:"destroy-qa-toolbar",onPropertyChange:!1}),i.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"cancel"}}),i.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),this.upperContext.clearRect(0,0,i.upperCanvas.width,i.upperCanvas.height)):e&&(!O.Browser.isDevice||O.Browser.isDevice&&!n)?i.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!(r={type:"main",isApplyBtn:null,isCropping:null,isZooming:null}),value:r}):(this.cancelItems(),0<i.transform.zoomFactor?(i.togglePan=!0,i.notify("selection",{prop:"setDragCanvas",value:{bool:!0}})):(i.togglePan=!1,i.notify("selection",{prop:"setDragCanvas",value:{bool:!1}}))),this.isShapeTextInserted=!1,this.isNewPath=!1,i.notify("toolbar",{prop:"refresh-dropdown-btn",value:{isDisabled:!1}}),i.notify("toolbar",{prop:"setCurrentToolbar",value:{type:"main"}}),o&&(i.noPushUndo=!1),i.drawingShape=null,i.notify("draw",{prop:"resetTempObjColl"}),i.notify("draw",{prop:"resetTempPointColl"})},t.prototype.cancelItems=function(){var e,t=this.parent,o=!1,i=t.element.id,r=t.element.querySelector("#"+i+"_aspectratio"),i=t.element.querySelector("#"+i+"_nonaspectratio");switch((o=void 0===(e=void 0!==t.activeObj.shape?t.activeObj.shape.split("-"):e)&&t.currObjType.isCustomCrop||void 0!==e&&"crop"===e[0]?!0:o)&&t.isCropTab&&(t.isCropTab=!1,t.transform.zoomFactor=t.transform.defaultZoomFactor),t.isResize&&(r||i||"resize-toolbar"===t.currentToolbar)&&(t.notify("selection",{prop:"getNumTextValue",onPropertyChange:!(e={width:null,height:null}),value:{obj:e}}),r={x:e.width,y:e.height},i=t.element.querySelector("#"+t.element.id+"_aspectratio"),e=t.element.querySelector(".e-ie-toolbar-aspect-ratio-btn"),r.x&&r.y&&!O.isNullOrUndefined(t.aspectWidth)&&(i||e&&!e.classList.contains("e-hidden")?t.notify("transform",{prop:"resizeImage",value:{width:t.aspectWidth,height:t.aspectHeight}}):(r=t.currObjType.isUndoAction,t.currObjType.isUndoAction=!1,t.notify("transform",{prop:"resizeCrop",value:{width:t.aspectWidth,height:t.aspectHeight}}),t.currObjType.isUndoAction=r)),i={prevCropObj:t.prevCropObj},e={prevObj:t.prevObj},t.notify("toolbar",{prop:"getPrevCropObj",onPropertyChange:!1,value:{obj:i}}),t.notify("toolbar",{prop:"getPrevObj",onPropertyChange:!1,value:{obj:e}}),i.prevCropObj&&e.prevObj&&(t.objColl=[],t.pointColl=[],t.freehandCounter=0,t.cropObj=O.extend({},i.prevCropObj,{},!0),this.setCurrentObj(e.prevObj),t.objColl=e.prevObj.objColl,t.pointColl=e.prevObj.pointColl,t.freehandCounter=t.pointColl.length,t.transform.straighten=0,t.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"zoom",pen:"zoom",isPreventApply:null}}),r=t.currSelectionPoint?O.extend({},t.currSelectionPoint,{},!0):null,t.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:-t.transform.zoomFactor,zoomPoint:null,isResize:!0}}),t.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:e.prevObj.defaultZoom,zoomPoint:null,isResize:!0}}),t.currSelectionPoint=r,e.prevObj.zoomFactor&&t.setProperties({zoomSettings:{zoomFactor:e.prevObj.zoomFactor}},!0),t.notify("transform",{prop:"setPreviousZoomValue",onPropertyChange:!1,value:{previousZoomValue:t.zoomSettings.zoomFactor}})),t.isResize=!1,t.notify("transform",{prop:"setResizedImgAngle",onPropertyChange:!1,value:{angle:null}}),i=t.isCropTab,t.isCropTab=!1,this.updateCropSelObj(),t.cancelCropSelection=null,t.isCropTab=i),!0){case t.togglePen:this.cancelPen();break;case"text"===t.activeObj.shape:this.cancelText();break;case-1!==["rectangle","ellipse","line","arrow","path","image"].indexOf(t.activeObj.shape):this.cancelShape();break;case o:this.cancelSelection();break;default:t.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),this.upperContext.clearRect(0,0,t.upperCanvas.width,t.upperCanvas.height),t.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"cancel"}})}t.notify("selection",{prop:"setCurrentDrawingShape",onPropertyChange:!1,value:{value:""}}),t.upperCanvas.style.cursor=t.cursor="default",t.currObjType.isCustomCrop=!1,this.tempStrokeSettings={strokeColor:"#fff",fillColor:"",strokeWidth:null};t.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"main",isApplyBtn:null,isCropping:!1,isZooming:null}})},t.prototype.cancelPen=function(){var e=this.parent,t=(this.upperContext.clearRect(0,0,e.upperCanvas.width,e.upperCanvas.height),e.togglePen=!1,e.upperCanvas.style.cursor=e.cursor="default",O.extend([],e.pointColl,[],!0));e.pointColl={};for(var o=0;o<this.tempFreehandCounter;o++)e.pointColl[o]=t[o];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=O.extend([],this.tempObjColl,[],!0),e.pointColl=O.extend([],this.tempPointColl,[],!0),e.freehandCounter=e.pointColl.length,this.tempPointColl={},this.renderImage(),e.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"ok",isCancel:!0}})},t.prototype.cancelText=function(){var e,t,o=this.parent;o.notify("shape",{prop:"setTextSettings",onPropertyChange:!1,value:{textSettings:this.tempTextSettings,fontFamily:null,fontSize:null}}),o.notify("shape",{prop:"setStrokeSettings",value:{strokeSettings:this.tempStrokeSettings,strokeColor:null,fillColor:null,strokeWidth:null}}),!O.isNullOrUndefined(o.activeObj.currIndex)&&(o.notify("undo-redo",{prop:"getAppliedUndoRedoColl",value:{obj:t={appliedUndoRedoColl:[]}}}),e=t.appliedUndoRedoColl.length,t=t.appliedUndoRedoColl[e-1],this.prevActObj)&&t&&t.currentObjColl.length&&t.currentObjColl[t.currentObjColl.length-1].currIndex===this.prevActObj.currIndex?(o.activeObj=this.prevActObj,this.prevActObj=null):(o.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),this.upperContext.clearRect(0,0,o.upperCanvas.width,o.upperCanvas.height)),o.notify("toolbar",{prop:"destroy-qa-toolbar",onPropertyChange:!1}),this.tempTextSettings={text:"Enter Text",fontFamily:o.fontFamily.default,fontSize:null,fontRatio:null,bold:!1,italic:!1,underline:!1},o.objColl=O.extend([],this.tempObjColl,[],!0),o.pointColl=O.extend([],this.tempPointColl,[],!0),this.renderImage(),this.tempObjColl=[],o.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"ok",isCancel:!0}})},t.prototype.cancelShape=function(){var e=this.parent;if(e.notify("shape",{prop:"setStrokeSettings",value:{strokeSettings:this.tempStrokeSettings,strokeColor:null,fillColor:null,strokeWidth:null}}),O.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);else{for(var t={appliedUndoRedoColl:[]},o=(e.notify("undo-redo",{prop:"getAppliedUndoRedoColl",value:{obj:t}}),void 0),i=0,r=t.appliedUndoRedoColl.length;i<r;i++)for(var n=t.appliedUndoRedoColl[i].currentObjColl,a=0,s=n.length;a<s;a++)if(this.prevActObj&&this.prevActObj.currIndex&&n[a].currIndex===this.prevActObj.currIndex){o=n[0];break}this.prevActObj&&o?(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 l={undoRedoStep:null};e.notify("undo-redo",{prop:"getUndoRedoStep",value:{obj:l}}),t.appliedUndoRedoColl[l.undoRedoStep-1]?e.objColl=O.extend([],t.appliedUndoRedoColl[l.undoRedoStep-1].currentObjColl,[],!0):e.objColl=[]}this.renderImage()}e.currObjType.isDragging=!1,e.notify("toolbar",{prop:"destroy-qa-toolbar",onPropertyChange:!1}),e.objColl=O.extend([],this.tempObjColl,[],!0),e.pointColl=O.extend([],this.tempPointColl,[],!0),this.renderImage(),this.tempObjColl=[],e.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"ok",isCancel:!0}})},t.prototype.cancelSelection=function(){var e,t=this.parent;t.cancelCropSelection&&(e={value:t.tempStraighten},t.transform.straighten=e.value,t.straightenBaseImageCanvas(),t.notify("freehand-draw",{prop:"resetStraightenPoint"}),t.notify("draw",{prop:"render-image",value:{isMouseWheel:!1}}),t.notify("draw",{prop:"setStraightenActObj",value:{activeObj:t.activeObj}}),t.notify("crop",{prop:"resizeWrapper"}),this.updateCropSelObj(),this.tempStraightenDestPoints)&&JSON.stringify(this.tempStraightenDestPoints)!==JSON.stringify(this.straightenDestPoints)&&(this.straightenDestPoints=O.extend({},this.tempStraightenDestPoints,{},!0))},t.prototype.updateCropSelObj=function(){var e=this.parent;e.cancelCropSelection&&(e.cropObj=O.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=O.extend({},e.cancelCropSelection.previousCropObj.activeObj,!0),e.currSelectionPoint&&O.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}})},t.prototype.updateCropSelection=function(){var e=this.parent,t={currObj:{}},t=(e.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:t}}),t.currObj),o=(t.objColl=O.extend([],e.objColl,[],!0),t.pointColl=O.extend([],e.pointColl,[],!0),t.afterCropActions=O.extend([],e.afterCropActions,[],!0),{selPointColl:null});e.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:o}}),t.selPointColl=O.extend([],o.selPointColl,[],!0),e.cancelCropSelection={operation:"cropTransform",previousObj:t,currentObj:t,previousObjColl:t.objColl,currentObjColl:t.objColl,previousPointColl:t.pointColl,currentPointColl:t.pointColl,previousSelPointColl:t.selPointColl,currentSelPointColl:t.selPointColl,previousCropObj:O.extend({},e.cropObj,{},!0),currentCropObj:O.extend({},e.cropObj,{},!0),previousText:null,currentText:null,filter:null,isCircleCrop:e.isCircleCrop}},t.prototype.updateFlipPan=function(e){var t,o=this.parent;""!==o.transform.currFlipState&&(t=this.lowerContext.filter,o.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),o.notify("transform",{prop:"rotatedFlip",onPropertyChange:!1}),this.lowerContext.filter="none",o.notify("freehand-draw",{prop:"freehandRedraw",onPropertyChange:!1,value:{context:this.lowerContext,points:null}}),this.lowerContext.filter=t,this.upperContext.clearRect(0,0,o.upperCanvas.width,o.upperCanvas.height),e)&&this.drawObject("duplicate",e)},t.prototype.select=function(e,t,o,i,r){var n,a,s=this.parent;e=e.toLowerCase(),!s.disabled&&s.isImageLoaded&&(s.allowDownScale=!1,s.notify("filter",{prop:"getCurrentObj",onPropertyChange:!(a={currObj:{}}),value:{object:a}}),(a=a.currObj).objColl=O.extend([],s.objColl,[],!0),a.pointColl=O.extend([],s.pointColl,[],!0),a.afterCropActions=s.afterCropActions,s.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!(n={selPointColl:null}),value:{obj:n}}),a.selPointColl=O.extend([],n.selPointColl,[],!0),s.notify("crop",{prop:"setPreviousCropCurrentObj",onPropertyChange:!1,value:{obj:a}}),0<s.transform.zoomFactor&&s.activeObj.shape&&"crop"===s.activeObj.shape.split("-")[0]&&O.isNullOrUndefined(this.currSelPoint)&&(this.currSelPoint=O.extend({},s.activeObj,{},!0)),n=!1,((a=void 0)===(a=void 0!==s.activeObj.shape?s.activeObj.shape.split("-"):a)&&s.currObjType.isCustomCrop||void 0!==a&&"crop"===a[0])&&(n=!0),s.notify("filter",{prop:"getCurrentObj",onPropertyChange:!(a={currObj:{}}),value:{object:a}}),(a=a.currObj).objColl=O.extend([],s.objColl,[],!0),a.pointColl=O.extend([],s.pointColl,[],!0),a.afterCropActions=O.extend([],s.afterCropActions,[],!0),s.notify("shape",{prop:"redrawActObj",onPropertyChange:!1,value:{x:null,y:null,isMouseDown:null}}),s.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),s.notify("shape",{prop:"setKeyHistory",onPropertyChange:!1,value:{keyHistory:""}}),this.upperContext.clearRect(0,0,s.upperCanvas.width,s.upperCanvas.height),s.upperCanvas.style.display="block",s.currSelectionPoint||0!==s.transform.defaultZoomFactor||0!==s.transform.degree&&0!==s.panPoint.totalPannedInternalPoint.x&&0!==s.panPoint.totalPannedInternalPoint.y&&!n?(s.isCircleCrop=!1,0===s.transform.defaultZoomFactor||this.isResizeSelect||(a=s.isCropTab,s.isCropTab=!1,s.notify("transform",{prop:"resetZoom",onPropertyChange:!1}),s.isCropTab=a,this.resetPanPoints()),s.notify("freehand-draw",{prop:"updateFHDColl",onPropertyChange:!1}),s.isCropTab=!0,s.isCircleCrop=!1,this.isResizeSelect||s.notify("crop",{prop:"setCurrSelPoints",onPropertyChange:!1,value:{isSetDimension:!0}}),s.transform.zoomFactor=s.transform.cropZoomFactor,O.isNullOrUndefined(s.cropObj.activeObj.shape)&&(s.currObjType.shape="crop-"+e,this.drawNewSelection(e,t,o,i,r))):(this.isCropSelect?this.isCropSelect=!1:(s.notify("crop",{prop:"adjustStraightenForShapes",onPropertyChange:!1,value:{type:"reverse",isInitialRotated:!0}}),s.notify("freehand-draw",{prop:"updateFHDColl",onPropertyChange:!1}),this.renderImage()),"custom"===e&&(s.currObjType.shape=""),this.drawNewSelection(e,t,o,i,r)))},t.prototype.drawNewSelection=function(e,t,o,i,r){var n,a=this.parent,e="crop-"+e.toLowerCase();"crop-custom"==e?""!==a.currObjType.shape&&"crop-custom"!==a.currObjType.shape||(this.drawCustomSelection("crop-custom",t,o,i,r),this.adjToStraighten(),this.updateSelectionInsert(),a.isStraightening&&(this.straightenActObj=O.extend({},a.activeObj,{},!0),this.straightenInitZoom=a.transform.zoomFactor)):"crop-canvas"==e?(a.upperCanvas.style.display="block",a.notify("selection",{prop:"setDragCanvas",value:{bool:!0}})):(a.currObjType.isCustomCrop=!1,a.currObjType.shape=e,i&&r?n={startX:t,startY:o,endX:t+i,endY:o+r,width:i,height:r}:i&&"crop-circle"==e&&(n={startX:t,startY:o,endX:t+i,endY:o+i,width:i,height:i}),a.activeObj.shape=e,this.updateSelectionInsert(n))},t.prototype.updateSelectionInsert=function(e){var t=this.parent,o=t.activeObj.activePoint,i={shapeSettingsObj:{}},i=(t.notify("selection",{prop:"updatePrevShapeSettings",onPropertyChange:!1,value:{obj:i}}),{type:t.getSelectionType(i.shapeSettingsObj.type),startX:i.shapeSettingsObj.startX,startY:i.shapeSettingsObj.startY,width:i.shapeSettingsObj.width,height:i.shapeSettingsObj.height}),i={action:"insert",previousSelectionSettings:i,currentSelectionSettings:i};t.trigger("selectionChanging",i),t.notify("shape",{prop:"updSelChangeEventArgs",onPropertyChange:!1,value:{selectionSettings:i.currentSelectionSettings}}),"Custom"===i.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))},t.prototype.drawCustomSelection=function(e,t,o,i,r){var n,a,s,l,p,h,d,c,u,g,v,f=this.parent,C=f.activeObj.activePoint;f.currObjType.isCustomCrop=!0,this.upperContext.clearRect(0,0,f.upperCanvas.width,f.upperCanvas.height),f.currObjType.shape=f.activeObj.shape=e.toLowerCase(),O.isNullOrUndefined(t)||O.isNullOrUndefined(o)||O.isNullOrUndefined(i)||O.isNullOrUndefined(r)?i&&r?(p=(e=f.img).destLeft,h=e.destTop,d=e.destWidth,c=e.destHeight,C.width=i,C.height=r,C.startX=p+(d/2-i/2),C.startY=h+(c/2-r/2)):(O.isNullOrUndefined(f.transform.zoomFactor)||0===f.transform.zoomFactor?(g=(e=f.img).destLeft,n=e.destTop,u=e.destWidth,e=e.destHeight,a=f.lowerCanvas.width,s=f.lowerCanvas.height,l=C,0<=g&&0<=n?(l.startX=g,l.startY=n,l.endX=g+u,l.endY=n+e):0<=g?(l.startX=g,l.startY=7.5,l.endX=g+u,l.endY=s-15):0<=n?(l.startX=7.5,l.startY=n,l.endX=a-15,l.endY=n+e):(l.startX=7.5,l.startY=7.5,l.endX=a-15,l.endY=s-15)):(u=(g=f.img).destLeft,n=g.destTop,e=g.destWidth,a=g.destHeight,l=f.lowerCanvas.width,s=f.lowerCanvas.height,(g=C).startX=Math.max(0<u?u:7.5,u),g.startY=Math.max(0<n?n:7.5,n),g.endX=Math.min(u+e+15<l?u+e-15:l-15,u+e),g.endY=Math.min(n+a+15<s?n+a-15:s-15,n+a)),p=(l=f.img).destLeft,h=l.destTop,d=l.destWidth,c=l.destHeight,u=f.lowerCanvas.clientWidth,e=f.lowerCanvas.clientHeight,(g=C).startX=Math.max(g.startX,p),g.startY=Math.max(g.startY,h),g.endX=Math.min(g.endX,p+d),g.endY=Math.min(g.endY,h+c),0<f.transform.straighten?(this.imgCanvasPoints[0].x>g.startX&&(g.startX=this.imgCanvasPoints[0].x),this.imgCanvasPoints[0].y>g.startY&&(g.startY=this.imgCanvasPoints[0].y),this.imgCanvasPoints[2].x<g.endX&&(g.endX=this.imgCanvasPoints[2].x),this.imgCanvasPoints[2].y<g.endY&&(g.endY=this.imgCanvasPoints[2].x)):f.transform.straighten<0&&(this.imgCanvasPoints[3].x>g.startX&&(g.startX=this.imgCanvasPoints[3].x),this.imgCanvasPoints[3].y<g.startY&&(g.startY=this.imgCanvasPoints[3].y),this.imgCanvasPoints[1].x<g.endX&&(g.endX=this.imgCanvasPoints[1].x),this.imgCanvasPoints[1].y>g.endY)&&(g.endY=this.imgCanvasPoints[1].x),g.startX===p&&u<p+d&&(g.endX=u-15),g.startY===h&&e<h+c&&(g.endY=e-15),f.activeObj.activePoint.startX>f.activeObj.activePoint.endX&&(v=f.activeObj.activePoint.startX,f.activeObj.activePoint.startX=f.activeObj.activePoint.endX,f.activeObj.activePoint.endX=v),f.activeObj.activePoint.startY>f.activeObj.activePoint.endY&&(v=f.activeObj.activePoint.startY,f.activeObj.activePoint.startY=f.activeObj.activePoint.endY,f.activeObj.activePoint.endY=v),f.activeObj=this.updateWidthHeight(f.activeObj),this.updateActiveObject(C,f.activeObj),this.adjActObj()):(C.startX=t,C.startY=o,C.endX=t+i,C.endY=o+r,C.width=i,C.height=r),this.updateSelectionInsert()},t.prototype.adjToStraighten=function(){var e,t=this.parent;0!==t.transform.straighten&&t.isStraightening&&((e=t.activeObj.activePoint).startX+=7.5,e.startY+=7.5,e.endX-=7.5,e.endY-=7.5,t.activeObj=this.updateWidthHeight(t.activeObj))},t.prototype.adjActObj=function(){var e=this.parent;if(0!==e.transform.straighten)for(var t=e.activeObj.activePoint,o=O.extend({},t,{},!0),i=0;;){i++;var r={isIntersect:null,arr:null};if(e.notify("draw",{prop:"updateImgCanvasPoints",onPropertyChange:!1}),e.notify("draw",{prop:"isLinesIntersect",onPropertyChange:!1,value:{obj:r}}),r.arr[0]||r.arr[1]||r.arr[2]||r.arr[3]||100===i){t=O.extend({},o,{},!0);break}o=O.extend({},t,{},!0),t.startX-=5,t.endX+=5,t.width=t.endX-t.startX,this.updateActiveObject(t,e.activeObj)}},t.prototype.callUpdateCurrTransState=function(){var e=this.parent,t=O.extend([],e.objColl,[],!0),o=O.extend({},e.activeObj,{},!0),i=(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&&0<e.rotateFlipColl.length&&(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,this.lowerContext.filter),t=(0===e.transform.degree&&e.notify("transform",{prop:"setDestPointsForFlipState",onPropertyChange:!1}),this.drawImage(),this.updateCurrTransState("reverse"),0===e.transform.degree&&0<e.rotateFlipColl.length&&(e.img.destLeft+=e.panPoint.totalPannedPoint.x,e.img.destTop+=e.panPoint.totalPannedPoint.y),this.isRotateZoom=!1,e.objColl=t,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=t,this.lowerContext.filter=i,e.activeObj=o},t.prototype.resetPanPoints=function(){this.parent.panPoint.totalPannedPoint={x:0,y:0},this.parent.panPoint.totalPannedClientPoint={x:0,y:0},this.parent.panPoint.totalPannedInternalPoint={x:0,y:0}},t.prototype.setClientTransDim=function(e){var t,o=this.parent;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,t=o.img.destWidth,o.img.destWidth=o.img.destHeight,o.img.destHeight=t):O.isNullOrUndefined(e)&&(o.img.destLeft=(o.lowerCanvas.clientWidth-o.img.destWidth)/2,o.img.destTop=(o.lowerCanvas.clientHeight-o.img.destHeight+1)/2)},t.prototype.redrawImgWithObj=function(){var e,t=this.parent,o={canvasFilter:t.canvasFilter};this.lowerContext.filter=o.canvasFilter,0!==t.rotateFlipColl.length?(o=O.extend({},t.panPoint.totalPannedInternalPoint,{},!0),e={startX:t.img.destLeft,startY:t.img.destTop,width:t.img.destWidth,height:t.img.destHeight},this.callUpdateCurrTransState(),t.panPoint.totalPannedInternalPoint=o,t.img.destLeft=e.startX,t.img.destTop=e.startY,t.img.destWidth=e.width,t.img.destHeight=e.height):this.callUpdateCurrTransState(),t.isCircleCrop&&t.notify("crop",{prop:"cropCircle",onPropertyChange:!1,value:{context:this.lowerContext,isSave:null,isFlip:null}})},t.prototype.setCurrentObj=function(e,t){var o,i,r=this.parent,n=!!e,a=(n||(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,!n||e.activeObj.shape&&"crop"===e.activeObj.shape.split("-")[0]?r.transform.zoomFactor=e.cropZoom:r.transform.zoomFactor=e.defaultZoom,r.setProperties({zoomSettings:{zoomFactor:e.zoomFactor}},!0),r.notify("transform",{prop:"setPreviousZoomValue",onPropertyChange:!1,value:{previousZoomValue:e.previousZoomValue}}),r.panPoint.totalPannedPoint=O.extend({},e.totalPannedPoint,{},!0),r.panPoint.totalPannedClientPoint=O.extend({},e.totalPannedClientPoint,{},!0),r.panPoint.totalPannedInternalPoint=O.extend({},e.totalPannedInternalPoint,{},!0),O.extend({},e.tempFlipPanPoint,{},!0)),a=(r.notify("crop",{prop:"setTempFlipPanPoint",onPropertyChange:!1,value:{point:a}}),r.rotateFlipColl=O.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&&!t||(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.isCircleCrop),t=(O.isNullOrUndefined(r.currSelectionPoint)?o=null:(o=O.extend({},r.currSelectionPoint,{},!0),r.currSelectionPoint=null),r.isCircleCrop=!1,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=O.extend({},e.totalPannedClientPoint,{},!0),r.panPoint.totalPannedInternalPoint=O.extend({},e.totalPannedInternalPoint,{},!0)),r.activeObj=O.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),O.extend({},e.activeObj,{},!0)),s=!1,l=(0<r.afterCropActions.length&&(i={collection:r.afterCropActions},r.notify("shape",{prop:"alignRotateFlipColl",onPropertyChange:!1,value:{collection:r.afterCropActions,isRotateFlipCollection:null,obj:i}}),r.afterCropActions=i.collection),O.extend([],r.afterCropActions,[],!0));if(!n&&0<l.length){for(var s=!0,p=0,h=l.length;p<h;p++)"horizontalflip"!==l[p]&&"verticalflip"!==l[p]||(r.activeObj=O.extend({},o,{},!0),this.rotatedFlipCropSel=!0),r.notify("transform",{prop:"updateTransform",onPropertyChange:!1,value:{text:l[p]}});t=O.extend({},r.activeObj,{},!0),this.resetPanPoints(),r.activeObj=t,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=l,this.isCancelAction||s||(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=t,r.isCircleCrop=a,(O.isNullOrUndefined(o)||(r.currSelectionPoint=O.extend({},o,{},!0),r.currSelectionPoint&&O.isNullOrUndefined(r.currSelectionPoint.shape)))&&(r.currSelectionPoint=null)},t.prototype.drawCropSelectionImage=function(e,t){var o,i=this.parent,r=this.lowerContext.filter,t=(i.clearContext(this.lowerContext),i.clearContext(this.upperContext),this.lowerContext.setTransform(1,0,0,1,0,0),t?this.updateCurrTransState("initial"):this.setTransformColl(this.lowerContext,"initial"),i.notify("transform",{prop:"setDestPointsForFlipState",onPropertyChange:!1}),this.drawImage(),t?this.updateCurrTransState("reverse"):this.setTransformColl(this.lowerContext,"reverse"),i.img.destLeft=i.cropObj.destPoints.startX,i.img.destTop=i.cropObj.destPoints.startY,O.extend({},e.activeObj,{},!0));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&&(o={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=o.startX,i.img.destTop=o.startY,i.img.destWidth=o.width,i.img.destHeight=o.height),i.activeObj=t,this.lowerContext.filter=r},t.prototype.performPointZoom=function(e,t,o,i,r){var n=this.parent,a=n.img,s=a.destLeft,l=a.destTop,s=(e-s)/a.destWidth,l=(t-l)/a.destHeight,a=n.isUndoRedo,r=(n.isUndoRedo=!0,n.setProperties({zoomSettings:{zoomPoint:{x:e,y:t}}},!0),r||("zoomIn"===o?.1:-.1));n.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:r,zoomPoint:null,isResize:i}}),n.isUndoRedo=a,this.panToPoint(e,t,s,l)},t.prototype.panToPoint=function(e,t,o,i){var r,n,a,s,l,p,h,d,c=this.parent;0<c.transform.zoomFactor&&(r=c.img.destLeft,n=c.img.destTop,a=O.extend({},c.activeObj,{},!0),0===c.transform.degree?(c.img.destLeft=e-o*c.img.destWidth,c.img.destTop=t-i*c.img.destHeight,this.drawZoomPanImage(c.img.destLeft-r,c.img.destTop-n)):(s=c.isCropTab,c.isCropTab=!0,l=O.extend([],c.objColl,[],!0),p=O.extend([],c.pointColl,[],!0),c.notify("freehand-draw",{prop:"getStraightenPoint",onPropertyChange:!(h={straightenPoint:null}),value:{obj:h}}),c.objColl=[],c.pointColl=[],c.freehandCounter=0,c.notify("freehand-draw",{prop:"setStraightenPoint",onPropertyChange:!1,value:{x:null,y:null,ratioX:null,ratioY:null}}),c.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!(d={selPointColl:null}),value:{obj:d}}),d=d.selPointColl,c.notify("freehand-draw",{prop:"setSelPointColl",onPropertyChange:!1,value:{obj:{selPointColl:[]}}}),c.panPoint.currentPannedPoint={x:e-o*c.img.destWidth-r,y:t-i*c.img.destHeight-n},c.notify("transform",{prop:"rotatePan",onPropertyChange:!1,value:{isCropSelection:null,isDefaultZoom:null}}),c.isCropTab=s,c.objColl=l,c.pointColl=p,c.freehandCounter=c.pointColl.length,h.straightenPoint.x&&h.straightenPoint.y&&c.notify("freehand-draw",{prop:"setStraightenPoint",onPropertyChange:!1,value:{x:h.straightenPoint.x,y:h.straightenPoint.y,ratioX:h.straightenPoint.ratioX,ratioY:h.straightenPoint.ratioY}}),c.notify("freehand-draw",{prop:"setSelPointColl",onPropertyChange:!1,value:{obj:{selPointColl:d}}}),c.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"pan",pen:"pan",x:c.panPoint.currentPannedPoint.x,y:c.panPoint.currentPannedPoint.y,panRegion:""}})),this.adjustPanning(a),c.activeObj=a,0!==c.activeObj.activePoint.width)&&0!==c.activeObj.activePoint.height&&this.drawObject("duplicate",null,null,null,!0)},t.prototype.adjustPanning=function(e){var t,o,i,r,n,a=this.parent,e=e.activePoint,s=e.startX,l=e.startY,p=e.width,e=e.height;0!==p&&0!==e&&(t=(n=a.img).destLeft,o=n.destTop,r=n.destWidth,n=n.destHeight,i={x:0,y:0},s<t?i.x=t-s:t+r<s+p&&(i.x=t+r-(s+p)),l<o?i.y=o-l:o+n<l+e&&(i.y=o+n-(l+e)),0===a.transform.degree?(a.img.destLeft-=i.x,a.img.destTop-=i.y,this.drawZoomPanImage(a.img.destLeft-t,a.img.destTop-o)):(r=a.isCropTab,a.isCropTab=!0,s=O.extend([],a.objColl,[],!0),p=O.extend([],a.pointColl,[],!0),a.objColl=[],a.pointColl=[],a.freehandCounter=0,a.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!(n={selPointColl:null}),value:{obj:n}}),l=n.selPointColl,a.notify("freehand-draw",{prop:"setSelPointColl",onPropertyChange:!1,value:{obj:{selPointColl:[]}}}),a.img.destLeft-=i.x,a.img.destTop-=i.y,a.panPoint.currentPannedPoint={x:a.img.destLeft-t,y:a.img.destTop-o},a.notify("transform",{prop:"rotatePan",onPropertyChange:!1,value:{isCropSelection:null,isDefaultZoom:null}}),a.isCropTab=r,a.objColl=s,a.pointColl=p,a.freehandCounter=a.pointColl.length,a.notify("freehand-draw",{prop:"setSelPointColl",onPropertyChange:!1,value:{obj:{selPointColl:l}}}),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:""}})))},t.prototype.panToSel=function(){var e=this.parent,t=O.extend({},e.activeObj,{},!0),o=t.activePoint,i=o.startX,r=o.startY,n=o.width,o=o.height,a={straightenPoint:null};if(e.notify("freehand-draw",{prop:"getStraightenPoint",onPropertyChange:!1,value:{obj:a}}),a.straightenPoint.x&&a.straightenPoint.y){var i=i+n/2-a.straightenPoint.x,n=r+o/2-a.straightenPoint.y,r=(0===e.transform.degree?(e.img.destLeft+=i,e.img.destTop+=n,e.notify("transform",{prop:"drawPannImage",value:{point:{x:i,y:n}}})):(e.panPoint.currentPannedPoint={x:i,y:n},e.notify("transform",{prop:"drawPannedImage",value:{xDiff:i,yDiff:n}}),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:t}}),e.img),s=r.destLeft,l=r.destTop,p=r.destWidth,h=r.destHeight,o=this.imgCanvasPoints,d=(o.forEach(function(e){e.x=e.ratioX*p+s,e.y=e.ratioY*h+l}),this.imgCanvasPoints=o,0);for(3!==e.transform.straighten||this.preventStraightening||(this.preventStraightening=!0,a=e.prevStraightenedDegree,e.prevStraightenedDegree=e.transform.straighten,e.setStraighten(0),e.setStraighten(3),e.prevStraightenedDegree=a,this.preventStraightening=!1);this.isLinesIntersect()&&0!==e.transform.straighten&&360!==e.transform.straighten&&d<100;)d++,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()}},t.prototype.drawZoomPanImage=function(e,t){var o=this.parent,i=(o.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"pan",pen:"pan",x:e,y:t,panRegion:""}}),this.renderImage(!0),{width:0,height:0});o.notify("transform",{prop:"calcMaxDimension",onPropertyChange:!1,value:{width:o.img.srcWidth,height:o.img.srcHeight,obj:i,isImgShape:null}});i.width+=i.width*o.transform.zoomFactor,i.height+=i.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}}})},t.prototype.openNewImage=function(){var t=this,e=this.parent,o=e.element.id,i=e.inMemoryCanvas.getContext("2d"),r=(u.showSpinner(e.element),e.element.style.opacity="0.5",document.querySelector("#"+o+"_currPos")),r=(r&&(r.style.display="none"),{defToolbarItems:null});e.notify("toolbar",{prop:"getDefToolbarItems",value:{obj:r}}),0===r.defToolbarItems.length&&O.isNullOrUndefined(document.getElementById(o+"_toolbar"))&&e.element.querySelector("#"+o+"_toolbarArea")&&(r=e.element.querySelector("#"+o+"_toolbarArea").clientHeight,e.notify("toolbar",{prop:"setToolbarHeight",value:{height:r}})),e.reset(),e.update(),e.transform.degree=0,e.transform.zoomFactor=0,e.isImageLoaded=!1,e.currSelectionPoint=null,"string"==typeof this.openURL?(1<(r=this.openURL.split(".")).length?(r=r[r.length-2].split("/"),this.fileName=r[r.length-1]):this.fileName="ImageEditor",this.fileType=this.getFileExtensionFromURL(this.openURL),this.fileType&&(this.fileType=e.toPascalCase(this.fileType),"jpg"!==(r=this.fileType.toLowerCase())&&"jpeg"!==r||(this.fileType="Jpeg",r="jpeg"),"jpeg"!==r)&&"png"!==r&&"svg"!==r&&(this.fileType=null),this.imageOnLoad(this.openURL),"string"==typeof this.openURL&&-1!==this.openURL.indexOf("localhost")||this.getImageSizeFromURL(this.openURL.toString(),function(e){null!==e&&t.parent.notify("toolbar",{prop:"setInitialSize",value:{value:+e}})})):(this.fileName="ImageEditor",this.fileType=null,e.lowerCanvas=document.querySelector("#"+o+"_lowerCanvas"),e.upperCanvas=document.querySelector("#"+o+"_upperCanvas"),this.lowerContext=e.lowerCanvas.getContext("2d"),this.upperContext=e.upperCanvas.getContext("2d"),e.clearContext(this.lowerContext),e.clearContext(this.upperContext),e.clearContext(i),e.inMemoryCanvas.width=this.openURL.width,e.inMemoryCanvas.height=this.openURL.height,i.putImageData(this.openURL,0,0),e.baseImg.src=e.inMemoryCanvas.toDataURL())},t.prototype.getImageSizeFromURL=function(o,i){return R(this,void 0,void 0,function(){var t;return E(this,function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),[4,fetch(o,{method:"HEAD"})];case 1:return t=e.sent(),t=parseInt(t.headers.get("content-length")||"0",10),i(t),[3,3];case 2:return t=e.sent(),console.log(t.message),[3,3];case 3:return[2]}})})},t.prototype.dlgBtnClick=function(){this.parent.export(),this.applyDialogOption()},t.prototype.dlgCloseBtnClick=function(){this.applyDialogOption()},t.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()),O.getComponent(document.getElementById(e.element.id+"_dialog"),"dialog").destroy(),this.isImageEdited=!1},t.prototype.showDialogPopup=function(){var e=this.parent,t={key:"ConfirmDialogHeader"},o=(e.notify("toolbar",{prop:"getLocaleText",onPropertyChange:!1,value:{obj:t}}),{key:"ConfirmDialogContent"}),i=(e.notify("toolbar",{prop:"getLocaleText",onPropertyChange:!1,value:{obj:o}}),{key:"Yes"}),r=(e.notify("toolbar",{prop:"getLocaleText",onPropertyChange:!1,value:{obj:i}}),{key:"No"});e.notify("toolbar",{prop:"getLocaleText",onPropertyChange:!1,value:{obj:r}}),e.element.querySelector("#"+e.element.id+"_dialog").style.display="block",new u.Dialog({header:t.value,closeOnEscape:!0,content:"<span>"+o.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:r.value,iconCss:"e-icons e-close"}},{click:this.dlgBtnClick.bind(this),buttonModel:{content:i.value,isPrimary:!0,iconCss:"e-icons e-check"}}]}).appendTo("#"+e.element.id+"_dialog")},t.prototype.restoreOldImage=function(){this.parent.isImageLoaded&&this.reset(),this.openNewImage()},t.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())},t.prototype.getInitialLoaded=function(e){e.isInitialLoaded=this.isInitialLoading},t.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},t.prototype.fileSelect=function(e,t){var o,i,r=this.parent,n=document.getElementById(r.element.id+"_dropArea");n&&(n.style.display="none"),r.disabled||(i=n=void 0,t=void(t.target?i=n=t.target.files[0]:n=i=t.filesData[0].rawFile),(t=i.name?(o=i.name.split("."))[o.length-1].toLowerCase():t)&&-1===["jpg","jpeg","png","svg"].indexOf(t)?this.errorLoading():(u.showSpinner(r.element),r.element.style.opacity="0.5",this.inputElem=e,(t=i.name&&i.name.split(".")[1])?(o=r.toPascalCase(t),this.fileType="JPG"===o||"Jpg"===o?"Jpeg":o):this.fileType=null,i=window.URL.createObjectURL(n),this.openURL=i,r.isImageLoaded&&!r.isChangesSaved&&(this.isImageEdited||0<r.pointColl.length||0<r.objColl.length)?(this.isFileChanged=!0,this.showDialogPopup()):this.checkToolbarTemplate(e,i)))},t.prototype.checkToolbarTemplate=function(e,t){var o=this.parent;O.isNullOrUndefined(o.toolbarTemplate)&&(o.reset(),o.update()),this.fileName=e.value.split("\\")[e.value.split("\\").length-1],this.fileName=this.fileName.split(".")[0],this.imageOnLoad(t.toString()),e.value=""},t.prototype.moveToSelectionRange=function(e,t){var o=this.parent;if(o.activeObj.shape){for(var i=!1,r=0,n=o.rotateFlipColl.length;r<n;r++){var a=o.rotateFlipColl[r];if(90===a||-90===a){i=!0;break}}if(i&&0!==o.transform.degree){var s=o.transform.zoomFactor,l=(o.objColl.push(o.activeObj),o.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),o.objColl[o.objColl.length-1]);if("rotateleft"===e||"rotateright"===e)if(o.transform.degree%90==0&&o.transform.degree%180!=0)if(l.activePoint.width<t.activePoint.height)for(r=2;r<o.zoomSettings.maxZoomFactor;r++){if(l.activePoint.width>=t.activePoint.height||this.isSelectionBiggerThanCanvas(l)||this.isSelectionOutsideCanvas(l)){O.isNullOrUndefined(s)||o.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:-.1,zoomPoint:null},isResize:null});break}s+=.1,o.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:s,zoomPoint:null},isResize:null})}else for(r=2;r<o.zoomSettings.maxZoomFactor;r++){if(l.activePoint.width>=t.activePoint.height||this.isSelectionBiggerThanCanvas(l)||this.isSelectionOutsideCanvas(l)){O.isNullOrUndefined(s)||o.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:.1,zoomPoint:null,isResize:null}});break}s-=.1,o.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:s,zoomPoint:null},isResize:null})}else if(l.activePoint.height<t.activePoint.width)for(r=2;r<o.zoomSettings.maxZoomFactor;r++){if(l.activePoint.height>=t.activePoint.width||this.isSelectionBiggerThanCanvas(l)||this.isSelectionOutsideCanvas(l)){O.isNullOrUndefined(s)||o.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:-.1,zoomPoint:null},isResize:null});break}s+=.1,o.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:s,zoomPoint:null},isResize:null})}else for(r=2;r<o.zoomSettings.maxZoomFactor;r++){if(l.activePoint.height>=t.activePoint.width||this.isSelectionBiggerThanCanvas(l)||this.isSelectionOutsideCanvas(l)){O.isNullOrUndefined(s)||o.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:.1,zoomPoint:null},isResize:null});break}s-=.1,o.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:s,zoomPoint:null},isResize:null})}var e=o.lowerCanvas.clientWidth/2-(l.activePoint.startX+l.activePoint.width/2),p=(o.lowerCanvas.clientHeight+1)/2-(l.activePoint.startY+l.activePoint.height/2);O.isNullOrUndefined(o.activeObj.shape)&&(o.activeObj=O.extend({},t,{},!0)),0===o.transform.degree?(o.img.destLeft+=e,o.img.destTop+=p,o.notify("transform",{prop:"drawPannImage",value:{point:{x:e,y:p}}})):(o.panPoint.currentPannedPoint={x:e,y:p},o.notify("transform",{prop:"drawPannedImage",value:{xDiff:e,yDiff:p}}),o.panPoint.currentPannedPoint={x:0,y:0}),o.notify("transform",{prop:"setTempPanMove",onPropertyChange:!1,value:{point:null}}),o.activeObj=O.extend({},o.objColl[o.objColl.length-1]),o.objColl.pop(),o.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate",obj:o.activeObj}})}}},t.prototype.isSelectionBiggerThanCanvas=function(e){var t=!1,o=this.parent,e=e.activePoint,i=e.startX,r=e.startY,n=e.endX,e=e.endY,o=o.img,a=o.destLeft,s=o.destTop,l=o.destWidth,o=o.destHeight;return t=i<=a||r<=s||a+l<=n||s+o<=e?!0:t},t.prototype.isSelectionOutsideCanvas=function(e){var t=!1,o=this.parent;return t=e.activePoint.height<o.lowerCanvas.height-o.toolbarHeight||e.activePoint.width<o.lowerCanvas.width?!0:t},t.prototype.downScaleImgCanvas=function(e,t,o,i){var r=this.parent,n=t?r.activeObj.imageCanvas:r.baseImgCanvas,a=t?r.activeObj.imageElement:r.baseImg,s=t?r.activeObj.activePoint.width:r.img.destWidth,l=t?r.activeObj.activePoint.height:r.img.destHeight,p={width:0,height:0};r.transform.degree%90==0&&r.transform.degree%180!=0?r.notify("transform",{prop:"calcMaxDimension",onPropertyChange:!1,value:{width:a.height,height:a.width,obj:p,isImgShape:t}}):r.notify("transform",{prop:"calcMaxDimension",onPropertyChange:!1,value:{width:a.width,height:a.height,obj:p,isImgShape:t}}),t||r.allowDownScale&&!r.isCropTab&&!r.isCropToolbar&&0!==a.width&&0!==a.height&&s<.75*p.width&&l<.75*p.height?((p=r.createElement("canvas",{id:r.element.id+"_downScaleCanvas",attrs:{name:"canvasImage"}})).width=t?a.width:r.img.srcWidth,p.height=t?a.height:r.img.srcHeight,t?p.getContext("2d").drawImage(a,0,0,p.width,p.height):p.getContext("2d").drawImage(n,r.img.srcLeft,r.img.srcTop,r.img.srcWidth,r.img.srcHeight,0,0,p.width,p.height),(t||this.isDownScale)&&this.downScale(p,s,l,t),t?(e.canvas.width=p.width,e.canvas.height=p.height,o&&i?(e.translate(r.activeObj.imageCanvas.width,0),e.scale(-1,1),e.translate(0,r.activeObj.imageCanvas.height),e.scale(1,-1)):o?(O.isNullOrUndefined(r.activeObj.isHorImageFlip)||!r.activeObj.isHorImageFlip?(r.activeObj.isHorImageFlip=!0,e.translate(r.activeObj.imageCanvas.width,0),e.scale(-1,1)):r.activeObj.isHorImageFlip&&(r.activeObj.isHorImageFlip=!1),r.activeObj.isVerImageFlip&&(e.translate(0,r.activeObj.imageCanvas.height),e.scale(1,-1))):i&&(O.isNullOrUndefined(r.activeObj.isVerImageFlip)||!r.activeObj.isVerImageFlip?(r.activeObj.isVerImageFlip=!0,e.translate(0,r.activeObj.imageCanvas.height),e.scale(1,-1)):r.activeObj.isVerImageFlip&&(r.activeObj.isVerImageFlip=!1),r.activeObj.isHorImageFlip)&&(e.translate(r.activeObj.imageCanvas.width,0),e.scale(-1,1)),e.drawImage(p,0,0),e.setTransform(1,0,0,1,0,0)):r.isFinetuning?(e.save(),e.setTransform(1,0,0,1,0,0),e.drawImage(r.inMemoryCanvas,0,0),e.restore()):e.drawImage(p,0,0,p.width,p.height,r.img.destLeft,r.img.destTop,p.width,p.height)):!O.isNullOrUndefined(t)&&t||0===r.baseImgCanvas.width||0===r.baseImgCanvas.height||e.drawImage(r.baseImgCanvas,r.img.srcLeft,r.img.srcTop,r.img.srcWidth,r.img.srcHeight,r.img.destLeft,r.img.destTop,r.img.destWidth,r.img.destHeight)},t.prototype.downScale=function(e,t,o,i){var r=this.parent;if(!i||!r.isStraightening){for(var n=e.width,a=e.height,s=n/(t=Math.round(t)),l=a/(o=Math.round(o)),p=Math.ceil(s/2),h=Math.ceil(l/2),d=e.getContext("2d"),a=d.getImageData(0,0,n,a),c=d.createImageData(t,o),u=a.data,g=c.data,v=0;v<o;v++)for(var f=0;f<t;f++){for(var C=4*(f+v*t),b=0,m=0,y=0,P=0,j=0,x=0,w=(v+.5)*l,O=Math.floor(v*l),S=Math.ceil((v+1)*l),T=O;T<S;T++)for(var F=Math.abs(w-(T+.5))/h,k=(f+.5)*s,I=F*F,F=Math.floor(f*s),A=Math.ceil((f+1)*s),z=F;z<A;z++){var D,X=Math.abs(k-(z+.5))/p,X=Math.sqrt(I+X*X);1<=X||(x+=(X=2*X*X*X-3*X*X+1)*u[3+(D=4*(z+T*n))],m+=X,y+=(X=X*u[3+D]/250)*u[D],P+=X*u[1+D],j+=X*u[2+D],b+=X)}g[C]=y/b,g[1+C]=P/b,g[2+C]=j/b,g[3+C]=x/m}e.width=(i?r.activeObj.activePoint:r.lowerCanvas).width,e.height=(i?r.activeObj.activePoint:r.lowerCanvas).height,d.putImageData(c,0,0)}},t.prototype.drawImgToCtx=function(e,t){var o=this.parent;e.canvas.id!==o.element.id+"_tempCanvas"&&e!==this.upperContext&&O.isNullOrUndefined(t)&&this.downScaleImgCanvas(e,null,null,null)},t.prototype.getFrameColor=function(e,t,o){this.parent.frameObj.color;return e.gradientColor?((t=t.createLinearGradient(o.startX,o.startY,o.startX+o.width,o.startY+o.height)).addColorStop(0,e.color),t.addColorStop(1,e.gradientColor),t):e.color},t.prototype.applyFrame=function(e,t,o){var i,r,n,a,s=this.parent,l=(s.frameObj.type=t,{width:1,height:1}),p={startX:s.img.destLeft-e.lineWidth,startY:s.img.destTop-e.lineWidth,width:s.img.destWidth+2*e.lineWidth,height:s.img.destHeight+2*e.lineWidth},h={type:s.frameObj.type,color:s.frameObj.color,size:s.frameObj.size,inset:s.frameObj.inset,offset:s.frameObj.offset/2,radius:s.frameObj.radius,amount:s.frameObj.amount,border:s.frameObj.border,gradientColor:s.frameObj.gradientColor},d=s.transform.zoomFactor,c=(e.canvas.id===s.element.id+"_tempCanvas"?(r=e.canvas.width,n=e.canvas.height,s.notify("crop",{prop:"calcRatio",onPropertyChange:!(a={width:0,height:0}),value:{obj:a,dimension:{width:r,height:n}}}),h.size*=((l=a).width+l.height)/2,h.inset*=(l.width+l.height)/2,h.offset*=(l.width+l.height)/2,h.radius*=(l.width+l.height)/2,p={startX:0,startY:0,width:e.canvas.width,height:e.canvas.height},s.notify("export",{prop:"updateSaveContext",onPropertyChange:!1,value:{context:e}})):e===this.upperContext&&s.activeObj.shape?p={startX:s.activeObj.activePoint.startX-e.lineWidth,startY:s.activeObj.activePoint.startY-e.lineWidth,width:s.activeObj.activePoint.width+2*e.lineWidth,height:s.activeObj.activePoint.height+2*e.lineWidth}:O.isNullOrUndefined(o)&&e.clearRect(0,0,e.canvas.width,e.canvas.height),(l.width+l.height)/2*40),u=(l.width+l.height)/2*50;if(e!==this.upperContext&&(h.size+=h.size*d,h.inset+=h.inset*d,h.offset+=h.offset*d,h.radius+=h.radius*d,c+=c*d,u+=u*d),e!==this.upperContext||!s.activeObj.shape||!("mat"===t&&(p.width-2*h.size<0||p.height-2*h.size<0)||"bevel"===t&&(p.width-2*h.size<40||p.height-2*h.size<40)||"inset"===t&&(p.startX+p.width-h.offset-(p.startX+h.offset)<0||p.startY+p.height-h.offset-(p.startY+h.offset)<0)||"hook"===t&&(p.width-2*h.size<50||p.height-2*h.size<50))){var g={bevelFilter:e.filter},v=e.filter;if(s.currSelectionPoint&&"crop-circle"===s.currSelectionPoint.shape||s.isCircleCrop||e===this.lowerContext&&s.isCropTab)this.drawImgToCtx(e,o);else{switch(t){case"none":this.drawImgToCtx(e,o);break;case"mat":for(this.drawImgToCtx(e,o);(p.width-2*h.size<0||p.height-2*h.size<0)&&0<h.size;)h.size-=20;e.filter="none",e.fillStyle=this.getFrameColor(h,e,p),e.beginPath(),e.rect(p.startX,p.startY,p.width,p.height),e.rect(p.startX+h.size,p.startY+h.size,p.width-2*h.size,p.height-2*h.size),e.fill("evenodd"),e.closePath();break;case"bevel":for(e.filter="none",e.fillStyle=this.getFrameColor(h,e,p),e.beginPath(),e.fillRect(p.startX,p.startY,p.width,p.height),e.closePath(),p.startX+=h.size,p.startY+=h.size,p.width-=2*h.size,p.height-=2*h.size;(p.width-2*h.size<40||p.height-2*h.size<40)&&0<h.size;)p.startX-=h.size,p.startY-=h.size,p.width+=2*h.size,p.height+=2*h.size,h.size-=20,p.startX+=h.size,p.startY+=h.size,p.width-=2*h.size,p.height-=2*h.size;e.fillStyle=this.getFrameColor(h,e,p),e.save(),e.beginPath(),e.moveTo(p.startX+c,p.startY),e.lineTo(p.startX+p.width-c,p.startY),e.quadraticCurveTo(p.startX+p.width,p.startY,p.startX+p.width,p.startY+c),e.lineTo(p.startX+p.width,p.startY+p.height-c),e.quadraticCurveTo(p.startX+p.width,p.startY+p.height,p.startX+p.width-c,p.startY+p.height),e.lineTo(p.startX+c,p.startY+p.height),e.quadraticCurveTo(p.startX,p.startY+p.height,p.startX,p.startY+p.height-c),e.lineTo(p.startX,p.startY+c),e.quadraticCurveTo(p.startX,p.startY,p.startX+c,p.startY),e.closePath(),e.clip(),e.filter="none"===v?s.canvasFilter:v,e.canvas.id===s.element.id+"_tempCanvas"?(o=null,e.filter="none",e.drawImage(s.inMemoryCanvas,0,0),e.filter="none"===v?s.canvasFilter:v):(e.clearRect(0,0,e.canvas.width,e.canvas.height),o?(o=null,0!==s.transform.zoomFactor&&(this.isRotateZoom=!0),s.notify("filter",{prop:"getBevelFilter",onPropertyChange:!1,value:{obj:g}}),e.filter=g.bevelFilter,this.updateCurrTransState("initial"),this.drawImgToCtx(e,o),this.updateCurrTransState("reverse"),this.isRotateZoom=!1,s.frameObj.type="none",e.filter="none",s.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:e,shape:"iterate",pen:"iterate",isPreventApply:null}}),s.frameObj.type="bevel",e.filter="none"===v?s.canvasFilter:v):(s.notify("filter",{prop:"getBevelFilter",onPropertyChange:!1,value:{obj:g}}),e.filter=g.bevelFilter,this.drawImgToCtx(e,o))),e.restore();break;case"line":this.drawImgToCtx(e,o),i=e.lineWidth,e.lineWidth=h.size/10;for(var f=0;f<s.frameObj.amount;f++){0<f&&(p.startX+=h.offset,p.startY+=h.offset,p.width-=2*h.offset,p.height-=2*h.offset);var C=p.startY+p.height-h.inset-h.radius,b=p.startY+h.inset+h.radius,m=p.startX+p.width-h.inset-h.radius,y=p.startX+h.inset+h.radius,P=p.startX+h.inset+h.radius,j=p.startX+p.width-h.inset-h.radius,x=p.startY+h.inset+h.radius,w=p.startY+p.height-h.inset-h.radius;b<=C&&y<=m&&P<=j&&x<=w&&(e.filter="none",e.strokeStyle=this.getFrameColor(h,e,p),"dashed"===h.border?e.setLineDash([2.5*e.lineWidth,1.5*e.lineWidth]):"dotted"===h.border&&e.setLineDash([e.lineWidth,e.lineWidth]),e.beginPath(),e.moveTo(p.startX+h.inset+h.radius,p.startY+h.inset),e.lineTo(p.startX+p.width-h.inset-h.radius,p.startY+h.inset),e.arcTo(p.startX+p.width-h.inset,p.startY+h.inset,p.startX+p.width-h.inset,p.startY+h.inset+h.radius,h.radius),e.lineTo(p.startX+p.width-h.inset,p.startY+p.height-h.inset-h.radius),e.arcTo(p.startX+p.width-h.inset,p.startY+p.height-h.inset,p.startX+p.width-h.inset-h.radius,p.startY+p.height-h.inset,h.radius),e.lineTo(p.startX+h.inset+h.radius,p.startY+p.height-h.inset),e.arcTo(p.startX+h.inset,p.startY+p.height-h.inset,p.startX+h.inset,p.startY+p.height-h.inset-h.radius,h.radius),e.lineTo(p.startX+h.inset,p.startY+h.inset+h.radius),e.arcTo(p.startX+h.inset,p.startY+h.inset,p.startX+h.inset+h.radius,p.startY+h.inset,h.radius),e.closePath(),e.stroke(),e.setLineDash([]))}e.lineWidth=i;break;case"inset":this.drawImgToCtx(e,o),e.filter="none",e.strokeStyle=this.getFrameColor(h,e,p),i=e.lineWidth,e.lineWidth=h.size/10,e.beginPath(),e.moveTo(p.startX+h.offset,p.startY+h.inset),e.lineTo(p.startX+p.width-h.offset,p.startY+h.inset),e.moveTo(p.startX+p.width-h.inset,p.startY+h.offset),e.lineTo(p.startX+p.width-h.inset,p.startY+p.height-h.offset),e.moveTo(p.startX+p.width-h.offset,p.startY+p.height-h.inset),e.lineTo(p.startX+h.offset,p.startY+p.height-h.inset),e.moveTo(p.startX+h.inset,p.startY+p.height-h.offset),e.lineTo(p.startX+h.inset,p.startY+h.offset),e.stroke(),e.closePath(),e.lineWidth=i;break;case"hook":this.drawImgToCtx(e,o),e.filter="none",e.strokeStyle=this.getFrameColor(h,e,p),i=e.lineWidth,e.lineWidth=h.size/10,e.beginPath(),e.moveTo(p.startX+h.inset+u,p.startY+h.inset),e.lineTo(p.startX+h.inset,p.startY+h.inset),e.lineTo(p.startX+h.inset,p.startY+h.inset+u),e.moveTo(p.startX+p.width-h.inset-u,p.startY+h.inset),e.lineTo(p.startX+p.width-h.inset,p.startY+h.inset),e.lineTo(p.startX+p.width-h.inset,p.startY+h.inset+u),e.moveTo(p.startX+p.width-h.inset-u,p.startY+p.height-h.inset),e.lineTo(p.startX+p.width-h.inset,p.startY+p.height-h.inset),e.lineTo(p.startX+p.width-h.inset,p.startY+p.height-h.inset-u),e.moveTo(p.startX+h.inset+u,p.startY+p.height-h.inset),e.lineTo(p.startX+h.inset,p.startY+p.height-h.inset),e.lineTo(p.startX+h.inset,p.startY+p.height-h.inset-u),e.stroke(),e.lineWidth=i}(s.isCircleCrop||s.currSelectionPoint&&"crop-circle"===s.currSelectionPoint.shape)&&s.notify("crop",{prop:"cropCircle",onPropertyChange:!1,value:{context:e,isSave:e.canvas.id===s.element.id+"_tempCanvas"||null,isFlip:null}}),e.filter=v}}},t.prototype.triggerFrameChange=function(e){var t=this.parent,e={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",e),e.cancel||this.setFrameObj(e.currentFrameSetting),e},t.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},t.prototype.zoomToSel=function(e,t){var o=this.parent;if(this.straightenActObj&&JSON.stringify(this.straightenActObj.activePoint)===JSON.stringify(e.activePoint))if(o.activeObj=O.extend({},this.straightenActObj,null,!0),0===o.transform.straighten){var i=o.img.destWidth,r=o.img.destHeight;for(o.transform.straighten=360;;){if(O.isNullOrUndefined(this.straightenInitZoom)||!(Math.round(o.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"),i===o.img.destWidth&&r===o.img.destHeight){this.performDummyZoom();break}0===o.transform.degree&&(o.transform.zoomFactor-=.025,o.transform.cropZoomFactor-=.025)}o.transform.straighten=0,o.img={destLeft:o.img.destLeft,destTop:o.img.destTop,destWidth:o.img.destWidth,destHeight:o.img.destHeight,srcLeft:o.img.srcLeft,srcTop:o.img.srcTop,srcWidth:o.img.srcWidth,srcHeight:o.img.srcHeight}}else O.isNullOrUndefined(this.straightenInitZoom)&&(this.straightenInitZoom=o.transform.zoomFactor),0<this.straightenInitZoom-o.transform.zoomFactor?o.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:-(this.straightenInitZoom-o.transform.zoomFactor),zoomPoint:null,isResize:!0}}):this.straightenInitZoom-o.transform.zoomFactor<0&&o.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:this.straightenInitZoom-o.transform.zoomFactor,zoomPoint:null,isResize:!0}}),o.activeObj=O.extend({},e,null,!0),o.transform.zoomFactor+=.001,this.calcStraightenedPoints(t);else this.straightenActObj=O.extend({},e,null,!0),o.activeObj=O.extend({},this.straightenActObj,null,!0),this.straightenInitZoom=o.transform.zoomFactor,this.calcStraightenedPoints(t)},t.prototype.isDestPointSmall=function(){var e=this.parent,t=e.img,o={startX:t.destLeft,startY:t.destTop,width:t.destWidth,height:t.destHeight},i=(e.notify("shape",{prop:"straightenShapes",onPropertyChange:!1}),!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},t.prototype.calcStraightenedPoints=function(n){for(var a=this.parent,s=a.img.destWidth,l=a.img.destHeight,p=(O.isNullOrUndefined(a.transform.zoomFactor)&&(a.transform.zoomFactor+=.025),this.updateImgCanvasPoints(),this);"break"!==function(){if(!(p.isLinesIntersect()||p.isSelOutsideImg()||n&&p.isDestPointSmall()))return p.performDummyZoom(),"break";if(a.activeObj=O.extend({},p.straightenActObj,null,!0),p.setZoomPan("in"),s===a.img.destWidth&&l===a.img.destHeight)return p.performDummyZoom(),"break";0===a.transform.degree&&(a.transform.zoomFactor+=.025,a.transform.cropZoomFactor+=.025);var e=p.imgCanvasPoints,t=a.img.destLeft,o=a.img.destTop,i=a.img.destWidth,r=a.img.destHeight;e.forEach(function(e){e.x=e.ratioX*i+t,e.y=e.ratioY*r+o}),p.imgCanvasPoints=e}(););},t.prototype.performDummyZoom=function(){var e=this.parent,t=(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}}),10*e.transform.zoomFactor);e.setProperties({zoomSettings:{zoomFactor:t=t<1?1+t/10:t}},!0),e.notify("transform",{prop:"setPreviousZoomValue",onPropertyChange:!1,value:{previousZoomValue:t}}),this.panToSel()},t.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"))},t.prototype.updateImgCanvasPoints=function(){var e,t,o,i=this.parent,r=this.getImagePoints(),n={width:0,height:0},a=i.baseImgCanvas.width,s=i.baseImgCanvas.height,a=(i.notify("crop",{prop:"calcRatio",onPropertyChange:!1,value:{obj:n,dimension:{width:a,height:s}}}),i.transform.degree%90==0&&i.transform.degree%180!=0?n.height:n.width),s=i.transform.degree%90==0&&i.transform.degree%180!=0?n.width:n.height,n=i.img,l=n.destLeft,p=n.destTop,h=n.destWidth,n=n.destHeight,i=0<i.transform.straighten?(e={x:l+r[0].x/a,y:p},t={x:l+h,y:p+r[1].y/s},o={x:l+h-r[0].x/a,y:p+n},{x:l,y:p+n-r[1].y/s}):(e={x:l,y:p+r[0].y/s},t={x:l+r[1].x/a,y:p},o={x:l+h,y:p+n-r[0].y/s},{x:l+h-r[1].x/a,y:p+n});e.ratioX=(e.x-l)/h,e.ratioY=(e.y-p)/n,t.ratioX=(t.x-l)/h,t.ratioY=(t.y-p)/n,o.ratioX=(o.x-l)/h,o.ratioY=(o.y-p)/n,i.ratioX=(i.x-l)/h,i.ratioY=(i.y-p)/n,this.imgCanvasPoints=[e,t,o,i]},t.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]),n=this.doIntersect({x:t.startX,y:t.endY},{x:t.endX,y:t.endY},o[2],o[3]),a=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,n,a]),i||r||n||a||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},t.prototype.isSelOutsideImg=function(){var e=this.parent,t=this.imgCanvasPoints,e=e.activeObj.activePoint;return"inside"!==this.checkPointPosition(e.startX,e.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(e.endX,e.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(e.startX,e.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(e.endX,e.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)},t.prototype.calcTriangleArea=function(e,t,o,i,r,n){return Math.abs((e*(i-n)+o*(n-t)+r*(t-i))/2)},t.prototype.checkPointPosition=function(e,t,o,i,r,n,a,s,l,p){var h=this.calcTriangleArea(e,t,o,i,l,p),d=this.calcTriangleArea(e,t,l,p,a,s),c=this.calcTriangleArea(e,t,a,s,r,n),e=this.calcTriangleArea(e,t,r,n,o,i),t=this.calcTriangleArea(o,i,r,n,a,s)+this.calcTriangleArea(a,s,l,p,o,i);return t<h+d+c+e?"outside":h+d+c+e!==t||0!==h&&0!==d&&0!==c&&0!==e?"inside":"on"},t.prototype.getImagePoints=function(){var e=[],t=this.parent,o=t.transform.degree,i=t.baseImg.width,r=t.baseImg.height,n={dim:null,width:r,height:i,angle:t.transform.straighten};n.dim=t.getRotatedCanvasDim(n.width,n.height,n.angle);var a=o%90==0&&o%180!=0?r:i,i=o%90==0&&o%180!=0?i:r,r=(o%90==0&&o%180!=0?n.dim:t.baseImgCanvas).width/2,o=(o%90==0&&o%180!=0?n.dim:t.baseImgCanvas).height/2,n=r-a/2,s=o-i/2,a=r+a/2,i=o+i/2,t=t.transform.straighten*(Math.PI/180),l={x:Math.cos(t)*(n-r)-Math.sin(t)*(s-o)+r,y:Math.sin(t)*(n-r)+Math.cos(t)*(s-o)+o},s={x:Math.cos(t)*(a-r)-Math.sin(t)*(s-o)+r,y:Math.sin(t)*(a-r)+Math.cos(t)*(s-o)+o},a={x:Math.cos(t)*(a-r)-Math.sin(t)*(i-o)+r,y:Math.sin(t)*(a-r)+Math.cos(t)*(i-o)+o},n={x:Math.cos(t)*(n-r)-Math.sin(t)*(i-o)+r,y:Math.sin(t)*(n-r)+Math.cos(t)*(i-o)+o};return e.push(l),e.push(s),e.push(a),e.push(n),e},t.prototype.doIntersect=function(e,t,o,i){var r=this.initiation(e,t,o),n=this.initiation(e,t,i),a=this.initiation(o,i,e),s=this.initiation(o,i,t);return r!==n&&a!==s||!!(0===r&&this.onSegment(e,o,t)||0===n&&this.onSegment(e,i,t)||0===a&&this.onSegment(o,e,i)||0===s&&this.onSegment(o,t,i))},t.prototype.initiation=function(e,t,o){e=(t.y-e.y)*(o.x-t.x)-(t.x-e.x)*(o.y-t.y);return 0==e?0:0<e?1:2},t.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)},t.prototype.isInsideRect=function(e){var t=this.parent.activeObj.activePoint,o=!1;return o=e.x>=t.startX&&e.x<=t.endX&&e.y>=t.startY&&e.y<=t.endY?!0:o},t.prototype.setDestForStraighten=function(){var e,t,o,i,r=this.parent;O.isNullOrUndefined(this.straightenDestPoints)&&(e=(i=r.img).destLeft,t=i.destTop,o=i.destWidth,i=i.destHeight,r.notify("shape",{prop:"straightenShapes",onPropertyChange:!1}),this.straightenDestPoints=O.extend({},r.img,{},!0),r.img.destLeft=e,r.img.destTop=t,r.img.destWidth=o,r.img.destHeight=i)},t);function t(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()}n.prototype.destroy=function(){this.parent.isDestroyed||this.removeEventListener()},n.prototype.addEventListener=function(){this.parent.on("export",this.export,this),this.parent.on("destroyed",this.destroy,this)},n.prototype.removeEventListener=function(){this.parent.off("export",this.export),this.parent.off("destroyed",this.destroy)},n.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);break;case"exportToCanvas":this.exportToCanvas(e.value.object);break;case"updateSaveContext":this.updateSaveContext(e.value.context);break;case"setImageQuality":this.imageQuality=e.value.value}},n.prototype.getModuleName=function(){return"export"},n.prototype.updatePvtVar=function(){var e=this.parent;e.lowerCanvas&&(this.lowerContext=e.lowerCanvas.getContext("2d"))},n.prototype.exportImg=function(e,t){var o,i=this.parent,r={fileName:""},r=(i.notify("draw",{prop:"getFileName",onPropertyChange:!1,value:{obj:r}}),r.fileName);!i.disabled&&i.isImageLoaded&&(i.notify("selection",{prop:"getFreehandDrawEditing",onPropertyChange:!(o={bool:!1}),value:{obj:o}}),o.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}}),o={canvasFilter:this.parent.canvasFilter},this.lowerContext.filter=o.canvasFilter,e=e||"Png",i.notify("shape",{prop:"redrawActObj",onPropertyChange:!1,value:{x:null,y:null,isMouseDown:null}}),i.trigger("beforeSave",o={cancel:!1,fileName:t||r,fileType:e}),this.beforeSaveEvent(o,e,t,r))},n.prototype.beforeSaveEvent=function(e,t,o,i){var r=this.parent;e.cancel||(r.currObjType.isSave=!0,o=(o=e.fileName||o)||i,"svg"===(e=t.toLowerCase())?this.toSVGImg(o):this.toBlobFn(o,e),r.trigger("saved",{fileName:o||i,fileType:t}),r.notify("toolbar",{prop:"refresh-main-toolbar",onPropertyChange:!1}),r.lowerCanvas.style.left=r.upperCanvas.style.left="",r.lowerCanvas.style.top=r.upperCanvas.style.top="",r.lowerCanvas.style.maxWidth=r.upperCanvas.style.maxWidth="",r.lowerCanvas.style.maxHeight=r.upperCanvas.style.maxHeight="")},n.prototype.toSVGImg=function(e){var t=this.parent,o=(u.showSpinner(t.element),t.element.style.opacity="0.5",this.exportToCanvas()),i=o.toDataURL(),t=(u.hideSpinner(t.element),t.element.style.opacity="1",document.createElementNS("http://www.w3.org/2000/svg","svg")),r=(t.setAttribute("width",o.style.maxWidth),t.setAttribute("height",o.style.maxHeight),document.createElementNS("http://www.w3.org/2000/svg","image")),i=(r.setAttributeNS(null,"height",o.height.toString()),r.setAttributeNS(null,"width",o.width.toString()),r.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",i),t.appendChild(r),'<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="'+o.width+'" height="'+o.height+'">'),r=t.innerHTML,o="data:image/svg+xml;base64,"+btoa(i+r+"</svg>");return null===e?o:(this.downloadImg(o,e+".svg"),null)},n.prototype.toBlobFn=function(t,o){var i=this,r=this.parent;u.showSpinner(r.element),r.element.style.opacity="0.5",this.exportToCanvas().toBlob(function(e){e=URL.createObjectURL(e);i.downloadImg(e,t+"."+o),u.hideSpinner(r.element),r.element.style.opacity="1"},"jpeg"!==o?"image/png":"image/jpeg",this.imageQuality||null)},n.prototype.exportToCanvas=function(e){var t,o,i=this.parent,r=O.extend({},i.cropObj,{},!0),n={currObj:{}},n=(i.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:n}}),n.currObj),a=(n.objColl=O.extend([],i.objColl,[],!0),n.pointColl=O.extend([],i.pointColl,[],!0),n.afterCropActions=O.extend([],i.afterCropActions,[],!0),{selPointColl:null}),s=(i.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:a}}),this.parent.aspectWidth?(i.notify("undo-redo",{prop:"setPreventUR",value:{bool:!0}}),i.notify("toolbar",{prop:"resizeClick",value:{bool:!1}}),i.okBtn(),o=i.transform.degree%90==0&&i.transform.degree%180!=0?(t=this.parent.aspectHeight,this.parent.aspectWidth):(t=this.parent.aspectWidth,this.parent.aspectHeight),i.notify("undo-redo",{prop:"setPreventUR",value:{bool:!1}})):o=i.currSelectionPoint?(t=i.img.srcWidth,i.img.srcHeight):(t=i.baseImgCanvas.width,i.baseImgCanvas.height),{width:0,height:0}),l=(i.notify("crop",{prop:"calcRatio",onPropertyChange:!1,value:{obj:s,dimension:{width:t,height:o}}}),this.lowerContext.filter),p=("none"!==this.lowerContext.filter&&(h=this.lowerContext.filter.split(" "),p=parseFloat(h[5].split("(")[1]),h[5]="blur("+(p*=(s.width+s.height)/2)+"px)",this.lowerContext.filter=h.join(" ")),i.createElement("canvas",{id:i.element.id+"_tempCanvas",attrs:{name:"canvasImage"}})),h=p.getContext("2d"),d=(p.width=t,p.height=o,{width:0,height:0}),d=(i.notify("transform",{prop:"calcMaxDimension",onPropertyChange:!1,value:{width:t,height:o,obj:d}}),p.style.maxWidth=d.width+"px",p.style.maxHeight=d.height+"px",this.lowerContext.filter);return h.filter=this.lowerContext.filter,this.downScaleImgCanvas(h,t,o),this.lowerContext.filter=d,0===i.transform.degree&&""===i.transform.currFlipState&&0===i.transform.straighten||(this.updateSaveContext(h),this.exportTransformedImage(h)),this.drawAnnotation(h,s),i.isCircleCrop&&i.notify("crop",{prop:"cropCircle",onPropertyChange:!1,value:{context:h,isSave:!0,isFlip:null}}),this.updateFrame(h,!0),this.lowerContext.filter=l,i.canvasFilter=l,e&&(e.canvas=p),i.aspectWidth&&(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:n}}),n.selPointColl=O.extend([],a.selPointColl,[],!0),i.notify("freehand-draw",{prop:"setSelPointColl",onPropertyChange:!1,value:{obj:{selPointColl:n.selPointColl}}}),i.cropObj=r,i.objColl=O.extend([],n.objColl,[],!0),i.pointColl=O.extend([],n.pointColl,[],!0),i.freehandCounter=i.pointColl.length,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=n.filter,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}}),p},n.prototype.drawAnnotation=function(e,t){for(var o=this.parent,i=O.extend([],o.objColl,[],!0),r=O.extend([],o.pointColl,[],!0),n=0;n<o.shapeColl.length;n++)o.shapeColl[n].order&&(o.shapeColl[n].currIndex&&-1<o.shapeColl[n].currIndex.indexOf("shape")?(o.objColl=[],o.objColl.push(O.extend({},o.shapeColl[n],{},!0)),this.drawShape(e,t)):o.shapeColl[n].id&&-1<o.shapeColl[n].id.indexOf("pen")&&(o.pointColl=[],o.freehandCounter=0,o.pointColl.push(O.extend({},o.shapeColl[n],{},!0)),o.freehandCounter=o.pointColl.length,this.drawPen(e,t)));o.objColl=i,o.pointColl=r,o.freehandCounter=o.pointColl.length},n.prototype.drawShape=function(e,t){var o=this.parent;if(0<o.objColl.length){for(var i=e.filter,r=(e.filter="none",{index:null}),n=(o.notify("shape",{prop:"getSmallestIndex",onPropertyChange:!1,value:{obj:r}}),r.index),a=O.extend([],o.objColl,[],!0),r=O.extend([],o.objColl,[],!0);0<a.length;){for(var s=!1,l=0;l<a.length;l++){var p=a[l];if(O.isNullOrUndefined(p.order))a.splice(l,1),l--;else if(p.order===n){var p=e.filter,h=(e.filter="none",a[l]),d=h.activePoint;if(d.startX-=o.img.destLeft,d.startY-=o.img.destTop,d.endX-=o.img.destLeft,d.endY-=o.img.destTop,d.width=d.endX-d.startX,d.height=d.endY-d.startY,d.startX*=t.width,d.startY*=t.height,d.endX*=t.width,d.endY*=t.height,d.width=d.endX-d.startX,d.height=d.endY-d.startY,h.strokeSettings.strokeWidth*=(t.width+t.height)/2,"text"===h.shape)h.textSettings.fontSize*=(t.width+t.height)/2;else if("path"===h.shape)for(var c=0;c<h.pointColl.length;c++)h.pointColl[c].x=(h.pointColl[c].x-o.img.destLeft)*t.width,h.pointColl[c].y=(h.pointColl[c].y-o.img.destTop)*t.height;else"image"===h.shape&&(o.activeObj=O.extend({},a[l],{},!0),o.notify("selection",{prop:"upgradeImageQuality",onPropertyChange:!1}),a[l]=O.extend({},o.activeObj,{},!0));o.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"saveContext",obj:a[l],isCropRatio:null,points:null,isPreventDrag:!0,saveContext:e,isPreventSelection:null}}),e.filter=p,o.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),n++;d={bool:!1};o.notify("shape",{prop:"isIndexInObjColl",onPropertyChange:!1,value:{obj:d,index:n}}),d.bool||n++,a.splice(l,1),s=!0;break}}if(!s)break}e.filter=i,o.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),o.objColl=r}},n.prototype.drawPen=function(e,t){var o=this.parent;if(0<o.freehandCounter){for(var i={penStrokeWidth:null},r=(o.notify("freehand-draw",{prop:"getPenStrokeWidth",onPropertyChange:!1,value:{obj:i}}),O.extend({},o.pointColl,{},!0)),n=0;n<o.freehandCounter;n++){o.points=O.extend([],o.pointColl[n].points,[]),o.notify("freehand-draw",{prop:"setPointCounter",onPropertyChange:!1,value:{value:0}});var a=o.points.length;o.pointColl[n].strokeWidth*=(t.width+t.height)/2;for(var s=0;s<a;s++)o.points[s].x=(o.points[s].x-o.img.destLeft)*t.width,o.points[s].y=(o.points[s].y-o.img.destTop)*t.height}o.notify("freehand-draw",{prop:"freehandRedraw",onPropertyChange:!1,value:{context:e,points:null}}),o.pointColl=r,o.notify("freehand-draw",{prop:"setPenStrokeWidth",onPropertyChange:!1,value:{value:i.penStrokeWidth}})}},n.prototype.downScaleImgCanvas=function(e,t,o){var i=this.parent,r=i.baseImgCanvas,n=i.baseImg,a={width:0,height:0};i.notify("transform",{prop:"calcMaxDimension",onPropertyChange:!1,value:{width:n.width,height:n.height,obj:a,isImgShape:null}}),t<a.width&&o<a.height?((n=i.createElement("canvas",{id:i.element.id+"_downScaleCanvas",attrs:{name:"canvasImage"}})).width=this.parent.img.srcWidth,n.height=this.parent.img.srcHeight,n.getContext("2d").drawImage(r,i.img.srcLeft,i.img.srcTop,i.img.srcWidth,i.img.srcHeight,0,0,n.width,n.height),i.notify("draw",{prop:"downScale",value:{canvas:n,width:t,height:o}}),e.drawImage(n,0,0)):e.drawImage(i.baseImgCanvas,i.img.srcLeft,i.img.srcTop,i.img.srcWidth,i.img.srcHeight,0,0,t,o)},n.prototype.updateFrame=function(e,t){var o;"none"!==this.parent.frameObj.type&&(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)},n.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)},n.prototype.exportTransformedImage=function(e){var t=this.parent,o=t.transform.degree;if(0<t.rotateFlipColl.length)for(var i=0,r=t.rotateFlipColl.length;i<r;i++){var n=t.rotateFlipColl[i];"number"==typeof n?this.exportRotate(e,n):"horizontal"===n?this.exportFlip(e,!0,!1):"vertical"===n&&this.exportFlip(e,!1,!0)}t.transform.degree=o},n.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)},n.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)},n.prototype.updateSaveContext=function(e){var t=this.parent.inMemoryCanvas.getContext("2d"),e=(e.setTransform(1,0,0,1,0,0),e.getImageData(0,0,e.canvas.width,e.canvas.height));this.parent.inMemoryCanvas.width=e.width,this.parent.inMemoryCanvas.height=e.height,t.putImageData(e,0,0)},n.prototype.setMaxDim=function(e,t){e%90==0&&e%180!=0?o=O.isNullOrUndefined(this.parent.currSelectionPoint)?(i=this.parent.baseImgCanvas.height,this.parent.baseImgCanvas.width):(i=this.parent.img.srcHeight,this.parent.img.srcWidth):e%180!=0&&0!==e||(o=O.isNullOrUndefined(this.parent.currSelectionPoint)?(i=this.parent.baseImgCanvas.width,this.parent.baseImgCanvas.height):(i=this.parent.img.srcWidth,this.parent.img.srcHeight)),O.isNullOrUndefined(this.parent.aspectWidth)||(i=this.parent.aspectWidth,o=this.parent.aspectHeight),t.width=i,t.height=o;var o,e={width:0,height:0},i=(this.parent.notify("transform",{prop:"calcMaxDimension",onPropertyChange:!1,value:{width:i,height:o,obj:e,isImgShape:null}}),e);t.style.maxWidth=i.width+"px",t.style.maxHeight=i.height+"px"};var r=n;function n(e){this.parent=e,this.addEventListener()}s.prototype.destroy=function(){this.parent.isDestroyed||this.removeEventListener()},s.prototype.addEventListener=function(){this.parent.on("filter",this.filter,this),this.parent.on("destroyed",this.destroy,this)},s.prototype.removeEventListener=function(){this.parent.off("filter",this.filter),this.parent.off("destroyed",this.destroy)},s.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":O.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=O.extend({},this.adjustmentLevel,{},!0);break;case"setTempFilVal":this.tempFilVal=this.parent.currentFilter;break;case"reset":this.reset()}},s.prototype.updatePrivateVariables=function(){var e=this.parent;e.lowerCanvas&&(this.lowerContext=e.lowerCanvas.getContext("2d"))},s.prototype.getModuleName=function(){return"filter"},s.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}},s.prototype.updateFinetunes=function(){var t=this,e=this.parent,o=e.finetuneSettings;o&&(["brightness","contrast","hue","saturation","exposure","opacity","blur"].forEach(function(e){o[e]&&(t.adjustmentLevel[e]=o[e].defaultValue,t.tempAdjustmentLevel[e]=o[e].defaultValue)}),e.notify("draw",{prop:"isInitialLoading",onPropertyChange:!1,value:{isInitialLoading:!0}}))},s.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)},s.prototype.updateAdj=function(e,t,o,i){var r,n,a=this.parent,s=(this.lowerContext.clearRect(0,0,a.lowerCanvas.width,a.lowerCanvas.height),this.lowerContext.filter.split(" ")),l=[],p=this.getFilterValue(this.adjustmentLevel.brightness);switch(-1===["brightness","contrast","hue","saturation","exposure","opacity","blur"].indexOf(e)&&O.isNullOrUndefined(o)&&(this.adjustmentLevel.sharpen||this.adjustmentLevel.bw)&&(a.isUndoRedo=!0,n=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=n,a.isUndoRedo=!1),e){case"brightness":t=this.getFilterValue(this.adjustmentLevel.exposure)+.005*t,s[0]="brightness("+t+")",t=0!==this.adjustmentLevel.brightness?this.adjustmentLevel.opacity/100-.3*this.adjustmentLevel.opacity/100:this.adjustmentLevel.opacity/100,s[4]="opacity("+t+")",this.adjustmentValue=s.join(" ");break;case"contrast":s[1]="contrast("+t+"%)",this.adjustmentValue=s.join(" ");break;case"hue":s[2]="hue-rotate("+t+"deg)",this.adjustmentValue=s.join(" ");break;case"saturation":s[3]="saturate("+t+"%)",this.adjustmentValue=s.join(" ");break;case"opacity":1!==parseFloat(s[0].split("(")[1])&&(t-=.2),s[4]="opacity("+(t=t<0?0:t)+")",this.adjustmentValue=s.join(" ");break;case"blur":s[5]="blur("+t+"px)",this.adjustmentValue=s.join(" ");break;case"exposure":1<t?(--t,t+=p):t<1&&(t=p-(t=1-t)),s[0]="brightness("+t+")",this.adjustmentValue=s.join(" ");break;case"chrome":r=this.getSaturationFilterValue(this.adjustmentLevel.saturation),s[3]="saturate("+(t=(r*=100)+.4*r)+"%)",l=this.adjustmentValue.split(" "),s[0]=l[0],s[1]=l[1],s[2]=l[2],s[4]=l[4],s[5]=l[5],s[6]="sepia(0%)",s[7]="grayscale(0%)",s[8]="invert(0%)";break;case"cold":r=this.getFilterValue(this.adjustmentLevel.brightness),t=.9*(r*=100),s[0]="brightness("+(t*=.01)+")",r=this.getFilterValue(this.adjustmentLevel.contrast),s[1]="contrast("+(t=(r*=100)+.5*r)+"%)",r=this.getSaturationFilterValue(this.adjustmentLevel.saturation),s[3]="saturate("+(t=r*=100)+"%)",l=this.adjustmentValue.split(" "),s[2]=l[2],s[4]=l[4],s[5]=l[5],s[6]="sepia(0%)",s[7]="grayscale(0%)",s[8]="invert(0%)";break;case"warm":r=this.getSaturationFilterValue(this.adjustmentLevel.saturation),s[3]="saturate("+(t=(r*=100)+.4*r)+"%)",s[6]="sepia(25%)",l=this.adjustmentValue.split(" "),s[0]=l[0],s[1]=l[1],s[2]=l[2],s[4]=l[4],s[5]=l[5],s[7]="grayscale(0%)",s[8]="invert(0%)";break;case"grayscale":s[7]="grayscale(100%)",l=this.adjustmentValue.split(" "),s[0]=l[0],s[1]=l[1],s[2]=l[2],s[3]=l[3],s[4]=l[4],s[5]=l[5],s[6]="sepia(0%)",s[8]="invert(0%)";break;case"sepia":s[6]="sepia(100%)",l=this.adjustmentValue.split(" "),s[0]=l[0],s[1]=l[1],s[2]=l[2],s[3]=l[3],s[4]=l[4],s[5]=l[5],s[7]="grayscale(0%)",s[8]="invert(0%)";break;case"invert":s[8]="invert(100%)",l=this.adjustmentValue.split(" "),s[0]=l[0],s[1]=l[1],s[2]=l[2],s[3]=l[3],s[4]=l[4],s[5]=l[5],s[6]="sepia(0%)",s[7]="grayscale(0%)"}"sharpen"!==e&&"blackandwhite"!==e&&(O.isNullOrUndefined(o)&&("default"===e&&(s=this.getDefaultCurrentFilter(s)),this.lowerContext.filter=s.join(" ")),s=this.setTempFilterValue(p,o,s,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}}),n=void 0,"bevel"===a.frameObj.type&&(n=this.lowerContext.filter,this.bevelFilter=n),0===a.transform.degree&&0<a.rotateFlipColl.length&&(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&&0<a.rotateFlipColl.length&&(a.img.destLeft+=a.panPoint.totalPannedPoint.x,a.img.destTop+=a.panPoint.totalPannedPoint.y),s=this.setTempFilterValue(p,o,s,e),O.isNullOrUndefined(o)&&(this.lowerContext.filter=s.join(" ")),a.initialAdjustmentValue=s.join(" "),n=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=n,a.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"iterate",pen:"iterate",isPreventApply:null}}),this.lowerContext.filter=n,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!==p);e=s.join(" ");i&&(i.filter=e)},s.prototype.setTempFilterValue=function(e,t,o,i){return t&&("default"===i?o=this.getDefaultCurrentFilter(o):1!==e&&((t=this.lowerContext.filter.split(" "))[4]=o[4],this.lowerContext.filter=t.join(" "))),o},s.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%)"]},s.prototype.getFilterValue=function(e){return 0===e?1:1+.5*e/100},s.prototype.getSaturationFilterValue=function(e){return 0===e?1:1+e/100},s.prototype.setFilterAdj=function(e,t){var o=this.parent;switch(o.notify("freehand-draw",{prop:"apply-pen-draw",onPropertyChange:!1}),this.adjustmentLevel[""+e]=t,e){case"contrast":case"exposure":t=this.getFilterValue(t),"contrast"===e&&(t*=100);break;case"hue":t*=3;break;case"saturation":t=100*this.getSaturationFilterValue(t);break;case"opacity":t<10&&(t+=1),t/=100;break;case"blur":0!==t&&(t=t/20+.5)}var i=O.extend({},o.cropObj,{},!0),r=this.getCurrentObj(),n=(r.objColl=O.extend([],o.objColl,[],!0),r.pointColl=O.extend([],o.pointColl,[],!0),r.afterCropActions=O.extend([],o.afterCropActions,[],!0),{selPointColl:null});o.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:n}}),r.selPointColl=O.extend([],n.selPointColl,[],!0),this.updateAdj(e,t),o.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:e,previousObj:r,previousObjColl:r.objColl,previousPointColl:r.pointColl,previousSelPointColl:r.selPointColl,previousCropObj:i,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}})},s.prototype.setFilter=function(e){var t=this.parent;e=e.toLowerCase(),t.notify("freehand-draw",{prop:"apply-pen-draw",onPropertyChange:!1});var o={currentFilter:this.parent.currentFilter}.currentFilter,i=O.extend({},t.cropObj,{},!0),r=this.getCurrentObj(),n=(r.objColl=O.extend([],t.objColl,[],!0),r.pointColl=O.extend([],t.pointColl,[],!0),r.afterCropActions=O.extend([],t.afterCropActions,[],!0),{selPointColl:null});t.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:n}}),r.selPointColl=O.extend([],n.selPointColl,[],!0),this.updateAdj(e,null),t.notify("draw",{prop:"setImageEdited",onPropertyChange:!1}),t.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:e,previousObj:r,previousObjColl:r.objColl,previousPointColl:r.pointColl,previousSelPointColl:r.selPointColl,previousCropObj:i,previousText:null,currentText:null,previousFilter:o,isCircleCrop:null}})},s.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]),this.adjustmentLevel.contrast=this.setFilterValue(t/=100);break;case"hue":o=i[2].split("("),t=parseFloat(o[1].split(")")[0]),this.adjustmentLevel.hue=t/=3;break;case"saturation":o=i[3].split("("),t=parseFloat(o[1].split(")")[0]),this.adjustmentLevel.saturation=this.setSaturationFilterValue(t/=100);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]),this.adjustmentLevel.blur=t*=20;break;case"exposure":o=i[0].split("("),t=parseFloat(o[1].split(")")[0]),this.adjustmentLevel.exposure=this.setFilterValue(t)}},s.prototype.setFilterValue=function(e){return Math.round(1===e?0:100*(e-1)/.5)},s.prototype.setSaturationFilterValue=function(e){return Math.round(1===e?0:100*(e-1))},s.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"}})}},s.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}},s.prototype.getCurrentObj=function(e){var t=this.parent,o={point:null},i=(t.notify("crop",{prop:"getTempFlipPanPoint",value:{obj:o}}),{previousZoomValue:null}),r=(t.notify("transform",{prop:"getPreviousZoomValue",value:{obj:i}}),{zoomFactor:null}),n=(t.notify("draw",{prop:"getStraightenInitZoom",value:{obj:r}}),{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:O.extend({},this.tempAdjVal,{},!0),currentFilter:this.tempFilVal});return n.cropZoom=t.transform.cropZoomFactor,n.defaultZoom=t.transform.defaultZoomFactor,n.zoomFactor=t.zoomSettings.zoomFactor,n.previousZoomValue=i.previousZoomValue,n.straightenZoom=r.zoomFactor,n.totalPannedPoint=O.extend({},t.panPoint.totalPannedPoint,{},!0),n.totalPannedClientPoint=O.extend({},t.panPoint.totalPannedClientPoint,{},!0),n.totalPannedInternalPoint=O.extend({},t.panPoint.totalPannedInternalPoint,{},!0),n.tempFlipPanPoint=O.extend({},o.point,{},!0),n.activeObj=O.extend({},t.activeObj,{},!0),n.rotateFlipColl=O.extend([],t.rotateFlipColl,[],!0),n.degree=t.transform.degree,n.straighten=t.cropObj.straighten,n.currFlipState=t.transform.currFlipState,n.destPoints={startX:t.img.destLeft,startY:t.img.destTop,endX:0,endY:0,width:t.img.destWidth,height:t.img.destHeight},n.srcPoints={startX:t.img.srcLeft,startY:t.img.srcTop,endX:0,endY:0,width:t.img.srcWidth,height:t.img.srcHeight},n.filter=this.lowerContext.filter,n.aspectWidth=t.aspectWidth,n.aspectHeight=t.aspectHeight,n.frame=t.frameObj.type,n.frameObj=O.extend({},t.frameObj),e&&(e.currObj=n),n};var a=s;function s(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()}p.prototype.destroy=function(){this.parent.isDestroyed||this.removeEventListener()},p.prototype.addEventListener=function(){this.parent.on("freehand-draw",this.draw,this),this.parent.on("destroyed",this.destroy,this)},p.prototype.removeEventListener=function(){this.parent.off("freehand-draw",this.draw),this.parent.off("destroyed",this.destroy)},p.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":var t=parseInt(e.value.id.split("_")[1],10)-1;this.isFHDIdx(t)&&this.deleteFhd(t,!0);break;case"freehandRedraw":this.freehandRedraw(e.value.context,e.value.points);break;case"deleteFhd":t=parseInt(e.value.id.split("_")[1],10)-1;this.deleteFhd(t,!0);break;case"selectFhd":t=null;e.value.id&&(t=parseInt(e.value.id.split("_")[1],10)-1),this.selectFhd(t);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=O.extend([],this.selPointColl);break;case"setSelPointColl":this.selPointColl=O.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=O.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)}},p.prototype.updateFhdPvtVar=function(){var e=this.parent;e.lowerCanvas&&(this.lowerContext=e.lowerCanvas.getContext("2d")),e.upperCanvas&&(this.upperContext=e.upperCanvas.getContext("2d"))},p.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},p.prototype.getModuleName=function(){return"freehand-draw"},p.prototype.hoverFhd=function(e,t){var o,i,r,n,a,s,l=this.parent,p=this.upperContext,h=-1,h=-1<this.fhdHovIdx?this.fhdHovIdx:this.fhdSelIdx,d=(l.points=O.extend([],l.pointColl[h].points),this.pointCounter=0,l.points.length);p.fillStyle=e||l.pointColl[h].strokeColor,p.strokeStyle=p.fillStyle,a=s=this.penStrokeWidth=t||l.pointColl[h].strokeWidth,1===d&&(o=i=r=n=l.points[0],this.startDraw(p,o,i,r,n,a,s));for(var c=0;c<d-3;c++)l.points[c+1]&&l.points[c+2]&&l.points[c+2]&&(o=this.calcCurveCP(l.points[c+0],l.points[c+1],l.points[c+2]).controlPoint2,i=this.calcCurveCP(l.points[c+1],l.points[c+2],l.points[c+3]).controlPoint1,r=0===c?l.points[c]:l.points[c+1],n=l.points[c+2],this.startDraw(p,o,i,r,n,a,s));p.closePath();e=this.getSqPtFD(h),t=p.lineWidth;p.lineWidth=2,p.strokeStyle=l.themeColl[l.theme].primaryColor,p.beginPath(),p.rect(e.startX,e.startY,e.width,e.height),p.stroke(),p.closePath(),p.lineWidth=t},p.prototype.freehandDownHandler=function(e,t){var o=this.parent,e=(o.lowerCanvas=document.querySelector("#"+o.element.id+"_lowerCanvas"),this.lowerContext=o.lowerCanvas.getContext("2d"),o.upperCanvas=document.querySelector("#"+o.element.id+"_upperCanvas"),this.upperContext=o.upperCanvas.getContext("2d"),this.fhdObj.time=(new Date).getTime(),this.isFreehandDrawing=!0,"mousedown"===e.type?this.freehandDownPoint={x:e.clientX,y:e.clientY}:this.freehandDownPoint={x:e.touches[0].clientX,y:e.touches[0].clientY},this.isFreehandPointMoved=!1,O.EventHandler.add(t,"mousemove touchmove",this.freehandMoveHandler,this),{id:"pen_"+(this.currFHDIdx+1),type:v.ShapeType.FreehandDraw,startX:this.freehandDownPoint.x,startY:this.freehandDownPoint.y,strokeColor:o.activeObj.strokeSettings.strokeColor,strokeWidth:this.penStrokeWidth,points:null,index:o.objColl.length+o.freehandCounter+1});this.triggerShapeChanging({cancel:!1,action:"draw-start",previousShapeSettings:e,currentShapeSettings:e})},p.prototype.freehandUpHandler=function(e,t,o){var i=t.getBoundingClientRect(),r=this.parent,t=(O.EventHandler.remove(t,"mousemove touchmove",this.freehandMoveHandler),0===r.points.length&&("mouseup"===e.type?this.processPoint(e.clientX-i.left,e.clientY-i.top,!0,o):"touchend"===e.type&&e.changedTouches?this.processPoint(e.changedTouches[0].clientX-i.left,e.changedTouches[0].clientY-i.top,!0,o):this.isFreehandPointMoved||this.processPoint(this.freehandDownPoint.x-i.left,this.freehandDownPoint.y-i.top,!0,o)),o.closePath(),O.extend({},r.cropObj,{},!0)),e={currObj:{}},i=(r.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:e}}),e.currObj),o=(i.objColl=O.extend([],r.objColl,[],!0),i.pointColl=O.extend([],r.pointColl,[],!0),i.afterCropActions=O.extend([],r.afterCropActions,[],!0),{selPointColl:null}),e=(r.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:o}}),i.selPointColl=O.extend([],o.selPointColl,[],!0),r.freehandCounter),o=r.objColl.length+r.freehandCounter+1,e=(r.pointColl[e]={points:O.extend([],r.points),strokeColor:r.activeObj.strokeSettings.strokeColor,strokeWidth:this.penStrokeWidth,flipState:r.transform.currFlipState,id:"pen_"+(this.currFHDIdx+1),order:o},r.points=[],this.dummyPoints=[],this.selPointColl[e]={points:O.extend([],this.selPoints)},this.selPoints=[],this.pointCounter=0,r.freehandCounter++,this.isFreehandDrawing=!1,r.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"freehand-draw",previousObj:i,previousObjColl:i.objColl,previousPointColl:i.pointColl,previousSelPointColl:i.selPointColl,previousCropObj:t,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),{id:"pen_"+(this.currFHDIdx+1),type:v.ShapeType.FreehandDraw,startX:this.freehandDownPoint.x,startY:this.freehandDownPoint.y,strokeColor:r.activeObj.strokeSettings.strokeColor,strokeWidth:this.penStrokeWidth,points:r.pointColl[this.currFHDIdx].points,index:o});this.triggerShapeChanging({cancel:!1,action:"draw-end",previousShapeSettings:e,currentShapeSettings:e}),this.currFHDIdx++},p.prototype.freehandMoveHandler=function(e){this.isFreehandPointMoved=!0;var t,o=this.parent.upperCanvas.getBoundingClientRect(),e="mousemove"===e.type?(t=e.clientX-o.left,e.clientY-o.top):(t=e.touches[0].clientX-o.left,e.touches[0].clientY-o.top);this.isFreehandDrawing&&(this.upperContext.fillStyle=this.parent.activeObj.strokeSettings.strokeColor,this.processPoint(t,e,!1,this.upperContext))},p.prototype.processPoint=function(e,t,o,i){var r,n,a,s,l,p,h,d=this.parent,c=(this.point(e,t,(new Date).getTime()),!!(r=0<d.points.length&&d.points[d.points.length-1])&&this.distanceTo(r)<=5);this.selPoints.push({x:e,y:t,ratioX:(e-d.img.destLeft)/d.img.destWidth,ratioY:(t-d.img.destTop)/d.img.destHeight,time:this.fhdObj.time}),r&&c&&!o||(this.fhdObj.time=(new Date).getTime(),d.points.push({x:e,y:t,ratioX:(e-d.img.destLeft)/d.img.destWidth,ratioY:(t-d.img.destTop)/d.img.destHeight,time:this.fhdObj.time}),this.dummyPoints.push({x:e,y:t,ratioX:(e-d.img.destLeft)/d.img.destWidth,ratioY:(t-d.img.destTop)/d.img.destHeight,time:this.fhdObj.time}),2<this.dummyPoints.length&&(3===this.dummyPoints.length&&this.dummyPoints.unshift(this.dummyPoints[0]),r=this.dummyPoints[0],c=this.dummyPoints[1],d=this.dummyPoints[2],a=this.dummyPoints[3],n=this.calcCurveCP(r,c,d).controlPoint2,a=this.calcCurveCP(c,d,a).controlPoint1,s=this.dummyPoints[1],l=this.dummyPoints[2],p=.5,h=5,O.isNullOrUndefined(this.penStrokeWidth)||(p=h=this.penStrokeWidth),this.startDraw(i,n,a,s,l,p,h),this.pointCounter++,this.dummyPoints.shift()),o&&(n=a=s=l={x:e,y:t,time:(new Date).getTime()},p=.5,h=5,O.isNullOrUndefined(this.penStrokeWidth)||(p=h=this.penStrokeWidth),this.startDraw(i,n,a,s,l,p,h)))},p.prototype.calcCurveCP=function(e,t,o){var i=e.x-(t=t||e).x,r=e.y-t.y,n=t.x-(o=o||t).x,a=t.y-o.y,s=(e.x+t.x)/2,e=(e.y+t.y)/2,l=(t.x+o.x)/2,o=(t.y+o.y)/2,i=Math.sqrt(i*i+r*r),r=Math.sqrt(n*n+a*a),n=r/(i+r),a=l+(s-l)*n,i=o+(e-o)*n,r=t.x-a,n=t.y-i;return{controlPoint1:this.point(s+r,e+n,0),controlPoint2:this.point(l+r,o+n,0)}},p.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}},p.prototype.startDraw=function(e,t,o,i,r,n,a){var s=this.pointVelocity(i),n=(s=.7*s+(1-.7)*this.fhdObj.lastVelocity,Math.max(a/1.7,n));this.drawCurve(this.fhdObj.time,n,e,t,o,i,r,a),this.fhdObj.lastVelocity=s,this.fhdObj.time=n},p.prototype.pointVelocity=function(e){return this.fhdObj.time!==e.time?this.distanceTo(e)/(this.fhdObj.time-e.time):0},p.prototype.distanceTo=function(e){return Math.sqrt(Math.pow(this.fhdObj.pointX-e.x,2)+Math.pow(this.fhdObj.pointY-e.y,2))},p.prototype.drawCurve=function(e,t,o,i,r,n,a,s){var l,p,h,d,c,u,g,v,f=t-e,t=this.bezierLength(i,r,n,a),C=2*Math.ceil(t);for(o.beginPath(),l=0;l<C;l++)g=(v=(u=(c=1-(p=l/C))*c)*c)*n.x,g=(g=(g+=3*u*p*i.x)+3*c*(h=p*p)*r.x)+(d=h*p)*a.x,v=v*n.y,v=(v=(v+=3*u*p*i.y)+3*c*h*r.y)+d*a.y,u=Math.min(e+d*f,s),this.drawArc(g,v,u,o);o.closePath(),o.fill()},p.prototype.bezierLength=function(e,t,o,i){for(var r,n,a,s,l,p,h=0,d=0;d<=10;d++)r=this.bezierPoint(n=d/10,o.x,e.x,t.x,i.x),n=this.bezierPoint(n,o.y,e.y,t.y,i.y),0<d&&(l=r-a,p=n-s,h+=Math.sqrt(l*l+p*p)),a=r,s=n;return h},p.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},p.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))},p.prototype.freehandRedraw=function(e,t){var o=this.parent,i=e.filter;if(e.filter="none",t&&(o.pointColl[o.freehandCounter]={points:t,strokeColor:o.activeObj.strokeSettings.strokeColor,strokeWidth:this.penStrokeWidth,flipState:o.transform.currFlipState,id:"pen_"+(o.freehandCounter+1),order:o.objColl.length+o.freehandCounter+1},this.selPointColl[o.freehandCounter]=O.extend({},o.pointColl[o.freehandCounter],{},!0),o.freehandCounter++),0<o.freehandCounter){for(var r=0;r<o.freehandCounter;r++){o.points=O.extend([],o.pointColl[r].points),this.pointCounter=0;var n=o.points.length,a=void 0,s=void 0,l=void 0,p=void 0,h=void 0,d=void 0;0<n&&(e.fillStyle=o.pointColl[r].strokeColor,h=d=this.penStrokeWidth=o.pointColl[r].strokeWidth),1===n&&(a=s=l=p=o.points[0],this.startDraw(e,a,s,l,p,h,d));for(var c=0;c<n-3;c++)o.points[c+1]&&o.points[c+2]&&o.points[c+2]&&(a=this.calcCurveCP(o.points[c+0],o.points[c+1],o.points[c+2]).controlPoint2,s=this.calcCurveCP(o.points[c+1],o.points[c+2],o.points[c+3]).controlPoint1,l=0===c?o.points[c]:o.points[c+1],p=o.points[c+2],this.startDraw(e,a,s,l,p,h,d));e.closePath()}e===this.lowerContext&&(o.notify("draw",{prop:"applyFrame",value:{ctx:this.lowerContext,frame:o.frameObj.type,preventImg:!0}}),this.upperContext.clearRect(0,0,o.upperCanvas.width,o.upperCanvas.height))}e.filter=i},p.prototype.getSqPtFD=function(e,t){for(var o={startX:0,startY:0,endX:0,endY:0,width:0,height:0},i=O.extend([],this.selPointColl[e].points,[]),r=(this.parent.points=O.extend([],this.parent.pointColl[e].points),this.pointCounter=0,i.length),n=0;n<r;n++)0===o.startX&&0===o.startY&&0===o.endX&&0===o.endY?(o.startX=i[n].x,o.startY=i[n].y,o.endX=i[n].x,o.endY=i[n].y):(o.startX=Math.min(o.startX,i[n].x),o.startY=Math.min(o.startY,i[n].y),o.endX=Math.max(o.endX,i[n].x),o.endY=Math.max(o.endY,i[n].y));return o.startX-=this.penStrokeWidth,o.startY-=this.penStrokeWidth,o.endX+=this.penStrokeWidth,o.endY+=this.penStrokeWidth,o.width=o.endX-o.startX,o.height=o.endY-o.startY,t&&(t.activePoint=o),o},p.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"})},p.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},p.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})},p.prototype.selectFhd=function(e){var t=this.parent,o=O.extend({},this.tempFHDStyles,{},!0);if(t.notify("selection",{prop:"setFreehandDrawEditing",onPropertyChange:!1,value:{bool:!0}}),e||0===e){if(!this.isFHDIdx(e))return;this.fhdSelIdx=this.fhdHovIdx=e,this.hoverFhd(),t.upperCanvas.style.cursor=t.cursor="pointer"}this.fhdSelIdx=this.fhdHovIdx;var e=t.pointColl[this.fhdSelIdx],i=(e.isSelected=!0,this.fhdSelID=e.id,"#42a5f5"!==e.strokeColor&&(t.activeObj.strokeSettings.strokeColor=this.tempFHDStyles.strokeColor=e.strokeColor),t.activeObj.strokeSettings.strokeWidth=this.tempFHDStyles.strokeWidth=t.pointColl[this.fhdHovIdx].strokeWidth,{bool:!1});t.notify("selection",{prop:"getFreehandDrawEditing",onPropertyChange:!1,value:{obj:i}}),i.bool?(i={id:"pen_"+(this.fhdSelIdx+1),type:v.ShapeType.FreehandDraw,startX:e.points[0].x,startY:e.points[0].y,strokeColor:e.strokeColor,strokeWidth:e.strokeWidth,points:e.points,opacity:e.opacity,index:e.order},this.triggerShapeChanging({cancel:!1,action:"select",previousShapeSettings:i,currentShapeSettings:i})):t.okBtn(null,!0),t.isUndoRedoStack&&(this.tempFHDStyles=o)},p.prototype.deleteFhd=function(e,t){var o=this.parent;if(this.isFHDIdx(e)){this.upperContext.clearRect(0,0,o.upperCanvas.width,o.upperCanvas.height);var i=O.extend({},o.pointColl,{},!0),r=O.extend({},this.selPointColl,{},!0),n=(o.pointColl={},this.selPointColl={},0);if(O.isNullOrUndefined(t))for(var a=0;a<o.freehandCounter;a++)a!==e&&(o.pointColl[n]=i[a],this.selPointColl[n]=r[a],n++);else for(a=0;a<o.freehandCounter;a++)parseInt(i[a].id.split("_")[1],10)-1!==e&&(o.pointColl[n]=i[a],this.selPointColl[n]=r[a],n++);--o.freehandCounter,this.fhdHovIdx=this.fhdSelIdx=null,o.notify("selection",{prop:"resetFreehandDrawVariables"}),o.notify("draw",{prop:"render-image",value:{isMouseWheel:null}}),o.notify("toolbar",{prop:"refresh-main-toolbar",onPropertyChange:!1})}},p.prototype.zoomX=function(e){return e*this.parent.img.destWidth+this.parent.img.destLeft},p.prototype.zoomY=function(e){return e*this.parent.img.destHeight+this.parent.img.destTop},p.prototype.zoomFHDColl=function(e){var t=this.parent,o={startX:t.img.destLeft,startY:t.img.destTop,width:t.img.destWidth,height:t.img.destHeight};t.notify("shape",{prop:"straightenShapes",onPropertyChange:!1});for(var i=0;i<t.freehandCounter;i++){t.points=O.extend([],t.pointColl[i].points,[]),this.pointCounter=0;for(var r=t.points.length,n=0;n<r;n++){var a=t.points[n];a.x=this.zoomX(a.ratioX),a.y=this.zoomY(a.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!==t.transform.straighten&&t.notify("shape",{prop:"straightenFHD",onPropertyChange:!1}),t.img.destLeft=o.startX,t.img.destTop=o.startY,t.img.destWidth=o.width,t.img.destHeight=o.height,O.isNullOrUndefined(e)&&this.freehandRedraw(this.lowerContext,null)},p.prototype.updateFHDCurPts=function(){for(var e=this.parent,t=0;t<e.freehandCounter;t++)if(this.selPointColl[t]){this.selPoints=O.extend([],this.selPointColl[t].points,[]),this.pointCounter=0;for(var o=this.selPoints.length,i=0;i<o;i++){var r=this.selPoints[i];r.x=this.zoomX(r.ratioX),r.y=this.zoomY(r.ratioY)}}},p.prototype.rotateFhdColl=function(){for(var e=this.parent,t=e.img,o=t.destLeft,i=t.destTop,r=t.destWidth,n=t.destHeight,a=0;a<e.freehandCounter;a++){e.points=O.extend([],e.pointColl[a].points,[]),this.pointCounter=0;for(var s=e.points.length,l=0;l<s;l++)(p=e.points[l]).y=i+n*p.ratioX,p.x=o+r-r*p.ratioY,p.ratioX=(p.x-o)/r,p.ratioY=(p.y-i)/n}for(a=0;a<e.freehandCounter;a++)if(this.selPointColl[a]){this.selPoints=O.extend([],this.selPointColl[a].points,[]),this.pointCounter=0;for(var p,s=this.selPoints.length,l=0;l<s;l++)(p=this.selPoints[l]).y=i+n*p.ratioX,p.x=o+r-r*p.ratioY,p.ratioX=(p.x-o)/r,p.ratioY=(p.y-i)/n}this.updateFHDCurPts()},p.prototype.flipFHDColl=function(e){e=e.toLowerCase();if("horizontal"===e)this.pointsHorizontalFlip();else{if("vertical"!==e){this.pointsHorizontalFlip();for(var t=0;t<this.parent.freehandCounter;t++)this.parent.pointColl[t].shapeFlip=""}this.pointsVerticalFlip()}},p.prototype.pointsHorizontalFlip=function(){for(var e=this.parent,t=e.img,o=t.destLeft,i=t.destTop,r=t.destWidth,n=t.destHeight,a=0;a<e.freehandCounter;a++)if(e.pointColl[a].shapeFlip!==e.transform.currFlipState){e.points=O.extend([],e.pointColl[a].points,[]),this.pointCounter=0;for(var s=e.points.length,l=0;l<s;l++)(p=e.points[l]).x<=o+r/2?p.x=o+r-(p.x-o):p.x>=o+r/2&&(p.x=o+(o+r-p.x)),p.ratioX=(p.x-o)/r,p.ratioY=(p.y-i)/n;e.pointColl[a].shapeFlip=e.transform.currFlipState}for(a=0;a<e.freehandCounter;a++)if(this.selPointColl[a]&&this.selPointColl[a].shapeFlip!==e.transform.currFlipState){this.selPoints=O.extend([],this.selPointColl[a].points,[]),this.pointCounter=0;for(var p,s=this.selPoints.length,l=0;l<s;l++)(p=this.selPoints[l]).x<=o+r/2?p.x=o+r-(p.x-o):p.x>=o+r/2&&(p.x=o+(o+r-p.x)),p.ratioX=(p.x-o)/r,p.ratioY=(p.y-i)/n}this.updateFHDCurPts()},p.prototype.pointsVerticalFlip=function(){for(var e=this.parent,t=e.img,o=t.destLeft,i=t.destTop,r=t.destWidth,n=t.destHeight,a=0;a<e.freehandCounter;a++)if(e.pointColl[a].shapeFlip!==e.transform.currFlipState){e.points=O.extend([],e.pointColl[a].points,[]),this.pointCounter=0;for(var s=e.points.length,l=0;l<s;l++)(p=e.points[l]).y<=i+n/2?p.y=i+n-(p.y-i):p.y>=i+n/2&&(p.y=i+(i+n-p.y)),p.ratioX=(p.x-o)/r,p.ratioY=(p.y-i)/n;e.pointColl[a].shapeFlip=e.transform.currFlipState}for(a=0;a<e.freehandCounter;a++)if(this.selPointColl[a]&&this.selPointColl[a].shapeFlip!==e.transform.currFlipState){this.selPoints=O.extend([],this.selPointColl[a].points,[]),this.pointCounter=0;for(var p,s=this.selPoints.length,l=0;l<s;l++)(p=this.selPoints[l]).y<=i+n/2?p.y=i+n-(p.y-i):p.y>=i+n/2&&(p.y=i+(i+n-p.y)),p.ratioX=(p.x-o)/r,p.ratioY=(p.y-i)/n}this.updateFHDCurPts()},p.prototype.updateFHDColl=function(e){for(var t=this.parent,o={startX:t.img.destLeft,startY:t.img.destTop,width:t.img.destWidth,height:t.img.destHeight},i=(t.notify("shape",{prop:"straightenShapes",onPropertyChange:!1}),t.img),r=i.destLeft,n=i.destTop,a=i.destWidth,s=i.destHeight,l=0,p=t.objColl.length;l<p;l++){var h,d=t.objColl[l];if("line"===d.shape||"arrow"===d.shape?t.notify("shape",{prop:"straightenShapePoints",value:{obj:d,isReverse:!0}}):"path"===d.shape&&(h=t.transform.straighten,t.transform.straighten=-t.transform.straighten,t.notify("shape",{prop:"straightenPath",onPropertyChange:!1,value:{obj:d}}),t.transform.straighten=h),d.imageRatio={startX:(d.activePoint.startX-r)/a,startY:(d.activePoint.startY-n)/s,endX:(d.activePoint.endX-r)/a,endY:(d.activePoint.endY-n)/s,width:a/d.activePoint.width,height:s/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-r)/a,d.pointColl[c].ratioY=(d.pointColl[c].y-n)/s;t.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1})}0<t.freehandCounter&&0!==t.transform.straighten&&(h=t.transform.straighten,t.transform.straighten=-t.transform.straighten,t.notify("shape",{prop:"straightenFHD",onPropertyChange:!1}),t.transform.straighten=h);for(var g=0;g<t.freehandCounter;g++){t.points=O.extend([],t.pointColl[g].points,[]),this.pointCounter=0;for(var v=t.points.length,f=0;f<v;f++)(C=t.points[f]).ratioX=(C.x-r)/a,C.ratioY=(C.y-n)/s}for(g=0;g<t.freehandCounter;g++)if(this.selPointColl[g]){this.selPoints=O.extend([],this.selPointColl[g].points,[]),this.pointCounter=0;for(var C,v=this.selPoints.length,f=0;f<v;f++)(C=this.selPoints[f]).ratioX=(C.x-r)/a,C.ratioY=(C.y-n)/s}this.straightenPoint.x&&this.straightenPoint.y&&(this.straightenPoint.ratioX=(this.straightenPoint.x-r)/a,this.straightenPoint.ratioY=(this.straightenPoint.y-n)/s),t.img.destLeft=o.startX,t.img.destTop=o.startY,t.img.destWidth=o.width,t.img.destHeight=o.height,t.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"zoom",pen:"zoom",isPreventApply:e}})},p.prototype.panFHDColl=function(e,t,o){for(var i=this.parent,r=0;r<i.freehandCounter;r++){i.points=O.extend([],i.pointColl[r].points,[]),this.pointCounter=0;for(var n=i.points.length,a=0;a<n;a++){var s=i.points[a];""===o||"vertical"===o?s.x+=e:s.x-=e,""===o||"horizontal"===o?s.y+=t:s.y-=t}}for(r=0;r<i.freehandCounter;r++)if(this.selPointColl[r]){this.selPoints=O.extend([],this.selPointColl[r].points,[]),this.pointCounter=0;for(n=this.selPoints.length,a=0;a<n;a++){s=this.selPoints[a];""===o||"vertical"===o?s.x+=e:s.x-=e,""===o||"horizontal"===o?s.y+=t:s.y-=t}}this.straightenPoint.x&&this.straightenPoint.y&&(""===o||"vertical"===o?this.straightenPoint.x+=e:this.straightenPoint.x-=e,""===o||"horizontal"===o?this.straightenPoint.y+=t:this.straightenPoint.y-=t),this.freehandRedraw(this.lowerContext,null)},p.prototype.freeHandDraw=function(e){var t=this.parent;e?(t.points=[],this.dummyPoints=[],t.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),t.togglePen=!0,t.upperCanvas.style.cursor=t.cursor="crosshair",t.upperCanvas.style.display="block",O.isNullOrUndefined(t.activeObj.strokeSettings)&&(t.notify("shape",{prop:"getStrokeSettings",onPropertyChange:!(e={strokeSettings:{}}),value:{obj:e}}),t.activeObj.strokeSettings=e.strokeSettings),O.isNullOrUndefined(t.activeObj.strokeSettings.strokeWidth)&&(t.activeObj.strokeSettings.strokeWidth=2),t.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"pen",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}})):(t.upperCanvas.style.cursor=t.cursor="default",e=this.penStrokeWidth,t.notify("shape",{prop:"apply",onPropertyChange:!1,value:{shape:null,obj:null,canvas:null}}),t.notify("toolbar",{prop:"refresh-main-toolbar",onPropertyChange:!1}),t.notify("toolbar",{prop:"setCurrentToolbar",value:{type:"main"}}),t.notify("selection",{prop:"setFreehandDrawCustomized",value:{isFreehandDrawCustomized:!1}}),this.penStrokeWidth=e)},p.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},p.prototype.updateCropPtsForSel=function(){for(var e=this.parent,t=e.activeObj.activePoint,o=0;o<e.freehandCounter;o++){var i={selPointColl:O.extend([],this.selPointColl)};if(i.selPointColl[o]){this.selPoints=O.extend([],i.selPointColl[o].points,[]),this.pointCounter=0;for(var r=this.selPoints.length,n=0;n<r;n++){var a=this.selPoints[n];a.ratioX=(a.x-t.startX)/t.width,a.ratioY=(a.y-t.startY)/t.height}}}},p.prototype.triggerShapeChanging=function(e){var t,o=this.parent,i=o.pointColl[this.fhdSelIdx];o.trigger("shapeChanging",e),-1!==e.currentShapeSettings.id.indexOf("pen_")||"draw-end"!==e.action&&"select"!==e.action||(t="pen_"+e.currentShapeSettings.id,this.fhdSelIdx?o.pointColl[this.fhdSelIdx].id=t:o.pointColl[o.freehandCounter-1].id=t),this.penStrokeWidth=e.currentShapeSettings.strokeWidth,o.activeObj.strokeSettings.strokeColor!==e.currentShapeSettings.strokeColor&&(o.activeObj.strokeSettings.strokeColor=e.currentShapeSettings.strokeColor,o.notify("toolbar",{prop:"update-toolbar-items",onPropertyChange:!1})),this.fhdSelID&&i&&e.currentShapeSettings&&(i.strokeColor=e.currentShapeSettings.strokeColor,i.strokeWidth=e.currentShapeSettings.strokeWidth,i.points=e.currentShapeSettings.points,i.opacity=e.currentShapeSettings.opacity),"select"===e.action&&(this.freehandRedraw(this.upperContext),o.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"pen",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}}))},p.prototype.setCenterSelPoints=function(){var e=this.parent,t={startX:e.img.destLeft,startY:e.img.destTop,width:e.img.destWidth,height:e.img.destHeight},o=(e.notify("shape",{prop:"straightenShapes",onPropertyChange:!1}),e.img),i=o.destLeft,r=o.destTop,n=o.destWidth,o=o.destHeight,a=e.activeObj.activePoint;!O.isNullOrUndefined(this.prevStraightenObj)&&JSON.stringify(this.prevStraightenObj.activePoint)===JSON.stringify(a)||(this.straightenPoint={x:a.startX+a.width/2,y:a.startY+a.height/2,ratioX:(a.startX+a.width/2-i)/n,ratioY:(a.startY+a.height/2-r)/o},this.prevStraightenObj=O.extend({},e.activeObj,{},!0),this.straightenPointAngle=e.transform.straighten),e.img.destLeft=t.startX,e.img.destTop=t.startY,e.img.destWidth=t.width,e.img.destHeight=t.height};var l=p;function p(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()}c.prototype.destroy=function(){this.parent.isDestroyed||this.removeEventListener()},c.prototype.addEventListener=function(){this.parent.on("selection",this.selection,this),this.parent.on("destroyed",this.destroy,this)},c.prototype.removeEventListener=function(){this.parent.off("selection",this.selection),this.parent.off("destroyed",this.destroy)},c.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)}},c.prototype.getModuleName=function(){return"selection"},c.prototype.updatePrivateVariables=function(){var e=this.parent;e.lowerCanvas&&(this.lowerContext=e.lowerCanvas.getContext("2d")),e.upperCanvas&&(this.upperContext=e.upperCanvas.getContext("2d"))},c.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=[v.ArrowheadType.None,v.ArrowheadType.SolidArrow]},c.prototype.performTabAction=function(){var e,t=this.parent;"block"!==t.textArea.style.display&&"inline-block"!==t.textArea.style.display||(e=this.applyCurrShape(!1),t.notify("shape",{prop:"redrawActObj",onPropertyChange:!1,value:{x:null,y:null,isMouseDown:null}}),e&&t.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"ok"}}))},c.prototype.selMouseUpEvent=function(){this.oldPoint.x=void 0,this.oldPoint.y=void 0},c.prototype.getMouseCursor=function(e,t,o,i,r){var n=this.getTransRotationPoint(e),a=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":n&&!r&&t>=n.x-(a+2)&&t<=n.x+(a+2)&&o>=n.y-(a+2)&&o<=n.y+(a+2)?"grabbing":"default"},c.prototype.setCursor=function(e,t){var o=this.parent,i=(o.upperCanvas.style.cursor=o.cursor="default",{bool:null});if(o.notify("toolbar",{prop:"getFrameToolbar",onPropertyChange:!1,value:{obj:i}}),o.isResize||this.isSliding||i.bool)o.upperCanvas.style.cursor="default";else if(o.currObjType.isDragging)""===this.dragElement?o.upperCanvas.style.cursor=o.cursor="move":o.upperCanvas.style.cursor=o.cursor=this.dragElement;else if(o.togglePen)o.upperCanvas.style.cursor=o.cursor="crosshair";else{if(o.activeObj.shape&&this.setCursorForActObj(void 0,!1,e,t),"default"===o.cursor||"grab"===o.cursor){for(var r=this.getHighestOrder(),n=O.extend([],o.shapeColl,[],!0),i=O.extend([],o.objColl,[],!0),a=!1;0<r;){a=!1;for(var s,l=n.length-1;0<=l;l--)n[l].order===r?(a=!0,n[l].id&&-1<n[l].id.indexOf("pen")?o.pointColl[0]&&(o.cursor,1)&&!o.currObjType.isDragging&&!o.currObjType.isResize&&(s=O.extend([],o.points,[],!0),this.setCursorForFreehandDrawing(e,t,o.upperCanvas,n[l].id),o.points=s):(o.objColl=[],o.objColl.push(O.extend({},n[l],null,!0)),s=o.upperCanvas.style.cursor,0<o.objColl.length&&(o.cursor,1)&&this.setCursorFromObj(e,t,o.objColl,o.upperCanvas,!1),"grab"===s&&"default"===o.cursor&&(o.upperCanvas.style.cursor=o.cursor="grab"))):O.isNullOrUndefined(n[l].order)&&(a=!0);if("default"!==o.cursor&&"grab"!==o.cursor)break;if(a)for(var p=!1;!p&&0<r;){for(var h=0;h<n.length;h++)if(n[h].order===r-1){p=!0;break}r--,p||r--}}o.objColl=i,"default"!==o.cursor&&"grab"!==o.cursor||o.togglePan&&(o.lowerCanvas.style.cursor=o.upperCanvas.style.cursor=o.cursor="grab")}""===this.currentDrawingShape||"default"!==o.cursor&&"grab"!==o.cursor||(o.upperCanvas.style.cursor=o.cursor="crosshair")}},c.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},c.prototype.setCursorForActObj=function(e,t,o,i){var r,n=this.parent;void 0!==n.activeObj.horTopLine?(!(t=void 0===(e=void 0!==n.activeObj.shape?n.activeObj.shape.split("-"):e)&&n.currObjType.isCustomCrop||void 0!==e&&"crop"===e[0]?!0:t)&&n.togglePan&&(n.lowerCanvas.style.cursor=n.upperCanvas.style.cursor=n.cursor="grab"),e=n.upperCanvas.style.cursor,r=O.extend({},n.activeObj,{},!0),this.cursorTargetId=r.currIndex,0===r.shapeDegree?n.transform.degree:(n.transform.degree,r.shapeDegree),"line"===r.shape||"arrow"===r.shape?this.setCursorForLineArrow(r,o,i,n.upperCanvas):"path"===r.shape?this.setCursorForPath(r,o,i,n.upperCanvas):O.isNullOrUndefined(r.rotatedAngle)||0===r.rotatedAngle?(n.upperCanvas.style.cursor=n.cursor=this.getMouseCursor(r,o,i,t,!1),"text"===r.shape&&-1<["n-resize","s-resize","e-resize","w-resize"].indexOf(n.cursor)&&(n.upperCanvas.style.cursor=n.cursor="move")):this.setCursorForRotatedObject(r,o,i,n.upperCanvas),"default"===e&&"default"===n.cursor&&t&&(n.upperCanvas.style.cursor=n.cursor="grab"),"grab"===e&&"default"===n.cursor&&(n.upperCanvas.style.cursor=n.cursor="grab")):n.togglePan&&!n.togglePen?n.lowerCanvas.style.cursor=n.upperCanvas.style.cursor=n.cursor="grab":n.currObjType.isCustomCrop||n.togglePen?n.upperCanvas.style.cursor=n.cursor="crosshair":n.upperCanvas.style.cursor=n.cursor="default"},c.prototype.setCursorForPath=function(e,t,o,i){this.setCursorForLineArrow(e,t,o,i);var r=this.parent;if("default"===r.cursor)for(var n=O.extend({},e,null,!0),a=!1,s=1,l=e.pointColl.length;s<l&&!a;s++){n.activePoint.startX=e.pointColl[s-1].x,n.activePoint.startY=e.pointColl[s-1].y,n.activePoint.endX=e.pointColl[s].x,n.activePoint.endY=e.pointColl[s].y,r.notify("shape",{prop:"setPointCollForLineArrow",onPropertyChange:!1,value:{obj:n}});for(var p=e.topLeftCircle.radius,h=0,d=n.pointColl.length;h<d;h++){var c=n.pointColl[h];if(!O.isNullOrUndefined(c.x-2*p)&&!O.isNullOrUndefined(c.x+2*p)&&!O.isNullOrUndefined(c.y-2*p)&&!O.isNullOrUndefined(c.y+2*p)&&t>=c.x-2*p&&t<=c.x+2*p&&o>=c.y-2*p&&o<=c.y+2*p){i.style.cursor=r.cursor="move",a=!0;break}i.style.cursor=r.cursor="default"}}return r.cursor},c.prototype.setCursorForLineArrow=function(e,t,o,i){var r,n=e.topLeftCircle.radius;if(!O.isNullOrUndefined(e.pointColl))for(var a=0,s=e.pointColl.length;a<s;a++){var l=e.pointColl[a];if(t>=l.x-2*n&&t<=l.x+2*n&&o>=l.y-2*n&&o<=l.y+2*n){i.style.cursor=this.parent.cursor="move",r=a;break}i.style.cursor=this.parent.cursor="default"}return r},c.prototype.setCursorForRotatedObject=function(e,t,o,i){this.resizedElement="";var r=this.parent,n=e.bottomCenterCircle.radius,a=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],g=e.horBottomLinePointColl[0];if(t>=u.x-(n+2)&&t<=u.x+(n+2)&&o>=u.y-(n+2)&&o<=u.y+(n+2)?i.style.cursor=r.cursor="nw-resize":t>=a.x-5&&t<=a.x+5&&o>=a.y-5&&o<=a.y+5?i.style.cursor=r.cursor=this.resizedElement="n-resize":t>=s.x-(n+2)&&t<=s.x+(n+2)&&o>=s.y-(n+2)&&o<=s.y+(n+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>=g.x-(n+2)&&t<=g.x+(n+2)&&o>=g.y-(n+2)&&o<=g.y+(n+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-(n+2)&&t<=d.x+(n+2)&&o>=d.y-(n+2)&&o<=d.y+(n+2)?i.style.cursor=r.cursor="se-resize":c&&t>=c.x-(n+2)&&t<=c.x+(n+2)&&o>=c.y-(n+2)&&o<=c.y+(n+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 v=0,f=e.horTopLinePointColl.length;v<f;v++){var C=e.horTopLinePointColl[v];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(v=0,f=e.horBottomLinePointColl.length;v<f;v++){var b=e.horBottomLinePointColl[v];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(v=0,f=e.verLeftLinePointColl.length;v<f;v++){var m=e.verLeftLinePointColl[v];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(v=0,f=e.verRightLinePointColl.length;v<f;v++){var y=e.verRightLinePointColl[v];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},c.prototype.adjustCursorStylesForRotatedState=function(e){var t=this.parent,o=e.rotatedAngle*(180/Math.PI);return(92<=(o=0<o?Math.floor(o):Math.ceil(o))&&o<=182||-178<=o&&o<=-88)&&t.cursor in(o={"nw-resize":"ne-resize","n-resize":"s-resize","ne-resize":"nw-resize","w-resize":"e-resize","e-resize":"w-resize","sw-resize":"se-resize","s-resize":"n-resize","se-resize":"sw-resize"})&&(t.cursor=o[t.cursor]),t.upperCanvas.style.cursor=this.getResizeElement(e.rotatedAngle*(180/Math.PI),t.cursor),t.cursor},c.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,n=o;r<n.length;r++){var a=n[r],s=a[0],l=a[1],a=a[2];if(s<i&&i<=l||s<i+360&&i+360<=l)return a}return t},c.prototype.setCursorForFreehandDrawing=function(e,t,o,i){var r,n=o.getContext("2d"),a=this.parent,s=document.querySelector("#"+a.element.id+"_textArea"),l=!1;a.notify("freehand-draw",{prop:"setFreehandDrawHoveredIndex",onPropertyChange:!1,value:{index:-1}});for(var p=0;p<a.freehandCounter;p++)if(!i||i===a.pointColl[p].id){for(var h={selPointColl:{}},d=(a.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:h}}),r=O.extend([],h.selPointColl[p].points,[]),a.points=O.extend([],a.pointColl[p].points,[]),a.pointColl[p]),c=(a.notify("freehand-draw",{prop:"setPointCounter",onPropertyChange:!1,value:{value:0}}),r.length),u=0;u<c;u++)if(0!==u){var g=!1;if(g=r[u-1]&&r[u]?this.isInside(e,t,r[u-1].x,r[u-1].y,r[u].x,r[u].y):g){this.isFhdPoint=!0,a.notify("freehand-draw",{prop:"setFreehandDrawHoveredIndex",onPropertyChange:!1,value:{index:p}}),a.notify("freehand-draw",{prop:"hoverFhd",onPropertyChange:!1,value:{strokeColor:null,strokeWidth:null}}),o.style.cursor=a.cursor="pointer",l=!0;break}this.isFhdEditing&&!d.isSelected||((this.isFhdPoint||this.isFhdEditing)&&(n.clearRect(0,0,o.width,o.height),a.activeObj.shape)&&"none"===s.style.display&&a.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate",obj:a.activeObj}}),this.isFhdEditing?(a.notify("freehand-draw",{prop:"getFreehandSelectedIndex",onPropertyChange:!(v={freehandSelectedIndex:-1}),value:{obj:v}}),f=a.pointColl[v.freehandSelectedIndex].strokeColor,C=a.pointColl[v.freehandSelectedIndex].strokeWidth,a.notify("freehand-draw",{prop:"hoverFhd",onPropertyChange:!1,value:{strokeColor:f,strokeWidth:C}})):a.notify("freehand-draw",{prop:"setFreehandDrawHoveredIndex",onPropertyChange:!1,value:{index:null}}),this.isFhdPoint=!1)}else{var v,f,C,g=a.points[u];if(e>g.x-d.strokeWidth&&e<g.x+d.strokeWidth&&t>g.y-d.strokeWidth&&t<g.y+d.strokeWidth){this.isFhdPoint=!0,a.notify("freehand-draw",{prop:"setFreehandDrawHoveredIndex",onPropertyChange:!1,value:{index:p}}),a.notify("freehand-draw",{prop:"hoverFhd",onPropertyChange:!1,value:{strokeColor:null,strokeWidth:null}}),o.style.cursor=a.cursor="pointer",l=!0;break}this.isFhdEditing&&!d.isSelected||((this.isFhdPoint||this.isFhdEditing)&&(n.clearRect(0,0,o.width,o.height),a.activeObj.shape)&&"none"===s.style.display&&a.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate",obj:a.activeObj}}),this.isFhdEditing&&(a.notify("freehand-draw",{prop:"getFreehandSelectedIndex",onPropertyChange:!(v={freehandSelectedIndex:-1}),value:{obj:v}}),f=a.pointColl[v.freehandSelectedIndex].strokeColor,C=a.pointColl[v.freehandSelectedIndex].strokeWidth,a.notify("freehand-draw",{prop:"hoverFhd",onPropertyChange:!1,value:{strokeColor:f,strokeWidth:C}})),this.isFhdPoint=!1)}if(l)break}},c.prototype.setCursorFromObj=function(e,t,o,i,r){for(var n=this.parent,a=0,s=o.length;a<s;a++){if("move"===n.cursor)return;var l=O.extend({},o[a],{},!0);this.cursorTargetId=l.currIndex,"line"===l.shape||"arrow"===l.shape?this.setCursorForLineArrow(l,e,t,i):"path"===l.shape?this.setCursorForPath(l,e,t,i):O.isNullOrUndefined(l.rotatedAngle)||0===l.rotatedAngle?i.style.cursor=n.cursor=this.getMouseCursor(l,e,t,r,!0):this.setCursorForRotatedObject(l,e,t,i)}},c.prototype.isInside=function(e,t,o,i,r,n){var a=Math.min(o,r),o=Math.max(o,r),r=Math.min(i,n),i=Math.max(i,n);return a<=e&&e<=o&&r<=t&&t<=i},c.prototype.updateActivePoint=function(e,t,o){var i,r,n=this.parent,a=n.activeObj.activePoint,s=a.startX,l=a.startY,a=(a.endX,a.endY,n.activeObj.activePoint),p=a.width,h=a.height,a=(n.notify("transform",{prop:"calcMaxDimension",onPropertyChange:!1,value:{width:p,height:h,obj:{width:0,height:0},isImgShape:null}}),this.updatePrevShapeSettings()),d={cancel:!1,action:"resize",previousShapeSettings:a},c={cancel:!1,action:"move",previousShapeSettings:a},u=(this.shapeResizingArgs=d,this.shapeMovingArgs=c,"text"===n.activeObj.shape&&""!==this.dragElement&&n.notify("shape",{prop:"updateFontRatio",onPropertyChange:!1,value:{obj:n.activeObj,isTextArea:null}}),""===this.currentDrawingShape||""!==this.dragElement&&"move"!==this.dragElement||!n.isShapeDrawing||(-1<["line","arrow","path"].indexOf(n.activeObj.shape)?this.dragElement="e-resize":s<e&&l<t?this.dragElement="se-resize":e<s&&l<t?this.dragElement="sw-resize":s<e&&t<l?this.dragElement="ne-resize":e<s&&t<l&&(this.dragElement="nw-resize")),"arrow"===n.activeObj.shape&&(0<Math.atan2(e-n.lowerCanvas.width/2,t-n.lowerCanvas.height/2)?n.activeObj.rotatedAngle=-Math.atan2(e-n.lowerCanvas.width/2,t-n.lowerCanvas.height/2):n.activeObj.rotatedAngle=Math.abs(Math.atan2(e-n.lowerCanvas.width/2,t-n.lowerCanvas.height/2))),!1),g=!1;if(!o||0===n.transform.straighten||!this.isMouseOutsideImg(e,t))switch(this.dragElement.toLowerCase()){case"nw-resize":this.updateNWPoints(e,t),n.notify("shape",{prop:"updateArrowDirection",onPropertyChange:!1,value:{obj:n.activeObj,flip:null,rotatedDegree:null}}),this.triggerShapeChange(d,c,"resize");break;case"n-resize":this.updateNPoints(e,t),n.notify("shape",{prop:"updateArrowDirection",onPropertyChange:!1,value:{obj:n.activeObj,flip:null,rotatedDegree:null}}),this.triggerShapeChange(d,c,"resize");break;case"ne-resize":this.updateNEPoints(e,t),n.notify("shape",{prop:"updateArrowDirection",onPropertyChange:!1,value:{obj:n.activeObj,flip:null,rotatedDegree:null}}),this.triggerShapeChange(d,c,"resize");break;case"w-resize":this.updateWPoints(e,t),n.notify("shape",{prop:"updateArrowDirection",onPropertyChange:!1,value:{obj:n.activeObj,flip:null,rotatedDegree:null}}),this.triggerShapeChange(d,c,"resize");break;case"e-resize":this.updateEPoints(e,t),n.notify("shape",{prop:"updateArrowDirection",onPropertyChange:!1,value:{obj:n.activeObj,flip:null,rotatedDegree:null}}),this.triggerShapeChange(d,c,"resize");break;case"sw-resize":this.updateSWPoints(e,t),n.notify("shape",{prop:"updateArrowDirection",onPropertyChange:!1,value:{obj:n.activeObj,flip:null,rotatedDegree:null}}),this.triggerShapeChange(d,c,"resize");break;case"s-resize":this.updateSPoints(e,t),n.notify("shape",{prop:"updateArrowDirection",onPropertyChange:!1,value:{obj:n.activeObj,flip:null,rotatedDegree:null}}),this.triggerShapeChange(d,c,"resize");break;case"se-resize":this.updateSEPoints(e,t),n.notify("shape",{prop:"updateArrowDirection",onPropertyChange:!1,value:{obj:n.activeObj,flip:null,rotatedDegree:null}}),this.triggerShapeChange(d,c,"resize");break;case"grabbing":0<Math.atan2(e-(s+p/2),t-(l+h/2))?n.activeObj.rotatedAngle=-Math.atan2(e-(s+p/2),t-(l+h/2)):n.activeObj.rotatedAngle=Math.abs(Math.atan2(e-(s+p/2),t-(l+h/2))),(C=0===n.activeObj.shapeDegree?n.transform.degree:n.transform.degree-n.activeObj.shapeDegree)<0&&(C=360+C);for(var v=0,f=n.activeObj.flipObjColl.length;v<f;v++)"horizontal"===n.activeObj.flipObjColl[v].toLowerCase()?u=!0:"vertical"===n.activeObj.flipObjColl[v].toLowerCase()&&(g=!0);n.activeObj.rotatedAngle-=C*(Math.PI/180),0===C||360===C?g&&(n.activeObj.rotatedAngle-=Math.PI/180*180):90===C||-270===C?u&&(n.activeObj.rotatedAngle-=Math.PI/180*180):180===C||-180===C?g&&(n.activeObj.rotatedAngle-=Math.PI/180*180):270!==C&&-90!==C||u&&(n.activeObj.rotatedAngle-=Math.PI/180*180);break;case"pathdrag":O.isNullOrUndefined(this.pathAdjustedIndex)||(n.activeObj.pointColl[this.pathAdjustedIndex].x=e,n.activeObj.pointColl[this.pathAdjustedIndex].y=t);break;default:if(!o&&!n.currObjType.isCustomCrop){var C=n.activeObj.activePoint;if(this.dragPoint.startX){var b=this.dragPoint.endX-this.previousPoint.x,m=this.dragPoint.endY-this.previousPoint.y;if(C.startX+=b,C.endX+=b,C.startY+=m,C.endY+=m,s=C.startX,l=C.startY,i=C.endX,r=C.endY,"line"!==n.activeObj.shape&&"arrow"!==n.activeObj.shape&&n.activeObj.rotationCirclePointColl&&(n.activeObj.rotationCirclePointColl.x+=b,n.activeObj.rotationCirclePointColl.y+=m,n.activeObj.rotationCirclePoint.x+=b,n.activeObj.rotationCirclePoint.y+=m),"path"===n.activeObj.shape)for(v=0,f=n.activeObj.pointColl.length;v<f;v++)n.activeObj.pointColl[v].x+=b,n.activeObj.pointColl[v].y+=m;!this.isPreventDragging&&"line"!==n.activeObj.shape&&0===n.activeObj.rotatedAngle&&(s<n.img.destLeft||l<n.img.destTop||i>n.img.destLeft+n.img.destWidth||r>n.img.destTop+n.img.destHeight)&&(C.startX-=b,C.endX-=b,C.startY-=m,C.endY-=m,"line"!==n.activeObj.shape&&"arrow"!==n.activeObj.shape&&n.activeObj.rotationCirclePointColl&&(n.activeObj.rotationCirclePointColl.x-=b,n.activeObj.rotationCirclePointColl.y-=m,n.activeObj.rotationCirclePoint.x-=b,n.activeObj.rotationCirclePoint.y-=m),this.setDragWidth(b),this.setDragHeight(m))}else C.startX=e<this.mouseDownPoint.x?e:this.mouseDownPoint.x,C.startY=t<this.mouseDownPoint.y?t:this.mouseDownPoint.y,e=e<this.mouseDownPoint.x?this.mouseDownPoint.x:e,t=t<this.mouseDownPoint.y?this.mouseDownPoint.y:t,C.endX=e,C.endY=t;this.triggerShapeChange(d,c,"move")}}},c.prototype.triggerShapeChange=function(e,t,o){var i=this.parent,r=i.activeObj.activePoint,r=(r.width=r.endX-r.startX,r.height=r.endY-r.startY,this.updatePrevShapeSettings());O.isNullOrUndefined(this.shapeResizingArgs)||O.isNullOrUndefined(this.shapeMovingArgs)?(e.currentShapeSettings=r,t.currentShapeSettings=r):(e.currentShapeSettings=this.shapeResizingArgs.currentShapeSettings=r,t.currentShapeSettings=this.shapeMovingArgs.currentShapeSettings=r),"resize"===o?(this.isCropSelection=!1,(r=void 0)!==(r=void 0!==i.activeObj.shape?i.activeObj.shape.split("-"):r)&&"crop"===r[0]&&(this.isCropSelection=!0),this.isCropSelection?(r={action:e.action,previousSelectionSettings:{type:i.getSelectionType(i.activeObj.shape),startX:e.previousShapeSettings.startX,startY:e.previousShapeSettings.startY,width:e.previousShapeSettings.width,height:e.previousShapeSettings.height},currentSelectionSettings:{type:i.getSelectionType(i.activeObj.shape),startX:e.currentShapeSettings.startX,startY:e.currentShapeSettings.startY,width:e.currentShapeSettings.width,height:e.currentShapeSettings.height}},this.selectionResizingArgs=r,i.trigger("selectionChanging",r),i.notify("shape",{prop:"updSelChangeEventArgs",onPropertyChange:!1,value:{selectionSettings:r.currentSelectionSettings}})):(""!==this.currentDrawingShape&&"crosshair"===i.upperCanvas.style.cursor&&(e.action="drawing"),i.trigger("shapeChanging",e),this.isPreventShaping=e.cancel,i.notify("shape",{prop:"updateShapeChangeEventArgs",onPropertyChange:!1,value:{shapeSettings:e.currentShapeSettings}}))):"mouse-down"===o||"mouse-up"===o?(i.trigger("shapeChanging",e),this.isPreventShaping=e.cancel,i.notify("shape",{prop:"updateShapeChangeEventArgs",onPropertyChange:!1,value:{shapeSettings:e.currentShapeSettings}})):(i.trigger("shapeChanging",t),this.isPreventShaping=t.cancel,i.notify("shape",{prop:"updateShapeChangeEventArgs",onPropertyChange:!1,value:{shapeSettings:t.currentShapeSettings}})),i.eventType=o},c.prototype.setDragWidth=function(e){var t=this.parent,o=t.activeObj.activePoint,t=t.img,i=t.destLeft,r=t.destWidth,n=e;if(0<=n)for(var a=0;a<n&&(o.startX+=e=n-a,o.endX+=e,!(o.startX>=i&&o.endX<=i+r));a++)o.startX-=e,o.endX-=e;else for(a=1;a<Math.abs(n)&&(o.startX+=e=n+a,o.endX+=e,!(o.startX>=i&&o.endX<=i+r));a++)o.startX-=e,o.endX-=e},c.prototype.setDragHeight=function(e){var t=this.parent,o=t.activeObj.activePoint,t=t.img,i=t.destTop,r=t.destHeight,n=e;if(0<=n)for(var a=1;a<n&&(o.startY+=e=n-a,o.endY+=e,!(o.startY>=i&&o.endY<=i+r));a++)o.startY-=e,o.endY-=e;else for(a=0;a<Math.abs(n)&&(o.startY+=e=n+a,o.endY+=e,!(o.startY>=i&&o.endY<=i+r));a++)o.startY-=e,o.endY-=e},c.prototype.limitDrag=function(e){var t=!1,o=this.parent,i=o.img,r=i.destLeft,n=i.destTop,a=i.destWidth,i=i.destHeight,s=o.activeObj.activePoint,l=e?s.startX:s.endX,p=e?s.startY:s.endY,h=e?s.endX:s.startX,d=e?s.endY:s.startY;return l<r&&(l=r),p<n&&(p=n),r+a<h&&(h=r+a),n+i<d&&(d=n+i),0!==o.transform.straighten&&(o.notify("draw",{prop:"updateImgCanvasPoints",onPropertyChange:!(r={isIntersect:null,arr:null})}),o.notify("draw",{prop:"isLinesIntersect",onPropertyChange:!1,value:{obj:r}}),r.arr[0]||r.arr[1]||r.arr[2]||r.arr[3])&&(t=!0),e?(s.startX=l,s.startY=p,s.endX=h,s.endY=d):(s.startX=h,s.startY=d,s.endX=l,s.endY=p),t},c.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},c.prototype.preventDraggingInvertly=function(){var e=!1,t=this.parent;return"image"===t.activeObj.shape||this.isPreventDragging||0!==t.activeObj.rotatedAngle||(e=this.limitDrag(!0),-1<["line","arrow","path"].indexOf(t.activeObj.shape)&&(e=this.limitDrag(!1))),e},c.prototype.preventTextDraggingInvertly=function(){var e=this.parent,t=!1,o=e.activeObj.activePoint,e=e.img,i=e.destLeft,r=e.destTop,n=e.destWidth,e=e.destHeight;return this.isPreventDragging||(o.startX<i||o.startY<r||o.endX>i+n||o.endY>r+e)&&(t=!0),t},c.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)},c.prototype.getScaleRatio=function(e){var t,o=this.parent,i={x:e,y:e};return o.activeObj.shape&&"crop-custom"!==o.activeObj.shape&&"crop-circle"!==o.activeObj.shape&&"crop-square"!==o.activeObj.shape&&(1<(t=("image"===o.activeObj.shape||"text"===o.activeObj.shape?this.findImageRatio(o.activeObj.activePoint.width,o.activeObj.activePoint.height):o.activeObj.shape).split("-")).length||"image"===o.activeObj.shape||"text"===o.activeObj.shape)&&(t=("image"===o.activeObj.shape||"text"===o.activeObj.shape?t[0]:t[1]).split(":"),o=e/parseInt(t[1],10),i.x=o*parseInt(t[0],10),i.y=o*parseInt(t[1],10)),i},c.prototype.findImageRatio=function(e,t,o){function i(e,t){return 0===t?e:i(t,e%t)}var r=i(e,t),e=e/r+":"+t/r;return o&&(o.ratio=e),e},c.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)},c.prototype.performSEResize=function(e,t,o,i){var r,n=this.parent;this.resizeImg(e,t,"se-resize",o),i.endX<i.startX&&(r=i.endX,i.endX=i.startX,i.startX=r,this.dragElement=n.upperCanvas.style.cursor=n.cursor="sw-resize"),i.endY<i.startY&&(r=i.endY,i.endY=i.startY,i.startY=r,this.dragElement=n.upperCanvas.style.cursor=n.cursor="ne-resize"),this.revertCustomSelection(i,o,"se-resize"),this.revertResizing(o)},c.prototype.performNWResize=function(e,t,o,i){var r,n=this.parent;this.resizeImg(e,t,"nw-resize",o),i.startX>i.endX&&(r=i.startX,i.startX=i.endX,i.endX=r,this.dragElement=n.upperCanvas.style.cursor=n.cursor="ne-resize"),i.startY>i.endY&&(r=i.startY,i.startY=i.endY,i.endY=r,this.dragElement=n.upperCanvas.style.cursor=n.cursor="sw-resize"),this.revertCustomSelection(i,o,"nw-resize"),this.revertResizing(o)},c.prototype.isCustomSelection=function(){return!!this.parent.activeObj.shape&&-1<this.parent.activeObj.shape.indexOf("crop-")&&-1===["custom","circle","square","2:3","3:2","3:4","4:3","4:5","5:4","5:7","7:5","9:16","16:9"].indexOf(this.parent.activeObj.shape.split("-")[1])},c.prototype.revertCustomSelection=function(e,t,o){var i,r,n,a,s=this.parent;this.isCustomSelection()&&(i=(a=s.img).destLeft,r=a.destTop,n=a.destWidth,a=a.destHeight,n=i+n<s.lowerCanvas.width?i+n:s.lowerCanvas.width,a=r+a<s.lowerCanvas.height?r+a:s.lowerCanvas.height,"se-resize"===o&&(e.endX>n||e.endY>a)||"nw-resize"===o&&(e.startX<(0<i?i:0)||e.startY<(0<r?r:0))||"ne-resize"===o&&(e.endX>n||e.startY<(0<r?r:0))||"sw-resize"===o&&(e.startX<(0<i?i:0)||e.endY>a))&&this.revertPoints(e,t)},c.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},c.prototype.updateNWPoints=function(e,t){var o,i,r,n,a,s,l=this.parent,p=l.activeObj.activePoint,h=O.extend({},l.activeObj,null,!0);"text"===l.activeObj.shape?(this.resizeImg(e,t,"nw-resize",h),l.notify("shape",{prop:"updateFontSize",onPropertyChange:!1,value:{obj:l.activeObj}})):((o=void 0)!==l.activeObj.shape&&(o=l.activeObj.shape.split("-")),"crop-custom"===l.activeObj.shape||void 0!==l.activeObj.shape&&"crop"!==o[0]||this.isCustomSelection()?("image"===l.activeObj.shape||this.isCustomSelection()?this.resizeImg(e,t,"nw-resize",h):this.adjustNWPoints(p,e,t,l.activeObj.rotatedAngle),p.startX>p.endX&&(i=p.startX,p.startX=p.endX,p.endX=i,this.dragElement=l.upperCanvas.style.cursor=l.cursor="ne-resize"),p.startY>p.endY&&(i=p.startY,p.startY=p.endY,p.endY=i,this.dragElement=l.upperCanvas.style.cursor=l.cursor="sw-resize"),this.revertCustomSelection(p,h,"nw-resize")):(i=(o=l.img).destLeft,l=o.destTop,p.startX<e&&p.startY<t?(r=e-p.startX,n=t-p.startY,a=Math.min(r,n),s=this.getScaleRatio(a),p.startX+=s.x,p.startY+=s.y,(p.startX<(0<i?i:0)||p.startY<(0<l?l:0))&&(p.startX-=s.x,p.startY-=s.y)):(r=p.startX-e,n=t-p.endY,a=Math.max(r,n),s=this.getScaleRatio(a),p.startX-=s.x,p.startY-=s.y,(p.startX<(0<i?i:0)||p.startY<(0<l?l:0))&&(p.startX+=s.x,p.startY+=s.y)),p.width=p.endX-p.startX,p.height=p.endY-p.startY),this.revertResizing(h),p.width=p.endX-p.startX,p.height=p.endY-p.startY,this.preventInverseResize(h))},c.prototype.updateNPoints=function(e,t){var o,i,r,n,a,s,l=this.parent,p=l.activeObj.activePoint,h=O.extend({},l.activeObj,null,!0);"text"!==l.activeObj.shape&&(i=void 0,l.activeObj.shape&&(i=l.activeObj.shape.split("-")),"crop-custom"===l.activeObj.shape||l.activeObj.shape&&"crop"!==i[0]?("line"!==l.activeObj.shape&&"arrow"!==l.activeObj.shape&&"path"!==l.activeObj.shape&&0!==l.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=t),r=this.dragPoint.endX-this.previousPoint.x,n=this.dragPoint.endY-this.previousPoint.y,this.adjustRotationPoints(p,r,n,l.activeObj.rotatedAngle)):(p.startY=t,p.height=p.endY-p.startY),p.startY>p.endY&&(i=p.startY,p.startY=p.endY,p.endY=i,this.dragElement=this.resizedElement="s-resize")):(l=(i=l.img).destLeft,o=i.destTop,i=i.destWidth,this.isCustomSelection()?this.performNWResize(e,t,h,p):p.endX>e&&p.startY<t?(r=p.endX-e,n=t-p.startY,a=Math.min(r,n),s=this.getScaleRatio(a),p.endX-=s.x,p.startY+=s.y,(p.endX>l+i||p.startY<o)&&(p.endX+=s.x,p.startY-=s.y)):(r=e-p.endX,n=p.startY-t,a=Math.max(r,n),s=this.getScaleRatio(a),p.endX+=s.x,p.startY-=s.y,(p.endX>l+i||p.startY<o)&&(p.endX-=s.x,p.startY+=s.y)),p.width=p.endX-p.startX,p.height=p.endY-p.startY),this.revertResizing(h))},c.prototype.updateNEPoints=function(e,t){var o,i,r,n,a,s,l,p,h,d=this.parent,c=d.activeObj.activePoint,u=O.extend({},d.activeObj,null,!0);"text"===d.activeObj.shape?(this.resizeImg(e,t,"ne-resize",u),d.notify("shape",{prop:"updateFontSize",onPropertyChange:!1,value:{obj:d.activeObj}})):(r=void 0,d.activeObj.shape&&(r=d.activeObj.shape.split("-")),"crop-custom"===d.activeObj.shape||void 0!==d.activeObj.shape&&"crop"!==r[0]||this.isCustomSelection()?("image"===d.activeObj.shape||this.isCustomSelection()?this.resizeImg(e,t,"ne-resize",u):this.adjustNEPoints(c,e,t,d.activeObj.rotatedAngle),c.endX<c.startX&&(o=c.endX,c.endX=c.startX,c.startX=o,this.dragElement=d.upperCanvas.style.cursor=d.cursor="nw-resize"),c.startY>c.endY&&(o=c.startY,c.startY=c.endY,c.endY=o,this.dragElement=d.upperCanvas.style.cursor=d.cursor="se-resize"),this.revertCustomSelection(c,u,"ne-resize")):(o=(r=d.img).destLeft,i=r.destTop,r=r.destWidth,c.endX>e&&c.startY<t?(n=c.endX-e,a=t-c.startY,s=Math.min(n,a),l=this.getScaleRatio(s),c.endX-=l.x,c.startY+=l.y,p=o+r<d.lowerCanvas.width?o+r:d.lowerCanvas.width,h=0<i?i:0,(c.endX>p||c.startY<h)&&(c.endX+=l.x,c.startY-=l.y)):(n=e-c.endX,a=c.startY-t,s=Math.max(n,a),l=this.getScaleRatio(s),c.endX+=l.x,c.startY-=l.y,p=o+r<d.lowerCanvas.width?o+r:d.lowerCanvas.width,h=0<i?i:0,(c.endX>p||c.startY<h)&&(c.endX-=l.x,c.startY+=l.y)),c.width=c.endX-c.startX,c.height=c.endY-c.startY),this.revertResizing(u),c.width=c.endX-c.startX,c.height=c.endY-c.startY,this.preventInverseResize(u))},c.prototype.updateWPoints=function(e,t){var o,i,r,n,a,s,l=this.parent,p=l.activeObj.activePoint,h=O.extend({},l.activeObj,null,!0);"text"!==l.activeObj.shape&&(i=void 0,l.activeObj.shape&&(i=l.activeObj.shape.split("-")),"crop-custom"===l.activeObj.shape||l.activeObj.shape&&"crop"!==i[0]?("line"!==l.activeObj.shape&&"arrow"!==l.activeObj.shape&&"path"!==l.activeObj.shape&&0!==l.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=t),r=this.dragPoint.endX-this.previousPoint.x,n=this.dragPoint.endY-this.previousPoint.y,this.adjustRotationPoints(p,r,n,l.activeObj.rotatedAngle)):(p.startX=e,p.width=p.endX-p.startX),"line"===l.activeObj.shape||"arrow"===l.activeObj.shape||"path"===l.activeObj.shape?(p.startY=t,p.height=p.endY-p.startY,this.adjustActObjForLineArrow()&&(this.dragElement="e-resize","right"===l.activeObj.triangleDirection?l.activeObj.triangleDirection="left":"left"===l.activeObj.triangleDirection&&(l.activeObj.triangleDirection="right"))):p.startX>p.endX&&(i=p.startX,p.startX=p.endX,p.endX=i,this.dragElement=this.resizedElement="e-resize")):(l=(i=l.img).destLeft,o=i.destTop,i=i.destHeight,this.isCustomSelection()?this.performNWResize(e,t,h,p):p.startX<e&&p.endY>t?(r=e-p.startX,n=p.endY-t,a=Math.min(r,n),s=this.getScaleRatio(a),p.startX+=s.x,p.endY-=s.y,(p.startX<l||p.endY>o+i)&&(p.startX-=s.x,p.endY+=s.y)):(r=p.startX-e,n=t-p.endY,a=Math.max(r,n),s=this.getScaleRatio(a),p.startX-=s.x,p.endY+=s.y,(p.startX<l||p.endY>o+i)&&(p.startX+=s.x,p.endY-=s.y)),p.width=p.endX-p.startX,p.height=p.endY-p.startY),this.revertResizing(h))},c.prototype.updateEPoints=function(e,t){var o,i,r,n,a,s,l,p=this.parent,h=p.activeObj.activePoint,d=O.extend({},p.activeObj,null,!0);"text"!==p.activeObj.shape&&(r=void 0,p.activeObj.shape&&(r=p.activeObj.shape.split("-")),"crop-custom"===p.activeObj.shape||p.activeObj.shape&&"crop"!==r[0]?("line"!==p.activeObj.shape&&"arrow"!==p.activeObj.shape&&"path"!==p.activeObj.shape&&0!==p.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=t),n=this.dragPoint.endX-this.previousPoint.x,a=this.dragPoint.endY-this.previousPoint.y,this.adjustRotationPoints(h,n,a,p.activeObj.rotatedAngle)):(h.endX=e,h.width=h.endX-h.startX),"line"===p.activeObj.shape||"arrow"===p.activeObj.shape||"path"===p.activeObj.shape?(h.endY=t,h.height=h.endY-h.startY,this.adjustActObjForLineArrow()&&(this.dragElement="w-resize","right"===p.activeObj.triangleDirection?p.activeObj.triangleDirection="left":"left"===p.activeObj.triangleDirection&&(p.activeObj.triangleDirection="right"))):h.endX<h.startX&&(r=h.endX,h.endX=h.startX,h.startX=r,this.dragElement=this.resizedElement="w-resize")):(p=(r=p.img).destLeft,o=r.destTop,i=r.destWidth,r=r.destHeight,this.isCustomSelection()?this.performSEResize(e,t,d,h):h.endX>e&&h.endY>t?(n=h.endX-e,a=h.endY-t,s=Math.min(n,a),l=this.getScaleRatio(s),h.endX-=l.x,h.endY-=l.y,(h.endX>p+i||h.endY>o+r)&&(h.endX+=l.x,h.endY+=l.y)):(n=e-h.endX,a=t-h.endY,s=Math.max(n,a),l=this.getScaleRatio(s),h.endX+=l.x,h.endY+=l.y,(h.endX>p+i||h.endY>o+r)&&(h.endX-=l.x,h.endY-=l.y)),h.width=h.endX-h.startX,h.height=h.endY-h.startY),this.revertResizing(d))},c.prototype.updateSWPoints=function(e,t){var o,i,r,n,a,s,l,p,h=this.parent,d=h.activeObj.activePoint,c=O.extend({},h.activeObj,null,!0);"text"===h.activeObj.shape?(this.resizeImg(e,t,"sw-resize",c),h.notify("shape",{prop:"updateFontSize",onPropertyChange:!1,value:{obj:h.activeObj}})):((r=void 0)!==h.activeObj.shape&&(r=h.activeObj.shape.split("-")),"crop-custom"===h.activeObj.shape||void 0!==h.activeObj.shape&&"crop"!==r[0]||this.isCustomSelection()?("image"===h.activeObj.shape||this.isCustomSelection()?this.resizeImg(e,t,"sw-resize",c):this.adjustSWPoints(d,e,t,h.activeObj.rotatedAngle),d.startX>d.endX&&(o=d.startX,d.startX=d.endX,d.endX=o,this.dragElement=h.upperCanvas.style.cursor=h.cursor="se-resize"),d.endY<d.startY&&(o=d.endY,d.endY=d.startY,d.startY=o,this.dragElement=h.upperCanvas.style.cursor=h.cursor="nw-resize"),this.revertCustomSelection(d,c,"sw-resize")):(o=(r=h.img).destLeft,i=r.destTop,r=r.destHeight,d.startX<e&&d.endY>t?(n=e-d.startX,a=d.endY-t,s=Math.min(n,a),l=this.getScaleRatio(s),d.startX+=l.x,d.endY-=l.y,p=i+r<h.lowerCanvas.height?i+r:h.lowerCanvas.height,(d.startX<(0<o?o:0)||d.endY>p)&&(d.startX-=l.x,d.endY+=l.y)):(n=d.startX-e,a=t-d.endY,s=Math.max(n,a),l=this.getScaleRatio(s),d.startX-=l.x,d.endY+=l.y,p=i+r<h.lowerCanvas.height?i+r:h.lowerCanvas.height,(d.startX<(0<o?o:0)||d.endY>p)&&(d.startX+=l.x,d.endY-=l.y)),d.width=d.endX-d.startX,d.height=d.endY-d.startY),this.revertResizing(c),d.width=d.endX-d.startX,d.height=d.endY-d.startY,this.preventInverseResize(c))},c.prototype.updateSPoints=function(e,t){var o,i,r,n,a,s,l,p=this.parent,h=p.activeObj.activePoint,d=O.extend({},p.activeObj,null,!0);"text"!==p.activeObj.shape&&(r=void 0,p.activeObj.shape&&(r=p.activeObj.shape.split("-")),"crop-custom"===p.activeObj.shape||p.activeObj.shape&&"crop"!==r[0]?("line"!==p.activeObj.shape&&"arrow"!==p.activeObj.shape&&"path"!==p.activeObj.shape&&0!==p.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=t),n=this.dragPoint.endX-this.previousPoint.x,a=this.dragPoint.endY-this.previousPoint.y,this.adjustRotationPoints(h,n,a,p.activeObj.rotatedAngle)):(h.endY=t,h.height=h.endY-h.startY),h.endY<h.startY&&(r=h.endY,h.endY=h.startY,h.startY=r,this.dragElement=this.resizedElement="n-resize")):(p=(r=p.img).destLeft,o=r.destTop,i=r.destWidth,r=r.destHeight,this.isCustomSelection()?this.performSEResize(e,t,d,h):h.endX>e&&h.endY>t?(n=h.endX-e,a=h.endY-t,s=Math.min(n,a),l=this.getScaleRatio(s),h.endX-=l.x,h.endY-=l.y,(h.endX>p+i||h.endY>o+r)&&(h.endX+=l.x,h.endY+=l.y)):(n=e-h.endX,a=t-h.endY,s=Math.max(n,a),l=this.getScaleRatio(s),h.endX+=l.x,h.endY+=l.x,(h.endX>p+i||h.endY>o+r)&&(h.endX-=l.x,h.endY-=l.y)),h.width=h.endX-h.startX,h.height=h.endY-h.startY),this.revertResizing(d))},c.prototype.updateSEPoints=function(e,t){var o,i,r,n,a,s,l,p,h,d,c=this.parent,u=c.activeObj.activePoint,g=O.extend({},c.activeObj,null,!0);"text"===c.activeObj.shape?(this.resizeImg(e,t,"se-resize",g),c.notify("shape",{prop:"updateFontSize",onPropertyChange:!1,value:{obj:c.activeObj}})):((n=p=void 0)!==c.activeObj.shape&&(p=c.activeObj.shape.split("-")),"crop-custom"===c.activeObj.shape||void 0!==c.activeObj.shape&&"crop"!==p[0]||this.isCustomSelection()?("image"===c.activeObj.shape||this.isCustomSelection()?this.resizeImg(e,t,"se-resize",g):this.adjustSEPoints(u,e,t,c.activeObj.rotatedAngle),u.endX<u.startX&&(a=u.endX,u.endX=u.startX,u.startX=a,this.dragElement=c.upperCanvas.style.cursor=c.cursor="sw-resize"),u.endY<u.startY&&(a=u.endY,u.endY=u.startY,u.startY=a,this.dragElement=c.upperCanvas.style.cursor=c.cursor="ne-resize"),this.revertCustomSelection(u,g,"se-resize")):(a=(p=c.img).destLeft,s=p.destTop,l=p.destWidth,p=p.destHeight,u.endX>e&&u.endY>t?(o=u.endX-e,i=u.endY-t,r=Math.min(o,i),n=this.getScaleRatio(r),u.endX-=n.x,u.endY-=n.y,h=a+l<c.lowerCanvas.width?a+l:c.lowerCanvas.width,d=s+p<c.lowerCanvas.height?s+p:c.lowerCanvas.height,(u.endX>h||u.endY>d)&&(u.endX+=n.x,u.endY+=n.y)):(o=e-u.endX,i=t-u.endY,r=Math.max(o,i),n=this.getScaleRatio(r),u.endX+=n.x,u.endY+=n.y,h=a+l<c.lowerCanvas.width?a+l:c.lowerCanvas.width,d=s+p<c.lowerCanvas.height?s+p:c.lowerCanvas.height,(u.endX>h||u.endY>d)&&(u.endX-=n.x,u.endY-=n.y)),u.width=u.endX-u.startX,u.height=u.endY-u.startY),this.revertResizing(g),this.preventInverseResize(g))},c.prototype.resizeImg=function(e,t,o,i){var r,n,a,s,l=this.parent,p=l.activeObj.activePoint;if(0!==this.previousPoint.x&&0!==this.previousPoint.y){switch("text"===this.currentDrawingShape&&(this.setCursor(e,t),0===l.activeObj.textSettings.fontSize)&&(l.activeObj.textSettings.fontSize=11,l.notify("shape",{prop:"updateFontRatio",onPropertyChange:!1,value:{obj:l.activeObj,isTextArea:null}}),l.activeObj.textSettings.text=l.activeObj.keyHistory="Enter Text",l.notify("shape",{prop:"updateFontStyles",onPropertyChange:!1,value:{isTextBox:null}}),s=this.upperContext.measureText(l.activeObj.textSettings.text).width+.5*l.activeObj.textSettings.fontSize,p.endX=p.startX+s,p.endY=p.startY+l.activeObj.textSettings.fontSize,p.width=p.endX-p.startX,p.height=p.endY-p.startY,i=O.extend({},l.activeObj,null,!0),l.notify("draw",{prop:"updateActiveObject",onPropertyChange:!1,value:{actPoint:l.activeObj.activePoint,obj:l.activeObj,isMouseMove:null,x:null,y:null}})),l.upperCanvas.style.cursor){case"se-resize":case"s-resize":this.previousPoint.x>e||this.previousPoint.y>t?(r=this.previousPoint.x-e,n=this.previousPoint.y-t,a=this.getScaleRatio((r+n)/2),this.adjustRotationPoints(p,-Math.abs(a.x),-Math.abs(a.y),l.activeObj.rotatedAngle,"img-resize",o)):0!==this.previousPoint.x&&0!==this.previousPoint.y&&(r=e-this.previousPoint.x,n=t-this.previousPoint.y,a=this.getScaleRatio((r+n)/2),this.adjustRotationPoints(p,Math.abs(a.x),Math.abs(a.y),l.activeObj.rotatedAngle,"img-resize",o));break;case"sw-resize":this.previousPoint.x<e||this.previousPoint.y>t?(r=e-this.previousPoint.x,n=this.previousPoint.y-t,a=this.getScaleRatio((r+n)/2),this.adjustRotationPoints(p,-Math.abs(a.x),-Math.abs(a.y),l.activeObj.rotatedAngle,"img-resize",o)):0!==this.previousPoint.x&&0!==this.previousPoint.y&&(r=this.previousPoint.x-e,n=t-this.previousPoint.y,a=this.getScaleRatio((r+n)/2),this.adjustRotationPoints(p,Math.abs(a.x),Math.abs(a.y),l.activeObj.rotatedAngle,"img-resize",o));break;case"w-resize":case"nw-resize":this.previousPoint.x<e||this.previousPoint.y<t?(r=e-this.previousPoint.x,n=t-this.previousPoint.y,a=this.getScaleRatio((r+n)/2),this.adjustRotationPoints(p,-Math.abs(a.x),-Math.abs(a.y),l.activeObj.rotatedAngle,"img-resize",o)):0!==this.previousPoint.x&&0!==this.previousPoint.y&&(r=this.previousPoint.x-e,n=this.previousPoint.y-t,a=this.getScaleRatio((r+n)/2),this.adjustRotationPoints(p,Math.abs(a.x),Math.abs(a.y),l.activeObj.rotatedAngle,"img-resize",o));break;case"n-resize":case"ne-resize":this.previousPoint.x>e||this.previousPoint.y<t?(r=this.previousPoint.x-e,n=t-this.previousPoint.y,a=this.getScaleRatio((r+n)/2),this.adjustRotationPoints(p,-Math.abs(a.x),-Math.abs(a.y),l.activeObj.rotatedAngle,"img-resize",o)):0!==this.previousPoint.x&&0!==this.previousPoint.y&&(r=e-this.previousPoint.x,n=this.previousPoint.y-t,a=this.getScaleRatio((r+n)/2),this.adjustRotationPoints(p,Math.abs(a.x),Math.abs(a.y),l.activeObj.rotatedAngle,"img-resize",o));break;case"e-resize":this.previousPoint.x>e||this.previousPoint.y>t?(r=this.previousPoint.x-e,n=this.previousPoint.y-t,a=this.getScaleRatio((r+n)/2),this.adjustRotationPoints(p,-Math.abs(a.x),-Math.abs(a.y),l.activeObj.rotatedAngle,"img-resize",o)):0!==this.previousPoint.x&&0!==this.previousPoint.y&&(r=e-this.previousPoint.x,n=t-this.previousPoint.y,a=this.getScaleRatio((r+n)/2),this.adjustRotationPoints(p,Math.abs(a.x),Math.abs(a.y),l.activeObj.rotatedAngle,"img-resize",o))}p.width=p.endX-p.startX,p.height=p.endY-p.startY,(p.width<10||p.height<10||"text"===l.activeObj.shape&&0===l.activeObj.rotatedAngle&&this.preventTextDraggingInvertly())&&(l.activeObj=O.extend({},i,null,!0))}this.previousPoint={x:e,y:t}},c.prototype.adjustNWPoints=function(e,t,o,i){var r=e.startX+e.width/2,n=e.startY+e.height/2,r=this.rotatePoints(e.endX,e.endY,r,n,i),n=[(r[0]+t)/2,(r[1]+o)/2],r=this.rotatePoints(r[0],r[1],n[0],n[1],-i),t=this.rotatePoints(t,o,n[0],n[1],-i);return e.endX=r[0],e.endY=r[1],e.startY=t[1],e.startX=t[0],e.width=e.endX-e.startX,e.height=e.endY-e.startY,e},c.prototype.adjustNEPoints=function(e,t,o,i){var r=e.startX+e.width/2,n=e.startY+e.height/2,r=this.rotatePoints(e.startX,e.endY,r,n,i),n=[(r[0]+t)/2,(r[1]+o)/2],r=this.rotatePoints(r[0],r[1],n[0],n[1],-i),t=this.rotatePoints(t,o,n[0],n[1],-i);return e.startX=r[0],e.endY=r[1],e.width=t[0]-r[0],e.height=r[1]-t[1],e.endX=e.startX+e.width,e.startY=e.endY-e.height,e},c.prototype.adjustSWPoints=function(e,t,o,i){var r=e.startX+e.width/2,n=e.startY+e.height/2,r=this.rotatePoints(e.endX,e.startY,r,n,i),n=[(r[0]+t)/2,(r[1]+o)/2],r=this.rotatePoints(r[0],r[1],n[0],n[1],-i),t=this.rotatePoints(t,o,n[0],n[1],-i);return e.endX=r[0],e.startY=r[1],e.startX=t[0],e.endY=t[1],e.width=e.endX-e.startX,e.height=e.endY-e.startY,e},c.prototype.adjustSEPoints=function(e,t,o,i){var r=e.startX+e.width/2,n=e.startY+e.height/2,r=this.rotatePoints(e.startX,e.startY,r,n,i),n=[(r[0]+t)/2,(r[1]+o)/2],r=this.rotatePoints(r[0],r[1],n[0],n[1],-i),t=this.rotatePoints(t,o,n[0],n[1],-i);return e.startX=r[0],e.startY=r[1],e.width=t[0]-r[0],e.height=t[1]-r[1],e.endX=e.startX+e.width,e.endY=e.startY+e.height,e},c.prototype.adjustRotationPoints=function(e,t,o,i,r,n){var a=e.startX+e.width/2,s=e.startY+e.height/2,t=(this.getResizeDirection(e,t,o,i,r,n),this.rotatePoints(e.startX,e.startY,a,s,i)),o=this.rotatePoints(e.endX,e.startY,a,s,i),r=this.rotatePoints(e.endX,e.endY,a,s,i),n=this.rotatePoints(e.startX,e.endY,a,s,i),a=[(t[0]+r[0])/2,(t[1]+r[1])/2],s=this.rotatePoints(t[0],t[1],a[0],a[1],-i),r=this.rotatePoints(n[0],n[1],a[0],a[1],-i),t=this.rotatePoints(o[0],o[1],a[0],a[1],-i);return e.startX=s[0],e.startY=s[1],e.endX=t[0],e.endY=r[1],e.width=e.endX-e.startX,e.height=e.endY-e.startY,e},c.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]},c.prototype.setResizedValue=function(e,t,o,i){switch(e){case"x":t+=o;break;case"y":t+=i;break;case"abs-x":t+=0<o?-o:Math.abs(o);break;case"abs-y":t+=0<i?-i:Math.abs(i);break;case"y-abs-x":t+=i+(0<o?-o:Math.abs(o))/2;break;case"abs-x-abs-y":t+=(0<o?-o:Math.abs(o))+(0<i?-i:Math.abs(i))/2;break;case"abs-y-x":t+=(0<i?-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},c.prototype.getResizeDirection=function(e,t,o,i,r,n){i*=180/Math.PI,i=this.getResizedElement(i,this.resizedElement);"e-resize"===this.resizedElement?(e.width=this.setResizedValue(i,e.width,t,o),e.endX=e.width+e.startX):"n-resize"===this.resizedElement?(e.startY=this.setResizedValue(i,e.startY,t,o),e.height=e.endY-e.startY):"w-resize"===this.resizedElement?(e.startX=this.setResizedValue(i,e.startX,t,o),e.width=e.startX+e.endX):"s-resize"===this.resizedElement?(e.height=this.setResizedValue(i,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"===n?(e.endX=e.width+e.startX,e.endY=e.height+e.startY):"sw-resize"===n?(e.startX=e.endX-e.width,e.endY=e.height+e.startY):"ne-resize"===n?(e.endX=e.width+e.startX,e.startY=e.endY-e.height):"nw-resize"===n&&(e.startX=e.endX-e.width,e.startY=e.endY-e.height)):r&&"text"===r&&("widthHeight"===n?(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"===n?(e.width=this.setResizedValue("x-y",e.width,t,o),e.endX=e.width+e.startX):"height"===n&&(e.height=this.setResizedValue("y-abs-x",e.height,t,o),e.endY=e.height+e.startY))},c.prototype.getResizedElement=function(e,t){for(var o=[],i=("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"]]),e<0?360-Math.abs(e):e),r=0,n=o;r<n.length;r++){var a=n[r],s=a[0],l=a[1],a=a[2];if(s<i&&i<=l||s<i+360&&i+360<=l)return a}return t},c.prototype.updateCursorStyles=function(e,t,o){var i,r,n=this.parent,a=!1,s=(""===n.activeObj.keyHistory||void 0!==n.activeObj.shape||n.currObjType.isCustomCrop||n.currObjType.isLine||!n.currObjType.isText||(n.activeObj.shape="text"),O.extend({},n.activeObj,{},!0));O.isNullOrUndefined(s.topLeftCircle)||((0===s.shapeDegree?n.transform.degree:n.transform.degree-s.shapeDegree)<0&&0,this.isObjSelected?"line"===s.shape||"arrow"===s.shape?a=this.updateCursorStylesForLineArrow(e,t,s):"path"===s.shape?a=this.updateCursorStylesForPath(e,t,s):s.rotatedAngle?(this.setCursorForRotatedObject(s,e,t,n.upperCanvas),"grabbing"===n.cursor?(n.upperCanvas.style.cursor=n.cursor="grabbing",this.dragElement=n.cursor):"move"===n.cursor?(this.dragPoint.startX=this.previousPoint.x=this.dragPoint.endX=e,this.dragPoint.startY=this.previousPoint.y=this.dragPoint.endY=t):"default"!==n.cursor&&(a=!0,this.dragElement=n.cursor,n.currObjType.isResize=!0)):(i=this.getTransRotationPoint(s),r=s.topLeftCircle.radius,e>=s.topLeftCircle.startX-2*r&&e<=s.topLeftCircle.startX+2*r&&t>=s.topLeftCircle.startY-2*r&&t<=s.topLeftCircle.startY+2*r&&"nw-resize"!==this.dragElement?(s.topLeftCircle.startX=s.topLeftCircle.startY=0,n.upperCanvas.style.cursor=n.cursor="nw-resize",a=!0,this.dragElement=n.upperCanvas.style.cursor):e>=s.topLeftCircle.startX-2*r&&e<=s.topRightCircle.startX-2*r&&t>=s.topCenterCircle.startY-2*r&&t<=s.topCenterCircle.startY+2*r&&"n-resize"!==this.dragElement?(s.topCenterCircle.startX=s.topCenterCircle.startY=0,n.upperCanvas.style.cursor=n.cursor="n-resize",a=!0,this.dragElement=n.upperCanvas.style.cursor):e>=s.topRightCircle.startX-2*r&&e<=s.topRightCircle.startX+2*r&&t>=s.topRightCircle.startY-2*r&&t<=s.topRightCircle.startY+2*r&&"ne-resize"!==this.dragElement?(s.topRightCircle.startX=s.topRightCircle.startY=0,n.upperCanvas.style.cursor=n.cursor="ne-resize",a=!0,this.dragElement=n.upperCanvas.style.cursor):e>=s.centerLeftCircle.startX-2*r&&e<=s.centerLeftCircle.startX+2*r&&t>=s.topLeftCircle.startY-2*r&&t<=s.bottomLeftCircle.startY-2*r&&"w-resize"!==this.dragElement?(s.centerLeftCircle.startX=s.centerLeftCircle.startY=0,n.upperCanvas.style.cursor=n.cursor="w-resize",a=!0,this.dragElement=n.upperCanvas.style.cursor):e>=s.centerRightCircle.startX-2*r&&e<=s.centerRightCircle.startX+2*r&&t>=s.topRightCircle.startY-2*r&&t<=s.bottomRightCircle.startY-2*r&&"e-resize"!==this.dragElement?(s.centerRightCircle.startX=s.centerRightCircle.startY=0,n.upperCanvas.style.cursor=n.cursor="e-resize",a=!0,this.dragElement=n.upperCanvas.style.cursor):e>=s.bottomLeftCircle.startX-2*r&&e<=s.bottomLeftCircle.startX+2*r&&t>=s.bottomLeftCircle.startY-2*r&&t<=s.bottomLeftCircle.startY+2*r&&"sw-resize"!==this.dragElement?(s.bottomLeftCircle.startX=s.bottomLeftCircle.startY=0,n.upperCanvas.style.cursor=n.cursor="sw-resize",a=!0,this.dragElement=n.upperCanvas.style.cursor):e>=s.bottomLeftCircle.startX-2*r&&e<=s.bottomRightCircle.startX-2*r&&t>=s.bottomCenterCircle.startY-2*r&&t<=s.bottomCenterCircle.startY+2*r&&"s-resize"!==this.dragElement?(s.bottomCenterCircle.startX=s.bottomCenterCircle.startY=0,n.upperCanvas.style.cursor=n.cursor="s-resize",a=!0,this.dragElement=n.upperCanvas.style.cursor):e>=s.bottomRightCircle.startX-2*r&&e<=s.bottomRightCircle.startX+2*r&&t>=s.bottomRightCircle.startY-2*r&&t<=s.bottomRightCircle.startY+2*r&&"se-resize"!==this.dragElement?(s.bottomRightCircle.startX=s.bottomRightCircle.startY=0,n.upperCanvas.style.cursor=n.cursor="se-resize",a=!0,this.dragElement=n.upperCanvas.style.cursor):i&&e>=i.x-2*r&&e<=i.x+2*r&&t>=i.y-2*r&&t<=i.y+2*r&&"grabbing"!==this.dragElement?(n.upperCanvas.style.cursor=n.cursor="grabbing",this.dragElement=n.upperCanvas.style.cursor):(this.dragPoint.startX=this.previousPoint.x=this.dragPoint.endX=e,this.dragPoint.startY=this.previousPoint.y=this.dragPoint.endY=t),"text"!==s.shape||"n-resize"!==n.cursor&&"s-resize"!==n.cursor&&"e-resize"!==n.cursor&&"w-resize"!==n.cursor||(n.upperCanvas.style.cursor=n.cursor="move",this.dragElement="",this.dragPoint.startX=this.previousPoint.x=this.dragPoint.endX=e,this.dragPoint.startY=this.previousPoint.y=this.dragPoint.endY=t)):(this.dragPoint.startX=this.previousPoint.x=this.dragPoint.endX=e,this.dragPoint.startY=this.previousPoint.y=this.dragPoint.endY=t),this.previousPoint.x=this.previousPoint.y=this.diffPoint.x=this.diffPoint.y=0,"touchstart"!==o||a||e>=s.activePoint.startX&&e<=s.activePoint.endX&&t>=s.activePoint.startY&&t<=s.activePoint.endY||"grabbing"===this.dragElement?n.currObjType.isDragging=!0:"line"===s.shape||"arrow"===s.shape?(this.setCursorForLineArrow(s,e,t,n.upperCanvas),"move"===n.cursor&&(n.currObjType.isDragging=!0)):"path"===s.shape&&(this.setCursorForPath(s,e,t,n.upperCanvas),"move"===n.cursor)&&(n.currObjType.isDragging=!0),0===s.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=t)},c.prototype.updateCursorStylesForLineArrow=function(e,t,o){for(var i,r=!1,n=this.parent,a=o.topLeftCircle.radius,s=0;s<5;s++)if(e>=(i=o.pointColl[s]).x-2*a&&e<=i.x+2*a&&t>=i.y-2*a&&t<=i.y+2*a){o.centerLeftCircle.startX=o.centerLeftCircle.startY=0,this.dragElement="w-resize",r=!0;break}if(!r)for(s=1;s<6;s++)if(e>=(i=o.pointColl[o.pointColl.length-s]).x-2*a&&e<=i.x+2*a&&t>=i.y-2*a&&t<=i.y+2*a){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(e>=(i=o.pointColl[s]).x-2*a&&e<=i.x+2*a&&t>=i.y-2*a&&t<=i.y+2*a){n.upperCanvas.style.cursor=n.cursor="move",this.dragPoint.startX=this.previousPoint.x=this.dragPoint.endX=e,this.dragPoint.startY=this.previousPoint.y=this.dragPoint.endY=t;break}n.upperCanvas.style.cursor=n.cursor="default"}return r},c.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},c.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 n=0,a=o.activeObj.flipObjColl.length;n<a;n++){var s=o.activeObj.flipObjColl[n].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)},c.prototype.setActivePoint=function(e,t){var o,i,r=this.parent,n=r.activeObj.activePoint;O.isNullOrUndefined(n)||(r.currObjType.isText?(i=e||0,o=t||r.activeObj.textSettings.fontSize,void 0===r.activeObj.textSettings.fontSize&&(r.activeObj.textSettings.fontSize=.1*Math.abs(r.baseImgCanvas.width-r.baseImgCanvas.height)),this.setTextSelection(i,o),this.mouseDownPoint.x=n.endX,this.mouseDownPoint.y=n.endY,void 0!==r.activeObj.horTopLine&&(r.activeObj.activePoint=O.extend({},n,{},!0)),r.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate"}})):e&&t?(n.startX=this.mouseDownPoint.x=e,n.startY=this.mouseDownPoint.y=t,r.currObjType.isDragging=!0):((n={startX:(i=r.activeObj).horTopLine.startX,startY:i.horTopLine.startY,endX:i.horTopLine.endX,endY:i.horTopLine.endY}).width=n.endX-n.startX,n.height=n.endY-n.startY))},c.prototype.mouseDownEventHandler=function(e){var t,o=this.parent;this.mouseDown=e.currentTarget===o.lowerCanvas||e.currentTarget===o.upperCanvas?"canvas":"","touchstart"===e.type?this.isTouch=!0:this.isTouch=!1,"touchstart"===e.type&&e.currentTarget===o.lowerCanvas&&!o.isImageLoaded||(this.isCropSelection=!1,this.isPan=!0,void 0!==(t=void 0!==o.activeObj.shape?o.activeObj.shape.split("-"):t)&&"crop"===t[0]&&(this.isCropSelection=!0),this.isCropSelection&&(this.dragCanvas=o.togglePan=!0),"grabbing"===o.cursor&&(t={shapeSettingsObj:{}},this.isGrabbing=!0,o.notify("selection",{prop:"updatePrevShapeSettings",onPropertyChange:!1,value:{obj:t}}),this.triggerShapeChange({cancel:!1,action:"rotate-start",previousShapeSettings:t=t.shapeSettingsObj},{cancel:!1,action:"rotate-start",previousShapeSettings:t},"mouse-down")),t={point:this.setXYPoints(e)},o.trigger("click",t),this.clickEvent(t,e))},c.prototype.getImagePoints=function(e,t){var o=this.parent.img,i=o.destLeft,r=o.destTop,n=o.destWidth,o=o.destHeight;return e<i?e=i:i+n<e&&(e=i+n),t<r?t=r:r+o<t&&(t=r+o),{x:e,y:t}},c.prototype.clickEvent=function(e,t){var o=this.parent,i=o.activeObj.activePoint,r=e.point.x,e=e.point.y,n=o.activeObj.shape&&"text"===o.activeObj.shape?o.cursor:"default";if(o.isResize)this.performEnterAction(),o.upperCanvas.style.cursor="default";else{if(JSON.stringify(o.frameObj)!==JSON.stringify(o.tempFrameObj))o.okBtn();else if(""!==this.currentDrawingShape&&(this.isTouch&&!this.isShapeTouch(t,this.isCropSelection)||"crosshair"===o.upperCanvas.style.cursor||o.isShapeDrawing))return o.drawingShape&&!o.isShapeDrawing&&(o.okBtn(),o.enableShapeDrawing(o.toPascalCase(o.drawingShape),!0)),i=o.activeObj.activePoint,o.notify("filter",{prop:"getCurrentObj",onPropertyChange:!(d={currObj:{}}),value:{object:d}}),this.initialPrevObj=d.currObj,this.initialPrevObj.objColl=O.extend([],o.objColl,[],!0),this.initialPrevObj.pointColl=O.extend([],o.pointColl,[],!0),this.initialPrevObj.afterCropActions=O.extend([],o.afterCropActions,[],!0),o.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!(d={selPointColl:null}),value:{obj:d}}),this.initialPrevObj.selPointColl=O.extend([],d.selPointColl,[],!0),this.setActivePoint(r,e),i=o.activeObj.activePoint,"path"===this.currentDrawingShape&&(s=this.getImagePoints(r,e),o.activeObj.pointColl.push({x:s.x,y:s.y}),0!==i.width)&&0!==i.height&&(i.width=0,i.height=0,i.startX=o.activeObj.pointColl[o.activeObj.pointColl.length-1].x,i.startY=o.activeObj.pointColl[o.activeObj.pointColl.length-1].y),i.endX=i.startX,i.endY=i.startY,"text"===this.currentDrawingShape?(o.activeObj.textSettings.fontSize=11,this.previousPoint.x=i.startX,this.previousPoint.y=i.startY,o.notify("shape",{prop:"updateFontStyles",onPropertyChange:!1,value:{isTextBox:null}}),d=this.upperContext.measureText(o.activeObj.textSettings.text).width+.5*o.activeObj.textSettings.fontSize,i.endX=i.startX+d,i.endY=i.startY+o.activeObj.textSettings.fontSize,i.width=i.endX-i.startX,i.height=i.endY-i.startY):"arrow"===this.currentDrawingShape&&(o.activeObj.start=this.arrowShape[0],o.activeObj.end=this.arrowShape[1]),d={cancel:!(h={cancel:!(o.currObjType.isDragging=!0),action:"draw-start",previousShapeSettings:d=this.updatePrevShapeSettings()}),action:"move",previousShapeSettings:d},this.shapeResizingArgs=h,this.shapeMovingArgs=d,this.triggerShapeChange(h,d,"mouse-down"),o.activeObj.activePoint=i,void(o.isShapeDrawing=!0);o.notify("draw",{prop:"resetFrameZoom",onPropertyChange:!1,value:{isOk:!0}}),this.isCropSelection&&this.dragCanvas&&(this.setCursor(r,e),"move"!==o.cursor)&&"crosshair"!==o.cursor&&"default"!==o.cursor&&"grab"!==o.cursor&&(this.isPan=!1),o.activeObj.shape?this.isObjSelected=!0:this.isObjSelected=!1;var a,s,l,p,h={currObj:{}},d=(o.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:h}}),h.currObj),i=O.extend({},o.activeObj,null,!0),h=this.isShapeTouch(t,this.isCropSelection),c=this.isFreehandDrawTouch(t,this.isCropSelection),u=h||this.isShapeClick(t,this.isCropSelection),u=this.applyCurrShape(u),g="none"!==o.textArea.style.display;this.isTouch&&!h&&i.shape&&!this.isCropSelection&&(this.applyObj(r,e)&&(o.okBtn(!0),o.notify("draw",{prop:"setPrevActObj",onPropertyChange:!1,value:{prevActObj:null}})),i=O.extend({},o.cropObj,{},!0),o.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"shapeTransform",previousObj:d,previousObjColl:d.objColl,previousPointColl:d.pointColl,previousSelPointColl:d.selPointColl,previousCropObj:i,previousText:null,currentText:null,previousFilter:null,isCircleCrop:o.isCircleCrop}}),u)&&o.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"ok"}}),h||o.togglePen||this.isCropSelection||(o.notify("toolbar",{prop:"refresh-main-toolbar",onPropertyChange:!1}),o.notify("toolbar",{prop:"close-contextual-toolbar",onPropertyChange:!1})),!this.dragCanvas||!this.isPan||"grab"!==o.cursor&&!this.isTouch||h||c||o.togglePen?(d=!1,!o.activeObj.shape||"line"!==o.activeObj.shape&&"arrow"!==o.activeObj.shape||(d=!0),h=(i=this.setXYPoints(t)).x,c=i.y,this.applyObj(h,c)&&(o.okBtn(!0),u&&(i=o.cursor,o.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"ok"}}),o.cursor=i),o.notify("draw",{prop:"setPrevActObj",onPropertyChange:!1,value:{prevActObj:null}})),o.notify("shape",{prop:"redrawActObj",onPropertyChange:!1,value:{x:h,y:c,isMouseDown:!0}}),o.notify("freehand-draw",{prop:"getFreehandDrawHoveredIndex",onPropertyChange:!(i={index:null}),value:{obj:i}}),o.notify("freehand-draw",{prop:"getFreehandSelectedIndex",onPropertyChange:!(a={freehandSelectedIndex:null}),value:{obj:a}}),this.isFhdPoint||this.isFhdCustomized&&!o.togglePen?(O.isNullOrUndefined(a.freehandSelectedIndex)||a.freehandSelectedIndex===i.index||(p=i.index,o.okBtn(),this.isFhdCustomized=!1,o.notify("freehand-draw",{prop:"setFreehandDrawHoveredIndex",onPropertyChange:!1,value:{index:p}}),-1<i.index&&(l=o.pointColl[i.index].strokeColor,o.notify("freehand-draw",{prop:"hoverFhd",onPropertyChange:!1,value:{strokeColor:l,strokeWidth:o.pointColl[i.index].strokeWidth}}))),a.freehandSelectedIndex=null,o.notify("freehand-draw",{prop:"getFreehandSelectedIndex",onPropertyChange:!1,value:{obj:a}}),p=O.extend([],o.objColl,[],!0),!O.isNullOrUndefined(i.index)&&-1<i.index?(o.notify("freehand-draw",{prop:"selectFhd",value:{type:"ok"}}),o.notify("freehand-draw",{prop:"hoverFhd",onPropertyChange:!1,value:{strokeColor:null,strokeWidth:null}}),o.notify("toolbar",{prop:"renderQAT",onPropertyChange:!1,value:{isPenEdit:!0}})):a.freehandSelectedIndex?(o.okBtn(),l=o.pointColl[a.freehandSelectedIndex].strokeColor,o.notify("freehand-draw",{prop:"hoverFhd",onPropertyChange:!1,value:{strokeColor:l,strokeWidth:o.pointColl[a.freehandSelectedIndex].strokeWidth}})):this.findTargetObj(h,c,!1)&&(o.objColl=p,this.findTarget(h,c,t.type),o.notify("draw",{prop:"redrawDownScale"}))):(this.isFhdEditing&&(o.apply(),(i=document.getElementById(o.element.id+"_quickAccessToolbarArea"))&&(i.style.display="none"),s=o.pointColl[a.freehandSelectedIndex],l={id:"pen_"+(a.freehandSelectedIndex+1),type:v.ShapeType.FreehandDraw,startX:s.points[0].x,startY:s.points[0].y,strokeColor:s.strokeColor,strokeWidth:s.strokeWidth,points:s.points,opacity:s.opacity,index:s.order},p={action:"apply",currentShapeSettings:O.extend({},l,{},!0)},o.trigger("shapeChange",p)),i=o.togglePen,o.notify("toolbar",{prop:"close-contextual-toolbar",onPropertyChange:!1}),i&&o.freeHandDraw(!0),this.isFhdEditing=!1,d?this.setCursor(h,c):"default"!==n&&(o.upperCanvas.style.cursor=o.cursor=n),("crosshair"===o.cursor||O.Browser.isDevice&&o.togglePen)&&(o.togglePen?(O.isNullOrUndefined(o.activeObj.strokeSettings)&&(o.notify("shape",{prop:"getStrokeSettings",onPropertyChange:!(a={strokeSettings:{}}),value:{obj:a}}),o.activeObj.strokeSettings=a.strokeSettings),o.notify("freehand-draw",{prop:"getPenStrokeWidth",onPropertyChange:!(s={penStrokeWidth:null}),value:{obj:s}}),O.isNullOrUndefined(s.penStrokeWidth)&&o.notify("freehand-draw",{prop:"setPenStrokeWidth",onPropertyChange:!1,value:{value:2}}),this.upperContext.strokeStyle=o.activeObj.strokeSettings.strokeColor,this.upperContext.fillStyle=o.activeObj.strokeSettings.strokeColor,o.notify("freehand-draw",{prop:"freehandDownHandler",onPropertyChange:!1,value:{e:t,canvas:o.upperCanvas}})):(o.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),this.upperContext.clearRect(0,0,o.upperCanvas.width,o.upperCanvas.height)),o.currObjType.isActiveObj=!1,this.dragElement="",this.dragPoint.startX=this.dragPoint.startY=this.dragPoint.endX=this.dragPoint.endY=0),"crosshair"!==o.cursor&&"touchstart"===t.type.toLowerCase()||o.currObjType.isActiveObj&&"default"!==o.cursor&&!o.togglePen?(o.notify("draw",{prop:"updateTempObjColl"}),o.notify("draw",{prop:"updateTempPointColl"}),this.findTarget(h,c,t.type),o.notify("draw",{prop:"redrawDownScale"})):""!==o.currObjType.shape&&!o.currObjType.isCustomCrop||o.togglePen||"default"===o.cursor||this.setActivePoint(h,c),g&&o.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.lowerContext}}))):(this.applyObj(r,e)&&(o.okBtn(!0),u&&(l=o.cursor,o.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"ok"}}),o.cursor=l),o.notify("draw",{prop:"setPrevActObj",onPropertyChange:!1,value:{prevActObj:null}})),this.isFhdEditing&&(o.notify("freehand-draw",{prop:"applyFhd",onPropertyChange:!1}),this.isFhdCustomized=!1,o.notify("toolbar",{prop:"destroy-qa-toolbar",onPropertyChange:!1})),(p=o.activeObj.shape)&&-1<["rectangle","ellipse","line","arrow","path","text","image"].indexOf(p)&&(o.notify("shape",{prop:"redrawActObj",onPropertyChange:!1,value:{x:null,y:null,isMouseDown:null}}),o.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),o.notify("toolbar",{prop:"setCurrentToolbar",value:{type:"main"}}),o.notify("toolbar",{prop:"refresh-main-toolbar",onPropertyChange:!1})),this.canvasMouseDownHandler(t)),this.isShapeInserted=!1,this.tempActiveObj=O.extend({},o.activeObj,{},!0)}},c.prototype.mouseMoveEventHandler=function(e){var t,o,i,r,n,a,s,l,p=this.parent,h=p.cursor,d=p.upperCanvas.style.cursor;e.preventDefault(),this.isPreventShaping||("grabbing"===p.cursor&&this.isGrabbing&&(p.notify("selection",{prop:"updatePrevShapeSettings",onPropertyChange:!(s={shapeSettingsObj:{}}),value:{obj:s}}),this.triggerShapeChange({cancel:!1,action:"rotating",previousShapeSettings:s=s.shapeSettingsObj},{cancel:!1,action:"rotating",previousShapeSettings:s},"mouse-down")),this.timer&&0<this.timer&&(this.timer=0),s=p.lowerCanvas.getBoundingClientRect(),"touchmove"===e.type&&2===e.touches.length?(this.isFirstMove?(this.startTouches=this.targetTouches(e.touches),this.tempTouches=[],this.tempTouches.push({x:e.touches[0].clientX||e.touches[0].pageX-p.lowerCanvas.offsetLeft-s.left,y:(e.touches[0].clientY||e.touches[0].pageY-p.lowerCanvas.offsetTop)-s.top}),this.tempTouches.push({x:(e.touches[1].clientX||e.touches[1].pageX-p.lowerCanvas.offsetLeft)-s.left,y:(e.touches[1].clientY||e.touches[1].pageY-p.lowerCanvas.offsetTop)-s.top})):(a=(e.touches[0].clientX||e.touches[0].pageX-p.lowerCanvas.offsetLeft)-s.left,r=(e.touches[0].clientY||e.touches[0].pageY-p.lowerCanvas.offsetTop)-s.top,n=(e.touches[1].clientX||e.touches[1].pageX-p.lowerCanvas.offsetLeft)-s.left,i=(e.touches[1].clientY||e.touches[1].pageY-p.lowerCanvas.offsetTop)-s.top,this.currMousePoint.x!==(a={x:a<n?n-(n-a)/2:a-(a-n)/2,y:r<i?i-(i-r)/2:r-(r-i)/2}).x&&this.currMousePoint.y!==a.y&&(n="","touchmove"===e.type&&(p.zoomSettings.zoomTrigger&v.ZoomTrigger.Pinch)===v.ZoomTrigger.Pinch&&(this.zoomType="Pinch",r=this.calculateScale(this.startTouches,this.targetTouches(e.touches)),this.startTouches=this.targetTouches(e.touches),1<r?n="zoomIn":r<1&&(n="zoomOut")),""!==n&&p.notify("draw",{prop:"performPointZoom",onPropertyChange:!1,value:{x:a.x,y:a.y,type:n,isResize:null}}),this.tempTouches=[],this.tempTouches.push({x:e.touches[0].clientX||e.touches[0].pageX-p.lowerCanvas.offsetLeft,y:e.touches[0].clientY||e.touches[0].pageY-p.lowerCanvas.offsetTop}),this.tempTouches.push({x:e.touches[1].clientX||e.touches[1].pageX-p.lowerCanvas.offsetLeft,y:e.touches[1].clientY||e.touches[1].pageY-p.lowerCanvas.offsetTop}),this.currMousePoint.x=a.x,this.currMousePoint.y=a.y,this.isPinching=!0)),this.isFirstMove=!1):("mousemove"===e.type?(t=e.clientX,o=e.clientY):(this.touchEndPoint.x=t=e.touches[0].clientX,this.touchEndPoint.y=o=e.touches[0].clientY),t-=s.left,o-=s.top,this.canvasMouseMoveHandler(e),i=!1,(i=void 0!==(l=void 0!==p.activeObj.shape?p.activeObj.shape.split("-"):l)&&"crop"===l[0]?!0:i)&&p.notify("transform",{prop:"disableZoomOutBtn",value:{isZoomOut:!0}}),p.upperCanvas.style.cursor=d,p.cursor=h,(p.currObjType.isActiveObj&&(void 0!==p.activeObj.activePoint||0<p.objColl.length)&&!this.dragCanvas||void 0!==p.activeObj.activePoint)&&""===this.dragElement&&(this.setCursor(t,o),p.activeObj.activePoint&&(0===p.activeObj.activePoint.width||!O.isNullOrUndefined(p.activeObj.currIndex)&&this.cursorTargetId!==p.activeObj.currIndex)&&"default"!==p.cursor&&"move"!==p.cursor&&"crosshair"!==p.cursor&&"grab"!==p.cursor&&"pointer"!==p.cursor&&(p.upperCanvas.style.cursor=p.cursor="move"),this.findTarget(t,o,e.type)),n=(r=p.img).destLeft,a=r.destTop,s=r.destWidth,l=r.destHeight,p.currObjType.isDragging&&(this.upperContext.clearRect(0,0,p.lowerCanvas.width,p.lowerCanvas.height),this.updateActivePoint(t,o,i),p.notify("shape",{prop:"updateTrianglePoints",onPropertyChange:!1,value:{obj:p.activeObj}}),this.isPreventDragging?(p.activeObj.activePoint.startX>n&&p.activeObj.activePoint.endX<n+s&&p.activeObj.activePoint.startY>a&&p.activeObj.activePoint.endY<a+l&&(this.isPreventDragging=!1),p.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate",obj:null,isCropRatio:null,points:null,isPreventDrag:!0,saveContext:null,isPreventSelection:null}})):p.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate",obj:null,isCropRatio:null,points:null,isPreventDrag:null,saveContext:null,isPreventSelection:null}}),i)&&(this.dragCanvas=p.togglePan=!0)))},c.prototype.mouseUpEventHandler=function(e){var t,o,i,r,n,a,s,l,p,h,d,c,u,g=this.parent,v=g.element.id;(O.Browser.isDevice||!(g.element.querySelector("#"+v+"_contextualToolbar")&&!g.element.querySelector("#"+v+"_contextualToolbar").parentElement.classList.contains("e-hide")||g.element.querySelector("#"+v+"_headWrapper")&&!g.element.querySelector("#"+v+"_headWrapper").parentElement.classList.contains("e-hide")))&&("grabbing"===g.cursor&&this.isGrabbing&&(g.notify("selection",{prop:"updatePrevShapeSettings",onPropertyChange:!(u={shapeSettingsObj:{}}),value:{obj:u}}),v=u.shapeSettingsObj,this.triggerShapeChange(c={cancel:!1,action:"rotate-end",previousShapeSettings:v},l={cancel:!1,action:"rotate-end",previousShapeSettings:v},"mouse-up")),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(),g.togglePan&&this.canvasMouseUpHandler(e),t=v=void 0,t="mouseup"===e.type?(v=e.clientX,e.clientY):(v=this.touchEndPoint.x,this.touchEndPoint.y),v-=(d=g.lowerCanvas.getBoundingClientRect()).left,d=void(t-=d.top),o=this.currentDrawingShape,i=!1,"touchend"===e.type&&(this.startTouches=this.tempTouches=[],this.isFirstMove=!1,"none"===g.textArea.style.display&&(this.timer=0),this.isPinching)?(this.isPinching=!1,g.notify("draw",{prop:"redrawDownScale"}),(g.isCropTab||g.activeObj.shape)&&(g.notify("draw",{prop:"setStraightenActObj",value:{activeObj:null}}),g.notify("freehand-draw",{prop:"resetStraightenPoint"})),g.isStraightening&&(g.notify("draw",{prop:"resetStraightenDestPoints"}),g.notify("draw",{prop:"setDestForStraighten"}))):(r=!1,(n=void 0)!==(n=void 0!==g.activeObj.shape?g.activeObj.shape.split("-"):n)&&"crop"===n[0]&&(r=!0),"path"===this.currentDrawingShape&&g.isShapeDrawing?(s=(h=e.srcElement).parentElement.id,a=g.element.id,e.currentTarget!==g.upperCanvas&&e.currentTarget!==g.lowerCanvas&&0<g.activeObj.pointColl.length&&(h.classList.contains("e-upload-icon")||s===a+"_zoomIn"||s===a+"_zoomOut"||s===a+"_annotationBtn"||s===a+"_borderColorBtn"||s===a+"_borderWidthBtn")&&(g.notify("shape",{prop:"stopPathDrawing",onPropertyChange:!1,value:{e:e,isApply:!0}}),this.upperContext.clearRect(0,0,g.upperCanvas.width,g.upperCanvas.height),g.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate",obj:g.activeObj,isCropRatio:null,points:null,isPreventDrag:!0,saveContext:null,isPreventSelection:!0}}))):(e.currentTarget!==g.upperCanvas||g.isResize||(this.pathAdjustedIndex=null,""!==this.currentDrawingShape&&("text"===this.currentDrawingShape?(h=O.extend({},g.cropObj,{},!0),g.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:h,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}})):g.notify("undo-redo",{prop:"updateUrObj",onPropertyChange:!1,value:{objColl:this.initialPrevObj.objColl,operation:"shapeInsert"}}),this.isShapeInserted=!0,this.currentDrawingShape="",(g.activeObj.shape&&"path"===g.activeObj.shape&&0===g.activeObj.pointColl.length||(!g.activeObj.shape||"path"!==g.activeObj.shape)&&0===g.activeObj.activePoint.width&&0===g.activeObj.activePoint.height)&&(g.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!(i=!0)}),this.upperContext.clearRect(0,0,g.upperCanvas.width,g.upperCanvas.height)),l={cancel:!(c={cancel:!1,action:"draw-end",previousShapeSettings:s=this.updatePrevShapeSettings()}),action:"move",previousShapeSettings:s},this.shapeResizingArgs=c,this.shapeMovingArgs=l,this.triggerShapeChange(c,l,"mouse-up")),this.adjustActObjForLineArrow(),this.updPtCollForShpRot(),g.currObjType.shape=g.currObjType.shape.toLowerCase(),a=O.extend({},g.cropObj,{},!0),g.notify("filter",{prop:"getCurrentObj",onPropertyChange:!(h={currObj:{}}),value:{object:h}}),(s=h.currObj).objColl=O.extend([],g.objColl,[],!0),s.pointColl=O.extend([],g.pointColl,[],!0),s.afterCropActions=O.extend([],g.afterCropActions,[],!0),g.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!(c={selPointColl:null}),value:{obj:c}}),s.selPointColl=O.extend([],c.selPointColl,[],!0),g.togglePen||r||(this.tempObjColl&&0!==g.activeObj.activePoint.width&&(g.notify("shape",{prop:"updImgRatioForActObj",onPropertyChange:!1}),g.objColl.push(g.activeObj),JSON.stringify(g.activeObj.activePoint)!==JSON.stringify(this.tempActiveObj.activePoint)&&g.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"shapeTransform",previousObj:s,previousObjColl:this.tempObjColl,previousPointColl:s.pointColl,previousSelPointColl:s.selPointColl,previousCropObj:a,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),this.redrawShape(g.objColl[g.objColl.length-1],!0),this.tempObjColl=void 0),this.isFhdEditing)||(this.applyCurrActObj(v,t),g.currObjType.isResize=!1,g.notify("toolbar",{prop:"destroy-qa-toolbar",onPropertyChange:!1})),g.activeObj&&(l=!1,(void 0===(p=void 0!==g.activeObj.shape?g.activeObj.shape.split("-"):p)&&(g.currObjType.isCustomCrop||g.togglePen)||void 0!==p&&"crop"===p[0])&&(l=!0),h=g.activeObj.shape,-1<["rectangle","ellipse","line","arrow","path"].indexOf(d=h)?g.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"shapes",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}}):"text"===h?"none"===g.textArea.style.display&&g.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"text",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}}):this.isFhdEditing?g.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"pen",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}}):l||g.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"main",isApplyBtn:null,isCropping:!1,isZooming:null}}),g.notify("toolbar",{prop:"update-toolbar-items",onPropertyChange:!1}),this.isFhdEditing||(g.activeObj.shape&&"text"===g.activeObj.shape&&11===g.activeObj.textSettings.fontSize&&55===Math.floor(g.activeObj.activePoint.width)&&11===Math.floor(g.activeObj.activePoint.height)&&g.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),l)||(g.isShapeDrawing?(c=this.currentDrawingShape,g.notify("undo-redo",{prop:"updateUndoRedoStack",onPropertyChange:!1}),this.currentDrawingShape=c):g.notify("undo-redo",{prop:"updateUndoRedoStack",onPropertyChange:!1})))),void 0!==(n=void 0!==g.activeObj.shape?g.activeObj.shape.split("-"):n)&&"crop"===n[0]&&(r=!0),g.activeObj.shape&&!r&&e.currentTarget===g.upperCanvas&&"none"===g.textArea.style.display&&("text"===g.activeObj.shape?g.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"text",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}}):g.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"shapes",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}}),g.notify("toolbar",{prop:"update-toolbar-items",onPropertyChange:!1}),g.notify("toolbar",{prop:"renderQAT",onPropertyChange:!1,value:{isPenEdit:null}})),g.notify("freehand-draw",{prop:"getFreehandDrawSelectedId",onPropertyChange:!(u={freehandDrawSelectedId:null}),value:{obj:u}}),g.togglePen&&e.currentTarget===g.upperCanvas&&!u.freehandDrawSelectedId?(g.notify("freehand-draw",{prop:"freehandUpHandler",onPropertyChange:!1,value:{e:e,canvas:g.upperCanvas,context:this.upperContext}}),g.togglePen&&(O.isNullOrUndefined(g.toolbar)||g.toolbar&&0<g.toolbar.length||!O.isNullOrUndefined(g.toolbarTemplate))&&(g.okBtn(),g.freeHandDraw(!0))):g.currObjType.shape="",this.dragElement="",this.mouseDown="",this.isSliderActive=!1,g.currObjType.isInitialLine=g.currObjType.isDragging=!1,this.selMouseUpEvent(),O.isNullOrUndefined(g.drawingShape)&&d&&""!==o&&(g.drawingShape=d),g.drawingShape&&(this.currentDrawingShape=g.drawingShape.toLowerCase(),i)&&(g.enableShapeDrawing(g.toPascalCase(g.drawingShape),!0),g.upperCanvas.style.cursor="crosshair"),g.isShapeDrawing=!1)))},c.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;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},c.prototype.updPtCollForShpRot=function(e){var t,o,i,r,n,a,s=this.parent;(e=e||s.activeObj).shape&&0!==e.rotatedAngle&&(s.notify("shape",{prop:"setPointCollForShapeRotation",onPropertyChange:!1,value:{obj:e}}),s=s.img,t=s.destLeft,o=s.destTop,i=s.destWidth,r=s.destHeight,s=e.horTopLinePointColl,n=e.horBottomLinePointColl,a=e.verLeftLinePointColl,e=e.verRightLinePointColl,s.forEach(s=function(e){e.ratioX=(e.x-t)/i,e.ratioY=(e.y-o)/r}),n.forEach(s),a.forEach(s),e.forEach(s))},c.prototype.setXYPoints=function(e){e.preventDefault(),"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 t,o,e=this.parent.lowerCanvas.getBoundingClientRect();return{x:t-=e.left,y:o-=e.top}},c.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},c.prototype.isShapeClick=function(e,t){var o,i,r,n,a=this.parent,s=!1;return a.togglePen||a.activeObj.shape&&"text"===a.activeObj.shape&&this.isShapeInserted&&(o="block"===a.textArea.style.display||"inline-block"===a.textArea.style.display,i=O.extend({},a.activeObj,null,!0),a.notify("shape",{prop:"redrawActObj",onPropertyChange:!1,value:{x:null,y:null,isMouseDown:!0}}),r=(e=this.setXYPoints(e)).x,e=e.y,s=this.findTargetObj(r,e,t),t||(this.upperContext.clearRect(0,0,a.upperCanvas.width,a.upperCanvas.height),s&&a.notify("shape",{prop:"redrawActObj",onPropertyChange:!1,value:{x:null,y:null,isMouseDown:!0}})),o?(a.textArea.value=a.objColl[a.objColl.length-1].keyHistory,a.textArea.style.display="block",a.activeObj=i,n=this.getCurrentIndex(),O.isNullOrUndefined(n)?a.objColl.pop():a.objColl.splice(n,1)):!s&&i.shape&&(a.activeObj=i,n=this.getCurrentIndex(),O.isNullOrUndefined(n)||JSON.stringify(a.activeObj.activePoint)!==JSON.stringify(a.objColl[n].activePoint)?O.isNullOrUndefined(a.activeObj.currIndex)&&a.objColl.pop():a.objColl.splice(n,1))),s},c.prototype.isShapeTouch=function(e,t){var o,i,r,n,a=this.parent,s=!1;return"touchstart"!==e.type||a.togglePen||(a.activeObj&&"text"===a.activeObj.shape&&(this.timer=setTimeout(this.setTimer.bind(this),1e3,e)),o="block"===a.textArea.style.display||"inline-block"===a.textArea.style.display,i=O.extend({},a.activeObj,null,!0),a.notify("shape",{prop:"redrawActObj",onPropertyChange:!1,value:{x:null,y:null,isMouseDown:!0}}),r=(e=this.setXYPoints(e)).x,e=e.y,s=this.findTargetObj(r,e,t),t||this.upperContext.clearRect(0,0,a.upperCanvas.width,a.upperCanvas.height),o?(a.textArea.value=a.objColl[a.objColl.length-1].keyHistory,a.textArea.style.display="block",a.activeObj=i,n=this.getCurrentIndex(),O.isNullOrUndefined(n)?a.objColl.pop():a.objColl.splice(n,1)):!s&&i.shape&&(a.activeObj=i,n=this.getCurrentIndex(),t||(O.isNullOrUndefined(n)||JSON.stringify(a.activeObj.activePoint)!==JSON.stringify(a.objColl[n].activePoint)?O.isNullOrUndefined(a.activeObj.currIndex)&&a.objColl.pop():a.objColl.splice(n,1)))),s},c.prototype.isFreehandDrawTouch=function(e,t){var o,i,r,n,a=this.parent,s=!1;return"touchstart"!==e.type||t||a.togglePen||(o="block"===a.textArea.style.display||"inline-block"===a.textArea.style.display,i=O.extend({},a.activeObj,null,!0),a.notify("shape",{prop:"redrawActObj",onPropertyChange:!1,value:{x:null,y:null,isMouseDown:!0}}),r=(e=this.setXYPoints(e)).x,e=e.y,this.setCursor(r,e),this.isFhdPoint&&(s=!0),o?(a.textArea.value=a.objColl[a.objColl.length-1].keyHistory,a.textArea.style.display="block",a.activeObj=i,n=this.getCurrentIndex(),O.isNullOrUndefined(n)?a.objColl.pop():a.objColl.splice(n,1)):i.shape&&(a.activeObj=i,n=this.getCurrentIndex(),t||(O.isNullOrUndefined(n)||JSON.stringify(a.activeObj.activePoint)!==JSON.stringify(a.objColl[n].activePoint)?O.isNullOrUndefined(a.activeObj.currIndex)&&a.objColl.pop():a.objColl.splice(n,1)))),s},c.prototype.applyObj=function(e,t){var o,i,r,n,a=this.parent,s=!1;return(0!==a.activeObj.activePoint.width||0!==a.activeObj.activePoint.height)&&(n=(r=a.activeObj.activePoint).startX,o=r.startY,i=r.endX,r=r.endY,a.activeObj.shape&&-1<["rectangle","ellipse","line","arrow","path","image","text"].indexOf(a.activeObj.shape)?!(n-2*(n=a.activeObj.topLeftCircle.radius)<=e&&e<=i+2*n&&o-2*n<=t&&t<=r+2*n||"default"!==a.upperCanvas.style.cursor&&"grab"!==a.upperCanvas.style.cursor&&"crosshair"!==a.upperCanvas.style.cursor&&"pointer"!==a.upperCanvas.style.cursor&&"move"!==a.upperCanvas.style.cursor):s)},c.prototype.applyCurrShape=function(e){var t,o=this.parent,i=!1;return o.togglePen||(t=O.extend({},o.activeObj,null,!0),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?(e=O.extend({},o.activeObj,null,!0),o.notify("shape",{prop:"redrawActObj",onPropertyChange:!1,value:{x:null,y:null,isMouseDown:null}}),t=O.extend({},o.objColl[o.objColl.length-1],null,!0),o.objColl.pop(),o.activeObj=O.extend({},e,null,!0),o.textArea.value=t.keyHistory,o.textArea.style.display="block",(e=t.strokeSettings&&t.strokeSettings.strokeColor?"rgb"===t.strokeSettings.strokeColor.split("(")[0]?this.rgbToHex(parseFloat(t.strokeSettings.strokeColor.split("(")[1].split(",")[0]),parseFloat(t.strokeSettings.strokeColor.split("(")[1].split(",")[1]),parseFloat(t.strokeSettings.strokeColor.split("(")[1].split(",")[2]),parseFloat(t.strokeSettings.strokeColor.split("(")[1].split(",")[3])):t.strokeSettings.strokeColor:null)&&"#ffffff"===e&&(e="#fff"),this.tempActiveObj.strokeSettings&&this.tempActiveObj.strokeSettings.strokeColor&&"#ffffff"===this.tempActiveObj.strokeSettings.strokeColor&&(this.tempActiveObj.strokeSettings.strokeColor="#fff"),(t.keyHistory!==this.tempActiveObj.keyHistory||e&&e!==this.tempActiveObj.strokeSettings.strokeColor||t.textSettings&&t.textSettings.fontFamily!==this.tempActiveObj.textSettings.fontFamily||t.textSettings&&Math.round(t.textSettings.fontSize)!==Math.round(this.tempActiveObj.textSettings.fontSize)||t.textSettings&&Math.round(t.textSettings.fontRatio)!==Math.round(this.tempActiveObj.textSettings.fontRatio)||t.textSettings&&t.textSettings.bold!==this.tempActiveObj.textSettings.bold||t.textSettings&&t.textSettings.italic!==this.tempActiveObj.textSettings.italic||t.textSettings&&t.textSettings.underline!==this.tempActiveObj.textSettings.underline)&&(i=!0),this.isInitialTextEdited&&!i&&(this.isInitialTextEdited=!(i=!0))):(this.tempActiveObj.activePoint.height=Math.abs(this.tempActiveObj.activePoint.height),i=JSON.stringify(t)!==JSON.stringify(this.tempActiveObj))),i},c.prototype.canvasMouseDownHandler=function(e){var t,o=this.parent,i=(e.preventDefault(),e="mousedown"===e.type?(t=e.offsetX||e.pageX-o.lowerCanvas.offsetLeft,e.offsetY||e.pageY-o.lowerCanvas.offsetTop):(t=e.touches[0].clientX||e.touches[0].pageX-o.lowerCanvas.offsetLeft,e.touches[0].clientY||e.touches[0].pageY-o.lowerCanvas.offsetTop),o.lowerCanvas.getBoundingClientRect()),i=(t-=i.left,e-=i.top,this.panDown={x:t,y:e},{tempPanMove:null});o.notify("transform",{prop:"getTempPanMove",onPropertyChange:!1,value:{obj:i}}),O.isNullOrUndefined(i.tempPanMove)&&o.notify("transform",{prop:"setTempPanMove",onPropertyChange:!1,value:{point:{x:t,y:e}}})},c.prototype.canvasMouseMoveHandler=function(e){var t,o=this.parent,i={bool:null};o.notify("toolbar",{prop:"getFrameToolbar",onPropertyChange:!1,value:{obj:i}}),o.isResize||i.bool?o.upperCanvas.style.cursor="default":(this.dragCanvas?o.lowerCanvas.style.cursor="grab":(this.dragCanvas=o.togglePan=!1,o.lowerCanvas.style.cursor=o.upperCanvas.style.cursor=o.cursor="default"),i="mousemove"===e.type?(t=e.offsetX,e.offsetY):(t=e.touches[0].clientX||e.touches[0].pageX-o.lowerCanvas.offsetLeft,e.touches[0].clientY||e.touches[0].pageY-o.lowerCanvas.offsetTop),e=o.lowerCanvas.getBoundingClientRect(),t-=e.left,i-=e.top,o.notify("transform",{prop:"setPanMove",onPropertyChange:!1,value:{point:{x:t,y:i}}}),this.panDown&&o.togglePan&&this.dragCanvas&&((o.isCropTab||o.activeObj.shape)&&(o.notify("draw",{prop:"setStraightenActObj",value:{activeObj:null}}),o.notify("freehand-draw",{prop:"resetStraightenPoint"})),o.notify("transform",{prop:"drawPannedImage",onPropertyChange:!1,value:{xDiff:null,yDiff:null}})))},c.prototype.canvasMouseUpHandler=function(e){var t=this.parent,e=(e.preventDefault(),{panMove:null});t.notify("transform",{prop:"getPanMove",onPropertyChange:!1,value:{obj:e}}),t.togglePan&&this.panDown&&e.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)},c.prototype.touchStartHandler=function(e){e.preventDefault();var t=this.parent;0!==this.touchTime&&(new Date).getTime()-this.touchTime<400?(t.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),O.EventHandler.add(t.lowerCanvas,"touchend",this.mouseUpEventHandler,this),O.EventHandler.add(t.lowerCanvas,"touchmove",this.mouseMoveEventHandler,this),O.EventHandler.add(t.upperCanvas,"touchend",this.mouseUpEventHandler,this),O.EventHandler.add(t.upperCanvas,"touchmove",this.mouseMoveEventHandler,this)},c.prototype.unwireEvent=function(){var e=this.parent;O.EventHandler.remove(e.lowerCanvas,"touchend",this.mouseUpEventHandler),O.EventHandler.remove(e.lowerCanvas,"touchmove",this.mouseMoveEventHandler),O.EventHandler.remove(e.upperCanvas,"touchend",this.mouseUpEventHandler),O.EventHandler.remove(e.upperCanvas,"touchmove",this.mouseMoveEventHandler)},c.prototype.keyDownEventHandler=function(e){var t=this.parent,o=(!e.ctrlKey||"+"!==e.key&&"-"!==e.key||e.preventDefault(),{fileName:"",fileType:null}),i=(t.notify("draw",{prop:"getFileName",onPropertyChange:!1,value:{obj:o}}),{fileName:o.fileName,fileType:o.fileType,cancel:!1});switch(e.key){case e.ctrlKey&&"s":t.trigger("beforeSave",i),this.beforeSaveEvent(i,e);break;case e.ctrlKey&&"z":t.allowUndoRedo&&(t.noPushUndo=!1,(t.togglePen||t.drawingShape)&&(t.okBtn(),t.drawingShape=null),t.notify("undo-redo",{prop:"call-undo"}));break;case e.ctrlKey&&"y":t.allowUndoRedo&&(t.noPushUndo=!1,(t.togglePen||t.drawingShape)&&(t.okBtn(),t.drawingShape=null),t.notify("undo-redo",{prop:"call-redo"}));break;case e.ctrlKey&&"+":(t.zoomSettings.zoomTrigger&v.ZoomTrigger.Commands)===v.ZoomTrigger.Commands&&(this.zoomType="Commands",t.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:.1,zoomPoint:null},isResize:null}),t.notify("draw",{prop:"redrawDownScale"}),(t.isCropTab||t.activeObj.shape)&&(t.notify("draw",{prop:"setStraightenActObj",value:{activeObj:null}}),t.notify("freehand-draw",{prop:"resetStraightenPoint"})),t.isStraightening)&&(t.notify("draw",{prop:"resetStraightenDestPoints"}),t.notify("draw",{prop:"setDestForStraighten"}));break;case e.ctrlKey&&"-":(t.zoomSettings.zoomTrigger&v.ZoomTrigger.Commands)===v.ZoomTrigger.Commands&&(this.zoomType="Commands",t.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:-.1,zoomPoint:null},isResize:null}),t.notify("draw",{prop:"redrawDownScale"}),(t.isCropTab||t.activeObj.shape)&&(t.notify("draw",{prop:"setStraightenActObj",value:{activeObj:null}}),t.notify("freehand-draw",{prop:"resetStraightenPoint"})),t.isStraightening)&&(t.notify("draw",{prop:"resetStraightenDestPoints"}),t.notify("draw",{prop:"setDestForStraighten"}));break;case"Delete":this.deleteItem();break;case"Escape":t.notify("draw",{prop:"performCancel",value:{isContextualToolbar:null,isFinalCancel:!0}});break;case"Enter":this.performEnterAction(e);break;case"Tab":this.performTabAction();break;default:!O.Browser.isDevice||"block"!==t.textArea.style.display&&"inline-block"!==t.textArea.style.display||setTimeout(this.textKeyDown.bind(this),1,e)}},c.prototype.performEnterAction=function(e){var t,o,i,r,n=this.parent;n.isResize?this.isValueUpdated()&&(o=this.getNumTextValue(),r=n.element.querySelector("#"+n.element.id+"_aspectratio"),t=n.element.querySelector(".e-ie-toolbar-aspect-ratio-btn"),o&&o.x&&o.y&&(r||t&&!t.classList.contains("e-hidden")?n.notify("transform",{prop:"resize",value:{width:o.x,height:null,isAspectRatio:!0}}):n.notify("transform",{prop:"resize",value:{width:o.x,height:o.y,isAspectRatio:!1}})),t=n.element.querySelector("#"+n.element.id+"_resizeHeight"),o=n.element.querySelector("#"+n.element.id+"_resizeWidth"),O.isNullOrUndefined(r)&&(t&&(i=O.getComponent(t,"numerictextbox"),t)&&""===t.value&&(i.value=parseFloat(i.placeholder),t.value=i.placeholder+"px"),o)&&(i=O.getComponent(o,"numerictextbox"),o)&&""===o.value&&(i.value=parseFloat(i.placeholder),o.value=i.placeholder+"px"),n.notify("draw",{prop:"redrawDownScale"})):(r=void 0,n.activeObj.shape&&(r=n.activeObj.shape.split("-")),e&&this.isKeyBoardCrop(e)&&n.activeObj.horTopLine&&n.activeObj.shape&&"crop"===r[0]&&n.crop())},c.prototype.isKeyBoardCrop=function(e){var t=!1,e=e.target;return t=e.id!==this.parent.element.id+"_ok"&&""!==e.id?t:!0},c.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()},c.prototype.handleScroll=function(e){var t,o,i=this.parent,r=!1,n=("mousewheel"===e.type&&(t=e.clientX,o=e.clientY),i.lowerCanvas.getBoundingClientRect());t-=n.left,o-=n.top,t>i.img.destLeft&&t<i.img.destLeft+i.img.destWidth&&o>i.img.destTop&&o<i.img.destTop+i.img.destHeight&&(r=!0),e.stopPropagation(),!0===e.ctrlKey&&r&&(e.preventDefault(),!i.isCropTab&&i.activeObj.shape&&"crop"!==i.activeObj.shape.split("-")[0]&&(i.okBtn(null,!0),i.notify("toolbar",{prop:"close-contextual-toolbar",onPropertyChange:!1})),n="","mousewheel"===e.type&&(i.zoomSettings.zoomTrigger&v.ZoomTrigger.MouseWheel)===v.ZoomTrigger.MouseWheel&&(this.zoomType="MouseWheel",n=0<e.wheelDelta?"zoomIn":"zoomOut"),""!==n)&&(i.notify("draw",{prop:"performPointZoom",onPropertyChange:!1,value:{x:t,y:o,type:n,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"}))},c.prototype.textKeyDown=function(e){var t=this.parent;0===t.activeObj.rotatedAngle&&("\r"===String.fromCharCode(e.which)&&(this.textRow+=1),t.textArea.setAttribute("rows",this.textRow.toString()),t.textArea.style.height="auto",t.textArea.style.height=t.textArea.scrollHeight+"px",t.notify("shape",{prop:"setTextBoxWidth",onPropertyChange:!1,value:{e:e}}),O.Browser.isDevice&&(t.textArea.style.width=parseFloat(t.textArea.style.width)+t.textArea.style.fontSize+"px"),e=t.textArea.value.split("\n"),this.textRow=e.length,t.textArea.setAttribute("rows",this.textRow.toString()),this.isInitialTextEdited=!1)},c.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"))},c.prototype.setDragDirection=function(e,t){var o=7.5,i=this.parent,r=i.activeObj.activePoint;i.img.destWidth>i.img.destHeight?(r.startX=this.dragPoint.startX=e/2-t/2+o,r.startY=this.dragPoint.startY=t/2-t/2+o,r.endX=e/2+t/2-o,r.endY=t/2+t/2-o):(r.startY=this.dragPoint.startX=t/2-e/2+o,r.endY=t/2+e/2-o,r.startX=this.dragPoint.startX=o,r.endX=e-o)},c.prototype.calcShapeRatio=function(e,t,o,i){for(var r=this.parent,n=r.activeObj.activePoint,a=i<=o?o:i,s=a*(e/t),l=a,p=this.getScale(s,o),h=[],e=r.img,t=e.destLeft,a=e.destTop,d=e.destWidth,e=e.destHeight,c=0;c<2;c++)h.push(0===c?s*p:l*p);for(var s=h[0],l=h[1],u=this.getScale(l,i),g=[],c=0;c<2;c++)g.push(0===c?s*u:l*u);l=g[1],n.width=s=g[0],n.height=l,n.startX=7.5+(this.dragPoint.startX=(o-s)/2),n.startY=7.5+(this.dragPoint.startY=(i-l)/2),n.endX=n.startX+n.width,n.endY=n.startY+n.height,n.startX<t&&t+d>r.lowerCanvas.clientWidth&&(n.startX=t,n.endX=n.startX+s-7.5),n.startY<a&&a+e>r.lowerCanvas.clientHeight&&(n.startY=a,n.endY=n.startY+l-7.5),n.width=n.endX-n.startX,n.height=n.endY-n.startY},c.prototype.getScale=function(e,t){return t<e?t/e:1},c.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 r=i.activeObj,n=r.topLeftCircle,a=r.topCenterCircle,s=r.topRightCircle,l=r.centerLeftCircle,p=r.centerRightCircle,h=r.bottomLeftCircle,d=r.bottomCenterCircle,c=r.bottomRightCircle;switch(this.dragElement.toLowerCase()){case"nw-resize":n.startX=e,n.startY=t;break;case"n-resize":a.startX=e,a.startY=t;break;case"ne-resize":s.startX=e,s.startY=t;break;case"w-resize":l.startX=e,l.startY=t;break;case"e-resize":p.startX=e,p.startY=t;break;case"sw-resize":h.startX=e,h.startY=t;break;case"s-resize":d.startX=e,d.startY=t;break;case"se-resize":c.startX=e,c.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)}}},c.prototype.findTargetObj=function(e,t,o){var i=this.parent,r=!1;if(0!==i.objColl.length&&!i.currObjType.isCustomCrop&&!o){for(var n,a,s=0,l=void 0,p=0;p<i.objColl.length;p++){var h=i.upperCanvas.style.cursor,d=(this.setCursor(e,t),O.extend({},i.objColl[p],{},!0)),c=d.topLeftCircle.radius;if("line"===d.shape||"arrow"===d.shape){for(var u=0;u<d.pointColl.length;u++)if(e>=d.pointColl[u].x-2*c&&e<=d.pointColl[u].x+2*c&&t>=d.pointColl[u].y-2*c&&t<=d.pointColl[u].y+2*c){if(this.tempActiveObj&&this.tempActiveObj.activePoint&&JSON.stringify(this.tempActiveObj.activePoint)===JSON.stringify(d.activePoint)){l=p;break}this.isTouch||"move"===i.cursor||"grab"===i.cursor||this.isShapeInserted?(0===s||s<d.order)&&(s=d.order,l=p):i.objColl[p].currIndex===this.tempActiveObj.currIndex&&(l=p);break}}else if("path"===d.shape){var g=this.setCursorForPath(d,e,t,i.upperCanvas);if("default"!==g&&"grab"!==g){if(this.tempActiveObj&&this.tempActiveObj.activePoint&&JSON.stringify(this.tempActiveObj.activePoint)===JSON.stringify(d.activePoint)){l=p;break}this.isTouch||"move"===i.cursor||"grab"===i.cursor||this.isShapeInserted?(0===s||s<d.order)&&(s=d.order,l=p):i.objColl[p].currIndex===this.tempActiveObj.currIndex&&(l=p)}}else if(0!==d.rotatedAngle){g=this.setCursorForRotatedObject(d,e,t,i.upperCanvas);if("default"!==g&&"grab"!==g){if(this.tempActiveObj&&this.tempActiveObj.activePoint&&JSON.stringify(this.tempActiveObj.activePoint)===JSON.stringify(d.activePoint)){l=p;break}this.isTouch||"move"===i.cursor||"grab"===i.cursor||this.isShapeInserted?(0===s||s<d.order)&&(s=d.order,l=p):i.objColl[p].currIndex===this.tempActiveObj.currIndex&&(l=p)}}else{var v=this.getTransRotationPoint(d);if(e>=d.activePoint.startX-2*c&&e<=d.activePoint.endX+2*c&&t>=d.activePoint.startY-2*c&&t<=d.activePoint.endY+2*c||v&&e>=v.x-2*c&&e<=v.x+2*c&&t>=v.y-2*c&&t<=v.y+2*c){if(this.tempActiveObj&&this.tempActiveObj.activePoint&&JSON.stringify(this.tempActiveObj.activePoint)===JSON.stringify(d.activePoint)){l=p;break}this.isTouch||"move"===h||"grabbing"===h||this.isShapeInserted||"move"===i.cursor||"grabbing"===i.cursor?(0===s||s<d.order)&&(s=d.order,l=p):i.objColl[p].currIndex===this.tempActiveObj.currIndex&&(l=p)}}}r=O.isNullOrUndefined(l)?(i.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),!1):(this.tempObjColl=O.extend([],i.objColl,[],!0),i.currObjType.isCustomCrop=!1,i.activeObj=O.extend({},i.objColl[l],{},!0),o=O.extend({},i.objColl[l],{},!0),i.objColl.splice(l,1),0===i.transform.degree?(n=this.lowerContext.filter,this.lowerContext.clearRect(0,0,i.lowerCanvas.width,i.lowerCanvas.height),i.notify("draw",{prop:"drawImage",onPropertyChange:!1}),this.lowerContext.filter="none",i.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"iterate",pen:"iterate",isPreventApply:null}}),i.activeObj=O.extend({},n,{},!0),this.lowerContext.filter=n,this.getCurrentFlipState()):(n=O.extend({},i.panPoint.totalPannedInternalPoint,{},!0),a={startX:i.img.destLeft,startY:i.img.destTop,width:i.img.destWidth,height:i.img.destHeight},i.notify("draw",{prop:"callUpdateCurrTransState",onPropertyChange:!1}),i.panPoint.totalPannedInternalPoint=n,i.img.destLeft=a.startX,i.img.destTop=a.startY,i.img.destWidth=a.width,i.img.destHeight=a.height,i.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"iterate",pen:"iterate",isPreventApply:null}})),i.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.lowerContext}}),(i.currSelectionPoint&&"crop-circle"===i.currSelectionPoint.shape||i.isCircleCrop)&&i.notify("crop",{prop:"cropCircle",onPropertyChange:!1,value:{context:this.lowerContext,isSave:null,isFlip:null}}),i.activeObj=O.extend({},o,{},!0),this.setActivePoint(),i.activeObj=O.extend({},o,{},!0),n=O.extend({},i.activeObj.strokeSettings,{},!0),i.notify("draw",{prop:"setTempStrokeSettings",onPropertyChange:!1,value:{tempStrokeSettings:n}}),a=O.extend({},i.activeObj.textSettings,{},!0),i.notify("draw",{prop:"setTempTextSettings",onPropertyChange:!1,value:{tempTextSettings:a}}),n={cancel:!1,action:"select",previousShapeSettings:o=this.updatePrevShapeSettings(),currentShapeSettings:o},"line"!==i.activeObj.shape&&"arrow"!==i.activeObj.shape||(n.currentShapeSettings.width=i.activeObj.activePoint.endX-i.activeObj.activePoint.startX,n.currentShapeSettings.height=i.activeObj.activePoint.endY-i.activeObj.activePoint.startY),a=void(this.isCropSelection=!1),void 0!==(a=void 0!==i.activeObj.shape?i.activeObj.shape.split("-"):a)&&"crop"===a[0]&&(this.isCropSelection=!0),this.isCropSelection?(o={action:n.action,previousSelectionSettings:{type:i.getSelectionType(i.activeObj.shape),startX:n.previousShapeSettings.startX,startY:n.previousShapeSettings.startY,width:n.previousShapeSettings.width,height:n.previousShapeSettings.height},currentSelectionSettings:{type:i.getSelectionType(i.activeObj.shape),startX:n.currentShapeSettings.startX,startY:n.currentShapeSettings.startY,width:n.currentShapeSettings.width,height:n.currentShapeSettings.height}},i.trigger("selectionChanging",o),n.currentShapeSettings.startX=o.currentSelectionSettings.startX,n.currentShapeSettings.startY=o.currentSelectionSettings.startY,n.currentShapeSettings.width=o.currentSelectionSettings.width,n.currentShapeSettings.height=o.currentSelectionSettings.height):i.trigger("shapeChanging",n),this.shapeEvent(n),!0)}return r},c.prototype.shapeEvent=function(e){var t,o,i,r=this.parent;r.notify("shape",{prop:"updateShapeChangeEventArgs",onPropertyChange:!1,value:{shapeSettings:e.currentShapeSettings}}),r.activeObj.activePoint&&(r.notify("draw",{prop:"getPrevActObj",onPropertyChange:!(e={prevActObj:null}),value:{obj:e}}),O.isNullOrUndefined(e.prevActObj)&&r.notify("draw",{prop:"setPrevActObj",onPropertyChange:!1,value:{prevActObj:O.extend({},r.activeObj,{},!0)}}),"image"!==r.activeObj.shape||this.isImageClarity||(this.upgradeImageQuality(),this.isImageClarity=!0),r.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate",obj:r.activeObj,isCropRatio:null,points:null,isPreventDrag:!0,saveContext:null,isPreventSelection:!0}}),this.isShapeInserted||(e=r.activeObj.activePoint,t=(r=r.img).destLeft,o=r.destWidth,i=r.destTop,r=r.destHeight,this.isPreventDragging=e.startX<t||e.endX>t+o||e.startY<i||e.endY>i+r))},c.prototype.upgradeImageQuality=function(){var e=this.parent,t=O.extend({},e.activeObj,null,!0),o=e.activeObj.imageCanvas.getContext("2d"),i={width:0,height:0};e.notify("transform",{prop:"calcMaxDimension",onPropertyChange:!1,value:{width:e.activeObj.imageElement.width,height:e.activeObj.imageElement.height,obj:i,isImgShape:null}}),e.notify("shape",{prop:"updateObj",onPropertyChange:!1,value:{dimObj:i,x:null,y:null}}),o.clearRect(0,0,e.activeObj.imageCanvas.width,e.activeObj.imageCanvas.height),this.applyTransformToImg(o),e.activeObj=t},c.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}})},c.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}]},c.prototype.calculateScale=function(e,t){e=this.getDistance(e[0],e[1]);return this.getDistance(t[0],t[1])/e},c.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)},c.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}}))},c.prototype.setTimer=function(e){var t=this.parent;10<this.timer&&(clearTimeout(this.timer),this.timer=0,t.notify("shape",{prop:"findTextTarget",onPropertyChange:!1,value:{e:e}}),O.Browser.isDevice)&&this.upperContext.clearRect(0,0,t.upperCanvas.width,t.upperCanvas.height)},c.prototype.applyCurrActObj=function(e,t){var o=this.parent,i=!1,r=O.extend({},o.activeObj,{},!0);if(!O.isNullOrUndefined(r.activePoint)){var n,a=r.activePoint,s=a.startX,l=a.startY,p=a.endX,a=a.endY,h=r.topLeftCircle?r.topLeftCircle.radius:0;if(e>=Math.floor(s)&&e<=Math.ceil(p)&&t>=Math.floor(l)&&t<=Math.ceil(a)?i=!0:0!==h&&e>=Math.floor(s)-h&&e<=Math.ceil(p)+h&&t>=Math.floor(l)-h&&t<=Math.ceil(a)+h?(i=!0,this.tempActiveObj={activePoint:{startX:0,startY:0,endX:0,endY:0,width:0,height:0},flipObjColl:[],triangle:[],triangleRatio:[]}):"text"!==r.shape&&"image"!==r.shape||""===this.dragElement?"line"===r.shape||"arrow"===r.shape?(h={x:s<p?s:p,y:l<a?l:a},s={x:p<s?s:p,y:a<l?l:a},e>=Math.floor(h.x)-5&&e<=Math.ceil(s.x)+5&&t>=Math.floor(h.y)-5&&t<=Math.ceil(s.y)+5&&(i=!0)):"path"===r.shape?"move"===(n=this.setCursorForPath(r,e,t,o.upperCanvas))&&(i=!0):"grabbing"===this.dragElement?i=!0:0!==r.rotatedAngle?("default"!==(n=this.setCursorForRotatedObject(r,e,t,o.upperCanvas))&&"grab"!==n||"n-resize"===this.dragElement||"e-resize"===this.dragElement||"s-resize"===this.dragElement||"w-resize"===this.dragElement)&&(i=!0):"block"!==o.textArea.style.display&&"inline-block"!==o.textArea.style.display||(i=!0):i=!0,!i){O.isNullOrUndefined(o.activeObj.currIndex)&&(p={id:"shape_"+(o.objColl.length+1)},o.notify("shape",{prop:"getNewShapeId",onPropertyChange:!1,value:{obj:p}}),o.activeObj.currIndex=p.id),o.notify("shape",{prop:"updImgRatioForActObj",onPropertyChange:!1}),void 0===o.activeObj.horTopLine||0===o.activeObj.horTopLine.startX||0===o.activeObj.horTopLine.endX||o.currObjType.isCustomCrop||""===o.currObjType.shape||o.objColl.push(O.extend({},o.activeObj,{},!0));if(-1<["rectangle","ellipse","line","arrow","path","text","image"].indexOf(o.activeObj.shape)){l=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 d=0;d<o.objColl.length;d++){var c={isInside:!1};o.notify("crop",{prop:"isObjInImage",onPropertyChange:!1,value:{obj:o.objColl[d],object:c}}),c.isInside&&(o.notify("shape",{prop:"apply",onPropertyChange:!1,value:{shape:o.objColl[d].shape,obj:o.objColl[d],canvas:null}}),o.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}))}o.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"zoom",pen:"zoom",isPreventApply:null}}),this.lowerContext.filter=l,o.activeObj.shape&&o.notify("shape",{prop:"apply",onPropertyChange:!1,value:{shape:null,obj:null,canvas:null}}),o.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.lowerContext}}),o.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.upperContext}}),o.isCircleCrop&&o.notify("crop",{prop:"cropCircle",onPropertyChange:!1,value:{context:this.lowerContext,isSave:null,isFlip:null}})}o.notify("toolbar",{prop:"refresh-main-toolbar",onPropertyChange:!1})}}},c.prototype.getCurrentFlipState=function(){var e,t=this.parent;0!==t.rotateFlipColl.length?(e=O.extend({},t.panPoint.totalPannedInternalPoint,{},!0),t.notify("draw",{prop:"callUpdateCurrTransState",onPropertyChange:!1}),t.panPoint.totalPannedInternalPoint=e):t.notify("draw",{prop:"callUpdateCurrTransState",onPropertyChange:!1})},c.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)},c.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")},c.prototype.padLeft=function(e,t,o){for(;e.length<t;)e=o+e;return e},c.prototype.deleteItem=function(){var e=this.parent;if(this.isFhdEditing){this.updateFreehandDrawColorChange();var t=O.extend({},e.cropObj,{},!0),o={currObj:{}};e.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:o}});(l=o.currObj).objColl=O.extend([],e.objColl,[],!0),l.pointColl=O.extend([],e.pointColl,[],!0),l.afterCropActions=O.extend([],e.afterCropActions,[],!0);var i={selPointColl:null},r=(e.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:i}}),l.selPointColl=O.extend([],i.selPointColl,[],!0),{freehandDrawSelectedId:null});e.notify("freehand-draw",{prop:"getFreehandDrawSelectedId",onPropertyChange:!1,value:{obj:r}}),e.notify("freehand-draw",{prop:"deleteFhd",value:{id:r.freehandDrawSelectedId}}),e.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"deleteFreehandDrawing",previousObj:l,previousObjColl:this.tempObjColl,previousPointColl:l.pointColl,previousSelPointColl:l.selPointColl,previousCropObj:t,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){r={prevActObj:null};if(e.notify("draw",{prop:"getPrevActObj",onPropertyChange:!1,value:{obj:r}}),r.prevActObj&&(r.prevActObj.activePoint.width=Math.abs(r.prevActObj.activePoint.width),r.prevActObj.activePoint.height=Math.abs(r.prevActObj.activePoint.height)),r.prevActObj&&JSON.stringify(r.prevActObj)!==JSON.stringify(e.activeObj)){var n=e.activeObj.currIndex;e.notify("draw",{prop:"performCancel",value:{isContextualToolbar:null,isFinalCancel:!0}});for(var a=0,s=e.objColl.length;a<s;a++)if(e.objColl[a].currIndex===n){e.objColl.splice(a,1),e.notify("draw",{prop:"render-image",value:{isMouseWheel:null}});break}}var l,o={isNewPath:null};e.notify("draw",{prop:"getNewPath",value:{obj:o}}),o.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})):e.activeObj.shape&&(e.objColl.push(e.activeObj),t=O.extend({},e.cropObj,{},!0),e.notify("filter",{prop:"getCurrentObj",onPropertyChange:!(r={currObj:{}}),value:{object:r}}),(l=r.currObj).objColl=O.extend([],e.objColl,[],!0),l.pointColl=O.extend([],e.pointColl,[],!0),l.afterCropActions=O.extend([],e.afterCropActions,[],!0),e.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!(i={selPointColl:null}),value:{obj:i}}),l.selPointColl=O.extend([],i.selPointColl,[],!0),e.objColl.pop(),o=this.updatePrevShapeSettings(),e.notify("shape",{prop:"setKeyHistory",onPropertyChange:!(r={cancel:!1,action:"delete",previousShapeSettings:o,currentShapeSettings:null}),value:{keyHistory:""}}),e.clearSelection(),e.trigger("shapeChanging",r),e.notify("toolbar",{prop:"refresh-main-toolbar",onPropertyChange:!1}),e.notify("draw",{prop:"render-image",value:{isMouseWheel:null}}),O.isNullOrUndefined(l.objColl[l.objColl.length-1].currIndex)||(e.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"deleteObj",previousObj:l,previousObjColl:this.tempObjColl,previousPointColl:l.pointColl,previousSelPointColl:l.selPointColl,previousCropObj:t,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")},c.prototype.updateFreehandDrawColorChange=function(){var e,t=this.parent,o={freehandSelectedIndex:null};t.notify("freehand-draw",{prop:"getFreehandSelectedIndex",onPropertyChange:!1,value:{obj:o}}),O.isNullOrUndefined(o.freehandSelectedIndex)||O.isNullOrUndefined(t.pointColl[o.freehandSelectedIndex])||"#42a5f5"!==t.pointColl[o.freehandSelectedIndex].strokeColor||(t.notify("freehand-draw",{prop:"getTempFreeHandDrawEditingStyles",value:{obj:e={tempFreeHandDrawEditingStyles:null}}}),t.pointColl[o.freehandSelectedIndex].strokeColor=e.tempFreeHandDrawEditingStyles.strokeColor)},c.prototype.updatePrevShapeSettings=function(e){var t=this.parent,o=[],i=(O.isNullOrUndefined(t.activeObj.currIndex)&&(i={id:"shape_"+(t.objColl.length+1)},t.notify("shape",{prop:"getNewShapeId",onPropertyChange:!1,value:{obj:i}}),t.activeObj.currIndex=i.id),"text"===t.activeObj.shape&&t.activeObj.textSettings&&(t.activeObj.textSettings.bold&&o.push("bold"),t.activeObj.textSettings.italic&&o.push("italic"),t.activeObj.textSettings.underline)&&o.push("underline"),t.activeObj.activePoint),r=i.startX,n=i.startY,a=i.endX,s=i.endY,l=i.width,i=i.height,p=t.activeObj,h=p.keyHistory,d=p.currIndex,c=p.shape,u=p.textSettings,g=p.strokeSettings,v=p.rotatedAngle,f=p.imageElement,p=p.opacity,d={id:O.isNullOrUndefined(d)?null:d,type:t.toPascalCase(c),startX:r,startY:n,width:l,height:i,strokeColor:g?g.strokeColor:null,strokeWidth:g?g.strokeWidth:null,fillColor:g?g.fillColor:null,radius:"ellipse"===c?l/2:null,length:"line"===c||"arrow"===c?l:null,text:"text"===c&&(h||u.text)||null,fontSize:"text"===c&&u?u.fontSize:null,fontFamily:"text"===c&&u?u.fontFamily:null,fontStyle:"text"===c?o:null,color:"text"===c&&g?g.strokeColor:null,degree:"ellipse"===c||"rectangle"===c||"image"===c||"text"===c?v*(180/Math.PI):null,imageData:"image"===c?f.src:null,opacity:"image"===c?p:null,radiusX:"ellipse"===c?l/2:null,radiusY:"ellipse"===c?i/2:null,endX:"line"===c||"arrow"===c?a:null,endY:"line"===c||"arrow"===c?s:null,arrowHead:"arrow"===c?this.getArrowType(t.activeObj.start):null,arrowTail:"arrow"===c?this.getArrowType(t.activeObj.end):null,points:"path"===c?t.activeObj.pointColl:null,index:t.activeObj.order};return e&&(e.shapeSettingsObj=d),d},c.prototype.getArrowType=function(e){return{none:"None",arrow:"Arrow",arrowSolid:"SolidArrow",circle:"Circle",circleSolid:"SolidCircle",square:"Square",squareSolid:"SolidSquare",bar:"Bar"}[""+e]},c.prototype.getRectanglePoints=function(e,t,o,i,r,n,a){var e=e+o/2,t=t+i/2,r=r*(Math.PI/180),s=Math.cos(r),r=Math.sin(r),n=n-e,e=a-t,a=n*s+e*r,t=-n*r+e*s,n=o/2,r=i/2;return-n<=a&&a<=n&&-r<=t&&t<=r},c.prototype.getTransRotationPoint=function(e,t){var o,i=!1,r=!1,n=0===e.shapeDegree?this.parent.transform.degree:this.parent.transform.degree-e.shapeDegree;if(n<0&&(n=360+n),e.flipObjColl)for(var a=0,s=e.flipObjColl.length;a<s;a++)"horizontal"===e.flipObjColl[a].toLowerCase()?i=!0:"vertical"===e.flipObjColl[a].toLowerCase()&&(r=!0);return 0===n||360===n?o=r?{x:e.topCenterCircle.startX,y:e.topCenterCircle.startY-e.rotationCircleLine}:{x:e.bottomCenterCircle.startX,y:e.bottomCenterCircle.startY+e.rotationCircleLine}:90===n||-270===n?o=i?{x:e.centerRightCircle.startX+e.rotationCircleLine,y:e.centerLeftCircle.startY}:{x:e.centerLeftCircle.startX-e.rotationCircleLine,y:e.centerLeftCircle.startY}:180===n||-180===n?o=r?{x:e.bottomCenterCircle.startX,y:e.bottomCenterCircle.startY+e.rotationCircleLine}:{x:e.topCenterCircle.startX,y:e.topCenterCircle.startY-e.rotationCircleLine}:270!==n&&-90!==n||(o=i?{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},c.prototype.getNumTextValue=function(e){var t,o,i=this.parent.element,r=i.querySelector("#"+i.id+"_resizeWidth"),i=i.querySelector("#"+i.id+"_resizeHeight");return r&&i&&(t=i.value.replace(/,/g,""),o=r.value.replace(/,/g,""),""===t&&(t=i.placeholder.replace(/,/g,"")),""===o&&(o=r.placeholder.replace(/,/g,"")),t=parseFloat(t),o=parseFloat(o)),e&&(e.width=o,e.height=t),{x:o,y:t}},c.prototype.isValueUpdated=function(){var e=!0,t=this.parent.element.querySelector("#"+this.parent.element.id+"_resizeWidth"),o=this.parent.element.querySelector("#"+this.parent.element.id+"_resizeHeight");return e=t&&o&&""===o.value.replace(/,/g,"")&&""===t.value.replace(/,/g,"")?!1:e};var h=c;function c(e){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=[v.ArrowheadType.None,v.ArrowheadType.SolidArrow],this.parent=e,this.addEventListener()}C.prototype.destroy=function(){this.parent.isDestroyed||this.removeEventListener()},C.prototype.addEventListener=function(){this.parent.on("shape",this.shape,this),this.parent.on("destroyed",this.destroy,this)},C.prototype.removeEventListener=function(){this.parent.off("shape",this.shape),this.parent.off("destroyed",this.destroy)},C.prototype.shape=function(e){var t,o=this.parent;switch(this.initShapePvtProps(),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":O.EventHandler.add(o.upperCanvas,"dblclick",this.findTextTarget,this),O.EventHandler.add(o.textArea,"mousedown",this.findTextTarget,this),(t=document.getElementById(o.element.id+"_fileUpload"))&&O.EventHandler.add(t,"change",this.fileChanged,this);break;case"unWireEvent":O.EventHandler.remove(o.upperCanvas,"dblclick",this.findTextTarget),O.EventHandler.remove(o.textArea,"mousedown",this.findTextTarget),(t=document.getElementById(o.element.id+"_fileUpload"))&&O.EventHandler.remove(t,"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()}},C.prototype.getModuleName=function(){return"shape"},C.prototype.initShapePvtProps=function(){var e=this.parent;e.lowerCanvas&&(this.lowerContext=e.lowerCanvas.getContext("2d")),e.upperCanvas&&(this.upperContext=e.upperCanvas.getContext("2d")),O.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)},C.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},C.prototype.drawEllipse=function(e,t,o,i,r,n,a,s,l){this.initializeShape("ellipse"),this.drawShape("ellipse",r,n,a,e&&t?{x:e,y:t}:null,o,i,null,null,null,s,null,l)},C.prototype.drawLine=function(e,t,o,i,r,n,a){this.initializeShape("line"),this.drawShape("line",r,n,null,e&&t?{x:e,y:t}:null,o-e,i-t,null,null,null,null,null,a)},C.prototype.drawPath=function(e,t,o,i){var r=this.parent;this.initializeShape("path"),e?this.drawShape("path",t,o,null,null,null,null,e,null,null,null,null,i):(this.drawShape("line",t,o,null,null,null,null,null,null,null,null,null,i),(e=O.extend({},r.objColl[r.objColl.length-1],null,!0)).shape="path",e.lineDraw=null,e.pointColl=[{x:e.activePoint.startX,y:e.activePoint.startY},{x:e.activePoint.endX,y:e.activePoint.endY}],r.objColl[r.objColl.length-1]=e)},C.prototype.drawArrow=function(e,t,o,i,r,n,a,s,l){this.initializeShape("arrow"),this.drawShape("arrow",r,n,null,e&&t?{x:e,y:t}:null,o-e,i-t,null,a,s,null,null,l)},C.prototype.drawRectangle=function(e,t,o,i,r,n,a,s,l){this.initializeShape("rectangle"),this.drawShape("rectangle",r,n,a,e&&t?{x:e,y:t}:null,o,i,null,null,null,s,null,l)},C.prototype.drawText=function(e,t,o,i,r,n,a,s,l,p){this.drawShapeText(o,i,r,n,a,s,e,t,l,p)},C.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},C.prototype.updateWidthHeight=function(e){return e.activePoint.width=e.activePoint.endX-e.activePoint.startX,e.activePoint.height=e.activePoint.endY-e.activePoint.startY,e},C.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)},C.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},C.prototype.drawShape=function(e,t,o,i,r,n,a,s,l,p,h,d,c){var u,g,v=this.parent;!v.disabled&&v.isImageLoaded&&(v.notify("draw",{prop:"setImageEdited",onPropertyChange:!1}),this.redrawActObj(),u=O.extend([],v.objColl,[],!0),v.togglePen=!1,this.keyHistory="",v.upperCanvas.style.display="block",this.refreshActiveObj(),v.currObjType.shape=e=e.toLowerCase(),"path"===e&&O.isNullOrUndefined(s)?(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})):"freehanddraw"!==e&&""!==e&&(v.activeObj.shape=e,g=v.activeObj.strokeSettings,this.upperContext.clearRect(0,0,v.upperCanvas.width,v.upperCanvas.height),O.isNullOrUndefined(g)&&(g=this.strokeSettings),"path"===e&&s&&(v.activeObj.pointColl=s),null!=d&&(v.activeObj.opacity=d),g.strokeWidth=t||g.strokeWidth,g.strokeColor=o||g.strokeColor,g.fillColor=i||g.fillColor,s=100<v.img.destWidth?100:v.img.destWidth/2,d=100<v.img.destHeight?100:v.img.destHeight/2,v.activeObj.activePoint.width=s,v.activeObj.activePoint.height=d,"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(l),v.activeObj.end=this.getArrowType(p))):"rectangle"===e&&(v.activeObj.activePoint.width+=v.activeObj.activePoint.width/2),this.setDimension(n,a),r?(v.activeObj.activePoint.startX=r.x,v.activeObj.activePoint.startY=r.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(),v.notify("selection",{prop:"updatePrevShapeSettings",onPropertyChange:!(t={shapeSettingsObj:{}}),value:{obj:t}}),v.trigger("shapeChanging",i={cancel:!1,action:"insert",previousShapeSettings:o=t.shapeSettingsObj,currentShapeSettings:o}),this.updateShapeChangeEventArgs(i.currentShapeSettings),this.setDimension(n,a),v.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate"}}),h&&(v.activeObj.rotatedAngle=h*(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:u}}),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&&!c&&v.notify("undo-redo",{prop:"updateUndoRedo",value:{operation:"shapeInsert"},onPropertyChange:!1}),v.isPublicMethod=!1))},C.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()},C.prototype.setPointCollForLineAndArrow=function(){var e=this.parent,t=e.activeObj.shape,o=e.activeObj.activePoint,i=o.startX,r=o.startY,n=o.endX,o=o.endY;if(("line"===t||"arrow"===t)&&(e.activeObj.pointColl=this.getLinePoints(i,r,n,o),e.activeObj.pointColl))for(var a=0,s=e.activeObj.pointColl.length;a<s;a++)e.activeObj.pointColl[a].ratioX=(e.activeObj.pointColl[a].x-e.img.destLeft)/e.img.destWidth,e.activeObj.pointColl[a].ratioY=(e.activeObj.pointColl[a].y-e.img.destTop)/e.img.destHeight},C.prototype.prevObjColl=function(){var e=this.parent,t={currObj:{}},t=(e.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:t}}),this.prevObj=t.currObj,this.prevObj.objColl=O.extend([],e.objColl,[],!0),this.prevObj.pointColl=O.extend([],e.pointColl,[],!0),this.prevObj.afterCropActions=O.extend([],e.afterCropActions,[],!0),{selPointColl:null});e.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:t}}),this.prevObj.selPointColl=O.extend([],t.selPointColl,[],!0)},C.prototype.drawShapeText=function(e,t,o,i,r,n,a,s,l,p){var h=this.parent;!h.disabled&&h.isImageLoaded&&("freehanddraw"===h.currObjType.shape&&(this.apply(),h.upperCanvas.style.cursor=h.cursor="default",h.currObjType.shape=""),h.notify("draw",{prop:"setImageEdited",onPropertyChange:!1}),h.togglePen=!1,this.redrawActObj(),this.prevObjColl(),this.refreshActiveObj(),h.activeObj.shape=h.currObjType.shape="text",h.currObjType.isCustomCrop=!1,this.initializeTextShape(e,t,o,i,r,n),h.currObjType.isText=h.currObjType.isInitialText=!0,O.isNullOrUndefined(h.activeObj.textSettings.fontSize)&&(h.getFontSizes(),h.activeObj.textSettings.fontSize=parseInt(h.fontSizeColl[parseInt("3",10)-1].text,10)),h.img.destWidth<100?h.activeObj.textSettings.fontSize=Math.floor(h.img.destWidth/20):h.img.destHeight<100&&(h.activeObj.textSettings.fontSize=Math.floor(h.img.destHeight/20)),h.activeObj.shapeDegree=h.transform.degree,h.activeObj.shapeFlip=h.transform.currFlipState,h.activeObj.flipObjColl=[],this.updateFontStyles(),h.activeObj.order=this.getNewOrder(),t=this.upperContext.measureText(h.activeObj.textSettings.text).width+.5*h.activeObj.textSettings.fontSize,o=h.activeObj.textSettings.fontSize+.25*h.activeObj.textSettings.fontSize,O.isNullOrUndefined(a)||O.isNullOrUndefined(s)?this.setCenterPoints(!0,t,o):(h.activeObj.activePoint.startX=a,h.activeObj.activePoint.startY=s,h.activeObj.activePoint.endX=h.activeObj.activePoint.startX+t,h.activeObj.activePoint.endY=h.activeObj.activePoint.startY+o),h.notify("selection",{prop:"updatePrevShapeSettings",onPropertyChange:!(i={shapeSettingsObj:{}}),value:{obj:i}}),h.trigger("shapeChanging",n={cancel:!1,action:"insert",previousShapeSettings:r=i.shapeSettingsObj,currentShapeSettings:r}),this.drawShapeTextEvent(n),p&&(h.activeObj.rotatedAngle=p*(Math.PI/180),h.notify("selection",{prop:"updPtCollForShpRot",onPropertyChange:!1,value:{obj:h.activeObj}}),this.upperContext.clearRect(0,0,h.upperCanvas.width,h.upperCanvas.height),h.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate",obj:h.activeObj,isCropRatio:null,points:null,isPreventDrag:!0,saveContext:null,isPreventSelection:null}}),h.notify("toolbar",{prop:"destroy-qa-toolbar",onPropertyChange:!1}),h.notify("toolbar",{prop:"renderQAT",onPropertyChange:!1,value:{isPenEdit:null}})),e&&-1<e.indexOf("\n")&&h.isPublicMethod&&(a=String(h.fontSizeColl.findIndex(function(e){return e.text===String(h.activeObj.textSettings.fontSize)})+1),h.noPushUndo=!0,h.updateFontSize("5"),h.updateFontSize(a),h.noPushUndo=!1),h.isPublicMethod&&!l&&h.notify("undo-redo",{prop:"updateUndoRedo",value:{operation:"shapeInsert"},onPropertyChange:!1}),h.isPublicMethod=!1)},C.prototype.drawShapeImageEvent=function(e,t){var o=this.parent,e=(this.updateShapeChangeEventArgs(e.currentShapeSettings),o.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate"}}),o.objColl.push(o.activeObj),O.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:e,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),o.notify("selection",{prop:"redrawShape",onPropertyChange:!1,value:{obj:o.objColl[o.objColl.length-1]}}),t?(o.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"shapes",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}}),o.notify("toolbar",{prop:"update-toolbar-items",onPropertyChange:!1}),o.notify("toolbar",{prop:"renderQAT",onPropertyChange:!1,value:{isPenEdit:null}})):o.okBtn(null,!0),o.notify("selection",{prop:"isShapeInserted",onPropertyChange:!1,value:{bool:!0}})},C.prototype.drawShapeTextEvent=function(e){var t=this.parent,e=(this.updateShapeChangeEventArgs(e.currentShapeSettings),this.addLetter(t.activeObj.textSettings.text),t.activeObj.textFlip=t.transform.currFlipState,this.updateFontRatio(t.activeObj),t.objColl.push(t.activeObj),O.extend({},t.cropObj,{},!0));t.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:e,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),t.notify("selection",{prop:"redrawShape",onPropertyChange:!1,value:{obj:t.objColl[t.objColl.length-1]}}),t.notify("toolbar",{prop:"renderQAT",onPropertyChange:!1,value:{isPenEdit:null}}),t.notify("selection",{prop:"isShapeInserted",onPropertyChange:!1,value:{bool:!0}}),t.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"text",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}}),t.notify("toolbar",{prop:"update-toolbar-items",onPropertyChange:!1})},C.prototype.initializeTextShape=function(e,t,o,i,r,n){var a=this.parent;this.keyHistory="",a.upperCanvas.style.display="block",O.isNullOrUndefined(a.activeObj.textSettings)&&(a.activeObj.textSettings=this.textSettings),O.isNullOrUndefined(a.activeObj.strokeSettings)&&(a.activeObj.strokeSettings=this.strokeSettings),a.activeObj.strokeSettings.strokeColor=n||a.activeObj.strokeSettings.strokeColor,a.activeObj.textSettings.text=e||a.activeObj.textSettings.text,a.activeObj.textSettings.fontFamily=t||a.activeObj.textSettings.fontFamily,a.activeObj.textSettings.fontSize=o||a.activeObj.textSettings.fontSize,a.activeObj.textSettings.bold=i||a.activeObj.textSettings.bold,a.activeObj.textSettings.italic=r||a.activeObj.textSettings.italic},C.prototype.drawImage=function(e,t,o,i,r,n,a,s,l){this.initializeShape("image"),this.onLoadImgShape(e,t,o,i,r,null,n,a,s,l)},C.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))},C.prototype.apply=function(e,t,o){var i,r,n,a,s,l=this.parent;l.disabled||(l.togglePen&&!l.currObjType.isCustomCrop?(i=l.img.destLeft,r=l.img.destTop,n=l.img.destWidth,a=l.img.destHeight,l.notify("draw",{prop:"callUpdateCurrTransState",onPropertyChange:!1}),s=this.lowerContext.filter,this.lowerContext.filter="none",l.togglePen=!1,(l.isCircleCrop||l.currSelectionPoint&&"crop-circle"===l.currSelectionPoint.shape)&&l.notify("crop",{prop:"cropCircle",onPropertyChange:!1,value:{context:this.lowerContext,isSave:null,isFlip:null}}),l.img.destLeft=i,l.img.destTop=r,l.img.destWidth=n,l.img.destHeight=a,this.lowerContext.filter=s):(o=o||"original",O.isNullOrUndefined(l.activeObj.shape)&&O.isNullOrUndefined(e)?l.currObjType.shape="":l.currObjType.shape=e||l.currObjType.shape,""!==l.currObjType.shape&&(this.upperContext.clearRect(0,0,l.upperCanvas.width,l.upperCanvas.height),"text"===l.activeObj.shape?l.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:o,obj:t,isCropRatio:null,points:null,isPreventDrag:!0,saveContext:null,isPreventSelection:null}}):l.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:o,obj:t}}),l.activeObj.shape=l.currObjType.shape.toLowerCase(),e||""===l.currObjType.shape||l.currObjType.isCustomCrop||l.objColl.push(O.extend({},l.activeObj,{},!0)),this.keyHistory="")))},C.prototype.setCenterPoints=function(e,t,o){var i,r=this.parent,e=e&&t&&o?(i=t,o):(i=r.activeObj.activePoint.width,r.activeObj.activePoint.height);r.activeObj.activePoint.startX=r.lowerCanvas.width/2-i/2,r.activeObj.activePoint.startY=r.lowerCanvas.height/2-e/2,r.activeObj.activePoint.endX=r.lowerCanvas.width/2+i/2,r.activeObj.activePoint.endY=r.lowerCanvas.height/2+e/2},C.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},C.prototype.updateShapeChangeEventArgs=function(e){var t,o=this.parent;if(e.id&&-1===e.id.indexOf("shape_")&&-1===e.id.indexOf("pen_")&&(o.activeObj.currIndex?o.activeObj.currIndex="shape_"+e.id:o.pointColl[t].id="pen_"+e.id),e.id&&e.id.split("_")[0]&&"pen"===e.id.split("_")[0])t=parseInt(e.id.split("_")[1],10)-1,o.pointColl[t].points=e.points,o.pointColl[t].strokeColor=e.strokeColor,o.pointColl[t].strokeWidth=e.strokeWidth,o.pointColl[t].opacity=e.opacity,o.pointColl[t].order=e.index;else{switch(o.activeObj.activePoint.startX=e.startX,o.activeObj.activePoint.startY=e.startY,e.width&&e.height&&(o.activeObj.activePoint.width=e.width,o.activeObj.activePoint.height=e.height,o.activeObj.activePoint.endX=o.activeObj.activePoint.startX+o.activeObj.activePoint.width,o.activeObj.activePoint.endY=o.activeObj.activePoint.startY+o.activeObj.activePoint.height),o.activeObj.strokeSettings.strokeColor=e.strokeColor,o.activeObj.strokeSettings.fillColor=e.fillColor,o.activeObj.strokeSettings.strokeWidth=e.strokeWidth,o.activeObj.opacity=e.opacity,o.activeObj.order=e.index,O.isNullOrUndefined(e.degree)&&(e.degree=0),o.activeObj.shape){case"ellipse":o.activeObj.activePoint.width=2*e.radiusX,o.activeObj.activePoint.height=2*e.radiusY,o.activeObj.activePoint.endX=o.activeObj.activePoint.startX+o.activeObj.activePoint.width,o.activeObj.activePoint.endY=o.activeObj.activePoint.startY+o.activeObj.activePoint.height,e.degree&&(o.activeObj.rotatedAngle=e.degree*(Math.PI/180));break;case"line":case"arrow":o.activeObj.activePoint.width=e.length,o.activeObj.activePoint.endX=e.endX,o.activeObj.activePoint.endY=e.endY,o.activeObj.activePoint.width=o.activeObj.activePoint.startX+o.activeObj.activePoint.width,o.activeObj.activePoint.height=o.activeObj.activePoint.startY+o.activeObj.activePoint.height,"arrow"===o.activeObj.shape&&(o.activeObj.start=this.getArrowType(e.arrowHead),o.activeObj.end=this.getArrowType(e.arrowTail));break;case"text":o.activeObj.keyHistory=o.activeObj.textSettings.text=e.text,o.activeObj.textSettings.fontSize=e.fontSize,o.activeObj.strokeSettings.strokeColor=e.color,o.activeObj.textSettings.fontFamily=e.fontFamily,e.degree&&(o.activeObj.rotatedAngle=e.degree*(Math.PI/180)),this.updateFontRatio(o.activeObj);break;case"rectangle":case"image":e.degree&&(o.activeObj.rotatedAngle=e.degree*(Math.PI/180));break;case"path":o.activeObj.pointColl=e.points}if("text"===o.activeObj.shape&&o.activeObj.textSettings){o.activeObj.textSettings.bold=!1,o.activeObj.textSettings.italic=!1,o.activeObj.textSettings.underline=!1;for(var i=0;i<e.fontStyle.length;i++)switch(e.fontStyle[i]){case"bold":o.activeObj.textSettings.bold=!0;break;case"italic":o.activeObj.textSettings.italic=!0;break;case"underline":o.activeObj.textSettings.underline=!0}}}},C.prototype.addLetter=function(e){var t,o,i=this.parent;"none"!==i.textArea.style.display||!i.currObjType.isText&&"text"!==i.activeObj.shape||(t=i.activeObj.textSettings.fontSize,"Backspace"===e?this.keyHistory=this.keyHistory.slice(0,-1):this.keyHistory+=e,this.upperContext.clearRect(0,0,i.upperCanvas.width,i.upperCanvas.height),this.updateFontStyles(),e=this.upperContext.measureText(this.keyHistory).width+.5*t,o=t+.25*t,this.upperContext.fillText(this.keyHistory,i.activeObj.activePoint.startX,i.activeObj.activePoint.startY+t),this.upperContext.clearRect(0,0,i.upperCanvas.width,i.upperCanvas.height),i.currObjType.isText=!0,i.notify("selection",{prop:"setActivePoint",onPropertyChange:!1,value:{startX:e,startY:o}}))},C.prototype.redrawText=function(){var e=this.parent,t=e.activeObj.textSettings,o=t.fontSize,i=t.fontFamily,r="",t=(t.bold&&(r+="bold "),t.italic&&(r+="italic "),this.upperContext.font=r+o+"px "+i,e.activeObj.keyHistory.split("\n")),r="block"===e.textArea.style.display||"inline-block"===e.textArea.style.display?this.getMaxText(!0):this.getMaxText(),i=this.upperContext.measureText(r).width+.5*o,r=t.length*(o+.25*o);e.notify("selection",{prop:"setTextSelection",onPropertyChange:!1,value:{width:i,height:r}}),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}})},C.prototype.updateTextFromTextArea=function(){var e,t=this.parent,o=!1,i=t.activeObj.textSettings.fontSize,r=O.extend({},t.activeObj,{},!0),n=O.extend({},t.cropObj,{},!0),a={currObj:{}},a=(t.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:a}}),a.currObj),s=(a.objColl=O.extend([],t.objColl,[],!0),a.pointColl=O.extend([],t.pointColl,[],!0),a.afterCropActions=O.extend([],t.afterCropActions,[],!0),{selPointColl:null}),s=(t.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:s}}),a.selPointColl=O.extend([],s.selPointColl,[],!0),t.activeObj.keyHistory!==t.textArea.value&&(o=!0),t.activeObj.keyHistory=t.textArea.value,t.textArea.style.display="none",t.textArea.value="",this.updateFontStyles(),this.upperContext.measureText(t.activeObj.keyHistory).width+.5*i),l=i+.25*i,p=t.activeObj.keyHistory.split("\n");if(1<p.length){l*=p.length;for(var h=[],d=0,c=p.length;d<c;d++)h.push(this.upperContext.measureText(p[d]).width+.5*i);s=Math.max.apply(Math,h)}t.notify("selection",{prop:"setTextSelection",onPropertyChange:!1,value:{width:s,height:l}}),0!==t.activeObj.rotatedAngle&&(s=t.activeObj.activePoint.width-r.activePoint.width,l=t.activeObj.activePoint.height-r.activePoint.height,e="",0<s&&0<l?e="widthHeight":0!=s?e="width":0!=l&&(e="height"),t.activeObj.activePoint=O.extend({},r.activePoint,{},!0),t.notify("selection",{prop:"adjustRotationPoints",onPropertyChange:!1,value:{rectangle:t.activeObj.activePoint,x:s,y:l,angle:t.activeObj.rotatedAngle,type:"text",elem:e}}),t.notify("shape",{prop:"updateFontSize",onPropertyChange:!1,value:{obj:t.activeObj}})),t.notify("draw",{prop:"updateActiveObject",onPropertyChange:!1,value:{actPoint:t.activeObj.activePoint,obj:t.activeObj,isMouseMove:null,x:null,y:null}}),this.updImgRatioForActObj(),0!==t.activeObj.rotatedAngle&&t.notify("selection",{prop:"updPtCollForShpRot",onPropertyChange:!1,value:{obj:t.activeObj}}),o?(this.apply(t.activeObj.shape,t.activeObj),t.objColl.push(O.extend({},t.activeObj,{},!0)),t.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"text",previousObj:a,previousObjColl:a.objColl,previousPointColl:a.pointColl,previousSelPointColl:a.selPointColl,previousCropObj:n,previousText:t.activeObj.keyHistory,currentText:t.textArea.value,previousFilter:null,isCircleCrop:null}})):(this.apply(t.activeObj.shape,t.activeObj),t.objColl.push(O.extend({},t.activeObj,{},!0)))},C.prototype.iterateObjColl=function(){var e=this.parent;if(0<e.objColl.length)for(var t=this.getSmallestIndex(),o=O.extend([],e.objColl,[],!0);0<o.length;){for(var i=!1,r=0;r<o.length;r++){var n=o[r];if(O.isNullOrUndefined(n.order))o.splice(r,1),r--;else if(n.order===t){this.apply(n.shape,n),this.refreshActiveObj(),t++,this.isIndexInObjColl(t)||t++,o.splice(r,1),i=!0;break}}if(!i)break}},C.prototype.getSmallestIndex=function(){for(var e,t=this.parent,o=0,i=t.objColl.length;o<i;o++){var r=t.objColl[o];O.isNullOrUndefined(r.order)||(O.isNullOrUndefined(e)||r.order<e)&&(e=r.order)}return e},C.prototype.isIndexInObjColl=function(e){for(var t=this.parent,o=0,i=t.objColl.length;o<i;o++){var r=t.objColl[o];if(!O.isNullOrUndefined(r.order)&&r.order===e)return!0}return!1},C.prototype.updImgRatioForActObj=function(){var e=this.parent,t={startX:e.img.destLeft,startY:e.img.destTop,width:e.img.destWidth,height:e.img.destHeight},o=(this.straightenShapes(),e.img),i=o.destLeft,r=o.destTop,n=o.destWidth,o=o.destHeight,a=e.activeObj.activePoint;e.activeObj.imageRatio={startX:(a.startX-i)/n,startY:(a.startY-r)/o,endX:(a.endX-i)/n,endY:(a.endY-r)/o,width:n/a.width,height:o/a.height},e.activeObj.rotationCirclePointColl&&(e.activeObj.rotationCirclePointColl.ratioX=(e.activeObj.rotationCirclePointColl.x-i)/n,e.activeObj.rotationCirclePointColl.ratioY=(e.activeObj.rotationCirclePointColl.y-r)/o),"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},C.prototype.zoomObjColl=function(e){var t=this.parent,o={startX:t.img.destLeft,startY:t.img.destTop,width:t.img.destWidth,height:t.img.destHeight};if(this.straightenShapes(),0<t.objColl.length){for(var i=0,r=t.objColl.length;i<r;i++){var n=t.objColl[i];if(n.imageRatio&&(n.activePoint.startX=n.imageRatio.startX*t.img.destWidth+t.img.destLeft,n.activePoint.startY=n.imageRatio.startY*t.img.destHeight+t.img.destTop,n.activePoint.endX=n.imageRatio.endX*t.img.destWidth+t.img.destLeft,n.activePoint.endY=n.imageRatio.endY*t.img.destHeight+t.img.destTop),"text"===(n=this.updateWidthHeight(n)).shape)this.updateFontSize(n);else if("line"===n.shape||"arrow"===n.shape){n.pointColl=this.getLinePoints(n.activePoint.startX,n.activePoint.startY,n.activePoint.endX,n.activePoint.endY);for(var a=0,s=n.pointColl.length;a<s;a++)n.pointColl[a].ratioX=(n.pointColl[a].x-t.img.destLeft)/t.img.destWidth,n.pointColl[a].ratioY=(n.pointColl[a].y-t.img.destTop)/t.img.destHeight;"arrow"===n.shape&&this.updateArrowSize(n),0===t.transform.straighten||"line"!==n.shape&&"arrow"!==n.shape||this.straightenShapePoints(n)}else if("path"===n.shape){for(var l=0,p=n.pointColl.length;l<p;l++)n.pointColl[l].x=n.pointColl[l].ratioX*t.img.destWidth+t.img.destLeft,n.pointColl[l].y=n.pointColl[l].ratioY*t.img.destHeight+t.img.destTop;this.updatePathRatio(n),0!==t.transform.straighten&&this.straightenPath(n)}t.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*t.img.destWidth+t.img.destLeft,n.rotationCirclePoint.y=n.rotationCirclePoint.ratioY*t.img.destHeight+t.img.destTop,n.rotationCirclePointColl)&&(n.rotationCirclePointColl.x=n.rotationCirclePointColl.ratioX*t.img.destWidth+t.img.destLeft,n.rotationCirclePointColl.y=n.rotationCirclePointColl.ratioY*t.img.destHeight+t.img.destTop)}O.isNullOrUndefined(e)&&(e=this.lowerContext.filter,this.lowerContext.filter="none",this.iterateObjColl(),this.lowerContext.filter=e)}t.img.destLeft=o.startX,t.img.destTop=o.startY,t.img.destWidth=o.width,t.img.destHeight=o.height},C.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},C.prototype.straightenFHD=function(){for(var e=this.parent,t=0,o=e.freehandCounter;t<o;t++){e.points=O.extend([],e.pointColl[t].points,[]);for(var i=e.points.length,r=void 0,n=0;n<i;n++)r=this.straightenPoints(e.points[n].x,e.points[n].y),e.points[n].x=r.x,e.points[n].y=r.y}var a={selPointColl:null};e.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:a}});for(t=0,o=e.freehandCounter;t<o;t++)for(i=a.selPointColl[t].points.length,r=void 0,n=0;n<i;n++)r=this.straightenPoints(a.selPointColl[t].points[n].x,a.selPointColl[t].points[n].y),a.selPointColl[t].points[n].x=r.x,a.selPointColl[t].points[n].y=r.y;var s,l={straightenPoint:null};e.notify("freehand-draw",{prop:"getStraightenPoint",onPropertyChange:!1,value:{obj:l}}),l.straightenPoint.x&&l.straightenPoint.y&&(e.notify("freehand-draw",{prop:"getStraightenPointAngle",onPropertyChange:!(s={angle:0}),value:{obj:s}}),s=((360===e.transform.straighten?0:e.transform.straighten)-s.angle)*(Math.PI/180),r=this.straightenPoints(l.straightenPoint.x,l.straightenPoint.y,s),0==s&&(r.x=l.straightenPoint.x,r.y=l.straightenPoint.y),e.notify("freehand-draw",{prop:"setStraightenPoint",onPropertyChange:!1,value:{x:r.x,y:r.y}}))},C.prototype.straightenPoints=function(e,t,o){var i=this.parent,r=i.img.destLeft+i.img.destWidth/2,n=i.img.destTop+i.img.destHeight/2;return o=o||i.transform.straighten*(Math.PI/180),{x:Math.cos(o)*(e-r)-Math.sin(o)*(t-n)+r,y:Math.sin(o)*(e-r)+Math.cos(o)*(t-n)+n}},C.prototype.straightenShapes=function(){var e,t,o,i=this.parent,r=i.img,n=r.destLeft,a=r.destTop,s=r.destWidth,r=r.destHeight;i.isStraightening&&0!==i.transform.straighten&&(i.notify("draw",{prop:"updateImgCanvasPoints"}),i.notify("draw",{prop:"getImageCanvasPoints",value:{obj:e={points:null}}}),n=n+s/2,s=a+r/2,a=-(i.transform.straighten*(Math.PI/180)),r={x:Math.cos(a)*(e.points[0].x-n)-Math.sin(a)*(e.points[0].y-s)+n,y:Math.sin(a)*(e.points[0].x-n)+Math.cos(a)*(e.points[0].y-s)+s},t=Math.cos(a)*(e.points[1].x-n)-Math.sin(a)*(e.points[1].y-s)+n,o=Math.sin(a)*(e.points[1].x-n)+Math.cos(a)*(e.points[1].y-s)+s,Math.cos(a),e.points[2].x,Math.sin(a),e.points[2].y,n=Math.sin(a)*(e.points[2].x-n)+Math.cos(a)*(e.points[2].y-s)+s,i.img.destWidth=t-r.x,i.img.destHeight=n-o,i.img.destLeft=r.x,i.img.destTop=r.y)},C.prototype.straightenShapePoints=function(e,t){var o=this.parent,i=o.img,r=i.destLeft,n=i.destTop,a=i.destWidth,i=i.destHeight;!o.isStraightening||"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,r=r+a/2,a=n+i/2,n=(t?-o.transform.straighten:o.transform.straighten)*(Math.PI/180),i={x:Math.cos(n)*(e.activePoint.startX-r)-Math.sin(n)*(e.activePoint.startY-a)+r,y:Math.sin(n)*(e.activePoint.startX-r)+Math.cos(n)*(e.activePoint.startY-a)+a},t={x:Math.cos(n)*(e.activePoint.endX-r)-Math.sin(n)*(e.activePoint.endY-a)+r,y:Math.sin(n)*(e.activePoint.endX-r)+Math.cos(n)*(e.activePoint.endY-a)+a},e.activePoint.startX=i.x,e.activePoint.startY=i.y,e.activePoint.endX=t.x,e.activePoint.endY=t.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}}))},C.prototype.redrawObj=function(e){var t=this.parent,o=!1;if(0<t.objColl.length)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);e=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 i=0,r=t.objColl.length;i<r;i++)"crop"!==t.objColl[i].shape.split("-")[0]&&(this.apply(t.objColl[i].shape,t.objColl[i]),o=!0);o&&t.notify("draw",{prop:"applyFrame",value:{ctx:this.lowerContext,frame:t.frameObj.type,preventImg:!0}}),this.lowerContext.filter=e}},C.prototype.updateCurrentActiveObjPoint=function(e){for(var t,o=this.parent,i=o.img,r=i.destLeft,n=i.destTop,a=i.destWidth,s=i.destHeight,l=0,p=o.objColl.length;l<p;l++){var h=o.objColl[l];if(o.activeObj.shape===h.shape&&o.activeObj.activePoint.startX===h.activePoint.startX&&o.activeObj.activePoint.startY===h.activePoint.startY&&o.activeObj.activePoint.endX===h.activePoint.endX&&o.activeObj.activePoint.endY===h.activePoint.endY&&o.activeObj.currIndex===h.currIndex){t=l;break}}if("horizontal"===e||"vertical"===e||"Horizontal"===e||"Vertical"===e||"horizontalvertical"===e||"verticalhorizontal"===e){if("horizontal"===e||"Horizontal"===e)for(var d=0,p=o.objColl.length;d<p;d++)(h=o.objColl[d]).shapeFlip!==o.transform.currFlipState&&(h.activePoint.startX<=r+a/2?(h.activePoint.endX=r+a-(h.activePoint.startX-r),h.activePoint.startX=h.activePoint.endX-h.activePoint.width,o.notify("draw",{prop:"updateActiveObject",onPropertyChange:!1,value:{actPoint:h.activePoint,obj:h}})):h.activePoint.startX>=r+a/2&&(h.activePoint.startX=r+(r+a-h.activePoint.endX),h.activePoint.endX=h.activePoint.startX+h.activePoint.width,o.notify("draw",{prop:"updateActiveObject",onPropertyChange:!1,value:{actPoint:h.activePoint,obj:h}})),"line"===h.shape||"arrow"===h.shape||"path"===h.shape?this.flipLineArrowObj(h,"horizontal"):0!==h.rotatedAngle&&(h.rotatedAngle=h.rotatedAngle+2*(Math.PI-h.rotatedAngle),h.rotationCirclePointColl.x<=r+a/2?h.rotationCirclePointColl.x=r+a-(h.rotationCirclePointColl.x-r):h.rotationCirclePointColl.x>=r+a/2&&(h.rotationCirclePointColl.x=r+(r+a-h.rotationCirclePointColl.x)),h.rotationCirclePointColl.ratioX=(h.rotationCirclePointColl.x-r)/a),h.shapeFlip=o.transform.currFlipState,h.imageRatio={startX:(h.activePoint.startX-r)/a,startY:(h.activePoint.startY-n)/s,endX:(h.activePoint.endX-r)/a,endY:(h.activePoint.endY-n)/s,width:a/h.activePoint.width,height:s/h.activePoint.height});else if("vertical"===e||"Vertical"===e)for(d=0;d<o.objColl.length;d++)(h=o.objColl[d]).shapeFlip!==o.transform.currFlipState&&(h.activePoint.startY<=n+s/2?(h.activePoint.endY=n+s-(h.activePoint.startY-n),h.activePoint.startY=h.activePoint.endY-h.activePoint.height,o.notify("draw",{prop:"updateActiveObject",onPropertyChange:!1,value:{actPoint:h.activePoint,obj:h}})):h.activePoint.startY>=o.lowerCanvas.height/2&&(h.activePoint.startY=n+(n+s-h.activePoint.endY),h.activePoint.endY=h.activePoint.startY+h.activePoint.height,o.notify("draw",{prop:"updateActiveObject",onPropertyChange:!1,value:{actPoint:h.activePoint,obj:h}})),"line"===h.shape||"arrow"===h.shape||"path"===h.shape?this.flipLineArrowObj(h,"vertical"):0!==h.rotatedAngle&&(h.rotatedAngle=-h.rotatedAngle,h.rotationCirclePointColl.y<=n+s/2?h.rotationCirclePointColl.y=n+s-(h.rotationCirclePointColl.y-n):h.rotationCirclePointColl.y>=n+s/2&&(h.rotationCirclePointColl.y=n+(n+s-h.rotationCirclePointColl.y)),h.rotationCirclePointColl.ratioY=(h.rotationCirclePointColl.y-n)/s),h.shapeFlip=o.transform.currFlipState,h.imageRatio={startX:(h.activePoint.startX-r)/a,startY:(h.activePoint.startY-n)/s,endX:(h.activePoint.endX-r)/a,endY:(h.activePoint.endY-n)/s,width:a/h.activePoint.width,height:s/h.activePoint.height});else if("verticalhorizontal"===e||"horizontalvertical"===e)for(d=0,p=o.objColl.length;d<p;d++)(h=o.objColl[d]).shapeFlip!==o.transform.currFlipState&&(h.activePoint.startX<=r+a/2?(h.activePoint.endX=r+a-(h.activePoint.startX-r),h.activePoint.startX=h.activePoint.endX-h.activePoint.width,o.notify("draw",{prop:"updateActiveObject",onPropertyChange:!1,value:{actPoint:h.activePoint,obj:h}})):h.activePoint.startX>=r+a/2&&(h.activePoint.startX=r+(r+a-h.activePoint.endX),h.activePoint.endX=h.activePoint.startX+h.activePoint.width,o.notify("draw",{prop:"updateActiveObject",onPropertyChange:!1,value:{actPoint:h.activePoint,obj:h}})),h.activePoint.startY<=n+s/2?(h.activePoint.endY=n+s-(h.activePoint.startY-n),h.activePoint.startY=h.activePoint.endY-h.activePoint.height,o.notify("draw",{prop:"updateActiveObject",onPropertyChange:!1,value:{actPoint:h.activePoint,obj:h}})):h.activePoint.startY>=o.lowerCanvas.height/2&&(h.activePoint.startY=n+(n+s-h.activePoint.endY),h.activePoint.endY=h.activePoint.startY+h.activePoint.height,o.notify("draw",{prop:"updateActiveObject",onPropertyChange:!1,value:{actPoint:h.activePoint,obj:h}})),"line"!==h.shape&&"arrow"!==h.shape&&"path"!==h.shape||this.flipLineArrowObj(h,e),h.shapeFlip=o.transform.currFlipState,h.imageRatio={startX:(h.activePoint.startX-r)/a,startY:(h.activePoint.startY-n)/s,endX:(h.activePoint.endX-r)/a,endY:(h.activePoint.endY-n)/s,width:a/h.activePoint.width,height:s/h.activePoint.height});void 0!==t&&(o.activeObj=O.extend({},o.objColl[t],{},!0))}else if(90===e)this.rotateObjColl();else if(-90===e)for(d=0;d<3;d++)this.rotateObjColl();else if("number"==typeof e)if(0<e)this.rotateObjColl();else for(d=0;d<3;d++)this.rotateObjColl()},C.prototype.rotateObjColl=function(){for(var e=this.parent,t=e.img,o=t.destWidth,i=t.destHeight,r=t.destLeft,n=t.destTop,a=0,s=e.objColl.length;a<s;a++){var l=(p=e.objColl[a]).shape;p.activePoint.startY=n+i*p.imageRatio.startX,p.activePoint.endY=n+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[a]),this.updateFontSize(p),"line"===l||"arrow"===l||"path"===l?(this.rotateLineArrowObj(p),"arrow"===l&&this.updateArrowSize(p)):0!==p.rotatedAngle&&(p.rotationCirclePointColl.y=n+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-n)/i)}for(a=0,s=e.objColl.length;a<s;a++)e.notify("draw",{prop:"updateActiveObject",onPropertyChange:!1,value:{actPoint:e.objColl[a].activePoint,obj:e.objColl[a]}});for(var p,a=0,s=e.objColl.length;a<s;a++)(p=e.objColl[a]).imageRatio={startX:(p.activePoint.startX-r)/o,startY:(p.activePoint.startY-n)/i,endX:(p.activePoint.endX-r)/o,endY:(p.activePoint.endY-n)/i,width:o/p.activePoint.width,height:i/p.activePoint.height}},C.prototype.rotateLineArrowObj=function(e){if(!O.isNullOrUndefined(e.pointColl)){var t=this.parent.img,o=t.destWidth,i=t.destHeight,r=t.destLeft,n=t.destTop;if(0<e.pointColl.length){for(var a=0;a<e.pointColl.length;a++)e.pointColl[a].y=n+i*e.pointColl[a].ratioX,e.pointColl[a].x=r+o-o*e.pointColl[a].ratioY;for(a=0;a<e.pointColl.length;a++)e.pointColl[a].ratioX=(e.pointColl[a].x-r)/o,e.pointColl[a].ratioY=(e.pointColl[a].y-n)/i;var t=void 0,t=O.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},s=e.pointColl[e.pointColl.length-1].x-t.x,t=e.pointColl[e.pointColl.length-1].y-t.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+s/2,e.activePoint.endY=e.pointColl[e.pointColl.length-1].y+t/2,this.updateWidthHeight(e)}}},C.prototype.flipLineArrowObj=function(e,t){t=t.toLowerCase(),O.isNullOrUndefined(e.pointColl)||("horizontal"===t?this.lineArrowHorizontalFlip(e):("vertical"!==t&&(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&&(t=e.activePoint.startX,e.activePoint.startX=e.activePoint.endX,e.activePoint.endX=t,t=e.activePoint.startY,e.activePoint.startY=e.activePoint.endY,e.activePoint.endY=t))},C.prototype.lineArrowHorizontalFlip=function(e){var t=this.parent,o=t.img,i=o.destWidth,r=o.destHeight,n=o.destLeft,a=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<=n+i/2?p.x=n+i-(p.x-n):p.x>=n+i/2&&(p.x=n+(n+i-p.x)),p.ratioX=(p.x-n)/i,p.ratioY=(p.y-a)/r}"arrow"===e.shape&&(o=e.start,e.start=e.end,e.end=o),e.shapeFlip=t.transform.currFlipState}},C.prototype.lineArrowVerticalFlip=function(e){var t=this.parent,o=t.img,i=o.destWidth,r=o.destHeight,n=o.destLeft,a=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<=a+r/2?p.y=a+r-(p.y-a):p.y>=a+r/2&&(p.y=a+(a+r-p.y)),p.ratioX=(p.x-n)/i,p.ratioY=(p.y-a)/r}e.shapeFlip=t.transform.currFlipState}},C.prototype.getRotDegOfShape=function(e){e=0===e.shapeDegree?this.parent.transform.degree:this.parent.transform.degree-e.shapeDegree;return e=e<0?360+e:e},C.prototype.renderTextArea=function(e,t,o){var i=this.parent,r=this.getRotDegOfShape(i.activeObj),n=(this.transformTextArea(),i.notify("toolbar",{prop:"destroy-qa-toolbar",onPropertyChange:!1}),i.element.querySelector("#"+i.element.id+"_zOrderBtn")),a=i.element.querySelector("#"+i.element.id+"_duplicate"),s=i.element.querySelector("#"+i.element.id+"_remove"),l=i.element.querySelector("#"+i.element.id+"_editText"),n=(n&&n.classList.add("e-disabled"),a&&a.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,o.activePoint),a=n.width,s=n.height,l=(r%90==0&&r%180!=0&&0!==r?(i.textArea.style.width=s+"px",i.textArea.style.height=a+"px"):(i.textArea.style.width=a+"px",i.textArea.style.height=s+"px"),this.setTextBoxWidth(),{flipColl:null});if(i.notify("transform",{prop:"getFlipColl",onPropertyChange:!1,value:{obj:l}}),l.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 p=parseFloat(i.textArea.style.left),e=parseFloat(i.textArea.style.top),h=(0<o.flipObjColl.length&&(n=(t=i.lowerCanvas).clientWidth,a=t.clientHeight,i.notify("crop",{prop:"getCurrFlipState",onPropertyChange:!(s={x:0,y:0}),value:{panObj:l={panRegion:""}}}),""!==l.panRegion)&&("horizontal"===l.panRegion?(s.x=n-n/2,p=s.x-p+s.x):e=("vertical"===l.panRegion?s.y=a-a/2:p=(s={x:n-n/2,y:a-a/2}).x-p+s.x,s.y-e+s.y)),p+parseFloat(i.textArea.style.width)),d=e+parseFloat(i.textArea.style.height),c=parseFloat(i.textArea.style.width),u=parseFloat(i.textArea.style.height),g={x:h-c/2,y:d-u/2},v=Math.cos(o.rotatedAngle),f=Math.sin(o.rotatedAngle),C={x:v*(h-g.x)-f*(d-g.y)+g.x,y:f*(h-g.x)+v*(d-g.y)+g.y};if(C.x>i.img.destLeft&&C.x<i.img.destLeft+i.img.destWidth&&C.y>i.img.destTop&&C.y+parseFloat(i.textArea.style.fontSize)<i.img.destTop+i.img.destHeight)i.textArea.style.width=i.textArea.style.width;else for(var b=0,m=parseFloat(i.textArea.style.width);;)if(b++,(C={x:v*((h=p+--c)-(g={x:h-c/2,y:d-u/2}).x)-f*(d-g.y)+g.x,y:f*(h-g.x)+v*(d-g.y)+g.y}).x>i.img.destLeft&&C.x<i.img.destLeft+i.img.destWidth&&C.y>i.img.destTop&&C.y+parseFloat(i.textArea.style.fontSize)<i.img.destTop+i.img.destHeight||b===m){i.textArea.style.width=c+"px";break}}i.notify("selection",{prop:"clearUpperCanvas",onPropertyChange:!1})},C.prototype.setTextBoxWidth=function(e){var t,o,i,r,n,a=this.parent;0!==a.activeObj.rotatedAngle?(a.textArea.style.whiteSpace="nowrap",a.textArea.style.textOverflow="ellipsis",a.textArea.style.display="inline-block"):(a.textArea.style.whiteSpace="",a.textArea.style.textOverflow="","inline-block"===a.textArea.style.display&&(a.textArea.style.display="block"),t=this.getMaxText(!0),"block"===a.textArea.style.display||"inline-block"===a.textArea.style.display?this.updateFontStyles(!0):this.updateFontStyles(),t=this.upperContext.measureText(t).width+parseFloat(a.textArea.style.fontSize)/2,o=e?this.upperContext.measureText(String.fromCharCode(e.which)).width:0,r=O.extend({},a.activeObj,{},!0),n="",i=this.getRotDegOfShape(r),n=r.shapeFlip!==a.transform.currFlipState?"":a.transform.currFlipState,(e&&parseFloat(a.textArea.style.width)<t+o||O.isNullOrUndefined(e))&&(0===i?"horizontal"===n.toLowerCase()?0<parseFloat(a.textArea.style.left)-a.img.destLeft-t-o&&(a.textArea.style.width=t+o+"px"):a.img.destWidth-(parseFloat(a.textArea.style.left)-a.img.destLeft)>t+o&&(a.textArea.style.width=t+o+"px"):90===i?"vertical"===n.toLowerCase()?0<parseFloat(a.textArea.style.top)-a.img.destTop-t-o&&(a.textArea.style.width=t+o+"px"):a.img.destHeight-(parseFloat(a.textArea.style.top)-a.img.destTop)>t+o&&(a.textArea.style.width=t+o+"px"):180===i?(r=parseFloat(a.textArea.style.left),e=a.img.destLeft,"horizontal"===n.toLowerCase()?t+o<a.img.destWidth-(r-e)&&(a.textArea.style.width=t+o+"px"):0<r-e-t-o&&(a.textArea.style.width=t+o+"px")):270===i&&(r=parseFloat(a.textArea.style.top),e=a.img.destTop,"vertical"===n.toLowerCase()?t+o<a.img.destHeight-(r-e)&&(a.textArea.style.width=t+o+"px"):0<r-e-t-o&&(a.textArea.style.width=t+o+"px"))))},C.prototype.setTextBoxHeight=function(){var e,t=this.parent,o=O.extend({},t.activeObj,{},!0),i="",r=this.getRotDegOfShape(o),i=o.textFlip===t.transform.currFlipState?"":""===o.textFlip?t.transform.currFlipState:o.textFlip;switch(r){case 0:"vertical"===i.toLowerCase()?t.textArea.style.maxHeight=t.img.destHeight-(t.img.destHeight-parseFloat(t.textArea.style.top))+"px":(e=parseFloat(t.textArea.style.top)-t.img.destTop,t.textArea.style.maxHeight=t.img.destHeight-e+"px");break;case 90:"horizontal"===i.toLowerCase()?t.textArea.style.maxHeight=t.img.destWidth-(parseFloat(t.textArea.style.left)-t.img.destLeft)+"px":t.textArea.style.maxHeight=parseFloat(t.textArea.style.left)-t.img.destLeft+"px";break;case 180:"vertical"===i.toLowerCase()?(e=parseFloat(t.textArea.style.top)-t.img.destTop,t.textArea.style.maxHeight=t.img.destHeight-e+"px"):t.textArea.style.maxHeight=parseFloat(t.textArea.style.top)-t.img.destTop+"px";break;case 270:"horizontal"===i.toLowerCase()?t.textArea.style.maxHeight=parseFloat(t.textArea.style.left)-t.img.destLeft+"px":t.textArea.style.maxHeight=t.img.destWidth-(parseFloat(t.textArea.style.left)-t.img.destLeft)+"px"}},C.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}},C.prototype.stopPathDrawing=function(e,t){var o,i,r,n=this.parent;"path"===n.activeObj.shape&&(n.notify("selection",{prop:"getCurrentDrawingShape",value:{obj:o={shape:null}}}),"path"===o.shape)&&(o=O.extend({},n.cropObj,{},!0),n.notify("filter",{prop:"getCurrentObj",onPropertyChange:!(r={currObj:{}}),value:{object:r}}),(r=r.currObj).objColl=O.extend([],n.objColl,[],!0),r.pointColl=O.extend([],n.pointColl,[],!0),r.afterCropActions=O.extend([],n.afterCropActions,[],!0),n.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!(i={selPointColl:null}),value:{obj:i}}),r.selPointColl=O.extend([],i.selPointColl,[],!0),n.notify("selection",{prop:"setCurrentDrawingShape",value:{value:""}}),n.currObjType.isDragging=!1,e&&"touchstart"!==e.type&&O.isNullOrUndefined(t)&&n.activeObj.pointColl.pop(),this.updatePathRatio(n.activeObj),O.isNullOrUndefined(n.activeObj.imageRatio)&&n.notify("shape",{prop:"updImgRatioForActObj",onPropertyChange:!1}),n.objColl.push(n.activeObj),n.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}}),n.objColl.pop(),e&&(n.notify("selection",{prop:"mouseUpEventHandler",value:{e:e}}),this.lowerContext.clearRect(0,0,n.lowerCanvas.width,n.lowerCanvas.height),n.notify("draw",{prop:"redrawImgWithObj",onPropertyChange:!1})),n.notify("draw",{prop:"setNewPath",value:{bool:!0}}),n.objColl[n.objColl.length-1]&&(i=n.drawingShape,n.notify("selection",{prop:"setCurrentDrawingShape",value:{value:""}}),n.selectShape(n.objColl[n.objColl.length-1].currIndex),n.notify("selection",{prop:"setCurrentDrawingShape",value:{value:"path"}}),n.drawingShape=i),n.notify("toolbar",{prop:"renderQAT",onPropertyChange:!1,value:{isPenEdit:null}}),n.notify("selection",{prop:"updatePrevShapeSettings",onPropertyChange:!(t={shapeSettingsObj:{}}),value:{obj:t}}),n.notify("selection",{prop:"triggerShapeChange",onPropertyChange:!1,value:{shapeResizingArgs:{cancel:!1,action:"draw-end",previousShapeSettings:r=t.shapeSettingsObj},shapeMovingArgs:{cancel:!1,action:"move",previousShapeSettings:r},type:"mouse-up"}}),n.notify("undo-redo",{prop:"updateUndoRedoStack",onPropertyChange:!1}))},C.prototype.findTextTarget=function(e){var t=this.parent;if("text"!==t.activeObj.shape){if("path"===t.activeObj.shape)return void this.stopPathDrawing(e,null);if("dblclick"!==e.type)return;var o=O.extend({},t.activeObj,{},!0),i=O.extend([],t.objColl,[],!0),r={bool:null};if(t.notify("selection",{prop:"findTargetObj",onPropertyChange:!1,value:{x:e.clientX,y:e.clientY,isCrop:!1,obj:r}}),t.objColl=i,!r.bool||"text"!==t.activeObj.shape)return void(t.activeObj=O.extend({},o,{},!0))}if("dblclick"===e.type?(s=e.clientX,l=e.clientY):"touchstart"===e.type&&(s=e.touches[0].clientX,l=e.touches[0].clientY,t.notify("selection",{prop:"setTouchEndPoint",onPropertyChange:!1,value:{x:e.touches[0].clientX,y:e.touches[0].clientY}})),t.notify("toolbar",{prop:"setPreventZoomBtn",onPropertyChange:!1,value:{isPrevent:!0}}),t.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"text",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}}),t.notify("toolbar",{prop:"setPreventZoomBtn",onPropertyChange:!1,value:{isPrevent:!1}}),t.notify("toolbar",{prop:"update-toolbar-items",onPropertyChange:!1}),O.isNullOrUndefined(s)||O.isNullOrUndefined(l))"block"!==t.textArea.style.display&&"inline-block"!==t.textArea.style.display||""===this.selectedText()||"mousedown"!==e.type?"none"===t.textArea.style.display&&(t.textArea.style.display="block"):(n=t.textArea.value,t.textArea.value+="a",t.textArea.value=n);else{var i=t.lowerCanvas.getBoundingClientRect(),o=(s-=i.left,l-=i.top,""),e=this.getRotDegOfShape(t.activeObj),o=""===t.activeObj.textFlip?t.activeObj.textFlip===t.transform.currFlipState?"":t.transform.currFlipState:t.activeObj.textFlip===t.transform.currFlipState?"":""===t.transform.currFlipState?t.activeObj.textFlip:t.transform.currFlipState,n=void 0;if("none"===t.textArea.style.display){n=O.extend({},t.activeObj,{},!0);for(var a=0;a<t.objColl.length;a++)JSON.stringify(t.activeObj)===JSON.stringify(t.objColl[a])&&t.objColl.splice(a,1);this.refreshActiveObj(),this.upperContext.clearRect(0,0,t.upperCanvas.width,t.upperCanvas.height),this.lowerContext.clearRect(0,0,t.upperCanvas.width,t.upperCanvas.height),t.notify("draw",{prop:"redrawImgWithObj",onPropertyChange:!1}),t.notify("draw",{prop:"redrawDownScale"}),t.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.lowerContext}}),t.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.upperContext}}),(t.currSelectionPoint&&"crop-circle"===t.currSelectionPoint.shape||t.isCircleCrop)&&t.notify("crop",{prop:"cropCircle",onPropertyChange:!1,value:{context:this.lowerContext,isSave:null,isFlip:null}}),t.activeObj=n,this.updateFontStyles();var s,l,i=O.extend({},t.activeObj,{},!0),n=i.topLeftCircle.radius,p=i.activePoint,h=p.startX,d=p.startY,c=p.endX,u=p.endY,g=h+p.width/2,p=d+p.height/2,v=Math.cos(i.rotatedAngle),f=Math.sin(i.rotatedAngle),C={x:v*(h-g)-f*(d-p)+g,y:f*(h-g)+v*(d-p)+p},d={x:v*(c-g)-f*(d-p)+g,y:f*(c-g)+v*(d-p)+p},h={x:v*(h-g)-f*(u-p)+g,y:f*(h-g)+v*(u-p)+p},f={x:v*(c-g)-f*(u-p)+g,y:f*(c-g)+v*(u-p)+p},r={position:null,x:s,y:l,x1:C.x,y1:C.y,x2:d.x,y2:d.y,x3:h.x,y3:h.y,x4:f.x,y4:f.y};t.notify("draw",{prop:"checkPointPosition",onPropertyChange:!1,value:{obj:r}}),0!==i.rotatedAngle&&("inside"===r.position||"on"===r.position)||0===i.rotatedAngle&&s>=i.activePoint.startX-2*n&&s<=i.activePoint.endX+2*n&&l>=i.activePoint.startY-2*n&&l<=i.activePoint.endY+2*n?(this.upperContext.clearRect(0,0,t.upperCanvas.width,t.upperCanvas.height),4===i.flipObjColl.length&&(i.flipObjColl=[],i.shapeFlip=o=""),""===o&&1<i.flipObjColl.length&&(o=i.flipObjColl[i.flipObjColl.length-1]),l=(s=(c=i.flipObjColl.length<=1?this.setTextBoxPos(i,e,o,s,l):this.setTextBoxPoints(i,e,o,s,l)).x,c.y),0!==t.activeObj.rotatedAngle&&(s=(g=this.getTextBoxPosition(t.activeObj)).x,l=g.y,s=(g=this.setFlipState(s,l,t.activeObj)).x,l=g.y),this.renderTextArea(s,l,i)):this.applyActObj()}}},C.prototype.getTextBoxPosition=function(e,t){var o={x:0,y:0},i=e.activePoint,r=i.startX,n=i.startY,a=i.endX,s=i.endY,l=r+i.width/2,i=n+i.height/2,p=Math.cos(e.rotatedAngle),h=Math.sin(e.rotatedAngle),d={x:p*(r-l)-h*(n-i)+l,y:h*(r-l)+p*(n-i)+i},n={x:p*(a-l)-h*(n-i)+l,y:h*(a-l)+p*(n-i)+i},r={x:p*(r-l)-h*(s-i)+l,y:h*(r-l)+p*(s-i)+i},h={x:p*(a-l)-h*(s-i)+l,y:h*(a-l)+p*(s-i)+i},a=this.getRotDegOfShape(e);return 0===a||360===a?o={x:d.x,y:d.y}:90===a||-270===a?o={x:n.x,y:n.y}:180===a||-180===a?o={x:h.x,y:h.y}:270!==a&&-90!==a||(o={x:r.x,y:r.y}),t&&(t.x=o.x,t.y=o.y),o},C.prototype.setFlipState=function(e,t,o,i){var r=this.parent,n={panRegion:""},a=r.lowerCanvas,s=a.clientWidth,a=a.clientHeight,l={x:0,y:0};return r.notify("crop",{prop:"getCurrFlipState",onPropertyChange:!1,value:{panObj:n}}),""!==n.panRegion&&("horizontal"===n.panRegion?(l.x=s-s/2,e=l.x-e+l.x):t=("vertical"===n.panRegion?l.y=a-a/2:e=(l={x:s-s/2,y:a-a/2}).x-e+l.x,l.y-t+l.y)),i&&(i.x=e,i.y=t),{x:e,y:t}},C.prototype.fileChanged=function(e){var t=e.target.files[0],t=t.name&&t.name.split(".")[1].toLowerCase();t&&-1===["jpg","jpeg","png","svg"].indexOf(t)?this.refreshActiveObj():(t=window.URL.createObjectURL(e.target.files[0]),this.onLoadImgShape(null,null,null,null,t.toString(),!0),document.getElementById(this.parent.element.id+"_fileUpload").value="")},C.prototype.onLoadImgShape=function(e,t,o,i,r,n,a,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(n,e,t,o,i,a,s,l,p)}},C.prototype.updateImgCanvas=function(e,t,o,i,r,n,a,s,l){var p=this.parent,h=(p.activeObj.imageElement=this.shapeImg,p.activeObj.imageCanvas=p.createElement("canvas"),{width:0,height:0}),a=(p.notify("transform",{prop:"calcMaxDimension",onPropertyChange:!1,value:{width:this.shapeImg.width,height:this.shapeImg.height,obj:h,isImgShape:null}}),i&&r&&(h=a?(p.notify("selection",{prop:"findImageRatio",onPropertyChange:!(d={ratio:null}),value:{width:this.shapeImg.width,height:this.shapeImg.height,obj:d}}),this.resizeImage(i,d.ratio)):{width:i,height:r}),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&&(h=a?(p.notify("selection",{prop:"findImageRatio",onPropertyChange:!(d={ratio:null}),value:{width:this.shapeImg.width,height:this.shapeImg.height,obj:d}}),this.resizeImage(i,d.ratio)):{width:i,height:r}),null!=s&&(p.activeObj.opacity=s),this.updateObj(h,t,o),p.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate"}}),this.shapeImg=null,n&&(p.activeObj.rotatedAngle=n*(Math.PI/180),p.notify("selection",{prop:"updPtCollForShpRot",onPropertyChange:!1,value:{obj:p.activeObj}})),{shapeSettingsObj:{}}),d=(p.notify("selection",{prop:"updatePrevShapeSettings",onPropertyChange:!1,value:{obj:a}}),a.shapeSettingsObj),i={cancel:!1,action:"insert",previousShapeSettings:d,currentShapeSettings:d};p.trigger("shapeChanging",i),this.drawShapeImageEvent(i,e=e||l),p.isPublicMethod&&!l?p.notify("undo-redo",{prop:"updateUndoRedo",onPropertyChange:!1}):p.isPublicMethod||p.notify("undo-redo",{prop:"updateUndoRedoStack",onPropertyChange:!1}),p.isPublicMethod=!1},C.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},C.prototype.resizeImage=function(e,t){var t=t.split(":"),o=parseInt(t[0],10),t=parseInt(t[1],10);return{width:e,height:Math.round(e*t/o)}},C.prototype.setTextBoxPos=function(e,t,o,i,r){var n={x:i,y:r},i=e.activePoint,a=i.startX,s=i.startY,l=i.endX,p=i.endY;switch(o=o.toLowerCase(),t){case 0:"horizontal"===o?(n.x=l,n.y=s):"vertical"===o?(n.x=a,n.y=p):(n.x=a,n.y=s);break;case 90:"horizontal"===o?(n.x=a,n.y=s):"vertical"===o?(n.x=l,n.y=p):(n.x=l,n.y=s);break;case 180:"horizontal"===o?(n.x=a,n.y=p):"vertical"===o?(n.x=l,n.y=s):(n.x=l,n.y=p);break;case 270:"horizontal"===o?(n.x=l,n.y=p):"vertical"===o?(n.x=a,n.y=s):(n.x=a,n.y=p)}return n},C.prototype.setTextBoxPoints=function(e,t,o,i,r){var n={x:i,y:r},i=e.activePoint,a=i.startX,s=i.startY,l=i.endX,p=i.endY;switch(o=o.toLowerCase(),t){case 0:e.flipObjColl[0]&&"horizontal"===e.flipObjColl[0].toLowerCase()?"horizontal"===o?(n.x=a,n.y=s):"vertical"===o&&(n.x=l,n.y=p):"horizontal"===o?(n.x=l,n.y=p):"vertical"===o&&(n.x=l,n.y=s);break;case 90:e.flipObjColl[0]&&"horizontal"===e.flipObjColl[0].toLowerCase()?"horizontal"===o?(n.x=l,n.y=p):"vertical"===o&&(n.x=a,n.y=p):"horizontal"===o?(n.x=a,n.y=p):"vertical"===o&&(n.x=a,n.y=s);break;case 180:e.flipObjColl[0]&&"horizontal"===e.flipObjColl[0].toLowerCase()?"horizontal"!==o&&"vertical"!==o||(n.x=a,n.y=s):"horizontal"===o?(n.x=a,n.y=s):"vertical"===o&&(n.x=a,n.y=p);break;case 270:e.flipObjColl[0]&&"horizontal"===e.flipObjColl[0].toLowerCase()?"horizontal"===o?(n.x=a,n.y=s):"vertical"===o&&(n.x=l,n.y=s):"horizontal"===o?(n.x=l,n.y=s):"vertical"===o&&(n.x=l,n.y=p)}return n},C.prototype.selectedText=function(){var e=this.parent,t=e.textArea.selectionStart,o=e.textArea.selectionEnd;return e.textArea.value.substring(t,o)},C.prototype.panObjColl=function(e,t,o){var i=this.parent;if(0<i.objColl.length){for(var r=0,n=i.objColl.length;r<n;r++){var a=i.objColl[r];if(""===o){if(a.activePoint.startX+=e,a.activePoint.endX+=e,a.rotationCirclePointColl&&(a.rotationCirclePointColl.x+=e),"path"===a.shape)for(var s=0,l=a.pointColl.length;s<l;s++)a.pointColl[s].x+=e;if(a.activePoint.startY+=t,a.activePoint.endY+=t,a.rotationCirclePointColl&&(a.rotationCirclePointColl.y+=t),"path"===a.shape)for(s=0;s<a.pointColl.length;s++)a.pointColl[s].y+=t}if(a=this.updateWidthHeight(a),i.notify("draw",{prop:"updateActiveObject",onPropertyChange:!1,value:{actPoint:a.activePoint,obj:a}}),"line"===a.shape||"arrow"===a.shape){a.pointColl=this.getLinePoints(a.activePoint.startX,a.activePoint.startY,a.activePoint.endX,a.activePoint.endY);for(var p=0,h=a.pointColl.length;p<h;p++)a.pointColl[p].ratioX=(a.pointColl[p].x-i.img.destLeft)/i.img.destWidth,a.pointColl[p].ratioY=(a.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}})}},C.prototype.updateFontStyles=function(e){var t=this.parent,o=(this.upperContext.strokeStyle=t.activeObj.strokeSettings.strokeColor,this.upperContext.fillStyle=t.activeObj.strokeSettings.strokeColor,""),e=(t.activeObj.textSettings.bold&&(o="bold "),t.activeObj.textSettings.italic&&(o="italic "),t.activeObj.textSettings.bold&&t.activeObj.textSettings.italic&&(o="italic bold "),e?parseFloat(t.textArea.style.fontSize):t.activeObj.textSettings.fontSize),t=("block"===t.textArea.style.display||"inline-block"===t.textArea.style.display?t.textArea.style:t.activeObj.textSettings).fontFamily;this.upperContext.font=o+e+"px "+t},C.prototype.applyFontStyle=function(e){var t=this.parent,o={shapeSettingsObj:{}},o=(t.notify("selection",{prop:"updatePrevShapeSettings",onPropertyChange:!1,value:{obj:o}}),o.shapeSettingsObj),i=(this.pushActItemIntoObj(),O.extend([],t.objColl,[],!0));switch(t.objColl.pop(),"none"===t.textArea.style.display?this.updateFontRatio(t.activeObj):this.updateFontRatio(t.activeObj,!0),e){case"default":this.updateFontStyle(e,i,"normal","normal");break;case"bold":this.updateFontStyle(e,i,"bold","normal");break;case"italic":this.updateFontStyle(e,i,"normal","italic");break;case"bolditalic":this.updateFontStyle(e,i,"bold","italic")}o={action:"font-style",currentShapeSettings:O.extend({},o,{},!0)};o.currentShapeSettings.fontStyle=[e],t.trigger("shapeChange",o)},C.prototype.updateFontStyle=function(e,t,o,i){var r,n=this.parent,a=n.textArea.style;"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"),r="normal"===a.fontWeight&&"normal"===a.fontStyle?"default":"bold"===a.fontWeight&&"normal"===a.fontStyle?"bold":"normal"===a.fontWeight&&"italic"===a.fontStyle?"italic":"bolditalic",r=this.getTextAreaWidth(r),a.width=r+"px",this.updateObjColl(e,t)):(this.textSettings.bold=n.activeObj.textSettings.bold="normal"!==o,this.textSettings.italic=n.activeObj.textSettings.italic="normal"!==i,0===n.activeObj.activePoint.width&&0===n.activeObj.activePoint.height||this.redrawText(),n.notify("undo-redo",{prop:"updateUrObj",onPropertyChange:!1,value:{objColl:t}}))},C.prototype.updateArrowRatio=function(e){for(var t,o={arrowDimension:null},i=(this.parent.notify("draw",{prop:"getArrowDimension",onPropertyChange:!1,value:{obj:o}}),t=Math.abs(e.activePoint.width)>Math.abs(e.activePoint.height)?Math.abs(e.activePoint.width):Math.abs(e.activePoint.height),0),r=["bar","arrow","arrowSolid","circle","square"];i<r.length;i++){var n,a=t/o.arrowDimension[n=r[i]].width,s=t/o.arrowDimension[n].height;o.arrowDimension[n].ratioX=a,o.arrowDimension[n].ratioY=s}},C.prototype.updateArrowSize=function(e){for(var t,o={arrowDimension:null},i=(this.parent.notify("draw",{prop:"getArrowDimension",onPropertyChange:!1,value:{obj:o}}),t=Math.abs(e.activePoint.width)>Math.abs(e.activePoint.height)?Math.abs(e.activePoint.width):Math.abs(e.activePoint.height),0),r=["bar","arrow","arrowSolid","circle","square"];i<r.length;i++){var n,a=o.arrowDimension[n=r[i]].ratioX,s=o.arrowDimension[n].ratioY;o.arrowDimension[n].width=t/a,o.arrowDimension[n].height=t/s}},C.prototype.updateFontRatio=function(e,t){var o=this.parent,i=this.getMaxText(t),i=this.upperContext.measureText(i).width+.5*o.activeObj.textSettings.fontSize,r=o.activeObj.textSettings.fontSize+.25*o.activeObj.textSettings.fontSize,n=this.getRotDegOfShape(e);O.isNullOrUndefined(t)?0===n||180===Math.abs(n)?e.textSettings.fontRatio=i/e.textSettings.fontSize:e.textSettings.fontRatio=r/e.textSettings.fontSize:t&&(e.textSettings.fontRatio=i/parseFloat(o.textArea.style.fontSize))},C.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},C.prototype.updateObjColl=function(e,t){var o=this.parent,i=O.extend({},o.cropObj,{},!0),r={currObj:{}},r=(o.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:r}}),r.currObj),t=(r.objColl=t,r.pointColl=O.extend([],o.pointColl,[],!0),r.afterCropActions=O.extend([],o.afterCropActions,[],!0),{selPointColl:null}),t=(o.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:t}}),r.selPointColl=O.extend([],t.selPointColl,[],!0),o.activeObj.textSettings.bold),n=o.activeObj.textSettings.italic;switch(e){case"default":o.activeObj.textSettings.bold=!1,o.activeObj.textSettings.italic=!1;break;case"bold":o.activeObj.textSettings.bold=!0,o.activeObj.textSettings.italic=!1;break;case"italic":o.activeObj.textSettings.bold=!1,o.activeObj.textSettings.italic=!0;break;case"bolditalic":o.activeObj.textSettings.bold=!0,o.activeObj.textSettings.italic=!0}o.objColl.push(o.activeObj),o.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"textAreaCustomization",previousObj:r,previousObjColl:r.objColl,previousPointColl:r.pointColl,previousSelPointColl:r.selPointColl,previousCropObj:i,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),o.objColl.pop(),o.activeObj.textSettings.bold=t,o.activeObj.textSettings.italic=n},C.prototype.pushActItemIntoObj=function(){var e,t=this.parent;"none"===t.textArea.style.display?0===t.activeObj.activePoint.width&&0===t.activeObj.activePoint.height||t.objColl.push(t.activeObj):(e=O.extend({},t.activeObj,{},!0),t.notify("selection",{prop:"setTextBoxStylesToActObj",onPropertyChange:!1}),t.objColl.push(t.activeObj),t.activeObj=e)},C.prototype.clearActObj=function(){var e=this.parent;"none"===e.textArea.style.display&&(this.refreshActiveObj(),this.applyActObj(),this.refreshActiveObj(),e.currObjType.isCustomCrop=!1)},C.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},C.prototype.applyActObj=function(e){var t=this.parent,o=!1;if(void 0!==t.activeObj.shape&&"text"===t.activeObj.shape&&""===t.activeObj.keyHistory)this.refreshActiveObj(),this.upperContext.clearRect(0,0,t.upperCanvas.width,t.upperCanvas.height);else{var i=void 0,r=!1;if((void 0===(i=void 0!==t.activeObj.shape?t.activeObj.shape.split("-"):i)&&t.currObjType.isCustomCrop||void 0!==i&&"crop"===i[0])&&(r=!0),t.activeObj.shape&&!r&&"shape"!==t.activeObj.shape){for(var n=0;n<t.objColl.length;n++)if(JSON.stringify(t.activeObj)===JSON.stringify(t.objColl[n])){o=!0;break}if(!o){O.isNullOrUndefined(t.activeObj.currIndex)&&(t.activeObj.currIndex=this.getNewShapeId()),O.isNullOrUndefined(t.activeObj.order)&&(t.activeObj.order=this.getNewOrder()),this.updImgRatioForActObj();var i=t.activeObj.currIndex.split("_"),a=t.objColl.splice(0,parseInt(i[1],10)-1);a.push(O.extend({},t.activeObj,{},!0));for(n=0;n<t.objColl.length;n++)a.push(t.objColl[n]);t.objColl=a,a=[],this.refreshActiveObj(),this.lowerContext.clearRect(0,0,t.lowerCanvas.width,t.lowerCanvas.height),t.notify("draw",{prop:"redrawImgWithObj",onPropertyChange:!1}),t.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.lowerContext}}),t.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.upperContext}}),t.currObjType.shape="",this.refreshActiveObj(),t.isCircleCrop&&t.notify("crop",{prop:"cropCircle",onPropertyChange:!1,value:{context:this.lowerContext,isSave:null,isFlip:null}}),t.notify("toolbar",{prop:"destroy-qa-toolbar",onPropertyChange:!1}),O.isNullOrUndefined(e)&&(t.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"ok"}}),t.notify("draw",{prop:"setPrevActObj",onPropertyChange:!1,value:{prevActObj:null}}))}}}},C.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},C.prototype.getNewOrder=function(){for(var e=this.parent,t=(this.updateShapeColl(),e.shapeColl.length+1),o=0;o<e.shapeColl.length;o++)e.shapeColl[o].order===t&&(t++,o=-1);return t},C.prototype.getHighestOrder=function(){for(var e=this.parent,t=(this.updateShapeColl(),0),o=0;o<e.shapeColl.length;o++)e.shapeColl[o].order>t&&(t=e.shapeColl[o].order);return t},C.prototype.getLowestOrder=function(){for(var e=this.parent,t=(this.updateShapeColl(),1),o=0;o<e.shapeColl.length;o++)e.shapeColl[o].order<t&&(t=e.shapeColl[o].order);return t},C.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()},C.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(0<e.activeObj.flipObjColl.length)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()||"vertical"===e.activeObj.flipObjColl[r].toLowerCase())&&(e.textArea.style.transform="rotate("+i+"deg)"+o);else e.textArea.style.transform="rotate("+(i+=t)+"deg)"}},C.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 e="none"!==t.textArea.style.display;return this.updateFontStyles(e),e=e?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,e},C.prototype.getObjDetails=function(e){var t,o=this.parent,i={};switch(i.id=e.currIndex,i.type=o.toPascalCase(e.shape),i.startX=e.activePoint.startX,i.startY=e.activePoint.startY,i.index=e.order,e.shape){case"rectangle":i.width=e.activePoint.width,i.height=e.activePoint.height,i.strokeColor=e.strokeSettings.strokeColor,i.fillColor=e.strokeSettings.fillColor,i.strokeWidth=e.strokeSettings.strokeWidth,i.degree=e.rotatedAngle*(180/Math.PI);break;case"ellipse":i.radius=e.activePoint.width/2,i.strokeColor=e.strokeSettings.strokeColor,i.fillColor=e.strokeSettings.fillColor,i.strokeWidth=e.strokeSettings.strokeWidth,i.radiusX=e.activePoint.width/2,i.radiusY=e.activePoint.height/2,i.degree=e.rotatedAngle*(180/Math.PI);break;case"line":case"arrow":i.length=e.activePoint.width,i.strokeColor=e.strokeSettings.strokeColor,i.strokeWidth=e.strokeSettings.strokeWidth,i.endX=e.activePoint.endX,i.endY=e.activePoint.endY,"arrow"===e.shape&&(o.notify("selection",{prop:"getArrowType",onPropertyChange:!(t={type:null}),value:{type:e.start,obj:t}}),i.arrowHead=t.type,o.notify("selection",{prop:"getArrowType",onPropertyChange:!1,value:{type:e.end,obj:t}}),i.arrowTail=t.type);break;case"text":i.text=e.keyHistory,i.fontSize=e.textSettings.fontSize,i.fontFamily=e.textSettings.fontFamily,i.color=e.strokeSettings.strokeColor,i.fontStyle=[],e.textSettings.bold&&i.fontStyle.push("bold"),e.textSettings.italic&&i.fontStyle.push("italic"),i.degree=e.rotatedAngle*(180/Math.PI);break;case"path":i.strokeColor=e.strokeSettings.strokeColor,i.strokeWidth=e.strokeSettings.strokeWidth,i.points=e.pointColl;break;case"image":i.imageData=e.imageCanvas.toDataURL(),i.degree=e.rotatedAngle*(180/Math.PI),i.width=e.activePoint.width,i.height=e.activePoint.height,i.opacity=e.opacity}return i},C.prototype.getFreehandDrawDetails=function(e){var t=this.parent,o={};return o.id=t.pointColl[e].id,o.type=v.ShapeType.FreehandDraw,o.points=O.extend([],t.pointColl[e].points),o.strokeColor=t.pointColl[e].strokeColor,o.strokeWidth=t.pointColl[e].strokeWidth,o.index=t.pointColl[e].order,o},C.prototype.getShapeSetting=function(e,t){var o,i=this.parent;if(!i.disabled&&i.isImageLoaded)if("none"!==i.textArea.style.display?i.okBtn(null,!0):this.applyActObj(!0),"shape"===e.split("_")[0]){for(var r,n=0,a=i.objColl.length;n<a;n++)if(i.objColl[n].currIndex===e){r=O.extend({},i.objColl[n],{},!0);break}o=this.getObjDetails(r)}else"pen"===e.split("_")[0]&&(o=this.getFreehandDrawDetails(parseInt(e.split("_")[1],10)-1));t.shapeDetails=o},C.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++){var n=this.getObjDetails(t.objColl[i]);o.push(n)}for(i=0;i<t.freehandCounter;i++){n=this.getFreehandDrawDetails(i);o.push(n)}}e.shapeDetailsColl=o},C.prototype.isPointsInRange=function(e,t,o){var i=!1,r=this.parent;!O.isNullOrUndefined(e)&&!O.isNullOrUndefined(t)&&e>=r.img.destLeft&&t>=r.img.destTop&&e<=r.img.destLeft+r.img.destWidth&&t<=r.img.destTop+r.img.destHeight&&(i=!0),o.inRange=i},C.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},C.prototype.popForDefaultTransformedState=function(e){for(var t=0,o=0,i=0,r=0,n=0;n<e.length;n++)90===e[n]||"rotateRight"===e[n]?(r=i=o=0,4===++t&&(e.pop(),e.pop(),e.pop(),e.pop())):-90===e[n]||"rotateLeft"===e[n]?(r=i=t=0,4===++o&&(e.pop(),e.pop(),e.pop(),e.pop())):"horizontal"===e[n]||"Horizontal"===e[n]||"horizontalflip"===e[n]?(r=t=o=0,2===++i&&(e.pop(),e.pop())):"vertical"!==e[n]&&"Vertical"!==e[n]&&"verticalflip"!==e[n]||(t=o=i=0,2===++r&&(e.pop(),e.pop()));return e},C.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],n="horizontal"===e[t+1]||"Horizontal"===e[t+1]||"horizontalFlip"===e[t+1],a="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&&a&&s&&l||r&&n&&l&&p)&&(e.splice(t,4),t-=4)}return e},C.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)}return e},C.prototype.selectShape=function(e,t){var o=this.parent,i=!1;if(!o.disabled&&o.isImageLoaded)if(this.applyActObj(),"shape"===e.split("_")[0]){for(var r,n,a=0,s=o.objColl.length;a<s;a++)if(o.objColl[a].currIndex===e){r=O.extend({},o.objColl[a],{},!0);break}O.isNullOrUndefined(r)?i=!1:(i=!0,o.activeObj=r,o.notify("toolbar",{prop:"getCanvasFilter",onPropertyChange:!(n={canvasFilter:null}),value:{obj:n}}),this.lowerContext.filter=n.canvasFilter,o.notify("selection",{prop:"redrawShape",onPropertyChange:!1,value:{obj:o.activeObj}}),"text"===o.activeObj.shape?o.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"text",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}}):"pen"===o.activeObj.shape?o.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"pen",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}}):o.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"shapes",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}}),o.notify("toolbar",{prop:"update-toolbar-items",onPropertyChange:!1}),o.notify("toolbar",{prop:"renderQAT",onPropertyChange:!1,value:{isPenEdit:null}}))}else"pen"===e.split("_")[0]&&(o.notify("selection",{prop:"getFreehandDrawEditing",onPropertyChange:!(n={bool:!1}),value:{obj:n}}),n.bool&&o.okBtn(null,!0),n={isIndex:!1},o.notify("freehand-draw",{prop:"isFHDIdx",value:{index:parseInt(e.split("_")[1],10)-1,obj:n}}),n.isIndex?(i=!0,o.notify("freehand-draw",{prop:"selectFhd",value:{id:e}}),o.notify("toolbar",{prop:"renderQAT",onPropertyChange:!1,value:{isPenEdit:!0}}),o.notify("toolbar",{prop:"update-toolbar-items",onPropertyChange:!1})):i=!1);t.isSelected=i},C.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})}},C.prototype.getMaxText=function(e,t,o){for(var i,r=(t=O.isNullOrUndefined(t)?e?this.parent.textArea.value:this.parent.activeObj.keyHistory:t).split("\n"),n=r[0].length,a=r[0],s=1;s<r.length;s++)n<(i=r[s].length)&&(a=r[s],n=i);return o&&(o.maxText=a),a},C.prototype.getLinePoints=function(e,t,o,i){var r,n,a=[];if(e===o){t<i?(r=[e,t],n=[o,i]):(n=[e,t],r=[o,i]);for(var s=this.getSlope(r,n,!0),l=this.getIntercept(r,s),p=r[1];p<=n[1];p++){var h=s*p+l;a.push({x:h,y:p})}}else{e<o?(r=[e,t],n=[o,i]):(n=[e,t],r=[o,i]);for(s=this.getSlope(r,n,!1),l=this.getIntercept(r,s),h=r[0];h<=n[0];h++){p=s*h+l;a.push({x:h,y:p})}}if(Math.floor(e)===Math.floor(o)||a.length<10&&(10<i-t||10<t-i)){for(var a=[],d=Math.min(t,i),c=0;c<Math.abs(Math.floor(i)-Math.floor(t));c++)a.push({x:e,y:d+c});1<a.length&&(u=void 0,u=O.isNullOrUndefined(a[a.length-2])?{x:0,y:0}:a[a.length-2],g=a[a.length-1].x-u.x,v=a[a.length-1].y-u.y,a.push({x:a[a.length-1].x+g/2,y:a[a.length-1].y+v/2}))}else if(Math.floor(t)===Math.floor(i)||a.length<10&&(10<o-e||10<e-o)){a=[];for(var u,g,v,f=Math.min(e,o),C=0;C<Math.abs(Math.floor(o)-Math.floor(e));C++)a.push({x:f+C,y:t});1<a.length&&(u=void 0,u=O.isNullOrUndefined(a[a.length-2])?{x:0,y:0}:a[a.length-2],g=a[a.length-1].x-u.x,v=a[a.length-1].y-u.y,a.push({x:a[a.length-1].x+g/2,y:a[a.length-1].y+v/2}))}return a},C.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},C.prototype.getIntercept=function(e,t){return null===t?e[0]:e[1]-t*e[0]},C.prototype.setPointCollForShapeRotation=function(e){var t=this.parent,o=e.activePoint,i=o.startX,r=o.startY,n=o.endX,a=o.endY,s=i+o.width/2,o=r+o.height/2,l=Math.cos(e.rotatedAngle),p=Math.sin(e.rotatedAngle),h={x:l*(i-s)-p*(r-o)+s,y:p*(i-s)+l*(r-o)+o},r={x:l*(n-s)-p*(r-o)+s,y:p*(n-s)+l*(r-o)+o},i={x:l*(i-s)-p*(a-o)+s,y:p*(i-s)+l*(a-o)+o},n={x:l*(n-s)-p*(a-o)+s,y:p*(n-s)+l*(a-o)+o};e.horTopLinePointColl=this.getLinePoints(h.x,h.y,r.x,r.y),e.horTopLinePointColl=this.getLinePoints(h.x,h.y,r.x,r.y),e.horBottomLinePointColl=this.getLinePoints(i.x,i.y,n.x,n.y),e.verLeftLinePointColl=this.getLinePoints(h.x,h.y,i.x,i.y),e.verRightLinePointColl=this.getLinePoints(r.x,r.y,n.x,n.y),e.verLeftLinePointColl.reverse(),e.verRightLinePointColl.reverse();for(var d=0;d<e.horTopLinePointColl.length;d++)e.horTopLinePointColl[d].ratioX=(e.horTopLinePointColl[d].x-this.parent.img.destLeft)/this.parent.img.destWidth,e.horTopLinePointColl[d].ratioY=(e.horTopLinePointColl[d].y-this.parent.img.destTop)/this.parent.img.destHeight;for(d=0;d<e.horBottomLinePointColl.length;d++)e.horBottomLinePointColl[d].ratioX=(e.horBottomLinePointColl[d].x-this.parent.img.destLeft)/this.parent.img.destWidth,e.horBottomLinePointColl[d].ratioY=(e.horBottomLinePointColl[d].y-this.parent.img.destTop)/this.parent.img.destHeight;for(d=0;d<e.verLeftLinePointColl.length;d++)e.verLeftLinePointColl[d].ratioX=(e.verLeftLinePointColl[d].x-this.parent.img.destLeft)/this.parent.img.destWidth,e.verLeftLinePointColl[d].ratioY=(e.verLeftLinePointColl[d].y-this.parent.img.destTop)/this.parent.img.destHeight;for(d=0;d<e.verRightLinePointColl.length;d++)e.verRightLinePointColl[d].ratioX=(e.verRightLinePointColl[d].x-this.parent.img.destLeft)/this.parent.img.destWidth,e.verRightLinePointColl[d].ratioY=(e.verRightLinePointColl[d].y-this.parent.img.destTop)/this.parent.img.destHeight;"move"!==t.upperCanvas.style.cursor&&(t.notify("selection",{prop:"getTransRotationPoint",value:{obj:e,object:a={rotationCirclePoint:null}}}),h=a.rotationCirclePoint)&&(e.rotationCirclePointColl={x:l*(h.x-s)-p*(h.y-o)+s,y:p*(h.x-s)+l*(h.y-o)+o},e.rotationCirclePointColl.ratioX=(e.rotationCirclePointColl.x-t.img.destLeft)/t.img.destWidth,e.rotationCirclePointColl.ratioY=(e.rotationCirclePointColl.y-t.img.destTop)/t.img.destHeight)},C.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,n=i.startY,a=i.endX,s=i.endY,l=r+i.width/2,i=n+i.height/2,p=Math.cos(e.rotatedAngle),e=Math.sin(e.rotatedAngle),h={x:p*(r-l)-e*(n-i)+l,y:e*(r-l)+p*(n-i)+i},n={x:p*(a-l)-e*(n-i)+l,y:e*(a-l)+p*(n-i)+i},r={x:p*(r-l)-e*(s-i)+l,y:e*(r-l)+p*(s-i)+i},e={x:p*(a-l)-e*(s-i)+l,y:e*(a-l)+p*(s-i)+i};return o.startX=h.x,o.startY=h.y,o.endX=h.x,o.endY=h.y,n.x<o.startX&&(o.startX=n.x),r.x<o.startX&&(o.startX=r.x),e.x<o.startX&&(o.startX=e.x),n.y<o.startY&&(o.startY=n.y),r.y<o.startY&&(o.startY=r.y),e.y<o.startY&&(o.startY=e.y),o.endX<n.x&&(o.endX=n.x),o.endX<r.x&&(o.endX=r.x),o.endX<e.x&&(o.endX=e.x),o.endY<n.y&&(o.endY=n.y),o.endY<r.y&&(o.endY=r.y),o.endY<e.y&&(o.endY=e.y),o.width=o.endX-o.startX,o.height=o.endY-o.startY,t&&(t.activePoint=o),o},C.prototype.updateZOrder=function(e,t){var o=this.parent,i=(t=t.toLowerCase(),e);if(!O.isNullOrUndefined(i.order)){var r,n,a=this.getHighestOrder();if(this.updateShapeColl(),0!==o.shapeColl.length){for(var s,l=0;l<o.shapeColl.length;l++)s=o.shapeColl[l],i.id&&-1<i.id.indexOf("pen")?s.id&&s.id===i.id&&o.shapeColl.splice(l,1):s.shape&&-1<s.shape.indexOf("crop-")&&o.shapeColl.splice(l,1);switch(t){case"sendtoback":n=i.order,r=i.order,i.order=1;break;case"sendbackward":--i.order,r=i.order;break;case"bringtofront":n=i.order,i.order=r=a;break;case"bringforward":i.order+=1,r=i.order}this.reArrangeObjColl(r,t,n),i.id&&-1<i.id.indexOf("pen")&&this.reUpdateShapeColl(i)}}},C.prototype.reArrangeObjColl=function(e,t,o){var i,r=this.parent;switch(t){case"sendtoback":for(var n=0,a=r.shapeColl.length;n<a;n++)(i=r.shapeColl[n]).order<o&&i.order<=e&&(i.order+=1,this.reUpdateShapeColl(i));break;case"sendbackward":for(n=0,a=r.shapeColl.length;n<a;n++)if((i=r.shapeColl[n]).order===e){i.order+=1,this.reUpdateShapeColl(i);break}break;case"bringtofront":for(n=0,a=r.shapeColl.length;n<a;n++)(i=r.shapeColl[n]).order>o&&i.order<=e&&(--i.order,this.reUpdateShapeColl(i));break;case"bringforward":for(n=0,a=r.shapeColl.length;n<a;n++)if((i=r.shapeColl[n]).order===e){--i.order,this.reUpdateShapeColl(i);break}}},C.prototype.updateShapeColl=function(){var e=this.parent,t=!1,o=1,i=O.extend([],e.objColl,[],!0),r=O.extend([],e.pointColl,[],!0);if(0<e.shapeColl.length&&e.shapeColl.length===e.objColl.length+e.pointColl.length){for(var n=0;n<e.shapeColl.length;n++){if(e.shapeColl[n].order!==o){t=!1;break}t=!0,o++}if(t){for(n=0;n<e.shapeColl.length;n++)if(e.shapeColl[n].currIndex&&-1<e.shapeColl[n].currIndex.indexOf("shape")){for(var a=0;a<i.length;a++)if(e.shapeColl[n].currIndex===i[a].currIndex){e.shapeColl[n]=O.extend({},i[a],{},!0),i.splice(a,1);break}}else if(e.shapeColl[n].id&&-1<e.shapeColl[n].id.indexOf("pen"))for(a=0;a<r.length;a++)if(e.shapeColl[n].id===r[a].id){e.shapeColl[n]=O.extend([],r[a],[],!0),r.splice(a,1);break}return}}for(var i=O.extend([],e.objColl,[],!0),r=O.extend([],e.pointColl,[],!0),s=1,l=!(e.shapeColl=[]);0!==i.length||0!==r.length;){for(var p=l=!1,n=0;n<i.length;n++)if(i[n].order===s||!i[n].order&&i[n].shape&&-1<i[n].shape.indexOf("crop-")){e.shapeColl.push(O.extend({},i[n],{},!0)),i[n].shape&&-1<i[n].shape.indexOf("crop-")&&(l=!0),i.splice(n,1),p=!0;break}if(!p)for(n=0;n<r.length;n++)if(r[n].order===s){e.shapeColl.push(O.extend([],r[n],[],!0)),r.splice(n,1),p=!0;break}l||s++}},C.prototype.reUpdateShapeColl=function(e){var t=this.parent;if(e.id&&-1<e.id.indexOf("pen")){if(0<t.freehandCounter)for(var o=0;o<t.freehandCounter;o++)t.pointColl[o].id===e.id&&(t.pointColl[o].order=e.order)}else if(e.currIndex&&-1<e.currIndex.indexOf("shape"))for(o=0;o<t.objColl.length;o++)t.objColl[o].currIndex===e.currIndex&&(t.objColl[o].order=e.order)},C.prototype.drawAnnotations=function(e,t,o,i,r,n,a){var s=this.parent,l=O.extend({},s.activeObj,{},!0),p=O.extend([],s.objColl,[],!0),h=O.extend([],s.pointColl,[],!0),d=(this.updateShapeColl(),O.extend([],s.shapeColl,[],!0)),c=!1;this.preventFrameAnnotation||(this.preventFrameAnnotation=c=!0);for(var u=0;u<d.length;u++){var g=d[u].id;if(d[u].order||!d[u].order&&d[u].shape&&-1<d[u].shape.indexOf("crop-")||!d[u].order&&"path"===d[u].shape&&"path"===s.drawingShape){if(d[u].currIndex&&-1<d[u].currIndex.indexOf("shape")){if(s.objColl=[],s.objColl.push(O.extend({},d[u],{},!0)),"iterate"===t){var v=this.lowerContext.filter;this.lowerContext.filter="none",this.iterateObjColl(),this.lowerContext.filter=v}else if("zoom"===t||"pan"===t){for(var f=-1,C=0;C<p.length;C++)if(JSON.stringify(p[C])===JSON.stringify(s.objColl[0])){f=C;break}"zoom"===t?this.zoomObjColl(i):this.panObjColl(r,n,a),-1<f&&(p[f]=O.extend({},s.objColl[0],{},!0))}}else if(d[u].id&&-1<d[u].id.indexOf("pen"))if(s.pointColl=[],s.freehandCounter=0,s.pointColl.push(O.extend({},d[u],{},!0)),s.freehandCounter=s.pointColl.length,"iterate"===o)s.notify("freehand-draw",{prop:"freehandRedraw",onPropertyChange:!1,value:{context:e,points:null}});else if("zoom"===o||"pan"===o){"zoom"===o?s.notify("freehand-draw",{prop:"zoomFHDColl",onPropertyChange:!1,value:{isPreventApply:i}}):s.notify("freehand-draw",{prop:"panFHDColl",onPropertyChange:!1,value:{xDiff:r,yDiff:n,panRegion:a}});for(var b=0;b<h.length;b++)if(h[b].id===s.pointColl[0].id){h[b]=O.extend({},s.pointColl[0],{},!0);break}}}else(d[u].shape||g)&&(d[u].currIndex||g)||d.splice(u,1)}o&&"zoom"===o&&(s.pointColl=[],s.freehandCounter=0,s.notify("freehand-draw",{prop:"zoomFHDColl",onPropertyChange:!1,value:{isPreventApply:i}})),s.objColl=p,s.pointColl=h,s.freehandCounter=s.pointColl.length,c&&this.preventFrameAnnotation&&(s.notify("draw",{prop:"applyFrame",value:{ctx:this.lowerContext,frame:s.frameObj.type,preventImg:!0}}),this.preventFrameAnnotation=!1),s.activeObj=l};var H=C;function C(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()}b.prototype.destroy=function(){this.parent.isDestroyed||this.removeEventListener()},b.prototype.addEventListener=function(){this.parent.on("transform",this.transform,this),this.parent.on("destroyed",this.destroy,this)},b.prototype.removeEventListener=function(){this.parent.off("transform",this.transform),this.parent.off("destroyed",this.destroy)},b.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}},b.prototype.getModuleName=function(){return"transform"},b.prototype.initTransformPvtVar=function(){this.parent.lowerCanvas&&(this.lowerContext=this.parent.lowerCanvas.getContext("2d")),this.parent.upperCanvas&&(this.upperContext=this.parent.upperCanvas.getContext("2d"))},b.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},b.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)},b.prototype.rotateEvent=function(e,t){var o,i=this.parent;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}})):(e=void 0,O.isNullOrUndefined(this.transCurrObj)&&(i.notify("filter",{prop:"getCurrentObj",onPropertyChange:!(o={currObj:{}}),value:{object:o}}),(e=o.currObj).objColl=O.extend([],i.objColl,null,!0),e.pointColl=O.extend({},i.pointColl,null,!0),e.afterCropActions=O.extend([],i.afterCropActions,[],!0),i.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!(o={selPointColl:null}),value:{obj:o}}),e.selPointColl=O.extend([],o.selPointColl,[],!0)),i.afterCropActions.push(90===t?"rotateRight":"rotateLeft"),e=[],o=void 0,i.activeObj.activePoint&&i.activeObj.shape&&(void 0!==i.activeObj.shape&&(e=i.activeObj.shape.split("-")),!i.currObjType.isCustomCrop&&"crop"!==e[0]||(o=i.currObjType.isCustomCrop?"custom":e[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(t),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}}),o&&(this.upperContext.clearRect(0,0,i.upperCanvas.width,i.upperCanvas.height),i.activeObj=O.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,e={collection:i.rotateFlipColl},i.notify("shape",{prop:"alignRotateFlipColl",onPropertyChange:!1,value:{collection:i.rotateFlipColl,isRotateFlipCollection:!0,obj:e}}),i.rotateFlipColl=e.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))},b.prototype.drawRotatedImage=function(e){var t=this.parent,o=(0===e?t.transform.degree=0:t.transform.degree+=e,360===Math.abs(t.transform.degree)&&(t.transform.degree=0),t.notify("draw",{prop:"setDestPoints",onPropertyChange:!1}),O.extend([],t.objColl,[],!0)),i=O.extend({},t.activeObj,{},!0);if(t.objColl=[],t.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),this.isReverseRotate||t.notify("draw",{prop:"updateCurrTransState",onPropertyChange:!1,value:{type:"initial",isPreventDestination:null,isRotatePan:null}}),this.rotateDegree(e),this.isReverseRotate||(t.notify("draw",{prop:"updateCurrTransState",onPropertyChange:!1,value:{type:"reverse",isPreventDestination:null,isRotatePan:null}}),t.rotateFlipColl.push(e)),t.objColl=O.extend([],o,[],!0),t.activeObj=O.extend({},i,{},!0),t.isCircleCrop&&t.notify("crop",{prop:"cropCircle",onPropertyChange:!1,value:{context:this.lowerContext,isSave:null,isFlip:null}}),t.notify("shape",{prop:"redrawObj",onPropertyChange:!1,value:{degree:e}}),t.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),0<e)t.notify("freehand-draw",{prop:"rotateFhdColl",onPropertyChange:!1});else for(var r=0;r<3;r++)t.notify("freehand-draw",{prop:"rotateFhdColl",onPropertyChange:!1});t.notify("freehand-draw",{prop:"freehandRedraw",onPropertyChange:!1,value:{context:this.lowerContext,points:null}}),this.updateCurrSelectionPoint(e)},b.prototype.rotateDegree=function(e){var t=this.parent,o=(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),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()},b.prototype.updateCurrSelectionPoint=function(e){var t,o,i,r,n=this.parent;n.currSelectionPoint&&this.currDestPoint&&(t=O.extend({},n.activeObj,{},!0),o=O.extend([],n.objColl,[],!0),i={startX:n.img.srcLeft,startY:n.img.srcTop,width:n.img.srcWidth,height:n.img.srcHeight},r={startX:n.img.destLeft,startY:n.img.destTop,width:n.img.destWidth,height:n.img.destHeight},n.objColl=[],n.objColl.push(O.extend({},n.currSelectionPoint,{},!0)),O.isNullOrUndefined(n.objColl[0].imageRatio)&&(n.activeObj=n.objColl[0],n.notify("shape",{prop:"updImgRatioForActObj",onPropertyChange:!1}),n.objColl[0]=n.activeObj),n.img={srcLeft:0,srcTop:0,srcWidth:n.baseImgCanvas.width,srcHeight:n.baseImgCanvas.height,destLeft:this.currDestPoint.startX,destTop:this.currDestPoint.startY,destWidth:this.currDestPoint.width,destHeight:this.currDestPoint.height},"number"==typeof e&&(n.notify("draw",{prop:"setDestPoints",onPropertyChange:!1}),n.notify("draw",{prop:"setClientTransDim",onPropertyChange:!1,value:{isPreventDimension:null}})),n.notify("shape",{prop:"redrawObj",onPropertyChange:!1,value:{degree:e}}),n.currSelectionPoint=O.extend({},n.objColl[0],{},!0),this.currDestPoint={startX:n.img.destLeft,startY:n.img.destTop,width:n.img.destWidth,height:n.img.destHeight},n.objColl=o,n.activeObj=t,n.img={srcLeft:i.startX,srcTop:i.startY,srcWidth:i.width,srcHeight:i.height,destLeft:r.startX,destTop:r.startY,destWidth:r.width,destHeight:r.height})},b.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)},b.prototype.flipEvent=function(e,t){var o=this.parent;if(e.cancel)o.notify("draw",{prop:"setCurrentObj",onPropertyChange:!1,value:{obj:o.prevEventObjPoint}}),o.activeObj=o.prevEventSelectionPoint,o.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate",obj:o.activeObj}});else{O.isNullOrUndefined(this.transCurrObj)&&(o.notify("filter",{prop:"getCurrentObj",onPropertyChange:!(e={currObj:{}}),value:{object:e}}),(e=e.currObj).objColl=O.extend([],o.objColl,null,!0),e.pointColl=O.extend({},o.pointColl,null,!0),e.afterCropActions=O.extend([],o.afterCropActions,[],!0),o.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!(r={selPointColl:null}),value:{obj:r}}),e.selPointColl=O.extend([],r.selPointColl,[],!0)),o.afterCropActions.push("horizontal"===t.toLowerCase()?"horizontalflip":"verticalflip");var i,e=[],r=(o.activeObj.activePoint&&(void 0!==o.activeObj.shape&&(e=o.activeObj.shape.split("-")),!o.currObjType.isCustomCrop&&"crop"!==e[0]||(i=o.currObjType.isCustomCrop?"custom":e[1],o.notify("shape",{prop:"updImgRatioForActObj",onPropertyChange:!1}),o.objColl.push(o.activeObj),o.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}))),o.notify("shape",{prop:"redrawActObj",onPropertyChange:!1,value:{x:null,y:null,isMouseDown:!0}}),o.clearContext(this.lowerContext),o.clearContext(this.upperContext),O.extend([],o.objColl,[],!0)),e=O.extend({},o.activeObj,{},!0),n=(o.objColl=[],o.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),this.isReverseFlip||o.notify("draw",{prop:"updateCurrTransState",onPropertyChange:!1,value:{type:"initial",isPreventDestination:null,isRotatePan:null}}),t.toLowerCase()),a=(this.updateFlipState(n),o.transform.currFlipState.toLowerCase()),a=(o.transform.currFlipState="horizontal"===n&&"horizontal"===a||"vertical"===n&&"vertical"===a?"":n,{isSelected:null}),n=(o.notify("draw",{prop:"getRotatedFlipCropSelection",onPropertyChange:!1,value:{bool:a}}),a.isSelected&&(o.img.destLeft+=o.panPoint.totalPannedInternalPoint.x,o.img.destTop+=o.panPoint.totalPannedInternalPoint.y),this.lowerContext.filter);o.notify("draw",{prop:"drawImage",onPropertyChange:!1}),this.lowerContext.filter=n,o.notify("draw",{prop:"setImageEdited",onPropertyChange:!1}),this.updateFlipState(t.toLowerCase()),this.isReverseFlip||(o.notify("draw",{prop:"updateCurrTransState",onPropertyChange:!1,value:{type:"reverse",isPreventDestination:null,isRotatePan:null}}),this.updateFlipColl(t.toLocaleLowerCase()),o.rotateFlipColl.push(t.toLowerCase())),1===o.rotateFlipColl.length&&(o.notify("crop",{prop:"getCurrFlipState",onPropertyChange:!(a={panRegion:""}),value:{panObj:a}}),""===a.panRegion?o.notify("draw",{prop:"setClientTransDim",onPropertyChange:!1,value:{isPreventDimension:null}}):this.setDestPointsForFlipState()),o.isCircleCrop&&o.notify("crop",{prop:"cropCircle",onPropertyChange:!1,value:{context:this.lowerContext,isSave:null,isFlip:null}}),o.objColl=O.extend([],r,[],!0),o.activeObj=O.extend({},e,{},!0);for(var s=0,l=o.objColl.length;s<l;s++){var p=o.objColl[s].flipObjColl;0!==p.length&&p[p.length-1]===t?p.pop():p.push(t)}o.notify("shape",{prop:"redrawObj",onPropertyChange:!1,value:{degree:t.toLowerCase()}});n=this.lowerContext.filter,a=(this.lowerContext.filter="brightness(1) contrast(100%) hue-rotate(0deg) saturate(100%) opacity(1) blur(0px) sepia(0%) grayscale(0%) invert(0%)",o.notify("shape",{prop:"iterateObjColl",onPropertyChange:!1}),t.toLowerCase()),r=(("horizontal"===a||"vertical"===a)&&o.notify("freehand-draw",{prop:"flipFHDColl",onPropertyChange:!1,value:{value:a}}),o.notify("freehand-draw",{prop:"freehandRedraw",onPropertyChange:!1,value:{context:this.lowerContext,points:null}}),this.lowerContext.filter=n,o.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),this.updateCurrSelectionPoint(a),o.isUndoRedo=!1,o.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.lowerContext}}),o.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.upperContext}}),o.isCircleCrop&&o.notify("crop",{prop:"cropCircle",onPropertyChange:!1,value:{context:this.lowerContext,isSave:null,isFlip:null}}),i&&(this.upperContext.clearRect(0,0,o.upperCanvas.width,o.upperCanvas.height),o.activeObj=O.extend({},o.objColl[o.objColl.length-1],{},!0),o.objColl.pop(),o.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate",obj:o.activeObj}})),{collection:o.rotateFlipColl});o.notify("shape",{prop:"alignRotateFlipColl",onPropertyChange:!1,value:{collection:o.rotateFlipColl,isRotateFlipCollection:!0,obj:r}}),o.rotateFlipColl=r.collection,o.cropObj.activeObj.shape&&!this.isPreventSelect&&(o.notify("draw",{prop:"setIsCropSelect",value:{bool:!0}}),this.isPreventSelect=!0,o.notify("draw",{prop:"select",onPropertyChange:!1,value:{type:"custom",startX:null,startY:null,width:null,height:null}}),this.isPreventSelect=!1,o.setProperties({zoomSettings:{zoomFactor:1}},!0),this.prevZoomValue=o.zoomSettings.zoomFactor)}},b.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())},b.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)},b.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)},b.prototype.updateFlipColl=function(e){this.isPreventSelect||(0===this.flipColl.length||this.flipColl[this.flipColl.length-1]!==e?this.flipColl.push(e):this.flipColl.pop(),4<=this.flipColl.length&&("horizontal"===(e=this.flipColl.slice(-4))[0]&&"vertical"===e[1]&&"horizontal"===e[2]&&"vertical"===e[3]||"vertical"===e[0]&&"horizontal"===e[1]&&"vertical"===e[2]&&"horizontal"===e[3])&&this.flipColl.splice(-4))},b.prototype.setDestPointsForFlipState=function(){var e=this.parent,t={panRegion:""},o=e.img,i=o.destLeft,r=o.destTop,n=o.destWidth,o=o.destHeight,a=e.lowerCanvas,s=a.clientWidth,a=a.clientHeight;e.notify("crop",{prop:"getCurrFlipState",onPropertyChange:!1,value:{panObj:t}}),""!==t.panRegion&&("horizontal"===t.panRegion?e.img.destLeft=s-(n+i):("vertical"!==t.panRegion&&(e.img.destLeft=s-(n+i)),e.img.destTop=a-(o+r)))},b.prototype.zoomAction=function(e,t,o,i){var r=this.parent;if(!r.disabled&&r.isImageLoaded)if(O.isNullOrUndefined(o)&&(r.zoomSettings.zoomFactor>=r.zoomSettings.maxZoomFactor&&0<e||r.zoomSettings.zoomFactor>r.zoomSettings.minZoomFactor&&e<0&&this.disableZoomOutBtn(!0)||r.zoomSettings.zoomFactor<=r.zoomSettings.minZoomFactor&&e<0))r.notify("toolbar",{prop:"zoom-up-handler",onPropertyChange:!1});else{r.notify("draw",{prop:"setImageEdited",onPropertyChange:!1});var n=e;e=0<n?.1:-.1;for(var a,s=0;s<Math.round(Math.abs(n/.1));s++)1===this.prevZoomValue?this.prevZoomValue+=0<e?10*e:10*e/10:1<this.prevZoomValue?this.prevZoomValue+=10*e:this.prevZoomValue<1&&(this.prevZoomValue+=10*e/10,a=Math.pow(10,1),this.prevZoomValue=Math.round(this.prevZoomValue*a)/a);e=n,r.setProperties({zoomSettings:{zoomFactor:this.prevZoomValue}},!0);var o=void 0,o=(this.tempActiveObj=null,this.isShape=!1,void 0!==r.activeObj.shape&&("shape"===r.activeObj.shape?r.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}):o=r.activeObj.shape.split("-")),void 0!==o&&"crop"===o[0]?(this.tempActiveObj=O.extend({},r.activeObj,{},!0),r.isCropTab=!0):r.activeObj.shape&&"crop"!==o[0]&&(this.isShape=!0),{zoomType:null}),l=(r.notify("selection",{prop:"getZoomType",onPropertyChange:!1,value:{obj:o}}),O.isNullOrUndefined(t)&&(t=r.isCropTab&&this.tempActiveObj?{x:r.activeObj.activePoint.startX+r.activeObj.activePoint.width/2,y:r.activeObj.activePoint.startY+r.activeObj.activePoint.height/2}:{x:r.lowerCanvas.clientWidth/2,y:r.lowerCanvas.clientHeight/2},"MouseWheel"!==o.zoomType&&"Pinch"!==o.zoomType||(t={x:r.zoomSettings.zoomPoint.x,y:r.zoomSettings.zoomPoint.y})),r.zoomSettings.zoomFactor-10*e),t={zoomPoint:t,cancel:!1,previousZoomFactor:l,currentZoomFactor:r.zoomSettings.zoomFactor,zoomTrigger:o.zoomType};!r.isCropToolbar&&r.isZoomBtnClick&&r.trigger("zooming",t),this.zoomEvent(t,e,i)}},b.prototype.zoomEvent=function(e,t,o){var i,r,n,a,s=this.parent,l=s.zoomSettings,p=l.zoomFactor,l=l.minZoomFactor;e.cancel?s.isZoomBtnClick=!1:(s.notify("toolbar",{prop:"close-contextual-toolbar",onPropertyChange:!1}),s.notify("shape",{prop:"redrawActObj",onPropertyChange:!1,value:{x:null,y:null,isMouseDown:!0}}),s.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),this.upperContext.clearRect(0,0,s.lowerCanvas.width,s.lowerCanvas.height),n={canvasFilter:s.canvasFilter},this.lowerContext.filter=n.canvasFilter,s.upperCanvas.style.cursor=s.cursor="default",n=O.extend([],s.objColl,[],!0),s.isCropTab||(0!==s.transform.degree?(s.notify("shape",{prop:"redrawActObj",onPropertyChange:!1,value:{x:null,y:null,isMouseDown:null}}),s.panPoint.currentPannedPoint={x:0,y:0},a=s.allowDownScale,s.allowDownScale=!1,this.rotatePan(!0,!0),s.allowDownScale=a):""!==s.transform.currFlipState&&(s.panPoint.totalPannedPoint={x:0,y:0}),0!==s.transform.straighten)||this.isPreventSelect||s.notify("freehand-draw",{prop:"updateFHDColl",onPropertyChange:!1,value:{isPreventApply:o}}),0===s.transform.degree?(this.drawZoomImgToCanvas(t,this.tempActiveObj),s.notify("crop",{prop:"getCurrFlipState",onPropertyChange:!(i={panRegion:""}),value:{panObj:i}}),""!==i.panRegion&&(s.notify("crop",{prop:"setTempFlipPanPoint",onPropertyChange:!1,value:{point:s.panPoint.totalPannedPoint,isAdd:!0}}),n=O.extend([],s.objColl,[],!0),s.objColl=[],i=s.img.destLeft,r=s.img.destTop,this.setDestPointsForFlipState(),this.rotatedFlip(),s.img.destLeft=i,s.img.destTop=r,s.objColl=n,s.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"zoom",pen:"zoom",isPreventApply:o}}),0!==s.transform.straighten||this.isPreventSelect||s.notify("freehand-draw",{prop:"updateFHDColl",onPropertyChange:!1,value:{isPreventApply:o}})),p<=l&&!s.isCropTab&&(s.panPoint.totalPannedPoint={x:0,y:0})):(0!==s.transform.straighten||this.isPreventSelect||s.notify("freehand-draw",{prop:"updateFHDColl",onPropertyChange:!1,value:{isPreventApply:o}}),s.panPoint.totalPannedClientPoint={x:0,y:0},s.panPoint.totalPannedInternalPoint={x:0,y:0},this.rotateZoom(t),s.notify("crop",{prop:"getCurrFlipState",onPropertyChange:!(i={panRegion:""}),value:{panObj:i}}),""!==i.panRegion&&(a=this.lowerContext.filter,this.lowerContext.filter="none",s.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"zoom",pen:"zoom",isPreventApply:o}}),this.lowerContext.filter=a)),r=Math.pow(10,1),(p<=l||Math.round(s.transform.zoomFactor*r)/r==2)&&(clearInterval(this.zoomBtnHold),this.zoomBtnHold=0),s.notify("crop",{prop:"getCurrFlipState",onPropertyChange:!(n={panRegion:""}),value:{panObj:n}}),""===n.panRegion&&(a=this.lowerContext.filter,this.lowerContext.filter="none",s.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"zoom",pen:"zoom",isPreventApply:o}}),this.lowerContext.filter=a),(s.currSelectionPoint&&"crop-circle"===s.currSelectionPoint.shape||s.isCircleCrop)&&s.notify("crop",{prop:"cropCircle",onPropertyChange:!1,value:{context:this.lowerContext,isSave:null,isFlip:null}}),s.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.lowerContext}}),s.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),this.tempActiveObj&&(s.activeObj=O.extend({},this.tempActiveObj,{},!0),s.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate",obj:s.activeObj}}),p<=l)&&(s.currSelectionPoint=null),s.isUndoRedo=!1,(t=document.querySelector("#"+s.element.id+"_zoomOut"))&&p<=l?(t.classList.add("e-disabled"),t.parentElement.classList.add("e-overlay")):t&&(t.classList.remove("e-disabled"),t.parentElement.classList.remove("e-overlay")),i=s.drawingShape,this.autoEnablePan(),s.drawingShape=i,this.tempActiveObj&&(s.activeObj=O.extend({},this.tempActiveObj,{},!0)),"crop-custom"===s.activeObj.shape&&(s.currObjType.isCustomCrop=!0),(r=s.element.querySelector(".e-img-pan .e-btn"))&&s.togglePan?r.classList.add("e-selected-btn"):r&&r.classList.remove("e-selected-btn"),this.isShape&&(s.activeObj=O.extend({},s.objColl[s.objColl.length-1],{},!0),s.objColl.pop(),s.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate",obj:s.activeObj,isCropRatio:null,points:null,isPreventDrag:!0,saveContext:null,isPreventSelection:null}}),s.notify("toolbar",{prop:"update-toolbar-items",onPropertyChange:!1}),s.notify("toolbar",{prop:"renderQAT",onPropertyChange:!1,value:{isPenEdit:null}})),s.notify("toolbar",{prop:"enable-disable-btns",onPropertyChange:!1}),s.notify("selection",{prop:"setZoomType",onPropertyChange:!1,value:{zoomType:"Toolbar"}}),e={zoomPoint:e.zoomPoint,previousZoomFactor:e.previousZoomFactor,currentZoomFactor:e.currentZoomFactor,zoomTrigger:e.zoomTrigger},!s.isCropToolbar&&s.isZoomBtnClick&&(s.isZoomBtnClick=!1),s.drawingShape&&(n=O.extend({},s.activeObj,{},!0),s.enableShapeDrawing(s.toPascalCase(s.drawingShape),!0),0<(s.activeObj=n).activePoint.width||0<n.activePoint.height||n.pointColl&&0<n.pointColl.length)&&(o=s.element.querySelector("#"+s.element.id+"_zOrderBtn"),a=s.element.querySelector("#"+s.element.id+"_duplicate"),p=s.element.querySelector("#"+s.element.id+"_remove"),l=s.element.querySelector("#"+s.element.id+"_editText"),o&&o.classList.remove("e-disabled"),a&&a.classList.remove("e-disabled"),p&&p.classList.remove("e-disabled"),l)&&l.classList.remove("e-disabled"))},b.prototype.disableZoomOutBtn=function(e){var t,o,i,r=this.parent,n=r.zoomSettings,a=n.zoomFactor,n=n.minZoomFactor,s=!1,l=(O.isNullOrUndefined(e)||(r.transform.zoomFactor-=.1),t=r.element.querySelector("#"+r.element.id+"_zoomOut"),{destLeft:r.img.destLeft,destTop:r.img.destTop,destWidth:r.img.destWidth,destHeight:r.img.destHeight});return r.activeObj.shape?(o=this.setZoomDimension(-.1,r.activeObj),O.isNullOrUndefined(t)||(i=r.activeObj.activePoint,s=0===r.transform.straighten?r.img.destLeft>i.startX||r.img.destTop>i.startY||r.img.destLeft+r.img.destWidth<i.endX||r.img.destTop+r.img.destHeight<i.endY||a===n?(t.classList.add("e-disabled"),t.parentElement.classList.add("e-overlay"),!0):(t.classList.remove("e-disabled"),t.parentElement.classList.remove("e-overlay"),!1):(r.img.destWidth=o.width,r.img.destHeight=o.height,r.notify("draw",{prop:"updateImgCanvasPoints",onPropertyChange:!(i={isIntersect:null})}),r.notify("draw",{prop:"isLinesIntersect",onPropertyChange:!1,value:{obj:i}}),i.isIntersect||a===n?(t.classList.add("e-disabled"),t.parentElement.classList.add("e-overlay"),!0):(t.classList.remove("e-disabled"),t.parentElement.classList.remove("e-overlay"),!1)))):this.setZoomDimension(-.1,null),O.isNullOrUndefined(e)||(r.transform.zoomFactor+=.1),r.img.destLeft=l.destLeft,r.img.destTop=l.destTop,r.img.destWidth=l.destWidth,r.img.destHeight=l.destHeight,s},b.prototype.drawZoomImgToCanvas=function(e,t){var o=this.parent,i=Math.pow(10,1),i=Math.round(o.transform.zoomFactor*i)/i,i=(.1==i&&-.1===e||0==i&&-.025===e?o.transform.zoomFactor=0:o.transform.zoomFactor+=e,o.transform[o.isCropTab?"cropZoomFactor":"defaultZoomFactor"]=o.transform.zoomFactor,{width:0,height:0});o.isCropTab?i=this.cropZoom(e,t):((i=this.calcMaxDimension(o.img.srcWidth,o.img.srcHeight)).width+=i.width*o.transform.zoomFactor,i.height+=i.height*o.transform.zoomFactor,o.img.destLeft=(o.lowerCanvas.clientWidth-i.width)/2,o.img.destTop=(o.lowerCanvas.clientHeight-i.height+1)/2),o.notify("draw",{prop:"draw-image-to-canvas",value:{dimension:i}}),i.width=this.cropDimension.width,i.height=this.cropDimension.height,i.width+=i.width*o.transform.zoomFactor,i.height+=i.height*o.transform.zoomFactor,o.notify("draw",{prop:"setZoomCropWidth",value:{width:i.width,height:i.height}})},b.prototype.rotatedFlip=function(){var e=this.parent,t=(this.isReverseFlip=!0,e.transform.currFlipState),o=this.flipColl,i=O.extend([],e.objColl,[],!0),r=O.extend({},e.activeObj,{},!0),n=(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}}),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}}),""===t&&""!==e.transform.currFlipState&&(t=e.transform.currFlipState),e.transform.currFlipState=t,this.flipColl=o,e.objColl=O.extend([],i,[],!0),this.lowerContext.filter="none",e.notify("shape",{prop:"iterateObjColl",onPropertyChange:!1}),this.lowerContext.filter=n,0!==r.activePoint.width&&(e.activeObj=O.extend({},r,{},!0)),this.isReverseFlip=!1},b.prototype.rotateZoom=function(e){var t=this.parent,o=Math.pow(10,1),o=Math.round(t.transform.zoomFactor*o)/o,o=(.1==o&&-.1===e||0==o&&-.025===e?t.transform.zoomFactor=0:t.transform.zoomFactor+=e,t.isCropTab?t.transform.cropZoomFactor=t.transform.zoomFactor:t.transform.defaultZoomFactor=t.transform.zoomFactor,O.extend([],t.objColl,[],!0)),e=O.extend({},t.activeObj,{},!0),i=(t.objColl=[],t.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),t.notify("draw",{prop:"updateCurrTransState",onPropertyChange:!1,value:{type:"initial",isPreventDestination:null,isRotatePan:null}}),t.notify("draw",{prop:"setRotateZoom",onPropertyChange:!1,value:{isRotateZoom:!0}}),t.notify("draw",{prop:"setDestPoints",onPropertyChange:!1}),this.lowerContext.filter),i=(t.notify("draw",{prop:"drawImage",onPropertyChange:!1}),this.lowerContext.filter=i,t.notify("draw",{prop:"setRotateZoom",onPropertyChange:!1,value:{isRotateZoom:!1}}),t.notify("draw",{prop:"updateCurrTransState",onPropertyChange:!1,value:{type:"reverse",isPreventDestination:null,isRotatePan:null}}),t.objColl=o,t.activeObj=e,{width:this.cropDimension.width,height:this.cropDimension.height});i.width+=i.width*t.transform.zoomFactor,i.height+=i.height*t.transform.zoomFactor,t.notify("draw",{prop:"setZoomCropWidth",value:{width:i.width,height:i.height}})},b.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)},b.prototype.cropZoom=function(e,t){var o=this.parent,i=o.img.destLeft,r=o.img.destTop,n={width:0,height:0};return 0===o.img.srcLeft||0===o.img.srcTop?n=O.isNullOrUndefined(t)?this.setZoomDimension(e,null):this.setZoomDimension(e,t):((n=o.transform.degree%90==0&&o.transform.degree%180!=0?this.calcMaxDimension(o.img.srcHeight,o.img.srcWidth):this.calcMaxDimension(o.img.srcWidth,o.img.srcHeight)).width+=n.width*o.transform.zoomFactor,n.height+=n.height*o.transform.zoomFactor),o.img.destLeft=i-(n.width-o.img.destWidth)/2,o.img.destTop=r-(n.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+n.width<t.activePoint.endX&&(o.img.destLeft=t.activePoint.endX-n.width,0===o.transform.degree)&&(o.panPoint.totalPannedPoint.x-=i-o.img.destLeft),o.img.destTop+n.height<t.activePoint.endY)&&(o.img.destTop=t.activePoint.endY-n.height,0===o.transform.degree)&&(o.panPoint.totalPannedPoint.y-=r-o.img.destTop),n},b.prototype.setZoomDimension=function(e,t){var o,i,r,n,a,s=this.parent,l=s.transform.degree,p={width:0,height:0};return(p=l%90==0&&l%180!=0?this.calcMaxDimension(s.img.srcHeight,s.img.srcWidth):this.calcMaxDimension(s.img.srcWidth,s.img.srcHeight)).width+=p.width*s.transform.zoomFactor,p.height+=p.height*s.transform.zoomFactor,s.img.destLeft+=(s.img.destWidth-p.width)/2,s.img.destTop+=(s.img.destHeight-p.height)/2,e<0&&t?(l=t.activePoint.startX,o=t.activePoint.startY,i=t.activePoint.width,r=t.activePoint.height,n=s.img.destLeft+p.width,a=s.img.destTop+p.height,s.img.destLeft>l&&(s.img.destLeft=l),s.img.destTop>o&&(s.img.destTop=o),n<l+i&&(s.img.destLeft=l+i-p.width),a<o+r&&(s.img.destTop=o+r-p.height)):e<0&&O.isNullOrUndefined(t)&&(0<s.img.destLeft&&(s.img.destLeft=0),0<s.img.destTop&&(s.img.destTop=0),s.img.destLeft+p.width<s.lowerCanvas.clientWidth&&(s.img.destLeft=s.lowerCanvas.clientWidth-s.img.destWidth),s.img.destTop+p.height<s.lowerCanvas.clientHeight)&&(s.img.destTop=s.lowerCanvas.clientHeight-s.img.destHeight),p},b.prototype.drawPannedImage=function(e,t){var o=this.parent,i={panDown:null},i=(o.notify("selection",{prop:"getPanDown",onPropertyChange:!1,value:{obj:i}}),{startPoint:i.panDown,endPoint:this.panMove,cancel:!1});o.trigger("panning",i),i.cancel||this.panEvent(e,t)},b.prototype.panEvent=function(e,t,o){var i,r,n,a,s,l=this.parent,p=!1;l.activeObj.shape&&"shape"===l.activeObj.shape&&l.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),O.isNullOrUndefined(l.activeObj.shape)&&(p=!0,s=(i=l.activeObj.activePoint={startX:l.img.destLeft,startY:l.img.destTop,endX:l.img.destLeft+l.img.destWidth,endY:l.img.destTop+l.img.destHeight}).startX,r=i.startY,n=i.endX,a=i.endY,s<0&&(i.startX=0),r<0&&(i.startY=0),n>l.lowerCanvas.width&&(i.endX=l.lowerCanvas.width),a>l.lowerCanvas.height&&(i.endY=l.lowerCanvas.height),i.width=i.endX-i.startX,i.height=i.endY-i.startY,l.activeObj.shape="crop-custom",l.notify("shape",{prop:"getStrokeSettings",onPropertyChange:!(s={strokeSettings:{}}),value:{obj:s}}),l.activeObj.strokeSettings=s.strokeSettings,l.notify("draw",{prop:"updateActiveObject",onPropertyChange:!1,value:{actPoint:i,obj:l.activeObj,isMouseMove:null,x:null,y:null}}),l.isCropTab=!0),0===l.transform.degree?(r=void 0,r=O.isNullOrUndefined(e)&&O.isNullOrUndefined(t)||o?o?this.updatePanPoints(e,t):this.updatePanPoints():{x:e,y:t},l.panPoint.totalPannedPoint.x+=r.x,l.panPoint.totalPannedPoint.y+=r.y,n=O.extend({},l.activeObj,{},!0),a=this.lowerContext.filter,this.drawPannImage(r,p),this.lowerContext.filter=a,this.tempPanMove=O.extend({},this.panMove,{},!0),l.activeObj=O.extend({},n,{},!0),this.upperContext.clearRect(0,0,l.upperCanvas.width,l.upperCanvas.height),l.activeObj.shape&&l.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate",obj:l.activeObj}})):(s=l.transform.currFlipState,l.isCropTab=!0,O.isNullOrUndefined(e)&&O.isNullOrUndefined(t)||o?l.panPoint.currentPannedPoint=o?this.updatePanPoints(e,t):this.updatePanPoints():l.panPoint.currentPannedPoint={x:e,y:t},l.transform.currFlipState=s,this.rotatePan(null,null,p),l.isCropTab=!1,this.tempPanMove=O.extend({},this.panMove,{},!0)),p&&(l.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),l.isCropTab=!1,this.upperContext.clearRect(0,0,l.upperCanvas.width,l.upperCanvas.height))},b.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},i=(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,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=i,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}})},b.prototype.resetZoom=function(){var e,t,o=this.parent;0!==o.transform.defaultZoomFactor&&(e=o.isUndoRedo,o.notify("filter",{prop:"getCurrentObj",onPropertyChange:!(t={currObj:{}}),value:{object:t}}),this.transCurrObj=t.currObj,this.transCurrObj.objColl=O.extend([],o.objColl,null,!0),this.transCurrObj.pointColl=O.extend({},o.pointColl,null,!0),this.transCurrObj.afterCropActions=O.extend([],o.afterCropActions,[],!0),o.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!(t={selPointColl:null}),value:{obj:t}}),this.transCurrObj.selPointColl=O.extend([],t.selPointColl,[],!0),o.isUndoRedo=o.isCropToolbar=!0,0<(t=o.transform.defaultZoomFactor)?this.zoomAction(-t):this.zoomAction(Math.abs(t)),o.isCropToolbar=!1,o.isUndoRedo=e)},b.prototype.performTransformation=function(e){var t=this.parent,o=t.transform.defaultZoomFactor,i=t.isUndoRedo,r=O.extend({},t.cropObj,{},!0);this.resetZoom(),this.updateTransform(e);for(var n,a=0,s=t.objColl.length;a<s;a++)0<t.objColl[a].flipObjColl.length&&(n={collection:t.objColl[a].flipObjColl},t.notify("shape",{prop:"alignRotateFlipColl",onPropertyChange:!1,value:{collection:n.collection,isRotateFlipCollection:null,obj:n}}),t.objColl[a].flipObjColl=n.collection,0===t.objColl[a].flipObjColl.length)&&(t.objColl[a].shapeFlip="");0!==o&&(t.isUndoRedo=!0,this.zoomAction(o),t.isUndoRedo=i,o="","rotateleft"===e||"rotateright"===e?o="rotate":"horizontalflip"!==e&&"verticalflip"!==e||(o="flip"),t.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:o,previousObj:this.transCurrObj,previousObjColl:this.transCurrObj.objColl,previousPointColl:this.transCurrObj.pointColl,previousSelPointColl:this.transCurrObj.selPointColl,previousCropObj:r,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),this.transCurrObj=null)},b.prototype.updateTransform=function(e){switch(e.toLowerCase()){case"rotateleft":this.rotateImage(-90);break;case"rotateright":this.rotateImage(90);break;case"horizontalflip":this.flipImage(v.Direction.Horizontal);break;case"verticalflip":this.flipImage(v.Direction.Vertical)}},b.prototype.rotatePan=function(e,t,o){var i,r=this.parent,n=(this.isReverseRotate=!0,r.transform.degree),a={selPointColl:null},s=(r.activeObj.activePoint&&r.activeObj.shape&&(i=O.extend({},r.activeObj,{},!0)),O.extend([],r.objColl,[],!0)),l=O.extend([],r.pointColl,[],!0),a=(r.objColl=[],r.pointColl=[],r.freehandCounter=0,r.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:a}}),a.selPointColl),p=(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}}),r.img.destLeft),h=r.img.destTop,d=r.panPoint.totalPannedInternalPoint,d=(r.isCropTab&&(r.img.destLeft+=d.x,r.img.destTop+=d.y),r.notify("crop",{prop:"updateRotatePan",onPropertyChange:!1}),r.isCropTab&&(r.panPoint.totalPannedInternalPoint.x=r.img.destLeft-p,r.panPoint.totalPannedInternalPoint.y=r.img.destTop-h),this.lowerContext.filter),p=(o&&(r.isCropTab=!1),r.notify("draw",{prop:"drawImage",onPropertyChange:!1}),o&&(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}}),r.img.destLeft),h=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-p,r.panPoint.totalPannedClientPoint.y=r.img.destTop-h,r.objColl=s,r.pointColl=l,r.freehandCounter=r.pointColl.length,r.notify("freehand-draw",{prop:"setSelPointColl",onPropertyChange:!1,value:{obj:{selPointColl:a}}}),r.transform.degree=n,this.lowerContext.filter="none",e&&(t?(r.panPoint.totalPannedClientPoint.x=-r.panPoint.totalPannedClientPoint.x,r.panPoint.totalPannedClientPoint.y=-r.panPoint.totalPannedClientPoint.y,r.panPoint.currentPannedPoint=O.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=O.extend({},r.panPoint.totalPannedClientPoint,{},!0)),o&&(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:""}}),o&&(r.isCropTab=!0),this.lowerContext.filter=d,r.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.lowerContext}}),this.upperContext.clearRect(0,0,r.upperCanvas.width,r.upperCanvas.height),r.activeObj=O.extend({},i,{},!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},b.prototype.limitPan=function(){var e=this.parent,t=e.activeObj.activePoint,o=t.startX,i=t.startY,r=t.endX,t=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<t)&&(e.img.destTop=t-n.destHeight)},b.prototype.pan=function(e,t,o){var i=this.parent;!i.disabled&&i.isImageLoaded&&(e?(i.togglePan=!0,i.notify("shape",{prop:"redrawActObj",onPropertyChange:!1,value:{x:null,y:null,isMouseDown:null}}),i.notify("selection",{prop:"setDragCanvas",value:{bool:!0}}),i.lowerCanvas.style.cursor=i.upperCanvas.style.cursor=i.cursor="grab",i.notify("selection",{prop:"setPanDown",onPropertyChange:!1,value:{panDown:null}}),(t||o)&&(t=t||0,o=o||0,O.isNullOrUndefined(this.panMove)&&(this.panMove={x:t,y:o}),O.isNullOrUndefined(this.tempPanMove)&&(this.tempPanMove={x:this.panMove.x,y:this.panMove.y}),this.panEvent(t,o,!0),this.tempPanMove=null)):(i.togglePan=i.currObjType.isCustomCrop=!1,i.notify("selection",{prop:"setDragCanvas",value:{bool:!1}}),i.lowerCanvas.style.cursor=i.upperCanvas.style.cursor=i.cursor="default"))},b.prototype.zoom=function(e,t){var o=this.parent;if(!o.disabled&&o.isImageLoaded){e=this.getCurrentZoomFactor(e);if(O.isNullOrUndefined(t))this.zoomAction(e,t);else for(var i=0<e?"zoomIn":"zoomOut",r=10*Math.abs(e),n=0;n<r;n++)o.notify("draw",{prop:"performPointZoom",onPropertyChange:!1,value:{x:t.x,y:t.y,type:i,isResize:null}})}},b.prototype.getCurrentZoomFactor=function(e){return!(1<=e)||this.prevZoomValue<1?e-this.prevZoomValue:.1*(e-this.prevZoomValue)},b.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},b.prototype.rotate=function(e,t){var o=this.parent;!o.disabled&&o.isImageLoaded&&e%90==0&&this.rotateImage(e),t.isRotate=!1},b.prototype.flip=function(e){var t=this.parent;!t.disabled&&t.isImageLoaded&&this.flipImage(e)},b.prototype.update=function(){var e,t,o=this.parent,i=0,r=!1,n={bool:!1},a=o.isStraightening,s=0,l=o.element.querySelector("#"+o.element.id+"_contextualToolbar"),p=o.element.querySelector(".e-contextual-toolbar-wrapper"),h=o.element.querySelector("#"+o.element.id+"_headWrapper"),d=(o.isImageLoaded&&(e=!1,d=void 0,O.Browser.isDevice&&(o.activeObj.shape&&(d=o.activeObj.shape.split("-")),o.currObjType.isCustomCrop||d&&"crop"===d[0])&&(e=!0),o.notify("toolbar",{prop:"getFrameToolbar",onPropertyChange:!1,value:{obj:{bool:null}}}),!a&&(l&&!l.parentElement.classList.contains("e-hide")||h&&!h.parentElement.classList.contains("e-hide"))&&(p.classList.add("e-hide"),e||o.okBtn(null,!0),o.notify("toolbar",{prop:"refresh-main-toolbar",onPropertyChange:!1}),o.notify("toolbar",{prop:"destroy-qa-toolbar",onPropertyChange:!1})),o.notify("selection",{prop:"getFreehandDrawEditing",onPropertyChange:!1,value:{obj:n}}),n.bool&&o.notify("toolbar",{prop:"destroy-qa-toolbar",onPropertyChange:!1}),void 0!==o.activeObj.shape)&&(r=!0,"block"===o.textArea.style.display||"inline-block"===o.textArea.style.display?(o.notify("shape",{prop:"redrawActObj",onPropertyChange:!1,value:{x:null,y:null,isMouseDown:null}}),o.notify("toolbar",{prop:"destroy-qa-toolbar",onPropertyChange:!1})):(o.notify("shape",{prop:"updImgRatioForActObj",onPropertyChange:!1}),o.objColl.push(o.activeObj)),o.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1})),this.lowerContext.filter),l=o.element.querySelector("#"+o.element.id+"_canvasWrapper"),h=(l&&(l.style.width=o.element.offsetWidth-2+"px"),o.lowerCanvas.width=o.upperCanvas.width=o.element.offsetWidth-2,o.toolbarTemplate?i=o.element.querySelector("#"+o.element.id+"_toolbarArea").clientHeight:o.element.querySelector("#"+o.element.id+"_toolbar")&&0===(i=o.element.querySelector("#"+o.element.id+"_toolbar").clientHeight)&&o.toolbar&&0<o.toolbar.length&&-1===o.toolbar.indexOf("Open")&&(o.notify("toolbar",{prop:"getToolbarHeight",value:{obj:t={toolbarHeight:0}}}),i=t.toolbarHeight),o.element.querySelector("#"+o.element.id+"_contextualToolbarArea"));O.Browser.isDevice&&a&&h&&(s=h.clientHeight),o.notify("toolbar",{prop:"setToolbarHeight",value:{height:i}}),O.Browser.isDevice?l&&(l.style.height=o.element.offsetHeight-(2*i+s)-4+"px"):l&&(l.style.height=o.element.offsetHeight-i-2+"px"),o.lowerCanvas.height=o.upperCanvas.height=parseFloat(l.style.height),this.lowerContext.filter="brightness(1) contrast(100%) hue-rotate(0deg) saturate(100%) opacity(1) blur(0px) sepia(0%) grayscale(0%) invert(0%)",o.notify("filter",{prop:"setAdjustmentValue",onPropertyChange:!1,value:{adjustmentValue:this.lowerContext.filter}}),o.canvasFilter=this.lowerContext.filter,o.initialAdjustmentValue=this.lowerContext.filter,o.clearContext(this.lowerContext),o.clearContext(this.upperContext),o.isImageLoaded&&(o.notify("shape",{prop:"applyActObj",onPropertyChange:!1,value:{isMouseDown:null}}),o.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),this.lowerContext.filter=d,o.initialAdjustmentValue=d,o.canvasFilter=this.lowerContext.filter,o.isImageLoaded&&(u.showSpinner(o.element),o.element.style.opacity="0.5"),this.lowerContext.clearRect(0,0,o.lowerCanvas.width,o.lowerCanvas.height),this.upperContext.clearRect(0,0,o.upperCanvas.width,o.upperCanvas.height),l&&(l.style.width=o.element.offsetWidth-2+"px",l.style.height=o.element.offsetHeight+"px",o.notify("toolbar",{prop:"getToolbarHeight",value:{obj:e={toolbarHeight:0}}}),O.Browser.isDevice?l.style.height=parseFloat(l.style.height)-2*e.toolbarHeight-s-4+"px":l.style.height=parseFloat(l.style.height)-e.toolbarHeight-2+"px"),o.lowerCanvas.width=o.upperCanvas.width=parseFloat(l.style.width),o.lowerCanvas.height=o.upperCanvas.height=parseFloat(l.style.height),this.lowerContext.filter=d,this.calcMaxDimension(o.img.srcWidth,o.img.srcHeight,t={width:0,height:0}),h=t,a&&0!==o.transform.cropZoomFactor?(h.width+=h.width*o.transform.cropZoomFactor,h.height+=h.height*o.transform.cropZoomFactor):0<o.transform.defaultZoomFactor&&(h.width+=h.width*o.transform.defaultZoomFactor,h.height+=h.height*o.transform.defaultZoomFactor),o.img.destLeft=(o.lowerCanvas.clientWidth-h.width)/2,o.img.destTop=(o.lowerCanvas.clientHeight-h.height+1)/2,0===o.transform.degree&&""===o.transform.currFlipState?(0<o.transform.defaultZoomFactor&&(o.img.destLeft+=o.panPoint.totalPannedPoint.x,o.img.destTop+=o.panPoint.totalPannedPoint.y),o.notify("draw",{prop:"draw-image-to-canvas",value:{dimension:h}})):(o.notify("draw",{prop:"draw-image-to-canvas",value:{dimension:h}}),o.notify("draw",{prop:"updateCurrTransState",onPropertyChange:!1,value:{type:"initial",isPreventDestination:null,isRotatePan:null}}),i=this.lowerContext.filter,o.notify("draw",{prop:"drawImage",onPropertyChange:!1}),this.lowerContext.filter=i,o.notify("draw",{prop:"updateCurrTransState",onPropertyChange:!1,value:{type:"reverse",isPreventDestination:null,isRotatePan:null}})),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.isCircleCrop&&o.notify("crop",{prop:"cropCircle",onPropertyChange:!1,value:{context:this.lowerContext,isSave:null,isFlip:null}}),u.hideSpinner(o.element),o.element.style.opacity="1",o.notify("toolbar",{prop:"getDefToolbarItems",value:{obj:s={defToolbarItems:null}}}),s.defToolbarItems&&0<s.defToolbarItems.length&&document.getElementById(o.element.id+"_toolbar")&&(O.getComponent(o.element.id+"_toolbar","toolbar").refreshOverflow(),p)&&!a&&p.classList.add("e-hide"),o.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),this.upperContext.clearRect(0,0,o.upperCanvas.width,o.upperCanvas.height),r&&(e=O.extend({},o.objColl[o.objColl.length-1],null,!0),o.objColl.pop(),0!==e.activePoint.width)&&0!==e.activePoint.height&&(this.lowerContext.clearRect(0,0,o.lowerCanvas.width,o.lowerCanvas.height),o.notify("draw",{prop:"render-image",value:{isMouseWheel:null}}),o.objColl.push(e),o.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"zoom",pen:"zoom",isPreventApply:null}}),e=O.extend({},o.objColl[o.objColl.length-1],null,!0),o.objColl.pop(),this.lowerContext.clearRect(0,0,o.lowerCanvas.width,o.lowerCanvas.height),o.notify("draw",{prop:"render-image",value:{isMouseWheel:null}}),o.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate",obj:e}}),a&&o.notify("draw",{prop:"setStraightenActObj",value:{activeObj:e}}),"rectangle"!==o.activeObj.shape&&"ellipse"!==o.activeObj.shape&&"text"!==o.activeObj.shape&&"line"!==o.activeObj.shape&&"arrow"!==o.activeObj.shape&&"path"!==o.activeObj.shape&&"image"!==o.activeObj.shape||o.notify("toolbar",{prop:"renderQAT",onPropertyChange:!1,value:{isPenEdit:null}})),n.bool&&o.notify("toolbar",{prop:"renderQAT",onPropertyChange:!1,value:{isPenEdit:!0}}),o.isResize&&(o.aspectWidth=Math.ceil(o.img.destWidth),o.aspectHeight=Math.ceil(o.img.destHeight),o.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"resize",isApplyBtn:!1,isCropping:!1}}),o.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"resize",isApplyBtn:!1,isCropping:!1}})),(0!==o.transform.degree||""!==o.transform.currFlipState)&&0<o.transform.defaultZoomFactor?(l=O.extend({},o.panPoint.totalPannedPoint,null,!0),d=O.extend({},o.panPoint.totalPannedInternalPoint,null,!0),t=O.extend({},o.panPoint.totalPannedClientPoint,null,!0),this.zoomAction(.1),this.zoomAction(-.1),0===o.transform.degree?(o.img.destLeft+=l.x,o.img.destTop+=l.y,o.panPoint.totalPannedPoint=l,o.notify("draw",{prop:"updateFlipPan",value:{tempSelectionObj:null}})):(o.panPoint.totalPannedInternalPoint=d,o.panPoint.totalPannedClientPoint=t,o.panPoint.currentPannedPoint={x:0,y:0},o.isCropTab=!0,this.rotatePan(),o.isCropTab=!1)):0!==o.transform.degree&&0<o.transform.cropZoomFactor&&(o.transform.zoomFactor=0,o.transform.cropZoomFactor=null,o.notify("toolbar",{prop:"enable-disable-btns",onPropertyChange:!1})))},b.prototype.calcMaxDimension=function(e,t,o,i){var r={toolbarHeight:0},n=this.parent,a=(n.notify("toolbar",{prop:"getToolbarHeight",value:{obj:r}}),i?n.element.clientWidth/3:n.element.clientWidth),s=i?(n.element.clientHeight-r.toolbarHeight)/3:n.element.clientHeight-r.toolbarHeight,s=O.Browser.isDevice?s-r.toolbarHeight:s,r=(O.Browser.isDevice&&n.isStraightening&&(s-=(r=n.element.querySelector("#"+n.element.id+"_contextualToolbarArea"))?r.clientHeight:0),i||0!==n.element.clientHeight||(s=0),O.isNullOrUndefined(i)&&(30<a&&(a-=30),30<s)&&(s-=30),a/e),l=s/t,a=Math.min(e,a),s=Math.min(t,s);return r<1&&r<l?(a=e*r,s=t*r):l<1&&l<r&&(a=e*l,s=t*l),O.isNullOrUndefined(i)&&(n.notify("crop",{prop:"getPreventScaling",onPropertyChange:!(r={bool:null}),value:{obj:r}}),r.bool)&&n.cropObj.activeObj.activePoint&&0!==n.cropObj.activeObj.activePoint.width&&0!==n.cropObj.activeObj.activePoint.height&&(a=n.cropObj.activeObj.activePoint.width,s=n.cropObj.activeObj.activePoint.height),o&&(o.width=a,o.height=s),{width:a,height:s}},b.prototype.updatePanPoints=function(e,t){for(var o=this.parent,i=O.extend({},o.activeObj,{},!0),r=o.img.destLeft,n=o.img.destTop,a=(O.isNullOrUndefined(this.tempPanMove)&&(this.tempPanMove={x:this.panMove.x,y:this.panMove.y}),this.panMove.x-this.tempPanMove.x),s=this.panMove.y-this.tempPanMove.y,l=((e||t)&&(a=e,s=t),o.img.destLeft+=a,o.img.destTop+=s,this.limitPan(),{bool:null}),p={isIntersect:null},h=(o.notify("draw",{prop:"updateImgCanvasPoints",onPropertyChange:!1}),o.notify("draw",{prop:"isLinesIntersect",onPropertyChange:!1,value:{obj:p}}),o.notify("draw",{prop:"isSelOutsideImg",onPropertyChange:!1,value:{obj:l}}),0);0!==o.transform.straighten&&(p.isIntersect||l.bool)&&(h++,o.img.destLeft=r,o.img.destTop=n,0!==a&&0<a?--a:0!==a&&a<0&&(a+=1),0!==s&&0<s?--s:0!==s&&s<0&&(s+=1),0!==a||0!==s)&&200!==h;)o.img.destLeft+=a,o.img.destTop+=s,this.limitPan(),o.notify("draw",{prop:"updateImgCanvasPoints",onPropertyChange:!1}),o.notify("draw",{prop:"isLinesIntersect",onPropertyChange:!1,value:{obj:p}}),o.notify("draw",{prop:"isSelOutsideImg",onPropertyChange:!1,value:{obj:l}});return o.activeObj=i,{x:o.img.destLeft-r,y:o.img.destTop-n}},b.prototype.resizeImage=function(e,t){var o=this.parent,i=!0,r=!0,n=(o.allowDownScale=!1,o.img.srcLeft=0,o.img.srcTop=0,o.isAspectRatio=!0,[]);for(o.img.srcWidth=o.baseImgCanvas.width,o.img.srcHeight=o.baseImgCanvas.height,o.resizeSrc&&0!==o.resizeSrc.width&&0!==o.resizeSrc.height&&(o.img.srcLeft=o.resizeSrc.startX,o.img.srcTop=o.resizeSrc.startY,o.img.srcWidth=o.resizeSrc.width,o.img.srcHeight=o.resizeSrc.height);(e<o.img.destWidth||t<o.img.destHeight)&&r;)if(this.zoomAction(-.1,null,!0,!0),e>o.img.destWidth||t>o.img.destHeight)for(;e>o.img.destWidth||t>o.img.destHeight;)this.zoomAction(.0125,null,!0,!0),r=!1,n.push(o.img.destWidth);for(;(e>o.img.destWidth||t>o.img.destHeight)&&r&&i;)if(this.zoomAction(.1,null,!0,!0),e<o.img.destWidth||t<o.img.destHeight)for(;e<o.img.destWidth;)this.zoomAction(-.0125,null,!0,!0),i=!1,n.push(o.img.destWidth);for(var a=n[0],s=Math.abs(o.img.destWidth-a),l=0,p=n;l<p.length;l++){var h=p[l],d=Math.abs(e-h);d<s&&(a=h,s=d)}a<e&&i&&(this.zoomAction(-.0125,null,!0,!0),i=!1),e<a&&!i&&(this.zoomAction(.0125,null,!0,!0),i=!1),this.zoomAction(.0125,null,!0),o.allowDownScale=!0,this.zoomAction(-.0125,null,!0);var c=O.extend({},o.cropObj,{},!0),u=O.extend({},this.prevResizeCurrObj,{},!0);o.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"resize",previousObj:u,previousObjColl:u.objColl,previousPointColl:u.pointColl,previousSelPointColl:u.selPointColl,previousCropObj:c,previousText:null,currentText:null,previousFilter:null,isCircleCrop:o.isCircleCrop}}),o.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"ok"}})},b.prototype.resizeCrop=function(e,t){var o=this.parent,i=!0,r={prevObj:o.prevObj},n=(o.cropObj=O.extend({},o.prevCropObj,{},!0),o.allowDownScale=!1,o.notify("toolbar",{prop:"getPrevObj",onPropertyChange:!1,value:{obj:r}}),O.extend({},r.prevObj.activeObj,{},!0)),a=(r.prevObj.activeObj=O.extend({},o.activeObj,{},!0),o.notify("draw",{prop:"setCurrentObj",onPropertyChange:!1,value:{obj:r.prevObj}}),o.objColl=O.extend([],r.prevObj.objColl,[],!0),o.pointColl=O.extend([],r.prevObj.pointColl,[],!0),o.transform.straighten=0,o.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"zoom",pen:"zoom",isPreventApply:null}}),0!==o.transform.straighten||this.isPreventSelect||o.notify("freehand-draw",{prop:"updateFHDColl",onPropertyChange:!1}),e),s=t,l=!1;if(e<=t&&t<=Math.ceil(o.img.destHeight)){for(;t<=Math.ceil(o.img.destHeight)&&i;)if(this.zoomAction(-.1,null,!0,!0),e>o.img.destWidth||t>o.img.destHeight)for(;e>o.img.destWidth||t>o.img.destHeight;)this.zoomAction(.0125,null,!0,!0),i=!1}else if(t<=e&&e<o.img.destWidth){for(;e<o.img.destWidth&&i;)if(this.zoomAction(-.1,null,!0,!0),e>o.img.destWidth||t>o.img.destHeight)for(;e>o.img.destWidth||t>o.img.destHeight;)this.zoomAction(.0125,null,!0,!0),i=!1}else if(e<=t&&t>=o.img.destHeight)for(;t>=o.img.destHeight&&i;)this.zoomAction(.1,null,!0,!0);else if(t<=e&&e>=o.img.destWidth){for(;e>=o.img.destWidth&&i;)this.zoomAction(.1,null,!0,!0);if(e<o.img.destWidth&&t<o.img.destHeight){for(;e<o.img.destWidth&&t<o.img.destHeight;)this.zoomAction(-.0125,null,!0,!0),i=!1;this.zoomAction(.0125,null,!0,!0)}}else if(t>o.img.destHeight&&e>o.img.destWidth){for(;t>o.img.destHeight&&e>o.img.destWidth&&i;)this.zoomAction(.1,null,!0,!0);if(e<o.img.destWidth&&t<o.img.destHeight){for(;e<o.img.destWidth&&t<o.img.destHeight;)this.zoomAction(-.0125,null,!0,!0),i=!1;this.zoomAction(.0125,null,!0,!0)}}if(this.resizeImg(n,e,t),e=a,(t=s)!==o.img.destHeight||e!==o.img.destWidth){for(;t>o.img.destHeight||e>o.img.destWidth;)this.zoomAction(.0125,null,!0,!0),l=!0;l&&(this.zoomAction(-.0125,null,!0,!0),l=!1)}if(t!==o.img.destHeight||e!==o.img.destWidth){for(;t<o.img.destHeight||e<o.img.destWidth;)this.zoomAction(-.0125,null,!0,!0),l=!0;l&&(this.zoomAction(-.0125,null,!0,!0),l=!1)}r.prevObj.activeObj=O.extend({},n,{},!0),this.zoomAction(.0125,null,!0),o.allowDownScale=!this.preventDownScale,o.isCropTab=!1,this.zoomAction(-.0125,null,!0),o.aspectWidth=e,o.aspectHeight=t},b.prototype.resizeImg=function(e,t,o){for(var i=this.parent,r=t/i.img.destWidth,n=o/i.img.destHeight,a=(e.shape?(i.currSelectionPoint=e,i.notify("crop",{prop:"setInitCrop",onPropertyChange:!1,value:{bool:!0}})):i.img.srcWidth===i.baseImgCanvas.width&&i.img.srcHeight===i.baseImgCanvas.height&&(i.currSelectionPoint=null,i.notify("draw",{prop:"select",onPropertyChange:!1,value:{type:"custom",startX:null,startY:null,width:null,height:null}})),O.isNullOrUndefined(i.currSelectionPoint)?i.notify("draw",{prop:"select",onPropertyChange:!1,value:{type:"custom",startX:i.img.destLeft,startY:i.img.destTop,width:i.img.destWidth,height:i.img.destHeight}}):i.notify("draw",{prop:"select",onPropertyChange:!1,value:{type:"custom",startX:null,startY:null,width:null,height:null}}),t=i.activeObj.activePoint.width*r,o=i.activeObj.activePoint.height*n,i.activeObj.activePoint.startX+i.activeObj.activePoint.width/2-t/2),s=i.activeObj.activePoint.startY+i.activeObj.activePoint.height/2-o/2,l=0;O.Browser.isDevice&&l<500&&(a<0||s<0||a+t>i.img.destWidth||s+o>i.img.destHeight);)l++,a=i.activeObj.activePoint.startX+i.activeObj.activePoint.width/2- --t/2,s=i.activeObj.activePoint.startY+i.activeObj.activePoint.height/2- --o/2;if(i.transform.defaultZoomFactor=0,i.notify("draw",{prop:"setResizeSelect",value:{bool:!0}}),i.notify("draw",{prop:"setIsCropSelect",value:{bool:!0}}),i.notify("draw",{prop:"select",onPropertyChange:!1,value:{type:"custom",startX:a,startY:s,width:t,height:o}}),i.notify("draw",{prop:"setResizeSelect",value:{bool:!1}}),0!==i.transform.straighten){var p={isIntersect:null,arr:null};for(i.notify("draw",{prop:"updateImgCanvasPoints",onPropertyChange:!1}),i.notify("draw",{prop:"isLinesIntersect",onPropertyChange:!1,value:{obj:p}});p.arr[0]||p.arr[1]||p.arr[2]||p.arr[3];)this.zoomAction(.0125,null,!0),i.notify("draw",{prop:"updateImgCanvasPoints",onPropertyChange:!1}),i.notify("draw",{prop:"isLinesIntersect",onPropertyChange:!1,value:{obj:p}})}i.isCropToolbar=!0,i.crop(),i.isCropToolbar=!1},b.prototype.updateResize=function(){var e=this.parent,t=(e.prevCropObj=O.extend({},e.cropObj,{},!0),{currObj:{}}),t=(e.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:t}}),e.prevObj=t.currObj,e.currSelectionPoint&&e.prevCropObj.activeObj.shape&&(e.prevObj.activeObj=O.extend({},e.prevCropObj.activeObj,{},!0)),e.prevObj.objColl=O.extend([],e.objColl,[],!0),e.prevObj.pointColl=O.extend([],e.pointColl,[],!0),e.prevObj.afterCropActions=O.extend([],e.afterCropActions,[],!0),{selPointColl:null});e.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:t}}),e.prevObj.selPointColl=O.extend([],t.selPointColl,[],!0),e.resizeSrc={startX:e.img.srcLeft,startY:e.img.srcTop,width:e.img.srcWidth,height:e.img.srcHeight}},b.prototype.resize=function(e,t,o){var i=this.parent,r=(i.isResize=!0,O.isNullOrUndefined(i.prevCropObj)&&O.isNullOrUndefined(i.prevObj)&&i.notify("transform",{prop:"updateResize",value:{bool:!1}}),i.element.querySelector("#"+i.element.id+"_aspectratio")),n=i.element.querySelector("#"+i.element.id+"_nonaspectratio"),r=(r&&n&&(i.notify("toolbar",{prop:"initResizeToolbar"}),O.Browser.isDevice)&&i.notify("toolbar",{prop:"init-main-toolbar",value:{isApplyBtn:!1,isDevice:!0,isOkBtn:!0,isResize:!0}}),i.element.querySelector("#"+i.element.id+"_resizeHeight")),n=""===r.value?r.placeholder:r.value,r={cancel:!1,previousWidth:Math.ceil(i.img.destWidth),previousHeight:Math.ceil(i.img.destHeight),width:Math.ceil(e),height:t&&0!==t?Math.ceil(t):o?Math.ceil(parseFloat(n)):Math.ceil(i.img.destHeight),isAspectRatio:o||!1};i.trigger("resizing",r),r.cancel?i.aspectHeight&&i.aspectWidth&&(i.aspectHeight=r.previousHeight,i.aspectWidth=r.previousWidth):this.resizeEventHandler(r)},b.prototype.resizeEventHandler=function(e){var t,o,i,r,n,a,s,l=this.parent,p=l.element.querySelector("#"+l.element.id+"_resizeWidth"),h=l.element.querySelector("#"+l.element.id+"_resizeHeight"),d=l.element.querySelector(".e-ie-toolbar-e-resize-height-input .e-textbox"),c=l.element.querySelector(".e-ie-toolbar-e-resize-width-input .e-textbox");e.isAspectRatio?(null!=this.resizedImgAngle&&this.resizedImgAngle===l.transform.degree||(this.resizedImgAngle=l.transform.degree,t=!0),t?(l.notify("transform",{prop:"resizeImage",value:{width:e.width,height:0}}),o=l.img.destWidth,i=l.img.destHeight,s=void 0,s=parseFloat(""===p.value?p.placeholder:p.value),h?(n=.5<=(r=s/(o/i))%1||r%1<=-.5?Math.round(r):r<0?Math.ceil(r):Math.floor(r),O.getComponent(h,"numerictextbox").value=n,h.value=n.toString()+" px",l.aspectHeight=n,p&&""===p.value&&(a=.5<=(r=parseFloat(""===h.value?h.placeholder:h.value)/(i/o))%1||r%1<=-.5?Math.round(r):r<0?Math.ceil(r):Math.floor(r),O.getComponent(p,"numerictextbox").value=a,p.value=a.toString()+" px",l.aspectWidth=a)):d&&(n=.5<=(r=s/(o/i))%1||r%1<=-.5?Math.round(r):r<0?Math.ceil(r):Math.floor(r),d.value=n.toString(),l.aspectHeight=n,c)&&""===c.value&&(a=.5<=(r=parseFloat(""===d.value?d.placeholder:d.value)/(i/o))%1||r%1<=-.5?Math.round(r):r<0?Math.ceil(r):Math.floor(r),c.value=a.toString(),l.aspectWidth=a)):l.notify("transform",{prop:"resizeImage",value:{width:e.width,height:null}})):(null!==this.resizedImgAngle&&this.resizedImgAngle!==l.transform.degree&&(this.resizedImgAngle=l.transform.degree,t=!0),t?(l.notify("transform",{prop:"setPreventDownScale",value:{bool:!0}}),l.notify("transform",{prop:"resizeCrop",value:{width:e.width,height:e.height}}),l.notify("undo-redo",{prop:"setPreventUR",value:{bool:!0}}),l.okBtn(null,!0),l.notify("undo-redo",{prop:"setPreventUR",value:{bool:!1}}),l.resizeSrc={startX:l.img.srcLeft,startY:l.img.srcTop,width:l.img.srcWidth,height:l.img.srcHeight},l.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"resize",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}}),l.notify("transform",{prop:"setPreventDownScale",value:{bool:!1}}),l.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"resize",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}})):l.notify("transform",{prop:"resizeCrop",value:{width:e.width,height:e.height}})),this.resizedImgAngle=l.transform.degree},b.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()};var B=b;function b(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()}m.prototype.destroy=function(){this.parent.isDestroyed||this.removeEventListener()},m.prototype.addEventListener=function(){this.parent.on("undo-redo",this.undoRedo,this),this.parent.on("destroyed",this.destroy,this)},m.prototype.removeEventListener=function(){this.parent.off("undo-redo",this.undoRedo),this.parent.off("destroyed",this.destroy)},m.prototype.initializeUrPvtProp=function(){this.parent.lowerCanvas&&(this.lowerContext=this.parent.lowerCanvas.getContext("2d")),this.parent.upperCanvas&&(this.upperContext=this.parent.upperCanvas.getContext("2d"))},m.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()}},m.prototype.getModuleName=function(){return"undo-redo"},m.prototype.reset=function(){this.tempCurrSelPoint=null,this.undoRedoStep=0,this.undoRedoColl=[],this.appliedUndoRedoColl=[],this.tempActObj=null,this.tempUndoRedoColl=[],this.tempUndoRedoStep=0,this.isPreventing=!1},m.prototype.refreshUrc=function(e){var t=this.parent;(e=e||!1)&&(t.notify("toolbar",{prop:"setEnableDisableUndoRedo",value:{isPrevent:!0}}),this.tempUndoRedoColl=O.extend([],this.appliedUndoRedoColl,[],!0),this.tempUndoRedoStep=this.undoRedoStep),t.notify("toolbar",{prop:"setEnableDisableUndoRedo",value:{isPrevent:!1}}),this.undoRedoColl=this.undoRedoColl.slice(0,this.undoRedoStep),this.appliedUndoRedoColl=this.appliedUndoRedoColl.slice(0,this.undoRedoStep),t.isUndoRedo=t.currObjType.isUndoAction=!1,t.notify("toolbar",{prop:"enable-disable-btns"})},m.prototype.updateCurrUrc=function(e,t){var o,i,r,n,a=this.parent;a.isResize||this.isPreventing||a.noPushUndo||(a.notify("toolbar",{prop:"setEnableDisableUndoRedo",value:{isPrevent:!1}}),"ok"===e?(a.notify("draw",{prop:"setShapeTextInsert",onPropertyChange:!1,value:{bool:!1}}),n=0<this.tempUndoRedoColl.length?O.extend([],this.tempUndoRedoColl,[],!0):O.extend([],this.undoRedoColl,[],!0),o=this.undoRedoColl[this.undoRedoColl.length-1],i=this.appliedUndoRedoColl[this.appliedUndoRedoColl.length-1],r=o?O.extend({},o.previousObj,{},!0):null,O.isNullOrUndefined(i)?this.undoRedoColl[0]&&(o.previousCropObj=n[0].previousCropObj,o.previousObj=n[0].previousObj,o.previousObjColl=n[0].previousObjColl,o.previousPointColl=n[0].previousPointColl,o.previousText=n[0].previousText):"imageHFlip"!==o.operation&&"imageVFlip"!==o.operation&&(o.previousCropObj=i.currentCropObj,o.previousObj=i.currentObj,o.previousObjColl=i.currentObjColl,o.previousPointColl=i.currentPointColl,o.previousText=i.currentText,"frame"===o.operation)&&o.previousObj&&r&&(o.previousObj.defaultZoom=r.defaultZoom,o.previousObj.zoomFactor=r.zoomFactor,o.previousObj.cropZoom=r.cropZoom),o&&("imageHFlip"!==o.operation&&"imageVFlip"!==o.operation&&(n=this.getZeroZoomObjPointValue(o.currentObjColl,o.currentPointColl),o.currentObjColl=n.obj,o.currentPointColl=n.point,a.notify("filter",{prop:"getAdjustmentLevel",onPropertyChange:!(i={adjustmentLevel:null}),value:{obj:i}}),o.currentObj.adjustmentLevel=O.extend({},i.adjustmentLevel,{},!0),a.notify("filter",{prop:"setTempAdjVal"}),o.currentObj.currentFilter=a.currentFilter),this.appliedUndoRedoColl.push(o)),this.tempUndoRedoColl=[],this.tempUndoRedoStep=0):0<this.tempUndoRedoColl.length&&(this.appliedUndoRedoColl=O.extend([],this.tempUndoRedoColl,[],!0),this.undoRedoStep=this.tempUndoRedoStep,this.tempUndoRedoColl=[],this.tempUndoRedoStep=0),r=this.appliedUndoRedoColl[this.appliedUndoRedoColl.length-1],n=this.appliedUndoRedoColl[this.appliedUndoRedoColl.length-2],16<this.appliedUndoRedoColl.length?this.appliedUndoRedoColl.splice(0,1):!t&&r&&n&&(("shapeTransform"===r.operation&&"shapeTransform"===n.operation||"shapeInsert"===r.operation&&"shapeInsert"===n.operation)&&JSON.stringify(r.currentObjColl)===JSON.stringify(n.currentObjColl)||"freehand-draw"===r.operation&&"freehand-draw"===n.operation&&JSON.stringify(r.currentPointColl)===JSON.stringify(n.currentPointColl)||"freehanddrawCustomized"===r.operation&&"freehanddrawCustomized"===n.operation&&JSON.stringify(r.currentPointColl)===JSON.stringify(n.currentPointColl))&&this.appliedUndoRedoColl.splice(this.appliedUndoRedoColl.length-1,1),this.undoRedoColl=[],this.undoRedoColl=O.extend([],this.appliedUndoRedoColl,[],!0),"ok"===e&&(this.undoRedoStep=this.undoRedoColl.length,a.notify("toolbar",{prop:"enable-disable-btns"})),0<a.transform.zoomFactor&&(a.togglePan=!0,a.notify("selection",{prop:"setDragCanvas",value:{bool:!0}})))},m.prototype.cancelCropSelection=function(){var e,t=this.parent,o=!1;t.activeObj.shape&&(e=t.activeObj.shape.split("-")),(o=t.currObjType.isCustomCrop||e&&"crop"===e[0]?!0:o)&&t.notify("draw",{prop:"performCancel",value:{isContextualToolbar:null}}),0===this.tempUndoRedoColl.length&&0===this.tempUndoRedoStep||(this.appliedUndoRedoColl=O.extend([],this.tempUndoRedoColl,[],!0),this.undoRedoColl=O.extend([],this.tempUndoRedoColl,[],!0),this.undoRedoStep=this.tempUndoRedoStep,this.tempUndoRedoColl=[],this.tempUndoRedoStep=0,t.notify("toolbar",{prop:"setEnableDisableUndoRedo",value:{isPrevent:!1}}))},m.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})},m.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)),0<this.appliedUndoRedoColl.length&&(this.undoRedoColl=O.extend([],this.appliedUndoRedoColl,[],!0))},m.prototype.callUndo=function(){this.applyCurrentChanges(),this.undo()},m.prototype.callRedo=function(){this.applyCurrentChanges(),this.redo()},m.prototype.undo=function(){var e=this.parent;if(this.cancelCropSelection(),e.notify("draw",{prop:"resetFrameZoom",onPropertyChange:!1,value:{isOk:!1}}),!e.disabled&&e.isImageLoaded&&0<this.undoRedoStep){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 t=this.undoRedoColl[this.undoRedoStep];this.undoRedoColl.length===this.undoRedoStep?e.currObjType.isUndoAction=!1:e.currObjType.isUndoAction=!0,"textAreaCustomization"===t.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=O.extend({},t.previousCropObj,{},!0),e.afterCropActions=t.previousObj.afterCropActions,this.lowerContext.filter=t.previousObj.filter,e.notify("filter",{prop:"setAdjustmentLevel",onPropertyChange:!1,value:{adjustmentLevel:t.previousObj.adjustmentLevel}}),e.notify("filter",{prop:"setTempAdjVal"}),e.currentFilter=t.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}}),t.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(t.previousObjColl,t.previousPointColl);break;case"freehanddraw":case"freehand-draw":this.updateFreehandDraw(t.previousPointColl,t.previousSelPointColl),e.notify("freehand-draw",{prop:"setCurrentFreehandDrawIndex",value:{value:e.pointColl.length}});break;case"freehanddrawCustomized":this.updateFreehandDrawCustomized(t.previousObjColl,t.previousPointColl);break;case"deleteFreehandDrawing":case"deleteObj":this.updateDelete(t.operation,t.previousObjColl,t.previousPointColl,t.previousSelPointColl);break;case"textAreaCustomization":this.shapeTransform(t.previousObjColl,t.previousPointColl),this.updateTextAreaCustomization(void 0,t.previousObjColl);break;case"text":this.updateText(t.previousObjColl,!0);break;case"frame":e.transform.zoomFactor=e.transform.defaultZoomFactor=t.previousObj.defaultZoom,e.setProperties({zoomSettings:{zoomFactor:t.previousObj.zoomFactor}},!0),e.notify("transform",{prop:"setPreviousZoomValue",onPropertyChange:!1,value:{previousZoomValue:e.zoomSettings.zoomFactor}}),O.extend(e.frameObj,t.previousObj.frameObj),e.notify("draw",{prop:"render-image",value:{isMouseWheel:!0,isPreventClearRect:null,isFrame:!0}});break;case"imageHFlip":this.imageFlip("horizontal",t.previousObjColl);break;case"imageVFlip":this.imageFlip("vertical",t.previousObjColl);break;default:this.undoDefault(t,!0),e.notify("filter",{prop:"set-adjustment",value:{operation:t.operation}}),e.notify("filter",{prop:"update-filter",value:{operation:t.operation,filter:t.filter}})}"crop"===t.operation?(t.previousObj.currSelectionPoint&&(e.currSelectionPoint=O.extend({},t.previousObj.currSelectionPoint,{},!0),e.currSelectionPoint)&&O.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=O.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"===t.operation&&e.cropObj&&e.cropObj.activeObj&&(e.currSelectionPoint=O.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(t.operation,!0)}},m.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 t,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=O.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}});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(void 0,o.currentObjColl);break;case"text":this.updateText(o.currentObjColl,!1);break;case"frame":O.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,t=O.extend({},e.activeObj,{},!0),e.objColl=O.extend([],o.currentObjColl,[],!0),e.pointColl=O.extend([],o.currentPointColl,[],!0),e.freehandCounter=e.pointColl.length,e.notify("freehand-draw",{prop:"setSelPointColl",onPropertyChange:!1,value:{obj:{selPointColl:O.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=t,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=O.extend({},this.tempCurrSelPoint,{},!0),this.tempCurrSelPoint=null),"crop"!==o.operation||o.isCircleCrop||(e.isCircleCrop=!1),"crop"===o.operation&&o.currentObj.currSelectionPoint&&(e.currSelectionPoint=O.extend({},o.currentObj.currSelectionPoint,{},!0),e.notify("draw",{prop:"setStraightenActObj",value:{activeObj:e.currSelectionPoint}})),e.currSelectionPoint&&O.isNullOrUndefined(e.currSelectionPoint.shape)&&(e.currSelectionPoint=null),"resize"===o.operation&&e.cropObj&&e.cropObj.activeObj&&(e.currSelectionPoint=O.extend({},e.cropObj.activeObj,{},!0)),this.endUndoRedo(o.operation,!1)}},m.prototype.imageFlip=function(e,t){var o=this.parent,t=(this.shapeTransform(t,null),o.activeObj=O.extend({},o.objColl[o.objColl.length-1],{},!0),o.activeObj),i=t.shape,r=t.isHorImageFlip,t=t.isVerImageFlip;o.objColl.pop(),i&&"image"===i?("horizontal"===e?(O.isNullOrUndefined(r)&&t?(o.activeObj.isHorImageFlip=!0,o.activeObj.isVerImageFlip=null):O.isNullOrUndefined(r)||!r?o.activeObj.isHorImageFlip=!0:o.activeObj.isHorImageFlip=null,o.horizontalFlip(this.upperContext,!0)):"vertical"===e&&(O.isNullOrUndefined(t)&&r?(o.activeObj.isVerImageFlip=!0,o.activeObj.isHorImageFlip=null):O.isNullOrUndefined(t)||!t?o.activeObj.isVerImageFlip=!0:o.activeObj.isVerImageFlip=null,o.verticalFlip(this.upperContext,!0)),o.notify("shape",{prop:"applyActObj",onPropertyChange:!1,value:{isMouseDown:!0}})):o.notify("draw",{prop:"render-image",value:{isMouseWheel:!0}})},m.prototype.shapeTransform=function(e,t){var o=this.parent;o.objColl=O.extend([],e,[],!0),t&&(o.pointColl=O.extend([],t,[],!0),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}),o.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1})},m.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})},m.prototype.updateFreehandDrawCustomized=function(e,t){var o=this.parent;o.objColl=O.extend([],e,[],!0),o.pointColl=t,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})},m.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})},m.prototype.updateTextAreaCustomization=function(e,t){var o=this.parent;o.objColl=O.extend([],t,[],!0),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),o.isUndoRedo=!0,o.notify("draw",{prop:"redrawImgWithObj",onPropertyChange:!1});for(var i=0,r=t.length;i<r;i++){if(!this.tempActObj){e=O.extend({},t[t.length-1],{},!0),o.objColl.splice(i,1);break}if(this.tempActObj.currIndex===t[i].currIndex){e=O.extend({},t[i],{},!0),o.objColl.splice(i,1);break}}e&&this.updateTextBox(e),"block"!==o.textArea.style.display&&"inline-block"!==o.textArea.style.display||o.notify("shape",{prop:"redrawActObj",onPropertyChange:!1,value:{x:null,y:null,isMouseDown:null}})},m.prototype.updateText=function(e,t){var o=this.parent;if(this.tempActObj&&(o.activeObj=O.extend({},this.tempActObj,{},!0)),0===e.length&&1===o.objColl.length)this.tempActObj=O.extend({},o.objColl[0],{},!0);else for(var i=0,r=o.objColl.length;i<r;i++){if(o.objColl[i]&&O.isNullOrUndefined(e[i])){this.tempActObj=O.extend({},o.objColl[i],{},!0);break}if(e[i].currIndex!==o.objColl[i].currIndex){this.tempActObj=O.extend({},o.objColl[i],{},!0);break}}t&&(o.activeObj=O.extend({},this.tempActObj,{},!0)),o.objColl=O.extend([],e,[],!0),o.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"zoom",pen:"zoom",isPreventApply:!0}}),this.upperContext.clearRect(0,0,o.upperCanvas.width,o.upperCanvas.height),this.lowerContext.clearRect(0,0,o.lowerCanvas.width,o.lowerCanvas.height),o.isUndoRedo=!0,o.notify("draw",{prop:"redrawImgWithObj",onPropertyChange:!1}),o.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1})},m.prototype.updateTextBox=function(e){var t=this.parent,o=(this.upperContext.clearRect(0,0,t.lowerCanvas.width,t.lowerCanvas.height),this.lowerContext.clearRect(0,0,t.lowerCanvas.width,t.lowerCanvas.height),t.notify("draw",{prop:"redrawImgWithObj",onPropertyChange:!1}),t.notify("toolbar",{prop:"destroy-qa-toolbar",onPropertyChange:!1}),t.textArea);o.style.display="block",o.style.fontFamily=e.textSettings.fontFamily,o.style.fontSize=e.textSettings.fontSize+"px",o.style.color=e.strokeSettings.strokeColor,o.style.fontWeight=e.textSettings.bold?"bold":"normal",o.style.fontStyle=e.textSettings.italic?"italic":"normal",o.style.border="2px solid "+t.themeColl[t.theme].primaryColor,o.value=e.keyHistory,t.activeObj=O.extend({},e,{},!0),t.notify("shape",{prop:"updateFontStyles",onPropertyChange:!1,value:{isTextBox:null}}),t.textArea.style.width=t.activeObj.activePoint.width+"px"},m.prototype.undoDefault=function(e,t){this.lowerContext.filter=e.previousObj.filter;var o=this.parent,t=(o.objColl=[],o.pointColl=[],o.freehandCounter=0,o.notify("freehand-draw",{prop:"setSelPointColl",onPropertyChange:!1,value:{obj:{selPointColl:[]}}}),o.notify("draw",{prop:"setCurrentObj",onPropertyChange:!1,value:{obj:e.previousObj,isUndoRedo:t}}),o.prevStraightenedDegree=o.transform.straighten,this.upperContext.clearRect(0,0,o.upperCanvas.width,o.upperCanvas.height),o.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),o.img.destLeft=e.previousObj.destPoints.startX,o.img.destTop=e.previousObj.destPoints.startY,O.extend({},o.activeObj,{},!0));o.objColl=O.extend([],e.previousObjColl,[],!0),o.pointColl=O.extend([],e.previousPointColl,[],!0),o.freehandCounter=o.pointColl.length,o.notify("freehand-draw",{prop:"setSelPointColl",onPropertyChange:!1,value:{obj:{selPointColl:O.extend([],e.previousSelPointColl,[],!0)}}}),o.transform.straighten=0,this.lowerContext.filter="none",o.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"zoom",pen:"zoom",isPreventApply:null}}),this.lowerContext.filter=e.previousObj.filter,o.activeObj=t,this.upperContext.clearRect(0,0,o.upperCanvas.width,o.upperCanvas.height),0!==o.activeObj.activePoint.width&&0!==o.activeObj.activePoint.height&&o.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate"}})},m.prototype.endUndoRedo=function(e,t){var o=this.parent;(o.currSelectionPoint&&"crop-circle"===o.currSelectionPoint.shape||o.isCircleCrop)&&JSON.stringify(o.frameObj)!==JSON.stringify({type:"none",color:"#fff",size:20,inset:20,offset:20,radius:0,amount:1,border:"solid",gradientColor:""})&&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}}),0<o.transform.zoomFactor&&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},m.prototype.updateUrc=function(e,t,o,i,r,n,a,s,l,p){var h=this.parent;if(!h.isResize&&!this.isPreventing){var d={isInitialLoaded:!1};if(h.currObjType.isUndoAction&&this.refreshUrc(!0),h.notify("draw",{prop:"isInitialLoaded",onPropertyChange:!1,value:{object:d}}),!d.isInitialLoaded&&h.allowUndoRedo){var d={currObj:{}},d=(h.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:d}}),d.currObj),c=(d.objColl=O.extend([],h.objColl,[],!0),d.pointColl=O.extend([],h.pointColl,[],!0),d.afterCropActions=O.extend([],h.afterCropActions,[],!0),{selPointColl:null});if(h.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:c}}),d.selPointColl=O.extend([],c.selPointColl,[],!0),"crop"===e)d.currSelectionPoint=O.extend({},h.currSelectionPoint,{},!0);else if("frame"===e)t.destPoints={startX:h.frameDestPoints.destLeft,startY:h.frameDestPoints.destTop,width:h.frameDestPoints.destWidth,height:h.frameDestPoints.destHeight},d.destPoints={startX:h.frameDestPoints.destLeft,startY:h.frameDestPoints.destTop,width:h.frameDestPoints.destWidth,height:h.frameDestPoints.destHeight},O.isNullOrUndefined(h.tempFrameZoomLevel)||(t.defaultZoom=d.defaultZoom=h.tempFrameZoomLevel);else if(("imageHFlip"===e||"imageVFlip"===e)&&0<this.appliedUndoRedoColl.length){var u=o[o.length-1].currIndex;if(o=this.appliedUndoRedoColl[this.appliedUndoRedoColl.length-1].currentObjColl,u)for(var g=0,v=o.length;g<v;g++)if(o[g].currIndex===u){var f=O.extend({},o[g],{},!0);o.splice(g,1),o.push(f);break}}this.undoRedoColl.push({operation:e,previousObj:t,currentObj:d,previousObjColl:o,currentObjColl:d.objColl,previousPointColl:i,currentPointColl:d.pointColl,previousSelPointColl:r,currentSelPointColl:d.selPointColl,previousCropObj:n,currentCropObj:O.extend({},h.cropObj,{},!0),previousText:a,currentText:s,filter:l,isCircleCrop:p}),h.notify("toolbar",{prop:"enable-disable-btns",onPropertyChange:!1})}}},m.prototype.updateUrObj=function(e,t){var o,i,r,n=this.parent;n.allowUndoRedo&&(n.currObjType.isUndoAction&&!n.isShapeDrawing&&this.refreshUrc(!0),O.isNullOrUndefined(n.activeObj.imageRatio)&&n.notify("shape",{prop:"updImgRatioForActObj",onPropertyChange:!1}),n.objColl.push(n.activeObj),o=O.extend({},n.cropObj,{},!0),n.notify("filter",{prop:"getCurrentObj",onPropertyChange:!(i={currObj:{}}),value:{object:i}}),(i=i.currObj).objColl=O.extend([],n.objColl,[],!0),i.pointColl=O.extend([],n.pointColl,[],!0),i.afterCropActions=O.extend([],n.afterCropActions,[],!0),n.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!(r={selPointColl:null}),value:{obj:r}}),i.selPointColl=O.extend([],r.selPointColl,[],!0),this.undoRedoColl.push({operation:t||"shapeTransform",previousObj:i,currentObj:i,previousObjColl:e,currentObjColl:i.objColl,previousPointColl:i.pointColl,currentPointColl:i.pointColl,previousSelPointColl:i.selPointColl,currentSelPointColl:i.selPointColl,previousCropObj:o,currentCropObj:o}),n.notify("selection",{prop:"redrawShape",onPropertyChange:!1,value:{obj:n.objColl[n.objColl.length-1]}}))},m.prototype.updateUndoRedo=function(e){var t=this.parent,o=O.extend({},t.cropObj,{},!0),i={currObj:{}},i=(t.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:i}}),i.currObj),r=(i.objColl=O.extend([],t.objColl,[],!0),i.pointColl=O.extend([],t.pointColl,[],!0),i.afterCropActions=O.extend([],t.afterCropActions,[],!0),{selPointColl:null});t.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:r}}),i.selPointColl=O.extend([],r.selPointColl,[],!0),O.isNullOrUndefined(t.activeObj.imageRatio)&&t.notify("shape",{prop:"updImgRatioForActObj",onPropertyChange:!1}),t.objColl.push(t.activeObj),this.updateUrc(e||"shapeTransform",i,i.objColl,i.pointColl,i.selPointColl,o),t.objColl.pop(),t.notify("shape",{prop:"applyActObj",onPropertyChange:!1,value:{isMouseDown:null}}),t.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),t.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"shapes",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}}),t.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"main",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}})},m.prototype.getZeroZoomObjPointValue=function(e,t){var o=this.parent,i=(this.updateObjColl(),{currObj:{}}),i=(o.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:i}}),i.currObj),r=(i.objColl=O.extend([],o.objColl,[],!0),i.pointColl=O.extend([],o.pointColl,[],!0),i.afterCropActions=O.extend([],o.afterCropActions,[],!0),{selPointColl:null}),r=(o.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:r}}),i.selPointColl=O.extend([],r.selPointColl,[],!0),{cropDimension:null}),n=(o.notify("transform",{prop:"getCropDimension",onPropertyChange:!1,value:{obj:r}}),O.extend([],o.objColl,[],!0)),a=O.extend([],o.pointColl,[],!0),s={arrowDimension:null},s=(this.parent.notify("draw",{prop:"getArrowDimension",onPropertyChange:!1,value:{obj:s}}),O.extend({},s.arrowDimension,{},!0));if(0<o.transform.zoomFactor&&(0<e.length||0<t.length)){if(0<e.length)for(var l=0;l<e.length;l++)e[l].currIndex||(e[l].currIndex="shape_"+(l+1));o.objColl=e,o.pointColl=t;var p,t=o.isUndoRedo,h=o.isCropTab;0!==o.transform.zoomFactor&&(o.isUndoRedo=!0,o.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"zoom",pen:"zoom",isPreventApply:!0}}),o.notify("freehand-draw",{prop:"updateFHDColl",onPropertyChange:!1}),o.isCropTab=!0,p=O.extend({},o.zoomSettings,null,!0),0<o.transform.zoomFactor?o.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:-o.transform.zoomFactor,zoomPoint:null,isResize:null}}):o.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:Math.abs(o.transform.zoomFactor),zoomPoint:null,isResize:null}}),o.zoomSettings=p,o.isCropTab=h,o.isUndoRedo=t,n=O.extend([],o.objColl,[],!0),a=O.extend([],o.pointColl,[],!0),o.objColl=[],o.pointColl=[],o.freehandCounter=0,o.notify("freehand-draw",{prop:"setSelPointColl",onPropertyChange:!1,value:{obj:{selPointColl:[]}}}),o.notify("transform",{prop:"setCropDimension",onPropertyChange:!1,value:{width:r.cropDimension.width,height:r.cropDimension.height}}),(p={width:r.cropDimension.width,height:r.cropDimension.height}).width+=p.width*i.defaultZoom,p.height+=p.height*i.defaultZoom,o.notify("draw",{prop:"setZoomCropWidth",value:{width:p.width,height:p.height}}),o.notify("draw",{prop:"setCurrentObj",onPropertyChange:!1,value:{obj:i}}),o.img.destLeft=i.destPoints.startX,o.img.destTop=i.destPoints.startY,o.panPoint.totalPannedPoint=i.totalPannedPoint,o.panPoint.totalPannedClientPoint=i.totalPannedClientPoint,o.panPoint.totalPannedInternalPoint=i.totalPannedInternalPoint,o.objColl=O.extend([],i.objColl,[],!0),o.pointColl=O.extend([],i.pointColl,[],!0),o.freehandCounter=o.pointColl.length,o.notify("draw",{prop:"setArrowDimension",onPropertyChange:!1,value:{arrowDimension:s}}),o.notify("freehand-draw",{prop:"setSelPointColl",onPropertyChange:!1,value:{obj:{selPointColl:O.extend([],i.selPointColl,[],!0)}}}),this.lowerContext.filter="none",o.transform.straighten=0,this.applyImgTranform(),o.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"iterate",pen:"iterate",isPreventApply:null}}),o.notify("freehand-draw",{prop:"updateFHDCurPts",onPropertyChange:!1}),this.lowerContext.filter=i.filter,0!==o.transform.degree&&o.notify("transform",{prop:"drawPannedImage",onPropertyChange:!1,value:{xDiff:0,yDiff:0}}),o.notify("draw",{prop:"clearOuterCanvas",onPropertyChange:!1,value:{context:this.lowerContext}}),o.isCircleCrop||o.currSelectionPoint&&"crop-circle"===o.currSelectionPoint.shape)&&o.notify("crop",{prop:"cropCircle",onPropertyChange:!1,value:{context:this.lowerContext,isSave:null,isFlip:null}})}return{obj:n,point:a}},m.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)))}},m.prototype.applyImgTranform=function(){for(var e,t=this.parent,o=O.extend({},t.activeObj,{},!0),i=0,r=t.objColl.length;i<r;i++)"image"===t.objColl[i].shape&&(t.activeObj=O.extend({},t.objColl[i],{},!0),e=t.objColl[i].imageCanvas.getContext("2d"),t.notify("selection",{prop:"applyTransformToImg",onPropertyChange:!1,value:{ctx:e}}),this.upperContext.clearRect(0,0,t.upperCanvas.width,t.upperCanvas.height),t.notify("selection",{prop:"setImageClarity",onPropertyChange:!1,value:{bool:!0}}));t.activeObj=o},m.prototype.updateUndoRedoStack=function(e){var t,o,i,r=this.parent;(r.activeObj.currIndex&&0!==r.activeObj.activePoint.width||0!==r.activeObj.activePoint.height||r.activeObj.pointColl&&0<r.activeObj.pointColl.length||e)&&(t="none"!==r.textArea.style.display,o=r.noPushUndo,r.noPushUndo=!1,r.isUndoRedoStack=!0,e?(e=r.togglePen,r.notify("freehand-draw",{prop:"getFreehandDrawSelectedId",onPropertyChange:!(i={freehandDrawSelectedId:null}),value:{obj:i}}),r.okBtn(),r.noPushUndo=o,i.freehandDrawSelectedId?r.selectShape(i.freehandDrawSelectedId):r.freeHandDraw(!0),r.togglePen=e):r.activeObj.currIndex&&(i=r.activeObj.currIndex,r.okBtn(),r.noPushUndo=o,r.selectShape(i),r.drawingShape&&r.notify("selection",{prop:"setCurrentDrawingShape",onPropertyChange:!1,value:{value:r.drawingShape.toLowerCase()}}),t)&&r.enableTextEditing(),r.isUndoRedoStack=!1)};var M=m;function m(e){this.undoRedoStep=0,this.undoRedoColl=[],this.appliedUndoRedoColl=[],this.tempUndoRedoColl=[],this.tempUndoRedoStep=0,this.isPreventing=!1,this.parent=e,this.addEventListener()}y=function(e,t){return(y=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])}))(e,t)};var y,P,j=function(e,t){function o(){this.constructor=e}y(e,t),e.prototype=null===t?Object.create(t):(o.prototype=t.prototype,new o)},x=function(e,t,o,i){var r,n=arguments.length,a=n<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,o):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,o,i);else for(var s=e.length-1;0<=s;s--)(r=e[s])&&(a=(n<3?r(a):3<n?r(t,o,a):r(t,o))||a);return 3<n&&a&&Object.defineProperty(t,o,a),a},U=(P=O.ChildProperty,j(w,P),x([O.Property(null)],w.prototype,"brightness",void 0),x([O.Property(null)],w.prototype,"contrast",void 0),x([O.Property(null)],w.prototype,"hue",void 0),x([O.Property(null)],w.prototype,"saturation",void 0),x([O.Property(null)],w.prototype,"exposure",void 0),x([O.Property(null)],w.prototype,"opacity",void 0),x([O.Property(null)],w.prototype,"blur",void 0),w);function w(){return null!==P&&P.apply(this,arguments)||this}S=O.ChildProperty,j(T,S),x([O.Property(null)],T.prototype,"zoomTrigger",void 0),x([O.Property(1)],T.prototype,"minZoomFactor",void 0),x([O.Property(10)],T.prototype,"maxZoomFactor",void 0),x([O.Property(1)],T.prototype,"zoomFactor",void 0),x([O.Property(null)],T.prototype,"zoomPoint",void 0);var S,W=T;function T(){return null!==S&&S.apply(this,arguments)||this}F=O.ChildProperty,j(k,F),x([O.Property(!0)],k.prototype,"showCircle",void 0),x([O.Property(null)],k.prototype,"strokeColor",void 0),x([O.Property(null)],k.prototype,"fillColor",void 0);var F,_=k;function k(){return null!==F&&F.apply(this,arguments)||this}I=O.ChildProperty,j(A,I),x([O.Property("Arial")],A.prototype,"default",void 0),x([O.Property(null)],A.prototype,"items",void 0);var I,N=A;function A(){return null!==I&&I.apply(this,arguments)||this}z=O.Component,j(X,z),(D=X).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},X.prototype.preRender=function(){this.element.id=this.element.id||O.getUniqueID("ej2-image-editor"),O.Browser.isDevice&&this.element.classList.add("e-device"),this.initializeThemeColl()},X.prototype.render=function(){var e,t;this.isAngular&&(t=(e=this.element).cloneNode(!0),e.parentNode.replaceChild(t,e),this.element=t,O.setValue("ej2_instances",[this],this.element)),this.initialize()},X.prototype.getModuleName=function(){return"image-editor"},X.prototype.getPersistData=function(){return this.addOnPersist([])},X.prototype.onPropertyChanged=function(e,t){for(var o,i=0,r=Object.keys(e);i<r.length;i++)switch(r[i]){case"cssClass":t.cssClass&&O.removeClass([this.element],t.cssClass.replace(/\s+/g," ").trim().split(" ")),e.cssClass&&O.addClass([this.element],e.cssClass.replace(/\s+/g," ").trim().split(" "));break;case"disabled":e.disabled?(this.element.classList.add("e-disabled"),this.unwireEvent()):(this.element.classList.remove("e-disabled"),this.wireEvent());break;case"height":this.element.style.height=e.height,this.update();break;case"width":this.element.style.width=e.width,this.update();break;case"theme":e.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":e.finetuneSettings&&(this.finetuneSettings=e.finetuneSettings,this.notify("filter",{prop:"update-finetunes"}));break;case"locale":e.locale&&(this.notify("toolbar",{prop:"setLocale",onPropertyChange:!1,value:{locale:e.locale}}),this.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"main",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}}));break;case"allowUndoRedo":e.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":e.showQuickAccessToolbar?(this.showQuickAccessToolbar=!0,this.notify("toolbar",{prop:"create-qa-toolbar",onPropertyChange:!1}),this.notify("freehand-draw",{prop:"getFreehandSelectedIndex",onPropertyChange:!(o={freehandSelectedIndex:null}),value:{obj:o}}),this.activeObj.shape?this.notify("toolbar",{prop:"renderQAT",onPropertyChange:!1,value:{isPenEdit:null}}):o.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":e.zoomSettings&&(this.zoomSettings.zoomTrigger=e.zoomSettings.zoomTrigger),O.isNullOrUndefined(this.zoomSettings.zoomTrigger)?(this.zoomSettings.zoomTrigger=v.ZoomTrigger.MouseWheel|v.ZoomTrigger.Pinch|v.ZoomTrigger.Toolbar|v.ZoomTrigger.Commands,this.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"main",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}})):(e.zoomSettings.zoomTrigger&v.ZoomTrigger.Toolbar)===v.ZoomTrigger.Toolbar&&this.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"main",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}});break;case"selectionSettings":e.selectionSettings&&(this.selectionSettings=e.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":e.toolbar&&(this.toolbar=e.toolbar,this.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"main",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}}));break;case"toolbarTemplate":e.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":e.quickAccessToolbarTemplate&&(this.notify("toolbar",{prop:"destroy-qa-toolbar",onPropertyChange:!1}),this.quickAccessToolbarTemplateFn())}},X.prototype.destroy=function(){var e=[],t=(this.element.removeAttribute("tabindex"),this.element.querySelector("#"+this.element.id+"_saveDialog"));t&&"block"===t.style.display&&O.getComponent(document.getElementById(this.element.id+"_saveDialog"),"dialog").destroy(),this.cssClass&&(e=e.concat(this.cssClass.replace(/\s+/g," ").trim().split(" "))),O.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),z.prototype.destroy.call(this),this.element.innerHTML=""},X.prototype.initialize=function(){var e;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(),359<this.element.offsetWidth&&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"})),(e=document.getElementById(this.element.id+"_quickAccessToolbarArea")).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&&O.addClass([this.element],this.cssClass.replace(/\s+/g," ").trim().split(" ")),this.element&&u.createSpinner({target:this.element}),this.initializeZoomSettings(),this.imgSrc&&this.open(this.imgSrc)},X.prototype.createDropUploader=function(){var i=this;new g.Uploader({dropArea:this.element.getElementsByClassName("e-canvas-wrapper")[0],allowedExtensions:".jpg, .jpeg, .png,.svg",multiple:!1,selected:function(e){var t,o;"change"!==e.event.type&&"drop"!==e.event.type||(t=e.filesData[0].type,o="unsupported","change"!==e.event.type&&("drop"!==e.event.type||1!==e.event.dataTransfer.files.length)||"png"!==t&&"jpg"!==t&&"jpeg"!==t&&"svg"!==t?("drop"===e.event.type&&1<e.event.dataTransfer.files.length&&(o="multi-select-image"),i.showDialogPopup(o)):i.notify("draw",{prop:"fileSelect",value:{inputElement:i.element.querySelector("#"+i.element.id+"_dropfileUpload"),args:e}}))}}).appendTo("#"+this.element.id+"_dropfileUpload")},X.prototype.dlgCloseBtnClick=function(){O.getComponent(document.getElementById(this.element.id+"_dialog"),"dialog").destroy()},X.prototype.showDialogPopup=function(e){var t,o,i="",r=(this.element.querySelector("#"+this.element.id+"_dialog").style.display="block",{key:"DlgOK"});this.notify("toolbar",{prop:"getLocaleText",onPropertyChange:!1,value:{obj:r}}),i="multi-select-image"===e?(this.notify("toolbar",{prop:"getLocaleText",onPropertyChange:!(t={key:"ImageErrorDialogHeader"}),value:{obj:t}}),this.notify("toolbar",{prop:"getLocaleText",onPropertyChange:!(o={key:"ImageErrorDialogContent"}),value:{obj:o}}),"<span>"+o.value+"</span>"):(this.notify("toolbar",{prop:"getLocaleText",onPropertyChange:!(t={key:"AlertDialogHeader"}),value:{obj:t}}),this.notify("toolbar",{prop:"getLocaleText",onPropertyChange:!(o={key:"AlertDialogContent"}),value:{obj:o}}),this.notify("toolbar",{prop:"getLocaleText",onPropertyChange:!(e={key:"SupportText"}),value:{obj:e}}),"<span>"+o.value+" "+e.value+"<b> JPG, PNG, and SVG</b></span>"),new u.Dialog({header:t.value,closeOnEscape:!0,content:i,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")},X.prototype.wireEvent=function(){O.EventHandler.add(document,"keydown",this.keyDownEventHandler,this),O.EventHandler.add(document,"keypress",this.keyUpEventHandler,this),O.EventHandler.add(this.upperCanvas,"mousedown",this.mouseDownEventHandler,this),O.EventHandler.add(this.upperCanvas,"mousemove",this.mouseMoveEventHandler,this),O.EventHandler.add(this.upperCanvas,"mouseup",this.mouseUpEventHandler,this),O.EventHandler.add(document,"mouseup",this.mouseUpEventHandler,this),O.EventHandler.add(this.lowerCanvas,"mousedown",this.canvasMouseDownHandler,this),O.EventHandler.add(this.lowerCanvas,"mousemove",this.canvasMouseMoveHandler,this),O.EventHandler.add(this.lowerCanvas,"mouseup",this.canvasMouseUpHandler,this),O.EventHandler.add(this.upperCanvas,"touchstart",this.touchStartHandler,this),O.EventHandler.add(this.lowerCanvas,"touchstart",this.touchStartHandler,this),O.EventHandler.add(this.lowerCanvas,"mousewheel DOMMouseScroll",this.handleScroll,this),O.EventHandler.add(this.upperCanvas,"mousewheel DOMMouseScroll",this.handleScroll,this),window.addEventListener("resize",this.windowResizeHandler.bind(this)),O.Browser.isIos||"safari"===O.Browser.info.name||screen.orientation.addEventListener("change",this.screenOrientation.bind(this)),this.notify("shape",{prop:"wireEvent",onPropertyChange:!1})},X.prototype.unwireEvent=function(){O.EventHandler.remove(document,"keydown",this.keyDownEventHandler),O.EventHandler.remove(document,"keypress",this.keyUpEventHandler),O.EventHandler.remove(this.upperCanvas,"mousedown",this.mouseDownEventHandler),O.EventHandler.remove(this.upperCanvas,"mousemove",this.mouseMoveEventHandler),O.EventHandler.remove(this.upperCanvas,"mouseup",this.mouseUpEventHandler),O.EventHandler.remove(document,"mouseup",this.mouseUpEventHandler),O.EventHandler.remove(this.lowerCanvas,"mousedown",this.canvasMouseDownHandler),O.EventHandler.remove(this.lowerCanvas,"mousemove",this.canvasMouseMoveHandler),O.EventHandler.remove(this.lowerCanvas,"mouseup",this.canvasMouseUpHandler),O.EventHandler.remove(this.upperCanvas,"touchstart",this.touchStartHandler),O.EventHandler.remove(this.lowerCanvas,"touchstart",this.touchStartHandler),O.EventHandler.remove(this.lowerCanvas,"mousewheel DOMMouseScroll",this.handleScroll),O.EventHandler.remove(this.upperCanvas,"mousewheel DOMMouseScroll",this.handleScroll),window.removeEventListener("resize",this.windowResizeHandler.bind(this)),O.Browser.isIos||"safari"===O.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})},X.prototype.createCanvas=function(){this.element.style.boxSizing="border-box";var e={toolbarHeight:0},e=(this.notify("toolbar",{prop:"getToolbarHeight",value:{obj:e}}),e.toolbarHeight),e=(this.toolbar&&0<this.toolbar.length&&-1===this.toolbar.indexOf("Open")&&(e=0),this.element.style.width=this.width,this.element.style.height=this.height,this.element.appendChild(this.createElement("div",{id:this.element.id+"_canvasWrapper",className:"e-canvas-wrapper",attrs:{style:"height:"+(this.element.offsetHeight-e-2)+"px; width:"+(this.element.offsetWidth-2)+"px; position: relative; overflow: hidden; margin: 0 auto;"}}))),t={key:"DragText"},o=(this.notify("toolbar",{prop:"getLocaleText",onPropertyChange:!1,value:{obj:t}}),{key:"DropText"}),i=(this.notify("toolbar",{prop:"getLocaleText",onPropertyChange:!1,value:{obj:o}}),{key:"BrowseText"}),r=(this.notify("toolbar",{prop:"getLocaleText",onPropertyChange:!1,value:{obj:i}}),{key:"SupportText"}),n=(this.notify("toolbar",{prop:"getLocaleText",onPropertyChange:!1,value:{obj:r}}),this.createElement("div",{id:this.element.id+"_dropArea",className:"e-ie-drop-area",attrs:{style:"position: relative;"}})),a=this.createElement("span",{className:"e-ie-drop-icon e-icons e-image",attrs:{style:"position: absolute;"}}),s=this.createElement("span",{className:"e-ie-drop-content",attrs:{style:"position: absolute; display: none;"}}),t=(s.textContent=t.value+" ",this.createElement("span",{className:"e-ie-min-drop-content",attrs:{style:"position: absolute;"}})),o=(t.textContent=o.value+" ",this.createElement("a",{id:this.element.id+"_dropBrowse",className:"e-ie-drop-browse"})),l=(o.textContent=i.value,this.createElement("a",{id:this.element.id+"_dropBrowse",className:"e-ie-drop-browse"})),i=(l.textContent=i.value,s.appendChild(o),t.appendChild(l),o.href="",l.href="",this.createElement("span",{className:"e-ie-drop-info",attrs:{position:"absolute"}})),p=(i.textContent=r.value+" SVG, PNG, and JPG",n.appendChild(this.createElement("input",{id:this.element.id+"_dropfileUpload",className:"e-fileUpload e-image-upload"})));p.setAttribute("type","file"),p.setAttribute("accept","image/*"),n.appendChild(a),n.appendChild(s),n.appendChild(t),n.appendChild(i),e.appendChild(n),this.lowerCanvas=e.appendChild(this.createElement("canvas",{id:this.element.id+"_lowerCanvas",attrs:{name:"canvasImage"}})),this.upperCanvas=e.appendChild(this.createElement("canvas",{id:this.element.id+"_upperCanvas",attrs:{name:"canvasImage"}})),this.inMemoryCanvas=this.createElement("canvas",{id:this.element.id+"_inMemoryCanvas",attrs:{name:"canvasImage"}}),this.baseImgCanvas=this.createElement("canvas",{id:this.element.id+"_baseImgCanvas",attrs:{name:"canvasImage"}}),this.textArea=e.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";r=this.element.appendChild(this.createElement("input",{id:this.element.id+"_fileUpload",className:"e-fileUpload"}));r.setAttribute("type","file"),r.setAttribute("accept","image/*"),r.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"),o.addEventListener("click",function(e){return e.preventDefault(),p.click(),!1}),l.addEventListener("click",function(e){return e.preventDefault(),p.click(),!1})},X.prototype.touchStartHandler=function(e){this.notify("selection",{prop:"touchStartHandler",onPropertyChange:!1,value:{e:e}})},X.prototype.mouseDownEventHandler=function(e){"e-ie-drop-browse"!==e.target.className&&this.notify("selection",{prop:"mouseDownEventHandler",onPropertyChange:!1,value:{e:e}})},X.prototype.mouseMoveEventHandler=function(e){this.notify("selection",{prop:"mouseMoveEventHandler",onPropertyChange:!1,value:{e:e}})},X.prototype.mouseUpEventHandler=function(e){"e-ie-drop-browse"!==e.target.className&&this.notify("selection",{prop:"mouseUpEventHandler",onPropertyChange:!1,value:{e:e}})},X.prototype.keyDownEventHandler=function(e){this.notify("selection",{prop:"keyDownEventHandler",onPropertyChange:!1,value:{e:e}})},X.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}})},X.prototype.canvasMouseDownHandler=function(e){"e-ie-drop-browse"!==e.target.className&&this.notify("selection",{prop:"canvasMouseDownHandler",onPropertyChange:!1,value:{e:e}})},X.prototype.canvasMouseMoveHandler=function(e){this.notify("selection",{prop:"canvasMouseMoveHandler",onPropertyChange:!1,value:{e:e}})},X.prototype.canvasMouseUpHandler=function(e){"e-ie-drop-browse"!==e.target.className&&this.notify("selection",{prop:"canvasMouseUpHandler",onPropertyChange:!1,value:{e:e}})},X.prototype.handleScroll=function(e){this.notify("selection",{prop:"handleScroll",onPropertyChange:!1,value:{e:e}})},X.prototype.adjustToScreen=function(){this.update()},X.prototype.screenOrientation=function(){O.Browser.isDevice&&setTimeout(this.adjustToScreen.bind(this),100)},X.prototype.windowResizeHandler=function(){!O.Browser.isDevice&&this.element.classList.contains("e-image-editor")&&this.adjustToScreen()},X.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})}},X.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},X.prototype.clearSelection=function(e){this.notify("selection",{prop:"clearSelection",onPropertyChange:!1,value:{resetCrop:e}})},X.prototype.crop=function(){var e={isCrop:!1};return this.notify("crop",{prop:"crop",onPropertyChange:!1,value:{obj:e}}),e.isCrop},X.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"}})},X.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)},X.prototype.open=function(e){var t;O.isNullOrUndefined(e)||((t=document.getElementById(this.element.id+"_dropArea"))&&(t.style.display="none"),this.notify("draw",{prop:"open",value:{data:e}}))},X.prototype.reset=function(){var e,t={isErrorImage:!1};this.notify("draw",{prop:"getErrorImage",value:{obj:t}}),this.disabled||t.isErrorImage||(this.clearContext(this.inMemoryContext),this.clearContext(this.lowerContext),this.clearContext(this.upperContext),this.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),this.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"main",isApplyBtn:!1,isCropping:!1,isZooming:null,cType:null}}),O.Browser.isDevice&&document.getElementById(this.element.id+"_bottomToolbar")&&(O.getComponent(document.getElementById(this.element.id+"_bottomToolbar"),"toolbar").destroy(),this.notify("toolbar",{prop:"create-bottom-toolbar",onPropertyChange:!1})),t=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=!1,e={initialZoomValue:!(this.shapeColl=[])},this.notify("draw",{prop:"getInitialZoomValue",onPropertyChange:!1,value:{obj:e}}),e.initialZoomValue&&this.setProperties({zoomSettings:{zoomFactor:e.initialZoomValue}},!0),(e=document.getElementById(this.element.id+"_quickAccessToolbarArea"))&&(e.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=t,this.straightenBaseImageCanvas(),this.isImageLoaded=!1,this.notify("draw",{prop:"update-canvas",onPropertyChange:!1}),this.isImageLoaded=t,this.prevStraightenedDegree=0,(e=this.element.querySelector(".e-contextual-toolbar-wrapper"))&&e.classList.add("e-hide"),this.notify("toolbar",{prop:"refresh-dropdown-btn",value:{isDisabled:!1}}),this.notify("toolbar",{prop:"enable-disable-btns"}),t=this.isStraightening,O.Browser.isDevice&&t&&this.notify("crop",{prop:"resizeWrapper"}))},X.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},X.prototype.export=function(e,t){this.applyShapes(),this.notify("export",{prop:"export",onPropertyChange:!1,value:{type:e,fileName:t}})},X.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:""}},X.prototype.freeHandDraw=function(e){this.notify("freehand-draw",{prop:"freeHandDraw",onPropertyChange:!1,value:{value:e}})},X.prototype.freehandDraw=function(e){!this.disabled&&this.isImageLoaded&&(this.applyShapes(),this.freeHandDraw(e))},X.prototype.pan=function(e,t,o){this.applyShapes(),this.notify("transform",{prop:"pan",onPropertyChange:!1,value:{value:e,x:t,y:o}})},X.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"})},X.prototype.drawEllipse=function(e,t,o,i,r,n,a,s,l){var p=!1,h=this.allowShape(e,t);return!this.disabled&&this.isImageLoaded&&(h||O.isNullOrUndefined(e)&&O.isNullOrUndefined(t))&&(this.notify("shape",{prop:"drawEllipse",onPropertyChange:!(p=!0),value:{x:e,y:t,radiusX:o,radiusY:i,strokeWidth:r,strokeColor:n,fillColor:a,degree:s,isSelected:l}}),this.notify("draw",{prop:"redrawDownScale"})),p},X.prototype.drawLine=function(e,t,o,i,r,n,a){var s=!1,l=this.allowShape(e,t);return!this.disabled&&this.isImageLoaded&&(l||O.isNullOrUndefined(e)&&O.isNullOrUndefined(t))&&(this.notify("shape",{prop:"drawLine",onPropertyChange:!(s=!0),value:{startX:e,startY:t,endX:o,endY:i,strokeWidth:r,strokeColor:n,isSelected:a}}),this.notify("draw",{prop:"redrawDownScale"})),s},X.prototype.drawArrow=function(e,t,o,i,r,n,a,s,l){var p=!1,h=this.allowShape(e,t);return!this.disabled&&this.isImageLoaded&&(h||O.isNullOrUndefined(e)&&O.isNullOrUndefined(t))&&(this.notify("shape",{prop:"drawArrow",onPropertyChange:!(p=!0),value:{startX:e,startY:t,endX:o,endY:i,strokeWidth:r,strokeColor:n,arrowStart:a,arrowEnd:s,isSelected:l}}),this.notify("draw",{prop:"redrawDownScale"})),p},X.prototype.drawPath=function(e,t,o,i){var r={inRange:!(this.isPublicMethod=!0)},n=!1;if(e&&0<e.length)for(var a=0;a<e.length&&!r.inRange;a++)this.notify("shape",{prop:"isPointsInRange",onPropertyChange:!1,value:{x:e[a].x,y:e[a].y,obj:r}});return!this.disabled&&this.isImageLoaded&&(r.inRange||O.isNullOrUndefined(e))&&(n=!0,this.applyShapes(),this.notify("shape",{prop:"drawPath",onPropertyChange:!1,value:{pointColl:e,strokeWidth:t,strokeColor:o,isSelected:i}}),this.notify("draw",{prop:"redrawDownScale"})),n},X.prototype.drawRectangle=function(e,t,o,i,r,n,a,s,l){var p=!1,h=this.allowShape(e,t);return!this.disabled&&this.isImageLoaded&&(h||O.isNullOrUndefined(e)&&O.isNullOrUndefined(t))&&(this.notify("shape",{prop:"drawRectangle",onPropertyChange:!(p=!0),value:{x:e,y:t,width:o,height:i,strokeWidth:r,strokeColor:n,fillColor:a,degree:s,isSelected:l}}),this.notify("draw",{prop:"redrawDownScale"})),p},X.prototype.drawText=function(e,t,o,i,r,n,a,s,l,p){var h=!1,d=this.allowShape(e,t);return!this.disabled&&this.isImageLoaded&&(d||O.isNullOrUndefined(e)&&O.isNullOrUndefined(t))&&(this.notify("shape",{prop:"drawText",onPropertyChange:!(h=!0),value:{x:e,y:t,text:o,fontFamily:i,fontSize:r,bold:n,italic:a,color:s,isSelected:l,degree:p}}),this.notify("draw",{prop:"redrawDownScale"})),h},X.prototype.drawImage=function(e,t,o,i,r,n,a,s,l){var p=!1,h=this.allowShape(t,o);return p=!this.disabled&&this.isImageLoaded&&(h||O.isNullOrUndefined(t)&&O.isNullOrUndefined(o))&&(h=this.objColl.length,this.notify("shape",{prop:"drawImage",onPropertyChange:!1,value:{x:t,y:o,width:i,height:r,src:e,degree:a,isAspectRatio:n,opacity:s,isSelected:l}}),this.notify("draw",{prop:"redrawDownScale"}),this.objColl.length>h)?!0:p},X.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},X.prototype.deleteShape=function(e){this.applyShapes(),this.notify("shape",{prop:"deleteShape",onPropertyChange:!1,value:{id:e}}),this.notify("draw",{prop:"redrawDownScale"})},X.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||{}},X.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},X.prototype.update=function(){this.notify("transform",{prop:"update"})},X.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"}))},X.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"}}))},X.prototype.undo=function(){this.applyShapes(),this.notify("undo-redo",{prop:"undo",onPropertyChange:!1}),this.notify("draw",{prop:"redrawDownScale"})},X.prototype.redo=function(){this.applyShapes(),this.notify("undo-redo",{prop:"redo",onPropertyChange:!1}),this.notify("draw",{prop:"redrawDownScale"})},X.prototype.getImageDimension=function(){return{x:this.img.destLeft,y:this.img.destTop,width:this.img.destWidth,height:this.img.destHeight}},X.prototype.resize=function(e,t,o){var i,r,n,a,s,l,p=!1;return e.toString().length<=4&&t.toString().length<=4&&(this.applyShapes(),i=this.img.destLeft,r=this.img.destTop,n=this.img.destWidth,a=this.img.destHeight,o&&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}}),s=this.element.querySelector("#"+this.element.id+"_resizeWidth"),l=this.element.querySelector("#"+this.element.id+"_resizeHeight"),s&&l&&(O.getComponent(s,"numerictextbox").value=Math.floor(e),s.value=Math.floor(e).toString()+" px",O.getComponent(l,"numerictextbox").value=Math.floor(t),l.value=Math.floor(t).toString()+" px"),this.notify("transform",{prop:"resize",value:{width:e,height:t,isAspectRatio:o}}),i!==this.img.destLeft||r!==this.img.destTop||n!==this.img.destWidth||a!==this.img.destHeight?(p=!0,this.okBtn()):this.notify("draw",{prop:"performCancel",value:{isContextualToolbar:null}}),this.notify("draw",{prop:"redrawDownScale"})),p},X.prototype.drawFrame=function(e,t,o,i,r,n,a,s,l){this.applyShapes();var p=!1,h={frameChangeEventArgs:null},d=(t=t||"#fff",o=o||"",i=i||20,r=r||0,n=n||0,a=a||0,s=s||v.FrameLineStyle.Solid,l=l||0,{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 O.extend(this.tempFrameObj,this.frameObj),this.tempFrameZoomLevel=this.transform.zoomFactor,this.frameDestPoints=O.extend({},this.img,{},!0),this.notify("toolbar",{prop:"frameToolbarClick"}),this.frameObj.type=e.toLowerCase(),this.frameObj.color=t,this.frameObj.gradientColor=o,this.frameObj.size=i,this.frameObj.inset=r,this.frameObj.offset=n,this.frameObj.radius=a,this.frameObj.border=s.toLowerCase(),this.frameObj.amount=l,this.notify("draw",{prop:"triggerFrameChange",value:{prevFrameSettings:d,obj:h}}),h.frameChangeEventArgs&&!h.frameChangeEventArgs.cancel?(this.notify("draw",{prop:"render-image",value:{isMouseWheel:null}}),JSON.stringify(this.frameObj)!==JSON.stringify(this.tempFrameObj)?(p=!0,this.okBtn()):this.tempFrameZoomLevel=null):(this.notify("draw",{prop:"performCancel",value:{isContextualToolbar:null}}),O.extend(this.frameObj,this.tempFrameObj),this.tempFrameZoomLevel=null),this.notify("draw",{prop:"redrawDownScale"}),p},X.prototype.straightenImage=function(e){var t=!1;return-45<=e&&e<=45&&(this.applyShapes(),t=!0,this.notify("transform",{prop:"straightenImage",value:{degree:e}}),this.notify("draw",{prop:"redrawDownScale"})),t},X.prototype.updateShape=function(e,t){var o,i={isSelected:!1},r=!1,n={bool:!1};return O.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}})):("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:n}}),i.isSelected&&(o=this.activeObj.textSettings.fontSize,this.notify("shape",{prop:"updateShapeChangeEventArgs",onPropertyChange:!1,value:{shapeSettings:e}}),"text"===this.activeObj.shape&&o&&0!=(o=this.activeObj.textSettings.fontSize-o)&&(this.activeObj.activePoint.height+=o,this.activeObj.activePoint.startY-=o/2,this.activeObj.activePoint.endY+=o/2,this.notify("draw",{prop:"updateActiveObject",onPropertyChange:!1,value:{actPoint:this.activeObj.activePoint,obj:this.activeObj,isMouseMove:null,x:null,y:null}})),o=O.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),o.shape&&this.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate",obj:o}}),"text"===this.activeObj.shape&&this.notify("toolbar",{prop:"editText",onPropertyChange:!1}),n.bool&&this.notify("undo-redo",{prop:"setPreventUR",value:{bool:!0}}),this.okBtn(t,!0),n.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(),t)&&this.selectShape(e.id)),i.isSelected},X.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},X.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},X.prototype.enableTextEditing=function(){var e=O.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})},X.prototype.canUndo=function(){var e=!1;return e=0<this.getUndoRedoColl().index?!0:e},X.prototype.canRedo=function(){var e=!1,t=this.getUndoRedoColl(),o=t.undoRedoColl,t=t.index;return o&&0<o.length&&t<o.length-1&&(e=!0),t===o.length?e=!1:(0===t&&0<o.length||0<t)&&(e=!0),e},X.prototype.apply=function(){this.closeOverlayTbar(),this.okBtn(null,!0)},X.prototype.discard=function(){this.notify("draw",{prop:"performCancel",value:{isContextualToolbar:this.closeOverlayTbar(),isFinalCancel:!0}})},X.prototype.enableShapeDrawing=function(e,t){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=[],this.notify("shape",{prop:"getNewOrder",onPropertyChange:!(e={order:null}),value:{obj:e}}),this.activeObj.order=e.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})):t||this.okBtn(null,!0)},X.prototype.bringToFront=function(e){this.selectShape(e)&&(this.updateShapeOrder(e,"bringToFront"),this.apply())},X.prototype.bringForward=function(e){this.selectShape(e)&&(this.updateShapeOrder(e,"bringForward"),this.apply())},X.prototype.sendToBack=function(e){this.selectShape(e)&&(this.updateShapeOrder(e,"sendToBack"),this.apply())},X.prototype.sendBackward=function(e){this.selectShape(e)&&(this.updateShapeOrder(e,"sendBackward"),this.apply())},X.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"),e=(O.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}),document.getElementById(this.element.id+"_dropArea"));e&&(e.style.display="block")},X.prototype.applyShapes=function(){var e;!this.isUndoRedoStack&&(this.notify("selection",{prop:"getFreehandDrawEditing",onPropertyChange:!(e={bool:!1}),value:{obj:e}}),e.bool||this.togglePen||this.activeObj.shape&&-1!==["rectangle","ellipse","line","arrow","path","text","image"].indexOf(this.activeObj.shape)||this.drawingShape)&&this.okBtn(null,!0)},X.prototype.closeOverlayTbar=function(){var e=!1,t={bool:null};return this.notify("toolbar",{prop:"getFrameToolbar",onPropertyChange:!1,value:{obj:t}}),!t.bool&&this.element.querySelector(".e-contextual-toolbar-wrapper")&&(this.element.querySelector(".e-contextual-toolbar-wrapper").classList.contains("e-hide")||(e=!0),t=this.isStraightening,O.Browser.isDevice&&(!O.Browser.isDevice||t)||this.element.querySelector(".e-contextual-toolbar-wrapper").classList.add("e-hide")),e},X.prototype.toolbarTemplateFn=function(){var e,t=this.element.id+"_toolbar",o=this.element.querySelector("#"+this.element.id+"_toolbarArea");this.toolbarTemplate&&(this.toolbarFn=this.templateParser(this.toolbarTemplate),e=!this.isReact&&this.isAngular?3===(e=this.toolbarFn({type:"toolbar"},this,"Template",t))[0].nodeType?e[1]:e[0]: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())},X.prototype.quickAccessToolbarTemplateFn=function(){var e,t=this.element.id+"_quickAccessToolbar",o=this.element.querySelector("#"+this.element.id+"_quickAccessToolbarArea");this.quickAccessToolbarTemplate&&(this.qatFn=this.templateParser(this.quickAccessToolbarTemplate),e=!this.isReact&&this.isAngular?3===(e=this.qatFn({type:"toolbar"},this,"Template",t))[0].nodeType?e[1]:e[0]:this.qatFn({type:"toolbar"},this,"Template",t)[0],o.appendChild(e),this.renderReactTemplates())},X.prototype.templateParser=function(t){if(t)try{return"function"!=typeof t&&document.querySelectorAll(t).length?O.compile(document.querySelector(t).innerHTML.trim()):O.compile(t)}catch(e){return O.compile(t)}},X.prototype.getTextFromId=function(e){return{1:"none",2:"bar",3:"arrow",4:"arrowSolid",5:"circle",6:"circleSolid",7:"square",8:"squareSolid"}[""+e]},X.prototype.getFinetuneOption=function(e){return{brightness:v.ImageFinetuneOption.Brightness,contrast:v.ImageFinetuneOption.Contrast,hue:v.ImageFinetuneOption.Hue,saturation:v.ImageFinetuneOption.Saturation,opacity:v.ImageFinetuneOption.Opacity,blur:v.ImageFinetuneOption.Blur,exposure:v.ImageFinetuneOption.Exposure}[""+e]},X.prototype.setPenStroke=function(e){this.notify("freehand-draw",{prop:"setPenStrokeWidth",onPropertyChange:!1,value:{value:parseInt(e,10)}})},X.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}})},X.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},X.prototype.updateImageTransformColl=function(e){var t;"rotateleft"===e?t=-90:"rotateright"===e?t=90:"horizontalflip"===e?t="horizontal":"verticalflip"===e&&(t="vertical");for(var o=0;o<this.objColl.length;o++){var i=this.objColl[o].shape;"image"!==i&&"text"!==i||(O.isNullOrUndefined(this.objColl[o].rotateFlipColl)&&(this.objColl[o].rotateFlipColl=[]),this.objColl[o].rotateFlipColl.push(t),i={collection:this.objColl[o].rotateFlipColl},this.notify("shape",{prop:"alignRotateFlipColl",onPropertyChange:!1,value:{collection:this.objColl[o].rotateFlipColl,isRotateFlipCollection:!1,obj:i}}),this.objColl[o].rotateFlipColl=i.collection)}},X.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&&0<this.transform.cropZoomFactor?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=O.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}})},X.prototype.updateCropTransformItems=function(){this.prevCurrSelectionPoint=O.extend({},this.currSelectionPoint,{},!0),this.notify("draw",{prop:"updateCropSelection",onPropertyChange:!1})},X.prototype.toPascalCase=function(e,t){var o=[];O.isNullOrUndefined(e)||(o=e.toLowerCase().split("-"));for(var i=0;i<o.length;i++)o[i]=o[i].charAt(0).toUpperCase()+o[i].slice(1);return t&&(t.maxText=o.join("")),o.join("")},X.prototype.getFontSizes=function(){var e=[];this.fontSizeColl=[];for(var t=0===this.transform.degree||this.transform.degree%180==0?this.img.destWidth/25:this.img.destHeight/25,o=1;o<=10;o++)this.fontSizeColl.push({text:(o*Math.round(t/2)).toString()}),e.push({text:o.toString()});return e},X.prototype.okBtn=function(e,t){t&&(this.noPushUndo=!1,this.notify("selection",{prop:"setTempActObj",onPropertyChange:!1,value:{obj:{activePoint:{startX:0,startY:0,endX:0,endY:0,width:0,height:0},flipObjColl:[],triangle:[],triangleRatio:[],order:null}}}));var o,i,r=this.element.querySelector(".e-contextual-toolbar-wrapper"),r=(r&&r.classList.remove("e-frame-wrapper"),!1),n=(this.isResizeOkBtn=!0,this.element.querySelector("#"+this.element.id+"_aspectratio")),a=this.element.querySelector("#"+this.element.id+"_nonaspectratio"),s=this.element.querySelector(".e-ie-toolbar-aspect-ratio-btn"),l=this.element.querySelector(".e-ie-toolbar-nonaspect-ratio-btn"),n=((void 0===(o=void 0!==this.activeObj.shape?this.activeObj.shape.split("-"):o)&&this.currObjType.isCustomCrop||void 0!==o&&"crop"===o[0])&&(r=!0),this.allowDownScale=!0,(this.activeObj.shape&&"image"!==this.activeObj.shape||this.togglePen)&&!r&&(this.notify("selection",{prop:"updatePrevShapeSettings",onPropertyChange:!(o={shapeSettingsObj:{}}),value:{obj:o}}),o=o.shapeSettingsObj,this.togglePen&&(o.type=v.ShapeType.FreehandDraw),o={action:"apply",currentShapeSettings:O.extend({},o,{},!0)},this.trigger("shapeChange",o)),(n||a)&&(this.notify("selection",{prop:"getNumTextValue",onPropertyChange:!(o={width:null,height:null}),value:{obj:o}}),i={prevCropObj:this.prevCropObj},p={prevObj:this.prevObj},(o={x:o.width,y:o.height}).x&&o.y&&i.prevCropObj&&p.prevObj?(a||l&&!l.classList.contains("e-hidden")?this.notify("transform",{prop:"resize",value:{width:o.x,height:o.y,isAspectRatio:!1}}):(n||s&&!s.classList.contains("e-hidden"))&&this.notify("transform",{prop:"resize",value:{width:o.x,height:null,isAspectRatio:!0}}),this.isResize=!1,this.aspectWidth=o.x,this.aspectHeight=o.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:p.prevObj.defaultZoom,zoomPoint:null,isResize:!0}}),p.prevObj.zoomFactor&&this.setProperties({zoomSettings:{zoomFactor:p.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:p.prevObj,previousObjColl:p.prevObj.objColl,previousPointColl:p.prevObj.pointColl,previousSelPointColl:p.prevObj.selPointColl,previousCropObj:i.prevCropObj,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),this.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"ok"}}),!(l=this.cancelCropSelection)||!O.isNullOrUndefined(a)&&a||(l.previousObj.aspectWidth=l.currentObj.aspectWidth=this.aspectWidth,l.previousObj.aspectHeight=l.currentObj.aspectHeight=this.aspectHeight,l.previousCropObj=O.extend({},this.cropObj,{},!0),l.currentCropObj=O.extend({},this.cropObj,{},!0),this.notify("draw",{prop:"updateCropSelObj"})),this.cancelCropSelection=null):0===o.x||0===o.y?this.notify("draw",{prop:"performCancel",value:{isContextualToolbar:null}}):this.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"main",isApplyBtn:!1,isCropping:!1,isZooming:null,cType:null}}),this.isAspectRatio=!1),this.element.querySelector(".e-contextual-toolbar-wrapper .e-toolbar-item.e-selected")),s={bool:!1},p=(this.notify("selection",{prop:"getFreehandDrawEditing",onPropertyChange:!1,value:{obj:s}}),this.notify("toolbar",{prop:"getFrameToolbar",onPropertyChange:!1,value:{obj:{bool:null}}}),document.querySelector("#"+this.element.id+"_sliderWrapper"));n&&(this.currentFilter=n.children[0].children[0].id.replace("Canvas","")),r?(0===this.transform.straighten||0===this.panPoint.totalPannedPoint.x&&0===this.panPoint.totalPannedPoint.y&&0===this.panPoint.totalPannedClientPoint.x&&0===this.panPoint.totalPannedClientPoint.y||(i=this.prevStraightenedDegree,this.prevStraightenedDegree=this.transform.straighten,this.setStraighten(this.transform.straighten-3),this.setStraighten(this.transform.straighten+3),this.prevStraightenedDegree=i),this.isCroppedEvent=this.crop()):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}})):"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}),O.isNullOrUndefined(e)&&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}})):p||this.currObjType.isFiltered?(this.initialAdjustmentValue=this.canvasFilter=this.lowerContext.filter,this.currObjType.isFiltered=!1,this.notify("draw",{prop:"getTempAdjustmentValue",value:{obj:a={value:null}}}),a.value===this.lowerContext.filter||p&&p.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&&0<this.activeObj.pointColl.length)&&this.notify("shape",{prop:"applyActObj",onPropertyChange:!1,value:{isMouseDown:null}})):s.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})):0!==this.activeObj.activePoint.width||0!==this.activeObj.activePoint.height||"path"===this.activeObj.shape&&0<this.activeObj.pointColl.length?("image"===this.activeObj.shape&&this.notify("draw",{prop:"setImageApply",onPropertyChange:!1,value:{bool:!0}}),this.notify("shape",{prop:"applyActObj",onPropertyChange:!1,value:{isMouseDown:null}})):(JSON.stringify(this.frameObj)!==JSON.stringify(this.tempFrameObj)&&(this.notify("filter",{prop:"getCurrentObj",onPropertyChange:!(l={currObj:{}}),value:{object:l}}),this.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:O.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=O.extend({},this.frameObj,{},!0)),this.notify("draw",{prop:"resetFrameZoom",onPropertyChange:!1,value:{isOk:!0}})),s.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,t&&(this.drawingShape=null,this.notify("draw",{prop:"resetTempObjColl"}),this.notify("draw",{prop:"resetTempPointColl"}))},X.prototype.getObjFromId=function(e){var t;if(this.activeObj.currIndex&&this.activeObj.currIndex===e)t=O.extend({},this.activeObj,{},!0);else for(var o=0;o<this.shapeColl.length;o++)if((this.shapeColl[o].id||this.shapeColl[o].currIndex)===e){t=O.extend({},this.shapeColl[o],{},!0);break}return t},X.prototype.setTempFilterProperties=function(){this.upperCanvas.style.display="block",this.cropSelectedState();var e={adjustmentLevel:null},e=(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:O.extend({},e.adjustmentLevel,{},!0)}}),this.notify("draw",{prop:"setTempFilter",value:{tempFilter:this.currentFilter}}),{undoRedoStep:null});this.notify("undo-redo",{prop:"getUndoRedoStep",value:{obj:e}}),this.notify("draw",{prop:"setTempUndoRedoStep",value:{tempUndoRedoStep:e.undoRedoStep}})},X.prototype.cropSelectedState=function(){this.activeObj.shape&&"crop"===this.activeObj.shape.split("-")[0]&&this.okBtn()},X.prototype.getCurrentCanvasData=function(){var e=O.extend({},this.frameObj,{},!0),t=(this.frameObj={type:"none",color:"#fff",size:20,inset:20,offset:20,radius:0,amount:1,border:"solid",gradientColor:""},this.lowerContext.filter),o=(this.lowerContext.filter=this.canvasFilter="none",O.extend([],this.objColl,null,!0)),i=O.extend([],this.pointColl,null,!0),r=(this.objColl=[],this.pointColl=[],this.freehandCounter=0,this.notify("draw",{prop:"render-image",value:{isMouseWheel:!1}}),this.element.querySelector(".e-contextual-toolbar-wrapper")),n=(r&&r.classList.add("e-hide"),this.getImageData());return r&&r.classList.remove("e-hide"),O.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=o,this.pointColl=i,this.freehandCounter=i.length,this.notify("shape",{prop:"drawAnnotations",onPropertyChange:!1,value:{ctx:this.lowerContext,shape:"iterate",pen:"iterate",isPreventApply:null}}),this.lowerContext.filter=this.canvasFilter=t,this.frameObj=e,n},X.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}})},X.prototype.getSquarePointForPath=function(e){var t={startX:0,startY:0,endX:0,endY:0,width:0,height:0};if(0<e.pointColl.length){for(var t={startX:e.pointColl[0].x,startY:e.pointColl[0].y,endX:e.pointColl[0].x,endY:e.pointColl[0].y},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},X.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)]||e.split("Crop")[1]},X.prototype.clearContext=function(e){e.clearRect(0,0,e.canvas.width,e.canvas.height),e.clearRect(0,0,e.canvas.height,e.canvas.width)},X.prototype.updateArrow=function(e,t){this.notify("shape",{prop:"pushActItemIntoObj"});var o=O.extend({},this.cropObj,{},!0),i={currObj:{}},r={shapeSettingsObj:{}},r=(this.notify("selection",{prop:"updatePrevShapeSettings",onPropertyChange:!1,value:{obj:r}}),r.shapeSettingsObj),i=(this.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:i}}),i.currObj),t=(i.objColl=O.extend([],this.objColl,[],!0),i.pointColl=O.extend([],this.pointColl,[],!0),i.afterCropActions=O.extend([],this.afterCropActions,[],!0),this.objColl.pop(),"startArrow"===e?this.activeObj.start=this.getTextFromId(t):"endArrow"===e&&(this.activeObj.end=this.getTextFromId(t)),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:i,previousObjColl:i.objColl,previousPointColl:i.pointColl,previousCropObj:o,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),this.notify("selection",{prop:"redrawShape",value:{obj:this.objColl[this.objColl.length-1]}}),O.Browser.isDevice?document.getElementById(this.element.id+"_bottomToolbar")&&O.getComponent(this.element.id+"_bottomToolbar","toolbar").refreshOverflow():document.getElementById(this.element.id+"_toolbar")&&O.getComponent(this.element.id+"_toolbar","toolbar").refreshOverflow(),{action:e,currentShapeSettings:O.extend({},r,{},!0)});this.trigger("shapeChange",t)},X.prototype.updateFontFamily=function(e){this.notify("selection",{prop:"setInitialTextEdit",value:{bool:!1}}),this.notify("shape",{prop:"pushActItemIntoObj"});var t,o=O.extend([],this.objColl,[],!0),i=O.extend({},this.cropObj,{},!0),r={shapeSettingsObj:{}},r=(this.notify("selection",{prop:"updatePrevShapeSettings",onPropertyChange:!1,value:{obj:r}}),r.shapeSettingsObj),n={currObj:{}},n=(this.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:n}}),n.currObj),a=(n.objColl=O.extend([],this.objColl,[],!0),n.pointColl=O.extend([],this.pointColl,[],!0),n.afterCropActions=O.extend([],this.afterCropActions,[],!0),{selPointColl:null}),a=(this.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:a}}),n.selPointColl=O.extend([],a.selPointColl,[],!0),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}}),a=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:n,previousObjColl:n.objColl,previousPointColl:n.pointColl,previousSelPointColl:n.selPointColl,previousCropObj:i,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),this.objColl.pop(),this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),t=this.activeObj.activePoint.width+.25*this.activeObj.textSettings.fontSize,this.textArea.style.width=t+"px",this.textArea.style.fontFamily=this.toPascalCase(e),this.activeObj.textSettings.fontFamily=a,this.notify("shape",{prop:"updateFontStyles",onPropertyChange:!1,value:{isTextBox:null}})):(this.notify("shape",{prop:"updateFontRatio",onPropertyChange:!1,value:{obj:this.activeObj,isTextArea:null}}),t=this.activeObj.textSettings.fontFamily=this.toPascalCase(e),this.notify("shape",{prop:"setTextSettings",onPropertyChange:!1,value:{textSettings:null,fontFamily:t,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:n,previousObjColl:o,previousPointColl:O.extend([],this.pointColl,[],!0),previousSelPointColl:n.selPointColl,previousCropObj:i,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),this.notify("selection",{prop:"redrawShape",value:{obj:this.objColl[this.objColl.length-1]}})),{action:"font-family",currentShapeSettings:O.extend({},r,{},!0)});a.currentShapeSettings.fontFamily=this.textArea.style.fontFamily,this.trigger("shapeChange",a)},X.prototype.updateFontSize=function(e){this.notify("selection",{prop:"setInitialTextEdit",value:{bool:!1}}),this.notify("shape",{prop:"pushActItemIntoObj"});var t,o,i=O.extend({},this.cropObj,{},!0),r={shapeSettingsObj:{}},r=(this.notify("selection",{prop:"updatePrevShapeSettings",onPropertyChange:!1,value:{obj:r}}),r.shapeSettingsObj),n={currObj:{}},n=(this.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:n}}),n.currObj),a=(n.objColl=O.extend([],this.objColl,[],!0),n.pointColl=O.extend([],this.pointColl,[],!0),n.afterCropActions=O.extend([],this.afterCropActions,[],!0),{selPointColl:null}),s=(this.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:a}}),n.selPointColl=O.extend([],a.selPointColl,[],!0),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}}),a=this.activeObj.textSettings.fontSize,this.activeObj.textSettings.fontSize=parseInt(this.fontSizeColl[parseInt(e,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:n,previousObjColl:n.objColl,previousPointColl:n.pointColl,previousSelPointColl:n.selPointColl,previousCropObj:i,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),this.objColl.pop(),t="","bold"===this.textArea.style.fontWeight&&(t="bold "),"italic"===this.textArea.style.fontStyle&&(t="italic "),"bold"===this.textArea.style.fontWeight&&"italic"===this.textArea.style.fontStyle&&(t="italic bold "),this.upperContext.font=t+this.activeObj.textSettings.fontSize+"px "+this.textArea.style.fontFamily,t=this.textArea.value.split("\n"),this.notify("shape",{prop:"getMaxText",onPropertyChange:!(s={maxText:""}),value:{isTextBox:!0,text:null,obj:s}}),o=s.maxText,o=this.upperContext.measureText(o).width+.5*this.activeObj.textSettings.fontSize,this.textArea.style.width=o+"px",this.textArea.style.height=t.length*(this.activeObj.textSettings.fontSize+.25*this.activeObj.textSettings.fontSize)+"px",this.activeObj.textSettings.fontSize=a,this.upperContext.font=this.activeObj.textSettings.fontSize+"px "+this.activeObj.textSettings.fontFamily,this.textArea.style.fontSize=parseInt(this.fontSizeColl[parseInt(e,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")):(this.notify("shape",{prop:"updateFontRatio",onPropertyChange:!1,value:{obj:this.activeObj,isTextArea:null}}),a=this.activeObj.textSettings.fontSize=parseInt(this.fontSizeColl[parseInt(e,10)-1].text,10),this.notify("shape",{prop:"setTextSettings",onPropertyChange:!1,value:{textSettings:null,fontFamily:null,fontSize:a}}),this.upperContext.font=this.activeObj.textSettings.fontSize+"px "+this.activeObj.textSettings.fontFamily,t=this.activeObj.keyHistory.split("\n"),this.notify("shape",{prop:"getMaxText",onPropertyChange:!(s={maxText:""}),value:{isTextBox:null,text:null,obj:s}}),e=s.maxText,o=this.upperContext.measureText(e).width+.5*this.activeObj.textSettings.fontSize,a=t.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:o,height:a}}),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:n,previousObjColl:n.objColl,previousPointColl:n.pointColl,previousSelPointColl:n.selPointColl,previousCropObj:i,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),this.notify("selection",{prop:"redrawShape",value:{obj:this.objColl[this.objColl.length-1]}})),{action:"font-size",currentShapeSettings:O.extend({},r,{},!0)});s.currentShapeSettings.fontSize=this.activeObj.textSettings.fontSize,this.trigger("shapeChange",s)},X.prototype.updateFontColor=function(e){this.notify("selection",{prop:"setInitialTextEdit",value:{bool:!1}}),this.notify("shape",{prop:"pushActItemIntoObj"});var t=O.extend({},this.cropObj,{},!0),o={shapeSettingsObj:{}},o=(this.notify("selection",{prop:"updatePrevShapeSettings",onPropertyChange:!1,value:{obj:o}}),o.shapeSettingsObj),i={currObj:{}},i=(this.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:i}}),i.currObj),r=(i.objColl=O.extend([],this.objColl,[],!0),i.pointColl=O.extend([],this.pointColl,[],!0),i.afterCropActions=O.extend([],this.afterCropActions,[],!0),{selPointColl:null}),r=(this.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:r}}),i.selPointColl=O.extend([],r.selPointColl,[],!0),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:i,previousObjColl:i.objColl,previousPointColl:i.pointColl,previousSelPointColl:i.selPointColl,previousCropObj:t,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),this.notify("selection",{prop:"redrawShape",value:{obj:this.objColl[this.objColl.length-1]}}))):"block"===this.textArea.style.display||"inline-block"===this.textArea.style.display?(this.textArea.style.color=e,r=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:i,previousObjColl:i.objColl,previousPointColl:i.pointColl,previousSelPointColl:i.selPointColl,previousCropObj:t,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),this.objColl.pop(),this.activeObj.strokeSettings.strokeColor=r):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:i,previousObjColl:i.objColl,previousPointColl:i.pointColl,previousSelPointColl:i.selPointColl,previousCropObj:t,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]}}),{action:"font-color",currentShapeSettings:O.extend({},o,{},!0)});r.currentShapeSettings.fillColor=e,this.trigger("shapeChange",r)},X.prototype.updatePenStrokeWidth=function(e){var t=O.extend([],this.pointColl,[],!0),o=(this.updateFreehandDrawColorChange(),O.extend({},this.cropObj,{},!0)),i={shapeSettingsObj:{}},i=(this.notify("selection",{prop:"updatePrevShapeSettings",onPropertyChange:!1,value:{obj:i}}),i.shapeSettingsObj),r={currObj:{}},r=(this.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:r}}),r.currObj),n=(r.objColl=O.extend([],this.objColl,[],!0),r.pointColl=O.extend([],this.pointColl,[],!0),r.afterCropActions=O.extend([],this.afterCropActions,[],!0),{selPointColl:null}),n=(this.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:n}}),r.selPointColl=O.extend([],n.selPointColl,[],!0),this.pointColl=t,this.notify("selection",{prop:"setFreehandDrawCustomized",value:{isFreehandDrawCustomized:!0}}),this.setPenStroke(e),{bool:!1}),n=(this.notify("selection",{prop:"getFreehandDrawEditing",onPropertyChange:!1,value:{obj:n}}),n.bool&&(this.notify("freehand-draw",{prop:"getPenStrokeWidth",onPropertyChange:!(t={penStrokeWidth:null}),value:{obj:t}}),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:t.penStrokeWidth}}),this.notify("freehand-draw",{prop:"getFreehandSelectedIndex",onPropertyChange:!(e={freehandSelectedIndex:null}),value:{obj:e}}),this.pointColl[e.freehandSelectedIndex].strokeWidth=t.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:t.penStrokeWidth}}),this.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"freehanddrawCustomized",previousObj:r,previousObjColl:r.objColl,previousPointColl:r.pointColl,previousSelPointColl:r.selPointColl,previousCropObj:o,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}})),i.type=v.ShapeType.FreehandDraw,{action:"stroke-width",currentShapeSettings:O.extend({},i,{},!0)});n.currentShapeSettings.strokeWidth=this.activeObj.strokeSettings.strokeWidth,this.trigger("shapeChange",n)},X.prototype.updatePenStrokeColor=function(e){var t=O.extend([],this.pointColl,[],!0),o=(this.updateFreehandDrawColorChange(),O.extend({},this.cropObj,{},!0)),i={shapeSettingsObj:{}},i=(this.notify("selection",{prop:"updatePrevShapeSettings",onPropertyChange:!1,value:{obj:i}}),i.shapeSettingsObj),r={currObj:{}},r=(this.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:r}}),r.currObj),n=(r.objColl=O.extend([],this.objColl,[],!0),r.pointColl=O.extend([],this.pointColl,[],!0),r.afterCropActions=O.extend([],this.afterCropActions,[],!0),{selPointColl:null}),n=(this.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:n}}),r.selPointColl=O.extend([],n.selPointColl,[],!0),this.pointColl=t,this.notify("selection",{prop:"setFreehandDrawCustomized",value:{isFreehandDrawCustomized:!0}}),this.activeObj.strokeSettings.strokeColor=e,{freehandSelectedIndex:null}),t=(this.notify("freehand-draw",{prop:"getFreehandSelectedIndex",onPropertyChange:!1,value:{obj:n}}),null!=n.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}})),{bool:!1}),t=(this.notify("selection",{prop:"getFreehandDrawEditing",onPropertyChange:!1,value:{obj:t}}),t.bool?(this.notify("freehand-draw",{prop:"getFreehandSelectedIndex",onPropertyChange:!(n={freehandSelectedIndex:null}),value:{obj:n}}),this.upperContext.clearRect(0,0,this.upperCanvas.width,this.upperCanvas.height),this.pointColl[n.freehandSelectedIndex].strokeColor=e,this.notify("freehand-draw",{prop:"hoverFhd",onPropertyChange:!1,value:{strokeColor:e}}),this.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"freehanddrawCustomized",previousObj:r,previousObjColl:r.objColl,previousPointColl:r.pointColl,previousSelPointColl:r.selPointColl,previousCropObj:o,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}})):this.togglePen||this.notify("selection",{prop:"redrawShape",value:{obj:this.activeObj}}),i.type=v.ShapeType.FreehandDraw,{action:"stroke-color",currentShapeSettings:O.extend({},i,{},!0)});t.currentShapeSettings.strokeColor=e,this.trigger("shapeChange",t)},X.prototype.updateStrokeWidth=function(e){var t,o,i,r;this.activeObj.shape&&("path"!==this.activeObj.shape||"path"===this.activeObj.shape&&0<this.activeObj.pointColl.length)?(this.notify("selection",{prop:"updatePrevShapeSettings",onPropertyChange:!(t={shapeSettingsObj:{}}),value:{obj:t}}),t=t.shapeSettingsObj,this.notify("shape",{prop:"pushActItemIntoObj"}),o=O.extend({},this.cropObj,{},!0),this.notify("filter",{prop:"getCurrentObj",onPropertyChange:!(i={currObj:{}}),value:{object:i}}),(i=i.currObj).objColl=O.extend([],this.objColl,[],!0),i.pointColl=O.extend([],this.pointColl,[],!0),i.afterCropActions=O.extend([],this.afterCropActions,[],!0),this.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!(r={selPointColl:null}),value:{obj:r}}),i.selPointColl=O.extend([],r.selPointColl,[],!0),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: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]}}),(r={action:"stroke-width",currentShapeSettings:O.extend({},t,{},!0)}).currentShapeSettings.strokeWidth=this.activeObj.strokeSettings.strokeWidth,this.trigger("shapeChange",r)):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}}))},X.prototype.updateStrokeColor=function(e){var t,o,i={shapeSettingsObj:{}},i=(this.notify("selection",{prop:"updatePrevShapeSettings",onPropertyChange:!1,value:{obj:i}}),i.shapeSettingsObj),r=(this.activeObj.shape&&("path"!==this.activeObj.shape||"path"===this.activeObj.shape&&0<this.activeObj.pointColl.length)?(this.notify("shape",{prop:"pushActItemIntoObj"}),t=O.extend({},this.cropObj,{},!0),this.notify("filter",{prop:"getCurrentObj",onPropertyChange:!(o={currObj:{}}),value:{object:o}}),(o=o.currObj).objColl=O.extend([],this.objColl,[],!0),o.pointColl=O.extend([],this.pointColl,[],!0),o.afterCropActions=O.extend([],this.afterCropActions,[],!0),this.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!(r={selPointColl:null}),value:{obj:r}}),o.selPointColl=O.extend([],r.selPointColl,[],!0),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:o,previousObjColl:o.objColl,previousPointColl:o.pointColl,previousSelPointColl:o.selPointColl,previousCropObj:t,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),this.notify("selection",{prop:"redrawShape",value:{obj:this.objColl[this.objColl.length-1]}}))):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}})),{action:"stroke-color",currentShapeSettings:O.extend({},i,{},!0)});r.currentShapeSettings.strokeColor=e,this.trigger("shapeChange",r)},X.prototype.updateFillColor=function(e){var t={shapeSettingsObj:{}},t=(this.notify("selection",{prop:"updatePrevShapeSettings",onPropertyChange:!1,value:{obj:t}}),t.shapeSettingsObj),o=(this.notify("shape",{prop:"pushActItemIntoObj"}),O.extend({},this.cropObj,{},!0)),i={currObj:{}},i=(this.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:i}}),i.currObj),r=(i.objColl=O.extend([],this.objColl,[],!0),i.pointColl=O.extend([],this.pointColl,[],!0),i.afterCropActions=O.extend([],this.afterCropActions,[],!0),{selPointColl:null}),r=(this.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:r}}),i.selPointColl=O.extend([],r.selPointColl,[],!0),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: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]}}),{action:"fill-color",currentShapeSettings:O.extend({},t,{},!0)});this.trigger("shapeChange",r)},X.prototype.horizontalFlip=function(e,t){O.isNullOrUndefined(t)&&(O.isNullOrUndefined(this.activeObj.imageRatio)&&this.notify("shape",{prop:"updImgRatioForActObj",onPropertyChange:!1}),this.notify("shape",{prop:"pushActItemIntoObj"}),o=O.extend({},this.cropObj,{},!0),this.notify("filter",{prop:"getCurrentObj",onPropertyChange:!(i={currObj:{}}),value:{object:i}}),(i=i.currObj).objColl=O.extend([],this.objColl,[],!0),i.pointColl=O.extend([],this.pointColl,[],!0),i.afterCropActions=O.extend([],this.afterCropActions,[],!0),this.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!(r={selPointColl:null}),value:{obj:r}}),i.selPointColl=O.extend([],r.selPointColl,[],!0),this.objColl.pop()),this.notify("toolbar",{prop:"refreshSlider"}),e.clearRect(0,0,this.activeObj.imageCanvas.width,this.activeObj.imageCanvas.height);var o,i,r=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=r,this.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate"}}),O.isNullOrUndefined(t)&&(this.objColl.push(this.activeObj),this.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"imageHFlip",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]}}))},X.prototype.verticalFlip=function(e,t){O.isNullOrUndefined(t)&&(O.isNullOrUndefined(this.activeObj.imageRatio)&&this.notify("shape",{prop:"updImgRatioForActObj",onPropertyChange:!1}),this.notify("shape",{prop:"pushActItemIntoObj"}),o=O.extend({},this.cropObj,{},!0),this.notify("filter",{prop:"getCurrentObj",onPropertyChange:!(i={currObj:{}}),value:{object:i}}),(i=i.currObj).objColl=O.extend([],this.objColl,[],!0),i.pointColl=O.extend([],this.pointColl,[],!0),i.afterCropActions=O.extend([],this.afterCropActions,[],!0),this.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!(r={selPointColl:null}),value:{obj:r}}),i.selPointColl=O.extend([],r.selPointColl,[],!0),this.objColl.pop()),this.notify("toolbar",{prop:"refreshSlider"}),e.clearRect(0,0,this.activeObj.imageCanvas.width,this.activeObj.imageCanvas.height);var o,i,r=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=r,this.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate"}}),O.isNullOrUndefined(t)&&(this.objColl.push(this.activeObj),this.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"imageVFlip",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]}}))},X.prototype.rotateImage=function(e){O.isNullOrUndefined(this.activeObj.imageRatio)&&this.notify("shape",{prop:"updImgRatioForActObj",onPropertyChange:!1}),this.notify("shape",{prop:"pushActItemIntoObj"}),t=O.extend({},this.cropObj,{},!0);var t,o={currObj:{}},i=(this.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:o}}),(o=o.currObj).objColl=O.extend([],this.objColl,[],!0),o.pointColl=O.extend([],this.pointColl,[],!0),o.afterCropActions=O.extend([],this.afterCropActions,[],!0),{selPointColl:null});this.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:i}}),o.selPointColl=O.extend([],i.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:o,previousObjColl:o.objColl,previousPointColl:o.pointColl,previousSelPointColl:o.selPointColl,previousCropObj:t,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}})},X.prototype.pascalToSplitWords=function(e){var t=(e=e.charAt(0).toUpperCase()+e.slice(1)).match(/[A-Z][a-z]+/g);return O.isNullOrUndefined(t)?e:t.map(function(e){return e.charAt(0).toUpperCase()+e.slice(1)}).join(" ")},X.prototype.getCurrAdjustmentValue=function(e){var t,o={freehandSelectedIndex:null};return this.notify("freehand-draw",{prop:"getFreehandSelectedIndex",onPropertyChange:!1,value:{obj:o}}),"transparency"===e&&this.togglePen?(this.notify("freehand-draw",{prop:"getPenOpacity",onPropertyChange:!(t={penOpacity:1}),value:{obj:t}}),100*t.penOpacity):"transparency"===e&&null!=o.freehandSelectedIndex?100*this.pointColl[o.freehandSelectedIndex].opacity:(this.notify("filter",{prop:"getAdjustmentLevel",onPropertyChange:!(t={adjustmentLevel:null}),value:{obj:t}}),{brightness:t.adjustmentLevel.brightness,contrast:t.adjustmentLevel.contrast,hue:t.adjustmentLevel.hue,saturation:t.adjustmentLevel.saturation,opacity:t.adjustmentLevel.opacity,blur:t.adjustmentLevel.blur,exposure:t.adjustmentLevel.exposure,transparency:t.adjustmentLevel.transparency,straighten:this.transform.straighten}[""+e])},X.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 t=this.transform.straighten,o=O.extend({},this.activeObj,{},!0),i=this.transform.zoomFactor,r=(this.prevEventSelectionPoint=O.extend({},this.activeObj,{},!0),{currObj:{}}),r=(this.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:r}}),this.prevEventObjPoint=r.currObj,this.prevEventObjPoint.objColl=O.extend([],this.objColl,[],!0),this.prevEventObjPoint.pointColl=O.extend([],this.pointColl,[],!0),this.prevEventObjPoint.afterCropActions=O.extend([],this.afterCropActions,[],!0),{selPointColl:null});if(this.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!1,value:{obj:r}}),this.prevEventObjPoint.selPointColl=O.extend([],r.selPointColl,[],!0),0!==this.transform.straighten){this.transform.straighten=0,this.straightenBaseImageCanvas();for(var n=0,a=this.objColl.length;n<a;n++)"line"!==(s=this.objColl[n].shape)&&"arrow"!==s&&"path"!==s&&(this.objColl[n].rotatedAngle-=t*(Math.PI/180),this.notify("selection",{prop:"updPtCollForShpRot",onPropertyChange:!1,value:{obj:this.objColl[n]}}));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();r=O.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:r}}),!this.isStraightening||"horizontalflip"!==e&&"verticalflip"!==e||(this.notify("draw",{prop:"resetStraightenDestPoints"}),this.notify("draw",{prop:"setDestForStraighten"})),0!==t){this.transform.straighten=t,this.straightenBaseImageCanvas();for(var s,n=0,a=this.objColl.length;n<a;n++)"line"!==(s=this.objColl[n].shape)&&"arrow"!==s&&"path"!==s&&(this.objColl[n].rotatedAngle+=t*(Math.PI/180),this.notify("selection",{prop:"updPtCollForShpRot",onPropertyChange:!1,value:{obj:this.objColl[n]}}));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:o}}),this.notify("draw",{prop:"setStraightenActObj",value:{activeObj:null}}),this.notify("draw",{prop:"setStraightenInitZoom",value:{zoomFactor:i}}),(this.isStraightening&&("horizontalflip"===e||"verticalflip"===e)&&O.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:o,isToolbar:!1}})}this.isCropToolbar=!1;r=this.element.querySelector(".e-ie-straighten-value-span");r&&(r.innerHTML=this.transform.straighten.toString()+"°")},X.prototype.getDefaultFilter=function(){return"brightness(1) contrast(100%) hue-rotate(0deg) saturate(100%) opacity(1) blur(0px) sepia(0%) grayscale(0%) invert(0%)"},X.prototype.setStraighten=function(e){e={cancel:!1,previousDegree:this.transform.straighten,currentDegree:e};this.trigger("rotating",e),e.cancel||this.performStraighten(e)},X.prototype.duplicateImage=function(){var e=O.extend({},this.activeObj.activePoint,{},!0),t={width:0,height:0};return this.notify("transform",{prop:"calcMaxDimension",onPropertyChange:!1,value:{width:this.activeObj.imageElement.width,height:this.activeObj.imageElement.height,obj:t,isImgShape:null}}),this.activeObj.activePoint.width=t.width,this.activeObj.activePoint.height=t.height,e},X.prototype.performStraighten=function(e){var e=e.currentDegree,t=this.element.querySelector(".e-ie-straighten-value-span"),t=(t&&(t.innerHTML=e.toString()+"°"),O.extend({},this.activeObj,null,!0));this.notify("freehand-draw",{prop:"setCenterSelPoints"}),this.transform.straighten=e,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 o=0,i=this.objColl.length;o<i;o++){var r=this.objColl[o].shape;"line"!==r&&"arrow"!==r&&"path"!==r&&(this.objColl[o].rotatedAngle+=(this.transform.straighten-this.prevStraightenedDegree)*(Math.PI/180),this.notify("selection",{prop:"updPtCollForShpRot",onPropertyChange:!1,value:{obj:this.objColl[o]}}))}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:t}}),this.notify("draw",{prop:"zoomToSel",value:{activeObj:t,isToolbar:!0}}),this.notify("transform",{prop:"disableZoomOutBtn",value:{isZoomOut:!0}}),this.prevStraightenedDegree=this.transform.straighten},X.prototype.straightenBaseImageCanvas=function(){var e,t,o,i;this.isImageLoaded&&(e="horizontal"===(e=this.getStraightenFlipState())||"vertical"===e?-this.transform.straighten:this.transform.straighten,o=void((t=this.baseImgCanvas.getContext("2d")).canvas.width!==this.lowerContext.canvas.width&&t.canvas.height!==this.lowerContext.canvas.height&&this.notify("crop",{prop:"calcRatio",onPropertyChange:!1,value:{obj:{width:0,height:0},dimension:{width:t.canvas.width,height:t.canvas.height}}})),o=this.getRotatedCanvasDim(this.baseImg.width,this.baseImg.height,this.transform.straighten),this.img.srcWidth=t.canvas.width=o.width,this.img.srcHeight=t.canvas.height=o.height,o=t.canvas.width/2,i=t.canvas.height/2,t.clearRect(0,0,t.canvas.width,t.canvas.height),t.translate(o,i),t.rotate(e*Math.PI/180),t.drawImage(this.baseImg,-this.baseImg.width/2,-this.baseImg.height/2,this.baseImg.width,this.baseImg.height),t.setTransform(1,0,0,1,0,0),this.notify("crop",{prop:"calcRatio",onPropertyChange:!1,value:{obj:{width:0,height:0},dimension:{width:t.canvas.width,height:t.canvas.height}}}))},X.prototype.getRotatedCanvasDim=function(e,t,o){var o=o*Math.PI/180,i=Math.cos(o),r=Math.sin(o),n=Math.min(0,e*i,t*Math.cos(Math.PI/2-o),e*i+t*Math.cos(Math.PI/2-o)),i=Math.max(0,e*i,t*Math.cos(Math.PI/2-o),e*i+t*Math.cos(Math.PI/2-o)),a=Math.min(0,e*r,t*Math.sin(Math.PI/2-o),e*r+t*Math.sin(Math.PI/2-o)),e=Math.max(0,e*r,t*Math.sin(Math.PI/2-o),e*r+t*Math.sin(Math.PI/2-o));return{width:Math.ceil(i-n),height:Math.ceil(e-a)}},X.prototype.updateShapeOrder=function(e,t){var o,i,r,n,e=this.getObjFromId(e);e.shape&&("path"!==e.shape||"path"===e.shape&&0<e.pointColl.length)||e&&e.id&&-1<e.id.indexOf("pen")?(this.notify("selection",{prop:"updatePrevShapeSettings",onPropertyChange:!(o={shapeSettingsObj:{}}),value:{obj:o}}),o=o.shapeSettingsObj,e.shape&&this.notify("shape",{prop:"pushActItemIntoObj"}),i=O.extend({},this.cropObj,{},!0),this.notify("filter",{prop:"getCurrentObj",onPropertyChange:!(r={currObj:{}}),value:{object:r}}),(r=r.currObj).objColl=O.extend([],this.objColl,[],!0),r.pointColl=O.extend([],this.pointColl,[],!0),r.afterCropActions=O.extend([],this.afterCropActions,[],!0),this.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!(n={selPointColl:null}),value:{obj:n}}),r.selPointColl=O.extend([],n.selPointColl,[],!0),e.shape&&this.objColl.pop(),this.notify("shape",{prop:"z-order",onPropertyChange:!1,value:{obj:e,value:t}}),e.shape&&(this.notify("shape",{prop:"setStrokeSettings",value:{strokeSettings:null,strokeColor:null,fillColor:null,strokeWidth:e.strokeSettings.strokeWidth}}),this.objColl.push(e)),this.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"shapeTransform",previousObj:r,previousObjColl:r.objColl,previousPointColl:r.pointColl,previousSelPointColl:r.selPointColl,previousCropObj:i,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),e.shape&&(this.notify("selection",{prop:"redrawShape",value:{obj:this.objColl[this.objColl.length-1]}}),this.activeObj.order=e.order),{action:"stroke-width",previousShapeSettings:O.extend({},o,{},!0),currentShapeSettings:O.extend({},o,{},!0)}.currentShapeSettings.strokeWidth=this.activeObj.strokeSettings.strokeWidth):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}})},X.prototype.getStraightenFlipState=function(){var e="";if(0<this.rotateFlipColl.length)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},X.prototype.initializeZoomSettings=function(){this.theme=O.isNullOrUndefined(this.theme)?"Bootstrap5":this.theme,!O.isNullOrUndefined(this.zoomSettings.zoomTrigger)&&0!==this.zoomSettings.zoomTrigger||(this.zoomSettings.zoomTrigger=v.ZoomTrigger.MouseWheel|v.ZoomTrigger.Pinch|v.ZoomTrigger.Toolbar|v.ZoomTrigger.Commands),O.isNullOrUndefined(this.selectionSettings.strokeColor)&&(this.selectionSettings.strokeColor=this.themeColl[this.theme].primaryColor),O.isNullOrUndefined(this.selectionSettings.fillColor)&&(this.selectionSettings.fillColor=this.themeColl[this.theme].secondaryColor)},X.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"}}},x([O.Property("")],X.prototype,"cssClass",void 0),x([O.Property(!1)],X.prototype,"disabled",void 0),x([O.Property("100%")],X.prototype,"height",void 0),x([O.Property("Bootstrap5")],X.prototype,"theme",void 0),x([O.Property()],X.prototype,"toolbar",void 0),x([O.Property()],X.prototype,"toolbarTemplate",void 0),x([O.Property("100%")],X.prototype,"width",void 0),x([O.Property(!0)],X.prototype,"allowUndoRedo",void 0),x([O.Property(!0)],X.prototype,"showQuickAccessToolbar",void 0),x([O.Property()],X.prototype,"quickAccessToolbarTemplate",void 0),x([O.Property(!1)],X.prototype,"isReadOnly",void 0),x([O.Property(!1)],X.prototype,"enableRtl",void 0),x([O.Property(!1)],X.prototype,"enablePersistence",void 0),x([O.Complex({},U)],X.prototype,"finetuneSettings",void 0),x([O.Complex({},W)],X.prototype,"zoomSettings",void 0),x([O.Complex({},_)],X.prototype,"selectionSettings",void 0),x([O.Complex({},N)],X.prototype,"fontFamily",void 0),x([O.Event()],X.prototype,"beforeSave",void 0),x([O.Event()],X.prototype,"created",void 0),x([O.Event()],X.prototype,"destroyed",void 0),x([O.Event()],X.prototype,"zooming",void 0),x([O.Event()],X.prototype,"panning",void 0),x([O.Event()],X.prototype,"cropping",void 0),x([O.Event()],X.prototype,"rotating",void 0),x([O.Event()],X.prototype,"flipping",void 0),x([O.Event()],X.prototype,"shapeChanging",void 0),x([O.Event()],X.prototype,"selectionChanging",void 0),x([O.Event()],X.prototype,"fileOpened",void 0),x([O.Event()],X.prototype,"saved",void 0),x([O.Event()],X.prototype,"toolbarCreated",void 0),x([O.Event()],X.prototype,"toolbarUpdating",void 0),x([O.Event()],X.prototype,"toolbarItemClicked",void 0),x([O.Event()],X.prototype,"imageFiltering",void 0),x([O.Event()],X.prototype,"finetuneValueChanging",void 0),x([O.Event()],X.prototype,"click",void 0),x([O.Event()],X.prototype,"shapeChange",void 0),x([O.Event()],X.prototype,"quickAccessToolbarOpen",void 0),x([O.Event()],X.prototype,"resizing",void 0),x([O.Event()],X.prototype,"quickAccessToolbarItemClick",void 0),x([O.Event()],X.prototype,"frameChange",void 0);var z,D,j=D=x([O.NotifyPropertyChanges],X);function X(e,t){e=z.call(this,e)||this;return e.isImageLoaded=!1,e.activeObj={activePoint:{startX:0,startY:0,endX:0,endY:0,width:0,height:0},flipObjColl:[],triangle:[],triangleRatio:[],rotatedAngle:0,opacity:1,order:null},e.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},e.objColl=[],e.pointColl={},e.freehandCounter=0,e.points=[],e.togglePen=!1,e.togglePan=!1,e.img={destLeft:0,destTop:0,destWidth:0,destHeight:0,srcLeft:0,srcTop:0,srcWidth:0,srcHeight:0},e.rotateFlipColl=[],e.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:""},e.afterCropActions=[],e.transform={degree:0,currFlipState:"",zoomFactor:0,cropZoomFactor:null,defaultZoomFactor:0,straighten:0},e.panPoint={currentPannedPoint:{x:0,y:0},totalPannedPoint:{x:0,y:0},totalPannedInternalPoint:{x:0,y:0},totalPannedClientPoint:{x:0,y:0}},e.isUndoRedo=!1,e.isCropTab=!1,e.isCircleCrop=!1,e.fontSizeColl=[],e.initialAdjustmentValue="",e.currentFilter="",e.canvasFilter="brightness(1) contrast(100%) hue-rotate(0deg) saturate(100%) opacity(1) blur(0px) sepia(0%) grayscale(0%) invert(0%)",e.toolbarHeight=0,e.isPublicMethod=!1,e.isCropToolbar=!1,e.cursor="default",e.resizeSrc={startX:e.img.srcLeft,startY:e.img.srcTop,width:e.img.srcWidth,height:e.img.srcHeight},e.isResize=!1,e.isAspectRatio=!1,e.frameObj={type:"none",color:"#fff",size:20,inset:20,offset:20,radius:0,amount:1,border:"solid",gradientColor:""},e.tempFrameObj={type:"none",color:"#fff",size:20,inset:20,offset:20,radius:0,amount:1,border:"solid",gradientColor:""},e.allowDownScale=!0,e.gradientColor="",e.size=20,e.inset=0,e.offset=0,e.borderRadius=0,e.lineCount=0,e.prevStraightenedDegree=0,e.tempStraighten=0,e.isStraightening=!1,e.isFinetuning=!1,e.isZoomBtnClick=!1,e.isFinetuneBtnClick=!1,e.isFilterCanvasClick=!1,e.isFrameBtnClick=!1,e.isChangesSaved=!1,e.isShapeDrawing=!1,e.noPushUndo=!1,e.isUndoRedoStack=!1,e.shapeColl=[],D.Inject(o,i,h,B,r,q),D.Inject(M),D.Inject(a),D.Inject(H),D.Inject(l),t&&e.appendTo(t),e}(x=v.FileType||(v.FileType={})).Png="Png",x.Jpeg="Jpeg",x.Svg="Svg",(x=v.Direction||(v.Direction={})).Horizontal="Horizontal",x.Vertical="Vertical",(x=v.ShapeType||(v.ShapeType={})).Rectangle="Rectangle",x.Ellipse="Ellipse",x.Line="Line",x.Arrow="Arrow",x.Path="Path",x.Text="Text",x.FreehandDraw="FreehandDraw",x.Image="Image",(x=v.ZoomTrigger||(v.ZoomTrigger={}))[x.MouseWheel=1]="MouseWheel",x[x.Pinch=2]="Pinch",x[x.Commands=4]="Commands",x[x.Toolbar=8]="Toolbar",(x=v.Theme||(v.Theme={})).Bootstrap5="Bootstrap5",x.Bootstrap5Dark="Bootstrap5Dark",x.Tailwind="Tailwind",x.TailwindDark="TailwindDark",x.Fluent="Fluent",x.FluentDark="FluentDark",x.Bootstrap4="Bootstrap4",x.Bootstrap="Bootstrap",x.BootstrapDark="BootstrapDark",x.Material="Material",x.MaterialDark="MaterialDark",x.Fabric="Fabric",x.FabricDark="FabricDark",x.Highcontrast="Highcontrast",x.Fluent2="Fluent2",x.Fluent2Dark="Fluent2Dark",(x=v.ImageEditorCommand||(v.ImageEditorCommand={})).Crop="Crop",x.Transform="Transform",x.Annotate="Annotate",x.ZoomIn="ZoomIn",x.ZoomOut="ZoomOut",x.Open="Open",x.Reset="Reset",x.Save="Save",x.Pan="Pan",x.Move="Move",x.Pen="Pen",x.Line="Line",x.Arrow="Arrow",x.Path="Path",x.Rectangle="Rectangle",x.Image="Image",x.Ellipse="Ellipse",x.Text="Text",x.CustomSelection="CustomSelection",x.CircleSelection="CircleSelection",x.SquareSelection="SquareSelection",x.RatioSelection="RatioSelection",x.RotateLeft="RotateLeft",x.RotateRight="RotateRight",x.FlipHorizontal="FlipHorizontal",x.FlipVertical="FlipVertical",x.Undo="Undo",x.Redo="Redo",x.None="None",x.Mat="Mat",x.Bevel="Bevel",x.Inset="Inset",x.Hook="Hook",x.Finetune="Finetune",x.Filter="Filter",x.Frame="Frame",x.Resize="Resize",x.HorizontalFlip="HorizontalFlip",x.VerticalFlip="VerticalFlip",x.Brightness="Brightness",x.Contrast="Contrast",x.Hue="Hue",x.Saturation="Saturation",x.Opacity="Opacity",x.Blur="Blur",x.Exposure="Exposure",x.Default="Default",x.Chrome="Chrome",x.Cold="Cold",x.Warm="Warm",x.Grayscale="Grayscale",x.Sepia="Sepia",x.Invert="Invert",x.Straightening="Straightening",(x=v.ImageFilterOption||(v.ImageFilterOption={})).Default="Default",x.Chrome="Chrome",x.Cold="Cold",x.Warm="Warm",x.Grayscale="Grayscale",x.Sepia="Sepia",x.Invert="Invert",(x=v.ImageFinetuneOption||(v.ImageFinetuneOption={})).Brightness="Brightness",x.Contrast="Contrast",x.Hue="Hue",x.Saturation="Saturation",x.Exposure="Exposure",x.Opacity="Opacity",x.Blur="Blur",(x=v.ArrowheadType||(v.ArrowheadType={})).None="None",x.Arrow="Arrow",x.SolidArrow="SolidArrow",x.Circle="Circle",x.SolidCircle="SolidCircle",x.Square="Square",x.SolidSquare="SolidSquare",x.Bar="Bar",(x=v.FrameType||(v.FrameType={})).None="None",x.Mat="Mat",x.Bevel="Bevel",x.Line="Line",x.Inset="Inset",x.Hook="Hook",(x=v.FrameLineStyle||(v.FrameLineStyle={})).Solid="Solid",x.Dashed="Dashed",x.Dotted="Dotted";Y.prototype.destroy=function(){this.parent.isDestroyed||this.removeEventListener()},Y.prototype.addEventListener=function(){this.parent.on("toolbar",this.toolbar,this),this.parent.on("destroyed",this.destroy,this)},Y.prototype.removeEventListener=function(){this.parent.off("toolbar",this.toolbar),this.parent.off("destroyed",this.destroy)},Y.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 O.L10n("image-editor",this.defaultLocale,this.parent.locale)},Y.prototype.toolbar=function(e){var t=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":(O.isNullOrUndefined(t.toolbar)||t.toolbar&&0<t.toolbar.length&&-1<t.toolbar.indexOf("Open"))&&(this.toolbarHeight=e.value.height);break;case"setCurrentToolbar":this.currentToolbar=e.value.type;break;case"setSelectedFreehandColor":this.selFhdColor=e.value.color;break;case"setInitialAdjustmentValue":t.initialAdjustmentValue=e.value.value;break;case"getCanvasFilter":e.value.obj.canvasFilter=t.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":t.setTempFilterProperties();break;case"refreshSlider":this.refreshSlider();break;case"getCurrAdjustmentValue":t.getCurrAdjustmentValue(e.value.type);break;case"setCurrAdjustmentValue":t.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)}},Y.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"))},Y.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},Y.prototype.destroyTopToolbar=function(){var e=this.parent,e=document.getElementById(e.element.id+"_toolbar");this.isToolbar()&&e&&e.classList.contains("e-control")&&O.getComponent(e,"toolbar").destroy()},Y.prototype.destroyBottomToolbar=function(){var e=this.parent,e=document.getElementById(e.element.id+"_bottomToolbar");e&&e.classList.contains("e-control")&&O.getComponent(e,"toolbar").destroy()},Y.prototype.isToolbar=function(){var e=this.parent;return O.isNullOrUndefined(e.toolbar)||e.toolbar&&0<e.toolbar.length||!O.isNullOrUndefined(e.toolbarTemplate)},Y.prototype.createToolbar=function(){var e,t,o=this,i=this.parent,r=i.element.id;O.isNullOrUndefined(i.toolbar)||i.toolbar&&0<i.toolbar.length?(i.element.appendChild(i.createElement("div",{id:r+"_toolbarArea",className:"e-toolbar-area"})),e={cssClass:"e-image-upload",align:"Left",type:"Input",tooltipText:this.l10n.getConstant("Browse"),template:new g.Uploader({allowedExtensions:".jpg, .jpeg, .png,.svg",multiple:!1})},O.isNullOrUndefined(this.defToolbarItems)&&(this.defToolbarItems=[]),this.defToolbarItems.push(e),e=document.getElementById(r+"_toolbarArea"),t=i.createElement("div",{id:r+"_toolbar"}),e.appendChild(t),e=[{cssClass:"e-image-upload",align:"Left",type:"Input",tooltipText:this.l10n.getConstant("Browse"),template:new g.Uploader({allowedExtensions:".jpg, .jpeg, .png,.svg",multiple:!1,selected:function(){var e=document.getElementById(r+"_toolbar"),t=document.getElementById(r+"_bottomToolbar");i.disabled||(O.Browser.isDevice?(0<o.defToolbarItems.length&&e&&O.getComponent(e,"toolbar").destroy(),t&&O.getComponent(t,"toolbar").destroy(),o.initMainToolbar(!1,O.Browser.isDevice,null),o.createBottomToolbar()):(0<o.defToolbarItems.length&&e&&O.getComponent(e,"toolbar").destroy(),o.initMainToolbar(!1,!1,null)))}})}],new d.Toolbar({items:e,width:"100%",created:function(){i.trigger("toolbarCreated",{toolbarType:"main"})},clicked:this.defToolbarClicked.bind(this)}).appendTo("#"+r+"_toolbar"),this.createLeftToolbarControls(),e=document.getElementById(r+"_toolbar"),t&&(this.toolbarHeight=e.clientHeight,i.toolbar)&&0<i.toolbar.length&&-1===i.toolbar.indexOf("Open")&&(t=O.getComponent(document.getElementById(i.element.id+"_toolbar"),"toolbar"))&&(t.destroy(),document.getElementById(i.element.id+"_toolbar").innerHTML="")):this.toolbarHeight=0},Y.prototype.createContextualToolbar=function(){var e,t=this.parent,o=t.element.id;(O.isNullOrUndefined(t.toolbar)||t.toolbar&&0<t.toolbar.length)&&(t.element.appendChild(t.createElement("div",{id:o+"_contextualToolbarArea",className:"e-contextual-toolbar-wrapper e-hide",attrs:{style:"position: absolute;"}})),e=document.getElementById(o+"_contextualToolbarArea"),t=t.createElement("div",{id:o+"_contextualToolbar"}),e.appendChild(t))},Y.prototype.createBottomToolbar=function(){var e,t=this.parent,o=t.element.id;t.element.querySelector("#"+o+"_bottomToolbarArea")&&t.element.querySelector("#"+o+"_bottomToolbarArea").remove(),(O.isNullOrUndefined(t.toolbar)||t.toolbar&&0<t.toolbar.length)&&(t.element.appendChild(t.createElement("div",{id:o+"_bottomToolbarArea",className:"e-bottom-toolbar"})),t.toolbarTemplate||(e=document.getElementById(o+"_bottomToolbarArea"),t=t.createElement("div",{id:o+"_bottomToolbar"}),e.appendChild(t)),this.initBottomToolbar())},Y.prototype.createQuickAccessToolbar=function(){var e,t=this.parent,o=t.element.id;t.showQuickAccessToolbar&&(e={cssClass:"e-image-upload",align:"Left",type:"Input",tooltipText:this.l10n.getConstant("Browse"),template:new g.Uploader({allowedExtensions:".jpg, .jpeg, .png,.svg",multiple:!1})},O.isNullOrUndefined(this.defToolbarItems)&&(this.defToolbarItems=[]),this.defToolbarItems.push(e),e=document.getElementById(o+"_quickAccessToolbarArea"),t=t.createElement("div",{id:o+"_quickAccessToolbar"}),e.appendChild(t),new d.Toolbar({clicked:this.defToolbarClicked.bind(this)}).appendTo("#"+o+"_quickAccessToolbar"))},Y.prototype.initMainToolbar=function(e,t,o,i,r,n){var a=this,s=this.parent,l=s.element.id;this.isToolbar()&&(i=this.getLeftToolbarItem(o,i),o=this.getRightToolbarItem(o,n),n=this.getMainToolbarItem(e,r),e=this.getZoomToolbarItem(),this.defToolbarItems=t?r?n:i.concat(o):i.concat(n,o,e),i={toolbarType:"main",toolbarItems:this.defToolbarItems},s.trigger("toolbarUpdating",i),this.defToolbarItems=i.toolbarItems,0<this.defToolbarItems.length)&&(n=new d.Toolbar({width:"100%",items:this.defToolbarItems,clicked:this.defToolbarClicked.bind(this),created:function(){t||a.renderAnnotationBtn(),a.wireZoomBtnEvents(),s.trigger("toolbarCreated",{toolbarType:"main"})}}),t&&r?n.appendTo("#"+l+"_bottomToolbar"):n.appendTo("#"+l+"_toolbar"),this.createLeftToolbarControls(),this.enableDisableTbrBtn(),this.isToolbar())&&document.getElementById(l+"_toolbar")&&O.getComponent(l+"_toolbar","toolbar").refreshOverflow()},Y.prototype.initBottomToolbar=function(){var e,t=this,o=this.parent,i=o.element.id;(O.isNullOrUndefined(o.toolbar)||o.toolbar&&0<o.toolbar.length)&&(e={toolbarType:"bottom-toolbar",toolbarItems:this.getMainToolbarItem()},o.trigger("toolbarUpdating",e),new d.Toolbar({items:e.toolbarItems,width:"100%",created:function(){t.renderAnnotationBtn(),t.renderCropBtn(),t.renderTransformBtn(),o.trigger("toolbarCreated",{toolbarType:"main"})},clicked:this.defToolbarClicked.bind(this)}).appendTo("#"+i+"_bottomToolbar"),0<this.defToolbarItems.length)&&document.getElementById(i+"_bottomToolbar")&&O.getComponent(i+"_bottomToolbar","toolbar").refreshOverflow()},Y.prototype.getLeftToolbarItem=function(e,t){for(var o=this.parent,i=o.element.id,r=[],n=(e&&!t||(O.isNullOrUndefined(o.toolbar)||o.toolbar&&-1<o.toolbar.indexOf("Open")?(r.push({id:i+"_upload",cssClass:"e-image-upload",align:"Left",type:"Input",template:new g.Uploader({allowedExtensions:".jpg, .jpeg, .png,.svg",multiple:!1})}),r.push({visible:!1,cssClass:"e-image-position e-btn e-flat",tooltipText:this.l10n.getConstant("Browse"),align:"Left"})):O.Browser.isDevice&&o.toolbar&&-1===o.toolbar.indexOf("Open")&&(r.push({visible:!1,id:i+"_upload",cssClass:"e-image-upload",align:"Left",type:"Input",template:new g.Uploader({allowedExtensions:".jpg, .jpeg, .png,.svg",multiple:!1})}),r.push({visible:!1,cssClass:"e-image-position e-btn e-flat",tooltipText:this.l10n.getConstant("Browse"),align:"Left"}))),o.allowUndoRedo&&!t&&((O.isNullOrUndefined(o.toolbar)||o.toolbar&&-1<o.toolbar.indexOf("Undo"))&&r.push({id:i+"_undo",prefixIcon:"e-icons e-undo",cssClass:"top-icon e-undo",tooltipText:this.l10n.getConstant("Undo"),align:"Left"}),O.isNullOrUndefined(o.toolbar)||o.toolbar&&-1<o.toolbar.indexOf("Redo"))&&r.push({id:i+"_redo",prefixIcon:"e-icons e-redo",cssClass:"top-icon e-redo",tooltipText:this.l10n.getConstant("Redo"),align:"Left"}),!this.preventZoomBtn&&(o.zoomSettings.zoomTrigger&v.ZoomTrigger.Toolbar)===v.ZoomTrigger.Toolbar&&!t&&((O.isNullOrUndefined(o.toolbar)||o.toolbar&&-1<o.toolbar.indexOf("ZoomOut"))&&r.push({id:i+"_zoomOut",prefixIcon:"e-icons e-zoom-out",cssClass:"top-icon e-dec-zoom",tooltipText:this.l10n.getConstant("ZoomOut"),align:"Left"}),O.isNullOrUndefined(o.toolbar)||o.toolbar&&-1<o.toolbar.indexOf("ZoomIn"))&&r.push({id:i+"_zoomIn",prefixIcon:"e-icons e-zoom-in",cssClass:"top-icon e-inc-zoom",tooltipText:this.l10n.getConstant("ZoomIn"),align:"Left"}),this.processToolbar("left")),a=0,s=n.length;a<s;a++)r.push(n[a]);return r},Y.prototype.getRightToolbarItem=function(e,t){for(var o=this.parent,i=o.element.id,r=[],n=(e&&(r.push({id:i+"_ok",prefixIcon:"e-icons e-check",cssClass:"top-icon e-tick",tooltipText:this.l10n.getConstant("OK"),align:"Right"}),r.push({id:i+"_cancel",prefixIcon:"e-icons e-close",cssClass:"top-icon e-save",tooltipText:this.l10n.getConstant("Cancel"),align:"Right"})),!t&&O.Browser.isDevice||!(O.isNullOrUndefined(o.toolbar)||o.toolbar&&-1<o.toolbar.indexOf("Reset"))||r.push({id:i+"_reset",prefixIcon:"e-icons e-btn-reset",cssClass:"top-icon e-img-reset",tooltipText:this.l10n.getConstant("Reset"),align:"Right"}),e||(O.isNullOrUndefined(o.toolbar)||o.toolbar&&-1<o.toolbar.indexOf("Save"))&&r.push({id:i+"_save",prefixIcon:"e-icons e-btn-save",cssClass:"e-caret-hide top-icon e-save",tooltipText:this.l10n.getConstant("Save"),align:"Right"}),this.processToolbar("right")),a=0,s=n.length;a<s;a++)r.push(n[a]);return r},Y.prototype.getMainToolbarItem=function(e,t){for(var o=this.parent,i=o.element.id,r=[],n=(t?((O.isNullOrUndefined(o.toolbar)||!O.isNullOrUndefined(o.toolbar)&&-1<o.toolbar.indexOf("None")||-1<o.toolbar.indexOf("Frame"))&&r.push({id:i+"_none",prefixIcon:"e-icons e-frame-none",cssClass:"top-icon e-frame-none",tooltipText:this.l10n.getConstant("None"),align:"Center"}),(O.isNullOrUndefined(o.toolbar)||!O.isNullOrUndefined(o.toolbar)&&-1<o.toolbar.indexOf("Mat")||-1<o.toolbar.indexOf("Frame"))&&r.push({id:i+"_mat",prefixIcon:"e-icons e-frame-mat",cssClass:"top-icon e-frame-mat",tooltipText:this.l10n.getConstant("Mat"),align:"Center"}),(O.isNullOrUndefined(o.toolbar)||!O.isNullOrUndefined(o.toolbar)&&-1<o.toolbar.indexOf("Bevel")||-1<o.toolbar.indexOf("Frame"))&&r.push({id:i+"_bevel",prefixIcon:"e-icons e-frame-bevel",cssClass:"top-icon e-frame-bevel",tooltipText:this.l10n.getConstant("Bevel"),align:"Center"}),(O.isNullOrUndefined(o.toolbar)||!O.isNullOrUndefined(o.toolbar)&&-1<o.toolbar.indexOf("Line")||-1<o.toolbar.indexOf("Frame"))&&r.push({id:i+"_line",prefixIcon:"e-icons e-frame-line",cssClass:"top-icon e-frame-line",tooltipText:this.l10n.getConstant("Line"),align:"Center"}),(O.isNullOrUndefined(o.toolbar)||!O.isNullOrUndefined(o.toolbar)&&-1<o.toolbar.indexOf("Inset")||-1<o.toolbar.indexOf("Frame"))&&r.push({id:i+"_inset",prefixIcon:"e-icons e-frame-inset",cssClass:"top-icon e-frame-inset",tooltipText:this.l10n.getConstant("Inset"),align:"Center"}),(O.isNullOrUndefined(o.toolbar)||!O.isNullOrUndefined(o.toolbar)&&-1<o.toolbar.indexOf("Hook")||-1<o.toolbar.indexOf("Frame"))&&r.push({id:i+"_hook",prefixIcon:"e-icons e-frame-hook",cssClass:"top-icon e-frame-hook",tooltipText:this.l10n.getConstant("Hook"),align:"Center"})):((O.isNullOrUndefined(o.toolbar)||o.toolbar&&-1<o.toolbar.indexOf("Crop"))&&r.push({id:i+"_cropTransform",prefixIcon:"e-icons e-crop",cssClass:"top-icon e-crop",tooltipText:this.l10n.getConstant("CropAndTransform"),align:"Center"}),(O.isNullOrUndefined(o.toolbar)||o.toolbar&&-1<o.toolbar.indexOf("Annotate"))&&r.push({id:i+"_annotation",tooltipText:this.l10n.getConstant("Annotation"),align:"Center",template:'<button id="'+i+'_annotationBtn"></button>'}),(O.isNullOrUndefined(o.toolbar)||o.toolbar&&-1<o.toolbar.indexOf("Finetune"))&&r.push({id:i+"_adjustment",prefixIcon:"e-icons e-adjustment",cssClass:"top-icon e-adjustment",tooltipText:this.l10n.getConstant("Finetune"),align:"Center"}),(O.isNullOrUndefined(o.toolbar)||o.toolbar&&-1<o.toolbar.indexOf("Filter"))&&r.push({id:i+"_filter",prefixIcon:"e-icons e-filters",cssClass:"top-icon e-filters",tooltipText:this.l10n.getConstant("Filter"),align:"Center"}),(O.isNullOrUndefined(o.toolbar)||!O.isNullOrUndefined(o.toolbar)&&-1<o.toolbar.indexOf("Frame"))&&r.push({id:i+"_frame",prefixIcon:"e-icons e-border-frame",cssClass:"top-icon e-border-frame",tooltipText:this.l10n.getConstant("Frame"),align:"Center"}),(O.isNullOrUndefined(o.toolbar)||!O.isNullOrUndefined(o.toolbar)&&-1<o.toolbar.indexOf("Resize"))&&r.push({id:i+"_resize",prefixIcon:"e-icons e-resize",cssClass:"top-icon e-resize",tooltipText:this.l10n.getConstant("Resize"),align:"Center"})),this.processToolbar("center")),a=0,s=n.length;a<s;a++)r.push(n[a]);return e&&(r.push({id:i+"_ok",prefixIcon:"e-icons e-check",cssClass:"top-icon e-tick",tooltipText:this.l10n.getConstant("OK"),align:"Right"}),r.push({id:i+"_cancel",prefixIcon:"e-icons e-close",cssClass:"top-icon e-save",tooltipText:this.l10n.getConstant("Cancel"),align:"Right"})),r},Y.prototype.getZoomToolbarItem=function(){return[]},Y.prototype.updateContextualToolbar=function(e,t,o){var i,r=this.parent,n=r.element.id,a=r.element.querySelector("#"+n+"_toolbarArea"),s=r.element.querySelector("#"+n+"_contextualToolbarArea");s&&(s.classList.remove("e-hide"),s.style.left=a.offsetLeft+"px","filter"===e?((a=document.getElementById(n+"_toolbar"))&&0<this.defToolbarItems.length&&O.getComponent(a,"toolbar").destroy(),O.Browser.isDevice?this.initMainToolbar(!1,!0,!0):this.initMainToolbar(!0,null,null),this.refreshSlider(),this.initFilterToolbarItem()):((i=document.querySelector("#"+n+"_contextualToolbar")).classList.contains("e-control")&&O.getComponent(i,"toolbar").destroy(),this.refreshSlider(),"frame"===e?this.initFrameToolbarItem():this.renderSlider(t,o)),r.toolbarTemplate?this.toolbarHeight=r.element.querySelector("#"+n+"_toolbarArea").clientHeight:r.element.querySelector("#"+n+"_toolbar")&&(this.toolbarHeight=r.element.querySelector("#"+n+"_toolbar").clientHeight),r.toolbarHeight=this.toolbarHeight,O.Browser.isDevice?(a=s.offsetHeight+1,e=r.element.querySelector("#"+n+"_customizeWrapper"),this.isFrameToolbar&&e&&(a=e.offsetHeight+2),e=r.element.querySelector("#"+n+"_canvasWrapper").offsetHeight,s.style.top=this.toolbarHeight+1+e-a+"px","straighten"===t&&(r.isStraightening=!0,"absolute"===(i=r.element.querySelector("#"+n+"_contextualToolbarArea")).style.position)&&(i.style.position="",r.element.insertBefore(i,r.element.querySelector("#"+n+"_bottomToolbarArea")),r.update(),o)&&r.notify("draw",{prop:"select",onPropertyChange:!1,value:{type:this.getCropTextContent(document.getElementById(n+"_cropBtn")).toLowerCase(),startX:null,startY:null,width:null,height:null}})):s.style.top=this.toolbarHeight+1+"px")},Y.prototype.processToolbar=function(e){var t=this.parent,o=[];if(t.toolbar)for(var i=0,r=t.toolbar.length;i<r;i++)"object"==typeof t.toolbar[i]&&(O.isNullOrUndefined(t.toolbar[i].align)?"left"===e&&o.push(t.toolbar[i]):t.toolbar[i].align.toLowerCase()===e&&o.push(t.toolbar[i]));return o},Y.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},Y.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)))},Y.prototype.widthPress=function(e){109===e.keyCode&&e.preventDefault()},Y.prototype.heightPress=function(e){109===e.keyCode&&e.preventDefault()},Y.prototype.widthAspectRatio=function(e){var t,o,i,r,n;109!==e.keyCode&&(o=(e=this.parent).element.id,n=e.element.querySelector("#"+o+"_resizeHeight"),t=e.element.querySelector("#"+o+"_resizeWidth"),o=e.element.querySelector("#"+o+"_aspectratio"),r=e.img.destWidth,i=e.img.destHeight,i=.5<=(n=parseFloat(n.value)/(i/r))%1||n%1<=-.5?Math.round(n):n<0?Math.ceil(n):Math.floor(n),r=O.getComponent(t,"numerictextbox"),n=O.getComponent(t,"numerictextbox"),o)&&(null==i||isNaN(i)?O.isNullOrUndefined(r.value)?(r.placeholder="0 px",t.placeholder="0 px",O.isNullOrUndefined(n.value)&&!O.isNullOrUndefined(n.placeholder)&&(r.placeholder=""+e.img.srcWidth,t.placeholder=""+e.img.srcWidth)):(r.value=0,t.value="0 px"):O.isNullOrUndefined(r.value)?(r.placeholder=i+" px",t.placeholder=i.toString()+" px"):(r.value=i,t.value=i.toString()+" px"))},Y.prototype.heightAspectRatio=function(e){var t,o,i,r,n;109!==e.keyCode&&(o=(e=this.parent).element.id,t=e.element.querySelector("#"+o+"_resizeHeight"),n=e.element.querySelector("#"+o+"_resizeWidth"),o=e.element.querySelector("#"+o+"_aspectratio"),r=e.img.destWidth,i=e.img.destHeight,i=.5<=(r=parseFloat(n.value)/(r/i))%1||r%1<=-.5?Math.round(r):r<0?Math.ceil(r):Math.floor(r),r=O.getComponent(t,"numerictextbox"),n=O.getComponent(n,"numerictextbox"),o)&&(isNaN(i)?O.isNullOrUndefined(r.value)?(r.placeholder="0 px",t.placeholder="0 px",O.isNullOrUndefined(n.value)&&!O.isNullOrUndefined(n.placeholder)&&(r.placeholder=""+e.img.srcHeight,t.placeholder=""+e.img.srcHeight)):(r.value=0,t.value="0 px"):O.isNullOrUndefined(r.value)?(r.placeholder=i+" px",t.placeholder=i.toString()+" px"):(r.value=i,t.value=i.toString()+" px"))},Y.prototype.getResizeToolbarItem=function(){var e=this.parent,t=e.element.id,o=!(!e.aspectWidth||!e.aspectHeight),i=(this.parent.transform.degree%90==0&&this.parent.transform.degree%180!=0?Math.ceil(this.parent.img.srcHeight):Math.ceil(this.parent.img.srcWidth)).toString(),r=(this.parent.transform.degree%90==0&&this.parent.transform.degree%180!=0?Math.ceil(this.parent.img.srcWidth):Math.ceil(this.parent.img.srcHeight)).toString(),n=[],a=document.createElement("span"),a=(a.innerHTML=this.l10n.getConstant("W"),n.push({id:t+"_width",cssClass:"e-ie-resize-width",template:a,align:"Center"}),n.push({id:t+"_resizeWidth",prefixIcon:"e-icons e-anti-clock-wise",tooltipText:this.l10n.getConstant("Width"),align:"Center",type:"Input",template:new g.NumericTextBox({width:75,htmlAttributes:{maxLength:"4"},showSpinButton:!1,value:o?e.aspectWidth:null,placeholder:o?null:i,format:"###.## px"})}),document.createElement("span"));return a.innerHTML=this.l10n.getConstant("H"),n.push({id:t+"_height",cssClass:"e-ie-resize-height",template:a,align:"Center"}),n.push({id:t+"_resizeHeight",prefixIcon:"e-icons e-clock-wise",tooltipText:this.l10n.getConstant("Height"),align:"Center",type:"Input",template:new g.NumericTextBox({width:75,htmlAttributes:{maxLength:"4"},showSpinButton:!1,value:o?e.aspectHeight:null,placeholder:o?null:r,format:"###.## px"})}),this.isAspectRatio?(n.push({id:t+"_nonaspectratio",prefixIcon:"e-icons e-unlock",align:"Center",tooltipText:this.l10n.getConstant("AspectRatio"),type:"Button"}),this.isAspectRatio=!1):(n.push({id:t+"_aspectratio",prefixIcon:"e-icons e-lock",align:"Center",tooltipText:this.l10n.getConstant("AspectRatio"),type:"Button"}),this.isAspectRatio=!0),O.Browser.isDevice||(n.push({id:t+"_ok",prefixIcon:"e-icons e-check",cssClass:"top-icon e-tick",tooltipText:this.l10n.getConstant("OK"),align:"Right"}),n.push({id:t+"_cancel",prefixIcon:"e-icons e-close",cssClass:"top-icon e-save",tooltipText:this.l10n.getConstant("Cancel"),align:"Right"})),n},Y.prototype.initResizeToolbar=function(){var e=this,t=this.parent,o=t.element.id,i=this.getLeftToolbarItem(!1,!0),r=this.getRightToolbarItem(),n=this.getResizeToolbarItem(),a=this.getZoomToolbarItem(),i=(O.Browser.isDevice?this.defToolbarItems=n:this.defToolbarItems=i.concat(a,n,r),{toolbarType:"resize",toolbarItems:this.defToolbarItems}),s=(t.trigger("toolbarUpdating",i),this.defToolbarItems=i.toolbarItems,new d.Toolbar({width:"100%",items:this.defToolbarItems,clicked:this.defToolbarClicked.bind(this),created:function(){e.wireResizeBtnEvents(),t.trigger("toolbarCreated",{toolbarType:"shapes"}),O.Browser.isDevice?0<e.defToolbarItems.length&&!O.isNullOrUndefined(document.getElementById(o+"_bottomToolbar"))&&s.refreshOverflow():(e.createLeftToolbarControls(),0<e.defToolbarItems.length&&!O.isNullOrUndefined(document.getElementById(o+"_toolbar"))&&s.refreshOverflow())}}));O.Browser.isDevice?s.appendTo("#"+o+"_bottomToolbar"):s.appendTo("#"+o+"_toolbar"),t.isResize=!1,this.enableDisableTbrBtn(),t.isResize=!0,t.notify("transform",{prop:"disableZoomOutBtn",value:{isZoomOut:!0}})},Y.prototype.wireResizeBtnEvents=function(){var e=this.parent,t=e.element.id,o=e.element.querySelector("#"+t+"_resizeHeight"),e=e.element.querySelector("#"+t+"_resizeWidth");O.isNullOrUndefined(o)||(o.addEventListener("keydown",this.widthPress.bind(this)),e.addEventListener("keyup",this.heightAspectRatio.bind(this))),O.isNullOrUndefined(e)||(e.addEventListener("keydown",this.heightPress.bind(this)),o.addEventListener("keyup",this.widthAspectRatio.bind(this)))},Y.prototype.enableDisableTbrBtn=function(){var e=this.parent,t=e.element.id,o=(this.preventEnableDisableUr||(e.notify("undo-redo",{prop:"getAppliedUndoRedoColl",value:{obj:o={appliedUndoRedoColl:[]}}}),e.notify("undo-redo",{prop:"getUndoRedoStep",value:{obj:i={undoRedoStep:null}}}),(r=e.element.querySelector("#"+t+"_undo"))&&0===i.undoRedoStep?(r.classList.add("e-disabled"),r.parentElement.classList.add("e-overlay")):r&&0<i.undoRedoStep&&(r.classList.remove("e-disabled"),r.parentElement.classList.remove("e-overlay")),(r=e.element.querySelector("#"+t+"_redo"))&&i.undoRedoStep===o.appliedUndoRedoColl.length?(r.classList.add("e-disabled"),r.parentElement.classList.add("e-overlay")):(r&&0===i.undoRedoStep&&0<o.appliedUndoRedoColl.length||r&&0<i.undoRedoStep)&&(r.classList.remove("e-disabled"),r.parentElement.classList.remove("e-overlay"))),document.querySelector("#"+t+"_zoomIn")),i=(o&&e.zoomSettings.zoomFactor>=e.zoomSettings.maxZoomFactor?(o.classList.add("e-disabled"),o.parentElement.classList.add("e-overlay")):o&&(o.classList.remove("e-disabled"),o.parentElement.classList.remove("e-overlay")),document.querySelector("#"+t+"_zoomOut")),r=(i&&e.zoomSettings.zoomFactor<=e.zoomSettings.minZoomFactor?(i.classList.add("e-disabled"),i.parentElement.classList.add("e-overlay")):i&&(i.classList.remove("e-disabled"),i.parentElement.classList.remove("e-overlay")),document.querySelector("#"+t+"_frame"));r&&(e.currSelectionPoint&&"crop-circle"===e.currSelectionPoint.shape||e.isCircleCrop)?r.classList.add("e-disabled"):r&&r.classList.remove("e-disabled")},Y.prototype.createLeftToolbarControls=function(){var e,t=this.parent,o=t.element.id;void 0!==this.defToolbarItems&&0<this.defToolbarItems.length&&document.getElementById(o+"_toolbar")&&(o=document.getElementById(o+"_toolbar").querySelector(".e-image-upload"))&&(e=o.getElementsByTagName("input")[0],(o=o.getElementsByTagName("button")[0]).className="e-tbar-btn e-tbtn-txt top-icon",o.innerHTML="",o.appendChild(t.createElement("span",{className:"e-btn-icon e-icons e-upload-icon e-icon-left"})),e.onchange=this.fileSelect.bind(this,e))},Y.prototype.fileSelect=function(e,t){var o=e.files[0].type.split("/")[1];this.fileName=e.files[0].name.split(".")[0],this.parent.notify("toolbar",{prop:"setInitialSize",value:{value:e.files[0].size}}),-1<["png","jpg","jpeg","svg","svg+xml"].indexOf(o)?this.parent.notify("draw",{prop:"fileSelect",value:{inputElement:e,args:t}}):this.parent.showDialogPopup()},Y.prototype.triggerTbarClickEvent=function(e){e={item:e.item,originalEvent:e.event};this.parent.trigger("toolbarItemClicked",e)},Y.prototype.renderAnnotationBtn=function(e){var s=this,l=this.parent,t=!1,o=[],p=l.element.id,i=["Ellipse","Arrow","Line","Rectangle","Pen","Path","Text","Image"];if(l.toolbar)for(var r=0;r<i.length;r++)if(-1!==l.toolbar.indexOf(i[r])){t=!0;break}(O.isNullOrUndefined(l.toolbar)||!t||l.toolbar&&-1<l.toolbar.indexOf("Pen"))&&o.push({text:this.l10n.getConstant("Pen"),id:"pen",iconCss:"e-icons e-free-pen"}),(O.isNullOrUndefined(l.toolbar)||!t||l.toolbar&&-1<l.toolbar.indexOf("Line"))&&o.push({text:this.l10n.getConstant("Line"),id:"line",iconCss:"e-icons e-line"}),(O.isNullOrUndefined(l.toolbar)||!t||l.toolbar&&-1<l.toolbar.indexOf("Rectangle"))&&o.push({text:this.l10n.getConstant("Rectangle"),id:"rectangle",iconCss:"e-icons e-rectangle"}),(O.isNullOrUndefined(l.toolbar)||!t||l.toolbar&&-1<l.toolbar.indexOf("Ellipse"))&&o.push({text:this.l10n.getConstant("Ellipse"),id:"ellipse",iconCss:"e-icons e-circle"}),(O.isNullOrUndefined(l.toolbar)||!t||l.toolbar&&-1<l.toolbar.indexOf("Arrow"))&&o.push({text:this.l10n.getConstant("Arrow"),id:"arrow",iconCss:"e-icons e-arrow-right-up"}),(O.isNullOrUndefined(l.toolbar)||!t||l.toolbar&&-1<l.toolbar.indexOf("Path"))&&o.push({text:this.l10n.getConstant("Path"),id:"path",iconCss:"e-icons e-critical-path"}),(O.isNullOrUndefined(l.toolbar)||!t||l.toolbar&&-1<l.toolbar.indexOf("Text"))&&o.push({text:this.l10n.getConstant("Text"),id:"text",iconCss:"e-icons e-add-text"}),(O.isNullOrUndefined(l.toolbar)||!t||l.toolbar&&-1<l.toolbar.indexOf("Image"))&&o.push({text:this.l10n.getConstant("Image"),id:"image",iconCss:"e-icons e-image"});var n={freehandDrawSelectedId:null},a=(l.notify("freehand-draw",{prop:"getFreehandDrawSelectedId",onPropertyChange:!1,value:{obj:n}}),document.querySelector("#"+p+"_duplicate")),h=document.querySelector("#"+p+"_remove"),d=document.querySelector("#"+p+"_editText"),c=document.querySelector("#"+p+"_zOrderBtn"),n=(0===l.activeObj.activePoint.width&&0===l.activeObj.activePoint.height&&(O.isNullOrUndefined(l.activeObj.pointColl)||l.activeObj.pointColl&&0===l.activeObj.pointColl.length)&&O.isNullOrUndefined(n.freehandDrawSelectedId)?(a&&a.classList.add("e-disabled"),h&&h.classList.add("e-disabled"),d&&d.classList.add("e-disabled"),c&&c.classList.add("e-disabled")):(a&&a.classList.remove("e-disabled"),h&&h.classList.remove("e-disabled"),d&&d.classList.remove("e-disabled"),c&&c.classList.remove("e-disabled")),e?this.getCurrentShapeIcon(l.activeObj.shape):"e-annotation"),u=new f.DropDownButton({items:o,iconCss:"e-icons "+n,cssClass:"e-image-popup",open:function(e){l.currObjType.isFiltered&&(l.okBtn(),l.element.querySelector("#"+p+"_annotationBtn").click()),O.Browser.isDevice&&(e.element.parentElement.style.top=u.element.getBoundingClientRect().top-e.element.parentElement.offsetHeight+"px"),l.activeObj.shape?document.getElementById(l.activeObj.shape).classList.add("e-selected"):l.togglePen&&document.getElementById("pen").classList.add("e-selected")},select:function(e){l.noPushUndo=!1,s.triggerTbarClickEvent(e),l.okBtn();var t,o,i=!1,r=((void 0===(a=void 0!==l.activeObj.shape?l.activeObj.shape.split("-"):a)&&l.currObjType.isCustomCrop||void 0!==a&&"crop"===a[0])&&(i=!0),l.currObjType.isCustomCrop=!1,(i||l.togglePan)&&(l.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),s.upperContext.clearRect(0,0,l.upperCanvas.width,l.upperCanvas.height),s.refreshToolbar("main")),{currentFreehandDrawIndex:null}),n=(l.notify("freehand-draw",{prop:"getCurrentFreehandDrawIndex",value:{obj:r}}),{shapeSettingsObj:{}});switch(u.iconCss="e-icons "+s.getCurrentShapeIcon(e.item.id),l.notify("draw",{prop:"updateTempObjColl"}),l.notify("draw",{prop:"updateTempPointColl"}),e.item.id){case"pen":l.drawingShape=null,l.notify("draw",{prop:"setTempFreehandCounter",value:{tempFreehandCounter:l.freehandCounter}}),l.notify("draw",{prop:"setTempCurrentFreehandDrawIndex",value:{tempCurrentFreehandDrawIndex:r.currentFreehandDrawIndex}}),s.currentToolbar="pen",l.freeHandDraw(!0),l.notify("selection",{prop:"updatePrevShapeSettings",onPropertyChange:!1,value:{obj:n}}),(t=n.shapeSettingsObj).type=v.ShapeType.FreehandDraw,l.notify("freehand-draw",{prop:"triggerShapeChanging",value:{shapeChangingArgs:o={cancel:!1,action:"insert",previousShapeSettings:t,currentShapeSettings:t}}});break;case"text":s.currentToolbar="text",l.drawingShape=e.item.id,s.currentToolbar="text",s.setInitialShapeSettings(e),l.notify("selection",{prop:"annotate",value:{shape:e.item.id}}),l.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"text",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}});break;case"image":l.drawingShape=null,s.currentToolbar="shapes",l.element.querySelector("#"+p+"_fileUpload").click();break;case"ellipse":case"arrow":case"line":case"rectangle":case"path":l.drawingShape=e.item.id,s.currentToolbar="shapes",s.setInitialShapeSettings(e),l.notify("selection",{prop:"annotate",value:{shape:e.item.id}}),l.notify("toolbar",{prop:"refresh-toolbar",onPropertyChange:!1,value:{type:"shapes",isApplyBtn:null,isCropping:null,isZooming:null,cType:null}}),l.notify("selection",{prop:"updatePrevShapeSettings",onPropertyChange:!1,value:{obj:n}}),l.trigger("shapeChanging",o={cancel:!1,action:"insert",previousShapeSettings:t=n.shapeSettingsObj,currentShapeSettings:t}),l.notify("shape",{prop:"updateShapeChangeEventArgs",value:{shapeSettings:o.currentShapeSettings}})}s.updateToolbarItems();var a=l.togglePen;"pen"===e.item.id&&(l.togglePen=!1),l.notify("draw",{prop:"redrawDownScale"}),l.togglePen=a}});u.appendTo("#"+p+"_annotationBtn")},Y.prototype.renderStraightenSlider=function(){var e=this.parent,t=e.element.id;(O.isNullOrUndefined(e.toolbar)||e.toolbar&&-1<e.toolbar.indexOf("Straightening"))&&e.element.querySelector("#"+t+"_straightenSlider")&&((e=this.createSlider(-45,45,e.cropObj.straighten,"straighten")).appendTo("#"+t+"_straightenSlider"),t=e.element.querySelector(".e-handle"))&&!O.Browser.isDevice&&(t.addEventListener("mousedown",function(e){e.preventDefault(),e.stopPropagation()}),t.addEventListener("touchstart",function(e){e.preventDefault(),e.stopPropagation()}))},Y.prototype.renderCropBtn=function(e){var t,o=this,i=this.parent,r=[],n=!1,a=["CustomSelection","CircleSelection","SquareSelection","RatioSelection"];if(i.toolbar)for(var s=0;s<a.length;s++)if(-1!==i.toolbar.indexOf(a[s])){n=!0;break}(O.isNullOrUndefined(i.toolbar)||!n||i.toolbar&&-1<i.toolbar.indexOf("CustomSelection"))&&r.push({text:this.l10n.getConstant("Custom"),id:"custom",iconCss:"e-icons e-custom"}),(O.isNullOrUndefined(i.toolbar)||!n||i.toolbar&&-1<i.toolbar.indexOf("CircleSelection"))&&r.push({text:this.l10n.getConstant("Circle"),id:"circle",iconCss:"e-icons e-circle"}),(O.isNullOrUndefined(i.toolbar)||!n||i.toolbar&&-1<i.toolbar.indexOf("SquareSelection"))&&r.push({text:this.l10n.getConstant("Square"),id:"square",iconCss:"e-icons e-square"}),(O.isNullOrUndefined(i.toolbar)||!n||i.toolbar&&-1<i.toolbar.indexOf("RatioSelection"))&&(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 e=e?(t=this.getCurrentShapeIcon(e),e):i.activeObj.shape&&(0!==i.activeObj.activePoint.width||0!==i.activeObj.activePoint.height)||"path"===i.activeObj.shape&&0<i.activeObj.pointColl.length?(t=this.getCurrentShapeIcon(i.activeObj.shape),i.activeObj.shape):i.currSelectionPoint?(t=this.getCurrentShapeIcon(i.currSelectionPoint.shape),i.currSelectionPoint.shape):(t=r[0].iconCss,r[0].id),l=new f.DropDownButton({open:function(e){i.togglePan&&o.cancelPan(),O.Browser.isDevice&&(e.element.parentElement.style.top=l.element.getBoundingClientRect().top-e.element.parentElement.offsetHeight+"px"),i.activeObj.shape&&1<i.activeObj.shape.split("-").length&&(e=document.getElementById(i.activeObj.shape.split("-")[1]))&&(e.classList.add("e-selected"),e.focus()),i.notify("transform",{prop:"disableZoomOutBtn",value:{isZoomOut:!0}})},items:r,select:function(e){o.triggerTbarClickEvent(e),o.cropSelect(e),l.iconCss="e-icons "+o.getCurrentShapeIcon("crop-"+e.item.id),l.content=O.Browser.isDevice?null:i.toPascalCase(e.item.id)},iconCss:"e-icons "+t,cssClass:"e-image-popup e-ie-crop-ddb-popup",content:O.Browser.isDevice?null:i.toPascalCase(e.replace("crop-",""))});l.appendTo("#"+i.element.id+"_cropBtn")},Y.prototype.renderTransformBtn=function(){var t=this,o=this.parent,e=[],i=((O.isNullOrUndefined(o.toolbar)||o.toolbar&&-1<o.toolbar.indexOf("RotateLeft"))&&e.push({text:this.l10n.getConstant("RotateLeft"),id:"rotateleft",iconCss:"e-icons e-anti-clock-wise"}),(O.isNullOrUndefined(o.toolbar)||o.toolbar&&-1<o.toolbar.indexOf("RotateRight"))&&e.push({text:this.l10n.getConstant("RotateRight"),id:"rotateright",iconCss:"e-icons e-clock-wise"}),(O.isNullOrUndefined(o.toolbar)||o.toolbar&&-1<o.toolbar.indexOf("FlipHorizontal"))&&e.push({text:this.l10n.getConstant("HorizontalFlip"),id:"horizontalflip",iconCss:"e-icons e-horizontal-flip"}),(O.isNullOrUndefined(o.toolbar)||o.toolbar&&-1<o.toolbar.indexOf("FlipVertical"))&&e.push({text:this.l10n.getConstant("VerticalFlip"),id:"verticalflip",iconCss:"e-icons e-vertical-flip"}),new f.DropDownButton({open:function(e){var t;O.Browser.isDevice&&(t=(e=e.element.parentElement).offsetHeight,e.style.display="none",e.style.top=i.element.getBoundingClientRect().top-t+"px",e.style.display="block")},items:e,select:function(e){t.triggerTbarClickEvent(e),o.transformSelect.bind(t)},iconCss:"e-icons e-transform",cssClass:"e-image-popup"}));i.appendTo("#"+o.element.id+"_transformBtn")},Y.prototype.saveDialogPopup=function(){var i=this,e=this.parent,r=e.element.id,t=(e.element.appendChild(e.createElement("div",{id:r+"_saveDialog"})),e.createElement("div",{id:r+"_dialogContent",attrs:{style:"display: flex;"}})),o=t.appendChild(e.createElement("div",{id:r+"_dialogImgContent",className:"e-ie-dlg-img-content"}));o.appendChild(e.createElement("canvas",{id:r+"_imgPic",className:"e-ie-img-dlg-canvas"}));o.appendChild(e.createElement("div",{id:r+"_imageNameContainer",className:"e-ie-img-size"})).appendChild(e.createElement("span",{id:r+"_imageNameLabel",className:"e-ie-quality-info"}));var o=t.appendChild(e.createElement("div",{id:r+"_dialogRightContent",className:"e-ie-dlg-right-content"})),n=o.appendChild(e.createElement("div",{id:r+"_namediv",className:"e-ie-img-save-name"})),n=(n.appendChild(e.createElement("span",{id:r+"_labelImgname",className:"e-ie-img-label-name",innerHTML:this.l10n.getConstant("ImageName")})),n.appendChild(e.createElement("input",{id:r+"_imgNametext",className:"e-ie-img-input",attrs:{type:"text"}})),o.appendChild(e.createElement("div",{id:r+"_imgNamediv",className:"e-ie-img-save-dlg"}))),n=(n.appendChild(e.createElement("span",{id:r+"_labelname",className:"e-ie-img-label-name",innerHTML:this.l10n.getConstant("Format")})),n.appendChild(e.createElement("button",{id:r+"_saveDropdownbtn",attrs:{tabindex:"1"}})),o.appendChild(e.createElement("div",{id:r+"_imgQualitydiv",className:"e-ie-img-quality-name"}))),o=e.createElement("div",{id:r+"_qualityContainer"});o.appendChild(e.createElement("span",{id:r+"_qualityLabel",className:"e-ie-img-quality-label",innerHTML:this.l10n.getConstant("Quality")})),o.appendChild(e.createElement("span",{id:r+"_qualityInfo",className:"e-circle-info e-icons e-ie-quality-span",attrs:{title:this.l10n.getConstant("QualityInfo")}}));o.appendChild(e.createElement("div",{id:r+"_imgsizeSpan",className:"e-ie-img-size-value-span"})).appendChild(e.createElement("span",{id:r+"_imgsizeValueSpan",className:""})),n.appendChild(o);var o=e.createElement("div",{id:r+"_qualityOptionContainer",className:"e-ie-quality-option-container"}),a=n.appendChild(e.createElement("div",{id:r+"_qualityButtonGroup",className:"e-btn-group"})),s=(["Good","Great","Highest"].forEach(function(e){var t=document.createElement("input"),o=(t.type="radio",t.id=r+"_"+e.toLowerCase(),t.name="quality",t.value=e.toLowerCase(),document.createElement("label"));o.className="e-btn",o.htmlFor=e.toLowerCase(),o.textContent=i.l10n.getConstant(e),a.appendChild(t),a.appendChild(o)}),o.appendChild(a),o.appendChild(e.createElement("div",{id:r+"_qualitySlider",className:"e-ie-img-quality-slider"})),o.appendChild(e.createElement("button",{id:r+"_qualitybuttonIcon",className:"e-ie-img-icon-button",attrs:{type:"button"}})),n.appendChild(o),O.Browser.isDevice&&n.appendChild(e.createElement("span",{id:r+"_qualitySize",className:"e-ie-img-quality-size"})),e.element.querySelector("#"+r+"_saveDialog").style.display="block",e.element.appendChild(t),new u.Dialog({target:e.element,header:this.l10n.getConstant("SaveAs"),closeOnEscape:!0,content:document.getElementById(r+"_dialogContent"),width:O.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(){s.hide()},buttonModel:{content:this.l10n.getConstant("Close"),cssClass:"e-save-cancel-btn"}},{click:function(){i.download(),s.hide(),i.isSlider=!1},buttonModel:{isPrimary:!0,content:this.l10n.getConstant("Download"),cssClass:"e-flat e-save-download-btn"}}]}));s.appendTo("#"+r+"_saveDialog")},Y.prototype.saveDialogClosed=function(e){O.getComponent(document.getElementById(e+"_saveDropdownbtn"),"dropdownbutton")&&O.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(),O.getComponent(document.getElementById(e+"_saveDialog"),"dialog").destroy(),document.getElementById(e+"_saveDialog").remove()},Y.prototype.onBeforeopen=function(){var t=this,e=this.parent,o=e.element.id,i={canvas:null},r=(new g.TextBox({placeholder:this.l10n.getConstant("ImageName")}).appendTo("#"+o+"_imgNametext"),document.getElementById(o+"_imgQualitydiv")),n=document.getElementById(o+"_qualitySlider"),a=document.querySelector("#"+o+"_qualityButtonGroup"),s=document.querySelector("#"+o+"_qualitybuttonIcon"),l=document.querySelector("#"+o+"_imgsizeSpan"),p=O.Browser.isDevice?document.getElementById(o+"_qualitySize"):document.getElementById(o+"_imageNameLabel"),h={fileName:"",fileType:""},e=(e.notify("draw",{prop:"getFileName",onPropertyChange:!1,value:{obj:h}}),this.fileType=h.fileType,e.notify("export",{prop:"exportToCanvas",value:{object:i}}),i.canvas),d=document.getElementById(o+"_imgPic");d.width=e.width,d.height=e.height;new L.Button({iconCss:"e-icons e-settings"}).appendTo("#"+o+"_qualitybuttonIcon");var c,u,d=document.getElementById(o+"_saveDropdownbtn");d&&((c=document.createElement("span")).innerHTML=h.fileType.toUpperCase(),d&&d.appendChild(c),(u=new f.DropDownButton({items:[{id:"jpeg",text:"JPEG"},{id:"png",text:"PNG"},{id:"svg",text:"SVG"}],open:function(e){O.Browser.isDevice&&(e.element.parentElement.style.top=u.element.getBoundingClientRect().top-e.element.parentElement.offsetHeight+"px");var t=c.innerHTML;""!==t&&e.element.querySelector('[aria-label = "'+t+'"]').classList.add("e-selected-btn")},select:function(e){l.style.display="none",t.fileType=c.innerHTML=e.item.text,"jpeg"!==e.item.id?(r.style.display="none",p.style.display="block",1e3<t.initialSize?(e=t.initialSize/1048576,p.innerHTML=t.l10n.getConstant("ImageSize")+": "+e.toFixed(2)+" MB"):p.innerHTML=t.l10n.getConstant("ImageSize")+": "+t.initialSize.toFixed(2)+" KB",n&&(t.isSlider&&O.getComponent(n,"slider").destroy(),n.style.display="none"),t.isSlider=!1):(r.style.display="block",O.removeClass([a],"e-hide"),n.style.display="none",p.style.display="block",t.updateImageSize(O.isNullOrUndefined(t.currentQuality)?1:t.currentQuality,i.canvas),document.getElementById(o+"_"+t.imageQuality).checked=!0)}})).appendTo("#"+o+"_saveDropdownbtn"),document.getElementById(o+"_imgNametext").value=this.fileName||h.fileName,"JPEG"!==h.fileType.toUpperCase()&&(r.style.display="none",l.style.display="none"),O.Browser.isDevice&&(document.getElementById(o+"_dialogImgContent").style.display="none",document.getElementById(o+"_dialogRightContent").style.width="100%"),this.updateImageSize(1,i.canvas)),document.getElementById(o+"_"+this.imageQuality).checked=!0,a.addEventListener("click",this.qualityBtnClickHandler.bind(this)),s.addEventListener("click",this.qualityBtnClickHandler.bind(this))},Y.prototype.qualityBtnClickHandler=function(e){var t=this,o=this.parent,i=o.element.id,r=e.target,n={canvas:null},a={Good:.8,Great:.9,Highest:1},s=document.querySelector("#"+i+"_qualityButtonGroup"),l=document.querySelector("#"+i+"_qualitySlider"),p=document.querySelector("#"+i+"_qualityOptionContainer"),h=document.querySelector("#"+i+"_imgsizeSpan"),d=document.querySelector("#"+i+"_imgsizeValueSpan");o.notify("draw",{prop:"getFileName",onPropertyChange:!1,value:{obj:{fileName:""}}}),o.notify("export",{prop:"exportToCanvas",value:{object:n}}),e.currentTarget.id!==i+"_qualitybuttonIcon"||this.isSlider?e.currentTarget.id===i+"_qualitybuttonIcon"&&this.isSlider?(O.getComponent(l,"slider").destroy(),l.style.display="none",h.style.display="none",O.removeClass([s],"e-hide"),p.style.display="block",this.isSlider=!1):a.hasOwnProperty(r.textContent)&&!this.isSlider&&(e.target.previousElementSibling.checked=!0,this.currentQuality=a[r.textContent],this.imageQuality=r.textContent.toLowerCase(),this.updateImageSize(a[r.textContent],n.canvas)):(O.addClass([s],"e-hide"),l.style.display="block",h.style.display="inline-block",p.style.display="flex",(e=new g.Slider({tooltip:{placement:"Before",isVisible:!0,format:"P0",showOn:"Focus"},min:.01,max:1,step:.01,value:this.currentQuality,type:"MinRange",width:O.Browser.isDevice?"80%":"190px",created:function(){t.updateImageSize(t.currentQuality,n.canvas),d.innerHTML=Math.round(100*t.currentQuality).toString()},changed:function(e){t.currentQuality=e.value,d.innerHTML=Math.round(100*t.currentQuality).toString(),o.notify("export",{prop:"setImageQuality",value:{value:e.value}}),t.updateImageSize(e.value,n.canvas)}})).appendTo("#"+i+"_qualitySlider"),e.element.parentElement.classList.add("e-ie-quality-slider"),this.isSlider=!0)},Y.prototype.updateImageSize=function(e,t){var i,o=this.parent.element.id,r=document.getElementById(o+"_imgPic"),n=r.getContext("2d"),a=O.Browser.isDevice?document.getElementById(o+"_qualitySize"):document.getElementById(o+"_imageNameLabel");t.toBlob(function(e){var t,o;i=1e3<(i=Math.floor(e.size/1024))?(t=i/1024,a.innerHTML="Image size: "+t.toFixed(2)+" MB",+t.toFixed(2)):(a.innerHTML="Image size: "+i.toFixed(2)+" KB",+i.toFixed(2)),O.Browser.isDevice?r.style.display="none":((o=new Image).src=URL.createObjectURL(e),o.onload=function(){n.drawImage(o,0,0),URL.revokeObjectURL(o.src)}),this.fileSize=i}.bind(this),"image/jpeg",e)},Y.prototype.download=function(){var e=this.parent,t=e.element.id,o=("JPEG"===this.fileType&&this.isSlider?(o=O.getComponent(document.getElementById(t+"_qualitySlider"),"slider").value,e.notify("export",{prop:"setImageQuality",value:{value:o}})):e.notify("export",{prop:"setImageQuality",value:{value:this.currentQuality}}),document.getElementById(t+"_imgNametext").value);e.export(this.fileType,o)},Y.prototype.getCropTransformToolbarItem=function(){var e,t=this.parent,o=t.element.id,i=[];return i.push({id:o+"_crop",tooltipText:this.l10n.getConstant("CropSelection"),align:"Center",template:'<button id="'+o+'_cropBtn"></button>'}),i.push({align:"Center",type:"Separator"}),(O.isNullOrUndefined(t.toolbar)||t.toolbar&&(-1<t.toolbar.indexOf("Transform")||-1<t.toolbar.indexOf("RotateLeft")))&&i.push({id:o+"_rotateLeft",prefixIcon:"e-icons e-anti-clock-wise",tooltipText:this.l10n.getConstant("RotateLeft"),align:"Center"}),(O.isNullOrUndefined(t.toolbar)||t.toolbar&&(-1<t.toolbar.indexOf("Transform")||-1<t.toolbar.indexOf("RotateRight")))&&i.push({id:o+"_rotateRight",prefixIcon:"e-icons e-clock-wise",tooltipText:this.l10n.getConstant("RotateRight"),align:"Center"}),2<i.length&&i.push({align:"Center",type:"Separator"}),(O.isNullOrUndefined(t.toolbar)||t.toolbar&&(-1<t.toolbar.indexOf("Transform")||-1<t.toolbar.indexOf("HorizontalFlip")))&&i.push({id:o+"_horizontalFlip",prefixIcon:"e-icons e-horizontal-flip",tooltipText:this.l10n.getConstant("HorizontalFlip"),align:"Center"}),(O.isNullOrUndefined(t.toolbar)||t.toolbar&&(-1<t.toolbar.indexOf("Transform")||-1<t.toolbar.indexOf("VerticalFlip")))&&i.push({id:o+"_verticalFlip",prefixIcon:"e-icons e-vertical-flip",tooltipText:this.l10n.getConstant("VerticalFlip"),align:"Center"}),(O.isNullOrUndefined(t.toolbar)||t.toolbar&&-1<t.toolbar.indexOf("Straightening"))&&!O.Browser.isDevice&&(i.push({align:"Center",type:"Separator"}),O.isNullOrUndefined(t.toolbar)||t.toolbar&&(-1<t.toolbar.indexOf("Straighten")||-1<t.toolbar.indexOf("Straighten")))&&((e=document.createElement("span")).innerHTML=this.l10n.getConstant("Straighten"),i.push({id:o+"_straightenSpan",cssClass:"e-ie-straighten-span",template:e,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>'}),(e=document.createElement("span")).innerHTML=t.transform.straighten.toString()+"°",i.push({id:o+"_straightenSpan",cssClass:"e-ie-straighten-value-span",template:e,align:"Center"})),O.Browser.isDevice||(i.push({id:o+"_ok",prefixIcon:"e-icons e-check",cssClass:"top-icon e-tick",tooltipText:this.l10n.getConstant("OK"),align:"Right"}),i.push({id:o+"_cancel",prefixIcon:"e-icons e-close",cssClass:"top-icon e-save",tooltipText:this.l10n.getConstant("Cancel"),align:"Right"})),i},Y.prototype.getShapesToolbarItem=function(e){for(var t=this.parent,o=t.element.id,i=[],r=((O.isNullOrUndefined(t.toolbar)||t.toolbar)&&i.push({id:o+"_annotation",tooltipText:this.l10n.getConstant("Annotation"),align:"Center",template:'<button id="'+o+'_annotationBtn"></button>'}),-1<e.indexOf("fillColor")&&i.push({prefixIcon:"e-icons e-copy",id:o+"_fillcolor",cssClass:"top-icon e-fill",tooltipText:this.l10n.getConstant("FillColor"),align:"Center",type:"Input",template:'<button id="'+o+'_fillColorBtn"></button>'}),-1<e.indexOf("strokeColor")&&i.push({prefixIcon:"e-icons e-copy",id:o+"_strokecolor",cssClass:"top-icon e-stroke",tooltipText:this.l10n.getConstant("StrokeColor"),align:"Center",type:"Input",template:'<button id="'+o+'_borderColorBtn"></button>'}),-1<e.indexOf("strokeWidth")&&i.push({id:o+"_strokeWidth",cssClass:"top-icon e-size",tooltipText:"Stroke Width",align:"Center",type:"Input",template:'<button id="'+o+'_borderWidthBtn"></button>'}),-1<e.indexOf("start")&&i.push({id:o+"_start",cssClass:"top-icon e-size",tooltipText:"Start",align:"Center",type:"Input",template:'<button id="'+o+'_startBtn"></button>'}),-1<e.indexOf("end")&&i.push({id:o+"_end",cssClass:"top-icon e-size",tooltipText:"End",align:"Center",type:"Input",template:'<button id="'+o+'_endBtn"></button>'}),-1<e.indexOf("flip")&&(i.push({id:o+"_rotLeft",prefixIcon:"e-anti-clock-wise",tooltipText:this.l10n.getConstant("RotateLeft"),align:"Center"}),i.push({id:o+"_rotRight",prefixIcon:"e-clock-wise",tooltipText:this.l10n.getConstant("RotateRight"),align:"Center"}),i.push({id:o+"_hFlip",prefixIcon:"e-horizontal-flip",tooltipText:this.l10n.getConstant("HorizontalFlip"),align:"Center"}),i.push({id:o+"_vFlip",prefixIcon:"e-vertical-flip",tooltipText:this.l10n.getConstant("VerticalFlip"),align:"Center"})),-1<e.indexOf("transparency")&&(i.push({align:"Center",type:"Separator"}),i.push({id:o+"_transparency",prefixIcon:"e-opacity",tooltipText:this.l10n.getConstant("Opacity"),align:"Center"})),i.push({align:"Center",type:"Separator"}),-1<e.indexOf("z-order")&&i.push({id:o+"_zOrder",cssClass:"top-icon e-list-unordered-3",tooltipText:this.l10n.getConstant("ZOrder"),align:"Center",type:"Input",template:'<button id="'+o+'_zOrderBtn"></button>'}),-1<e.indexOf("duplicate")&&i.push({id:o+"_duplicate",prefixIcon:"e-icons e-order",cssClass:"top-icon e-order",tooltipText:this.l10n.getConstant("Duplicate"),align:"Center"}),-1<e.indexOf("remove")&&i.push({id:o+"_remove",prefixIcon:"e-icons e-trash",cssClass:"top-icon e-trash",tooltipText:this.l10n.getConstant("Remove"),align:"Center"}),-1<e.indexOf("text")&&i.push({id:o+"_editText",prefixIcon:"e-icons e-annotation-edit",cssClass:"top-icon e-annotation-edit",tooltipText:this.l10n.getConstant("EditText"),align:"Center"}),this.processSubToolbar(e)),n=0,a=r.length;n<a;n++)i.push(r[n]);return O.Browser.isDevice||(t.notify("selection",{prop:"getCurrentDrawingShape",value:{obj:e={shape:null}}}),"path"!==e.shape&&(i.push({id:o+"_ok",prefixIcon:"e-icons e-check",cssClass:"top-icon e-tick",tooltipText:this.l10n.getConstant("OK"),align:"Right"}),i.push({id:o+"_cancel",prefixIcon:"e-icons e-close",cssClass:"top-icon e-save",tooltipText:this.l10n.getConstant("Cancel"),align:"Right"}))),i},Y.prototype.initCropTransformToolbar=function(e,t){var o=this,i=this.parent,r=i.element.id,n=this.getLeftToolbarItem(),a=this.getRightToolbarItem(),s=this.getCropTransformToolbarItem(),l=this.getZoomToolbarItem(),n=(O.Browser.isDevice?this.defToolbarItems=s:this.defToolbarItems=n.concat(l,s,a),{toolbarType:"crop-transform",toolbarItems:this.defToolbarItems}),p=(i.trigger("toolbarUpdating",n),this.defToolbarItems=n.toolbarItems,new d.Toolbar({width:"100%",items:this.defToolbarItems,clicked:this.defToolbarClicked.bind(this),created:function(){o.renderCropBtn(e),o.renderStraightenSlider(),o.wireZoomBtnEvents(),i.trigger("toolbarCreated",{toolbarType:"shapes"}),O.Browser.isDevice?0<o.defToolbarItems.length&&document.getElementById(r+"_bottomToolbar")&&(p.refreshOverflow(),p.refreshOverflow(),p.refreshOverflow()):(o.createLeftToolbarControls(),0<o.defToolbarItems.length&&document.getElementById(r+"_toolbar")&&p.refreshOverflow()),document.getElementById(r+"_cropBtn")&&O.isNullOrUndefined(t)&&(O.Browser.isDevice||i.notify("draw",{prop:"select",onPropertyChange:!1,value:{type:o.getCropTextContent(document.getElementById(r+"_cropBtn")).toLowerCase(),startX:null,startY:null,width:null,height:null}}))}})),l=(O.Browser.isDevice?p.appendTo("#"+r+"_bottomToolbar"):p.appendTo("#"+r+"_toolbar"),i.element.querySelector("#"+r+"_straightenSlider"));(O.isNullOrUndefined(i.toolbar)||i.toolbar&&-1<i.toolbar.indexOf("Straightening"))&&l&&l.parentElement.clientHeight>this.toolbarHeight&&(this.toolbarHeight=i.toolbarHeight=l.parentElement.clientHeight),this.enableDisableTbrBtn(),i.notify("transform",{prop:"disableZoomOutBtn",value:{isZoomOut:!0}})},Y.prototype.getCropTextContent=function(e){if(e){var t,o={"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"},i=e.children[0].classList;for(t in o)if(i.contains(t))return o[t]}return""},Y.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]||(e&&-1!==e.indexOf("crop-")?"e-custom":"e-free-pen")},Y.prototype.initShapesToolbarItem=function(e){var t=this,o=this.parent,i=o.element.id,r=this.getLeftToolbarItem(),n=this.getRightToolbarItem(),a=this.getShapesToolbarItem(e),s=this.getZoomToolbarItem(),r=(O.Browser.isDevice?this.defToolbarItems=a:this.defToolbarItems=r.concat(s,a,n),{toolbarType:o.activeObj.shape||"shapes",toolbarItems:this.defToolbarItems}),l=(o.trigger("toolbarUpdating",r),this.isToolbarString(r.toolbarItems)?(e=r.toolbarItems,this.excludeItems(r.toolbarItems)):this.defToolbarItems=r.toolbarItems,new d.Toolbar({width:"100%",items:this.defToolbarItems,clicked:this.defToolbarClicked.bind(this),created:function(){t.renderAnnotationBtn(!0),t.createShapeColor(e),t.createShapeBtn(e),t.createZOrderBtn(e),"arrow"===o.activeObj.shape&&(e.some(function(e){return-1<e.toLowerCase().indexOf("start")})&&t.createStartBtn(),e.some(function(e){return-1<e.toLowerCase().indexOf("end")}))&&t.createEndBtn(),t.wireZoomBtnEvents(),o.trigger("toolbarCreated",{toolbarType:"shapes"}),O.Browser.isDevice?0<t.defToolbarItems.length&&document.getElementById(i+"_bottomToolbar")&&(l.refreshOverflow(),l.refreshOverflow(),l.refreshOverflow()):(t.createLeftToolbarControls(),0<t.defToolbarItems.length&&document.getElementById(i+"_toolbar")&&l.refreshOverflow())}}));O.Browser.isDevice?l.appendTo("#"+i+"_bottomToolbar"):l.appendTo("#"+i+"_toolbar"),this.enableDisableTbrBtn()},Y.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"))},Y.prototype.createShapeColor=function(e){var t,o,i,r,n=this,a=this.parent,s=a.element.id;-1<e.indexOf("fillColor")&&(a.element.querySelector(".e-template.e-fill").appendChild(a.createElement("input",{id:s+"_shape_fill"})),t=new g.ColorPicker({modeSwitcher:!0,noColor:!0,value:"",inline:!0,showButtons:!1,mode:"Palette",cssClass:"e-shape-fill-color",beforeModeSwitch:function(e){return n.beforeModeSwitch(e,t)},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){a.updateFillColor(e.value),""===e.currentValue.rgba?o.element.children[0].classList.add("e-nocolor-item"):(o.element.children[0].classList.remove("e-nocolor-item"),o.element.children[0].style.backgroundColor=e.currentValue.rgba),o.toggle(),a.notify("undo-redo",{prop:"updateUndoRedoStack",onPropertyChange:!1})},onModeSwitch:function(e){O.Browser.isDevice&&(e.element.parentElement.parentElement.style.left=n.popupLeft,e.element.parentElement.parentElement.style.top=o.element.getBoundingClientRect().top-e.element.parentElement.parentElement.offsetHeight+"px")},beforeClose:function(){o.toggle()}},"#"+s+"_shape_fill"),o=new f.DropDownButton({open:function(e){e=e.element.parentElement;O.Browser.isDevice&&(e.style.top=o.element.getBoundingClientRect().top-e.offsetHeight+"px",e.style.left=a.element.offsetLeft+"px")},target:".e-shape-fill-color",iconCss:"e-dropdownbtn-preview",cssClass:"e-ie-ddb-popup"},"#"+s+"_fillColorBtn"),t.inline=!0,t.value=t.getValue(t.value,"rgba"),a.element.querySelector(".e-fill.e-template .e-dropdownbtn-preview").classList.add("e-nocolor-item")),-1<e.indexOf("strokeColor")&&(a.element.querySelector(".e-template.e-stroke").appendChild(a.createElement("input",{id:s+"_shape_stroke"})),i=new g.ColorPicker({modeSwitcher:!0,noColor:!1,value:"#fff",inline:!0,showButtons:!1,mode:"Palette",cssClass:"e-shape-stroke-color",beforeModeSwitch:function(e){n.popupLeft=e.element.offsetParent.style.left,i.value="#fff"!==a.activeObj.strokeSettings.strokeColor?a.activeObj.strokeSettings.strokeColor:"#008000ff",n.beforeModeSwitch(e,i)},presetColors:this.presetColors,change:function(e){a.updateStrokeColor(e.value),r.element.children[0].style.backgroundColor=e.currentValue.rgba,r.toggle(),a.notify("undo-redo",{prop:"updateUndoRedoStack",onPropertyChange:!1})},onModeSwitch:function(e){O.Browser.isDevice&&(e.element.parentElement.parentElement.style.left=n.popupLeft,e.element.parentElement.parentElement.style.top=r.element.getBoundingClientRect().top-e.element.parentElement.parentElement.offsetHeight+"px")},beforeClose:function(){r.toggle()}},"#"+s+"_shape_stroke"),r=new f.DropDownButton({open:function(e){e=e.element.parentElement;O.Browser.isDevice&&(e.style.top=r.element.getBoundingClientRect().top-e.offsetHeight+"px",e.style.left=a.element.offsetLeft+"px")},target:".e-shape-stroke-color",iconCss:"e-dropdownbtn-preview",cssClass:"e-ie-ddb-popup"},"#"+s+"_borderColorBtn"),i.inline=!0,i.value=i.getValue(i.value,"rgba"),a.element.querySelector(".e-stroke.e-template .e-dropdownbtn-preview").style.background="#fff")},Y.prototype.createShapeBtn=function(e){var t,o,i,r=this,n=this.parent,a=n.element.id;-1<e.indexOf("strokeWidth")&&(e=[{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")}],!n.activeObj.shape||"rectangle"!==n.activeObj.shape&&"ellipse"!==n.activeObj.shape||(e=[{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")}]),t=document.getElementById(a+"_borderWidthBtn"),(o=document.createElement("span")).innerHTML=this.l10n.getConstant("XSmall"),o.className="e-shape-stroke-width",t.appendChild(o),(i=new f.DropDownButton({items:e,open:function(e){O.Browser.isDevice&&(e.element.parentElement.style.top=i.element.getBoundingClientRect().top-e.element.parentElement.offsetHeight+"px");var t=o.innerHTML;""!==t&&e.element.querySelector('[aria-label = "'+t+'"]').classList.add("e-selected-btn")},select:function(e){r.triggerTbarClickEvent(e),o.textContent=e.item.text,n.updateStrokeWidth(e.item.id),O.Browser.isDevice?document.getElementById(a+"_bottomToolbar")&&O.getComponent(a+"_bottomToolbar","toolbar").refreshOverflow():document.getElementById(a+"_toolbar")&&O.getComponent(a+"_toolbar","toolbar").refreshOverflow(),n.notify("undo-redo",{prop:"updateUndoRedoStack",onPropertyChange:!1})}})).appendTo("#"+a+"_borderWidthBtn"))},Y.prototype.createZOrderBtn=function(e){var t,o=this,i=this.parent,r=i.element.id;-1<e.indexOf("z-order")&&(e=[{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"}],(t=new f.DropDownButton({items:e,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},o=(i.notify("freehand-draw",{prop:"getFreehandSelectedIndex",onPropertyChange:!1,value:{obj:t}}),{order:null}),t=(i.notify("shape",{prop:"getHighestOrder",onPropertyChange:!1,value:{obj:o}}),i.activeObj.order||i.getObjFromId(i.pointColl[t.freehandSelectedIndex].id).order);t&&o.order<=t?(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}}),t&&t<=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){O.Browser.isDevice&&(e.element.parentElement.style.top=t.element.getBoundingClientRect().top-e.element.parentElement.offsetHeight+"px")},select:function(e){o.triggerTbarClickEvent(e);var t={freehandDrawSelectedId:null},t=(i.notify("freehand-draw",{prop:"getFreehandDrawSelectedId",onPropertyChange:!1,value:{obj:t}}),t.freehandDrawSelectedId||i.activeObj.currIndex);i.updateShapeOrder(t,e.item.id),O.Browser.isDevice?document.getElementById(r+"_bottomToolbar")&&O.getComponent(r+"_bottomToolbar","toolbar").refreshOverflow():document.getElementById(r+"_toolbar")&&O.getComponent(r+"_toolbar","toolbar").refreshOverflow(),-1<t.indexOf("shape")?i.notify("undo-redo",{prop:"updateUndoRedoStack",onPropertyChange:!1}):-1<t.indexOf("pen")&&i.notify("undo-redo",{prop:"updateUndoRedoStack",value:{isPenDraw:!0}})}})).appendTo("#"+r+"_zOrderBtn"))},Y.prototype.createStartBtn=function(){var t=this,o=this.parent,e=o.element.id,i=[{id:"1",text:this.l10n.getConstant("None")},{id:"2",text:this.l10n.getConstant("Bar")},{id:"3",text:this.l10n.getConstant("Arrow")},{id:"4",text:this.l10n.getConstant("ArrowSolid")},{id:"5",text:this.l10n.getConstant("Circle")},{id:"6",text:this.l10n.getConstant("CircleSolid")},{id:"7",text:this.l10n.getConstant("Square")},{id:"8",text:this.l10n.getConstant("SquareSolid")}],r=document.getElementById(e+"_startBtn"),n=document.createElement("span"),a=(O.isNullOrUndefined(o.activeObj.start)&&(o.activeObj.start="none"),n.innerHTML=o.pascalToSplitWords(o.activeObj.start),n.className="e-shape-start",r.appendChild(n),new f.DropDownButton({items:i,open:function(e){O.Browser.isDevice&&(e.element.parentElement.style.top=a.element.getBoundingClientRect().top-e.element.parentElement.offsetHeight+"px");var t=n.innerHTML;""!==t&&e.element.querySelector('[aria-label = "'+t+'"]').classList.add("e-selected-btn")},select:function(e){o.notify("selection",{prop:"setArrowShape",value:{type:"initial",shape:{1:"none",2:"bar",3:"arrow",4:"arrowSolid",5:"circle",6:"circleSolid",7:"square",8:"squareSolid"}[""+e.item.id]}}),t.triggerTbarClickEvent(e),n.textContent=e.item.text,o.updateArrow("startArrow",e.item.id),o.notify("undo-redo",{prop:"updateUndoRedoStack",onPropertyChange:!1})}}));a.appendTo("#"+e+"_startBtn")},Y.prototype.createEndBtn=function(){var t=this,o=this.parent,e=o.element.id,i=[{id:"1",text:this.l10n.getConstant("None")},{id:"2",text:this.l10n.getConstant("Bar")},{id:"3",text:this.l10n.getConstant("Arrow")},{id:"4",text:this.l10n.getConstant("ArrowSolid")},{id:"5",text:this.l10n.getConstant("Circle")},{id:"6",text:this.l10n.getConstant("CircleSolid")},{id:"7",text:this.l10n.getConstant("Square")},{id:"8",text:this.l10n.getConstant("SquareSolid")}],r=document.getElementById(e+"_endBtn"),n=document.createElement("span"),a=(O.isNullOrUndefined(o.activeObj.end)&&(o.activeObj.end="arrowSolid"),n.innerHTML=o.pascalToSplitWords(o.activeObj.end),n.className="e-shape-end",r.appendChild(n),new f.DropDownButton({items:i,open:function(e){O.Browser.isDevice&&(e.element.parentElement.style.top=a.element.getBoundingClientRect().top-e.element.parentElement.offsetHeight+"px");var t=n.innerHTML;""!==t&&e.element.querySelector('[aria-label = "'+t+'"]').classList.add("e-selected-btn")},select:function(e){o.notify("selection",{prop:"setArrowShape",value:{type:"final",shape:{1:"none",2:"bar",3:"arrow",4:"arrowSolid",5:"circle",6:"circleSolid",7:"square",8:"squareSolid"}[""+e.item.id]}}),t.triggerTbarClickEvent(e),n.textContent=e.item.text,o.updateArrow("endArrow",e.item.id),o.notify("undo-redo",{prop:"updateUndoRedoStack",onPropertyChange:!1})}}));a.appendTo("#"+e+"_endBtn")},Y.prototype.getTextToolbarItem=function(e){for(var t=this.parent,o=t.element.id,i=[],r=((O.isNullOrUndefined(t.toolbar)||t.toolbar)&&i.push({id:o+"_annotation",tooltipText:this.l10n.getConstant("Annotation"),align:"Center",template:'<button id="'+o+'_annotationBtn"></button>'}),-1<e.indexOf("fontFamily")&&i.push({id:o+"_fontFamily",cssClass:"top-icon e-img-font-family",tooltipText:this.l10n.getConstant("FontFamily"),align:"Center",template:'<button id="'+o+'_fontFamilyBtn"></button>'}),-1<e.indexOf("fontSize")&&i.push({id:o+"_fontSize",cssClass:"top-icon e-img-font-size",tooltipText:this.l10n.getConstant("FontSize"),align:"Center",template:'<button id="'+o+'_fontSizeBtn"></button>'}),-1<e.indexOf("fontColor")&&i.push({cssClass:"top-icon e-text-font-color",id:o+"_text_strokecolor",tooltipText:this.l10n.getConstant("FontColor"),align:"Center",type:"Input",template:'<button id="'+o+'_fontColorBtn"></button>'}),-1<e.indexOf("bold")&&i.push({id:o+"_bold",prefixIcon:"e-icons e-bold",cssClass:"top-icon e-bold",tooltipText:this.l10n.getConstant("Bold"),align:"Center"}),-1<e.indexOf("italic")&&i.push({id:o+"_italic",prefixIcon:"e-icons e-italic",cssClass:"top-icon e-italic",tooltipText:this.l10n.getConstant("Italic"),align:"Center"}),-1<e.indexOf("transparency")&&i.push({id:o+"_transparency",prefixIcon:"e-opacity",tooltipText:this.l10n.getConstant("Opacity"),align:"Center"}),i.push({align:"Center",type:"Separator"}),-1<e.indexOf("z-order")&&i.push({id:o+"_zOrder",cssClass:"top-icon e-list-unordered-3",tooltipText:this.l10n.getConstant("ZOrder"),align:"Center",type:"Input",template:'<button id="'+o+'_zOrderBtn"></button>'}),-1<e.indexOf("duplicate")&&i.push({id:o+"_duplicate",prefixIcon:"e-icons e-order",cssClass:"top-icon e-order",tooltipText:this.l10n.getConstant("Duplicate"),align:"Center",disabled:"block"===t.textArea.style.display||"inline-block"===t.textArea.style.display}),-1<e.indexOf("remove")&&i.push({id:o+"_remove",prefixIcon:"e-icons e-trash",cssClass:"top-icon e-trash",tooltipText:this.l10n.getConstant("Remove"),align:"Center",disabled:"block"===t.textArea.style.display||"inline-block"===t.textArea.style.display}),-1<e.indexOf("text")&&i.push({id:o+"_editText",prefixIcon:"e-icons e-annotation-edit",cssClass:"top-icon e-annotation-edit",tooltipText:this.l10n.getConstant("EditText"),align:"Center",disabled:"block"===t.textArea.style.display||"inline-block"===t.textArea.style.display}),this.processSubToolbar(e)),n=0,a=r.length;n<a;n++)i.push(r[n]);return O.Browser.isDevice||(i.push({id:o+"_ok",prefixIcon:"e-icons e-check",cssClass:"top-icon e-tick",tooltipText:this.l10n.getConstant("OK"),align:"Right"}),i.push({id:o+"_cancel",prefixIcon:"e-icons e-close",cssClass:"top-icon e-save",tooltipText:this.l10n.getConstant("Cancel"),align:"Right"})),i},Y.prototype.getFontFamilyItems=function(){var e=this.parent;return e.fontFamily&&e.fontFamily.items&&0<e.fontFamily.items.length?e.fontFamily.items:O.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"}]},Y.prototype.initTextToolbarItem=function(e){var t=this,o=this.parent,i=o.element.id,r=this.getLeftToolbarItem(),n=this.getRightToolbarItem(),a=this.getTextToolbarItem(e),s=this.getZoomToolbarItem(),r=(O.Browser.isDevice?this.defToolbarItems=a:this.defToolbarItems=r.concat(s,a,n),{toolbarType:"text",toolbarItems:this.defToolbarItems}),l=(o.trigger("toolbarUpdating",r),this.isToolbarString(r.toolbarItems)?(e=r.toolbarItems,this.excludeItems(r.toolbarItems)):this.defToolbarItems=r.toolbarItems,new d.Toolbar({width:"100%",items:this.defToolbarItems,clicked:this.defToolbarClicked.bind(this),created:function(){t.renderAnnotationBtn(!0),t.createTextColor(e),t.createTextBtn(e),t.createZOrderBtn(e),t.wireZoomBtnEvents(),o.trigger("toolbarCreated",{toolbarType:"text"}),O.Browser.isDevice?0<t.defToolbarItems.length&&document.getElementById(i+"_bottomToolbar")&&(l.refreshOverflow(),l.refreshOverflow(),l.refreshOverflow()):(t.createLeftToolbarControls(),0<t.defToolbarItems.length&&document.getElementById(i+"_toolbar")&&l.refreshOverflow())}}));O.Browser.isDevice?l.appendTo("#"+i+"_bottomToolbar"):l.appendTo("#"+i+"_toolbar"),this.enableDisableTbrBtn()},Y.prototype.createTextColor=function(e){var t,o,i=this,r=this.parent,n=r.element.id;-1<e.indexOf("fontColor")&&r.element.querySelector(".e-template.e-text-font-color")&&(r.element.querySelector(".e-template.e-text-font-color").appendChild(r.createElement("input",{id:n+"_text_font"})),t=new g.ColorPicker({modeSwitcher:!0,noColor:!1,value:"#fff",inline:!0,showButtons:!1,mode:"Palette",cssClass:"e-text-fontt-color",beforeModeSwitch:function(e){i.popupLeft=e.element.offsetParent.style.left,t.value="#fff"!==r.activeObj.strokeSettings.strokeColor?r.activeObj.strokeSettings.strokeColor:"#008000ff",i.beforeModeSwitch(e,t)},presetColors:this.presetColors,change:function(e){r.updateFontColor(e.value),o.element.children[0].style.backgroundColor=e.currentValue.rgba,o.toggle(),0===r.activeObj.activePoint.width&&0===r.activeObj.activePoint.height||r.notify("undo-redo",{prop:"updateUndoRedoStack",onPropertyChange:!1})},onModeSwitch:function(e){O.Browser.isDevice&&(e.element.parentElement.parentElement.style.left=i.popupLeft,e.element.parentElement.parentElement.style.top=o.element.getBoundingClientRect().top-e.element.parentElement.parentElement.offsetHeight+"px")},beforeClose:function(){o.toggle()}},"#"+n+"_text_font"),o=new f.DropDownButton({open:function(e){e=e.element.parentElement;O.Browser.isDevice&&(e.style.top=o.element.getBoundingClientRect().top-e.offsetHeight+"px",e.style.left=r.element.offsetLeft+"px")},target:".e-text-fontt-color",iconCss:"e-dropdownbtn-preview",cssClass:"e-ie-ddb-popup"},"#"+n+"_fontColorBtn"),t.inline=!0,t.value=t.getValue(t.value,"rgba"),r.element.querySelector(".e-text-font-color.e-template .e-dropdownbtn-preview").style.background="#fff")},Y.prototype.createTextBtn=function(e){var t,o,i,r,n,a=this,s=this.parent,l=s.element.id;-1<e.indexOf("fontFamily")&&(i=document.getElementById(l+"_fontFamilyBtn"),t=document.createElement("span"),O.Browser.isDevice?(t.innerHTML="ABC",t.setAttribute("style","font-family: "+s.fontFamily.default.toLowerCase()+"'")):t.innerHTML=s.fontFamily.default,t.className="e-text-font-family",i&&i.appendChild(t),(o=new f.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){O.Browser.isDevice&&(e.element.parentElement.style.top=o.element.getBoundingClientRect().top-e.element.parentElement.offsetHeight+"px"),t=("block"===s.textArea.style.display||"inline-block"===s.textArea.style.display?s.textArea.style:s.activeObj.textSettings).fontFamily;var t,e=e.element.querySelector('[id *= "'+t.toLowerCase()+'"]');e&&e.classList.add("e-selected-btn")},select:function(e){a.triggerTbarClickEvent(e),t.textContent=e.item.text,O.Browser.isDevice&&t.setAttribute("style","font-family:"+e.item.id),s.updateFontFamily(e.item.id),s.notify("undo-redo",{prop:"updateUndoRedoStack",onPropertyChange:!1})}})).appendTo("#"+l+"_fontFamilyBtn")),-1<e.indexOf("fontSize")&&(i=document.getElementById(l+"_fontSizeBtn"),r=document.createElement("span"),e=s.getFontSizes(),r.innerHTML=e[0].text,r.className="e-text-font-size",i.appendChild(r),(n=new f.DropDownButton({cssClass:"e-font-size",items:e,open:function(e){O.Browser.isDevice&&(e.element.parentElement.style.top=n.element.getBoundingClientRect().top-e.element.parentElement.offsetHeight+"px");var t=r.innerHTML;e.element.querySelector('[aria-label *= "'+t+'"]').classList.add("e-selected-btn")},select:function(e){a.triggerTbarClickEvent(e),r.textContent=e.item.text,s.updateFontSize(e.item.text),s.notify("undo-redo",{prop:"updateUndoRedoStack",onPropertyChange:!1})}})).appendTo("#"+l+"_fontSizeBtn"))},Y.prototype.refreshToolbar=function(e,t,o,i,r,n,a){var s=this.parent,l=s.element.id;if(s.isImageLoaded&&!s.isCropToolbar){var p,h,d,c,u={};switch("filter"!==e&&"color"!==e&&(h=document.getElementById(l+"_toolbar"),c=document.getElementById(l+"_customizeWrapper"),d=document.getElementById(l+"_bottomToolbar"),c&&O.getComponent(c,"toolbar")&&0<this.defToolbarItems.length&&(O.getComponent(c,"toolbar").destroy(),c.innerHTML=""),h&&h.classList.contains("e-control")&&0<this.defToolbarItems.length&&(O.getComponent(h,"toolbar").destroy(),h.innerHTML=""),h&&(0<this.defToolbarItems.length||s.toolbar&&0<s.toolbar.length&&-1===s.toolbar.indexOf("Open"))&&(c=O.getComponent(h,"toolbar"),O.isNullOrUndefined(c)||(c.destroy(),document.getElementById(s.element.id+"_toolbar").innerHTML="")),d)&&0<this.defToolbarItems.length&&-1<d.className.indexOf("e-control")&&(O.getComponent(d,"toolbar").destroy(),d.innerHTML=""),this.refreshSlider(),document.querySelector(".e-slider-tooltip")&&document.querySelector(".e-slider-tooltip").remove(),this.isFrameToolbar=s.isCropTab=!1,e){case"main":O.Browser.isDevice?o?this.initMainToolbar(!1,!0,!0,!1,!1,!0):this.initMainToolbar(!1,!0,null,!1,!1,!0):O.Browser.isDevice&&!i||this.initMainToolbar(t,O.Browser.isDevice,null),O.Browser.isDevice&&this.initBottomToolbar();break;case"shapes":s.noPushUndo=!0,O.Browser.isDevice&&this.initMainToolbar(!1,!0,!0),"line"===s.activeObj.shape||"path"===s.activeObj.shape?u.toolbarItems=["strokeColor","strokeWidth","z-order","duplicate","remove"]:"arrow"===s.activeObj.shape?u.toolbarItems=["strokeColor","strokeWidth","start","end","z-order","duplicate","remove"]:"image"===s.activeObj.shape?u.toolbarItems=["flip","z-order","duplicate","remove","transparency"]:u.toolbarItems=["fillColor","strokeColor","strokeWidth","z-order","duplicate","remove"],this.initShapesToolbarItem(u.toolbarItems);break;case"text":O.Browser.isDevice&&this.initMainToolbar(!1,!0,!0),u.toolbarItems=["fontFamily","fontSize","fontColor","bold","italic","z-order","duplicate","remove","text"],this.initTextToolbarItem(u.toolbarItems);break;case"pen":O.Browser.isDevice&&this.initMainToolbar(!1,!0,!0),u.toolbarItems=["strokeColor","strokeWidth","z-order","remove","transparency"],this.initPenToolbarItem(u.toolbarItems);break;case"adjustment":O.Browser.isDevice&&this.initMainToolbar(!1,!0,!0),this.initAdjustmentToolbarItem();break;case"filter":this.updateContextualToolbar(e);break;case"resize":(s.isCircleCrop||s.currSelectionPoint&&"crop-circle"===s.currSelectionPoint.shape)&&(s.aspectHeight=s.aspectWidth,this.isAspectRatio=!1),this.initResizeToolbar(),O.Browser.isDevice&&this.initMainToolbar(!1,!0,!0,!0),p=s.element.querySelector("#"+l+"_aspectratio"),g=s.element.querySelector("#"+l+"_nonaspectratio"),s.aspectWidth&&s.aspectHeight&&(g?s.notify("transform",{prop:"resize",value:{width:s.aspectWidth,height:s.aspectHeight,isAspectRatio:!1}}):p&&s.notify("transform",{prop:"resize",value:{width:s.aspectWidth,height:null,isAspectRatio:!0}}));break;case"color":this.updateContextualToolbar(e,r);break;case"croptransform":O.isNullOrUndefined(a)&&(s.allowDownScale=!1,s.isCropTab=!0),O.Browser.isDevice&&this.initMainToolbar(!1,!0,!0),O.isNullOrUndefined(a)&&s.updateCropTransformItems(),this.initCropTransformToolbar(n,a),O.Browser.isDevice&&this.isToolbar()&&this.updateContextualToolbar("color","straighten",!0);break;case"frame":this.isFrameToolbar=!0,O.Browser.isDevice?(this.initMainToolbar(!1,!0,!0),this.initMainToolbar(!1,!0,!0,!1,!0)):this.initMainToolbar(!0,null,null,!1,!0);var g=s.element.querySelector("#"+l+"_"+s.frameObj.type);g&&g.classList.add("e-selected-btn"),"none"!==s.frameObj.type&&this.updateContextualToolbar(e,r),s.notify("draw",{prop:"render-image",value:{isMouseWheel:null,isPreventClearRect:null,isFrame:!0}})}this.currToolbar=e,this.refreshDropDownBtn(o)}},Y.prototype.performCropTransformClick=function(e,t){var o=this.parent;O.isNullOrUndefined(t)&&(o.notify("draw",{prop:"setTempStraightenZoomDeg"}),o.tempStraighten=o.transform.straighten,o.currObjType.isFiltered&&o.okBtn(),o.isStraightening=!0),this.refreshToolbar("croptransform",null,null,null,null,e,t),O.isNullOrUndefined(t)&&(o.notify("draw",{prop:"setDestForStraighten"}),o.notify("draw",{prop:"setTempDestForStraighten"}))},Y.prototype.getAdjustmentToolbarItem=function(){var e=[],t=this.parent,o=!1,i=t.element.id,r=["Brightness","Contrast","Hue","Saturation","Exposure","Opacity","Blur"];if(t.toolbar)for(var n=0;n<r.length;n++)if(-1!==t.toolbar.indexOf(r[n])){o=!0;break}(O.isNullOrUndefined(t.toolbar)||!o||t.toolbar&&-1<t.toolbar.indexOf("Brightness"))&&e.push({id:i+"_brightness",prefixIcon:"e-icons e-brightness",cssClass:"top-icon e-brightness",tooltipText:this.l10n.getConstant("Brightness"),align:"Center"}),(O.isNullOrUndefined(t.toolbar)||!o||t.toolbar&&-1<t.toolbar.indexOf("Contrast"))&&e.push({id:i+"_contrast",prefixIcon:"e-icons e-contrast",cssClass:"top-icon e-contrast",tooltipText:this.l10n.getConstant("Contrast"),align:"Center"}),(O.isNullOrUndefined(t.toolbar)||!o||t.toolbar&&-1<t.toolbar.indexOf("Hue"))&&e.push({id:i+"_hue",prefixIcon:"e-icons e-fade",cssClass:"top-icon e-fade",tooltipText:this.l10n.getConstant("Hue"),align:"Center"}),(O.isNullOrUndefined(t.toolbar)||!o||t.toolbar&&-1<t.toolbar.indexOf("Saturation"))&&e.push({id:i+"_saturation",prefixIcon:"e-icons e-saturation",cssClass:"top-icon e-saturation",tooltipText:this.l10n.getConstant("Saturation"),align:"Center"}),(O.isNullOrUndefined(t.toolbar)||!o||t.toolbar&&-1<t.toolbar.indexOf("Exposure"))&&e.push({id:i+"_exposure",prefixIcon:"e-icons e-grain",cssClass:"top-icon e-grain",tooltipText:this.l10n.getConstant("Exposure"),align:"Center"}),(O.isNullOrUndefined(t.toolbar)||!o||t.toolbar&&-1<t.toolbar.indexOf("Opacity"))&&e.push({id:i+"_opacity",prefixIcon:"e-icons e-opacity",cssClass:"top-icon e-opacity",tooltipText:this.l10n.getConstant("Opacity"),align:"Center"}),(O.isNullOrUndefined(t.toolbar)||!o||t.toolbar&&-1<t.toolbar.indexOf("Blur"))&&e.push({id:i+"_blur",prefixIcon:"e-icons e-tint",cssClass:"top-icon e-tint",tooltipText:this.l10n.getConstant("Blur"),align:"Center"});for(var a=this.processToolbar("center"),n=0,s=a.length;n<s;n++)e.push(a[n]);return O.Browser.isDevice||(e.push({id:i+"_ok",prefixIcon:"e-icons e-check",cssClass:"top-icon e-tick",tooltipText:this.l10n.getConstant("OK"),align:"Right"}),e.push({id:i+"_cancel",prefixIcon:"e-icons e-close",cssClass:"top-icon e-save",tooltipText:this.l10n.getConstant("Cancel"),align:"Right"})),e},Y.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},Y.prototype.getFilterToolbarItem=function(){var e=[],t=this.parent,o=!1,i=t.element.id,r=["Default","Chrome","Cold","Warm","Grayscale","Sepia","Invert"];if(t.toolbar)for(var n=0;n<r.length;n++)if(-1!==t.toolbar.indexOf(r[n])){o=!0;break}(O.isNullOrUndefined(t.toolbar)||!o||t.toolbar&&-1<t.toolbar.indexOf("Default"))&&e.push({id:i+"_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='+i+'_defaultCanvas></canvas><div style="text-align:center;"><span>'+this.l10n.getConstant("Default")+"</span></div></div>"}),(O.isNullOrUndefined(t.toolbar)||!o||t.toolbar&&-1<t.toolbar.indexOf("Chrome"))&&e.push({id:i+"_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='+i+'_chromeCanvas></canvas><div style="text-align:center;"><span>'+this.l10n.getConstant("Chrome")+"</span></div></div>"}),(O.isNullOrUndefined(t.toolbar)||!o||t.toolbar&&-1<t.toolbar.indexOf("Cold"))&&e.push({id:i+"_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='+i+'_coldCanvas></canvas><div style="text-align:center;"><span>'+this.l10n.getConstant("Cold")+"</span></div></div>"}),(O.isNullOrUndefined(t.toolbar)||!o||t.toolbar&&-1<t.toolbar.indexOf("Warm"))&&e.push({id:i+"_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='+i+'_warmCanvas></canvas><div style="text-align:center;"><span>'+this.l10n.getConstant("Warm")+"</span></div></div>"}),(O.isNullOrUndefined(t.toolbar)||!o||t.toolbar&&-1<t.toolbar.indexOf("Grayscale"))&&e.push({id:i+"_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='+i+'_grayscaleCanvas></canvas><div style="text-align:center;"><span>'+this.l10n.getConstant("Grayscale")+"</span></div></div>"}),(O.isNullOrUndefined(t.toolbar)||!o||t.toolbar&&-1<t.toolbar.indexOf("Sepia"))&&e.push({id:i+"_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='+i+'_sepiaCanvas></canvas><div style="text-align:center;"><span>'+this.l10n.getConstant("Sepia")+"</span></div></div>"}),(O.isNullOrUndefined(t.toolbar)||!o||t.toolbar&&-1<t.toolbar.indexOf("Invert"))&&e.push({id:i+"_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='+i+'_invertCanvas></canvas><div style="text-align:center;"><span>'+this.l10n.getConstant("Invert")+"</span></div></div>"});for(var a=this.processToolbar("center"),n=0,s=a.length;n<s;n++)e.push(a[n]);return e},Y.prototype.getPenToolbarItem=function(e){for(var t=this.parent,o=t.element.id,i=[],r=((O.isNullOrUndefined(t.toolbar)||t.toolbar)&&i.push({id:o+"_annotation",tooltipText:this.l10n.getConstant("Annotation"),align:"Center",template:'<button id="'+o+'_annotationBtn"></button>'}),-1<e.indexOf("strokeColor")&&i.push({prefixIcon:"e-icons e-copy",id:o+"_pen_strokecolor",cssClass:"top-icon e-pen-stroke-color",tooltipText:this.l10n.getConstant("StrokeColor"),align:"Center",type:"Input",template:'<button id="'+o+'_penColorBtn"></button>'}),-1<e.indexOf("strokeWidth")&&i.push({prefixIcon:"e-icons e-copy",id:o+"_pen_strokewidth",cssClass:"top-icon e-size",tooltipText:this.l10n.getConstant("StrokeWidth"),align:"Center",type:"Input",template:'<button id="'+o+'_penStrokeWidth"></button>'}),i.push({align:"Center",type:"Separator"}),-1<e.indexOf("z-order")&&i.push({id:o+"_zOrder",cssClass:"top-icon e-list-unordered-3",tooltipText:this.l10n.getConstant("ZOrder"),align:"Center",type:"Input",template:'<button id="'+o+'_zOrderBtn"></button>'}),-1<e.indexOf("remove")&&i.push({id:o+"_remove",prefixIcon:"e-icons e-trash",cssClass:"top-icon e-trash",tooltipText:this.l10n.getConstant("Remove"),align:"Center"}),this.processSubToolbar(e)),n=0,a=r.length;n<a;n++)i.push(r[n]);return O.Browser.isDevice||(i.push({id:o+"_ok",prefixIcon:"e-icons e-check",cssClass:"top-icon e-tick",tooltipText:this.l10n.getConstant("OK"),align:"Right"}),i.push({id:o+"_cancel",prefixIcon:"e-icons e-close",cssClass:"top-icon e-save",tooltipText:this.l10n.getConstant("Cancel"),align:"Right"})),i},Y.prototype.initPenToolbarItem=function(e){var t=this,o=this.parent,i=o.element.id,r=this.getLeftToolbarItem(),n=this.getRightToolbarItem(),a=this.getPenToolbarItem(e),s=this.getZoomToolbarItem(),r=(O.Browser.isDevice?this.defToolbarItems=a:this.defToolbarItems=r.concat(s,a,n),{toolbarType:"pen",toolbarItems:this.defToolbarItems}),l=(o.trigger("toolbarUpdating",r),this.isToolbarString(r.toolbarItems)?(e=r.toolbarItems,this.excludeItems(r.toolbarItems)):this.defToolbarItems=r.toolbarItems,new d.Toolbar({width:"100%",items:this.defToolbarItems,clicked:this.defToolbarClicked.bind(this),created:function(){t.renderAnnotationBtn(!0),t.createPenColor(e),t.createPenBtn(e),t.createZOrderBtn(e),t.wireZoomBtnEvents(),o.trigger("toolbarCreated",{toolbarType:"pen"}),O.Browser.isDevice?0<t.defToolbarItems.length&&document.getElementById(i+"_toolbar")&&(l.refreshOverflow(),l.refreshOverflow()):(t.createLeftToolbarControls(),0<t.defToolbarItems.length&&document.getElementById(i+"_toolbar")&&l.refreshOverflow())}}));O.Browser.isDevice?l.appendTo("#"+i+"_bottomToolbar"):l.appendTo("#"+i+"_toolbar"),this.enableDisableTbrBtn()},Y.prototype.createPenColor=function(e){var t,o,i=this,r=this.parent,n=r.element.id;-1<e.indexOf("strokeColor")&&(r.element.querySelector(".e-template.e-pen-stroke-color").appendChild(r.createElement("input",{id:n+"_pen_stroke"})),e=r.activeObj.strokeSettings.strokeColor,t=new g.ColorPicker({modeSwitcher:!1,value:"#fff",showButtons:!1,mode:"Palette",cssClass:"e-pen-color",change:function(e){r.updatePenStrokeColor(e.currentValue.hex),i.selFhdColor=e.currentValue.hex,o.element.children[0].style.backgroundColor=e.currentValue.rgba,o.toggle(),r.notify("undo-redo",{prop:"updateUndoRedoStack",value:{isPenDraw:!0}})}},"#"+n+"_pen_stroke"),o=new f.DropDownButton({open:function(e){e=e.element.parentElement;O.Browser.isDevice&&(e.style.top=o.element.getBoundingClientRect().top-e.offsetHeight+"px",e.style.left=r.element.offsetLeft+"px")},target:".e-pen-color",iconCss:"e-dropdownbtn-preview",cssClass:"e-ie-ddb-popup"},"#"+n+"_penColorBtn"),t.inline=!0,t.value=t.getValue(r.activeObj.strokeSettings.strokeColor,"rgba"),"null"===t.value&&(t.value=e),r.notify("freehand-draw",{prop:"getTempFreeHandDrawEditingStyles",value:{obj:n={tempFreeHandDrawEditingStyles:null}}}),r.notify("freehand-draw",{prop:"getFreehandSelectedIndex",onPropertyChange:!(e={freehandSelectedIndex:null}),value:{obj:e}}),!O.isNullOrUndefined(e.freehandSelectedIndex)&&-1<e.freehandSelectedIndex?r.element.querySelector(".e-pen-stroke-color.e-template .e-dropdownbtn-preview").style.background=("#42a5f5"===this.selFhdColor?n.tempFreeHandDrawEditingStyles:r.pointColl[e.freehandSelectedIndex]).strokeColor:r.element.querySelector(".e-pen-stroke-color.e-template .e-dropdownbtn-preview").style.background=t.value)},Y.prototype.createPenBtn=function(e){var o,t,i,r=this,n=this.parent,a=n.element.id,s=[{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")}];-1<e.indexOf("strokeWidth")&&(e=document.getElementById(a+"_penStrokeWidth"),o=document.createElement("span"),n.notify("freehand-draw",{prop:"getFreehandSelectedIndex",onPropertyChange:!(t={freehandSelectedIndex:null}),value:{obj:t}}),!O.isNullOrUndefined(t.freehandSelectedIndex)&&-1<t.freehandSelectedIndex?o.innerHTML=this.getPenStroke(n.pointColl[t.freehandSelectedIndex].strokeWidth):(n.notify("freehand-draw",{prop:"getPenStrokeWidth",onPropertyChange:!(t={penStrokeWidth:2}),value:{obj:t}}),o.innerHTML=t.penStrokeWidth?this.getPenStroke(t.penStrokeWidth):this.l10n.getConstant("Small")),o.className="e-pen-stroke-width",e.appendChild(o),(i=new f.DropDownButton({items:s,open:function(e){O.Browser.isDevice&&(e.element.parentElement.style.top=i.element.getBoundingClientRect().top-e.element.parentElement.offsetHeight+"px");var t=o.innerHTML;e.element.querySelector('[aria-label = "'+t+'"]').classList.add("e-selected-btn")},select:function(e){r.triggerTbarClickEvent(e),o.textContent=e.item.text,n.updatePenStrokeWidth(e.item.id),O.Browser.isDevice?document.getElementById(a+"_bottomToolbar")&&O.getComponent(a+"_bottomToolbar","toolbar").refreshOverflow():document.getElementById(a+"_toolbar")&&O.getComponent(a+"_toolbar","toolbar").refreshOverflow(),n.notify("undo-redo",{prop:"updateUndoRedoStack",value:{isPenDraw:!0}})}})).appendTo("#"+a+"_penStrokeWidth"))},Y.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 t=1<=e&&e<=5?o[e]:t},Y.prototype.initAdjustmentToolbarItem=function(){var e=this,t=this.parent,o=t.element.id,i=this.getLeftToolbarItem(null),r=this.getRightToolbarItem(),n=this.getAdjustmentToolbarItem(),a=this.getZoomToolbarItem(),i=(O.Browser.isDevice?this.defToolbarItems=n:this.defToolbarItems=i.concat(a,n,r),{toolbarType:"finetune",toolbarItems:this.defToolbarItems}),s=(t.trigger("toolbarUpdating",i),this.defToolbarItems=i.toolbarItems,new d.Toolbar({width:"100%",items:this.defToolbarItems,clicked:this.defToolbarClicked.bind(this),created:function(){e.wireZoomBtnEvents(),O.Browser.isDevice||e.createLeftToolbarControls(),0<e.defToolbarItems.length&&document.getElementById(o+"_toolbar")&&s.refreshOverflow()}}));O.Browser.isDevice?s.appendTo("#"+o+"_bottomToolbar"):s.appendTo("#"+o+"_toolbar"),this.enableDisableTbrBtn()},Y.prototype.initFrameToolbarItem=function(){var t=this,o=this.parent,i=o.element.id,e=document.querySelector("#"+i+"_contextualToolbarArea"),r=document.querySelector("#"+i+"_frameWrapper");r?r.style.display="block":r=e.appendChild(o.createElement("div",{id:i+"_frameWrapper",className:"e-frame-wrapper",styles:"position: relative"})),r.appendChild(o.createElement("div",{id:i+"_customizeWrapper",styles:"position: absolute"}));var e={toolbarType:"frame",toolbarItems:this.getFrameToolbarItem()},n=(o.trigger("toolbarUpdating",e),new d.Toolbar({width:"100%",items:e.toolbarItems,clicked:this.defToolbarClicked.bind(this),created:function(){t.createFrameColor(),t.createFrameSize();var e=o.frameObj.type;"line"===e&&t.createFrameRadius(),"line"!==e&&"inset"!==e&&"hook"!==e||t.createFrameInset(),"line"!==e&&"inset"!==e||t.createFrameOffset(),"line"===e&&(t.createFrameAmount(),t.createFrameBorder()),t.createFrameGradientColor(),O.Browser.isDevice?0<t.defToolbarItems.length&&document.getElementById(i+"_bottomToolbar")&&(n.refreshOverflow(),n.refreshOverflow(),n.refreshOverflow()):(t.createLeftToolbarControls(),0<t.defToolbarItems.length&&document.getElementById(i+"_toolbar")&&n.refreshOverflow()),o.element.querySelector("#"+i+"_"+e).focus()}}));n.appendTo("#"+i+"_customizeWrapper")},Y.prototype.createFrameGradientColor=function(){var i,r=this.parent,n={frameChangeEventArgs:null},e=r.element.id,t=(r.element.querySelector(".e-template.e-frame-stroke").appendChild(r.createElement("input",{id:e+"_frame_gradient_fill"})),new g.ColorPicker({modeSwitcher:!1,noColor:!0,value:r.frameObj.gradientColor,showButtons:!1,mode:"Palette",cssClass:"e-frame-gradient-fill-color",change:function(e){i={type:r.toPascalCase(r.frameObj.type),color:r.frameObj.color,gradientColor:r.frameObj.gradientColor,size:r.frameObj.size,inset:r.frameObj.inset,offset:r.frameObj.offset,borderRadius:r.frameObj.radius,frameLineStyle:r.toPascalCase(r.frameObj.border),lineCount:r.frameObj.amount};var t=r.frameObj.gradientColor,o={currObj:{}};r.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:o}}),r.frameObj.gradientColor=e.currentValue.hex,r.notify("draw",{prop:"triggerFrameChange",value:{prevFrameSettings:i,obj:n}}),n.frameChangeEventArgs&&!n.frameChangeEventArgs.cancel?(r.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"frame",previousObj:o.currObj,previousObjColl:o.currObj.objColl,previousPointColl:o.currObj.pointColl,previousSelPointColl:o.currObj.selPointColl,previousCropObj:O.extend({},r.cropObj,{},!0),previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),r.notify("draw",{prop:"render-image",value:{isMouseWheel:null,isPreventClearRect:null,isFrame:!0}}),r.notify("draw",{prop:"redrawDownScale"}),""===e.currentValue.rgba?a.element.children[0].classList.add("e-nocolor-item"):(a.element.children[0].classList.remove("e-nocolor-item"),a.element.children[0].style.backgroundColor=e.currentValue.rgba),r.curFrameObjEvent={previousFrameSetting:n.frameChangeEventArgs.previousFrameSetting,currentFrameSetting:n.frameChangeEventArgs.currentFrameSetting},r.isFrameBtnClick=!0):r.frameObj.gradientColor=t,a.toggle()}},"#"+e+"_frame_gradient_fill")),a=new f.DropDownButton({open:function(e){O.Browser.isDevice&&((e=e.element.parentElement).style.top=a.element.getBoundingClientRect().top-e.offsetHeight+"px",e.style.left=r.element.offsetLeft+"px")},target:".e-frame-gradient-fill-color",iconCss:"e-dropdownbtn-preview",cssClass:"e-ie-ddb-popup"},"#"+e+"_frameGradientColorBtn");t.inline=!0,""===r.frameObj.gradientColor?r.element.querySelector(".e-frame-stroke.e-template .e-dropdownbtn-preview").classList.add("e-nocolor-item"):r.element.querySelector(".e-frame-stroke.e-template .e-dropdownbtn-preview").style.background=r.frameObj.gradientColor},Y.prototype.createFrameColor=function(){var i,r=this.parent,n={frameChangeEventArgs:null},e=r.element.id,t=(r.element.querySelector(".e-template.e-stroke").appendChild(r.createElement("input",{id:e+"_frame_fill"})),new g.ColorPicker({modeSwitcher:!1,value:r.frameObj.color,showButtons:!1,mode:"Palette",cssClass:"e-frame-fill-color",change:function(e){i={type:r.toPascalCase(r.frameObj.type),color:r.frameObj.color,gradientColor:r.frameObj.gradientColor,size:r.frameObj.size,inset:r.frameObj.inset,offset:r.frameObj.offset,borderRadius:r.frameObj.radius,frameLineStyle:r.toPascalCase(r.frameObj.border),lineCount:r.frameObj.amount};var t=r.frameObj.color,o={currObj:{}};r.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:o}}),r.frameObj.color=e.currentValue.hex,r.notify("draw",{prop:"triggerFrameChange",value:{prevFrameSettings:i,obj:n}}),n.frameChangeEventArgs&&!n.frameChangeEventArgs.cancel?(r.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"frame",previousObj:o.currObj,previousObjColl:o.currObj.objColl,previousPointColl:o.currObj.pointColl,previousSelPointColl:o.currObj.selPointColl,previousCropObj:O.extend({},r.cropObj,{},!0),previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),r.notify("draw",{prop:"render-image",value:{isMouseWheel:null,isPreventClearRect:null,isFrame:!0}}),r.notify("draw",{prop:"redrawDownScale"}),""===e.currentValue.rgba?a.element.children[0].classList.add("e-nocolor-item"):(a.element.children[0].classList.remove("e-nocolor-item"),a.element.children[0].style.backgroundColor=e.currentValue.rgba),r.curFrameObjEvent={previousFrameSetting:n.frameChangeEventArgs.previousFrameSetting,currentFrameSetting:n.frameChangeEventArgs.currentFrameSetting},r.isFrameBtnClick=!0):r.frameObj.color=t,a.toggle()}},"#"+e+"_frame_fill")),a=new f.DropDownButton({open:function(e){O.Browser.isDevice&&((e=e.element.parentElement).style.top=a.element.getBoundingClientRect().top-e.offsetHeight+"px",e.style.left=r.element.offsetLeft+"px")},target:".e-frame-fill-color",iconCss:"e-dropdownbtn-preview",cssClass:"e-ie-ddb-popup"},"#"+e+"_frameColorBtn");t.inline=!0,r.element.querySelector(".e-stroke.e-template .e-dropdownbtn-preview").style.background=r.frameObj.color},Y.prototype.createFrameSize=function(){var i,r=this,n=this.parent,a={frameChangeEventArgs:null},s=n.element.id,e=[{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")}],t=document.getElementById(s+"_frameSizeBtn"),o=document.createElement("span"),l=(o.innerHTML=this.l10n.getConstant(n.frameObj.size.toString()),o.className="e-frame-stroke-width",t.appendChild(o),new f.DropDownButton({items:e,open:function(e){O.Browser.isDevice&&((t=e.element.parentElement).style.top=l.element.getBoundingClientRect().top-t.offsetHeight+"px");var t=l.element.childNodes[0].textContent;""!==t&&e.element.querySelector('[aria-label = "'+t+'"]').classList.add("e-selected-btn")},select:function(e){r.triggerTbarClickEvent(e),i={type:n.toPascalCase(n.frameObj.type),color:n.frameObj.color,gradientColor:n.frameObj.gradientColor,size:n.frameObj.size,inset:n.frameObj.inset,offset:n.frameObj.offset,borderRadius:n.frameObj.radius,frameLineStyle:n.toPascalCase(n.frameObj.border),lineCount:n.frameObj.amount};var t=n.frameObj.size,o={currObj:{}};n.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:o}}),n.frameObj.size=parseInt(e.item.text,10),n.notify("draw",{prop:"triggerFrameChange",value:{prevFrameSettings:i,obj:a}}),a.frameChangeEventArgs&&!a.frameChangeEventArgs.cancel?(n.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"frame",previousObj:o.currObj,previousObjColl:o.currObj.objColl,previousPointColl:o.currObj.pointColl,previousSelPointColl:o.currObj.selPointColl,previousCropObj:O.extend({},n.cropObj,{},!0),previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),n.notify("draw",{prop:"render-image",value:{isMouseWheel:null,isPreventClearRect:null,isFrame:!0}}),n.notify("draw",{prop:"redrawDownScale"}),l.content=e.item.text,n.curFrameObjEvent={previousFrameSetting:a.frameChangeEventArgs.previousFrameSetting,currentFrameSetting:a.frameChangeEventArgs.currentFrameSetting},n.isFrameBtnClick=!0):n.frameObj.size=t,O.Browser.isDevice?document.getElementById(s+"_bottomToolbar")&&O.getComponent(s+"_bottomToolbar","toolbar").refreshOverflow():document.getElementById(s+"_toolbar")&&O.getComponent(s+"_toolbar","toolbar").refreshOverflow()}}));l.appendTo("#"+s+"_frameSizeBtn")},Y.prototype.createFrameInset=function(){var i,r=this,n=this.parent,a={frameChangeEventArgs:null},s=n.element.id,e=[{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")}],t=document.getElementById(s+"_frameInsetBtn"),o=document.createElement("span"),l=(o.innerHTML=this.l10n.getConstant(n.frameObj.inset.toString()),o.className="e-frame-inset",t.appendChild(o),new f.DropDownButton({items:e,open:function(e){O.Browser.isDevice&&((t=e.element.parentElement).style.top=l.element.getBoundingClientRect().top-t.offsetHeight+"px");var t=l.element.childNodes[0].textContent;""!==t&&e.element.querySelector('[aria-label = "'+t+'"]').classList.add("e-selected-btn")},select:function(e){r.triggerTbarClickEvent(e),i={type:n.toPascalCase(n.frameObj.type),color:n.frameObj.color,gradientColor:n.frameObj.gradientColor,size:n.frameObj.size,inset:n.frameObj.inset,offset:n.frameObj.offset,borderRadius:n.frameObj.radius,frameLineStyle:n.toPascalCase(n.frameObj.border),lineCount:n.frameObj.amount};var t=n.frameObj.inset,o={currObj:{}};n.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:o}}),n.frameObj.inset=parseInt(e.item.text,10),n.notify("draw",{prop:"triggerFrameChange",value:{prevFrameSettings:i,obj:a}}),a.frameChangeEventArgs&&!a.frameChangeEventArgs.cancel?(n.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"frame",previousObj:o.currObj,previousObjColl:o.currObj.objColl,previousPointColl:o.currObj.pointColl,previousSelPointColl:o.currObj.selPointColl,previousCropObj:O.extend({},n.cropObj,{},!0),previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),n.notify("draw",{prop:"render-image",value:{isMouseWheel:null,isPreventClearRect:null,isFrame:!0}}),n.notify("draw",{prop:"redrawDownScale"}),l.content=e.item.text,n.curFrameObjEvent={previousFrameSetting:a.frameChangeEventArgs.previousFrameSetting,currentFrameSetting:a.frameChangeEventArgs.currentFrameSetting},n.isFrameBtnClick=!0):n.frameObj.inset=t,O.Browser.isDevice?document.getElementById(s+"_bottomToolbar")&&O.getComponent(s+"_bottomToolbar","toolbar").refreshOverflow():document.getElementById(s+"_toolbar")&&O.getComponent(s+"_toolbar","toolbar").refreshOverflow()}}));l.appendTo("#"+s+"_frameInsetBtn")},Y.prototype.createFrameOffset=function(){var i,r=this,n=this.parent,a={frameChangeEventArgs:null},s=n.element.id,e=[{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")}],t=document.getElementById(s+"_frameOffsetBtn"),o=document.createElement("span"),l=(o.innerHTML=this.l10n.getConstant(n.frameObj.offset.toString()),o.className="e-frame-offset",t.appendChild(o),new f.DropDownButton({items:e,open:function(e){O.Browser.isDevice&&((t=e.element.parentElement).style.top=l.element.getBoundingClientRect().top-t.offsetHeight+"px");var t=l.element.childNodes[0].textContent;""!==t&&e.element.querySelector('[aria-label = "'+t+'"]').classList.add("e-selected-btn")},select:function(e){r.triggerTbarClickEvent(e),i={type:n.toPascalCase(n.frameObj.type),color:n.frameObj.color,gradientColor:n.frameObj.gradientColor,size:n.frameObj.size,inset:n.frameObj.inset,offset:n.frameObj.offset,borderRadius:n.frameObj.radius,lineCount:n.frameObj.amount,frameLineStyle:n.toPascalCase(n.frameObj.border)};var t=n.frameObj.offset,o={currObj:{}};n.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:o}}),n.frameObj.offset=parseInt(e.item.text,10),n.notify("draw",{prop:"triggerFrameChange",value:{prevFrameSettings:i,obj:a}}),a.frameChangeEventArgs&&!a.frameChangeEventArgs.cancel?(n.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"frame",previousObj:o.currObj,previousObjColl:o.currObj.objColl,previousPointColl:o.currObj.pointColl,previousSelPointColl:o.currObj.selPointColl,previousCropObj:O.extend({},n.cropObj,{},!0),previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),n.notify("draw",{prop:"render-image",value:{isMouseWheel:null,isPreventClearRect:null,isFrame:!0}}),n.notify("draw",{prop:"redrawDownScale"}),l.content=e.item.text,n.curFrameObjEvent={previousFrameSetting:a.frameChangeEventArgs.previousFrameSetting,currentFrameSetting:a.frameChangeEventArgs.currentFrameSetting},n.isFrameBtnClick=!0):n.frameObj.offset=t,O.Browser.isDevice?document.getElementById(s+"_bottomToolbar")&&O.getComponent(s+"_bottomToolbar","toolbar").refreshOverflow():document.getElementById(s+"_toolbar")&&O.getComponent(s+"_toolbar","toolbar").refreshOverflow()}}));l.appendTo("#"+s+"_frameOffsetBtn")},Y.prototype.createFrameRadius=function(){var i,r=this,n=this.parent,a={frameChangeEventArgs:null},s=n.element.id,e=[{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")}],t=document.getElementById(s+"_frameRadiusBtn"),o=document.createElement("span"),l=(o.innerHTML=this.l10n.getConstant(n.frameObj.radius.toString()),o.className="e-frame-radius",t.appendChild(o),new f.DropDownButton({items:e,open:function(e){O.Browser.isDevice&&((t=e.element.parentElement).style.top=l.element.getBoundingClientRect().top-t.offsetHeight+"px");var t=l.element.childNodes[0].textContent;""!==t&&e.element.querySelector('[aria-label = "'+t+'"]').classList.add("e-selected-btn")},select:function(e){r.triggerTbarClickEvent(e),i={type:n.toPascalCase(n.frameObj.type),color:n.frameObj.color,gradientColor:n.frameObj.gradientColor,size:n.frameObj.size,inset:n.frameObj.inset,offset:n.frameObj.offset,borderRadius:n.frameObj.radius,frameLineStyle:n.toPascalCase(n.frameObj.border),lineCount:n.frameObj.amount};var t=n.frameObj.radius,o={currObj:{}};n.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:o}}),n.frameObj.radius=parseInt(e.item.text,10),n.notify("draw",{prop:"triggerFrameChange",value:{prevFrameSettings:i,obj:a}}),a.frameChangeEventArgs&&!a.frameChangeEventArgs.cancel?(n.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"frame",previousObj:o.currObj,previousObjColl:o.currObj.objColl,previousPointColl:o.currObj.pointColl,previousSelPointColl:o.currObj.selPointColl,previousCropObj:O.extend({},n.cropObj,{},!0),previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),n.notify("draw",{prop:"render-image",value:{isMouseWheel:null,isPreventClearRect:null,isFrame:!0}}),n.notify("draw",{prop:"redrawDownScale"}),l.content=e.item.text,n.curFrameObjEvent={previousFrameSetting:a.frameChangeEventArgs.previousFrameSetting,currentFrameSetting:a.frameChangeEventArgs.currentFrameSetting},n.isFrameBtnClick=!0):n.frameObj.radius=t,O.Browser.isDevice?document.getElementById(s+"_bottomToolbar")&&O.getComponent(s+"_bottomToolbar","toolbar").refreshOverflow():document.getElementById(s+"_toolbar")&&O.getComponent(s+"_toolbar","toolbar").refreshOverflow()}}));l.appendTo("#"+s+"_frameRadiusBtn")},Y.prototype.createFrameAmount=function(){var i,r=this,n=this.parent,a={frameChangeEventArgs:null},s=n.element.id,e=[{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")}],t=document.getElementById(s+"_frameAmountBtn"),o=document.createElement("span"),l=(o.innerHTML=this.l10n.getConstant(n.frameObj.amount.toString()),o.className="e-frame-amount",t.appendChild(o),new f.DropDownButton({items:e,open:function(e){O.Browser.isDevice&&((t=e.element.parentElement).style.top=l.element.getBoundingClientRect().top-t.offsetHeight+"px");var t=l.element.childNodes[0].textContent;""!==t&&e.element.querySelector('[aria-label = "'+t+'"]').classList.add("e-selected-btn")},select:function(e){r.triggerTbarClickEvent(e),i={type:n.toPascalCase(n.frameObj.type),color:n.frameObj.color,gradientColor:n.frameObj.gradientColor,size:n.frameObj.size,inset:n.frameObj.inset,offset:n.frameObj.offset,borderRadius:n.frameObj.radius,lineCount:n.frameObj.amount,frameLineStyle:n.toPascalCase(n.frameObj.border)};var t=n.frameObj.amount,o={currObj:{}};n.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:o}}),n.frameObj.amount=parseInt(e.item.text,10),n.notify("draw",{prop:"triggerFrameChange",value:{prevFrameSettings:i,obj:a}}),a.frameChangeEventArgs&&!a.frameChangeEventArgs.cancel?(n.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"frame",previousObj:o.currObj,previousObjColl:o.currObj.objColl,previousPointColl:o.currObj.pointColl,previousSelPointColl:o.currObj.selPointColl,previousCropObj:O.extend({},n.cropObj,{},!0),previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),n.notify("draw",{prop:"render-image",value:{isMouseWheel:null,isPreventClearRect:null,isFrame:!0}}),n.notify("draw",{prop:"redrawDownScale"}),l.content=e.item.text,n.curFrameObjEvent={previousFrameSetting:a.frameChangeEventArgs.previousFrameSetting,currentFrameSetting:a.frameChangeEventArgs.currentFrameSetting},n.isFrameBtnClick=!0):n.frameObj.amount=t,O.Browser.isDevice?document.getElementById(s+"_bottomToolbar")&&O.getComponent(s+"_bottomToolbar","toolbar").refreshOverflow():document.getElementById(s+"_toolbar")&&O.getComponent(s+"_toolbar","toolbar").refreshOverflow()}}));l.appendTo("#"+s+"_frameAmountBtn")},Y.prototype.createFrameBorder=function(){var i,r=this,n=this.parent,a={frameChangeEventArgs:null},s=n.element.id,e=[{id:"1",text:this.l10n.getConstant("Solid")},{id:"2",text:this.l10n.getConstant("Dashed")},{id:"3",text:this.l10n.getConstant("Dotted")}],t=document.getElementById(s+"_frameBorderBtn"),o=document.createElement("span"),l=(o.innerHTML=this.l10n.getConstant(n.toPascalCase(n.frameObj.border)),o.className="e-frame-border",t.appendChild(o),new f.DropDownButton({items:e,open:function(e){O.Browser.isDevice&&((t=e.element.parentElement).style.top=l.element.getBoundingClientRect().top-t.offsetHeight+"px");var t=l.element.childNodes[0].textContent;""!==t&&e.element.querySelector('[aria-label = "'+t+'"]').classList.add("e-selected-btn")},select:function(e){r.triggerTbarClickEvent(e),i={lineCount:n.frameObj.amount,color:n.frameObj.color,borderRadius:n.frameObj.radius,gradientColor:n.frameObj.gradientColor,size:n.frameObj.size,inset:n.frameObj.inset,offset:n.frameObj.offset,frameLineStyle:n.toPascalCase(n.frameObj.border),type:n.toPascalCase(n.frameObj.type)};var t=n.frameObj.border,o={currObj:{}};n.notify("filter",{prop:"getCurrentObj",onPropertyChange:!1,value:{object:o}}),n.frameObj.border=e.item.text.toLowerCase(),n.notify("draw",{prop:"triggerFrameChange",value:{prevFrameSettings:i,obj:a}}),a.frameChangeEventArgs&&!a.frameChangeEventArgs.cancel?(n.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"frame",previousObj:o.currObj,previousObjColl:o.currObj.objColl,previousPointColl:o.currObj.pointColl,previousSelPointColl:o.currObj.selPointColl,previousCropObj:O.extend({},n.cropObj,{},!0),previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),n.notify("draw",{prop:"render-image",value:{isMouseWheel:null,isPreventClearRect:null,isFrame:!0}}),n.notify("draw",{prop:"redrawDownScale"}),l.content=e.item.text,n.curFrameObjEvent={previousFrameSetting:a.frameChangeEventArgs.previousFrameSetting,currentFrameSetting:a.frameChangeEventArgs.currentFrameSetting},n.isFrameBtnClick=!0):n.frameObj.border=t,O.Browser.isDevice?document.getElementById(s+"_bottomToolbar")&&O.getComponent(s+"_bottomToolbar","toolbar").refreshOverflow():document.getElementById(s+"_toolbar")&&O.getComponent(s+"_toolbar","toolbar").refreshOverflow()}}));l.appendTo("#"+s+"_frameBorderBtn")},Y.prototype.initFilterToolbarItem=function(){var t=this,o=this.parent,i=o.element.id,e={toolbarType:"filter",toolbarItems:this.getFilterToolbarItem()},r=(o.trigger("toolbarUpdating",e),e=e.toolbarItems,document.querySelector("#"+i+"_contextualToolbar").classList.contains("e-control")&&O.getComponent(document.getElementById(i+"_contextualToolbar"),"toolbar").destroy(),new d.Toolbar({width:"100%",items:e,clicked:this.contextualToolbarClicked.bind(this),created:function(){t.updatePrivateVariables(),t.createCanvasFilter(),""===o.currentFilter&&(o.currentFilter=i+"_default");var e=document.querySelector("#"+i+"_headWrapper"),e=(e&&(e.style.display="none"),document.getElementById(o.currentFilter+"Canvas"));e&&e.parentElement.parentElement.classList.add("e-selected"),t.enableDisableTbrBtn(),r.refreshOverflow()}}));r.appendTo("#"+i+"_contextualToolbar")},Y.prototype.drawDashedLine=function(e){e.beginPath(),e.setLineDash([5]),e.rect(10,10,280,130),e.stroke(),e.closePath()},Y.prototype.createCanvasFilter=function(){var e=this.parent,t=(u.showSpinner(e.element),e.element.style.opacity="0.5",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"),u.hideSpinner(e.element),e.element.style.opacity="1",e.initialAdjustmentValue=this.lowerContext.filter},Y.prototype.updateFilterCanvas=function(e,t){var o,i=this.parent,e=i.element.querySelector("#"+i.element.id+e);e&&(o=e.getContext("2d"),o=e.getContext("2d"),e.style.width="100px",e.style.height="100px",i.notify("filter",{prop:"updateAdj",value:{type:t,value:null,isPreview:!0,ctx:o}}),o.drawImage(this.inMemoryCanvas,0,0,300,150))},Y.prototype.getQuickAccessToolbarItem=function(e){var t=this.parent,o=t.element.id,i={cancel:!1,toolbarItems:[]},r=[],n=(O.isNullOrUndefined(e)?("image"===t.activeObj.shape&&r.push("Flip"),r.push("BringToFront"),r.push("Clone"),r.push("Delete"),"text"===t.activeObj.shape&&r.push("EditText"),i.shape=t.toPascalCase(t.activeObj.shape)):e&&(r.push("BringToFront"),r.push("Delete"),i.shape="Freehand draw"),i.toolbarItems=O.extend([],r,null,!0),t.trigger("quickAccessToolbarOpen",i),[]);if(i.cancel)n=[];else for(var a=0;a<i.toolbarItems.length;a++)switch(i.toolbarItems[a]){case"BringToFront":n.push({id:o+"_bringToFront",prefixIcon:"e-icons e-bring-to-front",tooltipText:this.l10n.getConstant("BringToFront"),align:"Left"});break;case"Clone":n.push({id:o+"_duplicate",prefixIcon:"e-icons e-order",cssClass:"top-icon e-order",tooltipText:this.l10n.getConstant("Duplicate"),align:"Left"});break;case"Delete":n.push({id:o+"_remove",prefixIcon:"e-icons e-trash",cssClass:"top-icon e-trash",tooltipText:this.l10n.getConstant("Remove"),align:"Left"});break;case"EditText":n.push({id:o+"_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:o+"_hFlip",prefixIcon:"e-icons e-horizontal-flip",tooltipText:this.l10n.getConstant("HorizontalFlip"),align:"Left"}),n.push({id:o+"_vFlip",prefixIcon:"e-icons e-vertical-flip",tooltipText:this.l10n.getConstant("VerticalFlip"),align:"Left"});break;default:n.push(i.toolbarItems[a])}return n},Y.prototype.renderQAT=function(e){var t,o,i,r,n,a,s,l,p=this.parent,h=p.element.id;p.activeObj&&p.showQuickAccessToolbar&&((t=document.getElementById(h+"_quickAccessToolbarArea"))&&(this.destroyQuickAccessToolbar(),t.style.display="block"),0!==(o=this.getQuickAccessToolbarItem(e)).length)&&(O.isNullOrUndefined(p.quickAccessToolbarTemplate)&&new d.Toolbar({items:o,clicked:this.quickAccessToolbarClicked.bind(this)}).appendTo("#"+h+"_quickAccessToolbar"),h=this.toolbarHeight&&0!==this.toolbarHeight?this.toolbarHeight:t.clientHeight,O.isNullOrUndefined(e)&&(0!==p.activeObj.activePoint.width||0!==p.activeObj.activePoint.height||p.activeObj.shape&&"path"===p.activeObj.shape&&0<p.activeObj.pointColl.length)?(p.notify("shape",{prop:"getHighestOrder",onPropertyChange:!(a={order:null}),value:{obj:a}}),p.activeObj.order>a.order?document.getElementById(p.element.id+"_bringToFront").classList.add("e-disabled"):document.getElementById(p.element.id+"_bringToFront").classList.remove("e-disabled"),t.style.width="auto",p.activeObj.activePoint.width=Math.abs(p.activeObj.activePoint.width),p.activeObj.activePoint.height=Math.abs(p.activeObj.activePoint.height),n=p.activeObj.activePoint.startX<p.activeObj.activePoint.endX?p.activeObj.activePoint.startX:p.activeObj.activePoint.endX,i=p.activeObj.activePoint.startY<p.activeObj.activePoint.endY?p.activeObj.activePoint.startY:p.activeObj.activePoint.endY,s=p.activeObj.activePoint.width,0!==p.activeObj.rotatedAngle&&"arrow"!==p.activeObj.shape?(p.notify("shape",{prop:"getSquarePointForRotatedShape",onPropertyChange:!(l={activePoint:null}),value:{obj:p.activeObj,object:l}}),n=(l=l.activePoint).startX,i=l.startY,s=l.width):"path"===p.activeObj.shape&&(n=(r=p.getSquarePointForPath(p.activeObj)).startX,i=r.startY,s=r.width),t.style.left=n+s/2-25*o.length+"px",parseFloat(t.style.left)+t.clientWidth/2!==n+s/2&&(r=n+s/2-(parseFloat(t.style.left)+t.clientWidth/2),t.style.left=parseFloat(t.style.left)+r+"px"),i-(h+h/1.5)<p.img.destTop?t.style.top=p.img.destTop+"px":t.style.top=i-(h+h/1.5)+"px"):e?(p.notify("freehand-draw",{prop:"getFreehandSelectedIndex",onPropertyChange:!(n={freehandSelectedIndex:-1}),value:{obj:n}}),p.notify("shape",{prop:"getHighestOrder",onPropertyChange:!(a={order:null}),value:{obj:a}}),p.getObjFromId(p.pointColl[n.freehandSelectedIndex].id).order>=a.order?document.getElementById(p.element.id+"_bringToFront").classList.add("e-disabled"):document.getElementById(p.element.id+"_bringToFront").classList.remove("e-disabled"),p.notify("freehand-draw",{prop:"getSqPtFD",value:{idx:n.freehandSelectedIndex,obj:s={activePoint:null}}}),l=s.activePoint,t.style.width="auto",t.style.left=l.startX+l.width/2-24*o.length+"px",l.startY-(h+h/1.5)<p.img.destTop?t.style.top=p.img.destTop+"px":t.style.top=l.startY-(h+h/1.5)+"px"):t.style.display="none",parseFloat(t.style.top)<0)&&(t.style.top="0px")},Y.prototype.refreshDropDownBtn=function(e){var t,o;!O.isNullOrUndefined(e)&&(t=this.parent.element.id,(o=document.querySelector("#"+t+"_annotationBtn"))&&(e?(o.classList.add("e-disabled"),o.parentElement.classList.add("e-overlay")):(o.classList.remove("e-disabled"),o.parentElement.classList.remove("e-overlay")),O.getComponent(o,"dropdown-btn").disabled=e),(o=document.querySelector("#"+t+"_transformBtn"))&&(e?(o.classList.add("e-disabled"),o.parentElement.classList.add("e-overlay")):(o.classList.remove("e-disabled"),o.parentElement.classList.remove("e-overlay")),O.getComponent(o,"dropdown-btn").disabled=e),(o=document.querySelector("#"+t+"_adjustment"))&&(e?(o.classList.add("e-disabled"),o.parentElement.classList.add("e-overlay")):(o.classList.remove("e-disabled"),o.parentElement.classList.remove("e-overlay")),O.getComponent(o,"btn").disabled=e),o=document.querySelector("#"+t+"_filter"))&&(e?(o.classList.add("e-disabled"),o.parentElement.classList.add("e-overlay")):(o.classList.remove("e-disabled"),o.parentElement.classList.remove("e-overlay")),O.getComponent(o,"btn").disabled=e)},Y.prototype.cropSelect=function(e){var t=this.parent,e=(t.isCropTab=!0,O.isNullOrUndefined(t.transform.cropZoomFactor)&&(t.transform.cropZoomFactor=t.transform.zoomFactor,t.notify("draw",{prop:"setTempZoomFactor",onPropertyChange:!1,value:{tempZoomFactor:t.transform.zoomFactor}})),t.transform.zoomFactor=t.transform.cropZoomFactor,e.item.id),o=(this.currentToolbar="crop",t.currSelectionPoint=null,t.notify("draw",{prop:"setIsCropSelect",value:{bool:!0}}),{prevObj:null});t.notify("crop",{prop:"getPreviousCropCurrentObj",value:{obj:o}}),t.notify("draw",{prop:"select",onPropertyChange:!1,value:{type:e,startX:null,startY:null,width:null,height:null}}),t.notify("crop",{prop:"setPreviousCropCurrentObj",value:{obj:o.prevObj}}),this.enableDisableTbrBtn(),t.notify("transform",{prop:"disableZoomOutBtn",value:{isZoomOut:!0}})},Y.prototype.quickAccessToolbarClicked=function(e,t){var o=this.parent,i=o.element.id;if(e.item){var r,n=null,a={tempObj:null},s=(o.notify("draw",{prop:"getPrevActObj",onPropertyChange:!1,value:{obj:{prevActObj:null}}}),o.notify("selection",{prop:"getTempActObj",onPropertyChange:!1,value:{obj:a}}),a.tempObj.activePoint.height=Math.abs(a.tempObj.activePoint.height),{isNewPath:null}),l=void 0,p=(o.notify("draw",{prop:"getNewPath",value:{obj:s}}),e.item.id.replace(i+"_","").toLowerCase()),h=void 0,d=void 0,c={freehandSelectedIndex:null},u=void 0,g={order:null};switch(p){case"duplicate":o.element.querySelector("#"+i+"_duplicate").classList.contains("e-disabled")||(this.refreshSlider(),s.isNewPath||JSON.stringify(a.tempObj)!==JSON.stringify(o.activeObj)||(n=!0),this.duplicateShape(n));break;case"remove":o.element.querySelector("#"+i+"_remove").classList.contains("e-disabled")||(o.noPushUndo=!1,this.refreshSlider(),o.notify("selection",{prop:"deleteItem",onPropertyChange:!1}));break;case"edittext":o.element.querySelector("#"+i+"_editText").classList.contains("e-disabled")||this.editText();break;case"rotleft":case"rotright":h=o.element.querySelector("#"+i+"_rotLeft"),d=o.element.querySelector("#"+i+"_rotRight"),(h&&!h.classList.contains("e-disabled")||d&&!d.classList.contains("e-disabled"))&&o.rotateImage(e.item.id.replace(i+"_","").toLowerCase()),o.notify("undo-redo",{prop:"updateUndoRedoStack",onPropertyChange:!1});break;case"hflip":o.element.querySelector("#"+i+"_hFlip").classList.contains("e-disabled")||(l=o.activeObj.imageCanvas.getContext("2d"),o.horizontalFlip(l)),o.notify("undo-redo",{prop:"updateUndoRedoStack",onPropertyChange:!1});break;case"vflip":o.element.querySelector("#"+i+"_vFlip").classList.contains("e-disabled")||(l=o.activeObj.imageCanvas.getContext("2d"),o.verticalFlip(l)),o.notify("undo-redo",{prop:"updateUndoRedoStack",onPropertyChange:!1});break;case"bringtofront":o.element.querySelector("#"+i+"_bringToFront").classList.contains("e-disabled")||(o.notify("freehand-draw",{prop:"getFreehandSelectedIndex",onPropertyChange:!1,value:{obj:c}}),u=null!==c.freehandSelectedIndex?o.pointColl[c.freehandSelectedIndex].id:o.activeObj.currIndex,o.updateShapeOrder(u,p),o.notify("shape",{prop:"getHighestOrder",onPropertyChange:!1,value:{obj:g}}),(-1<u.indexOf("pen")?(o.notify("shape",{prop:"updateShapeColl",onPropertyChange:!1}),r=o.getObjFromId(u).order,g.order<=r):(r=o.getObjFromId(u).order,g.order<r))?document.getElementById(o.element.id+"_bringToFront").classList.add("e-disabled"):document.getElementById(o.element.id+"_bringToFront").classList.remove("e-disabled"),o.notify("undo-redo",{prop:"updateUndoRedoStack",onPropertyChange:!1}))}"duplicate"!==p&&"remove"!==p||o.notify("draw",{prop:"redrawDownScale"})}O.isNullOrUndefined(t)&&o.trigger("quickAccessToolbarItemClick",e)},Y.prototype.editText=function(){var e=this.parent,t={x:e.activeObj.activePoint.startX,y:e.activeObj.activePoint.startY},o=(this.upperContext.clearRect(0,0,e.upperCanvas.width,e.upperCanvas.height),e.notify("selection",{prop:"setTempActObj",onPropertyChange:!1,value:{obj:O.extend({},e.activeObj,{},!0)}}),e.notify("selection",{prop:"setInitialTextEdit",onPropertyChange:!1,value:{bool:!0}}),e.notify("draw",{prop:"setPrevActObj",onPropertyChange:!1,value:{prevActObj:O.extend({},e.activeObj,{},!0)}}),0!==e.activeObj.rotatedAngle&&(o={x:t.x,y:t.y},e.notify("shape",{prop:"getTextBoxPosition",onPropertyChange:!1,value:{obj:e.activeObj,object:o}}),t.x=o.x,t.y=o.y,o={x:t.x,y:t.y},e.notify("shape",{prop:"setFlipState",onPropertyChange:!1,value:{x:t.x,y:t.y,obj:e.activeObj,object:o}}),t.x=o.x,t.y=o.y),O.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=o,e.notify("shape",{prop:"renderTextArea",onPropertyChange:!1,value:{x:t.x,y:t.y,actObj:e.activeObj}}),O.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")},Y.prototype.duplicateShape=function(e,t){var o,i=this.parent,r=(i.notify("selection",{prop:"setTempActObj",onPropertyChange:!1,value:{obj:{activePoint:{startX:0,startY:0,endX:0,endY:0,width:0,height:0},flipObjColl:[],triangle:[],triangleRatio:[]}}}),{prevActObj:null}),n=(i.notify("draw",{prop:"getPrevActObj",onPropertyChange:!1,value:{obj:r}}),i.notify("draw",{prop:"getNewPath",value:{obj:{isNewPath:null}}}),O.extend({},i.activeObj,{},!0)),a={order:null},a=(i.notify("shape",{prop:"getHighestOrder",onPropertyChange:!1,value:{obj:a}}),n.order?i.notify("shape",{prop:"updateShapeColl",onPropertyChange:!1}):(i.noPushUndo=!0,i.okBtn(),i.noPushUndo=!1,i.selectShape(n.currIndex)),n.order=a.order>n.order?a.order+1:n.order+1,"image"===n.shape&&(o=O.extend([],i.objColl,[],!0),i.notify("undo-redo",{prop:"updateUrObj",onPropertyChange:!1,value:{objColl:o}})),O.isNullOrUndefined(i.activeObj.currIndex)?i.notify("shape",{prop:"applyActObj",onPropertyChange:!1,value:{isMouseDown:e}}):r.prevActObj||t?(i.activeObj.currIndex=null,n.currIndex=null,i.notify("shape",{prop:"applyActObj",onPropertyChange:!1,value:{isMouseDown:e}})):i.notify("shape",{prop:"applyActObj",onPropertyChange:!1,value:{isMouseDown:!0}}),i.noPushUndo);if(i.noPushUndo=!1,i.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"ok"}}),i.noPushUndo=a,o=O.extend([],i.objColl,[],!0),n.activePoint.startX+=10,n.activePoint.startY-=10,n.activePoint.endX+=10,n.activePoint.endY-=10,"path"===n.shape)for(var s=0;s<n.pointColl.length;s++)n.pointColl[s].x+=10,n.pointColl[s].y-=10;else"image"===n.shape&&(n.imageCanvas=i.createElement("canvas"));r={id:"shape_"+(i.objColl.length+1)};i.notify("shape",{prop:"getNewShapeId",onPropertyChange:!1,value:{obj:r}}),n.currIndex=r.id,i.activeObj=O.extend({},n,{},!0),"image"===i.activeObj.shape&&(t=O.extend({},n.activePoint,{},!0),i.notify("transform",{prop:"calcMaxDimension",onPropertyChange:!(e={width:0,height:0}),value:{width:i.activeObj.imageElement.width,height:i.activeObj.imageElement.height,obj:e,isImgShape:null}}),i.activeObj.activePoint.width=e.width,i.activeObj.activePoint.height=e.height,i.activeObj.isHorImageFlip&&i.activeObj.isVerImageFlip?(i.activeObj.isHorImageFlip=i.activeObj.isVerImageFlip=!1,i.notify("draw",{prop:"downScaleImgCanvas",onPropertyChange:!1,value:{ctx:n.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:n.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:n.imageCanvas.getContext("2d"),isImgAnnotation:!0,isHFlip:null,isVFlip:!0}}),i.activeObj.isVerImageFlip=!0):i.notify("draw",{prop:"downScaleImgCanvas",onPropertyChange:!1,value:{ctx:n.imageCanvas.getContext("2d"),isImgAnnotation:!0,isHFlip:null,isVFlip:null}}),i.activeObj.activePoint=t),"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:o}}),this.renderQAT()},Y.prototype.defToolbarClicked=function(e){var t,o,i,r,n=this.parent,a=n.element.id,s=!1,l=!1;!this.isFrameToolbar&&n.element.querySelector(".e-contextual-toolbar-wrapper")&&(n.element.querySelector(".e-contextual-toolbar-wrapper").classList.contains("e-hide")||(s=l=!0),t=n.isStraightening,O.Browser.isDevice&&(!O.Browser.isDevice||t)||n.element.querySelector(".e-contextual-toolbar-wrapper").classList.add("e-hide")),e.item&&("duplicate"===(t=e.item.id.replace(a+"_","").toLowerCase())||"remove"===t||"edittext"===t||"hflip"===t||"vflip"===t||"rotleft"===t||"rotright"===t?(this.quickAccessToolbarClicked(e,!0),n.trigger("toolbarItemClicked",e)):(i=o=!1,(r=document.querySelector("#"+a+"_adjustment"))&&r.classList.contains("e-disabled")&&(i=!0),(r=document.querySelector("#"+a+"_filter"))&&r.classList.contains("e-disabled")&&(o=!0),this.enableDisableTbrBtn(),this.performDefTbrClick(t,s,i,o,l),n.trigger("toolbarItemClicked",e),n.isStraightening&&n.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(t)&&n.notify("draw",{prop:"redrawDownScale"})))},Y.prototype.performDefTbrClick=function(e,t,o,i,r){var n,a,s=this.parent,l=s.element.id,p=s.element.querySelector("#"+l+"_zoomIn"),h=s.element.querySelector("#"+l+"_resizeHeight"),d=s.element.querySelector("#"+l+"_resizeWidth"),c=!1;if((void 0===(a=void 0!==s.activeObj.shape?s.activeObj.shape.split("-"):a)&&s.currObjType.isCustomCrop||void 0!==a&&"crop"===a[0])&&(c=!0),!s.disabled)switch(e){case"pan":s.currObjType.isCustomCrop=s.currObjType.isFiltered=!1,s.currObjType.isUndoAction&&s.notify("undo-redo",{prop:"refreshUrc",value:{bool:null}}),c&&(s.currObjType.isCustomCrop=!1,s.notify("shape",{prop:"refreshActiveObj",onPropertyChange:!1}),this.upperContext.clearRect(0,0,s.upperCanvas.width,s.upperCanvas.height),this.refreshToolbar("main")),s.togglePan?(this.cancelPan(),s.notify("transform",{prop:"setDisablePan",onPropertyChange:!1,value:{bool:!0}}),"pen"===this.currentToolbar&&s.freeHandDraw(!0)):((n=s.element.querySelector(".e-img-pan .e-btn"))&&n.classList.add("e-selected-btn"),s.pan(!0),s.notify("transform",{prop:"setDisablePan",onPropertyChange:!1,value:{bool:!1}})),p&&s.zoomSettings.zoomFactor>=s.zoomSettings.maxZoomFactor?(p.classList.add("e-disabled"),p.parentElement.classList.add("e-overlay")):p&&(p.classList.remove("e-disabled"),p.parentElement.classList.remove("e-overlay")),this.refreshToolbar("main");break;case"cancel":s.notify("draw",{prop:"performCancel",value:{isContextualToolbar:t,isFinalCancel:!0}});break;case"ok":s.okBtn(null,!0),s.drawingShape=null,this.refreshDropDownBtn(!1),this.currentToolbar="main",s.isStraightening=!1,s.notify("draw",{prop:"resetTempObjColl"}),s.notify("draw",{prop:"resetTempPointColl"});break;case"crop":s.notify("transform",{prop:"disableZoomOutBtn",value:{isZoomOut:!0}}),O.Browser.isDevice&&this.updateContextualToolbar("color","straighten");break;case"reset":s.reset(),this.imageHeight=null,this.imageWidth=null,s.aspectHeight=null,s.aspectWidth=null,this.isAspectRatio=!0,this.currentToolbar="main";break;case"undo":s.noPushUndo=!1,(s.togglePen||s.drawingShape)&&(s.okBtn(),s.drawingShape=null),s.notify("undo-redo",{prop:"call-undo"});break;case"redo":s.noPushUndo=!1,(s.togglePen||s.drawingShape)&&(s.okBtn(),s.drawingShape=null),s.notify("undo-redo",{prop:"call-redo"});break;case"aspectratio":(!s.isCircleCrop&&O.isNullOrUndefined(s.currSelectionPoint)||s.currSelectionPoint&&"crop-circle"!==s.currSelectionPoint.shape)&&(O.getComponent(d,"numerictextbox").value?(s.aspectWidth=O.getComponent(d,"numerictextbox").value,s.aspectHeight=O.getComponent(h,"numerictextbox").value,s.notify("transform",{prop:"resize",value:{width:s.aspectWidth,height:null,isAspectRatio:!0}})):O.getComponent(h,"numerictextbox").value&&(s.aspectWidth=parseFloat(O.getComponent(d,"numerictextbox").placeholder),s.aspectHeight=O.getComponent(h,"numerictextbox").value,s.notify("transform",{prop:"resize",value:{width:s.aspectWidth,height:s.aspectHeight,isAspectRatio:!0}})),s.resizeSrc={startX:s.img.srcLeft,startY:s.img.srcTop,width:s.img.srcWidth,height:s.img.srcHeight},this.refreshToolbar("resize"));break;case"nonaspectratio":(O.getComponent(d,"numerictextbox").value||O.getComponent(h,"numerictextbox").value)&&(s.aspectWidth=O.getComponent(d,"numerictextbox").value?O.getComponent(d,"numerictextbox").value:parseFloat(O.getComponent(d,"numerictextbox").placeholder),s.aspectHeight=O.getComponent(h,"numerictextbox").value?O.getComponent(h,"numerictextbox").value:parseFloat(O.getComponent(h,"numerictextbox").placeholder),s.notify("transform",{prop:"resize",value:{width:s.aspectWidth,height:s.aspectHeight,isAspectRatio:!1}})),s.resizeSrc={startX:s.img.srcLeft,startY:s.img.srcTop,width:s.img.srcWidth,height:s.img.srcHeight},this.refreshToolbar("resize");break;case"resize":s.currObjType.isFiltered&&s.okBtn(),this.resizeClick();break;case"adjustment":o||(s.currObjType.isFiltered&&s.okBtn(),this.refreshToolbar("adjustment"),s.setTempFilterProperties(),s.notify("draw",{prop:"updateFinetune"}),s.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":i||(u.showSpinner(s.element),this.refreshToolbar("filter"),s.setTempFilterProperties(),u.hideSpinner(s.element));break;case"default":case"chrome":case"cold":case"warm":case"grayscale":case"blackandwhite":case"sepia":case"invert":case"sharpen":s.currObjType.isFiltered=!0,s.notify("filter",{prop:"applyImageFilter",value:{option:e}});break;case"upload":r&&s.element.querySelector(".e-contextual-toolbar-wrapper").classList.remove("e-hide");break;case"bold":s.notify("selection",{prop:"setInitialTextEdit",value:{bool:!1}}),s.activeObj.textSettings.bold&&s.activeObj.textSettings.italic?s.notify("shape",{prop:"applyFontStyle",onPropertyChange:!1,value:{item:"italic"}}):s.activeObj.textSettings.bold&&!s.activeObj.textSettings.italic?s.notify("shape",{prop:"applyFontStyle",onPropertyChange:!1,value:{item:"default"}}):!s.activeObj.textSettings.bold&&s.activeObj.textSettings.italic?s.notify("shape",{prop:"applyFontStyle",onPropertyChange:!1,value:{item:"bolditalic"}}):s.activeObj.textSettings.bold||s.activeObj.textSettings.italic||s.notify("shape",{prop:"applyFontStyle",onPropertyChange:!1,value:{item:"bold"}}),s.element.querySelector("#"+l+"_bold").classList.contains("e-selected-btn")?s.element.querySelector("#"+l+"_bold").classList.remove("e-selected-btn"):s.element.querySelector("#"+l+"_bold").classList.add("e-selected-btn"),0===s.activeObj.activePoint.width&&0===s.activeObj.activePoint.height||s.notify("undo-redo",{prop:"updateUndoRedoStack",onPropertyChange:!1});break;case"italic":s.notify("selection",{prop:"setInitialTextEdit",value:{bool:!1}}),s.activeObj.textSettings.bold&&s.activeObj.textSettings.italic?s.notify("shape",{prop:"applyFontStyle",onPropertyChange:!1,value:{item:"bold"}}):s.activeObj.textSettings.bold&&!s.activeObj.textSettings.italic?s.notify("shape",{prop:"applyFontStyle",onPropertyChange:!1,value:{item:"bolditalic"}}):!s.activeObj.textSettings.bold&&s.activeObj.textSettings.italic?s.notify("shape",{prop:"applyFontStyle",onPropertyChange:!1,value:{item:"default"}}):s.activeObj.textSettings.bold||s.activeObj.textSettings.italic||s.notify("shape",{prop:"applyFontStyle",onPropertyChange:!1,value:{item:"italic"}}),s.element.querySelector("#"+l+"_italic").classList.contains("e-selected-btn")?s.element.querySelector("#"+l+"_italic").classList.remove("e-selected-btn"):s.element.querySelector("#"+l+"_italic").classList.add("e-selected-btn"),0===s.activeObj.activePoint.width&&0===s.activeObj.activePoint.height||s.notify("undo-redo",{prop:"updateUndoRedoStack",onPropertyChange:!1});break;case"croptransform":this.performCropTransformClick();break;case"rotateleft":case"rotateright":case"horizontalflip":case"verticalflip":s.transformSelect(e),"rotateleft"!==e&&"rotateright"!==e||(s.notify("draw",{prop:"resetStraightenDestPoints"}),s.notify("draw",{prop:"setDestForStraighten"})),s.notify("transform",{prop:"disableZoomOutBtn",value:{isZoomOut:!0}}),O.Browser.isDevice&&this.updateContextualToolbar("color","straighten");break;case"save":s.noPushUndo=!1,s.okBtn(),s.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(),s.element.querySelector("#"+l+"_"+e)&&s.element.querySelector("#"+l+"_"+e).classList.add("e-selected-btn"),s.frameObj.type=e,s.frameObj.size=20,s.frameObj.inset=20,s.frameObj.radius=0,s.frameObj.amount=1,s.frameObj.offset="inset"===e?60:20,this.refreshToolbar("frame"),s.notify("draw",{prop:"render-image",value:{isMouseWheel:null,isPreventClearRect:null,isFrame:!0}}),s.isFrameBtnClick=!0,s.curFrameObjEvent={previousFrameSetting:s.tempFrameObj,currentFrameSetting:s.frameObj}}},Y.prototype.frameToolbarClick=function(){var e,t,o=this.parent,i=o.element.id,r=document.querySelector("#"+i+"_frame");o.notify("draw",{prop:"updateCropSelection",onPropertyChange:!1}),o.currObjType.isFiltered&&o.okBtn(),r&&!r.classList.contains("e-disabled")&&(r=o.transform.zoomFactor,o.frameDestPoints=O.extend({},o.img,{},!0),O.isNullOrUndefined(o.cxtTbarHeight)&&(e=O.extend({},o.frameObj,{},!0),t=O.extend({},o.tempFrameObj,{},!0),this.callFrameToolbar(),o.frameObj.type="mat",this.callFrameToolbar(),o.cxtTbarHeight=o.element.querySelector("#"+i+"_customizeWrapper").scrollHeight,o.frameObj=e,o.tempFrameObj=t),this.zoomToFrameRange(),o.tempFrameZoomLevel=r,O.Browser.isDevice?o.img.destTop-=o.cxtTbarHeight/2:o.img.destTop+=o.cxtTbarHeight/2,this.callFrameToolbar())},Y.prototype.zoomToFrameRange=function(){for(var e=this.parent,t=(this.isFrameToolbar=!1,e.notify("transform",{prop:"resetZoom",onPropertyChange:!1}),!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},Y.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")},Y.prototype.callFrameToolbar=function(){var e=this.parent,t=(O.extend(e.tempFrameObj,e.frameObj),{appliedUndoRedoColl:[]});e.notify("undo-redo",{prop:"getAppliedUndoRedoColl",value:{obj:t}}),0===t.appliedUndoRedoColl.length&&(e.notify("filter",{prop:"getCurrentObj",onPropertyChange:!(t={currObj:{}}),value:{object:t}}),e.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"frame",previousObj:t.currObj,previousObjColl:t.currObj.objColl,previousPointColl:t.currObj.pointColl,previousSelPointColl:t.currObj.selPointColl,previousCropObj:O.extend({},e.cropObj,{},!0),previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}})),this.refreshToolbar("frame")},Y.prototype.contextualToolbarClicked=function(e){var t=this.parent,o=t.element.querySelector(".e-contextual-toolbar-wrapper .e-toolbar-item.e-selected"),o=(o&&o.classList.remove("e-selected"),e.item.id.replace(t.element.id,"").split("_")[1]),i={filter:t.toPascalCase(o),cancel:!1};t.trigger("imageFiltering",i),i.cancel||(document.getElementById(e.item.id+"Canvas").parentElement.parentElement.classList.add("e-selected"),t.currObjType.isFiltered=!0,t.notify("filter",{prop:"applyImageFilter",value:{option:o.toLowerCase()}}),t.notify("draw",{prop:"redrawDownScale"}),t.currentFilter=e.item.id,this.enableDisableTbrBtn(),t.isFilterCanvasClick=!0,t.curFilterObjEvent=i)},Y.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))},Y.prototype.zoomInBtnClickHandler=function(e){if(e){var t=this.parent;if((t.zoomSettings.zoomTrigger&v.ZoomTrigger.Toolbar)===v.ZoomTrigger.Toolbar){t.noPushUndo=!1,t.currObjType.isFiltered&&t.okBtn();var o=t.drawingShape;if(t.drawingShape&&(i=t.activeObj.currIndex,t.noPushUndo=!0,t.okBtn(),t.noPushUndo=!1,t.drawingShape=null,i)&&t.selectShape(i),this.refreshShapeDrawing(),O.Browser.isDevice&&"touchstart"===e.type){if(!e.returnValue)return;e.preventDefault()}var i=document.querySelector("#"+t.element.id+"_zoomIn"),e=(O.EventHandler.trigger(i,"click"),{bool:!1});t.notify("selection",{prop:"getFreehandDrawEditing",onPropertyChange:!1,value:{obj:e}}),e.bool&&(t.notify("freehand-draw",{prop:"applyFhd",onPropertyChange:!1}),this.destroyQuickAccessToolbar()),t.isZoomBtnClick=!0,this.applyPreviewFilter(),t.currObjType.isFiltered=!1,t.togglePen&&(t.currObjType.isZoomed=!0,t.freeHandDraw(!1),t.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"ok"}})),t.notify("draw",{prop:"resetCurrentSelectionPoint"}),t.drawingShape=o,t.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:.1,zoomPoint:null,isResize:null}}),t.notify("draw",{prop:"redrawDownScale"}),(t.isCropTab||t.activeObj.shape)&&(t.notify("draw",{prop:"setStraightenActObj",value:{activeObj:null}}),t.notify("freehand-draw",{prop:"resetStraightenPoint"})),t.isStraightening&&(t.notify("draw",{prop:"resetStraightenDestPoints"}),t.notify("draw",{prop:"setDestForStraighten"}))}}},Y.prototype.zoomOutBtnClickHandler=function(e){if(e){var t=this.parent;if((t.zoomSettings.zoomTrigger&v.ZoomTrigger.Toolbar)===v.ZoomTrigger.Toolbar){t.noPushUndo=!1,t.currObjType.isFiltered&&t.okBtn();var o=t.drawingShape;if(t.drawingShape&&(i=t.activeObj.currIndex,t.noPushUndo=!0,t.okBtn(),t.noPushUndo=!1,t.drawingShape=null,i)&&t.selectShape(i),this.refreshShapeDrawing(),O.Browser.isDevice&&"touchstart"===e.type){if(!e.returnValue)return;e.preventDefault()}var i=document.querySelector("#"+t.element.id+"_zoomOut"),e=(O.EventHandler.trigger(i,"click"),{bool:!1});t.notify("selection",{prop:"getFreehandDrawEditing",onPropertyChange:!1,value:{obj:e}}),e.bool&&(t.notify("freehand-draw",{prop:"applyFhd",onPropertyChange:!1}),this.destroyQuickAccessToolbar()),t.isZoomBtnClick=!0,this.applyPreviewFilter(),t.currObjType.isFiltered=!1,t.togglePen&&(t.currObjType.isZoomed=!0,t.freeHandDraw(!1),t.notify("undo-redo",{prop:"updateCurrUrc",value:{type:"ok"}})),t.notify("draw",{prop:"resetCurrentSelectionPoint"}),t.drawingShape=o,t.notify("transform",{prop:"zoomAction",onPropertyChange:!1,value:{zoomFactor:-.1,zoomPoint:null,isResize:null}}),t.notify("draw",{prop:"redrawDownScale"}),(t.isCropTab||t.activeObj.shape)&&(t.notify("draw",{prop:"setStraightenActObj",value:{activeObj:null}}),t.notify("freehand-draw",{prop:"resetStraightenPoint"})),t.isStraightening&&(t.notify("draw",{prop:"resetStraightenDestPoints"}),t.notify("draw",{prop:"setDestForStraighten"}))}}},Y.prototype.zoomInBtnMouseDownHandler=function(e){e.preventDefault(),this.zoomBtnHold=setInterval(this.zoomInBtnClickHandler.bind(this),250)},Y.prototype.zoomOutBtnMouseDownHandler=function(e){e.preventDefault(),this.zoomBtnHold=setInterval(this.zoomOutBtnClickHandler.bind(this),250)},Y.prototype.zoomBtnMouseUpHandler=function(){clearInterval(this.zoomBtnHold),this.zoomBtnHold=0},Y.prototype.closeContextualToolbar=function(){var e=this.parent,t=e.element.id,o=!1,i=e.isStraightening;return(!O.Browser.isDevice||O.Browser.isDevice&&!i)&&(e.element.querySelector("#"+t+"_contextualToolbar")&&!e.element.querySelector("#"+t+"_contextualToolbar").parentElement.classList.contains("e-hide")||e.element.querySelector("#"+t+"_headWrapper")&&!e.element.querySelector("#"+t+"_headWrapper").parentElement.classList.contains("e-hide"))&&(e.element.querySelector(".e-contextual-toolbar-wrapper").classList.add("e-hide"),e.okBtn(),this.refreshMainToolbar(),o=!0),o},Y.prototype.destroyQuickAccessToolbar=function(){var e=this.parent.element.id,t=document.getElementById(e+"_quickAccessToolbar"),t=(t&&t.classList.contains("e-control")&&O.getComponent(t,"toolbar").destroy(),document.getElementById(e+"_quickAccessToolbarArea"));t&&(t.style.display="none")},Y.prototype.renderSlider=function(e,t){var o,i,r,n=this.parent,a=n.element.id,s=document.querySelector("#"+a+"_contextualToolbarArea"),l=document.querySelector("#"+a+"_headWrapper"),p=document.querySelector("#"+a+"_labelWrapper"),p=(l&&(l.remove(),p.remove()),l=s.appendChild(n.createElement("div",{id:a+"_headWrapper",styles:"position: relative"})),(p="transparency"===e?l.appendChild(n.createElement("label",{id:a+"_labelWrapper",className:"e-ie-finetune-slider-label",styles:O.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;"})):l.appendChild(n.createElement("label",{id:a+"_labelWrapper",className:"e-ie-finetune-slider-label",styles:O.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(n.toPascalCase("transparency"===e?"opacity":e)),l.appendChild(n.createElement("div",{id:a+"_sliderWrapper",className:"e-ie-finetune-slider-wrap",styles:"position: absolute"}))),h=n.getCurrAdjustmentValue(e);t&&"straighten"===e&&O.Browser.isDevice&&(h=n.cropObj.straighten),"brightness"===e||"contrast"===e||"saturation"===e||"exposure"===e?(i=n.finetuneSettings?"brightness"===e&&n.finetuneSettings.brightness?(o=n.finetuneSettings.brightness.min,n.finetuneSettings.brightness.max):"contrast"===e&&n.finetuneSettings.contrast?(o=n.finetuneSettings.contrast.min,n.finetuneSettings.contrast.max):"saturation"===e&&n.finetuneSettings.saturation?(o=n.finetuneSettings.saturation.min,n.finetuneSettings.saturation.max):"exposure"===e&&n.finetuneSettings.exposure?(o=n.finetuneSettings.exposure.min,n.finetuneSettings.exposure.max):(o=-100,100):(o=-100,100),r=this.createSlider(o,i,h,e)):"hue"===e||"blur"===e||"opacity"===e?(i=n.finetuneSettings?"hue"===e&&n.finetuneSettings.hue?(o=n.finetuneSettings.hue.min,n.finetuneSettings.hue.max):"blur"===e&&n.finetuneSettings.blur?(o=n.finetuneSettings.blur.min,n.finetuneSettings.blur.max):"opacity"===e&&n.finetuneSettings.opacity?(o=n.finetuneSettings.opacity.min,n.finetuneSettings.opacity.max):(o=0,100):(o=0,100),r=this.createSlider(o,i,h,e)):"transparency"===e?r=this.createSlider(o=0,i=100,h,e):"straighten"===e&&(r=this.createSlider(o=-45,i=45,h,e)),r.appendTo("#"+a+"_sliderWrapper"),p.style.left=(parseFloat(s.style.width)-parseFloat(r.width))/2+"px","straighten"===e&&O.Browser.isDevice&&(l.appendChild(n.createElement("label",{id:a+"_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=n.transform.straighten.toString()+"°",p.parentElement.classList.add("e-straighten-slider")),"straighten"!==e&&(l.appendChild(n.createElement("label",{id:a+"_finetuneSpan",className:"e-ie-finetune-value-span",styles:O.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;"})),p.parentElement.classList.add("e-finetune-slider"),"transparency"===e&&O.Browser.isDevice&&p.parentElement.classList.add("e-ie-device-transparency-slider"),this.updateFinetuneSpan(e))},Y.prototype.createSlider=function(e,t,o,r){var n=this,a=this.parent;return new g.Slider({value:o,type:"MinRange",min:e,max:t,step:"straighten"===r?3:1,width:O.Browser.isDevice?"180px":"straighten"===r?"200px":"300px",cssClass:"e-slider",change:function(e){var t,o,i;a.notify("selection",{prop:"setSliderActive",onPropertyChange:!1,value:{bool:!0}}),"transparency"===r?a.activeObj.shape&&(O.isNullOrUndefined(a.activeObj.imageRatio)&&a.notify("shape",{prop:"updImgRatioForActObj",onPropertyChange:!1}),a.notify("shape",{prop:"pushActItemIntoObj"}),t=O.extend({},a.cropObj,{},!0),a.notify("filter",{prop:"getCurrentObj",onPropertyChange:!(o={currObj:{}}),value:{object:o}}),(o=o.currObj).objColl=O.extend([],a.objColl,[],!0),o.pointColl=O.extend([],a.pointColl,[],!0),o.afterCropActions=O.extend([],a.afterCropActions,[],!0),a.notify("freehand-draw",{prop:"getSelPointColl",onPropertyChange:!(i={selPointColl:null}),value:{obj:i}}),o.selPointColl=O.extend([],i.selPointColl,[],!0),a.objColl.pop(),a.activeObj.opacity=e.value/100,n.upperContext.clearRect(0,0,a.upperCanvas.width,a.upperCanvas.height),a.notify("draw",{prop:"drawObject",onPropertyChange:!1,value:{canvas:"duplicate"}}),a.objColl.push(a.activeObj),a.notify("undo-redo",{prop:"updateUndoRedoColl",onPropertyChange:!1,value:{operation:"shapeTransform",previousObj:o,previousObjColl:o.objColl,previousPointColl:o.pointColl,previousSelPointColl:o.selPointColl,previousCropObj:t,previousText:null,currentText:null,previousFilter:null,isCircleCrop:null}}),a.notify("selection",{prop:"redrawShape",value:{obj:a.objColl[a.objColl.length-1]}}),n.updateFinetuneSpan(r)):"straighten"===r?a.setStraighten(e.value):(a.transform.zoomFactor&&a.transform.zoomFactor<0&&(a.isFinetuning=!0),a.notify("selection",{prop:"setSliding",value:{bool:!0}}),a.setCurrAdjustmentValue(r,e.value),n.updateFinetuneSpan(r),n.enableDisableTbrBtn(),a.isFinetuning=!1)},changed:function(){"transparency"!==r&&"straighten"!==r&&(a.notify("selection",{prop:"setSliding",value:{bool:!1}}),a.notify("draw",{prop:"redrawDownScale"})),a.notify("selection",{prop:"setSliderActive",onPropertyChange:!1,value:{bool:!1}}),"transparency"===r&&(a.notify("undo-redo",{prop:"updateUndoRedoStack",onPropertyChange:!1}),a.element.querySelector("#"+a.element.id+"_transparency").click())}})},Y.prototype.updateFinetuneSpan=function(e){var t=this.parent,o=t.element.querySelector(".e-ie-finetune-value-span");o&&(t.notify("filter",{prop:"getAdjustmentLevel",onPropertyChange:!(t={adjustmentLevel:null}),value:{obj:t}}),o.innerHTML=Math.round(t.adjustmentLevel[e]).toString())},Y.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)},Y.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=document.querySelector(o[t]);if(i&&i.classList.contains("e-selected-btn")){i.classList.remove("e-selected-btn");break}}},Y.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")},Y.prototype.refreshSlider=function(){var e=this.parent.element.id,t=document.querySelector("#"+e+"_sliderWrapper"),o=document.querySelector(".e-slider"),e=document.querySelector("#"+e+"_headWrapper");e&&(e.style.display="none"),t&&o&&(o.ej2_instances[0].destroy(),t.remove())},Y.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=document.querySelector(o[t]);if(i.classList.contains("e-selected-btn")){i.classList.remove("e-selected-btn");break}}},Y.prototype.updateToolbarItems=function(){var e=this.parent,t=e.element.id;if(e.isImageLoaded&&this.isToolbar()){var o,i=e.element.querySelector(".e-fill.e-template .e-dropdownbtn-preview"),r=e.element.querySelector(".e-stroke.e-template .e-dropdownbtn-preview"),n=e.element.querySelector(".e-text-font-color.e-template .e-dropdownbtn-preview"),a=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("#"+t+"_bold"),d=e.element.querySelector("#"+t+"_italic");if(e.activeObj.strokeSettings&&e.activeObj.textSettings){if(O.isNullOrUndefined(e.activeObj.strokeSettings.strokeWidth)&&(e.activeObj.strokeSettings.strokeWidth=2),i&&(o=e.activeObj.strokeSettings.fillColor,""===e.activeObj.strokeSettings.fillColor?i.classList.add("e-nocolor-item"):(i.classList.remove("e-nocolor-item"),i.style.background=o),document.querySelector("#"+t+"_shape_fill"))&&(O.getComponent(t+"_shape_fill","colorpicker").value=o),r&&(o=e.activeObj.strokeSettings.strokeColor,r.style.background=o,document.querySelector("#"+t+"_shape_stroke"))&&(O.getComponent(t+"_shape_stroke","colorpicker").value=o),n&&(o=e.activeObj.strokeSettings.strokeColor,n.style.background=o,document.querySelector("#"+t+"_text_font"))&&(O.getComponent(t+"_text_font","colorpicker").value=o),a&&(o=e.activeObj.strokeSettings.strokeColor,a.style.background=o,document.querySelector("#"+t+"_pen_stroke")&&(O.getComponent(t+"_pen_stroke","colorpicker").value=o),e.notify("freehand-draw",{prop:"getPenOpacity",onPropertyChange:!1,value:{obj:{penOpacity:1}}})),l&&(O.Browser.isDevice?l.setAttribute("style","font-family:"+e.activeObj.textSettings.fontFamily.toLowerCase()):l.textContent=e.activeObj.textSettings.fontFamily),p)for(var c=0;c<e.fontSizeColl.length;c++)if(parseInt(e.fontSizeColl[c].text,10)>=Math.round(e.activeObj.textSettings.fontSize)){p.textContent=(c+1).toString();break}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&&(i=Math.round(e.activeObj.strokeSettings.strokeWidth).toString(),s.textContent=this.getStrokeWidth(i))}}},Y.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},Y.prototype.cancelPan=function(){var e=this.parent,t=(e.notify("shape",{prop:"applyActObj",onPropertyChange:!1,value:{isMouseDown:!0}}),e.element.querySelector(".e-img-pan .e-btn"));t&&t.classList.remove("e-selected-btn"),e.pan(!1)},Y.prototype.refreshMainToolbar=function(){"main"!==this.currToolbar&&this.refreshToolbar("main")},Y.prototype.destroySubComponents=function(){for(var e=this.parent,t=e.element.querySelectorAll("input.e-control"),o=e.element.querySelectorAll("button.e-control"),i=0,r=t.length;i<r;i++)t[i].classList.contains("e-color-picker")&&(O.getComponent(t[i],"color-picker").destroy(),O.detach(O.select("input#"+t[i].id,e.element)));for(i=0,r=o.length;i<r;i++)o[i].classList.contains("e-dropdown-btn")?(O.getComponent(o[i],"dropdown-btn").destroy(),O.detach(O.select("button#"+o[i].id,e.element))):o[i].classList.contains("e-btn")&&(O.getComponent(o[i],"btn").destroy(),O.detach(O.select("button#"+o[i].id,e.element)))},Y.prototype.setInitialShapeSettings=function(e){var t=this.parent,e=(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=[],{order:null});t.notify("shape",{prop:"getNewOrder",onPropertyChange:!1,value:{obj:e}}),t.activeObj.order=e.order},Y.prototype.isToolbarString=function(e){for(var t=!1,o=0;o<e.length;o++)if("string"==typeof e[o]){t=!0;break}return t},Y.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;0<=o;o--)this.defToolbarItems.splice(r[o],1)},Y.prototype.isSameIndex=function(e,t){for(var o=0;o<e.length;o++)if(e[o]===t)return!0;return!1},Y.prototype.getIndex=function(e){var t=-1,o=!1;"fontColor"===(e="arrowEnd"===(e="arrowStart"===(e="verticalFlip"===(e="horizontalFlip"===(e="rotateRight"===(e="rotateLeft"===e?"rotLeft":e)?"rotRight":e)?"hflip":e)?"vflip":e)?"start":e)?"end":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},Y.prototype.getModuleName=function(){return"toolbar-module"};var q=Y;function Y(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()}v.Crop=o,v.Draw=i,v.Export=r,v.Filter=a,v.FinetuneSettings=U,v.FontFamily=N,v.FreehandDrawing=l,v.ImageEditor=j,v.Selection=h,v.SelectionSettings=_,v.Shape=H,v.ToolbarModule=q,v.Transform=B,v.UndoRedo=M,v.ZoomSettings=W,Object.defineProperty(v,"__esModule",{value:!0})});
|
|
11
11
|
//# sourceMappingURL=ej2-image-editor.umd.min.js.map
|