lexical
Version:
Lexical is an extensible text editor framework that provides excellent reliability, accessible and performance.
9 lines (8 loc) • 125 kB
JavaScript
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
function t(t,...e){const n=new URL("https://lexical.dev/docs/error"),r=new URLSearchParams;r.append("code",t);for(const t of e)r.append("v",t);throw n.search=r.toString(),Error(`Minified Lexical error #${t}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}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,m=0,y=1,x=2,S=0,v=1,C=2,k=1,b=2,T=4,w=8,N=16,E=32,P=64,F=128,L=1792|(112|(3|T|w)|F),A=1,O=2,M=3,I=4,D=5,z=6,B=o||l||f?" ":"",W="\n\n",R=i?" ":B,K="֑-߿יִ-﷽ﹰ-ﻼ",J="A-Za-zÀ-ÖØ-öø-ʸ̀-ࠀ-Ⰰ-︀--",$=new RegExp("^[^"+J+"]*["+K+"]"),j=new RegExp("^[^"+K+"]*["+J+"]"),U={bold:1,capitalize:1024,code:16,highlight:F,italic:2,lowercase:256,strikethrough:T,subscript:32,superscript:64,underline:w,uppercase:512},V={directionless:1,unmergeable:2},q={center:O,end:z,justify:I,left:A,right:M,start:D},H={[O]:"center",[z]:"end",[I]:"justify",[A]:"left",[M]:"right",[D]:"start"},G={normal:0,segmented:2,token:1},Q={[S]:"normal",[C]:"segmented",[v]:"token"},X="$";function Y(t,e,n,r,i,s){let o=t.getFirstChild();for(;null!==o;){const t=o.__key;o.__parent===e&&(di(o)&&Y(o,t,n,r,i,s),n.has(t)||s.delete(t),i.push(t)),o=o.getNextSibling()}}const Z=100;let tt=!1,et=0;function nt(t){et=t.timeStamp}function rt(t,e,n){const r="BR"===t.nodeName,i=e.__lexicalLineBreak;return i&&(t===i||r&&t.previousSibling===i)||r&&void 0!==rs(t,n)}function it(t,e,n){const r=Ys(Js(n));let i=null,s=null;null!==r&&r.anchorNode===t&&(i=r.anchorOffset,s=r.focusOffset);const o=t.nodeValue;null!==o&&ms(e,o,i,s,!1)}function st(t,e,n){if(cr(t)){const e=t.anchor.getNode();if(e.is(n)&&t.format!==e.getFormat())return!1}return Ui(e)&&n.isAttached()}function ot(t,e,n,r){for(let i=t;i&&!mo(i);i=Is(i)){const t=rs(i,e);if(void 0!==t){const e=es(t,n);if(e)return _i(e)||!no(i)?void 0:[i,e]}else if(i===r)return[r,cs(n)]}}function lt(t,e,n){tt=!0;const r=performance.now()-et>Z;try{ci(t,(()=>{const s=wr()||function(t){return t.getEditorState().read((()=>{const t=wr();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,_=ot(g,t,c,l);if(!_)continue;const[p,m]=_;if("characterData"===h)r&&Yn(m)&&Ui(g)&&st(s,g,m)&&it(g,m,t);else if("childList"===h){u=!0;const e=d.addedNodes;for(let n=0;n<e.length;n++){const r=e[n],s=ns(r),o=r.parentNode;if(null!=o&&r!==a&&null===s&&!rt(r,o,t)){if(i){const t=(no(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];(rt(r,g,t)||a===r)&&(g.appendChild(r),e++)}r!==e&&o.set(p,m)}}}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||rt(n,i,t)||s.removeChild(n)}}n.takeRecords()}null!==s&&(u&&as(s),i&&Ls(t)&&s.insertRawText(f))}))}finally{tt=!1}}function ct(t){const e=t._observer;if(null!==e){lt(t,e.takeRecords(),e)}}function at(t){!function(t){0===et&&Js(t).addEventListener("textInput",nt,!0)}(t),t._observer=new MutationObserver(((e,n)=>{lt(t,e,n)}))}function ut(t){return t}class ft{constructor(t,e){this.key=t,this.parse=e.parse.bind(e),this.unparse=(e.unparse||ut).bind(e),this.isEqual=(e.isEqual||Object.is).bind(e),this.defaultValue=this.parse(void 0)}}function dt(t,e){return new ft(t,e)}function ht(t,e,n){const r=gt(t,n,"direct"),i=gt(e,n,"direct");return n.isEqual(r,i)?null:[r,i]}function gt(t,e,n="latest"){const r=("latest"===n?t.getLatest():t).__state;return r?r.getValue(e):e.defaultValue}function _t(t,e,n){let r;if(Vr(),"function"==typeof n){const i=t.getLatest(),s=gt(i,e);if(r=n(s),e.isEqual(s,r))return i}else r=n;const i=t.getWritable();return yt(i).updateFromKnown(e,r),i}class pt{constructor(t,e=new Map,n=void 0,r=new Map,i=void 0){this.node=t,this.sharedConfigMap=e,this.unknownState=n,this.knownState=r;const 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}(e,n,r);this.size=s}getValue(t){const e=this.knownState.get(t);if(void 0!==e)return e;this.sharedConfigMap.set(t.key,t);let n=t.defaultValue;if(this.unknownState&&t.key in this.unknownState){const e=this.unknownState[t.key];void 0!==e&&(n=t.parse(e)),this.updateFromKnown(t,n)}return n}getInternalState(){return[this.unknownState,this.knownState]}toJSON(){const t={...this.unknownState};for(const[e,n]of this.knownState)e.isEqual(n,e.defaultValue)?delete t[e.key]:t[e.key]=e.unparse(n);return mt(t)?{[X]:t}:{}}getWritable(t){if(this.node===t)return this;const e=new Map(this.knownState),n=mt(r=this.unknownState)&&{...r};var r;if(n)for(const t of e.keys())delete n[t.key];return new pt(t,this.sharedConfigMap,mt(n),e,this.size)}updateFromKnown(t,e){const n=t.key;this.sharedConfigMap.set(n,t);const{knownState:r,unknownState:i}=this;r.has(t)||i&&n in i||this.size++,r.set(t,e)}updateFromUnknown(t,e){const n=this.sharedConfigMap.get(t);n?this.updateFromKnown(n,n.parse(e)):(this.unknownState=this.unknownState||{},t in this.unknownState||this.size++,this.unknownState[t]=e)}updateFromJSON(t){const{knownState:e}=this;for(const t of e.keys())e.set(t,t.defaultValue);if(this.size=e.size,this.unknownState={},t)for(const[e,n]of Object.entries(t))this.updateFromUnknown(e,n);this.unknownState=mt(this.unknownState)}}function mt(t){if(t)for(const e in t)return t}function yt(t){const e=t.getWritable(),n=e.__state?e.__state.getWritable(e):new pt(e);return e.__state=n,n}function xt(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,r=(t,e)=>{for(const[r,i]of t.knownState){if(n.has(r.key))continue;n.add(r.key);const t=e?e.getValue(r):r.defaultValue;if(t!==i&&!r.isEqual(t,i))return!0}return!1},i=(t,e)=>{const{unknownState:r}=t,i=e?e.unknownState:void 0;if(r)for(const[t,e]of Object.entries(r))if(!n.has(t)&&(n.add(t),e!==(i?i[t]:void 0)))return!0;return!1};return!(t&&r(t,e)||e&&r(e,t)||t&&i(t,e)||e&&i(e,t))}(c,a))}function St(t,e){const n=t.mergeWithSibling(e),r=Gr()._normalizedNodes;return r.add(t.__key),r.add(e.__key),n}function vt(t){let e,n,r=t;if(""!==r.__text||!r.isSimpleText()||r.isUnmergeable()){for(;null!==(e=r.getPreviousSibling())&&Yn(e)&&e.isSimpleText()&&!e.isUnmergeable();){if(""!==e.__text){if(xt(e,r)){r=St(e,r);break}break}e.remove()}for(;null!==(n=r.getNextSibling())&&Yn(n)&&n.isSimpleText()&&!n.isUnmergeable();){if(""!==n.__text){if(xt(r,n)){r=St(r,n);break}break}n.remove()}}else r.remove()}function Ct(t){return kt(t.anchor),kt(t.focus),t}function kt(t){for(;"element"===t.type;){const e=t.getNode(),n=t.offset;let r,i;if(n===e.getChildrenSize()?(r=e.getChildAtIndex(n-1),i=!0):(r=e.getChildAtIndex(n),i=!1),Yn(r)){t.set(r.__key,i?r.getTextContentSize():0,"text",!0);break}if(!di(r))break;t.set(r.__key,i?r.getChildrenSize():0,"element",!0)}}let bt,Tt,wt,Nt,Et,Pt,Ft,Lt,At,Ot,Mt="",It="",Dt=null,zt="",Bt="",Wt=!1,Rt=!1,Kt=null;function Jt(t,e){const n=Ft.get(t);if(null!==e){const n=se(t);n.parentNode===e&&e.removeChild(n)}if(Lt.has(t)||Tt._keyToDOMMap.delete(t),di(n)){const t=te(n,Ft);$t(t,0,t.length-1,null)}void 0!==n&&Ns(Ot,wt,Nt,n,"destroyed")}function $t(t,e,n,r){let i=e;for(;i<=n;++i){const e=t[i];void 0!==e&&Jt(e,r)}}function jt(t,e){t.setProperty("text-align",e)}const Ut="40px";function Vt(t,e){const n=bt.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")||Ut;t.style.setProperty("padding-inline-start",0===e?"":`calc(${e} * ${r})`)}function qt(t,e){const n=t.style;0===e?jt(n,""):e===A?jt(n,"left"):e===O?jt(n,"center"):e===M?jt(n,"right"):e===I?jt(n,"justify"):e===D?jt(n,"start"):e===z&&jt(n,"end")}function Ht(e,n){const r=Lt.get(e);void 0===r&&t(60);const i=r.createDOM(bt,Tt);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,Tt),Yn(r)?i.setAttribute("data-lexical-text","true"):_i(r)&&i.setAttribute("data-lexical-decorator","true"),di(r)){const t=r.__indent,e=r.__size;if(0!==t&&Vt(i,t),0!==e){const t=e-1;!function(t,e,n,r){const i=It;It="",Gt(t,n,0,e,n.getDOMSlot(r)),Yt(n,r),It=i}(te(r,Lt),t,r,i)}const n=r.__format;0!==n&&qt(i,n),r.isInline()||Xt(null,r,i),Os(r)&&(Mt+=W,Bt+=W)}else{const t=r.getTextContent();if(_i(r)){const t=r.decorate(Tt,bt);null!==t&&ne(e,t),i.contentEditable="false"}else Yn(r)&&(r.isDirectionless()||(It+=t));Mt+=t,Bt+=t}return null!==n&&n.insertChild(i),Ns(Ot,wt,Nt,r,"created"),i}function Gt(t,e,n,r,i){const s=Mt;Mt="";let o=n;for(;o<=r;++o){Ht(t[o],i);const e=Lt.get(t[o]);null!==e&&Yn(e)&&(null===Dt&&(Dt=e.getFormat()),""===zt&&(zt=e.getStyle()))}Os(e)&&(Mt+=W);i.element.__lexicalTextContent=Mt,Mt=s+Mt}function Qt(t,e){if(t){const n=t.__last;if(n){const t=e.get(n);if(t)return Mn(t)?"line-break":_i(t)&&t.isInline()?"decorator":null}return"empty"}return null}function Xt(t,e,n){const r=Qt(t,Ft),i=Qt(e,Lt);r!==i&&e.getDOMSlot(n).setManagedLineBreak(i)}function Yt(t,e){const n=e.__lexicalDirTextContent||"",r=e.__lexicalDir||"";if(n!==It||r!==Kt){const n=""===It,i=n?Kt:function(t){if($.test(t))return"rtl";if(j.test(t))return"ltr";return null}(It);if(i!==r){const s=e.classList,o=bt.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(!Rt){t.getWritable().__dir=i}}Kt=i,e.__lexicalDirTextContent=It,e.__lexicalDir=i}}function Zt(e,n,r){const i=It;var s;It="",Dt=null,zt="",function(e,n,r){const i=Mt,s=e.__size,o=n.__size;Mt="";const l=r.element;if(1===s&&1===o){const t=e.__first,r=n.__first;if(t===r)ee(t,l);else{const e=se(t),n=Ht(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}Jt(t,null)}const i=Lt.get(r);Yn(i)&&(null===Dt&&(Dt=i.getFormat()),""===zt&&(zt=i.getStyle()))}else{const i=te(e,Ft),c=te(n,Lt);if(i.length!==s&&t(227),c.length!==o&&t(228),0===s)0!==o&&Gt(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;$t(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=re(ee(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=Ms(Tt,r);t===u?u=re(ee(r,s.element)):(s.withBefore(u).insertChild(t),ee(r,s.element)),f++,d++}else Ht(r,s.withBefore(u)),d++;else u=re(se(t)),Jt(t,s.element),f++}const i=Lt.get(r);null!==i&&Yn(i)&&(null===Dt&&(Dt=i.getFormat()),""===zt&&(zt=i.getStyle()))}const h=f>o,g=d>l;if(h&&!g){const e=n[l+1],r=void 0===e?null:Tt.getElementByKey(e);Gt(n,t,d,l,s.withBefore(r))}else g&&!h&&$t(e,f,o,s.element)}(n,i,c,s,o,r)}Os(n)&&(Mt+=W);l.__lexicalTextContent=Mt,Mt=i+Mt}(e,n,n.getDOMSlot(r)),Yt(n,r),s=n,null==Dt||Dt===s.__textFormat||Rt||s.setTextFormat(Dt),function(t){""===zt||zt===t.__textStyle||Rt||t.setTextStyle(zt)}(n),It=i}function te(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 ee(e,n){const r=Ft.get(e);let i=Lt.get(e);void 0!==r&&void 0!==i||t(61);const s=Wt||Pt.has(e)||Et.has(e),o=Ms(Tt,e);if(r===i&&!s){if(di(r)){const t=o.__lexicalTextContent;void 0!==t&&(Mt+=t,Bt+=t);const e=o.__lexicalDirTextContent;void 0!==e&&(It+=e)}else{const t=r.getTextContent();Yn(r)&&!r.isDirectionless()&&(It+=t),Bt+=t,Mt+=t}return o}if(r!==i&&s&&Ns(Ot,wt,Nt,i,"updated"),i.updateDOM(r,o,bt)){const r=Ht(e,null);return null===n&&t(62),n.replaceChild(r,o),Jt(e,null),r}if(di(r)&&di(i)){const t=i.__indent;t!==r.__indent&&Vt(o,t);const e=i.__format;e!==r.__format&&qt(o,e),s&&(Zt(r,i,o),mi(i)||i.isInline()||Xt(r,i,o)),Os(i)&&(Mt+=W,Bt+=W)}else{const t=i.getTextContent();if(_i(i)){const t=i.decorate(Tt,bt);null!==t&&ne(e,t)}else Yn(i)&&!i.isDirectionless()&&(It+=t);Mt+=t,Bt+=t}if(!Rt&&mi(i)&&i.__cachedText!==Bt){const t=i.getWritable();t.__cachedText=Bt,i=t}return o}function ne(t,e){let n=Tt._pendingDecorators;const r=Tt._decorators;if(null===n){if(r[t]===e)return;n=ss(Tt)}n[t]=e}function re(t){let e=t.nextSibling;return null!==e&&e===Tt._blockCursorElement&&(e=e.nextSibling),e}function ie(t,e,n,r,i,s){Mt="",Bt="",It="",Wt=r===x,Kt=null,Tt=n,bt=n._config,wt=n._nodes,Nt=Tt._listeners.mutation,Et=i,Pt=s,Ft=t._nodeMap,Lt=e._nodeMap,Rt=e._readOnly,At=new Map(n._keyToDOMMap);const o=new Map;return Ot=o,ee("root",null),Tt=void 0,wt=void 0,Et=void 0,Pt=void 0,Ft=void 0,Lt=void 0,bt=void 0,At=void 0,Ot=void 0,o}function se(e){const n=At.get(e);return void 0===n&&t(75,e),n}function oe(t){return{}}const le={},ce={},ae={},ue={},fe={},de={},he={},ge={},_e={},pe={},me={},ye={},xe={},Se={},ve={},Ce={},ke={},be={},Te={},we={},Ne={},Ee={},Pe={},Fe={},Le={},Ae={},Oe={},Me={},Ie={},De={},ze={},Be={},We={},Re={},Ke={},Je={},$e={},je={},Ue={},Ve={},qe={},He={},Ge={},Qe={},Xe={},Ye=Object.freeze({}),Ze=30,tn=[["keydown",function(t,e){if(en=t.timeStamp,nn=t.key,e.isComposing())return;const{key:n,shiftKey:s,ctrlKey:o,metaKey:l,altKey:c}=t;if(As(e,ve,t))return;if(null==n)return;if(fn&&Cs(nn))return ci(e,(()=>{vn(e,dn)})),fn=!1,void(dn="");if(function(t,e,n,r){return xs(t)&&!e&&!r&&!n}(n,o,c,l))As(e,Ce,t);else if(function(t,e,n,r,i){return xs(t)&&!r&&!n&&(e||i)}(n,o,s,c,l))As(e,ke,t);else if(function(t,e,n,r){return ys(t)&&!e&&!r&&!n}(n,o,c,l))As(e,be,t);else if(function(t,e,n,r,i){return ys(t)&&!r&&!n&&(e||i)}(n,o,s,c,l))As(e,Te,t);else if(function(t,e,n){return function(t){return"ArrowUp"===t}(t)&&!e&&!n}(n,o,l))As(e,we,t);else if(function(t,e,n){return function(t){return"ArrowDown"===t}(t)&&!e&&!n}(n,o,l))As(e,Ne,t);else if(function(t,e){return vs(t)&&e}(n,s))an=!0,As(e,Ee,t);else if(function(t){return" "===t}(n))As(e,Pe,t);else if(function(t,e){return r&&e&&"o"===t.toLowerCase()}(n,o))t.preventDefault(),an=!0,As(e,fe,!0);else if(function(t,e){return vs(t)&&!e}(n,s))an=!1,As(e,Ee,t);else if(function(t,e,n,i){if(r)return!e&&!n&&(Cs(t)||"h"===t.toLowerCase()&&i);if(i||e||n)return!1;return Cs(t)}(n,c,l,o))Cs(n)?As(e,Fe,t):(t.preventDefault(),As(e,ue,!0));else if(function(t){return"Escape"===t}(n))As(e,Le,t);else if(function(t,e,n,i,s){if(r)return!(n||i||s)&&(ks(t)||"d"===t.toLowerCase()&&e);if(e||i||s)return!1;return ks(t)}(n,o,s,c,l))ks(n)?As(e,Ae,t):(t.preventDefault(),As(e,ue,!1));else if(function(t,e,n){return Cs(t)&&(r?e:n)}(n,c,o))t.preventDefault(),As(e,pe,!0);else if(function(t,e,n){return ks(t)&&(r?e:n)}(n,c,o))t.preventDefault(),As(e,pe,!1);else if(function(t,e){return r&&e&&Cs(t)}(n,l))t.preventDefault(),As(e,me,!0);else if(function(t,e,n){return r&&(e&&ks(t)||n&&"k"===t.toLowerCase())}(n,l,o))t.preventDefault(),As(e,me,!1);else if(function(t,e,n,r){return"b"===t.toLowerCase()&&!e&&Ss(n,r)}(n,c,l,o))t.preventDefault(),As(e,ye,"bold");else if(function(t,e,n,r){return"u"===t.toLowerCase()&&!e&&Ss(n,r)}(n,c,l,o))t.preventDefault(),As(e,ye,"underline");else if(function(t,e,n,r){return"i"===t.toLowerCase()&&!e&&Ss(n,r)}(n,c,l,o))t.preventDefault(),As(e,ye,"italic");else if(function(t,e,n,r){return"Tab"===t&&!e&&!n&&!r}(n,c,o,l))As(e,Oe,t);else if(function(t,e,n,r){return"z"===t.toLowerCase()&&!e&&Ss(n,r)}(n,s,l,o))t.preventDefault(),As(e,xe,void 0);else if(function(t,e,n,i){if(r)return"z"===t.toLowerCase()&&n&&e;return"y"===t.toLowerCase()&&i||"z"===t.toLowerCase()&&i&&e}(n,s,l,o))t.preventDefault(),As(e,Se,void 0);else{const c=e._editorState._selection;null===c||cr(c)?!i&&bs(n,l,o)&&(t.preventDefault(),As(e,je,t)):!function(t,e,n,i){if(e)return!1;if("c"===t.toLowerCase())return r?n:i;return!1}(n,s,l,o)?!function(t,e,n,i){if(e)return!1;if("x"===t.toLowerCase())return r?n:i;return!1}(n,s,l,o)?bs(n,l,o)&&(t.preventDefault(),As(e,je,t)):(t.preventDefault(),As(e,$e,t)):(t.preventDefault(),As(e,Je,t))}(function(t,e,n,r){return t||e||n||r})(o,s,c,l)&&As(e,Xe,t)}],["pointerdown",function(t,e){const n=t.target,r=t.pointerType;ro(n)&&"touch"!==r&&0===t.button&&ci(e,(()=>{Bi(n)||(cn=!0)}))}],["compositionstart",function(t,e){ci(e,(()=>{const n=wr();if(cr(n)&&!e.isComposing()){const r=n.anchor,i=n.anchor.getNode();Zi(r.key),(t.timeStamp<en+Ze||"element"===r.type||!n.isCollapsed()||i.getFormat()!==n.format||Yn(i)&&i.getStyle()!==n.style)&&As(e,he,R)}}))}],["compositionend",function(t,e){i?un=!0:l||!o&&!f?ci(e,(()=>{vn(e,t.data)})):(fn=!0,dn=t.data)}],["input",function(t,e){t.stopPropagation(),ci(e,(()=>{if(no(t.target)&&Bi(t.target))return;const n=wr(),r=t.data,c=Sn(t);if(null!=r&&cr(n)&&_n(n,c,r,t.timeStamp,!1)){un&&(vn(e,r),un=!1);const c=n.anchor.getNode(),a=Ys(Js(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()&&Yn(c)&&null!==a.anchorNode&&c.getTextContent().slice(0,d)+r+c.getTextContent().slice(d+h)===_s(a.anchorNode)||As(e,he,r);const g=r.length;i&&g>1&&"insertCompositionText"===t.inputType&&!e.isComposing()&&(n.anchor.offset-=g),o||l||f||!e.isComposing()||(en=0,Zi(null))}else{ps(!1,e,null!==r?r:void 0),un&&(vn(e,r||void 0),un=!1)}!function(){Vr();const t=Gr();ct(t)}()}),{event:t}),sn=null}],["click",function(t,e){ci(e,(()=>{const n=wr(),r=Ys(Js(e)),i=Nr();if(r)if(cr(n)){const e=n.anchor,s=e.getNode();if("element"===e.type&&0===e.offset&&n.isCollapsed()&&!mi(s)&&1===ls().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!==ls()&&null!=n;){if(e(n))return n;n=n.getParent()}return null}(s,(t=>di(t)&&!t.isInline()));di(t)&&t.select(0)}}}else if("touch"===t.pointerType){const n=r.anchorNode;if(no(n)||Ui(n)){as(Tr(i,r,e,t))}}As(e,ae,t)}))}],["cut",Ye],["copy",Ye],["dragstart",Ye],["dragover",Ye],["dragend",Ye],["paste",Ye],["focus",Ye],["blur",Ye],["drop",Ye]];s&&tn.push(["beforeinput",(e,n)=>function(e,n){const r=e.inputType,s=Sn(e);if("deleteCompositionText"===r||i&&Ls(n))return;if("insertCompositionText"===r)return;ci(n,(()=>{const i=wr();if("deleteContentBackward"===r){if(null===i){const t=Nr();if(!cr(t))return;as(t.clone())}if(cr(i)){const r=i.anchor.key===i.focus.key;if(o=e.timeStamp,"MediaLast"===nn&&o<en+Ze&&n.isComposing()&&r){if(Zi(null),en=0,setTimeout((()=>{ci(n,(()=>{Zi(null)}))}),Ze),cr(i)){const e=i.anchor.getNode();e.markDirty(),Yn(e)||t(142),xn(i,e)}}else{Zi(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=!_i(Fs(i.anchor,!0))),!c){As(n,ue,!0);const t=wr();u&&cr(t)&&t.isCollapsed()&&(hn=t,setTimeout((()=>hn=null)))}}return}}var o;if(!cr(i))return;const c=e.data;null!==sn&&ps(!1,n,sn),i.dirty&&null===sn||!i.isCollapsed()||mi(i.anchor.getNode())||null===s||i.applyDOMRange(s),sn=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":As(n,he,e);break;case"insertFromComposition":Zi(null),As(n,he,e);break;case"insertLineBreak":Zi(null),As(n,fe,!1);break;case"insertParagraph":Zi(null),an&&!l?(an=!1,As(n,fe,!1)):As(n,de,void 0);break;case"insertFromPaste":case"insertFromPasteAsQuotation":As(n,ge,e);break;case"deleteByComposition":(function(t,e){return t!==e||di(t)||di(e)||!t.isToken()||!e.isToken()})(d,h)&&As(n,_e,e);break;case"deleteByDrag":case"deleteByCut":As(n,_e,e);break;case"deleteContent":As(n,ue,!1);break;case"deleteWordBackward":As(n,pe,!0);break;case"deleteWordForward":As(n,pe,!1);break;case"deleteHardLineBackward":case"deleteSoftLineBackward":As(n,me,!0);break;case"deleteContentForward":case"deleteHardLineForward":case"deleteSoftLineForward":As(n,me,!1);break;case"formatStrikeThrough":As(n,ye,"strikethrough");break;case"formatBold":As(n,ye,"bold");break;case"formatItalic":As(n,ye,"italic");break;case"formatUnderline":As(n,ye,"underline");break;case"historyUndo":As(n,xe,void 0);break;case"historyRedo":As(n,Se,void 0)}else{if("\n"===c)e.preventDefault(),As(n,fe,!1);else if(c===W)e.preventDefault(),As(n,de,void 0);else if(null==c&&e.dataTransfer){const t=e.dataTransfer.getData("text/plain");e.preventDefault(),i.insertRawText(t)}else null!=c&&_n(i,s,c,e.timeStamp,!0)?(e.preventDefault(),As(n,he,c)):sn=c;rn=e.timeStamp}}))}(e,n)]);let en=0,nn=null,rn=0,sn=null;const on=new WeakMap;let ln=!1,cn=!1,an=!1,un=!1,fn=!1,dn="",hn=null,gn=[0,"",0,"root",0];function _n(t,e,n,r,i){const o=t.anchor,l=t.focus,c=o.getNode(),a=Gr(),u=Ys(Js(a)),f=null!==u?u.anchorNode:null,d=o.key,h=a.getElementByKey(d),g=n.length;return d!==l.key||!Yn(c)||(!i&&(!s||rn<r+50)||c.isDirty()&&g<2||ds(n))&&o.offset!==l.offset&&!c.isComposing()||ji(c)||c.isDirty()&&g>1||(i||!s)&&null!==h&&!c.isComposing()&&f!==qi(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=e.isToken();return 0===n?!e.canInsertTextBefore()||!r.canInsertTextBefore()&&!e.isComposing()||i||function(t){const e=t.getPreviousSibling();return(Yn(e)||di(e)&&e.isInline())&&!e.canInsertTextAfter()}(e):n===e.getTextContentSize()&&(!e.canInsertTextAfter()||!r.canInsertTextAfter()&&!e.isComposing()||i)}(t,c)}function pn(t,e){return Ui(t)&&null!==t.nodeValue&&0!==e&&e!==t.nodeValue.length}function mn(e,n,r){const{anchorNode:i,anchorOffset:s,focusNode:o,focusOffset:l}=e;ln&&(ln=!1,pn(i,s)&&pn(o,l)&&!hn)||ci(n,(()=>{if(!r)return void as(null);if(!Ri(n,i,o))return;let c=wr();if(hn&&cr(c)&&c.isCollapsed()){const t=c.anchor,e=hn.anchor;(t.key===e.key&&t.offset===e.offset+1||1===t.offset&&e.getNode().is(t.getNode().getPreviousSibling()))&&(c=hn.clone(),as(c))}if(hn=null,cr(c)){const r=c.anchor,i=r.getNode();if(c.isCollapsed()){"Range"===e.type&&e.anchorNode===e.focusNode&&(c.dirty=!0);const s=Js(n).event,o=s?s.timeStamp:performance.now(),[l,a,u,f,d]=gn,h=ls(),g=!1===n.isComposing()&&""===h.getTextContent();if(o<d+200&&r.offset===u&&r.key===f)yn(c,l,a);else if("text"===r.type)Yn(i)||t(141),xn(c,i);else if("element"===r.type&&!g){di(i)||t(259);const e=r.getNode();e.isEmpty()?function(t,e){const n=e.getTextFormat(),r=e.getTextStyle();yn(t,n,r)}(c,e):yn(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=L,g=!1;for(let t=0;t<i;t++){const e=n[t],r=e.getTextContentSize();if(Yn(e)&&0!==r&&!(0===t&&e.__key===f&&a===r||t===i-1&&e.__key===d&&0===u)&&(g=!0,h&=e.getFormat(),0===h))break}c.format=g?h:0}}As(n,le,void 0)}))}function yn(t,e,n){t.format===e&&t.style===n||(t.format=e,t.style=n,t.dirty=!0)}function xn(t,e){yn(t,e.getFormat(),e.getStyle())}function Sn(t){if(!t.getTargetRanges)return null;const e=t.getTargetRanges();return 0===e.length?null:e[0]}function vn(t,e){const n=t._compositionKey;if(Zi(null),null!==n&&null!=e){if(""===e){const e=es(n),r=qi(t.getElementByKey(n));return void(null!==r&&null!==r.nodeValue&&Yn(e)&&ms(e,r.nodeValue,null,null,!0))}if("\n"===e[e.length-1]){const e=wr();if(cr(e)){const n=e.focus;return e.anchor.set(n.key,n.offset,n.type),void As(t,Ee,null)}}}ps(!0,t,e)}function Cn(t){let e=t.__lexicalEventHandles;return void 0===e&&(e=[],t.__lexicalEventHandles=e),e}const kn=new Map;function bn(t){const e=Zs(t.target);if(null===e)return;const n=Ji(e.anchorNode);if(null===n)return;cn&&(cn=!1,ci(n,(()=>{const r=Nr(),i=e.anchorNode;if(no(i)||Ui(i)){as(Tr(r,e,n,t))}})));const r=hs(n),i=r[r.length-1],s=i._key,o=kn.get(s),l=o||i;l!==n&&mn(e,l,!1),mn(e,n,!0),n!==i?kn.set(s,n):o&&kn.delete(s)}function Tn(t){t._lexicalHandled=!0}function wn(t){return!0===t._lexicalHandled}const Nn=()=>{};function En(e){const n=e.ownerDocument,r=on.get(n);if(void 0===r)return void Nn();const i=r-1;i>=0||t(164),on.set(n,i),0===i&&n.removeEventListener("selectionchange",bn);const s=$i(e);Ki(s)?(!function(t){if(null!==t._parentEditor){const e=hs(t),n=e[e.length-1]._key;kn.get(n)===t&&kn.delete(n)}else kn.delete(t._key)}(s),e.__lexicalEditor=null):s&&t(198);const o=Cn(e);for(let t=0;t<o.length;t++)o[t]();e.__lexicalEventHandles=[]}function Pn(t,e,n){Vr();const r=t.__key,i=t.getParent();if(null===i)return;const s=function(t){const e=wr();if(!cr(e)||!di(t))return e;const{anchor:n,focus:r}=e,i=n.getNode(),s=r.getNode();Rs(i,t)&&n.set(t.__key,0,"element");Rs(s,t)&&r.set(t.__key,0,"element");return e}(t);let o=!1;if(cr(s)&&e){const e=s.anchor,n=s.focus;e.key===r&&(Fr(e,t,i,t.getPreviousSibling(),t.getNextSibling()),o=!0),n.key===r&&(Fr(n,t,i,t.getPreviousSibling(),t.getNextSibling()),o=!0)}else ur(s)&&e&&t.isSelected()&&t.selectPrevious();if(cr(s)&&e&&!o){const e=t.getIndexWithinParent();Xi(t),Er(s,i,e,-1)}else Xi(t);n||Us(i)||i.canBeEmpty()||!i.isEmpty()||Pn(i,e),e&&s&&mi(i)&&i.isEmpty()&&i.selectEnd()}class Fn{static getType(){t(64,this.name)}static clone(e){t(65,this.name)}afterCloneFrom(t){this.__parent=t.__parent,this.__next=t.__next,this.__prev=t.__prev,this.__state=t.__state}constructor(t){this.__type=this.constructor.getType(),this.__parent=null,this.__prev=null,this.__next=null,Object.defineProperty(this,"__state",{configurable:!0,enumerable:!1,value:void 0,writable:!0}),Qi(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=es(t);if(null===e)break;t=e.__parent}return!1}isSelected(t){const e=t||wr();if(null==e)return!1;const n=e.getNodes().some((t=>t.__key===this.__key));if(Yn(this))return n;if(cr(e)&&"element"===e.anchor.type&&"element"===e.focus.type){if(e.isCollapsed())return!1;const t=this.getParent();if(_i(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:es(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(Us(n))return di(e)||e===this&&_i(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:es(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:es(t)}getNextSiblings(){const t=[];let e=this.getNextSibling();for(;null!==e;)t.push(e),e=e.getNextSibling();return t}getCommonAncestor(t){const e=di(this)?this:this.getParent(),n=di(t)?t:t.getParent(),r=e&&n?Xo(e,n):null;return r?r.commonAncestor:null}is(t){return null!=t&&this.__key===t.__key}isBefore(e){const n=Xo(this,e);return null!==n&&("descendant"===n.type||("branch"===n.type?-1===Ho(n):("same"!==n.type&&"ancestor"!==n.type&&t(279),!1)))}isParentOf(t){const e=Xo(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=di(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=Gr()._dirtyLeaves;return null!==t&&t.has(this.__key)}getLatest(){const e=es(this.__key);return null===e&&t(113),e}getWritable(){Vr();const t=Hr(),e=Gr(),n=t._nodeMap,r=this.__key,i=this.getLatest(),s=e._cloneNotNeeded,o=wr();if(null!==o&&o.setCachedNodes(null),s.has(r))return Yi(i),i;const l=go(i);return s.add(r),Yi(l),n.set(r,l),l}getTextContent(){return""}getTextContentSize(){return this.getTextContent().length}createDOM(e,n){t(70)}updateDOM(e,n,r){t(71)}exportDOM(t){return{element:this.createDOM(t._config,t)}}exportJSON(){const t=this.__state?this.__state.toJSON():void 0;return{type:this.__type,version:1,...t}}static importJSON(e){t(18,this.name)}updateFromJSON(t){return function(t,e){const n=t.getWritable();return(e||n.__state)&&yt(t).updateFromJSON(e),n}(this,t.$)}static transform(){return null}remove(t){Pn(this,!0,t)}replace(e,n){Vr();let r=wr();null!==r&&(r=r.clone()),Hs(this,e);const i=this.getLatest(),s=this.__key,o=e.__key,l=e.getWritable(),c=this.getParentOrThrow().getWritable(),a=c.__size;Xi(l);const u=i.getPreviousSibling(),f=i.getNextSibling(),d=i.__prev,h=i.__next,g=i.__parent;if(Pn(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&&(di(this)&&di(l)||t(139),this.getChildren().forEach((t=>{l.append(t)}))),cr(r)){as(r);const t=r.anchor,e=r.focus;t.key===s&&or(t,l),e.key===s&&or(e,l)}return ts()===s&&Zi(o),l}insertAfter(t,e=!0){Vr(),Hs(this,t);const n=this.getWritable(),r=t.getWritable(),i=r.getParent(),s=wr();let o=!1,l=!1;if(null!==i){const e=t.getIndexWithinParent();if(Xi(r),cr(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&&cr(s)){const t=this.getIndexWithinParent();Er(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){Vr(),Hs(this,t);const n=this.getWritable(),r=t.getWritable(),i=r.__key;Xi(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=wr();if(e&&cr(a)){Er(a,this.getParentOrThrow(),c)}return t}isParentRequired(){return!1}createParentElementNode(){return Ti()}selectStart(){return this.selectPrevious()}selectEnd(){return this.selectNext(0,0)}selectPrevious(t,e){Vr();const n=this.getPreviousSibling(),r=this.getParentOrThrow();if(null===n)return r.select(0,0);if(di(n))return n.select();if(!Yn(n)){const t=n.getIndexWithinParent()+1;return r.select(t,t)}return n.select(t,e)}selectNext(t,e){Vr();const n=this.getNextSibling(),r=this.getParentOrThrow();if(null===n)return r.select();if(di(n))return n.select(0,0);if(!Yn(n)){const t=n.getIndexWithinParent();return r.select(t,t)}return n.select(t,e)}markDirty(){this.getWritable()}reconcileObservedMutation(t,e){this.markDirty()}}class Ln extends Fn{static getType(){return"linebreak"}static clone(t){return new Ln(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&&oo(e)){const n=e.firstChild;if(n===t||n.nextSibling===t&&In(n)){const n=e.lastChild;if(n===t||n.previousSibling===t&&In(n))return!0}}return!1}(t)||function(t){const e=t.parentElement;if(null!==e&&oo(e)){const n=e.firstChild;if(n===t||n.nextSibling===t&&In(n))return!1;const r=e.lastChild;if(r===t||r.previousSibling===t&&In(r))return!0}return!1}(t)?null:{conversion:An,priority:0}}}static importJSON(t){return On().updateFromJSON(t)}}function An(t){return{node:On()}}function On(){return qs(new Ln)}function Mn(t){return t instanceof Ln}function In(t){return Ui(t)&&/^( |\t|\r?\n)+$/.test(t.textContent||"")}function Dn(t,e){return 16&e?"code":e&F?"mark":32&e?"sub":64&e?"sup":null}function zn(t,e){return 1&e?"strong":2&e?"em":"span"}function Bn(t,e,n,r,i){const s=r.classList;let o=ws(i,"base");void 0!==o&&s.add(...o),o=ws(i,"underlineStrikethrough");let l=!1;const c=e&w&&e&T;void 0!==o&&(n&w&&n&T?(l=!0,c||s.add(...o)):c&&s.remove(...o));for(const t in U){const r=U[t];if(o=ws(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 Wn(t,e,n){const r=e.firstChild,s=n.isComposing(),o=t+(s?B:"");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 Rn(t,e,n,r,i,s){Wn(i,t,e);const o=s.theme.text;void 0!==o&&Bn(0,0,r,t,o)}function Kn(t,e){const n=document.createElement(e);return n.appendChild(t),n}class Jn extends Fn{static getType(){return"text"}static clone(t){return new Jn(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 Q[t.__mode]}getStyle(){return this.getLatest().__style}isToken(){return 1===this.getLatest().__mode}isComposing(){return this.__key===ts()}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 Hi(this.getLatest().__format,t,e)}canHaveFormat(){return!0}isInline(){return!0}createDOM(t,e){const n=this.__format,r=Dn(0,n),i=zn(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));Rn(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=Dn(0,s),c=Dn(0,o),a=zn(0,s),u=zn(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 Rn(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)),Wn(i,f,this);const d=r.theme.text;void 0!==d&&s!==o&&Bn(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:qn,priority:0}),b:()=>({conversion:jn,priority:0}),code:()=>({conversion:Qn,priority:0}),em:()=>({conversion:Qn,priority:0}),i:()=>({conversion:Qn,priority:0}),mark:()=>({conversion:Qn,priority:0}),s:()=>({conversion:Qn,priority:0}),span:()=>({conversion:$n,priority:0}),strong:()=>({conversion:Qn,priority:0}),sub:()=>({conversion:Qn,priority:0}),sup:()=>({conversion:Qn,priority:0}),u:()=>({conversion:Qn,priority:0})}}static importJSON(t){return Xn().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 no(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?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=Hi(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=G[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){Vr();let n=t,r=e;const i=wr(),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(!cr(i))return vr(o,n,o,r,"text","text");{const t=ts();t!==i.anchor.key&&t!==i.focus.key||Zi(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=wr();if(r&&cr(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){Vr();const e=this.getLatest(),n=e.getTextContent();if(""===n)return[];const r=e.__key,i=ts(),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,m=null;const y=wr();if(cr(y)){const[t,e]=y.isBackward()?[y.focus,y.anchor]:[y.anchor,y.focus];"text"===t.type&&t.key===r&&(p=t),"text"===e.type&&e.key===r&&(m=e)}e.isSegmented()?(f=Xn(a),f.__format=d,f.__style=h,f.__detail=g,_=!0):(f=e.getWritable(),f.__text=a);const x=[f];for(let t=1;t<c;t++){const e=Xn(o[t]);e.__format=d,e.__style=h,e.__detail=g;const n=e.__key;i===r&&Zi(n),x.push(e)}const S=p?p.offset:null,v=m?m.offset:null;let C=0;for(const t of x){if(!p&&!m)break;const e=C+t.getTextContentSize();if(null!==p&&null!==S&&S<=e&&S>=C&&(p.set(t.getKey(),S-C,"text"),S<e&&(p=null)),null!==m&&null!==v&&v<=e&&v>=C){m.set(t.getKey(),v-C,"text");break}C=e}if(null!==u){!function(t){const e=t.getPreviousSibling(),n=t.getNextSibling();null!==e&&Yi(e);null!==n&&Yi(n)}(this);const t=u.getWritable(),e=this.getIndexWithinParent();_?(t.splice(e,0,x),this.remove()):t.splice(e,1,x),cr(y)&&Er(y,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;ts()===i&&Zi(r);const l=wr();if(cr(l)){const t=l.anchor,s=l.focus;null!==t&&t.key===i&&Lr(t,n,r,e,o),null!==s&&s.key===i&&Lr(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 $n(t){return{forChild:Zn(t.style),node:null}}function jn(t){const e=t,n="normal"===e.style.fontWeight;return{forChild:Zn(e.style,n?void 0:"bold"),node:null}}const Un=new WeakMap;function Vn(t){if(!no(t))return!1;if("PRE"===t.nodeName)return!0;const e=t.style.whiteSpace;return"string"==typeof e&&e.startsWith("pre")}function qn(e){const n=e;null===e.parentElement&&t(129);let r=n.textContent||"";if(null!==function(t){let e,n=t.parentNode;const r=[t];for(;null!==n&&void 0===(e=Un.get(n))&&!Vn(n);)r.push(n),n=n.parentNode;const i=void 0===e?n:e;for(let t=0;t<r.length;t++)Un.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(On()):"\t"===n?e.push(er()):""!==n&&e.push(Xn(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=Hn(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=Hn(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:Xn(r)}}function Hn(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,no(n)){const t=n.style.display;if(""===t&&!so(n)||""!==t&&!t.startsWith("inline"))return null}let r=n;for(;null!==(r=e?n.firstChild:n.lastChild);)n=r;if(Ui(n))return n;if("BR"===n.nodeName)return null}}const Gn={code:"code",em:"italic",i:"italic",mark:"highlight",s:"strikethrough",strong:"bold",sub:"subscript",sup:"superscript",u:"underline"};function Qn(t){const e=Gn[t.nodeName.toLowerCase()];return void 0===e?{node:null}:{forChild:Zn(t.style,e),node:null}}function Xn(t=""){return qs(new Jn(t))}function Yn(t){return t instanceof Jn}function Zn(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=>Yn(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 tr extends Jn{static getType(){return"tab"}static clone(t){return new tr(t.__key)}constructor(t){super("\t",t),this.__detail=2}static importDOM(){return null}createDOM(t){const e=super.createDOM(t),n=ws(t.theme,"tab");if(void 0!==n){e.classList.add(...n)}return e}static importJSON(t){return er().updateFromJSON(t)}setTextContent(e){return"\t"!==e&&""!==e&&t(126),super.setTextContent(e)}setDetail(e){return 2!==e&&t(127),this}setMode(e){return"normal"!==e&&t(128),this}canInsertTextBefore(){return!1}canInsertTextAfter(){return!1}}function er(){return qs(new tr)}function nr(t){return t instanceof tr}class rr{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 qo(ll(Yo(this,"next")),ll(Yo(t,"next")))<0}getNode(){const e=es(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,Ur()||(ts()===s&&Zi(t),null!==i&&(i.setCachedNodes(null),i.dirty=!0)))}}function ir(t,e,n){return new rr(t,e,n)}function sr(t,e){let n=e.__key,r=t.offset,i="element";if(Yn(e)){i="text";const t=e.getTextContentSize();r>t&&(r=t)}else if(!di(e)){const t=e.getNextSibling();if(Yn(t))n=t.__key,r=0,i="text";else{const t=e.getParent();t&&(n=t.__key,r=e.getIndexWithinParent()+1)}}t.set(n,r,i)}function or(t,e){if(di(e)){const n=e.getLastDescendant();di(n)||Yn(n)?sr(t,n):sr(t,e)}else sr(t,e)}class lr{constructor(t){this._cachedNodes=null,this._nodes=t,this.dirty=!1}getCachedNodes(){return this._cachedNodes}setCachedNodes(t){this._cachedNodes=t}is(t){if(!ur(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 lr(new Set(this._nodes))}extract(){return this.getNodes()}insertRawText(t){}insertText(){}insertNodes(t){const e=this.getNodes(),n=e.length,r=e[n-1];let i;if(Yn(r))i=r.select();else{const t=r.getIndexWithinParent()+1;i=r.getParentOrThrow().select(t,t)}i.insertNodes(t);for(let t=0;t<n;t++)e[t].remove()}getNodes(){const t=this._cachedNodes;if(null!==t)return t;const e=this._nodes,n=[];for(const t of e){const e=es(t);null!==e&&n.push(e)}return Ur()||(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((wr()||Nr())===this&&t[0]){const e=Oo(t[0],"next");tl(Uo(e,e))}for(const e of t)e.remove()}}function cr(t){return t instanceof ar}class ar{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!!cr(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(Po(n)){const{origin:t}=n;0===e.length?i.add(t):(s.add(t),e.push(t))}else{const{origin:t}=n;di(t)&&s.has(t)||e.push(t)}r&&e.push(r.caret.origin);if(Eo(t.focus)&&di(t.focus.origin)&&null===t.focus.getNodeAtCaret())for(let n=zo(t.focus.origin,"previous");Po(n)&&i.has(n.origin)&&!n.origin.isEmpty()&&n.origin.is(e[e.length-1]);n=Wo(n))i.delete(n.origin),e.pop();for(;e.length>1;){const t=e[e.length-1];if(!di(t)||s.has(t)||t.isEmpty()||i.has(t))break;e.pop()}if(0===e.length&&t.isCollapsed()){const n=ll(t.anchor),r=ll(t.anchor.getFlipped()),i=t=>wo(t)?t.origin:t.getNodeAtCaret(),s=i(n)||i(r)||(t.anchor.getNodeAtCaret()?n.origin:r.origin);e.push(s)}return e}(ul(nl(this),"next"));return Ur()||(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,s=r.isBefore(i),[o,l]=dr(this);let c="",a=!0;for(let u=0;u<t.length;u++){const f=t[u];if(di(f)&&!f.isInline())a||(c+="\n"),a=!f.isEmpty();else if(a=!1,Yn(f)){let t=f.getTextContent();f===e?f===n?"element"===r.type&&"element"===i.type&&i.offset!==r.offset||(t=o<l?t.slice(o,l):t.slice(l,o)):t=s?t.slice(o):t.slice(l):f===n&&(t=s?t.slice(0,l):t.slice(0,o)),c+=t}else!_i(f)&&!Mn(f)||f===n&&this.isCollapsed()||(c+=f.getTextContent())}return c}applyDOMRange(t){const e=Gr(),n=e.getEditorState()._selection,r=xr(t.startContainer,t.startOffset,t.endContainer,t.endOffset,e,n);if(null===r)return;const[i,s]=r;this.anchor.set(i.key,i.offset,i.type,!0),this.focus.set(s.key,s.offset,s.type,!0),Ct(this)}clone(){const t=this.anchor,e=this.focus;return new ar(ir(t.key,t.offset,t.type),ir(e.key,e.offset,e.type),this.format,this.style)}toggleFormat(t){this.format=Hi(this.format,t,null),this.dirty=!0}setStyle(t){this.style=t,this.dirty=!0}hasFormat(t){const e=U[t];return!!(this.format&e)}insertRawText(t){const e=t.split(/(\r?\n|\t)/),n=[],r=e.length;for(let t=0;t<r;t++){const r=e[t];"\n"===r||"\r\n"===r?n.push(On()):"\t"===r?n.push(er()):n.push(Xn(r))}this.insertNodes(n)}insertText(e){const n=this.anchor,r=this.focus,i=this.format,s=this.style;let o=n,l=r;!this.isCollapsed()&&r.isBefore(n)&&(o=r,l=n),"element"===o.type&&function(t,e,n,r){const i=t.getNode(),s=i.getChildAtIndex(t.offset),o=Xn(),l=mi(i)?Ti().append(o):o;o.setFormat(n),o.setStyle(r),null===s?i.append(l):s.insertBefore(l),t.is(e)&&e.set(o.__key,0,"text"),t.set(o.__key,0,"text")}(o,l,i,s),"element"===l.type&&Zo(l,ll(Yo(l,"next")));const c=o.offset;let a=l.offset;const u=this.getNodes(),f=u.length;let d=u[0];Yn(d)||t(26);const h=d.getTextContent().length,g=d.getParentOrThrow();let _=u[f-1];if(1===f&&"element"===l.type&&(a=h,l.set(o.key,a,"text")),this.isCollapsed()&&c===h&&(d.isSegmented()||d.isToken()||!d.