c;)t==a&&(t=n[--r].from,a=r?n[r-1].to:e),pj[--t]=u;c=o}else a=o,c++}}}function lA(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 fj(c,m.from,f)),uA(e,m.direction==cj==!(f%2)?r:r+1,i,m.inner,m.from,m.to,o),c=m.to),p=m.to}else if(p==n||(t?pj[p]!=s:pj[p]==s))break;else p++;d?lA(e,c,p,r+1,i,d,o):ct;){let n=!0,u=!1;if(!l||c>a[l-1].to){let e=pj[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(pj[e-1]==s)break run;else break}d?d.push(m):(m.topj.length;)pj[pj.length]=256;let r=[],i=t==cj?0:1;return uA(e,i,i,n,0,e.length,r),r}function d6e(e){return[new fj(0,e,0)]}function f6e(e,t,n,r,i){let a=r.head-e.from,o=fj.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=EO(e.text,a,s.forward(i,n));(ls.to)&&(l=c),mj=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+(i?0:1)t instanceof Function?t(e):t),i=[];return Mk.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??=p6e(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 fA(e){let t=0,n=0,r=0,i=0;for(let a of e.state.facet(zj)){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 h6e(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 g6e(e,t){let n=e.observer.selectionRange;if(!n.focusNode)return null;let r=G3e(n.focusNode,n.focusOffset),i=K3e(n.focusNode,n.focusOffset),a=r||i;if(i&&r&&i.node!=r.node){let t=jA.get(i.node);if(!t||t instanceof GA&&t.text!=i.node.nodeValue)a=i;else if(e.docView.lastCompositionAfterCursor){let e=jA.get(r.node);!e||e instanceof GA&&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 _6e(e,t,n){let r=g6e(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 Vj(c.mapPos(a),c.mapPos(o),a,o),u=[];for(let t=i.parentNode;;t=t.parentNode){let n=jA.get(t);if(n instanceof KA)u.push({node:t,deco:n.mark});else if(n instanceof nj||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 $A({inclusive:!0,attributes:t6e(t),tagName:t.tagName.toLowerCase()})});else return null}}function v6e(e,t){return e.nodeType==1?(t&&e.childNodes[t-1].contentEditable==`false`?1:0)|(t{et.from&&(n=!0)}),n}function S6e(e,t,n=1){let r=e.charCategorizer(t),i=e.doc.lineAt(t),a=t-i.from;if(i.length==0)return ak.cursor(t);a==0?n=1:a==i.length&&(n=-1);let o=a,s=a;n<0?o=EO(i.text,a,!1):s=EO(i.text,a);let c=r(i.text.slice(o,s));for(;o>0;){let e=EO(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 w6e(e,t){return t.top>e?t.top-e:Math.max(0,e-t.bottom)}function pA(e,t){return e.topt.top+1}function T6e(e,t){return te.bottom?{top:e.top,left:e.left,right:e.right,bottom:t}:e}function mA(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=Xk(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&&pA(u,m)?u=E6e(u,m.bottom):d&&pA(d,m)&&(d=T6e(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?D6e(r,f,n):s&&r.contentEditable!=`false`?mA(r,f,n):{node:e,offset:Array.prototype.indexOf.call(e.childNodes,r)+(t>=(i.left+i.right)/2?1:0)}}function D6e(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((WA.chrome||WA.gecko)&&nA(e,s).getBoundingClientRect().left==l.right&&(r=!n),u<=0)return{node:e,offset:s+(r?1:0)};i=s+(r?1:0),a=u}}}return{node:e,offset:i>-1?i:o>0?e.nodeValue.length:0}}function O6e(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!=ZA.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:k6e(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)||WA.safari&&A6e(h,g,c)||WA.chrome&&j6e(h,g,c))&&(h=void 0))}h&&(g=Math.min(eA(h),g))}if(!h||!e.docView.dom.contains(h)){let t=nj.find(e.docView,d);if(!t)return u>o.top+o.height/2?o.to:o.from;({node:h,offset:g}=mA(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+S3e(o,a,e.state.tabSize)}function A6e(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 nA(e,r-1,r).getBoundingClientRect().left>n}function j6e(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():nA(e,0,Math.max(e.nodeValue.length,1)).getBoundingClientRect()).left>5}function M6e(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==ZA.Text))return e}return n}function N6e(e,t,n,r){let i=M6e(e,t.head),a=!r||i.type!=ZA.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==sj.LTR)?t.right-1:t.left+1,y:(a.top+a.bottom)/2});if(o!=null)return ak.cursor(o,n?-1:1)}return ak.cursor(n?i.to:i.from,n?-1:1)}function P6e(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=f6e(i,a,o,s,n),l=mj;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 F6e(e,t,n){let r=e.state.charCategorizer(t),i=r(n);return e=>{let t=r(e);return i==Dk.Space&&(i=t),i==t}}function I6e(e,t,n,r){let i=t.head,a=n?1:-1;if(i==(n?e.state.doc.length:0))return ak.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=O6e(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:ak.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||WA.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))}:(WA.mac||WA.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=ak.single(r.main.anchor-1,r.main.head-1)),n={from:i.from,to:i.to,insert:qO.of([` `])}):WA.chrome&&n&&n.from==n.to&&n.from==i.head&&n.insert.toString()==`
+ `&&e.lineWrapping&&(r&&=ak.single(r.main.anchor-1,r.main.head-1),n={from:i.from,to:i.to,insert:qO.of([` `])}),n)return _A(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 _A(e,t,n,r=-1){if(WA.ios&&e.inputState.flushIOSKey(t))return!0;let i=e.state.selection.main;if(WA.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&&rA(e.contentDOM,`Enter`,13)||(t.from==i.from-1&&t.to==i.to&&t.insert.length==0||r==8&&t.insert.lengthi.head)&&rA(e.contentDOM,`Backspace`,8)||t.from==i.from&&t.to==i.to+1&&t.insert.length==0&&rA(e.contentDOM,`Delete`,46)))return!0;let a=t.insert.toString();e.inputState.composing>=0&&e.inputState.composing++;let o,s=()=>o||=z6e(e,t,n);return e.state.facet(bj).some(n=>n(e,t.from,t.to,a,s))||e.dispatch(s()),!0}function z6e(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&&g6e(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?ak.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 B6e(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 V6e(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 Gj(n,r)),(i!=n||a!=r)&&t.push(new Gj(i,a))),t}function H6e(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?ak.single(n+t,r+t):null}function U6e(e,t){return(n,r)=>{try{return t.call(e,r,n)}catch(e){dA(n.state,e)}}}function W6e(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(U6e(t.value,i))}if(e&&e.domEventObservers)for(let r in e.domEventObservers){let i=e.domEventObservers[r];i&&n(r).observers.push(U6e(t.value,i))}}for(let e in Yj)n(e).handlers.push(Yj[e]);for(let e in Xj)n(e).observers.push(Xj[e]);return t}function vA(e){return Math.max(0,e)*.7+8}function G6e(e,t){return Math.max(Math.abs(e.clientX-t.clientX),Math.abs(e.clientY-t.clientY))}function K6e(e,t){let n=e.state.facet(hj);return n.length?n[0](t):WA.mac?t.metaKey:t.ctrlKey}function q6e(e,t){let n=e.state.facet(gj);return n.length?n[0](t):WA.mac?!t.altKey:!t.ctrlKey}function J6e(e,t){let{main:n}=e.state.selection;if(n.empty)return!1;let r=qk(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 Y6e(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=jA.get(n))&&r.ignoreEvent(t))return!1;return!0}function X6e(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(),Z6e(e,n.value)},50)}function yA(e,t,n){for(let r of e.facet(t))n=r(n,e);return n}function Z6e(e,t){t=yA(e.state,Sj,t);let{state:n}=e,r,i=1,a=n.toText(t),o=a.lines==n.selection.ranges.length;if(nM!=null&&n.selection.ranges.every(e=>e.empty)&&nM==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:ak.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:ak.cursor(e.from+t.length)}}):n.replaceSelection(a);e.dispatch(r,{userEvent:`input.paste`,scrollIntoView:!0})}function Q6e(e,t,n,r){if(r==1)return ak.cursor(t,n);if(r==2)return S6e(e.state,t,n);{let n=nj.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 e8e(e,t){let n=e.posAtCoords({x:t.clientX,y:t.clientY},!1);return{pos:n,bias:$6e(e,n,t.clientX,t.clientY)}}function t8e(e){if(!a5e)return e.detail;let t=$j,n=tM;return $j=e,tM=Date.now(),eM=!t||n>Date.now()-400&&Math.abs(t.clientX-e.clientX)<2&&Math.abs(t.clientY-e.clientY)<2?(eM+1)%3:1}function n8e(e,t){let n=e8e(e,t),r=t8e(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=e8e(e,t),c,l=Q6e(e,s.pos,s.bias,r);if(n.pos!=s.pos&&!a){let t=Q6e(e,n.pos,n.bias,r),i=Math.min(t.from,l.from),a=Math.max(t.to,l.to);l=i1&&(c=r8e(i,s.pos))?c:o?i.addRange(l):ak.create([l])}}}function r8e(e,t){for(let n=0;n=t)return ak.create(e.ranges.slice(0,n).concat(e.ranges.slice(n+1)),e.mainIndex==n?0:e.mainIndex-(e.mainIndex>n?1:0))}return null}function i8e(e,t,n,r){if(n=yA(e.state,Sj,n),!n)return;let i=e.posAtCoords({x:t.clientX,y:t.clientY},!1),{draggedContent:a}=e.inputState,o=r&&a&&q6e(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 a8e(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 o8e(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:yA(e,Cj,t.join(e.lineBreak)),ranges:n,linewise:r}}function s8e(e,t){let n=[];for(let r of e.facet(xj)){let i=r(e,t);i&&n.push(i)}return n?e.update({effects:n,annotations:rM.of(!0)}):null}function c8e(e){setTimeout(()=>{let t=e.hasFocus;if(t!=e.inputState.notifiedFocused){let n=s8e(e.state,t);n?e.dispatch(n):e.update([])}},10)}function l8e(e){iM.has(e)||(iM.add(e),e.addEventListener(`copy`,()=>{}),e.addEventListener(`cut`,()=>{}))}function u8e(){oM=!1}function bA(e,t){return e==t?e:(e.constructor!=t.constructor&&(oM=!0),t)}function d8e(e,t){let n,r;e[t]==null&&(n=e[t-1])instanceof pM&&(r=e[t+1])instanceof pM&&e.splice(t-1,3,new pM(n.length+1+r.length))}function f8e(e,t,n){let r=new d5e;return Mk.compare(e,t,n,r,0),r.changes}function p8e(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 m8e(e,t){let n=e.getBoundingClientRect();return{left:0,right:n.right-n.left,top:t,bottom:n.bottom-(n.top+t)}}function h8e(e,t,n){let r=[],i=e,a=0;return Mk.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 SA(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 g8e(e,t){for(let n of e)if(t(n))return n}function CA(e,t){if(t.scale==1)return e;let n=t.toDOM(e.top),r=t.toDOM(e.bottom);return new sM(e.from,e.length,n,r-n,Array.isArray(e._content)?e._content.map(e=>CA(e,t)):e._content)}function wA(e,t,n){return new Hk(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 _8e(e,t,n){for(;t;){let r=jA.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 v8e(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 Zk(o.node,o.offset,i,a)&&([n,r,i,a]=[i,a,n,r]),{anchorNode:n,anchorOffset:r,focusNode:i,focusOffset:a}}function y8e(e,t){if(t.getComposedRanges){let n=t.getComposedRanges(e.root)[0];if(n)return v8e(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?v8e(e,n):null}function b8e(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&&iA(a,n)}return n}function x8e(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 C8e(e,t=y5e){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=>x8e(e,t));for(let t=1;t{let r=AM={view:t,prefix:n,scope:e};return setTimeout(()=>{AM==r&&(AM=null)},x5e),!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,jM))}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 w8e(e,t,n,r){jM=t;let i=j3e(t),a=OO(DO(i,0))==i.length&&i!=` `,o=``,s=!1,c=!1,l=!1;AM&&AM.view==n&&AM.scope==r&&(o=AM.prefix+` `,qj.indexOf(t.keyCode)<0&&(c=!0,AM=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+TA(i,t,!a)])?s=!0:a&&(t.altKey||t.metaKey||t.ctrlKey)&&!(WA.windows&&t.ctrlKey&&t.altKey)&&(p=Wk[t.keyCode])&&p!=i?(d(f[o+TA(p,t,!0)])||t.shiftKey&&(m=Gk[t.keyCode])!=i&&m!=p&&d(f[o+TA(m,t,!1)]))&&(s=!0):a&&t.shiftKey&&d(f[o+TA(i,t,!0)])&&(s=!0),!s&&d(f._any)&&(s=!0)),c&&(s=!0),s&&l&&t.stopPropagation(),jM=null,s}function T8e(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 E8e(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 D8e(){if(FM==null&&typeof document<`u`&&document.body){let e=document.body.style;FM=(e.tabSize??e.MozTabSize)!=null}return FM||!1}function O8e(e={}){return[IM.of(e),k8e()]}function k8e(){return T5e||=jj.fromClass(class{constructor(e){this.view=e,this.decorations=QA.none,this.decorationCache=Object.create(null),this.decorator=this.makeDecorator(e.state.facet(IM)),this.decorations=this.decorator.createDeco(e)}makeDecorator(e){return new NM({regexp:e.specialChars,decoration:(t,n,r)=>{let{doc:i}=n.state,a=DO(t[0],0);if(a==9){let e=i.lineAt(r),t=n.state.tabSize,a=KO(e.text,t,r-e.from);return QA.replace({widget:new O5e((t-a%t)*this.view.defaultCharacterWidth/this.view.scaleX)})}return this.decorationCache[a]||(this.decorationCache[a]=QA.replace({widget:new D5e(e,a)}))},boundary:e.replaceTabs?void 0:/[^]/})}update(e){let t=e.state.facet(IM);e.startState.facet(IM)==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 A8e(e){return e>=32?E5e:e==10?``:String.fromCharCode(9216+e)}function j8e(e){return jj.fromClass(class{constructor(t){this.view=t,this.placeholder=e?QA.set([QA.widget({widget:new k5e(e),side:1}).range(0)]):QA.none}get decorations(){return this.view.state.doc.length?QA.none:this.placeholder}},{decorations:e=>e.decorations})}function M8e(e){let{win:t}=e;return{top:0,left:0,bottom:t.innerHeight,right:t.innerWidth}}function N8e(e,t){let n=parseInt(e.style.left,10);(isNaN(n)||Math.abs(t-n)>1)&&(e.style.left=t+`px`)}function P8e(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-GM&&t.clientX<=r+GM&&t.clientY>=i-GM&&t.clientY<=a+GM}function F8e(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 I8e(e,t={}){let n=Tk.define(),r=uk.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,ek.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(P5e)&&(e=[]);return e},provide:e=>UM.from(e)});return{active:r,extension:[r,jj.define(i=>new N5e(i,e,r,n,t.hoverTime||300)),M5e]}}function L8e(e,t){let n=e.plugin(VM);if(!n)return null;let r=n.manager.tooltips.indexOf(t);return r<0?null:n.manager.tooltipViews[r]}function R8e(e){let t=e.nextSibling;return e.remove(),t}function z8e(e){return[B8e(),ZM.of(Object.assign(Object.assign({},L5e),e))]}function B8e(e){let t=[R5e];return e&&e.fixed===!1&&t.push(QM.of(!0)),t}function V8e(e){return Array.isArray(e)?e:[e]}function EA(e,t,n){for(;e.value&&e.from<=n;)e.from==n&&t.push(e.value),e.next()}function H8e(e,t){if(e.length!=t.length)return!1;for(let n=0;n{Lk(),A3e(),P3e(),G8e=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?eA(t):0),n,Math.min(e.focusOffset,n?eA(n):0))}set(e,t,n,r){this.anchorNode=e,this.anchorOffset=t,this.focusNode=n,this.focusOffset=r}},OA=null,kA=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,Qk(t),n)}static after(t,n){return new e(t.parentNode,Qk(t)+1,n)}},AA=[],jA=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=q3e(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=q3e(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=eA(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=AA){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}}},NA=typeof navigator<`u`?navigator:{userAgent:``,vendor:``,platform:``},PA=typeof document<`u`?document:{documentElement:{style:{}}},FA=/Edge\/(\d+)/.exec(NA.userAgent),IA=/MSIE \d/.test(NA.userAgent),LA=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(NA.userAgent),RA=!!(IA||LA||FA),zA=!RA&&/gecko\/(\d+)/i.test(NA.userAgent),BA=!RA&&/Chrome\/(\d+)/.exec(NA.userAgent),VA=`webkitFontSmoothing`in PA.documentElement.style,HA=!RA&&/Apple Computer/.test(NA.vendor),UA=HA&&(/Mobile\/\w+/.test(NA.userAgent)||NA.maxTouchPoints>2),WA={mac:UA||/Mac/.test(NA.platform),windows:/Win/.test(NA.platform),linux:/Linux|X11/.test(NA.platform),ie:RA,ie_version:IA?PA.documentMode||6:LA?+LA[1]:FA?+FA[1]:0,gecko:zA,gecko_version:zA?+(/Firefox\/(\d+)/.exec(NA.userAgent)||[0,0])[1]:0,chrome:!!BA,chrome_version:BA?+BA[1]:0,ios:UA,android:/Android\b/.test(NA.userAgent),webkit:VA,safari:HA,webkit_version:VA?+(/\bAppleWebKit\/(\d+)/.exec(NA.userAgent)||[0,0])[1]:0,tabSize:PA.documentElement.style.tabSize==null?`-moz-tab-size`:`tab-size`},q8e=256,GA=class e extends jA{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>q8e||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 kA(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 X3e(this.dom,e,t)}},KA=class e extends jA{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(H3e(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 Z3e(this,e)}coordsAt(e,t){return $3e(this,e,t)}},qA=class e extends jA{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)?kA.before(this.dom):kA.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?kA.before(this.dom):kA.after(this.dom)}localPosFromDOM(){return 0}domBoundsAround(){return null}coordsAt(e){return this.dom.getBoundingClientRect()}get overrideDOMText(){return qO.empty}get isHidden(){return!0}},GA.prototype.children=qA.prototype.children=JA.prototype.children=AA,YA=Object.create(null),XA=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){}},ZA=(function(e){return e[e.Text=0]=`Text`,e[e.WidgetBefore=1]=`WidgetBefore`,e[e.WidgetAfter=2]=`WidgetAfter`,e[e.WidgetRange=3]=`WidgetRange`,e})(ZA||={}),QA=class extends Ak{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 $A(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 tj(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}=n6e(e,t);n=(i?t?-3e8:-1:5e8)-1,r=(a?t?2e8:1:-6e8)+1}return new tj(e,n,r,t,e.widget||null,!0)}static line(e){return new ej(e)}static set(e,t=!1){return Mk.of(e,t)}hasHeight(){return this.widget?this.widget.estimatedHeight>-1:!1}},QA.none=Mk.empty,$A=class e extends QA{constructor(e){let{start:t,end:n}=n6e(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)&&aA(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)}},$A.prototype.point=!1,ej=class e extends QA{constructor(e){super(-2e8,-2e8,null,e)}eq(t){return t instanceof e&&this.spec.class==t.spec.class&&aA(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)}},ej.prototype.mapMode=ek.TrackBefore,ej.prototype.point=!0,tj=class e extends QA{constructor(e,t,n,r,i,a){super(t,n,i,e),this.block=r,this.isReplace=a,this.mapMode=r?t<=0?ek.TrackBefore:ek.TrackAfter:ek.TrackDel}get type(){return this.startSide==this.endSide?this.startSide<=0?ZA.WidgetBefore:ZA.WidgetAfter:ZA.WidgetRange}get heightRelevant(){return this.block||!!this.widget&&(this.widget.estimatedHeight>=5||this.widget.lineBreaks>0)}eq(t){return t instanceof e&&r6e(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)}},tj.prototype.point=!0,nj=class e extends jA{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),Y3e(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){aA(this.attrs,e)||(this.dom&&(this.prevAttrs=this.attrs,this.markDirty()),this.attrs=e)}append(e,t){Q3e(this,e,t)}addLineDeco(e){let t=e.spec.attributes,n=e.spec.class;t&&(this.attrs=iA(t,this.attrs||{})),n&&(this.attrs=iA({class:n},this.attrs||{}))}domAtPos(e){return Z3e(this,e)}reuseDOM(e){e.nodeName==`DIV`&&(this.setDOM(e),this.flags|=6)}sync(e,t){this.dom?this.flags&4&&(H3e(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&&(oA(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&&jA.get(n)instanceof KA;)n=n.lastChild;if(!n||!this.length||n.nodeName!=`BR`&&jA.get(n)?.isEditable==0&&(!WA.ios||!this.children.some(e=>e instanceof GA))){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 GA)||/[^ -~]/.test(n.text))return null;let r=Xk(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=$3e(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}},rj=class e extends jA{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}},ij=class extends XA{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}},aj=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 rj&&e.deco.endSide<0)}getLine(){return this.curLine||(this.content.push(this.curLine=new nj),this.atCursorPos=!0),this.curLine}flushBuffer(e=this.bufferMarks){this.pendingBuffer&&=(this.curLine.append(cA(new JA(-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 rj)&&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(cA(new GA(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 tj){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 tj)if(n.block)n.startSide>0&&!this.posCovered()&&this.getLine(),this.addBlockWidget(new rj(n.widget||oj.block,o,n));else{let a=qA.create(n.widget||oj.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(cA(new JA(1),r),i),i=r.length+Math.max(0,i-r.length)),l.append(cA(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=Mk.spans(i,n,r,o),o.openStart<0&&(o.openStart=o.openEnd),o.finish(o.openEnd),o}},oj=class extends XA{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}},oj.inline=new oj(`span`),oj.block=new oj(`div`),sj=(function(e){return e[e.LTR=0]=`LTR`,e[e.RTL=1]=`RTL`,e})(sj||={}),cj=sj.LTR,lj=sj.RTL,J8e=i6e(`88888888888888888888888888888888888666888888787833333333337888888000000000000000000000000008888880000000000000000000000000088888888888888888888888888888888888887866668888088888663380888308888800000000000000000000000800000000000000000000000000000008`),Y8e=i6e(`4444448826627288999999999992222222222222222222222222222222222222222222222229999999999999999999994444444444644222822222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222999999949999999229989999223333333333`),uj=Object.create(null),dj=[];for(let e of[`()`,`[]`,`{}`]){let t=e.charCodeAt(0),n=e.charCodeAt(1);uj[t]=n,uj[n]=-t}X8e=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac\ufb50-\ufdff]/,fj=class{get dir(){return this.level%2?lj:cj}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}},pj=[],mj=``,hj=sk.define(),gj=sk.define(),_j=sk.define(),vj=sk.define(),yj=sk.define(),bj=sk.define(),xj=sk.define(),Sj=sk.define(),Cj=sk.define(),wj=sk.define({combine:e=>e.some(e=>e)}),Z8e=sk.define({combine:e=>e.some(e=>e)}),Tj=sk.define(),Ej=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(ak.cursor(t.doc.length),this.y,this.x,this.yMargin,this.xMargin,this.isSnapshot)}},Dj=Tk.define({map:(e,t)=>e.map(t)}),Oj=Tk.define(),kj=sk.define({combine:e=>e.length?e[0]:!0}),Q8e=0,Aj=sk.define(),jj=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(Q8e++,t,r,i,e=>{let t=[Aj.of(e)];return o&&t.push(Fj.of(t=>{let n=t.plugin(e);return n?o(n):QA.none})),a&&t.push(a(e)),t})}static fromClass(t,n){return e.define(e=>new t(e),n)}},Mj=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){dA(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(dA(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){dA(e.state,t,`CodeMirror plugin crashed`)}}deactivate(){this.spec=this.value=null}},Nj=sk.define(),Pj=sk.define(),Fj=sk.define(),Ij=sk.define(),Lj=sk.define(),Rj=sk.define(),zj=sk.define(),Bj=sk.define(),Vj=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}}},Hj=class e{constructor(e,t,n){this.view=e,this.state=t,this.transactions=n,this.flags=0,this.startState=e.state,this.changes=nk.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 Vj(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}},Uj=class extends jA{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=QA.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 nj],this.children[0].setParent(this),this.updateDeco(),this.updateInner([new Vj(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})=>tthis.minWidthTo)?(this.minWidthFrom=e.changes.mapPos(this.minWidthFrom,1),this.minWidthTo=e.changes.mapPos(this.minWidthTo,1)):this.minWidth=this.minWidthFrom=this.minWidthTo=0),this.updateEditContextFormatting(e);let n=-1;this.view.inputState.composing>=0&&!this.view.observer.editContext&&(this.domChanged?.newSel?n=this.domChanged.newSel.head:!x6e(e.changes,this.hasComposition)&&!e.selectionSet&&(n=e.state.selection.main.head));let r=n>-1?_6e(this.view,e.changes,n):null;if(this.domChanged=null,this.hasComposition){this.markedForComposition.clear();let{from:n,to:r}=this.hasComposition;t=new Vj(n,r,e.changes.mapPos(n,-1),e.changes.mapPos(r,1)).addToSet(t.slice())}this.hasComposition=r?{from:r.range.fromB,to:r.range.toB}:null,(WA.ie||WA.chrome)&&!r&&e&&e.state.doc.lines!=e.startState.doc.lines&&(this.forceSelection=!0);let i=this.decorations,a=y6e(i,this.updateDeco(),e.changes);return t=Vj.extendWithRanges(t,a),!(this.flags&7)&&t.length==0?!1:(this.updateInner(t,e.startState.doc.length,r),e.transactions.length&&(this.lastUpdate=Date.now()),!0)}updateInner(e,t,n){this.view.viewState.mustMeasureContent=!0,this.updateChildren(e,t,n);let{observer:r}=this.view;r.ignore(()=>{this.dom.style.height=this.view.viewState.contentHeight/this.view.scaleY+`px`,this.dom.style.flexBasis=this.minWidth?this.minWidth+`px`:``;let e=WA.chrome||WA.ios?{node:r.selectionRange.focusNode,written:!1}:void 0;this.sync(this.view,e),this.flags&=-8,e&&(e.written||r.selectionRange.focusNode!=e.node)&&(this.forceSelection=!0),this.dom.style.height=``}),this.markedForComposition.forEach(e=>e.flags&=-9);let i=[];if(this.view.viewport.from||this.view.viewport.to=0?r[e]:null;if(!t)break;let{fromA:a,toA:o,fromB:s,toB:c}=t,l,u,d,f;if(n&&n.range.fromB