/*!
 * Tiny Uploadcare plugin
 *
 * Copyright (c) 2024 Ephox Corporation DBA Tiny Technologies, Inc.
 * Licensed under the Tiny commercial license. See https://www.tiny.cloud/legal/
 *
 * Version: 8.3.0-112
 */

/*!
 * This resource uses the code from the following libraries:
 *
 * upload-client
 *  Copyright (c) 2019 Uploadcare Inc.
 *  https://github.com/uploadcare/uploadcare-js-api-clients
 *
 */

!function(){"use strict";const e=Object.getPrototypeOf,t=(e,t,r)=>!!r(e,t.prototype)||e.constructor?.name===t.name,r=e=>r=>(e=>{const r=typeof e;return null===e?"null":"object"===r&&Array.isArray(e)?"array":"object"===r&&t(e,String,((e,t)=>t.isPrototypeOf(e)))?"string":r})(r)===e,o=e=>t=>typeof t===e,n=e=>t=>e===t,a=r("string"),s=r("object"),i=r=>((r,o)=>s(r)&&t(r,o,((t,r)=>e(t)===r)))(r,Object),c=r("array"),l=n(null),d=o("boolean"),u=n(void 0),m=e=>null==e,p=e=>!m(e),g=o("function"),h=o("number"),f=()=>{},y=(e,t)=>(...r)=>e(t.apply(null,r)),v=e=>()=>e,b=e=>e,x=(e,t)=>e===t;function w(e,...t){return(...r)=>{const o=t.concat(r);return e.apply(null,o)}}const T=e=>e(),S=v(!1),k=v(!0);class C{tag;value;static singletonNone=new C(!1);constructor(e,t){this.tag=e,this.value=t}static some(e){return new C(!0,e)}static none(){return C.singletonNone}fold(e,t){return this.tag?t(this.value):e()}isSome(){return this.tag}isNone(){return!this.tag}map(e){return this.tag?C.some(e(this.value)):C.none()}bind(e){return this.tag?e(this.value):C.none()}exists(e){return this.tag&&e(this.value)}forall(e){return!this.tag||e(this.value)}filter(e){return!this.tag||e(this.value)?this:C.none()}getOr(e){return this.tag?this.value:e}or(e){return this.tag?this:e}getOrThunk(e){return this.tag?this.value:e()}orThunk(e){return this.tag?this:e()}getOrDie(e){if(this.tag)return this.value;throw new Error(e??"Called getOrDie on None")}static from(e){return p(e)?C.some(e):C.none()}getOrNull(){return this.tag?this.value:null}getOrUndefined(){return this.value}each(e){this.tag&&e(this.value)}toArray(){return this.tag?[this.value]:[]}toString(){return this.tag?`some(${this.value})`:"none()"}}const A=Array.prototype.indexOf,$=Array.prototype.push,E=(e,t)=>{return r=e,o=t,A.call(r,o)>-1;var r,o},P=(e,t)=>{for(let r=0,o=e.length;r<o;r++)if(t(e[r],r))return!0;return!1},j=(e,t)=>{const r=[];for(let o=0;o<e;o++)r.push(t(o));return r},R=(e,t)=>{const r=e.length,o=new Array(r);for(let n=0;n<r;n++){const r=e[n];o[n]=t(r,n)}return o},_=(e,t)=>{for(let r=0,o=e.length;r<o;r++)t(e[r],r)},O=(e,t)=>{const r=[];for(let o=0,n=e.length;o<n;o++){const n=e[o];t(n,o)&&r.push(n)}return r},N=(e,t,r)=>(_(e,((e,o)=>{r=t(r,e,o)})),r),U=(e,t)=>((e,t,r)=>{for(let o=0,n=e.length;o<n;o++){const n=e[o];if(t(n,o))return C.some(n);if(r(n,o))break}return C.none()})(e,t,S),M=(e,t)=>{for(let r=0,o=e.length;r<o;r++)if(t(e[r],r))return C.some(r);return C.none()},z=e=>{const t=[];for(let r=0,o=e.length;r<o;++r){if(!c(e[r]))throw new Error("Arr.flatten item "+r+" was not an array, input: "+e);$.apply(t,e[r])}return t},I=(e,t)=>z(R(e,t)),L=(e,t)=>{for(let r=0,o=e.length;r<o;++r)if(!0!==t(e[r],r))return!1;return!0},B=(e,t)=>t>=0&&t<e.length?C.some(e[t]):C.none(),D=e=>B(e,0),q=Object.keys,K=Object.hasOwnProperty,F=(e,t)=>{const r=q(e);for(let o=0,n=r.length;o<n;o++){const n=r[o];t(e[n],n)}},V=(e,t)=>H(e,((e,r)=>({k:r,v:t(e,r)}))),H=(e,t)=>{const r={};return F(e,((e,o)=>{const n=t(e,o);r[n.k]=n.v})),r},W=(e,t)=>{const r={};var o;return((e,t,r,o)=>{F(e,((e,n)=>{(t(e,n)?r:o)(e,n)}))})(e,t,(o=r,(e,t)=>{o[t]=e}),f),r},J=(e,t)=>G(e,t)?C.from(e[t]):C.none(),G=(e,t)=>K.call(e,t),X=(e,t)=>G(e,t)&&void 0!==e[t]&&null!==e[t],Q=e=>{let t=e;return{get:()=>t,set:e=>{t=e}}},Y=e=>{const t=t=>t(e),r=v(e),o=()=>n,n={tag:!0,inner:e,fold:(t,r)=>r(e),isValue:k,isError:S,map:t=>ee.value(t(e)),mapError:o,bind:t,exists:t,forall:t,getOr:r,or:o,getOrThunk:r,orThunk:o,getOrDie:r,each:t=>{t(e)},toOptional:()=>C.some(e)};return n},Z=e=>{const t=()=>r,r={tag:!1,inner:e,fold:(t,r)=>t(e),isValue:S,isError:k,map:t,mapError:t=>ee.error(t(e)),bind:t,exists:S,forall:k,getOr:b,or:b,getOrThunk:T,orThunk:T,getOrDie:(o=String(e),()=>{throw new Error(o)}),each:f,toOptional:C.none};var o;return r},ee={value:Y,error:Z,fromOption:(e,t)=>e.fold((()=>Z(t)),Y)},te=(e,t,r)=>Math.min(Math.max(e,t),r);let re=0;const oe=e=>{const t=(new Date).getTime(),r=Math.floor(window.crypto.getRandomValues(new Uint32Array(1))[0]/4294967295*1e9);return re++,e+"_"+r+re+String(t)},ne=e=>(...t)=>{if(0===t.length)throw new Error("Can't merge zero objects");const r={};for(let o=0;o<t.length;o++){const n=t[o];for(const t in n)G(n,t)&&(r[t]=e(r[t],n[t]))}return r},ae=ne(((e,t)=>i(e)&&i(t)?ae(e,t):t)),se=(ne(((e,t)=>t)),(e,t,r,o)=>e.isSome()&&t.isSome()&&r.isSome()?C.some(o(e.getOrDie(),t.getOrDie(),r.getOrDie())):C.none()),ie=(e,t)=>e?C.some(t):C.none(),ce=()=>{const e=(e=>{const t=Q(C.none()),r=()=>t.get().each(e);return{clear:()=>{r(),t.set(C.none())},isSet:()=>t.get().isSome(),get:()=>t.get(),set:e=>{r(),t.set(C.some(e))}}})(f);return{...e,on:t=>e.get().each(t)}},le=(e,t,r)=>""===t||e.length>=t.length&&e.substr(r,r+t.length)===t,de=(e,t,r=0,o)=>{const n=e.indexOf(t,r);return-1!==n&&(!!u(o)||n+t.length<=o)},ue=e=>""===e?"":e.charAt(0).toUpperCase()+e.substring(1),me=(e,t)=>le(e,t,0),pe=(ge=/^\s+|\s+$/g,e=>e.replace(ge,""));var ge;const he=(e,t=10)=>{const r=parseInt(e,t);return isNaN(r)?C.none():C.some(r)},fe=(e,t)=>{let r=null;const o=()=>{l(r)||(clearTimeout(r),r=null)};return{cancel:o,throttle:(...n)=>{o(),r=setTimeout((()=>{r=null,e.apply(null,n)}),t)}}},ye=(e,t)=>{const{type:r,message:o}=t;e.notificationManager.open({type:r,text:o})},ve=e=>{(e=>{switch(e){case"error":return console.error;case"info":return console.info;case"warn":return console.warn;default:return console.log}})(e.type)(e.message)},be=(e,t)=>{const{protect:r,allowList:o=[],blockList:n=[]}=null!=e?e:{};let a;return a=p(r)?r:o.length>0||n.length>0||t,{protect:a,allowList:o,blockList:n}},xe=e=>{const{protect:t,allowList:r,blockList:o}=null!=e?e:{};return e=>{const n=e.toLowerCase();return r.length>0?!P(r,(e=>e.toLowerCase()===n)):o.length>0?P(o,(e=>e.toLowerCase()===n)):t}},we=e=>{const t=xe(e);return(e,r)=>{const o=((e,t)=>`${e}:${t}`)(r,e.toLowerCase());return t(o)}},Te=(e,t,r,o)=>{const n=Reflect.get(e,"on"),a={protectedEventHandlers:[],cleanupScheduled:!1},s=(e,t)=>{o&&console.log(`[EventsProxy] ${e}`,t||"")},i=t=>{"invalid"===t&&a.protectedEventHandlers.length>0&&(s("Removing event handlers",a.protectedEventHandlers),_(a.protectedEventHandlers,(t=>{e.off(t.name,t.callback)})),a.protectedEventHandlers=[])},c=t.onStatusChange(i);return e.on("remove",c),(o,c,l)=>{s(`Adding event listener: ${o}`,{shouldProtect:r(o)});const d=((e,o)=>{const n=r(e),s=t.getStatus(),i=n&&"invalid"===s?f:o;return n&&a.protectedEventHandlers.push({name:e,callback:i}),i})(o,c);return a.cleanupScheduled||(a.cleanupScheduled=!0,window.setTimeout((()=>{i(t.getStatus()),a.cleanupScheduled=!1}),0)),Reflect.apply(n,e,[o,d,l])}},Se=(e,t,r)=>o=>{const n="invalid"!==t.getStatus()&&p(r)?r(o):f,a=((e,t,r)=>{const o=e=>{"invalid"===e&&r.setEnabled(!1)},n=()=>o(t.getStatus());o(t.getStatus()),e.on("NodeChange",n);const a=t.onStatusChange(o);return()=>{e.off("NodeChange",n),a()}})(e,t,o);return e=>{null==n||n(e),a()}},ke=(e,t,r)=>(...o)=>{var n;return"invalid"===e.getStatus()?r:null!==(n=null==t?void 0:t(...o))&&void 0!==n?n:r},Ce=(e,t)=>ke(e,t,Promise.resolve([])),Ae=(e,t)=>ke(e,t,[]),$e=(e,t)=>ke(e,t,!1),Ee=(e,t,r,o)=>{const n=t=>{const{command:n,value:s}=t,i=C.from(s).filter(a).map((e=>e.toLowerCase())),c=n.toLowerCase()===o.toLowerCase(),l=i.exists((e=>r.has(e))),d=i.exists((t=>t===e.queryCommandValue(o)));c&&l&&!d&&t.preventDefault()},s=t.onStatusChange((t=>{if("invalid"===t){e.on("BeforeExecCommand",n);const t=()=>{const t=e.queryCommandValue(o);r.has(t.toLowerCase())&&e.execCommand(o,!1,t)};e.initialized?t():e.on("init",t)}}));e.on("remove",(()=>{s(),e.off("BeforeExecCommand",n)}))},Pe=(e,t,r,o,n,s=!1)=>{const i=new Set,c=new Set,l=(e,t)=>{s&&console.log(`[UiProxy] ${e}`,t||"")};((e,t,r)=>{Ee(e,t,r,"ToggleView")})(e,r,i),((e,t,r)=>{Ee(e,t,r,"ToggleSidebar")})(e,r,c);const d=(t,a,s,i)=>{const c=n(t,s);return l(`${i}: ${t}`,{spec:a,context:o,shouldProtect:c}),c?{...a,onSetup:Se(e,r,a.onSetup)}:a};return new Proxy(t,{get:(e,t,s)=>{const u=Reflect.get(e,t,s);if(!a(t))return u;switch(t){case"addButton":case"addGroupToolbarButton":case"addToggleButton":case"addMenuButton":case"addSplitButton":return(...r)=>{const[o,n,...a]=r,s=d(o,n,"button",String(t));return Reflect.apply(u,e,[o,s,...a])};case"addMenuItem":case"addToggleMenuItem":case"addNestedMenuItem":return(...r)=>{const[o,n,...a]=r,s=d(o,n,"menuitem",String(t));return Reflect.apply(u,e,[o,s,...a])};case"addAutocompleter":return(...a)=>{const[s,i,...c]=a,d=n(s,"autocompleter");if(l(`${String(t)}: ${s}`,{spec:i,context:o,shouldProtect:d}),d){const t={...i,fetch:Ce(r,i.fetch)};return Reflect.apply(u,e,[s,t,...c])}return Reflect.apply(u,e,[s,i,...c])};case"addSidebar":return(...r)=>{const[a,s,...i]=r,d=n(a,"sidebar");if(l(`${String(t)}: ${a}`,{spec:s,context:o,shouldProtect:d}),d){c.add(a.toLowerCase());const t={...s};return Reflect.apply(u,e,[a,t,...i])}return Reflect.apply(u,e,[a,s,...i])};case"addView":return(...r)=>{const[a,s,...c]=r,d=n(a,"view");if(l(`${String(t)}: ${a}`,{spec:s,context:o,shouldProtect:d}),d){i.add(a.toLowerCase());const t={...s};return Reflect.apply(u,e,[a,t,...c])}return Reflect.apply(u,e,[a,s,...c])};case"addContextMenu":return(...a)=>{const[s,i,...c]=a,d=n(s,"contextmenu");if(l(`${String(t)}: ${s}`,{spec:i,context:o,shouldProtect:d}),d){const t={...i,update:Ae(r,i.update)};return Reflect.apply(u,e,[s,t,...c])}return Reflect.apply(u,e,[s,i,...c])};case"addContextToolbar":case"addContextForm":return(...a)=>{const[s,i,...c]=a,d=n(s,"contexttoolbar");if(l(`${String(t)}: ${s}`,{spec:i,context:o,shouldProtect:d}),d){const t={...i,predicate:$e(r,i.predicate)};return Reflect.apply(u,e,[s,t,...c])}return Reflect.apply(u,e,[s,i,...c])};case"addIcon":case"getAll":case"addContext":return u}}})},je=new Set(["addCommand","addCommands","addQueryStateHandler","addQueryValueHandler"]),Re=e=>(t,r)=>{e&&console.log(`[EditorProxy] ${t}`,r||"")},_e=(e,t)=>{const{statusProvider:r,uiContext:o,protection:n,debug:a=!1}=t,{events:s,commands:i,ui:c}=n;Re(a)("Creating enhanced editor with options:",{hasStatusProvider:!!r,uiContext:o,debug:a,protection:n});const{editorUiProxy:l,editorCommandsProxy:d,editorEventListenerProxy:u}=((e,t,r,o,n,a,s)=>{const i=a.protect?{...e.ui,registry:Pe(e,e.ui.registry,t,r,we(a),s)}:e.ui,c=o.protect?((e,t,r,o,n)=>{const a={protectedCommands:[],cleanupScheduled:!1},s=(e,t)=>{n&&console.log(`[CommandsProxy] ${e}`,t||"")},i=(e,t)=>{const n=o(e),s=r.getStatus();return n&&a.protectedCommands.push(e),n&&"invalid"===s?f:t},c=t=>{"invalid"===t&&a.protectedCommands.length>0&&(s("Removing commands",a.protectedCommands),_(a.protectedCommands,(t=>{e.editorCommands.removeCommand(t)})),a.protectedCommands=[])},l=()=>{a.cleanupScheduled||(a.cleanupScheduled=!0,window.setTimeout((()=>{c(r.getStatus()),a.cleanupScheduled=!1}),0))},d=r.onStatusChange(c);return e.on("remove",d),new Proxy(t,{get:(e,r,n)=>{if(s(`Accessing property: ${String(r)}`),"addCommand"===r){const a=Reflect.get(e,r,n);return(e,r,...n)=>{s(`Adding command: ${e}`,{shouldProtect:o(e)});const c=i(e,r);return l(),Reflect.apply(a,t,[e,c,...n])}}if("addCommands"===r){const o=Reflect.get(e,r,n);return(e,r="exec")=>{s(`Adding commands (${r})`,{commandCount:Object.keys(e).length,willApplyEnforcement:"exec"===r});const n="exec"!==r?e:V(e,((e,t)=>i(t,e)));return l(),Reflect.apply(o,t,[n,r])}}return Reflect.get(e,r,n)}})})(e,e.editorCommands,t,xe(o),s):e.editorCommands;return{editorUiProxy:i,editorCommandsProxy:c,editorEventListenerProxy:n.protect?Te(e,t,xe(n),s):e.on.bind(e)}})(e,r,o||"",i,s,c,a),m=((e,t,r,o)=>(n,a,s)=>{const i=String(a);if("on"===a)return Re(o)("on intercepted"),r;if(je.has(i))return Re(o)(`${i} intercepted`),t[i].bind(t);if("editorCommands"===a)return Re(o)("editorCommands accessed"),t;if("ui"===a)return Re(o)("ui accessed"),e;const c=Reflect.get(n,a,s);return g(c)?c.bind(n):c})(l,d,u,a);return new Proxy(e,{get:m,set:(e,t,r,o)=>Reflect.set(e,t,r,o),has:(e,t)=>Reflect.has(e,t),ownKeys:e=>Reflect.ownKeys(e),getOwnPropertyDescriptor:(e,t)=>Reflect.getOwnPropertyDescriptor(e,t),defineProperty:(e,t,r)=>Reflect.defineProperty(e,t,r),deleteProperty:(e,t)=>Reflect.deleteProperty(e,t),isExtensible:e=>Reflect.isExtensible(e),preventExtensions:e=>Reflect.preventExtensions(e),getPrototypeOf:e=>Reflect.getPrototypeOf(e),setPrototypeOf:(e,t)=>Reflect.setPrototypeOf(e,t)})},Oe=e=>parseInt(e,10),Ne=(e,t)=>{const r=e-t;return 0===r?0:r>0?1:-1},Ue=(e,t,r)=>({major:e,minor:t,patch:r}),Me=e=>{const t=/([0-9]+)\.([0-9]+)\.([0-9]+)(?:(\-.+)?)/.exec(e);return t?Ue(Oe(t[1]),Oe(t[2]),Oe(t[3])):Ue(0,0,0)},ze=(e,t)=>!!e&&-1===((e,t)=>{const r=Ne(e.major,t.major);if(0!==r)return r;const o=Ne(e.minor,t.minor);if(0!==o)return o;const n=Ne(e.patch,t.patch);return 0!==n?n:0})((e=>Me((e=>[e.majorVersion,e.minorVersion].join(".").split(".").slice(0,3).join("."))(e)))(e),Me(t)),Ie=Me("8.3.0"),Le=`${Ie.major}.${Ie.minor}.0`,Be=`${Ie.major+1}.0.0`,De=(e,t)=>{const{setup:r,protection:o}=t;return(n,a)=>{if(!((e,t)=>ze(e,Le)?(console.error(`The "${t}" plugin requires at least version ${Le} of TinyMCE.`),!1):!!ze(e,Be)||(console.error(`The "${t}" plugin requires at least version ${Le} of TinyMCE but less than ${Be}.`),!1))(tinymce,e)||((e,t)=>!!(e=>{var t;const r=null===(t=e.options.get("license_key"))||void 0===t?void 0:t.toLowerCase(),o=e.options.get("online_license_key");return m(o)&&"gpl"===r})(e)&&(((e,t)=>{const{console:r,editor:o}=t;p(o)&&(e._skinLoaded?ye(e,o):e.on("SkinLoaded",(()=>{ye(e,o)}))),p(r)&&ve(r)})(e,{console:{type:"error",message:[`The "${t}" plugin requires a valid TinyMCE license key.`,"Read more: https://www.tiny.cloud/docs/tinymce/latest/license-key/"].join(" ")}}),!0))(n,e))return{};const s=(e=>{const{protect:t=!0,events:r,commands:o,ui:n,api:a}=null!=e?e:{};return{protect:t,events:be(r,false),commands:be(o,true),ui:be(n,true),api:be(a,true)}})(o),i=((e="pre-validation")=>{const t=Q(e),r=new Set;let o=!1;const{enableLogging:n=!1}={},a=(e,...t)=>{n&&console.log(`[StatusProvider] ${e}`,...t)};return{setStatus:e=>{const o=t.get();if(o===e)return a("Status unchanged:",e),!1;t.set(e),a("Status changed:",o,"->",e);const n={currentStatus:e,previousStatus:o},s=Array.from(r);return _(s,(e=>{e(n.currentStatus,n.previousStatus)})),!0},onStatusChange:e=>(r.add(e),a("Callback registered, total listeners:",r.size),()=>{r.delete(e)&&a("Callback unregistered, remaining listeners:",r.size)}),getStatus:t.get,hasListeners:()=>r.size>0,destroy:()=>{o||(a("Destroying StatusProvider, clearing",r.size,"listeners"),r.clear(),o=!0)}}})(),c=((e,t,r)=>{const o=`commercial-license-${t}`;return e.ui.registry.addContext(o,(()=>"invalid"!==r.getStatus()&&!e.mode.isReadOnly())),e.licenseKeyManager.validate({plugin:t}).then((e=>{r.setStatus(e?"valid":"invalid")}),(e=>{console.error(e),console.error(`An unknown error occurred when trying to validate "${t}" plugin.`),r.setStatus("invalid")})),{ui:{context:o}}})(n,e,i),l=s.protect?_e(n,{statusProvider:i,uiContext:c.ui.context,debug:t.debug||!1,protection:s}):n,d=((e,t)=>({pluginCode:e,enforcer:{isInvalid:()=>"invalid"===t.getStatus(),onInvalid:e=>t.onStatusChange(((t,r)=>{"invalid"===t&&e(t,r)}))}}))(e,i);return((e,t,r,o)=>{if(t.protect&&t.api.protect&&p(e)){const a=xe(t.api);return(n=e=>"invalid"===r.getStatus()&&a(e),(e,t)=>V(e,((e,r)=>g(e)?(...o)=>{if(n(r.toLowerCase())){const e=`Method "${p(t)?`${t}.`:""}${r}" is not available due to license key restrictions.`,o=new Error(e);throw console.error(e),o}return e(...o)}:e)))(e,o)}var n;return e})(r(l,a,d),s,i,e)}},qe=e=>{if(null==e)throw new Error("Node cannot be null or undefined");return{dom:e}},Ke=(e,t)=>{const r=(t||document).createElement("div");if(r.innerHTML=e,!r.hasChildNodes()||r.childNodes.length>1){const t="HTML does not have a single root node";throw console.error(t,e),new Error(t)}return qe(r.childNodes[0])},Fe=(e,t)=>{const r=(t||document).createElement(e);return qe(r)},Ve=qe,He=(e,t)=>{const r=e.dom;if(1!==r.nodeType)return!1;{const e=r;if(void 0!==e.matches)return e.matches(t);if(void 0!==e.msMatchesSelector)return e.msMatchesSelector(t);if(void 0!==e.webkitMatchesSelector)return e.webkitMatchesSelector(t);if(void 0!==e.mozMatchesSelector)return e.mozMatchesSelector(t);throw new Error("Browser lacks native selectors")}},We=e=>1!==e.nodeType&&9!==e.nodeType&&11!==e.nodeType||0===e.childElementCount,Je=e=>e.dom.nodeName.toLowerCase(),Ge=e=>t=>(e=>e.dom.nodeType)(t)===e,Xe=Ge(1),Qe=Ge(3),Ye=Ge(11),Ze=e=>t=>Xe(t)&&Je(t)===e,et=e=>C.from(e.dom.parentNode).map(Ve),tt=e=>Ve(e.dom.host),rt=e=>{const t=Ve((e=>{if(p(e.target)){const t=Ve(e.target);if(Xe(t)&&p(t.dom.shadowRoot)&&e.composed&&e.composedPath){const t=e.composedPath();if(t)return D(t)}}return C.from(e.target)})(e).getOr(e.target)),r=()=>e.stopPropagation(),o=()=>e.preventDefault(),n=y(o,r);return((e,t,r,o,n,a,s)=>({target:e,x:t,y:r,stop:o,prevent:n,kill:a,raw:s}))(t,e.clientX,e.clientY,r,o,n,e)},ot=(e,t,r,o,n)=>{const a=((e,t)=>r=>{e(r)&&t(rt(r))})(r,o);return e.dom.addEventListener(t,a,n),{unbind:w(nt,e,t,a,n)}},nt=(e,t,r,o)=>{e.dom.removeEventListener(t,r,o)},at=k,st=(e,t,r)=>((e,t,r,o)=>ot(e,t,r,o,!1))(e,t,at,r),it=(e,t)=>{et(e).each((r=>{r.dom.insertBefore(t.dom,e.dom)}))},ct=(e,t)=>{e.dom.appendChild(t.dom)},lt=(e,t,r)=>{if(!(a(r)||d(r)||h(r)))throw console.error("Invalid call to Attribute.set. Key ",t,":: Value ",r,":: Element ",e),new Error("Attribute value was not simple");e.setAttribute(t,r+"")},dt=(e,t,r)=>{lt(e.dom,t,r)},ut=(e,t)=>{const r=e.dom;F(t,((e,t)=>{lt(r,t,e)}))},mt=(e,t)=>{const r=e.dom.getAttribute(t);return null===r?void 0:r},pt=(e,t)=>C.from(mt(e,t)),gt=(e,t)=>{const r=e.dom;return!(!r||!r.hasAttribute)&&r.hasAttribute(t)},ht=(e,t)=>{e.dom.removeAttribute(t)},ft=e=>N(e.dom.attributes,((e,t)=>(e[t.name]=t.value,e)),{}),yt=e=>{const t=e.dom;null!==t.parentNode&&t.parentNode.removeChild(t)},vt=e=>e.dom.innerHTML,bt=e=>{const t=Fe("div"),r=Ve(e.dom.cloneNode(!0));return ct(t,r),vt(t)},xt=e=>new Promise(((t,r)=>{const o=()=>{a(),t(e)},n=[st(e,"load",o),st(e,"error",(()=>{a(),r("Unable to load data from image: "+e.dom.src)}))],a=()=>_(n,(e=>e.unbind()));e.dom.complete&&o()})),wt=e=>void 0!==e.style&&g(e.style.getPropertyValue),Tt=e=>{const t=Qe(e)?e.dom.parentNode:e.dom;if(null==t||null===t.ownerDocument)return!1;const r=t.ownerDocument;return(e=>{const t=(e=>Ve(e.dom.getRootNode()))(e);return Ye(r=t)&&p(r.dom.host)?C.some(t):C.none();var r})(Ve(t)).fold((()=>r.body.contains(t)),(o=Tt,n=tt,e=>o(n(e))));var o,n},St=(e,t,r)=>{if(!a(r))throw console.error("Invalid call to CSS.set. Property ",t,":: Value ",r,":: Element ",e),new Error("CSS value must be a string: "+r);wt(e)&&e.style.setProperty(t,r)},kt=(e,t,r)=>{const o=e.dom;St(o,t,r)},Ct=(e,t)=>{const r=e.dom;F(t,((e,t)=>{St(r,t,e)}))},At=(e,t)=>{const r=e.dom,o=window.getComputedStyle(r).getPropertyValue(t);return""!==o||Tt(e)?o:$t(r,t)},$t=(e,t)=>wt(e)?e.style.getPropertyValue(t):"",Et=(e,t)=>{const r=e.dom,o=$t(r,t);return C.from(o).filter((e=>e.length>0))},Pt=(e,t)=>{((e,t)=>{wt(e)&&e.style.removeProperty(t)})(e.dom,t),((e,t,r=x)=>e.exists((e=>r(e,t))))(pt(e,"style").map(pe),"")&&ht(e,"style")},jt=(e,t)=>{const r=r=>{const o=t(r);if(o<=0||null===o){const t=At(r,e);return parseFloat(t)||0}return o},o=(e,t)=>N(t,((t,r)=>{const o=At(e,r),n=void 0===o?0:parseInt(o,10);return isNaN(n)?t:t+n}),0);return{set:(t,r)=>{if(!h(r)&&!r.match(/^[0-9]+$/))throw new Error(e+".set accepts only positive integer values. Value was "+r);const o=t.dom;wt(o)&&(o.style[e]=r+"px")},get:r,getOuter:r,aggregate:o,max:(e,t,r)=>{const n=o(e,r);return t>n?t-n:0}}},Rt=jt("height",(e=>{const t=e.dom;return Tt(e)?t.getBoundingClientRect().height:t.offsetHeight})),_t=jt("width",(e=>{const t=e.dom;return Tt(e)?t.getBoundingClientRect().width:t.offsetWidth}));var Ot=(e,t,r,o,n)=>e(r,o)?C.some(r):g(n)&&n(r)?C.none():t(r,o,n);const Nt=(e,t,r)=>{let o=e.dom;const n=g(r)?r:S;for(;o.parentNode;){o=o.parentNode;const e=Ve(o);if(t(e))return C.some(e);if(n(e))break}return C.none()},Ut=(e,t,r)=>Ot(((e,t)=>t(e)),Nt,e,t,r),Mt=(e,t,r)=>Nt(e,(e=>He(e,t)),r),zt=(e,t)=>(e=>U(e.dom.childNodes,(e=>{return r=Ve(e),He(r,t);var r})).map(Ve))(e),It=(e,t)=>((e,t)=>{const r=void 0===t?document:t.dom;return We(r)?C.none():C.from(r.querySelector(e)).map(Ve)})(t,e),Lt=(e,t)=>{(e=>void 0!==e.dom.classList)(e)?e.dom.classList.add(t):((e,t)=>{((e,t,r)=>{const o=((e,t)=>{const r=mt(e,t);return void 0===r||""===r?[]:r.split(" ")})(e,t),n=o.concat([r]);dt(e,t,n.join(" "))})(e,"class",t)})(e,t)},Bt=(e,t)=>{e.dom.contentEditable=t?"true":"false"},Dt=(e,t)=>((e,t)=>{const r=void 0===t?document:t.dom;return We(r)?[]:R(r.querySelectorAll(e),Ve)})(t,e);var qt;!function(e){e[e.Error=0]="Error",e[e.Value=1]="Value"}(qt||(qt={}));const Kt=(e,t,r)=>e.stype===qt.Error?t(e.serror):r(e.svalue),Ft=e=>({stype:qt.Value,svalue:e}),Vt=e=>({stype:qt.Error,serror:e}),Ht=Kt,Wt=e=>s(e)&&q(e).length>100?" removed due to size":JSON.stringify(e,null,2),Jt=(e,t)=>Vt([{path:e,getErrorInfo:t}]),Gt=e=>({extract:(t,r)=>{return o=e(r),n=e=>((e,t)=>Jt(e,v(t)))(t,e),o.stype===qt.Error?n(o.serror):o;var o,n},toString:v("val")}),Xt=(Qt=a,Gt((e=>{const t=typeof e;return Qt(e)?Ft(e):Vt(`Expected type: string but got: ${t}`)})));var Qt;const Yt=(e,t,r)=>{switch(e.tag){case"field":return t(e.key,e.newKey,e.presence,e.prop);case"custom":return r(e.newKey,e.instantiator)}},Zt=e=>{const t=(e=>{const t=[],r=[];return _(e,(e=>{Kt(e,(e=>r.push(e)),(e=>t.push(e)))})),{values:t,errors:r}})(e);return t.errors.length>0?(r=t.errors,y(Vt,z)(r)):Ft(t.values);var r},er=(e,t,r,o)=>o(J(e,t).getOrThunk((()=>r(e)))),tr=(e,t,r,o,n)=>{const a=e=>n.extract(t.concat([o]),e),s=e=>e.fold((()=>Ft(C.none())),(e=>{const r=n.extract(t.concat([o]),e);return a=r,s=C.some,a.stype===qt.Value?{stype:qt.Value,svalue:s(a.svalue)}:a;var a,s}));switch(e.tag){case"required":return((e,t,r,o)=>J(t,r).fold((()=>((e,t,r)=>Jt(e,(()=>'Could not find valid *required* value for "'+t+'" in '+Wt(r))))(e,r,t)),o))(t,r,o,a);case"defaultedThunk":return er(r,o,e.process,a);case"option":return((e,t,r)=>r(J(e,t)))(r,o,s);case"defaultedOptionThunk":return((e,t,r,o)=>o(J(e,t).map((t=>!0===t?r(e):t))))(r,o,e.process,s);case"mergeWithThunk":return er(r,o,v({}),(t=>{const o=ae(e.process(r),t);return a(o)}))}},rr=e=>({extract:(t,r)=>((e,t,r)=>{const o={},n=[];for(const a of r)Yt(a,((r,a,s,i)=>{const c=tr(s,e,t,r,i);Ht(c,(e=>{n.push(...e)}),(e=>{o[a]=e}))}),((e,r)=>{o[e]=r(t)}));return n.length>0?Vt(n):Ft(o)})(t,r,e),toString:()=>{const t=R(e,(e=>Yt(e,((e,t,r,o)=>e+" -> "+o.toString()),((e,t)=>"state("+e+")"))));return"obj{\n"+t.join("\n")+"}"}}),or=y((e=>({extract:(t,r)=>{const o=R(r,((r,o)=>e.extract(t.concat(["["+o+"]"]),r)));return Zt(o)},toString:()=>"array("+e.toString()+")"})),rr),nr=e=>Gt((t=>e(t).fold(Vt,Ft))),ar=(e,t,r)=>{return o=((e,t,r)=>((e,t)=>e.stype===qt.Error?{stype:qt.Error,serror:t(e.serror)}:e)(t.extract([e],r),(e=>({input:r,errors:e}))))(e,t,r),Kt(o,ee.error,ee.value);var o},sr=(e,t,r,o)=>({tag:"field",key:e,newKey:t,presence:r,prop:o}),ir=(e,t)=>sr(e,e,{tag:"required",process:{}},t),cr=(e,t)=>sr(e,e,{tag:"required",process:{}},(e=>nr((t=>E(e,t)?ee.value(t):ee.error(`Unsupported value: "${t}", choose one of "${e.join(", ")}".`))))(t)),lr=(e,t)=>sr(e,e,{tag:"option",process:{}},t),dr=e=>{try{return!!a(e)&&(new URL(e),!0)}catch(e){return!1}},ur=e=>{const t=new URL(e);return t.pathname.endsWith("/")||(t.pathname=`${t.pathname}/`),t.toString()},mr=e=>/\S+\.[a-zA-Z]{2,4}$/.test(e),pr=e=>/^([0-9a-f]{8}|[0-9a-f]{10})-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-([0-9a-f]{12}|[0-9a-f]{10})$/i.test(e),gr=({protocol:e})=>"http:"===e||"https:"===e||(e=>"blob:"===e)(e),hr=e=>"-"===e,fr=e=>{try{return C.some(new URL(e))}catch(e){return C.none()}},yr=(e,t)=>{const r=[];let o=t;for(;o<e.length;o++){if(hr(e[o]))return[o-1,r];""!==e[o]&&r.push(e[o])}return[o,r]},vr=e=>{let t="";const r=[];for(let o=0;o<e.length;o++)if(hr(e[o])&&o<e.length-1){if(t=e[o+1],hr(t)){o++;continue}const[n,a]=yr(e,o+2);o=n,r.push({name:t,args:a})}return r},br=e=>fr(e).filter(gr).bind((e=>(e=>{const t=e.split("/"),r=(o=t,B(o,o.length-1)).filter(mr);var o;return((e,t)=>M(e,hr).fold((()=>C.some({pathPrefix:e.join("/"),operations:[],fileName:t})),(r=>C.some({pathPrefix:e.slice(0,r).join("/"),operations:vr(e.slice(r)),fileName:t}))))(r.isSome()?t.slice(0,-1):t,r)})(e.pathname).map((t=>((e,t)=>{const r=""===e.host?"":`//${e.host}`;return{prefix:`${e.protocol}${r}${t.pathPrefix}`,operations:t.operations,suffix:t.fileName.getOr("")+e.search+e.hash}})(e,t))))),xr=e=>"preview"===e.name&&0===e.args.length,wr=(e,t)=>br(e).map((e=>(e=>{const t=(e=>{const t=O(e.operations,(r=xr,e=>!r(e)));var r;return P(t,(({name:e})=>(e=>E(["resize","smart_resize","scale_crop","preview"],e))(e)))?{...e,operations:t}:{...e,operations:[{name:"preview",args:[]},...t]}})(e),r=R(t.operations,(e=>["-",e.name,...e.args].join("/")));return[t.prefix.replace(/\/$/,""),...r,""].join("/")+t.suffix})(t(e)))).getOr(e),Tr=(e,t)=>P(e.operations,(e=>e.name===t)),Sr=(e,t)=>({...e,operations:O(e.operations,(e=>!t(e.name,e.args)))}),kr=(e,t)=>wr(e,(e=>Sr(e,(e=>e===t)))),Cr=(e,t)=>wr(e,(e=>Sr(e,t))),Ar=(e,t,r)=>wr(e,(e=>((e,t,r)=>{if(Tr(e,t)){const o=I(e.operations,(e=>{if(e.name===t){const o=r(e.args);return o.length>0?[{name:t,args:o}]:[]}return[e]}));return{...e,operations:o}}return{...e,operations:e.operations.concat({name:t,args:r([])})}})(e,t,r))),$r=(e,t,r)=>wr(e,(e=>((e,t,r)=>{let o=!1;const n=I(e.operations,(e=>{if(t(e.name,e.args)){o=!0;const t=R(r(e.args),(e=>({name:e.name,args:e.args})));return O(t,(e=>e.args.length>0))}return[e]}));return o?{...e,operations:n}:{...e,operations:e.operations.concat(r([]))}})(e,t,r))),Er=(e,t)=>br(e).bind((e=>((e,t)=>U(e.operations,(e=>e.name===t)))(e,t))),Pr=(e,t)=>Er(e,t).bind((e=>C.from(e.args[0]))),jr=(e,t)=>Pr(e,t).bind(he),Rr=(e,t,r)=>((e,t,r)=>Ar(e,t,(e=>[r])))(e,t,String(r)),_r=["none","adaris","briaril","calarel","carris","cynarel","cyren","elmet","elonni","enzana","erydark","fenralan","ferand","galen","gavin","gethriel","iorill","iothari","iselva","jadis","lavra","misiara","namala","nerion","nethari","pamaya","sarnar","sedis","sewen","sorahel","sorlen","tarian","thellassan","varriel","varven","vevera","virkas","yedis","yllara","zatvel","zevcen"],Or=(e,t)=>Ar(e,"filter",(e=>{let r=[];return"none"!==t.name&&e[0]!==t.name&&(r=t.amount.map((e=>[t.name,`${e}`])).getOr([t.name])),r})),Nr=(e,t,r)=>{const o=kr(e,"filter"),{filter:n,args:a}=T((()=>({filter:"scale_crop",args:["96x96","smart"]})));return Ar(Or(o,t),n,v(a))},Ur=e=>({name:e.name,amount:e.amount,label:e.label}),Mr={autoplay:void 0,controls:!0,disablePictureInPicture:void 0,height:void 0,loop:void 0,muted:void 0,poster:void 0,width:void 0,showLogo:!1,posterOffset:void 0},zr=rr([ir("signature",Xt),ir("expire",nr((e=>{const t="Invalid expire value in uploadcare signature provider response must be a number or a parsable string";return h(e)?ee.value(e):a(e)?ee.fromOption(he(e),t):ee.error(t)})))]);const Ir=e=>async t=>{const r=e(t);return s(n=r)&&g(n.then)&&g(n.catch)?(o=await r,ar("uploadcare_signed_upload_auth_provider",zr,o).fold((e=>{return Promise.reject(new Error("Invalid uploadcare signature provider response.\n"+("Errors: \n"+(e=>{const t=e.length>10?e.slice(0,10).concat([{path:[],getErrorInfo:v("... (only showing first ten failures)")}]):e;return R(t,(e=>"Failed path: ("+e.path.join(" > ")+")\n"+e.getErrorInfo()))})((t=e).errors).join("\n")+"\n\nInput object: "+Wt(t.input))));var t}),(e=>(h(e.expire)?C.some(e.expire):he(e.expire)).fold((()=>Promise.reject(new Error("Invalid expire value in uploadcare signature provider response must be a number or a parsable string"))),(t=>Promise.resolve({signature:e.signature,expire:t})))))):Promise.reject(new Error("Invalid signature provider response; expected a promise."));var o,n},Lr=e=>{const t=e.options.get("uploadcare_public_key"),r=C.from(e.options.get("uploadcare_signed_upload_auth_provider")).map(Ir);if(!a(t))throw new Error("Uploadcare public key is not set");return{pubKey:t,signatureProvider:r}},Br=e=>e.options.get("uploadcare_store_type"),Dr=e=>e.options.get("uploadcare_cdn_base_url"),qr=e=>C.from(e.options.get("uploadcare_upload_base_url")),Kr=e=>e.options.get("uploadcare_srcset_steps"),Fr=e=>e.options.isSet("documents_file_types")?e.options.get("documents_file_types"):[{mimeType:"application/msword",extensions:["doc"]},{mimeType:"application/vnd.ms-excel",extensions:["xls"]},{mimeType:"application/vnd.ms-powerpoint",extensions:["ppt","pps"]},{mimeType:"application/vnd.openxmlformats-officedocument.wordprocessingml.document",extensions:["docx"]},{mimeType:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",extensions:["xlsx"]},{mimeType:"application/vnd.openxmlformats-officedocument.presentationml.presentation",extensions:["pptx"]},{mimeType:"application/pdf",extensions:["pdf"]},{mimeType:"application/rtf",extensions:["rtf"]},{mimeType:"text/plain",extensions:["txt"]},{mimeType:"application/vnd.apple.keynote",extensions:["key"]},{mimeType:"application/vnd.apple.pages",extensions:["pages"]},{mimeType:"application/vnd.apple.numbers",extensions:["numbers"]},{mimeType:"audio/wav",extensions:["wav","wave"]},{mimeType:"audio/mpeg",extensions:["mp3"]},{mimeType:"audio/ogg",extensions:["ogg"]},{mimeType:"application/zip",extensions:["zip"]},{mimeType:"application/gzip",extensions:["gz","gzip"]},{mimeType:"application/x-tar",extensions:["tar"]},{mimeType:"application/x-gtar",extensions:["tar.gz","tgz"]},{mimeType:"application/x-compressed-tar",extensions:["tar.gz","tgz"]},{mimeType:"application/x-7z-compressed",extensions:["7z"]},{mimeType:"application/vnd.rar",extensions:["rar"]}],Vr=e=>e.options.get("uploadcare_resources"),Hr=e=>e.options.get("uploadcare_video_properties"),Wr=e=>e.options.get("a11y_advanced_options"),Jr="uc-video",Gr=e=>e.nodeName.toLowerCase()===Jr,Xr={"image/jpeg":["jpg","jpeg","jpe","jif","jfi","jfif"],"image/gif":["gif"],"image/png":["png"],"image/avif":["avif"],"image/bmp":["bmp"],"image/tiff":["tif","tiff"],"image/webp":["webp"],"image/heic":["heic"],"image/x-pcx":["pcx"],"image/x-tga":["tga","icb","vda","vst"]},Qr={...Xr,"application/mxf":["mxf"],"application/ogg":["ogv","ogg","ogx","oga","ogm","spx"],"application/vnd.rn-realmedia":["rm","rma","rmi","rmv","rmvb","rmhd","rmm","ra","ram"],"application/x-riff":["avi","wav"],"video/mp4":["mp4","m4v"],"video/webm":["webm"],"video/3gpp":["3gp","3gpp"],"video/3gpp2":["3g2","3gp2","3gpp2"],"video/MP2T":["m2t","m2ts","MTS"],"video/mj2":["mj2","mjp2"],"video/mpeg":["mpeg","mpg","mpe","m1v","m2v","mpv"],"video/mpeg4-generic":["mp4"],"video/ogg":["ogv","ogg","ogx","oga","ogm","spx"],"video/quicktime":["mov","movie","qt"],"video/vnd.dvb.file":["dvb"],"video/x-4xmv":["4xmv"],"video/x-amv":["amv","mtv"],"video/x-cdxa":["dat"],"video/x-flc":["flc"],"video/x-fli":["fli"],"video/x-flv":["flv"],"video/x-ifo":["ifo"],"video/x-jng":["jng"],"video/x-m4v":["m4v"],"video/x-matroska":["mkv","mk3d","mka","mks"],"video/x-mmm":["mmm"],"video/x-mng":["mng"],"video/x-ms-asf":["asf","wmv","wma"],"video/x-msvideo":["avi"],"video/x-sgi-movie":["movie"],"video/x-vdr":["vdr"]},Yr=e=>{const t=Object.keys(e),r=I(t,(t=>R(e[t],(e=>[e,t]))));return Object.fromEntries(r)};Yr(Qr);const Zr=Yr(Xr),eo=e=>Qr[e],to=["image/jpeg","image/gif","image/png","image/avif","image/bmp","image/tiff","image/webp","image/heic","image/x-pcx","image/x-tga"],ro=["application/mxf","application/ogg","application/vnd.rn-realmedia","application/x-riff","video/mp4","video/webm","video/3gpp","video/3gpp2","video/MP2T","video/mj2","video/mpeg","video/mpeg4-generic","video/ogg","video/quicktime","video/vnd.dvb.file","video/x-4xmv","video/x-amv","video/x-cdxa","video/x-flc","video/x-fli","video/x-flv","video/x-ifo","video/x-jng","video/x-m4v","video/x-matroska","video/x-mmm","video/x-mng","video/x-ms-asf","video/x-msvideo","video/x-sgi-movie","video/x-vdr"],oo=(e,t)=>P(e,(e=>de(t,e.replace("*","")))),no=e=>R(Fr(e),(e=>e.mimeType)),ao=[...to,...ro],so=(e,t)=>oo(no(e),t),io=e=>{const t=(e=>e.options.get("images_file_types"))(e).split(","),r=[...N(t,((e,t)=>{var r;return(r=t,C.from(Zr[r])).fold(f,(t=>e.push(t))),e}),[]),...ro];return O(ao,(e=>oo(r,e)))},co=e=>[...io(e),...no(e)],lo=(e,t)=>E(co(t),e),uo=(e,t)=>P((e=>I(io(e),eo).concat((e=>N(Fr(e),((e,t)=>e.concat(t.extensions).flat()),[]))(e)))(t),(t=>{return r=e.toLowerCase(),o=`.${t.toLowerCase()}`,le(r,o,r.length-o.length);var r,o}));function mo(e){return"[object Object]"===Object.prototype.toString.call(e)}const po=/\W|_/g;function go(e,{ignoreKeys:t}={ignoreKeys:[]}){return Array.isArray(e)?e.map((e=>ho(e,{ignoreKeys:t}))):e}function ho(e,{ignoreKeys:t}={ignoreKeys:[]}){if(Array.isArray(e))return go(e,{ignoreKeys:t});if(!mo(e))return e;const r={};for(const n of Object.keys(e)){let a=e[n];t.includes(n)?r[n]=a:(mo(a)?a=ho(a,{ignoreKeys:t}):Array.isArray(a)&&(a=go(a,{ignoreKeys:t})),r[(o=n,o.split(po).map(((e,t)=>e.charAt(0)[t>0?"toUpperCase":"toLowerCase"]()+e.slice(1))).join(""))]=a)}var o;return r}const fo={factor:2,time:100};class yo extends Error{}class vo extends yo{originalProgressEvent;constructor(e){super(),this.name="NetworkError",this.message="Network error",Object.setPrototypeOf(this,vo.prototype),this.originalProgressEvent=e}}const bo=(e,t)=>{e&&(e.aborted?Promise.resolve().then(t):e.addEventListener("abort",(()=>t()),{once:!0}))};class xo extends yo{isCancel=!0;constructor(e="Request canceled"){super(e),this.name="CancelError",Object.setPrototypeOf(this,xo.prototype)}}const wo=({check:e,interval:t=500,timeout:r,signal:o})=>new Promise(((n,a)=>{let s,i;bo(o,(()=>{s&&clearTimeout(s),a(new xo("Poll cancelled"))})),r&&(i=setTimeout((()=>{s&&clearTimeout(s),a(new xo("Timed out"))}),r));const c=()=>{try{Promise.resolve(e(o)).then((e=>{e?(i&&clearTimeout(i),n(e)):s=setTimeout(c,t)})).catch((e=>{i&&clearTimeout(i),a(e)}))}catch(e){i&&clearTimeout(i),a(e)}};s=setTimeout(c,0)})),To="https://upload.uploadcare.com",So="application/octet-stream",ko=({method:e,url:t,data:r,headers:o={},signal:n,onProgress:a})=>new Promise(((s,i)=>{const c=new XMLHttpRequest,l=e?.toUpperCase()||"GET";let d=!1;c.open(l,t,!0),o&&Object.entries(o).forEach((e=>{const[t,r]=e;void 0!==r&&!Array.isArray(r)&&c.setRequestHeader(t,r)})),c.responseType="text",bo(n,(()=>{d=!0,c.abort(),i(new xo)})),c.onload=()=>{if(200!=c.status)i(new Error(`Error ${c.status}: ${c.statusText}`));else{const e={method:l,url:t,data:r,headers:o||void 0,signal:n,onProgress:a},i=c.getAllResponseHeaders().trim().split(/[\r\n]+/),d={};i.forEach((function(e){const t=e.split(": "),r=t.shift(),o=t.join(": ");r&&void 0!==r&&(d[r]=o)}));const u=c.response,m=c.status;s({request:e,data:u,headers:d,status:m})}},c.onerror=e=>{d||i(new vo(e))},a&&"function"==typeof a&&(c.upload.onprogress=e=>{e.lengthComputable?a({isComputable:!0,value:e.loaded/e.total}):a({isComputable:!1})}),r?c.send(r):c.send()})),Co=e=>"undefined"!=typeof Blob&&e instanceof Blob,Ao=e=>"undefined"!=typeof File&&e instanceof File,$o=e=>!!e&&"object"==typeof e&&!Array.isArray(e)&&"uri"in e&&"string"==typeof e.uri;function Eo(e,t,r){if(Array.isArray(r))for(const o of r)Eo(e,`${t}[]`,o);else if((e=>{return!!e&&"object"==typeof e&&"data"in e&&(t=e.data,Co(t)||Ao(t)||$o(t));var t})(r)){const{name:o,contentType:n}=r,a=r.data,s=(({name:e})=>e?[e]:[])({name:o});e.push([t,a,...s])}else if((e=>!!e&&"object"==typeof e&&!Array.isArray(e))(r))for(const[o,n]of Object.entries(r))void 0!==n&&e.push([`${t}[${o}]`,String(n)]);else(e=>"string"==typeof e||"number"==typeof e||void 0===e)(r)&&r&&e.push([t,r.toString()])}function Po(e){const t=new FormData,r=function(e){const t=[];for(const[r,o]of Object.entries(e))Eo(t,r,o);return t}(e);for(const e of r){const[r,o,...n]=e;t.append(r,o,...n)}return t}class jo extends yo{code;request;response;headers;constructor(e,t,r,o,n){super(),this.name="UploadError",this.message=e,this.code=t,this.request=r,this.response=o,this.headers=n,Object.setPrototypeOf(this,jo.prototype)}}const Ro=(e,t,r)=>{const o=new URL(e);return o.pathname=(o.pathname+t).replace("//","/"),r&&(o.search=(e=>{const t=new URLSearchParams;for(const[r,o]of Object.entries(e))o&&"object"==typeof o&&!Array.isArray(o)?Object.entries(o).filter((e=>e[1]??!1)).forEach((e=>t.set(`${r}[${e[0]}]`,String(e[1])))):Array.isArray(o)?o.forEach((e=>{t.append(`${r}[]`,e)})):"string"==typeof o&&o?t.set(r,o):"number"==typeof o&&t.set(r,o.toString());return t.toString()})(r)),o.toString()};function _o(e){return function({libraryName:e,libraryVersion:t,userAgent:r,publicKey:o="",integration:n=""}){const a="JavaScript";return"string"==typeof r?r:"function"==typeof r?r({publicKey:o,libraryName:e,libraryVersion:t,languageName:a,integration:n}):`${[e,t,o].filter(Boolean).join("/")} (${[a,n].filter(Boolean).join("; ")})`}({libraryName:"UploadcareUploadClient",libraryVersion:"6.14.2",...e})}function Oo(e,t){const{retryThrottledRequestMaxTimes:r,retryNetworkErrorMaxTimes:o}=t;return function(e,t=fo){let r=0;return function e(o){const n=Math.round(t.time*t.factor**r);return o({attempt:r,retry:t=>(e=>new Promise((t=>setTimeout(t,e))))(t??n).then((()=>(r+=1,e(o))))})}(e)}((({attempt:t,retry:n})=>e().catch((e=>{if("response"in e&&"RequestThrottledError"===e?.code&&t<r)return n(function(e){const{headers:t}=e||{};if(!t||"string"!=typeof t["retry-after"])return 15e3;const r=parseInt(t["retry-after"],10);return Number.isFinite(r)?1e3*r:15e3}(e));if(e instanceof vo&&t<o)return n(1e3*(t+1));throw e}))))}const No=e=>{let t="";return(Co(e)||Ao(e)||$o(e))&&(t=e.type),t||So},Uo=e=>{let t="";return Ao(e)&&e.name?t=e.name:Co(e)?t="":$o(e)&&e.name&&(t=e.name),t||"original"};function Mo(e){return void 0===e||"auto"===e?"auto":e?"1":"0"}var zo,Io;function Lo(e,{publicKey:t,baseURL:r,source:o,integration:n,userAgent:a,retryThrottledRequestMaxTimes:s,retryNetworkErrorMaxTimes:i,signal:c,onProgress:l}){return wo({check:c=>function(e,{publicKey:t,baseURL:r=To,signal:o,source:n,integration:a,userAgent:s,retryThrottledRequestMaxTimes:i=1,retryNetworkErrorMaxTimes:c=3}){return Oo((()=>ko({method:"GET",headers:{"X-UC-User-Agent":_o({publicKey:t,integration:a,userAgent:s})},url:Ro(r,"/info/",{jsonerrors:1,pub_key:t,file_id:e,source:n}),signal:o}).then((({data:e,headers:t,request:r})=>{const o=ho(JSON.parse(e));if("error"in o)throw new jo(o.error.content,o.error.errorCode,r,o,t);return o}))),{retryThrottledRequestMaxTimes:i,retryNetworkErrorMaxTimes:c})}(e,{publicKey:t,baseURL:r,signal:c,source:o,integration:n,userAgent:a,retryThrottledRequestMaxTimes:s,retryNetworkErrorMaxTimes:i}).then((e=>e.isReady?e:(l&&l({isComputable:!0,value:1}),!1))),signal:c})}!function(e){e.Token="token",e.FileInfo="file_info"}(zo||(zo={})),function(e){e.Unknown="unknown",e.Waiting="waiting",e.Progress="progress",e.Error="error",e.Success="success"}(Io||(Io={}));class Bo{uuid;name;size;isStored;isImage;mimeType;cdnUrl;s3Url;originalFilename;imageInfo;videoInfo;contentInfo;metadata;s3Bucket;defaultEffects=null;constructor(e,{baseCDN:t="https://ucarecdn.com",fileName:r}={}){const{uuid:o,s3Bucket:n}=e,a=Ro(t,`${o}/`),s=n?Ro(`https://${n}.s3.amazonaws.com/`,`${o}/${e.filename}`):null;this.uuid=o,this.name=r||e.filename,this.size=e.size,this.isStored=e.isStored,this.isImage=e.isImage,this.mimeType=e.mimeType,this.cdnUrl=a,this.originalFilename=e.originalFilename,this.imageInfo=e.imageInfo,this.videoInfo=e.videoInfo,this.contentInfo=e.contentInfo,this.metadata=e.metadata||null,this.s3Bucket=n||null,this.s3Url=s,function(e){return"defaultEffects"in e}(e)&&(this.defaultEffects=e.defaultEffects)}}var Do=window.WebSocket;class qo{events=Object.create({});emit(e,t){this.events[e]?.forEach((e=>e(t)))}on(e,t){this.events[e]=this.events[e]||[],this.events[e].push(t)}off(e,t){this.events[e]=t?this.events[e].filter((e=>e!==t)):[]}}class Ko{key;disconnectTime;ws=void 0;queue=[];isConnected=!1;subscribers=0;emmitter=new qo;disconnectTimeoutId=null;constructor(e,t=3e4){this.key=e,this.disconnectTime=t}connect(){if(this.disconnectTimeoutId&&clearTimeout(this.disconnectTimeoutId),!this.isConnected&&!this.ws){const e=`wss://ws.pusherapp.com/app/${this.key}?protocol=5&client=js&version=1.12.2`;this.ws=new Do(e),this.ws.addEventListener("error",(e=>{this.emmitter.emit("error",new Error(e.message))})),this.emmitter.on("connected",(()=>{this.isConnected=!0,this.queue.forEach((e=>this.send(e.event,e.data))),this.queue=[]})),this.ws.addEventListener("message",(e=>{const t=JSON.parse(e.data.toString());switch(t.event){case"pusher:connection_established":this.emmitter.emit("connected",void 0);break;case"pusher:ping":this.send("pusher:pong",{});break;case"progress":case"success":case"fail":this.emmitter.emit(t.channel,((e,t)=>"success"===e?{status:Io.Success,...t}:"progress"===e?{status:Io.Progress,...t}:{status:Io.Error,...t})(t.event,JSON.parse(t.data)))}}))}}disconnect(){const e=()=>{this.ws?.close(),this.ws=void 0,this.isConnected=!1};this.disconnectTime?this.disconnectTimeoutId=setTimeout((()=>{e()}),this.disconnectTime):e()}send(e,t){const r=JSON.stringify({event:e,data:t});this.ws?.send(r)}subscribe(e,t){this.subscribers+=1,this.connect();const r=`task-status-${e}`,o={event:"pusher:subscribe",data:{channel:r}};this.emmitter.on(r,t),this.isConnected?this.send(o.event,o.data):this.queue.push(o)}unsubscribe(e){this.subscribers-=1;const t=`task-status-${e}`,r={event:"pusher:unsubscribe",data:{channel:t}};this.emmitter.off(t),this.isConnected?this.send(r.event,r.data):this.queue=this.queue.filter((e=>e.data.channel!==t)),0===this.subscribers&&this.disconnect()}onError(e){return this.emmitter.on("error",e),()=>this.emmitter.off("error",e)}}let Fo=null;const Vo=e=>{if(!Fo){const t="undefined"==typeof window?0:3e4;Fo=new Ko(e,t)}return Fo},Ho=(e,{publicKey:t,fileName:r,baseURL:o,baseCDN:n,checkForUrlDuplicates:a,saveUrlForRecurrentUploads:s,secureSignature:i,secureExpire:c,store:l,signal:d,onProgress:u,source:m,integration:p,userAgent:g,retryThrottledRequestMaxTimes:h,pusherKey:f="79ae88bd931ea68464d9",metadata:y})=>Promise.resolve((e=>{Vo(e).connect()})(f)).then((()=>function(e,{publicKey:t,baseURL:r=To,store:o,fileName:n,checkForUrlDuplicates:a,saveUrlForRecurrentUploads:s,secureSignature:i,secureExpire:c,source:l="url",signal:d,integration:u,userAgent:m,retryThrottledRequestMaxTimes:p=1,retryNetworkErrorMaxTimes:g=3,metadata:h}){return Oo((()=>ko({method:"POST",headers:{"X-UC-User-Agent":_o({publicKey:t,integration:u,userAgent:m})},url:Ro(r,"/from_url/",{jsonerrors:1,pub_key:t,source_url:e,store:Mo(o),filename:n,check_URL_duplicates:a?1:void 0,save_URL_duplicates:s?1:void 0,signature:i,expire:c,source:l,metadata:h}),signal:d}).then((({data:e,headers:t,request:r})=>{const o=ho(JSON.parse(e));if("error"in o)throw new jo(o.error.content,o.error.errorCode,r,o,t);return o}))),{retryNetworkErrorMaxTimes:g,retryThrottledRequestMaxTimes:p})}(e,{publicKey:t,fileName:r,baseURL:o,checkForUrlDuplicates:a,saveUrlForRecurrentUploads:s,secureSignature:i,secureExpire:c,store:l,signal:d,source:m,integration:p,userAgent:g,retryThrottledRequestMaxTimes:h,metadata:y}))).catch((e=>{const t=Vo(f);return t?.disconnect(),Promise.reject(e)})).then((e=>e.type===zo.FileInfo?e:((e,{signal:t}={})=>{let r=null,o=null;const n=e.map((()=>new AbortController));return bo(t,(()=>{n.forEach((e=>e.abort()))})),Promise.all(e.map(((e,t)=>{const a=(e=>()=>{o=e,n.forEach(((t,r)=>r!==e&&t.abort()))})(t);return Promise.resolve().then((()=>e({stopRace:a,signal:n[t].signal}))).then((e=>(a(),e))).catch((e=>(r=e,null)))}))).then((e=>{if(null===o)throw r;return e[o]}))})([({signal:r})=>function({token:e,publicKey:t,baseURL:r,integration:o,userAgent:n,retryThrottledRequestMaxTimes:a,retryNetworkErrorMaxTimes:s,onProgress:i,signal:c}){return wo({check:c=>function(e,{publicKey:t,baseURL:r=To,signal:o,integration:n,userAgent:a,retryThrottledRequestMaxTimes:s=1,retryNetworkErrorMaxTimes:i=3}={}){return Oo((()=>ko({method:"GET",headers:t?{"X-UC-User-Agent":_o({publicKey:t,integration:n,userAgent:a})}:void 0,url:Ro(r,"/from_url/status/",{jsonerrors:1,token:e}),signal:o}).then((({data:e,headers:t,request:r})=>{const o=ho(JSON.parse(e));if("error"in o&&!(e=>"status"in e&&e.status===Io.Error)(o))throw new jo(o.error.content,o.error.errorCode,r,o,t);return o}))),{retryNetworkErrorMaxTimes:i,retryThrottledRequestMaxTimes:s})}(e,{publicKey:t,baseURL:r,integration:o,userAgent:n,retryThrottledRequestMaxTimes:a,retryNetworkErrorMaxTimes:s,signal:c}).then((t=>{switch(t.status){case Io.Error:return new jo(t.error,t.errorCode);case Io.Waiting:return!1;case Io.Unknown:return new jo(`Token "${e}" was not found.`);case Io.Progress:return i&&("unknown"===t.total?i({isComputable:!1}):i({isComputable:!0,value:t.done/t.total})),!1;case Io.Success:return i&&i({isComputable:!0,value:t.done/t.total}),t;default:throw new Error("Unknown status")}})),signal:c})}({token:e.token,publicKey:t,baseURL:o,integration:p,userAgent:g,retryThrottledRequestMaxTimes:h,onProgress:u,signal:r}),({signal:t})=>(({token:e,pusherKey:t,signal:r,onProgress:o})=>new Promise(((n,a)=>{const s=Vo(t),i=s.onError(a),c=()=>{i(),s.unsubscribe(e)};bo(r,(()=>{c(),a(new xo("pusher cancelled"))})),s.subscribe(e,(e=>{switch(e.status){case Io.Progress:o&&("unknown"===e.total?o({isComputable:!1}):o({isComputable:!0,value:e.done/e.total}));break;case Io.Success:c(),o&&o({isComputable:!0,value:e.done/e.total}),n(e);break;case Io.Error:c(),a(new jo(e.msg,e.error_code))}}))})))({token:e.token,pusherKey:f,signal:t,onProgress:u})],{signal:d}))).then((e=>{if(e instanceof jo)throw e;return e})).then((e=>Lo(e.uuid,{publicKey:t,baseURL:o,integration:p,userAgent:g,retryThrottledRequestMaxTimes:h,onProgress:u,signal:d}))).then((e=>new Bo(e,{baseCDN:n}))),Wo="The file type is not supported",Jo="Back",Go="Apply",Xo="Reset",Qo="Default",Yo="Image",Zo="Face",en="Smart (content-aware)",tn="Ratio {0}",rn="Choose Filter",on="Filter: {0}",nn="None",an={SignatureRequiredError:'Option "uploadcare_signed_upload_auth_provider" is required for this public key.',ProjectPublicKeyInvalidError:'Invalid "uploadcare_public_key" value.'},sn=e=>{const t=new Error((e=>(e=>e instanceof jo)(e)&&a(e.code)?J(an,e.code).getOr(e.message):e.message)(e));return t.stack=e.stack,t},cn=(e,t,r)=>{e.notificationManager.open({text:t,type:"error"}),((e,t)=>{console.error(e+"\n",t)})(t,r)},ln=e=>t=>{const r=sn(t);cn(e,e.translate(["Failed to upload file: {0}",r.message]),r)},dn=e=>t=>cn(e,"Image operation failed",sn(t)),un=e=>"auto"===e?"auto":"temporary"!==e,mn=async e=>e.signatureProvider.map((async t=>t(e.pubKey).then((e=>({secureSignature:e.signature,secureExpire:String(e.expire)}))))).getOrThunk((()=>Promise.resolve({}))),pn=async(e,t)=>{var r,o;const n=await mn(t.credentials),a=Wo;if(""!==e.type&&!t.validate(e.type))return Promise.reject(new Error(a));const s=await((e,{publicKey:t,fileName:r,baseURL:o,secureSignature:n,secureExpire:a,store:s,contentType:i,signal:c,onProgress:l,source:d,integration:u,userAgent:m,retryThrottledRequestMaxTimes:p,retryNetworkErrorMaxTimes:g,baseCDN:h,metadata:f})=>function(e,{publicKey:t,fileName:r,contentType:o,baseURL:n=To,secureSignature:a,secureExpire:s,store:i,signal:c,onProgress:l,source:d="local",integration:u,userAgent:m,retryThrottledRequestMaxTimes:p=1,retryNetworkErrorMaxTimes:g=3,metadata:h}){return Oo((()=>ko({method:"POST",url:Ro(n,"/base/",{jsonerrors:1}),headers:{"X-UC-User-Agent":_o({publicKey:t,integration:u,userAgent:m})},data:Po({file:{data:e,name:r||Uo(e),contentType:o||No(e)},UPLOADCARE_PUB_KEY:t,UPLOADCARE_STORE:Mo(i),signature:a,expire:s,source:d,metadata:h}),signal:c,onProgress:l}).then((({data:e,headers:t,request:r})=>{const o=ho(JSON.parse(e));if("error"in o)throw new jo(o.error.content,o.error.errorCode,r,o,t);return o}))),{retryNetworkErrorMaxTimes:g,retryThrottledRequestMaxTimes:p})}(e,{publicKey:t,fileName:r,contentType:i,baseURL:o,secureSignature:n,secureExpire:a,store:s,signal:c,onProgress:l,source:d,integration:u,userAgent:m,retryThrottledRequestMaxTimes:p,retryNetworkErrorMaxTimes:g,metadata:f}).then((({file:e})=>Lo(e,{publicKey:t,baseURL:o,source:d,integration:u,userAgent:m,retryThrottledRequestMaxTimes:p,retryNetworkErrorMaxTimes:g,onProgress:l,signal:c}))).then((e=>new Bo(e,{baseCDN:h}))))(e,{...t.baseUrl.map((e=>({baseURL:e}))).getOr({}),baseCDN:t.cdnUrl,publicKey:t.credentials.pubKey,store:un(t.storeType),...n,onProgress:e=>{e.isComputable&&t.progress(e.value)}}),i=C.from(null===(o=null===(r=s.contentInfo)||void 0===r?void 0:r.mime)||void 0===o?void 0:o.mime).getOr(s.mimeType);return{url:s.cdnUrl,mimeType:i,isImage:s.isImage,name:s.name,additionalData:p(s.videoInfo)?C.some({videoInfo:s.videoInfo}):C.none()}},gn=e=>new Promise(((t,r)=>{const o=()=>{a(),t(e)},n=[st(e,"load",o),st(e,"error",(()=>{a(),r(new Error("Unable to load data from image: "+e.dom.src))}))],a=()=>_(n,(e=>e.unbind()));e.dom.complete&&o()})),hn=(e,t)=>It(t,"img"),fn=e=>{const t=e.attr("class");return p(t)&&/\bimage\b/.test(t)},yn=e=>t=>{let r=t.length;const o=t=>{t.attr("contenteditable",e?"true":null)};for(;r--;){const n=t[r];fn(n)&&(n.attr("contenteditable",e?"false":null),_(n.getAll("figcaption"),o))}},vn=Ze("img"),bn=Ze("figure"),xn=(e,t)=>me(t,Dr(e)),wn=(e,t)=>vn(t)&&pt(t,"src").exists((t=>xn(e,t))),Tn=async(e,t)=>{dt(t,"src",e),dt(t,"data-mce-src",e),await gn(t)},Sn=e=>{const t=R(e.split(","),pe);return R(t,(e=>{const[t,r]=e.split(/\s+/);return{url:t,descriptor:a(r)?r:""}}))},kn=(e,t,r)=>{const o=O(e,(e=>e<r));return ie(o.length>0,R(o,(e=>`${((e,t)=>Ar(e,"resize",(e=>[`${t}x`])))(t,e)} ${e}w`)).concat(`${t} ${r}w`).join(","))},Cn=e=>`(min-width: ${e}px) ${e}px, 100vw`,An=(e,t,r,o,n)=>{kn(Kr(e),r,o).each((r=>{dt(t,"srcset",r),dt(t,"sizes",Cn(o)),Pn(e,t,o,n)}))},$n=(e,t)=>{pt(e,"srcset").each((r=>{const o=Sn(r),n=R(o,(e=>({url:t(e.url),descriptor:e.descriptor})));dt(e,"srcset",(e=>pe(R(e,(e=>`${e.url} ${e.descriptor}`)).join(",")))(n))}))},En=(e,t)=>{dt(e,"sizes",`${t}px`)},Pn=(e,t,r,o)=>{e.dom.setStyle(t.dom,"aspect-ratio",`${r} / ${o}`)},jn=(e,t,r=t.dom.naturalWidth,o=t.dom.naturalHeight)=>{e.dom.setStyle(t.dom,"width",`min(${r}px, 100%)`),An(e,t,t.dom.src,r,o)},Rn=(e,t,r,o)=>{(e=>!gt(e,"sizes")||pt(e,"sizes").exists((e=>de(e,"(min-width:"))))(t)?(Pn(e,t,t.dom.naturalWidth,t.dom.naturalHeight),dt(t,"sizes",Cn(t.dom.width))):(Pn(e,t,r,o),En(t,r)),kn(Kr(e),t.dom.src,r).fold((()=>dt(t,"srcset","")),(e=>dt(t,"srcset",e)))},_n=oe("data-mce-uc-srcset").replaceAll("_","-"),On=(e,t,r,o)=>e.replaceAll(`${t}/-/resize/`,`${r}-/resize/`).replaceAll(t,o),Nn=e=>{const t=e.options.isSet("images_upload_handler"),r=e.options.isSet("images_upload_url");t||r||(e.options.set("images_upload_handler",(async(t,r)=>{const{url:o}=await pn(Mn(t.blob(),t.filename()),{baseUrl:qr(e),cdnUrl:Dr(e),storeType:Br(e),credentials:Lr(e),progress:e=>r(Math.round(100*e)),validate:t=>lo(t,e)}),n=`${o}-/preview/`;return a=e.undoManager.data,s=e=>de(e,t.blobUri()),i=e=>((e,t,r,o)=>e.replaceAll(`src="${t}"`,`src="${o}"`).replaceAll(`data-mce-src="${t}"`,`data-mce-src="${o}"`).replace(new RegExp(`${_n}="([^"]+)"`,"g"),((e,n)=>de(n,t)?`srcset="${On(n,t,r,o)}"`:e)))(e,t.blobUri(),o,n),_(a,(e=>{s((e=>"complete"===e.type?e.content:e.fragments.join(""))(e))&&((e,t)=>{"complete"===e.type?e.content=t(e.content):e.fragments=R(e.fragments,t)})(e,i)})),_(Dt(Ve(e.getBody()),"img"),(e=>{pt(e,_n).each((r=>{de(r,t.blobUri())&&(dt(e,_n,On(r,t.blobUri(),o,n)),(e=>{pt(e,_n).each((t=>{dt(e,"srcset",t),ht(e,_n)}))})(e))}))})),n;var a,s,i})),e.options.set("automatic_uploads",!0)),e.on("BeforeSetContent",(t=>{var r;t.paste&&!t.uploadcareProcessed&&(r=t.content,de(r,'src="blob:'))&&(t.preventDefault(),t.stopImmediatePropagation(),(async(e,t)=>{const r=Ve((new DOMParser).parseFromString(t,"text/html").body),o=I(Dt(r,"img"),(e=>me(e.dom.src,"blob:")&&!gt(e,"srcset")?[e]:[])),n=await Promise.all(R(o,(e=>{return(t=e.dom.src,new Promise(((e,r)=>{const o=new Image;o.src=t,o.addEventListener("load",(()=>{e({width:o.naturalWidth,height:o.naturalHeight})})),o.addEventListener("error",(()=>{r(new Error("Failed to load image"))}))}))).then((({width:t,height:r})=>({img:e,width:t,height:r})));var t})));return _(n,(({img:t,width:r,height:o})=>{jn(e,t,r,o),(e=>{pt(e,"srcset").each((t=>{dt(e,_n,t),ht(e,"srcset")}))})(t)})),vt(r)})(e,t.content).then((t=>{e.insertContent(t,{paste:!0,uploadcareProcessed:!0})}),ln))}),!0),e.on("PreInit",(()=>{e.serializer.addAttributeFilter(_n,(e=>{_(e,(e=>e.attr(_n,null)))}))}))},Un=(e,t)=>{return{url:!t.isImage||(r=t.mimeType,me(r,"video/"))||so(e,t.mimeType)?t.url:`${t.url}-/preview/`,mimetype:t.mimeType,name:t.name,additionalData:t.additionalData};var r},Mn=(e,t)=>new window.File([e],t,{type:e.type}),zn=async(e,t,r)=>await pn(t,{baseUrl:qr(e),cdnUrl:Dr(e),storeType:Br(e),credentials:Lr(e),progress:r,validate:t=>lo(t,e)}).then((t=>Un(e,t))),In=async(e,t,r)=>{if(me(t,"blob:")){const o=e.editorUpload.blobCache.getByUri(t);return m(o)?Promise.reject(new Error("Blob not found in local cache")):zn(e,Mn(o.blob(),o.filename()),r)}return await(async(e,t)=>{const r=await mn(t.credentials),o=await Ho(e,{...t.baseUrl.map((e=>({baseURL:e}))).getOr({}),baseCDN:t.cdnUrl,publicKey:t.credentials.pubKey,store:un(t.storeType),...r,onProgress:e=>{e.isComputable&&t.progress(e.value)}});return t.validate(o.mimeType)?{url:o.cdnUrl,mimeType:o.mimeType,isImage:o.isImage,name:o.name,additionalData:p(o.videoInfo)?C.some({videoInfo:o.videoInfo}):C.none()}:Promise.reject(new Error(Wo))})(t,{baseUrl:qr(e),cdnUrl:Dr(e),storeType:Br(e),credentials:Lr(e),progress:r,validate:t=>lo(t,e)}).then((t=>Un(e,t)))},Ln={colorAdjustmentDebounceTime:600},Bn=(e,t,r,o=[])=>{class n extends e.HTMLElement{constructor(){super(),this.spec=r(),this.spec.setup(this.attachShadow({mode:"open"}));for(const e in this.spec.properties){const t=this.spec.properties[e].get.bind(this),r=this.spec.properties[e].set.bind(this);Object.defineProperty(this,e,{get(){return t(this)},set(e){r(this,e)}})}}connectedCallback(){this.spec.connectedCallback&&this.spec.connectedCallback(this)}disconnectedCallback(){this.spec.disconnectedCallback&&this.spec.disconnectedCallback(this)}attributeChangedCallback(e,t,r){this.spec.attributeChangedCallback&&this.spec.attributeChangedCallback({element:this,name:e,oldValue:t,newValue:r})}}n.observedAttributes=o,m(e.customElements.get(t))&&e.customElements.define(t,n)},Dn=async(e,t,r,o,n)=>E(ro,r)?(async(e,t,r)=>{const o=Fe("uc-video");var n;dt(o,"uuid",(n=t,fr(n).filter(gr).bind((e=>U(e.pathname.split("/"),pr)))).getOr("")),dt(o,"contenteditable","false");const a=Hr(e);return X(a,"width")||X(a,"height")||dt(o,"fluid","true"),r.each((({videoInfo:t})=>{const r={};X(a,"width")||X(a,"height")||(r.width=`min(${t.video.width}px, 100%)`),J(a,"height").each((e=>{if(p(e)){const o=h(e)?e:parseInt(e,10);r.width=`${Math.round(o*(t.video.width/t.video.height))}px`,r.height=`${o}px`}})),J(a,"width").each((e=>{p(e)&&(r.width=`${e}px`)})),dt(o,"style",e.dom.serializeStyle(r))})),o})(e,t,n):(e=>E(to,e))(r)?(async(e,t)=>{const r=Fe("img");return dt(r,"src",t),await xt(r),jn(e,r),r})(e,t):(async(e,t,r)=>{const o=Fe("a");return dt(o,"href",t),dt(o,"target","_blank"),((e,t)=>{e.dom.textContent=t})(o,r),o})(0,t,o),qn=(e,t)=>{const r=e.dom.createRng();r.setStartAfter(t.dom),r.setEndAfter(t.dom),e.selection.setRng(r)},Kn=Ze("a"),Fn=(e,t)=>{if(Kn(e)&&!t){const t=Fe("span");return((e,t)=>{it(e,t),ct(t,e)})(e,t),ct(t,Ke(" ")),bt(t)}return bt(e)},Vn=(e,t,r=f)=>{const o=Fe("div"),n=["input","NodeChange","ResizeEditor","ResizeWindow","ResizeContent","drop"].join(" "),a=()=>{C.from(e.inline?e.getBody():e.getBody().parentElement).map(Ve).each((r=>{if(!((e,t)=>{const r=e.dom,o=t.dom;return r!==o&&r.contains(o)})(r,t))return void s();const n=e.dom.getPos(t.dom,e.getBody()),a=(i=t,_t.get(i));var i;const c=(e=>Rt.get(e))(t);Ct(o,{left:`${n.x}px`,top:`${n.y}px`,width:`${a}px`,height:`${c}px`,position:"absolute","pointer-events":"none"}),Lt(o,"tox-uc-image-overlay"),dt(o,"data-mce-bogus","all")}))},s=()=>{e.off(n,a),e.off("remove",s),yt(o),r()};return(()=>{const t=Ve(e.getBody());ct(t,o),e.on(n,a,!0),a()})(),e.on("remove",s),{element:o,destroy:s}},Hn="tox-uc-loading-spinner-wrapper",Wn="tox-uc-loading-spinner",Jn=e=>{const t=Fe("progress");return dt(e,"style","flex-direction: column;"),dt(t,"max",100),dt(t,"value",0),ct(e,t),e=>{dt(t,"value",Math.floor(100*e))}},Gn=e=>{const t=Fe("div");return Lt(t,"tox-uc-loading-element"),e.semiTransparentBackground&&(e=>{Lt(e,"tox-uc-loading-background")})(t),e.spinner&&(e=>{Lt(e,Hn);const t=Fe("div");Lt(t,Wn),ct(e,t)})(t),e.whiteBackground&&(e=>{kt(e,"background-color","white")})(t),e.zIndex.each((e=>((e,t)=>{Ct(e,{position:"absolute","z-index":t})})(t,e))),t},Xn="tiny-uploadcare-placeholder",Qn=e=>Je(e)===Xn&&"loading"in e.dom,Yn=(e,t,r)=>{Bn(e.getWin(),t,(()=>{let t=!1,o=f;const n=(e,r)=>{t=r,e.shadowRoot&&It(Ve(e.shadowRoot),".tox-uc-loading-spinner-wrapper").each((e=>{kt(e,"display",r?`var(--${Hn}-display)`:`var(--${Hn}-display-none)`)}))},a=(e,t)=>{o=t};return{setup:t=>{const s=document.createElement("style");s.textContent=`\n        @keyframes tox-rotation {\n          0% {\n            transform: rotate(0deg);\n          }\n          100% {\n            transform: rotate(360deg);\n          }\n        }\n\n        :host {\n          border: var(--${r}--content-border) !important; /* needs important to not be overwritten by all: initial rule */\n        }\n\n        .${Hn} {\n          display: var(--${Hn}-display-none);\n\n          position: var(--${Hn}-position);\n          top: var(--${Hn}-top);\n          left: var(--${Hn}-left);\n\n          width: var(--${Hn}-width);\n          height: var(--${Hn}-height);\n          justify-content: var(--${Hn}-justify-content);\n          align-items: var(--${Hn}-align-items);\n        }\n\n        .${Wn} {\n          aspect-ratio: var(--${Wn}-aspect-ratio);\n          width: var(--${Wn}-width);\n          border-radius: var(--${Wn}-border-radius);\n          border: var(--${Wn}-border);\n          border-bottom-color: var(--${Wn}-border-bottom-color);\n          animation: var(--${Wn}-animation);\n        }\n\n        .${r}--content {\n          cursor: var(--${r}--content-cursor);\n          color: var(--${r}--content-color);\n          background-color: var(--${r}--content-background-color);\n          font-family: var(--${r}--content-font-family);\n          height: var(--${r}--content-height);\n          width: var(--${r}--content-width);\n          display: var(--${r}--content-display);\n          align-items: var(--${r}--content-align-items);\n          justify-content: var(--${r}--content-justify-content);\n          gap: var(--${r}--content-gap);\n\n          svg {\n            fill: var(--${r}--icon-fill);\n            min-width: var(--${r}--icon-min-width);\n          }\n        }\n      `,t.appendChild(s),t.append(((e,t)=>{const r=`\n  ${J(e.ui.registry.getAll().icons,"add-file").getOr("unknown")}\n  <span>${e.translate("Drop files here")}</span>\n  `.trim(),o=document.createElement("span");return o.classList.add(`${t}--content`),o.innerHTML=r,o})(e,r));const i=(e=>{const t=Gn({semiTransparentBackground:!1,whiteBackground:!0,spinner:!0,zIndex:C.none()}),r=Jn(t);return e(t.dom,r),t})(a);t.append(i.dom);const c=Ve(t.host);c.dom.addEventListener("drop",(e=>{const t=e.dataTransfer;var r;e.preventDefault(),e.stopPropagation(),(r=c,U(tinymce.get(),(e=>e.getBody().contains(r.dom)))).each((r=>{(e=>p(e.dataTransfer)&&L(e.dataTransfer.items,(e=>"file"===e.kind)))(e)&&p(t)&&(n(c.dom,!0),(async(e,t,r,o)=>{const n=O(r,(t=>((e,t)=>lo(e.type,t)||uo(e.name,t))(t,e))),a=await Promise.all(R(n,(async t=>{const r=await zn(e,new window.File([t],t.name,{type:t.type}),o);return Dn(e,r.url,r.mimetype,t.name,r.additionalData)})));a.length>0&&ra(e,t).each((t=>{e.undoManager.transact((()=>{qn(e,t);const r=e.selection.getBookmark(),o=e=>((e,t)=>{for(let r=e.length-1;r>=0;r--)if(t(e[r],r))return C.some(r);return C.none()})(a,Kn).exists((t=>t===e));_(a,((r,n)=>{0===n?(e.selection.select(t.dom),e.insertContent(Fn(r,o(n))),yt(t)):(qn(e,Ve(e.selection.getNode())),e.insertContent(Fn(r,o(n))))})),e.selection.moveToBookmark(r)}))}))})(r,mt(c,ta),t.files,o).finally((()=>n(c.dom,!1))).catch(ln))}))}),!1)},properties:{loading:{get:()=>t,set:n},progress:{get:()=>o,set:a}}}}))},Zn="tox-uploadcare-placeholder",ea=e=>{e.on("PreInit",(()=>{(e=>{e.schema.addCustomElements({[Xn]:{extends:"span"}})})(e),Yn(e,Xn,Zn),(e=>{e.parser.addNodeFilter(Xn,(e=>{e.forEach((e=>{e.attr("contenteditable","false")}))})),e.serializer.addNodeFilter(Xn,(e=>{e.forEach((e=>{e.remove()}))}))})(e),(e=>{e.serializer.addNodeFilter(Xn,(e=>{for(let t=0;t<e.length;t++)e[t].remove()}))})(e),(e=>{const t=((e,t,r,o)=>ot(e,t,r,o,!0))(Ve(e.getBody()),"load",at,(t=>{vn(t.target)&&e.nodeChanged()}));e.on("remove",(()=>{t.unbind()}))})(e)})),e.on("ResolveName",(e=>{e.name===Xn&&(e.name="placeholder")}))},ta="data-uc-placeholder-id",ra=(e,t)=>It(Ve(e.getBody()),`[${ta}="${t}"]`),oa=async(e,t,r)=>{t.dom.loading=!0,await r(t.dom.progress).finally((()=>t.dom.loading=!1))},na=e=>t=>((e,t)=>wr(e,(e=>((e,t)=>Tr(e,t)?{...e,operations:O(e.operations,(e=>e.name!==t))}:{...e,operations:e.operations.concat([{name:t,args:[]}])})(e,t))))(t,e),aa=e=>t=>Cr(t,e),sa=(e,t)=>r=>Ar(r,e,t),ia={brightness:{zero:0,min:-100,max:100,keypoints:2},exposure:{zero:0,min:-500,max:500,keypoints:2},gamma:{zero:100,min:0,max:1e3,keypoints:2},contrast:{zero:0,min:-100,max:500,keypoints:2},saturation:{zero:0,min:-100,max:500,keypoints:1},vibrance:{zero:0,min:-100,max:500,keypoints:1},warmth:{zero:0,min:-100,max:100,keypoints:1},enhance:{zero:0,min:0,max:100,keypoints:1}},ca=e=>J(ia,e),la=(e,t,r)=>ca(t).map((o=>"enhance"===t&&50===r?Ar(e,t,v([])):r===o.zero?kr(e,t):Rr(e,t,te(Math.floor(r),o.min,o.max)))).getOr(e),da=na("invert"),ua=na("grayscale"),ma=e=>{const t=(e=>/\d+:\d+/.test(e))(e)?":":"x",[r,o]=R(e.split(t),(e=>he(e)));return{width:r,height:o}},pa=e=>{const{width:t,height:r}=ma(e);return n=r,a=(e,t)=>e/t,(o=t).isSome()&&n.isSome()?C.some(a(o.getOrDie(),n.getOrDie())):C.none();var o,n,a},ga=(e,t)=>{if(de(e,`-/crop/${t}/`))return!0;const r=e.substring(e.indexOf("-/scale_crop/")+13),o=(e=>{const t=[];for(let r=0;r<e.length;r++){const o=e[r];if(!o.isSome())return C.none();t.push(o.getOrDie())}return C.some(t)})(R(r.substring(0,r.indexOf("/")).split("x"),(e=>he(e))));return o.map((e=>{if(e.length<2)return!1;const r=e[0]/e[1],o=e[1]/e[0];switch(t){case"1:1":return Math.round(100*r)/100==1;case"3:4":return Math.round(100*r)/100==.75;case"4:3":return Math.round(100*o)/100==.75;default:return!1}})).getOr(!1)},ha=["smart","smart_faces_objects_points","smart_faces_objects","smart_faces_points","smart_objects_faces_points","smart_objects_faces","smart_objects_points","smart_points","smart_objects","smart_faces"],fa=e=>/\d+x\d+/.test(e),ya=e=>"scale_crop"===e,va=(e,t)=>!(t.length<1)&&(ya(e)||"crop"===e&&("face"===t[0]||"image"===t[0])),ba=(e,t)=>!(t.length<1)&&"crop"===e&&new RegExp(/\d:\d/).test(t[0]),xa=(e,t)=>va(e,t)||ba(e,t),wa=(e,t)=>ba(e,t)||ya(e),Ta=aa(va),Sa=aa(wa),ka=na("flip"),Ca=na("mirror"),Aa=sa("rotate",(e=>0===e.length||"0"===e[0]?["270"]:"270"===e[0]?["180"]:"180"===e[0]?["90"]:[])),$a=sa("rotate",(e=>0===e.length||"0"===e[0]?["90"]:"90"===e[0]?["180"]:"180"===e[0]?["270"]:[])),Ea=e=>{const t=Ve(e.selection.getNode());return ie(vn(t)&&!Qn(t),t)},Pa=e=>Ut(Ve(e.selection.getNode()),bn,(e=>t=>t.dom===e.getBody())(e)),ja=e=>Ea(e).orThunk((()=>Pa(e).bind((e=>hn(0,e))))),Ra=e=>{const t=Ve(e.selection.getNode());return Qn(t)?C.some(t):C.none()},_a=e=>ja(e).bind((e=>Pr(e.dom.src,"filter"))).filter((e=>E(_r,e))),Oa=(e,t,r)=>{e.undoManager.transact((()=>{Ea(e).fold((()=>Pa(e).each((e=>r(e)))),(e=>t(e)))}))},Na=(e,t,r)=>Ea(e).fold((()=>Pa(e).map((e=>r(e)))),(e=>C.from(t(e)))),Ua="data-mce-original-dimensions",Ma=e=>{const t=e=>gt(e,Ua)?mt(e,Ua):`${e.dom.width}x${e.dom.height}`;return Na(e,t,(e=>hn(0,e).map(t).getOr("0x0"))).getOr("")},za=["src","alt"],Ia=(e,t)=>pt(e,t).fold((()=>{const r="width"===t?e.dom.clientWidth:e.dom.clientHeight;return Et(e,t).getOr(`${r}px`)}),(e=>`${e}px`)),La=e=>/^[\d.]+px$/.test(e)?(e=>{const t=parseFloat(e);return isNaN(t)?C.none():C.some(t)})(e):C.none(),Ba=(e,t,r)=>{const o=Ia(t,"width"),n=Ia(t,"height"),a=(e=>/^min\(([\d.]+)px,\s*100%\)$/.test(e))(o),s=a?`min(${r.dom.naturalWidth}px, 100%)`:n,i=o;ht(r,"width"),ht(r,"height"),kt(r,"width",s),a?Pt(r,"height"):kt(r,"height",i);const c=La(s).getOr(r.dom.naturalWidth),l=La(i).getOr(r.dom.naturalHeight);Rn(e,r,c,l)},Da=e=>{Oa(e,(t=>((e,t)=>{const r=Fe("figure");dt(r,"class","image"),Bt(r,!1),it(t,r),ct(r,t);const o=Fe("figcaption");Bt(o,!0),At(t,"float")&&"none"!==At(t,"float")&&kt(o,"clear","both"),o.dom.textContent=""!==t.dom.alt?t.dom.alt:tinymce.i18n.translate("Caption"),ct(r,o),((e,t)=>{const r=((e,t)=>{var r;const o=e.dom,n=W(e.schema.getTextBlockElements(),((t,r)=>!e.schema.isValidChild(r,"figure"))),a=o.getParent(t.parentNode,(e=>X(n,e.nodeName)),e.getBody());return a&&null!==(r=o.split(a,t))&&void 0!==r?r:t})(e,t.dom);e.selection.select(r)})(e,r)})(e,t)),(t=>((e,t)=>{hn(0,t).each((r=>{const o=Fe((e=>e.options.get("forced_root_block"))(e));var n,a;a=o,(e=>C.from(e.dom.nextSibling).map(Ve))(n=t).fold((()=>{et(n).each((e=>{ct(e,a)}))}),(e=>{it(e,a)})),ct(o,r),yt(t),e.selection.select(r.dom)}))})(e,t)))},qa=e=>Na(e,(e=>{const t=pt(e,"alt"),r=pt(e,"role");return t.exists((e=>""===e))||r.exists((e=>"presentation"===e||"none"===e))}),(e=>((e,t)=>hn(0,t).exists((e=>{const t=pt(e,"alt"),r=pt(e,"role");return t.exists((e=>""===e))||r.exists((e=>"presentation"===e||"none"===e))})))(0,e))).getOr(!1),Ka=e=>{pt(e,"title").each((t=>{ht(e,"title"),gt(e,"alt")||dt(e,"alt",t)}))},Fa=(e,t,r,o={shouldUpdateDimensions:!1})=>{const n=r.dom.naturalWidth,a=r.dom.naturalHeight,s=r.dom.src;return Ka(r),((e,t,r,o)=>{const n=Vn(e,t),a=Gn({semiTransparentBackground:!0,whiteBackground:!1,spinner:!0,zIndex:C.none()}),s=Jn(a);return o(a.dom,s),ct(n.element,a),r().finally(n.destroy)})(e,r,(async()=>{const i=await(async(e,t,r)=>xn(e,t)?t:(await In(e,t,r)).url)(e,s,f),c=t(i),l=(e=>{const t=Fe("img"),r=W(ft(e),((e,t)=>!E(["data-mce-selected","src","data-mce-src","srcset"],t)));return ut(t,r),t})(r);await Tn(c,l),o.shouldUpdateDimensions&&(e=>{gt(e,"width")&&dt(e,"width",e.dom.naturalWidth),gt(e,"height")&&dt(e,"height",e.dom.naturalHeight)})(l),o.imgUpdate?o.imgUpdate(e,r,l):pt(r,"srcset").filter((t=>!((e,t)=>P(Sn(t),(t=>!xn(e,t.url))))(e,t))).fold((()=>An(e,l,c,n,a)),(e=>{dt(l,"srcset",e),$n(l,t)})),e.undoManager.transact((()=>{((e,t,r)=>{ht(r,"width"),ht(r,"height");const o=W(ft(t),((e,t)=>!E(["data-mce-selected","src","data-mce-src"],t)));ut(r,o),e.dom.setAttrib(r.dom,"src",t.dom.src),t.dom.remove()})(e,l,r)})),await xt(r)}),f).catch(dn(e))},Va=(e,t,r={shouldUpdateDimensions:!1})=>ja(e).map((o=>Fa(e,t,o,r))).getOrThunk((()=>Promise.resolve())),Ha=(e,t={shouldUpdateDimensions:!1})=>async r=>Va(r,e,t),Wa=(e,t={shouldUpdateDimensions:!1})=>r=>{Va(r,e,t)},Ja=(e,t)=>async r=>{try{await xt(t),Ka(t);const o=(e=>Ve(e.dom.cloneNode(!1)))(t);if(await xt(o),!xn(r,o.dom.src)){const e=(await In(r,o.dom.src,f)).url;await Tn(e,o)}gt(o,"srcset")||An(r,o,o.dom.src,o.dom.naturalWidth,o.dom.naturalHeight),await e(o),await xt(o),gt(o,"srcset")||An(r,o,o.dom.src,o.dom.naturalWidth,o.dom.naturalHeight),r.undoManager.transact((()=>((e,t)=>{F(ft(e),((e,r)=>{dt(t,r,e)})),_(q(ft(t)),(r=>{gt(e,r)||ht(t,r)}))})(o,t))),await xt(t)}catch(e){e instanceof Error&&dn(r)(e)}},Ga=Wa(ka),Xa=Wa(Ca),Qa=Ha(da),Ya=Ha(ua),Za=(e,t)=>Wa((e=>((e,t)=>Ar(e,"border_radius",(e=>{switch(t){case"Rounded":return["50"];case"Circle":return["50p"];default:return[]}})))(e,t)))(e),es=Wa(Aa,{imgUpdate:Ba}),ts=Wa($a,{imgUpdate:Ba}),rs=(e,t,r,o)=>Ja((o=>((e,t,r,o)=>(Pn(e,t,r,o),En(t,r),((e,t,r,o)=>{Et(t,"width").fold((()=>dt(t,"width",r)),(()=>e.dom.setStyle(t.dom,"width",`${r}px`))),Et(t,"height").fold((()=>dt(t,"height",o)),(()=>e.dom.setStyle(t.dom,"height",`${o}px`)))})(e,t,r,o),Promise.resolve()))(e,o,t,r)),o)(e),os=(e,t,r,o)=>Wa((e=>((e,t,r,o)=>$r(e,va,(e=>{let n=[];return(e=>{const t=N(e,((e,t)=>{return{smartCropArg:e.smartCropArg||(r=t,E(ha,r)),smartCropDimensionsArg:e.smartCropDimensionsArg||fa(t)};var r}),{smartCropArg:!1,smartCropDimensionsArg:!1});return t.smartCropArg&&t.smartCropDimensionsArg})(e)&&o.isSome()&&U(e,fa).each((e=>{o.each((t=>{((e,t)=>{const r=pa(e),o=pa(t);if(r.exists((e=>o.exists((t=>e===t)))))return C.none();{const e=N(["4:3","3:4","1:1"],((e,t)=>{const{width:r,height:n}=ma(t),a=se(o,r,n,((e,t,r)=>Math.abs(e-t/r)));return e.isNone()||e.exists((e=>a.exists((t=>t<Math.abs(e.diff)))))?a.map((e=>({diff:e,ratio:t}))):e}),C.none());return e.map((e=>e.ratio))}})(t,e).each((e=>{n=[{name:"crop",args:[e]}]}))}))})),[{name:"crop",args:[t,r]}].concat(n)})))(e,t,r,o)))(e),ns=(e,t,r,o)=>Wa((e=>((e,t,r,o)=>$r(e,xa,(e=>o.fold((()=>[{name:"scale_crop",args:[r,t]}]),(e=>((e,t)=>{const{width:r,height:o}=ma(e),{width:n,height:a}=ma(t);var s,i,c,l,d;return(i=o,c=n,l=a,d=(e,t,r,o)=>((e,t,r,o)=>{const n=e/r*o;if(n<=t)return[e,Math.round(n)];const a=t/o*r;return a<=e?[Math.round(a),t]:[0,0]})(e,t,r,o),(s=r).isSome()&&i.isSome()&&c.isSome()&&l.isSome()?C.some(d(s.getOrDie(),i.getOrDie(),c.getOrDie(),l.getOrDie())):C.none()).map((([e,t])=>`${e}x${t}`))})(r,e).fold((()=>[]),(e=>[{name:"scale_crop",args:[e,t]}])))))))(e,t,r,o)))(e),as=(e,t)=>{e.undoManager.transact((()=>{const r=Ve(e.selection.getNode());if(Qn(r)&&(vn(t)||Gr(t.dom))){const o=oe("mce");pt(r,"style").each((e=>{dt(t,"style",e)})),dt(t,"data-mce-id",o),((e,t)=>{const r=e.dom.createRng();r.setStartAfter(t.dom),r.setEndAfter(t.dom),e.selection.setRng(r)})(e,r),yt(r),e.insertContent(bt(t)),D(e.dom.select(`[data-mce-id="${o}"]`)).each((t=>{t.removeAttribute("data-mce-id"),e.selection.select(t)}))}else{const r=oe("mce");dt(t,"data-mce-id",r),e.insertContent(bt(t)),It(Ve(e.getBody()),`[data-mce-id="${r}"]`).each((t=>{ht(t,"data-mce-id"),e.selection.select(t.dom)}))}}))},ss=e=>as(e,(()=>{const e=Fe(Xn);return dt(e,"class",`${Zn} mce-placeholder`),dt(e,ta,`${oe("uc-placeholder")}`),e})()),is=e=>{e.focus(),ss(e)},cs=async(e,t,r,o,n,a)=>{const s=await Dn(e,r,o,n,a),i=ra(e,t),c=Ve(e.selection.getNode());i.exists((e=>{return t=e,c.dom===t.dom;var t}))?as(e,s):e.undoManager.transact((()=>{i.each((t=>{e.selection.select(t.dom),e.insertContent(bt(s)),yt(t)}))}))},ls=(e,t,r)=>(((e,t)=>{Wa((e=>((e,t)=>((e,t)=>br(t).map((({prefix:t})=>wr(e,(e=>({...e,prefix:t}))))).getOr(e))(e,t))(e,t)),{imgUpdate:(e,t,r)=>Rn(e,r,r.dom.naturalWidth,r.dom.naturalHeight)})(e)})(e,r),Promise.resolve()),ds=(e,t)=>t(Na(e,(e=>pt(e,"src").getOr("")),(e=>hn(0,e).bind((e=>pt(e,"src"))).getOr(""))).getOr("")),us=e=>{e.ui.registry.addButton("uploadcare-flip",{tooltip:"Flip vertically",icon:"flip-vertically",onAction:()=>{e.focus(),Ga(e)}}),e.ui.registry.addButton("uploadcare-mirror",{tooltip:"Flip horizontally",icon:"flip-horizontally",onAction:()=>{e.focus(),Xa(e)}}),e.ui.registry.addButton("uploadcare-rotate-counter",{tooltip:"Rotate left",icon:"rotate-left",onAction:()=>{e.focus(),ts(e)}}),e.ui.registry.addButton("uploadcare-rotate",{tooltip:"Rotate right",icon:"rotate-right",onAction:()=>{e.focus(),es(e)}}),e.ui.registry.addMenuButton("uploadcare-crop",{text:Qo,icon:"horizontal-rule",onSetup:t=>(ds(e,(e=>de(e,"-/crop/image/175px175p")))?(t.setText(Yo),t.setIcon("image")):ds(e,(e=>de(e,"-/crop/face/175px175p")))?(t.setText(Zo),t.setIcon("emoji")):ds(e,(e=>de(e,"-/scale_crop/")))&&(t.setText(en),t.setIcon("ai-prompt")),f),fetch:t=>{t([{type:"menuitem",text:Qo,icon:"horizontal-rule",onAction:()=>{(e=>{Wa((e=>Ta(e)),{shouldUpdateDimensions:!0})(e)})(e),e.focus()}},{type:"menuitem",text:Yo,icon:"image",onAction:()=>{os(e,"image","175px175p",C.some(Ma(e))),e.focus()}},{type:"menuitem",text:Zo,icon:"emoji",onAction:()=>{os(e,"face","175px175p",C.some(Ma(e))),e.focus()}},{type:"menuitem",text:en,icon:"ai-prompt",onAction:()=>{ns(e,"smart",Ma(e),C.none()),e.focus()}}])}});const t=t=>{ds(e,(e=>de(e,"-/scale_crop/")))?ns(e,"smart",Ma(e),t):t.fold((()=>(e=>Wa((e=>Sa(e)),{shouldUpdateDimensions:!0})(e))(e)),(t=>((e,t)=>Wa((e=>((e,t)=>$r(e,wa,(e=>[{name:"crop",args:[t]}])))(e,t)),{shouldUpdateDimensions:!0})(e))(e,t)))};e.ui.registry.addToggleButton("uploadcare-ratio-original",{tooltip:"Original ratio",text:"Original",onAction:()=>{t(C.none())},onSetup:t=>(t.setActive(ds(e,(e=>!P(["4:3","3:4","1:1"],(t=>ga(e,t)))))),f)}),e.ui.registry.addToggleButton("uploadcare-ratio-1-1",{tooltip:e.translate([tn,"1:1"]),icon:"unselected",text:"1:1",onAction:()=>{t(C.some("1:1"))},onSetup:t=>(t.setActive(ds(e,(e=>ga(e,"1:1")))),f)}),e.ui.registry.addToggleButton("uploadcare-ratio-4-3",{tooltip:e.translate([tn,"4:3"]),icon:"unselected",text:"4:3",onAction:()=>{t(C.some("4:3"))},onSetup:t=>(t.setActive(ds(e,(e=>ga(e,"4:3")))),f)}),e.ui.registry.addToggleButton("uploadcare-ratio-3-4",{tooltip:e.translate([tn,"3:4"]),icon:"unselected",text:"3:4",onAction:()=>{t(C.some("3:4"))},onSetup:t=>(t.setActive(ds(e,(e=>ga(e,"3:4")))),f)}),e.ui.registry.addToggleButton("uploadcare-border-none",{tooltip:"None",icon:"unselected",onAction:()=>{Za(e,"None")},onSetup:t=>(t.setActive(ds(e,(e=>!de(e,"-/border_radius/")))),f)}),e.ui.registry.addToggleButton("uploadcare-border-rounded",{tooltip:"Rounded",icon:"rounded",onAction:()=>{Za(e,"Rounded")},onSetup:t=>(t.setActive(ds(e,(e=>de(e,"-/border_radius/50/")))),f)}),e.ui.registry.addToggleButton("uploadcare-border-circle",{tooltip:"Circle",icon:"circle",onAction:()=>{Za(e,"Circle")},onSetup:t=>(t.setActive(ds(e,(e=>de(e,"-/border_radius/50p/")))),f)}),e.ui.registry.addMenuButton("uploadcare-enhance-filter",{buttonType:"bordered",tooltip:rn,icon:"color-swatch-remove-color",onSetup:t=>(_a(e).each((r=>{t.setTooltip(e.translate([on,ue(r)])),t.setIcon("photo-filter")})),f),fetch:(t,r,o)=>{((e,t)=>{Wa((e=>(t(e),e)))(e)})(e,(r=>{const n=(e=>e.options.get("uploadcare_filters"))(e);ja(e).map((e=>e.dom.naturalWidth/e.dom.naturalHeight)).getOr(1),t([{type:"fancymenuitem",fancytype:"imageselect",onAction:t=>{const r=_a(e),n=(e=>{const[t,r]=e.split("/");return{name:t,amount:he(r)}})(t.value);r.exists((e=>e===n.name))||r.isNone()&&"none"===n.name||("none"!==n.name?(o.setIcon("photo-filter"),o.setTooltip(e.translate([on,ue(n.name)]))):(o.setIcon("color-swatch-remove-color"),o.setTooltip(rn)),((e,t)=>{Wa((e=>Or(e,t)))(e)})(e,n)),e.focus()},select:t=>Ea(e).bind((t=>Er(e.dom.getAttrib(t.dom,"src"),"filter"))).exists((({args:e})=>e.join("/")===t)),initData:{columns:3,items:R(n,(t=>{return{..."none"===t.name?{icon:"color-swatch-remove-color",type:"resetimage",label:nn,tooltip:nn}:{url:Nr(r,t),type:"imageitem",label:t.label.getOr(ue(t.name)),tooltip:e.translate(["Apply: {0}",t.label.getOr(ue(t.name))])},value:(o=t,[o.name].concat(o.amount.map((e=>`${e}`)).toArray()).join("/"))};var o}))}}])}))}}),e.ui.registry.addToggleButton("uploadcare-enhance-auto-enhance",{icon:"auto-image-enhancement",text:"Auto enhance",onAction:t=>{((e,t=50)=>Ha((e=>la(e,"enhance",t)))(e))(e).then((()=>{t.setActive(ds(e,(e=>de(e,"-/enhance/"))))}))},onSetup:t=>(t.setActive(ds(e,(e=>de(e,"-/enhance/")))),f)})},ms=e=>{e.hasPlugin("quickbars")?(e.addCommand("QuickbarInsertImage",(()=>ss(e))),e.on("PreInit",(()=>{e.ui.registry.addContextToolbar("imageselection",{predicate:S,items:[],position:"node"})}))):e.ui.registry.addButton("uploadcare",{icon:"image",tooltip:"Insert image",onAction:()=>is(e)}),e.ui.registry.addButton("uploadcare-video",{icon:"embed",tooltip:"Insert video",onAction:()=>is(e)}),e.ui.registry.addToggleButton("uploadcare-caption",{icon:"caption",tooltip:"Caption",onSetup:t=>{const r=()=>{t.setActive(Pa(e).isSome())};return e.on("NodeChange",r),r(),()=>{e.off("NodeChange",r)}},onAction:()=>{e.focus(),Da(e)}});const t=(t,r)=>{e.ui.registry.addButton(t,{icon:"upload-from-device",tooltip:"Upload from device",onAction:()=>{(e=>new Promise((t=>{let r=!1;const o=document.createElement("input");o.type="file",o.accept=[...co(e)].join(","),o.style.position="fixed",o.style.left="0",o.style.top="0",o.style.opacity="0.001",document.body.appendChild(o);const n=e=>{var n;r||(null===(n=o.parentNode)||void 0===n||n.removeChild(o),r=!0,t(D(e)))},a=e=>{n(Array.prototype.slice.call(e.target.files))};o.addEventListener("input",a),o.addEventListener("change",a);const s=t=>{const o=()=>{n([])};r||("focusin"===t.type?tinymce.util.Delay.setEditorTimeout(e,o,1e3):o()),e.off("focusin remove",s)};e.on("focusin remove",s),o.click()})))(e).then((t=>{t.each((t=>{Ra(e).each((o=>{oa(0,o,(n=>zn(e,t,n).then((({url:n,additionalData:a,mimetype:s})=>r(e,mt(o,ta),n,s,t.name,a))))).catch(ln(e))}))}))}))}})};t("uploadcare-local",cs),t("uploadcare-replace-local",ls);const r=(t,r)=>{e.ui.registry.addContextForm(t,{launch:{type:"contextformbutton",icon:"upload-from-link",tooltip:"Upload from URL"},placeholder:"https://",label:"Upload from URL:",commands:[{type:"contextformbutton",tooltip:Jo,icon:"chevron-left",align:"start",onAction:e=>{e.back()}},{type:"contextformbutton",icon:"checkmark",tooltip:Go,align:"end",primary:!0,onAction:t=>{e.focus(),((e,t)=>{try{new URL(t)}catch(e){return!1}return!(e=>/.*\.[a-zA-Z]{3,4}$/i.test(e))(t)||uo(t,e)})(e,t.getValue())?Ra(e).each((o=>{oa(0,o,(n=>In(e,t.getValue(),n).then((({url:t,mimetype:n,name:a,additionalData:s})=>r(e,mt(o,ta),t,n,a,s))))).catch(ln(e))})):e.notificationManager.open({text:"Image URL is not correct",type:"error"})}}]})};r("uploadcare-url",cs),r("uploadcare-replace-url",ls),us(e);const o=(t,r)=>{ja(e).each((e=>{t.setActive(((e,t)=>Er(e,t).isSome())(e.dom.src,r))}))};e.ui.registry.addToggleButton("uploadcare-invert",{tooltip:"Invert colors",icon:"invert",onSetup:e=>(o(e,"invert"),f),onAction:t=>{e.focus(),Qa(e).then((()=>{o(t,"invert")}))}}),e.ui.registry.addToggleButton("uploadcare-grayscale",{tooltip:"Grayscale",icon:"grayscale",onSetup:e=>(o(e,"grayscale"),f),onAction:t=>{e.focus(),Ya(e).then((()=>{o(t,"grayscale")}))}}),e.ui.registry.addButton("uploadcare-revert",{icon:"revert-changes",tooltip:"Revert",onAction:()=>{e.focus(),ja(e).each((t=>((e,t)=>Wa((e=>((e,t)=>(_(t.dom.getAttributeNames(),(e=>{E(za,e)||ht(t,e)})),Cr(e,k)))(e,t)),{imgUpdate:(e,t,r)=>jn(e,r)})(e))(e,t)))}})},ps=(e,t,r)=>{const o=Ve(t);return(vn(o)||bn(o))&&!Qn(o)&&e.get().exists((e=>e===r))},gs={blur:{zero:10,min:10,max:100,keypoints:1},sharp:{zero:0,min:0,max:20,keypoints:1}},hs=e=>J(gs,e),fs=(e,t,r)=>{const o=Math.min(e.length,t.length);return j(o,(o=>r(e[o],t[o])))},ys=(e,t,r)=>{const o=r-1;return j(r,(r=>Math.ceil((r*t+(o-r)*e)/o)))},vs=(e,t,r)=>{const o=((e,t,r)=>{return U((o=e,N(o,((e,t,r)=>r<o.length-1?[...e,[t,o[r+1]]]:e),[])),(([e,r])=>e<=t&&t<=r)).map((o=>R(e,(e=>{const n=Math.abs(o[0]-o[1]),a=Math.abs(t-o[0])/n;return o[0]===e?t>r?1:1-a:o[1]===e?t>=r?a:1:0}))));var o})(e,t,r).getOr([]),n=((e,t)=>R(e,((r,o)=>r<t?e.length-o:o)))(e,r),a=fs(o,n,((e,t)=>[e,t]));return fs(e,a,((e,[t,r])=>({value:e,opacity:t,zIndex:r})))},bs=async(e,t,r,o,n,a)=>{let s=((e,t)=>vs(((e,t)=>{const{min:r,max:o,zero:n,keypoints:a}=e;return[...new Set([...ys(r,n,a+1),...ys(n,o,a+1),n,t])].sort(((e,t)=>e-t))})(e,t),t,e.zero))(o,r),i=!1;const c=()=>{return t=e=>He(e,"img"),O(R(e.dom.childNodes,Ve),t);var t},l=async e=>{n(!0);try{const t=await e;return n(!1),t}catch(e){throw n(!1),e}},d=async e=>{const r=Fe("img");return dt(r,"src",a(e)),Ct(r,{position:"absolute",left:"0",top:"0",width:`${t.dom.clientWidth}px`,height:`${t.dom.clientHeight}px`}),await gn(r),r},u=e=>{s=e,c().forEach(((t,r)=>{const o=e[r];Ct(t,{opacity:String(o.opacity),"z-index":String(o.zIndex)})}))};return await(async()=>{Ct(e,{position:"absolute",left:"0",top:"0"});const t=await l(Promise.all(R(s,(e=>d(e.value)))));_(t,(t=>ct(e,t))),u(s)})(),{update:e=>{u(((e,t,r)=>{const o=R(t,(e=>e.value));return vs(o,r,e.zero)})(o,s,e))},commit:e=>i?Promise.resolve():l(d(e)).then((t=>{i||((e,t,r)=>{const o=R(t,(e=>e.value)),n=M(o,(e=>e>=r)).getOr(0);return o[n]!==r?(o.splice(n,0,r),C.some({index:n,keypoints:vs(o,r,e.zero)})):C.none()})(o,s,e).each((({index:e,keypoints:r})=>{B(c(),e).each((e=>{it(e,t),u(r)}))}))})),destroy:()=>{c().forEach(yt),i=!0}}},xs=(e,t,r)=>ca(t).isSome()?la(e,t,r):((e,t,r)=>hs(t).map((o=>r===o.zero?kr(e,t):Rr(e,t,te(Math.floor(r),o.min,o.max)))).getOr(e))(e,t,r),ws=(e,t,r,o)=>{e.undoManager.transact((()=>{pt(t,"src").each((e=>{const n=xs(e,r,o);dt(t,"src",n),dt(t,"data-mce-src",n),$n(t,(e=>xs(e,r,o)))}))}))},Ts=(e,t)=>{const r=ce();let o=0;const n=()=>{r.get().each((({previewer:e,overlay:t,commitAdjustmentThrottle:r})=>{e.destroy(),t.destroy(),r.cancel()})),r.clear()},a=(e,t)=>{r.get().each((({previewer:e,commitAdjustmentThrottle:r})=>{e.update(t),r.throttle(t)}))},s=(e,t)=>((e,t)=>jr(e,t).filter((e=>ca(t).isSome())))(e,t).or(((e,t)=>jr(e,t).filter((e=>hs(t).isSome())))(e,t)),i=(i,c,l,d)=>{ca(l).orThunk((()=>hs(l))).each((u=>{e.ui.registry.addContextForm(`uploadcare-adjust-${l}`,{type:"contextsliderform",launch:{type:"contextformtogglebutton",icon:d,tooltip:i,onSetup:t=>(ja(e).each((e=>{t.setActive(((e,t)=>s(e,t).isSome())(e.dom.src,l))})),f)},onSetup:a=>{const i=new window.AbortController,c=()=>{a.back(),e.focus()};e.on("ObjectResizeStart",c);const d=ja(e).map((c=>{const d=s(c.dom.src,l).getOr(u.zero);return a.setValue(d),((e,t)=>Fa(e,b,t))(e,c).then((()=>{if(!i.signal.aborted&&wn(e,c)){const s=a.getValue();(async(a,s,i,c,l)=>{n();const d=((e,t)=>{const r=Vn(e,t,f);return ct(r.element,Gn({semiTransparentBackground:!1,whiteBackground:!1,spinner:!0,zIndex:C.from("1298")})),r})(e,a);if(l.aborted)return Promise.resolve();l.addEventListener("abort",(()=>d.destroy()));const u=Fe("div");Lt(u,"tox-uc-adjustment-preview-container"),ct(d.element,u);const m=(e=>{const t=e.dom.currentSrc;return""!==t?t:e.dom.src})(a),p=await bs(u,a,c,i,(e=>{e?o++:o--,zt(d.element,".tox-uc-loading-element").each((e=>{o>0?Pt(e,"display"):kt(e,"display","none")}))}),(e=>xs(m,s,e))),g=fe((t=>{p.commit(t).catch(dn),r.get().each((({image:r})=>ws(e,r,s,t)))}),t.colorAdjustmentDebounceTime);r.set({image:a,overlay:d,previewer:p,commitAdjustmentThrottle:g}),l.aborted?d.destroy():l.addEventListener("abort",(()=>d.destroy()))})(c,l,u,s,i.signal).catch(dn),ws(e,c,l,s)}})),c}));return()=>{i.abort(),e.off("ObjectResizeStart",c),n(),d.each((t=>{wn(e,t)&&!e.removed&&ws(e,t,l,a.getValue())}))}},onInput:e=>a(0,e.getValue()),initValue:v(u.zero),min:v(u.min),max:v(u.max),label:c,commands:[{type:"contextformbutton",icon:"chevron-left",tooltip:Jo,align:"start",onAction:e=>{n(),e.back()}},{type:"contextformbutton",text:Xo,onAction:e=>{a(0,u.zero),e.setValue(u.zero)}}]})}))};i("Brightness","Brightness:","brightness","brightness"),i("Contrast","Contrast:","contrast","contrast"),i("Exposure","Exposure:","exposure","exposure"),i("Gamma","Gamma:","gamma","gamma"),i("Vibrance","Vibrance:","vibrance","vibrance"),i("Saturation","Saturation:","saturation","saturation"),i("Warmth","Warmth:","warmth","warmth"),i("Sharpen","Sharpen:","sharp","sharpen"),i("Blur","Blur:","blur","blur")},Ss=(e,t,r)=>{e.ui.registry.addContextToolbar("uploadcare-insert",{predicate:t=>{const r=Ve(t),o=e.schema.getTextBlockElements(),n=t=>t.dom===e.getBody();return!gt(r,"data-mce-bogus")&&((e,t,r)=>Ot(((e,t)=>He(e,t)),Mt,e,'table,[data-mce-bogus="all"]',r))(r,0,n).fold((()=>((t,r,n)=>Ut(t,(t=>Je(t)in o&&e.dom.isEmpty(t.dom)),n).isSome())(r,0,n)),S)},items:(e.hasPlugin("quickbars")?"quickimage":"uploadcare")+" uploadcare-video",position:"line",scope:"editor"}),e.ui.registry.addContextToolbar("uploadcare-placeholder",{predicate:e=>Qn(Ve(e)),items:"uploadcare-local uploadcare-url uploadcare-camera uploadcare-dropbox uploadcare-gdrive",position:"node",scope:"node"}),e.ui.registry.addContextToolbar("uploadcare-img",{predicate:e=>ps(t,e,"uploadcare-img"),items:["uploadcare-subtoolbar-alignment","uploadcare-subtoolbar-transform","uploadcare-subtoolbar-adjust","uploadcare-subtoolbar-border","uploadcare-subtoolbar-enhance","uploadcare-alt","uploadcare-caption",,"uploadcare-revert"].join(" "),position:"node",scope:"node"});const o={type:"contextformbutton",align:"start",icon:"chevron-left",tooltip:Jo,onAction:e=>{e.back()}},n={type:"contextformtogglebutton",icon:"image-decorative",tooltip:"Decorative image",align:"start",onSetup:t=>{const r=qa(e);return t.setActive(r),f},onAction:(e,t)=>{const r=!t.isActive();e.setInputEnabled(!r),t.setActive(r)}},a={type:"contextformbutton",icon:"checkmark",tooltip:Go,primary:!0,onAction:t=>{t.back(),e.focus(),((e,t)=>{Oa(e,(r=>{t.fold((()=>{dt(r,"alt",""),dt(r,"role","presentation")}),(t=>{ht(r,"role"),""===t&&Wr(e)?ht(r,"alt"):dt(r,"alt",t)}))}),(r=>((e,t,r)=>{hn(0,t).each((t=>{r.fold((()=>{dt(t,"alt",""),dt(t,"role","presentation")}),(r=>{ht(t,"role"),""===r&&Wr(e)?ht(t,"alt"):dt(t,"alt",r)}))}))})(e,r,t)))})(e,t.isInputEnabled()?C.from(t.getValue()):C.none())}};e.ui.registry.addContextForm("uploadcare-alt",{launch:{type:"contextformbutton",tooltip:"Alt text",icon:"alt-text"},initValue:()=>(e=>Na(e,(e=>e.dom.alt),(e=>((e,t)=>hn(0,t).bind((e=>pt(e,"alt"))).getOr(""))(0,e))).getOr(""))(e),label:"Alt text:",onSetup:t=>{const r=qa(e);return t.setInputEnabled(!Wr(e)||!r),f},commands:Wr(e)?[o,n,a]:[o,a]}),Ts(e,r)},ks=(e,t)=>{const r=ce();r.set("uploadcare-img");const o=ce();Ss(e,r,t),((e,t)=>{_([{name:"uploadcare-subtoolbar-transform",items:[{label:"Transform:",items:["uploadcare-rotate-counter","uploadcare-rotate","uploadcare-flip","uploadcare-mirror","uploadcare-resize-form"]}],tooltip:"Transform",icon:"transform-image"},{name:"uploadcare-subtoolbar-alignment",items:[{label:"Align:",items:["alignleft","aligncenter","alignright"]}],tooltip:"Align",icon:"align-left"},{name:"uploadcare-subtoolbar-enhance",items:[{items:["uploadcare-enhance-auto-enhance"]},{label:"Filter",items:["uploadcare-enhance-filter"]}],tooltip:"Filters",icon:"auto-image-enhancement"},{name:"uploadcare-subtoolbar-replace",items:[{label:"Replace image:",items:["uploadcare-replace-local","uploadcare-replace-url","uploadcare-camera","uploadcare-dropbox","uploadcare-gdrive"]}],tooltip:"Replace",icon:"reload"},{name:"uploadcare-subtoolbar-adjust",items:[{label:"Adjust:",items:["uploadcare-adjust-brightness","uploadcare-adjust-contrast","uploadcare-adjust-exposure","uploadcare-adjust-gamma","uploadcare-adjust-vibrance","uploadcare-adjust-saturation","uploadcare-adjust-warmth","uploadcare-grayscale","uploadcare-invert","uploadcare-adjust-sharp","uploadcare-adjust-blur"]}],tooltip:"Adjust",icon:"adjustments"}],(r=>{e.ui.registry.addContextToolbar(r.name,{launch:{icon:r.icon,tooltip:r.tooltip},predicate:e=>ps(t,e,r.name),items:Array.isArray(r.items)?[{items:["navigateback"]},...r.items]:"navigateback "+r.items,position:"node",scope:"node"})}))})(e,r),(e=>{const t=ce(),r=fe(((t,r,o)=>{rs(e,r,o,t)}),300);e.ui.registry.addContextForm("uploadcare-resize-form",{type:"contextsizeinputform",launch:{type:"contextformbutton",icon:"resize",tooltip:"Resize"},onSetup:r=>{const o=()=>{r.back(),e.focus()};return ja(e).each(t.set),e.on("ObjectResizeStart",o),()=>{t.clear(),e.off("ObjectResizeStart",o)}},initValue:()=>ja(e).map((e=>({width:`${e.dom.width}`,height:`${e.dom.height}`}))).getOr({width:"0",height:"0"}),onInput:e=>{const{width:o,height:n}=e.getValue();se(t.get(),he(o),he(n),((e,t,o)=>r.throttle(e,t,o)))},label:"Constrain Proportions",commands:[{type:"contextformbutton",align:"start",icon:"chevron-left",tooltip:Jo,onAction:e=>e.back()},{type:"contextformbutton",text:Xo,onAction:r=>{ja(e).each((o=>{((e,t)=>Ja((e=>(async e=>{e.dom.srcset="",ht(e,"srcset"),ht(e,"width"),ht(e,"height"),Pt(e,"width"),Pt(e,"height"),Pt(e,"aspect-ratio"),ht(e,"sizes"),ht(e,Ua),await xt(e),kt(e,"width",`min(${e.dom.naturalWidth}px, 100%)`)})(e)),t)(e))(e,o).then((()=>{t.isSet()&&r.setValue({width:String(o.dom.width),height:String(o.dom.height)})}))}))}}]})})(e),e.on("NodeChange",(e=>{o.get().exists((t=>t===e.element))||(o.set(e.element),r.set("uploadcare-img"))})),e.on("Blur",(()=>{o.clear(),r.set("uploadcare-img")}))},Cs=["tinydrive","moxiemanager","image","editimage"],As=e=>(t,r)=>{t.on("PreInit",(()=>{const e="uploadcare/css/uc-video.css";tinymce.Resource.has(e)?t.dom.styleSheetLoader.loadRawCss(e,tinymce.Resource.get(e)):t.contentCSS.push(t.documentBaseURI.toAbsolute(Vr(t)+"/css/uc-video.css")),t.options.isSet("files_upload_handler")||t.options.set("files_upload_handler",(async(e,r)=>{const o=await zn(t,Mn(e.blob(),e.filename()),r);return{fileName:o.name,url:o.url}})),t.options.set("documents_file_types",Fr(t))})),(e=>{const t=(e=>O(Cs,(t=>e.hasPlugin(t))))(e);return!(t.length>0&&(e.on("Init",(()=>{e.notificationManager.open({text:"Unable to initialize uploadcare due to the presence of incompatible plugins. Details are in the browser console.",type:"error"})})),console.error(`Unable to initialize uploadcare due to the presence of incompatible plugins: ${t.join(", ")}`),1))})(t)&&(((e,t)=>{const r=e.options.register;r("uploadcare_resources",{processor:"string",default:t}),r("uploadcare_cdn_base_url",{processor:e=>dr(e)?{valid:!0,value:ur(e)}:{valid:!1,message:"Needs to be a valid URL"},default:"https://ucarecdn.com/"}),r("uploadcare_upload_base_url",{processor:e=>dr(e)?{valid:!0,value:ur(e)}:{valid:!1,message:"Needs to be a valid URL"}}),r("uploadcare_public_key",{processor:"string"}),r("uploadcare_signed_upload_auth_provider",{processor:"function"}),r("uploadcare_srcset_steps",{processor:e=>c(e)&&L(e,(e=>h(e)&&!Number.isNaN(e)&&Number.isFinite(e)))?{valid:!0,value:e}:{valid:!1,message:"srcset steps need to be an array of numbers."},default:[100,200,300,500,750,1e3,1250,1500,2e3,2500,3e3]}),r("uploadcare_store_type",{processor:e=>{const t=["auto","temporary","permanent"];return E(t,e)?{valid:!0,value:e}:{valid:!1,message:`Store needs to be set to one of [${t.join(", ")}].`}},default:"permanent"});const o=or([cr("name",[..._r]),lr("amount",nr((e=>u(e)||h(e)&&e>=-100&&e<=200?ee.value(e):ee.error("Amount must be a number between -100 and 200")))),lr("label",Xt)]);r("uploadcare_filters",{processor:e=>ar("uploadcare_filters",o,e).fold((e=>({valid:!1,message:"Must be a non-empty array of objects matching the configuration schema: https://www.tiny.cloud/docs/tinymce/latest/uploadcare/#uploadcare-filters"})),(e=>{return{valid:!0,value:(t=e,R(t,Ur))};var t})),default:[{name:"erydark",amount:60},{name:"nerion"},{name:"sarnar",amount:40},{name:"sedis"},{name:"sorlen"},{name:"carris"},{name:"galen"},{name:"iorill"},{name:"none"}]}),r("uploadcare_video_properties",{processor:e=>s(e)?{value:{...e},valid:!0}:{valid:!1,message:"Must be an object."},default:Mr}),r("uploadcare_video_resize",{processor:t=>(!0!==t?e.options.set("object_resizing",e.options.get("object_resizing").replace(",uc-video","")):de(e.options.get("object_resizing"),"uc-video")||e.options.set("object_resizing",e.options.get("object_resizing")+",uc-video"),{value:t,valid:!0}),default:!0})})(t,r),Nn(t),ea(t),ks(t,e),ms(t),(e=>{e.ui.registry.addMenuItem("image",{icon:"image",text:"Image...",onAction:()=>is(e)}),e.ui.registry.addMenuItem("video",{icon:"embed",text:"Video...",onAction:()=>is(e)})})(t),(e=>{e.on("PreInit",(()=>{e.parser.addNodeFilter("figure",yn(!0)),e.serializer.addNodeFilter("figure",yn(!1))}))})(t),(e=>{e.on("ObjectResized",(t=>{const r=Ve(t.target);vn(r)&&(t.stopImmediatePropagation(),rs(e,t.width,t.height,Ve(t.target))),Gr(r.dom)&&(t.stopImmediatePropagation(),e.undoManager.add())}))})(t),(e=>{e.on("PreInit",(()=>{e.schema.addCustomElements({[Jr]:{extends:"div",attributes:["uuid","class","contenteditable","data-setup","autoplay","controls","controlslist","disablepictureinpicture","disableremoteplayback","fluid","height","loop","muted","playsinline","poster","preload","width","crossorigin","posteroffset","showlogo","style"],componentUrl:Vr(e)+"/js/ucvideo.min.js"}})}))})(t),(e=>{e.on("PreInit",(()=>{e.parser.addNodeFilter(Jr,(e=>t=>{_(t,(t=>{const r=t.attr("class");a(r)?t.attr("class",de(r,"tox-uc-video")?r:`${r} tox-uc-video`):t.attr("class","tox-uc-video"),t.attr("contenteditable","false");const o=t.attr("style"),n=o?e.dom.parseStyle(o):{},s=p(t.attr("fluid"))&&"false"!==t.attr("fluid");F(Hr(e),((e,r)=>{p(e)&&m(t.attr(r))&&((!s||"width"!==r&&"height"!==r)&&t.attr(r,`${e}`),s||"width"!==r&&"height"!==r||(n[r]=`${e}px`))})),t.attr("style",e.dom.serializeStyle(n))}))})(e)),e.serializer.addNodeFilter(Jr,(e=>{_(e,(e=>{e.attr("contenteditable",null),e.empty()}))}))}))})(t),(e=>{e.on("NodeChange",(t=>{Gr(t.element)&&It(Ve(e.getBody()),`.mce-offscreen-selection ${Jr}`).each((e=>{dt(e,"muted","true")}))}))})(t))};((e=Ln)=>{((e,t)=>{const{i18n:r=!0}=t;r&&tinymce.PluginManager.requireLangPack(e,"ar,bg-BG,ca,cs,da,de,el,es,eu,fa,fi,fr-FR,he-IL,hi,hr,hu-HU,id,it,ja,kk,ko-KR,ms,nb-NO,nl,pl,pt-BR,pt-PT,ro,ru,sk,sl-SI,sv-SE,th-TH,tr,uk,vi,zh-CN,zh-TW"),tinymce.PluginManager.add(e,De(e,t))})("uploadcare",{setup:As(e)})})()}();