lexical
Version:
Lexical is an extensible text editor framework that provides excellent reliability, accessible and performance.
9 lines (8 loc) • 138 kB
JavaScript
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
"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,c=n&&/Android/.test(navigator.userAgent),a=n&&/Version\/[\d.]+.*Safari/.test(navigator.userAgent)&&!c,u=n&&/^(?=.*Chrome).*/i.test(navigator.userAgent),f=n&&c&&u,d=n&&/AppleWebKit\/[\d.]+/.test(navigator.userAgent)&&o&&!u,h=0,g=1,_=2,p=128,y=1,m=2,x=3,C=4,S=5,N=6,T=a||l||d?"\xa0":"\u200b",v="\n\n",O=i?"\xa0":T,E="\u0591-\u07ff\ufb1d-\ufdfd\ufe70-\ufefc",k="A-Za-z\xc0-\xd6\xd8-\xf6\xf8-\u02b8\u0300-\u0590\u0800-\u1fff\u200e\u2c00-\ufb1c\ufe00-\ufe6f\ufefd-\uffff",M=new RegExp("^[^"+k+"]*["+E+"]"),b=new RegExp("^[^"+E+"]*["+k+"]"),A={bold:1,capitalize:1024,code:16,highlight:p,italic:2,lowercase:256,strikethrough:4,subscript:32,superscript:64,underline:8,uppercase:512},D={directionless:1,unmergeable:2},w={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"},R="$config";class L{_front=new Set;_back=new Set;_cache;get size(){return this._front.size+this._back.size}addBack(t){return delete this._cache,this._front.has(t)||this._back.add(t),this}addFront(t){return delete this._cache,this._back.has(t)||this._front.add(t),this}delete(t){return delete this._cache,this._front.delete(t)||this._back.delete(t)}toArray(){const t=Array.from(this._front).reverse();for(const e of this._back)t.push(e);return t}toReadonlyArray(){return this._cache=this._cache||this.toArray(),this._cache}[Symbol.iterator](){return this.toReadonlyArray()[Symbol.iterator]()}}function K(t,e,n,r,o,i){let s=t.getFirstChild();for(;null!==s;){const t=s.__key;s.__parent===e&&(mo(s)&&K(s,t,n,r,o,i),n.has(t)||i.delete(t),o.push(t)),s=s.getNextSibling()}}let $=!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!==fi(t,n)}function U(t,e,n){const r=es(Ji(n));let o=null,i=null;null!==r&&r.anchorNode===t&&(o=r.anchorOffset,i=r.focusOffset);const s=t.nodeValue;null!==s&&vi(e,s,o,i,!1)}function Y(t,e,n){if(_r(t)){const e=t.anchor.getNode();if(e.is(n)&&t.format!==e.getFormat())return!1}return ti(e)&&n.isAttached()}function j(t,e,n,r){for(let o=t;o&&!ps(o);o=Bi(o)){const t=fi(o,e);if(void 0!==t){const e=ai(t,n);if(e)return So(e)||!rs(o)?void 0:[o,e]}else if(o===r)return[r,pi(n)]}}function J(t,e,n){$=!0;const r=performance.now()-B>100;try{go(t,()=>{const o=Dr()||function(t){return t.getEditorState().read(()=>{const t=Dr();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,_=j(g,t,c,l);if(!_)continue;const[p,y]=_;if("characterData"===h)r&&ir(y)&&ti(g)&&Y(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=ui(r),s=r.parentNode;if(null!=s&&r!==a&&null===o&&!W(r,s,t)){if(i){const t=(rs(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)||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||W(n,o,t)||i.removeChild(n)}}n.takeRecords()}null!==o&&(u&&yi(o),i&&Li(t)&&o.insertRawText(f))})}finally{$=!1}}function H(t){const e=t._observer;if(null!==e){J(t,e.takeRecords(),e)}}function G(t){!function(t){0===B&&Ji(t).addEventListener("textInput",z,!0)}(t),t._observer=new MutationObserver((e,n)=>{J(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||nt).bind(e),this.isEqual=(e.isEqual||Object.is).bind(e),this.defaultValue=this.parse(void 0),this.resetOnCopyNode=e.resetOnCopyNode||!1}}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}=ms(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)}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=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:Uo(as(),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;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=Zr()._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())&&ir(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())&&ir(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),ir(r)){t.set(r.__key,o?r.getTextContentSize():0,"text",!0);break}if(!mo(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="",Tt=null,vt=null,Ot=!1,Et=!1;function kt(t,e){const n=yt.get(t);if(null!==e){const n=Yt(t);n.parentNode===e&&e.removeChild(n)}if(mt.has(t)||dt._keyToDOMMap.delete(t),mo(n)){const t=Cs(n,yt);Mt(t,0,t.length-1,null)}void 0!==n&&Ii(Ct,ht,gt,n,"destroyed")}function Mt(t,e,n,r){for(let o=e;o<=n;++o){const e=t[o];void 0!==e&&kt(e,r)}}function bt(t,e){t.setProperty("text-align",e)}const At="40px";function Dt(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)}if(0===e)return void t.style.setProperty("padding-inline-start","");const r=getComputedStyle(dt._rootElement||t).getPropertyValue("--lexical-indent-base-value")||At;t.style.setProperty("padding-inline-start",`calc(${e} * ${r})`)}function wt(t,e){const n=t.style;0===e?bt(n,""):1===e?bt(n,"left"):2===e?bt(n,"center"):3===e?bt(n,"right"):4===e?bt(n,"justify"):5===e?bt(n,"start"):6===e&&bt(n,"end")}function Pt(t,e){const n=function(t){const e=t.__dir;if(null!==e)return e;if(To(t))return null;const n=t.getParentOrThrow();return To(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=St.$createDOM(r,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),ir(r)?o.setAttribute("data-lexical-text","true"):So(r)&&o.setAttribute("data-lexical-decorator","true"),mo(r)){const t=r.__indent,e=r.__size;if(Pt(o,r),0!==t&&Dt(o,t),0!==e){const t=e-1;Ft(Cs(r,mt),r,0,t,St.$getDOMSlot(r,o,dt))}const n=r.__format;0!==n&&wt(o,n),r.isInline()||Lt(null,r,o)}else{const t=r.getTextContent();if(So(r)){const t=r.decorate(dt,ft);null!==t&&Bt(e,t),o.contentEditable="false"}Nt+=t}return null!==n&&n.insertChild(o),St.$decorateDOM(r,null,o,dt),Ii(Ct,ht,gt,r,"created"),o}function Ft(t,e,n,r,o){const i=Nt;Nt="";let s=n;for(;s<=r;++s){It(t[s],o);const e=mt.get(t[s]);null!==e&&ir(e)?null===Tt&&(Tt=e.getFormat(),vt=e.getStyle()):mo(e)&&s<r&&!e.isInline()&&(Nt+=v)}o.element.__lexicalTextContent=Nt,Nt=i+Nt}function Rt(t,e){if(t){const n=t.__last;if(n){const t=e.get(n);if(t)return zn(t)?"line-break":So(t)&&t.isInline()?"decorator":null}return"empty"}return null}function Lt(t,e,n){const r=Rt(t,yt),o=Rt(e,mt);r!==o&&St.$getDOMSlot(e,n,dt).setManagedLineBreak(o)}function Kt(e,n,r){var o;Tt=null,vt=null,function(e,n,r){const o=Nt,i=e.__size,s=n.__size;Nt="";const l=r.element;if(1===i&&1===s){const t=e.__first,r=n.__first;if(t===r)$t(t,l);else{const e=Yt(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}kt(t,null)}const o=mt.get(r);ir(o)&&null===Tt&&(Tt=o.getFormat(),vt=o.getStyle())}else{const o=Cs(e,yt),c=Cs(n,mt);if(o.length!==i&&t(227),c.length!==s&&t(228),0===i)0!==s&&Ft(c,0,0,s-1,r);else if(0===s){if(0!==i){const t=null==r.after&&null==r.before&&null==r.element.__lexicalLineBreak;Mt(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=zt($t(r,i.element)),f++,d++;else{if(void 0===a&&(a=Wt(n,d)),void 0===c)c=Wt(e,f);else if(!c.has(t)){f++;continue}if(!a.has(t)){u=zt(Yt(t)),kt(t,i.element),f++,c.delete(t);continue}if(c.has(r)){const t=$i(dt,r);t!==u&&i.withBefore(u).insertChild(t),u=zt($t(r,i.element)),f++,d++}else It(r,i.withBefore(u)),d++}const o=mt.get(r);null!==o&&ir(o)?null===Tt&&(Tt=o.getFormat(),vt=o.getStyle()):mo(o)&&d<=l&&!o.isInline()&&(Nt+=v)}const h=f>s,g=d>l;if(h&&!g){const t=n[l+1],e=void 0===t?null:dt.getElementByKey(t);Ft(n,0,d,l,i.withBefore(e))}else g&&!h&&Mt(e,f,s,i.element)}(0,o,c,i,s,r)}l.__lexicalTextContent=Nt,Nt=o+Nt}(e,n,St.$getDOMSlot(n,r,dt)),o=n,null==Tt||Tt===o.__textFormat||Et||o.setTextFormat(Tt),function(t){null==vt||vt===t.__textStyle||Et||t.setTextStyle(vt)}(n)}function $t(e,n){const r=yt.get(e);let o=mt.get(e);void 0!==r&&void 0!==o||t(61);const i=Ot||pt.has(e)||_t.has(e),s=$i(dt,e);if(r===o&&!i){let t;if(mo(r)){const e=s.__lexicalTextContent;"string"==typeof e?t=e:(t=r.getTextContent(),s.__lexicalTextContent=t)}else t=r.getTextContent();return Nt+=t,s}if(r!==o&&i&&Ii(Ct,ht,gt,o,"updated"),St.$updateDOM(o,r,s,dt)){const r=It(e,null);return null===n&&t(62),n.replaceChild(r,s),kt(e,null),r}if(mo(r)){mo(o)||t(334,e);const n=o.__indent;(Ot||n!==r.__indent)&&Dt(s,n);const l=o.__format;if((Ot||l!==r.__format)&&wt(s,l),i)Kt(r,o,s),To(o)||o.isInline()||Lt(r,o,s);else{const t=s.__lexicalTextContent;let e;"string"==typeof t?e=t:(e=r.getTextContent(),s.__lexicalTextContent=e),Nt+=e}if((Ot||o.__dir!==r.__dir)&&(Pt(s,o),To(o)&&!Ot))for(const t of o.getChildren())if(mo(t)){Pt($i(dt,t.getKey()),t)}}else{const t=o.getTextContent();if(So(o)){const t=o.decorate(dt,ft);null!==t&&Bt(e,t)}Nt+=t}if(!Et&&To(o)&&o.__cachedText!==Nt){const t=o.getWritable();t.__cachedText=Nt,o=t}return St.$decorateDOM(o,r,s,dt),s}function Bt(t,e){let n=dt._pendingDecorators;const r=dt._decorators;if(null===n){if(r[t]===e)return;n=hi(dt)}n[t]=e}function zt(t){let e=t.nextSibling;return null!==e&&e===dt._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 Ut(t,e,n,r,o,i){Nt="",Ot=2===r,dt=n,ft=n._config,St=n._config.dom||Ro,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,$t("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,St=Ro,s}function Yt(e){const n=xt.get(e);return void 0===n&&t(75,e),n}function jt(t){return{type:t}}const Jt=jt("SELECTION_CHANGE_COMMAND"),Ht=jt("SELECTION_INSERT_CLIPBOARD_NODES_COMMAND"),Gt=jt("CLICK_COMMAND"),Vt=jt("BEFORE_INPUT_COMMAND"),qt=jt("INPUT_COMMAND"),Xt=jt("COMPOSITION_START_COMMAND"),Qt=jt("COMPOSITION_END_COMMAND"),Zt=jt("DELETE_CHARACTER_COMMAND"),te=jt("INSERT_LINE_BREAK_COMMAND"),ee=jt("INSERT_PARAGRAPH_COMMAND"),ne=jt("CONTROLLED_TEXT_INSERTION_COMMAND"),re=jt("PASTE_COMMAND"),oe=jt("REMOVE_TEXT_COMMAND"),ie=jt("DELETE_WORD_COMMAND"),se=jt("DELETE_LINE_COMMAND"),le=jt("FORMAT_TEXT_COMMAND"),ce=jt("UNDO_COMMAND"),ae=jt("REDO_COMMAND"),ue=jt("KEYDOWN_COMMAND"),fe=jt("KEY_ARROW_RIGHT_COMMAND"),de=jt("MOVE_TO_END"),he=jt("KEY_ARROW_LEFT_COMMAND"),ge=jt("MOVE_TO_START"),_e=jt("KEY_ARROW_UP_COMMAND"),pe=jt("KEY_ARROW_DOWN_COMMAND"),ye=jt("KEY_ENTER_COMMAND"),me=jt("KEY_SPACE_COMMAND"),xe=jt("KEY_BACKSPACE_COMMAND"),Ce=jt("KEY_ESCAPE_COMMAND"),Se=jt("KEY_DELETE_COMMAND"),Ne=jt("KEY_TAB_COMMAND"),Te=jt("INSERT_TAB_COMMAND"),ve=jt("INDENT_CONTENT_COMMAND"),Oe=jt("OUTDENT_CONTENT_COMMAND"),Ee=jt("DROP_COMMAND"),ke=jt("FORMAT_ELEMENT_COMMAND"),Me=jt("DRAGSTART_COMMAND"),be=jt("DRAGOVER_COMMAND"),Ae=jt("DRAGEND_COMMAND"),De=jt("COPY_COMMAND"),we=jt("CUT_COMMAND"),Pe=jt("SELECT_ALL_COMMAND"),Ie=jt("CLEAR_EDITOR_COMMAND"),Fe=jt("CLEAR_HISTORY_COMMAND"),Re=jt("CAN_REDO_COMMAND"),Le=jt("CAN_UNDO_COMMAND"),Ke=jt("FOCUS_COMMAND"),$e=jt("BLUR_COMMAND"),Be=jt("KEY_MODIFIER_COMMAND"),ze=Object.freeze({}),We=[["keydown",function(t,e){if(Ue=t.timeStamp,Ye=t.key,e.isComposing())return;Ki(e,ue,t)}],["pointerdown",function(t,e){const n=t.target,r=t.pointerType;os(n)&&"touch"!==r&&"pen"!==r&&0===t.button&&go(e,()=>{Jo(n)||(qe=!0)})}],["compositionstart",function(t,e){Ki(e,Xt,t)}],["compositionend",function(t,e){i?Qe=!0:l||!a&&!d?Ki(e,Qt,t):(Ze=!0,tn=t.data)}],["input",function(t,e){t.stopPropagation(),go(e,()=>{e.dispatchCommand(qt,t)},{event:t}),Je=null}],["click",function(t,e){go(e,()=>{const n=Dr(),r=es(Ji(e)),o=wr();if(r)if(_r(n)){const e=n.anchor,i=e.getNode();if("element"===e.type&&0===e.offset&&n.isCollapsed()&&!To(i)&&1===_i().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=xs(i,t=>mo(t)&&!t.isInline());mo(t)&&t.select(0)}}}else if("touch"===t.pointerType||"pen"===t.pointerType){const n=r.anchorNode;if(rs(n)||ti(n)){yi(Ar(o,r,e,t))}}Ki(e,Gt,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&&Li(e))return;if("insertCompositionText"===n)return;Ki(e,Vt,t)}(t,e)]);let Ue=0,Ye=null,je=0,Je=null;const He=new WeakMap,Ge=new WeakMap;let Ve=!1,qe=!1,Xe=!1,Qe=!1,Ze=!1,tn="",en=null,nn=[0,"",0,"root",0];function rn(t,e,n,r,o){const i=t.anchor,l=t.focus,c=i.getNode(),a=Zr(),u=es(Ji(a)),f=null!==u?u.anchorNode:null,d=i.key,h=a.getElementByKey(d),g=n.length;return d!==l.key||!ir(c)||(!o&&(!s||je<r+50)||c.isDirty()&&g<2||xi(n))&&i.offset!==l.offset&&!c.isComposing()||Zo(c)||c.isDirty()&&g>1||(o||!s)&&null!==h&&!c.isComposing()&&f!==ni(h)||null!==u&&null!==e&&(!e.collapsed||e.startContainer!==u.anchorNode||e.startOffset!==u.anchorOffset)||!c.isComposing()&&(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=Qo(e);return 0===n?!e.canInsertTextBefore()||!r.canInsertTextBefore()&&!e.isComposing()||o||function(t){const e=t.getPreviousSibling();return(ir(e)||mo(e)&&e.isInline())&&!e.canInsertTextAfter()}(e):n===e.getTextContentSize()&&(!e.canInsertTextAfter()||!r.canInsertTextAfter()&&!e.isComposing()||o)}(t,c)}function on(t,e){return ti(t)&&null!==t.nodeValue&&0!==e&&e!==t.nodeValue.length}function sn(e,n,r){const{anchorNode:o,anchorOffset:i,focusNode:s,focusOffset:l}=e;Ve&&(Ve=!1,on(o,i)&&on(s,l)&&!en)||go(n,()=>{if(!r)return void yi(null);if(!Go(n,o,s))return;let c=Dr();if(en&&_r(c)&&c.isCollapsed()){const t=c.anchor,e=en.anchor;(t.key===e.key&&t.offset===e.offset+1||1===t.offset&&e.getNode().is(t.getNode().getPreviousSibling()))&&(c=en.clone(),yi(c))}if(en=null,_r(c)){const r=c.anchor,o=r.getNode();if(c.isCollapsed()){"Range"===e.type&&e.anchorNode===e.focusNode&&(c.dirty=!0);const i=Ji(n).event,s=i?i.timeStamp:performance.now(),[l,a,u,f,d]=nn,h=_i(),g=!1===n.isComposing()&&""===h.getTextContent();if(s<d+200&&r.offset===u&&r.key===f)ln(c,l,a);else if("text"===r.type)ir(o)||t(141),cn(c,o);else if("element"===r.type&&!g){mo(o)||t(259);const e=r.getNode();e.isEmpty()?function(t,e){const n=e.getTextFormat(),r=e.getTextStyle();ln(t,n,r)}(c,e):ln(c,c.format,"")}}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(ir(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}}Ki(n,Jt,void 0)})}function ln(t,e,n){t.format===e&&t.style===n||(t.format=e,t.style=n,t.dirty=!0)}function cn(t,e){ln(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 un(e){const n=e.inputType,r=an(e),o=Zr(),i=Dr();if("deleteContentBackward"===n){if(null===i){const t=wr();if(!_r(t))return!0;yi(t.clone())}if(_r(i)){const n=i.anchor.key===i.focus.key;if(s=e.timeStamp,"MediaLast"===Ye&&s<Ue+30&&o.isComposing()&&n){if(li(null),Ue=0,setTimeout(()=>{go(o,()=>{li(null)})},30),_r(i)){const e=i.anchor.getNode();e.markDirty(),ir(e)||t(142),cn(i,e)}}else{li(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 c=f&&n&&!l&&s;if(c&&i.isCollapsed()&&(c=!So(Ri(i.anchor,!0))),!c){Ki(o,Zt,!0);const t=Dr();f&&_r(t)&&t.isCollapsed()&&(en=t,setTimeout(()=>en=null))}}return!0}}var s;if(!_r(i))return!0;const c=e.data;null!==Je&&Ti(!1,o,Je),i.dirty&&null===Je||!i.isCollapsed()||To(i.anchor.getNode())||null===r||i.applyDOMRange(r),Je=null;const a=i.anchor,u=i.focus,d=a.getNode(),h=u.getNode();if("insertText"===n||"insertTranspose"===n){if("\n"===c)e.preventDefault(),Ki(o,te,!1);else if(c===v)e.preventDefault(),Ki(o,ee,void 0);else if(null==c&&e.dataTransfer){const t=e.dataTransfer.getData("text/plain");e.preventDefault(),i.insertRawText(t)}else null!=c&&rn(i,r,c,e.timeStamp,!0)?(e.preventDefault(),Ki(o,ne,c)):Je=c;return je=e.timeStamp,!0}switch(e.preventDefault(),n){case"insertFromYank":case"insertFromDrop":case"insertReplacementText":Ki(o,ne,e);break;case"insertFromComposition":li(null),Ki(o,ne,e);break;case"insertLineBreak":li(null),Ki(o,te,!1);break;case"insertParagraph":li(null),Xe&&!l?(Xe=!1,Ki(o,te,!1)):Ki(o,ee,void 0);break;case"insertFromPaste":case"insertFromPasteAsQuotation":Ki(o,re,e);break;case"deleteByComposition":(function(t,e){return t!==e||mo(t)||mo(e)||!Qo(t)||!Qo(e)})(d,h)&&Ki(o,oe,e);break;case"deleteByDrag":Wi(Dn),Ki(o,oe,e);break;case"deleteByCut":Ki(o,oe,e);break;case"deleteContent":Ki(o,Zt,!1);break;case"deleteWordBackward":Ki(o,ie,!0);break;case"deleteWordForward":Ki(o,ie,!1);break;case"deleteHardLineBackward":case"deleteSoftLineBackward":Ki(o,se,!0);break;case"deleteContentForward":case"deleteHardLineForward":case"deleteSoftLineForward":Ki(o,se,!1);break;case"formatStrikeThrough":Ki(o,le,"strikethrough");break;case"formatBold":Ki(o,le,"bold");break;case"formatItalic":Ki(o,le,"italic");break;case"formatUnderline":Ki(o,le,"underline");break;case"historyUndo":Ki(o,ce,void 0);break;case"historyRedo":Ki(o,ae,void 0)}return!0}function fn(t){if(rs(t.target)&&Jo(t.target))return!0;const e=Zr(),n=Dr(),r=t.data,o=an(t);if(null!=r&&_r(n)&&rn(n,o,r,t.timeStamp,!1)){Qe&&(gn(e,r),Qe=!1);const o=n.anchor.getNode(),l=es(Ji(e));if(null===l)return!0;const c=n.isBackward(),a=c?n.anchor.offset:n.focus.offset,u=c?n.focus.offset:n.anchor.offset;s&&!n.isCollapsed()&&ir(o)&&null!==l.anchorNode&&o.getTextContent().slice(0,a)+r+o.getTextContent().slice(a+u)===Ni(l.anchorNode)||Ki(e,ne,r);const d=r.length;i&&d>1&&"insertCompositionText"===t.inputType&&!e.isComposing()&&(n.anchor.offset-=d),f&&e.isComposing()&&(Ue=0,li(null))}else{Ti(!1,e,null!==r?r:void 0),Qe&&(gn(e,r||void 0),Qe=!1)}return function(){qr();const t=Zr();H(t)}(),!0}function dn(t){const e=Zr(),n=Dr();if(_r(n)&&!e.isComposing()){const r=n.anchor,o=n.anchor.getNode();li(r.key),Wi(wn),(t.timeStamp<Ue+30||"element"===r.type||!n.isCollapsed()||o.getFormat()!==n.format||ir(o)&&o.getStyle()!==n.style)&&Ki(e,ne,O)}return!0}function hn(t){return gn(Zr(),t.data),Wi(Pn),!0}function gn(t,e){const n=t._compositionKey;if(li(null),null!==n&&null!=e){if(""===e){const e=ai(n),r=ni(t.getElementByKey(n));if(null!==r&&null!==r.nodeValue&&ir(e)){const n=es(Ji(t));let o=null,i=null;null!==n&&n.anchorNode===r&&(o=n.anchorOffset,i=n.focusOffset),vi(e,r.nodeValue,o,i,!0)}return}if("\n"===e[e.length-1]){const e=Dr();if(_r(e)||yr(e)){if(_r(e)){const t=e.focus;e.anchor.set(t.key,t.offset,t.type)}return void Ki(t,ye,null)}}}Ti(!0,t,e)}function _n(t){const e=Zr();if(null==t.key)return!0;if(Ze){if(Di(t))return go(e,()=>{gn(e,tn)}),Ze=!1,tn="",!0;Ze=!1,tn=""}if(function(t){return Mi(t,"ArrowRight",{shiftKey:"any"})}(t))Ki(e,fe,t);else if(function(t){return Mi(t,"ArrowRight",bi)}(t))Ki(e,de,t);else if(function(t){return Mi(t,"ArrowLeft",{shiftKey:"any"})}(t))Ki(e,he,t);else if(function(t){return Mi(t,"ArrowLeft",bi)}(t))Ki(e,ge,t);else if(function(t){return Mi(t,"ArrowUp",{altKey:"any",shiftKey:"any"})}(t))Ki(e,_e,t);else if(function(t){return Mi(t,"ArrowDown",{altKey:"any",shiftKey:"any"})}(t))Ki(e,pe,t);else if(function(t){return Mi(t,"Enter",{altKey:"any",ctrlKey:"any",metaKey:"any",shiftKey:!0})}(t))Xe=!0,Ki(e,ye,t);else if(function(t){return" "===t.key}(t))Ki(e,me,t);else if(function(t){return o&&Mi(t,"o",{ctrlKey:!0})}(t))t.preventDefault(),Xe=!0,Ki(e,te,!0);else if(function(t){return Mi(t,"Enter",{altKey:"any",ctrlKey:"any",metaKey:"any"})}(t))Xe=!1,Ki(e,ye,t);else if(function(t){return Mi(t,"Backspace",{shiftKey:"any"})||o&&Mi(t,"h",{ctrlKey:!0})}(t))Di(t)?Ki(e,xe,t):(t.preventDefault(),Ki(e,Zt,!0));else if(function(t){return"Escape"===t.key}(t))Ki(e,Ce,t);else if(function(t){return Mi(t,"Delete",{})||o&&Mi(t,"d",{ctrlKey:!0})}(t))!function(t){return"Delete"===t.key}(t)?(t.preventDefault(),Ki(e,Zt,!1)):Ki(e,Se,t);else if(function(t){return Mi(t,"Backspace",Ai)}(t))t.preventDefault(),Ki(e,ie,!0);else if(function(t){return Mi(t,"Delete",Ai)}(t))t.preventDefault(),Ki(e,ie,!1);else if(function(t){return o&&Mi(t,"Backspace",{metaKey:!0})}(t))t.preventDefault(),Ki(e,se,!0);else if(function(t){return o&&(Mi(t,"Delete",{metaKey:!0})||Mi(t,"k",{ctrlKey:!0}))}(t))t.preventDefault(),Ki(e,se,!1);else if(function(t){return Mi(t,"b",bi)}(t))t.preventDefault(),Ki(e,le,"bold");else if(function(t){return Mi(t,"u",bi)}(t))t.preventDefault(),Ki(e,le,"underline");else if(function(t){return Mi(t,"i",bi)}(t))t.preventDefault(),Ki(e,le,"italic");else if(function(t){return Mi(t,"Tab",{shiftKey:"any"})}(t))Ki(e,Ne,t);else if(function(t){return Mi(t,"z",bi)}(t))t.preventDefault(),Ki(e,ce,void 0);else if(function(t){if(o)return Mi(t,"z",{metaKey:!0,shiftKey:!0});return Mi(t,"y",{ctrlKey:!0})||Mi(t,"z",{ctrlKey:!0,shiftKey:!0})}(t))t.preventDefault(),Ki(e,ae,void 0);else{const n=e._editorState._selection;null===n||_r(n)?wi(t)&&(t.preventDefault(),Ki(e,Pe,t)):!function(t){return Mi(t,"c",bi)}(t)?!function(t){return Mi(t,"x",bi)}(t)?wi(t)&&(t.preventDefault(),Ki(e,Pe,t)):(t.preventDefault(),Ki(e,we,t)):(t.preventDefault(),Ki(e,De,t))}return function(t){return t.ctrlKey||t.shiftKey||t.altKey||t.metaKey}(t)&&e.dispatchCommand(Be,t),!0}function pn(t){let e=t.__lexicalEventHandles;return void 0===e&&(e=[],t.__lexicalEventHandles=e),e}const yn=new Map;function mn(t){const e=ns(t.target);if(null===e)return;const n=qo(e.anchorNode);if(null===n)return;qe&&(qe=!1,go(n,()=>{const r=wr(),o=e.anchorNode;if(rs(o)||ti(o)){yi(Ar(r,e,n,t))}}));const r=Ci(n),o=r[r.length-1],i=o._key,s=yn.get(i),l=s||o;l!==n&&sn(e,l,!1),sn(e,n,!0),n!==o?yn.set(i,n):s&&yn.delete(i)}function xn(t){t._lexicalHandled=!0}function Cn(t){return!0===t._lexicalHandled}const Sn=()=>{};function Nn(e){const n=He.get(e);if(void 0===n)return void Sn();const r=Ge.get(n);if(void 0===r)return void Sn();const o=r-1;o>=0||t(164),He.delete(e),Ge.set(n,o),0===o&&n.removeEventListener("selectionchange",mn);const i=Xo(e);Vo(i)?(!function(t){if(null!==t._parentEditor){const e=Ci(t),n=e[e.length-1]._key;yn.get(n)===t&&yn.delete(n)}else yn.delete(t._key)}(i),e.__lexicalEditor=null):i&&t(198);const s=pn(e);for(let t=0;t<s.length;t++)s[t]();e.__lexicalEventHandles=[]}function Tn(t,e,n){qr();const r=t.__key,o=t.getParent();if(null===o)return;const i=function(t){const e=Dr();if(!_r(e)||!mo(t))return e;const{anchor:n,focus:r}=e,o=n.getNode(),i=r.getNode();Yi(o,t)&&n.set(t.__key,0,"element");Yi(i,t)&&r.set(t.__key,0,"element");return e}(t);let s=!1;if(_r(i)&&e){const e=i.anchor,n=i.focus;e.key===r&&(Fr(e,t,o,t.getPreviousSibling(),t.getNextSibling()),s=!0),n.key===r&&(Fr(n,t,o,t.getPreviousSibling(),t.getNextSibling()),s=!0)}else yr(i)&&e&&t.isSelected()&&t.selectPrevious();if(_r(i)&&e&&!s){const e=t.getIndexWithinParent();ii(t),Pr(i,o,e,-1)}else ii(t);n||Gi(o)||o.canBeEmpty()||!o.isEmpty()||Tn(o,e),e&&i&&To(o)&&o.isEmpty()&&o.selectEnd()}const vn=Symbol.for("ephemeral");function On(t){return t[vn]||!1}class En{__type;__key;__parent;__prev;__next;__state;static getType(){const{ownNodeType:e}=ms(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}),oi(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=ai(t);if(null===e)break;t=e.__parent}return!1}isSelected(t){const e=t||Dr();if(null==e)return!1;const n=e.getNodes().some(t=>t.__key===this.__key);if(ir(this))return n;if(_r(e)&&"element"===e.anchor.type&&"element"===e.focus.type){if(e.isCollapsed())return!1;const t=this.getParent();if(So(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:ai(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(Gi(n))return mo(e)||e===this&&So(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:ai(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:ai(t)}getNextSiblings(){const t=[];let e=this.getNextSibling();for(;null!==e;)t.push(e),e=e.getNextSibling();return t}getCommonAncestor(t){const e=mo(this)?this:this.getParent(),n=mo(t)?t:t.getParent(),r=e&&n?Qs(e,n):null;return r?r.commonAncestor:null}is(t){return null!=t&&this.__key===t.__key}isBefore(e){const n=Qs(this,e);return null!==n&&("descendant"===n.type||("branch"===n.type?-1===Vs(n):("same"!==n.type&&"ancestor"!==n.type&&t(279),!1)))}isParentOf(t){const e=Qs(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=mo(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=Zr()._dirtyLeaves;return null!==t&&t.has(this.__key)}getLatest(){if(On(this))return this;const e=ai(this.__key);return null===e&&t(113),e}getWritable(){if(On(this))return this;qr();const t=Qr(),e=Zr(),n=t._nodeMap,r=this.__key,o=this.getLatest(),i=e._cloneNotNeeded,s=Dr();if(null!==s&&s.setCachedNodes(null),i.has(r))return si(o),o;const l=gs(o);return i.add(r),si(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){Tn(this,!0,t)}replace(e,n){qr();let r=Dr();null!==r&&(r=r.clone()),Xi(this,e);const o=this.getLatest(),i=this.__key,s=e.__key,l=e.getWritable(),c=this.getParentOrThrow().getWritable(),a=c.__size;ii(l);const u=o.getPreviousSibling(),f=o.getNextSibling(),d=o.__prev,h=o.__next,g=o.__parent;if(Tn(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&&(mo(this)&&mo(l)||t(139),this.getChildren().forEach(t=>{l.append(t)})),_r(r)){yi(r);const t=r.anchor,e=r.focus;t.key===i&&hr(t,l),e.key===i&&hr(e,l)}return ci()===i&&li(s),l}insertAfter(t,e=!0){qr(),Xi(this,t);const n=this.getWritable(),r=t.getWritable(),o=r.getParent(),i=Dr();let s=!1,l=!1;if(null!==o){const e=t.getIndexWithinParent();if(ii(r),_r(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&&_r(i)){const t=this.getIndexWithinParent();Pr(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){qr(),Xi(this,t);const n=this.getWritable(),r=t.getWritable(),o=r.__key;ii(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=Dr();if(e&&_r(a)){Pr(a,this.getParentOrThrow(),c)}return t}isParentRequired(){return!1}createParentElementNode(){return Do()}selectStart(){return this.selectPrevious()}selectEnd(){return this.selectNext(0,0)}selectPrevious(t,e){qr();const n=this.getPreviousSibling(),r=this.getParentOrThrow();if(null===n)return r.select(0,0);if(mo(n))return n.select();if(!ir(n)){const t=n.getIndexWithinParent()+1;return r.select(t,t)}return n.select(t,e)}selectNext(t,e){qr();const n=this.getNextSibling(),r=this.getParentOrThrow();if(null===n)return r.select();if(mo(n))return n.select(0,0);if(!ir(n)){const t=n.getIndexWithinParent();return r.select(t,t)}return n.select(t,e)}markDirty(){this.getWritable()}reconcileObservedMutation(t,e){this.markDirty()}}const kn="history-merge",Mn="collaboration",bn="skip-scroll-into-view",An="skip-dom-selection",Dn="skip-selection-focus",wn="composition-start",Pn="composition-end",In=/\s*!important\s*$/i;function Fn(t){const e={};if(!t)return e;let n="",r="",o=null,i=!1,s=!1,l=!1,c=0;for(let a=0;a<t.length;a++){const u=t[a];if(i)"*"===u&&"/"===t[a+1]&&(i=!1,a++);else if(s)l?r+=u:n+=u,s=!1;else if(null===o)if("/"!==u||"*"!==t[a+1])if('"'!==u&&"'"!==u)if("("!==u)if(")"!==u)if(l||":"!==u||0!==c){if(";"===u&&0===c){const t=n.trim(),o=r.trim();""!==t&&""!==o&&(e[t]=o),n="",r="",l=!1;continue}l?r+=u:n+=u}else l=!0;else c=Math.max(0,c-1),l?r+=u:n+=u;else c++,l?r+=u:n+=u;else o=u,l?r+=u:n+=u;else i=!0,a++;else l?r+=u:n+=u,"\\"===u?s=!0:u===o&&(o=null)}const a=n.trim(),u=r.trim();return""!==a&&""!==u&&(e[a]=u),e}function Rn(t,e,n){const r=In.test(n)?"important":"",o=""===r?n:n.replace(In,"").trim();t.setProperty(e,o,r)}function Ln(t,e,n=""){if(e===n)return;const r=Fn(n),o=Fn(e);for(const e in o)delete r[e],Rn(t,e,o[e]);for(const e in r)t.removeProperty(e)}class Kn extends En{static getType(){return"linebreak"}static clone(t){return new Kn(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&&ls(e)){const n=e.firstChild;if(n===t||n.nextSibling===t&&Wn(n)){const n=e.lastChild;if(n===t||n.previousSibling===t&&Wn(n))return!0}}return!1}(t)||function(t){const e=t.parentElement;if(null!==e&&ls(e)){const n=e.firstChild;if(n===t||n.nextSibling===t&&Wn(n))return!1;const r=e.lastChild;if(r===t||r.previousSibling===t&&Wn(r))return!0}return!1}(t)?null:{conversion:$n,priority:0}}}static importJSON(t){return Bn().updateFromJSON(t)}}function $n(t){return{node:Bn()}}function Bn(){return qi(new Kn)}function zn(t){return t instanceof Kn}function Wn(t){return ti(t)&&/^( |\t|\r?\n)+$/.test(t.textContent||"")}function Un(t,e){return 16&e?"code":e&p?"mark":32&e?"sub":64&e?"sup":null}function Yn(t,e){return 1&e?"strong":2&e?"em":"span"}function jn(t,e,n,r,o){const i=r.classList;let s=Pi(o,"base");void 0!==s&&i.add(...s),s=Pi(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 A){const r=A[t];if(s=Pi(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 Jn(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 Hn(t,e,n,r,o,i){Jn(o,t,e);const s=i.theme.text;void 0!==s&&jn(0,0,r,t,s)}function Gn(t,e){const n=document.createElement(e);return n.appendChild(t),n}class Vn extends En{__text;__format;__style;__mode;__detail;static getType(){return"text"}static clone(t){return new Vn(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===ci()}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 ri(this.getLatest().__format,t,e)}canHaveFormat(){return!0}isInline(){return!0}createDOM(t,e){const n=this.__format,r=Un(0,n),o=Yn(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));Hn(l,this,0,n,this.__text,t);const c=this.__style;return""!==c&&Ln(s.style,c),s}updateDOM(e,n,r){const o=this.__text,i=e.__format,s=this.__format,l=Un(0,i),c=Un(0,s),a=Yn(0,i),u=Yn(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 Hn(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)),Jn(o,f,this);const d=r.theme.text;void 0!==d&&i!==s&&jn(0,i,s,f,d);const h=e.__style,g=this.__style;return h!==g&&Ln(n.style,g,h),!1}static importDOM(){return{"#text":()=>({conversion:tr,priority:0}),b:()=>({conversion:Xn,priority:0}),code:()=>({conversion:rr,priority:0}),em:()=>({conversion:rr,priority:0}),i:()=>({conversion:rr,priority:0}),mark:()=>({conversion:rr,priority:0}),s:()=>({conversion:rr,priority:0}),span:()=>({conversion:qn,priority:0}),strong:()=>({conversion:rr,priority:0}),sub:()=>({conversion:rr,priority:0}),sup:()=>({conversion:rr,priority:0}),u:()=>({conversion:rr,priority:0})}}static importJSON(t){return or().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 rs(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=Gn(n,"b")),this.hasFormat("italic")&&(n=Gn(n,"i")),this.hasFormat("strikethrough")&&(n=Gn(n,"s")),this.hasFormat("underline")&&(n=Gn(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?D[t]:t,e}setStyle(t){const e=this.getWritable();return e.__style=t,e}toggleFormat(t){const e=ri(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){qr();let n=t,r=e;const o=Dr(),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(!_r(o))return kr(s,n,s,r,"text","text");{const t=ci();t!==o.anchor.key&&t!==o.focus.key||li(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=Dr();if(r&&_r(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){qr();const e=this.getLatest(),n=e.getTextContent();if(""===n)return[];const r=e.__key,o=ci(),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=Dr();if(_r(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=or(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=or(s[t]);n.__format=d,n.__style=h,n.__detail=g,n.__state=it(e,n);const i=n.__key;o===r&&li(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&&si(e);null!==n&&si(n)}(this);const t=u.getWritable(),e=this.getIndexWithinParent();_?(t.splice(e,0,x),this.remove()):t.splice(e,1,x),_r(m)&&Pr(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;ci()===o&&li(r);const l=Dr();if(_r(l)){const t=l.anchor,i=l.focus;null!==t&&t.key===o&&Rr(t,n,r,e,s),null!==i&&i.key===o&&Rr(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 qn(t){return{forChild:sr(t.style),node:null}}function Xn(t){const e=t,n="normal"===e.style.fontWeight;return{forChild:sr(e.style,n?void 0:"bold"),node:null}}const Qn=new WeakMap;function Zn(t){if(!rs(t))return!1;if("PRE"===t.nodeName)return!0;const e=t.style.whiteSpace;return"string"==typeof e&&e.startsWith("pre")}function tr(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=Qn.get(n))&&!Zn(n);)r.push(n),n=n.parentNode;const o=void 0===e?n:e;for(let t=0;t<r.length;t++)Qn.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(Bn()):"\t"===n?e.push(cr()):""!==n&&e.push(or(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=er(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=er(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:or(r)}}function er(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,rs(n)){const t=n.style.display;if(""===t&&!ss(n)||""!==t&&!t.startsWith("inline"))return null}let r=n;for(;null!==(r=e?n.firstChild:n.lastChild);)n=r;if(ti(n))return n;if("BR"===n.nodeName)return null}}const nr={code:"code",em:"italic",i:"italic",mark:"highlight",s:"strikethrough",strong:"bold",sub:"subscript",sup:"superscript",u:"underline"};function rr(t){const e=nr[t.nodeName.toLowerCase()];return void 0===e?{node:null}:{forChild:sr(t.style,e),node:null}}function or(t=""){return qi(new Vn(t))}function ir(t){return t instanceof Vn}function sr(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=>ir(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 lr extends Vn{static getType(){return"tab"}static clone(t){return new lr(t.__key)}constructor(t){super("\t",t),this.__detail=2}static importDOM(){return null}createDOM(t){const e=super.createDOM(t),n=Pi(t.theme,"tab");if(void 0!==n){e.classList.add(...n)}return e}static importJSON(t){return cr().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 cr(){return qi(new lr)}function ar(t){return t instanceof lr}class ur{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 Gs(cl(Zs(this,"next")),cl(Zs(t,"next")))<0}getNode(){const e=ai(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,Vr()||(ci()===i&&li(t),null!==o&&(o.setCachedNodes(null),o.dirty=!0)))}}function fr(t,e,n){return new ur(t,e,n)}function dr(t,e){let n=e.__key,r=t.offset,o="element";if(ir(e)){o="text";const t=e.getTextContentSize();r>t&&(r=t)}else if(!mo(e)){const t=e.getNextSibling();if(ir(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 hr(t,e){if(mo(e)){const n=e.getLastDescendant();mo(n)||ir(n)?dr(t,n):dr(t,e)}else dr(t,e)}class gr{_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(!yr(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._no