UNPKG

lexical

Version:

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

9 lines (8 loc) 129 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. * */ 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),s=!(!e||!("InputEvent"in window)||n)&&"getTargetRanges"in new window.InputEvent("input"),o=e&&/Version\/[\d.]+.*Safari/.test(navigator.userAgent),l=e&&/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream,c=e&&/Android/.test(navigator.userAgent),a=e&&/^(?=.*Chrome).*/i.test(navigator.userAgent),u=e&&c&&a,f=e&&/AppleWebKit\/[\d.]+/.test(navigator.userAgent)&&!a;function d(...t){const e=[];for(const n of t)if(n&&"string"==typeof n)for(const[t]of n.matchAll(/\S+/g))e.push(t);return e}const h=1,g=3,_=9,p=11,y=0,m=1,x=2,C=0,S=1,v=2,k=1,T=2,N=4,b=8,w=16,E=32,M=64,O=128,A=1792|(112|(3|N|b)|O),D=1,P=2,F=3,L=4,I=5,K=6,z=o||l||f?" ":"​",R="\n\n",B=i?" ":z,W="֑-߿יִ-﷽ﹰ-ﻼ",J="A-Za-zÀ-ÖØ-öø-ʸ̀-֐ࠀ-῿‎Ⰰ-﬜︀-﹯﻽-￿",$=new RegExp("^[^"+J+"]*["+W+"]"),j=new RegExp("^[^"+W+"]*["+J+"]"),U={bold:1,capitalize:1024,code:16,highlight:O,italic:2,lowercase:256,strikethrough:N,subscript:32,superscript:64,underline:b,uppercase:512},V={directionless:1,unmergeable:2},Y={center:P,end:K,justify:L,left:D,right:F,start:I},H={[P]:"center",[K]:"end",[L]:"justify",[D]:"left",[F]:"right",[I]:"start"},q={normal:0,segmented:2,token:1},G={[C]:"normal",[v]:"segmented",[S]:"token"},X="$",Q="$config";function Z(t,e,n,r,i,s){let o=t.getFirstChild();for(;null!==o;){const t=o.__key;o.__parent===e&&(xi(o)&&Z(o,t,n,r,i,s),n.has(t)||s.delete(t),i.push(t)),o=o.getNextSibling()}}const tt=100;let et=!1,nt=0;function rt(t){nt=t.timeStamp}function it(t,e,n){const r="BR"===t.nodeName,i=e.__lexicalLineBreak;return i&&(t===i||r&&t.previousSibling===i)||r&&void 0!==ks(t,n)}function st(t,e,n){const r=xo(co(n));let i=null,s=null;null!==r&&r.anchorNode===t&&(i=r.anchorOffset,s=r.focusOffset);const o=t.nodeValue;null!==o&&Is(e,o,i,s,!1)}function ot(t,e,n){if(_r(t)){const e=t.anchor.getNode();if(e.is(n)&&t.format!==e.getFormat())return!1}return fs(e)&&n.isAttached()}function lt(t,e,n,r){for(let i=t;i&&!Ko(i);i=eo(i)){const t=ks(i,e);if(void 0!==t){const e=Ss(t,n);if(e)return vi(e)||!ko(i)?void 0:[i,e]}else if(i===r)return[r,Es(n)]}}function ct(t,e,n){et=!0;const r=performance.now()-nt>tt;try{_i(t,(()=>{const s=Pr()||function(t){return t.getEditorState().read((()=>{const t=Pr();return null!==t?t.clone():null}))}(t),o=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,_=lt(g,t,c,l);if(!_)continue;const[p,y]=_;if("characterData"===h)r&&sr(y)&&fs(g)&&ot(s,g,y)&&st(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],s=vs(r),o=r.parentNode;if(null!=o&&r!==a&&null===s&&!it(r,o,t)){if(i){const t=(ko(r)?r.innerText:null)||r.nodeValue;t&&(f+=t)}o.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];(it(r,g,t)||a===r)&&(g.appendChild(r),e++)}r!==e&&o.set(p,y)}}}if(o.size>0)for(const[e,n]of o)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],s=n.parentNode;null==s||"BR"!==n.nodeName||it(n,i,t)||s.removeChild(n)}}n.takeRecords()}null!==s&&(u&&Ms(s),i&&Xs(t)&&s.insertRawText(f))}))}finally{et=!1}}function at(t){const e=t._observer;if(null!==e){ct(t,e.takeRecords(),e)}}function ut(t){!function(t){0===nt&&co(t).addEventListener("textInput",rt,!0)}(t),t._observer=new MutationObserver(((e,n)=>{ct(t,e,n)}))}class ft{constructor(t,e){this.key=t,this.parse=e.parse.bind(e),this.unparse=(e.unparse||St).bind(e),this.isEqual=(e.isEqual||Object.is).bind(e),this.defaultValue=this.parse(void 0)}}function dt(t,e){return new ft(t,e)}function ht(t,e,n="latest"){const r=("latest"===n?t.getLatest():t).__state;return r?r.getValue(e):e.defaultValue}function gt(t,e,n){const r=ht(t,n,"direct"),i=ht(e,n,"direct");return n.isEqual(r,i)?null:[r,i]}function _t(t,e,n){let r;if(Zr(),"function"==typeof n){const i=t.getLatest(),s=ht(i,e);if(r=n(s),e.isEqual(s,r))return i}else r=n;const i=t.getWritable();return mt(i).updateFromKnown(e,r),i}function pt(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}=Ro(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 yt{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:s}=this.sharedNodeState,o=void 0!==i?i:function(t,e,n){let r=n.size;if(e)for(const i in e){const e=t.get(i);e&&n.has(e)||r++}return r}(s,n,r);this.size=o}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 Ct(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 yt(t,e,function(t,e,n){let r;if(n)for(const[i,s]of Object.entries(n)){const n=t.get(i);n?e.has(n)||e.set(n,n.parse(s)):(r=r||{},r[i]=s)}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=Ct(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 mt(t){const e=t.getWritable(),n=e.__state?e.__state.getWritable(e):new yt(e,xt(e));return e.__state=n,n}function xt(t){return t.__state?t.__state.sharedNodeState:ts(Oo(),t.getType()).sharedNodeState}function Ct(t){if(t)for(const e in t)return t}function St(t){return t}function vt(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 kt(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 Tt(t,e){const n=t.__state;return n&&n.node===t?n.getWritable(e):n}function Nt(t,e){const n=t.__mode,r=t.__format,i=t.__style,s=e.__mode,o=e.__format,l=e.__style,c=t.__state,a=e.__state;return(null===n||n===s)&&(null===r||r===o)&&(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&&vt(n,t,e)||e&&vt(n,e,t)||t&&kt(n,t,e)||e&&kt(n,e,t))}(c,a))}function bt(t,e){const n=t.mergeWithSibling(e),r=ni()._normalizedNodes;return r.add(t.__key),r.add(e.__key),n}function wt(t){let e,n,r=t;if(""!==r.__text||!r.isSimpleText()||r.isUnmergeable()){for(;null!==(e=r.getPreviousSibling())&&sr(e)&&e.isSimpleText()&&!e.isUnmergeable();){if(""!==e.__text){if(Nt(e,r)){r=bt(e,r);break}break}e.remove()}for(;null!==(n=r.getNextSibling())&&sr(n)&&n.isSimpleText()&&!n.isUnmergeable();){if(""!==n.__text){if(Nt(r,n)){r=bt(r,n);break}break}n.remove()}}else r.remove()}function Et(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),sr(r)){t.set(r.__key,i?r.getTextContentSize():0,"text",!0);break}if(!xi(r))break;t.set(r.__key,i?r.getChildrenSize():0,"element",!0)}}let Ot,At,Dt,Pt,Ft,Lt,It,Kt,zt,Rt,Bt="",Wt="",Jt=null,$t="",jt="",Ut=!1,Vt=!1,Yt=null;function Ht(t,e){const n=It.get(t);if(null!==e){const n=fe(t);n.parentNode===e&&e.removeChild(n)}if(Kt.has(t)||At._keyToDOMMap.delete(t),xi(n)){const t=oe(n,It);qt(t,0,t.length-1,null)}void 0!==n&&Ys(Rt,Dt,Pt,n,"destroyed")}function qt(t,e,n,r){let i=e;for(;i<=n;++i){const e=t[i];void 0!==e&&Ht(e,r)}}function Gt(t,e){t.setProperty("text-align",e)}const Xt="40px";function Qt(t,e){const n=Ot.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")||Xt;t.style.setProperty("padding-inline-start",0===e?"":`calc(${e} * ${r})`)}function Zt(t,e){const n=t.style;0===e?Gt(n,""):e===D?Gt(n,"left"):e===P?Gt(n,"center"):e===F?Gt(n,"right"):e===L?Gt(n,"justify"):e===I?Gt(n,"start"):e===K&&Gt(n,"end")}function te(e,n){const r=Kt.get(e);void 0===r&&t(60);const i=r.createDOM(Ot,At);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,At),sr(r)?i.setAttribute("data-lexical-text","true"):vi(r)&&i.setAttribute("data-lexical-decorator","true"),xi(r)){const t=r.__indent,e=r.__size;if(0!==t&&Qt(i,t),0!==e){const t=e-1;!function(t,e,n,r){const i=Wt;Wt="",ee(t,n,0,e,n.getDOMSlot(r)),ie(n,r),Wt=i}(oe(r,Kt),t,r,i)}const n=r.__format;0!==n&&Zt(i,n),r.isInline()||re(null,r,i),Zs(r)&&(Bt+=R,jt+=R)}else{const t=r.getTextContent();if(vi(r)){const t=r.decorate(At,Ot);null!==t&&ce(e,t),i.contentEditable="false"}else sr(r)&&(r.isDirectionless()||(Wt+=t));Bt+=t,jt+=t}return null!==n&&n.insertChild(i),Ys(Rt,Dt,Pt,r,"created"),i}function ee(t,e,n,r,i){const s=Bt;Bt="";let o=n;for(;o<=r;++o){te(t[o],i);const e=Kt.get(t[o]);null!==e&&sr(e)&&(null===Jt&&(Jt=e.getFormat()),""===$t&&($t=e.getStyle()))}Zs(e)&&(Bt+=R);i.element.__lexicalTextContent=Bt,Bt=s+Bt}function ne(t,e){if(t){const n=t.__last;if(n){const t=e.get(n);if(t)return Wn(t)?"line-break":vi(t)&&t.isInline()?"decorator":null}return"empty"}return null}function re(t,e,n){const r=ne(t,It),i=ne(e,Kt);r!==i&&e.getDOMSlot(n).setManagedLineBreak(i)}function ie(t,e){const n=e.__lexicalDirTextContent||"",r=e.__lexicalDir||"";if(n!==Wt||r!==Yt){const n=""===Wt,i=n?Yt:function(t){if($.test(t))return"rtl";if(j.test(t))return"ltr";return null}(Wt);if(i!==r){const s=e.classList,o=Ot.theme;let l=null!==r?o[r]:void 0,c=null!==i?o[i]:void 0;if(void 0!==l){if("string"==typeof l){const t=d(l);l=o[r]=t}s.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=o[i]=t}void 0!==c&&s.add(...c)}e.dir=i}if(!Vt){t.getWritable().__dir=i}}Yt=i,e.__lexicalDirTextContent=Wt,e.__lexicalDir=i}}function se(e,n,r){const i=Wt;var s;Wt="",Jt=null,$t="",function(e,n,r){const i=Bt,s=e.__size,o=n.__size;Bt="";const l=r.element;if(1===s&&1===o){const t=e.__first,r=n.__first;if(t===r)le(t,l);else{const e=fe(t),n=te(r,null);try{l.replaceChild(n,e)}catch(i){if("object"==typeof i&&null!=i){const s=`${i.toString()} Parent: ${l.tagName}, new child: {tag: ${n.tagName} key: ${r}}, old child: {tag: ${e.tagName}, key: ${t}}.`;throw new Error(s)}throw i}Ht(t,null)}const i=Kt.get(r);sr(i)&&(null===Jt&&(Jt=i.getFormat()),""===$t&&($t=i.getStyle()))}else{const i=oe(e,It),c=oe(n,Kt);if(i.length!==s&&t(227),c.length!==o&&t(228),0===s)0!==o&&ee(c,n,0,o-1,r);else if(0===o){if(0!==s){const t=null==r.after&&null==r.before&&null==r.element.__lexicalLineBreak;qt(i,0,s-1,t?null:l),t&&(l.textContent="")}}else!function(t,e,n,r,i,s){const o=r-1,l=i-1;let c,a,u=s.getFirstChild(),f=0,d=0;for(;f<=o&&d<=l;){const t=e[f],r=n[d];if(t===r)u=ae(le(r,s.element)),f++,d++;else{void 0===c&&(c=new Set(e)),void 0===a&&(a=new Set(n));const i=a.has(t),o=c.has(r);if(i)if(o){const t=to(At,r);t===u?u=ae(le(r,s.element)):(s.withBefore(u).insertChild(t),le(r,s.element)),f++,d++}else te(r,s.withBefore(u)),d++;else u=ae(fe(t)),Ht(t,s.element),f++}const i=Kt.get(r);null!==i&&sr(i)&&(null===Jt&&(Jt=i.getFormat()),""===$t&&($t=i.getStyle()))}const h=f>o,g=d>l;if(h&&!g){const e=n[l+1],r=void 0===e?null:At.getElementByKey(e);ee(n,t,d,l,s.withBefore(r))}else g&&!h&&qt(e,f,o,s.element)}(n,i,c,s,o,r)}Zs(n)&&(Bt+=R);l.__lexicalTextContent=Bt,Bt=i+Bt}(e,n,n.getDOMSlot(r)),ie(n,r),s=n,null==Jt||Jt===s.__textFormat||Vt||s.setTextFormat(Jt),function(t){""===$t||$t===t.__textStyle||Vt||t.setTextStyle($t)}(n),Wt=i}function oe(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 le(e,n){const r=It.get(e);let i=Kt.get(e);void 0!==r&&void 0!==i||t(61);const s=Ut||Lt.has(e)||Ft.has(e),o=to(At,e);if(r===i&&!s){if(xi(r)){const t=o.__lexicalTextContent;void 0!==t&&(Bt+=t,jt+=t);const e=o.__lexicalDirTextContent;void 0!==e&&(Wt+=e)}else{const t=r.getTextContent();sr(r)&&!r.isDirectionless()&&(Wt+=t),jt+=t,Bt+=t}return o}if(r!==i&&s&&Ys(Rt,Dt,Pt,i,"updated"),i.updateDOM(r,o,Ot)){const r=te(e,null);return null===n&&t(62),n.replaceChild(r,o),Ht(e,null),r}if(xi(r)&&xi(i)){const t=i.__indent;t!==r.__indent&&Qt(o,t);const e=i.__format;e!==r.__format&&Zt(o,e),s&&(se(r,i,o),Ti(i)||i.isInline()||re(r,i,o)),Zs(i)&&(Bt+=R,jt+=R)}else{const t=i.getTextContent();if(vi(i)){const t=i.decorate(At,Ot);null!==t&&ce(e,t)}else sr(i)&&!i.isDirectionless()&&(Wt+=t);Bt+=t,jt+=t}if(!Vt&&Ti(i)&&i.__cachedText!==jt){const t=i.getWritable();t.__cachedText=jt,i=t}return o}function ce(t,e){let n=At._pendingDecorators;const r=At._decorators;if(null===n){if(r[t]===e)return;n=Ns(At)}n[t]=e}function ae(t){let e=t.nextSibling;return null!==e&&e===At._blockCursorElement&&(e=e.nextSibling),e}function ue(t,e,n,r,i,s){Bt="",jt="",Wt="",Ut=r===x,Yt=null,At=n,Ot=n._config,Dt=n._nodes,Pt=At._listeners.mutation,Ft=i,Lt=s,It=t._nodeMap,Kt=e._nodeMap,Vt=e._readOnly,zt=new Map(n._keyToDOMMap);const o=new Map;return Rt=o,le("root",null),At=void 0,Dt=void 0,Ft=void 0,Lt=void 0,It=void 0,Kt=void 0,Ot=void 0,zt=void 0,Rt=void 0,o}function fe(e){const n=zt.get(e);return void 0===n&&t(75,e),n}function de(t){return{type:t}}const he=de("SELECTION_CHANGE_COMMAND"),ge=de("SELECTION_INSERT_CLIPBOARD_NODES_COMMAND"),_e=de("CLICK_COMMAND"),pe=de("DELETE_CHARACTER_COMMAND"),ye=de("INSERT_LINE_BREAK_COMMAND"),me=de("INSERT_PARAGRAPH_COMMAND"),xe=de("CONTROLLED_TEXT_INSERTION_COMMAND"),Ce=de("PASTE_COMMAND"),Se=de("REMOVE_TEXT_COMMAND"),ve=de("DELETE_WORD_COMMAND"),ke=de("DELETE_LINE_COMMAND"),Te=de("FORMAT_TEXT_COMMAND"),Ne=de("UNDO_COMMAND"),be=de("REDO_COMMAND"),we=de("KEYDOWN_COMMAND"),Ee=de("KEY_ARROW_RIGHT_COMMAND"),Me=de("MOVE_TO_END"),Oe=de("KEY_ARROW_LEFT_COMMAND"),Ae=de("MOVE_TO_START"),De=de("KEY_ARROW_UP_COMMAND"),Pe=de("KEY_ARROW_DOWN_COMMAND"),Fe=de("KEY_ENTER_COMMAND"),Le=de("KEY_SPACE_COMMAND"),Ie=de("KEY_BACKSPACE_COMMAND"),Ke=de("KEY_ESCAPE_COMMAND"),ze=de("KEY_DELETE_COMMAND"),Re=de("KEY_TAB_COMMAND"),Be=de("INSERT_TAB_COMMAND"),We=de("INDENT_CONTENT_COMMAND"),Je=de("OUTDENT_CONTENT_COMMAND"),$e=de("DROP_COMMAND"),je=de("FORMAT_ELEMENT_COMMAND"),Ue=de("DRAGSTART_COMMAND"),Ve=de("DRAGOVER_COMMAND"),Ye=de("DRAGEND_COMMAND"),He=de("COPY_COMMAND"),qe=de("CUT_COMMAND"),Ge=de("SELECT_ALL_COMMAND"),Xe=de("CLEAR_EDITOR_COMMAND"),Qe=de("CLEAR_HISTORY_COMMAND"),Ze=de("CAN_REDO_COMMAND"),tn=de("CAN_UNDO_COMMAND"),en=de("FOCUS_COMMAND"),nn=de("BLUR_COMMAND"),rn=de("KEY_MODIFIER_COMMAND"),sn=Object.freeze({}),on=30,ln=[["keydown",function(t,e){if(cn=t.timeStamp,an=t.key,e.isComposing())return;if(Qs(e,we,t))return;if(null==t.key)return;if(yn&&$s(t))return _i(e,(()=>{wn(e,mn)})),yn=!1,void(mn="");if(function(t){return Bs(t,"ArrowRight",{shiftKey:"any"})}(t))Qs(e,Ee,t);else if(function(t){return Bs(t,"ArrowRight",Ws)}(t))Qs(e,Me,t);else if(function(t){return Bs(t,"ArrowLeft",{shiftKey:"any"})}(t))Qs(e,Oe,t);else if(function(t){return Bs(t,"ArrowLeft",Ws)}(t))Qs(e,Ae,t);else if(function(t){return Bs(t,"ArrowUp",{altKey:"any",shiftKey:"any"})}(t))Qs(e,De,t);else if(function(t){return Bs(t,"ArrowDown",{altKey:"any",shiftKey:"any"})}(t))Qs(e,Pe,t);else if(function(t){return Bs(t,"Enter",{altKey:"any",ctrlKey:"any",metaKey:"any",shiftKey:!0})}(t))_n=!0,Qs(e,Fe,t);else if(function(t){return" "===t.key}(t))Qs(e,Le,t);else if(function(t){return r&&Bs(t,"o",{ctrlKey:!0})}(t))t.preventDefault(),_n=!0,Qs(e,ye,!0);else if(function(t){return Bs(t,"Enter",{altKey:"any",ctrlKey:"any",metaKey:"any"})}(t))_n=!1,Qs(e,Fe,t);else if(function(t){return Bs(t,"Backspace",{shiftKey:"any"})||r&&Bs(t,"h",{ctrlKey:!0})}(t))$s(t)?Qs(e,Ie,t):(t.preventDefault(),Qs(e,pe,!0));else if(function(t){return"Escape"===t.key}(t))Qs(e,Ke,t);else if(function(t){return Bs(t,"Delete",{})||r&&Bs(t,"d",{ctrlKey:!0})}(t))!function(t){return"Delete"===t.key}(t)?(t.preventDefault(),Qs(e,pe,!1)):Qs(e,ze,t);else if(function(t){return Bs(t,"Backspace",Js)}(t))t.preventDefault(),Qs(e,ve,!0);else if(function(t){return Bs(t,"Delete",Js)}(t))t.preventDefault(),Qs(e,ve,!1);else if(function(t){return r&&Bs(t,"Backspace",{metaKey:!0})}(t))t.preventDefault(),Qs(e,ke,!0);else if(function(t){return r&&(Bs(t,"Delete",{metaKey:!0})||Bs(t,"k",{ctrlKey:!0}))}(t))t.preventDefault(),Qs(e,ke,!1);else if(function(t){return Bs(t,"b",Ws)}(t))t.preventDefault(),Qs(e,Te,"bold");else if(function(t){return Bs(t,"u",Ws)}(t))t.preventDefault(),Qs(e,Te,"underline");else if(function(t){return Bs(t,"i",Ws)}(t))t.preventDefault(),Qs(e,Te,"italic");else if(function(t){return Bs(t,"Tab",{shiftKey:"any"})}(t))Qs(e,Re,t);else if(function(t){return Bs(t,"z",Ws)}(t))t.preventDefault(),Qs(e,Ne,void 0);else if(function(t){if(r)return Bs(t,"z",{metaKey:!0,shiftKey:!0});return Bs(t,"y",{ctrlKey:!0})||Bs(t,"z",{ctrlKey:!0,shiftKey:!0})}(t))t.preventDefault(),Qs(e,be,void 0);else{const n=e._editorState._selection;null===n||_r(n)?js(t)&&(t.preventDefault(),Qs(e,Ge,t)):!function(t){return Bs(t,"c",Ws)}(t)?!function(t){return Bs(t,"x",Ws)}(t)?js(t)&&(t.preventDefault(),Qs(e,Ge,t)):(t.preventDefault(),Qs(e,qe,t)):(t.preventDefault(),Qs(e,He,t))}(function(t){return t.ctrlKey||t.shiftKey||t.altKey||t.metaKey})(t)&&Qs(e,rn,t)}],["pointerdown",function(t,e){const n=t.target,r=t.pointerType;To(n)&&"touch"!==r&&"pen"!==r&&0===t.button&&_i(e,(()=>{rs(n)||(gn=!0)}))}],["compositionstart",function(t,e){_i(e,(()=>{const n=Pr();if(_r(n)&&!e.isComposing()){const r=n.anchor,i=n.anchor.getNode();xs(r.key),(t.timeStamp<cn+on||"element"===r.type||!n.isCollapsed()||i.getFormat()!==n.format||sr(i)&&i.getStyle()!==n.style)&&Qs(e,xe,B)}}))}],["compositionend",function(t,e){i?pn=!0:l||!o&&!f?_i(e,(()=>{wn(e,t.data)})):(yn=!0,mn=t.data)}],["input",function(t,e){t.stopPropagation(),_i(e,(()=>{if(ko(t.target)&&rs(t.target))return;const n=Pr(),r=t.data,c=bn(t);if(null!=r&&_r(n)&&Sn(n,c,r,t.timeStamp,!1)){pn&&(wn(e,r),pn=!1);const c=n.anchor.getNode(),a=xo(co(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;s&&!n.isCollapsed()&&sr(c)&&null!==a.anchorNode&&c.getTextContent().slice(0,d)+r+c.getTextContent().slice(d+h)===Fs(a.anchorNode)||Qs(e,xe,r);const g=r.length;i&&g>1&&"insertCompositionText"===t.inputType&&!e.isComposing()&&(n.anchor.offset-=g),o||l||f||!e.isComposing()||(cn=0,xs(null))}else{Ls(!1,e,null!==r?r:void 0),pn&&(wn(e,r||void 0),pn=!1)}!function(){Zr();const t=ni();at(t)}()}),{event:t}),fn=null}],["click",function(t,e){_i(e,(()=>{const n=Pr(),r=xo(co(e)),i=Fr();if(r)if(_r(n)){const e=n.anchor,s=e.getNode();if("element"===e.type&&0===e.offset&&n.isCollapsed()&&!Ti(s)&&1===ws().getChildrenSize()&&s.getTopLevelElementOrThrow().isEmpty()&&null!==i&&n.is(i))r.removeAllRanges(),n.dirty=!0;else if(3===t.detail&&!n.isCollapsed()){if(s!==n.focus.getNode()){const t=function(t,e){let n=t;for(;n!==ws()&&null!=n;){if(e(n))return n;n=n.getParent()}return null}(s,(t=>xi(t)&&!t.isInline()));xi(t)&&t.select(0)}}}else if("touch"===t.pointerType||"pen"===t.pointerType){const n=r.anchorNode;if(ko(n)||fs(n)){Ms(Dr(i,r,e,t))}}Qs(e,_e,t)}))}],["cut",sn],["copy",sn],["dragstart",sn],["dragover",sn],["dragend",sn],["paste",sn],["focus",sn],["blur",sn],["drop",sn]];s&&ln.push(["beforeinput",(e,n)=>function(e,n){const r=e.inputType,s=bn(e);if("deleteCompositionText"===r||i&&Xs(n))return;if("insertCompositionText"===r)return;_i(n,(()=>{const i=Pr();if("deleteContentBackward"===r){if(null===i){const t=Fr();if(!_r(t))return;Ms(t.clone())}if(_r(i)){const r=i.anchor.key===i.focus.key;if(o=e.timeStamp,"MediaLast"===an&&o<cn+on&&n.isComposing()&&r){if(xs(null),cn=0,setTimeout((()=>{_i(n,(()=>{xs(null)}))}),on),_r(i)){const e=i.anchor.getNode();e.markDirty(),sr(e)||t(142),Nn(i,e)}}else{xs(null),e.preventDefault();const t=i.anchor.getNode(),s=t.getTextContent(),o=t.canInsertTextAfter(),l=0===i.anchor.offset&&i.focus.offset===s.length;let c=u&&r&&!l&&o;if(c&&i.isCollapsed()&&(c=!vi(Gs(i.anchor,!0))),!c){Qs(n,pe,!0);const t=Pr();u&&_r(t)&&t.isCollapsed()&&(xn=t,setTimeout((()=>xn=null)))}}return}}var o;if(!_r(i))return;const c=e.data;null!==fn&&Ls(!1,n,fn),i.dirty&&null===fn||!i.isCollapsed()||Ti(i.anchor.getNode())||null===s||i.applyDOMRange(s),fn=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":Qs(n,xe,e);break;case"insertFromComposition":xs(null),Qs(n,xe,e);break;case"insertLineBreak":xs(null),Qs(n,ye,!1);break;case"insertParagraph":xs(null),_n&&!l?(_n=!1,Qs(n,ye,!1)):Qs(n,me,void 0);break;case"insertFromPaste":case"insertFromPasteAsQuotation":Qs(n,Ce,e);break;case"deleteByComposition":(function(t,e){return t!==e||xi(t)||xi(e)||!as(t)||!as(e)})(d,h)&&Qs(n,Se,e);break;case"deleteByDrag":case"deleteByCut":Qs(n,Se,e);break;case"deleteContent":Qs(n,pe,!1);break;case"deleteWordBackward":Qs(n,ve,!0);break;case"deleteWordForward":Qs(n,ve,!1);break;case"deleteHardLineBackward":case"deleteSoftLineBackward":Qs(n,ke,!0);break;case"deleteContentForward":case"deleteHardLineForward":case"deleteSoftLineForward":Qs(n,ke,!1);break;case"formatStrikeThrough":Qs(n,Te,"strikethrough");break;case"formatBold":Qs(n,Te,"bold");break;case"formatItalic":Qs(n,Te,"italic");break;case"formatUnderline":Qs(n,Te,"underline");break;case"historyUndo":Qs(n,Ne,void 0);break;case"historyRedo":Qs(n,be,void 0)}else{if("\n"===c)e.preventDefault(),Qs(n,ye,!1);else if(c===R)e.preventDefault(),Qs(n,me,void 0);else if(null==c&&e.dataTransfer){const t=e.dataTransfer.getData("text/plain");e.preventDefault(),i.insertRawText(t)}else null!=c&&Sn(i,s,c,e.timeStamp,!0)?(e.preventDefault(),Qs(n,xe,c)):fn=c;un=e.timeStamp}}))}(e,n)]);let cn=0,an=null,un=0,fn=null;const dn=new WeakMap;let hn=!1,gn=!1,_n=!1,pn=!1,yn=!1,mn="",xn=null,Cn=[0,"",0,"root",0];function Sn(t,e,n,r,i){const o=t.anchor,l=t.focus,c=o.getNode(),a=ni(),u=xo(co(a)),f=null!==u?u.anchorNode:null,d=o.key,h=a.getElementByKey(d),g=n.length;return d!==l.key||!sr(c)||(!i&&(!s||un<r+50)||c.isDirty()&&g<2||As(n))&&o.offset!==l.offset&&!c.isComposing()||us(c)||c.isDirty()&&g>1||(i||!s)&&null!==h&&!c.isComposing()&&f!==hs(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=as(e);return 0===n?!e.canInsertTextBefore()||!r.canInsertTextBefore()&&!e.isComposing()||i||function(t){const e=t.getPreviousSibling();return(sr(e)||xi(e)&&e.isInline())&&!e.canInsertTextAfter()}(e):n===e.getTextContentSize()&&(!e.canInsertTextAfter()||!r.canInsertTextAfter()&&!e.isComposing()||i)}(t,c)}function vn(t,e){return fs(t)&&null!==t.nodeValue&&0!==e&&e!==t.nodeValue.length}function kn(e,n,r){const{anchorNode:i,anchorOffset:s,focusNode:o,focusOffset:l}=e;hn&&(hn=!1,vn(i,s)&&vn(o,l)&&!xn)||_i(n,(()=>{if(!r)return void Ms(null);if(!ss(n,i,o))return;let c=Pr();if(xn&&_r(c)&&c.isCollapsed()){const t=c.anchor,e=xn.anchor;(t.key===e.key&&t.offset===e.offset+1||1===t.offset&&e.getNode().is(t.getNode().getPreviousSibling()))&&(c=xn.clone(),Ms(c))}if(xn=null,_r(c)){const r=c.anchor,i=r.getNode();if(c.isCollapsed()){"Range"===e.type&&e.anchorNode===e.focusNode&&(c.dirty=!0);const s=co(n).event,o=s?s.timeStamp:performance.now(),[l,a,u,f,d]=Cn,h=ws(),g=!1===n.isComposing()&&""===h.getTextContent();if(o<d+200&&r.offset===u&&r.key===f)Tn(c,l,a);else if("text"===r.type)sr(i)||t(141),Nn(c,i);else if("element"===r.type&&!g){xi(i)||t(259);const e=r.getNode();e.isEmpty()?function(t,e){const n=e.getTextFormat(),r=e.getTextStyle();Tn(t,n,r)}(c,e):Tn(c,0,"")}}else{const t=r.key,e=c.focus.key,n=c.getNodes(),i=n.length,o=c.isBackward(),a=o?l:s,u=o?s:l,f=o?e:t,d=o?t:e;let h=A,g=!1;for(let t=0;t<i;t++){const e=n[t],r=e.getTextContentSize();if(sr(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}}Qs(n,he,void 0)}))}function Tn(t,e,n){t.format===e&&t.style===n||(t.format=e,t.style=n,t.dirty=!0)}function Nn(t,e){Tn(t,e.getFormat(),e.getStyle())}function bn(t){if(!t.getTargetRanges)return null;const e=t.getTargetRanges();return 0===e.length?null:e[0]}function wn(t,e){const n=t._compositionKey;if(xs(null),null!==n&&null!=e){if(""===e){const e=Ss(n),r=hs(t.getElementByKey(n));return void(null!==r&&null!==r.nodeValue&&sr(e)&&Is(e,r.nodeValue,null,null,!0))}if("\n"===e[e.length-1]){const e=Pr();if(_r(e)){const n=e.focus;return e.anchor.set(n.key,n.offset,n.type),void Qs(t,Fe,null)}}}Ls(!0,t,e)}function En(t){let e=t.__lexicalEventHandles;return void 0===e&&(e=[],t.__lexicalEventHandles=e),e}const Mn=new Map;function On(t){const e=Co(t.target);if(null===e)return;const n=ls(e.anchorNode);if(null===n)return;gn&&(gn=!1,_i(n,(()=>{const r=Fr(),i=e.anchorNode;if(ko(i)||fs(i)){Ms(Dr(r,e,n,t))}})));const r=Ds(n),i=r[r.length-1],s=i._key,o=Mn.get(s),l=o||i;l!==n&&kn(e,l,!1),kn(e,n,!0),n!==i?Mn.set(s,n):o&&Mn.delete(s)}function An(t){t._lexicalHandled=!0}function Dn(t){return!0===t._lexicalHandled}const Pn=()=>{};function Fn(e){const n=e.ownerDocument,r=dn.get(n);if(void 0===r)return void Pn();const i=r-1;i>=0||t(164),dn.set(n,i),0===i&&n.removeEventListener("selectionchange",On);const s=cs(e);os(s)?(!function(t){if(null!==t._parentEditor){const e=Ds(t),n=e[e.length-1]._key;Mn.get(n)===t&&Mn.delete(n)}else Mn.delete(t._key)}(s),e.__lexicalEditor=null):s&&t(198);const o=En(e);for(let t=0;t<o.length;t++)o[t]();e.__lexicalEventHandles=[]}function Ln(t,e,n){Zr();const r=t.__key,i=t.getParent();if(null===i)return;const s=function(t){const e=Pr();if(!_r(e)||!xi(t))return e;const{anchor:n,focus:r}=e,i=n.getNode(),s=r.getNode();oo(i,t)&&n.set(t.__key,0,"element");oo(s,t)&&r.set(t.__key,0,"element");return e}(t);let o=!1;if(_r(s)&&e){const e=s.anchor,n=s.focus;e.key===r&&(Kr(e,t,i,t.getPreviousSibling(),t.getNextSibling()),o=!0),n.key===r&&(Kr(n,t,i,t.getPreviousSibling(),t.getNextSibling()),o=!0)}else yr(s)&&e&&t.isSelected()&&t.selectPrevious();if(_r(s)&&e&&!o){const e=t.getIndexWithinParent();ys(t),Lr(s,i,e,-1)}else ys(t);n||fo(i)||i.canBeEmpty()||!i.isEmpty()||Ln(i,e),e&&s&&Ti(i)&&i.isEmpty()&&i.selectEnd()}function In(t){return t}class Kn{static getType(){const{ownNodeType:e}=Ro(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}),ps(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=Ss(t);if(null===e)break;t=e.__parent}return!1}isSelected(t){const e=t||Pr();if(null==e)return!1;const n=e.getNodes().some((t=>t.__key===this.__key));if(sr(this))return n;if(_r(e)&&"element"===e.anchor.type&&"element"===e.focus.type){if(e.isCollapsed())return!1;const t=this.getParent();if(vi(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:Ss(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(fo(n))return xi(e)||e===this&&vi(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:Ss(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:Ss(t)}getNextSiblings(){const t=[];let e=this.getNextSibling();for(;null!==e;)t.push(e),e=e.getNextSibling();return t}getCommonAncestor(t){const e=xi(this)?this:this.getParent(),n=xi(t)?t:t.getParent(),r=e&&n?Cl(e,n):null;return r?r.commonAncestor:null}is(t){return null!=t&&this.__key===t.__key}isBefore(e){const n=Cl(this,e);return null!==n&&("descendant"===n.type||("branch"===n.type?-1===yl(n):("same"!==n.type&&"ancestor"!==n.type&&t(279),!1)))}isParentOf(t){const e=Cl(this,t);return null!==e&&"ancestor"===e.type}getNodesBetween(e){const n=this.isBefore(e),r=[],i=new Set;let s=this;for(;null!==s;){const o=s.__key;if(i.has(o)||(i.add(o),r.push(s)),s===e)break;const l=xi(s)?n?s.getFirstChild():s.getLastChild():null;if(null!==l){s=l;continue}const c=n?s.getNextSibling():s.getPreviousSibling();if(null!==c){s=c;continue}const a=s.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);s=u}return n||r.reverse(),r}isDirty(){const t=ni()._dirtyLeaves;return null!==t&&t.has(this.__key)}getLatest(){const e=Ss(this.__key);return null===e&&t(113),e}getWritable(){Zr();const t=ei(),e=ni(),n=t._nodeMap,r=this.__key,i=this.getLatest(),s=e._cloneNotNeeded,o=Pr();if(null!==o&&o.setCachedNodes(null),s.has(r))return ms(i),i;const l=Fo(i);return s.add(r),ms(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 xt(n).flatKeys)t in e&&(void 0!==i&&i!==r||(i={...r}),i[t]=e[t]);return(n.__state||i)&&mt(t).updateFromJSON(i),n}(this,t)}static transform(){return null}remove(t){Ln(this,!0,t)}replace(e,n){Zr();let r=Pr();null!==r&&(r=r.clone()),_o(this,e);const i=this.getLatest(),s=this.__key,o=e.__key,l=e.getWritable(),c=this.getParentOrThrow().getWritable(),a=c.__size;ys(l);const u=i.getPreviousSibling(),f=i.getNextSibling(),d=i.__prev,h=i.__next,g=i.__parent;if(Ln(i,!1,!0),null===u)c.__first=o;else{u.getWritable().__next=o}if(l.__prev=d,null===f)c.__last=o;else{f.getWritable().__prev=o}if(l.__next=h,l.__parent=g,c.__size=a,n&&(xi(this)&&xi(l)||t(139),this.getChildren().forEach((t=>{l.append(t)}))),_r(r)){Ms(r);const t=r.anchor,e=r.focus;t.key===s&&hr(t,l),e.key===s&&hr(e,l)}return Cs()===s&&xs(o),l}insertAfter(t,e=!0){Zr(),_o(this,t);const n=this.getWritable(),r=t.getWritable(),i=r.getParent(),s=Pr();let o=!1,l=!1;if(null!==i){const e=t.getIndexWithinParent();if(ys(r),_r(s)){const t=i.__key,n=s.anchor,r=s.focus;o="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&&_r(s)){const t=this.getIndexWithinParent();Lr(s,a,t+1);const e=a.__key;o&&s.anchor.set(e,t+2,"element"),l&&s.focus.set(e,t+2,"element")}return t}insertBefore(t,e=!0){Zr(),_o(this,t);const n=this.getWritable(),r=t.getWritable(),i=r.__key;ys(r);const s=this.getPreviousSibling(),o=this.getParentOrThrow().getWritable(),l=n.__prev,c=this.getIndexWithinParent();if(null===s)o.__first=i;else{s.getWritable().__next=i}o.__size++,n.__prev=i,r.__prev=l,r.__next=n.__key,r.__parent=n.__parent;const a=Pr();if(e&&_r(a)){Lr(a,this.getParentOrThrow(),c)}return t}isParentRequired(){return!1}createParentElementNode(){return Bi()}selectStart(){return this.selectPrevious()}selectEnd(){return this.selectNext(0,0)}selectPrevious(t,e){Zr();const n=this.getPreviousSibling(),r=this.getParentOrThrow();if(null===n)return r.select(0,0);if(xi(n))return n.select();if(!sr(n)){const t=n.getIndexWithinParent()+1;return r.select(t,t)}return n.select(t,e)}selectNext(t,e){Zr();const n=this.getNextSibling(),r=this.getParentOrThrow();if(null===n)return r.select();if(xi(n))return n.select(0,0);if(!sr(n)){const t=n.getIndexWithinParent();return r.select(t,t)}return n.select(t,e)}markDirty(){this.getWritable()}reconcileObservedMutation(t,e){this.markDirty()}}class zn extends Kn{static getType(){return"linebreak"}static clone(t){return new zn(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&&wo(e)){const n=e.firstChild;if(n===t||n.nextSibling===t&&Jn(n)){const n=e.lastChild;if(n===t||n.previousSibling===t&&Jn(n))return!0}}return!1}(t)||function(t){const e=t.parentElement;if(null!==e&&wo(e)){const n=e.firstChild;if(n===t||n.nextSibling===t&&Jn(n))return!1;const r=e.lastChild;if(r===t||r.previousSibling===t&&Jn(r))return!0}return!1}(t)?null:{conversion:Rn,priority:0}}}static importJSON(t){return Bn().updateFromJSON(t)}}function Rn(t){return{node:Bn()}}function Bn(){return go(new zn)}function Wn(t){return t instanceof zn}function Jn(t){return fs(t)&&/^( |\t|\r?\n)+$/.test(t.textContent||"")}function $n(t,e){return 16&e?"code":e&O?"mark":32&e?"sub":64&e?"sup":null}function jn(t,e){return 1&e?"strong":2&e?"em":"span"}function Un(t,e,n,r,i){const s=r.classList;let o=Vs(i,"base");void 0!==o&&s.add(...o),o=Vs(i,"underlineStrikethrough");let l=!1;const c=e&b&&e&N;void 0!==o&&(n&b&&n&N?(l=!0,c||s.add(...o)):c&&s.remove(...o));for(const t in U){const r=U[t];if(o=Vs(i,t),void 0!==o)if(n&r){if(l&&("underline"===t||"strikethrough"===t)){e&r&&s.remove(...o);continue}e&r&&(!c||"underline"!==t)&&"strikethrough"!==t||s.add(...o)}else e&r&&s.remove(...o)}}function Vn(t,e,n){const r=e.firstChild,s=n.isComposing(),o=t+(s?z:"");if(null==r)e.textContent=o;else{const t=r.nodeValue;if(t!==o)if(s||i){const[e,n,i]=function(t,e){const n=t.length,r=e.length;let i=0,s=0;for(;i<n&&i<r&&t[i]===e[i];)i++;for(;s+i<n&&s+i<r&&t[n-s-1]===e[r-s-1];)s++;return[i,n-i-s,e.slice(i,r-s)]}(t,o);0!==n&&r.deleteData(e,n),r.insertData(e,i)}else r.nodeValue=o}}function Yn(t,e,n,r,i,s){Vn(i,t,e);const o=s.theme.text;void 0!==o&&Un(0,0,r,t,o)}function Hn(t,e){const n=document.createElement(e);return n.appendChild(t),n}class qn extends Kn{static getType(){return"text"}static clone(t){return new qn(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 G[t.__mode]}getStyle(){return this.getLatest().__style}isToken(){return 1===this.getLatest().__mode}isComposing(){return this.__key===Cs()}isSegmented(){return 2===this.getLatest().__mode}isDirectionless(){return!!(1&this.getLatest().__detail)}isUnmergeable(){return!!(2&this.getLatest().__detail)}hasFormat(t){const e=U[t];return!!(this.getFormat()&e)}isSimpleText(){return"text"===this.__type&&0===this.__mode}getTextContent(){return this.getLatest().__text}getFormatFlags(t,e){return gs(this.getLatest().__format,t,e)}canHaveFormat(){return!0}isInline(){return!0}createDOM(t,e){const n=this.__format,r=$n(0,n),i=jn(0,n),s=null===r?i:r,o=document.createElement(s);let l=o;this.hasFormat("code")&&o.setAttribute("spellcheck","false"),null!==r&&(l=document.createElement(i),o.appendChild(l));Yn(l,this,0,n,this.__text,t);const c=this.__style;return""!==c&&(o.style.cssText=c),o}updateDOM(e,n,r){const i=this.__text,s=e.__format,o=this.__format,l=$n(0,s),c=$n(0,o),a=jn(0,s),u=jn(0,o);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 s=document.createElement(u);return Yn(s,this,0,o,i,r),n.replaceChild(s,e),!1}let f=n;null!==c&&null!==l&&(f=n.firstChild,null==f&&t(49)),Vn(i,f,this);const d=r.theme.text;void 0!==d&&s!==o&&Un(0,s,o,f,d);const h=e.__style,g=this.__style;return h!==g&&(n.style.cssText=g),!1}static importDOM(){return{"#text":()=>({conversion:tr,priority:0}),b:()=>({conversion:Xn,priority:0}),code:()=>({conversion:rr,priority:0}),em:()=>({conversion:rr,priority:0}),i:()=>({conversion:rr,priority:0}),mark:()=>({conversion:rr,priority:0}),s:()=>({conversion:rr,priority:0}),span:()=>({conversion:Gn,priority:0}),strong:()=>({conversion:rr,priority:0}),sub:()=>({conversion:rr,priority:0}),sup:()=>({conversion:rr,priority:0}),u:()=>({conversion:rr,priority:0})}}static importJSON(t){return ir().updateFromJSON(t)}updateFromJSON(t){return super.updateFromJSON(t).setTextContent(t.text).setFormat(t.format).setDetail(t.detail).setMode(t.mode).setStyle(t.style)}exportDOM(e){let{element:n}=super.exportDOM(e);return ko(n)||t(132),n.style.whiteSpace="pre-wrap",this.hasFormat("lowercase")?n.style.textTransform="lowercase":this.hasFormat("uppercase")?n.style.textTransform="uppercase":this.hasFormat("capitalize")&&(n.style.textTransform="capitalize"),this.hasFormat("bold")&&(n=Hn(n,"b")),this.hasFormat("italic")&&(n=Hn(n,"i")),this.hasFormat("strikethrough")&&(n=Hn(n,"s")),this.hasFormat("underline")&&(n=Hn(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?U[t]:t,e}setDetail(t){const e=this.getWritable();return e.__detail="string"==typeof t?V[t]:t,e}setStyle(t){const e=this.getWritable();return e.__style=t,e}toggleFormat(t){const e=gs(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=q[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){Zr();let n=t,r=e;const i=Pr(),s=this.getTextContent(),o=this.__key;if("string"==typeof s){const t=s.length;void 0===n&&(n=t),void 0===r&&(r=t)}else n=0,r=0;if(!_r(i))return Er(o,n,o,r,"text","text");{const t=Cs();t!==i.anchor.key&&t!==i.focus.key||xs(o),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(),s=i.__text,o=n.length;let l=t;l<0&&(l=o+l,l<0&&(l=0));const c=Pr();if(r&&_r(c)){const e=t+o;c.setTextNodeRange(i,e,i,e)}const a=s.slice(0,l)+n+s.slice(l+e);return i.__text=a,i}canInsertTextBefore(){return!0}canInsertTextAfter(){return!0}splitText(...t){Zr();const e=this.getLatest(),n=e.getTextContent();if(""===n)return[];const r=e.__key,i=Cs(),s=n.length;t.sort(((t,e)=>t-e)),t.push(s);const o=[],l=t.length;for(let e=0,r=0;e<s&&r<=l;r++){const i=t[r];i>e&&(o.push(n.slice(e,i)),e=i)}const c=o.length;if(1===c)return[e];const a=o[0],u=e.getParent();let f;const d=e.getFormat(),h=e.getStyle(),g=e.__detail;let _=!1,p=null,y=null;const m=Pr();if(_r(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=ir(a),f.__format=d,f.__style=h,f.__detail=g,f.__state=Tt(e,f),_=!0):f=e.setTextContent(a);const x=[f];for(let t=1;t<c;t++){const n=ir(o[t]);n.__format=d,n.__style=h,n.__detail=g,n.__state=Tt(e,n);const s=n.__key;i===r&&xs(s),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&&ms(e);null!==n&&ms(n)}(this);const t=u.getWritable(),e=this.getIndexWithinParent();_?(t.splice(e,0,x),this.remove()):t.splice(e,1,x),_r(m)&&Lr(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,s=this.__text,o=s.length;Cs()===i&&xs(r);const l=Pr();if(_r(l)){const t=l.anchor,s=l.focus;null!==t&&t.key===i&&zr(t,n,r,e,o),null!==s&&s.key===i&&zr(s,n,r,e,o)}const c=e.__text,a=n?c+s:s+c;this.setTextContent(a);const u=this.getWritable();return e.remove(),u}isTextEntity(){return!1}}function Gn(t){return{forChild:or(t.style),node:null}}function Xn(t){const e=t,n="normal"===e.style.fontWeight;return{forChild:or(e.style,n?void 0:"bold"),node:null}}const Qn=new WeakMap;function Zn(t){if(!ko(t))return!1;if("PRE"===t.nodeName)return!0;const e=t.style.whiteSpace;return"string"==typeof e&&e.startsWith("pre")}function tr(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=Qn.get(n))&&!Zn(n);)r.push(n),n=n.parentNode;const i=void 0===e?n:e;for(let t=0;t<r.length;t++)Qn.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(Bn()):"\t"===n?e.push(cr()):""!==n&&e.push(ir(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=er(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=er(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:ir(r)}}function er(t,e){let n=t;for(;;){let t;for(;null===(t=e?n.nextSibling:n.previousSibling);){const t=n.parentElement;if(null===t)return null;n=t}if(n=t,ko(n)){const t=n.style.display;if(""===t&&!bo(n)||""!==t&&!t.startsWith("inline"))return null}let r=n;for(;null!==(r=e?n.firstChild:n.lastChild);)n=r;if(fs(n))return n;if("BR"===n.nodeName)return null}}const nr={code:"code",em:"italic",i:"italic",mark:"highlight",s:"strikethrough",strong:"bold",sub:"subscript",sup:"superscript",u:"underline"};function rr(t){const e=nr[t.nodeName.toLowerCase()];return void 0===e?{node:null}:{forChild:or(t.style,e),node:null}}function ir(t=""){return go(new qn(t))}function sr(t){return t instanceof qn}function or(t,e){const n=t.fontWeight,r=t.textDecoration.split(" "),i="700"===n||"bold"===n,s=r.includes("line-through"),o="italic"===t.fontStyle,l=r.includes("underline"),c=t.verticalAlign;return t=>sr(t)?(i&&!t.hasFormat("bold")&&t.toggleFormat("bold"),s&&!t.hasFormat("strikethrough")&&t.toggleFormat("strikethrough"),o&&!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 lr extends qn{static getType(){return"tab"}static clone(t){return new lr(t.__key)}constructor(t){super("\t",t),this.__detail=2}static importDOM(){return null}createDOM(t){const e=super.createDOM(t),n=Vs(t.theme,"tab");if(void 0!==n){e.classList.add(...n)}return e}static importJSON(t){return cr().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 cr(){return go(new lr)}function ar(t){return t instanceof lr}class ur{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 pl(Ol(Sl(this,"next")),Ol(Sl(t,"next")))<0}getNode(){const e=Ss(this.key);return null===e&&t(20),e}set(t,e,n,r){const i=this._selection,s=this.key;r&&this.key===t&&this.offset===e&&this.type===n||(this.key=t,this.offset=e,this.type=n,Qr()||(Cs()===s&&xs(t),null!==i&&(i.setCachedNodes(null),i.dirty=!0)))}}function fr(t,e,n){return new ur(t,e,n)}function dr(t,e){let n=e.__key,r=t.offset,i="element";if(sr(e)){i="text";const t=e.getTextContentSize();r>t&&(r=t)}else if(!xi(e)){const t=e.getNextSibling();if(sr(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 hr(t,e){if(xi(e)){const n=e.getLastDescendant();xi(n)||sr(n)?dr(t,n):dr(t,e)}else dr(t,e)}class gr{constructor(t){this._cachedNodes=null,this._nodes=t,this.dirty=!1}getCachedNodes(){return this._cachedNodes}setCachedNodes(t){this._cachedNodes=t}is(t){if(!yr(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 gr(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(sr(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=Ss(t);null!==e&&n.push(e)}return Qr()||(this._cachedNodes=n),n}getTextContent(){const t=this.getNodes();let e="";for(let n=0;n<t.length;n++)e+=t[n].getTextContent();return e}deleteNodes(){const t=this.getNodes();if((Pr()||Fr())===this&&t[0]){const e=nl(t[0],"next");kl(gl(e,e))}for(const e of t)e.remove()}}function _r(t){return t instanceof pr}class pr{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!!_r(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,s=new Set;for(const n of t)if(Qo(n)){const{origin:t}=n;0===e.length?i.add(t):(s.add(t),e.push(t))}else{const{origin:t}=n;xi(t)&&s.has(t)||e.push(t)}r&&e.push(r.caret.origin);if(Xo(t.focus)&&xi(t.focus.origin)&&null===t.focus.getNodeAtCaret())for(let n=ol(t.focus.origin,"previous");Qo(n)&&i.has(n.origin)&&!n.origin.isEmpty()&&n.origin.is(e[e.length-1]);n=cl(n))i.delete(n.origin),e.pop();for(;e.length>1;){const t=e[e.length-1];if(!xi(t)||s.has(t)||t.isEmpty()||i.has(t))break;e.pop()}if(0===e.length&&t.isCollapsed()){const n=Ol(t.anchor),r=Ol(t.anchor.getFlipped()),i=t=>qo(t)?t.origin:t.getNodeAtCaret(),s=i(n)||i(r)||(t.anchor.getNodeAtCaret()?n.origin:r.origin);e.push(s)}return e}(Pl(Nl(this),"next"));return Qr()||