10 lines
30 KiB
JavaScript

/*!
* Tiny Footnotes plugin
*
* Copyright (c) 2022 Ephox Corporation DBA Tiny Technologies, Inc.
* Licensed under the Tiny commercial license. See https://www.tiny.cloud/legal/
*
* Version: 8.3.0-112
*/
!function(){"use strict";const e=e=>t=>typeof t===e,t=e=>"string"===(e=>{const t=typeof e;return null===e?"null":"object"===t&&Array.isArray(e)?"array":"object"===t&&(o=n=e,(r=String).prototype.isPrototypeOf(o)||n.constructor?.name===r.name)?"string":t;var o,n,r})(e),o=e("boolean"),n=e=>null==e,r=e=>!n(e),s=e("function"),i=e("number"),a=()=>{},d=e=>()=>e,c=(e,t)=>e===t,l=d(!1);class u{tag;value;static singletonNone=new u(!1);constructor(e,t){this.tag=e,this.value=t}static some(e){return new u(!0,e)}static none(){return u.singletonNone}fold(e,t){return this.tag?t(this.value):e()}isSome(){return this.tag}isNone(){return!this.tag}map(e){return this.tag?u.some(e(this.value)):u.none()}bind(e){return this.tag?e(this.value):u.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:u.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 r(e)?u.some(e):u.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 m=Array.prototype.indexOf,f=(e,t)=>{return o=e,n=t,m.call(o,n)>-1;var o,n},p=(e,t)=>{for(let o=0,n=e.length;o<n;o++)if(t(e[o],o))return!0;return!1},g=(e,t)=>{const o=e.length,n=new Array(o);for(let r=0;r<o;r++){const o=e[r];n[r]=t(o,r)}return n},h=(e,t)=>{for(let o=0,n=e.length;o<n;o++)t(e[o],o)},y=(e,t)=>{const o=[];for(let n=0,r=e.length;n<r;n++){const r=e[n];t(r,n)&&o.push(r)}return o},v=(e,t,o)=>(h(e,((e,n)=>{o=t(o,e,n)})),o),x=Object.keys,b=Object.hasOwnProperty,w=(e,t)=>{const o=x(e);for(let n=0,r=o.length;n<r;n++){const r=o[n];t(e[r],r)}},S=(e,t)=>C(e,((e,o)=>({k:o,v:t(e,o)}))),C=(e,t)=>{const o={};return w(e,((e,n)=>{const r=t(e,n);o[r.k]=r.v})),o},P=(e,t)=>b.call(e,t),k=e=>{let t=e;return{get:()=>t,set:e=>{t=e}}};let T=0;const $=e=>{const t=[],o=e=>{t.push(e)};for(let t=0;t<e.length;t++)e[t].each(o);return t},I=(e,t)=>E(e,t)?((e,t)=>e.substring(t))(e,t.length):e,E=(e,t)=>((e,t)=>""===t||e.length>=t.length&&e.substr(0,0+t.length)===t)(e,t),D=(R=/^\s+|\s+$/g,e=>e.replace(R,""));var R;const L="\xa0",N=(e,t)=>{const{type:o,message:n}=t;e.notificationManager.open({type:o,text:n})},A=e=>{const t=(e=>{switch(e){case"error":return console.error;case"info":return console.info;case"warn":return console.warn;default:return console.log}})(e.type);t(e.message)},M=(e,t)=>{const{protect:o,allowList:n=[],blockList:s=[]}=null!=e?e:{};let i;return i=r(o)?o:n.length>0||s.length>0||t,{protect:i,allowList:n,blockList:s}},B=e=>{const{protect:t,allowList:o,blockList:n}=null!=e?e:{};return e=>{const r=e.toLowerCase();return o.length>0?!p(o,(e=>e.toLowerCase()===r)):n.length>0?p(n,(e=>e.toLowerCase()===r)):t}},W=e=>{const t=B(e);return(e,o)=>{const n=((e,t)=>`${e}:${t}`)(o,e.toLowerCase());return t(n)}},O=(e,t,o,n)=>{const r=Reflect.get(e,"on"),s={protectedEventHandlers:[],cleanupScheduled:!1},i=(e,t)=>{n&&console.log(`[EventsProxy] ${e}`,t||"")},d=t=>{"invalid"===t&&s.protectedEventHandlers.length>0&&(i("Removing event handlers",s.protectedEventHandlers),h(s.protectedEventHandlers,(t=>{e.off(t.name,t.callback)})),s.protectedEventHandlers=[])},c=t.onStatusChange(d);return e.on("remove",c),(n,c,l)=>{i(`Adding event listener: ${n}`,{shouldProtect:o(n)});const u=((e,n)=>{const r=o(e),i=t.getStatus(),d=r&&"invalid"===i?a:n;return r&&s.protectedEventHandlers.push({name:e,callback:d}),d})(n,c);return s.cleanupScheduled||(s.cleanupScheduled=!0,window.setTimeout((()=>{d(t.getStatus()),s.cleanupScheduled=!1}),0)),Reflect.apply(r,e,[n,u,l])}},F=(e,t,o)=>n=>{const s="invalid"!==t.getStatus()&&r(o)?o(n):a,i=((e,t,o)=>{const n=e=>{"invalid"===e&&o.setEnabled(!1)},r=()=>n(t.getStatus());n(t.getStatus()),e.on("NodeChange",r);const s=t.onStatusChange(n);return()=>{e.off("NodeChange",r),s()}})(e,t,n);return e=>{null==s||s(e),i()}},U=(e,t,o)=>(...n)=>{var r;return"invalid"===e.getStatus()?o:null!==(r=null==t?void 0:t(...n))&&void 0!==r?r:o},V=(e,t)=>U(e,t,Promise.resolve([])),j=(e,t)=>U(e,t,[]),H=(e,t)=>U(e,t,!1),q=(e,o,n,r)=>{const s=o=>{const{command:s,value:i}=o,a=u.from(i).filter(t).map((e=>e.toLowerCase())),d=s.toLowerCase()===r.toLowerCase(),c=a.exists((e=>n.has(e))),l=a.exists((t=>t===e.queryCommandValue(r)));d&&c&&!l&&o.preventDefault()},i=o.onStatusChange((t=>{if("invalid"===t){e.on("BeforeExecCommand",s);const t=()=>{const t=e.queryCommandValue(r);n.has(t.toLowerCase())&&e.execCommand(r,!1,t)};e.initialized?t():e.on("init",t)}}));e.on("remove",(()=>{i(),e.off("BeforeExecCommand",s)}))},_=(e,o,n,r,s,i=!1)=>{const a=new Set,d=new Set,c=(e,t)=>{i&&console.log(`[UiProxy] ${e}`,t||"")};((e,t,o)=>{q(e,t,o,"ToggleView")})(e,n,a),((e,t,o)=>{q(e,t,o,"ToggleSidebar")})(e,n,d);const l=(t,o,i,a)=>{const d=s(t,i);return c(`${a}: ${t}`,{spec:o,context:r,shouldProtect:d}),d?{...o,onSetup:F(e,n,o.onSetup)}:o};return new Proxy(o,{get:(e,o,i)=>{const u=Reflect.get(e,o,i);if(!t(o))return u;switch(o){case"addButton":case"addGroupToolbarButton":case"addToggleButton":case"addMenuButton":case"addSplitButton":return(...t)=>{const[n,r,...s]=t,i=l(n,r,"button",String(o));return Reflect.apply(u,e,[n,i,...s])};case"addMenuItem":case"addToggleMenuItem":case"addNestedMenuItem":return(...t)=>{const[n,r,...s]=t,i=l(n,r,"menuitem",String(o));return Reflect.apply(u,e,[n,i,...s])};case"addAutocompleter":return(...t)=>{const[i,a,...d]=t,l=s(i,"autocompleter");if(c(`${String(o)}: ${i}`,{spec:a,context:r,shouldProtect:l}),l){const t={...a,fetch:V(n,a.fetch)};return Reflect.apply(u,e,[i,t,...d])}return Reflect.apply(u,e,[i,a,...d])};case"addSidebar":return(...t)=>{const[n,i,...a]=t,l=s(n,"sidebar");if(c(`${String(o)}: ${n}`,{spec:i,context:r,shouldProtect:l}),l){d.add(n.toLowerCase());const t={...i};return Reflect.apply(u,e,[n,t,...a])}return Reflect.apply(u,e,[n,i,...a])};case"addView":return(...t)=>{const[n,i,...d]=t,l=s(n,"view");if(c(`${String(o)}: ${n}`,{spec:i,context:r,shouldProtect:l}),l){a.add(n.toLowerCase());const t={...i};return Reflect.apply(u,e,[n,t,...d])}return Reflect.apply(u,e,[n,i,...d])};case"addContextMenu":return(...t)=>{const[i,a,...d]=t,l=s(i,"contextmenu");if(c(`${String(o)}: ${i}`,{spec:a,context:r,shouldProtect:l}),l){const t={...a,update:j(n,a.update)};return Reflect.apply(u,e,[i,t,...d])}return Reflect.apply(u,e,[i,a,...d])};case"addContextToolbar":case"addContextForm":return(...t)=>{const[i,a,...d]=t,l=s(i,"contexttoolbar");if(c(`${String(o)}: ${i}`,{spec:a,context:r,shouldProtect:l}),l){const t={...a,predicate:H(n,a.predicate)};return Reflect.apply(u,e,[i,t,...d])}return Reflect.apply(u,e,[i,a,...d])};case"addIcon":case"getAll":case"addContext":return u}}})},z=new Set(["addCommand","addCommands","addQueryStateHandler","addQueryValueHandler"]),K=e=>(t,o)=>{e&&console.log(`[EditorProxy] ${t}`,o||"")},G=(e,t)=>{const{statusProvider:o,uiContext:n,protection:r,debug:i=!1}=t,{events:d,commands:c,ui:l}=r;K(i)("Creating enhanced editor with options:",{hasStatusProvider:!!o,uiContext:n,debug:i,protection:r});const{editorUiProxy:u,editorCommandsProxy:m,editorEventListenerProxy:f}=((e,t,o,n,r,s,i)=>{const d=s.protect?{...e.ui,registry:_(e,e.ui.registry,t,o,W(s),i)}:e.ui,c=n.protect?((e,t,o,n,r)=>{const s={protectedCommands:[],cleanupScheduled:!1},i=(e,t)=>{r&&console.log(`[CommandsProxy] ${e}`,t||"")},d=(e,t)=>{const r=n(e),i=o.getStatus();return r&&s.protectedCommands.push(e),r&&"invalid"===i?a:t},c=t=>{"invalid"===t&&s.protectedCommands.length>0&&(i("Removing commands",s.protectedCommands),h(s.protectedCommands,(t=>{e.editorCommands.removeCommand(t)})),s.protectedCommands=[])},l=()=>{s.cleanupScheduled||(s.cleanupScheduled=!0,window.setTimeout((()=>{c(o.getStatus()),s.cleanupScheduled=!1}),0))},u=o.onStatusChange(c);return e.on("remove",u),new Proxy(t,{get:(e,o,r)=>{if(i(`Accessing property: ${String(o)}`),"addCommand"===o){const s=Reflect.get(e,o,r);return(e,o,...r)=>{i(`Adding command: ${e}`,{shouldProtect:n(e)});const a=d(e,o);return l(),Reflect.apply(s,t,[e,a,...r])}}if("addCommands"===o){const n=Reflect.get(e,o,r);return(e,o="exec")=>{i(`Adding commands (${o})`,{commandCount:Object.keys(e).length,willApplyEnforcement:"exec"===o});const r="exec"!==o?e:S(e,((e,t)=>d(t,e)));return l(),Reflect.apply(n,t,[r,o])}}return Reflect.get(e,o,r)}})})(e,e.editorCommands,t,B(n),i):e.editorCommands;return{editorUiProxy:d,editorCommandsProxy:c,editorEventListenerProxy:r.protect?O(e,t,B(r),i):e.on.bind(e)}})(e,o,n||"",c,d,l,i),p=((e,t,o,n)=>(r,i,a)=>{const d=String(i);if("on"===i)return K(n)("on intercepted"),o;if(z.has(d))return K(n)(`${d} intercepted`),t[d].bind(t);if("editorCommands"===i)return K(n)("editorCommands accessed"),t;if("ui"===i)return K(n)("ui accessed"),e;const c=Reflect.get(r,i,a);return s(c)?c.bind(r):c})(u,m,f,i);return new Proxy(e,{get:p,set:(e,t,o,n)=>Reflect.set(e,t,o,n),has:(e,t)=>Reflect.has(e,t),ownKeys:e=>Reflect.ownKeys(e),getOwnPropertyDescriptor:(e,t)=>Reflect.getOwnPropertyDescriptor(e,t),defineProperty:(e,t,o)=>Reflect.defineProperty(e,t,o),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)})},Q=e=>parseInt(e,10),J=(e,t)=>{const o=e-t;return 0===o?0:o>0?1:-1},X=(e,t,o)=>({major:e,minor:t,patch:o}),Y=e=>{const t=/([0-9]+)\.([0-9]+)\.([0-9]+)(?:(\-.+)?)/.exec(e);return t?X(Q(t[1]),Q(t[2]),Q(t[3])):X(0,0,0)},Z=(e,t)=>!!e&&-1===((e,t)=>{const o=J(e.major,t.major);if(0!==o)return o;const n=J(e.minor,t.minor);if(0!==n)return n;const r=J(e.patch,t.patch);return 0!==r?r:0})((e=>Y((e=>[e.majorVersion,e.minorVersion].join(".").split(".").slice(0,3).join("."))(e)))(e),Y(t)),ee=Y("8.3.0"),te=`${ee.major}.${ee.minor}.0`,oe=`${ee.major+1}.0.0`,ne=(e,t)=>{const{setup:o,protection:i}=t;return(a,d)=>{if(!((e,t)=>Z(e,te)?(console.error(`The "${t}" plugin requires at least version ${te} of TinyMCE.`),!1):!!Z(e,oe)||(console.error(`The "${t}" plugin requires at least version ${te} of TinyMCE but less than ${oe}.`),!1))(tinymce,e)||((e,t)=>!!(e=>{var t;const o=null===(t=e.options.get("license_key"))||void 0===t?void 0:t.toLowerCase(),r=e.options.get("online_license_key");return n(r)&&"gpl"===o})(e)&&(((e,t)=>{const{console:o,editor:n}=t;r(n)&&(e._skinLoaded?N(e,n):e.on("SkinLoaded",(()=>{N(e,n)}))),r(o)&&A(o)})(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))(a,e))return{};const c=(e=>{const{protect:t=!0,events:o,commands:n,ui:r,api:s}=null!=e?e:{};return{protect:t,events:M(o,false),commands:M(n,true),ui:M(r,true),api:M(s,true)}})(i),l=((e="pre-validation")=>{const t=k(e),o=new Set;let n=!1;const{enableLogging:r=!1}={},s=(e,...t)=>{r&&console.log(`[StatusProvider] ${e}`,...t)};return{setStatus:e=>{const n=t.get();if(n===e)return s("Status unchanged:",e),!1;t.set(e),s("Status changed:",n,"->",e);const r={currentStatus:e,previousStatus:n},i=Array.from(o);return h(i,(e=>{e(r.currentStatus,r.previousStatus)})),!0},onStatusChange:e=>(o.add(e),s("Callback registered, total listeners:",o.size),()=>{o.delete(e)&&s("Callback unregistered, remaining listeners:",o.size)}),getStatus:t.get,hasListeners:()=>o.size>0,destroy:()=>{n||(s("Destroying StatusProvider, clearing",o.size,"listeners"),o.clear(),n=!0)}}})(),u=((e,t,o)=>{const n=`commercial-license-${t}`;return e.ui.registry.addContext(n,(()=>"invalid"!==o.getStatus()&&!e.mode.isReadOnly())),e.licenseKeyManager.validate({plugin:t}).then((e=>{o.setStatus(e?"valid":"invalid")}),(e=>{console.error(e),console.error(`An unknown error occurred when trying to validate "${t}" plugin.`),o.setStatus("invalid")})),{ui:{context:n}}})(a,e,l),m=c.protect?G(a,{statusProvider:l,uiContext:u.ui.context,debug:t.debug||!1,protection:c}):a,f=((e,t)=>({pluginCode:e,enforcer:{isInvalid:()=>"invalid"===t.getStatus(),onInvalid:e=>t.onStatusChange(((t,o)=>{"invalid"===t&&e(t,o)}))}}))(e,l);return((e,t,o,n)=>{if(t.protect&&t.api.protect&&r(e)){const a=B(t.api);return(i=e=>"invalid"===o.getStatus()&&a(e),(e,t)=>S(e,((e,o)=>s(e)?(...n)=>{if(i(o.toLowerCase())){const e=`Method "${r(t)?`${t}.`:""}${o}" is not available due to license key restrictions.`,n=new Error(e);throw console.error(e),n}return e(...n)}:e)))(e,n)}var i;return e})(o(m,d,f),c,l,e)}},re=(e,t)=>({element:e,offset:t}),se=e=>{if(null==e)throw new Error("Node cannot be null or undefined");return{dom:e}},ie={fromHtml:(e,t)=>{const o=(t||document).createElement("div");if(o.innerHTML=e,!o.hasChildNodes()||o.childNodes.length>1){const t="HTML does not have a single root node";throw console.error(t,e),new Error(t)}return se(o.childNodes[0])},fromTag:(e,t)=>{const o=(t||document).createElement(e);return se(o)},fromText:(e,t)=>{const o=(t||document).createTextNode(e);return se(o)},fromDom:se,fromPoint:(e,t,o)=>u.from(e.dom.elementFromPoint(t,o)).map(se)},ae=(e,t)=>{const o=e.dom;if(1!==o.nodeType)return!1;{const e=o;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")}},de=e=>1!==e.nodeType&&9!==e.nodeType&&11!==e.nodeType||0===e.childElementCount,ce=(e,t)=>e.dom===t.dom,le=ae,ue=e=>e.dom.nodeName.toLowerCase(),me=e=>e.dom.nodeType,fe=e=>t=>me(t)===e,pe=fe(1),ge=fe(3),he=fe(9),ye=fe(11),ve=e=>ie.fromDom(e.dom.ownerDocument),xe=e=>u.from(e.dom.parentNode).map(ie.fromDom),be=e=>u.from(e.dom.nextSibling).map(ie.fromDom),we=e=>g(e.dom.childNodes,ie.fromDom),Se=e=>ie.fromDom(e.dom.host),Ce=(e,t)=>{xe(e).each((o=>{o.dom.insertBefore(t.dom,e.dom)}))},Pe=(e,t)=>{be(e).fold((()=>{xe(e).each((e=>{ke(e,t)}))}),(e=>{Ce(e,t)}))},ke=(e,t)=>{e.dom.appendChild(t.dom)},Te=(e,t)=>{h(t,((o,n)=>{const r=0===n?e:t[n-1];Pe(r,o)}))},$e=(e,t)=>{h(t,(t=>{ke(e,t)}))},Ie=(e,n,r)=>{if(!(t(r)||o(r)||i(r)))throw console.error("Invalid call to Attribute.set. Key ",n,":: Value ",r,":: Element ",e),new Error("Attribute value was not simple");e.setAttribute(n,r+"")},Ee=(e,t,o)=>{Ie(e.dom,t,o)},De=(e,t)=>{const o=e.dom;w(t,((e,t)=>{Ie(o,t,e)}))},Re=(e,t)=>{const o=e.dom.getAttribute(t);return null===o?void 0:o},Le=(e,t)=>u.from(Re(e,t)),Ne=(e,t)=>{e.dom.removeAttribute(t)},Ae=e=>{e.dom.textContent="",h(we(e),(e=>{Me(e)}))},Me=e=>{const t=e.dom;null!==t.parentNode&&t.parentNode.removeChild(t)},Be=e=>e.dom.innerHTML,We=e=>void 0!==e.style&&s(e.style.getPropertyValue),Oe=e=>{const t=ge(e)?e.dom.parentNode:e.dom;if(null==t||null===t.ownerDocument)return!1;const o=t.ownerDocument;return(e=>{const t=(e=>ie.fromDom(e.dom.getRootNode()))(e);return ye(o=t)&&r(o.dom.host)?u.some(t):u.none();var o})(ie.fromDom(t)).fold((()=>o.body.contains(t)),(n=Oe,s=Se,e=>n(s(e))));var n,s},Fe=(e,t)=>We(e)?e.style.getPropertyValue(t):"",Ue=(e=>{const t=t=>e(t)?u.from(t.dom.nodeValue):u.none();return{get:o=>{if(!e(o))throw new Error("Can only get text value of a text node");return t(o).getOr("")},getOption:t,set:(t,o)=>{if(!e(t))throw new Error("Can only set raw text value of a text node");t.dom.nodeValue=o}}})(ge),Ve=(e,t,o)=>{let n=e.dom;const r=s(o)?o:l;for(;n.parentNode;){n=n.parentNode;const e=ie.fromDom(n);if(t(e))return u.some(e);if(r(e))break}return u.none()},je=(e,t,o)=>Ve(e,(e=>ae(e,t)),o),He=(e,t)=>(e=>{return(o=e.dom.childNodes,n=e=>{return o=ie.fromDom(e),ae(o,t);var o},((e,t,o)=>{for(let n=0,r=e.length;n<r;n++){const r=e[n];if(t(r,n))return u.some(r);if(o(r,n))break}return u.none()})(o,n,l)).map(ie.fromDom);var o,n})(e),qe=(e,t)=>((e,t)=>{const o=void 0===t?document:t.dom;return de(o)?u.none():u.from(o.querySelector(e)).map(ie.fromDom)})(t,e),_e=(e,t)=>{(e=>void 0!==e.dom.classList)(e)?e.dom.classList.add(t):((e,t)=>{((e,t,o)=>{const n=((e,t)=>{const o=Re(e,t);return void 0===o||""===o?[]:o.split(" ")})(e,t),r=n.concat([o]);Ee(e,t,r.join(" "))})(e,"class",t)})(e,t)},ze=(e,t)=>{e.dom.textContent=t},Ke=(e,t)=>{let o=[];return h(we(e),(e=>{t(e)&&(o=o.concat([e])),o=o.concat(Ke(e,t))})),o},Ge=(e,t)=>(e=>y(we(e),(e=>ae(e,t))))(e),Qe=(e,t)=>((e,t)=>{const o=void 0===t?document:t.dom;return de(o)?[]:g(o.querySelectorAll(e),ie.fromDom)})(t,e),Je=(e,t,o)=>je(e,t,o).isSome();var Xe=["body","p","div","article","aside","figcaption","figure","footer","header","nav","section","ol","ul","li","table","thead","tbody","tfoot","caption","tr","td","th","h1","h2","h3","h4","h5","h6","blockquote","pre","address"];const Ye=(e,t,o)=>e.property().isText(t)&&0===e.property().getText(t).trim().length||e.property().isComment(t)?o(t).bind((t=>Ye(e,t,o).orThunk((()=>u.some(t))))):u.none(),Ze=(e,t)=>e.property().isText(t)?e.property().getText(t).length:e.property().children(t).length,et=(e,t)=>{const o=Ye(e,t,e.query().prevSibling).getOr(t);if(e.property().isText(o))return re(o,Ze(e,o));const n=e.property().children(o);return n.length>0?et(e,n[n.length-1]):re(o,Ze(e,o))},tt=et,ot={up:d({selector:je,closest:(e,t,o)=>((e,t,o,n,r)=>((e,t)=>ae(e,t))(o,n)?u.some(o):s(r)&&r(o)?u.none():t(o,n,r))(0,je,e,t,o),predicate:Ve,all:(e,t)=>{const o=s(t)?t:l;let n=e.dom;const r=[];for(;null!==n.parentNode&&void 0!==n.parentNode;){const e=n.parentNode,t=ie.fromDom(e);if(r.push(t),!0===o(t))break;n=e}return r}}),down:d({selector:Qe,predicate:Ke}),styles:d({get:(e,t)=>{const o=e.dom,n=window.getComputedStyle(o).getPropertyValue(t);return""!==n||Oe(e)?n:Fe(o,t)},getRaw:(e,t)=>{const o=e.dom,n=Fe(o,t);return u.from(n).filter((e=>e.length>0))},set:(e,o,n)=>{((e,o,n)=>{if(!t(n))throw console.error("Invalid call to CSS.set. Property ",o,":: Value ",n,":: Element ",e),new Error("CSS value must be a string: "+n);We(e)&&e.style.setProperty(o,n)})(e.dom,o,n)},remove:(e,t)=>{((e,t)=>{We(e)&&e.style.removeProperty(t)})(e.dom,t),((e,t,o=c)=>e.exists((e=>o(e,t))))(Le(e,"style").map(D),"")&&Ne(e,"style")}}),attrs:d({get:Re,set:Ee,remove:Ne,copyTo:(e,t)=>{const o=v(e.dom.attributes,((e,t)=>(e[t.name]=t.value,e)),{});De(t,o)}}),insert:d({before:Ce,after:Pe,afterAll:Te,append:ke,appendAll:$e,prepend:(e,t)=>{(e=>(e=>{const t=e.dom.childNodes;return u.from(t[0]).map(ie.fromDom)})(e))(e).fold((()=>{ke(e,t)}),(o=>{e.dom.insertBefore(t.dom,o.dom)}))},wrap:(e,t)=>{Ce(e,t),ke(t,e)}}),remove:d({unwrap:e=>{const t=we(e);t.length>0&&Te(e,t),Me(e)},remove:Me}),create:d({nu:ie.fromTag,clone:e=>ie.fromDom(e.dom.cloneNode(!1)),text:ie.fromText}),query:d({comparePosition:(e,t)=>e.dom.compareDocumentPosition(t.dom),prevSibling:e=>u.from(e.dom.previousSibling).map(ie.fromDom),nextSibling:be}),property:d({children:we,name:ue,parent:xe,document:e=>{return(t=e,he(t)?t:ve(t)).dom;var t},isText:ge,isComment:e=>8===me(e)||"#comment"===ue(e),isElement:pe,isSpecial:e=>{const t=ue(e);return f(["script","noscript","iframe","noframes","noembed","title","style","textarea","xmp"],t)},getLanguage:e=>pe(e)?Le(e,"lang"):u.none(),getText:e=>Ue.get(e),setText:(e,t)=>Ue.set(e,t),isBoundary:e=>!!pe(e)&&("body"===ue(e)||f(Xe,ue(e))),isEmptyTag:e=>!!pe(e)&&f(["br","img","hr","input"],ue(e)),isNonEditable:e=>pe(e)&&"false"===Re(e,"contenteditable")}),eq:ce,is:le},nt="footnote",rt="mce-footnote",st="mce-footnotes",it="footnotes_entry",at="mce-footnotes-backlink",dt="mce-footnotes-note",ct="sup",lt="div",ut="li",mt="span",ft='[contenteditable="false"]',pt=e=>`${ct}.${rt}${t(e)?`#${e}`:""}${ft}`,gt=`${lt}.${st}${ft}`,ht=e=>`${ut}#${e}`,yt=`a.${at}`,vt=`${mt}.${dt}[contenteditable="true"]`,xt=e=>`${nt}_${e}`,bt=e=>`${it}_${e}`,wt=e=>t=>I(t,e+"_"),St=wt(nt),Ct=wt(it),Pt=e=>e.startsWith(nt+"_"),kt=e=>e.startsWith(it+"_"),Tt=e=>{const t=e.getBody(),o=e.selection.getStart(),n=`${gt} ${ut}`;return u.from(e.dom.getParent(o,n,t)).bind((o=>u.from(e.dom.getParent(o,gt,t)).map((e=>({section:ie.fromDom(e),entry:ie.fromDom(o)})))))},$t=(It=e=>r(e.dom.getParent(e.selection.getStart(),gt,e.getBody())),e=>!It(e));var It;const Et=e=>ie.fromDom(e.getBody()),Dt=(Rt=ut,e=>pe(e)&&ue(e)===Rt);var Rt;const Lt=e=>qe(e,gt),Nt=e=>He(e,"ol"),At=e=>He(e,vt),Mt=e=>Le(e,"id").filter(kt),Bt=e=>Dt(e)&&Mt(e).isSome()&&Je(e,gt),Wt=(e,t)=>Lt(Et(e)).bind(Nt).bind((e=>((e,t)=>He(e,ht(t)))(e,t))).bind(At).each((t=>{Ot(e,t),e.selection.scrollIntoView(void 0,!0)})),Ot=(e,t)=>{const o=e.dom.createRng(),n=tt(ot,t);o.setStart(n.element.dom,n.offset),o.setEnd(n.element.dom,n.offset),e.selection.setRng(o)},Ft=e=>Mt(e).bind((t=>At(e).map(Be).bind((o=>{return(n=e,He(n,yt)).bind((e=>Le(e,"href"))).map((e=>({entryIdWithPrefix:t,note:o,backlinkIdWithPrefix:e})));var n})))),Ut=e=>{const t=ie.fromTag(ut),o=ie.fromTag("a");_e(o,at),ze(o,`^${L}`);const n=ie.fromTag(mt);_e(n,dt),Ee(n,"contenteditable",!0);return((e,t)=>{const o=ve(e).dom,n=ie.fromDom(o.createDocumentFragment()),r=((e,t)=>{const o=(t||document).createElement("div");return o.innerHTML=e,we(ie.fromDom(o))})(t,o);$e(n,r),Ae(e),ke(e,n)})(n,e.note.length>0?e.note:'<br data-mce-bogus="1">'),ke(t,o),ke(t,n),Ee(t,"id",e.entryIdWithPrefix),Ee(o,"href",e.backlinkIdWithPrefix),t},Vt=e=>{const t=Qe(e,pt());return y(t,(t=>{return n=e,!((e=>{const t=e.dom;return!(!t||!t.hasAttribute)&&t.hasAttribute("data-mce-bogus")})(o=t)||Je(o,'[data-mce-bogus="all"]',(e=>t=>ce(t,e))(n)));var o,n}))},jt=e=>qe(e,"a"),Ht=()=>(e=>{const t=(new Date).getTime(),o=Math.floor(window.crypto.getRandomValues(new Uint32Array(1))[0]/4294967295*1e9);return T++,e+"_"+o+T+String(t)})(nt),qt=e=>{return(t=e,Le(t,"id").filter(Pt)).bind((t=>jt(e).bind((e=>(e=>Le(e,"data-mce-href").orThunk((()=>Le(e,"href"))).bind((e=>{return t=e,E(e,"#")?u.some(t):u.none();var t})))(e).map((o=>{var n,r;return{footnoteIdWithPrefix:t,symbol:null!==(r=e,n=r.dom.textContent)&&void 0!==n?n:"",forwardlinkIdWithPrefix:o}}))))));var t},_t=(e,t,o)=>{Ee(e,"id",o.footnoteIdWithPrefix),ze(t,o.symbol),Ee(t,"href",o.forwardlinkIdWithPrefix),Ee(t,"data-mce-href",o.forwardlinkIdWithPrefix)},zt=(e,t)=>{const o=Vt(e),n=y(o,(e=>qt(e).isSome()));h(n,((e,o)=>{var n,r;n=e,r=t[o],jt(n).each((e=>{_t(n,e,r)}))}))},Kt=(e,t,o)=>{const n=v(t,((e,t)=>{const o=Ct(t.entryIdWithPrefix);return{...e,[o]:t}}),{}),r=v(e,((e,t,r)=>{const s=St(t.footnoteIdWithPrefix),i={newBaseId:P(e.existingIds,s)?St(o(s)):s,note:(a=n,d=s,P(a,d)?u.from(a[d]):u.none()).map((e=>e.note)).getOr(""),symbol:String(r+1)};var a,d;return{intexts:e.intexts.concat([i]),existingIds:{...e.existingIds,[s]:!0}}}),{existingIds:{},intexts:[]}),s=g(r.intexts,(e=>({note:e.note,entryIdWithPrefix:bt(e.newBaseId),backlinkIdWithPrefix:`#${xt(e.newBaseId)}`})));return{intext:g(r.intexts,(e=>({footnoteIdWithPrefix:xt(e.newBaseId),forwardlinkIdWithPrefix:`#${bt(e.newBaseId)}`,symbol:e.symbol}))),entries:s}},Gt=(e,t)=>{(e=>{h(Vt(e),Me)})(t);const o=(e=>{const t=e.getBody();return Lt(ie.fromDom(t)).bind((t=>{if("1"===Re(t,"data-mce-selected")||((e,t)=>Tt(e).filter((({section:e})=>ce(t,e))).isSome())(e,t)){const o=e.dom.createRng();return o.setStartBefore(t.dom),o.setEndBefore(t.dom),Me(t),u.some(o)}return Me(t),u.none()}))})(e);e.dom.isEmpty(e.getBody())?(e.setContent(""),e.selection.setCursorLocation()):o.each(e.selection.setRng)},Qt=(e,t)=>{const o=Et(e),{addUndo:n,isDeleteTrigger:r}=t,s=(e=>{const t=Vt(e);return $(g(t,qt))})(o),i=(e=>{const t=Lt(e),o=(e=>Lt(e).bind(Nt).map((e=>Ge(e,ut))).getOr([]))(e);return t.map((e=>({entries:$(g(o,Ft))})))})(o),a=((e,t,o)=>e.section.fold((()=>e.intext.length>0?o?{kind:"remove-footnotes"}:((e,t)=>{const{intext:o,entries:n}=Kt(e,[],t);return{kind:"insert-footnotes",newFootnotes:{intext:o,entries:n}}})(e.intext,t):{kind:"noop-footnotes"}),(o=>e.intext.length>0?((e,t,o)=>{const{intext:n,entries:r}=Kt(e,t,o);return n.length!==e.length||p(n,((t,o)=>t.footnoteIdWithPrefix!==e[o].footnoteIdWithPrefix||t.symbol!==e[o].symbol||t.forwardlinkIdWithPrefix!==e[o].forwardlinkIdWithPrefix))||r.length!==t.length||p(r,((e,o)=>e.entryIdWithPrefix!==t[o].entryIdWithPrefix||e.backlinkIdWithPrefix!==t[o].backlinkIdWithPrefix||e.note!==t[o].note))?{kind:"update-footnotes",newFootnotes:{intext:n,entries:r}}:{kind:"noop-footnotes"}})(e.intext,o.entries,t):{kind:"remove-footnotes"})))({intext:s,section:i},Ht,r),d=n?e.undoManager.transact:e.undoManager.ignore;switch(a.kind){case"noop-footnotes":return;case"remove-footnotes":return void d((()=>{Gt(e,o)}));case"insert-footnotes":return void d((()=>{zt(o,a.newFootnotes.intext),((e,t)=>{const o=(e=>{const t=(()=>{const e=ie.fromTag(lt);return De(e,{contentEditable:!1}),_e(e,st),e})(),o=ie.fromTag("hr"),n=ie.fromTag("ol");return $e(n,e),ke(t,o),ke(t,n),t})(g(t,Ut));ke(e,o)})(o,a.newFootnotes.entries)}));case"update-footnotes":return void d((()=>{zt(o,a.newFootnotes.intext),((e,t)=>{Tt(e).bind((({entry:e,section:t})=>Mt(e).map((e=>({entryId:e,section:t}))))).filter((({section:t})=>Lt(Et(e)).exists((e=>ce(e,t))))).fold((()=>t()),(o=>{const n=t(),r=`${ht(o.entryId)} ${vt}`;return qe(o.section,r).orThunk((()=>{const e=`${ut} ${vt}`;return qe(o.section,e)})).each((t=>Ot(e,t))),n}))})(e,(()=>{((e,t)=>{const o=g(t,Ut);Lt(e).bind(Nt).each((e=>{Ae(e),$e(e,o)}))})(o,a.newFootnotes.entries)}))}))}},Jt=e=>{e.addCommand("mceInsertFootnote",((t,o)=>{e.selection.isEditable()&&(e=>{$t(e)&&e.undoManager.transact((()=>{const t=(e=>{const t=Ht(),o=St(t);return e.undoManager.ignore((()=>{const o=((e,t)=>{const o=ie.fromTag(ct);Ee(o,"contenteditable","false"),_e(o,rt);const n=ie.fromTag("a");return ke(o,n),_t(o,n,{footnoteIdWithPrefix:e,symbol:t,forwardlinkIdWithPrefix:`#${bt(St(e))}`}),o})(t,L),n=(e=>{const t=ie.fromTag("div"),o=ie.fromDom(e.dom.cloneNode(!0));return ke(t,o),Be(t)})(o);e.selection.collapse(!1),e.insertContent(n,{no_events:!0})})),o})(e);Qt(e,{addUndo:!1,isDeleteTrigger:!1}),Wt(e,bt(t))}))})(e)})),e.addCommand("mceUpdateFootnotes",((t,o)=>{e.selection.isEditable()&&Qt(e,{addUndo:!0,isDeleteTrigger:!1})}))},Xt=e=>i(null==e?void 0:e.nodeType),Yt=(e,t)=>{e.on("init",(()=>{e.on("click",(o=>{t.isInvalid()||u.from(o.target).filter(Xt).bind((t=>((e,t)=>u.from(e.dom.getParent(t,"a[href]")).map(ie.fromDom))(e,t))).each((t=>{const n=((e,t,o)=>Le(t,"href").filter((e=>/^#/.test(e))).map((e=>I(e,"#"))).exists((t=>Pt(t)?(((e,t)=>{((e,t)=>qe(e,pt(t)))(Et(e),t).each((t=>e.selection.scrollIntoView(t.dom,!0)))})(e,t),!0):!(!kt(t)||!o||(Wt(e,t),0)))))(e,t,tinymce.util.VK.metaKeyPressed(o));n&&o.preventDefault()}))}))}))},Zt=e=>{var t,o;return null!==(o=null===(t=e.attr("class"))||void 0===t?void 0:t.split(" "))&&void 0!==o?o:[]},eo=(e,t)=>{const o=Zt(e).concat(t);e.attr("class",o.join(" "))},to=e=>{const t=new tinymce.html.Node("br",1);t.attr("data-mce-bogus","1"),e.empty(),e.append(t)},oo=e=>{const t=new tinymce.html.Node("#text",3);t.value=L,e.empty(),e.append(t)},no=e=>e.name===lt&&f(Zt(e),st),ro=e=>{const t=e.attr("id");return e.name===ut&&r(t)&&kt(t)},so=e=>{const t=e.attr("id");return e.name===ct&&r(t)&&Pt(t)},io=e=>{let t=e.parent;for(;r(t);){if(no(t))return t;t=t.parent}},ao=e=>{const t=e.children();for(let e=t.length-1;e>=0;e--){const n=t[e];if((o=n).name===mt&&f(Zt(o),dt))return n}var o},co=e=>{const t=[],o=[];for(let n=0;n<e.length;n++){const s=e[n];if(ro(s)){const e=io(s);if(r(e)){const t=o.find((t=>t.node===e));r(t)?t.entries.push(s):o.push({node:e,entries:[s]})}}else so(s)&&t.push(s)}return{intextFootnotes:t,footnotesSections:o}},lo=e=>i(null==e?void 0:e.nodeType);((e,t)=>{const{i18n:o=!0}=t;o&&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,ne(e,t))})("footnotes",{setup:(e,t,o)=>{Jt(e),(e=>{const t=()=>e.execCommand("mceInsertFootnote"),o=()=>e.execCommand("mceUpdateFootnotes"),n=t=>{const o=()=>t.setEnabled(e.selection.isEditable()&&$t(e));return o(),e.on("NodeChange",o),()=>e.off("NodeChange",o)};e.ui.registry.addButton("footnotes",{icon:"footnote",tooltip:"Insert footnote",onAction:t,onSetup:n}),e.ui.registry.addMenuItem("footnotes",{icon:"footnote",text:"Insert footnote",onAction:t,onSetup:n}),e.ui.registry.addButton("footnotesupdate",{icon:"reload",tooltip:"Update footnotes",onAction:o}),e.ui.registry.addMenuItem("footnotesupdate",{icon:"reload",text:"Update footnotes",onAction:o})})(e),(e=>{e.on("PreInit",(()=>{e.serializer.addAttributeFilter("id",(e=>{const t=co(e);for(const e of t.intextFootnotes)e.attr("contenteditable",null);for(const e of t.footnotesSections){const t=e.node,o=e.entries;t.attr("contenteditable",null);for(const e of o){const t=ao(e);if(r(t))t.attr("contenteditable",null);else{const t=new tinymce.html.Node(mt,1);eo(t,[dt]),oo(t),e.append(t)}}}})),e.parser.addAttributeFilter("id",(e=>{var t;const o=co(e);for(const e of o.intextFootnotes)e.attr("contenteditable","false");for(const e of o.footnotesSections){const o=e.node,n=e.entries;o.attr("contenteditable","false");for(const e of n){const o=ao(e);r(o)&&(o.firstChild===o.lastChild&&(null===(t=o.firstChild)||void 0===t?void 0:t.value)===L&&to(o),o.attr("contenteditable","true"))}}}))}))})(e),Yt(e,o.enforcer),(e=>{e.on("PreInit",(()=>{e.on("mousedown tap",(t=>{u.from(t.target).filter(lo).map(ie.fromDom).filter(Bt).filter((t=>At(t).exists((t=>e.dom.isEmpty(t.dom))))).bind(Mt).each((o=>{t.preventDefault(),Wt(e,o)}))}))}))})(e),(e=>{const t=(()=>{const e=(e=>{const t=k(u.none()),o=()=>t.get().each(e);return{clear:()=>{o(),t.set(u.none())},isSet:()=>t.get().isSome(),get:()=>t.get(),set:e=>{o(),t.set(u.some(e))}}})(a);return{...e,on:t=>e.get().each(t)}})();e.on("ExecCommand",(t=>{const o=t.command.toLowerCase();"delete"!==o&&"forwarddelete"!==o||Qt(e,{addUndo:!1,isDeleteTrigger:!0})}),!0),e.on("input",(o=>{var n;("insertParagraph"===(n=o.inputType)||"insertLineBreak"===n||"insertFromPaste"===n||"insertFromDrop"===n||"insertReplacementText"===n)&&(Qt(e,{addUndo:!1,isDeleteTrigger:!0}),t.clear())})),e.on("keydown",(()=>{t.set(!e.selection.isCollapsed())}),!0),e.on("keyup",(o=>{const n=o.keyCode,r=8===n||46===n;(t.get().getOr(!1)||r)&&Qt(e,{addUndo:!1,isDeleteTrigger:!0}),t.clear()})),e.on("dragend",(()=>{Qt(e,{addUndo:!1,isDeleteTrigger:!1})})),e.on("SetContent",(t=>{"raw"!==t.format&&Qt(e,{addUndo:!1,isDeleteTrigger:!t.set})}))})(e)}})}();