UNPKG

lexical

Version:

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

9 lines (8 loc) 131 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&&/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)&&o&&!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=128,m=1,x=2,C=3,S=4,N=5,T=6,v=l||c||d?" ":"​",k="\n\n",E=i?" ":v,b="֑-߿יִ-﷽ﹰ-ﻼ",O="A-Za-zÀ-ÖØ-öø-ʸ̀-֐ࠀ-῿‎Ⰰ-﬜︀-﹯﻽-￿",M=new RegExp("^[^"+O+"]*["+b+"]"),A=new RegExp("^[^"+b+"]*["+O+"]"),w={bold:1,capitalize:1024,code:16,highlight:y,italic:2,lowercase:256,strikethrough:4,subscript:32,superscript:64,underline:8,uppercase:512},D={directionless:1,unmergeable:2},P={center:2,end:6,justify:4,left:1,right:3,start:5},I={[x]:"center",[T]:"end",[S]:"justify",[m]:"left",[C]:"right",[N]:"start"},L={normal:0,segmented:2,token:1},F={[g]:"normal",[p]:"segmented",[_]:"token"},R="$config";function K(t,e,n,r,o,i){let s=t.getFirstChild();for(;null!==s;){const t=s.__key;s.__parent===e&&(Zr(s)&&K(s,t,n,r,o,i),n.has(t)||i.delete(t),o.push(t)),s=s.getNextSibling()}}let B=!1,z=0;function W(t){z=t.timeStamp}function $(t,e,n){const r="BR"===t.nodeName,o=e.__lexicalLineBreak;return o&&(t===o||r&&t.previousSibling===o)||r&&void 0!==Uo(t,n)}function U(t,e,n){const r=Ii(ki(n));let o=null,i=null;null!==r&&r.anchorNode===t&&(o=r.anchorOffset,i=r.focusOffset);const s=t.nodeValue;null!==s&&ni(e,s,o,i,!1)}function J(t,e,n){if(tr(t)){const e=t.anchor.getNode();if(e.is(n)&&t.format!==e.getFormat())return!1}return Do(e)&&n.isAttached()}function Y(t,e,n,r){for(let o=t;o&&!Vi(o);o=xi(o)){const t=Uo(o,e);if(void 0!==t){const e=Wo(t,n);if(e)return no(e)||!Fi(o)?void 0:[o,e]}else if(o===r)return[r,Vo(n)]}}function j(t,e,n){B=!0;const r=performance.now()-z>100;try{Gr(t,()=>{const o=pr()||function(t){return t.getEditorState().read(()=>{const t=pr();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,_=Y(g,t,c,l);if(!_)continue;const[p,y]=_;if("characterData"===h)r&&Jn(y)&&Do(g)&&J(o,g,y)&&U(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=$o(r),s=r.parentNode;if(null!=s&&r!==a&&null===o&&!$(r,s,t)){if(i){const t=(Fi(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];($(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,o=n.target;for(let e=0;e<r.length;e++){const n=r[e],i=n.parentNode;null==i||"BR"!==n.nodeName||$(n,o,t)||i.removeChild(n)}}n.takeRecords()}null!==o&&(u&&Go(o),i&&_i(t)&&o.insertRawText(f))})}finally{B=!1}}function H(t){const e=t._observer;if(null!==e){j(t,e.takeRecords(),e)}}function V(t){!function(t){0===z&&ki(t).addEventListener("textInput",W,!0)}(t),t._observer=new MutationObserver((e,n)=>{j(t,e,n)})}class G{key;parse;unparse;isEqual;defaultValue;constructor(t,e){this.key=t,this.parse=e.parse.bind(e),this.unparse=(e.unparse||nt).bind(e),this.isEqual=(e.isEqual||Object.is).bind(e),this.defaultValue=this.parse(void 0)}}function q(t,e,n="latest"){const r=("latest"===n?t.getLatest():t).__state;return r?r.getValue(e):e.defaultValue}function X(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}=qi(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 Q{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 et(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 Q(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)}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=et(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 Z(t){const e=t.getWritable(),n=e.__state?e.__state.getWritable(e):new Q(e,tt(e));return e.__state=n,n}function tt(t){return t.__state?t.__state.sharedNodeState:So($i(),t.getType()).sharedNodeState}function et(t){if(t)for(const e in t)return t}function nt(t){return t}function rt(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 ot(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 it(t,e){const n=t.__state;return n&&n.node===t?n.getWritable(e):n}function st(t,e){const n=t.__mode,r=t.__format,o=t.__style,i=e.__mode,s=e.__format,l=e.__style,c=t.__state,a=e.__state;return(null===n||n===i)&&(null===r||r===s)&&(null===o||o===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&&rt(n,t,e)||e&&rt(n,e,t)||t&&ot(n,t,e)||e&&ot(n,e,t))}(c,a))}function lt(t,e){const n=t.mergeWithSibling(e),r=Rr()._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())&&Jn(e)&&e.isSimpleText()&&!e.isUnmergeable();){if(""!==e.__text){if(st(e,r)){r=lt(e,r);break}break}e.remove()}for(;null!==(n=r.getNextSibling())&&Jn(n)&&n.isSimpleText()&&!n.isUnmergeable();){if(""!==n.__text){if(st(r,n)){r=lt(r,n);break}break}n.remove()}}else r.remove()}function at(t){return ut(t.anchor),ut(t.focus),t}function ut(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),Jn(r)){t.set(r.__key,o?r.getTextContentSize():0,"text",!0);break}if(!Zr(r))break;t.set(r.__key,o?r.getChildrenSize():0,"element",!0)}}let ft,dt,ht,gt,_t,pt,yt,mt,xt,Ct,St="",Nt=null,Tt="",vt="",kt=!1,Et=!1;function bt(t,e){const n=yt.get(t);if(null!==e){const n=Jt(t);n.parentNode===e&&e.removeChild(n)}if(mt.has(t)||dt._keyToDOMMap.delete(t),Zr(n)){const t=Bt(n,yt);Ot(t,0,t.length-1,null)}void 0!==n&&di(Ct,ht,gt,n,"destroyed")}function Ot(t,e,n,r){let o=e;for(;o<=n;++o){const e=t[o];void 0!==e&&bt(e,r)}}function Mt(t,e){t.setProperty("text-align",e)}const At="40px";function wt(t,e){const n=ft.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")||At;t.style.setProperty("padding-inline-start",0===e?"":`calc(${e} * ${r})`)}function Dt(t,e){const n=t.style;0===e?Mt(n,""):1===e?Mt(n,"left"):2===e?Mt(n,"center"):3===e?Mt(n,"right"):4===e?Mt(n,"justify"):5===e?Mt(n,"start"):6===e&&Mt(n,"end")}function Pt(t,e){const n=function(t){const e=t.__dir;if(null!==e)return e;if(oo(t))return null;const n=t.getParentOrThrow();return oo(n)&&null===n.__dir?"auto":null}(e);null!==n?t.dir=n:t.removeAttribute("dir")}function It(e,n){const r=mt.get(e);void 0===r&&t(60);const o=r.createDOM(ft,dt);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,dt),Jn(r)?o.setAttribute("data-lexical-text","true"):no(r)&&o.setAttribute("data-lexical-decorator","true"),Zr(r)){const t=r.__indent,e=r.__size;if(Pt(o,r),0!==t&&wt(o,t),0!==e){const t=e-1;Lt(Bt(r,mt),r,0,t,r.getDOMSlot(o))}const n=r.__format;0!==n&&Dt(o,n),r.isInline()||Rt(null,r,o),yi(r)&&(St+=k,vt+=k)}else{const t=r.getTextContent();if(no(r)){const t=r.decorate(dt,ft);null!==t&&Wt(e,t),o.contentEditable="false"}St+=t,vt+=t}return null!==n&&n.insertChild(o),di(Ct,ht,gt,r,"created"),o}function Lt(t,e,n,r,o){const i=St;St="";let s=n;for(;s<=r;++s){It(t[s],o);const e=mt.get(t[s]);null!==e&&Jn(e)&&(null===Nt&&(Nt=e.getFormat()),""===Tt&&(Tt=e.getStyle()))}yi(e)&&(St+=k);o.element.__lexicalTextContent=St,St=i+St}function Ft(t,e){if(t){const n=t.__last;if(n){const t=e.get(n);if(t)return En(t)?"line-break":no(t)&&t.isInline()?"decorator":null}return"empty"}return null}function Rt(t,e,n){const r=Ft(t,yt),o=Ft(e,mt);r!==o&&e.getDOMSlot(n).setManagedLineBreak(o)}function Kt(e,n,r){var o;Nt=null,Tt="",function(e,n,r){const o=St,i=e.__size,s=n.__size;St="";const l=r.element;if(1===i&&1===s){const t=e.__first,r=n.__first;if(t===r)zt(t,l);else{const e=Jt(t),n=It(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}bt(t,null)}const o=mt.get(r);Jn(o)&&(null===Nt&&(Nt=o.getFormat()),""===Tt&&(Tt=o.getStyle()))}else{const o=Bt(e,yt),c=Bt(n,mt);if(o.length!==i&&t(227),c.length!==s&&t(228),0===i)0!==s&&Lt(c,n,0,s-1,r);else if(0===s){if(0!==i){const t=null==r.after&&null==r.before&&null==r.element.__lexicalLineBreak;Ot(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 c,a,u=i.getFirstChild(),f=0,d=0;for(;f<=s&&d<=l;){const t=e[f],r=n[d];if(t===r)u=$t(zt(r,i.element)),f++,d++;else{void 0===c&&(c=new Set(e)),void 0===a&&(a=new Set(n));const o=a.has(t),s=c.has(r);if(o)if(s){const t=mi(dt,r);t===u?u=$t(zt(r,i.element)):(i.withBefore(u).insertChild(t),zt(r,i.element)),f++,d++}else It(r,i.withBefore(u)),d++;else u=$t(Jt(t)),bt(t,i.element),f++}const o=mt.get(r);null!==o&&Jn(o)&&(null===Nt&&(Nt=o.getFormat()),""===Tt&&(Tt=o.getStyle()))}const h=f>s,g=d>l;if(h&&!g){const e=n[l+1],r=void 0===e?null:dt.getElementByKey(e);Lt(n,t,d,l,i.withBefore(r))}else g&&!h&&Ot(e,f,s,i.element)}(n,o,c,i,s,r)}yi(n)&&(St+=k);l.__lexicalTextContent=St,St=o+St}(e,n,n.getDOMSlot(r)),o=n,null==Nt||Nt===o.__textFormat||Et||o.setTextFormat(Nt),function(t){""===Tt||Tt===t.__textStyle||Et||t.setTextStyle(Tt)}(n)}function Bt(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 zt(e,n){const r=yt.get(e);let o=mt.get(e);void 0!==r&&void 0!==o||t(61);const i=kt||pt.has(e)||_t.has(e),s=mi(dt,e);if(r===o&&!i){if(Zr(r)){const t=s.__lexicalTextContent;void 0!==t&&(St+=t,vt+=t)}else{const t=r.getTextContent();vt+=t,St+=t}return s}if(r!==o&&i&&di(Ct,ht,gt,o,"updated"),o.updateDOM(r,s,ft)){const r=It(e,null);return null===n&&t(62),n.replaceChild(r,s),bt(e,null),r}if(Zr(r)&&Zr(o)){const t=o.__indent;(kt||t!==r.__indent)&&wt(s,t);const e=o.__format;if((kt||e!==r.__format)&&Dt(s,e),i&&(Kt(r,o,s),oo(o)||o.isInline()||Rt(r,o,s)),yi(o)&&(St+=k,vt+=k),(kt||o.__dir!==r.__dir)&&(Pt(s,o),oo(o)&&!kt))for(const t of o.getChildren())if(Zr(t)){Pt(mi(dt,t.getKey()),t)}}else{const t=o.getTextContent();if(no(o)){const t=o.decorate(dt,ft);null!==t&&Wt(e,t)}St+=t,vt+=t}if(!Et&&oo(o)&&o.__cachedText!==vt){const t=o.getWritable();t.__cachedText=vt,o=t}return s}function Wt(t,e){let n=dt._pendingDecorators;const r=dt._decorators;if(null===n){if(r[t]===e)return;n=Yo(dt)}n[t]=e}function $t(t){let e=t.nextSibling;return null!==e&&e===dt._blockCursorElement&&(e=e.nextSibling),e}function Ut(t,e,n,r,o,i){St="",vt="",kt=2===r,dt=n,ft=n._config,ht=n._nodes,gt=dt._listeners.mutation,_t=o,pt=i,yt=t._nodeMap,mt=e._nodeMap,Et=e._readOnly,xt=new Map(n._keyToDOMMap);const s=new Map;return Ct=s,zt("root",null),dt=void 0,ht=void 0,_t=void 0,pt=void 0,yt=void 0,mt=void 0,ft=void 0,xt=void 0,Ct=void 0,s}function Jt(e){const n=xt.get(e);return void 0===n&&t(75,e),n}function Yt(t){return{type:t}}const jt=Yt("SELECTION_CHANGE_COMMAND"),Ht=Yt("SELECTION_INSERT_CLIPBOARD_NODES_COMMAND"),Vt=Yt("CLICK_COMMAND"),Gt=Yt("DELETE_CHARACTER_COMMAND"),qt=Yt("INSERT_LINE_BREAK_COMMAND"),Xt=Yt("INSERT_PARAGRAPH_COMMAND"),Qt=Yt("CONTROLLED_TEXT_INSERTION_COMMAND"),Zt=Yt("PASTE_COMMAND"),te=Yt("REMOVE_TEXT_COMMAND"),ee=Yt("DELETE_WORD_COMMAND"),ne=Yt("DELETE_LINE_COMMAND"),re=Yt("FORMAT_TEXT_COMMAND"),oe=Yt("UNDO_COMMAND"),ie=Yt("REDO_COMMAND"),se=Yt("KEYDOWN_COMMAND"),le=Yt("KEY_ARROW_RIGHT_COMMAND"),ce=Yt("MOVE_TO_END"),ae=Yt("KEY_ARROW_LEFT_COMMAND"),ue=Yt("MOVE_TO_START"),fe=Yt("KEY_ARROW_UP_COMMAND"),de=Yt("KEY_ARROW_DOWN_COMMAND"),he=Yt("KEY_ENTER_COMMAND"),ge=Yt("KEY_SPACE_COMMAND"),_e=Yt("KEY_BACKSPACE_COMMAND"),pe=Yt("KEY_ESCAPE_COMMAND"),ye=Yt("KEY_DELETE_COMMAND"),me=Yt("KEY_TAB_COMMAND"),xe=Yt("INSERT_TAB_COMMAND"),Ce=Yt("INDENT_CONTENT_COMMAND"),Se=Yt("OUTDENT_CONTENT_COMMAND"),Ne=Yt("DROP_COMMAND"),Te=Yt("FORMAT_ELEMENT_COMMAND"),ve=Yt("DRAGSTART_COMMAND"),ke=Yt("DRAGOVER_COMMAND"),Ee=Yt("DRAGEND_COMMAND"),be=Yt("COPY_COMMAND"),Oe=Yt("CUT_COMMAND"),Me=Yt("SELECT_ALL_COMMAND"),Ae=Yt("CLEAR_EDITOR_COMMAND"),we=Yt("CLEAR_HISTORY_COMMAND"),De=Yt("CAN_REDO_COMMAND"),Pe=Yt("CAN_UNDO_COMMAND"),Ie=Yt("FOCUS_COMMAND"),Le=Yt("BLUR_COMMAND"),Fe=Yt("KEY_MODIFIER_COMMAND"),Re=Object.freeze({}),Ke=[["keydown",function(t,e){if(Be=t.timeStamp,ze=t.key,e.isComposing())return;if(pi(e,se,t))return;if(null==t.key)return;if(Ge&&ai(t))return Gr(e,()=>{sn(e,qe)}),Ge=!1,void(qe="");if(function(t){return si(t,"ArrowRight",{shiftKey:"any"})}(t))pi(e,le,t);else if(function(t){return si(t,"ArrowRight",li)}(t))pi(e,ce,t);else if(function(t){return si(t,"ArrowLeft",{shiftKey:"any"})}(t))pi(e,ae,t);else if(function(t){return si(t,"ArrowLeft",li)}(t))pi(e,ue,t);else if(function(t){return si(t,"ArrowUp",{altKey:"any",shiftKey:"any"})}(t))pi(e,fe,t);else if(function(t){return si(t,"ArrowDown",{altKey:"any",shiftKey:"any"})}(t))pi(e,de,t);else if(function(t){return si(t,"Enter",{altKey:"any",ctrlKey:"any",metaKey:"any",shiftKey:!0})}(t))He=!0,pi(e,he,t);else if(function(t){return" "===t.key}(t))pi(e,ge,t);else if(function(t){return o&&si(t,"o",{ctrlKey:!0})}(t))t.preventDefault(),He=!0,pi(e,qt,!0);else if(function(t){return si(t,"Enter",{altKey:"any",ctrlKey:"any",metaKey:"any"})}(t))He=!1,pi(e,he,t);else if(function(t){return si(t,"Backspace",{shiftKey:"any"})||o&&si(t,"h",{ctrlKey:!0})}(t))ai(t)?pi(e,_e,t):(t.preventDefault(),pi(e,Gt,!0));else if(function(t){return"Escape"===t.key}(t))pi(e,pe,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(),pi(e,Gt,!1)):pi(e,ye,t);else if(function(t){return si(t,"Backspace",ci)}(t))t.preventDefault(),pi(e,ee,!0);else if(function(t){return si(t,"Delete",ci)}(t))t.preventDefault(),pi(e,ee,!1);else if(function(t){return o&&si(t,"Backspace",{metaKey:!0})}(t))t.preventDefault(),pi(e,ne,!0);else if(function(t){return o&&(si(t,"Delete",{metaKey:!0})||si(t,"k",{ctrlKey:!0}))}(t))t.preventDefault(),pi(e,ne,!1);else if(function(t){return si(t,"b",li)}(t))t.preventDefault(),pi(e,re,"bold");else if(function(t){return si(t,"u",li)}(t))t.preventDefault(),pi(e,re,"underline");else if(function(t){return si(t,"i",li)}(t))t.preventDefault(),pi(e,re,"italic");else if(function(t){return si(t,"Tab",{shiftKey:"any"})}(t))pi(e,me,t);else if(function(t){return si(t,"z",li)}(t))t.preventDefault(),pi(e,oe,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(),pi(e,ie,void 0);else{const n=e._editorState._selection;null===n||tr(n)?ui(t)&&(t.preventDefault(),pi(e,Me,t)):!function(t){return si(t,"c",li)}(t)?!function(t){return si(t,"x",li)}(t)?ui(t)&&(t.preventDefault(),pi(e,Me,t)):(t.preventDefault(),pi(e,Oe,t)):(t.preventDefault(),pi(e,be,t))}(function(t){return t.ctrlKey||t.shiftKey||t.altKey||t.metaKey})(t)&&pi(e,Fe,t)}],["pointerdown",function(t,e){const n=t.target,r=t.pointerType;Ri(n)&&"touch"!==r&&"pen"!==r&&0===t.button&&Gr(e,()=>{vo(n)||(je=!0)})}],["compositionstart",function(t,e){Gr(e,()=>{const n=pr();if(tr(n)&&!e.isComposing()){const r=n.anchor,o=n.anchor.getNode();Bo(r.key),(t.timeStamp<Be+30||"element"===r.type||!n.isCollapsed()||o.getFormat()!==n.format||Jn(o)&&o.getStyle()!==n.style)&&pi(e,Qt,E)}})}],["compositionend",function(t,e){i?Ve=!0:c||!l&&!d?Gr(e,()=>{sn(e,t.data)}):(Ge=!0,qe=t.data)}],["input",function(t,e){t.stopPropagation(),Gr(e,()=>{if(Fi(t.target)&&vo(t.target))return;const n=pr(),r=t.data,o=on(t);if(null!=r&&tr(n)&&Ze(n,o,r,t.timeStamp,!1)){Ve&&(sn(e,r),Ve=!1);const o=n.anchor.getNode(),a=Ii(ki(e));if(null===a)return;const u=n.isBackward(),f=u?n.anchor.offset:n.focus.offset,h=u?n.focus.offset:n.anchor.offset;s&&!n.isCollapsed()&&Jn(o)&&null!==a.anchorNode&&o.getTextContent().slice(0,f)+r+o.getTextContent().slice(f+h)===ti(a.anchorNode)||pi(e,Qt,r);const g=r.length;i&&g>1&&"insertCompositionText"===t.inputType&&!e.isComposing()&&(n.anchor.offset-=g),l||c||d||!e.isComposing()||(Be=0,Bo(null))}else{ei(!1,e,null!==r?r:void 0),Ve&&(sn(e,r||void 0),Ve=!1)}!function(){Ir();const t=Rr();H(t)}()},{event:t}),$e=null}],["click",function(t,e){Gr(e,()=>{const n=pr(),r=Ii(ki(e)),o=yr();if(r)if(tr(n)){const e=n.anchor,i=e.getNode();if("element"===e.type&&0===e.offset&&n.isCollapsed()&&!oo(i)&&1===Ho().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=Xi(i,t=>Zr(t)&&!t.isInline());Zr(t)&&t.select(0)}}}else if("touch"===t.pointerType||"pen"===t.pointerType){const n=r.anchorNode;if(Fi(n)||Do(n)){Go(_r(o,r,e,t))}}pi(e,Vt,t)})}],["cut",Re],["copy",Re],["dragstart",Re],["dragover",Re],["dragend",Re],["paste",Re],["focus",Re],["blur",Re],["drop",Re]];s&&Ke.push(["beforeinput",(e,n)=>function(e,n){const r=e.inputType,o=on(e);if("deleteCompositionText"===r||i&&_i(n))return;if("insertCompositionText"===r)return;Gr(n,()=>{const i=pr();if("deleteContentBackward"===r){if(null===i){const t=yr();if(!tr(t))return;Go(t.clone())}if(tr(i)){const r=i.anchor.key===i.focus.key;if(s=e.timeStamp,"MediaLast"===ze&&s<Be+30&&n.isComposing()&&r){if(Bo(null),Be=0,setTimeout(()=>{Gr(n,()=>{Bo(null)})},30),tr(i)){const e=i.anchor.getNode();e.markDirty(),Jn(e)||t(142),rn(i,e)}}else{Bo(null),e.preventDefault();const t=i.anchor.getNode(),o=t.getTextContent(),s=t.canInsertTextAfter(),l=0===i.anchor.offset&&i.focus.offset===o.length;let c=f&&r&&!l&&s;if(c&&i.isCollapsed()&&(c=!no(gi(i.anchor,!0))),!c){pi(n,Gt,!0);const t=pr();f&&tr(t)&&t.isCollapsed()&&(Xe=t,setTimeout(()=>Xe=null))}}return}}var s;if(!tr(i))return;const l=e.data;null!==$e&&ei(!1,n,$e),i.dirty&&null===$e||!i.isCollapsed()||oo(i.anchor.getNode())||null===o||i.applyDOMRange(o),$e=null;const a=i.anchor,u=i.focus,d=a.getNode(),h=u.getNode();if("insertText"!==r&&"insertTranspose"!==r)switch(e.preventDefault(),r){case"insertFromYank":case"insertFromDrop":case"insertReplacementText":pi(n,Qt,e);break;case"insertFromComposition":Bo(null),pi(n,Qt,e);break;case"insertLineBreak":Bo(null),pi(n,qt,!1);break;case"insertParagraph":Bo(null),He&&!c?(He=!1,pi(n,qt,!1)):pi(n,Xt,void 0);break;case"insertFromPaste":case"insertFromPasteAsQuotation":pi(n,Zt,e);break;case"deleteByComposition":(function(t,e){return t!==e||Zr(t)||Zr(e)||!Ao(t)||!Ao(e)})(d,h)&&pi(n,te,e);break;case"deleteByDrag":case"deleteByCut":pi(n,te,e);break;case"deleteContent":pi(n,Gt,!1);break;case"deleteWordBackward":pi(n,ee,!0);break;case"deleteWordForward":pi(n,ee,!1);break;case"deleteHardLineBackward":case"deleteSoftLineBackward":pi(n,ne,!0);break;case"deleteContentForward":case"deleteHardLineForward":case"deleteSoftLineForward":pi(n,ne,!1);break;case"formatStrikeThrough":pi(n,re,"strikethrough");break;case"formatBold":pi(n,re,"bold");break;case"formatItalic":pi(n,re,"italic");break;case"formatUnderline":pi(n,re,"underline");break;case"historyUndo":pi(n,oe,void 0);break;case"historyRedo":pi(n,ie,void 0)}else{if("\n"===l)e.preventDefault(),pi(n,qt,!1);else if(l===k)e.preventDefault(),pi(n,Xt,void 0);else if(null==l&&e.dataTransfer){const t=e.dataTransfer.getData("text/plain");e.preventDefault(),i.insertRawText(t)}else null!=l&&Ze(i,o,l,e.timeStamp,!0)?(e.preventDefault(),pi(n,Qt,l)):$e=l;We=e.timeStamp}})}(e,n)]);let Be=0,ze=null,We=0,$e=null;const Ue=new WeakMap,Je=new WeakMap;let Ye=!1,je=!1,He=!1,Ve=!1,Ge=!1,qe="",Xe=null,Qe=[0,"",0,"root",0];function Ze(t,e,n,r,o){const i=t.anchor,l=t.focus,c=i.getNode(),a=Rr(),u=Ii(ki(a)),f=null!==u?u.anchorNode:null,d=i.key,h=a.getElementByKey(d),g=n.length;return d!==l.key||!Jn(c)||(!o&&(!s||We<r+50)||c.isDirty()&&g<2||Xo(n))&&i.offset!==l.offset&&!c.isComposing()||wo(c)||c.isDirty()&&g>1||(o||!s)&&null!==h&&!c.isComposing()&&f!==Io(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(),o=Ao(e);return 0===n?!e.canInsertTextBefore()||!r.canInsertTextBefore()&&!e.isComposing()||o||function(t){const e=t.getPreviousSibling();return(Jn(e)||Zr(e)&&e.isInline())&&!e.canInsertTextAfter()}(e):n===e.getTextContentSize()&&(!e.canInsertTextAfter()||!r.canInsertTextAfter()&&!e.isComposing()||o)}(t,c)}function tn(t,e){return Do(t)&&null!==t.nodeValue&&0!==e&&e!==t.nodeValue.length}function en(e,n,r){const{anchorNode:o,anchorOffset:i,focusNode:s,focusOffset:l}=e;Ye&&(Ye=!1,tn(o,i)&&tn(s,l)&&!Xe)||Gr(n,()=>{if(!r)return void Go(null);if(!Eo(n,o,s))return;let c=pr();if(Xe&&tr(c)&&c.isCollapsed()){const t=c.anchor,e=Xe.anchor;(t.key===e.key&&t.offset===e.offset+1||1===t.offset&&e.getNode().is(t.getNode().getPreviousSibling()))&&(c=Xe.clone(),Go(c))}if(Xe=null,tr(c)){const r=c.anchor,o=r.getNode();if(c.isCollapsed()){"Range"===e.type&&e.anchorNode===e.focusNode&&(c.dirty=!0);const i=ki(n).event,s=i?i.timeStamp:performance.now(),[l,a,u,f,d]=Qe,h=Ho(),g=!1===n.isComposing()&&""===h.getTextContent();if(s<d+200&&r.offset===u&&r.key===f)nn(c,l,a);else if("text"===r.type)Jn(o)||t(141),rn(c,o);else if("element"===r.type&&!g){Zr(o)||t(259);const e=r.getNode();e.isEmpty()?function(t,e){const n=e.getTextFormat(),r=e.getTextStyle();nn(t,n,r)}(c,e):nn(c,0,"")}}else{const t=r.key,e=c.focus.key,n=c.getNodes(),o=n.length,s=c.isBackward(),a=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(Jn(e)&&0!==r&&!(0===t&&e.__key===f&&a===r||t===o-1&&e.__key===d&&0===u)&&(g=!0,h&=e.getFormat(),0===h))break}c.format=g?h:0}}pi(n,jt,void 0)})}function nn(t,e,n){t.format===e&&t.style===n||(t.format=e,t.style=n,t.dirty=!0)}function rn(t,e){nn(t,e.getFormat(),e.getStyle())}function on(t){if(!t.getTargetRanges)return null;const e=t.getTargetRanges();return 0===e.length?null:e[0]}function sn(t,e){const n=t._compositionKey;if(Bo(null),null!==n&&null!=e){if(""===e){const e=Wo(n),r=Io(t.getElementByKey(n));return void(null!==r&&null!==r.nodeValue&&Jn(e)&&ni(e,r.nodeValue,null,null,!0))}if("\n"===e[e.length-1]){const e=pr();if(tr(e)){const n=e.focus;return e.anchor.set(n.key,n.offset,n.type),void pi(t,he,null)}}}ei(!0,t,e)}function ln(t){let e=t.__lexicalEventHandles;return void 0===e&&(e=[],t.__lexicalEventHandles=e),e}const cn=new Map;function an(t){const e=Li(t.target);if(null===e)return;const n=Oo(e.anchorNode);if(null===n)return;je&&(je=!1,Gr(n,()=>{const r=yr(),o=e.anchorNode;if(Fi(o)||Do(o)){Go(_r(r,e,n,t))}}));const r=Qo(n),o=r[r.length-1],i=o._key,s=cn.get(i),l=s||o;l!==n&&en(e,l,!1),en(e,n,!0),n!==o?cn.set(i,n):s&&cn.delete(i)}function un(t){t._lexicalHandled=!0}function fn(t){return!0===t._lexicalHandled}const dn=()=>{};function hn(e){const n=Ue.get(e);if(void 0===n)return void dn();const r=Je.get(n);if(void 0===r)return void dn();const o=r-1;o>=0||t(164),Ue.delete(e),Je.set(n,o),0===o&&n.removeEventListener("selectionchange",an);const i=Mo(e);bo(i)?(!function(t){if(null!==t._parentEditor){const e=Qo(t),n=e[e.length-1]._key;cn.get(n)===t&&cn.delete(n)}else cn.delete(t._key)}(i),e.__lexicalEditor=null):i&&t(198);const s=ln(e);for(let t=0;t<s.length;t++)s[t]();e.__lexicalEventHandles=[]}function gn(t,e,n){Ir();const r=t.__key,o=t.getParent();if(null===o)return;const i=function(t){const e=pr();if(!tr(e)||!Zr(t))return e;const{anchor:n,focus:r}=e,o=n.getNode(),i=r.getNode();Ti(o,t)&&n.set(t.__key,0,"element");Ti(i,t)&&r.set(t.__key,0,"element");return e}(t);let s=!1;if(tr(i)&&e){const e=i.anchor,n=i.focus;e.key===r&&(Cr(e,t,o,t.getPreviousSibling(),t.getNextSibling()),s=!0),n.key===r&&(Cr(n,t,o,t.getPreviousSibling(),t.getNextSibling()),s=!0)}else nr(i)&&e&&t.isSelected()&&t.selectPrevious();if(tr(i)&&e&&!s){const e=t.getIndexWithinParent();Ro(t),mr(i,o,e,-1)}else Ro(t);n||bi(o)||o.canBeEmpty()||!o.isEmpty()||gn(o,e),e&&i&&oo(o)&&o.isEmpty()&&o.selectEnd()}const _n=Symbol.for("ephemeral");function pn(t){return t[_n]||!1}class yn{__type;__key;__parent;__prev;__next;__state;static getType(){const{ownNodeType:e}=qi(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}),Fo(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=Wo(t);if(null===e)break;t=e.__parent}return!1}isSelected(t){const e=t||pr();if(null==e)return!1;const n=e.getNodes().some(t=>t.__key===this.__key);if(Jn(this))return n;if(tr(e)&&"element"===e.anchor.type&&"element"===e.focus.type){if(e.isCollapsed())return!1;const t=this.getParent();if(no(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:Wo(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(bi(n))return Zr(e)||e===this&&no(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:Wo(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:Wo(t)}getNextSiblings(){const t=[];let e=this.getNextSibling();for(;null!==e;)t.push(e),e=e.getNextSibling();return t}getCommonAncestor(t){const e=Zr(this)?this:this.getParent(),n=Zr(t)?t:t.getParent(),r=e&&n?Ms(e,n):null;return r?r.commonAncestor:null}is(t){return null!=t&&this.__key===t.__key}isBefore(e){const n=Ms(this,e);return null!==n&&("descendant"===n.type||("branch"===n.type?-1===Es(n):("same"!==n.type&&"ancestor"!==n.type&&t(279),!1)))}isParentOf(t){const e=Ms(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=Zr(i)?n?i.getFirstChild():i.getLastChild():null;if(null!==l){i=l;continue}const c=n?i.getNextSibling():i.getPreviousSibling();if(null!==c){i=c;continue}const a=i.getParentOrThrow();if(o.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||o.has(f.__key)||r.push(f)}while(null===u);i=u}return n||r.reverse(),r}isDirty(){const t=Rr()._dirtyLeaves;return null!==t&&t.has(this.__key)}getLatest(){if(pn(this))return this;const e=Wo(this.__key);return null===e&&t(113),e}getWritable(){if(pn(this))return this;Ir();const t=Fr(),e=Rr(),n=t._nodeMap,r=this.__key,o=this.getLatest(),i=e._cloneNotNeeded,s=pr();if(null!==s&&s.setCachedNodes(null),i.has(r))return Ko(o),o;const l=ji(o);return i.add(r),Ko(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 tt(n).flatKeys)t in e&&(void 0!==o&&o!==r||(o={...r}),o[t]=e[t]);return(n.__state||o)&&Z(t).updateFromJSON(o),n}(this,t)}static transform(){return null}remove(t){gn(this,!0,t)}replace(e,n){Ir();let r=pr();null!==r&&(r=r.clone()),Ai(this,e);const o=this.getLatest(),i=this.__key,s=e.__key,l=e.getWritable(),c=this.getParentOrThrow().getWritable(),a=c.__size;Ro(l);const u=o.getPreviousSibling(),f=o.getNextSibling(),d=o.__prev,h=o.__next,g=o.__parent;if(gn(o,!1,!0),null===u)c.__first=s;else{u.getWritable().__next=s}if(l.__prev=d,null===f)c.__last=s;else{f.getWritable().__prev=s}if(l.__next=h,l.__parent=g,c.__size=a,n&&(Zr(this)&&Zr(l)||t(139),this.getChildren().forEach(t=>{l.append(t)})),tr(r)){Go(r);const t=r.anchor,e=r.focus;t.key===i&&Qn(t,l),e.key===i&&Qn(e,l)}return zo()===i&&Bo(s),l}insertAfter(t,e=!0){Ir(),Ai(this,t);const n=this.getWritable(),r=t.getWritable(),o=r.getParent(),i=pr();let s=!1,l=!1;if(null!==o){const e=t.getIndexWithinParent();if(Ro(r),tr(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 c=this.getNextSibling(),a=this.getParentOrThrow().getWritable(),u=r.__key,f=n.__next;if(null===c)a.__last=u;else{c.getWritable().__prev=u}if(a.__size++,n.__next=u,r.__next=f,r.__prev=n.__key,r.__parent=n.__parent,e&&tr(i)){const t=this.getIndexWithinParent();mr(i,a,t+1);const e=a.__key;s&&i.anchor.set(e,t+2,"element"),l&&i.focus.set(e,t+2,"element")}return t}insertBefore(t,e=!0){Ir(),Ai(this,t);const n=this.getWritable(),r=t.getWritable(),o=r.__key;Ro(r);const i=this.getPreviousSibling(),s=this.getParentOrThrow().getWritable(),l=n.__prev,c=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 a=pr();if(e&&tr(a)){mr(a,this.getParentOrThrow(),c)}return t}isParentRequired(){return!1}createParentElementNode(){return ho()}selectStart(){return this.selectPrevious()}selectEnd(){return this.selectNext(0,0)}selectPrevious(t,e){Ir();const n=this.getPreviousSibling(),r=this.getParentOrThrow();if(null===n)return r.select(0,0);if(Zr(n))return n.select();if(!Jn(n)){const t=n.getIndexWithinParent()+1;return r.select(t,t)}return n.select(t,e)}selectNext(t,e){Ir();const n=this.getNextSibling(),r=this.getParentOrThrow();if(null===n)return r.select();if(Zr(n))return n.select(0,0);if(!Jn(n)){const t=n.getIndexWithinParent();return r.select(t,t)}return n.select(t,e)}markDirty(){this.getWritable()}reconcileObservedMutation(t,e){this.markDirty()}}const mn="history-merge",xn="collaboration",Cn="skip-scroll-into-view",Sn="skip-dom-selection",Nn="skip-selection-focus";class Tn extends yn{static getType(){return"linebreak"}static clone(t){return new Tn(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&&zi(e)){const n=e.firstChild;if(n===t||n.nextSibling===t&&bn(n)){const n=e.lastChild;if(n===t||n.previousSibling===t&&bn(n))return!0}}return!1}(t)||function(t){const e=t.parentElement;if(null!==e&&zi(e)){const n=e.firstChild;if(n===t||n.nextSibling===t&&bn(n))return!1;const r=e.lastChild;if(r===t||r.previousSibling===t&&bn(r))return!0}return!1}(t)?null:{conversion:vn,priority:0}}}static importJSON(t){return kn().updateFromJSON(t)}}function vn(t){return{node:kn()}}function kn(){return Mi(new Tn)}function En(t){return t instanceof Tn}function bn(t){return Do(t)&&/^( |\t|\r?\n)+$/.test(t.textContent||"")}function On(t,e){return 16&e?"code":e&y?"mark":32&e?"sub":64&e?"sup":null}function Mn(t,e){return 1&e?"strong":2&e?"em":"span"}function An(t,e,n,r,o){const i=r.classList;let s=fi(o,"base");void 0!==s&&i.add(...s),s=fi(o,"underlineStrikethrough");let l=!1;const c=8&e&&4&e;void 0!==s&&(8&n&&4&n?(l=!0,c||i.add(...s)):c&&i.remove(...s));for(const t in w){const r=w[t];if(s=fi(o,t),void 0!==s)if(n&r){if(l&&("underline"===t||"strikethrough"===t)){e&r&&i.remove(...s);continue}(0===(e&r)||c&&"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?v:"");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 Dn(t,e,n,r,o,i){wn(o,t,e);const s=i.theme.text;void 0!==s&&An(0,0,r,t,s)}function Pn(t,e){const n=document.createElement(e);return n.appendChild(t),n}class In extends yn{__text;__format;__style;__mode;__detail;static getType(){return"text"}static clone(t){return new In(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===zo()}isSegmented(){return 2===this.getLatest().__mode}isDirectionless(){return!!(1&this.getLatest().__detail)}isUnmergeable(){return!!(2&this.getLatest().__detail)}hasFormat(t){const e=w[t];return 0!==(this.getFormat()&e)}isSimpleText(){return"text"===this.__type&&0===this.__mode}getTextContent(){return this.getLatest().__text}getFormatFlags(t,e){return Lo(this.getLatest().__format,t,e)}canHaveFormat(){return!0}isInline(){return!0}createDOM(t,e){const n=this.__format,r=On(0,n),o=Mn(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));Dn(l,this,0,n,this.__text,t);const c=this.__style;return""!==c&&(s.style.cssText=c),s}updateDOM(e,n,r){const o=this.__text,i=e.__format,s=this.__format,l=On(0,i),c=On(0,s),a=Mn(0,i),u=Mn(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 i=document.createElement(u);return Dn(i,this,0,s,o,r),n.replaceChild(i,e),!1}let f=n;null!==c&&null!==l&&(f=n.firstChild,null==f&&t(49)),wn(o,f,this);const d=r.theme.text;void 0!==d&&i!==s&&An(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:Bn,priority:0}),b:()=>({conversion:Fn,priority:0}),code:()=>({conversion:$n,priority:0}),em:()=>({conversion:$n,priority:0}),i:()=>({conversion:$n,priority:0}),mark:()=>({conversion:$n,priority:0}),s:()=>({conversion:$n,priority:0}),span:()=>({conversion:Ln,priority:0}),strong:()=>({conversion:$n,priority:0}),sub:()=>({conversion:$n,priority:0}),sup:()=>({conversion:$n,priority:0}),u:()=>({conversion:$n,priority:0})}}static importJSON(t){return Un().updateFromJSON(t)}updateFromJSON(t){return super.updateFromJSON(t).setTextContent(t.text).setFormat(t.format).setDetail(t.detail).setMode(t.mode).setStyle(t.style)}exportDOM(e){let{element:n}=super.exportDOM(e);return Fi(n)||t(132),n.style.whiteSpace="pre-wrap",this.hasFormat("lowercase")?n.style.textTransform="lowercase":this.hasFormat("uppercase")?n.style.textTransform="uppercase":this.hasFormat("capitalize")&&(n.style.textTransform="capitalize"),this.hasFormat("bold")&&(n=Pn(n,"b")),this.hasFormat("italic")&&(n=Pn(n,"i")),this.hasFormat("strikethrough")&&(n=Pn(n,"s")),this.hasFormat("underline")&&(n=Pn(n,"u")),{element:n}}exportJSON(){return{detail:this.getDetail(),format:this.getFormat(),mode:this.getMode(),style:this.getStyle(),text:this.getTextContent(),...super.exportJSON()}}selectionTransform(t,e){}setFormat(t){const e=this.getWritable();return e.__format="string"==typeof t?w[t]:t,e}setDetail(t){const e=this.getWritable();return e.__detail="string"==typeof t?D[t]:t,e}setStyle(t){const e=this.getWritable();return e.__style=t,e}toggleFormat(t){const e=Lo(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=L[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){Ir();let n=t,r=e;const o=pr(),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(!tr(o))return dr(s,n,s,r,"text","text");{const t=zo();t!==o.anchor.key&&t!==o.focus.key||Bo(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 c=pr();if(r&&tr(c)){const e=t+s;c.setTextNodeRange(o,e,o,e)}const a=i.slice(0,l)+n+i.slice(l+e);return o.__text=a,o}canInsertTextBefore(){return!0}canInsertTextAfter(){return!0}splitText(...t){Ir();const e=this.getLatest(),n=e.getTextContent();if(""===n)return[];const r=e.__key,o=zo(),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 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=pr();if(tr(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=Un(a),f.__format=d,f.__style=h,f.__detail=g,f.__state=it(e,f),_=!0):f=e.setTextContent(a);const x=[f];for(let t=1;t<c;t++){const n=Un(s[t]);n.__format=d,n.__style=h,n.__detail=g,n.__state=it(e,n);const i=n.__key;o===r&&Bo(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&&Ko(e);null!==n&&Ko(n)}(this);const t=u.getWritable(),e=this.getIndexWithinParent();_?(t.splice(e,0,x),this.remove()):t.splice(e,1,x),tr(m)&&mr(m,u,e,c-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;zo()===o&&Bo(r);const l=pr();if(tr(l)){const t=l.anchor,i=l.focus;null!==t&&t.key===o&&Sr(t,n,r,e,s),null!==i&&i.key===o&&Sr(i,n,r,e,s)}const c=e.__text,a=n?c+i:i+c;this.setTextContent(a);const u=this.getWritable();return e.remove(),u}isTextEntity(){return!1}}function Ln(t){return{forChild:Yn(t.style),node:null}}function Fn(t){const e=t,n="normal"===e.style.fontWeight;return{forChild:Yn(e.style,n?void 0:"bold"),node:null}}const Rn=new WeakMap;function Kn(t){if(!Fi(t))return!1;if("PRE"===t.nodeName)return!0;const e=t.style.whiteSpace;return"string"==typeof e&&e.startsWith("pre")}function Bn(e){const n=e;null===e.parentElement&&t(129);let r=n.textContent||"";if(null!==function(t){let e,n=t.parentNode;const r=[t];for(;null!==n&&void 0===(e=Rn.get(n))&&!Kn(n);)r.push(n),n=n.parentNode;const o=void 0===e?n:e;for(let t=0;t<r.length;t++)Rn.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(kn()):"\t"===n?e.push(Hn()):""!==n&&e.push(Un(n))}return{node:e}}if(r=r.replace(/\r/g,"").replace(/[ \t\n]+/g," "),""===r)return{node:null};if(" "===r[0]){let t=n,e=!0;for(;null!==t&&null!==(t=zn(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=zn(t,!0));){if((t.textContent||"").replace(/^( |\t|\r?\n)+/,"").length>0){e=!1;break}}e&&(r=r.slice(0,r.length-1))}return""===r?{node:null}:{node:Un(r)}}function zn(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,Fi(n)){const t=n.style.display;if(""===t&&!Bi(n)||""!==t&&!t.startsWith("inline"))return null}let r=n;for(;null!==(r=e?n.firstChild:n.lastChild);)n=r;if(Do(n))return n;if("BR"===n.nodeName)return null}}const Wn={code:"code",em:"italic",i:"italic",mark:"highlight",s:"strikethrough",strong:"bold",sub:"subscript",sup:"superscript",u:"underline"};function $n(t){const e=Wn[t.nodeName.toLowerCase()];return void 0===e?{node:null}:{forChild:Yn(t.style,e),node:null}}function Un(t=""){return Mi(new In(t))}function Jn(t){return t instanceof In}function Yn(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"),c=t.verticalAlign;return t=>Jn(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"!==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 jn extends In{static getType(){return"tab"}static clone(t){return new jn(t.__key)}constructor(t){super("\t",t),this.__detail=2}static importDOM(){return null}createDOM(t){const e=super.createDOM(t),n=fi(t.theme,"tab");if(void 0!==n){e.classList.add(...n)}return e}static importJSON(t){return Hn().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 Hn(){return Mi(new jn)}function Vn(t){return t instanceof jn}class Gn{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 ks(Bs(As(this,"next")),Bs(As(t,"next")))<0}getNode(){const e=Wo(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,Pr()||(zo()===i&&Bo(t),null!==o&&(o.setCachedNodes(null),o.dirty=!0)))}}function qn(t,e,n){return new Gn(t,e,n)}function Xn(t,e){let n=e.__key,r=t.offset,o="element";if(Jn(e)){o="text";const t=e.getTextContentSize();r>t&&(r=t)}else if(!Zr(e)){const t=e.getNextSibling();if(Jn(t))n=t.__key,r=0,o="text";else{const t=e.getParent();t&&(n=t.__key,r=e.getIndexWithinParent()+1)}}t.set(n,r,o)}function Qn(t,e){if(Zr(e)){const n=e.getLastDescendant();Zr(n)||Jn(n)?Xn(t,n):Xn(t,e)}else Xn(t,e)}class Zn{_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(!nr(t))return!1;const e=this._nodes,n=t._nodes;return e.size===n.size&&Array.from(e).every(t=>n.has(t))}isCollapsed(){return!1}isBackward(){return!1}getStartEndPoints(){return null}add(t){this.dirty=!0,this._nodes.add(t),this._cachedNodes=null}delete(t){this.dirty=!0,this._nodes.delete(t),this._cachedNodes=null}clear(){this.dirty=!0,this._nodes.clear(),this._cachedNodes=null}has(t){return this._nodes.has(t)}clone(){return new Zn(new Set(this._nodes))}extract(){return this.getNodes()}insertRawText(t){}insertText(){}insertNodes(t){const e=this.getNodes(),n=e.length,r=e[n-1];let o;if(Jn(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=Wo(t);null!==e&&n.push(e)}return Pr()||(this._cachedNodes=n),n}getTextContent(){const t=this.getNodes();let e="";for(let n=0;n<t.length;n++)e+=t[n].getTextContent();return e}deleteNodes(){const t=this.getNodes();if((pr()||yr())===this&&t[0]){const e=ds(t[0],"next");Ds(Ts(e,e))}for(const e of t)e.remove()}}function tr(t){return t instanceof er}class er{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!!tr(t)&&(this.anchor.is(t.anchor)&&this.focus.is(t.focus)&&this.format===t.format&&this.style===t.style)}isCollapsed(){return this.anchor.is(this.focus)}getNodes(){const t=this._cachedNodes;if(null!==t)return t;const e=function(t){const e=[],[n,r]=t.getTextSlices();n&&e.push(n.caret.origin);const o=new Set,i=new Set;for(const n of t)if(cs(n)){const{origin:t}=n;0===e.length?o.add(t):(i.add(t),e.push(t))}else{const{origin:t}=n;Zr(t)&&i.has(t)||e.push(t)}r&&e.push(r.caret.origin);if(ls(t.focus)&&Zr(t.focus.origin)&&null===t.focus.getNodeAtCaret())for(let n=ps(t.focus.origin,"previous");cs(n)&&o.has(n.origin)&&!n.origin.isEmpty()&&n.origin.is(e[e.length-1]);n=ms(n))o.delete(n.origin),e.pop();for(;e.length>1;){const t=e[e.length-1];if(!Zr(t)||i.has(t)||t.isEmpty()||o.has(t))break;e.pop()}if(0===e.length&&t.isCollapsed()){const n=Bs(t.anchor),r=Bs(t.anchor.getFlipped()),o=t=>ss(t)?t.origin:t.getNodeAtCaret(),i=o(n)||o(r)||(t.anchor.getNodeAtCaret()?n.origin:r.origin);e.push(i)}return e}($s(Is(this),"next"));return Pr()||(this._cachedNodes=e),e}setTextNodeRange(t,e,n,r){this.anchor.set(t.__key,e,"text"),this.focus.set(n.__key,r,"text")}getTextContent(){const t=this.getNodes();if(0===t.length)return"";const e=t[0],n=t[t.leng