lexical
Version:
Lexical is an extensible text editor framework that provides excellent reliability, accessible and performance.
9 lines (8 loc) • 130 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.
*
*/
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.`)}function e(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);n.search=r.toString(),console.warn(`Minified Lexical warning #${t}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}const n="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement,r=n&&"documentMode"in document?document.documentMode:null,i=n&&/Mac|iPod|iPhone|iPad/.test(navigator.platform),o=n&&/^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent),s=!(!n||!("InputEvent"in window)||r)&&"getTargetRanges"in new window.InputEvent("input"),l=n&&/Version\/[\d.]+.*Safari/.test(navigator.userAgent),c=n&&/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream,a=n&&/Android/.test(navigator.userAgent),u=n&&/^(?=.*Chrome).*/i.test(navigator.userAgent),f=n&&a&&u,d=n&&/AppleWebKit\/[\d.]+/.test(navigator.userAgent)&&i&&!u;function h(...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 g=0,_=1,p=2,y=1,m=2,x=4,C=8,S=16,v=32,k=64,T=128,N=2047,b=1,w=2,E=3,M=4,O=5,A=6,P=l||c||d?" ":"",D="\n\n",F=o?" ":P,L={bold:1,capitalize:1024,code:16,highlight:T,italic:2,lowercase:256,strikethrough:4,subscript:32,superscript:64,underline:8,uppercase:512},I={directionless:1,unmergeable:2},K={center:2,end:6,justify:4,left:1,right:3,start:5},z={[w]:"center",[A]:"end",[M]:"justify",[b]:"left",[E]:"right",[O]:"start"},B={normal:0,segmented:2,token:1},R={[g]:"normal",[p]:"segmented",[_]:"token"},W="$",J="$config";function $(t,e,n,r,i,o){let s=t.getFirstChild();for(;null!==s;){const t=s.__key;s.__parent===e&&(yi(s)&&$(s,t,n,r,i,o),n.has(t)||o.delete(t),i.push(t)),s=s.getNextSibling()}}let j=!1,U=0;function V(t){U=t.timeStamp}function Y(t,e,n){const r="BR"===t.nodeName,i=e.__lexicalLineBreak;return i&&(t===i||r&&t.previousSibling===i)||r&&void 0!==_o(t,n)}function q(t,e,n){const r=us(ts(n));let i=null,o=null;null!==r&&r.anchorNode===t&&(i=r.anchorOffset,o=r.focusOffset);const s=t.nodeValue;null!==s&&Eo(e,s,i,o,!1)}function H(t,e,n){if(hr(t)){const e=t.anchor.getNode();if(e.is(n)&&t.format!==e.getFormat())return!1}return no(e)&&n.isAttached()}function G(t,e,n,r){for(let i=t;i&&!Es(i);i=Yo(i)){const t=_o(i,e);if(void 0!==t){const e=ho(t,n);if(e)return Ci(e)||!gs(i)?void 0:[i,e]}else if(i===r)return[r,Co(n)]}}function X(t,e,n){j=!0;const r=performance.now()-U>100;try{hi(t,()=>{const i=Ar()||function(t){return t.getEditorState().read(()=>{const t=Ar();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,_=G(g,t,c,l);if(!_)continue;const[p,y]=_;if("characterData"===h)r&&rr(y)&&no(g)&&H(i,g,y)&&q(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],i=go(r),s=r.parentNode;if(null!=s&&r!==a&&null===i&&!Y(r,s,t)){if(o){const t=(gs(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];(Y(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||Y(n,i,t)||o.removeChild(n)}}n.takeRecords()}null!==i&&(u&&So(i),o&&$o(t)&&i.insertRawText(f))})}finally{j=!1}}function Q(t){const e=t._observer;if(null!==e){X(t,e.takeRecords(),e)}}function Z(t){!function(t){0===U&&ts(t).addEventListener("textInput",V,!0)}(t),t._observer=new MutationObserver((e,n)=>{X(t,e,n)})}class tt{key;parse;unparse;isEqual;defaultValue;constructor(t,e){this.key=t,this.parse=e.parse.bind(e),this.unparse=(e.unparse||ut).bind(e),this.isEqual=(e.isEqual||Object.is).bind(e),this.defaultValue=this.parse(void 0)}}function et(t,e){return new tt(t,e)}function nt(t,e,n="latest"){const r=("latest"===n?t.getLatest():t).__state;return r?r.getValue(e):e.defaultValue}function rt(t,e,n){const r=nt(t,n,"direct"),i=nt(e,n,"direct");return n.isEqual(r,i)?null:[r,i]}function it(t,e,n){let r;if(Xr(),"function"==typeof n){const i=t.getLatest(),o=nt(i,e);if(r=n(o),e.isEqual(o,r))return i}else r=n;const i=t.getWritable();return lt(i).updateFromKnown(e,r),i}function ot(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}=Os(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 st{node;knownState;unknownState;sharedNodeState;size;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 at(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 st(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=at(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 lt(t){const e=t.getWritable(),n=e.__state?e.__state.getWritable(e):new st(e,ct(e));return e.__state=n,n}function ct(t){return t.__state?t.__state.sharedNodeState:Ui(Cs(),t.getType()).sharedNodeState}function at(t){if(t)for(const e in t)return t}function ut(t){return t}function ft(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 dt(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 ht(t,e){const n=t.__state;return n&&n.node===t?n.getWritable(e):n}function gt(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&&ft(n,t,e)||e&&ft(n,e,t)||t&&dt(n,t,e)||e&&dt(n,e,t))}(c,a))}function _t(t,e){const n=t.mergeWithSibling(e),r=ti()._normalizedNodes;return r.add(t.__key),r.add(e.__key),n}function pt(t){let e,n,r=t;if(""!==r.__text||!r.isSimpleText()||r.isUnmergeable()){for(;null!==(e=r.getPreviousSibling())&&rr(e)&&e.isSimpleText()&&!e.isUnmergeable();){if(""!==e.__text){if(gt(e,r)){r=_t(e,r);break}break}e.remove()}for(;null!==(n=r.getNextSibling())&&rr(n)&&n.isSimpleText()&&!n.isUnmergeable();){if(""!==n.__text){if(gt(r,n)){r=_t(r,n);break}break}n.remove()}}else r.remove()}function yt(t){return mt(t.anchor),mt(t.focus),t}function mt(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),rr(r)){t.set(r.__key,i?r.getTextContentSize():0,"text",!0);break}if(!yi(r))break;t.set(r.__key,i?r.getChildrenSize():0,"element",!0)}}let xt,Ct,St,vt,kt,Tt,Nt,bt,wt,Et,Mt="",Ot=null,At="",Pt="",Dt=!1,Ft=!1;function Lt(t,e){const n=Nt.get(t);if(null!==e){const n=Qt(t);n.parentNode===e&&e.removeChild(n)}if(bt.has(t)||Ct._keyToDOMMap.delete(t),yi(n)){const t=Yt(n,Nt);It(t,0,t.length-1,null)}void 0!==n&&Bo(Et,St,vt,n,"destroyed")}function It(t,e,n,r){let i=e;for(;i<=n;++i){const e=t[i];void 0!==e&&Lt(e,r)}}function Kt(t,e){t.setProperty("text-align",e)}const zt="40px";function Bt(t,e){const n=xt.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")||zt;t.style.setProperty("padding-inline-start",0===e?"":`calc(${e} * ${r})`)}function Rt(t,e){const n=t.style;0===e?Kt(n,""):1===e?Kt(n,"left"):2===e?Kt(n,"center"):3===e?Kt(n,"right"):4===e?Kt(n,"justify"):5===e?Kt(n,"start"):6===e&&Kt(n,"end")}function Wt(t,e){const n=function(t){const e=t.__dir;if(null!==e)return e;if(vi(t))return null;const n=t.getParentOrThrow();return vi(n)&&null===n.__dir?"auto":null}(e);null!==n?t.dir=n:t.removeAttribute("dir")}function Jt(e,n){const r=bt.get(e);void 0===r&&t(60);const i=r.createDOM(xt,Ct);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,Ct),rr(r)?i.setAttribute("data-lexical-text","true"):Ci(r)&&i.setAttribute("data-lexical-decorator","true"),yi(r)){const t=r.__indent,e=r.__size;if(Wt(i,r),0!==t&&Bt(i,t),0!==e){const t=e-1;$t(Yt(r,bt),r,0,t,r.getDOMSlot(i))}const n=r.__format;0!==n&&Rt(i,n),r.isInline()||Ut(null,r,i),Uo(r)&&(Mt+=D,Pt+=D)}else{const t=r.getTextContent();if(Ci(r)){const t=r.decorate(Ct,xt);null!==t&&Ht(e,t),i.contentEditable="false"}Mt+=t,Pt+=t}return null!==n&&n.insertChild(i),Bo(Et,St,vt,r,"created"),i}function $t(t,e,n,r,i){const o=Mt;Mt="";let s=n;for(;s<=r;++s){Jt(t[s],i);const e=bt.get(t[s]);null!==e&&rr(e)&&(null===Ot&&(Ot=e.getFormat()),""===At&&(At=e.getStyle()))}Uo(e)&&(Mt+=D);i.element.__lexicalTextContent=Mt,Mt=o+Mt}function jt(t,e){if(t){const n=t.__last;if(n){const t=e.get(n);if(t)return Bn(t)?"line-break":Ci(t)&&t.isInline()?"decorator":null}return"empty"}return null}function Ut(t,e,n){const r=jt(t,Nt),i=jt(e,bt);r!==i&&e.getDOMSlot(n).setManagedLineBreak(i)}function Vt(e,n,r){var i;Ot=null,At="",function(e,n,r){const i=Mt,o=e.__size,s=n.__size;Mt="";const l=r.element;if(1===o&&1===s){const t=e.__first,r=n.__first;if(t===r)qt(t,l);else{const e=Qt(t),n=Jt(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}Lt(t,null)}const i=bt.get(r);rr(i)&&(null===Ot&&(Ot=i.getFormat()),""===At&&(At=i.getStyle()))}else{const i=Yt(e,Nt),c=Yt(n,bt);if(i.length!==o&&t(227),c.length!==s&&t(228),0===o)0!==s&&$t(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=Gt(qt(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=Vo(Ct,r);t===u?u=Gt(qt(r,o.element)):(o.withBefore(u).insertChild(t),qt(r,o.element)),f++,d++}else Jt(r,o.withBefore(u)),d++;else u=Gt(Qt(t)),Lt(t,o.element),f++}const i=bt.get(r);null!==i&&rr(i)&&(null===Ot&&(Ot=i.getFormat()),""===At&&(At=i.getStyle()))}const h=f>s,g=d>l;if(h&&!g){const e=n[l+1],r=void 0===e?null:Ct.getElementByKey(e);$t(n,t,d,l,o.withBefore(r))}else g&&!h&&It(e,f,s,o.element)}(n,i,c,o,s,r)}Uo(n)&&(Mt+=D);l.__lexicalTextContent=Mt,Mt=i+Mt}(e,n,n.getDOMSlot(r)),i=n,null==Ot||Ot===i.__textFormat||Ft||i.setTextFormat(Ot),function(t){""===At||At===t.__textStyle||Ft||t.setTextStyle(At)}(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 qt(e,n){const r=Nt.get(e);let i=bt.get(e);void 0!==r&&void 0!==i||t(61);const o=Dt||Tt.has(e)||kt.has(e),s=Vo(Ct,e);if(r===i&&!o){if(yi(r)){const t=s.__lexicalTextContent;void 0!==t&&(Mt+=t,Pt+=t)}else{const t=r.getTextContent();Pt+=t,Mt+=t}return s}if(r!==i&&o&&Bo(Et,St,vt,i,"updated"),i.updateDOM(r,s,xt)){const r=Jt(e,null);return null===n&&t(62),n.replaceChild(r,s),Lt(e,null),r}if(yi(r)&&yi(i)){const t=i.__indent;(Dt||t!==r.__indent)&&Bt(s,t);const e=i.__format;if((Dt||e!==r.__format)&&Rt(s,e),o&&(Vt(r,i,s),vi(i)||i.isInline()||Ut(r,i,s)),Uo(i)&&(Mt+=D,Pt+=D),(Dt||i.__dir!==r.__dir)&&(Wt(s,i),vi(i)&&!Dt))for(const t of i.getChildren())if(yi(t)){Wt(Vo(Ct,t.getKey()),t)}}else{const t=i.getTextContent();if(Ci(i)){const t=i.decorate(Ct,xt);null!==t&&Ht(e,t)}Mt+=t,Pt+=t}if(!Ft&&vi(i)&&i.__cachedText!==Pt){const t=i.getWritable();t.__cachedText=Pt,i=t}return s}function Ht(t,e){let n=Ct._pendingDecorators;const r=Ct._decorators;if(null===n){if(r[t]===e)return;n=yo(Ct)}n[t]=e}function Gt(t){let e=t.nextSibling;return null!==e&&e===Ct._blockCursorElement&&(e=e.nextSibling),e}function Xt(t,e,n,r,i,o){Mt="",Pt="",Dt=2===r,Ct=n,xt=n._config,St=n._nodes,vt=Ct._listeners.mutation,kt=i,Tt=o,Nt=t._nodeMap,bt=e._nodeMap,Ft=e._readOnly,wt=new Map(n._keyToDOMMap);const s=new Map;return Et=s,qt("root",null),Ct=void 0,St=void 0,kt=void 0,Tt=void 0,Nt=void 0,bt=void 0,xt=void 0,wt=void 0,Et=void 0,s}function Qt(e){const n=wt.get(e);return void 0===n&&t(75,e),n}function Zt(t){return{type:t}}const te=Zt("SELECTION_CHANGE_COMMAND"),ee=Zt("SELECTION_INSERT_CLIPBOARD_NODES_COMMAND"),ne=Zt("CLICK_COMMAND"),re=Zt("DELETE_CHARACTER_COMMAND"),ie=Zt("INSERT_LINE_BREAK_COMMAND"),oe=Zt("INSERT_PARAGRAPH_COMMAND"),se=Zt("CONTROLLED_TEXT_INSERTION_COMMAND"),le=Zt("PASTE_COMMAND"),ce=Zt("REMOVE_TEXT_COMMAND"),ae=Zt("DELETE_WORD_COMMAND"),ue=Zt("DELETE_LINE_COMMAND"),fe=Zt("FORMAT_TEXT_COMMAND"),de=Zt("UNDO_COMMAND"),he=Zt("REDO_COMMAND"),ge=Zt("KEYDOWN_COMMAND"),_e=Zt("KEY_ARROW_RIGHT_COMMAND"),pe=Zt("MOVE_TO_END"),ye=Zt("KEY_ARROW_LEFT_COMMAND"),me=Zt("MOVE_TO_START"),xe=Zt("KEY_ARROW_UP_COMMAND"),Ce=Zt("KEY_ARROW_DOWN_COMMAND"),Se=Zt("KEY_ENTER_COMMAND"),ve=Zt("KEY_SPACE_COMMAND"),ke=Zt("KEY_BACKSPACE_COMMAND"),Te=Zt("KEY_ESCAPE_COMMAND"),Ne=Zt("KEY_DELETE_COMMAND"),be=Zt("KEY_TAB_COMMAND"),we=Zt("INSERT_TAB_COMMAND"),Ee=Zt("INDENT_CONTENT_COMMAND"),Me=Zt("OUTDENT_CONTENT_COMMAND"),Oe=Zt("DROP_COMMAND"),Ae=Zt("FORMAT_ELEMENT_COMMAND"),Pe=Zt("DRAGSTART_COMMAND"),De=Zt("DRAGOVER_COMMAND"),Fe=Zt("DRAGEND_COMMAND"),Le=Zt("COPY_COMMAND"),Ie=Zt("CUT_COMMAND"),Ke=Zt("SELECT_ALL_COMMAND"),ze=Zt("CLEAR_EDITOR_COMMAND"),Be=Zt("CLEAR_HISTORY_COMMAND"),Re=Zt("CAN_REDO_COMMAND"),We=Zt("CAN_UNDO_COMMAND"),Je=Zt("FOCUS_COMMAND"),$e=Zt("BLUR_COMMAND"),je=Zt("KEY_MODIFIER_COMMAND"),Ue=Object.freeze({}),Ve=[["keydown",function(t,e){if(Ye=t.timeStamp,qe=t.key,e.isComposing())return;if(jo(e,ge,t))return;if(null==t.key)return;if(rn&&Lo(t))return hi(e,()=>{gn(e,on)}),rn=!1,void(on="");if(function(t){return Po(t,"ArrowRight",{shiftKey:"any"})}(t))jo(e,_e,t);else if(function(t){return Po(t,"ArrowRight",Do)}(t))jo(e,pe,t);else if(function(t){return Po(t,"ArrowLeft",{shiftKey:"any"})}(t))jo(e,ye,t);else if(function(t){return Po(t,"ArrowLeft",Do)}(t))jo(e,me,t);else if(function(t){return Po(t,"ArrowUp",{altKey:"any",shiftKey:"any"})}(t))jo(e,xe,t);else if(function(t){return Po(t,"ArrowDown",{altKey:"any",shiftKey:"any"})}(t))jo(e,Ce,t);else if(function(t){return Po(t,"Enter",{altKey:"any",ctrlKey:"any",metaKey:"any",shiftKey:!0})}(t))en=!0,jo(e,Se,t);else if(function(t){return" "===t.key}(t))jo(e,ve,t);else if(function(t){return i&&Po(t,"o",{ctrlKey:!0})}(t))t.preventDefault(),en=!0,jo(e,ie,!0);else if(function(t){return Po(t,"Enter",{altKey:"any",ctrlKey:"any",metaKey:"any"})}(t))en=!1,jo(e,Se,t);else if(function(t){return Po(t,"Backspace",{shiftKey:"any"})||i&&Po(t,"h",{ctrlKey:!0})}(t))Lo(t)?jo(e,ke,t):(t.preventDefault(),jo(e,re,!0));else if(function(t){return"Escape"===t.key}(t))jo(e,Te,t);else if(function(t){return Po(t,"Delete",{})||i&&Po(t,"d",{ctrlKey:!0})}(t))!function(t){return"Delete"===t.key}(t)?(t.preventDefault(),jo(e,re,!1)):jo(e,Ne,t);else if(function(t){return Po(t,"Backspace",Fo)}(t))t.preventDefault(),jo(e,ae,!0);else if(function(t){return Po(t,"Delete",Fo)}(t))t.preventDefault(),jo(e,ae,!1);else if(function(t){return i&&Po(t,"Backspace",{metaKey:!0})}(t))t.preventDefault(),jo(e,ue,!0);else if(function(t){return i&&(Po(t,"Delete",{metaKey:!0})||Po(t,"k",{ctrlKey:!0}))}(t))t.preventDefault(),jo(e,ue,!1);else if(function(t){return Po(t,"b",Do)}(t))t.preventDefault(),jo(e,fe,"bold");else if(function(t){return Po(t,"u",Do)}(t))t.preventDefault(),jo(e,fe,"underline");else if(function(t){return Po(t,"i",Do)}(t))t.preventDefault(),jo(e,fe,"italic");else if(function(t){return Po(t,"Tab",{shiftKey:"any"})}(t))jo(e,be,t);else if(function(t){return Po(t,"z",Do)}(t))t.preventDefault(),jo(e,de,void 0);else if(function(t){if(i)return Po(t,"z",{metaKey:!0,shiftKey:!0});return Po(t,"y",{ctrlKey:!0})||Po(t,"z",{ctrlKey:!0,shiftKey:!0})}(t))t.preventDefault(),jo(e,he,void 0);else{const n=e._editorState._selection;null===n||hr(n)?Io(t)&&(t.preventDefault(),jo(e,Ke,t)):!function(t){return Po(t,"c",Do)}(t)?!function(t){return Po(t,"x",Do)}(t)?Io(t)&&(t.preventDefault(),jo(e,Ke,t)):(t.preventDefault(),jo(e,Ie,t)):(t.preventDefault(),jo(e,Le,t))}(function(t){return t.ctrlKey||t.shiftKey||t.altKey||t.metaKey})(t)&&jo(e,je,t)}],["pointerdown",function(t,e){const n=t.target,r=t.pointerType;_s(n)&&"touch"!==r&&"pen"!==r&&0===t.button&&hi(e,()=>{qi(n)||(tn=!0)})}],["compositionstart",function(t,e){hi(e,()=>{const n=Ar();if(hr(n)&&!e.isComposing()){const r=n.anchor,i=n.anchor.getNode();uo(r.key),(t.timeStamp<Ye+30||"element"===r.type||!n.isCollapsed()||i.getFormat()!==n.format||rr(i)&&i.getStyle()!==n.style)&&jo(e,se,F)}})}],["compositionend",function(t,e){o?nn=!0:c||!l&&!d?hi(e,()=>{gn(e,t.data)}):(rn=!0,on=t.data)}],["input",function(t,e){t.stopPropagation(),hi(e,()=>{if(gs(t.target)&&qi(t.target))return;const n=Ar(),r=t.data,i=hn(t);if(null!=r&&hr(n)&&cn(n,i,r,t.timeStamp,!1)){nn&&(gn(e,r),nn=!1);const i=n.anchor.getNode(),a=us(ts(e));if(null===a)return;const u=n.isBackward(),f=u?n.anchor.offset:n.focus.offset,h=u?n.focus.offset:n.anchor.offset;s&&!n.isCollapsed()&&rr(i)&&null!==a.anchorNode&&i.getTextContent().slice(0,f)+r+i.getTextContent().slice(f+h)===bo(a.anchorNode)||jo(e,se,r);const g=r.length;o&&g>1&&"insertCompositionText"===t.inputType&&!e.isComposing()&&(n.anchor.offset-=g),l||c||d||!e.isComposing()||(Ye=0,uo(null))}else{wo(!1,e,null!==r?r:void 0),nn&&(gn(e,r||void 0),nn=!1)}!function(){Xr();const t=ti();Q(t)}()},{event:t}),Ge=null}],["click",function(t,e){hi(e,()=>{const n=Ar(),r=us(ts(e)),i=Pr();if(r)if(hr(n)){const e=n.anchor,o=e.getNode();if("element"===e.type&&0===e.offset&&n.isCollapsed()&&!vi(o)&&1===xo().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=Ps(o,t=>yi(t)&&!t.isInline());yi(t)&&t.select(0)}}}else if("touch"===t.pointerType||"pen"===t.pointerType){const n=r.anchorNode;if(gs(n)||no(n)){So(Or(i,r,e,t))}}jo(e,ne,t)})}],["cut",Ue],["copy",Ue],["dragstart",Ue],["dragover",Ue],["dragend",Ue],["paste",Ue],["focus",Ue],["blur",Ue],["drop",Ue]];s&&Ve.push(["beforeinput",(e,n)=>function(e,n){const r=e.inputType,i=hn(e);if("deleteCompositionText"===r||o&&$o(n))return;if("insertCompositionText"===r)return;hi(n,()=>{const o=Ar();if("deleteContentBackward"===r){if(null===o){const t=Pr();if(!hr(t))return;So(t.clone())}if(hr(o)){const r=o.anchor.key===o.focus.key;if(s=e.timeStamp,"MediaLast"===qe&&s<Ye+30&&n.isComposing()&&r){if(uo(null),Ye=0,setTimeout(()=>{hi(n,()=>{uo(null)})},30),hr(o)){const e=o.anchor.getNode();e.markDirty(),rr(e)||t(142),dn(o,e)}}else{uo(null),e.preventDefault();const t=o.anchor.getNode(),i=t.getTextContent(),s=t.canInsertTextAfter(),l=0===o.anchor.offset&&o.focus.offset===i.length;let c=f&&r&&!l&&s;if(c&&o.isCollapsed()&&(c=!Ci(Jo(o.anchor,!0))),!c){jo(n,re,!0);const t=Ar();f&&hr(t)&&t.isCollapsed()&&(sn=t,setTimeout(()=>sn=null))}}return}}var s;if(!hr(o))return;const l=e.data;null!==Ge&&wo(!1,n,Ge),o.dirty&&null===Ge||!o.isCollapsed()||vi(o.anchor.getNode())||null===i||o.applyDOMRange(i),Ge=null;const a=o.anchor,u=o.focus,d=a.getNode(),h=u.getNode();if("insertText"!==r&&"insertTranspose"!==r)switch(e.preventDefault(),r){case"insertFromYank":case"insertFromDrop":case"insertReplacementText":jo(n,se,e);break;case"insertFromComposition":uo(null),jo(n,se,e);break;case"insertLineBreak":uo(null),jo(n,ie,!1);break;case"insertParagraph":uo(null),en&&!c?(en=!1,jo(n,ie,!1)):jo(n,oe,void 0);break;case"insertFromPaste":case"insertFromPasteAsQuotation":jo(n,le,e);break;case"deleteByComposition":(function(t,e){return t!==e||yi(t)||yi(e)||!to(t)||!to(e)})(d,h)&&jo(n,ce,e);break;case"deleteByDrag":case"deleteByCut":jo(n,ce,e);break;case"deleteContent":jo(n,re,!1);break;case"deleteWordBackward":jo(n,ae,!0);break;case"deleteWordForward":jo(n,ae,!1);break;case"deleteHardLineBackward":case"deleteSoftLineBackward":jo(n,ue,!0);break;case"deleteContentForward":case"deleteHardLineForward":case"deleteSoftLineForward":jo(n,ue,!1);break;case"formatStrikeThrough":jo(n,fe,"strikethrough");break;case"formatBold":jo(n,fe,"bold");break;case"formatItalic":jo(n,fe,"italic");break;case"formatUnderline":jo(n,fe,"underline");break;case"historyUndo":jo(n,de,void 0);break;case"historyRedo":jo(n,he,void 0)}else{if("\n"===l)e.preventDefault(),jo(n,ie,!1);else if(l===D)e.preventDefault(),jo(n,oe,void 0);else if(null==l&&e.dataTransfer){const t=e.dataTransfer.getData("text/plain");e.preventDefault(),o.insertRawText(t)}else null!=l&&cn(o,i,l,e.timeStamp,!0)?(e.preventDefault(),jo(n,se,l)):Ge=l;He=e.timeStamp}})}(e,n)]);let Ye=0,qe=null,He=0,Ge=null;const Xe=new WeakMap,Qe=new WeakMap;let Ze=!1,tn=!1,en=!1,nn=!1,rn=!1,on="",sn=null,ln=[0,"",0,"root",0];function cn(t,e,n,r,i){const o=t.anchor,l=t.focus,c=o.getNode(),a=ti(),u=us(ts(a)),f=null!==u?u.anchorNode:null,d=o.key,h=a.getElementByKey(d),g=n.length;return d!==l.key||!rr(c)||(!i&&(!s||He<r+50)||c.isDirty()&&g<2||ko(n))&&o.offset!==l.offset&&!c.isComposing()||eo(c)||c.isDirty()&&g>1||(i||!s)&&null!==h&&!c.isComposing()&&f!==io(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=to(e);return 0===n?!e.canInsertTextBefore()||!r.canInsertTextBefore()&&!e.isComposing()||i||function(t){const e=t.getPreviousSibling();return(rr(e)||yi(e)&&e.isInline())&&!e.canInsertTextAfter()}(e):n===e.getTextContentSize()&&(!e.canInsertTextAfter()||!r.canInsertTextAfter()&&!e.isComposing()||i)}(t,c)}function an(t,e){return no(t)&&null!==t.nodeValue&&0!==e&&e!==t.nodeValue.length}function un(e,n,r){const{anchorNode:i,anchorOffset:o,focusNode:s,focusOffset:l}=e;Ze&&(Ze=!1,an(i,o)&&an(s,l)&&!sn)||hi(n,()=>{if(!r)return void So(null);if(!Gi(n,i,s))return;let c=Ar();if(sn&&hr(c)&&c.isCollapsed()){const t=c.anchor,e=sn.anchor;(t.key===e.key&&t.offset===e.offset+1||1===t.offset&&e.getNode().is(t.getNode().getPreviousSibling()))&&(c=sn.clone(),So(c))}if(sn=null,hr(c)){const r=c.anchor,i=r.getNode();if(c.isCollapsed()){"Range"===e.type&&e.anchorNode===e.focusNode&&(c.dirty=!0);const o=ts(n).event,s=o?o.timeStamp:performance.now(),[l,a,u,f,d]=ln,h=xo(),g=!1===n.isComposing()&&""===h.getTextContent();if(s<d+200&&r.offset===u&&r.key===f)fn(c,l,a);else if("text"===r.type)rr(i)||t(141),dn(c,i);else if("element"===r.type&&!g){yi(i)||t(259);const e=r.getNode();e.isEmpty()?function(t,e){const n=e.getTextFormat(),r=e.getTextStyle();fn(t,n,r)}(c,e):fn(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=2047,g=!1;for(let t=0;t<i;t++){const e=n[t],r=e.getTextContentSize();if(rr(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}}jo(n,te,void 0)})}function fn(t,e,n){t.format===e&&t.style===n||(t.format=e,t.style=n,t.dirty=!0)}function dn(t,e){fn(t,e.getFormat(),e.getStyle())}function hn(t){if(!t.getTargetRanges)return null;const e=t.getTargetRanges();return 0===e.length?null:e[0]}function gn(t,e){const n=t._compositionKey;if(uo(null),null!==n&&null!=e){if(""===e){const e=ho(n),r=io(t.getElementByKey(n));return void(null!==r&&null!==r.nodeValue&&rr(e)&&Eo(e,r.nodeValue,null,null,!0))}if("\n"===e[e.length-1]){const e=Ar();if(hr(e)){const n=e.focus;return e.anchor.set(n.key,n.offset,n.type),void jo(t,Se,null)}}}wo(!0,t,e)}function _n(t){let e=t.__lexicalEventHandles;return void 0===e&&(e=[],t.__lexicalEventHandles=e),e}const pn=new Map;function yn(t){const e=fs(t.target);if(null===e)return;const n=Qi(e.anchorNode);if(null===n)return;tn&&(tn=!1,hi(n,()=>{const r=Pr(),i=e.anchorNode;if(gs(i)||no(i)){So(Or(r,e,n,t))}}));const r=To(n),i=r[r.length-1],o=i._key,s=pn.get(o),l=s||i;l!==n&&un(e,l,!1),un(e,n,!0),n!==i?pn.set(o,n):s&&pn.delete(o)}function mn(t){t._lexicalHandled=!0}function xn(t){return!0===t._lexicalHandled}const Cn=()=>{};function Sn(e){const n=Xe.get(e);if(void 0===n)return void Cn();const r=Qe.get(n);if(void 0===r)return void Cn();const i=r-1;i>=0||t(164),Xe.delete(e),Qe.set(n,i),0===i&&n.removeEventListener("selectionchange",yn);const o=Zi(e);Xi(o)?(!function(t){if(null!==t._parentEditor){const e=To(t),n=e[e.length-1]._key;pn.get(n)===t&&pn.delete(n)}else pn.delete(t._key)}(o),e.__lexicalEditor=null):o&&t(198);const s=_n(e);for(let t=0;t<s.length;t++)s[t]();e.__lexicalEventHandles=[]}function vn(t,e,n){Xr();const r=t.__key,i=t.getParent();if(null===i)return;const o=function(t){const e=Ar();if(!hr(e)||!yi(t))return e;const{anchor:n,focus:r}=e,i=n.getNode(),o=r.getNode();Qo(i,t)&&n.set(t.__key,0,"element");Qo(o,t)&&r.set(t.__key,0,"element");return e}(t);let s=!1;if(hr(o)&&e){const e=o.anchor,n=o.focus;e.key===r&&(Lr(e,t,i,t.getPreviousSibling(),t.getNextSibling()),s=!0),n.key===r&&(Lr(n,t,i,t.getPreviousSibling(),t.getNextSibling()),s=!0)}else _r(o)&&e&&t.isSelected()&&t.selectPrevious();if(hr(o)&&e&&!s){const e=t.getIndexWithinParent();co(t),Dr(o,i,e,-1)}else co(t);n||rs(i)||i.canBeEmpty()||!i.isEmpty()||vn(i,e),e&&o&&vi(i)&&i.isEmpty()&&i.selectEnd()}function kn(t){return t}const Tn=Symbol.for("ephemeral");function Nn(t){return t[Tn]||!1}class bn{__type;__key;__parent;__prev;__next;__state;static getType(){const{ownNodeType:e}=Os(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))}static importDOM;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}),lo(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=ho(t);if(null===e)break;t=e.__parent}return!1}isSelected(t){const e=t||Ar();if(null==e)return!1;const n=e.getNodes().some(t=>t.__key===this.__key);if(rr(this))return n;if(hr(e)&&"element"===e.anchor.type&&"element"===e.focus.type){if(e.isCollapsed())return!1;const t=this.getParent();if(Ci(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:ho(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(rs(n))return yi(e)||e===this&&Ci(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:ho(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:ho(t)}getNextSiblings(){const t=[];let e=this.getNextSibling();for(;null!==e;)t.push(e),e=e.getNextSibling();return t}getCommonAncestor(t){const e=yi(this)?this:this.getParent(),n=yi(t)?t:t.getParent(),r=e&&n?dl(e,n):null;return r?r.commonAncestor:null}is(t){return null!=t&&this.__key===t.__key}isBefore(e){const n=dl(this,e);return null!==n&&("descendant"===n.type||("branch"===n.type?-1===al(n):("same"!==n.type&&"ancestor"!==n.type&&t(279),!1)))}isParentOf(t){const e=dl(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=yi(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=ti()._dirtyLeaves;return null!==t&&t.has(this.__key)}getLatest(){if(Nn(this))return this;const e=ho(this.__key);return null===e&&t(113),e}getWritable(){if(Nn(this))return this;Xr();const t=Zr(),e=ti(),n=t._nodeMap,r=this.__key,i=this.getLatest(),o=e._cloneNotNeeded,s=Ar();if(null!==s&&s.setCachedNodes(null),o.has(r))return ao(i),i;const l=Ts(i);return o.add(r),ao(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 ct(n).flatKeys)t in e&&(void 0!==i&&i!==r||(i={...r}),i[t]=e[t]);return(n.__state||i)&<(t).updateFromJSON(i),n}(this,t)}static transform(){return null}remove(t){vn(this,!0,t)}replace(e,n){Xr();let r=Ar();null!==r&&(r=r.clone()),ss(this,e);const i=this.getLatest(),o=this.__key,s=e.__key,l=e.getWritable(),c=this.getParentOrThrow().getWritable(),a=c.__size;co(l);const u=i.getPreviousSibling(),f=i.getNextSibling(),d=i.__prev,h=i.__next,g=i.__parent;if(vn(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&&(yi(this)&&yi(l)||t(139),this.getChildren().forEach(t=>{l.append(t)})),hr(r)){So(r);const t=r.anchor,e=r.focus;t.key===o&&fr(t,l),e.key===o&&fr(e,l)}return fo()===o&&uo(s),l}insertAfter(t,e=!0){Xr(),ss(this,t);const n=this.getWritable(),r=t.getWritable(),i=r.getParent(),o=Ar();let s=!1,l=!1;if(null!==i){const e=t.getIndexWithinParent();if(co(r),hr(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&&hr(o)){const t=this.getIndexWithinParent();Dr(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){Xr(),ss(this,t);const n=this.getWritable(),r=t.getWritable(),i=r.__key;co(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=Ar();if(e&&hr(a)){Dr(a,this.getParentOrThrow(),c)}return t}isParentRequired(){return!1}createParentElementNode(){return Ai()}selectStart(){return this.selectPrevious()}selectEnd(){return this.selectNext(0,0)}selectPrevious(t,e){Xr();const n=this.getPreviousSibling(),r=this.getParentOrThrow();if(null===n)return r.select(0,0);if(yi(n))return n.select();if(!rr(n)){const t=n.getIndexWithinParent()+1;return r.select(t,t)}return n.select(t,e)}selectNext(t,e){Xr();const n=this.getNextSibling(),r=this.getParentOrThrow();if(null===n)return r.select();if(yi(n))return n.select(0,0);if(!rr(n)){const t=n.getIndexWithinParent();return r.select(t,t)}return n.select(t,e)}markDirty(){this.getWritable()}reconcileObservedMutation(t,e){this.markDirty()}}const wn="historic",En="history-push",Mn="history-merge",On="paste",An="collaboration",Pn="skip-collab",Dn="skip-scroll-into-view",Fn="skip-dom-selection",Ln="skip-selection-focus";class In extends bn{static getType(){return"linebreak"}static clone(t){return new In(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&&ms(e)){const n=e.firstChild;if(n===t||n.nextSibling===t&&Rn(n)){const n=e.lastChild;if(n===t||n.previousSibling===t&&Rn(n))return!0}}return!1}(t)||function(t){const e=t.parentElement;if(null!==e&&ms(e)){const n=e.firstChild;if(n===t||n.nextSibling===t&&Rn(n))return!1;const r=e.lastChild;if(r===t||r.previousSibling===t&&Rn(r))return!0}return!1}(t)?null:{conversion:Kn,priority:0}}}static importJSON(t){return zn().updateFromJSON(t)}}function Kn(t){return{node:zn()}}function zn(){return os(new In)}function Bn(t){return t instanceof In}function Rn(t){return no(t)&&/^( |\t|\r?\n)+$/.test(t.textContent||"")}function Wn(t,e){return 16&e?"code":e&T?"mark":32&e?"sub":64&e?"sup":null}function Jn(t,e){return 1&e?"strong":2&e?"em":"span"}function $n(t,e,n,r,i){const o=r.classList;let s=zo(i,"base");void 0!==s&&o.add(...s),s=zo(i,"underlineStrikethrough");let l=!1;const c=8&e&&4&e;void 0!==s&&(8&n&&4&n?(l=!0,c||o.add(...s)):c&&o.remove(...s));for(const t in L){const r=L[t];if(s=zo(i,t),void 0!==s)if(n&r){if(l&&("underline"===t||"strikethrough"===t)){e&r&&o.remove(...s);continue}(0===(e&r)||c&&"underline"===t||"strikethrough"===t)&&o.add(...s)}else e&r&&o.remove(...s)}}function jn(t,e,n){const r=e.firstChild,i=n.isComposing(),s=t+(i?P:"");if(null==r)e.textContent=s;else{const t=r.nodeValue;if(t!==s)if(i||o){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 Un(t,e,n,r,i,o){jn(i,t,e);const s=o.theme.text;void 0!==s&&$n(0,0,r,t,s)}function Vn(t,e){const n=document.createElement(e);return n.appendChild(t),n}class Yn extends bn{__text;__format;__style;__mode;__detail;static getType(){return"text"}static clone(t){return new Yn(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 R[t.__mode]}getStyle(){return this.getLatest().__style}isToken(){return 1===this.getLatest().__mode}isComposing(){return this.__key===fo()}isSegmented(){return 2===this.getLatest().__mode}isDirectionless(){return!!(1&this.getLatest().__detail)}isUnmergeable(){return!!(2&this.getLatest().__detail)}hasFormat(t){const e=L[t];return 0!==(this.getFormat()&e)}isSimpleText(){return"text"===this.__type&&0===this.__mode}getTextContent(){return this.getLatest().__text}getFormatFlags(t,e){return oo(this.getLatest().__format,t,e)}canHaveFormat(){return!0}isInline(){return!0}createDOM(t,e){const n=this.__format,r=Wn(0,n),i=Jn(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));Un(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=Wn(0,o),c=Wn(0,s),a=Jn(0,o),u=Jn(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 Un(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)),jn(i,f,this);const d=r.theme.text;void 0!==d&&o!==s&&$n(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:Qn,priority:0}),b:()=>({conversion:Hn,priority:0}),code:()=>({conversion:er,priority:0}),em:()=>({conversion:er,priority:0}),i:()=>({conversion:er,priority:0}),mark:()=>({conversion:er,priority:0}),s:()=>({conversion:er,priority:0}),span:()=>({conversion:qn,priority:0}),strong:()=>({conversion:er,priority:0}),sub:()=>({conversion:er,priority:0}),sup:()=>({conversion:er,priority:0}),u:()=>({conversion:er,priority:0})}}static importJSON(t){return nr().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 gs(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=Vn(n,"b")),this.hasFormat("italic")&&(n=Vn(n,"i")),this.hasFormat("strikethrough")&&(n=Vn(n,"s")),this.hasFormat("underline")&&(n=Vn(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?L[t]:t,e}setDetail(t){const e=this.getWritable();return e.__detail="string"==typeof t?I[t]:t,e}setStyle(t){const e=this.getWritable();return e.__style=t,e}toggleFormat(t){const e=oo(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=B[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){Xr();let n=t,r=e;const i=Ar(),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(!hr(i))return br(s,n,s,r,"text","text");{const t=fo();t!==i.anchor.key&&t!==i.focus.key||uo(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=Ar();if(r&&hr(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){Xr();const e=this.getLatest(),n=e.getTextContent();if(""===n)return[];const r=e.__key,i=fo(),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=Ar();if(hr(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=nr(a),f.__format=d,f.__style=h,f.__detail=g,f.__state=ht(e,f),_=!0):f=e.setTextContent(a);const x=[f];for(let t=1;t<c;t++){const n=nr(s[t]);n.__format=d,n.__style=h,n.__detail=g,n.__state=ht(e,n);const o=n.__key;i===r&&uo(o),x.push(n)}const C=p?p.offset:null,S=y?y.offset:null;let v=0;for(const t of x){if(!p&&!y)break;const e=v+t.getTextContentSize();if(null!==p&&null!==C&&C<=e&&C>=v&&(p.set(t.getKey(),C-v,"text"),C<e&&(p=null)),null!==y&&null!==S&&S<=e&&S>=v){y.set(t.getKey(),S-v,"text");break}v=e}if(null!==u){!function(t){const e=t.getPreviousSibling(),n=t.getNextSibling();null!==e&&ao(e);null!==n&&ao(n)}(this);const t=u.getWritable(),e=this.getIndexWithinParent();_?(t.splice(e,0,x),this.remove()):t.splice(e,1,x),hr(m)&&Dr(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;fo()===i&&uo(r);const l=Ar();if(hr(l)){const t=l.anchor,o=l.focus;null!==t&&t.key===i&&Ir(t,n,r,e,s),null!==o&&o.key===i&&Ir(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 qn(t){return{forChild:ir(t.style),node:null}}function Hn(t){const e=t,n="normal"===e.style.fontWeight;return{forChild:ir(e.style,n?void 0:"bold"),node:null}}const Gn=new WeakMap;function Xn(t){if(!gs(t))return!1;if("PRE"===t.nodeName)return!0;const e=t.style.whiteSpace;return"string"==typeof e&&e.startsWith("pre")}function Qn(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=Gn.get(n))&&!Xn(n);)r.push(n),n=n.parentNode;const i=void 0===e?n:e;for(let t=0;t<r.length;t++)Gn.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(zn()):"\t"===n?e.push(sr()):""!==n&&e.push(nr(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:nr(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,gs(n)){const t=n.style.display;if(""===t&&!ys(n)||""!==t&&!t.startsWith("inline"))return null}let r=n;for(;null!==(r=e?n.firstChild:n.lastChild);)n=r;if(no(n))return n;if("BR"===n.nodeName)return null}}const tr={code:"code",em:"italic",i:"italic",mark:"highlight",s:"strikethrough",strong:"bold",sub:"subscript",sup:"superscript",u:"underline"};function er(t){const e=tr[t.nodeName.toLowerCase()];return void 0===e?{node:null}:{forChild:ir(t.style,e),node:null}}function nr(t=""){return os(new Yn(t))}function rr(t){return t instanceof Yn}function ir(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=>rr(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 or extends Yn{static getType(){return"tab"}static clone(t){return new or(t.__key)}constructor(t){super("\t",t),this.__detail=2}static importDOM(){return null}createDOM(t){const e=super.createDOM(t),n=zo(t.theme,"tab");if(void 0!==n){e.classList.add(...n)}return e}static importJSON(t){return sr().updateFromJSON(t)}setTextContent(t){return"\t"!==t&&""!==t&&e(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 sr(){return os(new or)}function lr(t){return t instanceof or}class cr{key;offset;type;_selection;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 cl(vl(hl(this,"next")),vl(hl(t,"next")))<0}getNode(){const e=ho(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,Gr()||(fo()===o&&uo(t),null!==i&&(i.setCachedNodes(null),i.dirty=!0)))}}function ar(t,e,n){return new cr(t,e,n)}function ur(t,e){let n=e.__key,r=t.offset,i="element";if(rr(e)){i="text";const t=e.getTextContentSize();r>t&&(r=t)}else if(!yi(e)){const t=e.getNextSibling();if(rr(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 fr(t,e){if(yi(e)){const n=e.getLastDescendant();yi(n)||rr(n)?ur(t,n):ur(t,e)}else ur(t,e)}class dr{_nodes;_cachedNodes;dirty;constructor(t){this._cachedNodes=null,this._nodes=t,this.dirty=!1}getCachedNodes(){return this._cachedNodes}setCachedNodes(t){this._cachedNodes=t}is(t){if(!_r(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 dr(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(rr(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=ho(t);null!==e&&n.push(e)}return Gr()||(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((Ar()||Pr())===this&&t[0]){const e=qs(t[0],"next");_l(sl(e,e))}for(const e of t)e.remove()}}function hr(t){return t instanceof gr}class gr{format;style;anchor;focus;_cachedNodes;dirty;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!!hr(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(js(n)){const{origin:t}=n;0===e.length?i.add(t):(o.add(t),e.push(t))}else{const{origin:t}=n;yi(t)&&o.has(t)||e.push(t)}r&&e.push(r.caret.origin);if($s(t.focus)&&yi(t.focus.origin)&&null===t.focus.getNodeAtCaret())for(let n=Qs(t.focus.origin,"previous");js(n)&&i.has(n.origin)&&!n.origin.isEmpty()&&n.origin.is(e[e.length-1]);n=tl(n))i.delete(n.origin),e.pop();for(;e.length>1;){const t=e[e.length-1];if(!yi(t)||o.has(t)||t.isEmpty()||i.has(t))break;e.pop()}if(0===e.length&&t.isCollapsed()){const n=vl(t.anchor),r=vl(t.anchor.getFlipped()),i=t=>Ws(t)?t.origin:t.getNodeAtC