l&&s.push(new Ne(l,f.from,d)),Le(e,f.direction==Se!=!(d%2)?r+1:r,i,f.inner,f.from,f.to,s),l=f.to}p=f.to}else{if(p==n||(t?Qe[p]!=a:Qe[p]==a))break;p++}h?Me(e,l,p,r+1,i,h,s):lt;){let n=!0,c=!1;if(!u||l>o[u-1].to){let e=Qe[l-1];e!=a&&(n=!1,c=16==e)}let h=n||1!=a?null:[],d=n?r:r+1,p=l;e:for(;;)if(u&&p==o[u-1].to){if(c)break e;let f=o[--u];if(!n)for(let e=f.from,n=u;;){if(e==t)break e;if(!n||o[n-1].to!=e){if(Qe[e-1]==a)break e;break}e=o[--n].from}if(h)h.push(f);else{f.to=0;e-=3)if(Pe[e+1]==-n){let t=Pe[e+2],n=2&t?i:4&t?1&t?o:i:0;n&&(Qe[s]=Qe[Pe[e]]=n),a=e;break}}else{if(189==Pe.length)break;Pe[a++]=s,Pe[a++]=t,Pe[a++]=l}else if(2==(r=Qe[s])||1==r){let e=r==i;l=e?0:1;for(let t=a-3;t>=0;t-=3){let n=Pe[t+2];if(2&n)break;if(e)Pe[t+2]|=2;else{if(4&n)break;Pe[t+2]|=4}}}}}(e,i,o,r,a),function(e,t,n,r){for(let i=0,o=r;i<=n.length;i++){let s=i?n[i-1].to:e,a=il;)t==o&&(t=n[--r].from,o=r?n[r-1].to:e),Qe[--t]=c;l=s}else o=s,l++}}}(i,o,r,a),Me(e,i,o,t,n,r,s)}function $e(e,t,n){if(!e)return[new Ne(0,0,t==xe?1:0)];if(t==Se&&!n.length&&!Re.test(e))return ze(e.length);if(n.length)for(;e.length>Qe.length;)Qe[Qe.length]=256;let r=[],i=t==Se?0:1;return Le(e,i,i,n,0,e.length,r),r}function ze(e){return[new Ne(0,e,0)]}let Ue="";function je(e,t,n,i,o){var s;let a=i.head-e.from,l=Ne.find(t,a,null!==(s=i.bidiLevel)&&void 0!==s?s:-1,i.assoc),u=t[l],c=u.side(o,n);if(a==c){let e=l+=o?1:-1;if(e<0||e>=t.length)return null;u=t[l=e],a=u.side(!o,n),c=u.side(o,n)}let h=(0,r.zK)(e.text,a,u.forward(o,n));(hu.to)&&(h=c),Ue=e.text.slice(Math.min(a,h),Math.max(a,h));let d=l==(o?t.length-1:0)?null:t[l+(o?1:-1)];return d&&h==c&&d.level+(o?0:1)e.some((e=>e))}),tt=r.sj.define({combine:e=>e.some((e=>e))}),nt=r.sj.define();class rt{constructor(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"nearest",n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"nearest",r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:5,i=arguments.length>4&&void 0!==arguments[4]?arguments[4]:5,o=arguments.length>5&&void 0!==arguments[5]&&arguments[5];this.range=e,this.y=t,this.x=n,this.yMargin=r,this.xMargin=i,this.isSnapshot=o}map(e){return e.empty?this:new rt(this.range.map(e),this.y,this.x,this.yMargin,this.xMargin,this.isSnapshot)}clip(e){return this.range.to<=e.doc.length?this:new rt(r.OF.cursor(e.doc.length),this.y,this.x,this.yMargin,this.xMargin,this.isSnapshot)}}const it=r.Pe.define({map:(e,t)=>e.map(t)}),ot=r.Pe.define();function st(e,t,n){let r=e.facet(Ye);r.length?r[0](t):window.onerror&&window.onerror(String(t),n,void 0,void 0,t)||(n?console.error(n+":",t):console.error(t))}const at=r.sj.define({combine:e=>!e.length||e[0]});let lt=0;const ut=r.sj.define();class ct{constructor(e,t,n,r,i){this.id=e,this.create=t,this.domEventHandlers=n,this.domEventObservers=r,this.extension=i(this)}static define(e,t){const{eventHandlers:n,eventObservers:r,provide:i,decorations:o}=t||{};return new ct(lt++,e,n,r,(e=>{let t=[ut.of(e)];return o&&t.push(ft.of((t=>{let n=t.plugin(e);return n?o(n):pe.none}))),i&&t.push(i(e)),t}))}static fromClass(e,t){return ct.define((t=>new e(t)),t)}}class ht{constructor(e){this.spec=e,this.mustUpdate=null,this.value=null}update(e){if(this.value){if(this.mustUpdate){let e=this.mustUpdate;if(this.mustUpdate=null,this.value.update)try{this.value.update(e)}catch(t){if(st(e.state,t,"CodeMirror plugin crashed"),this.value.destroy)try{this.value.destroy()}catch(n){}this.deactivate()}}}else if(this.spec)try{this.value=this.spec.create(e)}catch(t){st(e.state,t,"CodeMirror plugin crashed"),this.deactivate()}return this}destroy(e){var t;if(null===(t=this.value)||void 0===t?void 0:t.destroy)try{this.value.destroy()}catch(n){st(e.state,n,"CodeMirror plugin crashed")}}deactivate(){this.spec=this.value=null}}const dt=r.sj.define(),pt=r.sj.define(),ft=r.sj.define(),mt=r.sj.define(),gt=r.sj.define(),Ot=r.sj.define();function Dt(e,t){let n=e.state.facet(Ot);if(!n.length)return n;let i=n.map((t=>t instanceof Function?t(e):t)),o=[];return r.om.spans(i,t.from,t.to,{point(){},span(e,n,r,i){let s=e-t.from,a=n-t.from,l=o;for(let o=r.length-1;o>=0;o--,i--){let e,n=r[o].spec.bidiIsolate;if(null==n&&(n=qe(t.text,s,a)),i>0&&l.length&&(e=l[l.length-1]).to==s&&e.direction==n)e.to=a,l=e.inner;else{let e={from:s,to:a,direction:n,inner:[]};l.push(e),l=e.inner}}}}),o}const bt=r.sj.define();function yt(e){let t=0,n=0,r=0,i=0;for(let o of e.state.facet(bt)){let s=o(e);s&&(null!=s.left&&(t=Math.max(t,s.left)),null!=s.right&&(n=Math.max(n,s.right)),null!=s.top&&(r=Math.max(r,s.top)),null!=s.bottom&&(i=Math.max(i,s.bottom)))}return{left:t,right:n,top:r,bottom:i}}const vt=r.sj.define();class At{constructor(e,t,n,r){this.fromA=e,this.toA=t,this.fromB=n,this.toB=r}join(e){return new At(Math.min(this.fromA,e.fromA),Math.max(this.toA,e.toA),Math.min(this.fromB,e.fromB),Math.max(this.toB,e.toB))}addToSet(e){let t=e.length,n=this;for(;t>0;t--){let r=e[t-1];if(!(r.fromA>n.toA)){if(r.toAu)break;i+=2}if(!a)return n;new At(a.fromA,a.toA,a.fromB,a.toB).addToSet(n),o=a.toA,s=a.toB}}}class Et{constructor(e,t,n){this.view=e,this.state=t,this.transactions=n,this.flags=0,this.startState=e.state,this.changes=r.VR.empty(this.startState.doc.length);for(let r of n)this.changes=this.changes.compose(r.changes);let i=[];this.changes.iterChangedRanges(((e,t,n,r)=>i.push(new At(e,t,n,r)))),this.changedRanges=i}static create(e,t,n){return new Et(e,t,n)}get viewportChanged(){return(4&this.flags)>0}get viewportMoved(){return(8&this.flags)>0}get heightChanged(){return(2&this.flags)>0}get geometryChanged(){return this.docChanged||(18&this.flags)>0}get focusChanged(){return(1&this.flags)>0}get docChanged(){return!this.changes.empty}get selectionSet(){return this.transactions.some((e=>e.selection))}get empty(){return 0==this.flags&&0==this.transactions.length}}class Ct extends N{get length(){return this.view.state.doc.length}constructor(e){super(),this.view=e,this.decorations=[],this.dynamicDecorationMap=[!1],this.domChanged=null,this.hasComposition=null,this.markedForComposition=new Set,this.editContextFormatting=pe.none,this.lastCompositionAfterCursor=!1,this.minWidth=0,this.minWidthFrom=0,this.minWidthTo=0,this.impreciseAnchor=null,this.impreciseHead=null,this.forceSelection=!1,this.lastUpdate=Date.now(),this.setDOM(e.contentDOM),this.children=[new be],this.children[0].setParent(this),this.updateDeco(),this.updateInner([new At(0,0,0,e.state.doc.length)],0,null)}update(e){var t;let n=e.changedRanges;this.minWidth>0&&n.length&&(n.every((e=>{let{fromA:t,toA:n}=e;return nthis.minWidthTo}))?(this.minWidthFrom=e.changes.mapPos(this.minWidthFrom,1),this.minWidthTo=e.changes.mapPos(this.minWidthTo,1)):this.minWidth=this.minWidthFrom=this.minWidthTo=0),this.updateEditContextFormatting(e);let i=-1;this.view.inputState.composing>=0&&!this.view.observer.editContext&&((null===(t=this.domChanged)||void 0===t?void 0:t.newSel)?i=this.domChanged.newSel.head:function(e,t){let n=!1;t&&e.iterChangedRanges(((e,r)=>{et.from&&(n=!0)}));return n}(e.changes,this.hasComposition)||e.selectionSet||(i=e.state.selection.main.head));let o=i>-1?function(e,t,n){let r=kt(e,n);if(!r)return null;let{node:i,from:o,to:s}=r,a=i.nodeValue;if(/[\n\r]/.test(a))return null;if(e.state.doc.sliceString(r.from,r.to)!=a)return null;let l=t.invertedDesc,u=new At(l.mapPos(o),l.mapPos(s),o,s),c=[];for(let h=i.parentNode;;h=h.parentNode){let t=N.get(h);if(t instanceof J)c.push({node:h,deco:t.mark});else{if(t instanceof be||"DIV"==h.nodeName&&h.parentNode==e.contentDOM)return{range:u,text:i,marks:c,line:h};if(h==e.contentDOM)return null;c.push({node:h,deco:new fe({inclusive:!0,attributes:ce(h),tagName:h.tagName.toLowerCase()})})}}}(this.view,e.changes,i):null;if(this.domChanged=null,this.hasComposition){this.markedForComposition.clear();let{from:t,to:r}=this.hasComposition;n=new At(t,r,e.changes.mapPos(t,-1),e.changes.mapPos(r,1)).addToSet(n.slice())}this.hasComposition=o?{from:o.range.fromB,to:o.range.toB}:null,(W.ie||W.chrome)&&!o&&e&&e.state.doc.lines!=e.startState.doc.lines&&(this.forceSelection=!0);let s=function(e,t,n){let i=new St;return r.om.compare(e,t,n,i),i.changes}(this.decorations,this.updateDeco(),e.changes);return n=At.extendWithRanges(n,s),!!(7&this.flags||0!=n.length)&&(this.updateInner(n,e.startState.doc.length,o),e.transactions.length&&(this.lastUpdate=Date.now()),!0)}updateInner(e,t,n){this.view.viewState.mustMeasureContent=!0,this.updateChildren(e,t,n);let{observer:r}=this.view;r.ignore((()=>{this.dom.style.height=this.view.viewState.contentHeight/this.view.scaleY+"px",this.dom.style.flexBasis=this.minWidth?this.minWidth+"px":"";let e=W.chrome||W.ios?{node:r.selectionRange.focusNode,written:!1}:void 0;this.sync(this.view,e),this.flags&=-8,e&&(e.written||r.selectionRange.focusNode!=e.node)&&(this.forceSelection=!0),this.dom.style.height=""})),this.markedForComposition.forEach((e=>e.flags&=-9));let i=[];if(this.view.viewport.from||this.view.viewport.to=0?r[o]:null;if(!e)break;let t,s,a,l,{fromA:u,toA:c,fromB:h,toB:d}=e;if(n&&n.range.fromBh){let e=Ae.build(this.view.state.doc,h,n.range.fromB,this.decorations,this.dynamicDecorationMap),r=Ae.build(this.view.state.doc,n.range.toB,d,this.decorations,this.dynamicDecorationMap);s=e.breakAtStart,a=e.openStart,l=r.openEnd;let i=this.compositionView(n);r.breakAtStart?i.breakAfter=1:r.content.length&&i.merge(i.length,i.length,r.content[0],!1,r.openStart,0)&&(i.breakAfter=r.content[0].breakAfter,r.content.shift()),e.content.length&&i.merge(0,0,e.content[e.content.length-1],!0,0,e.openEnd)&&e.content.pop(),t=e.content.concat(i).concat(r.content)}else({content:t,breakAtStart:s,openStart:a,openEnd:l}=Ae.build(this.view.state.doc,h,d,this.decorations,this.dynamicDecorationMap));let{i:p,off:f}=i.findPos(c,1),{i:m,off:g}=i.findPos(u,-1);M(this,m,g,p,f,t,s,a,l)}n&&this.fixCompositionDOM(n)}updateEditContextFormatting(e){this.editContextFormatting=this.editContextFormatting.map(e.changes);for(let t of e.transactions)for(let e of t.effects)e.is(ot)&&(this.editContextFormatting=e.value)}compositionView(e){let t=new K(e.text.nodeValue);t.flags|=8;for(let{deco:r}of e.marks)t=new J(r,[t],t.length);let n=new be;return n.append(t,0),n}fixCompositionDOM(e){let t=(e,t)=>{t.flags|=8|(t.children.some((e=>7&e.flags))?1:0),this.markedForComposition.add(t);let n=N.get(e);n&&n!=t&&(n.dom=null),t.setDOM(e)},n=this.childPos(e.range.fromB,1),r=this.children[n.i];t(e.line,r);for(let i=e.marks.length-1;i>=-1;i--)n=r.childPos(n.off,1),r=r.children[n.i],t(i>=0?e.marks[i].node:e.text,r)}updateSelection(){let e=arguments.length>1&&void 0!==arguments[1]&&arguments[1];!(arguments.length>0&&void 0!==arguments[0]&&arguments[0])&&this.view.observer.selectionRange.focusNode||this.view.observer.readSelectionRange();let t=this.view.root.activeElement,n=t==this.dom,r=!n&&!(this.view.state.facet(at)||this.dom.tabIndex>-1)&&p(this.dom,this.view.observer.selectionRange)&&!(t&&this.dom.contains(t));if(!(n||e||r))return;let i=this.forceSelection;this.forceSelection=!1;let o=this.view.state.selection.main,s=this.moveToLine(this.domAtPos(o.anchor)),a=o.empty?s:this.moveToLine(this.domAtPos(o.head));if(W.gecko&&o.empty&&!this.hasComposition&&(1==(l=s).node.nodeType&&l.node.firstChild&&(0==l.offset||"false"==l.node.childNodes[l.offset-1].contentEditable)&&(l.offset==l.node.childNodes.length||"false"==l.node.childNodes[l.offset].contentEditable))){let e=document.createTextNode("");this.view.observer.ignore((()=>s.node.insertBefore(e,s.node.childNodes[s.offset]||null))),s=a=new B(e,0),i=!0}var l;let u=this.view.observer.selectionRange;!i&&u.focusNode&&(m(s.node,s.offset,u.anchorNode,u.anchorOffset)&&m(a.node,a.offset,u.focusNode,u.focusOffset)||this.suppressWidgetCursorChange(u,o))||(this.view.observer.ignore((()=>{W.android&&W.chrome&&this.dom.contains(u.focusNode)&&function(e,t){for(let n=e;n&&n!=t;n=n.assignedSlot||n.parentNode)if(1==n.nodeType&&"false"==n.contentEditable)return!0;return!1}(u.focusNode,this.dom)&&(this.dom.blur(),this.dom.focus({preventScroll:!0}));let e=h(this.view.root);if(e)if(o.empty){if(W.gecko){let e=(n=s.node,i=s.offset,1!=n.nodeType?0:(i&&"false"==n.childNodes[i-1].contentEditable?1:0)|(io.head&&([s,a]=[a,s]),t.setEnd(a.node,a.offset),t.setStart(s.node,s.offset),e.removeAllRanges(),e.addRange(t)}else;var n,i;r&&this.view.root.activeElement==this.dom&&(this.dom.blur(),t&&t.focus())})),this.view.observer.setSelectionRange(s,a)),this.impreciseAnchor=s.precise?null:new B(u.anchorNode,u.anchorOffset),this.impreciseHead=a.precise?null:new B(u.focusNode,u.focusOffset)}suppressWidgetCursorChange(e,t){return this.hasComposition&&t.empty&&m(e.focusNode,e.focusOffset,e.anchorNode,e.anchorOffset)&&this.posFromDOM(e.focusNode,e.focusOffset)==t.head}enforceCursorAssoc(){if(this.hasComposition)return;let{view:e}=this,t=e.state.selection.main,n=h(e.root),{anchorNode:r,anchorOffset:i}=e.observer.selectionRange;if(!n||!t.empty||!t.assoc||!n.modify)return;let o=be.find(this,t.head);if(!o)return;let s=o.posAtStart;if(t.head==s||t.head==s+o.length)return;let a=this.coordsAt(t.head,-1),l=this.coordsAt(t.head,1);if(!a||!l||a.bottom>l.top)return;let u=this.domAtPos(t.head+t.assoc);n.collapse(u.node,u.offset),n.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&&n.collapse(r,i)}moveToLine(e){let t,n=this.dom;if(e.node!=n)return e;for(let r=e.offset;!t&&r=0;r--){let e=N.get(n.childNodes[r]);e instanceof be&&(t=e.domAtPos(e.length))}return t?new B(t.node,t.offset,!0):e}nearest(e){for(let t=e;t;){let e=N.get(t);if(e&&e.rootView==this)return e;t=t.parentNode}return null}posFromDOM(e,t){let n=this.nearest(e);if(!n)throw new RangeError("Trying to find position for a DOM position outside of the document");return n.localPosFromDOM(e,t)+n.posAtStart}domAtPos(e){let{i:t,off:n}=this.childCursor().findPos(e,-1);for(;t=0;o--){let s=this.children[o],a=i-s.breakAfter,l=a-s.length;if(ae||s.covers(1))&&(!n||s instanceof be&&!(n instanceof be&&t>=0)))n=s,r=l;else if(n&&l==e&&a==e&&s instanceof ye&&Math.abs(t)<2){if(s.deco.startSide<0)break;o&&(n=null)}i=l}return n?n.coordsAt(e-r,t):null}coordsForChar(e){let{i:t,off:n}=this.childPos(e,1),i=this.children[t];if(!(i instanceof be))return null;for(;i.children.length;){let{i:e,off:t}=i.childPos(n,1);for(;;e++){if(e==i.children.length)return null;if((i=i.children[e]).length)break}n=t}if(!(i instanceof K))return null;let o=(0,r.zK)(i.text,n);if(o==n)return null;let s=x(i.dom,n,o).getClientRects();for(let r=0;rMath.max(this.view.scrollDOM.clientWidth,this.minWidth)+1,s=-1,a=this.view.textDirection==ke.LTR;for(let l=0,u=0;ur)break;if(l>=n){let n=e.dom.getBoundingClientRect();if(t.push(n.height),o){let t=e.dom.lastChild,r=t?f(t):[];if(r.length){let e=r[r.length-1],t=a?e.right-n.left:n.right-e.left;t>s&&(s=t,this.minWidth=i,this.minWidthFrom=l,this.minWidthTo=c)}}}l=c+e.breakAfter}return t}textDirectionAt(e){let{i:t}=this.childPos(e,1);return"rtl"==getComputedStyle(this.children[t].dom).direction?ke.RTL:ke.LTR}measureTextSize(){for(let i of this.children)if(i instanceof be){let e=i.measureTextSize();if(e)return e}let e,t,n,r=document.createElement("div");return r.className="cm-line",r.style.width="99999px",r.style.position="absolute",r.textContent="abc def ghi jkl mno pqr stu",this.view.observer.ignore((()=>{this.dom.appendChild(r);let i=f(r.firstChild)[0];e=r.getBoundingClientRect().height,t=i?i.width/27:7,n=i?i.height:e,r.remove()})),{lineHeight:e,charWidth:t,textHeight:n}}childCursor(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.length,t=this.children.length;return t&&(e-=this.children[--t].length),new Q(this.children,e,t)}computeBlockGapDeco(){let e=[],t=this.view.viewState;for(let n=0,r=0;;r++){let i=r==t.viewports.length?null:t.viewports[r],o=i?i.from-1:this.length;if(o>n){let r=(t.lineBlockAt(o).bottom-t.lineBlockAt(n).top)/this.view.scaleY;e.push(pe.replace({widget:new ve(r),block:!0,inclusive:!0,isBlockGap:!0}).range(n,o))}if(!i)break;n=i.to+1}return pe.set(e)}updateDeco(){let e=1,t=this.view.state.facet(ft).map((t=>(this.dynamicDecorationMap[e++]="function"==typeof t)?t(this.view):t)),n=!1,i=this.view.state.facet(mt).map(((e,t)=>{let r="function"==typeof e;return r&&(n=!0),r?e(this.view):e}));for(i.length&&(this.dynamicDecorationMap[e++]=n,t.push(r.om.join(i))),this.decorations=[this.editContextFormatting,...t,this.computeBlockGapDeco(),this.view.viewState.lineGapDeco];en.anchor?-1:1);if(!r)return;!n.empty&&(t=this.coordsAt(n.anchor,n.anchor>n.head?-1:1))&&(r={left:Math.min(r.left,t.left),top:Math.min(r.top,t.top),right:Math.max(r.right,t.right),bottom:Math.max(r.bottom,t.bottom)});let i=yt(this.view),o={left:r.left-i.left,top:r.top-i.top,right:r.right+i.right,bottom:r.bottom+i.bottom},{offsetWidth:s,offsetHeight:a}=this.view.scrollDOM;!function(e,t,n,r,i,o,s,a){let l=e.ownerDocument,u=l.defaultView||window;for(let c=e,h=!1;c&&!h;)if(1==c.nodeType){let e,d=c==l.body,p=1,f=1;if(d)e=v(u);else{if(/^(fixed|sticky)$/.test(getComputedStyle(c).position)&&(h=!0),c.scrollHeight<=c.clientHeight&&c.scrollWidth<=c.clientWidth){c=c.assignedSlot||c.parentNode;continue}let t=c.getBoundingClientRect();({scaleX:p,scaleY:f}=A(c,t)),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"==i)t.top0&&t.bottom>e.bottom+g&&(g=t.bottom-e.bottom+s)):t.bottom>e.bottom&&(g=t.bottom-e.bottom+s,n<0&&t.top-g0&&t.right>e.right+m&&(m=t.right-e.right+o)):t.right>e.right&&(m=t.right-e.right+o,n<0&&t.lefte.bottom||t.lefte.right)&&(t={left:Math.max(t.left,e.left),right:Math.min(t.right,e.right),top:Math.max(t.top,e.top),bottom:Math.min(t.bottom,e.bottom)}),c=c.assignedSlot||c.parentNode}else{if(11!=c.nodeType)break;c=c.host}}(this.view.scrollDOM,o,n.heade?t.left-e:Math.max(0,e-t.right)}function wt(e,t){return t.top>e?t.top-e:Math.max(0,e-t.bottom)}function Tt(e,t){return e.topt.top+1}function Ft(e,t){return te.bottom?{top:e.top,left:e.left,right:e.right,bottom:t}:e}function Pt(e,t,n){let r,i,o,s,a,l,u,c,h=!1;for(let p=e.firstChild;p;p=p.nextSibling){let e=f(p);for(let d=0;dg||s==g&&o>m){r=p,i=f,o=m,s=g;let a=g?n0?d0)}0==m?n>f.bottom&&(!u||u.bottomf.top)&&(l=p,c=f):u&&Tt(u,f)?u=_t(u,f.bottom):c&&Tt(c,f)&&(c=Ft(c,f.top))}}if(u&&u.bottom>=n?(r=a,i=u):c&&c.top<=n&&(r=l,i=c),!r)return{node:e,offset:0};let d=Math.max(i.left,Math.min(i.right,t));return 3==r.nodeType?Bt(r,d,n):h&&"false"!=r.contentEditable?Pt(r,d,n):{node:e,offset:Array.prototype.indexOf.call(e.childNodes,r)+(t>=(i.left+i.right)/2?1:0)}}function Bt(e,t,n){let r=e.nodeValue.length,i=-1,o=1e9,s=0;for(let a=0;an?u.top-n:n-u.bottom)-1;if(u.left-1<=t&&u.right+1>=t&&c=(u.left+u.right)/2,r=n;if(W.chrome||W.gecko){x(e,a).getBoundingClientRect().left==u.right&&(r=!n)}if(c<=0)return{node:e,offset:a+(r?1:0)};i=a+(r?1:0),o=c}}}return{node:e,offset:i>-1?i:s>0?e.nodeValue.length:0}}function Rt(e,t,n){let r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:-1;var i,o;let s,a=e.contentDOM.getBoundingClientRect(),l=a.top+e.viewState.paddingTop,{docHeight:u}=e.viewState,{x:c,y:h}=t,d=h-l;if(d<0)return 0;if(d>u)return e.state.doc.length;for(let b=e.viewState.heightOracle.textHeight/2,v=!1;s=e.elementAtHeight(d),s.type!=de.Text;)for(;d=r>0?s.bottom+b:s.top-b,!(d>=0&&d<=u);){if(v)return n?null:0;v=!0,r=-r}h=l+d;let p=s.from;if(pe.viewport.to)return e.viewport.to==e.state.doc.length?e.state.doc.length:n?null:Nt(e,a,s,c,h);let f=e.dom.ownerDocument,m=e.root.elementFromPoint?e.root:f,g=m.elementFromPoint(c,h);g&&!e.contentDOM.contains(g)&&(g=null),g||(c=Math.max(a.left+1,Math.min(a.right-1,c)),g=m.elementFromPoint(c,h),g&&!e.contentDOM.contains(g)&&(g=null));let O,D=-1;if(g&&0!=(null===(i=e.docView.nearest(g))||void 0===i?void 0:i.isEditable)){if(f.caretPositionFromPoint){let e=f.caretPositionFromPoint(c,h);e&&({offsetNode:O,offset:D}=e)}else if(f.caretRangeFromPoint){let t=f.caretRangeFromPoint(c,h);t&&(({startContainer:O,startOffset:D}=t),(!e.contentDOM.contains(O)||W.safari&&function(e,t,n){let r;if(3!=e.nodeType||t!=(r=e.nodeValue.length))return!1;for(let i=e.nextSibling;i;i=i.nextSibling)if(1!=i.nodeType||"BR"!=i.nodeName)return!1;return x(e,r-1,r).getBoundingClientRect().left>n}(O,D,c)||W.chrome&&function(e,t,n){if(0!=t)return!1;for(let i=e;;){let e=i.parentNode;if(!e||1!=e.nodeType||e.firstChild!=i)return!1;if(e.classList.contains("cm-line"))break;i=e}let r=1==e.nodeType?e.getBoundingClientRect():x(e,0,Math.max(e.nodeValue.length,1)).getBoundingClientRect();return n-r.left>5}(O,D,c))&&(O=void 0))}O&&(D=Math.min(b(O),D))}if(!O||!e.docView.dom.contains(O)){let t=be.find(e.docView,p);if(!t)return d>s.top+s.height/2?s.to:s.from;({node:O,offset:D}=Pt(t.dom,c,h))}let y=e.docView.nearest(O);if(!y)return null;if(y.isWidget&&1==(null===(o=y.dom)||void 0===o?void 0:o.nodeType)){let e=y.dom.getBoundingClientRect();return t.y1.5*e.defaultLineHeight){let t=e.viewState.heightOracle.textHeight;s+=Math.floor((o-n.top-.5*(e.defaultLineHeight-t))/t)*e.viewState.heightOracle.lineLength}let a=e.state.sliceDoc(n.from,n.to);return n.from+(0,r.kn)(a,s,e.state.tabSize)}function It(e,t,n){let r=e.lineBlockAt(t);if(Array.isArray(r.type)){let e;for(let i of r.type){if(i.from>t)break;if(!(i.tot)return i;e&&(i.type!=de.Text||e.type==i.type&&!(n<0?i.fromt))||(e=i)}}return e||r}return r}function Qt(e,t,n,r){let i=e.state.doc.lineAt(t.head),o=e.bidiSpans(i),s=e.textDirectionAt(i.from);for(let a=t,l=null;;){let t=je(i,o,s,a,n),u=Ue;if(!t){if(i.number==(n?e.state.doc.lines:1))return a;u="\n",i=e.state.doc.line(i.number+(n?1:-1)),o=e.bidiSpans(i),t=e.visualLineSide(i,!n)}if(l){if(!l(u))return a}else{if(!r)return t;l=r(u)}a=t}}function Mt(e,t,n){for(;;){let r=0;for(let i of e)i.between(t-1,t+1,((e,i,o)=>{if(t>e&&tt(e))),n.from,t.head>n.from?-1:1);return i==n.from?n:r.OF.cursor(i,ie)&&this.lineBreak(),r=i}return this.findPointBefore(n,t),this}readTextNode(e){let t=e.nodeValue;for(let n of this.points)n.node==e&&(n.pos=this.text.length+Math.min(n.offset,t.length));for(let n=0,r=this.lineSeparator?null:/\r\n?|\n/g;;){let i,o=-1,s=1;if(this.lineSeparator?(o=t.indexOf(this.lineSeparator,n),s=this.lineSeparator.length):(i=r.exec(t))&&(o=i.index,s=i[0].length),this.append(t.slice(n,o<0?t.length:o)),o<0)break;if(this.lineBreak(),s>1)for(let t of this.points)t.node==e&&t.pos>this.text.length&&(t.pos-=s-1);n=o+s}}readNode(e){if(e.cmIgnore)return;let t=N.get(e),n=t&&t.overrideDOMText;if(null!=n){this.findPointInside(e,n.length);for(let e=n.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 n of this.points)n.node==e&&e.childNodes[n.offset]==t&&(n.pos=this.text.length)}findPointInside(e,t){for(let n of this.points)(3==e.nodeType?n.node==e:e.contains(n.node))&&(n.pos=this.text.length+(Ut(e,n.node,n.offset)?t:0))}}function Ut(e,t,n){for(;;){if(!t||n-1;let{impreciseHead:o,impreciseAnchor:s}=e.docView;if(e.state.readOnly&&t>-1)this.newSel=null;else if(t>-1&&(this.bounds=e.docView.domBoundsAround(t,n,0))){let t=o||s?[]:function(e){let t=[];if(e.root.activeElement!=e.contentDOM)return t;let{anchorNode:n,anchorOffset:r,focusNode:i,focusOffset:o}=e.observer.selectionRange;n&&(t.push(new jt(n,r)),i==n&&o==r||t.push(new jt(i,o)));return t}(e),n=new zt(t,e.state);n.readRange(this.bounds.startDOM,this.bounds.endDOM),this.text=n.text,this.newSel=function(e,t){if(0==e.length)return null;let n=e[0].pos,i=2==e.length?e[1].pos:n;return n>-1&&i>-1?r.OF.single(n+t,i+t):null}(t,this.bounds.from)}else{let t=e.observer.selectionRange,n=o&&o.node==t.focusNode&&o.offset==t.focusOffset||!d(e.contentDOM,t.focusNode)?e.state.selection.main.head:e.docView.posFromDOM(t.focusNode,t.focusOffset),i=s&&s.node==t.anchorNode&&s.offset==t.anchorOffset||!d(e.contentDOM,t.anchorNode)?e.state.selection.main.anchor:e.docView.posFromDOM(t.anchorNode,t.anchorOffset),a=e.viewport;if((W.ios||W.chrome)&&e.state.selection.main.empty&&n!=i&&(a.from>0||a.toDate.now()-100?e.inputState.lastKeyCode:-1;if(t.bounds){let{from:i,to:a}=t.bounds,l=o.from,u=null;(8===s||W.android&&t.text.length0&&a>0&&e.charCodeAt(s-1)==t.charCodeAt(a-1);)s--,a--;if("end"==r){n-=s+Math.max(0,o-Math.min(s,a))-o}if(s=s?o-n:0,a=o+(a-s),s=o}else if(a=a?o-n:0,s=o+(s-a),a=o}return{from:o,toA:s,toB:a}}(e.state.doc.sliceString(i,a,$t),t.text,l-i,u);c&&(W.chrome&&13==s&&c.toB==c.from+2&&t.text.slice(c.from,c.toB)==$t+$t&&c.toB--,n={from:i+c.from,to:i+c.toA,insert:r.EY.of(t.text.slice(c.from,c.toB).split($t))})}else i&&(!e.hasFocus&&e.state.facet(at)||i.main.eq(o))&&(i=null);if(!n&&!i)return!1;if(!n&&t.typeOver&&!o.empty&&i&&i.main.empty?n={from:o.from,to:o.to,insert:e.state.doc.slice(o.from,o.to)}:(W.mac||W.android)&&n&&n.from==n.to&&n.from==o.head-1&&/^\. ?$/.test(n.insert.toString())&&"off"==e.contentDOM.getAttribute("autocorrect")?(i&&2==n.insert.length&&(i=r.OF.single(i.main.anchor-1,i.main.head-1)),n={from:n.from,to:n.to,insert:r.EY.of([n.insert.toString().replace("."," ")])}):n&&n.from>=o.from&&n.to<=o.to&&(n.from!=o.from||n.to!=o.to)&&o.to-o.from-(n.to-n.from)<=4?n={from:o.from,to:o.to,insert:e.state.doc.slice(o.from,n.from).append(n.insert).append(e.state.doc.slice(n.to,o.to))}:W.chrome&&n&&n.from==n.to&&n.from==o.head&&"\n "==n.insert.toString()&&e.lineWrapping&&(i&&(i=r.OF.single(i.main.anchor-1,i.main.head-1)),n={from:o.from,to:o.to,insert:r.EY.of([" "])}),n)return Zt(e,n,i,s);if(i&&!i.main.eq(o)){let t=!1,n="select";return e.inputState.lastSelectionTime>Date.now()-50&&("select"==e.inputState.lastSelectionOrigin&&(t=!0),n=e.inputState.lastSelectionOrigin),e.dispatch({selection:i,scrollIntoView:t,userEvent:n}),!0}return!1}function Zt(e,t,n){let i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:-1;if(W.ios&&e.inputState.flushIOSKey(t))return!0;let o=e.state.selection.main;if(W.android&&(t.to==o.to&&(t.from==o.from||t.from==o.from-1&&" "==e.state.sliceDoc(t.from,o.from))&&1==t.insert.length&&2==t.insert.lines&&w(e.contentDOM,"Enter",13)||(t.from==o.from-1&&t.to==o.to&&0==t.insert.length||8==i&&t.insert.lengtho.head)&&w(e.contentDOM,"Backspace",8)||t.from==o.from&&t.to==o.to+1&&0==t.insert.length&&w(e.contentDOM,"Delete",46)))return!0;let s,a=t.insert.toString();e.inputState.composing>=0&&e.inputState.composing++;let l=()=>s||(s=function(e,t,n){let i,o=e.state,s=o.selection.main;if(t.from>=s.from&&t.to<=s.to&&t.to-t.from>=(s.to-s.from)/3&&(!n||n.main.empty&&n.main.from==t.from+t.insert.length)&&e.inputState.composing<0){let n=s.fromt.to?o.sliceDoc(t.to,s.to):"";i=o.replaceSelection(e.state.toText(n+t.insert.sliceString(0,void 0,e.state.lineBreak)+r))}else{let a=o.changes(t),l=n&&n.main.to<=a.newLength?n.main:void 0;if(o.selection.ranges.length>1&&e.inputState.composing>=0&&t.to<=s.to&&t.to>=s.to-10){let u,c=e.state.sliceDoc(t.from,t.to),h=n&&kt(e,n.main.head);if(h){let e=t.insert.length-(t.to-t.from);u={from:h.from,to:h.to-e}}else u=e.state.doc.lineAt(s.head);let d=s.to-t.to,p=s.to-s.from;i=o.changeByRange((n=>{if(n.from==s.from&&n.to==s.to)return{changes:a,range:l||n.map(a)};let i=n.to-d,h=i-c.length;if(n.to-n.from!=p||e.state.sliceDoc(h,i)!=c||n.to>=u.from&&n.from<=u.to)return{range:n};let f=o.changes({from:h,to:i,insert:t.insert}),m=n.to-s.to;return{changes:f,range:l?r.OF.range(Math.max(0,l.anchor+m),Math.max(0,l.head+m)):n.map(f)}}))}else i={changes:a,selection:l&&o.selection.replaceRange(l)}}let a="input.type";(e.composing||e.inputState.compositionPendingChange&&e.inputState.compositionEndedAt>Date.now()-50)&&(e.inputState.compositionPendingChange=!1,a+=".compose",e.inputState.compositionFirstChange&&(a+=".start",e.inputState.compositionFirstChange=!1));return o.update(i,{userEvent:a,scrollIntoView:!0})}(e,t,n));return e.state.facet(Ge).some((n=>n(e,t.from,t.to,a,l)))||e.dispatch(l()),!0}class Ht{setSelectionOrigin(e){this.lastSelectionOrigin=e,this.lastSelectionTime=Date.now()}constructor(e){this.view=e,this.lastKeyCode=0,this.lastKeyTime=0,this.lastTouchTime=0,this.lastFocusTime=0,this.lastScrollTop=0,this.lastScrollLeft=0,this.pendingIOSKey=void 0,this.tabFocusMode=-1,this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastContextMenu=0,this.scrollHandlers=[],this.handlers=Object.create(null),this.composing=-1,this.compositionFirstChange=null,this.compositionEndedAt=0,this.compositionPendingKey=!1,this.compositionPendingChange=!1,this.mouseSelection=null,this.draggedContent=null,this.handleEvent=this.handleEvent.bind(this),this.notifiedFocused=e.hasFocus,W.safari&&e.contentDOM.addEventListener("input",(()=>null)),W.gecko&&function(e){vn.has(e)||(vn.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 n,r=t.target;r!=e.contentDOM;r=r.parentNode)if(!r||11==r.nodeType||(n=N.get(r))&&n.ignoreEvent(t))return!1;return!0})(this.view,e)&&!this.ignoreDuringComposition(e)&&("keydown"==e.type&&this.keydown(e)||(0!=this.view.updateState?Promise.resolve().then((()=>this.runHandlers(e.type,e))):this.runHandlers(e.type,e)))}runHandlers(e,t){let n=this.handlers[e];if(n){for(let e of n.observers)e(this.view,t);for(let e of n.handlers){if(t.defaultPrevented)break;if(e(this.view,t)){t.preventDefault();break}}}}ensureHandlers(e){let t=Vt(e),n=this.handlers,r=this.view.contentDOM;for(let i in t)if("scroll"!=i){let e=!t[i].handlers.length,o=n[i];o&&e!=!o.handlers.length&&(r.removeEventListener(i,this.handleEvent),o=null),o||r.addEventListener(i,this.handleEvent,{passive:e})}for(let i in n)"scroll"==i||t[i]||r.removeEventListener(i,this.handleEvent);this.handlers=t}keydown(e){if(this.lastKeyCode=e.keyCode,this.lastKeyTime=Date.now(),9==e.keyCode&&this.tabFocusMode>-1&&(!this.tabFocusMode||Date.now()<=this.tabFocusMode))return!0;if(this.tabFocusMode>0&&27!=e.keyCode&&Kt.indexOf(e.keyCode)<0&&(this.tabFocusMode=-1),W.android&&W.chrome&&!e.synthetic&&(13==e.keyCode||8==e.keyCode))return this.view.observer.delayAndroidKey(e.key,e.keyCode),!0;let t;return!W.ios||e.synthetic||e.altKey||e.metaKey||!((t=Gt.find((t=>t.keyCode==e.keyCode)))&&!e.ctrlKey||Wt.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(e){let t=this.pendingIOSKey;return!!t&&(!("Enter"==t.key&&e&&e.from0||!!(W.safari&&!W.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.view.observer.update(e),this.mouseSelection&&this.mouseSelection.update(e),this.draggedContent&&e.docChanged&&(this.draggedContent=this.draggedContent.map(e.changes)),e.transactions.length&&(this.lastKeyCode=this.lastSelectionTime=0)}destroy(){this.mouseSelection&&this.mouseSelection.destroy()}}function Yt(e,t){return(n,r)=>{try{return t.call(e,r,n)}catch(i){st(n.state,i)}}}function Vt(e){let t=Object.create(null);function n(e){return t[e]||(t[e]={observers:[],handlers:[]})}for(let r of e){let e=r.spec;if(e&&e.domEventHandlers)for(let t in e.domEventHandlers){let i=e.domEventHandlers[t];i&&n(t).handlers.push(Yt(r.value,i))}if(e&&e.domEventObservers)for(let t in e.domEventObservers){let i=e.domEventObservers[t];i&&n(t).observers.push(Yt(r.value,i))}}for(let r in tn)n(r).handlers.push(tn[r]);for(let r in nn)n(r).observers.push(nn[r]);return t}const Gt=[{key:"Backspace",keyCode:8,inputType:"deleteContentBackward"},{key:"Enter",keyCode:13,inputType:"insertParagraph"},{key:"Enter",keyCode:13,inputType:"insertLineBreak"},{key:"Delete",keyCode:46,inputType:"deleteContentForward"}],Wt="dthko",Kt=[16,17,18,20,91,92,224,225];function Jt(e){return.7*Math.max(0,e)+8}class en{constructor(e,t,n,i){this.view=e,this.startEvent=t,this.style=n,this.mustSelect=i,this.scrollSpeed={x:0,y:0},this.scrolling=-1,this.lastEvent=t,this.scrollParents=function(e){let t,n,r=e.ownerDocument;for(let i=e.parentNode;i&&!(i==r.body||t&&n);)if(1==i.nodeType)!n&&i.scrollHeight>i.clientHeight&&(n=i),!t&&i.scrollWidth>i.clientWidth&&(t=i),i=i.assignedSlot||i.parentNode;else{if(11!=i.nodeType)break;i=i.host}return{x:t,y:n}}(e.contentDOM),this.atoms=e.state.facet(gt).map((t=>t(e)));let o=e.contentDOM.ownerDocument;o.addEventListener("mousemove",this.move=this.move.bind(this)),o.addEventListener("mouseup",this.up=this.up.bind(this)),this.extend=t.shiftKey,this.multiple=e.state.facet(r.$t.allowMultipleSelections)&&function(e,t){let n=e.state.facet(Xe);return n.length?n[0](t):W.mac?t.metaKey:t.ctrlKey}(e,t),this.dragging=!(!function(e,t){let{main:n}=e.state.selection;if(n.empty)return!1;let r=h(e.root);if(!r||0==r.rangeCount)return!0;let i=r.getRangeAt(0).getClientRects();for(let o=0;o=t.clientX&&e.top<=t.clientY&&e.bottom>=t.clientY)return!0}return!1}(e,t)||1!=mn(t))&&null}start(e){!1===this.dragging&&this.select(e)}move(e){if(0==e.buttons)return this.destroy();if(this.dragging||null==this.dragging&&(t=this.startEvent,n=e,Math.max(Math.abs(t.clientX-n.clientX),Math.abs(t.clientY-n.clientY))<10))return;var t,n;this.select(this.lastEvent=e);let r=0,i=0,o=0,s=0,a=this.view.win.innerWidth,l=this.view.win.innerHeight;this.scrollParents.x&&({left:o,right:a}=this.scrollParents.x.getBoundingClientRect()),this.scrollParents.y&&({top:s,bottom:l}=this.scrollParents.y.getBoundingClientRect());let u=yt(this.view);e.clientX-u.left<=o+6?r=-Jt(o-e.clientX):e.clientX+u.right>=a-6&&(r=Jt(e.clientX-a)),e.clientY-u.top<=s+6?i=-Jt(s-e.clientY):e.clientY+u.bottom>=l-6&&(i=Jt(e.clientY-l)),this.setScrollSpeed(r,i)}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=this.view.inputState.draggedContent=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(){let{x:e,y:t}=this.scrollSpeed;e&&this.scrollParents.x&&(this.scrollParents.x.scrollLeft+=e,e=0),t&&this.scrollParents.y&&(this.scrollParents.y.scrollTop+=t,t=0),(e||t)&&this.view.win.scrollBy(e,t),!1===this.dragging&&this.select(this.lastEvent)}skipAtoms(e){let t=null;for(let n=0;ne.isUserEvent("input.type")))?this.destroy():this.style.update(e)&&setTimeout((()=>this.select(this.lastEvent)),20)}}const tn=Object.create(null),nn=Object.create(null),rn=W.ie&&W.ie_version<15||W.ios&&W.webkit_version<604;function on(e,t,n){for(let r of e.facet(t))n=r(n,e);return n}function sn(e,t){t=on(e.state,Ke,t);let n,{state:i}=e,o=1,s=i.toText(t),a=s.lines==i.selection.ranges.length;if(null!=On&&i.selection.ranges.every((e=>e.empty))&&On==s.toString()){let e=-1;n=i.changeByRange((n=>{let l=i.doc.lineAt(n.from);if(l.from==e)return{range:n};e=l.from;let u=i.toText((a?s.line(o++).text:t)+i.lineBreak);return{changes:{from:l.from,insert:u},range:r.OF.cursor(n.from+u.length)}}))}else n=a?i.changeByRange((e=>{let t=s.line(o++);return{changes:{from:e.from,to:e.to,insert:t.text},range:r.OF.cursor(e.from+t.length)}})):i.replaceSelection(s);e.dispatch(n,{userEvent:"input.paste",scrollIntoView:!0})}function an(e,t,n,i){if(1==i)return r.OF.cursor(t,n);if(2==i)return function(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1,i=e.charCategorizer(t),o=e.doc.lineAt(t),s=t-o.from;if(0==o.length)return r.OF.cursor(t);0==s?n=1:s==o.length&&(n=-1);let a=s,l=s;n<0?a=(0,r.zK)(o.text,s,!1):l=(0,r.zK)(o.text,s);let u=i(o.text.slice(a,l));for(;a>0;){let e=(0,r.zK)(o.text,a,!1);if(i(o.text.slice(e,a))!=u)break;a=e}for(;l{e.inputState.lastScrollTop=e.scrollDOM.scrollTop,e.inputState.lastScrollLeft=e.scrollDOM.scrollLeft},tn.keydown=(e,t)=>(e.inputState.setSelectionOrigin("select"),27==t.keyCode&&0!=e.inputState.tabFocusMode&&(e.inputState.tabFocusMode=Date.now()+2e3),!1),nn.touchstart=(e,t)=>{e.inputState.lastTouchTime=Date.now(),e.inputState.setSelectionOrigin("select.pointer")},nn.touchmove=e=>{e.inputState.setSelectionOrigin("select.pointer")},tn.mousedown=(e,t)=>{if(e.observer.flush(),e.inputState.lastTouchTime>Date.now()-2e3)return!1;let n=null;for(let r of e.state.facet(He))if(n=r(e,t),n)break;if(n||0!=t.button||(n=function(e,t){let n=cn(e,t),i=mn(t),o=e.state.selection;return{update(e){e.docChanged&&(n.pos=e.changes.mapPos(n.pos),o=o.map(e.changes))},get(t,s,a){let l,u=cn(e,t),c=an(e,u.pos,u.bias,i);if(n.pos!=u.pos&&!s){let t=an(e,n.pos,n.bias,i),o=Math.min(t.from,c.from),s=Math.max(t.to,c.to);c=o1&&(l=function(e,t){for(let n=0;n=t)return r.OF.create(e.ranges.slice(0,n).concat(e.ranges.slice(n+1)),e.mainIndex==n?0:e.mainIndex-(e.mainIndex>n?1:0))}return null}(o,u.pos))?l:a?o.addRange(c):r.OF.create([c])}}}(e,t)),n){let r=!e.hasFocus;e.inputState.startMouseSelection(new en(e,t,n,r)),r&&e.observer.ignore((()=>{S(e.contentDOM);let t=e.root.activeElement;t&&!t.contains(e.contentDOM)&&t.blur()}));let i=e.inputState.mouseSelection;if(i)return i.start(t),!1===i.dragging}return!1};let ln=(e,t,n)=>t>=n.top&&t<=n.bottom&&e>=n.left&&e<=n.right;function un(e,t,n,r){let i=be.find(e.docView,t);if(!i)return 1;let o=t-i.posAtStart;if(0==o)return 1;if(o==i.length)return-1;let s=i.coordsAt(o,-1);if(s&&ln(n,r,s))return-1;let a=i.coordsAt(o,1);return a&&ln(n,r,a)?1:s&&s.bottom>=r?-1:1}function cn(e,t){let n=e.posAtCoords({x:t.clientX,y:t.clientY},!1);return{pos:n,bias:un(e,n,t.clientX,t.clientY)}}const hn=W.ie&&W.ie_version<=11;let dn=null,pn=0,fn=0;function mn(e){if(!hn)return e.detail;let t=dn,n=fn;return dn=e,fn=Date.now(),pn=!t||n>Date.now()-400&&Math.abs(t.clientX-e.clientX)<2&&Math.abs(t.clientY-e.clientY)<2?(pn+1)%3:1}function gn(e,t,n,r){if(!(n=on(e.state,Ke,n)))return;let i=e.posAtCoords({x:t.clientX,y:t.clientY},!1),{draggedContent:o}=e.inputState,s=r&&o&&function(e,t){let n=e.state.facet(Ze);return n.length?n[0](t):W.mac?!t.altKey:!t.ctrlKey}(e,t)?{from:o.from,to:o.to}:null,a={from:i,insert:n},l=e.state.changes(s?[s,a]:a);e.focus(),e.dispatch({changes:l,selection:{anchor:l.mapPos(i,-1),head:l.mapPos(i,1)},userEvent:s?"move.drop":"input.drop"}),e.inputState.draggedContent=null}tn.dragstart=(e,t)=>{let{selection:{main:n}}=e.state;if(t.target.draggable){let i=e.docView.nearest(t.target);if(i&&i.isWidget){let e=i.posAtStart,t=e+i.length;(e>=n.to||t<=n.from)&&(n=r.OF.range(e,t))}}let{inputState:i}=e;return i.mouseSelection&&(i.mouseSelection.dragging=!0),i.draggedContent=n,t.dataTransfer&&(t.dataTransfer.setData("Text",on(e.state,Je,e.state.sliceDoc(n.from,n.to))),t.dataTransfer.effectAllowed="copyMove"),!1},tn.dragend=e=>(e.inputState.draggedContent=null,!1),tn.drop=(e,t)=>{if(!t.dataTransfer)return!1;if(e.state.readOnly)return!0;let n=t.dataTransfer.files;if(n&&n.length){let r=Array(n.length),i=0,o=()=>{++i==n.length&&gn(e,t,r.filter((e=>null!=e)).join(e.state.lineBreak),!1)};for(let e=0;e{/[\x00-\x08\x0e-\x1f]{2}/.test(t.result)||(r[e]=t.result),o()},t.readAsText(n[e])}return!0}{let n=t.dataTransfer.getData("Text");if(n)return gn(e,t,n,!0),!0}return!1},tn.paste=(e,t)=>{if(e.state.readOnly)return!0;e.observer.flush();let n=rn?null:t.clipboardData;return n?(sn(e,n.getData("text/plain")||n.getData("text/uri-list")),!0):(function(e){let t=e.dom.parentNode;if(!t)return;let n=t.appendChild(document.createElement("textarea"));n.style.cssText="position: fixed; left: -10000px; top: 10px",n.focus(),setTimeout((()=>{e.focus(),n.remove(),sn(e,n.value)}),50)}(e),!1)};let On=null;tn.copy=tn.cut=(e,t)=>{let{text:n,ranges:r,linewise:i}=function(e){let t=[],n=[],r=!1;for(let i of e.selection.ranges)i.empty||(t.push(e.sliceDoc(i.from,i.to)),n.push(i));if(!t.length){let i=-1;for(let{from:r}of e.selection.ranges){let o=e.doc.lineAt(r);o.number>i&&(t.push(o.text),n.push({from:o.from,to:Math.min(e.doc.length,o.to+1)})),i=o.number}r=!0}return{text:on(e,Je,t.join(e.lineBreak)),ranges:n,linewise:r}}(e.state);if(!n&&!i)return!1;On=i?n:null,"cut"!=t.type||e.state.readOnly||e.dispatch({changes:r,scrollIntoView:!0,userEvent:"delete.cut"});let o=rn?null:t.clipboardData;return o?(o.clearData(),o.setData("text/plain",n),!0):(function(e,t){let n=e.dom.parentNode;if(!n)return;let r=n.appendChild(document.createElement("textarea"));r.style.cssText="position: fixed; left: -10000px; top: 10px",r.value=t,r.focus(),r.selectionEnd=t.length,r.selectionStart=0,setTimeout((()=>{r.remove(),e.focus()}),50)}(e,n),!1)};const Dn=r.YH.define();function bn(e,t){let n=[];for(let r of e.facet(We)){let i=r(e,t);i&&n.push(i)}return n.length?e.update({effects:n,annotations:Dn.of(!0)}):null}function yn(e){setTimeout((()=>{let t=e.hasFocus;if(t!=e.inputState.notifiedFocused){let n=bn(e.state,t);n?e.dispatch(n):e.update([])}}),10)}nn.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),yn(e)},nn.blur=e=>{e.observer.clearSelectionRange(),yn(e)},nn.compositionstart=nn.compositionupdate=e=>{e.observer.editContext||(null==e.inputState.compositionFirstChange&&(e.inputState.compositionFirstChange=!0),e.inputState.composing<0&&(e.inputState.composing=0))},nn.compositionend=e=>{e.observer.editContext||(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,W.chrome&&W.android?e.observer.flushSoon():e.inputState.compositionPendingChange?Promise.resolve().then((()=>e.observer.flush())):setTimeout((()=>{e.inputState.composing<0&&e.docView.hasComposition&&e.update([])}),50))},nn.contextmenu=e=>{e.inputState.lastContextMenu=Date.now()},tn.beforeinput=(e,t)=>{var n,r;if("insertReplacementText"==t.inputType&&e.observer.editContext){let r=null===(n=t.dataTransfer)||void 0===n?void 0:n.getData("text/plain"),i=t.getTargetRanges();if(r&&i.length){let t=i[0],n=e.posAtDOM(t.startContainer,t.startOffset),o=e.posAtDOM(t.endContainer,t.endOffset);return Zt(e,{from:n,to:o,insert:e.state.toText(r)},null),!0}}let i;if(W.chrome&&W.android&&(i=Gt.find((e=>e.inputType==t.inputType)))&&(e.observer.delayAndroidKey(i.key,i.keyCode),"Backspace"==i.key||"Delete"==i.key)){let t=(null===(r=window.visualViewport)||void 0===r?void 0:r.height)||0;setTimeout((()=>{var n;((null===(n=window.visualViewport)||void 0===n?void 0:n.height)||0)>t+10&&e.hasFocus&&(e.contentDOM.blur(),e.focus())}),100)}return W.ios&&"deleteContentForward"==t.inputType&&e.observer.flushSoon(),W.safari&&"insertText"==t.inputType&&e.inputState.composing>=0&&setTimeout((()=>nn.compositionend(e,t)),20),!1};const vn=new Set;const An=["pre-wrap","normal","pre-line","break-spaces"];let En=!1;function Cn(){En=!1}class kn{constructor(e){this.lineWrapping=e,this.doc=r.EY.empty,this.heightSamples={},this.lineHeight=14,this.charWidth=7,this.textHeight=14,this.lineLength=30}heightForGap(e,t){let n=this.doc.lineAt(t).number-this.doc.lineAt(e).number+1;return this.lineWrapping&&(n+=Math.max(0,Math.ceil((t-e-n*this.lineLength*.5)/this.lineLength))),this.lineHeight*n}heightForLine(e){if(!this.lineWrapping)return this.lineHeight;return(1+Math.max(0,Math.ceil((e-this.lineLength)/(this.lineLength-5))))*this.lineHeight}setDoc(e){return this.doc=e,this}mustRefreshForWrapping(e){return An.indexOf(e)>-1!=this.lineWrapping}mustRefreshForHeights(e){let t=!1;for(let n=0;n-1,a=Math.round(t)!=Math.round(this.lineHeight)||this.lineWrapping!=s;if(this.lineWrapping=s,this.lineHeight=t,this.charWidth=n,this.textHeight=r,this.lineLength=i,a){this.heightSamples={};for(let e=0;e2&&void 0!==arguments[2]?arguments[2]:2;this.length=e,this.height=t,this.flags=n}get outdated(){return(2&this.flags)>0}set outdated(e){this.flags=(e?2:0)|-3&this.flags}setHeight(e){this.height!=e&&(Math.abs(this.height-e)>Tn&&(En=!0),this.height=e)}replace(e,t,n){return Fn.of(n)}decomposeLeft(e,t){t.push(this)}decomposeRight(e,t){t.push(this)}applyChanges(e,t,n,r){let i=this,o=n.doc;for(let s=r.length-1;s>=0;s--){let{fromA:a,toA:l,fromB:u,toB:c}=r[s],h=i.lineAt(a,wn.ByPosNoHeight,n.setDoc(t),0,0),d=h.to>=l?h:i.lineAt(l,wn.ByPosNoHeight,n,0,0);for(c+=d.to-l,l=d.to;s>0&&h.from<=r[s-1].toA;)a=r[s-1].fromA,u=r[s-1].fromB,s--,a2*i){let i=e[t-1];i.break?e.splice(--t,1,i.left,null,i.right):e.splice(--t,1,i.left,i.right),n+=1+i.break,r-=i.size}else{if(!(i>2*r))break;{let t=e[n];t.break?e.splice(n,1,t.left,null,t.right):e.splice(n,1,t.left,t.right),n+=2+t.break,i-=t.size}}else if(r=i&&o(this.blockAt(0,n,r,i))}updateHeight(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,n=arguments.length>3?arguments[3]:void 0;return n&&n.from<=t&&n.more&&this.setHeight(n.heights[n.index++]),this.outdated=!1,this}toString(){return"block(".concat(this.length,")")}}class Bn extends Pn{constructor(e,t){super(e,t,null),this.collapsed=0,this.widgetHeight=0,this.breaks=0}blockAt(e,t,n,r){return new xn(r,this.length,n,this.height,this.breaks)}replace(e,t,n){let r=n[0];return 1==n.length&&(r instanceof Bn||r instanceof Rn&&4&r.flags)&&Math.abs(this.length-r.length)<10?(r instanceof Rn?r=new Bn(r.length,this.height):r.height=this.height,this.outdated||(r.outdated=!1),r):Fn.of(n)}updateHeight(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,n=arguments.length>2&&void 0!==arguments[2]&&arguments[2],r=arguments.length>3?arguments[3]:void 0;return r&&r.from<=t&&r.more?this.setHeight(r.heights[r.index++]):(n||this.outdated)&&this.setHeight(Math.max(this.widgetHeight,e.heightForLine(this.length-this.collapsed))+this.breaks*e.lineHeight),this.outdated=!1,this}toString(){return"line(".concat(this.length).concat(this.collapsed?-this.collapsed:"").concat(this.widgetHeight?":"+this.widgetHeight:"",")")}}class Rn extends Fn{constructor(e){super(e,0)}heightMetrics(e,t){let n,r=e.doc.lineAt(t).number,i=e.doc.lineAt(t+this.length).number,o=i-r+1,s=0;if(e.lineWrapping){let t=Math.min(this.height,e.lineHeight*o);n=t/o,this.length>o+1&&(s=(this.height-t)/(this.length-o-1))}else n=this.height/o;return{firstLine:r,lastLine:i,perLine:n,perChar:s}}blockAt(e,t,n,r){let{firstLine:i,lastLine:o,perLine:s,perChar:a}=this.heightMetrics(t,r);if(t.lineWrapping){let i=r+(e0){let e=n[n.length-1];e instanceof Rn?n[n.length-1]=new Rn(e.length+r):n.push(null,new Rn(r-1))}if(e>0){let t=n[0];t instanceof Rn?n[0]=new Rn(e+t.length):n.unshift(new Rn(e-1),null)}return Fn.of(n)}decomposeLeft(e,t){t.push(new Rn(e-1),null)}decomposeRight(e,t){t.push(null,new Rn(this.length-e-1))}updateHeight(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,n=arguments.length>2&&void 0!==arguments[2]&&arguments[2],r=arguments.length>3?arguments[3]:void 0,i=t+this.length;if(r&&r.from<=t+this.length&&r.more){let n=[],o=Math.max(t,r.from),s=-1;for(r.from>t&&n.push(new Rn(r.from-t-1).updateHeight(e,t));o<=i&&r.more;){let t=e.doc.lineAt(o).length;n.length&&n.push(null);let i=r.heights[r.index++];-1==s?s=i:Math.abs(i-s)>=Tn&&(s=-2);let a=new Bn(t,i);a.outdated=!1,n.push(a),o+=t+1}o<=i&&n.push(null,new Rn(i-o).updateHeight(e,o));let a=Fn.of(n);return(s<0||Math.abs(a.height-this.height)>=Tn||Math.abs(s-this.heightMetrics(e,t).perLine)>=Tn)&&(En=!0),_n(this,a)}return(n||this.outdated)&&(this.setHeight(e.heightForGap(t,t+this.length)),this.outdated=!1),this}toString(){return"gap(".concat(this.length,")")}}class Nn extends Fn{constructor(e,t,n){super(e.length+t+n.length,e.height+n.height,t|(e.outdated||n.outdated?2:0)),this.left=e,this.right=n,this.size=e.size+n.size}get break(){return 1&this.flags}blockAt(e,t,n,r){let i=n+this.left.height;return es))return l;let u=t==wn.ByPosNoHeight?wn.ByPosNoHeight:wn.ByPos;return a?l.join(this.right.lineAt(s,u,n,o,s)):this.left.lineAt(s,u,n,r,i).join(l)}forEachLine(e,t,n,r,i,o){let s=r+this.left.height,a=i+this.left.length+this.break;if(this.break)e=a&&this.right.forEachLine(e,t,n,s,a,o);else{let l=this.lineAt(a,wn.ByPos,n,r,i);e=e&&l.from<=t&&o(l),t>l.to&&this.right.forEachLine(l.to+1,t,n,s,a,o)}}replace(e,t,n){let r=this.left.length+this.break;if(t