// See the "/licenses" URI for full package license details var yh=Object.defineProperty;var Sh=(o,t,e)=>t in o?yh(o,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[t]=e;var p=(o,t,e)=>Sh(o,typeof t!="symbol"?t+"":t,e);function P(o){return __DEV__?{type:o}:{}}var De=P("SELECTION_CHANGE_COMMAND"),rr=P("SELECTION_INSERT_CLIPBOARD_NODES_COMMAND"),Ht=P("CLICK_COMMAND"),Je=P("DELETE_CHARACTER_COMMAND"),Kt=P("INSERT_LINE_BREAK_COMMAND"),Ut=P("INSERT_PARAGRAPH_COMMAND"),ct=P("CONTROLLED_TEXT_INSERTION_COMMAND"),ao=P("PASTE_COMMAND"),hn=P("REMOVE_TEXT_COMMAND"),St=P("DELETE_WORD_COMMAND"),ut=P("DELETE_LINE_COMMAND"),xe=P("FORMAT_TEXT_COMMAND"),co=P("UNDO_COMMAND"),uo=P("REDO_COMMAND"),Hs=P("KEYDOWN_COMMAND"),Ao=P("KEY_ARROW_RIGHT_COMMAND"),Ks=P("MOVE_TO_END"),Ro=P("KEY_ARROW_LEFT_COMMAND"),Us=P("MOVE_TO_START"),zt=P("KEY_ARROW_UP_COMMAND"),Wt=P("KEY_ARROW_DOWN_COMMAND"),Ke=P("KEY_ENTER_COMMAND"),ir=P("KEY_SPACE_COMMAND"),qt=P("KEY_BACKSPACE_COMMAND"),ko=P("KEY_ESCAPE_COMMAND"),Yt=P("KEY_DELETE_COMMAND"),Io=P("KEY_TAB_COMMAND"),zs=P("INSERT_TAB_COMMAND"),Lh=P("INDENT_CONTENT_COMMAND"),Mh=P("OUTDENT_CONTENT_COMMAND"),$o=P("DROP_COMMAND"),sr=P("DRAGSTART_COMMAND"),lr=P("DRAGOVER_COMMAND"),Ws=P("DRAGEND_COMMAND"),fo=P("COPY_COMMAND"),mo=P("CUT_COMMAND"),Nn=P("SELECT_ALL_COMMAND"),qs=P("CLEAR_EDITOR_COMMAND"),Ys=P("CLEAR_HISTORY_COMMAND"),po=P("CAN_REDO_COMMAND"),go=P("CAN_UNDO_COMMAND"),ar=P("FOCUS_COMMAND"),Zs=P("BLUR_COMMAND"),Vs=P("KEY_MODIFIER_COMMAND");var me=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u";var wh=me&&"documentMode"in document?document.documentMode:null,Ue=me&&/Mac|iPod|iPhone|iPad/.test(navigator.platform),ze=me&&/^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent),ho=me&&"InputEvent"in window&&!wh?"getTargetRanges"in new window.InputEvent("input"):!1,Zt=me&&/Version\/[\d.]+.*Safari/.test(navigator.userAgent),Lt=me&&/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream,Sd=me&&/Android/.test(navigator.userAgent),Xs=me&&/^(?=.*Chrome).*/i.test(navigator.userAgent),js=me&&Sd&&Xs,Vt=me&&/AppleWebKit\/[\d.]+/.test(navigator.userAgent)&&!Xs;var No=1,We=3,Mt=0,Gs=1,Xt=2,Ld=0,ri=1,ii=2,dr=1,cr=2,xn=4,En=8,ur=16,fr=32,mr=64,pr=128,Js=dr|cr|xn|En|ur|fr|mr|pr,si=1,Tn=2;var Md="\xA0",vh="\u200B",Cn=Zt||Lt||Vt?Md:vh,Qe=` `,wd=ze?Md:Cn,vd="\u0591-\u07FF\uFB1D-\uFDFD\uFE70-\uFEFC",Dd="A-Za-z\xC0-\xD6\xD8-\xF6\xF8-\u02B8\u0300-\u0590\u0800-\u1FFF\u200E\u2C00-\uFB1C\uFE00-\uFE6F\uFEFD-\uFFFF",Dh=new RegExp("^[^"+Dd+"]*["+vd+"]"),Oh=new RegExp("^[^"+vd+"]*["+Dd+"]"),Oe={bold:dr,code:ur,highlight:pr,italic:cr,strikethrough:xn,subscript:fr,superscript:mr,underline:En},Od={directionless:si,unmergeable:Tn},Ad={normal:Ld,segmented:ii,token:ri},Rd={[Ld]:"normal",[ii]:"segmented",[ri]:"token"};function E(o,t,...e){if(!o){for(let n of e)t=(t||"").replace("%s",n);throw new Error(t)}}function wt(...o){let t=[];for(let e of o)if(e&&typeof e=="string")for(let[n]of e.matchAll(/\S+/g))t.push(n);return t}var Ah=100,el=!1,tl=0;function kd(){return el}function Rh(o){tl=o.timeStamp}function kh(o){tl===0&&bn(o).addEventListener("textInput",Rh,!0)}function Qs(o,t,e){return t.__lexicalLineBreak===o||o[`__lexicalKey_${e._key}`]!==void 0}function Ih(o){return o.getEditorState().read(()=>{let t=C();return t!==null?t.clone():null})}function $h(o,t,e){let n=ye(e._window),r=null,i=null;n!==null&&n.anchorNode===o&&(r=n.anchorOffset,i=n.focusOffset);let s=o.nodeValue;s!==null&&gr(t,s,r,i,!1)}function Ph(o,t,e){return t.nodeType===We&&e.isAttached()}function Id(o,t,e){el=!0;let n=performance.now()-tl>Ah;try{Ee(o,()=>{let r=C()||Ih(o),i=new Map,s=o.getRootElement(),l=o._editorState,a=o._blockCursorElement,d=!1,u="";for(let c=0;c0){let v=0;for(let M=0;M0)for(let[c,f]of i)if(T(f)){let g=f.getChildrenKeys(),h=c.firstChild;for(let N=0;N0){for(let c=0;c{Id(o,t,e)})}function $d(o,t){let e=o.__mode,n=o.__format,r=o.__style,i=t.__mode,s=t.__format,l=t.__style;return(e===null||e===i)&&(n===null||n===s)&&(r===null||r===l)}function Pd(o,t){let e=o.mergeWithSibling(t),n=J()._normalizedNodes;return n.add(o.__key),n.add(t.__key),e}function rl(o){let t=o;if(t.__text===""&&t.isSimpleText()&&!t.isUnmergeable()){t.remove();return}let e;for(;(e=t.getPreviousSibling())!==null&&L(e)&&e.isSimpleText()&&!e.isUnmergeable();)if(e.__text==="")e.remove();else if($d(e,t)){t=Pd(e,t);break}else break;let n;for(;(n=t.getNextSibling())!==null&&L(n)&&n.isSimpleText()&&!n.isUnmergeable();)if(n.__text==="")n.remove();else if($d(t,n)){t=Pd(t,n);break}else break}function Po(o){return Bd(o.anchor),Bd(o.focus),o}function Bd(o){for(;o.type==="element";){let t=o.getNode(),e=o.offset,n,r;if(e===t.getChildrenSize()?(n=t.getChildAtIndex(e-1),r=!0):(n=t.getChildAtIndex(e),r=!1),L(n)){o.set(n.__key,r?n.getTextContentSize():0,"text");break}else if(!T(n))break;o.set(n.__key,r?n.getChildrenSize():0,"element")}}var Bh=1;function Fh(){return""+Bh++}function Kd(o,t){let e=o._nodes.get(t);return e===void 0&&E(!1,"registeredNode: Type %s not found",t),e}var nC=Array.isArray,Ud=typeof queueMicrotask=="function"?queueMicrotask:o=>{Promise.resolve().then(o)};function zd(o){return F(ee(o))}function Ln(o){let t=document.activeElement;if(t===null)return!1;let e=t.nodeName;return F(ee(o))&&(e==="INPUT"||e==="TEXTAREA"||t.contentEditable==="true"&&Bo(t)==null)}function jt(o,t,e){let n=o.getRootElement();try{return n!==null&&n.contains(t)&&n.contains(e)&&t!==null&&!Ln(t)&&ci(t)===o}catch{return!1}}function Mn(o){return o instanceof eo}function ci(o){let t=o;for(;t!=null;){let e=Bo(t);if(Mn(e))return e;t=gi(t)}return null}function Bo(o){return o?o.__lexicalEditor:null}function qe(o){return o.isToken()||o.isSegmented()}function Hh(o){return o.nodeType===We}function wn(o){let t=o;for(;t!=null;){if(Hh(t))return t;t=t.firstChild}return null}function Nr(o,t,e){let n=Oe[t];if(e!==null&&(o&n)===(e&n))return o;let r=o^n;return t==="subscript"?r&=~Oe.superscript:t==="superscript"&&(r&=~Oe.subscript),r}function xr(o){return L(o)||Ae(o)||F(o)}function Wd(o,t){if(t!=null){__DEV__&&Kh(o,t),o.__key=t;return}ce(),pl();let e=J(),n=tt(),r=Fh();n._nodeMap.set(r,o),T(o)?e._dirtyElements.set(r,!0):e._dirtyLeaves.add(r),e._cloneNotNeeded.add(r),e._dirtyType=Gs,o.__key=r}function Kh(o,t){let e=vc();if(!e)return;let n=e._nodeMap.get(t);n&&n.constructor!==o.constructor&&(o.constructor.name!==n.constructor.name?E(!1,"Lexical node with constructor %s attempted to re-use key from node in active editor state with constructor %s. Keys must not be re-used when the type is changed.",o.constructor.name,n.constructor.name):E(!1,"Lexical node with constructor %s attempted to re-use key from node in active editor state with different constructor with the same name (possibly due to invalid Hot Module Replacement). Keys must not be re-used when the type is changed.",o.constructor.name))}function Uh(o,t,e){let n=o;for(;n!==null;){if(e.has(n))return;let r=t.get(n);if(r===void 0)break;e.set(n,!1),n=r.__parent}}function Gt(o){let t=o.getParent();if(t!==null){let e=o.getWritable(),n=t.getWritable(),r=o.getPreviousSibling(),i=o.getNextSibling();if(r===null)if(i!==null){let s=i.getWritable();n.__first=i.__key,s.__prev=null}else n.__first=null;else{let s=r.getWritable();if(i!==null){let l=i.getWritable();l.__prev=s.__key,s.__next=l.__key}else s.__next=null;e.__prev=null}if(i===null)if(r!==null){let s=r.getWritable();n.__last=r.__key,s.__next=null}else n.__last=null;else{let s=i.getWritable();if(r!==null){let l=r.getWritable();l.__next=s.__key,s.__prev=l.__key}else s.__prev=null;e.__next=null}n.__size--,e.__parent=null}}function hr(o){pl();let t=o.getLatest(),e=t.__parent,n=tt(),r=J(),i=n._nodeMap,s=r._dirtyElements;e!==null&&Uh(e,i,s);let l=t.__key;r._dirtyType=Gs,T(o)?s.set(l,!0):r._dirtyLeaves.add(l)}function qd(o){let t=o.getPreviousSibling(),e=o.getNextSibling();t!==null&&hr(t),e!==null&&hr(e)}function le(o){ce();let t=J(),e=t._compositionKey;if(o!==e){if(t._compositionKey=o,e!==null){let n=Q(e);n!==null&&n.getWritable()}if(o!==null){let n=Q(o);n!==null&&n.getWritable()}}}function et(){return ft()?null:J()._compositionKey}function Q(o,t){let n=(t||tt())._nodeMap.get(o);return n===void 0?null:n}function ol(o,t){let e=J(),n=o[`__lexicalKey_${e._key}`];return n!==void 0?Q(n,t):null}function ee(o,t){let e=o;for(;e!=null;){let n=ol(e,t);if(n!==null)return n;e=gi(e)}return null}function ui(o){let t=o._decorators,e=Object.assign({},t);return o._pendingDecorators=e,e}function sl(o){return o.read(()=>H().getTextContent())}function Yd(o,t){Ee(o,()=>{let e=tt();if(e.isEmpty())return;if(t==="root"){H().markDirty();return}let n=e._nodeMap;for(let[,r]of n)r.markDirty()},o._pendingEditorState===null?{tag:"history-merge"}:void 0)}function H(){return nl(tt())}function nl(o){return o._nodeMap.get("root")}function Y(o){ce();let t=tt();o!==null&&(__DEV__&&Object.isFrozen(o)&&E(!1,"$setSelection called on frozen selection object. Ensure selection is cloned before passing in."),o.dirty=!0,o.setCachedNodes(null)),t._selection=o}function Zd(){ce();let o=J();li(o)}function Fo(o){let t=J(),e=zh(o,t);if(e===null){let n=t.getRootElement();return o===n?Q("root"):null}return Q(e)}function ll(o,t){return t?o.getTextContentSize():0}function zh(o,t){let e=o;for(;e!=null;){let n=e[`__lexicalKey_${t._key}`];if(n!==void 0)return n;e=gi(e)}return null}function fi(o){return/[\uD800-\uDBFF][\uDC00-\uDFFF]/g.test(o)}function Er(o){let t=[],e=o;for(;e!==null;)t.push(e),e=e._parentEditor;return t}function al(){return Math.random().toString(36).replace(/[^a-z]+/g,"").substr(0,5)}function dl(o){return o.nodeType===We?o.nodeValue:null}function mi(o,t,e){let n=ye(t._window);if(n===null)return;let r=n.anchorNode,{anchorOffset:i,focusOffset:s}=n;if(r!==null){let l=dl(r),a=ee(r);if(l!==null&&L(a)){if(l===Cn&&e){let d=e.length;l=e,i=d,s=d}l!==null&&gr(a,l,i,s,o)}}}function gr(o,t,e,n,r){let i=o;if(i.isAttached()&&(r||!i.isDirty())){let s=i.isComposing(),l=t;(s||r)&&t[t.length-1]===Cn&&(l=t.slice(0,-1));let a=i.getTextContent();if(r||l!==a){if(l===""){if(le(null),!Zt&&!Lt&&!Vt){let h=J();setTimeout(()=>{h.update(()=>{i.isAttached()&&i.remove()})},20)}else i.remove();return}let d=i.getParent(),u=Ye(),m=i.getTextContentSize(),c=et(),f=i.getKey();if(i.isToken()||c!==null&&f===c&&!s||_(u)&&(d!==null&&!d.canInsertTextBefore()&&u.anchor.offset===0||u.anchor.key===o.__key&&u.anchor.offset===0&&!i.canInsertTextBefore()&&!s||u.focus.key===o.__key&&u.focus.offset===m&&!i.canInsertTextAfter()&&!s)){i.markDirty();return}let g=C();if(!_(g)||e===null||n===null){i.setTextContent(l);return}if(g.setTextNodeRange(i,e,i,n),i.isSegmented()){let h=i.getTextContent(),N=q(h);i.replace(N),i=N}i.setTextContent(l)}}}function Wh(o){let t=o.getPreviousSibling();return(L(t)||T(t)&&t.isInline())&&!t.canInsertTextAfter()}function Vd(o,t){if(t.isSegmented())return!0;if(!o.isCollapsed())return!1;let e=o.anchor.offset,n=t.getParentOrThrow(),r=t.isToken();return e===0?!t.canInsertTextBefore()||!n.canInsertTextBefore()&&!t.isComposing()||r||Wh(t):e===t.getTextContentSize()?!t.canInsertTextAfter()||!n.canInsertTextAfter()&&!t.isComposing()||r:!1}function Xd(o,t,e,n){return o==="Tab"&&!t&&!e&&!n}function jd(o,t,e,n){return o.toLowerCase()==="b"&&!t&&Tr(e,n)}function Gd(o,t,e,n){return o.toLowerCase()==="i"&&!t&&Tr(e,n)}function Jd(o,t,e,n){return o.toLowerCase()==="u"&&!t&&Tr(e,n)}function Qd(o,t){return bc(o)&&!t}function ec(o,t){return bc(o)&&t}function tc(o,t){return Ue&&t&&o.toLowerCase()==="o"}function oc(o,t,e){return _n(o)&&(Ue?t:e)}function nc(o,t,e){return yn(o)&&(Ue?t:e)}function rc(o,t){return Ue&&t&&_n(o)}function ic(o,t){return Ue&&t&&yn(o)}function sc(o,t,e,n){return Ue?t||e?!1:_n(o)||o.toLowerCase()==="h"&&n:n||t||e?!1:_n(o)}function lc(o,t,e,n,r){return Ue?e||n||r?!1:yn(o)||o.toLowerCase()==="d"&&t:t||n||r?!1:yn(o)}function ac(o,t,e,n){return o.toLowerCase()==="z"&&!t&&Tr(e,n)}function dc(o,t,e,n){return Ue?o.toLowerCase()==="z"&&e&&t:o.toLowerCase()==="y"&&n||o.toLowerCase()==="z"&&n&&t}function cc(o,t,e,n){return t?!1:o.toLowerCase()==="c"?Ue?e:n:!1}function uc(o,t,e,n){return t?!1:o.toLowerCase()==="x"?Ue?e:n:!1}function fc(o){return o==="ArrowLeft"}function mc(o){return o==="ArrowRight"}function qh(o){return o==="ArrowUp"}function Yh(o){return o==="ArrowDown"}function pc(o,t,e,n){return fc(o)&&!t&&!n&&!e}function gc(o,t,e,n,r){return fc(o)&&!n&&!e&&(t||r)}function hc(o,t,e,n){return mc(o)&&!t&&!n&&!e}function Nc(o,t,e,n,r){return mc(o)&&!n&&!e&&(t||r)}function xc(o,t,e){return qh(o)&&!t&&!e}function Ec(o,t,e){return Yh(o)&&!t&&!e}function Tc(o,t,e,n){return o||t||e||n}function Cc(o){return o===" "}function Tr(o,t){return Ue?o:t}function bc(o){return o==="Enter"}function _n(o){return o==="Backspace"}function _c(o){return o==="Escape"}function yn(o){return o==="Delete"}function cl(o,t,e){return o.toLowerCase()==="a"&&Tr(t,e)}function ul(){let o=H(),t=o.select(0,o.getChildrenSize());Y(Po(t))}function xo(o,t){o.__lexicalClassNameCache===void 0&&(o.__lexicalClassNameCache={});let e=o.__lexicalClassNameCache,n=e[t];if(n!==void 0)return n;let r=o[t];if(typeof r=="string"){let i=wt(r);return e[t]=i,i}return r}function pi(o,t,e,n,r){if(e.size===0)return;let i=n.__type,s=n.__key,l=t.get(i);l===void 0&&E(!1,"Type %s not in registeredNodes",i);let a=l.klass,d=o.get(a);d===void 0&&(d=new Map,o.set(a,d));let u=d.get(s),m=u==="destroyed"&&r==="created";(u===void 0||m)&&d.set(s,m?"updated":r)}function Fd(o,t,e){let n=o.getParent(),r=e,i=o;return n!==null&&(t&&e===0?(r=i.getIndexWithinParent(),i=n):!t&&e===i.getChildrenSize()&&(r=i.getIndexWithinParent()+1,i=n)),i.getChildAtIndex(t?r-1:r)}function Jt(o,t){let e=o.offset;if(o.type==="element"){let n=o.getNode();return Fd(n,t,e)}else{let n=o.getNode();if(t&&e===0||!t&&e===n.getTextContentSize()){let r=t?n.getPreviousSibling():n.getNextSibling();return r===null?Fd(n.getParentOrThrow(),t,n.getIndexWithinParent()+(t?0:1)):r}}return null}function di(o){let t=bn(o).event,e=t&&t.inputType;return e==="insertFromPaste"||e==="insertFromPasteAsQuotation"}function O(o,t,e){return gl(o,t,e)}function Cr(o){return!ne(o)&&!o.isLastChild()&&!o.isInline()}function vn(o,t){let e=o._keyToDOMMap.get(t);return e===void 0&&E(!1,"Reconciliation: could not find DOM element for node key %s",t),e}function gi(o){let t=o.assignedSlot||o.parentElement;return t!==null&&t.nodeType===11?t.host:t}function yc(o,t,e){let n=e.ownerDocument,r=n.defaultView;if(r===null)return;let{top:i,bottom:s}=t,l=0,a=0,d=e;for(;d!==null;){let u=d===n.body;if(u)l=0,a=bn(o).innerHeight;else{let c=d.getBoundingClientRect();l=c.top,a=c.bottom}let m=0;if(ia&&(m=s-a),m!==0)if(u)r.scrollBy(0,m);else{let c=d.scrollTop;d.scrollTop+=m;let f=d.scrollTop-c;i-=f,s-=f}if(u)break;d=gi(d)}}function Sc(o){let t=C();if(!_(t)||!T(o))return t;let{anchor:e,focus:n}=t,r=e.getNode(),i=n.getNode();return Sn(r,o)&&e.set(o.__key,0,"element"),Sn(i,o)&&n.set(o.__key,0,"element"),t}function Sn(o,t){let e=o.getParent();for(;e!==null;){if(e.is(t))return!0;e=e.getParent()}return!1}function Lc(o){let t=o.ownerDocument;return t&&t.defaultView||null}function bn(o){let t=o._window;return t===null&&E(!1,"window object not found"),t}function fl(o){let t=o.getParentOrThrow();for(;t!==null;){if(pe(t))return t;t=t.getParentOrThrow()}return t}var rC=Symbol.for("@lexical/ShadowRootNodeBrand");function pe(o){return ne(o)||T(o)&&o.isShadowRoot()}function re(o){let t=J(),e=o.constructor.getType(),n=t._nodes.get(e);n===void 0&&E(!1,'$initializeNode failed. Ensure node has been registered to the editor. You can do this by passing the node class via the "nodes" array in the editor config.');let r=n.replace;if(r!==null){let i=r(o);return i instanceof o.constructor||E(!1,"$initializeNode failed. Ensure replacement node is a subclass of the original node."),i}return o}function hi(o,t){let e=o.getParent();ne(e)&&!T(t)&&!F(t)&&E(!1,"Only element or decorator nodes can be inserted in to the root node")}function Zh(o){let t=o.theme,e=document.createElement("div");e.contentEditable="false",e.setAttribute("data-lexical-cursor","true");let n=t.blockCursor;if(n!==void 0){if(typeof n=="string"){let r=wt(n);n=t.blockCursor=r}n!==void 0&&e.classList.add(...n)}return e}function il(o){return(F(o)||T(o)&&!o.canBeEmpty())&&!o.isInline()}function br(o,t,e){e.style.removeProperty("caret-color"),t._blockCursorElement=null;let n=o.parentElement;n!==null&&n.removeChild(o)}function Mc(o,t,e){let n=o._blockCursorElement;if(_(e)&&e.isCollapsed()&&e.anchor.type==="element"&&t.contains(document.activeElement)){let r=e.anchor,i=r.getNode(),s=r.offset,l=i.getChildrenSize(),a=!1,d=null;if(s===l){let u=i.getChildAtIndex(s-1);il(u)&&(a=!0)}else{let u=i.getChildAtIndex(s);if(il(u)){let m=u.getPreviousSibling();(m===null||il(m))&&(a=!0,d=o.getElementByKey(u.__key))}}if(a){let u=o.getElementByKey(i.__key);n===null&&(o._blockCursorElement=n=Zh(o._config)),t.style.caretColor="transparent",d===null?u.appendChild(n):u.insertBefore(n,d);return}}n!==null&&br(n,o,t)}function ye(o){return me?(o||window).getSelection():null}function Ni(o){return ge(o)&&o.tagName==="A"}function ge(o){return o.nodeType===1}function Ho(o){let t=new RegExp(/^(a|abbr|acronym|b|cite|code|del|em|i|ins|kbd|label|output|q|ruby|s|samp|span|strong|sub|sup|time|u|tt|var|#text)$/,"i");return o.nodeName.match(t)!==null}function Eo(o){let t=new RegExp(/^(address|article|aside|blockquote|canvas|dd|div|dl|dt|fieldset|figcaption|figure|footer|form|h1|h2|h3|h4|h5|h6|header|hr|li|main|nav|noscript|ol|p|pre|section|table|td|tfoot|ul|video)$/,"i");return o.nodeName.match(t)!==null}function Ko(o){if(ne(o)||F(o)&&!o.isInline())return!0;if(!T(o)||pe(o))return!1;let t=o.getFirstChild(),e=t===null||Ae(t)||L(t)||t.isInline();return!o.isInline()&&o.canBeEmpty()!==!1&&e}function xi(o,t){let e=o;for(;e!==null&&e.getParent()!==null&&!t(e);)e=e.getParentOrThrow();return t(e)?e:null}function ml(){return J()}var Hd=new WeakMap,Vh=new Map;function wc(o){if(!o._readOnly&&o.isEmpty())return Vh;E(o._readOnly,"getCachedTypeToNodeMap called with a writable EditorState");let t=Hd.get(o);if(!t){t=new Map,Hd.set(o,t);for(let[e,n]of o._nodeMap){let r=n.__type,i=t.get(r);i||(i=new Map,t.set(r,i)),i.set(e,n)}}return t}function Qt(o){let t=o.constructor,e=t.clone(o);return e.afterCloneFrom(o),__DEV__&&(E(e.__key===o.__key,"$cloneWithProperties: %s.clone(node) (with type '%s') did not return a node with the same key, make sure to specify node.__key as the last argument to the constructor",t.name,t.getType()),E(e.__parent===o.__parent&&e.__next===o.__next&&e.__prev===o.__prev,"$cloneWithProperties: %s.clone(node) (with type '%s') overrided afterCloneFrom but did not call super.afterCloneFrom(prevNode)",t.name,t.getType())),e}function Dc(o,t){let e=o._decorators,r=o._pendingDecorators||e,i=t._nodeMap,s;for(s in r)i.has(s)||(r===e&&(r=ui(o)),delete r[s])}function Oc(o,t,e,n,r,i){let s=o.getFirstChild();for(;s!==null;){let l=s.__key;s.__parent===t&&(T(s)&&Oc(s,l,e,n,r,i),e.has(l)||i.delete(l),r.push(l)),s=s.getNextSibling()}}function Ac(o,t,e,n){let r=o._nodeMap,i=t._nodeMap,s=[];for(let[l]of n){let a=i.get(l);a!==void 0&&(a.isAttached()||(T(a)&&Oc(a,l,r,i,s,n),r.has(l)||n.delete(l),s.push(l)))}for(let l of s)i.delete(l);for(let l of e){let a=i.get(l);a!==void 0&&!a.isAttached()&&(r.has(l)||e.delete(l),i.delete(l))}}var ue="",To=null,mt="",to="",Dn,Se,yr,kc=!1,Ti=!1,Ci,Nl,xl,Uo,pt,El,Sr;function bi(o,t){let e=Uo.get(o);if(t!==null){let n=bl(o);n.parentNode===t&&t.removeChild(n)}if(pt.has(o)||Se._keyToDOMMap.delete(o),T(e)){let n=Ei(e,Uo);Tl(n,0,n.length-1,null)}e!==void 0&&pi(Sr,yr,Ci,e,"destroyed")}function Tl(o,t,e,n){let r=t;for(;r<=e;++r){let i=o[r];i!==void 0&&bi(i,n)}}function _i(o,t,e){let n=pt.get(o);n===void 0&&E(!1,"createNode: node does not exist in nodeMap");let r=n.createDOM(Dn,Se);if(tN(o,r,Se),L(n)?r.setAttribute("data-lexical-text","true"):F(n)&&r.setAttribute("data-lexical-decorator","true"),T(n)){let i=n.__size;if(i!==0){let s=i-1,l=Ei(n,pt);Cl(l,n,0,s,r,null)}n.isInline()||Ic(null,n,r),Cr(n)&&(ue+=Qe,to+=Qe)}else{let i=n.getTextContent();if(F(n)){let s=n.decorate(Se,Dn);s!==null&&$c(o,s),r.contentEditable="false"}ue+=i,to+=i}if(t!==null&&!n?.insertDOMIntoParent(r,t))if(e!=null)t.insertBefore(r,e);else{let s=t.__lexicalLineBreak;s!=null?t.insertBefore(r,s):t.appendChild(r)}return __DEV__&&Object.freeze(n),pi(Sr,yr,Ci,n,"created"),r}function Cl(o,t,e,n,r,i){let s=ue;ue="";let l=e;for(;l<=n;++l){_i(o[l],r,i);let a=pt.get(o[l]);a!==null&&L(a)&&(To===null&&(To=a.getFormat()),mt===""&&(mt=a.getStyle()))}Cr(t)&&(ue+=Qe),r.__lexicalTextContent=ue,ue=s+ue}function Rc(o,t){let e=t.get(o);return Ae(e)||F(e)&&e.isInline()}function Ic(o,t,e){let n=o!==null&&(o.__size===0||Rc(o.__last,Uo)),r=t.__size===0||Rc(t.__last,pt);if(n){if(!r){let i=e.__lexicalLineBreak;if(i!=null)try{e.removeChild(i)}catch(s){if(typeof s=="object"&&s!=null){let l=`${s.toString()} Parent: ${e.tagName}, child: ${i.tagName}.`;throw new Error(l)}else throw s}e.__lexicalLineBreak=null}}else if(r){let i=document.createElement("br");e.__lexicalLineBreak=i,e.appendChild(i)}}function Xh(o){Ze(o)&&To!=null&&!Ti&&o.setTextStyle(mt)}function jh(o){Ze(o)&&mt!==""&&mt!==o.__textStyle&&!Ti&&o.setTextStyle(mt)}function Gh(o,t,e){To=null,mt="",Jh(o,t,e),Xh(t),jh(t)}function Ei(o,t){let e=[],n=o.__first;for(;n!==null;){let r=t.get(n);r===void 0&&E(!1,"createChildrenArray: node does not exist in nodeMap"),e.push(n),n=r.__next}return e}function Jh(o,t,e){let n=ue,r=o.__size,i=t.__size;if(ue="",r===1&&i===1){let s=o.__first,l=t.__first;if(s===l)_r(s,e);else{let d=bl(s),u=_i(l,null,null);try{e.replaceChild(u,d)}catch(m){if(typeof m=="object"&&m!=null){let c=`${m.toString()} Parent: ${e.tagName}, new child: {tag: ${u.tagName} key: ${l}}, old child: {tag: ${d.tagName}, key: ${s}}.`;throw new Error(c)}else throw m}bi(s,null)}let a=pt.get(l);L(a)&&(To===null&&(To=a.getFormat()),mt===""&&(mt=a.getStyle()))}else{let s=Ei(o,Uo),l=Ei(t,pt);if(r===0)i!==0&&Cl(l,t,0,i-1,e,null);else if(i===0){if(r!==0){let d=e.__lexicalLineBreak==null;Tl(s,0,r-1,d?null:e),d&&(e.textContent="")}}else eN(t,s,l,r,i,e)}Cr(t)&&(ue+=Qe),e.__lexicalTextContent=ue,ue=n+ue}function _r(o,t){let e=Uo.get(o),n=pt.get(o);(e===void 0||n===void 0)&&E(!1,"reconcileNode: prevNode or nextNode does not exist in nodeMap");let r=kc||xl.has(o)||Nl.has(o),i=vn(Se,o);if(e===n&&!r){if(T(e)){let s=i.__lexicalTextContent;s!==void 0&&(ue+=s,to+=s)}else{let s=e.getTextContent();to+=s,ue+=s}return i}if(e!==n&&r&&pi(Sr,yr,Ci,n,"updated"),n.updateDOM(e,i,Dn)){let s=_i(o,null,null);return t===null&&E(!1,"reconcileNode: parentDOM is null"),t.replaceChild(s,i),bi(o,null),s}if(T(e)&&T(n))r&&(Gh(e,n,i),!ne(n)&&!n.isInline()&&Ic(e,n,i)),Cr(n)&&(ue+=Qe,to+=Qe);else{let s=n.getTextContent();if(F(n)){let l=n.decorate(Se,Dn);l!==null&&$c(o,l)}ue+=s,to+=s}if(!Ti&&ne(n)&&n.__cachedText!==to){let s=n.getWritable();s.__cachedText=to,n=s}return __DEV__&&Object.freeze(n),i}function $c(o,t){let e=Se._pendingDecorators,n=Se._decorators;if(e===null){if(n[o]===t)return;e=ui(Se)}e[o]=t}function Qh(o){return o.firstChild}function hl(o){let t=o.nextSibling;return t!==null&&t===Se._blockCursorElement&&(t=t.nextSibling),t}function eN(o,t,e,n,r,i){let s=n-1,l=r-1,a,d,u=Qh(i),m=0,c=0;for(;m<=s&&c<=l;){let h=t[m],N=e[c];if(h===N)u=hl(_r(N,i)),m++,c++;else{a===void 0&&(a=new Set(t)),d===void 0&&(d=new Set(e));let x=d.has(h),S=a.has(N);if(!x)u=hl(bl(h)),bi(h,i),m++;else if(!S)_i(N,i,u),c++;else{let v=vn(Se,N);v===u?u=hl(_r(N,i)):(u!=null?i.insertBefore(v,u):i.appendChild(v),_r(N,i)),m++,c++}}let b=pt.get(N);b!==null&&L(b)&&(To===null&&(To=b.getFormat()),mt===""&&(mt=b.getStyle()))}let f=m>s,g=c>l;if(f&&!g){let h=e[l+1],N=h===void 0?null:Se.getElementByKey(h);Cl(e,o,c,l,i,N)}else g&&!f&&Tl(t,m,s,i)}function Pc(o,t,e,n,r,i){ue="",to="",kc=n===Xt,Se=e,Dn=e._config,yr=e._nodes,Ci=Se._listeners.mutation,Nl=r,xl=i,Uo=o._nodeMap,pt=t._nodeMap,Ti=t._readOnly,El=new Map(e._keyToDOMMap);let s=new Map;return Sr=s,_r("root",null),Se=void 0,yr=void 0,Nl=void 0,xl=void 0,Uo=void 0,pt=void 0,Dn=void 0,El=void 0,Sr=void 0,s}function tN(o,t,e){let n=e._keyToDOMMap;t["__lexicalKey_"+e._key]=o,n.set(o,t)}function bl(o){let t=El.get(o);return t===void 0&&E(!1,"Reconciliation: could not find DOM element for node key %s",o),t}var oo=Object.freeze({}),Ml=30,_l=[["keydown",cN],["pointerdown",nN],["compositionstart",aN],["compositionend",dN],["input",lN],["click",oN],["cut",oo],["copy",oo],["dragstart",oo],["dragover",oo],["dragend",oo],["paste",oo],["focus",oo],["blur",oo],["drop",oo]];ho&&_l.push(["beforeinput",(o,t)=>sN(o,t)]);var wr=0,Uc=null,zc=0,On=null,yi=new WeakMap,yl=!1,Sl=!1,Mr=!1,Lr=!1,Wc=[0,"",0,"root",0];function qc(o,t,e,n,r){let i=o.anchor,s=o.focus,l=i.getNode(),a=J(),d=ye(a._window),u=d!==null?d.anchorNode:null,m=i.key,c=a.getElementByKey(m),f=e.length;return m!==s.key||!L(l)||(!r&&(!ho||zc1||(r||!ho)&&c!==null&&!l.isComposing()&&u!==wn(c)||d!==null&&t!==null&&(!t.collapsed||t.startContainer!==d.anchorNode||t.startOffset!==d.anchorOffset)||l.getFormat()!==o.format||l.getStyle()!==o.style||Vd(o,l)}function Bc(o,t){return o!==null&&o.nodeValue!==null&&o.nodeType===We&&t!==0&&t!==o.nodeValue.length}function Fc(o,t,e){let{anchorNode:n,anchorOffset:r,focusNode:i,focusOffset:s}=o;yl&&(yl=!1,Bc(n,r)&&Bc(i,s))||Ee(t,()=>{if(!e){Y(null);return}if(!jt(t,n,i))return;let l=C();if(_(l)){let a=l.anchor,d=a.getNode();if(l.isCollapsed()){o.type==="Range"&&o.anchorNode===o.focusNode&&(l.dirty=!0);let u=bn(t).event,m=u?u.timeStamp:performance.now(),[c,f,g,h,N]=Wc,b=H(),x=t.isComposing()===!1&&b.getTextContent()==="";if(m{let e=C(),n=ye(t._window),r=Ye();if(n){if(_(e)){let i=e.anchor,s=i.getNode();if(i.type==="element"&&i.offset===0&&e.isCollapsed()&&!ne(s)&&H().getChildrenSize()===1&&s.getTopLevelElementOrThrow().isEmpty()&&r!==null&&e.is(r))n.removeAllRanges(),e.dirty=!0;else if(o.detail===3&&!e.isCollapsed()){let a=e.focus.getNode();s!==a&&(T(s)?s.select(0):s.getParentOrThrow().select(0))}}else if(o.pointerType==="touch"){let i=n.anchorNode;if(i!==null){let s=i.nodeType;if(s===No||s===We){let l=vr(r,n,t,o);Y(l)}}}}O(t,Ht,o)})}function nN(o,t){let e=o.target,n=o.pointerType;e instanceof Node&&n!=="touch"&&Ee(t,()=>{zd(e)||(Sl=!0)})}function Yc(o){if(!o.getTargetRanges)return null;let t=o.getTargetRanges();return t.length===0?null:t[0]}function rN(o,t){return o!==t||T(o)||T(t)||!o.isToken()||!t.isToken()}function iN(o){return Uc==="MediaLast"&&o{let r=C();if(e==="deleteContentBackward"){if(r===null){let u=Ye();if(!_(u))return;Y(u.clone())}if(_(r)){let u=r.anchor.key===r.focus.key;if(iN(o.timeStamp)&&t.isComposing()&&u){if(le(null),wr=0,setTimeout(()=>{Ee(t,()=>{le(null)})},Ml),_(r)){let m=r.anchor.getNode();m.markDirty(),E(L(m),"Anchor node must be a TextNode"),r.style=m.getStyle()}}else{le(null),o.preventDefault();let m=r.anchor.getNode().getTextContent(),c=r.anchor.offset===0&&r.focus.offset===m.length;js&&u&&!c||O(t,Je,!0)}return}}if(!_(r))return;let i=o.data;On!==null&&mi(!1,t,On),(!r.dirty||On!==null)&&r.isCollapsed()&&!ne(r.anchor.getNode())&&n!==null&&r.applyDOMRange(n),On=null;let s=r.anchor,l=r.focus,a=s.getNode(),d=l.getNode();if(e==="insertText"||e==="insertTranspose"){if(i===` `)o.preventDefault(),O(t,Kt,!1);else if(i===Qe)o.preventDefault(),O(t,Ut,void 0);else if(i==null&&o.dataTransfer){let u=o.dataTransfer.getData("text/plain");o.preventDefault(),r.insertRawText(u)}else i!=null&&qc(r,n,i,o.timeStamp,!0)?(o.preventDefault(),O(t,ct,i)):On=i;zc=o.timeStamp;return}switch(o.preventDefault(),e){case"insertFromYank":case"insertFromDrop":case"insertReplacementText":{O(t,ct,o);break}case"insertFromComposition":{le(null),O(t,ct,o);break}case"insertLineBreak":{le(null),O(t,Kt,!1);break}case"insertParagraph":{le(null),Mr&&!Lt?(Mr=!1,O(t,Kt,!1)):O(t,Ut,void 0);break}case"insertFromPaste":case"insertFromPasteAsQuotation":{O(t,ao,o);break}case"deleteByComposition":{rN(a,d)&&O(t,hn,o);break}case"deleteByDrag":case"deleteByCut":{O(t,hn,o);break}case"deleteContent":{O(t,Je,!1);break}case"deleteWordBackward":{O(t,St,!0);break}case"deleteWordForward":{O(t,St,!1);break}case"deleteHardLineBackward":case"deleteSoftLineBackward":{O(t,ut,!0);break}case"deleteContentForward":case"deleteHardLineForward":case"deleteSoftLineForward":{O(t,ut,!1);break}case"formatStrikeThrough":{O(t,xe,"strikethrough");break}case"formatBold":{O(t,xe,"bold");break}case"formatItalic":{O(t,xe,"italic");break}case"formatUnderline":{O(t,xe,"underline");break}case"historyUndo":{O(t,co,void 0);break}case"historyRedo":{O(t,uo,void 0);break}default:}})}function lN(o,t){o.stopPropagation(),Ee(t,()=>{let e=C(),n=o.data,r=Yc(o);if(n!=null&&_(e)&&qc(e,r,n,o.timeStamp,!1)){Lr&&(Ll(t,n),Lr=!1);let s=e.anchor.getNode(),l=ye(t._window);if(l===null)return;let a=e.isBackward(),d=a?e.anchor.offset:e.focus.offset,u=a?e.focus.offset:e.anchor.offset;(!ho||e.isCollapsed()||!L(s)||l.anchorNode===null||s.getTextContent().slice(0,d)+n+s.getTextContent().slice(d+u)!==dl(l.anchorNode))&&O(t,ct,n);let m=n.length;ze&&m>1&&o.inputType==="insertCompositionText"&&!t.isComposing()&&(e.anchor.offset-=m),!Zt&&!Lt&&!Vt&&t.isComposing()&&(wr=0,le(null))}else mi(!1,t,n!==null?n:void 0),Lr&&(Ll(t,n||void 0),Lr=!1);Zd()}),On=null}function aN(o,t){Ee(t,()=>{let e=C();if(_(e)&&!t.isComposing()){let n=e.anchor,r=e.anchor.getNode();le(n.key),(o.timeStamp{Ll(t,o.data)})}function cN(o,t){if(wr=o.timeStamp,Uc=o.key,t.isComposing())return;let{key:e,shiftKey:n,ctrlKey:r,metaKey:i,altKey:s}=o;if(!O(t,Hs,o)&&e!=null){if(hc(e,r,s,i))O(t,Ao,o);else if(Nc(e,r,n,s,i))O(t,Ks,o);else if(pc(e,r,s,i))O(t,Ro,o);else if(gc(e,r,n,s,i))O(t,Us,o);else if(xc(e,r,i))O(t,zt,o);else if(Ec(e,r,i))O(t,Wt,o);else if(ec(e,n))Mr=!0,O(t,Ke,o);else if(Cc(e))O(t,ir,o);else if(tc(e,r))o.preventDefault(),Mr=!0,O(t,Kt,!0);else if(Qd(e,n))Mr=!1,O(t,Ke,o);else if(sc(e,s,i,r))_n(e)?O(t,qt,o):(o.preventDefault(),O(t,Je,!0));else if(_c(e))O(t,ko,o);else if(lc(e,r,n,s,i))yn(e)?O(t,Yt,o):(o.preventDefault(),O(t,Je,!1));else if(oc(e,s,r))o.preventDefault(),O(t,St,!0);else if(nc(e,s,r))o.preventDefault(),O(t,St,!1);else if(rc(e,i))o.preventDefault(),O(t,ut,!0);else if(ic(e,i))o.preventDefault(),O(t,ut,!1);else if(jd(e,s,i,r))o.preventDefault(),O(t,xe,"bold");else if(Jd(e,s,i,r))o.preventDefault(),O(t,xe,"underline");else if(Gd(e,s,i,r))o.preventDefault(),O(t,xe,"italic");else if(Xd(e,s,r,i))O(t,Io,o);else if(ac(e,n,i,r))o.preventDefault(),O(t,co,void 0);else if(dc(e,n,i,r))o.preventDefault(),O(t,uo,void 0);else{let l=t._editorState._selection;Le(l)?cc(e,n,i,r)?(o.preventDefault(),O(t,fo,o)):uc(e,n,i,r)?(o.preventDefault(),O(t,mo,o)):cl(e,i,r)&&(o.preventDefault(),O(t,Nn,o)):!ze&&cl(e,i,r)&&(o.preventDefault(),O(t,Nn,o))}Tc(r,n,s,i)&&O(t,Vs,o)}}function Zc(o){let t=o.__lexicalEventHandles;return t===void 0&&(t=[],o.__lexicalEventHandles=t),t}var An=new Map;function Vc(o){let t=o.target,e=t==null?null:t.nodeType===9?t.defaultView:t.ownerDocument.defaultView,n=ye(e);if(n===null)return;let r=ci(n.anchorNode);if(r===null)return;Sl&&(Sl=!1,Ee(r,()=>{let u=Ye(),m=n.anchorNode;if(m===null)return;let c=m.nodeType;if(c!==No&&c!==We)return;let f=vr(u,n,r,o);Y(f)}));let i=Er(r),s=i[i.length-1],l=s._key,a=An.get(l),d=a||s;d!==r&&Fc(n,d,!1),Fc(n,r,!0),r!==s?An.set(l,r):a&&An.delete(l)}function Hc(o){o._lexicalHandled=!0}function Kc(o){return o._lexicalHandled===!0}function Xc(o,t){let e=o.ownerDocument,n=yi.get(e);(n===void 0||n<1)&&e.addEventListener("selectionchange",Vc),yi.set(e,(n||0)+1),o.__lexicalEditor=t;let r=Zc(o);for(let i=0;i<_l.length;i++){let[s,l]=_l[i],a=typeof l=="function"?d=>{Kc(d)||(Hc(d),(t.isEditable()||s==="click")&&l(d,t))}:d=>{if(Kc(d))return;Hc(d);let u=t.isEditable();switch(s){case"cut":return u&&O(t,mo,d);case"copy":return O(t,fo,d);case"paste":return u&&O(t,ao,d);case"dragstart":return u&&O(t,sr,d);case"dragover":return u&&O(t,lr,d);case"dragend":return u&&O(t,Ws,d);case"focus":return u&&O(t,ar,d);case"blur":return u&&O(t,Zs,d);case"drop":return u&&O(t,$o,d)}};o.addEventListener(s,a),r.push(()=>{o.removeEventListener(s,a)})}}function jc(o){let t=o.ownerDocument,e=yi.get(t);E(e!==void 0,"Root element not registered");let n=e-1;E(n>=0,"Root element count less than 0"),yi.set(t,n),n===0&&t.removeEventListener("selectionchange",Vc);let r=Bo(o);Mn(r)?(uN(r),o.__lexicalEditor=null):r&&E(!1,"Attempted to remove event handlers from a node that does not belong to this build of Lexical");let i=Zc(o);for(let s=0;si.__key===this.__key);if(L(this))return n;if(_(e)&&e.anchor.type==="element"&&e.focus.type==="element"){if(e.isCollapsed())return!1;let i=this.getParent();if(F(this)&&this.isInline()&&i){let s=e.isBackward()?e.focus:e.anchor,l=s.getNode();if(s.offset===l.getChildrenSize()&&l.is(i)&&l.getLastChildOrThrow().is(this))return!1}}return n}getKey(){return this.__key}getIndexWithinParent(){let t=this.getParent();if(t===null)return-1;let e=t.getFirstChild(),n=0;for(;e!==null;){if(this.is(e))return n;n++,e=e.getNextSibling()}return-1}getParent(){let t=this.getLatest().__parent;return t===null?null:Q(t)}getParentOrThrow(){let t=this.getParent();return t===null&&E(!1,"Expected node %s to have a parent.",this.__key),t}getTopLevelElement(){let t=this;for(;t!==null;){let e=t.getParent();if(pe(e))return E(T(t)||t===this&&F(t),"Children of root nodes must be elements or decorators"),t;t=e}return null}getTopLevelElementOrThrow(){let t=this.getTopLevelElement();return t===null&&E(!1,"Expected node %s to have a top parent element.",this.__key),t}getParents(){let t=[],e=this.getParent();for(;e!==null;)t.push(e),e=e.getParent();return t}getParentKeys(){let t=[],e=this.getParent();for(;e!==null;)t.push(e.__key),e=e.getParent();return t}getPreviousSibling(){let e=this.getLatest().__prev;return e===null?null:Q(e)}getPreviousSiblings(){let t=[],e=this.getParent();if(e===null)return t;let n=e.getFirstChild();for(;n!==null&&!n.is(this);)t.push(n),n=n.getNextSibling();return t}getNextSibling(){let e=this.getLatest().__next;return e===null?null:Q(e)}getNextSiblings(){let t=[],e=this.getNextSibling();for(;e!==null;)t.push(e),e=e.getNextSibling();return t}getCommonAncestor(t){let e=this.getParents(),n=t.getParents();T(this)&&e.unshift(this),T(t)&&n.unshift(t);let r=e.length,i=n.length;if(r===0||i===0||e[r-1]!==n[i-1])return null;let s=new Set(n);for(let l=0;l{l.append(h)})),_(n)){Y(n);let h=n.anchor,N=n.focus;h.key===i&&vl(h,l),N.key===i&&vl(N,l)}return et()===i&&le(s),l}insertAfter(t,e=!0){ce(),hi(this,t);let n=this.getWritable(),r=t.getWritable(),i=r.getParent(),s=C(),l=!1,a=!1;if(i!==null){let f=t.getIndexWithinParent();if(Gt(r),_(s)){let g=i.__key,h=s.anchor,N=s.focus;l=h.type==="element"&&h.key===g&&h.offset===f+1,a=N.type==="element"&&N.key===g&&N.offset===f+1}}let d=this.getNextSibling(),u=this.getParentOrThrow().getWritable(),m=r.__key,c=n.__next;if(d===null)u.__last=m;else{let f=d.getWritable();f.__prev=m}if(u.__size++,n.__next=m,r.__next=c,r.__prev=n.__key,r.__parent=n.__parent,e&&_(s)){let f=this.getIndexWithinParent();Rn(s,u,f+1);let g=u.__key;l&&s.anchor.set(g,f+2,"element"),a&&s.focus.set(g,f+2,"element")}return t}insertBefore(t,e=!0){ce(),hi(this,t);let n=this.getWritable(),r=t.getWritable(),i=r.__key;Gt(r);let s=this.getPreviousSibling(),l=this.getParentOrThrow().getWritable(),a=n.__prev,d=this.getIndexWithinParent();if(s===null)l.__first=i;else{let m=s.getWritable();m.__next=i}l.__size++,n.__prev=i,r.__prev=a,r.__next=n.__key,r.__parent=n.__parent;let u=C();if(e&&_(u)){let m=this.getParentOrThrow();Rn(u,m,d)}return t}isParentRequired(){return!1}createParentElementNode(){return I()}selectStart(){return this.selectPrevious()}selectEnd(){return this.selectNext(0,0)}selectPrevious(t,e){ce();let n=this.getPreviousSibling(),r=this.getParentOrThrow();if(n===null)return r.select(0,0);if(T(n))return n.select();if(!L(n)){let i=n.getIndexWithinParent()+1;return r.select(i,i)}return n.select(t,e)}selectNext(t,e){ce();let n=this.getNextSibling(),r=this.getParentOrThrow();if(n===null)return r.select();if(T(n))return n.select(0,0);if(!L(n)){let i=n.getIndexWithinParent();return r.select(i,i)}return n.select(t,e)}markDirty(){this.getWritable()}insertDOMIntoParent(t,e){return!1}};p(gt,"importDOM");function fN(o,t){let e=J()._nodes.get(o);e===void 0&&E(!1,"Create node: Attempted to create node %s that was not configured to be used on the editor.",t.name);let n=e.klass;n!==t&&E(!1,"Create node: Type %s in node %s does not match registered node %s with the same type",o,t.name,n.name)}function Qc(o,t,e){let n=e||t.getParentOrThrow().getLastChild(),r=t,i=[t];for(;r!==n;)r.getNextSibling()||E(!1,"insertRangeAfter: lastToInsert must be a later sibling of firstToInsert"),r=r.getNextSibling(),i.push(r);let s=o;for(let l of i)s=s.insertAfter(l)}var zo=class o extends gt{static getType(){return"linebreak"}static clone(t){return new o(t.__key)}constructor(t){super(t)}getTextContent(){return` `}createDOM(){return document.createElement("br")}updateDOM(){return!1}static importDOM(){return{br:t=>pN(t)||gN(t)?null:{conversion:mN,priority:0}}}static importJSON(t){return ht()}exportJSON(){return{type:"linebreak",version:1}}};function mN(o){return{node:ht()}}function ht(){return re(new zo)}function Ae(o){return o instanceof zo}function pN(o){let t=o.parentElement;if(t!==null&&Eo(t)){let e=t.firstChild;if(e===o||e.nextSibling===o&&Si(e)){let n=t.lastChild;if(n===o||n.previousSibling===o&&Si(n))return!0}}return!1}function gN(o){let t=o.parentElement;if(t!==null&&Eo(t)){let e=t.firstChild;if(e===o||e.nextSibling===o&&Si(e))return!1;let n=t.lastChild;if(n===o||n.previousSibling===o&&Si(n))return!0}return!1}function Si(o){return o.nodeType===We&&/^( |\t|\r?\n)+$/.test(o.textContent||"")}function Dl(o,t){return t&ur?"code":t&pr?"mark":t&fr?"sub":t&mr?"sup":null}function Ol(o,t){return t&dr?"strong":t&cr?"em":"span"}function nu(o,t,e,n,r){let i=n.classList,s=xo(r,"base");s!==void 0&&i.add(...s),s=xo(r,"underlineStrikethrough");let l=!1,a=t&En&&t&xn,d=e&En&&e&xn;s!==void 0&&(d?(l=!0,a||i.add(...s)):a&&i.remove(...s));for(let u in Oe){let c=Oe[u];if(s=xo(r,u),s!==void 0)if(e&c){if(l&&(u==="underline"||u==="strikethrough")){t&c&&i.remove(...s);continue}((t&c)===0||a&&u==="underline"||u==="strikethrough")&&i.add(...s)}else t&c&&i.remove(...s)}}function hN(o,t){let e=o.length,n=t.length,r=0,i=0;for(;r({conversion:CN,priority:0}),b:()=>({conversion:xN,priority:0}),code:()=>({conversion:Co,priority:0}),em:()=>({conversion:Co,priority:0}),i:()=>({conversion:Co,priority:0}),s:()=>({conversion:Co,priority:0}),span:()=>({conversion:NN,priority:0}),strong:()=>({conversion:Co,priority:0}),sub:()=>({conversion:Co,priority:0}),sup:()=>({conversion:Co,priority:0}),u:()=>({conversion:Co,priority:0})}}static importJSON(e){let n=q(e.text);return n.setFormat(e.format),n.setDetail(e.detail),n.setMode(e.mode),n.setStyle(e.style),n}exportDOM(e){let{element:n}=super.exportDOM(e),r=(n?.nodeName||"").toLowerCase();E(n!==null&&ge(n),"Expected TextNode createDOM to always return a HTMLElement");let i=this.getTextContent();/^\s|\s$/.test(i)&&(n.style.whiteSpace="pre-wrap");for(let s of Array.from(n.classList.values()))s.startsWith("editor-theme-")&&n.classList.remove(s);return n.classList.length===0&&n.removeAttribute("class"),n.nodeName==="SPAN"&&!n.getAttribute("style")&&(n=document.createTextNode(i)),this.hasFormat("bold")&&r!=="strong"&&(n=Li(n,"strong")),this.hasFormat("italic")&&(n=Li(n,"em")),this.hasFormat("strikethrough")&&(n=Li(n,"s")),this.hasFormat("underline")&&(n=Li(n,"u")),{element:n}}exportJSON(){return{detail:this.getDetail(),format:this.getFormat(),mode:this.getMode(),style:this.getStyle(),text:this.getTextContent(),type:"text",version:1}}selectionTransform(e,n){}setFormat(e){let n=this.getWritable();return n.__format=typeof e=="string"?Oe[e]:e,n}setDetail(e){let n=this.getWritable();return n.__detail=typeof e=="string"?Od[e]:e,n}setStyle(e){let n=this.getWritable();return n.__style=e,n}toggleFormat(e){let n=this.getFormat(),r=Nr(n,e,null);return this.setFormat(r)}toggleDirectionless(){let e=this.getWritable();return e.__detail^=si,e}toggleUnmergeable(){let e=this.getWritable();return e.__detail^=Tn,e}setMode(e){let n=Ad[e];if(this.__mode===n)return this;let r=this.getWritable();return r.__mode=n,r}setTextContent(e){if(this.__text===e)return this;let n=this.getWritable();return n.__text=e,n}select(e,n){ce();let r=e,i=n,s=C(),l=this.getTextContent(),a=this.__key;if(typeof l=="string"){let d=l.length;r===void 0&&(r=d),i===void 0&&(i=d)}else r=0,i=0;if(_(s)){let d=et();(d===s.anchor.key||d===s.focus.key)&&le(a),s.setTextNodeRange(this,r,this,i)}else return Mi(a,r,a,i,"text","text");return s}selectStart(){return this.select(0,0)}selectEnd(){let e=this.getTextContentSize();return this.select(e,e)}spliceText(e,n,r,i){let s=this.getWritable(),l=s.__text,a=r.length,d=e;d<0&&(d=a+d,d<0&&(d=0));let u=C();if(i&&_(u)){let c=e+a;u.setTextNodeRange(s,c,s,c)}let m=l.slice(0,d)+r+l.slice(d+n);return s.__text=m,s}canInsertTextBefore(){return!0}canInsertTextAfter(){return!0}splitText(...e){ce();let n=this.getLatest(),r=n.getTextContent(),i=n.__key,s=et(),l=new Set(e),a=[],d=r.length,u="";for(let R=0;RM&&se.offset<=j&&(se.key=k,se.offset-=M,S.dirty=!0),Fe.key===i&&Fe.type==="text"&&Fe.offset>M&&Fe.offset<=j&&(Fe.key=k,Fe.offset-=M,S.dirty=!0)}s===i&&le(k),M=j,v.push(B)}if(f!==null){qd(this);let R=f.getWritable(),A=this.getIndexWithinParent();x?(R.splice(A,0,v),this.remove()):R.splice(A,1,v),_(S)&&Rn(S,f,A,m-1)}return v}mergeWithSibling(e){let n=e===this.getPreviousSibling();!n&&e!==this.getNextSibling()&&E(!1,"mergeWithSibling: sibling must be a previous or next sibling");let r=this.__key,i=e.__key,s=this.__text,l=s.length;et()===i&&le(r);let d=C();if(_(d)){let f=d.anchor,g=d.focus;f!==null&&f.key===i&&(Al(f,n,r,e,l),d.dirty=!0),g!==null&&g.key===i&&(Al(g,n,r,e,l),d.dirty=!0)}let u=e.__text,m=n?u+s:s+u;this.setTextContent(m);let c=this.getWritable();return e.remove(),c}isTextEntity(){return!1}};function NN(o){let e=o.style;return{forChild:Rl(e),node:null}}function xN(o){let t=o,e=t.style.fontWeight==="normal";return{forChild:Rl(t.style,e?void 0:"bold"),node:null}}var tu=new WeakMap;function EN(o){return o.nodeName==="PRE"||o.nodeType===No&&o.style!==void 0&&o.style.whiteSpace!==void 0&&o.style.whiteSpace.startsWith("pre")}function TN(o){let t,e=o.parentNode,n=[o];for(;e!==null&&(t=tu.get(e))===void 0&&!EN(e);)n.push(e),e=e.parentNode;let r=t===void 0?e:t;for(let i=0;i0){/[ \t\n]$/.test(s)&&(n=n.slice(1)),i=!1;break}}i&&(n=n.slice(1))}if(n[n.length-1]===" "){let r=t,i=!0;for(;r!==null&&(r=ou(r,!0))!==null;)if((r.textContent||"").replace(/^( |\t|\r?\n)+/,"").length>0){i=!1;break}i&&(n=n.slice(0,n.length-1))}return n===""?{node:null}:{node:q(n)}}function ou(o,t){let e=o;for(;;){let n;for(;(n=t?e.nextSibling:e.previousSibling)===null;){let i=e.parentElement;if(i===null)return null;e=i}if(e=n,e.nodeType===No){let i=e.style.display;if(i===""&&!Ho(e)||i!==""&&!i.startsWith("inline"))return null}let r=e;for(;(r=t?e.firstChild:e.lastChild)!==null;)e=r;if(e.nodeType===We)return e;if(e.nodeName==="BR")return null}}var bN={code:"code",em:"italic",i:"italic",s:"strikethrough",strong:"bold",sub:"subscript",sup:"superscript",u:"underline"};function Co(o){let t=bN[o.nodeName.toLowerCase()];return t==="code"&&o.closest("pre")?{node:null}:t===void 0?{node:null}:{forChild:Rl(o.style,t),node:null}}function q(o=""){return re(new nt(o))}function L(o){return o instanceof nt}function Rl(o,t){let e=o.fontWeight,n=o.textDecoration.split(" "),r=e==="700"||e==="bold",i=n.includes("line-through"),s=o.fontStyle==="italic",l=n.includes("underline"),a=o.verticalAlign,d=o.color,u=o.backgroundColor;return m=>{if(!L(m))return m;r&&!m.hasFormat("bold")&&m.toggleFormat("bold"),i&&!m.hasFormat("strikethrough")&&m.toggleFormat("strikethrough"),s&&!m.hasFormat("italic")&&m.toggleFormat("italic"),l&&!m.hasFormat("underline")&&m.toggleFormat("underline"),a==="sub"&&!m.hasFormat("subscript")&&m.toggleFormat("subscript"),a==="super"&&!m.hasFormat("superscript")&&m.toggleFormat("superscript");let c=m.getStyle();return d&&(c+=`color: ${d};`),u&&u!=="transparent"&&(c+=`background-color: ${u};`),c&&m.setStyle(c),t&&!m.hasFormat(t)&&m.toggleFormat(t),m}}var Wo=class o extends nt{static getType(){return"tab"}static clone(t){return new o(t.__key)}afterCloneFrom(t){super.afterCloneFrom(t),this.__text=t.__text}constructor(t){super(" ",t),this.__detail=Tn}static importDOM(){return null}static importJSON(t){let e=vt();return e.setFormat(t.format),e.setStyle(t.style),e}exportJSON(){return{...super.exportJSON(),type:"tab",version:1}}setTextContent(t){E(!1,"TabNode does not support setTextContent")}setDetail(t){E(!1,"TabNode does not support setDetail")}setMode(t){E(!1,"TabNode does not support setMode")}canInsertTextBefore(){return!1}canInsertTextAfter(){return!1}};function vt(){return re(new Wo)}function kl(o){return o instanceof Wo}function Dt(...o){return()=>{for(let t=o.length-1;t>=0;t--)o[t]();o.length=0}}var In=new Map;function Il(o){let t={},e=o.split(";");for(let n of e)if(n!==""){let[r,i]=n.split(/:([^]+)/);r&&i&&(t[r.trim()]=i.trim())}return t}function $n(o){let t=In.get(o);return t===void 0&&(t=Il(o),In.set(o,t)),__DEV__&&Object.freeze(t),t}function iu(o){let t="";for(let e in o)e&&(t+=`${e}: ${o[e]};`);return t}function Dr(o,t){let e=o.getStartEndPoints();if(t.isSelected(o)&&!t.isSegmented()&&!t.isToken()&&e!==null){let[n,r]=e,i=o.isBackward(),s=n.getNode(),l=r.getNode(),a=t.is(s),d=t.is(l);if(a||d){let[u,m]=Or(o),c=s.is(l),f=t.is(i?l:s),g=t.is(i?s:l),h=0,N;if(c)h=u>m?m:u,N=u>m?u:m;else if(f)h=i?m:u,N=void 0;else if(g){let b=i?u:m;h=0,N=b}return t.__text=t.__text.slice(h,N),t}}return t}function $l(o){let t=o.getStyle(),e=Il(t);In.set(t,e)}function Pn(o,t){let e=$n("getStyle"in o?o.getStyle():o.style),n=Object.entries(t).reduce((i,[s,l])=>(typeof l=="function"?i[s]=l(e[s],o):l===null?delete i[s]:i[s]=l,i),{...e}),r=iu(n);o.setStyle(r),In.set(r,n)}function Pl(o,t){let e=o.getNodes(),n=e.length,r=o.getStartEndPoints();if(r===null)return;let[i,s]=r,l=n-1,a=e[0],d=e[l];if(o.isCollapsed()&&_(o)){Pn(o,t);return}let m=a.getTextContent().length,c=s.offset,f=i.offset,g=i.isBefore(s),h=g?f:c,N=g?c:f,b=g?i.type:s.type,x=g?s.type:i.type,S=g?s.key:i.key;if(L(a)&&h===m){let v=a.getNextSibling();L(v)&&(f=0,h=0,a=v)}if(e.length===1){if(L(a)&&a.canHaveFormat()){if(h=b==="element"?0:f>c?c:f,N=x==="element"?m:f>c?f:c,h===N)return;if(qe(a)||h===0&&N===m)Pn(a,t),a.select(h,N);else{let v=a.splitText(h,N),M=h===0?v[0]:v[1];Pn(M,t),M.select(0,N-h)}}}else{if(L(a)&&h0&&o.classList.add(...e)}function Oi(o,...t){let e=wt(...t);e.length>0&&o.classList.remove(...e)}function cu(o,t){let e=o;for(;e!=null;){if(e instanceof t)return e;e=e.getParent()}return null}function uu(o){let t=U(o,e=>T(e)&&!e.isInline());return T(t)||E(!1,"Expected node %s to have closest block element node.",o.__key),t}var U=(o,t)=>{let e=o;for(;e!==H()&&e!=null;){if(t(e))return e;e=e.getParent()}return null};function Nt(o,t){return o!==null?Object.getPrototypeOf(o).constructor.name===t.name:!1}function Ai(o,t){let e=t.body?t.body.childNodes:[],n=[],r=[];for(let i=0;i"u"||typeof window>"u"&&typeof global.window>"u")throw new Error("To use $generateHtmlFromNodes in headless mode please initialize a headless browser implementation such as JSDom before calling this function.");let e=document.createElement("div"),r=H().getChildren();for(let s=0;s{let g=new bo;return e.push(g),g}):c=fu(o,c,I)),l==null?c.length>0?s=s.concat(c):Eo(o)&&DN(o)&&(s=s.concat(ht())):T(l)&&l.append(...c),s}function fu(o,t,e){let n=[],r=[];for(let i=0;i{if(L(t)){let e=I();return e.append(t),e}return t})}function _o(o,t){let e=hu(t),n=Ai(o,e);return ON(n)}function Ot(o,t){for(let e of o.getParents())if(t(e))return e;return null}function Hl(o,t){t||(t=H());let e=[];for(let n of t.getChildren())o(n)&&e.push(n),T(n)&&e.push(...Hl(o,n));return e}function Eu(o,t,e){let n=H().getChildren();for(let r of n){let i=o.getElementByKey(r.__key);if(!i)continue;let s=i.getBoundingClientRect();if(e<=s.bottom)return r}return null}function Zo(o){let t=e=>(T(e)||F(e))&&!e.isInline()&&!ne(e);return t(o)?o:U(o,t)}function Tu(o){let t=[],e=i=>{for(let s of i.getChildren())t.push(s.getKey()),T(s)&&e(s)},n=H();e(n);let r=Array.from(o);return r.sort((i,s)=>{let l=t.indexOf(i.getKey()),a=t.indexOf(s.getKey());return l-a}),r}function Ar(o,t){let e=Zo(o)||o,n=t?e.getNextSibling():e.getPreviousSibling();return n||(n=I(),t?e.insertAfter(n):e.insertBefore(n)),t?n.selectStart():n.selectEnd()}function Rr(o){return"__alignment"in o}function Cu(o){return"__inset"in o}var bu=new WeakMap;function ae(o){return bu.get(o)||null}function _u(o,t){bu.set(o,t)}function de(o,t){return Z(o,t)!==null}function Z(o,t){if(!o)return null;for(let e of o.getNodes()){if(t(e))return e;let n=Ot(e,t);if(n)return n}return null}function yu(o){return Z(o,L)}function Su(o,t){if(!o)return!1;let e=o.getNodes();for(let n of e)if(L(n)&&n.hasFormat(t))return!0;return!!(e.length===1&&Ze(e[0])&&e[0].hasTextFormat(t))}function Fn(o,t){let e=C(),n=e?uu(e.getNodes()[0]):null;e&&o(n)?wi(e,I):wi(e,t)}function Vo(o,t=!0){Kl([o],t)}function Kl(o,t=!0){let e=C()?.getNodes()||[],n=e.length>0?Zo(e[0]):null;if(n)if(t)for(let r=o.length-1;r>=0;r--)n.insertAfter(o[r]);else for(let r of o)n.insertBefore(r);else H().append(...o)}function rt(o){let t=jo();t.add(o.getKey()),Y(t)}function Lu(o){for(let t of o){if(L(t))return t;if(T(t)){let e=t.getChildren(),n=Lu(e);if(n!==null)return n}}return null}function Mu(o){let t=[...o].reverse();for(let e of t){if(L(e))return e;if(T(e)){let n=[...e.getChildren()].reverse(),r=Mu(n);if(r!==null)return r}}return null}function wu(o){if(o.length===0)return;let t=Xo(),e=Lu(o),n=Mu(o);e&&n&&(t.setTextNodeRange(e,0,n,n.getTextContentSize()||0),Y(t))}function vu(o){let t=ae(o);t&&window.requestAnimationFrame(()=>{o.update(()=>{Y(t.clone())})})}function ki(o,t){if(!o)return!1;let e=t.getKey();for(let n of o.getNodes())if(n.getKey()===e)return!0;return!1}function kr(o,t){let e=[...o?.getNodes()||[],...At(o)];for(let n of e)if(Rr(n)&&n.getAlignment()===t)return!0;return!1}function Ul(o,t){let e=[...o?.getNodes()||[],...At(o)];for(let n of e)if(qo(n)&&n.getDirection()===t)return!0;return!1}function At(o){if(!o)return[];let t=new Map;for(let e of o.getNodes()){let n=Zo(e);T(n)&&t.set(n.getKey(),n)}return Array.from(t.values())}var ql=class{constructor(t,e,n){p(this,"key");p(this,"offset");p(this,"type");p(this,"_selection");this._selection=null,this.key=t,this.offset=e,this.type=n}is(t){return this.key===t.key&&this.offset===t.offset&&this.type===t.type}isBefore(t){let e=this.getNode(),n=t.getNode(),r=this.offset,i=t.offset;if(T(e)){let s=e.getDescendantByIndex(r);e=s??e}if(T(n)){let s=n.getDescendantByIndex(i);n=s??n}return e===n?ri&&(n=i)}else if(!T(t)){let i=t.getNextSibling();if(L(i))e=i.__key,n=0,r="text";else{let s=t.getParent();s&&(e=s.__key,n=t.getIndexWithinParent()+1)}}o.set(e,n,r)}function vl(o,t){if(T(t)){let e=t.getLastDescendant();T(e)||L(e)?zl(o,e):zl(o,t)}else zl(o,t)}function AN(o,t,e,n){let r=o.getNode(),i=r.getChildAtIndex(o.offset),s=q(),l=ne(r)?I().append(s):s;s.setFormat(e),s.setStyle(n),i===null?r.append(l):i.insertBefore(l),o.is(t)&&t.set(s.__key,0,"text"),o.set(s.__key,0,"text")}function yo(o,t,e,n){o.key=t,o.offset=e,o.type=n}var Ii=class o{constructor(t){p(this,"_nodes");p(this,"_cachedNodes");p(this,"dirty");this._cachedNodes=null,this._nodes=t,this.dirty=!1}getCachedNodes(){return this._cachedNodes}setCachedNodes(t){this._cachedNodes=t}is(t){if(!Le(t))return!1;let e=this._nodes,n=t._nodes;return e.size===n.size&&Array.from(e).every(r=>n.has(r))}isCollapsed(){return!1}isBackward(){return!1}getStartEndPoints(){return null}add(t){this.dirty=!0,this._nodes.add(t),this._cachedNodes=null}delete(t){this.dirty=!0,this._nodes.delete(t),this._cachedNodes=null}clear(){this.dirty=!0,this._nodes.clear(),this._cachedNodes=null}has(t){return this._nodes.has(t)}clone(){return new o(new Set(this._nodes))}extract(){return this.getNodes()}insertRawText(t){}insertText(){}insertNodes(t){let e=this.getNodes(),n=e.length,r=e[n-1],i;if(L(r))i=r.select();else{let s=r.getIndexWithinParent()+1;i=r.getParentOrThrow().select(s,s)}i.insertNodes(t);for(let s=0;s0?m=[]:m=[l]:m=l.getNodesBetween(a),ft()||(this._cachedNodes=m),m}setTextNodeRange(t,e,n,r){yo(this.anchor,t.__key,e,"text"),yo(this.focus,n.__key,r,"text"),this._cachedNodes=null,this.dirty=!0}getTextContent(){let t=this.getNodes();if(t.length===0)return"";let e=t[0],n=t[t.length-1],r=this.anchor,i=this.focus,s=r.isBefore(i),[l,a]=Or(this),d="",u=!0;for(let m=0;m=0;k--){let j=R[k];if(j.is(c)||T(j)&&j.isParentOf(c))break;j.isAttached()&&(!A.has(j)||j.is(M)?$||B.insertAfter(j,!1):j.remove())}if(!$){let k=v,j=null;for(;k!==null;){let se=k.getChildren(),Fe=se.length;(Fe===0||se[Fe-1].is(j))&&(x.delete(k.__key),j=k),k=k.getParent()}}if(!c.isToken())c=c.spliceText(a,g-a,t,!0),c.getTextContent()===""?c.remove():c.isComposing()&&this.anchor.type==="text"&&(this.anchor.offset-=t.length);else if(a===g)c.select();else{let k=q(t);k.select(),c.replace(k)}for(let k=1;k0&&(N!==h.getTextContentSize()&&!qe(h)&&([h]=h.splitText(N)),h.setFormat(b));for(let x=u+1;x(T(N)||F(N))&&!N.isInline();if(!t.some(i)){E(T(n),"Expected 'firstBlock' to be an ElementNode");let N=Wl(this);n.splice(N,0,t),r.selectEnd();return}let s=BN(t),l=s.getLastDescendant(),a=s.getChildren(),d=N=>T(N)&&Ko(N)&&!N.isEmpty()&&T(n)&&(!n.isEmpty()||n.canMergeWhenEmpty()),m=!T(n)||!n.isEmpty()?this.insertParagraph():null,c=a[a.length-1],f=a[0];d(f)&&(E(T(n),"Expected 'firstBlock' to be an ElementNode"),n.append(...f.getChildren()),f=a[1]),f&&Qc(n,f);let g=xi(l,Ko);m&&T(g)&&(m.canMergeWhenEmpty()||Ko(c))&&(g.append(...m.getChildren()),m.remove()),T(n)&&n.isEmpty()&&n.remove(),l.selectEnd();let h=T(n)?n.getLastChild():null;Ae(h)&&g!==n&&h.remove()}insertParagraph(){if(this.anchor.key==="root"){let s=I();return H().splice(this.anchor.offset,0,[s]),s.select(),s}let t=Wl(this),e=xi(this.anchor.getNode(),Ko);E(T(e),"Expected ancestor to be an ElementNode");let n=e.getChildAtIndex(t),r=n?[n,...n.getNextSiblings()]:[],i=e.insertNewAfter(this,!1);return i?(i.append(...r),i.selectStart(),i):null}insertLineBreak(t){let e=ht();if(this.insertNodes([e]),t){let n=e.getParentOrThrow(),r=e.getIndexWithinParent();n.select(r,r)}}extract(){let t=this.getNodes(),e=t.length,n=e-1,r=this.anchor,i=this.focus,s=t[0],l=t[n],[a,d]=Or(this);if(e===0)return[];if(e===1){if(L(s)&&!this.isCollapsed()){let m=a>d?d:a,c=a>d?a:d,f=s.splitText(m,c),g=m===0?f[0]:f[1];return g!=null?[g]:[]}return[s]}let u=r.isBefore(i);if(L(s)){let m=u?a:d;m===s.getTextContentSize()?t.shift():m!==0&&([,s]=s.splitText(m),t[0]=s)}if(L(l)){let c=l.getTextContent().length,f=u?d:a;f===0?t.pop():f!==c&&([l]=l.splitText(f),t[n]=l)}return t}modify(t,e,n){let r=this.focus,i=this.anchor,s=t==="move",l=Jt(r,e);if(F(l)&&!l.isIsolated()){if(s&&l.isKeyboardSelectable()){let f=jo();f.add(l.__key),Y(f);return}let c=e?l.getPreviousSibling():l.getNextSibling();if(L(c)){let f=c.__key,g=e?c.getTextContent().length:0;r.set(f,g,"text"),s&&i.set(f,g,"text");return}else{let f=l.getParentOrThrow(),g,h;T(c)?(h=c.__key,g=e?c.getChildrenSize():0):(g=l.getIndexWithinParent(),h=f.__key,e||g++),r.set(h,g,"element"),s&&i.set(h,g,"element");return}}let a=J(),d=ye(a._window);if(!d)return;let u=a._blockCursorElement,m=a._rootElement;if(m!==null&&u!==null&&T(l)&&!l.isInline()&&!l.canBeEmpty()&&br(u,a,m),kN(d,t,e?"backward":"forward",n),d.rangeCount>0){let c=d.getRangeAt(0),f=this.anchor.getNode(),g=ne(f)?f:fl(f);if(this.applyDOMRange(c),this.dirty=!0,!s){let h=this.getNodes(),N=[],b=!1;for(let x=0;x0)if(e){let x=N[0];T(x)?x.selectStart():x.getParentOrThrow().selectStart()}else{let x=N[N.length-1];T(x)?x.selectEnd():x.getParentOrThrow().selectEnd()}(d.anchorNode!==c.startContainer||d.anchorOffset!==c.startOffset)&&RN(this)}}}forwardDeletion(t,e,n){if(!n&&(t.type==="element"&&T(e)&&t.offset===e.getChildrenSize()||t.type==="text"&&t.offset===e.getTextContentSize())){let r=e.getParent(),i=e.getNextSibling()||(r===null?null:r.getNextSibling());if(T(i)&&i.isShadowRoot())return!0}return!1}deleteCharacter(t){let e=this.isCollapsed();if(this.isCollapsed()){let n=this.anchor,r=n.getNode();if(this.forwardDeletion(n,r,t))return;let i=this.focus,s=Jt(i,t);if(F(s)&&!s.isIsolated()){if(s.isKeyboardSelectable()&&T(r)&&r.getChildrenSize()===0){r.remove();let l=jo();l.add(s.__key),Y(l)}else s.remove(),J().dispatchCommand(De,void 0);return}else if(!t&&T(s)&&T(r)&&r.isEmpty()){r.remove(),s.selectStart();return}if(this.modify("extend",t,"character"),this.isCollapsed()){if(t&&n.offset===0&&(n.type==="element"?n.getNode():n.getNode().getParentOrThrow()).collapseAtStart(this))return}else{let l=i.type==="text"?i.getNode():null;if(r=n.type==="text"?n.getNode():null,l!==null&&l.isSegmented()){let a=i.offset,d=l.getTextContentSize();if(l.is(r)||t&&a!==d||!t&&a!==0){Ou(l,t,a);return}}else if(r!==null&&r.isSegmented()){let a=n.offset,d=r.getTextContentSize();if(r.is(l)||t&&a!==0||!t&&a!==d){Ou(r,t,a);return}}IN(this,t)}}if(this.removeText(),t&&!e&&this.isCollapsed()&&this.anchor.type==="element"&&this.anchor.offset===0){let n=this.anchor.getNode();n.isEmpty()&&ne(n.getParent())&&n.getIndexWithinParent()===0&&n.collapseAtStart(this)}}deleteLine(t){if(this.isCollapsed()){let e=this.anchor.type==="element";if(e&&this.insertText(" "),this.modify("extend",t,"lineboundary"),(t?this.focus:this.anchor).offset===0&&this.modify("extend",t,"character"),e){let r=t?this.anchor:this.focus;r.set(r.key,r.offset+1,r.type)}}this.removeText()}deleteWord(t){if(this.isCollapsed()){let e=this.anchor,n=e.getNode();if(this.forwardDeletion(e,n,t))return;this.modify("extend",t,"word")}this.removeText()}isBackward(){return this.focus.isBefore(this.anchor)}getStartEndPoints(){return[this.anchor,this.focus]}};function Le(o){return o instanceof Ii}function Du(o){let t=o.offset;if(o.type==="text")return t;let e=o.getNode();return t===e.getChildrenSize()?e.getTextContent().length:0}function Or(o){let t=o.getStartEndPoints();if(t===null)return[0,0];let[e,n]=t;return e.type==="element"&&n.type==="element"&&e.key===n.key&&e.offset===n.offset?[0,0]:[Du(e),Du(n)]}function RN(o){let t=o.focus,e=o.anchor,n=e.key,r=e.offset,i=e.type;yo(e,t.key,t.offset,t.type),yo(t,n,r,i),o._cachedNodes=null}function kN(o,t,e,n){o.modify(t,e,n)}function IN(o,t){let e=o.anchor,n=o.focus,r=e.getNode(),i=n.getNode();if(r===i&&e.type==="text"&&n.type==="text"){let s=e.offset,l=n.offset,a=se||c){i.splice(u,1),c&&(a=void 0);break}}let d=i.join("").trim();d===""?n.remove():(n.setTextContent(d),n.select(a,a))}function $N(o,t,e){let n=o.getParent();return e===null||n===null||!n.canBeEmpty()||n!==e.getNode()}function Au(o,t,e,n){let r=t,i;if(o.nodeType===No){let s=!1,l=o.childNodes,a=l.length,d=n._blockCursorElement;r===a&&(s=!0,r=a-1);let u=l[r],m=!1;if(u===d)u=l[r+1],m=!0;else if(d!==null){let c=d.parentNode;if(o===c){let f=Array.prototype.indexOf.call(c.children,d);t>f&&r--}}if(i=Fo(u),L(i))r=ll(i,s);else{let c=Fo(o);if(c===null)return null;if(T(c)){r=Math.min(c.getChildrenSize(),r);let f=c.getChildAtIndex(r);if(T(f)&&$N(f,r,e)){let g=s?f.getLastDescendant():f.getFirstDescendant();g===null?c=f:(f=g,c=T(f)?f:f.getParentOrThrow()),r=0}L(f)?(i=f,c=null,r=ll(f,s)):f!==c&&s&&!m&&r++}else{let f=c.getIndexWithinParent();t===0&&F(c)&&Fo(o)===c?r=f:r=f+1,c=c.getParentOrThrow()}if(T(c))return Re(c.__key,r,"element")}}else i=Fo(o);return L(i)?Re(i.__key,r,"text"):null}function Ru(o,t,e){let n=o.offset,r=o.getNode();if(n===0){let i=r.getPreviousSibling(),s=r.getParent();if(!t)T(i)&&!e&&i.isInline()?(o.key=i.__key,o.offset=i.getChildrenSize(),o.type="element"):L(i)&&(o.key=i.__key,o.offset=i.getTextContent().length);else if((e||!t)&&i===null&&T(s)&&s.isInline()){let l=s.getPreviousSibling();L(l)&&(o.key=l.__key,o.offset=l.getTextContent().length)}}else if(n===r.getTextContent().length){let i=r.getNextSibling(),s=r.getParent();if(t&&T(i)&&i.isInline())o.key=i.__key,o.offset=0,o.type="element";else if((e||t)&&i===null&&T(s)&&s.isInline()&&!s.canInsertTextAfter()){let l=s.getNextSibling();L(l)&&(o.key=l.__key,o.offset=0)}}}function Iu(o,t,e){if(o.type==="text"&&t.type==="text"){let n=o.isBefore(t),r=o.is(t);Ru(o,n,r),Ru(t,!n,r),r&&(t.key=o.key,t.offset=o.offset,t.type=o.type);let i=J();if(i.isComposing()&&i._compositionKey!==o.key&&_(e)){let s=e.anchor,l=e.focus;yo(o,s.key,s.offset,s.type),yo(t,l.key,l.offset,l.type)}}}function $u(o,t,e,n,r,i){if(o===null||e===null||!jt(r,o,e))return null;let s=Au(o,t,_(i)?i.anchor:null,r);if(s===null)return null;let l=Au(e,n,_(i)?i.focus:null,r);if(l===null)return null;if(s.type==="element"&&l.type==="element"){let a=Fo(o),d=Fo(e);if(F(a)&&F(d))return null}return Iu(s,l,i),[s,l]}function qo(o){return T(o)&&!o.isInline()}function Mi(o,t,e,n,r,i){let s=tt(),l=new So(Re(o,t,r),Re(e,n,i),0,"");return l.dirty=!0,s._selection=l,l}function Xo(){let o=Re("root",0,"element"),t=Re("root",0,"element");return new So(o,t,0,"")}function jo(){return new Ii(new Set)}function Pu(o){let e=o.getEditorState()._selection,n=ye(o._window);return _(e)||e==null?vr(e,n,o,null):e.clone()}function Yl(o,t){return vr(null,o,t,null)}function vr(o,t,e,n){let r=e._window;if(r===null)return null;let i=n||r.event,s=i?i.type:void 0,l=s==="selectionchange",a=!kd()&&(l||s==="beforeinput"||s==="compositionstart"||s==="compositionend"||s==="click"&&i&&i.detail===3||s==="drop"||s===void 0),d,u,m,c;if(!_(o)||a){if(t===null)return null;if(d=t.anchorNode,u=t.focusNode,m=t.anchorOffset,c=t.focusOffset,l&&_(o)&&!jt(e,d,u))return o.clone()}else return o.clone();let f=$u(d,m,u,c,e,o);if(f===null)return null;let[g,h]=f;return new So(g,h,_(o)?o.format:0,_(o)?o.style:"")}function C(){return tt()._selection}function Ye(){return J()._editorState._selection}function Rn(o,t,e,n=1){let r=o.anchor,i=o.focus,s=r.getNode(),l=i.getNode();if(!t.is(s)&&!t.is(l))return;let a=t.__key;if(o.isCollapsed()){let d=r.offset;if(e<=d&&n>0||e0||e0||e=l,d=a?i.getChildAtIndex(l-1):i.getChildAtIndex(e);if(L(d)){let u=0;a&&(u=d.getTextContentSize()),t.set(d.__key,u,"text"),n.set(d.__key,u,"text")}return}if(T(i)){let l=i.getChildrenSize(),a=e>=l,d=a?i.getChildAtIndex(l-1):i.getChildAtIndex(e);if(L(d)){let u=0;a&&(u=d.getTextContentSize()),t.set(d.__key,u,"text")}}if(T(s)){let l=s.getChildrenSize(),a=r>=l,d=a?s.getChildAtIndex(l-1):s.getChildAtIndex(r);if(L(d)){let u=0;a&&(u=d.getTextContentSize()),n.set(d.__key,u,"text")}}}function Bu(o,t){let n=t.getEditorState()._selection,r=o._selection;if(_(r)){let i=r.anchor,s=r.focus,l;if(i.type==="text"&&(l=i.getNode(),l.selectionTransform(n,r)),s.type==="text"){let a=s.getNode();l!==a&&a.selectionTransform(n,r)}}}function kn(o,t,e,n,r){let i=null,s=0,l=null;n!==null?(i=n.__key,L(n)?(s=n.getTextContentSize(),l="text"):T(n)&&(s=n.getChildrenSize(),l="element")):r!==null&&(i=r.__key,L(r)?l="text":T(r)&&(l="element")),i!==null&&l!==null?o.set(i,s,l):(s=t.getIndexWithinParent(),s===-1&&(s=e.getChildrenSize()),o.set(e.__key,s,"element"))}function Al(o,t,e,n,r){o.type==="text"?(o.key=e,t||(o.offset+=r)):o.offset>n.getIndexWithinParent()&&(o.offset-=1)}function Fu(o,t,e,n,r,i,s){let l=n.anchorNode,a=n.focusNode,d=n.anchorOffset,u=n.focusOffset,m=document.activeElement;if(r.has("collaboration")&&m!==i||m!==null&&Ln(m))return;if(!_(t)){if(m!==null&&n.isCollapsed&&a instanceof Node){let k=ee(a);if(F(k)){n.removeAllRanges(),rt(k);return}}o!==null&&jt(e,l,a)&&n.removeAllRanges();return}let c=t.anchor,f=t.focus,g=c.key,h=f.key,N=vn(e,g),b=vn(e,h),x=c.offset,S=f.offset,v=t.format,M=t.style,R=t.isCollapsed(),A=N,$=b,B=!1;if(c.type==="text"){A=wn(N);let k=c.getNode();B=k.getFormat()!==v||k.getStyle()!==M}else _(o)&&o.anchor.type==="text"&&(B=!0);if(f.type==="text"&&($=wn(b)),!(A===null||$===null)&&(R&&(o===null||B||_(o)&&(o.format!==v||o.style!==M))&&Jc(v,M,x,g,performance.now()),!(d===x&&u===S&&l===A&&a===$&&!(n.type==="Range"&&R)&&((m===null||!i.contains(m))&&i.focus({preventScroll:!0}),c.type!=="element")))){try{n.setBaseAndExtent(A,x,$,S)}catch(k){__DEV__&&console.warn(k)}if(!r.has("skip-scroll-into-view")&&t.isCollapsed()&&i!==null&&i===document.activeElement){let k=t instanceof So&&t.anchor.type==="element"?A.childNodes[x]||null:n.rangeCount>0?n.getRangeAt(0):null;if(k!==null){let j;if(k instanceof Text){let se=document.createRange();se.selectNode(k),j=se.getBoundingClientRect()}else j=k.getBoundingClientRect();yc(e,j,i)}}Gc()}}function Me(o){let t=C()||Ye();t===null&&(t=H().selectEnd()),t.insertNodes(o)}function Wl(o){let t=o;o.isCollapsed()||t.removeText();let e=C();_(e)&&(t=e),E(_(t),"Unexpected dirty selection to be null");let n=t.anchor,r=n.getNode(),i=n.offset;for(;!Ko(r);)[r,i]=PN(r,i);return i}function PN(o,t){let e=o.getParent();if(!e){let r=I();return H().append(r),r.select(),[H(),0]}if(L(o)){let r=o.splitText(t);if(r.length===0)return[e,o.getIndexWithinParent()];let i=t===0?0:1,s=r[0].getIndexWithinParent()+i;return[e,s]}if(!T(o)||t===0)return[e,o.getIndexWithinParent()];let n=o.getChildAtIndex(t);if(n){let r=new So(Re(o.__key,t,"element"),Re(o.__key,t,"element"),0,""),i=o.insertNewAfter(r);i&&i.append(n,...n.getNextSiblings())}return[e,o.getIndexWithinParent()+1]}function BN(o){let t=I(),e=null;for(let n=0;n99&&E(!1,"One or more transforms are endlessly triggering additional transforms. May have encountered infinite recursion caused by transforms that have their preconditions too lose and/or conflict with each other.")}function tt(){return fe===null&&E(!1,"Unable to find an active editor state. State helpers or node methods can only be used synchronously during the callback of editor.update(), editor.read(), or editorState.read().%s",Wu()),fe}function J(){return he===null&&E(!1,"Unable to find an active editor. This method can only be used synchronously during the callback of editor.update() or editor.read().%s",Wu()),he}function Wu(){let o=0,t=new Set,e=eo.version;if(typeof window<"u")for(let r of document.querySelectorAll("[contenteditable]")){let i=Bo(r);if(Mn(i))o++;else if(i){let s=String(i.constructor.version||"<0.17.1");s===e&&(s+=" (separately built, likely a bundler configuration issue)"),t.add(s)}}let n=` Detected on the page: ${o} compatible editor(s) with version ${e}`;return t.size&&(n+=` and incompatible editors with versions ${Array.from(t).join(", ")}`),n}function qu(){return he}function vc(){return fe}function Ku(o,t,e){let n=t.__type,r=Kd(o,n),i=e.get(n);i===void 0&&(i=Array.from(r.transforms),e.set(n,i));let s=i.length;for(let l=0;l0||u>0;){if(a>0){t._dirtyLeaves=new Set;for(let m of l){let c=r.get(m);L(c)&&c.isAttached()&&c.isSimpleText()&&!c.isUnmergeable()&&rl(c),c!==void 0&&Uu(c,i)&&Ku(t,c,s),e.add(m)}if(l=t._dirtyLeaves,a=l.size,a>0){$i++;continue}}t._dirtyLeaves=new Set,t._dirtyElements=new Map;for(let m of d){let c=m[0],f=m[1];if(c!=="root"&&!f)continue;let g=r.get(c);g!==void 0&&Uu(g,i)&&Ku(t,g,s),n.set(c,f)}l=t._dirtyLeaves,a=l.size,d=t._dirtyElements,u=d.size,$i++}t._dirtyLeaves=e,t._dirtyElements=n}function Vl(o){return Xl(o,J()._nodes)}function Xl(o,t){let e=o.type,n=t.get(e);n===void 0&&E(!1,'parseEditorState: type "%s" + not found',e);let r=n.klass;o.type!==r.getType()&&E(!1,"LexicalNode: Node %s does not implement .importJSON().",r.name);let i=r.importJSON(o),s=o.children;if(T(i)&&Array.isArray(s))for(let l=0;l{throw new Error("Cannot call set() on a frozen Lexical node map")},t.clear=()=>{throw new Error("Cannot call clear() on a frozen Lexical node map")},t.delete=()=>{throw new Error("Cannot call delete() on a frozen Lexical node map")}}function Rt(o,t){let e=o._pendingEditorState,n=o._rootElement,r=o._headless||n===null;if(e===null)return;let i=o._editorState,s=i._selection,l=e._selection,a=o._dirtyType!==Mt,d=fe,u=ke,m=he,c=o._updating,f=o._observer,g=null;if(o._pendingEditorState=null,o._editorState=e,!r&&a&&f!==null){he=o,fe=e,ke=!1,o._updating=!0;try{let A=o._dirtyType,$=o._dirtyElements,B=o._dirtyLeaves;f.disconnect(),g=Pc(i,e,o,A,$,B)}catch(A){if(A instanceof Error&&o._onError(A),!Zl)Gl(o,null,n,e),ai(o),o._dirtyType=Xt,Zl=!0,Rt(o,i),Zl=!1;else throw A;return}finally{f.observe(n,Hu),o._updating=c,fe=d,ke=u,he=m}}e._readOnly||(e._readOnly=!0,__DEV__&&(Zu(e),_(l)&&(Object.freeze(l.anchor),Object.freeze(l.focus)),Object.freeze(l)));let h=o._dirtyLeaves,N=o._dirtyElements,b=o._normalizedNodes,x=o._updateTags,S=o._deferred,v=e._nodeMap.size;a&&(o._dirtyType=Mt,o._cloneNotNeeded.clear(),o._dirtyLeaves=new Set,o._dirtyElements=new Map,o._normalizedNodes=new Set,o._updateTags=new Set),Dc(o,e);let M=r?null:ye(o._window);if(o._editable&&M!==null&&(a||l===null||l.dirty)){he=o,fe=e;try{if(f!==null&&f.disconnect(),a||l===null||l.dirty){let A=o._blockCursorElement;A!==null&&br(A,o,n),Fu(s,l,o,M,x,n,v)}Mc(o,n,l),f!==null&&f.observe(n,Hu)}finally{he=m,fe=d}}g!==null&&UN(o,g,x,h,i),!_(l)&&l!==null&&(s===null||!s.is(l))&&o.dispatchCommand(De,void 0);let R=o._pendingDecorators;R!==null&&(o._decorators=R,o._pendingDecorators=null,Hn("decorator",o,!0,R)),KN(o,t||i,e),Hn("update",o,!0,{dirtyElements:N,dirtyLeaves:h,editorState:e,normalizedNodes:b,prevEditorState:t||i,tags:x}),WN(o,S),zN(o)}function KN(o,t,e){let n=sl(t),r=sl(e);n!==r&&Hn("textcontent",o,!0,r)}function UN(o,t,e,n,r){let i=Array.from(o._listeners.mutation),s=i.length;for(let l=0;l{r=gl(o,t,e)}),r}let n=Er(o);for(let r=4;r>=0;r--)for(let i=0;i{Rt(o)}):(d._flushSync=!1,u&&(n.clear(),o._deferred=[],o._pendingEditorState=null))}function Ee(o,t,e){o._updating?o._updates.push([t,e]):Vu(o,t,e)}var V=class extends gt{constructor(e){super(e);p(this,"__first");p(this,"__last");p(this,"__size");p(this,"__style");p(this,"__dir");this.__first=null,this.__last=null,this.__size=0,this.__style="",this.__dir=null}afterCloneFrom(e){super.afterCloneFrom(e),this.__first=e.__first,this.__last=e.__last,this.__size=e.__size,this.__style=e.__style,this.__dir=e.__dir}getStyle(){return this.getLatest().__style}getChildren(){let e=[],n=this.getFirstChild();for(;n!==null;)e.push(n),n=n.getNextSibling();return e}getChildrenKeys(){let e=[],n=this.getFirstChild();for(;n!==null;)e.push(n.__key),n=n.getNextSibling();return e}getChildrenSize(){return this.getLatest().__size}isEmpty(){return this.getChildrenSize()===0}isDirty(){let n=J()._dirtyElements;return n!==null&&n.has(this.__key)}isLastChild(){let e=this.getLatest(),n=this.getParentOrThrow().getLastChild();return n!==null&&n.is(e)}getAllTextNodes(){let e=[],n=this.getFirstChild();for(;n!==null;){if(L(n)&&e.push(n),T(n)){let r=n.getAllTextNodes();e.push(...r)}n=n.getNextSibling()}return e}getFirstDescendant(){let e=this.getFirstChild();for(;T(e);){let n=e.getFirstChild();if(n===null)break;e=n}return e}getLastDescendant(){let e=this.getLastChild();for(;T(e);){let n=e.getLastChild();if(n===null)break;e=n}return e}getDescendantByIndex(e){let n=this.getChildren(),r=n.length;if(e>=r){let s=n[r-1];return T(s)&&s.getLastDescendant()||s||null}let i=n[e];return T(i)&&i.getFirstDescendant()||i||null}getFirstChild(){let n=this.getLatest().__first;return n===null?null:Q(n)}getFirstChildOrThrow(){let e=this.getFirstChild();return e===null&&E(!1,"Expected node %s to have a first child.",this.__key),e}getLastChild(){let n=this.getLatest().__last;return n===null?null:Q(n)}getLastChildOrThrow(){let e=this.getLastChild();return e===null&&E(!1,"Expected node %s to have a last child.",this.__key),e}getChildAtIndex(e){let n=this.getChildrenSize(),r,i;if(e=e;){if(i===e)return r;r=r.getPreviousSibling(),i--}return null}getTextContent(){let e="",n=this.getChildren(),r=n.length;for(let i=0;ir.remove()),e}append(...e){return this.splice(this.getChildrenSize(),0,e)}setDirection(e){let n=this.getWritable();return n.__dir=e,n}setStyle(e){let n=this.getWritable();return n.__style=e||"",this}splice(e,n,r){let i=r.length,s=this.getChildrenSize(),l=this.getWritable(),a=l.__key,d=[],u=[],m=this.getChildAtIndex(e+n),c=null,f=s-n+i;if(e!==0)if(e===s)c=this.getLastChild();else{let h=this.getChildAtIndex(e);h!==null&&(c=h.getPreviousSibling())}if(n>0){let h=c===null?this.getFirstChild():c.getNextSibling();for(let N=0;N({root:Qu(H())}))}};var bo=class extends V{static getType(){return"artificial"}createDOM(t){return document.createElement("div")}};var ef=["left","right","center","justify"];function $r(o){let t=o.style.textAlign||"";return ef.includes(t)?t:o.classList.contains("align-left")?"left":o.classList.contains("align-right")?"right":o.classList.contains("align-center")?"center":o.classList.contains("align-justify")?"justify":""}function qN(o){let t=o.style.paddingLeft||"0";return Yo(t)}function Pr(o){let t=(o.dir||"").toLowerCase();return t==="rtl"||t==="ltr"?t:null}function it(o,t){o.id&&t.setId(o.id),t.setAlignment($r(o)),t.setInset(qN(o)),t.setDirection(Pr(o))}function Lo(o,t){return o.__id!==t.__id||o.__alignment!==t.__alignment||o.__inset!==t.__inset||o.__dir!==t.__dir}function tf(o,t,e){if(o.__id!==t.__id&&e.setAttribute("id",t.__id),o.__alignment!==t.__alignment){for(let n of ef)e.classList.remove("align-"+n);t.__alignment&&e.classList.add("align-"+t.__alignment)}o.__inset!==t.__inset&&(t.__inset?e.style.paddingLeft=`${t.__inset}px`:e.style.removeProperty("paddingLeft")),o.__dir!==t.__dir&&(t.__dir?e.dir=t.__dir:e.removeAttribute("dir"))}function st(o,t){t.__id&&o.setAttribute("id",t.__id),t.__alignment&&o.classList.add("align-"+t.__alignment),t.__inset&&(o.style.paddingLeft=`${t.__inset}px`),t.__dir&&(o.dir=t.__dir)}function lt(o,t){t.setId(o.id),t.setAlignment(o.alignment),t.setInset(o.inset),t.setDirection(o.direction)}var It=class extends V{constructor(){super(...arguments);p(this,"__id","");p(this,"__alignment","");p(this,"__inset",0)}setId(e){let n=this.getWritable();n.__id=e}getId(){return this.getLatest().__id}setAlignment(e){let n=this.getWritable();n.__alignment=e}getAlignment(){return this.getLatest().__alignment}setInset(e){let n=this.getWritable();n.__inset=e}getInset(){return this.getLatest().__inset}exportJSON(){return{...super.exportJSON(),id:this.__id,alignment:this.__alignment,inset:this.__inset}}};function Mo(o,t){t.__alignment=o.__alignment,t.__inset=o.__inset}var ot=class o extends It{constructor(e){super(e);p(this,"__textFormat");p(this,"__textStyle");this.__textFormat=0,this.__textStyle=""}static getType(){return"paragraph"}getTextFormat(){return this.getLatest().__textFormat}setTextFormat(e){let n=this.getWritable();return n.__textFormat=e,n}hasTextFormat(e){let n=Oe[e];return(this.getTextFormat()&n)!==0}getTextStyle(){return this.getLatest().__textStyle}setTextStyle(e){let n=this.getWritable();return n.__textStyle=e,n}static clone(e){return new o(e.__key)}afterCloneFrom(e){super.afterCloneFrom(e),this.__textFormat=e.__textFormat,this.__textStyle=e.__textStyle,Mo(e,this)}createDOM(e){let n=document.createElement("p"),r=xo(e.theme,"paragraph");return r!==void 0&&n.classList.add(...r),st(n,this),n}updateDOM(e,n,r){return Lo(e,this)}static importDOM(){return{p:e=>({conversion:YN,priority:0})}}exportDOM(e){let{element:n}=super.exportDOM(e);return n&&ge(n)&&this.isEmpty()&&n.append(document.createElement("br")),{element:n}}static importJSON(e){let n=I();return lt(e,n),n.setTextFormat(e.textFormat),n}exportJSON(){return{...super.exportJSON(),textFormat:this.getTextFormat(),textStyle:this.getTextStyle(),type:"paragraph",version:1}}insertNewAfter(e,n){let r=I();r.setTextFormat(e.format),r.setTextStyle(e.style);let i=this.getDirection();return r.setDirection(i),r.setStyle(this.getTextStyle()),this.insertAfter(r,n),r}collapseAtStart(){let e=this.getChildren();if(e.length===0||L(e[0])&&e[0].getTextContent().trim()===""){if(this.getNextSibling()!==null)return this.selectNext(),this.remove(),!0;if(this.getPreviousSibling()!==null)return this.selectPrevious(),this.remove(),!0}return!1}};function YN(o){let t=I();return it(o,t),{node:t}}function I(){return re(new ot)}function Ze(o){return o instanceof ot}var ZN=!0,G=0,Ve=1,Kn=2,Xe=3,Ie=4;function Gl(o,t,e,n){let r=o._keyToDOMMap;r.clear(),o._editorState=Ir(),o._pendingEditorState=n,o._compositionKey=null,o._dirtyType=Mt,o._cloneNotNeeded.clear(),o._dirtyLeaves=new Set,o._dirtyElements.clear(),o._normalizedNodes=new Set,o._updateTags=new Set,o._updates=[],o._blockCursorElement=null;let i=o._observer;i!==null&&(i.disconnect(),o._observer=null),t!==null&&(t.textContent=""),e!==null&&(e.textContent="",r.set("root",e))}function VN(o,t){let e=new Map,n=new Set,r=i=>{Object.keys(i).forEach(s=>{let l=e.get(s);l===void 0&&(l=[],e.set(s,l)),l.push(i[s])})};return o.forEach(i=>{let s=i.klass.importDOM;if(s==null||n.has(s))return;n.add(s);let l=s.call(i.klass);l!==null&&r(l)}),t&&r(t),e}function Bi(o){let t=o||{},e=qu(),n=t.theme||{},r=o===void 0?e:t.parentEditor||null,i=t.disableEvents||!1,s=Ir(),l=t.namespace||(r!==null?r._config.namespace:al()),a=t.editorState,d=[Go,nt,zo,Wo,ot,bo,...t.nodes||[]],{onError:u,html:m}=t,c=t.editable!==void 0?t.editable:!0,f;if(o===void 0&&e!==null)f=e._nodes;else{f=new Map;for(let h=0;h{N.hasOwnProperty(B)||console.warn(`${A} must implement static "${B}" method`)}),!N.hasOwnProperty("importDOM")&&N.hasOwnProperty("exportDOM")&&console.warn(`${A} should implement "importDOM" if using a custom "exportDOM" method to ensure HTML serialization (important for copy & paste) works as expected`),$ instanceof kt&&($.hasOwnProperty("decorate")||console.warn(`${$.constructor.name} must implement "decorate" method`)),N.hasOwnProperty("importJSON")||console.warn(`${A} should implement "importJSON" method to ensure JSON and default HTML serialization works as expected`),$.hasOwnProperty("exportJSON")||console.warn(`${A} should implement "exportJSON" method to ensure JSON and default HTML serialization works as expected`)}}let S=N.getType(),v=N.transform(),M=new Set;v!==null&&M.add(v),f.set(S,{exportDOM:m&&m.export?m.export.get(N):void 0,klass:N,replace:b,replaceWithKlass:x,transforms:M})}}let g=new eo(s,r,f,{disableEvents:i,namespace:l,theme:n},u||console.error,VN(f,m?m.import:void 0),c);return a!==void 0&&(g._pendingEditorState=a,g._dirtyType=Xt),g}var eo=class{constructor(t,e,n,r,i,s,l){p(this,"constructor");p(this,"_headless");p(this,"_parentEditor");p(this,"_rootElement");p(this,"_editorState");p(this,"_pendingEditorState");p(this,"_compositionKey");p(this,"_deferred");p(this,"_keyToDOMMap");p(this,"_updates");p(this,"_updating");p(this,"_listeners");p(this,"_commands");p(this,"_nodes");p(this,"_decorators");p(this,"_pendingDecorators");p(this,"_config");p(this,"_dirtyType");p(this,"_cloneNotNeeded");p(this,"_dirtyLeaves");p(this,"_dirtyElements");p(this,"_normalizedNodes");p(this,"_updateTags");p(this,"_observer");p(this,"_key");p(this,"_onError");p(this,"_htmlConversions");p(this,"_window");p(this,"_editable");p(this,"_blockCursorElement");this._parentEditor=e,this._rootElement=null,this._editorState=t,this._pendingEditorState=null,this._compositionKey=null,this._deferred=[],this._keyToDOMMap=new Map,this._updates=[],this._updating=!1,this._listeners={decorator:new Set,editable:new Set,mutation:new Map,root:new Set,textcontent:new Set,update:new Set},this._commands=new Map,this._config=r,this._nodes=n,this._decorators={},this._pendingDecorators=null,this._dirtyType=Mt,this._cloneNotNeeded=new Set,this._dirtyLeaves=new Set,this._dirtyElements=new Map,this._normalizedNodes=new Set,this._updateTags=new Set,this._observer=null,this._key=al(),this._onError=i,this._htmlConversions=s,this._editable=l,this._headless=e!==null&&e._headless,this._window=null,this._blockCursorElement=null}isComposing(){return this._compositionKey!=null}registerUpdateListener(t){let e=this._listeners.update;return e.add(t),()=>{e.delete(t)}}registerEditableListener(t){let e=this._listeners.editable;return e.add(t),()=>{e.delete(t)}}registerDecoratorListener(t){let e=this._listeners.decorator;return e.add(t),()=>{e.delete(t)}}registerTextContentListener(t){let e=this._listeners.textcontent;return e.add(t),()=>{e.delete(t)}}registerRootListener(t){let e=this._listeners.root;return t(this._rootElement,null),e.add(t),()=>{t(null,this._rootElement),e.delete(t)}}registerCommand(t,e,n){n===void 0&&E(!1,'Listener for type "command" requires a "priority".');let r=this._commands;r.has(t)||r.set(t,[new Set,new Set,new Set,new Set,new Set]);let i=r.get(t);i===void 0&&E(!1,"registerCommand: Command %s not found in command map",String(t));let s=i[n];return s.add(e),()=>{s.delete(e),i.every(l=>l.size===0)&&r.delete(t)}}registerMutationListener(t,e,n){let r=this.resolveRegisteredNodeAfterReplacements(this.getRegisteredNode(t)).klass,i=this._listeners.mutation;i.set(e,r);let s=n&&n.skipInitialization;return(s===void 0?ZN:s)||this.initializeMutationListener(e,r),()=>{i.delete(e)}}getRegisteredNode(t){let e=this._nodes.get(t.getType());return e===void 0&&E(!1,"Node %s has not been registered. Ensure node has been passed to createEditor.",t.name),e}resolveRegisteredNodeAfterReplacements(t){for(;t.replaceWithKlass;)t=this.getRegisteredNode(t.replaceWithKlass);return t}initializeMutationListener(t,e){let n=this._editorState,r=wc(n).get(e.getType());if(!r)return;let i=new Map;for(let s of r.keys())i.set(s,"created");i.size>0&&t(i,{dirtyLeaves:new Set,prevEditorState:n,updateTags:new Set(["registerMutationListener"])})}registerNodeTransformToKlass(t,e){let n=this.getRegisteredNode(t);return n.transforms.add(e),n}registerNodeTransform(t,e){let n=this.registerNodeTransformToKlass(t,e),r=[n],i=n.replaceWithKlass;if(i!=null){let s=this.registerNodeTransformToKlass(i,e);r.push(s)}return Yd(this,t.getType()),()=>{r.forEach(s=>s.transforms.delete(e))}}hasNode(t){return this._nodes.has(t.getType())}hasNodes(t){return t.every(this.hasNode.bind(this))}dispatchCommand(t,e){return O(this,t,e)}getDecorators(){return this._decorators}getRootElement(){return this._rootElement}getKey(){return this._key}setRootElement(t){let e=this._rootElement;if(t!==e){let n=xo(this._config.theme,"root"),r=this._pendingEditorState||this._editorState;if(this._rootElement=t,Gl(this,e,t,r),e!==null&&(this._config.disableEvents||jc(e),n!=null&&e.classList.remove(...n)),t!==null){let i=Lc(t),s=t.style;s.userSelect="text",s.whiteSpace="pre-wrap",s.wordBreak="break-word",t.setAttribute("data-lexical-editor","true"),this._window=i,this._dirtyType=Xt,ai(this),this._updateTags.add("history-merge"),Rt(this),this._config.disableEvents||Xc(t,this),n!=null&&t.classList.add(...n)}else this._editorState=r,this._pendingEditorState=null,this._window=null;Hn("root",this,!1,t,e)}}getElementByKey(t){return this._keyToDOMMap.get(t)||null}getEditorState(){return this._editorState}setEditorState(t,e){t.isEmpty()&&E(!1,"setEditorState: the editor state is empty. Ensure the editor state's root node never becomes empty."),li(this);let n=this._pendingEditorState,r=this._updateTags,i=e!==void 0?e.tag:null;n!==null&&!n.isEmpty()&&(i!=null&&r.add(i),Rt(this)),this._pendingEditorState=t,this._dirtyType=Xt,this._dirtyElements.set("root",!1),this._compositionKey=null,i!=null&&r.add(i),Rt(this)}parseEditorState(t,e){let n=typeof t=="string"?JSON.parse(t):t;return Yu(n,this,e)}read(t){return Rt(this),this.getEditorState().read(t,{editor:this})}update(t,e){Ee(this,t,e)}updateAndCommit(t,e){this.update(t,e),this.commitUpdates()}focus(t,e={}){let n=this._rootElement;n!==null&&(n.setAttribute("autocapitalize","off"),Ee(this,()=>{let r=C(),i=H();r!==null?r.dirty=!0:i.getChildrenSize()!==0&&(e.defaultSelection==="rootStart"?i.selectStart():i.selectEnd())},{onUpdate:()=>{n.removeAttribute("autocapitalize"),t&&t()},tag:"focus"}),this._pendingEditorState===null&&n.removeAttribute("autocapitalize"))}commitUpdates(){Rt(this)}blur(){let t=this._rootElement;t!==null&&t.blur();let e=ye(this._window);e!==null&&e.removeAllRanges()}isEditable(){return this._editable}setEditable(t){this._editable!==t&&(this._editable=t,Hn("editable",this,!0,t))}toJSON(){return{editorState:this._editorState.toJSON()}}};p(eo,"version");eo.version="0.17.1";var Fi=0,Jl=1,Ql=2,Et=0,XN=1,of=2,jN=3,GN=4;function JN(o,t,e){let n=o._nodeMap,r=[];for(let i of t){let s=n.get(i);s!==void 0&&r.push(s)}for(let[i,s]of e){if(!s)continue;let l=n.get(i);l!==void 0&&!ne(l)&&r.push(l)}return r}function QN(o,t,e,n,r){if(o===null||e.size===0&&n.size===0&&!r)return Et;let i=t._selection,s=o._selection;if(r)return XN;if(!_(i)||!_(s)||!s.isCollapsed()||!i.isCollapsed())return Et;let l=JN(t,e,n);if(l.length===0)return Et;if(l.length>1){let b=t._nodeMap,x=b.get(i.anchor.key),S=b.get(s.anchor.key);return x&&S&&!o._nodeMap.has(x.__key)&&L(x)&&x.__text.length===1&&i.anchor.offset===1?of:Et}let a=l[0],d=o._nodeMap.get(a.__key);if(!L(d)||!L(a)||d.__mode!==a.__mode)return Et;let u=d.__text,m=a.__text;if(u===m)return Et;let c=i.anchor,f=s.anchor;if(c.key!==f.key||c.type!=="text")return Et;let g=c.offset,h=f.offset,N=m.length-u.length;return N===1&&h===g-1?of:N===-1&&h===g+1?jN:N===-1&&h===g?GN:Et}function ex(o,t,e){let n=t._nodeMap.get(o),r=e._nodeMap.get(o),i=t._selection,s=e._selection;return!(_(i)&&_(s)&&i.anchor.type==="element"&&i.focus.type==="element"&&s.anchor.type==="text"&&s.focus.type==="text")&&L(n)&&L(r)&&n.__parent===r.__parent?JSON.stringify(t.read(()=>n.exportJSON()))===JSON.stringify(e.read(()=>r.exportJSON())):!1}function tx(o,t){let e=Date.now(),n=Et;return(r,i,s,l,a,d)=>{let u=Date.now();if(d.has("historic"))return n=Et,e=u,Ql;let m=QN(r,i,l,a,o.isComposing()),c=(()=>{let f=s===null||s.editor===o,g=d.has("history-push");if(!g&&f&&d.has("history-merge"))return Fi;if(r===null)return Jl;let N=i._selection;if(!(l.size>0||a.size>0))return N!==null?Fi:Ql;if(g===!1&&m!==Et&&m===n&&u{let m=t.current,c=t.redoStack,f=t.undoStack,g=m===null?null:m.editorState;if(m!==null&&s===g)return;let h=n(l,s,m,a,d,u);if(h===Jl)c.length!==0&&(t.redoStack=[],o.dispatchCommand(po,!1)),m!==null&&(f.push({...m}),o.dispatchCommand(go,!0));else if(h===Ql)return;t.current={editor:o,editorState:s}};return Dt(o.registerCommand(co,()=>(nx(o,t),!0),G),o.registerCommand(uo,()=>(ox(o,t),!0),G),o.registerCommand(qs,()=>(nf(t),!1),G),o.registerCommand(Ys,()=>(nf(t),o.dispatchCommand(po,!1),o.dispatchCommand(go,!1),!0),G),o.registerUpdateListener(r))}function ta(){return{current:null,redoStack:[],undoStack:[]}}var sf=o=>me?(o||window).getSelection():null;function lf(o,t=C()){return t==null&&E(!1,"Expected valid LexicalSelection"),_(t)&&t.isCollapsed()||t.getNodes().length===0?"":Ri(o,t)}function af(o,t=C()){return t==null&&E(!1,"Expected valid LexicalSelection"),_(t)&&t.isCollapsed()||t.getNodes().length===0?null:JSON.stringify(cf(o,t))}function Hi(o,t,e){let n=o.getData("application/x-lexical-editor");if(n)try{let s=JSON.parse(n);if(s.namespace===e._config.namespace&&Array.isArray(s.nodes)){let l=uf(s.nodes);return oa(e,l,t)}}catch{}let r=o.getData("text/html");if(r)try{let l=new DOMParser().parseFromString(r,"text/html"),a=Ai(e,l);return oa(e,a,t)}catch{}let i=o.getData("text/plain")||o.getData("text/uri-list");if(i!=null)if(_(t)){let s=i.split(/(\r?\n|\t)/);s[s.length-1]===""&&s.pop();for(let l=0;l0?a.text=d:r=!1}for(let d=0;d{o.update(()=>{a(rf(o,t,e))})});let n=o.getRootElement(),r=o._window==null?window.document:o._window.document,i=sf(o._window);if(n===null||i===null)return!1;let s=r.createElement("span");s.style.cssText="position: fixed; top: -1000px;",s.append(r.createTextNode("#")),n.append(s);let l=new Range;return l.setStart(s,0),l.setEnd(s,1),i.removeAllRanges(),i.addRange(l),new Promise((a,d)=>{let u=o.registerCommand(fo,m=>(Nt(m,ClipboardEvent)&&(u(),Un!==null&&(window.clearTimeout(Un),Un=null),a(rf(o,m,e))),!0),Ie);Un=window.setTimeout(()=>{u(),Un=null,a(!1)},ix),r.execCommand("copy"),s.remove()})}function rf(o,t,e){if(e===void 0){let r=sf(o._window);if(!r)return!1;let i=r.anchorNode,s=r.focusNode;if(i!==null&&s!==null&&!jt(o,i,s))return!1;let l=C();if(l===null)return!1;e=Ki(l)}t.preventDefault();let n=t.clipboardData;return n===null?!1:(ff(n,e),!0)}var sx=[["text/html",lf],["application/x-lexical-editor",af]];function Ki(o=C()){let t={"text/plain":o?o.getTextContent():""};if(o){let e=ml();for(let[n,r]of sx){let i=r(e,o);i!==null&&(t[n]=i)}}return t}function ff(o,t){for(let e in t){let n=t[e];n!==void 0&&o.setData(e,n)}}function Ui(o,t){if(typeof document.caretRangeFromPoint<"u"){let e=document.caretRangeFromPoint(o,t);return e===null?null:{node:e.startContainer,offset:e.startOffset}}else if(document.caretPositionFromPoint!=="undefined"){let e=document.caretPositionFromPoint(o,t);return e===null?null:{node:e.offsetNode,offset:e.offset}}else return null}var mf=P("DRAG_DROP_PASTE_FILE");function lx(o,t){o.preventDefault(),t.update(()=>{let e=C(),n=Nt(o,InputEvent)||Nt(o,KeyboardEvent)?null:o.clipboardData;n!=null&&e!==null&&Hi(n,e,t)},{tag:"paste"})}async function ax(o,t){await zn(t,Nt(o,ClipboardEvent)?o:null),t.update(()=>{let e=C();_(e)?e.removeText():Le(e)&&e.getNodes().forEach(n=>n.remove())})}function zi(o){let t=null;if(Nt(o,DragEvent)?t=o.dataTransfer:Nt(o,ClipboardEvent)&&(t=o.clipboardData),t===null)return[!1,[],!1];let e=t.types,n=e.includes("Files"),r=e.includes("text/html")||e.includes("text/plain");return[n,Array.from(t.files),r]}function Wi(o){let t=ee(o);return F(t)}function dx(o){let t=o.focus;return t.key==="root"&&t.offset===H().getChildrenSize()}function na(o){return Dt(o.registerCommand(Ht,e=>{let n=C();return Le(n)?(n.clear(),!0):!1},0),o.registerCommand(Je,e=>{let n=C();return _(n)?(n.deleteCharacter(e),!0):!1},G),o.registerCommand(St,e=>{let n=C();return _(n)?(n.deleteWord(e),!0):!1},G),o.registerCommand(ut,e=>{let n=C();return _(n)?(n.deleteLine(e),!0):!1},G),o.registerCommand(ct,e=>{let n=C();if(typeof e=="string")n!==null&&n.insertText(e);else{if(n===null)return!1;let r=e.dataTransfer;if(r!=null)Hi(r,n,o);else if(_(n)){let i=e.data;return i&&n.insertText(i),!0}}return!0},G),o.registerCommand(hn,()=>{let e=C();return _(e)?(e.removeText(),!0):!1},G),o.registerCommand(xe,e=>{let n=C();return _(n)?(n.formatText(e),!0):!1},G),o.registerCommand(Kt,e=>{let n=C();return _(n)?(n.insertLineBreak(e),!0):!1},G),o.registerCommand(Ut,()=>{let e=C();return _(e)?(e.insertParagraph(),!0):!1},G),o.registerCommand(zs,()=>(Me([vt()]),!0),G),o.registerCommand(zt,e=>{let n=C();if(Le(n)&&!Wi(e.target)){let r=n.getNodes();if(r.length>0)return r[0].selectPrevious(),!0}else if(_(n)){let r=Jt(n.focus,!0);if(!e.shiftKey&&F(r)&&!r.isIsolated()&&!r.isInline())return r.selectPrevious(),e.preventDefault(),!0}return!1},G),o.registerCommand(Wt,e=>{let n=C();if(Le(n)){let r=n.getNodes();if(r.length>0)return r[0].selectNext(0,0),!0}else if(_(n)){if(dx(n))return e.preventDefault(),!0;let r=Jt(n.focus,!1);if(!e.shiftKey&&F(r)&&!r.isIsolated()&&!r.isInline())return r.selectNext(),e.preventDefault(),!0}return!1},G),o.registerCommand(Ro,e=>{let n=C();if(Le(n)){let r=n.getNodes();if(r.length>0)return e.preventDefault(),r[0].selectPrevious(),!0}if(!_(n))return!1;if(vi(n,!0)){let r=e.shiftKey;return e.preventDefault(),Di(n,r,!0),!0}return!1},G),o.registerCommand(Ao,e=>{let n=C();if(Le(n)&&!Wi(e.target)){let i=n.getNodes();if(i.length>0)return e.preventDefault(),i[0].selectNext(0,0),!0}if(!_(n))return!1;let r=e.shiftKey;return vi(n,!1)?(e.preventDefault(),Di(n,r,!1),!0):!1},G),o.registerCommand(qt,e=>{if(Wi(e.target))return!1;let n=C();return _(n)?(e.preventDefault(),o.dispatchCommand(Je,!0)):!1},G),o.registerCommand(Yt,e=>{if(Wi(e.target))return!1;let n=C();return _(n)?(e.preventDefault(),o.dispatchCommand(Je,!1)):!1},G),o.registerCommand(Ke,e=>{let n=C();if(!_(n))return!1;if(e!==null){if((Lt||Zt||Vt)&&ho)return!1;if(e.preventDefault(),e.shiftKey)return o.dispatchCommand(Kt,!1)}return o.dispatchCommand(Ut,void 0)},G),o.registerCommand(ko,()=>{let e=C();return _(e)?(o.blur(),!0):!1},G),o.registerCommand($o,e=>{let[,n]=zi(e);if(n.length>0){let i=e.clientX,s=e.clientY,l=Ui(i,s);if(l!==null){let{offset:a,node:d}=l,u=ee(d);if(u!==null){let m=Xo();if(L(u))m.anchor.set(u.getKey(),a,"text"),m.focus.set(u.getKey(),a,"text");else{let f=u.getParentOrThrow().getKey(),g=u.getIndexWithinParent()+1;m.anchor.set(f,g,"element"),m.focus.set(f,g,"element")}let c=Po(m);Y(c)}o.dispatchCommand(mf,n)}return e.preventDefault(),!0}let r=C();return!!_(r)},G),o.registerCommand(sr,e=>{let[n]=zi(e),r=C();return!(n&&!_(r))},G),o.registerCommand(lr,e=>{let[n]=zi(e),r=C();if(n&&!_(r))return!1;let i=e.clientX,s=e.clientY,l=Ui(i,s);if(l!==null){let a=ee(l.node);F(a)&&e.preventDefault()}return!0},G),o.registerCommand(Nn,()=>(ul(),!0),G),o.registerCommand(fo,e=>(zn(o,Nt(e,ClipboardEvent)?e:null),!0),G),o.registerCommand(mo,e=>(ax(e,o),!0),G),o.registerCommand(ao,e=>{let[,n,r]=zi(e);return n.length>0&&!r?(o.dispatchCommand(mf,n),!0):Ln(e.target)?!1:C()!==null?(lx(e,o),!0):!1},G))}var Jo=class o extends V{constructor(e,n){super(n);p(this,"__id","");p(this,"__category","info");p(this,"__alignment","");p(this,"__inset",0);this.__category=e}static getType(){return"callout"}static clone(e){let n=new o(e.__category,e.__key);return n.__id=e.__id,n.__alignment=e.__alignment,n.__inset=e.__inset,n}setCategory(e){let n=this.getWritable();n.__category=e}getCategory(){return this.getLatest().__category}setId(e){let n=this.getWritable();n.__id=e}getId(){return this.getLatest().__id}setAlignment(e){let n=this.getWritable();n.__alignment=e}getAlignment(){return this.getLatest().__alignment}setInset(e){let n=this.getWritable();n.__inset=e}getInset(){return this.getLatest().__inset}createDOM(e,n){let r=document.createElement("p");return r.classList.add("callout",this.__category||""),st(r,this),r}updateDOM(e){return e.__category!==this.__category||Lo(e,this)}insertNewAfter(e,n){let r=e?e.anchor.offset:0,i=r===this.getTextContentSize()||!e?I():Wn(this.__category);if(i.setDirection(this.getDirection()),this.insertAfter(i,n),r===0&&!this.isEmpty()&&e){let s=I();s.select(),this.replace(s,!0)}return i}static importDOM(){return{p(e){return e.classList.contains("callout")?{conversion:n=>{let r="info",i=["info","success","warning","danger"];for(let l of i)if(n.classList.contains(l)){r=l;break}let s=new o(r);return it(n,s),{node:s}},priority:3}:null}}}exportJSON(){return{...super.exportJSON(),type:"callout",version:1,category:this.__category,id:this.__id,alignment:this.__alignment,inset:this.__inset}}static importJSON(e){let n=Wn(e.category);return lt(e,n),n}};function Wn(o="info"){return new Jo(o)}function ra(o){return o instanceof Jo}function ia(o,t="info"){return o instanceof Jo&&o.getCategory()===t}var Qo=class o extends V{constructor(e,n={},r){super(r);p(this,"__url");p(this,"__target");p(this,"__rel");p(this,"__title");let{target:i=null,rel:s=null,title:l=null}=n;this.__url=e,this.__target=i,this.__rel=s,this.__title=l}static getType(){return"link"}static clone(e){return new o(e.__url,{rel:e.__rel,target:e.__target,title:e.__title},e.__key)}createDOM(e){let n=document.createElement("a");return n.href=this.__url,this.__target!==null&&(n.target=this.__target),this.__rel!==null&&(n.rel=this.__rel),this.__title!==null&&(n.title=this.__title),Ce(n,e.theme.link),n}updateDOM(e,n,r){if(n instanceof HTMLAnchorElement){let i=this.__url,s=this.__target,l=this.__rel,a=this.__title;i!==e.__url&&(n.href=i),s!==e.__target&&(s?n.target=s:n.removeAttribute("target")),l!==e.__rel&&(l?n.rel=l:n.removeAttribute("rel")),a!==e.__title&&(a?n.title=a:n.removeAttribute("title"))}return!1}static importDOM(){return{a:e=>({conversion:cx,priority:1})}}static importJSON(e){let n=Tt(e.url,{rel:e.rel,target:e.target,title:e.title});return n.setDirection(e.direction),n}exportJSON(){return{...super.exportJSON(),rel:this.getRel(),target:this.getTarget(),title:this.getTitle(),type:"link",url:this.getURL(),version:1}}getURL(){return this.getLatest().__url}setURL(e){let n=this.getWritable();n.__url=e}getTarget(){return this.getLatest().__target}setTarget(e){let n=this.getWritable();n.__target=e}getRel(){return this.getLatest().__rel}setRel(e){let n=this.getWritable();n.__rel=e}getTitle(){return this.getLatest().__title}setTitle(e){let n=this.getWritable();n.__title=e}insertNewAfter(e,n=!0){let r=Tt(this.__url,{rel:this.__rel,target:this.__target,title:this.__title});return this.insertAfter(r,n),r}canInsertTextBefore(){return!1}canInsertTextAfter(){return!1}canBeEmpty(){return!1}isInline(){return!0}extractWithChild(e,n,r){if(!_(n))return!1;let i=n.anchor.getNode(),s=n.focus.getNode();return this.isParentOf(i)&&this.isParentOf(s)&&n.getTextContent().length>0}isEmailURI(){return this.__url.startsWith("mailto:")}isWebSiteURI(){return this.__url.startsWith("https://")||this.__url.startsWith("http://")}};function cx(o){let t=null;if(Ni(o)){let e=o.textContent;(e!==null&&e!==""||o.children.length>0)&&(t=Tt(o.getAttribute("href")||"",{rel:o.getAttribute("rel"),target:o.getAttribute("target"),title:o.getAttribute("title")}))}return{node:t}}function Tt(o,t){return re(new Qo(o,t))}function $t(o){return o instanceof Qo}var O0=P("TOGGLE_LINK_COMMAND");var en=class o extends V{constructor(e,n,r){super(r);p(this,"__src","");p(this,"__alt","");p(this,"__width",0);p(this,"__height",0);p(this,"__alignment","");this.__src=e,n.alt&&(this.__alt=n.alt),n.width&&(this.__width=n.width),n.height&&(this.__height=n.height)}static getType(){return"image"}static clone(e){let n=new o(e.__src,{alt:e.__alt,width:e.__width,height:e.__height},e.__key);return n.__alignment=e.__alignment,n}setSrc(e){let n=this.getWritable();n.__src=e}getSrc(){return this.getLatest().__src}setAltText(e){let n=this.getWritable();n.__alt=e}getAltText(){return this.getLatest().__alt}setHeight(e){let n=this.getWritable();n.__height=e}getHeight(){return this.getLatest().__height}setWidth(e){let n=this.getWritable();n.__width=e}getWidth(){return this.getLatest().__width}setAlignment(e){let n=this.getWritable();n.__alignment=e}getAlignment(){return this.getLatest().__alignment}isInline(){return!0}createDOM(e,n){let r=document.createElement("img");return r.setAttribute("src",this.__src),this.__width&&r.setAttribute("width",String(this.__width)),this.__height&&r.setAttribute("height",String(this.__height)),this.__alt&&r.setAttribute("alt",this.__alt),this.__alignment&&r.classList.add("align-"+this.__alignment),r.addEventListener("click",i=>{n.update(()=>{this.select()})}),r}updateDOM(e,n){return e.__src!==this.__src&&n.setAttribute("src",this.__src),e.__width!==this.__width&&(this.__width?n.setAttribute("width",String(this.__width)):n.removeAttribute("width")),e.__height!==this.__height&&(this.__height?n.setAttribute("height",String(this.__height)):n.removeAttribute("height")),e.__alt!==this.__alt&&(this.__alt?n.setAttribute("alt",String(this.__alt)):n.removeAttribute("alt")),e.__alignment!==this.__alignment&&(e.__alignment&&n.classList.remove("align-"+e.__alignment),this.__alignment&&n.classList.add("align-"+this.__alignment)),!1}static importDOM(){return{img(e){return{conversion:n=>{let r=n.getAttribute("src")||"",i={alt:n.getAttribute("alt")||"",height:Number.parseInt(n.getAttribute("height")||"0"),width:Number.parseInt(n.getAttribute("width")||"0")},s=new o(r,i);return s.setAlignment($r(n)),{node:s}},priority:3}}}}exportJSON(){return{...super.exportJSON(),type:"image",version:1,src:this.__src,alt:this.__alt,height:this.__height,width:this.__width,alignment:this.__alignment}}static importJSON(e){let n=tn(e.src,{alt:e.alt,width:e.width,height:e.height});return n.setAlignment(e.alignment),n}};function tn(o,t={}){return new en(o,t)}function je(o){return o instanceof en}var qn=class o extends V{constructor(){super(...arguments);p(this,"__id","");p(this,"__summary","");p(this,"__open",!1)}static getType(){return"details"}setId(e){let n=this.getWritable();n.__id=e}getId(){return this.getLatest().__id}setSummary(e){let n=this.getWritable();n.__summary=e}getSummary(){return this.getLatest().__summary}setOpen(e){let n=this.getWritable();n.__open=e}getOpen(){return this.getLatest().__open}static clone(e){let n=new o(e.__key);return n.__id=e.__id,n.__dir=e.__dir,n.__summary=e.__summary,n.__open=e.__open,n}createDOM(e,n){let r=document.createElement("details");this.__id&&r.setAttribute("id",this.__id),this.__dir&&r.setAttribute("dir",this.__dir),this.__open&&r.setAttribute("open","true");let i=document.createElement("summary");return i.textContent=this.__summary,i.setAttribute("contenteditable","false"),i.addEventListener("click",s=>{s.preventDefault(),n.update(()=>{this.select()})}),r.append(i),r}updateDOM(e,n){return e.__open!==this.__open&&n.toggleAttribute("open",this.__open),e.__id!==this.__id||e.__dir!==this.__dir||e.__summary!==this.__summary}static importDOM(){return{details(e){return{conversion:n=>{let r=new o;n.id&&r.setId(n.id),n.dir&&r.setDirection(Pr(n));let i=Array.from(n.children).find(s=>s.nodeName==="SUMMARY");return r.setSummary(i?.textContent||""),{node:r}},priority:3}},summary(e){return{conversion:n=>({node:"ignore"}),priority:3}}}}exportDOM(e){let n=this.createDOM(e._config,e),r=n.querySelectorAll("[contenteditable]");for(let i of r)i.removeAttribute("contenteditable");return n.removeAttribute("open"),{element:n}}exportJSON(){return{...super.exportJSON(),type:"details",version:1,id:this.__id,summary:this.__summary}}static importJSON(e){let n=sa();return n.setId(e.id),n.setDirection(e.direction),n}};function sa(){return new qn}function $e(o){return o instanceof qn}function la(o){let t=1,e=o.getParent();for(;e!=null;){if(X(e)){let n=e.getParent();if(z(n)){t++,e=n.getParent();continue}E(!1,"A ListItemNode must have a ListNode for a parent.")}return t}return t}function aa(o){let t=o.getParent();z(t)||E(!1,"A ListItemNode must have a ListNode for a parent.");let e=t;for(;e!==null;)e=e.getParent(),z(e)&&(t=e);return t}function da(o){let t=[],e=o.getChildren().filter(X);for(let n=0;n{let e=C();if(e!==null){let n=e.getNodes();if(_(e)){let i=e.getStartEndPoints();E(i!==null,"insertList: anchor should be defined");let[s]=i,l=s.getNode(),a=l.getParent();if(hf(l,n)){let d=be(t);if(pe(a)){l.replace(d);let u=Pe();d.append(u)}else if(X(l)){let u=l.getParentOrThrow();Br(d,u.getChildren()),u.replace(d)}return}}let r=new Set;for(let i=0;i0&&o.append(...r),t.remove()}function ua(o){o.update(()=>{let t=C();if(_(t)){let e=new Set,n=t.getNodes(),r=t.anchor.getNode();if(hf(r,n))e.add(aa(r));else for(let i=0;i{if(E(X(e),"node is not a ListItemNode"),e.__checked==null)return;let n=e.getParent();z(n)&&n.getListType()!=="check"&&e.getChecked()!=null&&e.setChecked(void 0)}}static importDOM(){return{li:()=>({conversion:ux,priority:0})}}static importJSON(e){let n=Pe();return n.setChecked(e.checked),n.setValue(e.value),n.setDirection(e.direction),n}exportDOM(e){let n=this.createDOM(e._config);if(n.classList.contains("task-list-item")){let r=y("input",{type:"checkbox",disabled:"disabled"});n.hasAttribute("checked")&&(r.setAttribute("checked","checked"),n.removeAttribute("checked")),n.prepend(r)}return{element:n}}exportJSON(){return{...super.exportJSON(),checked:this.getChecked(),type:"listitem",value:this.getValue(),version:1}}append(...e){for(let n=0;n{e.append(i)})),this.remove(),r.getChildrenSize()===0&&r.remove(),e}insertAfter(e,n=!0){let r=this.getParentOrThrow();if(z(r)||E(!1,"insertAfter: list node is not parent of list item node"),X(e))return super.insertAfter(e,n);let i=this.getNextSiblings();if(r.insertAfter(e,n),i.length!==0){let s=be(r.getListType());i.forEach(l=>s.append(l)),e.insertAfter(s,n)}return e}remove(e){let n=this.getPreviousSibling(),r=this.getNextSibling();super.remove(e),n&&r&&Yn(n)&&Yn(r)&&(qi(n.getFirstChild(),r.getFirstChild()),r.remove())}insertNewAfter(e,n=!0){if(this.getTextContent().trim()===""&&this.isLastChild()){let i=this.getParentOrThrow(),s=i.getParent();if(X(s))return s.insertAfter(this),this.selectStart(),null;{let l=I();return i.insertAfter(l,n),this.remove(),l}}let r=Pe(this.__checked==null?void 0:!1);return this.insertAfter(r,n),r}collapseAtStart(e){let n=I();this.getChildren().forEach(a=>n.append(a));let i=this.getParentOrThrow(),s=i.getParentOrThrow(),l=X(s);if(i.getChildrenSize()===1)if(l)i.remove(),s.select();else{i.insertBefore(n),i.remove();let a=e.anchor,d=e.focus,u=n.getKey();a.type==="element"&&a.getNode().is(this)&&a.set(u,a.offset,"element"),d.type==="element"&&d.getNode().is(this)&&d.set(u,d.offset,"element")}else i.insertBefore(n),this.remove();return!0}getValue(){return this.getLatest().__value}setValue(e){let n=this.getWritable();n.__value=e}getChecked(){let e=this.getLatest(),n,r=this.getParent();return z(r)&&(n=r.getListType()),n==="check"?!!e.__checked:void 0}setChecked(e){let n=this.getWritable();n.__checked=e}toggleChecked(){this.setChecked(!this.__checked)}canInsertAfter(e){return X(e)}canReplaceWith(e){return X(e)}canMergeWith(e){return Ze(e)||X(e)}extractWithChild(e,n){if(!_(n))return!1;let r=n.anchor.getNode(),i=n.focus.getNode();return this.isParentOf(r)&&this.isParentOf(i)&&this.getTextContent().length===n.getTextContent().length}isParentRequired(){return!0}createParentElementNode(){return be("bullet")}canMergeWhenEmpty(){return!0}};function Ef(o){let t=o.getChildren(),e=!1,n=!1;for(let r of t)z(r)?n=!0:r.getTextContent().trim().length>0&&(e=!0);return n&&!e}function Tf(o,t){let e=!z(t.getFirstChild());o.classList.toggle("task-list-item",e),t.__checked?o.setAttribute("checked","checked"):o.removeAttribute("checked")}function ux(o){if(o.classList.contains("task-list-item")){for(let r of o.children)if(r.tagName==="INPUT")return fx(r)}let e=o.getAttribute("aria-checked");return{node:Pe(e==="true"?!0:e==="false"?!1:void 0)}}function fx(o){if(!(o.getAttribute("type")==="checkbox"))return{node:null};let e=o.hasAttribute("checked");return{node:Pe(e)}}function Pe(o){return re(new Pt(void 0,o))}function X(o){return o instanceof Pt}var wo=class o extends V{constructor(e,n,r){super(r);p(this,"__tag");p(this,"__start");p(this,"__listType");p(this,"__id","");let i=gx[e]||e;this.__listType=i,this.__tag=i==="number"?"ol":"ul",this.__start=n}static getType(){return"list"}static clone(e){let n=new o(e.__listType,e.__start,e.__key);return n.__id=e.__id,n.__dir=e.__dir,n}getTag(){return this.__tag}setId(e){let n=this.getWritable();n.__id=e}getId(){return this.getLatest().__id}setListType(e){let n=this.getWritable();n.__listType=e,n.__tag=e==="number"?"ol":"ul"}getListType(){return this.__listType}getStart(){return this.__start}createDOM(e,n){let r=this.__tag,i=document.createElement(r);return this.__start!==1&&i.setAttribute("start",String(this.__start)),i.__lexicalListType=this.__listType,Cf(i,e.theme,this),this.__id&&i.setAttribute("id",this.__id),this.__dir&&i.setAttribute("dir",this.__dir),i}updateDOM(e,n,r){return e.__tag!==this.__tag||e.__dir!==this.__dir||e.__id!==this.__id?!0:(Cf(n,r.theme,this),!1)}static transform(){return e=>{E(z(e),"node is not a ListNode"),xf(e),Nf(e)}}static importDOM(){return{ol:()=>({conversion:bf,priority:0}),ul:()=>({conversion:bf,priority:0})}}static importJSON(e){let n=be(e.listType,e.start);return n.setId(e.id),n.setDirection(e.direction),n}exportDOM(e){let{element:n}=super.exportDOM(e);return n&&ge(n)&&(this.__start!==1&&n.setAttribute("start",String(this.__start)),this.__listType==="check"&&n.setAttribute("__lexicalListType","check")),{element:n}}exportJSON(){return{...super.exportJSON(),listType:this.getListType(),start:this.getStart(),tag:this.getTag(),type:"list",version:1,id:this.__id}}canBeEmpty(){return!1}canIndent(){return!1}append(...e){for(let n=0;n1?n.push(...g):r.push(...g)}}r.length>0&&Oi(o,...r),n.length>0&&Ce(o,...n)}function mx(o){let t=[];for(let e of o)X(e)?t.push(e):t.push(pf(e));return t}function px(o){if(o.getAttribute("__lexicallisttype")==="check"||o.classList.contains("contains-task-list"))return!0;for(let t of o.childNodes)if(ge(t)&&(t.hasAttribute("aria-checked")||t.classList.contains("task-list-item")||t.firstElementChild&&t.firstElementChild.matches('input[type="checkbox"]')))return!0;return!1}function bf(o){let t=o.nodeName.toLowerCase(),e=null;if(t==="ol"){let n=o.start;e=be("number",n)}else t==="ul"&&(px(o)?e=be("check"):e=be("bullet"));return o.id&&e&&e.setId(o.id),o.dir&&e&&e.setDirection(Pr(o)),{after:mx,node:e}}var gx={ol:"number",ul:"bullet"};function be(o,t=1){return re(new wo(o,t))}function z(o){return o instanceof wo}var sM=P("INSERT_UNORDERED_LIST_COMMAND"),lM=P("INSERT_ORDERED_LIST_COMMAND"),aM=P("INSERT_CHECK_LIST_COMMAND"),dM=P("REMOVE_LIST_COMMAND");var ie={BOTH:3,COLUMN:2,NO_STATUS:0,ROW:1},no=class o extends V{constructor(e=ie.NO_STATUS,n=1,r,i){super(i);p(this,"__colSpan");p(this,"__rowSpan");p(this,"__headerState");p(this,"__width");p(this,"__backgroundColor");p(this,"__styles",new Map);p(this,"__alignment","");this.__colSpan=n,this.__rowSpan=1,this.__headerState=e,this.__width=r,this.__backgroundColor=null}static getType(){return"tablecell"}static clone(e){let n=new o(e.__headerState,e.__colSpan,e.__width,e.__key);return n.__rowSpan=e.__rowSpan,n.__backgroundColor=e.__backgroundColor,n.__styles=new Map(e.__styles),n.__alignment=e.__alignment,n}static importDOM(){return{td:e=>({conversion:_f,priority:0}),th:e=>({conversion:_f,priority:0})}}static importJSON(e){let n=Be(e.headerState,e.colSpan,e.width);return e.rowSpan&&n.setRowSpan(e.rowSpan),n.setStyles(new Map(Object.entries(e.styles))),n.setAlignment(e.alignment),n}createDOM(e){let n=document.createElement(this.getTag());this.__width&&(n.style.width=`${this.__width}px`),this.__colSpan>1&&(n.colSpan=this.__colSpan),this.__rowSpan>1&&(n.rowSpan=this.__rowSpan),this.__backgroundColor!==null&&(n.style.backgroundColor=this.__backgroundColor),Ce(n,e.theme.tableCell,this.hasHeader()&&e.theme.tableCellHeader);for(let[r,i]of this.__styles.entries())n.style.setProperty(r,i);return this.__alignment&&n.classList.add("align-"+this.__alignment),n}exportDOM(e){let{element:n}=super.exportDOM(e);return{element:n}}exportJSON(){return{...super.exportJSON(),backgroundColor:this.getBackgroundColor(),colSpan:this.__colSpan,headerState:this.__headerState,rowSpan:this.__rowSpan,type:"tablecell",width:this.getWidth(),styles:Object.fromEntries(this.__styles),alignment:this.__alignment}}getColSpan(){return this.__colSpan}setColSpan(e){return this.getWritable().__colSpan=e,this}getRowSpan(){return this.__rowSpan}setRowSpan(e){return this.getWritable().__rowSpan=e,this}getTag(){return this.hasHeader()?"th":"td"}setHeaderStyles(e){let n=this.getWritable();return n.__headerState=e,this.__headerState}getHeaderStyles(){return this.getLatest().__headerState}setWidth(e){let n=this.getWritable();return n.__width=e,this.__width}getWidth(){return this.getLatest().__width}clearWidth(){let e=this.getWritable();e.__width=void 0}getStyles(){let e=this.getLatest();return new Map(e.__styles)}setStyles(e){let n=this.getWritable();n.__styles=new Map(e)}setAlignment(e){let n=this.getWritable();n.__alignment=e}getAlignment(){return this.getLatest().__alignment}updateTag(e){let r=e.toLowerCase()==="th"?ie.ROW:ie.NO_STATUS,i=this.getWritable();i.__headerState=r}getBackgroundColor(){return this.getLatest().__backgroundColor}setBackgroundColor(e){this.getWritable().__backgroundColor=e}toggleHeaderStyle(e){let n=this.getWritable();return(n.__headerState&e)===e?n.__headerState-=e:n.__headerState+=e,n}hasHeaderState(e){return(this.getHeaderStyles()&e)===e}hasHeader(){return this.getLatest().__headerState!==ie.NO_STATUS}updateDOM(e){return e.__headerState!==this.__headerState||e.__width!==this.__width||e.__colSpan!==this.__colSpan||e.__rowSpan!==this.__rowSpan||e.__backgroundColor!==this.__backgroundColor||e.__styles!==this.__styles||e.__alignment!==this.__alignment}isShadowRoot(){return!0}collapseAtStart(){return!0}canBeEmpty(){return!1}canIndent(){return!1}};function _f(o){let t=o,e=o.nodeName.toLowerCase(),n;/^(\d+(?:\.\d+)?)px$/.test(t.style.width)&&(n=parseFloat(t.style.width));let i=Be(e==="th"?ie.ROW:ie.NO_STATUS,t.colSpan,n);i.__rowSpan=t.rowSpan;let s=t.style,l=s.textDecoration.split(" "),a=s.fontWeight==="700"||s.fontWeight==="bold",d=l.includes("line-through"),u=s.fontStyle==="italic",m=l.includes("underline");if(o instanceof HTMLElement){let f=Bn(o);f.delete("background-color"),i.setStyles(f),i.setAlignment($r(o))}let c=s.backgroundColor||null;return c&&i.setBackgroundColor(c),{after:f=>(f.length===0&&f.push(I()),f),forChild:(f,g)=>{if(D(g)&&!T(f)){let h=I();return Ae(f)&&f.getTextContent()===` `?null:(L(f)&&(a&&f.toggleFormat("bold"),d&&f.toggleFormat("strikethrough"),u&&f.toggleFormat("italic"),m&&f.toggleFormat("underline")),h.append(f),h)}return f},node:i}}function Be(o=ie.NO_STATUS,t=1,e){return re(new no(o,t,e))}function D(o){return o instanceof no}var hx=P("INSERT_TABLE_COMMAND");var ro=class o extends V{constructor(e){super(e);p(this,"__height");p(this,"__styles",new Map)}static getType(){return"tablerow"}static clone(e){let n=new o(e.__key);return n.__styles=new Map(e.__styles),n}static importDOM(){return{tr:e=>({conversion:Nx,priority:0})}}static importJSON(e){let n=on();return n.setStyles(new Map(Object.entries(e.styles))),n}exportJSON(){return{...super.exportJSON(),type:"tablerow",version:1,styles:Object.fromEntries(this.__styles),height:this.__height||0}}createDOM(e){let n=document.createElement("tr");this.__height&&(n.style.height=`${this.__height}px`);for(let[r,i]of this.__styles.entries())n.style.setProperty(r,i);return Ce(n,e.theme.tableRow),n}isShadowRoot(){return!0}getStyles(){let e=this.getLatest();return new Map(e.__styles)}setStyles(e){let n=this.getWritable();n.__styles=new Map(e)}setHeight(e){let n=this.getWritable();return n.__height=e,this.__height}getHeight(){return this.getLatest().__height}updateDOM(e){return e.__height!==this.__height||e.__styles!==this.__styles}canBeEmpty(){return!1}canIndent(){return!1}};function Nx(o){let t=on(),n=Yo(o.style.height);return t.setHeight(n),o instanceof HTMLElement&&t.setStyles(Bn(o)),{node:t}}function on(){return re(new ro)}function te(o){return o instanceof ro}var Zn=class o extends V{static getType(){return"caption"}static clone(t){return new o(t.__key)}createDOM(t,e){return document.createElement("caption")}updateDOM(t,e,n){return!1}isParentRequired(){return!0}canBeEmpty(){return!1}exportJSON(){return{...super.exportJSON(),type:"caption",version:1}}insertDOMIntoParent(t,e){return e.insertBefore(t,e.firstChild),!0}static importJSON(t){return fa()}static importDOM(){return{caption:t=>({conversion(e){return{node:fa()}},priority:0})}}};function fa(){return new Zn}function Fr(o){return o instanceof Zn}function ma(o){for(let t of o.getChildren())if(Fr(t))return!0;return!1}function yf(o,t=""){let e=fa(),n=q(t||" ");e.append(n),o.append(e)}function ga(o,t,e=!0){let n=Kr();for(let r=0;ro===ie.BOTH||o===t?t:ie.NO_STATUS;function Yi(o=!0){let t=C();E(_(t)||W(t),"Expected a RangeSelection or TableSelection");let e=t.focus.getNode(),[n,,r]=we(e),[i,s]=at(r,n,n),l=i[0].length,{startRow:a}=s;if(o){let d=a+n.__rowSpan-1,u=i[d],m=on();for(let f=0;f1;)if(k-=M.__colSpan,k>=0){let{cell:j,startRow:se}=x[k];$=j,B=se}else{N.append(h(v));continue e}$.insertAfter(h(v))}else M.setColSpan(M.__colSpan+1)}g!==null&&Hr(g)}function ha(){let o=C();E(_(o)||W(o),"Expected a RangeSelection or TableSelection");let t=o.anchor.getNode(),e=o.focus.getNode(),[n,,r]=we(t),[i]=we(e),[s,l,a]=at(r,n,i),{startRow:d}=l,{startRow:u}=a,m=u+i.__rowSpan-1;if(s.length===m-d+1){r.remove();return}let c=s[0].length,f=s[m+1],g=r.getChildAtIndex(m+1);for(let h=m;h>=d;h--){for(let b=c-1;b>=0;b--){let{cell:x,startRow:S,startColumn:v}=s[h][b];if(v===b&&(h===d&&S=d&&S+x.__rowSpan-1>m))if(x.setRowSpan(x.__rowSpan-(m-S+1)),E(g!==null,"Expected nextRowNode not to be null"),b===0)xa(g,x);else{let{cell:M}=f[b-1];M.insertAfter(x)}}let N=r.getChildAtIndex(h);E(te(N),"Expected GridNode childAtIndex(%s) to be RowNode",String(h)),N.remove()}if(f!==void 0){let{cell:h}=f[0];Hr(h)}else{let h=s[d-1],{cell:N}=h[0];Hr(N)}}function Na(){let o=C();E(_(o)||W(o),"Expected a RangeSelection or TableSelection");let t=o.anchor.getNode(),e=o.focus.getNode(),[n,,r]=we(t),[i]=we(e),[s,l,a]=at(r,n,i),{startColumn:d}=l,{startRow:u,startColumn:m}=a,c=Math.min(d,m),f=Math.max(d+n.__colSpan-1,m+i.__colSpan-1),g=f-c+1;if(s[0].length===f-c+1){r.selectPrevious(),r.remove();return}let N=s.length;for(let S=0;Sf){if(v===f){let A=f-R+1;M.setColSpan(M.__colSpan-A)}}else M.remove()}let b=s[u],x=d>m?b[d+n.__colSpan]:b[m+i.__colSpan];if(x!==void 0){let{cell:S}=x;Hr(S)}else{let S=m1){for(let l=1;l1){let[l,a]=at(r,e,e),{startColumn:d,startRow:u}=a,m;for(let c=1;c1&&(N+=x.__colSpan-1)}if(h===null)for(let N=0;N!Fr(d));for(let d=0;dx||h>S;){if(cx){let A=S-b,$=x+1;for(let B=0;B<=A;B++)v(d[b+B][$]);x=$}if(h>S){let A=x-N,$=S+1;for(let B=0;B<=A;B++)v(d[$][N+B]);S=$}}let M=[l],R=null;for(let A=f;A<=h;A++)for(let $=c;$<=g;$++){let{cell:B}=d[A][$],k=B.getParent();E(te(k),"Expected TableCellNode parent to be a TableRowNode"),k!==R&&M.push(k),M.push(B,...xx(B)),R=k}return ft()||(this._cachedNodes=M),M}getTextContent(){let t=this.getNodes().filter(n=>D(n)),e="";for(let n=0;n0;){let n=e.pop();E(n!==void 0,"Stack.length > 0; can't be undefined"),T(n)&&e.unshift(...n.getChildren()),n!==o&&t.push(n)}return t}var zr=class{constructor(t,e){p(this,"focusX");p(this,"focusY");p(this,"listenersToRemove");p(this,"table");p(this,"isHighlightingCells");p(this,"anchorX");p(this,"anchorY");p(this,"tableNodeKey");p(this,"anchorCell");p(this,"focusCell");p(this,"anchorCellNodeKey");p(this,"focusCellNodeKey");p(this,"editor");p(this,"tableSelection");p(this,"hasHijackedSelectionStyles");p(this,"isSelecting");this.isHighlightingCells=!1,this.anchorX=-1,this.anchorY=-1,this.focusX=-1,this.focusY=-1,this.listenersToRemove=new Set,this.tableNodeKey=e,this.editor=t,this.table={columns:0,domRows:[],rows:0},this.tableSelection=null,this.anchorCellNodeKey=null,this.focusCellNodeKey=null,this.anchorCell=null,this.focusCell=null,this.hasHijackedSelectionStyles=!1,this.trackTable(),this.isSelecting=!1}getTable(){return this.table}removeListeners(){Array.from(this.listenersToRemove).forEach(t=>t())}trackTable(){let t=new MutationObserver(e=>{this.editor.update(()=>{let n=!1;for(let i=0;i{let e=this.editor.getElementByKey(this.tableNodeKey);if(!e)throw new Error("Expected to find TableElement in DOM");this.table=nn(e),t.observe(e,{attributes:!0,childList:!0,subtree:!0})})}clearHighlight(){let t=this.editor;this.isHighlightingCells=!1,this.anchorX=-1,this.anchorY=-1,this.focusX=-1,this.focusY=-1,this.tableSelection=null,this.anchorCellNodeKey=null,this.focusCellNodeKey=null,this.anchorCell=null,this.focusCell=null,this.hasHijackedSelectionStyles=!1,this.enableHighlightStyle(),t.update(()=>{let e=Q(this.tableNodeKey);if(!K(e))throw new Error("Expected TableNode.");let n=t.getElementByKey(this.tableNodeKey);if(!n)throw new Error("Expected to find TableElement in DOM");let r=nn(n);Ur(t,r,null),Y(null),t.dispatchCommand(De,void 0)})}enableHighlightStyle(){let t=this.editor;t.update(()=>{let e=t.getElementByKey(this.tableNodeKey);if(!e)throw new Error("Expected to find TableElement in DOM");Oi(e,t._config.theme.tableSelection),e.classList.remove("disable-selection"),this.hasHijackedSelectionStyles=!1})}disableHighlightStyle(){let t=this.editor;t.update(()=>{let e=t.getElementByKey(this.tableNodeKey);if(!e)throw new Error("Expected to find TableElement in DOM");Ce(e,t._config.theme.tableSelection),this.hasHijackedSelectionStyles=!0})}updateTableTableSelection(t){if(t!==null&&t.tableKey===this.tableNodeKey){let e=this.editor;this.tableSelection=t,this.isHighlightingCells=!0,this.disableHighlightStyle(),Ur(e,this.table,this.tableSelection)}else t==null?this.clearHighlight():(this.tableNodeKey=t.tableKey,this.updateTableTableSelection(t))}setFocusCellForSelection(t,e=!1){let n=this.editor;n.update(()=>{let r=Q(this.tableNodeKey);if(!K(r))throw new Error("Expected TableNode.");if(!n.getElementByKey(this.tableNodeKey))throw new Error("Expected to find TableElement in DOM");let s=t.x,l=t.y;if(this.focusCell=t,this.anchorCell!==null){let a=Ta(n._window);a&&a.setBaseAndExtent(this.anchorCell.elem,0,this.focusCell.elem,0)}if(!this.isHighlightingCells&&(this.anchorX!==s||this.anchorY!==l||e))this.isHighlightingCells=!0,this.disableHighlightStyle();else if(s===this.focusX&&l===this.focusY)return;if(this.focusX=s,this.focusY=l,this.isHighlightingCells){let a=ee(t.elem);if(this.tableSelection!=null&&this.anchorCellNodeKey!=null&&D(a)&&r.is(vo(a))){let d=a.getKey();this.tableSelection=this.tableSelection.clone()||ji(),this.focusCellNodeKey=d,this.tableSelection.set(this.tableNodeKey,this.anchorCellNodeKey,this.focusCellNodeKey),Y(this.tableSelection),n.dispatchCommand(De,void 0),Ur(n,this.table,this.tableSelection)}}})}setAnchorCellForSelection(t){this.isHighlightingCells=!1,this.anchorCell=t,this.anchorX=t.x,this.anchorY=t.y,this.editor.update(()=>{let e=ee(t.elem);if(D(e)){let n=e.getKey();this.tableSelection=this.tableSelection!=null?this.tableSelection.clone():ji(),this.anchorCellNodeKey=n}})}formatCells(t){this.editor.update(()=>{let e=C();W(e)||E(!1,"Expected grid selection");let n=Xo(),r=n.anchor,i=n.focus;e.getNodes().forEach(s=>{D(s)&&s.getTextContentSize()!==0&&(r.set(s.getKey(),0,"element"),i.set(s.getKey(),s.getChildrenSize(),"element"),n.formatText(t))}),Y(e),this.editor.dispatchCommand(De,void 0)})}clearText(){let t=this.editor;t.update(()=>{let e=Q(this.tableNodeKey);if(!K(e))throw new Error("Expected TableNode.");let n=C();W(n)||E(!1,"Expected grid selection");let r=n.getNodes().filter(D);if(r.length===this.table.columns*this.table.rows){e.selectPrevious(),e.remove(),H().selectStart();return}r.forEach(i=>{if(T(i)){let s=I(),l=q();s.append(l),i.append(s),i.getChildren().forEach(a=>{a!==s&&a.remove()})}}),Ur(t,this.table,null),Y(null),t.dispatchCommand(De,void 0)})}};var Ex="__lexicalTableSelection",Ta=o=>me?(o||window).getSelection():null,Tx=o=>(o.buttons&1)===1;function _a(o,t,e,n){let r=e.getRootElement();if(r===null)throw new Error("No root element.");let i=new zr(e,o.getKey()),s=e._window||window;Cx(t,i);let l=()=>{let c=()=>{i.isSelecting=!1,s.removeEventListener("mouseup",c),s.removeEventListener("mousemove",f)},f=g=>{setTimeout(()=>{if(!Tx(g)&&i.isSelecting){i.isSelecting=!1,s.removeEventListener("mouseup",c),s.removeEventListener("mousemove",f);return}let h=ba(g.target);h!==null&&(i.anchorX!==h.x||i.anchorY!==h.y)&&(g.preventDefault(),i.setFocusCellForSelection(h))},0)};return{onMouseMove:f,onMouseUp:c}};t.addEventListener("mousedown",c=>{setTimeout(()=>{if(c.button!==0||!s)return;let f=ba(c.target);f!==null&&(sn(c),i.setAnchorCellForSelection(f));let{onMouseUp:g,onMouseMove:h}=l();i.isSelecting=!0,s.addEventListener("mouseup",g),s.addEventListener("mousemove",h)},0)});let a=c=>{c.button===0&&e.update(()=>{let f=C(),g=c.target;W(f)&&f.tableKey===i.tableNodeKey&&r.contains(g)&&i.clearHighlight()})};s.addEventListener("mousedown",a),i.listenersToRemove.add(()=>s.removeEventListener("mousedown",a)),i.listenersToRemove.add(e.registerCommand(Wt,c=>Wr(e,c,"down",o,i),Xe)),i.listenersToRemove.add(e.registerCommand(zt,c=>Wr(e,c,"up",o,i),Xe)),i.listenersToRemove.add(e.registerCommand(Ro,c=>Wr(e,c,"backward",o,i),Xe)),i.listenersToRemove.add(e.registerCommand(Ao,c=>Wr(e,c,"forward",o,i),Xe)),i.listenersToRemove.add(e.registerCommand(ko,c=>{let f=C();if(W(f)){let g=U(f.focus.getNode(),D);if(D(g))return sn(c),g.selectEnd(),!0}return!1},Xe));let d=c=>()=>{let f=C();if(!rn(f,o))return!1;if(W(f))return i.clearText(),!0;if(_(f)){let g=U(f.anchor.getNode(),R=>D(R));if(!D(g))return!1;let h=f.anchor.getNode(),N=f.focus.getNode(),b=o.isParentOf(h),x=o.isParentOf(N);if(b&&!x||x&&!b)return i.clearText(),!0;let v=U(f.anchor.getNode(),R=>T(R)),M=v&&U(v,R=>T(R)&&D(R.getParent()));if(!T(M)||!T(v))return!1;if(c===ut&&M.getPreviousSibling()===null)return!0}return!1};[St,ut,Je].forEach(c=>{i.listenersToRemove.add(e.registerCommand(c,d(c),Ie))});let u=c=>{let f=C();if(!rn(f,o)){let g=f?f.getNodes():null;if(g){let h=g.find(N=>K(N)&&N.getKey()===i.tableNodeKey);if(K(h)){if(!h.getParent())return!1;h.remove()}}return!1}if(W(f))return c&&(c.preventDefault(),c.stopPropagation()),i.clearText(),!0;if(_(f)){let g=U(f.anchor.getNode(),h=>D(h));if(!D(g))return!1}return!1};i.listenersToRemove.add(e.registerCommand(qt,u,Ie)),i.listenersToRemove.add(e.registerCommand(Yt,u,Ie)),i.listenersToRemove.add(e.registerCommand(mo,c=>{let f=C();if(f){if(!(W(f)||_(f)))return!1;zn(e,Nt(c,ClipboardEvent)?c:null,Ki(f));let g=u(c);return _(f)&&f.removeText(),g}return!1},Ie)),i.listenersToRemove.add(e.registerCommand(xe,c=>{let f=C();if(!rn(f,o))return!1;if(W(f))return i.formatCells(c),!0;if(_(f)){let g=U(f.anchor.getNode(),h=>D(h));if(!D(g))return!1}return!1},Ie)),i.listenersToRemove.add(e.registerCommand(ct,c=>{let f=C();if(!rn(f,o))return!1;if(W(f))return i.clearHighlight(),!1;if(_(f)){let g=U(f.anchor.getNode(),h=>D(h));if(!D(g))return!1;if(typeof c=="string"){let h=wf(e,f,o);if(h)return Mf(h,o,[q(c)]),!0}}return!1},Ie)),n&&i.listenersToRemove.add(e.registerCommand(Io,c=>{let f=C();if(!_(f)||!f.isCollapsed()||!rn(f,o))return!1;let g=Ji(f.anchor.getNode());if(g===null)return!1;sn(c);let h=o.getCordsFromCellNode(g,i.table);return vf(i,o,h.x,h.y,c.shiftKey?"backward":"forward"),!0},Ie)),i.listenersToRemove.add(e.registerCommand(ar,c=>o.isSelected(),Xe));function m(c){let f=o.getCordsFromCellNode(c,i.table);return o.getDOMCellFromCordsOrThrow(f.x,f.y,i.table)}return i.listenersToRemove.add(e.registerCommand(rr,c=>{let{nodes:f,selection:g}=c,h=g.getStartEndPoints(),N=W(g),x=_(g)&&U(g.anchor.getNode(),He=>D(He))!==null&&U(g.focus.getNode(),He=>D(He))!==null||N;if(f.length!==1||!K(f[0])||!x||h===null)return!1;let[S]=h,v=f[0],M=v.getChildren(),R=v.getFirstChildOrThrow().getChildrenSize(),A=v.getChildrenSize(),$=U(S.getNode(),He=>D(He)),B=$&&U($,He=>te(He)),k=B&&U(B,He=>K(He));if(!D($)||!te(B)||!K(k))return!1;let j=B.getIndexWithinParent(),se=Math.min(k.getChildrenSize()-1,j+A-1),Fe=$.getIndexWithinParent(),Ed=Math.min(B.getChildrenSize()-1,Fe+R-1),hh=Math.min(Fe,Ed),Nh=Math.min(j,se),xh=Math.max(Fe,Ed),Eh=Math.max(j,se),Th=k.getChildren(),Td=0;for(let He=Nh;He<=Eh;He++){let Cd=Th[He];if(!te(Cd))return!1;let bd=M[Td];if(!te(bd))return!1;let Ch=Cd.getChildren(),bh=bd.getChildren(),_d=0;for(let Fs=hh;Fs<=xh;Fs++){let ni=Ch[Fs];if(!D(ni))return!1;let yd=bh[_d];if(!D(yd))return!1;let _h=ni.getChildren();yd.getChildren().forEach(gn=>{L(gn)&&I().append(gn),ni.append(gn)}),_h.forEach(gn=>gn.remove()),_d++}Td++}return!0},Ie)),i.listenersToRemove.add(e.registerCommand(De,()=>{let c=C(),f=Ye();if(_(c)){let{anchor:g,focus:h}=c,N=g.getNode(),b=h.getNode(),x=Ji(N),S=Ji(b),v=!!(x&&o.is(vo(x))),M=!!(S&&o.is(vo(S))),R=v!==M,A=v&&M,$=c.isBackward();if(R){let B=c.clone();if(M){let[k]=at(o,S,S),j=k[0][0].cell,se=k[k.length-1].at(-1).cell;B.focus.set($?j.getKey():se.getKey(),$?j.getChildrenSize():se.getChildrenSize(),"element")}Y(B),Lf(e,i)}else A&&(x.is(S)||(i.setAnchorCellForSelection(m(x)),i.setFocusCellForSelection(m(S),!0),i.isSelecting||setTimeout(()=>{let{onMouseUp:B,onMouseMove:k}=l();i.isSelecting=!0,s.addEventListener("mouseup",B),s.addEventListener("mousemove",k)},0)))}else if(c&&W(c)&&c.is(f)&&c.tableKey===o.getKey()){let g=Ta(e._window);if(g&&g.anchorNode&&g.focusNode){let h=ee(g.focusNode),N=h&&!o.is(vo(h)),b=ee(g.anchorNode),x=b&&o.is(vo(b));if(N&&x&&g.rangeCount>0){let S=Yl(g,e);S&&(S.anchor.set(o.getKey(),c.isBackward()?o.getChildrenSize():0,"element"),g.removeAllRanges(),Y(S))}}}return c&&!c.is(f)&&(W(c)||W(f))&&i.tableSelection&&!i.tableSelection.is(f)?(W(c)&&c.tableKey===i.tableNodeKey?i.updateTableTableSelection(c):!W(c)&&W(f)&&f.tableKey===i.tableNodeKey&&i.updateTableTableSelection(null),!1):(i.hasHijackedSelectionStyles&&!o.isSelected()?bx(e,i):!i.hasHijackedSelectionStyles&&o.isSelected()&&Lf(e,i),!1)},Ie)),i.listenersToRemove.add(e.registerCommand(Ut,()=>{let c=C();if(!_(c)||!c.isCollapsed()||!rn(c,o))return!1;let f=wf(e,c,o);return f?(Mf(f,o),!0):!1},Ie)),i}function Cx(o,t){o[Ex]=t}function ba(o){let t=o;for(;t!=null;){let e=t.nodeName;if(e==="TD"||e==="TH"){let n=t._cell;return n===void 0?null:n}t=t.parentNode}return null}function nn(o){let t=[],e={columns:0,domRows:t,rows:0},n=o.firstChild,r=0,i=0;for(t.length=0;n!=null;){let s=n.nodeName;if(s==="COLGROUP"||s==="CAPTION"){n=n.nextSibling;continue}if(s==="TD"||s==="TH"){let d=n,u={elem:d,hasBackgroundColor:d.style.backgroundColor!=="",highlighted:!1,x:r,y:i};n._cell=u;let m=t[i];m===void 0&&(m=t[i]=[]),m[r]=u}else{let d=n.firstChild;if(d!=null){n=d;continue}}let l=n.nextSibling;if(l!=null){r++,n=l;continue}let a=n.parentNode;if(a!=null){let d=a.nextSibling;if(d==null)break;i++,r=0,n=d}}return e.columns=r+1,e.rows=i+1,e}function Ur(o,t,e){let n=new Set(e?e.getNodes():[]);ya(t,(r,i)=>{let s=r.elem;n.has(i)?(r.highlighted=!0,Df(o,r)):(r.highlighted=!1,Of(o,r),s.getAttribute("style")||s.removeAttribute("style"))})}function ya(o,t){let{domRows:e}=o;for(let n=0;n{e.highlighted=!0,Df(o,e)})}function bx(o,t){t.enableHighlightStyle(),ya(t.table,e=>{let n=e.elem;e.highlighted=!1,Of(o,e),n.getAttribute("style")||n.removeAttribute("style")})}var vf=(o,t,e,n,r)=>{let i=r==="forward";switch(r){case"backward":case"forward":return e!==(i?o.table.columns-1:0)?Gi(t.getCellNodeFromCordsOrThrow(e+(i?1:-1),n,o.table),i):n!==(i?o.table.rows-1:0)?Gi(t.getCellNodeFromCordsOrThrow(i?0:o.table.columns-1,n+(i?1:-1),o.table),i):i?t.selectNext():t.selectPrevious(),!0;case"up":return n!==0?Gi(t.getCellNodeFromCordsOrThrow(e,n-1,o.table),!1):Ar(t,!1),!0;case"down":return n!==o.table.rows-1?Gi(t.getCellNodeFromCordsOrThrow(e,n+1,o.table),!0):Ar(t,!0),!0;default:return!1}},_x=(o,t,e,n,r)=>{let i=r==="forward";switch(r){case"backward":case"forward":return e!==(i?o.table.columns-1:0)&&o.setFocusCellForSelection(t.getDOMCellFromCordsOrThrow(e+(i?1:-1),n,o.table)),!0;case"up":return n!==0?(o.setFocusCellForSelection(t.getDOMCellFromCordsOrThrow(e,n-1,o.table)),!0):!1;case"down":return n!==o.table.rows-1?(o.setFocusCellForSelection(t.getDOMCellFromCordsOrThrow(e,n+1,o.table)),!0):!1;default:return!1}};function rn(o,t){if(_(o)||W(o)){let e=t.isParentOf(o.anchor.getNode()),n=t.isParentOf(o.focus.getNode());return e&&n}return!1}function Gi(o,t){t?o.selectStart():o.selectEnd()}var Ca="172,206,247";function Df(o,t){let e=t.elem,n=ee(e);E(D(n),"Expected to find LexicalNode from Table Cell DOMNode"),n.getBackgroundColor()===null?e.style.setProperty("background-color",`rgb(${Ca})`):e.style.setProperty("background-image",`linear-gradient(to right, rgba(${Ca},0.85), rgba(${Ca},0.85))`),e.style.setProperty("caret-color","transparent")}function Of(o,t){let e=t.elem,n=ee(e);E(D(n),"Expected to find LexicalNode from Table Cell DOMNode"),n.getBackgroundColor()===null&&e.style.removeProperty("background-color"),e.style.removeProperty("background-image"),e.style.removeProperty("caret-color")}function Ji(o){let t=U(o,D);return D(t)?t:null}function vo(o){let t=U(o,K);return K(t)?t:null}function Wr(o,t,e,n,r){if((e==="up"||e==="down")&&yx(o))return!1;let i=C();if(!rn(i,n)){if(_(i)){if(i.isCollapsed()&&e==="backward"){let s=i.anchor.type,l=i.anchor.offset;if(s!=="element"&&!(s==="text"&&l===0))return!1;let a=i.anchor.getNode();if(!a)return!1;let d=U(a,m=>T(m)&&!m.isInline());if(!d)return!1;let u=d.getPreviousSibling();return!u||!K(u)?!1:(sn(t),u.selectEnd(),!0)}else if(t.shiftKey&&(e==="up"||e==="down")){let s=i.focus.getNode();if(pe(s)){let l=i.getNodes()[0];if(l){let a=U(l,D);if(a&&n.isParentOf(a)){let d=n.getFirstDescendant(),u=n.getLastDescendant();if(!d||!u)return!1;let[m]=we(d),[c]=we(u),f=n.getCordsFromCellNode(m,r.table),g=n.getCordsFromCellNode(c,r.table),h=n.getDOMCellFromCordsOrThrow(f.x,f.y,r.table),N=n.getDOMCellFromCordsOrThrow(g.x,g.y,r.table);return r.setAnchorCellForSelection(h),r.setFocusCellForSelection(N,!0),!0}}return!1}else{let l=U(s,d=>T(d)&&!d.isInline());if(!l)return!1;let a=e==="down"?l.getNextSibling():l.getPreviousSibling();if(K(a)&&r.tableNodeKey===a.getKey()){let d=a.getFirstDescendant(),u=a.getLastDescendant();if(!d||!u)return!1;let[m]=we(d),[c]=we(u),f=i.clone();return f.focus.set((e==="up"?m:c).getKey(),e==="up"?0:c.getChildrenSize(),"element"),Y(f),!0}}}}return!1}if(_(i)&&i.isCollapsed()){let{anchor:s,focus:l}=i,a=U(s.getNode(),D),d=U(l.getNode(),D);if(!D(a)||!a.is(d))return!1;let u=vo(a);if(u!==n&&u!=null){let x=o.getElementByKey(u.getKey());if(x!=null)return r.table=nn(x),Wr(o,t,e,u,r)}if(e==="backward"||e==="forward"){let x=s.type,S=s.offset,v=s.getNode();if(!v)return!1;let M=i.getNodes();return M.length===1&&F(M[0])?!1:Sx(x,S,v,e)?wx(t,v,n,e):!1}let m=o.getElementByKey(a.__key),c=o.getElementByKey(s.key);if(c==null||m==null)return!1;let f;if(s.type==="element")f=c.getBoundingClientRect();else{let x=window.getSelection();if(x===null||x.rangeCount===0)return!1;f=x.getRangeAt(0).getBoundingClientRect()}let g=e==="up"?a.getFirstChild():a.getLastChild();if(g==null)return!1;let h=o.getElementByKey(g.__key);if(h==null)return!1;let N=h.getBoundingClientRect();if(e==="up"?N.top>f.top-f.height:f.bottom+f.height>N.bottom){sn(t);let x=n.getCordsFromCellNode(a,r.table);if(t.shiftKey){let S=n.getDOMCellFromCordsOrThrow(x.x,x.y,r.table);r.setAnchorCellForSelection(S),r.setFocusCellForSelection(S,!0)}else return vf(r,n,x.x,x.y,e);return!0}}else if(W(i)){let{anchor:s,focus:l}=i,a=U(s.getNode(),D),d=U(l.getNode(),D),[u]=i.getNodes(),m=o.getElementByKey(u.getKey());if(!D(a)||!D(d)||!K(u)||m==null)return!1;r.updateTableTableSelection(i);let c=nn(m),f=n.getCordsFromCellNode(a,c),g=n.getDOMCellFromCordsOrThrow(f.x,f.y,c);if(r.setAnchorCellForSelection(g),sn(t),t.shiftKey){let h=n.getCordsFromCellNode(d,c);return _x(r,u,h.x,h.y,e)}else d.selectEnd();return!0}return!1}function sn(o){o.preventDefault(),o.stopImmediatePropagation(),o.stopPropagation()}function yx(o){let t=o.getRootElement();return t?t.hasAttribute("aria-controls")&&t.getAttribute("aria-controls")==="typeahead-menu":!1}function Sx(o,t,e,n){return Lx(o,e,n)||Mx(o,t,e,n)}function Lx(o,t,e){return o==="element"&&(e==="backward"?t.getPreviousSibling()===null:t.getNextSibling()===null)}function Mx(o,t,e,n){let r=U(e,s=>T(s)&&!s.isInline());if(!r)return!1;let i=n==="backward"?t===0:t===e.getTextContentSize();return o==="text"&&i&&(n==="backward"?r.getPreviousSibling()===null:r.getNextSibling()===null)}function wx(o,t,e,n){let r=U(t,D);if(!D(r))return!1;let[i,s]=at(e,r,r);if(!vx(i,s,n))return!1;let l=Dx(t,n,e);return!l||K(l)?!1:(sn(o),n==="backward"?l.selectEnd():l.selectStart(),!0)}function vx(o,t,e){let n=o[0][0],r=o[o.length-1][o[0].length-1],{startColumn:i,startRow:s}=t;return e==="backward"?i===n.startColumn&&s===n.startRow:i===r.startColumn&&s===r.startRow}function Dx(o,t,e){let n=U(o,i=>T(i)&&!i.isInline());if(!n)return;let r=t==="backward"?n.getPreviousSibling():n.getNextSibling();return r&&K(r)?r:t==="backward"?e.getPreviousSibling():e.getNextSibling()}function Mf(o,t,e){let n=I();o==="first"?t.insertBefore(n):t.insertAfter(n),n.append(...e||[]),n.selectEnd()}function wf(o,t,e){let n=e.getParent();if(!n)return;let r=o.getElementByKey(n.getKey());if(!r)return;let i=window.getSelection();if(!i||i.anchorNode!==r)return;let s=U(t.anchor.getNode(),N=>D(N));if(!s)return;let l=U(s,N=>K(N));if(!K(l)||!l.is(e))return;let[a,d]=at(e,s,s),u=a[0][0],m=a[a.length-1][a[0].length-1],{startRow:c,startColumn:f}=d,g=c===u.startRow&&f===u.startColumn,h=c===m.startRow&&f===m.startColumn;return g?"first":h?"last":void 0}var Bt=class{constructor(t){p(this,"rowCount",0);p(this,"columnCount",0);p(this,"cells",[]);this.buildCellMap(t)}buildCellMap(t){let e=[],n=(a,d,u)=>{typeof e[d]>"u"&&(e[d]=[]),e[d][a]=u},r=(a,d)=>!!(e[d]&&e[d][a]),i=t.getChildren().filter(a=>te(a));for(let a=0;aD(c)),m=0;for(let c=0;ca.length));let s=[],l=e[0][0];for(let a=0;a=this.cells.length)throw new Error(`TableMap Error: Attempted to get cell ${n+1} of ${this.cells.length}`);return this.cells[n]}getCellsInRange(t){let e=Math.max(Math.min(t.fromX,t.toX),0),n=Math.min(Math.max(t.fromX,t.toX),this.columnCount-1),r=Math.max(Math.min(t.fromY,t.toY),0),i=Math.min(Math.max(t.fromY,t.toY),this.rowCount-1),s=new Set;for(let l=r;l<=i;l++)for(let a=e;a<=n;a++)s.add(this.getCellAtPosition(a,l));return[...s.values()]}getCellsInColumn(t){return this.getCellsInRange({fromX:t,toX:t,fromY:0,toY:this.rowCount-1})}getRangeForCell(t){let e=null,n=t.getKey();for(let r=0;re&&(n=r,e=r.childElementCount);return n}function Af(o){return[...o.children].map(t=>Ox(t))}function Ox(o){let t=o.style.width||o.getAttribute("width");return t&&!Number.isNaN(Number(t))&&(t=t+"px"),t||""}function La(o,t,e){let n=o.getChildren(),r=0;for(let s of n){let l=s.getChildren().length;l>r&&(r=l)}let i=o.getColWidths();(i.length===0||i.lengthi.length&&console.error(`Attempted to set table column width for column [${t}] but only ${i.length} columns found`),i[t]=xt(e),o.setColWidths(i)}function If(o,t,e){let n=t.getColWidths();if(n.length>e&&n[e].endsWith("px"))return Number(n[e].replace("px",""));let r=o.getElementByKey(t.__key);if(r){let i=kf(r);if(i&&i.children.length>e)return i.children[e].clientWidth}return 0}function $f(o){let t=o.getParent();if(!te(t))return-1;let e=0,n=t.getChildren();for(let r of n){let i=r.getColSpan()||1;if(e+=i,r.getKey()===o.getKey())break}return e-1}function Pf(o,t){let e=Sa(o),n=$f(o);e&&n>=0&&La(e,n,t)}function Bf(o,t){let e=Sa(t),n=$f(t);if(!e)return"";let r=e.getColWidths();return r.length>n?r[n]:""}function Ma(o){if(o.length===0)return null;let t=y("colgroup");for(let e of o){let n=y("col");e&&(n.style.width=e),t.append(n)}return t}function ln(o){if(W(o))return o.getNodes().filter(n=>D(n));let t=Z(o,D);return t?[t]:[]}function Ff(o){let t=o.getShape(),e=ln(o);if(e.length===0)return;let n=Sa(e[0]);if(!n)return;let r=new Bt(n),i=r.getCellAtPosition(t.toX,t.toY);if(!i)return;let s=t.toX+((i.getColSpan()||1)-1),l=t.toY+((i.getRowSpan()||1)-1),a=r.getCellsInRange({fromX:t.fromX,fromY:t.fromY,toX:s,toY:l});if(a.length===0)return;let d=a[0],u=Math.abs(t.fromX-s)+1,m=Math.abs(t.fromY-l)+1;for(let c=1;cD(r));for(let r of n){let i=r.getStyles();i.delete("height"),i.delete("width"),r.setStyles(i),r.clearWidth()}}}function Kf(o){o.setColWidths([]),o.setStyles(new Map);for(let t of o.getChildren()){if(!te(t))continue;t.setStyles(new Map);let e=t.getChildren().filter(n=>D(n));for(let n of e)n.setStyles(new Map),n.setBackgroundColor(null),n.clearWidth()}}function wa(o,t){e:for(let e of o.getChildren()){if(!te(e))continue;let n=e.getChildren();for(let r of n){if(!D(r))return;if(t(r)===!1)break e}}}function Uf(o){let t=null;return wa(o,e=>{let n=e.getStyles().get("padding")||"";if(t===null&&(t=n),n!==t)return t=null,!1}),t||""}var bt=class o extends It{constructor(e){super(e);p(this,"__colWidths",[]);p(this,"__styles",new Map)}static getType(){return"table"}static clone(e){let n=new o(e.__key);return Mo(e,n),n.__colWidths=[...e.__colWidths],n.__styles=new Map(e.__styles),n}static importDOM(){return{table:e=>({conversion:Ax,priority:1})}}static importJSON(e){let n=Kr();return lt(e,n),n.setColWidths(e.colWidths),n.setStyles(new Map(Object.entries(e.styles))),n}exportJSON(){return{...super.exportJSON(),type:"table",version:1,colWidths:this.__colWidths,styles:Object.fromEntries(this.__styles)}}createDOM(e,n){let r=document.createElement("table");Ce(r,e.theme.table),st(r,this);let i=this.getColWidths(),s=Ma(i);s&&r.append(s);for(let[l,a]of this.__styles.entries())r.style.setProperty(l,a);return r}updateDOM(e,n){if(tf(e,this,n),this.__colWidths.join(":")!==e.__colWidths.join(":")){let r=Array.from(n.children).find(s=>s.nodeName==="COLGROUP"),i=Ma(this.__colWidths);r&&r.remove(),i&&n.prepend(i)}if(Array.from(this.__styles.values()).join(":")!==Array.from(e.__styles.values()).join(":")){n.style.cssText="";for(let[r,i]of this.__styles.entries())n.style.setProperty(r,i)}return!1}exportDOM(e){return{...super.exportDOM(e),after:n=>{if(!n)return;let r=n.cloneNode(),i=document.createElement("tbody");if(ge(n))for(let s of Array.from(n.children))s.nodeName==="TR"?i.append(s):s.nodeName==="CAPTION"?r.insertBefore(s,r.firstChild):r.append(s);return r.append(i),r}}}canBeEmpty(){return!1}isShadowRoot(){return!0}setColWidths(e){let n=this.getWritable();n.__colWidths=e}getColWidths(){return[...this.getLatest().__colWidths]}getStyles(){let e=this.getLatest();return new Map(e.__styles)}setStyles(e){let n=this.getWritable();n.__styles=new Map(e)}getCordsFromCellNode(e,n){let{rows:r,domRows:i}=n;for(let s=0;s{if(!d)return;let{elem:u}=d;return ee(u)===e});if(a!==-1)return{x:a,y:s}}throw new Error("Cell not found in table.")}getDOMCellFromCords(e,n,r){let{domRows:i}=r,s=i[n];if(s==null)return null;let l=e{let r=new o;return n.id&&r.setId(n.id),{node:r}},priority:3}}}}exportJSON(){return{...super.exportJSON(),type:"horizontal-rule",version:1,id:this.__id}}static importJSON(e){let n=va();return n.setId(e.id),n}};function va(){return new Vn}function zf(o){return o instanceof Vn}var Wf=o=>(o.split(" ").filter(e=>e.startsWith("language-"))[0]||"").replace("language-",""),an=class o extends kt{constructor(e="",n="",r){super(r);p(this,"__id","");p(this,"__language","");p(this,"__code","");this.__language=e,this.__code=n}static getType(){return"code-block"}static clone(e){let n=new o(e.__language,e.__code,e.__key);return n.__id=e.__id,n}setLanguage(e){let n=this.getWritable();n.__language=e}getLanguage(){return this.getLatest().__language}setCode(e){let n=this.getWritable();n.__code=e}getCode(){return this.getLatest().__code}setId(e){let n=this.getWritable();n.__id=e}getId(){return this.getLatest().__id}decorate(e,n){return{type:"code",getNode:()=>this}}isInline(){return!1}isIsolated(){return!0}createDOM(e,n){let r=y("pre",{id:this.__id||null},[y("code",{class:this.__language?`language-${this.__language}`:null},[this.__code])]);return y("div",{class:"editor-code-block-wrap"},[r])}updateDOM(e,n){let r=n.querySelector("code");return r&&(e.__language!==this.__language&&(r.className=this.__language?`language-${this.__language}`:""),e.__id!==this.__id&&n.setAttribute("id",this.__id),e.__code!==this.__code&&(r.textContent=this.__code)),!1}exportDOM(e){return{element:this.createDOM(e._config,e).querySelector("pre")}}static importDOM(){return{pre(e){return{conversion:n=>{let r=n.querySelector("code"),i=Wf(n.className)||r&&Wf(r.className)||"",s=r?(r.textContent||"").trim():(n.textContent||"").trim(),l=Qi(i,s);return n.id&&l.setId(n.id),{node:l,after(a){return[]}}},priority:3}}}}exportJSON(){return{type:"code-block",version:1,id:this.__id,language:this.__language,code:this.__code}}static importJSON(e){let n=Qi(e.language,e.code);return n.setId(e.id||""),n}};function Qi(o="",t=""){return new an(o,t)}function es(o){return o instanceof an}function qr(o,t){let e=t.getCode(),n=t.getLanguage();window.$components.first("code-editor").open(e,n,"ltr",(i,s)=>{o.update(()=>{t.setCode(i),t.setLanguage(s)})},()=>{})}var Do=class o extends kt{constructor(e,n,r){super(r);p(this,"__id","");p(this,"__drawingId","");p(this,"__drawingUrl","");this.__drawingId=e,this.__drawingUrl=n}static getType(){return"diagram"}static clone(e){let n=new o(e.__drawingId,e.__drawingUrl);return n.__id=e.__id,n}setDrawingIdAndUrl(e,n){let r=this.getWritable();r.__drawingUrl=n,r.__drawingId=e}getDrawingIdAndUrl(){let e=this.getLatest();return{id:e.__drawingId,url:e.__drawingUrl}}setId(e){let n=this.getWritable();n.__id=e}getId(){return this.getLatest().__id}decorate(e,n){return{type:"diagram",getNode:()=>this}}isInline(){return!1}isIsolated(){return!0}createDOM(e,n){return y("div",{id:this.__id||null,"drawio-diagram":this.__drawingId},[y("img",{src:this.__drawingUrl})])}updateDOM(e,n){let r=n.querySelector("img");return r&&(e.__id!==this.__id&&n.setAttribute("id",this.__id),e.__drawingUrl!==this.__drawingUrl&&r.setAttribute("src",this.__drawingUrl),e.__drawingId!==this.__drawingId&&n.setAttribute("drawio-diagram",this.__drawingId)),!1}static importDOM(){return{div(e){return e.hasAttribute("drawio-diagram")?{conversion:n=>{let i=n.querySelector("img")?.getAttribute("src")||"",s=n.getAttribute("drawio-diagram")||"",l=Xn(s,i);return n.id&&l.setId(n.id),{node:l}},priority:3}:null}}}exportJSON(){return{type:"diagram",version:1,id:this.__id,drawingId:this.__drawingId,drawingUrl:this.__drawingUrl}}static importJSON(e){let n=Xn(e.drawingId,e.drawingUrl);return n.setId(e.id||""),n}};function Xn(o="",t=""){return new Do(o,t)}var Rx=["width","height","style","title","name","src","allow","allowfullscreen","loading","sandbox","type","data","controls","autoplay","controlslist","loop","muted","playsinline","poster","preload"];function kx(o){let t={};for(let e of Object.keys(o))Rx.includes(e)&&(t[e]=o[e]);return t}function ts(o,t){let e=Object.assign({},o);if(!o.style)return e;let n=Fl(o.style);return n.delete(t),e.style=Nu(n),e}function qf(o,t){let e=Yf(o),n={};for(let i of t.attributes)n[i.name]=i.value;e.setAttributes(n);let r=[];if(o==="video"||o==="audio"){for(let i of t.children)if(i.tagName==="SOURCE"){let s=i.getAttribute("src"),l=i.getAttribute("type");s&&l&&r.push({src:s,type:l})}e.setSources(r)}return it(t,e),e}var Oo=class o extends V{constructor(e,n){super(n);p(this,"__id","");p(this,"__alignment","");p(this,"__tag");p(this,"__attributes",{});p(this,"__sources",[]);p(this,"__inset",0);this.__tag=e}static getType(){return"media"}static clone(e){let n=new o(e.__tag,e.__key);return n.__attributes=Object.assign({},e.__attributes),n.__sources=e.__sources.map(r=>Object.assign({},r)),n.__id=e.__id,n.__alignment=e.__alignment,n.__inset=e.__inset,n}setTag(e){let n=this.getWritable();n.__tag=e}getTag(){return this.getLatest().__tag}setAttributes(e){let n=this.getWritable();n.__attributes=kx(e)}getAttributes(){let e=this.getLatest();return Object.assign({},e.__attributes)}setSources(e){let n=this.getWritable();n.__sources=e}getSources(){return this.getLatest().__sources.map(n=>Object.assign({},n))}setSrc(e){let n=this.getAttributes(),r=this.getSources();this.__tag==="object"&&(n.data=e),this.__tag==="video"&&r.length>0?(r[0].src=e,delete n.src,r.length>1&&r.splice(1,r.length-1),this.setSources(r)):n.src=e,this.setAttributes(n)}setWidthAndHeight(e,n){let r=Object.assign(this.getAttributes(),{width:e,height:n});r=ts(r,"width"),r=ts(r,"height"),this.setAttributes(r)}setId(e){let n=this.getWritable();n.__id=e}getId(){return this.getLatest().__id}setAlignment(e){let n=this.getWritable();n.__alignment=e}getAlignment(){return this.getLatest().__alignment}setInset(e){let n=this.getWritable();n.__inset=e}getInset(){return this.getLatest().__inset}setHeight(e){if(!e)return;let n=Object.assign(this.getAttributes(),{height:e});this.setAttributes(ts(n,"height"))}getHeight(){let e=this.getLatest();return Yo(e.__attributes.height||"0")}setWidth(e){let n=this.getAttributes(),r=Object.assign(n,{width:e});this.setAttributes(ts(r,"width"))}getWidth(){let e=this.getLatest();return Yo(e.__attributes.width||"0")}isInline(){return!0}isParentRequired(){return!0}createInnerDOM(){let n=(this.__tag==="video"||this.__tag==="audio"?this.__sources:[]).map(i=>y("source",i)),r=y(this.__tag,this.__attributes,n);return st(r,this),r}createDOM(e,n){let r=this.createInnerDOM();return y("span",{class:r.className+" editor-media-wrap"},[r])}updateDOM(e,n){if(e.__tag!==this.__tag||JSON.stringify(e.__sources)!==JSON.stringify(this.__sources)||JSON.stringify(e.__attributes)!==JSON.stringify(this.__attributes))return!0;let r=n.firstElementChild;return e.__id!==this.__id&&xu(r,"id",this.__id),e.__alignment!==this.__alignment&&(e.__alignment&&(n.classList.remove(`align-${e.__alignment}`),r.classList.remove(`align-${e.__alignment}`)),this.__alignment&&(n.classList.add(`align-${this.__alignment}`),r.classList.add(`align-${this.__alignment}`))),e.__inset!==this.__inset&&(n.style.paddingLeft=`${this.__inset}px`),!1}static importDOM(){let e=n=>r=>({conversion:i=>({node:qf(n,i)}),priority:3});return{iframe:e("iframe"),embed:e("embed"),object:e("object"),video:e("video"),audio:e("audio")}}exportDOM(e){return{element:this.createInnerDOM()}}exportJSON(){return{...super.exportJSON(),type:"media",version:1,id:this.__id,alignment:this.__alignment,inset:this.__inset,tag:this.__tag,attributes:this.__attributes,sources:this.__sources}}static importJSON(e){let n=Yf(e.tag);return lt(e,n),n}};function Yf(o){return new Oo(o)}function Zf(o){let n=new DOMParser().parseFromString(`${o}`,"text/html").body.children[0];if(!(n instanceof HTMLElement))return null;let r=n.tagName.toLowerCase();return["embed","iframe","video","audio","object"].includes(r)?qf(r,n):null}var Ix=[{regex:/.*?youtu\.be\/([\w\-_\?&=.]+)/i,w:560,h:314,url:"https://www.youtube.com/embed/$1"},{regex:/.*youtube\.com(.+)v=([^&]+)(&([a-z0-9&=\-_]+))?.*/i,w:560,h:314,url:"https://www.youtube.com/embed/$2?$4"},{regex:/.*youtube.com\/embed\/([a-z0-9\?&=\-_]+).*/i,w:560,h:314,url:"https://www.youtube.com/embed/$1"}],$x=["mp4","mpeg","m4v","m4p","mov"],Px=["3gp","aac","flac","mp3","m4a","ogg","wav","webm"],Bx=["html","htm","php","asp","aspx",""];function Vf(o){for(let s of Ix)if(o.match(s.regex)){let a=o.replace(s.regex,s.url),d=new Oo("iframe");return d.setSrc(a),d.setHeight(s.h),d.setWidth(s.w),d}let t="iframe",n=(o.split("?")[0].split("/").pop()||"").split("."),r=(n.length>1?n[n.length-1]:"").toLowerCase();$x.includes(r)?t="video":Px.includes(r)?t="audio":r&&!Bx.includes(r)&&(t="embed");let i=new Oo(t);return i.setSrc(o),i}function _t(o){return o instanceof Oo}var Jn=class o extends It{constructor(e,n){super(n);p(this,"__tag");this.__tag=e}static getType(){return"heading"}static clone(e){let n=new o(e.__tag,e.__key);return Mo(e,n),n}getTag(){return this.__tag}createDOM(e){let n=this.__tag,r=document.createElement(n),s=e.theme.heading;if(s!==void 0){let l=s[n];Ce(r,l)}return st(r,this),r}updateDOM(e,n){return Lo(e,this)}static importDOM(){return{h1:e=>({conversion:jn,priority:0}),h2:e=>({conversion:jn,priority:0}),h3:e=>({conversion:jn,priority:0}),h4:e=>({conversion:jn,priority:0}),h5:e=>({conversion:jn,priority:0}),h6:e=>({conversion:jn,priority:0})}}exportDOM(e){let{element:n}=super.exportDOM(e);return n&&ge(n)&&this.isEmpty()&&n.append(document.createElement("br")),{element:n}}static importJSON(e){let n=Gn(e.tag);return lt(e,n),n}exportJSON(){return{...super.exportJSON(),tag:this.getTag(),type:"heading",version:1}}insertNewAfter(e,n=!0){let r=e?e.anchor.offset:0,i=this.getLastDescendant(),l=!i||e&&e.anchor.key===i.getKey()&&r===i.getTextContentSize()||!e?I():Gn(this.getTag()),a=this.getDirection();if(l.setDirection(a),this.insertAfter(l,n),r===0&&!this.isEmpty()&&e){let d=I();d.select(),this.replace(d,!0)}return l}collapseAtStart(){let e=this.isEmpty()?I():Gn(this.getTag());return this.getChildren().forEach(r=>e.append(r)),this.replace(e),!0}extractWithChild(){return!0}};function jn(o){let t=o.nodeName.toLowerCase(),e=null;return(t==="h1"||t==="h2"||t==="h3"||t==="h4"||t==="h5"||t==="h6")&&(e=Gn(t),it(o,e)),{node:e}}function Gn(o){return re(new Jn(o))}function Qn(o){return o instanceof Jn}var er=class o extends It{static getType(){return"quote"}static clone(t){let e=new o(t.__key);return Mo(t,e),e}constructor(t){super(t)}createDOM(t){let e=document.createElement("blockquote");return Ce(e,t.theme.quote),st(e,this),e}updateDOM(t,e){return Lo(t,this)}static importDOM(){return{blockquote:t=>({conversion:Fx,priority:0})}}exportDOM(t){let{element:e}=super.exportDOM(t);return e&&ge(e)&&this.isEmpty()&&e.append(document.createElement("br")),{element:e}}static importJSON(t){let e=os();return lt(t,e),e}exportJSON(){return{...super.exportJSON(),type:"quote"}}insertNewAfter(t,e){let n=I(),r=this.getDirection();return n.setDirection(r),this.insertAfter(n,e),n}collapseAtStart(){let t=I();return this.getChildren().forEach(n=>t.append(n)),this.replace(t),!0}canMergeWhenEmpty(){return!0}};function os(){return re(new er)}function ns(o){return o instanceof er}function Fx(o){let t=os();return it(o,t),{node:t}}function Xf(){return[Jo,Jn,er,wo,Pt,bt,ro,no,Zn,en,Vn,qn,an,Do,Oo,ot,Qo]}function jf(){return[wo,Pt,ot,Qo]}function Gf(o){let t=[en,an,Do],e=n=>{for(let[r,i]of n)if(i==="destroyed"){let s=o.manager.getDecoratorByNodeKey(r);s&&s.teardown()}};for(let n of t)o.editor.registerMutationListener(n,r=>e(r))}function Da(o){return"build"in o}var ve=class{constructor(){p(this,"dom",null);p(this,"context",null);p(this,"abortController",new AbortController)}setContext(t){this.context=t}getContext(){if(this.context===null)throw new Error("Attempted to use EditorUIContext before it has been set");return this.context}getDOMElement(){return this.dom||(this.dom=this.buildDOM()),this.dom}rebuildDOM(){let t=this.buildDOM();return this.dom?.replaceWith(t),this.dom=t,this.dom}trans(t){return this.getContext().translate(t)}updateState(t){}emitEvent(t,e={}){this.dom&&this.dom.dispatchEvent(new CustomEvent("editor::"+t,{detail:e,bubbles:!0}))}onEvent(t,e,n=null){let r=n||this.dom;r&&r.addEventListener("editor::"+t,i=>{e(i.detail)},{signal:this.abortController.signal})}teardown(){this.dom&&this.dom.isConnected&&this.dom.remove(),this.abortController.abort("teardown")}},oe=class extends ve{constructor(e){super();p(this,"children",[]);this.children.push(...e)}buildDOM(){return y("div",{},this.getChildren().map(e=>e.getDOMElement()))}getChildren(){return this.children}addChildren(...e){this.children.push(...e)}removeChildren(...e){for(let n of e)this.removeChild(n)}removeChild(e){let n=this.children.indexOf(e);n!==-1&&this.children.splice(n,1)}updateState(e){for(let n of this.children)n.updateState(e)}setContext(e){super.setContext(e);for(let n of this.getChildren())n.setContext(e)}teardown(){for(let e of this.children)e.teardown();super.teardown()}},Yr=class extends oe{constructor(e,n){super(n);p(this,"className");this.className=e}buildDOM(){return y("div",{class:this.className},this.getChildren().map(e=>e.getDOMElement()))}};function Jf(){let o=()=>((1+Math.random())*65536|0).toString(16).substring(1);return`${o()+o()}-${o()}-${o()}-${o()}-${o()}${o()}${o()}`}function rs(){return((1+Math.random())*65536|0).toString(16).substring(1)}var Ft=class extends ve{constructor(e){super();p(this,"definition");this.definition=e}setValue(e){let n=this.getDOMElement().querySelector("input,select,textarea");this.definition.type==="checkbox"?n.checked=!!e:n.value=e,n.dispatchEvent(new Event("change"))}getName(){return this.definition.name}buildDOM(){let e=`editor-form-field-${this.definition.name}-${Date.now()}`,n;if(this.definition.type==="select"){let r=this.definition.valuesByLabel,s=Object.keys(r).map(l=>y("option",{value:r[l]},[this.trans(l)]));n=y("select",{id:e,name:this.definition.name,class:"editor-form-field-input"},s)}else if(this.definition.type==="textarea")n=y("textarea",{id:e,name:this.definition.name,class:"editor-form-field-input"});else if(this.definition.type==="checkbox")n=y("input",{id:e,name:this.definition.name,type:"checkbox",class:"editor-form-field-input-checkbox",value:"true"});else{if(this.definition.type==="hidden")return n=y("input",{id:e,name:this.definition.name,type:"hidden"}),y("div",{hidden:"true"},[n]);n=y("input",{id:e,name:this.definition.name,class:"editor-form-field-input"})}return y("div",{class:"editor-form-field-wrapper"},[y("label",{class:"editor-form-field-label",for:e},[this.trans(this.definition.label)]),n])}},is=class extends oe{constructor(e){let n=e.fields.map(r=>Da(r)?r.build():new Ft(r));super(n);p(this,"definition");p(this,"onCancel",null);p(this,"onSuccessfulSubmit",null);this.definition=e}setValues(e){for(let n of Object.keys(e)){let r=this.getFieldByName(n);r&&r.setValue(e[n])}}setOnCancel(e){this.onCancel=e}setOnSuccessfulSubmit(e){this.onSuccessfulSubmit=e}getFieldByName(e){let n=r=>{for(let i of r){if(i instanceof Ft&&i.getName()===e)return i;if(i instanceof oe){let s=n(i.getChildren());if(s)return s}}return null};return n(this.getChildren())}buildDOM(){let e=y("button",{type:"button",class:"editor-form-action-secondary"},[this.trans("Cancel")]),n=y("form",{},[...this.children.map(r=>r.getDOMElement()),y("div",{class:"editor-form-actions"},[e,y("button",{type:"submit",class:"editor-form-action-primary"},[this.trans(this.definition.submitText)])])]);return n.addEventListener("submit",async r=>{r.preventDefault();let i=new FormData(n);await this.definition.action(i,this.getContext())&&this.onSuccessfulSubmit&&this.onSuccessfulSubmit()}),e.addEventListener("click",r=>{this.onCancel&&this.onCancel()}),n}},Oa=class extends oe{constructor(e){let n=e.contents.map(r=>Da(r)?r.build():new Ft(r));super(n);p(this,"definition");p(this,"fields");p(this,"id");this.definition=e,this.fields=n,this.id=Jf()}getLabel(){return this.getContext().translate(this.definition.label)}getId(){return this.id}buildDOM(){return y("div",{class:"editor-form-tab-content",role:"tabpanel",id:`editor-tabpanel-${this.id}`,"aria-labelledby":`editor-tab-${this.id}`},this.fields.map(e=>e.getDOMElement()))}},dn=class extends oe{constructor(e){let n=e.map(r=>new Oa(r));super(n);p(this,"definitions",[]);p(this,"tabs",[]);this.definitions=e,this.tabs=n}buildDOM(){let e=[],n=[],r=i=>{for(let s=0;s{r(e.indexOf(s))})}return r(0),y("div",{class:"editor-form-tab-container"},[y("div",{class:"editor-form-tab-controls"},e),y("div",{class:"editor-form-tab-contents"},n)])}};var Qf='';var ss=class extends oe{constructor(e,n){super([new is(e.form)]);p(this,"definition");p(this,"key");this.definition=e,this.key=n}show(e){let n=this.getDOMElement();document.body.append(n);let r=this.getForm();r.setValues(e),r.setOnCancel(this.hide.bind(this)),r.setOnSuccessfulSubmit(this.hide.bind(this)),this.getContext().manager.setModalActive(this.key,this)}hide(){this.getContext().manager.setModalInactive(this.key),this.teardown()}getForm(){return this.children[0]}buildDOM(){let e=y("button",{class:"editor-modal-close",type:"button",title:this.trans("Close")});e.innerHTML=Qf,e.addEventListener("click",this.hide.bind(this));let n=y("div",{class:"editor-modal editor-form-modal"},[y("div",{class:"editor-modal-header"},[y("div",{class:"editor-modal-title"},[this.trans(this.definition.title)]),e]),y("div",{class:"editor-modal-body"},[this.getForm().getDOMElement()])]),r=y("div",{class:"editor-modal-wrapper"},[n]);return r.addEventListener("click",i=>{i.target&&!n.contains(i.target)&&this.hide()}),r}};var ls=class extends oe{constructor(e,n){super(n);p(this,"target");this.target=e}buildDOM(){return y("div",{class:"editor-context-toolbar"},this.getChildren().map(e=>e.getDOMElement()))}updatePosition(){let e=this.getContext().scrollDOM.getBoundingClientRect(),n=this.target.getBoundingClientRect(),r=this.getDOMElement(),i=r.getBoundingClientRect(),s=n.bottom>e.top&&n.tope.bottom;r.classList.toggle("is-above",l);let d=n.left+n.width/2-i.width/2;l?r.style.top=n.top-6-i.height+"px":r.style.top=n.bottom+6+"px",r.style.left=d+"px"}insert(e){this.addChildren(...e),this.getDOMElement().append(...e.map(r=>r.getDOMElement()))}};function Kx(o,t,e){let n=t.getBoundingClientRect(),r=o.getBoundingClientRect();if(o.style.position="fixed",e){let i=n.right;n.right+r.width>window.innerWidth&&(i=Math.max(n.left-r.width,0)),o.style.top=n.top+"px",o.style.left=i+"px"}else{let i=n.left+r.width>window.innerWidth,s=n.left;i&&(s=Math.max(n.right-r.width,0)),o.style.top=n.bottom+"px",o.style.left=s+"px"}}var as=class{constructor(){p(this,"dropdownOptions",new WeakMap);p(this,"openDropdowns",new Set);this.onMenuMouseOver=this.onMenuMouseOver.bind(this),this.onWindowClick=this.onWindowClick.bind(this),window.addEventListener("click",this.onWindowClick)}teardown(){window.removeEventListener("click",this.onWindowClick)}onWindowClick(t){let e=t.target;this.closeAllNotContainingElement(e)}closeAllNotContainingElement(t){for(let e of this.openDropdowns)e.parentElement?.contains(t)||this.closeDropdown(e)}onMenuMouseOver(t){let e=t.target;this.closeAllNotContainingElement(e)}closeAll(){for(let t of this.openDropdowns)this.closeDropdown(t)}closeDropdown(t){t.hidden=!0,t.style.removeProperty("position"),t.style.removeProperty("left"),t.style.removeProperty("top"),this.openDropdowns.delete(t),t.removeEventListener("mouseover",this.onMenuMouseOver);let e=this.getOptions(t).onClose;e&&e()}openDropdown(t){let{toggle:e,showAside:n,onOpen:r}=this.getOptions(t);t.hidden=!1,Kx(t,e,!!n),this.openDropdowns.add(t),t.addEventListener("mouseover",this.onMenuMouseOver),r&&r()}getOptions(t){let e=this.dropdownOptions.get(t);if(!e)throw new Error("Can't find options for dropdown menu");return e}handle(t){let{menu:e,toggle:n,showOnHover:r}=t;this.dropdownOptions.set(e,t);let i=s=>{e.hasAttribute("hidden")?this.openDropdown(e):this.closeDropdown(e)};n.addEventListener("click",i),r&&n.addEventListener("mouseenter",()=>{this.openDropdown(e)})}};var ds=class{constructor(){p(this,"dropdowns",new as);p(this,"modalDefinitionsByKey",{});p(this,"activeModalsByKey",{});p(this,"decoratorConstructorsByType",{});p(this,"decoratorInstancesByNodeKey",{});p(this,"context",null);p(this,"toolbar",null);p(this,"contextToolbarDefinitionsByKey",{});p(this,"activeContextToolbars",[]);p(this,"selectionChangeHandlers",new Set);p(this,"domEventAbortController",new AbortController);p(this,"teardownCallbacks",[])}setContext(t){this.context=t,this.setupEventListeners(),this.setupEditor(t.editor)}getContext(){if(this.context===null)throw new Error("Context attempted to be used without being set");return this.context}triggerStateUpdateForElement(t){t.updateState({selection:null,editor:this.getContext().editor})}registerModal(t,e){this.modalDefinitionsByKey[t]=e}createModal(t){let e=this.modalDefinitionsByKey[t];if(!e)throw new Error(`Attempted to show modal of key [${t}] but no modal registered for that key`);let n=new ss(e,t);return n.setContext(this.getContext()),n}setModalActive(t,e){this.activeModalsByKey[t]=e}setModalInactive(t){delete this.activeModalsByKey[t]}getActiveModal(t){return this.activeModalsByKey[t]}registerDecoratorType(t,e){this.decoratorConstructorsByType[t]=e}getDecorator(t,e){if(this.decoratorInstancesByNodeKey[e])return this.decoratorInstancesByNodeKey[e];let n=this.decoratorConstructorsByType[t];if(!n)throw new Error(`Attempted to use decorator of type [${t}] but not decorator registered for that type`);let r=new n(e);return this.decoratorInstancesByNodeKey[e]=r,r}getDecoratorByNodeKey(t){return this.decoratorInstancesByNodeKey[t]||null}setToolbar(t){this.toolbar&&this.toolbar.teardown(),this.toolbar=t,t.setContext(this.getContext()),this.getContext().containerDOM.prepend(t.getDOMElement())}registerContextToolbar(t,e){this.contextToolbarDefinitionsByKey[t]=e}triggerStateUpdate(t){_u(t.editor,t.selection),this.toolbar?.updateState(t),this.updateContextToolbars(t);for(let e of this.activeContextToolbars)e.updateState(t);this.triggerSelectionChange(t.selection)}triggerStateRefresh(){let t=this.getContext().editor,e={editor:t,selection:ae(t)};this.triggerStateUpdate(e),this.updateContextToolbars(e)}triggerFutureStateRefresh(){requestAnimationFrame(()=>{this.getContext().editor.getEditorState().read(()=>{this.triggerStateRefresh()})})}triggerSelectionChange(t){if(t)for(let e of this.selectionChangeHandlers)e(t)}onSelectionChange(t){this.selectionChangeHandlers.add(t)}offSelectionChange(t){this.selectionChangeHandlers.delete(t)}triggerLayoutUpdate(){window.requestAnimationFrame(()=>{for(let t of this.activeContextToolbars)t.updatePosition()})}getDefaultDirection(){return this.getContext().options.textDirection==="rtl"?"rtl":"ltr"}onTeardown(t){this.teardownCallbacks.push(t)}teardown(){this.domEventAbortController.abort("teardown");for(let[t,e]of Object.entries(this.activeModalsByKey))e.teardown();for(let[t,e]of Object.entries(this.decoratorInstancesByNodeKey))e.teardown();this.toolbar&&this.toolbar.teardown();for(let t of this.activeContextToolbars)t.teardown();this.dropdowns.teardown();for(let t of this.teardownCallbacks)t()}updateContextToolbars(t){for(let s=this.activeContextToolbars.length-1;s>=0;s--)this.activeContextToolbars[s].teardown(),this.activeContextToolbars.splice(s,1);let e=(t.selection?.getNodes()||[])[0]||null;if(!e)return;let n=t.editor.getElementByKey(e.getKey());if(!n)return;let r=Object.keys(this.contextToolbarDefinitionsByKey),i=new Map;for(let s of r){let l=this.contextToolbarDefinitionsByKey[s],a=n.closest(l.selector)||n.querySelector(l.selector);if(a){let d=l.displayTargetLocator?l.displayTargetLocator(a):a;i.has(d)||i.set(d,[]),i.get(d).push(...l.content())}}for(let[s,l]of i){let a=new ls(s,l);a.setContext(this.getContext()),this.activeContextToolbars.push(a),this.getContext().containerDOM.append(a.getDOMElement()),a.updatePosition()}}setupEditor(t){let e=n=>{t.getEditorState().read(()=>{let r=Object.keys(n);for(let i of r){let s=t.getElementByKey(i);if(!s)continue;let l=n[i],a=this.getDecorator(l.type,i);a.setNode(l.getNode());let d=a.render(this.getContext(),s);d&&s.append(d)}})};t.registerDecoratorListener(e),t.registerUpdateListener(({editorState:n,prevEditorState:r})=>{!r._selection?.is(n._selection)&&t.update(()=>{let s=C();this.triggerStateUpdate({editor:t,selection:s})})})}setupEventListeners(){let t=this.triggerLayoutUpdate.bind(this);window.addEventListener("scroll",t,{capture:!0,passive:!0,signal:this.domEventAbortController.signal}),window.addEventListener("resize",t,{passive:!0,signal:this.domEventAbortController.signal})}};function Aa(o,t,e){let n=y("div",{contenteditable:"true",class:`editor-content-area ${e.editorClass||""}`}),r=y("div",{class:"editor-content-wrap"},[n]);o.append(r),o.classList.add("editor-container"),o.setAttribute("dir",e.textDirection),e.darkMode&&o.classList.add("editor-dark");let i=new ds,s={editor:t,containerDOM:o,editorDOM:n,scrollDOM:r,manager:i,translate(l){return e.translations[l]||l},error(l){let a=l instanceof Error?l.message:l;window.$events.error(a)},options:e};return i.setContext(s),s}function cn(o,t){o.update(()=>{let e=H();for(let r of e.getChildren())r.remove(!0);let n=_o(o,t);e.append(...n)})}function em(o,t){o.update(()=>{let e=H(),n=_o(o,t);e.append(...n)})}function tm(o,t){o.update(()=>{let e=H(),n=_o(o,t),r=e.getChildren()[0];for(let i=n.length-1;i>=0;i--)r?r.insertBefore(n[i]):e.append(n[i]),r=n[i]})}function om(o,t){o.update(()=>{let e=C(),n=_o(o,t),r=e?.getNodes()[0],i=r?.getParents()||[];if(i[i.length-1]&&r)for(let l=n.length-1;l>=0;l--)r.insertAfter(n[l])})}function cs(o){return new Promise((t,e)=>{o.getEditorState().read(()=>{let n=Ri(o);t(n)})})}function us(o){o.focus(()=>{},{defaultSelection:"rootStart"})}var tr=class{constructor(t,e,n){p(this,"container");p(this,"dragTargetSelector");p(this,"options");p(this,"startX",0);p(this,"startY",0);p(this,"target",null);this.container=t,this.dragTargetSelector=e,this.options=n,this.onMouseDown=this.onMouseDown.bind(this),this.onMouseMove=this.onMouseMove.bind(this),this.onMouseUp=this.onMouseUp.bind(this),this.container.addEventListener("mousedown",this.onMouseDown)}teardown(){this.container.removeEventListener("mousedown",this.onMouseDown),this.container.removeEventListener("mouseup",this.onMouseUp),this.container.removeEventListener("mousemove",this.onMouseMove)}onMouseDown(t){this.target=t.target.closest(this.dragTargetSelector),this.target&&(this.startX=t.screenX,this.startY=t.screenY,window.addEventListener("mousemove",this.onMouseMove),window.addEventListener("mouseup",this.onMouseUp),this.options.down&&this.options.down(t,this.target))}onMouseMove(t){this.options.move&&this.target&&this.options.move(t,this.target,{x:t.screenX-this.startX,y:t.screenY-this.startY})}onMouseUp(t){window.removeEventListener("mousemove",this.onMouseMove),window.removeEventListener("mouseup",this.onMouseUp),this.options.up&&this.target&&this.options.up(t,this.target,{x:t.screenX-this.startX,y:t.screenY-this.startY})}};var Ra=class{constructor(t,e){p(this,"editor");p(this,"editScrollContainer");p(this,"markerDom",null);p(this,"mouseTracker",null);p(this,"dragging",!1);p(this,"targetCell",null);p(this,"xMarkerAtStart",!1);p(this,"yMarkerAtStart",!1);p(this,"activeInTable",!1);this.editor=t,this.editScrollContainer=e,this.setupListeners()}teardown(){this.editScrollContainer.removeEventListener("mousemove",this.onCellMouseMove),window.removeEventListener("scroll",this.onScrollOrResize,{capture:!0}),window.removeEventListener("resize",this.onScrollOrResize),this.mouseTracker&&this.mouseTracker.teardown()}setupListeners(){this.onTableMouseOver=this.onTableMouseOver.bind(this),this.onCellMouseMove=this.onCellMouseMove.bind(this),this.onScrollOrResize=this.onScrollOrResize.bind(this),this.editScrollContainer.addEventListener("mouseover",this.onTableMouseOver,{passive:!0}),window.addEventListener("scroll",this.onScrollOrResize,{capture:!0,passive:!0}),window.addEventListener("resize",this.onScrollOrResize,{passive:!0})}onScrollOrResize(){this.updateCurrentMarkerTargetPosition()}onTableMouseOver(t){if(this.dragging)return;let e=t.target.closest("table");e&&!this.activeInTable?(this.editScrollContainer.addEventListener("mousemove",this.onCellMouseMove,{passive:!0}),this.onCellMouseMove(t),this.activeInTable=!0):!e&&this.activeInTable&&(this.editScrollContainer.removeEventListener("mousemove",this.onCellMouseMove),this.hideMarkers(),this.activeInTable=!1)}onCellMouseMove(t){let e=t.target.closest("td,th");if(!e||this.dragging)return;let n=e.getBoundingClientRect(),r=n.left+n.width/2,i=n.top+n.height/2;this.targetCell=e,this.xMarkerAtStart=t.clientX<=r,this.yMarkerAtStart=t.clientY<=i;let s=this.xMarkerAtStart?n.left:n.right,l=this.yMarkerAtStart?n.top:n.bottom;this.updateMarkersTo(e,s,l)}updateMarkersTo(t,e,n){let r=this.getMarkers(),i=t.closest("table"),s=i.querySelector("caption"),l=i.getBoundingClientRect(),a=this.editScrollContainer.getBoundingClientRect(),d=l.top;s&&(d=s.getBoundingClientRect().bottom);let u=Math.max(d,a.top),c=Math.min(l.bottom,a.bottom)-u;r.x.style.left=e+"px",r.x.style.top=u+"px",r.x.style.height=c+"px",r.y.style.top=n+"px",r.y.style.left=l.left+"px",r.y.style.width=l.width+"px",r.y.hidden=na.bottom,r.x.hidden=l.top>a.bottom||l.bottom0?d-=1:e.xMarkerAtStart&&d===0&&(u=-u),e.editor.update(()=>{let m=ee(a);if(m instanceof bt){let c=If(e.editor,m,d),f=Math.max(c+u,10);La(m,d,f)}})}if(r==="top"&&e.targetCell){let d=e.targetCell;e.editor.update(()=>{let m=ee(d)?.getParent(),c=m?.getIndexWithinParent()||0,f=l.y;e.yMarkerAtStart&&c>0?c-=1:e.yMarkerAtStart&&c===0&&(f=-f);let g=m?.getParent()?.getChildren()[c];if(g instanceof ro){let h=g.getHeight()||0,N=Math.max(h+f,10);g.setHeight(N)}})}}})}getTargetCellColumnIndex(){let t=this.targetCell;if(t===null)return-1;let e=0,n=t.parentElement;for(let r of n?.children||[]){let i=Number(r.getAttribute("colspan"));if((Number.isNaN(i)||i<1)&&(i=1),e+=i,r===t)return e-1}return-1}};function nm(o,t){let e=new Ra(o,t);return()=>{e.teardown()}}function fs(o){return o.html||""}function rm(o){window.$events.listen("editor::replace",e=>{let n=fs(e);cn(o,n)}),window.$events.listen("editor::append",e=>{let n=fs(e);em(o,n)}),window.$events.listen("editor::prepend",e=>{let n=fs(e);tm(o,n)}),window.$events.listen("editor::insert",e=>{let n=fs(e);om(o,n)}),window.$events.listen("editor::focus",()=>{us(o)});let t=!0;o.registerUpdateListener(({dirtyElements:e,dirtyLeaves:n,editorState:r,prevEditorState:i})=>{(e.size>0||n.size>0)&&(t?t=!1:window.$events.emit("editor-html-change",""))})}var ms=class{constructor(t){p(this,"data");this.data=t}hasItems(){return!!this.data&&!!this.data.types&&this.data.types.length>0}containsTabularData(){let t=this.data.getData("text/rtf");return!!t&&t.includes("\\trowd")}getImages(){return this.getFiles().filter(t=>t.type.includes("image"))}getFiles(){let{files:t}=this.data;return[...t]}};function ps(o){window.$components.first("image-manager").show(e=>{o(e)},"gallery")}function im(o){let t=o.thumbs?.display||o.url,e=Tt(t,{target:"_blank"}),n=tn(t,{alt:o.name});return e.append(n),e}async function sm(o,t){if(o===null||o.type.indexOf("image")!==0)throw new Error("Not an image file");let e=o.name||`image-${Date.now()}.png`,n=new FormData;return n.append("file",o,e),n.append("uploaded_to",t),(await window.$http.post("/images/gallery",n)).data}function Ux(o,t){let e=o.clientX,n=o.clientY;return document.elementFromPoint(e,n)?Eu(t,o.clientX,o.clientY):null}function lm(o,t,e){let n=Ux(t,e);n&&rt(n),Kl(o,!0),(!F(n)||!n?.getTextContent())&&n?.remove()}async function zx(o,t,e){let i=((await window.$http.get(`/templates/${t}`)).data||{html:""}).html||"";o.update(()=>{let s=_o(o,i);lm(s,e,o)})}function am(o,t){let e=new ms(o),n=!1;if(!e.hasItems()||e.containsTabularData())return n;let r=e.getImages();return r.length>0&&(n=!0),t.editor.update(async()=>{for(let i of r){let s=window.baseUrl("/loading.gif"),l=tn(s),a=I();a.append(l),Me([a]);try{let d=await sm(i,t.options.pageId),u=d.name.replace(/"/g,"");t.editor.update(()=>{let m=tn(d.thumbs?.display||"",{alt:u}),c=Tt(d.url,{target:"_blank"});c.append(m),l.replace(c)})}catch(d){t.editor.update(()=>{l.remove(!1)}),window.$events.error(d?.data?.message||t.options.translations.imageUploadErrorText),console.error(d)}}}),n}function Wx(o,t){let e=/https?:\/\/([^?#]*?)\.(png|jpeg|jpg|gif|webp|bmp|avif)/i,n=o.getData("text/plain");return n&&e.test(n)?(t.editor.update(()=>{let r=tn(n);Me([r]),r.select()}),!0):!1}function qx(o){let t=o.editor;return e=>{let n=e.dataTransfer?.getData("bookstack/template")||"";if(n)return zx(t,n,e),e.preventDefault(),e.stopPropagation(),!0;let r=e.dataTransfer?.getData("text/html")||"";return r?(t.update(()=>{let i=_o(t,r);lm(i,e,t)}),e.preventDefault(),e.stopPropagation(),!0):e.dataTransfer&&am(e.dataTransfer,o)?(e.preventDefault(),e.stopPropagation(),!0):!1}}function Yx(o){return t=>{if(!t.clipboardData)return!1;let e=Wx(t.clipboardData,o)||am(t.clipboardData,o);return e&&t.preventDefault(),e}}function dm(o){let t=qx(o),e=Yx(o),n=o.editor.registerCommand($o,t,Xe),r=o.editor.registerCommand(ao,e,Xe);return o.scrollDOM.addEventListener("drop",t),()=>{n(),r(),o.scrollDOM.removeEventListener("drop",t)}}var ka=class{constructor(t,e){p(this,"editorContainer");p(this,"editor");this.editor=t,this.editorContainer=e,this.setupListeners()}setupListeners(){this.handleClick=this.handleClick.bind(this),this.editorContainer.addEventListener("click",this.handleClick)}handleClick(t){let e=t.target;e instanceof HTMLElement&&e.nodeName==="LI"&&e.classList.contains("task-list-item")&&(this.handleTaskListItemClick(e,t),t.preventDefault())}handleTaskListItemClick(t,e){let n=t.getBoundingClientRect();e.clientX<=n.right&&e.clientX>=n.left&&e.clientY>=n.top&&e.clientY<=n.bottom||this.editor.update(()=>{let i=ee(t);X(i)&&i.setChecked(!i.getChecked())})}teardown(){this.editorContainer.removeEventListener("click",this.handleClick)}};function cm(o,t){let e=new ka(o,t);return()=>{e.teardown()}}var Ia=class{constructor(t){p(this,"editor");p(this,"tableSelections",new Map);p(this,"unregisterMutationListener",()=>{});this.editor=t,this.init()}init(){this.unregisterMutationListener=this.editor.registerMutationListener(bt,t=>{for(let[e,n]of t)if(n==="created")this.editor.getEditorState().read(()=>{let r=Q(e);K(r)&&this.initializeTableNode(r)});else if(n==="destroyed"){let r=this.tableSelections.get(e);r!==void 0&&(r.removeListeners(),this.tableSelections.delete(e))}})}initializeTableNode(t){let e=t.getKey(),n=this.editor.getElementByKey(e);if(n&&!this.tableSelections.has(e)){let r=_a(t,n,this.editor,!0);this.tableSelections.set(e,r)}}teardown(){this.unregisterMutationListener();for(let[,t]of this.tableSelections)t.removeListeners()}};function um(o){let t=new Ia(o);return()=>{t.teardown()}}var Zx=(o,t)=>Qn(o)&&o.getTag()===t;function gs(o,t){o.update(()=>{Fn(e=>Zx(e,t),()=>Gn(t))})}function Zr(o){o.update(()=>{Fn(Ze,I)})}function Vr(o){o.update(()=>{Fn(ns,os)})}function Xr(o,t){o.getEditorState().read(()=>{let e=C();de(e,r=>z(r)&&r.getListType()===t)?ua(o):ca(o,t)})}function jr(o){o.getEditorState().read(()=>{let t=C(),e=ae(o),n=Z(e,es);n===null?o.update(()=>{let r=Qi();r.setCode(t?.getTextContent()||"");let i=At(t),s=i[0],l=i.slice(1);s?(s.replace(r),l.forEach(a=>a.remove())):Vo(r,!0),qr(o,r),rt(r)}):qr(o,n)})}function fm(o){o.update(()=>{let t=C(),e=At(t),n=!1;for(let i of e)ra(i)||(i.replace(Wn("info"),!0),n=!0);if(n)return;let r=["info","warning","danger","success"];for(let i of e)if(ra(i)){let s=i.getCategory(),a=(r.indexOf(s)+1)%r.length,d=r[a];i.setCategory(d)}})}function hs(o,t){o.update(()=>{let e=C(),n=Z(e,$t);if($t(n)?(n.setURL(t.url),n.setTarget(t.target),n.setTitle(t.title)):(n=Tt(t.url,{title:t.title,target:t.target}),Me([n])),$t(n)){for(let r of n.getChildren())r.remove(!0);n.append(q(t.text))}})}var Gr=class extends oe{constructor(e,n){super([e,n]);p(this,"input");p(this,"action");this.input=e,this.action=n}buildDOM(){return y("div",{class:"editor-action-input-container"},[this.input.getDOMElement(),this.action.getDOMElement()])}};var w=class extends ve{constructor(e){super();p(this,"definition");p(this,"active",!1);p(this,"completedSetup",!1);p(this,"disabled",!1);e.action!==void 0?this.definition=e:this.definition={...e,action(){return!1},isActive:()=>!1}}setContext(e){super.setContext(e),this.definition.setup&&!this.completedSetup&&(this.definition.setup(e,this),this.completedSetup=!0)}buildDOM(){let e=this.getLabel(),n=this.definition.format||"small",r=[];if(this.definition.icon||n==="long"){let s=y("div",{class:"editor-button-icon"});s.innerHTML=this.definition.icon||"",r.push(s)}if(!this.definition.icon||n==="long"){let s=y("div",{class:"editor-button-text"},[e]);r.push(s)}let i=y("button",{type:"button",class:`editor-button editor-button-${n}`,title:this.definition.icon?e:null,disabled:this.disabled?"true":null},r);return i.addEventListener("click",this.onClick.bind(this)),i}onClick(){let e=this.definition.action(this.getContext(),this);e instanceof Promise?e.then(n=>{n===!1&&this.emitEvent("button-action")}):e!==!1&&this.emitEvent("button-action")}updateActiveState(e){let n=this.definition.isActive(e,this.getContext());this.setActiveState(n)}updateDisabledState(e){if(this.definition.isDisabled){let n=this.definition.isDisabled(e,this.getContext());this.toggleDisabled(n)}}setActiveState(e){this.active=e,this.dom?.classList.toggle("editor-button-active",this.active)}updateState(e){this.updateActiveState(e.selection),this.updateDisabledState(e.selection)}isActive(){return this.active}getLabel(){return this.trans(this.definition.label)}toggleDisabled(e){this.disabled=e,e?this.dom?.setAttribute("disabled","true"):this.dom?.removeAttribute("disabled")}};var mm='';var pm='';function Ns(o,t){window.$components.first("entity-selector-popup").show(n=>o(n),{initialValue:t,searchEndpoint:"/search/entity-selector",entityTypes:"page,book,chapter,bookshelf",entityPermission:"view"})}var xs=class extends oe{constructor(e){super([e]);p(this,"input");p(this,"headerMap",new Map);this.input=e}buildDOM(){let e="editor-form-datalist-"+this.input.getName()+"-"+Date.now(),n=this.input.getDOMElement(),r=n.querySelector("input");r?.setAttribute("list",e),r?.setAttribute("autocomplete","off");let i=y("datalist",{id:e}),s=y("div",{class:"editor-link-field-container"},[n,i]);return r?.addEventListener("focusin",()=>{this.updateDataList(i)}),r?.addEventListener("input",()=>{let l=r.value,a=this.headerMap.get(l);a&&this.updateFormFromHeader(a)}),s}updateFormFromHeader(e){this.getHeaderIdAndText(e).then(({id:n,text:r})=>{let i=this.getContext().manager.getActiveModal("link");i&&i.getForm().setValues({url:`#${n}`,text:r,title:r})})}getHeaderIdAndText(e){return new Promise(n=>{this.getContext().editor.update(()=>{let r=e.getId();r||(r="header-"+rs(),e.setId(r));let i=e.getTextContent();n({id:r,text:i})})})}updateDataList(e){this.getContext().editor.getEditorState().read(()=>{let n=Hl(Qn);this.headerMap.clear();let r=[];for(let i of n){let s="header-"+i.getKey();this.headerMap.set(s,i),r.push(y("option",{value:s,label:i.getTextContent().substring(0,54)}))}e.innerHTML="",e.append(...r)})}};function gm(o,t){let e=t.manager.createModal("image"),n=o.getHeight(),r=o.getWidth(),i={src:o.getSrc(),alt:o.getAltText(),height:n===0?"":String(n),width:r===0?"":String(r)};e.show(i)}var hm={submitText:"Apply",async action(o,t){return t.editor.update(()=>{let e=ae(t.editor),n=Z(e,je);je(n)&&(n.setSrc(o.get("src")?.toString()||""),n.setAltText(o.get("alt")?.toString()||""),n.setWidth(Number(o.get("width")?.toString()||"0")),n.setHeight(Number(o.get("height")?.toString()||"0")))}),!0},fields:[{build(){return new Gr(new Ft({label:"Source",name:"src",type:"text"}),new w({label:"Browse files",icon:mm,action(o){ps(t=>{let e=o.manager.getActiveModal("image");e&&e.getForm().setValues({src:t.thumbs?.display||t.url,alt:t.name})})}}))}},{label:"Alternative description",name:"alt",type:"text"},{label:"Width",name:"width",type:"text"},{label:"Height",name:"height",type:"text"}]};function Es(o,t){let e=t.manager.createModal("link");if(o){let n={url:o.getURL(),text:o.getTextContent(),title:o.getTitle()||"",target:o.getTarget()||""};t.editor.update(()=>{let r=jo();r.add(o.getKey()),Y(r)}),e.show(n)}else t.editor.getEditorState().read(()=>{let i={text:C()?.getTextContent()||""};e.show(i)})}var Nm={submitText:"Apply",async action(o,t){return hs(t.editor,{url:o.get("url")?.toString()||"",title:o.get("title")?.toString()||"",target:o.get("target")?.toString()||"",text:o.get("text")?.toString()||""}),!0},fields:[{build(){return new Gr(new xs(new Ft({label:"URL",name:"url",type:"text"})),new w({label:"Browse links",icon:pm,action(o){Ns(t=>{let e=o.manager.getActiveModal("link");e&&e.getForm().setValues({url:t.link,text:t.name,title:t.name})})}}))}},{label:"Text to display",name:"text",type:"text"},{label:"Title",name:"title",type:"text"},{label:"Open link in...",name:"target",type:"select",valuesByLabel:{"Current window":"","New window":"_blank"}}]};function xm(o,t){let e=t.manager.createModal("media"),n={};if(o){let r=o.getAttributes(),i=o.exportDOM(t.editor).element,s=i instanceof HTMLElement?i.outerHTML:"";n={src:r.src||r.data||o.getSources()[0]?.src||"",width:r.width,height:r.height,embed:s,embed_check:s}}e.show(n)}var Em={submitText:"Save",async action(o,t){let e=await new Promise((i,s)=>{t.editor.getEditorState().read(()=>{let l=Z(C(),_t);i(l)})}),n=(o.get("embed")||"").toString().trim(),r=(o.get("embed_check")||"").toString().trim();return n&&n!==r?(t.editor.update(()=>{let i=Zf(n);e&&i?e.replace(i):i&&Me([i])}),!0):(t.editor.update(()=>{let i=(o.get("src")||"").toString().trim(),s=(o.get("height")||"").toString().trim(),l=(o.get("width")||"").toString().trim();if(e){e.setSrc(i),e.setWidthAndHeight(l,s),t.manager.triggerFutureStateRefresh();return}let a=Vf(i);(l||s)&&a.setWidthAndHeight(l,s),Me([a])}),!0)},fields:[{build(){return new dn([{label:"General",contents:[{label:"Source",name:"src",type:"text"},{label:"Width",name:"width",type:"text"},{label:"Height",name:"height",type:"text"}]},{label:"Embed",contents:[{label:"Paste your embed code below:",name:"embed",type:"textarea"},{label:"",name:"embed_check",type:"hidden"}]}])}}]};function Tm(o,t){let e=t.manager.createModal("details");o&&e.show({summary:o.getSummary()})}var Cm={submitText:"Save",async action(o,t){return t.editor.update(()=>{let e=Z(C(),$e),n=(o.get("summary")||"").toString().trim();$e(e)&&e.setSummary(n)}),!0},fields:[{label:"Toggle label",name:"summary",type:"text"}]};function Ts(o,t){return gs(o.editor,t),o.manager.triggerFutureStateRefresh(),!0}function so(o){return(t,e)=>(o(t),e.manager.triggerFutureStateRefresh(),!0)}function bm(o){return o.dispatchCommand(xe,"code"),!0}var _m={"meta+s":()=>(window.$events.emit("editor-save-draft"),!0),"meta+enter":()=>(window.$events.emit("editor-save-page"),!0),"meta+1":(o,t)=>Ts(t,"h2"),"meta+2":(o,t)=>Ts(t,"h3"),"meta+3":(o,t)=>Ts(t,"h4"),"meta+4":(o,t)=>Ts(t,"h5"),"meta+5":so(Zr),"meta+d":so(Zr),"meta+6":so(Vr),"meta+q":so(Vr),"meta+7":so(jr),"meta+e":so(jr),"meta+8":bm,"meta+shift+e":bm,"meta+9":so(fm),"meta+o":so(o=>Xr(o,"number")),"meta+p":so(o=>Xr(o,"bullet")),"meta+k":(o,t)=>(o.getEditorState().read(()=>{let e=Z(C(),$t);Es(e,t)}),!0),"meta+shift+k":(o,t)=>(Ns(e=>{hs(o,{text:e.name,title:e.link,target:"",url:e.link})}),!0)};function jx(o){return t=>{let e=Gx(t);_m[e]&&_m[e](o.editor,o)&&(t.stopPropagation(),t.preventDefault())}}function Gx(o){return[(ym()?o.metaKey:o.ctrlKey)?"meta":"",o.shiftKey?"shift":"",o.key].filter(Boolean).join("+").toLowerCase()}function ym(){return window.navigator.userAgent.includes("Mac OS X")}function Jx(o){o.registerCommand(Ke,t=>ym()?t?.metaKey||!1:t?.ctrlKey||!1,Xe)}function $a(o){let t=jx(o);return Jx(o.editor),o.editor.registerRootListener((e,n)=>{e?.addEventListener("keydown",t),n?.removeEventListener("keydown",t)})}function Qx(o){return je(o)||_t(o)}var Pa=class{constructor(t){p(this,"context");p(this,"resizerDOM",null);p(this,"targetNode",null);p(this,"scrollContainer");p(this,"mouseTracker",null);p(this,"activeSelection","");p(this,"loadAbortController",new AbortController);this.context=t,this.scrollContainer=t.scrollDOM,this.onSelectionChange=this.onSelectionChange.bind(this),this.onTargetDOMLoad=this.onTargetDOMLoad.bind(this),t.manager.onSelectionChange(this.onSelectionChange)}onSelectionChange(t){let e=t?.getNodes()||[];if(this.activeSelection&&this.hide(),e.length===1&&Qx(e[0])){let n=e[0],r=this.getTargetDOM(n);r&&this.showForNode(n,r)}}getTargetDOM(t){if(t==null)return null;let e=this.context.editor.getElementByKey(t.__key);return e&&e.nodeName==="SPAN"&&(e=e.firstElementChild),e}onTargetDOMLoad(){this.updateResizerPosition()}teardown(){this.context.manager.offSelectionChange(this.onSelectionChange),this.hide()}showForNode(t,e){this.resizerDOM=this.buildDOM(),this.targetNode=t;let n=y("span",{class:"editor-node-resizer-ghost"});je(t)&&(n=y("img",{src:e.getAttribute("src"),class:"editor-node-resizer-ghost"})),this.resizerDOM.append(n),this.context.scrollDOM.append(this.resizerDOM),this.updateResizerPosition(),this.mouseTracker=this.setupTracker(this.resizerDOM,t,e),this.activeSelection=t.getKey(),e.matches("img, embed, iframe, object")&&(this.loadAbortController=new AbortController,e.addEventListener("load",this.onTargetDOMLoad,{signal:this.loadAbortController.signal}))}updateResizerPosition(){let t=this.getTargetDOM(this.targetNode);if(!this.resizerDOM||!t)return;let e=this.scrollContainer.getBoundingClientRect(),n=t.getBoundingClientRect(),r=n.top-(e.top-this.scrollContainer.scrollTop),i=n.left-e.left;this.resizerDOM.style.top=`${r}px`,this.resizerDOM.style.left=`${i}px`,this.resizerDOM.style.width=n.width+"px",this.resizerDOM.style.height=n.height+"px"}updateDOMSize(t,e){this.resizerDOM&&(this.resizerDOM.style.width=t+"px",this.resizerDOM.style.height=e+"px")}hide(){this.mouseTracker?.teardown(),this.resizerDOM?.remove(),this.targetNode=null,this.activeSelection="",this.loadAbortController.abort()}buildDOM(){let e=["nw","ne","se","sw"].map(n=>y("div",{class:`editor-node-resizer-handle ${n}`}));return y("div",{class:"editor-node-resizer"},e)}setupTracker(t,e,n){let r=0,i=0,s=0,l=!1,a=this,d=!1,u=!1,m=c=>{let f=c.x;d&&(f=0-f);let g=c.y;u&&(g=0-g);let h=Math.sqrt(Math.pow(Math.abs(f),2)+Math.pow(Math.abs(g),2)),b=f+g>0?h:0-h,x=Math.max(5,Math.round(r+b)),S=Math.round(x*s);return{width:x,height:S}};return new tr(t,".editor-node-resizer-handle",{down(c,f){a.resizerDOM?.classList.add("active"),a.context.editor.getEditorState().read(()=>{let g=n.getBoundingClientRect();r=e.getWidth()||g.width,i=e.getHeight()||g.height,e.getHeight()&&(l=!0),s=i/r}),d=f.classList.contains("nw")||f.classList.contains("sw"),u=f.classList.contains("nw")||f.classList.contains("ne")},move(c,f,g){let h=m(g);a.updateDOMSize(h.width,h.height)},up(c,f,g){let h=m(g);a.context.editor.update(()=>{e.setWidth(h.width),e.setHeight(l?h.height:0)},{onUpdate:()=>{requestAnimationFrame(()=>{a.context.manager.triggerLayoutUpdate(),a.updateResizerPosition()})}}),a.resizerDOM?.classList.remove("active")}})}};function Sm(o){let t=new Pa(o);return()=>{t.teardown()}}function eE(o){let t=o.getParent();if(!z(t))return o;let e=o.getChildren().filter(d=>z(d))[0]||null,n=e?.getChildren()||[],r=t.getChildren(),i=r.findIndex(d=>d.getKey()===o.getKey()),s=i===0,l=Pe(),a=be(t.getListType());if(a.append(l),l.append(...o.getChildren()),s?o.append(a):(r[i-1].append(a),o.remove()),e){for(let d of n)l.insertAfter(d);e.remove()}return l}function tE(o){let t=o.getParent(),e=t?.getParent(),n=e?.getParent();if(!z(t)||!z(n)||!X(e))return o;let r=o.getNextSiblings();if(e.insertAfter(o),t.getChildren().length===0&&t.remove(),r.length>0){let i=be(t.getListType());i.append(...r),o.append(i)}return t.getChildrenSize()===0&&t.remove(),e.getChildren().length===0&&e.remove(),o}function oE(o){let t=o?.getNodes()||[],[e,n]=o?.getStartEndPoints()||[null,null],r=new Set;if(o&&e){o.isBackward()&&n&&([n,e]=[e,n]);let s=e.getNode().getParents(),l=!1;for(let a of s)X(a)&&(l?r.add(a.getKey()):l=!0)}let i=[];e:for(let s of t){if(X(s)){r.has(s.getKey())||i.push(s);continue}let l=s.getParents();for(let a of l)if(X(a)){r.has(a.getKey())||i.push(a);continue e}i.push(null)}return i}function nE(o){let t={};for(let n of o){if(n===null)continue;let r=n.getKey();typeof t[r]>"u"&&(t[r]=n)}let e=Object.values(t);return Tu(e)}function Jr(o,t){let e=C(),n=e?.getStartEndPoints(),r=oE(e);if(r.length>0&&!r.includes(null)){let l=[],a=nE(r);if(t>0)for(let d of a)l.push(eE(d));else if(t<0){for(let d of[...a].reverse())l.push(tE(d));l.reverse()}if(l.length===1&&n){let d=l[0],u=d.getChildren()[0];u||(u=q(""),d.append(u)),u.select(n[0].offset,n[1].offset)}else wu(l);return}let s=At(e);for(let l of s)if(Cu(l)){let a=l.getInset(),d=Math.min(Math.max(a+t,0),500);l.setInset(d)}vu(o)}var or=class extends Error{constructor(e,n){super(e.statusText);p(this,"data");p(this,"headers");p(this,"original");p(this,"redirected");p(this,"status");p(this,"statusText");p(this,"url");this.data=n,this.headers=e.headers,this.redirected=e.redirected,this.status=e.status,this.statusText=e.statusText,this.url=e.url,this.original=e}};function Cs(o){return new Promise((t,e)=>{o.oncomplete=o.onsuccess=()=>t(o.result),o.onabort=o.onerror=()=>e(o.error)})}function rE(o,t){let e,n=()=>{if(e)return e;let r=indexedDB.open(o);return r.onupgradeneeded=()=>r.result.createObjectStore(t),e=Cs(r),e.then(i=>{i.onclose=()=>e=void 0},()=>{}),e};return(r,i)=>n().then(s=>i(s.transaction(t,r).objectStore(t)))}var Ba;function Fa(){return Ba||(Ba=rE("keyval-store","keyval")),Ba}function Ha(o,t=Fa()){return t("readonly",e=>Cs(e.get(o)))}function Ka(o,t,e=Fa()){return e("readwrite",n=>(n.put(t,o),Cs(n.transaction)))}function Ua(o,t=Fa()){return t("readwrite",e=>(e.delete(o),Cs(e.transaction)))}var yt=null,qa,bs,za,Wa="last-drawing-save";function Ya(o){yt?.contentWindow?.postMessage(JSON.stringify(o),qa)}function sE(o){Ka(Wa,o.data),za&&za(o.data).then(()=>{Ua(Wa)})}function lE(o){Ya({action:"export",format:"xmlpng",xml:o.xml,spin:"Updating drawing"})}function aE(){bs&&bs().then(o=>{Ya({action:"load",autosave:1,xml:o})})}function dE(){let o={};yt&&(window.$events.emitPublic(yt,"editor-drawio::configure",{config:o}),Ya({action:"configure",config:o}))}function Lm(){window.removeEventListener("message",Mm),yt&&document.body.removeChild(yt)}function Mm(o){if(!o.data||o.data.length<1||o.origin!==qa)return;let t=JSON.parse(o.data);t.event==="init"?aE():t.event==="exit"?Lm():t.event==="save"?lE(t):t.event==="export"?sE(t):t.event==="configure"&&dE()}async function cE(){let o=await Ha(Wa),t=document.getElementById("unsaved-drawing-dialog");t||console.error("Missing expected unsaved-drawing dialog"),o&&t&&await window.$components.firstOnElement(t,"confirm-dialog").show()&&(bs=async()=>o)}async function wm(o,t,e){bs=t,za=e,await cE(),yt=document.createElement("iframe"),yt.setAttribute("frameborder","0"),window.addEventListener("message",Mm),yt.setAttribute("src",o),yt.setAttribute("class","fullscreen"),yt.style.backgroundColor="#FFFFFF",document.body.appendChild(yt),qa=new URL(o).origin}async function vm(o,t){let e={image:o,uploaded_to:t};return(await window.$http.post(window.baseUrl("/images/drawio"),e)).data}function Za(){Lm()}async function Dm(o){try{return`data:image/png;base64,${(await window.$http.get(window.baseUrl(`/images/drawio/base64/${o}`))).data.content}`}catch(t){throw t instanceof or&&window.$events.showResponseError(t),Za(),t}}function lo(o){return o instanceof Do}function fE(o,t){o.status===413?window.$events.emit("error",t.options.translations.serverUploadLimitText||""):window.$events.emit("error",t.options.translations.imageUploadErrorText||""),console.error(o)}async function mE(o,t){return await new Promise((n,r)=>{o.getEditorState().read(()=>{let{id:i}=t.getDrawingIdAndUrl();n(i)})})||""}async function pE(o,t,e,n){if(Za(),n){let r=window.baseUrl("/loading.gif");o.editor.update(()=>{t.setDrawingIdAndUrl("",r)})}try{let r=await vm(e,o.options.pageId);o.editor.update(()=>{t.setDrawingIdAndUrl(String(r.id),r.url)})}catch(r){throw r instanceof or&&fE(r,o),n&&o.editor.update(()=>{t.remove()}),new Error(`Failed to save image with error: ${r}`)}}function Qr(o,t){let e=!1;wm(o.options.drawioUrl,async()=>{let n=await mE(o.editor,t);return e=!n,e?"":Dm(n)},async n=>pE(o,t,n,e))}function gE(o){window.$components.first("image-manager").show(e=>{o(e)},"drawio")}function Om(o){let t=ae(o.editor);gE(e=>{o.editor.update(()=>{let n=Xn(e.id,e.url),r=Z(t,lo);lo(r)?r.replace(n):Me([n])})})}function Va(o){if(o.length===1){let t=o[0];if(F(t)||je(t)||_t(t)||lo(t))return!0}return!1}function Am(o){let t=ae(o)?.getNodes()||[];Va(t)&&o.update(()=>{t[0].remove()})}function hE(o,t){let e=ae(o)?.getNodes()||[];if(Va(e)){let n=e[0],r=Zo(n)||n,i=t?.shiftKey===!0;if(r)return requestAnimationFrame(()=>{o.update(()=>{let s=I();i?r.insertBefore(s):r.insertAfter(s),s.select()})}),t?.preventDefault(),!0}return!1}function Rm(o,t,e=!0){let n=ae(o)?.getNodes()||[];if(!Va(n))return!1;t?.preventDefault();let r=n[0];return o.update(()=>{Ar(r,e)}),!0}function NE(o,t){let e=km(o);return e===null||e.detailsSibling?!1:(o.update(()=>{let n=I();e.parentDetails.insertAfter(n),n.select()}),t?.preventDefault(),!0)}function xE(o,t){let e=km(o);if(e===null||e.parentBlock.getTextContent()!=="")return!1;t?.preventDefault();let n=e.parentDetails.getNextSibling();return o.update(()=>{if(n)n.selectStart();else{let r=I();e.parentDetails.insertAfter(r),r.select()}e.parentBlock.remove()}),!0}function km(o){let e=ae(o)?.getNodes()[0];if(!e)return null;let n=Zo(e),r=Ot(e,$e);if(!$e(r)||n===null||n.getKey()!==r.getLastChild()?.getKey())return null;let i=r.getNextSibling();return{parentDetails:r,parentBlock:n,detailsSibling:i}}function EE(o){if(o.length!==1)return!1;let t=o[0];return X(t)||X(t.getParent())}function TE(o,t){let e=t?.shiftKey?-40:40,r=C()?.getNodes()||[];return r.length>1||EE(r)?(o.update(()=>{Jr(o,e)}),t?.preventDefault(),!0):!1}function Im(o){let t=o.editor.registerCommand(qt,()=>(Am(o.editor),!1),Ve),e=o.editor.registerCommand(Yt,()=>(Am(o.editor),!1),Ve),n=o.editor.registerCommand(Ke,l=>hE(o.editor,l)||xE(o.editor,l),Ve),r=o.editor.registerCommand(Io,l=>TE(o.editor,l),Ve),i=o.editor.registerCommand(zt,l=>Rm(o.editor,l,!1),Ve),s=o.editor.registerCommand(Wt,l=>NE(o.editor,l)||Rm(o.editor,l,!0),Ve);return()=>{t(),e(),n(),r(),i(),s()}}function CE(o){return o.toLowerCase().startsWith("http")?/(http|https):\/\/(\S+)\.\S+$/.test(o):!1}function bE(o,t,e){let n=t.getStartEndPoints();if(!n)return;let r=n[0].offset,i=o.getTextContent(),a=i.slice(0,r).lastIndexOf(" ")+1,d=i.slice(a,r);CE(d)&&e.update(()=>{let u=Tt(d);u.append(new nt(d));let m=o.splitText(a,r),c=a>0?1:0,f=m[c];f&&f.replace(u)})}function Xa(o){let t=r=>{let i=C(),s=yu(i);return s&&i&&bE(s,i,o),!1},e=o.registerCommand(ir,t,Kn),n=o.registerCommand(Ke,t,Kn);return()=>{e(),n()}}var _s=class extends oe{buildDOM(){let t=this.getChildren().map(i=>i.getDOMElement()),e=y("div",{class:"editor-format-menu-dropdown editor-dropdown-menu editor-dropdown-menu-vertical",hidden:"true"},t),n=y("button",{class:"editor-format-menu-toggle editor-button",type:"button"},[this.trans("Formats")]),r=y("div",{class:"editor-format-menu editor-dropdown-menu-container"},[n,e]);return this.getContext().manager.dropdowns.handle({toggle:n,menu:e}),this.onEvent("button-action",()=>{this.getContext().manager.dropdowns.closeAll()},r),r}updateState(t){super.updateState(t);for(let e of this.children){if(e instanceof w&&e.isActive()){this.updateToggleLabel(e.getLabel());return}if(e instanceof oe){for(let n of e.getChildren())if(n instanceof w&&n.isActive()){this.updateToggleLabel(n.getLabel());return}}}this.updateToggleLabel(this.trans("Formats"))}updateToggleLabel(t){let e=this.getDOMElement().querySelector("button");e&&(e.innerText=t)}};var Ge=class extends w{constructor(e,n){super(n);p(this,"previewSampleElement");this.previewSampleElement=e}buildDOM(){let e=super.buildDOM();e.innerHTML="";let n=y("span",{class:"editor-button-format-preview"},[this.getLabel()]),r=this.getStylesFromPreview();for(let i of Object.keys(r))n.style.setProperty(i,r[i]);return e.append(n),e}getStylesFromPreview(){let e=y("div",{style:"display: none",hidden:"true",class:"page-content"}),n=this.previewSampleElement.cloneNode();n.textContent=this.getLabel(),e.append(n),document.body.append(e);let r=["color","font-size","background-color","border-inline-start"],i={},s=window.getComputedStyle(n);for(let l of r)i[l]=s.getPropertyValue(l);return e.remove(),i}};var $m='';var ys=class extends w{buildDOM(){let t=super.buildDOM(),e=y("div",{class:"editor-menu-button-icon"});return e.innerHTML=$m,t.append(e),t}};var yE={showOnHover:!1,direction:"horizontal",showAside:void 0,hideOnAction:!0,button:{label:"Menu"}},Te=class extends oe{constructor(e,n){super(n);p(this,"button");p(this,"childItems");p(this,"open",!1);p(this,"options");if(this.childItems=n,this.options=Object.assign({},yE,e),e.button instanceof w)this.button=e.button;else{let r=e.button.format==="long"?ys:w;this.button=new r({...e.button,action(){return!1},isActive:()=>this.open})}this.addChildren(this.button)}insertItems(...e){this.addChildren(...e),this.childItems.push(...e)}buildDOM(){let e=this.button.getDOMElement(),n=this.childItems.map(s=>s.getDOMElement()),r=y("div",{class:`editor-dropdown-menu editor-dropdown-menu-${this.options.direction}`,hidden:"true"},n),i=y("div",{class:"editor-dropdown-menu-container"},[e,r]);return this.getContext().manager.dropdowns.handle({toggle:e,menu:r,showOnHover:this.options.showOnHover,showAside:typeof this.options.showAside=="boolean"?this.options.showAside:this.options.direction==="vertical",onOpen:()=>{this.open=!0,this.getContext().manager.triggerStateUpdateForElement(this.button)},onClose:()=>{this.open=!1,this.getContext().manager.triggerStateUpdateForElement(this.button)}}),this.options.hideOnAction&&this.onEvent("button-action",()=>{this.getContext().manager.dropdowns.closeAll()},i),i}};var Pm='';var Bm='';var Fm=["#000000","#ffffff","#BFEDD2","#FBEEB8","#F8CAC6","#ECCAFA","#C2E0F4","#2DC26B","#F1C40F","#E03E2D","#B96AD9","#3598DB","#169179","#E67E23","#BA372A","#843FA1","#236FA1","#ECF0F1","#CED4D9","#95A5A6","#7E8C8D","#34495E"],Hm="bs-lexical-custom-colors",un=class extends ve{constructor(e){super();p(this,"callback");this.callback=e}buildDOM(){let e=rs(),r=[...Fm,...this.getCustomColorChoices()].map(u=>y("div",{class:"editor-color-select-option",style:`background-color: ${u}`,"data-color":u,"aria-label":u})),i=y("div",{class:"editor-color-select-option","data-color":"",title:this.getContext().translate("Remove color")},[]);i.innerHTML=Pm,r.push(i);let s=y("label",{class:"editor-color-select-option",for:`color-select-${e}`,"data-color":"",title:this.getContext().translate("Custom color")},[]);s.innerHTML=Bm,r.push(s);let l=y("input",{type:"color",hidden:"true",id:`color-select-${e}`});r.push(l),l.addEventListener("change",u=>{l.value&&(this.storeCustomColorChoice(l.value),this.setColor(l.value),this.rebuildDOM())});let a=[];for(let u=0;u{let l=s.target.closest(".editor-table-creator-cell");if(l){let a=Number(l.dataset.rows||0),d=Number(l.dataset.columns||0);this.updateGridSelection(a,d,n,r)}}),i.addEventListener("click",s=>{let l=s.target.closest(".editor-table-creator-cell");l&&this.onCellClick(l)}),i.addEventListener("mouseleave",s=>{this.updateGridSelection(0,0,n,r)}),y("div",{class:"editor-table-creator"},[i,r])}updateGridSelection(t,e,n,r){for(let i of n){let s=Number(i.dataset.rows)<=t&&Number(i.dataset.columns)<=e;i.classList.toggle("active",s)}r.textContent=`${t} x ${e}`}onCellClick(t){let e=Number(t.dataset.rows||0),n=Number(t.dataset.columns||0);if(e<1||n<1)return;let r=Math.min(Math.round(840/n),240),i=Array(n).fill(r+"px");this.getContext().editor.update(()=>{let s=ga(e,n,!1);s.setColWidths(i),Vo(s)})}};var ei=class extends w{constructor(e,n){super(e);p(this,"style");this.style=n}getColorBar(){let e=this.getDOMElement().querySelector("svg .editor-icon-color-bar");if(!e)throw new Error(`Could not find expected color bar in the icon for this ${this.definition.label} button`);return e}updateState(e){if(super.updateState(e),_(e.selection)){let n=Bl(e.selection,this.style);this.getColorBar().setAttribute("fill",n)}}};var Km='';var dt=class extends oe{constructor(e,n){super(n);p(this,"size");p(this,"overflowButton");p(this,"content");this.size=e,this.content=n,this.overflowButton=new Te({button:{label:"More",icon:Km},hideOnAction:!1},[]),this.addChildren(this.overflowButton)}buildDOM(){let e=this.content.length>this.size?this.size-1:this.size,n=this.content.slice(0,e),r=this.content.slice(e),i=n.map(s=>s.getDOMElement());return r.length>0&&(this.removeChildren(...r),this.overflowButton.insertItems(...r),i.push(this.overflowButton.getDOMElement())),y("div",{class:"editor-overflow-container"},i)}};var ja='';var Ls='';var Um='';var zm='';var Wm='';var qm='';var Ym='';var Zm='';var Vm=` `;var Ga=class extends oe{constructor(e){super([]);p(this,"input");p(this,"pickerButton");this.input=e,this.pickerButton=new Te({button:{icon:Vm,label:"Select color"}},[new un(this.onColorSelect.bind(this))]),this.addChildren(this.pickerButton,this.input)}buildDOM(){let e=this.input.getDOMElement();e.append(this.pickerButton.getDOMElement()),e.classList.add("editor-color-field-container");let n=e.querySelector("input");return n.addEventListener("change",()=>{this.setIconColor(n.value)}),e}onColorSelect(e,n){this.input.setValue(e)}setIconColor(e){let n=this.getDOMElement().querySelector("svg .editor-icon-color-display");n&&n.setAttribute("fill",e||"url(#pattern2)")}};function fn(o){return{build(){return new Ga(new Ft(o))}}}var Ja={label:"Border style",name:"border_style",type:"select",valuesByLabel:{"Select...":"",Solid:"solid",Dotted:"dotted",Dashed:"dashed",Double:"double",Groove:"groove",Ridge:"ridge",Inset:"inset",Outset:"outset",None:"none",Hidden:"hidden"}},Qa={label:"Border color",name:"border_color",type:"text"},ed={label:"Background color",name:"background_color",type:"text"},Xm={label:"Alignment",name:"align",type:"select",valuesByLabel:{None:"",Left:"left",Center:"center",Right:"right"}};function jm(o,t){let e=o.getStyles(),n=t.manager.createModal("cell_properties");return n.show({width:Bf(t.editor,o),height:e.get("height")||"",type:o.getTag(),h_align:o.getAlignment(),v_align:e.get("vertical-align")||"",border_width:e.get("border-width")||"",border_style:e.get("border-style")||"",border_color:e.get("border-color")||"",background_color:o.getBackgroundColor()||e.get("background-color")||""}),n}var Gm={submitText:"Save",async action(o,t){return t.editor.update(()=>{let e=ln(C());for(let n of e){let r=o.get("width")?.toString()||"";Pf(n,r),n.updateTag(o.get("type")?.toString()||""),n.setAlignment(o.get("h_align")?.toString()||""),n.setBackgroundColor(o.get("background_color")?.toString()||"");let i=n.getStyles();i.set("height",xt(o.get("height")?.toString()||"")),i.set("vertical-align",o.get("v_align")?.toString()||""),i.set("border-width",xt(o.get("border_width")?.toString()||"")),i.set("border-style",o.get("border_style")?.toString()||""),i.set("border-color",o.get("border_color")?.toString()||""),n.setStyles(i)}}),!0},fields:[{build(){let o=[{label:"Width",name:"width",type:"text"},{label:"Height",name:"height",type:"text"},{label:"Cell type",name:"type",type:"select",valuesByLabel:{Cell:"td","Header cell":"th"}},{...Xm,label:"Horizontal align",name:"h_align"},{label:"Vertical align",name:"v_align",type:"select",valuesByLabel:{None:"",Top:"top",Middle:"middle",Bottom:"bottom"}}],t=[{label:"Border width",name:"border_width",type:"text"},Ja,fn(Qa),fn(ed)];return new dn([{label:"General",contents:o},{label:"Advanced",contents:t}])}}]};function Jm(o,t){let e=o.getStyles(),n=t.manager.createModal("row_properties");return n.show({height:e.get("height")||"",border_style:e.get("border-style")||"",border_color:e.get("border-color")||"",background_color:e.get("background-color")||""}),n}var Qm={submitText:"Save",async action(o,t){return t.editor.update(()=>{let e=io(C());for(let n of e){let r=n.getStyles();r.set("height",xt(o.get("height")?.toString()||"")),r.set("border-style",o.get("border_style")?.toString()||""),r.set("border-color",o.get("border_color")?.toString()||""),r.set("background-color",o.get("background_color")?.toString()||""),n.setStyles(r)}}),!0},fields:[{label:"Height",name:"height",type:"text"},Ja,fn(Qa),fn(ed)]};function ep(o,t){let e=o.getStyles(),n=t.manager.createModal("table_properties");return n.show({width:e.get("width")||"",height:e.get("height")||"",cell_spacing:e.get("cell-spacing")||"",cell_padding:Uf(o),border_width:e.get("border-width")||"",border_style:e.get("border-style")||"",border_color:e.get("border-color")||"",background_color:e.get("background-color")||"",caption:ma(o)?"true":"",align:o.getAlignment()}),n}var tp={submitText:"Save",async action(o,t){return t.editor.update(()=>{let e=Ct(C());if(!e)return;let n=e.getStyles();n.set("width",xt(o.get("width")?.toString()||"")),n.set("height",xt(o.get("height")?.toString()||"")),n.set("cell-spacing",xt(o.get("cell_spacing")?.toString()||"")),n.set("border-width",xt(o.get("border_width")?.toString()||"")),n.set("border-style",o.get("border_style")?.toString()||""),n.set("border-color",o.get("border_color")?.toString()||""),n.set("background-color",o.get("background_color")?.toString()||""),e.setStyles(n),e.setAlignment(o.get("align"));let r=o.get("cell_padding")?.toString()||"";if(r){let l=xt(r);wa(e,a=>{let d=a.getStyles();d.set("padding",l),a.setStyles(d)})}let i=!!o.get("caption")?.toString(),s=ma(e);if(i&&!s)yf(e,t.translate("Caption"));else if(!i&&s)for(let l of e.getChildren())Fr(l)&&l.remove()}),!0},fields:[{build(){let o=[{label:"Width",name:"width",type:"text"},{label:"Height",name:"height",type:"text"},{label:"Cell spacing",name:"cell_spacing",type:"text"},{label:"Cell padding",name:"cell_padding",type:"text"},{label:"Border width",name:"border_width",type:"text"},{label:"Show caption",name:"caption",type:"checkbox"},Xm],t=[Ja,fn(Qa),fn(ed)];return new dn([{label:"General",contents:o},{label:"Advanced",contents:t}])}}]};function op(o){let t=T(o)?o.getChildren():[];return{node:o.exportJSON(),children:t.map(e=>op(e))}}function np(o,{node:t,children:e}){let n=o._nodes.get(t.type)?.klass.importJSON(t);if(!n)return null;let r=e.map(i=>np(o,i));for(let i of r)i&&T(n)&&n.append(i);return n}var ti=class{constructor(){p(this,"store",[])}set(...t){this.store.splice(0,this.store.length);for(let e of t)this.store.push(op(e))}get(t){return this.store.map(e=>np(t,e)).filter(e=>e!==null)}size(){return this.store.length}};var oi=new ti;function td(){return oi.size()===0}function rp(o){let t=null;for(let e of o){let n=e.getChildren().filter(i=>D(i)),r=0;for(let i of n)if(r+=i.getColSpan()||1,i.getRowSpan()>1)throw Error("Cannot copy rows with merged cells");if(t===null)t=r;else if(t!==r)throw Error("Cannot copy rows with inconsistent sizes")}}function ip(o,t){let e=new Bt(t).columnCount;for(let n of o){let r=n.getChildren().filter(s=>D(s)),i=0;for(let s of r)i+=s.getColSpan()||1;if(i>e)throw Error("Cannot paste rows that are wider than target table");for(;i{let n=new ti;return n.set(...e),n});Ms.splice(0,Ms.length,...t)}function od(){return Ms.length===0}function up(o){if(W(o)){let i=o.getShape();return{from:i.fromX,to:i.toX}}let t=Z(o,D),e=Ct(o);if(!D(t)||!e)return null;let r=new Bt(e).getRangeForCell(t);return r?{from:r.fromX,to:r.toX}:null}function fp(o,t){let e=new Bt(t),n=[];for(let r=o.from;r<=o.to;r++){let i=e.getCellsInColumn(r);n.push(i)}return n}function mp(o){let t=null;for(let e of o){let n=0;for(let r of e)if(n+=r.getRowSpan()||1,r.getColSpan()>1)throw Error("Cannot copy columns with merged cells");if(t===null)t=n;else if(t!==n)throw Error("Cannot copy columns with inconsistent sizes")}}function pp(){let o=C(),t=up(o),e=Ct(o);if(!t||!e)return;let n=e.getColWidths(),r=fp(t,e);mp(r),cp(r);for(let s of r)for(let l of s)l.remove();let i=[...n].splice(t.from,t.to-t.from+1);e.setColWidths(i)}function gp(){let o=C(),t=up(o),e=Ct(o);if(!t||!e)return;let n=fp(t,e);mp(n),cp(n)}function PE(o,t){let e=new Bt(t).rowCount;for(let n of o){let r=0;for(let i of n)r+=i.getRowSpan()||1;if(r>e)throw Error("Cannot paste columns that are taller than target table");for(;rf.get(o));t||s.reverse(),PE(s,n);let l=new Bt(n),a=l.getRangeForCell(i);if(!a)return;let d=t?a.fromX:a.toX,u=n.getColWidths();for(let f=0;fm);u.splice(t?d:d+1,0,...c)}function Np(o){hp(o,!0)}function xp(o){hp(o,!1)}var Ne=()=>!1,_e=o=>!de(o,D),Ep={label:"Table",icon:ja},nd={label:"Table properties",icon:ja,action(o){o.editor.getEditorState().read(()=>{let t=Ct(C());K(t)&&ep(t,o)})},isActive:Ne,isDisabled:_e},Tp={label:"Clear table formatting",format:"long",action(o){o.editor.update(()=>{let t=Z(C(),D);if(!D(t))return;let e=Ot(t,K);K(e)&&Kf(e)})},isActive:Ne,isDisabled:_e},Cp={label:"Resize to contents",format:"long",action(o){o.editor.update(()=>{let t=Z(C(),D);if(!D(t))return;let e=Ot(t,K);K(e)&&Hf(e)})},isActive:Ne,isDisabled:_e},rd={label:"Delete table",icon:Ls,action(o){o.editor.update(()=>{let t=Z(C(),K);t&&t.remove()})},isActive(){return!1}},bp={...rd,format:"long",isDisabled(o){return!de(o,K)}},id={label:"Insert row before",icon:Ym,action(o){o.editor.update(()=>{Yi(!1)})},isActive:Ne,isDisabled:_e},sd={label:"Insert row after",icon:Zm,action(o){o.editor.update(()=>{Yi(!0)})},isActive:Ne,isDisabled:_e},ld={label:"Delete row",icon:zm,action(o){o.editor.update(()=>{ha()})},isActive:Ne,isDisabled:_e},_p={label:"Row properties",format:"long",action(o){o.editor.getEditorState().read(()=>{let t=io(C());te(t[0])&&Jm(t[0],o)})},isActive:Ne,isDisabled:_e},yp={label:"Cut row",format:"long",action(o){o.editor.update(()=>{try{sp()}catch(t){o.error(t)}})},isActive:Ne,isDisabled:_e},Sp={label:"Copy row",format:"long",action(o){o.editor.getEditorState().read(()=>{try{lp()}catch(t){o.error(t)}})},isActive:Ne,isDisabled:_e},Lp={label:"Paste row before",format:"long",action(o){o.editor.update(()=>{try{ap(o.editor)}catch(t){o.error(t)}})},isActive:Ne,isDisabled:o=>_e(o)||td()},Mp={label:"Paste row after",format:"long",action(o){o.editor.update(()=>{try{dp(o.editor)}catch(t){o.error(t)}})},isActive:Ne,isDisabled:o=>_e(o)||td()},wp={label:"Cut column",format:"long",action(o){o.editor.update(()=>{try{pp()}catch(t){o.error(t)}})},isActive:Ne,isDisabled:_e},vp={label:"Copy column",format:"long",action(o){o.editor.getEditorState().read(()=>{try{gp()}catch(t){o.error(t)}})},isActive:Ne,isDisabled:_e},Dp={label:"Paste column before",format:"long",action(o){o.editor.update(()=>{try{Np(o.editor)}catch(t){o.error(t)}})},isActive:Ne,isDisabled:o=>_e(o)||od()},Op={label:"Paste column after",format:"long",action(o){o.editor.update(()=>{try{xp(o.editor)}catch(t){o.error(t)}})},isActive:Ne,isDisabled:o=>_e(o)||od()},ad={label:"Insert column before",icon:qm,action(o){o.editor.update(()=>{Zi(!1)})},isActive(){return!1}},dd={label:"Insert column after",icon:Wm,action(o){o.editor.update(()=>{Zi(!0)})},isActive(){return!1}},cd={label:"Delete column",icon:Um,action(o){o.editor.update(()=>{Na()})},isActive(){return!1}},Ap={label:"Cell properties",format:"long",action(o){o.editor.getEditorState().read(()=>{let t=Z(C(),D);D(t)&&jm(t,o)})},isActive:Ne,isDisabled:_e},Rp={label:"Merge cells",format:"long",action(o){o.editor.update(()=>{let t=C();W(t)&&Ff(t)})},isActive:Ne,isDisabled(o){return!W(o)}},kp={label:"Split cell",format:"long",action(o){o.editor.update(()=>{Ea()})},isActive:Ne,isDisabled(o){let t=Z(o,D);return t?!(t.getRowSpan()>1||t.getColSpan()>1):!0}};var Ip='';var $p='';var Pp='';var Bp='';var Fp='';var Hp={label:"Undo",icon:Ip,action(o){o.editor.dispatchCommand(co,void 0),o.manager.triggerFutureStateRefresh()},isActive(o){return!1},setup(o,t){t.toggleDisabled(!0),o.editor.registerCommand(go,e=>(t.toggleDisabled(!e),!1),Ve)}},Kp={label:"Redo",icon:$p,action(o){o.editor.dispatchCommand(uo,void 0),o.manager.triggerFutureStateRefresh()},isActive(o){return!1},setup(o,t){t.toggleDisabled(!0),o.editor.registerCommand(po,e=>(t.toggleDisabled(!e),!1),Ve)}},Up={label:"Source code",icon:Pp,async action(o){let t=o.manager.createModal("source"),e=await cs(o.editor);t.show({source:e})},isActive(){return!1}},zp={label:"Fullscreen",icon:Bp,async action(o,t){let e=o.containerDOM.classList.contains("fullscreen");o.containerDOM.classList.toggle("fullscreen",!e),o.containerDOM.closest("body").classList.toggle("editor-is-fullscreen",!e),t.setActiveState(!e)},isActive(o,t){return t.containerDOM.classList.contains("fullscreen")}},Wp={label:"About the editor",icon:Fp,async action(o,t){o.manager.createModal("about").show({})},isActive(o,t){return!1}};function ws(o,t){return{label:t,action(e){e.editor.update(()=>{Fn(n=>ia(n,o),()=>Wn(o))})},isActive(e){return de(e,n=>ia(n,o))}}}var qp=ws("info","Info"),Yp=ws("danger","Danger"),Zp=ws("warning","Warning"),Vp=ws("success","Success"),zE=(o,t)=>Qn(o)&&o.getTag()===t;function vs(o,t){return{label:t,action(e){gs(e.editor,o)},isActive(e){return de(e,n=>zE(n,o))}}}var Xp=vs("h2","Large Header"),jp=vs("h3","Medium Header"),Gp=vs("h4","Small Header"),Jp=vs("h5","Tiny Header"),Qp={label:"Blockquote",action(o){Vr(o.editor)},isActive(o){return de(o,ns)}},eg={label:"Paragraph",action(o){Zr(o.editor)},isActive(o){return de(o,Ze)}};var tg='';var og='';var ng='';var rg=` `;var ig='';var sg='';var lg='';var ag='';var dg='';var cg='';function mn(o,t,e){return{label:o,icon:e,action(n){n.editor.dispatchCommand(xe,t)},isActive(n){return Su(n,t)}}}var ud=mn("Bold","bold",tg),fd=mn("Italic","italic",og),ug=mn("Underline","underline",ng),fg={label:"Text color",icon:rg},mg={label:"Highlight color",icon:ig};function pg(o,t,e){o.editor.update(()=>{let n=C();n&&Pl(n,{[t]:e||null})})}var gg=(o,t)=>pg(t,"color",o),hg=(o,t)=>pg(t,"background-color",o),Ng=mn("Strikethrough","strikethrough",sg),xg=mn("Superscript","superscript",lg),Eg=mn("Subscript","subscript",ag),Tg=mn("Inline code","code",dg),Cg={label:"Clear formatting",icon:cg,action(o){o.editor.update(()=>{let t=C();for(let e of t?.getNodes()||[])L(e)&&(e.setFormat(0),e.setStyle(""))})},isActive(){return!1}};var bg='';var _g='';var yg='';var Sg='';var Lg='';var Mg='';function Ds(o,t){let e=ae(o.editor),n=e?.getNodes()||[];if(n.length===1&&T(n[0])&&n[0].isInline()&&Rr(n[0])){n[0].setAlignment(t),rt(n[0]),o.manager.triggerFutureStateRefresh();return}let i=At(e).filter(a=>Rr(a)),l=i.every(a=>a.getAlignment()===t)?"":t;for(let a of i)a.setAlignment(l);o.manager.triggerFutureStateRefresh()}function wg(o,t){let e=ae(o.editor),n=At(e);for(let r of n)r.setDirection(t);o.manager.triggerFutureStateRefresh()}var vg={label:"Align left",icon:bg,action(o){o.editor.update(()=>Ds(o,"left"))},isActive(o){return kr(o,"left")}},Dg={label:"Align center",icon:_g,action(o){o.editor.update(()=>Ds(o,"center"))},isActive(o){return kr(o,"center")}},Og={label:"Align right",icon:yg,action(o){o.editor.update(()=>Ds(o,"right"))},isActive(o){return kr(o,"right")}},Ag={label:"Justify",icon:Sg,action(o){o.editor.update(()=>Ds(o,"justify"))},isActive(o){return kr(o,"justify")}},Rg={label:"Left to right",icon:Lg,action(o){o.editor.update(()=>wg(o,"ltr"))},isActive(o){return Ul(o,"ltr")}},kg={label:"Right to left",icon:Mg,action(o){o.editor.update(()=>wg(o,"rtl"))},isActive(o){return Ul(o,"rtl")}};var Ig='';var $g='';var Pg='';var Bg='';var Fg='';function md(o,t,e){return{label:o,icon:e,action(n){Xr(n.editor,t)},isActive(n){return de(n,r=>z(r)&&r.getListType()===t)}}}var pd=md("Bullet list","bullet",Ig),gd=md("Numbered list","number",$g),Hg=md("Task list","check",Pg),Kg={label:"Increase indent",icon:Bg,action(o){o.editor.update(()=>{Jr(o.editor,40)})},isActive(){return!1}},Ug={label:"Decrease indent",icon:Fg,action(o){o.editor.update(()=>{Jr(o.editor,-40)})},isActive(){return!1}};var zg='';var Wg='';var qg='';var Yg='';var Zg='';var Vg='';var Xg='';var jg='';var Gg=` `;var Jg='';var Qg='';var Os={label:"Insert/edit link",icon:zg,action(o){o.editor.getEditorState().read(()=>{let t=Z(C(),$t);Es(t,o)})},isActive(o){return de(o,$t)}},eh={label:"Remove link",icon:Wg,action(o){o.editor.update(()=>{let t=ae(o.editor),e=Z(t,$t);if(e){let n=e.getChildren().reverse();for(let r of n)e.insertAfter(r);e.remove(),n[n.length-1].selectStart(),o.manager.triggerFutureStateRefresh()}})},isActive(o){return!1}},hd={label:"Insert/Edit Image",icon:qg,action(o){o.editor.getEditorState().read(()=>{let t=ae(o.editor),e=Z(t,je);if(e){gm(e,o);return}ps(n=>{o.editor.update(()=>{let r=im(n);Me([r]),r.select()})})})},isActive(o){return de(o,je)}},th={label:"Insert horizontal line",icon:Yg,action(o){o.editor.update(()=>{Vo(va(),!1)})},isActive(o){return de(o,zf)}},Nd={label:"Insert code block",icon:Zg,action(o){jr(o.editor)},isActive(o){return de(o,es)}},oh=Object.assign({},Nd,{label:"Edit code block",icon:Vg}),nh={label:"Insert/edit drawing",icon:Xg,action(o){o.editor.getEditorState().read(()=>{let t=ae(o.editor),e=Z(t,lo);e===null?o.editor.update(()=>{let n=Xn();Vo(n,!0),Qr(o,n),n.selectStart()}):Qr(o,e)})},isActive(o){return de(o,lo)}},rh={label:"Drawing manager",action(o){Om(o)},isActive(){return!1}},xd={label:"Insert/edit media",icon:Qg,action(o){o.editor.getEditorState().read(()=>{let t=C(),e=Z(t,_t);xm(e,o)})},isActive(o){return de(o,_t)}},ih={label:"Insert collapsible block",icon:jg,action(o){o.editor.update(()=>{let t=C(),e=sa(),r=(t?.getNodes()||[]).map(s=>s.getTopLevelElement()).filter(s=>s!==null),i=[...new Set(r)];i.length>0?i[0].insertAfter(e):H().append(e);for(let s of i)e.append(s)})},isActive(o){return de(o,$e)}},sh={label:"Edit label",icon:Jg,action(o){o.editor.getEditorState().read(()=>{let t=Z(C(),$e);$e(t)&&Tm(t,o)})},isActive(o){return!1}},lh={label:"Toggle open/closed",icon:Gg,action(o){o.editor.update(()=>{let t=Z(C(),$e);$e(t)&&(t.setOpen(!t.getOpen()),o.manager.triggerLayoutUpdate())})},isActive(o){return!1}},ah={label:"Unwrap",icon:Ls,action(o){o.editor.update(()=>{let t=Z(C(),$e);if($e(t)){let e=t.getChildren();for(let n of e)t.insertBefore(n);t.remove(),o.manager.triggerLayoutUpdate()}})},isActive(o){return!1}};var dh=` `;var As=class extends oe{constructor(e,n){super([e]);p(this,"button");p(this,"dropdownButton");this.button=e,this.dropdownButton=new Te({button:{label:"Menu",icon:dh},showOnHover:!1,direction:"vertical",showAside:!1},n),this.addChildren(this.dropdownButton)}buildDOM(){return y("div",{class:"editor-button-with-menu-container"},[this.button.getDOMElement(),this.dropdownButton.getDOMElement()])}};var pn=class extends ve{buildDOM(){return y("div",{class:"editor-separator"})}};function ch(o){let t=o.manager.getDefaultDirection()==="rtl";return new Yr("editor-toolbar-main",[new dt(2,[new w(Hp),new w(Kp)]),new _s([new Ge(y("h2"),Xp),new Ge(y("h3"),jp),new Ge(y("h4"),Gp),new Ge(y("h5"),Jp),new Ge(y("blockquote"),Qp),new Ge(y("p"),eg),new Te({button:{label:"Callouts",format:"long"},showOnHover:!0,direction:"vertical"},[new Ge(y("p",{class:"callout info"}),qp),new Ge(y("p",{class:"callout success"}),Vp),new Ge(y("p",{class:"callout warning"}),Zp),new Ge(y("p",{class:"callout danger"}),Yp)])]),new dt(6,[new w(ud),new w(fd),new w(ug),new Te({button:new ei(fg,"color")},[new un(gg)]),new Te({button:new ei(mg,"background-color")},[new un(hg)]),new w(Ng),new w(xg),new w(Eg),new w(Tg),new w(Cg)]),new dt(6,[new w(vg),new w(Dg),new w(Og),new w(Ag),t?new w(Rg):null,t?new w(kg):null].filter(e=>e!==null)),new dt(3,[new w(pd),new w(gd),new w(Hg),new w(Ug),new w(Kg)]),new dt(4,[new w(Os),new Te({button:Ep,direction:"vertical",showAside:!1},[new Te({button:{label:"Insert",format:"long"},showOnHover:!0,showAside:!0},[new Ss]),new pn,new Te({button:{label:"Cell",format:"long"},direction:"vertical",showOnHover:!0},[new w(Ap),new w(Rp),new w(kp)]),new Te({button:{label:"Row",format:"long"},direction:"vertical",showOnHover:!0},[new w({...id,format:"long"}),new w({...sd,format:"long"}),new w({...ld,format:"long"}),new w(_p),new pn,new w(yp),new w(Sp),new w(Lp),new w(Mp)]),new Te({button:{label:"Column",format:"long"},direction:"vertical",showOnHover:!0},[new w({...ad,format:"long"}),new w({...dd,format:"long"}),new w({...cd,format:"long"}),new pn,new w(wp),new w(vp),new w(Dp),new w(Op)]),new pn,new w({...nd,format:"long"}),new w(Tp),new w(Cp),new w(bp)]),new w(hd),new w(th),new w(Nd),new As(new w(nh),[new w(rh)]),new w(xd),new w(ih)]),new dt(3,[new w(Up),new w(Wp),new w(zp)])])}function uh(o){return new Yr("editor-toolbar-main",[new w(ud),new w(fd),new w(Os),new w(pd),new w(gd)])}var Rs={image:{selector:"img:not([drawio-diagram] img)",content:()=>[new w(hd)]},media:{selector:".editor-media-wrap",content:()=>[new w(xd)]},link:{selector:"a",content(){return[new w(Os),new w(eh)]},displayTargetLocator(o){return o.querySelector("img")||o}},code:{selector:".editor-code-block-wrap",content:()=>[new w(oh)]},table:{selector:"td,th",content(){return[new dt(2,[new w(nd),new w(rd)]),new dt(3,[new w(id),new w(sd),new w(ld)]),new dt(3,[new w(ad),new w(dd),new w(cd)])]},displayTargetLocator(o){return o.closest("table")}},details:{selector:"details",content(){return[new w(sh),new w(lh),new w(ah)]}}};var ks=class extends ve{constructor(e){super();p(this,"url","");this.url=e}buildDOM(){let e=y("div",{class:"editor-external-content"});return window.$http.get(this.url).then(n=>{typeof n.data=="string"&&(e.innerHTML=n.data)}),e}};var fh={submitText:"Save",async action(o,t){return cn(t.editor,o.get("source")?.toString()||""),!0},fields:[{label:"Source",name:"source",type:"textarea"}]},mh={submitText:"Close",async action(){return!0},fields:[{build(){return new ks("/help/wysiwyg")}}]};var Is={link:{title:"Insert/Edit Link",form:Nm},image:{title:"Insert/Edit Image",form:hm},media:{title:"Insert/Edit Media",form:Em},source:{title:"Source code",form:fh},cell_properties:{title:"Cell Properties",form:Gm},row_properties:{title:"Row Properties",form:Qm},table_properties:{title:"Table Properties",form:tp},details:{title:"Edit collapsible block",form:Cm},about:{title:"About the WYSIWYG Editor",form:mh}};var nr=class{constructor(t){p(this,"node",null);p(this,"context");p(this,"onDestroyCallbacks",[]);this.context=t}getNode(){if(!this.node)throw new Error("Attempted to get use node without it being set");return this.node}setNode(t){this.node=t}onDestroy(t){this.onDestroyCallbacks.push(t)}teardown(){for(let t of this.onDestroyCallbacks)t()}};var $s=class extends nr{constructor(){super(...arguments);p(this,"completedSetup",!1);p(this,"latestCode","");p(this,"latestLanguage","");p(this,"editor",null)}setup(e,n){let r=this.getNode(),i=n.querySelector("pre");if(!i)return;i&&(i.hidden=!0),this.latestCode=r.__code,this.latestLanguage=r.__language;let l=this.latestCode.split(` `).length*19.2+18+24;n.style.height=`${l}px`;let a=Date.now();n.addEventListener("click",m=>{requestAnimationFrame(()=>{e.editor.update(()=>{rt(this.getNode())})})}),n.addEventListener("dblclick",m=>{e.editor.getEditorState().read(()=>{qr(e.editor,this.getNode())})});let d=m=>{n.classList.toggle("selected",ki(m,r))};e.manager.onSelectionChange(d),this.onDestroy(()=>{e.manager.offSelectionChange(d)});let u=m=>{this.editor=m.wysiwygView(n,document,this.latestCode,this.latestLanguage),setTimeout(()=>{n.style.height=""},12)};window.importVersioned("code").then(m=>{let c=Date.now()-a<20?20:0;setTimeout(()=>u(m),c)}),this.completedSetup=!0}update(){let e=this.getNode(),n=e.getCode(),r=e.getLanguage();this.latestCode===n&&this.latestLanguage===r||(this.latestLanguage=r,this.latestCode=n,this.editor&&(this.editor.setContent(n),this.editor.setMode(r,n)))}render(e,n){this.completedSetup?this.update():this.setup(e,n)}};var Ps=class extends nr{constructor(){super(...arguments);p(this,"completedSetup",!1)}setup(e,n){let r=this.getNode();n.classList.add("editor-diagram"),e.editor.registerCommand(Ht,s=>n.contains(s.target)?(e.editor.update(()=>{rt(this.getNode())}),!0):!1,Kn),n.addEventListener("dblclick",s=>{e.editor.getEditorState().read(()=>{Qr(e,this.getNode())})});let i=s=>{n.classList.toggle("selected",ki(s,r))};e.manager.onSelectionChange(i),this.onDestroy(()=>{e.manager.offSelectionChange(i)}),this.completedSetup=!0}update(){}render(e,n){this.completedSetup?this.update():this.setup(e,n)}};function _T(o){return F(o)||je(o)||_t(o)||lo(o)||K(o)}function yT(o,t){let e=H().getLastChild();if(!e||!_T(e))return!1;let n=o.editor.getElementByKey(e.getKey());if(!n)return!1;let r=n.getBoundingClientRect();return t.clientY>r.bottom?(o.editor.update(()=>{let s=I();H().append(s),s.select()}),!0):!1}function ph(o){let t=o.editor.registerCommand(Ht,e=>(yT(o,e),!1),Ve);return()=>{t()}}var gh={text:{bold:"editor-theme-bold",code:"editor-theme-code",italic:"editor-theme-italic",strikethrough:"editor-theme-strikethrough",subscript:"editor-theme-subscript",superscript:"editor-theme-superscript",underline:"editor-theme-underline",underlineStrikethrough:"editor-theme-underline-strikethrough"}};function cF(o,t,e={}){let n=Bi({namespace:"BookStackPageEditor",nodes:Xf(),onError:console.error,theme:gh}),r=Aa(o,n,{...e,editorClass:"page-content"});n.setRootElement(r.editorDOM),Dt(na(n),ea(n,ta(),300),$a(r),Im(r),ph(r),nm(n,r.scrollDOM),um(n),cm(n,r.editorDOM),dm(r),Sm(r),Xa(n)),r.manager.setToolbar(ch(r));for(let s of Object.keys(Rs))r.manager.registerContextToolbar(s,Rs[s]);for(let s of Object.keys(Is))r.manager.registerModal(s,Is[s]);r.manager.registerDecoratorType("code",$s),r.manager.registerDecoratorType("diagram",Ps),rm(n),cn(n,t);let i=document.getElementById("lexical-debug");return i&&(i.hidden=!0,n.registerUpdateListener(({dirtyElements:s,dirtyLeaves:l,editorState:a,prevEditorState:d})=>{i.textContent=JSON.stringify(a.toJSON(),null,2)})),window.debugEditorState=()=>n.getEditorState().toJSON(),Gf(r),new Bs(r)}function uF(o,t,e={}){let n=Bi({namespace:"BookStackBasicEditor",nodes:jf(),onError:console.error,theme:gh}),r=Aa(o,n,e);n.setRootElement(r.editorDOM);let i=Dt(na(n),ea(n,ta(),300),$a(r),Xa(n));return r.manager.setToolbar(uh(r)),r.manager.registerContextToolbar("link",Rs.link),r.manager.registerModal("link",Is.link),r.manager.onTeardown(i),cn(n,t),new Bs(r)}var Bs=class{constructor(t){p(this,"context");p(this,"onChangeListeners",[]);p(this,"editorListenerTeardown",null);this.context=t}async getContentAsHtml(){return await cs(this.context.editor)}onChange(t){this.onChangeListeners.push(t),this.startListeningToChanges()}focus(){us(this.context.editor)}remove(){this.context.manager.teardown(),this.context.containerDOM.remove(),this.editorListenerTeardown&&this.editorListenerTeardown()}startListeningToChanges(){this.editorListenerTeardown||(this.editorListenerTeardown=this.context.editor.registerUpdateListener(()=>{for(let t of this.onChangeListeners)t()}))}};export{Bs as SimpleWysiwygEditorInterface,uF as createBasicEditorInstance,cF as createPageEditorInstance}; //# sourceMappingURL=wysiwyg.js.map