UNPKG

lexical

Version:

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

9 lines (8 loc) • 135 kB
/** * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * */ "use strict";function t(t,...e){const n=new URL("https://lexical.dev/docs/error"),r=new URLSearchParams;r.append("code",t);for(const t of e)r.append("v",t);throw n.search=r.toString(),Error(`Minified Lexical error #${t}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}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,o=n&&/Mac|iPod|iPhone|iPad/.test(navigator.platform),i=n&&/^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent),s=!(!n||!("InputEvent"in window)||r)&&"getTargetRanges"in new window.InputEvent("input"),l=n&&/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream,a=n&&/Android/.test(navigator.userAgent),c=n&&/Version\/[\d.]+.*Safari/.test(navigator.userAgent)&&!a,u=n&&/^(?=.*Chrome).*/i.test(navigator.userAgent),f=n&&a&&u,d=n&&/AppleWebKit\/[\d.]+/.test(navigator.userAgent)&&o&&!u,h=0,g=1,_=2,p=128,y=1,m=2,x=3,C=4,S=5,N=6,T=c||l||d?"\xa0":"\u200b",v="\n\n",k=i?"\xa0":T,E="\u0591-\u07ff\ufb1d-\ufdfd\ufe70-\ufefc",O="A-Za-z\xc0-\xd6\xd8-\xf6\xf8-\u02b8\u0300-\u0590\u0800-\u1fff\u200e\u2c00-\ufb1c\ufe00-\ufe6f\ufefd-\uffff",M=new RegExp("^[^"+O+"]*["+E+"]"),b=new RegExp("^[^"+E+"]*["+O+"]"),A={bold:1,capitalize:1024,code:16,highlight:p,italic:2,lowercase:256,strikethrough:4,subscript:32,superscript:64,underline:8,uppercase:512},w={directionless:1,unmergeable:2},D={center:2,end:6,justify:4,left:1,right:3,start:5},P={[m]:"center",[N]:"end",[C]:"justify",[y]:"left",[x]:"right",[S]:"start"},I={normal:0,segmented:2,token:1},F={[h]:"normal",[_]:"segmented",[g]:"token"},L="$config";function R(t,e,n,r,o,i){let s=t.getFirstChild();for(;null!==s;){const t=s.__key;s.__parent===e&&(fo(s)&&R(s,t,n,r,o,i),n.has(t)||i.delete(t),o.push(t)),s=s.getNextSibling()}}let K=!1,B=0;function z(t){B=t.timeStamp}function W(t,e,n){const r="BR"===t.nodeName,o=e.__lexicalLineBreak;return o&&(t===o||r&&t.previousSibling===o)||r&&void 0!==oi(t,n)}function $(t,e,n){const r=Vi(Bi(n));let o=null,i=null;null!==r&&r.anchorNode===t&&(o=r.anchorOffset,i=r.focusOffset);const s=t.nodeValue;null!==s&&yi(e,s,o,i,!1)}function U(t,e,n){if(ur(t)){const e=t.anchor.getNode();if(e.is(n)&&t.format!==e.getFormat())return!1}return Ho(e)&&n.isAttached()}function J(t,e,n,r){for(let o=t;o&&!as(o);o=Pi(o)){const t=oi(o,e);if(void 0!==t){const e=ni(t,n);if(e)return _o(e)||!qi(o)?void 0:[o,e]}else if(o===r)return[r,ci(n)]}}function Y(t,e,n){K=!0;const r=performance.now()-B>100;try{lo(t,()=>{const o=Er()||function(t){return t.getEditorState().read(()=>{const t=Er();return null!==t?t.clone():null})}(t),s=new Map,l=t.getRootElement(),a=t._editorState,c=t._blockCursorElement;let u=!1,f="";for(let n=0;n<e.length;n++){const d=e[n],h=d.type,g=d.target,_=J(g,t,a,l);if(!_)continue;const[p,y]=_;if("characterData"===h)r&&tr(y)&&Ho(g)&&U(o,g,y)&&$(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],o=ri(r),s=r.parentNode;if(null!=s&&r!==c&&null===o&&!W(r,s,t)){if(i){const t=(qi(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 o=0;o<r;o++){const r=n[o];(W(r,g,t)||c===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,o=n.target;for(let e=0;e<r.length;e++){const n=r[e],i=n.parentNode;null==i||"BR"!==n.nodeName||W(n,o,t)||i.removeChild(n)}}n.takeRecords()}null!==o&&(u&&ui(o),i&&Ai(t)&&o.insertRawText(f))})}finally{K=!1}}function j(t){const e=t._observer;if(null!==e){Y(t,e.takeRecords(),e)}}function H(t){!function(t){0===B&&Bi(t).addEventListener("textInput",z,!0)}(t),t._observer=new MutationObserver((e,n)=>{Y(t,e,n)})}class V{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 G(t,e,n="latest"){const r=("latest"===n?t.getLatest():t).__state;return r?r.getValue(e):e.defaultValue}function q(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 X{node;knownState;unknownState;sharedNodeState;size;constructor(t,e,n=void 0,r=new Map,o=void 0){this.node=t,this.sharedNodeState=e,this.unknownState=n,this.knownState=r;const{sharedConfigMap:i}=this.sharedNodeState,s=void 0!==o?o:function(t,e,n){let r=n.size;if(e)for(const o in e){const e=t.get(o);e&&n.has(e)||r++}return r}(i,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 tt(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 X(t,e,function(t,e,n){let r;if(n)for(const[o,i]of Object.entries(n)){const n=t.get(o);n?e.has(n)||e.set(n,n.parse(i)):(r=r||{},r[o]=i)}return r}(e.sharedConfigMap,r,n),r,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:r,unknownState:o}=this;r.has(t)||o&&n in o||(o&&(delete o[n],this.unknownState=tt(o)),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 Q(t){const e=t.getWritable(),n=e.__state?e.__state.getWritable(e):new X(e,Z(e));return e.__state=n,n}function Z(t){return t.__state?t.__state.sharedNodeState:Lo(ns(),t.getType()).sharedNodeState}function tt(t){if(t)for(const e in t)return t}function et(t){return t}function nt(t,e,n){for(const[r,o]of e.knownState){if(t.has(r.key))continue;t.add(r.key);const e=n?n.getValue(r):r.defaultValue;if(e!==o&&!r.isEqual(e,o))return!0}return!1}function rt(t,e,n){const{unknownState:r}=e,o=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!==(o?o[e]:void 0))return!0}return!1}function ot(t,e){const n=t.__state;return n&&n.node===t?n.getWritable(e):n}function it(t,e){const n=t.__mode,r=t.__format,o=t.__style,i=e.__mode,s=e.__format,l=e.__style,a=t.__state,c=e.__state;return(null===n||n===i)&&(null===r||r===s)&&(null===o||o===l)&&(null===t.__state||a===c||function(t,e){if(t===e)return!0;const n=new Set;return!(t&&nt(n,t,e)||e&&nt(n,e,t)||t&&rt(n,t,e)||e&&rt(n,e,t))}(a,c))}function st(t,e){const n=t.mergeWithSibling(e),r=Vr()._normalizedNodes;return r.add(t.__key),r.add(e.__key),n}function lt(t){let e,n,r=t;if(""!==r.__text||!r.isSimpleText()||r.isUnmergeable()){for(;null!==(e=r.getPreviousSibling())&&tr(e)&&e.isSimpleText()&&!e.isUnmergeable();){if(""!==e.__text){if(it(e,r)){r=st(e,r);break}break}e.remove()}for(;null!==(n=r.getNextSibling())&&tr(n)&&n.isSimpleText()&&!n.isUnmergeable();){if(""!==n.__text){if(it(r,n)){r=st(r,n);break}break}n.remove()}}else r.remove()}function at(t){return ct(t.anchor),ct(t.focus),t}function ct(t){for(;"element"===t.type;){const e=t.getNode(),n=t.offset;let r,o;if(n===e.getChildrenSize()?(r=e.getChildAtIndex(n-1),o=!0):(r=e.getChildAtIndex(n),o=!1),tr(r)){t.set(r.__key,o?r.getTextContentSize():0,"text",!0);break}if(!fo(r))break;t.set(r.__key,o?r.getChildrenSize():0,"element",!0)}}let ut,ft,dt,ht,gt,_t,pt,yt,mt,xt,Ct="",St=null,Nt=null,Tt=!1,vt=!1;function kt(t,e){const n=pt.get(t);if(null!==e){const n=Ut(t);n.parentNode===e&&e.removeChild(n)}if(yt.has(t)||ft._keyToDOMMap.delete(t),fo(n)){const t=Rt(n,pt);Et(t,0,t.length-1,null)}void 0!==n&&Oi(xt,dt,ht,n,"destroyed")}function Et(t,e,n,r){for(let o=e;o<=n;++o){const e=t[o];void 0!==e&&kt(e,r)}}function Ot(t,e){t.setProperty("text-align",e)}const Mt="40px";function bt(t,e){const n=ut.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)}if(0===e)return void t.style.setProperty("padding-inline-start","");const r=getComputedStyle(ft._rootElement||t).getPropertyValue("--lexical-indent-base-value")||Mt;t.style.setProperty("padding-inline-start",`calc(${e} * ${r})`)}function At(t,e){const n=t.style;0===e?Ot(n,""):1===e?Ot(n,"left"):2===e?Ot(n,"center"):3===e?Ot(n,"right"):4===e?Ot(n,"justify"):5===e?Ot(n,"start"):6===e&&Ot(n,"end")}function wt(t,e){const n=function(t){const e=t.__dir;if(null!==e)return e;if(yo(t))return null;const n=t.getParentOrThrow();return yo(n)&&null===n.__dir?"auto":null}(e);null!==n?t.dir=n:t.removeAttribute("dir")}function Dt(e,n){const r=yt.get(e);void 0===r&&t(60);const o=r.createDOM(ut,ft);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,o,ft),tr(r)?o.setAttribute("data-lexical-text","true"):_o(r)&&o.setAttribute("data-lexical-decorator","true"),fo(r)){const t=r.__indent,e=r.__size;if(wt(o,r),0!==t&&bt(o,t),0!==e){const t=e-1;Pt(Rt(r,yt),r,0,t,r.getDOMSlot(o))}const n=r.__format;0!==n&&At(o,n),r.isInline()||Ft(null,r,o)}else{const t=r.getTextContent();if(_o(r)){const t=r.decorate(ft,ut);null!==t&&Bt(e,t),o.contentEditable="false"}Ct+=t}return null!==n&&n.insertChild(o),Oi(xt,dt,ht,r,"created"),o}function Pt(t,e,n,r,o){const i=Ct;Ct="";let s=n;for(;s<=r;++s){Dt(t[s],o);const e=yt.get(t[s]);null!==e&&tr(e)?null===St&&(St=e.getFormat(),Nt=e.getStyle()):fo(e)&&s<r&&!e.isInline()&&(Ct+=v)}o.element.__lexicalTextContent=Ct,Ct=i+Ct}function It(t,e){if(t){const n=t.__last;if(n){const t=e.get(n);if(t)return Ln(t)?"line-break":_o(t)&&t.isInline()?"decorator":null}return"empty"}return null}function Ft(t,e,n){const r=It(t,pt),o=It(e,yt);r!==o&&e.getDOMSlot(n).setManagedLineBreak(o)}function Lt(e,n,r){var o;St=null,Nt=null,function(e,n,r){const o=Ct,i=e.__size,s=n.__size;Ct="";const l=r.element;if(1===i&&1===s){const t=e.__first,r=n.__first;if(t===r)Kt(t,l);else{const e=Ut(t),n=Dt(r,null);try{l.replaceChild(n,e)}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}kt(t,null)}const o=yt.get(r);tr(o)&&null===St&&(St=o.getFormat(),Nt=o.getStyle())}else{const o=Rt(e,pt),a=Rt(n,yt);if(o.length!==i&&t(227),a.length!==s&&t(228),0===i)0!==s&&Pt(a,0,0,s-1,r);else if(0===s){if(0!==i){const t=null==r.after&&null==r.before&&null==r.element.__lexicalLineBreak;Et(o,0,i-1,t?null:l),t&&(l.textContent="")}}else!function(t,e,n,r,o,i){const s=r-1,l=o-1;let a,c,u=i.getFirstChild(),f=0,d=0;for(;f<=s&&d<=l;){const t=e[f],r=n[d];if(t===r)u=zt(Kt(r,i.element)),f++,d++;else{if(void 0===c&&(c=Wt(n,d)),void 0===a)a=Wt(e,f);else if(!a.has(t)){f++;continue}if(!c.has(t)){u=zt(Ut(t)),kt(t,i.element),f++,a.delete(t);continue}if(a.has(r)){const t=Di(ft,r);t!==u&&i.withBefore(u).insertChild(t),u=zt(Kt(r,i.element)),f++,d++}else Dt(r,i.withBefore(u)),d++}const o=yt.get(r);null!==o&&tr(o)?null===St&&(St=o.getFormat(),Nt=o.getStyle()):fo(o)&&d<=l&&!o.isInline()&&(Ct+=v)}const h=f>s,g=d>l;if(h&&!g){const t=n[l+1],e=void 0===t?null:ft.getElementByKey(t);Pt(n,0,d,l,i.withBefore(e))}else g&&!h&&Et(e,f,s,i.element)}(0,o,a,i,s,r)}l.__lexicalTextContent=Ct,Ct=o+Ct}(e,n,n.getDOMSlot(r)),o=n,null==St||St===o.__textFormat||vt||o.setTextFormat(St),function(t){null==Nt||Nt===t.__textStyle||vt||t.setTextStyle(Nt)}(n)}function Rt(e,n){const r=[];let o=e.__first;for(;null!==o;){const e=n.get(o);void 0===e&&t(101),r.push(o),o=e.__next}return r}function Kt(e,n){const r=pt.get(e);let o=yt.get(e);void 0!==r&&void 0!==o||t(61);const i=Tt||_t.has(e)||gt.has(e),s=Di(ft,e);if(r===o&&!i){let t;if(fo(r)){const e=s.__lexicalTextContent;"string"==typeof e?t=e:(t=r.getTextContent(),s.__lexicalTextContent=t)}else t=r.getTextContent();return Ct+=t,s}if(r!==o&&i&&Oi(xt,dt,ht,o,"updated"),o.updateDOM(r,s,ut)){const r=Dt(e,null);return null===n&&t(62),n.replaceChild(r,s),kt(e,null),r}if(fo(r)){fo(o)||t(334,e);const n=o.__indent;(Tt||n!==r.__indent)&&bt(s,n);const l=o.__format;if((Tt||l!==r.__format)&&At(s,l),i)Lt(r,o,s),yo(o)||o.isInline()||Ft(r,o,s);else{const t=s.__lexicalTextContent;let e;"string"==typeof t?e=t:(e=r.getTextContent(),s.__lexicalTextContent=e),Ct+=e}if((Tt||o.__dir!==r.__dir)&&(wt(s,o),yo(o)&&!Tt))for(const t of o.getChildren())if(fo(t)){wt(Di(ft,t.getKey()),t)}}else{const t=o.getTextContent();if(_o(o)){const t=o.decorate(ft,ut);null!==t&&Bt(e,t)}Ct+=t}if(!vt&&yo(o)&&o.__cachedText!==Ct){const t=o.getWritable();t.__cachedText=Ct,o=t}return s}function Bt(t,e){let n=ft._pendingDecorators;const r=ft._decorators;if(null===n){if(r[t]===e)return;n=si(ft)}n[t]=e}function zt(t){let e=t.nextSibling;return null!==e&&e===ft._blockCursorElement&&(e=e.nextSibling),e}function Wt(t,e){const n=new Set;for(let r=e;r<t.length;r++)n.add(t[r]);return n}function $t(t,e,n,r,o,i){Ct="",Tt=2===r,ft=n,ut=n._config,dt=n._nodes,ht=ft._listeners.mutation,gt=o,_t=i,pt=t._nodeMap,yt=e._nodeMap,vt=e._readOnly,mt=new Map(n._keyToDOMMap);const s=new Map;return xt=s,Kt("root",null),ft=void 0,dt=void 0,gt=void 0,_t=void 0,pt=void 0,yt=void 0,ut=void 0,mt=void 0,xt=void 0,s}function Ut(e){const n=mt.get(e);return void 0===n&&t(75,e),n}function Jt(t){return{type:t}}const Yt=Jt("SELECTION_CHANGE_COMMAND"),jt=Jt("SELECTION_INSERT_CLIPBOARD_NODES_COMMAND"),Ht=Jt("CLICK_COMMAND"),Vt=Jt("BEFORE_INPUT_COMMAND"),Gt=Jt("INPUT_COMMAND"),qt=Jt("COMPOSITION_START_COMMAND"),Xt=Jt("COMPOSITION_END_COMMAND"),Qt=Jt("DELETE_CHARACTER_COMMAND"),Zt=Jt("INSERT_LINE_BREAK_COMMAND"),te=Jt("INSERT_PARAGRAPH_COMMAND"),ee=Jt("CONTROLLED_TEXT_INSERTION_COMMAND"),ne=Jt("PASTE_COMMAND"),re=Jt("REMOVE_TEXT_COMMAND"),oe=Jt("DELETE_WORD_COMMAND"),ie=Jt("DELETE_LINE_COMMAND"),se=Jt("FORMAT_TEXT_COMMAND"),le=Jt("UNDO_COMMAND"),ae=Jt("REDO_COMMAND"),ce=Jt("KEYDOWN_COMMAND"),ue=Jt("KEY_ARROW_RIGHT_COMMAND"),fe=Jt("MOVE_TO_END"),de=Jt("KEY_ARROW_LEFT_COMMAND"),he=Jt("MOVE_TO_START"),ge=Jt("KEY_ARROW_UP_COMMAND"),_e=Jt("KEY_ARROW_DOWN_COMMAND"),pe=Jt("KEY_ENTER_COMMAND"),ye=Jt("KEY_SPACE_COMMAND"),me=Jt("KEY_BACKSPACE_COMMAND"),xe=Jt("KEY_ESCAPE_COMMAND"),Ce=Jt("KEY_DELETE_COMMAND"),Se=Jt("KEY_TAB_COMMAND"),Ne=Jt("INSERT_TAB_COMMAND"),Te=Jt("INDENT_CONTENT_COMMAND"),ve=Jt("OUTDENT_CONTENT_COMMAND"),ke=Jt("DROP_COMMAND"),Ee=Jt("FORMAT_ELEMENT_COMMAND"),Oe=Jt("DRAGSTART_COMMAND"),Me=Jt("DRAGOVER_COMMAND"),be=Jt("DRAGEND_COMMAND"),Ae=Jt("COPY_COMMAND"),we=Jt("CUT_COMMAND"),De=Jt("SELECT_ALL_COMMAND"),Pe=Jt("CLEAR_EDITOR_COMMAND"),Ie=Jt("CLEAR_HISTORY_COMMAND"),Fe=Jt("CAN_REDO_COMMAND"),Le=Jt("CAN_UNDO_COMMAND"),Re=Jt("FOCUS_COMMAND"),Ke=Jt("BLUR_COMMAND"),Be=Jt("KEY_MODIFIER_COMMAND"),ze=Object.freeze({}),We=[["keydown",function(t,e){if($e=t.timeStamp,Ue=t.key,e.isComposing())return;wi(e,ce,t)}],["pointerdown",function(t,e){const n=t.target,r=t.pointerType;Xi(n)&&"touch"!==r&&"pen"!==r&&0===t.button&&lo(e,()=>{Bo(n)||(Ge=!0)})}],["compositionstart",function(t,e){wi(e,qt,t)}],["compositionend",function(t,e){i?Xe=!0:l||!c&&!d?wi(e,Xt,t):(Qe=!0,Ze=t.data)}],["input",function(t,e){t.stopPropagation(),lo(e,()=>{e.dispatchCommand(Gt,t)},{event:t}),Ye=null}],["click",function(t,e){lo(e,()=>{const n=Er(),r=Vi(Bi(e)),o=Or();if(r)if(ur(n)){const e=n.anchor,i=e.getNode();if("element"===e.type&&0===e.offset&&n.isCollapsed()&&!yo(i)&&1===ai().getChildrenSize()&&i.getTopLevelElementOrThrow().isEmpty()&&null!==o&&n.is(o))r.removeAllRanges(),n.dirty=!0;else if(3===t.detail&&!n.isCollapsed()){if(i!==n.focus.getNode()){const t=fs(i,t=>fo(t)&&!t.isInline());fo(t)&&t.select(0)}}}else if("touch"===t.pointerType||"pen"===t.pointerType){const n=r.anchorNode;if(qi(n)||Ho(n)){ui(kr(o,r,e,t))}}wi(e,Ht,t)})}],["cut",ze],["copy",ze],["dragstart",ze],["dragover",ze],["dragend",ze],["paste",ze],["focus",ze],["blur",ze],["drop",ze]];s&&We.push(["beforeinput",(t,e)=>function(t,e){const n=t.inputType;if("deleteCompositionText"===n||i&&Ai(e))return;if("insertCompositionText"===n)return;wi(e,Vt,t)}(t,e)]);let $e=0,Ue=null,Je=0,Ye=null;const je=new WeakMap,He=new WeakMap;let Ve=!1,Ge=!1,qe=!1,Xe=!1,Qe=!1,Ze="",tn=null,en=[0,"",0,"root",0];function nn(t,e,n,r,o){const i=t.anchor,l=t.focus,a=i.getNode(),c=Vr(),u=Vi(Bi(c)),f=null!==u?u.anchorNode:null,d=i.key,h=c.getElementByKey(d),g=n.length;return d!==l.key||!tr(a)||(!o&&(!s||Je<r+50)||a.isDirty()&&g<2||di(n))&&i.offset!==l.offset&&!a.isComposing()||jo(a)||a.isDirty()&&g>1||(o||!s)&&null!==h&&!a.isComposing()&&f!==Go(h)||null!==u&&null!==e&&(!e.collapsed||e.startContainer!==u.anchorNode||e.startOffset!==u.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,r=e.getParentOrThrow(),o=Yo(e);return 0===n?!e.canInsertTextBefore()||!r.canInsertTextBefore()&&!e.isComposing()||o||function(t){const e=t.getPreviousSibling();return(tr(e)||fo(e)&&e.isInline())&&!e.canInsertTextAfter()}(e):n===e.getTextContentSize()&&(!e.canInsertTextAfter()||!r.canInsertTextAfter()&&!e.isComposing()||o)}(t,a)}function rn(t,e){return Ho(t)&&null!==t.nodeValue&&0!==e&&e!==t.nodeValue.length}function on(e,n,r){const{anchorNode:o,anchorOffset:i,focusNode:s,focusOffset:l}=e;Ve&&(Ve=!1,rn(o,i)&&rn(s,l)&&!tn)||lo(n,()=>{if(!r)return void ui(null);if(!Wo(n,o,s))return;let a=Er();if(tn&&ur(a)&&a.isCollapsed()){const t=a.anchor,e=tn.anchor;(t.key===e.key&&t.offset===e.offset+1||1===t.offset&&e.getNode().is(t.getNode().getPreviousSibling()))&&(a=tn.clone(),ui(a))}if(tn=null,ur(a)){const r=a.anchor,o=r.getNode();if(a.isCollapsed()){"Range"===e.type&&e.anchorNode===e.focusNode&&(a.dirty=!0);const i=Bi(n).event,s=i?i.timeStamp:performance.now(),[l,c,u,f,d]=en,h=ai(),g=!1===n.isComposing()&&""===h.getTextContent();if(s<d+200&&r.offset===u&&r.key===f)sn(a,l,c);else if("text"===r.type)tr(o)||t(141),ln(a,o);else if("element"===r.type&&!g){fo(o)||t(259);const e=r.getNode();e.isEmpty()?function(t,e){const n=e.getTextFormat(),r=e.getTextStyle();sn(t,n,r)}(a,e):sn(a,a.format,"")}}else{const t=r.key,e=a.focus.key,n=a.getNodes(),o=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<o;t++){const e=n[t],r=e.getTextContentSize();if(tr(e)&&0!==r&&!(0===t&&e.__key===f&&c===r||t===o-1&&e.__key===d&&0===u)&&(g=!0,h&=e.getFormat(),0===h))break}a.format=g?h:0}}wi(n,Yt,void 0)})}function sn(t,e,n){t.format===e&&t.style===n||(t.format=e,t.style=n,t.dirty=!0)}function ln(t,e){sn(t,e.getFormat(),e.getStyle())}function an(t){if(!t.getTargetRanges)return null;const e=t.getTargetRanges();return 0===e.length?null:e[0]}function cn(e){const n=e.inputType,r=an(e),o=Vr(),i=Er();if("deleteContentBackward"===n){if(null===i){const t=Or();if(!ur(t))return!0;ui(t.clone())}if(ur(i)){const n=i.anchor.key===i.focus.key;if(s=e.timeStamp,"MediaLast"===Ue&&s<$e+30&&o.isComposing()&&n){if(ti(null),$e=0,setTimeout(()=>{lo(o,()=>{ti(null)})},30),ur(i)){const e=i.anchor.getNode();e.markDirty(),tr(e)||t(142),ln(i,e)}}else{ti(null),e.preventDefault();const t=i.anchor.getNode(),r=t.getTextContent(),s=t.canInsertTextAfter(),l=0===i.anchor.offset&&i.focus.offset===r.length;let a=f&&n&&!l&&s;if(a&&i.isCollapsed()&&(a=!_o(bi(i.anchor,!0))),!a){wi(o,Qt,!0);const t=Er();f&&ur(t)&&t.isCollapsed()&&(tn=t,setTimeout(()=>tn=null))}}return!0}}var s;if(!ur(i))return!0;const a=e.data;null!==Ye&&pi(!1,o,Ye),i.dirty&&null===Ye||!i.isCollapsed()||yo(i.anchor.getNode())||null===r||i.applyDOMRange(r),Ye=null;const c=i.anchor,u=i.focus,d=c.getNode(),h=u.getNode();if("insertText"===n||"insertTranspose"===n){if("\n"===a)e.preventDefault(),wi(o,Zt,!1);else if(a===v)e.preventDefault(),wi(o,te,void 0);else if(null==a&&e.dataTransfer){const t=e.dataTransfer.getData("text/plain");e.preventDefault(),i.insertRawText(t)}else null!=a&&nn(i,r,a,e.timeStamp,!0)?(e.preventDefault(),wi(o,ee,a)):Ye=a;return Je=e.timeStamp,!0}switch(e.preventDefault(),n){case"insertFromYank":case"insertFromDrop":case"insertReplacementText":wi(o,ee,e);break;case"insertFromComposition":ti(null),wi(o,ee,e);break;case"insertLineBreak":ti(null),wi(o,Zt,!1);break;case"insertParagraph":ti(null),qe&&!l?(qe=!1,wi(o,Zt,!1)):wi(o,te,void 0);break;case"insertFromPaste":case"insertFromPasteAsQuotation":wi(o,ne,e);break;case"deleteByComposition":(function(t,e){return t!==e||fo(t)||fo(e)||!Yo(t)||!Yo(e)})(d,h)&&wi(o,re,e);break;case"deleteByDrag":case"deleteByCut":wi(o,re,e);break;case"deleteContent":wi(o,Qt,!1);break;case"deleteWordBackward":wi(o,oe,!0);break;case"deleteWordForward":wi(o,oe,!1);break;case"deleteHardLineBackward":case"deleteSoftLineBackward":wi(o,ie,!0);break;case"deleteContentForward":case"deleteHardLineForward":case"deleteSoftLineForward":wi(o,ie,!1);break;case"formatStrikeThrough":wi(o,se,"strikethrough");break;case"formatBold":wi(o,se,"bold");break;case"formatItalic":wi(o,se,"italic");break;case"formatUnderline":wi(o,se,"underline");break;case"historyUndo":wi(o,le,void 0);break;case"historyRedo":wi(o,ae,void 0)}return!0}function un(t){if(qi(t.target)&&Bo(t.target))return!0;const e=Vr(),n=Er(),r=t.data,o=an(t);if(null!=r&&ur(n)&&nn(n,o,r,t.timeStamp,!1)){Xe&&(hn(e,r),Xe=!1);const o=n.anchor.getNode(),l=Vi(Bi(e));if(null===l)return!0;const a=n.isBackward(),c=a?n.anchor.offset:n.focus.offset,u=a?n.focus.offset:n.anchor.offset;s&&!n.isCollapsed()&&tr(o)&&null!==l.anchorNode&&o.getTextContent().slice(0,c)+r+o.getTextContent().slice(c+u)===_i(l.anchorNode)||wi(e,ee,r);const d=r.length;i&&d>1&&"insertCompositionText"===t.inputType&&!e.isComposing()&&(n.anchor.offset-=d),f&&e.isComposing()&&($e=0,ti(null))}else{pi(!1,e,null!==r?r:void 0),Xe&&(hn(e,r||void 0),Xe=!1)}return function(){Yr();const t=Vr();j(t)}(),!0}function fn(t){const e=Vr(),n=Er();if(ur(n)&&!e.isComposing()){const r=n.anchor,o=n.anchor.getNode();ti(r.key),Fi(wn),(t.timeStamp<$e+30||"element"===r.type||!n.isCollapsed()||o.getFormat()!==n.format||tr(o)&&o.getStyle()!==n.style)&&wi(e,ee,k)}return!0}function dn(t){return hn(Vr(),t.data),Fi(Dn),!0}function hn(t,e){const n=t._compositionKey;if(ti(null),null!==n&&null!=e){if(""===e){const e=ni(n),r=Go(t.getElementByKey(n));if(null!==r&&null!==r.nodeValue&&tr(e)){const n=Vi(Bi(t));let o=null,i=null;null!==n&&n.anchorNode===r&&(o=n.anchorOffset,i=n.focusOffset),yi(e,r.nodeValue,o,i,!0)}return}if("\n"===e[e.length-1]){const e=Er();if(ur(e)||dr(e)){if(ur(e)){const t=e.focus;e.anchor.set(t.key,t.offset,t.type)}return void wi(t,pe,null)}}}pi(!0,t,e)}function gn(t){const e=Vr();if(null==t.key)return!0;if(Qe){if(vi(t))return lo(e,()=>{hn(e,Ze)}),Qe=!1,Ze="",!0;Qe=!1,Ze=""}if(function(t){return Si(t,"ArrowRight",{shiftKey:"any"})}(t))wi(e,ue,t);else if(function(t){return Si(t,"ArrowRight",Ni)}(t))wi(e,fe,t);else if(function(t){return Si(t,"ArrowLeft",{shiftKey:"any"})}(t))wi(e,de,t);else if(function(t){return Si(t,"ArrowLeft",Ni)}(t))wi(e,he,t);else if(function(t){return Si(t,"ArrowUp",{altKey:"any",shiftKey:"any"})}(t))wi(e,ge,t);else if(function(t){return Si(t,"ArrowDown",{altKey:"any",shiftKey:"any"})}(t))wi(e,_e,t);else if(function(t){return Si(t,"Enter",{altKey:"any",ctrlKey:"any",metaKey:"any",shiftKey:!0})}(t))qe=!0,wi(e,pe,t);else if(function(t){return" "===t.key}(t))wi(e,ye,t);else if(function(t){return o&&Si(t,"o",{ctrlKey:!0})}(t))t.preventDefault(),qe=!0,wi(e,Zt,!0);else if(function(t){return Si(t,"Enter",{altKey:"any",ctrlKey:"any",metaKey:"any"})}(t))qe=!1,wi(e,pe,t);else if(function(t){return Si(t,"Backspace",{shiftKey:"any"})||o&&Si(t,"h",{ctrlKey:!0})}(t))vi(t)?wi(e,me,t):(t.preventDefault(),wi(e,Qt,!0));else if(function(t){return"Escape"===t.key}(t))wi(e,xe,t);else if(function(t){return Si(t,"Delete",{})||o&&Si(t,"d",{ctrlKey:!0})}(t))!function(t){return"Delete"===t.key}(t)?(t.preventDefault(),wi(e,Qt,!1)):wi(e,Ce,t);else if(function(t){return Si(t,"Backspace",Ti)}(t))t.preventDefault(),wi(e,oe,!0);else if(function(t){return Si(t,"Delete",Ti)}(t))t.preventDefault(),wi(e,oe,!1);else if(function(t){return o&&Si(t,"Backspace",{metaKey:!0})}(t))t.preventDefault(),wi(e,ie,!0);else if(function(t){return o&&(Si(t,"Delete",{metaKey:!0})||Si(t,"k",{ctrlKey:!0}))}(t))t.preventDefault(),wi(e,ie,!1);else if(function(t){return Si(t,"b",Ni)}(t))t.preventDefault(),wi(e,se,"bold");else if(function(t){return Si(t,"u",Ni)}(t))t.preventDefault(),wi(e,se,"underline");else if(function(t){return Si(t,"i",Ni)}(t))t.preventDefault(),wi(e,se,"italic");else if(function(t){return Si(t,"Tab",{shiftKey:"any"})}(t))wi(e,Se,t);else if(function(t){return Si(t,"z",Ni)}(t))t.preventDefault(),wi(e,le,void 0);else if(function(t){if(o)return Si(t,"z",{metaKey:!0,shiftKey:!0});return Si(t,"y",{ctrlKey:!0})||Si(t,"z",{ctrlKey:!0,shiftKey:!0})}(t))t.preventDefault(),wi(e,ae,void 0);else{const n=e._editorState._selection;null===n||ur(n)?ki(t)&&(t.preventDefault(),wi(e,De,t)):!function(t){return Si(t,"c",Ni)}(t)?!function(t){return Si(t,"x",Ni)}(t)?ki(t)&&(t.preventDefault(),wi(e,De,t)):(t.preventDefault(),wi(e,we,t)):(t.preventDefault(),wi(e,Ae,t))}return function(t){return t.ctrlKey||t.shiftKey||t.altKey||t.metaKey}(t)&&e.dispatchCommand(Be,t),!0}function _n(t){let e=t.__lexicalEventHandles;return void 0===e&&(e=[],t.__lexicalEventHandles=e),e}const pn=new Map;function yn(t){const e=Gi(t.target);if(null===e)return;const n=Uo(e.anchorNode);if(null===n)return;Ge&&(Ge=!1,lo(n,()=>{const r=Or(),o=e.anchorNode;if(qi(o)||Ho(o)){ui(kr(r,e,n,t))}}));const r=hi(n),o=r[r.length-1],i=o._key,s=pn.get(i),l=s||o;l!==n&&on(e,l,!1),on(e,n,!0),n!==o?pn.set(i,n):s&&pn.delete(i)}function mn(t){t._lexicalHandled=!0}function xn(t){return!0===t._lexicalHandled}const Cn=()=>{};function Sn(e){const n=je.get(e);if(void 0===n)return void Cn();const r=He.get(n);if(void 0===r)return void Cn();const o=r-1;o>=0||t(164),je.delete(e),He.set(n,o),0===o&&n.removeEventListener("selectionchange",yn);const i=Jo(e);$o(i)?(!function(t){if(null!==t._parentEditor){const e=hi(t),n=e[e.length-1]._key;pn.get(n)===t&&pn.delete(n)}else pn.delete(t._key)}(i),e.__lexicalEditor=null):i&&t(198);const s=_n(e);for(let t=0;t<s.length;t++)s[t]();e.__lexicalEventHandles=[]}function Nn(t,e,n){Yr();const r=t.__key,o=t.getParent();if(null===o)return;const i=function(t){const e=Er();if(!ur(e)||!fo(t))return e;const{anchor:n,focus:r}=e,o=n.getNode(),i=r.getNode();Ri(o,t)&&n.set(t.__key,0,"element");Ri(i,t)&&r.set(t.__key,0,"element");return e}(t);let s=!1;if(ur(i)&&e){const e=i.anchor,n=i.focus;e.key===r&&(Ar(e,t,o,t.getPreviousSibling(),t.getNextSibling()),s=!0),n.key===r&&(Ar(n,t,o,t.getPreviousSibling(),t.getNextSibling()),s=!0)}else dr(i)&&e&&t.isSelected()&&t.selectPrevious();if(ur(i)&&e&&!s){const e=t.getIndexWithinParent();Qo(t),Mr(i,o,e,-1)}else Qo(t);n||Wi(o)||o.canBeEmpty()||!o.isEmpty()||Nn(o,e),e&&i&&yo(o)&&o.isEmpty()&&o.selectEnd()}const Tn=Symbol.for("ephemeral");function vn(t){return t[Tn]||!1}class kn{__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))}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",{configurable:!0,enumerable:!1,value:void 0,writable:!0}),Xo(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=ni(t);if(null===e)break;t=e.__parent}return!1}isSelected(t){const e=t||Er();if(null==e)return!1;const n=e.getNodes().some(t=>t.__key===this.__key);if(tr(this))return n;if(ur(e)&&"element"===e.anchor.type&&"element"===e.focus.type){if(e.isCollapsed())return!1;const t=this.getParent();if(_o(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:ni(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(Wi(n))return fo(e)||e===this&&_o(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:ni(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:ni(t)}getNextSiblings(){const t=[];let e=this.getNextSibling();for(;null!==e;)t.push(e),e=e.getNextSibling();return t}getCommonAncestor(t){const e=fo(this)?this:this.getParent(),n=fo(t)?t:t.getParent(),r=e&&n?Us(e,n):null;return r?r.commonAncestor:null}is(t){return null!=t&&this.__key===t.__key}isBefore(e){const n=Us(this,e);return null!==n&&("descendant"===n.type||("branch"===n.type?-1===zs(n):("same"!==n.type&&"ancestor"!==n.type&&t(279),!1)))}isParentOf(t){const e=Us(this,t);return null!==e&&"ancestor"===e.type}getNodesBetween(e){const n=this.isBefore(e),r=[],o=new Set;let i=this;for(;null!==i;){const s=i.__key;if(o.has(s)||(o.add(s),r.push(i)),i===e)break;const l=fo(i)?n?i.getFirstChild():i.getLastChild():null;if(null!==l){i=l;continue}const a=n?i.getNextSibling():i.getPreviousSibling();if(null!==a){i=a;continue}const c=i.getParentOrThrow();if(o.has(c.__key)||r.push(c),c===e)break;let u=null,f=c;do{if(null===f&&t(68),u=n?f.getNextSibling():f.getPreviousSibling(),f=f.getParent(),null===f)break;null!==u||o.has(f.__key)||r.push(f)}while(null===u);i=u}return n||r.reverse(),r}isDirty(){const t=Vr()._dirtyLeaves;return null!==t&&t.has(this.__key)}getLatest(){if(vn(this))return this;const e=ni(this.__key);return null===e&&t(113),e}getWritable(){if(vn(this))return this;Yr();const t=Hr(),e=Vr(),n=t._nodeMap,r=this.__key,o=this.getLatest(),i=e._cloneNotNeeded,s=Er();if(null!==s&&s.setCachedNodes(null),i.has(r))return Zo(o),o;const l=ss(o);return i.add(r),Zo(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 o=r;for(const t of Z(n).flatKeys)t in e&&(void 0!==o&&o!==r||(o={...r}),o[t]=e[t]);return(n.__state||o)&&Q(t).updateFromJSON(o),n}(this,t)}static transform(){return null}remove(t){Nn(this,!0,t)}replace(e,n){Yr();let r=Er();null!==r&&(r=r.clone()),Ji(this,e);const o=this.getLatest(),i=this.__key,s=e.__key,l=e.getWritable(),a=this.getParentOrThrow().getWritable(),c=a.__size;Qo(l);const u=o.getPreviousSibling(),f=o.getNextSibling(),d=o.__prev,h=o.__next,g=o.__parent;if(Nn(o,!1,!0),null===u)a.__first=s;else{u.getWritable().__next=s}if(l.__prev=d,null===f)a.__last=s;else{f.getWritable().__prev=s}if(l.__next=h,l.__parent=g,a.__size=c,n&&(fo(this)&&fo(l)||t(139),this.getChildren().forEach(t=>{l.append(t)})),ur(r)){ui(r);const t=r.anchor,e=r.focus;t.key===i&&ar(t,l),e.key===i&&ar(e,l)}return ei()===i&&ti(s),l}insertAfter(t,e=!0){Yr(),Ji(this,t);const n=this.getWritable(),r=t.getWritable(),o=r.getParent(),i=Er();let s=!1,l=!1;if(null!==o){const e=t.getIndexWithinParent();if(Qo(r),ur(i)){const t=o.__key,n=i.anchor,r=i.focus;s="element"===n.type&&n.key===t&&n.offset===e+1,l="element"===r.type&&r.key===t&&r.offset===e+1}}const a=this.getNextSibling(),c=this.getParentOrThrow().getWritable(),u=r.__key,f=n.__next;if(null===a)c.__last=u;else{a.getWritable().__prev=u}if(c.__size++,n.__next=u,r.__next=f,r.__prev=n.__key,r.__parent=n.__parent,e&&ur(i)){const t=this.getIndexWithinParent();Mr(i,c,t+1);const e=c.__key;s&&i.anchor.set(e,t+2,"element"),l&&i.focus.set(e,t+2,"element")}return t}insertBefore(t,e=!0){Yr(),Ji(this,t);const n=this.getWritable(),r=t.getWritable(),o=r.__key;Qo(r);const i=this.getPreviousSibling(),s=this.getParentOrThrow().getWritable(),l=n.__prev,a=this.getIndexWithinParent();if(null===i)s.__first=o;else{i.getWritable().__next=o}s.__size++,n.__prev=o,r.__prev=l,r.__next=n.__key,r.__parent=n.__parent;const c=Er();if(e&&ur(c)){Mr(c,this.getParentOrThrow(),a)}return t}isParentRequired(){return!1}createParentElementNode(){return ko()}selectStart(){return this.selectPrevious()}selectEnd(){return this.selectNext(0,0)}selectPrevious(t,e){Yr();const n=this.getPreviousSibling(),r=this.getParentOrThrow();if(null===n)return r.select(0,0);if(fo(n))return n.select();if(!tr(n)){const t=n.getIndexWithinParent()+1;return r.select(t,t)}return n.select(t,e)}selectNext(t,e){Yr();const n=this.getNextSibling(),r=this.getParentOrThrow();if(null===n)return r.select();if(fo(n))return n.select(0,0);if(!tr(n)){const t=n.getIndexWithinParent();return r.select(t,t)}return n.select(t,e)}markDirty(){this.getWritable()}reconcileObservedMutation(t,e){this.markDirty()}}const En="history-merge",On="collaboration",Mn="skip-scroll-into-view",bn="skip-dom-selection",An="skip-selection-focus",wn="composition-start",Dn="composition-end";class Pn extends kn{static getType(){return"linebreak"}static clone(t){return new Pn(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&&ts(e)){const n=e.firstChild;if(n===t||n.nextSibling===t&&Rn(n)){const n=e.lastChild;if(n===t||n.previousSibling===t&&Rn(n))return!0}}return!1}(t)||function(t){const e=t.parentElement;if(null!==e&&ts(e)){const n=e.firstChild;if(n===t||n.nextSibling===t&&Rn(n))return!1;const r=e.lastChild;if(r===t||r.previousSibling===t&&Rn(r))return!0}return!1}(t)?null:{conversion:In,priority:0}}}static importJSON(t){return Fn().updateFromJSON(t)}}function In(t){return{node:Fn()}}function Fn(){return Ui(new Pn)}function Ln(t){return t instanceof Pn}function Rn(t){return Ho(t)&&/^( |\t|\r?\n)+$/.test(t.textContent||"")}function Kn(t,e){return 16&e?"code":e&p?"mark":32&e?"sub":64&e?"sup":null}function Bn(t,e){return 1&e?"strong":2&e?"em":"span"}function zn(t,e,n,r,o){const i=r.classList;let s=Ei(o,"base");void 0!==s&&i.add(...s),s=Ei(o,"underlineStrikethrough");let l=!1;const a=8&e&&4&e;void 0!==s&&(8&n&&4&n?(l=!0,a||i.add(...s)):a&&i.remove(...s));for(const t in A){const r=A[t];if(s=Ei(o,t),void 0!==s)if(n&r){if(l&&("underline"===t||"strikethrough"===t)){e&r&&i.remove(...s);continue}(0===(e&r)||a&&"underline"===t||"strikethrough"===t)&&i.add(...s)}else e&r&&i.remove(...s)}}function Wn(t,e,n){const r=e.firstChild,o=n.isComposing(),s=t+(o?T:"");if(null==r)e.textContent=s;else{const t=r.nodeValue;if(t!==s)if(o||i){const[e,n,o]=function(t,e){const n=t.length,r=e.length;let o=0,i=0;for(;o<n&&o<r&&t[o]===e[o];)o++;for(;i+o<n&&i+o<r&&t[n-i-1]===e[r-i-1];)i++;return[o,n-o-i,e.slice(o,r-i)]}(t,s);0!==n&&r.deleteData(e,n),r.insertData(e,o)}else r.nodeValue=s}}function $n(t,e,n,r,o,i){Wn(o,t,e);const s=i.theme.text;void 0!==s&&zn(0,0,r,t,s)}function Un(t,e){const n=document.createElement(e);return n.appendChild(t),n}class Jn extends kn{__text;__format;__style;__mode;__detail;static getType(){return"text"}static clone(t){return new Jn(t.__text,t.__key)}afterCloneFrom(t){super.afterCloneFrom(t),this.__text=t.__text,this.__format=t.__format,this.__style=t.__style,this.__mode=t.__mode,this.__detail=t.__detail}constructor(t="",e){super(e),this.__text=t,this.__format=0,this.__style="",this.__mode=0,this.__detail=0}getFormat(){return this.getLatest().__format}getDetail(){return this.getLatest().__detail}getMode(){const t=this.getLatest();return F[t.__mode]}getStyle(){return this.getLatest().__style}isToken(){return 1===this.getLatest().__mode}isComposing(){return this.__key===ei()}isSegmented(){return 2===this.getLatest().__mode}isDirectionless(){return!!(1&this.getLatest().__detail)}isUnmergeable(){return!!(2&this.getLatest().__detail)}hasFormat(t){const e=A[t];return 0!==(this.getFormat()&e)}isSimpleText(){return"text"===this.__type&&0===this.__mode}getTextContent(){return this.getLatest().__text}getFormatFlags(t,e){return qo(this.getLatest().__format,t,e)}canHaveFormat(){return!0}isInline(){return!0}createDOM(t,e){const n=this.__format,r=Kn(0,n),o=Bn(0,n),i=null===r?o:r,s=document.createElement(i);let l=s;this.hasFormat("code")&&s.setAttribute("spellcheck","false"),null!==r&&(l=document.createElement(o),s.appendChild(l));$n(l,this,0,n,this.__text,t);const a=this.__style;return""!==a&&(s.style.cssText=a),s}updateDOM(e,n,r){const o=this.__text,i=e.__format,s=this.__format,l=Kn(0,i),a=Kn(0,s),c=Bn(0,i),u=Bn(0,s);if((null===l?c:l)!==(null===a?u:a))return!0;if(l===a&&c!==u){const e=n.firstChild;null==e&&t(48);const i=document.createElement(u);return $n(i,this,0,s,o,r),n.replaceChild(i,e),!1}let f=n;null!==a&&null!==l&&(f=n.firstChild,null==f&&t(49)),Wn(o,f,this);const d=r.theme.text;void 0!==d&&i!==s&&zn(0,i,s,f,d);const h=e.__style,g=this.__style;return h!==g&&(n.style.cssText=g),!1}static importDOM(){return{"#text":()=>({conversion:Gn,priority:0}),b:()=>({conversion:jn,priority:0}),code:()=>({conversion:Qn,priority:0}),em:()=>({conversion:Qn,priority:0}),i:()=>({conversion:Qn,priority:0}),mark:()=>({conversion:Qn,priority:0}),s:()=>({conversion:Qn,priority:0}),span:()=>({conversion:Yn,priority:0}),strong:()=>({conversion:Qn,priority:0}),sub:()=>({conversion:Qn,priority:0}),sup:()=>({conversion:Qn,priority:0}),u:()=>({conversion:Qn,priority:0})}}static importJSON(t){return Zn().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 qi(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=Un(n,"b")),this.hasFormat("italic")&&(n=Un(n,"i")),this.hasFormat("strikethrough")&&(n=Un(n,"s")),this.hasFormat("underline")&&(n=Un(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?A[t]:t,e}setDetail(t){const e=this.getWritable();return e.__detail="string"==typeof t?w[t]:t,e}setStyle(t){const e=this.getWritable();return e.__style=t,e}toggleFormat(t){const e=qo(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=I[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){Yr();let n=t,r=e;const o=Er(),i=this.getTextContent(),s=this.__key;if("string"==typeof i){const t=i.length;void 0===n&&(n=t),void 0===r&&(r=t)}else n=0,r=0;if(!ur(o))return Nr(s,n,s,r,"text","text");{const t=ei();t!==o.anchor.key&&t!==o.focus.key||ti(s),o.setTextNodeRange(this,n,this,r)}return o}selectStart(){return this.select(0,0)}selectEnd(){const t=this.getTextContentSize();return this.select(t,t)}spliceText(t,e,n,r){const o=this.getWritable(),i=o.__text,s=n.length;let l=t;l<0&&(l=s+l,l<0&&(l=0));const a=Er();if(r&&ur(a)){const e=t+s;a.setTextNodeRange(o,e,o,e)}const c=i.slice(0,l)+n+i.slice(l+e);return o.__text=c,o}canInsertTextBefore(){return!0}canInsertTextAfter(){return!0}splitText(...t){Yr();const e=this.getLatest(),n=e.getTextContent();if(""===n)return[];const r=e.__key,o=ei(),i=n.length;t.sort((t,e)=>t-e),t.push(i);const s=[],l=t.length;for(let e=0,r=0;e<i&&r<=l;r++){const o=t[r];o>e&&(s.push(n.slice(e,o)),e=o)}const a=s.length;if(1===a)return[e];const c=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=Er();if(ur(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=Zn(c),f.__format=d,f.__style=h,f.__detail=g,f.__state=ot(e,f),_=!0):f=e.setTextContent(c);const x=[f];for(let t=1;t<a;t++){const n=Zn(s[t]);n.__format=d,n.__style=h,n.__detail=g,n.__state=ot(e,n);const i=n.__key;o===r&&ti(i),x.push(n)}const C=p?p.offset:null,S=y?y.offset:null;let N=0;for(const t of x){if(!p&&!y)break;const e=N+t.getTextContentSize();if(null!==p&&null!==C&&C<=e&&C>=N&&(p.set(t.getKey(),C-N,"text"),C<e&&(p=null)),null!==y&&null!==S&&S<=e&&S>=N){y.set(t.getKey(),S-N,"text");break}N=e}if(null!==u){!function(t){const e=t.getPreviousSibling(),n=t.getNextSibling();null!==e&&Zo(e);null!==n&&Zo(n)}(this);const t=u.getWritable(),e=this.getIndexWithinParent();_?(t.splice(e,0,x),this.remove()):t.splice(e,1,x),ur(m)&&Mr(m,u,e,a-1)}return x}mergeWithSibling(e){const n=e===this.getPreviousSibling();n||e===this.getNextSibling()||t(50);const r=this.__key,o=e.__key,i=this.__text,s=i.length;ei()===o&&ti(r);const l=Er();if(ur(l)){const t=l.anchor,i=l.focus;null!==t&&t.key===o&&wr(t,n,r,e,s),null!==i&&i.key===o&&wr(i,n,r,e,s)}const a=e.__text,c=n?a+i:i+a;this.setTextContent(c);const u=this.getWritable();return e.remove(),u}isTextEntity(){return!1}}function Yn(t){return{forChild:er(t.style),node:null}}function jn(t){const e=t,n="normal"===e.style.fontWeight;return{forChild:er(e.style,n?void 0:"bold"),node:null}}const Hn=new WeakMap;function Vn(t){if(!qi(t))return!1;if("PRE"===t.nodeName)return!0;const e=t.style.whiteSpace;return"string"==typeof e&&e.startsWith("pre")}function Gn(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=Hn.get(n))&&!Vn(n);)r.push(n),n=n.parentNode;const o=void 0===e?n:e;for(let t=0;t<r.length;t++)Hn.set(r[t],o);return o}(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(Fn()):"\t"===n?e.push(rr()):""!==n&&e.push(Zn(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=qn(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=qn(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:Zn(r)}}function qn(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,qi(n)){const t=n.style.display;if(""===t&&!Zi(n)||""!==t&&!t.startsWith("inline"))return null}let r=n;for(;null!==(r=e?n.firstChild:n.lastChild);)n=r;if(Ho(n))return n;if("BR"===n.nodeName)return null}}const Xn={code:"code",em:"italic",i:"italic",mark:"highlight",s:"strikethrough",strong:"bold",sub:"subscript",sup:"superscript",u:"underline"};function Qn(t){const e=Xn[t.nodeName.toLowerCase()];return void 0===e?{node:null}:{forChild:er(t.style,e),node:null}}function Zn(t=""){return Ui(new Jn(t))}function tr(t){return t instanceof Jn}function er(t,e){const n=t.fontWeight,r=t.textDecoration.split(" "),o="700"===n||"bold"===n,i=r.includes("line-through"),s="italic"===t.fontStyle,l=r.includes("underline"),a=t.verticalAlign;return t=>tr(t)?(o&&!t.hasFormat("bold")&&t.toggleFormat("bold"),i&&!t.hasFormat("strikethrough")&&t.toggleFormat("strikethrough"),s&&!t.hasFormat("italic")&&t.toggleFormat("italic"),l&&!t.hasFormat("underline")&&t.toggleFormat("underline"),"sub"!==a||t.hasFormat("subscript")||t.toggleFormat("subscript"),"super"!==a||t.hasFormat("superscript")||t.toggleFormat("superscript"),e&&!t.hasFormat(e)&&t.toggleFormat(e),t):t}class nr extends Jn{static getType(){return"tab"}static clone(t){return new nr(t.__key)}constructor(t){super("\t",t),this.__detail=2}static importDOM(){return null}createDOM(t){const e=super.createDOM(t),n=Ei(t.theme,"tab");if(void 0!==n){e.classList.add(...n)}return e}static importJSON(t){return rr().updateFromJSON(t)}setTextContent(t){return"\t"!==t&&""!==t&&e(126),super.setTextContent("\t")}spliceText(e,n,r,o){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 rr(){return Ui(new nr)}function or(t){return t instanceof nr}class ir{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 Bs(Zs(Js(this,"next")),Zs(Js(t,"next")))<0}getNode(){const e=ni(this.key);return null===e&&t(20),e}set(t,e,n,r){const o=this._selection,i=this.key;r&&this.key===t&&this.offset===e&&this.type===n||(this.key=t,this.offset=e,this.type=n,Jr()||(ei()===i&&ti(t),null!==o&&(o.setCachedNodes(null),o.dirty=!0)))}}function sr(t,e,n){return new ir(t,e,n)}function lr(t,e){let n=e.__key,r=t.offset,o="element";if(tr(e)){o="text";const t=e.getTextContentSize();r>t&&(r=t)}else if(!fo(e)){const t=e.getNextSibling();if(tr(t))n=t.__key,r=0,o="text";else{const t=e.getParent();t&&(n=t.__key,r=e.getIndexWithinParent()+1)}}t.set(n,r,o)}function ar(t,e){if(fo(e)){const n=e.getLastDescendant();fo(n)||tr(n)?lr(t,n):lr(t,e)}else lr(t,e)}class cr{_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(!dr(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 cr(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 o;if(tr(r))o=r.select();else{const t=r.getIndexWithinParent()+1;o=r.getParentOrThrow().select(t,t)}o.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=ni(t);null!==e&&n.push(e)}return Jr()||(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((Er()||Or())===this&&t[0]){const e=Es(t[0],"next");js(Rs(e,e))}for(const e of t)e.remove()}}function ur(t){return t instanceof fr}class fr{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!!ur(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(