UNPKG

lexical

Version:

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

9 lines (8 loc) 126 kB
/** * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * */ "use strict";function t(t,...e){const n=new URL("https://lexical.dev/docs/error"),r=new URLSearchParams;r.append("code",t);for(const t of e)r.append("v",t);throw n.search=r.toString(),Error(`Minified Lexical error #${t}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}const e="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement,n=e&&"documentMode"in document?document.documentMode:null,r=e&&/Mac|iPod|iPhone|iPad/.test(navigator.platform),i=e&&/^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent),o=!(!e||!("InputEvent"in window)||n)&&"getTargetRanges"in new window.InputEvent("input"),s=e&&/Version\/[\d.]+.*Safari/.test(navigator.userAgent),l=e&&/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream,c=e&&/Android/.test(navigator.userAgent),a=e&&/^(?=.*Chrome).*/i.test(navigator.userAgent),u=e&&c&&a,f=e&&/AppleWebKit\/[\d.]+/.test(navigator.userAgent)&&!a;function d(...t){const e=[];for(const n of t)if(n&&"string"==typeof n)for(const[t]of n.matchAll(/\S+/g))e.push(t);return e}const h=1,g=3,p=9,_=11,m=0,y=1,x=2,C=0,S=1,T=2,v=4,N=8,k=128,b=1792|(112|(3|v|N)|k),E=1,w=2,O=3,M=4,A=5,D=6,P=s||l||f?" ":"​",L="\n\n",F=i?" ":P,I="֑-߿יִ-﷽ﹰ-ﻼ",R="A-Za-zÀ-ÖØ-öø-ʸ̀-֐ࠀ-῿‎Ⰰ-﬜︀-﹯﻽-￿",B=new RegExp("^[^"+R+"]*["+I+"]"),z=new RegExp("^[^"+I+"]*["+R+"]"),W={bold:1,capitalize:1024,code:16,highlight:k,italic:2,lowercase:256,strikethrough:v,subscript:32,superscript:64,underline:N,uppercase:512},$={directionless:1,unmergeable:2},K={center:w,end:D,justify:M,left:E,right:O,start:A},U={[w]:"center",[D]:"end",[M]:"justify",[E]:"left",[O]:"right",[A]:"start"},J={normal:0,segmented:2,token:1},j={[C]:"normal",[T]:"segmented",[S]:"token"},V="$";function H(t,e,n,r,i,o){let s=t.getFirstChild();for(;null!==s;){const t=s.__key;s.__parent===e&&(Zr(s)&&H(s,t,n,r,i,o),n.has(t)||o.delete(t),i.push(t)),s=s.getNextSibling()}}const Y=100;let q=!1,G=0;function X(t){G=t.timeStamp}function Q(t,e,n){const r="BR"===t.nodeName,i=e.__lexicalLineBreak;return i&&(t===i||r&&t.previousSibling===i)||r&&void 0!==Fi(t,n)}function Z(t,e,n){const r=Eo(yo(n));let i=null,o=null;null!==r&&r.anchorNode===t&&(i=r.anchorOffset,o=r.focusOffset);const s=t.nodeValue;null!==s&&qi(e,s,i,o,!1)}function tt(t,e,n){if(tr(t)){const e=t.anchor.getNode();if(e.is(n)&&t.format!==e.getFormat())return!1}return Ni(e)&&n.isAttached()}function et(t,e,n,r){for(let i=t;i&&!$o(i);i=fo(i)){const t=Fi(i,e);if(void 0!==t){const e=Pi(t,n);if(e)return ni(e)||!Oo(i)?void 0:[i,e]}else if(i===r)return[r,Wi(n)]}}function nt(t,e,n){q=!0;const r=performance.now()-G>Y;try{qr(t,(()=>{const o=_r()||function(t){return t.getEditorState().read((()=>{const t=_r();return null!==t?t.clone():null}))}(t),s=new Map,l=t.getRootElement(),c=t._editorState,a=t._blockCursorElement;let u=!1,f="";for(let n=0;n<e.length;n++){const d=e[n],h=d.type,g=d.target,p=et(g,t,c,l);if(!p)continue;const[_,m]=p;if("characterData"===h)r&&Jn(m)&&Ni(g)&&tt(o,g,m)&&Z(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],o=Li(r),s=r.parentNode;if(null!=s&&r!==a&&null===o&&!Q(r,s,t)){if(i){const t=(Oo(r)?r.innerText:null)||r.nodeValue;t&&(f+=t)}s.removeChild(r)}}const n=d.removedNodes,r=n.length;if(r>0){let e=0;for(let i=0;i<r;i++){const r=n[i];(Q(r,g,t)||a===r)&&(g.appendChild(r),e++)}r!==e&&s.set(_,m)}}}if(s.size>0)for(const[e,n]of s)n.reconcileObservedMutation(e,t);const d=n.takeRecords();if(d.length>0){for(let e=0;e<d.length;e++){const n=d[e],r=n.addedNodes,i=n.target;for(let e=0;e<r.length;e++){const n=r[e],o=n.parentNode;null==o||"BR"!==n.nodeName||Q(n,i,t)||o.removeChild(n)}}n.takeRecords()}null!==o&&(u&&$i(o),i&&lo(t)&&o.insertRawText(f))}))}finally{q=!1}}function rt(t){const e=t._observer;if(null!==e){nt(t,e.takeRecords(),e)}}function it(t){!function(t){0===G&&yo(t).addEventListener("textInput",X,!0)}(t),t._observer=new MutationObserver(((e,n)=>{nt(t,e,n)}))}function ot(t){return t}class st{constructor(t,e){this.key=t,this.parse=e.parse.bind(e),this.unparse=(e.unparse||ot).bind(e),this.isEqual=(e.isEqual||Object.is).bind(e),this.defaultValue=this.parse(void 0)}}function lt(t,e,n="latest"){const r=("latest"===n?t.getLatest():t).__state;return r?r.getValue(e):e.defaultValue}class ct{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 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}(e,n,r);this.size=o}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 at(t)?{[V]:t}:{}}getWritable(t){if(this.node===t)return this;const e=new Map(this.knownState),n=at(r=this.unknownState)&&{...r};var r;if(n)for(const t of e.keys())delete n[t.key];return new ct(t,this.sharedConfigMap,at(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=at(this.unknownState)}}function at(t){if(t)for(const e in t)return t}function ut(t){const e=t.getWritable(),n=e.__state?e.__state.getWritable(e):new ct(e);return e.__state=n,n}function ft(t,e){const n=t.__mode,r=t.__format,i=t.__style,o=e.__mode,s=e.__format,l=e.__style,c=t.__state,a=e.__state;return(null===n||n===o)&&(null===r||r===s)&&(null===i||i===l)&&(null===t.__state||c===a||function(t,e){if(t===e)return!0;if(t&&e&&t.size!==e.size)return!1;const n=new Set,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 dt(t,e){const n=t.mergeWithSibling(e),r=Rr()._normalizedNodes;return r.add(t.__key),r.add(e.__key),n}function ht(t){let e,n,r=t;if(""!==r.__text||!r.isSimpleText()||r.isUnmergeable()){for(;null!==(e=r.getPreviousSibling())&&Jn(e)&&e.isSimpleText()&&!e.isUnmergeable();){if(""!==e.__text){if(ft(e,r)){r=dt(e,r);break}break}e.remove()}for(;null!==(n=r.getNextSibling())&&Jn(n)&&n.isSimpleText()&&!n.isUnmergeable();){if(""!==n.__text){if(ft(r,n)){r=dt(r,n);break}break}n.remove()}}else r.remove()}function gt(t){return pt(t.anchor),pt(t.focus),t}function pt(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),Jn(r)){t.set(r.__key,i?r.getTextContentSize():0,"text",!0);break}if(!Zr(r))break;t.set(r.__key,i?r.getChildrenSize():0,"element",!0)}}let _t,mt,yt,xt,Ct,St,Tt,vt,Nt,kt,bt="",Et="",wt=null,Ot="",Mt="",At=!1,Dt=!1,Pt=null;function Lt(t,e){const n=Tt.get(t);if(null!==e){const n=Xt(t);n.parentNode===e&&e.removeChild(n)}if(vt.has(t)||mt._keyToDOMMap.delete(t),Zr(n)){const t=Vt(n,Tt);Ft(t,0,t.length-1,null)}void 0!==n&&io(kt,yt,xt,n,"destroyed")}function Ft(t,e,n,r){let i=e;for(;i<=n;++i){const e=t[i];void 0!==e&&Lt(e,r)}}function It(t,e){t.setProperty("text-align",e)}const Rt="40px";function Bt(t,e){const n=_t.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")||Rt;t.style.setProperty("padding-inline-start",0===e?"":`calc(${e} * ${r})`)}function zt(t,e){const n=t.style;0===e?It(n,""):e===E?It(n,"left"):e===w?It(n,"center"):e===O?It(n,"right"):e===M?It(n,"justify"):e===A?It(n,"start"):e===D&&It(n,"end")}function Wt(e,n){const r=vt.get(e);void 0===r&&t(60);const i=r.createDOM(_t,mt);if(function(t,e,n){const r=n._keyToDOMMap;(function(t,e,n){const r=`__lexicalKey_${e._key}`;t[r]=n})(e,n,t),r.set(t,e)}(e,i,mt),Jn(r)?i.setAttribute("data-lexical-text","true"):ni(r)&&i.setAttribute("data-lexical-decorator","true"),Zr(r)){const t=r.__indent,e=r.__size;if(0!==t&&Bt(i,t),0!==e){const t=e-1;!function(t,e,n,r){const i=Et;Et="",$t(t,n,0,e,n.getDOMSlot(r)),Jt(n,r),Et=i}(Vt(r,vt),t,r,i)}const n=r.__format;0!==n&&zt(i,n),r.isInline()||Ut(null,r,i),ao(r)&&(bt+=L,Mt+=L)}else{const t=r.getTextContent();if(ni(r)){const t=r.decorate(mt,_t);null!==t&&Yt(e,t),i.contentEditable="false"}else Jn(r)&&(r.isDirectionless()||(Et+=t));bt+=t,Mt+=t}return null!==n&&n.insertChild(i),io(kt,yt,xt,r,"created"),i}function $t(t,e,n,r,i){const o=bt;bt="";let s=n;for(;s<=r;++s){Wt(t[s],i);const e=vt.get(t[s]);null!==e&&Jn(e)&&(null===wt&&(wt=e.getFormat()),""===Ot&&(Ot=e.getStyle()))}ao(e)&&(bt+=L);i.element.__lexicalTextContent=bt,bt=o+bt}function Kt(t,e){if(t){const n=t.__last;if(n){const t=e.get(n);if(t)return bn(t)?"line-break":ni(t)&&t.isInline()?"decorator":null}return"empty"}return null}function Ut(t,e,n){const r=Kt(t,Tt),i=Kt(e,vt);r!==i&&e.getDOMSlot(n).setManagedLineBreak(i)}function Jt(t,e){const n=e.__lexicalDirTextContent||"",r=e.__lexicalDir||"";if(n!==Et||r!==Pt){const n=""===Et,i=n?Pt:function(t){if(B.test(t))return"rtl";if(z.test(t))return"ltr";return null}(Et);if(i!==r){const o=e.classList,s=_t.theme;let l=null!==r?s[r]:void 0,c=null!==i?s[i]:void 0;if(void 0!==l){if("string"==typeof l){const t=d(l);l=s[r]=t}o.remove(...l)}if(null===i||n&&"ltr"===i)e.removeAttribute("dir");else{if(void 0!==c){if("string"==typeof c){const t=d(c);c=s[i]=t}void 0!==c&&o.add(...c)}e.dir=i}if(!Dt){t.getWritable().__dir=i}}Pt=i,e.__lexicalDirTextContent=Et,e.__lexicalDir=i}}function jt(e,n,r){const i=Et;var o;Et="",wt=null,Ot="",function(e,n,r){const i=bt,o=e.__size,s=n.__size;bt="";const l=r.element;if(1===o&&1===s){const t=e.__first,r=n.__first;if(t===r)Ht(t,l);else{const e=Xt(t),n=Wt(r,null);try{l.replaceChild(n,e)}catch(i){if("object"==typeof i&&null!=i){const o=`${i.toString()} Parent: ${l.tagName}, new child: {tag: ${n.tagName} key: ${r}}, old child: {tag: ${e.tagName}, key: ${t}}.`;throw new Error(o)}throw i}Lt(t,null)}const i=vt.get(r);Jn(i)&&(null===wt&&(wt=i.getFormat()),""===Ot&&(Ot=i.getStyle()))}else{const i=Vt(e,Tt),c=Vt(n,vt);if(i.length!==o&&t(227),c.length!==s&&t(228),0===o)0!==s&&$t(c,n,0,s-1,r);else if(0===s){if(0!==o){const t=null==r.after&&null==r.before&&null==r.element.__lexicalLineBreak;Ft(i,0,o-1,t?null:l),t&&(l.textContent="")}}else!function(t,e,n,r,i,o){const s=r-1,l=i-1;let c,a,u=o.getFirstChild(),f=0,d=0;for(;f<=s&&d<=l;){const t=e[f],r=n[d];if(t===r)u=qt(Ht(r,o.element)),f++,d++;else{void 0===c&&(c=new Set(e)),void 0===a&&(a=new Set(n));const i=a.has(t),s=c.has(r);if(i)if(s){const t=uo(mt,r);t===u?u=qt(Ht(r,o.element)):(o.withBefore(u).insertChild(t),Ht(r,o.element)),f++,d++}else Wt(r,o.withBefore(u)),d++;else u=qt(Xt(t)),Lt(t,o.element),f++}const i=vt.get(r);null!==i&&Jn(i)&&(null===wt&&(wt=i.getFormat()),""===Ot&&(Ot=i.getStyle()))}const h=f>s,g=d>l;if(h&&!g){const e=n[l+1],r=void 0===e?null:mt.getElementByKey(e);$t(n,t,d,l,o.withBefore(r))}else g&&!h&&Ft(e,f,s,o.element)}(n,i,c,o,s,r)}ao(n)&&(bt+=L);l.__lexicalTextContent=bt,bt=i+bt}(e,n,n.getDOMSlot(r)),Jt(n,r),o=n,null==wt||wt===o.__textFormat||Dt||o.setTextFormat(wt),function(t){""===Ot||Ot===t.__textStyle||Dt||t.setTextStyle(Ot)}(n),Et=i}function Vt(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 Ht(e,n){const r=Tt.get(e);let i=vt.get(e);void 0!==r&&void 0!==i||t(61);const o=At||St.has(e)||Ct.has(e),s=uo(mt,e);if(r===i&&!o){if(Zr(r)){const t=s.__lexicalTextContent;void 0!==t&&(bt+=t,Mt+=t);const e=s.__lexicalDirTextContent;void 0!==e&&(Et+=e)}else{const t=r.getTextContent();Jn(r)&&!r.isDirectionless()&&(Et+=t),Mt+=t,bt+=t}return s}if(r!==i&&o&&io(kt,yt,xt,i,"updated"),i.updateDOM(r,s,_t)){const r=Wt(e,null);return null===n&&t(62),n.replaceChild(r,s),Lt(e,null),r}if(Zr(r)&&Zr(i)){const t=i.__indent;t!==r.__indent&&Bt(s,t);const e=i.__format;e!==r.__format&&zt(s,e),o&&(jt(r,i,s),ii(i)||i.isInline()||Ut(r,i,s)),ao(i)&&(bt+=L,Mt+=L)}else{const t=i.getTextContent();if(ni(i)){const t=i.decorate(mt,_t);null!==t&&Yt(e,t)}else Jn(i)&&!i.isDirectionless()&&(Et+=t);bt+=t,Mt+=t}if(!Dt&&ii(i)&&i.__cachedText!==Mt){const t=i.getWritable();t.__cachedText=Mt,i=t}return s}function Yt(t,e){let n=mt._pendingDecorators;const r=mt._decorators;if(null===n){if(r[t]===e)return;n=Ri(mt)}n[t]=e}function qt(t){let e=t.nextSibling;return null!==e&&e===mt._blockCursorElement&&(e=e.nextSibling),e}function Gt(t,e,n,r,i,o){bt="",Mt="",Et="",At=r===x,Pt=null,mt=n,_t=n._config,yt=n._nodes,xt=mt._listeners.mutation,Ct=i,St=o,Tt=t._nodeMap,vt=e._nodeMap,Dt=e._readOnly,Nt=new Map(n._keyToDOMMap);const s=new Map;return kt=s,Ht("root",null),mt=void 0,yt=void 0,Ct=void 0,St=void 0,Tt=void 0,vt=void 0,_t=void 0,Nt=void 0,kt=void 0,s}function Xt(e){const n=Nt.get(e);return void 0===n&&t(75,e),n}function Qt(t){return{}}const Zt={},te={},ee={},ne={},re={},ie={},oe={},se={},le={},ce={},ae={},ue={},fe={},de={},he={},ge={},pe={},_e={},me={},ye={},xe={},Ce={},Se={},Te={},ve={},Ne={},ke={},be={},Ee={},we={},Oe={},Me={},Ae={},De={},Pe={},Le={},Fe={},Ie={},Re={},Be={},ze={},We={},$e={},Ke={},Ue={},Je=Object.freeze({}),je=30,Ve=[["keydown",function(t,e){if(He=t.timeStamp,Ye=t.key,e.isComposing())return;const{key:n,shiftKey:o,ctrlKey:s,metaKey:l,altKey:c}=t;if(co(e,he,t))return;if(null==n)return;if(nn&&to(Ye))return qr(e,(()=>{hn(e,rn)})),nn=!1,void(rn="");if(function(t,e,n,r){return Xi(t)&&!e&&!r&&!n}(n,s,c,l))co(e,ge,t);else if(function(t,e,n,r,i){return Xi(t)&&!r&&!n&&(e||i)}(n,s,o,c,l))co(e,pe,t);else if(function(t,e,n,r){return Gi(t)&&!e&&!r&&!n}(n,s,c,l))co(e,_e,t);else if(function(t,e,n,r,i){return Gi(t)&&!r&&!n&&(e||i)}(n,s,o,c,l))co(e,me,t);else if(function(t,e,n){return function(t){return"ArrowUp"===t}(t)&&!e&&!n}(n,s,l))co(e,ye,t);else if(function(t,e,n){return function(t){return"ArrowDown"===t}(t)&&!e&&!n}(n,s,l))co(e,xe,t);else if(function(t,e){return Zi(t)&&e}(n,o))tn=!0,co(e,Ce,t);else if(function(t){return" "===t}(n))co(e,Se,t);else if(function(t,e){return r&&e&&"o"===t.toLowerCase()}(n,s))t.preventDefault(),tn=!0,co(e,re,!0);else if(function(t,e){return Zi(t)&&!e}(n,o))tn=!1,co(e,Ce,t);else if(function(t,e,n,i){if(r)return!e&&!n&&(to(t)||"h"===t.toLowerCase()&&i);if(i||e||n)return!1;return to(t)}(n,c,l,s))to(n)?co(e,Te,t):(t.preventDefault(),co(e,ne,!0));else if(function(t){return"Escape"===t}(n))co(e,ve,t);else if(function(t,e,n,i,o){if(r)return!(n||i||o)&&(eo(t)||"d"===t.toLowerCase()&&e);if(e||i||o)return!1;return eo(t)}(n,s,o,c,l))eo(n)?co(e,Ne,t):(t.preventDefault(),co(e,ne,!1));else if(function(t,e,n){return to(t)&&(r?e:n)}(n,c,s))t.preventDefault(),co(e,ce,!0);else if(function(t,e,n){return eo(t)&&(r?e:n)}(n,c,s))t.preventDefault(),co(e,ce,!1);else if(function(t,e){return r&&e&&to(t)}(n,l))t.preventDefault(),co(e,ae,!0);else if(function(t,e,n){return r&&(e&&eo(t)||n&&"k"===t.toLowerCase())}(n,l,s))t.preventDefault(),co(e,ae,!1);else if(function(t,e,n,r){return"b"===t.toLowerCase()&&!e&&Qi(n,r)}(n,c,l,s))t.preventDefault(),co(e,ue,"bold");else if(function(t,e,n,r){return"u"===t.toLowerCase()&&!e&&Qi(n,r)}(n,c,l,s))t.preventDefault(),co(e,ue,"underline");else if(function(t,e,n,r){return"i"===t.toLowerCase()&&!e&&Qi(n,r)}(n,c,l,s))t.preventDefault(),co(e,ue,"italic");else if(function(t,e,n,r){return"Tab"===t&&!e&&!n&&!r}(n,c,s,l))co(e,ke,t);else if(function(t,e,n,r){return"z"===t.toLowerCase()&&!e&&Qi(n,r)}(n,o,l,s))t.preventDefault(),co(e,fe,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,o,l,s))t.preventDefault(),co(e,de,void 0);else{const c=e._editorState._selection;null===c||tr(c)?!i&&no(n,l,s)&&(t.preventDefault(),co(e,Ie,t)):!function(t,e,n,i){if(e)return!1;if("c"===t.toLowerCase())return r?n:i;return!1}(n,o,l,s)?!function(t,e,n,i){if(e)return!1;if("x"===t.toLowerCase())return r?n:i;return!1}(n,o,l,s)?no(n,l,s)&&(t.preventDefault(),co(e,Ie,t)):(t.preventDefault(),co(e,Fe,t)):(t.preventDefault(),co(e,Le,t))}(function(t,e,n,r){return t||e||n||r})(s,o,c,l)&&co(e,Ue,t)}],["pointerdown",function(t,e){const n=t.target,r=t.pointerType;Mo(n)&&"touch"!==r&&0===t.button&&qr(e,(()=>{mi(n)||(Ze=!0)}))}],["compositionstart",function(t,e){qr(e,(()=>{const n=_r();if(tr(n)&&!e.isComposing()){const r=n.anchor,i=n.anchor.getNode();Ai(r.key),(t.timeStamp<He+je||"element"===r.type||!n.isCollapsed()||i.getFormat()!==n.format||Jn(i)&&i.getStyle()!==n.style)&&co(e,oe,F)}}))}],["compositionend",function(t,e){i?en=!0:l||!s&&!f?qr(e,(()=>{hn(e,t.data)})):(nn=!0,rn=t.data)}],["input",function(t,e){t.stopPropagation(),qr(e,(()=>{if(Oo(t.target)&&mi(t.target))return;const n=_r(),r=t.data,c=dn(t);if(null!=r&&tr(n)&&ln(n,c,r,t.timeStamp,!1)){en&&(hn(e,r),en=!1);const c=n.anchor.getNode(),a=Eo(yo(e));if(null===a)return;const u=n.isBackward(),d=u?n.anchor.offset:n.focus.offset,h=u?n.focus.offset:n.anchor.offset;o&&!n.isCollapsed()&&Jn(c)&&null!==a.anchorNode&&c.getTextContent().slice(0,d)+r+c.getTextContent().slice(d+h)===Hi(a.anchorNode)||co(e,oe,r);const g=r.length;i&&g>1&&"insertCompositionText"===t.inputType&&!e.isComposing()&&(n.anchor.offset-=g),s||l||f||!e.isComposing()||(He=0,Ai(null))}else{Yi(!1,e,null!==r?r:void 0),en&&(hn(e,r||void 0),en=!1)}!function(){Lr();const t=Rr();rt(t)}()}),{event:t}),Ge=null}],["click",function(t,e){qr(e,(()=>{const n=_r(),r=Eo(yo(e)),i=mr();if(r)if(tr(n)){const e=n.anchor,o=e.getNode();if("element"===e.type&&0===e.offset&&n.isCollapsed()&&!ii(o)&&1===zi().getChildrenSize()&&o.getTopLevelElementOrThrow().isEmpty()&&null!==i&&n.is(i))r.removeAllRanges(),n.dirty=!0;else if(3===t.detail&&!n.isCollapsed()){if(o!==n.focus.getNode()){const t=function(t,e){let n=t;for(;n!==zi()&&null!=n;){if(e(n))return n;n=n.getParent()}return null}(o,(t=>Zr(t)&&!t.isInline()));Zr(t)&&t.select(0)}}}else if("touch"===t.pointerType){const n=r.anchorNode;if(Oo(n)||Ni(n)){$i(pr(i,r,e,t))}}co(e,ee,t)}))}],["cut",Je],["copy",Je],["dragstart",Je],["dragover",Je],["dragend",Je],["paste",Je],["focus",Je],["blur",Je],["drop",Je]];o&&Ve.push(["beforeinput",(e,n)=>function(e,n){const r=e.inputType,o=dn(e);if("deleteCompositionText"===r||i&&lo(n))return;if("insertCompositionText"===r)return;qr(n,(()=>{const i=_r();if("deleteContentBackward"===r){if(null===i){const t=mr();if(!tr(t))return;$i(t.clone())}if(tr(i)){const r=i.anchor.key===i.focus.key;if(s=e.timeStamp,"MediaLast"===Ye&&s<He+je&&n.isComposing()&&r){if(Ai(null),He=0,setTimeout((()=>{qr(n,(()=>{Ai(null)}))}),je),tr(i)){const e=i.anchor.getNode();e.markDirty(),Jn(e)||t(142),fn(i,e)}}else{Ai(null),e.preventDefault();const t=i.anchor.getNode(),o=t.getTextContent(),s=t.canInsertTextAfter(),l=0===i.anchor.offset&&i.focus.offset===o.length;let c=u&&r&&!l&&s;if(c&&i.isCollapsed()&&(c=!ni(so(i.anchor,!0))),!c){co(n,ne,!0);const t=_r();u&&tr(t)&&t.isCollapsed()&&(on=t,setTimeout((()=>on=null)))}}return}}var s;if(!tr(i))return;const c=e.data;null!==Ge&&Yi(!1,n,Ge),i.dirty&&null===Ge||!i.isCollapsed()||ii(i.anchor.getNode())||null===o||i.applyDOMRange(o),Ge=null;const a=i.anchor,f=i.focus,d=a.getNode(),h=f.getNode();if("insertText"!==r&&"insertTranspose"!==r)switch(e.preventDefault(),r){case"insertFromYank":case"insertFromDrop":case"insertReplacementText":co(n,oe,e);break;case"insertFromComposition":Ai(null),co(n,oe,e);break;case"insertLineBreak":Ai(null),co(n,re,!1);break;case"insertParagraph":Ai(null),tn&&!l?(tn=!1,co(n,re,!1)):co(n,ie,void 0);break;case"insertFromPaste":case"insertFromPasteAsQuotation":co(n,se,e);break;case"deleteByComposition":(function(t,e){return t!==e||Zr(t)||Zr(e)||!t.isToken()||!e.isToken()})(d,h)&&co(n,le,e);break;case"deleteByDrag":case"deleteByCut":co(n,le,e);break;case"deleteContent":co(n,ne,!1);break;case"deleteWordBackward":co(n,ce,!0);break;case"deleteWordForward":co(n,ce,!1);break;case"deleteHardLineBackward":case"deleteSoftLineBackward":co(n,ae,!0);break;case"deleteContentForward":case"deleteHardLineForward":case"deleteSoftLineForward":co(n,ae,!1);break;case"formatStrikeThrough":co(n,ue,"strikethrough");break;case"formatBold":co(n,ue,"bold");break;case"formatItalic":co(n,ue,"italic");break;case"formatUnderline":co(n,ue,"underline");break;case"historyUndo":co(n,fe,void 0);break;case"historyRedo":co(n,de,void 0)}else{if("\n"===c)e.preventDefault(),co(n,re,!1);else if(c===L)e.preventDefault(),co(n,ie,void 0);else if(null==c&&e.dataTransfer){const t=e.dataTransfer.getData("text/plain");e.preventDefault(),i.insertRawText(t)}else null!=c&&ln(i,o,c,e.timeStamp,!0)?(e.preventDefault(),co(n,oe,c)):Ge=c;qe=e.timeStamp}}))}(e,n)]);let He=0,Ye=null,qe=0,Ge=null;const Xe=new WeakMap;let Qe=!1,Ze=!1,tn=!1,en=!1,nn=!1,rn="",on=null,sn=[0,"",0,"root",0];function ln(t,e,n,r,i){const s=t.anchor,l=t.focus,c=s.getNode(),a=Rr(),u=Eo(yo(a)),f=null!==u?u.anchorNode:null,d=s.key,h=a.getElementByKey(d),g=n.length;return d!==l.key||!Jn(c)||(!i&&(!o||qe<r+50)||c.isDirty()&&g<2||Ji(n))&&s.offset!==l.offset&&!c.isComposing()||vi(c)||c.isDirty()&&g>1||(i||!o)&&null!==h&&!c.isComposing()&&f!==bi(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(Jn(e)||Zr(e)&&e.isInline())&&!e.canInsertTextAfter()}(e):n===e.getTextContentSize()&&(!e.canInsertTextAfter()||!r.canInsertTextAfter()&&!e.isComposing()||i)}(t,c)}function cn(t,e){return Ni(t)&&null!==t.nodeValue&&0!==e&&e!==t.nodeValue.length}function an(e,n,r){const{anchorNode:i,anchorOffset:o,focusNode:s,focusOffset:l}=e;Qe&&(Qe=!1,cn(i,o)&&cn(s,l)&&!on)||qr(n,(()=>{if(!r)return void $i(null);if(!xi(n,i,s))return;let c=_r();if(on&&tr(c)&&c.isCollapsed()){const t=c.anchor,e=on.anchor;(t.key===e.key&&t.offset===e.offset+1||1===t.offset&&e.getNode().is(t.getNode().getPreviousSibling()))&&(c=on.clone(),$i(c))}if(on=null,tr(c)){const r=c.anchor,i=r.getNode();if(c.isCollapsed()){"Range"===e.type&&e.anchorNode===e.focusNode&&(c.dirty=!0);const o=yo(n).event,s=o?o.timeStamp:performance.now(),[l,a,u,f,d]=sn,h=zi(),g=!1===n.isComposing()&&""===h.getTextContent();if(s<d+200&&r.offset===u&&r.key===f)un(c,l,a);else if("text"===r.type)Jn(i)||t(141),fn(c,i);else if("element"===r.type&&!g){Zr(i)||t(259);const e=r.getNode();e.isEmpty()?function(t,e){const n=e.getTextFormat(),r=e.getTextStyle();un(t,n,r)}(c,e):un(c,0,"")}}else{const t=r.key,e=c.focus.key,n=c.getNodes(),i=n.length,s=c.isBackward(),a=s?l:o,u=s?o:l,f=s?e:t,d=s?t:e;let h=b,g=!1;for(let t=0;t<i;t++){const e=n[t],r=e.getTextContentSize();if(Jn(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}}co(n,Zt,void 0)}))}function un(t,e,n){t.format===e&&t.style===n||(t.format=e,t.style=n,t.dirty=!0)}function fn(t,e){un(t,e.getFormat(),e.getStyle())}function dn(t){if(!t.getTargetRanges)return null;const e=t.getTargetRanges();return 0===e.length?null:e[0]}function hn(t,e){const n=t._compositionKey;if(Ai(null),null!==n&&null!=e){if(""===e){const e=Pi(n),r=bi(t.getElementByKey(n));return void(null!==r&&null!==r.nodeValue&&Jn(e)&&qi(e,r.nodeValue,null,null,!0))}if("\n"===e[e.length-1]){const e=_r();if(tr(e)){const n=e.focus;return e.anchor.set(n.key,n.offset,n.type),void co(t,Ce,null)}}}Yi(!0,t,e)}function gn(t){let e=t.__lexicalEventHandles;return void 0===e&&(e=[],t.__lexicalEventHandles=e),e}const pn=new Map;function _n(t){const e=wo(t.target);if(null===e)return;const n=Si(e.anchorNode);if(null===n)return;Ze&&(Ze=!1,qr(n,(()=>{const r=mr(),i=e.anchorNode;if(Oo(i)||Ni(i)){$i(pr(r,e,n,t))}})));const r=ji(n),i=r[r.length-1],o=i._key,s=pn.get(o),l=s||i;l!==n&&an(e,l,!1),an(e,n,!0),n!==i?pn.set(o,n):s&&pn.delete(o)}function mn(t){t._lexicalHandled=!0}function yn(t){return!0===t._lexicalHandled}const xn=()=>{};function Cn(e){const n=e.ownerDocument,r=Xe.get(n);if(void 0===r)return void xn();const i=r-1;i>=0||t(164),Xe.set(n,i),0===i&&n.removeEventListener("selectionchange",_n);const o=Ti(e);Ci(o)?(!function(t){if(null!==t._parentEditor){const e=ji(t),n=e[e.length-1]._key;pn.get(n)===t&&pn.delete(n)}else pn.delete(t._key)}(o),e.__lexicalEditor=null):o&&t(198);const s=gn(e);for(let t=0;t<s.length;t++)s[t]();e.__lexicalEventHandles=[]}function Sn(t,e,n){Lr();const r=t.__key,i=t.getParent();if(null===i)return;const o=function(t){const e=_r();if(!tr(e)||!Zr(t))return e;const{anchor:n,focus:r}=e,i=n.getNode(),o=r.getNode();_o(i,t)&&n.set(t.__key,0,"element");_o(o,t)&&r.set(t.__key,0,"element");return e}(t);let s=!1;if(tr(o)&&e){const e=o.anchor,n=o.focus;e.key===r&&(Cr(e,t,i,t.getPreviousSibling(),t.getNextSibling()),s=!0),n.key===r&&(Cr(n,t,i,t.getPreviousSibling(),t.getNextSibling()),s=!0)}else nr(o)&&e&&t.isSelected()&&t.selectPrevious();if(tr(o)&&e&&!s){const e=t.getIndexWithinParent();Oi(t),yr(o,i,e,-1)}else Oi(t);n||Co(i)||i.canBeEmpty()||!i.isEmpty()||Sn(i,e),e&&o&&ii(i)&&i.isEmpty()&&i.selectEnd()}class Tn{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}),wi(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=Pi(t);if(null===e)break;t=e.__parent}return!1}isSelected(t){const e=t||_r();if(null==e)return!1;const n=e.getNodes().some((t=>t.__key===this.__key));if(Jn(this))return n;if(tr(e)&&"element"===e.anchor.type&&"element"===e.focus.type){if(e.isCollapsed())return!1;const t=this.getParent();if(ni(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:Pi(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(Co(n))return Zr(e)||e===this&&ni(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:Pi(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:Pi(t)}getNextSiblings(){const t=[];let e=this.getNextSibling();for(;null!==e;)t.push(e),e=e.getNextSibling();return t}getCommonAncestor(t){const e=Zr(this)?this:this.getParent(),n=Zr(t)?t:t.getParent(),r=e&&n?xs(e,n):null;return r?r.commonAncestor:null}is(t){return null!=t&&this.__key===t.__key}isBefore(e){const n=xs(this,e);return null!==n&&("descendant"===n.type||("branch"===n.type?-1===_s(n):("same"!==n.type&&"ancestor"!==n.type&&t(279),!1)))}isParentOf(t){const e=xs(this,t);return null!==e&&"ancestor"===e.type}getNodesBetween(e){const n=this.isBefore(e),r=[],i=new Set;let o=this;for(;null!==o;){const s=o.__key;if(i.has(s)||(i.add(s),r.push(o)),o===e)break;const l=Zr(o)?n?o.getFirstChild():o.getLastChild():null;if(null!==l){o=l;continue}const c=n?o.getNextSibling():o.getPreviousSibling();if(null!==c){o=c;continue}const a=o.getParentOrThrow();if(i.has(a.__key)||r.push(a),a===e)break;let u=null,f=a;do{if(null===f&&t(68),u=n?f.getNextSibling():f.getPreviousSibling(),f=f.getParent(),null===f)break;null!==u||i.has(f.__key)||r.push(f)}while(null===u);o=u}return n||r.reverse(),r}isDirty(){const t=Rr()._dirtyLeaves;return null!==t&&t.has(this.__key)}getLatest(){const e=Pi(this.__key);return null===e&&t(113),e}getWritable(){Lr();const t=Ir(),e=Rr(),n=t._nodeMap,r=this.__key,i=this.getLatest(),o=e._cloneNotNeeded,s=_r();if(null!==s&&s.setCachedNodes(null),o.has(r))return Mi(i),i;const l=zo(i);return o.add(r),Mi(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)&&ut(t).updateFromJSON(e),n}(this,t.$)}static transform(){return null}remove(t){Sn(this,!0,t)}replace(e,n){Lr();let r=_r();null!==r&&(r=r.clone()),vo(this,e);const i=this.getLatest(),o=this.__key,s=e.__key,l=e.getWritable(),c=this.getParentOrThrow().getWritable(),a=c.__size;Oi(l);const u=i.getPreviousSibling(),f=i.getNextSibling(),d=i.__prev,h=i.__next,g=i.__parent;if(Sn(i,!1,!0),null===u)c.__first=s;else{u.getWritable().__next=s}if(l.__prev=d,null===f)c.__last=s;else{f.getWritable().__prev=s}if(l.__next=h,l.__parent=g,c.__size=a,n&&(Zr(this)&&Zr(l)||t(139),this.getChildren().forEach((t=>{l.append(t)}))),tr(r)){$i(r);const t=r.anchor,e=r.focus;t.key===o&&Qn(t,l),e.key===o&&Qn(e,l)}return Di()===o&&Ai(s),l}insertAfter(t,e=!0){Lr(),vo(this,t);const n=this.getWritable(),r=t.getWritable(),i=r.getParent(),o=_r();let s=!1,l=!1;if(null!==i){const e=t.getIndexWithinParent();if(Oi(r),tr(o)){const t=i.__key,n=o.anchor,r=o.focus;s="element"===n.type&&n.key===t&&n.offset===e+1,l="element"===r.type&&r.key===t&&r.offset===e+1}}const c=this.getNextSibling(),a=this.getParentOrThrow().getWritable(),u=r.__key,f=n.__next;if(null===c)a.__last=u;else{c.getWritable().__prev=u}if(a.__size++,n.__next=u,r.__next=f,r.__prev=n.__key,r.__parent=n.__parent,e&&tr(o)){const t=this.getIndexWithinParent();yr(o,a,t+1);const e=a.__key;s&&o.anchor.set(e,t+2,"element"),l&&o.focus.set(e,t+2,"element")}return t}insertBefore(t,e=!0){Lr(),vo(this,t);const n=this.getWritable(),r=t.getWritable(),i=r.__key;Oi(r);const o=this.getPreviousSibling(),s=this.getParentOrThrow().getWritable(),l=n.__prev,c=this.getIndexWithinParent();if(null===o)s.__first=i;else{o.getWritable().__next=i}s.__size++,n.__prev=i,r.__prev=l,r.__next=n.__key,r.__parent=n.__parent;const a=_r();if(e&&tr(a)){yr(a,this.getParentOrThrow(),c)}return t}isParentRequired(){return!1}createParentElementNode(){return di()}selectStart(){return this.selectPrevious()}selectEnd(){return this.selectNext(0,0)}selectPrevious(t,e){Lr();const n=this.getPreviousSibling(),r=this.getParentOrThrow();if(null===n)return r.select(0,0);if(Zr(n))return n.select();if(!Jn(n)){const t=n.getIndexWithinParent()+1;return r.select(t,t)}return n.select(t,e)}selectNext(t,e){Lr();const n=this.getNextSibling(),r=this.getParentOrThrow();if(null===n)return r.select();if(Zr(n))return n.select(0,0);if(!Jn(n)){const t=n.getIndexWithinParent();return r.select(t,t)}return n.select(t,e)}markDirty(){this.getWritable()}reconcileObservedMutation(t,e){this.markDirty()}}class vn extends Tn{static getType(){return"linebreak"}static clone(t){return new vn(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&&Po(e)){const n=e.firstChild;if(n===t||n.nextSibling===t&&En(n)){const n=e.lastChild;if(n===t||n.previousSibling===t&&En(n))return!0}}return!1}(t)||function(t){const e=t.parentElement;if(null!==e&&Po(e)){const n=e.firstChild;if(n===t||n.nextSibling===t&&En(n))return!1;const r=e.lastChild;if(r===t||r.previousSibling===t&&En(r))return!0}return!1}(t)?null:{conversion:Nn,priority:0}}}static importJSON(t){return kn().updateFromJSON(t)}}function Nn(t){return{node:kn()}}function kn(){return To(new vn)}function bn(t){return t instanceof vn}function En(t){return Ni(t)&&/^( |\t|\r?\n)+$/.test(t.textContent||"")}function wn(t,e){return 16&e?"code":e&k?"mark":32&e?"sub":64&e?"sup":null}function On(t,e){return 1&e?"strong":2&e?"em":"span"}function Mn(t,e,n,r,i){const o=r.classList;let s=ro(i,"base");void 0!==s&&o.add(...s),s=ro(i,"underlineStrikethrough");let l=!1;const c=e&N&&e&v;void 0!==s&&(n&N&&n&v?(l=!0,c||o.add(...s)):c&&o.remove(...s));for(const t in W){const r=W[t];if(s=ro(i,t),void 0!==s)if(n&r){if(l&&("underline"===t||"strikethrough"===t)){e&r&&o.remove(...s);continue}e&r&&(!c||"underline"!==t)&&"strikethrough"!==t||o.add(...s)}else e&r&&o.remove(...s)}}function An(t,e,n){const r=e.firstChild,o=n.isComposing(),s=t+(o?P:"");if(null==r)e.textContent=s;else{const t=r.nodeValue;if(t!==s)if(o||i){const[e,n,i]=function(t,e){const n=t.length,r=e.length;let i=0,o=0;for(;i<n&&i<r&&t[i]===e[i];)i++;for(;o+i<n&&o+i<r&&t[n-o-1]===e[r-o-1];)o++;return[i,n-i-o,e.slice(i,r-o)]}(t,s);0!==n&&r.deleteData(e,n),r.insertData(e,i)}else r.nodeValue=s}}function Dn(t,e,n,r,i,o){An(i,t,e);const s=o.theme.text;void 0!==s&&Mn(0,0,r,t,s)}function Pn(t,e){const n=document.createElement(e);return n.appendChild(t),n}class Ln extends Tn{static getType(){return"text"}static clone(t){return new Ln(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 j[t.__mode]}getStyle(){return this.getLatest().__style}isToken(){return 1===this.getLatest().__mode}isComposing(){return this.__key===Di()}isSegmented(){return 2===this.getLatest().__mode}isDirectionless(){return!!(1&this.getLatest().__detail)}isUnmergeable(){return!!(2&this.getLatest().__detail)}hasFormat(t){const e=W[t];return!!(this.getFormat()&e)}isSimpleText(){return"text"===this.__type&&0===this.__mode}getTextContent(){return this.getLatest().__text}getFormatFlags(t,e){return Ei(this.getLatest().__format,t,e)}canHaveFormat(){return!0}isInline(){return!0}createDOM(t,e){const n=this.__format,r=wn(0,n),i=On(0,n),o=null===r?i:r,s=document.createElement(o);let l=s;this.hasFormat("code")&&s.setAttribute("spellcheck","false"),null!==r&&(l=document.createElement(i),s.appendChild(l));Dn(l,this,0,n,this.__text,t);const c=this.__style;return""!==c&&(s.style.cssText=c),s}updateDOM(e,n,r){const i=this.__text,o=e.__format,s=this.__format,l=wn(0,o),c=wn(0,s),a=On(0,o),u=On(0,s);if((null===l?a:l)!==(null===c?u:c))return!0;if(l===c&&a!==u){const e=n.firstChild;null==e&&t(48);const o=document.createElement(u);return Dn(o,this,0,s,i,r),n.replaceChild(o,e),!1}let f=n;null!==c&&null!==l&&(f=n.firstChild,null==f&&t(49)),An(i,f,this);const d=r.theme.text;void 0!==d&&o!==s&&Mn(0,o,s,f,d);const h=e.__style,g=this.__style;return h!==g&&(n.style.cssText=g),!1}static importDOM(){return{"#text":()=>({conversion:zn,priority:0}),b:()=>({conversion:In,priority:0}),code:()=>({conversion:Kn,priority:0}),em:()=>({conversion:Kn,priority:0}),i:()=>({conversion:Kn,priority:0}),mark:()=>({conversion:Kn,priority:0}),s:()=>({conversion:Kn,priority:0}),span:()=>({conversion:Fn,priority:0}),strong:()=>({conversion:Kn,priority:0}),sub:()=>({conversion:Kn,priority:0}),sup:()=>({conversion:Kn,priority:0}),u:()=>({conversion:Kn,priority:0})}}static importJSON(t){return Un().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 Oo(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=Pn(n,"b")),this.hasFormat("italic")&&(n=Pn(n,"i")),this.hasFormat("strikethrough")&&(n=Pn(n,"s")),this.hasFormat("underline")&&(n=Pn(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?W[t]:t,e}setDetail(t){const e=this.getWritable();return e.__detail="string"==typeof t?$[t]:t,e}setStyle(t){const e=this.getWritable();return e.__style=t,e}toggleFormat(t){const e=Ei(this.getFormat(),t,null);return this.setFormat(e)}toggleDirectionless(){const t=this.getWritable();return t.__detail^=1,t}toggleUnmergeable(){const t=this.getWritable();return t.__detail^=2,t}setMode(t){const e=J[t];if(this.__mode===e)return this;const n=this.getWritable();return n.__mode=e,n}setTextContent(t){if(this.__text===t)return this;const e=this.getWritable();return e.__text=t,e}select(t,e){Lr();let n=t,r=e;const i=_r(),o=this.getTextContent(),s=this.__key;if("string"==typeof o){const t=o.length;void 0===n&&(n=t),void 0===r&&(r=t)}else n=0,r=0;if(!tr(i))return dr(s,n,s,r,"text","text");{const t=Di();t!==i.anchor.key&&t!==i.focus.key||Ai(s),i.setTextNodeRange(this,n,this,r)}return i}selectStart(){return this.select(0,0)}selectEnd(){const t=this.getTextContentSize();return this.select(t,t)}spliceText(t,e,n,r){const i=this.getWritable(),o=i.__text,s=n.length;let l=t;l<0&&(l=s+l,l<0&&(l=0));const c=_r();if(r&&tr(c)){const e=t+s;c.setTextNodeRange(i,e,i,e)}const a=o.slice(0,l)+n+o.slice(l+e);return i.__text=a,i}canInsertTextBefore(){return!0}canInsertTextAfter(){return!0}splitText(...t){Lr();const e=this.getLatest(),n=e.getTextContent();if(""===n)return[];const r=e.__key,i=Di(),o=n.length;t.sort(((t,e)=>t-e)),t.push(o);const s=[],l=t.length;for(let e=0,r=0;e<o&&r<=l;r++){const i=t[r];i>e&&(s.push(n.slice(e,i)),e=i)}const c=s.length;if(1===c)return[e];const a=s[0],u=e.getParent();let f;const d=e.getFormat(),h=e.getStyle(),g=e.__detail;let p=!1,_=null,m=null;const y=_r();if(tr(y)){const[t,e]=y.isBackward()?[y.focus,y.anchor]:[y.anchor,y.focus];"text"===t.type&&t.key===r&&(_=t),"text"===e.type&&e.key===r&&(m=e)}e.isSegmented()?(f=Un(a),f.__format=d,f.__style=h,f.__detail=g,p=!0):(f=e.getWritable(),f.__text=a);const x=[f];for(let t=1;t<c;t++){const e=Un(s[t]);e.__format=d,e.__style=h,e.__detail=g;const n=e.__key;i===r&&Ai(n),x.push(e)}const C=_?_.offset:null,S=m?m.offset:null;let T=0;for(const t of x){if(!_&&!m)break;const e=T+t.getTextContentSize();if(null!==_&&null!==C&&C<=e&&C>=T&&(_.set(t.getKey(),C-T,"text"),C<e&&(_=null)),null!==m&&null!==S&&S<=e&&S>=T){m.set(t.getKey(),S-T,"text");break}T=e}if(null!==u){!function(t){const e=t.getPreviousSibling(),n=t.getNextSibling();null!==e&&Mi(e);null!==n&&Mi(n)}(this);const t=u.getWritable(),e=this.getIndexWithinParent();p?(t.splice(e,0,x),this.remove()):t.splice(e,1,x),tr(y)&&yr(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,o=this.__text,s=o.length;Di()===i&&Ai(r);const l=_r();if(tr(l)){const t=l.anchor,o=l.focus;null!==t&&t.key===i&&Sr(t,n,r,e,s),null!==o&&o.key===i&&Sr(o,n,r,e,s)}const c=e.__text,a=n?c+o:o+c;this.setTextContent(a);const u=this.getWritable();return e.remove(),u}isTextEntity(){return!1}}function Fn(t){return{forChild:jn(t.style),node:null}}function In(t){const e=t,n="normal"===e.style.fontWeight;return{forChild:jn(e.style,n?void 0:"bold"),node:null}}const Rn=new WeakMap;function Bn(t){if(!Oo(t))return!1;if("PRE"===t.nodeName)return!0;const e=t.style.whiteSpace;return"string"==typeof e&&e.startsWith("pre")}function zn(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=Rn.get(n))&&!Bn(n);)r.push(n),n=n.parentNode;const i=void 0===e?n:e;for(let t=0;t<r.length;t++)Rn.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(kn()):"\t"===n?e.push(Hn()):""!==n&&e.push(Un(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=Wn(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=Wn(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:Un(r)}}function Wn(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,Oo(n)){const t=n.style.display;if(""===t&&!Do(n)||""!==t&&!t.startsWith("inline"))return null}let r=n;for(;null!==(r=e?n.firstChild:n.lastChild);)n=r;if(Ni(n))return n;if("BR"===n.nodeName)return null}}const $n={code:"code",em:"italic",i:"italic",mark:"highlight",s:"strikethrough",strong:"bold",sub:"subscript",sup:"superscript",u:"underline"};function Kn(t){const e=$n[t.nodeName.toLowerCase()];return void 0===e?{node:null}:{forChild:jn(t.style,e),node:null}}function Un(t=""){return To(new Ln(t))}function Jn(t){return t instanceof Ln}function jn(t,e){const n=t.fontWeight,r=t.textDecoration.split(" "),i="700"===n||"bold"===n,o=r.includes("line-through"),s="italic"===t.fontStyle,l=r.includes("underline"),c=t.verticalAlign;return t=>Jn(t)?(i&&!t.hasFormat("bold")&&t.toggleFormat("bold"),o&&!t.hasFormat("strikethrough")&&t.toggleFormat("strikethrough"),s&&!t.hasFormat("italic")&&t.toggleFormat("italic"),l&&!t.hasFormat("underline")&&t.toggleFormat("underline"),"sub"!==c||t.hasFormat("subscript")||t.toggleFormat("subscript"),"super"!==c||t.hasFormat("superscript")||t.toggleFormat("superscript"),e&&!t.hasFormat(e)&&t.toggleFormat(e),t):t}class Vn extends Ln{static getType(){return"tab"}static clone(t){return new Vn(t.__key)}constructor(t){super("\t",t),this.__detail=2}static importDOM(){return null}createDOM(t){const e=super.createDOM(t),n=ro(t.theme,"tab");if(void 0!==n){e.classList.add(...n)}return e}static importJSON(t){return Hn().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 Hn(){return To(new Vn)}function Yn(t){return t instanceof Vn}class qn{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 ps(Os(Cs(this,"next")),Os(Cs(t,"next")))<0}getNode(){const e=Pi(this.key);return null===e&&t(20),e}set(t,e,n,r){const i=this._selection,o=this.key;r&&this.key===t&&this.offset===e&&this.type===n||(this.key=t,this.offset=e,this.type=n,Pr()||(Di()===o&&Ai(t),null!==i&&(i.setCachedNodes(null),i.dirty=!0)))}}function Gn(t,e,n){return new qn(t,e,n)}function Xn(t,e){let n=e.__key,r=t.offset,i="element";if(Jn(e)){i="text";const t=e.getTextContentSize();r>t&&(r=t)}else if(!Zr(e)){const t=e.getNextSibling();if(Jn(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 Qn(t,e){if(Zr(e)){const n=e.getLastDescendant();Zr(n)||Jn(n)?Xn(t,n):Xn(t,e)}else Xn(t,e)}class Zn{constructor(t){this._cachedNodes=null,this._nodes=t,this.dirty=!1}getCachedNodes(){return this._cachedNodes}setCachedNodes(t){this._cachedNodes=t}is(t){if(!nr(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 Zn(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(Jn(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=Pi(t);null!==e&&n.push(e)}return Pr()||(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((_r()||mr())===this&&t[0]){const e=ns(t[0],"next");Ts(hs(e,e))}for(const e of t)e.remove()}}function tr(t){return t instanceof er}class er{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!!tr(t)&&(this.anchor.is(t.anchor)&&this.focus.is(t.focus)&&this.format===t.format&&this.style===t.style)}isCollapsed(){return this.anchor.is(this.focus)}getNodes(){const t=this._cachedNodes;if(null!==t)return t;const e=function(t){const e=[],[n,r]=t.getTextSlices();n&&e.push(n.caret.origin);const i=new Set,o=new Set;for(const n of t)if(Qo(n)){const{origin:t}=n;0===e.length?i.add(t):(o.add(t),e.push(t))}else{const{origin:t}=n;Zr(t)&&o.has(t)||e.push(t)}r&&e.push(r.caret.origin);if(Xo(t.focus)&&Zr(t.focus.origin)&&null===t.focus.getNodeAtCaret())for(let n=ss(t.focus.origin,"previous");Qo(n)&&i.has(n.origin)&&!n.origin.isEmpty()&&n.origin.is(e[e.length-1]);n=cs(n))i.delete(n.origin),e.pop();for(;e.length>1;){const t=e[e.length-1];if(!Zr(t)||o.has(t)||t.isEmpty()||i.has(t))break;e.pop()}if(0===e.length&&t.isCollapsed()){const n=Os(t.anchor),r=Os(t.anchor.getFlipped()),i=t=>Go(t)?t.origin:t.getNodeAtCaret(),o=i(n)||i(r)||(t.anchor.getNodeAtCaret()?n.origin:r.origin);e.push(o)}return e}(Ds(Ns(this),"next"));return Pr()||(this._cachedNodes=e),e}setTextNodeRange(t,e,n,r){this.anchor.set(t.__key,e,"text"),this.focus.set(n.__key,r,"text")}getTextContent(){const t=this.getNodes();if(0===t.length)return"";const e=t[0],n=t[t.length-1],r=this.anchor,i=this.focus,o=r.isBefore(i),[s,l]=ir(this);let c="",a=!0;for(let u=0;u<t.length;u++){const f=t[u];if(Zr(f)&&!f.isInline())a||(c+="\n"),a=!f.isEmpty();else if(a=!1,Jn(f)){let t=f.getTextContent();f===e?f===n?"element"===r.type&&"element"===i.type&&i.offset!==r.offset||(t=s<l?t.slice(s,l):t.slice(l,s)):t=o?t.slice(s):t.slice(l):f===n&&(t=o?t.slice(0,l):t.slice(0,s)),c+=t}else!ni(f)&&!bn(f)||f===n&&this.isCollapsed()||(c+=f.getTextContent())}return c}applyDOMRange(t){const e=Rr(),n=e.getEditorState()._selection,r=fr(t.startContainer,t.startOffset,t.endContainer,t.endOffset,e,n);if(null===r)return;const[i,o]=r;this.anchor.set(i.key,i.offset,i.type,!0),this.focus.set(o.key,o.offset,o.type,!0),gt(this)}clone(){const t=this.anchor,e=this.focus;return new er(Gn(t.key,t.offset,t.type),Gn(e.key,e.offset,e.type),this.format,this.style)}toggleFormat(t){this.format=Ei(this.format,t,null),this.dirty=!0}setStyle(t){this.style=t,this.dirty=!0}hasFormat(t){const e=W[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(kn()):"\t"===r?n.push(Hn()):n.push(Un(r))}this.insertNodes(n)}insertText(e){const n=this.anchor,r=this.focus,i=this.format,o=this.style;let s=n,l=r;!this.isCollapsed()&&r.isBefore(n)&&(s=r,l=n),"element"===s.type&&function(t,e,n,r){const i=t.getNode(),o=i.getChildAtIndex(t.offset),s=Un(),l=ii(i)?di().append(s):s;s.setFormat(n),s.setStyle(r),null===o?i.append(l):o.insertBefore(l),t.is(e)&&e.set(s.__key,0,"text"),t.set(s.__key,0,"text")}(s,l,i,o),"element"===l.type&&Ss(l,Os(Cs(l,"next")));const c=s.offset;let a=l.offset;const u=this.getNodes(),f=u.length;let d=u[0];Jn(d)||t(26);const h=d.getTextContent().length,g=d.getParentOrThrow();let p=u[f-1];if(1===f&&"element"===l.type&&(a=h,l.set(s.key,a,"text")),this.isCollapsed()&&c===h&&(d.isSegmented()||d.isToken()||!d.canInsertTextAfter()||!g.canInsertTextAfter()&&null===d.getNextSibling())){let t=d.getNextSibling();if(Jn(t)&&t.canInsertTextBefore()&&!vi(t)||(t=Un(),t.setFormat(i),t.setStyle(o),g.canInsertTextAfter()?d.insertAfter(t):g.insertAfter(t)),t.select(0,0),d=t,""!==e)return void this.insertText(e)}else if(this.isCollapsed()&&0===c&&(d.isSegmented()||