CoreFiles by mySites.guru
codemirror-view.min.js6 lines, 173,278 bytes, from Joomla_5.0.3-Stable-Full_Package.zip
Raw History Compare with 5.0.2
md5
5e107b6e7f96e4e44128bc736f9ec31d
sha1
b1a8d29e891f25f23562278e633f99000f960ed4
sha256
0c82b7b88353a26aec8a54e5379dfc2a2ee201bc824521aebcfca80d91fd1b44
import{RangeSet as F,MapMode as gt,EditorSelection as v,RangeValue as ui,Facet as C,ChangeSet as pi,EditorState as At,Transaction as On,Prec as ye,StateEffect as Dt,codePointAt as gi,codePointSize as Tn,RangeSetBuilder as Rn,countColumn as mi,StateField as bi,findClusterBreak as mt,findColumn as we,Annotation as Bn,Text as G,combineConfig as Se,CharCategory as Ln}from"@codemirror/state";const xe="\u037C",yi=typeof Symbol>"u"?"__"+xe:Symbol.for(xe),ve=typeof Symbol>"u"?"__styleSet"+Math.floor(Math.random()*1e8):Symbol("styleSet"),wi=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{};class bt{constructor(t,e){this.rules=[];let{finish:i}=e||{};function s(o){return/^@/.test(o)?[o]:o.split(/,\s*/)}function r(o,l,h,c){let a=[],d=/^@(\w+)\b/.exec(o[0]),f=d&&d[1]=="keyframes";if(d&&l==null)return h.push(o[0]+";");for(let u in l){let p=l[u];if(/&/.test(u))r(u.split(/,\s*/).map(g=>o.map(m=>g.replace(/&/,m))).reduce((g,m)=>g.concat(m)),p,h);else if(p&&typeof p=="object"){if(!d)throw new RangeError("The value of a property ("+u+") should be a primitive value.");r(s(u),p,a,f)}else p!=null&&a.push(u.replace(/_.*/,"").replace(/[A-Z]/g,g=>"-"+g.toLowerCase())+": "+p+";")}(a.length||f)&&h.push((i&&!d&&!c?o.map(i):o).join(", ")+" {"+a.join(" ")+"}")}for(let o in t)r(s(o),t[o],this.rules)}getRules(){return this.rules.join(`
`)}static newName(){let t=wi[yi]||1;return wi[yi]=t+1,xe+t.toString(36)}static mount(t,e,i){let s=t[ve],r=i&&i.nonce;s?r&&s.setNonce(r):s=new En(t,r),s.mount(Array.isArray(e)?e:[e])}}let Si=new Map;class En{constructor(t,e){let i=t.ownerDocument||t,s=i.defaultView;if(!t.head&&t.adoptedStyleSheets&&s.CSSStyleSheet){let r=Si.get(i);if(r)return t.adoptedStyleSheets=[r.sheet,...t.adoptedStyleSheets],t[ve]=r;this.sheet=new s.CSSStyleSheet,t.adoptedStyleSheets=[this.sheet,...t.adoptedStyleSheets],Si.set(i,this)}else{this.styleTag=i.createElement("style"),e&&this.styleTag.setAttribute("nonce",e);let r=t.head||t;r.insertBefore(this.styleTag,r.firstChild)}this.modules=[],t[ve]=this}mount(t){let e=this.sheet,i=0,s=0;for(let r=0;r<t.length;r++){let o=t[r],l=this.modules.indexOf(o);if(l<s&&l>-1&&(this.modules.splice(l,1),s--,l=-1),l==-1){if(this.modules.splice(s++,0,o),e)for(let h=0;h<o.rules.length;h++)e.insertRule(o.rules[h],i++)}else{for(;s<l;)i+=this.modules[s++].rules.length;i+=o.rules.length,s++}}if(!e){let r="";for(let o=0;o<this.modules.length;o++)r+=this.modules[o].getRules()+`
`;this.styleTag.textContent=r}}setNonce(t){this.styleTag&&this.styleTag.getAttribute("nonce")!=t&&this.styleTag.setAttribute("nonce",t)}}for(var nt={8:"Backspace",9:"Tab",10:"Enter",12:"NumLock",13:"Enter",16:"Shift",17:"Control",18:"Alt",20:"CapsLock",27:"Escape",32:" ",33:"PageUp",34:"PageDown",35:"End",36:"Home",37:"ArrowLeft",38:"ArrowUp",39:"ArrowRight",40:"ArrowDown",44:"PrintScreen",45:"Insert",46:"Delete",59:";",61:"=",91:"Meta",92:"Meta",106:"*",107:"+",108:",",109:"-",110:".",111:"/",144:"NumLock",145:"ScrollLock",160:"Shift",161:"Shift",162:"Control",163:"Control",164:"Alt",165:"Alt",173:"-",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"},Ot={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},Pn=typeof navigator<"u"&&/Mac/.test(navigator.platform),Hn=typeof navigator<"u"&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent),N=0;N<10;N++)nt[48+N]=nt[96+N]=String(N);for(var N=1;N<=24;N++)nt[N+111]="F"+N;for(var N=65;N<=90;N++)nt[N]=String.fromCharCode(N+32),Ot[N]=String.fromCharCode(N);for(var Me in nt)Ot.hasOwnProperty(Me)||(Ot[Me]=nt[Me]);function Nn(n){var t=Pn&&n.metaKey&&n.shiftKey&&!n.ctrlKey&&!n.altKey||Hn&&n.shiftKey&&n.key&&n.key.length==1||n.key=="Unidentified",e=!t&&n.key||(n.shiftKey?Ot:nt)[n.keyCode]||n.key||"Unidentified";return e=="Esc"&&(e="Escape"),e=="Del"&&(e="Delete"),e=="Left"&&(e="ArrowLeft"),e=="Up"&&(e="ArrowUp"),e=="Right"&&(e="ArrowRight"),e=="Down"&&(e="ArrowDown"),e}function Gt(n){let t;return n.nodeType==11?t=n.getSelection?n:n.ownerDocument:t=n,t.getSelection()}function Ce(n,t){return t?n==t||n.contains(t.nodeType!=1?t.parentNode:t):!1}function Vn(n){let t=n.activeElement;for(;t&&t.shadowRoot;)t=t.shadowRoot.activeElement;return t}function $t(n,t){if(!t.anchorNode)return!1;try{return Ce(n,t.anchorNode)}catch{return!1}}function yt(n){return n.nodeType==3?ft(n,0,n.nodeValue.length).getClientRects():n.nodeType==1?n.getClientRects():[]}function Ut(n,t,e,i){return e?xi(n,t,e,i,-1)||xi(n,t,e,i,1):!1}function Yt(n){for(var t=0;;t++)if(n=n.previousSibling,!n)return t}function xi(n,t,e,i,s){for(;;){if(n==e&&t==i)return!0;if(t==(s<0?0:rt(n))){if(n.nodeName=="DIV")return!1;let r=n.parentNode;if(!r||r.nodeType!=1)return!1;t=Yt(n)+(s<0?0:1),n=r}else if(n.nodeType==1){if(n=n.childNodes[t+(s<0?-1:0)],n.nodeType==1&&n.contentEditable=="false")return!1;t=s<0?rt(n):0}else return!1}}function rt(n){return n.nodeType==3?n.nodeValue.length:n.childNodes.length}function Xt(n,t){let e=t?n.left:n.right;return{left:e,right:e,top:n.top,bottom:n.bottom}}function Wn(n){return{left:0,right:n.innerWidth,top:0,bottom:n.innerHeight}}function Fn(n,t,e,i,s,r,o,l){let h=n.ownerDocument,c=h.defaultView||window;for(let a=n,d=!1;a&&!d;)if(a.nodeType==1){let f,u=a==h.body;if(u)f=Wn(c);else{if(/^(fixed|sticky)$/.test(getComputedStyle(a).position)&&(d=!0),a.scrollHeight<=a.clientHeight&&a.scrollWidth<=a.clientWidth){a=a.assignedSlot||a.parentNode;continue}let m=a.getBoundingClientRect();f={left:m.left,right:m.left+a.clientWidth,top:m.top,bottom:m.top+a.clientHeight}}let p=0,g=0;if(s=="nearest")t.top<f.top?(g=-(f.top-t.top+o),e>0&&t.bottom>f.bottom+g&&(g=t.bottom-f.bottom+g+o)):t.bottom>f.bottom&&(g=t.bottom-f.bottom+o,e<0&&t.top-g<f.top&&(g=-(f.top+g-t.top+o)));else{let m=t.bottom-t.top,b=f.bottom-f.top;g=(s=="center"&&m<=b?t.top+m/2-b/2:s=="start"||s=="center"&&e<0?t.top-o:t.bottom-b+o)-f.top}if(i=="nearest"?t.left<f.left?(p=-(f.left-t.left+r),e>0&&t.right>f.right+p&&(p=t.right-f.right+p+r)):t.right>f.right&&(p=t.right-f.right+r,e<0&&t.left<f.left+p&&(p=-(f.left+p-t.left+r))):p=(i=="center"?t.left+(t.right-t.left)/2-(f.right-f.left)/2:i=="start"==l?t.left-r:t.right-(f.right-f.left)+r)-f.left,p||g)if(u)c.scrollBy(p,g);else{let m=0,b=0;if(g){let S=a.scrollTop;a.scrollTop+=g,b=a.scrollTop-S}if(p){let S=a.scrollLeft;a.scrollLeft+=p,m=a.scrollLeft-S}t={left:t.left-m,top:t.top-b,right:t.right-m,bottom:t.bottom-b},m&&Math.abs(m-p)<1&&(i="nearest"),b&&Math.abs(b-g)<1&&(s="nearest")}if(u)break;a=a.assignedSlot||a.parentNode}else if(a.nodeType==11)a=a.host;else break}function zn(n){let t=n.ownerDocument;for(let e=n.parentNode;e&&e!=t.body;)if(e.nodeType==1){if(e.scrollHeight>e.clientHeight||e.scrollWidth>e.clientWidth)return e;e=e.assignedSlot||e.parentNode}else if(e.nodeType==11)e=e.host;else break;return null}class In{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?rt(e):0),i,Math.min(t.focusOffset,i?rt(i):0))}set(t,e,i,s){this.anchorNode=t,this.anchorOffset=e,this.focusNode=i,this.focusOffset=s}}let wt=null;function vi(n){if(n.setActive)return n.setActive();if(wt)return n.focus(wt);let t=[];for(let e=n;e&&(t.push(e,e.scrollTop,e.scrollLeft),e!=e.ownerDocument);e=e.parentNode);if(n.focus(wt==null?{get preventScroll(){return wt={preventScroll:!0},!0}}:void 0),!wt){wt=!1;for(let e=0;e<t.length;){let i=t[e++],s=t[e++],r=t[e++];i.scrollTop!=s&&(i.scrollTop=s),i.scrollLeft!=r&&(i.scrollLeft=r)}}}let Mi;function ft(n,t,e=t){let i=Mi||(Mi=document.createRange());return i.setEnd(n,e),i.setStart(n,t),i}function St(n,t,e){let i={key:t,code:t,keyCode:e,which:e,cancelable:!0},s=new KeyboardEvent("keydown",i);s.synthetic=!0,n.dispatchEvent(s);let r=new KeyboardEvent("keyup",i);return r.synthetic=!0,n.dispatchEvent(r),s.defaultPrevented||r.defaultPrevented}function Kn(n){for(;n;){if(n&&(n.nodeType==9||n.nodeType==11&&n.host))return n;n=n.assignedSlot||n.parentNode}return null}function Ci(n){for(;n.attributes.length;)n.removeAttributeNode(n.attributes[0])}function qn(n,t){let e=t.focusNode,i=t.focusOffset;if(!e||t.anchorNode!=e||t.anchorOffset!=i)return!1;for(i=Math.min(i,rt(e));;)if(i){if(e.nodeType!=1)return!1;let s=e.childNodes[i-1];s.contentEditable=="false"?i--:(e=s,i=rt(e))}else{if(e==n)return!0;i=Yt(e),e=e.parentNode}}function ki(n){return n.scrollTop>Math.max(1,n.scrollHeight-n.clientHeight-4)}class z{constructor(t,e,i=!0){this.node=t,this.offset=e,this.precise=i}static before(t,e){return new z(t.parentNode,Yt(t),e)}static after(t,e){return new z(t.parentNode,Yt(t)+1,e)}}const ke=[];class T{constructor(){this.parent=null,this.dom=null,this.flags=2}get overrideDOMText(){return null}get posAtStart(){return this.parent?this.parent.posBefore(this):0}get posAtEnd(){return this.posAtStart+this.length}posBefore(t){let e=this.posAtStart;for(let i of this.children){if(i==t)return e;e+=i.length+i.breakAfter}throw new RangeError("Invalid child in posBefore")}posAfter(t){return this.posBefore(t)+t.length}sync(t,e){if(this.flags&2){let i=this.dom,s=null,r;for(let o of this.children){if(o.flags&7){if(!o.dom&&(r=s?s.nextSibling:i.firstChild)){let l=T.get(r);(!l||!l.parent&&l.canReuseDOM(o))&&o.reuseDOM(r)}o.sync(t,e),o.flags&=-8}if(r=s?s.nextSibling:i.firstChild,e&&!e.written&&e.node==i&&r!=o.dom&&(e.written=!0),o.dom.parentNode==i)for(;r&&r!=o.dom;)r=Ai(r);else i.insertBefore(o.dom,r);s=o.dom}for(r=s?s.nextSibling:i.firstChild,r&&e&&e.node==i&&(e.written=!0);r;)r=Ai(r)}else if(this.flags&1)for(let i of this.children)i.flags&7&&(i.sync(t,e),i.flags&=-8)}reuseDOM(t){}localPosFromDOM(t,e){let i;if(t==this.dom)i=this.dom.childNodes[e];else{let s=rt(t)==0?0:e==0?-1:1;for(;;){let r=t.parentNode;if(r==this.dom)break;s==0&&r.firstChild!=r.lastChild&&(t==r.firstChild?s=-1:s=1),t=r}s<0?i=t:i=t.nextSibling}if(i==this.dom.firstChild)return 0;for(;i&&!T.get(i);)i=i.nextSibling;if(!i)return this.length;for(let s=0,r=0;;s++){let o=this.children[s];if(o.dom==i)return r;r+=o.length+o.breakAfter}}domBoundsAround(t,e,i=0){let s=-1,r=-1,o=-1,l=-1;for(let h=0,c=i,a=i;h<this.children.length;h++){let d=this.children[h],f=c+d.length;if(c<t&&f>e)return d.domBoundsAround(t,e,c);if(f>=t&&s==-1&&(s=h,r=c),c>e&&d.dom.parentNode==this.dom){o=h,l=a;break}a=f,c=f+d.breakAfter}return{from:r,to:l<0?i+this.length:l,startDOM:(s?this.children[s-1].dom.nextSibling:null)||this.dom.firstChild,endDOM:o<this.children.length&&o>=0?this.children[o].dom:null}}markDirty(t=!1){this.flags|=2,this.markParentsDirty(t)}markParentsDirty(t){for(let e=this.parent;e;e=e.parent){if(t&&(e.flags|=2),e.flags&1)return;e.flags|=1,t=!1}}setParent(t){this.parent!=t&&(this.parent=t,this.flags&7&&this.markParentsDirty(!0))}setDOM(t){this.dom&&(this.dom.cmView=null),this.dom=t,t.cmView=this}get rootView(){for(let t=this;;){let e=t.parent;if(!e)return t;t=e}}replaceChildren(t,e,i=ke){this.markDirty();for(let s=t;s<e;s++){let r=this.children[s];r.parent==this&&r.destroy()}this.children.splice(t,e-t,...i);for(let s=0;s<i.length;s++)i[s].setParent(this)}ignoreMutation(t){return!1}ignoreEvent(t){return!1}childCursor(t=this.length){return new Di(this.children,t,this.children.length)}childPos(t,e=1){return this.childCursor().findPos(t,e)}toString(){let t=this.constructor.name.replace("View","");return t+(this.children.length?"("+this.children.join()+")":this.length?"["+(t=="Text"?this.text:this.length)+"]":"")+(this.breakAfter?"#":"")}static get(t){return t.cmView}get isEditable(){return!0}get isWidget(){return!1}get isHidden(){return!1}merge(t,e,i,s,r,o){return!1}become(t){return!1}canReuseDOM(t){return t.constructor==this.constructor&&!((this.flags|t.flags)&8)}getSide(){return 0}destroy(){this.parent=null}}T.prototype.breakAfter=0;function Ai(n){let t=n.nextSibling;return n.parentNode.removeChild(n),t}class Di{constructor(t,e,i){this.children=t,this.pos=e,this.i=i,this.off=0}findPos(t,e=1){for(;;){if(t>this.pos||t==this.pos&&(e>0||this.i==0||this.children[this.i-1].breakAfter))return this.off=t-this.pos,this;let i=this.children[--this.i];this.pos-=i.length+i.breakAfter}}}function Oi(n,t,e,i,s,r,o,l,h){let{children:c}=n,a=c.length?c[t]:null,d=r.length?r[r.length-1]:null,f=d?d.breakAfter:o;if(!(t==i&&a&&!o&&!f&&r.length<2&&a.merge(e,s,r.length?d:null,e==0,l,h))){if(i<c.length){let u=c[i];u&&s<u.length?(t==i&&(u=u.split(s),s=0),!f&&d&&u.merge(0,s,d,!0,0,h)?r[r.length-1]=u:(s&&u.merge(0,s,null,!1,0,h),r.push(u))):u?.breakAfter&&(d?d.breakAfter=1:o=1),i++}for(a&&(a.breakAfter=o,e>0&&(!o&&r.length&&a.merge(e,a.length,r[0],!1,l,0)?a.breakAfter=r.shift().breakAfter:(e<a.length||a.children.length&&a.children[a.children.length-1].length==0)&&a.merge(e,a.length,null,!1,l,0),t++));t<i&&r.length;)if(c[i-1].become(r[r.length-1]))i--,r.pop(),h=r.length?0:l;else if(c[t].become(r[0]))t++,r.shift(),l=r.length?0:h;else break;!r.length&&t&&i<c.length&&!c[t-1].breakAfter&&c[i].merge(0,0,c[t-1],!1,l,h)&&t--,(t<i||r.length)&&n.replaceChildren(t,i,r)}}function Ti(n,t,e,i,s,r){let o=n.childCursor(),{i:l,off:h}=o.findPos(e,1),{i:c,off:a}=o.findPos(t,-1),d=t-e;for(let f of i)d+=f.length;n.length+=d,Oi(n,c,a,l,h,i,0,s,r)}const xt="\uFFFF";class Ri{constructor(t,e){this.points=t,this.text="",this.lineSeparator=e.facet(At.lineSeparator)}append(t){this.text+=t}lineBreak(){this.text+=xt}readRange(t,e){if(!t)return this;let i=t.parentNode;for(let s=t;;){this.findPointBefore(i,s);let r=this.text.length;this.readNode(s);let o=s.nextSibling;if(o==e)break;let l=T.get(s),h=T.get(o);(l&&h?l.breakAfter:(l?l.breakAfter:Bi(s))||Bi(o)&&(s.nodeName!="BR"||s.cmIgnore)&&this.text.length>r)&&this.lineBreak(),s=o}return this.findPointBefore(i,e),this}readTextNode(t){let e=t.nodeValue;for(let i of this.points)i.node==t&&(i.pos=this.text.length+Math.min(i.offset,e.length));for(let i=0,s=this.lineSeparator?null:/\r\n?|\n/g;;){let r=-1,o=1,l;if(this.lineSeparator?(r=e.indexOf(this.lineSeparator,i),o=this.lineSeparator.length):(l=s.exec(e))&&(r=l.index,o=l[0].length),this.append(e.slice(i,r<0?e.length:r)),r<0)break;if(this.lineBreak(),o>1)for(let h of this.points)h.node==t&&h.pos>this.text.length&&(h.pos-=o-1);i=r+o}}readNode(t){if(t.cmIgnore)return;let e=T.get(t),i=e&&e.overrideDOMText;if(i!=null){this.findPointInside(t,i.length);for(let s=i.iter();!s.next().done;)s.lineBreak?this.lineBreak():this.append(s.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+Math.min(e,i.offset))}}function Bi(n){return n.nodeType==1&&/^(DIV|P|LI|UL|OL|BLOCKQUOTE|DD|DT|H\d|SECTION|PRE)$/.test(n.nodeName)}class Li{constructor(t,e){this.node=t,this.offset=e,this.pos=-1}}let K=typeof navigator<"u"?navigator:{userAgent:"",vendor:"",platform:""},Ae=typeof document<"u"?document:{documentElement:{style:{}}};const De=/Edge\/(\d+)/.exec(K.userAgent),Ei=/MSIE \d/.test(K.userAgent),Oe=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(K.userAgent),Jt=!!(Ei||Oe||De),Pi=!Jt&&/gecko\/(\d+)/i.test(K.userAgent),Te=!Jt&&/Chrome\/(\d+)/.exec(K.userAgent),Hi="webkitFontSmoothing"in Ae.documentElement.style,Ni=!Jt&&/Apple Computer/.test(K.vendor),Vi=Ni&&(/Mobile\/\w+/.test(K.userAgent)||K.maxTouchPoints>2);var y={mac:Vi||/Mac/.test(K.platform),windows:/Win/.test(K.platform),linux:/Linux|X11/.test(K.platform),ie:Jt,ie_version:Ei?Ae.documentMode||6:Oe?+Oe[1]:De?+De[1]:0,gecko:Pi,gecko_version:Pi?+(/Firefox\/(\d+)/.exec(K.userAgent)||[0,0])[1]:0,chrome:!!Te,chrome_version:Te?+Te[1]:0,ios:Vi,android:/Android\b/.test(K.userAgent),webkit:Hi,safari:Ni,webkit_version:Hi?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0,tabSize:Ae.documentElement.style.tabSize!=null?"tab-size":"-moz-tab-size"};const _n=256;class U extends T{constructor(t){super(),this.text=t}get length(){return this.text.length}createDOM(t){this.setDOM(t||document.createTextNode(this.text))}sync(t,e){this.dom||this.createDOM(),this.dom.nodeValue!=this.text&&(e&&e.node==this.dom&&(e.written=!0),this.dom.nodeValue=this.text)}reuseDOM(t){t.nodeType==3&&this.createDOM(t)}merge(t,e,i){return this.flags&8||i&&(!(i instanceof U)||this.length-(e-t)+i.length>_n||i.flags&8)?!1:(this.text=this.text.slice(0,t)+(i?i.text:"")+this.text.slice(e),this.markDirty(),!0)}split(t){let e=new U(this.text.slice(t));return this.text=this.text.slice(0,t),this.markDirty(),e.flags|=this.flags&8,e}localPosFromDOM(t,e){return t==this.dom?e:e?this.text.length:0}domAtPos(t){return new z(this.dom,t)}domBoundsAround(t,e,i){return{from:i,to:i+this.length,startDOM:this.dom,endDOM:this.dom.nextSibling}}coordsAt(t,e){return jn(this.dom,t,e)}}class tt extends T{constructor(t,e=[],i=0){super(),this.mark=t,this.children=e,this.length=i;for(let s of e)s.setParent(this)}setAttrs(t){if(Ci(t),this.mark.class&&(t.className=this.mark.class),this.mark.attrs)for(let e in this.mark.attrs)t.setAttribute(e,this.mark.attrs[e]);return t}canReuseDOM(t){return super.canReuseDOM(t)&&!((this.flags|t.flags)&8)}reuseDOM(t){t.nodeName==this.mark.tagName.toUpperCase()&&(this.setDOM(t),this.flags|=6)}sync(t,e){this.dom?this.flags&4&&this.setAttrs(this.dom):this.setDOM(this.setAttrs(document.createElement(this.mark.tagName))),super.sync(t,e)}merge(t,e,i,s,r,o){return i&&(!(i instanceof tt&&i.mark.eq(this.mark))||t&&r<=0||e<this.length&&o<=0)?!1:(Ti(this,t,e,i?i.children:[],r-1,o-1),this.markDirty(),!0)}split(t){let e=[],i=0,s=-1,r=0;for(let l of this.children){let h=i+l.length;h>t&&e.push(i<t?l.split(t-i):l),s<0&&i>=t&&(s=r),i=h,r++}let o=this.length-t;return this.length=t,s>-1&&(this.children.length=s,this.markDirty()),new tt(this.mark,e,o)}domAtPos(t){return Wi(this,t)}coordsAt(t,e){return zi(this,t,e)}}function jn(n,t,e){let i=n.nodeValue.length;t>i&&(t=i);let s=t,r=t,o=0;t==0&&e<0||t==i&&e>=0?y.chrome||y.gecko||(t?(s--,o=1):r<i&&(r++,o=-1)):e<0?s--:r<i&&r++;let l=ft(n,s,r).getClientRects();if(!l.length)return null;let h=l[(o?o<0:e>=0)?0:l.length-1];return y.safari&&!o&&h.width==0&&(h=Array.prototype.find.call(l,c=>c.width)||h),o?Xt(h,o<0):h||null}class ht extends T{static create(t,e,i){return new ht(t,e,i)}constructor(t,e,i){super(),this.widget=t,this.length=e,this.side=i,this.prevWidget=null}split(t){let e=ht.create(this.widget,this.length-t,this.side);return this.length-=t,e}sync(t){(!this.dom||!this.widget.updateDOM(this.dom,t))&&(this.dom&&this.prevWidget&&this.prevWidget.destroy(this.dom),this.prevWidget=null,this.setDOM(this.widget.toDOM(t)),this.dom.contentEditable="false")}getSide(){return this.side}merge(t,e,i,s,r,o){return i&&(!(i instanceof ht)||!this.widget.compare(i.widget)||t>0&&r<=0||e<this.length&&o<=0)?!1:(this.length=t+(i?i.length:0)+(this.length-e),!0)}become(t){return t instanceof ht&&t.side==this.side&&this.widget.constructor==t.widget.constructor?(this.widget.compare(t.widget)||this.markDirty(!0),this.dom&&!this.prevWidget&&(this.prevWidget=this.widget),this.widget=t.widget,this.length=t.length,!0):!1}ignoreMutation(){return!0}ignoreEvent(t){return this.widget.ignoreEvent(t)}get overrideDOMText(){if(this.length==0)return G.empty;let t=this;for(;t.parent;)t=t.parent;let{view:e}=t,i=e&&e.state.doc,s=this.posAtStart;return i?i.slice(s,s+this.length):G.empty}domAtPos(t){return(this.length?t==0:this.side>0)?z.before(this.dom):z.after(this.dom,t==this.length)}domBoundsAround(){return null}coordsAt(t,e){let i=this.widget.coordsAt(this.dom,t,e);if(i)return i;let s=this.dom.getClientRects(),r=null;if(!s.length)return null;let o=this.side?this.side<0:t>0;for(let l=o?s.length-1:0;r=s[l],!(t>0?l==0:l==s.length-1||r.top<r.bottom);l+=o?-1:1);return Xt(r,!o)}get isEditable(){return!1}get isWidget(){return!0}get isHidden(){return this.widget.isHidden}destroy(){super.destroy(),this.dom&&this.widget.destroy(this.dom)}}class Ct extends T{constructor(t){super(),this.side=t}get length(){return 0}merge(){return!1}become(t){return t instanceof Ct&&t.side==this.side}split(){return new Ct(this.side)}sync(){if(!this.dom){let t=document.createElement("img");t.className="cm-widgetBuffer",t.setAttribute("aria-hidden","true"),this.setDOM(t)}}getSide(){return this.side}domAtPos(t){return this.side>0?z.before(this.dom):z.after(this.dom)}localPosFromDOM(){return 0}domBoundsAround(){return null}coordsAt(t){return this.dom.getBoundingClientRect()}get overrideDOMText(){return G.empty}get isHidden(){return!0}}U.prototype.children=ht.prototype.children=Ct.prototype.children=ke;function Wi(n,t){let e=n.dom,{children:i}=n,s=0;for(let r=0;s<i.length;s++){let o=i[s],l=r+o.length;if(!(l==r&&o.getSide()<=0)){if(t>r&&t<l&&o.dom.parentNode==e)return o.domAtPos(t-r);if(t<=r)break;r=l}}for(let r=s;r>0;r--){let o=i[r-1];if(o.dom.parentNode==e)return o.domAtPos(o.length)}for(let r=s;r<i.length;r++){let o=i[r];if(o.dom.parentNode==e)return o.domAtPos(0)}return new z(e,0)}function Fi(n,t,e){let i,{children:s}=n;e>0&&t instanceof tt&&s.length&&(i=s[s.length-1])instanceof tt&&i.mark.eq(t.mark)?Fi(i,t.children[0],e-1):(s.push(t),t.setParent(n)),n.length+=t.length}function zi(n,t,e){let i=null,s=-1,r=null,o=-1;function l(c,a){for(let d=0,f=0;d<c.children.length&&f<=a;d++){let u=c.children[d],p=f+u.length;p>=a&&(u.children.length?l(u,a-f):(!r||r.isHidden&&e>0)&&(p>a||f==p&&u.getSide()>0)?(r=u,o=a-f):(f<a||f==p&&u.getSide()<0&&!u.isHidden)&&(i=u,s=a-f)),f=p}}l(n,t);let h=(e<0?i:r)||i||r;return h?h.coordsAt(Math.max(0,h==i?s:o),e):Gn(n)}function Gn(n){let t=n.dom.lastChild;if(!t)return n.dom.getBoundingClientRect();let e=yt(t);return e[e.length-1]||null}function Re(n,t){for(let e in n)e=="class"&&t.class?t.class+=" "+n.class:e=="style"&&t.style?t.style+=";"+n.style:t[e]=n[e];return t}const Ii=Object.create(null);function Be(n,t,e){if(n==t)return!0;n||(n=Ii),t||(t=Ii);let i=Object.keys(n),s=Object.keys(t);if(i.length-(e&&i.indexOf(e)>-1?1:0)!=s.length-(e&&s.indexOf(e)>-1?1:0))return!1;for(let r of i)if(r!=e&&(s.indexOf(r)==-1||n[r]!==t[r]))return!1;return!0}function Le(n,t,e){let i=!1;if(t)for(let s in t)e&&s in e||(i=!0,s=="style"?n.style.cssText="":n.removeAttribute(s));if(e)for(let s in e)t&&t[s]==e[s]||(i=!0,s=="style"?n.style.cssText=e[s]:n.setAttribute(s,e[s]));return i}function $n(n){let t=Object.create(null);for(let e=0;e<n.attributes.length;e++){let i=n.attributes[e];t[i.name]=i.value}return t}class dt{eq(t){return!1}updateDOM(t,e){return!1}compare(t){return this==t||this.constructor==t.constructor&&this.eq(t)}get estimatedHeight(){return-1}get lineBreaks(){return 0}ignoreEvent(t){return!0}coordsAt(t,e,i){return null}get isHidden(){return!1}destroy(t){}}var R=function(n){return n[n.Text=0]="Text",n[n.WidgetBefore=1]="WidgetBefore",n[n.WidgetAfter=2]="WidgetAfter",n[n.WidgetRange=3]="WidgetRange",n}(R||(R={}));class B extends ui{constructor(t,e,i,s){super(),this.startSide=t,this.endSide=e,this.widget=i,this.spec=s}get heightRelevant(){return!1}static mark(t){return new Ft(t)}static widget(t){let e=Math.max(-1e4,Math.min(1e4,t.side||0)),i=!!t.block;return e+=i&&!t.inlineOrder?e>0?3e8:-4e8:e>0?1e8:-1e8,new lt(t,e,e,i,t.widget||null,!1)}static replace(t){let e=!!t.block,i,s;if(t.isBlockGap)i=-5e8,s=4e8;else{let{start:r,end:o}=Ki(t,e);i=(r?e?-3e8:-1:5e8)-1,s=(o?e?2e8:1:-6e8)+1}return new lt(t,i,s,e,t.widget||null,!0)}static line(t){return new zt(t)}static set(t,e=!1){return F.of(t,e)}hasHeight(){return this.widget?this.widget.estimatedHeight>-1:!1}}B.none=F.empty;class Ft extends B{constructor(t){let{start:e,end:i}=Ki(t);super(e?-1:5e8,i?1:-6e8,null,t),this.tagName=t.tagName||"span",this.class=t.class||"",this.attrs=t.attributes||null}eq(t){var e,i;return this==t||t instanceof Ft&&this.tagName==t.tagName&&(this.class||((e=this.attrs)===null||e===void 0?void 0:e.class))==(t.class||((i=t.attrs)===null||i===void 0?void 0:i.class))&&Be(this.attrs,t.attrs,"class")}range(t,e=t){if(t>=e)throw new RangeError("Mark decorations may not be empty");return super.range(t,e)}}Ft.prototype.point=!1;class zt extends B{constructor(t){super(-2e8,-2e8,null,t)}eq(t){return t instanceof zt&&this.spec.class==t.spec.class&&Be(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)}}zt.prototype.mapMode=gt.TrackBefore,zt.prototype.point=!0;class lt extends B{constructor(t,e,i,s,r,o){super(e,i,r,t),this.block=s,this.isReplace=o,this.mapMode=s?e<=0?gt.TrackBefore:gt.TrackAfter:gt.TrackDel}get type(){return this.startSide<this.endSide?R.WidgetRange:this.startSide<=0?R.WidgetBefore:R.WidgetAfter}get heightRelevant(){return this.block||!!this.widget&&(this.widget.estimatedHeight>=5||this.widget.lineBreaks>0)}eq(t){return t instanceof lt&&Un(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)}}lt.prototype.point=!0;function Ki(n,t=!1){let{inclusiveStart:e,inclusiveEnd:i}=n;return e==null&&(e=n.inclusive),i==null&&(i=n.inclusive),{start:e??t,end:i??t}}function Un(n,t){return n==t||!!(n&&t&&n.compare(t))}function Ee(n,t,e,i=0){let s=e.length-1;s>=0&&e[s]+i>=n?e[s]=Math.max(e[s],t):e.push(n,t)}class I extends T{constructor(){super(...arguments),this.children=[],this.length=0,this.prevAttrs=void 0,this.attrs=null,this.breakAfter=0}merge(t,e,i,s,r,o){if(i){if(!(i instanceof I))return!1;this.dom||i.transferDOM(this)}return s&&this.setDeco(i?i.attrs:null),Ti(this,t,e,i?i.children:[],r,o),!0}split(t){let e=new I;if(e.breakAfter=this.breakAfter,this.length==0)return e;let{i,off:s}=this.childPos(t);s&&(e.append(this.children[i].split(s),0),this.children[i].merge(s,this.children[i].length,null,!1,0,0),i++);for(let r=i;r<this.children.length;r++)e.append(this.children[r],0);for(;i>0&&this.children[i-1].length==0;)this.children[--i].destroy();return this.children.length=i,this.markDirty(),this.length=t,e}transferDOM(t){this.dom&&(this.markDirty(),t.setDOM(this.dom),t.prevAttrs=this.prevAttrs===void 0?this.attrs:this.prevAttrs,this.prevAttrs=void 0,this.dom=null)}setDeco(t){Be(this.attrs,t)||(this.dom&&(this.prevAttrs=this.attrs,this.markDirty()),this.attrs=t)}append(t,e){Fi(this,t,e)}addLineDeco(t){let e=t.spec.attributes,i=t.spec.class;e&&(this.attrs=Re(e,this.attrs||{})),i&&(this.attrs=Re({class:i},this.attrs||{}))}domAtPos(t){return Wi(this,t)}reuseDOM(t){t.nodeName=="DIV"&&(this.setDOM(t),this.flags|=6)}sync(t,e){var i;this.dom?this.flags&4&&(Ci(this.dom),this.dom.className="cm-line",this.prevAttrs=this.attrs?null:void 0):(this.setDOM(document.createElement("div")),this.dom.className="cm-line",this.prevAttrs=this.attrs?null:void 0),this.prevAttrs!==void 0&&(Le(this.dom,this.prevAttrs,this.attrs),this.dom.classList.add("cm-line"),this.prevAttrs=void 0),super.sync(t,e);let s=this.dom.lastChild;for(;s&&T.get(s)instanceof tt;)s=s.lastChild;if(!s||!this.length||s.nodeName!="BR"&&((i=T.get(s))===null||i===void 0?void 0:i.isEditable)==!1&&(!y.ios||!this.children.some(r=>r instanceof U))){let r=document.createElement("BR");r.cmIgnore=!0,this.dom.appendChild(r)}}measureTextSize(){if(this.children.length==0||this.length>20)return null;let t=0,e;for(let i of this.children){if(!(i instanceof U)||/[^ -~]/.test(i.text))return null;let s=yt(i.dom);if(s.length!=1)return null;t+=s[0].width,e=s[0].height}return t?{lineHeight:this.dom.getBoundingClientRect().height,charWidth:t/this.length,textHeight:e}:null}coordsAt(t,e){let i=zi(this,t,e);if(!this.children.length&&i&&this.parent){let{heightOracle:s}=this.parent.view.viewState,r=i.bottom-i.top;if(Math.abs(r-s.lineHeight)<2&&s.textHeight<r){let o=(r-s.textHeight)/2;return{top:i.top+o,bottom:i.bottom-o,left:i.left,right:i.left}}}return i}become(t){return!1}get type(){return R.Text}static find(t,e){for(let i=0,s=0;i<t.children.length;i++){let r=t.children[i],o=s+r.length;if(o>=e){if(r instanceof I)return r;if(o>e)break}s=o+r.breakAfter}return null}}class ut extends T{constructor(t,e,i){super(),this.widget=t,this.length=e,this.type=i,this.breakAfter=0,this.prevWidget=null}merge(t,e,i,s,r,o){return i&&(!(i instanceof ut)||!this.widget.compare(i.widget)||t>0&&r<=0||e<this.length&&o<=0)?!1:(this.length=t+(i?i.length:0)+(this.length-e),!0)}domAtPos(t){return t==0?z.before(this.dom):z.after(this.dom,t==this.length)}split(t){let e=this.length-t;this.length=t;let i=new ut(this.widget,e,this.type);return i.breakAfter=this.breakAfter,i}get children(){return ke}sync(t){(!this.dom||!this.widget.updateDOM(this.dom,t))&&(this.dom&&this.prevWidget&&this.prevWidget.destroy(this.dom),this.prevWidget=null,this.setDOM(this.widget.toDOM(t)),this.dom.contentEditable="false")}get overrideDOMText(){return this.parent?this.parent.view.state.doc.slice(this.posAtStart,this.posAtEnd):G.empty}domBoundsAround(){return null}become(t){return t instanceof ut&&t.widget.constructor==this.widget.constructor?(t.widget.compare(this.widget)||this.markDirty(!0),this.dom&&!this.prevWidget&&(this.prevWidget=this.widget),this.widget=t.widget,this.length=t.length,this.type=t.type,this.breakAfter=t.breakAfter,!0):!1}ignoreMutation(){return!0}ignoreEvent(t){return this.widget.ignoreEvent(t)}get isEditable(){return!1}get isWidget(){return!0}coordsAt(t,e){return this.widget.coordsAt(this.dom,t,e)}destroy(){super.destroy(),this.dom&&this.widget.destroy(this.dom)}}class It{constructor(t,e,i,s){this.doc=t,this.pos=e,this.end=i,this.disallowBlockEffectsFor=s,this.content=[],this.curLine=null,this.breakAtStart=0,this.pendingBuffer=0,this.bufferMarks=[],this.atCursorPos=!0,this.openStart=-1,this.openEnd=-1,this.text="",this.textOff=0,this.cursor=t.iter(),this.skip=e}posCovered(){if(this.content.length==0)return!this.breakAtStart&&this.doc.lineAt(this.pos).from!=this.pos;let t=this.content[this.content.length-1];return!t.breakAfter&&!(t instanceof ut&&t.type==R.WidgetBefore)}getLine(){return this.curLine||(this.content.push(this.curLine=new I),this.atCursorPos=!0),this.curLine}flushBuffer(t=this.bufferMarks){this.pendingBuffer&&(this.curLine.append(Zt(new Ct(-1),t),t.length),this.pendingBuffer=0)}addBlockWidget(t){this.flushBuffer(),this.curLine=null,this.content.push(t)}finish(t){this.pendingBuffer&&t<=this.bufferMarks.length?this.flushBuffer():this.pendingBuffer=0,this.posCovered()||this.getLine()}buildText(t,e,i){for(;t>0;){if(this.textOff==this.text.length){let{value:r,lineBreak:o,done:l}=this.cursor.next(this.skip);if(this.skip=0,l)throw new Error("Ran out of text content when drawing inline views");if(o){this.posCovered()||this.getLine(),this.content.length?this.content[this.content.length-1].breakAfter=1:this.breakAtStart=1,this.flushBuffer(),this.curLine=null,this.atCursorPos=!0,t--;continue}else this.text=r,this.textOff=0}let s=Math.min(this.text.length-this.textOff,t,512);this.flushBuffer(e.slice(e.length-i)),this.getLine().append(Zt(new U(this.text.slice(this.textOff,this.textOff+s)),e),i),this.atCursorPos=!0,this.textOff+=s,t-=s,i=0}}span(t,e,i,s){this.buildText(e-t,i,s),this.pos=e,this.openStart<0&&(this.openStart=s)}point(t,e,i,s,r,o){if(this.disallowBlockEffectsFor[o]&&i instanceof lt){if(i.block)throw new RangeError("Block decorations may not be specified via plugins");if(e>this.doc.lineAt(this.pos).to)throw new RangeError("Decorations that replace line breaks may not be specified via plugins")}let l=e-t;if(i instanceof lt)if(i.block){let{type:h}=i;h==R.WidgetAfter&&!this.posCovered()&&this.getLine(),this.addBlockWidget(new ut(i.widget||new qi("div"),l,h))}else{let h=ht.create(i.widget||new qi("span"),l,l?0:i.startSide),c=this.atCursorPos&&!h.isEditable&&r<=s.length&&(t<e||i.startSide>0),a=!h.isEditable&&(t<e||r>s.length||i.startSide<=0),d=this.getLine();this.pendingBuffer==2&&!c&&!h.isEditable&&(this.pendingBuffer=0),this.flushBuffer(s),c&&(d.append(Zt(new Ct(1),s),r),r=s.length+Math.max(0,r-s.length)),d.append(Zt(h,s),r),this.atCursorPos=a,this.pendingBuffer=a?t<e||r>s.length?1:2:0,this.pendingBuffer&&(this.bufferMarks=s.slice())}else this.doc.lineAt(this.pos).from==this.pos&&this.getLine().addLineDeco(i);l&&(this.textOff+l<=this.text.length?this.textOff+=l:(this.skip+=l-(this.text.length-this.textOff),this.text="",this.textOff=0),this.pos=e),this.openStart<0&&(this.openStart=r)}static build(t,e,i,s,r){let o=new It(t,e,i,r);return o.openEnd=F.spans(s,e,i,o),o.openStart<0&&(o.openStart=o.openEnd),o.finish(o.openEnd),o}}function Zt(n,t){for(let e of t)n=new tt(e,[n],n.length);return n}class qi extends dt{constructor(t){super(),this.tag=t}eq(t){return t.tag==this.tag}toDOM(){return document.createElement(this.tag)}updateDOM(t){return t.nodeName.toLowerCase()==this.tag}get isHidden(){return!0}}const _i=C.define(),ji=C.define(),Gi=C.define(),$i=C.define(),Pe=C.define(),Ui=C.define(),Yi=C.define(),Xi=C.define({combine:n=>n.some(t=>t)}),Ji=C.define({combine:n=>n.some(t=>t)});class me{constructor(t,e="nearest",i="nearest",s=5,r=5){this.range=t,this.y=e,this.x=i,this.yMargin=s,this.xMargin=r}map(t){return t.empty?this:new me(this.range.map(t),this.y,this.x,this.yMargin,this.xMargin)}}const Zi=Dt.define({map:(n,t)=>n.map(t)});function J(n,t,e){let i=n.facet($i);i.length?i[0](t):window.onerror?window.onerror(String(t),e,void 0,void 0,t):e?console.error(e+":",t):console.error(t)}const Qt=C.define({combine:n=>n.length?n[0]:!0});let Yn=0;const Tt=C.define();class P{constructor(t,e,i,s){this.id=t,this.create=e,this.domEventHandlers=i,this.extension=s(this)}static define(t,e){const{eventHandlers:i,provide:s,decorations:r}=e||{};return new P(Yn++,t,i,o=>{let l=[Tt.of(o)];return r&&l.push(Rt.of(h=>{let c=h.plugin(o);return c?r(c):B.none})),s&&l.push(s(o)),l})}static fromClass(t,e){return P.define(i=>new t(i),e)}}class He{constructor(t){this.spec=t,this.mustUpdate=null,this.value=null}update(t){if(this.value){if(this.mustUpdate){let e=this.mustUpdate;if(this.mustUpdate=null,this.value.update)try{this.value.update(e)}catch(i){if(J(e.state,i,"CodeMirror plugin crashed"),this.value.destroy)try{this.value.destroy()}catch{}this.deactivate()}}}else if(this.spec)try{this.value=this.spec.create(t)}catch(e){J(t.state,e,"CodeMirror plugin crashed"),this.deactivate()}return this}destroy(t){var e;if(!((e=this.value)===null||e===void 0)&&e.destroy)try{this.value.destroy()}catch(i){J(t.state,i,"CodeMirror plugin crashed")}}deactivate(){this.spec=this.value=null}}const Qi=C.define(),te=C.define(),Rt=C.define(),Ne=C.define(),ts=C.define();function es(n,t,e){let i=n.state.facet(ts);if(!i.length)return i;let s=i.map(o=>o instanceof Function?o(n):o),r=[];return F.spans(s,t,e,{point(){},span(o,l,h,c){let a=r;for(let d=h.length-1;d>=0;d--,c--){let f=h[d].spec.bidiIsolate,u;if(f!=null)if(c>0&&a.length&&(u=a[a.length-1]).to==o&&u.direction==f)u.to=l,a=u.inner;else{let p={from:o,to:l,direction:f,inner:[]};a.push(p),a=p.inner}}}}),r}const is=C.define();function ss(n){let t=0,e=0,i=0,s=0;for(let r of n.state.facet(is)){let o=r(n);o&&(o.left!=null&&(t=Math.max(t,o.left)),o.right!=null&&(e=Math.max(e,o.right)),o.top!=null&&(i=Math.max(i,o.top)),o.bottom!=null&&(s=Math.max(s,o.bottom)))}return{left:t,right:e,top:i,bottom:s}}const Bt=C.define();class _{constructor(t,e,i,s){this.fromA=t,this.toA=e,this.fromB=i,this.toB=s}join(t){return new _(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)}}return t.splice(e,0,i),t}static extendWithRanges(t,e){if(e.length==0)return t;let i=[];for(let s=0,r=0,o=0,l=0;;s++){let h=s==t.length?null:t[s],c=o-l,a=h?h.fromB:1e9;for(;r<e.length&&e[r]<a;){let d=e[r],f=e[r+1],u=Math.max(l,d),p=Math.min(a,f);if(u<=p&&new _(u+c,p+c,u,p).addToSet(i),f>a)break;r+=2}if(!h)return i;new _(h.fromA,h.toA,h.fromB,h.toB).addToSet(i),o=h.toA,l=h.toB}}}class Kt{constructor(t,e,i){this.view=t,this.state=e,this.transactions=i,this.flags=0,this.startState=t.state,this.changes=pi.empty(this.startState.doc.length);for(let r of i)this.changes=this.changes.compose(r.changes);let s=[];this.changes.iterChangedRanges((r,o,l,h)=>s.push(new _(r,o,l,h))),this.changedRanges=s}static create(t,e,i){return new Kt(t,e,i)}get viewportChanged(){return(this.flags&4)>0}get heightChanged(){return(this.flags&2)>0}get geometryChanged(){return this.docChanged||(this.flags&10)>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}}var L=function(n){return n[n.LTR=0]="LTR",n[n.RTL=1]="RTL",n}(L||(L={}));const Lt=L.LTR,ns=L.RTL;function rs(n){let t=[];for(let e=0;e<n.length;e++)t.push(1<<+n[e]);return t}const Xn=rs("88888888888888888888888888888888888666888888787833333333337888888000000000000000000000000008888880000000000000000000000000088888888888888888888888888888888888887866668888088888663380888308888800000000000000000000000800000000000000000000000000000008"),Jn=rs("4444448826627288999999999992222222222222222222222222222222222222222222222229999999999999999999994444444444644222822222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222999999949999999229989999223333333333"),Ve=Object.create(null),$=[];for(let n of["()","[]","{}"]){let t=n.charCodeAt(0),e=n.charCodeAt(1);Ve[t]=e,Ve[e]=-t}function Zn(n){return n<=247?Xn[n]:1424<=n&&n<=1524?2:1536<=n&&n<=1785?Jn[n-1536]:1774<=n&&n<=2220?4:8192<=n&&n<=8203?256:64336<=n&&n<=65023?4:n==8204?256:1}const Qn=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac\ufb50-\ufdff]/;class Z{get dir(){return this.level%2?ns:Lt}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}static find(t,e,i,s){let r=-1;for(let o=0;o<t.length;o++){let l=t[o];if(l.from<=e&&l.to>=e){if(l.level==i)return o;(r<0||(s!=0?s<0?l.from<e:l.to>e:t[r].level>l.level))&&(r=o)}}if(r<0)throw new RangeError("Index out of range");return r}}function os(n,t){if(n.length!=t.length)return!1;for(let e=0;e<n.length;e++){let i=n[e],s=t[e];if(i.from!=s.from||i.to!=s.to||i.direction!=s.direction||!os(i.inner,s.inner))return!1}return!0}const D=[];function tr(n,t,e,i,s){for(let r=0;r<=i.length;r++){let o=r?i[r-1].to:t,l=r<i.length?i[r].from:e,h=r?256:s;for(let c=o,a=h,d=h;c<l;c++){let f=Zn(n.charCodeAt(c));f==512?f=a:f==8&&d==4&&(f=16),D[c]=f==4?2:f,f&7&&(d=f),a=f}for(let c=o,a=h,d=h;c<l;c++){let f=D[c];if(f==128)c<l-1&&a==D[c+1]&&a&24?f=D[c]=a:D[c]=256;else if(f==64){let u=c+1;for(;u<l&&D[u]==64;)u++;let p=c&&a==8||u<e&&D[u]==8?d==1?1:8:256;for(let g=c;g<u;g++)D[g]=p;c=u-1}else f==8&&d==1&&(D[c]=1);a=f,f&7&&(d=f)}}}function er(n,t,e,i,s){let r=s==1?2:1;for(let o=0,l=0,h=0;o<=i.length;o++){let c=o?i[o-1].to:t,a=o<i.length?i[o].from:e;for(let d=c,f,u,p;d<a;d++)if(u=Ve[f=n.charCodeAt(d)])if(u<0){for(let g=l-3;g>=0;g-=3)if($[g+1]==-u){let m=$[g+2],b=m&2?s:m&4?m&1?r:s:0;b&&(D[d]=D[$[g]]=b),l=g;break}}else{if($.length==189)break;$[l++]=d,$[l++]=f,$[l++]=h}else if((p=D[d])==2||p==1){let g=p==s;h=g?0:1;for(let m=l-3;m>=0;m-=3){let b=$[m+2];if(b&2)break;if(g)$[m+2]|=2;else{if(b&4)break;$[m+2]|=4}}}}}function ir(n,t,e,i){for(let s=0,r=i;s<=e.length;s++){let o=s?e[s-1].to:n,l=s<e.length?e[s].from:t;for(let h=o;h<l;){let c=D[h];if(c==256){let a=h+1;for(;;)if(a==l){if(s==e.length)break;a=e[s++].to,l=s<e.length?e[s].from:t}else if(D[a]==256)a++;else break;let d=r==1,f=(a<t?D[a]:i)==1,u=d==f?d?1:2:i;for(let p=a,g=s,m=g?e[g-1].to:n;p>h;)p==m&&(p=e[--g].from,m=g?e[g-1].to:n),D[--p]=u;h=a}else r=c,h++}}}function We(n,t,e,i,s,r,o){let l=i%2?2:1;if(i%2==s%2)for(let h=t,c=0;h<e;){let a=!0,d=!1;if(c==r.length||h<r[c].from){let g=D[h];g!=l&&(a=!1,d=g==16)}let f=!a&&l==1?[]:null,u=a?i:i+1,p=h;t:for(;;)if(c<r.length&&p==r[c].from){if(d)break t;let g=r[c];if(!a)for(let m=g.to,b=c+1;;){if(m==e)break t;if(b<r.length&&r[b].from==m)m=r[b++].to;else{if(D[m]==l)break t;break}}if(c++,f)f.push(g);else{g.from>h&&o.push(new Z(h,g.from,u));let m=g.direction==Lt!=!(u%2);Fe(n,m?i+1:i,s,g.inner,g.from,g.to,o),h=g.to}p=g.to}else{if(p==e||(a?D[p]!=l:D[p]==l))break;p++}f?We(n,h,p,i+1,s,f,o):h<p&&o.push(new Z(h,p,u)),h=p}else for(let h=e,c=r.length;h>t;){let a=!0,d=!1;if(!c||h>r[c-1].to){let g=D[h-1];g!=l&&(a=!1,d=g==16)}let f=!a&&l==1?[]:null,u=a?i:i+1,p=h;t:for(;;)if(c&&p==r[c-1].to){if(d)break t;let g=r[--c];if(!a)for(let m=g.from,b=c;;){if(m==t)break t;if(b&&r[b-1].to==m)m=r[--b].from;else{if(D[m-1]==l)break t;break}}if(f)f.push(g);else{g.to<h&&o.push(new Z(g.to,h,u));let m=g.direction==Lt!=!(u%2);Fe(n,m?i+1:i,s,g.inner,g.from,g.to,o),h=g.from}p=g.from}else{if(p==t||(a?D[p-1]!=l:D[p-1]==l))break;p--}f?We(n,p,h,i+1,s,f,o):p<h&&o.push(new Z(p,h,u)),h=p}}function Fe(n,t,e,i,s,r,o){let l=t%2?2:1;tr(n,s,r,i,l),er(n,s,r,i,l),ir(s,r,i,l),We(n,s,r,t,e,i,o)}function ls(n,t,e){if(!n)return[new Z(0,0,t==ns?1:0)];if(t==Lt&&!e.length&&!Qn.test(n))return hs(n.length);if(e.length)for(;n.length>D.length;)D[D.length]=256;let i=[],s=t==Lt?0:1;return Fe(n,s,s,e,0,n.length,i),i}function hs(n){return[new Z(0,n,0)]}let as="";function cs(n,t,e,i,s){var r;let o=i.head-n.from,l=-1;if(o==0){if(!s||!n.length)return null;t[0].level!=e&&(o=t[0].side(!1,e),l=0)}else if(o==n.length){if(s)return null;let f=t[t.length-1];f.level!=e&&(o=f.side(!0,e),l=t.length-1)}l<0&&(l=Z.find(t,o,(r=i.bidiLevel)!==null&&r!==void 0?r:-1,i.assoc));let h=t[l];o==h.side(s,e)&&(h=t[l+=s?1:-1],o=h.side(!s,e));let c=s==(h.dir==e),a=mt(n.text,o,c);if(as=n.text.slice(Math.min(o,a),Math.max(o,a)),a!=h.side(s,e))return v.cursor(a+n.from,c?-1:1,h.level);let d=l==(s?t.length-1:0)?null:t[l+(s?1:-1)];return!d&&h.level!=e?v.cursor(s?n.to:n.from,s?-1:1,e):d&&d.level<h.level?v.cursor(d.side(!s,e)+n.from,s?1:-1,d.level):v.cursor(a+n.from,s?-1:1,h.level)}class fs extends T{get length(){return this.view.state.doc.length}constructor(t){super(),this.view=t,this.decorations=[],this.dynamicDecorationMap=[],this.hasComposition=null,this.markedForComposition=new Set,this.minWidth=0,this.minWidthFrom=0,this.minWidthTo=0,this.impreciseAnchor=null,this.impreciseHead=null,this.forceSelection=!1,this.lastUpdate=Date.now(),this.setDOM(t.contentDOM),this.children=[new I],this.children[0].setParent(this),this.updateDeco(),this.updateInner([new _(0,0,0,t.state.doc.length)],0,null)}update(t){let e=t.changedRanges;this.minWidth>0&&e.length&&(e.every(({fromA:l,toA:h})=>h<this.minWidthFrom||l>this.minWidthTo)?(this.minWidthFrom=t.changes.mapPos(this.minWidthFrom,1),this.minWidthTo=t.changes.mapPos(this.minWidthTo,1)):this.minWidth=this.minWidthFrom=this.minWidthTo=0);let i=this.view.inputState.composing<0?null:nr(this.view,t.changes);if(this.hasComposition){this.markedForComposition.clear();let{from:l,to:h}=this.hasComposition;e=new _(l,h,t.changes.mapPos(l,-1),t.changes.mapPos(h,1)).addToSet(e.slice())}this.hasComposition=i?{from:i.range.fromB,to:i.range.toB}:null,(y.ie||y.chrome)&&!i&&t&&t.state.doc.lines!=t.startState.doc.lines&&(this.forceSelection=!0);let s=this.decorations,r=this.updateDeco(),o=lr(s,r,t.changes);return e=_.extendWithRanges(e,o),!(this.flags&7)&&e.length==0?!1:(this.updateInner(e,t.startState.doc.length,i),t.transactions.length&&(this.lastUpdate=Date.now()),!0)}updateInner(t,e,i){this.view.viewState.mustMeasureContent=!0,this.updateChildren(t,e,i);let{observer:s}=this.view;s.ignore(()=>{this.dom.style.height=this.view.viewState.contentHeight+"px",this.dom.style.flexBasis=this.minWidth?this.minWidth+"px":"";let o=y.chrome||y.ios?{node:s.selectionRange.focusNode,written:!1}:void 0;this.sync(this.view,o),this.flags&=-8,o&&(o.written||s.selectionRange.focusNode!=o.node)&&(this.forceSelection=!0),this.dom.style.height=""}),this.markedForComposition.forEach(o=>o.flags&=-9);let r=[];if(this.view.viewport.from||this.view.viewport.to<this.view.state.doc.length)for(let o of this.children)o instanceof ut&&o.widget instanceof ds&&r.push(o.dom);s.updateGaps(r)}updateChildren(t,e,i){let s=i?i.range.addToSet(t.slice()):t,r=this.childCursor(e);for(let o=s.length-1;;o--){let l=o>=0?s[o]:null;if(!l)break;let{fromA:h,toA:c,fromB:a,toB:d}=l,f,u,p,g;if(i&&i.range.fromB<d&&i.range.toB>a){let w=It.build(this.view.state.doc,a,i.range.fromB,this.decorations,this.dynamicDecorationMap),x=It.build(this.view.state.doc,i.range.toB,d,this.decorations,this.dynamicDecorationMap);u=w.breakAtStart,p=w.openStart,g=x.openEnd;let M=this.compositionView(i);x.breakAtStart?M.breakAfter=1:x.content.length&&M.merge(M.length,M.length,x.content[0],!1,x.openStart,0)&&(M.breakAfter=x.content[0].breakAfter,x.content.shift()),w.content.length&&M.merge(0,0,w.content[w.content.length-1],!0,0,w.openEnd)&&w.content.pop(),f=w.content.concat(M).concat(x.content)}else({content:f,breakAtStart:u,openStart:p,openEnd:g}=It.build(this.view.state.doc,a,d,this.decorations,this.dynamicDecorationMap));let{i:m,off:b}=r.findPos(c,1),{i:S,off:k}=r.findPos(h,-1);Oi(this,S,k,m,b,f,u,p,g)}i&&this.fixCompositionDOM(i)}compositionView(t){let e=new U(t.text.nodeValue);e.flags|=8;for(let{deco:s}of t.marks)e=new tt(s,[e],e.length);let i=new I;return i.append(e,0),i}fixCompositionDOM(t){let e=(r,o)=>{o.flags|=8,this.markedForComposition.add(o);let l=T.get(r);l!=o&&(l&&(l.dom=null),o.setDOM(r))},i=this.childPos(t.range.fromB,1),s=this.children[i.i];e(t.line,s);for(let r=t.marks.length-1;r>=-1;r--)i=s.childPos(i.off,1),s=s.children[i.i],e(r>=0?t.marks[r].node:t.text,s)}updateSelection(t=!1,e=!1){(t||!this.view.observer.selectionRange.focusNode)&&this.view.observer.readSelectionRange();let i=this.view.root.activeElement,s=i==this.dom,r=!s&&$t(this.dom,this.view.observer.selectionRange)&&!(i&&this.dom.contains(i));if(!(s||e||r))return;let o=this.forceSelection;this.forceSelection=!1;let l=this.view.state.selection.main,h=this.domAtPos(l.anchor),c=l.empty?h:this.domAtPos(l.head);if(y.gecko&&l.empty&&!this.hasComposition&&sr(h)){let d=document.createTextNode("");this.view.observer.ignore(()=>h.node.insertBefore(d,h.node.childNodes[h.offset]||null)),h=c=new z(d,0),o=!0}let a=this.view.observer.selectionRange;(o||!a.focusNode||!Ut(h.node,h.offset,a.anchorNode,a.anchorOffset)||!Ut(c.node,c.offset,a.focusNode,a.focusOffset))&&(this.view.observer.ignore(()=>{y.android&&y.chrome&&this.dom.contains(a.focusNode)&&hr(a.focusNode,this.dom)&&(this.dom.blur(),this.dom.focus({preventScroll:!0}));let d=Gt(this.view.root);if(d)if(l.empty){if(y.gecko){let f=rr(h.node,h.offset);if(f&&f!=3){let u=ps(h.node,h.offset,f==1?1:-1);u&&(h=new z(u,f==1?0:u.nodeValue.length))}}d.collapse(h.node,h.offset),l.bidiLevel!=null&&a.caretBidiLevel!=null&&(a.caretBidiLevel=l.bidiLevel)}else if(d.extend){d.collapse(h.node,h.offset);try{d.extend(c.node,c.offset)}catch{}}else{let f=document.createRange();l.anchor>l.head&&([h,c]=[c,h]),f.setEnd(c.node,c.offset),f.setStart(h.node,h.offset),d.removeAllRanges(),d.addRange(f)}r&&this.view.root.activeElement==this.dom&&(this.dom.blur(),i&&i.focus())}),this.view.observer.setSelectionRange(h,c)),this.impreciseAnchor=h.precise?null:new z(a.anchorNode,a.anchorOffset),this.impreciseHead=c.precise?null:new z(a.focusNode,a.focusOffset)}enforceCursorAssoc(){if(this.hasComposition)return;let{view:t}=this,e=t.state.selection.main,i=Gt(t.root),{anchorNode:s,anchorOffset:r}=t.observer.selectionRange;if(!i||!e.empty||!e.assoc||!i.modify)return;let o=I.find(this,e.head);if(!o)return;let l=o.posAtStart;if(e.head==l||e.head==l+o.length)return;let h=this.coordsAt(e.head,-1),c=this.coordsAt(e.head,1);if(!h||!c||h.bottom>c.top)return;let a=this.domAtPos(e.head+e.assoc);i.collapse(a.node,a.offset),i.modify("move",e.assoc<0?"forward":"backward","lineboundary"),t.observer.readSelectionRange();let d=t.observer.selectionRange;t.docView.posFromDOM(d.anchorNode,d.anchorOffset)!=e.from&&i.collapse(s,r)}nearest(t){for(let e=t;e;){let i=T.get(e);if(i&&i.rootView==this)return i;e=e.parentNode}return null}posFromDOM(t,e){let i=this.nearest(t);if(!i)throw new RangeError("Trying to find position for a DOM position outside of the document");return i.localPosFromDOM(t,e)+i.posAtStart}domAtPos(t){let{i:e,off:i}=this.childCursor().findPos(t,-1);for(;e<this.children.length-1;){let s=this.children[e];if(i<s.length||s instanceof I)break;e++,i=0}return this.children[e].domAtPos(i)}coordsAt(t,e){for(let i=this.length,s=this.children.length-1;;s--){let r=this.children[s],o=i-r.breakAfter-r.length;if(t>o||t==o&&r.type!=R.WidgetBefore&&r.type!=R.WidgetAfter&&(!s||e==2||this.children[s-1].breakAfter||this.children[s-1].type==R.WidgetBefore&&e>-2))return r.coordsAt(t-o,e);i=o}}coordsForChar(t){let{i:e,off:i}=this.childPos(t,1),s=this.children[e];if(!(s instanceof I))return null;for(;s.children.length;){let{i:l,off:h}=s.childPos(i,1);for(;;l++){if(l==s.children.length)return null;if((s=s.children[l]).length)break}i=h}if(!(s instanceof U))return null;let r=mt(s.text,i);if(r==i)return null;let o=ft(s.dom,i,r).getClientRects();return!o.length||o[0].top>=o[0].bottom?null:o[0]}measureVisibleLineHeights(t){let e=[],{from:i,to:s}=t,r=this.view.contentDOM.clientWidth,o=r>Math.max(this.view.scrollDOM.clientWidth,this.minWidth)+1,l=-1,h=this.view.textDirection==L.LTR;for(let c=0,a=0;a<this.children.length;a++){let d=this.children[a],f=c+d.length;if(f>s)break;if(c>=i){let u=d.dom.getBoundingClientRect();if(e.push(u.height),o){let p=d.dom.lastChild,g=p?yt(p):[];if(g.length){let m=g[g.length-1],b=h?m.right-u.left:u.right-m.left;b>l&&(l=b,this.minWidth=r,this.minWidthFrom=c,this.minWidthTo=f)}}}c=f+d.breakAfter}return e}textDirectionAt(t){let{i:e}=this.childPos(t,1);return getComputedStyle(this.children[e].dom).direction=="rtl"?L.RTL:L.LTR}measureTextSize(){for(let r of this.children)if(r instanceof I){let o=r.measureTextSize();if(o)return o}let t=document.createElement("div"),e,i,s;return t.className="cm-line",t.style.width="99999px",t.style.position="absolute",t.textContent="abc def ghi jkl mno pqr stu",this.view.observer.ignore(()=>{this.dom.appendChild(t);let r=yt(t.firstChild)[0];e=t.getBoundingClientRect().height,i=r?r.width/27:7,s=r?r.height:e,t.remove()}),{lineHeight:e,charWidth:i,textHeight:s}}childCursor(t=this.length){let e=this.children.length;return e&&(t-=this.children[--e].length),new Di(this.children,t,e)}computeBlockGapDeco(){let t=[],e=this.view.viewState;for(let i=0,s=0;;s++){let r=s==e.viewports.length?null:e.viewports[s],o=r?r.from-1:this.length;if(o>i){let l=e.lineBlockAt(o).bottom-e.lineBlockAt(i).top;t.push(B.replace({widget:new ds(l),block:!0,inclusive:!0,isBlockGap:!0}).range(i,o))}if(!r)break;i=r.to+1}return B.set(t)}updateDeco(){let t=this.view.state.facet(Rt).map((e,i)=>(this.dynamicDecorationMap[i]=typeof e=="function")?e(this.view):e);for(let e=t.length;e<t.length+3;e++)this.dynamicDecorationMap[e]=!1;return this.decorations=[...t,this.computeBlockGapDeco(),this.view.viewState.lineGapDeco]}scrollIntoView(t){let{range:e}=t,i=this.coordsAt(e.head,e.empty?e.assoc:e.head>e.anchor?-1:1),s;if(!i)return;!e.empty&&(s=this.coordsAt(e.anchor,e.anchor>e.head?-1:1))&&(i={left:Math.min(i.left,s.left),top:Math.min(i.top,s.top),right:Math.max(i.right,s.right),bottom:Math.max(i.bottom,s.bottom)});let r=ss(this.view),o={left:i.left-r.left,top:i.top-r.top,right:i.right+r.right,bottom:i.bottom+r.bottom};Fn(this.view.scrollDOM,o,e.head<e.anchor?-1:1,t.x,t.y,t.xMargin,t.yMargin,this.view.textDirection==L.LTR)}}function sr(n){return n.node.nodeType==1&&n.node.firstChild&&(n.offset==0||n.node.childNodes[n.offset-1].contentEditable=="false")&&(n.offset==n.node.childNodes.length||n.node.childNodes[n.offset].contentEditable=="false")}class ds extends dt{constructor(t){super(),this.height=t}toDOM(){let t=document.createElement("div");return this.updateDOM(t),t}eq(t){return t.height==this.height}updateDOM(t){return t.style.height=this.height+"px",!0}get estimatedHeight(){return this.height}}function us(n,t){let e=n.observer.selectionRange,i=e.focusNode&&ps(e.focusNode,e.focusOffset,0);if(!i)return null;let s=T.get(i),r,o;if(s instanceof U)r=s.posAtStart,o=r+s.length;else{let l=Math.max(0,i.nodeValue.length-t);t:for(let h=0,c=i;;){for(let d=c.previousSibling,f;d;d=d.previousSibling){if(f=T.get(d)){o=f.posAtEnd+h,r=Math.max(0,o-l);break t}let u=new Ri([],n.state);if(u.readNode(d),u.text.indexOf(xt)>-1)return null;h+=u.text.length}if(c=c.parentNode,!c)return null;let a=T.get(c);if(a){r=a.posAtStart+h,o=r+l;break}}}return{from:r,to:o,node:i}}function nr(n,t){let e=us(n,t.newLength-t.length);if(!e)return null;let{from:i,to:s,node:r}=e,o=t.mapPos(i,-1),l=t.mapPos(s,1),h=r.nodeValue;if(/[\n\r]/.test(h))return null;if(l-o!=h.length){let f=t.mapPos(i,1),u=t.mapPos(s,-1);if(u-f==h.length)o=f,l=u;else if(n.state.doc.sliceString(l-h.length,l)==h)o=l-h.length;else if(n.state.doc.sliceString(o,o+h.length)==h)l=o+h.length;else return null}let{main:c}=n.state.selection;if(n.state.doc.sliceString(o,l)!=h||o>c.head||l<c.head)return null;let a=[],d=new _(i,s,o,l);for(let f=r.parentNode;;f=f.parentNode){let u=T.get(f);if(u instanceof tt)a.push({node:f,deco:u.mark});else{if(u instanceof I||f.nodeName=="DIV"&&f.parentNode==n.contentDOM)return{range:d,text:r,marks:a,line:f};if(f!=n.contentDOM)a.push({node:f,deco:new Ft({inclusive:!0,attributes:$n(f),tagName:f.tagName.toLowerCase()})});else return null}}}function ps(n,t,e){if(e<=0)for(let i=n,s=t;;){if(i.nodeType==3)return i;if(i.nodeType==1&&s>0)i=i.childNodes[s-1],s=rt(i);else break}if(e>=0)for(let i=n,s=t;;){if(i.nodeType==3)return i;if(i.nodeType==1&&s<i.childNodes.length&&e>=0)i=i.childNodes[s],s=0;else break}return null}function rr(n,t){return n.nodeType!=1?0:(t&&n.childNodes[t-1].contentEditable=="false"?1:0)|(t<n.childNodes.length&&n.childNodes[t].contentEditable=="false"?2:0)}let or=class{constructor(){this.changes=[]}compareRange(t,e){Ee(t,e,this.changes)}comparePoint(t,e){Ee(t,e,this.changes)}};function lr(n,t,e){let i=new or;return F.compare(n,t,e,i),i.changes}function hr(n,t){for(let e=n;e&&e!=t;e=e.assignedSlot||e.parentNode)if(e.nodeType==1&&e.contentEditable=="false")return!0;return!1}function ar(n,t,e=1){let i=n.charCategorizer(t),s=n.doc.lineAt(t),r=t-s.from;if(s.length==0)return v.cursor(t);r==0?e=1:r==s.length&&(e=-1);let o=r,l=r;e<0?o=mt(s.text,r,!1):l=mt(s.text,r);let h=i(s.text.slice(o,l));for(;o>0;){let c=mt(s.text,o,!1);if(i(s.text.slice(c,o))!=h)break;o=c}for(;l<s.length;){let c=mt(s.text,l);if(i(s.text.slice(l,c))!=h)break;l=c}return v.range(o+s.from,l+s.from)}function cr(n,t){return t.left>n?t.left-n:Math.max(0,n-t.right)}function fr(n,t){return t.top>n?t.top-n:Math.max(0,n-t.bottom)}function ze(n,t){return n.top<t.bottom-1&&n.bottom>t.top+1}function gs(n,t){return t<n.top?{top:t,left:n.left,right:n.right,bottom:n.bottom}:n}function ms(n,t){return t>n.bottom?{top:n.top,left:n.left,right:n.right,bottom:t}:n}function Ie(n,t,e){let i,s,r,o,l=!1,h,c,a,d;for(let p=n.firstChild;p;p=p.nextSibling){let g=yt(p);for(let m=0;m<g.length;m++){let b=g[m];s&&ze(s,b)&&(b=gs(ms(b,s.bottom),s.top));let S=cr(t,b),k=fr(e,b);if(S==0&&k==0)return p.nodeType==3?bs(p,t,e):Ie(p,t,e);if(!i||o>k||o==k&&r>S){i=p,s=b,r=S,o=k;let w=k?e<b.top?-1:1:S?t<b.left?-1:1:0;l=!w||(w>0?m<g.length-1:m>0)}S==0?e>b.bottom&&(!a||a.bottom<b.bottom)?(h=p,a=b):e<b.top&&(!d||d.top>b.top)&&(c=p,d=b):a&&ze(a,b)?a=ms(a,b.bottom):d&&ze(d,b)&&(d=gs(d,b.top))}}if(a&&a.bottom>=e?(i=h,s=a):d&&d.top<=e&&(i=c,s=d),!i)return{node:n,offset:0};let f=Math.max(s.left,Math.min(s.right,t));if(i.nodeType==3)return bs(i,f,e);if(l&&i.contentEditable!="false")return Ie(i,f,e);let u=Array.prototype.indexOf.call(n.childNodes,i)+(t>=(s.left+s.right)/2?1:0);return{node:n,offset:u}}function bs(n,t,e){let i=n.nodeValue.length,s=-1,r=1e9,o=0;for(let l=0;l<i;l++){let h=ft(n,l,l+1).getClientRects();for(let c=0;c<h.length;c++){let a=h[c];if(a.top==a.bottom)continue;o||(o=t-a.left);let d=(a.top>e?a.top-e:e-a.bottom)-1;if(a.left-1<=t&&a.right+1>=t&&d<r){let f=t>=(a.left+a.right)/2,u=f;if((y.chrome||y.gecko)&&ft(n,l).getBoundingClientRect().left==a.right&&(u=!f),d<=0)return{node:n,offset:l+(u?1:0)};s=l+(u?1:0),r=d}}}return{node:n,offset:s>-1?s:o>0?n.nodeValue.length:0}}function ys(n,t,e,i=-1){var s,r;let o=n.contentDOM.getBoundingClientRect(),l=o.top+n.viewState.paddingTop,h,{docHeight:c}=n.viewState,{x:a,y:d}=t,f=d-l;if(f<0)return 0;if(f>c)return n.state.doc.length;for(let w=n.viewState.heightOracle.textHeight/2,x=!1;h=n.elementAtHeight(f),h.type!=R.Text;)for(;f=i>0?h.bottom+w:h.top-w,!(f>=0&&f<=c);){if(x)return e?null:0;x=!0,i=-i}d=l+f;let u=h.from;if(u<n.viewport.from)return n.viewport.from==0?0:e?null:ws(n,o,h,a,d);if(u>n.viewport.to)return n.viewport.to==n.state.doc.length?n.state.doc.length:e?null:ws(n,o,h,a,d);let p=n.dom.ownerDocument,g=n.root.elementFromPoint?n.root:p,m=g.elementFromPoint(a,d);m&&!n.contentDOM.contains(m)&&(m=null),m||(a=Math.max(o.left+1,Math.min(o.right-1,a)),m=g.elementFromPoint(a,d),m&&!n.contentDOM.contains(m)&&(m=null));let b,S=-1;if(m&&((s=n.docView.nearest(m))===null||s===void 0?void 0:s.isEditable)!=!1){if(p.caretPositionFromPoint){let w=p.caretPositionFromPoint(a,d);w&&({offsetNode:b,offset:S}=w)}else if(p.caretRangeFromPoint){let w=p.caretRangeFromPoint(a,d);w&&({startContainer:b,startOffset:S}=w,(!n.contentDOM.contains(b)||y.safari&&dr(b,S,a)||y.chrome&&ur(b,S,a))&&(b=void 0))}}if(!b||!n.docView.dom.contains(b)){let w=I.find(n.docView,u);if(!w)return f>h.top+h.height/2?h.to:h.from;({node:b,offset:S}=Ie(w.dom,a,d))}let k=n.docView.nearest(b);if(!k)return null;if(k.isWidget&&((r=k.dom)===null||r===void 0?void 0:r.nodeType)==1){let w=k.dom.getBoundingClientRect();return t.y<w.top||t.y<=w.bottom&&t.x<=(w.left+w.right)/2?k.posAtStart:k.posAtEnd}else return k.localPosFromDOM(b,S)+k.posAtStart}function ws(n,t,e,i,s){let r=Math.round((i-t.left)*n.defaultCharacterWidth);if(n.lineWrapping&&e.height>n.defaultLineHeight*1.5){let l=n.viewState.heightOracle.textHeight,h=Math.floor((s-e.top-(n.defaultLineHeight-l)*.5)/l);r+=h*n.viewState.heightOracle.lineLength}let o=n.state.sliceDoc(e.from,e.to);return e.from+we(o,r,n.state.tabSize)}function dr(n,t,e){let i;if(n.nodeType!=3||t!=(i=n.nodeValue.length))return!1;for(let s=n.nextSibling;s;s=s.nextSibling)if(s.nodeType!=1||s.nodeName!="BR")return!1;return ft(n,i-1,i).getBoundingClientRect().left>e}function ur(n,t,e){if(t!=0)return!1;for(let s=n;;){let r=s.parentNode;if(!r||r.nodeType!=1||r.firstChild!=s)return!1;if(r.classList.contains("cm-line"))break;s=r}let i=n.nodeType==1?n.getBoundingClientRect():ft(n,0,Math.max(n.nodeValue.length,1)).getBoundingClientRect();return e-i.left>5}function Ke(n,t){let e=n.lineBlockAt(t);if(Array.isArray(e.type)){for(let i of e.type)if(i.to>t||i.to==t&&(i.to==e.to||i.type==R.Text))return i}return e}function pr(n,t,e,i){let s=Ke(n,t.head),r=!i||s.type!=R.Text||!(n.lineWrapping||s.widgetLineBreaks)?null:n.coordsAtPos(t.assoc<0&&t.head>s.from?t.head-1:t.head);if(r){let o=n.dom.getBoundingClientRect(),l=n.textDirectionAt(s.from),h=n.posAtCoords({x:e==(l==L.LTR)?o.right-1:o.left+1,y:(r.top+r.bottom)/2});if(h!=null)return v.cursor(h,e?-1:1)}return v.cursor(e?s.to:s.from,e?-1:1)}function Ss(n,t,e,i){let s=n.state.doc.lineAt(t.head),r=n.bidiSpans(s),o=n.textDirectionAt(s.from);for(let l=t,h=null;;){let c=cs(s,r,o,l,e),a=as;if(!c){if(s.number==(e?n.state.doc.lines:1))return l;a=`
`,s=n.state.doc.line(s.number+(e?1:-1)),r=n.bidiSpans(s),c=v.cursor(e?s.from:s.to)}if(h){if(!h(a))return l}else{if(!i)return c;h=i(a)}l=c}}function gr(n,t,e){let i=n.state.charCategorizer(t),s=i(e);return r=>{let o=i(r);return s==Ln.Space&&(s=o),s==o}}function mr(n,t,e,i){let s=t.head,r=e?1:-1;if(s==(e?n.state.doc.length:0))return v.cursor(s,t.assoc);let o=t.goalColumn,l,h=n.contentDOM.getBoundingClientRect(),c=n.coordsAtPos(s),a=n.documentTop;if(c)o==null&&(o=c.left-h.left),l=r<0?c.top:c.bottom;else{let u=n.viewState.lineBlockAt(s);o==null&&(o=Math.min(h.right-h.left,n.defaultCharacterWidth*(s-u.from))),l=(r<0?u.top:u.bottom)+a}let d=h.left+o,f=i??n.viewState.heightOracle.textHeight>>1;for(let u=0;;u+=10){let p=l+(f+u)*r,g=ys(n,{x:d,y:p},!1,r);if(p<h.top||p>h.bottom||(r<0?g<s:g>s))return v.cursor(g,t.assoc,void 0,o)}}function ee(n,t,e){for(;;){let i=0;for(let s of n)s.between(t-1,t+1,(r,o,l)=>{if(t>r&&t<o){let h=i||e||(t-r<o-t?-1:1);t=h<0?r:o,i=h}});if(!i)return t}}function qe(n,t,e){let i=ee(n.state.facet(Ne).map(s=>s(n)),e.from,t.head>e.from?-1:1);return i==e.from?e:v.cursor(i,i<e.from?1:-1)}class br{setSelectionOrigin(t){this.lastSelectionOrigin=t,this.lastSelectionTime=Date.now()}constructor(t){this.lastKeyCode=0,this.lastKeyTime=0,this.lastTouchTime=0,this.lastFocusTime=0,this.lastScrollTop=0,this.lastScrollLeft=0,this.chromeScrollHack=-1,this.pendingIOSKey=void 0,this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastEscPress=0,this.lastContextMenu=0,this.scrollHandlers=[],this.registeredEvents=[],this.customHandlers=[],this.composing=-1,this.compositionFirstChange=null,this.compositionEndedAt=0,this.compositionPendingKey=!1,this.compositionPendingChange=!1,this.mouseSelection=null;let e=(i,s)=>{this.ignoreDuringComposition(s)||s.type=="keydown"&&this.keydown(t,s)||(this.mustFlushObserver(s)&&t.observer.forceFlush(),this.runCustomHandlers(s.type,t,s)?s.preventDefault():i(t,s))};for(let i in E){let s=E[i];t.contentDOM.addEventListener(i,r=>{Ms(t,r)&&e(s,r)},_e[i]),this.registeredEvents.push(i)}t.scrollDOM.addEventListener("mousedown",i=>{if(i.target==t.scrollDOM&&i.clientY>t.contentDOM.getBoundingClientRect().bottom&&(e(E.mousedown,i),!i.defaultPrevented&&i.button==2)){let s=t.contentDOM.style.minHeight;t.contentDOM.style.minHeight="100%",setTimeout(()=>t.contentDOM.style.minHeight=s,200)}}),t.scrollDOM.addEventListener("drop",i=>{i.target==t.scrollDOM&&i.clientY>t.contentDOM.getBoundingClientRect().bottom&&e(E.drop,i)}),y.chrome&&y.chrome_version==102&&t.scrollDOM.addEventListener("wheel",()=>{this.chromeScrollHack<0?t.contentDOM.style.pointerEvents="none":window.clearTimeout(this.chromeScrollHack),this.chromeScrollHack=setTimeout(()=>{this.chromeScrollHack=-1,t.contentDOM.style.pointerEvents=""},100)},{passive:!0}),this.notifiedFocused=t.hasFocus,y.safari&&t.contentDOM.addEventListener("input",()=>null),y.gecko&&Br(t.contentDOM.ownerDocument)}ensureHandlers(t,e){var i;let s;this.customHandlers=[];for(let r of e)if(s=(i=r.update(t).spec)===null||i===void 0?void 0:i.domEventHandlers){this.customHandlers.push({plugin:r.value,handlers:s});for(let o in s)this.registeredEvents.indexOf(o)<0&&o!="scroll"&&(this.registeredEvents.push(o),t.contentDOM.addEventListener(o,l=>{Ms(t,l)&&this.runCustomHandlers(o,t,l)&&l.preventDefault()}))}}runCustomHandlers(t,e,i){for(let s of this.customHandlers){let r=s.handlers[t];if(r)try{if(r.call(s.plugin,i,e)||i.defaultPrevented)return!0}catch(o){J(e.state,o)}}return!1}runScrollHandlers(t,e){this.lastScrollTop=t.scrollDOM.scrollTop,this.lastScrollLeft=t.scrollDOM.scrollLeft;for(let i of this.customHandlers){let s=i.handlers.scroll;if(s)try{s.call(i.plugin,e,t)}catch(r){J(t.state,r)}}}keydown(t,e){if(this.lastKeyCode=e.keyCode,this.lastKeyTime=Date.now(),e.keyCode==9&&Date.now()<this.lastEscPress+2e3)return!0;if(e.keyCode!=27&&vs.indexOf(e.keyCode)<0&&(t.inputState.lastEscPress=0),y.android&&y.chrome&&!e.synthetic&&(e.keyCode==13||e.keyCode==8))return t.observer.delayAndroidKey(e.key,e.keyCode),!0;let i;return y.ios&&!e.synthetic&&!e.altKey&&!e.metaKey&&((i=xs.find(s=>s.keyCode==e.keyCode))&&!e.ctrlKey||yr.indexOf(e.key)>-1&&e.ctrlKey&&!e.shiftKey)?(this.pendingIOSKey=i||e,setTimeout(()=>this.flushIOSKey(t),250),!0):!1}flushIOSKey(t){let e=this.pendingIOSKey;return e?(this.pendingIOSKey=void 0,St(t.contentDOM,e.key,e.keyCode)):!1}ignoreDuringComposition(t){return/^key/.test(t.type)?this.composing>0?!0:y.safari&&!y.ios&&this.compositionPendingKey&&Date.now()-this.compositionEndedAt<100?(this.compositionPendingKey=!1,!0):!1:!1}mustFlushObserver(t){return t.type=="keydown"&&t.keyCode!=229}startMouseSelection(t){this.mouseSelection&&this.mouseSelection.destroy(),this.mouseSelection=t}update(t){this.mouseSelection&&this.mouseSelection.update(t),t.transactions.length&&(this.lastKeyCode=this.lastSelectionTime=0)}destroy(){this.mouseSelection&&this.mouseSelection.destroy()}}const xs=[{key:"Backspace",keyCode:8,inputType:"deleteContentBackward"},{key:"Enter",keyCode:13,inputType:"insertParagraph"},{key:"Enter",keyCode:13,inputType:"insertLineBreak"},{key:"Delete",keyCode:46,inputType:"deleteContentForward"}],yr="dthko",vs=[16,17,18,20,91,92,224,225],ie=6;function se(n){return Math.max(0,n)*.7+8}function wr(n,t){return Math.max(Math.abs(n.clientX-t.clientX),Math.abs(n.clientY-t.clientY))}class Sr{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.scrollParent=zn(t.contentDOM),this.atoms=t.state.facet(Ne).map(o=>o(t));let r=t.contentDOM.ownerDocument;r.addEventListener("mousemove",this.move=this.move.bind(this)),r.addEventListener("mouseup",this.up=this.up.bind(this)),this.extend=e.shiftKey,this.multiple=t.state.facet(At.allowMultipleSelections)&&xr(t,e),this.dragging=Mr(t,e)&&Es(e)==1?null:!1}start(t){this.dragging===!1&&(t.preventDefault(),this.select(t))}move(t){var e;if(t.buttons==0)return this.destroy();if(this.dragging||this.dragging==null&&wr(this.startEvent,t)<10)return;this.select(this.lastEvent=t);let i=0,s=0,r=((e=this.scrollParent)===null||e===void 0?void 0:e.getBoundingClientRect())||{left:0,top:0,right:this.view.win.innerWidth,bottom:this.view.win.innerHeight},o=ss(this.view);t.clientX-o.left<=r.left+ie?i=-se(r.left-t.clientX):t.clientX+o.right>=r.right-ie&&(i=se(t.clientX-r.right)),t.clientY-o.top<=r.top+ie?s=-se(r.top-t.clientY):t.clientY+o.bottom>=r.bottom-ie&&(s=se(t.clientY-r.bottom)),this.setScrollSpeed(i,s)}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=null}setScrollSpeed(t,e){this.scrollSpeed={x:t,y:e},t||e?this.scrolling<0&&(this.scrolling=setInterval(()=>this.scroll(),50)):this.scrolling>-1&&(clearInterval(this.scrolling),this.scrolling=-1)}scroll(){this.scrollParent?(this.scrollParent.scrollLeft+=this.scrollSpeed.x,this.scrollParent.scrollTop+=this.scrollSpeed.y):this.view.win.scrollBy(this.scrollSpeed.x,this.scrollSpeed.y),this.dragging===!1&&this.select(this.lastEvent)}skipAtoms(t){let e=null;for(let i=0;i<t.ranges.length;i++){let s=t.ranges[i],r=null;if(s.empty){let o=ee(this.atoms,s.from,0);o!=s.from&&(r=v.cursor(o,-1))}else{let o=ee(this.atoms,s.from,-1),l=ee(this.atoms,s.to,1);(o!=s.from||l!=s.to)&&(r=v.range(s.from==s.anchor?o:l,s.from==s.head?o:l))}r&&(e||(e=t.ranges.slice()),e[i]=r)}return e?v.create(e,t.mainIndex):t}select(t){let{view:e}=this,i=this.skipAtoms(this.style.get(t,this.extend,this.multiple));(this.mustSelect||!i.eq(e.state.selection)||i.main.assoc!=e.state.selection.main.assoc&&this.dragging===!1)&&this.view.dispatch({selection:i,userEvent:"select.pointer"}),this.mustSelect=!1}update(t){t.docChanged&&this.dragging&&(this.dragging=this.dragging.map(t.changes)),this.style.update(t)&&setTimeout(()=>this.select(this.lastEvent),20)}}function xr(n,t){let e=n.state.facet(_i);return e.length?e[0](t):y.mac?t.metaKey:t.ctrlKey}function vr(n,t){let e=n.state.facet(ji);return e.length?e[0](t):y.mac?!t.altKey:!t.ctrlKey}function Mr(n,t){let{main:e}=n.state.selection;if(e.empty)return!1;let i=Gt(n.root);if(!i||i.rangeCount==0)return!0;let s=i.getRangeAt(0).getClientRects();for(let r=0;r<s.length;r++){let o=s[r];if(o.left<=t.clientX&&o.right>=t.clientX&&o.top<=t.clientY&&o.bottom>=t.clientY)return!0}return!1}function Ms(n,t){if(!t.bubbles)return!0;if(t.defaultPrevented)return!1;for(let e=t.target,i;e!=n.contentDOM;e=e.parentNode)if(!e||e.nodeType==11||(i=T.get(e))&&i.ignoreEvent(t))return!1;return!0}const E=Object.create(null),_e=Object.create(null),Cs=y.ie&&y.ie_version<15||y.ios&&y.webkit_version<604;function Cr(n){let t=n.dom.parentNode;if(!t)return;let e=t.appendChild(document.createElement("textarea"));e.style.cssText="position: fixed; left: -10000px; top: 10px",e.focus(),setTimeout(()=>{n.focus(),e.remove(),ks(n,e.value)},50)}function ks(n,t){let{state:e}=n,i,s=1,r=e.toText(t),o=r.lines==e.selection.ranges.length;if(je!=null&&e.selection.ranges.every(h=>h.empty)&&je==r.toString()){let h=-1;i=e.changeByRange(c=>{let a=e.doc.lineAt(c.from);if(a.from==h)return{range:c};h=a.from;let d=e.toText((o?r.line(s++).text:t)+e.lineBreak);return{changes:{from:a.from,insert:d},range:v.cursor(c.from+d.length)}})}else o?i=e.changeByRange(h=>{let c=r.line(s++);return{changes:{from:h.from,to:h.to,insert:c.text},range:v.cursor(h.from+c.length)}}):i=e.replaceSelection(r);n.dispatch(i,{userEvent:"input.paste",scrollIntoView:!0})}E.keydown=(n,t)=>{n.inputState.setSelectionOrigin("select"),t.keyCode==27&&(n.inputState.lastEscPress=Date.now())},E.touchstart=(n,t)=>{n.inputState.lastTouchTime=Date.now(),n.inputState.setSelectionOrigin("select.pointer")},E.touchmove=n=>{n.inputState.setSelectionOrigin("select.pointer")},_e.touchstart=_e.touchmove={passive:!0},E.mousedown=(n,t)=>{if(n.observer.flush(),n.inputState.lastTouchTime>Date.now()-2e3)return;let e=null;for(let i of n.state.facet(Gi))if(e=i(n,t),e)break;if(!e&&t.button==0&&(e=Dr(n,t)),e){let i=!n.hasFocus;n.inputState.startMouseSelection(new Sr(n,t,e,i)),i&&n.observer.ignore(()=>vi(n.contentDOM)),n.inputState.mouseSelection&&n.inputState.mouseSelection.start(t)}};function As(n,t,e,i){if(i==1)return v.cursor(t,e);if(i==2)return ar(n.state,t,e);{let s=I.find(n.docView,t),r=n.state.doc.lineAt(s?s.posAtEnd:t),o=s?s.posAtStart:r.from,l=s?s.posAtEnd:r.to;return l<n.state.doc.length&&l==r.to&&l++,v.range(o,l)}}let Ds=(n,t)=>n>=t.top&&n<=t.bottom,Os=(n,t,e)=>Ds(t,e)&&n>=e.left&&n<=e.right;function kr(n,t,e,i){let s=I.find(n.docView,t);if(!s)return 1;let r=t-s.posAtStart;if(r==0)return 1;if(r==s.length)return-1;let o=s.coordsAt(r,-1);if(o&&Os(e,i,o))return-1;let l=s.coordsAt(r,1);return l&&Os(e,i,l)?1:o&&Ds(i,o)?-1:1}function Ts(n,t){let e=n.posAtCoords({x:t.clientX,y:t.clientY},!1);return{pos:e,bias:kr(n,e,t.clientX,t.clientY)}}const Ar=y.ie&&y.ie_version<=11;let Rs=null,Bs=0,Ls=0;function Es(n){if(!Ar)return n.detail;let t=Rs,e=Ls;return Rs=n,Ls=Date.now(),Bs=!t||e>Date.now()-400&&Math.abs(t.clientX-n.clientX)<2&&Math.abs(t.clientY-n.clientY)<2?(Bs+1)%3:1}function Dr(n,t){let e=Ts(n,t),i=Es(t),s=n.state.selection;return{update(r){r.docChanged&&(e.pos=r.changes.mapPos(e.pos),s=s.map(r.changes))},get(r,o,l){let h=Ts(n,r),c,a=As(n,h.pos,h.bias,i);if(e.pos!=h.pos&&!o){let d=As(n,e.pos,e.bias,i),f=Math.min(d.from,a.from),u=Math.max(d.to,a.to);a=f<a.from?v.range(f,u):v.range(u,f)}return o?s.replaceRange(s.main.extend(a.from,a.to)):l&&i==1&&s.ranges.length>1&&(c=Or(s,h.pos))?c:l?s.addRange(a):v.create([a])}}}function Or(n,t){for(let e=0;e<n.ranges.length;e++){let{from:i,to:s}=n.ranges[e];if(i<=t&&s>=t)return v.create(n.ranges.slice(0,e).concat(n.ranges.slice(e+1)),n.mainIndex==e?0:n.mainIndex-(n.mainIndex>e?1:0))}return null}E.dragstart=(n,t)=>{let{selection:{main:e}}=n.state,{mouseSelection:i}=n.inputState;i&&(i.dragging=e),t.dataTransfer&&(t.dataTransfer.setData("Text",n.state.sliceDoc(e.from,e.to)),t.dataTransfer.effectAllowed="copyMove")};function Ps(n,t,e,i){if(!e)return;let s=n.posAtCoords({x:t.clientX,y:t.clientY},!1);t.preventDefault();let{mouseSelection:r}=n.inputState,o=i&&r&&r.dragging&&vr(n,t)?{from:r.dragging.from,to:r.dragging.to}:null,l={from:s,insert:e},h=n.state.changes(o?[o,l]:l);n.focus(),n.dispatch({changes:h,selection:{anchor:h.mapPos(s,-1),head:h.mapPos(s,1)},userEvent:o?"move.drop":"input.drop"})}E.drop=(n,t)=>{if(!t.dataTransfer)return;if(n.state.readOnly)return t.preventDefault();let e=t.dataTransfer.files;if(e&&e.length){t.preventDefault();let i=Array(e.length),s=0,r=()=>{++s==e.length&&Ps(n,t,i.filter(o=>o!=null).join(n.state.lineBreak),!1)};for(let o=0;o<e.length;o++){let l=new FileReader;l.onerror=r,l.onload=()=>{/[\x00-\x08\x0e-\x1f]{2}/.test(l.result)||(i[o]=l.result),r()},l.readAsText(e[o])}}else Ps(n,t,t.dataTransfer.getData("Text"),!0)},E.paste=(n,t)=>{if(n.state.readOnly)return t.preventDefault();n.observer.flush();let e=Cs?null:t.clipboardData;e?(ks(n,e.getData("text/plain")||e.getData("text/uri-text")),t.preventDefault()):Cr(n)};function Tr(n,t){let e=n.dom.parentNode;if(!e)return;let i=e.appendChild(document.createElement("textarea"));i.style.cssText="position: fixed; left: -10000px; top: 10px",i.value=t,i.focus(),i.selectionEnd=t.length,i.selectionStart=0,setTimeout(()=>{i.remove(),n.focus()},50)}function Rr(n){let t=[],e=[],i=!1;for(let s of n.selection.ranges)s.empty||(t.push(n.sliceDoc(s.from,s.to)),e.push(s));if(!t.length){let s=-1;for(let{from:r}of n.selection.ranges){let o=n.doc.lineAt(r);o.number>s&&(t.push(o.text),e.push({from:o.from,to:Math.min(n.doc.length,o.to+1)})),s=o.number}i=!0}return{text:t.join(n.lineBreak),ranges:e,linewise:i}}let je=null;E.copy=E.cut=(n,t)=>{let{text:e,ranges:i,linewise:s}=Rr(n.state);if(!e&&!s)return;je=s?e:null;let r=Cs?null:t.clipboardData;r?(t.preventDefault(),r.clearData(),r.setData("text/plain",e)):Tr(n,e),t.type=="cut"&&!n.state.readOnly&&n.dispatch({changes:i,scrollIntoView:!0,userEvent:"delete.cut"})};const Hs=Bn.define();function Ns(n,t){let e=[];for(let i of n.facet(Yi)){let s=i(n,t);s&&e.push(s)}return e?n.update({effects:e,annotations:Hs.of(!0)}):null}function Vs(n){setTimeout(()=>{let t=n.hasFocus;if(t!=n.inputState.notifiedFocused){let e=Ns(n.state,t);e?n.dispatch(e):n.update([])}},10)}E.focus=n=>{n.inputState.lastFocusTime=Date.now(),!n.scrollDOM.scrollTop&&(n.inputState.lastScrollTop||n.inputState.lastScrollLeft)&&(n.scrollDOM.scrollTop=n.inputState.lastScrollTop,n.scrollDOM.scrollLeft=n.inputState.lastScrollLeft),Vs(n)},E.blur=n=>{n.observer.clearSelectionRange(),Vs(n)},E.compositionstart=E.compositionupdate=n=>{n.inputState.compositionFirstChange==null&&(n.inputState.compositionFirstChange=!0),n.inputState.composing<0&&(n.inputState.composing=0)},E.compositionend=n=>{n.inputState.composing=-1,n.inputState.compositionEndedAt=Date.now(),n.inputState.compositionPendingKey=!0,n.inputState.compositionPendingChange=n.observer.pendingRecords().length>0,n.inputState.compositionFirstChange=null,y.chrome&&y.android?n.observer.flushSoon():n.inputState.compositionPendingChange?Promise.resolve().then(()=>n.observer.flush()):setTimeout(()=>{n.inputState.composing<0&&n.docView.hasComposition&&n.update([])},50)},E.contextmenu=n=>{n.inputState.lastContextMenu=Date.now()},E.beforeinput=(n,t)=>{var e;let i;if(y.chrome&&y.android&&(i=xs.find(s=>s.inputType==t.inputType))&&(n.observer.delayAndroidKey(i.key,i.keyCode),i.key=="Backspace"||i.key=="Delete")){let s=((e=window.visualViewport)===null||e===void 0?void 0:e.height)||0;setTimeout(()=>{var r;(((r=window.visualViewport)===null||r===void 0?void 0:r.height)||0)>s+10&&n.hasFocus&&(n.contentDOM.blur(),n.focus())},100)}};const Ws=new Set;function Br(n){Ws.has(n)||(Ws.add(n),n.addEventListener("copy",()=>{}),n.addEventListener("cut",()=>{}))}const Fs=["pre-wrap","normal","pre-line","break-spaces"];class zs{constructor(t){this.lineWrapping=t,this.doc=G.empty,this.heightSamples={},this.lineHeight=14,this.charWidth=7,this.textHeight=14,this.lineLength=30,this.heightChanged=!1}heightForGap(t,e){let i=this.doc.lineAt(e).number-this.doc.lineAt(t).number+1;return this.lineWrapping&&(i+=Math.max(0,Math.ceil((e-t-i*this.lineLength*.5)/this.lineLength))),this.lineHeight*i}heightForLine(t){return this.lineWrapping?(1+Math.max(0,Math.ceil((t-this.lineLength)/(this.lineLength-5))))*this.lineHeight:this.lineHeight}setDoc(t){return this.doc=t,this}mustRefreshForWrapping(t){return Fs.indexOf(t)>-1!=this.lineWrapping}mustRefreshForHeights(t){let e=!1;for(let i=0;i<t.length;i++){let s=t[i];s<0?i++:this.heightSamples[Math.floor(s*10)]||(e=!0,this.heightSamples[Math.floor(s*10)]=!0)}return e}refresh(t,e,i,s,r,o){let l=Fs.indexOf(t)>-1,h=Math.round(e)!=Math.round(this.lineHeight)||this.lineWrapping!=l;if(this.lineWrapping=l,this.lineHeight=e,this.charWidth=i,this.textHeight=s,this.lineLength=r,h){this.heightSamples={};for(let c=0;c<o.length;c++){let a=o[c];a<0?c++:this.heightSamples[Math.floor(a*10)]=!0}}return h}}class Is{constructor(t,e){this.from=t,this.heights=e,this.index=0}get more(){return this.index<this.heights.length}}class j{constructor(t,e,i,s,r){this.from=t,this.length=e,this.top=i,this.height=s,this._content=r}get type(){return typeof this._content=="number"?R.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 lt?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 j(this.from,this.length+t.length,this.top,this.height+t.height,e)}}var O=function(n){return n[n.ByPos=0]="ByPos",n[n.ByHeight=1]="ByHeight",n[n.ByPosNoHeight=2]="ByPosNoHeight",n}(O||(O={}));const ne=.001;class W{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,e){this.height!=e&&(Math.abs(this.height-e)>ne&&(t.heightChanged=!0),this.height=e)}replace(t,e,i){return W.of(i)}decomposeLeft(t,e){e.push(this)}decomposeRight(t,e){e.push(this)}applyChanges(t,e,i,s){let r=this,o=i.doc;for(let l=s.length-1;l>=0;l--){let{fromA:h,toA:c,fromB:a,toB:d}=s[l],f=r.lineAt(h,O.ByPosNoHeight,i.setDoc(e),0,0),u=f.to>=c?f:r.lineAt(c,O.ByPosNoHeight,i,0,0);for(d+=u.to-c,c=u.to;l>0&&f.from<=s[l-1].toA;)h=s[l-1].fromA,a=s[l-1].fromB,l--,h<f.from&&(f=r.lineAt(h,O.ByPosNoHeight,i,0,0));a+=f.from-h,h=f.from;let p=ci.build(i.setDoc(o),t,a,d);r=r.replace(h,c,p)}return r.updateHeight(i,0)}static empty(){return new q(0,0)}static of(t){if(t.length==1)return t[0];let e=0,i=t.length,s=0,r=0;for(;;)if(e==i)if(s>r*2){let l=t[e-1];l.break?t.splice(--e,1,l.left,null,l.right):t.splice(--e,1,l.left,l.right),i+=1+l.break,s-=l.size}else if(r>s*2){let l=t[i];l.break?t.splice(i,1,l.left,null,l.right):t.splice(i,1,l.left,l.right),i+=2+l.break,r-=l.size}else break;else if(s<r){let l=t[e++];l&&(s+=l.size)}else{let l=t[--i];l&&(r+=l.size)}let o=0;return t[e-1]==null?(o=1,e--):t[e]==null&&(o=1,i++),new Lr(W.of(t.slice(0,e)),o,W.of(t.slice(i)))}}W.prototype.size=1;class Ks extends W{constructor(t,e,i){super(t,e),this.deco=i}blockAt(t,e,i,s){return new j(s,this.length,i,this.height,this.deco||0)}lineAt(t,e,i,s,r){return this.blockAt(0,i,s,r)}forEachLine(t,e,i,s,r,o){t<=r+this.length&&e>=r&&o(this.blockAt(0,i,s,r))}updateHeight(t,e=0,i=!1,s){return s&&s.from<=e&&s.more&&this.setHeight(t,s.heights[s.index++]),this.outdated=!1,this}toString(){return`block(${this.length})`}}class q extends Ks{constructor(t,e){super(t,e,null),this.collapsed=0,this.widgetHeight=0,this.breaks=0}blockAt(t,e,i,s){return new j(s,this.length,i,this.height,this.breaks)}replace(t,e,i){let s=i[0];return i.length==1&&(s instanceof q||s instanceof H&&s.flags&4)&&Math.abs(this.length-s.length)<10?(s instanceof H?s=new q(s.length,this.height):s.height=this.height,this.outdated||(s.outdated=!1),s):W.of(i)}updateHeight(t,e=0,i=!1,s){return s&&s.from<=e&&s.more?this.setHeight(t,s.heights[s.index++]):(i||this.outdated)&&this.setHeight(t,Math.max(this.widgetHeight,t.heightForLine(this.length-this.collapsed))+this.breaks*t.lineHeight),this.outdated=!1,this}toString(){return`line(${this.length}${this.collapsed?-this.collapsed:""}${this.widgetHeight?":"+this.widgetHeight:""})`}}class H extends W{constructor(t){super(t,0)}heightMetrics(t,e){let i=t.doc.lineAt(e).number,s=t.doc.lineAt(e+this.length).number,r=s-i+1,o,l=0;if(t.lineWrapping){let h=Math.min(this.height,t.lineHeight*r);o=h/r,this.length>r+1&&(l=(this.height-h)/(this.length-r-1))}else o=this.height/r;return{firstLine:i,lastLine:s,perLine:o,perChar:l}}blockAt(t,e,i,s){let{firstLine:r,lastLine:o,perLine:l,perChar:h}=this.heightMetrics(e,s);if(e.lineWrapping){let c=s+Math.round(Math.max(0,Math.min(1,(t-i)/this.height))*this.length),a=e.doc.lineAt(c),d=l+a.length*h,f=Math.max(i,t-d/2);return new j(a.from,a.length,f,d,0)}else{let c=Math.max(0,Math.min(o-r,Math.floor((t-i)/l))),{from:a,length:d}=e.doc.line(r+c);return new j(a,d,i+l*c,l,0)}}lineAt(t,e,i,s,r){if(e==O.ByHeight)return this.blockAt(t,i,s,r);if(e==O.ByPosNoHeight){let{from:u,to:p}=i.doc.lineAt(t);return new j(u,p-u,0,0,0)}let{firstLine:o,perLine:l,perChar:h}=this.heightMetrics(i,r),c=i.doc.lineAt(t),a=l+c.length*h,d=c.number-o,f=s+l*d+h*(c.from-r-d);return new j(c.from,c.length,Math.max(s,Math.min(f,s+this.height-a)),a,0)}forEachLine(t,e,i,s,r,o){t=Math.max(t,r),e=Math.min(e,r+this.length);let{firstLine:l,perLine:h,perChar:c}=this.heightMetrics(i,r);for(let a=t,d=s;a<=e;){let f=i.doc.lineAt(a);if(a==t){let p=f.number-l;d+=h*p+c*(t-r-p)}let u=h+c*f.length;o(new j(f.from,f.length,d,u,0)),d+=u,a=f.to+1}}replace(t,e,i){let s=this.length-e;if(s>0){let r=i[i.length-1];r instanceof H?i[i.length-1]=new H(r.length+s):i.push(null,new H(s-1))}if(t>0){let r=i[0];r instanceof H?i[0]=new H(t+r.length):i.unshift(new H(t-1),null)}return W.of(i)}decomposeLeft(t,e){e.push(new H(t-1),null)}decomposeRight(t,e){e.push(null,new H(this.length-t-1))}updateHeight(t,e=0,i=!1,s){let r=e+this.length;if(s&&s.from<=e+this.length&&s.more){let o=[],l=Math.max(e,s.from),h=-1;for(s.from>e&&o.push(new H(s.from-e-1).updateHeight(t,e));l<=r&&s.more;){let a=t.doc.lineAt(l).length;o.length&&o.push(null);let d=s.heights[s.index++];h==-1?h=d:Math.abs(d-h)>=ne&&(h=-2);let f=new q(a,d);f.outdated=!1,o.push(f),l+=a+1}l<=r&&o.push(null,new H(r-l).updateHeight(t,l));let c=W.of(o);return(h<0||Math.abs(c.height-this.height)>=ne||Math.abs(h-this.heightMetrics(t,e).perLine)>=ne)&&(t.heightChanged=!0),c}else(i||this.outdated)&&(this.setHeight(t,t.heightForGap(e,e+this.length)),this.outdated=!1);return this}toString(){return`gap(${this.length})`}}class Lr extends W{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 r=i+this.left.height;return t<r?this.left.blockAt(t,e,i,s):this.right.blockAt(t,e,r,s+this.left.length+this.break)}lineAt(t,e,i,s,r){let o=s+this.left.height,l=r+this.left.length+this.break,h=e==O.ByHeight?t<o:t<l,c=h?this.left.lineAt(t,e,i,s,r):this.right.lineAt(t,e,i,o,l);if(this.break||(h?c.to<l:c.from>l))return c;let a=e==O.ByPosNoHeight?O.ByPosNoHeight:O.ByPos;return h?c.join(this.right.lineAt(l,a,i,o,l)):this.left.lineAt(l,a,i,s,r).join(c)}forEachLine(t,e,i,s,r,o){let l=s+this.left.height,h=r+this.left.length+this.break;if(this.break)t<h&&this.left.forEachLine(t,e,i,s,r,o),e>=h&&this.right.forEachLine(t,e,i,l,h,o);else{let c=this.lineAt(h,O.ByPos,i,s,r);t<c.from&&this.left.forEachLine(t,c.from-1,i,s,r,o),c.to>=t&&c.from<=e&&o(c),e>c.to&&this.right.forEachLine(c.to+1,e,i,l,h,o)}}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 r=[];t>0&&this.decomposeLeft(t,r);let o=r.length;for(let l of i)r.push(l);if(t>0&&qs(r,o-1),e<this.length){let l=r.length;this.decomposeRight(e,r),qs(r,l)}return W.of(r)}decomposeLeft(t,e){let i=this.left.length;if(t<=i)return this.left.decomposeLeft(t,e);e.push(this.left),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){return t.size>2*e.size||e.size>2*t.size?W.of(this.break?[t,null,e]:[t,e]):(this.left=t,this.right=e,this.height=t.height+e.height,this.outdated=t.outdated||e.outdated,this.size=t.size+e.size,this.length=t.length+this.break+e.length,this)}updateHeight(t,e=0,i=!1,s){let{left:r,right:o}=this,l=e+r.length+this.break,h=null;return s&&s.from<=e+r.length&&s.more?h=r=r.updateHeight(t,e,i,s):r.updateHeight(t,e,i),s&&s.from<=l+o.length&&s.more?h=o=o.updateHeight(t,l,i,s):o.updateHeight(t,l,i),h?this.balanced(r,o):(this.height=this.left.height+this.right.height,this.outdated=!1,this)}toString(){return this.left+(this.break?" ":"-")+this.right}}function qs(n,t){let e,i;n[t]==null&&(e=n[t-1])instanceof H&&(i=n[t+1])instanceof H&&n.splice(t-1,3,new H(e.length+1+i.length))}const Er=5;class ci{constructor(t,e){this.pos=t,this.oracle=e,this.nodes=[],this.lineStart=-1,this.lineEnd=-1,this.covering=null,this.writtenTo=t}get isCovered(){return this.covering&&this.nodes[this.nodes.length-1]==this.covering}span(t,e){if(this.lineStart>-1){let i=Math.min(e,this.lineEnd),s=this.nodes[this.nodes.length-1];s instanceof q?s.length+=i-this.pos:(i>this.pos||!this.isCovered)&&this.nodes.push(new q(i-this.pos,-1)),this.writtenTo=i,e>i&&(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,r=i.widget?i.widget.lineBreaks:0;s<0&&(s=this.oracle.lineHeight);let o=e-t;i.block?this.addBlock(new Ks(o,s,i)):(o||r||s>=Er)&&this.addLineDeco(s,r,o)}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,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 q(this.pos-t,-1)),this.writtenTo=this.pos}blankContent(t,e){let i=new H(e-t);return this.oracle.doc.lineAt(t).to==e&&(i.flags|=4),i}ensureLine(){this.enterLine();let t=this.nodes.length?this.nodes[this.nodes.length-1]:null;if(t instanceof q)return t;let e=new q(0,-1);return this.nodes.push(e),e}addBlock(t){var e;this.enterLine();let i=(e=t.deco)===null||e===void 0?void 0:e.type;i==R.WidgetAfter&&!this.isCovered&&this.ensureLine(),this.nodes.push(t),this.writtenTo=this.pos=this.pos+t.length,i!=R.WidgetBefore&&(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 q)&&!this.isCovered?this.nodes.push(new q(0,-1)):(this.writtenTo<this.pos||e==null)&&this.nodes.push(this.blankContent(this.writtenTo,this.pos));let i=t;for(let s of this.nodes)s instanceof q&&s.updateHeight(this.oracle,i),i+=s?s.length:1;return this.nodes}static build(t,e,i,s){let r=new ci(i,t);return F.spans(e,i,s,r,0),r.finish(i)}}function Pr(n,t,e){let i=new Hr;return F.compare(n,t,e,i,0),i.changes}class Hr{constructor(){this.changes=[]}compareRange(){}comparePoint(t,e,i,s){(t<e||i&&i.heightRelevant||s&&s.heightRelevant)&&Ee(t,e,this.changes,5)}}function Nr(n,t){let e=n.getBoundingClientRect(),i=n.ownerDocument,s=i.defaultView||window,r=Math.max(0,e.left),o=Math.min(s.innerWidth,e.right),l=Math.max(0,e.top),h=Math.min(s.innerHeight,e.bottom);for(let c=n.parentNode;c&&c!=i.body;)if(c.nodeType==1){let a=c,d=window.getComputedStyle(a);if((a.scrollHeight>a.clientHeight||a.scrollWidth>a.clientWidth)&&d.overflow!="visible"){let f=a.getBoundingClientRect();r=Math.max(r,f.left),o=Math.min(o,f.right),l=Math.max(l,f.top),h=c==n.parentNode?f.bottom:Math.min(h,f.bottom)}c=d.position=="absolute"||d.position=="fixed"?a.offsetParent:a.parentNode}else if(c.nodeType==11)c=c.host;else break;return{left:r-e.left,right:Math.max(r,o)-e.left,top:l-(e.top+t),bottom:Math.max(l,h)-(e.top+t)}}function Vr(n,t){let e=n.getBoundingClientRect();return{left:0,right:e.right-e.left,top:t,bottom:e.bottom-(e.top+t)}}class Ge{constructor(t,e,i){this.from=t,this.to=e,this.size=i}static same(t,e){if(t.length!=e.length)return!1;for(let i=0;i<t.length;i++){let s=t[i],r=e[i];if(s.from!=r.from||s.to!=r.to||s.size!=r.size)return!1}return!0}draw(t){return B.replace({widget:new Wr(this.size,t)}).range(this.from,this.to)}}class Wr extends dt{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");return this.vertical?t.style.height=this.size+"px":(t.style.width=this.size+"px",t.style.height="2px",t.style.display="inline-block"),t}get estimatedHeight(){return this.vertical?this.size:-1}}class _s{constructor(t){this.state=t,this.pixelViewport={left:0,right:window.innerWidth,top:0,bottom:0},this.inView=!0,this.paddingTop=0,this.paddingBottom=0,this.contentDOMWidth=0,this.contentDOMHeight=0,this.editorHeight=0,this.editorWidth=0,this.scrollTop=0,this.scrolledToBottom=!0,this.scrollAnchorPos=0,this.scrollAnchorHeight=-1,this.scaler=js,this.scrollTarget=null,this.printing=!1,this.mustMeasureContent=!0,this.defaultTextDirection=L.LTR,this.visibleRanges=[],this.mustEnforceCursorAssoc=!1;let e=t.facet(te).some(i=>typeof i!="function"&&i.class=="cm-lineWrapping");this.heightOracle=new zs(e),this.stateDeco=t.facet(Rt).filter(i=>typeof i!="function"),this.heightMap=W.empty().applyChanges(this.stateDeco,G.empty,this.heightOracle.setDoc(t.doc),[new _(0,0,0,t.doc.length)]),this.viewport=this.getViewport(0,null),this.updateViewportLines(),this.updateForViewport(),this.lineGaps=this.ensureLineGaps([]),this.lineGapDeco=B.set(this.lineGaps.map(i=>i.draw(!1))),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:r,to:o})=>s>=r&&s<=o)){let{from:r,to:o}=this.lineBlockAt(s);t.push(new re(r,o))}}this.viewports=t.sort((i,s)=>i.from-s.from),this.scaler=this.heightMap.height<=7e6?js:new Ir(this.heightOracle,this.heightMap,this.viewports)}updateViewportLines(){this.viewportLines=[],this.heightMap.forEachLine(this.viewport.from,this.viewport.to,this.heightOracle.setDoc(this.state.doc),0,0,t=>{this.viewportLines.push(this.scaler.scale==1?t:Et(t,this.scaler))})}update(t,e=null){this.state=t.state;let i=this.stateDeco;this.stateDeco=this.state.facet(Rt).filter(a=>typeof a!="function");let s=t.changedRanges,r=_.extendWithRanges(s,Pr(i,this.stateDeco,t?t.changes:pi.empty(this.state.doc.length))),o=this.heightMap.height,l=this.scrolledToBottom?null:this.scrollAnchorAt(this.scrollTop);this.heightMap=this.heightMap.applyChanges(this.stateDeco,t.startState.doc,this.heightOracle.setDoc(this.state.doc),r),this.heightMap.height!=o&&(t.flags|=2),l?(this.scrollAnchorPos=t.changes.mapPos(l.from,-1),this.scrollAnchorHeight=l.top):(this.scrollAnchorPos=-1,this.scrollAnchorHeight=this.heightMap.height);let h=r.length?this.mapViewport(this.viewport,t.changes):this.viewport;(e&&(e.range.head<h.from||e.range.head>h.to)||!this.viewportIsAppropriate(h))&&(h=this.getViewport(0,e));let c=!t.changes.empty||t.flags&2||h.from!=this.viewport.from||h.to!=this.viewport.to;this.viewport=h,this.updateForViewport(),c&&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(),e&&(this.scrollTarget=e),!this.mustEnforceCursorAssoc&&t.selectionSet&&t.view.lineWrapping&&t.state.selection.main.empty&&t.state.selection.main.assoc&&!t.state.facet(Ji)&&(this.mustEnforceCursorAssoc=!0)}measure(t){let e=t.contentDOM,i=window.getComputedStyle(e),s=this.heightOracle,r=i.whiteSpace;this.defaultTextDirection=i.direction=="rtl"?L.RTL:L.LTR;let o=this.heightOracle.mustRefreshForWrapping(r),l=e.getBoundingClientRect(),h=o||this.mustMeasureContent||this.contentDOMHeight!=l.height;this.contentDOMHeight=l.height,this.mustMeasureContent=!1;let c=0,a=0,d=parseInt(i.paddingTop)||0,f=parseInt(i.paddingBottom)||0;(this.paddingTop!=d||this.paddingBottom!=f)&&(this.paddingTop=d,this.paddingBottom=f,c|=10),this.editorWidth!=t.scrollDOM.clientWidth&&(s.lineWrapping&&(h=!0),this.editorWidth=t.scrollDOM.clientWidth,c|=8),this.scrollTop!=t.scrollDOM.scrollTop&&(this.scrollAnchorHeight=-1,this.scrollTop=t.scrollDOM.scrollTop),this.scrolledToBottom=ki(t.scrollDOM);let u=(this.printing?Vr:Nr)(e,this.paddingTop),p=u.top-this.pixelViewport.top,g=u.bottom-this.pixelViewport.bottom;this.pixelViewport=u;let m=this.pixelViewport.bottom>this.pixelViewport.top&&this.pixelViewport.right>this.pixelViewport.left;if(m!=this.inView&&(this.inView=m,m&&(h=!0)),!this.inView&&!this.scrollTarget)return 0;let b=l.width;if((this.contentDOMWidth!=b||this.editorHeight!=t.scrollDOM.clientHeight)&&(this.contentDOMWidth=l.width,this.editorHeight=t.scrollDOM.clientHeight,c|=8),h){let k=t.docView.measureVisibleLineHeights(this.viewport);if(s.mustRefreshForHeights(k)&&(o=!0),o||s.lineWrapping&&Math.abs(b-this.contentDOMWidth)>s.charWidth){let{lineHeight:w,charWidth:x,textHeight:M}=t.docView.measureTextSize();o=w>0&&s.refresh(r,w,x,M,b/x,k),o&&(t.docView.minWidth=0,c|=8)}p>0&&g>0?a=Math.max(p,g):p<0&&g<0&&(a=Math.min(p,g)),s.heightChanged=!1;for(let w of this.viewports){let x=w.from==this.viewport.from?k:t.docView.measureVisibleLineHeights(w);this.heightMap=(o?W.empty().applyChanges(this.stateDeco,G.empty,this.heightOracle,[new _(0,0,0,t.state.doc.length)]):this.heightMap).updateHeight(s,0,o,new Is(w.from,x))}s.heightChanged&&(c|=2)}let S=!this.viewportIsAppropriate(this.viewport,a)||this.scrollTarget&&(this.scrollTarget.range.head<this.viewport.from||this.scrollTarget.range.head>this.viewport.to);return S&&(this.viewport=this.getViewport(a,this.scrollTarget)),this.updateForViewport(),(c&2||S)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(o?[]:this.lineGaps,t)),c|=this.computeVisibleRanges(),this.mustEnforceCursorAssoc&&(this.mustEnforceCursorAssoc=!1,t.docView.enforceCursorAssoc()),c}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)),s=this.heightMap,r=this.heightOracle,{visibleTop:o,visibleBottom:l}=this,h=new re(s.lineAt(o-i*1e3,O.ByHeight,r,0,0).from,s.lineAt(l+(1-i)*1e3,O.ByHeight,r,0,0).to);if(e){let{head:c}=e.range;if(c<h.from||c>h.to){let a=Math.min(this.editorHeight,this.pixelViewport.bottom-this.pixelViewport.top),d=s.lineAt(c,O.ByPos,r,0,0),f;e.y=="center"?f=(d.top+d.bottom)/2-a/2:e.y=="start"||e.y=="nearest"&&c<h.from?f=d.top:f=d.bottom-a,h=new re(s.lineAt(f-1e3/2,O.ByHeight,r,0,0).from,s.lineAt(f+a+1e3/2,O.ByHeight,r,0,0).to)}}return h}mapViewport(t,e){let i=e.mapPos(t.from,-1),s=e.mapPos(t.to,1);return new re(this.heightMap.lineAt(i,O.ByPos,this.heightOracle,0,0).from,this.heightMap.lineAt(s,O.ByPos,this.heightOracle,0,0).to)}viewportIsAppropriate({from:t,to:e},i=0){if(!this.inView)return!0;let{top:s}=this.heightMap.lineAt(t,O.ByPos,this.heightOracle,0,0),{bottom:r}=this.heightMap.lineAt(e,O.ByPos,this.heightOracle,0,0),{visibleTop:o,visibleBottom:l}=this;return(t==0||s<=o-Math.max(10,Math.min(-i,250)))&&(e==this.state.doc.length||r>=l+Math.max(10,Math.min(i,250)))&&s>o-2*1e3&&r<l+2*1e3}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 Ge(e.mapPos(s.from),e.mapPos(s.to),s.size));return i}ensureLineGaps(t,e){let i=this.heightOracle.lineWrapping,s=i?1e4:2e3,r=s>>1,o=s<<1;if(this.defaultTextDirection!=L.LTR&&!i)return[];let l=[],h=(c,a,d,f)=>{if(a-c<r)return;let u=this.state.selection.main,p=[u.from];u.empty||p.push(u.to);for(let m of p)if(m>c&&m<a){h(c,m-10,d,f),h(m+10,a,d,f);return}let g=zr(t,m=>m.from>=d.from&&m.to<=d.to&&Math.abs(m.from-c)<r&&Math.abs(m.to-a)<r&&!p.some(b=>m.from<b&&m.to>b));if(!g){if(a<d.to&&e&&i&&e.visibleRanges.some(m=>m.from<=a&&m.to>=a)){let m=e.moveToLineBoundary(v.cursor(a),!1,!0).head;m>c&&(a=m)}g=new Ge(c,a,this.gapSize(d,c,a,f))}l.push(g)};for(let c of this.viewportLines){if(c.length<o)continue;let a=Fr(c.from,c.to,this.stateDeco);if(a.total<o)continue;let d=this.scrollTarget?this.scrollTarget.range.head:null,f,u;if(i){let p=s/this.heightOracle.lineLength*this.heightOracle.lineHeight,g,m;if(d!=null){let b=le(a,d),S=((this.visibleBottom-this.visibleTop)/2+p)/c.height;g=b-S,m=b+S}else g=(this.visibleTop-c.top-p)/c.height,m=(this.visibleBottom-c.top+p)/c.height;f=oe(a,g),u=oe(a,m)}else{let p=a.total*this.heightOracle.charWidth,g=s*this.heightOracle.charWidth,m,b;if(d!=null){let S=le(a,d),k=((this.pixelViewport.right-this.pixelViewport.left)/2+g)/p;m=S-k,b=S+k}else m=(this.pixelViewport.left-g)/p,b=(this.pixelViewport.right+g)/p;f=oe(a,m),u=oe(a,b)}f>c.from&&h(c.from,f,c,a),u<c.to&&h(u,c.to,c,a)}return l}gapSize(t,e,i,s){let r=le(s,i)-le(s,e);return this.heightOracle.lineWrapping?t.height*r:s.total*this.heightOracle.charWidth*r}updateLineGaps(t){Ge.same(t,this.lineGaps)||(this.lineGaps=t,this.lineGapDeco=B.set(t.map(e=>e.draw(this.heightOracle.lineWrapping))))}computeVisibleRanges(){let t=this.stateDeco;this.lineGaps.length&&(t=t.concat(this.lineGapDeco));let e=[];F.spans(t,this.viewport.from,this.viewport.to,{span(s,r){e.push({from:s,to:r})},point(){}},20);let i=e.length!=this.visibleRanges.length||this.visibleRanges.some((s,r)=>s.from!=e[r].from||s.to!=e[r].to);return this.visibleRanges=e,i?4:0}lineBlockAt(t){return t>=this.viewport.from&&t<=this.viewport.to&&this.viewportLines.find(e=>e.from<=t&&e.to>=t)||Et(this.heightMap.lineAt(t,O.ByPos,this.heightOracle,0,0),this.scaler)}lineBlockAtHeight(t){return Et(this.heightMap.lineAt(this.scaler.fromDOM(t),O.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 Et(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 re{constructor(t,e){this.from=t,this.to=e}}function Fr(n,t,e){let i=[],s=n,r=0;return F.spans(e,n,t,{span(){},point(o,l){o>s&&(i.push({from:s,to:o}),r+=o-s),s=l}},20),s<t&&(i.push({from:s,to:t}),r+=t-s),{total:r,ranges:i}}function oe({total:n,ranges:t},e){if(e<=0)return t[0].from;if(e>=1)return t[t.length-1].to;let i=Math.floor(n*e);for(let s=0;;s++){let{from:r,to:o}=t[s],l=o-r;if(i<=l)return r+i;i-=l}}function le(n,t){let e=0;for(let{from:i,to:s}of n.ranges){if(t<=s){e+=t-i;break}e+=s-i}return e/n.total}function zr(n,t){for(let e of n)if(t(e))return e}const js={toDOM(n){return n},fromDOM(n){return n},scale:1};class Ir{constructor(t,e,i){let s=0,r=0,o=0;this.viewports=i.map(({from:l,to:h})=>{let c=e.lineAt(l,O.ByPos,t,0,0).top,a=e.lineAt(h,O.ByPos,t,0,0).bottom;return s+=a-c,{from:l,to:h,top:c,bottom:a,domTop:0,domBottom:0}}),this.scale=(7e6-s)/(e.height-s);for(let l of this.viewports)l.domTop=o+(l.top-r)*this.scale,o=l.domBottom=l.domTop+(l.bottom-l.top),r=l.bottom}toDOM(t){for(let e=0,i=0,s=0;;e++){let r=e<this.viewports.length?this.viewports[e]:null;if(!r||t<r.top)return s+(t-i)*this.scale;if(t<=r.bottom)return r.domTop+(t-r.top);i=r.bottom,s=r.domBottom}}fromDOM(t){for(let e=0,i=0,s=0;;e++){let r=e<this.viewports.length?this.viewports[e]:null;if(!r||t<r.domTop)return i+(t-s)/this.scale;if(t<=r.domBottom)return r.top+(t-r.domTop);i=r.bottom,s=r.domBottom}}}function Et(n,t){if(t.scale==1)return n;let e=t.toDOM(n.top),i=t.toDOM(n.bottom);return new j(n.from,n.length,e,i-e,Array.isArray(n._content)?n._content.map(s=>Et(s,t)):n._content)}const he=C.define({combine:n=>n.join(" ")}),$e=C.define({combine:n=>n.indexOf(!0)>-1}),Ue=bt.newName(),Gs=bt.newName(),$s=bt.newName(),Us={"&light":"."+Gs,"&dark":"."+$s};function Ye(n,t,e){return new bt(t,{finish(i){return/&/.test(i)?i.replace(/&\w*/,s=>{if(s=="&")return n;if(!e||!e[s])throw new RangeError(`Unsupported selector: ${s}`);return e[s]}):n+" "+i}})}const Kr=Ye("."+Ue,{"&":{position:"relative !important",boxSizing:"border-box","&.cm-focused":{outline:"1px dotted #212121"},display:"flex !important",flexDirection:"column"},".cm-scroller":{display:"flex !important",alignItems:"flex-start !important",fontFamily:"monospace",lineHeight:1.4,height:"100%",overflowX:"auto",position:"relative",zIndex:0},".cm-content":{margin:0,flexGrow:2,flexShrink:0,display:"block",whiteSpace:"pre",wordWrap:"normal",boxSizing:"border-box",padding:"4px 0",outline:"none","&[contenteditable=true]":{WebkitUserModify:"read-write-plaintext-only"}},".cm-lineWrapping":{whiteSpace_fallback:"pre-wrap",whiteSpace:"break-spaces",wordBreak:"break-word",overflowWrap:"anywhere",flexShrink:1},"&light .cm-content":{caretColor:"black"},"&dark .cm-content":{caretColor:"white"},".cm-line":{display:"block",padding:"0 2px 0 6px"},".cm-layer":{position:"absolute",left:0,top:0,contain:"size style","& > *":{position:"absolute"}},"&light .cm-selectionBackground":{background:"#d9d9d9"},"&dark .cm-selectionBackground":{background:"#222"},"&light.cm-focused > .cm-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:"#444"},".cm-dropCursor":{position:"absolute"},"&.cm-focused > .cm-scroller > .cm-cursorLayer .cm-cursor":{display:"block"},"&light .cm-activeLine":{backgroundColor:"#cceeff44"},"&dark .cm-activeLine":{backgroundColor:"#99eeff33"},"&light .cm-specialChar":{color:"red"},"&dark .cm-specialChar":{color:"#f78"},".cm-gutters":{flexShrink:0,display:"flex",height:"100%",boxSizing:"border-box",insetInlineStart:0,zIndex:200},"&light .cm-gutters":{backgroundColor:"#f5f5f5",color:"#6c6c6c",borderRight:"1px solid #ddd"},"&dark .cm-gutters":{backgroundColor:"#333338",color:"#ccc"},".cm-gutter":{display:"flex !important",flexDirection:"column",flexShrink:0,boxSizing:"border-box",minHeight:"100%",overflow:"hidden"},".cm-gutterElement":{boxSizing:"border-box"},".cm-lineNumbers .cm-gutterElement":{padding:"0 3px 0 5px",minWidth:"20px",textAlign:"right",whiteSpace:"nowrap"},"&light .cm-activeLineGutter":{backgroundColor:"#e2f2ff"},"&dark .cm-activeLineGutter":{backgroundColor:"#222227"},".cm-panels":{boxSizing:"border-box",position:"sticky",left:0,right:0},"&light .cm-panels":{backgroundColor:"#f5f5f5",color:"black"},"&light .cm-panels-top":{borderBottom:"1px solid #ddd"},"&light .cm-panels-bottom":{borderTop:"1px solid #ddd"},"&dark .cm-panels":{backgroundColor:"#333338",color:"white"},".cm-tab":{display:"inline-block",overflow:"hidden",verticalAlign:"bottom"},".cm-widgetBuffer":{verticalAlign:"text-top",height:"1em",width:0,display:"inline"},".cm-placeholder":{color:"#888",display:"inline-block",verticalAlign:"top"},".cm-highlightSpace:before":{content:"attr(data-display)",position:"absolute",pointerEvents:"none",color:"#888"},".cm-highlightTab":{backgroundImage:`url('data:image/svg+xml,<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"}},Us);class qr{constructor(t,e,i,s){this.typeOver=s,this.bounds=null,this.text="";let{impreciseHead:r,impreciseAnchor:o}=t.docView;if(t.state.readOnly&&e>-1)this.newSel=null;else if(e>-1&&(this.bounds=t.docView.domBoundsAround(e,i,0))){let l=r||o?[]:Gr(t),h=new Ri(l,t.state);h.readRange(this.bounds.startDOM,this.bounds.endDOM),this.text=h.text,this.newSel=$r(l,this.bounds.from)}else{let l=t.observer.selectionRange,h=r&&r.node==l.focusNode&&r.offset==l.focusOffset||!Ce(t.contentDOM,l.focusNode)?t.state.selection.main.head:t.docView.posFromDOM(l.focusNode,l.focusOffset),c=o&&o.node==l.anchorNode&&o.offset==l.anchorOffset||!Ce(t.contentDOM,l.anchorNode)?t.state.selection.main.anchor:t.docView.posFromDOM(l.anchorNode,l.anchorOffset);this.newSel=v.single(c,h)}}}function Ys(n,t){let e,{newSel:i}=t,s=n.state.selection.main,r=n.inputState.lastKeyTime>Date.now()-100?n.inputState.lastKeyCode:-1;if(t.bounds){let{from:o,to:l}=t.bounds,h=s.from,c=null;(r===8||y.android&&t.text.length<l-o)&&(h=s.to,c="end");let a=jr(n.state.doc.sliceString(o,l,xt),t.text,h-o,c);a&&(y.chrome&&r==13&&a.toB==a.from+2&&t.text.slice(a.from,a.toB)==xt+xt&&a.toB--,e={from:o+a.from,to:o+a.toA,insert:G.of(t.text.slice(a.from,a.toB).split(xt))})}else i&&(!n.hasFocus&&n.state.facet(Qt)||i.main.eq(s))&&(i=null);if(!e&&!i)return!1;if(!e&&t.typeOver&&!s.empty&&i&&i.main.empty?e={from:s.from,to:s.to,insert:n.state.doc.slice(s.from,s.to)}:e&&e.from>=s.from&&e.to<=s.to&&(e.from!=s.from||e.to!=s.to)&&s.to-s.from-(e.to-e.from)<=4?e={from:s.from,to:s.to,insert:n.state.doc.slice(s.from,e.from).append(e.insert).append(n.state.doc.slice(e.to,s.to))}:(y.mac||y.android)&&e&&e.from==e.to&&e.from==s.head-1&&/^\. ?$/.test(e.insert.toString())&&n.contentDOM.getAttribute("autocorrect")=="off"?(i&&e.insert.length==2&&(i=v.single(i.main.anchor-1,i.main.head-1)),e={from:s.from,to:s.to,insert:G.of([" "])}):y.chrome&&e&&e.from==e.to&&e.from==s.head&&e.insert.toString()==`
 `&&n.lineWrapping&&(i&&(i=v.single(i.main.anchor-1,i.main.head-1)),e={from:s.from,to:s.to,insert:G.of([" "])}),e){if(y.ios&&n.inputState.flushIOSKey(n)||y.android&&(e.from==s.from&&e.to==s.to&&e.insert.length==1&&e.insert.lines==2&&St(n.contentDOM,"Enter",13)||(e.from==s.from-1&&e.to==s.to&&e.insert.length==0||r==8&&e.insert.length<e.to-e.from&&e.to>s.head)&&St(n.contentDOM,"Backspace",8)||e.from==s.from&&e.to==s.to+1&&e.insert.length==0&&St(n.contentDOM,"Delete",46)))return!0;let o=e.insert.toString();n.inputState.composing>=0&&n.inputState.composing++;let l,h=()=>l||(l=_r(n,e,i));return n.state.facet(Ui).some(c=>c(n,e.from,e.to,o,h))||n.dispatch(h()),!0}else if(i&&!i.main.eq(s)){let o=!1,l="select";return n.inputState.lastSelectionTime>Date.now()-50&&(n.inputState.lastSelectionOrigin=="select"&&(o=!0),l=n.inputState.lastSelectionOrigin),n.dispatch({selection:i,scrollIntoView:o,userEvent:l}),!0}else return!1}function _r(n,t,e){let i,s=n.state,r=s.selection.main;if(t.from>=r.from&&t.to<=r.to&&t.to-t.from>=(r.to-r.from)/3&&(!e||e.main.empty&&e.main.from==t.from+t.insert.length)&&n.inputState.composing<0){let l=r.from<t.from?s.sliceDoc(r.from,t.from):"",h=r.to>t.to?s.sliceDoc(t.to,r.to):"";i=s.replaceSelection(n.state.toText(l+t.insert.sliceString(0,void 0,n.state.lineBreak)+h))}else{let l=s.changes(t),h=e&&e.main.to<=l.newLength?e.main:void 0;if(s.selection.ranges.length>1&&n.inputState.composing>=0&&t.to<=r.to&&t.to>=r.to-10){let c=n.state.sliceDoc(t.from,t.to),a=us(n,t.insert.length-(t.to-t.from))||n.state.doc.lineAt(r.head),d=r.to-t.to,f=r.to-r.from;i=s.changeByRange(u=>{if(u.from==r.from&&u.to==r.to)return{changes:l,range:h||u.map(l)};let p=u.to-d,g=p-c.length;if(u.to-u.from!=f||n.state.sliceDoc(g,p)!=c||a&&u.to>=a.from&&u.from<=a.to)return{range:u};let m=s.changes({from:g,to:p,insert:t.insert}),b=u.to-r.to;return{changes:m,range:h?v.range(Math.max(0,h.anchor+b),Math.max(0,h.head+b)):u.map(m)}})}else i={changes:l,selection:h&&s.selection.replaceRange(h)}}let o="input.type";return(n.composing||n.inputState.compositionPendingChange&&n.inputState.compositionEndedAt>Date.now()-50)&&(n.inputState.compositionPendingChange=!1,o+=".compose",n.inputState.compositionFirstChange&&(o+=".start",n.inputState.compositionFirstChange=!1)),s.update(i,{userEvent:o,scrollIntoView:!0})}function jr(n,t,e,i){let s=Math.min(n.length,t.length),r=0;for(;r<s&&n.charCodeAt(r)==t.charCodeAt(r);)r++;if(r==s&&n.length==t.length)return null;let o=n.length,l=t.length;for(;o>0&&l>0&&n.charCodeAt(o-1)==t.charCodeAt(l-1);)o--,l--;if(i=="end"){let h=Math.max(0,r-Math.min(o,l));e-=o+h-r}if(o<r&&n.length<t.length){let h=e<=r&&e>=o?r-e:0;r-=h,l=r+(l-o),o=r}else if(l<r){let h=e<=r&&e>=l?r-e:0;r-=h,o=r+(o-l),l=r}return{from:r,toA:o,toB:l}}function Gr(n){let t=[];if(n.root.activeElement!=n.contentDOM)return t;let{anchorNode:e,anchorOffset:i,focusNode:s,focusOffset:r}=n.observer.selectionRange;return e&&(t.push(new Li(e,i)),(s!=e||r!=i)&&t.push(new Li(s,r))),t}function $r(n,t){if(n.length==0)return null;let e=n[0].pos,i=n.length==2?n[1].pos:e;return e>-1&&i>-1?v.single(e+t,i+t):null}const Ur={childList:!0,characterData:!0,subtree:!0,attributes:!0,characterDataOldValue:!0},Xe=y.ie&&y.ie_version<=11;class Yr{constructor(t){this.view=t,this.active=!1,this.selectionRange=new In,this.selectionChanged=!1,this.delayedFlush=-1,this.resizeTimeout=-1,this.queue=[],this.delayedAndroidKey=null,this.flushingAndroidKey=-1,this.lastChange=0,this.scrollTargets=[],this.intersection=null,this.resizeScroll=null,this.resizeContent=null,this.intersecting=!1,this.gapIntersection=null,this.gaps=[],this.parentCheck=-1,this.dom=t.contentDOM,this.observer=new MutationObserver(e=>{for(let i of e)this.queue.push(i);(y.ie&&y.ie_version<=11||y.ios&&t.composing)&&e.some(i=>i.type=="childList"&&i.removedNodes.length||i.type=="characterData"&&i.oldValue.length>i.target.nodeValue.length)?this.flushSoon():this.flush()}),Xe&&(this.onCharData=e=>{this.queue.push({target:e.target,type:"characterData",oldValue:e.prevValue}),this.flushSoon()}),this.onSelectionChange=this.onSelectionChange.bind(this),this.onResize=this.onResize.bind(this),this.onPrint=this.onPrint.bind(this),this.onScroll=this.onScroll.bind(this),typeof ResizeObserver=="function"&&(this.resizeScroll=new ResizeObserver(()=>{var e;((e=this.view.docView)===null||e===void 0?void 0:e.lastUpdate)<Date.now()-75&&this.onResize()}),this.resizeScroll.observe(t.scrollDOM),this.resizeContent=new ResizeObserver(()=>this.view.requestMeasure()),this.resizeContent.observe(t.contentDOM)),this.addWindowListeners(this.win=t.win),this.start(),typeof IntersectionObserver=="function"&&(this.intersection=new IntersectionObserver(e=>{this.parentCheck<0&&(this.parentCheck=setTimeout(this.listenForScroll.bind(this),1e3)),e.length>0&&e[e.length-1].intersectionRatio>0!=this.intersecting&&(this.intersecting=!this.intersecting,this.intersecting!=this.view.inView&&this.onScrollChanged(document.createEvent("Event")))},{threshold:[0,.001]}),this.intersection.observe(this.dom),this.gapIntersection=new IntersectionObserver(e=>{e.length>0&&e[e.length-1].intersectionRatio>0&&this.onScrollChanged(document.createEvent("Event"))},{})),this.listenForScroll(),this.readSelectionRange()}onScrollChanged(t){this.view.inputState.runScrollHandlers(this.view,t),this.intersecting&&this.view.measure()}onScroll(t){this.intersecting&&this.flush(!1),this.onScrollChanged(t)}onResize(){this.resizeTimeout<0&&(this.resizeTimeout=setTimeout(()=>{this.resizeTimeout=-1,this.view.requestMeasure()},50))}onPrint(){this.view.viewState.printing=!0,this.view.measure(),setTimeout(()=>{this.view.viewState.printing=!1,this.view.requestMeasure()},500)}updateGaps(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(Qt)?i.root.activeElement!=this.dom:!$t(i.dom,s))return;let r=s.anchorNode&&i.docView.nearest(s.anchorNode);if(r&&r.ignoreEvent(t)){e||(this.selectionChanged=!1);return}(y.ie&&y.ie_version<=11||y.android&&y.chrome)&&!i.state.selection.main.empty&&s.focusNode&&Ut(s.focusNode,s.focusOffset,s.anchorNode,s.anchorOffset)?this.flushSoon():this.flush(!1)}readSelectionRange(){let{view:t}=this,e=y.safari&&t.root.nodeType==11&&Vn(this.dom.ownerDocument)==this.dom&&Xr(this.view)||Gt(t.root);if(!e||this.selectionRange.eq(e))return!1;let i=$t(this.dom,e);return i&&!this.selectionChanged&&t.inputState.lastFocusTime>Date.now()-200&&t.inputState.lastTouchTime<Date.now()-300&&qn(this.dom,e)?(this.view.inputState.lastFocusTime=0,t.docView.updateSelection(),!1):(this.selectionRange.setRange(e),i&&(this.selectionChanged=!0),!0)}setSelectionRange(t,e){this.selectionRange.set(t.node,t.offset,e.node,e.offset),this.selectionChanged=!1}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)i=i.host;else break;if(t<this.scrollTargets.length&&!e&&(e=this.scrollTargets.slice(0,t)),e){for(let i of this.scrollTargets)i.removeEventListener("scroll",this.onScroll);for(let i of this.scrollTargets=e)i.addEventListener("scroll",this.onScroll)}}ignore(t){if(!this.active)return t();try{return this.stop(),t()}finally{this.start(),this.clear()}}start(){this.active||(this.observer.observe(this.dom,Ur),Xe&&this.dom.addEventListener("DOMCharacterDataModified",this.onCharData),this.active=!0)}stop(){this.active&&(this.active=!1,this.observer.disconnect(),Xe&&this.dom.removeEventListener("DOMCharacterDataModified",this.onCharData))}clear(){this.processRecords(),this.queue.length=0,this.selectionChanged=!1}delayAndroidKey(t,e){var i;if(!this.delayedAndroidKey){let s=()=>{let r=this.delayedAndroidKey;r&&(this.clearDelayedAndroidKey(),this.view.inputState.lastKeyCode=r.keyCode,this.view.inputState.lastKeyTime=Date.now(),!this.flush()&&r.force&&St(this.dom,r.key,r.keyCode))};this.flushingAndroidKey=this.view.win.requestAnimationFrame(s)}(!this.delayedAndroidKey||t=="Enter")&&(this.delayedAndroidKey={key:t,keyCode:e,force:this.lastChange<Date.now()-50||!!(!((i=this.delayedAndroidKey)===null||i===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(){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=!1;for(let r of t){let o=this.readMutation(r);o&&(o.typeOver&&(s=!0),e==-1?{from:e,to:i}=o:(e=Math.min(o.from,e),i=Math.max(o.to,i)))}return{from:e,to:i,typeOver:s}}readChange(){let{from:t,to:e,typeOver:i}=this.processRecords(),s=this.selectionChanged&&$t(this.dom,this.selectionRange);return t<0&&!s?null:(t>-1&&(this.lastChange=Date.now()),this.view.inputState.lastFocusTime=0,this.selectionChanged=!1,new qr(this.view,t,e,i))}flush(t=!0){if(this.delayedFlush>=0||this.delayedAndroidKey)return!1;t&&this.readSelectionRange();let e=this.readChange();if(!e)return!1;let i=this.view.state,s=Ys(this.view,e);return this.view.state==i&&this.view.update([]),s}readMutation(t){let e=this.view.docView.nearest(t.target);if(!e||e.ignoreMutation(t))return null;if(e.markDirty(t.type=="attributes"),t.type=="attributes"&&(e.flags|=4),t.type=="childList"){let i=Xs(e,t.previousSibling||t.target.previousSibling,-1),s=Xs(e,t.nextSibling||t.target.nextSibling,1);return{from:i?e.posAfter(i):e.posAtStart,to:s?e.posBefore(s):e.posAtEnd,typeOver:!1}}else return t.type=="characterData"?{from:e.posAtStart,to:e.posAtEnd,typeOver:t.target.nodeValue==t.oldValue}:null}setWindow(t){t!=this.win&&(this.removeWindowListeners(this.win),this.win=t,this.addWindowListeners(this.win))}addWindowListeners(t){t.addEventListener("resize",this.onResize),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),t.removeEventListener("beforeprint",this.onPrint),t.document.removeEventListener("selectionchange",this.onSelectionChange)}destroy(){var t,e,i,s;this.stop(),(t=this.intersection)===null||t===void 0||t.disconnect(),(e=this.gapIntersection)===null||e===void 0||e.disconnect(),(i=this.resizeScroll)===null||i===void 0||i.disconnect(),(s=this.resizeContent)===null||s===void 0||s.disconnect();for(let r of this.scrollTargets)r.removeEventListener("scroll",this.onScroll);this.removeWindowListeners(this.win),clearTimeout(this.parentCheck),clearTimeout(this.resizeTimeout),this.win.cancelAnimationFrame(this.delayedFlush),this.win.cancelAnimationFrame(this.flushingAndroidKey)}}function Xs(n,t,e){for(;t;){let i=T.get(t);if(i&&i.parent==n)return i;let s=t.parentNode;t=s!=n.dom?s:e>0?t.nextSibling:t.previousSibling}return null}function Xr(n){let t=null;function e(h){h.preventDefault(),h.stopImmediatePropagation(),t=h.getTargetRanges()[0]}if(n.contentDOM.addEventListener("beforeinput",e,!0),n.dom.ownerDocument.execCommand("indent"),n.contentDOM.removeEventListener("beforeinput",e,!0),!t)return null;let i=t.startContainer,s=t.startOffset,r=t.endContainer,o=t.endOffset,l=n.docView.domAtPos(n.state.selection.main.anchor);return Ut(l.node,l.offset,r,o)&&([i,s,r,o]=[r,o,i,s]),{anchorNode:i,anchorOffset:s,focusNode:r,focusOffset:o}}class A{get state(){return this.viewState.state}get viewport(){return this.viewState.viewport}get visibleRanges(){return this.viewState.visibleRanges}get inView(){return this.viewState.inView}get composing(){return this.inputState.composing>0}get compositionStarted(){return this.inputState.composing>=0}get root(){return this._root}get win(){return this.dom.ownerDocument.defaultView||window}constructor(t={}){this.plugins=[],this.pluginMap=new Map,this.editorAttrs={},this.contentAttrs={},this.bidiCache=[],this.destroyed=!1,this.updateState=2,this.measureScheduled=-1,this.measureRequests=[],this.contentDOM=document.createElement("div"),this.scrollDOM=document.createElement("div"),this.scrollDOM.tabIndex=-1,this.scrollDOM.className="cm-scroller",this.scrollDOM.appendChild(this.contentDOM),this.announceDOM=document.createElement("div"),this.announceDOM.style.cssText="position: fixed; top: -10000px",this.announceDOM.setAttribute("aria-live","polite"),this.dom=document.createElement("div"),this.dom.appendChild(this.announceDOM),this.dom.appendChild(this.scrollDOM);let{dispatch:e}=t;this.dispatchTransactions=t.dispatchTransactions||e&&(i=>i.forEach(s=>e(s,this)))||(i=>this.update(i)),this.dispatch=this.dispatch.bind(this),this._root=t.root||Kn(t.parent)||document,this.viewState=new _s(t.state||At.create(t)),this.plugins=this.state.facet(Tt).map(i=>new He(i));for(let i of this.plugins)i.update(this);this.observer=new Yr(this),this.inputState=new br(this),this.inputState.ensureHandlers(this,this.plugins),this.docView=new fs(this),this.mountStyles(),this.updateAttrs(),this.updateState=0,this.requestMeasure(),t.parent&&t.parent.appendChild(this.dom)}dispatch(...t){let e=t.length==1&&t[0]instanceof On?t:t.length==1&&Array.isArray(t[0])?t[0]:[this.state.update(...t)];this.dispatchTransactions(e,this)}update(t){if(this.updateState!=0)throw new Error("Calls to EditorView.update are not allowed while an update is in progress");let e=!1,i=!1,s,r=this.state;for(let f of t){if(f.startState!=r)throw new RangeError("Trying to update state with a transaction that doesn't start from the previous state.");r=f.state}if(this.destroyed){this.viewState.state=r;return}let o=this.hasFocus,l=0,h=null;t.some(f=>f.annotation(Hs))?(this.inputState.notifiedFocused=o,l=1):o!=this.inputState.notifiedFocused&&(this.inputState.notifiedFocused=o,h=Ns(r,o),h||(l=1));let c=this.observer.delayedAndroidKey,a=null;if(c?(this.observer.clearDelayedAndroidKey(),a=this.observer.readChange(),(a&&!this.state.doc.eq(r.doc)||!this.state.selection.eq(r.selection))&&(a=null)):this.observer.clear(),r.facet(At.phrases)!=this.state.facet(At.phrases))return this.setState(r);s=Kt.create(this,r,t),s.flags|=l;let d=this.viewState.scrollTarget;try{this.updateState=2;for(let f of t){if(d&&(d=d.map(f.changes)),f.scrollIntoView){let{main:u}=f.state.selection;d=new me(u.empty?u:v.cursor(u.head,u.head>u.anchor?-1:1))}for(let u of f.effects)u.is(Zi)&&(d=u.value)}this.viewState.update(s,d),this.bidiCache=be.update(this.bidiCache,s.changes),s.empty||(this.updatePlugins(s),this.inputState.update(s)),e=this.docView.update(s),this.state.facet(Bt)!=this.styleModules&&this.mountStyles(),i=this.updateAttrs(),this.showAnnouncements(t),this.docView.updateSelection(e,t.some(f=>f.isUserEvent("select.pointer")))}finally{this.updateState=0}if(s.startState.facet(he)!=s.state.facet(he)&&(this.viewState.mustMeasureContent=!0),(e||i||d||this.viewState.mustEnforceCursorAssoc||this.viewState.mustMeasureContent)&&this.requestMeasure(),!s.empty)for(let f of this.state.facet(Pe))f(s);(h||a)&&Promise.resolve().then(()=>{h&&this.state==h.startState&&this.dispatch(h),a&&!Ys(this,a)&&c.force&&St(this.contentDOM,c.key,c.keyCode)})}setState(t){if(this.updateState!=0)throw new Error("Calls to EditorView.setState are not allowed while an update is in progress");if(this.destroyed){this.viewState.state=t;return}this.updateState=2;let e=this.hasFocus;try{for(let i of this.plugins)i.destroy(this);this.viewState=new _s(t),this.plugins=t.facet(Tt).map(i=>new He(i)),this.pluginMap.clear();for(let i of this.plugins)i.update(this);this.docView=new fs(this),this.inputState.ensureHandlers(this,this.plugins),this.mountStyles(),this.updateAttrs(),this.bidiCache=[]}finally{this.updateState=0}e&&this.focus(),this.requestMeasure()}updatePlugins(t){let e=t.startState.facet(Tt),i=t.state.facet(Tt);if(e!=i){let s=[];for(let r of i){let o=e.indexOf(r);if(o<0)s.push(new He(r));else{let l=this.plugins[o];l.mustUpdate=t,s.push(l)}}for(let r of this.plugins)r.mustUpdate!=t&&r.destroy(this);this.plugins=s,this.pluginMap.clear(),this.inputState.ensureHandlers(this,this.plugins)}else for(let s of this.plugins)s.mustUpdate=t;for(let s=0;s<this.plugins.length;s++)this.plugins[s].update(this)}measure(t=!0){if(this.destroyed)return;if(this.measureScheduled>-1&&this.win.cancelAnimationFrame(this.measureScheduled),this.observer.delayedAndroidKey){this.measureScheduled=-1,this.requestMeasure();return}this.measureScheduled=0,t&&this.observer.forceFlush();let e=null,i=this.scrollDOM,{scrollTop:s}=i,{scrollAnchorPos:r,scrollAnchorHeight:o}=this.viewState;s!=this.viewState.scrollTop&&(o=-1),this.viewState.scrollAnchorHeight=-1;try{for(let l=0;;l++){if(o<0)if(ki(i))r=-1,o=this.viewState.heightMap.height;else{let u=this.viewState.scrollAnchorAt(s);r=u.from,o=u.top}this.updateState=1;let h=this.viewState.measure(this);if(!h&&!this.measureRequests.length&&this.viewState.scrollTarget==null)break;if(l>5){console.warn(this.measureRequests.length?"Measure loop restarted more than 5 times":"Viewport failed to stabilize");break}let c=[];h&4||([this.measureRequests,c]=[c,this.measureRequests]);let a=c.map(u=>{try{return u.read(this)}catch(p){return J(this.state,p),Js}}),d=Kt.create(this,this.state,[]),f=!1;d.flags|=h,e?e.flags|=h:e=d,this.updateState=2,d.empty||(this.updatePlugins(d),this.inputState.update(d),this.updateAttrs(),f=this.docView.update(d));for(let u=0;u<c.length;u++)if(a[u]!=Js)try{let p=c[u];p.write&&p.write(a[u],this)}catch(p){J(this.state,p)}if(f&&this.docView.updateSelection(!0),!d.viewportChanged&&this.measureRequests.length==0){if(this.viewState.editorHeight)if(this.viewState.scrollTarget){this.docView.scrollIntoView(this.viewState.scrollTarget),this.viewState.scrollTarget=null;continue}else{let p=(r<0?this.viewState.heightMap.height:this.viewState.lineBlockAt(r).top)-o;if(p>1||p<-1){s=i.scrollTop=s+p,o=-1;continue}}break}}}finally{this.updateState=0,this.measureScheduled=-1}if(e&&!e.empty)for(let l of this.state.facet(Pe))l(e)}get themeClasses(){return Ue+" "+(this.state.facet($e)?$s:Gs)+" "+this.state.facet(he)}updateAttrs(){let t=Zs(this,Qi,{class:"cm-editor"+(this.hasFocus?" cm-focused ":" ")+this.themeClasses}),e={spellcheck:"false",autocorrect:"off",autocapitalize:"off",translate:"no",contenteditable:this.state.facet(Qt)?"true":"false",class:"cm-content",style:`${y.tabSize}: ${this.state.tabSize}`,role:"textbox","aria-multiline":"true"};this.state.readOnly&&(e["aria-readonly"]="true"),Zs(this,te,e);let i=this.observer.ignore(()=>{let s=Le(this.contentDOM,this.contentAttrs,e),r=Le(this.dom,this.editorAttrs,t);return s||r});return this.editorAttrs=t,this.contentAttrs=e,i}showAnnouncements(t){let e=!0;for(let i of t)for(let s of i.effects)if(s.is(A.announce)){e&&(this.announceDOM.textContent=""),e=!1;let r=this.announceDOM.appendChild(document.createElement("div"));r.textContent=s.value}}mountStyles(){this.styleModules=this.state.facet(Bt);let t=this.state.facet(A.cspNonce);bt.mount(this.root,this.styleModules.concat(Kr).reverse(),t?{nonce:t}:void 0)}readMeasured(){if(this.updateState==2)throw new Error("Reading the editor layout isn't allowed during an update");this.updateState==0&&this.measureScheduled>-1&&this.measure(!1)}requestMeasure(t){if(this.measureScheduled<0&&(this.measureScheduled=this.win.requestAnimationFrame(()=>this.measure())),t){if(this.measureRequests.indexOf(t)>-1)return;if(t.key!=null){for(let e=0;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);return(e===void 0||e&&e.spec!=t)&&this.pluginMap.set(t,e=this.plugins.find(i=>i.spec==t)||null),e&&e.update(this).value}get documentTop(){return this.contentDOM.getBoundingClientRect().top+this.viewState.paddingTop}get documentPadding(){return{top:this.viewState.paddingTop,bottom:this.viewState.paddingBottom}}elementAtHeight(t){return this.readMeasured(),this.viewState.elementAtHeight(t)}lineBlockAtHeight(t){return this.readMeasured(),this.viewState.lineBlockAtHeight(t)}get viewportLineBlocks(){return this.viewState.viewportLines}lineBlockAt(t){return this.viewState.lineBlockAt(t)}get contentHeight(){return this.viewState.contentHeight}moveByChar(t,e,i){return qe(this,t,Ss(this,t,e,i))}moveByGroup(t,e){return qe(this,t,Ss(this,t,e,i=>gr(this,t.head,i)))}moveToLineBoundary(t,e,i=!0){return pr(this,t,e,i)}moveVertically(t,e,i){return qe(this,t,mr(this,t,e,i))}domAtPos(t){return this.docView.domAtPos(t)}posAtDOM(t,e=0){return this.docView.posFromDOM(t,e)}posAtCoords(t,e=!0){return this.readMeasured(),ys(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),r=this.bidiSpans(s),o=r[Z.find(r,t-s.from,-1,e)];return Xt(i,o.dir==L.LTR==e>0)}coordsForChar(t){return this.readMeasured(),this.docView.coordsForChar(t)}get defaultCharacterWidth(){return this.viewState.heightOracle.charWidth}get defaultLineHeight(){return this.viewState.heightOracle.lineHeight}get textDirection(){return this.viewState.defaultTextDirection}textDirectionAt(t){return!this.state.facet(Xi)||t<this.viewport.from||t>this.viewport.to?this.textDirection:(this.readMeasured(),this.docView.textDirectionAt(t))}get lineWrapping(){return this.viewState.heightOracle.lineWrapping}bidiSpans(t){if(t.length>Jr)return hs(t.length);let e=this.textDirectionAt(t.from),i;for(let r of this.bidiCache)if(r.from==t.from&&r.dir==e&&(r.fresh||os(r.isolates,i=es(this,t.from,t.to))))return r.order;i||(i=es(this,t.from,t.to));let s=ls(t.text,e,i);return this.bidiCache.push(new be(t.from,t.to,e,i,!0,s)),s}get hasFocus(){var t;return(this.dom.ownerDocument.hasFocus()||y.safari&&((t=this.inputState)===null||t===void 0?void 0:t.lastContextMenu)>Date.now()-3e4)&&this.root.activeElement==this.contentDOM}focus(){this.observer.ignore(()=>{vi(this.contentDOM),this.docView.updateSelection()})}setRoot(t){this._root!=t&&(this._root=t,this.observer.setWindow((t.nodeType==9?t:t.ownerDocument).defaultView||window),this.mountStyles())}destroy(){for(let t of this.plugins)t.destroy(this);this.plugins=[],this.inputState.destroy(),this.dom.remove(),this.observer.destroy(),this.measureScheduled>-1&&this.win.cancelAnimationFrame(this.measureScheduled),this.destroyed=!0}static scrollIntoView(t,e={}){return Zi.of(new me(typeof t=="number"?v.cursor(t):t,e.y,e.x,e.yMargin,e.xMargin))}static domEventHandlers(t){return P.define(()=>({}),{eventHandlers:t})}static theme(t,e){let i=bt.newName(),s=[he.of(i),Bt.of(Ye(`.${i}`,t))];return e&&e.dark&&s.push($e.of(!0)),s}static baseTheme(t){return ye.lowest(Bt.of(Ye("."+Ue,t,Us)))}static findFromDOM(t){var e;let i=t.querySelector(".cm-content"),s=i&&T.get(i)||T.get(t);return((e=s?.rootView)===null||e===void 0?void 0:e.view)||null}}A.styleModule=Bt,A.inputHandler=Ui,A.focusChangeEffect=Yi,A.perLineTextDirection=Xi,A.exceptionSink=$i,A.updateListener=Pe,A.editable=Qt,A.mouseSelectionStyle=Gi,A.dragMovesSelection=ji,A.clickAddsSelectionRange=_i,A.decorations=Rt,A.atomicRanges=Ne,A.bidiIsolatedRanges=ts,A.scrollMargins=is,A.darkTheme=$e,A.cspNonce=C.define({combine:n=>n.length?n[0]:""}),A.contentAttributes=te,A.editorAttributes=Qi,A.lineWrapping=A.contentAttributes.of({class:"cm-lineWrapping"}),A.announce=Dt.define();const Jr=4096,Js={};class be{constructor(t,e,i,s,r,o){this.from=t,this.to=e,this.dir=i,this.isolates=s,this.fresh=r,this.order=o}static update(t,e){if(e.empty&&!t.some(r=>r.fresh))return t;let i=[],s=t.length?t[t.length-1].dir:L.LTR;for(let r=Math.max(0,t.length-10);r<t.length;r++){let o=t[r];o.dir==s&&!e.touchesRange(o.from,o.to)&&i.push(new be(e.mapPos(o.from,1),e.mapPos(o.to,-1),o.dir,o.isolates,!1,o.order))}return i}}function Zs(n,t,e){for(let i=n.state.facet(t),s=i.length-1;s>=0;s--){let r=i[s],o=typeof r=="function"?r(n):r;o&&Re(o,e)}return e}const Zr=y.mac?"mac":y.windows?"win":y.linux?"linux":"key";function Qr(n,t){const e=n.split(/-(?!$)/);let i=e[e.length-1];i=="Space"&&(i=" ");let s,r,o,l;for(let h=0;h<e.length-1;++h){const c=e[h];if(/^(cmd|meta|m)$/i.test(c))l=!0;else if(/^a(lt)?$/i.test(c))s=!0;else if(/^(c|ctrl|control)$/i.test(c))r=!0;else if(/^s(hift)?$/i.test(c))o=!0;else if(/^mod$/i.test(c))t=="mac"?l=!0:r=!0;else throw new Error("Unrecognized modifier name: "+c)}return s&&(i="Alt-"+i),r&&(i="Ctrl-"+i),l&&(i="Meta-"+i),o&&(i="Shift-"+i),i}function ae(n,t,e){return t.altKey&&(n="Alt-"+n),t.ctrlKey&&(n="Ctrl-"+n),t.metaKey&&(n="Meta-"+n),e!==!1&&t.shiftKey&&(n="Shift-"+n),n}const to=ye.default(A.domEventHandlers({keydown(n,t){return sn(en(t.state),n,t,"editor")}})),Qs=C.define({enables:to}),tn=new WeakMap;function en(n){let t=n.facet(Qs),e=tn.get(t);return e||tn.set(t,e=so(t.reduce((i,s)=>i.concat(s),[]))),e}function eo(n,t,e){return sn(en(n.state),t,n,e)}let ot=null;const io=4e3;function so(n,t=Zr){let e=Object.create(null),i=Object.create(null),s=(o,l)=>{let h=i[o];if(h==null)i[o]=l;else if(h!=l)throw new Error("Key binding "+o+" is used both as a regular binding and as a multi-stroke prefix")},r=(o,l,h,c,a)=>{var d,f;let u=e[o]||(e[o]=Object.create(null)),p=l.split(/ (?!$)/).map(b=>Qr(b,t));for(let b=1;b<p.length;b++){let S=p.slice(0,b).join(" ");s(S,!0),u[S]||(u[S]={preventDefault:!0,stopPropagation:!1,run:[k=>{let w=ot={view:k,prefix:S,scope:o};return setTimeout(()=>{ot==w&&(ot=null)},io),!0}]})}let g=p.join(" ");s(g,!1);let m=u[g]||(u[g]={preventDefault:!1,stopPropagation:!1,run:((f=(d=u._any)===null||d===void 0?void 0:d.run)===null||f===void 0?void 0:f.slice())||[]});h&&m.run.push(h),c&&(m.preventDefault=!0),a&&(m.stopPropagation=!0)};for(let o of n){let l=o.scope?o.scope.split(" "):["editor"];if(o.any)for(let c of l){let a=e[c]||(e[c]=Object.create(null));a._any||(a._any={preventDefault:!1,stopPropagation:!1,run:[]});for(let d in a)a[d].run.push(o.any)}let h=o[t]||o.key;if(h)for(let c of l)r(c,h,o.run,o.preventDefault,o.stopPropagation),o.shift&&r(c,"Shift-"+h,o.shift,o.preventDefault,o.stopPropagation)}return e}function sn(n,t,e,i){let s=Nn(t),r=gi(s,0),o=Tn(r)==s.length&&s!=" ",l="",h=!1,c=!1,a=!1;ot&&ot.view==e&&ot.scope==i&&(l=ot.prefix+" ",vs.indexOf(t.keyCode)<0&&(c=!0,ot=null));let d=new Set,f=m=>{if(m){for(let b of m.run)if(!d.has(b)&&(d.add(b),b(e,t)))return m.stopPropagation&&(a=!0),!0;m.preventDefault&&(m.stopPropagation&&(a=!0),c=!0)}return!1},u=n[i],p,g;return u&&(f(u[l+ae(s,t,!o)])?h=!0:o&&(t.altKey||t.metaKey||t.ctrlKey)&&!(y.windows&&t.ctrlKey&&t.altKey)&&(p=nt[t.keyCode])&&p!=s?(f(u[l+ae(p,t,!0)])||t.shiftKey&&(g=Ot[t.keyCode])!=s&&g!=p&&f(u[l+ae(g,t,!1)]))&&(h=!0):o&&t.shiftKey&&f(u[l+ae(s,t,!0)])&&(h=!0),!h&&f(u._any)&&(h=!0)),c&&(h=!0),h&&a&&t.stopPropagation(),h}class Mt{constructor(t,e,i,s,r){this.className=t,this.left=e,this.top=i,this.width=s,this.height=r}draw(){let t=document.createElement("div");return t.className=this.className,this.adjust(t),t}update(t,e){return e.className!=this.className?!1:(this.adjust(t),!0)}adjust(t){t.style.left=this.left+"px",t.style.top=this.top+"px",this.width!=null&&(t.style.width=this.width+"px"),t.style.height=this.height+"px"}eq(t){return this.left==t.left&&this.top==t.top&&this.width==t.width&&this.height==t.height&&this.className==t.className}static forRange(t,e,i){if(i.empty){let s=t.coordsAtPos(i.head,i.assoc||1);if(!s)return[];let r=nn(t);return[new Mt(e,s.left-r.left,s.top-r.top,null,s.bottom-s.top)]}else return no(t,e,i)}}function nn(n){let t=n.scrollDOM.getBoundingClientRect();return{left:(n.textDirection==L.LTR?t.left:t.right-n.scrollDOM.clientWidth)-n.scrollDOM.scrollLeft,top:t.top-n.scrollDOM.scrollTop}}function rn(n,t,e){let i=v.cursor(t);return{from:Math.max(e.from,n.moveToLineBoundary(i,!1,!0).from),to:Math.min(e.to,n.moveToLineBoundary(i,!0,!0).from),type:R.Text}}function no(n,t,e){if(e.to<=n.viewport.from||e.from>=n.viewport.to)return[];let i=Math.max(e.from,n.viewport.from),s=Math.min(e.to,n.viewport.to),r=n.textDirection==L.LTR,o=n.contentDOM,l=o.getBoundingClientRect(),h=nn(n),c=o.querySelector(".cm-line"),a=c&&window.getComputedStyle(c),d=l.left+(a?parseInt(a.paddingLeft)+Math.min(0,parseInt(a.textIndent)):0),f=l.right-(a?parseInt(a.paddingRight):0),u=Ke(n,i),p=Ke(n,s),g=u.type==R.Text?u:null,m=p.type==R.Text?p:null;if(g&&(n.lineWrapping||u.widgetLineBreaks)&&(g=rn(n,i,g)),m&&(n.lineWrapping||p.widgetLineBreaks)&&(m=rn(n,s,m)),g&&m&&g.from==m.from)return S(k(e.from,e.to,g));{let x=g?k(e.from,null,g):w(u,!1),M=m?k(null,e.to,m):w(p,!0),V=[];return(g||u).to<(m||p).from-(g&&m?1:0)||u.widgetLineBreaks>1&&x.bottom+n.defaultLineHeight/2<M.top?V.push(b(d,x.bottom,f,M.top)):x.bottom<M.top&&n.elementAtHeight((x.bottom+M.top)/2).type==R.Text&&(x.bottom=M.top=(x.bottom+M.top)/2),S(x).concat(V).concat(S(M))}function b(x,M,V,et){return new Mt(t,x-h.left,M-h.top-.01,V-x,et-M+.01)}function S({top:x,bottom:M,horizontal:V}){let et=[];for(let it=0;it<V.length;it+=2)et.push(b(V[it],x,V[it+1],M));return et}function k(x,M,V){let et=1e9,it=-1e9,qt=[];function di(at,st,pt,ct,kt){let Y=n.coordsAtPos(at,at==V.to?-2:2),X=n.coordsAtPos(pt,pt==V.from?2:-2);!Y||!X||(et=Math.min(Y.top,X.top,et),it=Math.max(Y.bottom,X.bottom,it),kt==L.LTR?qt.push(r&&st?d:Y.left,r&&ct?f:X.right):qt.push(!r&&ct?d:X.left,!r&&st?f:Y.right))}let _t=x??V.from,jt=M??V.to;for(let at of n.visibleRanges)if(at.to>_t&&at.from<jt)for(let st=Math.max(at.from,_t),pt=Math.min(at.to,jt);;){let ct=n.state.doc.lineAt(st);for(let kt of n.bidiSpans(ct)){let Y=kt.from+ct.from,X=kt.to+ct.from;if(Y>=pt)break;X>st&&di(Math.max(Y,st),x==null&&Y<=_t,Math.min(X,pt),M==null&&X>=jt,kt.dir)}if(st=ct.to+1,st>=pt)break}return qt.length==0&&di(_t,x==null,jt,M==null,n.textDirection),{top:et,bottom:it,horizontal:qt}}function w(x,M){let V=l.top+(M?x.top:x.bottom);return{top:V,bottom:V,horizontal:[]}}}function ro(n,t){return n.constructor==t.constructor&&n.eq(t)}class oo{constructor(t,e){this.view=t,this.layer=e,this.drawn=[],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.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(ce)!=t.state.facet(ce)&&this.setOrder(t.state),(this.layer.update(t,this.dom)||t.geometryChanged)&&t.view.requestMeasure(this.measureReq)}setOrder(t){let e=0,i=t.facet(ce);for(;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)}draw(t){if(t.length!=this.drawn.length||t.some((e,i)=>!ro(e,this.drawn[i]))){let e=this.dom.firstChild,i=0;for(let s of t)s.update&&e&&s.constructor&&this.drawn[i].constructor&&s.update(e,this.drawn[i])?(e=e.nextSibling,i++):this.dom.insertBefore(s.draw(),e);for(;e;){let s=e.nextSibling;e.remove(),e=s}this.drawn=t}}destroy(){this.layer.destroy&&this.layer.destroy(this.dom,this.view),this.dom.remove()}}const ce=C.define();function Je(n){return[P.define(t=>new oo(t,n)),ce.of(n)]}const on=!y.ios,Pt=C.define({combine(n){return Se(n,{cursorBlinkRate:1200,drawRangeCursor:!0},{cursorBlinkRate:(t,e)=>Math.min(t,e),drawRangeCursor:(t,e)=>t||e})}});function lo(n={}){return[Pt.of(n),ho,ao,co,Ji.of(!0)]}function ln(n){return n.startState.facet(Pt)!=n.state.facet(Pt)}const ho=Je({above:!0,markers(n){let{state:t}=n,e=t.facet(Pt),i=[];for(let s of t.selection.ranges){let r=s==t.selection.main;if(s.empty?!r||on:e.drawRangeCursor){let o=r?"cm-cursor cm-cursor-primary":"cm-cursor cm-cursor-secondary",l=s.empty?s:v.cursor(s.head,s.head>s.anchor?-1:1);for(let h of Mt.forRange(n,o,l))i.push(h)}}return i},update(n,t){n.transactions.some(i=>i.selection)&&(t.style.animationName=t.style.animationName=="cm-blink"?"cm-blink2":"cm-blink");let e=ln(n);return e&&hn(n.state,t),n.docChanged||n.selectionSet||e},mount(n,t){hn(t.state,n)},class:"cm-cursorLayer"});function hn(n,t){t.style.animationDuration=n.facet(Pt).cursorBlinkRate+"ms"}const ao=Je({above:!1,markers(n){return n.state.selection.ranges.map(t=>t.empty?[]:Mt.forRange(n,"cm-selectionBackground",t)).reduce((t,e)=>t.concat(e))},update(n,t){return n.docChanged||n.selectionSet||n.viewportChanged||ln(n)},class:"cm-selectionLayer"}),an={".cm-line":{"& ::selection":{backgroundColor:"transparent !important"},"&::selection":{backgroundColor:"transparent !important"}}};on&&(an[".cm-line"].caretColor="transparent !important");const co=ye.highest(A.theme(an)),cn=Dt.define({map(n,t){return n==null?null:t.mapPos(n)}}),Ht=bi.define({create(){return null},update(n,t){return n!=null&&(n=t.changes.mapPos(n)),t.effects.reduce((e,i)=>i.is(cn)?i.value:e,n)}}),fo=P.fromClass(class{constructor(n){this.view=n,this.cursor=null,this.measureReq={read:this.readPos.bind(this),write:this.drawCursor.bind(this)}}update(n){var t;let e=n.state.field(Ht);e==null?this.cursor!=null&&((t=this.cursor)===null||t===void 0||t.remove(),this.cursor=null):(this.cursor||(this.cursor=this.view.scrollDOM.appendChild(document.createElement("div")),this.cursor.className="cm-dropCursor"),(n.startState.field(Ht)!=e||n.docChanged||n.geometryChanged)&&this.view.requestMeasure(this.measureReq))}readPos(){let n=this.view.state.field(Ht),t=n!=null&&this.view.coordsAtPos(n);if(!t)return null;let e=this.view.scrollDOM.getBoundingClientRect();return{left:t.left-e.left+this.view.scrollDOM.scrollLeft,top:t.top-e.top+this.view.scrollDOM.scrollTop,height:t.bottom-t.top}}drawCursor(n){this.cursor&&(n?(this.cursor.style.left=n.left+"px",this.cursor.style.top=n.top+"px",this.cursor.style.height=n.height+"px"):this.cursor.style.left="-100000px")}destroy(){this.cursor&&this.cursor.remove()}setDropPos(n){this.view.state.field(Ht)!=n&&this.view.dispatch({effects:cn.of(n)})}},{eventHandlers:{dragover(n){this.setDropPos(this.view.posAtCoords({x:n.clientX,y:n.clientY}))},dragleave(n){(n.target==this.view.contentDOM||!this.view.contentDOM.contains(n.relatedTarget))&&this.setDropPos(null)},dragend(){this.setDropPos(null)},drop(){this.setDropPos(null)}}});function uo(){return[Ht,fo]}function fn(n,t,e,i,s){t.lastIndex=0;for(let r=n.iterRange(e,i),o=e,l;!r.next().done;o+=r.value.length)if(!r.lineBreak)for(;l=t.exec(r.value);)s(o+l.index,l)}function po(n,t){let e=n.visibleRanges;if(e.length==1&&e[0].from==n.viewport.from&&e[0].to==n.viewport.to)return e;let i=[];for(let{from:s,to:r}of e)s=Math.max(n.state.doc.lineAt(s).from,s-t),r=Math.min(n.state.doc.lineAt(r).to,r+t),i.length&&i[i.length-1].to>=s?i[i.length-1].to=r:i.push({from:s,to:r});return i}class fe{constructor(t){const{regexp:e,decoration:i,decorate:s,boundary:r,maxLength:o=1e3}=t;if(!e.global)throw new RangeError("The regular expression given to MatchDecorator should have its 'g' flag set");if(this.regexp=e,s)this.addMatch=(l,h,c,a)=>s(a,c,c+l[0].length,l,h);else if(typeof i=="function")this.addMatch=(l,h,c,a)=>{let d=i(l,h,c);d&&a(c,c+l[0].length,d)};else if(i)this.addMatch=(l,h,c,a)=>a(c,c+l[0].length,i);else throw new RangeError("Either 'decorate' or 'decoration' should be provided to MatchDecorator");this.boundary=r,this.maxLength=o}createDeco(t){let e=new Rn,i=e.add.bind(e);for(let{from:s,to:r}of po(t,this.maxLength))fn(t.state.doc,this.regexp,s,r,(o,l)=>this.addMatch(l,t,o,i));return e.finish()}updateDeco(t,e){let i=1e9,s=-1;return t.docChanged&&t.changes.iterChanges((r,o,l,h)=>{h>t.view.viewport.from&&l<t.view.viewport.to&&(i=Math.min(l,i),s=Math.max(h,s))}),t.viewportChanged||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 r of t.visibleRanges){let o=Math.max(r.from,i),l=Math.min(r.to,s);if(l>o){let h=t.state.doc.lineAt(o),c=h.to<l?t.state.doc.lineAt(l):h,a=Math.max(r.from,h.from),d=Math.min(r.to,c.to);if(this.boundary){for(;o>h.from;o--)if(this.boundary.test(h.text[o-1-h.from])){a=o;break}for(;l<c.to;l++)if(this.boundary.test(c.text[l-c.from])){d=l;break}}let f=[],u,p=(g,m,b)=>f.push(b.range(g,m));if(h==c)for(this.regexp.lastIndex=a-h.from;(u=this.regexp.exec(h.text))&&u.index<d-h.from;)this.addMatch(u,t,u.index+h.from,p);else fn(t.state.doc,this.regexp,a,d,(g,m)=>this.addMatch(m,t,g,p));e=e.update({filterFrom:a,filterTo:d,filter:(g,m)=>g<a||m>d,add:f})}}return e}}const Ze=/x/.unicode!=null?"gu":"g",go=new RegExp(`[\0-\b
-\x7F-\x9F\xAD\u061C\u200B\u200E\u200F\u2028\u2029\u202D\u202E\u2066\u2067\u2069\uFEFF\uFFF9-\uFFFC]`,Ze),mo={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 Qe=null;function bo(){var n;if(Qe==null&&typeof document<"u"&&document.body){let t=document.body.style;Qe=((n=t.tabSize)!==null&&n!==void 0?n:t.MozTabSize)!=null}return Qe||!1}const de=C.define({combine(n){let t=Se(n,{render:null,specialChars:go,addSpecialChars:null});return(t.replaceTabs=!bo())&&(t.specialChars=new RegExp("	|"+t.specialChars.source,Ze)),t.addSpecialChars&&(t.specialChars=new RegExp(t.specialChars.source+"|"+t.addSpecialChars.source,Ze)),t}});function yo(n={}){return[de.of(n),wo()]}let dn=null;function wo(){return dn||(dn=P.fromClass(class{constructor(n){this.view=n,this.decorations=B.none,this.decorationCache=Object.create(null),this.decorator=this.makeDecorator(n.state.facet(de)),this.decorations=this.decorator.createDeco(n)}makeDecorator(n){return new fe({regexp:n.specialChars,decoration:(t,e,i)=>{let{doc:s}=e.state,r=gi(t[0],0);if(r==9){let o=s.lineAt(i),l=e.state.tabSize,h=mi(o.text,l,i-o.from);return B.replace({widget:new Mo((l-h%l)*this.view.defaultCharacterWidth)})}return this.decorationCache[r]||(this.decorationCache[r]=B.replace({widget:new vo(n,r)}))},boundary:n.replaceTabs?void 0:/[^]/})}update(n){let t=n.state.facet(de);n.startState.facet(de)!=t?(this.decorator=this.makeDecorator(t),this.decorations=this.decorator.createDeco(n.view)):this.decorations=this.decorator.updateDeco(n,this.decorations)}},{decorations:n=>n.decorations}))}const So="\u2022";function xo(n){return n>=32?So:n==10?"\u2424":String.fromCharCode(9216+n)}class vo extends dt{constructor(t,e){super(),this.options=t,this.code=e}eq(t){return t.code==this.code}toDOM(t){let e=xo(this.code),i=t.state.phrase("Control character")+" "+(mo[this.code]||"0x"+this.code.toString(16)),s=this.options.render&&this.options.render(this.code,i,e);if(s)return s;let r=document.createElement("span");return r.textContent=e,r.title=i,r.setAttribute("aria-label",i),r.className="cm-specialChar",r}ignoreEvent(){return!1}}class Mo extends dt{constructor(t){super(),this.width=t}eq(t){return t.width==this.width}toDOM(){let t=document.createElement("span");return t.textContent="	",t.className="cm-tab",t.style.width=this.width+"px",t}ignoreEvent(){return!1}}const un=P.fromClass(class{constructor(){this.height=1e3,this.attrs={style:"padding-bottom: 1000px"}}update(n){let{view:t}=n,e=t.viewState.editorHeight-t.defaultLineHeight-t.documentPadding.top-.5;e>=0&&e!=this.height&&(this.height=e,this.attrs={style:`padding-bottom: ${e}px`})}});function Co(){return[un,te.of(n=>{var t;return((t=n.plugin(un))===null||t===void 0?void 0:t.attrs)||null})]}function ko(){return Do}const Ao=B.line({class:"cm-activeLine"}),Do=P.fromClass(class{constructor(n){this.decorations=this.getDeco(n)}update(n){(n.docChanged||n.selectionSet)&&(this.decorations=this.getDeco(n.view))}getDeco(n){let t=-1,e=[];for(let i of n.state.selection.ranges){let s=n.lineBlockAt(i.head);s.from>t&&(e.push(Ao.range(s.from)),t=s.from)}return B.set(e)}},{decorations:n=>n.decorations});class Oo extends dt{constructor(t){super(),this.content=t}toDOM(){let t=document.createElement("span");return t.className="cm-placeholder",t.style.pointerEvents="none",t.appendChild(typeof this.content=="string"?document.createTextNode(this.content):this.content),typeof this.content=="string"?t.setAttribute("aria-label","placeholder "+this.content):t.setAttribute("aria-hidden","true"),t}coordsAt(t){let e=t.firstChild?yt(t.firstChild):[];if(!e.length)return null;let i=window.getComputedStyle(t.parentNode),s=Xt(e[0],i.direction!="rtl"),r=parseInt(i.lineHeight);return s.bottom-s.top>r*1.5?{left:s.left,right:s.right,top:s.top,bottom:s.top+r}:s}ignoreEvent(){return!1}}function To(n){return P.fromClass(class{constructor(t){this.view=t,this.placeholder=n?B.set([B.widget({widget:new Oo(n),side:1}).range(0)]):B.none}get decorations(){return this.view.state.doc.length?B.none:this.placeholder}},{decorations:t=>t.decorations})}const ti=2e3;function Ro(n,t,e){let i=Math.min(t.line,e.line),s=Math.max(t.line,e.line),r=[];if(t.off>ti||e.off>ti||t.col<0||e.col<0){let o=Math.min(t.off,e.off),l=Math.max(t.off,e.off);for(let h=i;h<=s;h++){let c=n.doc.line(h);c.length<=l&&r.push(v.range(c.from+o,c.to+l))}}else{let o=Math.min(t.col,e.col),l=Math.max(t.col,e.col);for(let h=i;h<=s;h++){let c=n.doc.line(h),a=we(c.text,o,n.tabSize,!0);if(a<0)r.push(v.cursor(c.to));else{let d=we(c.text,l,n.tabSize);r.push(v.range(c.from+a,c.from+d))}}}return r}function Bo(n,t){let e=n.coordsAtPos(n.viewport.from);return e?Math.round(Math.abs((e.left-t)/n.defaultCharacterWidth)):-1}function pn(n,t){let e=n.posAtCoords({x:t.clientX,y:t.clientY},!1),i=n.state.doc.lineAt(e),s=e-i.from,r=s>ti?-1:s==i.length?Bo(n,t.clientX):mi(i.text,n.state.tabSize,e-i.from);return{line:i.number,col:r,off:s}}function Lo(n,t){let e=pn(n,t),i=n.state.selection;return e?{update(s){if(s.docChanged){let r=s.changes.mapPos(s.startState.doc.line(e.line).from),o=s.state.doc.lineAt(r);e={line:o.number,col:e.col,off:Math.min(e.off,o.length)},i=i.map(s.changes)}},get(s,r,o){let l=pn(n,s);if(!l)return i;let h=Ro(n.state,e,l);return h.length?o?v.create(h.concat(i.ranges)):v.create(h):i}}:null}function Eo(n){let t=n?.eventFilter||(e=>e.altKey&&e.button==0);return A.mouseSelectionStyle.of((e,i)=>t(i)?Lo(e,i):null)}const Po={Alt:[18,n=>!!n.altKey],Control:[17,n=>!!n.ctrlKey],Shift:[16,n=>!!n.shiftKey],Meta:[91,n=>!!n.metaKey]},Ho={style:"cursor: crosshair"};function No(n={}){let[t,e]=Po[n.key||"Alt"],i=P.fromClass(class{constructor(s){this.view=s,this.isDown=!1}set(s){this.isDown!=s&&(this.isDown=s,this.view.update([]))}},{eventHandlers:{keydown(s){this.set(s.keyCode==t||e(s))},keyup(s){(s.keyCode==t||!e(s))&&this.set(!1)},mousemove(s){this.set(e(s))}}});return[i,A.contentAttributes.of(s=>{var r;return!((r=s.plugin(i))===null||r===void 0)&&r.isDown?Ho:null})]}const ue="-10000px";class gn{constructor(t,e,i){this.facet=e,this.createTooltipView=i,this.input=t.state.facet(e),this.tooltips=this.input.filter(s=>s),this.tooltipViews=this.tooltips.map(i)}update(t){var e;let i=t.state.facet(this.facet),s=i.filter(o=>o);if(i===this.input){for(let o of this.tooltipViews)o.update&&o.update(t);return!1}let r=[];for(let o=0;o<s.length;o++){let l=s[o],h=-1;if(l){for(let c=0;c<this.tooltips.length;c++){let a=this.tooltips[c];a&&a.create==l.create&&(h=c)}if(h<0)r[o]=this.createTooltipView(l);else{let c=r[o]=this.tooltipViews[h];c.update&&c.update(t)}}}for(let o of this.tooltipViews)r.indexOf(o)<0&&(o.dom.remove(),(e=o.destroy)===null||e===void 0||e.call(o));return this.input=i,this.tooltips=s,this.tooltipViews=r,!0}}function Vo(n={}){return pe.of(n)}function Wo(n){let{win:t}=n;return{top:0,left:0,bottom:t.innerHeight,right:t.innerWidth}}const pe=C.define({combine:n=>{var t,e,i;return{position:y.ios?"absolute":((t=n.find(s=>s.position))===null||t===void 0?void 0:t.position)||"fixed",parent:((e=n.find(s=>s.parent))===null||e===void 0?void 0:e.parent)||null,tooltipSpace:((i=n.find(s=>s.tooltipSpace))===null||i===void 0?void 0:i.tooltipSpace)||Wo}}}),mn=new WeakMap,ei=P.fromClass(class{constructor(n){this.view=n,this.inView=!0,this.lastTransaction=0,this.measureTimeout=-1;let t=n.state.facet(pe);this.position=t.position,this.parent=t.parent,this.classes=n.themeClasses,this.createContainer(),this.measureReq={read:this.readMeasure.bind(this),write:this.writeMeasure.bind(this),key:this},this.manager=new gn(n,ii,e=>this.createTooltip(e)),this.intersectionObserver=typeof IntersectionObserver=="function"?new IntersectionObserver(e=>{Date.now()>this.lastTransaction-50&&e.length>0&&e[e.length-1].intersectionRatio<1&&this.measureSoon()},{threshold:[1]}):null,this.observeIntersection(),n.win.addEventListener("resize",this.measureSoon=this.measureSoon.bind(this)),this.maybeMeasure()}createContainer(){this.parent?(this.container=document.createElement("div"),this.container.style.position="relative",this.container.className=this.view.themeClasses,this.parent.appendChild(this.container)):this.container=this.view.dom}observeIntersection(){if(this.intersectionObserver){this.intersectionObserver.disconnect();for(let n of this.manager.tooltipViews)this.intersectionObserver.observe(n.dom)}}measureSoon(){this.measureTimeout<0&&(this.measureTimeout=setTimeout(()=>{this.measureTimeout=-1,this.maybeMeasure()},50))}update(n){n.transactions.length&&(this.lastTransaction=Date.now());let t=this.manager.update(n);t&&this.observeIntersection();let e=t||n.geometryChanged,i=n.state.facet(pe);if(i.position!=this.position){this.position=i.position;for(let s of this.manager.tooltipViews)s.dom.style.position=this.position;e=!0}if(i.parent!=this.parent){this.parent&&this.container.remove(),this.parent=i.parent,this.createContainer();for(let s of this.manager.tooltipViews)this.container.appendChild(s.dom);e=!0}else this.parent&&this.view.themeClasses!=this.classes&&(this.classes=this.container.className=this.view.themeClasses);e&&this.maybeMeasure()}createTooltip(n){let t=n.create(this.view);if(t.dom.classList.add("cm-tooltip"),n.arrow&&!t.dom.querySelector(".cm-tooltip > .cm-tooltip-arrow")){let e=document.createElement("div");e.className="cm-tooltip-arrow",t.dom.appendChild(e)}return t.dom.style.position=this.position,t.dom.style.top=ue,this.container.appendChild(t.dom),t.mount&&t.mount(this.view),t}destroy(){var n,t;this.view.win.removeEventListener("resize",this.measureSoon);for(let e of this.manager.tooltipViews)e.dom.remove(),(n=e.destroy)===null||n===void 0||n.call(e);(t=this.intersectionObserver)===null||t===void 0||t.disconnect(),clearTimeout(this.measureTimeout)}readMeasure(){let n=this.view.dom.getBoundingClientRect();return{editor:n,parent:this.parent?this.container.getBoundingClientRect():n,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(pe).tooltipSpace(this.view)}}writeMeasure(n){var t;let{editor:e,space:i}=n,s=[];for(let r=0;r<this.manager.tooltips.length;r++){let o=this.manager.tooltips[r],l=this.manager.tooltipViews[r],{dom:h}=l,c=n.pos[r],a=n.size[r];if(!c||c.bottom<=Math.max(e.top,i.top)||c.top>=Math.min(e.bottom,i.bottom)||c.right<Math.max(e.left,i.left)-.1||c.left>Math.min(e.right,i.right)+.1){h.style.top=ue;continue}let d=o.arrow?l.dom.querySelector(".cm-tooltip-arrow"):null,f=d?7:0,u=a.right-a.left,p=(t=mn.get(l))!==null&&t!==void 0?t:a.bottom-a.top,g=l.offset||zo,m=this.view.textDirection==L.LTR,b=a.width>i.right-i.left?m?i.left:i.right-a.width:m?Math.min(c.left-(d?14:0)+g.x,i.right-u):Math.max(i.left,c.left-u+(d?14:0)-g.x),S=!!o.above;!o.strictSide&&(S?c.top-(a.bottom-a.top)-g.y<i.top:c.bottom+(a.bottom-a.top)+g.y>i.bottom)&&S==i.bottom-c.bottom>c.top-i.top&&(S=!S);let k=(S?c.top-i.top:i.bottom-c.bottom)-f;if(k<p&&l.resize!==!1){if(k<this.view.defaultLineHeight){h.style.top=ue;continue}mn.set(l,p),h.style.height=(p=k)+"px"}else h.style.height&&(h.style.height="");let w=S?c.top-p-f-g.y:c.bottom+f+g.y,x=b+u;if(l.overlap!==!0)for(let M of s)M.left<x&&M.right>b&&M.top<w+p&&M.bottom>w&&(w=S?M.top-p-2-f:M.bottom+f+2);this.position=="absolute"?(h.style.top=w-n.parent.top+"px",h.style.left=b-n.parent.left+"px"):(h.style.top=w+"px",h.style.left=b+"px"),d&&(d.style.left=`${c.left+(m?g.x:-g.x)-(b+14-7)}px`),l.overlap!==!0&&s.push({left:b,top:w,right:x,bottom:w+p}),h.classList.toggle("cm-tooltip-above",S),h.classList.toggle("cm-tooltip-below",!S),l.positioned&&l.positioned(n.space)}}maybeMeasure(){if(this.manager.tooltips.length&&(this.view.inView&&this.view.requestMeasure(this.measureReq),this.inView!=this.view.inView&&(this.inView=this.view.inView,!this.inView)))for(let n of this.manager.tooltipViews)n.dom.style.top=ue}},{eventHandlers:{scroll(){this.maybeMeasure()}}}),Fo=A.baseTheme({".cm-tooltip":{zIndex:100,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:`${7*2}px`,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"}}}),zo={x:0,y:0},ii=C.define({enables:[ei,Fo]}),Nt=C.define();class fi{static create(t){return new fi(t)}constructor(t){this.view=t,this.mounted=!1,this.dom=document.createElement("div"),this.dom.classList.add("cm-tooltip-hover"),this.manager=new gn(t,Nt,e=>this.createHostedView(e))}createHostedView(t){let e=t.create(this.view);return e.dom.classList.add("cm-tooltip-section"),this.dom.appendChild(e.dom),this.mounted&&e.mount&&e.mount(this.view),e}mount(t){for(let e of this.manager.tooltipViews)e.mount&&e.mount(t);this.mounted=!0}positioned(t){for(let e of this.manager.tooltipViews)e.positioned&&e.positioned(t)}update(t){this.manager.update(t)}destroy(){var t;for(let e of this.manager.tooltipViews)(t=e.destroy)===null||t===void 0||t.call(e)}}const Io=ii.compute([Nt],n=>{let t=n.facet(Nt).filter(e=>e);return t.length===0?null:{pos:Math.min(...t.map(e=>e.pos)),end:Math.max(...t.filter(e=>e.end!=null).map(e=>e.end)),create:fi.create,above:t[0].above,arrow:t.some(e=>e.arrow)}});class Ko{constructor(t,e,i,s,r){this.view=t,this.source=e,this.field=i,this.setHover=s,this.hoverTime=r,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(){this.pending&&(this.pending=null,clearTimeout(this.restartTimeout),this.restartTimeout=setTimeout(()=>this.startHover(),20))}get active(){return this.view.state.field(this.field)}checkHover(){if(this.hoverTimeout=-1,this.active)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,i=t.docView.nearest(e.target);if(!i)return;let s,r=1;if(i instanceof ht)s=i.posAtStart;else{if(s=t.posAtCoords(e),s==null)return;let l=t.coordsAtPos(s);if(!l||e.y<l.top||e.y>l.bottom||e.x<l.left-t.defaultCharacterWidth||e.x>l.right+t.defaultCharacterWidth)return;let h=t.bidiSpans(t.state.doc.lineAt(s)).find(a=>a.from<=s&&a.to>=s),c=h&&h.dir==L.RTL?-1:1;r=e.x<l.left?-c:c}let o=this.source(t,s,r);if(o?.then){let l=this.pending={pos:s};o.then(h=>{this.pending==l&&(this.pending=null,h&&t.dispatch({effects:this.setHover.of(h)}))},h=>J(t.state,h,"hover tooltip"))}else o&&t.dispatch({effects:this.setHover.of(o)})}mousemove(t){var e;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 i=this.active;if(i&&!bn(this.lastMove.target)||this.pending){let{pos:s}=i||this.pending,r=(e=i?.end)!==null&&e!==void 0?e:s;(s==r?this.view.posAtCoords(this.lastMove)!=s:!qo(this.view,s,r,t.clientX,t.clientY))&&(this.view.dispatch({effects:this.setHover.of(null)}),this.pending=null)}}mouseleave(t){clearTimeout(this.hoverTimeout),this.hoverTimeout=-1,this.active&&!bn(t.relatedTarget)&&this.view.dispatch({effects:this.setHover.of(null)})}destroy(){clearTimeout(this.hoverTimeout),this.view.dom.removeEventListener("mouseleave",this.mouseleave),this.view.dom.removeEventListener("mousemove",this.mousemove)}}function bn(n){for(let t=n;t;t=t.parentNode)if(t.nodeType==1&&t.classList.contains("cm-tooltip"))return!0;return!1}function qo(n,t,e,i,s,r){let o=n.scrollDOM.getBoundingClientRect(),l=n.documentTop+n.documentPadding.top+n.contentHeight;if(o.left>i||o.right<i||o.top>s||Math.min(o.bottom,l)<s)return!1;let h=n.posAtCoords({x:i,y:s},!1);return h>=t&&h<=e}function _o(n,t={}){let e=Dt.define(),i=bi.define({create(){return null},update(s,r){if(s&&(t.hideOnChange&&(r.docChanged||r.selection)||t.hideOn&&t.hideOn(r,s)))return null;if(s&&r.docChanged){let o=r.changes.mapPos(s.pos,-1,gt.TrackDel);if(o==null)return null;let l=Object.assign(Object.create(null),s);l.pos=o,s.end!=null&&(l.end=r.changes.mapPos(s.end)),s=l}for(let o of r.effects)o.is(e)&&(s=o.value),o.is(yn)&&(s=null);return s},provide:s=>Nt.from(s)});return[i,P.define(s=>new Ko(s,n,i,e,t.hoverTime||300)),Io]}function jo(n,t){let e=n.plugin(ei);if(!e)return null;let i=e.manager.tooltips.indexOf(t);return i<0?null:e.manager.tooltipViews[i]}function Go(n){return n.facet(Nt).some(t=>t)}const yn=Dt.define(),$o=yn.of(null);function Uo(n){var t;(t=n.plugin(ei))===null||t===void 0||t.maybeMeasure()}const si=C.define({combine(n){let t,e;for(let i of n)t=t||i.topContainer,e=e||i.bottomContainer;return{topContainer:t,bottomContainer:e}}});function Yo(n){return n?[si.of(n)]:[]}function Xo(n,t){let e=n.plugin(wn),i=e?e.specs.indexOf(t):-1;return i>-1?e.panels[i]:null}const wn=P.fromClass(class{constructor(n){this.input=n.state.facet(ni),this.specs=this.input.filter(e=>e),this.panels=this.specs.map(e=>e(n));let t=n.state.facet(si);this.top=new ge(n,!0,t.topContainer),this.bottom=new ge(n,!1,t.bottomContainer),this.top.sync(this.panels.filter(e=>e.top)),this.bottom.sync(this.panels.filter(e=>!e.top));for(let e of this.panels)e.dom.classList.add("cm-panel"),e.mount&&e.mount()}update(n){let t=n.state.facet(si);this.top.container!=t.topContainer&&(this.top.sync([]),this.top=new ge(n.view,!0,t.topContainer)),this.bottom.container!=t.bottomContainer&&(this.bottom.sync([]),this.bottom=new ge(n.view,!1,t.bottomContainer)),this.top.syncClasses(),this.bottom.syncClasses();let e=n.state.facet(ni);if(e!=this.input){let i=e.filter(h=>h),s=[],r=[],o=[],l=[];for(let h of i){let c=this.specs.indexOf(h),a;c<0?(a=h(n.view),l.push(a)):(a=this.panels[c],a.update&&a.update(n)),s.push(a),(a.top?r:o).push(a)}this.specs=i,this.panels=s,this.top.sync(r),this.bottom.sync(o);for(let h of l)h.dom.classList.add("cm-panel"),h.mount&&h.mount()}else for(let i of this.panels)i.update&&i.update(n)}destroy(){this.top.sync([]),this.bottom.sync([])}},{provide:n=>A.scrollMargins.of(t=>{let e=t.plugin(n);return e&&{top:e.top.scrollMargin(),bottom:e.bottom.scrollMargin()}})});class ge{constructor(t,e,i){this.view=t,this.top=e,this.container=i,this.dom=void 0,this.classes="",this.panels=[],this.syncClasses()}sync(t){for(let e of this.panels)e.destroy&&t.indexOf(e)<0&&e.destroy();this.panels=t,this.syncDOM()}syncDOM(){if(this.panels.length==0){this.dom&&(this.dom.remove(),this.dom=void 0);return}if(!this.dom){this.dom=document.createElement("div"),this.dom.className=this.top?"cm-panels cm-panels-top":"cm-panels cm-panels-bottom",this.dom.style[this.top?"top":"bottom"]="0";let e=this.container||this.view.dom;e.insertBefore(this.dom,this.top?e.firstChild:null)}let t=this.dom.firstChild;for(let e of this.panels)if(e.dom.parentNode==this.dom){for(;t!=e.dom;)t=Sn(t);t=t.nextSibling}else this.dom.insertBefore(e.dom,t);for(;t;)t=Sn(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 Sn(n){let t=n.nextSibling;return n.remove(),t}const ni=C.define({enables:wn});class Q extends ui{compare(t){return this==t||this.constructor==t.constructor&&this.eq(t)}eq(t){return!1}destroy(t){}}Q.prototype.elementClass="",Q.prototype.toDOM=void 0,Q.prototype.mapMode=gt.TrackBefore,Q.prototype.startSide=Q.prototype.endSide=-1,Q.prototype.point=!0;const Vt=C.define(),Jo={class:"",renderEmptyElements:!1,elementStyle:"",markers:()=>F.empty,lineMarker:()=>null,widgetMarker:()=>null,lineMarkerChange:null,initialSpacer:null,updateSpacer:null,domEventHandlers:{}},Wt=C.define();function Zo(n){return[oi(),Wt.of(Object.assign(Object.assign({},Jo),n))]}const ri=C.define({combine:n=>n.some(t=>t)});function oi(n){let t=[Qo];return n&&n.fixed===!1&&t.push(ri.of(!0)),t}const Qo=P.fromClass(class{constructor(n){this.view=n,this.prevViewport=n.viewport,this.dom=document.createElement("div"),this.dom.className="cm-gutters",this.dom.setAttribute("aria-hidden","true"),this.dom.style.minHeight=this.view.contentHeight+"px",this.gutters=n.state.facet(Wt).map(t=>new vn(n,t));for(let t of this.gutters)this.dom.appendChild(t.dom);this.fixed=!n.state.facet(ri),this.fixed&&(this.dom.style.position="sticky"),this.syncGutters(!1),n.scrollDOM.insertBefore(this.dom,n.contentDOM)}update(n){if(this.updateGutters(n)){let t=this.prevViewport,e=n.view.viewport,i=Math.min(t.to,e.to)-Math.max(t.from,e.from);this.syncGutters(i<(e.to-e.from)*.8)}n.geometryChanged&&(this.dom.style.minHeight=this.view.contentHeight+"px"),this.view.state.facet(ri)!=!this.fixed&&(this.fixed=!this.fixed,this.dom.style.position=this.fixed?"sticky":""),this.prevViewport=n.view.viewport}syncGutters(n){let t=this.dom.nextSibling;n&&this.dom.remove();let e=F.iter(this.view.state.facet(Vt),this.view.viewport.from),i=[],s=this.gutters.map(r=>new tl(r,this.view.viewport,-this.view.documentPadding.top));for(let r of this.view.viewportLineBlocks)if(i.length&&(i=[]),Array.isArray(r.type)){let o=!0;for(let l of r.type)if(l.type==R.Text&&o){li(e,i,l.from);for(let h of s)h.line(this.view,l,i);o=!1}else if(l.widget)for(let h of s)h.widget(this.view,l)}else if(r.type==R.Text){li(e,i,r.from);for(let o of s)o.line(this.view,r,i)}for(let r of s)r.finish();n&&this.view.scrollDOM.insertBefore(this.dom,t)}updateGutters(n){let t=n.startState.facet(Wt),e=n.state.facet(Wt),i=n.docChanged||n.heightChanged||n.viewportChanged||!F.eq(n.startState.facet(Vt),n.state.facet(Vt),n.view.viewport.from,n.view.viewport.to);if(t==e)for(let s of this.gutters)s.update(n)&&(i=!0);else{i=!0;let s=[];for(let r of e){let o=t.indexOf(r);o<0?s.push(new vn(this.view,r)):(this.gutters[o].update(n),s.push(this.gutters[o]))}for(let r of this.gutters)r.dom.remove(),s.indexOf(r)<0&&r.destroy();for(let r of s)this.dom.appendChild(r.dom);this.gutters=s}return i}destroy(){for(let n of this.gutters)n.destroy();this.dom.remove()}},{provide:n=>A.scrollMargins.of(t=>{let e=t.plugin(n);return!e||e.gutters.length==0||!e.fixed?null:t.textDirection==L.LTR?{left:e.dom.offsetWidth}:{right:e.dom.offsetWidth}})});function xn(n){return Array.isArray(n)?n:[n]}function li(n,t,e){for(;n.value&&n.from<=e;)n.from==e&&t.push(n.value),n.next()}class tl{constructor(t,e,i){this.gutter=t,this.height=i,this.i=0,this.cursor=F.iter(t.markers,e.from)}addElement(t,e,i){let{gutter:s}=this,r=e.top-this.height;if(this.i==s.elements.length){let o=new Mn(t,e.height,r,i);s.elements.push(o),s.dom.appendChild(o.dom)}else s.elements[this.i].update(t,e.height,r,i);this.height=e.bottom,this.i++}line(t,e,i){let s=[];li(this.cursor,s,e.from),i.length&&(s=s.concat(i));let r=this.gutter.config.lineMarker(t,e,s);r&&s.unshift(r);let o=this.gutter;s.length==0&&!o.config.renderEmptyElements||this.addElement(t,e,s)}widget(t,e){let i=this.gutter.config.widgetMarker(t,e.widget,e);i&&this.addElement(t,e,[i])}finish(){let t=this.gutter;for(;t.elements.length>this.i;){let e=t.elements.pop();t.dom.removeChild(e.dom),e.destroy()}}}class vn{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 r=s.target,o;if(r!=this.dom&&this.dom.contains(r)){for(;r.parentNode!=this.dom;)r=r.parentNode;let h=r.getBoundingClientRect();o=(h.top+h.bottom)/2}else o=s.clientY;let l=t.lineBlockAtHeight(o-t.documentTop);e.domEventHandlers[i](t,l,s)&&s.preventDefault()});this.markers=xn(e.markers(t)),e.initialSpacer&&(this.spacer=new Mn(t,0,0,[e.initialSpacer(t)]),this.dom.appendChild(this.spacer.dom),this.spacer.dom.style.cssText+="visibility: hidden; pointer-events: none")}update(t){let e=this.markers;if(this.markers=xn(this.config.markers(t.view)),this.spacer&&this.config.updateSpacer){let s=this.config.updateSpacer(this.spacer.markers[0],t);s!=this.spacer.markers[0]&&this.spacer.update(t.view,0,0,[s])}let i=t.view.viewport;return!F.eq(this.markers,e,i.from,i.to)||(this.config.lineMarkerChange?this.config.lineMarkerChange(t):!1)}destroy(){for(let t of this.elements)t.destroy()}}class Mn{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){this.height!=e&&(this.dom.style.height=(this.height=e)+"px"),this.above!=i&&(this.dom.style.marginTop=(this.above=i)?i+"px":""),el(this.markers,s)||this.setMarkers(t,s)}setMarkers(t,e){let i="cm-gutterElement",s=this.dom.firstChild;for(let r=0,o=0;;){let l=o,h=r<e.length?e[r++]:null,c=!1;if(h){let a=h.elementClass;a&&(i+=" "+a);for(let d=o;d<this.markers.length;d++)if(this.markers[d].compare(h)){l=d,c=!0;break}}else l=this.markers.length;for(;o<l;){let a=this.markers[o++];if(a.toDOM){a.destroy(s);let d=s.nextSibling;s.remove(),s=d}}if(!h)break;h.toDOM&&(c?s=s.nextSibling:this.dom.insertBefore(h.toDOM(t),s)),c&&o++}this.dom.className=i,this.markers=e}destroy(){this.setMarkers(null,[])}}function el(n,t){if(n.length!=t.length)return!1;for(let e=0;e<n.length;e++)if(!n[e].compare(t[e]))return!1;return!0}const Cn=C.define(),vt=C.define({combine(n){return Se(n,{formatNumber:String,domEventHandlers:{}},{domEventHandlers(t,e){let i=Object.assign({},t);for(let s in e){let r=i[s],o=e[s];i[s]=r?(l,h,c)=>r(l,h,c)||o(l,h,c):o}return i}})}});class hi extends Q{constructor(t){super(),this.number=t}eq(t){return this.number==t.number}toDOM(){return document.createTextNode(this.number)}}function ai(n,t){return n.state.facet(vt).formatNumber(t,n.state)}const il=Wt.compute([vt],n=>({class:"cm-lineNumbers",renderEmptyElements:!1,markers(t){return t.state.facet(Cn)},lineMarker(t,e,i){return i.some(s=>s.toDOM)?null:new hi(ai(t,t.state.doc.lineAt(e.from).number))},widgetMarker:()=>null,lineMarkerChange:t=>t.startState.facet(vt)!=t.state.facet(vt),initialSpacer(t){return new hi(ai(t,kn(t.state.doc.lines)))},updateSpacer(t,e){let i=ai(e.view,kn(e.view.state.doc.lines));return i==t.number?t:new hi(i)},domEventHandlers:n.facet(vt).domEventHandlers}));function sl(n={}){return[vt.of(n),oi(),il]}function kn(n){let t=9;for(;t<n;)t=t*10+9;return t}const nl=new class extends Q{constructor(){super(...arguments),this.elementClass="cm-activeLineGutter"}},rl=Vt.compute(["selection"],n=>{let t=[],e=-1;for(let i of n.selection.ranges){let s=n.doc.lineAt(i.head).from;s>e&&(e=s,t.push(nl.range(s)))}return F.of(t)});function ol(){return rl}const An=new Map;function ll(n){let t=An.get(n);return t||An.set(n,t=B.mark({attributes:n==="	"?{class:"cm-highlightTab"}:{class:"cm-highlightSpace","data-display":n.replace(/ /g,"\xB7")}})),t}function Dn(n){return P.define(t=>({decorations:n.createDeco(t),update(e){this.decorations=n.updateDeco(e,this.decorations)}}),{decorations:t=>t.decorations})}const hl=Dn(new fe({regexp:/\t| +/g,decoration:n=>ll(n[0]),boundary:/\S/}));function al(){return hl}const cl=Dn(new fe({regexp:/\s+$/g,decoration:B.mark({class:"cm-trailingSpace"}),boundary:/\S/}));function fl(){return cl}const dl={HeightMap:W,HeightOracle:zs,MeasuredHeights:Is,QueryType:O,ChangedRange:_,computeOrder:ls,moveVisually:cs};export{Z as BidiSpan,j as BlockInfo,R as BlockType,B as Decoration,L as Direction,A as EditorView,Q as GutterMarker,fe as MatchDecorator,Mt as RectangleMarker,P as ViewPlugin,Kt as ViewUpdate,dt as WidgetType,dl as __test,$o as closeHoverTooltips,No as crosshairCursor,lo as drawSelection,uo as dropCursor,Xo as getPanel,jo as getTooltip,Zo as gutter,Vt as gutterLineClass,oi as gutters,Go as hasHoverTooltips,ko as highlightActiveLine,ol as highlightActiveLineGutter,yo as highlightSpecialChars,fl as highlightTrailingWhitespace,al as highlightWhitespace,_o as hoverTooltip,Qs as keymap,Je as layer,Cn as lineNumberMarkers,sl as lineNumbers,J as logException,Yo as panels,To as placeholder,Eo as rectangularSelection,Uo as repositionTooltips,eo as runScopeHandlers,Co as scrollPastEnd,ni as showPanel,ii as showTooltip,Vo as tooltips};

The same content is in 12 releases, Joomla 5.0.1-rc1 to 5.1.0-alpha4. See them all, or every version of this file.