`?n.push(ut()):s===" "?n.push(St()):n.push(Y(s))}this.insertNodes(n)}insertText(e){let t=this.anchor,n=this.focus,r=this.format,i=this.style,s=t,l=n;!this.isCollapsed()&&n.isBefore(t)&&(s=n,l=t),s.type==="element"&&nN(s,l,r,i);let a=s.offset,c=l.offset,m=this.getNodes(),f=m.length,d=m[0];b(d)||x(!1,"insertText: first node is not a text node");let p=d.getTextContent().length,g=d.getParentOrThrow(),h=f-1,_=m[h];if(f===1&&l.type==="element"&&(c=p,l.set(s.key,c,"text")),this.isCollapsed()&&a===p&&(d.isSegmented()||d.isToken()||!d.canInsertTextAfter()||!g.canInsertTextAfter()&&d.getNextSibling()===null)){let N=d.getNextSibling();if((!b(N)||!N.canInsertTextBefore()||ze(N))&&(N=Y(),N.setFormat(r),N.setStyle(i),g.canInsertTextAfter()?d.insertAfter(N):g.insertAfter(N)),N.select(0,0),d=N,e!==""){this.insertText(e);return}}else if(this.isCollapsed()&&a===0&&(d.isSegmented()||d.isToken()||!d.canInsertTextBefore()||!g.canInsertTextBefore()&&d.getPreviousSibling()===null)){let N=d.getPreviousSibling();if((!b(N)||ze(N))&&(N=Y(),N.setFormat(r),g.canInsertTextBefore()?d.insertBefore(N):g.insertBefore(N)),N.select(),d=N,e!==""){this.insertText(e);return}}else if(d.isSegmented()&&a!==p){let N=Y(d.getTextContent());N.setFormat(r),d.replace(N),d=N}else if(!this.isCollapsed()&&e!==""){let N=_.getParent();if(!g.canInsertTextBefore()||!g.canInsertTextAfter()||E(N)&&(!N.canInsertTextBefore()||!N.canInsertTextAfter())){this.insertText(""),Bd(this.anchor,this.focus,null),this.insertText(e);return}}if(f===1){if(d.isToken()){let S=Y(e);S.select(),d.replace(S);return}let N=d.getFormat(),L=d.getStyle();if(a===c&&(N!==r||L!==i))if(d.getTextContent()==="")d.setFormat(r),d.setStyle(i);else{let S=Y(e);if(S.setFormat(r),S.setStyle(i),S.select(),a===0)d.insertBefore(S,!1);else{let[A]=d.splitText(a);A.insertAfter(S,!1)}S.isComposing()&&this.anchor.type==="text"&&(this.anchor.offset-=e.length);return}else if(Cl(d)){let S=Y(e);S.setFormat(r),S.setStyle(i),S.select(),d.replace(S);return}let M=c-a;d=d.spliceText(a,M,e,!0),d.getTextContent()===""?d.remove():this.anchor.type==="text"&&(d.isComposing()?this.anchor.offset-=e.length:(this.format=N,this.style=L))}else{let N=new Set([...d.getParentKeys(),..._.getParentKeys()]),L=E(d)?d:d.getParentOrThrow(),M=E(_)?_:_.getParentOrThrow(),S=_;if(!L.is(M)&&M.isInline())do S=M,M=M.getParentOrThrow();while(M.isInline());if(l.type==="text"&&(c!==0||_.getTextContent()==="")||l.type==="element"&&_.getIndexWithinParent()<c)if(b(_)&&!_.isToken()&&c!==_.getTextContentSize()){if(_.isSegmented()){let k=Y(_.getTextContent());_.replace(k),_=k}!te(l.getNode())&&l.type==="text"&&(_=_.spliceText(0,c,"")),N.add(_.__key)}else{let k=_.getParentOrThrow();!k.canBeEmpty()&&k.getChildrenSize()===1?k.remove():_.remove()}else N.add(_.__key);let A=M.getChildren(),O=new Set(m),R=L.is(M),P=L.isInline()&&d.getNextSibling()===null?L:d;for(let k=A.length-1;k>=0;k--){let W=A[k];if(W.is(d)||E(W)&&W.isParentOf(d))break;W.isAttached()&&(!O.has(W)||W.is(S)?R||P.insertAfter(W,!1):W.remove())}if(!R){let k=M,W=null;for(;k!==null;){let ie=k.getChildren(),rn=ie.length;(rn===0||ie[rn-1].is(W))&&(N.delete(k.__key),W=k),k=k.getParent()}}if(!d.isToken())d=d.spliceText(a,p-a,e,!0),d.getTextContent()===""?d.remove():d.isComposing()&&this.anchor.type==="text"&&(this.anchor.offset-=e.length);else if(a===p)d.select();else{let k=Y(e);k.select(),d.replace(k)}for(let k=1;k<f;k++){let W=m[k],ie=W.__key;N.has(ie)||W.remove()}}}removeText(){this.insertText("")}formatText(e){if(this.isCollapsed()){this.toggleFormat(e),se(null);return}let t=this.getNodes(),n=[];for(let N of t)b(N)&&n.push(N);let r=n.length;if(r===0){this.toggleFormat(e),se(null);return}let i=this.anchor,s=this.focus,l=this.isBackward(),a=l?s:i,c=l?i:s,m=0,f=n[0],d=a.type==="element"?0:a.offset;if(a.type==="text"&&d===f.getTextContentSize()&&(m=1,f=n[1],d=0),f==null)return;let u=f.getFormatFlags(e,null),p=r-1,g=n[p],h=c.type==="text"?c.offset:g.getTextContentSize();if(f.is(g)){if(d===h)return;if(ze(f)||d===0&&h===f.getTextContentSize())f.setFormat(u);else{let N=f.splitText(d,h),L=d===0?N[0]:N[1];L.setFormat(u),a
`||c===`\r
`?a.insertParagraph():c===" "?a.insertNodes([St()]):a.insertText(c)}}}else e.insertRawText(i)}function Fl(o,e,t){o.dispatchCommand(jn,{nodes:e,selection:t})||t.insertNodes(e)}function BN(o){let e=o.exportJSON(),t=o.constructor;if(e.type!==t.getType()&&x(!1,"LexicalNode: Node %s does not implement .exportJSON().",t.name),E(o)){let n=e.children;Array.isArray(n)||x(!1,"LexicalNode: Node %s is an element but .exportJSON() does not have a children array.",t.name)}return e}function bu(o,e,t,n=[]){let r=e!==null?t.isSelected(e):!0,i=E(t)&&t.excludeFromCopy("html"),s=t;if(e!==null){let c=Yt(t);c=b(c)&&e!==null?vr(e,c):c,s=c}let l=E(s)?s.getChildren():[],a=BN(s);if(b(s)){let c=s.__text;c.length>0?a.text=c:r=!1}for(let c=0;c<l.length;c++){let m=l[c],f=bu(o,e,m,a.children);!r&&E(t)&&f&&t.extractWithChild(m,e,"clone")&&(r=!0)}if(r&&!i)n.push(a);else if(Array.isArray(a.children))for(let c=0;c<a.children.length;c++){let m=a.children[c];n.push(m)}return r}function Su(o,e){let t=[],r=F().getChildren();for(let i=0;i<r.length;i++){let s=r[i];bu(o,e,s,t)}return{namespace:o._config.namespace,nodes:t}}function Lu(o){let e=[];for(let t=0;t<o.length;t++){let n=o[t],r=vl(n);b(r)&&kl(r),e.push(r)}return e}var FN=50,On=null;async function An(o,e,t){if(On!==null)return!1;if(e!==null)return new Promise((a,c)=>{o.update(()=>{a(Tu(o,e,t))})});let n=o.getRootElement(),r=o._window==null?window.document:o._window.document,i=_u(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,c)=>{let m=o.registerCommand(io,f=>(mt(f,ClipboardEvent)&&(m(),On!==null&&(window.clearTimeout(On),On=null),a(Tu(o,f,t))),!0),Re);On=window.setTimeout(()=>{m(),On=null,a(!1)},FN),r.execCommand("copy"),s.remove()})}function Tu(o,e,t){if(t===void 0){let r=_u(o._window);if(!r)return!1;let i=r.anchorNode,s=r.focusNode;if(i!==null&&s!==null&&!zt(o,i,s))return!1;let l=T();if(l===null)return!1;t=Ri(l)}e.preventDefault();let n=e.clipboardData;return n===null?!1:(Mu(n,t),!0)}var HN=[["text/html",Cu],["application/x-lexical-editor",yu]];function Ri(o=T()){let e={"text/plain":o?o.getTextContent():""};if(o){let t=tl();for(let[n,r]of HN){let i=r(t,o);i!==null&&(e[n]=i)}}return e}function Mu(o,e){for(let t in e){let n=e[t];n!==void 0&&o.setData(t,n)}}function ki(o,e){if(typeof document.caretRangeFromPoint<"u"){let t=document.caretRangeFromPoint(o,e);return t===null?null:{node:t.startContainer,offset:t.startOffset}}else if(document.caretPositionFromPoint!=="undefined"){let t=document.caretPositionFromPoint(o,e);return t===null?null:{node:t.offsetNode,offset:t.offset}}else return null}var vu=I("DRAG_DROP_PASTE_FILE");function KN(o,e){o.preventDefault(),e.update(()=>{let t=T(),n=mt(o,InputEvent)||mt(o,KeyboardEvent)?null:o.clipboardData;n!=null&&t!==null&&Ai(n,t,e)},{tag:"paste"})}async function UN(o,e){await An(e,mt(o,ClipboardEvent)?o:null),e.update(()=>{let t=T();C(t)?t.removeText():Ee(t)&&t.getNodes().forEach(n=>n.remove())})}function Ii(o){let e=null;if(mt(o,DragEvent)?e=o.dataTransfer:mt(o,ClipboardEvent)&&(e=o.clipboardData),e===null)return[!1,[],!1];let t=e.types,n=t.includes("Files"),r=t.includes("text/html")||t.includes("text/plain");return[n,Array.from(e.files),r]}function $i(o){let e=ee(o);return B(e)}function zN(o){let e=o.focus;return e.key==="root"&&e.offset===F().getChildrenSize()}function wu(o){return Xt(o.registerCommand(Jn,t=>{let n=T();return Ee(n)?(n.clear(),!0):!1},0),o.registerCommand(Ze,t=>{let n=T();return C(n)?(n.deleteCharacter(t),!0):!1},Z),o.registerCommand(Tt,t=>{let n=T();return C(n)?(n.deleteWord(t),!0):!1},Z),o.registerCommand(it,t=>{let n=T();return C(n)?(n.deleteLine(t),!0):!1},Z),o.registerCommand(rt,t=>{let n=T();if(typeof t=="string")n!==null&&n.insertText(t);else{if(n===null)return!1;let r=t.dataTransfer;if(r!=null)Ai(r,n,o);else if(C(n)){let i=t.data;return i&&n.insertText(i),!0}}return!0},Z),o.registerCommand(ln,()=>{let t=T();return C(t)?(t.re
`?null:(b(d)&&(a&&d.toggleFormat("bold"),c&&d.toggleFormat("strikethrough"),m&&d.toggleFormat("italic"),f&&d.toggleFormat("underline")),p.append(d),p)}return d},node:i}}function Pe(o=re.NO_STATUS,e=1,t){return oe(new jt(o,e,t))}function w(o){return o instanceof jt}var JN=I("INSERT_TABLE_COMMAND");var Jt=class o extends J{constructor(t){super(t);this.__styles=new Map}static getType(){return"tablerow"}static clone(t){let n=new o(t.__key);return n.__styles=new Map(t.__styles),n}static importDOM(){return{tr:t=>({conversion:QN,priority:0})}}static importJSON(t){let n=Vo();return n.setStyles(new Map(Object.entries(t.styles))),n}exportJSON(){return{...super.exportJSON(),type:"tablerow",version:1,styles:Object.fromEntries(this.__styles),height:this.__height||0}}createDOM(t){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 Te(n,t.theme.tableRow),n}isShadowRoot(){return!0}getStyles(){let t=this.getLatest();return new Map(t.__styles)}setStyles(t){let n=this.getWritable();n.__styles=new Map(t)}setHeight(t){let n=this.getWritable();return n.__height=t,this.__height}getHeight(){return this.getLatest().__height}updateDOM(t){return t.__height!==this.__height||t.__styles!==this.__styles}canBeEmpty(){return!1}canIndent(){return!1}};function QN(o){let e=Vo(),n=zo(o.style.height);return e.setHeight(n),o instanceof HTMLElement&&e.setStyles(Mn(o)),{node:e}}function Vo(){return oe(new Jt)}function Q(o){return o instanceof Jt}function Jl(o,e,t=!0){let n=Rr();for(let r=0;r<o;r++){let i=Vo();for(let s=0;s<e;s++){let l=re.NO_STATUS;typeof t=="object"?(r===0&&t.rows&&(l|=re.ROW),s===0&&t.columns&&(l|=re.COLUMN)):t&&(r===0&&(l|=re.ROW),s===0&&(l|=re.COLUMN));let a=Pe(l),c=$();c.append(Y()),a.append(c),i.append(a)}n.append(i)}return n}var jl=(o,e)=>o===re.BOTH||o===e?e:re.NO_STATUS;function Fi(o=!0){let e=T();x(C(e)||z(e),"Expected a RangeSelection or TableSelection");let t=e.focus.getNode(),[n,,r]=Se(t),[i,s]=ot(r,n,n),l=i[0].length,{startRow:a}=s;if(o){let c=a+n.__rowSpan-1,m=i[c],f=Vo();for(let u=0;u<l;u++){let{cell:p,startRow:g}=m[u];if(g+p.__rowSpan-1<=c){let _=m[u].cell.__headerState,N=jl(_,re.COLUMN);f.append(Pe(N).append($()))}else p.setRowSpan(p.__rowSpan+1)}let d=r.getChildAtIndex(c);x(Q(d),"focusEndRow is not a TableRowNode"),d.insertAfter(f)}else{let c=i[a],m=Vo();for(let d=0;d<l;d++){let{cell:u,startRow:p}=c[d];if(p===a){let h=c[d].cell.__headerState,_=jl(h,re.COLUMN);m.append(Pe(_).append($()))}else u.setRowSpan(u.__rowSpan+1)}let f=r.getChildAtIndex(a);x(Q(f),"focusEndRow is not a TableRowNode"),f.insertBefore(m)}}function Hi(o=!0){let e=T();x(C(e)||z(e),"Expected a RangeSelection or TableSelection");let t=e.anchor.getNode(),n=e.focus.getNode(),[r]=Se(t),[i,,s]=Se(n),[l,a,c]=ot(s,i,r),m=l.length,f=o?Math.max(a.startColumn,c.startColumn):Math.min(a.startColumn,c.startColumn),d=o?f+i.__colSpan-1:f-1,u=s.getFirstChild();x(Q(u),"Expected firstTable child to be a row");let p=null;function g(_=re.NO_STATUS){let N=Pe(_).append($());return p===null&&(p=N),N}let h=u;e:for(let _=0;_<m;_++){if(_!==0){let R=h.getNextSibling();x(Q(R),"Expected row nextSibling to be a row"),h=R}let N=l[_],L=N[d<0?0:d].cell.__headerState,M=jl(L,re.ROW);if(d<0){ta(h,g(M));continue}let{cell:S,startColumn:A,startRow:O}=N[d];if(A+S.__colSpan-1<=d){let R=S,P=O,k=d;for(;P!==_&&R.__rowSpan>1;)if(k-=S.__colSpan,k>=0){let{cell:W,startRow:ie}=N[k];R=W,P=ie}else{h.append(g(M));continue e}R.insertAfter(g(M))}else S.setColSpan(S.__colSpan+1)}p!==null&&Ar(p)}function Ql(){let o=T();x(C(o)||z(o),"Expected a RangeSelection or TableSelection");let e=o.anchor.getNode(),t=o.focus.getNode(),[n,,r]=Se(e),[i]=Se(t),[s,l,a]=ot(r,n,i),{startRow:c}=l,{startRow:m}=a,f=m+i.__rowSpan-1;if(s.length===f-c+1){r.remove();return}let d=s[0].length,u=s[f+1],p=r.getChildAtIndex(f+1);for(let g=f;g>=c;g--){for(let _=d-1;_>=0;_--){let{cell:N,startRow:L,startColumn:M}=s[g][_];if(M===_&&(g===c&&L<c&&N.setRowSpan(N.__rowSpan-(L-c)),L>=c&&L+N.__rowSpan-1>f))if(N.setRowSpan(N.__rowSpan-(f-L+1)),x(p!==
`:" ")}return t}};function z(o){return o instanceof Ui}function zi(){let o=De("root",0,"element"),e=De("root",0,"element");return new Ui("root",o,e)}function ex(o){let e=[],t=[o];for(;t.length>0;){let n=t.pop();x(n!==void 0,"Stack.length > 0; can't be undefined"),E(n)&&t.unshift(...n.getChildren()),n!==o&&e.push(n)}return e}var Ir=class{constructor(e,t){this.isHighlightingCells=!1,this.anchorX=-1,this.anchorY=-1,this.focusX=-1,this.focusY=-1,this.listenersToRemove=new Set,this.tableNodeKey=t,this.editor=e,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(e=>e())}trackTable(){let e=new MutationObserver(t=>{this.editor.update(()=>{let n=!1;for(let i=0;i<t.length;i++){let a=t[i].target.nodeName;if(a==="TABLE"||a==="TBODY"||a==="THEAD"||a==="TR"){n=!0;break}}if(!n)return;let r=this.editor.getElementByKey(this.tableNodeKey);if(!r)throw new Error("Expected to find TableElement in DOM");this.table=Xo(r)})});this.editor.update(()=>{let t=this.editor.getElementByKey(this.tableNodeKey);if(!t)throw new Error("Expected to find TableElement in DOM");this.table=Xo(t),e.observe(t,{attributes:!0,childList:!0,subtree:!0})})}clearHighlight(){let e=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(),e.update(()=>{let t=j(this.tableNodeKey);if(!K(t))throw new Error("Expected TableNode.");let n=e.getElementByKey(this.tableNodeKey);if(!n)throw new Error("Expected to find TableElement in DOM");let r=Xo(n);kr(e,r,null),q(null),e.dispatchCommand(ve,void 0)})}enableHighlightStyle(){let e=this.editor;e.update(()=>{let t=e.getElementByKey(this.tableNodeKey);if(!t)throw new Error("Expected to find TableElement in DOM");vi(t,e._config.theme.tableSelection),t.classList.remove("disable-selection"),this.hasHijackedSelectionStyles=!1})}disableHighlightStyle(){let e=this.editor;e.update(()=>{let t=e.getElementByKey(this.tableNodeKey);if(!t)throw new Error("Expected to find TableElement in DOM");Te(t,e._config.theme.tableSelection),this.hasHijackedSelectionStyles=!0})}updateTableTableSelection(e){if(e!==null&&e.tableKey===this.tableNodeKey){let t=this.editor;this.tableSelection=e,this.isHighlightingCells=!0,this.disableHighlightStyle(),kr(t,this.table,this.tableSelection)}else e==null?this.clearHighlight():(this.tableNodeKey=e.tableKey,this.updateTableTableSelection(e))}setFocusCellForSelection(e,t=!1){let n=this.editor;n.update(()=>{let r=j(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=e.x,l=e.y;if(this.focusCell=e,this.anchorCell!==null){let a=na(n._window);a&&a.setBaseAndExtent(this.anchorCell.elem,0,this.focusCell.elem,0)}if(!this.isHighlightingCells&&(this.anchorX!==s||this.anchorY!==l||t))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(e.elem);if(this.tableSelection!=null&&this.anchorCellNodeKey!=null&&w(a)&&r.is(Co(a))){let c=a.getKey();this.tableSelection=this.tableSelection.clone()||zi(),this.focusCellNodeKey=c,this.tableSelection.set(this.tableNodeKey,this.anchorCellNodeKey,this.focusCellNodeKey),q(this.tableSelection),n.dispatchCommand(ve,void 0),kr(n,this.table,this.tableSelection)}}})}setAnchorCellForSelection(e){this.isHighlightingCells=!1,this.anchorCell=e,this.anchorX=e.x,this.anchorY=e.y,this.editor.update(()=>{let t=ee(e.elem);if(w(t)){let n=t.getKey();this.tableSelection=this.tableSelection!=null?this.tableSelection.clone():zi(),this.anchorCellNodeKey=n}})}formatCells(e){this.editor.update(()=>{