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