p.fromP));if(!d){if(cp.from<=c&&p.to>=c)){let p=t.moveToLineBoundary(X.cursor(c),!1,!0).head;p>l&&(c=p)}d=new Go(l,c,this.gapSize(h,l,c,Q))}o.push(d)};for(let l of this.viewportLines){if(l.lengthl.from&&a(l.from,Q,l,c),ut.draw(this.heightOracle.lineWrapping))))}computeVisibleRanges(){let e=this.stateDeco;this.lineGaps.length&&(e=e.concat(this.lineGapDeco));let t=[];ce.spans(e,this.viewport.from,this.viewport.to,{span(r,n){t.push({from:r,to:n})},point(){}},20);let i=t.length!=this.visibleRanges.length||this.visibleRanges.some((r,n)=>r.from!=t[n].from||r.to!=t[n].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)||$r(this.heightMap.lineAt(e,ge.ByPos,this.heightOracle,0,0),this.scaler)}lineBlockAtHeight(e){return $r(this.heightMap.lineAt(this.scaler.fromDOM(e),ge.ByHeight,this.heightOracle,0,0),this.scaler)}elementAtHeight(e){return $r(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 wn{constructor(e,t){this.from=e,this.to=t}}function h1(O,e,t){let i=[],r=O,n=0;return ce.spans(t,O,e,{span(){},point(s,o){s>r&&(i.push({from:r,to:s}),n+=s-r),r=o}},20),r=1)return e[e.length-1].to;let i=Math.floor(O*t);for(let r=0;;r++){let{from:n,to:s}=e[r],o=s-n;if(i<=o)return n+i;i-=o}}function Tn(O,e){let t=0;for(let{from:i,to:r}of O.ranges){if(e<=r){t+=e-i;break}t+=r-i}return t/O.total}function f1(O,e){for(let t of O)if(e(t))return t}const wf={toDOM(O){return O},fromDOM(O){return O},scale:1};class Q1{constructor(e,t,i){let r=0,n=0,s=0;this.viewports=i.map(({from:o,to:a})=>{let l=t.lineAt(o,ge.ByPos,e,0,0).top,c=t.lineAt(a,ge.ByPos,e,0,0).bottom;return r+=c-l,{from:o,to:a,top:l,bottom:c,domTop:0,domBottom:0}}),this.scale=(7e6-r)/(t.height-r);for(let o of this.viewports)o.domTop=s+(o.top-n)*this.scale,s=o.domBottom=o.domTop+(o.bottom-o.top),n=o.bottom}toDOM(e){for(let t=0,i=0,r=0;;t++){let n=t$r(r,e)):O.type)}const Yn=_.define({combine:O=>O.join(" ")}),al=_.define({combine:O=>O.indexOf(!0)>-1}),ll=IO.newName(),Kd=IO.newName(),Jd=IO.newName(),ep={"&light":"."+Kd,"&dark":"."+Jd};function cl(O,e,t){return new IO(e,{finish(i){return/&/.test(i)?i.replace(/&\w*/,r=>{if(r=="&")return O;if(!t||!t[r])throw new RangeError(`Unsupported selector: ${r}`);return t[r]}):O+" "+i}})}const u1=cl("."+ll,{"&":{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",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-selectionBackground":{background:"#d7d4f0"},"&dark.cm-focused .cm-selectionBackground":{background:"#233"},".cm-cursorLayer":{pointerEvents:"none"},"&.cm-focused .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-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",left: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"}},ep);class $1{constructor(e,t,i,r){this.typeOver=r,this.bounds=null,this.text="";let{impreciseHead:n,impreciseAnchor:s}=e.docView;if(e.state.readOnly&&t>-1)this.newSel=null;else if(t>-1&&(this.bounds=e.docView.domBoundsAround(t,i,0))){let o=n||s?[]:p1(e),a=new _d(o,e.state);a.readRange(this.bounds.startDOM,this.bounds.endDOM),this.text=a.text,this.newSel=m1(o,this.bounds.from)}else{let o=e.observer.selectionRange,a=n&&n.node==o.focusNode&&n.offset==o.focusOffset||!Gi(e.contentDOM,o.focusNode)?e.state.selection.main.head:e.docView.posFromDOM(o.focusNode,o.focusOffset),l=s&&s.node==o.anchorNode&&s.offset==o.anchorOffset||!Gi(e.contentDOM,o.anchorNode)?e.state.selection.main.anchor:e.docView.posFromDOM(o.anchorNode,o.anchorOffset);this.newSel=X.single(l,a)}}}function tp(O,e){let t,{newSel:i}=e,r=O.state.selection.main;if(e.bounds){let{from:n,to:s}=e.bounds,o=r.from,a=null;(O.inputState.lastKeyCode===8&&O.inputState.lastKeyTime>Date.now()-100||j.android&&e.text.length=r.from&&t.to<=r.to&&(t.from!=r.from||t.to!=r.to)&&r.to-r.from-(t.to-t.from)<=4?t={from:r.from,to:r.to,insert:O.state.doc.slice(r.from,t.from).append(t.insert).append(O.state.doc.slice(t.to,r.to))}:(j.mac||j.android)&&t&&t.from==t.to&&t.from==r.head-1&&/^\. ?$/.test(t.insert.toString())&&O.contentDOM.getAttribute("autocorrect")=="off"?(i&&t.insert.length==2&&(i=X.single(i.main.anchor-1,i.main.head-1)),t={from:r.from,to:r.to,insert:le.of([" "])}):j.chrome&&t&&t.from==t.to&&t.from==r.head&&t.insert.toString()==`
- `&&O.lineWrapping&&(i&&(i=X.single(i.main.anchor-1,i.main.head-1)),t={from:r.from,to:r.to,insert:le.of([" "])}),t){let n=O.state;if(j.ios&&O.inputState.flushIOSKey(O)||j.android&&(t.from==r.from&&t.to==r.to&&t.insert.length==1&&t.insert.lines==2&&ki(O.contentDOM,"Enter",13)||t.from==r.from-1&&t.to==r.to&&t.insert.length==0&&ki(O.contentDOM,"Backspace",8)||t.from==r.from&&t.to==r.to+1&&t.insert.length==0&&ki(O.contentDOM,"Delete",46)))return!0;let s=t.insert.toString();if(O.state.facet(Td).some(l=>l(O,t.from,t.to,s)))return!0;O.inputState.composing>=0&&O.inputState.composing++;let o;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)&&O.inputState.composing<0){let l=r.fromt.to?n.sliceDoc(t.to,r.to):"";o=n.replaceSelection(O.state.toText(l+t.insert.sliceString(0,void 0,O.state.lineBreak)+c))}else{let l=n.changes(t),c=i&&!n.selection.main.eq(i.main)&&i.main.to<=l.newLength?i.main:void 0;if(n.selection.ranges.length>1&&O.inputState.composing>=0&&t.to<=r.to&&t.to>=r.to-10){let h=O.state.sliceDoc(t.from,t.to),Q=jd(O)||O.state.doc.lineAt(r.head),u=r.to-t.to,$=r.to-r.from;o=n.changeByRange(d=>{if(d.from==r.from&&d.to==r.to)return{changes:l,range:c||d.map(l)};let p=d.to-u,P=p-h.length;if(d.to-d.from!=$||O.state.sliceDoc(P,p)!=h||Q&&d.to>=Q.from&&d.from<=Q.to)return{range:d};let y=n.changes({from:P,to:p,insert:t.insert}),x=d.to-r.to;return{changes:y,range:c?X.range(Math.max(0,c.anchor+x),Math.max(0,c.head+x)):d.map(y)}})}else o={changes:l,selection:c&&n.selection.replaceRange(c)}}let a="input.type";return O.composing&&(a+=".compose",O.inputState.compositionFirstChange&&(a+=".start",O.inputState.compositionFirstChange=!1)),O.dispatch(o,{scrollIntoView:!0,userEvent:a}),!0}else if(i&&!i.main.eq(r)){let n=!1,s="select";return O.inputState.lastSelectionTime>Date.now()-50&&(O.inputState.lastSelectionOrigin=="select"&&(n=!0),s=O.inputState.lastSelectionOrigin),O.dispatch({selection:i,scrollIntoView:n,userEvent:s}),!0}else return!1}function d1(O,e,t,i){let r=Math.min(O.length,e.length),n=0;for(;n0&&o>0&&O.charCodeAt(s-1)==e.charCodeAt(o-1);)s--,o--;if(i=="end"){let a=Math.max(0,n-Math.min(s,o));t-=s+a-n}if(s=s?n-t:0;n-=a,o=n+(o-s),s=n}else if(o=o?n-t:0;n-=a,s=n+(s-o),o=n}return{from:n,toA:s,toB:o}}function p1(O){let e=[];if(O.root.activeElement!=O.contentDOM)return e;let{anchorNode:t,anchorOffset:i,focusNode:r,focusOffset:n}=O.observer.selectionRange;return t&&(e.push(new of(t,i)),(r!=t||n!=i)&&e.push(new of(r,n))),e}function m1(O,e){if(O.length==0)return null;let t=O[0].pos,i=O.length==2?O[1].pos:t;return t>-1&&i>-1?X.single(t+e,i+e):null}const P1={childList:!0,characterData:!0,subtree:!0,attributes:!0,characterDataOldValue:!0},Co=j.ie&&j.ie_version<=11;class g1{constructor(e){this.view=e,this.active=!1,this.selectionRange=new Qy,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.resizeContent=null,this.intersecting=!1,this.gapIntersection=null,this.gaps=[],this.parentCheck=-1,this.dom=e.contentDOM,this.observer=new MutationObserver(t=>{for(let i of t)this.queue.push(i);(j.ie&&j.ie_version<=11||j.ios&&e.composing)&&t.some(i=>i.type=="childList"&&i.removedNodes.length||i.type=="characterData"&&i.oldValue.length>i.target.nodeValue.length)?this.flushSoon():this.flush()}),Co&&(this.onCharData=t=>{this.queue.push({target:t.target,type:"characterData",oldValue:t.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),typeof ResizeObserver=="function"&&(this.resizeScroll=new ResizeObserver(()=>{var t;((t=this.view.docView)===null||t===void 0?void 0:t.lastUpdate)this.view.requestMeasure()),this.resizeContent.observe(e.contentDOM)),this.addWindowListeners(this.win=e.win),this.start(),typeof IntersectionObserver=="function"&&(this.intersection=new IntersectionObserver(t=>{this.parentCheck<0&&(this.parentCheck=setTimeout(this.listenForScroll.bind(this),1e3)),t.length>0&&t[t.length-1].intersectionRatio>0!=this.intersecting&&(this.intersecting=!this.intersecting,this.intersecting!=this.view.inView&&this.onScrollChanged(document.createEvent("Event")))},{}),this.intersection.observe(this.dom),this.gapIntersection=new IntersectionObserver(t=>{t.length>0&&t[t.length-1].intersectionRatio>0&&this.onScrollChanged(document.createEvent("Event"))},{})),this.listenForScroll(),this.readSelectionRange()}onScrollChanged(e){this.view.inputState.runScrollHandlers(this.view,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,r=this.selectionRange;if(i.state.facet(ao)?i.root.activeElement!=this.dom:!ts(i.dom,r))return;let n=r.anchorNode&&i.docView.nearest(r.anchorNode);if(n&&n.ignoreEvent(e)){t||(this.selectionChanged=!1);return}(j.ie&&j.ie_version<=11||j.android&&j.chrome)&&!i.state.selection.main.empty&&r.focusNode&&ms(r.focusNode,r.focusOffset,r.anchorNode,r.anchorOffset)?this.flushSoon():this.flush(!1)}readSelectionRange(){let{view:e}=this,t=j.safari&&e.root.nodeType==11&&ly(this.dom.ownerDocument)==this.dom&&S1(this.view)||ps(e.root);if(!t||this.selectionRange.eq(t))return!1;let i=ts(this.dom,t);return i&&!this.selectionChanged&&e.inputState.lastFocusTime>Date.now()-200&&e.inputState.lastTouchTime{let n=this.delayedAndroidKey;n&&(this.clearDelayedAndroidKey(),!this.flush()&&n.force&&ki(this.dom,n.key,n.keyCode))};this.flushingAndroidKey=this.view.win.requestAnimationFrame(r)}(!this.delayedAndroidKey||e=="Enter")&&(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()}processRecords(){let e=this.queue;for(let n of this.observer.takeRecords())e.push(n);e.length&&(this.queue=[]);let t=-1,i=-1,r=!1;for(let n of e){let s=this.readMutation(n);s&&(s.typeOver&&(r=!0),t==-1?{from:t,to:i}=s:(t=Math.min(s.from,t),i=Math.max(s.to,i)))}return{from:t,to:i,typeOver:r}}readChange(){let{from:e,to:t,typeOver:i}=this.processRecords(),r=this.selectionChanged&&ts(this.dom,this.selectionRange);return e<0&&!r?null:(e>-1&&(this.lastChange=Date.now()),this.view.inputState.lastFocusTime=0,this.selectionChanged=!1,new $1(this.view,e,t,i))}flush(e=!0){if(this.delayedFlush>=0||this.delayedAndroidKey)return!1;e&&this.readSelectionRange();let t=this.readChange();if(!t)return!1;let i=this.view.state,r=tp(this.view,t);return this.view.state==i&&this.view.update([]),r}readMutation(e){let t=this.view.docView.nearest(e.target);if(!t||t.ignoreMutation(e))return null;if(t.markDirty(e.type=="attributes"),e.type=="attributes"&&(t.dirty|=4),e.type=="childList"){let i=Wf(t,e.previousSibling||e.target.previousSibling,-1),r=Wf(t,e.nextSibling||e.target.nextSibling,1);return{from:i?t.posAfter(i):t.posAtStart,to:r?t.posBefore(r):t.posAtEnd,typeOver:!1}}else return e.type=="characterData"?{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,r;this.stop(),(e=this.intersection)===null||e===void 0||e.disconnect(),(t=this.gapIntersection)===null||t===void 0||t.disconnect(),(i=this.resizeScroll)===null||i===void 0||i.disconnect(),(r=this.resizeContent)===null||r===void 0||r.disconnect();for(let n of this.scrollTargets)n.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 Wf(O,e,t){for(;e;){let i=Se.get(e);if(i&&i.parent==O)return i;let r=e.parentNode;e=r!=O.dom?r:t>0?e.nextSibling:e.previousSibling}return null}function S1(O){let e=null;function t(a){a.preventDefault(),a.stopImmediatePropagation(),e=a.getTargetRanges()[0]}if(O.contentDOM.addEventListener("beforeinput",t,!0),O.dom.ownerDocument.execCommand("indent"),O.contentDOM.removeEventListener("beforeinput",t,!0),!e)return null;let i=e.startContainer,r=e.startOffset,n=e.endContainer,s=e.endOffset,o=O.docView.domAtPos(O.state.selection.main.anchor);return ms(o.node,o.offset,n,s)&&([i,r,n,s]=[n,s,i,r]),{anchorNode:i,anchorOffset:r,focusNode:n,focusOffset:s}}class z{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),this._dispatch=e.dispatch||(t=>this.update([t])),this.dispatch=this.dispatch.bind(this),this._root=e.root||uy(e.parent)||document,this.viewState=new bf(e.state||te.create(e)),this.plugins=this.state.facet(Qr).map(t=>new zo(t));for(let t of this.plugins)t.update(this);this.observer=new g1(this),this.inputState=new Ey(this),this.inputState.ensureHandlers(this,this.plugins),this.docView=new af(this),this.mountStyles(),this.updateAttrs(),this.updateState=0,this.requestMeasure(),e.parent&&e.parent.appendChild(this.dom)}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}dispatch(...e){this._dispatch(e.length==1&&e[0]instanceof ze?e[0]:this.state.update(...e))}update(e){if(this.updateState!=0)throw new Error("Calls to EditorView.update are not allowed while an update is in progress");let t=!1,i=!1,r,n=this.state;for(let Q of e){if(Q.startState!=n)throw new RangeError("Trying to update state with a transaction that doesn't start from the previous state.");n=Q.state}if(this.destroyed){this.viewState.state=n;return}let s=this.hasFocus,o=0,a=null;e.some(Q=>Q.annotation(Ld))?(this.inputState.notifiedFocused=s,o=1):s!=this.inputState.notifiedFocused&&(this.inputState.notifiedFocused=s,a=Bd(n,s),a||(o=1));let l=this.observer.delayedAndroidKey,c=null;if(l?(this.observer.clearDelayedAndroidKey(),c=this.observer.readChange(),(c&&!this.state.doc.eq(n.doc)||!this.state.selection.eq(n.selection))&&(c=null)):this.observer.clear(),n.facet(te.phrases)!=this.state.facet(te.phrases))return this.setState(n);r=Ss.create(this,n,e),r.flags|=o;let h=this.viewState.scrollTarget;try{this.updateState=2;for(let Q of e){if(h&&(h=h.map(Q.changes)),Q.scrollIntoView){let{main:u}=Q.state.selection;h=new gs(u.empty?u:X.cursor(u.head,u.head>u.anchor?-1:1))}for(let u of Q.effects)u.is(nf)&&(h=u.value)}this.viewState.update(r,h),this.bidiCache=Xs.update(this.bidiCache,r.changes),r.empty||(this.updatePlugins(r),this.inputState.update(r)),t=this.docView.update(r),this.state.facet(ur)!=this.styleModules&&this.mountStyles(),i=this.updateAttrs(),this.showAnnouncements(e),this.docView.updateSelection(t,e.some(Q=>Q.isUserEvent("select.pointer")))}finally{this.updateState=0}if(r.startState.facet(Yn)!=r.state.facet(Yn)&&(this.viewState.mustMeasureContent=!0),(t||i||h||this.viewState.mustEnforceCursorAssoc||this.viewState.mustMeasureContent)&&this.requestMeasure(),!r.empty)for(let Q of this.state.facet(Ol))Q(r);(a||c)&&Promise.resolve().then(()=>{a&&this.state==a.startState&&this.dispatch(a),c&&!tp(this,c)&&l.force&&ki(this.contentDOM,l.key,l.keyCode)})}setState(e){if(this.updateState!=0)throw new Error("Calls to EditorView.setState are not allowed while an update is in progress");if(this.destroyed){this.viewState.state=e;return}this.updateState=2;let t=this.hasFocus;try{for(let i of this.plugins)i.destroy(this);this.viewState=new bf(e),this.plugins=e.facet(Qr).map(i=>new zo(i)),this.pluginMap.clear();for(let i of this.plugins)i.update(this);this.docView=new af(this),this.inputState.ensureHandlers(this,this.plugins),this.mountStyles(),this.updateAttrs(),this.bidiCache=[]}finally{this.updateState=0}t&&this.focus(),this.requestMeasure()}updatePlugins(e){let t=e.startState.facet(Qr),i=e.state.facet(Qr);if(t!=i){let r=[];for(let n of i){let s=t.indexOf(n);if(s<0)r.push(new zo(n));else{let o=this.plugins[s];o.mustUpdate=e,r.push(o)}}for(let n of this.plugins)n.mustUpdate!=e&&n.destroy(this);this.plugins=r,this.pluginMap.clear(),this.inputState.ensureHandlers(this,this.plugins)}else for(let r of this.plugins)r.mustUpdate=e;for(let r=0;r-1&&this.win.cancelAnimationFrame(this.measureScheduled),this.measureScheduled=0,e&&this.observer.forceFlush();let t=null,{scrollHeight:i,scrollTop:r,clientHeight:n}=this.scrollDOM,s=r>i-n-4?i:r;try{for(let o=0;;o++){this.updateState=1;let a=this.viewport,l=this.viewState.lineBlockAtHeight(s),c=this.viewState.measure(this);if(!c&&!this.measureRequests.length&&this.viewState.scrollTarget==null)break;if(o>5){console.warn(this.measureRequests.length?"Measure loop restarted more than 5 times":"Viewport failed to stabilize");break}let h=[];c&4||([this.measureRequests,h]=[h,this.measureRequests]);let Q=h.map(p=>{try{return p.read(this)}catch(P){return xt(this.state,P),Tf}}),u=Ss.create(this,this.state,[]),$=!1,d=!1;u.flags|=c,t?t.flags|=c:t=u,this.updateState=2,u.empty||(this.updatePlugins(u),this.inputState.update(u),this.updateAttrs(),$=this.docView.update(u));for(let p=0;p1||p<-1)&&(this.scrollDOM.scrollTop+=p,d=!0)}if($&&this.docView.updateSelection(!0),this.viewport.from==a.from&&this.viewport.to==a.to&&!d&&this.measureRequests.length==0)break}}finally{this.updateState=0,this.measureScheduled=-1}if(t&&!t.empty)for(let o of this.state.facet(Ol))o(t)}get themeClasses(){return ll+" "+(this.state.facet(al)?Jd:Kd)+" "+this.state.facet(Yn)}updateAttrs(){let e=Yf(this,kd,{class:"cm-editor"+(this.hasFocus?" cm-focused ":" ")+this.themeClasses}),t={spellcheck:"false",autocorrect:"off",autocapitalize:"off",translate:"no",contenteditable:this.state.facet(ao)?"true":"false",class:"cm-content",style:`${j.tabSize}: ${this.state.tabSize}`,role:"textbox","aria-multiline":"true"};this.state.readOnly&&(t["aria-readonly"]="true"),Yf(this,mc,t);let i=this.observer.ignore(()=>{let r=el(this.contentDOM,this.contentAttrs,t),n=el(this.dom,this.editorAttrs,e);return r||n});return this.editorAttrs=e,this.contentAttrs=t,i}showAnnouncements(e){let t=!0;for(let i of e)for(let r of i.effects)if(r.is(z.announce)){t&&(this.announceDOM.textContent=""),t=!1;let n=this.announceDOM.appendChild(document.createElement("div"));n.textContent=r.value}}mountStyles(){this.styleModules=this.state.facet(ur),IO.mount(this.root,this.styleModules.concat(u1).reverse())}readMeasured(){if(this.updateState==2)throw new Error("Reading the editor layout isn't allowed during an update");this.updateState==0&&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(e.key!=null){for(let t=0;ti.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}}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 jo(this,e,uf(this,e,t,i))}moveByGroup(e,t){return jo(this,e,uf(this,e,t,i=>Cy(this,e.head,i)))}moveToLineBoundary(e,t,i=!0){return Gy(this,e,t,i)}moveVertically(e,t,i){return jo(this,e,Iy(this,e,t,i))}domAtPos(e){return this.docView.domAtPos(e)}posAtDOM(e,t=0){return this.docView.posFromDOM(e,t)}posAtCoords(e,t=!0){return this.readMeasured(),Cd(this,e,t)}coordsAtPos(e,t=1){this.readMeasured();let i=this.docView.coordsAt(e,t);if(!i||i.left==i.right)return i;let r=this.state.doc.lineAt(e),n=this.bidiSpans(r),s=n[Zi.find(n,e-r.from,-1,t)];return uc(i,s.dir==We.LTR==t>0)}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(vd)||ethis.viewport.to?this.textDirection:(this.readMeasured(),this.docView.textDirectionAt(e))}get lineWrapping(){return this.viewState.heightOracle.lineWrapping}bidiSpans(e){if(e.length>X1)return Vd(e.length);let t=this.textDirectionAt(e.from);for(let r of this.bidiCache)if(r.from==e.from&&r.dir==t)return r.order;let i=wy(e.text,t);return this.bidiCache.push(new Xs(e.from,e.to,t,i)),i}get hasFocus(){var e;return(this.dom.ownerDocument.hasFocus()||j.safari&&((e=this.inputState)===null||e===void 0?void 0:e.lastContextMenu)>Date.now()-3e4)&&this.root.activeElement==this.contentDOM}focus(){this.observer.ignore(()=>{hd(this.contentDOM),this.docView.updateSelection()})}setRoot(e){this._root!=e&&(this._root=e,this.observer.setWindow((e.nodeType==9?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 nf.of(new gs(typeof e=="number"?X.cursor(e):e,t.y,t.x,t.yMargin,t.xMargin))}static domEventHandlers(e){return qe.define(()=>({}),{eventHandlers:e})}static theme(e,t){let i=IO.newName(),r=[Yn.of(i),ur.of(cl(`.${i}`,e))];return t&&t.dark&&r.push(al.of(!0)),r}static baseTheme(e){return MO.lowest(ur.of(cl("."+ll,e,ep)))}static findFromDOM(e){var t;let i=e.querySelector(".cm-content"),r=i&&Se.get(i)||Se.get(e);return((t=r==null?void 0:r.rootView)===null||t===void 0?void 0:t.view)||null}}z.styleModule=ur;z.inputHandler=Td;z.focusChangeEffect=Yd;z.perLineTextDirection=vd;z.exceptionSink=Wd;z.updateListener=Ol;z.editable=ao;z.mouseSelectionStyle=wd;z.dragMovesSelection=bd;z.clickAddsSelectionRange=xd;z.decorations=Cr;z.atomicRanges=Zd;z.scrollMargins=Rd;z.darkTheme=al;z.contentAttributes=mc;z.editorAttributes=kd;z.lineWrapping=z.contentAttributes.of({class:"cm-lineWrapping"});z.announce=B.define();const X1=4096,Tf={};class Xs{constructor(e,t,i,r){this.from=e,this.to=t,this.dir=i,this.order=r}static update(e,t){if(t.empty)return e;let i=[],r=e.length?e[e.length-1].dir:We.LTR;for(let n=Math.max(0,e.length-10);n=0;r--){let n=i[r],s=typeof n=="function"?n(O):n;s&&Ja(s,t)}return t}const y1=j.mac?"mac":j.windows?"win":j.linux?"linux":"key";function x1(O,e){const t=O.split(/-(?!$)/);let i=t[t.length-1];i=="Space"&&(i=" ");let r,n,s,o;for(let a=0;ai.concat(r),[]))),t}function w1(O,e,t){return ip(Op(O.state),e,O,t)}let qO=null;const W1=4e3;function T1(O,e=y1){let t=Object.create(null),i=Object.create(null),r=(s,o)=>{let a=i[s];if(a==null)i[s]=o;else if(a!=o)throw new Error("Key binding "+s+" is used both as a regular binding and as a multi-stroke prefix")},n=(s,o,a,l)=>{var c,h;let Q=t[s]||(t[s]=Object.create(null)),u=o.split(/ (?!$)/).map(p=>x1(p,e));for(let p=1;p{let x=qO={view:y,prefix:P,scope:s};return setTimeout(()=>{qO==x&&(qO=null)},W1),!0}]})}let $=u.join(" ");r($,!1);let d=Q[$]||(Q[$]={preventDefault:!1,run:((h=(c=Q._any)===null||c===void 0?void 0:c.run)===null||h===void 0?void 0:h.slice())||[]});a&&d.run.push(a),l&&(d.preventDefault=!0)};for(let s of O){let o=s.scope?s.scope.split(" "):["editor"];if(s.any)for(let l of o){let c=t[l]||(t[l]=Object.create(null));c._any||(c._any={preventDefault:!1,run:[]});for(let h in c)c[h].run.push(s.any)}let a=s[e]||s.key;if(a)for(let l of o)n(l,a,s.run,s.preventDefault),s.shift&&n(l,"Shift-"+a,s.shift,s.preventDefault)}return t}function ip(O,e,t,i){let r=ay(e),n=Be(r,0),s=wt(n)==r.length&&r!=" ",o="",a=!1;qO&&qO.view==t&&qO.scope==i&&(o=qO.prefix+" ",(a=Ed.indexOf(e.keyCode)<0)&&(qO=null));let l=new Set,c=$=>{if($){for(let d of $.run)if(!l.has(d)&&(l.add(d),d(t,e)))return!0;$.preventDefault&&(a=!0)}return!1},h=O[i],Q,u;if(h){if(c(h[o+vn(r,e,!s)]))return!0;if(s&&(e.altKey||e.metaKey||e.ctrlKey)&&!(j.windows&&e.ctrlKey&&e.altKey)&&(Q=EO[e.keyCode])&&Q!=r){if(c(h[o+vn(Q,e,!0)]))return!0;if(e.shiftKey&&(u=_r[e.keyCode])!=r&&u!=Q&&c(h[o+vn(u,e,!1)]))return!0}else if(s&&e.shiftKey&&c(h[o+vn(r,e,!0)]))return!0;if(c(h._any))return!0}return a}class sn{constructor(e,t,i,r,n){this.className=e,this.left=t,this.top=i,this.width=r,this.height=n}draw(){let e=document.createElement("div");return e.className=this.className,this.adjust(e),e}update(e,t){return t.className!=this.className?!1:(this.adjust(e),!0)}adjust(e){e.style.left=this.left+"px",e.style.top=this.top+"px",this.width!=null&&(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 r=e.coordsAtPos(i.head,i.assoc||1);if(!r)return[];let n=rp(e);return[new sn(t,r.left-n.left,r.top-n.top,null,r.bottom-r.top)]}else return Y1(e,t,i)}}function rp(O){let e=O.scrollDOM.getBoundingClientRect();return{left:(O.textDirection==We.LTR?e.left:e.right-O.scrollDOM.clientWidth)-O.scrollDOM.scrollLeft,top:e.top-O.scrollDOM.scrollTop}}function qf(O,e,t){let i=X.cursor(e);return{from:Math.max(t.from,O.moveToLineBoundary(i,!1,!0).from),to:Math.min(t.to,O.moveToLineBoundary(i,!0,!0).from),type:$e.Text}}function kf(O,e){let t=O.lineBlockAt(e);if(Array.isArray(t.type)){for(let i of t.type)if(i.to>e||i.to==e&&(i.to==t.to||i.type==$e.Text))return i}return t}function Y1(O,e,t){if(t.to<=O.viewport.from||t.from>=O.viewport.to)return[];let i=Math.max(t.from,O.viewport.from),r=Math.min(t.to,O.viewport.to),n=O.textDirection==We.LTR,s=O.contentDOM,o=s.getBoundingClientRect(),a=rp(O),l=s.querySelector(".cm-line"),c=l&&window.getComputedStyle(l),h=o.left+(c?parseInt(c.paddingLeft)+Math.min(0,parseInt(c.textIndent)):0),Q=o.right-(c?parseInt(c.paddingRight):0),u=kf(O,i),$=kf(O,r),d=u.type==$e.Text?u:null,p=$.type==$e.Text?$:null;if(O.lineWrapping&&(d&&(d=qf(O,i,d)),p&&(p=qf(O,r,p))),d&&p&&d.from==p.from)return y(x(t.from,t.to,d));{let Y=d?x(t.from,null,d):b(u,!1),Z=p?x(null,t.to,p):b($,!0),E=[];return(d||u).to<(p||$).from-1?E.push(P(h,Y.bottom,Q,Z.top)):Y.bottomXe&&Ge.from=ne)break;be>ke&&oe(Math.max(fe,ke),Y==null&&fe<=Xe,Math.min(be,ne),Z==null&&be>=Te,F.dir)}if(ke=ie.to+1,ke>=ne)break}return N.length==0&&oe(Xe,Y==null,Te,Z==null,O.textDirection),{top:Oe,bottom:H,horizontal:N}}function b(Y,Z){let E=o.top+(Z?Y.top:Y.bottom);return{top:E,bottom:E,horizontal:[]}}}function v1(O,e){return O.constructor==e.constructor&&O.eq(e)}class q1{constructor(e,t){this.view=e,this.layer=t,this.drawn=[],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.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(is)!=e.state.facet(is)&&this.setOrder(e.state),(this.layer.update(e,this.dom)||e.geometryChanged)&&e.view.requestMeasure(this.measureReq)}setOrder(e){let t=0,i=e.facet(is);for(;t!v1(t,this.drawn[i]))){let t=this.dom.firstChild,i=0;for(let r of e)r.update&&t&&r.constructor&&this.drawn[i].constructor&&r.update(t,this.drawn[i])?(t=t.nextSibling,i++):this.dom.insertBefore(r.draw(),t);for(;t;){let r=t.nextSibling;t.remove(),t=r}this.drawn=e}}destroy(){this.layer.destroy&&this.layer.destroy(this.dom,this.view),this.dom.remove()}}const is=_.define();function np(O){return[qe.define(e=>new q1(e,O)),is.of(O)]}const sp=!j.ios,Ir=_.define({combine(O){return cO(O,{cursorBlinkRate:1200,drawRangeCursor:!0},{cursorBlinkRate:(e,t)=>Math.min(e,t),drawRangeCursor:(e,t)=>e||t})}});function k1(O={}){return[Ir.of(O),Z1,R1,U1,qd.of(!0)]}function op(O){return O.startState.facet(Ir)!=O.state.facet(Ir)}const Z1=np({above:!0,markers(O){let{state:e}=O,t=e.facet(Ir),i=[];for(let r of e.selection.ranges){let n=r==e.selection.main;if(r.empty?!n||sp:t.drawRangeCursor){let s=n?"cm-cursor cm-cursor-primary":"cm-cursor cm-cursor-secondary",o=r.empty?r:X.cursor(r.head,r.head>r.anchor?-1:1);for(let a of sn.forRange(O,s,o))i.push(a)}}return i},update(O,e){O.transactions.some(i=>i.selection)&&(e.style.animationName=e.style.animationName=="cm-blink"?"cm-blink2":"cm-blink");let t=op(O);return t&&Zf(O.state,e),O.docChanged||O.selectionSet||t},mount(O,e){Zf(e.state,O)},class:"cm-cursorLayer"});function Zf(O,e){e.style.animationDuration=O.facet(Ir).cursorBlinkRate+"ms"}const R1=np({above:!1,markers(O){return O.state.selection.ranges.map(e=>e.empty?[]:sn.forRange(O,"cm-selectionBackground",e)).reduce((e,t)=>e.concat(t))},update(O,e){return O.docChanged||O.selectionSet||O.viewportChanged||op(O)},class:"cm-selectionLayer"}),ap={".cm-line":{"& ::selection":{backgroundColor:"transparent !important"},"&::selection":{backgroundColor:"transparent !important"}}};sp&&(ap[".cm-line"].caretColor="transparent !important");const U1=MO.highest(z.theme(ap)),lp=B.define({map(O,e){return O==null?null:e.mapPos(O)}}),dr=Ae.define({create(){return null},update(O,e){return O!=null&&(O=e.changes.mapPos(O)),e.effects.reduce((t,i)=>i.is(lp)?i.value:t,O)}}),V1=qe.fromClass(class{constructor(O){this.view=O,this.cursor=null,this.measureReq={read:this.readPos.bind(this),write:this.drawCursor.bind(this)}}update(O){var e;let t=O.state.field(dr);t==null?this.cursor!=null&&((e=this.cursor)===null||e===void 0||e.remove(),this.cursor=null):(this.cursor||(this.cursor=this.view.scrollDOM.appendChild(document.createElement("div")),this.cursor.className="cm-dropCursor"),(O.startState.field(dr)!=t||O.docChanged||O.geometryChanged)&&this.view.requestMeasure(this.measureReq))}readPos(){let O=this.view.state.field(dr),e=O!=null&&this.view.coordsAtPos(O);if(!e)return null;let t=this.view.scrollDOM.getBoundingClientRect();return{left:e.left-t.left+this.view.scrollDOM.scrollLeft,top:e.top-t.top+this.view.scrollDOM.scrollTop,height:e.bottom-e.top}}drawCursor(O){this.cursor&&(O?(this.cursor.style.left=O.left+"px",this.cursor.style.top=O.top+"px",this.cursor.style.height=O.height+"px"):this.cursor.style.left="-100000px")}destroy(){this.cursor&&this.cursor.remove()}setDropPos(O){this.view.state.field(dr)!=O&&this.view.dispatch({effects:lp.of(O)})}},{eventHandlers:{dragover(O){this.setDropPos(this.view.posAtCoords({x:O.clientX,y:O.clientY}))},dragleave(O){(O.target==this.view.contentDOM||!this.view.contentDOM.contains(O.relatedTarget))&&this.setDropPos(null)},dragend(){this.setDropPos(null)},drop(){this.setDropPos(null)}}});function z1(){return[dr,V1]}function Rf(O,e,t,i,r){e.lastIndex=0;for(let n=O.iterRange(t,i),s=t,o;!n.next().done;s+=n.value.length)if(!n.lineBreak)for(;o=e.exec(n.value);)r(s+o.index,o)}function _1(O,e){let t=O.visibleRanges;if(t.length==1&&t[0].from==O.viewport.from&&t[0].to==O.viewport.to)return t;let i=[];for(let{from:r,to:n}of t)r=Math.max(O.state.doc.lineAt(r).from,r-e),n=Math.min(O.state.doc.lineAt(n).to,n+e),i.length&&i[i.length-1].to>=r?i[i.length-1].to=n:i.push({from:r,to:n});return i}class j1{constructor(e){const{regexp:t,decoration:i,decorate:r,boundary:n,maxLength:s=1e3}=e;if(!t.global)throw new RangeError("The regular expression given to MatchDecorator should have its 'g' flag set");if(this.regexp=t,r)this.addMatch=(o,a,l,c)=>r(c,l,l+o[0].length,o,a);else if(typeof i=="function")this.addMatch=(o,a,l,c)=>{let h=i(o,a,l);h&&c(l,l+o[0].length,h)};else if(i)this.addMatch=(o,a,l,c)=>c(l,l+o[0].length,i);else throw new RangeError("Either 'decorate' or 'decoration' should be provided to MatchDecorator");this.boundary=n,this.maxLength=s}createDeco(e){let t=new CO,i=t.add.bind(t);for(let{from:r,to:n}of _1(e,this.maxLength))Rf(e.state.doc,this.regexp,r,n,(s,o)=>this.addMatch(o,e,s,i));return t.finish()}updateDeco(e,t){let i=1e9,r=-1;return e.docChanged&&e.changes.iterChanges((n,s,o,a)=>{a>e.view.viewport.from&&o1e3?this.createDeco(e.view):r>-1?this.updateRange(e.view,t.map(e.changes),i,r):t}updateRange(e,t,i,r){for(let n of e.visibleRanges){let s=Math.max(n.from,i),o=Math.min(n.to,r);if(o>s){let a=e.state.doc.lineAt(s),l=a.toa.from;s--)if(this.boundary.test(a.text[s-1-a.from])){c=s;break}for(;o