!function(){"use strict";function t(t,e){return n(document.createElement("canvas"),t,e)}function e(t){return t.getContext("2d")}function n(t,e,n){return t.width=e,t.height=n,t}function o(t){return new U(function(e,n){function o(){u(),e(a)}function r(){u(),n("Unable to load data of type "+t.type+": "+i)}var i=URL.createObjectURL(t),a=new Image,u=function(){a.removeEventListener("load",o),a.removeEventListener("error",r)};a.addEventListener("load",o),a.addEventListener("error",r),a.src=i,a.complete&&o()})}function r(t){return new U(function(e){var n=new XMLHttpRequest;n.open("GET",t,!0),n.responseType="blob",n.onload=function(){200==this.status&&e(this.response)},n.send()})}function i(t){var e=t.split(","),n=/data:([^;]+)/.exec(e[0]);if(!n)return H.none();for(var o=n[1],r=e[1],i=V.atob(r),a=i.length,u=Math.ceil(a/1024),c=new Array(u),l=0;ln?t=n:tn?t=n:t2)&&(i=i<.5?.5:2,u=!0),(a<.5||a>2)&&(a=a<.5?.5:2,u=!0);var c=function(t,e,n){return new U(function(o){var r=B.getWidth(t),i=B.getHeight(t),a=Math.floor(r*e),u=Math.floor(i*n),c=C.create(a,u),l=C.get2dContext(c);l.drawImage(t,0,0,r,i,0,0,a,u),o(c)})}(t,i,a);return u?c.then(function(t){return y(t,e,n)}):c}function b(t){return{blob:t,url:rt.createObjectURL(t)}}function w(t){t&&rt.revokeObjectURL(t.url)}function x(t){k.each(t,w)}function R(t,e,n,o){function r(t){var e,n,o,r;e=R.find("#w")[0],n=R.find("#h")[0],o=parseInt(e.value(),10),r=parseInt(n.value(),10),R.find("#constrain")[0].checked()&&X&&$&&o&&r&&("w"===t.control.settings.name?(r=Math.round(o*G),n.value(r)):(o=Math.round(r*Y),e.value(o))),X=o,$=r}function i(t){return Math.round(100*t)+"%"}function a(){R.find("#undo").disabled(!J.canUndo()),R.find("#redo").disabled(!J.canRedo()),R.statusbar.find("#save").disabled(!J.canUndo())}function u(){R.find("#undo").disabled(!0),R.find("#redo").disabled(!0)}function c(t){t&&j.imageSrc(t.url)}function l(t){return function(){var e=k.grep(N,function(e){return e.settings.name!==t});k.each(e,function(t){t.hide()}),t.show(),t.focus()}}function s(t){c(C=b(t))}function f(t){c(e=b(t)),x(J.add(e).removed),a()}function d(){var t=j.selection();nt.blobToImageResult(e.blob).then(function(e){tt.crop(e,t.x,t.y,t.w,t.h).then(Z).then(function(t){f(t),h()})})}function h(){c(e),w(C),l(I)(),a()}function p(e,n){C?n():setTimeout(function(){e-- >0?p(e,n):t.windowManager.alert("Error: failed to apply image operation.")},10)}function m(){C?(f(C.blob),h()):p(100,m)}function g(t){return kt.create("Form",{layout:"flex",direction:"row",labelGap:5,border:"0 0 1 0",align:"center",pack:"center",padding:"0 10 0 10",spacing:5,flex:0,minHeight:60,defaults:{classes:"imagetool",type:"button"},items:t})}function v(t,n){return g([{text:"Back",onclick:h},{type:"spacer",flex:1},{text:"Apply",subtype:"primary",onclick:m}]).hide().on("show",function(){u(),nt.blobToImageResult(e.blob).then(function(t){return n(t)}).then(Z).then(function(t){var e=b(t);c(e),w(C),C=e})})}function y(t,n,o,r,a){return g([{text:"Back",onclick:h},{type:"spacer",flex:1},{type:"slider",flex:1,ondragend:function(t){!function(t){nt.blobToImageResult(e.blob).then(function(e){return n(e,t)}).then(Z).then(function(t){var e=b(t);c(e),w(C),C=e})}(t.value)},minValue:r,maxValue:a,value:o,previewFilter:i},{type:"spacer",flex:1},{text:"Apply",subtype:"primary",onclick:m}]).hide().on("show",function(){this.find("slider").value(o),u()})}var R,I,T,C,B,U,M,j,A,z,E,S,L,H,O,_,D,F,P,W,q,V,N,X,$,G,Y,J=Ct(),K=function(t){var n=[].slice.call(arguments,1);return function(){var o=C||e;nt.blobToImageResult(o.blob).then(function(e){t.apply(this,[e].concat(n)).then(Z).then(s)})}},Z=function(t){return t.toBlob()};B=g([{text:"Back",onclick:h},{type:"spacer",flex:1},{text:"Apply",subtype:"primary",onclick:d}]).hide().on("show hide",function(t){j.toggleCropRect("show"===t.type)}).on("show",u),U=g([{text:"Back",onclick:h},{type:"spacer",flex:1},{type:"textbox",name:"w",label:"Width",size:4,onkeyup:r},{type:"textbox",name:"h",label:"Height",size:4,onkeyup:r},{type:"checkbox",name:"constrain",text:"Constrain proportions",checked:!0,onchange:function(t){!0===t.control.value()&&(G=$/X,Y=X/$)}},{type:"spacer",flex:1},{text:"Apply",subtype:"primary",onclick:"submit"}]).hide().on("submit",function(t){var n=parseInt(R.find("#w").value(),10),o=parseInt(R.find("#h").value(),10);t.preventDefault(),function(t){for(var n=[],o=1;o.1&&(t-=.1),j.zoom(t)}}]}),z=kt.create("Container",{type:"container",layout:"flex",direction:"row",align:"stretch",flex:1,items:[A,j]}),N=[I,B,U,M,T,E,S,L,H,O,_,D,F,P,W,q,V],(R=t.windowManager.open({layout:"flex",direction:"column",align:"stretch",minWidth:Math.min(Tt.DOM.getViewPort().w,800),minHeight:Math.min(Tt.DOM.getViewPort().h,650),title:"Edit image",items:N.concat([z]),buttons:[{text:"Save",name:"save",subtype:"primary",onclick:function(){n(e.blob),R.close()}},{text:"Cancel",onclick:"close"}]})).on("close",function(){o(),x(J.data),J=null,C=null}),J.add(e),a(),j.on("load",function(){X=j.imageSize().w,$=j.imageSize().h,G=$/X,Y=X/$,R.find("#w").value(X),R.find("#h").value($)}),j.on("crop",d)}var I=function(t){var e=t,n=function(){return e};return{get:n,set:function(t){e=t},clone:function(){return I(n())}}},T=tinymce.util.Tools.resolve("tinymce.PluginManager"),k=tinymce.util.Tools.resolve("tinymce.util.Tools"),C={create:t,clone:function(n){var o;return o=t(n.width,n.height),e(o).drawImage(n,0,0),o},resize:n,get2dContext:e,get3dContext:function(t){var e=null;try{e=t.getContext("webgl")||t.getContext("experimental-webgl")}catch(n){}return e||(e=null),e}},B={getWidth:function(t){return t.naturalWidth||t.width},getHeight:function(t){return t.naturalHeight||t.height}},U=window.Promise?window.Promise:function(){function t(t,e){return function(){t.apply(e,arguments)}}function e(t){var e=this;null!==this._state?u(function(){var n=e._state?t.onFulfilled:t.onRejected;if(null!==n){var o;try{o=n(e._value)}catch(r){return void t.reject(r)}t.resolve(o)}else(e._state?t.resolve:t.reject)(e._value)}):this._deferreds.push(t)}function n(e){try{if(e===this)throw new TypeError("A promise cannot be resolved with itself.");if(e&&("object"==typeof e||"function"==typeof e)){var a=e.then;if("function"==typeof a)return void i(t(a,e),t(n,this),t(o,this))}this._state=!0,this._value=e,r.call(this)}catch(u){o.call(this,u)}}function o(t){this._state=!1,this._value=t,r.call(this)}function r(){for(var t=0,n=this._deferreds.length;t0?3*e:e),f(t,[.3086*(1-n)+n,.6094*(1-n),.082*(1-n),0,0,.3086*(1-n),.6094*(1-n)+n,.082*(1-n),0,0,.3086*(1-n),.6094*(1-n),.082*(1-n)+n,0,0,0,0,0,1,0,0,0,0,0,1])},adjustHue:function(t,e){var n,o;return e=s(e,-180,180)/180*Math.PI,n=Math.cos(e),o=Math.sin(e),f(t,[.213+.787*n+-.213*o,.715+-.715*n+-.715*o,.072+-.072*n+.928*o,0,0,.213+-.213*n+.143*o,.715+n*(1-.715)+.14*o,.072+-.072*n+-.283*o,0,0,.213+-.213*n+-.787*o,.715+-.715*n+.715*o,.072+.928*n+.072*o,0,0,0,0,0,1,0,0,0,0,0,1])},adjustColors:function(t,e,n,o){return e=s(e,0,2),n=s(n,0,2),o=s(o,0,2),f(t,[e,0,0,0,0,0,n,0,0,0,0,0,o,0,0,0,0,0,1,0,0,0,0,0,1])},adjustSepia:function(t,e){return e=s(e,0,1),f(t,d([.393,.769,.189,0,0,.349,.686,.168,0,0,.272,.534,.131,0,0,0,0,0,1,0,0,0,0,0,1],e))},adjustGrayscale:function(t,e){return e=s(e,0,1),f(t,d([.33,.34,.33,0,0,.33,.34,.33,0,0,.33,.34,.33,0,0,0,0,0,1,0,0,0,0,0,1],e))}},K={invert:function(t){return function(e){return h(e,t)}}([-1,0,0,0,255,0,-1,0,0,255,0,0,-1,0,255,0,0,0,1,0]),brightness:g(J.adjustBrightness),hue:g(J.adjustHue),saturate:g(J.adjustSaturation),contrast:g(J.adjustContrast),grayscale:g(J.adjustGrayscale),sepia:g(J.adjustSepia),colorize:function(t,e,n,o){return h(t,J.adjustColors(J.identity(),e,n,o))},sharpen:v([0,-1,0,-1,5,-1,0,-1,0]),emboss:v([-2,-1,0,-1,1,1,0,1,2]),gamma:m(function(t,e){return 255*Math.pow(t/255,1-e)}),exposure:m(function(t,e){return 255*(1-Math.exp(-t/255*e))}),colorFilter:h,convoluteFilter:p},Z={scale:y},Q={rotate:function(t,e){return t.toCanvas().then(function(n){return function(t,e,n){var o=C.create(t.width,t.height),r=C.get2dContext(o),i=0,a=0;return 90!=(n=n<0?360+n:n)&&270!=n||C.resize(o,o.height,o.width),90!=n&&180!=n||(i=o.width),270!=n&&180!=n||(a=o.height),r.translate(i,a),r.rotate(n*Math.PI/180),r.drawImage(t,0,0),G.fromCanvas(o,e)}(n,t.getType(),e)})},flip:function(t,e){return t.toCanvas().then(function(n){return function(t,e,n){var o=C.create(t.width,t.height),r=C.get2dContext(o);return"v"==n?(r.scale(1,-1),r.drawImage(t,0,-o.height)):(r.scale(-1,1),r.drawImage(t,-o.width,0)),G.fromCanvas(o,e)}(n,t.getType(),e)})},crop:function(t,e,n,o,r){return t.toCanvas().then(function(i){return function(t,e,n,o,r,i){var a=C.create(r,i);return C.get2dContext(a).drawImage(t,-n,-o),G.fromCanvas(a,e)}(i,t.getType(),e,n,o,r)})},resize:function(t,e,n){return t.toCanvas().then(function(o){return Z.scale(o,e,n).then(function(e){return G.fromCanvas(e,t.getType())})})}},tt={invert:function(t){return K.invert(t)},sharpen:function(t){return K.sharpen(t)},emboss:function(t){return K.emboss(t)},brightness:function(t,e){return K.brightness(t,e)},hue:function(t,e){return K.hue(t,e)},saturate:function(t,e){return K.saturate(t,e)},contrast:function(t,e){return K.contrast(t,e)},grayscale:function(t,e){return K.grayscale(t,e)},sepia:function(t,e){return K.sepia(t,e)},colorize:function(t,e,n,o){return K.colorize(t,e,n,o)},gamma:function(t,e){return K.gamma(t,e)},exposure:function(t,e){return K.exposure(t,e)},flip:function(t,e){return Q.flip(t,e)},crop:function(t,e,n,o,r){return Q.crop(t,e,n,o,r)},resize:function(t,e,n){return Q.resize(t,e,n)},rotate:function(t,e){return Q.rotate(t,e)}},et=function(t){return t.toBlob()},nt={blobToImageResult:function(t){return G.fromBlob(t)},fromBlobAndUrlSync:function(t,e){return G.fromBlobAndUrlSync(t,e)},imageToImageResult:function(t){return G.fromImage(t)},imageResultToBlob:function(t,e,n){return e===undefined&&n===undefined?et(t):t.toAdjustedBlob(e,n)},imageResultToOriginalBlob:et,imageResultToDataURL:function(t){return t.toDataURL()}},ot=function(){return F("URL")},rt={createObjectURL:function(t){return ot().createObjectURL(t)},revokeObjectURL:function(t){ot().revokeObjectURL(t)}},it=tinymce.util.Tools.resolve("tinymce.util.Delay"),at=tinymce.util.Tools.resolve("tinymce.util.Promise"),ut=tinymce.util.Tools.resolve("tinymce.util.URI"),ct=function(t){return t.getParam("imagetools_toolbar","rotateleft rotateright | flipv fliph | crop editimage imageoptions")},lt=function(t){return t.getParam("imagetools_proxy")},st={getImageSize:function(t){function e(t){return/^[0-9\.]+px$/.test(t)}var n,o;return n=t.style.width,o=t.style.height,n||o?e(n)&&e(o)?{w:parseInt(n,10),h:parseInt(o,10)}:null:(n=t.width,o=t.height,n&&o?{w:parseInt(n,10),h:parseInt(o,10)}:null)},setImageSize:function(t,e){var n,o;e&&(n=t.style.width,o=t.style.height,(n||o)&&(t.style.width=e.w+"px",t.style.height=e.h+"px",t.removeAttribute("data-mce-style")),n=t.width,o=t.height,(n||o)&&(t.setAttribute("width",e.w),t.setAttribute("height",e.h)))},getNaturalImageSize:function(t){return{w:t.naturalWidth,h:t.naturalHeight}}},ft=(function(){var t=Array.prototype.indexOf;undefined}(),function(t,e){for(var n=0,o=t.length;n=300?xt.handleServiceErrorResponse(t.status,t.blob):at.resolve(t.blob)})},It=function(t,e){return e?Rt(t,e):function(t){return pt.requestUrlAsBlob(t,{}).then(function(t){return t.status<200||t.status>=300?xt.handleHttpError(t.status):at.resolve(t.blob)})}(t)},Tt=tinymce.util.Tools.resolve("tinymce.dom.DOMUtils"),kt=tinymce.util.Tools.resolve("tinymce.ui.Factory"),Ct=function(){function t(){return o>0}function e(){return-1!==o&&o').appendTo(o),k.each(h,function(t){Mt("#"+m,o).append('