/*!
 * Tiny Comments plugin
 *
 * Copyright (c) 2023 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:
 *
 * preact
 *  Copyright (c) 2015-present Jason Miller
 *  https://github.com/preactjs/preact
 *
 * grapheme-splitter
 *  Copyright (c) 2015 Orlin Georgiev
 *  https://github.com/orling/grapheme-splitter
 *
 * nanostores
 *  Copyright 2020 Andrey Sitnik <andrey@sitnik.ru>
 *  https://github.com/nanostores/nanostores
 *
 * radix-ui
 *  Copyright (c) 2022 WorkOS
 *  https://github.com/radix-ui/
 *
 */

!function(){"use strict";var e=function(e){if(null===e)return"null";if(void 0===e)return"undefined";var t=typeof e;return"object"===t&&(Array.prototype.isPrototypeOf(e)||e.constructor&&"Array"===e.constructor.name)?"array":"object"===t&&(String.prototype.isPrototypeOf(e)||e.constructor&&"String"===e.constructor.name)?"string":t},t=function(e){return{eq:e}},n=t((function(e,t){return e===t})),o=function(e){return t((function(t,n){if(t.length!==n.length)return!1;for(var o=t.length,r=0;r<o;r++)if(!e.eq(t[r],n[r]))return!1;return!0}))},r=t((function(s,a){if(s===a)return!0;var i,c=e(s);return c===e(a)&&(function(e){return-1!==["undefined","boolean","number","string","function","xml","null"].indexOf(e)}(c)?s===a:"array"===c?o(r).eq(s,a):"object"===c&&(i=r,t((function(e,r){var s=Object.keys(e),a=Object.keys(r);if(!function(e,n){return function(e,n){return t((function(t,o){return e.eq(n(t),n(o))}))}(o(e),(function(e){return function(e,t){return Array.prototype.slice.call(e).sort(t)}(e,n)}))}(n).eq(s,a))return!1;for(var c=s.length,l=0;l<c;l++){var d=s[l];if(!i.eq(e[d],r[d]))return!1}return!0}))).eq(s,a))}));const s=Object.getPrototypeOf,a=(e,t,n)=>!!n(e,t.prototype)||e.constructor?.name===t.name,i=e=>t=>(e=>{const t=typeof e;return null===e?"null":"object"===t&&Array.isArray(e)?"array":"object"===t&&a(e,String,((e,t)=>t.isPrototypeOf(e)))?"string":t})(t)===e,c=e=>t=>typeof t===e,l=e=>t=>e===t,d=i("string"),m=i("object"),u=e=>((e,t)=>m(e)&&a(e,t,((e,t)=>s(e)===t)))(e,Object),p=l(null),v=c("boolean"),g=l(void 0),_=e=>null==e,h=e=>!_(e),f=c("function"),y=c("number"),b=()=>{},w=e=>()=>e,x=e=>e,C=e=>e(),S=w(!1),k=w(!0);class A{tag;value;static singletonNone=new A(!1);constructor(e,t){this.tag=e,this.value=t}static some(e){return new A(!0,e)}static none(){return A.singletonNone}fold(e,t){return this.tag?t(this.value):e()}isSome(){return this.tag}isNone(){return!this.tag}map(e){return this.tag?A.some(e(this.value)):A.none()}bind(e){return this.tag?e(this.value):A.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:A.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 h(e)?A.some(e):A.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 R=Array.prototype.slice,D=Array.prototype.indexOf,O=(e,t)=>{return n=e,o=t,D.call(n,o)>-1;var n,o},E=(e,t)=>{for(let n=0,o=e.length;n<o;n++)if(t(e[n],n))return!0;return!1},P=(e,t)=>{const n=e.length,o=new Array(n);for(let r=0;r<n;r++){const n=e[r];o[r]=t(n,r)}return o},T=(e,t)=>{for(let n=0,o=e.length;n<o;n++)t(e[n],n)},$=(e,t)=>{const n=[];for(let o=0,r=e.length;o<r;o++){const r=e[o];t(r,o)&&n.push(r)}return n},L=(e,t)=>((e,t,n)=>{for(let o=0,r=e.length;o<r;o++){const r=e[o];if(t(r,o))return A.some(r);if(n(r,o))break}return A.none()})(e,t,S),M=(e,t)=>t>=0&&t<e.length?A.some(e[t]):A.none(),N=e=>M(e,0),I=Object.keys,j=Object.hasOwnProperty,U=(e,t)=>{const n=I(e);for(let o=0,r=n.length;o<r;o++){const r=n[o];t(e[r],r)}},B=(e,t)=>H(e,((e,n)=>({k:n,v:t(e,n)}))),H=(e,t)=>{const n={};return U(e,((e,o)=>{const r=t(e,o);n[r.k]=r.v})),n},F=(e,t)=>{const n={};var o;return((e,t,n,o)=>{U(e,((e,r)=>{(t(e,r)?n:o)(e,r)}))})(e,t,(o=n,(e,t)=>{o[t]=e}),b),n},q=(e,t)=>j.call(e,t),V=e=>{let t=e;return{get:()=>t,set:e=>{t=e}}},z=e=>{let t=A.none(),n=[];const o=e=>{r()?s(e):n.push(e)},r=()=>t.isSome(),s=e=>{t.each((t=>{setTimeout((()=>{e(t)}),0)}))};return e((e=>{r()||(t=A.some(e),T(n,s),n=[])})),{get:o,map:e=>z((t=>{o((n=>{t(e(n))}))})),isReady:r}},Y={nu:z,pure:e=>z((t=>{t(e)}))},W=e=>{setTimeout((()=>{throw e}),0)},G=e=>{const t=t=>{e().then(t,W)};return{map:t=>G((()=>e().then(t))),bind:t=>G((()=>e().then((e=>t(e).toPromise())))),anonBind:t=>G((()=>e().then((()=>t.toPromise())))),toLazy:()=>Y.nu(t),toCached:()=>{let t=null;return G((()=>(null===t&&(t=e()),t)))},toPromise:e,get:t}},Q=e=>G((()=>new Promise(e))),K=e=>G((()=>Promise.resolve(e))),J=e=>{const t=t=>t(e),n=w(e),o=()=>r,r={tag:!0,inner:e,fold:(t,n)=>n(e),isValue:k,isError:S,map:t=>Z.value(t(e)),mapError:o,bind:t,exists:t,forall:t,getOr:n,or:o,getOrThunk:n,orThunk:o,getOrDie:n,each:t=>{t(e)},toOptional:()=>A.some(e)};return r},X=e=>{const t=()=>n,n={tag:!1,inner:e,fold:(t,n)=>t(e),isValue:S,isError:k,map:t,mapError:t=>Z.error(t(e)),bind:t,exists:S,forall:k,getOr:x,or:x,getOrThunk:C,orThunk:C,getOrDie:(o=String(e),()=>{throw new Error(o)}),each:b,toOptional:A.none};var o;return n},Z={value:J,error:X,fromOption:(e,t)=>e.fold((()=>X(t)),J)},ee=e=>({...e,toCached:()=>ee(e.toCached()),bindFuture:t=>ee(e.bind((e=>e.fold((e=>K(Z.error(e))),(e=>t(e)))))),bindResult:t=>ee(e.map((e=>e.bind(t)))),mapResult:t=>ee(e.map((e=>e.map(t)))),mapError:t=>ee(e.map((e=>e.mapError(t)))),foldResult:(t,n)=>e.map((e=>e.fold(t,n))),withTimeout:(t,n)=>ee(Q((o=>{let r=!1;const s=setTimeout((()=>{r=!0,o(Z.error(n()))}),t);e.get((e=>{r||(clearTimeout(s),o(e))}))})))}),te=e=>ee(Q(e)),ne=e=>ee(K(Z.value(e))),oe=te,re=ne,se=ne,ae=e=>ee(K(Z.error(e))),ie="undefined"!=typeof window?window:Function("return this;")();let ce=0;const le=e=>{const t=(new Date).getTime(),n=Math.floor(window.crypto.getRandomValues(new Uint32Array(1))[0]/4294967295*1e9);return ce++,e+"_"+n+ce+String(t)},de=(me=(e,t)=>u(e)&&u(t)?de(e,t):t,(...e)=>{if(0===e.length)throw new Error("Can't merge zero objects");const t={};for(let n=0;n<e.length;n++){const o=e[n];for(const e in o)q(o,e)&&(t[e]=me(t[e],o[e]))}return t});var me;const ue=(e,t)=>((e,t)=>{let n=null!=t?t:ie;for(let t=0;t<e.length&&null!=n;++t)n=n[e[t]];return n})(e.split("."),t),pe=(e,t,n=0,o)=>{const r=e.indexOf(t,n);return-1!==r&&(!!g(o)||r+t.length<=o)},ve=(e,t)=>((e,t)=>""===t||e.length>=t.length&&e.substr(0,0+t.length)===t)(e,t),ge=e=>t=>t.replace(e,""),_e=ge(/^\s+|\s+$/g),he=ge(/^\s+/g),fe=e=>e.length>0,ye=(e,t)=>{const{type:n,message:o}=t;e.notificationManager.open({type:n,text:o})},be=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)},we=(e,t)=>{const{protect:n,allowList:o=[],blockList:r=[]}=null!=e?e:{};let s;return s=h(n)?n:o.length>0||r.length>0||t,{protect:s,allowList:o,blockList:r}},xe=e=>{const{protect:t,allowList:n,blockList:o}=null!=e?e:{};return e=>{const r=e.toLowerCase();return n.length>0?!E(n,(e=>e.toLowerCase()===r)):o.length>0?E(o,(e=>e.toLowerCase()===r)):t}},Ce=e=>{const t=xe(e);return(e,n)=>{const o=((e,t)=>`${e}:${t}`)(n,e.toLowerCase());return t(o)}},Se=(e,t,n,o)=>{const r=Reflect.get(e,"on"),s={protectedEventHandlers:[],cleanupScheduled:!1},a=(e,t)=>{o&&console.log(`[EventsProxy] ${e}`,t||"")},i=t=>{"invalid"===t&&s.protectedEventHandlers.length>0&&(a("Removing event handlers",s.protectedEventHandlers),T(s.protectedEventHandlers,(t=>{e.off(t.name,t.callback)})),s.protectedEventHandlers=[])},c=t.onStatusChange(i);return e.on("remove",c),(o,c,l)=>{a(`Adding event listener: ${o}`,{shouldProtect:n(o)});const d=((e,o)=>{const r=n(e),a=t.getStatus(),i=r&&"invalid"===a?b:o;return r&&s.protectedEventHandlers.push({name:e,callback:i}),i})(o,c);return s.cleanupScheduled||(s.cleanupScheduled=!0,window.setTimeout((()=>{i(t.getStatus()),s.cleanupScheduled=!1}),0)),Reflect.apply(r,e,[o,d,l])}},ke=(e,t,n)=>o=>{const r="invalid"!==t.getStatus()&&h(n)?n(o):b,s=((e,t,n)=>{const o=e=>{"invalid"===e&&n.setEnabled(!1)},r=()=>o(t.getStatus());o(t.getStatus()),e.on("NodeChange",r);const s=t.onStatusChange(o);return()=>{e.off("NodeChange",r),s()}})(e,t,o);return e=>{null==r||r(e),s()}},Ae=(e,t,n)=>(...o)=>{var r;return"invalid"===e.getStatus()?n:null!==(r=null==t?void 0:t(...o))&&void 0!==r?r:n},Re=(e,t)=>Ae(e,t,Promise.resolve([])),De=(e,t)=>Ae(e,t,[]),Oe=(e,t)=>Ae(e,t,!1),Ee=(e,t,n,o)=>{const r=t=>{const{command:r,value:s}=t,a=A.from(s).filter(d).map((e=>e.toLowerCase())),i=r.toLowerCase()===o.toLowerCase(),c=a.exists((e=>n.has(e))),l=a.exists((t=>t===e.queryCommandValue(o)));i&&c&&!l&&t.preventDefault()},s=t.onStatusChange((t=>{if("invalid"===t){e.on("BeforeExecCommand",r);const t=()=>{const t=e.queryCommandValue(o);n.has(t.toLowerCase())&&e.execCommand(o,!1,t)};e.initialized?t():e.on("init",t)}}));e.on("remove",(()=>{s(),e.off("BeforeExecCommand",r)}))},Pe=(e,t,n,o,r,s=!1)=>{const a=new Set,i=new Set,c=(e,t)=>{s&&console.log(`[UiProxy] ${e}`,t||"")};((e,t,n)=>{Ee(e,t,n,"ToggleView")})(e,n,a),((e,t,n)=>{Ee(e,t,n,"ToggleSidebar")})(e,n,i);const l=(t,s,a,i)=>{const l=r(t,a);return c(`${i}: ${t}`,{spec:s,context:o,shouldProtect:l}),l?{...s,onSetup:ke(e,n,s.onSetup)}:s};return new Proxy(t,{get:(e,t,s)=>{const m=Reflect.get(e,t,s);if(!d(t))return m;switch(t){case"addButton":case"addGroupToolbarButton":case"addToggleButton":case"addMenuButton":case"addSplitButton":return(...n)=>{const[o,r,...s]=n,a=l(o,r,"button",String(t));return Reflect.apply(m,e,[o,a,...s])};case"addMenuItem":case"addToggleMenuItem":case"addNestedMenuItem":return(...n)=>{const[o,r,...s]=n,a=l(o,r,"menuitem",String(t));return Reflect.apply(m,e,[o,a,...s])};case"addAutocompleter":return(...s)=>{const[a,i,...l]=s,d=r(a,"autocompleter");if(c(`${String(t)}: ${a}`,{spec:i,context:o,shouldProtect:d}),d){const t={...i,fetch:Re(n,i.fetch)};return Reflect.apply(m,e,[a,t,...l])}return Reflect.apply(m,e,[a,i,...l])};case"addSidebar":return(...n)=>{const[s,a,...l]=n,d=r(s,"sidebar");if(c(`${String(t)}: ${s}`,{spec:a,context:o,shouldProtect:d}),d){i.add(s.toLowerCase());const t={...a};return Reflect.apply(m,e,[s,t,...l])}return Reflect.apply(m,e,[s,a,...l])};case"addView":return(...n)=>{const[s,i,...l]=n,d=r(s,"view");if(c(`${String(t)}: ${s}`,{spec:i,context:o,shouldProtect:d}),d){a.add(s.toLowerCase());const t={...i};return Reflect.apply(m,e,[s,t,...l])}return Reflect.apply(m,e,[s,i,...l])};case"addContextMenu":return(...s)=>{const[a,i,...l]=s,d=r(a,"contextmenu");if(c(`${String(t)}: ${a}`,{spec:i,context:o,shouldProtect:d}),d){const t={...i,update:De(n,i.update)};return Reflect.apply(m,e,[a,t,...l])}return Reflect.apply(m,e,[a,i,...l])};case"addContextToolbar":case"addContextForm":return(...s)=>{const[a,i,...l]=s,d=r(a,"contexttoolbar");if(c(`${String(t)}: ${a}`,{spec:i,context:o,shouldProtect:d}),d){const t={...i,predicate:Oe(n,i.predicate)};return Reflect.apply(m,e,[a,t,...l])}return Reflect.apply(m,e,[a,i,...l])};case"addIcon":case"getAll":case"addContext":return m}}})},Te=new Set(["addCommand","addCommands","addQueryStateHandler","addQueryValueHandler"]),$e=e=>(t,n)=>{e&&console.log(`[EditorProxy] ${t}`,n||"")},Le=(e,t)=>{const{statusProvider:n,uiContext:o,protection:r,debug:s=!1}=t,{events:a,commands:i,ui:c}=r;$e(s)("Creating enhanced editor with options:",{hasStatusProvider:!!n,uiContext:o,debug:s,protection:r});const{editorUiProxy:l,editorCommandsProxy:d,editorEventListenerProxy:m}=((e,t,n,o,r,s,a)=>{const i=s.protect?{...e.ui,registry:Pe(e,e.ui.registry,t,n,Ce(s),a)}:e.ui,c=o.protect?((e,t,n,o,r)=>{const s={protectedCommands:[],cleanupScheduled:!1},a=(e,t)=>{r&&console.log(`[CommandsProxy] ${e}`,t||"")},i=(e,t)=>{const r=o(e),a=n.getStatus();return r&&s.protectedCommands.push(e),r&&"invalid"===a?b:t},c=t=>{"invalid"===t&&s.protectedCommands.length>0&&(a("Removing commands",s.protectedCommands),T(s.protectedCommands,(t=>{e.editorCommands.removeCommand(t)})),s.protectedCommands=[])},l=()=>{s.cleanupScheduled||(s.cleanupScheduled=!0,window.setTimeout((()=>{c(n.getStatus()),s.cleanupScheduled=!1}),0))},d=n.onStatusChange(c);return e.on("remove",d),new Proxy(t,{get:(e,n,r)=>{if(a(`Accessing property: ${String(n)}`),"addCommand"===n){const s=Reflect.get(e,n,r);return(e,n,...r)=>{a(`Adding command: ${e}`,{shouldProtect:o(e)});const c=i(e,n);return l(),Reflect.apply(s,t,[e,c,...r])}}if("addCommands"===n){const o=Reflect.get(e,n,r);return(e,n="exec")=>{a(`Adding commands (${n})`,{commandCount:Object.keys(e).length,willApplyEnforcement:"exec"===n});const r="exec"!==n?e:B(e,((e,t)=>i(t,e)));return l(),Reflect.apply(o,t,[r,n])}}return Reflect.get(e,n,r)}})})(e,e.editorCommands,t,xe(o),a):e.editorCommands;return{editorUiProxy:i,editorCommandsProxy:c,editorEventListenerProxy:r.protect?Se(e,t,xe(r),a):e.on.bind(e)}})(e,n,o||"",i,a,c,s),u=((e,t,n,o)=>(r,s,a)=>{const i=String(s);if("on"===s)return $e(o)("on intercepted"),n;if(Te.has(i))return $e(o)(`${i} intercepted`),t[i].bind(t);if("editorCommands"===s)return $e(o)("editorCommands accessed"),t;if("ui"===s)return $e(o)("ui accessed"),e;const c=Reflect.get(r,s,a);return f(c)?c.bind(r):c})(l,d,m,s);return new Proxy(e,{get:u,set:(e,t,n,o)=>Reflect.set(e,t,n,o),has:(e,t)=>Reflect.has(e,t),ownKeys:e=>Reflect.ownKeys(e),getOwnPropertyDescriptor:(e,t)=>Reflect.getOwnPropertyDescriptor(e,t),defineProperty:(e,t,n)=>Reflect.defineProperty(e,t,n),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)})},Me=e=>parseInt(e,10),Ne=(e,t)=>{const n=e-t;return 0===n?0:n>0?1:-1},Ie=(e,t,n)=>({major:e,minor:t,patch:n}),je=e=>{const t=/([0-9]+)\.([0-9]+)\.([0-9]+)(?:(\-.+)?)/.exec(e);return t?Ie(Me(t[1]),Me(t[2]),Me(t[3])):Ie(0,0,0)},Ue=(e,t)=>!!e&&-1===((e,t)=>{const n=Ne(e.major,t.major);if(0!==n)return n;const o=Ne(e.minor,t.minor);if(0!==o)return o;const r=Ne(e.patch,t.patch);return 0!==r?r:0})((e=>je((e=>[e.majorVersion,e.minorVersion].join(".").split(".").slice(0,3).join("."))(e)))(e),je(t)),Be=je("8.3.0"),He=`${Be.major}.${Be.minor}.0`,Fe=`${Be.major+1}.0.0`,qe=(e,t)=>{const{setup:n,protection:o}=t;return(r,s)=>{if(!((e,t)=>Ue(e,He)?(console.error(`The "${t}" plugin requires at least version ${He} of TinyMCE.`),!1):!!Ue(e,Fe)||(console.error(`The "${t}" plugin requires at least version ${He} of TinyMCE but less than ${Fe}.`),!1))(tinymce,e)||((e,t)=>!!(e=>{var t;const n=null===(t=e.options.get("license_key"))||void 0===t?void 0:t.toLowerCase(),o=e.options.get("online_license_key");return _(o)&&"gpl"===n})(e)&&(((e,t)=>{const{console:n,editor:o}=t;h(o)&&(e._skinLoaded?ye(e,o):e.on("SkinLoaded",(()=>{ye(e,o)}))),h(n)&&be(n)})(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))(r,e))return{};const a=(e=>{const{protect:t=!0,events:n,commands:o,ui:r,api:s}=null!=e?e:{};return{protect:t,events:we(n,false),commands:we(o,true),ui:we(r,true),api:we(s,true)}})(o),i=((e="pre-validation")=>{const t=V(e),n=new Set;let o=!1;const{enableLogging:r=!1}={},s=(e,...t)=>{r&&console.log(`[StatusProvider] ${e}`,...t)};return{setStatus:e=>{const o=t.get();if(o===e)return s("Status unchanged:",e),!1;t.set(e),s("Status changed:",o,"->",e);const r={currentStatus:e,previousStatus:o},a=Array.from(n);return T(a,(e=>{e(r.currentStatus,r.previousStatus)})),!0},onStatusChange:e=>(n.add(e),s("Callback registered, total listeners:",n.size),()=>{n.delete(e)&&s("Callback unregistered, remaining listeners:",n.size)}),getStatus:t.get,hasListeners:()=>n.size>0,destroy:()=>{o||(s("Destroying StatusProvider, clearing",n.size,"listeners"),n.clear(),o=!0)}}})(),c=((e,t,n)=>{const o=`commercial-license-${t}`;return e.ui.registry.addContext(o,(()=>"invalid"!==n.getStatus()&&!e.mode.isReadOnly())),e.licenseKeyManager.validate({plugin:t}).then((e=>{n.setStatus(e?"valid":"invalid")}),(e=>{console.error(e),console.error(`An unknown error occurred when trying to validate "${t}" plugin.`),n.setStatus("invalid")})),{ui:{context:o}}})(r,e,i),l=a.protect?Le(r,{statusProvider:i,uiContext:c.ui.context,debug:t.debug||!1,protection:a}):r,d=((e,t)=>({pluginCode:e,enforcer:{isInvalid:()=>"invalid"===t.getStatus(),onInvalid:e=>t.onStatusChange(((t,n)=>{"invalid"===t&&e(t,n)}))}}))(e,i);return((e,t,n,o)=>{if(t.protect&&t.api.protect&&h(e)){const s=xe(t.api);return(r=e=>"invalid"===n.getStatus()&&s(e),(e,t)=>B(e,((e,n)=>f(e)?(...o)=>{if(r(n.toLowerCase())){const e=`Method "${h(t)?`${t}.`:""}${n}" is not available due to license key restrictions.`,o=new Error(e);throw console.error(e),o}return e(...o)}:e)))(e,o)}var r;return e})(n(l,s,d),a,i,e)}};let Ve=[],ze=(e,t)=>{let n=[],o={get:()=>(o.lc||o.listen((()=>{}))(),o.value),l:t||0,lc:0,listen:(e,t)=>(o.lc=n.push(e,t||o.l)/2,()=>{let t=n.indexOf(e);~t&&(n.splice(t,2),--o.lc||o.off())}),notify(e,t){let r=!Ve.length;for(let r=0;r<n.length;r+=2)Ve.push(n[r],n[r+1],o.value,e,t);if(r){for(let e=0;e<Ve.length;e+=5){let t;for(let n=e+1;!t&&(n+=5)<Ve.length;)Ve[n]<Ve[e+1]&&(t=Ve.push(Ve[e],Ve[e+1],Ve[e+2],Ve[e+3],Ve[e+4]));t||Ve[e](Ve[e+2],Ve[e+3],Ve[e+4])}Ve.length=0}},off(){},set(e){let t=o.value;t!==e&&(o.value=e,o.notify(t))},subscribe(e,t){let n=o.listen(e,t);return e(o.value),n},value:e};return o};const Ye=e=>{if(null==e)throw new Error("Node cannot be null or undefined");return{dom:e}},We=(e,t)=>{const n=(t||document).createElement(e);return Ye(n)},Ge=Ye,Qe=(e,t)=>{const n=e.dom;if(1!==n.nodeType)return!1;{const e=n;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")}},Ke=e=>1!==e.nodeType&&9!==e.nodeType&&11!==e.nodeType||0===e.childElementCount,Je=()=>Xe(0,0),Xe=(e,t)=>({major:e,minor:t}),Ze={nu:Xe,detect:(e,t)=>{const n=String(t).toLowerCase();return 0===e.length?Je():((e,t)=>{const n=((e,t)=>{for(let n=0;n<e.length;n++){const o=e[n];if(o.test(t))return o}})(e,t);if(!n)return{major:0,minor:0};const o=e=>Number(t.replace(n,"$"+e));return Xe(o(1),o(2))})(e,n)},unknown:Je},et=(e,t)=>{const n=String(t).toLowerCase();return L(e,(e=>e.search(n)))},tt=/.*?version\/\ ?([0-9]+)\.([0-9]+).*/,nt=e=>t=>pe(t,e),ot=[{name:"Edge",versionRegexes:[/.*?edge\/ ?([0-9]+)\.([0-9]+)$/],search:e=>pe(e,"edge/")&&pe(e,"chrome")&&pe(e,"safari")&&pe(e,"applewebkit")},{name:"Chromium",brand:"Chromium",versionRegexes:[/.*?chrome\/([0-9]+)\.([0-9]+).*/,tt],search:e=>pe(e,"chrome")&&!pe(e,"chromeframe")},{name:"IE",versionRegexes:[/.*?msie\ ?([0-9]+)\.([0-9]+).*/,/.*?rv:([0-9]+)\.([0-9]+).*/],search:e=>pe(e,"msie")||pe(e,"trident")},{name:"Opera",versionRegexes:[tt,/.*?opera\/([0-9]+)\.([0-9]+).*/],search:nt("opera")},{name:"Firefox",versionRegexes:[/.*?firefox\/\ ?([0-9]+)\.([0-9]+).*/],search:nt("firefox")},{name:"Safari",versionRegexes:[tt,/.*?cpu os ([0-9]+)_([0-9]+).*/],search:e=>(pe(e,"safari")||pe(e,"mobile/"))&&pe(e,"applewebkit")}],rt=[{name:"Windows",search:nt("win"),versionRegexes:[/.*?windows\ nt\ ?([0-9]+)\.([0-9]+).*/]},{name:"iOS",search:e=>pe(e,"iphone")||pe(e,"ipad"),versionRegexes:[/.*?version\/\ ?([0-9]+)\.([0-9]+).*/,/.*cpu os ([0-9]+)_([0-9]+).*/,/.*cpu iphone os ([0-9]+)_([0-9]+).*/]},{name:"Android",search:nt("android"),versionRegexes:[/.*?android\ ?([0-9]+)\.([0-9]+).*/]},{name:"macOS",search:nt("mac os x"),versionRegexes:[/.*?mac\ os\ x\ ?([0-9]+)_([0-9]+).*/]},{name:"Linux",search:nt("linux"),versionRegexes:[]},{name:"Solaris",search:nt("sunos"),versionRegexes:[]},{name:"FreeBSD",search:nt("freebsd"),versionRegexes:[]},{name:"ChromeOS",search:nt("cros"),versionRegexes:[/.*?chrome\/([0-9]+)\.([0-9]+).*/]}],st={browsers:w(ot),oses:w(rt)},at=e=>{const t=e.current,n=e.version,o=e=>()=>t===e;return{current:t,version:n,isEdge:o("Edge"),isChromium:o("Chromium"),isIE:o("IE"),isOpera:o("Opera"),isFirefox:o("Firefox"),isSafari:o("Safari")}},it=()=>at({current:void 0,version:Ze.unknown()}),ct=at,lt=e=>{const t=e.current,n=e.version,o=e=>()=>t===e;return{current:t,version:n,isWindows:o("Windows"),isiOS:o("iOS"),isAndroid:o("Android"),isMacOS:o("macOS"),isLinux:o("Linux"),isSolaris:o("Solaris"),isFreeBSD:o("FreeBSD"),isChromeOS:o("ChromeOS")}},dt=()=>lt({current:void 0,version:Ze.unknown()}),mt=lt,ut=(e,t,n)=>{const o=st.browsers(),r=st.oses(),s=t.bind((e=>((e,t)=>((e,t)=>{for(let n=0;n<e.length;n++){const o=t(e[n]);if(o.isSome())return o}return A.none()})(t.brands,(t=>{const n=t.brand.toLowerCase();return L(e,(e=>n===e.brand?.toLowerCase())).map((e=>({current:e.name,version:Ze.nu(parseInt(t.version,10),0)})))})))(o,e))).orThunk((()=>((e,t)=>et(e,t).map((e=>{const n=Ze.detect(e.versionRegexes,t);return{current:e.name,version:n}})))(o,e))).fold(it,ct),a=((e,t)=>et(e,t).map((e=>{const n=Ze.detect(e.versionRegexes,t);return{current:e.name,version:n}})))(r,e).fold(dt,mt),i=((e,t,n,o)=>{const r=e.isiOS()&&!0===/ipad/i.test(n),s=e.isiOS()&&!r,a=e.isiOS()||e.isAndroid(),i=a||o("(pointer:coarse)"),c=r||!s&&a&&o("(min-device-width:768px)"),l=s||a&&!c,d=t.isSafari()&&e.isiOS()&&!1===/safari/i.test(n),m=!l&&!c&&!d;return{isiPad:w(r),isiPhone:w(s),isTablet:w(c),isPhone:w(l),isTouch:w(i),isAndroid:e.isAndroid,isiOS:e.isiOS,isWebView:w(d),isDesktop:w(m)}})(a,s,e,n);return{browser:s,os:a,deviceType:i}},pt=e=>window.matchMedia(e).matches;let vt=(e=>{let t,n=!1;return(...o)=>(n||(n=!0,t=e.apply(null,o)),t)})((()=>ut(window.navigator.userAgent,A.from(window.navigator.userAgentData),pt)));const gt=Object.getPrototypeOf,_t=e=>{const t=ue("ownerDocument.defaultView",e);return m(e)&&((e=>((e,t)=>{const n=((e,t)=>ue(e,t))(e,t);if(null==n)throw new Error(e+" not available on this browser");return n})("HTMLElement",e))(t).prototype.isPrototypeOf(e)||/^HTML\w*Element$/.test(gt(e).constructor.name))},ht=e=>1===(e=>e.dom.nodeType)(e);const ft=e=>t=>ht(t)&&t.dom.nodeName.toLowerCase()===e,yt=e=>A.from(e.dom.parentNode).map(Ge),bt=e=>P(e.dom.childNodes,Ge),wt=e=>{return((e=(()=>Ge(document))())=>A.from(e.dom.activeElement).map(Ge))((t=e,Ge(t.dom.getRootNode()))).filter((t=>e.dom.contains(t.dom)));var t},xt=(e,t)=>{e.dom.appendChild(t.dom)},Ct=(e,t,n)=>{if(!(d(n)||v(n)||y(n)))throw console.error("Invalid call to Attribute.set. Key ",t,":: Value ",n,":: Element ",e),new Error("Attribute value was not simple");e.setAttribute(t,n+"")},St=(e,t,n)=>{Ct(e.dom,t,n)},kt=(e,t)=>{const n=e.dom.getAttribute(t);return null===n?void 0:n},At=(e,t)=>A.from(kt(e,t)),Rt=(e,t)=>{e.dom.removeAttribute(t)},Dt=e=>{const t=e.dom;null!==t.parentNode&&t.parentNode.removeChild(t)},Ot=e=>{const t=bt(e);var n,o;t.length>0&&(n=e,T(o=t,((e,t)=>{((e,t)=>{const n=(e=>A.from(e.dom.nextSibling).map(Ge))(e);n.fold((()=>{yt(e).each((e=>{xt(e,t)}))}),(e=>{((e,t)=>{yt(e).each((n=>{n.dom.insertBefore(t.dom,e.dom)}))})(e,t)}))})(0===t?n:o[t-1],e)}))),Dt(e)},Et=(e,t)=>{const n=(e=>Ge(e.dom.ownerDocument))(e),o=n.dom,r=Ge(o.createDocumentFragment());((e,t)=>{T(t,(t=>{xt(e,t)}))})(r,((e,t)=>{const n=(t||document).createElement("div");return n.innerHTML=e,bt(Ge(n))})(t,o)),(e=>{e.dom.textContent="",T(bt(e),(e=>{Dt(e)}))})(e),xt(e,r)},Pt=()=>Tt(Ge(document)),Tt=e=>{const t=e.dom.body;if(null==t)throw new Error("Body is not available yet");return Ge(t)},$t=(e,t)=>{const n=kt(e,t);return void 0===n||""===n?[]:n.split(" ")},Lt=e=>void 0!==e.dom.classList,Mt=(e,t)=>{Lt(e)?e.dom.classList.remove(t):((e,t)=>{((e,t,n)=>{const o=$($t(e,t),(e=>e!==n));o.length>0?St(e,t,o.join(" ")):Rt(e,t)})(e,"class",t)})(e,t),(e=>{const t=Lt(e)?e.dom.classList:(e=>$t(e,"class"))(e);0===t.length&&Rt(e,"class")})(e)},Nt=(e,t)=>((e,t)=>{const n=void 0===t?document:t.dom;return Ke(n)?[]:P(n.querySelectorAll(e),Ge)})(t,e),It=vt().os.isMacOS()?"\u2318":"Ctrl",jt=B({tc_conversations_title:"Comments",tc_announce_sidebar_available:`Comment. Sidebar available. Press ${It} + Alt + M to switch to sidebar`,tc_items_addcomment:"Add comment",tc_items_showcomments:"Show comments",tc_items_deleteall:"Delete all conversations",tc_edit_buttons_save:"Save",tc_edit_buttons_saving:"Saving",tc_edit_buttons_cancel:"Cancel",tc_reply_buttons_comment:"Comment",tc_reply_buttons_clear:"Clear",tc_reply_placeholders:"Add comment...",tc_reply_with_mentions_placeholders:"Comment or mention with @",tc_kebab_tooltip:"Comment Actions",tc_kebab_tooltip_conversation:"Conversation Actions",tc_kebab_delete_conversation:"Delete conversation",tc_kebab_resolve_conversation:"Resolve conversation",tc_kebab_delete:"Delete",tc_kebab_edit:"Edit",tc_edit_problem_comment:"An error occurred editing this comment. See the console for details.",tc_edit_unauthorised_comment:"You are not allowed to edit this comment",tc_delete_buttons_cancel:"Cancel",tc_delete_buttons_proceed:"Delete",tc_resolve_buttons_proceed:"Resolve",tc_resolve_buttons_cancel:"Cancel",tc_create_problem:"An error occurred while creating a comment. See the console for details",tc_reply_problem:"An error occurred while replying to a comment. See the console for details",tc_delete_prompts_conversation:"Delete this conversation?",tc_delete_prompts_conversation_detail_sing:"1 comment will be deleted. You can't undo this action.",tc_delete_prompts_conversation_detail_pl:"{0} comments will be deleted. You can't undo this action.",tc_delete_prompts_all:"Delete all conversations in the content? This cannot be undone.",tc_delete_prompts_comment:"Are you sure you want to delete this comment?",tc_resolve_prompts_conversation:"Resolve this conversation?",tc_resolve_prompts_conversation_detail_sing:"1 comment will be resolved. You can't undo this action.",tc_resolve_prompts_conversation_detail_pl:"{0} comments will be resolved. You can't undo this action.",tc_delete_problem_all:"An error occurred deleting all the conversations. See the console for details.",tc_delete_problem_conversation:"An error occurred deleting the conversation. See the console for details.",tc_delete_problem_comment:"An error occurred deleting the comment. See the console for details.",tc_delete_unauthorised_all:"You are not allowed to delete all the conversations",tc_delete_unauthorised_conversation:"You are not allowed to delete this conversation",tc_delete_unauthorised_comment:"You are not allowed to delete this comment",tc_resolve_unauthorised_conversation:"You are not allowed to resolve this conversation",tc_resolve_problem_conversation:"An error occurred resolving the conversation. See the console for details.",tc_date_less_than_a_minute_ago:"a moment ago",tc_date_1_minute_ago:"1 minute ago",tc_date_x_minutes_ago:"{0} minutes ago",tc_date_1_hour_ago:"1 hour ago",tc_date_x_hours_ago:"{0} hours ago",tc_date_1_day_ago:"1 day ago",tc_date_x_days_ago:"{0} days ago",tc_date_1_week_ago:"1 week ago",tc_date_x_weeks_ago:"{0} weeks ago",tc_date_1_month_ago:"1 month ago",tc_date_x_months_ago:"{0} months ago",tc_date_1_year_ago:"1 year ago",tc_date_x_years_ago:"{0} years ago",tc_date_comment_edited:" (edited)",tc_conversations_one_reply:"1 reply",tc_conversations_multiple_replies:"{0} replies",tc_dialog_delete_conversation:"Delete Conversation",tc_dialog_resolve_conversation:"Resolve Conversation",tc_dialog_delete_comment:"Delete Comment",tc_mentions_no_results:"No users found"},x),Ut=le("aria-comment-description");let Bt=0;const Ht=e=>{const t=(n=Pt(),o=`#${Ut}`,((e,t)=>{const n=void 0===t?document:t.dom;return Ke(n)?A.none():A.from(n.querySelector(e)).map(Ge)})(o,n)).getOrThunk((()=>{const e=We("span");return((e,t)=>{const n=e.dom;U(t,((e,t)=>{Ct(n,t,e)}))})(e,{id:Ut,"aria-live":"polite","aria-atomic":"true",role:"alert"}),(e=>{const t=e.dom;U({position:"absolute",left:"-10000px",top:"-1000px"},((e,n)=>{((e,t,n)=>{if(!d(n))throw console.error("Invalid call to CSS.set. Property ",t,":: Value ",n,":: Element ",e),new Error("CSS value must be a string: "+n);(e=>void 0!==e.style&&f(e.style.getPropertyValue))(e)&&e.style.setProperty(t,n)})(t,n,e)}))})(e),xt(Pt(),e),e}));var n,o;return Bt++,((e,t)=>({onComment:()=>{Et(t,e.translate(jt.tc_announce_sidebar_available))},notOnComment:()=>{Et(t,"")},getMarker:()=>t,release:()=>{Bt--,0===Bt&&Dt(t)}}))(e,t)},Ft=()=>(new Date).toISOString();var qt;!function(e){e[e.LessThanMinute=0]="LessThanMinute",e[e.Minute=1]="Minute",e[e.Hour=2]="Hour",e[e.Day=3]="Day",e[e.Week=4]="Week",e[e.Month=5]="Month",e[e.Year=6]="Year"}(qt||(qt={}));const Vt=(e,t="")=>{const n=e.get(),o=""===t?0:Date.parse(t);return{timestamp:Ft(),events:o>0?$(n,(e=>Date.parse(e.timestamp)>o)):n}},zt=e=>(t={})=>d(t.after)?Vt(e,t.after):Vt(e),Yt=w("tox-comment"),Wt=w("tinycomments"),Gt=w("mce-annotation"),Qt=w("data-mce-annotation"),Kt=w("data-mce-annotation-uid"),Jt=w("data-mce-annotation-active"),Xt=w("data-mce-annotation-classes"),Zt=w("data-mce-annotation-attrs"),en=w("tmp"),tn=w("tox-comments-visible"),nn=e=>I(e.annotator.getAll(Wt())),on=e=>ve(e,en()),rn=(e,t)=>{const n=Ge(t.commonAncestorContainer),o=ht(r=n)&&_t(r.dom)?A.some(n):(e=>A.from(e.dom.parentElement).map(Ge))(n);var r;const s=`[${Qt()}="${Wt()}"]`,a=o.map((e=>Nt(e,s))).getOr([]),i=(e=>{const t=R.call(e,0);return t.reverse(),t})(((t,n)=>((e,t,n)=>$(((e,t)=>{const n=f(t)?t:S;let o=e.dom;const r=[];for(;null!==o.parentNode&&void 0!==o.parentNode;){const e=o.parentNode,t=Ge(e);if(r.push(t),!0===n(t))break;o=e}return r})(e,n),t))(t,(e=>Qe(e,n)),(t=>t.dom===e.getBody())))(n,s));return Qe(n,s)&&i.push(n),$(i.concat(a),(e=>{return!(kt(n=e,Qt())===Wt()&&At(n,Kt()).exists(on))&&((e,t)=>e.intersectsNode(t.dom))(t,e);var n}))},sn=ft("hr"),an=e=>{const t=Ge(e.selection.getNode()),n=Ge(e.selection.getStart());return(e=>{let t=e.selection.getRng().commonAncestorContainer;return 3===t.nodeType&&(t=t.parentNode),!!h(t)&&e.dom.isEmpty(t)})(e)||sn(t)||sn(n)},cn=(e,t)=>an(e)||!(e=>{if(e.selection){const t=e.selection.getRng(),n=rn(e,t);return N(n).forall((e=>{return(o=n,M(o,o.length-1)).forall((o=>{const r=kt(e,Kt());if(E(n,(e=>kt(e,Kt())!==r)))return!1;const s=new window.Range;return s.setStartBefore(e.dom),s.setEndAfter(o.dom),s.compareBoundaryPoints(window.Range.START_TO_START,t)<=0&&s.compareBoundaryPoints(window.Range.END_TO_END,t)>=0}));var o}))}return!1})(e)||!t.get().canWrite,ln=ft("span"),dn=e=>{ln(e)?Ot(e):(e=>{Mt(e,Gt()),Rt(e,`${Kt()}`),Rt(e,`${Qt()}`),Rt(e,`${Jt()}`);const t=At(e,`${Zt()}`).map((e=>e.split(","))).getOr([]),n=At(e,`${Xt()}`).map((e=>e.split(","))).getOr([]);T(t,(t=>Rt(e,t))),((e,t)=>{T(t,(t=>{Mt(e,t)}))})(e,n),Rt(e,`${Xt()}`),Rt(e,`${Zt()}`)})(e)},mn=(e,t,n,o)=>(Et(e,t),T(Nt(e,n),o),e.dom.innerHTML),un=(e,t,n)=>{const o=We("div");T(e,(e=>{if(e.content=mn(o,e.content,t,n),h(e.fragments))for(let r=0;r<e.fragments.length;r++)e.fragments[r]=mn(o,e.fragments[r],t,n)}))},pn=(e,t,n)=>{e.notificationManager.open({text:t,type:"error"}),n&&console.error(d(n)?n:n.message,n)},vn="tc-try-delete-all-conversations",gn=(e,t)=>{e.addCommand("tc-delete-conversation-at-cursor",((n,o)=>{if(an(e))return;const r=(null==o?void 0:o.conversationUid)?A.from(o.conversationUid):(e=>{const t=F(e.annotator.getAll(Wt()),(t=>O(t,e.selection.getNode())));return N(I(t))})(e);r.each((n=>{var o;e.undoManager.transact((()=>e.annotator.remove(Wt()))),o=e.undoManager.data,un(o,(e=>`[${Kt()}="${e}"]`)(n),dn),t.set(t.get().filter((e=>e!==n))),e.focus()}))}))},_n=(e,t,n,o)=>{gn(e,o),((e,t,n,o)=>{e.addCommand(vn,(()=>{an(e)||e.windowManager.confirm(jt.tc_delete_prompts_all,(r=>{if(r)return t.deleteAllConversations({}).get((t=>{t.fold((t=>pn(e,jt.tc_delete_problem_all,t)),(t=>{var r;t.canDelete?(n({type:"delete-all-conversations",timestamp:Ft()}),e.annotator.removeAll(Wt()),r=e.undoManager.data,un(r,`[${Qt()}="${Wt()}"]`,dn),e.undoManager.dispatchChange(),o.set([]),e.focus()):pn(e,jt.tc_delete_unauthorised_all)}))}))}))}))})(e,t,n,o)},hn=e=>{e.execCommand("ToggleSidebar",!1,"showcomments")},fn=e=>t=>oe((n=>e(t,(e=>{n(Z.value(e))}),(e=>{n(Z.error(e))})))),yn=e=>t=>t.options.get(e),bn=e=>t=>A.from(yn(e)(t)).filter(f),wn=e=>t=>bn(e)(t).getOrDie(e+" has not been implemented."),xn=(e,t)=>n=>{const o=((e,t)=>n=>{var o;return null!==(o=n.options.get(e))&&void 0!==o?o:t()})(e,(()=>t($n(n))))(n);return fn(o)},Cn=wn("tinycomments_create"),Sn=wn("tinycomments_reply"),kn=wn("tinycomments_delete"),An=bn("tinycomments_resolve"),Rn=wn("tinycomments_delete_all"),Dn=wn("tinycomments_delete_comment"),On=wn("tinycomments_edit_comment"),En=wn("tinycomments_lookup"),Pn=bn("tinycomments_fetch"),Tn=bn("tinycomments_fetch_author_info"),$n=e=>e.options.isSet("tinycomments_author")?e.options.get("tinycomments_author"):e.userLookup.userId,Ln=xn("tinycomments_can_delete",(e=>(t,n,o)=>{n({canDelete:t.comments.length>0&&t.comments[0].author===e&&!0})})),Mn=bn("tinycomments_can_resolve"),Nn=xn("tinycomments_can_delete_comment",(e=>(t,n,o)=>{n({canDelete:t.comment.author===e&&!0})})),In=xn("tinycomments_can_edit_comment",(e=>(t,n,o)=>{n({canEdit:t.comment.author===e&&!0})})),jn=yn("tinycomments_access"),Un=yn("tinycomments_mode"),Bn=yn("tinycomments_js_url"),Hn=yn("disabled"),Fn=e=>{const t=Cn(e),n=Sn(e),o=En(e),r=Pn(e),s=(e=>Tn(e).map((e=>(t,n,o)=>e(n,o))).getOr(((t,n,o)=>{const r=e.userLookup.userId;e.userLookup.fetchUsers([r])[r].then((e=>{n({author:e.id,authorName:e.name,authorAvatar:e.avatar})})).catch((e=>{var t;return o(null!==(t=e.message)&&void 0!==t?t:"Failed to fetch user info")}))})))(e),a=kn(e),i=An(e),c=Rn(e),l=Dn(e),d=On(e);return{create:fn(t),reply:fn(n),lookup:fn((m=o,(e,t,n)=>{m(e,(e=>{const n=P(e.conversation.comments,(e=>({authorName:e.author,...e})));t(de(e,{conversation:{comments:n}}))}),n)})),fetchConversations:r.map((e=>fn(e))),fetchAuthorInfo:fn(s),deleteConversation:fn(a),resolveConversation:i.map((e=>fn(e))),deleteAllConversations:fn(c),editComment:fn(d),deleteComment:fn(l),lifecycleHooks:{onPreInit:b,onGetContent:A.none}};var m},qn={base64:{versions:["2.0","2.1"],encryptor:{encryptText:e=>{const t=new Blob([e],{type:"application/json"}),n=new FileReader;return oe((e=>{n.addEventListener("loadend",(()=>e(Z.value({encrypted:[n.result]})))),n.addEventListener("error",(()=>e(Z.error(n.error||new Error("error decoding text"))))),n.readAsDataURL(t)}))},decryptText:e=>{return(t=e[0],(e=>{const t=e.split(","),n=/data:([^;]+)/.exec(t[0]);if(!n)return A.none();const o=n[1],r=t[1],s=1024,a=atob(r),i=a.length,c=Math.ceil(i/s),l=new Array(c);for(let e=0;e<c;++e){const t=e*s,n=Math.min(t+s,i),o=new Array(n-t);for(let e=t,r=0;e<n;++r,++e)o[r]=a[e].charCodeAt(0);l[e]=new Uint8Array(o)}return A.some(new Blob(l,{type:o}))})(t)).fold((()=>ae("Could not decode URI")),(e=>{const t=new FileReader;return oe((n=>{t.addEventListener("loadend",(()=>n(Z.value({decrypted:t.result})))),t.addEventListener("error",(()=>{var e;return n(Z.error((null===(e=t.error)||void 0===e?void 0:e.message)||"error decoding text"))})),t.readAsText(e)}))}));var t}}}};qn.current=qn.base64;const Vn=(e,t,n)=>t===e?n:"2.0"===e?Vn("2.1",t,(e=>({...e,authorName:e.author}))(n)):n,zn="tinycomments",Yn="2.1",Wn=e=>ve(he(e),zn),Gn=e=>{const t=_e(e).split("|");return t.length>2?Z.value({version:t[1],rest:t.slice(2)}):Z.error("Embedded comments not in expected format.")},Qn=(e,t,n)=>((e,t)=>{const n=(e=>{try{const t=JSON.parse(e);return Z.value(t)}catch(e){return Z.error("Could not JSON parse conversations.")}})(t);return e!==Yn?n.map((t=>B(t,(t=>({...t,comments:P(t.comments,(t=>Vn(e,Yn,t)))}))))):n})(e,n).map((e=>({conversations:e,encrypted:{encrypted:t}}))),Kn=e=>Wn(e)?Gn(e).fold((e=>ae(e)),(({version:e,rest:t})=>((e,t)=>(e=>((e,t)=>{const n=I(e);for(let o=0,r=n.length;o<r;o++){const r=e[n[o]];if(t(r))return A.some(r)}return A.none()})(qn,(t=>O(t.versions,e))).map((e=>e.encryptor)))(e).fold((()=>ae(`No Encryptor for version: ${e}`)),(e=>e.decryptText(t))))(e,t).bindResult((({decrypted:n})=>Qn(e,t,n))))):se({conversations:{},encrypted:{encrypted:[]}}),Jn=e=>{const t=(async e=>e.options.isSet("tinycomments_author")?(()=>{const t=e.options.get("tinycomments_author"),n=e.options.get("tinycomments_author_name");return{author:t,authorName:null!=n?n:t,authorAvatar:e.options.get("tinycomments_author_avatar")}})():(async()=>{const t=e.userLookup.userId,n=e.userLookup.fetchUsers([t]),o=await n[t];return{author:o.id,authorName:o.name,authorAvatar:o.avatar}})())(e),n=(()=>{let e={},t=A.none();const n=t=>Object.prototype.hasOwnProperty.call(e,t)?A.some(e[t]):A.none();return{get:()=>de(e,{}),clear:()=>{e={},t=A.none()},addData:(t,n)=>{e[t]=n},setData:(n,o)=>{e=n,t=A.some(o)},setEncryptedData:e=>{t=A.some(e)},getEncryptedData:()=>t,lookupData:n,removeData:t=>{delete e[t]},updateData:(t,o)=>n(t).map((n=>{const r=o(n);return e[t]=r,r}))}})(),o=Ln(e),r=Nn(e),s=In(e),a=Mn(e).map((e=>fn(e))),i=(g=t,te((e=>{g.then((t=>{e(Z.value(t))}),(t=>{e(Z.error(t))}))}))).mapResult((e=>{const{author:t,authorName:n,authorAvatar:o}=e;return{author:t,authorName:n,...void 0===o?{}:{authorAvatar:o}}})),c=w(i),l=qn.current.encryptor,d=()=>l.encryptText(JSON.stringify(n.get())).mapResult((e=>n.setEncryptedData(e))),m=A.some((e=>{return re({conversations:(t=e,o=(e,t)=>({...e,[t]:n.get()[t]}),r={},T(t,((e,t)=>{r=o(r,e)})),r)});var t,o,r})),u=a.map((e=>t=>n.lookupData(t.conversationUid).fold((()=>ae("Could not find conversation to resolve")),(o=>e({conversationUid:o.uid,comments:o.comments}).bindFuture((e=>e.canResolve?(n.removeData(t.conversationUid),d().mapResult((()=>({canResolve:!0})))):se({canResolve:!1}))))))),p=(e,t,o,r)=>(e=>n.lookupData(e.conversationUid).fold((()=>Z.error(`Could not find conversation with uid ${e.conversationUid}`)),(t=>L(t.comments,(t=>t.uid===e.commentUid)).fold((()=>Z.error(`Could not find comment with uid ${e.commentUid} in conversation ${e.conversationUid}`)),(e=>Z.value({conversationUid:t.uid,comment:e}))))))(e).fold((e=>ae(e)),(s=>o(s).bindFuture((o=>!0===o[t]?n.updateData(e.conversationUid,r(s)).fold((()=>ae("Could not operate on comment ("+t+")")),(e=>d().mapResult((()=>({[t]:!0}))))):se({[t]:!1}))))),v={onPreInit:t=>{e.parser.addNodeFilter("#comment",((t,o,r)=>{r.isRootContent&&(n.clear(),T(t,(t=>{const o=t.value;o&&Wn(o)&&(t.remove(),Gn(o).each((e=>n.setEncryptedData({encrypted:e.rest}))),Kn(o).get((t=>t.fold((e=>console.error("Error extracting embedded conversations: "+e)),(t=>{n.setData(t.conversations,t.encrypted),(e=>{e.dispatch("mce-tinycomments-update",{})})(e)})))))})))}))},onGetContent:(e,t)=>n.getEncryptedData().map((e=>t+(e=>{const t=Ge(document.createComment((e=>[zn,Yn,...e.encrypted].join("|"))(e)));return(e=>{const t=We("div"),n=Ge(e.dom.cloneNode(!0));return xt(t,n),(e=>e.dom.innerHTML)(t)})(t)})(e)))};var g;return{create:e=>{const t=le("mce-conversation");return i.bindFuture((o=>(n.addData(t,{uid:t,comments:[{uid:t,...o,content:e.content,createdAt:e.createdAt,modifiedAt:e.createdAt}]}),d().mapResult((()=>({conversationUid:t}))))))},reply:e=>{const t=le("mce-reply");return i.bindFuture((o=>{const r={uid:t,...o,content:e.content,createdAt:e.createdAt,modifiedAt:e.createdAt};return n.updateData(e.conversationUid,(e=>({...e,comments:e.comments.concat([r])}))).fold((()=>ae("Could not reply to uid: "+e.conversationUid)),(()=>d().mapResult((()=>({commentUid:t,author:r.author,authorName:r.authorName})))))}))},lookup:e=>n.lookupData(e.conversationUid).fold((()=>ae("Could not find uid: "+e.conversationUid)),(e=>se({conversation:e}))),fetchConversations:m,fetchAuthorInfo:c,deleteConversation:e=>n.lookupData(e.conversationUid).fold((()=>ae("Could not find conversation to delete")),(t=>o({conversationUid:t.uid,comments:t.comments}).bindFuture((t=>t.canDelete?(n.removeData(e.conversationUid),d().mapResult((()=>({canDelete:!0})))):se({canDelete:!1}))))),resolveConversation:u,deleteAllConversations:()=>{const e=I(n.get()),t=P(e,(e=>n.lookupData(e).fold((()=>ae("Could not find conversation")),(e=>o({conversationUid:e.uid,comments:e.comments})))));return oe((e=>{var o;(o=t,((e,t)=>t((t=>{const n=[];let o=0;0===e.length?t([]):T(e,((r,s)=>{r.get((r=>s=>{n[r]=s,o++,o>=e.length&&t(n)})(s))}))})))(o,Q)).get((t=>{const o=(e=>{for(let t=0,n=e.length;t<n;++t)if(!0!==e[t].exists((e=>e.canDelete)))return!1;return!0})(t);o&&n.clear(),e(Z.value({canDelete:o}))}))}))},deleteComment:e=>p(e,"canDelete",r,(e=>{return t=e.comment.uid,e=>({uid:e.uid,comments:$(e.comments,(e=>e.uid!==t))});var t})),editComment:e=>p(e,"canEdit",(t=>s({...t,edit:{modifiedAt:e.modifiedAt,content:e.content}})),(()=>{return t=e.commentUid,n=e.content,o=e.modifiedAt,e=>({uid:e.uid,comments:P(e.comments,(e=>e.uid===t?{...e,content:n,modifiedAt:o}:e))});var t,n,o})),lifecycleHooks:v}},Xn=(e,t)=>{if(Hn(e))return"disabled";const n=jn(e);return"readonly"===t&&"full"===n?"read":n};var Zn,eo;!function(e){e[e.Before=0]="Before",e[e.QueryingDelete=1]="QueryingDelete",e[e.QueryingResolve=2]="QueryingResolve",e[e.PostDelete=3]="PostDelete",e[e.PostResolve=4]="PostResolve"}(Zn||(Zn={})),function(e){e[e.Open=0]="Open",e[e.Closed=1]="Closed",e[e.Closing=2]="Closing"}(eo||(eo={}));const to="tox-button--naked",no="tox-button--icon",oo="tox-icon",ro="tox-button",so="tox-menu",ao="tox-collection",io="tox-collection--list",co="tox-collection__group",lo="tox-menu-nav__js",mo="tox-collection__item-container",uo="tox-collection__item",po="tox-collection__item--state-disabled",vo="tox-mentions__username",go="tox-sidebar-content",_o=e=>`.${e}`;[".tox-menu",`[role="menuitem"]:contains(${jt.tc_kebab_edit})`].join(" "),[".tox-menu",`[role="menuitem"]:contains(${jt.tc_kebab_delete})`].join(" "),[".tox-menu",`[role="menuitem"]:contains(${jt.tc_kebab_delete_conversation})`].join(" "),[".tox-menu",`[role="menuitem"]:contains(${jt.tc_kebab_resolve_conversation})`].join(" "),jt.tc_edit_buttons_save,jt.tc_edit_buttons_saving,`.tox-button:contains(${jt.tc_reply_placeholders})`.replace("...","\u2026"),jt.tc_edit_buttons_cancel,jt.tc_reply_buttons_clear,jt.tc_delete_buttons_proceed,jt.tc_resolve_buttons_proceed,[_o(po),_o(vo)+`:contains(${jt.tc_mentions_no_results})`].join(" ");const ho=e=>e.join(" "),fo={skeleton:ho(["tox-skeleton"]),skeletonLine:ho(["tox-skeleton__line"]),skeletonCircle:ho(["tox-skeleton__circle"]),conversationsTitle:ho(["tox-sidebar-content__title"]),conversationsHead:ho(["tox-sidebar-content__header"]),outerContainer:ho([go]),date:ho(["tox-comment__date"]),replySection:ho(["tox-comment__reply"]),replyTextarea:ho(["tox-textarea"]),textarea:ho([]),editTextarea:ho([]),kebab:ho([to,"tox-button--kebab",ro,no]),kebabIcon:ho([oo]),card:ho(["tox-comment"]),cardHead:ho(["tox-comment__header"]),cardHeadMeta:ho(["tox-comment__meta"]),cardBody:ho(["tox-comment__body"]),cardOverlay:ho(["tox-comment__overlay"]),cardOverlayText:ho(["tox-comment__overlaytext"]),cardOverlayButtons:ho(["tox-comment__buttonspacing"]),mentionsItem:ho(["tox-mentions-dropdown--menu-item"]),mentionsUser:ho(["tox-mentions-user"]),button:ho([ro]),secondaryButton:ho([ro,"tox-button--secondary"]),editActions:ho(["tox-comment__edit"]),outerScroll:ho(["tox-comment__scroll"]),commentList:ho(["tox-comment-thread"]),comment:ho(["tox-comment__single"]),avatar:ho(["tox-user__avatar"]),username:ho(["tox-user__name"]),user:ho(["tox-user"]),showMoreLess:ho([]),kebabItem:ho([uo]),kebabItemLabel:ho(["tox-collection__item-label"]),kebabDisabledItem:ho([po]),kebabMenu:ho([so,ao,io]),kebabMenuGroup:ho([co]),roots:ho([go]),mentionsButton:ho([ro,to,no]),mentionsButtonIcon:ho([oo]),mentionsDropdownContainer:ho(["tox-autocompleter"]),mentionsDropdownList:ho([so,ao,io]),mentionsDropdownGroup:ho([co]),mentionsDropdownItem:ho([lo,uo]),mentionsDropdownItemActive:ho(["tox-collection__item--active"]),mentionsDropdownItemDisabled:ho([lo,uo,po]),mentionsDropdownItemRow:ho([mo,"tox-collection__item-container--row"]),mentionsDropdownItemColumn:ho([mo,"tox-collection__item-container--column","tox-collection__item-container--align-left","tox-collection__item-container--valign-middle"]),mentionsDropdownItemAvatar:ho(["tox-mentions__avatar"]),mentionsDropdownItemName:ho([vo]),mentionsDropdownItemDescription:ho(["tox-mentions__description"])},yo=(e,t,n,o,r,s,a,i,c,l,d,m)=>u=>{var p,v;if(t.set(eo.Open),p=Ge(e.getBody()),v=tn(),Lt(p)?p.dom.classList.add(v):((e,t)=>{((e,t,n)=>{const o=$t(e,t).concat([n]);St(e,t,o.join(" "))})(e,"class",t)})(p,v),a.set(nn(e)),n.get()){const t=document.createElement("div");t.className=fo.outerContainer,u.element().append(t),d.then((()=>l.then((n=>{const l=n(e,o,r,s,a,i,c,m,t);e.on("remove",l)})))),n.set(!1)}},bo=(e,t)=>n=>{wt(Ge(n.element())).each((t=>{e.focus()})),t.set(eo.Closed),Mt(Ge(e.getBody()),tn())},wo=(e,t,n)=>{t.get()!==eo.Closed&&t.get()!==eo.Closing||hn(e),n.set(nn(e))},xo=(e,t,n,o,r)=>{r.set(!0),o.set(!1),wo(e,t,n)},Co=(e,t,n,o,r,s,a,i)=>{const c="comment-add";e.ui.registry.addToggleMenuItem("showcomments",{text:jt.tc_items_showcomments,icon:"comment",onAction:()=>hn(e),onSetup:e=>n.subscribe((t=>{e.setActive(t===eo.Open)})),context:"any"});const l=t=>{const n=()=>{t(!cn(e,a))};return n(),e.on("SelectionChange NodeChange SwitchMode DisabledStateChange",n),()=>e.off("SelectionChange NodeChange SwitchMode DisabledStateChange",n)},d=()=>{cn(e,a)||((e=>!!e.selection&&rn(e,e.selection.getRng()).length>0)(e)?xo(e,n,s,o,r):((e=>{const t=le(en());e.selection.expand(),(e=>{const t=e.selection.bookmarkManager.getBookmark();U(e.annotator.getAll(Wt()),((t,n)=>{on(n)&&t.forEach((t=>{e.selection.select(t),e.annotator.remove(Wt())}))})),e.selection.bookmarkManager.moveToBookmark(t)})(e),e.annotator.annotate(Wt(),{uid:t})})(e),((e,t,n,o,r)=>{r.set(!1),o.set(!0),wo(e,t,n)})(e,n,s,o,r)))};e.ui.registry.addButton("addcomment",{tooltip:jt.tc_items_addcomment,icon:c,onAction:d,onSetup:e=>l(e.setEnabled),context:"any"}),e.ui.registry.addMenuItem("addcomment",{text:jt.tc_items_addcomment,shortcut:"meta+Alt+M",icon:c,onAction:d,onSetup:e=>l(e.setEnabled),context:"any"}),e.ui.registry.addMenuItem("deleteallconversations",{text:jt.tc_items_deleteall,onAction:()=>{(e=>{e.execCommand(vn,!1,{})})(e)},onSetup:t=>{const n=e.annotator.getAll(Wt());return t.setEnabled(!(e=>{for(const t in e)if(j.call(e,t))return!1;return!0})(n)&&a.get().canWrite),b},context:"any"}),e.shortcuts.add("meta+alt+m","TinyComments addComment",(()=>{if(i.isInvalid())return;const t=F(e.annotator.getAll(Wt()),(t=>t.includes(e.selection.getNode())));N(I(t)).fold((()=>d()),(()=>xo(e,n,s,o,r)))}))};((e,t)=>{const{i18n:n=!0}=t;n&&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,qe(e,t))})("tinycomments",{setup:(e,t,s)=>{const a=V(!1),i=V([]),c=ze([]),l=ze(eo.Closed),m=ze(Xn(e,e.mode.get())),u=((e,t)=>{let n;Array.isArray(e)||(e=[e]);let o=0,r=()=>{let r=e.map((e=>e.get()));if(void 0===n||r.some(((e,t)=>e!==n[t]))){let e=++o;n=r;let a=t(...r);a&&a.then&&a.t?a.then((t=>{e===o&&s.set(t)})):s.set(a)}},s=ze(void 0,Math.max(...e.map((e=>e.l)))+1),a=r;var i,c,l,d,m;return c=()=>{let t=e.map((e=>e.listen(a,-1/s.l)));return r(),()=>{for(let e of t)e()}},d=e=>{let t=c();t&&i.events[6].push(t)},m=e=>{let t=i.listen;i.listen=(...n)=>(i.lc||i.active||(i.active=!0,e()),t(...n));let n=i.off;return i.events[6]=[],i.off=()=>{n(),setTimeout((()=>{if(i.active&&!i.lc){i.active=!1;for(let e of i.events[6])e();i.events[6]=[]}}),1e3)},()=>{i.listen=t,i.off=n}},(l=i=s).events=l.events||{},l.events[15]||(l.events[15]=m((e=>{l.events[5].reduceRight(((e,t)=>(t(e),e)),{shared:{},...e})}))),l.events[5]=l.events[5]||[],l.events[5].push(d),s})(m,(e=>{return t=e,{canWrite:(()=>{switch(t){case"read":case"disabled":return!1;default:return!0}})()};var t})),v=ze(!1),g=ze(!1),_=((e,t)=>n=>{const o=zt(t);t.set(t.get().concat([n])),((e,t)=>{const n={getEventLog:t};e.dispatch("CommentChange",n)})(e,o)})(e,i);((e,t)=>{const n=e.options.register;n("tinycomments_js_url",{processor:"string",default:t+"/js"}),n("tinycomments_mode",{processor:"string",default:"callback"}),n("tinycomments_access",{processor:e=>{const t=O(["full","comment"],e);return t?{value:e,valid:t}:{valid:!1,message:"Must be full, or comment."}},default:"full"}),n("tinycomments_author",{processor:e=>{const t="Must be a non-empty string";return d(e)?fe(e)?{valid:!0,value:e}:{valid:!1,value:"Anon",message:t}:{valid:!1,message:t}},default:"Anon"}),n("tinycomments_author_name",{processor:e=>{const t="Must be a non-empty string";return d(e)?fe(e)?{valid:!0,value:e}:{valid:!1,value:"Anon",message:t}:{valid:!1,message:t}}}),n("tinycomments_author_avatar",{processor:"string"}),n("tinycomments_mentions_enabled",{processor:"boolean",default:!0}),T(["tinycomments_create","tinycomments_reply","tinycomments_lookup","tinycomments_fetch","tinycomments_delete","tinycomments_delete_all","tinycomments_delete_comment","tinycomments_can_delete","tinycomments_can_delete_comment","tinycomments_resolve","tinycomments_can_resolve","tinycomments_edit_comment","tinycomments_can_edit_comment","tinycomments_fetch_author_info"],(e=>n(e,{processor:"function"})))})(e,t);const h=(e=>("embedded"===Un(e)?Jn:Fn)(e))(e),f={translate:e=>tinymce.translate(e),getIcon:t=>{var n;return null!==(n=e.ui.registry.getAll().icons[t])&&void 0!==n?n:"temporary-placeholder"}},y=((e,t)=>tinymce.Resource.load("tinymce.plugins.tinycomments.sidebar",t))(0,(e=>Bn(e)+"/")(e)+"tinycomments-sidebar.min.js").then((e=>(a.set(!0),e))),b=Ht(f);e.on("remove",b.release),e.on("PreInit",(()=>{h.lifecycleHooks.onPreInit(e),((e,t)=>{e.annotator.register(Wt(),{decorate:()=>({classes:[Yt()],attributes:{}})}),e.annotator.annotationChanged(Wt(),((e,n,o)=>{o&&on(o.uid)||(e?t.onComment():t.notOnComment())}))})(e,b)})),_n(e,h,_,c),Co(e,0,l,v,g,c,u,s.enforcer),((e,t,n,o,r,s,a,i,c,l)=>{const d=V(!0),m=new Promise((t=>{e.initialized?t():e.on("init",(()=>{t()}),!0)}));e.ui.registry.addSidebar("showcomments",{tooltip:jt.tc_items_showcomments,icon:"comment",onShow:yo(e,s,d,t,n,o,l,a,i,r,m,c),onHide:bo(e,s)})})(e,h,f,_,y,l,v,g,u,c),((e,t)=>{e.on("init DisabledStateChange",(()=>{n(e.mode.get())})),e.on("SwitchMode",(e=>{n(e.mode)}));const n=n=>{const o=Xn(e,n);var r;t.set(o),"readonly"!==n&&((e=>"read"===e)(r=o)||(e=>"comment"===e)(r))&&e.mode.set("readonly")}})(e,m);const w=()=>{const t=I(e.annotator.getAll("tinycomments"));((e,t,n=r)=>o(n).eq(e,t))(t,c.get(),n)||c.set(t)},x=(e=>{let t=null;const n=()=>{p(t)||(clearTimeout(t),t=null)};return{cancel:n,throttle:(...o)=>{n(),t=setTimeout((()=>{t=null,e.apply(null,o)}),250)}}})(w);return e.on("LoadContent",w),e.on("SetContent input Change",x.throttle),e.on("remove",x.cancel),e.on("GetContent",(t=>{if(d(t.content)){const n=!0===t.source_view,o=!0===t.contextual,r=!0===t.selection,s=n||o||r?A.none():h.lifecycleHooks.onGetContent(e,t.content);t.content=s.getOr(t.content)}})),((e,t)=>({getEventLog:zt(t),hasLoadedUi:e.get}))(a,i)}})}();