From 976c0d950461ab884a9d107659d3ba103d8cb269 Mon Sep 17 00:00:00 2001 From: Hizbu Azka Date: Wed, 21 Oct 2026 14:31:59 +0700 Subject: selfhost cm, add dark theme --- assets/cm/chunk-I3OVNVKL.js | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 assets/cm/chunk-I3OVNVKL.js (limited to 'assets/cm/chunk-I3OVNVKL.js') diff --git a/assets/cm/chunk-I3OVNVKL.js b/assets/cm/chunk-I3OVNVKL.js new file mode 100644 index 0000000..73b884f --- /dev/null +++ b/assets/cm/chunk-I3OVNVKL.js @@ -0,0 +1,7 @@ +import{A as Ts,B as ri,C as ye,a as q,c as ft,d as si,f as Cs,g as wt,i as ni,k as v,l as C,m as pe,n as ge,p as ks,s as U,t as Ms,u as As,v as Ot,w as me,x as be,z as E}from"./chunk-7PWEZHZB.js";var Ds=typeof Symbol>"u"?"__\u037C":Symbol.for("\u037C"),oi=typeof Symbol>"u"?"__styleSet"+Math.floor(Math.random()*1e8):Symbol("styleSet"),Os=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{},st=class{constructor(t,e){this.rules=[];let{finish:i}=e||{};function n(o){return/^@/.test(o)?[o]:o.split(/,\s*/)}function r(o,l,a,h){let c=[],f=/^@(\w+)\b/.exec(o[0]),d=f&&f[1]=="keyframes";if(f&&l==null)return a.push(o[0]+";");for(let u in l){let p=l[u];if(/&/.test(u))r(u.split(/,\s*/).map(g=>o.map(m=>g.replace(/&/,m))).reduce((g,m)=>g.concat(m)),p,a);else if(p&&typeof p=="object"){if(!f)throw new RangeError("The value of a property ("+u+") should be a primitive value.");r(n(u),p,c,d)}else p!=null&&c.push(u.replace(/_.*/,"").replace(/[A-Z]/g,g=>"-"+g.toLowerCase())+": "+p+";")}(c.length||d)&&a.push((i&&!f&&!h?o.map(i):o).join(", ")+" {"+c.join(" ")+"}")}for(let o in t)r(n(o),t[o],this.rules)}getRules(){return this.rules.join(` +`)}static newName(){let t=Os[Ds]||1;return Os[Ds]=t+1,"\u037C"+t.toString(36)}static mount(t,e,i){let n=t[oi],r=i&&i.nonce;n?r&&n.setNonce(r):n=new li(t,r),n.mount(Array.isArray(e)?e:[e],t)}},Rs=new Map,li=class{constructor(t,e){let i=t.ownerDocument||t,n=i.defaultView;if(!t.head&&t.adoptedStyleSheets&&n.CSSStyleSheet){let r=Rs.get(i);if(r)return t[oi]=r;this.sheet=new n.CSSStyleSheet,Rs.set(i,this)}else this.styleTag=i.createElement("style"),e&&this.styleTag.setAttribute("nonce",e);this.modules=[],t[oi]=this}mount(t,e){let i=this.sheet,n=0,r=0,o=!1;for(let l=0;l-1&&(this.modules.splice(h,1),o=!0,r--,h=-1),h==-1){if(this.modules.splice(r++,0,a),o=!0,i)for(let c=0;c",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},Mr=typeof navigator<"u"&&/Mac/.test(navigator.platform),Ar=typeof navigator<"u"&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent);for(H=0;H<10;H++)nt[48+H]=nt[96+H]=String(H);var H;for(H=1;H<=24;H++)nt[H+111]="F"+H;var H;for(H=65;H<=90;H++)nt[H]=String.fromCharCode(H+32),Rt[H]=String.fromCharCode(H);var H;for(we in nt)Rt.hasOwnProperty(we)||(Rt[we]=nt[we]);var we;function Ls(s){var t=Mr&&s.metaKey&&s.shiftKey&&!s.ctrlKey&&!s.altKey||Ar&&s.shiftKey&&s.key&&s.key.length==1||s.key=="Unidentified",e=!t&&s.key||(s.shiftKey?Rt:nt)[s.keyCode]||s.key||"Unidentified";return e=="Esc"&&(e="Escape"),e=="Del"&&(e="Delete"),e=="Left"&&(e="ArrowLeft"),e=="Up"&&(e="ArrowUp"),e=="Right"&&(e="ArrowRight"),e=="Down"&&(e="ArrowDown"),e}function dt(){var s=arguments[0];typeof s=="string"&&(s=document.createElement(s));var t=1,e=arguments[1];if(e&&typeof e=="object"&&e.nodeType==null&&!Array.isArray(e)){for(var i in e)if(Object.prototype.hasOwnProperty.call(e,i)){var n=e[i];typeof n=="string"?s.setAttribute(i,n):n!=null&&(s[i]=n)}t++}for(;t2),y={mac:Ps||/Mac/.test(F.platform),windows:/Win/.test(F.platform),linux:/Linux|X11/.test(F.platform),ie:Je,ie_version:bn?gi.documentMode||6:bi?+bi[1]:mi?+mi[1]:0,gecko:Es,gecko_version:Es?+(/Firefox\/(\d+)/.exec(F.userAgent)||[0,0])[1]:0,chrome:!!ai,chrome_version:ai?+ai[1]:0,ios:Ps,android:/Android\b/.test(F.userAgent),webkit:Hs,webkit_version:Hs?+(/\bAppleWebKit\/(\d+)/.exec(F.userAgent)||[0,0])[1]:0,safari:yi,safari_version:yi?+(/\bVersion\/(\d+(\.\d+)?)/.exec(F.userAgent)||[0,0])[1]:0,tabSize:gi.documentElement.style.tabSize!=null?"tab-size":"-moz-tab-size"};function us(s,t){for(let e in s)e=="class"&&t.class?t.class+=" "+s.class:e=="style"&&t.style?t.style+=";"+s.style:t[e]=s[e];return t}var Pe=Object.create(null);function ps(s,t,e){if(s==t)return!0;s||(s=Pe),t||(t=Pe);let i=Object.keys(s),n=Object.keys(t);if(i.length-0!=n.length-0)return!1;for(let r of i)if(r!=e&&(n.indexOf(r)==-1||s[r]!==t[r]))return!1;return!0}function Tr(s,t){for(let e=s.attributes.length-1;e>=0;e--){let i=s.attributes[e].name;t[i]==null&&s.removeAttribute(i)}for(let e in t){let i=t[e];e=="style"?s.style.cssText=i:s.getAttribute(e)!=i&&s.setAttribute(e,i)}}function Ns(s,t,e){let i=!1;if(t)for(let n in t)e&&n in e||(i=!0,n=="style"?s.style.cssText="":s.removeAttribute(n));if(e)for(let n in e)t&&t[n]==e[n]||(i=!0,n=="style"?s.style.cssText=e[n]:s.setAttribute(n,e[n]));return i}function Dr(s){let t=Object.create(null);for(let e=0;e0?3e8:-4e8:e>0?1e8:-1e8,new Ct(t,e,e,i,t.widget||null,!1)}static replace(t){let e=!!t.block,i,n;if(t.isBlockGap)i=-5e8,n=4e8;else{let{start:r,end:o}=yn(t,e);i=(r?e?-3e8:-1:5e8)-1,n=(o?e?2e8:1:-6e8)+1}return new Ct(t,i,n,e,t.widget||null,!0)}static line(t){return new ne(t)}static set(t,e=!1){return E.of(t,e)}hasHeight(){return this.widget?this.widget.estimatedHeight>-1:!1}};T.none=E.empty;var se=class s extends T{constructor(t){let{start:e,end:i}=yn(t);super(e?-1:5e8,i?1:-6e8,null,t),this.tagName=t.tagName||"span",this.attrs=t.class&&t.attributes?us(t.attributes,{class:t.class}):t.class?{class:t.class}:t.attributes||Pe}eq(t){return this==t||t instanceof s&&this.tagName==t.tagName&&ps(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)}};se.prototype.point=!1;var ne=class s extends T{constructor(t){super(-2e8,-2e8,null,t)}eq(t){return t instanceof s&&this.spec.class==t.spec.class&&ps(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)}};ne.prototype.mapMode=wt.TrackBefore;ne.prototype.point=!0;var Ct=class s extends T{constructor(t,e,i,n,r,o){super(e,i,r,t),this.block=n,this.isReplace=o,this.mapMode=n?e<=0?wt.TrackBefore:wt.TrackAfter:wt.TrackDel}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 s&&Or(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)}};Ct.prototype.point=!0;function yn(s,t=!1){let{inclusiveStart:e,inclusiveEnd:i}=s;return e==null&&(e=s.inclusive),i==null&&(i=s.inclusive),{start:e??t,end:i??t}}function Or(s,t){return s==t||!!(s&&t&&s.compare(t))}function Nt(s,t,e,i=0){let n=e.length-1;n>=0&&e[n]+i>=s?e[n]=Math.max(e[n],t):e.push(s,t)}var Ne=class s extends be{constructor(t,e,i){super(),this.tagName=t,this.attributes=e,this.rank=i}eq(t){return t==this||t instanceof s&&this.tagName==t.tagName&&ps(this.attributes,t.attributes)}static create(t){return new s(t.tagName,t.attributes||Pe,t.rank==null?50:Math.max(0,Math.min(t.rank,100)))}static set(t,e=!1){return E.of(t,e)}};Ne.prototype.startSide=Ne.prototype.endSide=-1;var N=s=>s.nodeType==1,Vt=s=>s.nodeType==3;function re(s){let t;return s.nodeType==11?t=s.getSelection?s:s.ownerDocument:t=s,t.getSelection()}function wi(s,t){return t?s==t||s.contains(t.nodeType!=1?t.parentNode:t):!1}function Xt(s,t){if(!t.anchorNode)return!1;try{return wi(s,t.anchorNode)}catch{return!1}}function $t(s){return Vt(s)?le(s,0,s.nodeValue.length).getClientRects():N(s)?s.getClientRects():[]}function Gt(s,t,e,i){return e?Ws(s,t,e,i,-1)||Ws(s,t,e,i,1):!1}function gt(s){for(var t=0;;t++)if(s=s.previousSibling,!s)return t}function We(s){return N(s)&&/^(DIV|P|LI|UL|OL|BLOCKQUOTE|DD|DT|H\d|SECTION|PRE)$/.test(s.nodeName)}function Ws(s,t,e,i,n){for(;;){if(s==e&&t==i)return!0;if(t==(n<0?0:at(s))){if(s.nodeName=="DIV")return!1;let r=s.parentNode;if(!r||!N(r))return!1;t=gt(s)+(n<0?0:1),s=r}else if(N(s)){if(s=s.childNodes[t+(n<0?-1:0)],N(s)&&(s.nodeName=="IMG"||s.nodeName=="BR"||s.contentEditable=="false"))return!1;t=n<0?at(s):0}else return!1}}function at(s){return Vt(s)?s.nodeValue.length:s.childNodes.length}function oe(s,t){let{left:e,right:i}=s;if(e==i)return s;let n=t?e:i;return{left:n,right:n,top:s.top,bottom:s.bottom}}function Rr(s){let t=s.visualViewport;return t?{left:0,right:t.width,top:0,bottom:t.height}:{left:0,right:s.innerWidth,top:0,bottom:s.innerHeight}}function wn(s,t){let e=t.width/s.offsetWidth,i=t.height/s.offsetHeight;return(e>.995&&e<1.005||!isFinite(e)||Math.abs(t.width-s.offsetWidth)<1)&&(e=1),(i>.995&&i<1.005||!isFinite(i)||Math.abs(t.height-s.offsetHeight)<1)&&(i=1),{scaleX:e,scaleY:i}}function Lr(s,t,e,i,n,r,o,l){let a=s.ownerDocument,h=a.defaultView||window;for(let c=s,f=!1;c&&!f;)if(N(c)){let d,u=c==a.body,p=1,g=1;if(u)d=Rr(h);else{if(/^(fixed|sticky)$/.test(getComputedStyle(c).position)&&(f=!0),c.scrollHeight<=c.clientHeight&&c.scrollWidth<=c.clientWidth){c=c.assignedSlot||c.parentNode;continue}let w=c.getBoundingClientRect();({scaleX:p,scaleY:g}=wn(c,w)),d={left:w.left,right:w.left+c.clientWidth*p,top:w.top,bottom:w.top+c.clientHeight*g}}let m=0,b=0;if(n=="nearest")t.top0&&t.bottom>d.bottom+b&&(b=t.bottom-d.bottom+o)):t.bottom>d.bottom-o&&(b=t.bottom-d.bottom+o,e<0&&t.top-b0&&t.right>d.right+m&&(m=t.right-d.right+r)):t.right>d.right-r&&(m=t.right-d.right+r,e<0&&t.leftd.bottom||t.leftd.right)&&(t={left:Math.max(t.left,d.left),right:Math.min(t.right,d.right),top:Math.max(t.top,d.top),bottom:Math.min(t.bottom,d.bottom)}),c=c.assignedSlot||c.parentNode}else if(c.nodeType==11)c=c.host;else break}function xn(s,t=!0){let e=s.ownerDocument,i=null,n=null;for(let r=s.parentNode;r&&!(r==e.body||(!t||i)&&n);)if(N(r))!n&&r.scrollHeight>r.clientHeight&&(n=r),t&&!i&&r.scrollWidth>r.clientWidth&&(i=r),r=r.assignedSlot||r.parentNode;else if(r.nodeType==11)r=r.host;else break;return{x:i,y:n}}var xi=class{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?at(e):0),i,Math.min(t.focusOffset,i?at(i):0))}set(t,e,i,n){this.anchorNode=t,this.anchorOffset=e,this.focusNode=i,this.focusOffset=n}};function vn(s){let t=[];for(let e=s;e;e=e.nodeType==11?e.host:e.parentNode)N(e)&&t.push({node:e,left:e.scrollLeft,top:e.scrollTop});return t}function Sn(s,t=!0){for(let{node:e,left:i,top:n}of s)t&&e.scrollTop!=n&&(e.scrollTop=n),e.scrollLeft!=i&&(e.scrollLeft=i)}var xt=null;y.safari&&y.safari_version>=26&&(xt=!1);function Cn(s){if(s.setActive)return s.setActive();if(xt)return s.focus(xt);let t=vn(s);s.focus(xt==null?{get preventScroll(){return xt={preventScroll:!0},!0}}:void 0),xt||(xt=!1,Sn(t))}var Vs;function le(s,t,e=t){let i=Vs||(Vs=document.createRange());return i.setEnd(s,e),i.setStart(s,t),i}function Wt(s,t,e,i){let n={key:t,code:t,keyCode:e,which:e,cancelable:!0};i&&({altKey:n.altKey,ctrlKey:n.ctrlKey,shiftKey:n.shiftKey,metaKey:n.metaKey}=i);let r=new KeyboardEvent("keydown",n);r.synthetic=!0,s.dispatchEvent(r);let o=new KeyboardEvent("keyup",n);return o.synthetic=!0,s.dispatchEvent(o),r.defaultPrevented||o.defaultPrevented}function Br(s){for(;s;){if(s&&(s.nodeType==9||s.nodeType==11&&s.host))return s;s=s.assignedSlot||s.parentNode}return null}function Er(s,t){let e=t.focusNode,i=t.focusOffset;if(!e||t.anchorNode!=e||t.anchorOffset!=i)return!1;for(i=Math.min(i,at(e));;)if(i){if(!N(e))return!1;let n=e.childNodes[i-1];n.contentEditable=="false"?i--:(e=n,i=at(e))}else{if(e==s)return!0;i=gt(e),e=e.parentNode}}function kn(s){return s instanceof Window?s.pageYOffset>Math.max(0,s.document.documentElement.scrollHeight-s.innerHeight-4):s.scrollTop>Math.max(1,s.scrollHeight-s.clientHeight-4)}function Mn(s,t){for(let e=s,i=t;;){if(Vt(e)&&i>0)return{node:e,offset:i};if(N(e)&&i>0){if(e.contentEditable=="false")return null;e=e.childNodes[i-1],i=at(e)}else if(e.parentNode&&!We(e))i=gt(e),e=e.parentNode;else return null}}function An(s,t){for(let e=s,i=t;;){if(Vt(e)&&i=e){if(l.level==i)return o;(r<0||(n!=0?n<0?l.frome:t[r].level>l.level))&&(r=o)}}if(r<0)throw new RangeError("Index out of range");return r}};function On(s,t){if(s.length!=t.length)return!1;for(let e=0;e=0;g-=3)if(Q[g+1]==-u){let m=Q[g+2],b=m&2?n:m&4?m&1?r:n:0;b&&(R[f]=R[Q[g]]=b),l=g;break}}else{if(Q.length==189)break;Q[l++]=f,Q[l++]=d,Q[l++]=a}else if((p=R[f])==2||p==1){let g=p==n;a=g?0:1;for(let m=l-3;m>=0;m-=3){let b=Q[m+2];if(b&2)break;if(g)Q[m+2]|=2;else{if(b&4)break;Q[m+2]|=4}}}}}function Fr(s,t,e,i){for(let n=0,r=i;n<=e.length;n++){let o=n?e[n-1].to:s,l=na;)p==m&&(p=e[--g].from,m=g?e[g-1].to:s),R[--p]=u;a=c}else r=h,a++}}}function Si(s,t,e,i,n,r,o){let l=i%2?2:1;if(i%2==n%2)for(let a=t,h=0;aa&&o.push(new Y(a,g.from,u));let m=g.direction==kt!=!(u%2);Ci(s,m?i+1:i,n,g.inner,g.from,g.to,o),a=g.to}p=g.to}else{if(p==e||(c?R[p]!=l:R[p]==l))break;p++}d?Si(s,a,p,i+1,n,d,o):at;){let c=!0,f=!1;if(!h||a>r[h-1].to){let g=R[a-1];g!=l&&(c=!1,f=g==16)}let d=!c&&l==1?[]:null,u=c?i:i+1,p=a;t:for(;;)if(h&&p==r[h-1].to){if(f)break t;let g=r[--h];if(!c)for(let m=g.from,b=h;;){if(m==t)break t;if(b&&r[b-1].to==m)m=r[--b].from;else{if(R[m-1]==l)break t;break}}if(d)d.push(g);else{g.toR.length;)R[R.length]=256;let i=[],n=t==kt?0:1;return Ci(s,n,n,e,0,s.length,i),i}function Ln(s){return[new Y(0,s,0)]}var Bn="";function En(s,t,e,i,n){var r;if(!s.length)return null;let o=i.head-s.from,l;if(i.head==s.from&&i.assoc<0){if(!n)return null;o=t[l=0].side(!1,e)}else if(i.head==s.to&&i.assoc>0){if(n)return null;o=t[l=t.length-1].side(!0,e)}else l=Y.find(t,o,(r=i.bidiLevel)!==null&&r!==void 0?r:-1,i.assoc);let a=t[l],h=a.side(n,e);if(o==h){let d=l+=n?1:-1;if(d<0||d>=t.length)return null;a=t[l=d],o=a.side(!n,e),h=a.side(n,e)}let c=ft(s.text,o,a.forward(n,e));(ca.to)&&(c=h),Bn=s.text.slice(Math.min(o,c),Math.max(o,c));let f=l==(n?t.length-1:0)?null:t[l+(n?1:-1)];if(c==h){if(!f)return n?v.cursor(s.to,1):v.cursor(s.from,-1);if(f.level+(n?0:1)s.some(t=>t)}),zn=C.define({combine:s=>s.some(t=>t)}),Kn=C.define(),Ut=class s{constructor(t,e,i,n,r,o=!1){this.range=t,this.y=e,this.x=i,this.yMargin=n,this.xMargin=r,this.isSnapshot=o}map(t){return t.empty?this:new s(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 s(v.cursor(t.doc.length),this.y,this.x,this.yMargin,this.xMargin,this.isSnapshot)}},xe=U.define({map:(s,t)=>s.map(t)}),qn=U.define();function Z(s,t,e){let i=s.facet(Wn);i.length?i[0](t):window.onerror&&window.onerror(String(t),e,void 0,void 0,t)||(e?console.error(e+":",t):console.error(t))}var rt=C.define({combine:s=>s.length?s[0]:!0}),zr=0,Bt=C.define({combine(s){return s.filter((t,e)=>{for(let i=0;i{let a=[];return o&&a.push(ti.of(h=>{let c=h.plugin(l);return c?o(c):T.none})),r&&a.push(r(l)),a})}static fromClass(t,e){return s.define((i,n)=>new t(i,n),e)}},Qt=class{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.mustUpdate){let e=this.mustUpdate;if(this.mustUpdate=null,this.value.update)try{this.value.update(e)}catch(i){if(Z(e.state,i,"CodeMirror plugin crashed"),this.value.destroy)try{this.value.destroy()}catch{}this.deactivate()}}}else if(this.spec)try{this.value=this.spec.plugin.create(t,this.spec.arg)}catch(e){Z(t.state,e,"CodeMirror plugin crashed"),this.deactivate()}return this}destroy(t){var e;if(!((e=this.value)===null||e===void 0)&&e.destroy)try{this.value.destroy()}catch(i){Z(t.state,i,"CodeMirror plugin crashed")}}deactivate(){this.spec=this.value=null}},_n=C.define(),Ze=C.define(),ti=C.define(),jn=C.define(),ys=C.define(),ce=C.define(),Yn=C.define();function Fs(s,t){let e=s.state.facet(Yn);if(!e.length)return e;let i=e.map(r=>r instanceof Function?r(s):r),n=[];return E.spans(i,t.from,t.to,{point(){},span(r,o,l,a){let h=r-t.from,c=o-t.from,f=n;for(let d=l.length-1;d>=0;d--,a--){let u=l[d].spec.bidiIsolate,p;if(u==null&&(u=Ir(t.text,h,c)),a>0&&f.length&&(p=f[f.length-1]).to==h&&p.direction==u)p.to=c,f=p.inner;else{let g={from:h,to:c,direction:u,inner:[]};f.push(g),f=g.inner}}}}),n}var Xn=C.define();function ws(s){let t=0,e=0,i=0,n=0;for(let r of s.state.facet(Xn)){let o=r(s);o&&(o.left!=null&&(t=Math.max(t,o.left)),o.right!=null&&(e=Math.max(e,o.right)),o.top!=null&&(i=Math.max(i,o.top)),o.bottom!=null&&(n=Math.max(n,o.bottom)))}return{left:t,right:e,top:i,bottom:n}}var _t=C.define(),X=class s{constructor(t,e,i,n){this.fromA=t,this.toA=e,this.fromB=i,this.toB=n}join(t){return new s(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 n=t[e-1];if(!(n.fromA>i.toA)){if(n.toAn.push(new X(r,o,l,a))),this.changedRanges=n}static create(t,e,i){return new s(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&18)>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}},Kr=[],L=class{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 Kr}isWidget(){return!1}get isHidden(){return!1}isComposite(){return!1}isLine(){return!1}isText(){return!1}isBlock(){return!1}get domAttrs(){return null}sync(t){if(this.flags|=2,this.flags&4){this.flags&=-5;let e=this.domAttrs;e&&Tr(this.dom,e)}}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 n of this.children){if(n==t)return i;i+=n.length+n.breakAfter}throw new RangeError("Invalid child in posBefore")}posAfter(t){return this.posBefore(t)+t.length}covers(t){return!0}coordsIn(t,e,i){return null}domPosFor(t,e){let i=gt(this.dom),n=this.length?t>0:e>0;return new J(this.parent.dom,i+(n?1:0),t==0||t==this.length)}markDirty(t){this.flags&=-3,t&&(this.flags|=4),this.parent&&this.parent.flags&2&&this.parent.markDirty(!1)}get overrideDOMText(){return null}get root(){for(let t=this;t;t=t.parent)if(t instanceof It)return t;return null}static get(t){return t.cmTile}},Ft=class extends L{constructor(t){super(t,0),this._children=[]}isComposite(){return!0}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,n,r=t?.node==e?t:null,o=0;for(let l of this.children){if(l.sync(t),o+=l.length+l.breakAfter,n=i?i.nextSibling:e.firstChild,r&&n!=l.dom&&(r.written=!0),l.dom.parentNode==e)for(;n&&n!=l.dom;)n=Is(n);else e.insertBefore(l.dom,n);i=l.dom}for(n=i?i.nextSibling:e.firstChild,r&&n&&(r.written=!0);n;)n=Is(n);this.length=o}};function Is(s){let t=s.nextSibling;return s.parentNode.removeChild(s),t}var It=class extends Ft{constructor(t,e){super(e),this.view=t}owns(t){for(;t;t=t.parent)if(t==this)return!0;return!1}isBlock(){return!0}nearest(t){for(;;){if(!t)return null;let e=L.get(t);if(e&&this.owns(e))return e;t=t.parentNode}}blockTiles(t){for(let e=[],i=this,n=0,r=0;;)if(n==i.children.length){if(!e.length)return;i=i.parent,i.breakAfter&&r++,n=e.pop()}else{let o=i.children[n++];if(o instanceof ot)e.push(n),i=o,n=0;else{let l=r+o.length,a=t(o,r);if(a!==void 0)return a;r=l+o.breakAfter}}}resolveBlock(t,e){let i,n=-1,r,o=-1;if(this.blockTiles((l,a)=>{let h=a+l.length;if(t>=a&&t<=h){if(l.isWidget()&&e>=-1&&e<=1){if(l.flags&32)return!0;l.flags&16&&(i=void 0)}(at||t==a&&(e>1?l.length:l.covers(-1)))&&(!r||!l.isWidget()&&r.isWidget())&&(r=l,o=t-a)}}),!i&&!r)throw new Error("No tile at position "+t);return i&&e<0||!r?{tile:i,offset:n}:{tile:r,offset:o}}},ot=class s extends Ft{constructor(t,e){super(t),this.wrapper=e}isBlock(){return!0}covers(t){return this.children.length?t<0?this.children[0].covers(-1):this.lastChild.covers(1):!1}get domAttrs(){return this.wrapper.attributes}static of(t,e){let i=new s(e||document.createElement(t.tagName),t);return e||(i.flags|=4),i}},zt=class s extends Ft{constructor(t,e){super(t),this.attrs=e}isLine(){return!0}static start(t,e,i){let n=new s(e||document.createElement("div"),t);return(!e||!i)&&(n.flags|=4),n}get domAttrs(){return this.attrs}resolveInline(t,e,i=!1){let n=null,r=-1,o=null,l=-1;function a(c,f){for(let d=0,u=0;d=f&&(p.isComposite()?a(p,f-u):(!o||i&&o.isHidden&&(e>0&&!(o.flags&32)||i&&_r(o,p)))&&(g>f||p.flags&32&&e<=1)?(o=p,l=f-u):(u=-1)&&(n=p,r=f-u)),u=g}}a(this,t);let h=(e<0?n:o)||n||o;return h?{tile:h,offset:h==n?r:l}:null}coordsIn(t,e,i){let n=this.resolveInline(t,e,!0);return n?n.tile.coordsIn(Math.max(0,n.offset),e,i):qr(this)}domIn(t,e){let i=this.resolveInline(t,e);if(i){let{tile:n,offset:r}=i;if(this.dom.contains(n.dom))return n.isText()?new J(n.dom,Math.min(n.dom.nodeValue.length,r)):n.domPosFor(r,n.flags&16?1:n.flags&32?-1:e);let o=i.tile.parent,l=!1;for(let a of o.children){if(l)return new J(a.dom,0);a==i.tile&&(l=!0)}}return new J(this.dom,0)}};function qr(s){let t=s.dom.lastChild;if(!t)return s.dom.getBoundingClientRect();let e=$t(t);return e[e.length-1]||null}function _r(s,t){let e=s.coordsIn(0,1),i=t.coordsIn(0,1);return e&&i&&i.topn&&(t=n);let r=t,o=t,l=0;t==0&&e<0||t==n&&e>=0?y.chrome||y.gecko||(t?(r--,l=1):o=0)?0:a.length-1];return y.safari&&!l&&h.width==0&&(h=Array.prototype.find.call(a,c=>c.width)||h),i==null?h:oe(h,(l?l>0:e<0)==i)}static of(t,e){let i=new s(e||document.createTextNode(t),t);return e||(i.flags|=2),i}},Mt=class s extends L{constructor(t,e,i,n){super(t,e,n),this.widget=i}isWidget(){return!0}get isHidden(){return this.widget.isHidden}covers(t){return this.flags&48?!1:(this.flags&(t<0?64:128))>0}coordsIn(t,e){return this.coordsInWidget(t,e,!1)}coordsInWidget(t,e,i){let n=this.widget.coordsAt(this.dom,t,e);if(n)return n;if(i)return oe(this.dom.getBoundingClientRect(),this.length?t==0:e<=0);{let r=this.dom.getClientRects(),o=null;if(!r.length)return null;let l=this.flags&16?!0:this.flags&32?!1:t>0;for(let a=l?r.length-1:0;o=r[a],!(t>0?a==0:a==r.length-1||o.top0==i)}},Mi=class{constructor(t){this.index=0,this.beforeBreak=!1,this.parents=[],this.tile=t}advance(t,e,i){let{tile:n,index:r,beforeBreak:o,parents:l}=this;for(;t||e>0;)if(n.isComposite())if(o){if(!t)break;i&&i.break(),t--,o=!1}else if(r==n.children.length){if(!t&&!l.length)break;i&&i.leave(n),o=!!n.breakAfter,{tile:n,index:r}=l.pop(),r++}else{let a=n.children[r],h=a.breakAfter;(e>0?a.length<=t:a.length=0;l--){let a=e.marks[l],h=n.lastChild;if(h instanceof z&&h.mark.eq(a.mark))h.dom!=a.dom&&h.setDOM(hi(a.dom)),n=h;else{let{dom:c}=a;this.cache.reused.get(a)&&L.get(a.dom)&&(c=hi(a.dom));let f=z.of(a.mark,c);n.append(f),n=f}this.cache.reused.set(a,2)}let r=L.get(t.text);r&&this.cache.reused.set(r,2);let o=new vt(t.text,t.text.nodeValue);o.flags|=8,this.pos=t.range.toB,n.append(o)}addInlineWidget(t,e,i){let n=this.afterWidget&&t.flags&48&&(this.afterWidget.flags&48)==(t.flags&48);n||this.flushBuffer();let r=this.ensureMarks(e,i);!n&&!(t.flags&16)&&r.append(this.getBuffer(1)),r.append(t),this.pos+=t.length,this.afterWidget=t}addMark(t,e,i){this.flushBuffer(),this.ensureMarks(e,i).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;t||(t=$n);let n=zt.start(t,e||((i=this.cache.find(zt))===null||i===void 0?void 0:i.dom),!!e);this.getBlockPos().append(this.lastBlock=this.curLine=n)}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){this.blockPosCovered()||this.addLineStart(t)}ensureLine(t){this.curLine||this.addLineStart(t)}ensureMarks(t,e){var i;let n=this.curLine;for(let r=t.length-1;r>=0;r--){let o=t[r],l;if(e>0&&(l=n.lastChild)&&l instanceof z&&l.mark.eq(o))n=l,e--;else{let a=z.of(o,(i=this.cache.find(z,h=>h.mark.eq(o)))===null||i===void 0?void 0:i.dom);n.append(a),n=a,e=0}}return n}endLine(){if(this.curLine){this.flushBuffer();let t=this.curLine.lastChild;(!t||!zs(this.curLine,!1)||t.dom.nodeName!="BR"&&t.isWidget()&&!(y.ios&&zs(this.curLine,!0)))&&this.curLine.append(this.cache.findWidget(ci,0,32)||new Mt(ci.toDOM(),0,ci,32)),this.curLine=this.afterWidget=null}}updateBlockWrappers(){this.wrapperPos>this.pos+1e4&&(this.blockWrappers.goto(this.pos),this.wrappers.length=0);for(let t=this.wrappers.length-1;t>=0;t--)this.wrappers[t].to=this.pos){let e=t.rank*102+t.value.rank,i=new Ai(t.from,t.to,t.value,e),n=this.wrappers.length;for(;n>0&&(this.wrappers[n-1].rank-i.rank||this.wrappers[n-1].to-i.to)<0;)n--;this.wrappers.splice(n,0,i)}this.wrapperPos=this.pos}getBlockPos(){var t;this.updateBlockWrappers();let e=this.root;for(let i of this.wrappers){let n=e.lastChild;if(i.fromo.wrapper.eq(i.wrapper)))===null||t===void 0?void 0:t.dom);e.append(r),e=r}}return e}blockPosCovered(){let t=this.lastBlock;return t!=null&&!t.breakAfter&&(!t.isWidget()||(t.flags&160)>0)}getBuffer(t){let e=2|(t<0?16:32),i=this.cache.find(Kt,void 0,1);return i&&(i.flags=e),i||new Kt(e)}flushBuffer(){this.afterWidget&&!(this.afterWidget.flags&32)&&(this.afterWidget.parent.append(this.getBuffer(-1)),this.afterWidget=null)}},Di=class{constructor(t){this.skipCount=0,this.text="",this.textOff=0,this.cursor=t.iter()}skip(t){this.textOff+t<=this.text.length?this.textOff+=t:(this.skipCount+=t-(this.text.length-this.textOff),this.text="",this.textOff=0)}next(t){if(this.textOff==this.text.length){let{value:n,lineBreak:r,done:o}=this.cursor.next(this.skipCount);if(this.skipCount=0,o)throw new Error("Ran out of text content when drawing inline views");this.text=n;let l=this.textOff=Math.min(t,n.length);return r?null:n.slice(0,l)}let e=Math.min(this.text.length,this.textOff+t),i=this.text.slice(this.textOff,e);return this.textOff=e,i}},Fe=[Mt,zt,vt,z,Kt,ot,It];for(let s=0;s[]),this.index=Fe.map(()=>0),this.reused=new Map}add(t){let e=t.constructor.bucket,i=this.buckets[e];i.length<6?i.push(t):i[this.index[e]=(this.index[e]+1)%6]=t}find(t,e,i=2){let n=t.bucket,r=this.buckets[n],o=this.index[n];for(let l=0;l{if(this.cache.add(o),o.isComposite())return!1},enter:o=>this.cache.add(o),leave:()=>{},break:()=>{}}}run(t,e){let i=e&&this.getCompositionContext(e.text);for(let n=0,r=0,o=0;;){let l=on){let h=a-n;this.preserve(h,!o,!l),n=a,r+=h}if(!l)break;e&&l.fromA<=e.range.fromA&&l.toA>=e.range.toA?(this.forward(l.fromA,e.range.fromA,e.range.fromA{if(o.isWidget())if(this.openWidget)this.builder.continueWidget(a-l);else{let h=a>0||l{o.isLine()?this.builder.addLineStart(o.attrs,this.cache.maybeReuse(o)):(this.cache.add(o),o instanceof z&&n.unshift(o.mark)),this.openWidget=!1},leave:o=>{o.isLine()?n.length&&(n.length=r=0):o instanceof z&&(n.shift(),r=Math.min(r,n.length))},break:()=>{this.builder.addBreak(),this.openWidget=!1}}),this.text.skip(t)}emit(t,e){let i=null,n=this.builder,r=-1,o=E.spans(this.decorations,t,e,{point:(l,a,h,c,f,d)=>{if(h instanceof Ct){if(this.disallowBlockEffectsFor[d]){if(h.block)throw new RangeError("Block decorations may not be specified via plugins");if(a>this.view.state.doc.lineAt(l).to)throw new RangeError("Decorations that replace line breaks may not be specified via plugins")}if(r=c.length,f>c.length)n.continueWidget(a-l);else{let u=h.widget||(h.block?mt.block:mt.inline),p=jr(h),g=this.cache.findWidget(u,a-l,p)||Mt.of(u,this.view,a-l,p);h.block?(h.startSide>0&&n.addLineStartIfNotCovered(i),n.addBlockWidget(g)):(n.ensureLine(i),n.addInlineWidget(g,c,f))}i=null}else i=Yr(i,h);a>l&&this.text.skip(a-l)},span:(l,a,h,c)=>{for(let f=l;f-1&&(this.openWidget=o>r),this.openWidget||n.addLineStartIfNotCovered(i),this.openMarks=o}forward(t,e,i=1){e-t<=10?this.old.advance(e-t,i,this.reuseWalker):(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 n=t.parentNode;;n=n.parentNode){let r=L.get(n);if(n==this.view.contentDOM)break;r instanceof z?e.push(r):r?.isLine()?i=r:r instanceof ot||(n.nodeName=="DIV"&&!i?i=new zt(n,$n):i||e.push(z.of(new se({tagName:n.nodeName.toLowerCase(),attributes:Dr(n)}),n)))}return i?{line:i,marks:e}:null}};function zs(s,t){let e=i=>{for(let n of i.children)if((t?n.isText():n.length)||e(n))return!0;return!1};return e(s)}function jr(s){let t=s.isReplace?(s.startSide<0?64:0)|(s.endSide>0?128:0):s.startSide>0?32:16;return s.block&&(t|=256),t}var $n={class:"cm-line"};function Yr(s,t){let e=t.spec.attributes,i=t.spec.class;return!e&&!i||(s||(s={class:"cm-line"}),e&&us(e,s),i&&(s.class+=" "+i)),s}function Xr(s){let t=[];for(let e=s.parents.length;e>1;e--){let i=e==s.parents.length?s.tile:s.parents[e].tile;i instanceof z&&t.push(i.mark)}return t}function hi(s){let t=L.get(s);return t&&t.setDOM(s.cloneNode()),s}var mt=class extends lt{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!0}};mt.inline=new mt("span");mt.block=new mt("div");var ci=new class extends lt{toDOM(){return document.createElement("br")}get isHidden(){return!0}get editable(){return!0}},Ie=class{constructor(t){this.view=t,this.decorations=[],this.blockWrappers=[],this.dynamicDecorationMap=[!1],this.domChanged=null,this.hasComposition=null,this.editContextFormatting=T.none,this.lastCompositionAfterCursor=!1,this.minWidth=0,this.minWidthFrom=0,this.minWidthTo=0,this.impreciseAnchor=null,this.impreciseHead=null,this.forceSelection=!1,this.lastUpdate=Date.now(),this.updateDeco(),this.tile=new It(t,t.contentDOM),this.updateInner([new X(0,0,0,t.state.doc.length)],null)}update(t){var e;let i=t.changedRanges;this.minWidth>0&&i.length&&(i.every(({fromA:c,toA:f})=>fthis.minWidthTo)?(this.minWidthFrom=t.changes.mapPos(this.minWidthFrom,1),this.minWidthTo=t.changes.mapPos(this.minWidthTo,1)):this.minWidth=this.minWidthFrom=this.minWidthTo=0),this.updateEditContextFormatting(t);let n=-1;this.view.inputState.composing>=0&&!this.view.observer.editContext&&(!((e=this.domChanged)===null||e===void 0)&&e.newSel?n=this.domChanged.newSel.head:!eo(t.changes,this.hasComposition)&&!t.selectionSet&&(n=t.state.selection.main.head));let r=n>-1?Gr(this.view,t.changes,n):null;if(this.domChanged=null,this.hasComposition){let{from:c,to:f}=this.hasComposition;i=new X(c,f,t.changes.mapPos(c,-1),t.changes.mapPos(f,1)).addToSet(i.slice())}this.hasComposition=r?{from:r.range.fromB,to:r.range.toB}:null,(y.ie||y.chrome)&&!r&&t&&t.state.doc.lines!=t.startState.doc.lines&&(this.forceSelection=!0);let o=this.decorations,l=this.blockWrappers;this.updateDeco();let a=Jr(o,this.decorations,t.changes);a.length&&(i=X.extendWithRanges(i,a));let h=Zr(l,this.blockWrappers,t.changes);return h.length&&(i=X.extendWithRanges(i,h)),r&&!i.some(c=>c.fromA<=r.range.fromA&&c.toA>=r.range.toA)&&(i=r.range.addToSet(i.slice())),this.tile.flags&2&&i.length==0?!1:(this.updateInner(i,r),t.transactions.length&&(this.lastUpdate=Date.now()),!0)}updateInner(t,e){this.view.viewState.mustMeasureContent=!0;let{observer:i}=this.view;i.ignore(()=>{if(e||t.length){let o=this.tile,l=new Ri(this.view,o,this.blockWrappers,this.decorations,this.dynamicDecorationMap);e&&L.get(e.text)&&l.cache.reused.set(L.get(e.text),2),this.tile=l.run(t,e),Li(o,l.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 r=y.chrome||y.ios?{node:i.selectionRange.focusNode,written:!1}:void 0;this.tile.sync(r),r&&(r.written||i.selectionRange.focusNode!=r.node||!this.tile.dom.contains(r.node))&&(this.forceSelection=!0),this.tile.dom.style.height=""});let n=[];if(this.view.viewport.from||this.view.viewport.to-1)&&Xt(i,this.view.observer.selectionRange)&&!(n&&i.contains(n));if(!(r||e||o))return;let l=this.forceSelection;this.forceSelection=!1;let a=this.view.state.selection.main,h,c;if(a.empty?c=h=this.inlineDOMNearPos(a.anchor,a.assoc||1):(c=this.inlineDOMNearPos(a.head,a.head==a.from?1:-1),h=this.inlineDOMNearPos(a.anchor,a.anchor==a.from?1:-1)),y.gecko&&a.empty&&!this.hasComposition&&$r(h)){let d=document.createTextNode("");this.view.observer.ignore(()=>h.node.insertBefore(d,h.node.childNodes[h.offset]||null)),h=c=new J(d,0),l=!0}let f=this.view.observer.selectionRange;(l||!f.focusNode||(!Gt(h.node,h.offset,f.anchorNode,f.anchorOffset)||!Gt(c.node,c.offset,f.focusNode,f.focusOffset))&&!this.suppressWidgetCursorChange(f,a))&&(this.view.observer.ignore(()=>{y.android&&y.chrome&&i.contains(f.focusNode)&&to(f.focusNode,i)&&(i.blur(),i.focus({preventScroll:!0}));let d=re(this.view.root);if(d)if(a.empty){if(y.gecko){let u=Ur(h.node,h.offset);if(u&&u!=3){let p=(u==1?Mn:An)(h.node,h.offset);p&&(h=new J(p.node,p.offset))}}d.collapse(h.node,h.offset),a.bidiLevel!=null&&d.caretBidiLevel!==void 0&&(d.caretBidiLevel=a.bidiLevel)}else if(d.extend){d.collapse(h.node,h.offset);try{d.extend(c.node,c.offset)}catch{}}else{let u=document.createRange();a.anchor>a.head&&([h,c]=[c,h]),u.setEnd(c.node,c.offset),u.setStart(h.node,h.offset),d.removeAllRanges(),d.addRange(u)}o&&this.view.root.activeElement==i&&(i.blur(),n&&n.focus())}),this.view.observer.setSelectionRange(h,c)),this.impreciseAnchor=h.precise?null:new J(f.anchorNode,f.anchorOffset),this.impreciseHead=c.precise?null:new J(f.focusNode,f.focusOffset)}suppressWidgetCursorChange(t,e){return this.hasComposition&&e.empty&&Gt(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,i=re(t.root),{anchorNode:n,anchorOffset:r}=t.observer.selectionRange;if(!i||!e.empty||!e.assoc||!i.modify)return;let o=this.lineAt(e.head,e.assoc);if(!o)return;let l=o.posAtStart;if(e.head==l||e.head==l+o.length)return;let a=this.coordsAt(e.head,-1),h=this.coordsAt(e.head,1);if(!a||!h||a.bottom>h.top)return;let c=this.domAtPos(e.head+e.assoc,e.assoc);i.collapse(c.node,c.offset),i.modify("move",e.assoc<0?"forward":"backward","lineboundary"),t.observer.readSelectionRange();let f=t.observer.selectionRange;t.docView.posFromDOM(f.anchorNode,f.anchorOffset)!=e.from&&i.collapse(n,r)}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 n=i.posAtStart;if(i.isComposite()){let r;if(t==i.dom)r=i.dom.childNodes[e];else{let o=at(t)==0?0:e==0?-1:1;for(;;){let l=t.parentNode;if(l==i.dom)break;o==0&&l.firstChild!=l.lastChild&&(t==l.firstChild?o=-1:o=1),t=l}o<0?r=t:r=t.nextSibling}if(r==i.dom.firstChild)return n;for(;r&&!L.get(r);)r=r.nextSibling;if(!r)return n+i.length;for(let o=0,l=n;;o++){let a=i.children[o];if(a.dom==r)return l;l+=a.length+a.breakAfter}}else return i.isText()?t==i.dom?n+e:n+(e?i.length:0):n}domAtPos(t,e){let{tile:i,offset:n}=this.tile.resolveBlock(t,e);return i.isWidget()?i.domPosFor(n,e):i.domIn(n,e)}inlineDOMNearPos(t,e){let i,n=-1,r=!1,o,l=-1,a=!1;return this.tile.blockTiles((h,c)=>{if(h.isWidget()){if(h.flags&32&&c>=t)return!0;h.flags&16&&(r=!0)}else{let f=c+h.length;if(c<=t&&(i=h,n=t-c,r=f=t&&!o&&(o=h,l=t-c,a=c>t),c>t&&o)return!0}}),!i&&!o?this.domAtPos(t,e):(r&&o?i=null:a&&i&&(o=null),i&&e<0||!o?i.domIn(n,e):o.domIn(l,e))}coordsAt(t,e,i){let{tile:n,offset:r}=this.tile.resolveBlock(t,e);return n.isWidget()?n.widget instanceof Jt?null:n.coordsInWidget(r,e,!0):n.coordsIn(r,e,i)}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 n(r,o){if(r.isComposite())for(let l of r.children){if(l.length>=o){let a=n(l,o);if(a)return a}if(o-=l.length,o<0)break}else if(r.isText()&&oMath.max(this.view.scrollDOM.clientWidth,this.minWidth)+1,l=-1,a=this.view.textDirection==B.LTR,h=0,c=(f,d,u)=>{for(let p=0;pn);p++){let g=f.children[p],m=d+g.length,b=g.dom.getBoundingClientRect(),{height:w}=b;if(u&&!p&&(h+=b.top-u.top),g instanceof ot)m>i&&c(g,d,b);else if(d>=i&&(h>0&&e.push(-h),e.push(w+h),h=0,o)){let x=g.dom.lastChild,A=x?$t(x):[];if(A.length){let k=A[A.length-1],S=a?k.right-b.left:b.right-k.left;S>l&&(l=S,this.minWidth=r,this.minWidthFrom=d,this.minWidthTo=m)}}u&&p==f.children.length-1&&(h+=u.bottom-b.bottom),d=m+g.breakAfter}};return c(this.tile,0,null),e}textDirectionAt(t){let{tile:e}=this.tile.resolveBlock(t,1);return getComputedStyle(e.dom).direction=="rtl"?B.RTL:B.LTR}measureTextSize(){let t=this.tile.blockTiles(o=>{if(o.isLine()&&o.children.length&&o.length<=20){let l=0,a;for(let h of o.children){if(!h.isText()||/[^ -~]/.test(h.text))return;let c=$t(h.dom);if(c.length!=1)return;l+=c[0].width,a=c[0].height}if(l)return{lineHeight:o.dom.getBoundingClientRect().height,charWidth:l/o.length,textHeight:a}}});if(t)return t;let e=document.createElement("div"),i,n,r;return 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 o=$t(e.firstChild)[0];i=e.getBoundingClientRect().height,n=o&&o.width?o.width/27:7,r=o&&o.height?o.height:i,e.remove()}),{lineHeight:i,charWidth:n,textHeight:r}}computeBlockGapDeco(){let t=[],e=this.view.viewState;for(let i=0,n=0;;n++){let r=n==e.viewports.length?null:e.viewports[n],o=r?r.from-1:this.view.state.doc.length;if(o>i){let l=(e.lineBlockAt(o).bottom-e.lineBlockAt(i).top)/this.view.scaleY;t.push(T.replace({widget:new Jt(l),block:!0,inclusive:!0,isBlockGap:!0}).range(i,o))}if(!r)break;i=r.to+1}return T.set(t)}updateDeco(){let t=1,e=this.view.state.facet(ti).map(r=>(this.dynamicDecorationMap[t++]=typeof r=="function")?r(this.view):r),i=!1,n=this.view.state.facet(ys).map((r,o)=>{let l=typeof r=="function";return l&&(i=!0),l?r(this.view):r});for(n.length&&(this.dynamicDecorationMap[t++]=i,e.push(E.join(n))),this.decorations=[this.editContextFormatting,...e,this.computeBlockGapDeco(),this.view.viewState.lineGapDeco];ttypeof r=="function"?r(this.view):r)}scrollIntoView(t){if(t.isSnapshot){let h=this.view.viewState.lineBlockAt(t.range.head);this.view.scrollDOM.scrollTop=h.top-t.yMargin,this.view.scrollDOM.scrollLeft=t.xMargin;return}for(let h of this.view.state.facet(Kn))try{if(h(this.view,t.range,t))return!0}catch(c){Z(this.view.state,c,"scroll handler")}let{range:e}=t,i=this.coordsAt(e.head,e.assoc||(e.head>e.anchor?-1:1)),n;if(!i)return;!e.empty&&(n=this.coordsAt(e.anchor,e.anchor>e.head?-1:1))&&(i={left:Math.min(i.left,n.left),top:Math.min(i.top,n.top),right:Math.max(i.right,n.right),bottom:Math.max(i.bottom,n.bottom)});let r=ws(this.view),o={left:i.left-r.left,top:i.top-r.top,right:i.right+r.right,bottom:i.bottom+r.bottom},{offsetWidth:l,offsetHeight:a}=this.view.scrollDOM;if(Lr(this.view.scrollDOM,o,e.head1&&(i.top>window.visualViewport.offsetTop+window.visualViewport.height||i.bottomi.isWidget()||i.children.some(e);return e(this.tile.resolveBlock(t,1).tile)}destroy(){Li(this.tile)}};function Li(s,t){let e=t?.get(s);if(e!=1){e==null&&s.destroy();for(let i of s.children)Li(i,t)}}function $r(s){return N(s.node)&&s.node.firstChild&&(s.offset==0||s.node.childNodes[s.offset-1].contentEditable=="false")&&(s.offset==s.node.childNodes.length||s.node.childNodes[s.offset].contentEditable=="false")}function Gn(s,t){let e=s.observer.selectionRange;if(!e.focusNode)return null;let i=Mn(e.focusNode,e.focusOffset),n=An(e.focusNode,e.focusOffset),r=i||n;if(n&&i&&n.node!=i.node){let l=L.get(n.node);if(!l||l.isText()&&l.text!=n.node.nodeValue)r=n;else if(s.docView.lastCompositionAfterCursor){let a=L.get(i.node);!a||a.isText()&&a.text!=i.node.nodeValue||(r=n)}}if(s.docView.lastCompositionAfterCursor=r!=i,!r)return null;let o=t-r.offset;return{from:o,to:o+r.node.nodeValue.length,node:r.node}}function Gr(s,t,e){let i=Gn(s,e);if(!i)return null;let{node:n,from:r,to:o}=i,l=n.nodeValue;if(/[\n\r]/.test(l)||s.state.doc.sliceString(i.from,i.to)!=l)return null;let a=t.invertedDesc;return{range:new X(a.mapPos(r),a.mapPos(o),r,o),text:n}}function Ur(s,t){return N(s)?(t&&s.childNodes[t-1].contentEditable=="false"?1:0)|(t{it.from&&(e=!0)}),e}var Jt=class extends lt{constructor(t){super(),this.height=t}toDOM(){let t=document.createElement("div");return t.className="cm-gap",this.updateDOM(t),t}eq(t){return t.height==this.height}updateDOM(t){return t.style.height=this.height+"px",!0}get editable(){return!0}get estimatedHeight(){return this.height}ignoreEvent(){return!1}};function io(s,t,e=1){let i=s.charCategorizer(t),n=s.doc.lineAt(t),r=t-n.from;if(n.length==0)return v.cursor(t);r==0?e=1:r==n.length&&(e=-1);let o=r,l=r;e<0?o=ft(n.text,r,!1):l=ft(n.text,r);let a=i(n.text.slice(o,l));for(;o>0;){let h=ft(n.text,o,!1);if(i(n.text.slice(h,o))!=a)break;o=h}for(;ls.defaultLineHeight*1.5){let l=s.viewState.heightOracle.textHeight,a=Math.floor((n-e.top-(s.defaultLineHeight-l)*.5)/l);r+=a*s.viewState.heightOracle.lineLength}let o=s.state.sliceDoc(e.from,e.to);return e.from+ye(o,r,s.state.tabSize)}function Ei(s,t,e){let i=s.lineBlockAt(t);if(Array.isArray(i.type)){let n;for(let r of i.type){if(r.from>t)break;if(!(r.tot)return r;(!n||r.type==W.Text&&(n.type!=r.type||(e<0?r.fromt)))&&(n=r)}}return n||i}return i}function no(s,t,e,i){let n=Ei(s,t.head,t.assoc||-1),r=!i||n.type!=W.Text||!(s.lineWrapping||n.widgetLineBreaks)?null:s.coordsAtPos(t.assoc<0&&t.head>n.from?t.head-1:t.head);if(r){let o=s.dom.getBoundingClientRect(),l=s.textDirectionAt(n.from),a=s.posAtCoords({x:e==(l==B.LTR)?o.right-1:o.left+1,y:(r.top+r.bottom)/2});if(a!=null)return v.cursor(a,e?-1:1)}return v.cursor(e?n.to:n.from,e?-1:1)}function Ks(s,t,e,i){let n=s.state.doc.lineAt(t.head),r=s.bidiSpans(n),o=s.textDirectionAt(n.from);for(let l=t,a=null;;){let h=En(n,r,o,l,e),c=Bn;if(!h){if(n.number==(e?s.state.doc.lines:1))return l;c=` +`,n=s.state.doc.line(n.number+(e?1:-1)),r=s.bidiSpans(n),h=e?v.cursor(n.from,-1):v.cursor(n.to,1)}if(a){if(!a(c))return l}else{if(!i)return h;a=i(c)}l=h}}function ro(s,t,e){let i=s.state.charCategorizer(t),n=i(e);return r=>{let o=i(r);return n==As.Space&&(n=o),n==o}}function oo(s,t,e,i){let n=t.head,r=e?1:-1;if(n==(e?s.state.doc.length:0))return v.cursor(n,t.assoc);let o=t.goalColumn,l,a=s.contentDOM.getBoundingClientRect(),h=s.coordsAtPos(n,t.assoc||((t.empty?e:t.head==t.from)?1:-1)),c=s.documentTop;if(h)o==null&&(o=h.left-a.left),l=r<0?h.top:h.bottom;else{let p=s.viewState.lineBlockAt(n);o==null&&(o=Math.min(a.right-a.left,s.defaultCharacterWidth*(n-p.from))),l=(r<0?p.top:p.bottom)+c}let f=a.left+o,d=s.viewState.heightOracle.textHeight>>1,u=i??d;for(let p=0;;p+=d){let g=l+(u+p)*r,m=Hi(s,{x:f,y:g},!1,r);if(e?g>a.bottom:gl:w{if(t>r&&tn(s)),e.from,t.head>e.from?-1:1);return i==e.from?e:v.cursor(i,is.viewState.docHeight)return new j(s.state.doc.length,-1);if(h=s.elementAtHeight(a),i==null)break;if(h.type==W.Text){if(i<0?h.tos.viewport.to)break;let d=s.docView.coordsAt(i<0?h.from:h.to,i>0?-1:1);if(d&&(i<0?d.top<=a+r:d.bottom>=a+r))break}let f=s.viewState.heightOracle.textHeight/2;a=i>0?h.bottom+f:h.top-f}if(s.viewport.from>=h.to||s.viewport.to<=h.from){if(e)return null;if(h.type==W.Text){let f=so(s,n,h,o,l);return new j(f,f==h.from?1:-1)}}if(h.type!=W.Text)return a<(h.top+h.bottom)/2?new j(h.from,1):new j(h.to,-1);let c=s.docView.lineAt(h.from,2);return(!c||c.length!=h.length)&&(c=s.docView.lineAt(h.from,-2)),new Pi(s,o,l,s.textDirectionAt(h.from)).scanTile(c,h.from)}var Pi=class{constructor(t,e,i,n){this.view=t,this.x=e,this.y=i,this.baseDir=n,this.line=null,this.spans=null}bidiSpansAt(t){return(!this.line||this.line.from>t||this.line.to1||i.length&&(i[0].level!=this.baseDir||i[0].to+n.from>1;e:if(o.has(g)){for(let w=1;w=r&&(x-=p),!o.has(x)){g=x;break e}}break t}o.add(g);let m=e(g),b=0;if(m)for(let w=0;w1))if(x.bottomthis.y)(!h||h.top>x.top)&&(h=x),b=-1;else{let A=x.left>this.x?this.x-x.left:x.right(p+p+g)/3)return this.y=a.bottom-1,this.scan(t,e,!0);if(h&&h.top<(p+g+g)/3)return this.y=h.top+1,this.scan(t,e,!0)}let u=(l?this.dirAt(t[c],1):this.baseDir)==B.LTR;return{i:c,after:this.x>(d.left+d.right)/2==u}}scanText(t,e){let i=[];for(let r=0;r{let o=i[r]-e,l=i[r+1]-e;return le(t.dom,o,l).getClientRects()});return n.after?new j(i[n.i+1],-1):new j(i[n.i],1)}scanTile(t,e){if(!t.length)return new j(e,1);if(t.children.length==1){let l=t.children[0];if(l.isText())return this.scanText(l,e);if(l.isComposite())return this.scanTile(l,e)}let i=[e];for(let l=0,a=e;l{let a=t.children[l];return a.flags&48?null:(N(a.dom)?a.dom:le(a.dom,0,a.length)).getClientRects()}),r=t.children[n.i],o=i[n.i];return r.isText()?this.scanText(r,o):r.isComposite()?this.scanTile(r,o):n.after?new j(i[n.i+1],-1):new j(o,1)}},Lt="\uFFFF",Ni=class{constructor(t,e){this.points=t,this.view=e,this.text="",this.lineSeparator=e.state.facet(Ot.lineSeparator)}append(t){this.text+=t}lineBreak(){this.text+=Lt}readRange(t,e){if(!t)return this;let i=t.parentNode;for(let n=t;;){this.findPointBefore(i,n);let r=this.text.length;this.readNode(n);let o=L.get(n),l=n.nextSibling;if(l==e){o?.breakAfter&&!l&&i!=this.view.contentDOM&&this.lineBreak();break}let a=L.get(l);(o&&a?o.breakAfter:(o?o.breakAfter:We(n))||We(l)&&(n.nodeName!="BR"||o?.isWidget())&&this.text.length>r)&&!ao(l,e)&&this.lineBreak(),n=l}return this.findPointBefore(i,e),this}readTextNode(t){let e=t.nodeValue;for(let i of this.points)i.node==t&&(i.pos=this.text.length+Math.min(i.offset,e.length));for(let i=0,n=this.lineSeparator?null:/\r\n?|\n/g;;){let r=-1,o=1,l;if(this.lineSeparator?(r=e.indexOf(this.lineSeparator,i),o=this.lineSeparator.length):(l=n.exec(e))&&(r=l.index,o=l[0].length),this.append(e.slice(i,r<0?e.length:r)),r<0)break;if(this.lineBreak(),o>1)for(let a of this.points)a.node==t&&a.pos>this.text.length&&(a.pos-=o-1);i=r+o}}readNode(t){let e=L.get(t),i=e&&e.overrideDOMText;if(i!=null){this.findPointInside(t,i.length);for(let n=i.iter();!n.next().done;)n.lineBreak?this.lineBreak():this.append(n.value)}else Vt(t)?this.readTextNode(t):t.nodeName=="BR"?t.nextSibling&&this.lineBreak():N(t)&&this.readRange(t.firstChild,null)}findPointBefore(t,e){for(let i of this.points)i.node==t&&t.childNodes[i.offset]==e&&(i.pos=this.text.length)}findPointInside(t,e){for(let i of this.points)(Vt(t)?i.node==t:t.contains(i.node))&&(i.pos=this.text.length+(lo(t,i.node,i.offset)?e:0))}};function lo(s,t,e){for(;;){if(!t||e-1;let{impreciseHead:r,impreciseAnchor:o}=t.docView,l=t.state.selection;if(t.state.readOnly&&e>-1)this.newSel=null;else if(e>-1&&(this.bounds=Qn(t.docView.tile,e,i,0))){let a=r||o?[]:co(t),h=new Ni(a,t);h.readRange(this.bounds.startDOM,this.bounds.endDOM),this.text=h.text,this.newSel=fo(a,this.bounds.from)}else{let a=t.observer.selectionRange,h=r&&r.node==a.focusNode&&r.offset==a.focusOffset||!wi(t.contentDOM,a.focusNode)?l.main.head:t.docView.posFromDOM(a.focusNode,a.focusOffset),c=o&&o.node==a.anchorNode&&o.offset==a.anchorOffset||!wi(t.contentDOM,a.anchorNode)?l.main.anchor:t.docView.posFromDOM(a.anchorNode,a.anchorOffset),f=t.viewport;if((y.ios||y.chrome)&&h!=c&&Math.min(h,c)<=l.main.from&&Math.max(h,c)>=l.main.to&&(f.from>0||f.to-1&&l.ranges.length>1)this.newSel=l.replaceRange(v.range(c,h));else if(t.lineWrapping&&c==h&&!(l.main.empty&&l.main.head==h)&&t.inputState.lastTouchTime>Date.now()-100){let d=t.coordsAtPos(h,-1),u=0;d&&(u=t.inputState.lastTouchY<=d.bottom?-1:1),this.newSel=v.create([v.cursor(h,u)])}else this.newSel=v.single(c,h)}}};function Qn(s,t,e,i){if(s.isComposite()){let n=-1,r=-1,o=-1,l=-1;for(let a=0,h=i,c=i;ae)return Qn(f,t,e,h);if(d>=t&&n==-1&&(n=a,r=h),h>e&&f.dom.parentNode==s.dom){o=a,l=c;break}c=d,h=d+f.breakAfter}return{from:r,to:l<0?i+s.length:l,startDOM:(n?s.children[n-1].dom.nextSibling:null)||s.dom.firstChild,endDOM:o=0?s.children[o].dom:null}}else return s.isText()?{from:i,to:i+s.length,startDOM:s.dom,endDOM:s.dom.nextSibling}:null}function Jn(s,t){let e,{newSel:i}=t,{state:n}=s,r=n.selection.main,o=s.inputState.lastKeyTime>Date.now()-100?s.inputState.lastKeyCode:-1;if(t.bounds){let{from:l,to:a}=t.bounds,h=r.from,c=null;(o===8||y.android&&t.text.length=l&&r.to<=a&&(t.typeOver||f!=t.text)&&f.slice(0,r.from-l)==t.text.slice(0,r.from-l)&&f.slice(r.to-l)==t.text.slice(d=t.text.length-(f.length-(r.to-l)))?e={from:r.from,to:r.to,insert:q.of(t.text.slice(r.from-l,d).split(Lt))}:(u=Zn(f,t.text,h-l,c))&&(y.chrome&&o==13&&u.toB==u.from+2&&t.text.slice(u.from,u.toB)==Lt+Lt&&u.toB--,e={from:l+u.from,to:l+u.toA,insert:q.of(t.text.slice(u.from,u.toB).split(Lt))})}else i&&(!s.hasFocus&&n.facet(rt)||Vi(i,r))&&(i=null);if(!e&&!i)return!1;if((y.mac||y.android)&&e&&e.from==e.to&&e.from==r.head-1&&/^\. ?$/.test(e.insert.toString())&&s.contentDOM.getAttribute("autocorrect")=="off"?(i&&e.insert.length==2&&(i=v.single(i.main.anchor-1,i.main.head-1)),e={from:e.from,to:e.to,insert:q.of([e.insert.toString().replace("."," ")])}):n.doc.lineAt(r.from).toDate.now()-50?e={from:r.from,to:r.to,insert:n.toText(s.inputState.insertingText)}:y.chrome&&e&&e.from==e.to&&e.from==r.head&&e.insert.toString()==` + `&&s.lineWrapping&&(i&&(i=v.single(i.main.anchor-1,i.main.head-1)),e={from:r.from,to:r.to,insert:q.of([" "])}),e)return xs(s,e,i,o);if(i&&!Vi(i,r)){let l=!1,a="select";return s.inputState.lastSelectionTime>Date.now()-50&&(s.inputState.lastSelectionOrigin=="select"&&(l=!0),a=s.inputState.lastSelectionOrigin,a=="select.pointer"&&(i=Un(n.facet(ce).map(h=>h(s)),i))),s.dispatch({selection:i,scrollIntoView:l,userEvent:a}),!0}else return!1}function xs(s,t,e,i=-1){if(y.ios&&s.inputState.flushIOSKey(t))return!0;let n=s.state.selection.main;if(y.android&&(t.to==n.to&&(t.from==n.from||t.from==n.from-1&&s.state.sliceDoc(t.from,n.from)==" ")&&t.insert.length==1&&t.insert.lines==2&&Wt(s.contentDOM,"Enter",13)||(t.from==n.from-1&&t.to==n.to&&t.insert.length==0||i==8&&t.insert.lengthn.head)&&Wt(s.contentDOM,"Backspace",8)||t.from==n.from&&t.to==n.to+1&&t.insert.length==0&&Wt(s.contentDOM,"Delete",46)))return!0;let r=t.insert.toString();s.inputState.composing>=0&&s.inputState.composing++;let o,l=()=>o||(o=ho(s,t,e));return s.state.facet(Vn).some(a=>a(s,t.from,t.to,r,l))||s.dispatch(l()),!0}function ho(s,t,e){let i,n=s.state,r=n.selection.main,o=-1;if(t.from==t.to&&t.fromr.to){let a=t.fromf(s)),h,a);t.from==c&&(o=c)}if(o>-1)i={changes:t,selection:v.cursor(t.from+t.insert.length,-1)};else if(t.from>=r.from&&t.to<=r.to&&t.to-t.from>=(r.to-r.from)/3&&(!e||e.main.empty&&e.main.from==t.from+t.insert.length)&&s.inputState.composing<0){let a=r.fromt.to?n.sliceDoc(t.to,r.to):"";i=n.replaceSelection(s.state.toText(a+t.insert.sliceString(0,void 0,s.state.lineBreak)+h))}else{let a=n.changes(t),h=e&&e.main.to<=a.newLength?e.main:void 0;if(n.selection.ranges.length>1&&(s.inputState.composing>=0||s.inputState.compositionPendingChange)&&t.to<=r.to+10&&t.to>=r.to-10){let c=s.state.sliceDoc(t.from,t.to),f,d=e&&Gn(s,e.main.head);if(d){let p=t.insert.length-(t.to-t.from);f={from:d.from,to:d.to-p}}else f=s.state.doc.lineAt(r.head);let u=r.to-t.to;i=n.changeByRange(p=>{if(p.from==r.from&&p.to==r.to)return{changes:a,range:h||p.map(a)};let g=p.to-u,m=g-c.length;if(s.state.sliceDoc(m,g)!=c||g>=f.from&&m<=f.to)return{range:p};let b=n.changes({from:m,to:g,insert:t.insert}),w=p.to-r.to;return{changes:b,range:h?v.range(Math.max(0,h.anchor+w),Math.max(0,h.head+w)):p.map(b)}})}else i={changes:a,selection:h&&n.selection.replaceRange(h)}}let l="input.type";return(s.composing||s.inputState.compositionPendingChange&&s.inputState.compositionEndedAt>Date.now()-50)&&(s.inputState.compositionPendingChange=!1,l+=".compose",s.inputState.compositionFirstChange&&(l+=".start",s.inputState.compositionFirstChange=!1)),n.update(i,{userEvent:l,scrollIntoView:!0})}function Zn(s,t,e,i){let n=Math.min(s.length,t.length),r=0;for(;r0&&l>0&&s.charCodeAt(o-1)==t.charCodeAt(l-1);)o--,l--;if(i=="end"){let a=Math.max(0,r-Math.min(o,l));e-=o+a-r}if(o=o?r-e:0;r-=a,l=r+(l-o),o=r}else if(l=l?r-e:0;r-=a,o=r+(o-l),l=r}return{from:r,toA:o,toB:l}}function co(s){let t=[];if(s.root.activeElement!=s.contentDOM)return t;let{anchorNode:e,anchorOffset:i,focusNode:n,focusOffset:r}=s.observer.selectionRange;return e&&(t.push(new ze(e,i)),(n!=e||r!=i)&&t.push(new ze(n,r))),t}function fo(s,t){if(s.length==0)return null;let e=s[0].pos,i=s.length==2?s[1].pos:e;return e<0||i<0?null:e==i?v.create([v.cursor(i+t,-1)]):v.single(e+t,i+t)}function Vi(s,t){return t.head==s.main.head&&t.anchor==s.main.anchor}var Fi=class{setSelectionOrigin(t){this.lastSelectionOrigin=t,this.lastSelectionTime=Date.now()}constructor(t){this.view=t,this.lastKeyCode=0,this.lastKeyTime=0,this.touchActive=!1,this.lastTouchTime=0,this.lastTouchX=0,this.lastTouchY=0,this.lastFocusTime=0,this.lastScrollTop=0,this.lastScrollLeft=0,this.lastWheelEvent=0,this.pendingIOSKey=void 0,this.lastIOSMomentumScroll=0,this.tabFocusMode=-1,this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastContextMenu=0,this.scrollHandlers=[],this.handlers=Object.create(null),this.composing=-1,this.compositionFirstChange=null,this.compositionEndedAt=0,this.compositionPendingKey=!1,this.compositionPendingChange=!1,this.insertingText="",this.insertingTextAt=0,this.mouseSelection=null,this.draggedContent=null,this.handleEvent=this.handleEvent.bind(this),this.notifiedFocused=t.hasFocus,y.safari&&t.contentDOM.addEventListener("input",()=>null),y.gecko&&To(t.contentDOM.ownerDocument)}handleEvent(t){!xo(this.view,t)||this.ignoreDuringComposition(t)||t.type=="keydown"&&this.keydown(t)||(this.view.updateState!=0?Promise.resolve().then(()=>this.runHandlers(t.type,t)):this.runHandlers(t.type,t))}runHandlers(t,e){let i=this.handlers[t];if(i){for(let n of i.observers)n(this.view,e);for(let n of i.handlers){if(e.defaultPrevented)break;if(n(this.view,e)){e.preventDefault();break}}}}ensureHandlers(t){let e=po(t),i=this.handlers,n=this.view.contentDOM;for(let r in e)if(r!="scroll"){let o=!e[r].handlers.length,l=i[r];l&&o!=!l.handlers.length&&(n.removeEventListener(r,this.handleEvent),l=null),l||n.addEventListener(r,this.handleEvent,{passive:o})}for(let r in i)r!="scroll"&&!e[r]&&n.removeEventListener(r,this.handleEvent);this.handlers=e}keydown(t){if(this.lastKeyCode=t.keyCode,this.lastKeyTime=Date.now(),t.keyCode==9&&this.tabFocusMode>-1&&(!this.tabFocusMode||Date.now()<=this.tabFocusMode))return!0;if(this.tabFocusMode>0&&t.keyCode!=27&&er.indexOf(t.keyCode)<0&&(this.tabFocusMode=-1),y.android&&y.chrome&&!t.synthetic&&(t.keyCode==13||t.keyCode==8))return this.view.observer.delayAndroidKey(t.key,t.keyCode),!0;if(y.ios&&!t.synthetic&&!t.altKey&&!t.metaKey&&(tr.some(e=>e.keyCode==t.keyCode)&&!t.ctrlKey||go.indexOf(t.key)>-1&&t.ctrlKey)){let e={ctrlKey:t.ctrlKey,altKey:t.altKey,metaKey:t.metaKey,shiftKey:t.shiftKey};e.shiftKey&&y.ios&&!/^(off|none)$/.test(this.view.contentDOM.autocapitalize)&&uo(this.view.win)&&(e.shiftKey=!1);let i=this.pendingIOSKey={key:t.key,keyCode:t.keyCode,mods:e};return setTimeout(()=>{this.pendingIOSKey==i&&this.flushIOSKey()},50),!0}return t.keyCode!=229&&this.view.observer.forceFlush(),!1}flushIOSKey(t){let e=this.pendingIOSKey;return!e||this.view.observer.pendingRecords().length||e.key=="Enter"&&t&&t.from0?!0:y.safari&&!y.ios&&this.compositionPendingKey&&Date.now()-this.compositionEndedAt<100?(this.compositionPendingKey=!1,!0):!1}startMouseSelection(t){this.mouseSelection&&this.mouseSelection.destroy(),this.mouseSelection=t}update(t){this.view.observer.update(t),this.mouseSelection&&this.mouseSelection.update(t),this.draggedContent&&t.docChanged&&(this.draggedContent=this.draggedContent.map(t.changes)),t.transactions.length&&(this.lastKeyCode=this.lastSelectionTime=0)}destroy(){this.mouseSelection&&this.mouseSelection.destroy()}};function uo(s){return s.visualViewport?s.visualViewport.height*s.visualViewport.scale/s.document.documentElement.clientHeight<.85:!1}function qs(s,t){return(e,i)=>{try{return t.call(s,i,e)}catch(n){Z(e.state,n)}}}function po(s){let t=Object.create(null);function e(i){return t[i]||(t[i]={observers:[],handlers:[]})}for(let i of s){let n=i.spec,r=n&&n.plugin.domEventHandlers,o=n&&n.plugin.domEventObservers;if(r)for(let l in r){let a=r[l];a&&e(l).handlers.push(qs(i.value,a))}if(o)for(let l in o){let a=o[l];a&&e(l).observers.push(qs(i.value,a))}}for(let i in G)e(i).handlers.push(G[i]);for(let i in I)e(i).observers.push(I[i]);return t}var tr=[{key:"Backspace",keyCode:8,inputType:"deleteContentBackward"},{key:"Enter",keyCode:13,inputType:"insertParagraph"},{key:"Enter",keyCode:13,inputType:"insertLineBreak"},{key:"Delete",keyCode:46,inputType:"deleteContentForward"}],go="dthko",er=[16,17,18,20,91,92,224,225],ve=6;function Se(s){return Math.max(0,s)*.7+8}function mo(s,t){return Math.max(Math.abs(s.clientX-t.clientX),Math.abs(s.clientY-t.clientY))}var Ii=class{constructor(t,e,i,n){this.view=t,this.startEvent=e,this.style=i,this.mustSelect=n,this.scrollSpeed={x:0,y:0},this.scrolling=-1,this.lastEvent=e,this.scrollParents=xn(t.contentDOM),this.atoms=t.state.facet(ce).map(o=>o(t));let r=t.contentDOM.ownerDocument;r.addEventListener("mousemove",this.move=this.move.bind(this)),r.addEventListener("mouseup",this.up=this.up.bind(this)),this.extend=e.shiftKey,this.multiple=t.state.facet(Ot.allowMultipleSelections)&&bo(t,e),this.dragging=wo(t,e)&&nr(e)==1?null:!1}start(t){this.dragging===!1&&this.select(t)}move(t){if(t.buttons==0)return this.destroy();if(this.dragging||this.dragging==null&&mo(this.startEvent,t)<10)return;this.select(this.lastEvent=t);let e=0,i=0,n=0,r=0,o=this.view.win.innerWidth,l=this.view.win.innerHeight;this.scrollParents.x&&({left:n,right:o}=this.scrollParents.x.getBoundingClientRect()),this.scrollParents.y&&({top:r,bottom:l}=this.scrollParents.y.getBoundingClientRect());let a=ws(this.view);t.clientX-a.left<=n+ve?e=-Se(n-t.clientX):t.clientX+a.right>=o-ve&&(e=Se(t.clientX-o)),t.clientY-a.top<=r+ve?i=-Se(r-t.clientY):t.clientY+a.bottom>=l-ve&&(i=Se(t.clientY-l)),this.setScrollSpeed(e,i)}up(t){this.dragging==null&&this.select(this.lastEvent),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},t||e?this.scrolling<0&&(this.scrolling=setInterval(()=>this.scroll(),50)):this.scrolling>-1&&(clearInterval(this.scrolling),this.scrolling=-1)}scroll(){let{x:t,y:e}=this.scrollSpeed;t&&this.scrollParents.x&&(this.scrollParents.x.scrollLeft+=t,t=0),e&&this.scrollParents.y&&(this.scrollParents.y.scrollTop+=e,e=0),(t||e)&&this.view.win.scrollBy(t,e),this.dragging===!1&&this.select(this.lastEvent)}select(t){let{view:e}=this,i=Un(this.atoms,this.style.get(t,this.extend,this.multiple));(this.mustSelect||!i.eq(e.state.selection,this.dragging===!1))&&this.view.dispatch({selection:i,userEvent:"select.pointer"}),this.mustSelect=!1}update(t){t.transactions.some(e=>e.isUserEvent("input.type"))?this.destroy():this.style.update(t)&&setTimeout(()=>this.select(this.lastEvent),20)}};function bo(s,t){let e=s.state.facet(Hn);return e.length?e[0](t):y.mac?t.metaKey:t.ctrlKey}function yo(s,t){let e=s.state.facet(Pn);return e.length?e[0](t):y.mac?!t.altKey:!t.ctrlKey}function wo(s,t){let{main:e}=s.state.selection;if(e.empty)return!1;let i=re(s.root);if(!i||i.rangeCount==0)return!0;let n=i.getRangeAt(0).getClientRects();for(let r=0;r=t.clientX&&o.top<=t.clientY&&o.bottom>=t.clientY)return!0}return!1}function xo(s,t){if(!t.bubbles)return!0;if(t.defaultPrevented)return!1;for(let e=t.target,i;e!=s.contentDOM;e=e.parentNode)if(!e||e.nodeType==11||(i=L.get(e))&&i.isWidget()&&!i.isHidden&&i.widget.ignoreEvent(t))return!1;return!0}var G=Object.create(null),I=Object.create(null),ir=y.ie&&y.ie_version<15||y.ios&&y.webkit_version<604;function vo(s){let t=s.dom.parentNode;if(!t)return;let e=t.appendChild(document.createElement("textarea"));e.style.cssText="position: fixed; left: -10000px; top: 10px",e.focus(),setTimeout(()=>{s.focus(),e.remove(),sr(s,e.value)},50)}function ei(s,t,e){for(let i of s.facet(t))e=i(e,s);return e}function sr(s,t){t=ei(s.state,ms,t);let{state:e}=s,i,n=1,r=e.toText(t),o=r.lines==e.selection.ranges.length;if(zi!=null&&e.selection.ranges.every(a=>a.empty)&&zi==r.toString()){let a=-1;i=e.changeByRange(h=>{let c=e.doc.lineAt(h.from);if(c.from==a)return{range:h};a=c.from;let f=e.toText((o?r.line(n++).text:t)+e.lineBreak);return{changes:{from:c.from,insert:f},range:v.cursor(h.from+f.length,-1)}})}else o?i=e.changeByRange(a=>{let h=r.line(n++);return{changes:{from:a.from,to:a.to,insert:h.text},range:v.cursor(a.from+h.length,-1)}}):i=e.replaceSelection(r);s.dispatch(i,{userEvent:"input.paste",scrollIntoView:!0})}I.scroll=s=>{let t=s.inputState;t.lastScrollTop=s.scrollDOM.scrollTop,t.lastScrollLeft=s.scrollDOM.scrollLeft,y.ios&&!t.touchActive&&(t.lastIOSMomentumScroll=Date.now())};I.wheel=I.mousewheel=s=>{s.inputState.lastWheelEvent=Date.now()};G.keydown=(s,t)=>(s.inputState.setSelectionOrigin("select"),t.keyCode==27&&s.inputState.tabFocusMode!=0&&(s.inputState.tabFocusMode=Date.now()+2e3),!1);I.touchstart=(s,t)=>{let e=s.inputState,i=t.targetTouches[0];e.touchActive=!0,e.lastTouchTime=Date.now(),i&&(e.lastTouchX=i.clientX,e.lastTouchY=i.clientY),e.setSelectionOrigin("select.pointer")};I.touchmove=s=>{s.inputState.setSelectionOrigin("select.pointer")};I.touchend=(s,t)=>{s.inputState.touchActive=!1};G.mousedown=(s,t)=>{if(s.observer.flush(),s.inputState.lastTouchTime>Date.now()-2e3)return!1;let e=null;for(let i of s.state.facet(Nn))if(e=i(s,t),e)break;if(!e&&t.button==0&&(e=Co(s,t)),e){let i=!s.hasFocus;s.inputState.startMouseSelection(new Ii(s,t,e,i)),i&&s.observer.ignore(()=>{Cn(s.contentDOM);let r=s.root.activeElement;r&&!r.contains(s.contentDOM)&&r.blur()});let n=s.inputState.mouseSelection;if(n)return n.start(t),n.dragging===!1}else s.inputState.setSelectionOrigin("select.pointer");return!1};function _s(s,t,e,i){if(i==1)return v.cursor(t,e);if(i==2)return io(s.state,t,e);{let n=s.docView.lineAt(t,e),r=s.state.doc.lineAt(n?n.posAtEnd:t),o=n?n.posAtStart:r.from,l=n?n.posAtEnd:r.to;return lDate.now()-400&&Math.abs(t.clientX-s.clientX)<2&&Math.abs(t.clientY-s.clientY)<2?(Ys+1)%3:1}function Co(s,t){let e=s.posAndSideAtCoords({x:t.clientX,y:t.clientY},!1),i=nr(t),n=s.state.selection;return{update(r){r.docChanged&&(e.pos=r.changes.mapPos(e.pos),n=n.map(r.changes))},get(r,o,l){let a=s.posAndSideAtCoords({x:r.clientX,y:r.clientY},!1),h,c=_s(s,a.pos,a.assoc,i);if(e.pos!=a.pos&&!o){let f=_s(s,e.pos,e.assoc,i),d=Math.min(f.from,c.from),u=Math.max(f.to,c.to);c=d1&&(h=ko(n,a.pos))?h:l?n.addRange(c):v.create([c])}}}function ko(s,t){for(let e=0;e=t)return v.create(s.ranges.slice(0,e).concat(s.ranges.slice(e+1)),s.mainIndex==e?0:s.mainIndex-(s.mainIndex>e?1:0))}return null}G.dragstart=(s,t)=>{let{selection:{main:e}}=s.state;if(t.target.draggable){let n=s.docView.tile.nearest(t.target);if(n&&n.isWidget()){let r=n.posAtStart,o=r+n.length;(r>=e.to||o<=e.from)&&(e=v.undirectionalRange(r,o))}}let{inputState:i}=s;return i.mouseSelection&&(i.mouseSelection.dragging=!0),i.draggedContent=e,t.dataTransfer&&(t.dataTransfer.setData("Text",ei(s.state,bs,s.state.sliceDoc(e.from,e.to))),t.dataTransfer.effectAllowed="copyMove"),!1};G.dragend=s=>(s.inputState.draggedContent=null,!1);function $s(s,t,e,i){if(e=ei(s.state,ms,e),!e)return;let n=s.posAtCoords({x:t.clientX,y:t.clientY},!1),{draggedContent:r}=s.inputState,o=i&&r&&yo(s,t)?{from:r.from,to:r.to}:null,l={from:n,insert:e},a=s.state.changes(o?[o,l]:l);s.focus(),s.dispatch({changes:a,selection:{anchor:a.mapPos(n,-1),head:a.mapPos(n,1)},userEvent:o?"move.drop":"input.drop"}),s.inputState.draggedContent=null}G.drop=(s,t)=>{if(!t.dataTransfer)return!1;if(s.state.readOnly)return!0;let e=t.dataTransfer.files;if(e&&e.length){let i=Array(e.length),n=0,r=()=>{++n==e.length&&$s(s,t,i.filter(o=>o!=null).join(s.state.lineBreak),!1)};for(let o=0;o{/[\x00-\x08\x0e-\x1f]{2}/.test(l.result)||(i[o]=l.result),r()},l.readAsText(e[o])}return!0}else{let i=t.dataTransfer.getData("Text");if(i)return $s(s,t,i,!0),!0}return!1};G.paste=(s,t)=>{if(s.state.readOnly)return!0;s.observer.flush();let e=ir?null:t.clipboardData;return e?(sr(s,e.getData("text/plain")||e.getData("text/uri-list")),!0):(vo(s),!1)};function Mo(s,t){let e=s.dom.parentNode;if(!e)return;let i=e.appendChild(document.createElement("textarea"));i.style.cssText="position: fixed; left: -10000px; top: 10px",i.value=t,i.focus(),i.selectionEnd=t.length,i.selectionStart=0,setTimeout(()=>{i.remove(),s.focus()},50)}function Ao(s){let t=[],e=[],i=!1;for(let n of s.selection.ranges)n.empty||(t.push(s.sliceDoc(n.from,n.to)),e.push(n));if(!t.length){let n=-1;for(let{from:r}of s.selection.ranges){let o=s.doc.lineAt(r);o.number>n&&(t.push(o.text),e.push({from:o.from,to:Math.min(s.doc.length,o.to+1)})),n=o.number}i=!0}return{text:ei(s,bs,t.join(s.lineBreak)),ranges:e,linewise:i}}var zi=null;G.copy=G.cut=(s,t)=>{if(!Xt(s.contentDOM,s.observer.selectionRange))return!1;let{text:e,ranges:i,linewise:n}=Ao(s.state);if(!e&&!n)return!1;zi=n?e:null,t.type=="cut"&&!s.state.readOnly&&s.dispatch({changes:i,scrollIntoView:!0,userEvent:"delete.cut"});let r=ir?null:t.clipboardData;return r?(r.clearData(),r.setData("text/plain",e),!0):(Mo(s,e),!1)};var rr=ks.define();function or(s,t){let e=[];for(let i of s.facet(Fn)){let n=i(s,t);n&&e.push(n)}return e.length?s.update({effects:e,annotations:rr.of(!0)}):null}function lr(s){setTimeout(()=>{let t=s.hasFocus;if(t!=s.inputState.notifiedFocused){let e=or(s.state,t);e?s.dispatch(e):s.update([])}},10)}I.focus=s=>{s.inputState.lastFocusTime=Date.now(),!s.scrollDOM.scrollTop&&(s.inputState.lastScrollTop||s.inputState.lastScrollLeft)&&(s.scrollDOM.scrollTop=s.inputState.lastScrollTop,s.scrollDOM.scrollLeft=s.inputState.lastScrollLeft),lr(s)};I.blur=s=>{s.observer.clearSelectionRange(),lr(s)};I.compositionstart=I.compositionupdate=(s,t)=>{if(!s.observer.editContext&&(s.inputState.compositionFirstChange==null&&(s.inputState.compositionFirstChange=!0),s.inputState.composing<0)){let{main:e}=s.state.selection;!e.empty&&s.lineBlockAt(e.from).from!=s.lineBlockAt(e.to).from&&!s.state.readOnly&&s.dispatch({changes:s.state.selection.ranges.filter(i=>!i.empty).map(i=>({from:i.from,to:i.to})),userEvent:"input"}),s.inputState.composing=0}};I.compositionend=s=>{s.observer.editContext||(s.inputState.composing=-1,s.inputState.compositionEndedAt=Date.now(),s.inputState.compositionPendingKey=!0,s.inputState.compositionPendingChange=s.observer.pendingRecords().length>0,s.inputState.compositionFirstChange=null,y.chrome&&y.android?s.observer.flushSoon():s.inputState.compositionPendingChange?Promise.resolve().then(()=>s.observer.flush()):setTimeout(()=>{s.inputState.composing<0&&s.docView.hasComposition&&s.update([])},50))};I.contextmenu=s=>{s.inputState.lastContextMenu=Date.now()};G.beforeinput=(s,t)=>{var e,i;if((t.inputType=="insertText"||t.inputType=="insertCompositionText")&&(s.inputState.insertingText=t.data,s.inputState.insertingTextAt=Date.now()),t.inputType=="insertReplacementText"&&s.observer.editContext){let r=(e=t.dataTransfer)===null||e===void 0?void 0:e.getData("text/plain"),o=t.getTargetRanges();if(r&&o.length){let l=o[0],a=s.posAtDOM(l.startContainer,l.startOffset),h=s.posAtDOM(l.endContainer,l.endOffset);return xs(s,{from:a,to:h,insert:s.state.toText(r)},null),!0}}let n;if(y.chrome&&y.android&&(n=tr.find(r=>r.inputType==t.inputType))&&(s.observer.delayAndroidKey(n.key,n.keyCode),n.key=="Backspace"||n.key=="Delete")){let r=((i=window.visualViewport)===null||i===void 0?void 0:i.height)||0;setTimeout(()=>{var o;(((o=window.visualViewport)===null||o===void 0?void 0:o.height)||0)>r+10&&s.hasFocus&&(s.contentDOM.blur(),s.focus())},100)}return y.ios&&t.inputType=="deleteContentForward"&&s.observer.flushSoon(),y.safari&&t.inputType=="insertText"&&s.inputState.composing>=0&&setTimeout(()=>I.compositionend(s,t),20),!1};var Gs=new Set;function To(s){Gs.has(s)||(Gs.add(s),s.addEventListener("copy",()=>{}),s.addEventListener("cut",()=>{}))}var Us=["pre-wrap","normal","pre-line","break-spaces"],At=!1;function Ki(){At=!1}var Ke=class{constructor(t){this.lineWrapping=t,this.doc=q.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;return this.lineWrapping&&(i+=Math.max(0,Math.ceil((e-t-i*this.lineLength*.5)/this.lineLength))),this.lineHeight*i}heightForLine(t){return this.lineWrapping?(1+Math.max(0,Math.ceil((t-this.lineLength)/Math.max(1,this.lineLength-5))))*this.lineHeight:this.lineHeight}setDoc(t){return this.doc=t,this}mustRefreshForWrapping(t){return Us.indexOf(t)>-1!=this.lineWrapping}mustRefreshForHeights(t){let e=!1;for(let i=0;i-1,a=Math.abs(e-this.lineHeight)>.3||this.lineWrapping!=l;if(this.lineWrapping=l,this.lineHeight=e,this.charWidth=i,this.textHeight=n,this.lineLength=r,a){this.heightSamples={};for(let h=0;h0}set outdated(t){this.flags=(t?2:0)|this.flags&-3}setHeight(t){this.height!=t&&(Math.abs(this.height-t)>Oe&&(At=!0),this.height=t)}replace(t,e,i){return s.of(i)}decomposeLeft(t,e){e.push(this)}decomposeRight(t,e){e.push(this)}applyChanges(t,e,i,n){let r=this,o=i.doc;for(let l=n.length-1;l>=0;l--){let{fromA:a,toA:h,fromB:c,toB:f}=n[l],d=r.lineAt(a,O.ByPosNoHeight,i.setDoc(e),0,0),u=d.to>=h?d:r.lineAt(h,O.ByPosNoHeight,i,0,0);for(f+=u.to-h,h=u.to;l>0&&d.from<=n[l-1].toA;)a=n[l-1].fromA,c=n[l-1].fromB,l--,ar*2){let l=t[e-1];l.break?t.splice(--e,1,l.left,null,l.right):t.splice(--e,1,l.left,l.right),i+=1+l.break,n-=l.size}else if(r>n*2){let l=t[i];l.break?t.splice(i,1,l.left,null,l.right):t.splice(i,1,l.left,l.right),i+=2+l.break,r-=l.size}else break;else if(n=r&&o(this.lineAt(0,O.ByPos,i,n,r))}setMeasuredHeight(t){let e=t.heights[t.index++];e<0?(this.spaceAbove=-e,e=t.heights[t.index++]):this.spaceAbove=0,this.setHeight(e)}updateHeight(t,e=0,i=!1,n){return n&&n.from<=e&&n.more&&this.setMeasuredHeight(n),this.outdated=!1,this}toString(){return`block(${this.length})`}},_=class s extends je{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 $(e,this.length,t+this.spaceAbove,this.height-this.spaceAbove,this.breaks)}replace(t,e,i){let n=i[0];return i.length==1&&(n instanceof s||n instanceof pt&&n.flags&4)&&Math.abs(this.length-n.length)<10?(n instanceof pt?n=new s(n.length,this.height,this.spaceAbove):n.height=this.height,this.outdated||(n.outdated=!1),n):K.of(i)}updateHeight(t,e=0,i=!1,n){return n&&n.from<=e&&n.more?this.setMeasuredHeight(n):(i||this.outdated)&&(this.spaceAbove=0,this.setHeight(Math.max(this.widgetHeight,t.heightForLine(this.length-this.collapsed))+this.breaks*t.lineHeight)),this.outdated=!1,this}toString(){return`line(${this.length}${this.collapsed?-this.collapsed:""}${this.widgetHeight?":"+this.widgetHeight:""})`}},pt=class s extends K{constructor(t){super(t,0)}heightMetrics(t,e){let i=t.doc.lineAt(e).number,n=t.doc.lineAt(e+this.length).number,r=n-i+1,o,l=0;if(t.lineWrapping){let a=Math.min(this.height,t.lineHeight*r);o=a/r,this.length>r+1&&(l=(this.height-a)/(this.length-r-1))}else o=this.height/r;return{firstLine:i,lastLine:n,perLine:o,perChar:l}}blockAt(t,e,i,n){let{firstLine:r,lastLine:o,perLine:l,perChar:a}=this.heightMetrics(e,n);if(e.lineWrapping){let h=n+(t0){let r=i[i.length-1];r instanceof s?i[i.length-1]=new s(r.length+n):i.push(null,new s(n-1))}if(t>0){let r=i[0];r instanceof s?i[0]=new s(t+r.length):i.unshift(new s(t-1),null)}return K.of(i)}decomposeLeft(t,e){e.push(new s(t-1),null)}decomposeRight(t,e){e.push(null,new s(this.length-t-1))}updateHeight(t,e=0,i=!1,n){let r=e+this.length;if(n&&n.from<=e+this.length&&n.more){let o=[],l=Math.max(e,n.from),a=-1;for(n.from>e&&o.push(new s(n.from-e-1).updateHeight(t,e));l<=r&&n.more;){let c=t.doc.lineAt(l).length;o.length&&o.push(null);let f=n.heights[n.index++],d=0;f<0&&(d=-f,f=n.heights[n.index++]),a==-1?a=f:Math.abs(f-a)>=Oe&&(a=-2);let u=new _(c,f,d);u.outdated=!1,o.push(u),l+=c+1}l<=r&&o.push(null,new s(r-l).updateHeight(t,l));let h=K.of(o);return(a<0||Math.abs(h.height-this.height)>=Oe||Math.abs(a-this.heightMetrics(t,e).perLine)>=Oe)&&(At=!0),_e(this,h)}else(i||this.outdated)&&(this.setHeight(t.heightForGap(e,e+this.length)),this.outdated=!1);return this}toString(){return`gap(${this.length})`}},qi=class extends K{constructor(t,e,i){super(t.length+(e?1:0)+i.length,t.height+i.height,(e?1:0)|(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,n){let r=i+this.left.height;return tl))return h;let c=e==O.ByPosNoHeight?O.ByPosNoHeight:O.ByPos;return a?h.join(this.right.lineAt(l,c,i,o,l)):this.left.lineAt(l,c,i,n,r).join(h)}forEachLine(t,e,i,n,r,o){let l=n+this.left.height,a=r+this.left.length+this.break;if(this.break)t=a&&this.right.forEachLine(t,e,i,l,a,o);else{let h=this.lineAt(a,O.ByPos,i,n,r);t=t&&h.from<=e&&o(h),e>h.to&&this.right.forEachLine(Math.max(t,h.to+1),e,i,l,a,o)}}replace(t,e,i){let n=this.left.length+this.break;if(ethis.left.length)return this.balanced(this.left,this.right.replace(t-n,e-n,i));let r=[];t>0&&this.decomposeLeft(t,r);let o=r.length;for(let l of i)r.push(l);if(t>0&&Qs(r,o-1),e=i&&e.push(null)),t>i&&this.right.decomposeLeft(t-i,e)}decomposeRight(t,e){let i=this.left.length,n=i+this.break;if(t>=n)return this.right.decomposeRight(t-n,e);t2*e.size||e.size>2*t.size?K.of(this.break?[t,null,e]:[t,e]):(this.left=_e(this.left,t),this.right=_e(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,this)}updateHeight(t,e=0,i=!1,n){let{left:r,right:o}=this,l=e+r.length+this.break,a=null;return n&&n.from<=e+r.length&&n.more?a=r=r.updateHeight(t,e,i,n):r.updateHeight(t,e,i),n&&n.from<=l+o.length&&n.more?a=o=o.updateHeight(t,l,i,n):o.updateHeight(t,l,i),a?this.balanced(r,o):(this.height=this.left.height+this.right.height,this.outdated=!1,this)}toString(){return this.left+(this.break?" ":"-")+this.right}};function Qs(s,t){let e,i;s[t]==null&&(e=s[t-1])instanceof pt&&(i=s[t+1])instanceof pt&&s.splice(t-1,3,new pt(e.length+1+i.length))}var Oo=5,_i=class s{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 i=Math.min(e,this.lineEnd),n=this.nodes[this.nodes.length-1];n instanceof _?n.length+=i-this.pos:(i>this.pos||!this.isCovered)&&this.nodes.push(new _(i-this.pos,-1,0)),this.writtenTo=i,e>i&&(this.nodes.push(null),this.writtenTo++,this.lineStart=-1)}this.pos=e}point(t,e,i){if(t=Oo)&&this.addLineDeco(n,r,o)}else e>t&&this.span(t,e);this.lineEnd>-1&&this.lineEnd-1)return;let{from:t,to:e}=this.oracle.doc.lineAt(this.pos);this.lineStart=t,this.lineEnd=e,this.writtenTot&&this.nodes.push(new _(this.pos-t,-1,0)),this.writtenTo=this.pos}blankContent(t,e){let i=new pt(e-t);return this.oracle.doc.lineAt(t).to==e&&(i.flags|=4),i}ensureLine(){this.enterLine();let t=this.nodes.length?this.nodes[this.nodes.length-1]:null;if(t instanceof _)return t;let e=new _(0,-1,0);return this.nodes.push(e),e}addBlock(t){this.enterLine();let e=t.deco;e&&e.startSide>0&&!this.isCovered&&this.ensureLine(),this.nodes.push(t),this.writtenTo=this.pos=this.pos+t.length,e&&e.endSide>0&&(this.covering=t)}addLineDeco(t,e,i){let n=this.ensureLine();n.length+=i,n.collapsed+=i,n.widgetHeight=Math.max(n.widgetHeight,t),n.breaks+=e,this.writtenTo=this.pos=this.pos+i}finish(t){let e=this.nodes.length==0?null:this.nodes[this.nodes.length-1];this.lineStart>-1&&!(e instanceof _)&&!this.isCovered?this.nodes.push(new _(0,-1,0)):(this.writtenToh.clientHeight||h.scrollWidth>h.clientWidth)&&c.overflow!="visible"){let f=h.getBoundingClientRect();r=Math.max(r,f.left),o=Math.min(o,f.right),l=Math.max(l,f.top),a=Math.min(h==s.parentNode?n.innerHeight:a,f.bottom)}h=c.position=="absolute"||c.position=="fixed"?h.offsetParent:h.parentNode}else if(h.nodeType==11)h=h.host;else break;return{left:r-e.left,right:Math.max(r,o)-e.left,top:l-(e.top+t),bottom:Math.max(l,a)-(e.top+t)}}function Bo(s){let t=s.getBoundingClientRect(),e=s.ownerDocument.defaultView||window;return t.left0&&t.top0}function Eo(s,t){let e=s.getBoundingClientRect();return{left:0,right:e.right-e.left,top:t,bottom:e.bottom-(e.top+t)}}var te=class{constructor(t,e,i,n){this.from=t,this.to=e,this.size=i,this.displaySize=n}static same(t,e){if(t.length!=e.length)return!1;for(let i=0;itypeof n!="function"&&n.class=="cm-lineWrapping");this.heightOracle=new Ke(i),this.stateDeco=Zs(e),this.heightMap=K.empty().applyChanges(this.stateDeco,q.empty,this.heightOracle.setDoc(e.doc),[new X(0,0,0,e.doc.length)]);for(let n=0;n<2&&(this.viewport=this.getViewport(0,null),!!this.updateForViewport());n++);this.updateViewportLines(),this.lineGaps=this.ensureLineGaps([]),this.lineGapDeco=T.set(this.lineGaps.map(n=>n.draw(this,!1))),this.scrollParent=t.scrollDOM,this.computeVisibleRanges()}updateForViewport(){let t=[this.viewport],{main:e}=this.state.selection;for(let i=0;i<=1;i++){let n=i?e.head:e.anchor;if(!t.some(({from:r,to:o})=>n>=r&&n<=o)){let{from:r,to:o}=this.lineBlockAt(n);t.push(new Et(r,o))}}return this.viewports=t.sort((i,n)=>i.from-n.from),this.updateScaler()}updateScaler(){let t=this.scaler;return this.scaler=this.heightMap.height<=7e6?Js:new Xi(this.heightOracle,this.heightMap,this.viewports),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(jt(t,this.scaler))})}update(t,e=null){this.state=t.state;let i=this.stateDeco;this.stateDeco=Zs(this.state);let n=t.changedRanges,r=X.extendWithRanges(n,Ro(i,this.stateDeco,t?t.changes:ni.empty(this.state.doc.length))),o=this.heightMap.height,l=this.scrolledToBottom?null:this.scrollAnchorAt(this.scrollOffset);Ki(),this.heightMap=this.heightMap.applyChanges(this.stateDeco,t.startState.doc,this.heightOracle.setDoc(this.state.doc),r),(this.heightMap.height!=o||At)&&(t.flags|=2),l?(this.scrollAnchorPos=t.changes.mapPos(l.from,-1),this.scrollAnchorHeight=l.top):(this.scrollAnchorPos=-1,this.scrollAnchorHeight=o);let a=r.length?this.mapViewport(this.viewport,t.changes):this.viewport;(e&&(e.range.heada.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(),(h||!t.changes.empty||t.flags&2)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(this.mapLineGaps(this.lineGaps,t.changes))),t.flags|=this.computeVisibleRanges(t.changes),e&&(this.scrollTarget=e),!this.mustEnforceCursorAssoc&&(t.selectionSet||t.focusChanged)&&t.view.lineWrapping&&t.state.selection.main.empty&&t.state.selection.main.assoc&&!t.state.facet(zn)&&(this.mustEnforceCursorAssoc=!0)}measure(){let{view:t}=this,e=t.contentDOM,i=window.getComputedStyle(e),n=this.heightOracle,r=i.whiteSpace;this.defaultTextDirection=i.direction=="rtl"?B.RTL:B.LTR;let o=this.heightOracle.mustRefreshForWrapping(r)||this.mustMeasureContent==="refresh",l=e.getBoundingClientRect(),a=o||this.mustMeasureContent||this.contentDOMHeight!=l.height;this.contentDOMHeight=l.height,this.mustMeasureContent=!1;let h=0,c=0;if(l.width&&l.height){let{scaleX:k,scaleY:S}=wn(e,l);(k>.005&&Math.abs(this.scaleX-k)>.005||S>.005&&Math.abs(this.scaleY-S)>.005)&&(this.scaleX=k,this.scaleY=S,h|=16,o=a=!0)}let f=(parseInt(i.paddingTop)||0)*this.scaleY,d=(parseInt(i.paddingBottom)||0)*this.scaleY;(this.paddingTop!=f||this.paddingBottom!=d)&&(this.paddingTop=f,this.paddingBottom=d,h|=18),this.editorWidth!=t.scrollDOM.clientWidth&&(n.lineWrapping&&(a=!0),this.editorWidth=t.scrollDOM.clientWidth,h|=16);let u=xn(this.view.contentDOM,!1).y;u!=this.scrollParent&&(this.scrollParent=u,this.scrollAnchorHeight=-1,this.scrollOffset=0);let p=this.getScrollOffset();this.scrollOffset!=p&&(this.scrollAnchorHeight=-1,this.scrollOffset=p),this.scrolledToBottom=kn(this.scrollParent||t.win);let g=(this.printing?Eo:Lo)(e,this.paddingTop),m=g.top-this.pixelViewport.top,b=g.bottom-this.pixelViewport.bottom;this.pixelViewport=g;let w=this.pixelViewport.bottom>this.pixelViewport.top&&this.pixelViewport.right>this.pixelViewport.left;if(w!=this.inView&&(this.inView=w,w&&(a=!0)),!this.inView&&!this.scrollTarget&&!Bo(t.dom))return 0;let x=l.width;if((this.contentDOMWidth!=x||this.editorHeight!=t.scrollDOM.clientHeight)&&(this.contentDOMWidth=l.width,this.editorHeight=t.scrollDOM.clientHeight,h|=16),a){let k=t.docView.measureVisibleLineHeights(this.viewport);if(n.mustRefreshForHeights(k)&&(o=!0),o||n.lineWrapping&&Math.abs(x-this.contentDOMWidth)>n.charWidth){let{lineHeight:S,charWidth:D,textHeight:P}=t.docView.measureTextSize();o=S>0&&n.refresh(r,S,D,P,Math.max(5,x/D),k),o&&(t.docView.minWidth=0,h|=16)}m>0&&b>0?c=Math.max(m,b):m<0&&b<0&&(c=Math.min(m,b)),Ki();for(let S of this.viewports){let D=S.from==this.viewport.from?k:t.docView.measureVisibleLineHeights(S);this.heightMap=(o?K.empty().applyChanges(this.stateDeco,q.empty,this.heightOracle,[new X(0,0,0,t.state.doc.length)]):this.heightMap).updateHeight(n,0,o,new qe(S.from,D))}At&&(h|=2)}let A=!this.viewportIsAppropriate(this.viewport,c)||this.scrollTarget&&(this.scrollTarget.range.headthis.viewport.to);return A&&(h&2&&(h|=this.updateScaler()),this.viewport=this.getViewport(c,this.scrollTarget),h|=this.updateForViewport()),(h&2||A)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(o?[]:this.lineGaps,t)),h|=this.computeVisibleRanges(),this.mustEnforceCursorAssoc&&(this.mustEnforceCursorAssoc=!1,t.docView.enforceCursorAssoc()),h}get visibleTop(){return this.scaler.fromDOM(this.pixelViewport.top)}get visibleBottom(){return this.scaler.fromDOM(this.pixelViewport.bottom)}getViewport(t,e){let i=.5-Math.max(-.5,Math.min(.5,t/1e3/2)),n=this.heightMap,r=this.heightOracle,{visibleTop:o,visibleBottom:l}=this,a=new Et(n.lineAt(o-i*1e3,O.ByHeight,r,0,0).from,n.lineAt(l+(1-i)*1e3,O.ByHeight,r,0,0).to);if(e){let{head:h}=e.range;if(ha.to){let c=Math.min(this.editorHeight,this.pixelViewport.bottom-this.pixelViewport.top),f=n.lineAt(h,O.ByPos,r,0,0),d;e.y=="center"?d=(f.top+f.bottom)/2-c/2:e.y=="start"||e.y=="nearest"&&h=l+Math.max(10,Math.min(i,250)))&&n>o-2*1e3&&r>1,o=n<<1;if(this.defaultTextDirection!=B.LTR&&!i)return[];let l=[],a=(c,f,d,u)=>{if(f-cc&&bb.from>=d.from&&b.to<=d.to&&Math.abs(b.from-c)b.fromw));if(!m){if(fx.from<=f&&x.to>=f)){let x=e.moveToLineBoundary(v.cursor(f),!1,!0).head;x>c&&(f=x)}let b=this.gapSize(d,c,f,u),w=i||b<2e6?b:2e6;m=new te(c,f,b,w)}l.push(m)},h=c=>{if(c.length2e6)for(let S of t)S.from>=c.from&&S.fromc.from&&a(c.from,u,c,f),pe.draw(this,this.heightOracle.lineWrapping))))}computeVisibleRanges(t){let e=this.stateDeco;this.lineGaps.length&&(e=e.concat(this.lineGapDeco));let i=[];E.spans(e,this.viewport.from,this.viewport.to,{span(r,o){i.push({from:r,to:o})},point(){}},20);let n=0;if(i.length!=this.visibleRanges.length)n=12;else for(let r=0;r=this.viewport.from&&t<=this.viewport.to&&this.viewportLines.find(e=>e.from<=t&&e.to>=t)||jt(this.heightMap.lineAt(t,O.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)||jt(this.heightMap.lineAt(this.scaler.fromDOM(t),O.ByHeight,this.heightOracle,0,0),this.scaler)}getScrollOffset(){return this.scrollParent==this.view.scrollDOM?this.scrollParent.scrollTop*this.scaleY:(this.scrollParent?this.scrollParent.getBoundingClientRect().top:0)-this.view.contentDOM.getBoundingClientRect().top}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 jt(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}},Et=class{constructor(t,e){this.from=t,this.to=e}};function Ho(s,t,e){let i=[],n=s,r=0;return E.spans(e,s,t,{span(){},point(o,l){o>n&&(i.push({from:n,to:o}),r+=o-n),n=l}},20),n=1)return t[t.length-1].to;let i=Math.floor(s*e);for(let n=0;;n++){let{from:r,to:o}=t[n],l=o-r;if(i<=l)return r+i;i-=l}}function ke(s,t){let e=0;for(let{from:i,to:n}of s.ranges){if(t<=n){e+=t-i;break}e+=n-i}return e/s.total}function Po(s,t){for(let e of s)if(t(e))return e}var Js={toDOM(s){return s},fromDOM(s){return s},scale:1,eq(s){return s==this}};function Zs(s){let t=s.facet(ti).filter(i=>typeof i!="function"),e=s.facet(ys).filter(i=>typeof i!="function");return e.length&&t.push(E.join(e)),t}var Xi=class s{constructor(t,e,i){let n=0,r=0,o=0;this.viewports=i.map(({from:l,to:a})=>{let h=e.lineAt(l,O.ByPos,t,0,0).top,c=e.lineAt(a,O.ByPos,t,0,0).bottom;return n+=c-h,{from:l,to:a,top:h,bottom:c,domTop:0,domBottom:0}}),this.scale=(7e6-n)/(e.height-n);for(let l of this.viewports)l.domTop=o+(l.top-r)*this.scale,o=l.domBottom=l.domTop+(l.bottom-l.top),r=l.bottom}toDOM(t){for(let e=0,i=0,n=0;;e++){let r=ee.from==t.viewports[i].from&&e.to==t.viewports[i].to):!1}};function jt(s,t){if(t.scale==1)return s;let e=t.toDOM(s.top),i=t.toDOM(s.bottom);return new $(s.from,s.length,e,i-e,Array.isArray(s._content)?s._content.map(n=>jt(n,t)):s._content)}var Me=C.define({combine:s=>s.join(" ")}),$i=C.define({combine:s=>s.indexOf(!0)>-1}),Gi=st.newName(),ar=st.newName(),hr=st.newName(),cr={"&light":"."+ar,"&dark":"."+hr};function Ui(s,t,e){return new st(t,{finish(i){return/&/.test(i)?i.replace(/&\w*/,n=>{if(n=="&")return s;if(!e||!e[n])throw new RangeError(`Unsupported selector: ${n}`);return e[n]}):s+" "+i}})}var No=Ui("."+Gi,{"&":{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":{userSelect:"none",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-selectionHandle":{backgroundColor:"currentColor",width:"1.5px"},".cm-selectionHandle-start::before, .cm-selectionHandle-end::before":{content:'""',backgroundColor:"inherit",borderRadius:"50%",width:"8px",height:"8px",position:"absolute",left:"-3.25px"},".cm-selectionHandle-start::before":{top:"-8px"},".cm-selectionHandle-end::before":{bottom:"-8px"},".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"},".cm-panels-top":{top:"0"},".cm-panels-bottom":{bottom:"0"},"&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:"baseline",height:"1em",width:0,display:"inline"},".cm-placeholder":{color:"#888",display:"inline-block",verticalAlign:"top",userSelect:"none"},".cm-highlightSpace":{background:"radial-gradient(circle at 50% 55%, #aaa 20%, transparent 0) no-repeat",backgroundSize:".4em",backgroundPosition:"calc(min(50%, 0px)) center"},".cm-highlightTab":{backgroundImage:`url('data:image/svg+xml,')`,backgroundSize:"auto 100%",backgroundPosition:"right 90%",backgroundRepeat:"no-repeat"},".cm-trailingSpace":{backgroundColor:"#ff332255"},".cm-button":{verticalAlign:"middle",color:"inherit",fontSize:"70%",padding:".2em 1em",borderRadius:"1px"},"&light .cm-button":{backgroundImage:"linear-gradient(#eff1f5, #d9d9df)",border:"1px solid #888","&:active":{backgroundImage:"linear-gradient(#b4b4b4, #d0d3d6)"}},"&dark .cm-button":{backgroundImage:"linear-gradient(#393939, #111)",border:"1px solid #888","&:active":{backgroundImage:"linear-gradient(#111, #333)"}},".cm-textfield":{verticalAlign:"middle",color:"inherit",fontSize:"70%",border:"1px solid silver",padding:".2em .5em"},"&light .cm-textfield":{backgroundColor:"white"},"&dark .cm-textfield":{border:"1px solid #555",backgroundColor:"inherit"}},cr),Wo={childList:!0,characterData:!0,subtree:!0,attributes:!0,characterDataOldValue:!0},di=y.ie&&y.ie_version<=11,Qi=class{constructor(t){this.view=t,this.active=!1,this.editContext=null,this.selectionRange=new xi,this.selectionChanged=!1,this.delayedFlush=-1,this.resizeTimeout=-1,this.queue=[],this.delayedAndroidKey=null,this.flushingAndroidKey=-1,this.lastChange=0,this.scrollTargets=[],this.intersection=null,this.resizeScroll=null,this.intersecting=!1,this.gapIntersection=null,this.gaps=[],this.printQuery=null,this.parentCheck=-1,this.dom=t.contentDOM,this.observer=new MutationObserver(e=>{for(let i of e)this.queue.push(i);(y.ie&&y.ie_version<=11||y.ios&&t.composing)&&e.some(i=>i.type=="childList"&&i.removedNodes.length||i.type=="characterData"&&i.oldValue.length>i.target.nodeValue.length)?this.flushSoon():this.flush()}),window.EditContext&&y.android&&t.constructor.EDIT_CONTEXT!==!1&&!(y.chrome&&y.chrome_version<126)&&(this.editContext=new Ji(t),t.state.facet(rt)&&(t.contentDOM.editContext=this.editContext.editContext)),di&&(this.onCharData=e=>{this.queue.push({target:e.target,type:"characterData",oldValue:e.prevValue}),this.flushSoon()}),this.onSelectionChange=this.onSelectionChange.bind(this),this.onResize=this.onResize.bind(this),this.onPrint=this.onPrint.bind(this),this.onScroll=this.onScroll.bind(this),window.matchMedia&&(this.printQuery=window.matchMedia("print")),typeof ResizeObserver=="function"&&(this.resizeScroll=new ResizeObserver(()=>{var e;((e=this.view.docView)===null||e===void 0?void 0:e.lastUpdate){this.parentCheck<0&&(this.parentCheck=setTimeout(this.listenForScroll.bind(this),1e3)),e.length>0&&e[e.length-1].intersectionRatio>0!=this.intersecting&&(this.intersecting=!this.intersecting,this.intersecting!=this.view.inView&&this.onScrollChanged(document.createEvent("Event")))},{threshold:[0,.001]}),this.intersection.observe(this.dom),this.gapIntersection=new IntersectionObserver(e=>{e.length>0&&e[e.length-1].intersectionRatio>0&&this.onScrollChanged(document.createEvent("Event"))},{})),this.listenForScroll(),this.readSelectionRange()}onScrollChanged(t){this.view.inputState.runHandlers("scroll",t),this.intersecting&&this.view.measure()}onScroll(t){this.intersecting&&this.flush(!1),this.editContext&&this.view.requestMeasure(this.editContext.measureReq),this.onScrollChanged(t)}onResize(){this.resizeTimeout<0&&(this.resizeTimeout=setTimeout(()=>{this.resizeTimeout=-1,this.view.requestMeasure()},50))}onPrint(t){(t.type=="change"||!t.type)&&!t.matches||(this.view.viewState.printing=!0,this.view.measure(),setTimeout(()=>{this.view.viewState.printing=!1,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,n=this.selectionRange;if(i.state.facet(rt)?i.root.activeElement!=this.dom:!Xt(this.dom,n))return;let r=n.anchorNode&&i.docView.tile.nearest(n.anchorNode);if(r&&r.isWidget()&&r.widget.ignoreEvent(t)){e||(this.selectionChanged=!1);return}(y.ie&&y.ie_version<=11||y.android&&y.chrome)&&!i.state.selection.main.empty&&n.focusNode&&Gt(n.focusNode,n.focusOffset,n.anchorNode,n.anchorOffset)?this.flushSoon():this.flush(!1)}readSelectionRange(){let{view:t}=this,e=re(t.root);if(!e)return!1;let i=y.safari&&t.root.nodeType==11&&t.root.activeElement==this.dom&&Vo(this.view,e)||e;if(!i||this.selectionRange.eq(i))return!1;let n=Xt(this.dom,i);return n&&!this.selectionChanged&&t.inputState.lastFocusTime>Date.now()-200&&t.inputState.lastTouchTime{let r=this.delayedAndroidKey;r&&(this.clearDelayedAndroidKey(),this.view.inputState.lastKeyCode=r.keyCode,this.view.inputState.lastKeyTime=Date.now(),!this.flush()&&r.force&&Wt(this.dom,r.key,r.keyCode))};this.flushingAndroidKey=this.view.win.requestAnimationFrame(n)}(!this.delayedAndroidKey||t=="Enter")&&(this.delayedAndroidKey={key:t,keyCode:e,force:this.lastChange{this.delayedFlush=-1,this.flush()}))}forceFlush(){this.delayedFlush>=0&&(this.view.win.cancelAnimationFrame(this.delayedFlush),this.delayedFlush=-1),this.flush()}pendingRecords(){for(let t of this.observer.takeRecords())this.queue.push(t);return this.queue}processRecords(){let t=this.pendingRecords();t.length&&(this.queue=[]);let e=-1,i=-1,n=!1;for(let r of t){let o=this.readMutation(r);o&&(o.typeOver&&(n=!0),e==-1?{from:e,to:i}=o:(e=Math.min(o.from,e),i=Math.max(o.to,i)))}return{from:e,to:i,typeOver:n}}readChange(){let{from:t,to:e,typeOver:i}=this.processRecords(),n=this.selectionChanged&&Xt(this.dom,this.selectionRange);if(t<0&&!n)return null;t>-1&&(this.lastChange=Date.now()),this.view.inputState.lastFocusTime=0,this.selectionChanged=!1;let r=new Wi(this.view,t,e,i);return this.view.docView.domChanged={newSel:r.newSel?r.newSel.main:null},r}flush(t=!0){if(this.delayedFlush>=0||this.delayedAndroidKey)return!1;t&&this.readSelectionRange();let e=this.selectionChanged,i=this.readChange();if(!i)return this.view.requestMeasure(),!1;let n=this.view.state,r=Jn(this.view,i);return this.view.state==n&&(i.domChanged||e)&&this.view.update([]),r}readMutation(t){let e=this.view.docView.tile.nearest(t.target);if(!e||e.isWidget())return null;if(e.markDirty(t.type=="attributes"),t.type=="childList"){let i=tn(e,t.previousSibling||t.target.previousSibling,-1),n=tn(e,t.nextSibling||t.target.nextSibling,1);return{from:i?e.posAfter(i):e.posAtStart,to:n?e.posBefore(n):e.posAtEnd,typeOver:!1}}else return t.type=="characterData"?{from:e.posAtStart,to:e.posAtEnd,typeOver:t.target.nodeValue==t.oldValue}:null}setWindow(t){t!=this.win&&(this.removeWindowListeners(this.win),this.win=t,this.addWindowListeners(this.win))}addWindowListeners(t){t.addEventListener("resize",this.onResize),this.printQuery?this.printQuery.addEventListener?this.printQuery.addEventListener("change",this.onPrint):this.printQuery.addListener(this.onPrint):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),this.printQuery?this.printQuery.removeEventListener?this.printQuery.removeEventListener("change",this.onPrint):this.printQuery.removeListener(this.onPrint):t.removeEventListener("beforeprint",this.onPrint),t.document.removeEventListener("selectionchange",this.onSelectionChange)}update(t){this.editContext&&(this.editContext.update(t),t.startState.facet(rt)!=t.state.facet(rt)&&(t.view.contentDOM.editContext=t.state.facet(rt)?this.editContext.editContext:null))}destroy(){var t,e,i;this.stop(),(t=this.intersection)===null||t===void 0||t.disconnect(),(e=this.gapIntersection)===null||e===void 0||e.disconnect(),(i=this.resizeScroll)===null||i===void 0||i.disconnect();for(let n of this.scrollTargets)n.removeEventListener("scroll",this.onScroll);this.removeWindowListeners(this.win),clearTimeout(this.parentCheck),clearTimeout(this.resizeTimeout),this.win.cancelAnimationFrame(this.delayedFlush),this.win.cancelAnimationFrame(this.flushingAndroidKey),this.editContext&&(this.view.contentDOM.editContext=null,this.editContext.destroy())}};function tn(s,t,e){for(;t;){let i=L.get(t);if(i&&i.parent==s)return i;let n=t.parentNode;t=n!=s.dom?n:e>0?t.nextSibling:t.previousSibling}return null}function en(s,t){let e=t.startContainer,i=t.startOffset,n=t.endContainer,r=t.endOffset,o=s.docView.domAtPos(s.state.selection.main.anchor,1);return Gt(o.node,o.offset,n,r)&&([e,i,n,r]=[n,r,e,i]),{anchorNode:e,anchorOffset:i,focusNode:n,focusOffset:r}}function Vo(s,t){if(t.getComposedRanges){let n=t.getComposedRanges(s.root)[0];if(n)return en(s,n)}let e=null;function i(n){n.preventDefault(),n.stopImmediatePropagation(),e=n.getTargetRanges()[0]}return s.contentDOM.addEventListener("beforeinput",i,!0),s.dom.ownerDocument.execCommand("indent"),s.contentDOM.removeEventListener("beforeinput",i,!0),e?en(s,e):null}var Ji=class{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 n=t.state.selection.main,{anchor:r,head:o}=n,l=this.toEditorPos(i.updateRangeStart),a=this.toEditorPos(i.updateRangeEnd);t.inputState.composing>=0&&!this.composing&&(this.composing={contextBase:i.updateRangeStart,editorBase:l,drifted:!1});let h=a-l>i.text.length;l==this.from&&rthis.to&&(a=r);let c=Zn(t.state.sliceDoc(l,a),i.text,(h?n.from:n.to)-l,h?"end":null);if(!c){let d=v.single(this.toEditorPos(i.selectionStart),this.toEditorPos(i.selectionEnd));Vi(d,n)||t.dispatch({selection:d,userEvent:"select"});return}let f={from:c.from+l,to:c.toA+l,insert:q.of(i.text.slice(c.from,c.toB).split(` +`))};if((y.mac||y.android)&&f.from==o-1&&/^\. ?$/.test(i.text)&&t.contentDOM.getAttribute("autocorrect")=="off"&&(f={from:l,to:a,insert:q.of([i.text.replace("."," ")])}),this.pendingContextChange=f,!t.state.readOnly){let d=this.to-this.from+(f.to-f.from+f.insert.length);xs(t,f,v.single(this.toEditorPos(i.selectionStart,d),this.toEditorPos(i.selectionEnd,d)))}this.pendingContextChange&&(this.revertPending(t.state),this.setSelection(t.state)),f.from=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 n=[],r=null;for(let o=this.toEditorPos(i.rangeStart),l=this.toEditorPos(i.rangeEnd);o{let n=[];for(let r of i.getTextFormats()){let o=r.underlineStyle,l=r.underlineThickness;if(!/none/i.test(o)&&!/none/i.test(l)){let a=this.toEditorPos(r.rangeStart),h=this.toEditorPos(r.rangeEnd);if(a{t.inputState.composing<0&&(t.inputState.composing=0,t.inputState.compositionFirstChange=!0)},this.handlers.compositionend=()=>{if(t.inputState.composing=-1,t.inputState.compositionFirstChange=null,this.composing){let{drifted:i}=this.composing;this.composing=null,i&&this.reset(t.state)}};for(let i in this.handlers)e.addEventListener(i,this.handlers[i]);this.measureReq={read:i=>{let n=re(i.root);n&&n.rangeCount&&this.editContext.updateSelectionBounds(n.getRangeAt(0).getBoundingClientRect())}}}applyEdits(t){let e=0,i=!1,n=this.pendingContextChange;return t.changes.iterChanges((r,o,l,a,h)=>{if(i)return;let c=h.length-(o-r);if(n&&o>=n.to)if(n.from==r&&n.to==o&&n.insert.eq(h)){n=this.pendingContextChange=null,e+=c,this.to+=c;return}else n=null,this.revertPending(t.state);if(r+=e,o+=e,o<=this.from)this.from+=c,this.to+=c;else if(rthis.to||this.to-this.from+h.length>3e4){i=!0;return}this.editContext.updateText(this.toContextPos(r),this.toContextPos(o),h.toString()),this.to+=c}e+=c}),n&&!i&&this.revertPending(t.state),!i}update(t){let e=this.pendingContextChange,i=t.startState.selection.main;this.composing&&(this.composing.drifted||!t.changes.touchesRange(i.from,i.to)&&t.transactions.some(n=>!n.isUserEvent("input.type")&&n.changes.touchesRange(this.from,this.to)))?(this.composing.drifted=!0,this.composing.editorBase=t.changes.mapPos(this.composing.editorBase)):!this.applyEdits(t)||!this.rangeIsValid(t.state)?(this.pendingContextChange=null,this.reset(t.state)):(t.docChanged||t.selectionSet||e)&&this.setSelection(t.state),(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,i=this.toContextPos(Math.max(this.from,Math.min(this.to,e.anchor))),n=this.toContextPos(e.head);(this.editContext.selectionStart!=i||this.editContext.selectionEnd!=n)&&this.editContext.updateSelection(i,n)}rangeIsValid(t){let{head:e}=t.selection.main;return!(this.from>0&&e-this.from<500||this.to1e4*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])}},M=class s{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=!1,this.updateState=2,this.measureScheduled=-1,this.measureRequests=[],this.clearAnnouncement=-1,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),t.parent&&t.parent.appendChild(this.dom);let{dispatch:i}=t;this.dispatchTransactions=t.dispatchTransactions||i&&(n=>n.forEach(r=>i(r,this)))||(n=>this.update(n)),this.dispatch=this.dispatch.bind(this),this._root=t.root||Br(t.parent)||document,this.viewState=new Ye(this,t.state||Ot.create(t)),t.scrollTo&&t.scrollTo.is(xe)&&(this.viewState.scrollTarget=t.scrollTo.value.clip(this.viewState.state)),this.plugins=this.state.facet(Bt).map(n=>new Qt(n));for(let n of this.plugins)n.update(this);this.observer=new Qi(this),this.inputState=new Fi(this),this.inputState.ensureHandlers(this.plugins),this.docView=new Ie(this),this.mountStyles(),this.updateAttrs(),this.updateState=0,this.requestMeasure(),!((e=document.fonts)===null||e===void 0)&&e.ready&&document.fonts.ready.then(()=>{this.viewState.mustMeasureContent="refresh",this.requestMeasure()})}dispatch(...t){let e=t.length==1&&t[0]instanceof Ms?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=!1,i=!1,n,r=this.state;for(let d of t){if(d.startState!=r)throw new RangeError("Trying to update state with a transaction that doesn't start from the previous state.");r=d.state}if(this.destroyed){this.viewState.state=r;return}let o=this.hasFocus,l=0,a=null;t.some(d=>d.annotation(rr))?(this.inputState.notifiedFocused=o,l=1):o!=this.inputState.notifiedFocused&&(this.inputState.notifiedFocused=o,a=or(r,o),a||(l=1));let h=this.observer.delayedAndroidKey,c=null;if(h?(this.observer.clearDelayedAndroidKey(),c=this.observer.readChange(),(c&&!this.state.doc.eq(r.doc)||!this.state.selection.eq(r.selection))&&(c=null)):this.observer.clear(),r.facet(Ot.phrases)!=this.state.facet(Ot.phrases))return this.setState(r);n=Ve.create(this,r,t),n.flags|=l;let f=this.viewState.scrollTarget;try{this.updateState=2;for(let d of t){if(f&&(f=f.map(d.changes)),d.scrollIntoView){let{main:u}=d.state.selection,{x:p,y:g}=this.state.facet(s.cursorScrollMargin);f=new Ut(u.empty?u:v.cursor(u.head,u.head>u.anchor?-1:1),"nearest","nearest",g,p)}for(let u of d.effects)u.is(xe)&&(f=u.value.clip(this.state))}this.viewState.update(n,f),this.bidiCache=Xe.update(this.bidiCache,n.changes),n.empty||(this.updatePlugins(n),this.inputState.update(n)),e=this.docView.update(n),this.state.facet(_t)!=this.styleModules&&this.mountStyles(),i=this.updateAttrs(),this.showAnnouncements(t),this.docView.updateSelection(e,t.some(d=>d.isUserEvent("select.pointer")))}finally{this.updateState=0}if(n.startState.facet(Me)!=n.state.facet(Me)&&(this.viewState.mustMeasureContent=!0),(e||i||f||this.viewState.mustEnforceCursorAssoc||this.viewState.mustMeasureContent)&&this.requestMeasure(),e&&this.docViewUpdate(),!n.empty)for(let d of this.state.facet(ki))try{d(n)}catch(u){Z(this.state,u,"update listener")}(a||c)&&Promise.resolve().then(()=>{a&&this.state==a.startState&&this.dispatch(a),c&&!Jn(this,c)&&h.force&&Wt(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 i of this.plugins)i.destroy(this);this.viewState=new Ye(this,t),this.plugins=t.facet(Bt).map(i=>new Qt(i)),this.pluginMap.clear();for(let i of this.plugins)i.update(this);this.docView.destroy(),this.docView=new Ie(this),this.inputState.ensureHandlers(this.plugins),this.mountStyles(),this.updateAttrs(),this.bidiCache=[]}finally{this.updateState=0}e&&this.focus(),this.requestMeasure()}updatePlugins(t){let e=t.startState.facet(Bt),i=t.state.facet(Bt);if(e!=i){let n=[];for(let r of i){let o=e.indexOf(r);if(o<0)n.push(new Qt(r));else{let l=this.plugins[o];l.mustUpdate=t,n.push(l)}}for(let r of this.plugins)r.mustUpdate!=t&&r.destroy(this);this.plugins=n,this.pluginMap.clear()}else for(let n of this.plugins)n.mustUpdate=t;for(let n=0;n-1&&this.win.cancelAnimationFrame(this.measureScheduled),this.observer.delayedAndroidKey){this.measureScheduled=-1,this.requestMeasure();return}this.measureScheduled=0,t&&this.observer.forceFlush();let e=null,i=this.viewState.scrollParent,n=this.viewState.getScrollOffset(),{scrollAnchorPos:r,scrollAnchorHeight:o,scaleY:l}=this.viewState;Math.abs(n-this.viewState.scrollOffset)>1&&(o=-1),this.viewState.scrollAnchorHeight=-1;try{for(let a=0;;a++){if(o<0){if(kn(i||this.win))r=-1,o=this.viewState.heightMap.height/this.viewState.scaleY;else{let p=this.viewState.scrollAnchorAt(n);r=p.from,o=p.top}l=this.viewState.scaleY}this.updateState=1;let h=this.viewState.measure();if(!h&&!this.measureRequests.length&&this.viewState.scrollTarget==null)break;if(a>5){console.warn(this.measureRequests.length?"Measure loop restarted more than 5 times":"Viewport failed to stabilize");break}let c=[];h&4||([this.measureRequests,c]=[c,this.measureRequests]);let f=c.map(p=>{try{return p.read(this)}catch(g){return Z(this.state,g),sn}}),d=Ve.create(this,this.state,[]),u=!1;d.flags|=h,e?e.flags|=h:e=d,this.updateState=2,d.empty||(this.updatePlugins(d),this.inputState.update(d),this.updateAttrs(),u=this.docView.update(d),u&&this.docViewUpdate());for(let p=0;p1||g<-1)&&!(y.ios&&this.inputState.lastIOSMomentumScroll>Date.now()-100)&&(i==this.scrollDOM||this.hasFocus||Math.max(this.inputState.lastWheelEvent,this.inputState.lastTouchTime)>Date.now()-100)){n=n+g,i?r<0?i.scrollTop=i.scrollHeight:i.scrollTop+=g:this.win.scrollBy(0,g),o=-1;continue}}break}}}finally{this.updateState=0,this.measureScheduled=-1}if(e&&!e.empty)for(let a of this.state.facet(ki))a(e)}get themeClasses(){return Gi+" "+(this.state.facet($i)?hr:ar)+" "+this.state.facet(Me)}updateAttrs(){let t=nn(this,_n,{class:"cm-editor"+(this.hasFocus?" cm-focused ":" ")+this.themeClasses}),e={spellcheck:"false",autocorrect:"off",autocapitalize:"off",writingsuggestions:"false",translate:"no",contenteditable:this.state.facet(rt)?"true":"false",class:"cm-content",style:`${y.tabSize}: ${this.state.tabSize}`,role:"textbox","aria-multiline":"true"};this.state.readOnly&&(e["aria-readonly"]="true"),nn(this,Ze,e);let i=this.observer.ignore(()=>{let n=Ns(this.contentDOM,this.contentAttrs,e),r=Ns(this.dom,this.editorAttrs,t);return n||r});return this.editorAttrs=t,this.contentAttrs=e,i}showAnnouncements(t){let e=!0;for(let i of t)for(let n of i.effects)if(n.is(s.announce)){e&&(this.announceDOM.textContent="",this.win.clearTimeout(this.clearAnnouncement),this.clearAnnouncement=this.win.setTimeout(()=>{this.announceDOM.textContent="\xA0"},200),e=!1);let r=this.announceDOM.appendChild(document.createElement("div"));r.textContent=n.value}}mountStyles(){this.styleModules=this.state.facet(_t);let t=this.state.facet(s.cspNonce);st.mount(this.root,this.styleModules.concat(No).reverse(),t?{nonce:t}:void 0)}readMeasured(){if(this.updateState==2)throw new Error("Reading the editor layout isn't allowed during an update");this.updateState==0&&this.measureScheduled>-1&&this.measure(!1)}requestMeasure(t){if(this.measureScheduled<0&&(this.measureScheduled=this.win.requestAnimationFrame(()=>this.measure())),t){if(this.measureRequests.indexOf(t)>-1)return;if(t.key!=null){for(let e=0;ei.plugin==t)||null),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){return this.readMeasured(),this.viewState.elementAtHeight(t)}lineBlockAtHeight(t){return this.readMeasured(),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 fi(this,t,Ks(this,t,e,i))}moveByGroup(t,e){return fi(this,t,Ks(this,t,e,i=>ro(this,t.head,i)))}visualLineSide(t,e){return e?v.cursor(t.to,1):v.cursor(t.from,-1)}moveToLineBoundary(t,e,i=!0){return no(this,t,e,i)}moveVertically(t,e,i){return fi(this,t,oo(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=!0){this.readMeasured();let i=Hi(this,t,e);return i&&i.pos}posAndSideAtCoords(t,e=!0){return this.readMeasured(),Hi(this,t,e)}coordsAtPos(t,e=1){this.readMeasured();let i=this.state.doc.lineAt(t),n=this.bidiSpans(i),r=n[Y.find(n,t-i.from,-1,e)];return i.length&&(t==i.from&&e<0||t==i.to&&e>0)&&r.dir!=this.textDirectionAt(i.from)&&(t==i.to?(t=i.from+r.from,e=1):(t=i.from+r.to,e=-1)),this.docView.coordsAt(t,e,r.dir==B.RTL)}coordsForChar(t){return this.readMeasured(),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){return!this.state.facet(In)||tthis.viewport.to?this.textDirection:(this.readMeasured(),this.docView.textDirectionAt(t))}get lineWrapping(){return this.viewState.heightOracle.lineWrapping}bidiSpans(t){if(t.length>Fo)return Ln(t.length);let e=this.textDirectionAt(t.from),i;for(let r of this.bidiCache)if(r.from==t.from&&r.dir==e&&(r.fresh||On(r.isolates,i=Fs(this,t))))return r.order;i||(i=Fs(this,t));let n=Rn(t.text,e,i);return this.bidiCache.push(new Xe(t.from,t.to,e,i,!0,n)),n}get hasFocus(){var t;return(this.dom.ownerDocument.hasFocus()||y.safari&&((t=this.inputState)===null||t===void 0?void 0:t.lastContextMenu)>Date.now()-3e4)&&this.root.activeElement==this.contentDOM}focus(){this.observer.ignore(()=>{Cn(this.contentDOM),this.docView.updateSelection()})}setRoot(t){this._root!=t&&(this._root=t,this.observer.setWindow((t.nodeType==9?t:t.ownerDocument).defaultView||window),this.mountStyles())}destroy(){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(),this.win.clearTimeout(this.clearAnnouncement),this.measureScheduled>-1&&this.win.cancelAnimationFrame(this.measureScheduled),this.destroyed=!0}static scrollIntoView(t,e={}){var i,n,r,o;return xe.of(new Ut(typeof t=="number"?v.cursor(t):t,(i=e.y)!==null&&i!==void 0?i:"nearest",(n=e.x)!==null&&n!==void 0?n:"nearest",(r=e.yMargin)!==null&&r!==void 0?r:5,(o=e.xMargin)!==null&&o!==void 0?o:5))}scrollSnapshot(){let{scrollTop:t,scrollLeft:e}=this.scrollDOM,i=this.viewState.scrollAnchorAt(t);return xe.of(new Ut(v.cursor(i.from),"start","start",i.top-t,e,!0))}setTabFocusMode(t){t==null?this.inputState.tabFocusMode=this.inputState.tabFocusMode<0?0:-1:typeof t=="boolean"?this.inputState.tabFocusMode=t?0:-1:this.inputState.tabFocusMode!=0&&(this.inputState.tabFocusMode=Date.now()+t)}static domEventHandlers(t){return V.define(()=>({}),{eventHandlers:t})}static domEventObservers(t){return V.define(()=>({}),{eventObservers:t})}static theme(t,e){let i=st.newName(),n=[Me.of(i),_t.of(Ui(`.${i}`,t))];return e&&e.dark&&n.push($i.of(!0)),n}static baseTheme(t){return ge.lowest(_t.of(Ui("."+Gi,t,cr)))}static findFromDOM(t){var e;let i=t.querySelector(".cm-content"),n=i&&L.get(i)||L.get(t);return((e=n?.root)===null||e===void 0?void 0:e.view)||null}};M.styleModule=_t;M.inputHandler=Vn;M.clipboardInputFilter=ms;M.clipboardOutputFilter=bs;M.scrollHandler=Kn;M.focusChangeEffect=Fn;M.perLineTextDirection=In;M.exceptionSink=Wn;M.updateListener=ki;M.editable=rt;M.mouseSelectionStyle=Nn;M.dragMovesSelection=Pn;M.clickAddsSelectionRange=Hn;M.decorations=ti;M.blockWrappers=jn;M.outerDecorations=ys;M.atomicRanges=ce;M.bidiIsolatedRanges=Yn;M.cursorScrollMargin=C.define({combine:s=>{let t=5,e=5;for(let i of s)typeof i=="number"?t=e=i:{x:t,y:e}=i;return{x:t,y:e}}});M.scrollMargins=Xn;M.darkTheme=$i;M.cspNonce=C.define({combine:s=>s.length?s[0]:""});M.contentAttributes=Ze;M.editorAttributes=_n;M.lineWrapping=M.contentAttributes.of({class:"cm-lineWrapping"});M.announce=U.define();var Fo=4096,sn={},Xe=class s{constructor(t,e,i,n,r,o){this.from=t,this.to=e,this.dir=i,this.isolates=n,this.fresh=r,this.order=o}static update(t,e){if(e.empty&&!t.some(r=>r.fresh))return t;let i=[],n=t.length?t[t.length-1].dir:B.LTR;for(let r=Math.max(0,t.length-10);r=0;n--){let r=i[n],o=typeof r=="function"?r(s):r;o&&us(o,e)}return e}var Io=y.mac?"mac":y.windows?"win":y.linux?"linux":"key";function zo(s,t){let e=s.split(/-(?!$)/),i=e[e.length-1];i=="Space"&&(i=" ");let n,r,o,l;for(let a=0;ai.concat(n),[]))),e}function Kl(s,t,e){return dr(fr(s.state),t,s,e)}var ut=null,_o=4e3;function jo(s,t=Io){let e=Object.create(null),i=Object.create(null),n=(o,l)=>{let a=i[o];if(a==null)i[o]=l;else if(a!=l)throw new Error("Key binding "+o+" is used both as a regular binding and as a multi-stroke prefix")},r=(o,l,a,h,c)=>{var f,d;let u=e[o]||(e[o]=Object.create(null)),p=l.split(/ (?!$)/).map(b=>zo(b,t));for(let b=1;b{let A=ut={view:x,prefix:w,scope:o};return setTimeout(()=>{ut==A&&(ut=null)},_o),!0}]})}let g=p.join(" ");n(g,!1);let m=u[g]||(u[g]={preventDefault:!1,stopPropagation:!1,run:((d=(f=u._any)===null||f===void 0?void 0:f.run)===null||d===void 0?void 0:d.slice())||[]});a&&m.run.push(a),h&&(m.preventDefault=!0),c&&(m.stopPropagation=!0)};for(let o of s){let l=o.scope?o.scope.split(" "):["editor"];if(o.any)for(let h of l){let c=e[h]||(e[h]=Object.create(null));c._any||(c._any={preventDefault:!1,stopPropagation:!1,run:[]});let{any:f}=o;for(let d in c)c[d].run.push(u=>f(u,Zi))}let a=o[t]||o.key;if(a)for(let h of l)r(h,a,o.run,o.preventDefault,o.stopPropagation),o.shift&&r(h,"Shift-"+a,o.shift,o.preventDefault,o.stopPropagation)}return e}var Zi=null;function dr(s,t,e,i){Zi=t;let n=Ls(t),r=si(n,0),o=Cs(r)==n.length&&n!=" ",l="",a=!1,h=!1,c=!1;ut&&ut.view==e&&ut.scope==i&&(l=ut.prefix+" ",er.indexOf(t.keyCode)<0&&(h=!0,ut=null));let f=new Set,d=m=>{if(m){for(let b of m.run)if(!f.has(b)&&(f.add(b),b(e)))return m.stopPropagation&&(c=!0),!0;m.preventDefault&&(m.stopPropagation&&(c=!0),h=!0)}return!1},u=s[i],p,g;return u&&(d(u[l+Ae(n,t,!o)])?a=!0:o&&(t.altKey||t.metaKey||t.ctrlKey)&&!(y.windows&&t.ctrlKey&&t.altKey)&&!(y.mac&&t.altKey&&!(t.ctrlKey||t.metaKey))&&(p=nt[t.keyCode])&&p!=n?(d(u[l+Ae(p,t,!0)])||t.shiftKey&&(g=Rt[t.keyCode])!=n&&g!=p&&d(u[l+Ae(g,t,!1)]))&&(a=!0):o&&t.shiftKey&&d(u[l+Ae(n,t,!0)])&&(a=!0),!a&&d(u._any)&&(a=!0)),h&&(a=!0),a&&c&&t.stopPropagation(),Zi=null,a}var St=class s{constructor(t,e,i,n,r){this.className=t,this.left=e,this.top=i,this.width=n,this.height=r}draw(){let t=document.createElement("div");return t.className=this.className,this.adjust(t),t}update(t,e){return e.className!=this.className?!1:(this.adjust(t),!0)}adjust(t){t.style.left=this.left+"px",t.style.top=this.top+"px",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 n=t.coordsAtPos(i.head,i.assoc||1);if(!n)return[];let r=ur(t);return[new s(e,n.left-r.left,n.top-r.top,null,n.bottom-n.top)]}else return Yo(t,e,i)}};function ur(s){let t=s.scrollDOM.getBoundingClientRect();return{left:(s.textDirection==B.LTR?t.left:t.right-s.scrollDOM.clientWidth*s.scaleX)-s.scrollDOM.scrollLeft*s.scaleX,top:t.top-s.scrollDOM.scrollTop*s.scaleY}}function on(s,t,e,i){let n=s.coordsAtPos(t,e*2);if(!n)return i;let r=s.dom.getBoundingClientRect(),o=(n.top+n.bottom)/2,l=s.posAtCoords({x:r.left+1,y:o}),a=s.posAtCoords({x:r.right-1,y:o});return l==null||a==null?i:{from:Math.max(i.from,Math.min(l,a)),to:Math.min(i.to,Math.max(l,a))}}function Yo(s,t,e){if(e.to<=s.viewport.from||e.from>=s.viewport.to)return[];let i=Math.max(e.from,s.viewport.from),n=Math.min(e.to,s.viewport.to),r=s.textDirection==B.LTR,o=s.contentDOM,l=o.getBoundingClientRect(),a=ur(s),h=o.querySelector(".cm-line"),c=h&&window.getComputedStyle(h),f=l.left+(c?parseInt(c.paddingLeft)+Math.min(0,parseInt(c.textIndent)):0),d=l.right-(c?parseInt(c.paddingRight):0),u=Ei(s,i,1),p=Ei(s,n,-1),g=u.type==W.Text?u:null,m=p.type==W.Text?p:null;if(g&&(s.lineWrapping||u.widgetLineBreaks)&&(g=on(s,i,1,g)),m&&(s.lineWrapping||p.widgetLineBreaks)&&(m=on(s,n,-1,m)),g&&m&&g.from==m.from&&g.to==m.to)return w(x(e.from,e.to,g));{let k=g?x(e.from,null,g):A(u,!1),S=m?x(null,e.to,m):A(p,!0),D=[];return(g||u).to<(m||p).from-(g&&m?1:0)||u.widgetLineBreaks>1&&k.bottom+s.defaultLineHeight/2de&&bt.from=Dt)break;it>ct&&Ss(Math.max(et,ct),k==null&&et<=de,Math.min(it,Dt),S==null&&it>=ue,qt.dir)}if(ct=yt.to+1,ct>=Dt)break}return fe.length==0&&Ss(de,k==null,ue,S==null,s.textDirection),{top:P,bottom:ht,horizontal:fe}}function A(k,S){let D=l.top+(S?k.top:k.bottom);return{top:D,bottom:D,horizontal:[]}}}function Xo(s,t){return s.constructor==t.constructor&&s.eq(t)}var ts=class{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"),e.above&&this.dom.classList.add("cm-layer-above"),e.class&&this.dom.classList.add(e.class),this.scale(),this.dom.setAttribute("aria-hidden","true"),this.setOrder(t.state),t.requestMeasure(this.measureReq),e.mount&&e.mount(this.dom,t)}update(t){t.startState.facet(Re)!=t.state.facet(Re)&&this.setOrder(t.state),(this.layer.update(t,this.dom)||t.geometryChanged)&&(this.scale(),t.view.requestMeasure(this.measureReq))}docViewUpdate(t){this.layer.updateOnDocViewUpdate!==!1&&t.requestMeasure(this.measureReq)}setOrder(t){let e=0,i=t.facet(Re);for(;e!Xo(e,this.drawn[i]))){let e=this.dom.firstChild,i=0;for(let n of t)n.update&&e&&n.constructor&&this.drawn[i].constructor&&n.update(e,this.drawn[i])?(e=e.nextSibling,i++):this.dom.insertBefore(n.draw(),e);for(;e;){let n=e.nextSibling;e.remove(),e=n}this.drawn=t,y.webkit&&(this.dom.style.display=this.dom.firstChild?"":"none")}}destroy(){this.layer.destroy&&this.layer.destroy(this.dom,this.view),this.dom.remove()}},Re=C.define();function pr(s){return[V.define(t=>new ts(t,s)),Re.of(s)]}var es=!y.ios,Tt=C.define({combine(s){return me(s,{cursorBlinkRate:1200,drawRangeCursor:!0,iosSelectionHandles:!0},{cursorBlinkRate:(t,e)=>Math.min(t,e),drawRangeCursor:(t,e)=>t||e})}});function ql(s={}){return[Tt.of(s),$o,Go,Qo,zn.of(!0)]}function _l(s){return s.facet(Tt)}function gr(s){return s.startState.facet(Tt)!=s.state.facet(Tt)}var $o=pr({above:!0,markers(s){let{state:t}=s,e=t.facet(Tt),i=[];for(let n of t.selection.ranges){let r=n==t.selection.main;if(n.empty||e.drawRangeCursor&&!(r&&y.ios&&e.iosSelectionHandles)){let o=r?"cm-cursor cm-cursor-primary":"cm-cursor cm-cursor-secondary",l=n.empty?n:v.cursor(n.head,n.assoc);for(let a of St.forRange(s,o,l))i.push(a)}}return i},update(s,t){s.transactions.some(i=>i.selection)&&(t.style.animationName=t.style.animationName=="cm-blink"?"cm-blink2":"cm-blink");let e=gr(s);return e&&ln(s.state,t),s.docChanged||s.selectionSet||e},mount(s,t){ln(t.state,s)},class:"cm-cursorLayer"});function ln(s,t){t.style.animationDuration=s.facet(Tt).cursorBlinkRate+"ms"}var Go=pr({above:!1,markers(s){let t=[],{main:e,ranges:i}=s.state.selection;for(let n of i)if(!n.empty&&(es||n!=e))for(let r of St.forRange(s,"cm-selectionBackground",n))t.push(r);if(y.ios&&!e.empty&&s.state.facet(Tt).iosSelectionHandles){for(let n of St.forRange(s,"cm-selectionHandle cm-selectionHandle-start",v.cursor(e.from,1)))t.push(n);for(let n of St.forRange(s,"cm-selectionHandle cm-selectionHandle-end",v.cursor(e.to,1)))t.push(n)}return t},update(s,t){return s.docChanged||s.selectionSet||s.viewportChanged||gr(s)},class:"cm-selectionLayer"}),Uo=y.gecko&&y.gecko_version==153?"#ffffff01":"transparent",Qo=ge.highest(M.theme({".cm-line":{...es?{"& ::selection, &::selection":{backgroundColor:`${Uo} !important`}}:{},caretColor:"transparent !important"},".cm-content":{caretColor:"transparent !important","& :focus":{caretColor:"initial !important",...es?{"&::selection, & ::selection":{backgroundColor:"Highlight !important"}}:{}}}})),mr=U.define({map(s,t){return s==null?null:t.mapPos(s)}}),Yt=pe.define({create(){return null},update(s,t){return s!=null&&(s=t.changes.mapPos(s)),t.effects.reduce((e,i)=>i.is(mr)?i.value:e,s)}}),Jo=V.fromClass(class{constructor(s){this.view=s,this.cursor=null,this.measureReq={read:this.readPos.bind(this),write:this.drawCursor.bind(this)}}update(s){var t;let e=s.state.field(Yt);e==null?this.cursor!=null&&((t=this.cursor)===null||t===void 0||t.remove(),this.cursor=null):(this.cursor||(this.cursor=this.view.scrollDOM.appendChild(document.createElement("div")),this.cursor.className="cm-dropCursor"),(s.startState.field(Yt)!=e||s.docChanged||s.geometryChanged)&&this.view.requestMeasure(this.measureReq))}readPos(){let{view:s}=this,t=s.state.field(Yt),e=t!=null&&s.coordsAtPos(t);if(!e)return null;let i=s.scrollDOM.getBoundingClientRect();return{left:e.left-i.left+s.scrollDOM.scrollLeft*s.scaleX,top:e.top-i.top+s.scrollDOM.scrollTop*s.scaleY,height:e.bottom-e.top}}drawCursor(s){if(this.cursor){let{scaleX:t,scaleY:e}=this.view;s?(this.cursor.style.left=s.left/t+"px",this.cursor.style.top=s.top/e+"px",this.cursor.style.height=s.height/e+"px"):this.cursor.style.left="-100000px"}}destroy(){this.cursor&&this.cursor.remove()}setDropPos(s){this.view.state.field(Yt)!=s&&this.view.dispatch({effects:mr.of(s)})}},{eventObservers:{dragover(s){this.setDropPos(this.view.posAtCoords({x:s.clientX,y:s.clientY}))},dragleave(s){(s.target==this.view.contentDOM||!this.view.contentDOM.contains(s.relatedTarget))&&this.setDropPos(null)},dragend(){this.setDropPos(null)},drop(){this.setDropPos(null)}}});function jl(){return[Yt,Jo]}function an(s,t,e,i,n){t.lastIndex=0;for(let r=s.iterRange(e,i),o=e,l;!r.next().done;o+=r.value.length)if(!r.lineBreak)for(;l=t.exec(r.value);)n(o+l.index,l)}function Zo(s,t){let e=s.visibleRanges;if(e.length==1&&e[0].from==s.viewport.from&&e[0].to==s.viewport.to)return e;let i=[];for(let{from:n,to:r}of e)n=Math.max(s.state.doc.lineAt(n).from,n-t),r=Math.min(s.state.doc.lineAt(r).to,r+t),i.length&&i[i.length-1].to>=n?i[i.length-1].to=r:i.push({from:n,to:r});return i}var ae=class{constructor(t){let{regexp:e,decoration:i,decorate:n,boundary:r,maxLength:o=1e3}=t;if(!e.global)throw new RangeError("The regular expression given to MatchDecorator should have its 'g' flag set");if(this.regexp=e,n)this.addMatch=(l,a,h,c)=>n(c,h,h+l[0].length,l,a);else if(typeof i=="function")this.addMatch=(l,a,h,c)=>{let f=i(l,a,h);f&&c(h,h+l[0].length,f)};else if(i)this.addMatch=(l,a,h,c)=>c(h,h+l[0].length,i);else throw new RangeError("Either 'decorate' or 'decoration' should be provided to MatchDecorator");this.boundary=r,this.maxLength=o}createDeco(t){let e=new Ts,i=e.add.bind(e);for(let{from:n,to:r}of Zo(t,this.maxLength))an(t.state.doc,this.regexp,n,r,(o,l)=>this.addMatch(l,t,o,i));return e.finish()}updateDeco(t,e){let i=1e9,n=-1;return t.docChanged&&t.changes.iterChanges((r,o,l,a)=>{a>=t.view.viewport.from&&l<=t.view.viewport.to&&(i=Math.min(l,i),n=Math.max(a,n))}),t.viewportMoved||n-i>1e3?this.createDeco(t.view):n>-1?this.updateRange(t.view,e.map(t.changes),i,n):e}updateRange(t,e,i,n){for(let r of t.visibleRanges){let o=Math.max(r.from,i),l=Math.min(r.to,n);if(l>=o){let a=t.state.doc.lineAt(o),h=a.toa.from;o--)if(this.boundary.test(a.text[o-1-a.from])){c=o;break}for(;ld.push(b.range(g,m));if(a==h)for(this.regexp.lastIndex=c-a.from;(u=this.regexp.exec(a.text))&&u.indexthis.addMatch(m,t,g,p));e=e.update({filterFrom:c,filterTo:f,filter:(g,m)=>gf,add:d})}}return e}},is=/x/.unicode!=null?"gu":"g",tl=new RegExp(`[\0-\b +-\x7F-\x9F\xAD\u061C\u200B\u200E\u200F\u2028\u2029\u202D\u202E\u2066\u2067\u2069\uFEFF\uFFF9-\uFFFC]`,is),el={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"},ui=null;function il(){var s;if(ui==null&&typeof document<"u"&&document.body){let t=document.body.style;ui=((s=t.tabSize)!==null&&s!==void 0?s:t.MozTabSize)!=null}return ui||!1}var Le=C.define({combine(s){let t=me(s,{render:null,specialChars:tl,addSpecialChars:null});return(t.replaceTabs=!il())&&(t.specialChars=new RegExp(" |"+t.specialChars.source,is)),t.addSpecialChars&&(t.specialChars=new RegExp(t.specialChars.source+"|"+t.addSpecialChars.source,is)),t}});function Yl(s={}){return[Le.of(s),sl()]}var hn=null;function sl(){return hn||(hn=V.fromClass(class{constructor(s){this.view=s,this.decorations=T.none,this.decorationCache=Object.create(null),this.decorator=this.makeDecorator(s.state.facet(Le)),this.decorations=this.decorator.createDeco(s)}makeDecorator(s){return new ae({regexp:s.specialChars,decoration:(t,e,i)=>{let{doc:n}=e.state,r=si(t[0],0);if(r==9){let o=n.lineAt(i),l=e.state.tabSize,a=ri(o.text,l,i-o.from);return T.replace({widget:new ns((l-a%l)*this.view.defaultCharacterWidth/this.view.scaleX)})}return this.decorationCache[r]||(this.decorationCache[r]=T.replace({widget:new ss(s,r)}))},boundary:s.replaceTabs?void 0:/[^]/})}update(s){let t=s.state.facet(Le);s.startState.facet(Le)!=t?(this.decorator=this.makeDecorator(t),this.decorations=this.decorator.createDeco(s.view)):this.decorations=this.decorator.updateDeco(s,this.decorations)}},{decorations:s=>s.decorations}))}var nl="\u2022";function rl(s){return s>=32?nl:s==10?"\u2424":String.fromCharCode(9216+s)}var ss=class extends lt{constructor(t,e){super(),this.options=t,this.code=e}eq(t){return t.code==this.code}toDOM(t){let e=rl(this.code),i=t.state.phrase("Control character")+" "+(el[this.code]||"0x"+this.code.toString(16)),n=this.options.render&&this.options.render(this.code,i,e);if(n)return n;let r=document.createElement("span");return r.textContent=e,r.title=i,r.setAttribute("aria-label",i),r.className="cm-specialChar",r}ignoreEvent(){return!1}},ns=class extends lt{constructor(t){super(),this.width=t}eq(t){return t.width==this.width}toDOM(){let t=document.createElement("span");return t.textContent=" ",t.className="cm-tab",t.style.width=this.width+"px",t}ignoreEvent(){return!1}},cn=V.fromClass(class{constructor(){this.height=1e3,this.attrs={style:"padding-bottom: 1000px"}}update(s){let{view:t}=s,e=t.viewState.editorHeight-t.defaultLineHeight-t.documentPadding.top-.5;e>=0&&e!=this.height&&(this.height=e,this.attrs={style:`padding-bottom: ${e}px`})}});function Xl(){return[cn,Ze.of(s=>{var t;return((t=s.plugin(cn))===null||t===void 0?void 0:t.attrs)||null})]}function $l(){return ll}var ol=T.line({class:"cm-activeLine"}),ll=V.fromClass(class{constructor(s){this.decorations=this.getDeco(s)}update(s){(s.docChanged||s.selectionSet)&&(this.decorations=this.getDeco(s.view))}getDeco(s){let t=-1,e=[];for(let i of s.state.selection.ranges){let n=s.lineBlockAt(i.head);n.from>t&&(e.push(ol.range(n.from)),t=n.from)}return T.set(e)}},{decorations:s=>s.decorations}),rs=class extends lt{constructor(t){super(),this.content=t}toDOM(t){let e=document.createElement("span");return 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(!0)),e.setAttribute("aria-hidden","true"),e}coordsAt(t){let e=t.firstChild?$t(t.firstChild):[];if(!e.length)return null;let i=window.getComputedStyle(t.parentNode),n=oe(e[0],i.direction!="rtl"),r=parseInt(i.lineHeight);return n.bottom-n.top>r*1.5?{left:n.left,right:n.right,top:n.top,bottom:n.top+r}:n}ignoreEvent(){return!1}};function Gl(s){let t=V.fromClass(class{constructor(e){this.view=e,this.placeholder=s?T.set([T.widget({widget:new rs(s),side:1}).range(0)]):T.none}get decorations(){return this.view.state.doc.length?T.none:this.placeholder}},{decorations:e=>e.decorations});return typeof s=="string"?[t,M.contentAttributes.of({"aria-placeholder":s})]:t}var os=2e3;function al(s,t,e){let i=Math.min(t.line,e.line),n=Math.max(t.line,e.line),r=[];if(t.off>os||e.off>os||t.col<0||e.col<0){let o=Math.min(t.off,e.off),l=Math.max(t.off,e.off);for(let a=i;a<=n;a++){let h=s.doc.line(a);h.length<=l&&r.push(v.range(h.from+o,h.to+l))}}else{let o=Math.min(t.col,e.col),l=Math.max(t.col,e.col);for(let a=i;a<=n;a++){let h=s.doc.line(a),c=ye(h.text,o,s.tabSize,!0);if(c<0)r.push(v.cursor(h.to));else{let f=ye(h.text,l,s.tabSize);r.push(v.range(h.from+c,h.from+f))}}}return r}function hl(s,t){let e=s.coordsAtPos(s.viewport.from);return e?Math.round(Math.abs((e.left-t)/s.defaultCharacterWidth)):-1}function fn(s,t){let e=s.posAtCoords({x:t.clientX,y:t.clientY},!1),i=s.state.doc.lineAt(e),n=e-i.from,r=n>os?-1:n==i.length?hl(s,t.clientX):ri(i.text,s.state.tabSize,e-i.from);return{line:i.number,col:r,off:n}}function cl(s,t){let e=fn(s,t),i=s.state.selection;return e?{update(n){if(n.docChanged){let r=n.changes.mapPos(n.startState.doc.line(e.line).from),o=n.state.doc.lineAt(r);e={line:o.number,col:e.col,off:Math.min(e.off,o.length)},i=i.map(n.changes)}},get(n,r,o){let l=fn(s,n);if(!l)return i;let a=al(s.state,e,l);return a.length?o?v.create(a.concat(i.ranges)):v.create(a):i}}:null}function Ul(s){let t=s?.eventFilter||(e=>e.altKey&&e.button==0);return M.mouseSelectionStyle.of((e,i)=>t(i)?cl(e,i):null)}var fl={Alt:[18,s=>!!s.altKey],Control:[17,s=>!!s.ctrlKey],Shift:[16,s=>!!s.shiftKey],Meta:[91,s=>!!s.metaKey]},dl={style:"cursor: crosshair"};function Ql(s={}){let[t,e]=fl[s.key||"Alt"],i=V.fromClass(class{constructor(n){this.view=n,this.isDown=!1}set(n){this.isDown!=n&&(this.isDown=n,this.view.update([]))}},{eventObservers:{keydown(n){this.set(n.keyCode==t||e(n))},keyup(n){(n.keyCode==t||!e(n))&&this.set(!1)},mousemove(n){this.set(e(n))}}});return[i,M.contentAttributes.of(n=>{var r;return!((r=n.plugin(i))===null||r===void 0)&&r.isDown?dl:null})]}var Te="-10000px",$e=class{constructor(t,e,i,n){this.facet=e,this.createTooltipView=i,this.removeTooltipView=n,this.input=t.state.facet(e),this.tooltips=this.input.filter(o=>o);let r=null;this.tooltipViews=this.tooltips.map(o=>r=i(o,r))}update(t,e){var i;let n=t.state.facet(this.facet),r=n.filter(a=>a);if(n===this.input){for(let a of this.tooltipViews)a.update&&a.update(t);return!1}let o=[],l=e?[]:null;for(let a=0;ae[h]=a),e.length=l.length),this.input=n,this.tooltips=r,this.tooltipViews=o,!0}};function Jl(s={}){return Be.of(s)}function br(s){let t=s.dom.ownerDocument.documentElement,e=t.clientWidth,i=getComputedStyle(t);if(!/stable/.test(i.scrollbarGutter||""))return{left:0,right:e};let n=t.getBoundingClientRect(),r=s.win.scrollX;return{left:Math.max(0,n.left+r-parseFloat(i.marginLeft)),right:Math.min(e,n.right+r+parseFloat(i.marginRight))}}function ul(s){let{left:t,right:e}=br(s);return{top:0,left:t,right:e,bottom:s.dom.ownerDocument.documentElement.clientHeight}}var Be=C.define({combine:s=>{var t,e,i;return{position:y.ios?"absolute":((t=s.find(n=>n.position))===null||t===void 0?void 0:t.position)||"fixed",parent:((e=s.find(n=>n.parent))===null||e===void 0?void 0:e.parent)||null,tooltipSpace:((i=s.find(n=>n.tooltipSpace))===null||i===void 0?void 0:i.tooltipSpace)||ul}}}),dn=new WeakMap,ii=V.fromClass(class{constructor(s){this.view=s,this.above=[],this.inView=!0,this.madeAbsolute=!1,this.lastTransaction=0,this.measureTimeout=-1;let t=s.state.facet(Be);this.position=t.position,this.parent=t.parent,this.classes=s.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 $e(s,yr,(e,i)=>this.createTooltip(e,i),e=>{this.resizeObserver&&this.resizeObserver.unobserve(e.dom),e.dom.remove()}),this.above=this.manager.tooltips.map(e=>!!e.above),this.intersectionObserver=typeof IntersectionObserver=="function"?new IntersectionObserver(e=>{Date.now()>this.lastTransaction-50&&e.length>0&&e[e.length-1].intersectionRatio<1&&this.measureSoon()},{threshold:[1]}):null,this.observeIntersection(),s.win.addEventListener("resize",this.measureSoon=this.measureSoon.bind(this)),this.maybeMeasure()}createContainer(){this.parent?(this.container=document.createElement("div"),this.container.style.position="relative",this.container.className=this.view.themeClasses,this.parent.appendChild(this.container)):this.container=this.view.dom}observeIntersection(){if(this.intersectionObserver){this.intersectionObserver.disconnect();for(let s of this.manager.tooltipViews)this.intersectionObserver.observe(s.dom)}}measureSoon(){this.measureTimeout<0&&(this.measureTimeout=setTimeout(()=>{this.measureTimeout=-1,this.maybeMeasure()},50))}update(s){s.transactions.length&&(this.lastTransaction=Date.now());let t=this.manager.update(s,this.above);t&&this.observeIntersection();let e=t||s.geometryChanged,i=s.state.facet(Be);if(i.position!=this.position&&!this.madeAbsolute){this.position=i.position;for(let n of this.manager.tooltipViews)n.dom.style.position=this.position;e=!0}if(i.parent!=this.parent){this.parent&&this.container.remove(),this.parent=i.parent,this.createContainer();for(let n of this.manager.tooltipViews)this.container.appendChild(n.dom);e=!0}else this.parent&&this.view.themeClasses!=this.classes&&(this.classes=this.container.className=this.view.themeClasses);e&&this.maybeMeasure()}createTooltip(s,t){let e=s.create(this.view),i=t?t.dom:null;if(e.dom.classList.add("cm-tooltip"),s.arrow&&!e.dom.querySelector(".cm-tooltip > .cm-tooltip-arrow")){let n=document.createElement("div");n.className="cm-tooltip-arrow",e.dom.appendChild(n)}return e.dom.style.position=this.position,e.dom.style.top=Te,e.dom.style.left="0px",this.container.insertBefore(e.dom,i),e.mount&&e.mount(this.view),this.resizeObserver&&this.resizeObserver.observe(e.dom),e}destroy(){var s,t,e;this.view.win.removeEventListener("resize",this.measureSoon);for(let i of this.manager.tooltipViews)i.dom.remove(),(s=i.destroy)===null||s===void 0||s.call(i);this.parent&&this.container.remove(),(t=this.resizeObserver)===null||t===void 0||t.disconnect(),(e=this.intersectionObserver)===null||e===void 0||e.disconnect(),clearTimeout(this.measureTimeout)}readMeasure(){let s=1,t=1,e=!1,i=0;if(this.position=="fixed"&&this.manager.tooltipViews.length){let{dom:o}=this.manager.tooltipViews[0];if(y.safari){let l=o.getBoundingClientRect();e=Math.abs(l.top+1e4)>1||Math.abs(l.left)>1}else e=!!o.offsetParent&&o.offsetParent!=this.container.ownerDocument.body}if(e||this.position=="absolute")if(this.parent){let o=this.parent.getBoundingClientRect();o.width&&o.height&&(s=o.width/this.parent.offsetWidth,t=o.height/this.parent.offsetHeight)}else({scaleX:s,scaleY:t}=this.view.viewState);else i=br(this.view).left;let n=this.view.scrollDOM.getBoundingClientRect(),r=ws(this.view);return{visible:{left:n.left+r.left,top:n.top+r.top,right:n.right-r.right,bottom:n.bottom-r.bottom},parent:this.parent?this.container.getBoundingClientRect():this.view.dom.getBoundingClientRect(),pos:this.manager.tooltips.map((o,l)=>{let a=this.manager.tooltipViews[l];return a.getCoords?a.getCoords(o.pos):this.view.coordsAtPos(o.pos)}),size:this.manager.tooltipViews.map(({dom:o})=>o.getBoundingClientRect()),space:this.view.state.facet(Be).tooltipSpace(this.view),scaleX:s,scaleY:t,makeAbsolute:e,fixedLeft:i}}writeMeasure(s){var t;if(s.makeAbsolute){this.madeAbsolute=!0,this.position="absolute";for(let l of this.manager.tooltipViews)l.dom.style.position="absolute"}let{visible:e,space:i,scaleX:n,scaleY:r}=s,o=[];for(let l=0;l=Math.min(e.bottom,i.bottom)||f.rightMath.min(e.right,i.right)+.1)){c.style.top=Te;continue}let u=a.arrow?h.dom.querySelector(".cm-tooltip-arrow"):null,p=u?7:0,g=d.right-d.left,m=(t=dn.get(h))!==null&&t!==void 0?t:d.bottom-d.top,b=h.offset||gl,w=this.view.textDirection==B.LTR,x=d.width>i.right-i.left?w?i.left:i.right-d.width:w?Math.max(i.left,Math.min(f.left-(u?14:0)+b.x,i.right-g)):Math.min(Math.max(i.left,f.left-g+(u?14:0)-b.x),i.right-g),A=this.above[l];!a.strictSide&&(A?f.top-m-p-b.yi.bottom)&&A==i.bottom-f.bottom>f.top-i.top&&(A=this.above[l]=!A);let k=(A?f.top-i.top:i.bottom-f.bottom)-p;if(kx&&P.topS&&(S=A?P.top-m-2-p:P.bottom+p+2);if(this.position=="absolute"?(c.style.top=(S-s.parent.top)/r+"px",un(c,(x-s.parent.left)/n)):(c.style.top=S/r+"px",un(c,(x-s.fixedLeft)/n)),u){let P=f.left+(w?b.x:-b.x)-(x+14-7);u.style.left=P/n+"px"}h.overlap!==!0&&o.push({left:x,top:S,right:D,bottom:S+m}),c.classList.toggle("cm-tooltip-above",A),c.classList.toggle("cm-tooltip-below",!A),h.positioned&&h.positioned(s.space)}}maybeMeasure(){if(this.manager.tooltips.length&&(this.view.inView&&this.view.requestMeasure(this.measureReq),this.inView!=this.view.inView&&(this.inView=this.view.inView,!this.inView)))for(let s of this.manager.tooltipViews)s.dom.style.top=Te}},{eventObservers:{scroll(){this.maybeMeasure()}}});function un(s,t){let e=parseInt(s.style.left,10);(isNaN(e)||Math.abs(t-e)>1)&&(s.style.left=t+"px")}var pl=M.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:"7px",width:"14px",position:"absolute",zIndex:-1,overflow:"hidden","&:before, &:after":{content:"''",position:"absolute",width:0,height:0,borderLeft:"7px solid transparent",borderRight:"7px solid transparent"},".cm-tooltip-above &":{bottom:"-7px","&:before":{borderTop:"7px solid #bbb"},"&:after":{borderTop:"7px solid #f5f5f5",bottom:"1px"}},".cm-tooltip-below &":{top:"-7px","&:before":{borderBottom:"7px solid #bbb"},"&:after":{borderBottom:"7px solid #f5f5f5",top:"1px"}}},"&dark .cm-tooltip .cm-tooltip-arrow":{"&:before":{borderTopColor:"#333338",borderBottomColor:"#333338"},"&:after":{borderTopColor:"transparent",borderBottomColor:"transparent"}}}),gl={x:0,y:0},yr=C.define({enables:[ii,pl]}),he=C.define({combine:s=>s.reduce((t,e)=>t.concat(e),[])}),Ge=class s{static create(t){return new s(t)}constructor(t){this.view=t,this.mounted=!1,this.dom=document.createElement("div"),this.dom.classList.add("cm-tooltip-hover"),this.manager=new $e(t,he,(e,i)=>this.createHostedView(e,i),e=>e.dom.remove())}createHostedView(t,e){let i=t.create(this.view);return i.dom.classList.add("cm-tooltip-section"),this.dom.insertBefore(i.dom,e?e.dom.nextSibling:this.dom.firstChild),this.mounted&&i.mount&&i.mount(this.view),i}mount(t){for(let e of this.manager.tooltipViews)e.mount&&e.mount(t);this.mounted=!0}positioned(t){for(let e of this.manager.tooltipViews)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||t.call(e)}passProp(t){let e;for(let i of this.manager.tooltipViews){let n=i[t];if(n!==void 0){if(e===void 0)e=n;else if(e!==n)return}}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")}},ml=yr.compute([he],s=>{let t=s.facet(he);return t.length===0?null:{pos:Math.min(...t.map(e=>e.pos)),end:Math.max(...t.map(e=>{var i;return(i=e.end)!==null&&i!==void 0?i:e.pos})),create:Ge.create,above:t[0].above,arrow:t.some(e=>e.arrow)}}),wr=C.define(),ls=class{constructor(t,e,i,n,r,o){this.view=t,this.source=e,this.field=i,this.locked=n,this.setHover=r,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(t){this.pending&&(this.pending=null,clearTimeout(this.restartTimeout),this.restartTimeout=setTimeout(()=>this.startHover(),20))}get active(){return this.view.state.field(this.field)}checkHover(){if(this.hoverTimeout=-1,this.active.length)return;let t=Date.now()-this.lastMove.time;to.bottom||e.xo.right+t.defaultCharacterWidth)return;let l=t.bidiSpans(t.state.doc.lineAt(n)).find(h=>h.from<=n&&h.to>=n),a=l&&l.dir==B.RTL?-1:1;r=e.x{if(l&&!(Array.isArray(l)&&!l.length)){let a=Array.isArray(l)?l:[l];n&&this.locked.set(a,n),t.dispatch({effects:this.setHover.of(a)})}};if(r&&"then"in r){let l=this.pending={pos:e};r.then(a=>{this.pending==l&&(this.pending=null,o(a))},a=>Z(t.state,a,"hover tooltip"))}else o(r)}get tooltip(){let t=this.view.plugin(ii),e=t?t.manager.tooltips.findIndex(i=>i.create==Ge.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()},this.hoverTimeout<0&&(this.hoverTimeout=setTimeout(this.checkHover,this.hoverTime));let{active:n,tooltip:r}=this;if(n.length&&!this.locked.has(n)&&r&&!bl(r.dom,t)||this.pending){let{pos:o}=n[0]||this.pending,l=(i=(e=n[0])===null||e===void 0?void 0:e.end)!==null&&i!==void 0?i:o;(o==l?this.view.posAtCoords(this.lastMove)!=o:!yl(this.view,o,l,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&&!this.locked.has(e)){let{tooltip:i}=this;i&&i.dom.contains(t.relatedTarget)?this.watchTooltipLeave(i.dom):this.view.dispatch({effects:this.setHover.of([])})}}watchTooltipLeave(t){let e=i=>{t.removeEventListener("mouseleave",e);let{active:n}=this;n.length&&!this.locked.has(n)&&!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)}},De=4;function bl(s,t){let{left:e,right:i,top:n,bottom:r}=s.getBoundingClientRect(),o;if(o=s.querySelector(".cm-tooltip-arrow")){let l=o.getBoundingClientRect();n=Math.min(l.top,n),r=Math.max(l.bottom,r)}return t.clientX>=e-De&&t.clientX<=i+De&&t.clientY>=n-De&&t.clientY<=r+De}function yl(s,t,e,i,n,r){let o=s.scrollDOM.getBoundingClientRect(),l=s.documentTop+s.documentPadding.top+s.contentHeight;if(o.left>i||o.rightn||Math.min(o.bottom,l)=t&&a<=e}function Zl(s,t={}){let e=U.define(),i=new WeakMap,n=pe.define({create(){return[]},update(o,l){let a=i.get(o);if(o.length&&(t.hideOnChange&&(l.docChanged||l.selection)?o=[]:a&&a(l)?o=[]:t.hideOn&&(o=o.filter(h=>!t.hideOn(l,h)))),l.docChanged&&o.length){let h=[];for(let c of o){let f=l.changes.mapPos(c.pos,-1,wt.TrackDel);if(f!=null){let d=Object.assign(Object.create(null),c);d.pos=f,d.end!=null&&(d.end=l.changes.mapPos(d.end)),h.push(d)}}o=h}for(let h of l.effects)h.is(e)&&(o=h.value,a=void 0),(h.is(vs)&&!h.value||h.value==n)&&(o=[]);return o.length&&a&&i.set(o,a),o},provide:o=>he.from(o)}),r=V.define(o=>new ls(o,s,n,i,e,t.hoverTime||300));return{active:n,extension:[n,r,wr.of(r),ml]}}function ta(s,t,e,i={}){var n;let r=s.state.facet(wr).map(o=>s.plugin(o)).filter(o=>!!o);if(i.tooltip&&i.tooltip.active){let o=r.find(l=>l.field==i.tooltip.active);o&&(r=[o])}for(let o of r)o.activateHover(s,t,e,(n=i.until)!==null&&n!==void 0?n:(()=>!1))}function ea(s,t){let e=s.plugin(ii);if(!e)return null;let i=e.manager.tooltips.indexOf(t);return i<0?null:e.manager.tooltipViews[i]}function ia(s){return s.facet(he).some(t=>t)}var vs=U.define(),sa=vs.of(null);function na(s){return vs.of(s.active)}function ra(s){let t=s.plugin(ii);t&&t.maybeMeasure()}var as=C.define({combine(s){let t,e;for(let i of s)t=t||i.topContainer,e=e||i.bottomContainer;return{topContainer:t,bottomContainer:e}}});function oa(s){return s?[as.of(s)]:[]}function wl(s,t){let e=s.plugin(xr),i=e?e.specs.indexOf(t):-1;return i>-1?e.panels[i]:null}var xr=V.fromClass(class{constructor(s){this.input=s.state.facet(hs),this.specs=this.input.filter(e=>e),this.panels=this.specs.map(e=>e(s));let t=s.state.facet(as);this.top=new Ht(s,!0,t.topContainer),this.bottom=new Ht(s,!1,t.bottomContainer),this.top.sync(this.panels.filter(e=>e.top)),this.bottom.sync(this.panels.filter(e=>!e.top));for(let e of this.panels)e.dom.classList.add("cm-panel"),e.mount&&e.mount()}update(s){let t=s.state.facet(as);this.top.container!=t.topContainer&&(this.top.sync([]),this.top=new Ht(s.view,!0,t.topContainer)),this.bottom.container!=t.bottomContainer&&(this.bottom.sync([]),this.bottom=new Ht(s.view,!1,t.bottomContainer)),this.top.syncClasses(),this.bottom.syncClasses();let e=s.state.facet(hs);if(e!=this.input){let i=e.filter(a=>a),n=[],r=[],o=[],l=[];for(let a of i){let h=this.specs.indexOf(a),c;h<0?(c=a(s.view),l.push(c)):(c=this.panels[h],c.update&&c.update(s)),n.push(c),(c.top?r:o).push(c)}this.specs=i,this.panels=n,this.top.sync(r),this.bottom.sync(o);for(let a of l)a.dom.classList.add("cm-panel"),a.mount&&a.mount()}else for(let i of this.panels)i.update&&i.update(s)}destroy(){this.top.sync([]),this.bottom.sync([])}},{provide:s=>M.scrollMargins.of(t=>{let e=t.plugin(s);return e&&{top:e.top.scrollMargin(),bottom:e.bottom.scrollMargin()}})}),Ht=class{constructor(t,e,i){this.view=t,this.top=e,this.container=i,this.dom=void 0,this.classes="",this.panels=[],this.syncClasses()}sync(t){for(let e of this.panels)e.destroy&&t.indexOf(e)<0&&e.destroy();this.panels=t,this.syncDOM()}syncDOM(){if(this.panels.length==0){this.dom&&(this.dom.remove(),this.dom=void 0);return}if(!this.dom){this.dom=document.createElement("div"),this.dom.className=this.top?"cm-panels cm-panels-top":"cm-panels cm-panels-bottom";let e=this.container||this.view.dom;e.insertBefore(this.dom,this.top?e.firstChild:null)}let t=this.dom.firstChild;for(let e of this.panels)if(e.dom.parentNode==this.dom){for(;t!=e.dom;)t=pn(t);t=t.nextSibling}else this.dom.insertBefore(e.dom,t);for(;t;)t=pn(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)){for(let t of this.classes.split(" "))t&&this.container.classList.remove(t);for(let t of(this.classes=this.view.themeClasses).split(" "))t&&this.container.classList.add(t)}}};function pn(s){let t=s.nextSibling;return s.remove(),t}var hs=C.define({enables:xr});function la(s,t){let e,i=new Promise(o=>e=o),n=o=>xl(o,t,e);s.state.field(Ee,!1)?s.dispatch({effects:vr.of(n)}):s.dispatch({effects:U.appendConfig.of(Ee.init(()=>[n]))});let r=Sr.of(n);return{close:r,result:i.then(o=>((s.win.queueMicrotask||(a=>s.win.setTimeout(a,10)))(()=>{s.state.field(Ee).indexOf(n)>-1&&s.dispatch({effects:r})}),o))}}function aa(s,t){let e=s.state.field(Ee,!1)||[];for(let i of e){let n=wl(s,i);if(n&&n.dom.classList.contains(t))return n}return null}var Ee=pe.define({create(){return[]},update(s,t){for(let e of t.effects)e.is(vr)?s=[e.value].concat(s):e.is(Sr)&&(s=s.filter(i=>i!=e.value));return s},provide:s=>hs.computeN([s],t=>t.field(s))}),vr=U.define(),Sr=U.define();function xl(s,t,e){let i=t.content?t.content(s,()=>o(null)):null;if(!i){if(i=dt("form"),t.input){let l=dt("input",t.input);/^(text|password|number|email|tel|url)$/.test(l.type)&&l.classList.add("cm-textfield"),l.name||(l.name="input"),i.appendChild(dt("label",(t.label||"")+": ",l))}else i.appendChild(document.createTextNode(t.label||""));i.appendChild(document.createTextNode(" ")),i.appendChild(dt("button",{class:"cm-button",type:"submit"},t.submitLabel||"OK"))}let n=i.nodeName=="FORM"?[i]:i.querySelectorAll("form");for(let l=0;l{h.keyCode==27?(h.preventDefault(),o(null)):h.keyCode==13&&(h.preventDefault(),o(a))}),a.addEventListener("submit",h=>{h.preventDefault(),o(a)})}let r=dt("div",i,dt("button",{onclick:()=>o(null),"aria-label":s.state.phrase("close"),class:"cm-dialog-close",type:"button"},["\xD7"]));t.class&&(r.className=t.class),r.classList.add("cm-dialog");function o(l){r.contains(r.ownerDocument.activeElement)&&s.focus(),e(l)}return{dom:r,top:t.top,mount:()=>{if(t.focus){let l;typeof t.focus=="string"?l=i.querySelector(t.focus):l=i.querySelector("input")||i.querySelector("button"),l&&"select"in l?l.select():l&&"focus"in l&&l.focus()}}}}var tt=class extends be{compare(t){return this==t||this.constructor==t.constructor&&this.eq(t)}eq(t){return!1}destroy(t){}};tt.prototype.elementClass="";tt.prototype.toDOM=void 0;tt.prototype.mapMode=wt.TrackBefore;tt.prototype.startSide=tt.prototype.endSide=-1;tt.prototype.point=!0;var He=C.define(),vl=C.define(),Sl={class:"",renderEmptyElements:!1,elementStyle:"",markers:()=>E.empty,lineMarker:()=>null,widgetMarker:()=>null,lineMarkerChange:null,initialSpacer:null,updateSpacer:null,domEventHandlers:{},side:"before"},ee=C.define();function ha(s){return[Cr(),ee.of({...Sl,...s})]}var cs=C.define({combine:s=>s.some(t=>t)});function Cr(s){let t=[Cl];return s&&s.fixed===!1&&t.push(cs.of(!0)),t}var Cl=V.fromClass(class{constructor(s){this.view=s,this.domAfter=null,this.prevViewport=s.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=s.state.facet(ee).map(t=>new Ue(s,t)),this.fixed=!s.state.facet(cs);for(let t of this.gutters)t.config.side=="after"?this.getDOMAfter().appendChild(t.dom):this.dom.appendChild(t.dom);this.fixed&&(this.dom.style.position="sticky"),this.syncGutters(!1),s.scrollDOM.insertBefore(this.dom,s.contentDOM)}getDOMAfter(){return 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)),this.domAfter}update(s){if(this.updateGutters(s)){let t=this.prevViewport,e=s.view.viewport,i=Math.min(t.to,e.to)-Math.max(t.from,e.from);this.syncGutters(i<(e.to-e.from)*.8)}if(s.geometryChanged){let t=this.view.contentHeight/this.view.scaleY+"px";this.dom.style.minHeight=t,this.domAfter&&(this.domAfter.style.minHeight=t)}this.view.state.facet(cs)!=!this.fixed&&(this.fixed=!this.fixed,this.dom.style.position=this.fixed?"sticky":"",this.domAfter&&(this.domAfter.style.position=this.fixed?"sticky":"")),this.prevViewport=s.view.viewport}syncGutters(s){let t=this.dom.nextSibling;s&&(this.dom.remove(),this.domAfter&&this.domAfter.remove());let e=E.iter(this.view.state.facet(He),this.view.viewport.from),i=[],n=this.gutters.map(r=>new ds(r,this.view.viewport,-this.view.documentPadding.top));for(let r of this.view.viewportLineBlocks)if(i.length&&(i=[]),Array.isArray(r.type)){let o=!0;for(let l of r.type)if(l.type==W.Text&&o){fs(e,i,l.from);for(let a of n)a.line(this.view,l,i);o=!1}else if(l.widget)for(let a of n)a.widget(this.view,l)}else if(r.type==W.Text){fs(e,i,r.from);for(let o of n)o.line(this.view,r,i)}else if(r.widget)for(let o of n)o.widget(this.view,r);for(let r of n)r.finish();s&&(this.view.scrollDOM.insertBefore(this.dom,t),this.domAfter&&this.view.scrollDOM.appendChild(this.domAfter))}updateGutters(s){let t=s.startState.facet(ee),e=s.state.facet(ee),i=s.docChanged||s.heightChanged||s.viewportChanged||!E.eq(s.startState.facet(He),s.state.facet(He),s.view.viewport.from,s.view.viewport.to);if(t==e)for(let n of this.gutters)n.update(s)&&(i=!0);else{i=!0;let n=[];for(let r of e){let o=t.indexOf(r);o<0?n.push(new Ue(this.view,r)):(this.gutters[o].update(s),n.push(this.gutters[o]))}for(let r of this.gutters)r.dom.remove(),n.indexOf(r)<0&&r.destroy();for(let r of n)r.config.side=="after"?this.getDOMAfter().appendChild(r.dom):this.dom.appendChild(r.dom);this.gutters=n}return i}destroy(){for(let s of this.gutters)s.destroy();this.dom.remove(),this.domAfter&&this.domAfter.remove()}},{provide:s=>M.scrollMargins.of(t=>{let e=t.plugin(s);if(!e||e.gutters.length==0||!e.fixed)return null;let i=e.dom.offsetWidth*t.scaleX,n=e.domAfter?e.domAfter.offsetWidth*t.scaleX:0;return t.textDirection==B.LTR?{left:i,right:n}:{right:i,left:n}})});function gn(s){return Array.isArray(s)?s:[s]}function fs(s,t,e){for(;s.value&&s.from<=e;)s.from==e&&t.push(s.value),s.next()}var ds=class{constructor(t,e,i){this.gutter=t,this.height=i,this.i=0,this.cursor=E.iter(t.markers,e.from)}addElement(t,e,i){let{gutter:n}=this,r=(e.top-this.height)/t.scaleY,o=e.height/t.scaleY;if(this.i==n.elements.length){let l=new Qe(t,o,r,i);n.elements.push(l),n.dom.appendChild(l.dom)}else n.elements[this.i].update(t,o,r,i);this.height=e.bottom,this.i++}line(t,e,i){let n=[];fs(this.cursor,n,e.from),i.length&&(n=n.concat(i));let r=this.gutter.config.lineMarker(t,e,n);r&&n.unshift(r);let o=this.gutter;n.length==0&&!o.config.renderEmptyElements||this.addElement(t,e,n)}widget(t,e){let i=this.gutter.config.widgetMarker(t,e.widget,e),n=i?[i]:null;for(let r of t.state.facet(vl)){let o=r(t,e.widget,e);o&&(n||(n=[])).push(o)}n&&this.addElement(t,e,n)}finish(){let t=this.gutter;for(;t.elements.length>this.i;){let e=t.elements.pop();t.dom.removeChild(e.dom),e.destroy()}}},Ue=class{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,n=>{let r=n.target,o;if(r!=this.dom&&this.dom.contains(r)){for(;r.parentNode!=this.dom;)r=r.parentNode;let a=r.getBoundingClientRect();o=(a.top+a.bottom)/2}else o=n.clientY;let l=t.lineBlockAtHeight(o-t.documentTop);e.domEventHandlers[i](t,l,n)&&n.preventDefault()});this.markers=gn(e.markers(t)),e.initialSpacer&&(this.spacer=new Qe(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;if(this.markers=gn(this.config.markers(t.view)),this.spacer&&this.config.updateSpacer){let n=this.config.updateSpacer(this.spacer.markers[0],t);n!=this.spacer.markers[0]&&this.spacer.update(t.view,0,0,[n])}let i=t.view.viewport;return!E.eq(this.markers,e,i.from,i.to)||(this.config.lineMarkerChange?this.config.lineMarkerChange(t):!1)}destroy(){for(let t of this.elements)t.destroy()}},Qe=class{constructor(t,e,i,n){this.height=-1,this.above=0,this.markers=[],this.dom=document.createElement("div"),this.dom.className="cm-gutterElement",this.update(t,e,i,n)}update(t,e,i,n){this.height!=e&&(this.height=e,this.dom.style.height=e+"px"),this.above!=i&&(this.dom.style.marginTop=(this.above=i)?i+"px":""),kl(this.markers,n)||this.setMarkers(t,n)}setMarkers(t,e){let i="cm-gutterElement",n=this.dom.firstChild;for(let r=0,o=0;;){let l=o,a=rr(l,a,h)||o(l,a,h):o}return i}})}}),ie=class extends tt{constructor(t){super(),this.number=t}eq(t){return this.number==t.number}toDOM(){return document.createTextNode(this.number)}};function pi(s,t){return s.state.facet(Pt).formatNumber(t,s.state)}var Tl=ee.compute([Pt],s=>({class:"cm-lineNumbers",renderEmptyElements:!1,markers(t){return t.state.facet(Ml)},lineMarker(t,e,i){return i.some(n=>n.toDOM)?null:new ie(pi(t,t.state.doc.lineAt(e.from).number))},widgetMarker:(t,e,i)=>{for(let n of t.state.facet(Al)){let r=n(t,e,i);if(r)return r}return null},lineMarkerChange:t=>t.startState.facet(Pt)!=t.state.facet(Pt),initialSpacer(t){return new ie(pi(t,mn(t.state.doc.lines)))},updateSpacer(t,e){let i=pi(e.view,mn(e.view.state.doc.lines));return i==t.number?t:new ie(i)},domEventHandlers:s.facet(Pt).domEventHandlers,side:"before"}));function ca(s={}){return[Pt.of(s),Cr(),Tl]}function mn(s){let t=9;for(;t{let t=[],e=-1;for(let i of s.selection.ranges){let n=s.doc.lineAt(i.head).from;n>e&&(e=n,t.push(Dl.range(n)))}return E.of(t)});function fa(){return Ol}function kr(s){return V.define(t=>({decorations:s.createDeco(t),update(e){this.decorations=s.updateDeco(e,this.decorations)}}),{decorations:t=>t.decorations})}var Rl=T.mark({class:"cm-highlightTab"}),Ll=T.mark({class:"cm-highlightSpace"}),Bl=kr(new ae({regexp:/\t| /g,decoration:s=>s[0]==" "?Rl:Ll,boundary:/\S/}));function da(){return Bl}var El=kr(new ae({regexp:/\s+$/g,decoration:T.mark({class:"cm-trailingSpace"})}));function ua(){return El}var pa={HeightMap:K,HeightOracle:Ke,MeasuredHeights:qe,QueryType:O,ChangedRange:X,computeOrder:Rn,moveVisually:En,clearHeightChangeFlag:Ki,getHeightChangeFlag:()=>At};export{st as a,lt as b,W as c,T as d,Ne as e,B as f,Y as g,Z as h,V as i,Ve as j,$ as k,M as l,qo as m,Kl as n,St as o,pr as p,ql as q,_l as r,jl as s,ae as t,Yl as u,Xl as v,$l as w,Gl as x,Ul as y,Ql as z,Jl as A,yr as B,Zl as C,ta as D,ea as E,ia as F,sa as G,na as H,ra as I,oa as J,wl as K,hs as L,la as M,aa as N,tt as O,He as P,vl as Q,ha as R,Cr as S,Ml as T,Al as U,ca as V,fa as W,da as X,ua as Y,pa as Z}; -- cgit