c;)t==a&&(t=n[--r].from,a=r?n[r-1].to:e),oj[--t]=u;c=o}else a=o,c++}}}function nA(e,t,n,r,i,a,o){let s=r%2?2:1;if(r%2==i%2)for(let c=t,l=0;cc&&o.push(new aj(c,m.from,f)),rA(e,m.direction==tj==!(f%2)?r:r+1,i,m.inner,m.from,m.to,o),c=m.to),p=m.to}else if(p==n||(t?oj[p]!=s:oj[p]==s))break;else p++;d?nA(e,c,p,r+1,i,d,o):ct;){let n=!0,u=!1;if(!l||c>a[l-1].to){let e=oj[c-1];e!=s&&(n=!1,u=e==16)}let d=!n&&s==1?[]:null,f=n?r:r+1,p=c;run:for(;;)if(l&&p==a[l-1].to){if(u)break run;let m=a[--l];if(!n)for(let e=m.from,n=l;;){if(e==t)break run;if(n&&a[n-1].to==e)e=a[--n].from;else if(oj[e-1]==s)break run;else break}d?d.push(m):(m.tooj.length;)oj[oj.length]=256;let r=[],i=t==tj?0:1;return rA(e,i,i,n,0,e.length,r),r}function G0e(e){return[new aj(0,e,0)]}function K0e(e,t,n,r,i){let a=r.head-e.from,o=aj.find(t,a,r.bidiLevel??-1,r.assoc),s=t[o],c=s.side(i,n);if(a==c){let e=o+=i?1:-1;if(e<0||e>=t.length)return null;s=t[o=e],a=s.side(!i,n),c=s.side(i,n)}let l=yO(e.text,a,s.forward(i,n));(ls.to)&&(l=c),sj=e.text.slice(Math.min(a,l),Math.max(a,l));let u=o==(i?t.length-1:0)?null:t[o+(i?1:-1)];return u&&l==c&&u.level+ +!it instanceof Function?t(e):t),i=[];return Tk.spans(r,t.from,t.to,{point(){},span(e,n,r,a){let o=e-t.from,s=n-t.from,c=i;for(let e=r.length-1;e>=0;e--,a--){let n=r[e].spec.bidiIsolate,i;if(n??=q0e(t.text,o,s),a>0&&c.length&&(i=c[c.length-1]).to==o&&i.direction==n)i.to=s,c=i.inner;else{let e={from:o,to:s,direction:n,inner:[]};c.push(e),c=e.inner}}}}),i}function aA(e){let t=0,n=0,r=0,i=0;for(let a of e.state.facet(Mj)){let o=a(e);o&&(o.left!=null&&(t=Math.max(t,o.left)),o.right!=null&&(n=Math.max(n,o.right)),o.top!=null&&(r=Math.max(r,o.top)),o.bottom!=null&&(i=Math.max(i,o.bottom)))}return{left:t,right:n,top:r,bottom:i}}function Y0e(e){return e.node.nodeType==1&&e.node.firstChild&&(e.offset==0||e.node.childNodes[e.offset-1].contentEditable==`false`)&&(e.offset==e.node.childNodes.length||e.node.childNodes[e.offset].contentEditable==`false`)}function X0e(e,t){let n=e.observer.selectionRange;if(!n.focusNode)return null;let r=T0e(n.focusNode,n.focusOffset),i=E0e(n.focusNode,n.focusOffset),a=r||i;if(i&&r&&i.node!=r.node){let t=wA.get(i.node);if(!t||t instanceof RA&&t.text!=i.node.nodeValue)a=i;else if(e.docView.lastCompositionAfterCursor){let e=wA.get(r.node);!e||e instanceof RA&&e.text!=r.node.nodeValue||(a=i)}}if(e.docView.lastCompositionAfterCursor=a!=r,!a)return null;let o=t-a.offset;return{from:o,to:o+a.node.nodeValue.length,node:a.node}}function Z0e(e,t,n){let r=X0e(e,n);if(!r)return null;let{node:i,from:a,to:o}=r,s=i.nodeValue;if(/[\n\r]/.test(s)||e.state.doc.sliceString(r.from,r.to)!=s)return null;let c=t.invertedDesc,l=new Pj(c.mapPos(a),c.mapPos(o),a,o),u=[];for(let t=i.parentNode;;t=t.parentNode){let n=wA.get(t);if(n instanceof zA)u.push({node:t,deco:n.mark});else if(n instanceof YA||t.nodeName==`DIV`&&t.parentNode==e.contentDOM)return{range:l,text:i,marks:u,line:t};else if(t!=e.contentDOM)u.push({node:t,deco:new KA({inclusive:!0,attributes:F0e(t),tagName:t.tagName.toLowerCase()})});else return null}}function Q0e(e,t){return e.nodeType==1?(t&&e.childNodes[t-1].contentEditable==`false`?1:0)|(t{et.from&&(n=!0)}),n}function n2e(e,t,n=1){let r=e.charCategorizer(t),i=e.doc.lineAt(t),a=t-i.from;if(i.length==0)return QO.cursor(t);a==0?n=1:a==i.length&&(n=-1);let o=a,s=a;n<0?o=yO(i.text,a,!1):s=yO(i.text,a);let c=r(i.text.slice(o,s));for(;o>0;){let e=yO(i.text,o,!1);if(r(i.text.slice(e,o))!=c)break;o=e}for(;se?t.left-e:Math.max(0,e-t.right)}function i2e(e,t){return t.top>e?t.top-e:Math.max(0,e-t.bottom)}function oA(e,t){return e.topt.top+1}function a2e(e,t){return te.bottom?{top:e.top,left:e.left,right:e.right,bottom:t}:e}function sA(e,t,n){let r,i,a,o,s=!1,c,l,u,d;for(let f=e.firstChild;f;f=f.nextSibling){let e=Uk(f);for(let p=0;pg||o==g&&a>h){r=f,i=m,a=h,o=g;let c=g?n0?p0)}h==0?n>m.bottom&&(!u||u.bottomm.top)&&(l=f,d=m):u&&oA(u,m)?u=o2e(u,m.bottom):d&&oA(d,m)&&(d=a2e(d,m.top))}}if(u&&u.bottom>=n?(r=c,i=u):d&&d.top<=n&&(r=l,i=d),!r)return{node:e,offset:0};let f=Math.max(i.left,Math.min(i.right,t));return r.nodeType==3?s2e(r,f,n):s&&r.contentEditable!=`false`?sA(r,f,n):{node:e,offset:Array.prototype.indexOf.call(e.childNodes,r)+ +(t>=(i.left+i.right)/2)}}function s2e(e,t,n){let r=e.nodeValue.length,i=-1,a=1e9,o=0;for(let s=0;sn?l.top-n:n-l.bottom)-1;if(l.left-1<=t&&l.right+1>=t&&u=(l.left+l.right)/2,r=n;if((LA.chrome||LA.gecko)&&Yk(e,s).getBoundingClientRect().left==l.right&&(r=!n),u<=0)return{node:e,offset:s+ +!!r};i=s+ +!!r,a=u}}}return{node:e,offset:i>-1?i:o>0?e.nodeValue.length:0}}function c2e(e,t,n,r=-1){let i=e.contentDOM.getBoundingClientRect(),a=i.top+e.viewState.paddingTop,o,{docHeight:s}=e.viewState,{x:c,y:l}=t,u=l-a;if(u<0)return 0;if(u>s)return e.state.doc.length;for(let t=e.viewState.heightOracle.textHeight/2,i=!1;o=e.elementAtHeight(u),o.type!=WA.Text;)for(;u=r>0?o.bottom+t:o.top-t,!(u>=0&&u<=s);){if(i)return n?null:0;i=!0,r=-r}l=a+u;let d=o.from;if(de.viewport.to)return e.viewport.to==e.state.doc.length?e.state.doc.length:n?null:l2e(e,i,o,c,l);let f=e.dom.ownerDocument,p=e.root.elementFromPoint?e.root:f,m=p.elementFromPoint(c,l);m&&!e.contentDOM.contains(m)&&(m=null),m||(c=Math.max(i.left+1,Math.min(i.right-1,c)),m=p.elementFromPoint(c,l),m&&!e.contentDOM.contains(m)&&(m=null));let h,g=-1;if(m&&e.docView.nearest(m)?.isEditable!=0){if(f.caretPositionFromPoint){let e=f.caretPositionFromPoint(c,l);e&&({offsetNode:h,offset:g}=e)}else if(f.caretRangeFromPoint){let t=f.caretRangeFromPoint(c,l);t&&({startContainer:h,startOffset:g}=t,(!e.contentDOM.contains(h)||LA.safari&&u2e(h,g,c)||LA.chrome&&d2e(h,g,c))&&(h=void 0))}h&&(g=Math.min(qk(h),g))}if(!h||!e.docView.dom.contains(h)){let t=YA.find(e.docView,d);if(!t)return u>o.top+o.height/2?o.to:o.from;({node:h,offset:g}=sA(t.dom,c,l))}let _=e.docView.nearest(h);if(!_)return null;if(_.isWidget&&_.dom?.nodeType==1){let e=_.dom.getBoundingClientRect();return t.ye.defaultLineHeight*1.5){let t=e.viewState.heightOracle.textHeight,r=Math.floor((i-n.top-(e.defaultLineHeight-t)*.5)/t);a+=r*e.viewState.heightOracle.lineLength}let o=e.state.sliceDoc(n.from,n.to);return n.from+n0e(o,a,e.state.tabSize)}function u2e(e,t,n){let r;if(e.nodeType!=3||t!=(r=e.nodeValue.length))return!1;for(let t=e.nextSibling;t;t=t.nextSibling)if(t.nodeType!=1||t.nodeName!=`BR`)return!1;return Yk(e,r-1,r).getBoundingClientRect().left>n}function d2e(e,t,n){if(t!=0)return!1;for(let t=e;;){let e=t.parentNode;if(!e||e.nodeType!=1||e.firstChild!=t)return!1;if(e.classList.contains(`cm-line`))break;t=e}return n-(e.nodeType==1?e.getBoundingClientRect():Yk(e,0,Math.max(e.nodeValue.length,1)).getBoundingClientRect()).left>5}function f2e(e,t){let n=e.lineBlockAt(t);if(Array.isArray(n.type)){for(let e of n.type)if(e.to>t||e.to==t&&(e.to==n.to||e.type==WA.Text))return e}return n}function p2e(e,t,n,r){let i=f2e(e,t.head),a=!r||i.type!=WA.Text||!(e.lineWrapping||i.widgetLineBreaks)?null:e.coordsAtPos(t.assoc<0&&t.head>i.from?t.head-1:t.head);if(a){let t=e.dom.getBoundingClientRect(),r=e.textDirectionAt(i.from),o=e.posAtCoords({x:n==(r==ej.LTR)?t.right-1:t.left+1,y:(a.top+a.bottom)/2});if(o!=null)return QO.cursor(o,n?-1:1)}return QO.cursor(n?i.to:i.from,n?-1:1)}function m2e(e,t,n,r){let i=e.state.doc.lineAt(t.head),a=e.bidiSpans(i),o=e.textDirectionAt(i.from);for(let s=t,c=null;;){let t=K0e(i,a,o,s,n),l=sj;if(!t){if(i.number==(n?e.state.doc.lines:1))return s;l=`
+`,i=e.state.doc.line(i.number+(n?1:-1)),a=e.bidiSpans(i),t=e.visualLineSide(i,!n)}if(!c){if(!r)return t;c=r(l)}else if(!c(l))return s;s=t}}function h2e(e,t,n){let r=e.state.charCategorizer(t),i=r(n);return e=>{let t=r(e);return i==bk.Space&&(i=t),i==t}}function g2e(e,t,n,r){let i=t.head,a=n?1:-1;if(i==(n?e.state.doc.length:0))return QO.cursor(i,t.assoc);let o=t.goalColumn,s,c=e.contentDOM.getBoundingClientRect(),l=e.coordsAtPos(i,t.assoc||-1),u=e.documentTop;if(l)o??=l.left-c.left,s=a<0?l.top:l.bottom;else{let t=e.viewState.lineBlockAt(i);o??=Math.min(c.right-c.left,e.defaultCharacterWidth*(i-t.from)),s=(a<0?t.top:t.bottom)+u}let d=c.left+o,f=r??e.viewState.heightOracle.textHeight>>1;for(let t=0;;t+=10){let n=s+(f+t)*a,r=c2e(e,{x:d,y:n},!1,a);if(nc.bottom||(a<0?ri)){let t=e.docView.coordsForChar(r),i=!t||n{if(t>e&&tt(e)),n.from,t.head>n.from?-1:1);return r==n.from?n:QO.cursor(r,rDate.now()-100?e.inputState.lastKeyCode:-1;if(t.bounds){let{from:r,to:o}=t.bounds,s=i.from,c=null;(a===8||LA.android&&t.text.length=i.from&&n.to<=i.to&&(n.from!=i.from||n.to!=i.to)&&i.to-i.from-(n.to-n.from)<=4?n={from:i.from,to:i.to,insert:e.state.doc.slice(i.from,n.from).append(n.insert).append(e.state.doc.slice(n.to,i.to))}:(LA.mac||LA.android)&&n&&n.from==n.to&&n.from==i.head-1&&/^\. ?$/.test(n.insert.toString())&&e.contentDOM.getAttribute(`autocorrect`)==`off`?(r&&n.insert.length==2&&(r=QO.single(r.main.anchor-1,r.main.head-1)),n={from:i.from,to:i.to,insert:BO.of([` `])}):LA.chrome&&n&&n.from==n.to&&n.from==i.head&&n.insert.toString()==`
+ `&&e.lineWrapping&&(r&&=QO.single(r.main.anchor-1,r.main.head-1),n={from:i.from,to:i.to,insert:BO.of([` `])}),n)return uA(e,n,r,a);if(r&&!r.main.eq(i)){let t=!1,n=`select`;return e.inputState.lastSelectionTime>Date.now()-50&&(e.inputState.lastSelectionOrigin==`select`&&(t=!0),n=e.inputState.lastSelectionOrigin),e.dispatch({selection:r,scrollIntoView:t,userEvent:n}),!0}else return!1}function uA(e,t,n,r=-1){if(LA.ios&&e.inputState.flushIOSKey(t))return!0;let i=e.state.selection.main;if(LA.android&&(t.to==i.to&&(t.from==i.from||t.from==i.from-1&&e.state.sliceDoc(t.from,i.from)==` `)&&t.insert.length==1&&t.insert.lines==2&&Xk(e.contentDOM,`Enter`,13)||(t.from==i.from-1&&t.to==i.to&&t.insert.length==0||r==8&&t.insert.lengthi.head)&&Xk(e.contentDOM,`Backspace`,8)||t.from==i.from&&t.to==i.to+1&&t.insert.length==0&&Xk(e.contentDOM,`Delete`,46)))return!0;let a=t.insert.toString();e.inputState.composing>=0&&e.inputState.composing++;let o,s=()=>o||=y2e(e,t,n);return e.state.facet(pj).some(n=>n(e,t.from,t.to,a,s))||e.dispatch(s()),!0}function y2e(e,t,n){let r,i=e.state,a=i.selection.main;if(t.from>=a.from&&t.to<=a.to&&t.to-t.from>=(a.to-a.from)/3&&(!n||n.main.empty&&n.main.from==t.from+t.insert.length)&&e.inputState.composing<0){let n=a.fromt.to?i.sliceDoc(t.to,a.to):``;r=i.replaceSelection(e.state.toText(n+t.insert.sliceString(0,void 0,e.state.lineBreak)+o))}else{let o=i.changes(t),s=n&&n.main.to<=o.newLength?n.main:void 0;if(i.selection.ranges.length>1&&e.inputState.composing>=0&&t.to<=a.to&&t.to>=a.to-10){let c=e.state.sliceDoc(t.from,t.to),l,u=n&&X0e(e,n.main.head);if(u){let e=t.insert.length-(t.to-t.from);l={from:u.from,to:u.to-e}}else l=e.state.doc.lineAt(a.head);let d=a.to-t.to,f=a.to-a.from;r=i.changeByRange(n=>{if(n.from==a.from&&n.to==a.to)return{changes:o,range:s||n.map(o)};let r=n.to-d,u=r-c.length;if(n.to-n.from!=f||e.state.sliceDoc(u,r)!=c||n.to>=l.from&&n.from<=l.to)return{range:n};let p=i.changes({from:u,to:r,insert:t.insert}),m=n.to-a.to;return{changes:p,range:s?QO.range(Math.max(0,s.anchor+m),Math.max(0,s.head+m)):n.map(p)}})}else r={changes:o,selection:s&&i.selection.replaceRange(s)}}let o=`input.type`;return(e.composing||e.inputState.compositionPendingChange&&e.inputState.compositionEndedAt>Date.now()-50)&&(e.inputState.compositionPendingChange=!1,o+=`.compose`,e.inputState.compositionFirstChange&&(o+=`.start`,e.inputState.compositionFirstChange=!1)),i.update(r,{userEvent:o,scrollIntoView:!0})}function b2e(e,t,n,r){let i=Math.min(e.length,t.length),a=0;for(;a0&&s>0&&e.charCodeAt(o-1)==t.charCodeAt(s-1);)o--,s--;if(r==`end`){let e=Math.max(0,a-Math.min(o,s));n-=o+e-a}if(o=o?a-n:0;a-=e,s=a+(s-o),o=a}else if(s=s?a-n:0;a-=e,o=a+(o-s),s=a}return{from:a,toA:o,toB:s}}function x2e(e){let t=[];if(e.root.activeElement!=e.contentDOM)return t;let{anchorNode:n,anchorOffset:r,focusNode:i,focusOffset:a}=e.observer.selectionRange;return n&&(t.push(new Rj(n,r)),(i!=n||a!=r)&&t.push(new Rj(i,a))),t}function S2e(e,t){if(e.length==0)return null;let n=e[0].pos,r=e.length==2?e[1].pos:n;return n>-1&&r>-1?QO.single(n+t,r+t):null}function C2e(e,t){return(n,r)=>{try{return t.call(e,r,n)}catch(e){iA(n.state,e)}}}function w2e(e){let t=Object.create(null);function n(e){return t[e]||(t[e]={observers:[],handlers:[]})}for(let t of e){let e=t.spec;if(e&&e.domEventHandlers)for(let r in e.domEventHandlers){let i=e.domEventHandlers[r];i&&n(r).handlers.push(C2e(t.value,i))}if(e&&e.domEventObservers)for(let r in e.domEventObservers){let i=e.domEventObservers[r];i&&n(r).observers.push(C2e(t.value,i))}}for(let e in Hj)n(e).handlers.push(Hj[e]);for(let e in Uj)n(e).observers.push(Uj[e]);return t}function dA(e){return Math.max(0,e)*.7+8}function T2e(e,t){return Math.max(Math.abs(e.clientX-t.clientX),Math.abs(e.clientY-t.clientY))}function E2e(e,t){let n=e.state.facet(cj);return n.length?n[0](t):LA.mac?t.metaKey:t.ctrlKey}function D2e(e,t){let n=e.state.facet(lj);return n.length?n[0](t):LA.mac?!t.altKey:!t.ctrlKey}function O2e(e,t){let{main:n}=e.state.selection;if(n.empty)return!1;let r=Bk(e.root);if(!r||r.rangeCount==0)return!0;let i=r.getRangeAt(0).getClientRects();for(let e=0;e=t.clientX&&n.top<=t.clientY&&n.bottom>=t.clientY)return!0}return!1}function k2e(e,t){if(!t.bubbles)return!0;if(t.defaultPrevented)return!1;for(let n=t.target,r;n!=e.contentDOM;n=n.parentNode)if(!n||n.nodeType==11||(r=wA.get(n))&&r.ignoreEvent(t))return!1;return!0}function A2e(e){let t=e.dom.parentNode;if(!t)return;let n=t.appendChild(document.createElement(`textarea`));n.style.cssText=`position: fixed; left: -10000px; top: 10px`,n.focus(),setTimeout(()=>{e.focus(),n.remove(),j2e(e,n.value)},50)}function fA(e,t,n){for(let r of e.facet(t))n=r(n,e);return n}function j2e(e,t){t=fA(e.state,hj,t);let{state:n}=e,r,i=1,a=n.toText(t),o=a.lines==n.selection.ranges.length;if(Yj!=null&&n.selection.ranges.every(e=>e.empty)&&Yj==a.toString()){let e=-1;r=n.changeByRange(r=>{let s=n.doc.lineAt(r.from);if(s.from==e)return{range:r};e=s.from;let c=n.toText((o?a.line(i++).text:t)+n.lineBreak);return{changes:{from:s.from,insert:c},range:QO.cursor(r.from+c.length)}})}else r=o?n.changeByRange(e=>{let t=a.line(i++);return{changes:{from:e.from,to:e.to,insert:t.text},range:QO.cursor(e.from+t.length)}}):n.replaceSelection(a);e.dispatch(r,{userEvent:`input.paste`,scrollIntoView:!0})}function M2e(e,t,n,r){if(r==1)return QO.cursor(t,n);if(r==2)return n2e(e.state,t,n);{let n=YA.find(e.docView,t),r=e.state.doc.lineAt(n?n.posAtEnd:t),i=n?n.posAtStart:r.from,a=n?n.posAtEnd:r.to;return a=r?-1:1}function P2e(e,t){let n=e.posAtCoords({x:t.clientX,y:t.clientY},!1);return{pos:n,bias:N2e(e,n,t.clientX,t.clientY)}}function F2e(e){if(!z4e)return e.detail;let t=Kj,n=Jj;return Kj=e,Jj=Date.now(),qj=!t||n>Date.now()-400&&Math.abs(t.clientX-e.clientX)<2&&Math.abs(t.clientY-e.clientY)<2?(qj+1)%3:1}function I2e(e,t){let n=P2e(e,t),r=F2e(t),i=e.state.selection;return{update(e){e.docChanged&&(n.pos=e.changes.mapPos(n.pos),i=i.map(e.changes))},get(t,a,o){let s=P2e(e,t),c,l=M2e(e,s.pos,s.bias,r);if(n.pos!=s.pos&&!a){let t=M2e(e,n.pos,n.bias,r),i=Math.min(t.from,l.from),a=Math.max(t.to,l.to);l=i1&&(c=L2e(i,s.pos))?c:o?i.addRange(l):QO.create([l])}}}function L2e(e,t){for(let n=0;n=t)return QO.create(e.ranges.slice(0,n).concat(e.ranges.slice(n+1)),e.mainIndex==n?0:e.mainIndex-+(e.mainIndex>n))}return null}function R2e(e,t,n,r){if(n=fA(e.state,hj,n),!n)return;let i=e.posAtCoords({x:t.clientX,y:t.clientY},!1),{draggedContent:a}=e.inputState,o=r&&a&&D2e(e,t)?{from:a.from,to:a.to}:null,s={from:i,insert:n},c=e.state.changes(o?[o,s]:s);e.focus(),e.dispatch({changes:c,selection:{anchor:c.mapPos(i,-1),head:c.mapPos(i,1)},userEvent:o?`move.drop`:`input.drop`}),e.inputState.draggedContent=null}function z2e(e,t){let n=e.dom.parentNode;if(!n)return;let r=n.appendChild(document.createElement(`textarea`));r.style.cssText=`position: fixed; left: -10000px; top: 10px`,r.value=t,r.focus(),r.selectionEnd=t.length,r.selectionStart=0,setTimeout(()=>{r.remove(),e.focus()},50)}function B2e(e){let t=[],n=[],r=!1;for(let r of e.selection.ranges)r.empty||(t.push(e.sliceDoc(r.from,r.to)),n.push(r));if(!t.length){let i=-1;for(let{from:r}of e.selection.ranges){let a=e.doc.lineAt(r);a.number>i&&(t.push(a.text),n.push({from:a.from,to:Math.min(e.doc.length,a.to+1)})),i=a.number}r=!0}return{text:fA(e,gj,t.join(e.lineBreak)),ranges:n,linewise:r}}function V2e(e,t){let n=[];for(let r of e.facet(mj)){let i=r(e,t);i&&n.push(i)}return n?e.update({effects:n,annotations:Xj.of(!0)}):null}function H2e(e){setTimeout(()=>{let t=e.hasFocus;if(t!=e.inputState.notifiedFocused){let n=V2e(e.state,t);n?e.dispatch(n):e.update([])}},10)}function U2e(e){Zj.has(e)||(Zj.add(e),e.addEventListener(`copy`,()=>{}),e.addEventListener(`cut`,()=>{}))}function W2e(){$j=!1}function pA(e,t){return e==t?e:(e.constructor!=t.constructor&&($j=!0),t)}function G2e(e,t){let n,r;e[t]==null&&(n=e[t-1])instanceof oM&&(r=e[t+1])instanceof oM&&e.splice(t-1,3,new oM(n.length+1+r.length))}function K2e(e,t,n){let r=new G4e;return Tk.compare(e,t,n,r,0),r.changes}function q2e(e,t){let n=e.getBoundingClientRect(),r=e.ownerDocument,i=r.defaultView||window,a=Math.max(0,n.left),o=Math.min(i.innerWidth,n.right),s=Math.max(0,n.top),c=Math.min(i.innerHeight,n.bottom);for(let t=e.parentNode;t&&t!=r.body;)if(t.nodeType==1){let n=t,r=window.getComputedStyle(n);if((n.scrollHeight>n.clientHeight||n.scrollWidth>n.clientWidth)&&r.overflow!=`visible`){let r=n.getBoundingClientRect();a=Math.max(a,r.left),o=Math.min(o,r.right),s=Math.max(s,r.top),c=Math.min(t==e.parentNode?i.innerHeight:c,r.bottom)}t=r.position==`absolute`||r.position==`fixed`?n.offsetParent:n.parentNode}else if(t.nodeType==11)t=t.host;else break;return{left:a-n.left,right:Math.max(a,o)-n.left,top:s-(n.top+t),bottom:Math.max(s,c)-(n.top+t)}}function J2e(e,t){let n=e.getBoundingClientRect();return{left:0,right:n.right-n.left,top:t,bottom:n.bottom-(n.top+t)}}function Y2e(e,t,n){let r=[],i=e,a=0;return Tk.spans(n,e,t,{span(){},point(e,t){e>i&&(r.push({from:i,to:e}),a+=e-i),i=t}},20),i=1)return t[t.length-1].to;let r=Math.floor(e*n);for(let e=0;;e++){let{from:n,to:i}=t[e],a=i-n;if(r<=a)return n+r;r-=a}}function hA(e,t){let n=0;for(let{from:r,to:i}of e.ranges){if(t<=i){n+=t-r;break}n+=i-r}return n/e.total}function X2e(e,t){for(let n of e)if(t(n))return n}function gA(e,t){if(t.scale==1)return e;let n=t.toDOM(e.top),r=t.toDOM(e.bottom);return new eM(e.from,e.length,n,r-n,Array.isArray(e._content)?e._content.map(e=>gA(e,t)):e._content)}function _A(e,t,n){return new Fk(t,{finish(t){return/&/.test(t)?t.replace(/&\w*/,t=>{if(t==`&`)return e;if(!n||!n[t])throw RangeError(`Unsupported selector: ${t}`);return n[t]}):e+` `+t}})}function Z2e(e,t,n){for(;t;){let r=wA.get(t);if(r&&r.parent==e)return r;let i=t.parentNode;t=i==e.dom?n>0?t.nextSibling:t.previousSibling:i}return null}function Q2e(e,t){let n=t.startContainer,r=t.startOffset,i=t.endContainer,a=t.endOffset,o=e.docView.domAtPos(e.state.selection.main.anchor);return Wk(o.node,o.offset,i,a)&&([n,r,i,a]=[i,a,n,r]),{anchorNode:n,anchorOffset:r,focusNode:i,focusOffset:a}}function $2e(e,t){if(t.getComposedRanges){let n=t.getComposedRanges(e.root)[0];if(n)return Q2e(e,n)}let n=null;function r(e){e.preventDefault(),e.stopImmediatePropagation(),n=e.getTargetRanges()[0]}return e.contentDOM.addEventListener(`beforeinput`,r,!0),e.dom.ownerDocument.execCommand(`indent`),e.contentDOM.removeEventListener(`beforeinput`,r,!0),n?Q2e(e,n):null}function e4e(e,t,n){for(let r=e.state.facet(t),i=r.length-1;i>=0;i--){let t=r[i],a=typeof t==`function`?t(e):t;a&&Zk(a,n)}return n}function t4e(e,t){let n=e.split(/-(?!$)/),r=n[n.length-1];r==`Space`&&(r=` `);let i,a,o,s;for(let e=0;ee.concat(t),[]))),n}function r4e(e,t=$4e){let n=Object.create(null),r=Object.create(null),i=(e,t)=>{let n=r[e];if(n==null)r[e]=t;else if(n!=t)throw Error(`Key binding `+e+` is used both as a regular binding and as a multi-stroke prefix`)},a=(e,r,a,o,s)=>{let c=n[e]||(n[e]=Object.create(null)),l=r.split(/ (?!$)/).map(e=>t4e(e,t));for(let t=1;t{let r=CM={view:t,prefix:n,scope:e};return setTimeout(()=>{CM==r&&(CM=null)},t3e),!0}]})}let u=l.join(` `);i(u,!1);let d=c[u]||(c[u]={preventDefault:!1,stopPropagation:!1,run:(c._any?.run)?.slice()||[]});a&&d.run.push(a),o&&(d.preventDefault=!0),s&&(d.stopPropagation=!0)};for(let r of e){let e=r.scope?r.scope.split(` `):[`editor`];if(r.any)for(let t of e){let e=n[t]||(n[t]=Object.create(null));e._any||={preventDefault:!1,stopPropagation:!1,run:[]};let{any:i}=r;for(let t in e)e[t].run.push(e=>i(e,wM))}let i=r[t]||r.key;if(i)for(let t of e)a(t,i,r.run,r.preventDefault,r.stopPropagation),r.shift&&a(t,`Shift-`+i,r.shift,r.preventDefault,r.stopPropagation)}return n}function i4e(e,t,n,r){wM=t;let i=d0e(t),a=xO(bO(i,0))==i.length&&i!=` `,o=``,s=!1,c=!1,l=!1;CM&&CM.view==n&&CM.scope==r&&(o=CM.prefix+` `,Bj.indexOf(t.keyCode)<0&&(c=!0,CM=null));let u=new Set,d=e=>{if(e){for(let t of e.run)if(!u.has(t)&&(u.add(t),t(n)))return e.stopPropagation&&(l=!0),!0;e.preventDefault&&(e.stopPropagation&&(l=!0),c=!0)}return!1},f=e[r],p,m;return f&&(d(f[o+vA(i,t,!a)])?s=!0:a&&(t.altKey||t.metaKey||t.ctrlKey)&&!(LA.windows&&t.ctrlKey&&t.altKey)&&(p=Lk[t.keyCode])&&p!=i?(d(f[o+vA(p,t,!0)])||t.shiftKey&&(m=Rk[t.keyCode])!=i&&m!=p&&d(f[o+vA(m,t,!1)]))&&(s=!0):a&&t.shiftKey&&d(f[o+vA(i,t,!0)])&&(s=!0),!s&&d(f._any)&&(s=!0)),c&&(s=!0),s&&l&&t.stopPropagation(),wM=null,s}function a4e(e,t,n,r,i){t.lastIndex=0;for(let a=e.iterRange(n,r),o=n,s;!a.next().done;o+=a.value.length)if(!a.lineBreak)for(;s=t.exec(a.value);)i(o+s.index,s)}function o4e(e,t){let n=e.visibleRanges;if(n.length==1&&n[0].from==e.viewport.from&&n[0].to==e.viewport.to)return n;let r=[];for(let{from:i,to:a}of n)i=Math.max(e.state.doc.lineAt(i).from,i-t),a=Math.min(e.state.doc.lineAt(a).to,a+t),r.length&&r[r.length-1].to>=i?r[r.length-1].to=a:r.push({from:i,to:a});return r}function s4e(){if(OM==null&&typeof document<`u`&&document.body){let e=document.body.style;OM=(e.tabSize??e.MozTabSize)!=null}return OM||!1}function c4e(e={}){return[kM.of(e),l4e()]}function l4e(){return a3e||=wj.fromClass(class{constructor(e){this.view=e,this.decorations=GA.none,this.decorationCache=Object.create(null),this.decorator=this.makeDecorator(e.state.facet(kM)),this.decorations=this.decorator.createDeco(e)}makeDecorator(e){return new EM({regexp:e.specialChars,decoration:(t,n,r)=>{let{doc:i}=n.state,a=bO(t[0],0);if(a==9){let e=i.lineAt(r),t=n.state.tabSize,a=zO(e.text,t,r-e.from);return GA.replace({widget:new c3e((t-a%t)*this.view.defaultCharacterWidth/this.view.scaleX)})}return this.decorationCache[a]||(this.decorationCache[a]=GA.replace({widget:new s3e(e,a)}))},boundary:e.replaceTabs?void 0:/[^]/})}update(e){let t=e.state.facet(kM);e.startState.facet(kM)==t?this.decorations=this.decorator.updateDeco(e,this.decorations):(this.decorator=this.makeDecorator(t),this.decorations=this.decorator.createDeco(e.view))}},{decorations:e=>e.decorations})}function u4e(e){return e>=32?o3e:e==10?``:String.fromCharCode(9216+e)}function d4e(e){return wj.fromClass(class{constructor(t){this.view=t,this.placeholder=e?GA.set([GA.widget({widget:new l3e(e),side:1}).range(0)]):GA.none}get decorations(){return this.view.state.doc.length?GA.none:this.placeholder}},{decorations:e=>e.decorations})}function f4e(e){let{win:t}=e;return{top:0,left:0,bottom:t.innerHeight,right:t.innerWidth}}function p4e(e,t){let n=parseInt(e.style.left,10);(isNaN(n)||Math.abs(t-n)>1)&&(e.style.left=t+`px`)}function m4e(e,t){let{left:n,right:r,top:i,bottom:a}=e.getBoundingClientRect(),o;if(o=e.querySelector(`.cm-tooltip-arrow`)){let e=o.getBoundingClientRect();i=Math.min(e.top,i),a=Math.max(e.bottom,a)}return t.clientX>=n-RM&&t.clientX<=r+RM&&t.clientY>=i-RM&&t.clientY<=a+RM}function h4e(e,t,n,r,i,a){let o=e.scrollDOM.getBoundingClientRect(),s=e.documentTop+e.documentPadding.top+e.contentHeight;if(o.left>r||o.righti||Math.min(o.bottom,s)=t&&c<=n}function g4e(e,t={}){let n=vk.define(),r=rk.define({create(){return[]},update(e,r){if(e.length&&(t.hideOnChange&&(r.docChanged||r.selection)?e=[]:t.hideOn&&(e=e.filter(e=>!t.hideOn(r,e))),r.docChanged)){let t=[];for(let n of e){let e=r.changes.mapPos(n.pos,-1,qO.TrackDel);if(e!=null){let i=Object.assign(Object.create(null),n);i.pos=e,i.end!=null&&(i.end=r.changes.mapPos(i.end)),t.push(i)}}e=t}for(let t of r.effects)t.is(n)&&(e=t.value),t.is(m3e)&&(e=[]);return e},provide:e=>IM.from(e)});return{active:r,extension:[r,wj.define(i=>new p3e(i,e,r,n,t.hoverTime||300)),f3e]}}function _4e(e,t){let n=e.plugin(PM);if(!n)return null;let r=n.manager.tooltips.indexOf(t);return r<0?null:n.manager.tooltipViews[r]}function v4e(e){let t=e.nextSibling;return e.remove(),t}function y4e(e){return[b4e(),WM.of(Object.assign(Object.assign({},_3e),e))]}function b4e(e){let t=[v3e];return e&&e.fixed===!1&&t.push(GM.of(!0)),t}function x4e(e){return Array.isArray(e)?e:[e]}function yA(e,t,n){for(;e.value&&e.from<=n;)e.from==n&&t.push(e.value),e.next()}function S4e(e,t){if(e.length!=t.length)return!1;for(let n=0;n{Ak(),u0e(),m0e(),T4e=class{constructor(){this.anchorNode=null,this.anchorOffset=0,this.focusNode=null,this.focusOffset=0}eq(e){return this.anchorNode==e.anchorNode&&this.anchorOffset==e.anchorOffset&&this.focusNode==e.focusNode&&this.focusOffset==e.focusOffset}setRange(e){let{anchorNode:t,focusNode:n}=e;this.set(t,Math.min(e.anchorOffset,t?qk(t):0),n,Math.min(e.focusOffset,n?qk(n):0))}set(e,t,n,r){this.anchorNode=e,this.anchorOffset=t,this.focusNode=n,this.focusOffset=r}},xA=null,SA=class e{constructor(e,t,n=!0){this.node=e,this.offset=t,this.precise=n}static before(t,n){return new e(t.parentNode,Gk(t),n)}static after(t,n){return new e(t.parentNode,Gk(t)+1,n)}},CA=[],wA=class e{constructor(){this.parent=null,this.dom=null,this.flags=2}get overrideDOMText(){return null}get posAtStart(){return this.parent?this.parent.posBefore(this):0}get posAtEnd(){return this.posAtStart+this.length}posBefore(e){let t=this.posAtStart;for(let n of this.children){if(n==e)return t;t+=n.length+n.breakAfter}throw RangeError(`Invalid child in posBefore`)}posAfter(e){return this.posBefore(e)+e.length}sync(t,n){if(this.flags&2){let r=this.dom,i=null,a;for(let o of this.children){if(o.flags&7){if(!o.dom&&(a=i?i.nextSibling:r.firstChild)){let t=e.get(a);(!t||!t.parent&&t.canReuseDOM(o))&&o.reuseDOM(a)}o.sync(t,n),o.flags&=-8}if(a=i?i.nextSibling:r.firstChild,n&&!n.written&&n.node==r&&a!=o.dom&&(n.written=!0),o.dom.parentNode==r)for(;a&&a!=o.dom;)a=D0e(a);else r.insertBefore(o.dom,a);i=o.dom}for(a=i?i.nextSibling:r.firstChild,a&&n&&n.node==r&&(n.written=!0);a;)a=D0e(a)}else if(this.flags&1)for(let e of this.children)e.flags&7&&(e.sync(t,n),e.flags&=-8)}reuseDOM(e){}localPosFromDOM(t,n){let r;if(t==this.dom)r=this.dom.childNodes[n];else{let e=qk(t)==0?0:n==0?-1:1;for(;;){let n=t.parentNode;if(n==this.dom)break;e==0&&n.firstChild!=n.lastChild&&(e=t==n.firstChild?-1:1),t=n}r=e<0?t:t.nextSibling}if(r==this.dom.firstChild)return 0;for(;r&&!e.get(r);)r=r.nextSibling;if(!r)return this.length;for(let e=0,t=0;;e++){let n=this.children[e];if(n.dom==r)return t;t+=n.length+n.breakAfter}}domBoundsAround(e,t,n=0){let r=-1,i=-1,a=-1,o=-1;for(let s=0,c=n,l=n;st)return n.domBoundsAround(e,t,c);if(u>=e&&r==-1&&(r=s,i=c),c>t&&n.dom.parentNode==this.dom){a=s,o=l;break}l=u,c=u+n.breakAfter}return{from:i,to:o<0?n+this.length:o,startDOM:(r?this.children[r-1].dom.nextSibling:null)||this.dom.firstChild,endDOM:a=0?this.children[a].dom:null}}markDirty(e=!1){this.flags|=2,this.markParentsDirty(e)}markParentsDirty(e){for(let t=this.parent;t;t=t.parent){if(e&&(t.flags|=2),t.flags&1)return;t.flags|=1,e=!1}}setParent(e){this.parent!=e&&(this.parent=e,this.flags&7&&this.markParentsDirty(!0))}setDOM(e){this.dom!=e&&(this.dom&&(this.dom.cmView=null),this.dom=e,e.cmView=this)}get rootView(){for(let e=this;;){let t=e.parent;if(!t)return e;e=t}}replaceChildren(e,t,n=CA){this.markDirty();for(let r=e;rthis.pos||e==this.pos&&(t>0||this.i==0||this.children[this.i-1].breakAfter))return this.off=e-this.pos,this;let n=this.children[--this.i];this.pos-=n.length+n.breakAfter}}},EA=typeof navigator<`u`?navigator:{userAgent:``,vendor:``,platform:``},DA=typeof document<`u`?document:{documentElement:{style:{}}},OA=/Edge\/(\d+)/.exec(EA.userAgent),kA=/MSIE \d/.test(EA.userAgent),AA=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(EA.userAgent),jA=!!(kA||AA||OA),MA=!jA&&/gecko\/(\d+)/i.test(EA.userAgent),NA=!jA&&/Chrome\/(\d+)/.exec(EA.userAgent),PA=`webkitFontSmoothing`in DA.documentElement.style,FA=!jA&&/Apple Computer/.test(EA.vendor),IA=FA&&(/Mobile\/\w+/.test(EA.userAgent)||EA.maxTouchPoints>2),LA={mac:IA||/Mac/.test(EA.platform),windows:/Win/.test(EA.platform),linux:/Linux|X11/.test(EA.platform),ie:jA,ie_version:kA?DA.documentMode||6:AA?+AA[1]:OA?+OA[1]:0,gecko:MA,gecko_version:MA?+(/Firefox\/(\d+)/.exec(EA.userAgent)||[0,0])[1]:0,chrome:!!NA,chrome_version:NA?+NA[1]:0,ios:IA,android:/Android\b/.test(EA.userAgent),webkit:PA,safari:FA,webkit_version:PA?+(/\bAppleWebKit\/(\d+)/.exec(EA.userAgent)||[0,0])[1]:0,tabSize:DA.documentElement.style.tabSize==null?`-moz-tab-size`:`tab-size`},D4e=256,RA=class e extends wA{constructor(e){super(),this.text=e}get length(){return this.text.length}createDOM(e){this.setDOM(e||document.createTextNode(this.text))}sync(e,t){this.dom||this.createDOM(),this.dom.nodeValue!=this.text&&(t&&t.node==this.dom&&(t.written=!0),this.dom.nodeValue=this.text)}reuseDOM(e){e.nodeType==3&&this.createDOM(e)}merge(t,n,r){return this.flags&8||r&&(!(r instanceof e)||this.length-(n-t)+r.length>D4e||r.flags&8)?!1:(this.text=this.text.slice(0,t)+(r?r.text:``)+this.text.slice(n),this.markDirty(),!0)}split(t){let n=new e(this.text.slice(t));return this.text=this.text.slice(0,t),this.markDirty(),n.flags|=this.flags&8,n}localPosFromDOM(e,t){return e==this.dom?t:t?this.text.length:0}domAtPos(e){return new SA(this.dom,e)}domBoundsAround(e,t,n){return{from:n,to:n+this.length,startDOM:this.dom,endDOM:this.dom.nextSibling}}coordsAt(e,t){return A0e(this.dom,e,t)}},zA=class e extends wA{constructor(e,t=[],n=0){super(),this.mark=e,this.children=t,this.length=n;for(let e of t)e.setParent(this)}setAttrs(e){if(S0e(e),this.mark.class&&(e.className=this.mark.class),this.mark.attrs)for(let t in this.mark.attrs)e.setAttribute(t,this.mark.attrs[t]);return e}canReuseDOM(e){return super.canReuseDOM(e)&&!((this.flags|e.flags)&8)}reuseDOM(e){e.nodeName==this.mark.tagName.toUpperCase()&&(this.setDOM(e),this.flags|=6)}sync(e,t){this.dom?this.flags&4&&this.setAttrs(this.dom):this.setDOM(this.setAttrs(document.createElement(this.mark.tagName))),super.sync(e,t)}merge(t,n,r,i,a,o){return r&&(!(r instanceof e&&r.mark.eq(this.mark))||t&&a<=0||nt&&n.push(r=t&&(i=a),r=o,a++}let o=this.length-t;return this.length=t,i>-1&&(this.children.length=i,this.markDirty()),new e(this.mark,n,o)}domAtPos(e){return j0e(this,e)}coordsAt(e,t){return N0e(this,e,t)}},BA=class e extends wA{static create(t,n,r){return new e(t,n,r)}constructor(e,t,n){super(),this.widget=e,this.length=t,this.side=n,this.prevWidget=null}split(t){let n=e.create(this.widget,this.length-t,this.side);return this.length-=t,n}sync(e){(!this.dom||!this.widget.updateDOM(this.dom,e))&&(this.dom&&this.prevWidget&&this.prevWidget.destroy(this.dom),this.prevWidget=null,this.setDOM(this.widget.toDOM(e)),this.widget.editable||(this.dom.contentEditable=`false`))}getSide(){return this.side}merge(t,n,r,i,a,o){return r&&(!(r instanceof e)||!this.widget.compare(r.widget)||t>0&&a<=0||n0)?SA.before(this.dom):SA.after(this.dom,e==this.length)}domBoundsAround(){return null}coordsAt(e,t){let n=this.widget.coordsAt(this.dom,e,t);if(n)return n;let r=this.dom.getClientRects(),i=null;if(!r.length)return null;let a=this.side?this.side<0:e>0;for(let t=a?r.length-1:0;i=r[t],!(e>0?t==0:t==r.length-1||i.top0?SA.before(this.dom):SA.after(this.dom)}localPosFromDOM(){return 0}domBoundsAround(){return null}coordsAt(e){return this.dom.getBoundingClientRect()}get overrideDOMText(){return BO.empty}get isHidden(){return!0}},RA.prototype.children=BA.prototype.children=VA.prototype.children=CA,HA=Object.create(null),UA=class{eq(e){return!1}updateDOM(e,t){return!1}compare(e){return this==e||this.constructor==e.constructor&&this.eq(e)}get estimatedHeight(){return-1}get lineBreaks(){return 0}ignoreEvent(e){return!0}coordsAt(e,t,n){return null}get isHidden(){return!1}get editable(){return!1}destroy(e){}},WA=(function(e){return e[e.Text=0]=`Text`,e[e.WidgetBefore=1]=`WidgetBefore`,e[e.WidgetAfter=2]=`WidgetAfter`,e[e.WidgetRange=3]=`WidgetRange`,e})(WA||={}),GA=class extends Ck{constructor(e,t,n,r){super(),this.startSide=e,this.endSide=t,this.widget=n,this.spec=r}get heightRelevant(){return!1}static mark(e){return new KA(e)}static widget(e){let t=Math.max(-1e4,Math.min(1e4,e.side||0)),n=!!e.block;return t+=n&&!e.inlineOrder?t>0?3e8:-4e8:t>0?1e8:-1e8,new JA(e,t,t,n,e.widget||null,!1)}static replace(e){let t=!!e.block,n,r;if(e.isBlockGap)n=-5e8,r=4e8;else{let{start:i,end:a}=I0e(e,t);n=(i?t?-3e8:-1:5e8)-1,r=(a?t?2e8:1:-6e8)+1}return new JA(e,n,r,t,e.widget||null,!0)}static line(e){return new qA(e)}static set(e,t=!1){return Tk.of(e,t)}hasHeight(){return this.widget?this.widget.estimatedHeight>-1:!1}},GA.none=Tk.empty,KA=class e extends GA{constructor(e){let{start:t,end:n}=I0e(e);super(t?-1:5e8,n?1:-6e8,null,e),this.tagName=e.tagName||`span`,this.class=e.class||``,this.attrs=e.attributes||null}eq(t){return this==t||t instanceof e&&this.tagName==t.tagName&&(this.class||this.attrs?.class)==(t.class||t.attrs?.class)&&Qk(this.attrs,t.attrs,`class`)}range(e,t=e){if(e>=t)throw RangeError(`Mark decorations may not be empty`);return super.range(e,t)}},KA.prototype.point=!1,qA=class e extends GA{constructor(e){super(-2e8,-2e8,null,e)}eq(t){return t instanceof e&&this.spec.class==t.spec.class&&Qk(this.spec.attributes,t.spec.attributes)}range(e,t=e){if(t!=e)throw RangeError(`Line decoration ranges must be zero-length`);return super.range(e,t)}},qA.prototype.mapMode=qO.TrackBefore,qA.prototype.point=!0,JA=class e extends GA{constructor(e,t,n,r,i,a){super(t,n,i,e),this.block=r,this.isReplace=a,this.mapMode=r?t<=0?qO.TrackBefore:qO.TrackAfter:qO.TrackDel}get type(){return this.startSide==this.endSide?this.startSide<=0?WA.WidgetBefore:WA.WidgetAfter:WA.WidgetRange}get heightRelevant(){return this.block||!!this.widget&&(this.widget.estimatedHeight>=5||this.widget.lineBreaks>0)}eq(t){return t instanceof e&&L0e(this.widget,t.widget)&&this.block==t.block&&this.startSide==t.startSide&&this.endSide==t.endSide}range(e,t=e){if(this.isReplace&&(e>t||e==t&&this.startSide>0&&this.endSide<=0))throw RangeError(`Invalid range for replacement decoration`);if(!this.isReplace&&t!=e)throw RangeError(`Widget decorations can only have zero-length ranges`);return super.range(e,t)}},JA.prototype.point=!0,YA=class e extends wA{constructor(){super(...arguments),this.children=[],this.length=0,this.prevAttrs=void 0,this.attrs=null,this.breakAfter=0}merge(t,n,r,i,a,o){if(r){if(!(r instanceof e))return!1;this.dom||r.transferDOM(this)}return i&&this.setDeco(r?r.attrs:null),k0e(this,t,n,r?r.children.slice():[],a,o),!0}split(t){let n=new e;if(n.breakAfter=this.breakAfter,this.length==0)return n;let{i:r,off:i}=this.childPos(t);i&&(n.append(this.children[r].split(i),0),this.children[r].merge(i,this.children[r].length,null,!1,0,0),r++);for(let e=r;e0&&this.children[r-1].length==0;)this.children[--r].destroy();return this.children.length=r,this.markDirty(),this.length=t,n}transferDOM(e){this.dom&&=(this.markDirty(),e.setDOM(this.dom),e.prevAttrs=this.prevAttrs===void 0?this.attrs:this.prevAttrs,this.prevAttrs=void 0,null)}setDeco(e){Qk(this.attrs,e)||(this.dom&&(this.prevAttrs=this.attrs,this.markDirty()),this.attrs=e)}append(e,t){M0e(this,e,t)}addLineDeco(e){let t=e.spec.attributes,n=e.spec.class;t&&(this.attrs=Zk(t,this.attrs||{})),n&&(this.attrs=Zk({class:n},this.attrs||{}))}domAtPos(e){return j0e(this,e)}reuseDOM(e){e.nodeName==`DIV`&&(this.setDOM(e),this.flags|=6)}sync(e,t){this.dom?this.flags&4&&(S0e(this.dom),this.dom.className=`cm-line`,this.prevAttrs=this.attrs?null:void 0):(this.setDOM(document.createElement(`div`)),this.dom.className=`cm-line`,this.prevAttrs=this.attrs?null:void 0),this.prevAttrs!==void 0&&($k(this.dom,this.prevAttrs,this.attrs),this.dom.classList.add(`cm-line`),this.prevAttrs=void 0),super.sync(e,t);let n=this.dom.lastChild;for(;n&&wA.get(n)instanceof zA;)n=n.lastChild;if(!n||!this.length||n.nodeName!=`BR`&&wA.get(n)?.isEditable==0&&(!LA.ios||!this.children.some(e=>e instanceof RA))){let e=document.createElement(`BR`);e.cmIgnore=!0,this.dom.appendChild(e)}}measureTextSize(){if(this.children.length==0||this.length>20)return null;let e=0,t;for(let n of this.children){if(!(n instanceof RA)||/[^ -~]/.test(n.text))return null;let r=Uk(n.dom);if(r.length!=1)return null;e+=r[0].width,t=r[0].height}return e?{lineHeight:this.dom.getBoundingClientRect().height,charWidth:e/this.length,textHeight:t}:null}coordsAt(e,t){let n=N0e(this,e,t);if(!this.children.length&&n&&this.parent){let{heightOracle:e}=this.parent.view.viewState,t=n.bottom-n.top;if(Math.abs(t-e.lineHeight)<2&&e.textHeight=n){if(a instanceof e)return a;if(o>n)break}i=o+a.breakAfter}return null}},XA=class e extends wA{constructor(e,t,n){super(),this.widget=e,this.length=t,this.deco=n,this.breakAfter=0,this.prevWidget=null}merge(t,n,r,i,a,o){return r&&(!(r instanceof e)||!this.widget.compare(r.widget)||t>0&&a<=0||n0}},ZA=class extends UA{constructor(e){super(),this.height=e}toDOM(){let e=document.createElement(`div`);return e.className=`cm-gap`,this.updateDOM(e),e}eq(e){return e.height==this.height}updateDOM(e){return e.style.height=this.height+`px`,!0}get editable(){return!0}get estimatedHeight(){return this.height}ignoreEvent(){return!1}},QA=class e{constructor(e,t,n,r){this.doc=e,this.pos=t,this.end=n,this.disallowBlockEffectsFor=r,this.content=[],this.curLine=null,this.breakAtStart=0,this.pendingBuffer=0,this.bufferMarks=[],this.atCursorPos=!0,this.openStart=-1,this.openEnd=-1,this.text=``,this.textOff=0,this.cursor=e.iter(),this.skip=t}posCovered(){if(this.content.length==0)return!this.breakAtStart&&this.doc.lineAt(this.pos).from!=this.pos;let e=this.content[this.content.length-1];return!(e.breakAfter||e instanceof XA&&e.deco.endSide<0)}getLine(){return this.curLine||(this.content.push(this.curLine=new YA),this.atCursorPos=!0),this.curLine}flushBuffer(e=this.bufferMarks){this.pendingBuffer&&=(this.curLine.append(tA(new VA(-1),e),e.length),0)}addBlockWidget(e){this.flushBuffer(),this.curLine=null,this.content.push(e)}finish(e){this.pendingBuffer&&e<=this.bufferMarks.length?this.flushBuffer():this.pendingBuffer=0,!this.posCovered()&&!(e&&this.content.length&&this.content[this.content.length-1]instanceof XA)&&this.getLine()}buildText(e,t,n){for(;e>0;){if(this.textOff==this.text.length){let{value:t,lineBreak:n,done:r}=this.cursor.next(this.skip);if(this.skip=0,r)throw Error(`Ran out of text content when drawing inline views`);if(n){this.posCovered()||this.getLine(),this.content.length?this.content[this.content.length-1].breakAfter=1:this.breakAtStart=1,this.flushBuffer(),this.curLine=null,this.atCursorPos=!0,e--;continue}else this.text=t,this.textOff=0}let r=Math.min(this.text.length-this.textOff,e,512);this.flushBuffer(t.slice(t.length-n)),this.getLine().append(tA(new RA(this.text.slice(this.textOff,this.textOff+r)),t),n),this.atCursorPos=!0,this.textOff+=r,e-=r,n=0}}span(e,t,n,r){this.buildText(t-e,n,r),this.pos=t,this.openStart<0&&(this.openStart=r)}point(e,t,n,r,i,a){if(this.disallowBlockEffectsFor[a]&&n instanceof JA){if(n.block)throw RangeError(`Block decorations may not be specified via plugins`);if(t>this.doc.lineAt(this.pos).to)throw RangeError(`Decorations that replace line breaks may not be specified via plugins`)}let o=t-e;if(n instanceof JA)if(n.block)n.startSide>0&&!this.posCovered()&&this.getLine(),this.addBlockWidget(new XA(n.widget||$A.block,o,n));else{let a=BA.create(n.widget||$A.inline,o,o?0:n.startSide),s=this.atCursorPos&&!a.isEditable&&i<=r.length&&(e0),c=!a.isEditable&&(er.length||n.startSide<=0),l=this.getLine();this.pendingBuffer==2&&!s&&!a.isEditable&&(this.pendingBuffer=0),this.flushBuffer(r),s&&(l.append(tA(new VA(1),r),i),i=r.length+Math.max(0,i-r.length)),l.append(tA(a,r),i),this.atCursorPos=c,this.pendingBuffer=c?er.length?1:2:0,this.pendingBuffer&&(this.bufferMarks=r.slice())}else this.doc.lineAt(this.pos).from==this.pos&&this.getLine().addLineDeco(n);o&&(this.textOff+o<=this.text.length?this.textOff+=o:(this.skip+=o-(this.text.length-this.textOff),this.text=``,this.textOff=0),this.pos=t),this.openStart<0&&(this.openStart=i)}static build(t,n,r,i,a){let o=new e(t,n,r,a);return o.openEnd=Tk.spans(i,n,r,o),o.openStart<0&&(o.openStart=o.openEnd),o.finish(o.openEnd),o}},$A=class extends UA{constructor(e){super(),this.tag=e}eq(e){return e.tag==this.tag}toDOM(){return document.createElement(this.tag)}updateDOM(e){return e.nodeName.toLowerCase()==this.tag}get isHidden(){return!0}},$A.inline=new $A(`span`),$A.block=new $A(`div`),ej=(function(e){return e[e.LTR=0]=`LTR`,e[e.RTL=1]=`RTL`,e})(ej||={}),tj=ej.LTR,nj=ej.RTL,O4e=R0e(`88888888888888888888888888888888888666888888787833333333337888888000000000000000000000000008888880000000000000000000000000088888888888888888888888888888888888887866668888088888663380888308888800000000000000000000000800000000000000000000000000000008`),k4e=R0e(`4444448826627288999999999992222222222222222222222222222222222222222222222229999999999999999999994444444444644222822222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222999999949999999229989999223333333333`),rj=Object.create(null),ij=[];for(let e of[`()`,`[]`,`{}`]){let t=e.charCodeAt(0),n=e.charCodeAt(1);rj[t]=n,rj[n]=-t}A4e=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac\ufb50-\ufdff]/,aj=class{get dir(){return this.level%2?nj:tj}constructor(e,t,n){this.from=e,this.to=t,this.level=n}side(e,t){return this.dir==t==e?this.to:this.from}forward(e,t){return e==(this.dir==t)}static find(e,t,n,r){let i=-1;for(let a=0;a=t){if(o.level==n)return a;(i<0||(r==0?e[i].level>o.level:r<0?o.fromt))&&(i=a)}}if(i<0)throw RangeError(`Index out of range`);return i}},oj=[],sj=``,cj=ek.define(),lj=ek.define(),uj=ek.define(),dj=ek.define(),fj=ek.define(),pj=ek.define(),mj=ek.define(),hj=ek.define(),gj=ek.define(),_j=ek.define({combine:e=>e.some(e=>e)}),j4e=ek.define({combine:e=>e.some(e=>e)}),vj=ek.define(),yj=class e{constructor(e,t=`nearest`,n=`nearest`,r=5,i=5,a=!1){this.range=e,this.y=t,this.x=n,this.yMargin=r,this.xMargin=i,this.isSnapshot=a}map(t){return t.empty?this:new e(this.range.map(t),this.y,this.x,this.yMargin,this.xMargin,this.isSnapshot)}clip(t){return this.range.to<=t.doc.length?this:new e(QO.cursor(t.doc.length),this.y,this.x,this.yMargin,this.xMargin,this.isSnapshot)}},bj=vk.define({map:(e,t)=>e.map(t)}),xj=vk.define(),Sj=ek.define({combine:e=>!e.length||e[0]}),M4e=0,Cj=ek.define(),wj=class e{constructor(e,t,n,r,i){this.id=e,this.create=t,this.domEventHandlers=n,this.domEventObservers=r,this.extension=i(this)}static define(t,n){let{eventHandlers:r,eventObservers:i,provide:a,decorations:o}=n||{};return new e(M4e++,t,r,i,e=>{let t=[Cj.of(e)];return o&&t.push(Oj.of(t=>{let n=t.plugin(e);return n?o(n):GA.none})),a&&t.push(a(e)),t})}static fromClass(t,n){return e.define(e=>new t(e),n)}},Tj=class{constructor(e){this.spec=e,this.mustUpdate=null,this.value=null}update(e){if(!this.value){if(this.spec)try{this.value=this.spec.create(e)}catch(t){iA(e.state,t,`CodeMirror plugin crashed`),this.deactivate()}}else if(this.mustUpdate){let e=this.mustUpdate;if(this.mustUpdate=null,this.value.update)try{this.value.update(e)}catch(t){if(iA(e.state,t,`CodeMirror plugin crashed`),this.value.destroy)try{this.value.destroy()}catch{}this.deactivate()}}return this}destroy(e){if(this.value?.destroy)try{this.value.destroy()}catch(t){iA(e.state,t,`CodeMirror plugin crashed`)}}deactivate(){this.spec=this.value=null}},Ej=ek.define(),Dj=ek.define(),Oj=ek.define(),kj=ek.define(),Aj=ek.define(),jj=ek.define(),Mj=ek.define(),Nj=ek.define(),Pj=class e{constructor(e,t,n,r){this.fromA=e,this.toA=t,this.fromB=n,this.toB=r}join(t){return new e(Math.min(this.fromA,t.fromA),Math.max(this.toA,t.toA),Math.min(this.fromB,t.fromB),Math.max(this.toB,t.toB))}addToSet(e){let t=e.length,n=this;for(;t>0;t--){let r=e[t-1];if(!(r.fromA>n.toA)){if(r.toAu)break;a+=2}if(!c)return r;new e(c.fromA,c.toA,c.fromB,c.toB).addToSet(r),o=c.toA,s=c.toB}}},Fj=class e{constructor(e,t,n){this.view=e,this.state=t,this.transactions=n,this.flags=0,this.startState=e.state,this.changes=YO.empty(this.startState.doc.length);for(let e of n)this.changes=this.changes.compose(e.changes);let r=[];this.changes.iterChangedRanges((e,t,n,i)=>r.push(new Pj(e,t,n,i))),this.changedRanges=r}static create(t,n,r){return new e(t,n,r)}get viewportChanged(){return(this.flags&4)>0}get heightChanged(){return(this.flags&2)>0}get geometryChanged(){return this.docChanged||(this.flags&10)>0}get focusChanged(){return(this.flags&1)>0}get docChanged(){return!this.changes.empty}get selectionSet(){return this.transactions.some(e=>e.selection)}get empty(){return this.flags==0&&this.transactions.length==0}},Ij=class extends wA{get length(){return this.view.state.doc.length}constructor(e){super(),this.view=e,this.decorations=[],this.dynamicDecorationMap=[!1],this.domChanged=null,this.hasComposition=null,this.markedForComposition=new Set,this.editContextFormatting=GA.none,this.lastCompositionAfterCursor=!1,this.minWidth=0,this.minWidthFrom=0,this.minWidthTo=0,this.impreciseAnchor=null,this.impreciseHead=null,this.forceSelection=!1,this.lastUpdate=Date.now(),this.setDOM(e.contentDOM),this.children=[new YA],this.children[0].setParent(this),this.updateDeco(),this.updateInner([new Pj(0,0,0,e.state.doc.length)],0,null)}update(e){let t=e.changedRanges;this.minWidth>0&&t.length&&(t.every(({fromA:e,toA:t})=>t