lexical
Version:
Lexical is an extensible text editor framework that provides excellent reliability, accessible and performance.
9 lines (8 loc) • 131 kB
JavaScript
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
function t(t,...e){const n=new URL("https://lexical.dev/docs/error"),r=new URLSearchParams;r.append("code",t);for(const t of e)r.append("v",t);throw n.search=r.toString(),Error(`Minified Lexical error #${t}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}function e(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);n.search=r.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,r=n&&"documentMode"in document?document.documentMode:null,i=n&&/Mac|iPod|iPhone|iPad/.test(navigator.platform),o=n&&/^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent),s=!(!n||!("InputEvent"in window)||r)&&"getTargetRanges"in new window.InputEvent("input"),l=n&&/Version\/[\d.]+.*Safari/.test(navigator.userAgent),c=n&&/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream,a=n&&/Android/.test(navigator.userAgent),u=n&&/^(?=.*Chrome).*/i.test(navigator.userAgent),f=n&&a&&u,d=n&&/AppleWebKit\/[\d.]+/.test(navigator.userAgent)&&i&&!u;function h(...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 g=0,_=1,p=2,y=1,m=2,x=4,C=8,S=16,v=32,k=64,T=128,N=2047,b=1,w=2,E=3,O=4,M=5,A=6,P=l||c||d?" ":"",D="\n\n",F=o?" ":P,L="֑-߿יִ-﷽ﹰ-ﻼ",I="A-Za-zÀ-ÖØ-öø-ʸ̀-ࠀ-Ⰰ-︀--",K=new RegExp("^[^"+I+"]*["+L+"]"),z=new RegExp("^[^"+L+"]*["+I+"]"),R={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},W={center:2,end:6,justify:4,left:1,right:3,start:5},J={[w]:"center",[A]:"end",[O]:"justify",[b]:"left",[E]:"right",[M]:"start"},j={normal:0,segmented:2,token:1},$={[g]:"normal",[p]:"segmented",[_]:"token"},U="$",V="$config";function Y(t,e,n,r,i,o){let s=t.getFirstChild();for(;null!==s;){const t=s.__key;s.__parent===e&&(Mi(s)&&Y(s,t,n,r,i,o),n.has(t)||o.delete(t),i.push(t)),s=s.getNextSibling()}}let q=!1,H=0;function G(t){H=t.timeStamp}function X(t,e,n){const r="BR"===t.nodeName,i=e.__lexicalLineBreak;return i&&(t===i||r&&t.previousSibling===i)||r&&void 0!==Mo(t,n)}function Q(t,e,n){const r=Ns(_s(n));let i=null,o=null;null!==r&&r.anchorNode===t&&(i=r.anchorOffset,o=r.focusOffset);const s=t.nodeValue;null!==s&&jo(e,s,i,o,!1)}function Z(t,e,n){if(br(t)){const e=t.anchor.getNode();if(e.is(n)&&t.format!==e.getFormat())return!1}return mo(e)&&n.isAttached()}function tt(t,e,n,r){for(let i=t;i&&!js(i);i=cs(i)){const t=Mo(i,e);if(void 0!==t){const e=Eo(t,n);if(e)return Di(e)||!Os(i)?void 0:[i,e]}else if(i===r)return[r,Lo(n)]}}function et(t,e,n){q=!0;const r=performance.now()-H>100;try{bi(t,()=>{const i=$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,_=tt(g,t,c,l);if(!_)continue;const[p,y]=_;if("characterData"===h)r&&pr(y)&&mo(g)&&Z(i,g,y)&&Q(g,y,t);else if("childList"===h){u=!0;const e=d.addedNodes;for(let n=0;n<e.length;n++){const r=e[n],i=Oo(r),s=r.parentNode;if(null!=s&&r!==a&&null===i&&!X(r,s,t)){if(o){const t=(Os(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];(X(r,g,t)||a===r)&&(g.appendChild(r),e++)}r!==e&&s.set(p,y)}}}if(s.size>0)for(const[e,n]of s)n.reconcileObservedMutation(e,t);const d=n.takeRecords();if(d.length>0){for(let e=0;e<d.length;e++){const n=d[e],r=n.addedNodes,i=n.target;for(let e=0;e<r.length;e++){const n=r[e],o=n.parentNode;null==o||"BR"!==n.nodeName||X(n,i,t)||o.removeChild(n)}}n.takeRecords()}null!==i&&(u&&Io(i),o&&is(t)&&i.insertRawText(f))})}finally{q=!1}}function nt(t){const e=t._observer;if(null!==e){et(t,e.takeRecords(),e)}}function rt(t){!function(t){0===H&&_s(t).addEventListener("textInput",G,!0)}(t),t._observer=new MutationObserver((e,n)=>{et(t,e,n)})}class it{key;parse;unparse;isEqual;defaultValue;constructor(t,e){this.key=t,this.parse=e.parse.bind(e),this.unparse=(e.unparse||gt).bind(e),this.isEqual=(e.isEqual||Object.is).bind(e),this.defaultValue=this.parse(void 0)}}function ot(t,e){return new it(t,e)}function st(t,e,n="latest"){const r=("latest"===n?t.getLatest():t).__state;return r?r.getValue(e):e.defaultValue}function lt(t,e,n){const r=st(t,n,"direct"),i=st(e,n,"direct");return n.isEqual(r,i)?null:[r,i]}function ct(t,e,n){let r;if(ui(),"function"==typeof n){const i=t.getLatest(),o=st(i,e);if(r=n(o),e.isEqual(o,r))return i}else r=n;const i=t.getWritable();return ft(i).updateFromKnown(e,r),i}function at(t){const e=new Map,n=new Set;for(let r="function"==typeof t?t:t.replace;r.prototype&&void 0!==r.prototype.getType;r=Object.getPrototypeOf(r)){const{ownNodeConfig:t}=Us(r);if(t&&t.stateConfigs)for(const r of t.stateConfigs){let t;"stateConfig"in r?(t=r.stateConfig,r.flat&&n.add(t.key)):t=r,e.set(t.key,t)}}return{flatKeys:n,sharedConfigMap:e}}class ut{node;knownState;unknownState;sharedNodeState;size;constructor(t,e,n=void 0,r=new Map,i=void 0){this.node=t,this.sharedNodeState=e,this.unknownState=n,this.knownState=r;const{sharedConfigMap:o}=this.sharedNodeState,s=void 0!==i?i:function(t,e,n){let r=n.size;if(e)for(const i in e){const e=t.get(i);e&&n.has(e)||r++}return r}(o,n,r);this.size=s}getValue(t){const e=this.knownState.get(t);if(void 0!==e)return e;this.sharedNodeState.sharedConfigMap.set(t.key,t);let n=t.defaultValue;if(this.unknownState&&t.key in this.unknownState){const e=this.unknownState[t.key];void 0!==e&&(n=t.parse(e)),this.updateFromKnown(t,n)}return n}getInternalState(){return[this.unknownState,this.knownState]}toJSON(){const t={...this.unknownState},e={};for(const[e,n]of this.knownState)e.isEqual(n,e.defaultValue)?delete t[e.key]:t[e.key]=e.unparse(n);for(const n of this.sharedNodeState.flatKeys)n in t&&(e[n]=t[n],delete t[n]);return ht(t)&&(e.$=t),e}getWritable(t){if(this.node===t)return this;const{sharedNodeState:e,unknownState:n}=this,r=new Map(this.knownState);return new ut(t,e,function(t,e,n){let r;if(n)for(const[i,o]of Object.entries(n)){const n=t.get(i);n?e.has(n)||e.set(n,n.parse(o)):(r=r||{},r[i]=o)}return r}(e.sharedConfigMap,r,n),r,this.size)}updateFromKnown(t,e){const n=t.key;this.sharedNodeState.sharedConfigMap.set(n,t);const{knownState:r,unknownState:i}=this;r.has(t)||i&&n in i||(i&&(delete i[n],this.unknownState=ht(i)),this.size++),r.set(t,e)}updateFromUnknown(t,e){const n=this.sharedNodeState.sharedConfigMap.get(t);n?this.updateFromKnown(n,n.parse(e)):(this.unknownState=this.unknownState||{},t in this.unknownState||this.size++,this.unknownState[t]=e)}updateFromJSON(t){const{knownState:e}=this;for(const t of e.keys())e.set(t,t.defaultValue);if(this.size=e.size,this.unknownState=void 0,t)for(const[e,n]of Object.entries(t))this.updateFromUnknown(e,n)}}function ft(t){const e=t.getWritable(),n=e.__state?e.__state.getWritable(e):new ut(e,dt(e));return e.__state=n,n}function dt(t){return t.__state?t.__state.sharedNodeState:oo(Ls(),t.getType()).sharedNodeState}function ht(t){if(t)for(const e in t)return t}function gt(t){return t}function _t(t,e,n){for(const[r,i]of e.knownState){if(t.has(r.key))continue;t.add(r.key);const e=n?n.getValue(r):r.defaultValue;if(e!==i&&!r.isEqual(e,i))return!0}return!1}function pt(t,e,n){const{unknownState:r}=e,i=n?n.unknownState:void 0;if(r)for(const[e,n]of Object.entries(r)){if(t.has(e))continue;t.add(e);if(n!==(i?i[e]:void 0))return!0}return!1}function yt(t,e){const n=t.__state;return n&&n.node===t?n.getWritable(e):n}function mt(t,e){const n=t.__mode,r=t.__format,i=t.__style,o=e.__mode,s=e.__format,l=e.__style,c=t.__state,a=e.__state;return(null===n||n===o)&&(null===r||r===s)&&(null===i||i===l)&&(null===t.__state||c===a||function(t,e){if(t===e)return!0;if(t&&e&&t.size!==e.size)return!1;const n=new Set;return!(t&&_t(n,t,e)||e&&_t(n,e,t)||t&&pt(n,t,e)||e&&pt(n,e,t))}(c,a))}function xt(t,e){const n=t.mergeWithSibling(e),r=hi()._normalizedNodes;return r.add(t.__key),r.add(e.__key),n}function Ct(t){let e,n,r=t;if(""!==r.__text||!r.isSimpleText()||r.isUnmergeable()){for(;null!==(e=r.getPreviousSibling())&&pr(e)&&e.isSimpleText()&&!e.isUnmergeable();){if(""!==e.__text){if(mt(e,r)){r=xt(e,r);break}break}e.remove()}for(;null!==(n=r.getNextSibling())&&pr(n)&&n.isSimpleText()&&!n.isUnmergeable();){if(""!==n.__text){if(mt(r,n)){r=xt(r,n);break}break}n.remove()}}else r.remove()}function St(t){return vt(t.anchor),vt(t.focus),t}function vt(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),pr(r)){t.set(r.__key,i?r.getTextContentSize():0,"text",!0);break}if(!Mi(r))break;t.set(r.__key,i?r.getChildrenSize():0,"element",!0)}}let kt,Tt,Nt,bt,wt,Et,Ot,Mt,At,Pt,Dt="",Ft=null,Lt=null,It="",Kt=!1,zt=!1;function Rt(t,e){const n=Ot.get(t);if(null!==e){const n=ne(t);n.parentNode===e&&e.removeChild(n)}if(Mt.has(t)||Tt._keyToDOMMap.delete(t),Mi(n)){const t=Xt(n,Ot);Bt(t,0,t.length-1,null)}void 0!==n&&ts(Pt,Nt,bt,n,"destroyed")}function Bt(t,e,n,r){let i=e;for(;i<=n;++i){const e=t[i];void 0!==e&&Rt(e,r)}}function Wt(t,e){t.setProperty("text-align",e)}const Jt="40px";function jt(t,e){const n=kt.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")||Jt;t.style.setProperty("padding-inline-start",0===e?"":`calc(${e} * ${r})`)}function $t(t,e){const n=t.style;0===e?Wt(n,""):1===e?Wt(n,"left"):2===e?Wt(n,"center"):3===e?Wt(n,"right"):4===e?Wt(n,"justify"):5===e?Wt(n,"start"):6===e&&Wt(n,"end")}function Ut(t,e){const n=function(t){const e=t.__dir;if(null!==e)return e;if(Li(t))return null;const n=t.getParentOrThrow();return Li(n)&&null===n.__dir?"auto":null}(e);null!==n?t.dir=n:t.removeAttribute("dir")}function Vt(e,n){const r=Mt.get(e);void 0===r&&t(60);const i=r.createDOM(kt,Tt);if(function(t,e,n){const r=n._keyToDOMMap;(function(t,e,n){const r=`__lexicalKey_${e._key}`;t[r]=n})(e,n,t),r.set(t,e)}(e,i,Tt),pr(r)?i.setAttribute("data-lexical-text","true"):Di(r)&&i.setAttribute("data-lexical-decorator","true"),Mi(r)){const t=r.__indent,e=r.__size;if(Ut(i,r),0!==t&&jt(i,t),0!==e){const t=e-1;Yt(Xt(r,Mt),r,0,t,r.getDOMSlot(i))}const n=r.__format;0!==n&&$t(i,n),r.isInline()||Ht(null,r,i),ss(r)&&(Dt+=D,It+=D)}else{const t=r.getTextContent();if(Di(r)){const t=r.decorate(Tt,kt);null!==t&&Zt(e,t),i.contentEditable="false"}Dt+=t,It+=t}return null!==n&&n.insertChild(i),ts(Pt,Nt,bt,r,"created"),i}function Yt(t,e,n,r,i){const o=Dt;Dt="";let s=n;for(;s<=r;++s){Vt(t[s],i);const e=Mt.get(t[s]);null!==e&&pr(e)&&null===Ft&&(Ft=e.getFormat(),Lt=e.getStyle())}ss(e)&&(Dt+=D);i.element.__lexicalTextContent=Dt,Dt=o+Dt}function qt(t,e){if(t){const n=t.__last;if(n){const t=e.get(n);if(t)return Qn(t)?"line-break":Di(t)&&t.isInline()?"decorator":null}return"empty"}return null}function Ht(t,e,n){const r=qt(t,Ot),i=qt(e,Mt);r!==i&&e.getDOMSlot(n).setManagedLineBreak(i)}function Gt(e,n,r){var i;Ft=null,Lt=null,function(e,n,r){const i=Dt,o=e.__size,s=n.__size;Dt="";const l=r.element;if(1===o&&1===s){const t=e.__first,r=n.__first;if(t===r)Qt(t,l);else{const e=ne(t),n=Vt(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}Rt(t,null)}const i=Mt.get(r);pr(i)&&null===Ft&&(Ft=i.getFormat(),Lt=i.getStyle())}else{const i=Xt(e,Ot),c=Xt(n,Mt);if(i.length!==o&&t(227),c.length!==s&&t(228),0===o)0!==s&&Yt(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;Bt(i,0,o-1,t?null:l),t&&(l.textContent="")}}else!function(t,e,n,r,i,o){const s=r-1,l=i-1;let c,a,u=o.getFirstChild(),f=0,d=0;for(;f<=s&&d<=l;){const t=e[f],r=n[d];if(t===r)u=te(Qt(r,o.element)),f++,d++;else{void 0===c&&(c=new Set(e)),void 0===a&&(a=new Set(n));const i=a.has(t),s=c.has(r);if(i)if(s){const t=ls(Tt,r);t===u?u=te(Qt(r,o.element)):(o.withBefore(u).insertChild(t),Qt(r,o.element)),f++,d++}else Vt(r,o.withBefore(u)),d++;else u=te(ne(t)),Rt(t,o.element),f++}const i=Mt.get(r);null!==i&&pr(i)&&null===Ft&&(Ft=i.getFormat(),Lt=i.getStyle())}const h=f>s,g=d>l;if(h&&!g){const e=n[l+1],r=void 0===e?null:Tt.getElementByKey(e);Yt(n,t,d,l,o.withBefore(r))}else g&&!h&&Bt(e,f,s,o.element)}(n,i,c,o,s,r)}ss(n)&&(Dt+=D);l.__lexicalTextContent=Dt,Dt=i+Dt}(e,n,n.getDOMSlot(r)),i=n,null==Ft||Ft===i.__textFormat||zt||i.setTextFormat(Ft),function(t){null==Lt||Lt===t.__textStyle||zt||t.setTextStyle(Lt)}(n)}function Xt(e,n){const r=[];let i=e.__first;for(;null!==i;){const e=n.get(i);void 0===e&&t(101),r.push(i),i=e.__next}return r}function Qt(e,n){const r=Ot.get(e);let i=Mt.get(e);void 0!==r&&void 0!==i||t(61);const o=Kt||Et.has(e)||wt.has(e),s=ls(Tt,e);if(r===i&&!o){if(Mi(r)){const t=s.__lexicalTextContent;void 0!==t&&(Dt+=t,It+=t)}else{const t=r.getTextContent();It+=t,Dt+=t}return s}if(r!==i&&o&&ts(Pt,Nt,bt,i,"updated"),i.updateDOM(r,s,kt)){const r=Vt(e,null);return null===n&&t(62),n.replaceChild(r,s),Rt(e,null),r}if(Mi(r)&&Mi(i)){const t=i.__indent;(Kt||t!==r.__indent)&&jt(s,t);const e=i.__format;if((Kt||e!==r.__format)&&$t(s,e),o&&(Gt(r,i,s),Li(i)||i.isInline()||Ht(r,i,s)),ss(i)&&(Dt+=D,It+=D),(Kt||i.__dir!==r.__dir)&&(Ut(s,i),Li(i)&&!Kt))for(const t of i.getChildren())if(Mi(t)){Ut(ls(Tt,t.getKey()),t)}}else{const t=i.getTextContent();if(Di(i)){const t=i.decorate(Tt,kt);null!==t&&Zt(e,t)}Dt+=t,It+=t}if(!zt&&Li(i)&&i.__cachedText!==It){const t=i.getWritable();t.__cachedText=It,i=t}return s}function Zt(t,e){let n=Tt._pendingDecorators;const r=Tt._decorators;if(null===n){if(r[t]===e)return;n=Po(Tt)}n[t]=e}function te(t){let e=t.nextSibling;return null!==e&&e===Tt._blockCursorElement&&(e=e.nextSibling),e}function ee(t,e,n,r,i,o){Dt="",It="",Kt=2===r,Tt=n,kt=n._config,Nt=n._nodes,bt=Tt._listeners.mutation,wt=i,Et=o,Ot=t._nodeMap,Mt=e._nodeMap,zt=e._readOnly,At=new Map(n._keyToDOMMap);const s=new Map;return Pt=s,Qt("root",null),Tt=void 0,Nt=void 0,wt=void 0,Et=void 0,Ot=void 0,Mt=void 0,kt=void 0,At=void 0,Pt=void 0,s}function ne(e){const n=At.get(e);return void 0===n&&t(75,e),n}function re(t){return{type:t}}const ie=re("SELECTION_CHANGE_COMMAND"),oe=re("SELECTION_INSERT_CLIPBOARD_NODES_COMMAND"),se=re("CLICK_COMMAND"),le=re("BEFORE_INPUT_COMMAND"),ce=re("INPUT_COMMAND"),ae=re("COMPOSITION_START_COMMAND"),ue=re("COMPOSITION_END_COMMAND"),fe=re("DELETE_CHARACTER_COMMAND"),de=re("INSERT_LINE_BREAK_COMMAND"),he=re("INSERT_PARAGRAPH_COMMAND"),ge=re("CONTROLLED_TEXT_INSERTION_COMMAND"),_e=re("PASTE_COMMAND"),pe=re("REMOVE_TEXT_COMMAND"),ye=re("DELETE_WORD_COMMAND"),me=re("DELETE_LINE_COMMAND"),xe=re("FORMAT_TEXT_COMMAND"),Ce=re("UNDO_COMMAND"),Se=re("REDO_COMMAND"),ve=re("KEYDOWN_COMMAND"),ke=re("KEY_ARROW_RIGHT_COMMAND"),Te=re("MOVE_TO_END"),Ne=re("KEY_ARROW_LEFT_COMMAND"),be=re("MOVE_TO_START"),we=re("KEY_ARROW_UP_COMMAND"),Ee=re("KEY_ARROW_DOWN_COMMAND"),Oe=re("KEY_ENTER_COMMAND"),Me=re("KEY_SPACE_COMMAND"),Ae=re("KEY_BACKSPACE_COMMAND"),Pe=re("KEY_ESCAPE_COMMAND"),De=re("KEY_DELETE_COMMAND"),Fe=re("KEY_TAB_COMMAND"),Le=re("INSERT_TAB_COMMAND"),Ie=re("INDENT_CONTENT_COMMAND"),Ke=re("OUTDENT_CONTENT_COMMAND"),ze=re("DROP_COMMAND"),Re=re("FORMAT_ELEMENT_COMMAND"),Be=re("DRAGSTART_COMMAND"),We=re("DRAGOVER_COMMAND"),Je=re("DRAGEND_COMMAND"),je=re("COPY_COMMAND"),$e=re("CUT_COMMAND"),Ue=re("SELECT_ALL_COMMAND"),Ve=re("CLEAR_EDITOR_COMMAND"),Ye=re("CLEAR_HISTORY_COMMAND"),qe=re("CAN_REDO_COMMAND"),He=re("CAN_UNDO_COMMAND"),Ge=re("FOCUS_COMMAND"),Xe=re("BLUR_COMMAND"),Qe=re("KEY_MODIFIER_COMMAND"),Ze=Object.freeze({}),tn=[["keydown",function(t,e){if(en=t.timeStamp,nn=t.key,e.isComposing())return;os(e,ve,t)}],["pointerdown",function(t,e){const n=t.target,r=t.pointerType;Ms(n)&&"touch"!==r&&"pen"!==r&&0===t.button&&bi(e,()=>{co(n)||(an=!0)})}],["compositionstart",function(t,e){os(e,ae,t)}],["compositionend",function(t,e){o?fn=!0:c||!l&&!d?os(e,ue,t):(dn=!0,hn=t.data)}],["input",function(t,e){t.stopPropagation(),bi(e,()=>{e.dispatchCommand(ce,t)},{event:t}),on=null}],["click",function(t,e){bi(e,()=>{const n=$r(),r=Ns(_s(e)),i=Ur();if(r)if(br(n)){const e=n.anchor,o=e.getNode();if("element"===e.type&&0===e.offset&&n.isCollapsed()&&!Li(o)&&1===Fo().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=Ys(o,t=>Mi(t)&&!t.isInline());Mi(t)&&t.select(0)}}}else if("touch"===t.pointerType||"pen"===t.pointerType){const n=r.anchorNode;if(Os(n)||mo(n)){Io(jr(i,r,e,t))}}os(e,se,t)})}],["cut",Ze],["copy",Ze],["dragstart",Ze],["dragover",Ze],["dragend",Ze],["paste",Ze],["focus",Ze],["blur",Ze],["drop",Ze]];s&&tn.push(["beforeinput",(t,e)=>function(t,e){const n=t.inputType;if("deleteCompositionText"===n||o&&is(e))return;if("insertCompositionText"===n)return;os(e,le,t)}(t,e)]);let en=0,nn=null,rn=0,on=null;const sn=new WeakMap,ln=new WeakMap;let cn=!1,an=!1,un=!1,fn=!1,dn=!1,hn="",gn=null,_n=[0,"",0,"root",0];function pn(t,e,n,r,i){const o=t.anchor,l=t.focus,c=o.getNode(),a=hi(),u=Ns(_s(a)),f=null!==u?u.anchorNode:null,d=o.key,h=a.getElementByKey(d),g=n.length;return d!==l.key||!pr(c)||(!i&&(!s||rn<r+50)||c.isDirty()&&g<2||zo(n))&&o.offset!==l.offset&&!c.isComposing()||yo(c)||c.isDirty()&&g>1||(i||!s)&&null!==h&&!c.isComposing()&&f!==Co(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=po(e);return 0===n?!e.canInsertTextBefore()||!r.canInsertTextBefore()&&!e.isComposing()||i||function(t){const e=t.getPreviousSibling();return(pr(e)||Mi(e)&&e.isInline())&&!e.canInsertTextAfter()}(e):n===e.getTextContentSize()&&(!e.canInsertTextAfter()||!r.canInsertTextAfter()&&!e.isComposing()||i)}(t,c)}function yn(t,e){return mo(t)&&null!==t.nodeValue&&0!==e&&e!==t.nodeValue.length}function mn(e,n,r){const{anchorNode:i,anchorOffset:o,focusNode:s,focusOffset:l}=e;cn&&(cn=!1,yn(i,o)&&yn(s,l)&&!gn)||bi(n,()=>{if(!r)return void Io(null);if(!uo(n,i,s))return;let c=$r();if(gn&&br(c)&&c.isCollapsed()){const t=c.anchor,e=gn.anchor;(t.key===e.key&&t.offset===e.offset+1||1===t.offset&&e.getNode().is(t.getNode().getPreviousSibling()))&&(c=gn.clone(),Io(c))}if(gn=null,br(c)){const r=c.anchor,i=r.getNode();if(c.isCollapsed()){"Range"===e.type&&e.anchorNode===e.focusNode&&(c.dirty=!0);const o=_s(n).event,s=o?o.timeStamp:performance.now(),[l,a,u,f,d]=_n,h=Fo(),g=!1===n.isComposing()&&""===h.getTextContent();if(s<d+200&&r.offset===u&&r.key===f)xn(c,l,a);else if("text"===r.type)pr(i)||t(141),Cn(c,i);else if("element"===r.type&&!g){Mi(i)||t(259);const e=r.getNode();e.isEmpty()?function(t,e){const n=e.getTextFormat(),r=e.getTextStyle();xn(t,n,r)}(c,e):xn(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=2047,g=!1;for(let t=0;t<i;t++){const e=n[t],r=e.getTextContentSize();if(pr(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}}os(n,ie,void 0)})}function xn(t,e,n){t.format===e&&t.style===n||(t.format=e,t.style=n,t.dirty=!0)}function Cn(t,e){xn(t,e.getFormat(),e.getStyle())}function Sn(t){if(!t.getTargetRanges)return null;const e=t.getTargetRanges();return 0===e.length?null:e[0]}function vn(e){const n=e.inputType,r=Sn(e),i=hi(),o=$r();if("deleteContentBackward"===n){if(null===o){const t=Ur();if(!br(t))return!0;Io(t.clone())}if(br(o)){const n=o.anchor.key===o.focus.key;if(s=e.timeStamp,"MediaLast"===nn&&s<en+30&&i.isComposing()&&n){if(bo(null),en=0,setTimeout(()=>{bi(i,()=>{bo(null)})},30),br(o)){const e=o.anchor.getNode();e.markDirty(),pr(e)||t(142),Cn(o,e)}}else{bo(null),e.preventDefault();const t=o.anchor.getNode(),r=t.getTextContent(),s=t.canInsertTextAfter(),l=0===o.anchor.offset&&o.focus.offset===r.length;let c=f&&n&&!l&&s;if(c&&o.isCollapsed()&&(c=!Di(rs(o.anchor,!0))),!c){os(i,fe,!0);const t=$r();f&&br(t)&&t.isCollapsed()&&(gn=t,setTimeout(()=>gn=null))}}return!0}}var s;if(!br(o))return!0;const l=e.data;null!==on&&Jo(!1,i,on),o.dirty&&null===on||!o.isCollapsed()||Li(o.anchor.getNode())||null===r||o.applyDOMRange(r),on=null;const a=o.anchor,u=o.focus,d=a.getNode(),h=u.getNode();if("insertText"===n||"insertTranspose"===n){if("\n"===l)e.preventDefault(),os(i,de,!1);else if(l===D)e.preventDefault(),os(i,he,void 0);else if(null==l&&e.dataTransfer){const t=e.dataTransfer.getData("text/plain");e.preventDefault(),o.insertRawText(t)}else null!=l&&pn(o,r,l,e.timeStamp,!0)?(e.preventDefault(),os(i,ge,l)):on=l;return rn=e.timeStamp,!0}switch(e.preventDefault(),n){case"insertFromYank":case"insertFromDrop":case"insertReplacementText":os(i,ge,e);break;case"insertFromComposition":bo(null),os(i,ge,e);break;case"insertLineBreak":bo(null),os(i,de,!1);break;case"insertParagraph":bo(null),un&&!c?(un=!1,os(i,de,!1)):os(i,he,void 0);break;case"insertFromPaste":case"insertFromPasteAsQuotation":os(i,_e,e);break;case"deleteByComposition":(function(t,e){return t!==e||Mi(t)||Mi(e)||!po(t)||!po(e)})(d,h)&&os(i,pe,e);break;case"deleteByDrag":case"deleteByCut":os(i,pe,e);break;case"deleteContent":os(i,fe,!1);break;case"deleteWordBackward":os(i,ye,!0);break;case"deleteWordForward":os(i,ye,!1);break;case"deleteHardLineBackward":case"deleteSoftLineBackward":os(i,me,!0);break;case"deleteContentForward":case"deleteHardLineForward":case"deleteSoftLineForward":os(i,me,!1);break;case"formatStrikeThrough":os(i,xe,"strikethrough");break;case"formatBold":os(i,xe,"bold");break;case"formatItalic":os(i,xe,"italic");break;case"formatUnderline":os(i,xe,"underline");break;case"historyUndo":os(i,Ce,void 0);break;case"historyRedo":os(i,Se,void 0)}return!0}function kn(t){if(Os(t.target)&&co(t.target))return!0;const e=hi(),n=$r(),r=t.data,i=Sn(t);if(null!=r&&br(n)&&pn(n,i,r,t.timeStamp,!1)){fn&&(bn(e,r),fn=!1);const i=n.anchor.getNode(),a=Ns(_s(e));if(null===a)return!0;const u=n.isBackward(),f=u?n.anchor.offset:n.focus.offset,h=u?n.focus.offset:n.anchor.offset;s&&!n.isCollapsed()&&pr(i)&&null!==a.anchorNode&&i.getTextContent().slice(0,f)+r+i.getTextContent().slice(f+h)===Wo(a.anchorNode)||os(e,ge,r);const g=r.length;o&&g>1&&"insertCompositionText"===t.inputType&&!e.isComposing()&&(n.anchor.offset-=g),l||c||d||!e.isComposing()||(en=0,bo(null))}else{Jo(!1,e,null!==r?r:void 0),fn&&(bn(e,r||void 0),fn=!1)}return function(){ui();const t=hi();nt(t)}(),!0}function Tn(t){const e=hi(),n=$r();if(br(n)&&!e.isComposing()){const r=n.anchor,i=n.anchor.getNode();bo(r.key),(t.timeStamp<en+30||"element"===r.type||!n.isCollapsed()||i.getFormat()!==n.format||pr(i)&&i.getStyle()!==n.style)&&os(e,ge,F)}return!0}function Nn(t){return bn(hi(),t.data),!0}function bn(t,e){const n=t._compositionKey;if(bo(null),null!==n&&null!=e){if(""===e){const e=Eo(n),r=Co(t.getElementByKey(n));return void(null!==r&&null!==r.nodeValue&&pr(e)&&jo(e,r.nodeValue,null,null,!0))}if("\n"===e[e.length-1]){const e=$r();if(br(e)){const n=e.focus;return e.anchor.set(n.key,n.offset,n.type),void os(t,Oe,null)}}}Jo(!0,t,e)}function wn(t){const e=hi();if(null==t.key)return!0;if(dn&&Go(t))return bi(e,()=>{bn(e,hn)}),dn=!1,hn="",!0;if(function(t){return Yo(t,"ArrowRight",{shiftKey:"any"})}(t))os(e,ke,t);else if(function(t){return Yo(t,"ArrowRight",qo)}(t))os(e,Te,t);else if(function(t){return Yo(t,"ArrowLeft",{shiftKey:"any"})}(t))os(e,Ne,t);else if(function(t){return Yo(t,"ArrowLeft",qo)}(t))os(e,be,t);else if(function(t){return Yo(t,"ArrowUp",{altKey:"any",shiftKey:"any"})}(t))os(e,we,t);else if(function(t){return Yo(t,"ArrowDown",{altKey:"any",shiftKey:"any"})}(t))os(e,Ee,t);else if(function(t){return Yo(t,"Enter",{altKey:"any",ctrlKey:"any",metaKey:"any",shiftKey:!0})}(t))un=!0,os(e,Oe,t);else if(function(t){return" "===t.key}(t))os(e,Me,t);else if(function(t){return i&&Yo(t,"o",{ctrlKey:!0})}(t))t.preventDefault(),un=!0,os(e,de,!0);else if(function(t){return Yo(t,"Enter",{altKey:"any",ctrlKey:"any",metaKey:"any"})}(t))un=!1,os(e,Oe,t);else if(function(t){return Yo(t,"Backspace",{shiftKey:"any"})||i&&Yo(t,"h",{ctrlKey:!0})}(t))Go(t)?os(e,Ae,t):(t.preventDefault(),os(e,fe,!0));else if(function(t){return"Escape"===t.key}(t))os(e,Pe,t);else if(function(t){return Yo(t,"Delete",{})||i&&Yo(t,"d",{ctrlKey:!0})}(t))!function(t){return"Delete"===t.key}(t)?(t.preventDefault(),os(e,fe,!1)):os(e,De,t);else if(function(t){return Yo(t,"Backspace",Ho)}(t))t.preventDefault(),os(e,ye,!0);else if(function(t){return Yo(t,"Delete",Ho)}(t))t.preventDefault(),os(e,ye,!1);else if(function(t){return i&&Yo(t,"Backspace",{metaKey:!0})}(t))t.preventDefault(),os(e,me,!0);else if(function(t){return i&&(Yo(t,"Delete",{metaKey:!0})||Yo(t,"k",{ctrlKey:!0}))}(t))t.preventDefault(),os(e,me,!1);else if(function(t){return Yo(t,"b",qo)}(t))t.preventDefault(),os(e,xe,"bold");else if(function(t){return Yo(t,"u",qo)}(t))t.preventDefault(),os(e,xe,"underline");else if(function(t){return Yo(t,"i",qo)}(t))t.preventDefault(),os(e,xe,"italic");else if(function(t){return Yo(t,"Tab",{shiftKey:"any"})}(t))os(e,Fe,t);else if(function(t){return Yo(t,"z",qo)}(t))t.preventDefault(),os(e,Ce,void 0);else if(function(t){if(i)return Yo(t,"z",{metaKey:!0,shiftKey:!0});return Yo(t,"y",{ctrlKey:!0})||Yo(t,"z",{ctrlKey:!0,shiftKey:!0})}(t))t.preventDefault(),os(e,Se,void 0);else{const n=e._editorState._selection;null===n||br(n)?Xo(t)&&(t.preventDefault(),os(e,Ue,t)):!function(t){return Yo(t,"c",qo)}(t)?!function(t){return Yo(t,"x",qo)}(t)?Xo(t)&&(t.preventDefault(),os(e,Ue,t)):(t.preventDefault(),os(e,$e,t)):(t.preventDefault(),os(e,je,t))}return function(t){return t.ctrlKey||t.shiftKey||t.altKey||t.metaKey}(t)&&e.dispatchCommand(Qe,t),!0}function En(t){let e=t.__lexicalEventHandles;return void 0===e&&(e=[],t.__lexicalEventHandles=e),e}const On=new Map;function Mn(t){const e=bs(t.target);if(null===e)return;const n=ho(e.anchorNode);if(null===n)return;an&&(an=!1,bi(n,()=>{const r=Ur(),i=e.anchorNode;if(Os(i)||mo(i)){Io(jr(r,e,n,t))}}));const r=Ro(n),i=r[r.length-1],o=i._key,s=On.get(o),l=s||i;l!==n&&mn(e,l,!1),mn(e,n,!0),n!==i?On.set(o,n):s&&On.delete(o)}function An(t){t._lexicalHandled=!0}function Pn(t){return!0===t._lexicalHandled}const Dn=()=>{};function Fn(e){const n=sn.get(e);if(void 0===n)return void Dn();const r=ln.get(n);if(void 0===r)return void Dn();const i=r-1;i>=0||t(164),sn.delete(e),ln.set(n,i),0===i&&n.removeEventListener("selectionchange",Mn);const o=go(e);fo(o)?(!function(t){if(null!==t._parentEditor){const e=Ro(t),n=e[e.length-1]._key;On.get(n)===t&&On.delete(n)}else On.delete(t._key)}(o),e.__lexicalEditor=null):o&&t(198);const s=En(e);for(let t=0;t<s.length;t++)s[t]();e.__lexicalEventHandles=[]}function Ln(t,e,n){ui();const r=t.__key,i=t.getParent();if(null===i)return;const o=function(t){const e=$r();if(!br(e)||!Mi(t))return e;const{anchor:n,focus:r}=e,i=n.getNode(),o=r.getNode();hs(i,t)&&n.set(t.__key,0,"element");hs(o,t)&&r.set(t.__key,0,"element");return e}(t);let s=!1;if(br(o)&&e){const e=o.anchor,n=o.focus;e.key===r&&(qr(e,t,i,t.getPreviousSibling(),t.getNextSibling()),s=!0),n.key===r&&(qr(n,t,i,t.getPreviousSibling(),t.getNextSibling()),s=!0)}else Er(o)&&e&&t.isSelected()&&t.selectPrevious();if(br(o)&&e&&!s){const e=t.getIndexWithinParent();To(t),Vr(o,i,e,-1)}else To(t);n||ms(i)||i.canBeEmpty()||!i.isEmpty()||Ln(i,e),e&&o&&Li(i)&&i.isEmpty()&&i.selectEnd()}function In(t){return t}const Kn=Symbol.for("ephemeral");function zn(t){return t[Kn]||!1}class Rn{__type;__key;__parent;__prev;__next;__state;static getType(){const{ownNodeType:e}=Us(this);return void 0===e&&t(64,this.name),e}static clone(e){t(65,this.name)}$config(){return{}}config(t,e){const n=e.extends||Object.getPrototypeOf(this.constructor);return Object.assign(e,{extends:n,type:t}),{[t]:e}}afterCloneFrom(t){this.__key===t.__key?(this.__parent=t.__parent,this.__next=t.__next,this.__prev=t.__prev,this.__state=t.__state):t.__state&&(this.__state=t.__state.getWritable(this))}static importDOM;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}),ko(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=Eo(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(pr(this))return n;if(br(e)&&"element"===e.anchor.type&&"element"===e.focus.type){if(e.isCollapsed())return!1;const t=this.getParent();if(Di(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:Eo(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(ms(n))return Mi(e)||e===this&&Di(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:Eo(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:Eo(t)}getNextSiblings(){const t=[];let e=this.getNextSibling();for(;null!==e;)t.push(e),e=e.getNextSibling();return t}getCommonAncestor(t){const e=Mi(this)?this:this.getParent(),n=Mi(t)?t:t.getParent(),r=e&&n?wl(e,n):null;return r?r.commonAncestor:null}is(t){return null!=t&&this.__key===t.__key}isBefore(e){const n=wl(this,e);return null!==n&&("descendant"===n.type||("branch"===n.type?-1===Tl(n):("same"!==n.type&&"ancestor"!==n.type&&t(279),!1)))}isParentOf(t){const e=wl(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=Mi(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=hi()._dirtyLeaves;return null!==t&&t.has(this.__key)}getLatest(){if(zn(this))return this;const e=Eo(this.__key);return null===e&&t(113),e}getWritable(){if(zn(this))return this;ui();const t=di(),e=hi(),n=t._nodeMap,r=this.__key,i=this.getLatest(),o=e._cloneNotNeeded,s=$r();if(null!==s&&s.setCachedNodes(null),o.has(r))return No(i),i;const l=Rs(i);return o.add(r),No(l),n.set(r,l),l}getTextContent(){return""}getTextContentSize(){return this.getTextContent().length}createDOM(e,n){t(70)}updateDOM(e,n,r){t(71)}exportDOM(t){return{element:this.createDOM(t._config,t)}}exportJSON(){const t=this.__state?this.__state.toJSON():void 0;return{type:this.__type,version:1,...t}}static importJSON(e){t(18,this.name)}updateFromJSON(t){return function(t,e){const n=t.getWritable(),r=e.$;let i=r;for(const t of dt(n).flatKeys)t in e&&(void 0!==i&&i!==r||(i={...r}),i[t]=e[t]);return(n.__state||i)&&ft(t).updateFromJSON(i),n}(this,t)}static transform(){return null}remove(t){Ln(this,!0,t)}replace(e,n){ui();let r=$r();null!==r&&(r=r.clone()),Ss(this,e);const i=this.getLatest(),o=this.__key,s=e.__key,l=e.getWritable(),c=this.getParentOrThrow().getWritable(),a=c.__size;To(l);const u=i.getPreviousSibling(),f=i.getNextSibling(),d=i.__prev,h=i.__next,g=i.__parent;if(Ln(i,!1,!0),null===u)c.__first=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&&(Mi(this)&&Mi(l)||t(139),this.getChildren().forEach(t=>{l.append(t)})),br(r)){Io(r);const t=r.anchor,e=r.focus;t.key===o&&Tr(t,l),e.key===o&&Tr(e,l)}return wo()===o&&bo(s),l}insertAfter(t,e=!0){ui(),Ss(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(To(r),br(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&&br(o)){const t=this.getIndexWithinParent();Vr(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){ui(),Ss(this,t);const n=this.getWritable(),r=t.getWritable(),i=r.__key;To(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&&br(a)){Vr(a,this.getParentOrThrow(),c)}return t}isParentRequired(){return!1}createParentElementNode(){return $i()}selectStart(){return this.selectPrevious()}selectEnd(){return this.selectNext(0,0)}selectPrevious(t,e){ui();const n=this.getPreviousSibling(),r=this.getParentOrThrow();if(null===n)return r.select(0,0);if(Mi(n))return n.select();if(!pr(n)){const t=n.getIndexWithinParent()+1;return r.select(t,t)}return n.select(t,e)}selectNext(t,e){ui();const n=this.getNextSibling(),r=this.getParentOrThrow();if(null===n)return r.select();if(Mi(n))return n.select(0,0);if(!pr(n)){const t=n.getIndexWithinParent();return r.select(t,t)}return n.select(t,e)}markDirty(){this.getWritable()}reconcileObservedMutation(t,e){this.markDirty()}}const Bn="historic",Wn="history-push",Jn="history-merge",jn="paste",$n="collaboration",Un="skip-collab",Vn="skip-scroll-into-view",Yn="skip-dom-selection",qn="skip-selection-focus";class Hn extends Rn{static getType(){return"linebreak"}static clone(t){return new Hn(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&&Ds(e)){const n=e.firstChild;if(n===t||n.nextSibling===t&&Zn(n)){const n=e.lastChild;if(n===t||n.previousSibling===t&&Zn(n))return!0}}return!1}(t)||function(t){const e=t.parentElement;if(null!==e&&Ds(e)){const n=e.firstChild;if(n===t||n.nextSibling===t&&Zn(n))return!1;const r=e.lastChild;if(r===t||r.previousSibling===t&&Zn(r))return!0}return!1}(t)?null:{conversion:Gn,priority:0}}}static importJSON(t){return Xn().updateFromJSON(t)}}function Gn(t){return{node:Xn()}}function Xn(){return Cs(new Hn)}function Qn(t){return t instanceof Hn}function Zn(t){return mo(t)&&/^( |\t|\r?\n)+$/.test(t.textContent||"")}function tr(t,e){return 16&e?"code":e&T?"mark":32&e?"sub":64&e?"sup":null}function er(t,e){return 1&e?"strong":2&e?"em":"span"}function nr(t,e,n,r,i){const o=r.classList;let s=Zo(i,"base");void 0!==s&&o.add(...s),s=Zo(i,"underlineStrikethrough");let l=!1;const c=8&e&&4&e;void 0!==s&&(8&n&&4&n?(l=!0,c||o.add(...s)):c&&o.remove(...s));for(const t in R){const r=R[t];if(s=Zo(i,t),void 0!==s)if(n&r){if(l&&("underline"===t||"strikethrough"===t)){e&r&&o.remove(...s);continue}(0===(e&r)||c&&"underline"===t||"strikethrough"===t)&&o.add(...s)}else e&r&&o.remove(...s)}}function rr(t,e,n){const r=e.firstChild,i=n.isComposing(),s=t+(i?P:"");if(null==r)e.textContent=s;else{const t=r.nodeValue;if(t!==s)if(i||o){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 ir(t,e,n,r,i,o){rr(i,t,e);const s=o.theme.text;void 0!==s&&nr(0,0,r,t,s)}function or(t,e){const n=document.createElement(e);return n.appendChild(t),n}class sr extends Rn{__text;__format;__style;__mode;__detail;static getType(){return"text"}static clone(t){return new sr(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 $[t.__mode]}getStyle(){return this.getLatest().__style}isToken(){return 1===this.getLatest().__mode}isComposing(){return this.__key===wo()}isSegmented(){return 2===this.getLatest().__mode}isDirectionless(){return!!(1&this.getLatest().__detail)}isUnmergeable(){return!!(2&this.getLatest().__detail)}hasFormat(t){const e=R[t];return 0!==(this.getFormat()&e)}isSimpleText(){return"text"===this.__type&&0===this.__mode}getTextContent(){return this.getLatest().__text}getFormatFlags(t,e){return So(this.getLatest().__format,t,e)}canHaveFormat(){return!0}isInline(){return!0}createDOM(t,e){const n=this.__format,r=tr(0,n),i=er(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));ir(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=tr(0,o),c=tr(0,s),a=er(0,o),u=er(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 ir(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)),rr(i,f,this);const d=r.theme.text;void 0!==d&&o!==s&&nr(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:fr,priority:0}),b:()=>({conversion:cr,priority:0}),code:()=>({conversion:gr,priority:0}),em:()=>({conversion:gr,priority:0}),i:()=>({conversion:gr,priority:0}),mark:()=>({conversion:gr,priority:0}),s:()=>({conversion:gr,priority:0}),span:()=>({conversion:lr,priority:0}),strong:()=>({conversion:gr,priority:0}),sub:()=>({conversion:gr,priority:0}),sup:()=>({conversion:gr,priority:0}),u:()=>({conversion:gr,priority:0})}}static importJSON(t){return _r().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 Os(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=or(n,"b")),this.hasFormat("italic")&&(n=or(n,"i")),this.hasFormat("strikethrough")&&(n=or(n,"s")),this.hasFormat("underline")&&(n=or(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?R[t]:t,e}setDetail(t){const e=this.getWritable();return e.__detail="string"==typeof t?B[t]:t,e}setStyle(t){const e=this.getWritable();return e.__style=t,e}toggleFormat(t){const e=So(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){ui();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(!br(i))return Rr(s,n,s,r,"text","text");{const t=wo();t!==i.anchor.key&&t!==i.focus.key||bo(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&&br(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){ui();const e=this.getLatest(),n=e.getTextContent();if(""===n)return[];const r=e.__key,i=wo(),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 _=!1,p=null,y=null;const m=$r();if(br(m)){const[t,e]=m.isBackward()?[m.focus,m.anchor]:[m.anchor,m.focus];"text"===t.type&&t.key===r&&(p=t),"text"===e.type&&e.key===r&&(y=e)}e.isSegmented()?(f=_r(a),f.__format=d,f.__style=h,f.__detail=g,f.__state=yt(e,f),_=!0):f=e.setTextContent(a);const x=[f];for(let t=1;t<c;t++){const n=_r(s[t]);n.__format=d,n.__style=h,n.__detail=g,n.__state=yt(e,n);const o=n.__key;i===r&&bo(o),x.push(n)}const C=p?p.offset:null,S=y?y.offset:null;let v=0;for(const t of x){if(!p&&!y)break;const e=v+t.getTextContentSize();if(null!==p&&null!==C&&C<=e&&C>=v&&(p.set(t.getKey(),C-v,"text"),C<e&&(p=null)),null!==y&&null!==S&&S<=e&&S>=v){y.set(t.getKey(),S-v,"text");break}v=e}if(null!==u){!function(t){const e=t.getPreviousSibling(),n=t.getNextSibling();null!==e&&No(e);null!==n&&No(n)}(this);const t=u.getWritable(),e=this.getIndexWithinParent();_?(t.splice(e,0,x),this.remove()):t.splice(e,1,x),br(m)&&Vr(m,u,e,c-1)}return x}mergeWithSibling(e){const n=e===this.getPreviousSibling();n||e===this.getNextSibling()||t(50);const r=this.__key,i=e.__key,o=this.__text,s=o.length;wo()===i&&bo(r);const l=$r();if(br(l)){const t=l.anchor,o=l.focus;null!==t&&t.key===i&&Hr(t,n,r,e,s),null!==o&&o.key===i&&Hr(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 lr(t){return{forChild:yr(t.style),node:null}}function cr(t){const e=t,n="normal"===e.style.fontWeight;return{forChild:yr(e.style,n?void 0:"bold"),node:null}}const ar=new WeakMap;function ur(t){if(!Os(t))return!1;if("PRE"===t.nodeName)return!0;const e=t.style.whiteSpace;return"string"==typeof e&&e.startsWith("pre")}function fr(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=ar.get(n))&&!ur(n);)r.push(n),n=n.parentNode;const i=void 0===e?n:e;for(let t=0;t<r.length;t++)ar.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(Xn()):"\t"===n?e.push(xr()):""!==n&&e.push(_r(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=dr(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=dr(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:_r(r)}}function dr(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,Os(n)){const t=n.style.display;if(""===t&&!Ps(n)||""!==t&&!t.startsWith("inline"))return null}let r=n;for(;null!==(r=e?n.firstChild:n.lastChild);)n=r;if(mo(n))return n;if("BR"===n.nodeName)return null}}const hr={code:"code",em:"italic",i:"italic",mark:"highlight",s:"strikethrough",strong:"bold",sub:"subscript",sup:"superscript",u:"underline"};function gr(t){const e=hr[t.nodeName.toLowerCase()];return void 0===e?{node:null}:{forChild:yr(t.style,e),node:null}}function _r(t=""){return Cs(new sr(t))}function pr(t){return t instanceof sr}function yr(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=>pr(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 mr extends sr{static getType(){return"tab"}static clone(t){return new mr(t.__key)}constructor(t){super("\t",t),this.__detail=2}static importDOM(){return null}createDOM(t){const e=super.createDOM(t),n=Zo(t.theme,"tab");if(void 0!==n){e.classList.add(...n)}return e}static importJSON(t){return xr().updateFromJSON(t)}setTextContent(t){return"\t"!==t&&""!==t&&e(126),super.setTextContent("\t")}spliceText(e,n,r,i){return""===r&&0===n||"\t"===r&&1===n||t(286),this}setDetail(e){return 2!==e&&t(127),this}setMode(e){return"normal"!==e&&t(128),this}canInsertTextBefore(){return!1}canInsertTextAfter(){return!1}}function xr(){return Cs(new mr)}function Cr(t){return t instanceof mr}class Sr{key;offset;type;_selection;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 kl(Kl(El(this,"next")),Kl(El(t,"next")))<0}getNode(){const e=Eo(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,ai()||(wo()===o&&bo(t),null!==i&&(i.setCachedNodes(null),i.dirty=!0)))}}function vr(t,e,n){return new Sr(t,e,n)}function kr(t,e){let n=e.__key,r=t.offset,i="element";if(pr(e)){i="text";const t=e.getTextContentSize();r>t&&(r=t)}else if(!Mi(e)){const t=e.getNextSibling();if(pr(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 Tr(t,e){if(Mi(e)){const n=e.getLastDescendant();Mi(n)||pr(n)?kr(t,n):kr(t,e)}else kr(t,e)}class Nr{_nodes;_cachedNodes;dirty;constructor(t){this._cachedNodes=null,this._nodes=t,this.dirty=!1}getCachedNodes(){return this._cachedNodes}setCachedNodes(t){this._cachedNodes=t}is(t){if(!Er(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 Nr(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(pr(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=Eo(t);null!==e&&n.push(e)}return ai()||(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()||Ur())===this&&t[0]){const e=al(t[0],"next");Ml(Sl(e,e))}for(const e of t)e.remove()}}function br(t){return t instanceof wr}class wr{format;style;anchor;focus;_cachedNodes;dirty;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!!br(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(ol(n)){const{origin:t}=n;0===e.length?i.add(t):(o.add(t),e.push(t))}else{const{origin:t}=n;Mi(t)&&o.has(t)||e.push(t)}r&&e.push(r.caret.origin);if(il(