UNPKG

lexical

Version:

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

9 lines (8 loc) 130 kB
/** * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * */ "use strict";function t(t,...e){const n=new URL("https://lexical.dev/docs/error"),r=new URLSearchParams;r.append("code",t);for(const t of e)r.append("v",t);throw n.search=r.toString(),Error(`Minified Lexical error #${t}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}const e="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement,n=e&&"documentMode"in document?document.documentMode:null,r=e&&/Mac|iPod|iPhone|iPad/.test(navigator.platform),i=e&&/^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent),o=!(!e||!("InputEvent"in window)||n)&&"getTargetRanges"in new window.InputEvent("input"),s=e&&/Version\/[\d.]+.*Safari/.test(navigator.userAgent),l=e&&/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream,c=e&&/Android/.test(navigator.userAgent),a=e&&/^(?=.*Chrome).*/i.test(navigator.userAgent),u=e&&c&&a,f=e&&/AppleWebKit\/[\d.]+/.test(navigator.userAgent)&&!a;function d(...t){const e=[];for(const n of t)if(n&&"string"==typeof n)for(const[t]of n.matchAll(/\S+/g))e.push(t);return e}const h=1,g=3,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="֑-߿יִ-﷽ﹰ-ﻼ",R="A-Za-zÀ-ÖØ-öø-ʸ̀-֐ࠀ-῿‎Ⰰ-﬜︀-﹯﻽-￿",K=new RegExp("^[^"+R+"]*["+F+"]"),B=new RegExp("^[^"+F+"]*["+R+"]"),z={bold:1,capitalize:1024,code:16,highlight:k,italic:2,lowercase:256,strikethrough:T,subscript:32,superscript:64,underline:v,uppercase:512},W={directionless:1,unmergeable:2},$={center:O,end:D,justify:A,left:b,right:M,start:w},U={[O]:"center",[D]:"end",[A]:"justify",[b]:"left",[M]:"right",[w]:"start"},J={normal:0,segmented:2,token:1},Y={[C]:"normal",[N]:"segmented",[S]:"token"},j="$config";function H(t,e,n,r,i,o){let s=t.getFirstChild();for(;null!==s;){const t=s.__key;s.__parent===e&&(ii(s)&&H(s,t,n,r,i,o),n.has(t)||o.delete(t),i.push(t)),s=s.getNextSibling()}}const V=100;let G=!1,q=0;function X(t){q=t.timeStamp}function Q(t,e,n){const r="BR"===t.nodeName,i=e.__lexicalLineBreak;return i&&(t===i||r&&t.previousSibling===i)||r&&void 0!==Gi(t,n)}function Z(t,e,n){const r=Wo(Do(n));let i=null,o=null;null!==r&&r.anchorNode===t&&(i=r.anchorOffset,o=r.focusOffset);const s=t.nodeValue;null!==s&&co(e,s,i,o,!1)}function tt(t,e,n){if(or(t)){const e=t.anchor.getNode();if(e.is(n)&&t.format!==e.getFormat())return!1}return Ki(e)&&n.isAttached()}function et(t,e,n,r){for(let i=t;i&&!ns(i);i=Eo(i)){const t=Gi(i,e);if(void 0!==t){const e=Hi(t,n);if(e)return li(e)||!Uo(i)?void 0:[i,e]}else if(i===r)return[r,to(n)]}}function nt(t,e,n){G=!0;const r=performance.now()-q>V;try{ti(t,(()=>{const o=Sr()||function(t){return t.getEditorState().read((()=>{const t=Sr();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=et(g,t,c,l);if(!p)continue;const[_,y]=p;if("characterData"===h)r&&Gn(y)&&Ki(g)&&tt(o,g,y)&&Z(g,y,t);else if("childList"===h){u=!0;const e=d.addedNodes;for(let n=0;n<e.length;n++){const r=e[n],o=Vi(r),s=r.parentNode;if(null!=s&&r!==a&&null===o&&!Q(r,s,t)){if(i){const t=(Uo(r)?r.innerText:null)||r.nodeValue;t&&(f+=t)}s.removeChild(r)}}const n=d.removedNodes,r=n.length;if(r>0){let e=0;for(let i=0;i<r;i++){const r=n[i];(Q(r,g,t)||a===r)&&(g.appendChild(r),e++)}r!==e&&s.set(_,y)}}}if(s.size>0)for(const[e,n]of s)n.reconcileObservedMutation(e,t);const d=n.takeRecords();if(d.length>0){for(let e=0;e<d.length;e++){const n=d[e],r=n.addedNodes,i=n.target;for(let e=0;e<r.length;e++){const n=r[e],o=n.parentNode;null==o||"BR"!==n.nodeName||Q(n,i,t)||o.removeChild(n)}}n.takeRecords()}null!==o&&(u&&eo(o),i&&No(t)&&o.insertRawText(f))}))}finally{G=!1}}function rt(t){const e=t._observer;if(null!==e){nt(t,e.takeRecords(),e)}}function it(t){!function(t){0===q&&Do(t).addEventListener("textInput",X,!0)}(t),t._observer=new MutationObserver(((e,n)=>{nt(t,e,n)}))}class ot{constructor(t,e){this.key=t,this.parse=e.parse.bind(e),this.unparse=(e.unparse||dt).bind(e),this.isEqual=(e.isEqual||Object.is).bind(e),this.defaultValue=this.parse(void 0)}}function st(t,e,n="latest"){const r=("latest"===n?t.getLatest():t).__state;return r?r.getValue(e):e.defaultValue}function lt(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}=is(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 ct{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 ft(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 ct(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=ft(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 at(t){const e=t.getWritable(),n=e.__state?e.__state.getWritable(e):new ct(e,ut(e));return e.__state=n,n}function ut(t){return t.__state?t.__state.sharedNodeState:bi(qo(),t.getType()).sharedNodeState}function ft(t){if(t)for(const e in t)return t}function dt(t){return t}function ht(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 gt(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 pt(t,e){const n=t.__state;return n&&n.node===t?n.getWritable(e):n}function _t(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&&ht(n,t,e)||e&&ht(n,e,t)||t&&gt(n,t,e)||e&&gt(n,e,t))}(c,a))}function yt(t,e){const n=t.mergeWithSibling(e),r=$r()._normalizedNodes;return r.add(t.__key),r.add(e.__key),n}function mt(t){let e,n,r=t;if(""!==r.__text||!r.isSimpleText()||r.isUnmergeable()){for(;null!==(e=r.getPreviousSibling())&&Gn(e)&&e.isSimpleText()&&!e.isUnmergeable();){if(""!==e.__text){if(_t(e,r)){r=yt(e,r);break}break}e.remove()}for(;null!==(n=r.getNextSibling())&&Gn(n)&&n.isSimpleText()&&!n.isUnmergeable();){if(""!==n.__text){if(_t(r,n)){r=yt(r,n);break}break}n.remove()}}else r.remove()}function xt(t){return Ct(t.anchor),Ct(t.focus),t}function Ct(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),Gn(r)){t.set(r.__key,i?r.getTextContentSize():0,"text",!0);break}if(!ii(r))break;t.set(r.__key,i?r.getChildrenSize():0,"element",!0)}}let St,Nt,Tt,vt,kt,Et,bt,Ot,Mt,At,wt="",Dt="",Pt=null,It="",Lt="",Ft=!1,Rt=!1,Kt=null;function Bt(t,e){const n=bt.get(t);if(null!==e){const n=ne(t);n.parentNode===e&&e.removeChild(n)}if(Ot.has(t)||Nt._keyToDOMMap.delete(t),ii(n)){const t=Xt(n,bt);zt(t,0,t.length-1,null)}void 0!==n&&xo(At,Tt,vt,n,"destroyed")}function zt(t,e,n,r){let i=e;for(;i<=n;++i){const e=t[i];void 0!==e&&Bt(e,r)}}function Wt(t,e){t.setProperty("text-align",e)}const $t="40px";function Ut(t,e){const n=St.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")||$t;t.style.setProperty("padding-inline-start",0===e?"":`calc(${e} * ${r})`)}function Jt(t,e){const n=t.style;0===e?Wt(n,""):e===b?Wt(n,"left"):e===O?Wt(n,"center"):e===M?Wt(n,"right"):e===A?Wt(n,"justify"):e===w?Wt(n,"start"):e===D&&Wt(n,"end")}function Yt(e,n){const r=Ot.get(e);void 0===r&&t(60);const i=r.createDOM(St,Nt);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,Nt),Gn(r)?i.setAttribute("data-lexical-text","true"):li(r)&&i.setAttribute("data-lexical-decorator","true"),ii(r)){const t=r.__indent,e=r.__size;if(0!==t&&Ut(i,t),0!==e){const t=e-1;!function(t,e,n,r){const i=Dt;Dt="",jt(t,n,0,e,n.getDOMSlot(r)),Gt(n,r),Dt=i}(Xt(r,Ot),t,r,i)}const n=r.__format;0!==n&&Jt(i,n),r.isInline()||Vt(null,r,i),vo(r)&&(wt+=I,Lt+=I)}else{const t=r.getTextContent();if(li(r)){const t=r.decorate(Nt,St);null!==t&&Zt(e,t),i.contentEditable="false"}else Gn(r)&&(r.isDirectionless()||(Dt+=t));wt+=t,Lt+=t}return null!==n&&n.insertChild(i),xo(At,Tt,vt,r,"created"),i}function jt(t,e,n,r,i){const o=wt;wt="";let s=n;for(;s<=r;++s){Yt(t[s],i);const e=Ot.get(t[s]);null!==e&&Gn(e)&&(null===Pt&&(Pt=e.getFormat()),""===It&&(It=e.getStyle()))}vo(e)&&(wt+=I);i.element.__lexicalTextContent=wt,wt=o+wt}function Ht(t,e){if(t){const n=t.__last;if(n){const t=e.get(n);if(t)return wn(t)?"line-break":li(t)&&t.isInline()?"decorator":null}return"empty"}return null}function Vt(t,e,n){const r=Ht(t,bt),i=Ht(e,Ot);r!==i&&e.getDOMSlot(n).setManagedLineBreak(i)}function Gt(t,e){const n=e.__lexicalDirTextContent||"",r=e.__lexicalDir||"";if(n!==Dt||r!==Kt){const n=""===Dt,i=n?Kt:function(t){if(K.test(t))return"rtl";if(B.test(t))return"ltr";return null}(Dt);if(i!==r){const o=e.classList,s=St.theme;let l=null!==r?s[r]:void 0,c=null!==i?s[i]:void 0;if(void 0!==l){if("string"==typeof l){const t=d(l);l=s[r]=t}o.remove(...l)}if(null===i||n&&"ltr"===i)e.removeAttribute("dir");else{if(void 0!==c){if("string"==typeof c){const t=d(c);c=s[i]=t}void 0!==c&&o.add(...c)}e.dir=i}if(!Rt){t.getWritable().__dir=i}}Kt=i,e.__lexicalDirTextContent=Dt,e.__lexicalDir=i}}function qt(e,n,r){const i=Dt;var o;Dt="",Pt=null,It="",function(e,n,r){const i=wt,o=e.__size,s=n.__size;wt="";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=ne(t),n=Yt(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}Bt(t,null)}const i=Ot.get(r);Gn(i)&&(null===Pt&&(Pt=i.getFormat()),""===It&&(It=i.getStyle()))}else{const i=Xt(e,bt),c=Xt(n,Ot);if(i.length!==o&&t(227),c.length!==s&&t(228),0===o)0!==s&&jt(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;zt(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=te(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=ko(Nt,r);t===u?u=te(Qt(r,o.element)):(o.withBefore(u).insertChild(t),Qt(r,o.element)),f++,d++}else Yt(r,o.withBefore(u)),d++;else u=te(ne(t)),Bt(t,o.element),f++}const i=Ot.get(r);null!==i&&Gn(i)&&(null===Pt&&(Pt=i.getFormat()),""===It&&(It=i.getStyle()))}const h=f>s,g=d>l;if(h&&!g){const e=n[l+1],r=void 0===e?null:Nt.getElementByKey(e);jt(n,t,d,l,o.withBefore(r))}else g&&!h&&zt(e,f,s,o.element)}(n,i,c,o,s,r)}vo(n)&&(wt+=I);l.__lexicalTextContent=wt,wt=i+wt}(e,n,n.getDOMSlot(r)),Gt(n,r),o=n,null==Pt||Pt===o.__textFormat||Rt||o.setTextFormat(Pt),function(t){""===It||It===t.__textStyle||Rt||t.setTextStyle(It)}(n),Dt=i}function Xt(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=bt.get(e);let i=Ot.get(e);void 0!==r&&void 0!==i||t(61);const o=Ft||Et.has(e)||kt.has(e),s=ko(Nt,e);if(r===i&&!o){if(ii(r)){const t=s.__lexicalTextContent;void 0!==t&&(wt+=t,Lt+=t);const e=s.__lexicalDirTextContent;void 0!==e&&(Dt+=e)}else{const t=r.getTextContent();Gn(r)&&!r.isDirectionless()&&(Dt+=t),Lt+=t,wt+=t}return s}if(r!==i&&o&&xo(At,Tt,vt,i,"updated"),i.updateDOM(r,s,St)){const r=Yt(e,null);return null===n&&t(62),n.replaceChild(r,s),Bt(e,null),r}if(ii(r)&&ii(i)){const t=i.__indent;t!==r.__indent&&Ut(s,t);const e=i.__format;e!==r.__format&&Jt(s,e),o&&(qt(r,i,s),ai(i)||i.isInline()||Vt(r,i,s)),vo(i)&&(wt+=I,Lt+=I)}else{const t=i.getTextContent();if(li(i)){const t=i.decorate(Nt,St);null!==t&&Zt(e,t)}else Gn(i)&&!i.isDirectionless()&&(Dt+=t);wt+=t,Lt+=t}if(!Rt&&ai(i)&&i.__cachedText!==Lt){const t=i.getWritable();t.__cachedText=Lt,i=t}return s}function Zt(t,e){let n=Nt._pendingDecorators;const r=Nt._decorators;if(null===n){if(r[t]===e)return;n=Xi(Nt)}n[t]=e}function te(t){let e=t.nextSibling;return null!==e&&e===Nt._blockCursorElement&&(e=e.nextSibling),e}function ee(t,e,n,r,i,o){wt="",Lt="",Dt="",Ft=r===x,Kt=null,Nt=n,St=n._config,Tt=n._nodes,vt=Nt._listeners.mutation,kt=i,Et=o,bt=t._nodeMap,Ot=e._nodeMap,Rt=e._readOnly,Mt=new Map(n._keyToDOMMap);const s=new Map;return At=s,Qt("root",null),Nt=void 0,Tt=void 0,kt=void 0,Et=void 0,bt=void 0,Ot=void 0,St=void 0,Mt=void 0,At=void 0,s}function ne(e){const n=Mt.get(e);return void 0===n&&t(75,e),n}function re(t){return{type:t}}const ie=re("SELECTION_CHANGE_COMMAND"),oe=re("SELECTION_INSERT_CLIPBOARD_NODES_COMMAND"),se=re("CLICK_COMMAND"),le=re("DELETE_CHARACTER_COMMAND"),ce=re("INSERT_LINE_BREAK_COMMAND"),ae=re("INSERT_PARAGRAPH_COMMAND"),ue=re("CONTROLLED_TEXT_INSERTION_COMMAND"),fe=re("PASTE_COMMAND"),de=re("REMOVE_TEXT_COMMAND"),he=re("DELETE_WORD_COMMAND"),ge=re("DELETE_LINE_COMMAND"),pe=re("FORMAT_TEXT_COMMAND"),_e=re("UNDO_COMMAND"),ye=re("REDO_COMMAND"),me=re("KEYDOWN_COMMAND"),xe=re("KEY_ARROW_RIGHT_COMMAND"),Ce=re("MOVE_TO_END"),Se=re("KEY_ARROW_LEFT_COMMAND"),Ne=re("MOVE_TO_START"),Te=re("KEY_ARROW_UP_COMMAND"),ve=re("KEY_ARROW_DOWN_COMMAND"),ke=re("KEY_ENTER_COMMAND"),Ee=re("KEY_SPACE_COMMAND"),be=re("KEY_BACKSPACE_COMMAND"),Oe=re("KEY_ESCAPE_COMMAND"),Me=re("KEY_DELETE_COMMAND"),Ae=re("KEY_TAB_COMMAND"),we=re("INSERT_TAB_COMMAND"),De=re("INDENT_CONTENT_COMMAND"),Pe=re("OUTDENT_CONTENT_COMMAND"),Ie=re("DROP_COMMAND"),Le=re("FORMAT_ELEMENT_COMMAND"),Fe=re("DRAGSTART_COMMAND"),Re=re("DRAGOVER_COMMAND"),Ke=re("DRAGEND_COMMAND"),Be=re("COPY_COMMAND"),ze=re("CUT_COMMAND"),We=re("SELECT_ALL_COMMAND"),$e=re("CLEAR_EDITOR_COMMAND"),Ue=re("CLEAR_HISTORY_COMMAND"),Je=re("CAN_REDO_COMMAND"),Ye=re("CAN_UNDO_COMMAND"),je=re("FOCUS_COMMAND"),He=re("BLUR_COMMAND"),Ve=re("KEY_MODIFIER_COMMAND"),Ge=Object.freeze({}),qe=30,Xe=[["keydown",function(t,e){if(Qe=t.timeStamp,Ze=t.key,e.isComposing())return;if(To(e,me,t))return;if(null==t.key)return;if(cn&&_o(t))return ti(e,(()=>{mn(e,an)})),cn=!1,void(an="");if(function(t){return ho(t,"ArrowRight",{shiftKey:"any"})}(t))To(e,xe,t);else if(function(t){return ho(t,"ArrowRight",go)}(t))To(e,Ce,t);else if(function(t){return ho(t,"ArrowLeft",{shiftKey:"any"})}(t))To(e,Se,t);else if(function(t){return ho(t,"ArrowLeft",go)}(t))To(e,Ne,t);else if(function(t){return ho(t,"ArrowUp",{altKey:"any",shiftKey:"any"})}(t))To(e,Te,t);else if(function(t){return ho(t,"ArrowDown",{altKey:"any",shiftKey:"any"})}(t))To(e,ve,t);else if(function(t){return ho(t,"Enter",{altKey:"any",ctrlKey:"any",metaKey:"any",shiftKey:!0})}(t))sn=!0,To(e,ke,t);else if(function(t){return" "===t.key}(t))To(e,Ee,t);else if(function(t){return r&&ho(t,"o",{ctrlKey:!0})}(t))t.preventDefault(),sn=!0,To(e,ce,!0);else if(function(t){return ho(t,"Enter",{altKey:"any",ctrlKey:"any",metaKey:"any"})}(t))sn=!1,To(e,ke,t);else if(function(t){return ho(t,"Backspace",{shiftKey:"any"})||r&&ho(t,"h",{ctrlKey:!0})}(t))_o(t)?To(e,be,t):(t.preventDefault(),To(e,le,!0));else if(function(t){return"Escape"===t.key}(t))To(e,Oe,t);else if(function(t){return ho(t,"Delete",{})||r&&ho(t,"d",{ctrlKey:!0})}(t))!function(t){return"Delete"===t.key}(t)?(t.preventDefault(),To(e,le,!1)):To(e,Me,t);else if(function(t){return ho(t,"Backspace",po)}(t))t.preventDefault(),To(e,he,!0);else if(function(t){return ho(t,"Delete",po)}(t))t.preventDefault(),To(e,he,!1);else if(function(t){return r&&ho(t,"Backspace",{metaKey:!0})}(t))t.preventDefault(),To(e,ge,!0);else if(function(t){return r&&(ho(t,"Delete",{metaKey:!0})||ho(t,"k",{ctrlKey:!0}))}(t))t.preventDefault(),To(e,ge,!1);else if(function(t){return ho(t,"b",go)}(t))t.preventDefault(),To(e,pe,"bold");else if(function(t){return ho(t,"u",go)}(t))t.preventDefault(),To(e,pe,"underline");else if(function(t){return ho(t,"i",go)}(t))t.preventDefault(),To(e,pe,"italic");else if(function(t){return ho(t,"Tab",{shiftKey:"any"})}(t))To(e,Ae,t);else if(function(t){return ho(t,"z",go)}(t))t.preventDefault(),To(e,_e,void 0);else if(function(t){if(r)return ho(t,"z",{metaKey:!0,shiftKey:!0});return ho(t,"y",{ctrlKey:!0})||ho(t,"z",{ctrlKey:!0,shiftKey:!0})}(t))t.preventDefault(),To(e,ye,void 0);else{const n=e._editorState._selection;null===n||or(n)?yo(t)&&(t.preventDefault(),To(e,We,t)):!function(t){return ho(t,"c",go)}(t)?!function(t){return ho(t,"x",go)}(t)?yo(t)&&(t.preventDefault(),To(e,We,t)):(t.preventDefault(),To(e,ze,t)):(t.preventDefault(),To(e,Be,t))}(function(t){return t.ctrlKey||t.shiftKey||t.altKey||t.metaKey})(t)&&To(e,Ve,t)}],["pointerdown",function(t,e){const n=t.target,r=t.pointerType;Jo(n)&&"touch"!==r&&"pen"!==r&&0===t.button&&ti(e,(()=>{Ai(n)||(on=!0)}))}],["compositionstart",function(t,e){ti(e,(()=>{const n=Sr();if(or(n)&&!e.isComposing()){const r=n.anchor,i=n.anchor.getNode();Yi(r.key),(t.timeStamp<Qe+qe||"element"===r.type||!n.isCollapsed()||i.getFormat()!==n.format||Gn(i)&&i.getStyle()!==n.style)&&To(e,ue,L)}}))}],["compositionend",function(t,e){i?ln=!0:l||!s&&!f?ti(e,(()=>{mn(e,t.data)})):(cn=!0,an=t.data)}],["input",function(t,e){t.stopPropagation(),ti(e,(()=>{if(Uo(t.target)&&Ai(t.target))return;const n=Sr(),r=t.data,c=yn(t);if(null!=r&&or(n)&&dn(n,c,r,t.timeStamp,!1)){ln&&(mn(e,r),ln=!1);const c=n.anchor.getNode(),a=Wo(Do(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()&&Gn(c)&&null!==a.anchorNode&&c.getTextContent().slice(0,d)+r+c.getTextContent().slice(d+h)===so(a.anchorNode)||To(e,ue,r);const g=r.length;i&&g>1&&"insertCompositionText"===t.inputType&&!e.isComposing()&&(n.anchor.offset-=g),s||l||f||!e.isComposing()||(Qe=0,Yi(null))}else{lo(!1,e,null!==r?r:void 0),ln&&(mn(e,r||void 0),ln=!1)}!function(){Br();const t=$r();rt(t)}()}),{event:t}),en=null}],["click",function(t,e){ti(e,(()=>{const n=Sr(),r=Wo(Do(e)),i=Nr();if(r)if(or(n)){const e=n.anchor,o=e.getNode();if("element"===e.type&&0===e.offset&&n.isCollapsed()&&!ai(o)&&1===Zi().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!==Zi()&&null!=n;){if(e(n))return n;n=n.getParent()}return null}(o,(t=>ii(t)&&!t.isInline()));ii(t)&&t.select(0)}}}else if("touch"===t.pointerType||"pen"===t.pointerType){const n=r.anchorNode;if(Uo(n)||Ki(n)){eo(Cr(i,r,e,t))}}To(e,se,t)}))}],["cut",Ge],["copy",Ge],["dragstart",Ge],["dragover",Ge],["dragend",Ge],["paste",Ge],["focus",Ge],["blur",Ge],["drop",Ge]];o&&Xe.push(["beforeinput",(e,n)=>function(e,n){const r=e.inputType,o=yn(e);if("deleteCompositionText"===r||i&&No(n))return;if("insertCompositionText"===r)return;ti(n,(()=>{const i=Sr();if("deleteContentBackward"===r){if(null===i){const t=Nr();if(!or(t))return;eo(t.clone())}if(or(i)){const r=i.anchor.key===i.focus.key;if(s=e.timeStamp,"MediaLast"===Ze&&s<Qe+qe&&n.isComposing()&&r){if(Yi(null),Qe=0,setTimeout((()=>{ti(n,(()=>{Yi(null)}))}),qe),or(i)){const e=i.anchor.getNode();e.markDirty(),Gn(e)||t(142),_n(i,e)}}else{Yi(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=!li(So(i.anchor,!0))),!c){To(n,le,!0);const t=Sr();u&&or(t)&&t.isCollapsed()&&(un=t,setTimeout((()=>un=null)))}}return}}var s;if(!or(i))return;const c=e.data;null!==en&&lo(!1,n,en),i.dirty&&null===en||!i.isCollapsed()||ai(i.anchor.getNode())||null===o||i.applyDOMRange(o),en=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":To(n,ue,e);break;case"insertFromComposition":Yi(null),To(n,ue,e);break;case"insertLineBreak":Yi(null),To(n,ce,!1);break;case"insertParagraph":Yi(null),sn&&!l?(sn=!1,To(n,ce,!1)):To(n,ae,void 0);break;case"insertFromPaste":case"insertFromPasteAsQuotation":To(n,fe,e);break;case"deleteByComposition":(function(t,e){return t!==e||ii(t)||ii(e)||!Fi(t)||!Fi(e)})(d,h)&&To(n,de,e);break;case"deleteByDrag":case"deleteByCut":To(n,de,e);break;case"deleteContent":To(n,le,!1);break;case"deleteWordBackward":To(n,he,!0);break;case"deleteWordForward":To(n,he,!1);break;case"deleteHardLineBackward":case"deleteSoftLineBackward":To(n,ge,!0);break;case"deleteContentForward":case"deleteHardLineForward":case"deleteSoftLineForward":To(n,ge,!1);break;case"formatStrikeThrough":To(n,pe,"strikethrough");break;case"formatBold":To(n,pe,"bold");break;case"formatItalic":To(n,pe,"italic");break;case"formatUnderline":To(n,pe,"underline");break;case"historyUndo":To(n,_e,void 0);break;case"historyRedo":To(n,ye,void 0)}else{if("\n"===c)e.preventDefault(),To(n,ce,!1);else if(c===I)e.preventDefault(),To(n,ae,void 0);else if(null==c&&e.dataTransfer){const t=e.dataTransfer.getData("text/plain");e.preventDefault(),i.insertRawText(t)}else null!=c&&dn(i,o,c,e.timeStamp,!0)?(e.preventDefault(),To(n,ue,c)):en=c;tn=e.timeStamp}}))}(e,n)]);let Qe=0,Ze=null,tn=0,en=null;const nn=new WeakMap;let rn=!1,on=!1,sn=!1,ln=!1,cn=!1,an="",un=null,fn=[0,"",0,"root",0];function dn(t,e,n,r,i){const s=t.anchor,l=t.focus,c=s.getNode(),a=$r(),u=Wo(Do(a)),f=null!==u?u.anchorNode:null,d=s.key,h=a.getElementByKey(d),g=n.length;return d!==l.key||!Gn(c)||(!i&&(!o||tn<r+50)||c.isDirty()&&g<2||ro(n))&&s.offset!==l.offset&&!c.isComposing()||Ri(c)||c.isDirty()&&g>1||(i||!o)&&null!==h&&!c.isComposing()&&f!==zi(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=Fi(e);return 0===n?!e.canInsertTextBefore()||!r.canInsertTextBefore()&&!e.isComposing()||i||function(t){const e=t.getPreviousSibling();return(Gn(e)||ii(e)&&e.isInline())&&!e.canInsertTextAfter()}(e):n===e.getTextContentSize()&&(!e.canInsertTextAfter()||!r.canInsertTextAfter()&&!e.isComposing()||i)}(t,c)}function hn(t,e){return Ki(t)&&null!==t.nodeValue&&0!==e&&e!==t.nodeValue.length}function gn(e,n,r){const{anchorNode:i,anchorOffset:o,focusNode:s,focusOffset:l}=e;rn&&(rn=!1,hn(i,o)&&hn(s,l)&&!un)||ti(n,(()=>{if(!r)return void eo(null);if(!Di(n,i,s))return;let c=Sr();if(un&&or(c)&&c.isCollapsed()){const t=c.anchor,e=un.anchor;(t.key===e.key&&t.offset===e.offset+1||1===t.offset&&e.getNode().is(t.getNode().getPreviousSibling()))&&(c=un.clone(),eo(c))}if(un=null,or(c)){const r=c.anchor,i=r.getNode();if(c.isCollapsed()){"Range"===e.type&&e.anchorNode===e.focusNode&&(c.dirty=!0);const o=Do(n).event,s=o?o.timeStamp:performance.now(),[l,a,u,f,d]=fn,h=Zi(),g=!1===n.isComposing()&&""===h.getTextContent();if(s<d+200&&r.offset===u&&r.key===f)pn(c,l,a);else if("text"===r.type)Gn(i)||t(141),_n(c,i);else if("element"===r.type&&!g){ii(i)||t(259);const e=r.getNode();e.isEmpty()?function(t,e){const n=e.getTextFormat(),r=e.getTextStyle();pn(t,n,r)}(c,e):pn(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(Gn(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}}To(n,ie,void 0)}))}function pn(t,e,n){t.format===e&&t.style===n||(t.format=e,t.style=n,t.dirty=!0)}function _n(t,e){pn(t,e.getFormat(),e.getStyle())}function yn(t){if(!t.getTargetRanges)return null;const e=t.getTargetRanges();return 0===e.length?null:e[0]}function mn(t,e){const n=t._compositionKey;if(Yi(null),null!==n&&null!=e){if(""===e){const e=Hi(n),r=zi(t.getElementByKey(n));return void(null!==r&&null!==r.nodeValue&&Gn(e)&&co(e,r.nodeValue,null,null,!0))}if("\n"===e[e.length-1]){const e=Sr();if(or(e)){const n=e.focus;return e.anchor.set(n.key,n.offset,n.type),void To(t,ke,null)}}}lo(!0,t,e)}function xn(t){let e=t.__lexicalEventHandles;return void 0===e&&(e=[],t.__lexicalEventHandles=e),e}const Cn=new Map;function Sn(t){const e=$o(t.target);if(null===e)return;const n=Ii(e.anchorNode);if(null===n)return;on&&(on=!1,ti(n,(()=>{const r=Nr(),i=e.anchorNode;if(Uo(i)||Ki(i)){eo(Cr(r,e,n,t))}})));const r=io(n),i=r[r.length-1],o=i._key,s=Cn.get(o),l=s||i;l!==n&&gn(e,l,!1),gn(e,n,!0),n!==i?Cn.set(o,n):s&&Cn.delete(o)}function Nn(t){t._lexicalHandled=!0}function Tn(t){return!0===t._lexicalHandled}const vn=()=>{};function kn(e){const n=e.ownerDocument,r=nn.get(n);if(void 0===r)return void vn();const i=r-1;i>=0||t(164),nn.set(n,i),0===i&&n.removeEventListener("selectionchange",Sn);const o=Li(e);Pi(o)?(!function(t){if(null!==t._parentEditor){const e=io(t),n=e[e.length-1]._key;Cn.get(n)===t&&Cn.delete(n)}else Cn.delete(t._key)}(o),e.__lexicalEditor=null):o&&t(198);const s=xn(e);for(let t=0;t<s.length;t++)s[t]();e.__lexicalEventHandles=[]}function En(t,e,n){Br();const r=t.__key,i=t.getParent();if(null===i)return;const o=function(t){const e=Sr();if(!or(e)||!ii(t))return e;const{anchor:n,focus:r}=e,i=n.getNode(),o=r.getNode();Ao(i,t)&&n.set(t.__key,0,"element");Ao(o,t)&&r.set(t.__key,0,"element");return e}(t);let s=!1;if(or(o)&&e){const e=o.anchor,n=o.focus;e.key===r&&(kr(e,t,i,t.getPreviousSibling(),t.getNextSibling()),s=!0),n.key===r&&(kr(n,t,i,t.getPreviousSibling(),t.getNextSibling()),s=!0)}else lr(o)&&e&&t.isSelected()&&t.selectPrevious();if(or(o)&&e&&!s){const e=t.getIndexWithinParent();Ui(t),Tr(o,i,e,-1)}else Ui(t);n||Io(i)||i.canBeEmpty()||!i.isEmpty()||En(i,e),e&&o&&ai(i)&&i.isEmpty()&&i.selectEnd()}class bn{static getType(){const{ownNodeType:e}=is(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}),$i(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=Hi(t);if(null===e)break;t=e.__parent}return!1}isSelected(t){const e=t||Sr();if(null==e)return!1;const n=e.getNodes().some((t=>t.__key===this.__key));if(Gn(this))return n;if(or(e)&&"element"===e.anchor.type&&"element"===e.focus.type){if(e.isCollapsed())return!1;const t=this.getParent();if(li(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:Hi(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(Io(n))return ii(e)||e===this&&li(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:Hi(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:Hi(t)}getNextSiblings(){const t=[];let e=this.getNextSibling();for(;null!==e;)t.push(e),e=e.getNextSibling();return t}getCommonAncestor(t){const e=ii(this)?this:this.getParent(),n=ii(t)?t:t.getParent(),r=e&&n?Fs(e,n):null;return r?r.commonAncestor:null}is(t){return null!=t&&this.__key===t.__key}isBefore(e){const n=Fs(this,e);return null!==n&&("descendant"===n.type||("branch"===n.type?-1===Ps(n):("same"!==n.type&&"ancestor"!==n.type&&t(279),!1)))}isParentOf(t){const e=Fs(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=ii(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=$r()._dirtyLeaves;return null!==t&&t.has(this.__key)}getLatest(){const e=Hi(this.__key);return null===e&&t(113),e}getWritable(){Br();const t=Wr(),e=$r(),n=t._nodeMap,r=this.__key,i=this.getLatest(),o=e._cloneNotNeeded,s=Sr();if(null!==s&&s.setCachedNodes(null),o.has(r))return Ji(i),i;const l=ts(i);return o.add(r),Ji(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 ut(n).flatKeys)t in e&&(void 0!==i&&i!==r||(i={...r}),i[t]=e[t]);return(n.__state||i)&&at(t).updateFromJSON(i),n}(this,t)}static transform(){return null}remove(t){En(this,!0,t)}replace(e,n){Br();let r=Sr();null!==r&&(r=r.clone()),Ro(this,e);const i=this.getLatest(),o=this.__key,s=e.__key,l=e.getWritable(),c=this.getParentOrThrow().getWritable(),a=c.__size;Ui(l);const u=i.getPreviousSibling(),f=i.getNextSibling(),d=i.__prev,h=i.__next,g=i.__parent;if(En(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&&(ii(this)&&ii(l)||t(139),this.getChildren().forEach((t=>{l.append(t)}))),or(r)){eo(r);const t=r.anchor,e=r.focus;t.key===o&&rr(t,l),e.key===o&&rr(e,l)}return ji()===o&&Yi(s),l}insertAfter(t,e=!0){Br(),Ro(this,t);const n=this.getWritable(),r=t.getWritable(),i=r.getParent(),o=Sr();let s=!1,l=!1;if(null!==i){const e=t.getIndexWithinParent();if(Ui(r),or(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&&or(o)){const t=this.getIndexWithinParent();Tr(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){Br(),Ro(this,t);const n=this.getWritable(),r=t.getWritable(),i=r.__key;Ui(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=Sr();if(e&&or(a)){Tr(a,this.getParentOrThrow(),c)}return t}isParentRequired(){return!1}createParentElementNode(){return Si()}selectStart(){return this.selectPrevious()}selectEnd(){return this.selectNext(0,0)}selectPrevious(t,e){Br();const n=this.getPreviousSibling(),r=this.getParentOrThrow();if(null===n)return r.select(0,0);if(ii(n))return n.select();if(!Gn(n)){const t=n.getIndexWithinParent()+1;return r.select(t,t)}return n.select(t,e)}selectNext(t,e){Br();const n=this.getNextSibling(),r=this.getParentOrThrow();if(null===n)return r.select();if(ii(n))return n.select(0,0);if(!Gn(n)){const t=n.getIndexWithinParent();return r.select(t,t)}return n.select(t,e)}markDirty(){this.getWritable()}reconcileObservedMutation(t,e){this.markDirty()}}class On extends bn{static getType(){return"linebreak"}static clone(t){return new On(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&&Ho(e)){const n=e.firstChild;if(n===t||n.nextSibling===t&&Dn(n)){const n=e.lastChild;if(n===t||n.previousSibling===t&&Dn(n))return!0}}return!1}(t)||function(t){const e=t.parentElement;if(null!==e&&Ho(e)){const n=e.firstChild;if(n===t||n.nextSibling===t&&Dn(n))return!1;const r=e.lastChild;if(r===t||r.previousSibling===t&&Dn(r))return!0}return!1}(t)?null:{conversion:Mn,priority:0}}}static importJSON(t){return An().updateFromJSON(t)}}function Mn(t){return{node:An()}}function An(){return Fo(new On)}function wn(t){return t instanceof On}function Dn(t){return Ki(t)&&/^( |\t|\r?\n)+$/.test(t.textContent||"")}function Pn(t,e){return 16&e?"code":e&k?"mark":32&e?"sub":64&e?"sup":null}function In(t,e){return 1&e?"strong":2&e?"em":"span"}function Ln(t,e,n,r,i){const o=r.classList;let s=mo(i,"base");void 0!==s&&o.add(...s),s=mo(i,"underlineStrikethrough");let l=!1;const c=e&v&&e&T;void 0!==s&&(n&v&&n&T?(l=!0,c||o.add(...s)):c&&o.remove(...s));for(const t in z){const r=z[t];if(s=mo(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 Fn(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 Rn(t,e,n,r,i,o){Fn(i,t,e);const s=o.theme.text;void 0!==s&&Ln(0,0,r,t,s)}function Kn(t,e){const n=document.createElement(e);return n.appendChild(t),n}class Bn extends bn{static getType(){return"text"}static clone(t){return new Bn(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 Y[t.__mode]}getStyle(){return this.getLatest().__style}isToken(){return 1===this.getLatest().__mode}isComposing(){return this.__key===ji()}isSegmented(){return 2===this.getLatest().__mode}isDirectionless(){return!!(1&this.getLatest().__detail)}isUnmergeable(){return!!(2&this.getLatest().__detail)}hasFormat(t){const e=z[t];return!!(this.getFormat()&e)}isSimpleText(){return"text"===this.__type&&0===this.__mode}getTextContent(){return this.getLatest().__text}getFormatFlags(t,e){return Wi(this.getLatest().__format,t,e)}canHaveFormat(){return!0}isInline(){return!0}createDOM(t,e){const n=this.__format,r=Pn(0,n),i=In(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));Rn(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=Pn(0,o),c=Pn(0,s),a=In(0,o),u=In(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 Rn(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)),Fn(i,f,this);const d=r.theme.text;void 0!==d&&o!==s&&Ln(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:Jn,priority:0}),b:()=>({conversion:Wn,priority:0}),code:()=>({conversion:Hn,priority:0}),em:()=>({conversion:Hn,priority:0}),i:()=>({conversion:Hn,priority:0}),mark:()=>({conversion:Hn,priority:0}),s:()=>({conversion:Hn,priority:0}),span:()=>({conversion:zn,priority:0}),strong:()=>({conversion:Hn,priority:0}),sub:()=>({conversion:Hn,priority:0}),sup:()=>({conversion:Hn,priority:0}),u:()=>({conversion:Hn,priority:0})}}static importJSON(t){return Vn().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 Uo(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=Kn(n,"b")),this.hasFormat("italic")&&(n=Kn(n,"i")),this.hasFormat("strikethrough")&&(n=Kn(n,"s")),this.hasFormat("underline")&&(n=Kn(n,"u")),{element:n}}exportJSON(){return{detail:this.getDetail(),format:this.getFormat(),mode:this.getMode(),style:this.getStyle(),text:this.getTextContent(),...super.exportJSON()}}selectionTransform(t,e){}setFormat(t){const e=this.getWritable();return e.__format="string"==typeof t?z[t]:t,e}setDetail(t){const e=this.getWritable();return e.__detail="string"==typeof t?W[t]:t,e}setStyle(t){const e=this.getWritable();return e.__style=t,e}toggleFormat(t){const e=Wi(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=J[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){Br();let n=t,r=e;const i=Sr(),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(!or(i))return yr(s,n,s,r,"text","text");{const t=ji();t!==i.anchor.key&&t!==i.focus.key||Yi(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=Sr();if(r&&or(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){Br();const e=this.getLatest(),n=e.getTextContent();if(""===n)return[];const r=e.__key,i=ji(),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=Sr();if(or(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=Vn(a),f.__format=d,f.__style=h,f.__detail=g,f.__state=pt(e,f),p=!0):f=e.setTextContent(a);const x=[f];for(let t=1;t<c;t++){const n=Vn(s[t]);n.__format=d,n.__style=h,n.__detail=g,n.__state=pt(e,n);const o=n.__key;i===r&&Yi(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&&Ji(e);null!==n&&Ji(n)}(this);const t=u.getWritable(),e=this.getIndexWithinParent();p?(t.splice(e,0,x),this.remove()):t.splice(e,1,x),or(m)&&Tr(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;ji()===i&&Yi(r);const l=Sr();if(or(l)){const t=l.anchor,o=l.focus;null!==t&&t.key===i&&Er(t,n,r,e,s),null!==o&&o.key===i&&Er(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 zn(t){return{forChild:qn(t.style),node:null}}function Wn(t){const e=t,n="normal"===e.style.fontWeight;return{forChild:qn(e.style,n?void 0:"bold"),node:null}}const $n=new WeakMap;function Un(t){if(!Uo(t))return!1;if("PRE"===t.nodeName)return!0;const e=t.style.whiteSpace;return"string"==typeof e&&e.startsWith("pre")}function Jn(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=$n.get(n))&&!Un(n);)r.push(n),n=n.parentNode;const i=void 0===e?n:e;for(let t=0;t<r.length;t++)$n.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(An()):"\t"===n?e.push(Qn()):""!==n&&e.push(Vn(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=Yn(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=Yn(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:Vn(r)}}function Yn(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,Uo(n)){const t=n.style.display;if(""===t&&!jo(n)||""!==t&&!t.startsWith("inline"))return null}let r=n;for(;null!==(r=e?n.firstChild:n.lastChild);)n=r;if(Ki(n))return n;if("BR"===n.nodeName)return null}}const jn={code:"code",em:"italic",i:"italic",mark:"highlight",s:"strikethrough",strong:"bold",sub:"subscript",sup:"superscript",u:"underline"};function Hn(t){const e=jn[t.nodeName.toLowerCase()];return void 0===e?{node:null}:{forChild:qn(t.style,e),node:null}}function Vn(t=""){return Fo(new Bn(t))}function Gn(t){return t instanceof Bn}function qn(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=>Gn(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 Xn extends Bn{static getType(){return"tab"}static clone(t){return new Xn(t.__key)}constructor(t){super("\t",t),this.__detail=2}static importDOM(){return null}createDOM(t){const e=super.createDOM(t),n=mo(t.theme,"tab");if(void 0!==n){e.classList.add(...n)}return e}static importJSON(t){return Qn().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 Qn(){return Fo(new Xn)}function Zn(t){return t instanceof Xn}class tr{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 Ds(js(Rs(this,"next")),js(Rs(t,"next")))<0}getNode(){const e=Hi(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,Kr()||(ji()===o&&Yi(t),null!==i&&(i.setCachedNodes(null),i.dirty=!0)))}}function er(t,e,n){return new tr(t,e,n)}function nr(t,e){let n=e.__key,r=t.offset,i="element";if(Gn(e)){i="text";const t=e.getTextContentSize();r>t&&(r=t)}else if(!ii(e)){const t=e.getNextSibling();if(Gn(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 rr(t,e){if(ii(e)){const n=e.getLastDescendant();ii(n)||Gn(n)?nr(t,n):nr(t,e)}else nr(t,e)}class ir{constructor(t){this._cachedNodes=null,this._nodes=t,this.dirty=!1}getCachedNodes(){return this._cachedNodes}setCachedNodes(t){this._cachedNodes=t}is(t){if(!lr(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 ir(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(Gn(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=Hi(t);null!==e&&n.push(e)}return Kr()||(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((Sr()||Nr())===this&&t[0]){const e=xs(t[0],"next");Bs(As(e,e))}for(const e of t)e.remove()}}function or(t){return t instanceof sr}class sr{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!!or(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(ps(n)){const{origin:t}=n;0===e.length?i.add(t):(o.add(t),e.push(t))}else{const{origin:t}=n;ii(t)&&o.has(t)||e.push(t)}r&&e.push(r.caret.origin);if(gs(t.focus)&&ii(t.focus.origin)&&null===t.focus.getNodeAtCaret())for(let n=Ts(t.focus.origin,"previous");ps(n)&&i.has(n.origin)&&!n.origin.isEmpty()&&n.origin.is(e[e.length-1]);n=ks(n))i.delete(n.origin),e.pop();for(;e.length>1;){const t=e[e.length-1];if(!ii(t)||o.has(t)||t.isEmpty()||i.has(t))break;e.pop()}if(0===e.length&&t.isCollapsed()){const n=js(t.anchor),r=js(t.anchor.getFlipped()),i=t=>hs(t)?t.origin:t.getNodeAtCaret(),o=i(n)||i(r)||(t.anchor.getNodeAtCaret()?n.origin:r.origin);e.push(o)}return e}(Gs(Ws(this),"next"));return Kr()||(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]=ar(this);let c="",a=!0;for(let u=0;u<t.length;u++){const f=t[u];if(ii(f)&&!f.isInline())a||(c+="\n"),a=!f.isEmpty();el