UNPKG

lexical

Version:

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

9 lines (8 loc) 119 kB
/** * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * */ function t(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var e=t((function(t){const e=new URL("https://lexical.dev/docs/error"),n=new URLSearchParams;n.append("code",t);for(let t=1;t<arguments.length;t++)n.append("v",arguments[t]);throw e.search=n.toString(),Error(`Minified Lexical error #${t}; visit ${e.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}));const n="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement,r=n&&"documentMode"in document?document.documentMode:null,i=n&&/Mac|iPod|iPhone|iPad/.test(navigator.platform),s=n&&/^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent),o=!(!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)&&!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=1,_=3,p=9,m=11,y=0,x=1,v=2,C=0,S=1,T=2,b=1,k=2,N=4,w=8,E=16,P=32,F=64,L=128,O=1792|(112|(3|N|w)|L),A=1,M=2,I=3,D=4,z=5,B=6,W=l||c||d?" ":"​",R="\n\n",K=s?" ":W,J="֑-߿יִ-﷽ﹰ-ﻼ",j="A-Za-zÀ-ÖØ-öø-ʸ̀-֐ࠀ-῿‎Ⰰ-﬜︀-﹯﻽-￿",$=new RegExp("^[^"+j+"]*["+J+"]"),U=new RegExp("^[^"+J+"]*["+j+"]"),V={bold:1,capitalize:1024,code:16,highlight:L,italic:2,lowercase:256,strikethrough:N,subscript:32,superscript:64,underline:w,uppercase:512},H={directionless:1,unmergeable:2},q={center:M,end:B,justify:D,left:A,right:I,start:z},G={[M]:"center",[B]:"end",[D]:"justify",[A]:"left",[I]:"right",[z]:"start"},Q={normal:0,segmented:2,token:1},X={[C]:"normal",[T]:"segmented",[S]:"token"};function Y(t,e,n,r,i,s){let o=t.getFirstChild();for(;null!==o;){const t=o.__key;o.__parent===e&&(Yr(o)&&Y(o,t,n,r,i,s),n.has(t)||s.delete(t),i.push(t)),o=o.getNextSibling()}}const Z=100;let tt=!1,et=0;function nt(t){et=t.timeStamp}function rt(t,e,n){const r="BR"===t.nodeName,i=e.__lexicalLineBreak;return i&&(t===i||r&&t.previousSibling===i)||r&&void 0!==Ji(t,n)}function it(t,e,n){const r=zs(ws(n));let i=null,s=null;null!==r&&r.anchorNode===t&&(i=r.anchorOffset,s=r.focusOffset);const o=t.nodeValue;null!==o&&ns(e,o,i,s,!1)}function st(t,e,n){if(Gn(t)){const e=t.anchor.getNode();if(e.is(n)&&t.format!==e.getFormat())return!1}return Fi(e)&&n.isAttached()}function ot(t,e,n,r){for(let i=t;i&&!eo(i);i=vs(i)){const t=Ji(i,e);if(void 0!==t){const e=Ri(t,n);if(e)return ei(e)||!Ks(i)?void 0:[i,e]}else if(i===r)return[r,Hi(n)]}}function lt(t,e,n){tt=!0;const r=performance.now()-et>Z;try{qr(t,(()=>{const i=hr()||function(t){return t.getEditorState().read((()=>{const t=hr();return null!==t?t.clone():null}))}(t),o=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,_=ot(g,t,c,l);if(!_)continue;const[p,m]=_;if("characterData"===h)r&&Wn(m)&&Fi(g)&&st(i,g,m)&&it(g,m,t);else if("childList"===h){u=!0;const e=d.addedNodes;for(let n=0;n<e.length;n++){const r=e[n],i=Ki(r),o=r.parentNode;if(null!=o&&r!==a&&null===i&&!rt(r,o,t)){if(s){const t=(Ks(r)?r.innerText:null)||r.nodeValue;t&&(f+=t)}o.removeChild(r)}}const n=d.removedNodes,r=n.length;if(r>0){let e=0;for(let i=0;i<r;i++){const r=n[i];(rt(r,g,t)||a===r)&&(g.appendChild(r),e++)}r!==e&&o.set(p,m)}}}if(o.size>0)for(const[e,n]of o)n.reconcileObservedMutation(e,t);const d=n.takeRecords();if(d.length>0){for(let e=0;e<d.length;e++){const n=d[e],r=n.addedNodes,i=n.target;for(let e=0;e<r.length;e++){const n=r[e],s=n.parentNode;null==s||"BR"!==n.nodeName||rt(n,i,t)||s.removeChild(n)}}n.takeRecords()}null!==i&&(u&&qi(i),s&&ps(t)&&i.insertRawText(f))}))}finally{tt=!1}}function ct(t){const e=t._observer;if(null!==e){lt(t,e.takeRecords(),e)}}function at(t){!function(t){0===et&&ws(t).addEventListener("textInput",nt,!0)}(t),t._observer=new MutationObserver(((e,n)=>{lt(t,e,n)}))}function ut(t,e){const n=t.__mode,r=t.__format,i=t.__style,s=e.__mode,o=e.__format,l=e.__style;return!(null!==n&&n!==s||null!==r&&r!==o||null!==i&&i!==l)}function ft(t,e){const n=t.mergeWithSibling(e),r=Mr()._normalizedNodes;return r.add(t.__key),r.add(e.__key),n}function dt(t){let e,n,r=t;if(""!==r.__text||!r.isSimpleText()||r.isUnmergeable()){for(;null!==(e=r.getPreviousSibling())&&Wn(e)&&e.isSimpleText()&&!e.isUnmergeable();){if(""!==e.__text){if(ut(e,r)){r=ft(e,r);break}break}e.remove()}for(;null!==(n=r.getNextSibling())&&Wn(n)&&n.isSimpleText()&&!n.isUnmergeable();){if(""!==n.__text){if(ut(r,n)){r=ft(r,n);break}break}n.remove()}}else r.remove()}function ht(t){return gt(t.anchor),gt(t.focus),t}function gt(t){for(;"element"===t.type;){const e=t.getNode(),n=t.offset;let r,i;if(n===e.getChildrenSize()?(r=e.getChildAtIndex(n-1),i=!0):(r=e.getChildAtIndex(n),i=!1),Wn(r)){t.set(r.__key,i?r.getTextContentSize():0,"text",!0);break}if(!Yr(r))break;t.set(r.__key,i?r.getChildrenSize():0,"element",!0)}}let _t,pt,mt,yt,xt,vt,Ct,St,Tt,bt,kt="",Nt="",wt=null,Et="",Pt="",Ft=!1,Lt=!1,Ot=null;function At(t,e){const n=Ct.get(t);if(null!==e){const n=Qt(t);n.parentNode===e&&e.removeChild(n)}if(St.has(t)||pt._keyToDOMMap.delete(t),Yr(n)){const t=Ut(n,Ct);Mt(t,0,t.length-1,null)}void 0!==n&&ds(bt,mt,yt,n,"destroyed")}function Mt(t,e,n,r){let i=e;for(;i<=n;++i){const e=t[i];void 0!==e&&At(e,r)}}function It(t,e){t.setProperty("text-align",e)}const Dt="40px";function zt(t,e){const n=_t.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")||Dt;t.style.setProperty("padding-inline-start",0===e?"":`calc(${e} * ${r})`)}function Bt(t,e){const n=t.style;0===e?It(n,""):e===A?It(n,"left"):e===M?It(n,"center"):e===I?It(n,"right"):e===D?It(n,"justify"):e===z?It(n,"start"):e===B&&It(n,"end")}function Wt(t,n){const r=St.get(t);void 0===r&&e(60);const i=r.createDOM(_t,pt);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)}(t,i,pt),Wn(r)?i.setAttribute("data-lexical-text","true"):ei(r)&&i.setAttribute("data-lexical-decorator","true"),Yr(r)){const t=r.__indent,e=r.__size;if(0!==t&&zt(i,t),0!==e){const t=e-1;!function(t,e,n,r){const i=Nt;Nt="",Rt(t,n,0,e,n.getDOMSlot(r)),jt(n,r),Nt=i}(Ut(r,St),t,r,i)}const n=r.__format;0!==n&&Bt(i,n),r.isInline()||Jt(null,r,i),ys(r)&&(kt+=R,Pt+=R)}else{const e=r.getTextContent();if(ei(r)){const e=r.decorate(pt,_t);null!==e&&Ht(t,e),i.contentEditable="false"}else Wn(r)&&(r.isDirectionless()||(Nt+=e));kt+=e,Pt+=e}return null!==n&&n.insertChild(i),ds(bt,mt,yt,r,"created"),i}function Rt(t,e,n,r,i){const s=kt;kt="";let o=n;for(;o<=r;++o){Wt(t[o],i);const e=St.get(t[o]);null!==e&&Wn(e)&&(null===wt&&(wt=e.getFormat()),""===Et&&(Et=e.getStyle()))}ys(e)&&(kt+=R);i.element.__lexicalTextContent=kt,kt=s+kt}function Kt(t,e){if(t){const n=t.__last;if(n){const t=e.get(n);if(t)return Cn(t)?"line-break":ei(t)&&t.isInline()?"decorator":null}return"empty"}return null}function Jt(t,e,n){const r=Kt(t,Ct),i=Kt(e,St);r!==i&&e.getDOMSlot(n).setManagedLineBreak(i)}function jt(t,e){const n=e.__lexicalDirTextContent||"",r=e.__lexicalDir||"";if(n!==Nt||r!==Ot){const n=""===Nt,i=n?Ot:function(t){if($.test(t))return"rtl";if(U.test(t))return"ltr";return null}(Nt);if(i!==r){const s=e.classList,o=_t.theme;let l=null!==r?o[r]:void 0,c=null!==i?o[i]:void 0;if(void 0!==l){if("string"==typeof l){const t=h(l);l=o[r]=t}s.remove(...l)}if(null===i||n&&"ltr"===i)e.removeAttribute("dir");else{if(void 0!==c){if("string"==typeof c){const t=h(c);c=o[i]=t}void 0!==c&&s.add(...c)}e.dir=i}if(!Lt){t.getWritable().__dir=i}}Ot=i,e.__lexicalDirTextContent=Nt,e.__lexicalDir=i}}function $t(t,n,r){const i=Nt;var s;Nt="",wt=null,Et="",function(t,n,r){const i=kt,s=t.__size,o=n.__size;kt="";const l=r.element;if(1===s&&1===o){const e=t.__first,r=n.__first;if(e===r)Vt(e,l);else{const t=Qt(e),n=Wt(r,null);try{l.replaceChild(n,t)}catch(i){if("object"==typeof i&&null!=i){const s=`${i.toString()} Parent: ${l.tagName}, new child: {tag: ${n.tagName} key: ${r}}, old child: {tag: ${t.tagName}, key: ${e}}.`;throw new Error(s)}throw i}At(e,null)}const i=St.get(r);Wn(i)&&(null===wt&&(wt=i.getFormat()),""===Et&&(Et=i.getStyle()))}else{const i=Ut(t,Ct),c=Ut(n,St);if(i.length!==s&&e(227),c.length!==o&&e(228),0===s)0!==o&&Rt(c,n,0,o-1,r);else if(0===o){if(0!==s){const t=null==r.after&&null==r.before&&null==r.element.__lexicalLineBreak;Mt(i,0,s-1,t?null:l),t&&(l.textContent="")}}else!function(t,e,n,r,i,s){const o=r-1,l=i-1;let c,a,u=s.getFirstChild(),f=0,d=0;for(;f<=o&&d<=l;){const t=e[f],r=n[d];if(t===r)u=qt(Vt(r,s.element)),f++,d++;else{void 0===c&&(c=new Set(e)),void 0===a&&(a=new Set(n));const i=a.has(t),o=c.has(r);if(i)if(o){const t=xs(pt,r);t===u?u=qt(Vt(r,s.element)):(s.withBefore(u).insertChild(t),Vt(r,s.element)),f++,d++}else Wt(r,s.withBefore(u)),d++;else u=qt(Qt(t)),At(t,s.element),f++}const i=St.get(r);null!==i&&Wn(i)&&(null===wt&&(wt=i.getFormat()),""===Et&&(Et=i.getStyle()))}const h=f>o,g=d>l;if(h&&!g){const e=n[l+1],r=void 0===e?null:pt.getElementByKey(e);Rt(n,t,d,l,s.withBefore(r))}else g&&!h&&Mt(e,f,o,s.element)}(n,i,c,s,o,r)}ys(n)&&(kt+=R);l.__lexicalTextContent=kt,kt=i+kt}(t,n,n.getDOMSlot(r)),jt(n,r),s=n,null==wt||wt===s.__textFormat||Lt||(s.setTextFormat(wt),s.setTextStyle(Et)),function(t){""===Et||Et===t.__textStyle||Lt||t.setTextStyle(Et)}(n),Nt=i}function Ut(t,n){const r=[];let i=t.__first;for(;null!==i;){const t=n.get(i);void 0===t&&e(101),r.push(i),i=t.__next}return r}function Vt(t,n){const r=Ct.get(t);let i=St.get(t);void 0!==r&&void 0!==i||e(61);const s=Ft||vt.has(t)||xt.has(t),o=xs(pt,t);if(r===i&&!s){if(Yr(r)){const t=o.__lexicalTextContent;void 0!==t&&(kt+=t,Pt+=t);const e=o.__lexicalDirTextContent;void 0!==e&&(Nt+=e)}else{const t=r.getTextContent();Wn(r)&&!r.isDirectionless()&&(Nt+=t),Pt+=t,kt+=t}return o}if(r!==i&&s&&ds(bt,mt,yt,i,"updated"),i.updateDOM(r,o,_t)){const r=Wt(t,null);return null===n&&e(62),n.replaceChild(r,o),At(t,null),r}if(Yr(r)&&Yr(i)){const t=i.__indent;t!==r.__indent&&zt(o,t);const e=i.__format;e!==r.__format&&Bt(o,e),s&&($t(r,i,o),ri(i)||i.isInline()||Jt(r,i,o)),ys(i)&&(kt+=R,Pt+=R)}else{const e=i.getTextContent();if(ei(i)){const e=i.decorate(pt,_t);null!==e&&Ht(t,e)}else Wn(i)&&!i.isDirectionless()&&(Nt+=e);kt+=e,Pt+=e}if(!Lt&&ri(i)&&i.__cachedText!==Pt){const t=i.getWritable();t.__cachedText=Pt,i=t}return o}function Ht(t,e){let n=pt._pendingDecorators;const r=pt._decorators;if(null===n){if(r[t]===e)return;n=$i(pt)}n[t]=e}function qt(t){let e=t.nextSibling;return null!==e&&e===pt._blockCursorElement&&(e=e.nextSibling),e}function Gt(t,e,n,r,i,s){kt="",Pt="",Nt="",Ft=r===v,Ot=null,pt=n,_t=n._config,mt=n._nodes,yt=pt._listeners.mutation,xt=i,vt=s,Ct=t._nodeMap,St=e._nodeMap,Lt=e._readOnly,Tt=new Map(n._keyToDOMMap);const o=new Map;return bt=o,Vt("root",null),pt=void 0,mt=void 0,xt=void 0,vt=void 0,Ct=void 0,St=void 0,_t=void 0,Tt=void 0,bt=void 0,o}function Qt(t){const n=Tt.get(t);return void 0===n&&e(75,t),n}function Xt(t){return{}}const Yt={},Zt={},te={},ee={},ne={},re={},ie={},se={},oe={},le={},ce={},ae={},ue={},fe={},de={},he={},ge={},_e={},pe={},me={},ye={},xe={},ve={},Ce={},Se={},Te={},be={},ke={},Ne={},we={},Ee={},Pe={},Fe={},Le={},Oe={},Ae={},Me={},Ie={},De={},ze={},Be={},We={},Re={},Ke={},Je={},je=Object.freeze({}),$e=30,Ue=[["keydown",function(t,e){if(Ve=t.timeStamp,He=t.key,e.isComposing())return;const{key:n,shiftKey:r,ctrlKey:o,metaKey:l,altKey:c}=t;if(ms(e,de,t))return;if(null==n)return;if(en&&ls(He))return qr(e,(()=>{an(e,nn)})),en=!1,void(nn="");if(function(t,e,n,r){return is(t)&&!e&&!r&&!n}(n,o,c,l))ms(e,he,t);else if(function(t,e,n,r,i){return is(t)&&!r&&!n&&(e||i)}(n,o,r,c,l))ms(e,ge,t);else if(function(t,e,n,r){return rs(t)&&!e&&!r&&!n}(n,o,c,l))ms(e,_e,t);else if(function(t,e,n,r,i){return rs(t)&&!r&&!n&&(e||i)}(n,o,r,c,l))ms(e,pe,t);else if(function(t,e,n){return function(t){return"ArrowUp"===t}(t)&&!e&&!n}(n,o,l))ms(e,me,t);else if(function(t,e,n){return function(t){return"ArrowDown"===t}(t)&&!e&&!n}(n,o,l))ms(e,ye,t);else if(function(t,e){return os(t)&&e}(n,r))Ze=!0,ms(e,xe,t);else if(function(t){return" "===t}(n))ms(e,ve,t);else if(function(t,e){return i&&e&&"o"===t.toLowerCase()}(n,o))t.preventDefault(),Ze=!0,ms(e,ne,!0);else if(function(t,e){return os(t)&&!e}(n,r))Ze=!1,ms(e,xe,t);else if(function(t,e,n,r){if(i)return!e&&!n&&(ls(t)||"h"===t.toLowerCase()&&r);if(r||e||n)return!1;return ls(t)}(n,c,l,o))ls(n)?ms(e,Ce,t):(t.preventDefault(),ms(e,ee,!0));else if(function(t){return"Escape"===t}(n))ms(e,Se,t);else if(function(t,e,n,r,s){if(i)return!(n||r||s)&&(cs(t)||"d"===t.toLowerCase()&&e);if(e||r||s)return!1;return cs(t)}(n,o,r,c,l))cs(n)?ms(e,Te,t):(t.preventDefault(),ms(e,ee,!1));else if(function(t,e,n){return ls(t)&&(i?e:n)}(n,c,o))t.preventDefault(),ms(e,le,!0);else if(function(t,e,n){return cs(t)&&(i?e:n)}(n,c,o))t.preventDefault(),ms(e,le,!1);else if(function(t,e){return i&&e&&ls(t)}(n,l))t.preventDefault(),ms(e,ce,!0);else if(function(t,e){return i&&e&&cs(t)}(n,l))t.preventDefault(),ms(e,ce,!1);else if(function(t,e,n,r){return"b"===t.toLowerCase()&&!e&&ss(n,r)}(n,c,l,o))t.preventDefault(),ms(e,ae,"bold");else if(function(t,e,n,r){return"u"===t.toLowerCase()&&!e&&ss(n,r)}(n,c,l,o))t.preventDefault(),ms(e,ae,"underline");else if(function(t,e,n,r){return"i"===t.toLowerCase()&&!e&&ss(n,r)}(n,c,l,o))t.preventDefault(),ms(e,ae,"italic");else if(function(t,e,n,r){return"Tab"===t&&!e&&!n&&!r}(n,c,o,l))ms(e,be,t);else if(function(t,e,n,r){return"z"===t.toLowerCase()&&!e&&ss(n,r)}(n,r,l,o))t.preventDefault(),ms(e,ue,void 0);else if(function(t,e,n,r){if(i)return"z"===t.toLowerCase()&&n&&e;return"y"===t.toLowerCase()&&r||"z"===t.toLowerCase()&&r&&e}(n,r,l,o))t.preventDefault(),ms(e,fe,void 0);else{const c=e._editorState._selection;null===c||Gn(c)?!s&&as(n,l,o)&&(t.preventDefault(),ms(e,Ie,t)):!function(t,e,n,r){if(e)return!1;if("c"===t.toLowerCase())return i?n:r;return!1}(n,r,l,o)?!function(t,e,n,r){if(e)return!1;if("x"===t.toLowerCase())return i?n:r;return!1}(n,r,l,o)?as(n,l,o)&&(t.preventDefault(),ms(e,Ie,t)):(t.preventDefault(),ms(e,Me,t)):(t.preventDefault(),ms(e,Ae,t))}(function(t,e,n,r){return t||e||n||r})(o,r,c,l)&&ms(e,Je,t)}],["pointerdown",function(t,e){const n=t.target,r=t.pointerType;Js(n)&&"touch"!==r&&0===t.button&&qr(e,(()=>{ei(ji(n))||(Ye=!0)}))}],["compositionstart",function(t,e){qr(e,(()=>{const n=hr();if(Gn(n)&&!e.isComposing()){const r=n.anchor,i=n.anchor.getNode();Bi(r.key),(t.timeStamp<Ve+$e||"element"===r.type||!n.isCollapsed()||i.getFormat()!==n.format||Wn(i)&&i.getStyle()!==n.style)&&ms(e,ie,K)}}))}],["compositionend",function(t,e){s?tn=!0:c||!l&&!d?qr(e,(()=>{an(e,t.data)})):(en=!0,nn=t.data)}],["input",function(t,e){t.stopPropagation(),qr(e,(()=>{const n=hr(),r=t.data,i=cn(t);if(null!=r&&Gn(n)&&sn(n,i,r,t.timeStamp,!1)){tn&&(an(e,r),tn=!1);const i=n.anchor.getNode(),a=zs(ws(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;o&&!n.isCollapsed()&&Wn(i)&&null!==a.anchorNode&&i.getTextContent().slice(0,f)+r+i.getTextContent().slice(f+h)===ts(a.anchorNode)||ms(e,ie,r);const g=r.length;s&&g>1&&"insertCompositionText"===t.inputType&&!e.isComposing()&&(n.anchor.offset-=g),l||c||d||!e.isComposing()||(Ve=0,Bi(null))}else{es(!1,e,null!==r?r:void 0),tn&&(an(e,r||void 0),tn=!1)}!function(){Lr();const t=Mr();ct(t)}()}),{event:t}),Ge=null}],["click",function(t,e){qr(e,(()=>{const n=hr(),r=zs(ws(e)),i=gr();if(r)if(Gn(n)){const e=n.anchor,s=e.getNode();if("element"===e.type&&0===e.offset&&n.isCollapsed()&&!ri(s)&&1===Vi().getChildrenSize()&&s.getTopLevelElementOrThrow().isEmpty()&&null!==i&&n.is(i))r.removeAllRanges(),n.dirty=!0;else if(3===t.detail&&!n.isCollapsed()){if(s!==n.focus.getNode()){const t=function(t,e){let n=t;for(;n!==Vi()&&null!=n;){if(e(n))return n;n=n.getParent()}return null}(s,(t=>Yr(t)&&!t.isInline()));Yr(t)&&t.select(0)}}}else if("touch"===t.pointerType){const n=r.anchorNode;if(Ks(n)||Fi(n)){qi(dr(i,r,e,t))}}ms(e,te,t)}))}],["cut",je],["copy",je],["dragstart",je],["dragover",je],["dragend",je],["paste",je],["focus",je],["blur",je],["drop",je]];o&&Ue.push(["beforeinput",(t,n)=>function(t,n){const r=t.inputType,i=cn(t);if("deleteCompositionText"===r||s&&ps(n))return;if("insertCompositionText"===r)return;qr(n,(()=>{const s=hr();if("deleteContentBackward"===r){if(null===s){const t=gr();if(!Gn(t))return;qi(t.clone())}if(Gn(s)){const r=s.anchor.key===s.focus.key;if(o=t.timeStamp,"MediaLast"===He&&o<Ve+$e&&n.isComposing()&&r){if(Bi(null),Ve=0,setTimeout((()=>{qr(n,(()=>{Bi(null)}))}),$e),Gn(s)){const t=s.anchor.getNode();t.markDirty(),s.format=t.getFormat(),Wn(t)||e(142),s.style=t.getStyle()}}else{Bi(null),t.preventDefault();const e=s.anchor.getNode(),i=e.getTextContent(),o=e.canInsertTextAfter(),l=0===s.anchor.offset&&s.focus.offset===i.length;let c=f&&r&&!l&&o;c&&s.isCollapsed()&&(c=!ei(_s(s.anchor,!0))),c||ms(n,ee,!0)}return}}var o;if(!Gn(s))return;const l=t.data;null!==Ge&&es(!1,n,Ge),s.dirty&&null===Ge||!s.isCollapsed()||ri(s.anchor.getNode())||null===i||s.applyDOMRange(i),Ge=null;const a=s.anchor,u=s.focus,d=a.getNode(),h=u.getNode();if("insertText"!==r&&"insertTranspose"!==r)switch(t.preventDefault(),r){case"insertFromYank":case"insertFromDrop":case"insertReplacementText":ms(n,ie,t);break;case"insertFromComposition":Bi(null),ms(n,ie,t);break;case"insertLineBreak":Bi(null),ms(n,ne,!1);break;case"insertParagraph":Bi(null),Ze&&!c?(Ze=!1,ms(n,ne,!1)):ms(n,re,void 0);break;case"insertFromPaste":case"insertFromPasteAsQuotation":ms(n,se,t);break;case"deleteByComposition":(function(t,e){return t!==e||Yr(t)||Yr(e)||!t.isToken()||!e.isToken()})(d,h)&&ms(n,oe,t);break;case"deleteByDrag":case"deleteByCut":ms(n,oe,t);break;case"deleteContent":ms(n,ee,!1);break;case"deleteWordBackward":ms(n,le,!0);break;case"deleteWordForward":ms(n,le,!1);break;case"deleteHardLineBackward":case"deleteSoftLineBackward":ms(n,ce,!0);break;case"deleteContentForward":case"deleteHardLineForward":case"deleteSoftLineForward":ms(n,ce,!1);break;case"formatStrikeThrough":ms(n,ae,"strikethrough");break;case"formatBold":ms(n,ae,"bold");break;case"formatItalic":ms(n,ae,"italic");break;case"formatUnderline":ms(n,ae,"underline");break;case"historyUndo":ms(n,ue,void 0);break;case"historyRedo":ms(n,fe,void 0)}else{if("\n"===l)t.preventDefault(),ms(n,ne,!1);else if(l===R)t.preventDefault(),ms(n,re,void 0);else if(null==l&&t.dataTransfer){const e=t.dataTransfer.getData("text/plain");t.preventDefault(),s.insertRawText(e)}else null!=l&&sn(s,i,l,t.timeStamp,!0)?(t.preventDefault(),ms(n,ie,l)):Ge=l;qe=t.timeStamp}}))}(t,n)]);let Ve=0,He=null,qe=0,Ge=null;const Qe=new WeakMap;let Xe=!1,Ye=!1,Ze=!1,tn=!1,en=!1,nn="",rn=[0,"",0,"root",0];function sn(t,e,n,r,i){const s=t.anchor,l=t.focus,c=s.getNode(),a=Mr(),u=zs(ws(a)),f=null!==u?u.anchorNode:null,d=s.key,h=a.getElementByKey(d),g=n.length;return d!==l.key||!Wn(c)||(!i&&(!o||qe<r+50)||c.isDirty()&&g<2||Xi(n))&&s.offset!==l.offset&&!c.isComposing()||Pi(c)||c.isDirty()&&g>1||(i||!o)&&null!==h&&!c.isComposing()&&f!==Oi(h)||null!==u&&null!==e&&(!e.collapsed||e.startContainer!==u.anchorNode||e.startOffset!==u.anchorOffset)||c.getFormat()!==t.format||c.getStyle()!==t.style||function(t,e){if(e.isSegmented())return!0;if(!t.isCollapsed())return!1;const n=t.anchor.offset,r=e.getParentOrThrow(),i=e.isToken();return 0===n?!e.canInsertTextBefore()||!r.canInsertTextBefore()&&!e.isComposing()||i||function(t){const e=t.getPreviousSibling();return(Wn(e)||Yr(e)&&e.isInline())&&!e.canInsertTextAfter()}(e):n===e.getTextContentSize()&&(!e.canInsertTextAfter()||!r.canInsertTextAfter()&&!e.isComposing()||i)}(t,c)}function on(t,e){return Fi(t)&&null!==t.nodeValue&&0!==e&&e!==t.nodeValue.length}function ln(t,n,r){const{anchorNode:i,anchorOffset:s,focusNode:o,focusOffset:l}=t;Xe&&(Xe=!1,on(i,s)&&on(o,l))||qr(n,(()=>{if(!r)return void qi(null);if(!ki(n,i,o))return;const c=hr();if(Gn(c)){const r=c.anchor,i=r.getNode();if(c.isCollapsed()){"Range"===t.type&&t.anchorNode===t.focusNode&&(c.dirty=!0);const s=ws(n).event,o=s?s.timeStamp:performance.now(),[l,a,u,f,d]=rn,h=Vi(),g=!1===n.isComposing()&&""===h.getTextContent();if(o<d+200&&r.offset===u&&r.key===f)c.format=l,c.style=a;else if("text"===r.type)Wn(i)||e(141),c.format=i.getFormat(),c.style=i.getStyle();else if("element"===r.type&&!g){Yr(i)||e(259);const t=r.getNode();c.style="",t.isEmpty()?(c.format=t.getTextFormat(),c.style=t.getTextStyle()):c.format=0}}else{const t=r.key,e=c.focus.key,n=c.getNodes(),i=n.length,o=c.isBackward(),a=o?l:s,u=o?s:l,f=o?e:t,d=o?t:e;let h=O,g=!1;for(let t=0;t<i;t++){const e=n[t],r=e.getTextContentSize();if(Wn(e)&&0!==r&&!(0===t&&e.__key===f&&a===r||t===i-1&&e.__key===d&&0===u)&&(g=!0,h&=e.getFormat(),0===h))break}c.format=g?h:0}}ms(n,Yt,void 0)}))}function cn(t){if(!t.getTargetRanges)return null;const e=t.getTargetRanges();return 0===e.length?null:e[0]}function an(t,e){const n=t._compositionKey;if(Bi(null),null!==n&&null!=e){if(""===e){const e=Ri(n),r=Oi(t.getElementByKey(n));return void(null!==r&&null!==r.nodeValue&&Wn(e)&&ns(e,r.nodeValue,null,null,!0))}if("\n"===e[e.length-1]){const e=hr();if(Gn(e)){const n=e.focus;return e.anchor.set(n.key,n.offset,n.type),void ms(t,xe,null)}}}es(!0,t,e)}function un(t){let e=t.__lexicalEventHandles;return void 0===e&&(e=[],t.__lexicalEventHandles=e),e}const fn=new Map;function dn(t){const e=Bs(t.target);if(null===e)return;const n=wi(e.anchorNode);if(null===n)return;Ye&&(Ye=!1,qr(n,(()=>{const r=gr(),i=e.anchorNode;if(Ks(i)||Fi(i)){qi(dr(r,e,n,t))}})));const r=Yi(n),i=r[r.length-1],s=i._key,o=fn.get(s),l=o||i;l!==n&&ln(e,l,!1),ln(e,n,!0),n!==i?fn.set(s,n):o&&fn.delete(s)}function hn(t){t._lexicalHandled=!0}function gn(t){return!0===t._lexicalHandled}function _n(t){const n=t.ownerDocument,r=Qe.get(n);void 0===r&&e(162);const i=r-1;i>=0||e(164),Qe.set(n,i),0===i&&n.removeEventListener("selectionchange",dn);const s=Ei(t);Ni(s)?(!function(t){if(null!==t._parentEditor){const e=Yi(t),n=e[e.length-1]._key;fn.get(n)===t&&fn.delete(n)}else fn.delete(t._key)}(s),t.__lexicalEditor=null):s&&e(198);const o=un(t);for(let t=0;t<o.length;t++)o[t]();t.__lexicalEventHandles=[]}function pn(t,e,n){Lr();const r=t.__key,i=t.getParent();if(null===i)return;const s=function(t){const e=hr();if(!Gn(e)||!Yr(t))return e;const{anchor:n,focus:r}=e,i=n.getNode(),s=r.getNode();ks(i,t)&&n.set(t.__key,0,"element");ks(s,t)&&r.set(t.__key,0,"element");return e}(t);let o=!1;if(Gn(s)&&e){const e=s.anchor,n=s.focus;e.key===r&&(mr(e,t,i,t.getPreviousSibling(),t.getNextSibling()),o=!0),n.key===r&&(mr(n,t,i,t.getPreviousSibling(),t.getNextSibling()),o=!0)}else Xn(s)&&e&&t.isSelected()&&t.selectPrevious();if(Gn(s)&&e&&!o){const e=t.getIndexWithinParent();Di(t),_r(s,i,e,-1)}else Di(t);n||Fs(i)||i.canBeEmpty()||!i.isEmpty()||pn(i,e),e&&ri(i)&&i.isEmpty()&&i.selectEnd()}class mn{static getType(){e(64,this.name)}static clone(t){e(65,this.name)}afterCloneFrom(t){this.__parent=t.__parent,this.__next=t.__next,this.__prev=t.__prev}constructor(t){this.__type=this.constructor.getType(),this.__parent=null,this.__prev=null,this.__next=null,Ii(this,t)}getType(){return this.__type}isInline(){e(137,this.constructor.name)}isAttached(){let t=this.__key;for(;null!==t;){if("root"===t)return!0;const e=Ri(t);if(null===e)break;t=e.__parent}return!1}isSelected(t){const e=t||hr();if(null==e)return!1;const n=e.getNodes().some((t=>t.__key===this.__key));if(Wn(this))return n;if(Gn(e)&&"element"===e.anchor.type&&"element"===e.focus.type){if(e.isCollapsed())return!1;const t=this.getParent();if(ei(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:Ri(t)}getParentOrThrow(){const t=this.getParent();return null===t&&e(66,this.__key),t}getTopLevelElement(){let t=this;for(;null!==t;){const n=t.getParent();if(Fs(n))return Yr(t)||t===this&&ei(t)||e(194),t;t=n}return null}getTopLevelElementOrThrow(){const t=this.getTopLevelElement();return null===t&&e(67,this.__key),t}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:Ri(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:Ri(t)}getNextSiblings(){const t=[];let e=this.getNextSibling();for(;null!==e;)t.push(e),e=e.getNextSibling();return t}getCommonAncestor(t){const e=this.getParents(),n=t.getParents();Yr(this)&&e.unshift(this),Yr(t)&&n.unshift(t);const r=e.length,i=n.length;if(0===r||0===i||e[r-1]!==n[i-1])return null;const s=new Set(n);for(let t=0;t<r;t++){const n=e[t];if(s.has(n))return n}return null}is(t){return null!=t&&this.__key===t.__key}isBefore(t){if(this===t)return!1;if(t.isParentOf(this))return!0;if(this.isParentOf(t))return!1;const e=this.getCommonAncestor(t);let n=0,r=0,i=this;for(;;){const t=i.getParentOrThrow();if(t===e){n=i.getIndexWithinParent();break}i=t}for(i=t;;){const t=i.getParentOrThrow();if(t===e){r=i.getIndexWithinParent();break}i=t}return n<r}isParentOf(t){const e=this.__key;if(e===t.__key)return!1;let n=t;for(;null!==n;){if(n.__key===e)return!0;n=n.getParent()}return!1}getNodesBetween(t){const n=this.isBefore(t),r=[],i=new Set;let s=this;for(;null!==s;){const o=s.__key;if(i.has(o)||(i.add(o),r.push(s)),s===t)break;const l=Yr(s)?n?s.getFirstChild():s.getLastChild():null;if(null!==l){s=l;continue}const c=n?s.getNextSibling():s.getPreviousSibling();if(null!==c){s=c;continue}const a=s.getParentOrThrow();if(i.has(a.__key)||r.push(a),a===t)break;let u=null,f=a;do{if(null===f&&e(68),u=n?f.getNextSibling():f.getPreviousSibling(),f=f.getParent(),null===f)break;null!==u||i.has(f.__key)||r.push(f)}while(null===u);s=u}return n||r.reverse(),r}isDirty(){const t=Mr()._dirtyLeaves;return null!==t&&t.has(this.__key)}getLatest(){const t=Ri(this.__key);return null===t&&e(113),t}getWritable(){Lr();const t=Ar(),e=Mr(),n=t._nodeMap,r=this.__key,i=this.getLatest(),s=e._cloneNotNeeded,o=hr();if(null!==o&&o.setCachedNodes(null),s.has(r))return zi(i),i;const l=Ys(i);return s.add(r),zi(l),n.set(r,l),l}getTextContent(){return""}getTextContentSize(){return this.getTextContent().length}createDOM(t,n){e(70)}updateDOM(t,n,r){e(71)}exportDOM(t){return{element:this.createDOM(t._config,t)}}exportJSON(){return{type:this.__type,version:1}}static importJSON(t){e(18,this.name)}updateFromJSON(t){return this}static transform(){return null}remove(t){pn(this,!0,t)}replace(t,n){Lr();let r=hr();null!==r&&(r=r.clone()),As(this,t);const i=this.getLatest(),s=this.__key,o=t.__key,l=t.getWritable(),c=this.getParentOrThrow().getWritable(),a=c.__size;Di(l);const u=i.getPreviousSibling(),f=i.getNextSibling(),d=i.__prev,h=i.__next,g=i.__parent;if(pn(i,!1,!0),null===u)c.__first=o;else{u.getWritable().__next=o}if(l.__prev=d,null===f)c.__last=o;else{f.getWritable().__prev=o}if(l.__next=h,l.__parent=g,c.__size=a,n&&(Yr(this)&&Yr(l)||e(139),this.getChildren().forEach((t=>{l.append(t)}))),Gn(r)){qi(r);const t=r.anchor,e=r.focus;t.key===s&&Hn(t,l),e.key===s&&Hn(e,l)}return Wi()===s&&Bi(o),l}insertAfter(t,e=!0){Lr(),As(this,t);const n=this.getWritable(),r=t.getWritable(),i=r.getParent(),s=hr();let o=!1,l=!1;if(null!==i){const e=t.getIndexWithinParent();if(Di(r),Gn(s)){const t=i.__key,n=s.anchor,r=s.focus;o="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&&Gn(s)){const t=this.getIndexWithinParent();_r(s,a,t+1);const e=a.__key;o&&s.anchor.set(e,t+2,"element"),l&&s.focus.set(e,t+2,"element")}return t}insertBefore(t,e=!0){Lr(),As(this,t);const n=this.getWritable(),r=t.getWritable(),i=r.__key;Di(r);const s=this.getPreviousSibling(),o=this.getParentOrThrow().getWritable(),l=n.__prev,c=this.getIndexWithinParent();if(null===s)o.__first=i;else{s.getWritable().__next=i}o.__size++,n.__prev=i,r.__prev=l,r.__next=n.__key,r.__parent=n.__parent;const a=hr();if(e&&Gn(a)){_r(a,this.getParentOrThrow(),c)}return t}isParentRequired(){return!1}createParentElementNode(){return fi()}selectStart(){return this.selectPrevious()}selectEnd(){return this.selectNext(0,0)}selectPrevious(t,e){Lr();const n=this.getPreviousSibling(),r=this.getParentOrThrow();if(null===n)return r.select(0,0);if(Yr(n))return n.select();if(!Wn(n)){const t=n.getIndexWithinParent()+1;return r.select(t,t)}return n.select(t,e)}selectNext(t,e){Lr();const n=this.getNextSibling(),r=this.getParentOrThrow();if(null===n)return r.select();if(Yr(n))return n.select(0,0);if(!Wn(n)){const t=n.getIndexWithinParent();return r.select(t,t)}return n.select(t,e)}markDirty(){this.getWritable()}reconcileObservedMutation(t,e){this.markDirty()}}class yn extends mn{static getType(){return"linebreak"}static clone(t){return new yn(t.__key)}constructor(t){super(t)}getTextContent(){return"\n"}createDOM(){return document.createElement("br")}updateDOM(){return!1}static importDOM(){return{br:t=>function(t){const e=t.parentElement;if(null!==e&&Us(e)){const n=e.firstChild;if(n===t||n.nextSibling===t&&Sn(n)){const n=e.lastChild;if(n===t||n.previousSibling===t&&Sn(n))return!0}}return!1}(t)||function(t){const e=t.parentElement;if(null!==e&&Us(e)){const n=e.firstChild;if(n===t||n.nextSibling===t&&Sn(n))return!1;const r=e.lastChild;if(r===t||r.previousSibling===t&&Sn(r))return!0}return!1}(t)?null:{conversion:xn,priority:0}}}static importJSON(t){return vn().updateFromJSON(t)}}function xn(t){return{node:vn()}}function vn(){return Os(new yn)}function Cn(t){return t instanceof yn}function Sn(t){return Fi(t)&&/^( |\t|\r?\n)+$/.test(t.textContent||"")}function Tn(t,e){return 16&e?"code":e&L?"mark":32&e?"sub":64&e?"sup":null}function bn(t,e){return 1&e?"strong":2&e?"em":"span"}function kn(t,e,n,r,i){const s=r.classList;let o=fs(i,"base");void 0!==o&&s.add(...o),o=fs(i,"underlineStrikethrough");let l=!1;const c=e&w&&e&N;void 0!==o&&(n&w&&n&N?(l=!0,c||s.add(...o)):c&&s.remove(...o));for(const t in V){const r=V[t];if(o=fs(i,t),void 0!==o)if(n&r){if(l&&("underline"===t||"strikethrough"===t)){e&r&&s.remove(...o);continue}e&r&&(!c||"underline"!==t)&&"strikethrough"!==t||s.add(...o)}else e&r&&s.remove(...o)}}function Nn(t,e,n){const r=e.firstChild,i=n.isComposing(),o=t+(i?W:"");if(null==r)e.textContent=o;else{const t=r.nodeValue;if(t!==o)if(i||s){const[e,n,i]=function(t,e){const n=t.length,r=e.length;let i=0,s=0;for(;i<n&&i<r&&t[i]===e[i];)i++;for(;s+i<n&&s+i<r&&t[n-s-1]===e[r-s-1];)s++;return[i,n-i-s,e.slice(i,r-s)]}(t,o);0!==n&&r.deleteData(e,n),r.insertData(e,i)}else r.nodeValue=o}}function wn(t,e,n,r,i,s){Nn(i,t,e);const o=s.theme.text;void 0!==o&&kn(0,0,r,t,o)}function En(t,e){const n=document.createElement(e);return n.appendChild(t),n}class Pn extends mn{static getType(){return"text"}static clone(t){return new Pn(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 X[t.__mode]}getStyle(){return this.getLatest().__style}isToken(){return 1===this.getLatest().__mode}isComposing(){return this.__key===Wi()}isSegmented(){return 2===this.getLatest().__mode}isDirectionless(){return!!(1&this.getLatest().__detail)}isUnmergeable(){return!!(2&this.getLatest().__detail)}hasFormat(t){const e=V[t];return!!(this.getFormat()&e)}isSimpleText(){return"text"===this.__type&&0===this.__mode}getTextContent(){return this.getLatest().__text}getFormatFlags(t,e){return Ai(this.getLatest().__format,t,e)}canHaveFormat(){return!0}createDOM(t,e){const n=this.__format,r=Tn(0,n),i=bn(0,n),s=null===r?i:r,o=document.createElement(s);let l=o;this.hasFormat("code")&&o.setAttribute("spellcheck","false"),null!==r&&(l=document.createElement(i),o.appendChild(l));wn(l,this,0,n,this.__text,t);const c=this.__style;return""!==c&&(o.style.cssText=c),o}updateDOM(t,n,r){const i=this.__text,s=t.__format,o=this.__format,l=Tn(0,s),c=Tn(0,o),a=bn(0,s),u=bn(0,o);if((null===l?a:l)!==(null===c?u:c))return!0;if(l===c&&a!==u){const t=n.firstChild;null==t&&e(48);const s=document.createElement(u);return wn(s,this,0,o,i,r),n.replaceChild(s,t),!1}let f=n;null!==c&&null!==l&&(f=n.firstChild,null==f&&e(49)),Nn(i,f,this);const d=r.theme.text;void 0!==d&&s!==o&&kn(0,s,o,f,d);const h=t.__style,g=this.__style;return h!==g&&(n.style.cssText=g),!1}static importDOM(){return{"#text":()=>({conversion:Mn,priority:0}),b:()=>({conversion:Ln,priority:0}),code:()=>({conversion:zn,priority:0}),em:()=>({conversion:zn,priority:0}),i:()=>({conversion:zn,priority:0}),mark:()=>({conversion:zn,priority:0}),s:()=>({conversion:zn,priority:0}),span:()=>({conversion:Fn,priority:0}),strong:()=>({conversion:zn,priority:0}),sub:()=>({conversion:zn,priority:0}),sup:()=>({conversion:zn,priority:0}),u:()=>({conversion:zn,priority:0})}}static importJSON(t){return Bn().updateFromJSON(t)}updateFromJSON(t){return super.updateFromJSON(t).setTextContent(t.text).setFormat(t.format).setDetail(t.detail).setMode(t.mode).setStyle(t.style)}exportDOM(t){let{element:n}=super.exportDOM(t);return Ks(n)||e(132),n.style.whiteSpace="pre-wrap",this.hasFormat("bold")&&(n=En(n,"b")),this.hasFormat("italic")&&(n=En(n,"i")),this.hasFormat("strikethrough")&&(n=En(n,"s")),this.hasFormat("underline")&&(n=En(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?V[t]:t,e}setDetail(t){const e=this.getWritable();return e.__detail="string"==typeof t?H[t]:t,e}setStyle(t){const e=this.getWritable();return e.__style=t,e}toggleFormat(t){const e=Ai(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=Q[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){Lr();let n=t,r=e;const i=hr(),s=this.getTextContent(),o=this.__key;if("string"==typeof s){const t=s.length;void 0===n&&(n=t),void 0===r&&(r=t)}else n=0,r=0;if(!Gn(i))return cr(o,n,o,r,"text","text");{const t=Wi();t!==i.anchor.key&&t!==i.focus.key||Bi(o),i.setTextNodeRange(this,n,this,r)}return i}selectStart(){return this.select(0,0)}selectEnd(){const t=this.getTextContentSize();return this.select(t,t)}spliceText(t,e,n,r){const i=this.getWritable(),s=i.__text,o=n.length;let l=t;l<0&&(l=o+l,l<0&&(l=0));const c=hr();if(r&&Gn(c)){const e=t+o;c.setTextNodeRange(i,e,i,e)}const a=s.slice(0,l)+n+s.slice(l+e);return i.__text=a,i}canInsertTextBefore(){return!0}canInsertTextAfter(){return!0}splitText(...t){Lr();const e=this.getLatest(),n=e.getTextContent();if(""===n)return[];const r=e.__key,i=Wi(),s=n.length;t.sort(((t,e)=>t-e)),t.push(s);const o=[],l=t.length;for(let e=0,r=0;e<s&&r<=l;r++){const i=t[r];i>e&&(o.push(n.slice(e,i)),e=i)}const c=o.length;if(1===c)return[e];const a=o[0],u=e.getParent();let f;const d=e.getFormat(),h=e.getStyle(),g=e.__detail;let _=!1,p=null,m=null;const y=hr();if(Gn(y)){const[t,e]=y.isBackward()?[y.focus,y.anchor]:[y.anchor,y.focus];"text"===t.type&&t.key===r&&(p=t),"text"===e.type&&e.key===r&&(m=e)}e.isSegmented()?(f=Bn(a),f.__format=d,f.__style=h,f.__detail=g,_=!0):(f=e.getWritable(),f.__text=a);const x=[f];for(let t=1;t<c;t++){const e=Bn(o[t]);e.__format=d,e.__style=h,e.__detail=g;const n=e.__key;i===r&&Bi(n),x.push(e)}const v=p?p.offset:null,C=m?m.offset:null;let S=0;for(const t of x){if(!p&&!m)break;const e=S+t.getTextContentSize();if(null!==p&&null!==v&&v<=e&&v>=S&&(p.set(t.getKey(),v-S,"text"),v<e&&(p=null)),null!==m&&null!==C&&C<=e&&C>=S){m.set(t.getKey(),C-S,"text");break}S=e}if(null!==u){!function(t){const e=t.getPreviousSibling(),n=t.getNextSibling();null!==e&&zi(e);null!==n&&zi(n)}(this);const t=u.getWritable(),e=this.getIndexWithinParent();_?(t.splice(e,0,x),this.remove()):t.splice(e,1,x),Gn(y)&&_r(y,u,e,c-1)}return x}mergeWithSibling(t){const n=t===this.getPreviousSibling();n||t===this.getNextSibling()||e(50);const r=this.__key,i=t.__key,s=this.__text,o=s.length;Wi()===i&&Bi(r);const l=hr();if(Gn(l)){const e=l.anchor,s=l.focus;null!==e&&e.key===i&&yr(e,n,r,t,o),null!==s&&s.key===i&&yr(s,n,r,t,o)}const c=t.__text,a=n?c+s:s+c;this.setTextContent(a);const u=this.getWritable();return t.remove(),u}isTextEntity(){return!1}}function Fn(t){return{forChild:Rn(t.style),node:null}}function Ln(t){const e=t,n="normal"===e.style.fontWeight;return{forChild:Rn(e.style,n?void 0:"bold"),node:null}}const On=new WeakMap;function An(t){if(!Ks(t))return!1;if("PRE"===t.nodeName)return!0;const e=t.style.whiteSpace;return"string"==typeof e&&e.startsWith("pre")}function Mn(t){const n=t;null===t.parentElement&&e(129);let r=n.textContent||"";if(null!==function(t){let e,n=t.parentNode;const r=[t];for(;null!==n&&void 0===(e=On.get(n))&&!An(n);)r.push(n),n=n.parentNode;const i=void 0===e?n:e;for(let t=0;t<r.length;t++)On.set(r[t],i);return i}(n)){const t=r.split(/(\r?\n|\t)/),e=[],n=t.length;for(let r=0;r<n;r++){const n=t[r];"\n"===n||"\r\n"===n?e.push(vn()):"\t"===n?e.push(Jn()):""!==n&&e.push(Bn(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=In(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=In(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:Bn(r)}}function In(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,Ks(n)){const t=n.style.display;if(""===t&&!$s(n)||""!==t&&!t.startsWith("inline"))return null}let r=n;for(;null!==(r=e?n.firstChild:n.lastChild);)n=r;if(Fi(n))return n;if("BR"===n.nodeName)return null}}const Dn={code:"code",em:"italic",i:"italic",mark:"highlight",s:"strikethrough",strong:"bold",sub:"subscript",sup:"superscript",u:"underline"};function zn(t){const e=Dn[t.nodeName.toLowerCase()];return void 0===e?{node:null}:{forChild:Rn(t.style,e),node:null}}function Bn(t=""){return Os(new Pn(t))}function Wn(t){return t instanceof Pn}function Rn(t,e){const n=t.fontWeight,r=t.textDecoration.split(" "),i="700"===n||"bold"===n,s=r.includes("line-through"),o="italic"===t.fontStyle,l=r.includes("underline"),c=t.verticalAlign;return t=>Wn(t)?(i&&!t.hasFormat("bold")&&t.toggleFormat("bold"),s&&!t.hasFormat("strikethrough")&&t.toggleFormat("strikethrough"),o&&!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 Kn extends Pn{static getType(){return"tab"}static clone(t){return new Kn(t.__key)}constructor(t){super("\t",t),this.__detail=2}static importDOM(){return null}createDOM(t){const e=super.createDOM(t),n=fs(t.theme,"tab");if(void 0!==n){e.classList.add(...n)}return e}static importJSON(t){return Jn().updateFromJSON(t)}setTextContent(t){return"\t"!==t&&""!==t&&e(126),super.setTextContent(t)}setDetail(t){return 2!==t&&e(127),this}setMode(t){return"normal"!==t&&e(128),this}canInsertTextBefore(){return!1}canInsertTextAfter(){return!1}}function Jn(){return Os(new Kn)}function jn(t){return t instanceof Kn}class $n{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){let e=this.getNode(),n=t.getNode();const r=this.offset,i=t.offset;if(Yr(e)){const t=e.getDescendantByIndex(r);e=null!=t?t:e}if(Yr(n)){const t=n.getDescendantByIndex(i);n=null!=t?t:n}return e===n?r<i:e.isBefore(n)}getNode(){const t=Ri(this.key);return null===t&&e(20),t}set(t,e,n,r){const i=this._selection,s=this.key;r&&this.key===t&&this.offset===e&&this.type===n||(this.key=t,this.offset=e,this.type=n,Fr()||(Wi()===s&&Bi(t),null!==i&&(i.setCachedNodes(null),i.dirty=!0)))}}function Un(t,e,n){return new $n(t,e,n)}function Vn(t,e){let n=e.__key,r=t.offset,i="element";if(Wn(e)){i="text";const t=e.getTextContentSize();r>t&&(r=t)}else if(!Yr(e)){const t=e.getNextSibling();if(Wn(t))n=t.__key,r=0,i="text";else{const t=e.getParent();t&&(n=t.__key,r=e.getIndexWithinParent()+1)}}t.set(n,r,i)}function Hn(t,e){if(Yr(e)){const n=e.getLastDescendant();Yr(n)||Wn(n)?Vn(t,n):Vn(t,e)}else Vn(t,e)}class qn{constructor(t){this._cachedNodes=null,this._nodes=t,this.dirty=!1}getCachedNodes(){return this._cachedNodes}setCachedNodes(t){this._cachedNodes=t}is(t){if(!Xn(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 qn(new Set(this._nodes))}extract(){return this.getNodes()}insertRawText(t){}insertText(){}insertNodes(t){const e=this.getNodes(),n=e.length,r=e[n-1];let i;if(Wn(r))i=r.select();else{const t=r.getIndexWithinParent()+1;i=r.getParentOrThrow().select(t,t)}i.insertNodes(t);for(let t=0;t<n;t++)e[t].remove()}getNodes(){const t=this._cachedNodes;if(null!==t)return t;const e=this._nodes,n=[];for(const t of e){const e=Ri(t);null!==e&&n.push(e)}return Fr()||(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}}function Gn(t){return t instanceof Qn}class Qn{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!!Gn(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=this.anchor,n=this.focus,r=e.isBefore(n),i=r?e:n,s=r?n:e,o=i.getNode(),l=s.getNode();let c=o,a=l,u=!1;const f=new Set;if(Yr(o)&&(u=i.offset>0&&i.offset>=o.getChildrenSize(),c=o.getDescendantByIndex(i.offset)||o),Yr(l)){const t=l.getChildAtIndex(s.offset);if(t){f.add(t.getKey()),a=Yr(t)&&t.getFirstDescendant()||t;for(let e=a;e&&!e.is(t);e=e.getParent())f.add(e.getKey())}else{const t=s.offset>0&&l.getChildAtIndex(s.offset-1);if(t)a=Yr(t)&&t.getLastDescendant()||t;else{let t=l.getParent();for(;null!==t;t=t.getParent()){f.add(t.getKey());const e=t.getNextSibling();if(e){a=e;break}}l.isEmpty()&&l.is(a)||f.add(a.getKey())}}}let d;if(c.is(a)||this.isCollapsed())d=Yr(c)&&c.getChildrenSize()>0?[]:[c];else{if(d=c.getNodesBetween(a),f.size>0)for(;d.length>0&&f.has(d[d.length-1].getKey());)d.pop();if(u){const t=d.findIndex((t=>!t.is(c)&&!t.isBefore(c)));d.splice(0,t)}}return Fr()||(this._cachedNodes=d),d}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.length-1],r=this.anchor,i=this.focus,s=r.isBefore(i),[o,l]=Zn(this);let c="",a=!0;for(let u=0;u<t.length;u++){const f=t[u];if(Yr(f)&&!f.isInline())a||(c+="\n"),a=!f.isEmpty();else if(a=!1,Wn(f)){let t=f.getTextContent();f===e?f===n?"element"===r.type&&"element"===i.type&&i.offset!==r.offset||(t=o<l?t.slice(o,l):t.slice(l,o)):t=s?t.slice(o):t.slice(l):f===n&&(t=s?t.slice(0,l):t.slice(0,o)),c+=t}else!ei(f)&&!Cn(f)||f===n&&this.isCollapsed()||(c+=f.getTextContent())}return c}applyDOMRange(t){const e=Mr(),n=e.getEditorState()._selection,r=or(t.startContainer,t.startOffset,t.endContainer,t.endOffset,e,n);if(null===r)return;const[i,s]=r;this.anchor.set(i.key,i.offset,i.type,!0),this.focus.set(s.key,s.offset,s.type,!0),ht(this)}clone(){const t=this.anchor,e=this.focus;return new Qn(Un(t.key,t.offset,t.type),Un(e.key,e.offset,e.type),this.format,this.style)}toggleFormat(t){this.format=Ai(this.format,t,null),this.dirty=!0}setStyle(t){this.style=t,this.dirty=!0}hasFormat(t){const e=V[t];return!!(this.format&e)}insertRawText(t){const e=t.split(/(\r?\n|\t)/),n=[],r=e.length;for(let t=0;t<r;t++){const r=e[t];"\n"===r||"\r\n"===r?n.push(vn()):"\t"===r?n.push(Jn()):n.push(Bn(r))}this.insertNodes(n)}insertText(t){const n=this.anchor,r=this.focus,i=this.format,s=this.style;let o=n,l=r;!this.isCollapsed()&&r.isBefore(n)&&(o=r,l=n),"element"===o.type&&function(t,e,n,r){const i=t.getNode(),s=i.getChildAtIndex(t.offset),o=Bn(),l=ri(i)?fi().append(o):o;o.setFormat(n),o.setStyle(r),null===s?i.append(l):s.insertBefore(l),t.is(e)&&e.set(o.__key,0,"text"),t.set(o.__key,0,"text")}(o,l,i,s),"element"===l.type&&Oo(l,Ro(Lo(l,"next")));const c=o.offset;let a=l.offset;const u=this.getNodes(),f=u.length;let d=u[0];Wn(d)||e(26);const h=d.getTextContent().length,g=d.getParentOrThrow();let _=u[f-1];if(1===f&&"element"===l.type&&(a=h,l.set(o.key,a,"text")),this.isCollapsed()&&c===h&&(d.isSegmented()||d.isToken()||!d.canInsertTextAfter()||!g.canInsertTextAfter()&&null===d.getNextSibling())){let e=d.getNextSibling();if(Wn(e)&&e.canInsertTextBefore()&&!Pi(e)||(e=Bn(),e.setFormat(i),e.setStyle(s),g.canInsertTextAfter()?d.insertAfter(e):g.insertAfter(e)),e.select(0,0),d=e,""!==t)return void this.insertText(t)}else if(this.isCollapsed()&&0===c&&(d.isSegmented()||d.isToken()||!d.canInsertTextBefore()||!g.canInsertTextBefore()&&null===d.getPreviousSibling())){let e=d.getPreviousSibling();if(Wn(e)&&!Pi(e)||(e=Bn(),e.setFormat(i),g.canInsertTextBefore()?d.insertBefore(e):g.insertBefore(e)),e.select(),d=e,""!==t)return void this.insertText(t)}else if(d.isSegmented()&&c!==h){const t=Bn(d.getTextContent());t.setFormat(i),d.replace(t),d=t}else if(!this.isCollapsed()&&""!==t){const e=_.getParent();if(!g.canInsertTextBefore()||!g.canInsertTextAfter()||Yr(e)&&(!e.canInsertTextBefore()||!e.canInsertTextAfter()))return this.insertText(""),sr(this.anchor,this.focus,null),void this.insertText(t)}if(1===f){if(d.isToken()){const e=Bn(t);return e.select(),void d.replace(e)}const e=d.getFormat(),n=d.getStyle();if(c!==a||e===i&&n===s){if(jn(d)){const e=Bn(t);return e.setFormat(i),e.setStyle(s),e.select(),void d.replace(e)}}else{if(""!==d.getTextContent()){const e=Bn(t);if(e.setFormat(i),e.setStyle(s),e.select(),0===c)d.insertBefore(e,!1);else{const[t]=d.splitText(c);t.insertAfter(e,!1)}return void(e.isComposing()&&"text"===this.anchor.type&&(this.anchor.offset-=t.length))}d.setFormat(i),d.setStyle(s)}const r=a-c;d=d.spliceText(c,r,t,!0),""===d.getTextContent()?d.remove():"text"===this.anchor.type&&(d.isComposing()?this.anchor.offset-=t.length:(this.format=e,this.style=n))}else{const e=new Set([...d.getParentKeys(),..._.getParentKeys()]),n=Yr(d)?d:d.getParentOrThrow();let r=Yr(_)?_:_.getParentOrThrow(),i=_;if(!n.is(r)&&r.isInline())do{i=r,r=r.getParentOrThrow()}while(r.isInline());if("text"===l.type&&(0!==a||""===_.getTextContent())||"element"===l.type&&_.getIndexWithinParent()<a)if(Wn(_)&&!_.isToken()&&a!==_.getTextContentSize()){if(_.isSegmented()){const t=Bn(_.getTextContent());_.replace(t),_=t}ri(l.getNode())||"text"!==l.type||(_=_.spliceText(0,a,"")),e.add(_.__key)}else{const t=_.getParentOrThrow();t.canBeEmpty()||1!==t.getChildrenSize()?_.remove():t.remove()}else e.add(_.__key);const s=r.getChildren(),o=new Set(u),g=n.is(r),p=n.isInline()&&null===d.getNextSibling()?n:d;for(let t=s.length-1;t>=0;t--){const e=s[t];if(e.is(d)||Yr(e)&&e.isParentOf(d))break;e.isAttached()&&(!o.has(e)||e.is(i)?g||p.insertAfter(e,!1):e.remove())}if(!g){let t=r,n=null;for(;null!==t;){const r=t.getChildren(),i=r.length;(0===i||r[i-1].is(n))&&(e.delete(t.__key),n=t),t=t.getParent()}}if(d.isToken())if(c===h)d.select();else{const e=Bn(t);e.select(),d.replace(e)}else d=d.spliceText(c,h-c,t,!0),""===d.getTextContent()?d.remove():d.isComposing()&&"text"===this.anchor.type&&(this.anchor.offset-=t.length);for(let t=1;t<f;t++){const n=u[t],r=n.__key;e.has(r)||n.remove()}}}removeText(){const t=hr()===this;Mo(this,Wo(Io(this))),t&&hr()!==this&&qi(this)}formatText(t,e=null){if(this.isCollapsed())return this.toggleFormat(t),void Bi(null);const n=this.getNodes(),r=[];for(const t of n)Wn(t)&&r.push(t);const i=e=>{n.forEach((n=>{if(Yr(n)){const r=n.getF