/** * 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.6.2 (2020-12-08) */!function(){"use strict";vart,e,n,r,l=function(t){vare=t;return{get:function(){returne},set:function(t){e=t}}},o=tinymce.util.Tools.resolve("tinymce.PluginManager"),d=tinymce.util.Tools.resolve("tinymce.util.Tools"),i=function(){},u=function(t){returnfunction(){returnt}},a=u(!1),c=u(!0),f=function(){returns},s=(t=function(t){returnt.isNone()},{fold:function(t,e){returnt()},is:a,isSome:a,isNone:c,getOr:n=function(t){returnt},getOrThunk:e=function(t){returnt()},getOrDie:function(t){thrownewError(t||"error: getOrDie called on none.")},getOrNull:u(null),getOrUndefined:u(undefined),or:n,orThunk:e,map:f,each:i,bind:f,exists:a,forall:c,filter:f,equals:t,equals_:t,toArray:function(){return[]},toString:u("none()")}),m=function(n){vart=u(n),e=function(){returno},r=function(t){returnt(n)},o={fold:function(t,e){returne(n)},is:function(t){returnn===t},isSome:c,isNone:a,getOr:t,getOrThunk:t,getOrDie:t,getOrNull:t,getOrUndefined:t,or:e,orThunk:e,map:function(t){returnm(t(n))},each:function(t){t(n)},bind:r,exists:r,forall:r,filter:function(t){returnt(n)?o:s},toArray:function(){return[n]},toString:function(){return"some("+n+")"},equals:function(t){returnt.is(n)},equals_:function(t,e){returnt.fold(a,function(t){returne(n,t)})}};returno},g={some:m,none:f,from:function(t){returnnull===t||t===undefined?s:m(t)}},h=function(t){return!(null===(e=t)||e===undefined);vare},v=(r="function",function(t){returntypeoft===r});functionp(t,e){returnb(document.createElement("canvas"),t,e)}functiony(t){vare=p(t.width,t.height);returnw(e).drawImage(t,0,0),e}functionw(t){returnt.getContext("2d")}functionb(t,e,n){returnt.width=e,t.height=n,t}varI,T,_,R,U=window.Promise?window.Promise:(I=function(t){if("object"!=typeofthis)thrownewTypeError("Promises must be constructed via new");if("function"!=typeoft)thrownewTypeError("not a function");this._state=null,this._value=null,this._deferreds=[],C(t,A(E,this),A(L,this))},T=window,_=I.immediateFn||"function"==typeofT.setImmediate&&T.setImmediate||function(t){setTimeout(t,1)},R=Array.isArray||function(t){return"[object Array]"===Object.prototype.toString.call(t)},I.prototype["catch"]=function(t){returnthis.then(null,t)},I.prototype.then=function(n,r){varo=this;returnnewI(function(t,e){x.call(o,newk(n,r,t,e))})},I.all=function(){for(vart=[],e=0;e<arguments.length;e++)t[e]=arguments[e];varc=Array.prototype.slice.call(1===t.length&&R(t[0])?t[0]:t);returnnewI(function(o,i){if(0===c.length)returno([]);for(varu=c.length,t=0;t<c.length;t++)!functiona(e,t){try{if(t&&("object"==typeoft||"function"==typeoft)){varn=t.then;if("function"==typeofn)returnvoidn.call(t,function(t){a(e,t)},i)}c[e]=t,0==--u&&o(c)}catch(r){i(r)}}(t,c[t])})},I.resolve=function(e){returne&&"object"==typeofe&&e.constructor===I?e:newI(function(t){t(e)})},I.reject=function(n){returnnewI(function(t,e){e(n)})},I.race=function(o){returnnewI(function(t,e){for(varn=0,r=o;n<r.length;n++)r[n].then(t,e)})},I);functionA(t,e){returnfunction(){returnt.apply(e,arguments)}}functionx(r){varo=this;null!==this._state?_(function(){vart,e=o._state?r.onFulfilled:r.onRejected;if(null!==e){try{t=e(o._value)}catch(n){returnvoidr.reject(n)}r.resolve(t)}else(o._state?r.resolve:r.reject)(o._value)}):this._deferreds.push(r)}functionE(t){try{if(t===this)thrownewTypeError("A promise cannot be resolved with itself.");if(t&&("object"==typeoft||"function"==typeoft)){vare=t.then;if("function"==typeofe)returnvoidC(A(e,t),A(E,this),A(L,this))}this._state=!0,this._value=t,j.call(this)}catch(n){L.call(this,n)}}functionL(t){this._state=!1,this._value=t,j.call(this)}functionj(){for(vart=0,e=this._deferreds;t<e.length;t++){varn=e[t];x.call(this,n)}this._deferreds=[]}functionk(t,e,n,r){this.onFulfilled="function"==typeoft?t:null,this.onRejected="function"==typeofe?e:null,this.resolve=n,this.reject=r}functionC(t,e,n){varr=!1;try{t(function(t){r||(r=!0,e(t))},function(t){r||(r=!0,n(t))})}catch(o){if(r)return;r=!0,n(o)}}functionO(t){varr,e=t.src;return0===e.indexOf("data:")?S(e):(r=e,newU(function(t,n){vare=newXMLHttpRequest;e.open("GET",r,!0),e.responseType="blob",e.onload=function(){200===this.status&&t(this.response)},e.onerror=function(){vart,e=this;n(0===this.status?((t=newError("No access to download image")).code=18,t.name="SecurityError",t):newError("Error "+e.status+" downloading image"))},e.send()}))}functionP(a){returnnewU(function(t,e){varn=URL.createObjectURL(a),r=newImage,o=function(){r.removeEventListener("load",i),r.removeEventListener("error",u)};functioni(){o(),t(r)}functionu(){o(),e("Unable to load data of type "+a.type+": "+n)}r.addEventListener("load",i),r.addEventListener("error",u),r.src=n,r.complete&&i()})}functionS(n){returnnewU(function(t,e){(function(t){vare=t.split(","),n=/data:([^;]+)/.exec(e[0]);if(!n)returng.none();for(varr=n[1],o=e[1],i=atob(o),u=i.length,a=Math.ceil(u/1024),c=newArray(a),f=0;f<a;++f){for(vars=1024*f,l=Math.min(1024+s,u),d=newArray(l-s),m=s,h=0;m<l;++h,++m)d[h]=i[m].charCodeAt(0);c[f]=newUint8Array(d)}returng.some(newBlob(c,{type:r}))})(n).fold(function(){e("uri is not base64: "+n)},t)})}functionM(t,r,o){returnr=r||"image/png",v(HTMLCanvasElement.prototype.toBlob)?newU(function(e,n){t.toBlob(function(t){t?e(t):n()},r,o)}):S(t.toDataURL(r,o))}functionB(t){returnP(t).then(function(t){vare;e=t,URL.revokeObjectURL(e.src);varn,r,o=p((r=t).naturalWidth||r.width,(n=t).naturalHeight||n.height);returnw(o).drawImage(t,0,0),o})}varN=P,D=O,F=function(t,e){returnfunction(t,e,n){for(varr=0,o=t.length;r<o;r++){vari=t[r];if(e(i,r))returng.some(i);if(n(i,r))break}returng.none()}(t,e,a)};functionH(t,e,n){varr=e.type;functiono(r,o){returnt.then(function(t){returnn=o,e=(e=r)||"image/png",t.toDataURL(e,n);vare,n})}return{getType:u(r),toBlob:function(){returnU.resolve(e)},toDataURL:u(n),toBase64:function(){returnn.split(",")[1]},toAdjustedBlob:function(e,n){returnt.then(function(t){returnM(t,e,n)})},toAdjustedDataURL:o,toAdjustedBase64:function(t,e){returno(t,e).then(function(t){returnt.split(",")[1]})},toCanvas:function(){returnt.then(y)}}}functionq(e){returnn=e,newU(function(t){vare=newFileReader;e.onloadend=function(){t(e.result)},e.readAsDataURL(n)}).then(function(t){returnH(B(e),e,t)});varn}functionz(e,t){returnM(e,t).then(function(t){returnH(U.resolve(e),t,e.toDataURL())})}function$(e,n){returne.toCanvas().then(function(t){returnfunction(t,e,n){varr=p(t.width,t.height),o=w(r),i=0,u=0;90!==(n=n<0?360+n:n)&&270!==n||b(r,r.height,r.width);90!==n&&180!==n||(i=r.width);270!==n&&180!==n||(u=r.height);returno.translate(i,u),o.rotate(n*Math.PI/180),o.drawImage(t,0,0),z(r,e)}(t,e.getType(),n)})}functionG(e,n){returne.toCanvas().then(function(t){returnfunction(t,e,n){varr=p(t.width,t.height),o=w(r);"v"===n?(o.scale(1,-1),o.drawImage(t,0,-r.height)):(o.scale(-1,1),o.drawImage(t,-r.width,0));returnz(r,e)}(t,e.getType(),n)})}varJ=G,K=$,V=Object.keys,W=function(e,r,o){returnvoid0===o&&(o=!1),newU(function(t){varn=newXMLHttpRequest;n.onreadystatechange=function(){4===n.readyState&&t({status:n.status,blob:n.response})},n.open("GET",e,!0),n.withCredentials=o,function(t,e){for(varn=V(t),r=0,o=n.length;r<o;r++){vari=n[r];e(t[i],i)}}(r,function(t,e){n.setRequestHeader(e,t)}),n.responseType="blob",n.send()})},X=[{code:404,message:"Could not find Image Proxy"},{code:403,message:"Rejected request"},{code:0,message:"Incorrect Image Proxy URL"}],Q=[{type:"not_found",message:"Failed to load image."},{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."}],Y=function(t,e){varn,r,o=(n=function(t,e){returnh(t)?t[e]:undefined},r=t,function(t,e){for(varn=0,r=t.length;n<r;n++)e(t[n],n)}(e,function(t){r=n(r,t)}),r);returng.from(o)},Z=function(t){vare,n=(e=t,"ImageProxy HTTP error: "+F(X,function(t){returne===t.code}).fold(u("Unknown ImageProxy error"),function(t){returnt.message}));returnU.reject(n)},tt=function(e){returnF(Q,function(t){returnt.type===e}).fold(u("Unknown service error"),function(t){returnt.message})},et=function(t){return"ImageProxy Service error: "+function(t){try{returng.some(JSON.parse(t))}catch(e){returng.none()}}(t).bind(function(t){returnY(t,["error","type"]).map(tt)}).getOr("Invalid JSON in service error message")},nt=function(t){returnr=t,newU(function(t,e){varn=newFileReader;n.onload=function(){t(n.result)},n.onerror=function(t){e(t)},n.readAsText(r)}).then(function(t){vare=et(t);returnU.reject(e)});varr},rt=function(t){returnt<200||300<=t},ot=function(t,e){varn,r,o,i={"Content-Type":"application/json;charset=UTF-8","tiny-api-key":e};returnW((r=e,o=-1===(n=t).indexOf("?")?"?":"&",/[?&]apiKey=/.test(n)?n:n+o+"apiKey="+encodeURIComponent(r)),i).then(function(t){returnrt(t.status)?(e=t.status,n=t.blob,r=e,"application/json"!==(null==(o=n)?void0:o.type)||400!==r&&403!==r&&404!==r&&500!==r?Z(e):nt(n)):U.resolve(t.blob);vare,n,r,o})},it=function(t,e,n){returnvoid0===n&&(n=!1),e?ot(t,e):W(t,{},n).then(function(t){returnrt(t.status)?Z(t.status):U.resolve(t.blob)})},ut=q,at=function(t){if(null===t||t===undefined)thrownewError("Node cannot be null or undefined");return{dom:t}},ct={fromHtml:function(t,e){varn=(e||document).createElement("div");if(n.innerHTML=t,!n.hasChildNodes()||1<n.childNodes.length)throwconsole.error("HTML does not have a single root node",t),newError("HTML must have a single root node");returnat(n.childNodes[0])},fromTag:function(t,e){varn=(e||document).createElement(t);returnat(n)},fromText:function(t,e){varn=(e||document).createTextNode(t);returnat(n)},fromDom:at,fromPoint:function(t,e,n){returng.from(t.dom.elementFromPoint(e,n)).map(at)}},ft=("undefined"!=typeofwindow||Function("return this;")(),function(t,e){returnn=function(t){returnfunction(t,e){varn=t.dom;if(1!==n.nodeType)return!1;varr=n;if(r.matches!==undefined)returnr.matches(e);if(r.msMatchesSelector!==undefined)returnr.msMatchesSelector(e);if(r.webkitMatchesSelector!==undefined)returnr.webkitMatchesSelector(e);if(r.mozMatchesSelector!==undefined)returnr.mozMatchesSelector(e);thrownewError("Browser lacks native selectors")}(t,e)},F(t.dom.childNodes,function(t){returnn(ct.fromDom(t))}).map(ct.fromDom);varn}),st=tinymce.util.Tools.resolve("tinymce.util.Delay"),lt=tinymce.util.Tools.resolve("tinymce.util.Promise"),dt=tinymce.util.Tools.resolve("tinymce.util.URI"),mt=function(t){returnt.getParam("imagetools_proxy")};functionht(t){vare,n;functionr(t){return/^[0-9\.]+px$/.test(t)}returne=t.style.width,n=t.style.height,e||n?r(e)&&r(n)?{w:parseInt(e,10),h:parseInt(n,10)}:null:(e=t.width,n=t.height,e&&n?{w:parseInt(e,10),h:parseInt(n,10)}:null)}functiongt(t){return{w:t.naturalWidth,h:t.naturalHeight}}varvt=0,pt=function(t){returnft(ct.fromDom(t),"img")},yt=function(t,e){returnt.dom.is(e,"figure")},wt=function(t,e){returnt.dom.is(e,"img:not([data-mce-object],[data-mce-placeholder])")},bt=function(e,t){varn=function(t){returnwt(e,t)&&(Rt(e,t)||Ut(e,t)||h(mt(e)))};returnyt(e,t)?pt(t).bind(function(t){returnn(t.dom)?g.some(t.dom):g.none()}):n(t)?g.some(t):g.none()},It=function(t,e){t.notificationManager.open({text:e,type:"error"})},Tt=function(t){vare=t.selection.getNode(),n=t.dom.getParent(e,"figure.image");returnnull!==n&&yt(t,n)?pt(n):wt(t,e)?g.some(ct.fromDom(e)):g.none()},_t=function(t,e,n){varr=e.match(/(?:\/|^)(([^\/\?]+)\.(?:[a-z0-9.]+))(?:\?|$)/i);returnh(r)?t.dom.encode(r[n]):null},Rt=function(t,e){varn=e.src;return0===n.indexOf("data:")||0===n.indexOf("blob:")||newdt(n).host===t.documentBaseURI.host},Ut=function(t,e){return-1!==d.inArray(t.getParam("imagetools_cors_hosts",[],"string[]"),newdt(e.src).host)},At=function(t,e){if(Ut(t,e))returnit(e.src,null,(n=t,r=e,-1!==d.inArray(n.getParam("imagetools_credentials_hosts",[],"string[]"),newdt(r.src).host)));varn,r,o;if(Rt(t,e))returnD(e);vari=mt(t),u=i+(-1===i.indexOf("?")?"?":"&")+"url="+encodeURIComponent(e.src),a=(o=t).getParam("api_key",o.getParam("imagetools_api_key","","string"),"string");returnit(u,a,!1)},xt=function(t,e){returnn=t,g.from(n.getParam("imagetools_fetch_image",null,"function")).fold(function(){returnAt(t,e)},function(t){returnt(e)});varn},Et=function(t,e){varn=t.editorUpload.blobCache.getByUri(e.src);returnn?lt.resolve(n.blob()):xt(t,e)},Lt=function(t){st.clearTimeout(t.get())},jt=function(a,c,f,s,l,d,m){returnf.toBlob().then(function(t){vare,n,o,r=a.editorUpload.blobCache,i=d.src,u=c.type===t.type;returna.getParam("images_reuse_filename",!1,"boolean")&&(o=r.getByUri(i),n=h(o)?(i=o.uri(),e=o.name(),o.filename()):(e=_t(a,i,2),_t(a,i,1))),o=r.create({id:"imagetools"+vt++,blob:t,base64:f.toBase64(),uri:i,name:e,filename:u?n:undefined}),r.add(o),a.undoManager.transact(function(){a.$(d).on("load",functionr(){vart,e,n;a.$(d).off("load",r),a.nodeChanged(),s?a.editorUpload.uploadImagesAuto():(Lt(l),t=a,e=l,n=st.setEditorTimeout(t,function(){t.editorUpload.uploadImagesAuto()},t.getParam("images_upload_timeout",3e4,"number")),e.set(n))}),m&&a.$(d).attr({width:m.w,height:m.h}),a.$(d).attr({src:o.blobUri()}).removeAttr("data-mce-src")}),o})},kt=function(r,o,t,i){returnfunction(){returnTt(r).fold(function(){It(r,"Could not find selected image")},function(n){returnr._scanForImages().then(function(){returnEt(r,n.dom)}).then(function(e){returnut(e).then(t).then(function(t){returnjt(r,e,t,!1,o,n.dom,i)})})["catch"](function(t){It(r,t)})})}},Ct=function(e,n,r){returnfunction(){vart=Tt(e).fold(function(){returnnull},function(t){vare=ht(t.dom);returne?{w:e.h,h:e.w}:null});returnkt(e,n,function(t){returnK(t,r)},t)()}},Ot=function(t,e,n){returnfunction(){returnkt(t,e,function(t){returnJ(t,n)})()}},Pt=function(e,n,u,a,c){returnN(c).then(function(t){vare,n,r,o,i=gt(t);returna.w===i.w&&a.h===i.h||ht(u)&&(e=u,(n=i)&&(r=e.style.width,o=e.style.height,(r||o)&&(e.style.width=n.w+"px",e.style.height=n.h+"px",e.removeAttribute("data-mce-style")),r=e.width,o=e.height,(r||o)&&(e.setAttribute("width",String(n.w)),e.setAttribute("height",String(n.h))))),URL.revokeObjectURL(t.src),c}).then(ut).then(function(t){returnjt(e,c,t,!0,n,u)})["catch"](function(){})},St=function(i,u){returnfunction(){varr=Tt(i),o=r.map(function(t){returngt(t.dom)});r.each(function(e){bt(i,e.dom).each(function(t){Et(i,e.dom).then(function(t){vare,n={blob:e=t,url:URL.createObjectURL(e)};i.windowManager.open({title:"Edit Image",size:"large",body:{type:"panel",items:[{type:"imagetools",name:"imagetools",label:"Edit Image",currentState:n}]},buttons:[{type:"cancel",name:"cancel",text:"Cancel"},{type:"submit",name:"save",text:"Save",primary:!0,disabled:!0}],onSubmit:function(t){varn=t.getData().imagetools.blob;r.each(function(e){o.each(function(t){Pt(i,u,e.dom,t,n)})}),t.close()},onCancel:function(){},onAction:function(t,e){switch(e.name){case"save-state":e.value?t.enable("save"):t.disable("save");break;case"disable":t.disable("save"),t.disable("cancel");break;case"enable":t.enable("cancel")}}})})})})}};o.add("imagetools",function(t){varn,e,r,o,i,u,a,c,f=l(0),s=l(null);n=t,e=f,d.each({mceImageRotateLeft:Ct(n,e,-90),mceImageRotateRight:Ct(n,e,90),mceImageFlipVertical:Ot(n,e,"v"),mceImageFlipHorizontal:Ot(n,e,"h"),mceEditImage:St(n,e)},function(t,e){n.addCommand(e,t)}),o=function(t){returnfunction(){returnr.execCommand(t)}},(r=t).ui.registry.addButton("rotateleft",{tooltip:"Rotate counterclockwise",icon:"rotate-left",onAction:o("mceImageRotateLeft")}),r.ui.registry.addButton("rotateright",{tooltip:"Rotate clockwise",icon:"rotate-right",onAction:o("mceImageRotateRight")}),r.ui.registry.addButton("flipv",{tooltip:"Flip vertically",icon:"flip-vertically",onAction:o("mceImageFlipVertical")}),r.ui.registry.addButton("fliph",{tooltip:"Flip horizontally",icon:"flip-horizontally",onAction:o("mceImageFlipHorizontal")}),r.ui.registry.addButton("editimage",{tooltip:"Edit image",icon:"edit-image",onAction:o("mceEditImage"),onSetup:function(e){vart=function(){vart=Tt(r).forall(function(t){returnbt(r,t.dom).isNone()});e.setDisabled(t)};returnr.on("NodeChange",t),function(){r.off("NodeChange",t)}}}),r.ui.registry.addButton("imageoptions",{tooltip:"Image options",icon:"image",onAction:o("mceImage")}),r.ui.registry.addContextMenu("imagetools",{update:function(t){returnbt(r,t).fold(function(){return[]},function(t){return[{text:"Edit image",icon:"edit-image",onAction:o("mceEditImage")}]})}}),(i=t).ui.registry.addContextToolbar("imagetools",{items:i.getParam("imagetools_toolbar","rotateleft rotateright flipv fliph editimage imageoptions"),predicate:function(t){returnbt(i,t).isSome()},position:"node",scope:"node"}),a=f,c=s,(u=t).on("NodeChange",function(t){vare=c.get(),n=bt(u,t.element);e&&!n.exists(function(t){returne.src===t.src})&&(Lt(a),u.editorUpload.uploadImagesAuto(),c.set(null)),n.each(c.set)})})}();