9296.d85e411246b128c4a4ef.js 199 KB

1
  1. "use strict";(self["webpackChunk_jupyterlab_application_top"]=self["webpackChunk_jupyterlab_application_top"]||[]).push([[9296],{49296:(t,e,i)=>{i.r(e);i.d(e,{BidiSpan:()=>At,BlockInfo:()=>xs,BlockType:()=>W,BlockWrapper:()=>K,Decoration:()=>P,Direction:()=>mt,EditorView:()=>uo,GutterMarker:()=>ur,MatchDecorator:()=>Zo,RectangleMarker:()=>Ro,ViewPlugin:()=>oe,ViewUpdate:()=>we,WidgetType:()=>H,__test:()=>Xr,closeHoverTooltips:()=>Jn,crosshairCursor:()=>On,drawSelection:()=>zo,dropCursor:()=>Uo,getDialog:()=>ar,getDrawSelectionConfig:()=>Io,getPanel:()=>ir,getTooltip:()=>$n,gutter:()=>wr,gutterLineClass:()=>pr,gutterWidgetClass:()=>gr,gutters:()=>yr,hasHoverTooltips:()=>Un,highlightActiveLine:()=>mn,highlightActiveLineGutter:()=>Vr,highlightSpecialChars:()=>ln,highlightTrailingWhitespace:()=>Yr,highlightWhitespace:()=>Kr,hoverTooltip:()=>jn,keymap:()=>So,layer:()=>Vo,lineNumberMarkers:()=>Dr,lineNumberWidgetMarker:()=>Or,lineNumbers:()=>Hr,logException:()=>te,panels:()=>er,placeholder:()=>yn,rectangularSelection:()=>An,repositionTooltips:()=>Zn,runScopeHandlers:()=>ko,scrollPastEnd:()=>gn,showDialog:()=>lr,showPanel:()=>rr,showTooltip:()=>zn,tooltips:()=>Bn});var s=i(71674);var o=i(23546);var n={8:"Backspace",9:"Tab",10:"Enter",12:"NumLock",13:"Enter",16:"Shift",17:"Control",18:"Alt",20:"CapsLock",27:"Escape",32:" ",33:"PageUp",34:"PageDown",35:"End",36:"Home",37:"ArrowLeft",38:"ArrowUp",39:"ArrowRight",40:"ArrowDown",44:"PrintScreen",45:"Insert",46:"Delete",59:";",61:"=",91:"Meta",92:"Meta",106:"*",107:"+",108:",",109:"-",110:".",111:"/",144:"NumLock",145:"ScrollLock",160:"Shift",161:"Shift",162:"Control",163:"Control",164:"Alt",165:"Alt",173:"-",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"};var r={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'};var l=typeof navigator!="undefined"&&/Chrome\/(\d+)/.exec(navigator.userAgent);var a=typeof navigator!="undefined"&&/Gecko\/\d+/.test(navigator.userAgent);var h=typeof navigator!="undefined"&&/Mac/.test(navigator.platform);var c=typeof navigator!="undefined"&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent);var f=h||l&&+l[1]<57;for(var d=0;d<10;d++)n[48+d]=n[96+d]=String(d);for(var d=1;d<=24;d++)n[d+111]="F"+d;for(var d=65;d<=90;d++){n[d]=String.fromCharCode(d+32);r[d]=String.fromCharCode(d)}for(var u in n)if(!r.hasOwnProperty(u))r[u]=n[u];function p(t){var e=f&&(t.ctrlKey||t.altKey||t.metaKey)||c&&t.shiftKey&&t.key&&t.key.length==1||t.key=="Unidentified";var i=!e&&t.key||(t.shiftKey?r:n)[t.keyCode]||t.key||"Unidentified";if(i=="Esc")i="Escape";if(i=="Del")i="Delete";if(i=="Left")i="ArrowLeft";if(i=="Up")i="ArrowUp";if(i=="Right")i="ArrowRight";if(i=="Down")i="ArrowDown";return i}var g=i(41107);let m=typeof navigator!="undefined"?navigator:{userAgent:"",vendor:"",platform:""};let v=typeof document!="undefined"?document:{documentElement:{style:{}}};const w=/Edge\/(\d+)/.exec(m.userAgent);const b=/MSIE \d/.test(m.userAgent);const y=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(m.userAgent);const x=!!(b||y||w);const S=!x&&/gecko\/(\d+)/i.test(m.userAgent);const C=!x&&/Chrome\/(\d+)/.exec(m.userAgent);const M="webkitFontSmoothing"in v.documentElement.style;const k=!x&&/Apple Computer/.test(m.vendor);const A=k&&(/Mobile\/\w+/.test(m.userAgent)||m.maxTouchPoints>2);var T={mac:A||/Mac/.test(m.platform),windows:/Win/.test(m.platform),linux:/Linux|X11/.test(m.platform),ie:x,ie_version:b?v.documentMode||6:y?+y[1]:w?+w[1]:0,gecko:S,gecko_version:S?+(/Firefox\/(\d+)/.exec(m.userAgent)||[0,0])[1]:0,chrome:!!C,chrome_version:C?+C[1]:0,ios:A,android:/Android\b/.test(m.userAgent),webkit:M,webkit_version:M?+(/\bAppleWebKit\/(\d+)/.exec(m.userAgent)||[0,0])[1]:0,safari:k,safari_version:k?+(/\bVersion\/(\d+(\.\d+)?)/.exec(m.userAgent)||[0,0])[1]:0,tabSize:v.documentElement.style.tabSize!=null?"tab-size":"-moz-tab-size"};function D(t,e){for(let i in t){if(i=="class"&&e.class)e.class+=" "+t.class;else if(i=="style"&&e.style)e.style+=";"+t.style;else e[i]=t[i]}return e}const O=Object.create(null);function E(t,e,i){if(t==e)return true;if(!t)t=O;if(!e)e=O;let s=Object.keys(t),o=Object.keys(e);if(s.length-(i&&s.indexOf(i)>-1?1:0)!=o.length-(i&&o.indexOf(i)>-1?1:0))return false;for(let n of s){if(n!=i&&(o.indexOf(n)==-1||t[n]!==e[n]))return false}return true}function R(t,e){for(let i=t.attributes.length-1;i>=0;i--){let s=t.attributes[i].name;if(e[s]==null)t.removeAttribute(s)}for(let i in e){let s=e[i];if(i=="style")t.style.cssText=s;else if(t.getAttribute(i)!=s)t.setAttribute(i,s)}}function B(t,e,i){let s=false;if(e)for(let o in e)if(!(i&&o in i)){s=true;if(o=="style")t.style.cssText="";else t.removeAttribute(o)}if(i)for(let o in i)if(!(e&&e[o]==i[o])){s=true;if(o=="style")t.style.cssText=i[o];else t.setAttribute(o,i[o])}return s}function L(t){let e=Object.create(null);for(let i=0;i<t.attributes.length;i++){let s=t.attributes[i];e[s.name]=s.value}return e}class H{eq(t){return false}updateDOM(t,e){return false}compare(t){return this==t||this.constructor==t.constructor&&this.eq(t)}get estimatedHeight(){return-1}get lineBreaks(){return 0}ignoreEvent(t){return true}coordsAt(t,e,i){return null}get isHidden(){return false}get editable(){return false}destroy(t){}}var W=function(t){t[t["Text"]=0]="Text";t[t["WidgetBefore"]=1]="WidgetBefore";t[t["WidgetAfter"]=2]="WidgetAfter";t[t["WidgetRange"]=3]="WidgetRange";return t}(W||(W={}));class P extends s.RangeValue{constructor(t,e,i,s){super();this.startSide=t;this.endSide=e;this.widget=i;this.spec=s}get heightRelevant(){return false}static mark(t){return new N(t)}static widget(t){let e=Math.max(-1e4,Math.min(1e4,t.side||0)),i=!!t.block;e+=i&&!t.inlineOrder?e>0?3e8:-4e8:e>0?1e8:-1e8;return new F(t,e,e,i,t.widget||null,false)}static replace(t){let e=!!t.block,i,s;if(t.isBlockGap){i=-5e8;s=4e8}else{let{start:o,end:n}=z(t,e);i=(o?e?-3e8:-1:5e8)-1;s=(n?e?2e8:1:-6e8)+1}return new F(t,i,s,e,t.widget||null,true)}static line(t){return new V(t)}static set(t,e=false){return s.RangeSet.of(t,e)}hasHeight(){return this.widget?this.widget.estimatedHeight>-1:false}}P.none=s.RangeSet.empty;class N extends P{constructor(t){let{start:e,end:i}=z(t);super(e?-1:5e8,i?1:-6e8,null,t);this.tagName=t.tagName||"span";this.attrs=t.class&&t.attributes?D(t.attributes,{class:t.class}):t.class?{class:t.class}:t.attributes||O}eq(t){return this==t||t instanceof N&&this.tagName==t.tagName&&E(this.attrs,t.attrs)}range(t,e=t){if(t>=e)throw new RangeError("Mark decorations may not be empty");return super.range(t,e)}}N.prototype.point=false;class V extends P{constructor(t){super(-2e8,-2e8,null,t)}eq(t){return t instanceof V&&this.spec.class==t.spec.class&&E(this.spec.attributes,t.spec.attributes)}range(t,e=t){if(e!=t)throw new RangeError("Line decoration ranges must be zero-length");return super.range(t,e)}}V.prototype.mapMode=s.MapMode.TrackBefore;V.prototype.point=true;class F extends P{constructor(t,e,i,o,n,r){super(e,i,n,t);this.block=o;this.isReplace=r;this.mapMode=!o?s.MapMode.TrackDel:e<=0?s.MapMode.TrackBefore:s.MapMode.TrackAfter}get type(){return this.startSide!=this.endSide?W.WidgetRange:this.startSide<=0?W.WidgetBefore:W.WidgetAfter}get heightRelevant(){return this.block||!!this.widget&&(this.widget.estimatedHeight>=5||this.widget.lineBreaks>0)}eq(t){return t instanceof F&&I(this.widget,t.widget)&&this.block==t.block&&this.startSide==t.startSide&&this.endSide==t.endSide}range(t,e=t){if(this.isReplace&&(t>e||t==e&&this.startSide>0&&this.endSide<=0))throw new RangeError("Invalid range for replacement decoration");if(!this.isReplace&&e!=t)throw new RangeError("Widget decorations can only have zero-length ranges");return super.range(t,e)}}F.prototype.point=true;function z(t,e=false){let{inclusiveStart:i,inclusiveEnd:s}=t;if(i==null)i=t.inclusive;if(s==null)s=t.inclusive;return{start:i!==null&&i!==void 0?i:e,end:s!==null&&s!==void 0?s:e}}function I(t,e){return t==e||!!(t&&e&&t.compare(e))}function q(t,e,i,s=0){let o=i.length-1;if(o>=0&&i[o]+s>=t)i[o]=Math.max(i[o],e);else i.push(t,e)}class K extends s.RangeValue{constructor(t,e){super();this.tagName=t;this.attributes=e}eq(t){return t==this||t instanceof K&&this.tagName==t.tagName&&E(this.attributes,t.attributes)}static create(t){return new K(t.tagName,t.attributes||O)}static set(t,e=false){return s.RangeSet.of(t,e)}}K.prototype.startSide=K.prototype.endSide=-1;function _(t){let e;if(t.nodeType==11){e=t.getSelection?t:t.ownerDocument}else{e=t}return e.getSelection()}function Y(t,e){return e?t==e||t.contains(e.nodeType!=1?e.parentNode:e):false}function X(t,e){if(!e.anchorNode)return false;try{return Y(t,e.anchorNode)}catch(i){return false}}function G(t){if(t.nodeType==3)return at(t,0,t.nodeValue.length).getClientRects();else if(t.nodeType==1)return t.getClientRects();else return[]}function j(t,e,i,s){return i?Q(t,e,i,s,-1)||Q(t,e,i,s,1):false}function $(t){for(var e=0;;e++){t=t.previousSibling;if(!t)return e}}function U(t){return t.nodeType==1&&/^(DIV|P|LI|UL|OL|BLOCKQUOTE|DD|DT|H\d|SECTION|PRE)$/.test(t.nodeName)}function Q(t,e,i,s,o){for(;;){if(t==i&&e==s)return true;if(e==(o<0?0:J(t))){if(t.nodeName=="DIV")return false;let i=t.parentNode;if(!i||i.nodeType!=1)return false;e=$(t)+(o<0?0:1);t=i}else if(t.nodeType==1){t=t.childNodes[e+(o<0?-1:0)];if(t.nodeType==1&&t.contentEditable=="false")return false;e=o<0?J(t):0}else{return false}}}function J(t){return t.nodeType==3?t.nodeValue.length:t.childNodes.length}function Z(t,e){let i=e?t.left:t.right;return{left:i,right:i,top:t.top,bottom:t.bottom}}function tt(t){let e=t.visualViewport;if(e)return{left:0,right:e.width,top:0,bottom:e.height};return{left:0,right:t.innerWidth,top:0,bottom:t.innerHeight}}function et(t,e){let i=e.width/t.offsetWidth;let s=e.height/t.offsetHeight;if(i>.995&&i<1.005||!isFinite(i)||Math.abs(e.width-t.offsetWidth)<1)i=1;if(s>.995&&s<1.005||!isFinite(s)||Math.abs(e.height-t.offsetHeight)<1)s=1;return{scaleX:i,scaleY:s}}function it(t,e,i,s,o,n,r,l){let a=t.ownerDocument,h=a.defaultView||window;for(let c=t,f=false;c&&!f;){if(c.nodeType==1){let t,d=c==a.body;let u=1,p=1;if(d){t=tt(h)}else{if(/^(fixed|sticky)$/.test(getComputedStyle(c).position))f=true;if(c.scrollHeight<=c.clientHeight&&c.scrollWidth<=c.clientWidth){c=c.assignedSlot||c.parentNode;continue}let e=c.getBoundingClientRect();({scaleX:u,scaleY:p}=et(c,e));t={left:e.left,right:e.left+c.clientWidth*u,top:e.top,bottom:e.top+c.clientHeight*p}}let g=0,m=0;if(o=="nearest"){if(e.top<t.top){m=e.top-(t.top+r);if(i>0&&e.bottom>t.bottom+m)m=e.bottom-t.bottom+r}else if(e.bottom>t.bottom){m=e.bottom-t.bottom+r;if(i<0&&e.top-m<t.top)m=e.top-(t.top+r)}}else{let s=e.bottom-e.top,n=t.bottom-t.top;let l=o=="center"&&s<=n?e.top+s/2-n/2:o=="start"||o=="center"&&i<0?e.top-r:e.bottom-n+r;m=l-t.top}if(s=="nearest"){if(e.left<t.left){g=e.left-(t.left+n);if(i>0&&e.right>t.right+g)g=e.right-t.right+n}else if(e.right>t.right){g=e.right-t.right+n;if(i<0&&e.left<t.left+g)g=e.left-(t.left+n)}}else{let i=s=="center"?e.left+(e.right-e.left)/2-(t.right-t.left)/2:s=="start"==l?e.left-n:e.right-(t.right-t.left)+n;g=i-t.left}if(g||m){if(d){h.scrollBy(g,m)}else{let t=0,i=0;if(m){let t=c.scrollTop;c.scrollTop+=m/p;i=(c.scrollTop-t)*p}if(g){let e=c.scrollLeft;c.scrollLeft+=g/u;t=(c.scrollLeft-e)*u}e={left:e.left-t,top:e.top-i,right:e.right-t,bottom:e.bottom-i};if(t&&Math.abs(t-g)<1)s="nearest";if(i&&Math.abs(i-m)<1)o="nearest"}}if(d)break;if(e.top<t.top||e.bottom>t.bottom||e.left<t.left||e.right>t.right)e={left:Math.max(e.left,t.left),right:Math.min(e.right,t.right),top:Math.max(e.top,t.top),bottom:Math.min(e.bottom,t.bottom)};c=c.assignedSlot||c.parentNode}else if(c.nodeType==11){c=c.host}else{break}}}function st(t){let e=t.ownerDocument,i,s;for(let o=t.parentNode;o;){if(o==e.body||i&&s){break}else if(o.nodeType==1){if(!s&&o.scrollHeight>o.clientHeight)s=o;if(!i&&o.scrollWidth>o.clientWidth)i=o;o=o.assignedSlot||o.parentNode}else if(o.nodeType==11){o=o.host}else{break}}return{x:i,y:s}}class ot{constructor(){this.anchorNode=null;this.anchorOffset=0;this.focusNode=null;this.focusOffset=0}eq(t){return this.anchorNode==t.anchorNode&&this.anchorOffset==t.anchorOffset&&this.focusNode==t.focusNode&&this.focusOffset==t.focusOffset}setRange(t){let{anchorNode:e,focusNode:i}=t;this.set(e,Math.min(t.anchorOffset,e?J(e):0),i,Math.min(t.focusOffset,i?J(i):0))}set(t,e,i,s){this.anchorNode=t;this.anchorOffset=e;this.focusNode=i;this.focusOffset=s}}let nt=null;if(T.safari&&T.safari_version>=26)nt=false;function rt(t){if(t.setActive)return t.setActive();if(nt)return t.focus(nt);let e=[];for(let i=t;i;i=i.parentNode){e.push(i,i.scrollTop,i.scrollLeft);if(i==i.ownerDocument)break}t.focus(nt==null?{get preventScroll(){nt={preventScroll:true};return true}}:undefined);if(!nt){nt=false;for(let t=0;t<e.length;){let i=e[t++],s=e[t++],o=e[t++];if(i.scrollTop!=s)i.scrollTop=s;if(i.scrollLeft!=o)i.scrollLeft=o}}}let lt;function at(t,e,i=e){let s=lt||(lt=document.createRange());s.setEnd(t,i);s.setStart(t,e);return s}function ht(t,e,i,s){let o={key:e,code:e,keyCode:i,which:i,cancelable:true};if(s)({altKey:o.altKey,ctrlKey:o.ctrlKey,shiftKey:o.shiftKey,metaKey:o.metaKey}=s);let n=new KeyboardEvent("keydown",o);n.synthetic=true;t.dispatchEvent(n);let r=new KeyboardEvent("keyup",o);r.synthetic=true;t.dispatchEvent(r);return n.defaultPrevented||r.defaultPrevented}function ct(t){while(t){if(t&&(t.nodeType==9||t.nodeType==11&&t.host))return t;t=t.assignedSlot||t.parentNode}return null}function ft(t,e){let i=e.focusNode,s=e.focusOffset;if(!i||e.anchorNode!=i||e.anchorOffset!=s)return false;s=Math.min(s,J(i));for(;;){if(s){if(i.nodeType!=1)return false;let t=i.childNodes[s-1];if(t.contentEditable=="false")s--;else{i=t;s=J(i)}}else if(i==t){return true}else{s=$(i);i=i.parentNode}}}function dt(t){return t.scrollTop>Math.max(1,t.scrollHeight-t.clientHeight-4)}function ut(t,e){for(let i=t,s=e;;){if(i.nodeType==3&&s>0){return{node:i,offset:s}}else if(i.nodeType==1&&s>0){if(i.contentEditable=="false")return null;i=i.childNodes[s-1];s=J(i)}else if(i.parentNode&&!U(i)){s=$(i);i=i.parentNode}else{return null}}}function pt(t,e){for(let i=t,s=e;;){if(i.nodeType==3&&s<i.nodeValue.length){return{node:i,offset:s}}else if(i.nodeType==1&&s<i.childNodes.length){if(i.contentEditable=="false")return null;i=i.childNodes[s];s=0}else if(i.parentNode&&!U(i)){s=$(i)+1;i=i.parentNode}else{return null}}}class gt{constructor(t,e,i=true){this.node=t;this.offset=e;this.precise=i}static before(t,e){return new gt(t.parentNode,$(t),e)}static after(t,e){return new gt(t.parentNode,$(t)+1,e)}}var mt=function(t){t[t["LTR"]=0]="LTR";t[t["RTL"]=1]="RTL";return t}(mt||(mt={}));const vt=mt.LTR,wt=mt.RTL;function bt(t){let e=[];for(let i=0;i<t.length;i++)e.push(1<<+t[i]);return e}const yt=bt("88888888888888888888888888888888888666888888787833333333337888888000000000000000000000000008888880000000000000000000000000088888888888888888888888888888888888887866668888088888663380888308888800000000000000000000000800000000000000000000000000000008");const xt=bt("4444448826627288999999999992222222222222222222222222222222222222222222222229999999999999999999994444444444644222822222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222999999949999999229989999223333333333");const St=Object.create(null),Ct=[];for(let Gr of["()","[]","{}"]){let t=Gr.charCodeAt(0),e=Gr.charCodeAt(1);St[t]=e;St[e]=-t}function Mt(t){return t<=247?yt[t]:1424<=t&&t<=1524?2:1536<=t&&t<=1785?xt[t-1536]:1774<=t&&t<=2220?4:8192<=t&&t<=8204?256:64336<=t&&t<=65023?4:1}const kt=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac\ufb50-\ufdff]/;class At{get dir(){return this.level%2?wt:vt}constructor(t,e,i){this.from=t;this.to=e;this.level=i}side(t,e){return this.dir==e==t?this.to:this.from}forward(t,e){return t==(this.dir==e)}static find(t,e,i,s){let o=-1;for(let n=0;n<t.length;n++){let r=t[n];if(r.from<=e&&r.to>=e){if(r.level==i)return n;if(o<0||(s!=0?s<0?r.from<e:r.to>e:t[o].level>r.level))o=n}}if(o<0)throw new RangeError("Index out of range");return o}}function Tt(t,e){if(t.length!=e.length)return false;for(let i=0;i<t.length;i++){let s=t[i],o=e[i];if(s.from!=o.from||s.to!=o.to||s.direction!=o.direction||!Tt(s.inner,o.inner))return false}return true}const Dt=[];function Ot(t,e,i,s,o){for(let n=0;n<=s.length;n++){let r=n?s[n-1].to:e,l=n<s.length?s[n].from:i;let a=n?256:o;for(let e=r,i=a,s=a;e<l;e++){let o=Mt(t.charCodeAt(e));if(o==512)o=i;else if(o==8&&s==4)o=16;Dt[e]=o==4?2:o;if(o&7)s=o;i=o}for(let t=r,e=a,s=a;t<l;t++){let o=Dt[t];if(o==128){if(t<l-1&&e==Dt[t+1]&&e&24)o=Dt[t]=e;else Dt[t]=256}else if(o==64){let o=t+1;while(o<l&&Dt[o]==64)o++;let n=t&&e==8||o<i&&Dt[o]==8?s==1?1:8:256;for(let e=t;e<o;e++)Dt[e]=n;t=o-1}else if(o==8&&s==1){Dt[t]=1}e=o;if(o&7)s=o}}}function Et(t,e,i,s,o){let n=o==1?2:1;for(let r=0,l=0,a=0;r<=s.length;r++){let h=r?s[r-1].to:e,c=r<s.length?s[r].from:i;for(let e=h,i,s,r;e<c;e++){if(s=St[i=t.charCodeAt(e)]){if(s<0){for(let t=l-3;t>=0;t-=3){if(Ct[t+1]==-s){let i=Ct[t+2];let s=i&2?o:!(i&4)?0:i&1?n:o;if(s)Dt[e]=Dt[Ct[t]]=s;l=t;break}}}else if(Ct.length==189){break}else{Ct[l++]=e;Ct[l++]=i;Ct[l++]=a}}else if((r=Dt[e])==2||r==1){let t=r==o;a=t?0:1;for(let e=l-3;e>=0;e-=3){let i=Ct[e+2];if(i&2)break;if(t){Ct[e+2]|=2}else{if(i&4)break;Ct[e+2]|=4}}}}}}function Rt(t,e,i,s){for(let o=0,n=s;o<=i.length;o++){let r=o?i[o-1].to:t,l=o<i.length?i[o].from:e;for(let a=r;a<l;){let r=Dt[a];if(r==256){let r=a+1;for(;;){if(r==l){if(o==i.length)break;r=i[o++].to;l=o<i.length?i[o].from:e}else if(Dt[r]==256){r++}else{break}}let h=n==1;let c=(r<e?Dt[r]:s)==1;let f=h==c?h?1:2:s;for(let e=r,s=o,n=s?i[s-1].to:t;e>a;){if(e==n){e=i[--s].from;n=s?i[s-1].to:t}Dt[--e]=f}a=r}else{n=r;a++}}}}function Bt(t,e,i,s,o,n,r){let l=s%2?2:1;if(s%2==o%2){for(let a=e,h=0;a<i;){let e=true,c=false;if(h==n.length||a<n[h].from){let t=Dt[a];if(t!=l){e=false;c=t==16}}let f=!e&&l==1?[]:null;let d=e?s:s+1;let u=a;t:for(;;){if(h<n.length&&u==n[h].from){if(c)break t;let p=n[h];if(!e)for(let t=p.to,e=h+1;;){if(t==i)break t;if(e<n.length&&n[e].from==t)t=n[e++].to;else if(Dt[t]==l)break t;else break}h++;if(f){f.push(p)}else{if(p.from>a)r.push(new At(a,p.from,d));let e=p.direction==vt!=!(d%2);Lt(t,e?s+1:s,o,p.inner,p.from,p.to,r);a=p.to}u=p.to}else if(u==i||(e?Dt[u]!=l:Dt[u]==l)){break}else{u++}}if(f)Bt(t,a,u,s+1,o,f,r);else if(a<u)r.push(new At(a,u,d));a=u}}else{for(let a=i,h=n.length;a>e;){let i=true,c=false;if(!h||a>n[h-1].to){let t=Dt[a-1];if(t!=l){i=false;c=t==16}}let f=!i&&l==1?[]:null;let d=i?s:s+1;let u=a;t:for(;;){if(h&&u==n[h-1].to){if(c)break t;let p=n[--h];if(!i)for(let t=p.from,i=h;;){if(t==e)break t;if(i&&n[i-1].to==t)t=n[--i].from;else if(Dt[t-1]==l)break t;else break}if(f){f.push(p)}else{if(p.to<a)r.push(new At(p.to,a,d));let e=p.direction==vt!=!(d%2);Lt(t,e?s+1:s,o,p.inner,p.from,p.to,r);a=p.from}u=p.from}else if(u==e||(i?Dt[u-1]!=l:Dt[u-1]==l)){break}else{u--}}if(f)Bt(t,u,a,s+1,o,f,r);else if(u<a)r.push(new At(u,a,d));a=u}}}function Lt(t,e,i,s,o,n,r){let l=e%2?2:1;Ot(t,o,n,s,l);Et(t,o,n,s,l);Rt(o,n,s,l);Bt(t,o,n,e,i,s,r)}function Ht(t,e,i){if(!t)return[new At(0,0,e==wt?1:0)];if(e==vt&&!i.length&&!kt.test(t))return Wt(t.length);if(i.length)while(t.length>Dt.length)Dt[Dt.length]=256;let s=[],o=e==vt?0:1;Lt(t,o,o,i,0,t.length,s);return s}function Wt(t){return[new At(0,t,0)]}let Pt="";function Nt(t,e,i,o,n){var r;let l=o.head-t.from;let a=At.find(e,l,(r=o.bidiLevel)!==null&&r!==void 0?r:-1,o.assoc);let h=e[a],c=h.side(n,i);if(l==c){let t=a+=n?1:-1;if(t<0||t>=e.length)return null;h=e[a=t];l=h.side(!n,i);c=h.side(n,i)}let f=(0,s.findClusterBreak)(t.text,l,h.forward(n,i));if(f<h.from||f>h.to)f=c;Pt=t.text.slice(Math.min(l,f),Math.max(l,f));let d=a==(n?e.length-1:0)?null:e[a+(n?1:-1)];if(d&&f==c&&d.level+(n?0:1)<h.level)return s.EditorSelection.cursor(d.side(!n,i)+t.from,d.forward(n,i)?1:-1,d.level);return s.EditorSelection.cursor(f+t.from,h.forward(n,i)?-1:1,h.level)}function Vt(t,e,i){for(let s=e;s<i;s++){let e=Mt(t.charCodeAt(s));if(e==1)return vt;if(e==2||e==4)return wt}return vt}const Ft=s.Facet.define();const zt=s.Facet.define();const It=s.Facet.define();const qt=s.Facet.define();const Kt=s.Facet.define();const _t=s.Facet.define();const Yt=s.Facet.define();const Xt=s.Facet.define();const Gt=s.Facet.define();const jt=s.Facet.define({combine:t=>t.some((t=>t))});const $t=s.Facet.define({combine:t=>t.some((t=>t))});const Ut=s.Facet.define();class Qt{constructor(t,e="nearest",i="nearest",s=5,o=5,n=false){this.range=t;this.y=e;this.x=i;this.yMargin=s;this.xMargin=o;this.isSnapshot=n}map(t){return t.empty?this:new Qt(this.range.map(t),this.y,this.x,this.yMargin,this.xMargin,this.isSnapshot)}clip(t){return this.range.to<=t.doc.length?this:new Qt(s.EditorSelection.cursor(t.doc.length),this.y,this.x,this.yMargin,this.xMargin,this.isSnapshot)}}const Jt=s.StateEffect.define({map:(t,e)=>t.map(e)});const Zt=s.StateEffect.define();function te(t,e,i){let s=t.facet(qt);if(s.length)s[0](e);else if(window.onerror&&window.onerror(String(e),i,undefined,undefined,e));else if(i)console.error(i+":",e);else console.error(e)}const ee=s.Facet.define({combine:t=>t.length?t[0]:true});let ie=0;const se=s.Facet.define({combine(t){return t.filter(((e,i)=>{for(let s=0;s<i;s++)if(t[s].plugin==e.plugin)return false;return true}))}});class oe{constructor(t,e,i,s,o){this.id=t;this.create=e;this.domEventHandlers=i;this.domEventObservers=s;this.baseExtensions=o(this);this.extension=this.baseExtensions.concat(se.of({plugin:this,arg:undefined}))}of(t){return this.baseExtensions.concat(se.of({plugin:this,arg:t}))}static define(t,e){const{eventHandlers:i,eventObservers:s,provide:o,decorations:n}=e||{};return new oe(ie++,t,i,s,(t=>{let e=[];if(n)e.push(ae.of((e=>{let i=e.plugin(t);return i?n(i):P.none})));if(o)e.push(o(t));return e}))}static fromClass(t,e){return oe.define(((e,i)=>new t(e,i)),e)}}class ne{constructor(t){this.spec=t;this.mustUpdate=null;this.value=null}get plugin(){return this.spec&&this.spec.plugin}update(t){if(!this.value){if(this.spec){try{this.value=this.spec.plugin.create(t,this.spec.arg)}catch(e){te(t.state,e,"CodeMirror plugin crashed");this.deactivate()}}}else if(this.mustUpdate){let t=this.mustUpdate;this.mustUpdate=null;if(this.value.update){try{this.value.update(t)}catch(e){te(t.state,e,"CodeMirror plugin crashed");if(this.value.destroy)try{this.value.destroy()}catch(i){}this.deactivate()}}}return this}destroy(t){var e;if((e=this.value)===null||e===void 0?void 0:e.destroy){try{this.value.destroy()}catch(i){te(t.state,i,"CodeMirror plugin crashed")}}}deactivate(){this.spec=this.value=null}}const re=s.Facet.define();const le=s.Facet.define();const ae=s.Facet.define();const he=s.Facet.define();const ce=s.Facet.define();const fe=s.Facet.define();const de=s.Facet.define();function ue(t,e){let i=t.state.facet(de);if(!i.length)return i;let o=i.map((e=>e instanceof Function?e(t):e));let n=[];s.RangeSet.spans(o,e.from,e.to,{point(){},span(t,i,s,o){let r=t-e.from,l=i-e.from;let a=n;for(let n=s.length-1;n>=0;n--,o--){let t=s[n].spec.bidiIsolate,i;if(t==null)t=Vt(e.text,r,l);if(o>0&&a.length&&(i=a[a.length-1]).to==r&&i.direction==t){i.to=l;a=i.inner}else{let e={from:r,to:l,direction:t,inner:[]};a.push(e);a=e.inner}}}});return n}const pe=s.Facet.define();function ge(t){let e=0,i=0,s=0,o=0;for(let n of t.state.facet(pe)){let r=n(t);if(r){if(r.left!=null)e=Math.max(e,r.left);if(r.right!=null)i=Math.max(i,r.right);if(r.top!=null)s=Math.max(s,r.top);if(r.bottom!=null)o=Math.max(o,r.bottom)}}return{left:e,right:i,top:s,bottom:o}}const me=s.Facet.define();class ve{constructor(t,e,i,s){this.fromA=t;this.toA=e;this.fromB=i;this.toB=s}join(t){return new ve(Math.min(this.fromA,t.fromA),Math.max(this.toA,t.toA),Math.min(this.fromB,t.fromB),Math.max(this.toB,t.toB))}addToSet(t){let e=t.length,i=this;for(;e>0;e--){let s=t[e-1];if(s.fromA>i.toA)continue;if(s.toA<i.fromA)break;i=i.join(s);t.splice(e-1,1)}t.splice(e,0,i);return t}static extendWithRanges(t,e){if(e.length==0)return t;let i=[];for(let s=0,o=0,n=0;;){let r=s<t.length?t[s].fromB:1e9;let l=o<e.length?e[o]:1e9;let a=Math.min(r,l);if(a==1e9)break;let h=a+n,c=a,f=h;for(;;){if(o<e.length&&e[o]<=c){let i=e[o+1];o+=2;c=Math.max(c,i);for(let e=s;e<t.length&&t[e].fromB<=c;e++)n=t[e].toA-t[e].toB;f=Math.max(f,i+n)}else if(s<t.length&&t[s].fromB<=c){let e=t[s++];c=Math.max(c,e.toB);f=Math.max(f,e.toA);n=e.toA-e.toB}else{break}}i.push(new ve(h,f,a,c))}return i}}class we{constructor(t,e,i){this.view=t;this.state=e;this.transactions=i;this.flags=0;this.startState=t.state;this.changes=s.ChangeSet.empty(this.startState.doc.length);for(let s of i)this.changes=this.changes.compose(s.changes);let o=[];this.changes.iterChangedRanges(((t,e,i,s)=>o.push(new ve(t,e,i,s))));this.changedRanges=o}static create(t,e,i){return new we(t,e,i)}get viewportChanged(){return(this.flags&4)>0}get viewportMoved(){return(this.flags&8)>0}get heightChanged(){return(this.flags&2)>0}get geometryChanged(){return this.docChanged||(this.flags&(16|2))>0}get focusChanged(){return(this.flags&1)>0}get docChanged(){return!this.changes.empty}get selectionSet(){return this.transactions.some((t=>t.selection))}get empty(){return this.flags==0&&this.transactions.length==0}}const be=[];class ye{constructor(t,e,i=0){this.dom=t;this.length=e;this.flags=i;this.parent=null;t.cmTile=this}get breakAfter(){return this.flags&1}get children(){return be}isWidget(){return false}get isHidden(){return false}isComposite(){return false}isLine(){return false}isText(){return false}isBlock(){return false}get domAttrs(){return null}sync(t){this.flags|=2;if(this.flags&4){this.flags&=~4;let t=this.domAttrs;if(t)R(this.dom,t)}}toString(){return this.constructor.name+(this.children.length?`(${this.children})`:"")+(this.breakAfter?"#":"")}destroy(){this.parent=null}setDOM(t){this.dom=t;t.cmTile=this}get posAtStart(){return this.parent?this.parent.posBefore(this):0}get posAtEnd(){return this.posAtStart+this.length}posBefore(t,e=this.posAtStart){let i=e;for(let s of this.children){if(s==t)return i;i+=s.length+s.breakAfter}throw new RangeError("Invalid child in posBefore")}posAfter(t){return this.posBefore(t)+t.length}covers(t){return true}coordsIn(t,e){return null}domPosFor(t,e){let i=$(this.dom);let s=this.length?t>0:e>0;return new gt(this.parent.dom,i+(s?1:0),t==0||t==this.length)}markDirty(t){this.flags&=~2;if(t)this.flags|=4;if(this.parent&&this.parent.flags&2)this.parent.markDirty(false)}get overrideDOMText(){return null}get root(){for(let t=this;t;t=t.parent)if(t instanceof Ce)return t;return null}static get(t){return t.cmTile}}class xe extends ye{constructor(t){super(t,0);this._children=[]}isComposite(){return true}get children(){return this._children}get lastChild(){return this.children.length?this.children[this.children.length-1]:null}append(t){this.children.push(t);t.parent=this}sync(t){if(this.flags&2)return;super.sync(t);let e=this.dom,i=null,s;let o=(t===null||t===void 0?void 0:t.node)==e?t:null;let n=0;for(let r of this.children){r.sync(t);n+=r.length+r.breakAfter;s=i?i.nextSibling:e.firstChild;if(o&&s!=r.dom)o.written=true;if(r.dom.parentNode==e){while(s&&s!=r.dom)s=Se(s)}else{e.insertBefore(r.dom,s)}i=r.dom}s=i?i.nextSibling:e.firstChild;if(o&&s)o.written=true;while(s)s=Se(s);this.length=n}}function Se(t){let e=t.nextSibling;t.parentNode.removeChild(t);return e}class Ce extends xe{constructor(t,e){super(e);this.view=t}owns(t){for(;t;t=t.parent)if(t==this)return true;return false}isBlock(){return true}nearest(t){for(;;){if(!t)return null;let e=ye.get(t);if(e&&this.owns(e))return e;t=t.parentNode}}blockTiles(t){for(let e=[],i=this,s=0,o=0;;){if(s==i.children.length){if(!e.length)return;i=i.parent;if(i.breakAfter)o++;s=e.pop()}else{let n=i.children[s++];if(n instanceof Me){e.push(s);i=n;s=0}else{let e=o+n.length;let i=t(n,o);if(i!==undefined)return i;o=e+n.breakAfter}}}}resolveBlock(t,e){let i,s=-1,o,n=-1;this.blockTiles(((r,l)=>{let a=l+r.length;if(t>=l&&t<=a){if(r.isWidget()&&e>=-1&&e<=1){if(r.flags&32)return true;if(r.flags&16)i=undefined}if((l<t||t==a&&(e<-1?r.length:r.covers(1)))&&(!i||!r.isWidget()&&i.isWidget())){i=r;s=t-l}if((a>t||t==l&&(e>1?r.length:r.covers(-1)))&&(!o||!r.isWidget()&&o.isWidget())){o=r;n=t-l}}}));if(!i&&!o)throw new Error("No tile at position "+t);return i&&e<0||!o?{tile:i,offset:s}:{tile:o,offset:n}}}class Me extends xe{constructor(t,e){super(t);this.wrapper=e}isBlock(){return true}covers(t){if(!this.children.length)return false;return t<0?this.children[0].covers(-1):this.lastChild.covers(1)}get domAttrs(){return this.wrapper.attributes}static of(t,e){let i=new Me(e||document.createElement(t.tagName),t);if(!e)i.flags|=4;return i}}class ke extends xe{constructor(t,e){super(t);this.attrs=e}isLine(){return true}static start(t,e,i){let s=new ke(e||document.createElement("div"),t);if(!e||!i)s.flags|=4;return s}get domAttrs(){return this.attrs}resolveInline(t,e,i){let s=null,o=-1,n=null,r=-1;function l(t,a){for(let h=0,c=0;h<t.children.length&&c<=a;h++){let f=t.children[h],d=c+f.length;if(d>=a){if(f.isComposite()){l(f,a-c)}else if((!n||n.isHidden&&(e>0||i&&Te(n,f)))&&(d>a||f.flags&32)){n=f;r=a-c}else if(c<a||f.flags&16&&!f.isHidden){s=f;o=a-c}}c=d}}l(this,t);let a=(e<0?s:n)||s||n;return a?{tile:a,offset:a==s?o:r}:null}coordsIn(t,e){let i=this.resolveInline(t,e,true);if(!i)return Ae(this);return i.tile.coordsIn(Math.max(0,i.offset),e)}domIn(t,e){let i=this.resolveInline(t,e);if(i){let{tile:t,offset:s}=i;if(this.dom.contains(t.dom)){if(t.isText())return new gt(t.dom,Math.min(t.dom.nodeValue.length,s));return t.domPosFor(s,t.flags&16?1:t.flags&32?-1:e)}let o=i.tile.parent,n=false;for(let e of o.children){if(n)return new gt(e.dom,0);if(e==i.tile){n=true}}}return new gt(this.dom,0)}}function Ae(t){let e=t.dom.lastChild;if(!e)return t.dom.getBoundingClientRect();let i=G(e);return i[i.length-1]||null}function Te(t,e){let i=t.coordsIn(0,1),s=e.coordsIn(0,1);return i&&s&&s.top<i.bottom}class De extends xe{constructor(t,e){super(t);this.mark=e}get domAttrs(){return this.mark.attrs}static of(t,e){let i=new De(e||document.createElement(t.tagName),t);if(!e)i.flags|=4;return i}}class Oe extends ye{constructor(t,e){super(t,e.length);this.text=e}sync(t){if(this.flags&2)return;super.sync(t);if(this.dom.nodeValue!=this.text){if(t&&t.node==this.dom)t.written=true;this.dom.nodeValue=this.text}}isText(){return true}toString(){return JSON.stringify(this.text)}coordsIn(t,e){let i=this.dom.nodeValue.length;if(t>i)t=i;let s=t,o=t,n=0;if(t==0&&e<0||t==i&&e>=0){if(!(T.chrome||T.gecko)){if(t){s--;n=1}else if(o<i){o++;n=-1}}}else{if(e<0)s--;else if(o<i)o++}let r=at(this.dom,s,o).getClientRects();if(!r.length)return null;let l=r[(n?n<0:e>=0)?0:r.length-1];if(T.safari&&!n&&l.width==0)l=Array.prototype.find.call(r,(t=>t.width))||l;return n?Z(l,n<0):l||null}static of(t,e){let i=new Oe(e||document.createTextNode(t),t);if(!e)i.flags|=2;return i}}class Ee extends ye{constructor(t,e,i,s){super(t,e,s);this.widget=i}isWidget(){return true}get isHidden(){return this.widget.isHidden}covers(t){if(this.flags&48)return false;return(this.flags&(t<0?64:128))>0}coordsIn(t,e){return this.coordsInWidget(t,e,false)}coordsInWidget(t,e,i){let s=this.widget.coordsAt(this.dom,t,e);if(s)return s;if(i){return Z(this.dom.getBoundingClientRect(),this.length?t==0:e<=0)}else{let e=this.dom.getClientRects(),i=null;if(!e.length)return null;let s=this.flags&16?true:this.flags&32?false:t>0;for(let o=s?e.length-1:0;;o+=s?-1:1){i=e[o];if(t>0?o==0:o==e.length-1||i.top<i.bottom)break}return Z(i,!s)}}get overrideDOMText(){if(!this.length)return s.Text.empty;let{root:t}=this;if(!t)return s.Text.empty;let e=this.posAtStart;return t.view.state.doc.slice(e,e+this.length)}destroy(){super.destroy();this.widget.destroy(this.dom)}static of(t,e,i,s,o){if(!o){o=t.toDOM(e);if(!t.editable)o.contentEditable="false"}return new Ee(o,i,t,s)}}class Re extends ye{constructor(t){let e=document.createElement("img");e.className="cm-widgetBuffer";e.setAttribute("aria-hidden","true");super(e,0,t)}get isHidden(){return true}get overrideDOMText(){return s.Text.empty}coordsIn(t){return this.dom.getBoundingClientRect()}}class Be{constructor(t){this.index=0;this.beforeBreak=false;this.parents=[];this.tile=t}advance(t,e,i){let{tile:s,index:o,beforeBreak:n,parents:r}=this;while(t||e>0){if(!s.isComposite()){if(o==s.length){n=!!s.breakAfter;({tile:s,index:o}=r.pop());o++}else if(!t){break}else{let e=Math.min(t,s.length-o);if(i)i.skip(s,o,o+e);t-=e;o+=e}}else if(n){if(!t)break;if(i)i.break();t--;n=false}else if(o==s.children.length){if(!t&&!r.length)break;if(i)i.leave(s);n=!!s.breakAfter;({tile:s,index:o}=r.pop());o++}else{let l=s.children[o],a=l.breakAfter;if((e>0?l.length<=t:l.length<t)&&(!i||i.skip(l,0,l.length)!==false||!l.isComposite)){n=!!a;o++;t-=l.length}else{r.push({tile:s,index:o});s=l;o=0;if(i&&l.isComposite())i.enter(l)}}}this.tile=s;this.index=o;this.beforeBreak=n;return this}get root(){return this.parents.length?this.parents[0].tile:this.tile}}class Le{constructor(t,e,i,s){this.from=t;this.to=e;this.wrapper=i;this.rank=s}}class He{constructor(t,e,i){this.cache=t;this.root=e;this.blockWrappers=i;this.curLine=null;this.lastBlock=null;this.afterWidget=null;this.pos=0;this.wrappers=[];this.wrapperPos=0}addText(t,e,i,s){var o;this.flushBuffer();let n=this.ensureMarks(e,i);let r=n.lastChild;if(r&&r.isText()&&!(r.flags&8)&&r.length+t.length<512){this.cache.reused.set(r,2);let e=n.children[n.children.length-1]=new Oe(r.dom,r.text+t);e.parent=n}else{n.append(s||Oe.of(t,(o=this.cache.find(Oe))===null||o===void 0?void 0:o.dom))}this.pos+=t.length;this.afterWidget=null}addComposition(t,e){let i=this.curLine;if(i.dom!=e.line.dom){i.setDOM(this.cache.reused.has(e.line)?_e(e.line.dom):e.line.dom);this.cache.reused.set(e.line,2)}let s=i;for(let r=e.marks.length-1;r>=0;r--){let t=e.marks[r];let i=s.lastChild;if(i instanceof De&&i.mark.eq(t.mark)){if(i.dom!=t.dom)i.setDOM(_e(t.dom));s=i}else{if(this.cache.reused.get(t)){let e=ye.get(t.dom);if(e)e.setDOM(_e(t.dom))}let e=De.of(t.mark,t.dom);s.append(e);s=e}this.cache.reused.set(t,2)}let o=ye.get(t.text);if(o)this.cache.reused.set(o,2);let n=new Oe(t.text,t.text.nodeValue);n.flags|=8;s.append(n)}addInlineWidget(t,e,i){let s=this.afterWidget&&t.flags&48&&(this.afterWidget.flags&48)==(t.flags&48);if(!s)this.flushBuffer();let o=this.ensureMarks(e,i);if(!s&&!(t.flags&16))o.append(this.getBuffer(1));o.append(t);this.pos+=t.length;this.afterWidget=t}addMark(t,e,i){this.flushBuffer();let s=this.ensureMarks(e,i);s.append(t);this.pos+=t.length;this.afterWidget=null}addBlockWidget(t){this.getBlockPos().append(t);this.pos+=t.length;this.lastBlock=t;this.endLine()}continueWidget(t){let e=this.afterWidget||this.lastBlock;e.length+=t;this.pos+=t}addLineStart(t,e){var i;if(!t)t=Ie;let s=ke.start(t,e||((i=this.cache.find(ke))===null||i===void 0?void 0:i.dom),!!e);this.getBlockPos().append(this.lastBlock=this.curLine=s)}addLine(t){this.getBlockPos().append(t);this.pos+=t.length;this.lastBlock=t;this.endLine()}addBreak(){this.lastBlock.flags|=1;this.endLine();this.pos++}addLineStartIfNotCovered(t){if(!this.blockPosCovered())this.addLineStart(t)}ensureLine(t){if(!this.curLine)this.addLineStart(t)}ensureMarks(t,e){var i;let s=this.curLine;for(let o=t.length-1;o>=0;o--){let n=t[o],r;if(e>0&&(r=s.lastChild)&&r instanceof De&&r.mark.eq(n)){s=r;e--}else{let t=De.of(n,(i=this.cache.find(De,(t=>t.mark.eq(n))))===null||i===void 0?void 0:i.dom);s.append(t);s=t;e=0}}return s}endLine(){if(this.curLine){this.flushBuffer();let t=this.curLine.lastChild;if(!t||!Fe(this.curLine,false)||t.dom.nodeName!="BR"&&t.isWidget()&&!(T.ios&&Fe(this.curLine,true)))this.curLine.append(this.cache.findWidget(Xe,0,32)||new Ee(Xe.toDOM(),0,Xe,32));this.curLine=this.afterWidget=null}}updateBlockWrappers(){if(this.wrapperPos>this.pos+1e4){this.blockWrappers.goto(this.pos);this.wrappers.length=0}for(let t=this.wrappers.length-1;t>=0;t--)if(this.wrappers[t].to<this.pos)this.wrappers.splice(t,1);for(let t=this.blockWrappers;t.value&&t.from<=this.pos;t.next())if(t.to>=this.pos){let e=new Le(t.from,t.to,t.value,t.rank),i=this.wrappers.length;while(i>0&&(this.wrappers[i-1].rank-e.rank||this.wrappers[i-1].to-e.to)<0)i--;this.wrappers.splice(i,0,e)}this.wrapperPos=this.pos}getBlockPos(){var t;this.updateBlockWrappers();let e=this.root;for(let i of this.wrappers){let s=e.lastChild;if(i.from<this.pos&&s instanceof Me&&s.wrapper.eq(i.wrapper)){e=s}else{let s=Me.of(i.wrapper,(t=this.cache.find(Me,(t=>t.wrapper.eq(i.wrapper))))===null||t===void 0?void 0:t.dom);e.append(s);e=s}}return e}blockPosCovered(){let t=this.lastBlock;return t!=null&&!t.breakAfter&&(!t.isWidget()||(t.flags&(32|128))>0)}getBuffer(t){let e=2|(t<0?16:32);let i=this.cache.find(Re,undefined,1);if(i)i.flags=e;return i||new Re(e)}flushBuffer(){if(this.afterWidget&&!(this.afterWidget.flags&32)){this.afterWidget.parent.append(this.getBuffer(-1));this.afterWidget=null}}}class We{constructor(t){this.skipCount=0;this.text="";this.textOff=0;this.cursor=t.iter()}skip(t){if(this.textOff+t<=this.text.length){this.textOff+=t}else{this.skipCount+=t-(this.text.length-this.textOff);this.text="";this.textOff=0}}next(t){if(this.textOff==this.text.length){let{value:e,lineBreak:i,done:s}=this.cursor.next(this.skipCount);this.skipCount=0;if(s)throw new Error("Ran out of text content when drawing inline views");this.text=e;let o=this.textOff=Math.min(t,e.length);return i?null:e.slice(0,o)}let e=Math.min(this.text.length,this.textOff+t);let i=this.text.slice(this.textOff,e);this.textOff=e;return i}}const Pe=[Ee,ke,Oe,De,Re,Me,Ce];for(let Gr=0;Gr<Pe.length;Gr++)Pe[Gr].bucket=Gr;class Ne{constructor(t){this.view=t;this.buckets=Pe.map((()=>[]));this.index=Pe.map((()=>0));this.reused=new Map}add(t){let e=t.constructor.bucket,i=this.buckets[e];if(i.length<6)i.push(t);else i[this.index[e]=(this.index[e]+1)%6]=t}find(t,e,i=2){let s=t.bucket;let o=this.buckets[s],n=this.index[s];for(let r=o.length-1;r>=0;r--){let t=(r+n)%o.length,l=o[t];if((!e||e(l))&&!this.reused.has(l)){o.splice(t,1);if(t<n)this.index[s]--;this.reused.set(l,i);return l}}return null}findWidget(t,e,i){let s=this.buckets[0];if(s.length)for(let o=0,n=0;;o++){if(o==s.length){if(n)return null;n=1;o=0}let r=s[o];if(!this.reused.has(r)&&(n==0?r.widget.compare(t):r.widget.constructor==t.constructor&&t.updateDOM(r.dom,this.view))){s.splice(o,1);if(o<this.index[0])this.index[0]--;if(r.widget==t&&r.length==e&&(r.flags&(496|1))==i){this.reused.set(r,1);return r}else{this.reused.set(r,2);return new Ee(r.dom,e,t,r.flags&~(496|1)|i)}}}}reuse(t){this.reused.set(t,1);return t}maybeReuse(t,e=2){if(this.reused.has(t))return undefined;this.reused.set(t,e);return t.dom}clear(){for(let t=0;t<this.buckets.length;t++)this.buckets[t].length=this.index[t]=0}}class Ve{constructor(t,e,i,o,n){this.view=t;this.decorations=o;this.disallowBlockEffectsFor=n;this.openWidget=false;this.openMarks=0;this.cache=new Ne(t);this.text=new We(t.state.doc);this.builder=new He(this.cache,new Ce(t,t.contentDOM),s.RangeSet.iter(i));this.cache.reused.set(e,2);this.old=new Be(e);this.reuseWalker={skip:(t,e,i)=>{this.cache.add(t);if(t.isComposite())return false},enter:t=>this.cache.add(t),leave:()=>{},break:()=>{}}}run(t,e){let i=e&&this.getCompositionContext(e.text);for(let s=0,o=0,n=0;;){let r=n<t.length?t[n++]:null;let l=r?r.fromA:this.old.root.length;if(l>s){let t=l-s;this.preserve(t,!n,!r);s=l;o+=t}if(!r)break;if(e&&r.fromA<=e.range.fromA&&r.toA>=e.range.toA){this.forward(r.fromA,e.range.fromA,e.range.fromA<e.range.toA?1:-1);this.emit(o,e.range.fromB);this.cache.clear();this.builder.addComposition(e,i);this.text.skip(e.range.toB-e.range.fromB);this.forward(e.range.fromA,r.toA);this.emit(e.range.toB,r.toB)}else{this.forward(r.fromA,r.toA);this.emit(o,r.toB)}o=r.toB;s=r.toA}if(this.builder.curLine)this.builder.endLine();return this.builder.root}preserve(t,e,i){let s=Ke(this.old),o=this.openMarks;this.old.advance(t,i?1:-1,{skip:(t,e,i)=>{if(t.isWidget()){if(this.openWidget){this.builder.continueWidget(i-e)}else{let n=i>0||e<t.length?Ee.of(t.widget,this.view,i-e,t.flags&496,this.cache.maybeReuse(t)):this.cache.reuse(t);if(n.flags&256){n.flags&=~1;this.builder.addBlockWidget(n)}else{this.builder.ensureLine(null);this.builder.addInlineWidget(n,s,o);o=s.length}}}else if(t.isText()){this.builder.ensureLine(null);if(!e&&i==t.length){this.builder.addText(t.text,s,o,this.cache.reuse(t))}else{this.cache.add(t);this.builder.addText(t.text.slice(e,i),s,o)}o=s.length}else if(t.isLine()){t.flags&=~1;this.cache.reused.set(t,1);this.builder.addLine(t)}else if(t instanceof Re){this.cache.add(t)}else if(t instanceof De){this.builder.ensureLine(null);this.builder.addMark(t,s,o);this.cache.reused.set(t,1);o=s.length}else{return false}this.openWidget=false},enter:t=>{if(t.isLine()){this.builder.addLineStart(t.attrs,this.cache.maybeReuse(t))}else{this.cache.add(t);if(t instanceof De)s.unshift(t.mark)}this.openWidget=false},leave:t=>{if(t.isLine()){if(s.length)s.length=o=0}else if(t instanceof De){s.shift();o=Math.min(o,s.length)}},break:()=>{this.builder.addBreak();this.openWidget=false}});this.text.skip(t)}emit(t,e){let i=null;let o=this.builder,n=0;let r=s.RangeSet.spans(this.decorations,t,e,{point:(t,e,s,r,l,a)=>{if(s instanceof F){if(this.disallowBlockEffectsFor[a]){if(s.block)throw new RangeError("Block decorations may not be specified via plugins");if(e>this.view.state.doc.lineAt(t).to)throw new RangeError("Decorations that replace line breaks may not be specified via plugins")}n=r.length;if(l>r.length){o.continueWidget(e-t)}else{let n=s.widget||(s.block?Ye.block:Ye.inline);let a=ze(s);let h=this.cache.findWidget(n,e-t,a)||Ee.of(n,this.view,e-t,a);if(s.block){if(s.startSide>0)o.addLineStartIfNotCovered(i);o.addBlockWidget(h)}else{o.ensureLine(i);o.addInlineWidget(h,r,l)}}i=null}else{i=qe(i,s)}if(e>t)this.text.skip(e-t)},span:(t,e,s,n)=>{for(let r=t;r<e;){let l=this.text.next(Math.min(512,e-r));if(l==null){o.addLineStartIfNotCovered(i);o.addBreak();r++}else{o.ensureLine(i);o.addText(l,s,r==t?n:s.length);r+=l.length}i=null}}});o.addLineStartIfNotCovered(i);this.openWidget=r>n;this.openMarks=r}forward(t,e,i=1){if(e-t<=10){this.old.advance(e-t,i,this.reuseWalker)}else{this.old.advance(5,-1,this.reuseWalker);this.old.advance(e-t-10,-1);this.old.advance(5,i,this.reuseWalker)}}getCompositionContext(t){let e=[],i=null;for(let s=t.parentNode;;s=s.parentNode){let t=ye.get(s);if(s==this.view.contentDOM)break;if(t instanceof De)e.push(t);else if(t===null||t===void 0?void 0:t.isLine())i=t;else if(s.nodeName=="DIV"&&!i&&s!=this.view.contentDOM)i=new ke(s,Ie);else e.push(De.of(new N({tagName:s.nodeName.toLowerCase(),attributes:L(s)}),s))}return{line:i,marks:e}}}function Fe(t,e){let i=t=>{for(let s of t.children)if((e?s.isText():s.length)||i(s))return true;return false};return i(t)}function ze(t){let e=t.isReplace?(t.startSide<0?64:0)|(t.endSide>0?128:0):t.startSide>0?32:16;if(t.block)e|=256;return e}const Ie={class:"cm-line"};function qe(t,e){let i=e.spec.attributes,s=e.spec.class;if(!i&&!s)return t;if(!t)t={class:"cm-line"};if(i)D(i,t);if(s)t.class+=" "+s;return t}function Ke(t){let e=[];for(let i=t.parents.length;i>1;i--){let s=i==t.parents.length?t.tile:t.parents[i].tile;if(s instanceof De)e.push(s.mark)}return e}function _e(t){let e=ye.get(t);if(e)e.setDOM(t.cloneNode());return t}class Ye extends H{constructor(t){super();this.tag=t}eq(t){return t.tag==this.tag}toDOM(){return document.createElement(this.tag)}updateDOM(t){return t.nodeName.toLowerCase()==this.tag}get isHidden(){return true}}Ye.inline=new Ye("span");Ye.block=new Ye("div");const Xe=new class extends H{toDOM(){return document.createElement("br")}get isHidden(){return true}get editable(){return true}};class Ge{constructor(t){this.view=t;this.decorations=[];this.blockWrappers=[];this.dynamicDecorationMap=[false];this.domChanged=null;this.hasComposition=null;this.editContextFormatting=P.none;this.lastCompositionAfterCursor=false;this.minWidth=0;this.minWidthFrom=0;this.minWidthTo=0;this.impreciseAnchor=null;this.impreciseHead=null;this.forceSelection=false;this.lastUpdate=Date.now();this.updateDeco();this.tile=new Ce(t,t.contentDOM);this.updateInner([new ve(0,0,0,t.state.doc.length)],null)}update(t){var e;let i=t.changedRanges;if(this.minWidth>0&&i.length){if(!i.every((({fromA:t,toA:e})=>e<this.minWidthFrom||t>this.minWidthTo))){this.minWidth=this.minWidthFrom=this.minWidthTo=0}else{this.minWidthFrom=t.changes.mapPos(this.minWidthFrom,1);this.minWidthTo=t.changes.mapPos(this.minWidthTo,1)}}this.updateEditContextFormatting(t);let s=-1;if(this.view.inputState.composing>=0&&!this.view.observer.editContext){if((e=this.domChanged)===null||e===void 0?void 0:e.newSel)s=this.domChanged.newSel.head;else if(!oi(t.changes,this.hasComposition)&&!t.selectionSet)s=t.state.selection.main.head}let o=s>-1?Qe(this.view,t.changes,s):null;this.domChanged=null;if(this.hasComposition){let{from:e,to:s}=this.hasComposition;i=new ve(e,s,t.changes.mapPos(e,-1),t.changes.mapPos(s,1)).addToSet(i.slice())}this.hasComposition=o?{from:o.range.fromB,to:o.range.toB}:null;if((T.ie||T.chrome)&&!o&&t&&t.state.doc.lines!=t.startState.doc.lines)this.forceSelection=true;let n=this.decorations,r=this.blockWrappers;this.updateDeco();let l=ti(n,this.decorations,t.changes);if(l.length)i=ve.extendWithRanges(i,l);let a=ii(r,this.blockWrappers,t.changes);if(a.length)i=ve.extendWithRanges(i,a);if(o&&!i.some((t=>t.fromA<=o.range.fromA&&t.toA>=o.range.toA)))i=o.range.addToSet(i.slice());if(this.tile.flags&2&&i.length==0){return false}else{this.updateInner(i,o);if(t.transactions.length)this.lastUpdate=Date.now();return true}}updateInner(t,e){this.view.viewState.mustMeasureContent=true;let{observer:i}=this.view;i.ignore((()=>{if(e||t.length){let i=this.tile;let s=new Ve(this.view,i,this.blockWrappers,this.decorations,this.dynamicDecorationMap);this.tile=s.run(t,e);je(i,s.cache.reused)}this.tile.dom.style.height=this.view.viewState.contentHeight/this.view.scaleY+"px";this.tile.dom.style.flexBasis=this.minWidth?this.minWidth+"px":"";let s=T.chrome||T.ios?{node:i.selectionRange.focusNode,written:false}:undefined;this.tile.sync(s);if(s&&(s.written||i.selectionRange.focusNode!=s.node||!this.tile.dom.contains(s.node)))this.forceSelection=true;this.tile.dom.style.height=""}));let s=[];if(this.view.viewport.from||this.view.viewport.to<this.view.state.doc.length)for(let o of this.tile.children)if(o.isWidget()&&o.widget instanceof ni)s.push(o.dom);i.updateGaps(s)}updateEditContextFormatting(t){this.editContextFormatting=this.editContextFormatting.map(t.changes);for(let e of t.transactions)for(let t of e.effects)if(t.is(Zt)){this.editContextFormatting=t.value}}updateSelection(t=false,e=false){if(t||!this.view.observer.selectionRange.focusNode)this.view.observer.readSelectionRange();let{dom:i}=this.tile;let s=this.view.root.activeElement,o=s==i;let n=!o&&!(this.view.state.facet(ee)||i.tabIndex>-1)&&X(i,this.view.observer.selectionRange)&&!(s&&i.contains(s));if(!(o||e||n))return;let r=this.forceSelection;this.forceSelection=false;let l=this.view.state.selection.main,a,h;if(l.empty){h=a=this.inlineDOMNearPos(l.anchor,l.assoc||1)}else{h=this.inlineDOMNearPos(l.head,l.head==l.from?1:-1);a=this.inlineDOMNearPos(l.anchor,l.anchor==l.from?1:-1)}if(T.gecko&&l.empty&&!this.hasComposition&&$e(a)){let t=document.createTextNode("");this.view.observer.ignore((()=>a.node.insertBefore(t,a.node.childNodes[a.offset]||null)));a=h=new gt(t,0);r=true}let c=this.view.observer.selectionRange;if(r||!c.focusNode||(!j(a.node,a.offset,c.anchorNode,c.anchorOffset)||!j(h.node,h.offset,c.focusNode,c.focusOffset))&&!this.suppressWidgetCursorChange(c,l)){this.view.observer.ignore((()=>{if(T.android&&T.chrome&&i.contains(c.focusNode)&&si(c.focusNode,i)){i.blur();i.focus({preventScroll:true})}let t=_(this.view.root);if(!t);else if(l.empty){if(T.gecko){let t=Je(a.node,a.offset);if(t&&t!=(1|2)){let e=(t==1?ut:pt)(a.node,a.offset);if(e)a=new gt(e.node,e.offset)}}t.collapse(a.node,a.offset);if(l.bidiLevel!=null&&t.caretBidiLevel!==undefined)t.caretBidiLevel=l.bidiLevel}else if(t.extend){t.collapse(a.node,a.offset);try{t.extend(h.node,h.offset)}catch(e){}}else{let e=document.createRange();if(l.anchor>l.head)[a,h]=[h,a];e.setEnd(h.node,h.offset);e.setStart(a.node,a.offset);t.removeAllRanges();t.addRange(e)}if(n&&this.view.root.activeElement==i){i.blur();if(s)s.focus()}}));this.view.observer.setSelectionRange(a,h)}this.impreciseAnchor=a.precise?null:new gt(c.anchorNode,c.anchorOffset);this.impreciseHead=h.precise?null:new gt(c.focusNode,c.focusOffset)}suppressWidgetCursorChange(t,e){return this.hasComposition&&e.empty&&j(t.focusNode,t.focusOffset,t.anchorNode,t.anchorOffset)&&this.posFromDOM(t.focusNode,t.focusOffset)==e.head}enforceCursorAssoc(){if(this.hasComposition)return;let{view:t}=this,e=t.state.selection.main;let i=_(t.root);let{anchorNode:s,anchorOffset:o}=t.observer.selectionRange;if(!i||!e.empty||!e.assoc||!i.modify)return;let n=this.lineAt(e.head,e.assoc);if(!n)return;let r=n.posAtStart;if(e.head==r||e.head==r+n.length)return;let l=this.coordsAt(e.head,-1),a=this.coordsAt(e.head,1);if(!l||!a||l.bottom>a.top)return;let h=this.domAtPos(e.head+e.assoc,e.assoc);i.collapse(h.node,h.offset);i.modify("move",e.assoc<0?"forward":"backward","lineboundary");t.observer.readSelectionRange();let c=t.observer.selectionRange;if(t.docView.posFromDOM(c.anchorNode,c.anchorOffset)!=e.from)i.collapse(s,o)}posFromDOM(t,e){let i=this.tile.nearest(t);if(!i)return this.tile.dom.compareDocumentPosition(t)&2?0:this.view.state.doc.length;let s=i.posAtStart;if(i.isComposite()){let o;if(t==i.dom){o=i.dom.childNodes[e]}else{let s=J(t)==0?0:e==0?-1:1;for(;;){let e=t.parentNode;if(e==i.dom)break;if(s==0&&e.firstChild!=e.lastChild){if(t==e.firstChild)s=-1;else s=1}t=e}if(s<0)o=t;else o=t.nextSibling}if(o==i.dom.firstChild)return s;while(o&&!ye.get(o))o=o.nextSibling;if(!o)return s+i.length;for(let t=0,e=s;;t++){let s=i.children[t];if(s.dom==o)return e;e+=s.length+s.breakAfter}}else if(i.isText()){return t==i.dom?s+e:s+(e?i.length:0)}else{return s}}domAtPos(t,e){let{tile:i,offset:s}=this.tile.resolveBlock(t,e);if(i.isWidget())return i.domPosFor(t,e);return i.domIn(s,e)}inlineDOMNearPos(t,e){let i,s=-1,o=false;let n,r=-1,l=false;this.tile.blockTiles(((e,a)=>{if(e.isWidget()){if(e.flags&32&&a>=t)return true;if(e.flags&16)o=true}else{let h=a+e.length;if(a<=t){i=e;s=t-a;o=h<t}if(h>=t&&!n){n=e;r=t-a;l=a>t}if(a>t&&n)return true}}));if(!i&&!n)return this.domAtPos(t,e);if(o&&n)i=null;else if(l&&i)n=null;return i&&e<0||!n?i.domIn(s,e):n.domIn(r,e)}coordsAt(t,e){let{tile:i,offset:s}=this.tile.resolveBlock(t,e);if(i.isWidget()){if(i.widget instanceof ni)return null;return i.coordsInWidget(s,e,true)}return i.coordsIn(s,e)}lineAt(t,e){let{tile:i}=this.tile.resolveBlock(t,e);return i.isLine()?i:null}coordsForChar(t){let{tile:e,offset:i}=this.tile.resolveBlock(t,1);if(!e.isLine())return null;function o(t,e){if(t.isComposite()){for(let i of t.children){if(i.length>=e){let t=o(i,e);if(t)return t}e-=i.length;if(e<0)break}}else if(t.isText()&&e<t.length){let i=(0,s.findClusterBreak)(t.text,e);if(i==e)return null;let o=at(t.dom,e,i).getClientRects();for(let t=0;t<o.length;t++){let e=o[t];if(t==o.length-1||e.top<e.bottom&&e.left<e.right)return e}}return null}return o(e,i)}measureVisibleLineHeights(t){let e=[],{from:i,to:s}=t;let o=this.view.contentDOM.clientWidth;let n=o>Math.max(this.view.scrollDOM.clientWidth,this.minWidth)+1;let r=-1,l=this.view.textDirection==mt.LTR;let a=0;let h=(t,c,f)=>{for(let d=0;d<t.children.length;d++){if(c>s)break;let u=t.children[d],p=c+u.length;let g=u.dom.getBoundingClientRect(),{height:m}=g;if(f&&!d)a+=g.top-f.top;if(u instanceof Me){if(p>i)h(u,c,g)}else if(c>=i){if(a>0)e.push(-a);e.push(m+a);a=0;if(n){let t=u.dom.lastChild;let e=t?G(t):[];if(e.length){let t=e[e.length-1];let i=l?t.right-g.left:g.right-t.left;if(i>r){r=i;this.minWidth=o;this.minWidthFrom=c;this.minWidthTo=p}}}}if(f&&d==t.children.length-1)a+=f.bottom-g.bottom;c=p+u.breakAfter}};h(this.tile,0,null);return e}textDirectionAt(t){let{tile:e}=this.tile.resolveBlock(t,1);return getComputedStyle(e.dom).direction=="rtl"?mt.RTL:mt.LTR}measureTextSize(){let t=this.tile.blockTiles((t=>{if(t.isLine()&&t.children.length&&t.length<=20){let e=0,i;for(let s of t.children){if(!s.isText()||/[^ -~]/.test(s.text))return undefined;let t=G(s.dom);if(t.length!=1)return undefined;e+=t[0].width;i=t[0].height}if(e)return{lineHeight:t.dom.getBoundingClientRect().height,charWidth:e/t.length,textHeight:i}}}));if(t)return t;let e=document.createElement("div"),i,s,o;e.className="cm-line";e.style.width="99999px";e.style.position="absolute";e.textContent="abc def ghi jkl mno pqr stu";this.view.observer.ignore((()=>{this.tile.dom.appendChild(e);let t=G(e.firstChild)[0];i=e.getBoundingClientRect().height;s=t&&t.width?t.width/27:7;o=t&&t.height?t.height:i;e.remove()}));return{lineHeight:i,charWidth:s,textHeight:o}}computeBlockGapDeco(){let t=[],e=this.view.viewState;for(let i=0,s=0;;s++){let o=s==e.viewports.length?null:e.viewports[s];let n=o?o.from-1:this.view.state.doc.length;if(n>i){let s=(e.lineBlockAt(n).bottom-e.lineBlockAt(i).top)/this.view.scaleY;t.push(P.replace({widget:new ni(s),block:true,inclusive:true,isBlockGap:true}).range(i,n))}if(!o)break;i=o.to+1}return P.set(t)}updateDeco(){let t=1;let e=this.view.state.facet(ae).map((e=>{let i=this.dynamicDecorationMap[t++]=typeof e=="function";return i?e(this.view):e}));let i=false,o=this.view.state.facet(ce).map(((t,e)=>{let s=typeof t=="function";if(s)i=true;return s?t(this.view):t}));if(o.length){this.dynamicDecorationMap[t++]=i;e.push(s.RangeSet.join(o))}this.decorations=[this.editContextFormatting,...e,this.computeBlockGapDeco(),this.view.viewState.lineGapDeco];while(t<this.decorations.length)this.dynamicDecorationMap[t++]=false;this.blockWrappers=this.view.state.facet(he).map((t=>typeof t=="function"?t(this.view):t))}scrollIntoView(t){if(t.isSnapshot){let e=this.view.viewState.lineBlockAt(t.range.head);this.view.scrollDOM.scrollTop=e.top-t.yMargin;this.view.scrollDOM.scrollLeft=t.xMargin;return}for(let h of this.view.state.facet(Ut)){try{if(h(this.view,t.range,t))return true}catch(a){te(this.view.state,a,"scroll handler")}}let{range:e}=t;let i=this.coordsAt(e.head,e.empty?e.assoc:e.head>e.anchor?-1:1),s;if(!i)return;if(!e.empty&&(s=this.coordsAt(e.anchor,e.anchor>e.head?-1:1)))i={left:Math.min(i.left,s.left),top:Math.min(i.top,s.top),right:Math.max(i.right,s.right),bottom:Math.max(i.bottom,s.bottom)};let o=ge(this.view);let n={left:i.left-o.left,top:i.top-o.top,right:i.right+o.right,bottom:i.bottom+o.bottom};let{offsetWidth:r,offsetHeight:l}=this.view.scrollDOM;it(this.view.scrollDOM,n,e.head<e.anchor?-1:1,t.x,t.y,Math.max(Math.min(t.xMargin,r),-r),Math.max(Math.min(t.yMargin,l),-l),this.view.textDirection==mt.LTR)}lineHasWidget(t){let e=t=>t.isWidget()||t.children.some(e);return e(this.tile.resolveBlock(t,1).tile)}destroy(){je(this.tile)}}function je(t,e){let i=e===null||e===void 0?void 0:e.get(t);if(i!=1){if(i==null)t.destroy();for(let i of t.children)je(i,e)}}function $e(t){return t.node.nodeType==1&&t.node.firstChild&&(t.offset==0||t.node.childNodes[t.offset-1].contentEditable=="false")&&(t.offset==t.node.childNodes.length||t.node.childNodes[t.offset].contentEditable=="false")}function Ue(t,e){let i=t.observer.selectionRange;if(!i.focusNode)return null;let s=ut(i.focusNode,i.focusOffset);let o=pt(i.focusNode,i.focusOffset);let n=s||o;if(o&&s&&o.node!=s.node){let e=ye.get(o.node);if(!e||e.isText()&&e.text!=o.node.nodeValue){n=o}else if(t.docView.lastCompositionAfterCursor){let t=ye.get(s.node);if(!(!t||t.isText()&&t.text!=s.node.nodeValue))n=o}}t.docView.lastCompositionAfterCursor=n!=s;if(!n)return null;let r=e-n.offset;return{from:r,to:r+n.node.nodeValue.length,node:n.node}}function Qe(t,e,i){let s=Ue(t,i);if(!s)return null;let{node:o,from:n,to:r}=s,l=o.nodeValue;if(/[\n\r]/.test(l))return null;if(t.state.doc.sliceString(s.from,s.to)!=l)return null;let a=e.invertedDesc;return{range:new ve(a.mapPos(n),a.mapPos(r),n,r),text:o}}function Je(t,e){if(t.nodeType!=1)return 0;return(e&&t.childNodes[e-1].contentEditable=="false"?1:0)|(e<t.childNodes.length&&t.childNodes[e].contentEditable=="false"?2:0)}let Ze=class t{constructor(){this.changes=[]}compareRange(t,e){q(t,e,this.changes)}comparePoint(t,e){q(t,e,this.changes)}boundChange(t){q(t,t,this.changes)}};function ti(t,e,i){let o=new Ze;s.RangeSet.compare(t,e,i,o);return o.changes}class ei{constructor(){this.changes=[]}compareRange(t,e){q(t,e,this.changes)}comparePoint(){}boundChange(t){q(t,t,this.changes)}}function ii(t,e,i){let o=new ei;s.RangeSet.compare(t,e,i,o);return o.changes}function si(t,e){for(let i=t;i&&i!=e;i=i.assignedSlot||i.parentNode){if(i.nodeType==1&&i.contentEditable=="false"){return true}}return false}function oi(t,e){let i=false;if(e)t.iterChangedRanges(((t,s)=>{if(t<e.to&&s>e.from)i=true}));return i}class ni extends H{constructor(t){super();this.height=t}toDOM(){let t=document.createElement("div");t.className="cm-gap";this.updateDOM(t);return t}eq(t){return t.height==this.height}updateDOM(t){t.style.height=this.height+"px";return true}get editable(){return true}get estimatedHeight(){return this.height}ignoreEvent(){return false}}function ri(t,e,i=1){let o=t.charCategorizer(e);let n=t.doc.lineAt(e),r=e-n.from;if(n.length==0)return s.EditorSelection.cursor(e);if(r==0)i=1;else if(r==n.length)i=-1;let l=r,a=r;if(i<0)l=(0,s.findClusterBreak)(n.text,r,false);else a=(0,s.findClusterBreak)(n.text,r);let h=o(n.text.slice(l,a));while(l>0){let t=(0,s.findClusterBreak)(n.text,l,false);if(o(n.text.slice(t,l))!=h)break;l=t}while(a<n.length){let t=(0,s.findClusterBreak)(n.text,a);if(o(n.text.slice(a,t))!=h)break;a=t}return s.EditorSelection.range(l+n.from,a+n.from)}function li(t,e,i,o,n){let r=Math.round((o-e.left)*t.defaultCharacterWidth);if(t.lineWrapping&&i.height>t.defaultLineHeight*1.5){let e=t.viewState.heightOracle.textHeight;let s=Math.floor((n-i.top-(t.defaultLineHeight-e)*.5)/e);r+=s*t.viewState.heightOracle.lineLength}let l=t.state.sliceDoc(i.from,i.to);return i.from+(0,s.findColumn)(l,r,t.state.tabSize)}function ai(t,e,i){let s=t.lineBlockAt(e);if(Array.isArray(s.type)){let t;for(let o of s.type){if(o.from>e)break;if(o.to<e)continue;if(o.from<e&&o.to>e)return o;if(!t||o.type==W.Text&&(t.type!=o.type||(i<0?o.from<e:o.to>e)))t=o}return t||s}return s}function hi(t,e,i,o){let n=ai(t,e.head,e.assoc||-1);let r=!o||n.type!=W.Text||!(t.lineWrapping||n.widgetLineBreaks)?null:t.coordsAtPos(e.assoc<0&&e.head>n.from?e.head-1:e.head);if(r){let e=t.dom.getBoundingClientRect();let o=t.textDirectionAt(n.from);let l=t.posAtCoords({x:i==(o==mt.LTR)?e.right-1:e.left+1,y:(r.top+r.bottom)/2});if(l!=null)return s.EditorSelection.cursor(l,i?-1:1)}return s.EditorSelection.cursor(i?n.to:n.from,i?-1:1)}function ci(t,e,i,s){let o=t.state.doc.lineAt(e.head),n=t.bidiSpans(o);let r=t.textDirectionAt(o.from);for(let l=e,a=null;;){let e=Nt(o,n,r,l,i),h=Pt;if(!e){if(o.number==(i?t.state.doc.lines:1))return l;h="\n";o=t.state.doc.line(o.number+(i?1:-1));n=t.bidiSpans(o);e=t.visualLineSide(o,!i)}if(!a){if(!s)return e;a=s(h)}else if(!a(h)){return l}l=e}}function fi(t,e,i){let o=t.state.charCategorizer(e);let n=o(i);return t=>{let e=o(t);if(n==s.CharCategory.Space)n=e;return n==e}}function di(t,e,i,o){let n=e.head,r=i?1:-1;if(n==(i?t.state.doc.length:0))return s.EditorSelection.cursor(n,e.assoc);let l=e.goalColumn,a;let h=t.contentDOM.getBoundingClientRect();let c=t.coordsAtPos(n,(e.empty?e.assoc:0)||(i?1:-1)),f=t.documentTop;if(c){if(l==null)l=c.left-h.left;a=r<0?c.top:c.bottom}else{let e=t.viewState.lineBlockAt(n);if(l==null)l=Math.min(h.right-h.left,t.defaultCharacterWidth*(n-e.from));a=(r<0?e.top:e.bottom)+f}let d=h.left+l;let u=o!==null&&o!==void 0?o:t.viewState.heightOracle.textHeight>>1;let p=vi(t,{x:d,y:a+u*r},false,r);return s.EditorSelection.cursor(p.pos,p.assoc,undefined,l)}function ui(t,e,i){for(;;){let s=0;for(let o of t){o.between(e-1,e+1,((t,o,n)=>{if(e>t&&e<o){let n=s||i||(e-t<o-e?-1:1);e=n<0?t:o;s=n}}))}if(!s)return e}}function pi(t,e){let i=null;for(let o=0;o<e.ranges.length;o++){let n=e.ranges[o],r=null;if(n.empty){let e=ui(t,n.from,0);if(e!=n.from)r=s.EditorSelection.cursor(e,-1)}else{let e=ui(t,n.from,-1);let i=ui(t,n.to,1);if(e!=n.from||i!=n.to)r=s.EditorSelection.range(n.from==n.anchor?e:i,n.from==n.head?e:i)}if(r){if(!i)i=e.ranges.slice();i[o]=r}}return i?s.EditorSelection.create(i,e.mainIndex):e}function gi(t,e,i){let o=ui(t.state.facet(fe).map((e=>e(t))),i.from,e.head>i.from?-1:1);return o==i.from?i:s.EditorSelection.cursor(o,o<i.from?1:-1)}class mi{constructor(t,e){this.pos=t;this.assoc=e}}function vi(t,e,i,s){let o=t.contentDOM.getBoundingClientRect(),n=o.top+t.viewState.paddingTop;let{x:r,y:l}=e,a=l-n,h;for(;;){if(a<0)return new mi(0,1);if(a>t.viewState.docHeight)return new mi(t.state.doc.length,-1);h=t.elementAtHeight(a);if(s==null)break;if(h.type==W.Text){if(s<0?h.to<t.viewport.from:h.from>t.viewport.to)break;let e=t.docView.coordsAt(s<0?h.from:h.to,s>0?-1:1);if(e&&(s<0?e.top<=a+n:e.bottom>=a+n))break}let e=t.viewState.heightOracle.textHeight/2;a=s>0?h.bottom+e:h.top-e}if(t.viewport.from>=h.to||t.viewport.to<=h.from){if(i)return null;if(h.type==W.Text){let e=li(t,o,h,r,l);return new mi(e,e==h.from?1:-1)}}if(h.type!=W.Text)return a<(h.top+h.bottom)/2?new mi(h.from,1):new mi(h.to,-1);let c=t.docView.lineAt(h.from,2);if(!c||c.length!=h.length)c=t.docView.lineAt(h.from,-2);return new wi(t,r,l,t.textDirectionAt(h.from)).scanTile(c,h.from)}class wi{constructor(t,e,i,s){this.view=t;this.x=e;this.y=i;this.baseDir=s;this.line=null;this.spans=null}bidiSpansAt(t){if(!this.line||this.line.from>t||this.line.to<t){this.line=this.view.state.doc.lineAt(t);this.spans=this.view.bidiSpans(this.line)}return this}baseDirAt(t,e){let{line:i,spans:s}=this.bidiSpansAt(t);let o=s[At.find(s,t-i.from,-1,e)].level;return o==this.baseDir}dirAt(t,e){let{line:i,spans:s}=this.bidiSpansAt(t);return s[At.find(s,t-i.from,-1,e)].dir}bidiIn(t,e){let{spans:i,line:s}=this.bidiSpansAt(t);return i.length>1||i.length&&(i[0].level!=this.baseDir||i[0].to+s.from<e)}scan(t,e){let i=0,s=t.length-1,o=new Set;let n=this.bidiIn(t[0],t[s]);let r,l;let a=-1,h=1e9,c;t:while(i<s){let f=s-i,d=i+s>>1;e:if(o.has(d)){let t=i+Math.floor(Math.random()*f);for(let e=0;e<f;e++){if(!o.has(t)){d=t;break e}t++;if(t==s)t=i}break t}o.add(d);let u=e(d);if(u)for(let e=0;e<u.length;e++){let o=u[e],f=0;if(o.bottom<this.y){if(!r||r.bottom<o.bottom)r=o;f=1}else if(o.top>this.y){if(!l||l.top>o.top)l=o;f=-1}else{let t=o.left>this.x?this.x-o.left:o.right<this.x?this.x-o.right:0;let e=Math.abs(t);if(e<h){a=d;h=e;c=o}if(t)f=t<0==(this.baseDir==mt.LTR)?-1:1}if(f==-1&&(!n||this.baseDirAt(t[d],1)))s=d;else if(f==1&&(!n||this.baseDirAt(t[d+1],-1)))i=d+1}}if(!c){let i=r&&(!l||this.y-r.bottom<l.top-this.y)?r:l;this.y=(i.top+i.bottom)/2;return this.scan(t,e)}let f=(n?this.dirAt(t[a],1):this.baseDir)==mt.LTR;return{i:a,after:this.x>(c.left+c.right)/2==f}}scanText(t,e){let i=[];for(let n=0;n<t.length;n=(0,s.findClusterBreak)(t.text,n))i.push(e+n);i.push(e+t.length);let o=this.scan(i,(s=>{let o=i[s]-e,n=i[s+1]-e;return at(t.dom,o,n).getClientRects()}));return o.after?new mi(i[o.i+1],-1):new mi(i[o.i],1)}scanTile(t,e){if(!t.length)return new mi(e,1);if(t.children.length==1){let i=t.children[0];if(i.isText())return this.scanText(i,e);else if(i.isComposite())return this.scanTile(i,e)}let i=[e];for(let r=0,l=e;r<t.children.length;r++)i.push(l+=t.children[r].length);let s=this.scan(i,(e=>{let i=t.children[e];if(i.flags&48)return null;return(i.dom.nodeType==1?i.dom:at(i.dom,0,i.length)).getClientRects()}));let o=t.children[s.i],n=i[s.i];if(o.isText())return this.scanText(o,n);if(o.isComposite())return this.scanTile(o,n);return s.after?new mi(i[s.i+1],-1):new mi(n,1)}}const bi="￿";class yi{constructor(t,e){this.points=t;this.view=e;this.text="";this.lineSeparator=e.state.facet(s.EditorState.lineSeparator)}append(t){this.text+=t}lineBreak(){this.text+=bi}readRange(t,e){if(!t)return this;let i=t.parentNode;for(let s=t;;){this.findPointBefore(i,s);let t=this.text.length;this.readNode(s);let o=ye.get(s),n=s.nextSibling;if(n==e){if((o===null||o===void 0?void 0:o.breakAfter)&&!n&&i!=this.view.contentDOM)this.lineBreak();break}let r=ye.get(n);if((o&&r?o.breakAfter:(o?o.breakAfter:U(s))||U(n)&&(s.nodeName!="BR"||(o===null||o===void 0?void 0:o.isWidget()))&&this.text.length>t)&&!Si(n,e))this.lineBreak();s=n}this.findPointBefore(i,e);return this}readTextNode(t){let e=t.nodeValue;for(let i of this.points)if(i.node==t)i.pos=this.text.length+Math.min(i.offset,e.length);for(let i=0,s=this.lineSeparator?null:/\r\n?|\n/g;;){let o=-1,n=1,r;if(this.lineSeparator){o=e.indexOf(this.lineSeparator,i);n=this.lineSeparator.length}else if(r=s.exec(e)){o=r.index;n=r[0].length}this.append(e.slice(i,o<0?e.length:o));if(o<0)break;this.lineBreak();if(n>1)for(let e of this.points)if(e.node==t&&e.pos>this.text.length)e.pos-=n-1;i=o+n}}readNode(t){let e=ye.get(t);let i=e&&e.overrideDOMText;if(i!=null){this.findPointInside(t,i.length);for(let t=i.iter();!t.next().done;){if(t.lineBreak)this.lineBreak();else this.append(t.value)}}else if(t.nodeType==3){this.readTextNode(t)}else if(t.nodeName=="BR"){if(t.nextSibling)this.lineBreak()}else if(t.nodeType==1){this.readRange(t.firstChild,null)}}findPointBefore(t,e){for(let i of this.points)if(i.node==t&&t.childNodes[i.offset]==e)i.pos=this.text.length}findPointInside(t,e){for(let i of this.points)if(t.nodeType==3?i.node==t:t.contains(i.node))i.pos=this.text.length+(xi(t,i.node,i.offset)?e:0)}}function xi(t,e,i){for(;;){if(!e||i<J(e))return false;if(e==t)return true;i=$(e)+1;e=e.parentNode}}function Si(t,e){let i;for(;;t=t.nextSibling){if(t==e||!t)break;let s=ye.get(t);if(!(s===null||s===void 0?void 0:s.isWidget()))return false;if(s)(i||(i=[])).push(s)}if(i)for(let s of i){let t=s.overrideDOMText;if(t===null||t===void 0?void 0:t.length)return false}return true}class Ci{constructor(t,e){this.node=t;this.offset=e;this.pos=-1}}class Mi{constructor(t,e,i,o){this.typeOver=o;this.bounds=null;this.text="";this.domChanged=e>-1;let{impreciseHead:n,impreciseAnchor:r}=t.docView;if(t.state.readOnly&&e>-1){this.newSel=null}else if(e>-1&&(this.bounds=ki(t.docView.tile,e,i,0))){let e=n||r?[]:Ei(t);let i=new yi(e,t);i.readRange(this.bounds.startDOM,this.bounds.endDOM);this.text=i.text;this.newSel=Ri(e,this.bounds.from)}else{let e=t.observer.selectionRange;let i=n&&n.node==e.focusNode&&n.offset==e.focusOffset||!Y(t.contentDOM,e.focusNode)?t.state.selection.main.head:t.docView.posFromDOM(e.focusNode,e.focusOffset);let o=r&&r.node==e.anchorNode&&r.offset==e.anchorOffset||!Y(t.contentDOM,e.anchorNode)?t.state.selection.main.anchor:t.docView.posFromDOM(e.anchorNode,e.anchorOffset);let l=t.viewport;if((T.ios||T.chrome)&&t.state.selection.main.empty&&i!=o&&(l.from>0||l.to<t.state.doc.length)){let e=Math.min(i,o),s=Math.max(i,o);let n=l.from-e,r=l.to-s;if((n==0||n==1||e==0)&&(r==0||r==-1||s==t.state.doc.length)){i=0;o=t.state.doc.length}}if(t.inputState.composing>-1&&t.state.selection.ranges.length>1)this.newSel=t.state.selection.replaceRange(s.EditorSelection.range(o,i));else this.newSel=s.EditorSelection.single(o,i)}}}function ki(t,e,i,s){if(t.isComposite()){let o=-1,n=-1,r=-1,l=-1;for(let a=0,h=s,c=s;a<t.children.length;a++){let s=t.children[a],f=h+s.length;if(h<e&&f>i)return ki(s,e,i,h);if(f>=e&&o==-1){o=a;n=h}if(h>i&&s.dom.parentNode==t.dom){r=a;l=c;break}c=f;h=f+s.breakAfter}return{from:n,to:l<0?s+t.length:l,startDOM:(o?t.children[o-1].dom.nextSibling:null)||t.dom.firstChild,endDOM:r<t.children.length&&r>=0?t.children[r].dom:null}}else if(t.isText()){return{from:s,to:s+t.length,startDOM:t.dom,endDOM:t.dom.nextSibling}}else{return null}}function Ai(t,e){let i;let{newSel:o}=e,n=t.state.selection.main;let r=t.inputState.lastKeyTime>Date.now()-100?t.inputState.lastKeyCode:-1;if(e.bounds){let{from:o,to:l}=e.bounds;let a=n.from,h=null;if(r===8||T.android&&e.text.length<l-o){a=n.to;h="end"}let c=Oi(t.state.doc.sliceString(o,l,bi),e.text,a-o,h);if(c){if(T.chrome&&r==13&&c.toB==c.from+2&&e.text.slice(c.from,c.toB)==bi+bi)c.toB--;i={from:o+c.from,to:o+c.toA,insert:s.Text.of(e.text.slice(c.from,c.toB).split(bi))}}}else if(o&&(!t.hasFocus&&t.state.facet(ee)||Bi(o,n))){o=null}if(!i&&!o)return false;if(!i&&e.typeOver&&!n.empty&&o&&o.main.empty){i={from:n.from,to:n.to,insert:t.state.doc.slice(n.from,n.to)}}else if((T.mac||T.android)&&i&&i.from==i.to&&i.from==n.head-1&&/^\. ?$/.test(i.insert.toString())&&t.contentDOM.getAttribute("autocorrect")=="off"){if(o&&i.insert.length==2)o=s.EditorSelection.single(o.main.anchor-1,o.main.head-1);i={from:i.from,to:i.to,insert:s.Text.of([i.insert.toString().replace("."," ")])}}else if(i&&i.from>=n.from&&i.to<=n.to&&(i.from!=n.from||i.to!=n.to)&&n.to-n.from-(i.to-i.from)<=4){i={from:n.from,to:n.to,insert:t.state.doc.slice(n.from,i.from).append(i.insert).append(t.state.doc.slice(i.to,n.to))}}else if(t.state.doc.lineAt(n.from).to<n.to&&t.docView.lineHasWidget(n.to)&&t.inputState.insertingTextAt>Date.now()-50){i={from:n.from,to:n.to,insert:t.state.toText(t.inputState.insertingText)}}else if(T.chrome&&i&&i.from==i.to&&i.from==n.head&&i.insert.toString()=="\n "&&t.lineWrapping){if(o)o=s.EditorSelection.single(o.main.anchor-1,o.main.head-1);i={from:n.from,to:n.to,insert:s.Text.of([" "])}}if(i){return Ti(t,i,o,r)}else if(o&&!Bi(o,n)){let e=false,i="select";if(t.inputState.lastSelectionTime>Date.now()-50){if(t.inputState.lastSelectionOrigin=="select")e=true;i=t.inputState.lastSelectionOrigin;if(i=="select.pointer")o=pi(t.state.facet(fe).map((e=>e(t))),o)}t.dispatch({selection:o,scrollIntoView:e,userEvent:i});return true}else{return false}}function Ti(t,e,i,s=-1){if(T.ios&&t.inputState.flushIOSKey(e))return true;let o=t.state.selection.main;if(T.android&&(e.to==o.to&&(e.from==o.from||e.from==o.from-1&&t.state.sliceDoc(e.from,o.from)==" ")&&e.insert.length==1&&e.insert.lines==2&&ht(t.contentDOM,"Enter",13)||(e.from==o.from-1&&e.to==o.to&&e.insert.length==0||s==8&&e.insert.length<e.to-e.from&&e.to>o.head)&&ht(t.contentDOM,"Backspace",8)||e.from==o.from&&e.to==o.to+1&&e.insert.length==0&&ht(t.contentDOM,"Delete",46)))return true;let n=e.insert.toString();if(t.inputState.composing>=0)t.inputState.composing++;let r;let l=()=>r||(r=Di(t,e,i));if(!t.state.facet(_t).some((i=>i(t,e.from,e.to,n,l))))t.dispatch(l());return true}function Di(t,e,i){let o,n=t.state,r=n.selection.main,l=-1;if(e.from==e.to&&e.from<r.from||e.from>r.to){let i=e.from<r.from?-1:1,s=i<0?r.from:r.to;let o=ui(n.facet(fe).map((e=>e(t))),s,i);if(e.from==o)l=o}if(l>-1){o={changes:e,selection:s.EditorSelection.cursor(e.from+e.insert.length,-1)}}else if(e.from>=r.from&&e.to<=r.to&&e.to-e.from>=(r.to-r.from)/3&&(!i||i.main.empty&&i.main.from==e.from+e.insert.length)&&t.inputState.composing<0){let i=r.from<e.from?n.sliceDoc(r.from,e.from):"";let s=r.to>e.to?n.sliceDoc(e.to,r.to):"";o=n.replaceSelection(t.state.toText(i+e.insert.sliceString(0,undefined,t.state.lineBreak)+s))}else{let l=n.changes(e);let a=i&&i.main.to<=l.newLength?i.main:undefined;if(n.selection.ranges.length>1&&(t.inputState.composing>=0||t.inputState.compositionPendingChange)&&e.to<=r.to+10&&e.to>=r.to-10){let h=t.state.sliceDoc(e.from,e.to);let c,f=i&&Ue(t,i.main.head);if(f){let t=e.insert.length-(e.to-e.from);c={from:f.from,to:f.to-t}}else{c=t.state.doc.lineAt(r.head)}let d=r.to-e.to;o=n.changeByRange((i=>{if(i.from==r.from&&i.to==r.to)return{changes:l,range:a||i.map(l)};let o=i.to-d,f=o-h.length;if(t.state.sliceDoc(f,o)!=h||o>=c.from&&f<=c.to)return{range:i};let u=n.changes({from:f,to:o,insert:e.insert}),p=i.to-r.to;return{changes:u,range:!a?i.map(u):s.EditorSelection.range(Math.max(0,a.anchor+p),Math.max(0,a.head+p))}}))}else{o={changes:l,selection:a&&n.selection.replaceRange(a)}}}let a="input.type";if(t.composing||t.inputState.compositionPendingChange&&t.inputState.compositionEndedAt>Date.now()-50){t.inputState.compositionPendingChange=false;a+=".compose";if(t.inputState.compositionFirstChange){a+=".start";t.inputState.compositionFirstChange=false}}return n.update(o,{userEvent:a,scrollIntoView:true})}function Oi(t,e,i,s){let o=Math.min(t.length,e.length);let n=0;while(n<o&&t.charCodeAt(n)==e.charCodeAt(n))n++;if(n==o&&t.length==e.length)return null;let r=t.length,l=e.length;while(r>0&&l>0&&t.charCodeAt(r-1)==e.charCodeAt(l-1)){r--;l--}if(s=="end"){let t=Math.max(0,n-Math.min(r,l));i-=r+t-n}if(r<n&&t.length<e.length){let t=i<=n&&i>=r?n-i:0;n-=t;l=n+(l-r);r=n}else if(l<n){let t=i<=n&&i>=l?n-i:0;n-=t;r=n+(r-l);l=n}return{from:n,toA:r,toB:l}}function Ei(t){let e=[];if(t.root.activeElement!=t.contentDOM)return e;let{anchorNode:i,anchorOffset:s,focusNode:o,focusOffset:n}=t.observer.selectionRange;if(i){e.push(new Ci(i,s));if(o!=i||n!=s)e.push(new Ci(o,n))}return e}function Ri(t,e){if(t.length==0)return null;let i=t[0].pos,o=t.length==2?t[1].pos:i;return i>-1&&o>-1?s.EditorSelection.single(i+e,o+e):null}function Bi(t,e){return e.head==t.main.head&&e.anchor==t.main.anchor}class Li{setSelectionOrigin(t){this.lastSelectionOrigin=t;this.lastSelectionTime=Date.now()}constructor(t){this.view=t;this.lastKeyCode=0;this.lastKeyTime=0;this.lastTouchTime=0;this.lastFocusTime=0;this.lastScrollTop=0;this.lastScrollLeft=0;this.pendingIOSKey=undefined;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=false;this.compositionPendingChange=false;this.insertingText="";this.insertingTextAt=0;this.mouseSelection=null;this.draggedContent=null;this.handleEvent=this.handleEvent.bind(this);this.notifiedFocused=t.hasFocus;if(T.safari)t.contentDOM.addEventListener("input",(()=>null));if(T.gecko)gs(t.contentDOM.ownerDocument)}handleEvent(t){if(!Xi(this.view,t)||this.ignoreDuringComposition(t))return;if(t.type=="keydown"&&this.keydown(t))return;if(this.view.updateState!=0)Promise.resolve().then((()=>this.runHandlers(t.type,t)));else this.runHandlers(t.type,t)}runHandlers(t,e){let i=this.handlers[t];if(i){for(let t of i.observers)t(this.view,e);for(let t of i.handlers){if(e.defaultPrevented)break;if(t(this.view,e)){e.preventDefault();break}}}}ensureHandlers(t){let e=Wi(t),i=this.handlers,s=this.view.contentDOM;for(let o in e)if(o!="scroll"){let t=!e[o].handlers.length;let n=i[o];if(n&&t!=!n.handlers.length){s.removeEventListener(o,this.handleEvent);n=null}if(!n)s.addEventListener(o,this.handleEvent,{passive:t})}for(let o in i)if(o!="scroll"&&!e[o])s.removeEventListener(o,this.handleEvent);this.handlers=e}keydown(t){this.lastKeyCode=t.keyCode;this.lastKeyTime=Date.now();if(t.keyCode==9&&this.tabFocusMode>-1&&(!this.tabFocusMode||Date.now()<=this.tabFocusMode))return true;if(this.tabFocusMode>0&&t.keyCode!=27&&Vi.indexOf(t.keyCode)<0)this.tabFocusMode=-1;if(T.android&&T.chrome&&!t.synthetic&&(t.keyCode==13||t.keyCode==8)){this.view.observer.delayAndroidKey(t.key,t.keyCode);return true}let e;if(T.ios&&!t.synthetic&&!t.altKey&&!t.metaKey&&((e=Pi.find((e=>e.keyCode==t.keyCode)))&&!t.ctrlKey||Ni.indexOf(t.key)>-1&&t.ctrlKey&&!t.shiftKey)){this.pendingIOSKey=e||t;setTimeout((()=>this.flushIOSKey()),250);return true}if(t.keyCode!=229)this.view.observer.forceFlush();return false}flushIOSKey(t){let e=this.pendingIOSKey;if(!e)return false;if(e.key=="Enter"&&t&&t.from<t.to&&/^\S+$/.test(t.insert.toString()))return false;this.pendingIOSKey=undefined;return ht(this.view.contentDOM,e.key,e.keyCode,e instanceof KeyboardEvent?e:undefined)}ignoreDuringComposition(t){if(!/^key/.test(t.type)||t.synthetic)return false;if(this.composing>0)return true;if(T.safari&&!T.ios&&this.compositionPendingKey&&Date.now()-this.compositionEndedAt<100){this.compositionPendingKey=false;return true}return false}startMouseSelection(t){if(this.mouseSelection)this.mouseSelection.destroy();this.mouseSelection=t}update(t){this.view.observer.update(t);if(this.mouseSelection)this.mouseSelection.update(t);if(this.draggedContent&&t.docChanged)this.draggedContent=this.draggedContent.map(t.changes);if(t.transactions.length)this.lastKeyCode=this.lastSelectionTime=0}destroy(){if(this.mouseSelection)this.mouseSelection.destroy()}}function Hi(t,e){return(i,s)=>{try{return e.call(t,s,i)}catch(o){te(i.state,o)}}}function Wi(t){let e=Object.create(null);function i(t){return e[t]||(e[t]={observers:[],handlers:[]})}for(let s of t){let t=s.spec,e=t&&t.plugin.domEventHandlers,o=t&&t.plugin.domEventObservers;if(e)for(let n in e){let t=e[n];if(t)i(n).handlers.push(Hi(s.value,t))}if(o)for(let n in o){let t=o[n];if(t)i(n).observers.push(Hi(s.value,t))}}for(let s in Gi)i(s).handlers.push(Gi[s]);for(let s in ji)i(s).observers.push(ji[s]);return e}const Pi=[{key:"Backspace",keyCode:8,inputType:"deleteContentBackward"},{key:"Enter",keyCode:13,inputType:"insertParagraph"},{key:"Enter",keyCode:13,inputType:"insertLineBreak"},{key:"Delete",keyCode:46,inputType:"deleteContentForward"}];const Ni="dthko";const Vi=[16,17,18,20,91,92,224,225];const Fi=6;function zi(t){return Math.max(0,t)*.7+8}function Ii(t,e){return Math.max(Math.abs(t.clientX-e.clientX),Math.abs(t.clientY-e.clientY))}class qi{constructor(t,e,i,o){this.view=t;this.startEvent=e;this.style=i;this.mustSelect=o;this.scrollSpeed={x:0,y:0};this.scrolling=-1;this.lastEvent=e;this.scrollParents=st(t.contentDOM);this.atoms=t.state.facet(fe).map((e=>e(t)));let n=t.contentDOM.ownerDocument;n.addEventListener("mousemove",this.move=this.move.bind(this));n.addEventListener("mouseup",this.up=this.up.bind(this));this.extend=e.shiftKey;this.multiple=t.state.facet(s.EditorState.allowMultipleSelections)&&Ki(t,e);this.dragging=Yi(t,e)&&os(e)==1?null:false}start(t){if(this.dragging===false)this.select(t)}move(t){if(t.buttons==0)return this.destroy();if(this.dragging||this.dragging==null&&Ii(this.startEvent,t)<10)return;this.select(this.lastEvent=t);let e=0,i=0;let s=0,o=0,n=this.view.win.innerWidth,r=this.view.win.innerHeight;if(this.scrollParents.x)({left:s,right:n}=this.scrollParents.x.getBoundingClientRect());if(this.scrollParents.y)({top:o,bottom:r}=this.scrollParents.y.getBoundingClientRect());let l=ge(this.view);if(t.clientX-l.left<=s+Fi)e=-zi(s-t.clientX);else if(t.clientX+l.right>=n-Fi)e=zi(t.clientX-n);if(t.clientY-l.top<=o+Fi)i=-zi(o-t.clientY);else if(t.clientY+l.bottom>=r-Fi)i=zi(t.clientY-r);this.setScrollSpeed(e,i)}up(t){if(this.dragging==null)this.select(this.lastEvent);if(!this.dragging)t.preventDefault();this.destroy()}destroy(){this.setScrollSpeed(0,0);let t=this.view.contentDOM.ownerDocument;t.removeEventListener("mousemove",this.move);t.removeEventListener("mouseup",this.up);this.view.inputState.mouseSelection=this.view.inputState.draggedContent=null}setScrollSpeed(t,e){this.scrollSpeed={x:t,y:e};if(t||e){if(this.scrolling<0)this.scrolling=setInterval((()=>this.scroll()),50)}else if(this.scrolling>-1){clearInterval(this.scrolling);this.scrolling=-1}}scroll(){let{x:t,y:e}=this.scrollSpeed;if(t&&this.scrollParents.x){this.scrollParents.x.scrollLeft+=t;t=0}if(e&&this.scrollParents.y){this.scrollParents.y.scrollTop+=e;e=0}if(t||e)this.view.win.scrollBy(t,e);if(this.dragging===false)this.select(this.lastEvent)}select(t){let{view:e}=this,i=pi(this.atoms,this.style.get(t,this.extend,this.multiple));if(this.mustSelect||!i.eq(e.state.selection,this.dragging===false))this.view.dispatch({selection:i,userEvent:"select.pointer"});this.mustSelect=false}update(t){if(t.transactions.some((t=>t.isUserEvent("input.type"))))this.destroy();else if(this.style.update(t))setTimeout((()=>this.select(this.lastEvent)),20)}}function Ki(t,e){let i=t.state.facet(Ft);return i.length?i[0](e):T.mac?e.metaKey:e.ctrlKey}function _i(t,e){let i=t.state.facet(zt);return i.length?i[0](e):T.mac?!e.altKey:!e.ctrlKey}function Yi(t,e){let{main:i}=t.state.selection;if(i.empty)return false;let s=_(t.root);if(!s||s.rangeCount==0)return true;let o=s.getRangeAt(0).getClientRects();for(let n=0;n<o.length;n++){let t=o[n];if(t.left<=e.clientX&&t.right>=e.clientX&&t.top<=e.clientY&&t.bottom>=e.clientY)return true}return false}function Xi(t,e){if(!e.bubbles)return true;if(e.defaultPrevented)return false;for(let i=e.target,s;i!=t.contentDOM;i=i.parentNode)if(!i||i.nodeType==11||(s=ye.get(i))&&s.isWidget()&&!s.isHidden&&s.widget.ignoreEvent(e))return false;return true}const Gi=Object.create(null);const ji=Object.create(null);const $i=T.ie&&T.ie_version<15||T.ios&&T.webkit_version<604;function Ui(t){let e=t.dom.parentNode;if(!e)return;let i=e.appendChild(document.createElement("textarea"));i.style.cssText="position: fixed; left: -10000px; top: 10px";i.focus();setTimeout((()=>{t.focus();i.remove();Ji(t,i.value)}),50)}function Qi(t,e,i){for(let s of t.facet(e))i=s(i,t);return i}function Ji(t,e){e=Qi(t.state,Xt,e);let{state:i}=t,o,n=1,r=i.toText(e);let l=r.lines==i.selection.ranges.length;let a=cs!=null&&i.selection.ranges.every((t=>t.empty))&&cs==r.toString();if(a){let t=-1;o=i.changeByRange((o=>{let a=i.doc.lineAt(o.from);if(a.from==t)return{range:o};t=a.from;let h=i.toText((l?r.line(n++).text:e)+i.lineBreak);return{changes:{from:a.from,insert:h},range:s.EditorSelection.cursor(o.from+h.length)}}))}else if(l){o=i.changeByRange((t=>{let e=r.line(n++);return{changes:{from:t.from,to:t.to,insert:e.text},range:s.EditorSelection.cursor(t.from+e.length)}}))}else{o=i.replaceSelection(r)}t.dispatch(o,{userEvent:"input.paste",scrollIntoView:true})}ji.scroll=t=>{t.inputState.lastScrollTop=t.scrollDOM.scrollTop;t.inputState.lastScrollLeft=t.scrollDOM.scrollLeft};Gi.keydown=(t,e)=>{t.inputState.setSelectionOrigin("select");if(e.keyCode==27&&t.inputState.tabFocusMode!=0)t.inputState.tabFocusMode=Date.now()+2e3;return false};ji.touchstart=(t,e)=>{t.inputState.lastTouchTime=Date.now();t.inputState.setSelectionOrigin("select.pointer")};ji.touchmove=t=>{t.inputState.setSelectionOrigin("select.pointer")};Gi.mousedown=(t,e)=>{t.observer.flush();if(t.inputState.lastTouchTime>Date.now()-2e3)return false;let i=null;for(let s of t.state.facet(It)){i=s(t,e);if(i)break}if(!i&&e.button==0)i=ns(t,e);if(i){let s=!t.hasFocus;t.inputState.startMouseSelection(new qi(t,e,i,s));if(s)t.observer.ignore((()=>{rt(t.contentDOM);let e=t.root.activeElement;if(e&&!e.contains(t.contentDOM))e.blur()}));let o=t.inputState.mouseSelection;if(o){o.start(e);return o.dragging===false}}else{t.inputState.setSelectionOrigin("select.pointer")}return false};function Zi(t,e,i,o){if(o==1){return s.EditorSelection.cursor(e,i)}else if(o==2){return ri(t.state,e,i)}else{let o=t.docView.lineAt(e,i),n=t.state.doc.lineAt(o?o.posAtEnd:e);let r=o?o.posAtStart:n.from,l=o?o.posAtEnd:n.to;if(l<t.state.doc.length&&l==n.to)l++;return s.EditorSelection.range(r,l)}}const ts=T.ie&&T.ie_version<=11;let es=null,is=0,ss=0;function os(t){if(!ts)return t.detail;let e=es,i=ss;es=t;ss=Date.now();return is=!e||i>Date.now()-400&&Math.abs(e.clientX-t.clientX)<2&&Math.abs(e.clientY-t.clientY)<2?(is+1)%3:1}function ns(t,e){let i=t.posAndSideAtCoords({x:e.clientX,y:e.clientY},false),o=os(e);let n=t.state.selection;return{update(t){if(t.docChanged){i.pos=t.changes.mapPos(i.pos);n=n.map(t.changes)}},get(e,r,l){let a=t.posAndSideAtCoords({x:e.clientX,y:e.clientY},false),h;let c=Zi(t,a.pos,a.assoc,o);if(i.pos!=a.pos&&!r){let e=Zi(t,i.pos,i.assoc,o);let n=Math.min(e.from,c.from),r=Math.max(e.to,c.to);c=n<c.from?s.EditorSelection.range(n,r):s.EditorSelection.range(r,n)}if(r)return n.replaceRange(n.main.extend(c.from,c.to));else if(l&&o==1&&n.ranges.length>1&&(h=rs(n,a.pos)))return h;else if(l)return n.addRange(c);else return s.EditorSelection.create([c])}}}function rs(t,e){for(let i=0;i<t.ranges.length;i++){let{from:o,to:n}=t.ranges[i];if(o<=e&&n>=e)return s.EditorSelection.create(t.ranges.slice(0,i).concat(t.ranges.slice(i+1)),t.mainIndex==i?0:t.mainIndex-(t.mainIndex>i?1:0))}return null}Gi.dragstart=(t,e)=>{let{selection:{main:i}}=t.state;if(e.target.draggable){let o=t.docView.tile.nearest(e.target);if(o&&o.isWidget()){let t=o.posAtStart,e=t+o.length;if(t>=i.to||e<=i.from)i=s.EditorSelection.range(t,e)}}let{inputState:o}=t;if(o.mouseSelection)o.mouseSelection.dragging=true;o.draggedContent=i;if(e.dataTransfer){e.dataTransfer.setData("Text",Qi(t.state,Gt,t.state.sliceDoc(i.from,i.to)));e.dataTransfer.effectAllowed="copyMove"}return false};Gi.dragend=t=>{t.inputState.draggedContent=null;return false};function ls(t,e,i,s){i=Qi(t.state,Xt,i);if(!i)return;let o=t.posAtCoords({x:e.clientX,y:e.clientY},false);let{draggedContent:n}=t.inputState;let r=s&&n&&_i(t,e)?{from:n.from,to:n.to}:null;let l={from:o,insert:i};let a=t.state.changes(r?[r,l]:l);t.focus();t.dispatch({changes:a,selection:{anchor:a.mapPos(o,-1),head:a.mapPos(o,1)},userEvent:r?"move.drop":"input.drop"});t.inputState.draggedContent=null}Gi.drop=(t,e)=>{if(!e.dataTransfer)return false;if(t.state.readOnly)return true;let i=e.dataTransfer.files;if(i&&i.length){let s=Array(i.length),o=0;let n=()=>{if(++o==i.length)ls(t,e,s.filter((t=>t!=null)).join(t.state.lineBreak),false)};for(let t=0;t<i.length;t++){let e=new FileReader;e.onerror=n;e.onload=()=>{if(!/[\x00-\x08\x0e-\x1f]{2}/.test(e.result))s[t]=e.result;n()};e.readAsText(i[t])}return true}else{let i=e.dataTransfer.getData("Text");if(i){ls(t,e,i,true);return true}}return false};Gi.paste=(t,e)=>{if(t.state.readOnly)return true;t.observer.flush();let i=$i?null:e.clipboardData;if(i){Ji(t,i.getData("text/plain")||i.getData("text/uri-list"));return true}else{Ui(t);return false}};function as(t,e){let i=t.dom.parentNode;if(!i)return;let s=i.appendChild(document.createElement("textarea"));s.style.cssText="position: fixed; left: -10000px; top: 10px";s.value=e;s.focus();s.selectionEnd=e.length;s.selectionStart=0;setTimeout((()=>{s.remove();t.focus()}),50)}function hs(t){let e=[],i=[],s=false;for(let o of t.selection.ranges)if(!o.empty){e.push(t.sliceDoc(o.from,o.to));i.push(o)}if(!e.length){let o=-1;for(let{from:s}of t.selection.ranges){let n=t.doc.lineAt(s);if(n.number>o){e.push(n.text);i.push({from:n.from,to:Math.min(t.doc.length,n.to+1)})}o=n.number}s=true}return{text:Qi(t,Gt,e.join(t.lineBreak)),ranges:i,linewise:s}}let cs=null;Gi.copy=Gi.cut=(t,e)=>{if(!X(t.contentDOM,t.observer.selectionRange))return false;let{text:i,ranges:s,linewise:o}=hs(t.state);if(!i&&!o)return false;cs=o?i:null;if(e.type=="cut"&&!t.state.readOnly)t.dispatch({changes:s,scrollIntoView:true,userEvent:"delete.cut"});let n=$i?null:e.clipboardData;if(n){n.clearData();n.setData("text/plain",i);return true}else{as(t,i);return false}};const fs=s.Annotation.define();function ds(t,e){let i=[];for(let s of t.facet(Yt)){let o=s(t,e);if(o)i.push(o)}return i.length?t.update({effects:i,annotations:fs.of(true)}):null}function us(t){setTimeout((()=>{let e=t.hasFocus;if(e!=t.inputState.notifiedFocused){let i=ds(t.state,e);if(i)t.dispatch(i);else t.update([])}}),10)}ji.focus=t=>{t.inputState.lastFocusTime=Date.now();if(!t.scrollDOM.scrollTop&&(t.inputState.lastScrollTop||t.inputState.lastScrollLeft)){t.scrollDOM.scrollTop=t.inputState.lastScrollTop;t.scrollDOM.scrollLeft=t.inputState.lastScrollLeft}us(t)};ji.blur=t=>{t.observer.clearSelectionRange();us(t)};ji.compositionstart=ji.compositionupdate=t=>{if(t.observer.editContext)return;if(t.inputState.compositionFirstChange==null)t.inputState.compositionFirstChange=true;if(t.inputState.composing<0){t.inputState.composing=0}};ji.compositionend=t=>{if(t.observer.editContext)return;t.inputState.composing=-1;t.inputState.compositionEndedAt=Date.now();t.inputState.compositionPendingKey=true;t.inputState.compositionPendingChange=t.observer.pendingRecords().length>0;t.inputState.compositionFirstChange=null;if(T.chrome&&T.android){t.observer.flushSoon()}else if(t.inputState.compositionPendingChange){Promise.resolve().then((()=>t.observer.flush()))}else{setTimeout((()=>{if(t.inputState.composing<0&&t.docView.hasComposition)t.update([])}),50)}};ji.contextmenu=t=>{t.inputState.lastContextMenu=Date.now()};Gi.beforeinput=(t,e)=>{var i,s;if(e.inputType=="insertText"||e.inputType=="insertCompositionText"){t.inputState.insertingText=e.data;t.inputState.insertingTextAt=Date.now()}if(e.inputType=="insertReplacementText"&&t.observer.editContext){let s=(i=e.dataTransfer)===null||i===void 0?void 0:i.getData("text/plain"),o=e.getTargetRanges();if(s&&o.length){let e=o[0];let i=t.posAtDOM(e.startContainer,e.startOffset),n=t.posAtDOM(e.endContainer,e.endOffset);Ti(t,{from:i,to:n,insert:t.state.toText(s)},null);return true}}let o;if(T.chrome&&T.android&&(o=Pi.find((t=>t.inputType==e.inputType)))){t.observer.delayAndroidKey(o.key,o.keyCode);if(o.key=="Backspace"||o.key=="Delete"){let e=((s=window.visualViewport)===null||s===void 0?void 0:s.height)||0;setTimeout((()=>{var i;if((((i=window.visualViewport)===null||i===void 0?void 0:i.height)||0)>e+10&&t.hasFocus){t.contentDOM.blur();t.focus()}}),100)}}if(T.ios&&e.inputType=="deleteContentForward"){t.observer.flushSoon()}if(T.safari&&e.inputType=="insertText"&&t.inputState.composing>=0){setTimeout((()=>ji.compositionend(t,e)),20)}return false};const ps=new Set;function gs(t){if(!ps.has(t)){ps.add(t);t.addEventListener("copy",(()=>{}));t.addEventListener("cut",(()=>{}))}}const ms=["pre-wrap","normal","pre-line","break-spaces"];let vs=false;function ws(){vs=false}class bs{constructor(t){this.lineWrapping=t;this.doc=s.Text.empty;this.heightSamples={};this.lineHeight=14;this.charWidth=7;this.textHeight=14;this.lineLength=30}heightForGap(t,e){let i=this.doc.lineAt(e).number-this.doc.lineAt(t).number+1;if(this.lineWrapping)i+=Math.max(0,Math.ceil((e-t-i*this.lineLength*.5)/this.lineLength));return this.lineHeight*i}heightForLine(t){if(!this.lineWrapping)return this.lineHeight;let e=1+Math.max(0,Math.ceil((t-this.lineLength)/Math.max(1,this.lineLength-5)));return e*this.lineHeight}setDoc(t){this.doc=t;return this}mustRefreshForWrapping(t){return ms.indexOf(t)>-1!=this.lineWrapping}mustRefreshForHeights(t){let e=false;for(let i=0;i<t.length;i++){let s=t[i];if(s<0){i++}else if(!this.heightSamples[Math.floor(s*10)]){e=true;this.heightSamples[Math.floor(s*10)]=true}}return e}refresh(t,e,i,s,o,n){let r=ms.indexOf(t)>-1;let l=Math.abs(e-this.lineHeight)>.3||this.lineWrapping!=r||Math.abs(i-this.charWidth)>.1;this.lineWrapping=r;this.lineHeight=e;this.charWidth=i;this.textHeight=s;this.lineLength=o;if(l){this.heightSamples={};for(let t=0;t<n.length;t++){let e=n[t];if(e<0)t++;else this.heightSamples[Math.floor(e*10)]=true}}return l}}class ys{constructor(t,e){this.from=t;this.heights=e;this.index=0}get more(){return this.index<this.heights.length}}class xs{constructor(t,e,i,s,o){this.from=t;this.length=e;this.top=i;this.height=s;this._content=o}get type(){return typeof this._content=="number"?W.Text:Array.isArray(this._content)?this._content:this._content.type}get to(){return this.from+this.length}get bottom(){return this.top+this.height}get widget(){return this._content instanceof F?this._content.widget:null}get widgetLineBreaks(){return typeof this._content=="number"?this._content:0}join(t){let e=(Array.isArray(this._content)?this._content:[this]).concat(Array.isArray(t._content)?t._content:[t]);return new xs(this.from,this.length+t.length,this.top,this.height+t.height,e)}}var Ss=function(t){t[t["ByPos"]=0]="ByPos";t[t["ByHeight"]=1]="ByHeight";t[t["ByPosNoHeight"]=2]="ByPosNoHeight";return t}(Ss||(Ss={}));const Cs=.001;class Ms{constructor(t,e,i=2){this.length=t;this.height=e;this.flags=i}get outdated(){return(this.flags&2)>0}set outdated(t){this.flags=(t?2:0)|this.flags&~2}setHeight(t){if(this.height!=t){if(Math.abs(this.height-t)>Cs)vs=true;this.height=t}}replace(t,e,i){return Ms.of(i)}decomposeLeft(t,e){e.push(this)}decomposeRight(t,e){e.push(this)}applyChanges(t,e,i,s){let o=this,n=i.doc;for(let r=s.length-1;r>=0;r--){let{fromA:l,toA:a,fromB:h,toB:c}=s[r];let f=o.lineAt(l,Ss.ByPosNoHeight,i.setDoc(e),0,0);let d=f.to>=a?f:o.lineAt(a,Ss.ByPosNoHeight,i,0,0);c+=d.to-a;a=d.to;while(r>0&&f.from<=s[r-1].toA){l=s[r-1].fromA;h=s[r-1].fromB;r--;if(l<f.from)f=o.lineAt(l,Ss.ByPosNoHeight,i,0,0)}h+=f.from-l;l=f.from;let u=Ls.build(i.setDoc(n),t,h,c);o=ks(o,o.replace(l,a,u))}return o.updateHeight(i,0)}static empty(){return new Ds(0,0,0)}static of(t){if(t.length==1)return t[0];let e=0,i=t.length,s=0,o=0;for(;;){if(e==i){if(s>o*2){let o=t[e-1];if(o.break)t.splice(--e,1,o.left,null,o.right);else t.splice(--e,1,o.left,o.right);i+=1+o.break;s-=o.size}else if(o>s*2){let e=t[i];if(e.break)t.splice(i,1,e.left,null,e.right);else t.splice(i,1,e.left,e.right);i+=2+e.break;o-=e.size}else{break}}else if(s<o){let i=t[e++];if(i)s+=i.size}else{let e=t[--i];if(e)o+=e.size}}let n=0;if(t[e-1]==null){n=1;e--}else if(t[e]==null){n=1;i++}return new Es(Ms.of(t.slice(0,e)),n,Ms.of(t.slice(i)))}}function ks(t,e){if(t==e)return t;if(t.constructor!=e.constructor)vs=true;return e}Ms.prototype.size=1;const As=P.replace({});class Ts extends Ms{constructor(t,e,i){super(t,e);this.deco=i;this.spaceAbove=0}mainBlock(t,e){return new xs(e,this.length,t+this.spaceAbove,this.height-this.spaceAbove,this.deco||0)}blockAt(t,e,i,s){return this.spaceAbove&&t<i+this.spaceAbove?new xs(s,0,i,this.spaceAbove,As):this.mainBlock(i,s)}lineAt(t,e,i,s,o){let n=this.mainBlock(s,o);return this.spaceAbove?this.blockAt(0,i,s,o).join(n):n}forEachLine(t,e,i,s,o,n){if(t<=o+this.length&&e>=o)n(this.lineAt(0,Ss.ByPos,i,s,o))}setMeasuredHeight(t){let e=t.heights[t.index++];if(e<0){this.spaceAbove=-e;e=t.heights[t.index++]}else{this.spaceAbove=0}this.setHeight(e)}updateHeight(t,e=0,i=false,s){if(s&&s.from<=e&&s.more)this.setMeasuredHeight(s);this.outdated=false;return this}toString(){return`block(${this.length})`}}class Ds extends Ts{constructor(t,e,i){super(t,e,null);this.collapsed=0;this.widgetHeight=0;this.breaks=0;this.spaceAbove=i}mainBlock(t,e){return new xs(e,this.length,t+this.spaceAbove,this.height-this.spaceAbove,this.breaks)}replace(t,e,i){let s=i[0];if(i.length==1&&(s instanceof Ds||s instanceof Os&&s.flags&4)&&Math.abs(this.length-s.length)<10){if(s instanceof Os)s=new Ds(s.length,this.height,this.spaceAbove);else s.height=this.height;if(!this.outdated)s.outdated=false;return s}else{return Ms.of(i)}}updateHeight(t,e=0,i=false,s){if(s&&s.from<=e&&s.more){this.setMeasuredHeight(s)}else if(i||this.outdated){this.spaceAbove=0;this.setHeight(Math.max(this.widgetHeight,t.heightForLine(this.length-this.collapsed))+this.breaks*t.lineHeight)}this.outdated=false;return this}toString(){return`line(${this.length}${this.collapsed?-this.collapsed:""}${this.widgetHeight?":"+this.widgetHeight:""})`}}class Os extends Ms{constructor(t){super(t,0)}heightMetrics(t,e){let i=t.doc.lineAt(e).number,s=t.doc.lineAt(e+this.length).number;let o=s-i+1;let n,r=0;if(t.lineWrapping){let e=Math.min(this.height,t.lineHeight*o);n=e/o;if(this.length>o+1)r=(this.height-e)/(this.length-o-1)}else{n=this.height/o}return{firstLine:i,lastLine:s,perLine:n,perChar:r}}blockAt(t,e,i,s){let{firstLine:o,lastLine:n,perLine:r,perChar:l}=this.heightMetrics(e,s);if(e.lineWrapping){let o=s+(t<e.lineHeight?0:Math.round(Math.max(0,Math.min(1,(t-i)/this.height))*this.length));let n=e.doc.lineAt(o),a=r+n.length*l;let h=Math.max(i,t-a/2);return new xs(n.from,n.length,h,a,0)}else{let s=Math.max(0,Math.min(n-o,Math.floor((t-i)/r)));let{from:l,length:a}=e.doc.line(o+s);return new xs(l,a,i+r*s,r,0)}}lineAt(t,e,i,s,o){if(e==Ss.ByHeight)return this.blockAt(t,i,s,o);if(e==Ss.ByPosNoHeight){let{from:e,to:s}=i.doc.lineAt(t);return new xs(e,s-e,0,0,0)}let{firstLine:n,perLine:r,perChar:l}=this.heightMetrics(i,o);let a=i.doc.lineAt(t),h=r+a.length*l;let c=a.number-n;let f=s+r*c+l*(a.from-o-c);return new xs(a.from,a.length,Math.max(s,Math.min(f,s+this.height-h)),h,0)}forEachLine(t,e,i,s,o,n){t=Math.max(t,o);e=Math.min(e,o+this.length);let{firstLine:r,perLine:l,perChar:a}=this.heightMetrics(i,o);for(let h=t,c=s;h<=e;){let e=i.doc.lineAt(h);if(h==t){let i=e.number-r;c+=l*i+a*(t-o-i)}let s=l+a*e.length;n(new xs(e.from,e.length,c,s,0));c+=s;h=e.to+1}}replace(t,e,i){let s=this.length-e;if(s>0){let t=i[i.length-1];if(t instanceof Os)i[i.length-1]=new Os(t.length+s);else i.push(null,new Os(s-1))}if(t>0){let e=i[0];if(e instanceof Os)i[0]=new Os(t+e.length);else i.unshift(new Os(t-1),null)}return Ms.of(i)}decomposeLeft(t,e){e.push(new Os(t-1),null)}decomposeRight(t,e){e.push(null,new Os(this.length-t-1))}updateHeight(t,e=0,i=false,s){let o=e+this.length;if(s&&s.from<=e+this.length&&s.more){let i=[],n=Math.max(e,s.from),r=-1;if(s.from>e)i.push(new Os(s.from-e-1).updateHeight(t,e));while(n<=o&&s.more){let e=t.doc.lineAt(n).length;if(i.length)i.push(null);let o=s.heights[s.index++],l=0;if(o<0){l=-o;o=s.heights[s.index++]}if(r==-1)r=o;else if(Math.abs(o-r)>=Cs)r=-2;let a=new Ds(e,o,l);a.outdated=false;i.push(a);n+=e+1}if(n<=o)i.push(null,new Os(o-n).updateHeight(t,n));let l=Ms.of(i);if(r<0||Math.abs(l.height-this.height)>=Cs||Math.abs(r-this.heightMetrics(t,e).perLine)>=Cs)vs=true;return ks(this,l)}else if(i||this.outdated){this.setHeight(t.heightForGap(e,e+this.length));this.outdated=false}return this}toString(){return`gap(${this.length})`}}class Es extends Ms{constructor(t,e,i){super(t.length+e+i.length,t.height+i.height,e|(t.outdated||i.outdated?2:0));this.left=t;this.right=i;this.size=t.size+i.size}get break(){return this.flags&1}blockAt(t,e,i,s){let o=i+this.left.height;return t<o?this.left.blockAt(t,e,i,s):this.right.blockAt(t,e,o,s+this.left.length+this.break)}lineAt(t,e,i,s,o){let n=s+this.left.height,r=o+this.left.length+this.break;let l=e==Ss.ByHeight?t<n:t<r;let a=l?this.left.lineAt(t,e,i,s,o):this.right.lineAt(t,e,i,n,r);if(this.break||(l?a.to<r:a.from>r))return a;let h=e==Ss.ByPosNoHeight?Ss.ByPosNoHeight:Ss.ByPos;if(l)return a.join(this.right.lineAt(r,h,i,n,r));else return this.left.lineAt(r,h,i,s,o).join(a)}forEachLine(t,e,i,s,o,n){let r=s+this.left.height,l=o+this.left.length+this.break;if(this.break){if(t<l)this.left.forEachLine(t,e,i,s,o,n);if(e>=l)this.right.forEachLine(t,e,i,r,l,n)}else{let a=this.lineAt(l,Ss.ByPos,i,s,o);if(t<a.from)this.left.forEachLine(t,a.from-1,i,s,o,n);if(a.to>=t&&a.from<=e)n(a);if(e>a.to)this.right.forEachLine(a.to+1,e,i,r,l,n)}}replace(t,e,i){let s=this.left.length+this.break;if(e<s)return this.balanced(this.left.replace(t,e,i),this.right);if(t>this.left.length)return this.balanced(this.left,this.right.replace(t-s,e-s,i));let o=[];if(t>0)this.decomposeLeft(t,o);let n=o.length;for(let r of i)o.push(r);if(t>0)Rs(o,n-1);if(e<this.length){let t=o.length;this.decomposeRight(e,o);Rs(o,t)}return Ms.of(o)}decomposeLeft(t,e){let i=this.left.length;if(t<=i)return this.left.decomposeLeft(t,e);e.push(this.left);if(this.break){i++;if(t>=i)e.push(null)}if(t>i)this.right.decomposeLeft(t-i,e)}decomposeRight(t,e){let i=this.left.length,s=i+this.break;if(t>=s)return this.right.decomposeRight(t-s,e);if(t<i)this.left.decomposeRight(t,e);if(this.break&&t<s)e.push(null);e.push(this.right)}balanced(t,e){if(t.size>2*e.size||e.size>2*t.size)return Ms.of(this.break?[t,null,e]:[t,e]);this.left=ks(this.left,t);this.right=ks(this.right,e);this.setHeight(t.height+e.height);this.outdated=t.outdated||e.outdated;this.size=t.size+e.size;this.length=t.length+this.break+e.length;return this}updateHeight(t,e=0,i=false,s){let{left:o,right:n}=this,r=e+o.length+this.break,l=null;if(s&&s.from<=e+o.length&&s.more)l=o=o.updateHeight(t,e,i,s);else o.updateHeight(t,e,i);if(s&&s.from<=r+n.length&&s.more)l=n=n.updateHeight(t,r,i,s);else n.updateHeight(t,r,i);if(l)return this.balanced(o,n);this.height=this.left.height+this.right.height;this.outdated=false;return this}toString(){return this.left+(this.break?" ":"-")+this.right}}function Rs(t,e){let i,s;if(t[e]==null&&(i=t[e-1])instanceof Os&&(s=t[e+1])instanceof Os)t.splice(e-1,3,new Os(i.length+1+s.length))}const Bs=5;class Ls{constructor(t,e){this.pos=t;this.oracle=e;this.nodes=[];this.lineStart=-1;this.lineEnd=-1;this.covering=null;this.writtenTo=t}get isCovered(){return this.covering&&this.nodes[this.nodes.length-1]==this.covering}span(t,e){if(this.lineStart>-1){let t=Math.min(e,this.lineEnd),i=this.nodes[this.nodes.length-1];if(i instanceof Ds)i.length+=t-this.pos;else if(t>this.pos||!this.isCovered)this.nodes.push(new Ds(t-this.pos,-1,0));this.writtenTo=t;if(e>t){this.nodes.push(null);this.writtenTo++;this.lineStart=-1}}this.pos=e}point(t,e,i){if(t<e||i.heightRelevant){let s=i.widget?i.widget.estimatedHeight:0;let o=i.widget?i.widget.lineBreaks:0;if(s<0)s=this.oracle.lineHeight;let n=e-t;if(i.block){this.addBlock(new Ts(n,s,i))}else if(n||o||s>=Bs){this.addLineDeco(s,o,n)}}else if(e>t){this.span(t,e)}if(this.lineEnd>-1&&this.lineEnd<this.pos)this.lineEnd=this.oracle.doc.lineAt(this.pos).to}enterLine(){if(this.lineStart>-1)return;let{from:t,to:e}=this.oracle.doc.lineAt(this.pos);this.lineStart=t;this.lineEnd=e;if(this.writtenTo<t){if(this.writtenTo<t-1||this.nodes[this.nodes.length-1]==null)this.nodes.push(this.blankContent(this.writtenTo,t-1));this.nodes.push(null)}if(this.pos>t)this.nodes.push(new Ds(this.pos-t,-1,0));this.writtenTo=this.pos}blankContent(t,e){let i=new Os(e-t);if(this.oracle.doc.lineAt(t).to==e)i.flags|=4;return i}ensureLine(){this.enterLine();let t=this.nodes.length?this.nodes[this.nodes.length-1]:null;if(t instanceof Ds)return t;let e=new Ds(0,-1,0);this.nodes.push(e);return e}addBlock(t){this.enterLine();let e=t.deco;if(e&&e.startSide>0&&!this.isCovered)this.ensureLine();this.nodes.push(t);this.writtenTo=this.pos=this.pos+t.length;if(e&&e.endSide>0)this.covering=t}addLineDeco(t,e,i){let s=this.ensureLine();s.length+=i;s.collapsed+=i;s.widgetHeight=Math.max(s.widgetHeight,t);s.breaks+=e;this.writtenTo=this.pos=this.pos+i}finish(t){let e=this.nodes.length==0?null:this.nodes[this.nodes.length-1];if(this.lineStart>-1&&!(e instanceof Ds)&&!this.isCovered)this.nodes.push(new Ds(0,-1,0));else if(this.writtenTo<this.pos||e==null)this.nodes.push(this.blankContent(this.writtenTo,this.pos));let i=t;for(let s of this.nodes){if(s instanceof Ds)s.updateHeight(this.oracle,i);i+=s?s.length:1}return this.nodes}static build(t,e,i,o){let n=new Ls(i,t);s.RangeSet.spans(e,i,o,n,0);return n.finish(i)}}function Hs(t,e,i){let o=new Ws;s.RangeSet.compare(t,e,i,o,0);return o.changes}class Ws{constructor(){this.changes=[]}compareRange(){}comparePoint(t,e,i,s){if(t<e||i&&i.heightRelevant||s&&s.heightRelevant)q(t,e,this.changes,5)}}function Ps(t,e){let i=t.getBoundingClientRect();let s=t.ownerDocument,o=s.defaultView||window;let n=Math.max(0,i.left),r=Math.min(o.innerWidth,i.right);let l=Math.max(0,i.top),a=Math.min(o.innerHeight,i.bottom);for(let h=t.parentNode;h&&h!=s.body;){if(h.nodeType==1){let e=h;let i=window.getComputedStyle(e);if((e.scrollHeight>e.clientHeight||e.scrollWidth>e.clientWidth)&&i.overflow!="visible"){let i=e.getBoundingClientRect();n=Math.max(n,i.left);r=Math.min(r,i.right);l=Math.max(l,i.top);a=Math.min(h==t.parentNode?o.innerHeight:a,i.bottom)}h=i.position=="absolute"||i.position=="fixed"?e.offsetParent:e.parentNode}else if(h.nodeType==11){h=h.host}else{break}}return{left:n-i.left,right:Math.max(n,r)-i.left,top:l-(i.top+e),bottom:Math.max(l,a)-(i.top+e)}}function Ns(t){let e=t.getBoundingClientRect(),i=t.ownerDocument.defaultView||window;return e.left<i.innerWidth&&e.right>0&&e.top<i.innerHeight&&e.bottom>0}function Vs(t,e){let i=t.getBoundingClientRect();return{left:0,right:i.right-i.left,top:e,bottom:i.bottom-(i.top+e)}}class Fs{constructor(t,e,i,s){this.from=t;this.to=e;this.size=i;this.displaySize=s}static same(t,e){if(t.length!=e.length)return false;for(let i=0;i<t.length;i++){let s=t[i],o=e[i];if(s.from!=o.from||s.to!=o.to||s.size!=o.size)return false}return true}draw(t,e){return P.replace({widget:new zs(this.displaySize*(e?t.scaleY:t.scaleX),e)}).range(this.from,this.to)}}class zs extends H{constructor(t,e){super();this.size=t;this.vertical=e}eq(t){return t.size==this.size&&t.vertical==this.vertical}toDOM(){let t=document.createElement("div");if(this.vertical){t.style.height=this.size+"px"}else{t.style.width=this.size+"px";t.style.height="2px";t.style.display="inline-block"}return t}get estimatedHeight(){return this.vertical?this.size:-1}}class Is{constructor(t){this.state=t;this.pixelViewport={left:0,right:window.innerWidth,top:0,bottom:0};this.inView=true;this.paddingTop=0;this.paddingBottom=0;this.contentDOMWidth=0;this.contentDOMHeight=0;this.editorHeight=0;this.editorWidth=0;this.scrollTop=0;this.scrolledToBottom=false;this.scaleX=1;this.scaleY=1;this.scrollAnchorPos=0;this.scrollAnchorHeight=-1;this.scaler=Gs;this.scrollTarget=null;this.printing=false;this.mustMeasureContent=true;this.defaultTextDirection=mt.LTR;this.visibleRanges=[];this.mustEnforceCursorAssoc=false;let e=t.facet(le).some((t=>typeof t!="function"&&t.class=="cm-lineWrapping"));this.heightOracle=new bs(e);this.stateDeco=js(t);this.heightMap=Ms.empty().applyChanges(this.stateDeco,s.Text.empty,this.heightOracle.setDoc(t.doc),[new ve(0,0,0,t.doc.length)]);for(let i=0;i<2;i++){this.viewport=this.getViewport(0,null);if(!this.updateForViewport())break}this.updateViewportLines();this.lineGaps=this.ensureLineGaps([]);this.lineGapDeco=P.set(this.lineGaps.map((t=>t.draw(this,false))));this.computeVisibleRanges()}updateForViewport(){let t=[this.viewport],{main:e}=this.state.selection;for(let i=0;i<=1;i++){let s=i?e.head:e.anchor;if(!t.some((({from:t,to:e})=>s>=t&&s<=e))){let{from:e,to:i}=this.lineBlockAt(s);t.push(new qs(e,i))}}this.viewports=t.sort(((t,e)=>t.from-e.from));return this.updateScaler()}updateScaler(){let t=this.scaler;this.scaler=this.heightMap.height<=7e6?Gs:new $s(this.heightOracle,this.heightMap,this.viewports);return t.eq(this.scaler)?0:2}updateViewportLines(){this.viewportLines=[];this.heightMap.forEachLine(this.viewport.from,this.viewport.to,this.heightOracle.setDoc(this.state.doc),0,0,(t=>{this.viewportLines.push(Us(t,this.scaler))}))}update(t,e=null){this.state=t.state;let i=this.stateDeco;this.stateDeco=js(this.state);let o=t.changedRanges;let n=ve.extendWithRanges(o,Hs(i,this.stateDeco,t?t.changes:s.ChangeSet.empty(this.state.doc.length)));let r=this.heightMap.height;let l=this.scrolledToBottom?null:this.scrollAnchorAt(this.scrollTop);ws();this.heightMap=this.heightMap.applyChanges(this.stateDeco,t.startState.doc,this.heightOracle.setDoc(this.state.doc),n);if(this.heightMap.height!=r||vs)t.flags|=2;if(l){this.scrollAnchorPos=t.changes.mapPos(l.from,-1);this.scrollAnchorHeight=l.top}else{this.scrollAnchorPos=-1;this.scrollAnchorHeight=r}let a=n.length?this.mapViewport(this.viewport,t.changes):this.viewport;if(e&&(e.range.head<a.from||e.range.head>a.to)||!this.viewportIsAppropriate(a))a=this.getViewport(0,e);let h=a.from!=this.viewport.from||a.to!=this.viewport.to;this.viewport=a;t.flags|=this.updateForViewport();if(h||!t.changes.empty||t.flags&2)this.updateViewportLines();if(this.lineGaps.length||this.viewport.to-this.viewport.from>2e3<<1)this.updateLineGaps(this.ensureLineGaps(this.mapLineGaps(this.lineGaps,t.changes)));t.flags|=this.computeVisibleRanges(t.changes);if(e)this.scrollTarget=e;if(!this.mustEnforceCursorAssoc&&(t.selectionSet||t.focusChanged)&&t.view.lineWrapping&&t.state.selection.main.empty&&t.state.selection.main.assoc&&!t.state.facet($t))this.mustEnforceCursorAssoc=true}measure(t){let e=t.contentDOM,i=window.getComputedStyle(e);let o=this.heightOracle;let n=i.whiteSpace;this.defaultTextDirection=i.direction=="rtl"?mt.RTL:mt.LTR;let r=this.heightOracle.mustRefreshForWrapping(n)||this.mustMeasureContent;let l=e.getBoundingClientRect();let a=r||this.mustMeasureContent||this.contentDOMHeight!=l.height;this.contentDOMHeight=l.height;this.mustMeasureContent=false;let h=0,c=0;if(l.width&&l.height){let{scaleX:t,scaleY:i}=et(e,l);if(t>.005&&Math.abs(this.scaleX-t)>.005||i>.005&&Math.abs(this.scaleY-i)>.005){this.scaleX=t;this.scaleY=i;h|=16;r=a=true}}let f=(parseInt(i.paddingTop)||0)*this.scaleY;let d=(parseInt(i.paddingBottom)||0)*this.scaleY;if(this.paddingTop!=f||this.paddingBottom!=d){this.paddingTop=f;this.paddingBottom=d;h|=16|2}if(this.editorWidth!=t.scrollDOM.clientWidth){if(o.lineWrapping)a=true;this.editorWidth=t.scrollDOM.clientWidth;h|=16}let u=t.scrollDOM.scrollTop*this.scaleY;if(this.scrollTop!=u){this.scrollAnchorHeight=-1;this.scrollTop=u}this.scrolledToBottom=dt(t.scrollDOM);let p=(this.printing?Vs:Ps)(e,this.paddingTop);let g=p.top-this.pixelViewport.top,m=p.bottom-this.pixelViewport.bottom;this.pixelViewport=p;let v=this.pixelViewport.bottom>this.pixelViewport.top&&this.pixelViewport.right>this.pixelViewport.left;if(v!=this.inView){this.inView=v;if(v)a=true}if(!this.inView&&!this.scrollTarget&&!Ns(t.dom))return 0;let w=l.width;if(this.contentDOMWidth!=w||this.editorHeight!=t.scrollDOM.clientHeight){this.contentDOMWidth=l.width;this.editorHeight=t.scrollDOM.clientHeight;h|=16}if(a){let e=t.docView.measureVisibleLineHeights(this.viewport);if(o.mustRefreshForHeights(e))r=true;if(r||o.lineWrapping&&Math.abs(w-this.contentDOMWidth)>o.charWidth){let{lineHeight:i,charWidth:s,textHeight:l}=t.docView.measureTextSize();r=i>0&&o.refresh(n,i,s,l,Math.max(5,w/s),e);if(r){t.docView.minWidth=0;h|=16}}if(g>0&&m>0)c=Math.max(g,m);else if(g<0&&m<0)c=Math.min(g,m);ws();for(let i of this.viewports){let n=i.from==this.viewport.from?e:t.docView.measureVisibleLineHeights(i);this.heightMap=(r?Ms.empty().applyChanges(this.stateDeco,s.Text.empty,this.heightOracle,[new ve(0,0,0,t.state.doc.length)]):this.heightMap).updateHeight(o,0,r,new ys(i.from,n))}if(vs)h|=2}let b=!this.viewportIsAppropriate(this.viewport,c)||this.scrollTarget&&(this.scrollTarget.range.head<this.viewport.from||this.scrollTarget.range.head>this.viewport.to);if(b){if(h&2)h|=this.updateScaler();this.viewport=this.getViewport(c,this.scrollTarget);h|=this.updateForViewport()}if(h&2||b)this.updateViewportLines();if(this.lineGaps.length||this.viewport.to-this.viewport.from>2e3<<1)this.updateLineGaps(this.ensureLineGaps(r?[]:this.lineGaps,t));h|=this.computeVisibleRanges();if(this.mustEnforceCursorAssoc){this.mustEnforceCursorAssoc=false;t.docView.enforceCursorAssoc()}return h}get visibleTop(){return this.scaler.fromDOM(this.pixelViewport.top)}get visibleBottom(){return this.scaler.fromDOM(this.pixelViewport.bottom)}getViewport(t,e){let i=.5-Math.max(-.5,Math.min(.5,t/1e3/2));let s=this.heightMap,o=this.heightOracle;let{visibleTop:n,visibleBottom:r}=this;let l=new qs(s.lineAt(n-i*1e3,Ss.ByHeight,o,0,0).from,s.lineAt(r+(1-i)*1e3,Ss.ByHeight,o,0,0).to);if(e){let{head:t}=e.range;if(t<l.from||t>l.to){let i=Math.min(this.editorHeight,this.pixelViewport.bottom-this.pixelViewport.top);let n=s.lineAt(t,Ss.ByPos,o,0,0),r;if(e.y=="center")r=(n.top+n.bottom)/2-i/2;else if(e.y=="start"||e.y=="nearest"&&t<l.from)r=n.top;else r=n.bottom-i;l=new qs(s.lineAt(r-1e3/2,Ss.ByHeight,o,0,0).from,s.lineAt(r+i+1e3/2,Ss.ByHeight,o,0,0).to)}}return l}mapViewport(t,e){let i=e.mapPos(t.from,-1),s=e.mapPos(t.to,1);return new qs(this.heightMap.lineAt(i,Ss.ByPos,this.heightOracle,0,0).from,this.heightMap.lineAt(s,Ss.ByPos,this.heightOracle,0,0).to)}viewportIsAppropriate({from:t,to:e},i=0){if(!this.inView)return true;let{top:s}=this.heightMap.lineAt(t,Ss.ByPos,this.heightOracle,0,0);let{bottom:o}=this.heightMap.lineAt(e,Ss.ByPos,this.heightOracle,0,0);let{visibleTop:n,visibleBottom:r}=this;return(t==0||s<=n-Math.max(10,Math.min(-i,250)))&&(e==this.state.doc.length||o>=r+Math.max(10,Math.min(i,250)))&&(s>n-2*1e3&&o<r+2*1e3)}mapLineGaps(t,e){if(!t.length||e.empty)return t;let i=[];for(let s of t)if(!e.touchesRange(s.from,s.to))i.push(new Fs(e.mapPos(s.from),e.mapPos(s.to),s.size,s.displaySize));return i}ensureLineGaps(t,e){let i=this.heightOracle.lineWrapping;let o=i?1e4:2e3,n=o>>1,r=o<<1;if(this.defaultTextDirection!=mt.LTR&&!i)return[];let l=[];let a=(o,r,h,c)=>{if(r-o<n)return;let f=this.state.selection.main,d=[f.from];if(!f.empty)d.push(f.to);for(let t of d){if(t>o&&t<r){a(o,t-10,h,c);a(t+10,r,h,c);return}}let u=Xs(t,(t=>t.from>=h.from&&t.to<=h.to&&Math.abs(t.from-o)<n&&Math.abs(t.to-r)<n&&!d.some((e=>t.from<e&&t.to>e))));if(!u){if(r<h.to&&e&&i&&e.visibleRanges.some((t=>t.from<=r&&t.to>=r))){let t=e.moveToLineBoundary(s.EditorSelection.cursor(r),false,true).head;if(t>o)r=t}let t=this.gapSize(h,o,r,c);let n=i||t<2e6?t:2e6;u=new Fs(o,r,t,n)}l.push(u)};let h=e=>{if(e.length<r||e.type!=W.Text)return;let s=Ks(e.from,e.to,this.stateDeco);if(s.total<r)return;let n=this.scrollTarget?this.scrollTarget.range.head:null;let l,h;if(i){let t=o/this.heightOracle.lineLength*this.heightOracle.lineHeight;let i,r;if(n!=null){let o=Ys(s,n);let l=((this.visibleBottom-this.visibleTop)/2+t)/e.height;i=o-l;r=o+l}else{i=(this.visibleTop-e.top-t)/e.height;r=(this.visibleBottom-e.top+t)/e.height}l=_s(s,i);h=_s(s,r)}else{let i=s.total*this.heightOracle.charWidth;let r=o*this.heightOracle.charWidth;let a=0;if(i>2e6)for(let s of t){if(s.from>=e.from&&s.from<e.to&&s.size!=s.displaySize&&s.from*this.heightOracle.charWidth+a<this.pixelViewport.left)a=s.size-s.displaySize}let c=this.pixelViewport.left+a,f=this.pixelViewport.right+a;let d,u;if(n!=null){let t=Ys(s,n);let e=((f-c)/2+r)/i;d=t-e;u=t+e}else{d=(c-r)/i;u=(f+r)/i}l=_s(s,d);h=_s(s,u)}if(l>e.from)a(e.from,l,e,s);if(h<e.to)a(h,e.to,e,s)};for(let s of this.viewportLines){if(Array.isArray(s.type))s.type.forEach(h);else h(s)}return l}gapSize(t,e,i,s){let o=Ys(s,i)-Ys(s,e);if(this.heightOracle.lineWrapping){return t.height*o}else{return s.total*this.heightOracle.charWidth*o}}updateLineGaps(t){if(!Fs.same(t,this.lineGaps)){this.lineGaps=t;this.lineGapDeco=P.set(t.map((t=>t.draw(this,this.heightOracle.lineWrapping))))}}computeVisibleRanges(t){let e=this.stateDeco;if(this.lineGaps.length)e=e.concat(this.lineGapDeco);let i=[];s.RangeSet.spans(e,this.viewport.from,this.viewport.to,{span(t,e){i.push({from:t,to:e})},point(){}},20);let o=0;if(i.length!=this.visibleRanges.length){o=8|4}else{for(let e=0;e<i.length&&!(o&8);e++){let s=this.visibleRanges[e],n=i[e];if(s.from!=n.from||s.to!=n.to){o|=4;if(!(t&&t.mapPos(s.from,-1)==n.from&&t.mapPos(s.to,1)==n.to))o|=8}}}this.visibleRanges=i;return o}lineBlockAt(t){return t>=this.viewport.from&&t<=this.viewport.to&&this.viewportLines.find((e=>e.from<=t&&e.to>=t))||Us(this.heightMap.lineAt(t,Ss.ByPos,this.heightOracle,0,0),this.scaler)}lineBlockAtHeight(t){return t>=this.viewportLines[0].top&&t<=this.viewportLines[this.viewportLines.length-1].bottom&&this.viewportLines.find((e=>e.top<=t&&e.bottom>=t))||Us(this.heightMap.lineAt(this.scaler.fromDOM(t),Ss.ByHeight,this.heightOracle,0,0),this.scaler)}scrollAnchorAt(t){let e=this.lineBlockAtHeight(t+8);return e.from>=this.viewport.from||this.viewportLines[0].top-t>200?e:this.viewportLines[0]}elementAtHeight(t){return Us(this.heightMap.blockAt(this.scaler.fromDOM(t),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 qs{constructor(t,e){this.from=t;this.to=e}}function Ks(t,e,i){let o=[],n=t,r=0;s.RangeSet.spans(i,t,e,{span(){},point(t,e){if(t>n){o.push({from:n,to:t});r+=t-n}n=e}},20);if(n<e){o.push({from:n,to:e});r+=e-n}return{total:r,ranges:o}}function _s({total:t,ranges:e},i){if(i<=0)return e[0].from;if(i>=1)return e[e.length-1].to;let s=Math.floor(t*i);for(let o=0;;o++){let{from:t,to:i}=e[o],n=i-t;if(s<=n)return t+s;s-=n}}function Ys(t,e){let i=0;for(let{from:s,to:o}of t.ranges){if(e<=o){i+=e-s;break}i+=o-s}return i/t.total}function Xs(t,e){for(let i of t)if(e(i))return i;return undefined}const Gs={toDOM(t){return t},fromDOM(t){return t},scale:1,eq(t){return t==this}};function js(t){let e=t.facet(ae).filter((t=>typeof t!="function"));let i=t.facet(ce).filter((t=>typeof t!="function"));if(i.length)e.push(s.RangeSet.join(i));return e}class $s{constructor(t,e,i){let s=0,o=0,n=0;this.viewports=i.map((({from:i,to:o})=>{let n=e.lineAt(i,Ss.ByPos,t,0,0).top;let r=e.lineAt(o,Ss.ByPos,t,0,0).bottom;s+=r-n;return{from:i,to:o,top:n,bottom:r,domTop:0,domBottom:0}}));this.scale=(7e6-s)/(e.height-s);for(let r of this.viewports){r.domTop=n+(r.top-o)*this.scale;n=r.domBottom=r.domTop+(r.bottom-r.top);o=r.bottom}}toDOM(t){for(let e=0,i=0,s=0;;e++){let o=e<this.viewports.length?this.viewports[e]:null;if(!o||t<o.top)return s+(t-i)*this.scale;if(t<=o.bottom)return o.domTop+(t-o.top);i=o.bottom;s=o.domBottom}}fromDOM(t){for(let e=0,i=0,s=0;;e++){let o=e<this.viewports.length?this.viewports[e]:null;if(!o||t<o.domTop)return i+(t-s)/this.scale;if(t<=o.domBottom)return o.top+(t-o.domTop);i=o.bottom;s=o.domBottom}}eq(t){if(!(t instanceof $s))return false;return this.scale==t.scale&&this.viewports.length==t.viewports.length&&this.viewports.every(((e,i)=>e.from==t.viewports[i].from&&e.to==t.viewports[i].to))}}function Us(t,e){if(e.scale==1)return t;let i=e.toDOM(t.top),s=e.toDOM(t.bottom);return new xs(t.from,t.length,i,s-i,Array.isArray(t._content)?t._content.map((t=>Us(t,e))):t._content)}const Qs=s.Facet.define({combine:t=>t.join(" ")});const Js=s.Facet.define({combine:t=>t.indexOf(true)>-1});const Zs=o.StyleModule.newName(),to=o.StyleModule.newName(),eo=o.StyleModule.newName();const io={"&light":"."+to,"&dark":"."+eo};function so(t,e,i){return new o.StyleModule(e,{finish(e){return/&/.test(e)?e.replace(/&\w*/,(e=>{if(e=="&")return t;if(!i||!i[e])throw new RangeError(`Unsupported selector: ${e}`);return i[e]})):t+" "+e}})}const oo=so("."+Zs,{"&":{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,overflowAnchor:"none"},".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:"#ddd"},".cm-dropCursor":{position:"absolute"},"&.cm-focused > .cm-scroller > .cm-cursorLayer .cm-cursor":{display:"block"},".cm-iso":{unicodeBidi:"isolate"},".cm-announced":{position:"fixed",top:"-10000px"},"@media print":{".cm-announced":{display:"none"}},"&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",zIndex:200},".cm-gutters-before":{insetInlineStart:0},".cm-gutters-after":{insetInlineEnd:0},"&light .cm-gutters":{backgroundColor:"#f5f5f5",color:"#6c6c6c",border:"0px solid #ddd","&.cm-gutters-before":{borderRightWidth:"1px"},"&.cm-gutters-after":{borderLeftWidth:"1px"}},"&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,zIndex:300},"&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-dialog":{padding:"2px 19px 4px 6px",position:"relative","& label":{fontSize:"80%"}},".cm-dialog-close":{position:"absolute",top:"3px",right:"4px",backgroundColor:"inherit",border:"none",font:"inherit",fontSize:"14px",padding:"0"},".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",userSelect:"none"},".cm-highlightSpace":{backgroundImage:"radial-gradient(circle at 50% 55%, #aaa 20%, transparent 5%)",backgroundPosition:"center"},".cm-highlightTab":{backgroundImage:`url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="200" height="20"><path stroke="%23888" stroke-width="1" fill="none" d="M1 10H196L190 5M190 15L196 10M197 4L197 16"/></svg>')`,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"}},io);const no={childList:true,characterData:true,subtree:true,attributes:true,characterDataOldValue:true};const ro=T.ie&&T.ie_version<=11;class lo{constructor(t){this.view=t;this.active=false;this.editContext=null;this.selectionRange=new ot;this.selectionChanged=false;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=false;this.gapIntersection=null;this.gaps=[];this.printQuery=null;this.parentCheck=-1;this.dom=t.contentDOM;this.observer=new MutationObserver((e=>{for(let t of e)this.queue.push(t);if((T.ie&&T.ie_version<=11||T.ios&&t.composing)&&e.some((t=>t.type=="childList"&&t.removedNodes.length||t.type=="characterData"&&t.oldValue.length>t.target.nodeValue.length)))this.flushSoon();else this.flush()}));if(window.EditContext&&T.android&&t.constructor.EDIT_CONTEXT!==false&&!(T.chrome&&T.chrome_version<126)){this.editContext=new fo(t);if(t.state.facet(ee))t.contentDOM.editContext=this.editContext.editContext}if(ro)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);if(window.matchMedia)this.printQuery=window.matchMedia("print");if(typeof ResizeObserver=="function"){this.resizeScroll=new ResizeObserver((()=>{var t;if(((t=this.view.docView)===null||t===void 0?void 0:t.lastUpdate)<Date.now()-75)this.onResize()}));this.resizeScroll.observe(t.scrollDOM)}this.addWindowListeners(this.win=t.win);this.start();if(typeof IntersectionObserver=="function"){this.intersection=new IntersectionObserver((t=>{if(this.parentCheck<0)this.parentCheck=setTimeout(this.listenForScroll.bind(this),1e3);if(t.length>0&&t[t.length-1].intersectionRatio>0!=this.intersecting){this.intersecting=!this.intersecting;if(this.intersecting!=this.view.inView)this.onScrollChanged(document.createEvent("Event"))}}),{threshold:[0,.001]});this.intersection.observe(this.dom);this.gapIntersection=new IntersectionObserver((t=>{if(t.length>0&&t[t.length-1].intersectionRatio>0)this.onScrollChanged(document.createEvent("Event"))}),{})}this.listenForScroll();this.readSelectionRange()}onScrollChanged(t){this.view.inputState.runHandlers("scroll",t);if(this.intersecting)this.view.measure()}onScroll(t){if(this.intersecting)this.flush(false);if(this.editContext)this.view.requestMeasure(this.editContext.measureReq);this.onScrollChanged(t)}onResize(){if(this.resizeTimeout<0)this.resizeTimeout=setTimeout((()=>{this.resizeTimeout=-1;this.view.requestMeasure()}),50)}onPrint(t){if((t.type=="change"||!t.type)&&!t.matches)return;this.view.viewState.printing=true;this.view.measure();setTimeout((()=>{this.view.viewState.printing=false;this.view.requestMeasure()}),500)}updateGaps(t){if(this.gapIntersection&&(t.length!=this.gaps.length||this.gaps.some(((e,i)=>e!=t[i])))){this.gapIntersection.disconnect();for(let e of t)this.gapIntersection.observe(e);this.gaps=t}}onSelectionChange(t){let e=this.selectionChanged;if(!this.readSelectionRange()||this.delayedAndroidKey)return;let{view:i}=this,s=this.selectionRange;if(i.state.facet(ee)?i.root.activeElement!=this.dom:!X(this.dom,s))return;let o=s.anchorNode&&i.docView.tile.nearest(s.anchorNode);if(o&&o.isWidget()&&o.widget.ignoreEvent(t)){if(!e)this.selectionChanged=false;return}if((T.ie&&T.ie_version<=11||T.android&&T.chrome)&&!i.state.selection.main.empty&&s.focusNode&&j(s.focusNode,s.focusOffset,s.anchorNode,s.anchorOffset))this.flushSoon();else this.flush(false)}readSelectionRange(){let{view:t}=this;let e=_(t.root);if(!e)return false;let i=T.safari&&t.root.nodeType==11&&t.root.activeElement==this.dom&&co(this.view,e)||e;if(!i||this.selectionRange.eq(i))return false;let s=X(this.dom,i);if(s&&!this.selectionChanged&&t.inputState.lastFocusTime>Date.now()-200&&t.inputState.lastTouchTime<Date.now()-300&&ft(this.dom,i)){this.view.inputState.lastFocusTime=0;t.docView.updateSelection();return false}this.selectionRange.setRange(i);if(s)this.selectionChanged=true;return true}setSelectionRange(t,e){this.selectionRange.set(t.node,t.offset,e.node,e.offset);this.selectionChanged=false}clearSelectionRange(){this.selectionRange.set(null,0,null,0)}listenForScroll(){this.parentCheck=-1;let t=0,e=null;for(let i=this.dom;i;){if(i.nodeType==1){if(!e&&t<this.scrollTargets.length&&this.scrollTargets[t]==i)t++;else if(!e)e=this.scrollTargets.slice(0,t);if(e)e.push(i);i=i.assignedSlot||i.parentNode}else if(i.nodeType==11){i=i.host}else{break}}if(t<this.scrollTargets.length&&!e)e=this.scrollTargets.slice(0,t);if(e){for(let t of this.scrollTargets)t.removeEventListener("scroll",this.onScroll);for(let t of this.scrollTargets=e)t.addEventListener("scroll",this.onScroll)}}ignore(t){if(!this.active)return t();try{this.stop();return t()}finally{this.start();this.clear()}}start(){if(this.active)return;this.observer.observe(this.dom,no);if(ro)this.dom.addEventListener("DOMCharacterDataModified",this.onCharData);this.active=true}stop(){if(!this.active)return;this.active=false;this.observer.disconnect();if(ro)this.dom.removeEventListener("DOMCharacterDataModified",this.onCharData)}clear(){this.processRecords();this.queue.length=0;this.selectionChanged=false}delayAndroidKey(t,e){var i;if(!this.delayedAndroidKey){let t=()=>{let t=this.delayedAndroidKey;if(t){this.clearDelayedAndroidKey();this.view.inputState.lastKeyCode=t.keyCode;this.view.inputState.lastKeyTime=Date.now();let e=this.flush();if(!e&&t.force)ht(this.dom,t.key,t.keyCode)}};this.flushingAndroidKey=this.view.win.requestAnimationFrame(t)}if(!this.delayedAndroidKey||t=="Enter")this.delayedAndroidKey={key:t,keyCode:e,force:this.lastChange<Date.now()-50||!!((i=this.delayedAndroidKey)===null||i===void 0?void 0:i.force)}}clearDelayedAndroidKey(){this.win.cancelAnimationFrame(this.flushingAndroidKey);this.delayedAndroidKey=null;this.flushingAndroidKey=-1}flushSoon(){if(this.delayedFlush<0)this.delayedFlush=this.view.win.requestAnimationFrame((()=>{this.delayedFlush=-1;this.flush()}))}forceFlush(){if(this.delayedFlush>=0){this.view.win.cancelAnimationFrame(this.delayedFlush);this.delayedFlush=-1}this.flush()}pendingRecords(){for(let t of this.observer.takeRecords())this.queue.push(t);return this.queue}processRecords(){let t=this.pendingRecords();if(t.length)this.queue=[];let e=-1,i=-1,s=false;for(let o of t){let t=this.readMutation(o);if(!t)continue;if(t.typeOver)s=true;if(e==-1){({from:e,to:i}=t)}else{e=Math.min(t.from,e);i=Math.max(t.to,i)}}return{from:e,to:i,typeOver:s}}readChange(){let{from:t,to:e,typeOver:i}=this.processRecords();let s=this.selectionChanged&&X(this.dom,this.selectionRange);if(t<0&&!s)return null;if(t>-1)this.lastChange=Date.now();this.view.inputState.lastFocusTime=0;this.selectionChanged=false;let o=new Mi(this.view,t,e,i);this.view.docView.domChanged={newSel:o.newSel?o.newSel.main:null};return o}flush(t=true){if(this.delayedFlush>=0||this.delayedAndroidKey)return false;if(t)this.readSelectionRange();let e=this.readChange();if(!e){this.view.requestMeasure();return false}let i=this.view.state;let s=Ai(this.view,e);if(this.view.state==i&&(e.domChanged||e.newSel&&!Bi(this.view.state.selection,e.newSel.main)))this.view.update([]);return s}readMutation(t){let e=this.view.docView.tile.nearest(t.target);if(!e||e.isWidget())return null;e.markDirty(t.type=="attributes");if(t.type=="childList"){let i=ao(e,t.previousSibling||t.target.previousSibling,-1);let s=ao(e,t.nextSibling||t.target.nextSibling,1);return{from:i?e.posAfter(i):e.posAtStart,to:s?e.posBefore(s):e.posAtEnd,typeOver:false}}else if(t.type=="characterData"){return{from:e.posAtStart,to:e.posAtEnd,typeOver:t.target.nodeValue==t.oldValue}}else{return null}}setWindow(t){if(t!=this.win){this.removeWindowListeners(this.win);this.win=t;this.addWindowListeners(this.win)}}addWindowListeners(t){t.addEventListener("resize",this.onResize);if(this.printQuery){if(this.printQuery.addEventListener)this.printQuery.addEventListener("change",this.onPrint);else this.printQuery.addListener(this.onPrint)}else t.addEventListener("beforeprint",this.onPrint);t.addEventListener("scroll",this.onScroll);t.document.addEventListener("selectionchange",this.onSelectionChange)}removeWindowListeners(t){t.removeEventListener("scroll",this.onScroll);t.removeEventListener("resize",this.onResize);if(this.printQuery){if(this.printQuery.removeEventListener)this.printQuery.removeEventListener("change",this.onPrint);else this.printQuery.removeListener(this.onPrint)}else t.removeEventListener("beforeprint",this.onPrint);t.document.removeEventListener("selectionchange",this.onSelectionChange)}update(t){if(this.editContext){this.editContext.update(t);if(t.startState.facet(ee)!=t.state.facet(ee))t.view.contentDOM.editContext=t.state.facet(ee)?this.editContext.editContext:null}}destroy(){var t,e,i;this.stop();(t=this.intersection)===null||t===void 0?void 0:t.disconnect();(e=this.gapIntersection)===null||e===void 0?void 0:e.disconnect();(i=this.resizeScroll)===null||i===void 0?void 0:i.disconnect();for(let s of this.scrollTargets)s.removeEventListener("scroll",this.onScroll);this.removeWindowListeners(this.win);clearTimeout(this.parentCheck);clearTimeout(this.resizeTimeout);this.win.cancelAnimationFrame(this.delayedFlush);this.win.cancelAnimationFrame(this.flushingAndroidKey);if(this.editContext){this.view.contentDOM.editContext=null;this.editContext.destroy()}}}function ao(t,e,i){while(e){let s=ye.get(e);if(s&&s.parent==t)return s;let o=e.parentNode;e=o!=t.dom?o:i>0?e.nextSibling:e.previousSibling}return null}function ho(t,e){let i=e.startContainer,s=e.startOffset;let o=e.endContainer,n=e.endOffset;let r=t.docView.domAtPos(t.state.selection.main.anchor,1);if(j(r.node,r.offset,o,n))[i,s,o,n]=[o,n,i,s];return{anchorNode:i,anchorOffset:s,focusNode:o,focusOffset:n}}function co(t,e){if(e.getComposedRanges){let i=e.getComposedRanges(t.root)[0];if(i)return ho(t,i)}let i=null;function s(t){t.preventDefault();t.stopImmediatePropagation();i=t.getTargetRanges()[0]}t.contentDOM.addEventListener("beforeinput",s,true);t.dom.ownerDocument.execCommand("indent");t.contentDOM.removeEventListener("beforeinput",s,true);return i?ho(t,i):null}class fo{constructor(t){this.from=0;this.to=0;this.pendingContextChange=null;this.handlers=Object.create(null);this.composing=null;this.resetRange(t.state);let e=this.editContext=new window.EditContext({text:t.state.doc.sliceString(this.from,this.to),selectionStart:this.toContextPos(Math.max(this.from,Math.min(this.to,t.state.selection.main.anchor))),selectionEnd:this.toContextPos(t.state.selection.main.head)});this.handlers.textupdate=i=>{let o=t.state.selection.main,{anchor:n,head:r}=o;let l=this.toEditorPos(i.updateRangeStart),a=this.toEditorPos(i.updateRangeEnd);if(t.inputState.composing>=0&&!this.composing)this.composing={contextBase:i.updateRangeStart,editorBase:l,drifted:false};let h=a-l>i.text.length;if(l==this.from&&n<this.from)l=n;else if(a==this.to&&n>this.to)a=n;let c=Oi(t.state.sliceDoc(l,a),i.text,(h?o.from:o.to)-l,h?"end":null);if(!c){let e=s.EditorSelection.single(this.toEditorPos(i.selectionStart),this.toEditorPos(i.selectionEnd));if(!Bi(e,o))t.dispatch({selection:e,userEvent:"select"});return}let f={from:c.from+l,to:c.toA+l,insert:s.Text.of(i.text.slice(c.from,c.toB).split("\n"))};if((T.mac||T.android)&&f.from==r-1&&/^\. ?$/.test(i.text)&&t.contentDOM.getAttribute("autocorrect")=="off")f={from:l,to:a,insert:s.Text.of([i.text.replace("."," ")])};this.pendingContextChange=f;if(!t.state.readOnly){let e=this.to-this.from+(f.to-f.from+f.insert.length);Ti(t,f,s.EditorSelection.single(this.toEditorPos(i.selectionStart,e),this.toEditorPos(i.selectionEnd,e)))}if(this.pendingContextChange){this.revertPending(t.state);this.setSelection(t.state)}if(f.from<f.to&&!f.insert.length&&t.inputState.composing>=0&&!/[\\p{Alphabetic}\\p{Number}_]/.test(e.text.slice(Math.max(0,i.updateRangeStart-1),Math.min(e.text.length,i.updateRangeStart+1))))this.handlers.compositionend(i)};this.handlers.characterboundsupdate=i=>{let s=[],o=null;for(let e=this.toEditorPos(i.rangeStart),n=this.toEditorPos(i.rangeEnd);e<n;e++){let i=t.coordsForChar(e);o=i&&new DOMRect(i.left,i.top,i.right-i.left,i.bottom-i.top)||o||new DOMRect;s.push(o)}e.updateCharacterBounds(i.rangeStart,s)};this.handlers.textformatupdate=e=>{let i=[];for(let t of e.getTextFormats()){let e=t.underlineStyle,s=t.underlineThickness;if(!/none/i.test(e)&&!/none/i.test(s)){let o=this.toEditorPos(t.rangeStart),n=this.toEditorPos(t.rangeEnd);if(o<n){let t=`text-decoration: underline ${/^[a-z]/.test(e)?e+" ":e=="Dashed"?"dashed ":e=="Squiggle"?"wavy ":""}${/thin/i.test(s)?1:2}px`;i.push(P.mark({attributes:{style:t}}).range(o,n))}}}t.dispatch({effects:Zt.of(P.set(i))})};this.handlers.compositionstart=()=>{if(t.inputState.composing<0){t.inputState.composing=0;t.inputState.compositionFirstChange=true}};this.handlers.compositionend=()=>{t.inputState.composing=-1;t.inputState.compositionFirstChange=null;if(this.composing){let{drifted:e}=this.composing;this.composing=null;if(e)this.reset(t.state)}};for(let i in this.handlers)e.addEventListener(i,this.handlers[i]);this.measureReq={read:t=>{this.editContext.updateControlBounds(t.contentDOM.getBoundingClientRect());let e=_(t.root);if(e&&e.rangeCount)this.editContext.updateSelectionBounds(e.getRangeAt(0).getBoundingClientRect())}}}applyEdits(t){let e=0,i=false,s=this.pendingContextChange;t.changes.iterChanges(((o,n,r,l,a)=>{if(i)return;let h=a.length-(n-o);if(s&&n>=s.to){if(s.from==o&&s.to==n&&s.insert.eq(a)){s=this.pendingContextChange=null;e+=h;this.to+=h;return}else{s=null;this.revertPending(t.state)}}o+=e;n+=e;if(n<=this.from){this.from+=h;this.to+=h}else if(o<this.to){if(o<this.from||n>this.to||this.to-this.from+a.length>3e4){i=true;return}this.editContext.updateText(this.toContextPos(o),this.toContextPos(n),a.toString());this.to+=h}e+=h}));if(s&&!i)this.revertPending(t.state);return!i}update(t){let e=this.pendingContextChange,i=t.startState.selection.main;if(this.composing&&(this.composing.drifted||!t.changes.touchesRange(i.from,i.to)&&t.transactions.some((t=>!t.isUserEvent("input.type")&&t.changes.touchesRange(this.from,this.to))))){this.composing.drifted=true;this.composing.editorBase=t.changes.mapPos(this.composing.editorBase)}else if(!this.applyEdits(t)||!this.rangeIsValid(t.state)){this.pendingContextChange=null;this.reset(t.state)}else if(t.docChanged||t.selectionSet||e){this.setSelection(t.state)}if(t.geometryChanged||t.docChanged||t.selectionSet)t.view.requestMeasure(this.measureReq)}resetRange(t){let{head:e}=t.selection.main;this.from=Math.max(0,e-1e4);this.to=Math.min(t.doc.length,e+1e4)}reset(t){this.resetRange(t);this.editContext.updateText(0,this.editContext.text.length,t.doc.sliceString(this.from,this.to));this.setSelection(t)}revertPending(t){let e=this.pendingContextChange;this.pendingContextChange=null;this.editContext.updateText(this.toContextPos(e.from),this.toContextPos(e.from+e.insert.length),t.doc.sliceString(e.from,e.to))}setSelection(t){let{main:e}=t.selection;let i=this.toContextPos(Math.max(this.from,Math.min(this.to,e.anchor)));let s=this.toContextPos(e.head);if(this.editContext.selectionStart!=i||this.editContext.selectionEnd!=s)this.editContext.updateSelection(i,s)}rangeIsValid(t){let{head:e}=t.selection.main;return!(this.from>0&&e-this.from<500||this.to<t.doc.length&&this.to-e<500||this.to-this.from>1e4*3)}toEditorPos(t,e=this.to-this.from){t=Math.min(t,e);let i=this.composing;return i&&i.drifted?i.editorBase+(t-i.contextBase):t+this.from}toContextPos(t){let e=this.composing;return e&&e.drifted?e.contextBase+(t-e.editorBase):t-this.from}destroy(){for(let t in this.handlers)this.editContext.removeEventListener(t,this.handlers[t])}}class uo{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&&this.inputState.composing>0}get compositionStarted(){return!!this.inputState&&this.inputState.composing>=0}get root(){return this._root}get win(){return this.dom.ownerDocument.defaultView||window}constructor(t={}){var e;this.plugins=[];this.pluginMap=new Map;this.editorAttrs={};this.contentAttrs={};this.bidiCache=[];this.destroyed=false;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.className="cm-announced";this.announceDOM.setAttribute("aria-live","polite");this.dom=document.createElement("div");this.dom.appendChild(this.announceDOM);this.dom.appendChild(this.scrollDOM);if(t.parent)t.parent.appendChild(this.dom);let{dispatch:i}=t;this.dispatchTransactions=t.dispatchTransactions||i&&(t=>t.forEach((t=>i(t,this))))||(t=>this.update(t));this.dispatch=this.dispatch.bind(this);this._root=t.root||ct(t.parent)||document;this.viewState=new Is(t.state||s.EditorState.create(t));if(t.scrollTo&&t.scrollTo.is(Jt))this.viewState.scrollTarget=t.scrollTo.value.clip(this.viewState.state);this.plugins=this.state.facet(se).map((t=>new ne(t)));for(let s of this.plugins)s.update(this);this.observer=new lo(this);this.inputState=new Li(this);this.inputState.ensureHandlers(this.plugins);this.docView=new Ge(this);this.mountStyles();this.updateAttrs();this.updateState=0;this.requestMeasure();if((e=document.fonts)===null||e===void 0?void 0:e.ready)document.fonts.ready.then((()=>{this.viewState.mustMeasureContent=true;this.requestMeasure()}))}dispatch(...t){let e=t.length==1&&t[0]instanceof s.Transaction?t:t.length==1&&Array.isArray(t[0])?t[0]:[this.state.update(...t)];this.dispatchTransactions(e,this)}update(t){if(this.updateState!=0)throw new Error("Calls to EditorView.update are not allowed while an update is in progress");let e=false,i=false,o;let n=this.state;for(let s of t){if(s.startState!=n)throw new RangeError("Trying to update state with a transaction that doesn't start from the previous state.");n=s.state}if(this.destroyed){this.viewState.state=n;return}let r=this.hasFocus,l=0,a=null;if(t.some((t=>t.annotation(fs)))){this.inputState.notifiedFocused=r;l=1}else if(r!=this.inputState.notifiedFocused){this.inputState.notifiedFocused=r;a=ds(n,r);if(!a)l=1}let h=this.observer.delayedAndroidKey,c=null;if(h){this.observer.clearDelayedAndroidKey();c=this.observer.readChange();if(c&&!this.state.doc.eq(n.doc)||!this.state.selection.eq(n.selection))c=null}else{this.observer.clear()}if(n.facet(s.EditorState.phrases)!=this.state.facet(s.EditorState.phrases))return this.setState(n);o=we.create(this,n,t);o.flags|=l;let f=this.viewState.scrollTarget;try{this.updateState=2;for(let e of t){if(f)f=f.map(e.changes);if(e.scrollIntoView){let{main:t}=e.state.selection;f=new Qt(t.empty?t:s.EditorSelection.cursor(t.head,t.head>t.anchor?-1:1))}for(let t of e.effects)if(t.is(Jt))f=t.value.clip(this.state)}this.viewState.update(o,f);this.bidiCache=mo.update(this.bidiCache,o.changes);if(!o.empty){this.updatePlugins(o);this.inputState.update(o)}e=this.docView.update(o);if(this.state.facet(me)!=this.styleModules)this.mountStyles();i=this.updateAttrs();this.showAnnouncements(t);this.docView.updateSelection(e,t.some((t=>t.isUserEvent("select.pointer"))))}finally{this.updateState=0}if(o.startState.facet(Qs)!=o.state.facet(Qs))this.viewState.mustMeasureContent=true;if(e||i||f||this.viewState.mustEnforceCursorAssoc||this.viewState.mustMeasureContent)this.requestMeasure();if(e)this.docViewUpdate();if(!o.empty)for(let s of this.state.facet(Kt)){try{s(o)}catch(d){te(this.state,d,"update listener")}}if(a||c)Promise.resolve().then((()=>{if(a&&this.state==a.startState)this.dispatch(a);if(c){if(!Ai(this,c)&&h.force)ht(this.contentDOM,h.key,h.keyCode)}}))}setState(t){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=t;return}this.updateState=2;let e=this.hasFocus;try{for(let t of this.plugins)t.destroy(this);this.viewState=new Is(t);this.plugins=t.facet(se).map((t=>new ne(t)));this.pluginMap.clear();for(let t of this.plugins)t.update(this);this.docView.destroy();this.docView=new Ge(this);this.inputState.ensureHandlers(this.plugins);this.mountStyles();this.updateAttrs();this.bidiCache=[]}finally{this.updateState=0}if(e)this.focus();this.requestMeasure()}updatePlugins(t){let e=t.startState.facet(se),i=t.state.facet(se);if(e!=i){let s=[];for(let o of i){let i=e.indexOf(o);if(i<0){s.push(new ne(o))}else{let e=this.plugins[i];e.mustUpdate=t;s.push(e)}}for(let e of this.plugins)if(e.mustUpdate!=t)e.destroy(this);this.plugins=s;this.pluginMap.clear()}else{for(let e of this.plugins)e.mustUpdate=t}for(let s=0;s<this.plugins.length;s++)this.plugins[s].update(this);if(e!=i)this.inputState.ensureHandlers(this.plugins)}docViewUpdate(){for(let e of this.plugins){let i=e.value;if(i&&i.docViewUpdate){try{i.docViewUpdate(this)}catch(t){te(this.state,t,"doc view update listener")}}}}measure(t=true){if(this.destroyed)return;if(this.measureScheduled>-1)this.win.cancelAnimationFrame(this.measureScheduled);if(this.observer.delayedAndroidKey){this.measureScheduled=-1;this.requestMeasure();return}this.measureScheduled=0;if(t)this.observer.forceFlush();let e=null;let i=this.scrollDOM,s=i.scrollTop*this.scaleY;let{scrollAnchorPos:o,scrollAnchorHeight:n}=this.viewState;if(Math.abs(s-this.viewState.scrollTop)>1)n=-1;this.viewState.scrollAnchorHeight=-1;try{for(let t=0;;t++){if(n<0){if(dt(i)){o=-1;n=this.viewState.heightMap.height}else{let t=this.viewState.scrollAnchorAt(s);o=t.from;n=t.top}}this.updateState=1;let l=this.viewState.measure(this);if(!l&&!this.measureRequests.length&&this.viewState.scrollTarget==null)break;if(t>5){console.warn(this.measureRequests.length?"Measure loop restarted more than 5 times":"Viewport failed to stabilize");break}let a=[];if(!(l&4))[this.measureRequests,a]=[a,this.measureRequests];let h=a.map((t=>{try{return t.read(this)}catch(e){te(this.state,e);return go}}));let c=we.create(this,this.state,[]),f=false;c.flags|=l;if(!e)e=c;else e.flags|=l;this.updateState=2;if(!c.empty){this.updatePlugins(c);this.inputState.update(c);this.updateAttrs();f=this.docView.update(c);if(f)this.docViewUpdate()}for(let t=0;t<a.length;t++)if(h[t]!=go){try{let e=a[t];if(e.write)e.write(h[t],this)}catch(r){te(this.state,r)}}if(f)this.docView.updateSelection(true);if(!c.viewportChanged&&this.measureRequests.length==0){if(this.viewState.editorHeight){if(this.viewState.scrollTarget){this.docView.scrollIntoView(this.viewState.scrollTarget);this.viewState.scrollTarget=null;n=-1;continue}else{let t=o<0?this.viewState.heightMap.height:this.viewState.lineBlockAt(o).top;let e=t-n;if(e>1||e<-1){s=s+e;i.scrollTop=s/this.scaleY;n=-1;continue}}}break}}}finally{this.updateState=0;this.measureScheduled=-1}if(e&&!e.empty)for(let l of this.state.facet(Kt))l(e)}get themeClasses(){return Zs+" "+(this.state.facet(Js)?eo:to)+" "+this.state.facet(Qs)}updateAttrs(){let t=vo(this,re,{class:"cm-editor"+(this.hasFocus?" cm-focused ":" ")+this.themeClasses});let e={spellcheck:"false",autocorrect:"off",autocapitalize:"off",writingsuggestions:"false",translate:"no",contenteditable:!this.state.facet(ee)?"false":"true",class:"cm-content",style:`${T.tabSize}: ${this.state.tabSize}`,role:"textbox","aria-multiline":"true"};if(this.state.readOnly)e["aria-readonly"]="true";vo(this,le,e);let i=this.observer.ignore((()=>{let i=B(this.contentDOM,this.contentAttrs,e);let s=B(this.dom,this.editorAttrs,t);return i||s}));this.editorAttrs=t;this.contentAttrs=e;return i}showAnnouncements(t){let e=true;for(let i of t)for(let t of i.effects)if(t.is(uo.announce)){if(e)this.announceDOM.textContent="";e=false;let i=this.announceDOM.appendChild(document.createElement("div"));i.textContent=t.value}}mountStyles(){this.styleModules=this.state.facet(me);let t=this.state.facet(uo.cspNonce);o.StyleModule.mount(this.root,this.styleModules.concat(oo).reverse(),t?{nonce:t}:undefined)}readMeasured(){if(this.updateState==2)throw new Error("Reading the editor layout isn't allowed during an update");if(this.updateState==0&&this.measureScheduled>-1)this.measure(false)}requestMeasure(t){if(this.measureScheduled<0)this.measureScheduled=this.win.requestAnimationFrame((()=>this.measure()));if(t){if(this.measureRequests.indexOf(t)>-1)return;if(t.key!=null)for(let e=0;e<this.measureRequests.length;e++){if(this.measureRequests[e].key===t.key){this.measureRequests[e]=t;return}}this.measureRequests.push(t)}}plugin(t){let e=this.pluginMap.get(t);if(e===undefined||e&&e.plugin!=t)this.pluginMap.set(t,e=this.plugins.find((e=>e.plugin==t))||null);return e&&e.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(t){this.readMeasured();return this.viewState.elementAtHeight(t)}lineBlockAtHeight(t){this.readMeasured();return this.viewState.lineBlockAtHeight(t)}get viewportLineBlocks(){return this.viewState.viewportLines}lineBlockAt(t){return this.viewState.lineBlockAt(t)}get contentHeight(){return this.viewState.contentHeight}moveByChar(t,e,i){return gi(this,t,ci(this,t,e,i))}moveByGroup(t,e){return gi(this,t,ci(this,t,e,(e=>fi(this,t.head,e))))}visualLineSide(t,e){let i=this.bidiSpans(t),o=this.textDirectionAt(t.from);let n=i[e?i.length-1:0];return s.EditorSelection.cursor(n.side(e,o)+t.from,n.forward(!e,o)?1:-1)}moveToLineBoundary(t,e,i=true){return hi(this,t,e,i)}moveVertically(t,e,i){return gi(this,t,di(this,t,e,i))}domAtPos(t,e=1){return this.docView.domAtPos(t,e)}posAtDOM(t,e=0){return this.docView.posFromDOM(t,e)}posAtCoords(t,e=true){this.readMeasured();let i=vi(this,t,e);return i&&i.pos}posAndSideAtCoords(t,e=true){this.readMeasured();return vi(this,t,e)}coordsAtPos(t,e=1){this.readMeasured();let i=this.docView.coordsAt(t,e);if(!i||i.left==i.right)return i;let s=this.state.doc.lineAt(t),o=this.bidiSpans(s);let n=o[At.find(o,t-s.from,-1,e)];return Z(i,n.dir==mt.LTR==e>0)}coordsForChar(t){this.readMeasured();return this.docView.coordsForChar(t)}get defaultCharacterWidth(){return this.viewState.heightOracle.charWidth}get defaultLineHeight(){return this.viewState.heightOracle.lineHeight}get textDirection(){return this.viewState.defaultTextDirection}textDirectionAt(t){let e=this.state.facet(jt);if(!e||t<this.viewport.from||t>this.viewport.to)return this.textDirection;this.readMeasured();return this.docView.textDirectionAt(t)}get lineWrapping(){return this.viewState.heightOracle.lineWrapping}bidiSpans(t){if(t.length>po)return Wt(t.length);let e=this.textDirectionAt(t.from),i;for(let o of this.bidiCache){if(o.from==t.from&&o.dir==e&&(o.fresh||Tt(o.isolates,i=ue(this,t))))return o.order}if(!i)i=ue(this,t);let s=Ht(t.text,e,i);this.bidiCache.push(new mo(t.from,t.to,e,i,true,s));return s}get hasFocus(){var t;return(this.dom.ownerDocument.hasFocus()||T.safari&&((t=this.inputState)===null||t===void 0?void 0:t.lastContextMenu)>Date.now()-3e4)&&this.root.activeElement==this.contentDOM}focus(){this.observer.ignore((()=>{rt(this.contentDOM);this.docView.updateSelection()}))}setRoot(t){if(this._root!=t){this._root=t;this.observer.setWindow((t.nodeType==9?t:t.ownerDocument).defaultView||window);this.mountStyles()}}destroy(){if(this.root.activeElement==this.contentDOM)this.contentDOM.blur();for(let t of this.plugins)t.destroy(this);this.plugins=[];this.inputState.destroy();this.docView.destroy();this.dom.remove();this.observer.destroy();if(this.measureScheduled>-1)this.win.cancelAnimationFrame(this.measureScheduled);this.destroyed=true}static scrollIntoView(t,e={}){return Jt.of(new Qt(typeof t=="number"?s.EditorSelection.cursor(t):t,e.y,e.x,e.yMargin,e.xMargin))}scrollSnapshot(){let{scrollTop:t,scrollLeft:e}=this.scrollDOM;let i=this.viewState.scrollAnchorAt(t);return Jt.of(new Qt(s.EditorSelection.cursor(i.from),"start","start",i.top-t,e,true))}setTabFocusMode(t){if(t==null)this.inputState.tabFocusMode=this.inputState.tabFocusMode<0?0:-1;else if(typeof t=="boolean")this.inputState.tabFocusMode=t?0:-1;else if(this.inputState.tabFocusMode!=0)this.inputState.tabFocusMode=Date.now()+t}static domEventHandlers(t){return oe.define((()=>({})),{eventHandlers:t})}static domEventObservers(t){return oe.define((()=>({})),{eventObservers:t})}static theme(t,e){let i=o.StyleModule.newName();let s=[Qs.of(i),me.of(so(`.${i}`,t))];if(e&&e.dark)s.push(Js.of(true));return s}static baseTheme(t){return s.Prec.lowest(me.of(so("."+Zs,t,io)))}static findFromDOM(t){var e;let i=t.querySelector(".cm-content");let s=i&&ye.get(i)||ye.get(t);return((e=s===null||s===void 0?void 0:s.root)===null||e===void 0?void 0:e.view)||null}}uo.styleModule=me;uo.inputHandler=_t;uo.clipboardInputFilter=Xt;uo.clipboardOutputFilter=Gt;uo.scrollHandler=Ut;uo.focusChangeEffect=Yt;uo.perLineTextDirection=jt;uo.exceptionSink=qt;uo.updateListener=Kt;uo.editable=ee;uo.mouseSelectionStyle=It;uo.dragMovesSelection=zt;uo.clickAddsSelectionRange=Ft;uo.decorations=ae;uo.blockWrappers=he;uo.outerDecorations=ce;uo.atomicRanges=fe;uo.bidiIsolatedRanges=de;uo.scrollMargins=pe;uo.darkTheme=Js;uo.cspNonce=s.Facet.define({combine:t=>t.length?t[0]:""});uo.contentAttributes=le;uo.editorAttributes=re;uo.lineWrapping=uo.contentAttributes.of({class:"cm-lineWrapping"});uo.announce=s.StateEffect.define();const po=4096;const go={};class mo{constructor(t,e,i,s,o,n){this.from=t;this.to=e;this.dir=i;this.isolates=s;this.fresh=o;this.order=n}static update(t,e){if(e.empty&&!t.some((t=>t.fresh)))return t;let i=[],s=t.length?t[t.length-1].dir:mt.LTR;for(let o=Math.max(0,t.length-10);o<t.length;o++){let n=t[o];if(n.dir==s&&!e.touchesRange(n.from,n.to))i.push(new mo(e.mapPos(n.from,1),e.mapPos(n.to,-1),n.dir,n.isolates,false,n.order))}return i}}function vo(t,e,i){for(let s=t.state.facet(e),o=s.length-1;o>=0;o--){let e=s[o],n=typeof e=="function"?e(t):e;if(n)D(n,i)}return i}const wo=T.mac?"mac":T.windows?"win":T.linux?"linux":"key";function bo(t,e){const i=t.split(/-(?!$)/);let s=i[i.length-1];if(s=="Space")s=" ";let o,n,r,l;for(let a=0;a<i.length-1;++a){const t=i[a];if(/^(cmd|meta|m)$/i.test(t))l=true;else if(/^a(lt)?$/i.test(t))o=true;else if(/^(c|ctrl|control)$/i.test(t))n=true;else if(/^s(hift)?$/i.test(t))r=true;else if(/^mod$/i.test(t)){if(e=="mac")l=true;else n=true}else throw new Error("Unrecognized modifier name: "+t)}if(o)s="Alt-"+s;if(n)s="Ctrl-"+s;if(l)s="Meta-"+s;if(r)s="Shift-"+s;return s}function yo(t,e,i){if(e.altKey)t="Alt-"+t;if(e.ctrlKey)t="Ctrl-"+t;if(e.metaKey)t="Meta-"+t;if(i!==false&&e.shiftKey)t="Shift-"+t;return t}const xo=s.Prec.default(uo.domEventHandlers({keydown(t,e){return Eo(Mo(e.state),t,e,"editor")}}));const So=s.Facet.define({enables:xo});const Co=new WeakMap;function Mo(t){let e=t.facet(So);let i=Co.get(e);if(!i)Co.set(e,i=Do(e.reduce(((t,e)=>t.concat(e)),[])));return i}function ko(t,e,i){return Eo(Mo(t.state),e,t,i)}let Ao=null;const To=4e3;function Do(t,e=wo){let i=Object.create(null);let s=Object.create(null);let o=(t,e)=>{let i=s[t];if(i==null)s[t]=e;else if(i!=e)throw new Error("Key binding "+t+" is used both as a regular binding and as a multi-stroke prefix")};let n=(t,s,n,r,l)=>{var a,h;let c=i[t]||(i[t]=Object.create(null));let f=s.split(/ (?!$)/).map((t=>bo(t,e)));for(let e=1;e<f.length;e++){let i=f.slice(0,e).join(" ");o(i,true);if(!c[i])c[i]={preventDefault:true,stopPropagation:false,run:[e=>{let s=Ao={view:e,prefix:i,scope:t};setTimeout((()=>{if(Ao==s)Ao=null}),To);return true}]}}let d=f.join(" ");o(d,false);let u=c[d]||(c[d]={preventDefault:false,stopPropagation:false,run:((h=(a=c._any)===null||a===void 0?void 0:a.run)===null||h===void 0?void 0:h.slice())||[]});if(n)u.run.push(n);if(r)u.preventDefault=true;if(l)u.stopPropagation=true};for(let r of t){let t=r.scope?r.scope.split(" "):["editor"];if(r.any)for(let e of t){let t=i[e]||(i[e]=Object.create(null));if(!t._any)t._any={preventDefault:false,stopPropagation:false,run:[]};let{any:s}=r;for(let e in t)t[e].run.push((t=>s(t,Oo)))}let s=r[e]||r.key;if(!s)continue;for(let e of t){n(e,s,r.run,r.preventDefault,r.stopPropagation);if(r.shift)n(e,"Shift-"+s,r.shift,r.preventDefault,r.stopPropagation)}}return i}let Oo=null;function Eo(t,e,i,o){Oo=e;let l=p(e);let a=(0,s.codePointAt)(l,0),h=(0,s.codePointSize)(a)==l.length&&l!=" ";let c="",f=false,d=false,u=false;if(Ao&&Ao.view==i&&Ao.scope==o){c=Ao.prefix+" ";if(Vi.indexOf(e.keyCode)<0){d=true;Ao=null}}let g=new Set;let m=t=>{if(t){for(let e of t.run)if(!g.has(e)){g.add(e);if(e(i)){if(t.stopPropagation)u=true;return true}}if(t.preventDefault){if(t.stopPropagation)u=true;d=true}}return false};let v=t[o],w,b;if(v){if(m(v[c+yo(l,e,!h)])){f=true}else if(h&&(e.altKey||e.metaKey||e.ctrlKey)&&!(T.windows&&e.ctrlKey&&e.altKey)&&!(T.mac&&e.altKey&&!(e.ctrlKey||e.metaKey))&&(w=n[e.keyCode])&&w!=l){if(m(v[c+yo(w,e,true)])){f=true}else if(e.shiftKey&&(b=r[e.keyCode])!=l&&b!=w&&m(v[c+yo(b,e,false)])){f=true}}else if(h&&e.shiftKey&&m(v[c+yo(l,e,true)])){f=true}if(!f&&m(v._any))f=true}if(d)f=true;if(f&&u)e.stopPropagation();Oo=null;return f}class Ro{constructor(t,e,i,s,o){this.className=t;this.left=e;this.top=i;this.width=s;this.height=o}draw(){let t=document.createElement("div");t.className=this.className;this.adjust(t);return t}update(t,e){if(e.className!=this.className)return false;this.adjust(t);return true}adjust(t){t.style.left=this.left+"px";t.style.top=this.top+"px";if(this.width!=null)t.style.width=this.width+"px";t.style.height=this.height+"px"}eq(t){return this.left==t.left&&this.top==t.top&&this.width==t.width&&this.height==t.height&&this.className==t.className}static forRange(t,e,i){if(i.empty){let s=t.coordsAtPos(i.head,i.assoc||1);if(!s)return[];let o=Bo(t);return[new Ro(e,s.left-o.left,s.top-o.top,null,s.bottom-s.top)]}else{return Ho(t,e,i)}}}function Bo(t){let e=t.scrollDOM.getBoundingClientRect();let i=t.textDirection==mt.LTR?e.left:e.right-t.scrollDOM.clientWidth*t.scaleX;return{left:i-t.scrollDOM.scrollLeft*t.scaleX,top:e.top-t.scrollDOM.scrollTop*t.scaleY}}function Lo(t,e,i,s){let o=t.coordsAtPos(e,i*2);if(!o)return s;let n=t.dom.getBoundingClientRect();let r=(o.top+o.bottom)/2;let l=t.posAtCoords({x:n.left+1,y:r});let a=t.posAtCoords({x:n.right-1,y:r});if(l==null||a==null)return s;return{from:Math.max(s.from,Math.min(l,a)),to:Math.min(s.to,Math.max(l,a))}}function Ho(t,e,i){if(i.to<=t.viewport.from||i.from>=t.viewport.to)return[];let s=Math.max(i.from,t.viewport.from),o=Math.min(i.to,t.viewport.to);let n=t.textDirection==mt.LTR;let r=t.contentDOM,l=r.getBoundingClientRect(),a=Bo(t);let h=r.querySelector(".cm-line"),c=h&&window.getComputedStyle(h);let f=l.left+(c?parseInt(c.paddingLeft)+Math.min(0,parseInt(c.textIndent)):0);let d=l.right-(c?parseInt(c.paddingRight):0);let u=ai(t,s,1),p=ai(t,o,-1);let g=u.type==W.Text?u:null;let m=p.type==W.Text?p:null;if(g&&(t.lineWrapping||u.widgetLineBreaks))g=Lo(t,s,1,g);if(m&&(t.lineWrapping||p.widgetLineBreaks))m=Lo(t,o,-1,m);if(g&&m&&g.from==m.from&&g.to==m.to){return w(b(i.from,i.to,g))}else{let e=g?b(i.from,null,g):y(u,false);let s=m?b(null,i.to,m):y(p,true);let o=[];if((g||u).to<(m||p).from-(g&&m?1:0)||u.widgetLineBreaks>1&&e.bottom+t.defaultLineHeight/2<s.top)o.push(v(f,e.bottom,d,s.top));else if(e.bottom<s.top&&t.elementAtHeight((e.bottom+s.top)/2).type==W.Text)e.bottom=s.top=(e.bottom+s.top)/2;return w(e).concat(o).concat(w(s))}function v(t,i,s,o){return new Ro(e,t-a.left,i-a.top,Math.max(0,s-t),o-i)}function w({top:t,bottom:e,horizontal:i}){let s=[];for(let o=0;o<i.length;o+=2)s.push(v(i[o],t,i[o+1],e));return s}function b(e,i,s){let o=1e9,r=-1e9,l=[];function a(e,i,a,h,c){let u=t.coordsAtPos(e,e==s.to?-2:2);let p=t.coordsAtPos(a,a==s.from?2:-2);if(!u||!p)return;o=Math.min(u.top,p.top,o);r=Math.max(u.bottom,p.bottom,r);if(c==mt.LTR)l.push(n&&i?f:u.left,n&&h?d:p.right);else l.push(!n&&h?f:p.left,!n&&i?d:u.right)}let h=e!==null&&e!==void 0?e:s.from,c=i!==null&&i!==void 0?i:s.to;for(let n of t.visibleRanges)if(n.to>h&&n.from<c){for(let s=Math.max(n.from,h),o=Math.min(n.to,c);;){let n=t.state.doc.lineAt(s);for(let r of t.bidiSpans(n)){let t=r.from+n.from,l=r.to+n.from;if(t>=o)break;if(l>s)a(Math.max(t,s),e==null&&t<=h,Math.min(l,o),i==null&&l>=c,r.dir)}s=n.to+1;if(s>=o)break}}if(l.length==0)a(h,e==null,c,i==null,t.textDirection);return{top:o,bottom:r,horizontal:l}}function y(t,e){let i=l.top+(e?t.top:t.bottom);return{top:i,bottom:i,horizontal:[]}}}function Wo(t,e){return t.constructor==e.constructor&&t.eq(e)}class Po{constructor(t,e){this.view=t;this.layer=e;this.drawn=[];this.scaleX=1;this.scaleY=1;this.measureReq={read:this.measure.bind(this),write:this.draw.bind(this)};this.dom=t.scrollDOM.appendChild(document.createElement("div"));this.dom.classList.add("cm-layer");if(e.above)this.dom.classList.add("cm-layer-above");if(e.class)this.dom.classList.add(e.class);this.scale();this.dom.setAttribute("aria-hidden","true");this.setOrder(t.state);t.requestMeasure(this.measureReq);if(e.mount)e.mount(this.dom,t)}update(t){if(t.startState.facet(No)!=t.state.facet(No))this.setOrder(t.state);if(this.layer.update(t,this.dom)||t.geometryChanged){this.scale();t.view.requestMeasure(this.measureReq)}}docViewUpdate(t){if(this.layer.updateOnDocViewUpdate!==false)t.requestMeasure(this.measureReq)}setOrder(t){let e=0,i=t.facet(No);while(e<i.length&&i[e]!=this.layer)e++;this.dom.style.zIndex=String((this.layer.above?150:-1)-e)}measure(){return this.layer.markers(this.view)}scale(){let{scaleX:t,scaleY:e}=this.view;if(t!=this.scaleX||e!=this.scaleY){this.scaleX=t;this.scaleY=e;this.dom.style.transform=`scale(${1/t}, ${1/e})`}}draw(t){if(t.length!=this.drawn.length||t.some(((t,e)=>!Wo(t,this.drawn[e])))){let e=this.dom.firstChild,i=0;for(let s of t){if(s.update&&e&&s.constructor&&this.drawn[i].constructor&&s.update(e,this.drawn[i])){e=e.nextSibling;i++}else{this.dom.insertBefore(s.draw(),e)}}while(e){let t=e.nextSibling;e.remove();e=t}this.drawn=t;if(T.safari&&T.safari_version>=26)this.dom.style.display=this.dom.firstChild?"":"none"}}destroy(){if(this.layer.destroy)this.layer.destroy(this.dom,this.view);this.dom.remove()}}const No=s.Facet.define();function Vo(t){return[oe.define((e=>new Po(e,t))),No.of(t)]}const Fo=s.Facet.define({combine(t){return(0,s.combineConfig)(t,{cursorBlinkRate:1200,drawRangeCursor:true},{cursorBlinkRate:(t,e)=>Math.min(t,e),drawRangeCursor:(t,e)=>t||e})}});function zo(t={}){return[Fo.of(t),Ko,Yo,Xo,$t.of(true)]}function Io(t){return t.facet(Fo)}function qo(t){return t.startState.facet(Fo)!=t.state.facet(Fo)}const Ko=Vo({above:true,markers(t){let{state:e}=t,i=e.facet(Fo);let o=[];for(let n of e.selection.ranges){let r=n==e.selection.main;if(n.empty||i.drawRangeCursor){let e=r?"cm-cursor cm-cursor-primary":"cm-cursor cm-cursor-secondary";let i=n.empty?n:s.EditorSelection.cursor(n.head,n.head>n.anchor?-1:1);for(let s of Ro.forRange(t,e,i))o.push(s)}}return o},update(t,e){if(t.transactions.some((t=>t.selection)))e.style.animationName=e.style.animationName=="cm-blink"?"cm-blink2":"cm-blink";let i=qo(t);if(i)_o(t.state,e);return t.docChanged||t.selectionSet||i},mount(t,e){_o(e.state,t)},class:"cm-cursorLayer"});function _o(t,e){e.style.animationDuration=t.facet(Fo).cursorBlinkRate+"ms"}const Yo=Vo({above:false,markers(t){return t.state.selection.ranges.map((e=>e.empty?[]:Ro.forRange(t,"cm-selectionBackground",e))).reduce(((t,e)=>t.concat(e)))},update(t,e){return t.docChanged||t.selectionSet||t.viewportChanged||qo(t)},class:"cm-selectionLayer"});const Xo=s.Prec.highest(uo.theme({".cm-line":{"& ::selection, &::selection":{backgroundColor:"transparent !important"},caretColor:"transparent !important"},".cm-content":{caretColor:"transparent !important","& :focus":{caretColor:"initial !important","&::selection, & ::selection":{backgroundColor:"Highlight !important"}}}}));const Go=s.StateEffect.define({map(t,e){return t==null?null:e.mapPos(t)}});const jo=s.StateField.define({create(){return null},update(t,e){if(t!=null)t=e.changes.mapPos(t);return e.effects.reduce(((t,e)=>e.is(Go)?e.value:t),t)}});const $o=oe.fromClass(class{constructor(t){this.view=t;this.cursor=null;this.measureReq={read:this.readPos.bind(this),write:this.drawCursor.bind(this)}}update(t){var e;let i=t.state.field(jo);if(i==null){if(this.cursor!=null){(e=this.cursor)===null||e===void 0?void 0:e.remove();this.cursor=null}}else{if(!this.cursor){this.cursor=this.view.scrollDOM.appendChild(document.createElement("div"));this.cursor.className="cm-dropCursor"}if(t.startState.field(jo)!=i||t.docChanged||t.geometryChanged)this.view.requestMeasure(this.measureReq)}}readPos(){let{view:t}=this;let e=t.state.field(jo);let i=e!=null&&t.coordsAtPos(e);if(!i)return null;let s=t.scrollDOM.getBoundingClientRect();return{left:i.left-s.left+t.scrollDOM.scrollLeft*t.scaleX,top:i.top-s.top+t.scrollDOM.scrollTop*t.scaleY,height:i.bottom-i.top}}drawCursor(t){if(this.cursor){let{scaleX:e,scaleY:i}=this.view;if(t){this.cursor.style.left=t.left/e+"px";this.cursor.style.top=t.top/i+"px";this.cursor.style.height=t.height/i+"px"}else{this.cursor.style.left="-100000px"}}}destroy(){if(this.cursor)this.cursor.remove()}setDropPos(t){if(this.view.state.field(jo)!=t)this.view.dispatch({effects:Go.of(t)})}},{eventObservers:{dragover(t){this.setDropPos(this.view.posAtCoords({x:t.clientX,y:t.clientY}))},dragleave(t){if(t.target==this.view.contentDOM||!this.view.contentDOM.contains(t.relatedTarget))this.setDropPos(null)},dragend(){this.setDropPos(null)},drop(){this.setDropPos(null)}}});function Uo(){return[jo,$o]}function Qo(t,e,i,s,o){e.lastIndex=0;for(let n=t.iterRange(i,s),r=i,l;!n.next().done;r+=n.value.length){if(!n.lineBreak)while(l=e.exec(n.value))o(r+l.index,l)}}function Jo(t,e){let i=t.visibleRanges;if(i.length==1&&i[0].from==t.viewport.from&&i[0].to==t.viewport.to)return i;let s=[];for(let{from:o,to:n}of i){o=Math.max(t.state.doc.lineAt(o).from,o-e);n=Math.min(t.state.doc.lineAt(n).to,n+e);if(s.length&&s[s.length-1].to>=o)s[s.length-1].to=n;else s.push({from:o,to:n})}return s}class Zo{constructor(t){const{regexp:e,decoration:i,decorate:s,boundary:o,maxLength:n=1e3}=t;if(!e.global)throw new RangeError("The regular expression given to MatchDecorator should have its 'g' flag set");this.regexp=e;if(s){this.addMatch=(t,e,i,o)=>s(o,i,i+t[0].length,t,e)}else if(typeof i=="function"){this.addMatch=(t,e,s,o)=>{let n=i(t,e,s);if(n)o(s,s+t[0].length,n)}}else if(i){this.addMatch=(t,e,s,o)=>o(s,s+t[0].length,i)}else{throw new RangeError("Either 'decorate' or 'decoration' should be provided to MatchDecorator")}this.boundary=o;this.maxLength=n}createDeco(t){let e=new s.RangeSetBuilder,i=e.add.bind(e);for(let{from:s,to:o}of Jo(t,this.maxLength))Qo(t.state.doc,this.regexp,s,o,((e,s)=>this.addMatch(s,t,e,i)));return e.finish()}updateDeco(t,e){let i=1e9,s=-1;if(t.docChanged)t.changes.iterChanges(((e,o,n,r)=>{if(r>=t.view.viewport.from&&n<=t.view.viewport.to){i=Math.min(n,i);s=Math.max(r,s)}}));if(t.viewportMoved||s-i>1e3)return this.createDeco(t.view);if(s>-1)return this.updateRange(t.view,e.map(t.changes),i,s);return e}updateRange(t,e,i,s){for(let o of t.visibleRanges){let n=Math.max(o.from,i),r=Math.min(o.to,s);if(r>=n){let i=t.state.doc.lineAt(n),s=i.to<r?t.state.doc.lineAt(r):i;let l=Math.max(o.from,i.from),a=Math.min(o.to,s.to);if(this.boundary){for(;n>i.from;n--)if(this.boundary.test(i.text[n-1-i.from])){l=n;break}for(;r<s.to;r++)if(this.boundary.test(s.text[r-s.from])){a=r;break}}let h=[],c;let f=(t,e,i)=>h.push(i.range(t,e));if(i==s){this.regexp.lastIndex=l-i.from;while((c=this.regexp.exec(i.text))&&c.index<a-i.from)this.addMatch(c,t,c.index+i.from,f)}else{Qo(t.state.doc,this.regexp,l,a,((e,i)=>this.addMatch(i,t,e,f)))}e=e.update({filterFrom:l,filterTo:a,filter:(t,e)=>t<l||e>a,add:h})}}return e}}const tn=/x/.unicode!=null?"gu":"g";const en=new RegExp("[\0-\b\n--Ÿ­؜​‎‏\u2028\u2029‭‮⁦⁧⁩\ufeff-]",tn);const sn={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 on=null;function nn(){var t;if(on==null&&typeof document!="undefined"&&document.body){let e=document.body.style;on=((t=e.tabSize)!==null&&t!==void 0?t:e.MozTabSize)!=null}return on||false}const rn=s.Facet.define({combine(t){let e=(0,s.combineConfig)(t,{render:null,specialChars:en,addSpecialChars:null});if(e.replaceTabs=!nn())e.specialChars=new RegExp("\t|"+e.specialChars.source,tn);if(e.addSpecialChars)e.specialChars=new RegExp(e.specialChars.source+"|"+e.addSpecialChars.source,tn);return e}});function ln(t={}){return[rn.of(t),hn()]}let an=null;function hn(){return an||(an=oe.fromClass(class{constructor(t){this.view=t;this.decorations=P.none;this.decorationCache=Object.create(null);this.decorator=this.makeDecorator(t.state.facet(rn));this.decorations=this.decorator.createDeco(t)}makeDecorator(t){return new Zo({regexp:t.specialChars,decoration:(e,i,o)=>{let{doc:n}=i.state;let r=(0,s.codePointAt)(e[0],0);if(r==9){let t=n.lineAt(o);let e=i.state.tabSize,r=(0,s.countColumn)(t.text,e,o-t.from);return P.replace({widget:new un((e-r%e)*this.view.defaultCharacterWidth/this.view.scaleX)})}return this.decorationCache[r]||(this.decorationCache[r]=P.replace({widget:new dn(t,r)}))},boundary:t.replaceTabs?undefined:/[^]/})}update(t){let e=t.state.facet(rn);if(t.startState.facet(rn)!=e){this.decorator=this.makeDecorator(e);this.decorations=this.decorator.createDeco(t.view)}else{this.decorations=this.decorator.updateDeco(t,this.decorations)}}},{decorations:t=>t.decorations}))}const cn="•";function fn(t){if(t>=32)return cn;if(t==10)return"␤";return String.fromCharCode(9216+t)}class dn extends H{constructor(t,e){super();this.options=t;this.code=e}eq(t){return t.code==this.code}toDOM(t){let e=fn(this.code);let i=t.state.phrase("Control character")+" "+(sn[this.code]||"0x"+this.code.toString(16));let s=this.options.render&&this.options.render(this.code,i,e);if(s)return s;let o=document.createElement("span");o.textContent=e;o.title=i;o.setAttribute("aria-label",i);o.className="cm-specialChar";return o}ignoreEvent(){return false}}class un extends H{constructor(t){super();this.width=t}eq(t){return t.width==this.width}toDOM(){let t=document.createElement("span");t.textContent="\t";t.className="cm-tab";t.style.width=this.width+"px";return t}ignoreEvent(){return false}}const pn=oe.fromClass(class{constructor(){this.height=1e3;this.attrs={style:"padding-bottom: 1000px"}}update(t){let{view:e}=t;let i=e.viewState.editorHeight-e.defaultLineHeight-e.documentPadding.top-.5;if(i>=0&&i!=this.height){this.height=i;this.attrs={style:`padding-bottom: ${i}px`}}}});function gn(){return[pn,le.of((t=>{var e;return((e=t.plugin(pn))===null||e===void 0?void 0:e.attrs)||null}))]}function mn(){return wn}const vn=P.line({class:"cm-activeLine"});const wn=oe.fromClass(class{constructor(t){this.decorations=this.getDeco(t)}update(t){if(t.docChanged||t.selectionSet)this.decorations=this.getDeco(t.view)}getDeco(t){let e=-1,i=[];for(let s of t.state.selection.ranges){let o=t.lineBlockAt(s.head);if(o.from>e){i.push(vn.range(o.from));e=o.from}}return P.set(i)}},{decorations:t=>t.decorations});class bn extends H{constructor(t){super();this.content=t}toDOM(t){let e=document.createElement("span");e.className="cm-placeholder";e.style.pointerEvents="none";e.appendChild(typeof this.content=="string"?document.createTextNode(this.content):typeof this.content=="function"?this.content(t):this.content.cloneNode(true));e.setAttribute("aria-hidden","true");return e}coordsAt(t){let e=t.firstChild?G(t.firstChild):[];if(!e.length)return null;let i=window.getComputedStyle(t.parentNode);let s=Z(e[0],i.direction!="rtl");let o=parseInt(i.lineHeight);if(s.bottom-s.top>o*1.5)return{left:s.left,right:s.right,top:s.top,bottom:s.top+o};return s}ignoreEvent(){return false}}function yn(t){let e=oe.fromClass(class{constructor(e){this.view=e;this.placeholder=t?P.set([P.widget({widget:new bn(t),side:1}).range(0)]):P.none}get decorations(){return this.view.state.doc.length?P.none:this.placeholder}},{decorations:t=>t.decorations});return typeof t=="string"?[e,uo.contentAttributes.of({"aria-placeholder":t})]:e}const xn=2e3;function Sn(t,e,i){let o=Math.min(e.line,i.line),n=Math.max(e.line,i.line);let r=[];if(e.off>xn||i.off>xn||e.col<0||i.col<0){let l=Math.min(e.off,i.off),a=Math.max(e.off,i.off);for(let e=o;e<=n;e++){let i=t.doc.line(e);if(i.length<=a)r.push(s.EditorSelection.range(i.from+l,i.to+a))}}else{let l=Math.min(e.col,i.col),a=Math.max(e.col,i.col);for(let e=o;e<=n;e++){let i=t.doc.line(e);let o=(0,s.findColumn)(i.text,l,t.tabSize,true);if(o<0){r.push(s.EditorSelection.cursor(i.to))}else{let e=(0,s.findColumn)(i.text,a,t.tabSize);r.push(s.EditorSelection.range(i.from+o,i.from+e))}}}return r}function Cn(t,e){let i=t.coordsAtPos(t.viewport.from);return i?Math.round(Math.abs((i.left-e)/t.defaultCharacterWidth)):-1}function Mn(t,e){let i=t.posAtCoords({x:e.clientX,y:e.clientY},false);let o=t.state.doc.lineAt(i),n=i-o.from;let r=n>xn?-1:n==o.length?Cn(t,e.clientX):(0,s.countColumn)(o.text,t.state.tabSize,i-o.from);return{line:o.number,col:r,off:n}}function kn(t,e){let i=Mn(t,e),o=t.state.selection;if(!i)return null;return{update(t){if(t.docChanged){let e=t.changes.mapPos(t.startState.doc.line(i.line).from);let s=t.state.doc.lineAt(e);i={line:s.number,col:i.col,off:Math.min(i.off,s.length)};o=o.map(t.changes)}},get(e,n,r){let l=Mn(t,e);if(!l)return o;let a=Sn(t.state,i,l);if(!a.length)return o;if(r)return s.EditorSelection.create(a.concat(o.ranges));else return s.EditorSelection.create(a)}}}function An(t){let e=(t===null||t===void 0?void 0:t.eventFilter)||(t=>t.altKey&&t.button==0);return uo.mouseSelectionStyle.of(((t,i)=>e(i)?kn(t,i):null))}const Tn={Alt:[18,t=>!!t.altKey],Control:[17,t=>!!t.ctrlKey],Shift:[16,t=>!!t.shiftKey],Meta:[91,t=>!!t.metaKey]};const Dn={style:"cursor: crosshair"};function On(t={}){let[e,i]=Tn[t.key||"Alt"];let s=oe.fromClass(class{constructor(t){this.view=t;this.isDown=false}set(t){if(this.isDown!=t){this.isDown=t;this.view.update([])}}},{eventObservers:{keydown(t){this.set(t.keyCode==e||i(t))},keyup(t){if(t.keyCode==e||!i(t))this.set(false)},mousemove(t){this.set(i(t))}}});return[s,uo.contentAttributes.of((t=>{var e;return((e=t.plugin(s))===null||e===void 0?void 0:e.isDown)?Dn:null}))]}const En="-10000px";class Rn{constructor(t,e,i,s){this.facet=e;this.createTooltipView=i;this.removeTooltipView=s;this.input=t.state.facet(e);this.tooltips=this.input.filter((t=>t));let o=null;this.tooltipViews=this.tooltips.map((t=>o=i(t,o)))}update(t,e){var i;let s=t.state.facet(this.facet);let o=s.filter((t=>t));if(s===this.input){for(let e of this.tooltipViews)if(e.update)e.update(t);return false}let n=[],r=e?[]:null;for(let l=0;l<o.length;l++){let i=o[l],s=-1;if(!i)continue;for(let t=0;t<this.tooltips.length;t++){let e=this.tooltips[t];if(e&&e.create==i.create)s=t}if(s<0){n[l]=this.createTooltipView(i,l?n[l-1]:null);if(r)r[l]=!!i.above}else{let i=n[l]=this.tooltipViews[s];if(r)r[l]=e[s];if(i.update)i.update(t)}}for(let l of this.tooltipViews)if(n.indexOf(l)<0){this.removeTooltipView(l);(i=l.destroy)===null||i===void 0?void 0:i.call(l)}if(e){r.forEach(((t,i)=>e[i]=t));e.length=r.length}this.input=s;this.tooltips=o;this.tooltipViews=n;return true}}function Bn(t={}){return Hn.of(t)}function Ln(t){let e=t.dom.ownerDocument.documentElement;return{top:0,left:0,bottom:e.clientHeight,right:e.clientWidth}}const Hn=s.Facet.define({combine:t=>{var e,i,s;return{position:T.ios?"absolute":((e=t.find((t=>t.position)))===null||e===void 0?void 0:e.position)||"fixed",parent:((i=t.find((t=>t.parent)))===null||i===void 0?void 0:i.parent)||null,tooltipSpace:((s=t.find((t=>t.tooltipSpace)))===null||s===void 0?void 0:s.tooltipSpace)||Ln}}});const Wn=new WeakMap;const Pn=oe.fromClass(class{constructor(t){this.view=t;this.above=[];this.inView=true;this.madeAbsolute=false;this.lastTransaction=0;this.measureTimeout=-1;let e=t.state.facet(Hn);this.position=e.position;this.parent=e.parent;this.classes=t.themeClasses;this.createContainer();this.measureReq={read:this.readMeasure.bind(this),write:this.writeMeasure.bind(this),key:this};this.resizeObserver=typeof ResizeObserver=="function"?new ResizeObserver((()=>this.measureSoon())):null;this.manager=new Rn(t,zn,((t,e)=>this.createTooltip(t,e)),(t=>{if(this.resizeObserver)this.resizeObserver.unobserve(t.dom);t.dom.remove()}));this.above=this.manager.tooltips.map((t=>!!t.above));this.intersectionObserver=typeof IntersectionObserver=="function"?new IntersectionObserver((t=>{if(Date.now()>this.lastTransaction-50&&t.length>0&&t[t.length-1].intersectionRatio<1)this.measureSoon()}),{threshold:[1]}):null;this.observeIntersection();t.win.addEventListener("resize",this.measureSoon=this.measureSoon.bind(this));this.maybeMeasure()}createContainer(){if(this.parent){this.container=document.createElement("div");this.container.style.position="relative";this.container.className=this.view.themeClasses;this.parent.appendChild(this.container)}else{this.container=this.view.dom}}observeIntersection(){if(this.intersectionObserver){this.intersectionObserver.disconnect();for(let t of this.manager.tooltipViews)this.intersectionObserver.observe(t.dom)}}measureSoon(){if(this.measureTimeout<0)this.measureTimeout=setTimeout((()=>{this.measureTimeout=-1;this.maybeMeasure()}),50)}update(t){if(t.transactions.length)this.lastTransaction=Date.now();let e=this.manager.update(t,this.above);if(e)this.observeIntersection();let i=e||t.geometryChanged;let s=t.state.facet(Hn);if(s.position!=this.position&&!this.madeAbsolute){this.position=s.position;for(let t of this.manager.tooltipViews)t.dom.style.position=this.position;i=true}if(s.parent!=this.parent){if(this.parent)this.container.remove();this.parent=s.parent;this.createContainer();for(let t of this.manager.tooltipViews)this.container.appendChild(t.dom);i=true}else if(this.parent&&this.view.themeClasses!=this.classes){this.classes=this.container.className=this.view.themeClasses}if(i)this.maybeMeasure()}createTooltip(t,e){let i=t.create(this.view);let s=e?e.dom:null;i.dom.classList.add("cm-tooltip");if(t.arrow&&!i.dom.querySelector(".cm-tooltip > .cm-tooltip-arrow")){let t=document.createElement("div");t.className="cm-tooltip-arrow";i.dom.appendChild(t)}i.dom.style.position=this.position;i.dom.style.top=En;i.dom.style.left="0px";this.container.insertBefore(i.dom,s);if(i.mount)i.mount(this.view);if(this.resizeObserver)this.resizeObserver.observe(i.dom);return i}destroy(){var t,e,i;this.view.win.removeEventListener("resize",this.measureSoon);for(let s of this.manager.tooltipViews){s.dom.remove();(t=s.destroy)===null||t===void 0?void 0:t.call(s)}if(this.parent)this.container.remove();(e=this.resizeObserver)===null||e===void 0?void 0:e.disconnect();(i=this.intersectionObserver)===null||i===void 0?void 0:i.disconnect();clearTimeout(this.measureTimeout)}readMeasure(){let t=1,e=1,i=false;if(this.position=="fixed"&&this.manager.tooltipViews.length){let{dom:t}=this.manager.tooltipViews[0];if(T.safari){let e=t.getBoundingClientRect();i=Math.abs(e.top+1e4)>1||Math.abs(e.left)>1}else{i=!!t.offsetParent&&t.offsetParent!=this.container.ownerDocument.body}}if(i||this.position=="absolute"){if(this.parent){let i=this.parent.getBoundingClientRect();if(i.width&&i.height){t=i.width/this.parent.offsetWidth;e=i.height/this.parent.offsetHeight}}else{({scaleX:t,scaleY:e}=this.view.viewState)}}let s=this.view.scrollDOM.getBoundingClientRect(),o=ge(this.view);return{visible:{left:s.left+o.left,top:s.top+o.top,right:s.right-o.right,bottom:s.bottom-o.bottom},parent:this.parent?this.container.getBoundingClientRect():this.view.dom.getBoundingClientRect(),pos:this.manager.tooltips.map(((t,e)=>{let i=this.manager.tooltipViews[e];return i.getCoords?i.getCoords(t.pos):this.view.coordsAtPos(t.pos)})),size:this.manager.tooltipViews.map((({dom:t})=>t.getBoundingClientRect())),space:this.view.state.facet(Hn).tooltipSpace(this.view),scaleX:t,scaleY:e,makeAbsolute:i}}writeMeasure(t){var e;if(t.makeAbsolute){this.madeAbsolute=true;this.position="absolute";for(let t of this.manager.tooltipViews)t.dom.style.position="absolute"}let{visible:i,space:s,scaleX:o,scaleY:n}=t;let r=[];for(let l=0;l<this.manager.tooltips.length;l++){let a=this.manager.tooltips[l],h=this.manager.tooltipViews[l],{dom:c}=h;let f=t.pos[l],d=t.size[l];if(!f||a.clip!==false&&(f.bottom<=Math.max(i.top,s.top)||f.top>=Math.min(i.bottom,s.bottom)||f.right<Math.max(i.left,s.left)-.1||f.left>Math.min(i.right,s.right)+.1)){c.style.top=En;continue}let u=a.arrow?h.dom.querySelector(".cm-tooltip-arrow"):null;let p=u?7:0;let g=d.right-d.left,m=(e=Wn.get(h))!==null&&e!==void 0?e:d.bottom-d.top;let v=h.offset||Fn,w=this.view.textDirection==mt.LTR;let b=d.width>s.right-s.left?w?s.left:s.right-d.width:w?Math.max(s.left,Math.min(f.left-(u?14:0)+v.x,s.right-g)):Math.min(Math.max(s.left,f.left-g+(u?14:0)-v.x),s.right-g);let y=this.above[l];if(!a.strictSide&&(y?f.top-m-p-v.y<s.top:f.bottom+m+p+v.y>s.bottom)&&y==s.bottom-f.bottom>f.top-s.top)y=this.above[l]=!y;let x=(y?f.top-s.top:s.bottom-f.bottom)-p;if(x<m&&h.resize!==false){if(x<this.view.defaultLineHeight){c.style.top=En;continue}Wn.set(h,m);c.style.height=(m=x)/n+"px"}else if(c.style.height){c.style.height=""}let S=y?f.top-m-p-v.y:f.bottom+p+v.y;let C=b+g;if(h.overlap!==true)for(let t of r)if(t.left<C&&t.right>b&&t.top<S+m&&t.bottom>S)S=y?t.top-m-2-p:t.bottom+p+2;if(this.position=="absolute"){c.style.top=(S-t.parent.top)/n+"px";Nn(c,(b-t.parent.left)/o)}else{c.style.top=S/n+"px";Nn(c,b/o)}if(u){let t=f.left+(w?v.x:-v.x)-(b+14-7);u.style.left=t/o+"px"}if(h.overlap!==true)r.push({left:b,top:S,right:C,bottom:S+m});c.classList.toggle("cm-tooltip-above",y);c.classList.toggle("cm-tooltip-below",!y);if(h.positioned)h.positioned(t.space)}}maybeMeasure(){if(this.manager.tooltips.length){if(this.view.inView)this.view.requestMeasure(this.measureReq);if(this.inView!=this.view.inView){this.inView=this.view.inView;if(!this.inView)for(let t of this.manager.tooltipViews)t.dom.style.top=En}}}},{eventObservers:{scroll(){this.maybeMeasure()}}});function Nn(t,e){let i=parseInt(t.style.left,10);if(isNaN(i)||Math.abs(e-i)>1)t.style.left=e+"px"}const Vn=uo.baseTheme({".cm-tooltip":{zIndex:500,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:`${7}px`,width:`${7*2}px`,position:"absolute",zIndex:-1,overflow:"hidden","&:before, &:after":{content:"''",position:"absolute",width:0,height:0,borderLeft:`${7}px solid transparent`,borderRight:`${7}px solid transparent`},".cm-tooltip-above &":{bottom:`-${7}px`,"&:before":{borderTop:`${7}px solid #bbb`},"&:after":{borderTop:`${7}px solid #f5f5f5`,bottom:"1px"}},".cm-tooltip-below &":{top:`-${7}px`,"&:before":{borderBottom:`${7}px solid #bbb`},"&:after":{borderBottom:`${7}px solid #f5f5f5`,top:"1px"}}},"&dark .cm-tooltip .cm-tooltip-arrow":{"&:before":{borderTopColor:"#333338",borderBottomColor:"#333338"},"&:after":{borderTopColor:"transparent",borderBottomColor:"transparent"}}});const Fn={x:0,y:0};const zn=s.Facet.define({enables:[Pn,Vn]});const In=s.Facet.define({combine:t=>t.reduce(((t,e)=>t.concat(e)),[])});class qn{static create(t){return new qn(t)}constructor(t){this.view=t;this.mounted=false;this.dom=document.createElement("div");this.dom.classList.add("cm-tooltip-hover");this.manager=new Rn(t,In,((t,e)=>this.createHostedView(t,e)),(t=>t.dom.remove()))}createHostedView(t,e){let i=t.create(this.view);i.dom.classList.add("cm-tooltip-section");this.dom.insertBefore(i.dom,e?e.dom.nextSibling:this.dom.firstChild);if(this.mounted&&i.mount)i.mount(this.view);return i}mount(t){for(let e of this.manager.tooltipViews){if(e.mount)e.mount(t)}this.mounted=true}positioned(t){for(let e of this.manager.tooltipViews){if(e.positioned)e.positioned(t)}}update(t){this.manager.update(t)}destroy(){var t;for(let e of this.manager.tooltipViews)(t=e.destroy)===null||t===void 0?void 0:t.call(e)}passProp(t){let e=undefined;for(let i of this.manager.tooltipViews){let s=i[t];if(s!==undefined){if(e===undefined)e=s;else if(e!==s)return undefined}}return e}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 Kn=zn.compute([In],(t=>{let e=t.facet(In);if(e.length===0)return null;return{pos:Math.min(...e.map((t=>t.pos))),end:Math.max(...e.map((t=>{var e;return(e=t.end)!==null&&e!==void 0?e:t.pos}))),create:qn.create,above:e[0].above,arrow:e.some((t=>t.arrow))}}));class _n{constructor(t,e,i,s,o){this.view=t;this.source=e;this.field=i;this.setHover=s;this.hoverTime=o;this.hoverTimeout=-1;this.restartTimeout=-1;this.pending=null;this.lastMove={x:0,y:0,target:t.dom,time:0};this.checkHover=this.checkHover.bind(this);t.dom.addEventListener("mouseleave",this.mouseleave=this.mouseleave.bind(this));t.dom.addEventListener("mousemove",this.mousemove=this.mousemove.bind(this))}update(){if(this.pending){this.pending=null;clearTimeout(this.restartTimeout);this.restartTimeout=setTimeout((()=>this.startHover()),20)}}get active(){return this.view.state.field(this.field)}checkHover(){this.hoverTimeout=-1;if(this.active.length)return;let t=Date.now()-this.lastMove.time;if(t<this.hoverTime)this.hoverTimeout=setTimeout(this.checkHover,this.hoverTime-t);else this.startHover()}startHover(){clearTimeout(this.restartTimeout);let{view:t,lastMove:e}=this;let i=t.docView.tile.nearest(e.target);if(!i)return;let s,o=1;if(i.isWidget()){s=i.posAtStart}else{s=t.posAtCoords(e);if(s==null)return;let i=t.coordsAtPos(s);if(!i||e.y<i.top||e.y>i.bottom||e.x<i.left-t.defaultCharacterWidth||e.x>i.right+t.defaultCharacterWidth)return;let n=t.bidiSpans(t.state.doc.lineAt(s)).find((t=>t.from<=s&&t.to>=s));let r=n&&n.dir==mt.RTL?-1:1;o=e.x<i.left?-r:r}let n=this.source(t,s,o);if(n===null||n===void 0?void 0:n.then){let e=this.pending={pos:s};n.then((i=>{if(this.pending==e){this.pending=null;if(i&&!(Array.isArray(i)&&!i.length))t.dispatch({effects:this.setHover.of(Array.isArray(i)?i:[i])})}}),(e=>te(t.state,e,"hover tooltip")))}else if(n&&!(Array.isArray(n)&&!n.length)){t.dispatch({effects:this.setHover.of(Array.isArray(n)?n:[n])})}}get tooltip(){let t=this.view.plugin(Pn);let e=t?t.manager.tooltips.findIndex((t=>t.create==qn.create)):-1;return e>-1?t.manager.tooltipViews[e]:null}mousemove(t){var e,i;this.lastMove={x:t.clientX,y:t.clientY,target:t.target,time:Date.now()};if(this.hoverTimeout<0)this.hoverTimeout=setTimeout(this.checkHover,this.hoverTime);let{active:s,tooltip:o}=this;if(s.length&&o&&!Xn(o.dom,t)||this.pending){let{pos:o}=s[0]||this.pending,n=(i=(e=s[0])===null||e===void 0?void 0:e.end)!==null&&i!==void 0?i:o;if(o==n?this.view.posAtCoords(this.lastMove)!=o:!Gn(this.view,o,n,t.clientX,t.clientY)){this.view.dispatch({effects:this.setHover.of([])});this.pending=null}}}mouseleave(t){clearTimeout(this.hoverTimeout);this.hoverTimeout=-1;let{active:e}=this;if(e.length){let{tooltip:e}=this;let i=e&&e.dom.contains(t.relatedTarget);if(!i)this.view.dispatch({effects:this.setHover.of([])});else this.watchTooltipLeave(e.dom)}}watchTooltipLeave(t){let e=i=>{t.removeEventListener("mouseleave",e);if(this.active.length&&!this.view.dom.contains(i.relatedTarget))this.view.dispatch({effects:this.setHover.of([])})};t.addEventListener("mouseleave",e)}destroy(){clearTimeout(this.hoverTimeout);clearTimeout(this.restartTimeout);this.view.dom.removeEventListener("mouseleave",this.mouseleave);this.view.dom.removeEventListener("mousemove",this.mousemove)}}const Yn=4;function Xn(t,e){let{left:i,right:s,top:o,bottom:n}=t.getBoundingClientRect(),r;if(r=t.querySelector(".cm-tooltip-arrow")){let t=r.getBoundingClientRect();o=Math.min(t.top,o);n=Math.max(t.bottom,n)}return e.clientX>=i-Yn&&e.clientX<=s+Yn&&e.clientY>=o-Yn&&e.clientY<=n+Yn}function Gn(t,e,i,s,o,n){let r=t.scrollDOM.getBoundingClientRect();let l=t.documentTop+t.documentPadding.top+t.contentHeight;if(r.left>s||r.right<s||r.top>o||Math.min(r.bottom,l)<o)return false;let a=t.posAtCoords({x:s,y:o},false);return a>=e&&a<=i}function jn(t,e={}){let i=s.StateEffect.define();let o=s.StateField.define({create(){return[]},update(t,o){if(t.length){if(e.hideOnChange&&(o.docChanged||o.selection))t=[];else if(e.hideOn)t=t.filter((t=>!e.hideOn(o,t)));if(o.docChanged){let e=[];for(let i of t){let t=o.changes.mapPos(i.pos,-1,s.MapMode.TrackDel);if(t!=null){let s=Object.assign(Object.create(null),i);s.pos=t;if(s.end!=null)s.end=o.changes.mapPos(s.end);e.push(s)}}t=e}}for(let e of o.effects){if(e.is(i))t=e.value;if(e.is(Qn))t=[]}return t},provide:t=>In.from(t)});return{active:o,extension:[o,oe.define((s=>new _n(s,t,o,i,e.hoverTime||300))),Kn]}}function $n(t,e){let i=t.plugin(Pn);if(!i)return null;let s=i.manager.tooltips.indexOf(e);return s<0?null:i.manager.tooltipViews[s]}function Un(t){return t.facet(In).some((t=>t))}const Qn=s.StateEffect.define();const Jn=Qn.of(null);function Zn(t){let e=t.plugin(Pn);if(e)e.maybeMeasure()}const tr=s.Facet.define({combine(t){let e,i;for(let s of t){e=e||s.topContainer;i=i||s.bottomContainer}return{topContainer:e,bottomContainer:i}}});function er(t){return t?[tr.of(t)]:[]}function ir(t,e){let i=t.plugin(sr);let s=i?i.specs.indexOf(e):-1;return s>-1?i.panels[s]:null}const sr=oe.fromClass(class{constructor(t){this.input=t.state.facet(rr);this.specs=this.input.filter((t=>t));this.panels=this.specs.map((e=>e(t)));let e=t.state.facet(tr);this.top=new or(t,true,e.topContainer);this.bottom=new or(t,false,e.bottomContainer);this.top.sync(this.panels.filter((t=>t.top)));this.bottom.sync(this.panels.filter((t=>!t.top)));for(let i of this.panels){i.dom.classList.add("cm-panel");if(i.mount)i.mount()}}update(t){let e=t.state.facet(tr);if(this.top.container!=e.topContainer){this.top.sync([]);this.top=new or(t.view,true,e.topContainer)}if(this.bottom.container!=e.bottomContainer){this.bottom.sync([]);this.bottom=new or(t.view,false,e.bottomContainer)}this.top.syncClasses();this.bottom.syncClasses();let i=t.state.facet(rr);if(i!=this.input){let e=i.filter((t=>t));let s=[],o=[],n=[],r=[];for(let i of e){let e=this.specs.indexOf(i),l;if(e<0){l=i(t.view);r.push(l)}else{l=this.panels[e];if(l.update)l.update(t)}s.push(l);(l.top?o:n).push(l)}this.specs=e;this.panels=s;this.top.sync(o);this.bottom.sync(n);for(let t of r){t.dom.classList.add("cm-panel");if(t.mount)t.mount()}}else{for(let e of this.panels)if(e.update)e.update(t)}}destroy(){this.top.sync([]);this.bottom.sync([])}},{provide:t=>uo.scrollMargins.of((e=>{let i=e.plugin(t);return i&&{top:i.top.scrollMargin(),bottom:i.bottom.scrollMargin()}}))});class or{constructor(t,e,i){this.view=t;this.top=e;this.container=i;this.dom=undefined;this.classes="";this.panels=[];this.syncClasses()}sync(t){for(let e of this.panels)if(e.destroy&&t.indexOf(e)<0)e.destroy();this.panels=t;this.syncDOM()}syncDOM(){if(this.panels.length==0){if(this.dom){this.dom.remove();this.dom=undefined}return}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 t=this.container||this.view.dom;t.insertBefore(this.dom,this.top?t.firstChild:null)}let t=this.dom.firstChild;for(let e of this.panels){if(e.dom.parentNode==this.dom){while(t!=e.dom)t=nr(t);t=t.nextSibling}else{this.dom.insertBefore(e.dom,t)}}while(t)t=nr(t)}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)return;for(let t of this.classes.split(" "))if(t)this.container.classList.remove(t);for(let t of(this.classes=this.view.themeClasses).split(" "))if(t)this.container.classList.add(t)}}function nr(t){let e=t.nextSibling;t.remove();return e}const rr=s.Facet.define({enables:sr});function lr(t,e){let i;let o=new Promise((t=>i=t));let n=t=>dr(t,e,i);if(t.state.field(hr,false)){t.dispatch({effects:cr.of(n)})}else{t.dispatch({effects:s.StateEffect.appendConfig.of(hr.init((()=>[n])))})}let r=fr.of(n);return{close:r,result:o.then((e=>{let i=t.win.queueMicrotask||(e=>t.win.setTimeout(e,10));i((()=>{if(t.state.field(hr).indexOf(n)>-1)t.dispatch({effects:r})}));return e}))}}function ar(t,e){let i=t.state.field(hr,false)||[];for(let s of i){let i=ir(t,s);if(i&&i.dom.classList.contains(e))return i}return null}const hr=s.StateField.define({create(){return[]},update(t,e){for(let i of e.effects){if(i.is(cr))t=[i.value].concat(t);else if(i.is(fr))t=t.filter((t=>t!=i.value))}return t},provide:t=>rr.computeN([t],(e=>e.field(t)))});const cr=s.StateEffect.define();const fr=s.StateEffect.define();function dr(t,e,i){let s=e.content?e.content(t,(()=>r(null))):null;if(!s){s=(0,g.A)("form");if(e.input){let t=(0,g.A)("input",e.input);if(/^(text|password|number|email|tel|url)$/.test(t.type))t.classList.add("cm-textfield");if(!t.name)t.name="input";s.appendChild((0,g.A)("label",(e.label||"")+": ",t))}else{s.appendChild(document.createTextNode(e.label||""))}s.appendChild(document.createTextNode(" "));s.appendChild((0,g.A)("button",{class:"cm-button",type:"submit"},e.submitLabel||"OK"))}let o=s.nodeName=="FORM"?[s]:s.querySelectorAll("form");for(let l=0;l<o.length;l++){let t=o[l];t.addEventListener("keydown",(e=>{if(e.keyCode==27){e.preventDefault();r(null)}else if(e.keyCode==13){e.preventDefault();r(t)}}));t.addEventListener("submit",(e=>{e.preventDefault();r(t)}))}let n=(0,g.A)("div",s,(0,g.A)("button",{onclick:()=>r(null),"aria-label":t.state.phrase("close"),class:"cm-dialog-close",type:"button"},["×"]));if(e.class)n.className=e.class;n.classList.add("cm-dialog");function r(e){if(n.contains(n.ownerDocument.activeElement))t.focus();i(e)}return{dom:n,top:e.top,mount:()=>{if(e.focus){let t;if(typeof e.focus=="string")t=s.querySelector(e.focus);else t=s.querySelector("input")||s.querySelector("button");if(t&&"select"in t)t.select();else if(t&&"focus"in t)t.focus()}}}}class ur extends s.RangeValue{compare(t){return this==t||this.constructor==t.constructor&&this.eq(t)}eq(t){return false}destroy(t){}}ur.prototype.elementClass="";ur.prototype.toDOM=undefined;ur.prototype.mapMode=s.MapMode.TrackBefore;ur.prototype.startSide=ur.prototype.endSide=-1;ur.prototype.point=true;const pr=s.Facet.define();const gr=s.Facet.define();const mr={class:"",renderEmptyElements:false,elementStyle:"",markers:()=>s.RangeSet.empty,lineMarker:()=>null,widgetMarker:()=>null,lineMarkerChange:null,initialSpacer:null,updateSpacer:null,domEventHandlers:{},side:"before"};const vr=s.Facet.define();function wr(t){return[yr(),vr.of({...mr,...t})]}const br=s.Facet.define({combine:t=>t.some((t=>t))});function yr(t){let e=[xr];if(t&&t.fixed===false)e.push(br.of(true));return e}const xr=oe.fromClass(class{constructor(t){this.view=t;this.domAfter=null;this.prevViewport=t.viewport;this.dom=document.createElement("div");this.dom.className="cm-gutters cm-gutters-before";this.dom.setAttribute("aria-hidden","true");this.dom.style.minHeight=this.view.contentHeight/this.view.scaleY+"px";this.gutters=t.state.facet(vr).map((e=>new kr(t,e)));this.fixed=!t.state.facet(br);for(let e of this.gutters){if(e.config.side=="after")this.getDOMAfter().appendChild(e.dom);else this.dom.appendChild(e.dom)}if(this.fixed){this.dom.style.position="sticky"}this.syncGutters(false);t.scrollDOM.insertBefore(this.dom,t.contentDOM)}getDOMAfter(){if(!this.domAfter){this.domAfter=document.createElement("div");this.domAfter.className="cm-gutters cm-gutters-after";this.domAfter.setAttribute("aria-hidden","true");this.domAfter.style.minHeight=this.view.contentHeight/this.view.scaleY+"px";this.domAfter.style.position=this.fixed?"sticky":"";this.view.scrollDOM.appendChild(this.domAfter)}return this.domAfter}update(t){if(this.updateGutters(t)){let e=this.prevViewport,i=t.view.viewport;let s=Math.min(e.to,i.to)-Math.max(e.from,i.from);this.syncGutters(s<(i.to-i.from)*.8)}if(t.geometryChanged){let t=this.view.contentHeight/this.view.scaleY+"px";this.dom.style.minHeight=t;if(this.domAfter)this.domAfter.style.minHeight=t}if(this.view.state.facet(br)!=!this.fixed){this.fixed=!this.fixed;this.dom.style.position=this.fixed?"sticky":"";if(this.domAfter)this.domAfter.style.position=this.fixed?"sticky":""}this.prevViewport=t.view.viewport}syncGutters(t){let e=this.dom.nextSibling;if(t){this.dom.remove();if(this.domAfter)this.domAfter.remove()}let i=s.RangeSet.iter(this.view.state.facet(pr),this.view.viewport.from);let o=[];let n=this.gutters.map((t=>new Mr(t,this.view.viewport,-this.view.documentPadding.top)));for(let s of this.view.viewportLineBlocks){if(o.length)o=[];if(Array.isArray(s.type)){let t=true;for(let e of s.type){if(e.type==W.Text&&t){Cr(i,o,e.from);for(let t of n)t.line(this.view,e,o);t=false}else if(e.widget){for(let t of n)t.widget(this.view,e)}}}else if(s.type==W.Text){Cr(i,o,s.from);for(let t of n)t.line(this.view,s,o)}else if(s.widget){for(let t of n)t.widget(this.view,s)}}for(let s of n)s.finish();if(t){this.view.scrollDOM.insertBefore(this.dom,e);if(this.domAfter)this.view.scrollDOM.appendChild(this.domAfter)}}updateGutters(t){let e=t.startState.facet(vr),i=t.state.facet(vr);let o=t.docChanged||t.heightChanged||t.viewportChanged||!s.RangeSet.eq(t.startState.facet(pr),t.state.facet(pr),t.view.viewport.from,t.view.viewport.to);if(e==i){for(let e of this.gutters)if(e.update(t))o=true}else{o=true;let s=[];for(let o of i){let i=e.indexOf(o);if(i<0){s.push(new kr(this.view,o))}else{this.gutters[i].update(t);s.push(this.gutters[i])}}for(let t of this.gutters){t.dom.remove();if(s.indexOf(t)<0)t.destroy()}for(let t of s){if(t.config.side=="after")this.getDOMAfter().appendChild(t.dom);else this.dom.appendChild(t.dom)}this.gutters=s}return o}destroy(){for(let t of this.gutters)t.destroy();this.dom.remove();if(this.domAfter)this.domAfter.remove()}},{provide:t=>uo.scrollMargins.of((e=>{let i=e.plugin(t);if(!i||i.gutters.length==0||!i.fixed)return null;let s=i.dom.offsetWidth*e.scaleX,o=i.domAfter?i.domAfter.offsetWidth*e.scaleX:0;return e.textDirection==mt.LTR?{left:s,right:o}:{right:s,left:o}}))});function Sr(t){return Array.isArray(t)?t:[t]}function Cr(t,e,i){while(t.value&&t.from<=i){if(t.from==i)e.push(t.value);t.next()}}class Mr{constructor(t,e,i){this.gutter=t;this.height=i;this.i=0;this.cursor=s.RangeSet.iter(t.markers,e.from)}addElement(t,e,i){let{gutter:s}=this,o=(e.top-this.height)/t.scaleY,n=e.height/t.scaleY;if(this.i==s.elements.length){let e=new Ar(t,n,o,i);s.elements.push(e);s.dom.appendChild(e.dom)}else{s.elements[this.i].update(t,n,o,i)}this.height=e.bottom;this.i++}line(t,e,i){let s=[];Cr(this.cursor,s,e.from);if(i.length)s=s.concat(i);let o=this.gutter.config.lineMarker(t,e,s);if(o)s.unshift(o);let n=this.gutter;if(s.length==0&&!n.config.renderEmptyElements)return;this.addElement(t,e,s)}widget(t,e){let i=this.gutter.config.widgetMarker(t,e.widget,e),s=i?[i]:null;for(let o of t.state.facet(gr)){let i=o(t,e.widget,e);if(i)(s||(s=[])).push(i)}if(s)this.addElement(t,e,s)}finish(){let t=this.gutter;while(t.elements.length>this.i){let e=t.elements.pop();t.dom.removeChild(e.dom);e.destroy()}}}class kr{constructor(t,e){this.view=t;this.config=e;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 e.domEventHandlers){this.dom.addEventListener(i,(s=>{let o=s.target,n;if(o!=this.dom&&this.dom.contains(o)){while(o.parentNode!=this.dom)o=o.parentNode;let t=o.getBoundingClientRect();n=(t.top+t.bottom)/2}else{n=s.clientY}let r=t.lineBlockAtHeight(n-t.documentTop);if(e.domEventHandlers[i](t,r,s))s.preventDefault()}))}this.markers=Sr(e.markers(t));if(e.initialSpacer){this.spacer=new Ar(t,0,0,[e.initialSpacer(t)]);this.dom.appendChild(this.spacer.dom);this.spacer.dom.style.cssText+="visibility: hidden; pointer-events: none"}}update(t){let e=this.markers;this.markers=Sr(this.config.markers(t.view));if(this.spacer&&this.config.updateSpacer){let e=this.config.updateSpacer(this.spacer.markers[0],t);if(e!=this.spacer.markers[0])this.spacer.update(t.view,0,0,[e])}let i=t.view.viewport;return!s.RangeSet.eq(this.markers,e,i.from,i.to)||(this.config.lineMarkerChange?this.config.lineMarkerChange(t):false)}destroy(){for(let t of this.elements)t.destroy()}}class Ar{constructor(t,e,i,s){this.height=-1;this.above=0;this.markers=[];this.dom=document.createElement("div");this.dom.className="cm-gutterElement";this.update(t,e,i,s)}update(t,e,i,s){if(this.height!=e){this.height=e;this.dom.style.height=e+"px"}if(this.above!=i)this.dom.style.marginTop=(this.above=i)?i+"px":"";if(!Tr(this.markers,s))this.setMarkers(t,s)}setMarkers(t,e){let i="cm-gutterElement",s=this.dom.firstChild;for(let o=0,n=0;;){let r=n,l=o<e.length?e[o++]:null,a=false;if(l){let t=l.elementClass;if(t)i+=" "+t;for(let e=n;e<this.markers.length;e++)if(this.markers[e].compare(l)){r=e;a=true;break}}else{r=this.markers.length}while(n<r){let t=this.markers[n++];if(t.toDOM){t.destroy(s);let e=s.nextSibling;s.remove();s=e}}if(!l)break;if(l.toDOM){if(a)s=s.nextSibling;else this.dom.insertBefore(l.toDOM(t),s)}if(a)n++}this.dom.className=i;this.markers=e}destroy(){this.setMarkers(null,[])}}function Tr(t,e){if(t.length!=e.length)return false;for(let i=0;i<t.length;i++)if(!t[i].compare(e[i]))return false;return true}const Dr=s.Facet.define();const Or=s.Facet.define();const Er=s.Facet.define({combine(t){return(0,s.combineConfig)(t,{formatNumber:String,domEventHandlers:{}},{domEventHandlers(t,e){let i=Object.assign({},t);for(let s in e){let t=i[s],o=e[s];i[s]=t?(e,i,s)=>t(e,i,s)||o(e,i,s):o}return i}})}});class Rr extends ur{constructor(t){super();this.number=t}eq(t){return this.number==t.number}toDOM(){return document.createTextNode(this.number)}}function Br(t,e){return t.state.facet(Er).formatNumber(e,t.state)}const Lr=vr.compute([Er],(t=>({class:"cm-lineNumbers",renderEmptyElements:false,markers(t){return t.state.facet(Dr)},lineMarker(t,e,i){if(i.some((t=>t.toDOM)))return null;return new Rr(Br(t,t.state.doc.lineAt(e.from).number))},widgetMarker:(t,e,i)=>{for(let s of t.state.facet(Or)){let o=s(t,e,i);if(o)return o}return null},lineMarkerChange:t=>t.startState.facet(Er)!=t.state.facet(Er),initialSpacer(t){return new Rr(Br(t,Wr(t.state.doc.lines)))},updateSpacer(t,e){let i=Br(e.view,Wr(e.view.state.doc.lines));return i==t.number?t:new Rr(i)},domEventHandlers:t.facet(Er).domEventHandlers,side:"before"})));function Hr(t={}){return[Er.of(t),yr(),Lr]}function Wr(t){let e=9;while(e<t)e=e*10+9;return e}const Pr=new class extends ur{constructor(){super(...arguments);this.elementClass="cm-activeLineGutter"}};const Nr=pr.compute(["selection"],(t=>{let e=[],i=-1;for(let s of t.selection.ranges){let o=t.doc.lineAt(s.head).from;if(o>i){i=o;e.push(Pr.range(o))}}return s.RangeSet.of(e)}));function Vr(){return Nr}function Fr(t){return oe.define((e=>({decorations:t.createDeco(e),update(e){this.decorations=t.updateDeco(e,this.decorations)}})),{decorations:t=>t.decorations})}const zr=P.mark({class:"cm-highlightTab"});const Ir=P.mark({class:"cm-highlightSpace"});const qr=Fr(new Zo({regexp:/\t| /g,decoration:t=>t[0]=="\t"?zr:Ir,boundary:/\S/}));function Kr(){return qr}const _r=Fr(new Zo({regexp:/\s+$/g,decoration:P.mark({class:"cm-trailingSpace"})}));function Yr(){return _r}const Xr={HeightMap:Ms,HeightOracle:bs,MeasuredHeights:ys,QueryType:Ss,ChangedRange:ve,computeOrder:Ht,moveVisually:Nt,clearHeightChangeFlag:ws,getHeightChangeFlag:()=>vs}},41107:(t,e,i)=>{i.d(e,{A:()=>s});function s(){var t=arguments[0];if(typeof t=="string")t=document.createElement(t);var e=1,i=arguments[1];if(i&&typeof i=="object"&&i.nodeType==null&&!Array.isArray(i)){for(var s in i)if(Object.prototype.hasOwnProperty.call(i,s)){var n=i[s];if(typeof n=="string")t.setAttribute(s,n);else if(n!=null)t[s]=n}e++}for(;e<arguments.length;e++)o(t,arguments[e]);return t}function o(t,e){if(typeof e=="string"){t.appendChild(document.createTextNode(e))}else if(e==null){}else if(e.nodeType!=null){t.appendChild(e)}else if(Array.isArray(e)){for(var i=0;i<e.length;i++)o(t,e[i])}else{throw new RangeError("Unsupported child node: "+e)}}}}]);