UNPKG

lexical

Version:

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

10 lines (9 loc) • 176 kB
/** * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * */ function t(t,...e){const n=new URL("https://lexical.dev/docs/error"),o=new URLSearchParams;o.append("code",t);for(const t of e)o.append("v",t);throw n.search=o.toString(),Error(`Minified Lexical error #${t}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}function e(t,...e){const n=new URL("https://lexical.dev/docs/error"),o=new URLSearchParams;o.append("code",t);for(const t of e)o.append("v",t);n.search=o.toString(),console.warn(`Minified Lexical warning #${t}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}const n="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement,o=n&&"documentMode"in document?document.documentMode:null,r=n&&/Mac|iPod|iPhone|iPad/.test(navigator.platform),i=n&&/^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent),s=!(!n||!("InputEvent"in window)||o)&&"getTargetRanges"in new window.InputEvent("input"),l=n&&/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream,c=n&&/Android/.test(navigator.userAgent),a=n&&/Version\/[\d.]+.*Safari/.test(navigator.userAgent)&&!c,u=n&&/^(?=.*Chrome).*/i.test(navigator.userAgent),f=n&&c&&u,d=n&&/AppleWebKit\/[\d.]+/.test(navigator.userAgent)&&r&&!u,h=0,g=1,_=2,p=1,y=2,m=4,x=8,C=16,S=32,v=64,T=128,k=2047,b=1,N=2,w=3,E=4,O=5,M=6,A=a||l||d?"\xa0":"\u200b",D="\n\n",P=i?"\xa0":A,F="\u0591-\u07ff\ufb1d-\ufdfd\ufe70-\ufefc",I="A-Za-z\xc0-\xd6\xd8-\xf6\xf8-\u02b8\u0300-\u0590\u0800-\u1fff\u200e\u2c00-\ufb1c\ufe00-\ufe6f\ufefd-\uffff",L=new RegExp("^[^"+I+"]*["+F+"]"),K=new RegExp("^[^"+F+"]*["+I+"]"),z={bold:1,capitalize:1024,code:16,highlight:T,italic:2,lowercase:256,strikethrough:4,subscript:32,superscript:64,underline:8,uppercase:512},B={directionless:1,unmergeable:2},R={center:2,end:6,justify:4,left:1,right:3,start:5},W={[N]:"center",[M]:"end",[E]:"justify",[b]:"left",[w]:"right",[O]:"start"},U={normal:0,segmented:2,token:1},$={[h]:"normal",[_]:"segmented",[g]:"token"},H="$",J="$config";function j(){return Cc()._blockCursorElement}function V(t){return null!==t&&1===t.nodeType&&t.hasAttribute("data-lexical-slot")}class q{element;before;after;constructor(t,e,n){this.element=t,this.before=e||null,this.after=n||null}withBefore(t){return new q(this.element,t,this.after)}withAfter(t){return new q(this.element,this.before,t)}withElement(t){return this.element===t?this:new q(t,this.before,this.after)}insertChild(e){const n=this.getInsertionAnchor();return null!==n&&n.parentElement!==this.element&&t(357),this.element.insertBefore(e,n),this}removeChild(e){return e.parentElement!==this.element&&t(358),this.element.removeChild(e),this}replaceChild(e,n){return n.parentElement!==this.element&&t(359),this.element.replaceChild(e,n),this}getFirstChild(){const t=this.getFirstChildAnchor(),e=t?t.nextSibling:this.element.firstChild;return e===this.getInsertionAnchor()?null:e}getFirstChildAnchor(){return this.after}resolveLeafPosition(t,e,n){if(this.element===t)return e===t&&0===n?"before":"after";const o=Y(t,this.element);if(null===o)return"after";const r=Array.prototype.indexOf.call(t.childNodes,o);if(r<0)return"after";if(e===t)return n<=r?"before":"after";const i=Y(t,e);if(null===i)return"after";const s=Array.prototype.indexOf.call(t.childNodes,i);return s>=0&&s<=r?"before":"after"}getInsertionAnchor(){return this.before}}function Y(t,e){let n=e;for(;null!==n&&n.parentNode!==t;)n=n.parentNode;return n}class G extends q{withBefore(t){return new G(this.element,t,this.after)}withAfter(t){return new G(this.element,this.before,t)}withElement(t){return this.element===t?this:new G(t,this.before,this.after)}getInsertionAnchor(){return super.getInsertionAnchor()||this.getManagedLineBreak()}getFirstChildAnchor(){let t=super.getFirstChildAnchor(),e=t?t.nextSibling:this.element.firstChild;for(;V(e);)t=e,e=e.nextSibling;const n=t?t.nextSibling:this.element.firstChild;return null!==n&&n===j()?n:t}getManagedLineBreak(){return this.element.__lexicalLineBreak||null}setManagedLineBreak(t){if(this.element.__lexicalLastChildKind=t,null===t)this.removeManagedLineBreak();else{const e="decorator"===t&&(d||l||a);this.insertManagedLineBreak(e)}}removeManagedLineBreak(){const t=this.getManagedLineBreak();if(t){const e=this.element,n="IMG"===t.nodeName?t.nextSibling:null;n&&e.removeChild(n),e.removeChild(t),e.__lexicalLineBreak=void 0}}insertManagedLineBreak(t){const e=this.getManagedLineBreak();if(e){if(t===("IMG"===e.nodeName))return;this.removeManagedLineBreak()}const n=this.element,o=this.before,r=Xl().createElement("br");if(r.setAttribute("data-lexical-managed-linebreak","true"),n.insertBefore(r,o),t){const t=Xl().createElement("img");t.setAttribute("data-lexical-managed-linebreak","true"),t.style.setProperty("display","inline","important"),t.style.setProperty("border","0px","important"),t.style.setProperty("margin","0px","important"),t.alt="",n.insertBefore(t,r),n.__lexicalLineBreak=t}else n.__lexicalLineBreak=r}getFirstChildOffset(){const t=this.getFirstChild(),e=this.getInsertionAnchor();let n=0;for(let o=this.element.firstChild;null!==o&&o!==t&&o!==e;o=o.nextSibling)n++;return n}resolveChildIndex(t,e,n,o){if(n===this.element){const e=this.getFirstChildOffset(),n=j(),r=this.element.childNodes,i=Math.min(o,r.length);let s=0;for(let t=e;t<i;t++)r[t]!==n&&s++;return[t,Math.min(s,t.getChildrenSize())]}const r=X(e,n);r.push(o);const i=X(e,this.element);let s=t.getIndexWithinParent();for(let t=0;t<i.length;t++){const e=r[t],n=i[t];if(void 0===e||e<n)break;if(e>n){s+=1;break}}return[t.getParentOrThrow(),s]}}function X(e,n){const o=[];let r=n;for(;r!==e&&null!==r;r=r.parentNode){let t=0;for(let e=r.previousSibling;null!==e;e=e.previousSibling)t++;o.push(t)}return r!==e&&t(225),o.reverse()}let Q;try{Q="0.47.0+prod.esm"}catch(t){}const Z=Q??'"<unknown>+source"';class tt{_front=new Set;_back=new Set;_cache;get size(){return this._front.size+this._back.size}addBack(t){return delete this._cache,this._front.has(t)||this._back.add(t),this}addFront(t){return delete this._cache,this._back.has(t)||this._front.add(t),this}delete(t){return delete this._cache,this._front.delete(t)||this._back.delete(t)}toArray(){const t=Array.from(this._front).reverse();for(const e of this._back)t.push(e);return t}toReadonlyArray(){return this._cache=this._cache||this.toArray(),this._cache}[Symbol.iterator](){return this.toReadonlyArray()[Symbol.iterator]()}}const et=null;function nt(t,e=1e3){return t instanceof ot?t.clone():t.size<e?new Map(t):(new ot).init(new Map(t),void 0,t.size)}class ot{_mutable=!1;_old=void 0;_nursery=void 0;_size=0;clone(){return this._mutable=!1,(new ot).init(this._old,this._nursery,this._size)}init(t,e,n){return this._old=t,this._nursery=e,this._size=n,this}get size(){return this._size}has(t){return void 0!==this.get(t)}getWithTombstone(t){const e=this._nursery&&this._nursery.get(t);return void 0!==e?e:this._old&&this._old.get(t)}get(t){const e=this.getWithTombstone(t);return e===et?void 0:e}shouldCompact(){return void 0!==this._nursery&&2*this._nursery.size>this._size}getNursery(){return this._mutable&&this._nursery||(this.compact(),this._nursery=new Map(this._nursery),this._mutable=!0),this._nursery}compact(t=!1){if(this._nursery&&this._nursery.size>0&&(t||this.shouldCompact())){const t=new Map(this._old);for(const[e,n]of this._nursery)n!==et?t.set(e,n):t.delete(e);this._old=t,this._nursery=void 0}return this._mutable=!1,this}set(t,e){const n=this.getWithTombstone(t);if(n===e)return this;const o=this.getNursery();return n!==et&&void 0!==n||(this._size++,n===et&&o.delete(t)),o.set(t,e),this}delete(t){const e=this.has(t);return e&&(this.getNursery().set(t,et),this._size--),e}getOrInsert(t,e){const n=this.get(t);return void 0!==n?n:(this.set(t,e),e)}getOrInsertComputed(t,e){const n=this.get(t);if(void 0!==n)return n;const o=e(t);return this.set(t,o),o}clear(){this._mutable=!1,this._old=void 0,this._nursery=void 0,this._size=0}*keys(){for(const t of this.entries())yield t[0]}*values(){for(const t of this.entries())yield t[1]}*entries(){const t=this._nursery,e=this._old;if(e)for(const n of e){const e=n[0],o=t?t.get(e):void 0;o!==et&&(void 0!==o&&(n[1]=o),yield n)}if(t)for(const n of t)n[1]===et||e&&e.has(n[0])||(yield n)}forEach(t,e){void 0!==e&&(t=t.bind(e));for(const[e,n]of this.entries())t(n,e,this)}get[Symbol.toStringTag](){return"GenMap"}[Symbol.iterator](){return this.entries()}}function rt(t,e,n,o,r,i){if(Pi(t)){let s=t.getFirstChild();for(;null!==s;){const t=s.__key;s.__parent===e&&((Pi(s)||Yc(s)&&null!==s.__slots)&&rt(s,t,n,o,r,i),n.has(t)||i.delete(t),r.push(t)),s=s.getNextSibling()}}for(const s of Yc(t)&&null!==t.__slots?t.__slots.values():[]){const t=o.get(s);void 0!==t&&Gc(t)&&t.__slotHost===e&&((Pi(t)||Yc(t)&&null!==t.__slots)&&rt(t,s,n,o,r,i),n.has(s)||i.delete(s),r.push(s))}}let it=!1,st=0;function lt(t){st=t.timeStamp}function ct(t,e,n){const o="BR"===t.nodeName,r=e.__lexicalLineBreak;return r&&(t===r||o&&t.previousSibling===r)||o&&void 0!==Gs(t,n)}function at(t,e,n){const o=Hl(Pl(n)),r=o&&tc(o,n._rootElement);let i=null,s=null;null!==r&&r.anchorNode===t&&(i=r.anchorOffset,s=r.focusOffset);const l=t.nodeValue;null!==l&&al(e,l,i,s,!1)}function ut(t,e,n){if(cr(t)){const e=t.anchor.getNode();if(e.is(n)&&t.format!==e.getFormat())return!1}return Ls(e)&&n.isAttached()}function ft(t,e,n){for(let o=t;o&&!Lc(o);o=Nl(o)){const t=Gs(o,e);if(void 0!==t){const e=Vs(t,n);if(e)return Li(e)||!dc(o)?void 0:[o,e]}}}function dt(t,e,n){it=!0;const o=performance.now()-st>100;try{Mi(t,()=>{const r=Lr()||function(t){return t.read("latest",()=>{const t=Lr();return null!==t?t.clone():null})}(t),s=new Map,l=t._editorState,c=t._blockCursorElement;let a=!1,u="";for(let n=0;n<e.length;n++){const f=e[n],d=f.type,h=f.target,g=ft(h,t,l);if(!g)continue;const[_,p]=g;if("characterData"===d)o&&Xo(p)&&Ls(h)&&ut(r,h,p)&&at(h,p,t);else if("childList"===d){a=!0;const e=f.addedNodes;for(let n=0;n<e.length;n++){const o=e[n],r=qs(o),s=o.parentNode;if(!(null==s||o===c||null!==r||ct(o,s,t)||t._slotsUsed&&dc(o)&&o.hasAttribute("data-lexical-slot")||Lc(o))){if(i){const t=(dc(o)?o.innerText:null)||o.nodeValue;t&&(u+=t)}s.removeChild(o)}}const n=f.removedNodes,o=n.length;if(o>0){let e=0;for(let r=0;r<o;r++){const o=n[r];(ct(o,h,t)||c===o)&&(h.appendChild(o),e++)}o!==e&&s.set(_,p)}}}if(s.size>0)for(const[e,n]of s)n.reconcileObservedMutation(e,t);const f=n.takeRecords();if(f.length>0){for(let e=0;e<f.length;e++){const n=f[e],o=n.addedNodes,r=n.target;for(let e=0;e<o.length;e++){const n=o[e],i=n.parentNode;null==i||"BR"!==n.nodeName||ct(n,r,t)||i.removeChild(n)}}n.takeRecords()}null!==r&&(a&&el(r),i&&Tl(t)&&r.insertRawText(u))})}finally{it=!1}}function ht(t){const e=t._observer;if(null!==e){dt(t,e.takeRecords(),e)}}function gt(t){!function(t){0===st&&Pl(t).addEventListener("textInput",lt,!0)}(t),t._observer=new MutationObserver((e,n)=>{dt(t,e,n)})}const _t="direct",pt="latest";class yt{key;parse;unparse;isEqual;defaultValue;resetOnCopyNode;constructor(t,e){this.key=t,this.parse=e.parse.bind(e),this.unparse=(e.unparse||Et).bind(e),this.isEqual=(e.isEqual||Object.is).bind(e),this.defaultValue=this.parse(void 0),this.resetOnCopyNode=e.resetOnCopyNode||!1}}function mt(t,e){return new yt(t,e)}function xt(t,e,n=pt){const o=(n===pt?t.getLatest():t).__state;return o?o.getValue(e):e.defaultValue}function Ct(t,e,n){const o=xt(t,n,_t),r=xt(e,n,_t);return n.isEqual(o,r)?null:[o,r]}function St(t,e,n){let o;if(ui(),"function"==typeof n){const r=t.getLatest(),i=xt(r,e);if(o=n(i),e.isEqual(i,o))return r}else o=n;const r=t.getWritable();return bt(r).updateFromKnown(e,o),r}function vt(t){const e=new Map,n=new Set;for(const{ownNodeConfig:o}of Uc("function"==typeof t?t:t.replace))if(o&&o.stateConfigs)for(const t of o.stateConfigs){let o;"stateConfig"in t?(o=t.stateConfig,t.flat&&n.add(o.key)):o=t,e.set(o.key,o)}return{flatKeys:n,sharedConfigMap:e}}const Tt=new Set(["__proto__","constructor","prototype"]);class kt{node;knownState;unknownState;sharedNodeState;size;constructor(t,e,n=void 0,o=new Map,r=void 0){this.node=t,this.sharedNodeState=e,this.unknownState=n,this.knownState=o;const{sharedConfigMap:i}=this.sharedNodeState,s=void 0!==r?r:function(t,e,n){let o=n.size;if(e)for(const r in e){const e=t.get(r);e&&n.has(e)||o++}return o}(i,n,o);this.size=s}getValue(t){const e=this.knownState.get(t);if(void 0!==e)return e;this.sharedNodeState.sharedConfigMap.set(t.key,t);let n=t.defaultValue;if(this.unknownState&&t.key in this.unknownState){const e=this.unknownState[t.key];void 0!==e&&(n=t.parse(e)),this.updateFromKnown(t,n)}return n}getInternalState(){return[this.unknownState,this.knownState]}toJSON(){const t={...this.unknownState},e={};for(const[e,n]of this.knownState)e.isEqual(n,e.defaultValue)?delete t[e.key]:t[e.key]=e.unparse(n);for(const n of this.sharedNodeState.flatKeys)n in t&&(e[n]=t[n],delete t[n]);return wt(t)&&(e.$=t),e}getWritable(t){if(this.node===t)return this;const{sharedNodeState:e,unknownState:n}=this,o=new Map(this.knownState);return new kt(t,e,function(t,e,n){let o;if(n)for(const[r,i]of Object.entries(n)){if(Tt.has(r))continue;const n=t.get(r);n?e.has(n)||e.set(n,n.parse(i)):(o=o||{},o[r]=i)}return o}(e.sharedConfigMap,o,n),o,this.size)}resetOnCopyNode(){for(const t of this.knownState.keys())t.resetOnCopyNode&&this.knownState.set(t,t.defaultValue);return this}updateFromKnown(t,e){const n=t.key;this.sharedNodeState.sharedConfigMap.set(n,t);const{knownState:o,unknownState:r}=this;o.has(t)||r&&n in r||(r&&(delete r[n],this.unknownState=wt(r)),this.size++),o.set(t,e)}updateFromUnknown(t,e){if(Tt.has(t))return;const n=this.sharedNodeState.sharedConfigMap.get(t);n?this.updateFromKnown(n,n.parse(e)):(this.unknownState=this.unknownState||{},t in this.unknownState||this.size++,this.unknownState[t]=e)}updateFromJSON(t){const{knownState:e}=this;for(const t of e.keys())e.set(t,t.defaultValue);if(this.size=e.size,this.unknownState=void 0,t)for(const[e,n]of Object.entries(t))this.updateFromUnknown(e,n)}}function bt(t){const e=t.getWritable(),n=e.__state?e.__state.getWritable(e):new kt(e,Nt(e));return e.__state=n,n}function Nt(t){return t.__state?t.__state.sharedNodeState:ks(Cc(),t.getType()).sharedNodeState}function wt(t){if(t)for(const e in t)return t}function Et(t){return t}function Ot(t,e,n){for(const[o,r]of e.knownState){if(t.has(o.key))continue;t.add(o.key);const e=n?n.getValue(o):o.defaultValue;if(e!==r&&!o.isEqual(e,r))return!0}return!1}function Mt(t,e,n){const{unknownState:o}=e,r=n?n.unknownState:void 0;if(o)for(const[e,n]of Object.entries(o)){if(t.has(e))continue;t.add(e);if(n!==(r?r[e]:void 0))return!0}return!1}function At(t,e){const n=t.__state;return n&&n.node===t?n.getWritable(e):n}function Dt(t,e){const n=t.__mode,o=t.__format,r=t.__style,i=e.__mode,s=e.__format,l=e.__style,c=t.__state,a=e.__state;return(null===n||n===i)&&(null===o||o===s)&&(null===r||r===l)&&(null===t.__state||c===a||function(t,e){if(t===e)return!0;const n=new Set;return!(t&&Ot(n,t,e)||e&&Ot(n,e,t)||t&&Mt(n,t,e)||e&&Mt(n,e,t))}(c,a))}function Pt(t,e){const n=t.mergeWithSibling(e),o=gi()._normalizedNodes;return o.add(t.__key),o.add(e.__key),n}function Ft(t){let e,n,o=t;if(""!==o.__text||!o.isSimpleText()||o.isUnmergeable()){for(;null!==(e=o.getPreviousSibling())&&Xo(e)&&e.isSimpleText()&&!e.isUnmergeable();){if(""!==e.__text){if(Dt(e,o)){o=Pt(e,o);break}break}e.remove()}for(;null!==(n=o.getNextSibling())&&Xo(n)&&n.isSimpleText()&&!n.isUnmergeable();){if(""!==n.__text){if(Dt(o,n)){o=Pt(o,n);break}break}n.remove()}}else o.remove()}function It(t){return Lt(t.anchor),Lt(t.focus),t}function Lt(t){for(;"element"===t.type;){const e=t.getNode(),n=t.offset;let o,r;if(n===e.getChildrenSize()?(o=e.getChildAtIndex(n-1),r=!0):(o=e.getChildAtIndex(n),r=!1),Xo(o)){t.set(o.__key,r?o.getTextContentSize():0,"text",!0);break}if(!Pi(o))break;t.set(o.__key,r?o.getChildrenSize():0,"element",!0)}}const Kt=Symbol.for("@lexical/CachedTextSize");function zt(e,n){return ee.read(()=>{let o=0,r=e;for(let e=0;e<n&&null!==r;e++){const i=te.get(r);if(void 0===i&&t(345,r),Pi(i)){const s=ne.get(r);if(void 0!==s&&Pi(s)&&s.__parent!==i.__parent)o+=i.getTextContentSize();else{const e=oe.get(r),n=e&&e.__lexicalTextContent;"string"!=typeof n&&t(346,i.getType()),o+=n.length}e<n-1&&!i.isInline()&&(o+=2)}else{const e=i[Kt];void 0===e&&t(347,i.getType(),r),o+=e}r=i.__next}return o},{editor:Ut})}function Bt(t){Pi(t)||void 0===t[Kt]&&(t[Kt]=Xo(t)?t.__text.length:t.getTextContentSize())}const Rt=4;let Wt,Ut,$t,Ht="",Jt=null,jt=null,Vt=null;function qt(){return{firstTextKey:Vt,format:Jt,style:jt}}function Yt(t){null!==t.firstTextKey&&(Jt=t.format,jt=t.style,Vt=t.firstTextKey)}function Gt(e){if(null!==Vt)return;const n=e.__lexicalFirstTextKey;if(void 0===n&&t(348),null===n)return;const o=ne.get(n);Xo(o)&&(Jt=o.getFormat(),jt=o.getStyle(),Vt=n)}let Xt,Qt,Zt,te,ee,ne,oe,re,ie,se,le=!1,ce=!1;function ae(t,e){const n=te.get(t),o=ne.has(t);if(null!==e){const n=Pe(t);n.parentNode===e&&e.removeChild(n)}if(!o){if(Ut._keyToDOMMap.delete(t),Pi(n)){const t=jc(n,te);ue(t,0,t.length-1,null)}if(void 0!==n){for(const t of xe(n).values()){const e=Se(t);ae(t,null),null!==e&&e.remove()}xl(ie,$t,Xt,n,"destroyed")}}}function ue(t,e,n,o){for(let r=e;r<=n;++r){const e=t[r];void 0!==e&&ae(e,o)}}function fe(t,e){t.setProperty("text-align",e)}const de="40px";function he(t,e){const n=Wt.theme.indent;if("string"==typeof n){const o=t.classList.contains(n);e>0&&!o?t.classList.add(n):e<1&&o&&t.classList.remove(n)}t.style.setProperty("padding-inline-start",0===e?"":`calc(${e} * var(--lexical-indent-base-value, ${de}))`)}function ge(t,e){const n=t.style;0===e?fe(n,""):1===e?fe(n,"left"):2===e?fe(n,"center"):3===e?fe(n,"right"):4===e?fe(n,"justify"):5===e?fe(n,"start"):6===e&&fe(n,"end")}function _e(t,e){const n=function(t){const e=t.__dir;if(null!==e)return e;if(zi(t))return null;const n=t.getParent();return null===n||Kl(n)&&null===n.__dir?"auto":null}(e);null!==n?t.dir=n:t.removeAttribute("dir")}function pe(t){const e=Xl().createElement("div");return e.setAttribute("data-lexical-slot",t),e.style.display="none",e}function ye(t,e,n){e||"false"===t.contentEditable?Kc(n,Ut):n.removeAttribute("contenteditable")}function me(t,e,n){const o=Ht,r=qt();Ht="";let i="";const s=Li(t);for(const[o,r]of n){const n=pe(o);ye(e,s,n),e.appendChild(n),Ht="";const l=qt();Te(r,vc(t,n,Ut)),Yt(l),Ce(t,o,e,n),i+=Ht}return Yt(r),Ht=o,i}function xe(t){return Yc(t)&&null!==t.__slots?t.__slots:qc}function Ce(t,e,n,o){const r=se.$getSlotTargetElement(t,e,n,Ut);null!==r&&(o.parentElement!==r&&r.appendChild(o),o.style.display="")}function Se(t){const e=oe.get(t);return void 0!==e?e.parentElement:null}function ve(t,e,n){const o=xe(t),r=xe(e);for(const[t,e]of o)if(!r.has(t)){const t=Se(e);ae(e,null),null!==t&&t.remove()}const i=Ht,s=qt();let l="",c=null;const a=Li(e);for(const[t,i]of r){const r=o.get(t);let s=void 0!==r?Se(r):null;Ht="";const u=qt();if(null===s){s=pe(t);let o=null;for(const t of n.children)if(!t.hasAttribute("data-lexical-slot")){o=t;break}n.insertBefore(s,o),Te(i,vc(e,s,Ut))}else r===i?Ee(i,s):(void 0!==r&&ae(r,s),Te(i,vc(e,s,Ut)));if(Yt(u),ye(n,a,s),Ce(e,t,n,s),l+=Ht,s.parentElement===n){const t=null===c?n.firstChild:c.nextSibling;t!==s&&n.insertBefore(s,t),c=s}}return Yt(s),Ht=i,l}function Te(e,n){const o=ne.get(e);if(void 0===o&&t(60),null!==n){const t=te.get(e);if(void 0!==t){const r=oe.get(e);if(void 0!==r){const i=Gc(t)?t.__slotHost:null,s=Gc(o)?o.__slotHost:null,l=t.__parent!==o.__parent||i!==s,c=null!==s&&r.parentElement!==n.element;if(l||c)return n.insertChild(r),Ee(e,n.element)}}}const r=se.$createDOM(o,Ut);if(function(t,e,n){const o=n._keyToDOMMap;Ys(e,n,t),o.set(t,e)}(e,r,Ut),Xo(o)?r.setAttribute("data-lexical-text","true"):Li(o)&&(r.setAttribute("data-lexical-decorator","true"),Ic(r,{captureSelection:!0})),Pi(o)){const t=o.__indent,e=o.__size;_e(r,o),0!==t&&he(r,t);const n=xe(o),i=n.size>0?me(o,r,n):"";if(0===e)r.__lexicalTextContent=i,r.__lexicalFirstTextKey=null,Ht+=i,n.size>0&&(r.__lexicalSlotTextLength=i.length);else{const t=Ht,s=e-1;if(ke(jc(o,ne),o,0,s,vc(o,r,Ut)),""!==i){const e=r.__lexicalTextContent||"";r.__lexicalTextContent=i+e,Ht=t+i+e}n.size>0&&(r.__lexicalSlotTextLength=i.length)}const s=o.__format;0!==s&&ge(r,s),o.isInline()||be(null,o,r)}else{const t=o.getTextContent();if(Li(o)){const t=o.decorate(Ut,Wt);null!==t&&Oe(e,t),r.contentEditable="false";const n=xe(o);n.size>0&&me(o,r,n)}Ht+=t}return null!==n&&n.insertChild(r),se.$decorateDOM(o,null,r,Ut),Bt(o),xl(ie,$t,Xt,o,"created"),r}function ke(e,n,o,r,i){const s=Ht,l=qt();Ht="",Jt=null,jt=null,Vt=null;let c=o;for(;c<=r;++c){const t=qt();Te(e[c],i);const n=ne.get(e[c]);null!==n&&Xo(n)?null===Jt&&(Jt=n.getFormat(),jt=n.getStyle(),Vt=n.__key):Pi(n)&&c<r&&!n.isInline()&&(Ht+=D),Yt(t)}const a=Ut._keyToDOMMap.get(n.__key);void 0===a&&t(349,n.__key),a.__lexicalTextContent=Ht,a.__lexicalFirstTextKey=Vt,Ht=s+Ht,Yt(l)}function be(t,e,n){const o=vc(e,n,Ut),r=o.element.__lexicalLastChildKind??null,i=function(t,e){if(t){const n=t.__last;if(n){const t=e.get(n);if(t)return qi(t)?"line-break":Li(t)&&t.isInline()?"decorator":null}return xe(t).size>0?null:"empty"}return null}(e,ne);r!==i&&o.setManagedLineBreak(i)}function Ne(e,n,o){var r;Jt=null,jt=null,Vt=null,function(e,n,o){const r=Ht,i=e.__size,s=n.__size;Ht="";const l=o.element,c=Ut._keyToDOMMap.get(n.__key);void 0===c&&t(351,n.__key);const a=s-i;if(!le&&Math.abs(a)<=1&&i>=Rt&&e.__first===n.__first&&(0!==a||!Ut._cloneNotNeeded.has(e.__key))){const i=c.__lexicalTextContent,u=re.get(e.__key);if(!le&&"string"==typeof i&&void 0!==u){const s=function(t,e){const n=e.size;if(0===n||n>=t.__size)return null;let o=t.__last,r=null,i=0;for(;null!==o&&i<n;){if(!e.has(o))return null;r=o;const t=ne.get(o);if(void 0===t)return null;o=t.__prev,i++}if(i!==n)return null;if(null!==o&&e.has(o))return null;return r}(n,u);if(null!==s){const f=u.size;if(0===a){const e=zt(s,f);let o=s,a=0;for(;null!==o&&a<f;){const t=ne.get(o);if(void 0===t)break;const e=qt();Ee(o,l),Xo(t)&&null===Jt&&(Jt=t.getFormat(),jt=t.getStyle(),Vt=t.__key),Yt(e),o=t.__next,a++}let d="";for(o=s,a=0;null!==o&&a<f;){const e=ne.get(o);if(void 0===e)break;let n;if(Pi(e)){const r=Ut._keyToDOMMap.get(o),i=r&&r.__lexicalTextContent;"string"!=typeof i&&t(352,e.getType()),n=i}else n=e.getTextContent();d+=n,a<f-1&&Pi(e)&&!e.isInline()&&(d+=D),o=e.__next,a++}const h=c.__lexicalSlotTextLength||0,g=h>0?i.slice(h):i,_=g.slice(0,g.length-e)+d;return c.__lexicalTextContent=_,Ht=r+_,void we(n,c,u)}if(function(e,n,o,r,i,s,l,c){if(1!==c&&-1!==c)return!1;const a=1===c?2:1;if(l!==a)return!1;const u=l-c;let f=e.__last;for(let t=0;t<u-1;t++){if(null===f)return!1;const t=te.get(f);if(void 0===t)return!1;f=t.__prev}if(null===f)return!1;const d=ne.get(s),h=te.get(f);if(void 0===d||void 0===h)return!1;if(d.__prev!==h.__prev)return!1;const g=[];let _=s;for(let t=0;t<l;t++){if(null===_)return!1;g.push(_);const t=ne.get(_);_=t?t.__next:null}const p=[];_=f;for(let t=0;t<u;t++){if(null===_)return!1;p.push(_);const t=te.get(_);_=t?t.__next:null}const y=new Set(p),m=new Set(g),x=[];let C=0,S=0;for(;C<u&&S<l;)if(g[S]===p[C])x.push({key:g[S],kind:"reconcile"}),C++,S++;else if(m.has(p[C])){if(y.has(g[S]))return!1;x.push({key:g[S],kind:"create",nextIndex:S}),S++}else x.push({key:p[C],kind:"destroy"}),C++;for(;C<u;)x.push({key:p[C++],kind:"destroy"});for(;S<l;)x.push({key:g[S],kind:"create",nextIndex:S}),S++;const v=zt(f,u);for(const t of x){const e=qt();if("reconcile"===t.kind)Ee(t.key,o.element);else if("destroy"===t.kind)ae(t.key,o.element);else{let e=null;for(let n=t.nextIndex+1;n<l;n++){const t=Ut._keyToDOMMap.get(g[n]);if(void 0!==t){e=t;break}}Te(t.key,o.withBefore(e??o.before))}if("destroy"!==t.kind){const e=ne.get(t.key);e&&Xo(e)&&null===Jt&&(Jt=e.getFormat(),jt=e.getStyle(),Vt=e.__key)}Yt(e)}let T="";for(let e=0;e<l;e++){const n=ne.get(g[e]);if(void 0===n)return!1;let o;if(Pi(n)){const r=Ut._keyToDOMMap.get(g[e]),i=r&&r.__lexicalTextContent;"string"!=typeof i&&t(350,n.getType()),o=i}else o=n.getTextContent();T+=o,e<l-1&&Pi(n)&&!n.isInline()&&(T+=D)}const k=r.__lexicalSlotTextLength||0,b=k>0?i.slice(k):i;return r.__lexicalTextContent=b.slice(0,b.length-v)+T,!0}(e,0,o,c,i,s,f,a)){const e=c.__lexicalTextContent;return"string"!=typeof e&&t(353),Ht=r+e,void we(n,c,u)}}}if(0===a){let n=e.__first,o=0;for(;null!==n;){const e=ne.get(n);if(void 0===e)break;const r=le||Zt.has(n)||Qt.has(n),i=qt();if(r)Ee(n,l);else{let o,r;if(Pi(e)){r=oe.get(n);const i=r&&r.__lexicalTextContent;"string"!=typeof i&&t(354,e.getType()),o=i}else o=e.getTextContent();Ht+=o,void 0!==r&&Gt(r)}Xo(e)?null===Jt&&(Jt=e.getFormat(),jt=e.getStyle(),Vt=e.__key):Pi(e)&&o<s-1&&!e.isInline()&&(Ht+=D),Yt(i),n=e.__next,o++}return c.__lexicalTextContent=Ht,c.__lexicalFirstTextKey=Vt,void(Ht=r+Ht)}}if(1===i&&1===s){const t=e.__first,r=n.__first;if(t===r)Ee(t,l);else{const e=Pe(t),n=Te(r,null);try{e.parentNode===l?l.replaceChild(n,e):o.insertChild(n)}catch(o){if("object"==typeof o&&null!=o){const i=`${o.toString()} Parent: ${l.tagName}, new child: {tag: ${n.tagName} key: ${r}}, old child: {tag: ${e.tagName}, key: ${t}}.`;throw new Error(i)}throw o}ae(t,null)}const i=ne.get(r);Xo(i)&&null===Jt&&(Jt=i.getFormat(),jt=i.getStyle(),Vt=i.__key)}else{const r=jc(e,te),c=jc(n,ne);if(r.length!==i&&t(227),c.length!==s&&t(228),0===i)0!==s&&ke(c,n,0,s-1,o);else if(0===s){if(0!==i){const t=null==o.after&&null==o.before&&0===xe(n).size&&null==o.element.__lexicalLineBreak;ue(r,0,i-1,t?null:l),t&&(l.textContent="")}}else!function(t,e,n,o,r,i){const s=o-1,l=r-1;let c,a,u=i.getFirstChild(),f=0,d=0;for(;f<=s&&d<=l;){const t=e[f],o=n[d],r=qt();if(t===o)u=Me(Ee(o,i.element)),f++,d++;else{if(void 0===a&&(a=Ae(n,d)),void 0===c)c=Ae(e,f);else if(!c.has(t)){f++,Yt(r);continue}if(!a.has(t)){u=Me(Pe(t)),ae(t,i.element),f++,c.delete(t),Yt(r);continue}if(c.has(o)){const t=bl(Ut,o);t!==u&&i.withBefore(u??i.before).insertChild(t),u=Me(Ee(o,i.element)),f++,d++}else Te(o,i.withBefore(u??i.before)),d++}const s=ne.get(o);null!==s&&Xo(s)?null===Jt&&(Jt=s.getFormat(),jt=s.getStyle(),Vt=s.__key):Pi(s)&&d<=l&&!s.isInline()&&(Ht+=D),Yt(r)}const h=f>s,g=d>l;if(h&&!g){const e=n[l+1],o=void 0===e?null:Ut.getElementByKey(e);ke(n,t,d,l,i.withBefore(o??i.before))}else g&&!h&&ue(e,f,s,i.element)}(n,r,c,i,s,o)}c.__lexicalTextContent=Ht,c.__lexicalFirstTextKey=Vt,Ht=r+Ht}(e,n,vc(n,o,Ut)),Kl(n)||(r=n,null==Jt||Jt===r.__textFormat||ce||r.setTextFormat(Jt),function(t){null==jt||jt===t.__textStyle||ce||t.setTextStyle(jt)}(n))}function we(t,e,n){const o=e.__lexicalFirstTextKey;if(null!=o){const e=t.__key;let r=o;for(;null!==r;){const t=ne.get(r);if(void 0===t){r=null;break}if(t.__parent===e)break;r=t.__parent}if(null!==r&&!n.has(r)){const t=ne.get(o);if(Xo(t))return Jt=t.getFormat(),void(jt=t.getStyle())}}e.__lexicalFirstTextKey=Vt}function Ee(e,n){const o=te.get(e);let r=ne.get(e);void 0!==o&&void 0!==r||t(61);const i=le||Zt.has(e)||Qt.has(e),s=bl(Ut,e);if(o===r&&!i){let e;if(Pi(o)){const n=s.__lexicalTextContent;"string"!=typeof n&&t(355,o.getType()),e=n,Gt(s)}else e=o.getTextContent();return Ht+=e,s}if(o!==r&&i&&xl(ie,$t,Xt,r,"updated"),se.$updateDOM(r,o,s,Ut)){const o=Te(e,null);return null===n&&t(62),n.replaceChild(o,s),ae(e,null),o}if(Pi(o)){Pi(r)||t(334,e);const n=r.__indent;(le||n!==o.__indent)&&he(s,n);const l=r.__format;(le||l!==o.__format)&&ge(s,l);const c=i&&(xe(r).size>0||xe(o).size>0)?ve(o,r,s):"";if(i){const t=Ht;if(Ne(o,r,s),zi(r)||r.isInline()||be(0,r,s),""!==c){const e=s.__lexicalTextContent||"";s.__lexicalTextContent=c+e,Ht=t+c+e,s.__lexicalSlotTextLength=c.length}else(xe(r).size>0||xe(o).size>0)&&(s.__lexicalSlotTextLength=0)}else{const e=s.__lexicalTextContent;"string"!=typeof e&&t(356,o.getType()),Ht+=e,Gt(s)}if((le||r.__dir!==o.__dir||r.__parent!==o.__parent)&&(_e(s,r),zi(r)&&!le))for(const t of r.getChildren())if(Pi(t)){_e(bl(Ut,t.getKey()),t)}}else{const t=r.getTextContent();if(Li(r)){const t=r.decorate(Ut,Wt);null!==t&&Oe(e,t),i&&(xe(r).size>0||xe(o).size>0)&&ve(o,r,s)}Ht+=t}if(!ce&&zi(r)){const t=r.getLatest();if(t.__cachedText!==Ht){const e=t.getWritable();e.__cachedText=Ht,r=e}}return se.$decorateDOM(r,o,s,Ut),Bt(r),s}function Oe(t,e){let n=Ut._pendingDecorators;const o=Ut._decorators;if(null===n){if(o[t]===e)return;n=Qs(Ut)}n[t]=e}function Me(t){let e=t.nextSibling;return null!==e&&e===Ut._blockCursorElement&&(e=e.nextSibling),e}function Ae(t,e){const n=new Set;for(let o=e;o<t.length;o++)n.add(t[o]);return n}function De(t,e,n,o,r,i){Ht="",Jt=null,jt=null,Vt=null,le=2===o,Ut=n,Wt=n._config,se=n._config.dom||_s,$t=n._nodes,Xt=Ut._listeners.mutation,Qt=r,Zt=i,te=t._nodeMap,ee=t,ne=e._nodeMap,ce=e._readOnly,oe=nt(n._keyToDOMMap),re=function(){const t=new Map,e=e=>{for(const n of e){const e=ne.get(n);if(void 0===e)continue;const o=e.__parent;if(null===o)continue;let r=t.get(o);void 0===r&&(r=new Set,t.set(o,r)),r.add(n)}};return e(Qt.keys()),e(Zt),t}();const s=new Map;return ie=s,Ee("root",null),Ut=void 0,$t=void 0,Qt=void 0,Zt=void 0,te=void 0,ee=void 0,ne=void 0,Wt=void 0,oe=void 0,re=void 0,ie=void 0,se=_s,s}function Pe(e){const n=oe.get(e);return void 0===n&&t(75,e),n} /*@__INLINE__*/function Fe(t){return{type:t}}const Ie=/* @__PURE__ */Fe("SELECTION_CHANGE_COMMAND"),Le=/* @__PURE__ */Fe("SELECTION_INSERT_CLIPBOARD_NODES_COMMAND"),Ke=/* @__PURE__ */Fe("CLICK_COMMAND"),ze=/* @__PURE__ */Fe("BEFORE_INPUT_COMMAND"),Be=/* @__PURE__ */Fe("INPUT_COMMAND"),Re=/* @__PURE__ */Fe("COMPOSITION_START_COMMAND"),We=/* @__PURE__ */Fe("COMPOSITION_END_COMMAND"),Ue=/* @__PURE__ */Fe("DELETE_CHARACTER_COMMAND"),$e=/* @__PURE__ */Fe("INSERT_LINE_BREAK_COMMAND"),He=/* @__PURE__ */Fe("INSERT_PARAGRAPH_COMMAND"),Je=/* @__PURE__ */Fe("CONTROLLED_TEXT_INSERTION_COMMAND"),je=/* @__PURE__ */Fe("PASTE_COMMAND"),Ve=/* @__PURE__ */Fe("REMOVE_TEXT_COMMAND"),qe=/* @__PURE__ */Fe("DELETE_WORD_COMMAND"),Ye=/* @__PURE__ */Fe("DELETE_LINE_COMMAND"),Ge=/* @__PURE__ */Fe("FORMAT_TEXT_COMMAND"),Xe=/* @__PURE__ */Fe("SET_TEXT_FORMAT_COMMAND"),Qe=/* @__PURE__ */Fe("UNDO_COMMAND"),Ze=/* @__PURE__ */Fe("REDO_COMMAND"),tn=/* @__PURE__ */Fe("KEYDOWN_COMMAND"),en=/* @__PURE__ */Fe("KEY_ARROW_RIGHT_COMMAND"),nn=/* @__PURE__ */Fe("MOVE_TO_END"),on=/* @__PURE__ */Fe("KEY_ARROW_LEFT_COMMAND"),rn=/* @__PURE__ */Fe("MOVE_TO_START"),sn=/* @__PURE__ */Fe("KEY_ARROW_UP_COMMAND"),ln=/* @__PURE__ */Fe("KEY_ARROW_DOWN_COMMAND"),cn=/* @__PURE__ */Fe("KEY_ENTER_COMMAND"),an=/* @__PURE__ */Fe("KEY_SPACE_COMMAND"),un=/* @__PURE__ */Fe("KEY_BACKSPACE_COMMAND"),fn=/* @__PURE__ */Fe("KEY_ESCAPE_COMMAND"),dn=/* @__PURE__ */Fe("KEY_DELETE_COMMAND"),hn=/* @__PURE__ */Fe("KEY_TAB_COMMAND"),gn=/* @__PURE__ */Fe("INSERT_TAB_COMMAND"),_n=/* @__PURE__ */Fe("INDENT_CONTENT_COMMAND"),pn=/* @__PURE__ */Fe("OUTDENT_CONTENT_COMMAND"),yn=/* @__PURE__ */Fe("DROP_COMMAND"),mn=/* @__PURE__ */Fe("FORMAT_ELEMENT_COMMAND"),xn=/* @__PURE__ */Fe("DRAGSTART_COMMAND"),Cn=/* @__PURE__ */Fe("DRAGOVER_COMMAND"),Sn=/* @__PURE__ */Fe("DRAGEND_COMMAND"),vn=/* @__PURE__ */Fe("COPY_COMMAND"),Tn=/* @__PURE__ */Fe("CUT_COMMAND"),kn=/* @__PURE__ */Fe("SELECT_ALL_COMMAND"),bn=/* @__PURE__ */Fe("CLEAR_EDITOR_COMMAND"),Nn=/* @__PURE__ */Fe("CLEAR_HISTORY_COMMAND"),wn=/* @__PURE__ */Fe("CAN_REDO_COMMAND"),En=/* @__PURE__ */Fe("CAN_UNDO_COMMAND"),On=/* @__PURE__ */Fe("FOCUS_COMMAND"),Mn=/* @__PURE__ */Fe("BLUR_COMMAND"),An=/* @__PURE__ */Fe("KEY_MODIFIER_COMMAND");function Dn(t){const e=new Map;return{dispose(){for(const t of e.values())t.dispose();e.clear()},register(n,o){let r=e.get(n);void 0===r&&(r={dispose:t(n,o),holders:new Set},e.set(n,r));const i=()=>{const t=e.get(n);t&&t.holders.delete(i)&&0===t.holders.size&&(e.delete(n),t.dispose())};return r.holders.add(i),i}}}function Pn(t,e,n,o){return t.addEventListener(e,n,o),t.removeEventListener.bind(t,e,n,o)}const Fn=Object.freeze({}),In=[["keydown",function(t,e){const n=e._inputState;n.lastKeyDownTimeStamp=t.timeStamp,n.lastKeyCode=t.key,"Backspace"!==t.key&&jn(n);if(e.isComposing())return;kl(e,tn,t)}],["pointerdown",function(t,e){const n=lc(t),o=t.pointerType;hc(n)&&"touch"!==o&&"pen"!==o&&0===t.button&&Mi(e,()=>{zc(n,e)||(e._inputState.isSelectionChangeFromMouseDown=!0)})}],["compositionstart",function(t,e){kl(e,Re,t)}],["compositionend",function(t,e){const n=e._inputState;i?n.compositionPhase="ending-firefox":l||!a&&!d?kl(e,We,t):(n.compositionPhase="ending-safari",n.compositionEndData=t.data)}],["input",function(t,e){t.stopPropagation();const n=e._inputState;jn(n),Mi(e,()=>{qn(t,e)||e.dispatchCommand(Be,t)},{event:t}),n.unprocessedBeforeInputData=null}],["click",function(t,e){Mi(e,()=>{const n=Lr(),o=Hl(Pl(e)),r=Kr();if(o)if(cr(n)){const t=n.anchor,e=t.getNode();"element"===t.type&&0===t.offset&&n.isCollapsed()&&!zi(e)&&1===tl().getChildrenSize()&&e.getTopLevelElementOrThrow().isEmpty()&&null!==r&&n.is(r)&&(o.removeAllRanges(),n.dirty=!0)}else if("touch"===t.pointerType||"pen"===t.pointerType){const n=tc(o,e._rootElement).anchorNode;if(dc(n)||Ls(n)){el(Ir(r,o,e,t))}}kl(e,Ke,t)})}],["cut",Fn],["copy",Fn],["dragstart",Fn],["dragover",Fn],["dragend",Fn],["paste",Fn],["focus",Fn],["blur",Fn],["drop",Fn]];s&&In.push(["beforeinput",(t,e)=>function(t,e){const n=t.inputType;if("deleteCompositionText"===n||i&&Tl(e))return;if("insertCompositionText"===n)return;Mi(e,()=>{qn(t,e)||kl(e,ze,t)},{event:t})}(t,e)]);const Ln=new WeakMap,Kn=new WeakMap,zn=Dn(t=>(t.addEventListener("selectionchange",ro),()=>t.removeEventListener("selectionchange",ro)));function Bn(t,e,n,o,r,i){const l=t.anchor,c=t.focus,a=l.getNode(),u=gi();let f;if(void 0!==i)f=i;else{const t=Hl(Pl(u));f=null!==t?tc(t,u._rootElement):null}const d=null!==f?f.anchorNode:null,h=l.key,g=u.getElementByKey(h),_=n.length;return h!==c.key||!Xo(a)||(!r&&(!s||u._inputState.lastBeforeInputInsertTextTimeStamp<o+50)||a.isDirty()&&_<2||rl(n))&&l.offset!==c.offset&&!a.isComposing()||Is(a)||a.isDirty()&&_>1||(r||!s)&&null!==g&&!a.isComposing()&&d!==Nc(a,g,u)||null!==f&&null!==e&&(!e.collapsed||e.startContainer!==f.anchorNode||e.startOffset!==f.anchorOffset)||!a.isComposing()&&(a.getFormat()!==t.format||a.getStyle()!==t.style)||function(t,e){if(e.isSegmented())return!0;if(!t.isCollapsed())return!1;const n=t.anchor.offset,o=e.getParentOrThrow(),r=Fs(e);return 0===n?!e.canInsertTextBefore()||!o.canInsertTextBefore()&&!e.isComposing()||r||function(t){const e=t.getPreviousSibling();return(Xo(e)||Pi(e)&&e.isInline())&&!e.canInsertTextAfter()}(e):n===e.getTextContentSize()&&(!e.canInsertTextAfter()||!o.canInsertTextAfter()&&!e.isComposing()||r)}(t,a)}function Rn(t,e){return Ls(t)&&null!==t.nodeValue&&0!==e&&e!==t.nodeValue.length}function Wn(e,n,o){const{anchorNode:r,anchorOffset:i,focusNode:s,focusOffset:l}=tc(e,n._rootElement),c=n._inputState;c.isSelectionChangeFromDOMUpdate&&(c.isSelectionChangeFromDOMUpdate=!1,Rn(r,i)&&Rn(s,l)&&!c.postDeleteSelectionToRestore)||Mi(n,()=>{if(!o)return void el(null);if(!Os(n,r,s))return;let a=Lr();if(c.postDeleteSelectionToRestore&&cr(a)&&a.isCollapsed()){const t=a.anchor,e=c.postDeleteSelectionToRestore.anchor;(t.key===e.key&&t.offset===e.offset+1||1===t.offset&&e.getNode().is(t.getNode().getPreviousSibling()))&&(a=c.postDeleteSelectionToRestore.clone(),el(a))}if(c.postDeleteSelectionToRestore=null,cr(a)){const o=a.anchor,u=o.getNode();if(a.isCollapsed()){"Range"===e.type&&r===s&&(a.dirty=!0);const i=Pl(n).event,l=i?i.timeStamp:performance.now(),{format:f,style:d,offset:h,key:g,timeStamp:_}=c.collapsedSelectionFormat,p=tl(),y=!1===n.isComposing()&&""===p.getTextContent();if(l<_+200&&o.offset===h&&o.key===g)Un(a,f,d);else if("text"===o.type)Xo(u)||t(141),$n(a,u);else if("element"===o.type&&!y){Pi(u)||t(259);const e=o.getNode();e.isEmpty()?function(t,e){const n=e.getTextFormat(),o=e.getTextStyle();Un(t,n,o)}(a,e):Un(a,a.format,"")}}else{const t=o.key,e=a.focus.key,n=a.getNodes(),r=n.length,s=a.isBackward(),c=s?l:i,u=s?i:l,f=s?e:t,d=s?t:e;let h=2047,g=!1;for(let t=0;t<r;t++){const e=n[t],o=e.getTextContentSize();if(Xo(e)&&0!==o&&!(0===t&&e.__key===f&&c===o||t===r-1&&e.__key===d&&0===u)&&(g=!0,h&=e.getFormat(),0===h))break}a.format=g?h:0}}kl(n,Ie,void 0)})}function Un(t,e,n){t.format===e&&t.style===n||(t.format=e,t.style=n,t.dirty=!0)}function $n(t,e){Un(t,e.getFormat(),e.getStyle())}function Hn(t){if(!t.getTargetRanges)return null;const e=t.getTargetRanges();return 0===e.length?null:e[0]}function Jn(t){const{lastKeyCode:e}=gi()._inputState;if(null==t||t.length<=1||null==e)return;const n=1===e.length?e:"Enter"===e?"\n":"Tab"===e?"\t":null;if(!n)return;const o=Lr();if(!cr(o)||!o.isCollapsed())return;const r=o.anchor.getNode();if(!Xo(r))return;const{offset:i}=o.anchor;if(r.getTextContentSize()===i){const t=r.getNextSibling();if("\n"===n){if(qi(t))t.selectEnd();else if(!t){const t=Jc(r,Mr),e=t&&t.getNextSibling();Pi(e)&&e.selectStart()}}else"\t"===n?er(t)&&t.selectEnd():Xo(t)&&t.getTextContent()[0]===n&&t.select(1,1)}else r.getTextContent()[i]===n&&r.select(i+1,i+1)}function jn(t){t.isInsertTextAfterHandledSelectionCommand=!1,null!==t.handledSelectionCommandTimeoutId&&(clearTimeout(t.handledSelectionCommandTimeoutId),t.handledSelectionCommandTimeoutId=null)}function Vn(t){jn(t),t.isInsertTextAfterHandledSelectionCommand=!0,t.handledSelectionCommandTimeoutId=setTimeout(()=>jn(t),0)}function qn(t,e){const n=lc(t);if(dc(n)&&zc(n,e))return!0;const o=e.getRootElement();if(null===o)return!1;const r=sc(o.ownerDocument);return null!==r&&o.contains(r)&&zc(r,e)}function Yn(e){const n=e.inputType,o=Hn(e),r=gi(),i=r._inputState,s=Lr();if("insertText"===n&&e.data&&i.isInsertTextAfterHandledSelectionCommand){if(jn(i),e.preventDefault(),cr(s)&&!s.isCollapsed()){const t=s.isBackward()?s.anchor:s.focus;s.anchor.set(t.key,t.offset,t.type),s.focus.set(t.key,t.offset,t.type)}return!0}if("deleteContentBackward"===n){if(null===s){const t=Kr();if(!cr(t))return!0;el(t.clone())}if(cr(s)){const n=s.anchor.key===s.focus.key;if(function(t,e){return"MediaLast"===t.lastKeyCode&&e<t.lastKeyDownTimeStamp+30}(i,e.timeStamp)&&r.isComposing()&&n){if(Js(null),i.lastKeyDownTimeStamp=0,setTimeout(()=>{Mi(r,()=>{Js(null)})},30),cr(s)){const e=s.anchor.getNode();e.markDirty(),Xo(e)||t(142),$n(s,e)}}else{if(Js(null),l&&null!==o&&!o.collapsed&&(s.applyDOMRange(o),!s.isCollapsed()))return e.preventDefault(),s.removeText(),!0;e.preventDefault();const t=s.anchor.getNode(),c=t.getTextContent(),a=t.canInsertTextAfter(),u=0===s.anchor.offset&&s.focus.offset===c.length;let d=f&&n&&!u&&a;if(d&&s.isCollapsed()&&(d=!Li(vl(s.anchor,!0))),!d){kl(r,Ue,!0);const t=Lr();f&&cr(t)&&t.isCollapsed()&&(i.postDeleteSelectionToRestore=t,setTimeout(()=>i.postDeleteSelectionToRestore=null))}}return!0}}if(!cr(s))return!0;const c=e.data;null!==i.unprocessedBeforeInputData&&cl(!1,r,i.unprocessedBeforeInputData),s.dirty&&null===i.unprocessedBeforeInputData||!s.isCollapsed()||zi(s.anchor.getNode())||null===o||s.applyDOMRange(o),i.unprocessedBeforeInputData=null;const a=s.anchor,u=s.focus,d=a.getNode(),h=u.getNode();if("insertText"===n||"insertTranspose"===n){if("\n"===c)e.preventDefault(),kl(r,$e,!1);else if(c===D)e.preventDefault(),kl(r,He,void 0);else if(null==c&&e.dataTransfer){const t=e.dataTransfer.getData("text/plain");e.preventDefault(),s.insertRawText(t)}else null!=c&&Bn(s,o,c,e.timeStamp,!0)?(e.preventDefault(),kl(r,Je,c),Jn(c)):i.unprocessedBeforeInputData=c;return i.lastBeforeInputInsertTextTimeStamp=e.timeStamp,!0}switch(e.preventDefault(),n){case"insertFromYank":case"insertFromDrop":case"insertReplacementText":kl(r,Je,e);Jn((e.dataTransfer?e.dataTransfer.getData("text/plain"):null)??e.data);break;case"insertFromComposition":{const t=i.hadOrphanedCompositionEvents;i.hadOrphanedCompositionEvents=!1;const n=r._compositionKey;Js(null),t||kl(r,Je,e),Zn(n);break}case"insertLineBreak":Js(null),kl(r,$e,!1);break;case"insertParagraph":Js(null),i.isInsertLineBreak&&!l?(i.isInsertLineBreak=!1,kl(r,$e,!1)):kl(r,He,void 0);break;case"insertFromPaste":case"insertFromPasteAsQuotation":kl(r,je,e);break;case"deleteByComposition":(function(t,e){return t!==e||Pi(t)||Pi(e)||!Fs(t)||!Fs(e)})(d,h)&&kl(r,Ve,e);break;case"deleteByDrag":Ol(No),kl(r,Ve,e);break;case"deleteByCut":kl(r,Ve,e);break;case"deleteContent":kl(r,Ue,!1);break;case"deleteWordBackward":kl(r,qe,!0);break;case"deleteWordForward":kl(r,qe,!1);break;case"deleteHardLineBackward":case"deleteSoftLineBackward":kl(r,Ye,!0);break;case"deleteContentForward":case"deleteHardLineForward":case"deleteSoftLineForward":kl(r,Ye,!1);break;case"formatStrikeThrough":kl(r,Ge,"strikethrough");break;case"formatBold":kl(r,Ge,"bold");break;case"formatItalic":kl(r,Ge,"italic");break;case"formatUnderline":kl(r,Ge,"underline");break;case"historyUndo":kl(r,Qe,void 0);break;case"historyRedo":kl(r,Ze,void 0)}return!0}function Gn(t){const e=gi(),n=e._inputState,o=Lr(),r=t.data,l=Hn(t);let c=!1;if(null!=r&&cr(o)){const a=Hl(Pl(e)),u=null!==a?tc(a,e._rootElement):null,d="insertCompositionText"===t.inputType&&"ending-firefox"!==n.compositionPhase&&!e.isComposing();d&&(n.hadOrphanedCompositionEvents=!0);const h=o.anchor.getNode(),g="insertCompositionText"===t.inputType&&"ending-firefox"!==n.compositionPhase&&e.isComposing()&&Xo(h)&&Is(h);if(!d&&!g&&Bn(o,l,r,t.timeStamp,!1,u)){if(c=!0,"ending-firefox"===n.compositionPhase){const t=to(e,r);if(n.compositionPhase="idle",t)return Ol(Eo),nl(),!0}const l=o.anchor.getNode();if(null===a||null===u)return!0;const d=o.isBackward(),h=d?o.anchor.offset:o.focus.offset,g=d?o.focus.offset:o.anchor.offset;s&&!o.isCollapsed()&&Xo(l)&&null!==u.anchorNode&&l.getTextContent().slice(0,h)+r+l.getTextContent().slice(h+g)===ll(u.anchorNode)||kl(e,Je,r);const _=r.length;i&&_>1&&"insertCompositionText"===t.inputType&&!e.isComposing()&&(o.anchor.offset-=_,o._cachedNodes=null,o._cachedIsBackward=null),f&&e.isComposing()&&(n.lastKeyDownTimeStamp=0,Js(null))}}if(!c){cl(!1,e,null!==r?r:void 0),"ending-firefox"===n.compositionPhase&&(to(e,r||void 0),Ol(Eo),n.compositionPhase="idle")}return nl(),!0}function Xn(t){const e=gi(),n=e._inputState,o=Lr();if(cr(o)&&!e.isComposing()){n.compositionPhase="composing",n.hadOrphanedCompositionEvents=!1;const r=o.anchor,i=o.anchor.getNode();if(Js(r.key),Ol(wo),t.timeStamp<n.lastKeyDownTimeStamp+30||"element"===r.type||!o.isCollapsed()||!f&&(i.getFormat()!==o.format||Xo(i)&&i.getStyle()!==o.style)||Xo(i)&&(Is(i)||0===r.offset&&!i.canInsertTextBefore()||r.offset===i.getTextContentSize()&&!i.canInsertTextAfter())){kl(e,Je,P);const t=Lr();cr(t)&&Js(t.anchor.key)}}return!0}function Qn(t){const e=gi();return e._inputState.compositionPhase="idle",to(e,t.data),Ol(Eo),!0}function Zn(t){if(null===t)return;const e=Vs(t);if(!Xo(e)||"text"===e.getType()||Is(e)||!e.isAttached())return;const n=Lr(),o=cr(n)&&n.anchor.key===t?n.anchor.offset:null,r=Go(e.getTextContent());if(r.setFormat(e.getFormat()),r.setStyle(e.getStyle()),e.replace(r),null!==o){const t=Math.min(o,r.getTextContentSize());r.select(t,t)}}function to(t,e){const n=t._compositionKey;if(Js(null),null!==n&&null!=e){if(""===e){const e=Vs(n),o=t.getElementByKey(n),r=null!==o&&Xo(e)?Nc(e,o,t):null;if(null!==r&&null!==r.nodeValue&&Xo(e)){const n=Hl(Pl(t)),o=n&&tc(n,t._rootElement);let i=null,s=null;null!==o&&o.anchorNode===r&&(i=o.anchorOffset,s=o.focusOffset),al(e,r.nodeValue,i,s,!0)}return Zn(n),!1}if("\n"===e[e.length-1]){const e=Lr();if(cr(e)||ur(e)){if(cr(e)){const t=e.focus;e.anchor.set(t.key,t.offset,t.type)}return kl(t,cn,null),Zn(n),!1}}const o=Vs(n);if(null!==o&&Xo(o)&&Is(o)){o.markDirty();const t=Lr(),r=o.getTextContentSize(),i=cr(t)&&t.anchor.key===n?t.anchor.offset:r;return o.select(i,i).insertText(e),!0}}return cl(!0,t,e),Zn(n),!1}function eo(t){const e=gi(),n=e._inputState;if(null==t.key)return!0;if("ending-safari"===n.compositionPhase){const o=pl(t);if(o&&Mi(e,()=>{to(e,n.compositionEndData)}),n.compositionPhase="idle",n.compositionEndData="",o)return!0}if(function(t){return hl(t,"ArrowRight",{shiftKey:"any"})}(t))kl(e,en,t);else if(function(t){return hl(t,"ArrowRight",{...gl,shiftKey:"any"})}(t))kl(e,nn,t);else if(function(t){return hl(t,"ArrowLeft",{shiftKey:"any"})}(t))kl(e,on,t);else if(function(t){return hl(t,"ArrowLeft",{...gl,shiftKey:"any"})}(t))kl(e,rn,t);else if(function(t){return hl(t,"ArrowUp",{altKey:"any",shiftKey:"any"})}(t))kl(e,sn,t);else if(function(t){return hl(t,"ArrowDown",{altKey:"any",shiftKey:"any"})}(t))kl(e,ln,t);else if(function(t){return hl(t,"Enter",{altKey:"any",ctrlKey:"any",metaKey:"any",shiftKey:!0})}(t))n.isInsertLineBreak=!0,kl(e,cn,t);else if(function(t){return" "===t.key}(t))kl(e,an,t);else if(function(t){return r&&hl(t,"o",{ctrlKey:!0})}(t))t.preventDefault(),n.isInsertLineBreak=!0,kl(e,$e,!0);else if(function(t){return hl(t,"Enter",{altKey:"any",ctrlKey:"any",metaKey:"any"})}(t))n.isInsertLineBreak=!1,kl(e,cn,t);else if(function(t){return hl(t,"Backspace",{shiftKey:"any"})||r&&hl(t,"h",{ctrlKey:!0})}(t))pl(t)?kl(e,un,t)&&Vn(n):(t.preventDefault(),kl(e,Ue,!0));else if(function(t){return"Escape"===t.key}(t))kl(e,fn,t);else if(function(t){return hl(t,"Delete",{})||r&&hl(t,"d",{ctrlKey:!0})}(t))!function(t){return"Delete"===t.key}(t)?(t.preventDefault(),kl(e,Ue,!1)):kl(e,dn,t);else if(function(t){return hl(t,"Backspace",_l)}(t))t.preventDefault(),kl(e,qe,!0);else if(function(t){return hl(t,"Delete",_l)}(t))t.preventDefault(),kl(e,qe,!1);else if(function(t){return r&&hl(t,"Backspace",{metaKey:!0})}(t))t.preventDefault(),kl(e,Ye,!0);else if(function(t){return r&&(hl(t,"Delete",{metaKey:!0})||hl(t,"k",{ctrlKey:!0}))}(t))t.preventDefault(),kl(e,Ye,!1);else if(function(t){return hl(t,"b",gl)}(t))t.preventDefault(),kl(e,Ge,"bold");else if(function(t){return hl(t,"u",gl)}(t))t.preventDefault(),kl(e,Ge,"underline");else if(function(t){return hl(t,"i",gl)}(t))t.preventDefault(),kl(e,Ge,"italic");else if(function(t){return hl(t,"Tab",{shiftKey:"any"})}(t))kl(e,hn,t);else if(function(t){return hl(t,"z",gl)}(t))t.preventDefault(),kl(e,Qe,void 0);else if(function(t){if(r)return hl(t,"z",{metaKey:!0,shiftKey:!0});return hl(t,"y",{ctrlKey:!0})||hl(t,"z",{ctrlKey:!0,shiftKey:!0})}(t))t.preventDefault(),kl(e,Ze,void 0);else{const o=e._editorState._selection;!function(t){return hl(t,"a",gl)}(t)?null===o||cr(o)||(!function(t){return hl(t,"c",gl)}(t)?function(t){return hl(t,"x",gl)}(t)&&(t.preventDefault(),kl(e,Tn,t)):(t.preventDefault(),kl(e,vn,t))):(t.preventDefault(),kl(e,kn,t)&&Vn(n))}return function(t){return t.ctrlKey||t.shiftKey||t.altKey||t.metaKey}(t)&&e.dispatchCommand(An,t),!0}function no(t){let e=t.__lexicalEventHandles;return void 0===e&&(e=[],t.__lexicalEventHandles=e),e}const oo=new Map;function ro(t){const e=Jl(t.target);if(null===e)return;const n=wl(t.target);let o=null,r=null;const i=null!==n?Kn.get(n):void 0;if(null!==n){if(void 0!==i){const t=i.editors;let n=i.hasShadowEditor;if(void 0===n){n=!1;for(const e of t)if(null!==e._rootElement&&jl(e._rootElement.getRootNode())){n=!0;break}i.hasShadowEditor=n}if(n){let n=null,i=null;for(const s of t){const t=s._rootElement;if(null===t)continue;const l=tc(e,t).anchorNode;if(null!==l&&As(l)===s){if(jl(t.getRootNode())){o=s,r=l;break}null===n&&(n=s,i=l)}}null===o&&null!==n&&(o=n,r=i)}else{const t=e.anchorNode;null===t||dc(t)&&null!==t.shadowRoot||(o=As(t),null!==o&&(r=t))}}if(null===o){const t=sc(n);o=null!==t?As(t):null}}if(null===o)return;if(o._inputState.isSelectionChangeFromMouseDown){if(void 0!==i)for(const t of i.editors)t._inputState.isSelectionChangeFromMouseDown=!1;Mi(o,()=>{const n=Kr(),i=r??tc(e,o._rootElement).anchorNode;if(dc(i)||Ls(i)){el(Ir(n,e,o,t))}})}const s=il(o),l=s[s.length-1],c=l._key,a=oo.get(c),u=a||l;u!==o&&Wn(e,u,!1),Wn(e,o,!0),o!==l?oo.set(c,o):a&&oo.delete(c)}function io(t){t._lexicalHandled=!0}function so(t){return!0===t._lexicalHandled}const lo=()=>{};function co(e){const n=Ln.get(e);if(void 0===n)return void lo();const o=Kn.get(n);if(void 0===o)return void lo();Ln.delete(e);const r=Ds(e);Ms(r)?(!function(t){if(null!==t._parentEditor){const e=il(t),n=e[e.length-1]._key;oo.get(n)===t&&oo.delete(n)}else oo.delete(t._key)}(r),o.editors.delete(r),o.hasShadowEditor=void 0,e.__lexicalEditor=null):r&&t(198);const i=no(e);for(let t=0;t<i.length;t++)i[t]();e.__lexicalEventHandles=[]}function ao(e,n,o){ui();const r=e.__key,i=e.getParent();if(null===i)return void(null!==Xc(e)&&t(367,r,String(Xc(e))));const s=function(t){const e=Lr();if(!cr(e)||!Pi(t))return e;const{anchor:n,focus:o}=e,r=n.getNode(),i=o.getNode();Al(r,t)&&n.set(t.__key,0,"element");Al(i,t)&&o.set(t.__key,0,"element");return e}(e);let l=!1;if(cr(s)&&n){const t=s.anchor,n=s.focus;t.key===r&&(Rr(t,e,i,e.getPreviousSibling(),e.getNextSibling()),l=!0),n.key===r&&(Rr(n,e,i,e.getPreviousSibling(),e.getNextSibling()),l=!0)}else ur(s)&&n&&e.isSelected()&&e.selectPrevious();if(cr(s)&&n&&!l){const t=e.getIndexWithinParent();Us(e),zr(s,i,t,-1)}else Us(e);o||Kl(i)||i.canBeEmpty()||!i.isEmpty()||ao(i,n),n&&s&&zi(i)&&i.isEmpty()&&i.selectEnd()}function uo(t){return t}const fo=Symbol.for("ephemeral");function ho(t){return t[fo]||!1}const go={configurable:!0,enumerable:!1,value:void 0,writable:!0};class _o{__type;__key;__parent;__prev;__next;__state;[Kt];static getType(){const{ownNodeType:e}=Wc(this);return void 0===e&&t(64,this.name),e}static clone(e){t(65,this.name)}$config(){return{}}config(t,e){const n=e.extends||Vc(this.constructor);return Object.assign(e,{extends:n}),"string"==typeof t&&Object.assign(e,{type:t}),{[t]:e}}afterCloneFrom(t){this.__key===t.__key?(this.__parent=t.__parent,this.__next=t.__next,this.__prev=t.__prev,this.__state=t.__state):t.__state&&(this.__state=t.__state.getWritable(this))}resetOnCopyNodeFrom(t){this.__state&&(this.__state=this.__state.getWritable(this).resetOnCopyNode())}static importDOM;constructor(t){this.__type=this.constructor.getType(),this.__parent=null,this.__prev=null,this.__next=null,Object.defineProperty(this,"__state",go),Object.defineProperty(this,Kt,go),Ws(this