lexical
Version:
Lexical is an extensible text editor framework that provides excellent reliability, accessible and performance.
9 lines (8 loc) • 129 kB
JavaScript
/**
* 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,p=9,_=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,O=2,M=3,A=4,w=5,D=6,P=s||l||f?" ":"",I="\n\n",L=i?" ":P,F={bold:1,capitalize:1024,code:16,highlight:k,italic:2,lowercase:256,strikethrough:T,subscript:32,superscript:64,underline:v,uppercase:512},R={directionless:1,unmergeable:2},K={center:O,end:D,justify:A,left:b,right:M,start:w},B={[O]:"center",[D]:"end",[A]:"justify",[b]:"left",[M]:"right",[w]:"start"},z={normal:0,segmented:2,token:1},W={[C]:"normal",[N]:"segmented",[S]:"token"},$="$config";function U(t,e,n,r,i,o){let s=t.getFirstChild();for(;null!==s;){const t=s.__key;s.__parent===e&&(Qr(s)&&U(s,t,n,r,i,o),n.has(t)||o.delete(t),i.push(t)),s=s.getNextSibling()}}const J=100;let Y=!1,j=0;function H(t){j=t.timeStamp}function V(t,e,n){const r="BR"===t.nodeName,i=e.__lexicalLineBreak;return i&&(t===i||r&&t.previousSibling===i)||r&&void 0!==Ji(t,n)}function G(t,e,n){const r=Fo(bo(n));let i=null,o=null;null!==r&&r.anchorNode===t&&(i=r.anchorOffset,o=r.focusOffset);const s=t.nodeValue;null!==s&&ro(e,s,i,o,!1)}function q(t,e,n){if(Zn(t)){const e=t.anchor.getNode();if(e.is(n)&&t.format!==e.getFormat())return!1}return Pi(e)&&n.isAttached()}function X(t,e,n,r){for(let i=t;i&&!Xo(i);i=So(i)){const t=Ji(i,e);if(void 0!==t){const e=$i(t,n);if(e)return ei(e)||!Ko(i)?void 0:[i,e]}else if(i===r)return[r,Gi(n)]}}function Q(t,e,n){Y=!0;const r=performance.now()-j>J;try{Vr(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,p=X(g,t,c,l);if(!p)continue;const[_,y]=p;if("characterData"===h)r&&Un(y)&&Pi(g)&&q(o,g,y)&&G(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=Ui(r),s=r.parentNode;if(null!=s&&r!==a&&null===o&&!V(r,s,t)){if(i){const t=(Ko(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];(V(r,g,t)||a===r)&&(g.appendChild(r),e++)}r!==e&&s.set(_,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||V(n,i,t)||o.removeChild(n)}}n.takeRecords()}null!==o&&(u&&qi(o),i&&yo(t)&&o.insertRawText(f))}))}finally{Y=!1}}function Z(t){const e=t._observer;if(null!==e){Q(t,e.takeRecords(),e)}}function tt(t){!function(t){0===j&&bo(t).addEventListener("textInput",H,!0)}(t),t._observer=new MutationObserver(((e,n)=>{Q(t,e,n)}))}class et{constructor(t,e){this.key=t,this.parse=e.parse.bind(e),this.unparse=(e.unparse||ct).bind(e),this.isEqual=(e.isEqual||Object.is).bind(e),this.defaultValue=this.parse(void 0)}}function nt(t,e,n="latest"){const r=("latest"===n?t.getLatest():t).__state;return r?r.getValue(e):e.defaultValue}function rt(t){const e=new Map,n=new Set;for(let r="function"==typeof t?t:t.replace;r.prototype&&void 0!==r.prototype.getType;r=Object.getPrototypeOf(r)){const{ownNodeConfig:t}=Zo(r);if(t&&t.stateConfigs)for(const r of t.stateConfigs){let t;"stateConfig"in r?(t=r.stateConfig,r.flat&&n.add(t.key)):t=r,e.set(t.key,t)}}return{flatKeys:n,sharedConfigMap:e}}class it{constructor(t,e,n=void 0,r=new Map,i=void 0){this.node=t,this.sharedNodeState=e,this.unknownState=n,this.knownState=r;const{sharedConfigMap:o}=this.sharedNodeState,s=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}(o,n,r);this.size=s}getValue(t){const e=this.knownState.get(t);if(void 0!==e)return e;this.sharedNodeState.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},e={};for(const[e,n]of this.knownState)e.isEqual(n,e.defaultValue)?delete t[e.key]:t[e.key]=e.unparse(n);for(const n of this.sharedNodeState.flatKeys)n in t&&(e[n]=t[n],delete t[n]);return lt(t)&&(e.$=t),e}getWritable(t){if(this.node===t)return this;const{sharedNodeState:e,unknownState:n}=this,r=new Map(this.knownState);return new it(t,e,function(t,e,n){let r;if(n)for(const[i,o]of Object.entries(n)){const n=t.get(i);n?e.has(n)||e.set(n,n.parse(o)):(r=r||{},r[i]=o)}return r}(e.sharedConfigMap,r,n),r,this.size)}updateFromKnown(t,e){const n=t.key;this.sharedNodeState.sharedConfigMap.set(n,t);const{knownState:r,unknownState:i}=this;r.has(t)||i&&n in i||(i&&(delete i[n],this.unknownState=lt(i)),this.size++),r.set(t,e)}updateFromUnknown(t,e){const n=this.sharedNodeState.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=void 0,t)for(const[e,n]of Object.entries(t))this.updateFromUnknown(e,n)}}function ot(t){const e=t.getWritable(),n=e.__state?e.__state.getWritable(e):new it(e,st(e));return e.__state=n,n}function st(t){return t.__state?t.__state.sharedNodeState:Ni(Yo(),t.getType()).sharedNodeState}function lt(t){if(t)for(const e in t)return t}function ct(t){return t}function at(t,e,n){for(const[r,i]of e.knownState){if(t.has(r.key))continue;t.add(r.key);const e=n?n.getValue(r):r.defaultValue;if(e!==i&&!r.isEqual(e,i))return!0}return!1}function ut(t,e,n){const{unknownState:r}=e,i=n?n.unknownState:void 0;if(r)for(const[e,n]of Object.entries(r)){if(t.has(e))continue;t.add(e);if(n!==(i?i[e]:void 0))return!0}return!1}function ft(t,e){const n=t.__state;return n&&n.node===t?n.getWritable(e):n}function dt(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;return!(t&&at(n,t,e)||e&&at(n,e,t)||t&&ut(n,t,e)||e&&ut(n,e,t))}(c,a))}function ht(t,e){const n=t.mergeWithSibling(e),r=Fr()._normalizedNodes;return r.add(t.__key),r.add(e.__key),n}function gt(t){let e,n,r=t;if(""!==r.__text||!r.isSimpleText()||r.isUnmergeable()){for(;null!==(e=r.getPreviousSibling())&&Un(e)&&e.isSimpleText()&&!e.isUnmergeable();){if(""!==e.__text){if(dt(e,r)){r=ht(e,r);break}break}e.remove()}for(;null!==(n=r.getNextSibling())&&Un(n)&&n.isSimpleText()&&!n.isUnmergeable();){if(""!==n.__text){if(dt(r,n)){r=ht(r,n);break}break}n.remove()}}else r.remove()}function pt(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),Un(r)){t.set(r.__key,i?r.getTextContentSize():0,"text",!0);break}if(!Qr(r))break;t.set(r.__key,i?r.getChildrenSize():0,"element",!0)}}let yt,mt,xt,Ct,St,Nt,Tt,vt,kt,Et,bt="",Ot=null,Mt="",At="",wt=!1,Dt=!1;function Pt(t,e){const n=Tt.get(t);if(null!==e){const n=qt(t);n.parentNode===e&&e.removeChild(n)}if(vt.has(t)||mt._keyToDOMMap.delete(t),Qr(n)){const t=Yt(n,Tt);It(t,0,t.length-1,null)}void 0!==n&&go(Et,xt,Ct,n,"destroyed")}function It(t,e,n,r){let i=e;for(;i<=n;++i){const e=t[i];void 0!==e&&Pt(e,r)}}function Lt(t,e){t.setProperty("text-align",e)}const Ft="40px";function Rt(t,e){const n=yt.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")||Ft;t.style.setProperty("padding-inline-start",0===e?"":`calc(${e} * ${r})`)}function Kt(t,e){const n=t.style;0===e?Lt(n,""):e===b?Lt(n,"left"):e===O?Lt(n,"center"):e===M?Lt(n,"right"):e===A?Lt(n,"justify"):e===w?Lt(n,"start"):e===D&&Lt(n,"end")}function Bt(t,e){const n=function(t){const e=t.__dir;if(null!==e)return e;if(ri(t))return null;const n=t.getParentOrThrow();return ri(n)&&null===n.__dir?"auto":null}(e);null!==n?t.dir=n:t.removeAttribute("dir")}function zt(e,n){const r=vt.get(e);void 0===r&&t(60);const i=r.createDOM(yt,mt);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,mt),Un(r)?i.setAttribute("data-lexical-text","true"):ei(r)&&i.setAttribute("data-lexical-decorator","true"),Qr(r)){const t=r.__indent,e=r.__size;if(Bt(i,r),0!==t&&Rt(i,t),0!==e){const t=e-1;Wt(Yt(r,vt),r,0,t,r.getDOMSlot(i))}const n=r.__format;0!==n&&Kt(i,n),r.isInline()||Ut(null,r,i),xo(r)&&(bt+=I,At+=I)}else{const t=r.getTextContent();if(ei(r)){const t=r.decorate(mt,yt);null!==t&&Ht(e,t),i.contentEditable="false"}bt+=t,At+=t}return null!==n&&n.insertChild(i),go(Et,xt,Ct,r,"created"),i}function Wt(t,e,n,r,i){const o=bt;bt="";let s=n;for(;s<=r;++s){zt(t[s],i);const e=vt.get(t[s]);null!==e&&Un(e)&&(null===Ot&&(Ot=e.getFormat()),""===Mt&&(Mt=e.getStyle()))}xo(e)&&(bt+=I);i.element.__lexicalTextContent=bt,bt=o+bt}function $t(t,e){if(t){const n=t.__last;if(n){const t=e.get(n);if(t)return kn(t)?"line-break":ei(t)&&t.isInline()?"decorator":null}return"empty"}return null}function Ut(t,e,n){const r=$t(t,Tt),i=$t(e,vt);r!==i&&e.getDOMSlot(n).setManagedLineBreak(i)}function Jt(e,n,r){var i;Ot=null,Mt="",function(e,n,r){const i=bt,o=e.__size,s=n.__size;bt="";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=qt(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}Pt(t,null)}const i=vt.get(r);Un(i)&&(null===Ot&&(Ot=i.getFormat()),""===Mt&&(Mt=i.getStyle()))}else{const i=Yt(e,Tt),c=Yt(n,vt);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;It(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=Vt(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=Co(mt,r);t===u?u=Vt(jt(r,o.element)):(o.withBefore(u).insertChild(t),jt(r,o.element)),f++,d++}else zt(r,o.withBefore(u)),d++;else u=Vt(qt(t)),Pt(t,o.element),f++}const i=vt.get(r);null!==i&&Un(i)&&(null===Ot&&(Ot=i.getFormat()),""===Mt&&(Mt=i.getStyle()))}const h=f>s,g=d>l;if(h&&!g){const e=n[l+1],r=void 0===e?null:mt.getElementByKey(e);Wt(n,t,d,l,o.withBefore(r))}else g&&!h&&It(e,f,s,o.element)}(n,i,c,o,s,r)}xo(n)&&(bt+=I);l.__lexicalTextContent=bt,bt=i+bt}(e,n,n.getDOMSlot(r)),i=n,null==Ot||Ot===i.__textFormat||Dt||i.setTextFormat(Ot),function(t){""===Mt||Mt===t.__textStyle||Dt||t.setTextStyle(Mt)}(n)}function Yt(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=Tt.get(e);let i=vt.get(e);void 0!==r&&void 0!==i||t(61);const o=wt||Nt.has(e)||St.has(e),s=Co(mt,e);if(r===i&&!o){if(Qr(r)){const t=s.__lexicalTextContent;void 0!==t&&(bt+=t,At+=t)}else{const t=r.getTextContent();At+=t,bt+=t}return s}if(r!==i&&o&&go(Et,xt,Ct,i,"updated"),i.updateDOM(r,s,yt)){const r=zt(e,null);return null===n&&t(62),n.replaceChild(r,s),Pt(e,null),r}if(Qr(r)&&Qr(i)){const t=i.__indent;(wt||t!==r.__indent)&&Rt(s,t);const e=i.__format;if((wt||e!==r.__format)&&Kt(s,e),o&&(Jt(r,i,s),ri(i)||i.isInline()||Ut(r,i,s)),xo(i)&&(bt+=I,At+=I),(wt||i.__dir!==r.__dir)&&(Bt(s,i),ri(i)&&!wt))for(const t of i.getChildren())if(Qr(t)){Bt(Co(mt,t.getKey()),t)}}else{const t=i.getTextContent();if(ei(i)){const t=i.decorate(mt,yt);null!==t&&Ht(e,t)}bt+=t,At+=t}if(!Dt&&ri(i)&&i.__cachedText!==At){const t=i.getWritable();t.__cachedText=At,i=t}return s}function Ht(t,e){let n=mt._pendingDecorators;const r=mt._decorators;if(null===n){if(r[t]===e)return;n=ji(mt)}n[t]=e}function Vt(t){let e=t.nextSibling;return null!==e&&e===mt._blockCursorElement&&(e=e.nextSibling),e}function Gt(t,e,n,r,i,o){bt="",At="",wt=r===x,mt=n,yt=n._config,xt=n._nodes,Ct=mt._listeners.mutation,St=i,Nt=o,Tt=t._nodeMap,vt=e._nodeMap,Dt=e._readOnly,kt=new Map(n._keyToDOMMap);const s=new Map;return Et=s,jt("root",null),mt=void 0,xt=void 0,St=void 0,Nt=void 0,Tt=void 0,vt=void 0,yt=void 0,kt=void 0,Et=void 0,s}function qt(e){const n=kt.get(e);return void 0===n&&t(75,e),n}function Xt(t){return{type:t}}const Qt=Xt("SELECTION_CHANGE_COMMAND"),Zt=Xt("SELECTION_INSERT_CLIPBOARD_NODES_COMMAND"),te=Xt("CLICK_COMMAND"),ee=Xt("DELETE_CHARACTER_COMMAND"),ne=Xt("INSERT_LINE_BREAK_COMMAND"),re=Xt("INSERT_PARAGRAPH_COMMAND"),ie=Xt("CONTROLLED_TEXT_INSERTION_COMMAND"),oe=Xt("PASTE_COMMAND"),se=Xt("REMOVE_TEXT_COMMAND"),le=Xt("DELETE_WORD_COMMAND"),ce=Xt("DELETE_LINE_COMMAND"),ae=Xt("FORMAT_TEXT_COMMAND"),ue=Xt("UNDO_COMMAND"),fe=Xt("REDO_COMMAND"),de=Xt("KEYDOWN_COMMAND"),he=Xt("KEY_ARROW_RIGHT_COMMAND"),ge=Xt("MOVE_TO_END"),pe=Xt("KEY_ARROW_LEFT_COMMAND"),_e=Xt("MOVE_TO_START"),ye=Xt("KEY_ARROW_UP_COMMAND"),me=Xt("KEY_ARROW_DOWN_COMMAND"),xe=Xt("KEY_ENTER_COMMAND"),Ce=Xt("KEY_SPACE_COMMAND"),Se=Xt("KEY_BACKSPACE_COMMAND"),Ne=Xt("KEY_ESCAPE_COMMAND"),Te=Xt("KEY_DELETE_COMMAND"),ve=Xt("KEY_TAB_COMMAND"),ke=Xt("INSERT_TAB_COMMAND"),Ee=Xt("INDENT_CONTENT_COMMAND"),be=Xt("OUTDENT_CONTENT_COMMAND"),Oe=Xt("DROP_COMMAND"),Me=Xt("FORMAT_ELEMENT_COMMAND"),Ae=Xt("DRAGSTART_COMMAND"),we=Xt("DRAGOVER_COMMAND"),De=Xt("DRAGEND_COMMAND"),Pe=Xt("COPY_COMMAND"),Ie=Xt("CUT_COMMAND"),Le=Xt("SELECT_ALL_COMMAND"),Fe=Xt("CLEAR_EDITOR_COMMAND"),Re=Xt("CLEAR_HISTORY_COMMAND"),Ke=Xt("CAN_REDO_COMMAND"),Be=Xt("CAN_UNDO_COMMAND"),ze=Xt("FOCUS_COMMAND"),We=Xt("BLUR_COMMAND"),$e=Xt("KEY_MODIFIER_COMMAND"),Ue=Object.freeze({}),Je=30,Ye=[["keydown",function(t,e){if(je=t.timeStamp,He=t.key,e.isComposing())return;if(mo(e,de,t))return;if(null==t.key)return;if(en&&uo(t))return Vr(e,(()=>{dn(e,nn)})),en=!1,void(nn="");if(function(t){return lo(t,"ArrowRight",{shiftKey:"any"})}(t))mo(e,he,t);else if(function(t){return lo(t,"ArrowRight",co)}(t))mo(e,ge,t);else if(function(t){return lo(t,"ArrowLeft",{shiftKey:"any"})}(t))mo(e,pe,t);else if(function(t){return lo(t,"ArrowLeft",co)}(t))mo(e,_e,t);else if(function(t){return lo(t,"ArrowUp",{altKey:"any",shiftKey:"any"})}(t))mo(e,ye,t);else if(function(t){return lo(t,"ArrowDown",{altKey:"any",shiftKey:"any"})}(t))mo(e,me,t);else if(function(t){return lo(t,"Enter",{altKey:"any",ctrlKey:"any",metaKey:"any",shiftKey:!0})}(t))Ze=!0,mo(e,xe,t);else if(function(t){return" "===t.key}(t))mo(e,Ce,t);else if(function(t){return r&&lo(t,"o",{ctrlKey:!0})}(t))t.preventDefault(),Ze=!0,mo(e,ne,!0);else if(function(t){return lo(t,"Enter",{altKey:"any",ctrlKey:"any",metaKey:"any"})}(t))Ze=!1,mo(e,xe,t);else if(function(t){return lo(t,"Backspace",{shiftKey:"any"})||r&&lo(t,"h",{ctrlKey:!0})}(t))uo(t)?mo(e,Se,t):(t.preventDefault(),mo(e,ee,!0));else if(function(t){return"Escape"===t.key}(t))mo(e,Ne,t);else if(function(t){return lo(t,"Delete",{})||r&&lo(t,"d",{ctrlKey:!0})}(t))!function(t){return"Delete"===t.key}(t)?(t.preventDefault(),mo(e,ee,!1)):mo(e,Te,t);else if(function(t){return lo(t,"Backspace",ao)}(t))t.preventDefault(),mo(e,le,!0);else if(function(t){return lo(t,"Delete",ao)}(t))t.preventDefault(),mo(e,le,!1);else if(function(t){return r&&lo(t,"Backspace",{metaKey:!0})}(t))t.preventDefault(),mo(e,ce,!0);else if(function(t){return r&&(lo(t,"Delete",{metaKey:!0})||lo(t,"k",{ctrlKey:!0}))}(t))t.preventDefault(),mo(e,ce,!1);else if(function(t){return lo(t,"b",co)}(t))t.preventDefault(),mo(e,ae,"bold");else if(function(t){return lo(t,"u",co)}(t))t.preventDefault(),mo(e,ae,"underline");else if(function(t){return lo(t,"i",co)}(t))t.preventDefault(),mo(e,ae,"italic");else if(function(t){return lo(t,"Tab",{shiftKey:"any"})}(t))mo(e,ve,t);else if(function(t){return lo(t,"z",co)}(t))t.preventDefault(),mo(e,ue,void 0);else if(function(t){if(r)return lo(t,"z",{metaKey:!0,shiftKey:!0});return lo(t,"y",{ctrlKey:!0})||lo(t,"z",{ctrlKey:!0,shiftKey:!0})}(t))t.preventDefault(),mo(e,fe,void 0);else{const n=e._editorState._selection;null===n||Zn(n)?fo(t)&&(t.preventDefault(),mo(e,Le,t)):!function(t){return lo(t,"c",co)}(t)?!function(t){return lo(t,"x",co)}(t)?fo(t)&&(t.preventDefault(),mo(e,Le,t)):(t.preventDefault(),mo(e,Ie,t)):(t.preventDefault(),mo(e,Pe,t))}(function(t){return t.ctrlKey||t.shiftKey||t.altKey||t.metaKey})(t)&&mo(e,$e,t)}],["pointerdown",function(t,e){const n=t.target,r=t.pointerType;Bo(n)&&"touch"!==r&&"pen"!==r&&0===t.button&&Vr(e,(()=>{ki(n)||(Qe=!0)}))}],["compositionstart",function(t,e){Vr(e,(()=>{const n=pr();if(Zn(n)&&!e.isComposing()){const r=n.anchor,i=n.anchor.getNode();zi(r.key),(t.timeStamp<je+Je||"element"===r.type||!n.isCollapsed()||i.getFormat()!==n.format||Un(i)&&i.getStyle()!==n.style)&&mo(e,ie,L)}}))}],["compositionend",function(t,e){i?tn=!0:l||!s&&!f?Vr(e,(()=>{dn(e,t.data)})):(en=!0,nn=t.data)}],["input",function(t,e){t.stopPropagation(),Vr(e,(()=>{if(Ko(t.target)&&ki(t.target))return;const n=pr(),r=t.data,c=fn(t);if(null!=r&&Zn(n)&&sn(n,c,r,t.timeStamp,!1)){tn&&(dn(e,r),tn=!1);const c=n.anchor.getNode(),a=Fo(bo(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()&&Un(c)&&null!==a.anchorNode&&c.getTextContent().slice(0,d)+r+c.getTextContent().slice(d+h)===eo(a.anchorNode)||mo(e,ie,r);const g=r.length;i&&g>1&&"insertCompositionText"===t.inputType&&!e.isComposing()&&(n.anchor.offset-=g),s||l||f||!e.isComposing()||(je=0,zi(null))}else{no(!1,e,null!==r?r:void 0),tn&&(dn(e,r||void 0),tn=!1)}!function(){Pr();const t=Fr();Z(t)}()}),{event:t}),Ge=null}],["click",function(t,e){Vr(e,(()=>{const n=pr(),r=Fo(bo(e)),i=_r();if(r)if(Zn(n)){const e=n.anchor,o=e.getNode();if("element"===e.type&&0===e.offset&&n.isCollapsed()&&!ri(o)&&1===Vi().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!==Vi()&&null!=n;){if(e(n))return n;n=n.getParent()}return null}(o,(t=>Qr(t)&&!t.isInline()));Qr(t)&&t.select(0)}}}else if("touch"===t.pointerType||"pen"===t.pointerType){const n=r.anchorNode;if(Ko(n)||Pi(n)){qi(gr(i,r,e,t))}}mo(e,te,t)}))}],["cut",Ue],["copy",Ue],["dragstart",Ue],["dragover",Ue],["dragend",Ue],["paste",Ue],["focus",Ue],["blur",Ue],["drop",Ue]];o&&Ye.push(["beforeinput",(e,n)=>function(e,n){const r=e.inputType,o=fn(e);if("deleteCompositionText"===r||i&&yo(n))return;if("insertCompositionText"===r)return;Vr(n,(()=>{const i=pr();if("deleteContentBackward"===r){if(null===i){const t=_r();if(!Zn(t))return;qi(t.clone())}if(Zn(i)){const r=i.anchor.key===i.focus.key;if(s=e.timeStamp,"MediaLast"===He&&s<je+Je&&n.isComposing()&&r){if(zi(null),je=0,setTimeout((()=>{Vr(n,(()=>{zi(null)}))}),Je),Zn(i)){const e=i.anchor.getNode();e.markDirty(),Un(e)||t(142),un(i,e)}}else{zi(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=!ei(_o(i.anchor,!0))),!c){mo(n,ee,!0);const t=pr();u&&Zn(t)&&t.isCollapsed()&&(rn=t,setTimeout((()=>rn=null)))}}return}}var s;if(!Zn(i))return;const c=e.data;null!==Ge&&no(!1,n,Ge),i.dirty&&null===Ge||!i.isCollapsed()||ri(i.anchor.getNode())||null===o||i.applyDOMRange(o),Ge=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":mo(n,ie,e);break;case"insertFromComposition":zi(null),mo(n,ie,e);break;case"insertLineBreak":zi(null),mo(n,ne,!1);break;case"insertParagraph":zi(null),Ze&&!l?(Ze=!1,mo(n,ne,!1)):mo(n,re,void 0);break;case"insertFromPaste":case"insertFromPasteAsQuotation":mo(n,oe,e);break;case"deleteByComposition":(function(t,e){return t!==e||Qr(t)||Qr(e)||!wi(t)||!wi(e)})(d,h)&&mo(n,se,e);break;case"deleteByDrag":case"deleteByCut":mo(n,se,e);break;case"deleteContent":mo(n,ee,!1);break;case"deleteWordBackward":mo(n,le,!0);break;case"deleteWordForward":mo(n,le,!1);break;case"deleteHardLineBackward":case"deleteSoftLineBackward":mo(n,ce,!0);break;case"deleteContentForward":case"deleteHardLineForward":case"deleteSoftLineForward":mo(n,ce,!1);break;case"formatStrikeThrough":mo(n,ae,"strikethrough");break;case"formatBold":mo(n,ae,"bold");break;case"formatItalic":mo(n,ae,"italic");break;case"formatUnderline":mo(n,ae,"underline");break;case"historyUndo":mo(n,ue,void 0);break;case"historyRedo":mo(n,fe,void 0)}else{if("\n"===c)e.preventDefault(),mo(n,ne,!1);else if(c===I)e.preventDefault(),mo(n,re,void 0);else if(null==c&&e.dataTransfer){const t=e.dataTransfer.getData("text/plain");e.preventDefault(),i.insertRawText(t)}else null!=c&&sn(i,o,c,e.timeStamp,!0)?(e.preventDefault(),mo(n,ie,c)):Ge=c;Ve=e.timeStamp}}))}(e,n)]);let je=0,He=null,Ve=0,Ge=null;const qe=new WeakMap;let Xe=!1,Qe=!1,Ze=!1,tn=!1,en=!1,nn="",rn=null,on=[0,"",0,"root",0];function sn(t,e,n,r,i){const s=t.anchor,l=t.focus,c=s.getNode(),a=Fr(),u=Fo(bo(a)),f=null!==u?u.anchorNode:null,d=s.key,h=a.getElementByKey(d),g=n.length;return d!==l.key||!Un(c)||(!i&&(!o||Ve<r+50)||c.isDirty()&&g<2||Qi(n))&&s.offset!==l.offset&&!c.isComposing()||Di(c)||c.isDirty()&&g>1||(i||!o)&&null!==h&&!c.isComposing()&&f!==Li(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=wi(e);return 0===n?!e.canInsertTextBefore()||!r.canInsertTextBefore()&&!e.isComposing()||i||function(t){const e=t.getPreviousSibling();return(Un(e)||Qr(e)&&e.isInline())&&!e.canInsertTextAfter()}(e):n===e.getTextContentSize()&&(!e.canInsertTextAfter()||!r.canInsertTextAfter()&&!e.isComposing()||i)}(t,c)}function ln(t,e){return Pi(t)&&null!==t.nodeValue&&0!==e&&e!==t.nodeValue.length}function cn(e,n,r){const{anchorNode:i,anchorOffset:o,focusNode:s,focusOffset:l}=e;Xe&&(Xe=!1,ln(i,o)&&ln(s,l)&&!rn)||Vr(n,(()=>{if(!r)return void qi(null);if(!bi(n,i,s))return;let c=pr();if(rn&&Zn(c)&&c.isCollapsed()){const t=c.anchor,e=rn.anchor;(t.key===e.key&&t.offset===e.offset+1||1===t.offset&&e.getNode().is(t.getNode().getPreviousSibling()))&&(c=rn.clone(),qi(c))}if(rn=null,Zn(c)){const r=c.anchor,i=r.getNode();if(c.isCollapsed()){"Range"===e.type&&e.anchorNode===e.focusNode&&(c.dirty=!0);const o=bo(n).event,s=o?o.timeStamp:performance.now(),[l,a,u,f,d]=on,h=Vi(),g=!1===n.isComposing()&&""===h.getTextContent();if(s<d+200&&r.offset===u&&r.key===f)an(c,l,a);else if("text"===r.type)Un(i)||t(141),un(c,i);else if("element"===r.type&&!g){Qr(i)||t(259);const e=r.getNode();e.isEmpty()?function(t,e){const n=e.getTextFormat(),r=e.getTextStyle();an(t,n,r)}(c,e):an(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(Un(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}}mo(n,Qt,void 0)}))}function an(t,e,n){t.format===e&&t.style===n||(t.format=e,t.style=n,t.dirty=!0)}function un(t,e){an(t,e.getFormat(),e.getStyle())}function fn(t){if(!t.getTargetRanges)return null;const e=t.getTargetRanges();return 0===e.length?null:e[0]}function dn(t,e){const n=t._compositionKey;if(zi(null),null!==n&&null!=e){if(""===e){const e=$i(n),r=Li(t.getElementByKey(n));return void(null!==r&&null!==r.nodeValue&&Un(e)&&ro(e,r.nodeValue,null,null,!0))}if("\n"===e[e.length-1]){const e=pr();if(Zn(e)){const n=e.focus;return e.anchor.set(n.key,n.offset,n.type),void mo(t,xe,null)}}}no(!0,t,e)}function hn(t){let e=t.__lexicalEventHandles;return void 0===e&&(e=[],t.__lexicalEventHandles=e),e}const gn=new Map;function pn(t){const e=Ro(t.target);if(null===e)return;const n=Mi(e.anchorNode);if(null===n)return;Qe&&(Qe=!1,Vr(n,(()=>{const r=_r(),i=e.anchorNode;if(Ko(i)||Pi(i)){qi(gr(r,e,n,t))}})));const r=Zi(n),i=r[r.length-1],o=i._key,s=gn.get(o),l=s||i;l!==n&&cn(e,l,!1),cn(e,n,!0),n!==i?gn.set(o,n):s&&gn.delete(o)}function _n(t){t._lexicalHandled=!0}function yn(t){return!0===t._lexicalHandled}const mn=()=>{};function xn(e){const n=e.ownerDocument,r=qe.get(n);if(void 0===r)return void mn();const i=r-1;i>=0||t(164),qe.set(n,i),0===i&&n.removeEventListener("selectionchange",pn);const o=Ai(e);Oi(o)?(!function(t){if(null!==t._parentEditor){const e=Zi(t),n=e[e.length-1]._key;gn.get(n)===t&&gn.delete(n)}else gn.delete(t._key)}(o),e.__lexicalEditor=null):o&&t(198);const s=hn(e);for(let t=0;t<s.length;t++)s[t]();e.__lexicalEventHandles=[]}function Cn(t,e,n){Pr();const r=t.__key,i=t.getParent();if(null===i)return;const o=function(t){const e=pr();if(!Zn(e)||!Qr(t))return e;const{anchor:n,focus:r}=e,i=n.getNode(),o=r.getNode();ko(i,t)&&n.set(t.__key,0,"element");ko(o,t)&&r.set(t.__key,0,"element");return e}(t);let s=!1;if(Zn(o)&&e){const e=o.anchor,n=o.focus;e.key===r&&(xr(e,t,i,t.getPreviousSibling(),t.getNextSibling()),s=!0),n.key===r&&(xr(n,t,i,t.getPreviousSibling(),t.getNextSibling()),s=!0)}else er(o)&&e&&t.isSelected()&&t.selectPrevious();if(Zn(o)&&e&&!s){const e=t.getIndexWithinParent();Ki(t),yr(o,i,e,-1)}else Ki(t);n||Mo(i)||i.canBeEmpty()||!i.isEmpty()||Cn(i,e),e&&o&&ri(i)&&i.isEmpty()&&i.selectEnd()}class Sn{static getType(){const{ownNodeType:e}=Zo(this);return void 0===e&&t(64,this.name),e}static clone(e){t(65,this.name)}$config(){return{}}config(t,e){const n=e.extends||Object.getPrototypeOf(this.constructor);return Object.assign(e,{extends:n,type:t}),{[t]:e}}afterCloneFrom(t){this.__key===t.__key?(this.__parent=t.__parent,this.__next=t.__next,this.__prev=t.__prev,this.__state=t.__state):t.__state&&(this.__state=t.__state.getWritable(this))}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}),Ri(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=$i(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(Un(this))return n;if(Zn(e)&&"element"===e.anchor.type&&"element"===e.focus.type){if(e.isCollapsed())return!1;const t=this.getParent();if(ei(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:$i(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(Mo(n))return Qr(e)||e===this&&ei(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:$i(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:$i(t)}getNextSiblings(){const t=[];let e=this.getNextSibling();for(;null!==e;)t.push(e),e=e.getNextSibling();return t}getCommonAncestor(t){const e=Qr(this)?this:this.getParent(),n=Qr(t)?t:t.getParent(),r=e&&n?ws(e,n):null;return r?r.commonAncestor:null}is(t){return null!=t&&this.__key===t.__key}isBefore(e){const n=ws(this,e);return null!==n&&("descendant"===n.type||("branch"===n.type?-1===Os(n):("same"!==n.type&&"ancestor"!==n.type&&t(279),!1)))}isParentOf(t){const e=ws(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=Qr(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=Fr()._dirtyLeaves;return null!==t&&t.has(this.__key)}getLatest(){const e=$i(this.__key);return null===e&&t(113),e}getWritable(){Pr();const t=Lr(),e=Fr(),n=t._nodeMap,r=this.__key,i=this.getLatest(),o=e._cloneNotNeeded,s=pr();if(null!==s&&s.setCachedNodes(null),o.has(r))return Bi(i),i;const l=Go(i);return o.add(r),Bi(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(),r=e.$;let i=r;for(const t of st(n).flatKeys)t in e&&(void 0!==i&&i!==r||(i={...r}),i[t]=e[t]);return(n.__state||i)&&ot(t).updateFromJSON(i),n}(this,t)}static transform(){return null}remove(t){Cn(this,!0,t)}replace(e,n){Pr();let r=pr();null!==r&&(r=r.clone()),Do(this,e);const i=this.getLatest(),o=this.__key,s=e.__key,l=e.getWritable(),c=this.getParentOrThrow().getWritable(),a=c.__size;Ki(l);const u=i.getPreviousSibling(),f=i.getNextSibling(),d=i.__prev,h=i.__next,g=i.__parent;if(Cn(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&&(Qr(this)&&Qr(l)||t(139),this.getChildren().forEach((t=>{l.append(t)}))),Zn(r)){qi(r);const t=r.anchor,e=r.focus;t.key===o&&Xn(t,l),e.key===o&&Xn(e,l)}return Wi()===o&&zi(s),l}insertAfter(t,e=!0){Pr(),Do(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(Ki(r),Zn(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&&Zn(o)){const t=this.getIndexWithinParent();yr(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){Pr(),Do(this,t);const n=this.getWritable(),r=t.getWritable(),i=r.__key;Ki(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&&Zn(a)){yr(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){Pr();const n=this.getPreviousSibling(),r=this.getParentOrThrow();if(null===n)return r.select(0,0);if(Qr(n))return n.select();if(!Un(n)){const t=n.getIndexWithinParent()+1;return r.select(t,t)}return n.select(t,e)}selectNext(t,e){Pr();const n=this.getNextSibling(),r=this.getParentOrThrow();if(null===n)return r.select();if(Qr(n))return n.select(0,0);if(!Un(n)){const t=n.getIndexWithinParent();return r.select(t,t)}return n.select(t,e)}markDirty(){this.getWritable()}reconcileObservedMutation(t,e){this.markDirty()}}class Nn extends Sn{static getType(){return"linebreak"}static clone(t){return new Nn(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&&$o(e)){const n=e.firstChild;if(n===t||n.nextSibling===t&&En(n)){const n=e.lastChild;if(n===t||n.previousSibling===t&&En(n))return!0}}return!1}(t)||function(t){const e=t.parentElement;if(null!==e&&$o(e)){const n=e.firstChild;if(n===t||n.nextSibling===t&&En(n))return!1;const r=e.lastChild;if(r===t||r.previousSibling===t&&En(r))return!0}return!1}(t)?null:{conversion:Tn,priority:0}}}static importJSON(t){return vn().updateFromJSON(t)}}function Tn(t){return{node:vn()}}function vn(){return wo(new Nn)}function kn(t){return t instanceof Nn}function En(t){return Pi(t)&&/^( |\t|\r?\n)+$/.test(t.textContent||"")}function bn(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 Mn(t,e,n,r,i){const o=r.classList;let s=ho(i,"base");void 0!==s&&o.add(...s),s=ho(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 F){const r=F[t];if(s=ho(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 An(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 wn(t,e,n,r,i,o){An(i,t,e);const s=o.theme.text;void 0!==s&&Mn(0,0,r,t,s)}function Dn(t,e){const n=document.createElement(e);return n.appendChild(t),n}class Pn extends Sn{static getType(){return"text"}static clone(t){return new Pn(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 W[t.__mode]}getStyle(){return this.getLatest().__style}isToken(){return 1===this.getLatest().__mode}isComposing(){return this.__key===Wi()}isSegmented(){return 2===this.getLatest().__mode}isDirectionless(){return!!(1&this.getLatest().__detail)}isUnmergeable(){return!!(2&this.getLatest().__detail)}hasFormat(t){const e=F[t];return!!(this.getFormat()&e)}isSimpleText(){return"text"===this.__type&&0===this.__mode}getTextContent(){return this.getLatest().__text}getFormatFlags(t,e){return Fi(this.getLatest().__format,t,e)}canHaveFormat(){return!0}isInline(){return!0}createDOM(t,e){const n=this.__format,r=bn(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));wn(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=bn(0,o),c=bn(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 wn(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)),An(i,f,this);const d=r.theme.text;void 0!==d&&o!==s&&Mn(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:Kn,priority:0}),b:()=>({conversion:Ln,priority:0}),code:()=>({conversion:Wn,priority:0}),em:()=>({conversion:Wn,priority:0}),i:()=>({conversion:Wn,priority:0}),mark:()=>({conversion:Wn,priority:0}),s:()=>({conversion:Wn,priority:0}),span:()=>({conversion:In,priority:0}),strong:()=>({conversion:Wn,priority:0}),sub:()=>({conversion:Wn,priority:0}),sup:()=>({conversion:Wn,priority:0}),u:()=>({conversion:Wn,priority:0})}}static importJSON(t){return $n().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 Ko(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=Dn(n,"b")),this.hasFormat("italic")&&(n=Dn(n,"i")),this.hasFormat("strikethrough")&&(n=Dn(n,"s")),this.hasFormat("underline")&&(n=Dn(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?F[t]:t,e}setDetail(t){const e=this.getWritable();return e.__detail="string"==typeof t?R[t]:t,e}setStyle(t){const e=this.getWritable();return e.__style=t,e}toggleFormat(t){const e=Fi(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=z[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){Pr();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(!Zn(i))return fr(s,n,s,r,"text","text");{const t=Wi();t!==i.anchor.key&&t!==i.focus.key||zi(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&&Zn(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){Pr();const e=this.getLatest(),n=e.getTextContent();if(""===n)return[];const r=e.__key,i=Wi(),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 p=!1,_=null,y=null;const m=pr();if(Zn(m)){const[t,e]=m.isBackward()?[m.focus,m.anchor]:[m.anchor,m.focus];"text"===t.type&&t.key===r&&(_=t),"text"===e.type&&e.key===r&&(y=e)}e.isSegmented()?(f=$n(a),f.__format=d,f.__style=h,f.__detail=g,f.__state=ft(e,f),p=!0):f=e.setTextContent(a);const x=[f];for(let t=1;t<c;t++){const n=$n(s[t]);n.__format=d,n.__style=h,n.__detail=g,n.__state=ft(e,n);const o=n.__key;i===r&&zi(o),x.push(n)}const C=_?_.offset:null,S=y?y.offset:null;let N=0;for(const t of x){if(!_&&!y)break;const e=N+t.getTextContentSize();if(null!==_&&null!==C&&C<=e&&C>=N&&(_.set(t.getKey(),C-N,"text"),C<e&&(_=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&&Bi(e);null!==n&&Bi(n)}(this);const t=u.getWritable(),e=this.getIndexWithinParent();p?(t.splice(e,0,x),this.remove()):t.splice(e,1,x),Zn(m)&&yr(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;Wi()===i&&zi(r);const l=pr();if(Zn(l)){const t=l.anchor,o=l.focus;null!==t&&t.key===i&&Cr(t,n,r,e,s),null!==o&&o.key===i&&Cr(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 In(t){return{forChild:Jn(t.style),node:null}}function Ln(t){const e=t,n="normal"===e.style.fontWeight;return{forChild:Jn(e.style,n?void 0:"bold"),node:null}}const Fn=new WeakMap;function Rn(t){if(!Ko(t))return!1;if("PRE"===t.nodeName)return!0;const e=t.style.whiteSpace;return"string"==typeof e&&e.startsWith("pre")}function Kn(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=Fn.get(n))&&!Rn(n);)r.push(n),n=n.parentNode;const i=void 0===e?n:e;for(let t=0;t<r.length;t++)Fn.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(vn()):"\t"===n?e.push(jn()):""!==n&&e.push($n(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=Bn(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=Bn(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:$n(r)}}function Bn(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,Ko(n)){const t=n.style.display;if(""===t&&!Wo(n)||""!==t&&!t.startsWith("inline"))return null}let r=n;for(;null!==(r=e?n.firstChild:n.lastChild);)n=r;if(Pi(n))return n;if("BR"===n.nodeName)return null}}const zn={code:"code",em:"italic",i:"italic",mark:"highlight",s:"strikethrough",strong:"bold",sub:"subscript",sup:"superscript",u:"underline"};function Wn(t){const e=zn[t.nodeName.toLowerCase()];return void 0===e?{node:null}:{forChild:Jn(t.style,e),node:null}}function $n(t=""){return wo(new Pn(t))}function Un(t){return t instanceof Pn}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=>Un(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 Yn extends Pn{static getType(){return"tab"}static clone(t){return new Yn(t.__key)}constructor(t){super("\t",t),this.__detail=2}static importDOM(){return null}createDOM(t){const e=super.createDOM(t),n=ho(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 wo(new Yn)}function Hn(t){return t instanceof Yn}class Vn{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 bs(Ws(Ds(this,"next")),Ws(Ds(t,"next")))<0}getNode(){const e=$i(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,Dr()||(Wi()===o&&zi(t),null!==i&&(i.setCachedNodes(null),i.dirty=!0)))}}function Gn(t,e,n){return new Vn(t,e,n)}function qn(t,e){let n=e.__key,r=t.offset,i="element";if(Un(e)){i="text";const t=e.getTextContentSize();r>t&&(r=t)}else if(!Qr(e)){const t=e.getNextSibling();if(Un(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 Xn(t,e){if(Qr(e)){const n=e.getLastDescendant();Qr(n)||Un(n)?qn(t,n):qn(t,e)}else qn(t,e)}class Qn{constructor(t){this._cachedNodes=null,this._nodes=t,this.dirty=!1}getCachedNodes(){return this._cachedNodes}setCachedNodes(t){this._cachedNodes=t}is(t){if(!er(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 Qn(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(Un(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=$i(t);null!==e&&n.push(e)}return Dr()||(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()||_r())===this&&t[0]){const e=gs(t[0],"next");Is(ks(e,e))}for(const e of t)e.remove()}}function Zn(t){return t instanceof tr}class tr{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!!Zn(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(us(n)){const{origin:t}=n;0===e.length?i.add(t):(o.add(t),e.push(t))}else{const{origin:t}=n;Qr(t)&&o.has(t)||e.push(t)}r&&e.push(r.caret.origin);if(as(t.focus)&&Qr(t.focus.origin)&&null===t.focus.getNodeAtCaret())for(let n=ms(t.focus.origin,"previous");us(n)&&i.has(n.origin)&&!n.origin.isEmpty()&&n.origin.is(e[e.length-1]);n=Cs(n))i.delete(n.origin),e.pop();for(;e.length>1;){const t=e[e.length-1];if(!Qr(t)||o.has(t)||t.isEmpty()||i.has(t))break;e.pop()}if(0===e.length&&t.isCollapsed()){const n=Ws(t.anchor),r=Ws(t.anchor.getFlipped()),i=t=>cs(t)?t.origin:t.getNodeAtCaret(),o=i(n)||i(r)||(t.anchor.getNodeAtCaret()?n.origin:r.origin);e.push(o)}return e}(Js(Fs(this),"next"));return Dr()||(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]=rr(this);let c="",a=!0;for(let u=0;u<t.length;u++){const f=t[u];if(Qr(f)&&!f.isInline())a||(c+="\n"),a=!f.isEmpty();else if(a=!1,Un(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!ei(f)&&!kn(f)||f===n&&this.isCollapsed()||(c+=f.getTextContent())}return c}applyDOMRange(t){const e=Fr(),n=e.getEditorState()._selection,r=ur(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),pt(this)}clone(){const t=this.anchor,e=this.focus;return new tr(Gn(t.key,t.offset,t.type),Gn(e.key,e.offset,e.type),this.form