agenda-libre-ruby/public/assets/tinymce/plugins/imagetools/plugin-1d3534a07deed87ffdde893dfa5259023e847e3410b3a6a7fedcd22b44e517a8.js
2019-08-04 22:45:24 +02:00

11 lines
22 KiB
JavaScript

/**
* Copyright (c) Tiny Technologies, Inc. All rights reserved.
* Licensed under the LGPL or a commercial license.
* For LGPL see License.txt in the project root for license information.
* For commercial licenses see https://www.tiny.cloud/
*
* Version: 5.0.12 (2019-07-18)
*/
!function(l){"use strict";var e,n,t,r,o=function(e){var n=e,t=function(){return n};return{get:t,set:function(e){n=e},clone:function(){return o(t())}}},i=tinymce.util.Tools.resolve("tinymce.PluginManager"),a=tinymce.util.Tools.resolve("tinymce.util.Tools"),v=function(e){return function(){return e}},u=v(!1),c=v(!0),s=u,f=c,d=function(){return m},m=(r={fold:function(e,n){return e()},is:s,isSome:s,isNone:f,getOr:t=function(e){return e},getOrThunk:n=function(e){return e()},getOrDie:function(e){throw new Error(e||"error: getOrDie called on none.")},getOrNull:function(){return null},getOrUndefined:function(){return undefined},or:t,orThunk:n,map:d,ap:d,each:function(){},bind:d,flatten:d,exists:s,forall:f,filter:d,equals:e=function(e){return e.isNone()},equals_:e,toArray:function(){return[]},toString:v("none()")},Object.freeze&&Object.freeze(r),r),h=function(t){var e=function(){return t},n=function(){return o},r=function(e){return e(t)},o={fold:function(e,n){return n(t)},is:function(e){return t===e},isSome:f,isNone:s,getOr:e,getOrThunk:e,getOrDie:e,getOrNull:e,getOrUndefined:e,or:n,orThunk:n,map:function(e){return h(e(t))},ap:function(e){return e.fold(d,function(e){return h(e(t))})},each:function(e){e(t)},bind:r,flatten:e,exists:r,forall:r,filter:function(e){return e(t)?o:m},equals:function(e){return e.is(t)},equals_:function(e,n){return e.fold(s,function(e){return n(t,e)})},toArray:function(){return[t]},toString:function(){return"some("+t+")"}};return o},p={some:h,none:d,from:function(e){return null===e||e===undefined?m:h(e)}},g="undefined"!=typeof l.window?l.window:Function("return this;")(),y=function(e,n){return function(e,n){for(var t=n!==undefined&&null!==n?n:g,r=0;r<e.length&&t!==undefined&&null!==t;++r)t=t[e[r]];return t}(e.split("."),n)},w={getOrDie:function(e,n){var t=y(e,n);if(t===undefined||null===t)throw new Error(e+" not available on this browser");return t}};function b(){return new(w.getOrDie("FileReader"))}var O={atob:function(e){return w.getOrDie("atob")(e)},requestAnimationFrame:function(e){w.getOrDie("requestAnimationFrame")(e)}};function E(e,n){return N(l.document.createElement("canvas"),e,n)}function T(e){var n=E(e.width,e.height);return I(n).drawImage(e,0,0),n}function I(e){return e.getContext("2d")}function N(e,n,t){return e.width=n,e.height=t,e}var S=window.Promise?window.Promise:function(){var i=function(e){if("object"!=typeof this)throw new TypeError("Promises must be constructed via new");if("function"!=typeof e)throw new TypeError("not a function");this._state=null,this._value=null,this._deferreds=[],f(e,r(o,this),r(a,this))},e=i.immediateFn||"function"==typeof window.setImmediate&&window.setImmediate||function(e){l.setTimeout(e,1)};function r(e,n){return function(){return e.apply(n,arguments)}}var t=Array.isArray||function(e){return"[object Array]"===Object.prototype.toString.call(e)};function u(r){var o=this;null!==this._state?e(function(){var e=o._state?r.onFulfilled:r.onRejected;if(null!==e){var n;try{n=e(o._value)}catch(t){return void r.reject(t)}r.resolve(n)}else(o._state?r.resolve:r.reject)(o._value)}):this._deferreds.push(r)}function o(e){try{if(e===this)throw new TypeError("A promise cannot be resolved with itself.");if(e&&("object"==typeof e||"function"==typeof e)){var n=e.then;if("function"==typeof n)return void f(r(n,e),r(o,this),r(a,this))}this._state=!0,this._value=e,c.call(this)}catch(t){a.call(this,t)}}function a(e){this._state=!1,this._value=e,c.call(this)}function c(){for(var e=0,n=this._deferreds;e<n.length;e++){var t=n[e];u.call(this,t)}this._deferreds=[]}function s(e,n,t,r){this.onFulfilled="function"==typeof e?e:null,this.onRejected="function"==typeof n?n:null,this.resolve=t,this.reject=r}function f(e,n,t){var r=!1;try{e(function(e){r||(r=!0,n(e))},function(e){r||(r=!0,t(e))})}catch(o){if(r)return;r=!0,t(o)}}return i.prototype["catch"]=function(e){return this.then(null,e)},i.prototype.then=function(t,r){var o=this;return new i(function(e,n){u.call(o,new s(t,r,e,n))})},i.all=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];var c=Array.prototype.slice.call(1===e.length&&t(e[0])?e[0]:e);return new i(function(o,i){if(0===c.length)return o([]);var u=c.length;function a(n,e){try{if(e&&("object"==typeof e||"function"==typeof e)){var t=e.then;if("function"==typeof t)return void t.call(e,function(e){a(n,e)},i)}c[n]=e,0==--u&&o(c)}catch(r){i(r)}}for(var e=0;e<c.length;e++)a(e,c[e])})},i.resolve=function(n){return n&&"object"==typeof n&&n.constructor===i?n:new i(function(e){e(n)})},i.reject=function(t){return new i(function(e,n){n(t)})},i.race=function(o){return new i(function(e,n){for(var t=0,r=o;t<r.length;t++)r[t].then(e,n)})},i}();function _(e){var n=e.src;return 0===n.indexOf("data:")?R(n):function t(r){return new S(function(e,t){var n=new l.XMLHttpRequest;n.open("GET",r,!0),n.responseType="blob",n.onload=function(){200===this.status&&e(this.response)},n.onerror=function(){var e,n=this;t(0===this.status?((e=new Error("No access to download image")).code=18,e.name="SecurityError",e):new Error("Error "+n.status+" downloading image"))},n.send()})}(n)}function x(a){return new S(function(e,n){var t=l.URL.createObjectURL(a),r=new l.Image,o=function(){r.removeEventListener("load",i),r.removeEventListener("error",u)};function i(){o(),e(r)}function u(){o(),n("Unable to load data of type "+a.type+": "+t)}r.addEventListener("load",i),r.addEventListener("error",u),r.src=t,r.complete&&i()})}function A(e){var n=e.split(","),t=/data:([^;]+)/.exec(n[0]);if(!t)return p.none();for(var r,o=t[1],i=n[1],u=O.atob(i),a=u.length,c=Math.ceil(a/1024),s=new Array(c),f=0;f<c;++f){for(var l=1024*f,d=Math.min(l+1024,a),m=new Array(d-l),h=l,g=0;h<d;++g,++h)m[g]=u[h].charCodeAt(0);s[f]=(r=m,new(w.getOrDie("Uint8Array"))(r))}return p.some(function v(e,n){return new(w.getOrDie("Blob"))(e,n)}(s,{type:o}))}function R(t){return new S(function(e,n){A(t).fold(function(){n("uri is not base64: "+t)},e)})}function D(e,r,o){return r=r||"image/png",l.HTMLCanvasElement.prototype.toBlob?new S(function(n,t){e.toBlob(function(e){e?n(e):t()},r,o)}):R(e.toDataURL(r,o))}function C(e){return x(e).then(function(e){!function t(e){l.URL.revokeObjectURL(e.src)}(e);var n=E(function r(e){return e.naturalWidth||e.width}(e),function o(e){return e.naturalHeight||e.height}(e));return I(n).drawImage(e,0,0),n})}function U(e,n,t){var r=n.type;function o(n,t){return e.then(function(e){return function r(e,n,t){return n=n||"image/png",e.toDataURL(n,t)}(e,n,t)})}return{getType:v(r),toBlob:function i(){return S.resolve(n)},toDataURL:function u(){return t},toBase64:function a(){return t.split(",")[1]},toAdjustedBlob:function c(n,t){return e.then(function(e){return D(e,n,t)})},toAdjustedDataURL:o,toAdjustedBase64:function s(e,n){return o(e,n).then(function(e){return e.split(",")[1]})},toCanvas:function f(){return e.then(T)}}}function j(n){return function e(t){return new S(function(e){var n=b();n.onloadend=function(){e(n.result)},n.readAsDataURL(t)})}(n).then(function(e){return U(C(n),n,e)})}function L(n,e){return D(n,e).then(function(e){return U(S.resolve(n),e,n.toDataURL())})}function k(n,t){return n.toCanvas().then(function(e){return function a(e,n,t){var r=E(e.width,e.height),o=I(r),i=0,u=0;90!==(t=t<0?360+t:t)&&270!==t||N(r,r.height,r.width);90!==t&&180!==t||(i=r.width);270!==t&&180!==t||(u=r.height);return o.translate(i,u),o.rotate(t*Math.PI/180),o.drawImage(e,0,0),L(r,n)}(e,n.getType(),t)})}function P(n,t){return n.toCanvas().then(function(e){return function i(e,n,t){var r=E(e.width,e.height),o=I(r);"v"===t?(o.scale(1,-1),o.drawImage(e,0,-r.height)):(o.scale(-1,1),o.drawImage(e,-r.width,0));return L(r,n)}(e,n.getType(),t)})}var M=function(e){return j(e)},B=function(){return w.getOrDie("URL")},F=function(e){return B().createObjectURL(e)},z=function(e){B().revokeObjectURL(e)},H=tinymce.util.Tools.resolve("tinymce.util.Delay"),q=tinymce.util.Tools.resolve("tinymce.util.Promise"),$=tinymce.util.Tools.resolve("tinymce.util.URI");var X,W={getImageSize:function Tn(e){var n,t;function r(e){return/^[0-9\.]+px$/.test(e)}return n=e.style.width,t=e.style.height,n||t?r(n)&&r(t)?{w:parseInt(n,10),h:parseInt(t,10)}:null:(n=e.width,t=e.height,n&&t?{w:parseInt(n,10),h:parseInt(t,10)}:null)},setImageSize:function In(e,n){var t,r;n&&(t=e.style.width,r=e.style.height,(t||r)&&(e.style.width=n.w+"px",e.style.height=n.h+"px",e.removeAttribute("data-mce-style")),t=e.width,r=e.height,(t||r)&&(e.setAttribute("width",n.w),e.setAttribute("height",n.h)))},getNaturalImageSize:function Nn(e){return{w:e.naturalWidth,h:e.naturalHeight}}},G=(X="function",function(e){return function(e){if(null===e)return"null";var n=typeof e;return"object"===n&&(Array.prototype.isPrototypeOf(e)||e.constructor&&"Array"===e.constructor.name)?"array":"object"===n&&(String.prototype.isPrototypeOf(e)||e.constructor&&"String"===e.constructor.name)?"string":n}(e)===X}),Y=Array.prototype.slice,V=function(e,n){for(var t=0,r=e.length;t<r;t++){var o=e[t];if(n(o,t,e))return p.some(o)}return p.none()};G(Array.from)&&Array.from;var J=function(e){return null!==e&&e!==undefined},K=function(e,n){var t;return t=n.reduce(function(e,n){return J(e)?e[n]:undefined},e),J(t)?t:null},Q=function(n){return new q(function(t){var e=b();e.onload=function(e){var n=e.target;t(n.result)},e.readAsText(n)})},Z=function(r,o,i){return new q(function(e){var t;(t=function n(){return new(w.getOrDie("XMLHttpRequest"))}()).onreadystatechange=function(){4===t.readyState&&e({status:t.status,blob:this.response})},t.open("GET",r,!0),t.withCredentials=i,a.each(o,function(e,n){t.setRequestHeader(n,e)}),t.responseType="blob",t.send()})},ee=function(e){var n;try{n=JSON.parse(e)}catch(t){}return n},ne=[{code:404,message:"Could not find Image Proxy"},{code:403,message:"Rejected request"},{code:0,message:"Incorrect Image Proxy URL"}],te=[{type:"key_missing",message:"The request did not include an api key."},{type:"key_not_found",message:"The provided api key could not be found."},{type:"domain_not_trusted",message:"The api key is not valid for the request origins."}],re=function(n){return"ImageProxy HTTP error: "+V(ne,function(e){return n===e.code}).fold(v("Unknown ImageProxy error"),function(e){return e.message})},oe=function(e){var n=re(e);return q.reject(n)},ie=function(n){return V(te,function(e){return e.type===n}).fold(v("Unknown service error"),function(e){return e.message})},ue=function(e,n){return Q(n).then(function(e){var n,t,r=(n=ee(e),"ImageProxy Service error: "+((t=K(n,["error","type"]))?ie(t):"Invalid JSON in service error message"));return q.reject(r)})},ae=function(e,n){return 400===(t=e)||403===t||500===t?ue(0,n):oe(e);var t},ce=oe,se=function(e,n){var t,r,o,i={"Content-Type":"application/json;charset=UTF-8","tiny-api-key":n};return Z((t=e,r=n,o=-1===t.indexOf("?")?"?":"&",/[?&]apiKey=/.test(t)||!r?t:t+o+"apiKey="+encodeURIComponent(r)),i,!1).then(function(e){return e.status<200||300<=e.status?ae(e.status,e.blob):q.resolve(e.blob)})};var fe,le,de,me=function(e,n,t){return n?se(e,n):function r(e,n){return Z(e,{},n).then(function(e){return e.status<200||300<=e.status?ce(e.status):q.resolve(e.blob)})}(e,t)},he=function(){return w.getOrDie("Node")},ge=function(e,n,t){return 0!=(e.compareDocumentPosition(n)&t)},ve=function(e,n){return ge(e,n,he().DOCUMENT_POSITION_CONTAINED_BY)},pe=function(e,n){var t=function(e,n){for(var t=0;t<e.length;t++){var r=e[t];if(r.test(n))return r}return undefined}(e,n);if(!t)return{major:0,minor:0};var r=function(e){return Number(n.replace(t,"$"+e))};return we(r(1),r(2))},ye=function(){return we(0,0)},we=function(e,n){return{major:e,minor:n}},be={nu:we,detect:function(e,n){var t=String(n).toLowerCase();return 0===e.length?ye():pe(e,t)},unknown:ye},Oe="Firefox",Ee=function(e,n){return function(){return n===e}},Te=function(e){var n=e.current;return{current:n,version:e.version,isEdge:Ee("Edge",n),isChrome:Ee("Chrome",n),isIE:Ee("IE",n),isOpera:Ee("Opera",n),isFirefox:Ee(Oe,n),isSafari:Ee("Safari",n)}},Ie={unknown:function(){return Te({current:undefined,version:be.unknown()})},nu:Te,edge:v("Edge"),chrome:v("Chrome"),ie:v("IE"),opera:v("Opera"),firefox:v(Oe),safari:v("Safari")},Ne="Windows",Se="Android",_e="Solaris",xe="FreeBSD",Ae=function(e,n){return function(){return n===e}},Re=function(e){var n=e.current;return{current:n,version:e.version,isWindows:Ae(Ne,n),isiOS:Ae("iOS",n),isAndroid:Ae(Se,n),isOSX:Ae("OSX",n),isLinux:Ae("Linux",n),isSolaris:Ae(_e,n),isFreeBSD:Ae(xe,n)}},De={unknown:function(){return Re({current:undefined,version:be.unknown()})},nu:Re,windows:v(Ne),ios:v("iOS"),android:v(Se),linux:v("Linux"),osx:v("OSX"),solaris:v(_e),freebsd:v(xe)},Ce=function(e,n){var t=String(n).toLowerCase();return V(e,function(e){return e.search(t)})},Ue=function(e,t){return Ce(e,t).map(function(e){var n=be.detect(e.versionRegexes,t);return{current:e.name,version:n}})},je=function(e,t){return Ce(e,t).map(function(e){var n=be.detect(e.versionRegexes,t);return{current:e.name,version:n}})},Le=function(e,n){return-1!==e.indexOf(n)},ke=/.*?version\/\ ?([0-9]+)\.([0-9]+).*/,Pe=function(n){return function(e){return Le(e,n)}},Me=[{name:"Edge",versionRegexes:[/.*?edge\/ ?([0-9]+)\.([0-9]+)$/],search:function(e){return Le(e,"edge/")&&Le(e,"chrome")&&Le(e,"safari")&&Le(e,"applewebkit")}},{name:"Chrome",versionRegexes:[/.*?chrome\/([0-9]+)\.([0-9]+).*/,ke],search:function(e){return Le(e,"chrome")&&!Le(e,"chromeframe")}},{name:"IE",versionRegexes:[/.*?msie\ ?([0-9]+)\.([0-9]+).*/,/.*?rv:([0-9]+)\.([0-9]+).*/],search:function(e){return Le(e,"msie")||Le(e,"trident")}},{name:"Opera",versionRegexes:[ke,/.*?opera\/([0-9]+)\.([0-9]+).*/],search:Pe("opera")},{name:"Firefox",versionRegexes:[/.*?firefox\/\ ?([0-9]+)\.([0-9]+).*/],search:Pe("firefox")},{name:"Safari",versionRegexes:[ke,/.*?cpu os ([0-9]+)_([0-9]+).*/],search:function(e){return(Le(e,"safari")||Le(e,"mobile/"))&&Le(e,"applewebkit")}}],Be=[{name:"Windows",search:Pe("win"),versionRegexes:[/.*?windows\ nt\ ?([0-9]+)\.([0-9]+).*/]},{name:"iOS",search:function(e){return Le(e,"iphone")||Le(e,"ipad")},versionRegexes:[/.*?version\/\ ?([0-9]+)\.([0-9]+).*/,/.*cpu os ([0-9]+)_([0-9]+).*/,/.*cpu iphone os ([0-9]+)_([0-9]+).*/]},{name:"Android",search:Pe("android"),versionRegexes:[/.*?android\ ?([0-9]+)\.([0-9]+).*/]},{name:"OSX",search:Pe("os x"),versionRegexes:[/.*?os\ x\ ?([0-9]+)_([0-9]+).*/]},{name:"Linux",search:Pe("linux"),versionRegexes:[]},{name:"Solaris",search:Pe("sunos"),versionRegexes:[]},{name:"FreeBSD",search:Pe("freebsd"),versionRegexes:[]}],Fe={browsers:v(Me),oses:v(Be)},ze=function(e){var n,t,r,o,i,u,a,c,s,f,l,d=Fe.browsers(),m=Fe.oses(),h=Ue(d,e).fold(Ie.unknown,Ie.nu),g=je(m,e).fold(De.unknown,De.nu);return{browser:h,os:g,deviceType:(t=h,r=e,o=(n=g).isiOS()&&!0===/ipad/i.test(r),i=n.isiOS()&&!o,u=n.isAndroid()&&3===n.version.major,a=n.isAndroid()&&4===n.version.major,c=o||u||a&&!0===/mobile/i.test(r),s=n.isiOS()||n.isAndroid(),f=s&&!c,l=t.isSafari()&&n.isiOS()&&!1===/safari/i.test(r),{isiPad:v(o),isiPhone:v(i),isTablet:v(c),isPhone:v(f),isTouch:v(s),isAndroid:n.isAndroid,isiOS:n.isiOS,isWebView:v(l)})}},He={detect:(de=!(fe=function(){var e=l.navigator.userAgent;return ze(e)}),function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];return de||(de=!0,le=fe.apply(null,e)),le})},qe=function(e){if(null===e||e===undefined)throw new Error("Node cannot be null or undefined");return{dom:v(e)}},$e={fromHtml:function(e,n){var t=(n||l.document).createElement("div");if(t.innerHTML=e,!t.hasChildNodes()||1<t.childNodes.length)throw l.console.error("HTML does not have a single root node",e),new Error("HTML must have a single root node");return qe(t.childNodes[0])},fromTag:function(e,n){var t=(n||l.document).createElement(e);return qe(t)},fromText:function(e,n){var t=(n||l.document).createTextNode(e);return qe(t)},fromDom:qe,fromPoint:function(e,n,t){var r=e.dom();return p.from(r.elementFromPoint(n,t)).map(qe)}},Xe=(l.Node.ATTRIBUTE_NODE,l.Node.CDATA_SECTION_NODE,l.Node.COMMENT_NODE,l.Node.DOCUMENT_NODE,l.Node.DOCUMENT_TYPE_NODE,l.Node.DOCUMENT_FRAGMENT_NODE,l.Node.ELEMENT_NODE),We=(l.Node.TEXT_NODE,l.Node.PROCESSING_INSTRUCTION_NODE,l.Node.ENTITY_REFERENCE_NODE,l.Node.ENTITY_NODE,l.Node.NOTATION_NODE,Xe),Ge=(He.detect().browser.isIE(),function(e,n){return t=function(e){return function(e,n){var t=e.dom();if(t.nodeType!==We)return!1;if(t.matches!==undefined)return t.matches(n);if(t.msMatchesSelector!==undefined)return t.msMatchesSelector(n);if(t.webkitMatchesSelector!==undefined)return t.webkitMatchesSelector(n);if(t.mozMatchesSelector!==undefined)return t.mozMatchesSelector(n);throw new Error("Browser lacks native selectors")}(e,n)},V(e.dom().childNodes,(r=t,o=$e.fromDom,function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];return r(o.apply(null,e))})).map($e.fromDom);var t,r,o}),Ye=0,Ve=function(e){return Ge($e.fromDom(e),"img")},Je=function(e,n){return e.dom.is(n,"figure")},Ke=function(e,n){e.notificationManager.open({text:n,type:"error"})},Qe=function(e){var n=e.selection.getNode();return Je(e,n)?Ve(n):p.some($e.fromDom(n))},Ze=function(e,n){var t=n.src;return 0===t.indexOf("data:")||0===t.indexOf("blob:")||new $(t).host===e.documentBaseURI.host},en=function(e,n){return-1!==a.inArray(e.getParam("imagetools_cors_hosts",[],"string[]"),new $(n.src).host)},nn=function(e,n){var t,r,o,i,u=n.src;return en(e,n)?me(n.src,null,(r=e,o=n,-1!==a.inArray(r.getParam("imagetools_credentials_hosts",[],"string[]"),new $(o.src).host))):Ze(e,n)?_(n):(u=e.getParam("imagetools_proxy"),u+=(-1===u.indexOf("?")?"?":"&")+"url="+encodeURIComponent(n.src),t=(i=e).getParam("api_key",i.getParam("imagetools_api_key","","string"),"string"),me(u,t,!1))},tn=function(e,n){return(t=e,p.from(t.getParam("imagetools_fetch_image",null,"function"))).fold(function(){return nn(e,n)},function(e){return e(n)});var t},rn=function(e,n){var t;return(t=e.editorUpload.blobCache.getByUri(n.src))?q.resolve(t.blob()):tn(e,n)},on=function(e){H.clearTimeout(e.get())},un=function(a,c,s,f,l,d){return c.toBlob().then(function(e){var n,t,r,o,i,u;return r=a.editorUpload.blobCache,n=l.src,a.getParam("images_reuse_filename",!1,"boolean")&&(t=(o=r.getByUri(n))?(n=o.uri(),o.name()):(i=a,(u=n.match(/\/([^\/\?]+)?\.(?:jpeg|jpg|png|gif)(?:\?|$)/i))?i.dom.encode(u[1]):null)),o=r.create({id:"imagetools"+Ye++,blob:e,base64:c.toBase64(),uri:n,name:t}),r.add(o),a.undoManager.transact(function(){a.$(l).on("load",function r(){var e,n,t;a.$(l).off("load",r),a.nodeChanged(),s?a.editorUpload.uploadImagesAuto():(on(f),e=a,n=f,t=H.setEditorTimeout(e,function(){e.editorUpload.uploadImagesAuto()},e.getParam("images_upload_timeout",3e4,"number")),n.set(t))}),d&&a.$(l).attr({width:d.w,height:d.h}),a.$(l).attr({src:o.blobUri()}).removeAttr("data-mce-src")}),o})},an=function(t,r,e,o){return function(){return Qe(t).fold(function(){Ke(t,"Could not find selected image")},function(n){return t._scanForImages().then(function(){return rn(t,n.dom())}).then(M).then(e).then(function(e){return un(t,e,!1,r,n.dom(),o)},function(e){Ke(t,e)})})}},cn=function(n,t,r){return function(){var e=Qe(n).fold(function(){return null},function(e){var n=W.getImageSize(e.dom());return n?{w:n.h,h:n.w}:null});return an(n,t,function(e){return k(e,r)},e)()}},sn=function(e,n,t){return function(){return an(e,n,function(e){return P(e,t)})()}},fn=function(t,e){var n=function(e){return n=e,t.dom.is(n,"img:not([data-mce-object],[data-mce-placeholder])")&&(Ze(t,e)||en(t,e)||t.settings.imagetools_proxy);var n};return Je(t,e)?Ve(e).map(function(e){return n(e.dom())?p.some(e.dom()):p.none()}):n(e)?p.some(e):p.none()},ln=on,dn=rn,mn=Qe,hn=function(t,r,o,i,u){return new q(function(e){var n;(n=u,x(n)).then(function(e){var n=W.getNaturalImageSize(e);return i.w===n.w&&i.h===n.h||W.getImageSize(o)&&W.setImageSize(o,n),z(e.src),u}).then(M).then(function(e){return un(t,e,!0,r,o)},function(){})})},gn=v("save-state"),vn=v("disable"),pn=v("enable"),yn=function(i,u){return function(){var r=mn(i),o=r.map(function(e){return W.getNaturalImageSize(e.dom())});mn(i).each(function(n){fn(i,n.dom()).each(function(e){dn(i,n.dom()).then(function(e){var n,t={blob:n=e,url:F(n)};i.windowManager.open({title:"Edit Image",size:"large",body:{type:"panel",items:[{type:"imagetools",name:"imagetools",label:"Edit Image",currentState:t}]},buttons:[{type:"cancel",name:"cancel",text:"Cancel"},{type:"submit",name:"save",text:"Save",primary:!0,disabled:!0}],onSubmit:function(e){var t=e.getData().imagetools.blob;r.each(function(n){o.each(function(e){hn(i,u,n.dom(),e,t)})}),e.close()},onCancel:function(){},onAction:function(e,n){switch(n.name){case gn():n.value?e.enable("save"):e.disable("save");break;case vn():e.disable("save"),e.disable("cancel");break;case pn():e.enable("cancel")}}})})})})}},wn=function(t,e){a.each({mceImageRotateLeft:cn(t,e,-90),mceImageRotateRight:cn(t,e,90),mceImageFlipVertical:sn(t,e,"v"),mceImageFlipHorizontal:sn(t,e,"h"),mceEditImage:yn(t,e)},function(e,n){t.addCommand(n,e)})},bn=function(t,r,o){t.on("NodeChange",function(e){var n=o.get();n&&n.src!==e.element.src&&(ln(r),t.editorUpload.uploadImagesAuto(),o.set(null)),fn(t,e.element).each(o.set)})},On=function(r){var n=function(e){return function(){return r.execCommand(e)}};r.ui.registry.addButton("rotateleft",{tooltip:"Rotate counterclockwise",icon:"rotate-left",onAction:n("mceImageRotateLeft")}),r.ui.registry.addButton("rotateright",{tooltip:"Rotate clockwise",icon:"rotate-right",onAction:n("mceImageRotateRight")}),r.ui.registry.addButton("flipv",{tooltip:"Flip vertically",icon:"flip-vertically",onAction:n("mceImageFlipVertical")}),r.ui.registry.addButton("fliph",{tooltip:"Flip horizontally",icon:"flip-horizontally",onAction:n("mceImageFlipHorizontal")}),r.ui.registry.addButton("editimage",{tooltip:"Edit image",icon:"edit-image",onAction:n("mceEditImage"),onSetup:function(t){var e=function(){mn(r).each(function(e){var n=fn(r,e.dom()).isNone();t.setDisabled(n)})};return r.on("NodeChange",e),function(){r.off("NodeChange",e)}}}),r.ui.registry.addButton("imageoptions",{tooltip:"Image options",icon:"image-options",onAction:n("mceImage")}),r.ui.registry.addContextMenu("imagetools",{update:function(e){return fn(r,e).fold(function(){return[]},function(e){return[{text:"Edit image",icon:"edit-image",onAction:n("mceEditImage")}]})}})},En=function(n){var e;n.ui.registry.addContextToolbar("imagetools",{items:(e=n,e.getParam("imagetools_toolbar","rotateleft rotateright flipv fliph editimage imageoptions")),predicate:function(e){return fn(n,e).isSome()},position:"node",scope:"node"})};!function Sn(){i.add("imagetools",function(e){var n=o(0),t=o(null);wn(e,n),On(e),En(e),bn(e,n,t)})}()}(window);