@pyscript/core 0.7.13 → 0.7.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/dist/{codemirror-lkW_eC9r.js → codemirror-BIjK0FyF.js} +2 -2
  2. package/dist/{codemirror-lkW_eC9r.js.map → codemirror-BIjK0FyF.js.map} +1 -1
  3. package/dist/{codemirror_commands-DL2aL4qa.js → codemirror_commands-Ot159sys.js} +2 -2
  4. package/dist/{codemirror_commands-DL2aL4qa.js.map → codemirror_commands-Ot159sys.js.map} +1 -1
  5. package/dist/{codemirror_lang-python-DD5EtV36.js → codemirror_lang-python-BrxzY-1G.js} +2 -2
  6. package/dist/{codemirror_lang-python-DD5EtV36.js.map → codemirror_lang-python-BrxzY-1G.js.map} +1 -1
  7. package/dist/{codemirror_language-DRHeqAwG.js → codemirror_language-CGuBIifm.js} +2 -2
  8. package/dist/{codemirror_language-DRHeqAwG.js.map → codemirror_language-CGuBIifm.js.map} +1 -1
  9. package/dist/{codemirror_view-FN7LalDk.js → codemirror_view-C_m1bYT7.js} +2 -2
  10. package/dist/{codemirror_view-FN7LalDk.js.map → codemirror_view-C_m1bYT7.js.map} +1 -1
  11. package/dist/core-uXjUCyYJ.js +4 -0
  12. package/dist/core-uXjUCyYJ.js.map +1 -0
  13. package/dist/core.js +1 -1
  14. package/dist/{deprecations-manager-BRHTwqUZ.js → deprecations-manager-9ZyrTvDd.js} +2 -2
  15. package/dist/{deprecations-manager-BRHTwqUZ.js.map → deprecations-manager-9ZyrTvDd.js.map} +1 -1
  16. package/dist/{donkey-CBEqGHeD.js → donkey-BT724r9p.js} +2 -2
  17. package/dist/{donkey-CBEqGHeD.js.map → donkey-BT724r9p.js.map} +1 -1
  18. package/dist/{error-DRVc1NKK.js → error-M0noMyk4.js} +2 -2
  19. package/dist/{error-DRVc1NKK.js.map → error-M0noMyk4.js.map} +1 -1
  20. package/dist/{index-C-U2wRvV.js → index-DM-nsZEM.js} +2 -2
  21. package/dist/{index-C-U2wRvV.js.map → index-DM-nsZEM.js.map} +1 -1
  22. package/dist/{mpy-B-jI5Qug.js → mpy-C-mFwLd4.js} +2 -2
  23. package/dist/{mpy-B-jI5Qug.js.map → mpy-C-mFwLd4.js.map} +1 -1
  24. package/dist/{py-DNLpCVR2.js → py-CCtvrzWS.js} +2 -2
  25. package/dist/{py-DNLpCVR2.js.map → py-CCtvrzWS.js.map} +1 -1
  26. package/dist/{py-editor-DCtATRBs.js → py-editor-DiFcvRlU.js} +2 -2
  27. package/dist/{py-editor-DCtATRBs.js.map → py-editor-DiFcvRlU.js.map} +1 -1
  28. package/dist/{py-game-BGWt8dH1.js → py-game-2v7HaC-d.js} +2 -2
  29. package/dist/{py-game-BGWt8dH1.js.map → py-game-2v7HaC-d.js.map} +1 -1
  30. package/dist/{py-terminal-BKvzGq7q.js → py-terminal-C8V2KXpf.js} +2 -2
  31. package/dist/{py-terminal-BKvzGq7q.js.map → py-terminal-C8V2KXpf.js.map} +1 -1
  32. package/dist/toml-DCqPSmRg.js +3 -0
  33. package/dist/toml-DCqPSmRg.js.map +1 -0
  34. package/dist/zip-CgZGjqjF.js.map +1 -1
  35. package/package.json +3 -3
  36. package/src/core.js +174 -186
  37. package/src/stdlib/pyscript/context.py +4 -1
  38. package/src/stdlib/pyscript.js +1 -1
  39. package/dist/core-B4BRXuDy.js +0 -4
  40. package/dist/core-B4BRXuDy.js.map +0 -1
  41. package/dist/toml-BK2RWy-G.js +0 -3
  42. package/dist/toml-BK2RWy-G.js.map +0 -1
@@ -1,2 +1,2 @@
1
- import{StateEffect as t,Facet as e,RangeValue as i,RangeSet as s,EditorState as o,Transaction as n,Annotation as r,EditorSelection as l,Prec as a,RangeSetBuilder as h,ChangeSet as c,findClusterBreak as d,Text as u,StateField as f,MapMode as p,combineConfig as g,codePointAt as m,countColumn as v,codePointSize as w,findColumn as b,CharCategory as y}from"./codemirror_state-BNbbkoNK.js";const x="undefined"==typeof Symbol?"__ͼ":Symbol.for("ͼ"),S="undefined"==typeof Symbol?"__styleSet"+Math.floor(1e8*Math.random()):Symbol("styleSet"),C="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:{};class M{constructor(t,e){this.rules=[];let{finish:i}=e||{};function s(t){return/^@/.test(t)?[t]:t.split(/,\s*/)}function o(t,e,n,r){let l=[],a=/^@(\w+)\b/.exec(t[0]),h=a&&"keyframes"==a[1];if(a&&null==e)return n.push(t[0]+";");for(let i in e){let r=e[i];if(/&/.test(i))o(i.split(/,\s*/).map(e=>t.map(t=>e.replace(/&/,t))).reduce((t,e)=>t.concat(e)),r,n);else if(r&&"object"==typeof r){if(!a)throw new RangeError("The value of a property ("+i+") should be a primitive value.");o(s(i),r,l,h)}else null!=r&&l.push(i.replace(/_.*/,"").replace(/[A-Z]/g,t=>"-"+t.toLowerCase())+": "+r+";")}(l.length||h)&&n.push((!i||a||r?t:t.map(i)).join(", ")+" {"+l.join(" ")+"}")}for(let e in t)o(s(e),t[e],this.rules)}getRules(){return this.rules.join("\n")}static newName(){let t=C[x]||1;return C[x]=t+1,"ͼ"+t.toString(36)}static mount(t,e,i){let s=t[S],o=i&&i.nonce;s?o&&s.setNonce(o):s=new A(t,o),s.mount(Array.isArray(e)?e:[e],t)}}let k=new Map;class A{constructor(t,e){let i=t.ownerDocument||t,s=i.defaultView;if(!t.head&&t.adoptedStyleSheets&&s.CSSStyleSheet){let e=k.get(i);if(e)return t[S]=e;this.sheet=new s.CSSStyleSheet,k.set(i,this)}else this.styleTag=i.createElement("style"),e&&this.styleTag.setAttribute("nonce",e);this.modules=[],t[S]=this}mount(t,e){let i=this.sheet,s=0,o=0;for(let e=0;e<t.length;e++){let n=t[e],r=this.modules.indexOf(n);if(r<o&&r>-1&&(this.modules.splice(r,1),o--,r=-1),-1==r){if(this.modules.splice(o++,0,n),i)for(let t=0;t<n.rules.length;t++)i.insertRule(n.rules[t],s++)}else{for(;o<r;)s+=this.modules[o++].rules.length;s+=n.rules.length,o++}}if(i)e.adoptedStyleSheets.indexOf(this.sheet)<0&&(e.adoptedStyleSheets=[this.sheet,...e.adoptedStyleSheets]);else{let t="";for(let e=0;e<this.modules.length;e++)t+=this.modules[e].getRules()+"\n";this.styleTag.textContent=t;let i=e.head||e;this.styleTag.parentNode!=i&&i.insertBefore(this.styleTag,i.firstChild)}}setNonce(t){this.styleTag&&this.styleTag.getAttribute("nonce")!=t&&this.styleTag.setAttribute("nonce",t)}}for(var T={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:"'"},D={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},O="undefined"!=typeof navigator&&/Mac/.test(navigator.platform),L="undefined"!=typeof navigator&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent),B=0;B<10;B++)T[48+B]=T[96+B]=String(B);for(B=1;B<=24;B++)T[B+111]="F"+B;for(B=65;B<=90;B++)T[B]=String.fromCharCode(B+32),D[B]=String.fromCharCode(B);for(var E in T)D.hasOwnProperty(E)||(D[E]=T[E]);function R(){var t=arguments[0];"string"==typeof t&&(t=document.createElement(t));var e=1,i=arguments[1];if(i&&"object"==typeof i&&null==i.nodeType&&!Array.isArray(i)){for(var s in i)if(Object.prototype.hasOwnProperty.call(i,s)){var o=i[s];"string"==typeof o?t.setAttribute(s,o):null!=o&&(t[s]=o)}e++}for(;e<arguments.length;e++)H(t,arguments[e]);return t}function H(t,e){if("string"==typeof e)t.appendChild(document.createTextNode(e));else if(null==e);else if(null!=e.nodeType)t.appendChild(e);else{if(!Array.isArray(e))throw new RangeError("Unsupported child node: "+e);for(var i=0;i<e.length;i++)H(t,e[i])}}let W="undefined"!=typeof navigator?navigator:{userAgent:"",vendor:"",platform:""},N="undefined"!=typeof document?document:{documentElement:{style:{}}};const P=/Edge\/(\d+)/.exec(W.userAgent),V=/MSIE \d/.test(W.userAgent),F=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(W.userAgent),z=!!(V||F||P),I=!z&&/gecko\/(\d+)/i.test(W.userAgent),q=!z&&/Chrome\/(\d+)/.exec(W.userAgent),K="webkitFontSmoothing"in N.documentElement.style,_=!z&&/Apple Computer/.test(W.vendor),Y=_&&(/Mobile\/\w+/.test(W.userAgent)||W.maxTouchPoints>2);var j={mac:Y||/Mac/.test(W.platform),windows:/Win/.test(W.platform),linux:/Linux|X11/.test(W.platform),ie:z,ie_version:V?N.documentMode||6:F?+F[1]:P?+P[1]:0,gecko:I,gecko_version:I?+(/Firefox\/(\d+)/.exec(W.userAgent)||[0,0])[1]:0,chrome:!!q,chrome_version:q?+q[1]:0,ios:Y,android:/Android\b/.test(W.userAgent),webkit_version:K?+(/\bAppleWebKit\/(\d+)/.exec(W.userAgent)||[0,0])[1]:0,safari:_,safari_version:_?+(/\bVersion\/(\d+(\.\d+)?)/.exec(W.userAgent)||[0,0])[1]:0,tabSize:null!=N.documentElement.style.tabSize?"tab-size":"-moz-tab-size"};function X(t,e){for(let i in t)"class"==i&&e.class?e.class+=" "+t.class:"style"==i&&e.style?e.style+=";"+t.style:e[i]=t[i];return e}const G=Object.create(null);function U(t,e,i){if(t==e)return!0;t||(t=G),e||(e=G);let s=Object.keys(t),o=Object.keys(e);if(s.length-0!=o.length-0)return!1;for(let n of s)if(n!=i&&(-1==o.indexOf(n)||t[n]!==e[n]))return!1;return!0}function $(t,e,i){let s=!1;if(e)for(let o in e)i&&o in i||(s=!0,"style"==o?t.style.cssText="":t.removeAttribute(o));if(i)for(let o in i)e&&e[o]==i[o]||(s=!0,"style"==o?t.style.cssText=i[o]:t.setAttribute(o,i[o]));return s}function Q(t){let e=Object.create(null);for(let i=0;i<t.attributes.length;i++){let s=t.attributes[i];e[s.name]=s.value}return e}class J{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}get editable(){return!1}destroy(t){}}var Z=function(t){return t[t.Text=0]="Text",t[t.WidgetBefore=1]="WidgetBefore",t[t.WidgetAfter=2]="WidgetAfter",t[t.WidgetRange=3]="WidgetRange",t}(Z||(Z={}));class tt extends i{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 et(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 st(t,e,e,i,t.widget||null,!1)}static replace(t){let e,i,s=!!t.block;if(t.isBlockGap)e=-5e8,i=4e8;else{let{start:o,end:n}=ot(t,s);e=(o?s?-3e8:-1:5e8)-1,i=1+(n?s?2e8:1:-6e8)}return new st(t,e,i,s,t.widget||null,!0)}static line(t){return new it(t)}static set(t,e=!1){return s.of(t,e)}hasHeight(){return!!this.widget&&this.widget.estimatedHeight>-1}}tt.none=s.empty;class et extends tt{constructor(t){let{start:e,end:i}=ot(t);super(e?-1:5e8,i?1:-6e8,null,t),this.tagName=t.tagName||"span",this.attrs=t.class&&t.attributes?X(t.attributes,{class:t.class}):t.class?{class:t.class}:t.attributes||G}eq(t){return this==t||t instanceof et&&this.tagName==t.tagName&&U(this.attrs,t.attrs)}range(t,e=t){if(t>=e)throw new RangeError("Mark decorations may not be empty");return super.range(t,e)}}et.prototype.point=!1;class it extends tt{constructor(t){super(-2e8,-2e8,null,t)}eq(t){return t instanceof it&&this.spec.class==t.spec.class&&U(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)}}it.prototype.mapMode=p.TrackBefore,it.prototype.point=!0;class st extends tt{constructor(t,e,i,s,o,n){super(e,i,o,t),this.block=s,this.isReplace=n,this.mapMode=s?e<=0?p.TrackBefore:p.TrackAfter:p.TrackDel}get type(){return this.startSide!=this.endSide?Z.WidgetRange:this.startSide<=0?Z.WidgetBefore:Z.WidgetAfter}get heightRelevant(){return this.block||!!this.widget&&(this.widget.estimatedHeight>=5||this.widget.lineBreaks>0)}eq(t){return t instanceof st&&(e=this.widget,i=t.widget,e==i||!!(e&&i&&e.compare(i)))&&this.block==t.block&&this.startSide==t.startSide&&this.endSide==t.endSide;var e,i}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)}}function ot(t,e=!1){let{inclusiveStart:i,inclusiveEnd:s}=t;return null==i&&(i=t.inclusive),null==s&&(s=t.inclusive),{start:null!=i?i:e,end:null!=s?s:e}}function nt(t,e,i,s=0){let o=i.length-1;o>=0&&i[o]+s>=t?i[o]=Math.max(i[o],e):i.push(t,e)}st.prototype.point=!0;class rt extends i{constructor(t,e){super(),this.tagName=t,this.attributes=e}eq(t){return t==this||t instanceof rt&&this.tagName==t.tagName&&U(this.attributes,t.attributes)}static create(t){return new rt(t.tagName,t.attributes||G)}static set(t,e=!1){return s.of(t,e)}}function lt(t){let e;return e=11==t.nodeType?t.getSelection?t:t.ownerDocument:t,e.getSelection()}function at(t,e){return!!e&&(t==e||t.contains(1!=e.nodeType?e.parentNode:e))}function ht(t,e){if(!e.anchorNode)return!1;try{return at(t,e.anchorNode)}catch(t){return!1}}function ct(t){return 3==t.nodeType?Ct(t,0,t.nodeValue.length).getClientRects():1==t.nodeType?t.getClientRects():[]}function dt(t,e,i,s){return!!i&&(pt(t,e,i,s,-1)||pt(t,e,i,s,1))}function ut(t){for(var e=0;;e++)if(!(t=t.previousSibling))return e}function ft(t){return 1==t.nodeType&&/^(DIV|P|LI|UL|OL|BLOCKQUOTE|DD|DT|H\d|SECTION|PRE)$/.test(t.nodeName)}function pt(t,e,i,s,o){for(;;){if(t==i&&e==s)return!0;if(e==(o<0?0:gt(t))){if("DIV"==t.nodeName)return!1;let i=t.parentNode;if(!i||1!=i.nodeType)return!1;e=ut(t)+(o<0?0:1),t=i}else{if(1!=t.nodeType)return!1;if(1==(t=t.childNodes[e+(o<0?-1:0)]).nodeType&&"false"==t.contentEditable)return!1;e=o<0?gt(t):0}}}function gt(t){return 3==t.nodeType?t.nodeValue.length:t.childNodes.length}function mt(t,e){let i=e?t.left:t.right;return{left:i,right:i,top:t.top,bottom:t.bottom}}function vt(t){let e=t.visualViewport;return e?{left:0,right:e.width,top:0,bottom:e.height}:{left:0,right:t.innerWidth,top:0,bottom:t.innerHeight}}function wt(t,e){let i=e.width/t.offsetWidth,s=e.height/t.offsetHeight;return(i>.995&&i<1.005||!isFinite(i)||Math.abs(e.width-t.offsetWidth)<1)&&(i=1),(s>.995&&s<1.005||!isFinite(s)||Math.abs(e.height-t.offsetHeight)<1)&&(s=1),{scaleX:i,scaleY:s}}rt.prototype.startSide=rt.prototype.endSide=-1;class bt{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?gt(e):0),i,Math.min(t.focusOffset,i?gt(i):0))}set(t,e,i,s){this.anchorNode=t,this.anchorOffset=e,this.focusNode=i,this.focusOffset=s}}let yt,xt=null;function St(t){if(t.setActive)return t.setActive();if(xt)return t.focus(xt);let e=[];for(let i=t;i&&(e.push(i,i.scrollTop,i.scrollLeft),i!=i.ownerDocument);i=i.parentNode);if(t.focus(null==xt?{get preventScroll(){return xt={preventScroll:!0},!0}}:void 0),!xt){xt=!1;for(let t=0;t<e.length;){let i=e[t++],s=e[t++],o=e[t++];i.scrollTop!=s&&(i.scrollTop=s),i.scrollLeft!=o&&(i.scrollLeft=o)}}}function Ct(t,e,i=e){let s=yt||(yt=document.createRange());return s.setEnd(t,i),s.setStart(t,e),s}function Mt(t,e,i,s){let o={key:e,code:e,keyCode:i,which:i,cancelable:!0};s&&({altKey:o.altKey,ctrlKey:o.ctrlKey,shiftKey:o.shiftKey,metaKey:o.metaKey}=s);let n=new KeyboardEvent("keydown",o);n.synthetic=!0,t.dispatchEvent(n);let r=new KeyboardEvent("keyup",o);return r.synthetic=!0,t.dispatchEvent(r),n.defaultPrevented||r.defaultPrevented}function kt(t){return t.scrollTop>Math.max(1,t.scrollHeight-t.clientHeight-4)}function At(t,e){for(let i=t,s=e;;){if(3==i.nodeType&&s>0)return{node:i,offset:s};if(1==i.nodeType&&s>0){if("false"==i.contentEditable)return null;i=i.childNodes[s-1],s=gt(i)}else{if(!i.parentNode||ft(i))return null;s=ut(i),i=i.parentNode}}}function Tt(t,e){for(let i=t,s=e;;){if(3==i.nodeType&&s<i.nodeValue.length)return{node:i,offset:s};if(1==i.nodeType&&s<i.childNodes.length){if("false"==i.contentEditable)return null;i=i.childNodes[s],s=0}else{if(!i.parentNode||ft(i))return null;s=ut(i)+1,i=i.parentNode}}}j.safari&&j.safari_version>=26&&(xt=!1);class Dt{constructor(t,e,i=!0){this.node=t,this.offset=e,this.precise=i}static before(t,e){return new Dt(t.parentNode,ut(t),e)}static after(t,e){return new Dt(t.parentNode,ut(t)+1,e)}}var Ot=function(t){return t[t.LTR=0]="LTR",t[t.RTL=1]="RTL",t}(Ot||(Ot={}));const Lt=Ot.LTR,Bt=Ot.RTL;function Et(t){let e=[];for(let i=0;i<t.length;i++)e.push(1<<+t[i]);return e}const Rt=Et("88888888888888888888888888888888888666888888787833333333337888888000000000000000000000000008888880000000000000000000000000088888888888888888888888888888888888887866668888088888663380888308888800000000000000000000000800000000000000000000000000000008"),Ht=Et("4444448826627288999999999992222222222222222222222222222222222222222222222229999999999999999999994444444444644222822222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222999999949999999229989999223333333333"),Wt=Object.create(null),Nt=[];for(let t of["()","[]","{}"]){let e=t.charCodeAt(0),i=t.charCodeAt(1);Wt[e]=i,Wt[i]=-e}function Pt(t){return t<=247?Rt[t]:1424<=t&&t<=1524?2:1536<=t&&t<=1785?Ht[t-1536]:1774<=t&&t<=2220?4:8192<=t&&t<=8204?256:64336<=t&&t<=65023?4:1}const Vt=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac\ufb50-\ufdff]/;class Ft{get dir(){return this.level%2?Bt: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}forward(t,e){return t==(this.dir==e)}static find(t,e,i,s){let o=-1;for(let n=0;n<t.length;n++){let r=t[n];if(r.from<=e&&r.to>=e){if(r.level==i)return n;(o<0||(0!=s?s<0?r.from<e:r.to>e:t[o].level>r.level))&&(o=n)}}if(o<0)throw new RangeError("Index out of range");return o}}function zt(t,e){if(t.length!=e.length)return!1;for(let i=0;i<t.length;i++){let s=t[i],o=e[i];if(s.from!=o.from||s.to!=o.to||s.direction!=o.direction||!zt(s.inner,o.inner))return!1}return!0}const It=[];function qt(t,e,i,s,o,n,r){let l=s%2?2:1;if(s%2==o%2)for(let a=e,h=0;a<i;){let e=!0,c=!1;if(h==n.length||a<n[h].from){let t=It[a];t!=l&&(e=!1,c=16==t)}let d=e||1!=l?null:[],u=e?s:s+1,f=a;t:for(;;)if(h<n.length&&f==n[h].from){if(c)break t;let p=n[h];if(!e)for(let t=p.to,e=h+1;;){if(t==i)break t;if(!(e<n.length&&n[e].from==t)){if(It[t]==l)break t;break}t=n[e++].to}if(h++,d)d.push(p);else{p.from>a&&r.push(new Ft(a,p.from,u)),Kt(t,p.direction==Lt!=!(u%2)?s+1:s,o,p.inner,p.from,p.to,r),a=p.to}f=p.to}else{if(f==i||(e?It[f]!=l:It[f]==l))break;f++}d?qt(t,a,f,s+1,o,d,r):a<f&&r.push(new Ft(a,f,u)),a=f}else for(let a=i,h=n.length;a>e;){let i=!0,c=!1;if(!h||a>n[h-1].to){let t=It[a-1];t!=l&&(i=!1,c=16==t)}let d=i||1!=l?null:[],u=i?s:s+1,f=a;t:for(;;)if(h&&f==n[h-1].to){if(c)break t;let p=n[--h];if(!i)for(let t=p.from,i=h;;){if(t==e)break t;if(!i||n[i-1].to!=t){if(It[t-1]==l)break t;break}t=n[--i].from}if(d)d.push(p);else{p.to<a&&r.push(new Ft(p.to,a,u)),Kt(t,p.direction==Lt!=!(u%2)?s+1:s,o,p.inner,p.from,p.to,r),a=p.from}f=p.from}else{if(f==e||(i?It[f-1]!=l:It[f-1]==l))break;f--}d?qt(t,f,a,s+1,o,d,r):f<a&&r.push(new Ft(f,a,u)),a=f}}function Kt(t,e,i,s,o,n,r){let l=e%2?2:1;!function(t,e,i,s,o){for(let n=0;n<=s.length;n++){let r=n?s[n-1].to:e,l=n<s.length?s[n].from:i,a=n?256:o;for(let e=r,i=a,s=a;e<l;e++){let o=Pt(t.charCodeAt(e));512==o?o=i:8==o&&4==s&&(o=16),It[e]=4==o?2:o,7&o&&(s=o),i=o}for(let t=r,e=a,s=a;t<l;t++){let o=It[t];if(128==o)t<l-1&&e==It[t+1]&&24&e?o=It[t]=e:It[t]=256;else if(64==o){let o=t+1;for(;o<l&&64==It[o];)o++;let n=t&&8==e||o<i&&8==It[o]?1==s?1:8:256;for(let e=t;e<o;e++)It[e]=n;t=o-1}else 8==o&&1==s&&(It[t]=1);e=o,7&o&&(s=o)}}}(t,o,n,s,l),function(t,e,i,s,o){let n=1==o?2:1;for(let r=0,l=0,a=0;r<=s.length;r++){let h=r?s[r-1].to:e,c=r<s.length?s[r].from:i;for(let e,i,s,r=h;r<c;r++)if(i=Wt[e=t.charCodeAt(r)])if(i<0){for(let t=l-3;t>=0;t-=3)if(Nt[t+1]==-i){let e=Nt[t+2],i=2&e?o:4&e?1&e?n:o:0;i&&(It[r]=It[Nt[t]]=i),l=t;break}}else{if(189==Nt.length)break;Nt[l++]=r,Nt[l++]=e,Nt[l++]=a}else if(2==(s=It[r])||1==s){let t=s==o;a=t?0:1;for(let e=l-3;e>=0;e-=3){let i=Nt[e+2];if(2&i)break;if(t)Nt[e+2]|=2;else{if(4&i)break;Nt[e+2]|=4}}}}}(t,o,n,s,l),function(t,e,i,s){for(let o=0,n=s;o<=i.length;o++){let r=o?i[o-1].to:t,l=o<i.length?i[o].from:e;for(let a=r;a<l;){let r=It[a];if(256==r){let r=a+1;for(;;)if(r==l){if(o==i.length)break;r=i[o++].to,l=o<i.length?i[o].from:e}else{if(256!=It[r])break;r++}let h=1==n,c=h==(1==(r<e?It[r]:s))?h?1:2:s;for(let e=r,s=o,n=s?i[s-1].to:t;e>a;)e==n&&(e=i[--s].from,n=s?i[s-1].to:t),It[--e]=c;a=r}else n=r,a++}}}(o,n,s,l),qt(t,o,n,e,i,s,r)}function _t(t,e,i){if(!t)return[new Ft(0,0,e==Bt?1:0)];if(e==Lt&&!i.length&&!Vt.test(t))return Yt(t.length);if(i.length)for(;t.length>It.length;)It[It.length]=256;let s=[],o=e==Lt?0:1;return Kt(t,o,o,i,0,t.length,s),s}function Yt(t){return[new Ft(0,t,0)]}let jt="";function Xt(t,e,i,s,o){var n;let r=s.head-t.from,a=Ft.find(e,r,null!==(n=s.bidiLevel)&&void 0!==n?n:-1,s.assoc),h=e[a],c=h.side(o,i);if(r==c){let t=a+=o?1:-1;if(t<0||t>=e.length)return null;h=e[a=t],r=h.side(!o,i),c=h.side(o,i)}let u=d(t.text,r,h.forward(o,i));(u<h.from||u>h.to)&&(u=c),jt=t.text.slice(Math.min(r,u),Math.max(r,u));let f=a==(o?e.length-1:0)?null:e[a+(o?1:-1)];return f&&u==c&&f.level+(o?0:1)<h.level?l.cursor(f.side(!o,i)+t.from,f.forward(o,i)?1:-1,f.level):l.cursor(u+t.from,h.forward(o,i)?-1:1,h.level)}function Gt(t,e,i){for(let s=e;s<i;s++){let e=Pt(t.charCodeAt(s));if(1==e)return Lt;if(2==e||4==e)return Bt}return Lt}const Ut=e.define(),$t=e.define(),Qt=e.define(),Jt=e.define(),Zt=e.define(),te=e.define(),ee=e.define(),ie=e.define(),se=e.define(),oe=e.define({combine:t=>t.some(t=>t)}),ne=e.define({combine:t=>t.some(t=>t)}),re=e.define();class le{constructor(t,e="nearest",i="nearest",s=5,o=5,n=!1){this.range=t,this.y=e,this.x=i,this.yMargin=s,this.xMargin=o,this.isSnapshot=n}map(t){return t.empty?this:new le(this.range.map(t),this.y,this.x,this.yMargin,this.xMargin,this.isSnapshot)}clip(t){return this.range.to<=t.doc.length?this:new le(l.cursor(t.doc.length),this.y,this.x,this.yMargin,this.xMargin,this.isSnapshot)}}const ae=t.define({map:(t,e)=>t.map(e)}),he=t.define();function ce(t,e,i){let s=t.facet(Jt);s.length?s[0](e):window.onerror&&window.onerror(String(e),i,void 0,void 0,e)||(i?console.error(i+":",e):console.error(e))}const de=e.define({combine:t=>!t.length||t[0]});let ue=0;const fe=e.define({combine:t=>t.filter((e,i)=>{for(let s=0;s<i;s++)if(t[s].plugin==e.plugin)return!1;return!0})});class pe{constructor(t,e,i,s,o){this.id=t,this.create=e,this.domEventHandlers=i,this.domEventObservers=s,this.baseExtensions=o(this),this.extension=this.baseExtensions.concat(fe.of({plugin:this,arg:void 0}))}of(t){return this.baseExtensions.concat(fe.of({plugin:this,arg:t}))}static define(t,e){const{eventHandlers:i,eventObservers:s,provide:o,decorations:n}=e||{};return new pe(ue++,t,i,s,t=>{let e=[];return n&&e.push(we.of(e=>{let i=e.plugin(t);return i?n(i):tt.none})),o&&e.push(o(t)),e})}static fromClass(t,e){return pe.define((e,i)=>new t(e,i),e)}}class ge{constructor(t){this.spec=t,this.mustUpdate=null,this.value=null}get plugin(){return this.spec&&this.spec.plugin}update(t){if(this.value){if(this.mustUpdate){let t=this.mustUpdate;if(this.mustUpdate=null,this.value.update)try{this.value.update(t)}catch(e){if(ce(t.state,e,"CodeMirror plugin crashed"),this.value.destroy)try{this.value.destroy()}catch(t){}this.deactivate()}}}else if(this.spec)try{this.value=this.spec.plugin.create(t,this.spec.arg)}catch(e){ce(t.state,e,"CodeMirror plugin crashed"),this.deactivate()}return this}destroy(t){var e;if(null===(e=this.value)||void 0===e?void 0:e.destroy)try{this.value.destroy()}catch(e){ce(t.state,e,"CodeMirror plugin crashed")}}deactivate(){this.spec=this.value=null}}const me=e.define(),ve=e.define(),we=e.define(),be=e.define(),ye=e.define(),xe=e.define(),Se=e.define();function Ce(t,e){let i=t.state.facet(Se);if(!i.length)return i;let o=i.map(e=>e instanceof Function?e(t):e),n=[];return s.spans(o,e.from,e.to,{point(){},span(t,i,s,o){let r=t-e.from,l=i-e.from,a=n;for(let t=s.length-1;t>=0;t--,o--){let i,n=s[t].spec.bidiIsolate;if(null==n&&(n=Gt(e.text,r,l)),o>0&&a.length&&(i=a[a.length-1]).to==r&&i.direction==n)i.to=l,a=i.inner;else{let t={from:r,to:l,direction:n,inner:[]};a.push(t),a=t.inner}}}}),n}const Me=e.define();function ke(t){let e=0,i=0,s=0,o=0;for(let n of t.state.facet(Me)){let r=n(t);r&&(null!=r.left&&(e=Math.max(e,r.left)),null!=r.right&&(i=Math.max(i,r.right)),null!=r.top&&(s=Math.max(s,r.top)),null!=r.bottom&&(o=Math.max(o,r.bottom)))}return{left:e,right:i,top:s,bottom:o}}const Ae=e.define();class Te{constructor(t,e,i,s){this.fromA=t,this.toA=e,this.fromB=i,this.toB=s}join(t){return new Te(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(0==e.length)return t;let i=[];for(let s=0,o=0,n=0;;){let r=s<t.length?t[s].fromB:1e9,l=o<e.length?e[o]:1e9,a=Math.min(r,l);if(1e9==a)break;let h=a+n,c=a,d=h;for(;;)if(o<e.length&&e[o]<=c){let i=e[o+1];o+=2,c=Math.max(c,i);for(let e=s;e<t.length&&t[e].fromB<=c;e++)n=t[e].toA-t[e].toB;d=Math.max(d,i+n)}else{if(!(s<t.length&&t[s].fromB<=c))break;{let e=t[s++];c=Math.max(c,e.toB),d=Math.max(d,e.toA),n=e.toA-e.toB}}i.push(new Te(h,d,a,c))}return i}}class De{constructor(t,e,i){this.view=t,this.state=e,this.transactions=i,this.flags=0,this.startState=t.state,this.changes=c.empty(this.startState.doc.length);for(let t of i)this.changes=this.changes.compose(t.changes);let s=[];this.changes.iterChangedRanges((t,e,i,o)=>s.push(new Te(t,e,i,o))),this.changedRanges=s}static create(t,e,i){return new De(t,e,i)}get viewportChanged(){return(4&this.flags)>0}get viewportMoved(){return(8&this.flags)>0}get heightChanged(){return(2&this.flags)>0}get geometryChanged(){return this.docChanged||(18&this.flags)>0}get focusChanged(){return(1&this.flags)>0}get docChanged(){return!this.changes.empty}get selectionSet(){return this.transactions.some(t=>t.selection)}get empty(){return 0==this.flags&&0==this.transactions.length}}const Oe=[];class Le{constructor(t,e,i=0){this.dom=t,this.length=e,this.flags=i,this.parent=null,t.cmTile=this}get breakAfter(){return 1&this.flags}get children(){return Oe}isWidget(){return!1}get isHidden(){return!1}isComposite(){return!1}isLine(){return!1}isText(){return!1}isBlock(){return!1}get domAttrs(){return null}sync(t){if(this.flags|=2,4&this.flags){this.flags&=-5;let t=this.domAttrs;t&&function(t,e){for(let i=t.attributes.length-1;i>=0;i--){let s=t.attributes[i].name;null==e[s]&&t.removeAttribute(s)}for(let i in e){let s=e[i];"style"==i?t.style.cssText=s:t.getAttribute(i)!=s&&t.setAttribute(i,s)}}(this.dom,t)}}toString(){return this.constructor.name+(this.children.length?`(${this.children})`:"")+(this.breakAfter?"#":"")}destroy(){this.parent=null}setDOM(t){this.dom=t,t.cmTile=this}get posAtStart(){return this.parent?this.parent.posBefore(this):0}get posAtEnd(){return this.posAtStart+this.length}posBefore(t,e=this.posAtStart){let i=e;for(let e of this.children){if(e==t)return i;i+=e.length+e.breakAfter}throw new RangeError("Invalid child in posBefore")}posAfter(t){return this.posBefore(t)+t.length}covers(t){return!0}coordsIn(t,e){return null}domPosFor(t,e){let i=ut(this.dom),s=this.length?t>0:e>0;return new Dt(this.parent.dom,i+(s?1:0),0==t||t==this.length)}markDirty(t){this.flags&=-3,t&&(this.flags|=4),this.parent&&2&this.parent.flags&&this.parent.markDirty(!1)}get overrideDOMText(){return null}get root(){for(let t=this;t;t=t.parent)if(t instanceof Re)return t;return null}static get(t){return t.cmTile}}class Be extends Le{constructor(t){super(t,0),this._children=[]}isComposite(){return!0}get children(){return this._children}get lastChild(){return this.children.length?this.children[this.children.length-1]:null}append(t){this.children.push(t),t.parent=this}sync(t){if(2&this.flags)return;super.sync(t);let e,i=this.dom,s=null,o=(null==t?void 0:t.node)==i?t:null,n=0;for(let r of this.children){if(r.sync(t),n+=r.length+r.breakAfter,e=s?s.nextSibling:i.firstChild,o&&e!=r.dom&&(o.written=!0),r.dom.parentNode==i)for(;e&&e!=r.dom;)e=Ee(e);else i.insertBefore(r.dom,e);s=r.dom}for(e=s?s.nextSibling:i.firstChild,o&&e&&(o.written=!0);e;)e=Ee(e);this.length=n}}function Ee(t){let e=t.nextSibling;return t.parentNode.removeChild(t),e}class Re extends Be{constructor(t,e){super(e),this.view=t}owns(t){for(;t;t=t.parent)if(t==this)return!0;return!1}isBlock(){return!0}nearest(t){for(;;){if(!t)return null;let e=Le.get(t);if(e&&this.owns(e))return e;t=t.parentNode}}blockTiles(t){for(let e=[],i=this,s=0,o=0;;)if(s==i.children.length){if(!e.length)return;i=i.parent,i.breakAfter&&o++,s=e.pop()}else{let n=i.children[s++];if(n instanceof He)e.push(s),i=n,s=0;else{let e=o+n.length,i=t(n,o);if(void 0!==i)return i;o=e+n.breakAfter}}}resolveBlock(t,e){let i,s,o=-1,n=-1;if(this.blockTiles((r,l)=>{let a=l+r.length;if(t>=l&&t<=a){if(r.isWidget()&&e>=-1&&e<=1){if(32&r.flags)return!0;16&r.flags&&(i=void 0)}(l<t||t==a&&(e<-1?r.length:r.covers(1)))&&(!i||!r.isWidget()&&i.isWidget())&&(i=r,o=t-l),(a>t||t==l&&(e>1?r.length:r.covers(-1)))&&(!s||!r.isWidget()&&s.isWidget())&&(s=r,n=t-l)}}),!i&&!s)throw new Error("No tile at position "+t);return i&&e<0||!s?{tile:i,offset:o}:{tile:s,offset:n}}}class He extends Be{constructor(t,e){super(t),this.wrapper=e}isBlock(){return!0}covers(t){return!!this.children.length&&(t<0?this.children[0].covers(-1):this.lastChild.covers(1))}get domAttrs(){return this.wrapper.attributes}static of(t,e){let i=new He(e||document.createElement(t.tagName),t);return e||(i.flags|=4),i}}class We extends Be{constructor(t,e){super(t),this.attrs=e}isLine(){return!0}static start(t,e,i){let s=new We(e||document.createElement("div"),t);return e&&i||(s.flags|=4),s}get domAttrs(){return this.attrs}resolveInline(t,e,i){let s=null,o=-1,n=null,r=-1;!function t(l,a){for(let h=0,c=0;h<l.children.length&&c<=a;h++){let d=l.children[h],u=c+d.length;u>=a&&(d.isComposite()?t(d,a-c):(!n||n.isHidden&&(e>0||i&&Ne(n,d)))&&(u>a||32&d.flags)?(n=d,r=a-c):(c<a||16&d.flags&&!d.isHidden)&&(s=d,o=a-c)),c=u}}(this,t);let l=(e<0?s:n)||s||n;return l?{tile:l,offset:l==s?o:r}:null}coordsIn(t,e){let i=this.resolveInline(t,e,!0);return i?i.tile.coordsIn(Math.max(0,i.offset),e):function(t){let e=t.dom.lastChild;if(!e)return t.dom.getBoundingClientRect();let i=ct(e);return i[i.length-1]||null}(this)}domIn(t,e){let i=this.resolveInline(t,e);if(i){let{tile:t,offset:s}=i;if(this.dom.contains(t.dom))return t.isText()?new Dt(t.dom,Math.min(t.dom.nodeValue.length,s)):t.domPosFor(s,16&t.flags?1:32&t.flags?-1:e);let o=i.tile.parent,n=!1;for(let t of o.children){if(n)return new Dt(t.dom,0);t==i.tile&&(n=!0)}}return new Dt(this.dom,0)}}function Ne(t,e){let i=t.coordsIn(0,1),s=e.coordsIn(0,1);return i&&s&&s.top<i.bottom}class Pe extends Be{constructor(t,e){super(t),this.mark=e}get domAttrs(){return this.mark.attrs}static of(t,e){let i=new Pe(e||document.createElement(t.tagName),t);return e||(i.flags|=4),i}}class Ve extends Le{constructor(t,e){super(t,e.length),this.text=e}sync(t){2&this.flags||(super.sync(t),this.dom.nodeValue!=this.text&&(t&&t.node==this.dom&&(t.written=!0),this.dom.nodeValue=this.text))}isText(){return!0}toString(){return JSON.stringify(this.text)}coordsIn(t,e){let i=this.dom.nodeValue.length;t>i&&(t=i);let s=t,o=t,n=0;0==t&&e<0||t==i&&e>=0?j.chrome||j.gecko||(t?(s--,n=1):o<i&&(o++,n=-1)):e<0?s--:o<i&&o++;let r=Ct(this.dom,s,o).getClientRects();if(!r.length)return null;let l=r[(n?n<0:e>=0)?0:r.length-1];return j.safari&&!n&&0==l.width&&(l=Array.prototype.find.call(r,t=>t.width)||l),n?mt(l,n<0):l||null}static of(t,e){let i=new Ve(e||document.createTextNode(t),t);return e||(i.flags|=2),i}}class Fe extends Le{constructor(t,e,i,s){super(t,e,s),this.widget=i}isWidget(){return!0}get isHidden(){return this.widget.isHidden}covers(t){return!(48&this.flags)&&(this.flags&(t<0?64:128))>0}coordsIn(t,e){return this.coordsInWidget(t,e,!1)}coordsInWidget(t,e,i){let s=this.widget.coordsAt(this.dom,t,e);if(s)return s;if(i)return mt(this.dom.getBoundingClientRect(),this.length?0==t:e<=0);{let e=this.dom.getClientRects(),i=null;if(!e.length)return null;let s=!!(16&this.flags)||!(32&this.flags)&&t>0;for(let o=s?e.length-1:0;i=e[o],!(t>0?0==o:o==e.length-1||i.top<i.bottom);o+=s?-1:1);return mt(i,!s)}}get overrideDOMText(){if(!this.length)return u.empty;let{root:t}=this;if(!t)return u.empty;let e=this.posAtStart;return t.view.state.doc.slice(e,e+this.length)}destroy(){super.destroy(),this.widget.destroy(this.dom)}static of(t,e,i,s,o){return o||(o=t.toDOM(e),t.editable||(o.contentEditable="false")),new Fe(o,i,t,s)}}class ze extends Le{constructor(t){let e=document.createElement("img");e.className="cm-widgetBuffer",e.setAttribute("aria-hidden","true"),super(e,0,t)}get isHidden(){return!0}get overrideDOMText(){return u.empty}coordsIn(t){return this.dom.getBoundingClientRect()}}class Ie{constructor(t){this.index=0,this.beforeBreak=!1,this.parents=[],this.tile=t}advance(t,e,i){let{tile:s,index:o,beforeBreak:n,parents:r}=this;for(;t||e>0;)if(s.isComposite())if(n){if(!t)break;i&&i.break(),t--,n=!1}else if(o==s.children.length){if(!t&&!r.length)break;i&&i.leave(s),n=!!s.breakAfter,({tile:s,index:o}=r.pop()),o++}else{let l=s.children[o],a=l.breakAfter;!(e>0?l.length<=t:l.length<t)||i&&!1===i.skip(l,0,l.length)&&l.isComposite?(r.push({tile:s,index:o}),s=l,o=0,i&&l.isComposite()&&i.enter(l)):(n=!!a,o++,t-=l.length)}else if(o==s.length)n=!!s.breakAfter,({tile:s,index:o}=r.pop()),o++;else{if(!t)break;{let e=Math.min(t,s.length-o);i&&i.skip(s,o,o+e),t-=e,o+=e}}return this.tile=s,this.index=o,this.beforeBreak=n,this}get root(){return this.parents.length?this.parents[0].tile:this.tile}}class qe{constructor(t,e,i,s){this.from=t,this.to=e,this.wrapper=i,this.rank=s}}class Ke{constructor(t,e,i){this.cache=t,this.root=e,this.blockWrappers=i,this.curLine=null,this.lastBlock=null,this.afterWidget=null,this.pos=0,this.wrappers=[],this.wrapperPos=0}addText(t,e,i,s){var o;this.flushBuffer();let n=this.ensureMarks(e,i),r=n.lastChild;if(!r||!r.isText()||8&r.flags)n.append(s||Ve.of(t,null===(o=this.cache.find(Ve))||void 0===o?void 0:o.dom));else{this.cache.reused.set(r,2),(n.children[n.children.length-1]=new Ve(r.dom,r.text+t)).parent=n}this.pos+=t.length,this.afterWidget=null}addComposition(t,e){let i=this.curLine;i.dom!=e.line.dom&&(i.setDOM(this.cache.reused.has(e.line)?$e(e.line.dom):e.line.dom),this.cache.reused.set(e.line,2));let s=i;for(let t=e.marks.length-1;t>=0;t--){let i=e.marks[t],o=s.lastChild;if(o instanceof Pe&&o.mark.eq(i.mark))o.dom!=i.dom&&o.setDOM($e(i.dom)),s=o;else{if(this.cache.reused.get(i)){let t=Le.get(i.dom);t&&t.setDOM($e(i.dom))}let t=Pe.of(i.mark,i.dom);s.append(t),s=t}this.cache.reused.set(i,2)}let o=Le.get(t.text);o&&this.cache.reused.set(o,2);let n=new Ve(t.text,t.text.nodeValue);n.flags|=8,s.append(n)}addInlineWidget(t,e,i){let s=this.afterWidget&&48&t.flags&&(48&this.afterWidget.flags)==(48&t.flags);s||this.flushBuffer();let o=this.ensureMarks(e,i);s||16&t.flags||o.append(this.getBuffer(1)),o.append(t),this.pos+=t.length,this.afterWidget=t}addMark(t,e,i){this.flushBuffer(),this.ensureMarks(e,i).append(t),this.pos+=t.length,this.afterWidget=null}addBlockWidget(t){this.getBlockPos().append(t),this.pos+=t.length,this.lastBlock=t,this.endLine()}continueWidget(t){(this.afterWidget||this.lastBlock).length+=t,this.pos+=t}addLineStart(t,e){var i;t||(t=Ue);let s=We.start(t,e||(null===(i=this.cache.find(We))||void 0===i?void 0:i.dom),!!e);this.getBlockPos().append(this.lastBlock=this.curLine=s)}addLine(t){this.getBlockPos().append(t),this.pos+=t.length,this.lastBlock=t,this.endLine()}addBreak(){this.lastBlock.flags|=1,this.endLine(),this.pos++}addLineStartIfNotCovered(t){this.blockPosCovered()||this.addLineStart(t)}ensureLine(t){this.curLine||this.addLineStart(t)}ensureMarks(t,e){var i;let s=this.curLine;for(let o=t.length-1;o>=0;o--){let n,r=t[o];if(e>0&&(n=s.lastChild)&&n instanceof Pe&&n.mark.eq(r))s=n,e--;else{let t=Pe.of(r,null===(i=this.cache.find(Pe,t=>t.mark.eq(r)))||void 0===i?void 0:i.dom);s.append(t),s=t,e=0}}return s}endLine(){if(this.curLine){this.flushBuffer();let t=this.curLine.lastChild;t&&Ge(this.curLine,!1)&&("BR"==t.dom.nodeName||!t.isWidget()||j.ios&&Ge(this.curLine,!0))||this.curLine.append(this.cache.findWidget(Je,0,32)||new Fe(Je.toDOM(),0,Je,32)),this.curLine=this.afterWidget=null}}updateBlockWrappers(){this.wrapperPos>this.pos+1e4&&(this.blockWrappers.goto(this.pos),this.wrappers.length=0);for(let t=this.wrappers.length-1;t>=0;t--)this.wrappers[t].to<this.pos&&this.wrappers.splice(t,1);for(let t=this.blockWrappers;t.value&&t.from<=this.pos;t.next())if(t.to>=this.pos){let e=new qe(t.from,t.to,t.value,t.rank),i=this.wrappers.length;for(;i>0&&(this.wrappers[i-1].rank-e.rank||this.wrappers[i-1].to-e.to)<0;)i--;this.wrappers.splice(i,0,e)}this.wrapperPos=this.pos}getBlockPos(){var t;this.updateBlockWrappers();let e=this.root;for(let i of this.wrappers){let s=e.lastChild;if(i.from<this.pos&&s instanceof He&&s.wrapper.eq(i.wrapper))e=s;else{let s=He.of(i.wrapper,null===(t=this.cache.find(He,t=>t.wrapper.eq(i.wrapper)))||void 0===t?void 0:t.dom);e.append(s),e=s}}return e}blockPosCovered(){let t=this.lastBlock;return null!=t&&!t.breakAfter&&(!t.isWidget()||(160&t.flags)>0)}getBuffer(t){let e=2|(t<0?16:32),i=this.cache.find(ze,void 0,1);return i&&(i.flags=e),i||new ze(e)}flushBuffer(){!this.afterWidget||32&this.afterWidget.flags||(this.afterWidget.parent.append(this.getBuffer(-1)),this.afterWidget=null)}}class _e{constructor(t){this.skipCount=0,this.text="",this.textOff=0,this.cursor=t.iter()}skip(t){this.textOff+t<=this.text.length?this.textOff+=t:(this.skipCount+=t-(this.text.length-this.textOff),this.text="",this.textOff=0)}next(t){if(this.textOff==this.text.length){let{value:e,lineBreak:i,done:s}=this.cursor.next(this.skipCount);if(this.skipCount=0,s)throw new Error("Ran out of text content when drawing inline views");this.text=e;let o=this.textOff=Math.min(t,e.length);return i?null:e.slice(0,o)}let e=Math.min(this.text.length,this.textOff+t),i=this.text.slice(this.textOff,e);return this.textOff=e,i}}const Ye=[Fe,We,Ve,Pe,ze,He,Re];for(let t=0;t<Ye.length;t++)Ye[t].bucket=t;class je{constructor(t){this.view=t,this.buckets=Ye.map(()=>[]),this.index=Ye.map(()=>0),this.reused=new Map}add(t){let e=t.constructor.bucket,i=this.buckets[e];i.length<6?i.push(t):i[this.index[e]=(this.index[e]+1)%6]=t}find(t,e,i=2){let s=t.bucket,o=this.buckets[s],n=this.index[s];for(let t=o.length-1;t>=0;t--){let r=(t+n)%o.length,l=o[r];if((!e||e(l))&&!this.reused.has(l))return o.splice(r,1),r<n&&this.index[s]--,this.reused.set(l,i),l}return null}findWidget(t,e,i){let s=this.buckets[0];if(s.length)for(let o=0,n=0;;o++){if(o==s.length){if(n)return null;n=1,o=0}let r=s[o];if(!this.reused.has(r)&&(0==n?r.widget.compare(t):r.widget.constructor==t.constructor&&t.updateDOM(r.dom,this.view)))return s.splice(o,1),o<this.index[0]&&this.index[0]--,r.widget==t&&r.length==e&&(497&r.flags)==i?(this.reused.set(r,1),r):(this.reused.set(r,2),new Fe(r.dom,e,t,-498&r.flags|i))}}reuse(t){return this.reused.set(t,1),t}maybeReuse(t,e=2){if(!this.reused.has(t))return this.reused.set(t,e),t.dom}clear(){for(let t=0;t<this.buckets.length;t++)this.buckets[t].length=this.index[t]=0}}class Xe{constructor(t,e,i,o,n){this.view=t,this.decorations=o,this.disallowBlockEffectsFor=n,this.openWidget=!1,this.openMarks=0,this.cache=new je(t),this.text=new _e(t.state.doc),this.builder=new Ke(this.cache,new Re(t,t.contentDOM),s.iter(i)),this.cache.reused.set(e,2),this.old=new Ie(e),this.reuseWalker={skip:(t,e,i)=>{if(this.cache.add(t),t.isComposite())return!1},enter:t=>this.cache.add(t),leave:()=>{},break:()=>{}}}run(t,e){let i=e&&this.getCompositionContext(e.text);for(let s=0,o=0,n=0;;){let r=n<t.length?t[n++]:null,l=r?r.fromA:this.old.root.length;if(l>s){let t=l-s;this.preserve(t,!n,!r),s=l,o+=t}if(!r)break;e&&r.fromA<=e.range.fromA&&r.toA>=e.range.toA?(this.forward(r.fromA,e.range.fromA,e.range.fromA<e.range.toA?1:-1),this.emit(o,e.range.fromB),this.cache.clear(),this.builder.addComposition(e,i),this.text.skip(e.range.toB-e.range.fromB),this.forward(e.range.fromA,r.toA),this.emit(e.range.toB,r.toB)):(this.forward(r.fromA,r.toA),this.emit(o,r.toB)),o=r.toB,s=r.toA}return this.builder.curLine&&this.builder.endLine(),this.builder.root}preserve(t,e,i){let s=function(t){let e=[];for(let i=t.parents.length;i>1;i--){let s=i==t.parents.length?t.tile:t.parents[i].tile;s instanceof Pe&&e.push(s.mark)}return e}(this.old),o=this.openMarks;this.old.advance(t,i?1:-1,{skip:(t,e,i)=>{if(t.isWidget())if(this.openWidget)this.builder.continueWidget(i-e);else{let n=i>0||e<t.length?Fe.of(t.widget,this.view,i-e,496&t.flags,this.cache.maybeReuse(t)):this.cache.reuse(t);256&n.flags?(n.flags&=-2,this.builder.addBlockWidget(n)):(this.builder.ensureLine(null),this.builder.addInlineWidget(n,s,o),o=s.length)}else if(t.isText())this.builder.ensureLine(null),e||i!=t.length?(this.cache.add(t),this.builder.addText(t.text.slice(e,i),s,o)):this.builder.addText(t.text,s,o,this.cache.reuse(t)),o=s.length;else if(t.isLine())t.flags&=-2,this.cache.reused.set(t,1),this.builder.addLine(t);else if(t instanceof ze)this.cache.add(t);else{if(!(t instanceof Pe))return!1;this.builder.ensureLine(null),this.builder.addMark(t,s,o),this.cache.reused.set(t,1),o=s.length}this.openWidget=!1},enter:t=>{t.isLine()?this.builder.addLineStart(t.attrs,this.cache.maybeReuse(t)):(this.cache.add(t),t instanceof Pe&&s.unshift(t.mark)),this.openWidget=!1},leave:t=>{t.isLine()?s.length&&(s.length=o=0):t instanceof Pe&&(s.shift(),o=Math.min(o,s.length))},break:()=>{this.builder.addBreak(),this.openWidget=!1}}),this.text.skip(t)}emit(t,e){let i=null,o=this.builder,n=0,r=s.spans(this.decorations,t,e,{point:(t,e,s,r,l,a)=>{if(s instanceof st){if(this.disallowBlockEffectsFor[a]){if(s.block)throw new RangeError("Block decorations may not be specified via plugins");if(e>this.view.state.doc.lineAt(t).to)throw new RangeError("Decorations that replace line breaks may not be specified via plugins")}if(n=r.length,l>r.length)o.continueWidget(e-t);else{let n=s.widget||(s.block?Qe.block:Qe.inline),a=function(t){let e=t.isReplace?(t.startSide<0?64:0)|(t.endSide>0?128:0):t.startSide>0?32:16;t.block&&(e|=256);return e}(s),h=this.cache.findWidget(n,e-t,a)||Fe.of(n,this.view,e-t,a);s.block?(s.startSide>0&&o.addLineStartIfNotCovered(i),o.addBlockWidget(h)):(o.ensureLine(i),o.addInlineWidget(h,r,l))}i=null}else i=function(t,e){let i=e.spec.attributes,s=e.spec.class;if(!i&&!s)return t;t||(t={class:"cm-line"});i&&X(i,t);s&&(t.class+=" "+s);return t}(i,s);e>t&&this.text.skip(e-t)},span:(t,e,s,n)=>{for(let r=t;r<e;){let t=this.text.next(Math.min(512,e-r));null==t?(o.addLineStartIfNotCovered(i),o.addBreak(),r++):(o.ensureLine(i),o.addText(t,s,n),r+=t.length),i=null}}});o.addLineStartIfNotCovered(i),this.openWidget=r>n,this.openMarks=r}forward(t,e,i=1){e-t<=10?this.old.advance(e-t,i,this.reuseWalker):(this.old.advance(5,-1,this.reuseWalker),this.old.advance(e-t-10,-1),this.old.advance(5,i,this.reuseWalker))}getCompositionContext(t){let e=[],i=null;for(let s=t.parentNode;;s=s.parentNode){let t=Le.get(s);if(s==this.view.contentDOM)break;t instanceof Pe?e.push(t):(null==t?void 0:t.isLine())?i=t:"DIV"!=s.nodeName||i||s==this.view.contentDOM?e.push(Pe.of(new et({tagName:s.nodeName.toLowerCase(),attributes:Q(s)}),s)):i=new We(s,Ue)}return{line:i,marks:e}}}function Ge(t,e){let i=t=>{for(let s of t.children)if((e?s.isText():s.length)||i(s))return!0;return!1};return i(t)}const Ue={class:"cm-line"};function $e(t){let e=Le.get(t);return e&&e.setDOM(t.cloneNode()),t}class Qe extends J{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}}Qe.inline=new Qe("span"),Qe.block=new Qe("div");const Je=new class extends J{toDOM(){return document.createElement("br")}get isHidden(){return!0}get editable(){return!0}};class Ze{constructor(t){this.view=t,this.decorations=[],this.blockWrappers=[],this.dynamicDecorationMap=[!1],this.domChanged=null,this.hasComposition=null,this.editContextFormatting=tt.none,this.lastCompositionAfterCursor=!1,this.minWidth=0,this.minWidthFrom=0,this.minWidthTo=0,this.impreciseAnchor=null,this.impreciseHead=null,this.forceSelection=!1,this.lastUpdate=Date.now(),this.updateDeco(),this.tile=new Re(t,t.contentDOM),this.updateInner([new Te(0,0,0,t.state.doc.length)],null)}update(t){var e;let i=t.changedRanges;this.minWidth>0&&i.length&&(i.every(({fromA:t,toA:e})=>e<this.minWidthFrom||t>this.minWidthTo)?(this.minWidthFrom=t.changes.mapPos(this.minWidthFrom,1),this.minWidthTo=t.changes.mapPos(this.minWidthTo,1)):this.minWidth=this.minWidthFrom=this.minWidthTo=0),this.updateEditContextFormatting(t);let o=-1;this.view.inputState.composing>=0&&!this.view.observer.editContext&&((null===(e=this.domChanged)||void 0===e?void 0:e.newSel)?o=this.domChanged.newSel.head:function(t,e){let i=!1;e&&t.iterChangedRanges((t,s)=>{t<e.to&&s>e.from&&(i=!0)});return i}(t.changes,this.hasComposition)||t.selectionSet||(o=t.state.selection.main.head));let n=o>-1?function(t,e,i){let s=ei(t,i);if(!s)return null;let{node:o,from:n,to:r}=s,l=o.nodeValue;if(/[\n\r]/.test(l))return null;if(t.state.doc.sliceString(s.from,s.to)!=l)return null;let a=e.invertedDesc;return{range:new Te(a.mapPos(n),a.mapPos(r),n,r),text:o}}(this.view,t.changes,o):null;if(this.domChanged=null,this.hasComposition){let{from:e,to:s}=this.hasComposition;i=new Te(e,s,t.changes.mapPos(e,-1),t.changes.mapPos(s,1)).addToSet(i.slice())}this.hasComposition=n?{from:n.range.fromB,to:n.range.toB}:null,(j.ie||j.chrome)&&!n&&t&&t.state.doc.lines!=t.startState.doc.lines&&(this.forceSelection=!0);let r=this.decorations,l=this.blockWrappers;this.updateDeco();let a=function(t,e,i){let o=new ii;return s.compare(t,e,i,o),o.changes}(r,this.decorations,t.changes);a.length&&(i=Te.extendWithRanges(i,a));let h=function(t,e,i){let o=new si;return s.compare(t,e,i,o),o.changes}(l,this.blockWrappers,t.changes);return h.length&&(i=Te.extendWithRanges(i,h)),n&&!i.some(t=>t.fromA<=n.range.fromA&&t.toA>=n.range.toA)&&(i=n.range.addToSet(i.slice())),!(2&this.tile.flags&&0==i.length)&&(this.updateInner(i,n),t.transactions.length&&(this.lastUpdate=Date.now()),!0)}updateInner(t,e){this.view.viewState.mustMeasureContent=!0;let{observer:i}=this.view;i.ignore(()=>{if(e||t.length){let i=this.tile,s=new Xe(this.view,i,this.blockWrappers,this.decorations,this.dynamicDecorationMap);this.tile=s.run(t,e),ti(i,s.cache.reused)}this.tile.dom.style.height=this.view.viewState.contentHeight/this.view.scaleY+"px",this.tile.dom.style.flexBasis=this.minWidth?this.minWidth+"px":"";let s=j.chrome||j.ios?{node:i.selectionRange.focusNode,written:!1}:void 0;this.tile.sync(s),!s||!s.written&&i.selectionRange.focusNode==s.node&&this.tile.dom.contains(s.node)||(this.forceSelection=!0),this.tile.dom.style.height=""});let s=[];if(this.view.viewport.from||this.view.viewport.to<this.view.state.doc.length)for(let t of this.tile.children)t.isWidget()&&t.widget instanceof oi&&s.push(t.dom);i.updateGaps(s)}updateEditContextFormatting(t){this.editContextFormatting=this.editContextFormatting.map(t.changes);for(let e of t.transactions)for(let t of e.effects)t.is(he)&&(this.editContextFormatting=t.value)}updateSelection(t=!1,e=!1){!t&&this.view.observer.selectionRange.focusNode||this.view.observer.readSelectionRange();let{dom:i}=this.tile,s=this.view.root.activeElement,o=s==i,n=!o&&!(this.view.state.facet(de)||i.tabIndex>-1)&&ht(i,this.view.observer.selectionRange)&&!(s&&i.contains(s));if(!(o||e||n))return;let r=this.forceSelection;this.forceSelection=!1;let l,a,h=this.view.state.selection.main;if(h.empty?a=l=this.inlineDOMNearPos(h.anchor,h.assoc||1):(a=this.inlineDOMNearPos(h.head,h.head==h.from?1:-1),l=this.inlineDOMNearPos(h.anchor,h.anchor==h.from?1:-1)),j.gecko&&h.empty&&!this.hasComposition&&(1==(c=l).node.nodeType&&c.node.firstChild&&(0==c.offset||"false"==c.node.childNodes[c.offset-1].contentEditable)&&(c.offset==c.node.childNodes.length||"false"==c.node.childNodes[c.offset].contentEditable))){let t=document.createTextNode("");this.view.observer.ignore(()=>l.node.insertBefore(t,l.node.childNodes[l.offset]||null)),l=a=new Dt(t,0),r=!0}var c;let d=this.view.observer.selectionRange;!r&&d.focusNode&&(dt(l.node,l.offset,d.anchorNode,d.anchorOffset)&&dt(a.node,a.offset,d.focusNode,d.focusOffset)||this.suppressWidgetCursorChange(d,h))||(this.view.observer.ignore(()=>{j.android&&j.chrome&&i.contains(d.focusNode)&&function(t,e){for(let i=t;i&&i!=e;i=i.assignedSlot||i.parentNode)if(1==i.nodeType&&"false"==i.contentEditable)return!0;return!1}(d.focusNode,i)&&(i.blur(),i.focus({preventScroll:!0}));let t=lt(this.view.root);if(t)if(h.empty){if(j.gecko){let t=(e=l.node,o=l.offset,1!=e.nodeType?0:(o&&"false"==e.childNodes[o-1].contentEditable?1:0)|(o<e.childNodes.length&&"false"==e.childNodes[o].contentEditable?2:0));if(t&&3!=t){let e=(1==t?At:Tt)(l.node,l.offset);e&&(l=new Dt(e.node,e.offset))}}t.collapse(l.node,l.offset),null!=h.bidiLevel&&void 0!==t.caretBidiLevel&&(t.caretBidiLevel=h.bidiLevel)}else if(t.extend){t.collapse(l.node,l.offset);try{t.extend(a.node,a.offset)}catch(t){}}else{let e=document.createRange();h.anchor>h.head&&([l,a]=[a,l]),e.setEnd(a.node,a.offset),e.setStart(l.node,l.offset),t.removeAllRanges(),t.addRange(e)}else;var e,o;n&&this.view.root.activeElement==i&&(i.blur(),s&&s.focus())}),this.view.observer.setSelectionRange(l,a)),this.impreciseAnchor=l.precise?null:new Dt(d.anchorNode,d.anchorOffset),this.impreciseHead=a.precise?null:new Dt(d.focusNode,d.focusOffset)}suppressWidgetCursorChange(t,e){return this.hasComposition&&e.empty&&dt(t.focusNode,t.focusOffset,t.anchorNode,t.anchorOffset)&&this.posFromDOM(t.focusNode,t.focusOffset)==e.head}enforceCursorAssoc(){if(this.hasComposition)return;let{view:t}=this,e=t.state.selection.main,i=lt(t.root),{anchorNode:s,anchorOffset:o}=t.observer.selectionRange;if(!(i&&e.empty&&e.assoc&&i.modify))return;let n=this.lineAt(e.head,e.assoc);if(!n)return;let r=n.posAtStart;if(e.head==r||e.head==r+n.length)return;let l=this.coordsAt(e.head,-1),a=this.coordsAt(e.head,1);if(!l||!a||l.bottom>a.top)return;let h=this.domAtPos(e.head+e.assoc,e.assoc);i.collapse(h.node,h.offset),i.modify("move",e.assoc<0?"forward":"backward","lineboundary"),t.observer.readSelectionRange();let c=t.observer.selectionRange;t.docView.posFromDOM(c.anchorNode,c.anchorOffset)!=e.from&&i.collapse(s,o)}posFromDOM(t,e){let i=this.tile.nearest(t);if(!i)return 2&this.tile.dom.compareDocumentPosition(t)?0:this.view.state.doc.length;let s=i.posAtStart;if(!i.isComposite())return i.isText()?t==i.dom?s+e:s+(e?i.length:0):s;{let o;if(t==i.dom)o=i.dom.childNodes[e];else{let s=0==gt(t)?0:0==e?-1:1;for(;;){let e=t.parentNode;if(e==i.dom)break;0==s&&e.firstChild!=e.lastChild&&(s=t==e.firstChild?-1:1),t=e}o=s<0?t:t.nextSibling}if(o==i.dom.firstChild)return s;for(;o&&!Le.get(o);)o=o.nextSibling;if(!o)return s+i.length;for(let t=0,e=s;;t++){let s=i.children[t];if(s.dom==o)return e;e+=s.length+s.breakAfter}}}domAtPos(t,e){let{tile:i,offset:s}=this.tile.resolveBlock(t,e);return i.isWidget()?i.domPosFor(t,e):i.domIn(s,e)}inlineDOMNearPos(t,e){let i,s,o=-1,n=!1,r=-1,l=!1;return this.tile.blockTiles((e,a)=>{if(e.isWidget()){if(32&e.flags&&a>=t)return!0;16&e.flags&&(n=!0)}else{let h=a+e.length;if(a<=t&&(i=e,o=t-a,n=h<t),h>=t&&!s&&(s=e,r=t-a,l=a>t),a>t&&s)return!0}}),i||s?(n&&s?i=null:l&&i&&(s=null),i&&e<0||!s?i.domIn(o,e):s.domIn(r,e)):this.domAtPos(t,e)}coordsAt(t,e){let{tile:i,offset:s}=this.tile.resolveBlock(t,e);return i.isWidget()?i.widget instanceof oi?null:i.coordsInWidget(s,e,!0):i.coordsIn(s,e)}lineAt(t,e){let{tile:i}=this.tile.resolveBlock(t,e);return i.isLine()?i:null}coordsForChar(t){let{tile:e,offset:i}=this.tile.resolveBlock(t,1);if(!e.isLine())return null;return function t(e,i){if(e.isComposite())for(let s of e.children){if(s.length>=i){let e=t(s,i);if(e)return e}if((i-=s.length)<0)break}else if(e.isText()&&i<e.length){let t=d(e.text,i);if(t==i)return null;let s=Ct(e.dom,i,t).getClientRects();for(let t=0;t<s.length;t++){let e=s[t];if(t==s.length-1||e.top<e.bottom&&e.left<e.right)return e}}return null}(e,i)}measureVisibleLineHeights(t){let e=[],{from:i,to:s}=t,o=this.view.contentDOM.clientWidth,n=o>Math.max(this.view.scrollDOM.clientWidth,this.minWidth)+1,r=-1,l=this.view.textDirection==Ot.LTR,a=0,h=(t,c,d)=>{for(let u=0;u<t.children.length&&!(c>s);u++){let s=t.children[u],f=c+s.length,p=s.dom.getBoundingClientRect(),{height:g}=p;if(d&&!u&&(a+=p.top-d.top),s instanceof He)f>i&&h(s,c,p);else if(c>=i&&(a>0&&e.push(-a),e.push(g+a),a=0,n)){let t=s.dom.lastChild,e=t?ct(t):[];if(e.length){let t=e[e.length-1],i=l?t.right-p.left:p.right-t.left;i>r&&(r=i,this.minWidth=o,this.minWidthFrom=c,this.minWidthTo=f)}}d&&u==t.children.length-1&&(a+=d.bottom-p.bottom),c=f+s.breakAfter}};return h(this.tile,0,null),e}textDirectionAt(t){let{tile:e}=this.tile.resolveBlock(t,1);return"rtl"==getComputedStyle(e.dom).direction?Ot.RTL:Ot.LTR}measureTextSize(){let t=this.tile.blockTiles(t=>{if(t.isLine()&&t.children.length&&t.length<=20){let e,i=0;for(let s of t.children){if(!s.isText()||/[^ -~]/.test(s.text))return;let t=ct(s.dom);if(1!=t.length)return;i+=t[0].width,e=t[0].height}if(i)return{lineHeight:t.dom.getBoundingClientRect().height,charWidth:i/t.length,textHeight:e}}});if(t)return t;let e,i,s,o=document.createElement("div");return o.className="cm-line",o.style.width="99999px",o.style.position="absolute",o.textContent="abc def ghi jkl mno pqr stu",this.view.observer.ignore(()=>{this.tile.dom.appendChild(o);let t=ct(o.firstChild)[0];e=o.getBoundingClientRect().height,i=t&&t.width?t.width/27:7,s=t&&t.height?t.height:e,o.remove()}),{lineHeight:e,charWidth:i,textHeight:s}}computeBlockGapDeco(){let t=[],e=this.view.viewState;for(let i=0,s=0;;s++){let o=s==e.viewports.length?null:e.viewports[s],n=o?o.from-1:this.view.state.doc.length;if(n>i){let s=(e.lineBlockAt(n).bottom-e.lineBlockAt(i).top)/this.view.scaleY;t.push(tt.replace({widget:new oi(s),block:!0,inclusive:!0,isBlockGap:!0}).range(i,n))}if(!o)break;i=o.to+1}return tt.set(t)}updateDeco(){let t=1,e=this.view.state.facet(we).map(e=>(this.dynamicDecorationMap[t++]="function"==typeof e)?e(this.view):e),i=!1,o=this.view.state.facet(ye).map((t,e)=>{let s="function"==typeof t;return s&&(i=!0),s?t(this.view):t});for(o.length&&(this.dynamicDecorationMap[t++]=i,e.push(s.join(o))),this.decorations=[this.editContextFormatting,...e,this.computeBlockGapDeco(),this.view.viewState.lineGapDeco];t<this.decorations.length;)this.dynamicDecorationMap[t++]=!1;this.blockWrappers=this.view.state.facet(be).map(t=>"function"==typeof t?t(this.view):t)}scrollIntoView(t){if(t.isSnapshot){let e=this.view.viewState.lineBlockAt(t.range.head);return this.view.scrollDOM.scrollTop=e.top-t.yMargin,void(this.view.scrollDOM.scrollLeft=t.xMargin)}for(let e of this.view.state.facet(re))try{if(e(this.view,t.range,t))return!0}catch(t){ce(this.view.state,t,"scroll handler")}let e,{range:i}=t,s=this.coordsAt(i.head,i.empty?i.assoc:i.head>i.anchor?-1:1);if(!s)return;!i.empty&&(e=this.coordsAt(i.anchor,i.anchor>i.head?-1:1))&&(s={left:Math.min(s.left,e.left),top:Math.min(s.top,e.top),right:Math.max(s.right,e.right),bottom:Math.max(s.bottom,e.bottom)});let o=ke(this.view),n={left:s.left-o.left,top:s.top-o.top,right:s.right+o.right,bottom:s.bottom+o.bottom},{offsetWidth:r,offsetHeight:l}=this.view.scrollDOM;!function(t,e,i,s,o,n,r,l){let a=t.ownerDocument,h=a.defaultView||window;for(let c=t,d=!1;c&&!d;)if(1==c.nodeType){let t,u=c==a.body,f=1,p=1;if(u)t=vt(h);else{if(/^(fixed|sticky)$/.test(getComputedStyle(c).position)&&(d=!0),c.scrollHeight<=c.clientHeight&&c.scrollWidth<=c.clientWidth){c=c.assignedSlot||c.parentNode;continue}let e=c.getBoundingClientRect();({scaleX:f,scaleY:p}=wt(c,e)),t={left:e.left,right:e.left+c.clientWidth*f,top:e.top,bottom:e.top+c.clientHeight*p}}let g=0,m=0;if("nearest"==o)e.top<t.top?(m=e.top-(t.top+r),i>0&&e.bottom>t.bottom+m&&(m=e.bottom-t.bottom+r)):e.bottom>t.bottom&&(m=e.bottom-t.bottom+r,i<0&&e.top-m<t.top&&(m=e.top-(t.top+r)));else{let s=e.bottom-e.top,n=t.bottom-t.top;m=("center"==o&&s<=n?e.top+s/2-n/2:"start"==o||"center"==o&&i<0?e.top-r:e.bottom-n+r)-t.top}if("nearest"==s?e.left<t.left?(g=e.left-(t.left+n),i>0&&e.right>t.right+g&&(g=e.right-t.right+n)):e.right>t.right&&(g=e.right-t.right+n,i<0&&e.left<t.left+g&&(g=e.left-(t.left+n))):g=("center"==s?e.left+(e.right-e.left)/2-(t.right-t.left)/2:"start"==s==l?e.left-n:e.right-(t.right-t.left)+n)-t.left,g||m)if(u)h.scrollBy(g,m);else{let t=0,i=0;if(m){let t=c.scrollTop;c.scrollTop+=m/p,i=(c.scrollTop-t)*p}if(g){let e=c.scrollLeft;c.scrollLeft+=g/f,t=(c.scrollLeft-e)*f}e={left:e.left-t,top:e.top-i,right:e.right-t,bottom:e.bottom-i},t&&Math.abs(t-g)<1&&(s="nearest"),i&&Math.abs(i-m)<1&&(o="nearest")}if(u)break;(e.top<t.top||e.bottom>t.bottom||e.left<t.left||e.right>t.right)&&(e={left:Math.max(e.left,t.left),right:Math.min(e.right,t.right),top:Math.max(e.top,t.top),bottom:Math.min(e.bottom,t.bottom)}),c=c.assignedSlot||c.parentNode}else{if(11!=c.nodeType)break;c=c.host}}(this.view.scrollDOM,n,i.head<i.anchor?-1:1,t.x,t.y,Math.max(Math.min(t.xMargin,r),-r),Math.max(Math.min(t.yMargin,l),-l),this.view.textDirection==Ot.LTR)}lineHasWidget(t){let e=t=>t.isWidget()||t.children.some(e);return e(this.tile.resolveBlock(t,1).tile)}destroy(){ti(this.tile)}}function ti(t,e){let i=null==e?void 0:e.get(t);if(1!=i){null==i&&t.destroy();for(let i of t.children)ti(i,e)}}function ei(t,e){let i=t.observer.selectionRange;if(!i.focusNode)return null;let s=At(i.focusNode,i.focusOffset),o=Tt(i.focusNode,i.focusOffset),n=s||o;if(o&&s&&o.node!=s.node){let e=Le.get(o.node);if(!e||e.isText()&&e.text!=o.node.nodeValue)n=o;else if(t.docView.lastCompositionAfterCursor){let t=Le.get(s.node);!t||t.isText()&&t.text!=s.node.nodeValue||(n=o)}}if(t.docView.lastCompositionAfterCursor=n!=s,!n)return null;let r=e-n.offset;return{from:r,to:r+n.node.nodeValue.length,node:n.node}}let ii=class{constructor(){this.changes=[]}compareRange(t,e){nt(t,e,this.changes)}comparePoint(t,e){nt(t,e,this.changes)}boundChange(t){nt(t,t,this.changes)}};class si{constructor(){this.changes=[]}compareRange(t,e){nt(t,e,this.changes)}comparePoint(){}boundChange(t){nt(t,t,this.changes)}}class oi extends J{constructor(t){super(),this.height=t}toDOM(){let t=document.createElement("div");return t.className="cm-gap",this.updateDOM(t),t}eq(t){return t.height==this.height}updateDOM(t){return t.style.height=this.height+"px",!0}get editable(){return!0}get estimatedHeight(){return this.height}ignoreEvent(){return!1}}function ni(t,e,i){let s=t.lineBlockAt(e);if(Array.isArray(s.type)){let t;for(let o of s.type){if(o.from>e)break;if(!(o.to<e)){if(o.from<e&&o.to>e)return o;t&&(o.type!=Z.Text||t.type==o.type&&!(i<0?o.from<e:o.to>e))||(t=o)}}return t||s}return s}function ri(t,e,i,s){let o=t.state.doc.lineAt(e.head),n=t.bidiSpans(o),r=t.textDirectionAt(o.from);for(let l=e,a=null;;){let e=Xt(o,n,r,l,i),h=jt;if(!e){if(o.number==(i?t.state.doc.lines:1))return l;h="\n",o=t.state.doc.line(o.number+(i?1:-1)),n=t.bidiSpans(o),e=t.visualLineSide(o,!i)}if(a){if(!a(h))return l}else{if(!s)return e;a=s(h)}l=e}}function li(t,e,i){for(;;){let s=0;for(let o of t)o.between(e-1,e+1,(t,o,n)=>{if(e>t&&e<o){let n=s||i||(e-t<o-e?-1:1);e=n<0?t:o,s=n}});if(!s)return e}}function ai(t,e){let i=null;for(let s=0;s<e.ranges.length;s++){let o=e.ranges[s],n=null;if(o.empty){let e=li(t,o.from,0);e!=o.from&&(n=l.cursor(e,-1))}else{let e=li(t,o.from,-1),i=li(t,o.to,1);e==o.from&&i==o.to||(n=l.range(o.from==o.anchor?e:i,o.from==o.head?e:i))}n&&(i||(i=e.ranges.slice()),i[s]=n)}return i?l.create(i,e.mainIndex):e}function hi(t,e,i){let s=li(t.state.facet(xe).map(e=>e(t)),i.from,e.head>i.from?-1:1);return s==i.from?i:l.cursor(s,s<i.from?1:-1)}class ci{constructor(t,e){this.pos=t,this.assoc=e}}function di(t,e,i,s){let o,n=t.contentDOM.getBoundingClientRect(),r=n.top+t.viewState.paddingTop,{x:l,y:a}=e,h=a-r;for(;;){if(h<0)return new ci(0,1);if(h>t.viewState.docHeight)return new ci(t.state.doc.length,-1);if(o=t.elementAtHeight(h),null==s)break;if(o.type==Z.Text){let e=t.docView.coordsAt(s<0?o.from:o.to,s);if(e&&(s<0?e.top<=h+r:e.bottom>=h+r))break}let e=t.viewState.heightOracle.textHeight/2;h=s>0?o.bottom+e:o.top-e}if(t.viewport.from>=o.to||t.viewport.to<=o.from){if(i)return null;if(o.type==Z.Text){let e=function(t,e,i,s,o){let n=Math.round((s-e.left)*t.defaultCharacterWidth);if(t.lineWrapping&&i.height>1.5*t.defaultLineHeight){let e=t.viewState.heightOracle.textHeight;n+=Math.floor((o-i.top-.5*(t.defaultLineHeight-e))/e)*t.viewState.heightOracle.lineLength}let r=t.state.sliceDoc(i.from,i.to);return i.from+b(r,n,t.state.tabSize)}(t,n,o,l,a);return new ci(e,e==o.from?1:-1)}}if(o.type!=Z.Text)return h<(o.top+o.bottom)/2?new ci(o.from,1):new ci(o.to,-1);let c=t.docView.lineAt(o.from,2);return c&&c.length==o.length||(c=t.docView.lineAt(o.from,-2)),ui(t,c,o.from,l,a)}function ui(t,e,i,s,o){let n=-1,r=null,l=1e9,a=1e9,h=o,c=o,u=(t,e)=>{for(let i=0;i<t.length;i++){let d=t[i];if(d.top==d.bottom)continue;let u=d.left>s?d.left-s:d.right<s?s-d.right:0,f=d.top>o?d.top-o:d.bottom<o?o-d.bottom:0;d.top<=c&&d.bottom>=h&&(h=Math.min(d.top,h),c=Math.max(d.bottom,c),f=0),(n<0||(f-a||u-l)<0)&&(n>=0&&a&&l<u&&r.top<=c-2&&r.bottom>=h+2?a=0:(n=e,l=u,a=f,r=d))}};if(e.isText()){for(let t=0;t<e.length;){let i=d(e.text,t);if(u(Ct(e.dom,t,i).getClientRects(),t),!l&&!a)break;t=i}return s>(r.left+r.right)/2==(fi(t,n+i)==Ot.LTR)?new ci(i+d(e.text,n),-1):new ci(i+n,1)}{if(!e.length)return new ci(i,1);for(let t=0;t<e.children.length;t++){let i=e.children[t];if(!(48&i.flags)&&(u((1==i.dom.nodeType?i.dom:Ct(i.dom,0,i.length)).getClientRects(),t),!l&&!a))break}let h=e.children[n],c=e.posBefore(h,i);return h.isComposite()||h.isText()?ui(t,h,c,Math.max(r.left,Math.min(r.right,s)),o):s>(r.left+r.right)/2==(fi(t,n+i)==Ot.LTR)?new ci(c+h.length,-1):new ci(c,1)}}function fi(t,e){let i=t.state.doc.lineAt(e);return t.bidiSpans(i)[Ft.find(t.bidiSpans(i),e-i.from,-1,1)].dir}const pi="￿";class gi{constructor(t,e){this.points=t,this.view=e,this.text="",this.lineSeparator=e.state.facet(o.lineSeparator)}append(t){this.text+=t}lineBreak(){this.text+=pi}readRange(t,e){if(!t)return this;let i=t.parentNode;for(let s=t;;){this.findPointBefore(i,s);let t=this.text.length;this.readNode(s);let o=Le.get(s),n=s.nextSibling;if(n==e){(null==o?void 0:o.breakAfter)&&!n&&i!=this.view.contentDOM&&this.lineBreak();break}let r=Le.get(n);(o&&r?o.breakAfter:(o?o.breakAfter:ft(s))||ft(n)&&("BR"!=s.nodeName||(null==o?void 0:o.isWidget()))&&this.text.length>t)&&!vi(n,e)&&this.lineBreak(),s=n}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 o,n=-1,r=1;if(this.lineSeparator?(n=e.indexOf(this.lineSeparator,i),r=this.lineSeparator.length):(o=s.exec(e))&&(n=o.index,r=o[0].length),this.append(e.slice(i,n<0?e.length:n)),n<0)break;if(this.lineBreak(),r>1)for(let e of this.points)e.node==t&&e.pos>this.text.length&&(e.pos-=r-1);i=n+r}}readNode(t){let e=Le.get(t),i=e&&e.overrideDOMText;if(null!=i){this.findPointInside(t,i.length);for(let t=i.iter();!t.next().done;)t.lineBreak?this.lineBreak():this.append(t.value)}else 3==t.nodeType?this.readTextNode(t):"BR"==t.nodeName?t.nextSibling&&this.lineBreak():1==t.nodeType&&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)(3==t.nodeType?i.node==t:t.contains(i.node))&&(i.pos=this.text.length+(mi(t,i.node,i.offset)?e:0))}}function mi(t,e,i){for(;;){if(!e||i<gt(e))return!1;if(e==t)return!0;i=ut(e)+1,e=e.parentNode}}function vi(t,e){let i;for(;t!=e&&t;t=t.nextSibling){let e=Le.get(t);if(!(null==e?void 0:e.isWidget()))return!1;e&&(i||(i=[])).push(e)}if(i)for(let t of i){let e=t.overrideDOMText;if(null==e?void 0:e.length)return!1}return!0}class wi{constructor(t,e){this.node=t,this.offset=e,this.pos=-1}}class bi{constructor(t,e,i,s){this.typeOver=s,this.bounds=null,this.text="",this.domChanged=e>-1;let{impreciseHead:o,impreciseAnchor:n}=t.docView;if(t.state.readOnly&&e>-1)this.newSel=null;else if(e>-1&&(this.bounds=yi(t.docView.tile,e,i,0))){let e=o||n?[]:function(t){let e=[];if(t.root.activeElement!=t.contentDOM)return e;let{anchorNode:i,anchorOffset:s,focusNode:o,focusOffset:n}=t.observer.selectionRange;i&&(e.push(new wi(i,s)),o==i&&n==s||e.push(new wi(o,n)));return e}(t),i=new gi(e,t);i.readRange(this.bounds.startDOM,this.bounds.endDOM),this.text=i.text,this.newSel=function(t,e){if(0==t.length)return null;let i=t[0].pos,s=2==t.length?t[1].pos:i;return i>-1&&s>-1?l.single(i+e,s+e):null}(e,this.bounds.from)}else{let e=t.observer.selectionRange,i=o&&o.node==e.focusNode&&o.offset==e.focusOffset||!at(t.contentDOM,e.focusNode)?t.state.selection.main.head:t.docView.posFromDOM(e.focusNode,e.focusOffset),s=n&&n.node==e.anchorNode&&n.offset==e.anchorOffset||!at(t.contentDOM,e.anchorNode)?t.state.selection.main.anchor:t.docView.posFromDOM(e.anchorNode,e.anchorOffset),r=t.viewport;if((j.ios||j.chrome)&&t.state.selection.main.empty&&i!=s&&(r.from>0||r.to<t.state.doc.length)){let e=Math.min(i,s),o=Math.max(i,s),n=r.from-e,l=r.to-o;0!=n&&1!=n&&0!=e||0!=l&&-1!=l&&o!=t.state.doc.length||(i=0,s=t.state.doc.length)}t.inputState.composing>-1&&t.state.selection.ranges.length>1?this.newSel=t.state.selection.replaceRange(l.range(s,i)):this.newSel=l.single(s,i)}}}function yi(t,e,i,s){if(t.isComposite()){let o=-1,n=-1,r=-1,l=-1;for(let a=0,h=s,c=s;a<t.children.length;a++){let s=t.children[a],d=h+s.length;if(h<e&&d>i)return yi(s,e,i,h);if(d>=e&&-1==o&&(o=a,n=h),h>i&&s.dom.parentNode==t.dom){r=a,l=c;break}c=d,h=d+s.breakAfter}return{from:n,to:l<0?s+t.length:l,startDOM:(o?t.children[o-1].dom.nextSibling:null)||t.dom.firstChild,endDOM:r<t.children.length&&r>=0?t.children[r].dom:null}}return t.isText()?{from:s,to:s+t.length,startDOM:t.dom,endDOM:t.dom.nextSibling}:null}function xi(t,e){let i,{newSel:s}=e,o=t.state.selection.main,n=t.inputState.lastKeyTime>Date.now()-100?t.inputState.lastKeyCode:-1;if(e.bounds){let{from:s,to:r}=e.bounds,l=o.from,a=null;(8===n||j.android&&e.text.length<r-s)&&(l=o.to,a="end");let h=Ci(t.state.doc.sliceString(s,r,pi),e.text,l-s,a);h&&(j.chrome&&13==n&&h.toB==h.from+2&&e.text.slice(h.from,h.toB)==pi+pi&&h.toB--,i={from:s+h.from,to:s+h.toA,insert:u.of(e.text.slice(h.from,h.toB).split(pi))})}else s&&(!t.hasFocus&&t.state.facet(de)||Mi(s,o))&&(s=null);if(!i&&!s)return!1;if(!i&&e.typeOver&&!o.empty&&s&&s.main.empty?i={from:o.from,to:o.to,insert:t.state.doc.slice(o.from,o.to)}:(j.mac||j.android)&&i&&i.from==i.to&&i.from==o.head-1&&/^\. ?$/.test(i.insert.toString())&&"off"==t.contentDOM.getAttribute("autocorrect")?(s&&2==i.insert.length&&(s=l.single(s.main.anchor-1,s.main.head-1)),i={from:i.from,to:i.to,insert:u.of([i.insert.toString().replace("."," ")])}):i&&i.from>=o.from&&i.to<=o.to&&(i.from!=o.from||i.to!=o.to)&&o.to-o.from-(i.to-i.from)<=4?i={from:o.from,to:o.to,insert:t.state.doc.slice(o.from,i.from).append(i.insert).append(t.state.doc.slice(i.to,o.to))}:t.state.doc.lineAt(o.from).to<o.to&&t.docView.lineHasWidget(o.to)&&t.inputState.insertingTextAt>Date.now()-50?i={from:o.from,to:o.to,insert:t.state.toText(t.inputState.insertingText)}:j.chrome&&i&&i.from==i.to&&i.from==o.head&&"\n "==i.insert.toString()&&t.lineWrapping&&(s&&(s=l.single(s.main.anchor-1,s.main.head-1)),i={from:o.from,to:o.to,insert:u.of([" "])}),i)return Si(t,i,s,n);if(s&&!Mi(s,o)){let e=!1,i="select";return t.inputState.lastSelectionTime>Date.now()-50&&("select"==t.inputState.lastSelectionOrigin&&(e=!0),i=t.inputState.lastSelectionOrigin,"select.pointer"==i&&(s=ai(t.state.facet(xe).map(e=>e(t)),s))),t.dispatch({selection:s,scrollIntoView:e,userEvent:i}),!0}return!1}function Si(t,e,i,s=-1){if(j.ios&&t.inputState.flushIOSKey(e))return!0;let o=t.state.selection.main;if(j.android&&(e.to==o.to&&(e.from==o.from||e.from==o.from-1&&" "==t.state.sliceDoc(e.from,o.from))&&1==e.insert.length&&2==e.insert.lines&&Mt(t.contentDOM,"Enter",13)||(e.from==o.from-1&&e.to==o.to&&0==e.insert.length||8==s&&e.insert.length<e.to-e.from&&e.to>o.head)&&Mt(t.contentDOM,"Backspace",8)||e.from==o.from&&e.to==o.to+1&&0==e.insert.length&&Mt(t.contentDOM,"Delete",46)))return!0;let n,r=e.insert.toString();t.inputState.composing>=0&&t.inputState.composing++;let a=()=>n||(n=function(t,e,i){let s,o=t.state,n=o.selection.main,r=-1;if(e.from==e.to&&e.from<n.from||e.from>n.to){let i=e.from<n.from?-1:1,s=i<0?n.from:n.to,l=li(o.facet(xe).map(e=>e(t)),s,i);e.from==l&&(r=l)}if(r>-1)s={changes:e,selection:l.cursor(e.from+e.insert.length,-1)};else if(e.from>=n.from&&e.to<=n.to&&e.to-e.from>=(n.to-n.from)/3&&(!i||i.main.empty&&i.main.from==e.from+e.insert.length)&&t.inputState.composing<0){let i=n.from<e.from?o.sliceDoc(n.from,e.from):"",r=n.to>e.to?o.sliceDoc(e.to,n.to):"";s=o.replaceSelection(t.state.toText(i+e.insert.sliceString(0,void 0,t.state.lineBreak)+r))}else{let r=o.changes(e),a=i&&i.main.to<=r.newLength?i.main:void 0;if(o.selection.ranges.length>1&&(t.inputState.composing>=0||t.inputState.compositionPendingChange)&&e.to<=n.to+10&&e.to>=n.to-10){let h,c=t.state.sliceDoc(e.from,e.to),d=i&&ei(t,i.main.head);if(d){let t=e.insert.length-(e.to-e.from);h={from:d.from,to:d.to-t}}else h=t.state.doc.lineAt(n.head);let u=n.to-e.to;s=o.changeByRange(i=>{if(i.from==n.from&&i.to==n.to)return{changes:r,range:a||i.map(r)};let s=i.to-u,d=s-c.length;if(t.state.sliceDoc(d,s)!=c||s>=h.from&&d<=h.to)return{range:i};let f=o.changes({from:d,to:s,insert:e.insert}),p=i.to-n.to;return{changes:f,range:a?l.range(Math.max(0,a.anchor+p),Math.max(0,a.head+p)):i.map(f)}})}else s={changes:r,selection:a&&o.selection.replaceRange(a)}}let a="input.type";(t.composing||t.inputState.compositionPendingChange&&t.inputState.compositionEndedAt>Date.now()-50)&&(t.inputState.compositionPendingChange=!1,a+=".compose",t.inputState.compositionFirstChange&&(a+=".start",t.inputState.compositionFirstChange=!1));return o.update(s,{userEvent:a,scrollIntoView:!0})}(t,e,i));return t.state.facet(te).some(i=>i(t,e.from,e.to,r,a))||t.dispatch(a()),!0}function Ci(t,e,i,s){let o=Math.min(t.length,e.length),n=0;for(;n<o&&t.charCodeAt(n)==e.charCodeAt(n);)n++;if(n==o&&t.length==e.length)return null;let r=t.length,l=e.length;for(;r>0&&l>0&&t.charCodeAt(r-1)==e.charCodeAt(l-1);)r--,l--;if("end"==s){i-=r+Math.max(0,n-Math.min(r,l))-n}if(r<n&&t.length<e.length){n-=i<=n&&i>=r?n-i:0,l=n+(l-r),r=n}else if(l<n){n-=i<=n&&i>=l?n-i:0,r=n+(r-l),l=n}return{from:n,toA:r,toB:l}}function Mi(t,e){return e.head==t.main.head&&e.anchor==t.main.anchor}class ki{setSelectionOrigin(t){this.lastSelectionOrigin=t,this.lastSelectionTime=Date.now()}constructor(t){this.view=t,this.lastKeyCode=0,this.lastKeyTime=0,this.lastTouchTime=0,this.lastFocusTime=0,this.lastScrollTop=0,this.lastScrollLeft=0,this.pendingIOSKey=void 0,this.tabFocusMode=-1,this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastContextMenu=0,this.scrollHandlers=[],this.handlers=Object.create(null),this.composing=-1,this.compositionFirstChange=null,this.compositionEndedAt=0,this.compositionPendingKey=!1,this.compositionPendingChange=!1,this.insertingText="",this.insertingTextAt=0,this.mouseSelection=null,this.draggedContent=null,this.handleEvent=this.handleEvent.bind(this),this.notifiedFocused=t.hasFocus,j.safari&&t.contentDOM.addEventListener("input",()=>null),j.gecko&&function(t){Ui.has(t)||(Ui.add(t),t.addEventListener("copy",()=>{}),t.addEventListener("cut",()=>{}))}(t.contentDOM.ownerDocument)}handleEvent(t){(function(t,e){if(!e.bubbles)return!0;if(e.defaultPrevented)return!1;for(let i,s=e.target;s!=t.contentDOM;s=s.parentNode)if(!s||11==s.nodeType||(i=Le.get(s))&&i.isWidget()&&!i.isHidden&&i.widget.ignoreEvent(e))return!1;return!0})(this.view,t)&&!this.ignoreDuringComposition(t)&&("keydown"==t.type&&this.keydown(t)||(0!=this.view.updateState?Promise.resolve().then(()=>this.runHandlers(t.type,t)):this.runHandlers(t.type,t)))}runHandlers(t,e){let i=this.handlers[t];if(i){for(let t of i.observers)t(this.view,e);for(let t of i.handlers){if(e.defaultPrevented)break;if(t(this.view,e)){e.preventDefault();break}}}}ensureHandlers(t){let e=Ti(t),i=this.handlers,s=this.view.contentDOM;for(let t in e)if("scroll"!=t){let o=!e[t].handlers.length,n=i[t];n&&o!=!n.handlers.length&&(s.removeEventListener(t,this.handleEvent),n=null),n||s.addEventListener(t,this.handleEvent,{passive:o})}for(let t in i)"scroll"==t||e[t]||s.removeEventListener(t,this.handleEvent);this.handlers=e}keydown(t){if(this.lastKeyCode=t.keyCode,this.lastKeyTime=Date.now(),9==t.keyCode&&this.tabFocusMode>-1&&(!this.tabFocusMode||Date.now()<=this.tabFocusMode))return!0;if(this.tabFocusMode>0&&27!=t.keyCode&&Li.indexOf(t.keyCode)<0&&(this.tabFocusMode=-1),j.android&&j.chrome&&!t.synthetic&&(13==t.keyCode||8==t.keyCode))return this.view.observer.delayAndroidKey(t.key,t.keyCode),!0;let e;return!j.ios||t.synthetic||t.altKey||t.metaKey||!((e=Di.find(e=>e.keyCode==t.keyCode))&&!t.ctrlKey||Oi.indexOf(t.key)>-1&&t.ctrlKey&&!t.shiftKey)?(229!=t.keyCode&&this.view.observer.forceFlush(),!1):(this.pendingIOSKey=e||t,setTimeout(()=>this.flushIOSKey(),250),!0)}flushIOSKey(t){let e=this.pendingIOSKey;return!!e&&(!("Enter"==e.key&&t&&t.from<t.to&&/^\S+$/.test(t.insert.toString()))&&(this.pendingIOSKey=void 0,Mt(this.view.contentDOM,e.key,e.keyCode,e instanceof KeyboardEvent?e:void 0)))}ignoreDuringComposition(t){return!(!/^key/.test(t.type)||t.synthetic)&&(this.composing>0||!!(j.safari&&!j.ios&&this.compositionPendingKey&&Date.now()-this.compositionEndedAt<100)&&(this.compositionPendingKey=!1,!0))}startMouseSelection(t){this.mouseSelection&&this.mouseSelection.destroy(),this.mouseSelection=t}update(t){this.view.observer.update(t),this.mouseSelection&&this.mouseSelection.update(t),this.draggedContent&&t.docChanged&&(this.draggedContent=this.draggedContent.map(t.changes)),t.transactions.length&&(this.lastKeyCode=this.lastSelectionTime=0)}destroy(){this.mouseSelection&&this.mouseSelection.destroy()}}function Ai(t,e){return(i,s)=>{try{return e.call(t,s,i)}catch(t){ce(i.state,t)}}}function Ti(t){let e=Object.create(null);function i(t){return e[t]||(e[t]={observers:[],handlers:[]})}for(let e of t){let t=e.spec,s=t&&t.plugin.domEventHandlers,o=t&&t.plugin.domEventObservers;if(s)for(let t in s){let o=s[t];o&&i(t).handlers.push(Ai(e.value,o))}if(o)for(let t in o){let s=o[t];s&&i(t).observers.push(Ai(e.value,s))}}for(let t in Ri)i(t).handlers.push(Ri[t]);for(let t in Hi)i(t).observers.push(Hi[t]);return e}const Di=[{key:"Backspace",keyCode:8,inputType:"deleteContentBackward"},{key:"Enter",keyCode:13,inputType:"insertParagraph"},{key:"Enter",keyCode:13,inputType:"insertLineBreak"},{key:"Delete",keyCode:46,inputType:"deleteContentForward"}],Oi="dthko",Li=[16,17,18,20,91,92,224,225];function Bi(t){return.7*Math.max(0,t)+8}class Ei{constructor(t,e,i,s){this.view=t,this.startEvent=e,this.style=i,this.mustSelect=s,this.scrollSpeed={x:0,y:0},this.scrolling=-1,this.lastEvent=e,this.scrollParents=function(t){let e,i,s=t.ownerDocument;for(let o=t.parentNode;o&&!(o==s.body||e&&i);)if(1==o.nodeType)!i&&o.scrollHeight>o.clientHeight&&(i=o),!e&&o.scrollWidth>o.clientWidth&&(e=o),o=o.assignedSlot||o.parentNode;else{if(11!=o.nodeType)break;o=o.host}return{x:e,y:i}}(t.contentDOM),this.atoms=t.state.facet(xe).map(e=>e(t));let n=t.contentDOM.ownerDocument;n.addEventListener("mousemove",this.move=this.move.bind(this)),n.addEventListener("mouseup",this.up=this.up.bind(this)),this.extend=e.shiftKey,this.multiple=t.state.facet(o.allowMultipleSelections)&&function(t,e){let i=t.state.facet(Ut);return i.length?i[0](e):j.mac?e.metaKey:e.ctrlKey}(t,e),this.dragging=!(!function(t,e){let{main:i}=t.state.selection;if(i.empty)return!1;let s=lt(t.root);if(!s||0==s.rangeCount)return!0;let o=s.getRangeAt(0).getClientRects();for(let t=0;t<o.length;t++){let i=o[t];if(i.left<=e.clientX&&i.right>=e.clientX&&i.top<=e.clientY&&i.bottom>=e.clientY)return!0}return!1}(t,e)||1!=Ki(e))&&null}start(t){!1===this.dragging&&this.select(t)}move(t){if(0==t.buttons)return this.destroy();if(this.dragging||null==this.dragging&&(e=this.startEvent,i=t,Math.max(Math.abs(e.clientX-i.clientX),Math.abs(e.clientY-i.clientY))<10))return;var e,i;this.select(this.lastEvent=t);let s=0,o=0,n=0,r=0,l=this.view.win.innerWidth,a=this.view.win.innerHeight;this.scrollParents.x&&({left:n,right:l}=this.scrollParents.x.getBoundingClientRect()),this.scrollParents.y&&({top:r,bottom:a}=this.scrollParents.y.getBoundingClientRect());let h=ke(this.view);t.clientX-h.left<=n+6?s=-Bi(n-t.clientX):t.clientX+h.right>=l-6&&(s=Bi(t.clientX-l)),t.clientY-h.top<=r+6?o=-Bi(r-t.clientY):t.clientY+h.bottom>=a-6&&(o=Bi(t.clientY-a)),this.setScrollSpeed(s,o)}up(t){null==this.dragging&&this.select(this.lastEvent),this.dragging||t.preventDefault(),this.destroy()}destroy(){this.setScrollSpeed(0,0);let t=this.view.contentDOM.ownerDocument;t.removeEventListener("mousemove",this.move),t.removeEventListener("mouseup",this.up),this.view.inputState.mouseSelection=this.view.inputState.draggedContent=null}setScrollSpeed(t,e){this.scrollSpeed={x:t,y:e},t||e?this.scrolling<0&&(this.scrolling=setInterval(()=>this.scroll(),50)):this.scrolling>-1&&(clearInterval(this.scrolling),this.scrolling=-1)}scroll(){let{x:t,y:e}=this.scrollSpeed;t&&this.scrollParents.x&&(this.scrollParents.x.scrollLeft+=t,t=0),e&&this.scrollParents.y&&(this.scrollParents.y.scrollTop+=e,e=0),(t||e)&&this.view.win.scrollBy(t,e),!1===this.dragging&&this.select(this.lastEvent)}select(t){let{view:e}=this,i=ai(this.atoms,this.style.get(t,this.extend,this.multiple));!this.mustSelect&&i.eq(e.state.selection,!1===this.dragging)||this.view.dispatch({selection:i,userEvent:"select.pointer"}),this.mustSelect=!1}update(t){t.transactions.some(t=>t.isUserEvent("input.type"))?this.destroy():this.style.update(t)&&setTimeout(()=>this.select(this.lastEvent),20)}}const Ri=Object.create(null),Hi=Object.create(null),Wi=j.ie&&j.ie_version<15||j.ios&&j.webkit_version<604;function Ni(t,e,i){for(let s of t.facet(e))i=s(i,t);return i}function Pi(t,e){e=Ni(t.state,ie,e);let i,{state:s}=t,o=1,n=s.toText(e),r=n.lines==s.selection.ranges.length;if(null!=Yi&&s.selection.ranges.every(t=>t.empty)&&Yi==n.toString()){let t=-1;i=s.changeByRange(i=>{let a=s.doc.lineAt(i.from);if(a.from==t)return{range:i};t=a.from;let h=s.toText((r?n.line(o++).text:e)+s.lineBreak);return{changes:{from:a.from,insert:h},range:l.cursor(i.from+h.length)}})}else i=r?s.changeByRange(t=>{let e=n.line(o++);return{changes:{from:t.from,to:t.to,insert:e.text},range:l.cursor(t.from+e.length)}}):s.replaceSelection(n);t.dispatch(i,{userEvent:"input.paste",scrollIntoView:!0})}function Vi(t,e,i,s){if(1==s)return l.cursor(e,i);if(2==s)return function(t,e,i=1){let s=t.charCategorizer(e),o=t.doc.lineAt(e),n=e-o.from;if(0==o.length)return l.cursor(e);0==n?i=1:n==o.length&&(i=-1);let r=n,a=n;i<0?r=d(o.text,n,!1):a=d(o.text,n);let h=s(o.text.slice(r,a));for(;r>0;){let t=d(o.text,r,!1);if(s(o.text.slice(t,r))!=h)break;r=t}for(;a<o.length;){let t=d(o.text,a);if(s(o.text.slice(a,t))!=h)break;a=t}return l.range(r+o.from,a+o.from)}(t.state,e,i);{let s=t.docView.lineAt(e,i),o=t.state.doc.lineAt(s?s.posAtEnd:e),n=s?s.posAtStart:o.from,r=s?s.posAtEnd:o.to;return r<t.state.doc.length&&r==o.to&&r++,l.range(n,r)}}Hi.scroll=t=>{t.inputState.lastScrollTop=t.scrollDOM.scrollTop,t.inputState.lastScrollLeft=t.scrollDOM.scrollLeft},Ri.keydown=(t,e)=>(t.inputState.setSelectionOrigin("select"),27==e.keyCode&&0!=t.inputState.tabFocusMode&&(t.inputState.tabFocusMode=Date.now()+2e3),!1),Hi.touchstart=(t,e)=>{t.inputState.lastTouchTime=Date.now(),t.inputState.setSelectionOrigin("select.pointer")},Hi.touchmove=t=>{t.inputState.setSelectionOrigin("select.pointer")},Ri.mousedown=(t,e)=>{if(t.observer.flush(),t.inputState.lastTouchTime>Date.now()-2e3)return!1;let i=null;for(let s of t.state.facet(Qt))if(i=s(t,e),i)break;if(i||0!=e.button||(i=function(t,e){let i=t.posAndSideAtCoords({x:e.clientX,y:e.clientY},!1),s=Ki(e),o=t.state.selection;return{update(t){t.docChanged&&(i.pos=t.changes.mapPos(i.pos),o=o.map(t.changes))},get(e,n,r){let a,h=t.posAndSideAtCoords({x:e.clientX,y:e.clientY},!1),c=Vi(t,h.pos,h.assoc,s);if(i.pos!=h.pos&&!n){let e=Vi(t,i.pos,i.assoc,s),o=Math.min(e.from,c.from),n=Math.max(e.to,c.to);c=o<c.from?l.range(o,n):l.range(n,o)}return n?o.replaceRange(o.main.extend(c.from,c.to)):r&&1==s&&o.ranges.length>1&&(a=function(t,e){for(let i=0;i<t.ranges.length;i++){let{from:s,to:o}=t.ranges[i];if(s<=e&&o>=e)return l.create(t.ranges.slice(0,i).concat(t.ranges.slice(i+1)),t.mainIndex==i?0:t.mainIndex-(t.mainIndex>i?1:0))}return null}(o,h.pos))?a:r?o.addRange(c):l.create([c])}}}(t,e)),i){let s=!t.hasFocus;t.inputState.startMouseSelection(new Ei(t,e,i,s)),s&&t.observer.ignore(()=>{St(t.contentDOM);let e=t.root.activeElement;e&&!e.contains(t.contentDOM)&&e.blur()});let o=t.inputState.mouseSelection;if(o)return o.start(e),!1===o.dragging}else t.inputState.setSelectionOrigin("select.pointer");return!1};const Fi=j.ie&&j.ie_version<=11;let zi=null,Ii=0,qi=0;function Ki(t){if(!Fi)return t.detail;let e=zi,i=qi;return zi=t,qi=Date.now(),Ii=!e||i>Date.now()-400&&Math.abs(e.clientX-t.clientX)<2&&Math.abs(e.clientY-t.clientY)<2?(Ii+1)%3:1}function _i(t,e,i,s){if(!(i=Ni(t.state,ie,i)))return;let o=t.posAtCoords({x:e.clientX,y:e.clientY},!1),{draggedContent:n}=t.inputState,r=s&&n&&function(t,e){let i=t.state.facet($t);return i.length?i[0](e):j.mac?!e.altKey:!e.ctrlKey}(t,e)?{from:n.from,to:n.to}:null,l={from:o,insert:i},a=t.state.changes(r?[r,l]:l);t.focus(),t.dispatch({changes:a,selection:{anchor:a.mapPos(o,-1),head:a.mapPos(o,1)},userEvent:r?"move.drop":"input.drop"}),t.inputState.draggedContent=null}Ri.dragstart=(t,e)=>{let{selection:{main:i}}=t.state;if(e.target.draggable){let s=t.docView.tile.nearest(e.target);if(s&&s.isWidget()){let t=s.posAtStart,e=t+s.length;(t>=i.to||e<=i.from)&&(i=l.range(t,e))}}let{inputState:s}=t;return s.mouseSelection&&(s.mouseSelection.dragging=!0),s.draggedContent=i,e.dataTransfer&&(e.dataTransfer.setData("Text",Ni(t.state,se,t.state.sliceDoc(i.from,i.to))),e.dataTransfer.effectAllowed="copyMove"),!1},Ri.dragend=t=>(t.inputState.draggedContent=null,!1),Ri.drop=(t,e)=>{if(!e.dataTransfer)return!1;if(t.state.readOnly)return!0;let i=e.dataTransfer.files;if(i&&i.length){let s=Array(i.length),o=0,n=()=>{++o==i.length&&_i(t,e,s.filter(t=>null!=t).join(t.state.lineBreak),!1)};for(let t=0;t<i.length;t++){let e=new FileReader;e.onerror=n,e.onload=()=>{/[\x00-\x08\x0e-\x1f]{2}/.test(e.result)||(s[t]=e.result),n()},e.readAsText(i[t])}return!0}{let i=e.dataTransfer.getData("Text");if(i)return _i(t,e,i,!0),!0}return!1},Ri.paste=(t,e)=>{if(t.state.readOnly)return!0;t.observer.flush();let i=Wi?null:e.clipboardData;return i?(Pi(t,i.getData("text/plain")||i.getData("text/uri-list")),!0):(function(t){let e=t.dom.parentNode;if(!e)return;let i=e.appendChild(document.createElement("textarea"));i.style.cssText="position: fixed; left: -10000px; top: 10px",i.focus(),setTimeout(()=>{t.focus(),i.remove(),Pi(t,i.value)},50)}(t),!1)};let Yi=null;Ri.copy=Ri.cut=(t,e)=>{let i=lt(t.root);if(i&&!ht(t.contentDOM,i))return!1;let{text:s,ranges:o,linewise:n}=function(t){let e=[],i=[],s=!1;for(let s of t.selection.ranges)s.empty||(e.push(t.sliceDoc(s.from,s.to)),i.push(s));if(!e.length){let o=-1;for(let{from:s}of t.selection.ranges){let n=t.doc.lineAt(s);n.number>o&&(e.push(n.text),i.push({from:n.from,to:Math.min(t.doc.length,n.to+1)})),o=n.number}s=!0}return{text:Ni(t,se,e.join(t.lineBreak)),ranges:i,linewise:s}}(t.state);if(!s&&!n)return!1;Yi=n?s:null,"cut"!=e.type||t.state.readOnly||t.dispatch({changes:o,scrollIntoView:!0,userEvent:"delete.cut"});let r=Wi?null:e.clipboardData;return r?(r.clearData(),r.setData("text/plain",s),!0):(function(t,e){let i=t.dom.parentNode;if(!i)return;let s=i.appendChild(document.createElement("textarea"));s.style.cssText="position: fixed; left: -10000px; top: 10px",s.value=e,s.focus(),s.selectionEnd=e.length,s.selectionStart=0,setTimeout(()=>{s.remove(),t.focus()},50)}(t,s),!1)};const ji=r.define();function Xi(t,e){let i=[];for(let s of t.facet(ee)){let o=s(t,e);o&&i.push(o)}return i.length?t.update({effects:i,annotations:ji.of(!0)}):null}function Gi(t){setTimeout(()=>{let e=t.hasFocus;if(e!=t.inputState.notifiedFocused){let i=Xi(t.state,e);i?t.dispatch(i):t.update([])}},10)}Hi.focus=t=>{t.inputState.lastFocusTime=Date.now(),t.scrollDOM.scrollTop||!t.inputState.lastScrollTop&&!t.inputState.lastScrollLeft||(t.scrollDOM.scrollTop=t.inputState.lastScrollTop,t.scrollDOM.scrollLeft=t.inputState.lastScrollLeft),Gi(t)},Hi.blur=t=>{t.observer.clearSelectionRange(),Gi(t)},Hi.compositionstart=Hi.compositionupdate=t=>{t.observer.editContext||(null==t.inputState.compositionFirstChange&&(t.inputState.compositionFirstChange=!0),t.inputState.composing<0&&(t.inputState.composing=0))},Hi.compositionend=t=>{t.observer.editContext||(t.inputState.composing=-1,t.inputState.compositionEndedAt=Date.now(),t.inputState.compositionPendingKey=!0,t.inputState.compositionPendingChange=t.observer.pendingRecords().length>0,t.inputState.compositionFirstChange=null,j.chrome&&j.android?t.observer.flushSoon():t.inputState.compositionPendingChange?Promise.resolve().then(()=>t.observer.flush()):setTimeout(()=>{t.inputState.composing<0&&t.docView.hasComposition&&t.update([])},50))},Hi.contextmenu=t=>{t.inputState.lastContextMenu=Date.now()},Ri.beforeinput=(t,e)=>{var i,s;if("insertText"!=e.inputType&&"insertCompositionText"!=e.inputType||(t.inputState.insertingText=e.data,t.inputState.insertingTextAt=Date.now()),"insertReplacementText"==e.inputType&&t.observer.editContext){let s=null===(i=e.dataTransfer)||void 0===i?void 0:i.getData("text/plain"),o=e.getTargetRanges();if(s&&o.length){let e=o[0],i=t.posAtDOM(e.startContainer,e.startOffset),n=t.posAtDOM(e.endContainer,e.endOffset);return Si(t,{from:i,to:n,insert:t.state.toText(s)},null),!0}}let o;if(j.chrome&&j.android&&(o=Di.find(t=>t.inputType==e.inputType))&&(t.observer.delayAndroidKey(o.key,o.keyCode),"Backspace"==o.key||"Delete"==o.key)){let e=(null===(s=window.visualViewport)||void 0===s?void 0:s.height)||0;setTimeout(()=>{var i;((null===(i=window.visualViewport)||void 0===i?void 0:i.height)||0)>e+10&&t.hasFocus&&(t.contentDOM.blur(),t.focus())},100)}return j.ios&&"deleteContentForward"==e.inputType&&t.observer.flushSoon(),j.safari&&"insertText"==e.inputType&&t.inputState.composing>=0&&setTimeout(()=>Hi.compositionend(t,e),20),!1};const Ui=new Set;const $i=["pre-wrap","normal","pre-line","break-spaces"];let Qi=!1;function Ji(){Qi=!1}class Zi{constructor(t){this.lineWrapping=t,this.doc=u.empty,this.heightSamples={},this.lineHeight=14,this.charWidth=7,this.textHeight=14,this.lineLength=30}heightForGap(t,e){let i=this.doc.lineAt(e).number-this.doc.lineAt(t).number+1;return this.lineWrapping&&(i+=Math.max(0,Math.ceil((e-t-i*this.lineLength*.5)/this.lineLength))),this.lineHeight*i}heightForLine(t){if(!this.lineWrapping)return this.lineHeight;return(1+Math.max(0,Math.ceil((t-this.lineLength)/Math.max(1,this.lineLength-5))))*this.lineHeight}setDoc(t){return this.doc=t,this}mustRefreshForWrapping(t){return $i.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(10*s)]||(e=!0,this.heightSamples[Math.floor(10*s)]=!0)}return e}refresh(t,e,i,s,o,n){let r=$i.indexOf(t)>-1,l=Math.abs(e-this.lineHeight)>.3||this.lineWrapping!=r||Math.abs(i-this.charWidth)>.1;if(this.lineWrapping=r,this.lineHeight=e,this.charWidth=i,this.textHeight=s,this.lineLength=o,l){this.heightSamples={};for(let t=0;t<n.length;t++){let e=n[t];e<0?t++:this.heightSamples[Math.floor(10*e)]=!0}}return l}}class ts{constructor(t,e){this.from=t,this.heights=e,this.index=0}get more(){return this.index<this.heights.length}}class es{constructor(t,e,i,s,o){this.from=t,this.length=e,this.top=i,this.height=s,this._content=o}get type(){return"number"==typeof this._content?Z.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 st?this._content.widget:null}get widgetLineBreaks(){return"number"==typeof this._content?this._content:0}join(t){let e=(Array.isArray(this._content)?this._content:[this]).concat(Array.isArray(t._content)?t._content:[t]);return new es(this.from,this.length+t.length,this.top,this.height+t.height,e)}}var is=function(t){return t[t.ByPos=0]="ByPos",t[t.ByHeight=1]="ByHeight",t[t.ByPosNoHeight=2]="ByPosNoHeight",t}(is||(is={}));const ss=.001;class os{constructor(t,e,i=2){this.length=t,this.height=e,this.flags=i}get outdated(){return(2&this.flags)>0}set outdated(t){this.flags=(t?2:0)|-3&this.flags}setHeight(t){this.height!=t&&(Math.abs(this.height-t)>ss&&(Qi=!0),this.height=t)}replace(t,e,i){return os.of(i)}decomposeLeft(t,e){e.push(this)}decomposeRight(t,e){e.push(this)}applyChanges(t,e,i,s){let o=this,n=i.doc;for(let r=s.length-1;r>=0;r--){let{fromA:l,toA:a,fromB:h,toB:c}=s[r],d=o.lineAt(l,is.ByPosNoHeight,i.setDoc(e),0,0),u=d.to>=a?d:o.lineAt(a,is.ByPosNoHeight,i,0,0);for(c+=u.to-a,a=u.to;r>0&&d.from<=s[r-1].toA;)l=s[r-1].fromA,h=s[r-1].fromB,r--,l<d.from&&(d=o.lineAt(l,is.ByPosNoHeight,i,0,0));h+=d.from-l,l=d.from;let f=us.build(i.setDoc(n),t,h,c);o=ns(o,o.replace(l,a,f))}return o.updateHeight(i,0)}static empty(){return new as(0,0,0)}static of(t){if(1==t.length)return t[0];let e=0,i=t.length,s=0,o=0;for(;;)if(e==i)if(s>2*o){let o=t[e-1];o.break?t.splice(--e,1,o.left,null,o.right):t.splice(--e,1,o.left,o.right),i+=1+o.break,s-=o.size}else{if(!(o>2*s))break;{let e=t[i];e.break?t.splice(i,1,e.left,null,e.right):t.splice(i,1,e.left,e.right),i+=2+e.break,o-=e.size}}else if(s<o){let i=t[e++];i&&(s+=i.size)}else{let e=t[--i];e&&(o+=e.size)}let n=0;return null==t[e-1]?(n=1,e--):null==t[e]&&(n=1,i++),new cs(os.of(t.slice(0,e)),n,os.of(t.slice(i)))}}function ns(t,e){return t==e?t:(t.constructor!=e.constructor&&(Qi=!0),e)}os.prototype.size=1;const rs=tt.replace({});class ls extends os{constructor(t,e,i){super(t,e),this.deco=i,this.spaceAbove=0}mainBlock(t,e){return new es(e,this.length,t+this.spaceAbove,this.height-this.spaceAbove,this.deco||0)}blockAt(t,e,i,s){return this.spaceAbove&&t<i+this.spaceAbove?new es(s,0,i,this.spaceAbove,rs):this.mainBlock(i,s)}lineAt(t,e,i,s,o){let n=this.mainBlock(s,o);return this.spaceAbove?this.blockAt(0,i,s,o).join(n):n}forEachLine(t,e,i,s,o,n){t<=o+this.length&&e>=o&&n(this.lineAt(0,is.ByPos,i,s,o))}setMeasuredHeight(t){let e=t.heights[t.index++];e<0?(this.spaceAbove=-e,e=t.heights[t.index++]):this.spaceAbove=0,this.setHeight(e)}updateHeight(t,e=0,i=!1,s){return s&&s.from<=e&&s.more&&this.setMeasuredHeight(s),this.outdated=!1,this}toString(){return`block(${this.length})`}}class as extends ls{constructor(t,e,i){super(t,e,null),this.collapsed=0,this.widgetHeight=0,this.breaks=0,this.spaceAbove=i}mainBlock(t,e){return new es(e,this.length,t+this.spaceAbove,this.height-this.spaceAbove,this.breaks)}replace(t,e,i){let s=i[0];return 1==i.length&&(s instanceof as||s instanceof hs&&4&s.flags)&&Math.abs(this.length-s.length)<10?(s instanceof hs?s=new as(s.length,this.height,this.spaceAbove):s.height=this.height,this.outdated||(s.outdated=!1),s):os.of(i)}updateHeight(t,e=0,i=!1,s){return s&&s.from<=e&&s.more?this.setMeasuredHeight(s):(i||this.outdated)&&(this.spaceAbove=0,this.setHeight(Math.max(this.widgetHeight,t.heightForLine(this.length-this.collapsed))+this.breaks*t.lineHeight)),this.outdated=!1,this}toString(){return`line(${this.length}${this.collapsed?-this.collapsed:""}${this.widgetHeight?":"+this.widgetHeight:""})`}}class hs extends os{constructor(t){super(t,0)}heightMetrics(t,e){let i,s=t.doc.lineAt(e).number,o=t.doc.lineAt(e+this.length).number,n=o-s+1,r=0;if(t.lineWrapping){let e=Math.min(this.height,t.lineHeight*n);i=e/n,this.length>n+1&&(r=(this.height-e)/(this.length-n-1))}else i=this.height/n;return{firstLine:s,lastLine:o,perLine:i,perChar:r}}blockAt(t,e,i,s){let{firstLine:o,lastLine:n,perLine:r,perChar:l}=this.heightMetrics(e,s);if(e.lineWrapping){let o=s+(t<e.lineHeight?0:Math.round(Math.max(0,Math.min(1,(t-i)/this.height))*this.length)),n=e.doc.lineAt(o),a=r+n.length*l,h=Math.max(i,t-a/2);return new es(n.from,n.length,h,a,0)}{let s=Math.max(0,Math.min(n-o,Math.floor((t-i)/r))),{from:l,length:a}=e.doc.line(o+s);return new es(l,a,i+r*s,r,0)}}lineAt(t,e,i,s,o){if(e==is.ByHeight)return this.blockAt(t,i,s,o);if(e==is.ByPosNoHeight){let{from:e,to:s}=i.doc.lineAt(t);return new es(e,s-e,0,0,0)}let{firstLine:n,perLine:r,perChar:l}=this.heightMetrics(i,o),a=i.doc.lineAt(t),h=r+a.length*l,c=a.number-n,d=s+r*c+l*(a.from-o-c);return new es(a.from,a.length,Math.max(s,Math.min(d,s+this.height-h)),h,0)}forEachLine(t,e,i,s,o,n){t=Math.max(t,o),e=Math.min(e,o+this.length);let{firstLine:r,perLine:l,perChar:a}=this.heightMetrics(i,o);for(let h=t,c=s;h<=e;){let e=i.doc.lineAt(h);if(h==t){let i=e.number-r;c+=l*i+a*(t-o-i)}let s=l+a*e.length;n(new es(e.from,e.length,c,s,0)),c+=s,h=e.to+1}}replace(t,e,i){let s=this.length-e;if(s>0){let t=i[i.length-1];t instanceof hs?i[i.length-1]=new hs(t.length+s):i.push(null,new hs(s-1))}if(t>0){let e=i[0];e instanceof hs?i[0]=new hs(t+e.length):i.unshift(new hs(t-1),null)}return os.of(i)}decomposeLeft(t,e){e.push(new hs(t-1),null)}decomposeRight(t,e){e.push(null,new hs(this.length-t-1))}updateHeight(t,e=0,i=!1,s){let o=e+this.length;if(s&&s.from<=e+this.length&&s.more){let i=[],n=Math.max(e,s.from),r=-1;for(s.from>e&&i.push(new hs(s.from-e-1).updateHeight(t,e));n<=o&&s.more;){let e=t.doc.lineAt(n).length;i.length&&i.push(null);let o=s.heights[s.index++],l=0;o<0&&(l=-o,o=s.heights[s.index++]),-1==r?r=o:Math.abs(o-r)>=ss&&(r=-2);let a=new as(e,o,l);a.outdated=!1,i.push(a),n+=e+1}n<=o&&i.push(null,new hs(o-n).updateHeight(t,n));let l=os.of(i);return(r<0||Math.abs(l.height-this.height)>=ss||Math.abs(r-this.heightMetrics(t,e).perLine)>=ss)&&(Qi=!0),ns(this,l)}return(i||this.outdated)&&(this.setHeight(t.heightForGap(e,e+this.length)),this.outdated=!1),this}toString(){return`gap(${this.length})`}}class cs extends os{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 1&this.flags}blockAt(t,e,i,s){let o=i+this.left.height;return t<o?this.left.blockAt(t,e,i,s):this.right.blockAt(t,e,o,s+this.left.length+this.break)}lineAt(t,e,i,s,o){let n=s+this.left.height,r=o+this.left.length+this.break,l=e==is.ByHeight?t<n:t<r,a=l?this.left.lineAt(t,e,i,s,o):this.right.lineAt(t,e,i,n,r);if(this.break||(l?a.to<r:a.from>r))return a;let h=e==is.ByPosNoHeight?is.ByPosNoHeight:is.ByPos;return l?a.join(this.right.lineAt(r,h,i,n,r)):this.left.lineAt(r,h,i,s,o).join(a)}forEachLine(t,e,i,s,o,n){let r=s+this.left.height,l=o+this.left.length+this.break;if(this.break)t<l&&this.left.forEachLine(t,e,i,s,o,n),e>=l&&this.right.forEachLine(t,e,i,r,l,n);else{let a=this.lineAt(l,is.ByPos,i,s,o);t<a.from&&this.left.forEachLine(t,a.from-1,i,s,o,n),a.to>=t&&a.from<=e&&n(a),e>a.to&&this.right.forEachLine(a.to+1,e,i,r,l,n)}}replace(t,e,i){let s=this.left.length+this.break;if(e<s)return this.balanced(this.left.replace(t,e,i),this.right);if(t>this.left.length)return this.balanced(this.left,this.right.replace(t-s,e-s,i));let o=[];t>0&&this.decomposeLeft(t,o);let n=o.length;for(let t of i)o.push(t);if(t>0&&ds(o,n-1),e<this.length){let t=o.length;this.decomposeRight(e,o),ds(o,t)}return os.of(o)}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?os.of(this.break?[t,null,e]:[t,e]):(this.left=ns(this.left,t),this.right=ns(this.right,e),this.setHeight(t.height+e.height),this.outdated=t.outdated||e.outdated,this.size=t.size+e.size,this.length=t.length+this.break+e.length,this)}updateHeight(t,e=0,i=!1,s){let{left:o,right:n}=this,r=e+o.length+this.break,l=null;return s&&s.from<=e+o.length&&s.more?l=o=o.updateHeight(t,e,i,s):o.updateHeight(t,e,i),s&&s.from<=r+n.length&&s.more?l=n=n.updateHeight(t,r,i,s):n.updateHeight(t,r,i),l?this.balanced(o,n):(this.height=this.left.height+this.right.height,this.outdated=!1,this)}toString(){return this.left+(this.break?" ":"-")+this.right}}function ds(t,e){let i,s;null==t[e]&&(i=t[e-1])instanceof hs&&(s=t[e+1])instanceof hs&&t.splice(e-1,3,new hs(i.length+1+s.length))}class us{constructor(t,e){this.pos=t,this.oracle=e,this.nodes=[],this.lineStart=-1,this.lineEnd=-1,this.covering=null,this.writtenTo=t}get isCovered(){return this.covering&&this.nodes[this.nodes.length-1]==this.covering}span(t,e){if(this.lineStart>-1){let t=Math.min(e,this.lineEnd),i=this.nodes[this.nodes.length-1];i instanceof as?i.length+=t-this.pos:(t>this.pos||!this.isCovered)&&this.nodes.push(new as(t-this.pos,-1,0)),this.writtenTo=t,e>t&&(this.nodes.push(null),this.writtenTo++,this.lineStart=-1)}this.pos=e}point(t,e,i){if(t<e||i.heightRelevant){let s=i.widget?i.widget.estimatedHeight:0,o=i.widget?i.widget.lineBreaks:0;s<0&&(s=this.oracle.lineHeight);let n=e-t;i.block?this.addBlock(new ls(n,s,i)):(n||o||s>=5)&&this.addLineDeco(s,o,n)}else e>t&&this.span(t,e);this.lineEnd>-1&&this.lineEnd<this.pos&&(this.lineEnd=this.oracle.doc.lineAt(this.pos).to)}enterLine(){if(this.lineStart>-1)return;let{from:t,to:e}=this.oracle.doc.lineAt(this.pos);this.lineStart=t,this.lineEnd=e,this.writtenTo<t&&((this.writtenTo<t-1||null==this.nodes[this.nodes.length-1])&&this.nodes.push(this.blankContent(this.writtenTo,t-1)),this.nodes.push(null)),this.pos>t&&this.nodes.push(new as(this.pos-t,-1,0)),this.writtenTo=this.pos}blankContent(t,e){let i=new hs(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 as)return t;let e=new as(0,-1,0);return this.nodes.push(e),e}addBlock(t){this.enterLine();let e=t.deco;e&&e.startSide>0&&!this.isCovered&&this.ensureLine(),this.nodes.push(t),this.writtenTo=this.pos=this.pos+t.length,e&&e.endSide>0&&(this.covering=t)}addLineDeco(t,e,i){let 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=0==this.nodes.length?null:this.nodes[this.nodes.length-1];!(this.lineStart>-1)||e instanceof as||this.isCovered?(this.writtenTo<this.pos||null==e)&&this.nodes.push(this.blankContent(this.writtenTo,this.pos)):this.nodes.push(new as(0,-1,0));let i=t;for(let t of this.nodes)t instanceof as&&t.updateHeight(this.oracle,i),i+=t?t.length:1;return this.nodes}static build(t,e,i,o){let n=new us(i,t);return s.spans(e,i,o,n,0),n.finish(i)}}class fs{constructor(){this.changes=[]}compareRange(){}comparePoint(t,e,i,s){(t<e||i&&i.heightRelevant||s&&s.heightRelevant)&&nt(t,e,this.changes,5)}}function ps(t,e){let i=t.getBoundingClientRect(),s=t.ownerDocument,o=s.defaultView||window,n=Math.max(0,i.left),r=Math.min(o.innerWidth,i.right),l=Math.max(0,i.top),a=Math.min(o.innerHeight,i.bottom);for(let e=t.parentNode;e&&e!=s.body;)if(1==e.nodeType){let i=e,s=window.getComputedStyle(i);if((i.scrollHeight>i.clientHeight||i.scrollWidth>i.clientWidth)&&"visible"!=s.overflow){let s=i.getBoundingClientRect();n=Math.max(n,s.left),r=Math.min(r,s.right),l=Math.max(l,s.top),a=Math.min(e==t.parentNode?o.innerHeight:a,s.bottom)}e="absolute"==s.position||"fixed"==s.position?i.offsetParent:i.parentNode}else{if(11!=e.nodeType)break;e=e.host}return{left:n-i.left,right:Math.max(n,r)-i.left,top:l-(i.top+e),bottom:Math.max(l,a)-(i.top+e)}}function gs(t,e){let i=t.getBoundingClientRect();return{left:0,right:i.right-i.left,top:e,bottom:i.bottom-(i.top+e)}}class ms{constructor(t,e,i,s){this.from=t,this.to=e,this.size=i,this.displaySize=s}static same(t,e){if(t.length!=e.length)return!1;for(let i=0;i<t.length;i++){let s=t[i],o=e[i];if(s.from!=o.from||s.to!=o.to||s.size!=o.size)return!1}return!0}draw(t,e){return tt.replace({widget:new vs(this.displaySize*(e?t.scaleY:t.scaleX),e)}).range(this.from,this.to)}}class vs extends J{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 ws{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=!1,this.scaleX=1,this.scaleY=1,this.scrollAnchorPos=0,this.scrollAnchorHeight=-1,this.scaler=Ss,this.scrollTarget=null,this.printing=!1,this.mustMeasureContent=!0,this.defaultTextDirection=Ot.LTR,this.visibleRanges=[],this.mustEnforceCursorAssoc=!1;let e=t.facet(ve).some(t=>"function"!=typeof t&&"cm-lineWrapping"==t.class);this.heightOracle=new Zi(e),this.stateDeco=Cs(t),this.heightMap=os.empty().applyChanges(this.stateDeco,u.empty,this.heightOracle.setDoc(t.doc),[new Te(0,0,0,t.doc.length)]);for(let t=0;t<2&&(this.viewport=this.getViewport(0,null),this.updateForViewport());t++);this.updateViewportLines(),this.lineGaps=this.ensureLineGaps([]),this.lineGapDeco=tt.set(this.lineGaps.map(t=>t.draw(this,!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:t,to:e})=>s>=t&&s<=e)){let{from:e,to:i}=this.lineBlockAt(s);t.push(new bs(e,i))}}return this.viewports=t.sort((t,e)=>t.from-e.from),this.updateScaler()}updateScaler(){let t=this.scaler;return this.scaler=this.heightMap.height<=7e6?Ss:new Ms(this.heightOracle,this.heightMap,this.viewports),t.eq(this.scaler)?0:2}updateViewportLines(){this.viewportLines=[],this.heightMap.forEachLine(this.viewport.from,this.viewport.to,this.heightOracle.setDoc(this.state.doc),0,0,t=>{this.viewportLines.push(ks(t,this.scaler))})}update(t,e=null){this.state=t.state;let i=this.stateDeco;this.stateDeco=Cs(this.state);let o=t.changedRanges,n=Te.extendWithRanges(o,function(t,e,i){let o=new fs;return s.compare(t,e,i,o,0),o.changes}(i,this.stateDeco,t?t.changes:c.empty(this.state.doc.length))),r=this.heightMap.height,l=this.scrolledToBottom?null:this.scrollAnchorAt(this.scrollTop);Ji(),this.heightMap=this.heightMap.applyChanges(this.stateDeco,t.startState.doc,this.heightOracle.setDoc(this.state.doc),n),(this.heightMap.height!=r||Qi)&&(t.flags|=2),l?(this.scrollAnchorPos=t.changes.mapPos(l.from,-1),this.scrollAnchorHeight=l.top):(this.scrollAnchorPos=-1,this.scrollAnchorHeight=r);let a=n.length?this.mapViewport(this.viewport,t.changes):this.viewport;(e&&(e.range.head<a.from||e.range.head>a.to)||!this.viewportIsAppropriate(a))&&(a=this.getViewport(0,e));let h=a.from!=this.viewport.from||a.to!=this.viewport.to;this.viewport=a,t.flags|=this.updateForViewport(),(h||!t.changes.empty||2&t.flags)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(this.mapLineGaps(this.lineGaps,t.changes))),t.flags|=this.computeVisibleRanges(t.changes),e&&(this.scrollTarget=e),!this.mustEnforceCursorAssoc&&(t.selectionSet||t.focusChanged)&&t.view.lineWrapping&&t.state.selection.main.empty&&t.state.selection.main.assoc&&!t.state.facet(ne)&&(this.mustEnforceCursorAssoc=!0)}measure(t){let e=t.contentDOM,i=window.getComputedStyle(e),s=this.heightOracle,o=i.whiteSpace;this.defaultTextDirection="rtl"==i.direction?Ot.RTL:Ot.LTR;let n=this.heightOracle.mustRefreshForWrapping(o)||this.mustMeasureContent,r=e.getBoundingClientRect(),l=n||this.mustMeasureContent||this.contentDOMHeight!=r.height;this.contentDOMHeight=r.height,this.mustMeasureContent=!1;let a=0,h=0;if(r.width&&r.height){let{scaleX:t,scaleY:i}=wt(e,r);(t>.005&&Math.abs(this.scaleX-t)>.005||i>.005&&Math.abs(this.scaleY-i)>.005)&&(this.scaleX=t,this.scaleY=i,a|=16,n=l=!0)}let c=(parseInt(i.paddingTop)||0)*this.scaleY,d=(parseInt(i.paddingBottom)||0)*this.scaleY;this.paddingTop==c&&this.paddingBottom==d||(this.paddingTop=c,this.paddingBottom=d,a|=18),this.editorWidth!=t.scrollDOM.clientWidth&&(s.lineWrapping&&(l=!0),this.editorWidth=t.scrollDOM.clientWidth,a|=16);let f=t.scrollDOM.scrollTop*this.scaleY;this.scrollTop!=f&&(this.scrollAnchorHeight=-1,this.scrollTop=f),this.scrolledToBottom=kt(t.scrollDOM);let p=(this.printing?gs:ps)(e,this.paddingTop),g=p.top-this.pixelViewport.top,m=p.bottom-this.pixelViewport.bottom;this.pixelViewport=p;let v=this.pixelViewport.bottom>this.pixelViewport.top&&this.pixelViewport.right>this.pixelViewport.left;if(v!=this.inView&&(this.inView=v,v&&(l=!0)),!this.inView&&!this.scrollTarget&&!function(t){let e=t.getBoundingClientRect(),i=t.ownerDocument.defaultView||window;return e.left<i.innerWidth&&e.right>0&&e.top<i.innerHeight&&e.bottom>0}(t.dom))return 0;let w=r.width;if(this.contentDOMWidth==w&&this.editorHeight==t.scrollDOM.clientHeight||(this.contentDOMWidth=r.width,this.editorHeight=t.scrollDOM.clientHeight,a|=16),l){let e=t.docView.measureVisibleLineHeights(this.viewport);if(s.mustRefreshForHeights(e)&&(n=!0),n||s.lineWrapping&&Math.abs(w-this.contentDOMWidth)>s.charWidth){let{lineHeight:i,charWidth:r,textHeight:l}=t.docView.measureTextSize();n=i>0&&s.refresh(o,i,r,l,Math.max(5,w/r),e),n&&(t.docView.minWidth=0,a|=16)}g>0&&m>0?h=Math.max(g,m):g<0&&m<0&&(h=Math.min(g,m)),Ji();for(let i of this.viewports){let o=i.from==this.viewport.from?e:t.docView.measureVisibleLineHeights(i);this.heightMap=(n?os.empty().applyChanges(this.stateDeco,u.empty,this.heightOracle,[new Te(0,0,0,t.state.doc.length)]):this.heightMap).updateHeight(s,0,n,new ts(i.from,o))}Qi&&(a|=2)}let b=!this.viewportIsAppropriate(this.viewport,h)||this.scrollTarget&&(this.scrollTarget.range.head<this.viewport.from||this.scrollTarget.range.head>this.viewport.to);return b&&(2&a&&(a|=this.updateScaler()),this.viewport=this.getViewport(h,this.scrollTarget),a|=this.updateForViewport()),(2&a||b)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(n?[]:this.lineGaps,t)),a|=this.computeVisibleRanges(),this.mustEnforceCursorAssoc&&(this.mustEnforceCursorAssoc=!1,t.docView.enforceCursorAssoc()),a}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,o=this.heightOracle,{visibleTop:n,visibleBottom:r}=this,l=new bs(s.lineAt(n-1e3*i,is.ByHeight,o,0,0).from,s.lineAt(r+1e3*(1-i),is.ByHeight,o,0,0).to);if(e){let{head:t}=e.range;if(t<l.from||t>l.to){let i,n=Math.min(this.editorHeight,this.pixelViewport.bottom-this.pixelViewport.top),r=s.lineAt(t,is.ByPos,o,0,0);i="center"==e.y?(r.top+r.bottom)/2-n/2:"start"==e.y||"nearest"==e.y&&t<l.from?r.top:r.bottom-n,l=new bs(s.lineAt(i-500,is.ByHeight,o,0,0).from,s.lineAt(i+n+500,is.ByHeight,o,0,0).to)}}return l}mapViewport(t,e){let i=e.mapPos(t.from,-1),s=e.mapPos(t.to,1);return new bs(this.heightMap.lineAt(i,is.ByPos,this.heightOracle,0,0).from,this.heightMap.lineAt(s,is.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,is.ByPos,this.heightOracle,0,0),{bottom:o}=this.heightMap.lineAt(e,is.ByPos,this.heightOracle,0,0),{visibleTop:n,visibleBottom:r}=this;return(0==t||s<=n-Math.max(10,Math.min(-i,250)))&&(e==this.state.doc.length||o>=r+Math.max(10,Math.min(i,250)))&&s>n-2e3&&o<r+2e3}mapLineGaps(t,e){if(!t.length||e.empty)return t;let i=[];for(let s of t)e.touchesRange(s.from,s.to)||i.push(new ms(e.mapPos(s.from),e.mapPos(s.to),s.size,s.displaySize));return i}ensureLineGaps(t,e){let i=this.heightOracle.lineWrapping,o=i?1e4:2e3,n=o>>1,r=o<<1;if(this.defaultTextDirection!=Ot.LTR&&!i)return[];let a=[],h=(s,o,r,c)=>{if(o-s<n)return;let d=this.state.selection.main,u=[d.from];d.empty||u.push(d.to);for(let t of u)if(t>s&&t<o)return h(s,t-10,r,c),void h(t+10,o,r,c);let f=function(t,e){for(let i of t)if(e(i))return i;return}(t,t=>t.from>=r.from&&t.to<=r.to&&Math.abs(t.from-s)<n&&Math.abs(t.to-o)<n&&!u.some(e=>t.from<e&&t.to>e));if(!f){if(o<r.to&&e&&i&&e.visibleRanges.some(t=>t.from<=o&&t.to>=o)){let t=e.moveToLineBoundary(l.cursor(o),!1,!0).head;t>s&&(o=t)}let t=this.gapSize(r,s,o,c);f=new ms(s,o,t,i||t<2e6?t:2e6)}a.push(f)},c=e=>{if(e.length<r||e.type!=Z.Text)return;let n=function(t,e,i){let o=[],n=t,r=0;s.spans(i,t,e,{span(){},point(t,e){t>n&&(o.push({from:n,to:t}),r+=t-n),n=e}},20),n<e&&(o.push({from:n,to:e}),r+=e-n);return{total:r,ranges:o}}(e.from,e.to,this.stateDeco);if(n.total<r)return;let l,a,c=this.scrollTarget?this.scrollTarget.range.head:null;if(i){let t,i,s=o/this.heightOracle.lineLength*this.heightOracle.lineHeight;if(null!=c){let o=xs(n,c),r=((this.visibleBottom-this.visibleTop)/2+s)/e.height;t=o-r,i=o+r}else t=(this.visibleTop-e.top-s)/e.height,i=(this.visibleBottom-e.top+s)/e.height;l=ys(n,t),a=ys(n,i)}else{let i=n.total*this.heightOracle.charWidth,s=o*this.heightOracle.charWidth,r=0;if(i>2e6)for(let i of t)i.from>=e.from&&i.from<e.to&&i.size!=i.displaySize&&i.from*this.heightOracle.charWidth+r<this.pixelViewport.left&&(r=i.size-i.displaySize);let h,d,u=this.pixelViewport.left+r,f=this.pixelViewport.right+r;if(null!=c){let t=xs(n,c),e=((f-u)/2+s)/i;h=t-e,d=t+e}else h=(u-s)/i,d=(f+s)/i;l=ys(n,h),a=ys(n,d)}l>e.from&&h(e.from,l,e,n),a<e.to&&h(a,e.to,e,n)};for(let t of this.viewportLines)Array.isArray(t.type)?t.type.forEach(c):c(t);return a}gapSize(t,e,i,s){let o=xs(s,i)-xs(s,e);return this.heightOracle.lineWrapping?t.height*o:s.total*this.heightOracle.charWidth*o}updateLineGaps(t){ms.same(t,this.lineGaps)||(this.lineGaps=t,this.lineGapDeco=tt.set(t.map(t=>t.draw(this,this.heightOracle.lineWrapping))))}computeVisibleRanges(t){let e=this.stateDeco;this.lineGaps.length&&(e=e.concat(this.lineGapDeco));let i=[];s.spans(e,this.viewport.from,this.viewport.to,{span(t,e){i.push({from:t,to:e})},point(){}},20);let o=0;if(i.length!=this.visibleRanges.length)o=12;else for(let e=0;e<i.length&&!(8&o);e++){let s=this.visibleRanges[e],n=i[e];s.from==n.from&&s.to==n.to||(o|=4,t&&t.mapPos(s.from,-1)==n.from&&t.mapPos(s.to,1)==n.to||(o|=8))}return this.visibleRanges=i,o}lineBlockAt(t){return t>=this.viewport.from&&t<=this.viewport.to&&this.viewportLines.find(e=>e.from<=t&&e.to>=t)||ks(this.heightMap.lineAt(t,is.ByPos,this.heightOracle,0,0),this.scaler)}lineBlockAtHeight(t){return t>=this.viewportLines[0].top&&t<=this.viewportLines[this.viewportLines.length-1].bottom&&this.viewportLines.find(e=>e.top<=t&&e.bottom>=t)||ks(this.heightMap.lineAt(this.scaler.fromDOM(t),is.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 ks(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 bs{constructor(t,e){this.from=t,this.to=e}}function ys({total:t,ranges:e},i){if(i<=0)return e[0].from;if(i>=1)return e[e.length-1].to;let s=Math.floor(t*i);for(let t=0;;t++){let{from:i,to:o}=e[t],n=o-i;if(s<=n)return i+s;s-=n}}function xs(t,e){let i=0;for(let{from:s,to:o}of t.ranges){if(e<=o){i+=e-s;break}i+=o-s}return i/t.total}const Ss={toDOM:t=>t,fromDOM:t=>t,scale:1,eq(t){return t==this}};function Cs(t){let e=t.facet(we).filter(t=>"function"!=typeof t),i=t.facet(ye).filter(t=>"function"!=typeof t);return i.length&&e.push(s.join(i)),e}class Ms{constructor(t,e,i){let s=0,o=0,n=0;this.viewports=i.map(({from:i,to:o})=>{let n=e.lineAt(i,is.ByPos,t,0,0).top,r=e.lineAt(o,is.ByPos,t,0,0).bottom;return s+=r-n,{from:i,to:o,top:n,bottom:r,domTop:0,domBottom:0}}),this.scale=(7e6-s)/(e.height-s);for(let t of this.viewports)t.domTop=n+(t.top-o)*this.scale,n=t.domBottom=t.domTop+(t.bottom-t.top),o=t.bottom}toDOM(t){for(let e=0,i=0,s=0;;e++){let o=e<this.viewports.length?this.viewports[e]:null;if(!o||t<o.top)return s+(t-i)*this.scale;if(t<=o.bottom)return o.domTop+(t-o.top);i=o.bottom,s=o.domBottom}}fromDOM(t){for(let e=0,i=0,s=0;;e++){let o=e<this.viewports.length?this.viewports[e]:null;if(!o||t<o.domTop)return i+(t-s)/this.scale;if(t<=o.domBottom)return o.top+(t-o.domTop);i=o.bottom,s=o.domBottom}}eq(t){return t instanceof Ms&&(this.scale==t.scale&&this.viewports.length==t.viewports.length&&this.viewports.every((e,i)=>e.from==t.viewports[i].from&&e.to==t.viewports[i].to))}}function ks(t,e){if(1==e.scale)return t;let i=e.toDOM(t.top),s=e.toDOM(t.bottom);return new es(t.from,t.length,i,s-i,Array.isArray(t._content)?t._content.map(t=>ks(t,e)):t._content)}const As=e.define({combine:t=>t.join(" ")}),Ts=e.define({combine:t=>t.indexOf(!0)>-1}),Ds=M.newName(),Os=M.newName(),Ls=M.newName(),Bs={"&light":"."+Os,"&dark":"."+Ls};function Es(t,e,i){return new M(e,{finish:e=>/&/.test(e)?e.replace(/&\w*/,e=>{if("&"==e)return t;if(!i||!i[e])throw new RangeError(`Unsupported selector: ${e}`);return i[e]}):t+" "+e})}const Rs=Es("."+Ds,{"&":{position:"relative !important",boxSizing:"border-box","&.cm-focused":{outline:"1px dotted #212121"},display:"flex !important",flexDirection:"column"},".cm-scroller":{display:"flex !important",alignItems:"flex-start !important",fontFamily:"monospace",lineHeight:1.4,height:"100%",overflowX:"auto",position:"relative",zIndex:0,overflowAnchor:"none"},".cm-content":{margin:0,flexGrow:2,flexShrink:0,display:"block",whiteSpace:"pre",wordWrap:"normal",boxSizing:"border-box",minHeight:"100%",padding:"4px 0",outline:"none","&[contenteditable=true]":{WebkitUserModify:"read-write-plaintext-only"}},".cm-lineWrapping":{whiteSpace_fallback:"pre-wrap",whiteSpace:"break-spaces",wordBreak:"break-word",overflowWrap:"anywhere",flexShrink:1},"&light .cm-content":{caretColor:"black"},"&dark .cm-content":{caretColor:"white"},".cm-line":{display:"block",padding:"0 2px 0 6px"},".cm-layer":{position:"absolute",left:0,top:0,contain:"size style","& > *":{position:"absolute"}},"&light .cm-selectionBackground":{background:"#d9d9d9"},"&dark .cm-selectionBackground":{background:"#222"},"&light.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground":{background:"#d7d4f0"},"&dark.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground":{background:"#233"},".cm-cursorLayer":{pointerEvents:"none"},"&.cm-focused > .cm-scroller > .cm-cursorLayer":{animation:"steps(1) cm-blink 1.2s infinite"},"@keyframes cm-blink":{"0%":{},"50%":{opacity:0},"100%":{}},"@keyframes cm-blink2":{"0%":{},"50%":{opacity:0},"100%":{}},".cm-cursor, .cm-dropCursor":{borderLeft:"1.2px solid black",marginLeft:"-0.6px",pointerEvents:"none"},".cm-cursor":{display:"none"},"&dark .cm-cursor":{borderLeftColor:"#ddd"},".cm-dropCursor":{position:"absolute"},"&.cm-focused > .cm-scroller > .cm-cursorLayer .cm-cursor":{display:"block"},".cm-iso":{unicodeBidi:"isolate"},".cm-announced":{position:"fixed",top:"-10000px"},"@media print":{".cm-announced":{display:"none"}},"&light .cm-activeLine":{backgroundColor:"#cceeff44"},"&dark .cm-activeLine":{backgroundColor:"#99eeff33"},"&light .cm-specialChar":{color:"red"},"&dark .cm-specialChar":{color:"#f78"},".cm-gutters":{flexShrink:0,display:"flex",height:"100%",boxSizing:"border-box",zIndex:200},".cm-gutters-before":{insetInlineStart:0},".cm-gutters-after":{insetInlineEnd:0},"&light .cm-gutters":{backgroundColor:"#f5f5f5",color:"#6c6c6c",border:"0px solid #ddd","&.cm-gutters-before":{borderRightWidth:"1px"},"&.cm-gutters-after":{borderLeftWidth:"1px"}},"&dark .cm-gutters":{backgroundColor:"#333338",color:"#ccc"},".cm-gutter":{display:"flex !important",flexDirection:"column",flexShrink:0,boxSizing:"border-box",minHeight:"100%",overflow:"hidden"},".cm-gutterElement":{boxSizing:"border-box"},".cm-lineNumbers .cm-gutterElement":{padding:"0 3px 0 5px",minWidth:"20px",textAlign:"right",whiteSpace:"nowrap"},"&light .cm-activeLineGutter":{backgroundColor:"#e2f2ff"},"&dark .cm-activeLineGutter":{backgroundColor:"#222227"},".cm-panels":{boxSizing:"border-box",position:"sticky",left:0,right:0,zIndex:300},"&light .cm-panels":{backgroundColor:"#f5f5f5",color:"black"},"&light .cm-panels-top":{borderBottom:"1px solid #ddd"},"&light .cm-panels-bottom":{borderTop:"1px solid #ddd"},"&dark .cm-panels":{backgroundColor:"#333338",color:"white"},".cm-dialog":{padding:"2px 19px 4px 6px",position:"relative","& label":{fontSize:"80%"}},".cm-dialog-close":{position:"absolute",top:"3px",right:"4px",backgroundColor:"inherit",border:"none",font:"inherit",fontSize:"14px",padding:"0"},".cm-tab":{display:"inline-block",overflow:"hidden",verticalAlign:"bottom"},".cm-widgetBuffer":{verticalAlign:"text-top",height:"1em",width:0,display:"inline"},".cm-placeholder":{color:"#888",display:"inline-block",verticalAlign:"top",userSelect:"none"},".cm-highlightSpace":{backgroundImage:"radial-gradient(circle at 50% 55%, #aaa 20%, transparent 5%)",backgroundPosition:"center"},".cm-highlightTab":{backgroundImage:'url(\'data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="200" height="20"><path stroke="%23888" stroke-width="1" fill="none" d="M1 10H196L190 5M190 15L196 10M197 4L197 16"/></svg>\')',backgroundSize:"auto 100%",backgroundPosition:"right 90%",backgroundRepeat:"no-repeat"},".cm-trailingSpace":{backgroundColor:"#ff332255"},".cm-button":{verticalAlign:"middle",color:"inherit",fontSize:"70%",padding:".2em 1em",borderRadius:"1px"},"&light .cm-button":{backgroundImage:"linear-gradient(#eff1f5, #d9d9df)",border:"1px solid #888","&:active":{backgroundImage:"linear-gradient(#b4b4b4, #d0d3d6)"}},"&dark .cm-button":{backgroundImage:"linear-gradient(#393939, #111)",border:"1px solid #888","&:active":{backgroundImage:"linear-gradient(#111, #333)"}},".cm-textfield":{verticalAlign:"middle",color:"inherit",fontSize:"70%",border:"1px solid silver",padding:".2em .5em"},"&light .cm-textfield":{backgroundColor:"white"},"&dark .cm-textfield":{border:"1px solid #555",backgroundColor:"inherit"}},Bs),Hs={childList:!0,characterData:!0,subtree:!0,attributes:!0,characterDataOldValue:!0},Ws=j.ie&&j.ie_version<=11;class Ns{constructor(t){this.view=t,this.active=!1,this.editContext=null,this.selectionRange=new bt,this.selectionChanged=!1,this.delayedFlush=-1,this.resizeTimeout=-1,this.queue=[],this.delayedAndroidKey=null,this.flushingAndroidKey=-1,this.lastChange=0,this.scrollTargets=[],this.intersection=null,this.resizeScroll=null,this.intersecting=!1,this.gapIntersection=null,this.gaps=[],this.printQuery=null,this.parentCheck=-1,this.dom=t.contentDOM,this.observer=new MutationObserver(e=>{for(let t of e)this.queue.push(t);(j.ie&&j.ie_version<=11||j.ios&&t.composing)&&e.some(t=>"childList"==t.type&&t.removedNodes.length||"characterData"==t.type&&t.oldValue.length>t.target.nodeValue.length)?this.flushSoon():this.flush()}),!window.EditContext||!j.android||!1===t.constructor.EDIT_CONTEXT||j.chrome&&j.chrome_version<126||(this.editContext=new Fs(t),t.state.facet(de)&&(t.contentDOM.editContext=this.editContext.editContext)),Ws&&(this.onCharData=t=>{this.queue.push({target:t.target,type:"characterData",oldValue:t.prevValue}),this.flushSoon()}),this.onSelectionChange=this.onSelectionChange.bind(this),this.onResize=this.onResize.bind(this),this.onPrint=this.onPrint.bind(this),this.onScroll=this.onScroll.bind(this),window.matchMedia&&(this.printQuery=window.matchMedia("print")),"function"==typeof ResizeObserver&&(this.resizeScroll=new ResizeObserver(()=>{var t;(null===(t=this.view.docView)||void 0===t?void 0:t.lastUpdate)<Date.now()-75&&this.onResize()}),this.resizeScroll.observe(t.scrollDOM)),this.addWindowListeners(this.win=t.win),this.start(),"function"==typeof IntersectionObserver&&(this.intersection=new IntersectionObserver(t=>{this.parentCheck<0&&(this.parentCheck=setTimeout(this.listenForScroll.bind(this),1e3)),t.length>0&&t[t.length-1].intersectionRatio>0!=this.intersecting&&(this.intersecting=!this.intersecting,this.intersecting!=this.view.inView&&this.onScrollChanged(document.createEvent("Event")))},{threshold:[0,.001]}),this.intersection.observe(this.dom),this.gapIntersection=new IntersectionObserver(t=>{t.length>0&&t[t.length-1].intersectionRatio>0&&this.onScrollChanged(document.createEvent("Event"))},{})),this.listenForScroll(),this.readSelectionRange()}onScrollChanged(t){this.view.inputState.runHandlers("scroll",t),this.intersecting&&this.view.measure()}onScroll(t){this.intersecting&&this.flush(!1),this.editContext&&this.view.requestMeasure(this.editContext.measureReq),this.onScrollChanged(t)}onResize(){this.resizeTimeout<0&&(this.resizeTimeout=setTimeout(()=>{this.resizeTimeout=-1,this.view.requestMeasure()},50))}onPrint(t){("change"!=t.type&&t.type||t.matches)&&(this.view.viewState.printing=!0,this.view.measure(),setTimeout(()=>{this.view.viewState.printing=!1,this.view.requestMeasure()},500))}updateGaps(t){if(this.gapIntersection&&(t.length!=this.gaps.length||this.gaps.some((e,i)=>e!=t[i]))){this.gapIntersection.disconnect();for(let e of t)this.gapIntersection.observe(e);this.gaps=t}}onSelectionChange(t){let e=this.selectionChanged;if(!this.readSelectionRange()||this.delayedAndroidKey)return;let{view:i}=this,s=this.selectionRange;if(i.state.facet(de)?i.root.activeElement!=this.dom:!ht(this.dom,s))return;let o=s.anchorNode&&i.docView.tile.nearest(s.anchorNode);o&&o.isWidget()&&o.widget.ignoreEvent(t)?e||(this.selectionChanged=!1):(j.ie&&j.ie_version<=11||j.android&&j.chrome)&&!i.state.selection.main.empty&&s.focusNode&&dt(s.focusNode,s.focusOffset,s.anchorNode,s.anchorOffset)?this.flushSoon():this.flush(!1)}readSelectionRange(){let{view:t}=this,e=lt(t.root);if(!e)return!1;let i=j.safari&&11==t.root.nodeType&&t.root.activeElement==this.dom&&function(t,e){if(e.getComposedRanges){let i=e.getComposedRanges(t.root)[0];if(i)return Vs(t,i)}let i=null;function s(t){t.preventDefault(),t.stopImmediatePropagation(),i=t.getTargetRanges()[0]}return t.contentDOM.addEventListener("beforeinput",s,!0),t.dom.ownerDocument.execCommand("indent"),t.contentDOM.removeEventListener("beforeinput",s,!0),i?Vs(t,i):null}(this.view,e)||e;if(!i||this.selectionRange.eq(i))return!1;let s=ht(this.dom,i);return s&&!this.selectionChanged&&t.inputState.lastFocusTime>Date.now()-200&&t.inputState.lastTouchTime<Date.now()-300&&function(t,e){let i=e.focusNode,s=e.focusOffset;if(!i||e.anchorNode!=i||e.anchorOffset!=s)return!1;for(s=Math.min(s,gt(i));;)if(s){if(1!=i.nodeType)return!1;let t=i.childNodes[s-1];"false"==t.contentEditable?s--:(i=t,s=gt(i))}else{if(i==t)return!0;s=ut(i),i=i.parentNode}}(this.dom,i)?(this.view.inputState.lastFocusTime=0,t.docView.updateSelection(),!1):(this.selectionRange.setRange(i),s&&(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(1==i.nodeType)!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(11!=i.nodeType)break;i=i.host}if(t<this.scrollTargets.length&&!e&&(e=this.scrollTargets.slice(0,t)),e){for(let t of this.scrollTargets)t.removeEventListener("scroll",this.onScroll);for(let t of this.scrollTargets=e)t.addEventListener("scroll",this.onScroll)}}ignore(t){if(!this.active)return t();try{return this.stop(),t()}finally{this.start(),this.clear()}}start(){this.active||(this.observer.observe(this.dom,Hs),Ws&&this.dom.addEventListener("DOMCharacterDataModified",this.onCharData),this.active=!0)}stop(){this.active&&(this.active=!1,this.observer.disconnect(),Ws&&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 t=()=>{let t=this.delayedAndroidKey;if(t){this.clearDelayedAndroidKey(),this.view.inputState.lastKeyCode=t.keyCode,this.view.inputState.lastKeyTime=Date.now(),!this.flush()&&t.force&&Mt(this.dom,t.key,t.keyCode)}};this.flushingAndroidKey=this.view.win.requestAnimationFrame(t)}this.delayedAndroidKey&&"Enter"!=t||(this.delayedAndroidKey={key:t,keyCode:e,force:this.lastChange<Date.now()-50||!!(null===(i=this.delayedAndroidKey)||void 0===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 o of t){let t=this.readMutation(o);t&&(t.typeOver&&(s=!0),-1==e?({from:e,to:i}=t):(e=Math.min(t.from,e),i=Math.max(t.to,i)))}return{from:e,to:i,typeOver:s}}readChange(){let{from:t,to:e,typeOver:i}=this.processRecords(),s=this.selectionChanged&&ht(this.dom,this.selectionRange);if(t<0&&!s)return null;t>-1&&(this.lastChange=Date.now()),this.view.inputState.lastFocusTime=0,this.selectionChanged=!1;let o=new bi(this.view,t,e,i);return this.view.docView.domChanged={newSel:o.newSel?o.newSel.main:null},o}flush(t=!0){if(this.delayedFlush>=0||this.delayedAndroidKey)return!1;t&&this.readSelectionRange();let e=this.readChange();if(!e)return this.view.requestMeasure(),!1;let i=this.view.state,s=xi(this.view,e);return this.view.state==i&&(e.domChanged||e.newSel&&!Mi(this.view.state.selection,e.newSel.main))&&this.view.update([]),s}readMutation(t){let e=this.view.docView.tile.nearest(t.target);if(!e||e.isWidget())return null;if(e.markDirty("attributes"==t.type),"childList"==t.type){let i=Ps(e,t.previousSibling||t.target.previousSibling,-1),s=Ps(e,t.nextSibling||t.target.nextSibling,1);return{from:i?e.posAfter(i):e.posAtStart,to:s?e.posBefore(s):e.posAtEnd,typeOver:!1}}return"characterData"==t.type?{from:e.posAtStart,to:e.posAtEnd,typeOver:t.target.nodeValue==t.oldValue}:null}setWindow(t){t!=this.win&&(this.removeWindowListeners(this.win),this.win=t,this.addWindowListeners(this.win))}addWindowListeners(t){t.addEventListener("resize",this.onResize),this.printQuery?this.printQuery.addEventListener?this.printQuery.addEventListener("change",this.onPrint):this.printQuery.addListener(this.onPrint):t.addEventListener("beforeprint",this.onPrint),t.addEventListener("scroll",this.onScroll),t.document.addEventListener("selectionchange",this.onSelectionChange)}removeWindowListeners(t){t.removeEventListener("scroll",this.onScroll),t.removeEventListener("resize",this.onResize),this.printQuery?this.printQuery.removeEventListener?this.printQuery.removeEventListener("change",this.onPrint):this.printQuery.removeListener(this.onPrint):t.removeEventListener("beforeprint",this.onPrint),t.document.removeEventListener("selectionchange",this.onSelectionChange)}update(t){this.editContext&&(this.editContext.update(t),t.startState.facet(de)!=t.state.facet(de)&&(t.view.contentDOM.editContext=t.state.facet(de)?this.editContext.editContext:null))}destroy(){var t,e,i;this.stop(),null===(t=this.intersection)||void 0===t||t.disconnect(),null===(e=this.gapIntersection)||void 0===e||e.disconnect(),null===(i=this.resizeScroll)||void 0===i||i.disconnect();for(let t of this.scrollTargets)t.removeEventListener("scroll",this.onScroll);this.removeWindowListeners(this.win),clearTimeout(this.parentCheck),clearTimeout(this.resizeTimeout),this.win.cancelAnimationFrame(this.delayedFlush),this.win.cancelAnimationFrame(this.flushingAndroidKey),this.editContext&&(this.view.contentDOM.editContext=null,this.editContext.destroy())}}function Ps(t,e,i){for(;e;){let s=Le.get(e);if(s&&s.parent==t)return s;let o=e.parentNode;e=o!=t.dom?o:i>0?e.nextSibling:e.previousSibling}return null}function Vs(t,e){let i=e.startContainer,s=e.startOffset,o=e.endContainer,n=e.endOffset,r=t.docView.domAtPos(t.state.selection.main.anchor,1);return dt(r.node,r.offset,o,n)&&([i,s,o,n]=[o,n,i,s]),{anchorNode:i,anchorOffset:s,focusNode:o,focusOffset:n}}class Fs{constructor(t){this.from=0,this.to=0,this.pendingContextChange=null,this.handlers=Object.create(null),this.composing=null,this.resetRange(t.state);let e=this.editContext=new window.EditContext({text:t.state.doc.sliceString(this.from,this.to),selectionStart:this.toContextPos(Math.max(this.from,Math.min(this.to,t.state.selection.main.anchor))),selectionEnd:this.toContextPos(t.state.selection.main.head)});this.handlers.textupdate=i=>{let s=t.state.selection.main,{anchor:o,head:n}=s,r=this.toEditorPos(i.updateRangeStart),a=this.toEditorPos(i.updateRangeEnd);t.inputState.composing>=0&&!this.composing&&(this.composing={contextBase:i.updateRangeStart,editorBase:r,drifted:!1});let h=a-r>i.text.length;r==this.from&&o<this.from?r=o:a==this.to&&o>this.to&&(a=o);let c=Ci(t.state.sliceDoc(r,a),i.text,(h?s.from:s.to)-r,h?"end":null);if(!c){let e=l.single(this.toEditorPos(i.selectionStart),this.toEditorPos(i.selectionEnd));return void(Mi(e,s)||t.dispatch({selection:e,userEvent:"select"}))}let d={from:c.from+r,to:c.toA+r,insert:u.of(i.text.slice(c.from,c.toB).split("\n"))};if((j.mac||j.android)&&d.from==n-1&&/^\. ?$/.test(i.text)&&"off"==t.contentDOM.getAttribute("autocorrect")&&(d={from:r,to:a,insert:u.of([i.text.replace("."," ")])}),this.pendingContextChange=d,!t.state.readOnly){let e=this.to-this.from+(d.to-d.from+d.insert.length);Si(t,d,l.single(this.toEditorPos(i.selectionStart,e),this.toEditorPos(i.selectionEnd,e)))}this.pendingContextChange&&(this.revertPending(t.state),this.setSelection(t.state)),d.from<d.to&&!d.insert.length&&t.inputState.composing>=0&&!/[\\p{Alphabetic}\\p{Number}_]/.test(e.text.slice(Math.max(0,i.updateRangeStart-1),Math.min(e.text.length,i.updateRangeStart+1)))&&this.handlers.compositionend(i)},this.handlers.characterboundsupdate=i=>{let s=[],o=null;for(let e=this.toEditorPos(i.rangeStart),n=this.toEditorPos(i.rangeEnd);e<n;e++){let i=t.coordsForChar(e);o=i&&new DOMRect(i.left,i.top,i.right-i.left,i.bottom-i.top)||o||new DOMRect,s.push(o)}e.updateCharacterBounds(i.rangeStart,s)},this.handlers.textformatupdate=e=>{let i=[];for(let t of e.getTextFormats()){let e=t.underlineStyle,s=t.underlineThickness;if(!/none/i.test(e)&&!/none/i.test(s)){let o=this.toEditorPos(t.rangeStart),n=this.toEditorPos(t.rangeEnd);if(o<n){let t=`text-decoration: underline ${/^[a-z]/.test(e)?e+" ":"Dashed"==e?"dashed ":"Squiggle"==e?"wavy ":""}${/thin/i.test(s)?1:2}px`;i.push(tt.mark({attributes:{style:t}}).range(o,n))}}}t.dispatch({effects:he.of(tt.set(i))})},this.handlers.compositionstart=()=>{t.inputState.composing<0&&(t.inputState.composing=0,t.inputState.compositionFirstChange=!0)},this.handlers.compositionend=()=>{if(t.inputState.composing=-1,t.inputState.compositionFirstChange=null,this.composing){let{drifted:e}=this.composing;this.composing=null,e&&this.reset(t.state)}};for(let t in this.handlers)e.addEventListener(t,this.handlers[t]);this.measureReq={read:t=>{this.editContext.updateControlBounds(t.contentDOM.getBoundingClientRect());let e=lt(t.root);e&&e.rangeCount&&this.editContext.updateSelectionBounds(e.getRangeAt(0).getBoundingClientRect())}}}applyEdits(t){let e=0,i=!1,s=this.pendingContextChange;return t.changes.iterChanges((o,n,r,l,a)=>{if(i)return;let h=a.length-(n-o);if(s&&n>=s.to){if(s.from==o&&s.to==n&&s.insert.eq(a))return s=this.pendingContextChange=null,e+=h,void(this.to+=h);s=null,this.revertPending(t.state)}if(o+=e,(n+=e)<=this.from)this.from+=h,this.to+=h;else if(o<this.to){if(o<this.from||n>this.to||this.to-this.from+a.length>3e4)return void(i=!0);this.editContext.updateText(this.toContextPos(o),this.toContextPos(n),a.toString()),this.to+=h}e+=h}),s&&!i&&this.revertPending(t.state),!i}update(t){let e=this.pendingContextChange,i=t.startState.selection.main;this.composing&&(this.composing.drifted||!t.changes.touchesRange(i.from,i.to)&&t.transactions.some(t=>!t.isUserEvent("input.type")&&t.changes.touchesRange(this.from,this.to)))?(this.composing.drifted=!0,this.composing.editorBase=t.changes.mapPos(this.composing.editorBase)):this.applyEdits(t)&&this.rangeIsValid(t.state)?(t.docChanged||t.selectionSet||e)&&this.setSelection(t.state):(this.pendingContextChange=null,this.reset(t.state)),(t.geometryChanged||t.docChanged||t.selectionSet)&&t.view.requestMeasure(this.measureReq)}resetRange(t){let{head:e}=t.selection.main;this.from=Math.max(0,e-1e4),this.to=Math.min(t.doc.length,e+1e4)}reset(t){this.resetRange(t),this.editContext.updateText(0,this.editContext.text.length,t.doc.sliceString(this.from,this.to)),this.setSelection(t)}revertPending(t){let e=this.pendingContextChange;this.pendingContextChange=null,this.editContext.updateText(this.toContextPos(e.from),this.toContextPos(e.from+e.insert.length),t.doc.sliceString(e.from,e.to))}setSelection(t){let{main:e}=t.selection,i=this.toContextPos(Math.max(this.from,Math.min(this.to,e.anchor))),s=this.toContextPos(e.head);this.editContext.selectionStart==i&&this.editContext.selectionEnd==s||this.editContext.updateSelection(i,s)}rangeIsValid(t){let{head:e}=t.selection.main;return!(this.from>0&&e-this.from<500||this.to<t.doc.length&&this.to-e<500||this.to-this.from>3e4)}toEditorPos(t,e=this.to-this.from){t=Math.min(t,e);let i=this.composing;return i&&i.drifted?i.editorBase+(t-i.contextBase):t+this.from}toContextPos(t){let e=this.composing;return e&&e.drifted?e.contextBase+(t-e.editorBase):t-this.from}destroy(){for(let t in this.handlers)this.editContext.removeEventListener(t,this.handlers[t])}}class zs{get state(){return this.viewState.state}get viewport(){return this.viewState.viewport}get visibleRanges(){return this.viewState.visibleRanges}get inView(){return this.viewState.inView}get composing(){return!!this.inputState&&this.inputState.composing>0}get compositionStarted(){return!!this.inputState&&this.inputState.composing>=0}get root(){return this._root}get win(){return this.dom.ownerDocument.defaultView||window}constructor(t={}){var e;this.plugins=[],this.pluginMap=new Map,this.editorAttrs={},this.contentAttrs={},this.bidiCache=[],this.destroyed=!1,this.updateState=2,this.measureScheduled=-1,this.measureRequests=[],this.contentDOM=document.createElement("div"),this.scrollDOM=document.createElement("div"),this.scrollDOM.tabIndex=-1,this.scrollDOM.className="cm-scroller",this.scrollDOM.appendChild(this.contentDOM),this.announceDOM=document.createElement("div"),this.announceDOM.className="cm-announced",this.announceDOM.setAttribute("aria-live","polite"),this.dom=document.createElement("div"),this.dom.appendChild(this.announceDOM),this.dom.appendChild(this.scrollDOM),t.parent&&t.parent.appendChild(this.dom);let{dispatch:i}=t;this.dispatchTransactions=t.dispatchTransactions||i&&(t=>t.forEach(t=>i(t,this)))||(t=>this.update(t)),this.dispatch=this.dispatch.bind(this),this._root=t.root||function(t){for(;t;){if(t&&(9==t.nodeType||11==t.nodeType&&t.host))return t;t=t.assignedSlot||t.parentNode}return null}(t.parent)||document,this.viewState=new ws(t.state||o.create(t)),t.scrollTo&&t.scrollTo.is(ae)&&(this.viewState.scrollTarget=t.scrollTo.value.clip(this.viewState.state)),this.plugins=this.state.facet(fe).map(t=>new ge(t));for(let t of this.plugins)t.update(this);this.observer=new Ns(this),this.inputState=new ki(this),this.inputState.ensureHandlers(this.plugins),this.docView=new Ze(this),this.mountStyles(),this.updateAttrs(),this.updateState=0,this.requestMeasure(),(null===(e=document.fonts)||void 0===e?void 0:e.ready)&&document.fonts.ready.then(()=>{this.viewState.mustMeasureContent=!0,this.requestMeasure()})}dispatch(...t){let e=1==t.length&&t[0]instanceof n?t:1==t.length&&Array.isArray(t[0])?t[0]:[this.state.update(...t)];this.dispatchTransactions(e,this)}update(t){if(0!=this.updateState)throw new Error("Calls to EditorView.update are not allowed while an update is in progress");let e,i=!1,s=!1,n=this.state;for(let e of t){if(e.startState!=n)throw new RangeError("Trying to update state with a transaction that doesn't start from the previous state.");n=e.state}if(this.destroyed)return void(this.viewState.state=n);let r=this.hasFocus,a=0,h=null;t.some(t=>t.annotation(ji))?(this.inputState.notifiedFocused=r,a=1):r!=this.inputState.notifiedFocused&&(this.inputState.notifiedFocused=r,h=Xi(n,r),h||(a=1));let c=this.observer.delayedAndroidKey,d=null;if(c?(this.observer.clearDelayedAndroidKey(),d=this.observer.readChange(),(d&&!this.state.doc.eq(n.doc)||!this.state.selection.eq(n.selection))&&(d=null)):this.observer.clear(),n.facet(o.phrases)!=this.state.facet(o.phrases))return this.setState(n);e=De.create(this,n,t),e.flags|=a;let u=this.viewState.scrollTarget;try{this.updateState=2;for(let e of t){if(u&&(u=u.map(e.changes)),e.scrollIntoView){let{main:t}=e.state.selection;u=new le(t.empty?t:l.cursor(t.head,t.head>t.anchor?-1:1))}for(let t of e.effects)t.is(ae)&&(u=t.value.clip(this.state))}this.viewState.update(e,u),this.bidiCache=Ks.update(this.bidiCache,e.changes),e.empty||(this.updatePlugins(e),this.inputState.update(e)),i=this.docView.update(e),this.state.facet(Ae)!=this.styleModules&&this.mountStyles(),s=this.updateAttrs(),this.showAnnouncements(t),this.docView.updateSelection(i,t.some(t=>t.isUserEvent("select.pointer")))}finally{this.updateState=0}if(e.startState.facet(As)!=e.state.facet(As)&&(this.viewState.mustMeasureContent=!0),(i||s||u||this.viewState.mustEnforceCursorAssoc||this.viewState.mustMeasureContent)&&this.requestMeasure(),i&&this.docViewUpdate(),!e.empty)for(let t of this.state.facet(Zt))try{t(e)}catch(t){ce(this.state,t,"update listener")}(h||d)&&Promise.resolve().then(()=>{h&&this.state==h.startState&&this.dispatch(h),d&&!xi(this,d)&&c.force&&Mt(this.contentDOM,c.key,c.keyCode)})}setState(t){if(0!=this.updateState)throw new Error("Calls to EditorView.setState are not allowed while an update is in progress");if(this.destroyed)return void(this.viewState.state=t);this.updateState=2;let e=this.hasFocus;try{for(let t of this.plugins)t.destroy(this);this.viewState=new ws(t),this.plugins=t.facet(fe).map(t=>new ge(t)),this.pluginMap.clear();for(let t of this.plugins)t.update(this);this.docView.destroy(),this.docView=new Ze(this),this.inputState.ensureHandlers(this.plugins),this.mountStyles(),this.updateAttrs(),this.bidiCache=[]}finally{this.updateState=0}e&&this.focus(),this.requestMeasure()}updatePlugins(t){let e=t.startState.facet(fe),i=t.state.facet(fe);if(e!=i){let s=[];for(let o of i){let i=e.indexOf(o);if(i<0)s.push(new ge(o));else{let e=this.plugins[i];e.mustUpdate=t,s.push(e)}}for(let e of this.plugins)e.mustUpdate!=t&&e.destroy(this);this.plugins=s,this.pluginMap.clear()}else for(let e of this.plugins)e.mustUpdate=t;for(let t=0;t<this.plugins.length;t++)this.plugins[t].update(this);e!=i&&this.inputState.ensureHandlers(this.plugins)}docViewUpdate(){for(let t of this.plugins){let e=t.value;if(e&&e.docViewUpdate)try{e.docViewUpdate(this)}catch(t){ce(this.state,t,"doc view update listener")}}}measure(t=!0){if(this.destroyed)return;if(this.measureScheduled>-1&&this.win.cancelAnimationFrame(this.measureScheduled),this.observer.delayedAndroidKey)return this.measureScheduled=-1,void this.requestMeasure();this.measureScheduled=0,t&&this.observer.forceFlush();let e=null,i=this.scrollDOM,s=i.scrollTop*this.scaleY,{scrollAnchorPos:o,scrollAnchorHeight:n}=this.viewState;Math.abs(s-this.viewState.scrollTop)>1&&(n=-1),this.viewState.scrollAnchorHeight=-1;try{for(let t=0;;t++){if(n<0)if(kt(i))o=-1,n=this.viewState.heightMap.height;else{let t=this.viewState.scrollAnchorAt(s);o=t.from,n=t.top}this.updateState=1;let r=this.viewState.measure(this);if(!r&&!this.measureRequests.length&&null==this.viewState.scrollTarget)break;if(t>5){console.warn(this.measureRequests.length?"Measure loop restarted more than 5 times":"Viewport failed to stabilize");break}let l=[];4&r||([this.measureRequests,l]=[l,this.measureRequests]);let a=l.map(t=>{try{return t.read(this)}catch(t){return ce(this.state,t),qs}}),h=De.create(this,this.state,[]),c=!1;h.flags|=r,e?e.flags|=r:e=h,this.updateState=2,h.empty||(this.updatePlugins(h),this.inputState.update(h),this.updateAttrs(),c=this.docView.update(h),c&&this.docViewUpdate());for(let t=0;t<l.length;t++)if(a[t]!=qs)try{let e=l[t];e.write&&e.write(a[t],this)}catch(t){ce(this.state,t)}if(c&&this.docView.updateSelection(!0),!h.viewportChanged&&0==this.measureRequests.length){if(this.viewState.editorHeight){if(this.viewState.scrollTarget){this.docView.scrollIntoView(this.viewState.scrollTarget),this.viewState.scrollTarget=null,n=-1;continue}{let t=(o<0?this.viewState.heightMap.height:this.viewState.lineBlockAt(o).top)-n;if(t>1||t<-1){s+=t,i.scrollTop=s/this.scaleY,n=-1;continue}}}break}}}finally{this.updateState=0,this.measureScheduled=-1}if(e&&!e.empty)for(let t of this.state.facet(Zt))t(e)}get themeClasses(){return Ds+" "+(this.state.facet(Ts)?Ls:Os)+" "+this.state.facet(As)}updateAttrs(){let t=_s(this,me,{class:"cm-editor"+(this.hasFocus?" cm-focused ":" ")+this.themeClasses}),e={spellcheck:"false",autocorrect:"off",autocapitalize:"off",writingsuggestions:"false",translate:"no",contenteditable:this.state.facet(de)?"true":"false",class:"cm-content",style:`${j.tabSize}: ${this.state.tabSize}`,role:"textbox","aria-multiline":"true"};this.state.readOnly&&(e["aria-readonly"]="true"),_s(this,ve,e);let i=this.observer.ignore(()=>{let i=$(this.contentDOM,this.contentAttrs,e),s=$(this.dom,this.editorAttrs,t);return i||s});return this.editorAttrs=t,this.contentAttrs=e,i}showAnnouncements(t){let e=!0;for(let i of t)for(let t of i.effects)if(t.is(zs.announce)){e&&(this.announceDOM.textContent=""),e=!1,this.announceDOM.appendChild(document.createElement("div")).textContent=t.value}}mountStyles(){this.styleModules=this.state.facet(Ae);let t=this.state.facet(zs.cspNonce);M.mount(this.root,this.styleModules.concat(Rs).reverse(),t?{nonce:t}:void 0)}readMeasured(){if(2==this.updateState)throw new Error("Reading the editor layout isn't allowed during an update");0==this.updateState&&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(null!=t.key)for(let e=0;e<this.measureRequests.length;e++)if(this.measureRequests[e].key===t.key)return void(this.measureRequests[e]=t);this.measureRequests.push(t)}}plugin(t){let e=this.pluginMap.get(t);return(void 0===e||e&&e.plugin!=t)&&this.pluginMap.set(t,e=this.plugins.find(e=>e.plugin==t)||null),e&&e.update(this).value}get documentTop(){return this.contentDOM.getBoundingClientRect().top+this.viewState.paddingTop}get documentPadding(){return{top:this.viewState.paddingTop,bottom:this.viewState.paddingBottom}}get scaleX(){return this.viewState.scaleX}get scaleY(){return this.viewState.scaleY}elementAtHeight(t){return this.readMeasured(),this.viewState.elementAtHeight(t)}lineBlockAtHeight(t){return this.readMeasured(),this.viewState.lineBlockAtHeight(t)}get viewportLineBlocks(){return this.viewState.viewportLines}lineBlockAt(t){return this.viewState.lineBlockAt(t)}get contentHeight(){return this.viewState.contentHeight}moveByChar(t,e,i){return hi(this,t,ri(this,t,e,i))}moveByGroup(t,e){return hi(this,t,ri(this,t,e,e=>function(t,e,i){let s=t.state.charCategorizer(e),o=s(i);return t=>{let e=s(t);return o==y.Space&&(o=e),o==e}}(this,t.head,e)))}visualLineSide(t,e){let i=this.bidiSpans(t),s=this.textDirectionAt(t.from),o=i[e?i.length-1:0];return l.cursor(o.side(e,s)+t.from,o.forward(!e,s)?1:-1)}moveToLineBoundary(t,e,i=!0){return function(t,e,i,s){let o=ni(t,e.head,e.assoc||-1),n=s&&o.type==Z.Text&&(t.lineWrapping||o.widgetLineBreaks)?t.coordsAtPos(e.assoc<0&&e.head>o.from?e.head-1:e.head):null;if(n){let e=t.dom.getBoundingClientRect(),s=t.textDirectionAt(o.from),r=t.posAtCoords({x:i==(s==Ot.LTR)?e.right-1:e.left+1,y:(n.top+n.bottom)/2});if(null!=r)return l.cursor(r,i?-1:1)}return l.cursor(i?o.to:o.from,i?-1:1)}(this,t,e,i)}moveVertically(t,e,i){return hi(this,t,function(t,e,i,s){let o=e.head,n=i?1:-1;if(o==(i?t.state.doc.length:0))return l.cursor(o,e.assoc);let r,a=e.goalColumn,h=t.contentDOM.getBoundingClientRect(),c=t.coordsAtPos(o,e.assoc||-1),d=t.documentTop;if(c)null==a&&(a=c.left-h.left),r=n<0?c.top:c.bottom;else{let e=t.viewState.lineBlockAt(o);null==a&&(a=Math.min(h.right-h.left,t.defaultCharacterWidth*(o-e.from))),r=(n<0?e.top:e.bottom)+d}let u=di(t,{x:h.left+a,y:r+(null!=s?s:t.viewState.heightOracle.textHeight>>1)*n},!1,n);return l.cursor(u.pos,u.assoc,void 0,a)}(this,t,e,i))}domAtPos(t,e=1){return this.docView.domAtPos(t,e)}posAtDOM(t,e=0){return this.docView.posFromDOM(t,e)}posAtCoords(t,e=!0){this.readMeasured();let i=di(this,t,e);return i&&i.pos}posAndSideAtCoords(t,e=!0){return this.readMeasured(),di(this,t,e)}coordsAtPos(t,e=1){this.readMeasured();let i=this.docView.coordsAt(t,e);if(!i||i.left==i.right)return i;let s=this.state.doc.lineAt(t),o=this.bidiSpans(s);return mt(i,o[Ft.find(o,t-s.from,-1,e)].dir==Ot.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(oe)||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>Is)return Yt(t.length);let e,i=this.textDirectionAt(t.from);for(let s of this.bidiCache)if(s.from==t.from&&s.dir==i&&(s.fresh||zt(s.isolates,e=Ce(this,t))))return s.order;e||(e=Ce(this,t));let s=_t(t.text,i,e);return this.bidiCache.push(new Ks(t.from,t.to,i,e,!0,s)),s}get hasFocus(){var t;return(this.dom.ownerDocument.hasFocus()||j.safari&&(null===(t=this.inputState)||void 0===t?void 0:t.lastContextMenu)>Date.now()-3e4)&&this.root.activeElement==this.contentDOM}focus(){this.observer.ignore(()=>{St(this.contentDOM),this.docView.updateSelection()})}setRoot(t){this._root!=t&&(this._root=t,this.observer.setWindow((9==t.nodeType?t:t.ownerDocument).defaultView||window),this.mountStyles())}destroy(){this.root.activeElement==this.contentDOM&&this.contentDOM.blur();for(let t of this.plugins)t.destroy(this);this.plugins=[],this.inputState.destroy(),this.docView.destroy(),this.dom.remove(),this.observer.destroy(),this.measureScheduled>-1&&this.win.cancelAnimationFrame(this.measureScheduled),this.destroyed=!0}static scrollIntoView(t,e={}){return ae.of(new le("number"==typeof t?l.cursor(t):t,e.y,e.x,e.yMargin,e.xMargin))}scrollSnapshot(){let{scrollTop:t,scrollLeft:e}=this.scrollDOM,i=this.viewState.scrollAnchorAt(t);return ae.of(new le(l.cursor(i.from),"start","start",i.top-t,e,!0))}setTabFocusMode(t){null==t?this.inputState.tabFocusMode=this.inputState.tabFocusMode<0?0:-1:"boolean"==typeof t?this.inputState.tabFocusMode=t?0:-1:0!=this.inputState.tabFocusMode&&(this.inputState.tabFocusMode=Date.now()+t)}static domEventHandlers(t){return pe.define(()=>({}),{eventHandlers:t})}static domEventObservers(t){return pe.define(()=>({}),{eventObservers:t})}static theme(t,e){let i=M.newName(),s=[As.of(i),Ae.of(Es(`.${i}`,t))];return e&&e.dark&&s.push(Ts.of(!0)),s}static baseTheme(t){return a.lowest(Ae.of(Es("."+Ds,t,Bs)))}static findFromDOM(t){var e;let i=t.querySelector(".cm-content"),s=i&&Le.get(i)||Le.get(t);return(null===(e=null==s?void 0:s.root)||void 0===e?void 0:e.view)||null}}zs.styleModule=Ae,zs.inputHandler=te,zs.clipboardInputFilter=ie,zs.clipboardOutputFilter=se,zs.scrollHandler=re,zs.focusChangeEffect=ee,zs.perLineTextDirection=oe,zs.exceptionSink=Jt,zs.updateListener=Zt,zs.editable=de,zs.mouseSelectionStyle=Qt,zs.dragMovesSelection=$t,zs.clickAddsSelectionRange=Ut,zs.decorations=we,zs.blockWrappers=be,zs.outerDecorations=ye,zs.atomicRanges=xe,zs.bidiIsolatedRanges=Se,zs.scrollMargins=Me,zs.darkTheme=Ts,zs.cspNonce=e.define({combine:t=>t.length?t[0]:""}),zs.contentAttributes=ve,zs.editorAttributes=me,zs.lineWrapping=zs.contentAttributes.of({class:"cm-lineWrapping"}),zs.announce=t.define();const Is=4096,qs={};class Ks{constructor(t,e,i,s,o,n){this.from=t,this.to=e,this.dir=i,this.isolates=s,this.fresh=o,this.order=n}static update(t,e){if(e.empty&&!t.some(t=>t.fresh))return t;let i=[],s=t.length?t[t.length-1].dir:Ot.LTR;for(let o=Math.max(0,t.length-10);o<t.length;o++){let n=t[o];n.dir!=s||e.touchesRange(n.from,n.to)||i.push(new Ks(e.mapPos(n.from,1),e.mapPos(n.to,-1),n.dir,n.isolates,!1,n.order))}return i}}function _s(t,e,i){for(let s=t.state.facet(e),o=s.length-1;o>=0;o--){let e=s[o],n="function"==typeof e?e(t):e;n&&X(n,i)}return i}const Ys=j.mac?"mac":j.windows?"win":j.linux?"linux":"key";function js(t,e,i){return e.altKey&&(t="Alt-"+t),e.ctrlKey&&(t="Ctrl-"+t),e.metaKey&&(t="Meta-"+t),!1!==i&&e.shiftKey&&(t="Shift-"+t),t}const Xs=a.default(zs.domEventHandlers({keydown:(t,e)=>eo($s(e.state),t,e,"editor")})),Gs=e.define({enables:Xs}),Us=new WeakMap;function $s(t){let e=t.facet(Gs),i=Us.get(e);return i||Us.set(e,i=function(t,e=Ys){let i=Object.create(null),s=Object.create(null),o=(t,e)=>{let i=s[t];if(null==i)s[t]=e;else if(i!=e)throw new Error("Key binding "+t+" is used both as a regular binding and as a multi-stroke prefix")},n=(t,s,n,r,l)=>{var a,h;let c=i[t]||(i[t]=Object.create(null)),d=s.split(/ (?!$)/).map(t=>function(t,e){const i=t.split(/-(?!$)/);let s,o,n,r,l=i[i.length-1];"Space"==l&&(l=" ");for(let t=0;t<i.length-1;++t){const l=i[t];if(/^(cmd|meta|m)$/i.test(l))r=!0;else if(/^a(lt)?$/i.test(l))s=!0;else if(/^(c|ctrl|control)$/i.test(l))o=!0;else if(/^s(hift)?$/i.test(l))n=!0;else{if(!/^mod$/i.test(l))throw new Error("Unrecognized modifier name: "+l);"mac"==e?r=!0:o=!0}}return s&&(l="Alt-"+l),o&&(l="Ctrl-"+l),r&&(l="Meta-"+l),n&&(l="Shift-"+l),l}(t,e));for(let e=1;e<d.length;e++){let i=d.slice(0,e).join(" ");o(i,!0),c[i]||(c[i]={preventDefault:!0,stopPropagation:!1,run:[e=>{let s=Js={view:e,prefix:i,scope:t};return setTimeout(()=>{Js==s&&(Js=null)},Zs),!0}]})}let u=d.join(" ");o(u,!1);let f=c[u]||(c[u]={preventDefault:!1,stopPropagation:!1,run:(null===(h=null===(a=c._any)||void 0===a?void 0:a.run)||void 0===h?void 0:h.slice())||[]});n&&f.run.push(n),r&&(f.preventDefault=!0),l&&(f.stopPropagation=!0)};for(let s of t){let t=s.scope?s.scope.split(" "):["editor"];if(s.any)for(let e of t){let t=i[e]||(i[e]=Object.create(null));t._any||(t._any={preventDefault:!1,stopPropagation:!1,run:[]});let{any:o}=s;for(let e in t)t[e].run.push(t=>o(t,to))}let o=s[e]||s.key;if(o)for(let e of t)n(e,o,s.run,s.preventDefault,s.stopPropagation),s.shift&&n(e,"Shift-"+o,s.shift,s.preventDefault,s.stopPropagation)}return i}(e.reduce((t,e)=>t.concat(e),[]))),i}function Qs(t,e,i){return eo($s(t.state),e,t,i)}let Js=null;const Zs=4e3;let to=null;function eo(t,e,i,s){to=e;let o=function(t){var e=!(O&&t.metaKey&&t.shiftKey&&!t.ctrlKey&&!t.altKey||L&&t.shiftKey&&t.key&&1==t.key.length||"Unidentified"==t.key)&&t.key||(t.shiftKey?D:T)[t.keyCode]||t.key||"Unidentified";return"Esc"==e&&(e="Escape"),"Del"==e&&(e="Delete"),"Left"==e&&(e="ArrowLeft"),"Up"==e&&(e="ArrowUp"),"Right"==e&&(e="ArrowRight"),"Down"==e&&(e="ArrowDown"),e}(e),n=m(o,0),r=w(n)==o.length&&" "!=o,l="",a=!1,h=!1,c=!1;Js&&Js.view==i&&Js.scope==s&&(l=Js.prefix+" ",Li.indexOf(e.keyCode)<0&&(h=!0,Js=null));let d,u,f=new Set,p=t=>{if(t){for(let e of t.run)if(!f.has(e)&&(f.add(e),e(i)))return t.stopPropagation&&(c=!0),!0;t.preventDefault&&(t.stopPropagation&&(c=!0),h=!0)}return!1},g=t[s];return g&&(p(g[l+js(o,e,!r)])?a=!0:!r||!(e.altKey||e.metaKey||e.ctrlKey)||j.windows&&e.ctrlKey&&e.altKey||j.mac&&e.altKey&&!e.ctrlKey&&!e.metaKey||!(d=T[e.keyCode])||d==o?r&&e.shiftKey&&p(g[l+js(o,e,!0)])&&(a=!0):(p(g[l+js(d,e,!0)])||e.shiftKey&&(u=D[e.keyCode])!=o&&u!=d&&p(g[l+js(u,e,!1)]))&&(a=!0),!a&&p(g._any)&&(a=!0)),h&&(a=!0),a&&c&&e.stopPropagation(),to=null,a}class io{constructor(t,e,i,s,o){this.className=t,this.left=e,this.top=i,this.width=s,this.height=o}draw(){let t=document.createElement("div");return t.className=this.className,this.adjust(t),t}update(t,e){return e.className==this.className&&(this.adjust(t),!0)}adjust(t){t.style.left=this.left+"px",t.style.top=this.top+"px",null!=this.width&&(t.style.width=this.width+"px"),t.style.height=this.height+"px"}eq(t){return this.left==t.left&&this.top==t.top&&this.width==t.width&&this.height==t.height&&this.className==t.className}static forRange(t,e,i){if(i.empty){let s=t.coordsAtPos(i.head,i.assoc||1);if(!s)return[];let o=so(t);return[new io(e,s.left-o.left,s.top-o.top,null,s.bottom-s.top)]}return function(t,e,i){if(i.to<=t.viewport.from||i.from>=t.viewport.to)return[];let s=Math.max(i.from,t.viewport.from),o=Math.min(i.to,t.viewport.to),n=t.textDirection==Ot.LTR,r=t.contentDOM,l=r.getBoundingClientRect(),a=so(t),h=r.querySelector(".cm-line"),c=h&&window.getComputedStyle(h),d=l.left+(c?parseInt(c.paddingLeft)+Math.min(0,parseInt(c.textIndent)):0),u=l.right-(c?parseInt(c.paddingRight):0),f=ni(t,s,1),p=ni(t,o,-1),g=f.type==Z.Text?f:null,m=p.type==Z.Text?p:null;g&&(t.lineWrapping||f.widgetLineBreaks)&&(g=oo(t,s,1,g));m&&(t.lineWrapping||p.widgetLineBreaks)&&(m=oo(t,o,-1,m));if(g&&m&&g.from==m.from&&g.to==m.to)return w(b(i.from,i.to,g));{let e=g?b(i.from,null,g):y(f,!1),s=m?b(null,i.to,m):y(p,!0),o=[];return(g||f).to<(m||p).from-(g&&m?1:0)||f.widgetLineBreaks>1&&e.bottom+t.defaultLineHeight/2<s.top?o.push(v(d,e.bottom,u,s.top)):e.bottom<s.top&&t.elementAtHeight((e.bottom+s.top)/2).type==Z.Text&&(e.bottom=s.top=(e.bottom+s.top)/2),w(e).concat(o).concat(w(s))}function v(t,i,s,o){return new io(e,t-a.left,i-a.top,s-t,o-i)}function w({top:t,bottom:e,horizontal:i}){let s=[];for(let o=0;o<i.length;o+=2)s.push(v(i[o],t,i[o+1],e));return s}function b(e,i,s){let o=1e9,r=-1e9,l=[];function a(e,i,a,h,c){let f=t.coordsAtPos(e,e==s.to?-2:2),p=t.coordsAtPos(a,a==s.from?2:-2);f&&p&&(o=Math.min(f.top,p.top,o),r=Math.max(f.bottom,p.bottom,r),c==Ot.LTR?l.push(n&&i?d:f.left,n&&h?u:p.right):l.push(!n&&h?d:p.left,!n&&i?u:f.right))}let h=null!=e?e:s.from,c=null!=i?i:s.to;for(let s of t.visibleRanges)if(s.to>h&&s.from<c)for(let o=Math.max(s.from,h),n=Math.min(s.to,c);;){let s=t.state.doc.lineAt(o);for(let r of t.bidiSpans(s)){let t=r.from+s.from,l=r.to+s.from;if(t>=n)break;l>o&&a(Math.max(t,o),null==e&&t<=h,Math.min(l,n),null==i&&l>=c,r.dir)}if(o=s.to+1,o>=n)break}return 0==l.length&&a(h,null==e,c,null==i,t.textDirection),{top:o,bottom:r,horizontal:l}}function y(t,e){let i=l.top+(e?t.top:t.bottom);return{top:i,bottom:i,horizontal:[]}}}(t,e,i)}}function so(t){let e=t.scrollDOM.getBoundingClientRect();return{left:(t.textDirection==Ot.LTR?e.left:e.right-t.scrollDOM.clientWidth*t.scaleX)-t.scrollDOM.scrollLeft*t.scaleX,top:e.top-t.scrollDOM.scrollTop*t.scaleY}}function oo(t,e,i,s){let o=t.coordsAtPos(e,2*i);if(!o)return s;let n=t.dom.getBoundingClientRect(),r=(o.top+o.bottom)/2,l=t.posAtCoords({x:n.left+1,y:r}),a=t.posAtCoords({x:n.right-1,y:r});return null==l||null==a?s:{from:Math.max(s.from,Math.min(l,a)),to:Math.min(s.to,Math.max(l,a))}}class no{constructor(t,e){this.view=t,this.layer=e,this.drawn=[],this.scaleX=1,this.scaleY=1,this.measureReq={read:this.measure.bind(this),write:this.draw.bind(this)},this.dom=t.scrollDOM.appendChild(document.createElement("div")),this.dom.classList.add("cm-layer"),e.above&&this.dom.classList.add("cm-layer-above"),e.class&&this.dom.classList.add(e.class),this.scale(),this.dom.setAttribute("aria-hidden","true"),this.setOrder(t.state),t.requestMeasure(this.measureReq),e.mount&&e.mount(this.dom,t)}update(t){t.startState.facet(ro)!=t.state.facet(ro)&&this.setOrder(t.state),(this.layer.update(t,this.dom)||t.geometryChanged)&&(this.scale(),t.view.requestMeasure(this.measureReq))}docViewUpdate(t){!1!==this.layer.updateOnDocViewUpdate&&t.requestMeasure(this.measureReq)}setOrder(t){let e=0,i=t.facet(ro);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)}scale(){let{scaleX:t,scaleY:e}=this.view;t==this.scaleX&&e==this.scaleY||(this.scaleX=t,this.scaleY=e,this.dom.style.transform=`scale(${1/t}, ${1/e})`)}draw(t){if(t.length!=this.drawn.length||t.some((t,e)=>{return i=t,s=this.drawn[e],!(i.constructor==s.constructor&&i.eq(s));var i,s})){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 t=e.nextSibling;e.remove(),e=t}this.drawn=t,j.safari&&j.safari_version>=26&&(this.dom.style.display=this.dom.firstChild?"":"none")}}destroy(){this.layer.destroy&&this.layer.destroy(this.dom,this.view),this.dom.remove()}}const ro=e.define();function lo(t){return[pe.define(e=>new no(e,t)),ro.of(t)]}const ao=e.define({combine:t=>g(t,{cursorBlinkRate:1200,drawRangeCursor:!0},{cursorBlinkRate:(t,e)=>Math.min(t,e),drawRangeCursor:(t,e)=>t||e})});function ho(t={}){return[ao.of(t),uo,po,go,ne.of(!0)]}function co(t){return t.startState.facet(ao)!=t.state.facet(ao)}const uo=lo({above:!0,markers(t){let{state:e}=t,i=e.facet(ao),s=[];for(let o of e.selection.ranges){let n=o==e.selection.main;if(o.empty||i.drawRangeCursor){let e=n?"cm-cursor cm-cursor-primary":"cm-cursor cm-cursor-secondary",i=o.empty?o:l.cursor(o.head,o.head>o.anchor?-1:1);for(let o of io.forRange(t,e,i))s.push(o)}}return s},update(t,e){t.transactions.some(t=>t.selection)&&(e.style.animationName="cm-blink"==e.style.animationName?"cm-blink2":"cm-blink");let i=co(t);return i&&fo(t.state,e),t.docChanged||t.selectionSet||i},mount(t,e){fo(e.state,t)},class:"cm-cursorLayer"});function fo(t,e){e.style.animationDuration=t.facet(ao).cursorBlinkRate+"ms"}const po=lo({above:!1,markers:t=>t.state.selection.ranges.map(e=>e.empty?[]:io.forRange(t,"cm-selectionBackground",e)).reduce((t,e)=>t.concat(e)),update:(t,e)=>t.docChanged||t.selectionSet||t.viewportChanged||co(t),class:"cm-selectionLayer"}),go=a.highest(zs.theme({".cm-line":{"& ::selection, &::selection":{backgroundColor:"transparent !important"},caretColor:"transparent !important"},".cm-content":{caretColor:"transparent !important","& :focus":{caretColor:"initial !important","&::selection, & ::selection":{backgroundColor:"Highlight !important"}}}})),mo=t.define({map:(t,e)=>null==t?null:e.mapPos(t)}),vo=f.define({create:()=>null,update:(t,e)=>(null!=t&&(t=e.changes.mapPos(t)),e.effects.reduce((t,e)=>e.is(mo)?e.value:t,t))}),wo=pe.fromClass(class{constructor(t){this.view=t,this.cursor=null,this.measureReq={read:this.readPos.bind(this),write:this.drawCursor.bind(this)}}update(t){var e;let i=t.state.field(vo);null==i?null!=this.cursor&&(null===(e=this.cursor)||void 0===e||e.remove(),this.cursor=null):(this.cursor||(this.cursor=this.view.scrollDOM.appendChild(document.createElement("div")),this.cursor.className="cm-dropCursor"),(t.startState.field(vo)!=i||t.docChanged||t.geometryChanged)&&this.view.requestMeasure(this.measureReq))}readPos(){let{view:t}=this,e=t.state.field(vo),i=null!=e&&t.coordsAtPos(e);if(!i)return null;let s=t.scrollDOM.getBoundingClientRect();return{left:i.left-s.left+t.scrollDOM.scrollLeft*t.scaleX,top:i.top-s.top+t.scrollDOM.scrollTop*t.scaleY,height:i.bottom-i.top}}drawCursor(t){if(this.cursor){let{scaleX:e,scaleY:i}=this.view;t?(this.cursor.style.left=t.left/e+"px",this.cursor.style.top=t.top/i+"px",this.cursor.style.height=t.height/i+"px"):this.cursor.style.left="-100000px"}}destroy(){this.cursor&&this.cursor.remove()}setDropPos(t){this.view.state.field(vo)!=t&&this.view.dispatch({effects:mo.of(t)})}},{eventObservers:{dragover(t){this.setDropPos(this.view.posAtCoords({x:t.clientX,y:t.clientY}))},dragleave(t){t.target!=this.view.contentDOM&&this.view.contentDOM.contains(t.relatedTarget)||this.setDropPos(null)},dragend(){this.setDropPos(null)},drop(){this.setDropPos(null)}}});function bo(){return[vo,wo]}function yo(t,e,i,s,o){e.lastIndex=0;for(let n,r=t.iterRange(i,s),l=i;!r.next().done;l+=r.value.length)if(!r.lineBreak)for(;n=e.exec(r.value);)o(l+n.index,n)}class xo{constructor(t){const{regexp:e,decoration:i,decorate:s,boundary:o,maxLength:n=1e3}=t;if(!e.global)throw new RangeError("The regular expression given to MatchDecorator should have its 'g' flag set");if(this.regexp=e,s)this.addMatch=(t,e,i,o)=>s(o,i,i+t[0].length,t,e);else if("function"==typeof i)this.addMatch=(t,e,s,o)=>{let n=i(t,e,s);n&&o(s,s+t[0].length,n)};else{if(!i)throw new RangeError("Either 'decorate' or 'decoration' should be provided to MatchDecorator");this.addMatch=(t,e,s,o)=>o(s,s+t[0].length,i)}this.boundary=o,this.maxLength=n}createDeco(t){let e=new h,i=e.add.bind(e);for(let{from:e,to:s}of function(t,e){let i=t.visibleRanges;if(1==i.length&&i[0].from==t.viewport.from&&i[0].to==t.viewport.to)return i;let s=[];for(let{from:o,to:n}of i)o=Math.max(t.state.doc.lineAt(o).from,o-e),n=Math.min(t.state.doc.lineAt(n).to,n+e),s.length&&s[s.length-1].to>=o?s[s.length-1].to=n:s.push({from:o,to:n});return s}(t,this.maxLength))yo(t.state.doc,this.regexp,e,s,(e,s)=>this.addMatch(s,t,e,i));return e.finish()}updateDeco(t,e){let i=1e9,s=-1;return t.docChanged&&t.changes.iterChanges((e,o,n,r)=>{r>=t.view.viewport.from&&n<=t.view.viewport.to&&(i=Math.min(n,i),s=Math.max(r,s))}),t.viewportMoved||s-i>1e3?this.createDeco(t.view):s>-1?this.updateRange(t.view,e.map(t.changes),i,s):e}updateRange(t,e,i,s){for(let o of t.visibleRanges){let n=Math.max(o.from,i),r=Math.min(o.to,s);if(r>=n){let i=t.state.doc.lineAt(n),s=i.to<r?t.state.doc.lineAt(r):i,l=Math.max(o.from,i.from),a=Math.min(o.to,s.to);if(this.boundary){for(;n>i.from;n--)if(this.boundary.test(i.text[n-1-i.from])){l=n;break}for(;r<s.to;r++)if(this.boundary.test(s.text[r-s.from])){a=r;break}}let h,c=[],d=(t,e,i)=>c.push(i.range(t,e));if(i==s)for(this.regexp.lastIndex=l-i.from;(h=this.regexp.exec(i.text))&&h.index<a-i.from;)this.addMatch(h,t,h.index+i.from,d);else yo(t.state.doc,this.regexp,l,a,(e,i)=>this.addMatch(i,t,e,d));e=e.update({filterFrom:l,filterTo:a,filter:(t,e)=>t<l||e>a,add:c})}}return e}}const So=null!=/x/.unicode?"gu":"g",Co=new RegExp("[\0-\b\n--Ÿ­؜​‎‏\u2028\u2029‭‮⁦⁧⁩\ufeff-]",So),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 ko=null;const Ao=e.define({combine(t){let e=g(t,{render:null,specialChars:Co,addSpecialChars:null});return(e.replaceTabs=!function(){var t;if(null==ko&&"undefined"!=typeof document&&document.body){let e=document.body.style;ko=null!=(null!==(t=e.tabSize)&&void 0!==t?t:e.MozTabSize)}return ko||!1}())&&(e.specialChars=new RegExp("\t|"+e.specialChars.source,So)),e.addSpecialChars&&(e.specialChars=new RegExp(e.specialChars.source+"|"+e.addSpecialChars.source,So)),e}});function To(t={}){return[Ao.of(t),Do||(Do=pe.fromClass(class{constructor(t){this.view=t,this.decorations=tt.none,this.decorationCache=Object.create(null),this.decorator=this.makeDecorator(t.state.facet(Ao)),this.decorations=this.decorator.createDeco(t)}makeDecorator(t){return new xo({regexp:t.specialChars,decoration:(e,i,s)=>{let{doc:o}=i.state,n=m(e[0],0);if(9==n){let t=o.lineAt(s),e=i.state.tabSize,n=v(t.text,e,s-t.from);return tt.replace({widget:new Lo((e-n%e)*this.view.defaultCharacterWidth/this.view.scaleX)})}return this.decorationCache[n]||(this.decorationCache[n]=tt.replace({widget:new Oo(t,n)}))},boundary:t.replaceTabs?void 0:/[^]/})}update(t){let e=t.state.facet(Ao);t.startState.facet(Ao)!=e?(this.decorator=this.makeDecorator(e),this.decorations=this.decorator.createDeco(t.view)):this.decorations=this.decorator.updateDeco(t,this.decorations)}},{decorations:t=>t.decorations}))]}let Do=null;class Oo extends J{constructor(t,e){super(),this.options=t,this.code=e}eq(t){return t.code==this.code}toDOM(t){let e=function(t){return t>=32?"•":10==t?"␤":String.fromCharCode(9216+t)}(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 o=document.createElement("span");return o.textContent=e,o.title=i,o.setAttribute("aria-label",i),o.className="cm-specialChar",o}ignoreEvent(){return!1}}class Lo extends J{constructor(t){super(),this.width=t}eq(t){return t.width==this.width}toDOM(){let t=document.createElement("span");return t.textContent="\t",t.className="cm-tab",t.style.width=this.width+"px",t}ignoreEvent(){return!1}}const Bo=pe.fromClass(class{constructor(){this.height=1e3,this.attrs={style:"padding-bottom: 1000px"}}update(t){let{view:e}=t,i=e.viewState.editorHeight-e.defaultLineHeight-e.documentPadding.top-.5;i>=0&&i!=this.height&&(this.height=i,this.attrs={style:`padding-bottom: ${i}px`})}});function Eo(){return Ho}const Ro=tt.line({class:"cm-activeLine"}),Ho=pe.fromClass(class{constructor(t){this.decorations=this.getDeco(t)}update(t){(t.docChanged||t.selectionSet)&&(this.decorations=this.getDeco(t.view))}getDeco(t){let e=-1,i=[];for(let s of t.state.selection.ranges){let o=t.lineBlockAt(s.head);o.from>e&&(i.push(Ro.range(o.from)),e=o.from)}return tt.set(i)}},{decorations:t=>t.decorations});class Wo extends J{constructor(t){super(),this.content=t}toDOM(t){let e=document.createElement("span");return e.className="cm-placeholder",e.style.pointerEvents="none",e.appendChild("string"==typeof this.content?document.createTextNode(this.content):"function"==typeof this.content?this.content(t):this.content.cloneNode(!0)),e.setAttribute("aria-hidden","true"),e}coordsAt(t){let e=t.firstChild?ct(t.firstChild):[];if(!e.length)return null;let i=window.getComputedStyle(t.parentNode),s=mt(e[0],"rtl"!=i.direction),o=parseInt(i.lineHeight);return s.bottom-s.top>1.5*o?{left:s.left,right:s.right,top:s.top,bottom:s.top+o}:s}ignoreEvent(){return!1}}const No=2e3;function Po(t,e){let i=t.posAtCoords({x:e.clientX,y:e.clientY},!1),s=t.state.doc.lineAt(i),o=i-s.from,n=o>No?-1:o==s.length?function(t,e){let i=t.coordsAtPos(t.viewport.from);return i?Math.round(Math.abs((i.left-e)/t.defaultCharacterWidth)):-1}(t,e.clientX):v(s.text,t.state.tabSize,i-s.from);return{line:s.number,col:n,off:o}}function Vo(t,e){let i=Po(t,e),s=t.state.selection;return i?{update(t){if(t.docChanged){let e=t.changes.mapPos(t.startState.doc.line(i.line).from),o=t.state.doc.lineAt(e);i={line:o.number,col:i.col,off:Math.min(i.off,o.length)},s=s.map(t.changes)}},get(e,o,n){let r=Po(t,e);if(!r)return s;let a=function(t,e,i){let s=Math.min(e.line,i.line),o=Math.max(e.line,i.line),n=[];if(e.off>No||i.off>No||e.col<0||i.col<0){let r=Math.min(e.off,i.off),a=Math.max(e.off,i.off);for(let e=s;e<=o;e++){let i=t.doc.line(e);i.length<=a&&n.push(l.range(i.from+r,i.to+a))}}else{let r=Math.min(e.col,i.col),a=Math.max(e.col,i.col);for(let e=s;e<=o;e++){let i=t.doc.line(e),s=b(i.text,r,t.tabSize,!0);if(s<0)n.push(l.cursor(i.to));else{let e=b(i.text,a,t.tabSize);n.push(l.range(i.from+s,i.from+e))}}}return n}(t.state,i,r);return a.length?n?l.create(a.concat(s.ranges)):l.create(a):s}}:null}function Fo(t){let e=(null==t?void 0:t.eventFilter)||(t=>t.altKey&&0==t.button);return zs.mouseSelectionStyle.of((t,i)=>e(i)?Vo(t,i):null)}const zo={Alt:[18,t=>!!t.altKey],Control:[17,t=>!!t.ctrlKey],Shift:[16,t=>!!t.shiftKey],Meta:[91,t=>!!t.metaKey]},Io={style:"cursor: crosshair"};function qo(t={}){let[e,i]=zo[t.key||"Alt"],s=pe.fromClass(class{constructor(t){this.view=t,this.isDown=!1}set(t){this.isDown!=t&&(this.isDown=t,this.view.update([]))}},{eventObservers:{keydown(t){this.set(t.keyCode==e||i(t))},keyup(t){t.keyCode!=e&&i(t)||this.set(!1)},mousemove(t){this.set(i(t))}}});return[s,zs.contentAttributes.of(t=>{var e;return(null===(e=t.plugin(s))||void 0===e?void 0:e.isDown)?Io:null})]}const Ko="-10000px";class _o{constructor(t,e,i,s){this.facet=e,this.createTooltipView=i,this.removeTooltipView=s,this.input=t.state.facet(e),this.tooltips=this.input.filter(t=>t);let o=null;this.tooltipViews=this.tooltips.map(t=>o=i(t,o))}update(t,e){var i;let s=t.state.facet(this.facet),o=s.filter(t=>t);if(s===this.input){for(let e of this.tooltipViews)e.update&&e.update(t);return!1}let n=[],r=e?[]:null;for(let i=0;i<o.length;i++){let s=o[i],l=-1;if(s){for(let t=0;t<this.tooltips.length;t++){let e=this.tooltips[t];e&&e.create==s.create&&(l=t)}if(l<0)n[i]=this.createTooltipView(s,i?n[i-1]:null),r&&(r[i]=!!s.above);else{let s=n[i]=this.tooltipViews[l];r&&(r[i]=e[l]),s.update&&s.update(t)}}}for(let t of this.tooltipViews)n.indexOf(t)<0&&(this.removeTooltipView(t),null===(i=t.destroy)||void 0===i||i.call(t));return e&&(r.forEach((t,i)=>e[i]=t),e.length=r.length),this.input=s,this.tooltips=o,this.tooltipViews=n,!0}}function Yo(t){let e=t.dom.ownerDocument.documentElement;return{top:0,left:0,bottom:e.clientHeight,right:e.clientWidth}}const jo=e.define({combine:t=>{var e,i,s;return{position:j.ios?"absolute":(null===(e=t.find(t=>t.position))||void 0===e?void 0:e.position)||"fixed",parent:(null===(i=t.find(t=>t.parent))||void 0===i?void 0:i.parent)||null,tooltipSpace:(null===(s=t.find(t=>t.tooltipSpace))||void 0===s?void 0:s.tooltipSpace)||Yo}}}),Xo=new WeakMap,Go=pe.fromClass(class{constructor(t){this.view=t,this.above=[],this.inView=!0,this.madeAbsolute=!1,this.lastTransaction=0,this.measureTimeout=-1;let e=t.state.facet(jo);this.position=e.position,this.parent=e.parent,this.classes=t.themeClasses,this.createContainer(),this.measureReq={read:this.readMeasure.bind(this),write:this.writeMeasure.bind(this),key:this},this.resizeObserver="function"==typeof ResizeObserver?new ResizeObserver(()=>this.measureSoon()):null,this.manager=new _o(t,Jo,(t,e)=>this.createTooltip(t,e),t=>{this.resizeObserver&&this.resizeObserver.unobserve(t.dom),t.dom.remove()}),this.above=this.manager.tooltips.map(t=>!!t.above),this.intersectionObserver="function"==typeof IntersectionObserver?new IntersectionObserver(t=>{Date.now()>this.lastTransaction-50&&t.length>0&&t[t.length-1].intersectionRatio<1&&this.measureSoon()},{threshold:[1]}):null,this.observeIntersection(),t.win.addEventListener("resize",this.measureSoon=this.measureSoon.bind(this)),this.maybeMeasure()}createContainer(){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 t of this.manager.tooltipViews)this.intersectionObserver.observe(t.dom)}}measureSoon(){this.measureTimeout<0&&(this.measureTimeout=setTimeout(()=>{this.measureTimeout=-1,this.maybeMeasure()},50))}update(t){t.transactions.length&&(this.lastTransaction=Date.now());let e=this.manager.update(t,this.above);e&&this.observeIntersection();let i=e||t.geometryChanged,s=t.state.facet(jo);if(s.position!=this.position&&!this.madeAbsolute){this.position=s.position;for(let t of this.manager.tooltipViews)t.dom.style.position=this.position;i=!0}if(s.parent!=this.parent){this.parent&&this.container.remove(),this.parent=s.parent,this.createContainer();for(let t of this.manager.tooltipViews)this.container.appendChild(t.dom);i=!0}else this.parent&&this.view.themeClasses!=this.classes&&(this.classes=this.container.className=this.view.themeClasses);i&&this.maybeMeasure()}createTooltip(t,e){let i=t.create(this.view),s=e?e.dom:null;if(i.dom.classList.add("cm-tooltip"),t.arrow&&!i.dom.querySelector(".cm-tooltip > .cm-tooltip-arrow")){let t=document.createElement("div");t.className="cm-tooltip-arrow",i.dom.appendChild(t)}return i.dom.style.position=this.position,i.dom.style.top=Ko,i.dom.style.left="0px",this.container.insertBefore(i.dom,s),i.mount&&i.mount(this.view),this.resizeObserver&&this.resizeObserver.observe(i.dom),i}destroy(){var t,e,i;this.view.win.removeEventListener("resize",this.measureSoon);for(let e of this.manager.tooltipViews)e.dom.remove(),null===(t=e.destroy)||void 0===t||t.call(e);this.parent&&this.container.remove(),null===(e=this.resizeObserver)||void 0===e||e.disconnect(),null===(i=this.intersectionObserver)||void 0===i||i.disconnect(),clearTimeout(this.measureTimeout)}readMeasure(){let t=1,e=1,i=!1;if("fixed"==this.position&&this.manager.tooltipViews.length){let{dom:t}=this.manager.tooltipViews[0];if(j.safari){let e=t.getBoundingClientRect();i=Math.abs(e.top+1e4)>1||Math.abs(e.left)>1}else i=!!t.offsetParent&&t.offsetParent!=this.container.ownerDocument.body}if(i||"absolute"==this.position)if(this.parent){let i=this.parent.getBoundingClientRect();i.width&&i.height&&(t=i.width/this.parent.offsetWidth,e=i.height/this.parent.offsetHeight)}else({scaleX:t,scaleY:e}=this.view.viewState);let s=this.view.scrollDOM.getBoundingClientRect(),o=ke(this.view);return{visible:{left:s.left+o.left,top:s.top+o.top,right:s.right-o.right,bottom:s.bottom-o.bottom},parent:this.parent?this.container.getBoundingClientRect():this.view.dom.getBoundingClientRect(),pos:this.manager.tooltips.map((t,e)=>{let i=this.manager.tooltipViews[e];return i.getCoords?i.getCoords(t.pos):this.view.coordsAtPos(t.pos)}),size:this.manager.tooltipViews.map(({dom:t})=>t.getBoundingClientRect()),space:this.view.state.facet(jo).tooltipSpace(this.view),scaleX:t,scaleY:e,makeAbsolute:i}}writeMeasure(t){var e;if(t.makeAbsolute){this.madeAbsolute=!0,this.position="absolute";for(let t of this.manager.tooltipViews)t.dom.style.position="absolute"}let{visible:i,space:s,scaleX:o,scaleY:n}=t,r=[];for(let l=0;l<this.manager.tooltips.length;l++){let a=this.manager.tooltips[l],h=this.manager.tooltipViews[l],{dom:c}=h,d=t.pos[l],u=t.size[l];if(!d||!1!==a.clip&&(d.bottom<=Math.max(i.top,s.top)||d.top>=Math.min(i.bottom,s.bottom)||d.right<Math.max(i.left,s.left)-.1||d.left>Math.min(i.right,s.right)+.1)){c.style.top=Ko;continue}let f=a.arrow?h.dom.querySelector(".cm-tooltip-arrow"):null,p=f?7:0,g=u.right-u.left,m=null!==(e=Xo.get(h))&&void 0!==e?e:u.bottom-u.top,v=h.offset||Qo,w=this.view.textDirection==Ot.LTR,b=u.width>s.right-s.left?w?s.left:s.right-u.width:w?Math.max(s.left,Math.min(d.left-(f?14:0)+v.x,s.right-g)):Math.min(Math.max(s.left,d.left-g+(f?14:0)-v.x),s.right-g),y=this.above[l];!a.strictSide&&(y?d.top-m-p-v.y<s.top:d.bottom+m+p+v.y>s.bottom)&&y==s.bottom-d.bottom>d.top-s.top&&(y=this.above[l]=!y);let x=(y?d.top-s.top:s.bottom-d.bottom)-p;if(x<m&&!1!==h.resize){if(x<this.view.defaultLineHeight){c.style.top=Ko;continue}Xo.set(h,m),c.style.height=(m=x)/n+"px"}else c.style.height&&(c.style.height="");let S=y?d.top-m-p-v.y:d.bottom+p+v.y,C=b+g;if(!0!==h.overlap)for(let t of r)t.left<C&&t.right>b&&t.top<S+m&&t.bottom>S&&(S=y?t.top-m-2-p:t.bottom+p+2);if("absolute"==this.position?(c.style.top=(S-t.parent.top)/n+"px",Uo(c,(b-t.parent.left)/o)):(c.style.top=S/n+"px",Uo(c,b/o)),f){let t=d.left+(w?v.x:-v.x)-(b+14-7);f.style.left=t/o+"px"}!0!==h.overlap&&r.push({left:b,top:S,right:C,bottom:S+m}),c.classList.toggle("cm-tooltip-above",y),c.classList.toggle("cm-tooltip-below",!y),h.positioned&&h.positioned(t.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 t of this.manager.tooltipViews)t.dom.style.top=Ko}},{eventObservers:{scroll(){this.maybeMeasure()}}});function Uo(t,e){let i=parseInt(t.style.left,10);(isNaN(i)||Math.abs(e-i)>1)&&(t.style.left=e+"px")}const $o=zs.baseTheme({".cm-tooltip":{zIndex:500,boxSizing:"border-box"},"&light .cm-tooltip":{border:"1px solid #bbb",backgroundColor:"#f5f5f5"},"&light .cm-tooltip-section:not(:first-child)":{borderTop:"1px solid #bbb"},"&dark .cm-tooltip":{backgroundColor:"#333338",color:"white"},".cm-tooltip-arrow":{height:"7px",width:"14px",position:"absolute",zIndex:-1,overflow:"hidden","&:before, &:after":{content:"''",position:"absolute",width:0,height:0,borderLeft:"7px solid transparent",borderRight:"7px solid transparent"},".cm-tooltip-above &":{bottom:"-7px","&:before":{borderTop:"7px solid #bbb"},"&:after":{borderTop:"7px solid #f5f5f5",bottom:"1px"}},".cm-tooltip-below &":{top:"-7px","&:before":{borderBottom:"7px solid #bbb"},"&:after":{borderBottom:"7px solid #f5f5f5",top:"1px"}}},"&dark .cm-tooltip .cm-tooltip-arrow":{"&:before":{borderTopColor:"#333338",borderBottomColor:"#333338"},"&:after":{borderTopColor:"transparent",borderBottomColor:"transparent"}}}),Qo={x:0,y:0},Jo=e.define({enables:[Go,$o]}),Zo=e.define({combine:t=>t.reduce((t,e)=>t.concat(e),[])});class tn{static create(t){return new tn(t)}constructor(t){this.view=t,this.mounted=!1,this.dom=document.createElement("div"),this.dom.classList.add("cm-tooltip-hover"),this.manager=new _o(t,Zo,(t,e)=>this.createHostedView(t,e),t=>t.dom.remove())}createHostedView(t,e){let i=t.create(this.view);return i.dom.classList.add("cm-tooltip-section"),this.dom.insertBefore(i.dom,e?e.dom.nextSibling:this.dom.firstChild),this.mounted&&i.mount&&i.mount(this.view),i}mount(t){for(let e of this.manager.tooltipViews)e.mount&&e.mount(t);this.mounted=!0}positioned(t){for(let e of this.manager.tooltipViews)e.positioned&&e.positioned(t)}update(t){this.manager.update(t)}destroy(){var t;for(let e of this.manager.tooltipViews)null===(t=e.destroy)||void 0===t||t.call(e)}passProp(t){let e;for(let i of this.manager.tooltipViews){let s=i[t];if(void 0!==s)if(void 0===e)e=s;else if(e!==s)return}return e}get offset(){return this.passProp("offset")}get getCoords(){return this.passProp("getCoords")}get overlap(){return this.passProp("overlap")}get resize(){return this.passProp("resize")}}const en=Jo.compute([Zo],t=>{let e=t.facet(Zo);return 0===e.length?null:{pos:Math.min(...e.map(t=>t.pos)),end:Math.max(...e.map(t=>{var e;return null!==(e=t.end)&&void 0!==e?e:t.pos})),create:tn.create,above:e[0].above,arrow:e.some(t=>t.arrow)}});class sn{constructor(t,e,i,s,o){this.view=t,this.source=e,this.field=i,this.setHover=s,this.hoverTime=o,this.hoverTimeout=-1,this.restartTimeout=-1,this.pending=null,this.lastMove={x:0,y:0,target:t.dom,time:0},this.checkHover=this.checkHover.bind(this),t.dom.addEventListener("mouseleave",this.mouseleave=this.mouseleave.bind(this)),t.dom.addEventListener("mousemove",this.mousemove=this.mousemove.bind(this))}update(){this.pending&&(this.pending=null,clearTimeout(this.restartTimeout),this.restartTimeout=setTimeout(()=>this.startHover(),20))}get active(){return this.view.state.field(this.field)}checkHover(){if(this.hoverTimeout=-1,this.active.length)return;let t=Date.now()-this.lastMove.time;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.tile.nearest(e.target);if(!i)return;let s,o=1;if(i.isWidget())s=i.posAtStart;else{if(s=t.posAtCoords(e),null==s)return;let i=t.coordsAtPos(s);if(!i||e.y<i.top||e.y>i.bottom||e.x<i.left-t.defaultCharacterWidth||e.x>i.right+t.defaultCharacterWidth)return;let n=t.bidiSpans(t.state.doc.lineAt(s)).find(t=>t.from<=s&&t.to>=s),r=n&&n.dir==Ot.RTL?-1:1;o=e.x<i.left?-r:r}let n=this.source(t,s,o);if(null==n?void 0:n.then){let e=this.pending={pos:s};n.then(i=>{this.pending==e&&(this.pending=null,!i||Array.isArray(i)&&!i.length||t.dispatch({effects:this.setHover.of(Array.isArray(i)?i:[i])}))},e=>ce(t.state,e,"hover tooltip"))}else!n||Array.isArray(n)&&!n.length||t.dispatch({effects:this.setHover.of(Array.isArray(n)?n:[n])})}get tooltip(){let t=this.view.plugin(Go),e=t?t.manager.tooltips.findIndex(t=>t.create==tn.create):-1;return e>-1?t.manager.tooltipViews[e]:null}mousemove(t){var e,i;this.lastMove={x:t.clientX,y:t.clientY,target:t.target,time:Date.now()},this.hoverTimeout<0&&(this.hoverTimeout=setTimeout(this.checkHover,this.hoverTime));let{active:s,tooltip:o}=this;if(s.length&&o&&!function(t,e){let i,{left:s,right:o,top:n,bottom:r}=t.getBoundingClientRect();if(i=t.querySelector(".cm-tooltip-arrow")){let t=i.getBoundingClientRect();n=Math.min(t.top,n),r=Math.max(t.bottom,r)}return e.clientX>=s-on&&e.clientX<=o+on&&e.clientY>=n-on&&e.clientY<=r+on}(o.dom,t)||this.pending){let{pos:o}=s[0]||this.pending,n=null!==(i=null===(e=s[0])||void 0===e?void 0:e.end)&&void 0!==i?i:o;(o==n?this.view.posAtCoords(this.lastMove)==o:function(t,e,i,s,o){let n=t.scrollDOM.getBoundingClientRect(),r=t.documentTop+t.documentPadding.top+t.contentHeight;if(n.left>s||n.right<s||n.top>o||Math.min(n.bottom,r)<o)return!1;let l=t.posAtCoords({x:s,y:o},!1);return l>=e&&l<=i}(this.view,o,n,t.clientX,t.clientY))||(this.view.dispatch({effects:this.setHover.of([])}),this.pending=null)}}mouseleave(t){clearTimeout(this.hoverTimeout),this.hoverTimeout=-1;let{active:e}=this;if(e.length){let{tooltip:e}=this;e&&e.dom.contains(t.relatedTarget)?this.watchTooltipLeave(e.dom):this.view.dispatch({effects:this.setHover.of([])})}}watchTooltipLeave(t){let e=i=>{t.removeEventListener("mouseleave",e),this.active.length&&!this.view.dom.contains(i.relatedTarget)&&this.view.dispatch({effects:this.setHover.of([])})};t.addEventListener("mouseleave",e)}destroy(){clearTimeout(this.hoverTimeout),clearTimeout(this.restartTimeout),this.view.dom.removeEventListener("mouseleave",this.mouseleave),this.view.dom.removeEventListener("mousemove",this.mousemove)}}const on=4;function nn(e,i={}){let s=t.define(),o=f.define({create:()=>[],update(t,e){if(t.length&&(i.hideOnChange&&(e.docChanged||e.selection)?t=[]:i.hideOn&&(t=t.filter(t=>!i.hideOn(e,t))),e.docChanged)){let i=[];for(let s of t){let t=e.changes.mapPos(s.pos,-1,p.TrackDel);if(null!=t){let o=Object.assign(Object.create(null),s);o.pos=t,null!=o.end&&(o.end=e.changes.mapPos(o.end)),i.push(o)}}t=i}for(let i of e.effects)i.is(s)&&(t=i.value),i.is(ln)&&(t=[]);return t},provide:t=>Zo.from(t)});return{active:o,extension:[o,pe.define(t=>new sn(t,e,o,s,i.hoverTime||300)),en]}}function rn(t,e){let i=t.plugin(Go);if(!i)return null;let s=i.manager.tooltips.indexOf(e);return s<0?null:i.manager.tooltipViews[s]}const ln=t.define(),an=ln.of(null);const hn=e.define({combine(t){let e,i;for(let s of t)e=e||s.topContainer,i=i||s.bottomContainer;return{topContainer:e,bottomContainer:i}}});function cn(t,e){let i=t.plugin(dn),s=i?i.specs.indexOf(e):-1;return s>-1?i.panels[s]:null}const dn=pe.fromClass(class{constructor(t){this.input=t.state.facet(pn),this.specs=this.input.filter(t=>t),this.panels=this.specs.map(e=>e(t));let e=t.state.facet(hn);this.top=new un(t,!0,e.topContainer),this.bottom=new un(t,!1,e.bottomContainer),this.top.sync(this.panels.filter(t=>t.top)),this.bottom.sync(this.panels.filter(t=>!t.top));for(let t of this.panels)t.dom.classList.add("cm-panel"),t.mount&&t.mount()}update(t){let e=t.state.facet(hn);this.top.container!=e.topContainer&&(this.top.sync([]),this.top=new un(t.view,!0,e.topContainer)),this.bottom.container!=e.bottomContainer&&(this.bottom.sync([]),this.bottom=new un(t.view,!1,e.bottomContainer)),this.top.syncClasses(),this.bottom.syncClasses();let i=t.state.facet(pn);if(i!=this.input){let e=i.filter(t=>t),s=[],o=[],n=[],r=[];for(let i of e){let e,l=this.specs.indexOf(i);l<0?(e=i(t.view),r.push(e)):(e=this.panels[l],e.update&&e.update(t)),s.push(e),(e.top?o:n).push(e)}this.specs=e,this.panels=s,this.top.sync(o),this.bottom.sync(n);for(let t of r)t.dom.classList.add("cm-panel"),t.mount&&t.mount()}else for(let e of this.panels)e.update&&e.update(t)}destroy(){this.top.sync([]),this.bottom.sync([])}},{provide:t=>zs.scrollMargins.of(e=>{let i=e.plugin(t);return i&&{top:i.top.scrollMargin(),bottom:i.bottom.scrollMargin()}})});class un{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(0==this.panels.length)return void(this.dom&&(this.dom.remove(),this.dom=void 0));if(!this.dom){this.dom=document.createElement("div"),this.dom.className=this.top?"cm-panels cm-panels-top":"cm-panels cm-panels-bottom",this.dom.style[this.top?"top":"bottom"]="0";let t=this.container||this.view.dom;t.insertBefore(this.dom,this.top?t.firstChild:null)}let t=this.dom.firstChild;for(let e of this.panels)if(e.dom.parentNode==this.dom){for(;t!=e.dom;)t=fn(t);t=t.nextSibling}else this.dom.insertBefore(e.dom,t);for(;t;)t=fn(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 fn(t){let e=t.nextSibling;return t.remove(),e}const pn=e.define({enables:dn});const gn=f.define({create:()=>[],update(t,e){for(let i of e.effects)i.is(mn)?t=[i.value].concat(t):i.is(vn)&&(t=t.filter(t=>t!=i.value));return t},provide:t=>pn.computeN([t],e=>e.field(t))}),mn=t.define(),vn=t.define();class wn extends i{compare(t){return this==t||this.constructor==t.constructor&&this.eq(t)}eq(t){return!1}destroy(t){}}wn.prototype.elementClass="",wn.prototype.toDOM=void 0,wn.prototype.mapMode=p.TrackBefore,wn.prototype.startSide=wn.prototype.endSide=-1,wn.prototype.point=!0;const bn=e.define(),yn=e.define(),xn={class:"",renderEmptyElements:!1,elementStyle:"",markers:()=>s.empty,lineMarker:()=>null,widgetMarker:()=>null,lineMarkerChange:null,initialSpacer:null,updateSpacer:null,domEventHandlers:{},side:"before"},Sn=e.define();function Cn(t){return[kn(),Sn.of({...xn,...t})]}const Mn=e.define({combine:t=>t.some(t=>t)});function kn(t){let e=[An];return t&&!1===t.fixed&&e.push(Mn.of(!0)),e}const An=pe.fromClass(class{constructor(t){this.view=t,this.domAfter=null,this.prevViewport=t.viewport,this.dom=document.createElement("div"),this.dom.className="cm-gutters cm-gutters-before",this.dom.setAttribute("aria-hidden","true"),this.dom.style.minHeight=this.view.contentHeight/this.view.scaleY+"px",this.gutters=t.state.facet(Sn).map(e=>new Ln(t,e)),this.fixed=!t.state.facet(Mn);for(let t of this.gutters)"after"==t.config.side?this.getDOMAfter().appendChild(t.dom):this.dom.appendChild(t.dom);this.fixed&&(this.dom.style.position="sticky"),this.syncGutters(!1),t.scrollDOM.insertBefore(this.dom,t.contentDOM)}getDOMAfter(){return this.domAfter||(this.domAfter=document.createElement("div"),this.domAfter.className="cm-gutters cm-gutters-after",this.domAfter.setAttribute("aria-hidden","true"),this.domAfter.style.minHeight=this.view.contentHeight/this.view.scaleY+"px",this.domAfter.style.position=this.fixed?"sticky":"",this.view.scrollDOM.appendChild(this.domAfter)),this.domAfter}update(t){if(this.updateGutters(t)){let e=this.prevViewport,i=t.view.viewport,s=Math.min(e.to,i.to)-Math.max(e.from,i.from);this.syncGutters(s<.8*(i.to-i.from))}if(t.geometryChanged){let t=this.view.contentHeight/this.view.scaleY+"px";this.dom.style.minHeight=t,this.domAfter&&(this.domAfter.style.minHeight=t)}this.view.state.facet(Mn)!=!this.fixed&&(this.fixed=!this.fixed,this.dom.style.position=this.fixed?"sticky":"",this.domAfter&&(this.domAfter.style.position=this.fixed?"sticky":"")),this.prevViewport=t.view.viewport}syncGutters(t){let e=this.dom.nextSibling;t&&(this.dom.remove(),this.domAfter&&this.domAfter.remove());let i=s.iter(this.view.state.facet(bn),this.view.viewport.from),o=[],n=this.gutters.map(t=>new On(t,this.view.viewport,-this.view.documentPadding.top));for(let t of this.view.viewportLineBlocks)if(o.length&&(o=[]),Array.isArray(t.type)){let e=!0;for(let s of t.type)if(s.type==Z.Text&&e){Dn(i,o,s.from);for(let t of n)t.line(this.view,s,o);e=!1}else if(s.widget)for(let t of n)t.widget(this.view,s)}else if(t.type==Z.Text){Dn(i,o,t.from);for(let e of n)e.line(this.view,t,o)}else if(t.widget)for(let e of n)e.widget(this.view,t);for(let t of n)t.finish();t&&(this.view.scrollDOM.insertBefore(this.dom,e),this.domAfter&&this.view.scrollDOM.appendChild(this.domAfter))}updateGutters(t){let e=t.startState.facet(Sn),i=t.state.facet(Sn),o=t.docChanged||t.heightChanged||t.viewportChanged||!s.eq(t.startState.facet(bn),t.state.facet(bn),t.view.viewport.from,t.view.viewport.to);if(e==i)for(let e of this.gutters)e.update(t)&&(o=!0);else{o=!0;let s=[];for(let o of i){let i=e.indexOf(o);i<0?s.push(new Ln(this.view,o)):(this.gutters[i].update(t),s.push(this.gutters[i]))}for(let t of this.gutters)t.dom.remove(),s.indexOf(t)<0&&t.destroy();for(let t of s)"after"==t.config.side?this.getDOMAfter().appendChild(t.dom):this.dom.appendChild(t.dom);this.gutters=s}return o}destroy(){for(let t of this.gutters)t.destroy();this.dom.remove(),this.domAfter&&this.domAfter.remove()}},{provide:t=>zs.scrollMargins.of(e=>{let i=e.plugin(t);if(!i||0==i.gutters.length||!i.fixed)return null;let s=i.dom.offsetWidth*e.scaleX,o=i.domAfter?i.domAfter.offsetWidth*e.scaleX:0;return e.textDirection==Ot.LTR?{left:s,right:o}:{right:s,left:o}})});function Tn(t){return Array.isArray(t)?t:[t]}function Dn(t,e,i){for(;t.value&&t.from<=i;)t.from==i&&e.push(t.value),t.next()}class On{constructor(t,e,i){this.gutter=t,this.height=i,this.i=0,this.cursor=s.iter(t.markers,e.from)}addElement(t,e,i){let{gutter:s}=this,o=(e.top-this.height)/t.scaleY,n=e.height/t.scaleY;if(this.i==s.elements.length){let e=new Bn(t,n,o,i);s.elements.push(e),s.dom.appendChild(e.dom)}else s.elements[this.i].update(t,n,o,i);this.height=e.bottom,this.i++}line(t,e,i){let s=[];Dn(this.cursor,s,e.from),i.length&&(s=s.concat(i));let o=this.gutter.config.lineMarker(t,e,s);o&&s.unshift(o);let n=this.gutter;(0!=s.length||n.config.renderEmptyElements)&&this.addElement(t,e,s)}widget(t,e){let i=this.gutter.config.widgetMarker(t,e.widget,e),s=i?[i]:null;for(let i of t.state.facet(yn)){let o=i(t,e.widget,e);o&&(s||(s=[])).push(o)}s&&this.addElement(t,e,s)}finish(){let t=this.gutter;for(;t.elements.length>this.i;){let e=t.elements.pop();t.dom.removeChild(e.dom),e.destroy()}}}class Ln{constructor(t,e){this.view=t,this.config=e,this.elements=[],this.spacer=null,this.dom=document.createElement("div"),this.dom.className="cm-gutter"+(this.config.class?" "+this.config.class:"");for(let i in e.domEventHandlers)this.dom.addEventListener(i,s=>{let o,n=s.target;if(n!=this.dom&&this.dom.contains(n)){for(;n.parentNode!=this.dom;)n=n.parentNode;let t=n.getBoundingClientRect();o=(t.top+t.bottom)/2}else o=s.clientY;let r=t.lineBlockAtHeight(o-t.documentTop);e.domEventHandlers[i](t,r,s)&&s.preventDefault()});this.markers=Tn(e.markers(t)),e.initialSpacer&&(this.spacer=new Bn(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=Tn(this.config.markers(t.view)),this.spacer&&this.config.updateSpacer){let e=this.config.updateSpacer(this.spacer.markers[0],t);e!=this.spacer.markers[0]&&this.spacer.update(t.view,0,0,[e])}let i=t.view.viewport;return!s.eq(this.markers,e,i.from,i.to)||!!this.config.lineMarkerChange&&this.config.lineMarkerChange(t)}destroy(){for(let t of this.elements)t.destroy()}}class Bn{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.height=e,this.dom.style.height=e+"px"),this.above!=i&&(this.dom.style.marginTop=(this.above=i)?i+"px":""),function(t,e){if(t.length!=e.length)return!1;for(let i=0;i<t.length;i++)if(!t[i].compare(e[i]))return!1;return!0}(this.markers,s)||this.setMarkers(t,s)}setMarkers(t,e){let i="cm-gutterElement",s=this.dom.firstChild;for(let o=0,n=0;;){let r=n,l=o<e.length?e[o++]:null,a=!1;if(l){let t=l.elementClass;t&&(i+=" "+t);for(let t=n;t<this.markers.length;t++)if(this.markers[t].compare(l)){r=t,a=!0;break}}else r=this.markers.length;for(;n<r;){let t=this.markers[n++];if(t.toDOM){t.destroy(s);let e=s.nextSibling;s.remove(),s=e}}if(!l)break;l.toDOM&&(a?s=s.nextSibling:this.dom.insertBefore(l.toDOM(t),s)),a&&n++}this.dom.className=i,this.markers=e}destroy(){this.setMarkers(null,[])}}const En=e.define(),Rn=e.define(),Hn=e.define({combine:t=>g(t,{formatNumber:String,domEventHandlers:{}},{domEventHandlers(t,e){let i=Object.assign({},t);for(let t in e){let s=i[t],o=e[t];i[t]=s?(t,e,i)=>s(t,e,i)||o(t,e,i):o}return i}})});class Wn extends wn{constructor(t){super(),this.number=t}eq(t){return this.number==t.number}toDOM(){return document.createTextNode(this.number)}}function Nn(t,e){return t.state.facet(Hn).formatNumber(e,t.state)}const Pn=Sn.compute([Hn],t=>({class:"cm-lineNumbers",renderEmptyElements:!1,markers:t=>t.state.facet(En),lineMarker:(t,e,i)=>i.some(t=>t.toDOM)?null:new Wn(Nn(t,t.state.doc.lineAt(e.from).number)),widgetMarker:(t,e,i)=>{for(let s of t.state.facet(Rn)){let o=s(t,e,i);if(o)return o}return null},lineMarkerChange:t=>t.startState.facet(Hn)!=t.state.facet(Hn),initialSpacer:t=>new Wn(Nn(t,Fn(t.state.doc.lines))),updateSpacer(t,e){let i=Nn(e.view,Fn(e.view.state.doc.lines));return i==t.number?t:new Wn(i)},domEventHandlers:t.facet(Hn).domEventHandlers,side:"before"}));function Vn(t={}){return[Hn.of(t),kn(),Pn]}function Fn(t){let e=9;for(;e<t;)e=10*e+9;return e}const zn=new class extends wn{constructor(){super(...arguments),this.elementClass="cm-activeLineGutter"}},In=bn.compute(["selection"],t=>{let e=[],i=-1;for(let s of t.selection.ranges){let o=t.doc.lineAt(s.head).from;o>i&&(i=o,e.push(zn.range(o)))}return s.of(e)});function qn(){return In}function Kn(t){return pe.define(e=>({decorations:t.createDeco(e),update(e){this.decorations=t.updateDeco(e,this.decorations)}}),{decorations:t=>t.decorations})}const _n=tt.mark({class:"cm-highlightTab"}),Yn=tt.mark({class:"cm-highlightSpace"}),jn=Kn(new xo({regexp:/\t| /g,decoration:t=>"\t"==t[0]?_n:Yn,boundary:/\S/}));const Xn=Kn(new xo({regexp:/\s+$/g,decoration:tt.mark({class:"cm-trailingSpace"})}));const Gn={HeightMap:os,HeightOracle:Zi,MeasuredHeights:ts,QueryType:is,ChangedRange:Te,computeOrder:_t,moveVisually:Xt,clearHeightChangeFlag:Ji,getHeightChangeFlag:()=>Qi};var Un=Object.freeze({__proto__:null,BidiSpan:Ft,BlockInfo:es,get BlockType(){return Z},BlockWrapper:rt,Decoration:tt,get Direction(){return Ot},EditorView:zs,GutterMarker:wn,MatchDecorator:xo,RectangleMarker:io,ViewPlugin:pe,ViewUpdate:De,WidgetType:J,__test:Gn,closeHoverTooltips:an,crosshairCursor:qo,drawSelection:ho,dropCursor:bo,getDialog:function(t,e){let i=t.state.field(gn,!1)||[];for(let s of i){let i=cn(t,s);if(i&&i.dom.classList.contains(e))return i}return null},getDrawSelectionConfig:function(t){return t.facet(ao)},getPanel:cn,getTooltip:rn,gutter:Cn,gutterLineClass:bn,gutterWidgetClass:yn,gutters:kn,hasHoverTooltips:function(t){return t.facet(Zo).some(t=>t)},highlightActiveLine:Eo,highlightActiveLineGutter:qn,highlightSpecialChars:To,highlightTrailingWhitespace:function(){return Xn},highlightWhitespace:function(){return jn},hoverTooltip:nn,keymap:Gs,layer:lo,lineNumberMarkers:En,lineNumberWidgetMarker:Rn,lineNumbers:Vn,logException:ce,panels:function(t){return t?[hn.of(t)]:[]},placeholder:function(t){let e=pe.fromClass(class{constructor(e){this.view=e,this.placeholder=t?tt.set([tt.widget({widget:new Wo(t),side:1}).range(0)]):tt.none}get decorations(){return this.view.state.doc.length?tt.none:this.placeholder}},{decorations:t=>t.decorations});return"string"==typeof t?[e,zs.contentAttributes.of({"aria-placeholder":t})]:e},rectangularSelection:Fo,repositionTooltips:function(t){let e=t.plugin(Go);e&&e.maybeMeasure()},runScopeHandlers:Qs,scrollPastEnd:function(){return[Bo,ve.of(t=>{var e;return(null===(e=t.plugin(Bo))||void 0===e?void 0:e.attrs)||null})]},showDialog:function(e,i){let s,o=new Promise(t=>s=t),n=t=>function(t,e,i){let s=e.content?e.content(t,()=>r(null)):null;if(!s){if(s=R("form"),e.input){let t=R("input",e.input);/^(text|password|number|email|tel|url)$/.test(t.type)&&t.classList.add("cm-textfield"),t.name||(t.name="input"),s.appendChild(R("label",(e.label||"")+": ",t))}else s.appendChild(document.createTextNode(e.label||""));s.appendChild(document.createTextNode(" ")),s.appendChild(R("button",{class:"cm-button",type:"submit"},e.submitLabel||"OK"))}let o="FORM"==s.nodeName?[s]:s.querySelectorAll("form");for(let t=0;t<o.length;t++){let e=o[t];e.addEventListener("keydown",t=>{27==t.keyCode?(t.preventDefault(),r(null)):13==t.keyCode&&(t.preventDefault(),r(e))}),e.addEventListener("submit",t=>{t.preventDefault(),r(e)})}let n=R("div",s,R("button",{onclick:()=>r(null),"aria-label":t.state.phrase("close"),class:"cm-dialog-close",type:"button"},["×"]));e.class&&(n.className=e.class);function r(e){n.contains(n.ownerDocument.activeElement)&&t.focus(),i(e)}return n.classList.add("cm-dialog"),{dom:n,top:e.top,mount:()=>{if(e.focus){let t;t="string"==typeof e.focus?s.querySelector(e.focus):s.querySelector("input")||s.querySelector("button"),t&&"select"in t?t.select():t&&"focus"in t&&t.focus()}}}}(t,i,s);e.state.field(gn,!1)?e.dispatch({effects:mn.of(n)}):e.dispatch({effects:t.appendConfig.of(gn.init(()=>[n]))});let r=vn.of(n);return{close:r,result:o.then(t=>((e.win.queueMicrotask||(t=>e.win.setTimeout(t,10)))(()=>{e.state.field(gn).indexOf(n)>-1&&e.dispatch({effects:r})}),t))}},showPanel:pn,showTooltip:Jo,tooltips:function(t={}){return jo.of(t)}});export{Ot as D,zs as E,wn as G,M as S,pe as V,J as W,tt as a,cn as b,pn as c,R as d,Vn as e,qn as f,rn as g,nn as h,To as i,ho as j,Gs as k,ce as l,bo as m,Fo as n,qo as o,Eo as p,Cn as q,Qs as r,Jo as s,Un as t};
2
- //# sourceMappingURL=codemirror_view-FN7LalDk.js.map
1
+ import{RangeValue as t,RangeSet as e,EditorState as i,Transaction as s,EditorSelection as o,Prec as n,RangeSetBuilder as r,ChangeSet as l,findClusterBreak as a,Text as h,Facet as c,StateEffect as d,StateField as u,MapMode as f,Annotation as p,combineConfig as g,codePointAt as m,countColumn as v,codePointSize as w,findColumn as b,CharCategory as y}from"./codemirror_state-BNbbkoNK.js";const x="undefined"==typeof Symbol?"__ͼ":Symbol.for("ͼ"),S="undefined"==typeof Symbol?"__styleSet"+Math.floor(1e8*Math.random()):Symbol("styleSet"),C="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:{};class M{constructor(t,e){this.rules=[];let{finish:i}=e||{};function s(t){return/^@/.test(t)?[t]:t.split(/,\s*/)}function o(t,e,n,r){let l=[],a=/^@(\w+)\b/.exec(t[0]),h=a&&"keyframes"==a[1];if(a&&null==e)return n.push(t[0]+";");for(let i in e){let r=e[i];if(/&/.test(i))o(i.split(/,\s*/).map(e=>t.map(t=>e.replace(/&/,t))).reduce((t,e)=>t.concat(e)),r,n);else if(r&&"object"==typeof r){if(!a)throw new RangeError("The value of a property ("+i+") should be a primitive value.");o(s(i),r,l,h)}else null!=r&&l.push(i.replace(/_.*/,"").replace(/[A-Z]/g,t=>"-"+t.toLowerCase())+": "+r+";")}(l.length||h)&&n.push((!i||a||r?t:t.map(i)).join(", ")+" {"+l.join(" ")+"}")}for(let e in t)o(s(e),t[e],this.rules)}getRules(){return this.rules.join("\n")}static newName(){let t=C[x]||1;return C[x]=t+1,"ͼ"+t.toString(36)}static mount(t,e,i){let s=t[S],o=i&&i.nonce;s?o&&s.setNonce(o):s=new A(t,o),s.mount(Array.isArray(e)?e:[e],t)}}let k=new Map;class A{constructor(t,e){let i=t.ownerDocument||t,s=i.defaultView;if(!t.head&&t.adoptedStyleSheets&&s.CSSStyleSheet){let e=k.get(i);if(e)return t[S]=e;this.sheet=new s.CSSStyleSheet,k.set(i,this)}else this.styleTag=i.createElement("style"),e&&this.styleTag.setAttribute("nonce",e);this.modules=[],t[S]=this}mount(t,e){let i=this.sheet,s=0,o=0;for(let e=0;e<t.length;e++){let n=t[e],r=this.modules.indexOf(n);if(r<o&&r>-1&&(this.modules.splice(r,1),o--,r=-1),-1==r){if(this.modules.splice(o++,0,n),i)for(let t=0;t<n.rules.length;t++)i.insertRule(n.rules[t],s++)}else{for(;o<r;)s+=this.modules[o++].rules.length;s+=n.rules.length,o++}}if(i)e.adoptedStyleSheets.indexOf(this.sheet)<0&&(e.adoptedStyleSheets=[this.sheet,...e.adoptedStyleSheets]);else{let t="";for(let e=0;e<this.modules.length;e++)t+=this.modules[e].getRules()+"\n";this.styleTag.textContent=t;let i=e.head||e;this.styleTag.parentNode!=i&&i.insertBefore(this.styleTag,i.firstChild)}}setNonce(t){this.styleTag&&this.styleTag.getAttribute("nonce")!=t&&this.styleTag.setAttribute("nonce",t)}}for(var T={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:"'"},D={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},O="undefined"!=typeof navigator&&/Mac/.test(navigator.platform),L="undefined"!=typeof navigator&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent),B=0;B<10;B++)T[48+B]=T[96+B]=String(B);for(B=1;B<=24;B++)T[B+111]="F"+B;for(B=65;B<=90;B++)T[B]=String.fromCharCode(B+32),D[B]=String.fromCharCode(B);for(var E in T)D.hasOwnProperty(E)||(D[E]=T[E]);function R(){var t=arguments[0];"string"==typeof t&&(t=document.createElement(t));var e=1,i=arguments[1];if(i&&"object"==typeof i&&null==i.nodeType&&!Array.isArray(i)){for(var s in i)if(Object.prototype.hasOwnProperty.call(i,s)){var o=i[s];"string"==typeof o?t.setAttribute(s,o):null!=o&&(t[s]=o)}e++}for(;e<arguments.length;e++)H(t,arguments[e]);return t}function H(t,e){if("string"==typeof e)t.appendChild(document.createTextNode(e));else if(null==e);else if(null!=e.nodeType)t.appendChild(e);else{if(!Array.isArray(e))throw new RangeError("Unsupported child node: "+e);for(var i=0;i<e.length;i++)H(t,e[i])}}let W="undefined"!=typeof navigator?navigator:{userAgent:"",vendor:"",platform:""},N="undefined"!=typeof document?document:{documentElement:{style:{}}};const P=/Edge\/(\d+)/.exec(W.userAgent),V=/MSIE \d/.test(W.userAgent),F=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(W.userAgent),z=!!(V||F||P),I=!z&&/gecko\/(\d+)/i.test(W.userAgent),q=!z&&/Chrome\/(\d+)/.exec(W.userAgent),K="webkitFontSmoothing"in N.documentElement.style,_=!z&&/Apple Computer/.test(W.vendor),Y=_&&(/Mobile\/\w+/.test(W.userAgent)||W.maxTouchPoints>2);var j={mac:Y||/Mac/.test(W.platform),windows:/Win/.test(W.platform),linux:/Linux|X11/.test(W.platform),ie:z,ie_version:V?N.documentMode||6:F?+F[1]:P?+P[1]:0,gecko:I,gecko_version:I?+(/Firefox\/(\d+)/.exec(W.userAgent)||[0,0])[1]:0,chrome:!!q,chrome_version:q?+q[1]:0,ios:Y,android:/Android\b/.test(W.userAgent),webkit_version:K?+(/\bAppleWebKit\/(\d+)/.exec(W.userAgent)||[0,0])[1]:0,safari:_,safari_version:_?+(/\bVersion\/(\d+(\.\d+)?)/.exec(W.userAgent)||[0,0])[1]:0,tabSize:null!=N.documentElement.style.tabSize?"tab-size":"-moz-tab-size"};function X(t,e){for(let i in t)"class"==i&&e.class?e.class+=" "+t.class:"style"==i&&e.style?e.style+=";"+t.style:e[i]=t[i];return e}const G=Object.create(null);function U(t,e,i){if(t==e)return!0;t||(t=G),e||(e=G);let s=Object.keys(t),o=Object.keys(e);if(s.length-0!=o.length-0)return!1;for(let n of s)if(n!=i&&(-1==o.indexOf(n)||t[n]!==e[n]))return!1;return!0}function $(t,e,i){let s=!1;if(e)for(let o in e)i&&o in i||(s=!0,"style"==o?t.style.cssText="":t.removeAttribute(o));if(i)for(let o in i)e&&e[o]==i[o]||(s=!0,"style"==o?t.style.cssText=i[o]:t.setAttribute(o,i[o]));return s}function Q(t){let e=Object.create(null);for(let i=0;i<t.attributes.length;i++){let s=t.attributes[i];e[s.name]=s.value}return e}class J{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}get editable(){return!1}destroy(t){}}var Z=function(t){return t[t.Text=0]="Text",t[t.WidgetBefore=1]="WidgetBefore",t[t.WidgetAfter=2]="WidgetAfter",t[t.WidgetRange=3]="WidgetRange",t}(Z||(Z={}));class tt extends t{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 et(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 st(t,e,e,i,t.widget||null,!1)}static replace(t){let e,i,s=!!t.block;if(t.isBlockGap)e=-5e8,i=4e8;else{let{start:o,end:n}=ot(t,s);e=(o?s?-3e8:-1:5e8)-1,i=1+(n?s?2e8:1:-6e8)}return new st(t,e,i,s,t.widget||null,!0)}static line(t){return new it(t)}static set(t,i=!1){return e.of(t,i)}hasHeight(){return!!this.widget&&this.widget.estimatedHeight>-1}}tt.none=e.empty;class et extends tt{constructor(t){let{start:e,end:i}=ot(t);super(e?-1:5e8,i?1:-6e8,null,t),this.tagName=t.tagName||"span",this.attrs=t.class&&t.attributes?X(t.attributes,{class:t.class}):t.class?{class:t.class}:t.attributes||G}eq(t){return this==t||t instanceof et&&this.tagName==t.tagName&&U(this.attrs,t.attrs)}range(t,e=t){if(t>=e)throw new RangeError("Mark decorations may not be empty");return super.range(t,e)}}et.prototype.point=!1;class it extends tt{constructor(t){super(-2e8,-2e8,null,t)}eq(t){return t instanceof it&&this.spec.class==t.spec.class&&U(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)}}it.prototype.mapMode=f.TrackBefore,it.prototype.point=!0;class st extends tt{constructor(t,e,i,s,o,n){super(e,i,o,t),this.block=s,this.isReplace=n,this.mapMode=s?e<=0?f.TrackBefore:f.TrackAfter:f.TrackDel}get type(){return this.startSide!=this.endSide?Z.WidgetRange:this.startSide<=0?Z.WidgetBefore:Z.WidgetAfter}get heightRelevant(){return this.block||!!this.widget&&(this.widget.estimatedHeight>=5||this.widget.lineBreaks>0)}eq(t){return t instanceof st&&(e=this.widget,i=t.widget,e==i||!!(e&&i&&e.compare(i)))&&this.block==t.block&&this.startSide==t.startSide&&this.endSide==t.endSide;var e,i}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)}}function ot(t,e=!1){let{inclusiveStart:i,inclusiveEnd:s}=t;return null==i&&(i=t.inclusive),null==s&&(s=t.inclusive),{start:null!=i?i:e,end:null!=s?s:e}}function nt(t,e,i,s=0){let o=i.length-1;o>=0&&i[o]+s>=t?i[o]=Math.max(i[o],e):i.push(t,e)}st.prototype.point=!0;class rt extends t{constructor(t,e){super(),this.tagName=t,this.attributes=e}eq(t){return t==this||t instanceof rt&&this.tagName==t.tagName&&U(this.attributes,t.attributes)}static create(t){return new rt(t.tagName,t.attributes||G)}static set(t,i=!1){return e.of(t,i)}}function lt(t){let e;return e=11==t.nodeType?t.getSelection?t:t.ownerDocument:t,e.getSelection()}function at(t,e){return!!e&&(t==e||t.contains(1!=e.nodeType?e.parentNode:e))}function ht(t,e){if(!e.anchorNode)return!1;try{return at(t,e.anchorNode)}catch(t){return!1}}function ct(t){return 3==t.nodeType?Ct(t,0,t.nodeValue.length).getClientRects():1==t.nodeType?t.getClientRects():[]}function dt(t,e,i,s){return!!i&&(pt(t,e,i,s,-1)||pt(t,e,i,s,1))}function ut(t){for(var e=0;;e++)if(!(t=t.previousSibling))return e}function ft(t){return 1==t.nodeType&&/^(DIV|P|LI|UL|OL|BLOCKQUOTE|DD|DT|H\d|SECTION|PRE)$/.test(t.nodeName)}function pt(t,e,i,s,o){for(;;){if(t==i&&e==s)return!0;if(e==(o<0?0:gt(t))){if("DIV"==t.nodeName)return!1;let i=t.parentNode;if(!i||1!=i.nodeType)return!1;e=ut(t)+(o<0?0:1),t=i}else{if(1!=t.nodeType)return!1;if(1==(t=t.childNodes[e+(o<0?-1:0)]).nodeType&&"false"==t.contentEditable)return!1;e=o<0?gt(t):0}}}function gt(t){return 3==t.nodeType?t.nodeValue.length:t.childNodes.length}function mt(t,e){let i=e?t.left:t.right;return{left:i,right:i,top:t.top,bottom:t.bottom}}function vt(t){let e=t.visualViewport;return e?{left:0,right:e.width,top:0,bottom:e.height}:{left:0,right:t.innerWidth,top:0,bottom:t.innerHeight}}function wt(t,e){let i=e.width/t.offsetWidth,s=e.height/t.offsetHeight;return(i>.995&&i<1.005||!isFinite(i)||Math.abs(e.width-t.offsetWidth)<1)&&(i=1),(s>.995&&s<1.005||!isFinite(s)||Math.abs(e.height-t.offsetHeight)<1)&&(s=1),{scaleX:i,scaleY:s}}rt.prototype.startSide=rt.prototype.endSide=-1;class bt{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?gt(e):0),i,Math.min(t.focusOffset,i?gt(i):0))}set(t,e,i,s){this.anchorNode=t,this.anchorOffset=e,this.focusNode=i,this.focusOffset=s}}let yt,xt=null;function St(t){if(t.setActive)return t.setActive();if(xt)return t.focus(xt);let e=[];for(let i=t;i&&(e.push(i,i.scrollTop,i.scrollLeft),i!=i.ownerDocument);i=i.parentNode);if(t.focus(null==xt?{get preventScroll(){return xt={preventScroll:!0},!0}}:void 0),!xt){xt=!1;for(let t=0;t<e.length;){let i=e[t++],s=e[t++],o=e[t++];i.scrollTop!=s&&(i.scrollTop=s),i.scrollLeft!=o&&(i.scrollLeft=o)}}}function Ct(t,e,i=e){let s=yt||(yt=document.createRange());return s.setEnd(t,i),s.setStart(t,e),s}function Mt(t,e,i,s){let o={key:e,code:e,keyCode:i,which:i,cancelable:!0};s&&({altKey:o.altKey,ctrlKey:o.ctrlKey,shiftKey:o.shiftKey,metaKey:o.metaKey}=s);let n=new KeyboardEvent("keydown",o);n.synthetic=!0,t.dispatchEvent(n);let r=new KeyboardEvent("keyup",o);return r.synthetic=!0,t.dispatchEvent(r),n.defaultPrevented||r.defaultPrevented}function kt(t){return t.scrollTop>Math.max(1,t.scrollHeight-t.clientHeight-4)}function At(t,e){for(let i=t,s=e;;){if(3==i.nodeType&&s>0)return{node:i,offset:s};if(1==i.nodeType&&s>0){if("false"==i.contentEditable)return null;i=i.childNodes[s-1],s=gt(i)}else{if(!i.parentNode||ft(i))return null;s=ut(i),i=i.parentNode}}}function Tt(t,e){for(let i=t,s=e;;){if(3==i.nodeType&&s<i.nodeValue.length)return{node:i,offset:s};if(1==i.nodeType&&s<i.childNodes.length){if("false"==i.contentEditable)return null;i=i.childNodes[s],s=0}else{if(!i.parentNode||ft(i))return null;s=ut(i)+1,i=i.parentNode}}}j.safari&&j.safari_version>=26&&(xt=!1);class Dt{constructor(t,e,i=!0){this.node=t,this.offset=e,this.precise=i}static before(t,e){return new Dt(t.parentNode,ut(t),e)}static after(t,e){return new Dt(t.parentNode,ut(t)+1,e)}}var Ot=function(t){return t[t.LTR=0]="LTR",t[t.RTL=1]="RTL",t}(Ot||(Ot={}));const Lt=Ot.LTR,Bt=Ot.RTL;function Et(t){let e=[];for(let i=0;i<t.length;i++)e.push(1<<+t[i]);return e}const Rt=Et("88888888888888888888888888888888888666888888787833333333337888888000000000000000000000000008888880000000000000000000000000088888888888888888888888888888888888887866668888088888663380888308888800000000000000000000000800000000000000000000000000000008"),Ht=Et("4444448826627288999999999992222222222222222222222222222222222222222222222229999999999999999999994444444444644222822222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222999999949999999229989999223333333333"),Wt=Object.create(null),Nt=[];for(let t of["()","[]","{}"]){let e=t.charCodeAt(0),i=t.charCodeAt(1);Wt[e]=i,Wt[i]=-e}function Pt(t){return t<=247?Rt[t]:1424<=t&&t<=1524?2:1536<=t&&t<=1785?Ht[t-1536]:1774<=t&&t<=2220?4:8192<=t&&t<=8204?256:64336<=t&&t<=65023?4:1}const Vt=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac\ufb50-\ufdff]/;class Ft{get dir(){return this.level%2?Bt: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}forward(t,e){return t==(this.dir==e)}static find(t,e,i,s){let o=-1;for(let n=0;n<t.length;n++){let r=t[n];if(r.from<=e&&r.to>=e){if(r.level==i)return n;(o<0||(0!=s?s<0?r.from<e:r.to>e:t[o].level>r.level))&&(o=n)}}if(o<0)throw new RangeError("Index out of range");return o}}function zt(t,e){if(t.length!=e.length)return!1;for(let i=0;i<t.length;i++){let s=t[i],o=e[i];if(s.from!=o.from||s.to!=o.to||s.direction!=o.direction||!zt(s.inner,o.inner))return!1}return!0}const It=[];function qt(t,e,i,s,o,n,r){let l=s%2?2:1;if(s%2==o%2)for(let a=e,h=0;a<i;){let e=!0,c=!1;if(h==n.length||a<n[h].from){let t=It[a];t!=l&&(e=!1,c=16==t)}let d=e||1!=l?null:[],u=e?s:s+1,f=a;t:for(;;)if(h<n.length&&f==n[h].from){if(c)break t;let p=n[h];if(!e)for(let t=p.to,e=h+1;;){if(t==i)break t;if(!(e<n.length&&n[e].from==t)){if(It[t]==l)break t;break}t=n[e++].to}if(h++,d)d.push(p);else{p.from>a&&r.push(new Ft(a,p.from,u)),Kt(t,p.direction==Lt!=!(u%2)?s+1:s,o,p.inner,p.from,p.to,r),a=p.to}f=p.to}else{if(f==i||(e?It[f]!=l:It[f]==l))break;f++}d?qt(t,a,f,s+1,o,d,r):a<f&&r.push(new Ft(a,f,u)),a=f}else for(let a=i,h=n.length;a>e;){let i=!0,c=!1;if(!h||a>n[h-1].to){let t=It[a-1];t!=l&&(i=!1,c=16==t)}let d=i||1!=l?null:[],u=i?s:s+1,f=a;t:for(;;)if(h&&f==n[h-1].to){if(c)break t;let p=n[--h];if(!i)for(let t=p.from,i=h;;){if(t==e)break t;if(!i||n[i-1].to!=t){if(It[t-1]==l)break t;break}t=n[--i].from}if(d)d.push(p);else{p.to<a&&r.push(new Ft(p.to,a,u)),Kt(t,p.direction==Lt!=!(u%2)?s+1:s,o,p.inner,p.from,p.to,r),a=p.from}f=p.from}else{if(f==e||(i?It[f-1]!=l:It[f-1]==l))break;f--}d?qt(t,f,a,s+1,o,d,r):f<a&&r.push(new Ft(f,a,u)),a=f}}function Kt(t,e,i,s,o,n,r){let l=e%2?2:1;!function(t,e,i,s,o){for(let n=0;n<=s.length;n++){let r=n?s[n-1].to:e,l=n<s.length?s[n].from:i,a=n?256:o;for(let e=r,i=a,s=a;e<l;e++){let o=Pt(t.charCodeAt(e));512==o?o=i:8==o&&4==s&&(o=16),It[e]=4==o?2:o,7&o&&(s=o),i=o}for(let t=r,e=a,s=a;t<l;t++){let o=It[t];if(128==o)t<l-1&&e==It[t+1]&&24&e?o=It[t]=e:It[t]=256;else if(64==o){let o=t+1;for(;o<l&&64==It[o];)o++;let n=t&&8==e||o<i&&8==It[o]?1==s?1:8:256;for(let e=t;e<o;e++)It[e]=n;t=o-1}else 8==o&&1==s&&(It[t]=1);e=o,7&o&&(s=o)}}}(t,o,n,s,l),function(t,e,i,s,o){let n=1==o?2:1;for(let r=0,l=0,a=0;r<=s.length;r++){let h=r?s[r-1].to:e,c=r<s.length?s[r].from:i;for(let e,i,s,r=h;r<c;r++)if(i=Wt[e=t.charCodeAt(r)])if(i<0){for(let t=l-3;t>=0;t-=3)if(Nt[t+1]==-i){let e=Nt[t+2],i=2&e?o:4&e?1&e?n:o:0;i&&(It[r]=It[Nt[t]]=i),l=t;break}}else{if(189==Nt.length)break;Nt[l++]=r,Nt[l++]=e,Nt[l++]=a}else if(2==(s=It[r])||1==s){let t=s==o;a=t?0:1;for(let e=l-3;e>=0;e-=3){let i=Nt[e+2];if(2&i)break;if(t)Nt[e+2]|=2;else{if(4&i)break;Nt[e+2]|=4}}}}}(t,o,n,s,l),function(t,e,i,s){for(let o=0,n=s;o<=i.length;o++){let r=o?i[o-1].to:t,l=o<i.length?i[o].from:e;for(let a=r;a<l;){let r=It[a];if(256==r){let r=a+1;for(;;)if(r==l){if(o==i.length)break;r=i[o++].to,l=o<i.length?i[o].from:e}else{if(256!=It[r])break;r++}let h=1==n,c=h==(1==(r<e?It[r]:s))?h?1:2:s;for(let e=r,s=o,n=s?i[s-1].to:t;e>a;)e==n&&(e=i[--s].from,n=s?i[s-1].to:t),It[--e]=c;a=r}else n=r,a++}}}(o,n,s,l),qt(t,o,n,e,i,s,r)}function _t(t,e,i){if(!t)return[new Ft(0,0,e==Bt?1:0)];if(e==Lt&&!i.length&&!Vt.test(t))return Yt(t.length);if(i.length)for(;t.length>It.length;)It[It.length]=256;let s=[],o=e==Lt?0:1;return Kt(t,o,o,i,0,t.length,s),s}function Yt(t){return[new Ft(0,t,0)]}let jt="";function Xt(t,e,i,s,n){var r;let l=s.head-t.from,h=Ft.find(e,l,null!==(r=s.bidiLevel)&&void 0!==r?r:-1,s.assoc),c=e[h],d=c.side(n,i);if(l==d){let t=h+=n?1:-1;if(t<0||t>=e.length)return null;c=e[h=t],l=c.side(!n,i),d=c.side(n,i)}let u=a(t.text,l,c.forward(n,i));(u<c.from||u>c.to)&&(u=d),jt=t.text.slice(Math.min(l,u),Math.max(l,u));let f=h==(n?e.length-1:0)?null:e[h+(n?1:-1)];return f&&u==d&&f.level+(n?0:1)<c.level?o.cursor(f.side(!n,i)+t.from,f.forward(n,i)?1:-1,f.level):o.cursor(u+t.from,c.forward(n,i)?-1:1,c.level)}function Gt(t,e,i){for(let s=e;s<i;s++){let e=Pt(t.charCodeAt(s));if(1==e)return Lt;if(2==e||4==e)return Bt}return Lt}const Ut=c.define(),$t=c.define(),Qt=c.define(),Jt=c.define(),Zt=c.define(),te=c.define(),ee=c.define(),ie=c.define(),se=c.define(),oe=c.define({combine:t=>t.some(t=>t)}),ne=c.define({combine:t=>t.some(t=>t)}),re=c.define();class le{constructor(t,e="nearest",i="nearest",s=5,o=5,n=!1){this.range=t,this.y=e,this.x=i,this.yMargin=s,this.xMargin=o,this.isSnapshot=n}map(t){return t.empty?this:new le(this.range.map(t),this.y,this.x,this.yMargin,this.xMargin,this.isSnapshot)}clip(t){return this.range.to<=t.doc.length?this:new le(o.cursor(t.doc.length),this.y,this.x,this.yMargin,this.xMargin,this.isSnapshot)}}const ae=d.define({map:(t,e)=>t.map(e)}),he=d.define();function ce(t,e,i){let s=t.facet(Jt);s.length?s[0](e):window.onerror&&window.onerror(String(e),i,void 0,void 0,e)||(i?console.error(i+":",e):console.error(e))}const de=c.define({combine:t=>!t.length||t[0]});let ue=0;const fe=c.define({combine:t=>t.filter((e,i)=>{for(let s=0;s<i;s++)if(t[s].plugin==e.plugin)return!1;return!0})});class pe{constructor(t,e,i,s,o){this.id=t,this.create=e,this.domEventHandlers=i,this.domEventObservers=s,this.baseExtensions=o(this),this.extension=this.baseExtensions.concat(fe.of({plugin:this,arg:void 0}))}of(t){return this.baseExtensions.concat(fe.of({plugin:this,arg:t}))}static define(t,e){const{eventHandlers:i,eventObservers:s,provide:o,decorations:n}=e||{};return new pe(ue++,t,i,s,t=>{let e=[];return n&&e.push(we.of(e=>{let i=e.plugin(t);return i?n(i):tt.none})),o&&e.push(o(t)),e})}static fromClass(t,e){return pe.define((e,i)=>new t(e,i),e)}}class ge{constructor(t){this.spec=t,this.mustUpdate=null,this.value=null}get plugin(){return this.spec&&this.spec.plugin}update(t){if(this.value){if(this.mustUpdate){let t=this.mustUpdate;if(this.mustUpdate=null,this.value.update)try{this.value.update(t)}catch(e){if(ce(t.state,e,"CodeMirror plugin crashed"),this.value.destroy)try{this.value.destroy()}catch(t){}this.deactivate()}}}else if(this.spec)try{this.value=this.spec.plugin.create(t,this.spec.arg)}catch(e){ce(t.state,e,"CodeMirror plugin crashed"),this.deactivate()}return this}destroy(t){var e;if(null===(e=this.value)||void 0===e?void 0:e.destroy)try{this.value.destroy()}catch(e){ce(t.state,e,"CodeMirror plugin crashed")}}deactivate(){this.spec=this.value=null}}const me=c.define(),ve=c.define(),we=c.define(),be=c.define(),ye=c.define(),xe=c.define(),Se=c.define();function Ce(t,i){let s=t.state.facet(Se);if(!s.length)return s;let o=s.map(e=>e instanceof Function?e(t):e),n=[];return e.spans(o,i.from,i.to,{point(){},span(t,e,s,o){let r=t-i.from,l=e-i.from,a=n;for(let t=s.length-1;t>=0;t--,o--){let e,n=s[t].spec.bidiIsolate;if(null==n&&(n=Gt(i.text,r,l)),o>0&&a.length&&(e=a[a.length-1]).to==r&&e.direction==n)e.to=l,a=e.inner;else{let t={from:r,to:l,direction:n,inner:[]};a.push(t),a=t.inner}}}}),n}const Me=c.define();function ke(t){let e=0,i=0,s=0,o=0;for(let n of t.state.facet(Me)){let r=n(t);r&&(null!=r.left&&(e=Math.max(e,r.left)),null!=r.right&&(i=Math.max(i,r.right)),null!=r.top&&(s=Math.max(s,r.top)),null!=r.bottom&&(o=Math.max(o,r.bottom)))}return{left:e,right:i,top:s,bottom:o}}const Ae=c.define();class Te{constructor(t,e,i,s){this.fromA=t,this.toA=e,this.fromB=i,this.toB=s}join(t){return new Te(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(0==e.length)return t;let i=[];for(let s=0,o=0,n=0;;){let r=s<t.length?t[s].fromB:1e9,l=o<e.length?e[o]:1e9,a=Math.min(r,l);if(1e9==a)break;let h=a+n,c=a,d=h;for(;;)if(o<e.length&&e[o]<=c){let i=e[o+1];o+=2,c=Math.max(c,i);for(let e=s;e<t.length&&t[e].fromB<=c;e++)n=t[e].toA-t[e].toB;d=Math.max(d,i+n)}else{if(!(s<t.length&&t[s].fromB<=c))break;{let e=t[s++];c=Math.max(c,e.toB),d=Math.max(d,e.toA),n=e.toA-e.toB}}i.push(new Te(h,d,a,c))}return i}}class De{constructor(t,e,i){this.view=t,this.state=e,this.transactions=i,this.flags=0,this.startState=t.state,this.changes=l.empty(this.startState.doc.length);for(let t of i)this.changes=this.changes.compose(t.changes);let s=[];this.changes.iterChangedRanges((t,e,i,o)=>s.push(new Te(t,e,i,o))),this.changedRanges=s}static create(t,e,i){return new De(t,e,i)}get viewportChanged(){return(4&this.flags)>0}get viewportMoved(){return(8&this.flags)>0}get heightChanged(){return(2&this.flags)>0}get geometryChanged(){return this.docChanged||(18&this.flags)>0}get focusChanged(){return(1&this.flags)>0}get docChanged(){return!this.changes.empty}get selectionSet(){return this.transactions.some(t=>t.selection)}get empty(){return 0==this.flags&&0==this.transactions.length}}const Oe=[];class Le{constructor(t,e,i=0){this.dom=t,this.length=e,this.flags=i,this.parent=null,t.cmTile=this}get breakAfter(){return 1&this.flags}get children(){return Oe}isWidget(){return!1}get isHidden(){return!1}isComposite(){return!1}isLine(){return!1}isText(){return!1}isBlock(){return!1}get domAttrs(){return null}sync(t){if(this.flags|=2,4&this.flags){this.flags&=-5;let t=this.domAttrs;t&&function(t,e){for(let i=t.attributes.length-1;i>=0;i--){let s=t.attributes[i].name;null==e[s]&&t.removeAttribute(s)}for(let i in e){let s=e[i];"style"==i?t.style.cssText=s:t.getAttribute(i)!=s&&t.setAttribute(i,s)}}(this.dom,t)}}toString(){return this.constructor.name+(this.children.length?`(${this.children})`:"")+(this.breakAfter?"#":"")}destroy(){this.parent=null}setDOM(t){this.dom=t,t.cmTile=this}get posAtStart(){return this.parent?this.parent.posBefore(this):0}get posAtEnd(){return this.posAtStart+this.length}posBefore(t,e=this.posAtStart){let i=e;for(let e of this.children){if(e==t)return i;i+=e.length+e.breakAfter}throw new RangeError("Invalid child in posBefore")}posAfter(t){return this.posBefore(t)+t.length}covers(t){return!0}coordsIn(t,e){return null}domPosFor(t,e){let i=ut(this.dom),s=this.length?t>0:e>0;return new Dt(this.parent.dom,i+(s?1:0),0==t||t==this.length)}markDirty(t){this.flags&=-3,t&&(this.flags|=4),this.parent&&2&this.parent.flags&&this.parent.markDirty(!1)}get overrideDOMText(){return null}get root(){for(let t=this;t;t=t.parent)if(t instanceof Re)return t;return null}static get(t){return t.cmTile}}class Be extends Le{constructor(t){super(t,0),this._children=[]}isComposite(){return!0}get children(){return this._children}get lastChild(){return this.children.length?this.children[this.children.length-1]:null}append(t){this.children.push(t),t.parent=this}sync(t){if(2&this.flags)return;super.sync(t);let e,i=this.dom,s=null,o=(null==t?void 0:t.node)==i?t:null,n=0;for(let r of this.children){if(r.sync(t),n+=r.length+r.breakAfter,e=s?s.nextSibling:i.firstChild,o&&e!=r.dom&&(o.written=!0),r.dom.parentNode==i)for(;e&&e!=r.dom;)e=Ee(e);else i.insertBefore(r.dom,e);s=r.dom}for(e=s?s.nextSibling:i.firstChild,o&&e&&(o.written=!0);e;)e=Ee(e);this.length=n}}function Ee(t){let e=t.nextSibling;return t.parentNode.removeChild(t),e}class Re extends Be{constructor(t,e){super(e),this.view=t}owns(t){for(;t;t=t.parent)if(t==this)return!0;return!1}isBlock(){return!0}nearest(t){for(;;){if(!t)return null;let e=Le.get(t);if(e&&this.owns(e))return e;t=t.parentNode}}blockTiles(t){for(let e=[],i=this,s=0,o=0;;)if(s==i.children.length){if(!e.length)return;i=i.parent,i.breakAfter&&o++,s=e.pop()}else{let n=i.children[s++];if(n instanceof He)e.push(s),i=n,s=0;else{let e=o+n.length,i=t(n,o);if(void 0!==i)return i;o=e+n.breakAfter}}}resolveBlock(t,e){let i,s,o=-1,n=-1;if(this.blockTiles((r,l)=>{let a=l+r.length;if(t>=l&&t<=a){if(r.isWidget()&&e>=-1&&e<=1){if(32&r.flags)return!0;16&r.flags&&(i=void 0)}(l<t||t==a&&(e<-1?r.length:r.covers(1)))&&(!i||!r.isWidget()&&i.isWidget())&&(i=r,o=t-l),(a>t||t==l&&(e>1?r.length:r.covers(-1)))&&(!s||!r.isWidget()&&s.isWidget())&&(s=r,n=t-l)}}),!i&&!s)throw new Error("No tile at position "+t);return i&&e<0||!s?{tile:i,offset:o}:{tile:s,offset:n}}}class He extends Be{constructor(t,e){super(t),this.wrapper=e}isBlock(){return!0}covers(t){return!!this.children.length&&(t<0?this.children[0].covers(-1):this.lastChild.covers(1))}get domAttrs(){return this.wrapper.attributes}static of(t,e){let i=new He(e||document.createElement(t.tagName),t);return e||(i.flags|=4),i}}class We extends Be{constructor(t,e){super(t),this.attrs=e}isLine(){return!0}static start(t,e,i){let s=new We(e||document.createElement("div"),t);return e&&i||(s.flags|=4),s}get domAttrs(){return this.attrs}resolveInline(t,e,i){let s=null,o=-1,n=null,r=-1;!function t(l,a){for(let h=0,c=0;h<l.children.length&&c<=a;h++){let d=l.children[h],u=c+d.length;u>=a&&(d.isComposite()?t(d,a-c):(!n||n.isHidden&&(e>0||i&&Ne(n,d)))&&(u>a||32&d.flags)?(n=d,r=a-c):(c<a||16&d.flags&&!d.isHidden)&&(s=d,o=a-c)),c=u}}(this,t);let l=(e<0?s:n)||s||n;return l?{tile:l,offset:l==s?o:r}:null}coordsIn(t,e){let i=this.resolveInline(t,e,!0);return i?i.tile.coordsIn(Math.max(0,i.offset),e):function(t){let e=t.dom.lastChild;if(!e)return t.dom.getBoundingClientRect();let i=ct(e);return i[i.length-1]||null}(this)}domIn(t,e){let i=this.resolveInline(t,e);if(i){let{tile:t,offset:s}=i;if(this.dom.contains(t.dom))return t.isText()?new Dt(t.dom,Math.min(t.dom.nodeValue.length,s)):t.domPosFor(s,16&t.flags?1:32&t.flags?-1:e);let o=i.tile.parent,n=!1;for(let t of o.children){if(n)return new Dt(t.dom,0);t==i.tile&&(n=!0)}}return new Dt(this.dom,0)}}function Ne(t,e){let i=t.coordsIn(0,1),s=e.coordsIn(0,1);return i&&s&&s.top<i.bottom}class Pe extends Be{constructor(t,e){super(t),this.mark=e}get domAttrs(){return this.mark.attrs}static of(t,e){let i=new Pe(e||document.createElement(t.tagName),t);return e||(i.flags|=4),i}}class Ve extends Le{constructor(t,e){super(t,e.length),this.text=e}sync(t){2&this.flags||(super.sync(t),this.dom.nodeValue!=this.text&&(t&&t.node==this.dom&&(t.written=!0),this.dom.nodeValue=this.text))}isText(){return!0}toString(){return JSON.stringify(this.text)}coordsIn(t,e){let i=this.dom.nodeValue.length;t>i&&(t=i);let s=t,o=t,n=0;0==t&&e<0||t==i&&e>=0?j.chrome||j.gecko||(t?(s--,n=1):o<i&&(o++,n=-1)):e<0?s--:o<i&&o++;let r=Ct(this.dom,s,o).getClientRects();if(!r.length)return null;let l=r[(n?n<0:e>=0)?0:r.length-1];return j.safari&&!n&&0==l.width&&(l=Array.prototype.find.call(r,t=>t.width)||l),n?mt(l,n<0):l||null}static of(t,e){let i=new Ve(e||document.createTextNode(t),t);return e||(i.flags|=2),i}}class Fe extends Le{constructor(t,e,i,s){super(t,e,s),this.widget=i}isWidget(){return!0}get isHidden(){return this.widget.isHidden}covers(t){return!(48&this.flags)&&(this.flags&(t<0?64:128))>0}coordsIn(t,e){return this.coordsInWidget(t,e,!1)}coordsInWidget(t,e,i){let s=this.widget.coordsAt(this.dom,t,e);if(s)return s;if(i)return mt(this.dom.getBoundingClientRect(),this.length?0==t:e<=0);{let e=this.dom.getClientRects(),i=null;if(!e.length)return null;let s=!!(16&this.flags)||!(32&this.flags)&&t>0;for(let o=s?e.length-1:0;i=e[o],!(t>0?0==o:o==e.length-1||i.top<i.bottom);o+=s?-1:1);return mt(i,!s)}}get overrideDOMText(){if(!this.length)return h.empty;let{root:t}=this;if(!t)return h.empty;let e=this.posAtStart;return t.view.state.doc.slice(e,e+this.length)}destroy(){super.destroy(),this.widget.destroy(this.dom)}static of(t,e,i,s,o){return o||(o=t.toDOM(e),t.editable||(o.contentEditable="false")),new Fe(o,i,t,s)}}class ze extends Le{constructor(t){let e=document.createElement("img");e.className="cm-widgetBuffer",e.setAttribute("aria-hidden","true"),super(e,0,t)}get isHidden(){return!0}get overrideDOMText(){return h.empty}coordsIn(t){return this.dom.getBoundingClientRect()}}class Ie{constructor(t){this.index=0,this.beforeBreak=!1,this.parents=[],this.tile=t}advance(t,e,i){let{tile:s,index:o,beforeBreak:n,parents:r}=this;for(;t||e>0;)if(s.isComposite())if(n){if(!t)break;i&&i.break(),t--,n=!1}else if(o==s.children.length){if(!t&&!r.length)break;i&&i.leave(s),n=!!s.breakAfter,({tile:s,index:o}=r.pop()),o++}else{let l=s.children[o],a=l.breakAfter;!(e>0?l.length<=t:l.length<t)||i&&!1===i.skip(l,0,l.length)&&l.isComposite?(r.push({tile:s,index:o}),s=l,o=0,i&&l.isComposite()&&i.enter(l)):(n=!!a,o++,t-=l.length)}else if(o==s.length)n=!!s.breakAfter,({tile:s,index:o}=r.pop()),o++;else{if(!t)break;{let e=Math.min(t,s.length-o);i&&i.skip(s,o,o+e),t-=e,o+=e}}return this.tile=s,this.index=o,this.beforeBreak=n,this}get root(){return this.parents.length?this.parents[0].tile:this.tile}}class qe{constructor(t,e,i,s){this.from=t,this.to=e,this.wrapper=i,this.rank=s}}class Ke{constructor(t,e,i){this.cache=t,this.root=e,this.blockWrappers=i,this.curLine=null,this.lastBlock=null,this.afterWidget=null,this.pos=0,this.wrappers=[],this.wrapperPos=0}addText(t,e,i,s){var o;this.flushBuffer();let n=this.ensureMarks(e,i),r=n.lastChild;if(!r||!r.isText()||8&r.flags)n.append(s||Ve.of(t,null===(o=this.cache.find(Ve))||void 0===o?void 0:o.dom));else{this.cache.reused.set(r,2),(n.children[n.children.length-1]=new Ve(r.dom,r.text+t)).parent=n}this.pos+=t.length,this.afterWidget=null}addComposition(t,e){let i=this.curLine;i.dom!=e.line.dom&&(i.setDOM(this.cache.reused.has(e.line)?$e(e.line.dom):e.line.dom),this.cache.reused.set(e.line,2));let s=i;for(let t=e.marks.length-1;t>=0;t--){let i=e.marks[t],o=s.lastChild;if(o instanceof Pe&&o.mark.eq(i.mark))o.dom!=i.dom&&o.setDOM($e(i.dom)),s=o;else{if(this.cache.reused.get(i)){let t=Le.get(i.dom);t&&t.setDOM($e(i.dom))}let t=Pe.of(i.mark,i.dom);s.append(t),s=t}this.cache.reused.set(i,2)}let o=Le.get(t.text);o&&this.cache.reused.set(o,2);let n=new Ve(t.text,t.text.nodeValue);n.flags|=8,s.append(n)}addInlineWidget(t,e,i){let s=this.afterWidget&&48&t.flags&&(48&this.afterWidget.flags)==(48&t.flags);s||this.flushBuffer();let o=this.ensureMarks(e,i);s||16&t.flags||o.append(this.getBuffer(1)),o.append(t),this.pos+=t.length,this.afterWidget=t}addMark(t,e,i){this.flushBuffer(),this.ensureMarks(e,i).append(t),this.pos+=t.length,this.afterWidget=null}addBlockWidget(t){this.getBlockPos().append(t),this.pos+=t.length,this.lastBlock=t,this.endLine()}continueWidget(t){(this.afterWidget||this.lastBlock).length+=t,this.pos+=t}addLineStart(t,e){var i;t||(t=Ue);let s=We.start(t,e||(null===(i=this.cache.find(We))||void 0===i?void 0:i.dom),!!e);this.getBlockPos().append(this.lastBlock=this.curLine=s)}addLine(t){this.getBlockPos().append(t),this.pos+=t.length,this.lastBlock=t,this.endLine()}addBreak(){this.lastBlock.flags|=1,this.endLine(),this.pos++}addLineStartIfNotCovered(t){this.blockPosCovered()||this.addLineStart(t)}ensureLine(t){this.curLine||this.addLineStart(t)}ensureMarks(t,e){var i;let s=this.curLine;for(let o=t.length-1;o>=0;o--){let n,r=t[o];if(e>0&&(n=s.lastChild)&&n instanceof Pe&&n.mark.eq(r))s=n,e--;else{let t=Pe.of(r,null===(i=this.cache.find(Pe,t=>t.mark.eq(r)))||void 0===i?void 0:i.dom);s.append(t),s=t,e=0}}return s}endLine(){if(this.curLine){this.flushBuffer();let t=this.curLine.lastChild;t&&Ge(this.curLine,!1)&&("BR"==t.dom.nodeName||!t.isWidget()||j.ios&&Ge(this.curLine,!0))||this.curLine.append(this.cache.findWidget(Je,0,32)||new Fe(Je.toDOM(),0,Je,32)),this.curLine=this.afterWidget=null}}updateBlockWrappers(){this.wrapperPos>this.pos+1e4&&(this.blockWrappers.goto(this.pos),this.wrappers.length=0);for(let t=this.wrappers.length-1;t>=0;t--)this.wrappers[t].to<this.pos&&this.wrappers.splice(t,1);for(let t=this.blockWrappers;t.value&&t.from<=this.pos;t.next())if(t.to>=this.pos){let e=new qe(t.from,t.to,t.value,t.rank),i=this.wrappers.length;for(;i>0&&(this.wrappers[i-1].rank-e.rank||this.wrappers[i-1].to-e.to)<0;)i--;this.wrappers.splice(i,0,e)}this.wrapperPos=this.pos}getBlockPos(){var t;this.updateBlockWrappers();let e=this.root;for(let i of this.wrappers){let s=e.lastChild;if(i.from<this.pos&&s instanceof He&&s.wrapper.eq(i.wrapper))e=s;else{let s=He.of(i.wrapper,null===(t=this.cache.find(He,t=>t.wrapper.eq(i.wrapper)))||void 0===t?void 0:t.dom);e.append(s),e=s}}return e}blockPosCovered(){let t=this.lastBlock;return null!=t&&!t.breakAfter&&(!t.isWidget()||(160&t.flags)>0)}getBuffer(t){let e=2|(t<0?16:32),i=this.cache.find(ze,void 0,1);return i&&(i.flags=e),i||new ze(e)}flushBuffer(){!this.afterWidget||32&this.afterWidget.flags||(this.afterWidget.parent.append(this.getBuffer(-1)),this.afterWidget=null)}}class _e{constructor(t){this.skipCount=0,this.text="",this.textOff=0,this.cursor=t.iter()}skip(t){this.textOff+t<=this.text.length?this.textOff+=t:(this.skipCount+=t-(this.text.length-this.textOff),this.text="",this.textOff=0)}next(t){if(this.textOff==this.text.length){let{value:e,lineBreak:i,done:s}=this.cursor.next(this.skipCount);if(this.skipCount=0,s)throw new Error("Ran out of text content when drawing inline views");this.text=e;let o=this.textOff=Math.min(t,e.length);return i?null:e.slice(0,o)}let e=Math.min(this.text.length,this.textOff+t),i=this.text.slice(this.textOff,e);return this.textOff=e,i}}const Ye=[Fe,We,Ve,Pe,ze,He,Re];for(let t=0;t<Ye.length;t++)Ye[t].bucket=t;class je{constructor(t){this.view=t,this.buckets=Ye.map(()=>[]),this.index=Ye.map(()=>0),this.reused=new Map}add(t){let e=t.constructor.bucket,i=this.buckets[e];i.length<6?i.push(t):i[this.index[e]=(this.index[e]+1)%6]=t}find(t,e,i=2){let s=t.bucket,o=this.buckets[s],n=this.index[s];for(let t=o.length-1;t>=0;t--){let r=(t+n)%o.length,l=o[r];if((!e||e(l))&&!this.reused.has(l))return o.splice(r,1),r<n&&this.index[s]--,this.reused.set(l,i),l}return null}findWidget(t,e,i){let s=this.buckets[0];if(s.length)for(let o=0,n=0;;o++){if(o==s.length){if(n)return null;n=1,o=0}let r=s[o];if(!this.reused.has(r)&&(0==n?r.widget.compare(t):r.widget.constructor==t.constructor&&t.updateDOM(r.dom,this.view)))return s.splice(o,1),o<this.index[0]&&this.index[0]--,r.widget==t&&r.length==e&&(497&r.flags)==i?(this.reused.set(r,1),r):(this.reused.set(r,2),new Fe(r.dom,e,t,-498&r.flags|i))}}reuse(t){return this.reused.set(t,1),t}maybeReuse(t,e=2){if(!this.reused.has(t))return this.reused.set(t,e),t.dom}clear(){for(let t=0;t<this.buckets.length;t++)this.buckets[t].length=this.index[t]=0}}class Xe{constructor(t,i,s,o,n){this.view=t,this.decorations=o,this.disallowBlockEffectsFor=n,this.openWidget=!1,this.openMarks=0,this.cache=new je(t),this.text=new _e(t.state.doc),this.builder=new Ke(this.cache,new Re(t,t.contentDOM),e.iter(s)),this.cache.reused.set(i,2),this.old=new Ie(i),this.reuseWalker={skip:(t,e,i)=>{if(this.cache.add(t),t.isComposite())return!1},enter:t=>this.cache.add(t),leave:()=>{},break:()=>{}}}run(t,e){let i=e&&this.getCompositionContext(e.text);for(let s=0,o=0,n=0;;){let r=n<t.length?t[n++]:null,l=r?r.fromA:this.old.root.length;if(l>s){let t=l-s;this.preserve(t,!n,!r),s=l,o+=t}if(!r)break;e&&r.fromA<=e.range.fromA&&r.toA>=e.range.toA?(this.forward(r.fromA,e.range.fromA,e.range.fromA<e.range.toA?1:-1),this.emit(o,e.range.fromB),this.cache.clear(),this.builder.addComposition(e,i),this.text.skip(e.range.toB-e.range.fromB),this.forward(e.range.fromA,r.toA),this.emit(e.range.toB,r.toB)):(this.forward(r.fromA,r.toA),this.emit(o,r.toB)),o=r.toB,s=r.toA}return this.builder.curLine&&this.builder.endLine(),this.builder.root}preserve(t,e,i){let s=function(t){let e=[];for(let i=t.parents.length;i>1;i--){let s=i==t.parents.length?t.tile:t.parents[i].tile;s instanceof Pe&&e.push(s.mark)}return e}(this.old),o=this.openMarks;this.old.advance(t,i?1:-1,{skip:(t,e,i)=>{if(t.isWidget())if(this.openWidget)this.builder.continueWidget(i-e);else{let n=i>0||e<t.length?Fe.of(t.widget,this.view,i-e,496&t.flags,this.cache.maybeReuse(t)):this.cache.reuse(t);256&n.flags?(n.flags&=-2,this.builder.addBlockWidget(n)):(this.builder.ensureLine(null),this.builder.addInlineWidget(n,s,o),o=s.length)}else if(t.isText())this.builder.ensureLine(null),e||i!=t.length?(this.cache.add(t),this.builder.addText(t.text.slice(e,i),s,o)):this.builder.addText(t.text,s,o,this.cache.reuse(t)),o=s.length;else if(t.isLine())t.flags&=-2,this.cache.reused.set(t,1),this.builder.addLine(t);else if(t instanceof ze)this.cache.add(t);else{if(!(t instanceof Pe))return!1;this.builder.ensureLine(null),this.builder.addMark(t,s,o),this.cache.reused.set(t,1),o=s.length}this.openWidget=!1},enter:t=>{t.isLine()?this.builder.addLineStart(t.attrs,this.cache.maybeReuse(t)):(this.cache.add(t),t instanceof Pe&&s.unshift(t.mark)),this.openWidget=!1},leave:t=>{t.isLine()?s.length&&(s.length=o=0):t instanceof Pe&&(s.shift(),o=Math.min(o,s.length))},break:()=>{this.builder.addBreak(),this.openWidget=!1}}),this.text.skip(t)}emit(t,i){let s=null,o=this.builder,n=0,r=e.spans(this.decorations,t,i,{point:(t,e,i,r,l,a)=>{if(i instanceof st){if(this.disallowBlockEffectsFor[a]){if(i.block)throw new RangeError("Block decorations may not be specified via plugins");if(e>this.view.state.doc.lineAt(t).to)throw new RangeError("Decorations that replace line breaks may not be specified via plugins")}if(n=r.length,l>r.length)o.continueWidget(e-t);else{let n=i.widget||(i.block?Qe.block:Qe.inline),a=function(t){let e=t.isReplace?(t.startSide<0?64:0)|(t.endSide>0?128:0):t.startSide>0?32:16;t.block&&(e|=256);return e}(i),h=this.cache.findWidget(n,e-t,a)||Fe.of(n,this.view,e-t,a);i.block?(i.startSide>0&&o.addLineStartIfNotCovered(s),o.addBlockWidget(h)):(o.ensureLine(s),o.addInlineWidget(h,r,l))}s=null}else s=function(t,e){let i=e.spec.attributes,s=e.spec.class;if(!i&&!s)return t;t||(t={class:"cm-line"});i&&X(i,t);s&&(t.class+=" "+s);return t}(s,i);e>t&&this.text.skip(e-t)},span:(t,e,i,n)=>{for(let r=t;r<e;){let t=this.text.next(Math.min(512,e-r));null==t?(o.addLineStartIfNotCovered(s),o.addBreak(),r++):(o.ensureLine(s),o.addText(t,i,n),r+=t.length),s=null}}});o.addLineStartIfNotCovered(s),this.openWidget=r>n,this.openMarks=r}forward(t,e,i=1){e-t<=10?this.old.advance(e-t,i,this.reuseWalker):(this.old.advance(5,-1,this.reuseWalker),this.old.advance(e-t-10,-1),this.old.advance(5,i,this.reuseWalker))}getCompositionContext(t){let e=[],i=null;for(let s=t.parentNode;;s=s.parentNode){let t=Le.get(s);if(s==this.view.contentDOM)break;t instanceof Pe?e.push(t):(null==t?void 0:t.isLine())?i=t:"DIV"!=s.nodeName||i||s==this.view.contentDOM?e.push(Pe.of(new et({tagName:s.nodeName.toLowerCase(),attributes:Q(s)}),s)):i=new We(s,Ue)}return{line:i,marks:e}}}function Ge(t,e){let i=t=>{for(let s of t.children)if((e?s.isText():s.length)||i(s))return!0;return!1};return i(t)}const Ue={class:"cm-line"};function $e(t){let e=Le.get(t);return e&&e.setDOM(t.cloneNode()),t}class Qe extends J{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}}Qe.inline=new Qe("span"),Qe.block=new Qe("div");const Je=new class extends J{toDOM(){return document.createElement("br")}get isHidden(){return!0}get editable(){return!0}};class Ze{constructor(t){this.view=t,this.decorations=[],this.blockWrappers=[],this.dynamicDecorationMap=[!1],this.domChanged=null,this.hasComposition=null,this.editContextFormatting=tt.none,this.lastCompositionAfterCursor=!1,this.minWidth=0,this.minWidthFrom=0,this.minWidthTo=0,this.impreciseAnchor=null,this.impreciseHead=null,this.forceSelection=!1,this.lastUpdate=Date.now(),this.updateDeco(),this.tile=new Re(t,t.contentDOM),this.updateInner([new Te(0,0,0,t.state.doc.length)],null)}update(t){var i;let s=t.changedRanges;this.minWidth>0&&s.length&&(s.every(({fromA:t,toA:e})=>e<this.minWidthFrom||t>this.minWidthTo)?(this.minWidthFrom=t.changes.mapPos(this.minWidthFrom,1),this.minWidthTo=t.changes.mapPos(this.minWidthTo,1)):this.minWidth=this.minWidthFrom=this.minWidthTo=0),this.updateEditContextFormatting(t);let o=-1;this.view.inputState.composing>=0&&!this.view.observer.editContext&&((null===(i=this.domChanged)||void 0===i?void 0:i.newSel)?o=this.domChanged.newSel.head:function(t,e){let i=!1;e&&t.iterChangedRanges((t,s)=>{t<e.to&&s>e.from&&(i=!0)});return i}(t.changes,this.hasComposition)||t.selectionSet||(o=t.state.selection.main.head));let n=o>-1?function(t,e,i){let s=ei(t,i);if(!s)return null;let{node:o,from:n,to:r}=s,l=o.nodeValue;if(/[\n\r]/.test(l))return null;if(t.state.doc.sliceString(s.from,s.to)!=l)return null;let a=e.invertedDesc;return{range:new Te(a.mapPos(n),a.mapPos(r),n,r),text:o}}(this.view,t.changes,o):null;if(this.domChanged=null,this.hasComposition){let{from:e,to:i}=this.hasComposition;s=new Te(e,i,t.changes.mapPos(e,-1),t.changes.mapPos(i,1)).addToSet(s.slice())}this.hasComposition=n?{from:n.range.fromB,to:n.range.toB}:null,(j.ie||j.chrome)&&!n&&t&&t.state.doc.lines!=t.startState.doc.lines&&(this.forceSelection=!0);let r=this.decorations,l=this.blockWrappers;this.updateDeco();let a=function(t,i,s){let o=new ii;return e.compare(t,i,s,o),o.changes}(r,this.decorations,t.changes);a.length&&(s=Te.extendWithRanges(s,a));let h=function(t,i,s){let o=new si;return e.compare(t,i,s,o),o.changes}(l,this.blockWrappers,t.changes);return h.length&&(s=Te.extendWithRanges(s,h)),n&&!s.some(t=>t.fromA<=n.range.fromA&&t.toA>=n.range.toA)&&(s=n.range.addToSet(s.slice())),!(2&this.tile.flags&&0==s.length)&&(this.updateInner(s,n),t.transactions.length&&(this.lastUpdate=Date.now()),!0)}updateInner(t,e){this.view.viewState.mustMeasureContent=!0;let{observer:i}=this.view;i.ignore(()=>{if(e||t.length){let i=this.tile,s=new Xe(this.view,i,this.blockWrappers,this.decorations,this.dynamicDecorationMap);this.tile=s.run(t,e),ti(i,s.cache.reused)}this.tile.dom.style.height=this.view.viewState.contentHeight/this.view.scaleY+"px",this.tile.dom.style.flexBasis=this.minWidth?this.minWidth+"px":"";let s=j.chrome||j.ios?{node:i.selectionRange.focusNode,written:!1}:void 0;this.tile.sync(s),!s||!s.written&&i.selectionRange.focusNode==s.node&&this.tile.dom.contains(s.node)||(this.forceSelection=!0),this.tile.dom.style.height=""});let s=[];if(this.view.viewport.from||this.view.viewport.to<this.view.state.doc.length)for(let t of this.tile.children)t.isWidget()&&t.widget instanceof oi&&s.push(t.dom);i.updateGaps(s)}updateEditContextFormatting(t){this.editContextFormatting=this.editContextFormatting.map(t.changes);for(let e of t.transactions)for(let t of e.effects)t.is(he)&&(this.editContextFormatting=t.value)}updateSelection(t=!1,e=!1){!t&&this.view.observer.selectionRange.focusNode||this.view.observer.readSelectionRange();let{dom:i}=this.tile,s=this.view.root.activeElement,o=s==i,n=!o&&!(this.view.state.facet(de)||i.tabIndex>-1)&&ht(i,this.view.observer.selectionRange)&&!(s&&i.contains(s));if(!(o||e||n))return;let r=this.forceSelection;this.forceSelection=!1;let l,a,h=this.view.state.selection.main;if(h.empty?a=l=this.inlineDOMNearPos(h.anchor,h.assoc||1):(a=this.inlineDOMNearPos(h.head,h.head==h.from?1:-1),l=this.inlineDOMNearPos(h.anchor,h.anchor==h.from?1:-1)),j.gecko&&h.empty&&!this.hasComposition&&(1==(c=l).node.nodeType&&c.node.firstChild&&(0==c.offset||"false"==c.node.childNodes[c.offset-1].contentEditable)&&(c.offset==c.node.childNodes.length||"false"==c.node.childNodes[c.offset].contentEditable))){let t=document.createTextNode("");this.view.observer.ignore(()=>l.node.insertBefore(t,l.node.childNodes[l.offset]||null)),l=a=new Dt(t,0),r=!0}var c;let d=this.view.observer.selectionRange;!r&&d.focusNode&&(dt(l.node,l.offset,d.anchorNode,d.anchorOffset)&&dt(a.node,a.offset,d.focusNode,d.focusOffset)||this.suppressWidgetCursorChange(d,h))||(this.view.observer.ignore(()=>{j.android&&j.chrome&&i.contains(d.focusNode)&&function(t,e){for(let i=t;i&&i!=e;i=i.assignedSlot||i.parentNode)if(1==i.nodeType&&"false"==i.contentEditable)return!0;return!1}(d.focusNode,i)&&(i.blur(),i.focus({preventScroll:!0}));let t=lt(this.view.root);if(t)if(h.empty){if(j.gecko){let t=(e=l.node,o=l.offset,1!=e.nodeType?0:(o&&"false"==e.childNodes[o-1].contentEditable?1:0)|(o<e.childNodes.length&&"false"==e.childNodes[o].contentEditable?2:0));if(t&&3!=t){let e=(1==t?At:Tt)(l.node,l.offset);e&&(l=new Dt(e.node,e.offset))}}t.collapse(l.node,l.offset),null!=h.bidiLevel&&void 0!==t.caretBidiLevel&&(t.caretBidiLevel=h.bidiLevel)}else if(t.extend){t.collapse(l.node,l.offset);try{t.extend(a.node,a.offset)}catch(t){}}else{let e=document.createRange();h.anchor>h.head&&([l,a]=[a,l]),e.setEnd(a.node,a.offset),e.setStart(l.node,l.offset),t.removeAllRanges(),t.addRange(e)}else;var e,o;n&&this.view.root.activeElement==i&&(i.blur(),s&&s.focus())}),this.view.observer.setSelectionRange(l,a)),this.impreciseAnchor=l.precise?null:new Dt(d.anchorNode,d.anchorOffset),this.impreciseHead=a.precise?null:new Dt(d.focusNode,d.focusOffset)}suppressWidgetCursorChange(t,e){return this.hasComposition&&e.empty&&dt(t.focusNode,t.focusOffset,t.anchorNode,t.anchorOffset)&&this.posFromDOM(t.focusNode,t.focusOffset)==e.head}enforceCursorAssoc(){if(this.hasComposition)return;let{view:t}=this,e=t.state.selection.main,i=lt(t.root),{anchorNode:s,anchorOffset:o}=t.observer.selectionRange;if(!(i&&e.empty&&e.assoc&&i.modify))return;let n=this.lineAt(e.head,e.assoc);if(!n)return;let r=n.posAtStart;if(e.head==r||e.head==r+n.length)return;let l=this.coordsAt(e.head,-1),a=this.coordsAt(e.head,1);if(!l||!a||l.bottom>a.top)return;let h=this.domAtPos(e.head+e.assoc,e.assoc);i.collapse(h.node,h.offset),i.modify("move",e.assoc<0?"forward":"backward","lineboundary"),t.observer.readSelectionRange();let c=t.observer.selectionRange;t.docView.posFromDOM(c.anchorNode,c.anchorOffset)!=e.from&&i.collapse(s,o)}posFromDOM(t,e){let i=this.tile.nearest(t);if(!i)return 2&this.tile.dom.compareDocumentPosition(t)?0:this.view.state.doc.length;let s=i.posAtStart;if(!i.isComposite())return i.isText()?t==i.dom?s+e:s+(e?i.length:0):s;{let o;if(t==i.dom)o=i.dom.childNodes[e];else{let s=0==gt(t)?0:0==e?-1:1;for(;;){let e=t.parentNode;if(e==i.dom)break;0==s&&e.firstChild!=e.lastChild&&(s=t==e.firstChild?-1:1),t=e}o=s<0?t:t.nextSibling}if(o==i.dom.firstChild)return s;for(;o&&!Le.get(o);)o=o.nextSibling;if(!o)return s+i.length;for(let t=0,e=s;;t++){let s=i.children[t];if(s.dom==o)return e;e+=s.length+s.breakAfter}}}domAtPos(t,e){let{tile:i,offset:s}=this.tile.resolveBlock(t,e);return i.isWidget()?i.domPosFor(t,e):i.domIn(s,e)}inlineDOMNearPos(t,e){let i,s,o=-1,n=!1,r=-1,l=!1;return this.tile.blockTiles((e,a)=>{if(e.isWidget()){if(32&e.flags&&a>=t)return!0;16&e.flags&&(n=!0)}else{let h=a+e.length;if(a<=t&&(i=e,o=t-a,n=h<t),h>=t&&!s&&(s=e,r=t-a,l=a>t),a>t&&s)return!0}}),i||s?(n&&s?i=null:l&&i&&(s=null),i&&e<0||!s?i.domIn(o,e):s.domIn(r,e)):this.domAtPos(t,e)}coordsAt(t,e){let{tile:i,offset:s}=this.tile.resolveBlock(t,e);return i.isWidget()?i.widget instanceof oi?null:i.coordsInWidget(s,e,!0):i.coordsIn(s,e)}lineAt(t,e){let{tile:i}=this.tile.resolveBlock(t,e);return i.isLine()?i:null}coordsForChar(t){let{tile:e,offset:i}=this.tile.resolveBlock(t,1);if(!e.isLine())return null;return function t(e,i){if(e.isComposite())for(let s of e.children){if(s.length>=i){let e=t(s,i);if(e)return e}if((i-=s.length)<0)break}else if(e.isText()&&i<e.length){let t=a(e.text,i);if(t==i)return null;let s=Ct(e.dom,i,t).getClientRects();for(let t=0;t<s.length;t++){let e=s[t];if(t==s.length-1||e.top<e.bottom&&e.left<e.right)return e}}return null}(e,i)}measureVisibleLineHeights(t){let e=[],{from:i,to:s}=t,o=this.view.contentDOM.clientWidth,n=o>Math.max(this.view.scrollDOM.clientWidth,this.minWidth)+1,r=-1,l=this.view.textDirection==Ot.LTR,a=0,h=(t,c,d)=>{for(let u=0;u<t.children.length&&!(c>s);u++){let s=t.children[u],f=c+s.length,p=s.dom.getBoundingClientRect(),{height:g}=p;if(d&&!u&&(a+=p.top-d.top),s instanceof He)f>i&&h(s,c,p);else if(c>=i&&(a>0&&e.push(-a),e.push(g+a),a=0,n)){let t=s.dom.lastChild,e=t?ct(t):[];if(e.length){let t=e[e.length-1],i=l?t.right-p.left:p.right-t.left;i>r&&(r=i,this.minWidth=o,this.minWidthFrom=c,this.minWidthTo=f)}}d&&u==t.children.length-1&&(a+=d.bottom-p.bottom),c=f+s.breakAfter}};return h(this.tile,0,null),e}textDirectionAt(t){let{tile:e}=this.tile.resolveBlock(t,1);return"rtl"==getComputedStyle(e.dom).direction?Ot.RTL:Ot.LTR}measureTextSize(){let t=this.tile.blockTiles(t=>{if(t.isLine()&&t.children.length&&t.length<=20){let e,i=0;for(let s of t.children){if(!s.isText()||/[^ -~]/.test(s.text))return;let t=ct(s.dom);if(1!=t.length)return;i+=t[0].width,e=t[0].height}if(i)return{lineHeight:t.dom.getBoundingClientRect().height,charWidth:i/t.length,textHeight:e}}});if(t)return t;let e,i,s,o=document.createElement("div");return o.className="cm-line",o.style.width="99999px",o.style.position="absolute",o.textContent="abc def ghi jkl mno pqr stu",this.view.observer.ignore(()=>{this.tile.dom.appendChild(o);let t=ct(o.firstChild)[0];e=o.getBoundingClientRect().height,i=t&&t.width?t.width/27:7,s=t&&t.height?t.height:e,o.remove()}),{lineHeight:e,charWidth:i,textHeight:s}}computeBlockGapDeco(){let t=[],e=this.view.viewState;for(let i=0,s=0;;s++){let o=s==e.viewports.length?null:e.viewports[s],n=o?o.from-1:this.view.state.doc.length;if(n>i){let s=(e.lineBlockAt(n).bottom-e.lineBlockAt(i).top)/this.view.scaleY;t.push(tt.replace({widget:new oi(s),block:!0,inclusive:!0,isBlockGap:!0}).range(i,n))}if(!o)break;i=o.to+1}return tt.set(t)}updateDeco(){let t=1,i=this.view.state.facet(we).map(e=>(this.dynamicDecorationMap[t++]="function"==typeof e)?e(this.view):e),s=!1,o=this.view.state.facet(ye).map((t,e)=>{let i="function"==typeof t;return i&&(s=!0),i?t(this.view):t});for(o.length&&(this.dynamicDecorationMap[t++]=s,i.push(e.join(o))),this.decorations=[this.editContextFormatting,...i,this.computeBlockGapDeco(),this.view.viewState.lineGapDeco];t<this.decorations.length;)this.dynamicDecorationMap[t++]=!1;this.blockWrappers=this.view.state.facet(be).map(t=>"function"==typeof t?t(this.view):t)}scrollIntoView(t){if(t.isSnapshot){let e=this.view.viewState.lineBlockAt(t.range.head);return this.view.scrollDOM.scrollTop=e.top-t.yMargin,void(this.view.scrollDOM.scrollLeft=t.xMargin)}for(let e of this.view.state.facet(re))try{if(e(this.view,t.range,t))return!0}catch(t){ce(this.view.state,t,"scroll handler")}let e,{range:i}=t,s=this.coordsAt(i.head,i.empty?i.assoc:i.head>i.anchor?-1:1);if(!s)return;!i.empty&&(e=this.coordsAt(i.anchor,i.anchor>i.head?-1:1))&&(s={left:Math.min(s.left,e.left),top:Math.min(s.top,e.top),right:Math.max(s.right,e.right),bottom:Math.max(s.bottom,e.bottom)});let o=ke(this.view),n={left:s.left-o.left,top:s.top-o.top,right:s.right+o.right,bottom:s.bottom+o.bottom},{offsetWidth:r,offsetHeight:l}=this.view.scrollDOM;!function(t,e,i,s,o,n,r,l){let a=t.ownerDocument,h=a.defaultView||window;for(let c=t,d=!1;c&&!d;)if(1==c.nodeType){let t,u=c==a.body,f=1,p=1;if(u)t=vt(h);else{if(/^(fixed|sticky)$/.test(getComputedStyle(c).position)&&(d=!0),c.scrollHeight<=c.clientHeight&&c.scrollWidth<=c.clientWidth){c=c.assignedSlot||c.parentNode;continue}let e=c.getBoundingClientRect();({scaleX:f,scaleY:p}=wt(c,e)),t={left:e.left,right:e.left+c.clientWidth*f,top:e.top,bottom:e.top+c.clientHeight*p}}let g=0,m=0;if("nearest"==o)e.top<t.top?(m=e.top-(t.top+r),i>0&&e.bottom>t.bottom+m&&(m=e.bottom-t.bottom+r)):e.bottom>t.bottom&&(m=e.bottom-t.bottom+r,i<0&&e.top-m<t.top&&(m=e.top-(t.top+r)));else{let s=e.bottom-e.top,n=t.bottom-t.top;m=("center"==o&&s<=n?e.top+s/2-n/2:"start"==o||"center"==o&&i<0?e.top-r:e.bottom-n+r)-t.top}if("nearest"==s?e.left<t.left?(g=e.left-(t.left+n),i>0&&e.right>t.right+g&&(g=e.right-t.right+n)):e.right>t.right&&(g=e.right-t.right+n,i<0&&e.left<t.left+g&&(g=e.left-(t.left+n))):g=("center"==s?e.left+(e.right-e.left)/2-(t.right-t.left)/2:"start"==s==l?e.left-n:e.right-(t.right-t.left)+n)-t.left,g||m)if(u)h.scrollBy(g,m);else{let t=0,i=0;if(m){let t=c.scrollTop;c.scrollTop+=m/p,i=(c.scrollTop-t)*p}if(g){let e=c.scrollLeft;c.scrollLeft+=g/f,t=(c.scrollLeft-e)*f}e={left:e.left-t,top:e.top-i,right:e.right-t,bottom:e.bottom-i},t&&Math.abs(t-g)<1&&(s="nearest"),i&&Math.abs(i-m)<1&&(o="nearest")}if(u)break;(e.top<t.top||e.bottom>t.bottom||e.left<t.left||e.right>t.right)&&(e={left:Math.max(e.left,t.left),right:Math.min(e.right,t.right),top:Math.max(e.top,t.top),bottom:Math.min(e.bottom,t.bottom)}),c=c.assignedSlot||c.parentNode}else{if(11!=c.nodeType)break;c=c.host}}(this.view.scrollDOM,n,i.head<i.anchor?-1:1,t.x,t.y,Math.max(Math.min(t.xMargin,r),-r),Math.max(Math.min(t.yMargin,l),-l),this.view.textDirection==Ot.LTR)}lineHasWidget(t){let e=t=>t.isWidget()||t.children.some(e);return e(this.tile.resolveBlock(t,1).tile)}destroy(){ti(this.tile)}}function ti(t,e){let i=null==e?void 0:e.get(t);if(1!=i){null==i&&t.destroy();for(let i of t.children)ti(i,e)}}function ei(t,e){let i=t.observer.selectionRange;if(!i.focusNode)return null;let s=At(i.focusNode,i.focusOffset),o=Tt(i.focusNode,i.focusOffset),n=s||o;if(o&&s&&o.node!=s.node){let e=Le.get(o.node);if(!e||e.isText()&&e.text!=o.node.nodeValue)n=o;else if(t.docView.lastCompositionAfterCursor){let t=Le.get(s.node);!t||t.isText()&&t.text!=s.node.nodeValue||(n=o)}}if(t.docView.lastCompositionAfterCursor=n!=s,!n)return null;let r=e-n.offset;return{from:r,to:r+n.node.nodeValue.length,node:n.node}}let ii=class{constructor(){this.changes=[]}compareRange(t,e){nt(t,e,this.changes)}comparePoint(t,e){nt(t,e,this.changes)}boundChange(t){nt(t,t,this.changes)}};class si{constructor(){this.changes=[]}compareRange(t,e){nt(t,e,this.changes)}comparePoint(){}boundChange(t){nt(t,t,this.changes)}}class oi extends J{constructor(t){super(),this.height=t}toDOM(){let t=document.createElement("div");return t.className="cm-gap",this.updateDOM(t),t}eq(t){return t.height==this.height}updateDOM(t){return t.style.height=this.height+"px",!0}get editable(){return!0}get estimatedHeight(){return this.height}ignoreEvent(){return!1}}function ni(t,e,i){let s=t.lineBlockAt(e);if(Array.isArray(s.type)){let t;for(let o of s.type){if(o.from>e)break;if(!(o.to<e)){if(o.from<e&&o.to>e)return o;t&&(o.type!=Z.Text||t.type==o.type&&!(i<0?o.from<e:o.to>e))||(t=o)}}return t||s}return s}function ri(t,e,i,s){let o=t.state.doc.lineAt(e.head),n=t.bidiSpans(o),r=t.textDirectionAt(o.from);for(let l=e,a=null;;){let e=Xt(o,n,r,l,i),h=jt;if(!e){if(o.number==(i?t.state.doc.lines:1))return l;h="\n",o=t.state.doc.line(o.number+(i?1:-1)),n=t.bidiSpans(o),e=t.visualLineSide(o,!i)}if(a){if(!a(h))return l}else{if(!s)return e;a=s(h)}l=e}}function li(t,e,i){for(;;){let s=0;for(let o of t)o.between(e-1,e+1,(t,o,n)=>{if(e>t&&e<o){let n=s||i||(e-t<o-e?-1:1);e=n<0?t:o,s=n}});if(!s)return e}}function ai(t,e){let i=null;for(let s=0;s<e.ranges.length;s++){let n=e.ranges[s],r=null;if(n.empty){let e=li(t,n.from,0);e!=n.from&&(r=o.cursor(e,-1))}else{let e=li(t,n.from,-1),i=li(t,n.to,1);e==n.from&&i==n.to||(r=o.range(n.from==n.anchor?e:i,n.from==n.head?e:i))}r&&(i||(i=e.ranges.slice()),i[s]=r)}return i?o.create(i,e.mainIndex):e}function hi(t,e,i){let s=li(t.state.facet(xe).map(e=>e(t)),i.from,e.head>i.from?-1:1);return s==i.from?i:o.cursor(s,s<i.from?1:-1)}class ci{constructor(t,e){this.pos=t,this.assoc=e}}function di(t,e,i,s){let o,n=t.contentDOM.getBoundingClientRect(),r=n.top+t.viewState.paddingTop,{x:l,y:a}=e,h=a-r;for(;;){if(h<0)return new ci(0,1);if(h>t.viewState.docHeight)return new ci(t.state.doc.length,-1);if(o=t.elementAtHeight(h),null==s)break;if(o.type==Z.Text){let e=t.docView.coordsAt(s<0?o.from:o.to,s);if(e&&(s<0?e.top<=h+r:e.bottom>=h+r))break}let e=t.viewState.heightOracle.textHeight/2;h=s>0?o.bottom+e:o.top-e}if(t.viewport.from>=o.to||t.viewport.to<=o.from){if(i)return null;if(o.type==Z.Text){let e=function(t,e,i,s,o){let n=Math.round((s-e.left)*t.defaultCharacterWidth);if(t.lineWrapping&&i.height>1.5*t.defaultLineHeight){let e=t.viewState.heightOracle.textHeight;n+=Math.floor((o-i.top-.5*(t.defaultLineHeight-e))/e)*t.viewState.heightOracle.lineLength}let r=t.state.sliceDoc(i.from,i.to);return i.from+b(r,n,t.state.tabSize)}(t,n,o,l,a);return new ci(e,e==o.from?1:-1)}}if(o.type!=Z.Text)return h<(o.top+o.bottom)/2?new ci(o.from,1):new ci(o.to,-1);let c=t.docView.lineAt(o.from,2);return c&&c.length==o.length||(c=t.docView.lineAt(o.from,-2)),ui(t,c,o.from,l,a)}function ui(t,e,i,s,o){let n=-1,r=null,l=1e9,h=1e9,c=o,d=o,u=(t,e)=>{for(let i=0;i<t.length;i++){let a=t[i];if(a.top==a.bottom)continue;let u=a.left>s?a.left-s:a.right<s?s-a.right:0,f=a.top>o?a.top-o:a.bottom<o?o-a.bottom:0;a.top<=d&&a.bottom>=c&&(c=Math.min(a.top,c),d=Math.max(a.bottom,d),f=0),(n<0||(f-h||u-l)<0)&&(n>=0&&h&&l<u&&r.top<=d-2&&r.bottom>=c+2?h=0:(n=e,l=u,h=f,r=a))}};if(e.isText()){for(let t=0;t<e.length;){let i=a(e.text,t);if(u(Ct(e.dom,t,i).getClientRects(),t),!l&&!h)break;t=i}return s>(r.left+r.right)/2==(fi(t,n+i)==Ot.LTR)?new ci(i+a(e.text,n),-1):new ci(i+n,1)}{if(!e.length)return new ci(i,1);for(let t=0;t<e.children.length;t++){let i=e.children[t];if(!(48&i.flags)&&(u((1==i.dom.nodeType?i.dom:Ct(i.dom,0,i.length)).getClientRects(),t),!l&&!h))break}let a=e.children[n],c=e.posBefore(a,i);return a.isComposite()||a.isText()?ui(t,a,c,Math.max(r.left,Math.min(r.right,s)),o):s>(r.left+r.right)/2==(fi(t,n+i)==Ot.LTR)?new ci(c+a.length,-1):new ci(c,1)}}function fi(t,e){let i=t.state.doc.lineAt(e);return t.bidiSpans(i)[Ft.find(t.bidiSpans(i),e-i.from,-1,1)].dir}const pi="￿";class gi{constructor(t,e){this.points=t,this.view=e,this.text="",this.lineSeparator=e.state.facet(i.lineSeparator)}append(t){this.text+=t}lineBreak(){this.text+=pi}readRange(t,e){if(!t)return this;let i=t.parentNode;for(let s=t;;){this.findPointBefore(i,s);let t=this.text.length;this.readNode(s);let o=Le.get(s),n=s.nextSibling;if(n==e){(null==o?void 0:o.breakAfter)&&!n&&i!=this.view.contentDOM&&this.lineBreak();break}let r=Le.get(n);(o&&r?o.breakAfter:(o?o.breakAfter:ft(s))||ft(n)&&("BR"!=s.nodeName||(null==o?void 0:o.isWidget()))&&this.text.length>t)&&!vi(n,e)&&this.lineBreak(),s=n}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 o,n=-1,r=1;if(this.lineSeparator?(n=e.indexOf(this.lineSeparator,i),r=this.lineSeparator.length):(o=s.exec(e))&&(n=o.index,r=o[0].length),this.append(e.slice(i,n<0?e.length:n)),n<0)break;if(this.lineBreak(),r>1)for(let e of this.points)e.node==t&&e.pos>this.text.length&&(e.pos-=r-1);i=n+r}}readNode(t){let e=Le.get(t),i=e&&e.overrideDOMText;if(null!=i){this.findPointInside(t,i.length);for(let t=i.iter();!t.next().done;)t.lineBreak?this.lineBreak():this.append(t.value)}else 3==t.nodeType?this.readTextNode(t):"BR"==t.nodeName?t.nextSibling&&this.lineBreak():1==t.nodeType&&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)(3==t.nodeType?i.node==t:t.contains(i.node))&&(i.pos=this.text.length+(mi(t,i.node,i.offset)?e:0))}}function mi(t,e,i){for(;;){if(!e||i<gt(e))return!1;if(e==t)return!0;i=ut(e)+1,e=e.parentNode}}function vi(t,e){let i;for(;t!=e&&t;t=t.nextSibling){let e=Le.get(t);if(!(null==e?void 0:e.isWidget()))return!1;e&&(i||(i=[])).push(e)}if(i)for(let t of i){let e=t.overrideDOMText;if(null==e?void 0:e.length)return!1}return!0}class wi{constructor(t,e){this.node=t,this.offset=e,this.pos=-1}}class bi{constructor(t,e,i,s){this.typeOver=s,this.bounds=null,this.text="",this.domChanged=e>-1;let{impreciseHead:n,impreciseAnchor:r}=t.docView;if(t.state.readOnly&&e>-1)this.newSel=null;else if(e>-1&&(this.bounds=yi(t.docView.tile,e,i,0))){let e=n||r?[]:function(t){let e=[];if(t.root.activeElement!=t.contentDOM)return e;let{anchorNode:i,anchorOffset:s,focusNode:o,focusOffset:n}=t.observer.selectionRange;i&&(e.push(new wi(i,s)),o==i&&n==s||e.push(new wi(o,n)));return e}(t),i=new gi(e,t);i.readRange(this.bounds.startDOM,this.bounds.endDOM),this.text=i.text,this.newSel=function(t,e){if(0==t.length)return null;let i=t[0].pos,s=2==t.length?t[1].pos:i;return i>-1&&s>-1?o.single(i+e,s+e):null}(e,this.bounds.from)}else{let e=t.observer.selectionRange,i=n&&n.node==e.focusNode&&n.offset==e.focusOffset||!at(t.contentDOM,e.focusNode)?t.state.selection.main.head:t.docView.posFromDOM(e.focusNode,e.focusOffset),s=r&&r.node==e.anchorNode&&r.offset==e.anchorOffset||!at(t.contentDOM,e.anchorNode)?t.state.selection.main.anchor:t.docView.posFromDOM(e.anchorNode,e.anchorOffset),l=t.viewport;if((j.ios||j.chrome)&&t.state.selection.main.empty&&i!=s&&(l.from>0||l.to<t.state.doc.length)){let e=Math.min(i,s),o=Math.max(i,s),n=l.from-e,r=l.to-o;0!=n&&1!=n&&0!=e||0!=r&&-1!=r&&o!=t.state.doc.length||(i=0,s=t.state.doc.length)}t.inputState.composing>-1&&t.state.selection.ranges.length>1?this.newSel=t.state.selection.replaceRange(o.range(s,i)):this.newSel=o.single(s,i)}}}function yi(t,e,i,s){if(t.isComposite()){let o=-1,n=-1,r=-1,l=-1;for(let a=0,h=s,c=s;a<t.children.length;a++){let s=t.children[a],d=h+s.length;if(h<e&&d>i)return yi(s,e,i,h);if(d>=e&&-1==o&&(o=a,n=h),h>i&&s.dom.parentNode==t.dom){r=a,l=c;break}c=d,h=d+s.breakAfter}return{from:n,to:l<0?s+t.length:l,startDOM:(o?t.children[o-1].dom.nextSibling:null)||t.dom.firstChild,endDOM:r<t.children.length&&r>=0?t.children[r].dom:null}}return t.isText()?{from:s,to:s+t.length,startDOM:t.dom,endDOM:t.dom.nextSibling}:null}function xi(t,e){let i,{newSel:s}=e,n=t.state.selection.main,r=t.inputState.lastKeyTime>Date.now()-100?t.inputState.lastKeyCode:-1;if(e.bounds){let{from:s,to:o}=e.bounds,l=n.from,a=null;(8===r||j.android&&e.text.length<o-s)&&(l=n.to,a="end");let c=Ci(t.state.doc.sliceString(s,o,pi),e.text,l-s,a);c&&(j.chrome&&13==r&&c.toB==c.from+2&&e.text.slice(c.from,c.toB)==pi+pi&&c.toB--,i={from:s+c.from,to:s+c.toA,insert:h.of(e.text.slice(c.from,c.toB).split(pi))})}else s&&(!t.hasFocus&&t.state.facet(de)||Mi(s,n))&&(s=null);if(!i&&!s)return!1;if(!i&&e.typeOver&&!n.empty&&s&&s.main.empty?i={from:n.from,to:n.to,insert:t.state.doc.slice(n.from,n.to)}:(j.mac||j.android)&&i&&i.from==i.to&&i.from==n.head-1&&/^\. ?$/.test(i.insert.toString())&&"off"==t.contentDOM.getAttribute("autocorrect")?(s&&2==i.insert.length&&(s=o.single(s.main.anchor-1,s.main.head-1)),i={from:i.from,to:i.to,insert:h.of([i.insert.toString().replace("."," ")])}):i&&i.from>=n.from&&i.to<=n.to&&(i.from!=n.from||i.to!=n.to)&&n.to-n.from-(i.to-i.from)<=4?i={from:n.from,to:n.to,insert:t.state.doc.slice(n.from,i.from).append(i.insert).append(t.state.doc.slice(i.to,n.to))}:t.state.doc.lineAt(n.from).to<n.to&&t.docView.lineHasWidget(n.to)&&t.inputState.insertingTextAt>Date.now()-50?i={from:n.from,to:n.to,insert:t.state.toText(t.inputState.insertingText)}:j.chrome&&i&&i.from==i.to&&i.from==n.head&&"\n "==i.insert.toString()&&t.lineWrapping&&(s&&(s=o.single(s.main.anchor-1,s.main.head-1)),i={from:n.from,to:n.to,insert:h.of([" "])}),i)return Si(t,i,s,r);if(s&&!Mi(s,n)){let e=!1,i="select";return t.inputState.lastSelectionTime>Date.now()-50&&("select"==t.inputState.lastSelectionOrigin&&(e=!0),i=t.inputState.lastSelectionOrigin,"select.pointer"==i&&(s=ai(t.state.facet(xe).map(e=>e(t)),s))),t.dispatch({selection:s,scrollIntoView:e,userEvent:i}),!0}return!1}function Si(t,e,i,s=-1){if(j.ios&&t.inputState.flushIOSKey(e))return!0;let n=t.state.selection.main;if(j.android&&(e.to==n.to&&(e.from==n.from||e.from==n.from-1&&" "==t.state.sliceDoc(e.from,n.from))&&1==e.insert.length&&2==e.insert.lines&&Mt(t.contentDOM,"Enter",13)||(e.from==n.from-1&&e.to==n.to&&0==e.insert.length||8==s&&e.insert.length<e.to-e.from&&e.to>n.head)&&Mt(t.contentDOM,"Backspace",8)||e.from==n.from&&e.to==n.to+1&&0==e.insert.length&&Mt(t.contentDOM,"Delete",46)))return!0;let r,l=e.insert.toString();t.inputState.composing>=0&&t.inputState.composing++;let a=()=>r||(r=function(t,e,i){let s,n=t.state,r=n.selection.main,l=-1;if(e.from==e.to&&e.from<r.from||e.from>r.to){let i=e.from<r.from?-1:1,s=i<0?r.from:r.to,o=li(n.facet(xe).map(e=>e(t)),s,i);e.from==o&&(l=o)}if(l>-1)s={changes:e,selection:o.cursor(e.from+e.insert.length,-1)};else if(e.from>=r.from&&e.to<=r.to&&e.to-e.from>=(r.to-r.from)/3&&(!i||i.main.empty&&i.main.from==e.from+e.insert.length)&&t.inputState.composing<0){let i=r.from<e.from?n.sliceDoc(r.from,e.from):"",o=r.to>e.to?n.sliceDoc(e.to,r.to):"";s=n.replaceSelection(t.state.toText(i+e.insert.sliceString(0,void 0,t.state.lineBreak)+o))}else{let l=n.changes(e),a=i&&i.main.to<=l.newLength?i.main:void 0;if(n.selection.ranges.length>1&&(t.inputState.composing>=0||t.inputState.compositionPendingChange)&&e.to<=r.to+10&&e.to>=r.to-10){let h,c=t.state.sliceDoc(e.from,e.to),d=i&&ei(t,i.main.head);if(d){let t=e.insert.length-(e.to-e.from);h={from:d.from,to:d.to-t}}else h=t.state.doc.lineAt(r.head);let u=r.to-e.to;s=n.changeByRange(i=>{if(i.from==r.from&&i.to==r.to)return{changes:l,range:a||i.map(l)};let s=i.to-u,d=s-c.length;if(t.state.sliceDoc(d,s)!=c||s>=h.from&&d<=h.to)return{range:i};let f=n.changes({from:d,to:s,insert:e.insert}),p=i.to-r.to;return{changes:f,range:a?o.range(Math.max(0,a.anchor+p),Math.max(0,a.head+p)):i.map(f)}})}else s={changes:l,selection:a&&n.selection.replaceRange(a)}}let a="input.type";(t.composing||t.inputState.compositionPendingChange&&t.inputState.compositionEndedAt>Date.now()-50)&&(t.inputState.compositionPendingChange=!1,a+=".compose",t.inputState.compositionFirstChange&&(a+=".start",t.inputState.compositionFirstChange=!1));return n.update(s,{userEvent:a,scrollIntoView:!0})}(t,e,i));return t.state.facet(te).some(i=>i(t,e.from,e.to,l,a))||t.dispatch(a()),!0}function Ci(t,e,i,s){let o=Math.min(t.length,e.length),n=0;for(;n<o&&t.charCodeAt(n)==e.charCodeAt(n);)n++;if(n==o&&t.length==e.length)return null;let r=t.length,l=e.length;for(;r>0&&l>0&&t.charCodeAt(r-1)==e.charCodeAt(l-1);)r--,l--;if("end"==s){i-=r+Math.max(0,n-Math.min(r,l))-n}if(r<n&&t.length<e.length){n-=i<=n&&i>=r?n-i:0,l=n+(l-r),r=n}else if(l<n){n-=i<=n&&i>=l?n-i:0,r=n+(r-l),l=n}return{from:n,toA:r,toB:l}}function Mi(t,e){return e.head==t.main.head&&e.anchor==t.main.anchor}class ki{setSelectionOrigin(t){this.lastSelectionOrigin=t,this.lastSelectionTime=Date.now()}constructor(t){this.view=t,this.lastKeyCode=0,this.lastKeyTime=0,this.lastTouchTime=0,this.lastFocusTime=0,this.lastScrollTop=0,this.lastScrollLeft=0,this.pendingIOSKey=void 0,this.tabFocusMode=-1,this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastContextMenu=0,this.scrollHandlers=[],this.handlers=Object.create(null),this.composing=-1,this.compositionFirstChange=null,this.compositionEndedAt=0,this.compositionPendingKey=!1,this.compositionPendingChange=!1,this.insertingText="",this.insertingTextAt=0,this.mouseSelection=null,this.draggedContent=null,this.handleEvent=this.handleEvent.bind(this),this.notifiedFocused=t.hasFocus,j.safari&&t.contentDOM.addEventListener("input",()=>null),j.gecko&&function(t){Ui.has(t)||(Ui.add(t),t.addEventListener("copy",()=>{}),t.addEventListener("cut",()=>{}))}(t.contentDOM.ownerDocument)}handleEvent(t){(function(t,e){if(!e.bubbles)return!0;if(e.defaultPrevented)return!1;for(let i,s=e.target;s!=t.contentDOM;s=s.parentNode)if(!s||11==s.nodeType||(i=Le.get(s))&&i.isWidget()&&!i.isHidden&&i.widget.ignoreEvent(e))return!1;return!0})(this.view,t)&&!this.ignoreDuringComposition(t)&&("keydown"==t.type&&this.keydown(t)||(0!=this.view.updateState?Promise.resolve().then(()=>this.runHandlers(t.type,t)):this.runHandlers(t.type,t)))}runHandlers(t,e){let i=this.handlers[t];if(i){for(let t of i.observers)t(this.view,e);for(let t of i.handlers){if(e.defaultPrevented)break;if(t(this.view,e)){e.preventDefault();break}}}}ensureHandlers(t){let e=Ti(t),i=this.handlers,s=this.view.contentDOM;for(let t in e)if("scroll"!=t){let o=!e[t].handlers.length,n=i[t];n&&o!=!n.handlers.length&&(s.removeEventListener(t,this.handleEvent),n=null),n||s.addEventListener(t,this.handleEvent,{passive:o})}for(let t in i)"scroll"==t||e[t]||s.removeEventListener(t,this.handleEvent);this.handlers=e}keydown(t){if(this.lastKeyCode=t.keyCode,this.lastKeyTime=Date.now(),9==t.keyCode&&this.tabFocusMode>-1&&(!this.tabFocusMode||Date.now()<=this.tabFocusMode))return!0;if(this.tabFocusMode>0&&27!=t.keyCode&&Li.indexOf(t.keyCode)<0&&(this.tabFocusMode=-1),j.android&&j.chrome&&!t.synthetic&&(13==t.keyCode||8==t.keyCode))return this.view.observer.delayAndroidKey(t.key,t.keyCode),!0;let e;return!j.ios||t.synthetic||t.altKey||t.metaKey||!((e=Di.find(e=>e.keyCode==t.keyCode))&&!t.ctrlKey||Oi.indexOf(t.key)>-1&&t.ctrlKey&&!t.shiftKey)?(229!=t.keyCode&&this.view.observer.forceFlush(),!1):(this.pendingIOSKey=e||t,setTimeout(()=>this.flushIOSKey(),250),!0)}flushIOSKey(t){let e=this.pendingIOSKey;return!!e&&(!("Enter"==e.key&&t&&t.from<t.to&&/^\S+$/.test(t.insert.toString()))&&(this.pendingIOSKey=void 0,Mt(this.view.contentDOM,e.key,e.keyCode,e instanceof KeyboardEvent?e:void 0)))}ignoreDuringComposition(t){return!(!/^key/.test(t.type)||t.synthetic)&&(this.composing>0||!!(j.safari&&!j.ios&&this.compositionPendingKey&&Date.now()-this.compositionEndedAt<100)&&(this.compositionPendingKey=!1,!0))}startMouseSelection(t){this.mouseSelection&&this.mouseSelection.destroy(),this.mouseSelection=t}update(t){this.view.observer.update(t),this.mouseSelection&&this.mouseSelection.update(t),this.draggedContent&&t.docChanged&&(this.draggedContent=this.draggedContent.map(t.changes)),t.transactions.length&&(this.lastKeyCode=this.lastSelectionTime=0)}destroy(){this.mouseSelection&&this.mouseSelection.destroy()}}function Ai(t,e){return(i,s)=>{try{return e.call(t,s,i)}catch(t){ce(i.state,t)}}}function Ti(t){let e=Object.create(null);function i(t){return e[t]||(e[t]={observers:[],handlers:[]})}for(let e of t){let t=e.spec,s=t&&t.plugin.domEventHandlers,o=t&&t.plugin.domEventObservers;if(s)for(let t in s){let o=s[t];o&&i(t).handlers.push(Ai(e.value,o))}if(o)for(let t in o){let s=o[t];s&&i(t).observers.push(Ai(e.value,s))}}for(let t in Ri)i(t).handlers.push(Ri[t]);for(let t in Hi)i(t).observers.push(Hi[t]);return e}const Di=[{key:"Backspace",keyCode:8,inputType:"deleteContentBackward"},{key:"Enter",keyCode:13,inputType:"insertParagraph"},{key:"Enter",keyCode:13,inputType:"insertLineBreak"},{key:"Delete",keyCode:46,inputType:"deleteContentForward"}],Oi="dthko",Li=[16,17,18,20,91,92,224,225];function Bi(t){return.7*Math.max(0,t)+8}class Ei{constructor(t,e,s,o){this.view=t,this.startEvent=e,this.style=s,this.mustSelect=o,this.scrollSpeed={x:0,y:0},this.scrolling=-1,this.lastEvent=e,this.scrollParents=function(t){let e,i,s=t.ownerDocument;for(let o=t.parentNode;o&&!(o==s.body||e&&i);)if(1==o.nodeType)!i&&o.scrollHeight>o.clientHeight&&(i=o),!e&&o.scrollWidth>o.clientWidth&&(e=o),o=o.assignedSlot||o.parentNode;else{if(11!=o.nodeType)break;o=o.host}return{x:e,y:i}}(t.contentDOM),this.atoms=t.state.facet(xe).map(e=>e(t));let n=t.contentDOM.ownerDocument;n.addEventListener("mousemove",this.move=this.move.bind(this)),n.addEventListener("mouseup",this.up=this.up.bind(this)),this.extend=e.shiftKey,this.multiple=t.state.facet(i.allowMultipleSelections)&&function(t,e){let i=t.state.facet(Ut);return i.length?i[0](e):j.mac?e.metaKey:e.ctrlKey}(t,e),this.dragging=!(!function(t,e){let{main:i}=t.state.selection;if(i.empty)return!1;let s=lt(t.root);if(!s||0==s.rangeCount)return!0;let o=s.getRangeAt(0).getClientRects();for(let t=0;t<o.length;t++){let i=o[t];if(i.left<=e.clientX&&i.right>=e.clientX&&i.top<=e.clientY&&i.bottom>=e.clientY)return!0}return!1}(t,e)||1!=Ki(e))&&null}start(t){!1===this.dragging&&this.select(t)}move(t){if(0==t.buttons)return this.destroy();if(this.dragging||null==this.dragging&&(e=this.startEvent,i=t,Math.max(Math.abs(e.clientX-i.clientX),Math.abs(e.clientY-i.clientY))<10))return;var e,i;this.select(this.lastEvent=t);let s=0,o=0,n=0,r=0,l=this.view.win.innerWidth,a=this.view.win.innerHeight;this.scrollParents.x&&({left:n,right:l}=this.scrollParents.x.getBoundingClientRect()),this.scrollParents.y&&({top:r,bottom:a}=this.scrollParents.y.getBoundingClientRect());let h=ke(this.view);t.clientX-h.left<=n+6?s=-Bi(n-t.clientX):t.clientX+h.right>=l-6&&(s=Bi(t.clientX-l)),t.clientY-h.top<=r+6?o=-Bi(r-t.clientY):t.clientY+h.bottom>=a-6&&(o=Bi(t.clientY-a)),this.setScrollSpeed(s,o)}up(t){null==this.dragging&&this.select(this.lastEvent),this.dragging||t.preventDefault(),this.destroy()}destroy(){this.setScrollSpeed(0,0);let t=this.view.contentDOM.ownerDocument;t.removeEventListener("mousemove",this.move),t.removeEventListener("mouseup",this.up),this.view.inputState.mouseSelection=this.view.inputState.draggedContent=null}setScrollSpeed(t,e){this.scrollSpeed={x:t,y:e},t||e?this.scrolling<0&&(this.scrolling=setInterval(()=>this.scroll(),50)):this.scrolling>-1&&(clearInterval(this.scrolling),this.scrolling=-1)}scroll(){let{x:t,y:e}=this.scrollSpeed;t&&this.scrollParents.x&&(this.scrollParents.x.scrollLeft+=t,t=0),e&&this.scrollParents.y&&(this.scrollParents.y.scrollTop+=e,e=0),(t||e)&&this.view.win.scrollBy(t,e),!1===this.dragging&&this.select(this.lastEvent)}select(t){let{view:e}=this,i=ai(this.atoms,this.style.get(t,this.extend,this.multiple));!this.mustSelect&&i.eq(e.state.selection,!1===this.dragging)||this.view.dispatch({selection:i,userEvent:"select.pointer"}),this.mustSelect=!1}update(t){t.transactions.some(t=>t.isUserEvent("input.type"))?this.destroy():this.style.update(t)&&setTimeout(()=>this.select(this.lastEvent),20)}}const Ri=Object.create(null),Hi=Object.create(null),Wi=j.ie&&j.ie_version<15||j.ios&&j.webkit_version<604;function Ni(t,e,i){for(let s of t.facet(e))i=s(i,t);return i}function Pi(t,e){e=Ni(t.state,ie,e);let i,{state:s}=t,n=1,r=s.toText(e),l=r.lines==s.selection.ranges.length;if(null!=Yi&&s.selection.ranges.every(t=>t.empty)&&Yi==r.toString()){let t=-1;i=s.changeByRange(i=>{let a=s.doc.lineAt(i.from);if(a.from==t)return{range:i};t=a.from;let h=s.toText((l?r.line(n++).text:e)+s.lineBreak);return{changes:{from:a.from,insert:h},range:o.cursor(i.from+h.length)}})}else i=l?s.changeByRange(t=>{let e=r.line(n++);return{changes:{from:t.from,to:t.to,insert:e.text},range:o.cursor(t.from+e.length)}}):s.replaceSelection(r);t.dispatch(i,{userEvent:"input.paste",scrollIntoView:!0})}function Vi(t,e,i,s){if(1==s)return o.cursor(e,i);if(2==s)return function(t,e,i=1){let s=t.charCategorizer(e),n=t.doc.lineAt(e),r=e-n.from;if(0==n.length)return o.cursor(e);0==r?i=1:r==n.length&&(i=-1);let l=r,h=r;i<0?l=a(n.text,r,!1):h=a(n.text,r);let c=s(n.text.slice(l,h));for(;l>0;){let t=a(n.text,l,!1);if(s(n.text.slice(t,l))!=c)break;l=t}for(;h<n.length;){let t=a(n.text,h);if(s(n.text.slice(h,t))!=c)break;h=t}return o.range(l+n.from,h+n.from)}(t.state,e,i);{let s=t.docView.lineAt(e,i),n=t.state.doc.lineAt(s?s.posAtEnd:e),r=s?s.posAtStart:n.from,l=s?s.posAtEnd:n.to;return l<t.state.doc.length&&l==n.to&&l++,o.range(r,l)}}Hi.scroll=t=>{t.inputState.lastScrollTop=t.scrollDOM.scrollTop,t.inputState.lastScrollLeft=t.scrollDOM.scrollLeft},Ri.keydown=(t,e)=>(t.inputState.setSelectionOrigin("select"),27==e.keyCode&&0!=t.inputState.tabFocusMode&&(t.inputState.tabFocusMode=Date.now()+2e3),!1),Hi.touchstart=(t,e)=>{t.inputState.lastTouchTime=Date.now(),t.inputState.setSelectionOrigin("select.pointer")},Hi.touchmove=t=>{t.inputState.setSelectionOrigin("select.pointer")},Ri.mousedown=(t,e)=>{if(t.observer.flush(),t.inputState.lastTouchTime>Date.now()-2e3)return!1;let i=null;for(let s of t.state.facet(Qt))if(i=s(t,e),i)break;if(i||0!=e.button||(i=function(t,e){let i=t.posAndSideAtCoords({x:e.clientX,y:e.clientY},!1),s=Ki(e),n=t.state.selection;return{update(t){t.docChanged&&(i.pos=t.changes.mapPos(i.pos),n=n.map(t.changes))},get(e,r,l){let a,h=t.posAndSideAtCoords({x:e.clientX,y:e.clientY},!1),c=Vi(t,h.pos,h.assoc,s);if(i.pos!=h.pos&&!r){let e=Vi(t,i.pos,i.assoc,s),n=Math.min(e.from,c.from),r=Math.max(e.to,c.to);c=n<c.from?o.range(n,r):o.range(r,n)}return r?n.replaceRange(n.main.extend(c.from,c.to)):l&&1==s&&n.ranges.length>1&&(a=function(t,e){for(let i=0;i<t.ranges.length;i++){let{from:s,to:n}=t.ranges[i];if(s<=e&&n>=e)return o.create(t.ranges.slice(0,i).concat(t.ranges.slice(i+1)),t.mainIndex==i?0:t.mainIndex-(t.mainIndex>i?1:0))}return null}(n,h.pos))?a:l?n.addRange(c):o.create([c])}}}(t,e)),i){let s=!t.hasFocus;t.inputState.startMouseSelection(new Ei(t,e,i,s)),s&&t.observer.ignore(()=>{St(t.contentDOM);let e=t.root.activeElement;e&&!e.contains(t.contentDOM)&&e.blur()});let o=t.inputState.mouseSelection;if(o)return o.start(e),!1===o.dragging}else t.inputState.setSelectionOrigin("select.pointer");return!1};const Fi=j.ie&&j.ie_version<=11;let zi=null,Ii=0,qi=0;function Ki(t){if(!Fi)return t.detail;let e=zi,i=qi;return zi=t,qi=Date.now(),Ii=!e||i>Date.now()-400&&Math.abs(e.clientX-t.clientX)<2&&Math.abs(e.clientY-t.clientY)<2?(Ii+1)%3:1}function _i(t,e,i,s){if(!(i=Ni(t.state,ie,i)))return;let o=t.posAtCoords({x:e.clientX,y:e.clientY},!1),{draggedContent:n}=t.inputState,r=s&&n&&function(t,e){let i=t.state.facet($t);return i.length?i[0](e):j.mac?!e.altKey:!e.ctrlKey}(t,e)?{from:n.from,to:n.to}:null,l={from:o,insert:i},a=t.state.changes(r?[r,l]:l);t.focus(),t.dispatch({changes:a,selection:{anchor:a.mapPos(o,-1),head:a.mapPos(o,1)},userEvent:r?"move.drop":"input.drop"}),t.inputState.draggedContent=null}Ri.dragstart=(t,e)=>{let{selection:{main:i}}=t.state;if(e.target.draggable){let s=t.docView.tile.nearest(e.target);if(s&&s.isWidget()){let t=s.posAtStart,e=t+s.length;(t>=i.to||e<=i.from)&&(i=o.range(t,e))}}let{inputState:s}=t;return s.mouseSelection&&(s.mouseSelection.dragging=!0),s.draggedContent=i,e.dataTransfer&&(e.dataTransfer.setData("Text",Ni(t.state,se,t.state.sliceDoc(i.from,i.to))),e.dataTransfer.effectAllowed="copyMove"),!1},Ri.dragend=t=>(t.inputState.draggedContent=null,!1),Ri.drop=(t,e)=>{if(!e.dataTransfer)return!1;if(t.state.readOnly)return!0;let i=e.dataTransfer.files;if(i&&i.length){let s=Array(i.length),o=0,n=()=>{++o==i.length&&_i(t,e,s.filter(t=>null!=t).join(t.state.lineBreak),!1)};for(let t=0;t<i.length;t++){let e=new FileReader;e.onerror=n,e.onload=()=>{/[\x00-\x08\x0e-\x1f]{2}/.test(e.result)||(s[t]=e.result),n()},e.readAsText(i[t])}return!0}{let i=e.dataTransfer.getData("Text");if(i)return _i(t,e,i,!0),!0}return!1},Ri.paste=(t,e)=>{if(t.state.readOnly)return!0;t.observer.flush();let i=Wi?null:e.clipboardData;return i?(Pi(t,i.getData("text/plain")||i.getData("text/uri-list")),!0):(function(t){let e=t.dom.parentNode;if(!e)return;let i=e.appendChild(document.createElement("textarea"));i.style.cssText="position: fixed; left: -10000px; top: 10px",i.focus(),setTimeout(()=>{t.focus(),i.remove(),Pi(t,i.value)},50)}(t),!1)};let Yi=null;Ri.copy=Ri.cut=(t,e)=>{let i=lt(t.root);if(i&&!ht(t.contentDOM,i))return!1;let{text:s,ranges:o,linewise:n}=function(t){let e=[],i=[],s=!1;for(let s of t.selection.ranges)s.empty||(e.push(t.sliceDoc(s.from,s.to)),i.push(s));if(!e.length){let o=-1;for(let{from:s}of t.selection.ranges){let n=t.doc.lineAt(s);n.number>o&&(e.push(n.text),i.push({from:n.from,to:Math.min(t.doc.length,n.to+1)})),o=n.number}s=!0}return{text:Ni(t,se,e.join(t.lineBreak)),ranges:i,linewise:s}}(t.state);if(!s&&!n)return!1;Yi=n?s:null,"cut"!=e.type||t.state.readOnly||t.dispatch({changes:o,scrollIntoView:!0,userEvent:"delete.cut"});let r=Wi?null:e.clipboardData;return r?(r.clearData(),r.setData("text/plain",s),!0):(function(t,e){let i=t.dom.parentNode;if(!i)return;let s=i.appendChild(document.createElement("textarea"));s.style.cssText="position: fixed; left: -10000px; top: 10px",s.value=e,s.focus(),s.selectionEnd=e.length,s.selectionStart=0,setTimeout(()=>{s.remove(),t.focus()},50)}(t,s),!1)};const ji=p.define();function Xi(t,e){let i=[];for(let s of t.facet(ee)){let o=s(t,e);o&&i.push(o)}return i.length?t.update({effects:i,annotations:ji.of(!0)}):null}function Gi(t){setTimeout(()=>{let e=t.hasFocus;if(e!=t.inputState.notifiedFocused){let i=Xi(t.state,e);i?t.dispatch(i):t.update([])}},10)}Hi.focus=t=>{t.inputState.lastFocusTime=Date.now(),t.scrollDOM.scrollTop||!t.inputState.lastScrollTop&&!t.inputState.lastScrollLeft||(t.scrollDOM.scrollTop=t.inputState.lastScrollTop,t.scrollDOM.scrollLeft=t.inputState.lastScrollLeft),Gi(t)},Hi.blur=t=>{t.observer.clearSelectionRange(),Gi(t)},Hi.compositionstart=Hi.compositionupdate=t=>{t.observer.editContext||(null==t.inputState.compositionFirstChange&&(t.inputState.compositionFirstChange=!0),t.inputState.composing<0&&(t.inputState.composing=0))},Hi.compositionend=t=>{t.observer.editContext||(t.inputState.composing=-1,t.inputState.compositionEndedAt=Date.now(),t.inputState.compositionPendingKey=!0,t.inputState.compositionPendingChange=t.observer.pendingRecords().length>0,t.inputState.compositionFirstChange=null,j.chrome&&j.android?t.observer.flushSoon():t.inputState.compositionPendingChange?Promise.resolve().then(()=>t.observer.flush()):setTimeout(()=>{t.inputState.composing<0&&t.docView.hasComposition&&t.update([])},50))},Hi.contextmenu=t=>{t.inputState.lastContextMenu=Date.now()},Ri.beforeinput=(t,e)=>{var i,s;if("insertText"!=e.inputType&&"insertCompositionText"!=e.inputType||(t.inputState.insertingText=e.data,t.inputState.insertingTextAt=Date.now()),"insertReplacementText"==e.inputType&&t.observer.editContext){let s=null===(i=e.dataTransfer)||void 0===i?void 0:i.getData("text/plain"),o=e.getTargetRanges();if(s&&o.length){let e=o[0],i=t.posAtDOM(e.startContainer,e.startOffset),n=t.posAtDOM(e.endContainer,e.endOffset);return Si(t,{from:i,to:n,insert:t.state.toText(s)},null),!0}}let o;if(j.chrome&&j.android&&(o=Di.find(t=>t.inputType==e.inputType))&&(t.observer.delayAndroidKey(o.key,o.keyCode),"Backspace"==o.key||"Delete"==o.key)){let e=(null===(s=window.visualViewport)||void 0===s?void 0:s.height)||0;setTimeout(()=>{var i;((null===(i=window.visualViewport)||void 0===i?void 0:i.height)||0)>e+10&&t.hasFocus&&(t.contentDOM.blur(),t.focus())},100)}return j.ios&&"deleteContentForward"==e.inputType&&t.observer.flushSoon(),j.safari&&"insertText"==e.inputType&&t.inputState.composing>=0&&setTimeout(()=>Hi.compositionend(t,e),20),!1};const Ui=new Set;const $i=["pre-wrap","normal","pre-line","break-spaces"];let Qi=!1;function Ji(){Qi=!1}class Zi{constructor(t){this.lineWrapping=t,this.doc=h.empty,this.heightSamples={},this.lineHeight=14,this.charWidth=7,this.textHeight=14,this.lineLength=30}heightForGap(t,e){let i=this.doc.lineAt(e).number-this.doc.lineAt(t).number+1;return this.lineWrapping&&(i+=Math.max(0,Math.ceil((e-t-i*this.lineLength*.5)/this.lineLength))),this.lineHeight*i}heightForLine(t){if(!this.lineWrapping)return this.lineHeight;return(1+Math.max(0,Math.ceil((t-this.lineLength)/Math.max(1,this.lineLength-5))))*this.lineHeight}setDoc(t){return this.doc=t,this}mustRefreshForWrapping(t){return $i.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(10*s)]||(e=!0,this.heightSamples[Math.floor(10*s)]=!0)}return e}refresh(t,e,i,s,o,n){let r=$i.indexOf(t)>-1,l=Math.abs(e-this.lineHeight)>.3||this.lineWrapping!=r||Math.abs(i-this.charWidth)>.1;if(this.lineWrapping=r,this.lineHeight=e,this.charWidth=i,this.textHeight=s,this.lineLength=o,l){this.heightSamples={};for(let t=0;t<n.length;t++){let e=n[t];e<0?t++:this.heightSamples[Math.floor(10*e)]=!0}}return l}}class ts{constructor(t,e){this.from=t,this.heights=e,this.index=0}get more(){return this.index<this.heights.length}}class es{constructor(t,e,i,s,o){this.from=t,this.length=e,this.top=i,this.height=s,this._content=o}get type(){return"number"==typeof this._content?Z.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 st?this._content.widget:null}get widgetLineBreaks(){return"number"==typeof this._content?this._content:0}join(t){let e=(Array.isArray(this._content)?this._content:[this]).concat(Array.isArray(t._content)?t._content:[t]);return new es(this.from,this.length+t.length,this.top,this.height+t.height,e)}}var is=function(t){return t[t.ByPos=0]="ByPos",t[t.ByHeight=1]="ByHeight",t[t.ByPosNoHeight=2]="ByPosNoHeight",t}(is||(is={}));const ss=.001;class os{constructor(t,e,i=2){this.length=t,this.height=e,this.flags=i}get outdated(){return(2&this.flags)>0}set outdated(t){this.flags=(t?2:0)|-3&this.flags}setHeight(t){this.height!=t&&(Math.abs(this.height-t)>ss&&(Qi=!0),this.height=t)}replace(t,e,i){return os.of(i)}decomposeLeft(t,e){e.push(this)}decomposeRight(t,e){e.push(this)}applyChanges(t,e,i,s){let o=this,n=i.doc;for(let r=s.length-1;r>=0;r--){let{fromA:l,toA:a,fromB:h,toB:c}=s[r],d=o.lineAt(l,is.ByPosNoHeight,i.setDoc(e),0,0),u=d.to>=a?d:o.lineAt(a,is.ByPosNoHeight,i,0,0);for(c+=u.to-a,a=u.to;r>0&&d.from<=s[r-1].toA;)l=s[r-1].fromA,h=s[r-1].fromB,r--,l<d.from&&(d=o.lineAt(l,is.ByPosNoHeight,i,0,0));h+=d.from-l,l=d.from;let f=us.build(i.setDoc(n),t,h,c);o=ns(o,o.replace(l,a,f))}return o.updateHeight(i,0)}static empty(){return new as(0,0,0)}static of(t){if(1==t.length)return t[0];let e=0,i=t.length,s=0,o=0;for(;;)if(e==i)if(s>2*o){let o=t[e-1];o.break?t.splice(--e,1,o.left,null,o.right):t.splice(--e,1,o.left,o.right),i+=1+o.break,s-=o.size}else{if(!(o>2*s))break;{let e=t[i];e.break?t.splice(i,1,e.left,null,e.right):t.splice(i,1,e.left,e.right),i+=2+e.break,o-=e.size}}else if(s<o){let i=t[e++];i&&(s+=i.size)}else{let e=t[--i];e&&(o+=e.size)}let n=0;return null==t[e-1]?(n=1,e--):null==t[e]&&(n=1,i++),new cs(os.of(t.slice(0,e)),n,os.of(t.slice(i)))}}function ns(t,e){return t==e?t:(t.constructor!=e.constructor&&(Qi=!0),e)}os.prototype.size=1;const rs=tt.replace({});class ls extends os{constructor(t,e,i){super(t,e),this.deco=i,this.spaceAbove=0}mainBlock(t,e){return new es(e,this.length,t+this.spaceAbove,this.height-this.spaceAbove,this.deco||0)}blockAt(t,e,i,s){return this.spaceAbove&&t<i+this.spaceAbove?new es(s,0,i,this.spaceAbove,rs):this.mainBlock(i,s)}lineAt(t,e,i,s,o){let n=this.mainBlock(s,o);return this.spaceAbove?this.blockAt(0,i,s,o).join(n):n}forEachLine(t,e,i,s,o,n){t<=o+this.length&&e>=o&&n(this.lineAt(0,is.ByPos,i,s,o))}setMeasuredHeight(t){let e=t.heights[t.index++];e<0?(this.spaceAbove=-e,e=t.heights[t.index++]):this.spaceAbove=0,this.setHeight(e)}updateHeight(t,e=0,i=!1,s){return s&&s.from<=e&&s.more&&this.setMeasuredHeight(s),this.outdated=!1,this}toString(){return`block(${this.length})`}}class as extends ls{constructor(t,e,i){super(t,e,null),this.collapsed=0,this.widgetHeight=0,this.breaks=0,this.spaceAbove=i}mainBlock(t,e){return new es(e,this.length,t+this.spaceAbove,this.height-this.spaceAbove,this.breaks)}replace(t,e,i){let s=i[0];return 1==i.length&&(s instanceof as||s instanceof hs&&4&s.flags)&&Math.abs(this.length-s.length)<10?(s instanceof hs?s=new as(s.length,this.height,this.spaceAbove):s.height=this.height,this.outdated||(s.outdated=!1),s):os.of(i)}updateHeight(t,e=0,i=!1,s){return s&&s.from<=e&&s.more?this.setMeasuredHeight(s):(i||this.outdated)&&(this.spaceAbove=0,this.setHeight(Math.max(this.widgetHeight,t.heightForLine(this.length-this.collapsed))+this.breaks*t.lineHeight)),this.outdated=!1,this}toString(){return`line(${this.length}${this.collapsed?-this.collapsed:""}${this.widgetHeight?":"+this.widgetHeight:""})`}}class hs extends os{constructor(t){super(t,0)}heightMetrics(t,e){let i,s=t.doc.lineAt(e).number,o=t.doc.lineAt(e+this.length).number,n=o-s+1,r=0;if(t.lineWrapping){let e=Math.min(this.height,t.lineHeight*n);i=e/n,this.length>n+1&&(r=(this.height-e)/(this.length-n-1))}else i=this.height/n;return{firstLine:s,lastLine:o,perLine:i,perChar:r}}blockAt(t,e,i,s){let{firstLine:o,lastLine:n,perLine:r,perChar:l}=this.heightMetrics(e,s);if(e.lineWrapping){let o=s+(t<e.lineHeight?0:Math.round(Math.max(0,Math.min(1,(t-i)/this.height))*this.length)),n=e.doc.lineAt(o),a=r+n.length*l,h=Math.max(i,t-a/2);return new es(n.from,n.length,h,a,0)}{let s=Math.max(0,Math.min(n-o,Math.floor((t-i)/r))),{from:l,length:a}=e.doc.line(o+s);return new es(l,a,i+r*s,r,0)}}lineAt(t,e,i,s,o){if(e==is.ByHeight)return this.blockAt(t,i,s,o);if(e==is.ByPosNoHeight){let{from:e,to:s}=i.doc.lineAt(t);return new es(e,s-e,0,0,0)}let{firstLine:n,perLine:r,perChar:l}=this.heightMetrics(i,o),a=i.doc.lineAt(t),h=r+a.length*l,c=a.number-n,d=s+r*c+l*(a.from-o-c);return new es(a.from,a.length,Math.max(s,Math.min(d,s+this.height-h)),h,0)}forEachLine(t,e,i,s,o,n){t=Math.max(t,o),e=Math.min(e,o+this.length);let{firstLine:r,perLine:l,perChar:a}=this.heightMetrics(i,o);for(let h=t,c=s;h<=e;){let e=i.doc.lineAt(h);if(h==t){let i=e.number-r;c+=l*i+a*(t-o-i)}let s=l+a*e.length;n(new es(e.from,e.length,c,s,0)),c+=s,h=e.to+1}}replace(t,e,i){let s=this.length-e;if(s>0){let t=i[i.length-1];t instanceof hs?i[i.length-1]=new hs(t.length+s):i.push(null,new hs(s-1))}if(t>0){let e=i[0];e instanceof hs?i[0]=new hs(t+e.length):i.unshift(new hs(t-1),null)}return os.of(i)}decomposeLeft(t,e){e.push(new hs(t-1),null)}decomposeRight(t,e){e.push(null,new hs(this.length-t-1))}updateHeight(t,e=0,i=!1,s){let o=e+this.length;if(s&&s.from<=e+this.length&&s.more){let i=[],n=Math.max(e,s.from),r=-1;for(s.from>e&&i.push(new hs(s.from-e-1).updateHeight(t,e));n<=o&&s.more;){let e=t.doc.lineAt(n).length;i.length&&i.push(null);let o=s.heights[s.index++],l=0;o<0&&(l=-o,o=s.heights[s.index++]),-1==r?r=o:Math.abs(o-r)>=ss&&(r=-2);let a=new as(e,o,l);a.outdated=!1,i.push(a),n+=e+1}n<=o&&i.push(null,new hs(o-n).updateHeight(t,n));let l=os.of(i);return(r<0||Math.abs(l.height-this.height)>=ss||Math.abs(r-this.heightMetrics(t,e).perLine)>=ss)&&(Qi=!0),ns(this,l)}return(i||this.outdated)&&(this.setHeight(t.heightForGap(e,e+this.length)),this.outdated=!1),this}toString(){return`gap(${this.length})`}}class cs extends os{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 1&this.flags}blockAt(t,e,i,s){let o=i+this.left.height;return t<o?this.left.blockAt(t,e,i,s):this.right.blockAt(t,e,o,s+this.left.length+this.break)}lineAt(t,e,i,s,o){let n=s+this.left.height,r=o+this.left.length+this.break,l=e==is.ByHeight?t<n:t<r,a=l?this.left.lineAt(t,e,i,s,o):this.right.lineAt(t,e,i,n,r);if(this.break||(l?a.to<r:a.from>r))return a;let h=e==is.ByPosNoHeight?is.ByPosNoHeight:is.ByPos;return l?a.join(this.right.lineAt(r,h,i,n,r)):this.left.lineAt(r,h,i,s,o).join(a)}forEachLine(t,e,i,s,o,n){let r=s+this.left.height,l=o+this.left.length+this.break;if(this.break)t<l&&this.left.forEachLine(t,e,i,s,o,n),e>=l&&this.right.forEachLine(t,e,i,r,l,n);else{let a=this.lineAt(l,is.ByPos,i,s,o);t<a.from&&this.left.forEachLine(t,a.from-1,i,s,o,n),a.to>=t&&a.from<=e&&n(a),e>a.to&&this.right.forEachLine(a.to+1,e,i,r,l,n)}}replace(t,e,i){let s=this.left.length+this.break;if(e<s)return this.balanced(this.left.replace(t,e,i),this.right);if(t>this.left.length)return this.balanced(this.left,this.right.replace(t-s,e-s,i));let o=[];t>0&&this.decomposeLeft(t,o);let n=o.length;for(let t of i)o.push(t);if(t>0&&ds(o,n-1),e<this.length){let t=o.length;this.decomposeRight(e,o),ds(o,t)}return os.of(o)}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?os.of(this.break?[t,null,e]:[t,e]):(this.left=ns(this.left,t),this.right=ns(this.right,e),this.setHeight(t.height+e.height),this.outdated=t.outdated||e.outdated,this.size=t.size+e.size,this.length=t.length+this.break+e.length,this)}updateHeight(t,e=0,i=!1,s){let{left:o,right:n}=this,r=e+o.length+this.break,l=null;return s&&s.from<=e+o.length&&s.more?l=o=o.updateHeight(t,e,i,s):o.updateHeight(t,e,i),s&&s.from<=r+n.length&&s.more?l=n=n.updateHeight(t,r,i,s):n.updateHeight(t,r,i),l?this.balanced(o,n):(this.height=this.left.height+this.right.height,this.outdated=!1,this)}toString(){return this.left+(this.break?" ":"-")+this.right}}function ds(t,e){let i,s;null==t[e]&&(i=t[e-1])instanceof hs&&(s=t[e+1])instanceof hs&&t.splice(e-1,3,new hs(i.length+1+s.length))}class us{constructor(t,e){this.pos=t,this.oracle=e,this.nodes=[],this.lineStart=-1,this.lineEnd=-1,this.covering=null,this.writtenTo=t}get isCovered(){return this.covering&&this.nodes[this.nodes.length-1]==this.covering}span(t,e){if(this.lineStart>-1){let t=Math.min(e,this.lineEnd),i=this.nodes[this.nodes.length-1];i instanceof as?i.length+=t-this.pos:(t>this.pos||!this.isCovered)&&this.nodes.push(new as(t-this.pos,-1,0)),this.writtenTo=t,e>t&&(this.nodes.push(null),this.writtenTo++,this.lineStart=-1)}this.pos=e}point(t,e,i){if(t<e||i.heightRelevant){let s=i.widget?i.widget.estimatedHeight:0,o=i.widget?i.widget.lineBreaks:0;s<0&&(s=this.oracle.lineHeight);let n=e-t;i.block?this.addBlock(new ls(n,s,i)):(n||o||s>=5)&&this.addLineDeco(s,o,n)}else e>t&&this.span(t,e);this.lineEnd>-1&&this.lineEnd<this.pos&&(this.lineEnd=this.oracle.doc.lineAt(this.pos).to)}enterLine(){if(this.lineStart>-1)return;let{from:t,to:e}=this.oracle.doc.lineAt(this.pos);this.lineStart=t,this.lineEnd=e,this.writtenTo<t&&((this.writtenTo<t-1||null==this.nodes[this.nodes.length-1])&&this.nodes.push(this.blankContent(this.writtenTo,t-1)),this.nodes.push(null)),this.pos>t&&this.nodes.push(new as(this.pos-t,-1,0)),this.writtenTo=this.pos}blankContent(t,e){let i=new hs(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 as)return t;let e=new as(0,-1,0);return this.nodes.push(e),e}addBlock(t){this.enterLine();let e=t.deco;e&&e.startSide>0&&!this.isCovered&&this.ensureLine(),this.nodes.push(t),this.writtenTo=this.pos=this.pos+t.length,e&&e.endSide>0&&(this.covering=t)}addLineDeco(t,e,i){let 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=0==this.nodes.length?null:this.nodes[this.nodes.length-1];!(this.lineStart>-1)||e instanceof as||this.isCovered?(this.writtenTo<this.pos||null==e)&&this.nodes.push(this.blankContent(this.writtenTo,this.pos)):this.nodes.push(new as(0,-1,0));let i=t;for(let t of this.nodes)t instanceof as&&t.updateHeight(this.oracle,i),i+=t?t.length:1;return this.nodes}static build(t,i,s,o){let n=new us(s,t);return e.spans(i,s,o,n,0),n.finish(s)}}class fs{constructor(){this.changes=[]}compareRange(){}comparePoint(t,e,i,s){(t<e||i&&i.heightRelevant||s&&s.heightRelevant)&&nt(t,e,this.changes,5)}}function ps(t,e){let i=t.getBoundingClientRect(),s=t.ownerDocument,o=s.defaultView||window,n=Math.max(0,i.left),r=Math.min(o.innerWidth,i.right),l=Math.max(0,i.top),a=Math.min(o.innerHeight,i.bottom);for(let e=t.parentNode;e&&e!=s.body;)if(1==e.nodeType){let i=e,s=window.getComputedStyle(i);if((i.scrollHeight>i.clientHeight||i.scrollWidth>i.clientWidth)&&"visible"!=s.overflow){let s=i.getBoundingClientRect();n=Math.max(n,s.left),r=Math.min(r,s.right),l=Math.max(l,s.top),a=Math.min(e==t.parentNode?o.innerHeight:a,s.bottom)}e="absolute"==s.position||"fixed"==s.position?i.offsetParent:i.parentNode}else{if(11!=e.nodeType)break;e=e.host}return{left:n-i.left,right:Math.max(n,r)-i.left,top:l-(i.top+e),bottom:Math.max(l,a)-(i.top+e)}}function gs(t,e){let i=t.getBoundingClientRect();return{left:0,right:i.right-i.left,top:e,bottom:i.bottom-(i.top+e)}}class ms{constructor(t,e,i,s){this.from=t,this.to=e,this.size=i,this.displaySize=s}static same(t,e){if(t.length!=e.length)return!1;for(let i=0;i<t.length;i++){let s=t[i],o=e[i];if(s.from!=o.from||s.to!=o.to||s.size!=o.size)return!1}return!0}draw(t,e){return tt.replace({widget:new vs(this.displaySize*(e?t.scaleY:t.scaleX),e)}).range(this.from,this.to)}}class vs extends J{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 ws{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=!1,this.scaleX=1,this.scaleY=1,this.scrollAnchorPos=0,this.scrollAnchorHeight=-1,this.scaler=Ss,this.scrollTarget=null,this.printing=!1,this.mustMeasureContent=!0,this.defaultTextDirection=Ot.LTR,this.visibleRanges=[],this.mustEnforceCursorAssoc=!1;let e=t.facet(ve).some(t=>"function"!=typeof t&&"cm-lineWrapping"==t.class);this.heightOracle=new Zi(e),this.stateDeco=Cs(t),this.heightMap=os.empty().applyChanges(this.stateDeco,h.empty,this.heightOracle.setDoc(t.doc),[new Te(0,0,0,t.doc.length)]);for(let t=0;t<2&&(this.viewport=this.getViewport(0,null),this.updateForViewport());t++);this.updateViewportLines(),this.lineGaps=this.ensureLineGaps([]),this.lineGapDeco=tt.set(this.lineGaps.map(t=>t.draw(this,!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:t,to:e})=>s>=t&&s<=e)){let{from:e,to:i}=this.lineBlockAt(s);t.push(new bs(e,i))}}return this.viewports=t.sort((t,e)=>t.from-e.from),this.updateScaler()}updateScaler(){let t=this.scaler;return this.scaler=this.heightMap.height<=7e6?Ss:new Ms(this.heightOracle,this.heightMap,this.viewports),t.eq(this.scaler)?0:2}updateViewportLines(){this.viewportLines=[],this.heightMap.forEachLine(this.viewport.from,this.viewport.to,this.heightOracle.setDoc(this.state.doc),0,0,t=>{this.viewportLines.push(ks(t,this.scaler))})}update(t,i=null){this.state=t.state;let s=this.stateDeco;this.stateDeco=Cs(this.state);let o=t.changedRanges,n=Te.extendWithRanges(o,function(t,i,s){let o=new fs;return e.compare(t,i,s,o,0),o.changes}(s,this.stateDeco,t?t.changes:l.empty(this.state.doc.length))),r=this.heightMap.height,a=this.scrolledToBottom?null:this.scrollAnchorAt(this.scrollTop);Ji(),this.heightMap=this.heightMap.applyChanges(this.stateDeco,t.startState.doc,this.heightOracle.setDoc(this.state.doc),n),(this.heightMap.height!=r||Qi)&&(t.flags|=2),a?(this.scrollAnchorPos=t.changes.mapPos(a.from,-1),this.scrollAnchorHeight=a.top):(this.scrollAnchorPos=-1,this.scrollAnchorHeight=r);let h=n.length?this.mapViewport(this.viewport,t.changes):this.viewport;(i&&(i.range.head<h.from||i.range.head>h.to)||!this.viewportIsAppropriate(h))&&(h=this.getViewport(0,i));let c=h.from!=this.viewport.from||h.to!=this.viewport.to;this.viewport=h,t.flags|=this.updateForViewport(),(c||!t.changes.empty||2&t.flags)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(this.mapLineGaps(this.lineGaps,t.changes))),t.flags|=this.computeVisibleRanges(t.changes),i&&(this.scrollTarget=i),!this.mustEnforceCursorAssoc&&(t.selectionSet||t.focusChanged)&&t.view.lineWrapping&&t.state.selection.main.empty&&t.state.selection.main.assoc&&!t.state.facet(ne)&&(this.mustEnforceCursorAssoc=!0)}measure(t){let e=t.contentDOM,i=window.getComputedStyle(e),s=this.heightOracle,o=i.whiteSpace;this.defaultTextDirection="rtl"==i.direction?Ot.RTL:Ot.LTR;let n=this.heightOracle.mustRefreshForWrapping(o)||this.mustMeasureContent,r=e.getBoundingClientRect(),l=n||this.mustMeasureContent||this.contentDOMHeight!=r.height;this.contentDOMHeight=r.height,this.mustMeasureContent=!1;let a=0,c=0;if(r.width&&r.height){let{scaleX:t,scaleY:i}=wt(e,r);(t>.005&&Math.abs(this.scaleX-t)>.005||i>.005&&Math.abs(this.scaleY-i)>.005)&&(this.scaleX=t,this.scaleY=i,a|=16,n=l=!0)}let d=(parseInt(i.paddingTop)||0)*this.scaleY,u=(parseInt(i.paddingBottom)||0)*this.scaleY;this.paddingTop==d&&this.paddingBottom==u||(this.paddingTop=d,this.paddingBottom=u,a|=18),this.editorWidth!=t.scrollDOM.clientWidth&&(s.lineWrapping&&(l=!0),this.editorWidth=t.scrollDOM.clientWidth,a|=16);let f=t.scrollDOM.scrollTop*this.scaleY;this.scrollTop!=f&&(this.scrollAnchorHeight=-1,this.scrollTop=f),this.scrolledToBottom=kt(t.scrollDOM);let p=(this.printing?gs:ps)(e,this.paddingTop),g=p.top-this.pixelViewport.top,m=p.bottom-this.pixelViewport.bottom;this.pixelViewport=p;let v=this.pixelViewport.bottom>this.pixelViewport.top&&this.pixelViewport.right>this.pixelViewport.left;if(v!=this.inView&&(this.inView=v,v&&(l=!0)),!this.inView&&!this.scrollTarget&&!function(t){let e=t.getBoundingClientRect(),i=t.ownerDocument.defaultView||window;return e.left<i.innerWidth&&e.right>0&&e.top<i.innerHeight&&e.bottom>0}(t.dom))return 0;let w=r.width;if(this.contentDOMWidth==w&&this.editorHeight==t.scrollDOM.clientHeight||(this.contentDOMWidth=r.width,this.editorHeight=t.scrollDOM.clientHeight,a|=16),l){let e=t.docView.measureVisibleLineHeights(this.viewport);if(s.mustRefreshForHeights(e)&&(n=!0),n||s.lineWrapping&&Math.abs(w-this.contentDOMWidth)>s.charWidth){let{lineHeight:i,charWidth:r,textHeight:l}=t.docView.measureTextSize();n=i>0&&s.refresh(o,i,r,l,Math.max(5,w/r),e),n&&(t.docView.minWidth=0,a|=16)}g>0&&m>0?c=Math.max(g,m):g<0&&m<0&&(c=Math.min(g,m)),Ji();for(let i of this.viewports){let o=i.from==this.viewport.from?e:t.docView.measureVisibleLineHeights(i);this.heightMap=(n?os.empty().applyChanges(this.stateDeco,h.empty,this.heightOracle,[new Te(0,0,0,t.state.doc.length)]):this.heightMap).updateHeight(s,0,n,new ts(i.from,o))}Qi&&(a|=2)}let b=!this.viewportIsAppropriate(this.viewport,c)||this.scrollTarget&&(this.scrollTarget.range.head<this.viewport.from||this.scrollTarget.range.head>this.viewport.to);return b&&(2&a&&(a|=this.updateScaler()),this.viewport=this.getViewport(c,this.scrollTarget),a|=this.updateForViewport()),(2&a||b)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(n?[]:this.lineGaps,t)),a|=this.computeVisibleRanges(),this.mustEnforceCursorAssoc&&(this.mustEnforceCursorAssoc=!1,t.docView.enforceCursorAssoc()),a}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,o=this.heightOracle,{visibleTop:n,visibleBottom:r}=this,l=new bs(s.lineAt(n-1e3*i,is.ByHeight,o,0,0).from,s.lineAt(r+1e3*(1-i),is.ByHeight,o,0,0).to);if(e){let{head:t}=e.range;if(t<l.from||t>l.to){let i,n=Math.min(this.editorHeight,this.pixelViewport.bottom-this.pixelViewport.top),r=s.lineAt(t,is.ByPos,o,0,0);i="center"==e.y?(r.top+r.bottom)/2-n/2:"start"==e.y||"nearest"==e.y&&t<l.from?r.top:r.bottom-n,l=new bs(s.lineAt(i-500,is.ByHeight,o,0,0).from,s.lineAt(i+n+500,is.ByHeight,o,0,0).to)}}return l}mapViewport(t,e){let i=e.mapPos(t.from,-1),s=e.mapPos(t.to,1);return new bs(this.heightMap.lineAt(i,is.ByPos,this.heightOracle,0,0).from,this.heightMap.lineAt(s,is.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,is.ByPos,this.heightOracle,0,0),{bottom:o}=this.heightMap.lineAt(e,is.ByPos,this.heightOracle,0,0),{visibleTop:n,visibleBottom:r}=this;return(0==t||s<=n-Math.max(10,Math.min(-i,250)))&&(e==this.state.doc.length||o>=r+Math.max(10,Math.min(i,250)))&&s>n-2e3&&o<r+2e3}mapLineGaps(t,e){if(!t.length||e.empty)return t;let i=[];for(let s of t)e.touchesRange(s.from,s.to)||i.push(new ms(e.mapPos(s.from),e.mapPos(s.to),s.size,s.displaySize));return i}ensureLineGaps(t,i){let s=this.heightOracle.lineWrapping,n=s?1e4:2e3,r=n>>1,l=n<<1;if(this.defaultTextDirection!=Ot.LTR&&!s)return[];let a=[],h=(e,n,l,c)=>{if(n-e<r)return;let d=this.state.selection.main,u=[d.from];d.empty||u.push(d.to);for(let t of u)if(t>e&&t<n)return h(e,t-10,l,c),void h(t+10,n,l,c);let f=function(t,e){for(let i of t)if(e(i))return i;return}(t,t=>t.from>=l.from&&t.to<=l.to&&Math.abs(t.from-e)<r&&Math.abs(t.to-n)<r&&!u.some(e=>t.from<e&&t.to>e));if(!f){if(n<l.to&&i&&s&&i.visibleRanges.some(t=>t.from<=n&&t.to>=n)){let t=i.moveToLineBoundary(o.cursor(n),!1,!0).head;t>e&&(n=t)}let t=this.gapSize(l,e,n,c);f=new ms(e,n,t,s||t<2e6?t:2e6)}a.push(f)},c=i=>{if(i.length<l||i.type!=Z.Text)return;let o=function(t,i,s){let o=[],n=t,r=0;e.spans(s,t,i,{span(){},point(t,e){t>n&&(o.push({from:n,to:t}),r+=t-n),n=e}},20),n<i&&(o.push({from:n,to:i}),r+=i-n);return{total:r,ranges:o}}(i.from,i.to,this.stateDeco);if(o.total<l)return;let r,a,c=this.scrollTarget?this.scrollTarget.range.head:null;if(s){let t,e,s=n/this.heightOracle.lineLength*this.heightOracle.lineHeight;if(null!=c){let n=xs(o,c),r=((this.visibleBottom-this.visibleTop)/2+s)/i.height;t=n-r,e=n+r}else t=(this.visibleTop-i.top-s)/i.height,e=(this.visibleBottom-i.top+s)/i.height;r=ys(o,t),a=ys(o,e)}else{let e=o.total*this.heightOracle.charWidth,s=n*this.heightOracle.charWidth,l=0;if(e>2e6)for(let e of t)e.from>=i.from&&e.from<i.to&&e.size!=e.displaySize&&e.from*this.heightOracle.charWidth+l<this.pixelViewport.left&&(l=e.size-e.displaySize);let h,d,u=this.pixelViewport.left+l,f=this.pixelViewport.right+l;if(null!=c){let t=xs(o,c),i=((f-u)/2+s)/e;h=t-i,d=t+i}else h=(u-s)/e,d=(f+s)/e;r=ys(o,h),a=ys(o,d)}r>i.from&&h(i.from,r,i,o),a<i.to&&h(a,i.to,i,o)};for(let t of this.viewportLines)Array.isArray(t.type)?t.type.forEach(c):c(t);return a}gapSize(t,e,i,s){let o=xs(s,i)-xs(s,e);return this.heightOracle.lineWrapping?t.height*o:s.total*this.heightOracle.charWidth*o}updateLineGaps(t){ms.same(t,this.lineGaps)||(this.lineGaps=t,this.lineGapDeco=tt.set(t.map(t=>t.draw(this,this.heightOracle.lineWrapping))))}computeVisibleRanges(t){let i=this.stateDeco;this.lineGaps.length&&(i=i.concat(this.lineGapDeco));let s=[];e.spans(i,this.viewport.from,this.viewport.to,{span(t,e){s.push({from:t,to:e})},point(){}},20);let o=0;if(s.length!=this.visibleRanges.length)o=12;else for(let e=0;e<s.length&&!(8&o);e++){let i=this.visibleRanges[e],n=s[e];i.from==n.from&&i.to==n.to||(o|=4,t&&t.mapPos(i.from,-1)==n.from&&t.mapPos(i.to,1)==n.to||(o|=8))}return this.visibleRanges=s,o}lineBlockAt(t){return t>=this.viewport.from&&t<=this.viewport.to&&this.viewportLines.find(e=>e.from<=t&&e.to>=t)||ks(this.heightMap.lineAt(t,is.ByPos,this.heightOracle,0,0),this.scaler)}lineBlockAtHeight(t){return t>=this.viewportLines[0].top&&t<=this.viewportLines[this.viewportLines.length-1].bottom&&this.viewportLines.find(e=>e.top<=t&&e.bottom>=t)||ks(this.heightMap.lineAt(this.scaler.fromDOM(t),is.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 ks(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 bs{constructor(t,e){this.from=t,this.to=e}}function ys({total:t,ranges:e},i){if(i<=0)return e[0].from;if(i>=1)return e[e.length-1].to;let s=Math.floor(t*i);for(let t=0;;t++){let{from:i,to:o}=e[t],n=o-i;if(s<=n)return i+s;s-=n}}function xs(t,e){let i=0;for(let{from:s,to:o}of t.ranges){if(e<=o){i+=e-s;break}i+=o-s}return i/t.total}const Ss={toDOM:t=>t,fromDOM:t=>t,scale:1,eq(t){return t==this}};function Cs(t){let i=t.facet(we).filter(t=>"function"!=typeof t),s=t.facet(ye).filter(t=>"function"!=typeof t);return s.length&&i.push(e.join(s)),i}class Ms{constructor(t,e,i){let s=0,o=0,n=0;this.viewports=i.map(({from:i,to:o})=>{let n=e.lineAt(i,is.ByPos,t,0,0).top,r=e.lineAt(o,is.ByPos,t,0,0).bottom;return s+=r-n,{from:i,to:o,top:n,bottom:r,domTop:0,domBottom:0}}),this.scale=(7e6-s)/(e.height-s);for(let t of this.viewports)t.domTop=n+(t.top-o)*this.scale,n=t.domBottom=t.domTop+(t.bottom-t.top),o=t.bottom}toDOM(t){for(let e=0,i=0,s=0;;e++){let o=e<this.viewports.length?this.viewports[e]:null;if(!o||t<o.top)return s+(t-i)*this.scale;if(t<=o.bottom)return o.domTop+(t-o.top);i=o.bottom,s=o.domBottom}}fromDOM(t){for(let e=0,i=0,s=0;;e++){let o=e<this.viewports.length?this.viewports[e]:null;if(!o||t<o.domTop)return i+(t-s)/this.scale;if(t<=o.domBottom)return o.top+(t-o.domTop);i=o.bottom,s=o.domBottom}}eq(t){return t instanceof Ms&&(this.scale==t.scale&&this.viewports.length==t.viewports.length&&this.viewports.every((e,i)=>e.from==t.viewports[i].from&&e.to==t.viewports[i].to))}}function ks(t,e){if(1==e.scale)return t;let i=e.toDOM(t.top),s=e.toDOM(t.bottom);return new es(t.from,t.length,i,s-i,Array.isArray(t._content)?t._content.map(t=>ks(t,e)):t._content)}const As=c.define({combine:t=>t.join(" ")}),Ts=c.define({combine:t=>t.indexOf(!0)>-1}),Ds=M.newName(),Os=M.newName(),Ls=M.newName(),Bs={"&light":"."+Os,"&dark":"."+Ls};function Es(t,e,i){return new M(e,{finish:e=>/&/.test(e)?e.replace(/&\w*/,e=>{if("&"==e)return t;if(!i||!i[e])throw new RangeError(`Unsupported selector: ${e}`);return i[e]}):t+" "+e})}const Rs=Es("."+Ds,{"&":{position:"relative !important",boxSizing:"border-box","&.cm-focused":{outline:"1px dotted #212121"},display:"flex !important",flexDirection:"column"},".cm-scroller":{display:"flex !important",alignItems:"flex-start !important",fontFamily:"monospace",lineHeight:1.4,height:"100%",overflowX:"auto",position:"relative",zIndex:0,overflowAnchor:"none"},".cm-content":{margin:0,flexGrow:2,flexShrink:0,display:"block",whiteSpace:"pre",wordWrap:"normal",boxSizing:"border-box",minHeight:"100%",padding:"4px 0",outline:"none","&[contenteditable=true]":{WebkitUserModify:"read-write-plaintext-only"}},".cm-lineWrapping":{whiteSpace_fallback:"pre-wrap",whiteSpace:"break-spaces",wordBreak:"break-word",overflowWrap:"anywhere",flexShrink:1},"&light .cm-content":{caretColor:"black"},"&dark .cm-content":{caretColor:"white"},".cm-line":{display:"block",padding:"0 2px 0 6px"},".cm-layer":{position:"absolute",left:0,top:0,contain:"size style","& > *":{position:"absolute"}},"&light .cm-selectionBackground":{background:"#d9d9d9"},"&dark .cm-selectionBackground":{background:"#222"},"&light.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground":{background:"#d7d4f0"},"&dark.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground":{background:"#233"},".cm-cursorLayer":{pointerEvents:"none"},"&.cm-focused > .cm-scroller > .cm-cursorLayer":{animation:"steps(1) cm-blink 1.2s infinite"},"@keyframes cm-blink":{"0%":{},"50%":{opacity:0},"100%":{}},"@keyframes cm-blink2":{"0%":{},"50%":{opacity:0},"100%":{}},".cm-cursor, .cm-dropCursor":{borderLeft:"1.2px solid black",marginLeft:"-0.6px",pointerEvents:"none"},".cm-cursor":{display:"none"},"&dark .cm-cursor":{borderLeftColor:"#ddd"},".cm-dropCursor":{position:"absolute"},"&.cm-focused > .cm-scroller > .cm-cursorLayer .cm-cursor":{display:"block"},".cm-iso":{unicodeBidi:"isolate"},".cm-announced":{position:"fixed",top:"-10000px"},"@media print":{".cm-announced":{display:"none"}},"&light .cm-activeLine":{backgroundColor:"#cceeff44"},"&dark .cm-activeLine":{backgroundColor:"#99eeff33"},"&light .cm-specialChar":{color:"red"},"&dark .cm-specialChar":{color:"#f78"},".cm-gutters":{flexShrink:0,display:"flex",height:"100%",boxSizing:"border-box",zIndex:200},".cm-gutters-before":{insetInlineStart:0},".cm-gutters-after":{insetInlineEnd:0},"&light .cm-gutters":{backgroundColor:"#f5f5f5",color:"#6c6c6c",border:"0px solid #ddd","&.cm-gutters-before":{borderRightWidth:"1px"},"&.cm-gutters-after":{borderLeftWidth:"1px"}},"&dark .cm-gutters":{backgroundColor:"#333338",color:"#ccc"},".cm-gutter":{display:"flex !important",flexDirection:"column",flexShrink:0,boxSizing:"border-box",minHeight:"100%",overflow:"hidden"},".cm-gutterElement":{boxSizing:"border-box"},".cm-lineNumbers .cm-gutterElement":{padding:"0 3px 0 5px",minWidth:"20px",textAlign:"right",whiteSpace:"nowrap"},"&light .cm-activeLineGutter":{backgroundColor:"#e2f2ff"},"&dark .cm-activeLineGutter":{backgroundColor:"#222227"},".cm-panels":{boxSizing:"border-box",position:"sticky",left:0,right:0,zIndex:300},"&light .cm-panels":{backgroundColor:"#f5f5f5",color:"black"},"&light .cm-panels-top":{borderBottom:"1px solid #ddd"},"&light .cm-panels-bottom":{borderTop:"1px solid #ddd"},"&dark .cm-panels":{backgroundColor:"#333338",color:"white"},".cm-dialog":{padding:"2px 19px 4px 6px",position:"relative","& label":{fontSize:"80%"}},".cm-dialog-close":{position:"absolute",top:"3px",right:"4px",backgroundColor:"inherit",border:"none",font:"inherit",fontSize:"14px",padding:"0"},".cm-tab":{display:"inline-block",overflow:"hidden",verticalAlign:"bottom"},".cm-widgetBuffer":{verticalAlign:"text-top",height:"1em",width:0,display:"inline"},".cm-placeholder":{color:"#888",display:"inline-block",verticalAlign:"top",userSelect:"none"},".cm-highlightSpace":{backgroundImage:"radial-gradient(circle at 50% 55%, #aaa 20%, transparent 5%)",backgroundPosition:"center"},".cm-highlightTab":{backgroundImage:'url(\'data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="200" height="20"><path stroke="%23888" stroke-width="1" fill="none" d="M1 10H196L190 5M190 15L196 10M197 4L197 16"/></svg>\')',backgroundSize:"auto 100%",backgroundPosition:"right 90%",backgroundRepeat:"no-repeat"},".cm-trailingSpace":{backgroundColor:"#ff332255"},".cm-button":{verticalAlign:"middle",color:"inherit",fontSize:"70%",padding:".2em 1em",borderRadius:"1px"},"&light .cm-button":{backgroundImage:"linear-gradient(#eff1f5, #d9d9df)",border:"1px solid #888","&:active":{backgroundImage:"linear-gradient(#b4b4b4, #d0d3d6)"}},"&dark .cm-button":{backgroundImage:"linear-gradient(#393939, #111)",border:"1px solid #888","&:active":{backgroundImage:"linear-gradient(#111, #333)"}},".cm-textfield":{verticalAlign:"middle",color:"inherit",fontSize:"70%",border:"1px solid silver",padding:".2em .5em"},"&light .cm-textfield":{backgroundColor:"white"},"&dark .cm-textfield":{border:"1px solid #555",backgroundColor:"inherit"}},Bs),Hs={childList:!0,characterData:!0,subtree:!0,attributes:!0,characterDataOldValue:!0},Ws=j.ie&&j.ie_version<=11;class Ns{constructor(t){this.view=t,this.active=!1,this.editContext=null,this.selectionRange=new bt,this.selectionChanged=!1,this.delayedFlush=-1,this.resizeTimeout=-1,this.queue=[],this.delayedAndroidKey=null,this.flushingAndroidKey=-1,this.lastChange=0,this.scrollTargets=[],this.intersection=null,this.resizeScroll=null,this.intersecting=!1,this.gapIntersection=null,this.gaps=[],this.printQuery=null,this.parentCheck=-1,this.dom=t.contentDOM,this.observer=new MutationObserver(e=>{for(let t of e)this.queue.push(t);(j.ie&&j.ie_version<=11||j.ios&&t.composing)&&e.some(t=>"childList"==t.type&&t.removedNodes.length||"characterData"==t.type&&t.oldValue.length>t.target.nodeValue.length)?this.flushSoon():this.flush()}),!window.EditContext||!j.android||!1===t.constructor.EDIT_CONTEXT||j.chrome&&j.chrome_version<126||(this.editContext=new Fs(t),t.state.facet(de)&&(t.contentDOM.editContext=this.editContext.editContext)),Ws&&(this.onCharData=t=>{this.queue.push({target:t.target,type:"characterData",oldValue:t.prevValue}),this.flushSoon()}),this.onSelectionChange=this.onSelectionChange.bind(this),this.onResize=this.onResize.bind(this),this.onPrint=this.onPrint.bind(this),this.onScroll=this.onScroll.bind(this),window.matchMedia&&(this.printQuery=window.matchMedia("print")),"function"==typeof ResizeObserver&&(this.resizeScroll=new ResizeObserver(()=>{var t;(null===(t=this.view.docView)||void 0===t?void 0:t.lastUpdate)<Date.now()-75&&this.onResize()}),this.resizeScroll.observe(t.scrollDOM)),this.addWindowListeners(this.win=t.win),this.start(),"function"==typeof IntersectionObserver&&(this.intersection=new IntersectionObserver(t=>{this.parentCheck<0&&(this.parentCheck=setTimeout(this.listenForScroll.bind(this),1e3)),t.length>0&&t[t.length-1].intersectionRatio>0!=this.intersecting&&(this.intersecting=!this.intersecting,this.intersecting!=this.view.inView&&this.onScrollChanged(document.createEvent("Event")))},{threshold:[0,.001]}),this.intersection.observe(this.dom),this.gapIntersection=new IntersectionObserver(t=>{t.length>0&&t[t.length-1].intersectionRatio>0&&this.onScrollChanged(document.createEvent("Event"))},{})),this.listenForScroll(),this.readSelectionRange()}onScrollChanged(t){this.view.inputState.runHandlers("scroll",t),this.intersecting&&this.view.measure()}onScroll(t){this.intersecting&&this.flush(!1),this.editContext&&this.view.requestMeasure(this.editContext.measureReq),this.onScrollChanged(t)}onResize(){this.resizeTimeout<0&&(this.resizeTimeout=setTimeout(()=>{this.resizeTimeout=-1,this.view.requestMeasure()},50))}onPrint(t){("change"!=t.type&&t.type||t.matches)&&(this.view.viewState.printing=!0,this.view.measure(),setTimeout(()=>{this.view.viewState.printing=!1,this.view.requestMeasure()},500))}updateGaps(t){if(this.gapIntersection&&(t.length!=this.gaps.length||this.gaps.some((e,i)=>e!=t[i]))){this.gapIntersection.disconnect();for(let e of t)this.gapIntersection.observe(e);this.gaps=t}}onSelectionChange(t){let e=this.selectionChanged;if(!this.readSelectionRange()||this.delayedAndroidKey)return;let{view:i}=this,s=this.selectionRange;if(i.state.facet(de)?i.root.activeElement!=this.dom:!ht(this.dom,s))return;let o=s.anchorNode&&i.docView.tile.nearest(s.anchorNode);o&&o.isWidget()&&o.widget.ignoreEvent(t)?e||(this.selectionChanged=!1):(j.ie&&j.ie_version<=11||j.android&&j.chrome)&&!i.state.selection.main.empty&&s.focusNode&&dt(s.focusNode,s.focusOffset,s.anchorNode,s.anchorOffset)?this.flushSoon():this.flush(!1)}readSelectionRange(){let{view:t}=this,e=lt(t.root);if(!e)return!1;let i=j.safari&&11==t.root.nodeType&&t.root.activeElement==this.dom&&function(t,e){if(e.getComposedRanges){let i=e.getComposedRanges(t.root)[0];if(i)return Vs(t,i)}let i=null;function s(t){t.preventDefault(),t.stopImmediatePropagation(),i=t.getTargetRanges()[0]}return t.contentDOM.addEventListener("beforeinput",s,!0),t.dom.ownerDocument.execCommand("indent"),t.contentDOM.removeEventListener("beforeinput",s,!0),i?Vs(t,i):null}(this.view,e)||e;if(!i||this.selectionRange.eq(i))return!1;let s=ht(this.dom,i);return s&&!this.selectionChanged&&t.inputState.lastFocusTime>Date.now()-200&&t.inputState.lastTouchTime<Date.now()-300&&function(t,e){let i=e.focusNode,s=e.focusOffset;if(!i||e.anchorNode!=i||e.anchorOffset!=s)return!1;for(s=Math.min(s,gt(i));;)if(s){if(1!=i.nodeType)return!1;let t=i.childNodes[s-1];"false"==t.contentEditable?s--:(i=t,s=gt(i))}else{if(i==t)return!0;s=ut(i),i=i.parentNode}}(this.dom,i)?(this.view.inputState.lastFocusTime=0,t.docView.updateSelection(),!1):(this.selectionRange.setRange(i),s&&(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(1==i.nodeType)!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(11!=i.nodeType)break;i=i.host}if(t<this.scrollTargets.length&&!e&&(e=this.scrollTargets.slice(0,t)),e){for(let t of this.scrollTargets)t.removeEventListener("scroll",this.onScroll);for(let t of this.scrollTargets=e)t.addEventListener("scroll",this.onScroll)}}ignore(t){if(!this.active)return t();try{return this.stop(),t()}finally{this.start(),this.clear()}}start(){this.active||(this.observer.observe(this.dom,Hs),Ws&&this.dom.addEventListener("DOMCharacterDataModified",this.onCharData),this.active=!0)}stop(){this.active&&(this.active=!1,this.observer.disconnect(),Ws&&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 t=()=>{let t=this.delayedAndroidKey;if(t){this.clearDelayedAndroidKey(),this.view.inputState.lastKeyCode=t.keyCode,this.view.inputState.lastKeyTime=Date.now(),!this.flush()&&t.force&&Mt(this.dom,t.key,t.keyCode)}};this.flushingAndroidKey=this.view.win.requestAnimationFrame(t)}this.delayedAndroidKey&&"Enter"!=t||(this.delayedAndroidKey={key:t,keyCode:e,force:this.lastChange<Date.now()-50||!!(null===(i=this.delayedAndroidKey)||void 0===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 o of t){let t=this.readMutation(o);t&&(t.typeOver&&(s=!0),-1==e?({from:e,to:i}=t):(e=Math.min(t.from,e),i=Math.max(t.to,i)))}return{from:e,to:i,typeOver:s}}readChange(){let{from:t,to:e,typeOver:i}=this.processRecords(),s=this.selectionChanged&&ht(this.dom,this.selectionRange);if(t<0&&!s)return null;t>-1&&(this.lastChange=Date.now()),this.view.inputState.lastFocusTime=0,this.selectionChanged=!1;let o=new bi(this.view,t,e,i);return this.view.docView.domChanged={newSel:o.newSel?o.newSel.main:null},o}flush(t=!0){if(this.delayedFlush>=0||this.delayedAndroidKey)return!1;t&&this.readSelectionRange();let e=this.readChange();if(!e)return this.view.requestMeasure(),!1;let i=this.view.state,s=xi(this.view,e);return this.view.state==i&&(e.domChanged||e.newSel&&!Mi(this.view.state.selection,e.newSel.main))&&this.view.update([]),s}readMutation(t){let e=this.view.docView.tile.nearest(t.target);if(!e||e.isWidget())return null;if(e.markDirty("attributes"==t.type),"childList"==t.type){let i=Ps(e,t.previousSibling||t.target.previousSibling,-1),s=Ps(e,t.nextSibling||t.target.nextSibling,1);return{from:i?e.posAfter(i):e.posAtStart,to:s?e.posBefore(s):e.posAtEnd,typeOver:!1}}return"characterData"==t.type?{from:e.posAtStart,to:e.posAtEnd,typeOver:t.target.nodeValue==t.oldValue}:null}setWindow(t){t!=this.win&&(this.removeWindowListeners(this.win),this.win=t,this.addWindowListeners(this.win))}addWindowListeners(t){t.addEventListener("resize",this.onResize),this.printQuery?this.printQuery.addEventListener?this.printQuery.addEventListener("change",this.onPrint):this.printQuery.addListener(this.onPrint):t.addEventListener("beforeprint",this.onPrint),t.addEventListener("scroll",this.onScroll),t.document.addEventListener("selectionchange",this.onSelectionChange)}removeWindowListeners(t){t.removeEventListener("scroll",this.onScroll),t.removeEventListener("resize",this.onResize),this.printQuery?this.printQuery.removeEventListener?this.printQuery.removeEventListener("change",this.onPrint):this.printQuery.removeListener(this.onPrint):t.removeEventListener("beforeprint",this.onPrint),t.document.removeEventListener("selectionchange",this.onSelectionChange)}update(t){this.editContext&&(this.editContext.update(t),t.startState.facet(de)!=t.state.facet(de)&&(t.view.contentDOM.editContext=t.state.facet(de)?this.editContext.editContext:null))}destroy(){var t,e,i;this.stop(),null===(t=this.intersection)||void 0===t||t.disconnect(),null===(e=this.gapIntersection)||void 0===e||e.disconnect(),null===(i=this.resizeScroll)||void 0===i||i.disconnect();for(let t of this.scrollTargets)t.removeEventListener("scroll",this.onScroll);this.removeWindowListeners(this.win),clearTimeout(this.parentCheck),clearTimeout(this.resizeTimeout),this.win.cancelAnimationFrame(this.delayedFlush),this.win.cancelAnimationFrame(this.flushingAndroidKey),this.editContext&&(this.view.contentDOM.editContext=null,this.editContext.destroy())}}function Ps(t,e,i){for(;e;){let s=Le.get(e);if(s&&s.parent==t)return s;let o=e.parentNode;e=o!=t.dom?o:i>0?e.nextSibling:e.previousSibling}return null}function Vs(t,e){let i=e.startContainer,s=e.startOffset,o=e.endContainer,n=e.endOffset,r=t.docView.domAtPos(t.state.selection.main.anchor,1);return dt(r.node,r.offset,o,n)&&([i,s,o,n]=[o,n,i,s]),{anchorNode:i,anchorOffset:s,focusNode:o,focusOffset:n}}class Fs{constructor(t){this.from=0,this.to=0,this.pendingContextChange=null,this.handlers=Object.create(null),this.composing=null,this.resetRange(t.state);let e=this.editContext=new window.EditContext({text:t.state.doc.sliceString(this.from,this.to),selectionStart:this.toContextPos(Math.max(this.from,Math.min(this.to,t.state.selection.main.anchor))),selectionEnd:this.toContextPos(t.state.selection.main.head)});this.handlers.textupdate=i=>{let s=t.state.selection.main,{anchor:n,head:r}=s,l=this.toEditorPos(i.updateRangeStart),a=this.toEditorPos(i.updateRangeEnd);t.inputState.composing>=0&&!this.composing&&(this.composing={contextBase:i.updateRangeStart,editorBase:l,drifted:!1});let c=a-l>i.text.length;l==this.from&&n<this.from?l=n:a==this.to&&n>this.to&&(a=n);let d=Ci(t.state.sliceDoc(l,a),i.text,(c?s.from:s.to)-l,c?"end":null);if(!d){let e=o.single(this.toEditorPos(i.selectionStart),this.toEditorPos(i.selectionEnd));return void(Mi(e,s)||t.dispatch({selection:e,userEvent:"select"}))}let u={from:d.from+l,to:d.toA+l,insert:h.of(i.text.slice(d.from,d.toB).split("\n"))};if((j.mac||j.android)&&u.from==r-1&&/^\. ?$/.test(i.text)&&"off"==t.contentDOM.getAttribute("autocorrect")&&(u={from:l,to:a,insert:h.of([i.text.replace("."," ")])}),this.pendingContextChange=u,!t.state.readOnly){let e=this.to-this.from+(u.to-u.from+u.insert.length);Si(t,u,o.single(this.toEditorPos(i.selectionStart,e),this.toEditorPos(i.selectionEnd,e)))}this.pendingContextChange&&(this.revertPending(t.state),this.setSelection(t.state)),u.from<u.to&&!u.insert.length&&t.inputState.composing>=0&&!/[\\p{Alphabetic}\\p{Number}_]/.test(e.text.slice(Math.max(0,i.updateRangeStart-1),Math.min(e.text.length,i.updateRangeStart+1)))&&this.handlers.compositionend(i)},this.handlers.characterboundsupdate=i=>{let s=[],o=null;for(let e=this.toEditorPos(i.rangeStart),n=this.toEditorPos(i.rangeEnd);e<n;e++){let i=t.coordsForChar(e);o=i&&new DOMRect(i.left,i.top,i.right-i.left,i.bottom-i.top)||o||new DOMRect,s.push(o)}e.updateCharacterBounds(i.rangeStart,s)},this.handlers.textformatupdate=e=>{let i=[];for(let t of e.getTextFormats()){let e=t.underlineStyle,s=t.underlineThickness;if(!/none/i.test(e)&&!/none/i.test(s)){let o=this.toEditorPos(t.rangeStart),n=this.toEditorPos(t.rangeEnd);if(o<n){let t=`text-decoration: underline ${/^[a-z]/.test(e)?e+" ":"Dashed"==e?"dashed ":"Squiggle"==e?"wavy ":""}${/thin/i.test(s)?1:2}px`;i.push(tt.mark({attributes:{style:t}}).range(o,n))}}}t.dispatch({effects:he.of(tt.set(i))})},this.handlers.compositionstart=()=>{t.inputState.composing<0&&(t.inputState.composing=0,t.inputState.compositionFirstChange=!0)},this.handlers.compositionend=()=>{if(t.inputState.composing=-1,t.inputState.compositionFirstChange=null,this.composing){let{drifted:e}=this.composing;this.composing=null,e&&this.reset(t.state)}};for(let t in this.handlers)e.addEventListener(t,this.handlers[t]);this.measureReq={read:t=>{this.editContext.updateControlBounds(t.contentDOM.getBoundingClientRect());let e=lt(t.root);e&&e.rangeCount&&this.editContext.updateSelectionBounds(e.getRangeAt(0).getBoundingClientRect())}}}applyEdits(t){let e=0,i=!1,s=this.pendingContextChange;return t.changes.iterChanges((o,n,r,l,a)=>{if(i)return;let h=a.length-(n-o);if(s&&n>=s.to){if(s.from==o&&s.to==n&&s.insert.eq(a))return s=this.pendingContextChange=null,e+=h,void(this.to+=h);s=null,this.revertPending(t.state)}if(o+=e,(n+=e)<=this.from)this.from+=h,this.to+=h;else if(o<this.to){if(o<this.from||n>this.to||this.to-this.from+a.length>3e4)return void(i=!0);this.editContext.updateText(this.toContextPos(o),this.toContextPos(n),a.toString()),this.to+=h}e+=h}),s&&!i&&this.revertPending(t.state),!i}update(t){let e=this.pendingContextChange,i=t.startState.selection.main;this.composing&&(this.composing.drifted||!t.changes.touchesRange(i.from,i.to)&&t.transactions.some(t=>!t.isUserEvent("input.type")&&t.changes.touchesRange(this.from,this.to)))?(this.composing.drifted=!0,this.composing.editorBase=t.changes.mapPos(this.composing.editorBase)):this.applyEdits(t)&&this.rangeIsValid(t.state)?(t.docChanged||t.selectionSet||e)&&this.setSelection(t.state):(this.pendingContextChange=null,this.reset(t.state)),(t.geometryChanged||t.docChanged||t.selectionSet)&&t.view.requestMeasure(this.measureReq)}resetRange(t){let{head:e}=t.selection.main;this.from=Math.max(0,e-1e4),this.to=Math.min(t.doc.length,e+1e4)}reset(t){this.resetRange(t),this.editContext.updateText(0,this.editContext.text.length,t.doc.sliceString(this.from,this.to)),this.setSelection(t)}revertPending(t){let e=this.pendingContextChange;this.pendingContextChange=null,this.editContext.updateText(this.toContextPos(e.from),this.toContextPos(e.from+e.insert.length),t.doc.sliceString(e.from,e.to))}setSelection(t){let{main:e}=t.selection,i=this.toContextPos(Math.max(this.from,Math.min(this.to,e.anchor))),s=this.toContextPos(e.head);this.editContext.selectionStart==i&&this.editContext.selectionEnd==s||this.editContext.updateSelection(i,s)}rangeIsValid(t){let{head:e}=t.selection.main;return!(this.from>0&&e-this.from<500||this.to<t.doc.length&&this.to-e<500||this.to-this.from>3e4)}toEditorPos(t,e=this.to-this.from){t=Math.min(t,e);let i=this.composing;return i&&i.drifted?i.editorBase+(t-i.contextBase):t+this.from}toContextPos(t){let e=this.composing;return e&&e.drifted?e.contextBase+(t-e.editorBase):t-this.from}destroy(){for(let t in this.handlers)this.editContext.removeEventListener(t,this.handlers[t])}}class zs{get state(){return this.viewState.state}get viewport(){return this.viewState.viewport}get visibleRanges(){return this.viewState.visibleRanges}get inView(){return this.viewState.inView}get composing(){return!!this.inputState&&this.inputState.composing>0}get compositionStarted(){return!!this.inputState&&this.inputState.composing>=0}get root(){return this._root}get win(){return this.dom.ownerDocument.defaultView||window}constructor(t={}){var e;this.plugins=[],this.pluginMap=new Map,this.editorAttrs={},this.contentAttrs={},this.bidiCache=[],this.destroyed=!1,this.updateState=2,this.measureScheduled=-1,this.measureRequests=[],this.contentDOM=document.createElement("div"),this.scrollDOM=document.createElement("div"),this.scrollDOM.tabIndex=-1,this.scrollDOM.className="cm-scroller",this.scrollDOM.appendChild(this.contentDOM),this.announceDOM=document.createElement("div"),this.announceDOM.className="cm-announced",this.announceDOM.setAttribute("aria-live","polite"),this.dom=document.createElement("div"),this.dom.appendChild(this.announceDOM),this.dom.appendChild(this.scrollDOM),t.parent&&t.parent.appendChild(this.dom);let{dispatch:s}=t;this.dispatchTransactions=t.dispatchTransactions||s&&(t=>t.forEach(t=>s(t,this)))||(t=>this.update(t)),this.dispatch=this.dispatch.bind(this),this._root=t.root||function(t){for(;t;){if(t&&(9==t.nodeType||11==t.nodeType&&t.host))return t;t=t.assignedSlot||t.parentNode}return null}(t.parent)||document,this.viewState=new ws(t.state||i.create(t)),t.scrollTo&&t.scrollTo.is(ae)&&(this.viewState.scrollTarget=t.scrollTo.value.clip(this.viewState.state)),this.plugins=this.state.facet(fe).map(t=>new ge(t));for(let t of this.plugins)t.update(this);this.observer=new Ns(this),this.inputState=new ki(this),this.inputState.ensureHandlers(this.plugins),this.docView=new Ze(this),this.mountStyles(),this.updateAttrs(),this.updateState=0,this.requestMeasure(),(null===(e=document.fonts)||void 0===e?void 0:e.ready)&&document.fonts.ready.then(()=>{this.viewState.mustMeasureContent=!0,this.requestMeasure()})}dispatch(...t){let e=1==t.length&&t[0]instanceof s?t:1==t.length&&Array.isArray(t[0])?t[0]:[this.state.update(...t)];this.dispatchTransactions(e,this)}update(t){if(0!=this.updateState)throw new Error("Calls to EditorView.update are not allowed while an update is in progress");let e,s=!1,n=!1,r=this.state;for(let e of t){if(e.startState!=r)throw new RangeError("Trying to update state with a transaction that doesn't start from the previous state.");r=e.state}if(this.destroyed)return void(this.viewState.state=r);let l=this.hasFocus,a=0,h=null;t.some(t=>t.annotation(ji))?(this.inputState.notifiedFocused=l,a=1):l!=this.inputState.notifiedFocused&&(this.inputState.notifiedFocused=l,h=Xi(r,l),h||(a=1));let c=this.observer.delayedAndroidKey,d=null;if(c?(this.observer.clearDelayedAndroidKey(),d=this.observer.readChange(),(d&&!this.state.doc.eq(r.doc)||!this.state.selection.eq(r.selection))&&(d=null)):this.observer.clear(),r.facet(i.phrases)!=this.state.facet(i.phrases))return this.setState(r);e=De.create(this,r,t),e.flags|=a;let u=this.viewState.scrollTarget;try{this.updateState=2;for(let e of t){if(u&&(u=u.map(e.changes)),e.scrollIntoView){let{main:t}=e.state.selection;u=new le(t.empty?t:o.cursor(t.head,t.head>t.anchor?-1:1))}for(let t of e.effects)t.is(ae)&&(u=t.value.clip(this.state))}this.viewState.update(e,u),this.bidiCache=Ks.update(this.bidiCache,e.changes),e.empty||(this.updatePlugins(e),this.inputState.update(e)),s=this.docView.update(e),this.state.facet(Ae)!=this.styleModules&&this.mountStyles(),n=this.updateAttrs(),this.showAnnouncements(t),this.docView.updateSelection(s,t.some(t=>t.isUserEvent("select.pointer")))}finally{this.updateState=0}if(e.startState.facet(As)!=e.state.facet(As)&&(this.viewState.mustMeasureContent=!0),(s||n||u||this.viewState.mustEnforceCursorAssoc||this.viewState.mustMeasureContent)&&this.requestMeasure(),s&&this.docViewUpdate(),!e.empty)for(let t of this.state.facet(Zt))try{t(e)}catch(t){ce(this.state,t,"update listener")}(h||d)&&Promise.resolve().then(()=>{h&&this.state==h.startState&&this.dispatch(h),d&&!xi(this,d)&&c.force&&Mt(this.contentDOM,c.key,c.keyCode)})}setState(t){if(0!=this.updateState)throw new Error("Calls to EditorView.setState are not allowed while an update is in progress");if(this.destroyed)return void(this.viewState.state=t);this.updateState=2;let e=this.hasFocus;try{for(let t of this.plugins)t.destroy(this);this.viewState=new ws(t),this.plugins=t.facet(fe).map(t=>new ge(t)),this.pluginMap.clear();for(let t of this.plugins)t.update(this);this.docView.destroy(),this.docView=new Ze(this),this.inputState.ensureHandlers(this.plugins),this.mountStyles(),this.updateAttrs(),this.bidiCache=[]}finally{this.updateState=0}e&&this.focus(),this.requestMeasure()}updatePlugins(t){let e=t.startState.facet(fe),i=t.state.facet(fe);if(e!=i){let s=[];for(let o of i){let i=e.indexOf(o);if(i<0)s.push(new ge(o));else{let e=this.plugins[i];e.mustUpdate=t,s.push(e)}}for(let e of this.plugins)e.mustUpdate!=t&&e.destroy(this);this.plugins=s,this.pluginMap.clear()}else for(let e of this.plugins)e.mustUpdate=t;for(let t=0;t<this.plugins.length;t++)this.plugins[t].update(this);e!=i&&this.inputState.ensureHandlers(this.plugins)}docViewUpdate(){for(let t of this.plugins){let e=t.value;if(e&&e.docViewUpdate)try{e.docViewUpdate(this)}catch(t){ce(this.state,t,"doc view update listener")}}}measure(t=!0){if(this.destroyed)return;if(this.measureScheduled>-1&&this.win.cancelAnimationFrame(this.measureScheduled),this.observer.delayedAndroidKey)return this.measureScheduled=-1,void this.requestMeasure();this.measureScheduled=0,t&&this.observer.forceFlush();let e=null,i=this.scrollDOM,s=i.scrollTop*this.scaleY,{scrollAnchorPos:o,scrollAnchorHeight:n}=this.viewState;Math.abs(s-this.viewState.scrollTop)>1&&(n=-1),this.viewState.scrollAnchorHeight=-1;try{for(let t=0;;t++){if(n<0)if(kt(i))o=-1,n=this.viewState.heightMap.height;else{let t=this.viewState.scrollAnchorAt(s);o=t.from,n=t.top}this.updateState=1;let r=this.viewState.measure(this);if(!r&&!this.measureRequests.length&&null==this.viewState.scrollTarget)break;if(t>5){console.warn(this.measureRequests.length?"Measure loop restarted more than 5 times":"Viewport failed to stabilize");break}let l=[];4&r||([this.measureRequests,l]=[l,this.measureRequests]);let a=l.map(t=>{try{return t.read(this)}catch(t){return ce(this.state,t),qs}}),h=De.create(this,this.state,[]),c=!1;h.flags|=r,e?e.flags|=r:e=h,this.updateState=2,h.empty||(this.updatePlugins(h),this.inputState.update(h),this.updateAttrs(),c=this.docView.update(h),c&&this.docViewUpdate());for(let t=0;t<l.length;t++)if(a[t]!=qs)try{let e=l[t];e.write&&e.write(a[t],this)}catch(t){ce(this.state,t)}if(c&&this.docView.updateSelection(!0),!h.viewportChanged&&0==this.measureRequests.length){if(this.viewState.editorHeight){if(this.viewState.scrollTarget){this.docView.scrollIntoView(this.viewState.scrollTarget),this.viewState.scrollTarget=null,n=-1;continue}{let t=(o<0?this.viewState.heightMap.height:this.viewState.lineBlockAt(o).top)-n;if(t>1||t<-1){s+=t,i.scrollTop=s/this.scaleY,n=-1;continue}}}break}}}finally{this.updateState=0,this.measureScheduled=-1}if(e&&!e.empty)for(let t of this.state.facet(Zt))t(e)}get themeClasses(){return Ds+" "+(this.state.facet(Ts)?Ls:Os)+" "+this.state.facet(As)}updateAttrs(){let t=_s(this,me,{class:"cm-editor"+(this.hasFocus?" cm-focused ":" ")+this.themeClasses}),e={spellcheck:"false",autocorrect:"off",autocapitalize:"off",writingsuggestions:"false",translate:"no",contenteditable:this.state.facet(de)?"true":"false",class:"cm-content",style:`${j.tabSize}: ${this.state.tabSize}`,role:"textbox","aria-multiline":"true"};this.state.readOnly&&(e["aria-readonly"]="true"),_s(this,ve,e);let i=this.observer.ignore(()=>{let i=$(this.contentDOM,this.contentAttrs,e),s=$(this.dom,this.editorAttrs,t);return i||s});return this.editorAttrs=t,this.contentAttrs=e,i}showAnnouncements(t){let e=!0;for(let i of t)for(let t of i.effects)if(t.is(zs.announce)){e&&(this.announceDOM.textContent=""),e=!1,this.announceDOM.appendChild(document.createElement("div")).textContent=t.value}}mountStyles(){this.styleModules=this.state.facet(Ae);let t=this.state.facet(zs.cspNonce);M.mount(this.root,this.styleModules.concat(Rs).reverse(),t?{nonce:t}:void 0)}readMeasured(){if(2==this.updateState)throw new Error("Reading the editor layout isn't allowed during an update");0==this.updateState&&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(null!=t.key)for(let e=0;e<this.measureRequests.length;e++)if(this.measureRequests[e].key===t.key)return void(this.measureRequests[e]=t);this.measureRequests.push(t)}}plugin(t){let e=this.pluginMap.get(t);return(void 0===e||e&&e.plugin!=t)&&this.pluginMap.set(t,e=this.plugins.find(e=>e.plugin==t)||null),e&&e.update(this).value}get documentTop(){return this.contentDOM.getBoundingClientRect().top+this.viewState.paddingTop}get documentPadding(){return{top:this.viewState.paddingTop,bottom:this.viewState.paddingBottom}}get scaleX(){return this.viewState.scaleX}get scaleY(){return this.viewState.scaleY}elementAtHeight(t){return this.readMeasured(),this.viewState.elementAtHeight(t)}lineBlockAtHeight(t){return this.readMeasured(),this.viewState.lineBlockAtHeight(t)}get viewportLineBlocks(){return this.viewState.viewportLines}lineBlockAt(t){return this.viewState.lineBlockAt(t)}get contentHeight(){return this.viewState.contentHeight}moveByChar(t,e,i){return hi(this,t,ri(this,t,e,i))}moveByGroup(t,e){return hi(this,t,ri(this,t,e,e=>function(t,e,i){let s=t.state.charCategorizer(e),o=s(i);return t=>{let e=s(t);return o==y.Space&&(o=e),o==e}}(this,t.head,e)))}visualLineSide(t,e){let i=this.bidiSpans(t),s=this.textDirectionAt(t.from),n=i[e?i.length-1:0];return o.cursor(n.side(e,s)+t.from,n.forward(!e,s)?1:-1)}moveToLineBoundary(t,e,i=!0){return function(t,e,i,s){let n=ni(t,e.head,e.assoc||-1),r=s&&n.type==Z.Text&&(t.lineWrapping||n.widgetLineBreaks)?t.coordsAtPos(e.assoc<0&&e.head>n.from?e.head-1:e.head):null;if(r){let e=t.dom.getBoundingClientRect(),s=t.textDirectionAt(n.from),l=t.posAtCoords({x:i==(s==Ot.LTR)?e.right-1:e.left+1,y:(r.top+r.bottom)/2});if(null!=l)return o.cursor(l,i?-1:1)}return o.cursor(i?n.to:n.from,i?-1:1)}(this,t,e,i)}moveVertically(t,e,i){return hi(this,t,function(t,e,i,s){let n=e.head,r=i?1:-1;if(n==(i?t.state.doc.length:0))return o.cursor(n,e.assoc);let l,a=e.goalColumn,h=t.contentDOM.getBoundingClientRect(),c=t.coordsAtPos(n,e.assoc||-1),d=t.documentTop;if(c)null==a&&(a=c.left-h.left),l=r<0?c.top:c.bottom;else{let e=t.viewState.lineBlockAt(n);null==a&&(a=Math.min(h.right-h.left,t.defaultCharacterWidth*(n-e.from))),l=(r<0?e.top:e.bottom)+d}let u=di(t,{x:h.left+a,y:l+(null!=s?s:t.viewState.heightOracle.textHeight>>1)*r},!1,r);return o.cursor(u.pos,u.assoc,void 0,a)}(this,t,e,i))}domAtPos(t,e=1){return this.docView.domAtPos(t,e)}posAtDOM(t,e=0){return this.docView.posFromDOM(t,e)}posAtCoords(t,e=!0){this.readMeasured();let i=di(this,t,e);return i&&i.pos}posAndSideAtCoords(t,e=!0){return this.readMeasured(),di(this,t,e)}coordsAtPos(t,e=1){this.readMeasured();let i=this.docView.coordsAt(t,e);if(!i||i.left==i.right)return i;let s=this.state.doc.lineAt(t),o=this.bidiSpans(s);return mt(i,o[Ft.find(o,t-s.from,-1,e)].dir==Ot.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(oe)||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>Is)return Yt(t.length);let e,i=this.textDirectionAt(t.from);for(let s of this.bidiCache)if(s.from==t.from&&s.dir==i&&(s.fresh||zt(s.isolates,e=Ce(this,t))))return s.order;e||(e=Ce(this,t));let s=_t(t.text,i,e);return this.bidiCache.push(new Ks(t.from,t.to,i,e,!0,s)),s}get hasFocus(){var t;return(this.dom.ownerDocument.hasFocus()||j.safari&&(null===(t=this.inputState)||void 0===t?void 0:t.lastContextMenu)>Date.now()-3e4)&&this.root.activeElement==this.contentDOM}focus(){this.observer.ignore(()=>{St(this.contentDOM),this.docView.updateSelection()})}setRoot(t){this._root!=t&&(this._root=t,this.observer.setWindow((9==t.nodeType?t:t.ownerDocument).defaultView||window),this.mountStyles())}destroy(){this.root.activeElement==this.contentDOM&&this.contentDOM.blur();for(let t of this.plugins)t.destroy(this);this.plugins=[],this.inputState.destroy(),this.docView.destroy(),this.dom.remove(),this.observer.destroy(),this.measureScheduled>-1&&this.win.cancelAnimationFrame(this.measureScheduled),this.destroyed=!0}static scrollIntoView(t,e={}){return ae.of(new le("number"==typeof t?o.cursor(t):t,e.y,e.x,e.yMargin,e.xMargin))}scrollSnapshot(){let{scrollTop:t,scrollLeft:e}=this.scrollDOM,i=this.viewState.scrollAnchorAt(t);return ae.of(new le(o.cursor(i.from),"start","start",i.top-t,e,!0))}setTabFocusMode(t){null==t?this.inputState.tabFocusMode=this.inputState.tabFocusMode<0?0:-1:"boolean"==typeof t?this.inputState.tabFocusMode=t?0:-1:0!=this.inputState.tabFocusMode&&(this.inputState.tabFocusMode=Date.now()+t)}static domEventHandlers(t){return pe.define(()=>({}),{eventHandlers:t})}static domEventObservers(t){return pe.define(()=>({}),{eventObservers:t})}static theme(t,e){let i=M.newName(),s=[As.of(i),Ae.of(Es(`.${i}`,t))];return e&&e.dark&&s.push(Ts.of(!0)),s}static baseTheme(t){return n.lowest(Ae.of(Es("."+Ds,t,Bs)))}static findFromDOM(t){var e;let i=t.querySelector(".cm-content"),s=i&&Le.get(i)||Le.get(t);return(null===(e=null==s?void 0:s.root)||void 0===e?void 0:e.view)||null}}zs.styleModule=Ae,zs.inputHandler=te,zs.clipboardInputFilter=ie,zs.clipboardOutputFilter=se,zs.scrollHandler=re,zs.focusChangeEffect=ee,zs.perLineTextDirection=oe,zs.exceptionSink=Jt,zs.updateListener=Zt,zs.editable=de,zs.mouseSelectionStyle=Qt,zs.dragMovesSelection=$t,zs.clickAddsSelectionRange=Ut,zs.decorations=we,zs.blockWrappers=be,zs.outerDecorations=ye,zs.atomicRanges=xe,zs.bidiIsolatedRanges=Se,zs.scrollMargins=Me,zs.darkTheme=Ts,zs.cspNonce=c.define({combine:t=>t.length?t[0]:""}),zs.contentAttributes=ve,zs.editorAttributes=me,zs.lineWrapping=zs.contentAttributes.of({class:"cm-lineWrapping"}),zs.announce=d.define();const Is=4096,qs={};class Ks{constructor(t,e,i,s,o,n){this.from=t,this.to=e,this.dir=i,this.isolates=s,this.fresh=o,this.order=n}static update(t,e){if(e.empty&&!t.some(t=>t.fresh))return t;let i=[],s=t.length?t[t.length-1].dir:Ot.LTR;for(let o=Math.max(0,t.length-10);o<t.length;o++){let n=t[o];n.dir!=s||e.touchesRange(n.from,n.to)||i.push(new Ks(e.mapPos(n.from,1),e.mapPos(n.to,-1),n.dir,n.isolates,!1,n.order))}return i}}function _s(t,e,i){for(let s=t.state.facet(e),o=s.length-1;o>=0;o--){let e=s[o],n="function"==typeof e?e(t):e;n&&X(n,i)}return i}const Ys=j.mac?"mac":j.windows?"win":j.linux?"linux":"key";function js(t,e,i){return e.altKey&&(t="Alt-"+t),e.ctrlKey&&(t="Ctrl-"+t),e.metaKey&&(t="Meta-"+t),!1!==i&&e.shiftKey&&(t="Shift-"+t),t}const Xs=n.default(zs.domEventHandlers({keydown:(t,e)=>eo($s(e.state),t,e,"editor")})),Gs=c.define({enables:Xs}),Us=new WeakMap;function $s(t){let e=t.facet(Gs),i=Us.get(e);return i||Us.set(e,i=function(t,e=Ys){let i=Object.create(null),s=Object.create(null),o=(t,e)=>{let i=s[t];if(null==i)s[t]=e;else if(i!=e)throw new Error("Key binding "+t+" is used both as a regular binding and as a multi-stroke prefix")},n=(t,s,n,r,l)=>{var a,h;let c=i[t]||(i[t]=Object.create(null)),d=s.split(/ (?!$)/).map(t=>function(t,e){const i=t.split(/-(?!$)/);let s,o,n,r,l=i[i.length-1];"Space"==l&&(l=" ");for(let t=0;t<i.length-1;++t){const l=i[t];if(/^(cmd|meta|m)$/i.test(l))r=!0;else if(/^a(lt)?$/i.test(l))s=!0;else if(/^(c|ctrl|control)$/i.test(l))o=!0;else if(/^s(hift)?$/i.test(l))n=!0;else{if(!/^mod$/i.test(l))throw new Error("Unrecognized modifier name: "+l);"mac"==e?r=!0:o=!0}}return s&&(l="Alt-"+l),o&&(l="Ctrl-"+l),r&&(l="Meta-"+l),n&&(l="Shift-"+l),l}(t,e));for(let e=1;e<d.length;e++){let i=d.slice(0,e).join(" ");o(i,!0),c[i]||(c[i]={preventDefault:!0,stopPropagation:!1,run:[e=>{let s=Js={view:e,prefix:i,scope:t};return setTimeout(()=>{Js==s&&(Js=null)},Zs),!0}]})}let u=d.join(" ");o(u,!1);let f=c[u]||(c[u]={preventDefault:!1,stopPropagation:!1,run:(null===(h=null===(a=c._any)||void 0===a?void 0:a.run)||void 0===h?void 0:h.slice())||[]});n&&f.run.push(n),r&&(f.preventDefault=!0),l&&(f.stopPropagation=!0)};for(let s of t){let t=s.scope?s.scope.split(" "):["editor"];if(s.any)for(let e of t){let t=i[e]||(i[e]=Object.create(null));t._any||(t._any={preventDefault:!1,stopPropagation:!1,run:[]});let{any:o}=s;for(let e in t)t[e].run.push(t=>o(t,to))}let o=s[e]||s.key;if(o)for(let e of t)n(e,o,s.run,s.preventDefault,s.stopPropagation),s.shift&&n(e,"Shift-"+o,s.shift,s.preventDefault,s.stopPropagation)}return i}(e.reduce((t,e)=>t.concat(e),[]))),i}function Qs(t,e,i){return eo($s(t.state),e,t,i)}let Js=null;const Zs=4e3;let to=null;function eo(t,e,i,s){to=e;let o=function(t){var e=!(O&&t.metaKey&&t.shiftKey&&!t.ctrlKey&&!t.altKey||L&&t.shiftKey&&t.key&&1==t.key.length||"Unidentified"==t.key)&&t.key||(t.shiftKey?D:T)[t.keyCode]||t.key||"Unidentified";return"Esc"==e&&(e="Escape"),"Del"==e&&(e="Delete"),"Left"==e&&(e="ArrowLeft"),"Up"==e&&(e="ArrowUp"),"Right"==e&&(e="ArrowRight"),"Down"==e&&(e="ArrowDown"),e}(e),n=m(o,0),r=w(n)==o.length&&" "!=o,l="",a=!1,h=!1,c=!1;Js&&Js.view==i&&Js.scope==s&&(l=Js.prefix+" ",Li.indexOf(e.keyCode)<0&&(h=!0,Js=null));let d,u,f=new Set,p=t=>{if(t){for(let e of t.run)if(!f.has(e)&&(f.add(e),e(i)))return t.stopPropagation&&(c=!0),!0;t.preventDefault&&(t.stopPropagation&&(c=!0),h=!0)}return!1},g=t[s];return g&&(p(g[l+js(o,e,!r)])?a=!0:!r||!(e.altKey||e.metaKey||e.ctrlKey)||j.windows&&e.ctrlKey&&e.altKey||j.mac&&e.altKey&&!e.ctrlKey&&!e.metaKey||!(d=T[e.keyCode])||d==o?r&&e.shiftKey&&p(g[l+js(o,e,!0)])&&(a=!0):(p(g[l+js(d,e,!0)])||e.shiftKey&&(u=D[e.keyCode])!=o&&u!=d&&p(g[l+js(u,e,!1)]))&&(a=!0),!a&&p(g._any)&&(a=!0)),h&&(a=!0),a&&c&&e.stopPropagation(),to=null,a}class io{constructor(t,e,i,s,o){this.className=t,this.left=e,this.top=i,this.width=s,this.height=o}draw(){let t=document.createElement("div");return t.className=this.className,this.adjust(t),t}update(t,e){return e.className==this.className&&(this.adjust(t),!0)}adjust(t){t.style.left=this.left+"px",t.style.top=this.top+"px",null!=this.width&&(t.style.width=this.width+"px"),t.style.height=this.height+"px"}eq(t){return this.left==t.left&&this.top==t.top&&this.width==t.width&&this.height==t.height&&this.className==t.className}static forRange(t,e,i){if(i.empty){let s=t.coordsAtPos(i.head,i.assoc||1);if(!s)return[];let o=so(t);return[new io(e,s.left-o.left,s.top-o.top,null,s.bottom-s.top)]}return function(t,e,i){if(i.to<=t.viewport.from||i.from>=t.viewport.to)return[];let s=Math.max(i.from,t.viewport.from),o=Math.min(i.to,t.viewport.to),n=t.textDirection==Ot.LTR,r=t.contentDOM,l=r.getBoundingClientRect(),a=so(t),h=r.querySelector(".cm-line"),c=h&&window.getComputedStyle(h),d=l.left+(c?parseInt(c.paddingLeft)+Math.min(0,parseInt(c.textIndent)):0),u=l.right-(c?parseInt(c.paddingRight):0),f=ni(t,s,1),p=ni(t,o,-1),g=f.type==Z.Text?f:null,m=p.type==Z.Text?p:null;g&&(t.lineWrapping||f.widgetLineBreaks)&&(g=oo(t,s,1,g));m&&(t.lineWrapping||p.widgetLineBreaks)&&(m=oo(t,o,-1,m));if(g&&m&&g.from==m.from&&g.to==m.to)return w(b(i.from,i.to,g));{let e=g?b(i.from,null,g):y(f,!1),s=m?b(null,i.to,m):y(p,!0),o=[];return(g||f).to<(m||p).from-(g&&m?1:0)||f.widgetLineBreaks>1&&e.bottom+t.defaultLineHeight/2<s.top?o.push(v(d,e.bottom,u,s.top)):e.bottom<s.top&&t.elementAtHeight((e.bottom+s.top)/2).type==Z.Text&&(e.bottom=s.top=(e.bottom+s.top)/2),w(e).concat(o).concat(w(s))}function v(t,i,s,o){return new io(e,t-a.left,i-a.top,s-t,o-i)}function w({top:t,bottom:e,horizontal:i}){let s=[];for(let o=0;o<i.length;o+=2)s.push(v(i[o],t,i[o+1],e));return s}function b(e,i,s){let o=1e9,r=-1e9,l=[];function a(e,i,a,h,c){let f=t.coordsAtPos(e,e==s.to?-2:2),p=t.coordsAtPos(a,a==s.from?2:-2);f&&p&&(o=Math.min(f.top,p.top,o),r=Math.max(f.bottom,p.bottom,r),c==Ot.LTR?l.push(n&&i?d:f.left,n&&h?u:p.right):l.push(!n&&h?d:p.left,!n&&i?u:f.right))}let h=null!=e?e:s.from,c=null!=i?i:s.to;for(let s of t.visibleRanges)if(s.to>h&&s.from<c)for(let o=Math.max(s.from,h),n=Math.min(s.to,c);;){let s=t.state.doc.lineAt(o);for(let r of t.bidiSpans(s)){let t=r.from+s.from,l=r.to+s.from;if(t>=n)break;l>o&&a(Math.max(t,o),null==e&&t<=h,Math.min(l,n),null==i&&l>=c,r.dir)}if(o=s.to+1,o>=n)break}return 0==l.length&&a(h,null==e,c,null==i,t.textDirection),{top:o,bottom:r,horizontal:l}}function y(t,e){let i=l.top+(e?t.top:t.bottom);return{top:i,bottom:i,horizontal:[]}}}(t,e,i)}}function so(t){let e=t.scrollDOM.getBoundingClientRect();return{left:(t.textDirection==Ot.LTR?e.left:e.right-t.scrollDOM.clientWidth*t.scaleX)-t.scrollDOM.scrollLeft*t.scaleX,top:e.top-t.scrollDOM.scrollTop*t.scaleY}}function oo(t,e,i,s){let o=t.coordsAtPos(e,2*i);if(!o)return s;let n=t.dom.getBoundingClientRect(),r=(o.top+o.bottom)/2,l=t.posAtCoords({x:n.left+1,y:r}),a=t.posAtCoords({x:n.right-1,y:r});return null==l||null==a?s:{from:Math.max(s.from,Math.min(l,a)),to:Math.min(s.to,Math.max(l,a))}}class no{constructor(t,e){this.view=t,this.layer=e,this.drawn=[],this.scaleX=1,this.scaleY=1,this.measureReq={read:this.measure.bind(this),write:this.draw.bind(this)},this.dom=t.scrollDOM.appendChild(document.createElement("div")),this.dom.classList.add("cm-layer"),e.above&&this.dom.classList.add("cm-layer-above"),e.class&&this.dom.classList.add(e.class),this.scale(),this.dom.setAttribute("aria-hidden","true"),this.setOrder(t.state),t.requestMeasure(this.measureReq),e.mount&&e.mount(this.dom,t)}update(t){t.startState.facet(ro)!=t.state.facet(ro)&&this.setOrder(t.state),(this.layer.update(t,this.dom)||t.geometryChanged)&&(this.scale(),t.view.requestMeasure(this.measureReq))}docViewUpdate(t){!1!==this.layer.updateOnDocViewUpdate&&t.requestMeasure(this.measureReq)}setOrder(t){let e=0,i=t.facet(ro);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)}scale(){let{scaleX:t,scaleY:e}=this.view;t==this.scaleX&&e==this.scaleY||(this.scaleX=t,this.scaleY=e,this.dom.style.transform=`scale(${1/t}, ${1/e})`)}draw(t){if(t.length!=this.drawn.length||t.some((t,e)=>{return i=t,s=this.drawn[e],!(i.constructor==s.constructor&&i.eq(s));var i,s})){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 t=e.nextSibling;e.remove(),e=t}this.drawn=t,j.safari&&j.safari_version>=26&&(this.dom.style.display=this.dom.firstChild?"":"none")}}destroy(){this.layer.destroy&&this.layer.destroy(this.dom,this.view),this.dom.remove()}}const ro=c.define();function lo(t){return[pe.define(e=>new no(e,t)),ro.of(t)]}const ao=c.define({combine:t=>g(t,{cursorBlinkRate:1200,drawRangeCursor:!0},{cursorBlinkRate:(t,e)=>Math.min(t,e),drawRangeCursor:(t,e)=>t||e})});function ho(t={}){return[ao.of(t),uo,po,go,ne.of(!0)]}function co(t){return t.startState.facet(ao)!=t.state.facet(ao)}const uo=lo({above:!0,markers(t){let{state:e}=t,i=e.facet(ao),s=[];for(let n of e.selection.ranges){let r=n==e.selection.main;if(n.empty||i.drawRangeCursor){let e=r?"cm-cursor cm-cursor-primary":"cm-cursor cm-cursor-secondary",i=n.empty?n:o.cursor(n.head,n.head>n.anchor?-1:1);for(let o of io.forRange(t,e,i))s.push(o)}}return s},update(t,e){t.transactions.some(t=>t.selection)&&(e.style.animationName="cm-blink"==e.style.animationName?"cm-blink2":"cm-blink");let i=co(t);return i&&fo(t.state,e),t.docChanged||t.selectionSet||i},mount(t,e){fo(e.state,t)},class:"cm-cursorLayer"});function fo(t,e){e.style.animationDuration=t.facet(ao).cursorBlinkRate+"ms"}const po=lo({above:!1,markers:t=>t.state.selection.ranges.map(e=>e.empty?[]:io.forRange(t,"cm-selectionBackground",e)).reduce((t,e)=>t.concat(e)),update:(t,e)=>t.docChanged||t.selectionSet||t.viewportChanged||co(t),class:"cm-selectionLayer"}),go=n.highest(zs.theme({".cm-line":{"& ::selection, &::selection":{backgroundColor:"transparent !important"},caretColor:"transparent !important"},".cm-content":{caretColor:"transparent !important","& :focus":{caretColor:"initial !important","&::selection, & ::selection":{backgroundColor:"Highlight !important"}}}})),mo=d.define({map:(t,e)=>null==t?null:e.mapPos(t)}),vo=u.define({create:()=>null,update:(t,e)=>(null!=t&&(t=e.changes.mapPos(t)),e.effects.reduce((t,e)=>e.is(mo)?e.value:t,t))}),wo=pe.fromClass(class{constructor(t){this.view=t,this.cursor=null,this.measureReq={read:this.readPos.bind(this),write:this.drawCursor.bind(this)}}update(t){var e;let i=t.state.field(vo);null==i?null!=this.cursor&&(null===(e=this.cursor)||void 0===e||e.remove(),this.cursor=null):(this.cursor||(this.cursor=this.view.scrollDOM.appendChild(document.createElement("div")),this.cursor.className="cm-dropCursor"),(t.startState.field(vo)!=i||t.docChanged||t.geometryChanged)&&this.view.requestMeasure(this.measureReq))}readPos(){let{view:t}=this,e=t.state.field(vo),i=null!=e&&t.coordsAtPos(e);if(!i)return null;let s=t.scrollDOM.getBoundingClientRect();return{left:i.left-s.left+t.scrollDOM.scrollLeft*t.scaleX,top:i.top-s.top+t.scrollDOM.scrollTop*t.scaleY,height:i.bottom-i.top}}drawCursor(t){if(this.cursor){let{scaleX:e,scaleY:i}=this.view;t?(this.cursor.style.left=t.left/e+"px",this.cursor.style.top=t.top/i+"px",this.cursor.style.height=t.height/i+"px"):this.cursor.style.left="-100000px"}}destroy(){this.cursor&&this.cursor.remove()}setDropPos(t){this.view.state.field(vo)!=t&&this.view.dispatch({effects:mo.of(t)})}},{eventObservers:{dragover(t){this.setDropPos(this.view.posAtCoords({x:t.clientX,y:t.clientY}))},dragleave(t){t.target!=this.view.contentDOM&&this.view.contentDOM.contains(t.relatedTarget)||this.setDropPos(null)},dragend(){this.setDropPos(null)},drop(){this.setDropPos(null)}}});function bo(){return[vo,wo]}function yo(t,e,i,s,o){e.lastIndex=0;for(let n,r=t.iterRange(i,s),l=i;!r.next().done;l+=r.value.length)if(!r.lineBreak)for(;n=e.exec(r.value);)o(l+n.index,n)}class xo{constructor(t){const{regexp:e,decoration:i,decorate:s,boundary:o,maxLength:n=1e3}=t;if(!e.global)throw new RangeError("The regular expression given to MatchDecorator should have its 'g' flag set");if(this.regexp=e,s)this.addMatch=(t,e,i,o)=>s(o,i,i+t[0].length,t,e);else if("function"==typeof i)this.addMatch=(t,e,s,o)=>{let n=i(t,e,s);n&&o(s,s+t[0].length,n)};else{if(!i)throw new RangeError("Either 'decorate' or 'decoration' should be provided to MatchDecorator");this.addMatch=(t,e,s,o)=>o(s,s+t[0].length,i)}this.boundary=o,this.maxLength=n}createDeco(t){let e=new r,i=e.add.bind(e);for(let{from:e,to:s}of function(t,e){let i=t.visibleRanges;if(1==i.length&&i[0].from==t.viewport.from&&i[0].to==t.viewport.to)return i;let s=[];for(let{from:o,to:n}of i)o=Math.max(t.state.doc.lineAt(o).from,o-e),n=Math.min(t.state.doc.lineAt(n).to,n+e),s.length&&s[s.length-1].to>=o?s[s.length-1].to=n:s.push({from:o,to:n});return s}(t,this.maxLength))yo(t.state.doc,this.regexp,e,s,(e,s)=>this.addMatch(s,t,e,i));return e.finish()}updateDeco(t,e){let i=1e9,s=-1;return t.docChanged&&t.changes.iterChanges((e,o,n,r)=>{r>=t.view.viewport.from&&n<=t.view.viewport.to&&(i=Math.min(n,i),s=Math.max(r,s))}),t.viewportMoved||s-i>1e3?this.createDeco(t.view):s>-1?this.updateRange(t.view,e.map(t.changes),i,s):e}updateRange(t,e,i,s){for(let o of t.visibleRanges){let n=Math.max(o.from,i),r=Math.min(o.to,s);if(r>=n){let i=t.state.doc.lineAt(n),s=i.to<r?t.state.doc.lineAt(r):i,l=Math.max(o.from,i.from),a=Math.min(o.to,s.to);if(this.boundary){for(;n>i.from;n--)if(this.boundary.test(i.text[n-1-i.from])){l=n;break}for(;r<s.to;r++)if(this.boundary.test(s.text[r-s.from])){a=r;break}}let h,c=[],d=(t,e,i)=>c.push(i.range(t,e));if(i==s)for(this.regexp.lastIndex=l-i.from;(h=this.regexp.exec(i.text))&&h.index<a-i.from;)this.addMatch(h,t,h.index+i.from,d);else yo(t.state.doc,this.regexp,l,a,(e,i)=>this.addMatch(i,t,e,d));e=e.update({filterFrom:l,filterTo:a,filter:(t,e)=>t<l||e>a,add:c})}}return e}}const So=null!=/x/.unicode?"gu":"g",Co=new RegExp("[\0-\b\n--Ÿ­؜​‎‏\u2028\u2029‭‮⁦⁧⁩\ufeff-]",So),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 ko=null;const Ao=c.define({combine(t){let e=g(t,{render:null,specialChars:Co,addSpecialChars:null});return(e.replaceTabs=!function(){var t;if(null==ko&&"undefined"!=typeof document&&document.body){let e=document.body.style;ko=null!=(null!==(t=e.tabSize)&&void 0!==t?t:e.MozTabSize)}return ko||!1}())&&(e.specialChars=new RegExp("\t|"+e.specialChars.source,So)),e.addSpecialChars&&(e.specialChars=new RegExp(e.specialChars.source+"|"+e.addSpecialChars.source,So)),e}});function To(t={}){return[Ao.of(t),Do||(Do=pe.fromClass(class{constructor(t){this.view=t,this.decorations=tt.none,this.decorationCache=Object.create(null),this.decorator=this.makeDecorator(t.state.facet(Ao)),this.decorations=this.decorator.createDeco(t)}makeDecorator(t){return new xo({regexp:t.specialChars,decoration:(e,i,s)=>{let{doc:o}=i.state,n=m(e[0],0);if(9==n){let t=o.lineAt(s),e=i.state.tabSize,n=v(t.text,e,s-t.from);return tt.replace({widget:new Lo((e-n%e)*this.view.defaultCharacterWidth/this.view.scaleX)})}return this.decorationCache[n]||(this.decorationCache[n]=tt.replace({widget:new Oo(t,n)}))},boundary:t.replaceTabs?void 0:/[^]/})}update(t){let e=t.state.facet(Ao);t.startState.facet(Ao)!=e?(this.decorator=this.makeDecorator(e),this.decorations=this.decorator.createDeco(t.view)):this.decorations=this.decorator.updateDeco(t,this.decorations)}},{decorations:t=>t.decorations}))]}let Do=null;class Oo extends J{constructor(t,e){super(),this.options=t,this.code=e}eq(t){return t.code==this.code}toDOM(t){let e=function(t){return t>=32?"•":10==t?"␤":String.fromCharCode(9216+t)}(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 o=document.createElement("span");return o.textContent=e,o.title=i,o.setAttribute("aria-label",i),o.className="cm-specialChar",o}ignoreEvent(){return!1}}class Lo extends J{constructor(t){super(),this.width=t}eq(t){return t.width==this.width}toDOM(){let t=document.createElement("span");return t.textContent="\t",t.className="cm-tab",t.style.width=this.width+"px",t}ignoreEvent(){return!1}}const Bo=pe.fromClass(class{constructor(){this.height=1e3,this.attrs={style:"padding-bottom: 1000px"}}update(t){let{view:e}=t,i=e.viewState.editorHeight-e.defaultLineHeight-e.documentPadding.top-.5;i>=0&&i!=this.height&&(this.height=i,this.attrs={style:`padding-bottom: ${i}px`})}});function Eo(){return Ho}const Ro=tt.line({class:"cm-activeLine"}),Ho=pe.fromClass(class{constructor(t){this.decorations=this.getDeco(t)}update(t){(t.docChanged||t.selectionSet)&&(this.decorations=this.getDeco(t.view))}getDeco(t){let e=-1,i=[];for(let s of t.state.selection.ranges){let o=t.lineBlockAt(s.head);o.from>e&&(i.push(Ro.range(o.from)),e=o.from)}return tt.set(i)}},{decorations:t=>t.decorations});class Wo extends J{constructor(t){super(),this.content=t}toDOM(t){let e=document.createElement("span");return e.className="cm-placeholder",e.style.pointerEvents="none",e.appendChild("string"==typeof this.content?document.createTextNode(this.content):"function"==typeof this.content?this.content(t):this.content.cloneNode(!0)),e.setAttribute("aria-hidden","true"),e}coordsAt(t){let e=t.firstChild?ct(t.firstChild):[];if(!e.length)return null;let i=window.getComputedStyle(t.parentNode),s=mt(e[0],"rtl"!=i.direction),o=parseInt(i.lineHeight);return s.bottom-s.top>1.5*o?{left:s.left,right:s.right,top:s.top,bottom:s.top+o}:s}ignoreEvent(){return!1}}const No=2e3;function Po(t,e){let i=t.posAtCoords({x:e.clientX,y:e.clientY},!1),s=t.state.doc.lineAt(i),o=i-s.from,n=o>No?-1:o==s.length?function(t,e){let i=t.coordsAtPos(t.viewport.from);return i?Math.round(Math.abs((i.left-e)/t.defaultCharacterWidth)):-1}(t,e.clientX):v(s.text,t.state.tabSize,i-s.from);return{line:s.number,col:n,off:o}}function Vo(t,e){let i=Po(t,e),s=t.state.selection;return i?{update(t){if(t.docChanged){let e=t.changes.mapPos(t.startState.doc.line(i.line).from),o=t.state.doc.lineAt(e);i={line:o.number,col:i.col,off:Math.min(i.off,o.length)},s=s.map(t.changes)}},get(e,n,r){let l=Po(t,e);if(!l)return s;let a=function(t,e,i){let s=Math.min(e.line,i.line),n=Math.max(e.line,i.line),r=[];if(e.off>No||i.off>No||e.col<0||i.col<0){let l=Math.min(e.off,i.off),a=Math.max(e.off,i.off);for(let e=s;e<=n;e++){let i=t.doc.line(e);i.length<=a&&r.push(o.range(i.from+l,i.to+a))}}else{let l=Math.min(e.col,i.col),a=Math.max(e.col,i.col);for(let e=s;e<=n;e++){let i=t.doc.line(e),s=b(i.text,l,t.tabSize,!0);if(s<0)r.push(o.cursor(i.to));else{let e=b(i.text,a,t.tabSize);r.push(o.range(i.from+s,i.from+e))}}}return r}(t.state,i,l);return a.length?r?o.create(a.concat(s.ranges)):o.create(a):s}}:null}function Fo(t){let e=(null==t?void 0:t.eventFilter)||(t=>t.altKey&&0==t.button);return zs.mouseSelectionStyle.of((t,i)=>e(i)?Vo(t,i):null)}const zo={Alt:[18,t=>!!t.altKey],Control:[17,t=>!!t.ctrlKey],Shift:[16,t=>!!t.shiftKey],Meta:[91,t=>!!t.metaKey]},Io={style:"cursor: crosshair"};function qo(t={}){let[e,i]=zo[t.key||"Alt"],s=pe.fromClass(class{constructor(t){this.view=t,this.isDown=!1}set(t){this.isDown!=t&&(this.isDown=t,this.view.update([]))}},{eventObservers:{keydown(t){this.set(t.keyCode==e||i(t))},keyup(t){t.keyCode!=e&&i(t)||this.set(!1)},mousemove(t){this.set(i(t))}}});return[s,zs.contentAttributes.of(t=>{var e;return(null===(e=t.plugin(s))||void 0===e?void 0:e.isDown)?Io:null})]}const Ko="-10000px";class _o{constructor(t,e,i,s){this.facet=e,this.createTooltipView=i,this.removeTooltipView=s,this.input=t.state.facet(e),this.tooltips=this.input.filter(t=>t);let o=null;this.tooltipViews=this.tooltips.map(t=>o=i(t,o))}update(t,e){var i;let s=t.state.facet(this.facet),o=s.filter(t=>t);if(s===this.input){for(let e of this.tooltipViews)e.update&&e.update(t);return!1}let n=[],r=e?[]:null;for(let i=0;i<o.length;i++){let s=o[i],l=-1;if(s){for(let t=0;t<this.tooltips.length;t++){let e=this.tooltips[t];e&&e.create==s.create&&(l=t)}if(l<0)n[i]=this.createTooltipView(s,i?n[i-1]:null),r&&(r[i]=!!s.above);else{let s=n[i]=this.tooltipViews[l];r&&(r[i]=e[l]),s.update&&s.update(t)}}}for(let t of this.tooltipViews)n.indexOf(t)<0&&(this.removeTooltipView(t),null===(i=t.destroy)||void 0===i||i.call(t));return e&&(r.forEach((t,i)=>e[i]=t),e.length=r.length),this.input=s,this.tooltips=o,this.tooltipViews=n,!0}}function Yo(t){let e=t.dom.ownerDocument.documentElement;return{top:0,left:0,bottom:e.clientHeight,right:e.clientWidth}}const jo=c.define({combine:t=>{var e,i,s;return{position:j.ios?"absolute":(null===(e=t.find(t=>t.position))||void 0===e?void 0:e.position)||"fixed",parent:(null===(i=t.find(t=>t.parent))||void 0===i?void 0:i.parent)||null,tooltipSpace:(null===(s=t.find(t=>t.tooltipSpace))||void 0===s?void 0:s.tooltipSpace)||Yo}}}),Xo=new WeakMap,Go=pe.fromClass(class{constructor(t){this.view=t,this.above=[],this.inView=!0,this.madeAbsolute=!1,this.lastTransaction=0,this.measureTimeout=-1;let e=t.state.facet(jo);this.position=e.position,this.parent=e.parent,this.classes=t.themeClasses,this.createContainer(),this.measureReq={read:this.readMeasure.bind(this),write:this.writeMeasure.bind(this),key:this},this.resizeObserver="function"==typeof ResizeObserver?new ResizeObserver(()=>this.measureSoon()):null,this.manager=new _o(t,Jo,(t,e)=>this.createTooltip(t,e),t=>{this.resizeObserver&&this.resizeObserver.unobserve(t.dom),t.dom.remove()}),this.above=this.manager.tooltips.map(t=>!!t.above),this.intersectionObserver="function"==typeof IntersectionObserver?new IntersectionObserver(t=>{Date.now()>this.lastTransaction-50&&t.length>0&&t[t.length-1].intersectionRatio<1&&this.measureSoon()},{threshold:[1]}):null,this.observeIntersection(),t.win.addEventListener("resize",this.measureSoon=this.measureSoon.bind(this)),this.maybeMeasure()}createContainer(){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 t of this.manager.tooltipViews)this.intersectionObserver.observe(t.dom)}}measureSoon(){this.measureTimeout<0&&(this.measureTimeout=setTimeout(()=>{this.measureTimeout=-1,this.maybeMeasure()},50))}update(t){t.transactions.length&&(this.lastTransaction=Date.now());let e=this.manager.update(t,this.above);e&&this.observeIntersection();let i=e||t.geometryChanged,s=t.state.facet(jo);if(s.position!=this.position&&!this.madeAbsolute){this.position=s.position;for(let t of this.manager.tooltipViews)t.dom.style.position=this.position;i=!0}if(s.parent!=this.parent){this.parent&&this.container.remove(),this.parent=s.parent,this.createContainer();for(let t of this.manager.tooltipViews)this.container.appendChild(t.dom);i=!0}else this.parent&&this.view.themeClasses!=this.classes&&(this.classes=this.container.className=this.view.themeClasses);i&&this.maybeMeasure()}createTooltip(t,e){let i=t.create(this.view),s=e?e.dom:null;if(i.dom.classList.add("cm-tooltip"),t.arrow&&!i.dom.querySelector(".cm-tooltip > .cm-tooltip-arrow")){let t=document.createElement("div");t.className="cm-tooltip-arrow",i.dom.appendChild(t)}return i.dom.style.position=this.position,i.dom.style.top=Ko,i.dom.style.left="0px",this.container.insertBefore(i.dom,s),i.mount&&i.mount(this.view),this.resizeObserver&&this.resizeObserver.observe(i.dom),i}destroy(){var t,e,i;this.view.win.removeEventListener("resize",this.measureSoon);for(let e of this.manager.tooltipViews)e.dom.remove(),null===(t=e.destroy)||void 0===t||t.call(e);this.parent&&this.container.remove(),null===(e=this.resizeObserver)||void 0===e||e.disconnect(),null===(i=this.intersectionObserver)||void 0===i||i.disconnect(),clearTimeout(this.measureTimeout)}readMeasure(){let t=1,e=1,i=!1;if("fixed"==this.position&&this.manager.tooltipViews.length){let{dom:t}=this.manager.tooltipViews[0];if(j.safari){let e=t.getBoundingClientRect();i=Math.abs(e.top+1e4)>1||Math.abs(e.left)>1}else i=!!t.offsetParent&&t.offsetParent!=this.container.ownerDocument.body}if(i||"absolute"==this.position)if(this.parent){let i=this.parent.getBoundingClientRect();i.width&&i.height&&(t=i.width/this.parent.offsetWidth,e=i.height/this.parent.offsetHeight)}else({scaleX:t,scaleY:e}=this.view.viewState);let s=this.view.scrollDOM.getBoundingClientRect(),o=ke(this.view);return{visible:{left:s.left+o.left,top:s.top+o.top,right:s.right-o.right,bottom:s.bottom-o.bottom},parent:this.parent?this.container.getBoundingClientRect():this.view.dom.getBoundingClientRect(),pos:this.manager.tooltips.map((t,e)=>{let i=this.manager.tooltipViews[e];return i.getCoords?i.getCoords(t.pos):this.view.coordsAtPos(t.pos)}),size:this.manager.tooltipViews.map(({dom:t})=>t.getBoundingClientRect()),space:this.view.state.facet(jo).tooltipSpace(this.view),scaleX:t,scaleY:e,makeAbsolute:i}}writeMeasure(t){var e;if(t.makeAbsolute){this.madeAbsolute=!0,this.position="absolute";for(let t of this.manager.tooltipViews)t.dom.style.position="absolute"}let{visible:i,space:s,scaleX:o,scaleY:n}=t,r=[];for(let l=0;l<this.manager.tooltips.length;l++){let a=this.manager.tooltips[l],h=this.manager.tooltipViews[l],{dom:c}=h,d=t.pos[l],u=t.size[l];if(!d||!1!==a.clip&&(d.bottom<=Math.max(i.top,s.top)||d.top>=Math.min(i.bottom,s.bottom)||d.right<Math.max(i.left,s.left)-.1||d.left>Math.min(i.right,s.right)+.1)){c.style.top=Ko;continue}let f=a.arrow?h.dom.querySelector(".cm-tooltip-arrow"):null,p=f?7:0,g=u.right-u.left,m=null!==(e=Xo.get(h))&&void 0!==e?e:u.bottom-u.top,v=h.offset||Qo,w=this.view.textDirection==Ot.LTR,b=u.width>s.right-s.left?w?s.left:s.right-u.width:w?Math.max(s.left,Math.min(d.left-(f?14:0)+v.x,s.right-g)):Math.min(Math.max(s.left,d.left-g+(f?14:0)-v.x),s.right-g),y=this.above[l];!a.strictSide&&(y?d.top-m-p-v.y<s.top:d.bottom+m+p+v.y>s.bottom)&&y==s.bottom-d.bottom>d.top-s.top&&(y=this.above[l]=!y);let x=(y?d.top-s.top:s.bottom-d.bottom)-p;if(x<m&&!1!==h.resize){if(x<this.view.defaultLineHeight){c.style.top=Ko;continue}Xo.set(h,m),c.style.height=(m=x)/n+"px"}else c.style.height&&(c.style.height="");let S=y?d.top-m-p-v.y:d.bottom+p+v.y,C=b+g;if(!0!==h.overlap)for(let t of r)t.left<C&&t.right>b&&t.top<S+m&&t.bottom>S&&(S=y?t.top-m-2-p:t.bottom+p+2);if("absolute"==this.position?(c.style.top=(S-t.parent.top)/n+"px",Uo(c,(b-t.parent.left)/o)):(c.style.top=S/n+"px",Uo(c,b/o)),f){let t=d.left+(w?v.x:-v.x)-(b+14-7);f.style.left=t/o+"px"}!0!==h.overlap&&r.push({left:b,top:S,right:C,bottom:S+m}),c.classList.toggle("cm-tooltip-above",y),c.classList.toggle("cm-tooltip-below",!y),h.positioned&&h.positioned(t.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 t of this.manager.tooltipViews)t.dom.style.top=Ko}},{eventObservers:{scroll(){this.maybeMeasure()}}});function Uo(t,e){let i=parseInt(t.style.left,10);(isNaN(i)||Math.abs(e-i)>1)&&(t.style.left=e+"px")}const $o=zs.baseTheme({".cm-tooltip":{zIndex:500,boxSizing:"border-box"},"&light .cm-tooltip":{border:"1px solid #bbb",backgroundColor:"#f5f5f5"},"&light .cm-tooltip-section:not(:first-child)":{borderTop:"1px solid #bbb"},"&dark .cm-tooltip":{backgroundColor:"#333338",color:"white"},".cm-tooltip-arrow":{height:"7px",width:"14px",position:"absolute",zIndex:-1,overflow:"hidden","&:before, &:after":{content:"''",position:"absolute",width:0,height:0,borderLeft:"7px solid transparent",borderRight:"7px solid transparent"},".cm-tooltip-above &":{bottom:"-7px","&:before":{borderTop:"7px solid #bbb"},"&:after":{borderTop:"7px solid #f5f5f5",bottom:"1px"}},".cm-tooltip-below &":{top:"-7px","&:before":{borderBottom:"7px solid #bbb"},"&:after":{borderBottom:"7px solid #f5f5f5",top:"1px"}}},"&dark .cm-tooltip .cm-tooltip-arrow":{"&:before":{borderTopColor:"#333338",borderBottomColor:"#333338"},"&:after":{borderTopColor:"transparent",borderBottomColor:"transparent"}}}),Qo={x:0,y:0},Jo=c.define({enables:[Go,$o]}),Zo=c.define({combine:t=>t.reduce((t,e)=>t.concat(e),[])});class tn{static create(t){return new tn(t)}constructor(t){this.view=t,this.mounted=!1,this.dom=document.createElement("div"),this.dom.classList.add("cm-tooltip-hover"),this.manager=new _o(t,Zo,(t,e)=>this.createHostedView(t,e),t=>t.dom.remove())}createHostedView(t,e){let i=t.create(this.view);return i.dom.classList.add("cm-tooltip-section"),this.dom.insertBefore(i.dom,e?e.dom.nextSibling:this.dom.firstChild),this.mounted&&i.mount&&i.mount(this.view),i}mount(t){for(let e of this.manager.tooltipViews)e.mount&&e.mount(t);this.mounted=!0}positioned(t){for(let e of this.manager.tooltipViews)e.positioned&&e.positioned(t)}update(t){this.manager.update(t)}destroy(){var t;for(let e of this.manager.tooltipViews)null===(t=e.destroy)||void 0===t||t.call(e)}passProp(t){let e;for(let i of this.manager.tooltipViews){let s=i[t];if(void 0!==s)if(void 0===e)e=s;else if(e!==s)return}return e}get offset(){return this.passProp("offset")}get getCoords(){return this.passProp("getCoords")}get overlap(){return this.passProp("overlap")}get resize(){return this.passProp("resize")}}const en=Jo.compute([Zo],t=>{let e=t.facet(Zo);return 0===e.length?null:{pos:Math.min(...e.map(t=>t.pos)),end:Math.max(...e.map(t=>{var e;return null!==(e=t.end)&&void 0!==e?e:t.pos})),create:tn.create,above:e[0].above,arrow:e.some(t=>t.arrow)}});class sn{constructor(t,e,i,s,o){this.view=t,this.source=e,this.field=i,this.setHover=s,this.hoverTime=o,this.hoverTimeout=-1,this.restartTimeout=-1,this.pending=null,this.lastMove={x:0,y:0,target:t.dom,time:0},this.checkHover=this.checkHover.bind(this),t.dom.addEventListener("mouseleave",this.mouseleave=this.mouseleave.bind(this)),t.dom.addEventListener("mousemove",this.mousemove=this.mousemove.bind(this))}update(){this.pending&&(this.pending=null,clearTimeout(this.restartTimeout),this.restartTimeout=setTimeout(()=>this.startHover(),20))}get active(){return this.view.state.field(this.field)}checkHover(){if(this.hoverTimeout=-1,this.active.length)return;let t=Date.now()-this.lastMove.time;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.tile.nearest(e.target);if(!i)return;let s,o=1;if(i.isWidget())s=i.posAtStart;else{if(s=t.posAtCoords(e),null==s)return;let i=t.coordsAtPos(s);if(!i||e.y<i.top||e.y>i.bottom||e.x<i.left-t.defaultCharacterWidth||e.x>i.right+t.defaultCharacterWidth)return;let n=t.bidiSpans(t.state.doc.lineAt(s)).find(t=>t.from<=s&&t.to>=s),r=n&&n.dir==Ot.RTL?-1:1;o=e.x<i.left?-r:r}let n=this.source(t,s,o);if(null==n?void 0:n.then){let e=this.pending={pos:s};n.then(i=>{this.pending==e&&(this.pending=null,!i||Array.isArray(i)&&!i.length||t.dispatch({effects:this.setHover.of(Array.isArray(i)?i:[i])}))},e=>ce(t.state,e,"hover tooltip"))}else!n||Array.isArray(n)&&!n.length||t.dispatch({effects:this.setHover.of(Array.isArray(n)?n:[n])})}get tooltip(){let t=this.view.plugin(Go),e=t?t.manager.tooltips.findIndex(t=>t.create==tn.create):-1;return e>-1?t.manager.tooltipViews[e]:null}mousemove(t){var e,i;this.lastMove={x:t.clientX,y:t.clientY,target:t.target,time:Date.now()},this.hoverTimeout<0&&(this.hoverTimeout=setTimeout(this.checkHover,this.hoverTime));let{active:s,tooltip:o}=this;if(s.length&&o&&!function(t,e){let i,{left:s,right:o,top:n,bottom:r}=t.getBoundingClientRect();if(i=t.querySelector(".cm-tooltip-arrow")){let t=i.getBoundingClientRect();n=Math.min(t.top,n),r=Math.max(t.bottom,r)}return e.clientX>=s-on&&e.clientX<=o+on&&e.clientY>=n-on&&e.clientY<=r+on}(o.dom,t)||this.pending){let{pos:o}=s[0]||this.pending,n=null!==(i=null===(e=s[0])||void 0===e?void 0:e.end)&&void 0!==i?i:o;(o==n?this.view.posAtCoords(this.lastMove)==o:function(t,e,i,s,o){let n=t.scrollDOM.getBoundingClientRect(),r=t.documentTop+t.documentPadding.top+t.contentHeight;if(n.left>s||n.right<s||n.top>o||Math.min(n.bottom,r)<o)return!1;let l=t.posAtCoords({x:s,y:o},!1);return l>=e&&l<=i}(this.view,o,n,t.clientX,t.clientY))||(this.view.dispatch({effects:this.setHover.of([])}),this.pending=null)}}mouseleave(t){clearTimeout(this.hoverTimeout),this.hoverTimeout=-1;let{active:e}=this;if(e.length){let{tooltip:e}=this;e&&e.dom.contains(t.relatedTarget)?this.watchTooltipLeave(e.dom):this.view.dispatch({effects:this.setHover.of([])})}}watchTooltipLeave(t){let e=i=>{t.removeEventListener("mouseleave",e),this.active.length&&!this.view.dom.contains(i.relatedTarget)&&this.view.dispatch({effects:this.setHover.of([])})};t.addEventListener("mouseleave",e)}destroy(){clearTimeout(this.hoverTimeout),clearTimeout(this.restartTimeout),this.view.dom.removeEventListener("mouseleave",this.mouseleave),this.view.dom.removeEventListener("mousemove",this.mousemove)}}const on=4;function nn(t,e={}){let i=d.define(),s=u.define({create:()=>[],update(t,s){if(t.length&&(e.hideOnChange&&(s.docChanged||s.selection)?t=[]:e.hideOn&&(t=t.filter(t=>!e.hideOn(s,t))),s.docChanged)){let e=[];for(let i of t){let t=s.changes.mapPos(i.pos,-1,f.TrackDel);if(null!=t){let o=Object.assign(Object.create(null),i);o.pos=t,null!=o.end&&(o.end=s.changes.mapPos(o.end)),e.push(o)}}t=e}for(let e of s.effects)e.is(i)&&(t=e.value),e.is(ln)&&(t=[]);return t},provide:t=>Zo.from(t)});return{active:s,extension:[s,pe.define(o=>new sn(o,t,s,i,e.hoverTime||300)),en]}}function rn(t,e){let i=t.plugin(Go);if(!i)return null;let s=i.manager.tooltips.indexOf(e);return s<0?null:i.manager.tooltipViews[s]}const ln=d.define(),an=ln.of(null);const hn=c.define({combine(t){let e,i;for(let s of t)e=e||s.topContainer,i=i||s.bottomContainer;return{topContainer:e,bottomContainer:i}}});function cn(t,e){let i=t.plugin(dn),s=i?i.specs.indexOf(e):-1;return s>-1?i.panels[s]:null}const dn=pe.fromClass(class{constructor(t){this.input=t.state.facet(pn),this.specs=this.input.filter(t=>t),this.panels=this.specs.map(e=>e(t));let e=t.state.facet(hn);this.top=new un(t,!0,e.topContainer),this.bottom=new un(t,!1,e.bottomContainer),this.top.sync(this.panels.filter(t=>t.top)),this.bottom.sync(this.panels.filter(t=>!t.top));for(let t of this.panels)t.dom.classList.add("cm-panel"),t.mount&&t.mount()}update(t){let e=t.state.facet(hn);this.top.container!=e.topContainer&&(this.top.sync([]),this.top=new un(t.view,!0,e.topContainer)),this.bottom.container!=e.bottomContainer&&(this.bottom.sync([]),this.bottom=new un(t.view,!1,e.bottomContainer)),this.top.syncClasses(),this.bottom.syncClasses();let i=t.state.facet(pn);if(i!=this.input){let e=i.filter(t=>t),s=[],o=[],n=[],r=[];for(let i of e){let e,l=this.specs.indexOf(i);l<0?(e=i(t.view),r.push(e)):(e=this.panels[l],e.update&&e.update(t)),s.push(e),(e.top?o:n).push(e)}this.specs=e,this.panels=s,this.top.sync(o),this.bottom.sync(n);for(let t of r)t.dom.classList.add("cm-panel"),t.mount&&t.mount()}else for(let e of this.panels)e.update&&e.update(t)}destroy(){this.top.sync([]),this.bottom.sync([])}},{provide:t=>zs.scrollMargins.of(e=>{let i=e.plugin(t);return i&&{top:i.top.scrollMargin(),bottom:i.bottom.scrollMargin()}})});class un{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(0==this.panels.length)return void(this.dom&&(this.dom.remove(),this.dom=void 0));if(!this.dom){this.dom=document.createElement("div"),this.dom.className=this.top?"cm-panels cm-panels-top":"cm-panels cm-panels-bottom",this.dom.style[this.top?"top":"bottom"]="0";let t=this.container||this.view.dom;t.insertBefore(this.dom,this.top?t.firstChild:null)}let t=this.dom.firstChild;for(let e of this.panels)if(e.dom.parentNode==this.dom){for(;t!=e.dom;)t=fn(t);t=t.nextSibling}else this.dom.insertBefore(e.dom,t);for(;t;)t=fn(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 fn(t){let e=t.nextSibling;return t.remove(),e}const pn=c.define({enables:dn});const gn=u.define({create:()=>[],update(t,e){for(let i of e.effects)i.is(mn)?t=[i.value].concat(t):i.is(vn)&&(t=t.filter(t=>t!=i.value));return t},provide:t=>pn.computeN([t],e=>e.field(t))}),mn=d.define(),vn=d.define();class wn extends t{compare(t){return this==t||this.constructor==t.constructor&&this.eq(t)}eq(t){return!1}destroy(t){}}wn.prototype.elementClass="",wn.prototype.toDOM=void 0,wn.prototype.mapMode=f.TrackBefore,wn.prototype.startSide=wn.prototype.endSide=-1,wn.prototype.point=!0;const bn=c.define(),yn=c.define(),xn={class:"",renderEmptyElements:!1,elementStyle:"",markers:()=>e.empty,lineMarker:()=>null,widgetMarker:()=>null,lineMarkerChange:null,initialSpacer:null,updateSpacer:null,domEventHandlers:{},side:"before"},Sn=c.define();function Cn(t){return[kn(),Sn.of({...xn,...t})]}const Mn=c.define({combine:t=>t.some(t=>t)});function kn(t){let e=[An];return t&&!1===t.fixed&&e.push(Mn.of(!0)),e}const An=pe.fromClass(class{constructor(t){this.view=t,this.domAfter=null,this.prevViewport=t.viewport,this.dom=document.createElement("div"),this.dom.className="cm-gutters cm-gutters-before",this.dom.setAttribute("aria-hidden","true"),this.dom.style.minHeight=this.view.contentHeight/this.view.scaleY+"px",this.gutters=t.state.facet(Sn).map(e=>new Ln(t,e)),this.fixed=!t.state.facet(Mn);for(let t of this.gutters)"after"==t.config.side?this.getDOMAfter().appendChild(t.dom):this.dom.appendChild(t.dom);this.fixed&&(this.dom.style.position="sticky"),this.syncGutters(!1),t.scrollDOM.insertBefore(this.dom,t.contentDOM)}getDOMAfter(){return this.domAfter||(this.domAfter=document.createElement("div"),this.domAfter.className="cm-gutters cm-gutters-after",this.domAfter.setAttribute("aria-hidden","true"),this.domAfter.style.minHeight=this.view.contentHeight/this.view.scaleY+"px",this.domAfter.style.position=this.fixed?"sticky":"",this.view.scrollDOM.appendChild(this.domAfter)),this.domAfter}update(t){if(this.updateGutters(t)){let e=this.prevViewport,i=t.view.viewport,s=Math.min(e.to,i.to)-Math.max(e.from,i.from);this.syncGutters(s<.8*(i.to-i.from))}if(t.geometryChanged){let t=this.view.contentHeight/this.view.scaleY+"px";this.dom.style.minHeight=t,this.domAfter&&(this.domAfter.style.minHeight=t)}this.view.state.facet(Mn)!=!this.fixed&&(this.fixed=!this.fixed,this.dom.style.position=this.fixed?"sticky":"",this.domAfter&&(this.domAfter.style.position=this.fixed?"sticky":"")),this.prevViewport=t.view.viewport}syncGutters(t){let i=this.dom.nextSibling;t&&(this.dom.remove(),this.domAfter&&this.domAfter.remove());let s=e.iter(this.view.state.facet(bn),this.view.viewport.from),o=[],n=this.gutters.map(t=>new On(t,this.view.viewport,-this.view.documentPadding.top));for(let t of this.view.viewportLineBlocks)if(o.length&&(o=[]),Array.isArray(t.type)){let e=!0;for(let i of t.type)if(i.type==Z.Text&&e){Dn(s,o,i.from);for(let t of n)t.line(this.view,i,o);e=!1}else if(i.widget)for(let t of n)t.widget(this.view,i)}else if(t.type==Z.Text){Dn(s,o,t.from);for(let e of n)e.line(this.view,t,o)}else if(t.widget)for(let e of n)e.widget(this.view,t);for(let t of n)t.finish();t&&(this.view.scrollDOM.insertBefore(this.dom,i),this.domAfter&&this.view.scrollDOM.appendChild(this.domAfter))}updateGutters(t){let i=t.startState.facet(Sn),s=t.state.facet(Sn),o=t.docChanged||t.heightChanged||t.viewportChanged||!e.eq(t.startState.facet(bn),t.state.facet(bn),t.view.viewport.from,t.view.viewport.to);if(i==s)for(let e of this.gutters)e.update(t)&&(o=!0);else{o=!0;let e=[];for(let o of s){let s=i.indexOf(o);s<0?e.push(new Ln(this.view,o)):(this.gutters[s].update(t),e.push(this.gutters[s]))}for(let t of this.gutters)t.dom.remove(),e.indexOf(t)<0&&t.destroy();for(let t of e)"after"==t.config.side?this.getDOMAfter().appendChild(t.dom):this.dom.appendChild(t.dom);this.gutters=e}return o}destroy(){for(let t of this.gutters)t.destroy();this.dom.remove(),this.domAfter&&this.domAfter.remove()}},{provide:t=>zs.scrollMargins.of(e=>{let i=e.plugin(t);if(!i||0==i.gutters.length||!i.fixed)return null;let s=i.dom.offsetWidth*e.scaleX,o=i.domAfter?i.domAfter.offsetWidth*e.scaleX:0;return e.textDirection==Ot.LTR?{left:s,right:o}:{right:s,left:o}})});function Tn(t){return Array.isArray(t)?t:[t]}function Dn(t,e,i){for(;t.value&&t.from<=i;)t.from==i&&e.push(t.value),t.next()}class On{constructor(t,i,s){this.gutter=t,this.height=s,this.i=0,this.cursor=e.iter(t.markers,i.from)}addElement(t,e,i){let{gutter:s}=this,o=(e.top-this.height)/t.scaleY,n=e.height/t.scaleY;if(this.i==s.elements.length){let e=new Bn(t,n,o,i);s.elements.push(e),s.dom.appendChild(e.dom)}else s.elements[this.i].update(t,n,o,i);this.height=e.bottom,this.i++}line(t,e,i){let s=[];Dn(this.cursor,s,e.from),i.length&&(s=s.concat(i));let o=this.gutter.config.lineMarker(t,e,s);o&&s.unshift(o);let n=this.gutter;(0!=s.length||n.config.renderEmptyElements)&&this.addElement(t,e,s)}widget(t,e){let i=this.gutter.config.widgetMarker(t,e.widget,e),s=i?[i]:null;for(let i of t.state.facet(yn)){let o=i(t,e.widget,e);o&&(s||(s=[])).push(o)}s&&this.addElement(t,e,s)}finish(){let t=this.gutter;for(;t.elements.length>this.i;){let e=t.elements.pop();t.dom.removeChild(e.dom),e.destroy()}}}class Ln{constructor(t,e){this.view=t,this.config=e,this.elements=[],this.spacer=null,this.dom=document.createElement("div"),this.dom.className="cm-gutter"+(this.config.class?" "+this.config.class:"");for(let i in e.domEventHandlers)this.dom.addEventListener(i,s=>{let o,n=s.target;if(n!=this.dom&&this.dom.contains(n)){for(;n.parentNode!=this.dom;)n=n.parentNode;let t=n.getBoundingClientRect();o=(t.top+t.bottom)/2}else o=s.clientY;let r=t.lineBlockAtHeight(o-t.documentTop);e.domEventHandlers[i](t,r,s)&&s.preventDefault()});this.markers=Tn(e.markers(t)),e.initialSpacer&&(this.spacer=new Bn(t,0,0,[e.initialSpacer(t)]),this.dom.appendChild(this.spacer.dom),this.spacer.dom.style.cssText+="visibility: hidden; pointer-events: none")}update(t){let i=this.markers;if(this.markers=Tn(this.config.markers(t.view)),this.spacer&&this.config.updateSpacer){let e=this.config.updateSpacer(this.spacer.markers[0],t);e!=this.spacer.markers[0]&&this.spacer.update(t.view,0,0,[e])}let s=t.view.viewport;return!e.eq(this.markers,i,s.from,s.to)||!!this.config.lineMarkerChange&&this.config.lineMarkerChange(t)}destroy(){for(let t of this.elements)t.destroy()}}class Bn{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.height=e,this.dom.style.height=e+"px"),this.above!=i&&(this.dom.style.marginTop=(this.above=i)?i+"px":""),function(t,e){if(t.length!=e.length)return!1;for(let i=0;i<t.length;i++)if(!t[i].compare(e[i]))return!1;return!0}(this.markers,s)||this.setMarkers(t,s)}setMarkers(t,e){let i="cm-gutterElement",s=this.dom.firstChild;for(let o=0,n=0;;){let r=n,l=o<e.length?e[o++]:null,a=!1;if(l){let t=l.elementClass;t&&(i+=" "+t);for(let t=n;t<this.markers.length;t++)if(this.markers[t].compare(l)){r=t,a=!0;break}}else r=this.markers.length;for(;n<r;){let t=this.markers[n++];if(t.toDOM){t.destroy(s);let e=s.nextSibling;s.remove(),s=e}}if(!l)break;l.toDOM&&(a?s=s.nextSibling:this.dom.insertBefore(l.toDOM(t),s)),a&&n++}this.dom.className=i,this.markers=e}destroy(){this.setMarkers(null,[])}}const En=c.define(),Rn=c.define(),Hn=c.define({combine:t=>g(t,{formatNumber:String,domEventHandlers:{}},{domEventHandlers(t,e){let i=Object.assign({},t);for(let t in e){let s=i[t],o=e[t];i[t]=s?(t,e,i)=>s(t,e,i)||o(t,e,i):o}return i}})});class Wn extends wn{constructor(t){super(),this.number=t}eq(t){return this.number==t.number}toDOM(){return document.createTextNode(this.number)}}function Nn(t,e){return t.state.facet(Hn).formatNumber(e,t.state)}const Pn=Sn.compute([Hn],t=>({class:"cm-lineNumbers",renderEmptyElements:!1,markers:t=>t.state.facet(En),lineMarker:(t,e,i)=>i.some(t=>t.toDOM)?null:new Wn(Nn(t,t.state.doc.lineAt(e.from).number)),widgetMarker:(t,e,i)=>{for(let s of t.state.facet(Rn)){let o=s(t,e,i);if(o)return o}return null},lineMarkerChange:t=>t.startState.facet(Hn)!=t.state.facet(Hn),initialSpacer:t=>new Wn(Nn(t,Fn(t.state.doc.lines))),updateSpacer(t,e){let i=Nn(e.view,Fn(e.view.state.doc.lines));return i==t.number?t:new Wn(i)},domEventHandlers:t.facet(Hn).domEventHandlers,side:"before"}));function Vn(t={}){return[Hn.of(t),kn(),Pn]}function Fn(t){let e=9;for(;e<t;)e=10*e+9;return e}const zn=new class extends wn{constructor(){super(...arguments),this.elementClass="cm-activeLineGutter"}},In=bn.compute(["selection"],t=>{let i=[],s=-1;for(let e of t.selection.ranges){let o=t.doc.lineAt(e.head).from;o>s&&(s=o,i.push(zn.range(o)))}return e.of(i)});function qn(){return In}function Kn(t){return pe.define(e=>({decorations:t.createDeco(e),update(e){this.decorations=t.updateDeco(e,this.decorations)}}),{decorations:t=>t.decorations})}const _n=tt.mark({class:"cm-highlightTab"}),Yn=tt.mark({class:"cm-highlightSpace"}),jn=Kn(new xo({regexp:/\t| /g,decoration:t=>"\t"==t[0]?_n:Yn,boundary:/\S/}));const Xn=Kn(new xo({regexp:/\s+$/g,decoration:tt.mark({class:"cm-trailingSpace"})}));const Gn={HeightMap:os,HeightOracle:Zi,MeasuredHeights:ts,QueryType:is,ChangedRange:Te,computeOrder:_t,moveVisually:Xt,clearHeightChangeFlag:Ji,getHeightChangeFlag:()=>Qi};var Un=Object.freeze({__proto__:null,BidiSpan:Ft,BlockInfo:es,get BlockType(){return Z},BlockWrapper:rt,Decoration:tt,get Direction(){return Ot},EditorView:zs,GutterMarker:wn,MatchDecorator:xo,RectangleMarker:io,ViewPlugin:pe,ViewUpdate:De,WidgetType:J,__test:Gn,closeHoverTooltips:an,crosshairCursor:qo,drawSelection:ho,dropCursor:bo,getDialog:function(t,e){let i=t.state.field(gn,!1)||[];for(let s of i){let i=cn(t,s);if(i&&i.dom.classList.contains(e))return i}return null},getDrawSelectionConfig:function(t){return t.facet(ao)},getPanel:cn,getTooltip:rn,gutter:Cn,gutterLineClass:bn,gutterWidgetClass:yn,gutters:kn,hasHoverTooltips:function(t){return t.facet(Zo).some(t=>t)},highlightActiveLine:Eo,highlightActiveLineGutter:qn,highlightSpecialChars:To,highlightTrailingWhitespace:function(){return Xn},highlightWhitespace:function(){return jn},hoverTooltip:nn,keymap:Gs,layer:lo,lineNumberMarkers:En,lineNumberWidgetMarker:Rn,lineNumbers:Vn,logException:ce,panels:function(t){return t?[hn.of(t)]:[]},placeholder:function(t){let e=pe.fromClass(class{constructor(e){this.view=e,this.placeholder=t?tt.set([tt.widget({widget:new Wo(t),side:1}).range(0)]):tt.none}get decorations(){return this.view.state.doc.length?tt.none:this.placeholder}},{decorations:t=>t.decorations});return"string"==typeof t?[e,zs.contentAttributes.of({"aria-placeholder":t})]:e},rectangularSelection:Fo,repositionTooltips:function(t){let e=t.plugin(Go);e&&e.maybeMeasure()},runScopeHandlers:Qs,scrollPastEnd:function(){return[Bo,ve.of(t=>{var e;return(null===(e=t.plugin(Bo))||void 0===e?void 0:e.attrs)||null})]},showDialog:function(t,e){let i,s=new Promise(t=>i=t),o=t=>function(t,e,i){let s=e.content?e.content(t,()=>r(null)):null;if(!s){if(s=R("form"),e.input){let t=R("input",e.input);/^(text|password|number|email|tel|url)$/.test(t.type)&&t.classList.add("cm-textfield"),t.name||(t.name="input"),s.appendChild(R("label",(e.label||"")+": ",t))}else s.appendChild(document.createTextNode(e.label||""));s.appendChild(document.createTextNode(" ")),s.appendChild(R("button",{class:"cm-button",type:"submit"},e.submitLabel||"OK"))}let o="FORM"==s.nodeName?[s]:s.querySelectorAll("form");for(let t=0;t<o.length;t++){let e=o[t];e.addEventListener("keydown",t=>{27==t.keyCode?(t.preventDefault(),r(null)):13==t.keyCode&&(t.preventDefault(),r(e))}),e.addEventListener("submit",t=>{t.preventDefault(),r(e)})}let n=R("div",s,R("button",{onclick:()=>r(null),"aria-label":t.state.phrase("close"),class:"cm-dialog-close",type:"button"},["×"]));e.class&&(n.className=e.class);function r(e){n.contains(n.ownerDocument.activeElement)&&t.focus(),i(e)}return n.classList.add("cm-dialog"),{dom:n,top:e.top,mount:()=>{if(e.focus){let t;t="string"==typeof e.focus?s.querySelector(e.focus):s.querySelector("input")||s.querySelector("button"),t&&"select"in t?t.select():t&&"focus"in t&&t.focus()}}}}(t,e,i);t.state.field(gn,!1)?t.dispatch({effects:mn.of(o)}):t.dispatch({effects:d.appendConfig.of(gn.init(()=>[o]))});let n=vn.of(o);return{close:n,result:s.then(e=>((t.win.queueMicrotask||(e=>t.win.setTimeout(e,10)))(()=>{t.state.field(gn).indexOf(o)>-1&&t.dispatch({effects:n})}),e))}},showPanel:pn,showTooltip:Jo,tooltips:function(t={}){return jo.of(t)}});export{Ot as D,zs as E,wn as G,M as S,pe as V,J as W,tt as a,cn as b,pn as c,R as d,Vn as e,qn as f,rn as g,nn as h,To as i,ho as j,Gs as k,ce as l,bo as m,Fo as n,qo as o,Eo as p,Cn as q,Qs as r,Jo as s,Un as t};
2
+ //# sourceMappingURL=codemirror_view-C_m1bYT7.js.map