l&&o.push(new zi(l,f.from,u)),Ui(e,f.direction==Di!=!(u%2)?n+1:n,s,f.inner,f.from,f.to,o),l=f.to),p=f.to}else{if(p==i||(t?Wi[p]!=a:Wi[p]==a))break;p++}d?Vi(e,l,p,n+1,s,d,o):lt;){let i=!0,c=!1;if(!h||l>r[h-1].to){let e=Wi[l-1];e!=a&&(i=!1,c=16==e)}let d=i||1!=a?null:[],u=i?n:n+1,p=l;e:for(;;)if(h&&p==r[h-1].to){if(c)break e;let f=r[--h];if(!i)for(let e=f.from,i=h;;){if(e==t)break e;if(!i||r[i-1].to!=e){if(Wi[e-1]==a)break e;break}e=r[--i].from}d?d.push(f):(f.to=0;e-=3)if($i[e+1]==-i){let t=$i[e+2],i=2&t?s:4&t?1&t?r:s:0;i&&(Wi[o]=Wi[$i[e]]=i),a=e;break}}else{if(189==$i.length)break;$i[a++]=o,$i[a++]=t,$i[a++]=l}else if(2==(n=Wi[o])||1==n){let e=n==s;l=e?0:1;for(let t=a-3;t>=0;t-=3){let i=$i[t+2];if(2&i)break;if(e)$i[t+2]|=2;else{if(4&i)break;$i[t+2]|=4}}}}}(e,s,r,n,a),function(e,t,i,n){for(let s=0,r=n;s<=i.length;s++){let o=s?i[s-1].to:e,a=sl;)t==r&&(t=i[--n].from,r=n?i[n-1].to:e),Wi[--t]=c;l=o}else r=o,l++}}}(s,r,n,a),Vi(e,s,r,t,i,n,o)}function Fi(e){return[new zi(0,e,0)]}let Hi="";function Xi(e,t,i,n,s){var r;let o=n.head-e.from,a=-1;if(0==o){if(!s||!e.length)return null;t[0].level!=i&&(o=t[0].side(!1,i),a=0)}else if(o==e.length){if(s)return null;let e=t[t.length-1];e.level!=i&&(o=e.side(!0,i),a=t.length-1)}a<0&&(a=zi.find(t,o,null!==(r=n.bidiLevel)&&void 0!==r?r:-1,n.assoc));let l=t[a];o==l.side(s,i)&&(l=t[a+=s?1:-1],o=l.side(!s,i));let h=s==(l.dir==i),c=p(e.text,o,h);if(Hi=e.text.slice(Math.min(o,c),Math.max(o,c)),c!=l.side(s,i))return R.cursor(c+e.from,h?-1:1,l.level);let d=a==(s?t.length-1:0)?null:t[a+(s?1:-1)];return d||l.level==i?d&&d.level0&&i.length&&(i.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);let n=-1;this.view.inputState.composing>=0&&((null===(t=this.domChanged)||void 0===t?void 0:t.newSel)?n=this.domChanged.newSel.head:function(e,t){let i=!1;return t&&e.iterChangedRanges(((e,n)=>{et.from&&(i=!0)})),i}(e.changes,this.hasComposition)||e.selectionSet||(n=e.state.selection.main.head));let s=n>-1?function(e,t,i){let n=Zi(e,i);if(!n)return null;let{node:s,from:r,to:o}=n,a=s.nodeValue;if(/[\n\r]/.test(a))return null;if(e.state.doc.sliceString(n.from,n.to)!=a)return null;let l=t.invertedDesc,h=new Ei(l.mapPos(r),l.mapPos(o),r,o),c=[];for(let t=s.parentNode;;t=t.parentNode){let i=gt.get(t);if(i instanceof It)c.push({node:t,deco:i.mark});else{if(i instanceof Ut||"DIV"==t.nodeName&&t.parentNode==e.contentDOM)return{range:h,text:s,marks:c,line:t};if(t==e.contentDOM)return null;c.push({node:t,deco:new Gt({inclusive:!0,attributes:Vt(t),tagName:t.tagName.toLowerCase()})})}}}(this.view,e.changes,n):null;if(this.domChanged=null,this.hasComposition){this.markedForComposition.clear();let{from:t,to:n}=this.hasComposition;i=new Ei(t,n,e.changes.mapPos(t,-1),e.changes.mapPos(n,1)).addToSet(i.slice())}this.hasComposition=s?{from:s.range.fromB,to:s.range.toB}:null,(Rt.ie||Rt.chrome)&&!s&&e&&e.state.doc.lines!=e.startState.doc.lines&&(this.forceSelection=!0);let r=function(e,t,i){let n=new Ji;return Se.compare(e,t,i,n),n.changes}(this.decorations,this.updateDeco(),e.changes);return i=Ei.extendWithRanges(i,r),!!(7&this.flags||0!=i.length)&&(this.updateInner(i,e.startState.doc.length,s),e.transactions.length&&(this.lastUpdate=Date.now()),!0)}updateInner(e,t,i){this.view.viewState.mustMeasureContent=!0,this.updateChildren(e,t,i);let{observer:n}=this.view;n.ignore((()=>{this.dom.style.height=this.view.viewState.contentHeight/this.view.scaleY+"px",this.dom.style.flexBasis=this.minWidth?this.minWidth+"px":"";let e=Rt.chrome||Rt.ios?{node:n.selectionRange.focusNode,written:!1}:void 0;this.sync(this.view,e),this.flags&=-8,e&&(e.written||n.selectionRange.focusNode!=e.node)&&(this.forceSelection=!0),this.dom.style.height=""})),this.markedForComposition.forEach((e=>e.flags&=-9));let s=[];if(this.view.viewport.from||this.view.viewport.to=0?n[e]:null;if(!t)break;let r,o,a,l,{fromA:h,toA:c,fromB:d,toB:u}=t;if(i&&i.range.fromBd){let e=ti.build(this.view.state.doc,d,i.range.fromB,this.decorations,this.dynamicDecorationMap),t=ti.build(this.view.state.doc,i.range.toB,u,this.decorations,this.dynamicDecorationMap);o=e.breakAtStart,a=e.openStart,l=t.openEnd;let n=this.compositionView(i);t.breakAtStart?n.breakAfter=1:t.content.length&&n.merge(n.length,n.length,t.content[0],!1,t.openStart,0)&&(n.breakAfter=t.content[0].breakAfter,t.content.shift()),e.content.length&&n.merge(0,0,e.content[e.content.length-1],!0,0,e.openEnd)&&e.content.pop(),r=e.content.concat(n).concat(t.content)}else({content:r,breakAtStart:o,openStart:a,openEnd:l}=ti.build(this.view.state.doc,d,u,this.decorations,this.dynamicDecorationMap));let{i:p,off:f}=s.findPos(c,1),{i:m,off:g}=s.findPos(h,-1);bt(this,m,g,p,f,r,o,a,l)}i&&this.fixCompositionDOM(i)}compositionView(e){let t=new Dt(e.text.nodeValue);t.flags|=8;for(let{deco:i}of e.marks)t=new It(i,[t],t.length);let i=new Ut;return i.append(t,0),i}fixCompositionDOM(e){let t=(e,t)=>{t.flags|=8|(t.children.some((e=>7&e.flags))?1:0),this.markedForComposition.add(t);let i=gt.get(e);i&&i!=t&&(i.dom=null),t.setDOM(e)},i=this.childPos(e.range.fromB,1),n=this.children[i.i];t(e.line,n);for(let s=e.marks.length-1;s>=-1;s--)i=n.childPos(i.off,1),n=n.children[i.i],t(s>=0?e.marks[s].node:e.text,n)}updateSelection(e=!1,t=!1){!e&&this.view.observer.selectionRange.focusNode||this.view.observer.readSelectionRange();let i=this.view.root.activeElement,n=i==this.dom,s=!n&&Ke(this.dom,this.view.observer.selectionRange)&&!(i&&this.dom.contains(i));if(!(n||t||s))return;let r=this.forceSelection;this.forceSelection=!1;let o=this.view.state.selection.main,a=this.moveToLine(this.domAtPos(o.anchor)),l=o.empty?a:this.moveToLine(this.domAtPos(o.head));if(Rt.gecko&&o.empty&&!this.hasComposition&&1==(h=a).node.nodeType&&h.node.firstChild&&(0==h.offset||"false"==h.node.childNodes[h.offset-1].contentEditable)&&(h.offset==h.node.childNodes.length||"false"==h.node.childNodes[h.offset].contentEditable)){let e=document.createTextNode("");this.view.observer.ignore((()=>a.node.insertBefore(e,a.node.childNodes[a.offset]||null))),a=l=new ft(e,0),r=!0}var h;let c=this.view.observer.selectionRange;!r&&c.focusNode&&et(a.node,a.offset,c.anchorNode,c.anchorOffset)&&et(l.node,l.offset,c.focusNode,c.focusOffset)||(this.view.observer.ignore((()=>{Rt.android&&Rt.chrome&&this.dom.contains(c.focusNode)&&function(e,t){for(let i=e;i&&i!=t;i=i.assignedSlot||i.parentNode)if(1==i.nodeType&&"false"==i.contentEditable)return!0;return!1}(c.focusNode,this.dom)&&(this.dom.blur(),this.dom.focus({preventScroll:!0}));let e=Ge(this.view.root);if(e)if(o.empty){if(Rt.gecko){let e=(t=a.node,n=a.offset,1!=t.nodeType?0:(n&&"false"==t.childNodes[n-1].contentEditable?1:0)|(no.head&&([a,l]=[l,a]),t.setEnd(l.node,l.offset),t.setStart(a.node,a.offset),e.removeAllRanges(),e.addRange(t)}var t,n;s&&this.view.root.activeElement==this.dom&&(this.dom.blur(),i&&i.focus())})),this.view.observer.setSelectionRange(a,l)),this.impreciseAnchor=a.precise?null:new ft(c.anchorNode,c.anchorOffset),this.impreciseHead=l.precise?null:new ft(c.focusNode,c.focusOffset)}enforceCursorAssoc(){if(this.hasComposition)return;let{view:e}=this,t=e.state.selection.main,i=Ge(e.root),{anchorNode:n,anchorOffset:s}=e.observer.selectionRange;if(!(i&&t.empty&&t.assoc&&i.modify))return;let r=Ut.find(this,t.head);if(!r)return;let o=r.posAtStart;if(t.head==o||t.head==o+r.length)return;let a=this.coordsAt(t.head,-1),l=this.coordsAt(t.head,1);if(!a||!l||a.bottom>l.top)return;let h=this.domAtPos(t.head+t.assoc);i.collapse(h.node,h.offset),i.modify("move",t.assoc<0?"forward":"backward","lineboundary"),e.observer.readSelectionRange();let c=e.observer.selectionRange;e.docView.posFromDOM(c.anchorNode,c.anchorOffset)!=t.from&&i.collapse(n,s)}moveToLine(e){let t,i=this.dom;if(e.node!=i)return e;for(let n=e.offset;!t&&n=0;n--){let e=gt.get(i.childNodes[n]);e instanceof Ut&&(t=e.domAtPos(e.length))}return t?new ft(t.node,t.offset,!0):e}nearest(e){for(let t=e;t;){let e=gt.get(t);if(e&&e.rootView==this)return e;t=t.parentNode}return null}posFromDOM(e,t){let i=this.nearest(e);if(!i)throw new RangeError("Trying to find position for a DOM position outside of the document");return i.localPosFromDOM(e,t)+i.posAtStart}domAtPos(e){let{i:t,off:i}=this.childCursor().findPos(e,-1);for(;t=0;r--){let o=this.children[r],a=s-o.breakAfter,l=a-o.length;if(ae||o.covers(1))&&(!i||o instanceof Ut&&!(i instanceof Ut&&t>=0))&&(i=o,n=l),s=l}return i?i.coordsAt(e-n,t):null}coordsForChar(e){let{i:t,off:i}=this.childPos(e,1),n=this.children[t];if(!(n instanceof Ut))return null;for(;n.children.length;){let{i:e,off:t}=n.childPos(i,1);for(;;e++){if(e==n.children.length)return null;if((n=n.children[e]).length)break}i=t}if(!(n instanceof Dt))return null;let s=p(n.text,i);if(s==i)return null;let r=ct(n.dom,i,s).getClientRects();for(let e=0;eMath.max(this.view.scrollDOM.clientWidth,this.minWidth)+1,o=-1,a=this.view.textDirection==Ri.LTR;for(let e=0,l=0;ln)break;if(e>=i){let i=h.dom.getBoundingClientRect();if(t.push(i.height),r){let t=h.dom.lastChild,n=t?Je(t):[];if(n.length){let t=n[n.length-1],r=a?t.right-i.left:i.right-t.left;r>o&&(o=r,this.minWidth=s,this.minWidthFrom=e,this.minWidthTo=c)}}}e=c+h.breakAfter}return t}textDirectionAt(e){let{i:t}=this.childPos(e,1);return"rtl"==getComputedStyle(this.children[t].dom).direction?Ri.RTL:Ri.LTR}measureTextSize(){for(let e of this.children)if(e instanceof Ut){let t=e.measureTextSize();if(t)return t}let e,t,i,n=document.createElement("div");return n.className="cm-line",n.style.width="99999px",n.style.position="absolute",n.textContent="abc def ghi jkl mno pqr stu",this.view.observer.ignore((()=>{this.dom.appendChild(n);let s=Je(n.firstChild)[0];e=n.getBoundingClientRect().height,t=s?s.width/27:7,i=s?s.height:e,n.remove()})),{lineHeight:e,charWidth:t,textHeight:i}}childCursor(e=this.length){let t=this.children.length;return t&&(e-=this.children[--t].length),new Ot(this.children,e,t)}computeBlockGapDeco(){let e=[],t=this.view.viewState;for(let i=0,n=0;;n++){let s=n==t.viewports.length?null:t.viewports[n],r=s?s.from-1:this.length;if(r>i){let n=(t.lineBlockAt(r).bottom-t.lineBlockAt(i).top)/this.view.scaleY;e.push(Yt.replace({widget:new Gi(n),block:!0,inclusive:!0,isBlockGap:!0}).range(i,r))}if(!s)break;i=s.to+1}return Yt.set(e)}updateDeco(){let e=this.view.state.facet(xi).map(((e,t)=>(this.dynamicDecorationMap[t]="function"==typeof e)?e(this.view):e));for(let t=e.length;ti.anchor?-1:1);if(!n)return;!i.empty&&(t=this.coordsAt(i.anchor,i.anchor>i.head?-1:1))&&(n={left:Math.min(n.left,t.left),top:Math.min(n.top,t.top),right:Math.max(n.right,t.right),bottom:Math.max(n.bottom,t.bottom)});let s=Pi(this.view),r={left:n.left-s.left,top:n.top-s.top,right:n.right+s.right,bottom:n.bottom+s.bottom};!function(e,t,i,n,s,r,o,a){let l=e.ownerDocument,h=l.defaultView||window;for(let c=e,d=!1;c&&!d;)if(1==c.nodeType){let e,u=c==l.body,p=1,f=1;if(u)e=rt(h);else{if(/^(fixed|sticky)$/.test(getComputedStyle(c).position)&&(d=!0),c.scrollHeight<=c.clientHeight&&c.scrollWidth<=c.clientWidth){c=c.assignedSlot||c.parentNode;continue}let t=c.getBoundingClientRect();p=t.width/c.offsetWidth,f=t.height/c.offsetHeight,e={left:t.left,right:t.left+c.clientWidth*p,top:t.top,bottom:t.top+c.clientHeight*f}}let m=0,g=0;if("nearest"==s)t.top0&&t.bottom>e.bottom+g&&(g=t.bottom-e.bottom+g+o)):t.bottom>e.bottom&&(g=t.bottom-e.bottom+o,i<0&&t.top-g0&&t.right>e.right+m&&(m=t.right-e.right+m+r)):t.right>e.right&&(m=t.right-e.right+r,i<0&&t.left0))break;i=i.childNodes[n-1],n=nt(i)}if(i>=0)for(let n=e,s=t;;){if(3==n.nodeType)return{node:n,offset:s};if(!(1==n.nodeType&&s=0))break;n=n.childNodes[s],s=0}return null}let Ji=class{constructor(){this.changes=[]}compareRange(e,t){ei(e,t,this.changes)}comparePoint(e,t){ei(e,t,this.changes)}};function en(e,t){return t.left>e?t.left-e:Math.max(0,e-t.right)}function tn(e,t){return t.top>e?t.top-e:Math.max(0,e-t.bottom)}function nn(e,t){return e.topt.top+1}function sn(e,t){return te.bottom?{top:e.top,left:e.left,right:e.right,bottom:t}:e}function on(e,t,i){let n,s,r,o,a,l,h,c,d=!1;for(let u=e.firstChild;u;u=u.nextSibling){let e=Je(u);for(let p=0;pg||o==g&&r>m){n=u,s=f,r=m,o=g;let a=g?i0?p0)}0==m?i>f.bottom&&(!h||h.bottomf.top)&&(l=u,c=f):h&&nn(h,f)?h=rn(h,f.bottom):c&&nn(c,f)&&(c=sn(c,f.top))}}if(h&&h.bottom>=i?(n=a,s=h):c&&c.top<=i&&(n=l,s=c),!n)return{node:e,offset:0};let u=Math.max(s.left,Math.min(s.right,t));return 3==n.nodeType?an(n,u,i):d&&"false"!=n.contentEditable?on(n,u,i):{node:e,offset:Array.prototype.indexOf.call(e.childNodes,n)+(t>=(s.left+s.right)/2?1:0)}}function an(e,t,i){let n=e.nodeValue.length,s=-1,r=1e9,o=0;for(let a=0;ai?h.top-i:i-h.bottom)-1;if(h.left-1<=t&&h.right+1>=t&&c=(h.left+h.right)/2,n=i;if((Rt.chrome||Rt.gecko)&&ct(e,a).getBoundingClientRect().left==h.right&&(n=!i),c<=0)return{node:e,offset:a+(n?1:0)};s=a+(n?1:0),r=c}}}return{node:e,offset:s>-1?s:o>0?e.nodeValue.length:0}}function ln(e,t,i,n=-1){var s,r;let o,a=e.contentDOM.getBoundingClientRect(),l=a.top+e.viewState.paddingTop,{docHeight:h}=e.viewState,{x:c,y:d}=t,u=d-l;if(u<0)return 0;if(u>h)return e.state.doc.length;for(let t=e.viewState.heightOracle.textHeight/2,s=!1;o=e.elementAtHeight(u),o.type!=Xt.Text;)for(;u=n>0?o.bottom+t:o.top-t,!(u>=0&&u<=h);){if(s)return i?null:0;s=!0,n=-n}d=l+u;let p=o.from;if(pe.viewport.to)return e.viewport.to==e.state.doc.length?e.state.doc.length:i?null:hn(e,a,o,c,d);let f=e.dom.ownerDocument,m=e.root.elementFromPoint?e.root:f,g=m.elementFromPoint(c,d);g&&!e.contentDOM.contains(g)&&(g=null),g||(c=Math.max(a.left+1,Math.min(a.right-1,c)),g=m.elementFromPoint(c,d),g&&!e.contentDOM.contains(g)&&(g=null));let v,O=-1;if(g&&0!=(null===(s=e.docView.nearest(g))||void 0===s?void 0:s.isEditable))if(f.caretPositionFromPoint){let e=f.caretPositionFromPoint(c,d);e&&({offsetNode:v,offset:O}=e)}else if(f.caretRangeFromPoint){let t=f.caretRangeFromPoint(c,d);t&&(({startContainer:v,startOffset:O}=t),(!e.contentDOM.contains(v)||Rt.safari&&function(e,t,i){let n;if(3!=e.nodeType||t!=(n=e.nodeValue.length))return!1;for(let t=e.nextSibling;t;t=t.nextSibling)if(1!=t.nodeType||"BR"!=t.nodeName)return!1;return ct(e,n-1,n).getBoundingClientRect().left>i}(v,O,c)||Rt.chrome&&function(e,t,i){if(0!=t)return!1;for(let t=e;;){let e=t.parentNode;if(!e||1!=e.nodeType||e.firstChild!=t)return!1;if(e.classList.contains("cm-line"))break;t=e}return i-(1==e.nodeType?e.getBoundingClientRect():ct(e,0,Math.max(e.nodeValue.length,1)).getBoundingClientRect()).left>5}(v,O,c))&&(v=void 0))}if(!v||!e.docView.dom.contains(v)){let t=Ut.find(e.docView,p);if(!t)return u>o.top+o.height/2?o.to:o.from;({node:v,offset:O}=on(t.dom,c,d))}let b=e.docView.nearest(v);if(!b)return null;if(b.isWidget&&1==(null===(r=b.dom)||void 0===r?void 0:r.nodeType)){let e=b.dom.getBoundingClientRect();return t.y1.5*e.defaultLineHeight){let t=e.viewState.heightOracle.textHeight;r+=Math.floor((s-i.top-.5*(e.defaultLineHeight-t))/t)*e.viewState.heightOracle.lineLength}let o=e.state.sliceDoc(i.from,i.to);return i.from+Ne(o,r,e.state.tabSize)}function cn(e,t){let i=e.lineBlockAt(t);if(Array.isArray(i.type))for(let e of i.type)if(e.to>t||e.to==t&&(e.to==i.to||e.type==Xt.Text))return e;return i}function dn(e,t,i,n){let s=e.state.doc.lineAt(t.head),r=e.bidiSpans(s),o=e.textDirectionAt(s.from);for(let a=t,l=null;;){let t=Xi(s,r,o,a,i),h=Hi;if(!t){if(s.number==(i?e.state.doc.lines:1))return a;h="\n",s=e.state.doc.line(s.number+(i?1:-1)),r=e.bidiSpans(s),t=R.cursor(i?s.from:s.to)}if(l){if(!l(h))return a}else{if(!n)return t;l=n(h)}a=t}}function un(e,t,i){for(;;){let n=0;for(let s of e)s.between(t-1,t+1,((e,s,r)=>{if(t>e&&tt(e))),i.from,t.head>i.from?-1:1);return n==i.from?i:R.cursor(n,nnull)),Rt.gecko&&function(e){zn.has(e)||(zn.add(e),e.addEventListener("copy",(()=>{})),e.addEventListener("cut",(()=>{})))}(e.contentDOM.ownerDocument)}handleEvent(e){(function(e,t){if(!t.bubbles)return!0;if(t.defaultPrevented)return!1;for(let i,n=t.target;n!=e.contentDOM;n=n.parentNode)if(!n||11==n.nodeType||(i=gt.get(n))&&i.ignoreEvent(t))return!1;return!0})(this.view,e)&&!this.ignoreDuringComposition(e)&&("keydown"==e.type&&this.keydown(e)||this.runHandlers(e.type,e))}runHandlers(e,t){let i=this.handlers[e];if(i){for(let e of i.observers)e(this.view,t);for(let e of i.handlers){if(t.defaultPrevented)break;if(e(this.view,t)){t.preventDefault();break}}}}ensureHandlers(e){let t=gn(e),i=this.handlers,n=this.view.contentDOM;for(let e in t)if("scroll"!=e){let s=!t[e].handlers.length,r=i[e];r&&s!=!r.handlers.length&&(n.removeEventListener(e,this.handleEvent),r=null),r||n.addEventListener(e,this.handleEvent,{passive:s})}for(let e in i)"scroll"==e||t[e]||n.removeEventListener(e,this.handleEvent);this.handlers=t}keydown(e){if(this.lastKeyCode=e.keyCode,this.lastKeyTime=Date.now(),9==e.keyCode&&Date.now()t.keyCode==e.keyCode)))&&!e.ctrlKey||On.indexOf(e.key)>-1&&e.ctrlKey&&!e.shiftKey)?(229!=e.keyCode&&this.view.observer.forceFlush(),!1):(this.pendingIOSKey=t||e,setTimeout((()=>this.flushIOSKey()),250),!0)}flushIOSKey(){let e=this.pendingIOSKey;return!!e&&(this.pendingIOSKey=void 0,dt(this.view.contentDOM,e.key,e.keyCode))}ignoreDuringComposition(e){return!!/^key/.test(e.type)&&(this.composing>0||!!(Rt.safari&&!Rt.ios&&this.compositionPendingKey&&Date.now()-this.compositionEndedAt<100)&&(this.compositionPendingKey=!1,!0))}startMouseSelection(e){this.mouseSelection&&this.mouseSelection.destroy(),this.mouseSelection=e}update(e){this.mouseSelection&&this.mouseSelection.update(e),e.transactions.length&&(this.lastKeyCode=this.lastSelectionTime=0)}destroy(){this.mouseSelection&&this.mouseSelection.destroy()}}function mn(e,t){return(i,n)=>{try{return t.call(e,n,i)}catch(e){mi(i.state,e)}}}function gn(e){let t=Object.create(null);function i(e){return t[e]||(t[e]={observers:[],handlers:[]})}for(let t of e){let e=t.spec;if(e&&e.domEventHandlers)for(let n in e.domEventHandlers){let s=e.domEventHandlers[n];s&&i(n).handlers.push(mn(t.value,s))}if(e&&e.domEventObservers)for(let n in e.domEventObservers){let s=e.domEventObservers[n];s&&i(n).observers.push(mn(t.value,s))}}for(let e in wn)i(e).handlers.push(wn[e]);for(let e in xn)i(e).observers.push(xn[e]);return t}const vn=[{key:"Backspace",keyCode:8,inputType:"deleteContentBackward"},{key:"Enter",keyCode:13,inputType:"insertParagraph"},{key:"Enter",keyCode:13,inputType:"insertLineBreak"},{key:"Delete",keyCode:46,inputType:"deleteContentForward"}],On="dthko",bn=[16,17,18,20,91,92,224,225];function _n(e){return.7*Math.max(0,e)+8}class yn{constructor(e,t,i,n){this.view=e,this.startEvent=t,this.style=i,this.mustSelect=n,this.scrollSpeed={x:0,y:0},this.scrolling=-1,this.lastEvent=t,this.scrollParent=function(e){let t=e.ownerDocument;for(let i=e.parentNode;i&&i!=t.body;)if(1==i.nodeType){if(i.scrollHeight>i.clientHeight||i.scrollWidth>i.clientWidth)return i;i=i.assignedSlot||i.parentNode}else{if(11!=i.nodeType)break;i=i.host}return null}(e.contentDOM),this.atoms=e.state.facet(Si).map((t=>t(e)));let s=e.contentDOM.ownerDocument;s.addEventListener("mousemove",this.move=this.move.bind(this)),s.addEventListener("mouseup",this.up=this.up.bind(this)),this.extend=t.shiftKey,this.multiple=e.state.facet(Oe.allowMultipleSelections)&&function(e,t){let i=e.state.facet(si);return i.length?i[0](t):Rt.mac?t.metaKey:t.ctrlKey}(e,t),this.dragging=!(!function(e,t){let{main:i}=e.state.selection;if(i.empty)return!1;let n=Ge(e.root);if(!n||0==n.rangeCount)return!0;let s=n.getRangeAt(0).getClientRects();for(let e=0;e=t.clientX&&i.top<=t.clientY&&i.bottom>=t.clientY)return!0}return!1}(e,t)||1!=qn(t))&&null}start(e){!1===this.dragging&&this.select(e)}move(e){var t,i,n;if(0==e.buttons)return this.destroy();if(this.dragging||null==this.dragging&&(i=this.startEvent,n=e,Math.max(Math.abs(i.clientX-n.clientX),Math.abs(i.clientY-n.clientY))<10))return;this.select(this.lastEvent=e);let s=0,r=0,o=(null===(t=this.scrollParent)||void 0===t?void 0:t.getBoundingClientRect())||{left:0,top:0,right:this.view.win.innerWidth,bottom:this.view.win.innerHeight},a=Pi(this.view);e.clientX-a.left<=o.left+6?s=-_n(o.left-e.clientX):e.clientX+a.right>=o.right-6&&(s=_n(e.clientX-o.right)),e.clientY-a.top<=o.top+6?r=-_n(o.top-e.clientY):e.clientY+a.bottom>=o.bottom-6&&(r=_n(e.clientY-o.bottom)),this.setScrollSpeed(s,r)}up(e){null==this.dragging&&this.select(this.lastEvent),this.dragging||e.preventDefault(),this.destroy()}destroy(){this.setScrollSpeed(0,0);let e=this.view.contentDOM.ownerDocument;e.removeEventListener("mousemove",this.move),e.removeEventListener("mouseup",this.up),this.view.inputState.mouseSelection=null}setScrollSpeed(e,t){this.scrollSpeed={x:e,y:t},e||t?this.scrolling<0&&(this.scrolling=setInterval((()=>this.scroll()),50)):this.scrolling>-1&&(clearInterval(this.scrolling),this.scrolling=-1)}scroll(){this.scrollParent?(this.scrollParent.scrollLeft+=this.scrollSpeed.x,this.scrollParent.scrollTop+=this.scrollSpeed.y):this.view.win.scrollBy(this.scrollSpeed.x,this.scrollSpeed.y),!1===this.dragging&&this.select(this.lastEvent)}skipAtoms(e){let t=null;for(let i=0;ithis.select(this.lastEvent)),20)}}const wn=Object.create(null),xn=Object.create(null),Sn=Rt.ie&&Rt.ie_version<15||Rt.ios&&Rt.webkit_version<604;function kn(e,t){let i,{state:n}=e,s=1,r=n.toText(t),o=r.lines==n.selection.ranges.length;if(null!=Nn&&n.selection.ranges.every((e=>e.empty))&&Nn==r.toString()){let e=-1;i=n.changeByRange((i=>{let a=n.doc.lineAt(i.from);if(a.from==e)return{range:i};e=a.from;let l=n.toText((o?r.line(s++).text:t)+n.lineBreak);return{changes:{from:a.from,insert:l},range:R.cursor(i.from+l.length)}}))}else i=o?n.changeByRange((e=>{let t=r.line(s++);return{changes:{from:e.from,to:e.to,insert:t.text},range:R.cursor(e.from+t.length)}})):n.replaceSelection(r);e.dispatch(i,{userEvent:"input.paste",scrollIntoView:!0})}function Tn(e,t,i,n){if(1==n)return R.cursor(t,i);if(2==n)return function(e,t,i=1){let n=e.charCategorizer(t),s=e.doc.lineAt(t),r=t-s.from;if(0==s.length)return R.cursor(t);0==r?i=1:r==s.length&&(i=-1);let o=r,a=r;i<0?o=p(s.text,r,!1):a=p(s.text,r);let l=n(s.text.slice(o,a));for(;o>0;){let e=p(s.text,o,!1);if(n(s.text.slice(e,o))!=l)break;o=e}for(;a{e.inputState.lastScrollTop=e.scrollDOM.scrollTop,e.inputState.lastScrollLeft=e.scrollDOM.scrollLeft},wn.keydown=(e,t)=>(e.inputState.setSelectionOrigin("select"),27==t.keyCode&&(e.inputState.lastEscPress=Date.now()),!1),xn.touchstart=(e,t)=>{e.inputState.lastTouchTime=Date.now(),e.inputState.setSelectionOrigin("select.pointer")},xn.touchmove=e=>{e.inputState.setSelectionOrigin("select.pointer")},wn.mousedown=(e,t)=>{if(e.observer.flush(),e.inputState.lastTouchTime>Date.now()-2e3)return!1;let i=null;for(let n of e.state.facet(oi))if(i=n(e,t),i)break;if(i||0!=t.button||(i=function(e,t){let i=En(e,t),n=qn(t),s=e.state.selection;return{update(e){e.docChanged&&(i.pos=e.changes.mapPos(i.pos),s=s.map(e.changes))},get(t,r,o){let a,l=En(e,t),h=Tn(e,l.pos,l.bias,n);if(i.pos!=l.pos&&!r){let t=Tn(e,i.pos,i.bias,n),s=Math.min(t.from,h.from),r=Math.max(t.to,h.to);h=s1&&(a=function(e,t){for(let i=0;i=t)return R.create(e.ranges.slice(0,i).concat(e.ranges.slice(i+1)),e.mainIndex==i?0:e.mainIndex-(e.mainIndex>i?1:0))}return null}(s,l.pos))?a:o?s.addRange(h):R.create([h])}}}(e,t)),i){let n=!e.hasFocus;e.inputState.startMouseSelection(new yn(e,t,i,n)),n&&e.observer.ignore((()=>ht(e.contentDOM)));let s=e.inputState.mouseSelection;if(s)return s.start(t),!1===s.dragging}return!1};let Cn=(e,t)=>e>=t.top&&e<=t.bottom,Pn=(e,t,i)=>Cn(t,i)&&e>=i.left&&e<=i.right;function Mn(e,t,i,n){let s=Ut.find(e.docView,t);if(!s)return 1;let r=t-s.posAtStart;if(0==r)return 1;if(r==s.length)return-1;let o=s.coordsAt(r,-1);if(o&&Pn(i,n,o))return-1;let a=s.coordsAt(r,1);return a&&Pn(i,n,a)?1:o&&Cn(n,o)?-1:1}function En(e,t){let i=e.posAtCoords({x:t.clientX,y:t.clientY},!1);return{pos:i,bias:Mn(e,i,t.clientX,t.clientY)}}const An=Rt.ie&&Rt.ie_version<=11;let Rn=null,Dn=0,In=0;function qn(e){if(!An)return e.detail;let t=Rn,i=In;return Rn=e,In=Date.now(),Dn=!t||i>Date.now()-400&&Math.abs(t.clientX-e.clientX)<2&&Math.abs(t.clientY-e.clientY)<2?(Dn+1)%3:1}function Ln(e,t,i,n){if(!i)return;let s=e.posAtCoords({x:t.clientX,y:t.clientY},!1),{mouseSelection:r}=e.inputState,o=n&&r&&r.dragging&&function(e,t){let i=e.state.facet(ri);return i.length?i[0](t):Rt.mac?!t.altKey:!t.ctrlKey}(e,t)?{from:r.dragging.from,to:r.dragging.to}:null,a={from:s,insert:i},l=e.state.changes(o?[o,a]:a);e.focus(),e.dispatch({changes:l,selection:{anchor:l.mapPos(s,-1),head:l.mapPos(s,1)},userEvent:o?"move.drop":"input.drop"})}wn.dragstart=(e,t)=>{let{selection:{main:i}}=e.state,{mouseSelection:n}=e.inputState;return n&&(n.dragging=i),t.dataTransfer&&(t.dataTransfer.setData("Text",e.state.sliceDoc(i.from,i.to)),t.dataTransfer.effectAllowed="copyMove"),!1},wn.drop=(e,t)=>{if(!t.dataTransfer)return!1;if(e.state.readOnly)return!0;let i=t.dataTransfer.files;if(i&&i.length){let n=Array(i.length),s=0,r=()=>{++s==i.length&&Ln(e,t,n.filter((e=>null!=e)).join(e.state.lineBreak),!1)};for(let e=0;e{/[\x00-\x08\x0e-\x1f]{2}/.test(t.result)||(n[e]=t.result),r()},t.readAsText(i[e])}return!0}{let i=t.dataTransfer.getData("Text");if(i)return Ln(e,t,i,!0),!0}return!1},wn.paste=(e,t)=>{if(e.state.readOnly)return!0;e.observer.flush();let i=Sn?null:t.clipboardData;return i?(kn(e,i.getData("text/plain")||i.getData("text/uri-text")),!0):(function(e){let t=e.dom.parentNode;if(!t)return;let i=t.appendChild(document.createElement("textarea"));i.style.cssText="position: fixed; left: -10000px; top: 10px",i.focus(),setTimeout((()=>{e.focus(),i.remove(),kn(e,i.value)}),50)}(e),!1)};let Nn=null;wn.copy=wn.cut=(e,t)=>{let{text:i,ranges:n,linewise:s}=function(e){let t=[],i=[],n=!1;for(let n of e.selection.ranges)n.empty||(t.push(e.sliceDoc(n.from,n.to)),i.push(n));if(!t.length){let s=-1;for(let{from:n}of e.selection.ranges){let r=e.doc.lineAt(n);r.number>s&&(t.push(r.text),i.push({from:r.from,to:Math.min(e.doc.length,r.to+1)})),s=r.number}n=!0}return{text:t.join(e.lineBreak),ranges:i,linewise:n}}(e.state);if(!i&&!s)return!1;Nn=s?i:null,"cut"!=t.type||e.state.readOnly||e.dispatch({changes:n,scrollIntoView:!0,userEvent:"delete.cut"});let r=Sn?null:t.clipboardData;return r?(r.clearData(),r.setData("text/plain",i),!0):(function(e,t){let i=e.dom.parentNode;if(!i)return;let n=i.appendChild(document.createElement("textarea"));n.style.cssText="position: fixed; left: -10000px; top: 10px",n.value=t,n.focus(),n.selectionEnd=t.length,n.selectionStart=0,setTimeout((()=>{n.remove(),e.focus()}),50)}(e,i),!1)};const Bn=se.define();function $n(e,t){let i=[];for(let n of e.facet(ci)){let s=n(e,t);s&&i.push(s)}return i?e.update({effects:i,annotations:Bn.of(!0)}):null}function Qn(e){setTimeout((()=>{let t=e.hasFocus;if(t!=e.inputState.notifiedFocused){let i=$n(e.state,t);i?e.dispatch(i):e.update([])}}),10)}xn.focus=e=>{e.inputState.lastFocusTime=Date.now(),e.scrollDOM.scrollTop||!e.inputState.lastScrollTop&&!e.inputState.lastScrollLeft||(e.scrollDOM.scrollTop=e.inputState.lastScrollTop,e.scrollDOM.scrollLeft=e.inputState.lastScrollLeft),Qn(e)},xn.blur=e=>{e.observer.clearSelectionRange(),Qn(e)},xn.compositionstart=xn.compositionupdate=e=>{null==e.inputState.compositionFirstChange&&(e.inputState.compositionFirstChange=!0),e.inputState.composing<0&&(e.inputState.composing=0)},xn.compositionend=e=>{e.inputState.composing=-1,e.inputState.compositionEndedAt=Date.now(),e.inputState.compositionPendingKey=!0,e.inputState.compositionPendingChange=e.observer.pendingRecords().length>0,e.inputState.compositionFirstChange=null,Rt.chrome&&Rt.android?e.observer.flushSoon():e.inputState.compositionPendingChange?Promise.resolve().then((()=>e.observer.flush())):setTimeout((()=>{e.inputState.composing<0&&e.docView.hasComposition&&e.update([])}),50)},xn.contextmenu=e=>{e.inputState.lastContextMenu=Date.now()},wn.beforeinput=(e,t)=>{var i;let n;if(Rt.chrome&&Rt.android&&(n=vn.find((e=>e.inputType==t.inputType)))&&(e.observer.delayAndroidKey(n.key,n.keyCode),"Backspace"==n.key||"Delete"==n.key)){let t=(null===(i=window.visualViewport)||void 0===i?void 0:i.height)||0;setTimeout((()=>{var i;((null===(i=window.visualViewport)||void 0===i?void 0:i.height)||0)>t+10&&e.hasFocus&&(e.contentDOM.blur(),e.focus())}),100)}return!1};const zn=new Set,jn=["pre-wrap","normal","pre-line","break-spaces"];class Wn{constructor(t){this.lineWrapping=t,this.doc=e.empty,this.heightSamples={},this.lineHeight=14,this.charWidth=7,this.textHeight=14,this.lineLength=30,this.heightChanged=!1}heightForGap(e,t){let i=this.doc.lineAt(t).number-this.doc.lineAt(e).number+1;return this.lineWrapping&&(i+=Math.max(0,Math.ceil((t-e-i*this.lineLength*.5)/this.lineLength))),this.lineHeight*i}heightForLine(e){return this.lineWrapping?(1+Math.max(0,Math.ceil((e-this.lineLength)/(this.lineLength-5))))*this.lineHeight:this.lineHeight}setDoc(e){return this.doc=e,this}mustRefreshForWrapping(e){return jn.indexOf(e)>-1!=this.lineWrapping}mustRefreshForHeights(e){let t=!1;for(let i=0;i-1,a=Math.round(t)!=Math.round(this.lineHeight)||this.lineWrapping!=o;if(this.lineWrapping=o,this.lineHeight=t,this.charWidth=i,this.textHeight=n,this.lineLength=s,a){this.heightSamples={};for(let e=0;e0}set outdated(e){this.flags=(e?2:0)|-3&this.flags}setHeight(e,t){this.height!=t&&(Math.abs(this.height-t)>Hn&&(e.heightChanged=!0),this.height=t)}replace(e,t,i){return Xn.of(i)}decomposeLeft(e,t){t.push(this)}decomposeRight(e,t){t.push(this)}applyChanges(e,t,i,n){let s=this,r=i.doc;for(let o=n.length-1;o>=0;o--){let{fromA:a,toA:l,fromB:h,toB:c}=n[o],d=s.lineAt(a,Fn.ByPosNoHeight,i.setDoc(t),0,0),u=d.to>=l?d:s.lineAt(l,Fn.ByPosNoHeight,i,0,0);for(c+=u.to-l,l=u.to;o>0&&d.from<=n[o-1].toA;)a=n[o-1].fromA,h=n[o-1].fromB,o--,a2*s){let s=e[t-1];s.break?e.splice(--t,1,s.left,null,s.right):e.splice(--t,1,s.left,s.right),i+=1+s.break,n-=s.size}else{if(!(s>2*n))break;{let t=e[i];t.break?e.splice(i,1,t.left,null,t.right):e.splice(i,1,t.left,t.right),i+=2+t.break,s-=t.size}}else if(n=s&&r(this.blockAt(0,i,n,s))}updateHeight(e,t=0,i=!1,n){return n&&n.from<=t&&n.more&&this.setHeight(e,n.heights[n.index++]),this.outdated=!1,this}toString(){return`block(${this.length})`}}class Gn extends Yn{constructor(e,t){super(e,t,null),this.collapsed=0,this.widgetHeight=0,this.breaks=0}blockAt(e,t,i,n){return new Un(n,this.length,i,this.height,this.breaks)}replace(e,t,i){let n=i[0];return 1==i.length&&(n instanceof Gn||n instanceof Zn&&4&n.flags)&&Math.abs(this.length-n.length)<10?(n instanceof Zn?n=new Gn(n.length,this.height):n.height=this.height,this.outdated||(n.outdated=!1),n):Xn.of(i)}updateHeight(e,t=0,i=!1,n){return n&&n.from<=t&&n.more?this.setHeight(e,n.heights[n.index++]):(i||this.outdated)&&this.setHeight(e,Math.max(this.widgetHeight,e.heightForLine(this.length-this.collapsed))+this.breaks*e.lineHeight),this.outdated=!1,this}toString(){return`line(${this.length}${this.collapsed?-this.collapsed:""}${this.widgetHeight?":"+this.widgetHeight:""})`}}class Zn extends Xn{constructor(e){super(e,0)}heightMetrics(e,t){let i,n=e.doc.lineAt(t).number,s=e.doc.lineAt(t+this.length).number,r=s-n+1,o=0;if(e.lineWrapping){let t=Math.min(this.height,e.lineHeight*r);i=t/r,this.length>r+1&&(o=(this.height-t)/(this.length-r-1))}else i=this.height/r;return{firstLine:n,lastLine:s,perLine:i,perChar:o}}blockAt(e,t,i,n){let{firstLine:s,lastLine:r,perLine:o,perChar:a}=this.heightMetrics(t,n);if(t.lineWrapping){let s=n+Math.round(Math.max(0,Math.min(1,(e-i)/this.height))*this.length),r=t.doc.lineAt(s),l=o+r.length*a,h=Math.max(i,e-l/2);return new Un(r.from,r.length,h,l,0)}{let n=Math.max(0,Math.min(r-s,Math.floor((e-i)/o))),{from:a,length:l}=t.doc.line(s+n);return new Un(a,l,i+o*n,o,0)}}lineAt(e,t,i,n,s){if(t==Fn.ByHeight)return this.blockAt(e,i,n,s);if(t==Fn.ByPosNoHeight){let{from:t,to:n}=i.doc.lineAt(e);return new Un(t,n-t,0,0,0)}let{firstLine:r,perLine:o,perChar:a}=this.heightMetrics(i,s),l=i.doc.lineAt(e),h=o+l.length*a,c=l.number-r,d=n+o*c+a*(l.from-s-c);return new Un(l.from,l.length,Math.max(n,Math.min(d,n+this.height-h)),h,0)}forEachLine(e,t,i,n,s,r){e=Math.max(e,s),t=Math.min(t,s+this.length);let{firstLine:o,perLine:a,perChar:l}=this.heightMetrics(i,s);for(let h=e,c=n;h<=t;){let t=i.doc.lineAt(h);if(h==e){let i=t.number-o;c+=a*i+l*(e-s-i)}let n=a+l*t.length;r(new Un(t.from,t.length,c,n,0)),c+=n,h=t.to+1}}replace(e,t,i){let n=this.length-t;if(n>0){let e=i[i.length-1];e instanceof Zn?i[i.length-1]=new Zn(e.length+n):i.push(null,new Zn(n-1))}if(e>0){let t=i[0];t instanceof Zn?i[0]=new Zn(e+t.length):i.unshift(new Zn(e-1),null)}return Xn.of(i)}decomposeLeft(e,t){t.push(new Zn(e-1),null)}decomposeRight(e,t){t.push(null,new Zn(this.length-e-1))}updateHeight(e,t=0,i=!1,n){let s=t+this.length;if(n&&n.from<=t+this.length&&n.more){let i=[],r=Math.max(t,n.from),o=-1;for(n.from>t&&i.push(new Zn(n.from-t-1).updateHeight(e,t));r<=s&&n.more;){let t=e.doc.lineAt(r).length;i.length&&i.push(null);let s=n.heights[n.index++];-1==o?o=s:Math.abs(s-o)>=Hn&&(o=-2);let a=new Gn(t,s);a.outdated=!1,i.push(a),r+=t+1}r<=s&&i.push(null,new Zn(s-r).updateHeight(e,r));let a=Xn.of(i);return(o<0||Math.abs(a.height-this.height)>=Hn||Math.abs(o-this.heightMetrics(e,t).perLine)>=Hn)&&(e.heightChanged=!0),a}return(i||this.outdated)&&(this.setHeight(e,e.heightForGap(t,t+this.length)),this.outdated=!1),this}toString(){return`gap(${this.length})`}}class Kn extends Xn{constructor(e,t,i){super(e.length+t+i.length,e.height+i.height,t|(e.outdated||i.outdated?2:0)),this.left=e,this.right=i,this.size=e.size+i.size}get break(){return 1&this.flags}blockAt(e,t,i,n){let s=i+this.left.height;return eo))return l;let h=t==Fn.ByPosNoHeight?Fn.ByPosNoHeight:Fn.ByPos;return a?l.join(this.right.lineAt(o,h,i,r,o)):this.left.lineAt(o,h,i,n,s).join(l)}forEachLine(e,t,i,n,s,r){let o=n+this.left.height,a=s+this.left.length+this.break;if(this.break)e=a&&this.right.forEachLine(e,t,i,o,a,r);else{let l=this.lineAt(a,Fn.ByPos,i,n,s);e=e&&l.from<=t&&r(l),t>l.to&&this.right.forEachLine(l.to+1,t,i,o,a,r)}}replace(e,t,i){let n=this.left.length+this.break;if(tthis.left.length)return this.balanced(this.left,this.right.replace(e-n,t-n,i));let s=[];e>0&&this.decomposeLeft(e,s);let r=s.length;for(let e of i)s.push(e);if(e>0&&Jn(s,r-1),t=i&&t.push(null)),e>i&&this.right.decomposeLeft(e-i,t)}decomposeRight(e,t){let i=this.left.length,n=i+this.break;if(e>=n)return this.right.decomposeRight(e-n,t);e2*t.size||t.size>2*e.size?Xn.of(this.break?[e,null,t]:[e,t]):(this.left=e,this.right=t,this.height=e.height+t.height,this.outdated=e.outdated||t.outdated,this.size=e.size+t.size,this.length=e.length+this.break+t.length,this)}updateHeight(e,t=0,i=!1,n){let{left:s,right:r}=this,o=t+s.length+this.break,a=null;return n&&n.from<=t+s.length&&n.more?a=s=s.updateHeight(e,t,i,n):s.updateHeight(e,t,i),n&&n.from<=o+r.length&&n.more?a=r=r.updateHeight(e,o,i,n):r.updateHeight(e,o,i),a?this.balanced(s,r):(this.height=this.left.height+this.right.height,this.outdated=!1,this)}toString(){return this.left+(this.break?" ":"-")+this.right}}function Jn(e,t){let i,n;null==e[t]&&(i=e[t-1])instanceof Zn&&(n=e[t+1])instanceof Zn&&e.splice(t-1,3,new Zn(i.length+1+n.length))}class es{constructor(e,t){this.pos=e,this.oracle=t,this.nodes=[],this.lineStart=-1,this.lineEnd=-1,this.covering=null,this.writtenTo=e}get isCovered(){return this.covering&&this.nodes[this.nodes.length-1]==this.covering}span(e,t){if(this.lineStart>-1){let e=Math.min(t,this.lineEnd),i=this.nodes[this.nodes.length-1];i instanceof Gn?i.length+=e-this.pos:(e>this.pos||!this.isCovered)&&this.nodes.push(new Gn(e-this.pos,-1)),this.writtenTo=e,t>e&&(this.nodes.push(null),this.writtenTo++,this.lineStart=-1)}this.pos=t}point(e,t,i){if(e=5)&&this.addLineDeco(n,s,r)}else t>e&&this.span(e,t);this.lineEnd>-1&&this.lineEnd-1)return;let{from:e,to:t}=this.oracle.doc.lineAt(this.pos);this.lineStart=e,this.lineEnd=t,this.writtenToe&&this.nodes.push(new Gn(this.pos-e,-1)),this.writtenTo=this.pos}blankContent(e,t){let i=new Zn(t-e);return this.oracle.doc.lineAt(e).to==t&&(i.flags|=4),i}ensureLine(){this.enterLine();let e=this.nodes.length?this.nodes[this.nodes.length-1]:null;if(e instanceof Gn)return e;let t=new Gn(0,-1);return this.nodes.push(t),t}addBlock(e){this.enterLine();let t=e.deco;t&&t.startSide>0&&!this.isCovered&&this.ensureLine(),this.nodes.push(e),this.writtenTo=this.pos=this.pos+e.length,t&&t.endSide>0&&(this.covering=e)}addLineDeco(e,t,i){let n=this.ensureLine();n.length+=i,n.collapsed+=i,n.widgetHeight=Math.max(n.widgetHeight,e),n.breaks+=t,this.writtenTo=this.pos=this.pos+i}finish(e){let t=0==this.nodes.length?null:this.nodes[this.nodes.length-1];!(this.lineStart>-1)||t instanceof Gn||this.isCovered?(this.writtenToi.clientHeight||i.scrollWidth>i.clientWidth)&&"visible"!=n.overflow){let n=i.getBoundingClientRect();r=Math.max(r,n.left),o=Math.min(o,n.right),a=Math.max(a,n.top),l=t==e.parentNode?n.bottom:Math.min(l,n.bottom)}t="absolute"==n.position||"fixed"==n.position?i.offsetParent:i.parentNode}else{if(11!=t.nodeType)break;t=t.host}return{left:r-i.left,right:Math.max(r,o)-i.left,top:a-(i.top+t),bottom:Math.max(a,l)-(i.top+t)}}function ns(e,t){let i=e.getBoundingClientRect();return{left:0,right:i.right-i.left,top:t,bottom:i.bottom-(i.top+t)}}class ss{constructor(e,t,i){this.from=e,this.to=t,this.size=i}static same(e,t){if(e.length!=t.length)return!1;for(let i=0;i"function"!=typeof e&&"cm-lineWrapping"==e.class));this.heightOracle=new Wn(i),this.stateDeco=t.facet(xi).filter((e=>"function"!=typeof e)),this.heightMap=Xn.empty().applyChanges(this.stateDeco,e.empty,this.heightOracle.setDoc(t.doc),[new Ei(0,0,0,t.doc.length)]),this.viewport=this.getViewport(0,null),this.updateViewportLines(),this.updateForViewport(),this.lineGaps=this.ensureLineGaps([]),this.lineGapDeco=Yt.set(this.lineGaps.map((e=>e.draw(this,!1)))),this.computeVisibleRanges()}updateForViewport(){let e=[this.viewport],{main:t}=this.state.selection;for(let i=0;i<=1;i++){let n=i?t.head:t.anchor;if(!e.some((({from:e,to:t})=>n>=e&&n<=t))){let{from:t,to:i}=this.lineBlockAt(n);e.push(new as(t,i))}}this.viewports=e.sort(((e,t)=>e.from-t.from)),this.scaler=this.heightMap.height<=7e6?ds:new us(this.heightOracle,this.heightMap,this.viewports)}updateViewportLines(){this.viewportLines=[],this.heightMap.forEachLine(this.viewport.from,this.viewport.to,this.heightOracle.setDoc(this.state.doc),0,0,(e=>{this.viewportLines.push(1==this.scaler.scale?e:ps(e,this.scaler))}))}update(e,t=null){this.state=e.state;let i=this.stateDeco;this.stateDeco=this.state.facet(xi).filter((e=>"function"!=typeof e));let n=e.changedRanges,s=Ei.extendWithRanges(n,function(e,t,i){let n=new ts;return Se.compare(e,t,i,n,0),n.changes}(i,this.stateDeco,e?e.changes:S.empty(this.state.doc.length))),r=this.heightMap.height,o=this.scrolledToBottom?null:this.scrollAnchorAt(this.scrollTop);this.heightMap=this.heightMap.applyChanges(this.stateDeco,e.startState.doc,this.heightOracle.setDoc(this.state.doc),s),this.heightMap.height!=r&&(e.flags|=2),o?(this.scrollAnchorPos=e.changes.mapPos(o.from,-1),this.scrollAnchorHeight=o.top):(this.scrollAnchorPos=-1,this.scrollAnchorHeight=this.heightMap.height);let a=s.length?this.mapViewport(this.viewport,e.changes):this.viewport;(t&&(t.range.heada.to)||!this.viewportIsAppropriate(a))&&(a=this.getViewport(0,t));let l=!e.changes.empty||2&e.flags||a.from!=this.viewport.from||a.to!=this.viewport.to;this.viewport=a,this.updateForViewport(),l&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(this.mapLineGaps(this.lineGaps,e.changes))),e.flags|=this.computeVisibleRanges(),t&&(this.scrollTarget=t),!this.mustEnforceCursorAssoc&&e.selectionSet&&e.view.lineWrapping&&e.state.selection.main.empty&&e.state.selection.main.assoc&&!e.state.facet(ui)&&(this.mustEnforceCursorAssoc=!0)}measure(t){let i=t.contentDOM,n=window.getComputedStyle(i),s=this.heightOracle,r=n.whiteSpace;this.defaultTextDirection="rtl"==n.direction?Ri.RTL:Ri.LTR;let o=this.heightOracle.mustRefreshForWrapping(r),a=i.getBoundingClientRect(),l=o||this.mustMeasureContent||this.contentDOMHeight!=a.height;this.contentDOMHeight=a.height,this.mustMeasureContent=!1;let h=0,c=0;if(a.width&&a.height){let e=a.width/i.offsetWidth,t=a.height/i.offsetHeight;(e>.995&&e<1.005||!isFinite(e)||Math.abs(a.width-i.offsetWidth)<1)&&(e=1),(t>.995&&t<1.005||!isFinite(t)||Math.abs(a.height-i.offsetHeight)<1)&&(t=1),this.scaleX==e&&this.scaleY==t||(this.scaleX=e,this.scaleY=t,h|=8,o=l=!0)}let d=(parseInt(n.paddingTop)||0)*this.scaleY,u=(parseInt(n.paddingBottom)||0)*this.scaleY;this.paddingTop==d&&this.paddingBottom==u||(this.paddingTop=d,this.paddingBottom=u,h|=10),this.editorWidth!=t.scrollDOM.clientWidth&&(s.lineWrapping&&(l=!0),this.editorWidth=t.scrollDOM.clientWidth,h|=8);let p=t.scrollDOM.scrollTop*this.scaleY;this.scrollTop!=p&&(this.scrollAnchorHeight=-1,this.scrollTop=p),this.scrolledToBottom=pt(t.scrollDOM);let f=(this.printing?ns:is)(i,this.paddingTop),m=f.top-this.pixelViewport.top,g=f.bottom-this.pixelViewport.bottom;this.pixelViewport=f;let v=this.pixelViewport.bottom>this.pixelViewport.top&&this.pixelViewport.right>this.pixelViewport.left;if(v!=this.inView&&(this.inView=v,v&&(l=!0)),!this.inView&&!this.scrollTarget)return 0;let O=a.width;if(this.contentDOMWidth==O&&this.editorHeight==t.scrollDOM.clientHeight||(this.contentDOMWidth=a.width,this.editorHeight=t.scrollDOM.clientHeight,h|=8),l){let i=t.docView.measureVisibleLineHeights(this.viewport);if(s.mustRefreshForHeights(i)&&(o=!0),o||s.lineWrapping&&Math.abs(O-this.contentDOMWidth)>s.charWidth){let{lineHeight:e,charWidth:n,textHeight:a}=t.docView.measureTextSize();o=e>0&&s.refresh(r,e,n,a,O/n,i),o&&(t.docView.minWidth=0,h|=8)}m>0&&g>0?c=Math.max(m,g):m<0&&g<0&&(c=Math.min(m,g)),s.heightChanged=!1;for(let n of this.viewports){let r=n.from==this.viewport.from?i:t.docView.measureVisibleLineHeights(n);this.heightMap=(o?Xn.empty().applyChanges(this.stateDeco,e.empty,this.heightOracle,[new Ei(0,0,0,t.state.doc.length)]):this.heightMap).updateHeight(s,0,o,new Vn(n.from,r))}s.heightChanged&&(h|=2)}let b=!this.viewportIsAppropriate(this.viewport,c)||this.scrollTarget&&(this.scrollTarget.range.headthis.viewport.to);return b&&(this.viewport=this.getViewport(c,this.scrollTarget)),this.updateForViewport(),(2&h||b)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(o?[]:this.lineGaps,t)),h|=this.computeVisibleRanges(),this.mustEnforceCursorAssoc&&(this.mustEnforceCursorAssoc=!1,t.docView.enforceCursorAssoc()),h}get visibleTop(){return this.scaler.fromDOM(this.pixelViewport.top)}get visibleBottom(){return this.scaler.fromDOM(this.pixelViewport.bottom)}getViewport(e,t){let i=.5-Math.max(-.5,Math.min(.5,e/1e3/2)),n=this.heightMap,s=this.heightOracle,{visibleTop:r,visibleBottom:o}=this,a=new as(n.lineAt(r-1e3*i,Fn.ByHeight,s,0,0).from,n.lineAt(o+1e3*(1-i),Fn.ByHeight,s,0,0).to);if(t){let{head:e}=t.range;if(ea.to){let i,r=Math.min(this.editorHeight,this.pixelViewport.bottom-this.pixelViewport.top),o=n.lineAt(e,Fn.ByPos,s,0,0);i="center"==t.y?(o.top+o.bottom)/2-r/2:"start"==t.y||"nearest"==t.y&&e=o+Math.max(10,Math.min(i,250)))&&n>r-2e3&&s>1,r=n<<1;if(this.defaultTextDirection!=Ri.LTR&&!i)return[];let o=[],a=(n,r,l,h)=>{if(r-nn&&ee.from>=l.from&&e.to<=l.to&&Math.abs(e.from-n)e.fromt))));if(!u){if(re.from<=r&&e.to>=r))){let e=t.moveToLineBoundary(R.cursor(r),!1,!0).head;e>n&&(r=e)}u=new ss(n,r,this.gapSize(l,n,r,h))}o.push(u)};for(let e of this.viewportLines){if(e.lengthe.from&&a(e.from,s,e,t),oe.draw(this,this.heightOracle.lineWrapping)))))}computeVisibleRanges(){let e=this.stateDeco;this.lineGaps.length&&(e=e.concat(this.lineGapDeco));let t=[];Se.spans(e,this.viewport.from,this.viewport.to,{span(e,i){t.push({from:e,to:i})},point(){}},20);let i=t.length!=this.visibleRanges.length||this.visibleRanges.some(((e,i)=>e.from!=t[i].from||e.to!=t[i].to));return this.visibleRanges=t,i?4:0}lineBlockAt(e){return e>=this.viewport.from&&e<=this.viewport.to&&this.viewportLines.find((t=>t.from<=e&&t.to>=e))||ps(this.heightMap.lineAt(e,Fn.ByPos,this.heightOracle,0,0),this.scaler)}lineBlockAtHeight(e){return ps(this.heightMap.lineAt(this.scaler.fromDOM(e),Fn.ByHeight,this.heightOracle,0,0),this.scaler)}scrollAnchorAt(e){let t=this.lineBlockAtHeight(e+8);return t.from>=this.viewport.from||this.viewportLines[0].top-e>200?t:this.viewportLines[0]}elementAtHeight(e){return ps(this.heightMap.blockAt(this.scaler.fromDOM(e),this.heightOracle,0,0),this.scaler)}get docHeight(){return this.scaler.toDOM(this.heightMap.height)}get contentHeight(){return this.docHeight+this.paddingTop+this.paddingBottom}}class as{constructor(e,t){this.from=e,this.to=t}}function ls(e,t,i){let n=[],s=e,r=0;return Se.spans(i,e,t,{span(){},point(e,t){e>s&&(n.push({from:s,to:e}),r+=e-s),s=t}},20),s=1)return t[t.length-1].to;let n=Math.floor(e*i);for(let e=0;;e++){let{from:i,to:s}=t[e],r=s-i;if(n<=r)return i+n;n-=r}}function cs(e,t){let i=0;for(let{from:n,to:s}of e.ranges){if(t<=s){i+=t-n;break}i+=s-n}return i/e.total}const ds={toDOM:e=>e,fromDOM:e=>e,scale:1};class us{constructor(e,t,i){let n=0,s=0,r=0;this.viewports=i.map((({from:i,to:s})=>{let r=t.lineAt(i,Fn.ByPos,e,0,0).top,o=t.lineAt(s,Fn.ByPos,e,0,0).bottom;return n+=o-r,{from:i,to:s,top:r,bottom:o,domTop:0,domBottom:0}})),this.scale=(7e6-n)/(t.height-n);for(let e of this.viewports)e.domTop=r+(e.top-s)*this.scale,r=e.domBottom=e.domTop+(e.bottom-e.top),s=e.bottom}toDOM(e){for(let t=0,i=0,n=0;;t++){let s=tps(e,t))):e._content)}const fs=q.define({combine:e=>e.join(" ")}),ms=q.define({combine:e=>e.indexOf(!0)>-1}),gs=ze.newName(),vs=ze.newName(),Os=ze.newName(),bs={"&light":"."+vs,"&dark":"."+Os};function _s(e,t,i){return new ze(t,{finish:t=>/&/.test(t)?t.replace(/&\w*/,(t=>{if("&"==t)return e;if(!i||!i[t])throw new RangeError(`Unsupported selector: ${t}`);return i[t]})):e+" "+t})}const ys=_s("."+gs,{"&":{position:"relative !important",boxSizing:"border-box","&.cm-focused":{outline:"1px dotted #212121"},display:"flex !important",flexDirection:"column"},".cm-scroller":{display:"flex !important",alignItems:"flex-start !important",fontFamily:"monospace",lineHeight:1.4,height:"100%",overflowX:"auto",position:"relative",zIndex:0},".cm-content":{margin:0,flexGrow:2,flexShrink:0,display:"block",whiteSpace:"pre",wordWrap:"normal",boxSizing:"border-box",minHeight:"100%",padding:"4px 0",outline:"none","&[contenteditable=true]":{WebkitUserModify:"read-write-plaintext-only"}},".cm-lineWrapping":{whiteSpace_fallback:"pre-wrap",whiteSpace:"break-spaces",wordBreak:"break-word",overflowWrap:"anywhere",flexShrink:1},"&light .cm-content":{caretColor:"black"},"&dark .cm-content":{caretColor:"white"},".cm-line":{display:"block",padding:"0 2px 0 6px"},".cm-layer":{position:"absolute",left:0,top:0,contain:"size style","& > *":{position:"absolute"}},"&light .cm-selectionBackground":{background:"#d9d9d9"},"&dark .cm-selectionBackground":{background:"#222"},"&light.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground":{background:"#d7d4f0"},"&dark.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground":{background:"#233"},".cm-cursorLayer":{pointerEvents:"none"},"&.cm-focused > .cm-scroller > .cm-cursorLayer":{animation:"steps(1) cm-blink 1.2s infinite"},"@keyframes cm-blink":{"0%":{},"50%":{opacity:0},"100%":{}},"@keyframes cm-blink2":{"0%":{},"50%":{opacity:0},"100%":{}},".cm-cursor, .cm-dropCursor":{borderLeft:"1.2px solid black",marginLeft:"-0.6px",pointerEvents:"none"},".cm-cursor":{display:"none"},"&dark .cm-cursor":{borderLeftColor:"#444"},".cm-dropCursor":{position:"absolute"},"&.cm-focused > .cm-scroller > .cm-cursorLayer .cm-cursor":{display:"block"},"&light .cm-activeLine":{backgroundColor:"#cceeff44"},"&dark .cm-activeLine":{backgroundColor:"#99eeff33"},"&light .cm-specialChar":{color:"red"},"&dark .cm-specialChar":{color:"#f78"},".cm-gutters":{flexShrink:0,display:"flex",height:"100%",boxSizing:"border-box",insetInlineStart:0,zIndex:200},"&light .cm-gutters":{backgroundColor:"#f5f5f5",color:"#6c6c6c",borderRight:"1px solid #ddd"},"&dark .cm-gutters":{backgroundColor:"#333338",color:"#ccc"},".cm-gutter":{display:"flex !important",flexDirection:"column",flexShrink:0,boxSizing:"border-box",minHeight:"100%",overflow:"hidden"},".cm-gutterElement":{boxSizing:"border-box"},".cm-lineNumbers .cm-gutterElement":{padding:"0 3px 0 5px",minWidth:"20px",textAlign:"right",whiteSpace:"nowrap"},"&light .cm-activeLineGutter":{backgroundColor:"#e2f2ff"},"&dark .cm-activeLineGutter":{backgroundColor:"#222227"},".cm-panels":{boxSizing:"border-box",position:"sticky",left:0,right:0},"&light .cm-panels":{backgroundColor:"#f5f5f5",color:"black"},"&light .cm-panels-top":{borderBottom:"1px solid #ddd"},"&light .cm-panels-bottom":{borderTop:"1px solid #ddd"},"&dark .cm-panels":{backgroundColor:"#333338",color:"white"},".cm-tab":{display:"inline-block",overflow:"hidden",verticalAlign:"bottom"},".cm-widgetBuffer":{verticalAlign:"text-top",height:"1em",width:0,display:"inline"},".cm-placeholder":{color:"#888",display:"inline-block",verticalAlign:"top"},".cm-highlightSpace:before":{content:"attr(data-display)",position:"absolute",pointerEvents:"none",color:"#888"},".cm-highlightTab":{backgroundImage:'url(\'data:image/svg+xml,\')',backgroundSize:"auto 100%",backgroundPosition:"right 90%",backgroundRepeat:"no-repeat"},".cm-trailingSpace":{backgroundColor:"#ff332255"},".cm-button":{verticalAlign:"middle",color:"inherit",fontSize:"70%",padding:".2em 1em",borderRadius:"1px"},"&light .cm-button":{backgroundImage:"linear-gradient(#eff1f5, #d9d9df)",border:"1px solid #888","&:active":{backgroundImage:"linear-gradient(#b4b4b4, #d0d3d6)"}},"&dark .cm-button":{backgroundImage:"linear-gradient(#393939, #111)",border:"1px solid #888","&:active":{backgroundImage:"linear-gradient(#111, #333)"}},".cm-textfield":{verticalAlign:"middle",color:"inherit",fontSize:"70%",border:"1px solid silver",padding:".2em .5em"},"&light .cm-textfield":{backgroundColor:"white"},"&dark .cm-textfield":{border:"1px solid #555",backgroundColor:"inherit"}},bs),ws="ï¿¿";class xs{constructor(e,t){this.points=e,this.text="",this.lineSeparator=t.facet(Oe.lineSeparator)}append(e){this.text+=e}lineBreak(){this.text+=ws}readRange(e,t){if(!e)return this;let i=e.parentNode;for(let n=e;;){this.findPointBefore(i,n);let e=this.text.length;this.readNode(n);let s=n.nextSibling;if(s==t)break;let r=gt.get(n),o=gt.get(s);(r&&o?r.breakAfter:(r?r.breakAfter:ks(n))||ks(s)&&("BR"!=n.nodeName||n.cmIgnore)&&this.text.length>e)&&this.lineBreak(),n=s}return this.findPointBefore(i,t),this}readTextNode(e){let t=e.nodeValue;for(let i of this.points)i.node==e&&(i.pos=this.text.length+Math.min(i.offset,t.length));for(let i=0,n=this.lineSeparator?null:/\r\n?|\n/g;;){let s,r=-1,o=1;if(this.lineSeparator?(r=t.indexOf(this.lineSeparator,i),o=this.lineSeparator.length):(s=n.exec(t))&&(r=s.index,o=s[0].length),this.append(t.slice(i,r<0?t.length:r)),r<0)break;if(this.lineBreak(),o>1)for(let t of this.points)t.node==e&&t.pos>this.text.length&&(t.pos-=o-1);i=r+o}}readNode(e){if(e.cmIgnore)return;let t=gt.get(e),i=t&&t.overrideDOMText;if(null!=i){this.findPointInside(e,i.length);for(let e=i.iter();!e.next().done;)e.lineBreak?this.lineBreak():this.append(e.value)}else 3==e.nodeType?this.readTextNode(e):"BR"==e.nodeName?e.nextSibling&&this.lineBreak():1==e.nodeType&&this.readRange(e.firstChild,null)}findPointBefore(e,t){for(let i of this.points)i.node==e&&e.childNodes[i.offset]==t&&(i.pos=this.text.length)}findPointInside(e,t){for(let i of this.points)(3==e.nodeType?i.node==e:e.contains(i.node))&&(i.pos=this.text.length+(Ss(e,i.node,i.offset)?t:0))}}function Ss(e,t,i){for(;;){if(!t||i-1)this.newSel=null;else if(t>-1&&(this.bounds=e.docView.domBoundsAround(t,i,0))){let t=s||r?[]:function(e){let t=[];if(e.root.activeElement!=e.contentDOM)return t;let{anchorNode:i,anchorOffset:n,focusNode:s,focusOffset:r}=e.observer.selectionRange;return i&&(t.push(new Ts(i,n)),s==i&&r==n||t.push(new Ts(s,r))),t}(e),i=new xs(t,e.state);i.readRange(this.bounds.startDOM,this.bounds.endDOM),this.text=i.text,this.newSel=function(e,t){if(0==e.length)return null;let i=e[0].pos,n=2==e.length?e[1].pos:i;return i>-1&&n>-1?R.single(i+t,n+t):null}(t,this.bounds.from)}else{let t=e.observer.selectionRange,i=s&&s.node==t.focusNode&&s.offset==t.focusOffset||!Ze(e.contentDOM,t.focusNode)?e.state.selection.main.head:e.docView.posFromDOM(t.focusNode,t.focusOffset),n=r&&r.node==t.anchorNode&&r.offset==t.anchorOffset||!Ze(e.contentDOM,t.anchorNode)?e.state.selection.main.anchor:e.docView.posFromDOM(t.anchorNode,t.anchorOffset);this.newSel=R.single(n,i)}}}function Ps(t,i){let n,{newSel:s}=i,r=t.state.selection.main,o=t.inputState.lastKeyTime>Date.now()-100?t.inputState.lastKeyCode:-1;if(i.bounds){let{from:s,to:a}=i.bounds,l=r.from,h=null;(8===o||Rt.android&&i.text.length0&&a>0&&e.charCodeAt(o-1)==t.charCodeAt(a-1);)o--,a--;return"end"==n&&(i-=o+Math.max(0,r-Math.min(o,a))-r),o=o?r-i:0,a=r+(a-o),o=r):a=a?r-i:0,o=r+(o-a),a=r),{from:r,toA:o,toB:a}}(t.state.doc.sliceString(s,a,ws),i.text,l-s,h);c&&(Rt.chrome&&13==o&&c.toB==c.from+2&&i.text.slice(c.from,c.toB)==ws+ws&&c.toB--,n={from:s+c.from,to:s+c.toA,insert:e.of(i.text.slice(c.from,c.toB).split(ws))})}else s&&(!t.hasFocus&&t.state.facet(gi)||s.main.eq(r))&&(s=null);if(!n&&!s)return!1;if(!n&&i.typeOver&&!r.empty&&s&&s.main.empty?n={from:r.from,to:r.to,insert:t.state.doc.slice(r.from,r.to)}:n&&n.from>=r.from&&n.to<=r.to&&(n.from!=r.from||n.to!=r.to)&&r.to-r.from-(n.to-n.from)<=4?n={from:r.from,to:r.to,insert:t.state.doc.slice(r.from,n.from).append(n.insert).append(t.state.doc.slice(n.to,r.to))}:(Rt.mac||Rt.android)&&n&&n.from==n.to&&n.from==r.head-1&&/^\. ?$/.test(n.insert.toString())&&"off"==t.contentDOM.getAttribute("autocorrect")?(s&&2==n.insert.length&&(s=R.single(s.main.anchor-1,s.main.head-1)),n={from:r.from,to:r.to,insert:e.of([" "])}):Rt.chrome&&n&&n.from==n.to&&n.from==r.head&&"\n "==n.insert.toString()&&t.lineWrapping&&(s&&(s=R.single(s.main.anchor-1,s.main.head-1)),n={from:r.from,to:r.to,insert:e.of([" "])}),n){if(Rt.ios&&t.inputState.flushIOSKey())return!0;if(Rt.android&&(n.from==r.from&&n.to==r.to&&1==n.insert.length&&2==n.insert.lines&&dt(t.contentDOM,"Enter",13)||(n.from==r.from-1&&n.to==r.to&&0==n.insert.length||8==o&&n.insert.lengthr.head)&&dt(t.contentDOM,"Backspace",8)||n.from==r.from&&n.to==r.to+1&&0==n.insert.length&&dt(t.contentDOM,"Delete",46)))return!0;let e,i=n.insert.toString();t.inputState.composing>=0&&t.inputState.composing++;let a=()=>e||(e=function(e,t,i){let n,s=e.state,r=s.selection.main;if(t.from>=r.from&&t.to<=r.to&&t.to-t.from>=(r.to-r.from)/3&&(!i||i.main.empty&&i.main.from==t.from+t.insert.length)&&e.inputState.composing<0){let i=r.fromt.to?s.sliceDoc(t.to,r.to):"";n=s.replaceSelection(e.state.toText(i+t.insert.sliceString(0,void 0,e.state.lineBreak)+o))}else{let o=s.changes(t),a=i&&i.main.to<=o.newLength?i.main:void 0;if(s.selection.ranges.length>1&&e.inputState.composing>=0&&t.to<=r.to&&t.to>=r.to-10){let l,h=e.state.sliceDoc(t.from,t.to),c=i&&Zi(e,i.main.head);if(c){let e=t.insert.length-(t.to-t.from);l={from:c.from,to:c.to-e}}else l=e.state.doc.lineAt(r.head);let d=r.to-t.to,u=r.to-r.from;n=s.changeByRange((i=>{if(i.from==r.from&&i.to==r.to)return{changes:o,range:a||i.map(o)};let n=i.to-d,c=n-h.length;if(i.to-i.from!=u||e.state.sliceDoc(c,n)!=h||i.to>=l.from&&i.from<=l.to)return{range:i};let p=s.changes({from:c,to:n,insert:t.insert}),f=i.to-r.to;return{changes:p,range:a?R.range(Math.max(0,a.anchor+f),Math.max(0,a.head+f)):i.map(p)}}))}else n={changes:o,selection:a&&s.selection.replaceRange(a)}}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)),s.update(n,{userEvent:o,scrollIntoView:!0})}(t,n,s));return t.state.facet(hi).some((e=>e(t,n.from,n.to,i,a)))||t.dispatch(a()),!0}if(s&&!s.main.eq(r)){let e=!1,i="select";return t.inputState.lastSelectionTime>Date.now()-50&&("select"==t.inputState.lastSelectionOrigin&&(e=!0),i=t.inputState.lastSelectionOrigin),t.dispatch({selection:s,scrollIntoView:e,userEvent:i}),!0}return!1}const Ms={childList:!0,characterData:!0,subtree:!0,attributes:!0,characterDataOldValue:!0},Es=Rt.ie&&Rt.ie_version<=11;class As{constructor(e){this.view=e,this.active=!1,this.selectionRange=new ot,this.selectionChanged=!1,this.delayedFlush=-1,this.resizeTimeout=-1,this.queue=[],this.delayedAndroidKey=null,this.flushingAndroidKey=-1,this.lastChange=0,this.scrollTargets=[],this.intersection=null,this.resizeScroll=null,this.intersecting=!1,this.gapIntersection=null,this.gaps=[],this.parentCheck=-1,this.dom=e.contentDOM,this.observer=new MutationObserver((t=>{for(let e of t)this.queue.push(e);(Rt.ie&&Rt.ie_version<=11||Rt.ios&&e.composing)&&t.some((e=>"childList"==e.type&&e.removedNodes.length||"characterData"==e.type&&e.oldValue.length>e.target.nodeValue.length))?this.flushSoon():this.flush()})),Es&&(this.onCharData=e=>{this.queue.push({target:e.target,type:"characterData",oldValue:e.prevValue}),this.flushSoon()}),this.onSelectionChange=this.onSelectionChange.bind(this),this.onResize=this.onResize.bind(this),this.onPrint=this.onPrint.bind(this),this.onScroll=this.onScroll.bind(this),"function"==typeof ResizeObserver&&(this.resizeScroll=new ResizeObserver((()=>{var e;(null===(e=this.view.docView)||void 0===e?void 0:e.lastUpdate){this.parentCheck<0&&(this.parentCheck=setTimeout(this.listenForScroll.bind(this),1e3)),e.length>0&&e[e.length-1].intersectionRatio>0!=this.intersecting&&(this.intersecting=!this.intersecting,this.intersecting!=this.view.inView&&this.onScrollChanged(document.createEvent("Event")))}),{threshold:[0,.001]}),this.intersection.observe(this.dom),this.gapIntersection=new IntersectionObserver((e=>{e.length>0&&e[e.length-1].intersectionRatio>0&&this.onScrollChanged(document.createEvent("Event"))}),{})),this.listenForScroll(),this.readSelectionRange()}onScrollChanged(e){this.view.inputState.runHandlers("scroll",e),this.intersecting&&this.view.measure()}onScroll(e){this.intersecting&&this.flush(!1),this.onScrollChanged(e)}onResize(){this.resizeTimeout<0&&(this.resizeTimeout=setTimeout((()=>{this.resizeTimeout=-1,this.view.requestMeasure()}),50))}onPrint(){this.view.viewState.printing=!0,this.view.measure(),setTimeout((()=>{this.view.viewState.printing=!1,this.view.requestMeasure()}),500)}updateGaps(e){if(this.gapIntersection&&(e.length!=this.gaps.length||this.gaps.some(((t,i)=>t!=e[i])))){this.gapIntersection.disconnect();for(let t of e)this.gapIntersection.observe(t);this.gaps=e}}onSelectionChange(e){let t=this.selectionChanged;if(!this.readSelectionRange()||this.delayedAndroidKey)return;let{view:i}=this,n=this.selectionRange;if(i.state.facet(gi)?i.root.activeElement!=this.dom:!Ke(i.dom,n))return;let s=n.anchorNode&&i.docView.nearest(n.anchorNode);s&&s.ignoreEvent(e)?t||(this.selectionChanged=!1):(Rt.ie&&Rt.ie_version<=11||Rt.android&&Rt.chrome)&&!i.state.selection.main.empty&&n.focusNode&&et(n.focusNode,n.focusOffset,n.anchorNode,n.anchorOffset)?this.flushSoon():this.flush(!1)}readSelectionRange(){let{view:e}=this,t=Rt.safari&&11==e.root.nodeType&&function(e){let t=e.activeElement;for(;t&&t.shadowRoot;)t=t.shadowRoot.activeElement;return t}(this.dom.ownerDocument)==this.dom&&function(e){let t=null;function i(e){e.preventDefault(),e.stopImmediatePropagation(),t=e.getTargetRanges()[0]}if(e.contentDOM.addEventListener("beforeinput",i,!0),e.dom.ownerDocument.execCommand("indent"),e.contentDOM.removeEventListener("beforeinput",i,!0),!t)return null;let n=t.startContainer,s=t.startOffset,r=t.endContainer,o=t.endOffset,a=e.docView.domAtPos(e.state.selection.main.anchor);return et(a.node,a.offset,r,o)&&([n,s,r,o]=[r,o,n,s]),{anchorNode:n,anchorOffset:s,focusNode:r,focusOffset:o}}(this.view)||Ge(e.root);if(!t||this.selectionRange.eq(t))return!1;let i=Ke(this.dom,t);return i&&!this.selectionChanged&&e.inputState.lastFocusTime>Date.now()-200&&e.inputState.lastTouchTime{let e=this.delayedAndroidKey;e&&(this.clearDelayedAndroidKey(),this.view.inputState.lastKeyCode=e.keyCode,this.view.inputState.lastKeyTime=Date.now(),!this.flush()&&e.force&&dt(this.dom,e.key,e.keyCode))};this.flushingAndroidKey=this.view.win.requestAnimationFrame(e)}this.delayedAndroidKey&&"Enter"!=e||(this.delayedAndroidKey={key:e,keyCode:t,force:this.lastChange{this.delayedFlush=-1,this.flush()})))}forceFlush(){this.delayedFlush>=0&&(this.view.win.cancelAnimationFrame(this.delayedFlush),this.delayedFlush=-1),this.flush()}pendingRecords(){for(let e of this.observer.takeRecords())this.queue.push(e);return this.queue}processRecords(){let e=this.pendingRecords();e.length&&(this.queue=[]);let t=-1,i=-1,n=!1;for(let s of e){let e=this.readMutation(s);e&&(e.typeOver&&(n=!0),-1==t?({from:t,to:i}=e):(t=Math.min(e.from,t),i=Math.max(e.to,i)))}return{from:t,to:i,typeOver:n}}readChange(){let{from:e,to:t,typeOver:i}=this.processRecords(),n=this.selectionChanged&&Ke(this.dom,this.selectionRange);if(e<0&&!n)return null;e>-1&&(this.lastChange=Date.now()),this.view.inputState.lastFocusTime=0,this.selectionChanged=!1;let s=new Cs(this.view,e,t,i);return this.view.docView.domChanged={newSel:s.newSel?s.newSel.main:null},s}flush(e=!0){if(this.delayedFlush>=0||this.delayedAndroidKey)return!1;e&&this.readSelectionRange();let t=this.readChange();if(!t)return this.view.requestMeasure(),!1;let i=this.view.state,n=Ps(this.view,t);return this.view.state==i&&this.view.update([]),n}readMutation(e){let t=this.view.docView.nearest(e.target);if(!t||t.ignoreMutation(e))return null;if(t.markDirty("attributes"==e.type),"attributes"==e.type&&(t.flags|=4),"childList"==e.type){let i=Rs(t,e.previousSibling||e.target.previousSibling,-1),n=Rs(t,e.nextSibling||e.target.nextSibling,1);return{from:i?t.posAfter(i):t.posAtStart,to:n?t.posBefore(n):t.posAtEnd,typeOver:!1}}return"characterData"==e.type?{from:t.posAtStart,to:t.posAtEnd,typeOver:e.target.nodeValue==e.oldValue}:null}setWindow(e){e!=this.win&&(this.removeWindowListeners(this.win),this.win=e,this.addWindowListeners(this.win))}addWindowListeners(e){e.addEventListener("resize",this.onResize),e.addEventListener("beforeprint",this.onPrint),e.addEventListener("scroll",this.onScroll),e.document.addEventListener("selectionchange",this.onSelectionChange)}removeWindowListeners(e){e.removeEventListener("scroll",this.onScroll),e.removeEventListener("resize",this.onResize),e.removeEventListener("beforeprint",this.onPrint),e.document.removeEventListener("selectionchange",this.onSelectionChange)}destroy(){var e,t,i;this.stop(),null===(e=this.intersection)||void 0===e||e.disconnect(),null===(t=this.gapIntersection)||void 0===t||t.disconnect(),null===(i=this.resizeScroll)||void 0===i||i.disconnect();for(let e of this.scrollTargets)e.removeEventListener("scroll",this.onScroll);this.removeWindowListeners(this.win),clearTimeout(this.parentCheck),clearTimeout(this.resizeTimeout),this.win.cancelAnimationFrame(this.delayedFlush),this.win.cancelAnimationFrame(this.flushingAndroidKey)}}function Rs(e,t,i){for(;t;){let n=gt.get(t);if(n&&n.parent==e)return n;let s=t.parentNode;t=s!=e.dom?s:i>0?t.nextSibling:t.previousSibling}return null}class Ds{get state(){return this.viewState.state}get viewport(){return this.viewState.viewport}get visibleRanges(){return this.viewState.visibleRanges}get inView(){return this.viewState.inView}get composing(){return this.inputState.composing>0}get compositionStarted(){return this.inputState.composing>=0}get root(){return this._root}get win(){return this.dom.ownerDocument.defaultView||window}constructor(e={}){this.plugins=[],this.pluginMap=new Map,this.editorAttrs={},this.contentAttrs={},this.bidiCache=[],this.destroyed=!1,this.updateState=2,this.measureScheduled=-1,this.measureRequests=[],this.contentDOM=document.createElement("div"),this.scrollDOM=document.createElement("div"),this.scrollDOM.tabIndex=-1,this.scrollDOM.className="cm-scroller",this.scrollDOM.appendChild(this.contentDOM),this.announceDOM=document.createElement("div"),this.announceDOM.style.cssText="position: fixed; top: -10000px",this.announceDOM.setAttribute("aria-live","polite"),this.dom=document.createElement("div"),this.dom.appendChild(this.announceDOM),this.dom.appendChild(this.scrollDOM);let{dispatch:t}=e;this.dispatchTransactions=e.dispatchTransactions||t&&(e=>e.forEach((e=>t(e,this))))||(e=>this.update(e)),this.dispatch=this.dispatch.bind(this),this._root=e.root||function(e){for(;e;){if(e&&(9==e.nodeType||11==e.nodeType&&e.host))return e;e=e.assignedSlot||e.parentNode}return null}(e.parent)||document,this.viewState=new os(e.state||Oe.create(e)),this.plugins=this.state.facet(Oi).map((e=>new _i(e)));for(let e of this.plugins)e.update(this);this.observer=new As(this),this.inputState=new fn(this),this.inputState.ensureHandlers(this.plugins),this.docView=new Yi(this),this.mountStyles(),this.updateAttrs(),this.updateState=0,this.requestMeasure(),e.parent&&e.parent.appendChild(this.dom)}dispatch(...e){let t=1==e.length&&e[0]instanceof le?e:1==e.length&&Array.isArray(e[0])?e[0]:[this.state.update(...e)];this.dispatchTransactions(t,this)}update(e){if(0!=this.updateState)throw new Error("Calls to EditorView.update are not allowed while an update is in progress");let t,i=!1,n=!1,s=this.state;for(let t of e){if(t.startState!=s)throw new RangeError("Trying to update state with a transaction that doesn't start from the previous state.");s=t.state}if(this.destroyed)return void(this.viewState.state=s);let r=this.hasFocus,o=0,a=null;e.some((e=>e.annotation(Bn)))?(this.inputState.notifiedFocused=r,o=1):r!=this.inputState.notifiedFocused&&(this.inputState.notifiedFocused=r,a=$n(s,r),a||(o=1));let l=this.observer.delayedAndroidKey,h=null;if(l?(this.observer.clearDelayedAndroidKey(),h=this.observer.readChange(),(h&&!this.state.doc.eq(s.doc)||!this.state.selection.eq(s.selection))&&(h=null)):this.observer.clear(),s.facet(Oe.phrases)!=this.state.facet(Oe.phrases))return this.setState(s);t=Ai.create(this,s,e),t.flags|=o;let c=this.viewState.scrollTarget;try{this.updateState=2;for(let t of e){if(c&&(c=c.map(t.changes)),t.scrollIntoView){let{main:e}=t.state.selection;c=new pi(e.empty?e:R.cursor(e.head,e.head>e.anchor?-1:1))}for(let e of t.effects)e.is(fi)&&(c=e.value)}this.viewState.update(t,c),this.bidiCache=Ls.update(this.bidiCache,t.changes),t.empty||(this.updatePlugins(t),this.inputState.update(t)),i=this.docView.update(t),this.state.facet(Mi)!=this.styleModules&&this.mountStyles(),n=this.updateAttrs(),this.showAnnouncements(e),this.docView.updateSelection(i,e.some((e=>e.isUserEvent("select.pointer"))))}finally{this.updateState=0}if(t.startState.facet(fs)!=t.state.facet(fs)&&(this.viewState.mustMeasureContent=!0),(i||n||c||this.viewState.mustEnforceCursorAssoc||this.viewState.mustMeasureContent)&&this.requestMeasure(),!t.empty)for(let e of this.state.facet(li))e(t);(a||h)&&Promise.resolve().then((()=>{a&&this.state==a.startState&&this.dispatch(a),h&&!Ps(this,h)&&l.force&&dt(this.contentDOM,l.key,l.keyCode)}))}setState(e){if(0!=this.updateState)throw new Error("Calls to EditorView.setState are not allowed while an update is in progress");if(this.destroyed)return void(this.viewState.state=e);this.updateState=2;let t=this.hasFocus;try{for(let e of this.plugins)e.destroy(this);this.viewState=new os(e),this.plugins=e.facet(Oi).map((e=>new _i(e))),this.pluginMap.clear();for(let e of this.plugins)e.update(this);this.docView=new Yi(this),this.inputState.ensureHandlers(this.plugins),this.mountStyles(),this.updateAttrs(),this.bidiCache=[]}finally{this.updateState=0}t&&this.focus(),this.requestMeasure()}updatePlugins(e){let t=e.startState.facet(Oi),i=e.state.facet(Oi);if(t!=i){let n=[];for(let s of i){let i=t.indexOf(s);if(i<0)n.push(new _i(s));else{let t=this.plugins[i];t.mustUpdate=e,n.push(t)}}for(let t of this.plugins)t.mustUpdate!=e&&t.destroy(this);this.plugins=n,this.pluginMap.clear()}else for(let t of this.plugins)t.mustUpdate=e;for(let e=0;e-1&&this.win.cancelAnimationFrame(this.measureScheduled),this.observer.delayedAndroidKey)return this.measureScheduled=-1,void this.requestMeasure();this.measureScheduled=0,e&&this.observer.forceFlush();let t=null,i=this.scrollDOM,n=i.scrollTop*this.scaleY,{scrollAnchorPos:s,scrollAnchorHeight:r}=this.viewState;Math.abs(n-this.viewState.scrollTop)>1&&(r=-1),this.viewState.scrollAnchorHeight=-1;try{for(let e=0;;e++){if(r<0)if(pt(i))s=-1,r=this.viewState.heightMap.height;else{let e=this.viewState.scrollAnchorAt(n);s=e.from,r=e.top}this.updateState=1;let o=this.viewState.measure(this);if(!o&&!this.measureRequests.length&&null==this.viewState.scrollTarget)break;if(e>5){console.warn(this.measureRequests.length?"Measure loop restarted more than 5 times":"Viewport failed to stabilize");break}let a=[];4&o||([this.measureRequests,a]=[a,this.measureRequests]);let l=a.map((e=>{try{return e.read(this)}catch(e){return mi(this.state,e),qs}})),h=Ai.create(this,this.state,[]),c=!1;h.flags|=o,t?t.flags|=o:t=h,this.updateState=2,h.empty||(this.updatePlugins(h),this.inputState.update(h),this.updateAttrs(),c=this.docView.update(h));for(let e=0;e1||e<-1){n+=e,i.scrollTop=n/this.scaleY,r=-1;continue}}}break}}}finally{this.updateState=0,this.measureScheduled=-1}if(t&&!t.empty)for(let e of this.state.facet(li))e(t)}get themeClasses(){return gs+" "+(this.state.facet(ms)?Os:vs)+" "+this.state.facet(fs)}updateAttrs(){let e=Ns(this,yi,{class:"cm-editor"+(this.hasFocus?" cm-focused ":" ")+this.themeClasses}),t={spellcheck:"false",autocorrect:"off",autocapitalize:"off",translate:"no",contenteditable:this.state.facet(gi)?"true":"false",class:"cm-content",style:`${Rt.tabSize}: ${this.state.tabSize}`,role:"textbox","aria-multiline":"true"};this.state.readOnly&&(t["aria-readonly"]="true"),Ns(this,wi,t);let i=this.observer.ignore((()=>{let i=Wt(this.contentDOM,this.contentAttrs,t),n=Wt(this.dom,this.editorAttrs,e);return i||n}));return this.editorAttrs=e,this.contentAttrs=t,i}showAnnouncements(e){let t=!0;for(let i of e)for(let e of i.effects)e.is(Ds.announce)&&(t&&(this.announceDOM.textContent=""),t=!1,this.announceDOM.appendChild(document.createElement("div")).textContent=e.value)}mountStyles(){this.styleModules=this.state.facet(Mi);let e=this.state.facet(Ds.cspNonce);ze.mount(this.root,this.styleModules.concat(ys).reverse(),e?{nonce:e}:void 0)}readMeasured(){if(2==this.updateState)throw new Error("Reading the editor layout isn't allowed during an update");0==this.updateState&&this.measureScheduled>-1&&this.measure(!1)}requestMeasure(e){if(this.measureScheduled<0&&(this.measureScheduled=this.win.requestAnimationFrame((()=>this.measure()))),e){if(this.measureRequests.indexOf(e)>-1)return;if(null!=e.key)for(let t=0;tt.spec==e))||null),t&&t.update(this).value}get documentTop(){return this.contentDOM.getBoundingClientRect().top+this.viewState.paddingTop}get documentPadding(){return{top:this.viewState.paddingTop,bottom:this.viewState.paddingBottom}}get scaleX(){return this.viewState.scaleX}get scaleY(){return this.viewState.scaleY}elementAtHeight(e){return this.readMeasured(),this.viewState.elementAtHeight(e)}lineBlockAtHeight(e){return this.readMeasured(),this.viewState.lineBlockAtHeight(e)}get viewportLineBlocks(){return this.viewState.viewportLines}lineBlockAt(e){return this.viewState.lineBlockAt(e)}get contentHeight(){return this.viewState.contentHeight}moveByChar(e,t,i){return pn(this,e,dn(this,e,t,i))}moveByGroup(e,t){return pn(this,e,dn(this,e,t,(t=>function(e,t,i){let n=e.state.charCategorizer(t),s=n(i);return e=>{let t=n(e);return s==me.Space&&(s=t),s==t}}(this,e.head,t))))}moveToLineBoundary(e,t,i=!0){return function(e,t,i,n){let s=cn(e,t.head),r=n&&s.type==Xt.Text&&(e.lineWrapping||s.widgetLineBreaks)?e.coordsAtPos(t.assoc<0&&t.head>s.from?t.head-1:t.head):null;if(r){let t=e.dom.getBoundingClientRect(),n=e.textDirectionAt(s.from),o=e.posAtCoords({x:i==(n==Ri.LTR)?t.right-1:t.left+1,y:(r.top+r.bottom)/2});if(null!=o)return R.cursor(o,i?-1:1)}return R.cursor(i?s.to:s.from,i?-1:1)}(this,e,t,i)}moveVertically(e,t,i){return pn(this,e,function(e,t,i,n){let s=t.head,r=i?1:-1;if(s==(i?e.state.doc.length:0))return R.cursor(s,t.assoc);let o,a=t.goalColumn,l=e.contentDOM.getBoundingClientRect(),h=e.coordsAtPos(s,t.assoc||-1),c=e.documentTop;if(h)null==a&&(a=h.left-l.left),o=r<0?h.top:h.bottom;else{let t=e.viewState.lineBlockAt(s);null==a&&(a=Math.min(l.right-l.left,e.defaultCharacterWidth*(s-t.from))),o=(r<0?t.top:t.bottom)+c}let d=l.left+a,u=null!=n?n:e.viewState.heightOracle.textHeight>>1;for(let t=0;;t+=10){let i=o+(u+t)*r,n=ln(e,{x:d,y:i},!1,r);if(il.bottom||(r<0?ns)){let t=e.docView.coordsForChar(n),s=!t||i0)}coordsForChar(e){return this.readMeasured(),this.docView.coordsForChar(e)}get defaultCharacterWidth(){return this.viewState.heightOracle.charWidth}get defaultLineHeight(){return this.viewState.heightOracle.lineHeight}get textDirection(){return this.viewState.defaultTextDirection}textDirectionAt(e){return!this.state.facet(di)||ethis.viewport.to?this.textDirection:(this.readMeasured(),this.docView.textDirectionAt(e))}get lineWrapping(){return this.viewState.heightOracle.lineWrapping}bidiSpans(e){if(e.length>Is)return Fi(e.length);let t,i=this.textDirectionAt(e.from);for(let n of this.bidiCache)if(n.from==e.from&&n.dir==i&&(n.fresh||ji(n.isolates,t=Ti(this,e.from,e.to))))return n.order;t||(t=Ti(this,e.from,e.to));let n=function(e,t,i){if(!e)return[new zi(0,0,t==Ii?1:0)];if(t==Di&&!i.length&&!Qi.test(e))return Fi(e.length);if(i.length)for(;e.length>Wi.length;)Wi[Wi.length]=256;let n=[],s=t==Di?0:1;return Ui(e,s,s,i,0,e.length,n),n}(e.text,i,t);return this.bidiCache.push(new Ls(e.from,e.to,i,t,!0,n)),n}get hasFocus(){var e;return(this.dom.ownerDocument.hasFocus()||Rt.safari&&(null===(e=this.inputState)||void 0===e?void 0:e.lastContextMenu)>Date.now()-3e4)&&this.root.activeElement==this.contentDOM}focus(){this.observer.ignore((()=>{ht(this.contentDOM),this.docView.updateSelection()}))}setRoot(e){this._root!=e&&(this._root=e,this.observer.setWindow((9==e.nodeType?e:e.ownerDocument).defaultView||window),this.mountStyles())}destroy(){for(let e of this.plugins)e.destroy(this);this.plugins=[],this.inputState.destroy(),this.dom.remove(),this.observer.destroy(),this.measureScheduled>-1&&this.win.cancelAnimationFrame(this.measureScheduled),this.destroyed=!0}static scrollIntoView(e,t={}){return fi.of(new pi("number"==typeof e?R.cursor(e):e,t.y,t.x,t.yMargin,t.xMargin))}static domEventHandlers(e){return bi.define((()=>({})),{eventHandlers:e})}static domEventObservers(e){return bi.define((()=>({})),{eventObservers:e})}static theme(e,t){let i=ze.newName(),n=[fs.of(i),Mi.of(_s(`.${i}`,e))];return t&&t.dark&&n.push(ms.of(!0)),n}static baseTheme(e){return V.lowest(Mi.of(_s("."+gs,e,bs)))}static findFromDOM(e){var t;let i=e.querySelector(".cm-content"),n=i&>.get(i)||gt.get(e);return(null===(t=null==n?void 0:n.rootView)||void 0===t?void 0:t.view)||null}}Ds.styleModule=Mi,Ds.inputHandler=hi,Ds.focusChangeEffect=ci,Ds.perLineTextDirection=di,Ds.exceptionSink=ai,Ds.updateListener=li,Ds.editable=gi,Ds.mouseSelectionStyle=oi,Ds.dragMovesSelection=ri,Ds.clickAddsSelectionRange=si,Ds.decorations=xi,Ds.atomicRanges=Si,Ds.bidiIsolatedRanges=ki,Ds.scrollMargins=Ci,Ds.darkTheme=ms,Ds.cspNonce=q.define({combine:e=>e.length?e[0]:""}),Ds.contentAttributes=wi,Ds.editorAttributes=yi,Ds.lineWrapping=Ds.contentAttributes.of({class:"cm-lineWrapping"}),Ds.announce=ae.define();const Is=4096,qs={};class Ls{constructor(e,t,i,n,s,r){this.from=e,this.to=t,this.dir=i,this.isolates=n,this.fresh=s,this.order=r}static update(e,t){if(t.empty&&!e.some((e=>e.fresh)))return e;let i=[],n=e.length?e[e.length-1].dir:Ri.LTR;for(let s=Math.max(0,e.length-10);s=0;s--){let t=n[s],r="function"==typeof t?t(e):t;r&&Qt(r,i)}return i}const Bs=Rt.mac?"mac":Rt.windows?"win":Rt.linux?"linux":"key";function $s(e,t,i){return t.altKey&&(e="Alt-"+e),t.ctrlKey&&(e="Ctrl-"+e),t.metaKey&&(e="Meta-"+e),!1!==i&&t.shiftKey&&(e="Shift-"+e),e}const Qs=V.default(Ds.domEventHandlers({keydown:(e,t)=>Fs(Ws(t.state),e,t,"editor")})),zs=q.define({enables:Qs}),js=new WeakMap;function Ws(e){let t=e.facet(zs),i=js.get(t);return i||js.set(t,i=function(e,t=Bs){let i=Object.create(null),n=Object.create(null),s=(e,t)=>{let i=n[e];if(null==i)n[e]=t;else if(i!=t)throw new Error("Key binding "+e+" is used both as a regular binding and as a multi-stroke prefix")},r=(e,n,r,o,a)=>{var l,h;let c=i[e]||(i[e]=Object.create(null)),d=n.split(/ (?!$)/).map((e=>function(e,t){const i=e.split(/-(?!$)/);let n,s,r,o,a=i[i.length-1];"Space"==a&&(a=" ");for(let e=0;e{let n=Vs={view:t,prefix:i,scope:e};return setTimeout((()=>{Vs==n&&(Vs=null)}),Us),!0}]})}let u=d.join(" ");s(u,!1);let p=c[u]||(c[u]={preventDefault:!1,stopPropagation:!1,run:(null===(h=null===(l=c._any)||void 0===l?void 0:l.run)||void 0===h?void 0:h.slice())||[]});r&&p.run.push(r),o&&(p.preventDefault=!0),a&&(p.stopPropagation=!0)};for(let n of e){let e=n.scope?n.scope.split(" "):["editor"];if(n.any)for(let t of e){let e=i[t]||(i[t]=Object.create(null));e._any||(e._any={preventDefault:!1,stopPropagation:!1,run:[]});for(let t in e)e[t].run.push(n.any)}let s=n[t]||n.key;if(s)for(let t of e)r(t,s,n.run,n.preventDefault,n.stopPropagation),n.shift&&r(t,"Shift-"+s,n.shift,n.preventDefault,n.stopPropagation)}return i}(t.reduce(((e,t)=>e.concat(t)),[]))),i}let Vs=null;const Us=4e3;function Fs(e,t,i,n){let s=function(e){var t=!(Fe&&e.metaKey&&e.shiftKey&&!e.ctrlKey&&!e.altKey||He&&e.shiftKey&&e.key&&1==e.key.length||"Unidentified"==e.key)&&e.key||(e.shiftKey?Ue:Ve)[e.keyCode]||e.key||"Unidentified";return"Esc"==t&&(t="Escape"),"Del"==t&&(t="Delete"),"Left"==t&&(t="ArrowLeft"),"Up"==t&&(t="ArrowUp"),"Right"==t&&(t="ArrowRight"),"Down"==t&&(t="ArrowDown"),t}(t),r=_(O(s,0))==s.length&&" "!=s,o="",a=!1,l=!1,h=!1;Vs&&Vs.view==i&&Vs.scope==n&&(o=Vs.prefix+" ",bn.indexOf(t.keyCode)<0&&(l=!0,Vs=null));let c,d,u=new Set,p=e=>{if(e){for(let n of e.run)if(!u.has(n)&&(u.add(n),n(i,t)))return e.stopPropagation&&(h=!0),!0;e.preventDefault&&(e.stopPropagation&&(h=!0),l=!0)}return!1},f=e[n];return f&&(p(f[o+$s(s,t,!r)])?a=!0:r&&(t.altKey||t.metaKey||t.ctrlKey)&&!(Rt.windows&&t.ctrlKey&&t.altKey)&&(c=Ve[t.keyCode])&&c!=s?(p(f[o+$s(c,t,!0)])||t.shiftKey&&(d=Ue[t.keyCode])!=s&&d!=c&&p(f[o+$s(d,t,!1)]))&&(a=!0):r&&t.shiftKey&&p(f[o+$s(s,t,!0)])&&(a=!0),!a&&p(f._any)&&(a=!0)),l&&(a=!0),a&&h&&t.stopPropagation(),a}class Hs{constructor(e,t,i,n,s){this.className=e,this.left=t,this.top=i,this.width=n,this.height=s}draw(){let e=document.createElement("div");return e.className=this.className,this.adjust(e),e}update(e,t){return t.className==this.className&&(this.adjust(e),!0)}adjust(e){e.style.left=this.left+"px",e.style.top=this.top+"px",null!=this.width&&(e.style.width=this.width+"px"),e.style.height=this.height+"px"}eq(e){return this.left==e.left&&this.top==e.top&&this.width==e.width&&this.height==e.height&&this.className==e.className}static forRange(e,t,i){if(i.empty){let n=e.coordsAtPos(i.head,i.assoc||1);if(!n)return[];let s=Xs(e);return[new Hs(t,n.left-s.left,n.top-s.top,null,n.bottom-n.top)]}return function(e,t,i){if(i.to<=e.viewport.from||i.from>=e.viewport.to)return[];let n=Math.max(i.from,e.viewport.from),s=Math.min(i.to,e.viewport.to),r=e.textDirection==Ri.LTR,o=e.contentDOM,a=o.getBoundingClientRect(),l=Xs(e),h=o.querySelector(".cm-line"),c=h&&window.getComputedStyle(h),d=a.left+(c?parseInt(c.paddingLeft)+Math.min(0,parseInt(c.textIndent)):0),u=a.right-(c?parseInt(c.paddingRight):0),p=cn(e,n),f=cn(e,s),m=p.type==Xt.Text?p:null,g=f.type==Xt.Text?f:null;if(m&&(e.lineWrapping||p.widgetLineBreaks)&&(m=Ys(e,n,m)),g&&(e.lineWrapping||f.widgetLineBreaks)&&(g=Ys(e,s,g)),m&&g&&m.from==g.from)return O(b(i.from,i.to,m));{let t=m?b(i.from,null,m):_(p,!1),n=g?b(null,i.to,g):_(f,!0),s=[];return(m||p).to<(g||f).from-(m&&g?1:0)||p.widgetLineBreaks>1&&t.bottom+e.defaultLineHeight/2h&&n.from=r)break;a>s&&l(Math.max(e,s),null==t&&e<=h,Math.min(a,r),null==i&&a>=c,o.dir)}if(s=n.to+1,s>=r)break}return 0==a.length&&l(h,null==t,c,null==i,e.textDirection),{top:s,bottom:o,horizontal:a}}function _(e,t){let i=a.top+(t?e.top:e.bottom);return{top:i,bottom:i,horizontal:[]}}}(e,t,i)}}function Xs(e){let t=e.scrollDOM.getBoundingClientRect();return{left:(e.textDirection==Ri.LTR?t.left:t.right-e.scrollDOM.clientWidth*e.scaleX)-e.scrollDOM.scrollLeft*e.scaleX,top:t.top-e.scrollDOM.scrollTop*e.scaleY}}function Ys(e,t,i){let n=R.cursor(t);return{from:Math.max(i.from,e.moveToLineBoundary(n,!1,!0).from),to:Math.min(i.to,e.moveToLineBoundary(n,!0,!0).from),type:Xt.Text}}class Gs{constructor(e,t){this.view=e,this.layer=t,this.drawn=[],this.scaleX=1,this.scaleY=1,this.measureReq={read:this.measure.bind(this),write:this.draw.bind(this)},this.dom=e.scrollDOM.appendChild(document.createElement("div")),this.dom.classList.add("cm-layer"),t.above&&this.dom.classList.add("cm-layer-above"),t.class&&this.dom.classList.add(t.class),this.scale(),this.dom.setAttribute("aria-hidden","true"),this.setOrder(e.state),e.requestMeasure(this.measureReq),t.mount&&t.mount(this.dom,e)}update(e){e.startState.facet(Zs)!=e.state.facet(Zs)&&this.setOrder(e.state),(this.layer.update(e,this.dom)||e.geometryChanged)&&(this.scale(),e.view.requestMeasure(this.measureReq))}setOrder(e){let t=0,i=e.facet(Zs);for(;t{return i=e,n=this.drawn[t],!(i.constructor==n.constructor&&i.eq(n));var i,n}))){let t=this.dom.firstChild,i=0;for(let n of e)n.update&&t&&n.constructor&&this.drawn[i].constructor&&n.update(t,this.drawn[i])?(t=t.nextSibling,i++):this.dom.insertBefore(n.draw(),t);for(;t;){let e=t.nextSibling;t.remove(),t=e}this.drawn=e}}destroy(){this.layer.destroy&&this.layer.destroy(this.dom,this.view),this.dom.remove()}}const Zs=q.define();function Ks(e){return[bi.define((t=>new Gs(t,e))),Zs.of(e)]}const Js=!Rt.ios,er=q.define({combine:e=>be(e,{cursorBlinkRate:1200,drawRangeCursor:!0},{cursorBlinkRate:(e,t)=>Math.min(e,t),drawRangeCursor:(e,t)=>e||t})});function tr(e={}){return[er.of(e),nr,rr,ar,ui.of(!0)]}function ir(e){return e.startState.facet(er)!=e.state.facet(er)}const nr=Ks({above:!0,markers(e){let{state:t}=e,i=t.facet(er),n=[];for(let s of t.selection.ranges){let r=s==t.selection.main;if(s.empty?!r||Js:i.drawRangeCursor){let t=r?"cm-cursor cm-cursor-primary":"cm-cursor cm-cursor-secondary",i=s.empty?s:R.cursor(s.head,s.head>s.anchor?-1:1);for(let s of Hs.forRange(e,t,i))n.push(s)}}return n},update(e,t){e.transactions.some((e=>e.selection))&&(t.style.animationName="cm-blink"==t.style.animationName?"cm-blink2":"cm-blink");let i=ir(e);return i&&sr(e.state,t),e.docChanged||e.selectionSet||i},mount(e,t){sr(t.state,e)},class:"cm-cursorLayer"});function sr(e,t){t.style.animationDuration=e.facet(er).cursorBlinkRate+"ms"}const rr=Ks({above:!1,markers:e=>e.state.selection.ranges.map((t=>t.empty?[]:Hs.forRange(e,"cm-selectionBackground",t))).reduce(((e,t)=>e.concat(t))),update:(e,t)=>e.docChanged||e.selectionSet||e.viewportChanged||ir(e),class:"cm-selectionLayer"}),or={".cm-line":{"& ::selection":{backgroundColor:"transparent !important"},"&::selection":{backgroundColor:"transparent !important"}}};Js&&(or[".cm-line"].caretColor="transparent !important");const ar=V.highest(Ds.theme(or)),lr=ae.define({map:(e,t)=>null==e?null:t.mapPos(e)}),hr=j.define({create:()=>null,update:(e,t)=>(null!=e&&(e=t.changes.mapPos(e)),t.effects.reduce(((e,t)=>t.is(lr)?t.value:e),e))}),cr=bi.fromClass(class{constructor(e){this.view=e,this.cursor=null,this.measureReq={read:this.readPos.bind(this),write:this.drawCursor.bind(this)}}update(e){var t;let i=e.state.field(hr);null==i?null!=this.cursor&&(null===(t=this.cursor)||void 0===t||t.remove(),this.cursor=null):(this.cursor||(this.cursor=this.view.scrollDOM.appendChild(document.createElement("div")),this.cursor.className="cm-dropCursor"),(e.startState.field(hr)!=i||e.docChanged||e.geometryChanged)&&this.view.requestMeasure(this.measureReq))}readPos(){let{view:e}=this,t=e.state.field(hr),i=null!=t&&e.coordsAtPos(t);if(!i)return null;let n=e.scrollDOM.getBoundingClientRect();return{left:i.left-n.left+e.scrollDOM.scrollLeft*e.scaleX,top:i.top-n.top+e.scrollDOM.scrollTop*e.scaleY,height:i.bottom-i.top}}drawCursor(e){if(this.cursor){let{scaleX:t,scaleY:i}=this.view;e?(this.cursor.style.left=e.left/t+"px",this.cursor.style.top=e.top/i+"px",this.cursor.style.height=e.height/i+"px"):this.cursor.style.left="-100000px"}}destroy(){this.cursor&&this.cursor.remove()}setDropPos(e){this.view.state.field(hr)!=e&&this.view.dispatch({effects:lr.of(e)})}},{eventObservers:{dragover(e){this.setDropPos(this.view.posAtCoords({x:e.clientX,y:e.clientY}))},dragleave(e){e.target!=this.view.contentDOM&&this.view.contentDOM.contains(e.relatedTarget)||this.setDropPos(null)},dragend(){this.setDropPos(null)},drop(){this.setDropPos(null)}}});function dr(e,t,i,n,s){t.lastIndex=0;for(let r,o=e.iterRange(i,n),a=i;!o.next().done;a+=o.value.length)if(!o.lineBreak)for(;r=t.exec(o.value);)s(a+r.index,r)}class ur{constructor(e){const{regexp:t,decoration:i,decorate:n,boundary:s,maxLength:r=1e3}=e;if(!t.global)throw new RangeError("The regular expression given to MatchDecorator should have its 'g' flag set");if(this.regexp=t,n)this.addMatch=(e,t,i,s)=>n(s,i,i+e[0].length,e,t);else if("function"==typeof i)this.addMatch=(e,t,n,s)=>{let r=i(e,t,n);r&&s(n,n+e[0].length,r)};else{if(!i)throw new RangeError("Either 'decorate' or 'decoration' should be provided to MatchDecorator");this.addMatch=(e,t,n,s)=>s(n,n+e[0].length,i)}this.boundary=s,this.maxLength=r}createDeco(e){let t=new ke,i=t.add.bind(t);for(let{from:t,to:n}of function(e,t){let i=e.visibleRanges;if(1==i.length&&i[0].from==e.viewport.from&&i[0].to==e.viewport.to)return i;let n=[];for(let{from:s,to:r}of i)s=Math.max(e.state.doc.lineAt(s).from,s-t),r=Math.min(e.state.doc.lineAt(r).to,r+t),n.length&&n[n.length-1].to>=s?n[n.length-1].to=r:n.push({from:s,to:r});return n}(e,this.maxLength))dr(e.state.doc,this.regexp,t,n,((t,n)=>this.addMatch(n,e,t,i)));return t.finish()}updateDeco(e,t){let i=1e9,n=-1;return e.docChanged&&e.changes.iterChanges(((t,s,r,o)=>{o>e.view.viewport.from&&r1e3?this.createDeco(e.view):n>-1?this.updateRange(e.view,t.map(e.changes),i,n):t}updateRange(e,t,i,n){for(let s of e.visibleRanges){let r=Math.max(s.from,i),o=Math.min(s.to,n);if(o>r){let i=e.state.doc.lineAt(r),n=i.toi.from;r--)if(this.boundary.test(i.text[r-1-i.from])){a=r;break}for(;oc.push(i.range(e,t));if(i==n)for(this.regexp.lastIndex=a-i.from;(h=this.regexp.exec(i.text))&&h.indexthis.addMatch(i,e,t,d)));t=t.update({filterFrom:a,filterTo:l,filter:(e,t)=>el,add:c})}}return t}}const pr=null!=/x/.unicode?"gu":"g",fr=new RegExp("[\0-\b\n--ŸÂ؜​‎â€\u2028\u2029â€â€®â¦â§â©\ufeff-]",pr),mr={0:"null",7:"bell",8:"backspace",10:"newline",11:"vertical tab",13:"carriage return",27:"escape",8203:"zero width space",8204:"zero width non-joiner",8205:"zero width joiner",8206:"left-to-right mark",8207:"right-to-left mark",8232:"line separator",8237:"left-to-right override",8238:"right-to-left override",8294:"left-to-right isolate",8295:"right-to-left isolate",8297:"pop directional isolate",8233:"paragraph separator",65279:"zero width no-break space",65532:"object replacement"};let gr=null;const vr=q.define({combine(e){let t=be(e,{render:null,specialChars:fr,addSpecialChars:null});return(t.replaceTabs=!function(){var e;if(null==gr&&"undefined"!=typeof document&&document.body){let t=document.body.style;gr=null!=(null!==(e=t.tabSize)&&void 0!==e?e:t.MozTabSize)}return gr||!1}())&&(t.specialChars=new RegExp("\t|"+t.specialChars.source,pr)),t.addSpecialChars&&(t.specialChars=new RegExp(t.specialChars.source+"|"+t.addSpecialChars.source,pr)),t}});function Or(e={}){return[vr.of(e),br||(br=bi.fromClass(class{constructor(e){this.view=e,this.decorations=Yt.none,this.decorationCache=Object.create(null),this.decorator=this.makeDecorator(e.state.facet(vr)),this.decorations=this.decorator.createDeco(e)}makeDecorator(e){return new ur({regexp:e.specialChars,decoration:(t,i,n)=>{let{doc:s}=i.state,r=O(t[0],0);if(9==r){let e=s.lineAt(n),t=i.state.tabSize,r=Le(e.text,t,n-e.from);return Yt.replace({widget:new yr((t-r%t)*this.view.defaultCharacterWidth/this.view.scaleX)})}return this.decorationCache[r]||(this.decorationCache[r]=Yt.replace({widget:new _r(e,r)}))},boundary:e.replaceTabs?void 0:/[^]/})}update(e){let t=e.state.facet(vr);e.startState.facet(vr)!=t?(this.decorator=this.makeDecorator(t),this.decorations=this.decorator.createDeco(e.view)):this.decorations=this.decorator.updateDeco(e,this.decorations)}},{decorations:e=>e.decorations}))]}let br=null;class _r extends Ht{constructor(e,t){super(),this.options=e,this.code=t}eq(e){return e.code==this.code}toDOM(e){let t=function(e){return e>=32?"•":10==e?"â¤":String.fromCharCode(9216+e)}(this.code),i=e.state.phrase("Control character")+" "+(mr[this.code]||"0x"+this.code.toString(16)),n=this.options.render&&this.options.render(this.code,i,t);if(n)return n;let s=document.createElement("span");return s.textContent=t,s.title=i,s.setAttribute("aria-label",i),s.className="cm-specialChar",s}ignoreEvent(){return!1}}class yr extends Ht{constructor(e){super(),this.width=e}eq(e){return e.width==this.width}toDOM(){let e=document.createElement("span");return e.textContent="\t",e.className="cm-tab",e.style.width=this.width+"px",e}ignoreEvent(){return!1}}const wr=Yt.line({class:"cm-activeLine"}),xr=bi.fromClass(class{constructor(e){this.decorations=this.getDeco(e)}update(e){(e.docChanged||e.selectionSet)&&(this.decorations=this.getDeco(e.view))}getDeco(e){let t=-1,i=[];for(let n of e.state.selection.ranges){let s=e.lineBlockAt(n.head);s.from>t&&(i.push(wr.range(s.from)),t=s.from)}return Yt.set(i)}},{decorations:e=>e.decorations}),Sr=2e3;function kr(e,t){let i=e.posAtCoords({x:t.clientX,y:t.clientY},!1),n=e.state.doc.lineAt(i),s=i-n.from,r=s>Sr?-1:s==n.length?function(e,t){let i=e.coordsAtPos(e.viewport.from);return i?Math.round(Math.abs((i.left-t)/e.defaultCharacterWidth)):-1}(e,t.clientX):Le(n.text,e.state.tabSize,i-n.from);return{line:n.number,col:r,off:s}}function Tr(e){let t=(null==e?void 0:e.eventFilter)||(e=>e.altKey&&0==e.button);return Ds.mouseSelectionStyle.of(((e,i)=>t(i)?function(e,t){let i=kr(e,t),n=e.state.selection;return i?{update(e){if(e.docChanged){let t=e.changes.mapPos(e.startState.doc.line(i.line).from),s=e.state.doc.lineAt(t);i={line:s.number,col:i.col,off:Math.min(i.off,s.length)},n=n.map(e.changes)}},get(t,s,r){let o=kr(e,t);if(!o)return n;let a=function(e,t,i){let n=Math.min(t.line,i.line),s=Math.max(t.line,i.line),r=[];if(t.off>Sr||i.off>Sr||t.col<0||i.col<0){let o=Math.min(t.off,i.off),a=Math.max(t.off,i.off);for(let t=n;t<=s;t++){let i=e.doc.line(t);i.length<=a&&r.push(R.range(i.from+o,i.to+a))}}else{let o=Math.min(t.col,i.col),a=Math.max(t.col,i.col);for(let t=n;t<=s;t++){let i=e.doc.line(t),n=Ne(i.text,o,e.tabSize,!0);if(n<0)r.push(R.cursor(i.to));else{let t=Ne(i.text,a,e.tabSize);r.push(R.range(i.from+n,i.from+t))}}}return r}(e.state,i,o);return a.length?r?R.create(a.concat(n.ranges)):R.create(a):n}}:null}(e,i):null))}const Cr={Alt:[18,e=>!!e.altKey],Control:[17,e=>!!e.ctrlKey],Shift:[16,e=>!!e.shiftKey],Meta:[91,e=>!!e.metaKey]},Pr={style:"cursor: crosshair"};function Mr(e={}){let[t,i]=Cr[e.key||"Alt"],n=bi.fromClass(class{constructor(e){this.view=e,this.isDown=!1}set(e){this.isDown!=e&&(this.isDown=e,this.view.update([]))}},{eventObservers:{keydown(e){this.set(e.keyCode==t||i(e))},keyup(e){e.keyCode!=t&&i(e)||this.set(!1)},mousemove(e){this.set(i(e))}}});return[n,Ds.contentAttributes.of((e=>{var t;return(null===(t=e.plugin(n))||void 0===t?void 0:t.isDown)?Pr:null}))]}const Er="-10000px";class Ar{constructor(e,t,i){this.facet=t,this.createTooltipView=i,this.input=e.state.facet(t),this.tooltips=this.input.filter((e=>e)),this.tooltipViews=this.tooltips.map(i)}update(e,t){var i;let n=e.state.facet(this.facet),s=n.filter((e=>e));if(n===this.input){for(let t of this.tooltipViews)t.update&&t.update(e);return!1}let r=[],o=t?[]:null;for(let i=0;it[i]=e)),t.length=o.length),this.input=n,this.tooltips=s,this.tooltipViews=r,!0}}function Rr(e){let{win:t}=e;return{top:0,left:0,bottom:t.innerHeight,right:t.innerWidth}}const Dr=q.define({combine:e=>{var t,i,n;return{position:Rt.ios?"absolute":(null===(t=e.find((e=>e.position)))||void 0===t?void 0:t.position)||"fixed",parent:(null===(i=e.find((e=>e.parent)))||void 0===i?void 0:i.parent)||null,tooltipSpace:(null===(n=e.find((e=>e.tooltipSpace)))||void 0===n?void 0:n.tooltipSpace)||Rr}}}),Ir=new WeakMap,qr=bi.fromClass(class{constructor(e){this.view=e,this.above=[],this.inView=!0,this.madeAbsolute=!1,this.lastTransaction=0,this.measureTimeout=-1;let t=e.state.facet(Dr);this.position=t.position,this.parent=t.parent,this.classes=e.themeClasses,this.createContainer(),this.measureReq={read:this.readMeasure.bind(this),write:this.writeMeasure.bind(this),key:this},this.manager=new Ar(e,Br,(e=>this.createTooltip(e))),this.intersectionObserver="function"==typeof IntersectionObserver?new IntersectionObserver((e=>{Date.now()>this.lastTransaction-50&&e.length>0&&e[e.length-1].intersectionRatio<1&&this.measureSoon()}),{threshold:[1]}):null,this.observeIntersection(),e.win.addEventListener("resize",this.measureSoon=this.measureSoon.bind(this)),this.maybeMeasure()}createContainer(){this.parent?(this.container=document.createElement("div"),this.container.style.position="relative",this.container.className=this.view.themeClasses,this.parent.appendChild(this.container)):this.container=this.view.dom}observeIntersection(){if(this.intersectionObserver){this.intersectionObserver.disconnect();for(let e of this.manager.tooltipViews)this.intersectionObserver.observe(e.dom)}}measureSoon(){this.measureTimeout<0&&(this.measureTimeout=setTimeout((()=>{this.measureTimeout=-1,this.maybeMeasure()}),50))}update(e){e.transactions.length&&(this.lastTransaction=Date.now());let t=this.manager.update(e,this.above);t&&this.observeIntersection();let i=t||e.geometryChanged,n=e.state.facet(Dr);if(n.position!=this.position&&!this.madeAbsolute){this.position=n.position;for(let e of this.manager.tooltipViews)e.dom.style.position=this.position;i=!0}if(n.parent!=this.parent){this.parent&&this.container.remove(),this.parent=n.parent,this.createContainer();for(let e of this.manager.tooltipViews)this.container.appendChild(e.dom);i=!0}else this.parent&&this.view.themeClasses!=this.classes&&(this.classes=this.container.className=this.view.themeClasses);i&&this.maybeMeasure()}createTooltip(e){let t=e.create(this.view);if(t.dom.classList.add("cm-tooltip"),e.arrow&&!t.dom.querySelector(".cm-tooltip > .cm-tooltip-arrow")){let e=document.createElement("div");e.className="cm-tooltip-arrow",t.dom.appendChild(e)}return t.dom.style.position=this.position,t.dom.style.top=Er,t.dom.style.left="0px",this.container.appendChild(t.dom),t.mount&&t.mount(this.view),t}destroy(){var e,t;this.view.win.removeEventListener("resize",this.measureSoon);for(let t of this.manager.tooltipViews)t.dom.remove(),null===(e=t.destroy)||void 0===e||e.call(t);this.parent&&this.container.remove(),null===(t=this.intersectionObserver)||void 0===t||t.disconnect(),clearTimeout(this.measureTimeout)}readMeasure(){let e=this.view.dom.getBoundingClientRect(),t=1,i=1,n=!1;if("fixed"==this.position&&this.manager.tooltipViews.length){let{dom:e}=this.manager.tooltipViews[0];if(Rt.gecko)n=e.offsetParent!=this.container.ownerDocument.body;else if(1!=this.view.scaleX||1!=this.view.scaleY)n=!0;else if(e.style.top==Er&&"0px"==e.style.left){let t=e.getBoundingClientRect();n=Math.abs(t.top+1e4)>1||Math.abs(t.left)>1}}if(n||"absolute"==this.position)if(this.parent){let e=this.parent.getBoundingClientRect();e.width&&e.height&&(t=e.width/this.parent.offsetWidth,i=e.height/this.parent.offsetHeight)}else({scaleX:t,scaleY:i}=this.view.viewState);return{editor:e,parent:this.parent?this.container.getBoundingClientRect():e,pos:this.manager.tooltips.map(((e,t)=>{let i=this.manager.tooltipViews[t];return i.getCoords?i.getCoords(e.pos):this.view.coordsAtPos(e.pos)})),size:this.manager.tooltipViews.map((({dom:e})=>e.getBoundingClientRect())),space:this.view.state.facet(Dr).tooltipSpace(this.view),scaleX:t,scaleY:i,makeAbsolute:n}}writeMeasure(e){var t;if(e.makeAbsolute){this.madeAbsolute=!0,this.position="absolute";for(let e of this.manager.tooltipViews)e.dom.style.position="absolute"}let{editor:i,space:n,scaleX:s,scaleY:r}=e,o=[];for(let a=0;a=Math.min(i.bottom,n.bottom)||d.rightMath.min(i.right,n.right)+.1){c.style.top=Er;continue}let p=l.arrow?h.dom.querySelector(".cm-tooltip-arrow"):null,f=p?7:0,m=u.right-u.left,g=null!==(t=Ir.get(h))&&void 0!==t?t:u.bottom-u.top,v=h.offset||Nr,O=this.view.textDirection==Ri.LTR,b=u.width>n.right-n.left?O?n.left:n.right-u.width:O?Math.min(d.left-(p?14:0)+v.x,n.right-m):Math.max(n.left,d.left-m+(p?14:0)-v.x),_=this.above[a];!l.strictSide&&(_?d.top-(u.bottom-u.top)-v.yn.bottom)&&_==n.bottom-d.bottom>d.top-n.top&&(_=this.above[a]=!_);let y=(_?d.top-n.top:n.bottom-d.bottom)-f;if(yb&&e.topw&&(w=_?e.top-g-2-f:e.bottom+f+2);if("absolute"==this.position?(c.style.top=(w-e.parent.top)/r+"px",c.style.left=(b-e.parent.left)/s+"px"):(c.style.top=w/r+"px",c.style.left=b/s+"px"),p){let e=d.left+(O?v.x:-v.x)-(b+14-7);p.style.left=e/s+"px"}!0!==h.overlap&&o.push({left:b,top:w,right:x,bottom:w+g}),c.classList.toggle("cm-tooltip-above",_),c.classList.toggle("cm-tooltip-below",!_),h.positioned&&h.positioned(e.space)}}maybeMeasure(){if(this.manager.tooltips.length&&(this.view.inView&&this.view.requestMeasure(this.measureReq),this.inView!=this.view.inView&&(this.inView=this.view.inView,!this.inView)))for(let e of this.manager.tooltipViews)e.dom.style.top=Er}},{eventObservers:{scroll(){this.maybeMeasure()}}}),Lr=Ds.baseTheme({".cm-tooltip":{zIndex:100,boxSizing:"border-box"},"&light .cm-tooltip":{border:"1px solid #bbb",backgroundColor:"#f5f5f5"},"&light .cm-tooltip-section:not(:first-child)":{borderTop:"1px solid #bbb"},"&dark .cm-tooltip":{backgroundColor:"#333338",color:"white"},".cm-tooltip-arrow":{height:"7px",width:"14px",position:"absolute",zIndex:-1,overflow:"hidden","&:before, &:after":{content:"''",position:"absolute",width:0,height:0,borderLeft:"7px solid transparent",borderRight:"7px solid transparent"},".cm-tooltip-above &":{bottom:"-7px","&:before":{borderTop:"7px solid #bbb"},"&:after":{borderTop:"7px solid #f5f5f5",bottom:"1px"}},".cm-tooltip-below &":{top:"-7px","&:before":{borderBottom:"7px solid #bbb"},"&:after":{borderBottom:"7px solid #f5f5f5",top:"1px"}}},"&dark .cm-tooltip .cm-tooltip-arrow":{"&:before":{borderTopColor:"#333338",borderBottomColor:"#333338"},"&:after":{borderTopColor:"transparent",borderBottomColor:"transparent"}}}),Nr={x:0,y:0},Br=q.define({enables:[qr,Lr]}),$r=q.define();class Qr{static create(e){return new Qr(e)}constructor(e){this.view=e,this.mounted=!1,this.dom=document.createElement("div"),this.dom.classList.add("cm-tooltip-hover"),this.manager=new Ar(e,$r,(e=>this.createHostedView(e)))}createHostedView(e){let t=e.create(this.view);return t.dom.classList.add("cm-tooltip-section"),this.dom.appendChild(t.dom),this.mounted&&t.mount&&t.mount(this.view),t}mount(e){for(let t of this.manager.tooltipViews)t.mount&&t.mount(e);this.mounted=!0}positioned(e){for(let t of this.manager.tooltipViews)t.positioned&&t.positioned(e)}update(e){this.manager.update(e)}destroy(){var e;for(let t of this.manager.tooltipViews)null===(e=t.destroy)||void 0===e||e.call(t)}passProp(e){let t;for(let i of this.manager.tooltipViews){let n=i[e];if(void 0!==n)if(void 0===t)t=n;else if(t!==n)return}return t}get offset(){return this.passProp("offset")}get getCoords(){return this.passProp("getCoords")}get overlap(){return this.passProp("overlap")}get resize(){return this.passProp("resize")}}const zr=Br.compute([$r],(e=>{let t=e.facet($r).filter((e=>e));return 0===t.length?null:{pos:Math.min(...t.map((e=>e.pos))),end:Math.max(...t.filter((e=>null!=e.end)).map((e=>e.end))),create:Qr.create,above:t[0].above,arrow:t.some((e=>e.arrow))}}));class jr{constructor(e,t,i,n,s){this.view=e,this.source=t,this.field=i,this.setHover=n,this.hoverTime=s,this.hoverTimeout=-1,this.restartTimeout=-1,this.pending=null,this.lastMove={x:0,y:0,target:e.dom,time:0},this.checkHover=this.checkHover.bind(this),e.dom.addEventListener("mouseleave",this.mouseleave=this.mouseleave.bind(this)),e.dom.addEventListener("mousemove",this.mousemove=this.mousemove.bind(this))}update(){this.pending&&(this.pending=null,clearTimeout(this.restartTimeout),this.restartTimeout=setTimeout((()=>this.startHover()),20))}get active(){return this.view.state.field(this.field)}checkHover(){if(this.hoverTimeout=-1,this.active)return;let e=Date.now()-this.lastMove.time;ei.bottom||t.xi.right+e.defaultCharacterWidth)return;let r=e.bidiSpans(e.state.doc.lineAt(n)).find((e=>e.from<=n&&e.to>=n)),o=r&&r.dir==Ri.RTL?-1:1;s=t.x{this.pending==t&&(this.pending=null,i&&e.dispatch({effects:this.setHover.of(i)}))}),(t=>mi(e.state,t,"hover tooltip")))}else r&&e.dispatch({effects:this.setHover.of(r)})}mousemove(e){var t;this.lastMove={x:e.clientX,y:e.clientY,target:e.target,time:Date.now()},this.hoverTimeout<0&&(this.hoverTimeout=setTimeout(this.checkHover,this.hoverTime));let i=this.active;if(i&&!Wr(this.lastMove.target)||this.pending){let{pos:n}=i||this.pending,s=null!==(t=null==i?void 0:i.end)&&void 0!==t?t:n;(n==s?this.view.posAtCoords(this.lastMove)==n:function(e,t,i,n,s,r){let o=e.scrollDOM.getBoundingClientRect(),a=e.documentTop+e.documentPadding.top+e.contentHeight;if(o.left>n||o.rights||Math.min(o.bottom,a)=t&&l<=i}(this.view,n,s,e.clientX,e.clientY))||(this.view.dispatch({effects:this.setHover.of(null)}),this.pending=null)}}mouseleave(e){clearTimeout(this.hoverTimeout),this.hoverTimeout=-1,this.active&&!Wr(e.relatedTarget)&&this.view.dispatch({effects:this.setHover.of(null)})}destroy(){clearTimeout(this.hoverTimeout),this.view.dom.removeEventListener("mouseleave",this.mouseleave),this.view.dom.removeEventListener("mousemove",this.mousemove)}}function Wr(e){for(let t=e;t;t=t.parentNode)if(1==t.nodeType&&t.classList.contains("cm-tooltip"))return!0;return!1}function Vr(e,t={}){let i=ae.define(),n=j.define({create:()=>null,update(e,n){if(e&&(t.hideOnChange&&(n.docChanged||n.selection)||t.hideOn&&t.hideOn(n,e)))return null;if(e&&n.docChanged){let t=n.changes.mapPos(e.pos,-1,w.TrackDel);if(null==t)return null;let i=Object.assign(Object.create(null),e);i.pos=t,null!=e.end&&(i.end=n.changes.mapPos(e.end)),e=i}for(let t of n.effects)t.is(i)&&(e=t.value),t.is(Fr)&&(e=null);return e},provide:e=>$r.from(e)});return[n,bi.define((s=>new jr(s,e,n,i,t.hoverTime||300))),zr]}function Ur(e,t){let i=e.plugin(qr);if(!i)return null;let n=i.manager.tooltips.indexOf(t);return n<0?null:i.manager.tooltipViews[n]}const Fr=ae.define(),Hr=q.define({combine(e){let t,i;for(let n of e)t=t||n.topContainer,i=i||n.bottomContainer;return{topContainer:t,bottomContainer:i}}});function Xr(e,t){let i=e.plugin(Yr),n=i?i.specs.indexOf(t):-1;return n>-1?i.panels[n]:null}const Yr=bi.fromClass(class{constructor(e){this.input=e.state.facet(Kr),this.specs=this.input.filter((e=>e)),this.panels=this.specs.map((t=>t(e)));let t=e.state.facet(Hr);this.top=new Gr(e,!0,t.topContainer),this.bottom=new Gr(e,!1,t.bottomContainer),this.top.sync(this.panels.filter((e=>e.top))),this.bottom.sync(this.panels.filter((e=>!e.top)));for(let e of this.panels)e.dom.classList.add("cm-panel"),e.mount&&e.mount()}update(e){let t=e.state.facet(Hr);this.top.container!=t.topContainer&&(this.top.sync([]),this.top=new Gr(e.view,!0,t.topContainer)),this.bottom.container!=t.bottomContainer&&(this.bottom.sync([]),this.bottom=new Gr(e.view,!1,t.bottomContainer)),this.top.syncClasses(),this.bottom.syncClasses();let i=e.state.facet(Kr);if(i!=this.input){let t=i.filter((e=>e)),n=[],s=[],r=[],o=[];for(let i of t){let t,a=this.specs.indexOf(i);a<0?(t=i(e.view),o.push(t)):(t=this.panels[a],t.update&&t.update(e)),n.push(t),(t.top?s:r).push(t)}this.specs=t,this.panels=n,this.top.sync(s),this.bottom.sync(r);for(let e of o)e.dom.classList.add("cm-panel"),e.mount&&e.mount()}else for(let t of this.panels)t.update&&t.update(e)}destroy(){this.top.sync([]),this.bottom.sync([])}},{provide:e=>Ds.scrollMargins.of((t=>{let i=t.plugin(e);return i&&{top:i.top.scrollMargin(),bottom:i.bottom.scrollMargin()}}))});class Gr{constructor(e,t,i){this.view=e,this.top=t,this.container=i,this.dom=void 0,this.classes="",this.panels=[],this.syncClasses()}sync(e){for(let t of this.panels)t.destroy&&e.indexOf(t)<0&&t.destroy();this.panels=e,this.syncDOM()}syncDOM(){if(0==this.panels.length)return void(this.dom&&(this.dom.remove(),this.dom=void 0));if(!this.dom){this.dom=document.createElement("div"),this.dom.className=this.top?"cm-panels cm-panels-top":"cm-panels cm-panels-bottom",this.dom.style[this.top?"top":"bottom"]="0";let e=this.container||this.view.dom;e.insertBefore(this.dom,this.top?e.firstChild:null)}let e=this.dom.firstChild;for(let t of this.panels)if(t.dom.parentNode==this.dom){for(;e!=t.dom;)e=Zr(e);e=e.nextSibling}else this.dom.insertBefore(t.dom,e);for(;e;)e=Zr(e)}scrollMargin(){return!this.dom||this.container?0:Math.max(0,this.top?this.dom.getBoundingClientRect().bottom-Math.max(0,this.view.scrollDOM.getBoundingClientRect().top):Math.min(innerHeight,this.view.scrollDOM.getBoundingClientRect().bottom)-this.dom.getBoundingClientRect().top)}syncClasses(){if(this.container&&this.classes!=this.view.themeClasses){for(let e of this.classes.split(" "))e&&this.container.classList.remove(e);for(let e of(this.classes=this.view.themeClasses).split(" "))e&&this.container.classList.add(e)}}}function Zr(e){let t=e.nextSibling;return e.remove(),t}const Kr=q.define({enables:Yr});class Jr extends _e{compare(e){return this==e||this.constructor==e.constructor&&this.eq(e)}eq(e){return!1}destroy(e){}}Jr.prototype.elementClass="",Jr.prototype.toDOM=void 0,Jr.prototype.mapMode=w.TrackBefore,Jr.prototype.startSide=Jr.prototype.endSide=-1,Jr.prototype.point=!0;const eo=q.define(),to={class:"",renderEmptyElements:!1,elementStyle:"",markers:()=>Se.empty,lineMarker:()=>null,widgetMarker:()=>null,lineMarkerChange:null,initialSpacer:null,updateSpacer:null,domEventHandlers:{}},io=q.define();function no(e){return[ro(),io.of(Object.assign(Object.assign({},to),e))]}const so=q.define({combine:e=>e.some((e=>e))});function ro(e){let t=[oo];return e&&!1===e.fixed&&t.push(so.of(!0)),t}const oo=bi.fromClass(class{constructor(e){this.view=e,this.prevViewport=e.viewport,this.dom=document.createElement("div"),this.dom.className="cm-gutters",this.dom.setAttribute("aria-hidden","true"),this.dom.style.minHeight=this.view.contentHeight/this.view.scaleY+"px",this.gutters=e.state.facet(io).map((t=>new co(e,t)));for(let e of this.gutters)this.dom.appendChild(e.dom);this.fixed=!e.state.facet(so),this.fixed&&(this.dom.style.position="sticky"),this.syncGutters(!1),e.scrollDOM.insertBefore(this.dom,e.contentDOM)}update(e){if(this.updateGutters(e)){let t=this.prevViewport,i=e.view.viewport,n=Math.min(t.to,i.to)-Math.max(t.from,i.from);this.syncGutters(n<.8*(i.to-i.from))}e.geometryChanged&&(this.dom.style.minHeight=this.view.contentHeight+"px"),this.view.state.facet(so)!=!this.fixed&&(this.fixed=!this.fixed,this.dom.style.position=this.fixed?"sticky":""),this.prevViewport=e.view.viewport}syncGutters(e){let t=this.dom.nextSibling;e&&this.dom.remove();let i=Se.iter(this.view.state.facet(eo),this.view.viewport.from),n=[],s=this.gutters.map((e=>new ho(e,this.view.viewport,-this.view.documentPadding.top)));for(let e of this.view.viewportLineBlocks)if(n.length&&(n=[]),Array.isArray(e.type)){let t=!0;for(let r of e.type)if(r.type==Xt.Text&&t){lo(i,n,r.from);for(let e of s)e.line(this.view,r,n);t=!1}else if(r.widget)for(let e of s)e.widget(this.view,r)}else if(e.type==Xt.Text){lo(i,n,e.from);for(let t of s)t.line(this.view,e,n)}else if(e.widget)for(let t of s)t.widget(this.view,e);for(let e of s)e.finish();e&&this.view.scrollDOM.insertBefore(this.dom,t)}updateGutters(e){let t=e.startState.facet(io),i=e.state.facet(io),n=e.docChanged||e.heightChanged||e.viewportChanged||!Se.eq(e.startState.facet(eo),e.state.facet(eo),e.view.viewport.from,e.view.viewport.to);if(t==i)for(let t of this.gutters)t.update(e)&&(n=!0);else{n=!0;let s=[];for(let n of i){let i=t.indexOf(n);i<0?s.push(new co(this.view,n)):(this.gutters[i].update(e),s.push(this.gutters[i]))}for(let e of this.gutters)e.dom.remove(),s.indexOf(e)<0&&e.destroy();for(let e of s)this.dom.appendChild(e.dom);this.gutters=s}return n}destroy(){for(let e of this.gutters)e.destroy();this.dom.remove()}},{provide:e=>Ds.scrollMargins.of((t=>{let i=t.plugin(e);return i&&0!=i.gutters.length&&i.fixed?t.textDirection==Ri.LTR?{left:i.dom.offsetWidth*t.scaleX}:{right:i.dom.offsetWidth*t.scaleX}:null}))});function ao(e){return Array.isArray(e)?e:[e]}function lo(e,t,i){for(;e.value&&e.from<=i;)e.from==i&&t.push(e.value),e.next()}class ho{constructor(e,t,i){this.gutter=e,this.height=i,this.i=0,this.cursor=Se.iter(e.markers,t.from)}addElement(e,t,i){let{gutter:n}=this,s=(t.top-this.height)/e.scaleY,r=t.height/e.scaleY;if(this.i==n.elements.length){let t=new uo(e,r,s,i);n.elements.push(t),n.dom.appendChild(t.dom)}else n.elements[this.i].update(e,r,s,i);this.height=t.bottom,this.i++}line(e,t,i){let n=[];lo(this.cursor,n,t.from),i.length&&(n=n.concat(i));let s=this.gutter.config.lineMarker(e,t,n);s&&n.unshift(s);let r=this.gutter;(0!=n.length||r.config.renderEmptyElements)&&this.addElement(e,t,n)}widget(e,t){let i=this.gutter.config.widgetMarker(e,t.widget,t);i&&this.addElement(e,t,[i])}finish(){let e=this.gutter;for(;e.elements.length>this.i;){let t=e.elements.pop();e.dom.removeChild(t.dom),t.destroy()}}}class co{constructor(e,t){this.view=e,this.config=t,this.elements=[],this.spacer=null,this.dom=document.createElement("div"),this.dom.className="cm-gutter"+(this.config.class?" "+this.config.class:"");for(let i in t.domEventHandlers)this.dom.addEventListener(i,(n=>{let s,r=n.target;if(r!=this.dom&&this.dom.contains(r)){for(;r.parentNode!=this.dom;)r=r.parentNode;let e=r.getBoundingClientRect();s=(e.top+e.bottom)/2}else s=n.clientY;let o=e.lineBlockAtHeight(s-e.documentTop);t.domEventHandlers[i](e,o,n)&&n.preventDefault()}));this.markers=ao(t.markers(e)),t.initialSpacer&&(this.spacer=new uo(e,0,0,[t.initialSpacer(e)]),this.dom.appendChild(this.spacer.dom),this.spacer.dom.style.cssText+="visibility: hidden; pointer-events: none")}update(e){let t=this.markers;if(this.markers=ao(this.config.markers(e.view)),this.spacer&&this.config.updateSpacer){let t=this.config.updateSpacer(this.spacer.markers[0],e);t!=this.spacer.markers[0]&&this.spacer.update(e.view,0,0,[t])}let i=e.view.viewport;return!Se.eq(this.markers,t,i.from,i.to)||!!this.config.lineMarkerChange&&this.config.lineMarkerChange(e)}destroy(){for(let e of this.elements)e.destroy()}}class uo{constructor(e,t,i,n){this.height=-1,this.above=0,this.markers=[],this.dom=document.createElement("div"),this.dom.className="cm-gutterElement",this.update(e,t,i,n)}update(e,t,i,n){this.height!=t&&(this.height=t,this.dom.style.height=t+"px"),this.above!=i&&(this.dom.style.marginTop=(this.above=i)?i+"px":""),function(e,t){if(e.length!=t.length)return!1;for(let i=0;ibe(e,{formatNumber:String,domEventHandlers:{}},{domEventHandlers(e,t){let i=Object.assign({},e);for(let e in t){let n=i[e],s=t[e];i[e]=n?(e,t,i)=>n(e,t,i)||s(e,t,i):s}return i}})});class mo extends Jr{constructor(e){super(),this.number=e}eq(e){return this.number==e.number}toDOM(){return document.createTextNode(this.number)}}function go(e,t){return e.state.facet(fo).formatNumber(t,e.state)}const vo=io.compute([fo],(e=>({class:"cm-lineNumbers",renderEmptyElements:!1,markers:e=>e.state.facet(po),lineMarker:(e,t,i)=>i.some((e=>e.toDOM))?null:new mo(go(e,e.state.doc.lineAt(t.from).number)),widgetMarker:()=>null,lineMarkerChange:e=>e.startState.facet(fo)!=e.state.facet(fo),initialSpacer:e=>new mo(go(e,bo(e.state.doc.lines))),updateSpacer(e,t){let i=go(t.view,bo(t.view.state.doc.lines));return i==e.number?e:new mo(i)},domEventHandlers:e.facet(fo).domEventHandlers})));function Oo(e={}){return[fo.of(e),ro(),vo]}function bo(e){let t=9;for(;t{let t=[],i=-1;for(let n of e.selection.ranges){let s=e.doc.lineAt(n.head).from;s>i&&(i=s,t.push(_o.range(s)))}return Se.of(t)})),wo=1024;let xo=0;class So{constructor(e,t){this.from=e,this.to=t}}class ko{constructor(e={}){this.id=xo++,this.perNode=!!e.perNode,this.deserialize=e.deserialize||(()=>{throw new Error("This node type doesn't define a deserialize function")})}add(e){if(this.perNode)throw new RangeError("Can't add per-node props to node types");return"function"!=typeof e&&(e=Po.match(e)),t=>{let i=e(t);return void 0===i?null:[this,i]}}}ko.closedBy=new ko({deserialize:e=>e.split(" ")}),ko.openedBy=new ko({deserialize:e=>e.split(" ")}),ko.group=new ko({deserialize:e=>e.split(" ")}),ko.contextHash=new ko({perNode:!0}),ko.lookAhead=new ko({perNode:!0}),ko.mounted=new ko({perNode:!0});class To{constructor(e,t,i){this.tree=e,this.overlay=t,this.parser=i}static get(e){return e&&e.props&&e.props[ko.mounted.id]}}const Co=Object.create(null);class Po{constructor(e,t,i,n=0){this.name=e,this.props=t,this.id=i,this.flags=n}static define(e){let t=e.props&&e.props.length?Object.create(null):Co,i=(e.top?1:0)|(e.skipped?2:0)|(e.error?4:0)|(null==e.name?8:0),n=new Po(e.name||"",t,e.id,i);if(e.props)for(let i of e.props)if(Array.isArray(i)||(i=i(n)),i){if(i[0].perNode)throw new RangeError("Can't store a per-node prop on a node type");t[i[0].id]=i[1]}return n}prop(e){return this.props[e.id]}get isTop(){return(1&this.flags)>0}get isSkipped(){return(2&this.flags)>0}get isError(){return(4&this.flags)>0}get isAnonymous(){return(8&this.flags)>0}is(e){if("string"==typeof e){if(this.name==e)return!0;let t=this.prop(ko.group);return!!t&&t.indexOf(e)>-1}return this.id==e}static match(e){let t=Object.create(null);for(let i in e)for(let n of i.split(" "))t[n]=e[i];return e=>{for(let i=e.prop(ko.group),n=-1;n<(i?i.length:0);n++){let s=t[n<0?e.name:i[n]];if(s)return s}}}}Po.none=new Po("",Object.create(null),0,8);class Mo{constructor(e){this.types=e;for(let t=0;t=t){let o=new $o(r.tree,r.overlay[0].from+e.from,0,null);(s||(s=[n])).push(No(o,t,i,!1))}}return s?Vo(s):n}(this,e,t)}iterate(e){let{enter:t,leave:i,from:n=0,to:s=this.length}=e,r=e.mode||0,o=(r&Ro.IncludeAnonymous)>0;for(let e=this.cursor(r|Ro.IncludeAnonymous);;){let r=!1;if(e.from<=s&&e.to>=n&&(!o&&e.type.isAnonymous||!1!==t(e))){if(e.firstChild())continue;r=!0}for(;r&&i&&(o||!e.type.isAnonymous)&&i(e),!e.nextSibling();){if(!e.parent())return;r=!0}}}prop(e){return e.perNode?this.props?this.props[e.id]:void 0:this.type.prop(e)}get propValues(){let e=[];if(this.props)for(let t in this.props)e.push([+t,this.props[t]]);return e}balance(e={}){return this.children.length<=8?this:Go(Po.none,this.children,this.positions,0,this.children.length,0,this.length,((e,t,i)=>new Do(this.type,e,t,i,this.propValues)),e.makeTree||((e,t,i)=>new Do(Po.none,e,t,i)))}static build(e){return function(e){var t;let{buffer:i,nodeSet:n,maxBufferLength:s=wo,reused:r=[],minRepeatType:o=n.types.length}=e,a=Array.isArray(i)?new Io(i,i.length):i,l=n.types,h=0,c=0;function d(e,t,i,m,g){let{id:v,start:O,end:b,size:_}=a,y=c;for(;_<0;){if(a.next(),-1==_){let t=r[v];return i.push(t),void m.push(O-e)}if(-3==_)return void(h=v);if(-4==_)return void(c=v);throw new RangeError(`Unrecognized record size: ${_}`)}let w,x,S=l[v],k=O-e;if(b-O<=s&&(x=function(e,t){let i=a.fork(),n=0,r=0,l=0,h=i.end-s,c={size:0,start:0,skip:0};e:for(let s=i.pos-e;i.pos>s;){let e=i.size;if(i.id==t&&e>=0){c.size=n,c.start=r,c.skip=l,l+=4,n+=4,i.next();continue}let a=i.pos-e;if(e<0||a=o?4:0,u=i.start;for(i.next();i.pos>a;){if(i.size<0){if(-3!=i.size)break e;d+=4}else i.id>=o&&(d+=4);i.next()}r=u,n+=e,l+=d}return(t<0||n==e)&&(c.size=n,c.start=r,c.skip=l),c.size>4?c:void 0}(a.pos-t,g))){let t=new Uint16Array(x.size-x.skip),i=a.pos-x.size,s=t.length;for(;a.pos>i;)s=f(x.start,t,s);w=new qo(t,b-x.start,n),k=x.start-e}else{let e=a.pos-_;a.next();let t=[],i=[],n=v>=o?v:-1,r=0,l=b;for(;a.pos>e;)n>=0&&a.id==n&&a.size>=0?(a.end<=l-s&&(u(t,i,O,r,a.end,l,n,y),r=t.length,l=a.end),a.next()):d(O,e,t,i,n);if(n>=0&&r>0&&r-1&&r>0){let e=function(e){return(t,i,n)=>{let s,r,o=0,a=t.length-1;if(a>=0&&(s=t[a])instanceof Do){if(!a&&s.type==e&&s.length==n)return s;(r=s.prop(ko.lookAhead))&&(o=i[a]+s.length+r)}return p(e,t,i,n,o)}}(S);w=Go(S,t,i,0,t.length,0,b-O,e,e)}else w=p(S,t,i,b-O,y-b)}i.push(w),m.push(k)}function u(e,t,i,s,r,o,a,l){let h=[],c=[];for(;e.length>s;)h.push(e.pop()),c.push(t.pop()+i-r);e.push(p(n.types[a],h,c,o-r,l-o)),t.push(r-i)}function p(e,t,i,n,s=0,r){if(h){let e=[ko.contextHash,h];r=r?[e].concat(r):[e]}if(s>25){let e=[ko.lookAhead,s];r=r?[e].concat(r):[e]}return new Do(e,t,i,n,r)}function f(e,t,i){let{id:n,start:s,end:r,size:l}=a;if(a.next(),l>=0&&n4){let n=a.pos-(l-4);for(;a.pos>n;)i=f(e,t,i)}t[--i]=o,t[--i]=r-e,t[--i]=s-e,t[--i]=n}else-3==l?h=n:-4==l&&(c=n);return i}let m=[],g=[];for(;a.pos>0;)d(e.start||0,e.bufferStart||0,m,g,-1);let v=null!==(t=e.length)&&void 0!==t?t:m.length?g[0]+m[0].length:0;return new Do(l[e.topID],m.reverse(),g.reverse(),v)}(e)}}Do.empty=new Do(Po.none,[],[],0);class Io{constructor(e,t){this.buffer=e,this.index=t}get id(){return this.buffer[this.index-4]}get start(){return this.buffer[this.index-3]}get end(){return this.buffer[this.index-2]}get size(){return this.buffer[this.index-1]}get pos(){return this.index}next(){this.index-=4}fork(){return new Io(this.buffer,this.index)}}class qo{constructor(e,t,i){this.buffer=e,this.length=t,this.set=i}get type(){return Po.none}toString(){let e=[];for(let t=0;t0));a=r[a+3]);return o}slice(e,t,i){let n=this.buffer,s=new Uint16Array(t-e),r=0;for(let o=e,a=0;o=t&⁢case 1:return i<=t&&n>t;case 2:return n>t;case 4:return!0}}function No(e,t,i,n){for(var s;e.from==e.to||(i<1?e.from>=t:e.from>t)||(i>-1?e.to<=t:e.to