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