UNPKG

lexical

Version:

Lexical is an extensible text editor framework that provides excellent reliability, accessible and performance.

9 lines (8 loc) 127 kB
/** * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * */ "use strict";function t(t,...e){const n=new URL("https://lexical.dev/docs/error"),r=new URLSearchParams;r.append("code",t);for(const t of e)r.append("v",t);throw n.search=r.toString(),Error(`Minified Lexical error #${t}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}const e="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement,n=e&&"documentMode"in document?document.documentMode:null,r=e&&/Mac|iPod|iPhone|iPad/.test(navigator.platform),i=e&&/^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent),o=!(!e||!("InputEvent"in window)||n)&&"getTargetRanges"in new window.InputEvent("input"),s=e&&/Version\/[\d.]+.*Safari/.test(navigator.userAgent),l=e&&/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream,c=e&&/Android/.test(navigator.userAgent),a=e&&/^(?=.*Chrome).*/i.test(navigator.userAgent),u=e&&c&&a,f=e&&/AppleWebKit\/[\d.]+/.test(navigator.userAgent)&&!a;function d(...t){const e=[];for(const n of t)if(n&&"string"==typeof n)for(const[t]of n.matchAll(/\S+/g))e.push(t);return e}const h=1,g=3,_=9,p=11,y=0,m=1,x=2,C=0,S=1,N=2,T=4,v=8,k=128,E=1792|(112|(3|T|v)|k),b=1,M=2,O=3,A=4,w=5,D=6,P=s||l||f?" ":"​",I="\n\n",L=i?" ":P,F="֑-߿יִ-﷽ﹰ-ﻼ",R="A-Za-zÀ-ÖØ-öø-ʸ̀-֐ࠀ-῿‎Ⰰ-﬜︀-﹯﻽-￿",K=new RegExp("^[^"+R+"]*["+F+"]"),B=new RegExp("^[^"+F+"]*["+R+"]"),z={bold:1,capitalize:1024,code:16,highlight:k,italic:2,lowercase:256,strikethrough:T,subscript:32,superscript:64,underline:v,uppercase:512},W={directionless:1,unmergeable:2},$={center:M,end:D,justify:A,left:b,right:O,start:w},U={[M]:"center",[D]:"end",[A]:"justify",[b]:"left",[O]:"right",[w]:"start"},Y={normal:0,segmented:2,token:1},J={[C]:"normal",[N]:"segmented",[S]:"token"},H="$";function j(t,e,n,r,i,o){let s=t.getFirstChild();for(;null!==s;){const t=s.__key;s.__parent===e&&(Zr(s)&&j(s,t,n,r,i,o),n.has(t)||o.delete(t),i.push(t)),s=s.getNextSibling()}}const V=100;let G=!1,q=0;function X(t){q=t.timeStamp}function Q(t,e,n){const r="BR"===t.nodeName,i=e.__lexicalLineBreak;return i&&(t===i||r&&t.previousSibling===i)||r&&void 0!==zi(t,n)}function Z(t,e,n){const r=Do(To(n));let i=null,o=null;null!==r&&r.anchorNode===t&&(i=r.anchorOffset,o=r.focusOffset);const s=t.nodeValue;null!==s&&to(e,s,i,o,!1)}function tt(t,e,n){if(tr(t)){const e=t.anchor.getNode();if(e.is(n)&&t.format!==e.getFormat())return!1}return Oi(e)&&n.isAttached()}function et(t,e,n,r){for(let i=t;i&&!Ho(i);i=yo(i)){const t=zi(i,e);if(void 0!==t){const e=Ki(t,n);if(e)return ni(e)||!Io(i)?void 0:[i,e]}else if(i===r)return[r,Ji(n)]}}function nt(t,e,n){G=!0;const r=performance.now()-q>V;try{Gr(t,(()=>{const o=pr()||function(t){return t.getEditorState().read((()=>{const t=pr();return null!==t?t.clone():null}))}(t),s=new Map,l=t.getRootElement(),c=t._editorState,a=t._blockCursorElement;let u=!1,f="";for(let n=0;n<e.length;n++){const d=e[n],h=d.type,g=d.target,_=et(g,t,c,l);if(!_)continue;const[p,y]=_;if("characterData"===h)r&&Yn(y)&&Oi(g)&&tt(o,g,y)&&Z(g,y,t);else if("childList"===h){u=!0;const e=d.addedNodes;for(let n=0;n<e.length;n++){const r=e[n],o=Bi(r),s=r.parentNode;if(null!=s&&r!==a&&null===o&&!Q(r,s,t)){if(i){const t=(Io(r)?r.innerText:null)||r.nodeValue;t&&(f+=t)}s.removeChild(r)}}const n=d.removedNodes,r=n.length;if(r>0){let e=0;for(let i=0;i<r;i++){const r=n[i];(Q(r,g,t)||a===r)&&(g.appendChild(r),e++)}r!==e&&s.set(p,y)}}}if(s.size>0)for(const[e,n]of s)n.reconcileObservedMutation(e,t);const d=n.takeRecords();if(d.length>0){for(let e=0;e<d.length;e++){const n=d[e],r=n.addedNodes,i=n.target;for(let e=0;e<r.length;e++){const n=r[e],o=n.parentNode;null==o||"BR"!==n.nodeName||Q(n,i,t)||o.removeChild(n)}}n.takeRecords()}null!==o&&(u&&Hi(o),i&&ho(t)&&o.insertRawText(f))}))}finally{G=!1}}function rt(t){const e=t._observer;if(null!==e){nt(t,e.takeRecords(),e)}}function it(t){!function(t){0===q&&To(t).addEventListener("textInput",X,!0)}(t),t._observer=new MutationObserver(((e,n)=>{nt(t,e,n)}))}function ot(t){return t}class st{constructor(t,e){this.key=t,this.parse=e.parse.bind(e),this.unparse=(e.unparse||ot).bind(e),this.isEqual=(e.isEqual||Object.is).bind(e),this.defaultValue=this.parse(void 0)}}function lt(t,e,n="latest"){const r=("latest"===n?t.getLatest():t).__state;return r?r.getValue(e):e.defaultValue}class ct{constructor(t,e=new Map,n=void 0,r=new Map,i=void 0){this.node=t,this.sharedConfigMap=e,this.unknownState=n,this.knownState=r;const o=void 0!==i?i:function(t,e,n){let r=n.size;if(e)for(const i in e){const e=t.get(i);e&&n.has(e)||r++}return r}(e,n,r);this.size=o}getValue(t){const e=this.knownState.get(t);if(void 0!==e)return e;this.sharedConfigMap.set(t.key,t);let n=t.defaultValue;if(this.unknownState&&t.key in this.unknownState){const e=this.unknownState[t.key];void 0!==e&&(n=t.parse(e)),this.updateFromKnown(t,n)}return n}getInternalState(){return[this.unknownState,this.knownState]}toJSON(){const t={...this.unknownState};for(const[e,n]of this.knownState)e.isEqual(n,e.defaultValue)?delete t[e.key]:t[e.key]=e.unparse(n);return at(t)?{[H]:t}:{}}getWritable(t){if(this.node===t)return this;const e=new Map(this.knownState),n=at(r=this.unknownState)&&{...r};var r;if(n)for(const t of e.keys())delete n[t.key];return new ct(t,this.sharedConfigMap,at(n),e,this.size)}updateFromKnown(t,e){const n=t.key;this.sharedConfigMap.set(n,t);const{knownState:r,unknownState:i}=this;r.has(t)||i&&n in i||this.size++,r.set(t,e)}updateFromUnknown(t,e){const n=this.sharedConfigMap.get(t);n?this.updateFromKnown(n,n.parse(e)):(this.unknownState=this.unknownState||{},t in this.unknownState||this.size++,this.unknownState[t]=e)}updateFromJSON(t){const{knownState:e}=this;for(const t of e.keys())e.set(t,t.defaultValue);if(this.size=e.size,this.unknownState={},t)for(const[e,n]of Object.entries(t))this.updateFromUnknown(e,n);this.unknownState=at(this.unknownState)}}function at(t){if(t)for(const e in t)return t}function ut(t){const e=t.getWritable(),n=e.__state?e.__state.getWritable(e):new ct(e);return e.__state=n,n}function ft(t,e){const n=t.__mode,r=t.__format,i=t.__style,o=e.__mode,s=e.__format,l=e.__style,c=t.__state,a=e.__state;return(null===n||n===o)&&(null===r||r===s)&&(null===i||i===l)&&(null===t.__state||c===a||function(t,e){if(t===e)return!0;if(t&&e&&t.size!==e.size)return!1;const n=new Set,r=(t,e)=>{for(const[r,i]of t.knownState){if(n.has(r.key))continue;n.add(r.key);const t=e?e.getValue(r):r.defaultValue;if(t!==i&&!r.isEqual(t,i))return!0}return!1},i=(t,e)=>{const{unknownState:r}=t,i=e?e.unknownState:void 0;if(r)for(const[t,e]of Object.entries(r))if(!n.has(t)&&(n.add(t),e!==(i?i[t]:void 0)))return!0;return!1};return!(t&&r(t,e)||e&&r(e,t)||t&&i(t,e)||e&&i(e,t))}(c,a))}function dt(t,e){const n=t.mergeWithSibling(e),r=Rr()._normalizedNodes;return r.add(t.__key),r.add(e.__key),n}function ht(t){let e,n,r=t;if(""!==r.__text||!r.isSimpleText()||r.isUnmergeable()){for(;null!==(e=r.getPreviousSibling())&&Yn(e)&&e.isSimpleText()&&!e.isUnmergeable();){if(""!==e.__text){if(ft(e,r)){r=dt(e,r);break}break}e.remove()}for(;null!==(n=r.getNextSibling())&&Yn(n)&&n.isSimpleText()&&!n.isUnmergeable();){if(""!==n.__text){if(ft(r,n)){r=dt(r,n);break}break}n.remove()}}else r.remove()}function gt(t){return _t(t.anchor),_t(t.focus),t}function _t(t){for(;"element"===t.type;){const e=t.getNode(),n=t.offset;let r,i;if(n===e.getChildrenSize()?(r=e.getChildAtIndex(n-1),i=!0):(r=e.getChildAtIndex(n),i=!1),Yn(r)){t.set(r.__key,i?r.getTextContentSize():0,"text",!0);break}if(!Zr(r))break;t.set(r.__key,i?r.getChildrenSize():0,"element",!0)}}let pt,yt,mt,xt,Ct,St,Nt,Tt,vt,kt,Et="",bt="",Mt=null,Ot="",At="",wt=!1,Dt=!1,Pt=null;function It(t,e){const n=Nt.get(t);if(null!==e){const n=Xt(t);n.parentNode===e&&e.removeChild(n)}if(Tt.has(t)||yt._keyToDOMMap.delete(t),Zr(n)){const t=Ht(n,Nt);Lt(t,0,t.length-1,null)}void 0!==n&&ao(kt,mt,xt,n,"destroyed")}function Lt(t,e,n,r){let i=e;for(;i<=n;++i){const e=t[i];void 0!==e&&It(e,r)}}function Ft(t,e){t.setProperty("text-align",e)}const Rt="40px";function Kt(t,e){const n=pt.theme.indent;if("string"==typeof n){const r=t.classList.contains(n);e>0&&!r?t.classList.add(n):e<1&&r&&t.classList.remove(n)}const r=getComputedStyle(t).getPropertyValue("--lexical-indent-base-value")||Rt;t.style.setProperty("padding-inline-start",0===e?"":`calc(${e} * ${r})`)}function Bt(t,e){const n=t.style;0===e?Ft(n,""):e===b?Ft(n,"left"):e===M?Ft(n,"center"):e===O?Ft(n,"right"):e===A?Ft(n,"justify"):e===w?Ft(n,"start"):e===D&&Ft(n,"end")}function zt(e,n){const r=Tt.get(e);void 0===r&&t(60);const i=r.createDOM(pt,yt);if(function(t,e,n){const r=n._keyToDOMMap;(function(t,e,n){const r=`__lexicalKey_${e._key}`;t[r]=n})(e,n,t),r.set(t,e)}(e,i,yt),Yn(r)?i.setAttribute("data-lexical-text","true"):ni(r)&&i.setAttribute("data-lexical-decorator","true"),Zr(r)){const t=r.__indent,e=r.__size;if(0!==t&&Kt(i,t),0!==e){const t=e-1;!function(t,e,n,r){const i=bt;bt="",Wt(t,n,0,e,n.getDOMSlot(r)),Yt(n,r),bt=i}(Ht(r,Tt),t,r,i)}const n=r.__format;0!==n&&Bt(i,n),r.isInline()||Ut(null,r,i),_o(r)&&(Et+=I,At+=I)}else{const t=r.getTextContent();if(ni(r)){const t=r.decorate(yt,pt);null!==t&&Vt(e,t),i.contentEditable="false"}else Yn(r)&&(r.isDirectionless()||(bt+=t));Et+=t,At+=t}return null!==n&&n.insertChild(i),ao(kt,mt,xt,r,"created"),i}function Wt(t,e,n,r,i){const o=Et;Et="";let s=n;for(;s<=r;++s){zt(t[s],i);const e=Tt.get(t[s]);null!==e&&Yn(e)&&(null===Mt&&(Mt=e.getFormat()),""===Ot&&(Ot=e.getStyle()))}_o(e)&&(Et+=I);i.element.__lexicalTextContent=Et,Et=o+Et}function $t(t,e){if(t){const n=t.__last;if(n){const t=e.get(n);if(t)return En(t)?"line-break":ni(t)&&t.isInline()?"decorator":null}return"empty"}return null}function Ut(t,e,n){const r=$t(t,Nt),i=$t(e,Tt);r!==i&&e.getDOMSlot(n).setManagedLineBreak(i)}function Yt(t,e){const n=e.__lexicalDirTextContent||"",r=e.__lexicalDir||"";if(n!==bt||r!==Pt){const n=""===bt,i=n?Pt:function(t){if(K.test(t))return"rtl";if(B.test(t))return"ltr";return null}(bt);if(i!==r){const o=e.classList,s=pt.theme;let l=null!==r?s[r]:void 0,c=null!==i?s[i]:void 0;if(void 0!==l){if("string"==typeof l){const t=d(l);l=s[r]=t}o.remove(...l)}if(null===i||n&&"ltr"===i)e.removeAttribute("dir");else{if(void 0!==c){if("string"==typeof c){const t=d(c);c=s[i]=t}void 0!==c&&o.add(...c)}e.dir=i}if(!Dt){t.getWritable().__dir=i}}Pt=i,e.__lexicalDirTextContent=bt,e.__lexicalDir=i}}function Jt(e,n,r){const i=bt;var o;bt="",Mt=null,Ot="",function(e,n,r){const i=Et,o=e.__size,s=n.__size;Et="";const l=r.element;if(1===o&&1===s){const t=e.__first,r=n.__first;if(t===r)jt(t,l);else{const e=Xt(t),n=zt(r,null);try{l.replaceChild(n,e)}catch(i){if("object"==typeof i&&null!=i){const o=`${i.toString()} Parent: ${l.tagName}, new child: {tag: ${n.tagName} key: ${r}}, old child: {tag: ${e.tagName}, key: ${t}}.`;throw new Error(o)}throw i}It(t,null)}const i=Tt.get(r);Yn(i)&&(null===Mt&&(Mt=i.getFormat()),""===Ot&&(Ot=i.getStyle()))}else{const i=Ht(e,Nt),c=Ht(n,Tt);if(i.length!==o&&t(227),c.length!==s&&t(228),0===o)0!==s&&Wt(c,n,0,s-1,r);else if(0===s){if(0!==o){const t=null==r.after&&null==r.before&&null==r.element.__lexicalLineBreak;Lt(i,0,o-1,t?null:l),t&&(l.textContent="")}}else!function(t,e,n,r,i,o){const s=r-1,l=i-1;let c,a,u=o.getFirstChild(),f=0,d=0;for(;f<=s&&d<=l;){const t=e[f],r=n[d];if(t===r)u=Gt(jt(r,o.element)),f++,d++;else{void 0===c&&(c=new Set(e)),void 0===a&&(a=new Set(n));const i=a.has(t),s=c.has(r);if(i)if(s){const t=po(yt,r);t===u?u=Gt(jt(r,o.element)):(o.withBefore(u).insertChild(t),jt(r,o.element)),f++,d++}else zt(r,o.withBefore(u)),d++;else u=Gt(Xt(t)),It(t,o.element),f++}const i=Tt.get(r);null!==i&&Yn(i)&&(null===Mt&&(Mt=i.getFormat()),""===Ot&&(Ot=i.getStyle()))}const h=f>s,g=d>l;if(h&&!g){const e=n[l+1],r=void 0===e?null:yt.getElementByKey(e);Wt(n,t,d,l,o.withBefore(r))}else g&&!h&&Lt(e,f,s,o.element)}(n,i,c,o,s,r)}_o(n)&&(Et+=I);l.__lexicalTextContent=Et,Et=i+Et}(e,n,n.getDOMSlot(r)),Yt(n,r),o=n,null==Mt||Mt===o.__textFormat||Dt||o.setTextFormat(Mt),function(t){""===Ot||Ot===t.__textStyle||Dt||t.setTextStyle(Ot)}(n),bt=i}function Ht(e,n){const r=[];let i=e.__first;for(;null!==i;){const e=n.get(i);void 0===e&&t(101),r.push(i),i=e.__next}return r}function jt(e,n){const r=Nt.get(e);let i=Tt.get(e);void 0!==r&&void 0!==i||t(61);const o=wt||St.has(e)||Ct.has(e),s=po(yt,e);if(r===i&&!o){if(Zr(r)){const t=s.__lexicalTextContent;void 0!==t&&(Et+=t,At+=t);const e=s.__lexicalDirTextContent;void 0!==e&&(bt+=e)}else{const t=r.getTextContent();Yn(r)&&!r.isDirectionless()&&(bt+=t),At+=t,Et+=t}return s}if(r!==i&&o&&ao(kt,mt,xt,i,"updated"),i.updateDOM(r,s,pt)){const r=zt(e,null);return null===n&&t(62),n.replaceChild(r,s),It(e,null),r}if(Zr(r)&&Zr(i)){const t=i.__indent;t!==r.__indent&&Kt(s,t);const e=i.__format;e!==r.__format&&Bt(s,e),o&&(Jt(r,i,s),ii(i)||i.isInline()||Ut(r,i,s)),_o(i)&&(Et+=I,At+=I)}else{const t=i.getTextContent();if(ni(i)){const t=i.decorate(yt,pt);null!==t&&Vt(e,t)}else Yn(i)&&!i.isDirectionless()&&(bt+=t);Et+=t,At+=t}if(!Dt&&ii(i)&&i.__cachedText!==At){const t=i.getWritable();t.__cachedText=At,i=t}return s}function Vt(t,e){let n=yt._pendingDecorators;const r=yt._decorators;if(null===n){if(r[t]===e)return;n=$i(yt)}n[t]=e}function Gt(t){let e=t.nextSibling;return null!==e&&e===yt._blockCursorElement&&(e=e.nextSibling),e}function qt(t,e,n,r,i,o){Et="",At="",bt="",wt=r===x,Pt=null,yt=n,pt=n._config,mt=n._nodes,xt=yt._listeners.mutation,Ct=i,St=o,Nt=t._nodeMap,Tt=e._nodeMap,Dt=e._readOnly,vt=new Map(n._keyToDOMMap);const s=new Map;return kt=s,jt("root",null),yt=void 0,mt=void 0,Ct=void 0,St=void 0,Nt=void 0,Tt=void 0,pt=void 0,vt=void 0,kt=void 0,s}function Xt(e){const n=vt.get(e);return void 0===n&&t(75,e),n}function Qt(t){return{type:t}}const Zt=Qt("SELECTION_CHANGE_COMMAND"),te=Qt("SELECTION_INSERT_CLIPBOARD_NODES_COMMAND"),ee=Qt("CLICK_COMMAND"),ne=Qt("DELETE_CHARACTER_COMMAND"),re=Qt("INSERT_LINE_BREAK_COMMAND"),ie=Qt("INSERT_PARAGRAPH_COMMAND"),oe=Qt("CONTROLLED_TEXT_INSERTION_COMMAND"),se=Qt("PASTE_COMMAND"),le=Qt("REMOVE_TEXT_COMMAND"),ce=Qt("DELETE_WORD_COMMAND"),ae=Qt("DELETE_LINE_COMMAND"),ue=Qt("FORMAT_TEXT_COMMAND"),fe=Qt("UNDO_COMMAND"),de=Qt("REDO_COMMAND"),he=Qt("KEYDOWN_COMMAND"),ge=Qt("KEY_ARROW_RIGHT_COMMAND"),_e=Qt("MOVE_TO_END"),pe=Qt("KEY_ARROW_LEFT_COMMAND"),ye=Qt("MOVE_TO_START"),me=Qt("KEY_ARROW_UP_COMMAND"),xe=Qt("KEY_ARROW_DOWN_COMMAND"),Ce=Qt("KEY_ENTER_COMMAND"),Se=Qt("KEY_SPACE_COMMAND"),Ne=Qt("KEY_BACKSPACE_COMMAND"),Te=Qt("KEY_ESCAPE_COMMAND"),ve=Qt("KEY_DELETE_COMMAND"),ke=Qt("KEY_TAB_COMMAND"),Ee=Qt("INSERT_TAB_COMMAND"),be=Qt("INDENT_CONTENT_COMMAND"),Me=Qt("OUTDENT_CONTENT_COMMAND"),Oe=Qt("DROP_COMMAND"),Ae=Qt("FORMAT_ELEMENT_COMMAND"),we=Qt("DRAGSTART_COMMAND"),De=Qt("DRAGOVER_COMMAND"),Pe=Qt("DRAGEND_COMMAND"),Ie=Qt("COPY_COMMAND"),Le=Qt("CUT_COMMAND"),Fe=Qt("SELECT_ALL_COMMAND"),Re=Qt("CLEAR_EDITOR_COMMAND"),Ke=Qt("CLEAR_HISTORY_COMMAND"),Be=Qt("CAN_REDO_COMMAND"),ze=Qt("CAN_UNDO_COMMAND"),We=Qt("FOCUS_COMMAND"),$e=Qt("BLUR_COMMAND"),Ue=Qt("KEY_MODIFIER_COMMAND"),Ye=Object.freeze({}),Je=30,He=[["keydown",function(t,e){if(je=t.timeStamp,Ve=t.key,e.isComposing())return;if(go(e,he,t))return;if(null==t.key)return;if(nn&&so(t))return Gr(e,(()=>{hn(e,rn)})),nn=!1,void(rn="");if(function(t){return ro(t,"ArrowRight",{shiftKey:"any"})}(t))go(e,ge,t);else if(function(t){return ro(t,"ArrowRight",io)}(t))go(e,_e,t);else if(function(t){return ro(t,"ArrowLeft",{shiftKey:"any"})}(t))go(e,pe,t);else if(function(t){return ro(t,"ArrowLeft",io)}(t))go(e,ye,t);else if(function(t){return ro(t,"ArrowUp",{altKey:"any",shiftKey:"any"})}(t))go(e,me,t);else if(function(t){return ro(t,"ArrowDown",{altKey:"any",shiftKey:"any"})}(t))go(e,xe,t);else if(function(t){return ro(t,"Enter",{altKey:"any",ctrlKey:"any",metaKey:"any",shiftKey:!0})}(t))tn=!0,go(e,Ce,t);else if(function(t){return" "===t.key}(t))go(e,Se,t);else if(function(t){return r&&ro(t,"o",{ctrlKey:!0})}(t))t.preventDefault(),tn=!0,go(e,re,!0);else if(function(t){return ro(t,"Enter",{altKey:"any",ctrlKey:"any",metaKey:"any"})}(t))tn=!1,go(e,Ce,t);else if(function(t){return ro(t,"Backspace",{shiftKey:"any"})||r&&ro(t,"h",{ctrlKey:!0})}(t))so(t)?go(e,Ne,t):(t.preventDefault(),go(e,ne,!0));else if(function(t){return"Escape"===t.key}(t))go(e,Te,t);else if(function(t){return ro(t,"Delete",{})||r&&ro(t,"d",{ctrlKey:!0})}(t))!function(t){return"Delete"===t.key}(t)?(t.preventDefault(),go(e,ne,!1)):go(e,ve,t);else if(function(t){return ro(t,"Backspace",oo)}(t))t.preventDefault(),go(e,ce,!0);else if(function(t){return ro(t,"Delete",oo)}(t))t.preventDefault(),go(e,ce,!1);else if(function(t){return r&&ro(t,"Backspace",{metaKey:!0})}(t))t.preventDefault(),go(e,ae,!0);else if(function(t){return r&&(ro(t,"Delete",{metaKey:!0})||ro(t,"k",{ctrlKey:!0}))}(t))t.preventDefault(),go(e,ae,!1);else if(function(t){return ro(t,"b",io)}(t))t.preventDefault(),go(e,ue,"bold");else if(function(t){return ro(t,"u",io)}(t))t.preventDefault(),go(e,ue,"underline");else if(function(t){return ro(t,"i",io)}(t))t.preventDefault(),go(e,ue,"italic");else if(function(t){return ro(t,"Tab",{shiftKey:"any"})}(t))go(e,ke,t);else if(function(t){return ro(t,"z",io)}(t))t.preventDefault(),go(e,fe,void 0);else if(function(t){if(r)return ro(t,"z",{metaKey:!0,shiftKey:!0});return ro(t,"y",{ctrlKey:!0})||ro(t,"z",{ctrlKey:!0,shiftKey:!0})}(t))t.preventDefault(),go(e,de,void 0);else{const n=e._editorState._selection;null===n||tr(n)?lo(t)&&(t.preventDefault(),go(e,Fe,t)):!function(t){return ro(t,"c",io)}(t)?!function(t){return ro(t,"x",io)}(t)?lo(t)&&(t.preventDefault(),go(e,Fe,t)):(t.preventDefault(),go(e,Le,t)):(t.preventDefault(),go(e,Ie,t))}(function(t){return t.ctrlKey||t.shiftKey||t.altKey||t.metaKey})(t)&&go(e,Ue,t)}],["pointerdown",function(t,e){const n=t.target,r=t.pointerType;Lo(n)&&"touch"!==r&&"pen"!==r&&0===t.button&&Gr(e,(()=>{Si(n)||(Ze=!0)}))}],["compositionstart",function(t,e){Gr(e,(()=>{const n=pr();if(tr(n)&&!e.isComposing()){const r=n.anchor,i=n.anchor.getNode();Fi(r.key),(t.timeStamp<je+Je||"element"===r.type||!n.isCollapsed()||i.getFormat()!==n.format||Yn(i)&&i.getStyle()!==n.style)&&go(e,oe,L)}}))}],["compositionend",function(t,e){i?en=!0:l||!s&&!f?Gr(e,(()=>{hn(e,t.data)})):(nn=!0,rn=t.data)}],["input",function(t,e){t.stopPropagation(),Gr(e,(()=>{if(Io(t.target)&&Si(t.target))return;const n=pr(),r=t.data,c=dn(t);if(null!=r&&tr(n)&&ln(n,c,r,t.timeStamp,!1)){en&&(hn(e,r),en=!1);const c=n.anchor.getNode(),a=Do(To(e));if(null===a)return;const u=n.isBackward(),d=u?n.anchor.offset:n.focus.offset,h=u?n.focus.offset:n.anchor.offset;o&&!n.isCollapsed()&&Yn(c)&&null!==a.anchorNode&&c.getTextContent().slice(0,d)+r+c.getTextContent().slice(d+h)===Qi(a.anchorNode)||go(e,oe,r);const g=r.length;i&&g>1&&"insertCompositionText"===t.inputType&&!e.isComposing()&&(n.anchor.offset-=g),s||l||f||!e.isComposing()||(je=0,Fi(null))}else{Zi(!1,e,null!==r?r:void 0),en&&(hn(e,r||void 0),en=!1)}!function(){Ir();const t=Rr();rt(t)}()}),{event:t}),qe=null}],["click",function(t,e){Gr(e,(()=>{const n=pr(),r=Do(To(e)),i=yr();if(r)if(tr(n)){const e=n.anchor,o=e.getNode();if("element"===e.type&&0===e.offset&&n.isCollapsed()&&!ii(o)&&1===Yi().getChildrenSize()&&o.getTopLevelElementOrThrow().isEmpty()&&null!==i&&n.is(i))r.removeAllRanges(),n.dirty=!0;else if(3===t.detail&&!n.isCollapsed()){if(o!==n.focus.getNode()){const t=function(t,e){let n=t;for(;n!==Yi()&&null!=n;){if(e(n))return n;n=n.getParent()}return null}(o,(t=>Zr(t)&&!t.isInline()));Zr(t)&&t.select(0)}}}else if("touch"===t.pointerType||"pen"===t.pointerType){const n=r.anchorNode;if(Io(n)||Oi(n)){Hi(_r(i,r,e,t))}}go(e,ee,t)}))}],["cut",Ye],["copy",Ye],["dragstart",Ye],["dragover",Ye],["dragend",Ye],["paste",Ye],["focus",Ye],["blur",Ye],["drop",Ye]];o&&He.push(["beforeinput",(e,n)=>function(e,n){const r=e.inputType,o=dn(e);if("deleteCompositionText"===r||i&&ho(n))return;if("insertCompositionText"===r)return;Gr(n,(()=>{const i=pr();if("deleteContentBackward"===r){if(null===i){const t=yr();if(!tr(t))return;Hi(t.clone())}if(tr(i)){const r=i.anchor.key===i.focus.key;if(s=e.timeStamp,"MediaLast"===Ve&&s<je+Je&&n.isComposing()&&r){if(Fi(null),je=0,setTimeout((()=>{Gr(n,(()=>{Fi(null)}))}),Je),tr(i)){const e=i.anchor.getNode();e.markDirty(),Yn(e)||t(142),fn(i,e)}}else{Fi(null),e.preventDefault();const t=i.anchor.getNode(),o=t.getTextContent(),s=t.canInsertTextAfter(),l=0===i.anchor.offset&&i.focus.offset===o.length;let c=u&&r&&!l&&s;if(c&&i.isCollapsed()&&(c=!ni(fo(i.anchor,!0))),!c){go(n,ne,!0);const t=pr();u&&tr(t)&&t.isCollapsed()&&(on=t,setTimeout((()=>on=null)))}}return}}var s;if(!tr(i))return;const c=e.data;null!==qe&&Zi(!1,n,qe),i.dirty&&null===qe||!i.isCollapsed()||ii(i.anchor.getNode())||null===o||i.applyDOMRange(o),qe=null;const a=i.anchor,f=i.focus,d=a.getNode(),h=f.getNode();if("insertText"!==r&&"insertTranspose"!==r)switch(e.preventDefault(),r){case"insertFromYank":case"insertFromDrop":case"insertReplacementText":go(n,oe,e);break;case"insertFromComposition":Fi(null),go(n,oe,e);break;case"insertLineBreak":Fi(null),go(n,re,!1);break;case"insertParagraph":Fi(null),tn&&!l?(tn=!1,go(n,re,!1)):go(n,ie,void 0);break;case"insertFromPaste":case"insertFromPasteAsQuotation":go(n,se,e);break;case"deleteByComposition":(function(t,e){return t!==e||Zr(t)||Zr(e)||!bi(t)||!bi(e)})(d,h)&&go(n,le,e);break;case"deleteByDrag":case"deleteByCut":go(n,le,e);break;case"deleteContent":go(n,ne,!1);break;case"deleteWordBackward":go(n,ce,!0);break;case"deleteWordForward":go(n,ce,!1);break;case"deleteHardLineBackward":case"deleteSoftLineBackward":go(n,ae,!0);break;case"deleteContentForward":case"deleteHardLineForward":case"deleteSoftLineForward":go(n,ae,!1);break;case"formatStrikeThrough":go(n,ue,"strikethrough");break;case"formatBold":go(n,ue,"bold");break;case"formatItalic":go(n,ue,"italic");break;case"formatUnderline":go(n,ue,"underline");break;case"historyUndo":go(n,fe,void 0);break;case"historyRedo":go(n,de,void 0)}else{if("\n"===c)e.preventDefault(),go(n,re,!1);else if(c===I)e.preventDefault(),go(n,ie,void 0);else if(null==c&&e.dataTransfer){const t=e.dataTransfer.getData("text/plain");e.preventDefault(),i.insertRawText(t)}else null!=c&&ln(i,o,c,e.timeStamp,!0)?(e.preventDefault(),go(n,oe,c)):qe=c;Ge=e.timeStamp}}))}(e,n)]);let je=0,Ve=null,Ge=0,qe=null;const Xe=new WeakMap;let Qe=!1,Ze=!1,tn=!1,en=!1,nn=!1,rn="",on=null,sn=[0,"",0,"root",0];function ln(t,e,n,r,i){const s=t.anchor,l=t.focus,c=s.getNode(),a=Rr(),u=Do(To(a)),f=null!==u?u.anchorNode:null,d=s.key,h=a.getElementByKey(d),g=n.length;return d!==l.key||!Yn(c)||(!i&&(!o||Ge<r+50)||c.isDirty()&&g<2||Gi(n))&&s.offset!==l.offset&&!c.isComposing()||Mi(c)||c.isDirty()&&g>1||(i||!o)&&null!==h&&!c.isComposing()&&f!==wi(h)||null!==u&&null!==e&&(!e.collapsed||e.startContainer!==u.anchorNode||e.startOffset!==u.anchorOffset)||c.getFormat()!==t.format||c.getStyle()!==t.style||function(t,e){if(e.isSegmented())return!0;if(!t.isCollapsed())return!1;const n=t.anchor.offset,r=e.getParentOrThrow(),i=bi(e);return 0===n?!e.canInsertTextBefore()||!r.canInsertTextBefore()&&!e.isComposing()||i||function(t){const e=t.getPreviousSibling();return(Yn(e)||Zr(e)&&e.isInline())&&!e.canInsertTextAfter()}(e):n===e.getTextContentSize()&&(!e.canInsertTextAfter()||!r.canInsertTextAfter()&&!e.isComposing()||i)}(t,c)}function cn(t,e){return Oi(t)&&null!==t.nodeValue&&0!==e&&e!==t.nodeValue.length}function an(e,n,r){const{anchorNode:i,anchorOffset:o,focusNode:s,focusOffset:l}=e;Qe&&(Qe=!1,cn(i,o)&&cn(s,l)&&!on)||Gr(n,(()=>{if(!r)return void Hi(null);if(!Ti(n,i,s))return;let c=pr();if(on&&tr(c)&&c.isCollapsed()){const t=c.anchor,e=on.anchor;(t.key===e.key&&t.offset===e.offset+1||1===t.offset&&e.getNode().is(t.getNode().getPreviousSibling()))&&(c=on.clone(),Hi(c))}if(on=null,tr(c)){const r=c.anchor,i=r.getNode();if(c.isCollapsed()){"Range"===e.type&&e.anchorNode===e.focusNode&&(c.dirty=!0);const o=To(n).event,s=o?o.timeStamp:performance.now(),[l,a,u,f,d]=sn,h=Yi(),g=!1===n.isComposing()&&""===h.getTextContent();if(s<d+200&&r.offset===u&&r.key===f)un(c,l,a);else if("text"===r.type)Yn(i)||t(141),fn(c,i);else if("element"===r.type&&!g){Zr(i)||t(259);const e=r.getNode();e.isEmpty()?function(t,e){const n=e.getTextFormat(),r=e.getTextStyle();un(t,n,r)}(c,e):un(c,0,"")}}else{const t=r.key,e=c.focus.key,n=c.getNodes(),i=n.length,s=c.isBackward(),a=s?l:o,u=s?o:l,f=s?e:t,d=s?t:e;let h=E,g=!1;for(let t=0;t<i;t++){const e=n[t],r=e.getTextContentSize();if(Yn(e)&&0!==r&&!(0===t&&e.__key===f&&a===r||t===i-1&&e.__key===d&&0===u)&&(g=!0,h&=e.getFormat(),0===h))break}c.format=g?h:0}}go(n,Zt,void 0)}))}function un(t,e,n){t.format===e&&t.style===n||(t.format=e,t.style=n,t.dirty=!0)}function fn(t,e){un(t,e.getFormat(),e.getStyle())}function dn(t){if(!t.getTargetRanges)return null;const e=t.getTargetRanges();return 0===e.length?null:e[0]}function hn(t,e){const n=t._compositionKey;if(Fi(null),null!==n&&null!=e){if(""===e){const e=Ki(n),r=wi(t.getElementByKey(n));return void(null!==r&&null!==r.nodeValue&&Yn(e)&&to(e,r.nodeValue,null,null,!0))}if("\n"===e[e.length-1]){const e=pr();if(tr(e)){const n=e.focus;return e.anchor.set(n.key,n.offset,n.type),void go(t,Ce,null)}}}Zi(!0,t,e)}function gn(t){let e=t.__lexicalEventHandles;return void 0===e&&(e=[],t.__lexicalEventHandles=e),e}const _n=new Map;function pn(t){const e=Po(t.target);if(null===e)return;const n=ki(e.anchorNode);if(null===n)return;Ze&&(Ze=!1,Gr(n,(()=>{const r=yr(),i=e.anchorNode;if(Io(i)||Oi(i)){Hi(_r(r,e,n,t))}})));const r=qi(n),i=r[r.length-1],o=i._key,s=_n.get(o),l=s||i;l!==n&&an(e,l,!1),an(e,n,!0),n!==i?_n.set(o,n):s&&_n.delete(o)}function yn(t){t._lexicalHandled=!0}function mn(t){return!0===t._lexicalHandled}const xn=()=>{};function Cn(e){const n=e.ownerDocument,r=Xe.get(n);if(void 0===r)return void xn();const i=r-1;i>=0||t(164),Xe.set(n,i),0===i&&n.removeEventListener("selectionchange",pn);const o=Ei(e);vi(o)?(!function(t){if(null!==t._parentEditor){const e=qi(t),n=e[e.length-1]._key;_n.get(n)===t&&_n.delete(n)}else _n.delete(t._key)}(o),e.__lexicalEditor=null):o&&t(198);const s=gn(e);for(let t=0;t<s.length;t++)s[t]();e.__lexicalEventHandles=[]}function Sn(t,e,n){Ir();const r=t.__key,i=t.getParent();if(null===i)return;const o=function(t){const e=pr();if(!tr(e)||!Zr(t))return e;const{anchor:n,focus:r}=e,i=n.getNode(),o=r.getNode();So(i,t)&&n.set(t.__key,0,"element");So(o,t)&&r.set(t.__key,0,"element");return e}(t);let s=!1;if(tr(o)&&e){const e=o.anchor,n=o.focus;e.key===r&&(Cr(e,t,i,t.getPreviousSibling(),t.getNextSibling()),s=!0),n.key===r&&(Cr(n,t,i,t.getPreviousSibling(),t.getNextSibling()),s=!0)}else nr(o)&&e&&t.isSelected()&&t.selectPrevious();if(tr(o)&&e&&!s){const e=t.getIndexWithinParent();Ii(t),mr(o,i,e,-1)}else Ii(t);n||ko(i)||i.canBeEmpty()||!i.isEmpty()||Sn(i,e),e&&o&&ii(i)&&i.isEmpty()&&i.selectEnd()}class Nn{static getType(){t(64,this.name)}static clone(e){t(65,this.name)}afterCloneFrom(t){this.__parent=t.__parent,this.__next=t.__next,this.__prev=t.__prev,this.__state=t.__state}constructor(t){this.__type=this.constructor.getType(),this.__parent=null,this.__prev=null,this.__next=null,Object.defineProperty(this,"__state",{configurable:!0,enumerable:!1,value:void 0,writable:!0}),Pi(this,t)}getType(){return this.__type}isInline(){t(137,this.constructor.name)}isAttached(){let t=this.__key;for(;null!==t;){if("root"===t)return!0;const e=Ki(t);if(null===e)break;t=e.__parent}return!1}isSelected(t){const e=t||pr();if(null==e)return!1;const n=e.getNodes().some((t=>t.__key===this.__key));if(Yn(this))return n;if(tr(e)&&"element"===e.anchor.type&&"element"===e.focus.type){if(e.isCollapsed())return!1;const t=this.getParent();if(ni(this)&&this.isInline()&&t){const n=e.isBackward()?e.focus:e.anchor;if(t.is(n.getNode())&&n.offset===t.getChildrenSize()&&this.is(t.getLastChild()))return!1}}return n}getKey(){return this.__key}getIndexWithinParent(){const t=this.getParent();if(null===t)return-1;let e=t.getFirstChild(),n=0;for(;null!==e;){if(this.is(e))return n;n++,e=e.getNextSibling()}return-1}getParent(){const t=this.getLatest().__parent;return null===t?null:Ki(t)}getParentOrThrow(){const e=this.getParent();return null===e&&t(66,this.__key),e}getTopLevelElement(){let e=this;for(;null!==e;){const n=e.getParent();if(ko(n))return Zr(e)||e===this&&ni(e)||t(194),e;e=n}return null}getTopLevelElementOrThrow(){const e=this.getTopLevelElement();return null===e&&t(67,this.__key),e}getParents(){const t=[];let e=this.getParent();for(;null!==e;)t.push(e),e=e.getParent();return t}getParentKeys(){const t=[];let e=this.getParent();for(;null!==e;)t.push(e.__key),e=e.getParent();return t}getPreviousSibling(){const t=this.getLatest().__prev;return null===t?null:Ki(t)}getPreviousSiblings(){const t=[],e=this.getParent();if(null===e)return t;let n=e.getFirstChild();for(;null!==n&&!n.is(this);)t.push(n),n=n.getNextSibling();return t}getNextSibling(){const t=this.getLatest().__next;return null===t?null:Ki(t)}getNextSiblings(){const t=[];let e=this.getNextSibling();for(;null!==e;)t.push(e),e=e.getNextSibling();return t}getCommonAncestor(t){const e=Zr(this)?this:this.getParent(),n=Zr(t)?t:t.getParent(),r=e&&n?vs(e,n):null;return r?r.commonAncestor:null}is(t){return null!=t&&this.__key===t.__key}isBefore(e){const n=vs(this,e);return null!==n&&("descendant"===n.type||("branch"===n.type?-1===Ss(n):("same"!==n.type&&"ancestor"!==n.type&&t(279),!1)))}isParentOf(t){const e=vs(this,t);return null!==e&&"ancestor"===e.type}getNodesBetween(e){const n=this.isBefore(e),r=[],i=new Set;let o=this;for(;null!==o;){const s=o.__key;if(i.has(s)||(i.add(s),r.push(o)),o===e)break;const l=Zr(o)?n?o.getFirstChild():o.getLastChild():null;if(null!==l){o=l;continue}const c=n?o.getNextSibling():o.getPreviousSibling();if(null!==c){o=c;continue}const a=o.getParentOrThrow();if(i.has(a.__key)||r.push(a),a===e)break;let u=null,f=a;do{if(null===f&&t(68),u=n?f.getNextSibling():f.getPreviousSibling(),f=f.getParent(),null===f)break;null!==u||i.has(f.__key)||r.push(f)}while(null===u);o=u}return n||r.reverse(),r}isDirty(){const t=Rr()._dirtyLeaves;return null!==t&&t.has(this.__key)}getLatest(){const e=Ki(this.__key);return null===e&&t(113),e}getWritable(){Ir();const t=Fr(),e=Rr(),n=t._nodeMap,r=this.__key,i=this.getLatest(),o=e._cloneNotNeeded,s=pr();if(null!==s&&s.setCachedNodes(null),o.has(r))return Li(i),i;const l=Yo(i);return o.add(r),Li(l),n.set(r,l),l}getTextContent(){return""}getTextContentSize(){return this.getTextContent().length}createDOM(e,n){t(70)}updateDOM(e,n,r){t(71)}exportDOM(t){return{element:this.createDOM(t._config,t)}}exportJSON(){const t=this.__state?this.__state.toJSON():void 0;return{type:this.__type,version:1,...t}}static importJSON(e){t(18,this.name)}updateFromJSON(t){return function(t,e){const n=t.getWritable();return(e||n.__state)&&ut(t).updateFromJSON(e),n}(this,t.$)}static transform(){return null}remove(t){Sn(this,!0,t)}replace(e,n){Ir();let r=pr();null!==r&&(r=r.clone()),Mo(this,e);const i=this.getLatest(),o=this.__key,s=e.__key,l=e.getWritable(),c=this.getParentOrThrow().getWritable(),a=c.__size;Ii(l);const u=i.getPreviousSibling(),f=i.getNextSibling(),d=i.__prev,h=i.__next,g=i.__parent;if(Sn(i,!1,!0),null===u)c.__first=s;else{u.getWritable().__next=s}if(l.__prev=d,null===f)c.__last=s;else{f.getWritable().__prev=s}if(l.__next=h,l.__parent=g,c.__size=a,n&&(Zr(this)&&Zr(l)||t(139),this.getChildren().forEach((t=>{l.append(t)}))),tr(r)){Hi(r);const t=r.anchor,e=r.focus;t.key===o&&Qn(t,l),e.key===o&&Qn(e,l)}return Ri()===o&&Fi(s),l}insertAfter(t,e=!0){Ir(),Mo(this,t);const n=this.getWritable(),r=t.getWritable(),i=r.getParent(),o=pr();let s=!1,l=!1;if(null!==i){const e=t.getIndexWithinParent();if(Ii(r),tr(o)){const t=i.__key,n=o.anchor,r=o.focus;s="element"===n.type&&n.key===t&&n.offset===e+1,l="element"===r.type&&r.key===t&&r.offset===e+1}}const c=this.getNextSibling(),a=this.getParentOrThrow().getWritable(),u=r.__key,f=n.__next;if(null===c)a.__last=u;else{c.getWritable().__prev=u}if(a.__size++,n.__next=u,r.__next=f,r.__prev=n.__key,r.__parent=n.__parent,e&&tr(o)){const t=this.getIndexWithinParent();mr(o,a,t+1);const e=a.__key;s&&o.anchor.set(e,t+2,"element"),l&&o.focus.set(e,t+2,"element")}return t}insertBefore(t,e=!0){Ir(),Mo(this,t);const n=this.getWritable(),r=t.getWritable(),i=r.__key;Ii(r);const o=this.getPreviousSibling(),s=this.getParentOrThrow().getWritable(),l=n.__prev,c=this.getIndexWithinParent();if(null===o)s.__first=i;else{o.getWritable().__next=i}s.__size++,n.__prev=i,r.__prev=l,r.__next=n.__key,r.__parent=n.__parent;const a=pr();if(e&&tr(a)){mr(a,this.getParentOrThrow(),c)}return t}isParentRequired(){return!1}createParentElementNode(){return pi()}selectStart(){return this.selectPrevious()}selectEnd(){return this.selectNext(0,0)}selectPrevious(t,e){Ir();const n=this.getPreviousSibling(),r=this.getParentOrThrow();if(null===n)return r.select(0,0);if(Zr(n))return n.select();if(!Yn(n)){const t=n.getIndexWithinParent()+1;return r.select(t,t)}return n.select(t,e)}selectNext(t,e){Ir();const n=this.getNextSibling(),r=this.getParentOrThrow();if(null===n)return r.select();if(Zr(n))return n.select(0,0);if(!Yn(n)){const t=n.getIndexWithinParent();return r.select(t,t)}return n.select(t,e)}markDirty(){this.getWritable()}reconcileObservedMutation(t,e){this.markDirty()}}class Tn extends Nn{static getType(){return"linebreak"}static clone(t){return new Tn(t.__key)}constructor(t){super(t)}getTextContent(){return"\n"}createDOM(){return document.createElement("br")}updateDOM(){return!1}isInline(){return!0}static importDOM(){return{br:t=>function(t){const e=t.parentElement;if(null!==e&&Ko(e)){const n=e.firstChild;if(n===t||n.nextSibling===t&&bn(n)){const n=e.lastChild;if(n===t||n.previousSibling===t&&bn(n))return!0}}return!1}(t)||function(t){const e=t.parentElement;if(null!==e&&Ko(e)){const n=e.firstChild;if(n===t||n.nextSibling===t&&bn(n))return!1;const r=e.lastChild;if(r===t||r.previousSibling===t&&bn(r))return!0}return!1}(t)?null:{conversion:vn,priority:0}}}static importJSON(t){return kn().updateFromJSON(t)}}function vn(t){return{node:kn()}}function kn(){return bo(new Tn)}function En(t){return t instanceof Tn}function bn(t){return Oi(t)&&/^( |\t|\r?\n)+$/.test(t.textContent||"")}function Mn(t,e){return 16&e?"code":e&k?"mark":32&e?"sub":64&e?"sup":null}function On(t,e){return 1&e?"strong":2&e?"em":"span"}function An(t,e,n,r,i){const o=r.classList;let s=co(i,"base");void 0!==s&&o.add(...s),s=co(i,"underlineStrikethrough");let l=!1;const c=e&v&&e&T;void 0!==s&&(n&v&&n&T?(l=!0,c||o.add(...s)):c&&o.remove(...s));for(const t in z){const r=z[t];if(s=co(i,t),void 0!==s)if(n&r){if(l&&("underline"===t||"strikethrough"===t)){e&r&&o.remove(...s);continue}e&r&&(!c||"underline"!==t)&&"strikethrough"!==t||o.add(...s)}else e&r&&o.remove(...s)}}function wn(t,e,n){const r=e.firstChild,o=n.isComposing(),s=t+(o?P:"");if(null==r)e.textContent=s;else{const t=r.nodeValue;if(t!==s)if(o||i){const[e,n,i]=function(t,e){const n=t.length,r=e.length;let i=0,o=0;for(;i<n&&i<r&&t[i]===e[i];)i++;for(;o+i<n&&o+i<r&&t[n-o-1]===e[r-o-1];)o++;return[i,n-i-o,e.slice(i,r-o)]}(t,s);0!==n&&r.deleteData(e,n),r.insertData(e,i)}else r.nodeValue=s}}function Dn(t,e,n,r,i,o){wn(i,t,e);const s=o.theme.text;void 0!==s&&An(0,0,r,t,s)}function Pn(t,e){const n=document.createElement(e);return n.appendChild(t),n}class In extends Nn{static getType(){return"text"}static clone(t){return new In(t.__text,t.__key)}afterCloneFrom(t){super.afterCloneFrom(t),this.__text=t.__text,this.__format=t.__format,this.__style=t.__style,this.__mode=t.__mode,this.__detail=t.__detail}constructor(t="",e){super(e),this.__text=t,this.__format=0,this.__style="",this.__mode=0,this.__detail=0}getFormat(){return this.getLatest().__format}getDetail(){return this.getLatest().__detail}getMode(){const t=this.getLatest();return J[t.__mode]}getStyle(){return this.getLatest().__style}isToken(){return 1===this.getLatest().__mode}isComposing(){return this.__key===Ri()}isSegmented(){return 2===this.getLatest().__mode}isDirectionless(){return!!(1&this.getLatest().__detail)}isUnmergeable(){return!!(2&this.getLatest().__detail)}hasFormat(t){const e=z[t];return!!(this.getFormat()&e)}isSimpleText(){return"text"===this.__type&&0===this.__mode}getTextContent(){return this.getLatest().__text}getFormatFlags(t,e){return Di(this.getLatest().__format,t,e)}canHaveFormat(){return!0}isInline(){return!0}createDOM(t,e){const n=this.__format,r=Mn(0,n),i=On(0,n),o=null===r?i:r,s=document.createElement(o);let l=s;this.hasFormat("code")&&s.setAttribute("spellcheck","false"),null!==r&&(l=document.createElement(i),s.appendChild(l));Dn(l,this,0,n,this.__text,t);const c=this.__style;return""!==c&&(s.style.cssText=c),s}updateDOM(e,n,r){const i=this.__text,o=e.__format,s=this.__format,l=Mn(0,o),c=Mn(0,s),a=On(0,o),u=On(0,s);if((null===l?a:l)!==(null===c?u:c))return!0;if(l===c&&a!==u){const e=n.firstChild;null==e&&t(48);const o=document.createElement(u);return Dn(o,this,0,s,i,r),n.replaceChild(o,e),!1}let f=n;null!==c&&null!==l&&(f=n.firstChild,null==f&&t(49)),wn(i,f,this);const d=r.theme.text;void 0!==d&&o!==s&&An(0,o,s,f,d);const h=e.__style,g=this.__style;return h!==g&&(n.style.cssText=g),!1}static importDOM(){return{"#text":()=>({conversion:Bn,priority:0}),b:()=>({conversion:Fn,priority:0}),code:()=>({conversion:$n,priority:0}),em:()=>({conversion:$n,priority:0}),i:()=>({conversion:$n,priority:0}),mark:()=>({conversion:$n,priority:0}),s:()=>({conversion:$n,priority:0}),span:()=>({conversion:Ln,priority:0}),strong:()=>({conversion:$n,priority:0}),sub:()=>({conversion:$n,priority:0}),sup:()=>({conversion:$n,priority:0}),u:()=>({conversion:$n,priority:0})}}static importJSON(t){return Un().updateFromJSON(t)}updateFromJSON(t){return super.updateFromJSON(t).setTextContent(t.text).setFormat(t.format).setDetail(t.detail).setMode(t.mode).setStyle(t.style)}exportDOM(e){let{element:n}=super.exportDOM(e);return Io(n)||t(132),n.style.whiteSpace="pre-wrap",this.hasFormat("lowercase")?n.style.textTransform="lowercase":this.hasFormat("uppercase")?n.style.textTransform="uppercase":this.hasFormat("capitalize")&&(n.style.textTransform="capitalize"),this.hasFormat("bold")&&(n=Pn(n,"b")),this.hasFormat("italic")&&(n=Pn(n,"i")),this.hasFormat("strikethrough")&&(n=Pn(n,"s")),this.hasFormat("underline")&&(n=Pn(n,"u")),{element:n}}exportJSON(){return{detail:this.getDetail(),format:this.getFormat(),mode:this.getMode(),style:this.getStyle(),text:this.getTextContent(),...super.exportJSON()}}selectionTransform(t,e){}setFormat(t){const e=this.getWritable();return e.__format="string"==typeof t?z[t]:t,e}setDetail(t){const e=this.getWritable();return e.__detail="string"==typeof t?W[t]:t,e}setStyle(t){const e=this.getWritable();return e.__style=t,e}toggleFormat(t){const e=Di(this.getFormat(),t,null);return this.setFormat(e)}toggleDirectionless(){const t=this.getWritable();return t.__detail^=1,t}toggleUnmergeable(){const t=this.getWritable();return t.__detail^=2,t}setMode(t){const e=Y[t];if(this.__mode===e)return this;const n=this.getWritable();return n.__mode=e,n}setTextContent(t){if(this.__text===t)return this;const e=this.getWritable();return e.__text=t,e}select(t,e){Ir();let n=t,r=e;const i=pr(),o=this.getTextContent(),s=this.__key;if("string"==typeof o){const t=o.length;void 0===n&&(n=t),void 0===r&&(r=t)}else n=0,r=0;if(!tr(i))return dr(s,n,s,r,"text","text");{const t=Ri();t!==i.anchor.key&&t!==i.focus.key||Fi(s),i.setTextNodeRange(this,n,this,r)}return i}selectStart(){return this.select(0,0)}selectEnd(){const t=this.getTextContentSize();return this.select(t,t)}spliceText(t,e,n,r){const i=this.getWritable(),o=i.__text,s=n.length;let l=t;l<0&&(l=s+l,l<0&&(l=0));const c=pr();if(r&&tr(c)){const e=t+s;c.setTextNodeRange(i,e,i,e)}const a=o.slice(0,l)+n+o.slice(l+e);return i.__text=a,i}canInsertTextBefore(){return!0}canInsertTextAfter(){return!0}splitText(...t){Ir();const e=this.getLatest(),n=e.getTextContent();if(""===n)return[];const r=e.__key,i=Ri(),o=n.length;t.sort(((t,e)=>t-e)),t.push(o);const s=[],l=t.length;for(let e=0,r=0;e<o&&r<=l;r++){const i=t[r];i>e&&(s.push(n.slice(e,i)),e=i)}const c=s.length;if(1===c)return[e];const a=s[0],u=e.getParent();let f;const d=e.getFormat(),h=e.getStyle(),g=e.__detail;let _=!1,p=null,y=null;const m=pr();if(tr(m)){const[t,e]=m.isBackward()?[m.focus,m.anchor]:[m.anchor,m.focus];"text"===t.type&&t.key===r&&(p=t),"text"===e.type&&e.key===r&&(y=e)}e.isSegmented()?(f=Un(a),f.__format=d,f.__style=h,f.__detail=g,_=!0):f=e.setTextContent(a);const x=[f];for(let t=1;t<c;t++){const e=Un(s[t]);e.__format=d,e.__style=h,e.__detail=g;const n=e.__key;i===r&&Fi(n),x.push(e)}const C=p?p.offset:null,S=y?y.offset:null;let N=0;for(const t of x){if(!p&&!y)break;const e=N+t.getTextContentSize();if(null!==p&&null!==C&&C<=e&&C>=N&&(p.set(t.getKey(),C-N,"text"),C<e&&(p=null)),null!==y&&null!==S&&S<=e&&S>=N){y.set(t.getKey(),S-N,"text");break}N=e}if(null!==u){!function(t){const e=t.getPreviousSibling(),n=t.getNextSibling();null!==e&&Li(e);null!==n&&Li(n)}(this);const t=u.getWritable(),e=this.getIndexWithinParent();_?(t.splice(e,0,x),this.remove()):t.splice(e,1,x),tr(m)&&mr(m,u,e,c-1)}return x}mergeWithSibling(e){const n=e===this.getPreviousSibling();n||e===this.getNextSibling()||t(50);const r=this.__key,i=e.__key,o=this.__text,s=o.length;Ri()===i&&Fi(r);const l=pr();if(tr(l)){const t=l.anchor,o=l.focus;null!==t&&t.key===i&&Sr(t,n,r,e,s),null!==o&&o.key===i&&Sr(o,n,r,e,s)}const c=e.__text,a=n?c+o:o+c;this.setTextContent(a);const u=this.getWritable();return e.remove(),u}isTextEntity(){return!1}}function Ln(t){return{forChild:Jn(t.style),node:null}}function Fn(t){const e=t,n="normal"===e.style.fontWeight;return{forChild:Jn(e.style,n?void 0:"bold"),node:null}}const Rn=new WeakMap;function Kn(t){if(!Io(t))return!1;if("PRE"===t.nodeName)return!0;const e=t.style.whiteSpace;return"string"==typeof e&&e.startsWith("pre")}function Bn(e){const n=e;null===e.parentElement&&t(129);let r=n.textContent||"";if(null!==function(t){let e,n=t.parentNode;const r=[t];for(;null!==n&&void 0===(e=Rn.get(n))&&!Kn(n);)r.push(n),n=n.parentNode;const i=void 0===e?n:e;for(let t=0;t<r.length;t++)Rn.set(r[t],i);return i}(n)){const t=r.split(/(\r?\n|\t)/),e=[],n=t.length;for(let r=0;r<n;r++){const n=t[r];"\n"===n||"\r\n"===n?e.push(kn()):"\t"===n?e.push(jn()):""!==n&&e.push(Un(n))}return{node:e}}if(r=r.replace(/\r/g,"").replace(/[ \t\n]+/g," "),""===r)return{node:null};if(" "===r[0]){let t=n,e=!0;for(;null!==t&&null!==(t=zn(t,!1));){const n=t.textContent||"";if(n.length>0){/[ \t\n]$/.test(n)&&(r=r.slice(1)),e=!1;break}}e&&(r=r.slice(1))}if(" "===r[r.length-1]){let t=n,e=!0;for(;null!==t&&null!==(t=zn(t,!0));){if((t.textContent||"").replace(/^( |\t|\r?\n)+/,"").length>0){e=!1;break}}e&&(r=r.slice(0,r.length-1))}return""===r?{node:null}:{node:Un(r)}}function zn(t,e){let n=t;for(;;){let t;for(;null===(t=e?n.nextSibling:n.previousSibling);){const t=n.parentElement;if(null===t)return null;n=t}if(n=t,Io(n)){const t=n.style.display;if(""===t&&!Ro(n)||""!==t&&!t.startsWith("inline"))return null}let r=n;for(;null!==(r=e?n.firstChild:n.lastChild);)n=r;if(Oi(n))return n;if("BR"===n.nodeName)return null}}const Wn={code:"code",em:"italic",i:"italic",mark:"highlight",s:"strikethrough",strong:"bold",sub:"subscript",sup:"superscript",u:"underline"};function $n(t){const e=Wn[t.nodeName.toLowerCase()];return void 0===e?{node:null}:{forChild:Jn(t.style,e),node:null}}function Un(t=""){return bo(new In(t))}function Yn(t){return t instanceof In}function Jn(t,e){const n=t.fontWeight,r=t.textDecoration.split(" "),i="700"===n||"bold"===n,o=r.includes("line-through"),s="italic"===t.fontStyle,l=r.includes("underline"),c=t.verticalAlign;return t=>Yn(t)?(i&&!t.hasFormat("bold")&&t.toggleFormat("bold"),o&&!t.hasFormat("strikethrough")&&t.toggleFormat("strikethrough"),s&&!t.hasFormat("italic")&&t.toggleFormat("italic"),l&&!t.hasFormat("underline")&&t.toggleFormat("underline"),"sub"!==c||t.hasFormat("subscript")||t.toggleFormat("subscript"),"super"!==c||t.hasFormat("superscript")||t.toggleFormat("superscript"),e&&!t.hasFormat(e)&&t.toggleFormat(e),t):t}class Hn extends In{static getType(){return"tab"}static clone(t){return new Hn(t.__key)}constructor(t){super("\t",t),this.__detail=2}static importDOM(){return null}createDOM(t){const e=super.createDOM(t),n=co(t.theme,"tab");if(void 0!==n){e.classList.add(...n)}return e}static importJSON(t){return jn().updateFromJSON(t)}setTextContent(e){return"\t"!==e&&""!==e&&t(126),super.setTextContent("\t")}spliceText(e,n,r,i){return""===r&&0===n||"\t"===r&&1===n||t(286),this}setDetail(e){return 2!==e&&t(127),this}setMode(e){return"normal"!==e&&t(128),this}canInsertTextBefore(){return!1}canInsertTextAfter(){return!1}}function jn(){return bo(new Hn)}function Vn(t){return t instanceof Hn}class Gn{constructor(t,e,n){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){if(this.key===t.key)return this.offset<t.offset;return Cs(Is(ks(this,"next")),Is(ks(t,"next")))<0}getNode(){const e=Ki(this.key);return null===e&&t(20),e}set(t,e,n,r){const i=this._selection,o=this.key;r&&this.key===t&&this.offset===e&&this.type===n||(this.key=t,this.offset=e,this.type=n,Pr()||(Ri()===o&&Fi(t),null!==i&&(i.setCachedNodes(null),i.dirty=!0)))}}function qn(t,e,n){return new Gn(t,e,n)}function Xn(t,e){let n=e.__key,r=t.offset,i="element";if(Yn(e)){i="text";const t=e.getTextContentSize();r>t&&(r=t)}else if(!Zr(e)){const t=e.getNextSibling();if(Yn(t))n=t.__key,r=0,i="text";else{const t=e.getParent();t&&(n=t.__key,r=e.getIndexWithinParent()+1)}}t.set(n,r,i)}function Qn(t,e){if(Zr(e)){const n=e.getLastDescendant();Zr(n)||Yn(n)?Xn(t,n):Xn(t,e)}else Xn(t,e)}class Zn{constructor(t){this._cachedNodes=null,this._nodes=t,this.dirty=!1}getCachedNodes(){return this._cachedNodes}setCachedNodes(t){this._cachedNodes=t}is(t){if(!nr(t))return!1;const e=this._nodes,n=t._nodes;return e.size===n.size&&Array.from(e).every((t=>n.has(t)))}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 Zn(new Set(this._nodes))}extract(){return this.getNodes()}insertRawText(t){}insertText(){}insertNodes(t){const e=this.getNodes(),n=e.length,r=e[n-1];let i;if(Yn(r))i=r.select();else{const t=r.getIndexWithinParent()+1;i=r.getParentOrThrow().select(t,t)}i.insertNodes(t);for(let t=0;t<n;t++)e[t].remove()}getNodes(){const t=this._cachedNodes;if(null!==t)return t;const e=this._nodes,n=[];for(const t of e){const e=Ki(t);null!==e&&n.push(e)}return Pr()||(this._cachedNodes=n),n}getTextContent(){const t=this.getNodes();let e="";for(let n=0;n<t.length;n++)e+=t[n].getTextContent();return e}deleteNodes(){const t=this.getNodes();if((pr()||yr())===this&&t[0]){const e=ls(t[0],"next");bs(ms(e,e))}for(const e of t)e.remove()}}function tr(t){return t instanceof er}class er{constructor(t,e,n,r){this.anchor=t,this.focus=e,t._selection=this,e._selection=this,this._cachedNodes=null,this.format=n,this.style=r,this.dirty=!1}getCachedNodes(){return this._cachedNodes}setCachedNodes(t){this._cachedNodes=t}is(t){return!!tr(t)&&(this.anchor.is(t.anchor)&&this.focus.is(t.focus)&&this.format===t.format&&this.style===t.style)}isCollapsed(){return this.anchor.is(this.focus)}getNodes(){const t=this._cachedNodes;if(null!==t)return t;const e=function(t){const e=[],[n,r]=t.getTextSlices();n&&e.push(n.caret.origin);const i=new Set,o=new Set;for(const n of t)if(rs(n)){const{origin:t}=n;0===e.length?i.add(t):(o.add(t),e.push(t))}else{const{origin:t}=n;Zr(t)&&o.has(t)||e.push(t)}r&&e.push(r.caret.origin);if(ns(t.focus)&&Zr(t.focus.origin)&&null===t.focus.getNodeAtCaret())for(let n=fs(t.focus.origin,"previous");rs(n)&&i.has(n.origin)&&!n.origin.isEmpty()&&n.origin.is(e[e.length-1]);n=hs(n))i.delete(n.origin),e.pop();for(;e.length>1;){const t=e[e.length-1];if(!Zr(t)||o.has(t)||t.isEmpty()||i.has(t))break;e.pop()}if(0===e.length&&t.isCollapsed()){const n=Is(t.anchor),r=Is(t.anchor.getFlipped()),i=t=>es(t)?t.origin:t.getNodeAtCaret(),o=i(n)||i(r)||(t.anchor.getNodeAtCaret()?n.origin:r.origin);e.push(o)}return e}(Rs(Os(this),"next"));return Pr()||(this._cachedNodes=e),e}setTextNodeRange(t,e,n,r){this.anchor.set(t.__key,e,"text"),this.focus.set(n.__key,r,"text")}getTextContent(){const t=this.getNodes();if(0===t.length)return"";const e=t[0],n=t[t.length-1],r=this.anchor,i=this.focus,o=r.isBefore(i),[s,l]=ir(this);let c="",a=!0;for(let u=0;u<t.length;u++){const f=t[u];if(Zr(f)&&!f.isInline())a||(c+="\n"),a=!f.isEmpty();else if(a=!1,Yn(f)){let t=f.getTextContent();f===e?f===n?"element"===r.type&&"element"===i.type&&i.offset!==r.offset||(t=s<l?t.slice(s,l):t.slice(l,s)):t=o?t.slice(s):t.slice(l):f===n&&(t=o?t.slice(0,l):t.slice(0,s)),c+=t}else!ni(f)&&!En(f)||f===n&&this.isCollapsed()||(c+=f.getTextContent())}return c}applyDOMRange(t){const e=Rr(),n=e.getEditorState()._selection,r=fr(t.startContainer,t.startOffset,t.endContainer,t.endOffset,e,n);if(null===r)return;const[i,o]=r;this.anchor.set(i.key,i.offset,i.type,!0),this.focus.set(o.key,o.offset,o.type,!0),gt(this)}clone(){const t=this.anchor,e=this.focus;return new er(qn(t.key,t.offset,t.type),qn(e.key,e.offset,e.type),this.format,this.style)}toggleFormat(t){this.format=Di(this.format,t,null),this.dirty=!0}setStyle(t){this.style=t,this.dirty=!0}hasFormat(t){const e=z[t];return!!(this.format&e)}insertRawText(t){const e=t.split(/(\r?\n|\t)/),n=[],r=e.length;for(let t=0;t<r;t++){const r=e[t];"\n"===r||"\r\n"===r?n.push(kn()):"\t"===r?n.push(jn()):n.push(Un(r))}this.insertNodes(n)}insertText(e){const n=this.anchor,r=this.focus,i=this.format,o=this.style;let s=n,l=r;!this.isCollapsed()&&r.isBefore(n)&&(s=r,l=n),"element"===s.type&&function(t,e,n,r){const i=t.getNode(),o=i.getChildAtI